Skip to content

Commit

Permalink
fixup! fix(tools): add proper wikipedia result types
Browse files Browse the repository at this point in the history
  • Loading branch information
jezekra1 committed Jan 6, 2025
1 parent a108ae8 commit f2b2de4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/internals/helpers/promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import { isFunction, isPromise } from "remeda";
import { getProp } from "@/internals/helpers/object.js";
import { UnwrapPromise } from "@/internals/types.js";

export function isPromiseLike<T>(value: unknown): value is PromiseLike<T> {
return isPromise(value) || isFunction(getProp(value, ["then"]));
Expand Down Expand Up @@ -70,7 +69,7 @@ export async function* emitterToGenerator<T, R>(fn: EmitterToGeneratorFn<T, R>)

export async function asyncProperties<T extends NonNullable<unknown>>(
obj: T,
): Promise<{ [K in keyof T]: UnwrapPromise<T[K]> }> {
): Promise<{ [K in keyof T]: Awaited<T[K]> }> {
return Object.fromEntries(
await Promise.all(Object.entries(obj).map(async ([key, value]) => [key, await value])),
);
Expand Down
12 changes: 5 additions & 7 deletions src/tools/search/wikipedia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
* limitations under the License.
*/

import type { Page, pageFunctions, searchOptions } from "wikipedia";
import wiki from "wikipedia";
import { Cache } from "@/cache/decoratorCache.js";
import * as R from "remeda";
import type { Page, pageFunctions, searchOptions } from "wikipedia";
import { ArrayKeys, Common, UnwrapPromise } from "@/internals/types.js";
import { keys, mapValues } from "remeda";
import { ArrayKeys, Common } from "@/internals/types.js";
import {
SearchToolOptions,
SearchToolOutput,
Expand All @@ -27,11 +28,10 @@ import {
} from "./base.js";
import { asyncProperties } from "@/internals/helpers/promise.js";
import { z } from "zod";
import { ToolEmitter, Tool, ToolInput } from "@/tools/base.js";
import { Tool, ToolEmitter, ToolInput } from "@/tools/base.js";
import Turndown from "turndown";
// @ts-expect-error missing types
import turndownPlugin from "joplin-turndown-plugin-gfm";
import { keys, mapValues } from "remeda";
import stringComparison from "string-comparison";
import { pageResult } from "wikipedia/dist/resultTypes.js";
import { Emitter } from "@/emitter/emitter.js";
Expand Down Expand Up @@ -82,9 +82,7 @@ export interface WikipediaToolRunOptions extends SearchToolRunOptions {

type PageWithMarkdown = Page & { markdown: () => Promise<string> };

type ResultFields = {
[K in keyof PageFunctions]: UnwrapPromise<ReturnType<PageWithMarkdown[K]>>;
};
type ResultFields = { [K in keyof PageFunctions]: Awaited<ReturnType<PageWithMarkdown[K]>> };

export interface WikipediaToolResult extends SearchToolResult {
fields: Partial<ResultFields>;
Expand Down

0 comments on commit f2b2de4

Please sign in to comment.