@better-agent/core 0.1.0-beta.1
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/README.md +3 -0
- package/dist/agent/constants.mjs +6 -0
- package/dist/agent/constants.mjs.map +1 -0
- package/dist/agent/define-agent.d.mts +29 -0
- package/dist/agent/define-agent.d.mts.map +1 -0
- package/dist/agent/define-agent.mjs +27 -0
- package/dist/agent/define-agent.mjs.map +1 -0
- package/dist/agent/index.d.mts +2 -0
- package/dist/agent/types.d.mts +216 -0
- package/dist/agent/types.d.mts.map +1 -0
- package/dist/agent/validation.mjs +64 -0
- package/dist/agent/validation.mjs.map +1 -0
- package/dist/api.d.mts +8 -0
- package/dist/api.d.mts.map +1 -0
- package/dist/api.mjs +63 -0
- package/dist/api.mjs.map +1 -0
- package/dist/app/config.mjs +43 -0
- package/dist/app/config.mjs.map +1 -0
- package/dist/app/create-app.d.mts +36 -0
- package/dist/app/create-app.d.mts.map +1 -0
- package/dist/app/create-app.mjs +132 -0
- package/dist/app/create-app.mjs.map +1 -0
- package/dist/app/registry.mjs +43 -0
- package/dist/app/registry.mjs.map +1 -0
- package/dist/app/types.d.mts +142 -0
- package/dist/app/types.d.mts.map +1 -0
- package/dist/events/constants.d.mts +49 -0
- package/dist/events/constants.d.mts.map +1 -0
- package/dist/events/constants.mjs +46 -0
- package/dist/events/constants.mjs.map +1 -0
- package/dist/events/index.d.mts +4 -0
- package/dist/events/index.mjs +3 -0
- package/dist/events/types.d.mts +289 -0
- package/dist/events/types.d.mts.map +1 -0
- package/dist/index.d.mts +23 -0
- package/dist/index.mjs +14 -0
- package/dist/internal/id.mjs +21 -0
- package/dist/internal/id.mjs.map +1 -0
- package/dist/internal/types.d.mts +11 -0
- package/dist/internal/types.d.mts.map +1 -0
- package/dist/mcp/error/mcp-client-error.d.mts +36 -0
- package/dist/mcp/error/mcp-client-error.d.mts.map +1 -0
- package/dist/mcp/error/mcp-client-error.mjs +33 -0
- package/dist/mcp/error/mcp-client-error.mjs.map +1 -0
- package/dist/mcp/index.d.mts +8 -0
- package/dist/mcp/index.mjs +9 -0
- package/dist/mcp/tool/json-rpc-message.d.mts +50 -0
- package/dist/mcp/tool/json-rpc-message.d.mts.map +1 -0
- package/dist/mcp/tool/json-rpc-message.mjs +84 -0
- package/dist/mcp/tool/json-rpc-message.mjs.map +1 -0
- package/dist/mcp/tool/mcp-client.d.mts +71 -0
- package/dist/mcp/tool/mcp-client.d.mts.map +1 -0
- package/dist/mcp/tool/mcp-client.mjs +304 -0
- package/dist/mcp/tool/mcp-client.mjs.map +1 -0
- package/dist/mcp/tool/mcp-http-transport.d.mts +62 -0
- package/dist/mcp/tool/mcp-http-transport.d.mts.map +1 -0
- package/dist/mcp/tool/mcp-http-transport.mjs +307 -0
- package/dist/mcp/tool/mcp-http-transport.mjs.map +1 -0
- package/dist/mcp/tool/mcp-tools.d.mts +20 -0
- package/dist/mcp/tool/mcp-tools.d.mts.map +1 -0
- package/dist/mcp/tool/mcp-tools.mjs +73 -0
- package/dist/mcp/tool/mcp-tools.mjs.map +1 -0
- package/dist/mcp/tool/mcp-transport.d.mts +81 -0
- package/dist/mcp/tool/mcp-transport.d.mts.map +1 -0
- package/dist/mcp/tool/mcp-transport.mjs +11 -0
- package/dist/mcp/tool/mcp-transport.mjs.map +1 -0
- package/dist/mcp/tool/types.d.mts +230 -0
- package/dist/mcp/tool/types.d.mts.map +1 -0
- package/dist/mcp/tool/types.mjs +19 -0
- package/dist/mcp/tool/types.mjs.map +1 -0
- package/dist/persistence/index.d.mts +3 -0
- package/dist/persistence/index.mjs +3 -0
- package/dist/persistence/memory.d.mts +21 -0
- package/dist/persistence/memory.d.mts.map +1 -0
- package/dist/persistence/memory.mjs +107 -0
- package/dist/persistence/memory.mjs.map +1 -0
- package/dist/persistence/types.d.mts +124 -0
- package/dist/persistence/types.d.mts.map +1 -0
- package/dist/plugins/index.d.mts +2 -0
- package/dist/plugins/runtime.d.mts +17 -0
- package/dist/plugins/runtime.d.mts.map +1 -0
- package/dist/plugins/runtime.mjs +456 -0
- package/dist/plugins/runtime.mjs.map +1 -0
- package/dist/plugins/types.d.mts +344 -0
- package/dist/plugins/types.d.mts.map +1 -0
- package/dist/providers/index.d.mts +9 -0
- package/dist/providers/index.mjs +0 -0
- package/dist/providers/types/capabilities.d.mts +153 -0
- package/dist/providers/types/capabilities.d.mts.map +1 -0
- package/dist/providers/types/content.d.mts +125 -0
- package/dist/providers/types/content.d.mts.map +1 -0
- package/dist/providers/types/conversation.d.mts +32 -0
- package/dist/providers/types/conversation.d.mts.map +1 -0
- package/dist/providers/types/index.d.mts +8 -0
- package/dist/providers/types/input.d.mts +74 -0
- package/dist/providers/types/input.d.mts.map +1 -0
- package/dist/providers/types/model.d.mts +68 -0
- package/dist/providers/types/model.d.mts.map +1 -0
- package/dist/providers/types/output.d.mts +29 -0
- package/dist/providers/types/output.d.mts.map +1 -0
- package/dist/providers/types/response.d.mts +35 -0
- package/dist/providers/types/response.d.mts.map +1 -0
- package/dist/providers/types/tool-calls.d.mts +51 -0
- package/dist/providers/types/tool-calls.d.mts.map +1 -0
- package/dist/run/agent-loop.mjs +231 -0
- package/dist/run/agent-loop.mjs.map +1 -0
- package/dist/run/event-queue.mjs +67 -0
- package/dist/run/event-queue.mjs.map +1 -0
- package/dist/run/execute-tool-calls.mjs +550 -0
- package/dist/run/execute-tool-calls.mjs.map +1 -0
- package/dist/run/execution.mjs +93 -0
- package/dist/run/execution.mjs.map +1 -0
- package/dist/run/helpers.mjs +466 -0
- package/dist/run/helpers.mjs.map +1 -0
- package/dist/run/hooks.mjs +124 -0
- package/dist/run/hooks.mjs.map +1 -0
- package/dist/run/index.d.mts +4 -0
- package/dist/run/messages.d.mts +8 -0
- package/dist/run/messages.d.mts.map +1 -0
- package/dist/run/messages.mjs +83 -0
- package/dist/run/messages.mjs.map +1 -0
- package/dist/run/model-strategy.mjs +105 -0
- package/dist/run/model-strategy.mjs.map +1 -0
- package/dist/run/output-errors.d.mts +75 -0
- package/dist/run/output-errors.d.mts.map +1 -0
- package/dist/run/pending-tools.d.mts +1 -0
- package/dist/run/pending-tools.mjs +185 -0
- package/dist/run/pending-tools.mjs.map +1 -0
- package/dist/run/registry.mjs +22 -0
- package/dist/run/registry.mjs.map +1 -0
- package/dist/run/runtime.d.mts +19 -0
- package/dist/run/runtime.d.mts.map +1 -0
- package/dist/run/runtime.mjs +491 -0
- package/dist/run/runtime.mjs.map +1 -0
- package/dist/run/stop-conditions.mjs +41 -0
- package/dist/run/stop-conditions.mjs.map +1 -0
- package/dist/run/types.d.mts +348 -0
- package/dist/run/types.d.mts.map +1 -0
- package/dist/schema/index.d.mts +2 -0
- package/dist/schema/resolve-json-schema.d.mts +12 -0
- package/dist/schema/resolve-json-schema.d.mts.map +1 -0
- package/dist/schema/resolve-json-schema.mjs +167 -0
- package/dist/schema/resolve-json-schema.mjs.map +1 -0
- package/dist/schema/types.d.mts +27 -0
- package/dist/schema/types.d.mts.map +1 -0
- package/dist/server/create-server.d.mts +21 -0
- package/dist/server/create-server.d.mts.map +1 -0
- package/dist/server/create-server.mjs +107 -0
- package/dist/server/create-server.mjs.map +1 -0
- package/dist/server/http.mjs +182 -0
- package/dist/server/http.mjs.map +1 -0
- package/dist/server/index.d.mts +3 -0
- package/dist/server/index.mjs +3 -0
- package/dist/server/routes.mjs +399 -0
- package/dist/server/routes.mjs.map +1 -0
- package/dist/server/types.d.mts +31 -0
- package/dist/server/types.d.mts.map +1 -0
- package/dist/tools/constants.d.mts +12 -0
- package/dist/tools/constants.d.mts.map +1 -0
- package/dist/tools/constants.mjs +13 -0
- package/dist/tools/constants.mjs.map +1 -0
- package/dist/tools/define-tool.d.mts +25 -0
- package/dist/tools/define-tool.d.mts.map +1 -0
- package/dist/tools/define-tool.mjs +76 -0
- package/dist/tools/define-tool.mjs.map +1 -0
- package/dist/tools/index.d.mts +5 -0
- package/dist/tools/lazy-tools.d.mts +49 -0
- package/dist/tools/lazy-tools.d.mts.map +1 -0
- package/dist/tools/lazy-tools.mjs +87 -0
- package/dist/tools/lazy-tools.mjs.map +1 -0
- package/dist/tools/resolve-tools.d.mts +12 -0
- package/dist/tools/resolve-tools.d.mts.map +1 -0
- package/dist/tools/resolve-tools.mjs +86 -0
- package/dist/tools/resolve-tools.mjs.map +1 -0
- package/dist/tools/types.d.mts +318 -0
- package/dist/tools/types.d.mts.map +1 -0
- package/dist/tools/validation.mjs +23 -0
- package/dist/tools/validation.mjs.map +1 -0
- package/package.json +72 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.mjs","names":[],"sources":["../../src/run/runtime.ts"],"sourcesContent":["import { BetterAgentError } from \"@better-agent/shared/errors\";\nimport { logger } from \"@better-agent/shared/logger\";\nimport type { AnyAgentDefinition } from \"../agent\";\nimport { type Event, Events } from \"../events\";\nimport type { ConversationRuntimeStateStore, ConversationStore, StreamStore } from \"../persistence\";\nimport type { PluginRuntime } from \"../plugins\";\nimport type { ConversationItem, OutputSchemaDefinition } from \"../providers\";\nimport { type AsyncEventQueue, createAsyncEventQueue } from \"./event-queue\";\nimport { executeRun } from \"./execution\";\nimport {\n createStreamPersistenceEmitter,\n generateId,\n loadConversationMessages,\n saveConversationMessages,\n toEventEmitter,\n validateAgentContext,\n validateStoredConversationItems,\n} from \"./helpers\";\nimport { createPendingToolRuntime } from \"./pending-tools\";\nimport { createAgentRegistry, resolveAgentFromRegistry } from \"./registry\";\nimport type {\n BetterAgentRuntime,\n ContextBoundAgent,\n ResumeConversationOptions,\n RunAdvancedOptions,\n RunOptions,\n RunResult,\n StreamResult,\n SubmitToolApprovalParams,\n SubmitToolResultParams,\n} from \"./types\";\n\n/** Creates a runtime for registered agents. */\nexport function createRuntime<const TAgents extends readonly AnyAgentDefinition[]>(options: {\n agents: TAgents;\n pluginRuntime?: PluginRuntime | null;\n stream?: StreamStore;\n conversations?: ConversationStore;\n runtimeState?: ConversationRuntimeStateStore;\n streamLifecycle?: \"request_bound\" | \"detached\";\n advanced?: RunAdvancedOptions;\n}): BetterAgentRuntime<TAgents> {\n const agents = createAgentRegistry(options.agents);\n const pluginRuntime = options.pluginRuntime ?? null;\n const pendingToolRuntime = createPendingToolRuntime();\n const streamLifecycle = options.streamLifecycle ?? \"request_bound\";\n const activeRuns = new Map<string, AbortController>();\n\n const resolveConversationReplay = (\n agent: AnyAgentDefinition,\n runReplay: RunOptions<unknown>[\"conversationReplay\"],\n ): RunOptions<unknown>[\"conversationReplay\"] => {\n const agentReplay = agent.conversationReplay;\n if (!agentReplay && !runReplay) {\n return undefined;\n }\n\n const merged = {\n ...(agentReplay ?? {}),\n ...(runReplay ?? {}),\n };\n\n if (\n runReplay &&\n Object.prototype.hasOwnProperty.call(runReplay, \"prepareInput\") &&\n runReplay.prepareInput === null\n ) {\n merged.prepareInput = undefined;\n }\n\n return merged;\n };\n\n const warnIgnoredConversationReplay = (params: {\n agent: AnyAgentDefinition;\n conversationReplay: RunOptions<unknown>[\"conversationReplay\"];\n }) => {\n if (!params.conversationReplay) {\n return;\n }\n\n const replayMode =\n params.agent.model.caps.replayMode ??\n (params.agent.model.caps.inputShape === \"prompt\"\n ? \"single_turn_persistent\"\n : \"multi_turn\");\n\n if (replayMode === \"multi_turn\") {\n return;\n }\n\n logger.warn(\n `conversationReplay was provided for agent '${params.agent.name}', but model replayMode is '${replayMode}', so stored history replay customization was skipped.`,\n );\n };\n\n const buildPersistence = <TContext>(\n persistence?: RunOptions<TContext>[\"persistence\"],\n defaults?: {\n stream?: StreamStore;\n conversations?: ConversationStore;\n runtimeState?: ConversationRuntimeStateStore;\n },\n ) => {\n const resolved = {\n stream: persistence?.stream ?? defaults?.stream,\n conversations: persistence?.conversations ?? defaults?.conversations,\n runtimeState: persistence?.runtimeState ?? defaults?.runtimeState,\n };\n\n return resolved.stream || resolved.conversations || resolved.runtimeState\n ? resolved\n : undefined;\n };\n\n const createPluginEventContext = (params: {\n runId: string;\n agentName: string;\n conversationId?: string;\n abortController: AbortController;\n }) => ({\n runId: params.runId,\n agentName: params.agentName,\n conversationId: params.conversationId,\n control: {\n abortRun: async () => {\n params.abortController.abort();\n },\n },\n });\n\n const createLiveEmitter = (params: {\n runId: string;\n agentName: string;\n conversationId?: string;\n abortController: AbortController;\n persistenceEmit?: (event: Event) => Promise<void>;\n queuePush?: (event: Event) => Promise<void>;\n onEvent?: RunOptions<unknown>[\"onEvent\"];\n }) => {\n const userEmit = toEventEmitter(params.onEvent);\n\n return async (event: Event) => {\n const pluginEventContext = createPluginEventContext({\n runId: params.runId,\n agentName: params.agentName,\n abortController: params.abortController,\n conversationId: params.conversationId,\n });\n\n const transformed =\n pluginRuntime?.hasEventMiddleware === true\n ? await pluginRuntime.dispatchEvent(event, pluginEventContext)\n : event;\n\n if (!transformed) {\n return;\n }\n\n if (params.persistenceEmit) {\n await params.persistenceEmit(transformed);\n }\n\n if (pluginRuntime?.hasOnEvent) {\n await pluginRuntime.dispatchOnEvent(transformed, pluginEventContext);\n }\n\n if (params.queuePush) {\n await params.queuePush(transformed);\n }\n\n await userEmit(transformed);\n };\n };\n\n const wrapRuntimeError = (params: {\n error: unknown;\n message: string;\n traceAt: string;\n isAbort?: boolean;\n }) =>\n BetterAgentError.wrap({\n err: params.error,\n message: params.message,\n opts: {\n code: params.isAbort\n ? \"ABORTED\"\n : params.error instanceof BetterAgentError\n ? params.error.code\n : \"INTERNAL\",\n trace: [{ at: params.traceAt }],\n },\n });\n\n const emitSafely = async (emit: (event: Event) => Promise<void>, event: Event) => {\n try {\n await emit(event);\n } catch (error) {\n logger.error(\"Failed to emit runtime event.\", error);\n }\n };\n\n const closeStreamSafely = async (streamStore: StreamStore | undefined, runId: string) => {\n if (!streamStore) {\n return;\n }\n\n try {\n await streamStore.close(runId);\n } catch (error) {\n logger.error(`Failed to close stream '${runId}'.`, error);\n }\n };\n\n const createRuntimeExecutionContext = (params: {\n resolvedAgent: AnyAgentDefinition;\n conversationId?: string;\n onEvent?: RunOptions<unknown>[\"onEvent\"];\n externalSignal?: AbortSignal;\n streamStore?: StreamStore;\n queue?: AsyncEventQueue<Event>;\n queueSignal?: AbortSignal;\n detachFromExternalAbort?: boolean;\n }) => {\n const runId = generateId(\"run\");\n const abortController = new AbortController();\n activeRuns.set(runId, abortController);\n const signalController = new AbortController();\n const abortFromSignal = (signal: AbortSignal) => {\n if (!signalController.signal.aborted) {\n signalController.abort(signal.reason);\n }\n };\n const onInternalAbort = () => abortFromSignal(abortController.signal);\n const onExternalAbort = () => {\n if (params.externalSignal) {\n abortFromSignal(params.externalSignal);\n }\n };\n const signal = signalController.signal;\n const persistenceEmit = params.streamStore\n ? createStreamPersistenceEmitter({\n stream: params.streamStore,\n streamId: runId,\n })\n : undefined;\n const emit = createLiveEmitter({\n runId,\n agentName: params.resolvedAgent.name,\n abortController,\n conversationId: params.conversationId,\n persistenceEmit,\n queuePush: params.queue\n ? async (event) => {\n if (!params.queueSignal?.aborted) {\n params.queue?.push(event);\n }\n }\n : undefined,\n onEvent: params.onEvent,\n });\n\n abortController.signal.addEventListener(\"abort\", onInternalAbort, { once: true });\n if (params.externalSignal && !params.detachFromExternalAbort) {\n if (params.externalSignal.aborted) {\n abortFromSignal(params.externalSignal);\n } else {\n params.externalSignal.addEventListener(\"abort\", onExternalAbort, { once: true });\n }\n }\n\n if (params.queue && params.queueSignal) {\n const closeQueueOnAbort = () => params.queue?.close();\n if (params.queueSignal.aborted) {\n closeQueueOnAbort();\n } else {\n params.queueSignal.addEventListener(\"abort\", closeQueueOnAbort, { once: true });\n }\n }\n\n return {\n runId,\n signal,\n emit,\n cleanupSignal() {\n abortController.signal.removeEventListener(\"abort\", onInternalAbort);\n params.externalSignal?.removeEventListener(\"abort\", onExternalAbort);\n },\n };\n };\n\n const completeRunSuccess = async <TResult>(params: {\n runId: string;\n resolvedAgent: AnyAgentDefinition;\n conversationId?: string;\n emit: (event: Event) => Promise<void>;\n result: RunResult & { items: ConversationItem[] };\n saveConversationParams?: Omit<Parameters<typeof saveConversationMessages>[0], \"result\">;\n streamStore?: StreamStore;\n runtimeState?: ConversationRuntimeStateStore;\n queue?: AsyncEventQueue<Event>;\n success: (result: RunResult) => TResult;\n }) => {\n const itemsToSave =\n pluginRuntime?.hasOnBeforeSave === true\n ? await pluginRuntime.applyBeforeSave({\n runId: params.runId,\n agentName: params.resolvedAgent.name,\n items: params.result.items,\n conversationId: params.conversationId,\n })\n : params.result.items;\n\n if (params.saveConversationParams) {\n await saveConversationMessages({\n ...params.saveConversationParams,\n result: { ...params.result, items: itemsToSave },\n });\n }\n\n const publicResult = {\n response: params.result.response,\n structured: params.result.structured,\n };\n await params.emit({\n type: Events.RUN_FINISHED,\n runId: params.runId,\n agentName: params.resolvedAgent.name,\n result: publicResult,\n timestamp: Date.now(),\n conversationId: params.conversationId,\n });\n\n activeRuns.delete(params.runId);\n if (params.runtimeState && params.conversationId !== undefined) {\n await params.runtimeState.clear({\n conversationId: params.conversationId,\n agentName: params.resolvedAgent.name,\n });\n }\n await closeStreamSafely(params.streamStore, params.runId);\n params.queue?.close();\n pendingToolRuntime.clearRun(params.runId, \"Run finished\");\n return params.success(publicResult);\n };\n\n const handleRunFailure = async (params: {\n error: unknown;\n signal: AbortSignal;\n traceAt: string;\n emit: (event: Event) => Promise<void>;\n runId: string;\n resolvedAgent: AnyAgentDefinition;\n conversationId?: string;\n streamStore?: StreamStore;\n runtimeState?: ConversationRuntimeStateStore;\n queue?: AsyncEventQueue<Event>;\n }): Promise<never> => {\n const isAbort =\n params.signal.aborted ||\n (params.error instanceof BetterAgentError && params.error.code === \"ABORTED\");\n\n const wrapped = wrapRuntimeError({\n error: params.error,\n message: \"Run failed\",\n traceAt: params.traceAt,\n isAbort,\n });\n\n if (isAbort) {\n await emitSafely(params.emit, {\n type: Events.RUN_ABORTED,\n runId: params.runId,\n agentName: params.resolvedAgent.name,\n timestamp: Date.now(),\n conversationId: params.conversationId,\n });\n } else {\n await emitSafely(params.emit, {\n type: Events.RUN_ERROR,\n runId: params.runId,\n agentName: params.resolvedAgent.name,\n error: wrapped,\n timestamp: Date.now(),\n conversationId: params.conversationId,\n });\n }\n\n activeRuns.delete(params.runId);\n if (params.runtimeState && params.conversationId !== undefined) {\n await params.runtimeState.clear({\n conversationId: params.conversationId,\n agentName: params.resolvedAgent.name,\n });\n }\n await closeStreamSafely(params.streamStore, params.runId);\n params.queue?.fail(wrapped);\n pendingToolRuntime.clearRun(params.runId, wrapped.message);\n throw wrapped;\n };\n\n return {\n streamLifecycle,\n run: (async <TContext, TOutput extends OutputSchemaDefinition | undefined = undefined>(\n agent: TAgents[number][\"name\"],\n runOptions: RunOptions<TContext, TOutput>,\n ): Promise<RunResult> => {\n const resolvedAgent = resolveAgentFromRegistry(\n agents,\n agent,\n \"core.run.createRuntime.run\",\n ) as ContextBoundAgent<TContext>;\n if (\n runOptions.conversationId !== undefined &&\n runOptions.conversationId.trim().length === 0\n ) {\n throw BetterAgentError.fromCode(\n \"VALIDATION_FAILED\",\n \"conversationId must be a non-empty string.\",\n {\n context: { conversationId: runOptions.conversationId },\n trace: [{ at: \"core.run.createRuntime.run.validateConversationId\" }],\n },\n );\n }\n\n const execution = createRuntimeExecutionContext({\n resolvedAgent,\n conversationId: runOptions.conversationId,\n onEvent: runOptions.onEvent,\n externalSignal: runOptions.signal,\n });\n\n const resolvedPersistence = buildPersistence(runOptions.persistence, {\n stream: options.stream,\n conversations: options.conversations,\n runtimeState: options.runtimeState,\n });\n\n try {\n const effectiveConversationReplay = resolveConversationReplay(\n resolvedAgent,\n runOptions.conversationReplay,\n );\n warnIgnoredConversationReplay({\n agent: resolvedAgent,\n conversationReplay: effectiveConversationReplay,\n });\n const validatedContext = await validateAgentContext(\n resolvedAgent,\n runOptions.context,\n );\n const runPersistence = runOptions.persistence;\n const resolvedConversations =\n runPersistence?.conversations ?? options.conversations;\n const conversationInput = await loadConversationMessages({\n input: runOptions.input,\n caps: resolvedAgent.model.caps,\n agentName: resolvedAgent.name,\n replaceHistory: runOptions.replaceHistory,\n conversationReplay: effectiveConversationReplay,\n conversations: resolvedConversations,\n conversationId: runOptions.conversationId,\n });\n\n await execution.emit({\n type: Events.RUN_STARTED,\n runId: execution.runId,\n agentName: resolvedAgent.name,\n runInput: {\n input: runOptions.input,\n context: validatedContext,\n },\n timestamp: Date.now(),\n conversationId: runOptions.conversationId,\n });\n\n if (execution.signal.aborted) {\n throw BetterAgentError.fromCode(\"ABORTED\", \"Run aborted before it started\", {\n context: { runId: execution.runId, agentName: resolvedAgent.name },\n trace: [{ at: \"core.run.createRuntime.run.abortedBeforeStart\" }],\n });\n }\n\n const result = await executeRun({\n agent: resolvedAgent,\n options: {\n ...runOptions,\n input: conversationInput.input,\n initialItems: conversationInput.items,\n replayStartIndex: conversationInput.replayStartIndex,\n conversationReplayActive: conversationInput.conversationReplayActive,\n conversationReplay: effectiveConversationReplay,\n context: validatedContext,\n runId: execution.runId,\n signal: execution.signal,\n emit: execution.emit,\n generateMessageId: () => generateId(\"message\"),\n mode: \"run\",\n advancedDefaults: options.advanced,\n persistence: resolvedPersistence,\n pendingToolRuntime,\n pluginRuntime,\n },\n });\n\n return await completeRunSuccess({\n runId: execution.runId,\n resolvedAgent,\n emit: execution.emit,\n result,\n saveConversationParams: {\n agentName: resolvedAgent.name,\n loaded: conversationInput.loaded,\n conversations: resolvedConversations,\n conversationId: runOptions.conversationId,\n },\n runtimeState: resolvedPersistence?.runtimeState,\n conversationId: runOptions.conversationId,\n success: (publicResult) => publicResult,\n });\n } catch (error) {\n return await handleRunFailure({\n error,\n signal: execution.signal,\n traceAt: \"core.run.createRuntime.run\",\n emit: execution.emit,\n runId: execution.runId,\n resolvedAgent,\n conversationId: runOptions.conversationId,\n runtimeState: resolvedPersistence?.runtimeState,\n });\n } finally {\n execution.cleanupSignal();\n }\n }) as unknown as BetterAgentRuntime<TAgents>[\"run\"],\n\n stream: (<TContext, TOutput extends OutputSchemaDefinition | undefined = undefined>(\n agent: TAgents[number][\"name\"],\n runOptions: RunOptions<TContext, TOutput>,\n ): StreamResult => {\n const resolvedAgent = resolveAgentFromRegistry(\n agents,\n agent,\n \"core.run.createRuntime.stream\",\n ) as ContextBoundAgent<TContext>;\n if (\n runOptions.conversationId !== undefined &&\n runOptions.conversationId.trim().length === 0\n ) {\n throw BetterAgentError.fromCode(\n \"VALIDATION_FAILED\",\n \"conversationId must be a non-empty string.\",\n {\n context: { conversationId: runOptions.conversationId },\n trace: [{ at: \"core.run.createRuntime.stream.validateConversationId\" }],\n },\n );\n }\n\n const queue = createAsyncEventQueue<Event>();\n const runPersistence = runOptions.persistence;\n const streamStore = runPersistence?.stream ?? options.stream;\n const execution = createRuntimeExecutionContext({\n resolvedAgent,\n conversationId: runOptions.conversationId,\n onEvent: runOptions.onEvent,\n externalSignal: runOptions.signal,\n detachFromExternalAbort: streamLifecycle === \"detached\",\n queueSignal: streamLifecycle === \"detached\" ? runOptions.signal : undefined,\n streamStore,\n queue,\n });\n\n const resolvedPersistence = buildPersistence(runPersistence, {\n stream: streamStore,\n conversations: options.conversations,\n runtimeState: options.runtimeState,\n });\n\n const result = (async (): Promise<RunResult> => {\n try {\n const effectiveConversationReplay = resolveConversationReplay(\n resolvedAgent,\n runOptions.conversationReplay,\n );\n warnIgnoredConversationReplay({\n agent: resolvedAgent,\n conversationReplay: effectiveConversationReplay,\n });\n const validatedContext = await validateAgentContext(\n resolvedAgent,\n runOptions.context,\n );\n const resolvedConversations =\n runPersistence?.conversations ?? options.conversations;\n const conversationInput = await loadConversationMessages({\n input: runOptions.input,\n caps: resolvedAgent.model.caps,\n agentName: resolvedAgent.name,\n replaceHistory: runOptions.replaceHistory,\n conversationReplay: effectiveConversationReplay,\n conversations: resolvedConversations,\n conversationId: runOptions.conversationId,\n });\n\n if (streamStore) {\n await streamStore.open(execution.runId, { runId: execution.runId });\n }\n\n if (\n resolvedPersistence?.runtimeState &&\n runOptions.conversationId !== undefined\n ) {\n await resolvedPersistence.runtimeState.set({\n conversationId: runOptions.conversationId,\n agentName: resolvedAgent.name,\n status: \"running\",\n updatedAt: Date.now(),\n activeRunId: execution.runId,\n activeStreamId: streamStore ? execution.runId : undefined,\n });\n }\n\n await execution.emit({\n type: Events.RUN_STARTED,\n runId: execution.runId,\n agentName: resolvedAgent.name,\n runInput: {\n input: runOptions.input,\n context: validatedContext,\n },\n timestamp: Date.now(),\n conversationId: runOptions.conversationId,\n });\n\n if (execution.signal.aborted) {\n throw BetterAgentError.fromCode(\n \"ABORTED\",\n \"Run aborted before it started\",\n {\n context: { runId: execution.runId, agentName: resolvedAgent.name },\n trace: [{ at: \"core.run.createRuntime.stream.abortedBeforeStart\" }],\n },\n );\n }\n\n const runResult = await executeRun({\n agent: resolvedAgent,\n options: {\n ...runOptions,\n input: conversationInput.input,\n initialItems: conversationInput.items,\n replayStartIndex: conversationInput.replayStartIndex,\n conversationReplayActive: conversationInput.conversationReplayActive,\n conversationReplay: effectiveConversationReplay,\n context: validatedContext,\n runId: execution.runId,\n signal: execution.signal,\n emit: execution.emit,\n generateMessageId: () => generateId(\"message\"),\n mode: \"stream\",\n advancedDefaults: options.advanced,\n persistence: resolvedPersistence,\n pendingToolRuntime,\n pluginRuntime,\n },\n });\n\n return await completeRunSuccess({\n runId: execution.runId,\n resolvedAgent,\n emit: execution.emit,\n result: runResult,\n streamStore,\n queue,\n saveConversationParams: {\n agentName: resolvedAgent.name,\n loaded: conversationInput.loaded,\n conversations: resolvedConversations,\n conversationId: runOptions.conversationId,\n },\n runtimeState: resolvedPersistence?.runtimeState,\n conversationId: runOptions.conversationId,\n success: (publicResult) => publicResult,\n });\n } catch (error) {\n return await handleRunFailure({\n error,\n signal: execution.signal,\n traceAt: \"core.run.createRuntime.stream\",\n emit: execution.emit,\n runId: execution.runId,\n resolvedAgent,\n conversationId: runOptions.conversationId,\n streamStore,\n runtimeState: resolvedPersistence?.runtimeState,\n queue,\n });\n } finally {\n execution.cleanupSignal();\n }\n })();\n\n void result.catch(() => {});\n\n return {\n runId: execution.runId,\n events: queue.iterate(),\n result,\n };\n }) as unknown as BetterAgentRuntime<TAgents>[\"stream\"],\n\n loadConversation: async <TName extends TAgents[number][\"name\"]>(\n agent: TName,\n conversationId: string,\n ) => {\n if (conversationId.trim().length === 0) {\n throw BetterAgentError.fromCode(\n \"VALIDATION_FAILED\",\n \"conversationId must be a non-empty string.\",\n {\n context: { conversationId },\n trace: [\n {\n at: \"core.run.createRuntime.loadConversation.validateConversationId\",\n },\n ],\n },\n );\n }\n const resolvedAgent = resolveAgentFromRegistry(\n agents,\n agent,\n \"core.run.createRuntime.loadConversation\",\n );\n const conversations = options.conversations;\n if (!conversations) {\n return null;\n }\n\n const loaded = await conversations.load({\n conversationId,\n agentName: resolvedAgent.name,\n });\n if (!loaded) {\n return null;\n }\n\n validateStoredConversationItems(loaded.items, conversationId);\n return { items: loaded.items };\n },\n resumeStream: async (params) => {\n if (params.streamId.trim().length === 0) {\n throw BetterAgentError.fromCode(\n \"VALIDATION_FAILED\",\n \"streamId must be a non-empty string.\",\n {\n context: { streamId: params.streamId },\n trace: [{ at: \"core.run.createRuntime.resumeStream.validateStreamId\" }],\n },\n );\n }\n if (!options.stream) {\n return null;\n }\n\n return options.stream.resume(params.streamId, params.afterSeq);\n },\n\n resumeConversation: async <TName extends TAgents[number][\"name\"]>(\n agent: TName,\n params: ResumeConversationOptions,\n ) => {\n if (params.conversationId.trim().length === 0) {\n throw BetterAgentError.fromCode(\n \"VALIDATION_FAILED\",\n \"conversationId must be a non-empty string.\",\n {\n context: { conversationId: params.conversationId },\n trace: [\n {\n at: \"core.run.createRuntime.resumeConversation.validateConversationId\",\n },\n ],\n },\n );\n }\n\n const resolvedAgent = resolveAgentFromRegistry(\n agents,\n agent,\n \"core.run.createRuntime.resumeConversation\",\n );\n const state = !options.runtimeState\n ? null\n : await options.runtimeState.get({\n conversationId: params.conversationId,\n agentName: resolvedAgent.name,\n });\n\n if (!state || state.status !== \"running\" || !state.activeStreamId || !options.stream) {\n return null;\n }\n\n // biome-ignore lint/style/noNonNullAssertion: activeStreamId is checked above via runtime state existence\n return options.stream.resume(state.activeStreamId!, params.afterSeq);\n },\n\n abortRun: async (runId: string): Promise<boolean> => {\n const controller = activeRuns.get(runId);\n if (!controller) {\n return false;\n }\n\n controller.abort();\n return true;\n },\n\n submitToolResult: async (params: SubmitToolResultParams): Promise<boolean> =>\n pendingToolRuntime.submitToolResult(params),\n\n submitToolApproval: async (params: SubmitToolApprovalParams): Promise<boolean> =>\n pendingToolRuntime.submitToolApproval(params),\n };\n}\n"],"mappings":";;;;;;;;;;;AAiCA,SAAgB,cAAmE,SAQnD;CAC5B,MAAM,SAAS,oBAAoB,QAAQ,OAAO;CAClD,MAAM,gBAAgB,QAAQ,iBAAiB;CAC/C,MAAM,qBAAqB,0BAA0B;CACrD,MAAM,kBAAkB,QAAQ,mBAAmB;CACnD,MAAM,6BAAa,IAAI,KAA8B;CAErD,MAAM,6BACF,OACA,cAC4C;EAC5C,MAAM,cAAc,MAAM;AAC1B,MAAI,CAAC,eAAe,CAAC,UACjB;EAGJ,MAAM,SAAS;GACX,GAAI,eAAe,EAAE;GACrB,GAAI,aAAa,EAAE;GACtB;AAED,MACI,aACA,OAAO,UAAU,eAAe,KAAK,WAAW,eAAe,IAC/D,UAAU,iBAAiB,KAE3B,QAAO,eAAe;AAG1B,SAAO;;CAGX,MAAM,iCAAiC,WAGjC;AACF,MAAI,CAAC,OAAO,mBACR;EAGJ,MAAM,aACF,OAAO,MAAM,MAAM,KAAK,eACvB,OAAO,MAAM,MAAM,KAAK,eAAe,WAClC,2BACA;AAEV,MAAI,eAAe,aACf;AAGJ,SAAO,KACH,8CAA8C,OAAO,MAAM,KAAK,8BAA8B,WAAW,wDAC5G;;CAGL,MAAM,oBACF,aACA,aAKC;EACD,MAAM,WAAW;GACb,QAAQ,aAAa,UAAU,UAAU;GACzC,eAAe,aAAa,iBAAiB,UAAU;GACvD,cAAc,aAAa,gBAAgB,UAAU;GACxD;AAED,SAAO,SAAS,UAAU,SAAS,iBAAiB,SAAS,eACvD,WACA;;CAGV,MAAM,4BAA4B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gBAAiB,OAAO,SAAS;;EAGxE,UAAU,OAAO,UAAoC;GACjD,MAAM,aAAa,WAAW,IAAI,MAAM;AACxC,OAAI,CAAC,WACD,QAAO;AAGX,cAAW,OAAO;AAClB,UAAO;;EAGX,kBAAkB,OAAO,WACrB,mBAAmB,iBAAiB,OAAO;EAE/C,oBAAoB,OAAO,WACvB,mBAAmB,mBAAmB,OAAO;EACpD"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
//#region src/run/stop-conditions.ts
|
|
2
|
+
/** Extracts tool-call requests from a response. */
|
|
3
|
+
const extractToolCallRequests = (response) => response.output.filter((item) => item.type === "tool-call" && "arguments" in item);
|
|
4
|
+
/** Checks whether the loop hit `maxSteps`. */
|
|
5
|
+
const shouldStopByMaxSteps = (params) => params.maxSteps !== void 0 && params.maxSteps > 0 && params.stepIndex + 1 >= params.maxSteps;
|
|
6
|
+
/** Checks whether the loop produced no tool calls. */
|
|
7
|
+
const shouldStopNaturally = (params) => extractToolCallRequests(params.response).length === 0;
|
|
8
|
+
/** Evaluates stop conditions for the current step. */
|
|
9
|
+
const evaluateStopConditions = (params) => {
|
|
10
|
+
if (shouldStopNaturally({ response: params.lastStep.response })) return {
|
|
11
|
+
stop: true,
|
|
12
|
+
reason: "no_tool_calls"
|
|
13
|
+
};
|
|
14
|
+
const baseStopWhenContext = {
|
|
15
|
+
stepIndex: params.stepIndex,
|
|
16
|
+
maxSteps: params.maxSteps,
|
|
17
|
+
lastStep: params.lastStep,
|
|
18
|
+
steps: params.steps,
|
|
19
|
+
messages: params.messages
|
|
20
|
+
};
|
|
21
|
+
const stopWhenContext = params.context !== void 0 ? {
|
|
22
|
+
...baseStopWhenContext,
|
|
23
|
+
context: params.context
|
|
24
|
+
} : baseStopWhenContext;
|
|
25
|
+
if (params.stopWhen?.(stopWhenContext) === true) return {
|
|
26
|
+
stop: true,
|
|
27
|
+
reason: "stop_when"
|
|
28
|
+
};
|
|
29
|
+
if (shouldStopByMaxSteps({
|
|
30
|
+
stepIndex: params.stepIndex,
|
|
31
|
+
maxSteps: params.maxSteps
|
|
32
|
+
})) return {
|
|
33
|
+
stop: true,
|
|
34
|
+
reason: "max_steps"
|
|
35
|
+
};
|
|
36
|
+
return { stop: false };
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
export { evaluateStopConditions, extractToolCallRequests };
|
|
41
|
+
//# sourceMappingURL=stop-conditions.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stop-conditions.mjs","names":[],"sources":["../../src/run/stop-conditions.ts"],"sourcesContent":["import type {\n Capabilities,\n GenerativeModelInputItem,\n GenerativeModelToolCallRequest,\n} from \"../providers\";\nimport type { ResolvableSchema } from \"../schema\";\nimport type { PreviousStepResult, StopWhen, StopWhenContext } from \"./types\";\n\n/** Stop decision for loop evaluation. */\nexport type LoopStopDecision =\n | { stop: false }\n | { stop: true; reason: \"max_steps\" | \"stop_when\" | \"no_tool_calls\" };\n\n/** Extracts tool-call requests from a response. */\nexport const extractToolCallRequests = (\n response: PreviousStepResult[\"response\"],\n): GenerativeModelToolCallRequest[] =>\n response.output.filter(\n (item): item is GenerativeModelToolCallRequest =>\n item.type === \"tool-call\" && \"arguments\" in item,\n );\n\n/** Checks whether the loop hit `maxSteps`. */\nexport const shouldStopByMaxSteps = (params: {\n stepIndex: number;\n maxSteps: number | undefined;\n}): boolean =>\n params.maxSteps !== undefined && params.maxSteps > 0 && params.stepIndex + 1 >= params.maxSteps;\n\n/** Checks whether the loop produced no tool calls. */\nexport const shouldStopNaturally = (params: {\n response: PreviousStepResult[\"response\"];\n}): boolean => extractToolCallRequests(params.response).length === 0;\n\n/** Evaluates stop conditions for the current step. */\nexport const evaluateStopConditions = <\n TContextSchema extends ResolvableSchema | undefined,\n TContext,\n TModelCaps extends Capabilities = Capabilities,\n>(params: {\n maxSteps: number | undefined;\n stepIndex: number;\n stopWhen?: StopWhen<TContextSchema, TContext, TModelCaps>;\n steps: PreviousStepResult[];\n messages: GenerativeModelInputItem<TModelCaps>[];\n context?: TContext;\n lastStep: PreviousStepResult;\n}): LoopStopDecision => {\n if (shouldStopNaturally({ response: params.lastStep.response })) {\n return { stop: true, reason: \"no_tool_calls\" };\n }\n\n // Add `context` only when present.\n const baseStopWhenContext = {\n stepIndex: params.stepIndex,\n maxSteps: params.maxSteps,\n lastStep: params.lastStep,\n steps: params.steps,\n messages: params.messages,\n };\n\n const stopWhenContext =\n params.context !== undefined\n ? { ...baseStopWhenContext, context: params.context }\n : baseStopWhenContext;\n\n if (\n params.stopWhen?.(\n stopWhenContext as StopWhenContext<TContextSchema, TContext, TModelCaps>,\n ) === true\n ) {\n return { stop: true, reason: \"stop_when\" };\n }\n\n if (\n shouldStopByMaxSteps({\n stepIndex: params.stepIndex,\n maxSteps: params.maxSteps,\n })\n ) {\n return { stop: true, reason: \"max_steps\" };\n }\n\n return { stop: false };\n};\n"],"mappings":";;AAcA,MAAa,2BACT,aAEA,SAAS,OAAO,QACX,SACG,KAAK,SAAS,eAAe,eAAe,KACnD;;AAGL,MAAa,wBAAwB,WAIjC,OAAO,aAAa,UAAa,OAAO,WAAW,KAAK,OAAO,YAAY,KAAK,OAAO;;AAG3F,MAAa,uBAAuB,WAErB,wBAAwB,OAAO,SAAS,CAAC,WAAW;;AAGnE,MAAa,0BAIX,WAQsB;AACpB,KAAI,oBAAoB,EAAE,UAAU,OAAO,SAAS,UAAU,CAAC,CAC3D,QAAO;EAAE,MAAM;EAAM,QAAQ;EAAiB;CAIlD,MAAM,sBAAsB;EACxB,WAAW,OAAO;EAClB,UAAU,OAAO;EACjB,UAAU,OAAO;EACjB,OAAO,OAAO;EACd,UAAU,OAAO;EACpB;CAED,MAAM,kBACF,OAAO,YAAY,SACb;EAAE,GAAG;EAAqB,SAAS,OAAO;EAAS,GACnD;AAEV,KACI,OAAO,WACH,gBACH,KAAK,KAEN,QAAO;EAAE,MAAM;EAAM,QAAQ;EAAa;AAG9C,KACI,qBAAqB;EACjB,WAAW,OAAO;EAClB,UAAU,OAAO;EACpB,CAAC,CAEF,QAAO;EAAE,MAAM;EAAM,QAAQ;EAAa;AAG9C,QAAO,EAAE,MAAM,OAAO"}
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import { Awaitable, BivariantFn } from "../internal/types.mjs";
|
|
2
|
+
import { ResolvableSchema } from "../schema/types.mjs";
|
|
3
|
+
import { Capabilities, InferOutputSchema, InstructionEnabled, ModalitiesParam, ModalityOptionsFor, OutputSchemaDefinition, OutputSchemaForCaps } from "../providers/types/capabilities.mjs";
|
|
4
|
+
import { ToolChoice } from "../providers/types/tool-calls.mjs";
|
|
5
|
+
import { GenerativeModelInput, GenerativeModelInputItem, GenerativeModelInputMessageContent, ModelOptions } from "../providers/types/input.mjs";
|
|
6
|
+
import { ConversationItem } from "../providers/types/conversation.mjs";
|
|
7
|
+
import { GenerativeModelResponse } from "../providers/types/response.mjs";
|
|
8
|
+
import { GenerativeModel } from "../providers/types/model.mjs";
|
|
9
|
+
import { AgentContext, AgentContextSchema, AgentModelCaps, AgentOutputSchema, AnyAgentDefinition } from "../agent/types.mjs";
|
|
10
|
+
import { ConversationRuntimeStateStore, ConversationStore, StreamEvent, StreamStore } from "../persistence/types.mjs";
|
|
11
|
+
import { Event } from "../events/types.mjs";
|
|
12
|
+
//#region src/run/types.d.ts
|
|
13
|
+
/**
|
|
14
|
+
* Conditional `context` field based on whether a schema is defined.
|
|
15
|
+
*/
|
|
16
|
+
type ConditionalContextField<TContextSchema extends ResolvableSchema | undefined, TContext> = [TContextSchema] extends [undefined] ? Record<never, never> : undefined extends TContextSchema ? {
|
|
17
|
+
context?: TContext;
|
|
18
|
+
} : {
|
|
19
|
+
context: TContext;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Final result returned when a run completes.
|
|
23
|
+
*/
|
|
24
|
+
interface RunResult<TStructured = unknown> {
|
|
25
|
+
/** Final model response for the run. */
|
|
26
|
+
response: GenerativeModelResponse;
|
|
27
|
+
/** Parsed and validated structured output, when requested. */
|
|
28
|
+
structured?: TStructured;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Live stream handle returned by `.stream()`.
|
|
32
|
+
*/
|
|
33
|
+
interface StreamResult<TStructured = unknown> {
|
|
34
|
+
/** Unique id for this run. */
|
|
35
|
+
runId: string;
|
|
36
|
+
/** Live event stream for the run. */
|
|
37
|
+
events: AsyncGenerator<Event>;
|
|
38
|
+
/** Final result once the run finishes. */
|
|
39
|
+
result: Promise<RunResult<TStructured>>;
|
|
40
|
+
}
|
|
41
|
+
/** Options for resuming a stream by its known stream id. */
|
|
42
|
+
interface ResumeStreamOptions {
|
|
43
|
+
/** Stream id to resume. */
|
|
44
|
+
streamId: string;
|
|
45
|
+
/** Optional sequence number to continue after. */
|
|
46
|
+
afterSeq?: number;
|
|
47
|
+
}
|
|
48
|
+
/** Options for resuming the active stream for a conversation. */
|
|
49
|
+
interface ResumeConversationOptions {
|
|
50
|
+
/** Conversation id used to resolve the active stream. */
|
|
51
|
+
conversationId: string;
|
|
52
|
+
/** Optional sequence number to continue after. */
|
|
53
|
+
afterSeq?: number;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Runtime customization for replaying stored conversation history.
|
|
57
|
+
*/
|
|
58
|
+
interface ConversationReplayOptions {
|
|
59
|
+
/**
|
|
60
|
+
* When true, removes message parts that the current model cannot accept as
|
|
61
|
+
* input before replaying stored conversation history.
|
|
62
|
+
*
|
|
63
|
+
* Defaults to `true`.
|
|
64
|
+
*/
|
|
65
|
+
omitUnsupportedParts?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Customizes the provider input built from stored conversation items for
|
|
68
|
+
* this run.
|
|
69
|
+
*
|
|
70
|
+
* When provided, this fully replaces the default projection and
|
|
71
|
+
* capability-based pruning behavior. Set this to `null` on a run to
|
|
72
|
+
* disable an inherited agent-level hook.
|
|
73
|
+
*/
|
|
74
|
+
prepareInput?: ((params: {
|
|
75
|
+
items: ConversationItem[];
|
|
76
|
+
caps: Capabilities;
|
|
77
|
+
agentName: string;
|
|
78
|
+
conversationId: string;
|
|
79
|
+
}) => Awaitable<GenerativeModelInputItem[]>) | null;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Payload used to submit a pending client tool result.
|
|
83
|
+
*/
|
|
84
|
+
type SubmitToolResultParams = {
|
|
85
|
+
/** Run id that owns the pending tool call. */runId: string; /** Tool call id to resolve. */
|
|
86
|
+
toolCallId: string; /** Submit a successful result for the tool call. */
|
|
87
|
+
status: "success"; /** Result payload to send back to the run. */
|
|
88
|
+
result: unknown;
|
|
89
|
+
} | {
|
|
90
|
+
/** Run id that owns the pending tool call. */runId: string; /** Tool call id to resolve. */
|
|
91
|
+
toolCallId: string; /** Submit an execution error for the tool call. */
|
|
92
|
+
status: "error"; /** Error message to send back instead of a result. */
|
|
93
|
+
error: string;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Payload used to submit a pending tool approval decision.
|
|
97
|
+
*/
|
|
98
|
+
interface SubmitToolApprovalParams {
|
|
99
|
+
/** Run id that owns the pending approval. */
|
|
100
|
+
runId: string;
|
|
101
|
+
/** Tool call id to approve or deny. */
|
|
102
|
+
toolCallId: string;
|
|
103
|
+
/** Approval decision. */
|
|
104
|
+
decision: "approved" | "denied";
|
|
105
|
+
/** Optional note about the decision. */
|
|
106
|
+
note?: string;
|
|
107
|
+
/** Optional actor id for audit trails. */
|
|
108
|
+
actorId?: string;
|
|
109
|
+
}
|
|
110
|
+
type RuntimeAgentByName<TAgents extends readonly AnyAgentDefinition[], TName extends TAgents[number]["name"]> = Extract<TAgents[number], {
|
|
111
|
+
name: TName;
|
|
112
|
+
}>;
|
|
113
|
+
/**
|
|
114
|
+
* Structured output override accepted by one agent's model.
|
|
115
|
+
*/
|
|
116
|
+
type RunOutputOverrideForAgent<TAgent extends AnyAgentDefinition> = OutputSchemaForCaps<AgentModelCaps<TAgent["model"]>>;
|
|
117
|
+
type StructuredRunResult<TStructured> = Omit<RunResult<TStructured>, "structured"> & {
|
|
118
|
+
structured: TStructured;
|
|
119
|
+
};
|
|
120
|
+
type UnstructuredRunResult = Omit<RunResult<never>, "structured">;
|
|
121
|
+
type StructuredStreamResult<TStructured> = Omit<StreamResult<TStructured>, "result"> & {
|
|
122
|
+
result: Promise<StructuredRunResult<TStructured>>;
|
|
123
|
+
};
|
|
124
|
+
type UnstructuredStreamResult = Omit<StreamResult<never>, "result"> & {
|
|
125
|
+
result: Promise<UnstructuredRunResult>;
|
|
126
|
+
};
|
|
127
|
+
type AgentDefaultStructuredOutput<TAgent extends AnyAgentDefinition> = [AgentOutputSchema<TAgent>] extends [undefined] ? never : InferOutputSchema<AgentOutputSchema<TAgent>>;
|
|
128
|
+
type RunOutputField<TAgent extends AnyAgentDefinition, TOutput extends RunOutputOverrideForAgent<TAgent> | undefined> = [RunOutputOverrideForAgent<TAgent>] extends [never] ? object : {
|
|
129
|
+
/** Optional structured output schema override for this run. */output?: TOutput;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Structured output type produced for one agent run.
|
|
133
|
+
*/
|
|
134
|
+
type StructuredOutputForAgentRun<TAgent extends AnyAgentDefinition, TOutput extends RunOutputOverrideForAgent<TAgent> | undefined = undefined> = [TOutput] extends [undefined] ? AgentDefaultStructuredOutput<TAgent> : InferOutputSchema<TOutput>;
|
|
135
|
+
type AgentModelOptions<TAgent extends AnyAgentDefinition> = TAgent["model"] extends GenerativeModel<infer TOptions, infer _TProviderId, infer _TModelId, infer _TCaps> ? ModelOptions<TOptions> : TAgent["model"] extends {
|
|
136
|
+
options: infer TOptions extends Record<string, unknown>;
|
|
137
|
+
} ? ModelOptions<TOptions> : Record<never, never>;
|
|
138
|
+
/**
|
|
139
|
+
* Agent-aware run options with capability-gated structured output overrides.
|
|
140
|
+
*/
|
|
141
|
+
type RunOptionsForAgent<TAgent extends AnyAgentDefinition, TOutput extends RunOutputOverrideForAgent<TAgent> | undefined = RunOutputOverrideForAgent<TAgent> | undefined, TModalities extends ModalitiesParam<AgentModelCaps<TAgent["model"]>> | undefined = undefined> = Omit<RunOptions<AgentContext<TAgent>, TOutput, AgentModelCaps<TAgent["model"]>, AgentModelOptions<TAgent>, TModalities>, "output" | "context"> & ConditionalContextField<AgentContextSchema<TAgent>, AgentContext<TAgent>> & RunOutputField<TAgent, TOutput>;
|
|
142
|
+
/**
|
|
143
|
+
* Final run result for one agent.
|
|
144
|
+
*/
|
|
145
|
+
type RunResultForAgent<TAgent extends AnyAgentDefinition, TOutput extends RunOutputOverrideForAgent<TAgent> | undefined = undefined> = [StructuredOutputForAgentRun<TAgent, TOutput>] extends [never] ? UnstructuredRunResult : StructuredRunResult<StructuredOutputForAgentRun<TAgent, TOutput>>;
|
|
146
|
+
/**
|
|
147
|
+
* Stream handle for one agent and optional structured output override.
|
|
148
|
+
*/
|
|
149
|
+
type StreamResultForAgent<TAgent extends AnyAgentDefinition, TOutput extends RunOutputOverrideForAgent<TAgent> | undefined = undefined> = [StructuredOutputForAgentRun<TAgent, TOutput>] extends [never] ? UnstructuredStreamResult : StructuredStreamResult<StructuredOutputForAgentRun<TAgent, TOutput>>;
|
|
150
|
+
/**
|
|
151
|
+
* Runtime interface used by the app and HTTP server.
|
|
152
|
+
*/
|
|
153
|
+
interface BetterAgentRuntime<TAgents extends readonly AnyAgentDefinition[] = readonly AnyAgentDefinition[]> {
|
|
154
|
+
/** Runs an agent and returns the final result. */
|
|
155
|
+
run<TName extends TAgents[number]["name"], TAgent extends RuntimeAgentByName<TAgents, TName>, TOutput extends RunOutputOverrideForAgent<TAgent> | undefined = undefined>(agent: TName, runOptions: RunOptionsForAgent<TAgent, TOutput>): Promise<RunResultForAgent<TAgent, TOutput>>;
|
|
156
|
+
/** Runs an agent and streams events as they happen. */
|
|
157
|
+
stream<TName extends TAgents[number]["name"], TAgent extends RuntimeAgentByName<TAgents, TName>, TOutput extends RunOutputOverrideForAgent<TAgent> | undefined = undefined>(agent: TName, runOptions: RunOptionsForAgent<TAgent, TOutput>): StreamResultForAgent<TAgent, TOutput>;
|
|
158
|
+
/** Resumes a stream from a known stream id. */
|
|
159
|
+
resumeStream(params: ResumeStreamOptions): Promise<AsyncIterable<StreamEvent> | null>;
|
|
160
|
+
/**
|
|
161
|
+
* Resume the active stream for a conversation when runtime-state lookup is configured.
|
|
162
|
+
*
|
|
163
|
+
* Returns `null` when runtime-state lookup is not configured, no active
|
|
164
|
+
* stream exists, or the stored stream cannot be resumed.
|
|
165
|
+
*/
|
|
166
|
+
resumeConversation<TName extends TAgents[number]["name"]>(agent: TName, params: ResumeConversationOptions): Promise<AsyncIterable<StreamEvent> | null>;
|
|
167
|
+
/** Aborts an active run by id. Returns `false` when no active run is found. */
|
|
168
|
+
abortRun(runId: string): Promise<boolean>;
|
|
169
|
+
/**
|
|
170
|
+
* Load the persisted message history for one conversation.
|
|
171
|
+
*
|
|
172
|
+
* Returns `null` when no stored conversation exists.
|
|
173
|
+
*/
|
|
174
|
+
loadConversation<TName extends TAgents[number]["name"]>(agent: TName, conversationId: string): Promise<{
|
|
175
|
+
items: ConversationItem[];
|
|
176
|
+
} | null>;
|
|
177
|
+
/** Submits a result for a pending client tool call. */
|
|
178
|
+
submitToolResult(params: SubmitToolResultParams): Promise<boolean>;
|
|
179
|
+
/** Submits an approval decision for a pending tool call. */
|
|
180
|
+
submitToolApproval(params: SubmitToolApprovalParams): Promise<boolean>;
|
|
181
|
+
/** Effective lifecycle for streaming runs created by this runtime. */
|
|
182
|
+
streamLifecycle?: "request_bound" | "detached";
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Function used to stop the loop based on the latest completed step.
|
|
186
|
+
*/
|
|
187
|
+
type StopWhen<TContextSchema extends ResolvableSchema | undefined = undefined, TContext = unknown, TModelCaps extends Capabilities = Capabilities> = BivariantFn<[StopWhenContext<TContextSchema, TContext, TModelCaps>], boolean>;
|
|
188
|
+
/**
|
|
189
|
+
* Conditional tool-control fields.
|
|
190
|
+
*/
|
|
191
|
+
type ConditionalToolControlField<TModelCaps extends Capabilities = Capabilities> = TModelCaps["tools"] extends true ? {
|
|
192
|
+
setToolChoice(choice: ToolChoice): void;
|
|
193
|
+
setActiveTools(names: readonly string[]): void;
|
|
194
|
+
} : Record<never, never>;
|
|
195
|
+
/**
|
|
196
|
+
* Conditional instruction-control fields.
|
|
197
|
+
*/
|
|
198
|
+
type ConditionalInstructionControlField<TModelCaps extends Capabilities = Capabilities> = InstructionEnabled<TModelCaps> extends true ? {
|
|
199
|
+
setSystemInstruction(instruction: GenerativeModelInputMessageContent<TModelCaps>): void;
|
|
200
|
+
} : Record<never, never>;
|
|
201
|
+
/**
|
|
202
|
+
* Base context passed to `onStep`.
|
|
203
|
+
*/
|
|
204
|
+
interface OnStepContextBase<TModelCaps extends Capabilities = Capabilities> {
|
|
205
|
+
/** Unique id for this run. */
|
|
206
|
+
runId: string;
|
|
207
|
+
/** Name of the active agent. */
|
|
208
|
+
agentName: string;
|
|
209
|
+
/** Shared conversation id, if this run uses one. */
|
|
210
|
+
conversationId?: string;
|
|
211
|
+
/** Zero-based step number for the next step. */
|
|
212
|
+
stepIndex: number;
|
|
213
|
+
/** Maximum number of steps allowed for this run. */
|
|
214
|
+
maxSteps: number | undefined;
|
|
215
|
+
/** Current message history before the next model call. */
|
|
216
|
+
messages: GenerativeModelInputItem<TModelCaps>[];
|
|
217
|
+
/** Result from the last completed step, if one exists. */
|
|
218
|
+
previousStep?: PreviousStepResult;
|
|
219
|
+
/** Replace the current messages before the next step runs. */
|
|
220
|
+
updateMessages(updater: (messages: GenerativeModelInputItem<TModelCaps>[]) => GenerativeModelInputItem<TModelCaps>[]): void;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Context passed to `onStep`.
|
|
224
|
+
*/
|
|
225
|
+
type OnStepContext<TContextSchema extends ResolvableSchema | undefined = undefined, TContext = unknown, TModelCaps extends Capabilities = Capabilities> = OnStepContextBase<TModelCaps> & ConditionalInstructionControlField<TModelCaps> & ConditionalContextField<TContextSchema, TContext> & ConditionalToolControlField<TModelCaps>;
|
|
226
|
+
/**
|
|
227
|
+
* Base context passed to `onStepFinish`.
|
|
228
|
+
*/
|
|
229
|
+
interface OnStepFinishContextBase {
|
|
230
|
+
/** Unique id for this run. */
|
|
231
|
+
runId: string;
|
|
232
|
+
/** Name of the active agent. */
|
|
233
|
+
agentName: string;
|
|
234
|
+
/** Shared conversation id, if this run uses one. */
|
|
235
|
+
conversationId?: string;
|
|
236
|
+
/** Zero-based step number that just finished. */
|
|
237
|
+
stepIndex: number;
|
|
238
|
+
/** Maximum number of steps allowed for this run. */
|
|
239
|
+
maxSteps: number | undefined;
|
|
240
|
+
/** Result from the step that just finished. */
|
|
241
|
+
result: PreviousStepResult;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Context passed to `onStepFinish`.
|
|
245
|
+
*/
|
|
246
|
+
type OnStepFinishContext<TContextSchema extends ResolvableSchema | undefined = undefined, TContext = unknown> = OnStepFinishContextBase & ConditionalContextField<TContextSchema, TContext>;
|
|
247
|
+
/**
|
|
248
|
+
* Base context passed to `stopWhen`.
|
|
249
|
+
*/
|
|
250
|
+
interface StopWhenContextBase<TModelCaps extends Capabilities = Capabilities> {
|
|
251
|
+
/** Zero-based index of the current step. */
|
|
252
|
+
stepIndex: number;
|
|
253
|
+
/** Maximum number of steps allowed for this run. If undefined, no limit. */
|
|
254
|
+
maxSteps: number | undefined;
|
|
255
|
+
/** Result from the most recent completed step. */
|
|
256
|
+
lastStep: PreviousStepResult;
|
|
257
|
+
/** Results from all completed steps so far. */
|
|
258
|
+
steps: PreviousStepResult[];
|
|
259
|
+
/** Current message history after the last step. */
|
|
260
|
+
messages: GenerativeModelInputItem<TModelCaps>[];
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Context passed to `stopWhen`.
|
|
264
|
+
*/
|
|
265
|
+
type StopWhenContext<TContextSchema extends ResolvableSchema | undefined = undefined, TContext = unknown, TModelCaps extends Capabilities = Capabilities> = StopWhenContextBase<TModelCaps> & ConditionalContextField<TContextSchema, TContext>;
|
|
266
|
+
/**
|
|
267
|
+
* Summary of the most recently completed loop step.
|
|
268
|
+
*/
|
|
269
|
+
interface PreviousStepResult {
|
|
270
|
+
/** Model response produced by that step. */
|
|
271
|
+
response: GenerativeModelResponse;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Basic runtime context for the current run.
|
|
275
|
+
*/
|
|
276
|
+
interface RunContext {
|
|
277
|
+
/** Unique id for this run. */
|
|
278
|
+
runId: string;
|
|
279
|
+
/** Name of the active agent. */
|
|
280
|
+
agentName: string;
|
|
281
|
+
/** Provider identifier for the model being used. */
|
|
282
|
+
providerId: string;
|
|
283
|
+
/** Model identifier within the provider. */
|
|
284
|
+
modelId: string;
|
|
285
|
+
/** Shared conversation id, if this run uses one. */
|
|
286
|
+
conversationId?: string;
|
|
287
|
+
/** Abort signal for canceling work. */
|
|
288
|
+
signal: AbortSignal;
|
|
289
|
+
/** Generate a stable message id for provider-authored model events. */
|
|
290
|
+
generateMessageId: () => string;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Persistence overrides for one run.
|
|
294
|
+
*/
|
|
295
|
+
interface RunPersistenceOptions {
|
|
296
|
+
/** Advanced: override the stream store for this run. */
|
|
297
|
+
stream?: StreamStore;
|
|
298
|
+
/** Advanced: override the conversation store for this run. */
|
|
299
|
+
conversations?: ConversationStore;
|
|
300
|
+
/** Advanced: override the conversation runtime-state store for this run. */
|
|
301
|
+
runtimeState?: ConversationRuntimeStateStore;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Advanced runtime controls for interactive runs.
|
|
305
|
+
*/
|
|
306
|
+
interface RunAdvancedOptions {
|
|
307
|
+
/**
|
|
308
|
+
* Default timeout for waiting on client tool results when the tool itself
|
|
309
|
+
* does not provide a more specific timeout.
|
|
310
|
+
*/
|
|
311
|
+
clientToolResultTimeoutMs?: number;
|
|
312
|
+
/**
|
|
313
|
+
* Default timeout for waiting on tool approvals when the tool itself does
|
|
314
|
+
* not provide a more specific timeout.
|
|
315
|
+
*/
|
|
316
|
+
toolApprovalTimeoutMs?: number;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Options for running an agent.
|
|
320
|
+
*
|
|
321
|
+
* Prefer {@link RunOptionsForAgent} for agent-aware APIs.
|
|
322
|
+
*/
|
|
323
|
+
type RunOptions<TContext = unknown, TOutput extends OutputSchemaDefinition | undefined = undefined, TModelCaps extends Capabilities = Capabilities, TModelOptions extends object = Record<never, never>, TModalities extends ModalitiesParam<TModelCaps> | undefined = undefined> = {
|
|
324
|
+
/** Input to send to the agent. */input: GenerativeModelInput<TModelCaps>; /** Extra agent context to validate and use during the run. */
|
|
325
|
+
context?: TContext; /** Optional structured output schema override for this run. */
|
|
326
|
+
output?: TOutput; /** Optional output modalities to request for this run. */
|
|
327
|
+
modalities?: TModalities; /** Optional provider-specific model options for this run. Unknown keys are passed through to the provider. */
|
|
328
|
+
modelOptions?: TModelOptions & ModalityOptionsFor<TModelCaps, TModalities> & Record<string, unknown>; /** Conversation id to load and save message history. */
|
|
329
|
+
conversationId?: string; /** Controls how stored conversation history is prepared for replay in this run. */
|
|
330
|
+
conversationReplay?: ConversationReplayOptions;
|
|
331
|
+
/**
|
|
332
|
+
* When true, array input replaces stored conversation history instead of being
|
|
333
|
+
* prepended with it.
|
|
334
|
+
*
|
|
335
|
+
* This is primarily used when a client submits the full conversation history
|
|
336
|
+
* together with a `conversationId`, for example during retry/regenerate flows.
|
|
337
|
+
* String or single-message inputs should usually leave this unset.
|
|
338
|
+
*/
|
|
339
|
+
replaceHistory?: boolean; /** Abort signal for canceling the run. */
|
|
340
|
+
signal?: AbortSignal; /** Called for each event emitted during the run. */
|
|
341
|
+
onEvent?: (event: Event) => void | Promise<void>; /** Max loop steps for this run. Overrides the agent default. */
|
|
342
|
+
maxSteps?: number; /** Advanced interactive runtime options for this run. */
|
|
343
|
+
advanced?: RunAdvancedOptions; /** Advanced: override persistence stores for this run. */
|
|
344
|
+
persistence?: RunPersistenceOptions;
|
|
345
|
+
};
|
|
346
|
+
//#endregion
|
|
347
|
+
export { BetterAgentRuntime, ConditionalContextField, ConditionalInstructionControlField, ConditionalToolControlField, ConversationReplayOptions, OnStepContext, OnStepContextBase, OnStepFinishContext, OnStepFinishContextBase, PreviousStepResult, ResumeConversationOptions, ResumeStreamOptions, RunAdvancedOptions, RunContext, RunOptions, RunOptionsForAgent, RunOutputOverrideForAgent, RunPersistenceOptions, RunResult, RunResultForAgent, StopWhen, StopWhenContext, StopWhenContextBase, StreamResult, StreamResultForAgent, StructuredOutputForAgentRun, SubmitToolApprovalParams, SubmitToolResultParams };
|
|
348
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":[],"sources":["../../src/run/types.ts"],"mappings":";;;;;;;;;;;;;;;KA0CY,uBAAA,wBACe,gBAAA,2BAEtB,cAAA,wBACC,MAAA,mCACkB,cAAA;EACd,OAAA,GAAU,QAAA;AAAA;EACV,OAAA,EAAS,QAAA;AAAA;;;;UAKF,SAAA;EAZL;EAcR,QAAA,EAAU,uBAAA;EAdqB;EAgB/B,UAAA,GAAa,WAAA;AAAA;;;;UAMA,YAAA;EAfU;EAiBvB,KAAA;EAvBA;EAyBA,MAAA,EAAQ,cAAA,CAAe,KAAA;EAxBvB;EA0BA,MAAA,EAAQ,OAAA,CAAQ,SAAA,CAAU,WAAA;AAAA;;UAIb,mBAAA;EA1BG;EA4BhB,QAAA;EA3Be;EA6Bf,QAAA;AAAA;AAxBJ;AAAA,UA4BiB,yBAAA;EA5BS;EA8BtB,cAAA;EA9BuB;EAgCvB,QAAA;AAAA;;;;UAMa,yBAAA;EA5BA;;;;;;EAmCb,oBAAA;EA7BQ;;;;;;;;EAsCR,YAAA,KACQ,MAAA;IACE,KAAA,EAAO,gBAAA;IACP,IAAA,EAAM,YA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AiQF,MAAA,GAAS,WAAA;EA9PQ;EAgQjB,aAAA,GAAgB,iBAAA;EA/PZ;EAiQJ,YAAA,GAAe,6BAAA;AAAA;;;;UAMF,kBAAA;EAjRP;;;;EAsRN,yBAAA;EAjRe;;;;EAsRf,qBAAA;AAAA;;;;;AA5QJ;KAoRY,UAAA,qCAEQ,sBAAA,6CACG,YAAA,GAAe,YAAA,iCACH,MAAA,oCACX,eAAA,CAAgB,UAAA;EAzRV,kCA4R1B,KAAA,EAAO,oBAAA,CAAqB,UAAA,GA1Rc;EA4R1C,OAAA,GAAU,QAAA,EA3RsB;EA6RhC,MAAA,GAAS,OAAA,EA3R0C;EA6RnD,UAAA,GAAa,WAAA,EA7RO;EA+RpB,YAAA,GAAe,aAAA,GACX,kBAAA,CAAmB,UAAA,EAAY,WAAA,IAC/B,MAAA,mBA9RA;EAgSJ,cAAA,WA9RmB;EAgSnB,kBAAA,GAAqB,yBAAA;EA/RC;;;;;;;;EAwStB,cAAA,YAnSA;EAqSA,MAAA,GAAS,WAAA,EApSc;EAsSvB,OAAA,IAAW,KAAA,EAAO,KAAA,YAAiB,OAAA,QAtSrB;EAwSd,QAAA,WAxTA;EA0TA,QAAA,GAAW,kBAAA,EAzTX;EA2TA,WAAA,GAAc,qBAAA;AAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ResolvableSchema, ValidatableSchema } from "./types.mjs";
|
|
2
|
+
import { BetterAgentError } from "@better-agent/shared/errors";
|
|
3
|
+
import { Result } from "@better-agent/shared/neverthrow";
|
|
4
|
+
|
|
5
|
+
//#region src/schema/resolve-json-schema.d.ts
|
|
6
|
+
declare const resolveToJsonSchema: (schema: ResolvableSchema) => Result<Record<string, unknown>, BetterAgentError>;
|
|
7
|
+
declare const validateInput: <T>(schema: ValidatableSchema, data: unknown, options?: {
|
|
8
|
+
invalidMessage?: string;
|
|
9
|
+
}) => Promise<Result<T, BetterAgentError>>;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { resolveToJsonSchema, validateInput };
|
|
12
|
+
//# sourceMappingURL=resolve-json-schema.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-json-schema.d.mts","names":[],"sources":["../../src/schema/resolve-json-schema.ts"],"mappings":";;;;;cA8Ia,mBAAA,GAAmB,MAAA,EACpB,gBAAA,KACT,MAAA,CAAO,MAAA,mBAAyB,gBAAA;AAAA,cA4EtB,aAAA,MAAwB,MAAA,EACzB,iBAAA,EAAiB,IAAA,WACZ,OAAA;EAET,cAAA;AAAA,MAEL,OAAA,CAAQ,MAAA,CAAO,CAAA,EAAG,gBAAA"}
|