@langchain/core 1.1.1 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/agents.d.cts +0 -2
- package/dist/agents.d.ts +0 -2
- package/dist/callbacks/base.d.cts +22 -60
- package/dist/callbacks/base.d.ts +22 -60
- package/dist/callbacks/dispatch/index.d.cts +1 -3
- package/dist/callbacks/dispatch/index.d.ts +1 -3
- package/dist/callbacks/dispatch/web.d.cts +1 -3
- package/dist/callbacks/dispatch/web.d.ts +1 -3
- package/dist/callbacks/manager.d.cts +2 -12
- package/dist/callbacks/manager.d.ts +2 -12
- package/dist/chat_history.cjs +1 -1
- package/dist/chat_history.d.cts +0 -1
- package/dist/chat_history.d.ts +0 -1
- package/dist/chat_history.js +1 -1
- package/dist/document_loaders/langsmith.d.cts +0 -3
- package/dist/document_loaders/langsmith.d.ts +0 -3
- package/dist/documents/document.d.cts +3 -12
- package/dist/documents/document.d.ts +3 -12
- package/dist/example_selectors/length_based.d.cts +1 -1
- package/dist/example_selectors/length_based.d.ts +1 -1
- package/dist/indexing/base.d.cts +0 -1
- package/dist/indexing/base.d.ts +0 -1
- package/dist/indexing/record_manager.d.cts +0 -1
- package/dist/indexing/record_manager.d.ts +0 -1
- package/dist/language_models/base.d.cts +8 -38
- package/dist/language_models/base.d.ts +8 -38
- package/dist/language_models/chat_models.cjs +1 -1
- package/dist/language_models/chat_models.d.cts +6 -33
- package/dist/language_models/chat_models.d.ts +6 -33
- package/dist/language_models/chat_models.js +1 -1
- package/dist/language_models/llms.d.cts +0 -6
- package/dist/language_models/llms.d.ts +0 -6
- package/dist/load/import_type.d.cts +0 -1
- package/dist/load/import_type.d.ts +0 -1
- package/dist/load/map_keys.cjs +4 -5
- package/dist/load/map_keys.cjs.map +1 -1
- package/dist/load/map_keys.d.cts +0 -1
- package/dist/load/map_keys.d.ts +0 -1
- package/dist/load/map_keys.js +3 -3
- package/dist/load/map_keys.js.map +1 -1
- package/dist/load/serializable.d.cts +0 -1
- package/dist/load/serializable.d.ts +0 -1
- package/dist/memory.d.cts +0 -3
- package/dist/memory.d.ts +0 -3
- package/dist/messages/ai.cjs +6 -48
- package/dist/messages/ai.cjs.map +1 -1
- package/dist/messages/ai.js +6 -48
- package/dist/messages/ai.js.map +1 -1
- package/dist/messages/base.cjs +3 -2
- package/dist/messages/base.cjs.map +1 -1
- package/dist/messages/base.d.cts +1 -13
- package/dist/messages/base.d.ts +1 -13
- package/dist/messages/base.js +3 -2
- package/dist/messages/base.js.map +1 -1
- package/dist/messages/content/data.d.cts +2 -7
- package/dist/messages/content/data.d.ts +2 -7
- package/dist/messages/content/index.d.cts +1 -4
- package/dist/messages/content/index.d.ts +1 -4
- package/dist/messages/content/multimodal.d.cts +0 -1
- package/dist/messages/content/multimodal.d.ts +0 -1
- package/dist/messages/content/tools.d.cts +0 -1
- package/dist/messages/content/tools.d.ts +0 -1
- package/dist/messages/index.cjs +4 -2
- package/dist/messages/index.d.cts +2 -2
- package/dist/messages/index.d.ts +2 -2
- package/dist/messages/index.js +5 -4
- package/dist/messages/tool.d.cts +2 -9
- package/dist/messages/tool.d.ts +2 -9
- package/dist/messages/transformers.cjs +2 -2
- package/dist/messages/transformers.d.cts +0 -3
- package/dist/messages/transformers.d.ts +0 -3
- package/dist/messages/transformers.js +2 -2
- package/dist/messages/utils.cjs +77 -4
- package/dist/messages/utils.cjs.map +1 -1
- package/dist/messages/utils.d.cts +35 -7
- package/dist/messages/utils.d.ts +35 -7
- package/dist/messages/utils.js +77 -5
- package/dist/messages/utils.js.map +1 -1
- package/dist/node_modules/.pnpm/ansi-styles@6.2.3/node_modules/ansi-styles/index.cjs +169 -0
- package/dist/node_modules/.pnpm/ansi-styles@6.2.3/node_modules/ansi-styles/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/ansi-styles@6.2.3/node_modules/ansi-styles/index.js +168 -0
- package/dist/node_modules/.pnpm/ansi-styles@6.2.3/node_modules/ansi-styles/index.js.map +1 -0
- package/dist/node_modules/.pnpm/camelcase@9.0.0/node_modules/camelcase/index.cjs +122 -0
- package/dist/node_modules/.pnpm/camelcase@9.0.0/node_modules/camelcase/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/camelcase@9.0.0/node_modules/camelcase/index.js +121 -0
- package/dist/node_modules/.pnpm/camelcase@9.0.0/node_modules/camelcase/index.js.map +1 -0
- package/dist/node_modules/.pnpm/decamelize@6.0.1/node_modules/decamelize/index.cjs +18 -0
- package/dist/node_modules/.pnpm/decamelize@6.0.1/node_modules/decamelize/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/decamelize@6.0.1/node_modules/decamelize/index.js +17 -0
- package/dist/node_modules/.pnpm/decamelize@6.0.1/node_modules/decamelize/index.js.map +1 -0
- package/dist/node_modules/.pnpm/is-network-error@1.3.0/node_modules/is-network-error/index.cjs +27 -0
- package/dist/node_modules/.pnpm/is-network-error@1.3.0/node_modules/is-network-error/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/is-network-error@1.3.0/node_modules/is-network-error/index.js +26 -0
- package/dist/node_modules/.pnpm/is-network-error@1.3.0/node_modules/is-network-error/index.js.map +1 -0
- package/dist/node_modules/.pnpm/p-retry@7.1.0/node_modules/p-retry/index.cjs +141 -0
- package/dist/node_modules/.pnpm/p-retry@7.1.0/node_modules/p-retry/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/p-retry@7.1.0/node_modules/p-retry/index.js +141 -0
- package/dist/node_modules/.pnpm/p-retry@7.1.0/node_modules/p-retry/index.js.map +1 -0
- package/dist/output_parsers/json.cjs.map +1 -1
- package/dist/output_parsers/json.d.cts +1 -5
- package/dist/output_parsers/json.d.ts +1 -5
- package/dist/output_parsers/json.js.map +1 -1
- package/dist/output_parsers/openai_functions/json_output_functions_parsers.d.cts +2 -6
- package/dist/output_parsers/openai_functions/json_output_functions_parsers.d.ts +2 -6
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.d.cts +10 -34
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.d.ts +10 -34
- package/dist/output_parsers/transform.d.cts +0 -1
- package/dist/output_parsers/transform.d.ts +0 -1
- package/dist/outputs.d.cts +0 -6
- package/dist/outputs.d.ts +0 -6
- package/dist/prompts/base.d.cts +2 -10
- package/dist/prompts/base.d.ts +2 -10
- package/dist/prompts/chat.cjs +2 -2
- package/dist/prompts/chat.d.cts +13 -51
- package/dist/prompts/chat.d.ts +13 -51
- package/dist/prompts/chat.js +2 -2
- package/dist/prompts/few_shot.d.cts +1 -5
- package/dist/prompts/few_shot.d.ts +1 -5
- package/dist/prompts/image.d.cts +2 -10
- package/dist/prompts/image.d.ts +2 -10
- package/dist/prompts/prompt.d.cts +4 -15
- package/dist/prompts/prompt.d.ts +4 -16
- package/dist/prompts/serde.d.cts +0 -1
- package/dist/prompts/serde.d.ts +0 -1
- package/dist/prompts/string.d.cts +1 -5
- package/dist/prompts/string.d.ts +1 -5
- package/dist/prompts/structured.d.cts +3 -16
- package/dist/prompts/structured.d.ts +3 -16
- package/dist/retrievers/document_compressors/index.d.cts +0 -1
- package/dist/retrievers/document_compressors/index.d.ts +0 -1
- package/dist/retrievers/index.d.cts +2 -6
- package/dist/retrievers/index.d.ts +2 -6
- package/dist/runnables/base.cjs +7 -7
- package/dist/runnables/base.cjs.map +1 -1
- package/dist/runnables/base.d.cts +12 -64
- package/dist/runnables/base.d.ts +12 -64
- package/dist/runnables/base.js +1 -1
- package/dist/runnables/branch.d.cts +0 -2
- package/dist/runnables/branch.d.ts +0 -2
- package/dist/runnables/config.d.cts +0 -1
- package/dist/runnables/config.d.ts +0 -1
- package/dist/runnables/graph.d.cts +1 -5
- package/dist/runnables/graph.d.ts +1 -5
- package/dist/runnables/graph_mermaid.cjs +2 -1
- package/dist/runnables/graph_mermaid.cjs.map +1 -1
- package/dist/runnables/graph_mermaid.js +3 -1
- package/dist/runnables/graph_mermaid.js.map +1 -1
- package/dist/runnables/history.cjs +1 -1
- package/dist/runnables/history.d.cts +4 -12
- package/dist/runnables/history.d.ts +4 -12
- package/dist/runnables/history.js +1 -1
- package/dist/runnables/passthrough.d.cts +0 -2
- package/dist/runnables/passthrough.d.ts +0 -2
- package/dist/runnables/router.d.cts +0 -1
- package/dist/runnables/router.d.ts +0 -1
- package/dist/runnables/types.d.cts +2 -9
- package/dist/runnables/types.d.ts +2 -9
- package/dist/runnables/utils.cjs +5 -0
- package/dist/runnables/utils.cjs.map +1 -1
- package/dist/runnables/utils.js +5 -1
- package/dist/runnables/utils.js.map +1 -1
- package/dist/singletons/async_local_storage/context.d.cts +0 -2
- package/dist/singletons/async_local_storage/context.d.ts +0 -2
- package/dist/singletons/async_local_storage/globals.d.cts +0 -1
- package/dist/singletons/async_local_storage/globals.d.ts +0 -1
- package/dist/singletons/callbacks.cjs.map +1 -1
- package/dist/singletons/callbacks.js.map +1 -1
- package/dist/stores.d.cts +0 -1
- package/dist/stores.d.ts +0 -1
- package/dist/structured_query/utils.d.cts +1 -4
- package/dist/structured_query/utils.d.ts +1 -4
- package/dist/tools/index.d.cts +1 -6
- package/dist/tools/index.d.ts +1 -6
- package/dist/tools/types.d.cts +3 -13
- package/dist/tools/types.d.ts +3 -13
- package/dist/tracers/base.d.cts +1 -20
- package/dist/tracers/base.d.ts +1 -20
- package/dist/tracers/console.cjs +3 -3
- package/dist/tracers/console.cjs.map +1 -1
- package/dist/tracers/console.d.cts +0 -2
- package/dist/tracers/console.d.ts +0 -2
- package/dist/tracers/console.js +3 -3
- package/dist/tracers/console.js.map +1 -1
- package/dist/tracers/event_stream.d.cts +0 -4
- package/dist/tracers/event_stream.d.ts +0 -4
- package/dist/tracers/log_stream.d.cts +0 -6
- package/dist/tracers/log_stream.d.ts +0 -6
- package/dist/types/_internal.d.cts +0 -3
- package/dist/types/_internal.d.ts +0 -3
- package/dist/types/type-utils.d.cts +0 -2
- package/dist/types/type-utils.d.ts +0 -2
- package/dist/utils/async_caller.cjs +2 -7
- package/dist/utils/async_caller.cjs.map +1 -1
- package/dist/utils/async_caller.d.cts +0 -3
- package/dist/utils/async_caller.d.ts +0 -3
- package/dist/utils/async_caller.js +1 -6
- package/dist/utils/async_caller.js.map +1 -1
- package/dist/utils/env.d.cts +0 -4
- package/dist/utils/env.d.ts +0 -4
- package/dist/utils/event_source_parse.d.cts +1 -4
- package/dist/utils/event_source_parse.d.ts +1 -4
- package/dist/utils/function_calling.d.cts +1 -3
- package/dist/utils/function_calling.d.ts +1 -3
- package/dist/utils/json.cjs +182 -22
- package/dist/utils/json.cjs.map +1 -1
- package/dist/utils/json.d.cts +1 -3
- package/dist/utils/json.d.ts +1 -3
- package/dist/utils/json.js +182 -22
- package/dist/utils/json.js.map +1 -1
- package/dist/utils/stream.d.cts +1 -13
- package/dist/utils/stream.d.ts +1 -13
- package/dist/utils/testing/chat_models.d.cts +3 -11
- package/dist/utils/testing/chat_models.d.ts +3 -11
- package/dist/utils/testing/message_history.cjs +1 -1
- package/dist/utils/testing/message_history.js +1 -1
- package/dist/utils/testing/retrievers.d.cts +1 -3
- package/dist/utils/testing/retrievers.d.ts +1 -3
- package/dist/utils/testing/vectorstores.d.cts +0 -1
- package/dist/utils/testing/vectorstores.d.ts +0 -1
- package/dist/utils/types/index.cjs +4 -0
- package/dist/utils/types/index.d.cts +2 -4
- package/dist/utils/types/index.d.ts +2 -4
- package/dist/utils/types/index.js +4 -2
- package/dist/utils/types/zod.cjs +24 -0
- package/dist/utils/types/zod.cjs.map +1 -1
- package/dist/utils/types/zod.d.cts +4 -4
- package/dist/utils/types/zod.d.ts +4 -4
- package/dist/utils/types/zod.js +23 -1
- package/dist/utils/types/zod.js.map +1 -1
- package/dist/vectorstores.d.cts +5 -17
- package/dist/vectorstores.d.ts +5 -17
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async_caller.cjs","names":["
|
|
1
|
+
{"version":3,"file":"async_caller.cjs","names":["error: any","params: AsyncCallerParams","PQueueMod","callable: T","pRetry","options: AsyncCallerCallOptions","listener: (() => void) | undefined","getAbortSignalError"],"sources":["../../src/utils/async_caller.ts"],"sourcesContent":["import PQueueMod from \"p-queue\";\nimport pRetry from \"p-retry\";\n\nimport { getAbortSignalError } from \"./signal.js\";\n\nconst STATUS_NO_RETRY = [\n 400, // Bad Request\n 401, // Unauthorized\n 402, // Payment Required\n 403, // Forbidden\n 404, // Not Found\n 405, // Method Not Allowed\n 406, // Not Acceptable\n 407, // Proxy Authentication Required\n 409, // Conflict\n];\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst defaultFailedAttemptHandler = (error: any) => {\n if (\n error.message.startsWith(\"Cancel\") ||\n error.message.startsWith(\"AbortError\") ||\n error.name === \"AbortError\"\n ) {\n throw error;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if ((error as any)?.code === \"ECONNABORTED\") {\n throw error;\n }\n const status =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (error as any)?.response?.status ?? (error as any)?.status;\n if (status && STATUS_NO_RETRY.includes(+status)) {\n throw error;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if ((error as any)?.error?.code === \"insufficient_quota\") {\n const err = new Error(error?.message);\n err.name = \"InsufficientQuotaError\";\n throw err;\n }\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type FailedAttemptHandler = (error: any) => any;\n\nexport interface AsyncCallerParams {\n /**\n * The maximum number of concurrent calls that can be made.\n * Defaults to `Infinity`, which means no limit.\n */\n maxConcurrency?: number;\n /**\n * The maximum number of retries that can be made for a single call,\n * with an exponential backoff between each attempt. Defaults to 6.\n */\n maxRetries?: number;\n /**\n * Custom handler to handle failed attempts. Takes the originally thrown\n * error object as input, and should itself throw an error if the input\n * error is not retryable.\n */\n onFailedAttempt?: FailedAttemptHandler;\n}\n\nexport interface AsyncCallerCallOptions {\n signal?: AbortSignal;\n}\n\n/**\n * A class that can be used to make async calls with concurrency and retry logic.\n *\n * This is useful for making calls to any kind of \"expensive\" external resource,\n * be it because it's rate-limited, subject to network issues, etc.\n *\n * Concurrent calls are limited by the `maxConcurrency` parameter, which defaults\n * to `Infinity`. This means that by default, all calls will be made in parallel.\n *\n * Retries are limited by the `maxRetries` parameter, which defaults to 6. This\n * means that by default, each call will be retried up to 6 times, with an\n * exponential backoff between each attempt.\n */\nexport class AsyncCaller {\n protected maxConcurrency: AsyncCallerParams[\"maxConcurrency\"];\n\n protected maxRetries: AsyncCallerParams[\"maxRetries\"];\n\n protected onFailedAttempt: AsyncCallerParams[\"onFailedAttempt\"];\n\n private queue: typeof import(\"p-queue\")[\"default\"][\"prototype\"];\n\n constructor(params: AsyncCallerParams) {\n this.maxConcurrency = params.maxConcurrency ?? Infinity;\n this.maxRetries = params.maxRetries ?? 6;\n this.onFailedAttempt =\n params.onFailedAttempt ?? defaultFailedAttemptHandler;\n\n const PQueue = (\n \"default\" in PQueueMod ? PQueueMod.default : PQueueMod\n ) as typeof PQueueMod;\n this.queue = new PQueue({ concurrency: this.maxConcurrency });\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async call<A extends any[], T extends (...args: A) => Promise<any>>(\n callable: T,\n ...args: Parameters<T>\n ): Promise<Awaited<ReturnType<T>>> {\n return this.queue.add(\n () =>\n pRetry(\n () =>\n callable(...args).catch((error) => {\n // eslint-disable-next-line no-instanceof/no-instanceof\n if (error instanceof Error) {\n throw error;\n } else {\n throw new Error(error);\n }\n }),\n {\n onFailedAttempt: ({ error }) => this.onFailedAttempt?.(error),\n retries: this.maxRetries,\n randomize: true,\n // If needed we can change some of the defaults here,\n // but they're quite sensible.\n }\n ),\n { throwOnTimeout: true }\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n callWithOptions<A extends any[], T extends (...args: A) => Promise<any>>(\n options: AsyncCallerCallOptions,\n callable: T,\n ...args: Parameters<T>\n ): Promise<Awaited<ReturnType<T>>> {\n // Note this doesn't cancel the underlying request,\n // when available prefer to use the signal option of the underlying call\n if (options.signal) {\n let listener: (() => void) | undefined;\n return Promise.race([\n this.call<A, T>(callable, ...args),\n new Promise<never>((_, reject) => {\n listener = () => {\n reject(getAbortSignalError(options.signal));\n };\n options.signal?.addEventListener(\"abort\", listener);\n }),\n ]).finally(() => {\n if (options.signal && listener) {\n options.signal.removeEventListener(\"abort\", listener);\n }\n });\n }\n return this.call<A, T>(callable, ...args);\n }\n\n fetch(...args: Parameters<typeof fetch>): ReturnType<typeof fetch> {\n return this.call(() =>\n fetch(...args).then((res) => (res.ok ? res : Promise.reject(res)))\n );\n }\n}\n"],"mappings":";;;;;;;;AAKA,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD;AAGD,MAAM,8BAA8B,CAACA,UAAe;AAClD,KACE,MAAM,QAAQ,WAAW,SAAS,IAClC,MAAM,QAAQ,WAAW,aAAa,IACtC,MAAM,SAAS,aAEf,OAAM;AAGR,KAAK,OAAe,SAAS,eAC3B,OAAM;CAER,MAAM,SAEH,OAAe,UAAU,UAAW,OAAe;AACtD,KAAI,UAAU,gBAAgB,SAAS,CAAC,OAAO,CAC7C,OAAM;AAGR,KAAK,OAAe,OAAO,SAAS,sBAAsB;EACxD,MAAM,MAAM,IAAI,MAAM,OAAO;EAC7B,IAAI,OAAO;AACX,QAAM;CACP;AACF;;;;;;;;;;;;;;AAyCD,IAAa,cAAb,MAAyB;CACvB,AAAU;CAEV,AAAU;CAEV,AAAU;CAEV,AAAQ;CAER,YAAYC,QAA2B;EACrC,KAAK,iBAAiB,OAAO,kBAAkB;EAC/C,KAAK,aAAa,OAAO,cAAc;EACvC,KAAK,kBACH,OAAO,mBAAmB;EAE5B,MAAM,SACJ,aAAaC,kBAAYA,gBAAU,UAAUA;EAE/C,KAAK,QAAQ,IAAI,OAAO,EAAE,aAAa,KAAK,eAAgB;CAC7D;CAGD,MAAM,KACJC,UACA,GAAG,MAC8B;AACjC,SAAO,KAAK,MAAM,IAChB,MACEC,qBACE,MACE,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,UAAU;AAEjC,OAAI,iBAAiB,MACnB,OAAM;OAEN,OAAM,IAAI,MAAM;EAEnB,EAAC,EACJ;GACE,iBAAiB,CAAC,EAAE,OAAO,KAAK,KAAK,kBAAkB,MAAM;GAC7D,SAAS,KAAK;GACd,WAAW;EAGZ,EACF,EACH,EAAE,gBAAgB,KAAM,EACzB;CACF;CAGD,gBACEC,SACAF,UACA,GAAG,MAC8B;AAGjC,MAAI,QAAQ,QAAQ;GAClB,IAAIG;AACJ,UAAO,QAAQ,KAAK,CAClB,KAAK,KAAW,UAAU,GAAG,KAAK,EAClC,IAAI,QAAe,CAAC,GAAG,WAAW;IAChC,WAAW,MAAM;KACf,OAAOC,mCAAoB,QAAQ,OAAO,CAAC;IAC5C;IACD,QAAQ,QAAQ,iBAAiB,SAAS,SAAS;GACpD,EACF,EAAC,CAAC,QAAQ,MAAM;AACf,QAAI,QAAQ,UAAU,UACpB,QAAQ,OAAO,oBAAoB,SAAS,SAAS;GAExD,EAAC;EACH;AACD,SAAO,KAAK,KAAW,UAAU,GAAG,KAAK;CAC1C;CAED,MAAM,GAAG,MAA0D;AACjE,SAAO,KAAK,KAAK,MACf,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,QAAS,IAAI,KAAK,MAAM,QAAQ,OAAO,IAAI,CAAE,CACnE;CACF;AACF"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
//#region src/utils/async_caller.d.ts
|
|
2
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3
2
|
type FailedAttemptHandler = (error: any) => any;
|
|
4
3
|
interface AsyncCallerParams {
|
|
5
4
|
/**
|
|
@@ -41,9 +40,7 @@ declare class AsyncCaller {
|
|
|
41
40
|
protected onFailedAttempt: AsyncCallerParams["onFailedAttempt"];
|
|
42
41
|
private queue;
|
|
43
42
|
constructor(params: AsyncCallerParams);
|
|
44
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
45
43
|
call<A extends any[], T extends (...args: A) => Promise<any>>(callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
|
|
46
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
44
|
callWithOptions<A extends any[], T extends (...args: A) => Promise<any>>(options: AsyncCallerCallOptions, callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
|
|
48
45
|
fetch(...args: Parameters<typeof fetch>): ReturnType<typeof fetch>;
|
|
49
46
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
//#region src/utils/async_caller.d.ts
|
|
2
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3
2
|
type FailedAttemptHandler = (error: any) => any;
|
|
4
3
|
interface AsyncCallerParams {
|
|
5
4
|
/**
|
|
@@ -41,9 +40,7 @@ declare class AsyncCaller {
|
|
|
41
40
|
protected onFailedAttempt: AsyncCallerParams["onFailedAttempt"];
|
|
42
41
|
private queue;
|
|
43
42
|
constructor(params: AsyncCallerParams);
|
|
44
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
45
43
|
call<A extends any[], T extends (...args: A) => Promise<any>>(callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
|
|
46
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
44
|
callWithOptions<A extends any[], T extends (...args: A) => Promise<any>>(options: AsyncCallerCallOptions, callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
|
|
48
45
|
fetch(...args: Parameters<typeof fetch>): ReturnType<typeof fetch>;
|
|
49
46
|
}
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import { __export } from "../_virtual/rolldown_runtime.js";
|
|
2
|
+
import { pRetry } from "../node_modules/.pnpm/p-retry@7.1.0/node_modules/p-retry/index.js";
|
|
2
3
|
import { getAbortSignalError } from "./signal.js";
|
|
3
4
|
import PQueueMod from "p-queue";
|
|
4
5
|
|
|
5
6
|
//#region src/utils/async_caller.ts
|
|
6
7
|
var async_caller_exports = {};
|
|
7
8
|
__export(async_caller_exports, { AsyncCaller: () => AsyncCaller });
|
|
8
|
-
let pRetryModule = null;
|
|
9
|
-
async function getPRetry() {
|
|
10
|
-
if (!pRetryModule) pRetryModule = await import("p-retry");
|
|
11
|
-
return pRetryModule.default;
|
|
12
|
-
}
|
|
13
9
|
const STATUS_NO_RETRY = [
|
|
14
10
|
400,
|
|
15
11
|
401,
|
|
@@ -58,7 +54,6 @@ var AsyncCaller = class {
|
|
|
58
54
|
this.queue = new PQueue({ concurrency: this.maxConcurrency });
|
|
59
55
|
}
|
|
60
56
|
async call(callable, ...args) {
|
|
61
|
-
const pRetry = await getPRetry();
|
|
62
57
|
return this.queue.add(() => pRetry(() => callable(...args).catch((error) => {
|
|
63
58
|
if (error instanceof Error) throw error;
|
|
64
59
|
else throw new Error(error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async_caller.js","names":["
|
|
1
|
+
{"version":3,"file":"async_caller.js","names":["error: any","params: AsyncCallerParams","callable: T","options: AsyncCallerCallOptions","listener: (() => void) | undefined"],"sources":["../../src/utils/async_caller.ts"],"sourcesContent":["import PQueueMod from \"p-queue\";\nimport pRetry from \"p-retry\";\n\nimport { getAbortSignalError } from \"./signal.js\";\n\nconst STATUS_NO_RETRY = [\n 400, // Bad Request\n 401, // Unauthorized\n 402, // Payment Required\n 403, // Forbidden\n 404, // Not Found\n 405, // Method Not Allowed\n 406, // Not Acceptable\n 407, // Proxy Authentication Required\n 409, // Conflict\n];\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst defaultFailedAttemptHandler = (error: any) => {\n if (\n error.message.startsWith(\"Cancel\") ||\n error.message.startsWith(\"AbortError\") ||\n error.name === \"AbortError\"\n ) {\n throw error;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if ((error as any)?.code === \"ECONNABORTED\") {\n throw error;\n }\n const status =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (error as any)?.response?.status ?? (error as any)?.status;\n if (status && STATUS_NO_RETRY.includes(+status)) {\n throw error;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if ((error as any)?.error?.code === \"insufficient_quota\") {\n const err = new Error(error?.message);\n err.name = \"InsufficientQuotaError\";\n throw err;\n }\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type FailedAttemptHandler = (error: any) => any;\n\nexport interface AsyncCallerParams {\n /**\n * The maximum number of concurrent calls that can be made.\n * Defaults to `Infinity`, which means no limit.\n */\n maxConcurrency?: number;\n /**\n * The maximum number of retries that can be made for a single call,\n * with an exponential backoff between each attempt. Defaults to 6.\n */\n maxRetries?: number;\n /**\n * Custom handler to handle failed attempts. Takes the originally thrown\n * error object as input, and should itself throw an error if the input\n * error is not retryable.\n */\n onFailedAttempt?: FailedAttemptHandler;\n}\n\nexport interface AsyncCallerCallOptions {\n signal?: AbortSignal;\n}\n\n/**\n * A class that can be used to make async calls with concurrency and retry logic.\n *\n * This is useful for making calls to any kind of \"expensive\" external resource,\n * be it because it's rate-limited, subject to network issues, etc.\n *\n * Concurrent calls are limited by the `maxConcurrency` parameter, which defaults\n * to `Infinity`. This means that by default, all calls will be made in parallel.\n *\n * Retries are limited by the `maxRetries` parameter, which defaults to 6. This\n * means that by default, each call will be retried up to 6 times, with an\n * exponential backoff between each attempt.\n */\nexport class AsyncCaller {\n protected maxConcurrency: AsyncCallerParams[\"maxConcurrency\"];\n\n protected maxRetries: AsyncCallerParams[\"maxRetries\"];\n\n protected onFailedAttempt: AsyncCallerParams[\"onFailedAttempt\"];\n\n private queue: typeof import(\"p-queue\")[\"default\"][\"prototype\"];\n\n constructor(params: AsyncCallerParams) {\n this.maxConcurrency = params.maxConcurrency ?? Infinity;\n this.maxRetries = params.maxRetries ?? 6;\n this.onFailedAttempt =\n params.onFailedAttempt ?? defaultFailedAttemptHandler;\n\n const PQueue = (\n \"default\" in PQueueMod ? PQueueMod.default : PQueueMod\n ) as typeof PQueueMod;\n this.queue = new PQueue({ concurrency: this.maxConcurrency });\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async call<A extends any[], T extends (...args: A) => Promise<any>>(\n callable: T,\n ...args: Parameters<T>\n ): Promise<Awaited<ReturnType<T>>> {\n return this.queue.add(\n () =>\n pRetry(\n () =>\n callable(...args).catch((error) => {\n // eslint-disable-next-line no-instanceof/no-instanceof\n if (error instanceof Error) {\n throw error;\n } else {\n throw new Error(error);\n }\n }),\n {\n onFailedAttempt: ({ error }) => this.onFailedAttempt?.(error),\n retries: this.maxRetries,\n randomize: true,\n // If needed we can change some of the defaults here,\n // but they're quite sensible.\n }\n ),\n { throwOnTimeout: true }\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n callWithOptions<A extends any[], T extends (...args: A) => Promise<any>>(\n options: AsyncCallerCallOptions,\n callable: T,\n ...args: Parameters<T>\n ): Promise<Awaited<ReturnType<T>>> {\n // Note this doesn't cancel the underlying request,\n // when available prefer to use the signal option of the underlying call\n if (options.signal) {\n let listener: (() => void) | undefined;\n return Promise.race([\n this.call<A, T>(callable, ...args),\n new Promise<never>((_, reject) => {\n listener = () => {\n reject(getAbortSignalError(options.signal));\n };\n options.signal?.addEventListener(\"abort\", listener);\n }),\n ]).finally(() => {\n if (options.signal && listener) {\n options.signal.removeEventListener(\"abort\", listener);\n }\n });\n }\n return this.call<A, T>(callable, ...args);\n }\n\n fetch(...args: Parameters<typeof fetch>): ReturnType<typeof fetch> {\n return this.call(() =>\n fetch(...args).then((res) => (res.ok ? res : Promise.reject(res)))\n );\n }\n}\n"],"mappings":";;;;;;;;AAKA,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD;AAGD,MAAM,8BAA8B,CAACA,UAAe;AAClD,KACE,MAAM,QAAQ,WAAW,SAAS,IAClC,MAAM,QAAQ,WAAW,aAAa,IACtC,MAAM,SAAS,aAEf,OAAM;AAGR,KAAK,OAAe,S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AQ,OAAO,oBAAoB,SAAS,SAAS;GAExD,EAAC;EACH;AACD,SAAO,KAAK,KAAW,UAAU,GAAG,KAAK;CAC1C;CAED,MAAM,GAAG,MAA0D;AACjE,SAAO,KAAK,KAAK,MACf,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,QAAS,IAAI,KAAK,MAAM,QAAQ,OAAO,IAAI,CAAE,CACnE;CACF;AACF"}
|
package/dist/utils/env.d.cts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
//#region src/utils/env.d.ts
|
|
2
|
-
// Inlined from https://github.com/flexdinesh/browser-or-node
|
|
3
2
|
declare global {
|
|
4
3
|
const Deno: {
|
|
5
4
|
version: {
|
|
@@ -13,10 +12,7 @@ declare global {
|
|
|
13
12
|
declare const isBrowser: () => boolean;
|
|
14
13
|
declare const isWebWorker: () => boolean;
|
|
15
14
|
declare const isJsDom: () => boolean;
|
|
16
|
-
// Supabase Edge Function provides a `Deno` global object
|
|
17
|
-
// without `version` property
|
|
18
15
|
declare const isDeno: () => boolean;
|
|
19
|
-
// Mark not-as-node if in Supabase Edge Function
|
|
20
16
|
declare const isNode: () => boolean;
|
|
21
17
|
declare const getEnv: () => string;
|
|
22
18
|
type RuntimeEnvironment = {
|
package/dist/utils/env.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
//#region src/utils/env.d.ts
|
|
2
|
-
// Inlined from https://github.com/flexdinesh/browser-or-node
|
|
3
2
|
declare global {
|
|
4
3
|
const Deno: {
|
|
5
4
|
version: {
|
|
@@ -13,10 +12,7 @@ declare global {
|
|
|
13
12
|
declare const isBrowser: () => boolean;
|
|
14
13
|
declare const isWebWorker: () => boolean;
|
|
15
14
|
declare const isJsDom: () => boolean;
|
|
16
|
-
// Supabase Edge Function provides a `Deno` global object
|
|
17
|
-
// without `version` property
|
|
18
15
|
declare const isDeno: () => boolean;
|
|
19
|
-
// Mark not-as-node if in Supabase Edge Function
|
|
20
16
|
declare const isNode: () => boolean;
|
|
21
17
|
declare const getEnv: () => string;
|
|
22
18
|
type RuntimeEnvironment = {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { IterableReadableStream } from "./stream.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/utils/event_source_parse.d.ts
|
|
4
|
-
|
|
5
4
|
declare const EventStreamContentType = "text/event-stream";
|
|
6
5
|
/**
|
|
7
6
|
* Represents a message sent in an event stream
|
|
@@ -23,9 +22,7 @@ interface EventSourceMessage {
|
|
|
23
22
|
* @param onChunk A function that will be called on each new byte chunk in the stream.
|
|
24
23
|
* @returns {Promise<void>} A promise that will be resolved when the stream closes.
|
|
25
24
|
*/
|
|
26
|
-
declare function getBytes(
|
|
27
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
-
stream: ReadableStream<Uint8Array> | AsyncIterable<any>, onChunk: (arr: Uint8Array, flush?: boolean) => void): Promise<void>;
|
|
25
|
+
declare function getBytes(stream: ReadableStream<Uint8Array> | AsyncIterable<any>, onChunk: (arr: Uint8Array, flush?: boolean) => void): Promise<void>;
|
|
29
26
|
/**
|
|
30
27
|
* Parses arbitary byte chunks into EventSource line buffers.
|
|
31
28
|
* Each line should be of the format "field: value" and ends with \r, \n, or \r\n.
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { IterableReadableStream } from "./stream.js";
|
|
2
2
|
|
|
3
3
|
//#region src/utils/event_source_parse.d.ts
|
|
4
|
-
|
|
5
4
|
declare const EventStreamContentType = "text/event-stream";
|
|
6
5
|
/**
|
|
7
6
|
* Represents a message sent in an event stream
|
|
@@ -23,9 +22,7 @@ interface EventSourceMessage {
|
|
|
23
22
|
* @param onChunk A function that will be called on each new byte chunk in the stream.
|
|
24
23
|
* @returns {Promise<void>} A promise that will be resolved when the stream closes.
|
|
25
24
|
*/
|
|
26
|
-
declare function getBytes(
|
|
27
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
-
stream: ReadableStream<Uint8Array> | AsyncIterable<any>, onChunk: (arr: Uint8Array, flush?: boolean) => void): Promise<void>;
|
|
25
|
+
declare function getBytes(stream: ReadableStream<Uint8Array> | AsyncIterable<any>, onChunk: (arr: Uint8Array, flush?: boolean) => void): Promise<void>;
|
|
29
26
|
/**
|
|
30
27
|
* Parses arbitary byte chunks into EventSource line buffers.
|
|
31
28
|
* Each line should be of the format "field: value" and ends with \r, \n, or \r\n.
|
|
@@ -29,9 +29,7 @@ declare function convertToOpenAIFunction(tool: StructuredToolInterface | Runnabl
|
|
|
29
29
|
* @param {StructuredToolInterface | Record<string, any> | RunnableToolLike} tool The tool to convert to an OpenAI tool.
|
|
30
30
|
* @returns {ToolDefinition} The inputted tool in OpenAI tool format.
|
|
31
31
|
*/
|
|
32
|
-
declare function convertToOpenAITool(
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
|
-
tool: StructuredToolInterface | Record<string, any> | RunnableToolLike, fields?: {
|
|
32
|
+
declare function convertToOpenAITool(tool: StructuredToolInterface | Record<string, any> | RunnableToolLike, fields?: {
|
|
35
33
|
/**
|
|
36
34
|
* If `true`, model output is guaranteed to exactly match the JSON Schema
|
|
37
35
|
* provided in the function definition.
|
|
@@ -29,9 +29,7 @@ declare function convertToOpenAIFunction(tool: StructuredToolInterface | Runnabl
|
|
|
29
29
|
* @param {StructuredToolInterface | Record<string, any> | RunnableToolLike} tool The tool to convert to an OpenAI tool.
|
|
30
30
|
* @returns {ToolDefinition} The inputted tool in OpenAI tool format.
|
|
31
31
|
*/
|
|
32
|
-
declare function convertToOpenAITool(
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
|
-
tool: StructuredToolInterface | Record<string, any> | RunnableToolLike, fields?: {
|
|
32
|
+
declare function convertToOpenAITool(tool: StructuredToolInterface | Record<string, any> | RunnableToolLike, fields?: {
|
|
35
33
|
/**
|
|
36
34
|
* If `true`, model output is guaranteed to exactly match the JSON Schema
|
|
37
35
|
* provided in the function definition.
|
package/dist/utils/json.cjs
CHANGED
|
@@ -13,33 +13,193 @@ function parseJsonMarkdown(s, parser = parsePartialJson) {
|
|
|
13
13
|
if (closingFenceIndex !== -1) finalContent = contentAfterFence.substring(0, closingFenceIndex);
|
|
14
14
|
return parser(finalContent.trim());
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Recursive descent partial JSON parser.
|
|
18
|
+
* @param s - The string to parse.
|
|
19
|
+
* @returns The parsed value.
|
|
20
|
+
* @throws Error if the input is a malformed JSON string.
|
|
21
|
+
*/
|
|
22
|
+
function strictParsePartialJson(s) {
|
|
18
23
|
try {
|
|
19
24
|
return JSON.parse(s);
|
|
20
25
|
} catch {}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
let
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
26
|
+
const buffer = s.trim();
|
|
27
|
+
if (buffer.length === 0) throw new Error("Unexpected end of JSON input");
|
|
28
|
+
let pos = 0;
|
|
29
|
+
function skipWhitespace() {
|
|
30
|
+
while (pos < buffer.length && /\s/.test(buffer[pos])) pos += 1;
|
|
31
|
+
}
|
|
32
|
+
function parseString() {
|
|
33
|
+
if (buffer[pos] !== "\"") throw new Error(`Expected '"' at position ${pos}, got '${buffer[pos]}'`);
|
|
34
|
+
pos += 1;
|
|
35
|
+
let result = "";
|
|
36
|
+
let escaped = false;
|
|
37
|
+
while (pos < buffer.length) {
|
|
38
|
+
const char = buffer[pos];
|
|
39
|
+
if (escaped) {
|
|
40
|
+
if (char === "n") result += "\n";
|
|
41
|
+
else if (char === "t") result += " ";
|
|
42
|
+
else if (char === "r") result += "\r";
|
|
43
|
+
else if (char === "\\") result += "\\";
|
|
44
|
+
else if (char === "\"") result += "\"";
|
|
45
|
+
else if (char === "b") result += "\b";
|
|
46
|
+
else if (char === "f") result += "\f";
|
|
47
|
+
else if (char === "/") result += "/";
|
|
48
|
+
else if (char === "u") {
|
|
49
|
+
const hex = buffer.substring(pos + 1, pos + 5);
|
|
50
|
+
if (/^[0-9A-Fa-f]{0,4}$/.test(hex)) {
|
|
51
|
+
if (hex.length === 4) result += String.fromCharCode(Number.parseInt(hex, 16));
|
|
52
|
+
else result += `u${hex}`;
|
|
53
|
+
pos += hex.length;
|
|
54
|
+
} else throw new Error(`Invalid unicode escape sequence '\\u${hex}' at position ${pos}`);
|
|
55
|
+
} else throw new Error(`Invalid escape sequence '\\${char}' at position ${pos}`);
|
|
56
|
+
escaped = false;
|
|
57
|
+
} else if (char === "\\") escaped = true;
|
|
58
|
+
else if (char === "\"") {
|
|
59
|
+
pos += 1;
|
|
60
|
+
return result;
|
|
61
|
+
} else result += char;
|
|
62
|
+
pos += 1;
|
|
63
|
+
}
|
|
64
|
+
if (escaped) result += "\\";
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
function parseNumber() {
|
|
68
|
+
const start = pos;
|
|
69
|
+
let numStr = "";
|
|
70
|
+
if (buffer[pos] === "-") {
|
|
71
|
+
numStr += "-";
|
|
72
|
+
pos += 1;
|
|
73
|
+
}
|
|
74
|
+
if (pos < buffer.length && buffer[pos] === "0") {
|
|
75
|
+
numStr += "0";
|
|
76
|
+
pos += 1;
|
|
77
|
+
if (buffer[pos] >= "0" && buffer[pos] <= "9") throw new Error(`Invalid number at position ${start}`);
|
|
78
|
+
}
|
|
79
|
+
if (pos < buffer.length && buffer[pos] >= "1" && buffer[pos] <= "9") while (pos < buffer.length && buffer[pos] >= "0" && buffer[pos] <= "9") {
|
|
80
|
+
numStr += buffer[pos];
|
|
81
|
+
pos += 1;
|
|
82
|
+
}
|
|
83
|
+
if (pos < buffer.length && buffer[pos] === ".") {
|
|
84
|
+
numStr += ".";
|
|
85
|
+
pos += 1;
|
|
86
|
+
while (pos < buffer.length && buffer[pos] >= "0" && buffer[pos] <= "9") {
|
|
87
|
+
numStr += buffer[pos];
|
|
88
|
+
pos += 1;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (pos < buffer.length && (buffer[pos] === "e" || buffer[pos] === "E")) {
|
|
92
|
+
numStr += buffer[pos];
|
|
93
|
+
pos += 1;
|
|
94
|
+
if (pos < buffer.length && (buffer[pos] === "+" || buffer[pos] === "-")) {
|
|
95
|
+
numStr += buffer[pos];
|
|
96
|
+
pos += 1;
|
|
97
|
+
}
|
|
98
|
+
while (pos < buffer.length && buffer[pos] >= "0" && buffer[pos] <= "9") {
|
|
99
|
+
numStr += buffer[pos];
|
|
100
|
+
pos += 1;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (numStr === "-") return -0;
|
|
104
|
+
const num = Number.parseFloat(numStr);
|
|
105
|
+
if (Number.isNaN(num)) {
|
|
106
|
+
pos = start;
|
|
107
|
+
throw new Error(`Invalid number '${numStr}' at position ${start}`);
|
|
108
|
+
}
|
|
109
|
+
return num;
|
|
110
|
+
}
|
|
111
|
+
function parseValue() {
|
|
112
|
+
skipWhitespace();
|
|
113
|
+
if (pos >= buffer.length) throw new Error(`Unexpected end of input at position ${pos}`);
|
|
114
|
+
const char = buffer[pos];
|
|
115
|
+
if (char === "{") return parseObject();
|
|
116
|
+
if (char === "[") return parseArray();
|
|
117
|
+
if (char === "\"") return parseString();
|
|
118
|
+
if ("null".startsWith(buffer.substring(pos, pos + 4))) {
|
|
119
|
+
pos += Math.min(4, buffer.length - pos);
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
if ("true".startsWith(buffer.substring(pos, pos + 4))) {
|
|
123
|
+
pos += Math.min(4, buffer.length - pos);
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
if ("false".startsWith(buffer.substring(pos, pos + 5))) {
|
|
127
|
+
pos += Math.min(5, buffer.length - pos);
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
if (char === "-" || char >= "0" && char <= "9") return parseNumber();
|
|
131
|
+
throw new Error(`Unexpected character '${char}' at position ${pos}`);
|
|
38
132
|
}
|
|
39
|
-
|
|
40
|
-
|
|
133
|
+
function parseArray() {
|
|
134
|
+
if (buffer[pos] !== "[") throw new Error(`Expected '[' at position ${pos}, got '${buffer[pos]}'`);
|
|
135
|
+
const arr = [];
|
|
136
|
+
pos += 1;
|
|
137
|
+
skipWhitespace();
|
|
138
|
+
if (pos >= buffer.length) return arr;
|
|
139
|
+
if (buffer[pos] === "]") {
|
|
140
|
+
pos += 1;
|
|
141
|
+
return arr;
|
|
142
|
+
}
|
|
143
|
+
while (pos < buffer.length) {
|
|
144
|
+
skipWhitespace();
|
|
145
|
+
if (pos >= buffer.length) return arr;
|
|
146
|
+
arr.push(parseValue());
|
|
147
|
+
skipWhitespace();
|
|
148
|
+
if (pos >= buffer.length) return arr;
|
|
149
|
+
if (buffer[pos] === "]") {
|
|
150
|
+
pos += 1;
|
|
151
|
+
return arr;
|
|
152
|
+
} else if (buffer[pos] === ",") {
|
|
153
|
+
pos += 1;
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
throw new Error(`Expected ',' or ']' at position ${pos}, got '${buffer[pos]}'`);
|
|
157
|
+
}
|
|
158
|
+
return arr;
|
|
159
|
+
}
|
|
160
|
+
function parseObject() {
|
|
161
|
+
if (buffer[pos] !== "{") throw new Error(`Expected '{' at position ${pos}, got '${buffer[pos]}'`);
|
|
162
|
+
const obj = {};
|
|
163
|
+
pos += 1;
|
|
164
|
+
skipWhitespace();
|
|
165
|
+
if (pos >= buffer.length) return obj;
|
|
166
|
+
if (buffer[pos] === "}") {
|
|
167
|
+
pos += 1;
|
|
168
|
+
return obj;
|
|
169
|
+
}
|
|
170
|
+
while (pos < buffer.length) {
|
|
171
|
+
skipWhitespace();
|
|
172
|
+
if (pos >= buffer.length) return obj;
|
|
173
|
+
const key = parseString();
|
|
174
|
+
skipWhitespace();
|
|
175
|
+
if (pos >= buffer.length) return obj;
|
|
176
|
+
if (buffer[pos] !== ":") throw new Error(`Expected ':' at position ${pos}, got '${buffer[pos]}'`);
|
|
177
|
+
pos += 1;
|
|
178
|
+
skipWhitespace();
|
|
179
|
+
if (pos >= buffer.length) return obj;
|
|
180
|
+
obj[key] = parseValue();
|
|
181
|
+
skipWhitespace();
|
|
182
|
+
if (pos >= buffer.length) return obj;
|
|
183
|
+
if (buffer[pos] === "}") {
|
|
184
|
+
pos += 1;
|
|
185
|
+
return obj;
|
|
186
|
+
} else if (buffer[pos] === ",") {
|
|
187
|
+
pos += 1;
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
throw new Error(`Expected ',' or '}' at position ${pos}, got '${buffer[pos]}'`);
|
|
191
|
+
}
|
|
192
|
+
return obj;
|
|
193
|
+
}
|
|
194
|
+
const value = parseValue();
|
|
195
|
+
skipWhitespace();
|
|
196
|
+
if (pos < buffer.length) throw new Error(`Unexpected character '${buffer[pos]}' at position ${pos}`);
|
|
197
|
+
return value;
|
|
198
|
+
}
|
|
199
|
+
function parsePartialJson(s) {
|
|
41
200
|
try {
|
|
42
|
-
|
|
201
|
+
if (typeof s === "undefined") return null;
|
|
202
|
+
return strictParsePartialJson(s);
|
|
43
203
|
} catch {
|
|
44
204
|
return null;
|
|
45
205
|
}
|
package/dist/utils/json.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.cjs","names":["s: string"],"sources":["../../src/utils/json.ts"],"sourcesContent":["export function parseJsonMarkdown(s: string, parser = parsePartialJson) {\n // eslint-disable-next-line no-param-reassign\n s = s.trim();\n\n const firstFenceIndex = s.indexOf(\"```\");\n if (firstFenceIndex === -1) {\n return parser(s);\n }\n\n let contentAfterFence = s.substring(firstFenceIndex + 3);\n\n if (contentAfterFence.startsWith(\"json\\n\")) {\n contentAfterFence = contentAfterFence.substring(5);\n } else if (contentAfterFence.startsWith(\"json\")) {\n contentAfterFence = contentAfterFence.substring(4);\n } else if (contentAfterFence.startsWith(\"\\n\")) {\n contentAfterFence = contentAfterFence.substring(1);\n }\n\n const closingFenceIndex = contentAfterFence.indexOf(\"```\");\n let finalContent = contentAfterFence;\n if (closingFenceIndex !== -1) {\n finalContent = contentAfterFence.substring(0, closingFenceIndex);\n }\n\n return parser(finalContent.trim());\n}\n\n// Adapted from https://github.com/KillianLucas/open-interpreter/blob/main/interpreter/core/llm/utils/parse_partial_json.py\n// MIT License\nexport function parsePartialJson(s: string) {\n // If the input is undefined, return null to indicate failure.\n if (typeof s === \"undefined\") {\n return null;\n }\n\n // Attempt to parse the string as-is.\n try {\n return JSON.parse(s);\n } catch {\n // Pass\n }\n\n // Initialize variables.\n let new_s = \"\";\n const stack = [];\n let isInsideString = false;\n let escaped = false;\n\n // Process each character in the string one at a time.\n for (let char of s) {\n if (isInsideString) {\n if (char === '\"' && !escaped) {\n isInsideString = false;\n } else if (char === \"\\n\" && !escaped) {\n char = \"\\\\n\"; // Replace the newline character with the escape sequence.\n } else if (char === \"\\\\\") {\n escaped = !escaped;\n } else {\n escaped = false;\n }\n } else {\n if (char === '\"') {\n isInsideString = true;\n escaped = false;\n } else if (char === \"{\") {\n stack.push(\"}\");\n } else if (char === \"[\") {\n stack.push(\"]\");\n } else if (char === \"}\" || char === \"]\") {\n if (stack && stack[stack.length - 1] === char) {\n stack.pop();\n } else {\n // Mismatched closing character; the input is malformed.\n return null;\n }\n }\n }\n\n // Append the processed character to the new string.\n new_s += char;\n }\n\n // If we're still inside a string at the end of processing,\n // we need to close the string.\n if (isInsideString) {\n new_s += '\"';\n }\n\n // Close any remaining open structures in the reverse order that they were opened.\n for (let i = stack.length - 1; i >= 0; i -= 1) {\n new_s += stack[i];\n }\n\n // Attempt to parse the modified string as JSON.\n try {\n return JSON.parse(new_s);\n } catch {\n // If we still can't parse the string as JSON, return null to indicate failure.\n return null;\n }\n}\n"],"mappings":";;AAAA,SAAgB,kBAAkBA,GAAW,SAAS,kBAAkB;CAEt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AACF,SAAO,KAAK,MAAM,MAAM;CACzB,QAAO;AAEN,SAAO;CACR;AACF"}
|
|
1
|
+
{"version":3,"file":"json.cjs","names":["s: string","arr: unknown[]","obj: Record<string, unknown>"],"sources":["../../src/utils/json.ts"],"sourcesContent":["export function parseJsonMarkdown(s: string, parser = parsePartialJson) {\n // eslint-disable-next-line no-param-reassign\n s = s.trim();\n\n const firstFenceIndex = s.indexOf(\"```\");\n if (firstFenceIndex === -1) {\n return parser(s);\n }\n\n let contentAfterFence = s.substring(firstFenceIndex + 3);\n\n if (contentAfterFence.startsWith(\"json\\n\")) {\n contentAfterFence = contentAfterFence.substring(5);\n } else if (contentAfterFence.startsWith(\"json\")) {\n contentAfterFence = contentAfterFence.substring(4);\n } else if (contentAfterFence.startsWith(\"\\n\")) {\n contentAfterFence = contentAfterFence.substring(1);\n }\n\n const closingFenceIndex = contentAfterFence.indexOf(\"```\");\n let finalContent = contentAfterFence;\n if (closingFenceIndex !== -1) {\n finalContent = contentAfterFence.substring(0, closingFenceIndex);\n }\n\n return parser(finalContent.trim());\n}\n\n/**\n * Recursive descent partial JSON parser.\n * @param s - The string to parse.\n * @returns The parsed value.\n * @throws Error if the input is a malformed JSON string.\n */\nexport function strictParsePartialJson(s: string): unknown {\n try {\n return JSON.parse(s);\n } catch {\n // Continue to partial parsing\n }\n\n const buffer = s.trim();\n if (buffer.length === 0) throw new Error(\"Unexpected end of JSON input\");\n\n let pos = 0;\n\n function skipWhitespace(): void {\n while (pos < buffer.length && /\\s/.test(buffer[pos])) {\n pos += 1;\n }\n }\n\n function parseString(): string {\n if (buffer[pos] !== '\"') {\n throw new Error(`Expected '\"' at position ${pos}, got '${buffer[pos]}'`);\n }\n\n pos += 1;\n let result = \"\";\n let escaped = false;\n\n while (pos < buffer.length) {\n const char = buffer[pos];\n\n if (escaped) {\n if (char === \"n\") {\n result += \"\\n\";\n } else if (char === \"t\") {\n result += \"\\t\";\n } else if (char === \"r\") {\n result += \"\\r\";\n } else if (char === \"\\\\\") {\n result += \"\\\\\";\n } else if (char === '\"') {\n result += '\"';\n } else if (char === \"b\") {\n result += \"\\b\";\n } else if (char === \"f\") {\n result += \"\\f\";\n } else if (char === \"/\") {\n result += \"/\";\n } else if (char === \"u\") {\n const hex = buffer.substring(pos + 1, pos + 5);\n if (/^[0-9A-Fa-f]{0,4}$/.test(hex)) {\n if (hex.length === 4) {\n result += String.fromCharCode(Number.parseInt(hex, 16));\n } else {\n result += `u${hex}`;\n }\n\n pos += hex.length;\n } else {\n throw new Error(\n `Invalid unicode escape sequence '\\\\u${hex}' at position ${pos}`\n );\n }\n } else {\n throw new Error(\n `Invalid escape sequence '\\\\${char}' at position ${pos}`\n );\n }\n escaped = false;\n } else if (char === \"\\\\\") {\n escaped = true;\n } else if (char === '\"') {\n pos += 1;\n return result;\n } else {\n result += char;\n }\n\n pos += 1;\n }\n\n if (escaped) result += \"\\\\\";\n return result;\n }\n\n function parseNumber(): number {\n const start = pos;\n let numStr = \"\";\n\n if (buffer[pos] === \"-\") {\n numStr += \"-\";\n pos += 1;\n }\n\n if (pos < buffer.length && buffer[pos] === \"0\") {\n numStr += \"0\";\n pos += 1;\n\n if (buffer[pos] >= \"0\" && buffer[pos] <= \"9\") {\n throw new Error(`Invalid number at position ${start}`);\n }\n }\n\n if (pos < buffer.length && buffer[pos] >= \"1\" && buffer[pos] <= \"9\") {\n while (pos < buffer.length && buffer[pos] >= \"0\" && buffer[pos] <= \"9\") {\n numStr += buffer[pos];\n pos += 1;\n }\n }\n\n if (pos < buffer.length && buffer[pos] === \".\") {\n numStr += \".\";\n pos += 1;\n while (pos < buffer.length && buffer[pos] >= \"0\" && buffer[pos] <= \"9\") {\n numStr += buffer[pos];\n pos += 1;\n }\n }\n\n if (pos < buffer.length && (buffer[pos] === \"e\" || buffer[pos] === \"E\")) {\n numStr += buffer[pos];\n pos += 1;\n if (pos < buffer.length && (buffer[pos] === \"+\" || buffer[pos] === \"-\")) {\n numStr += buffer[pos];\n pos += 1;\n }\n while (pos < buffer.length && buffer[pos] >= \"0\" && buffer[pos] <= \"9\") {\n numStr += buffer[pos];\n pos += 1;\n }\n }\n\n if (numStr === \"-\") return -0;\n\n const num = Number.parseFloat(numStr);\n\n if (Number.isNaN(num)) {\n pos = start;\n throw new Error(`Invalid number '${numStr}' at position ${start}`);\n }\n\n return num;\n }\n\n function parseValue(): unknown {\n skipWhitespace();\n\n if (pos >= buffer.length) {\n throw new Error(`Unexpected end of input at position ${pos}`);\n }\n\n const char = buffer[pos];\n\n if (char === \"{\") return parseObject();\n if (char === \"[\") return parseArray();\n if (char === '\"') return parseString();\n\n if (\"null\".startsWith(buffer.substring(pos, pos + 4))) {\n pos += Math.min(4, buffer.length - pos);\n return null;\n }\n\n if (\"true\".startsWith(buffer.substring(pos, pos + 4))) {\n pos += Math.min(4, buffer.length - pos);\n return true;\n }\n\n if (\"false\".startsWith(buffer.substring(pos, pos + 5))) {\n pos += Math.min(5, buffer.length - pos);\n return false;\n }\n\n if (char === \"-\" || (char >= \"0\" && char <= \"9\")) {\n return parseNumber();\n }\n\n throw new Error(`Unexpected character '${char}' at position ${pos}`);\n }\n\n function parseArray(): unknown[] {\n if (buffer[pos] !== \"[\") {\n throw new Error(`Expected '[' at position ${pos}, got '${buffer[pos]}'`);\n }\n\n const arr: unknown[] = [];\n\n pos += 1;\n skipWhitespace();\n\n if (pos >= buffer.length) return arr;\n if (buffer[pos] === \"]\") {\n pos += 1;\n return arr;\n }\n\n while (pos < buffer.length) {\n skipWhitespace();\n if (pos >= buffer.length) return arr;\n\n arr.push(parseValue());\n\n skipWhitespace();\n if (pos >= buffer.length) return arr;\n\n if (buffer[pos] === \"]\") {\n pos += 1;\n return arr;\n } else if (buffer[pos] === \",\") {\n pos += 1;\n continue;\n }\n\n throw new Error(\n `Expected ',' or ']' at position ${pos}, got '${buffer[pos]}'`\n );\n }\n\n return arr;\n }\n\n function parseObject(): Record<string, unknown> {\n if (buffer[pos] !== \"{\") {\n throw new Error(`Expected '{' at position ${pos}, got '${buffer[pos]}'`);\n }\n\n const obj: Record<string, unknown> = {};\n pos += 1;\n skipWhitespace();\n\n if (pos >= buffer.length) return obj;\n if (buffer[pos] === \"}\") {\n pos += 1;\n return obj;\n }\n\n while (pos < buffer.length) {\n skipWhitespace();\n if (pos >= buffer.length) return obj;\n\n const key = parseString();\n\n skipWhitespace();\n if (pos >= buffer.length) return obj;\n\n if (buffer[pos] !== \":\") {\n throw new Error(\n `Expected ':' at position ${pos}, got '${buffer[pos]}'`\n );\n }\n pos += 1;\n\n skipWhitespace();\n if (pos >= buffer.length) return obj;\n\n obj[key] = parseValue();\n\n skipWhitespace();\n if (pos >= buffer.length) return obj;\n\n if (buffer[pos] === \"}\") {\n pos += 1;\n return obj;\n } else if (buffer[pos] === \",\") {\n pos += 1;\n continue;\n }\n\n throw new Error(\n `Expected ',' or '}' at position ${pos}, got '${buffer[pos]}'`\n );\n }\n\n return obj;\n }\n\n const value = parseValue();\n skipWhitespace();\n\n if (pos < buffer.length) {\n throw new Error(`Unexpected character '${buffer[pos]}' at position ${pos}`);\n }\n\n return value;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function parsePartialJson(s: string): any | null {\n // Attempt to parse the modified string as JSON.\n try {\n if (typeof s === \"undefined\") return null;\n return strictParsePartialJson(s);\n } catch {\n // If we still can't parse the string as JSON, return null to indicate failure.\n return null;\n }\n}\n"],"mappings":";;AAAA,SAAgB,kBAAkBA,GAAW,SAAS,kBAAkB;CAEtE,IAAI,EAAE,MAAM;CAEZ,MAAM,kBAAkB,EAAE,QAAQ,MAAM;AACxC,KAAI,oBAAoB,GACtB,QAAO,OAAO,EAAE;CAGlB,IAAI,oBAAoB,EAAE,UAAU,kBAAkB,EAAE;AAExD,KAAI,kBAAkB,WAAW,SAAS,EACxC,oBAAoB,kBAAkB,UAAU,EAAE;UACzC,kBAAkB,WAAW,OAAO,EAC7C,oBAAoB,kBAAkB,UAAU,EAAE;UACzC,kBAAkB,WAAW,KAAK,EA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AC;EAEjE;AAED,SAAO;CACR;CAED,MAAM,QAAQ,YAAY;CAC1B,gBAAgB;AAEhB,KAAI,MAAM,OAAO,OACf,OAAM,IAAI,MAAM,CAAC,sBAAsB,EAAE,OAAO,KAAK,cAAc,EAAE,KAAK;AAG5E,QAAO;AACR;AAGD,SAAgB,iBAAiBF,GAAuB;AAEtD,KAAI;AACF,MAAI,OAAO,MAAM,YAAa,QAAO;AACrC,SAAO,uBAAuB,EAAE;CACjC,QAAO;AAEN,SAAO;CACR;AACF"}
|
package/dist/utils/json.d.cts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
//#region src/utils/json.d.ts
|
|
2
2
|
declare function parseJsonMarkdown(s: string, parser?: typeof parsePartialJson): any;
|
|
3
|
-
|
|
4
|
-
// MIT License
|
|
5
|
-
declare function parsePartialJson(s: string): any;
|
|
3
|
+
declare function parsePartialJson(s: string): any | null;
|
|
6
4
|
//#endregion
|
|
7
5
|
export { parseJsonMarkdown, parsePartialJson };
|
|
8
6
|
//# sourceMappingURL=json.d.cts.map
|
package/dist/utils/json.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
//#region src/utils/json.d.ts
|
|
2
2
|
declare function parseJsonMarkdown(s: string, parser?: typeof parsePartialJson): any;
|
|
3
|
-
|
|
4
|
-
// MIT License
|
|
5
|
-
declare function parsePartialJson(s: string): any;
|
|
3
|
+
declare function parsePartialJson(s: string): any | null;
|
|
6
4
|
//#endregion
|
|
7
5
|
export { parseJsonMarkdown, parsePartialJson };
|
|
8
6
|
//# sourceMappingURL=json.d.ts.map
|