@anvia/core 1.0.0-rc.9 → 1.0.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 +99 -77
- package/dist/agent/index.d.ts +11 -16
- package/dist/agent/index.js +12 -12
- package/dist/{agent-XPQBM4rX.d.ts → agent-qRKa3ibC.d.ts} +11 -7
- package/dist/{chunk-X4LK4ODN.js → chunk-AHLKV6KP.js} +1 -1
- package/dist/chunk-AHLKV6KP.js.map +1 -0
- package/dist/{chunk-KIXN5DGS.js → chunk-DHJL44R2.js} +2 -2
- package/dist/{chunk-PISJAAMX.js → chunk-E2J7MLAB.js} +321 -117
- package/dist/chunk-E2J7MLAB.js.map +1 -0
- package/dist/{chunk-SJMSS5SI.js → chunk-EO2GECYH.js} +3 -3
- package/dist/{chunk-WZVHZZW6.js → chunk-GBCKSWQF.js} +2 -2
- package/dist/{chunk-3SKZ2BKP.js → chunk-IWJK7JB5.js} +2 -2
- package/dist/{chunk-3RM57ZT2.js → chunk-IZNOP6JG.js} +2 -2
- package/dist/chunk-IZNOP6JG.js.map +1 -0
- package/dist/chunk-J6LVLV6P.js +13 -0
- package/dist/chunk-J6LVLV6P.js.map +1 -0
- package/dist/{chunk-ZA564323.js → chunk-K5L7R7XM.js} +2 -2
- package/dist/{chunk-QOUPWOGW.js → chunk-SPD4XVR7.js} +1 -1
- package/dist/{chunk-WTRGYFCD.js → chunk-TB5EKZM7.js} +4 -4
- package/dist/chunk-TB5EKZM7.js.map +1 -0
- package/dist/{chunk-TC4FILD3.js → chunk-XMVOBX43.js} +51 -4
- package/dist/chunk-XMVOBX43.js.map +1 -0
- package/dist/{chunk-EMZKPRE6.js → chunk-YFJ4NHV6.js} +2 -2
- package/dist/chunk-YFJ4NHV6.js.map +1 -0
- package/dist/completion/index.js +2 -2
- package/dist/documents/index.js +26 -1
- package/dist/documents/index.js.map +1 -1
- package/dist/embeddings/index.js +2 -2
- package/dist/evals/index.d.ts +5 -5
- package/dist/evals/index.js +9 -9
- package/dist/evals/index.js.map +1 -1
- package/dist/extractor/index.js +3 -3
- package/dist/index.d.ts +7 -12
- package/dist/index.js +26 -24
- package/dist/internal/agent.d.ts +4 -9
- package/dist/internal/agent.js +12 -12
- package/dist/mcp/index.d.ts +3 -17
- package/dist/mcp/index.js +1 -15
- package/dist/memory/index.d.ts +6 -3
- package/dist/memory/index.js +6 -4
- package/dist/observability/index.d.ts +2 -2
- package/dist/observability/index.js +3 -3
- package/dist/pipeline/index.d.ts +6 -11
- package/dist/pipeline/index.js +7 -7
- package/dist/pipeline/index.js.map +1 -1
- package/dist/skills/index.js +5 -5
- package/dist/tool/index.js +4 -4
- package/dist/{types-Sue2hb_L.d.ts → types-CLCLFpAL.d.ts} +23 -15
- package/dist/{types-DKOXVTcq.d.ts → types-CSYt7-It.d.ts} +18 -3
- package/dist/types-DjqRHeAi.d.ts +31 -0
- package/dist/vector-store/index.js +3 -3
- package/package.json +10 -4
- package/dist/chunk-3RM57ZT2.js.map +0 -1
- package/dist/chunk-76JLMBVT.js +0 -716
- package/dist/chunk-76JLMBVT.js.map +0 -1
- package/dist/chunk-EMZKPRE6.js.map +0 -1
- package/dist/chunk-PISJAAMX.js.map +0 -1
- package/dist/chunk-TC4FILD3.js.map +0 -1
- package/dist/chunk-WTRGYFCD.js.map +0 -1
- package/dist/chunk-X4LK4ODN.js.map +0 -1
- package/dist/client-DTPl0hZv.d.ts +0 -84
- /package/dist/{chunk-KIXN5DGS.js.map → chunk-DHJL44R2.js.map} +0 -0
- /package/dist/{chunk-SJMSS5SI.js.map → chunk-EO2GECYH.js.map} +0 -0
- /package/dist/{chunk-WZVHZZW6.js.map → chunk-GBCKSWQF.js.map} +0 -0
- /package/dist/{chunk-3SKZ2BKP.js.map → chunk-IWJK7JB5.js.map} +0 -0
- /package/dist/{chunk-ZA564323.js.map → chunk-K5L7R7XM.js.map} +0 -0
- /package/dist/{chunk-QOUPWOGW.js.map → chunk-SPD4XVR7.js.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/pipeline/errors.ts","../../src/pipeline/pipeline.ts","../../src/pipeline/graph.ts","../../src/pipeline/runtime.ts"],"sourcesContent":["import type { AgentSuspendedResult } from \"../agent/run-types\";\n\nexport class PipelineAgentSuspensionError extends Error {\n constructor(readonly result: AgentSuspendedResult) {\n super(\"Pipeline agent stage suspended for human interaction.\");\n this.name = \"PipelineAgentSuspensionError\";\n }\n}\n","import { z } from \"zod\";\nimport type { Agent } from \"../agent/agent\";\nimport { AgentRunBlockedError } from \"../agent/errors\";\nimport type { AgentInput, AgentRunOptions, AgentRunSettings } from \"../agent/run-types\";\nimport type { CompletionModel, JsonObject } from \"../completion\";\nimport { type ExtractOptions, extract as extractData } from \"../extractor\";\nimport { throwIfAborted } from \"../internal/abort\";\nimport { mapWithConcurrency } from \"../internal/concurrency\";\nimport { PipelineAgentSuspensionError } from \"./errors\";\nimport {\n appendComposedGraph,\n appendParallelBranch,\n appendStageNode,\n cloneGraph,\n initialPipelineState,\n withOutputNode,\n withTerminalPaths,\n} from \"./graph\";\nimport {\n childContext,\n combineAbortSignals,\n pipelineAbortError,\n runNode,\n stageContext,\n} from \"./runtime\";\nimport type {\n ParallelOutput,\n PipelineBatchItem,\n PipelineBatchOptions,\n PipelineExecutor,\n PipelineGraph,\n PipelineGraphNode,\n PipelineNodePath,\n PipelineOptions,\n PipelineRunContext,\n PipelineRunOptions,\n PipelineRunResult,\n PipelineStageContext,\n PipelineStageMetadata,\n PipelineState,\n} from \"./types\";\n\nconst internalPipelineOptions = Symbol(\"internal-pipeline-options\");\n\ntype RawResponseOf<Model> =\n Model extends CompletionModel<infer RawResponse> ? RawResponse : unknown;\n\ntype PipelineAgentRequest<Output, Model extends CompletionModel> = AgentInput &\n Omit<AgentRunSettings<Output, RawResponseOf<Model>>, \"abortSignal\">;\n\nexport type PipelineStepOptions<Input, Output> = PipelineStageMetadata & {\n run(context: PipelineStageContext<Input>): Output | Promise<Output>;\n};\n\nexport type PipelineComposeOptions<Input, Output> = PipelineStageMetadata & {\n pipeline: Pipeline<Input, Output>;\n};\n\nexport type PipelineParallelOptions<\n Input,\n Branches extends Record<string, Pipeline<Input, unknown>>,\n> = PipelineStageMetadata & {\n branches: Branches;\n};\n\nexport type PipelineAgentOptions<\n Input,\n AgentOutput,\n Model extends CompletionModel,\n> = PipelineStageMetadata & {\n agent: Agent<AgentOutput, Model>;\n request(\n context: PipelineStageContext<Input>,\n ): PipelineAgentRequest<AgentOutput, Model> | Promise<PipelineAgentRequest<AgentOutput, Model>>;\n suspension: \"reject\";\n};\n\nexport type PipelineExtractOptions<\n Input,\n Extracted,\n Model extends CompletionModel,\n> = PipelineStageMetadata &\n Omit<ExtractOptions<Extracted, Model>, \"text\" | \"abortSignal\"> & {\n text(context: PipelineStageContext<Input>): string | Promise<string>;\n };\n\ntype InternalPipelineOptions<Input, Output> = {\n [internalPipelineOptions]: {\n executor: PipelineExecutor<Input, Output>;\n state: PipelineState;\n };\n};\n\n/** Immutable, typed Pipeline with explicit stage and execution boundaries. */\nexport class Pipeline<Input, Output = Input> {\n readonly id: string;\n readonly name: string | undefined;\n readonly description: string | undefined;\n readonly metadata: JsonObject | undefined;\n\n private readonly executor: PipelineExecutor<Input, Output>;\n private readonly state: PipelineState;\n\n constructor(options: PipelineOptions<Input, Output>);\n constructor(options: PipelineOptions<Input, Output> | InternalPipelineOptions<Input, Output>) {\n if (isInternalPipelineOptions(options)) {\n this.executor = options[internalPipelineOptions].executor;\n this.state = options[internalPipelineOptions].state;\n } else {\n const id = normalizePipelineId(options.id);\n if (!isZodSchema(options.inputSchema)) {\n throw new TypeError(\"Pipeline inputSchema must be a Zod schema.\");\n }\n const inputSchema = options.inputSchema;\n this.executor = (async (input, context) => {\n throwIfAborted(context.abortSignal);\n return inputSchema.parseAsync(input) as Promise<Output>;\n }) as PipelineExecutor<Input, Output>;\n this.state = initialPipelineState({\n id,\n name: options.name,\n description: options.description,\n metadata: options.metadata,\n });\n }\n\n const graph = this.state.graph;\n this.id = graph.id;\n this.name = graph.name;\n this.description = graph.description;\n this.metadata = graph.metadata;\n }\n\n step<Next>(options: PipelineStepOptions<Awaited<Output>, Next>): Pipeline<Input, Awaited<Next>> {\n const next = appendStageNode(this.state, \"step\", options);\n const executor = (async (input, context, pathPrefix) => {\n const value = await this.execute(input, context, pathPrefix);\n const path = [...pathPrefix, next.node.id];\n return (await runNode(context, next.node, path, () =>\n options.run(stageContext(value, context)),\n )) as Awaited<Next>;\n }) as PipelineExecutor<Input, Awaited<Next>>;\n return this.derive(executor, next.state);\n }\n\n compose<Next>(\n options: PipelineComposeOptions<Awaited<Output>, Next>,\n ): Pipeline<Input, Awaited<Next>> {\n const boundary = appendStageNode(this.state, \"pipeline\", options, {\n defaultLabel: options.pipeline.name ?? options.pipeline.id,\n pipelineId: options.pipeline.id,\n });\n const state = appendComposedGraph(boundary.state, boundary.node, options.pipeline.graph());\n const executor = (async (input, context, pathPrefix) => {\n const value = await this.execute(input, context, pathPrefix);\n const path = [...pathPrefix, boundary.node.id];\n return (await runNode(context, boundary.node, path, () =>\n options.pipeline.execute(value, context, path),\n )) as Awaited<Next>;\n }) as PipelineExecutor<Input, Awaited<Next>>;\n return this.derive(executor, state);\n }\n\n parallel<Branches extends Record<string, Pipeline<Awaited<Output>, unknown>>>(\n options: PipelineParallelOptions<Awaited<Output>, Branches>,\n ): Pipeline<Input, ParallelOutput<Branches>> {\n const branchEntries = normalizeParallelBranches(options.branches);\n if (branchEntries.length === 0) {\n throw new TypeError(\"Pipeline parallel branches must not be empty.\");\n }\n const parallel = appendStageNode(this.state, \"parallel\", options, {\n defaultLabel: `${branchEntries.length} parallel branches`,\n });\n let nextState = parallel.state;\n const branchNodes = new Map<string, PipelineGraphNode>();\n const terminalPaths: PipelineNodePath[] = [];\n for (const [key, branch] of branchEntries) {\n const appended = appendParallelBranch(nextState, parallel.node, key, branch.graph());\n nextState = appended.state;\n branchNodes.set(key, appended.node);\n terminalPaths.push(...appended.terminalPaths);\n }\n nextState = withTerminalPaths(nextState, terminalPaths);\n\n return this.derive<ParallelOutput<Branches>>(async (input, context, pathPrefix) => {\n const value = await this.execute(input, context, pathPrefix);\n const parallelPath = [...pathPrefix, parallel.node.id];\n return runNode(context, parallel.node, parallelPath, async () => {\n const controller = new AbortController();\n const combined = combineAbortSignals(context.abortSignal, controller.signal);\n const branchContext = childContext(context, combined.signal);\n let firstError: unknown;\n const promises = branchEntries.map(async ([key, branch]) => {\n const node = branchNodes.get(key) as PipelineGraphNode;\n const path = [...parallelPath, node.id];\n try {\n const output = await runNode(branchContext, node, path, () =>\n branch.execute(value, branchContext, path),\n );\n return [key, output] as const;\n } catch (error) {\n if (firstError === undefined) firstError = error;\n if (!controller.signal.aborted) controller.abort(error);\n throw error;\n }\n });\n\n const settled = await Promise.allSettled(promises);\n combined.dispose();\n if (context.abortSignal?.aborted === true) {\n throw pipelineAbortError(context.abortSignal);\n }\n if (firstError !== undefined) throw firstError;\n return Object.fromEntries(\n settled.map(\n (result) => (result as PromiseFulfilledResult<readonly [string, unknown]>).value,\n ),\n ) as ParallelOutput<Branches>;\n });\n }, nextState);\n }\n\n agent<AgentOutput, Model extends CompletionModel>(\n options: PipelineAgentOptions<Awaited<Output>, AgentOutput, Model>,\n ): Pipeline<Input, AgentOutput> {\n if (options.suspension !== \"reject\") {\n throw new TypeError('Pipeline Agent stages require suspension: \"reject\".');\n }\n const next = appendStageNode(this.state, \"agent\", options, {\n defaultLabel: options.agent.name ?? options.agent.id,\n agentId: options.agent.id,\n agentName: options.agent.name,\n });\n return this.derive<AgentOutput>(async (input, context, pathPrefix) => {\n const value = await this.execute(input, context, pathPrefix);\n const path = [...pathPrefix, next.node.id];\n return runNode(context, next.node, path, async () => {\n const request = await options.request(stageContext(value, context));\n const response = await options.agent.generate({\n ...request,\n abortSignal: context.abortSignal,\n } as AgentRunOptions<AgentOutput, RawResponseOf<Model>>);\n if (response.status === \"suspended\") {\n throw new PipelineAgentSuspensionError(response);\n }\n if (response.status === \"blocked\") {\n throw new AgentRunBlockedError(response);\n }\n return response.output;\n });\n }, next.state);\n }\n\n extract<Extracted, Model extends CompletionModel>(\n options: PipelineExtractOptions<Awaited<Output>, Extracted, Model>,\n ): Pipeline<Input, Extracted> {\n const next = appendStageNode(this.state, \"extractor\", options);\n return this.derive<Extracted>(async (input, context, pathPrefix) => {\n const value = await this.execute(input, context, pathPrefix);\n const path = [...pathPrefix, next.node.id];\n return runNode(context, next.node, path, async () => {\n const text = await options.text(stageContext(value, context));\n const result = await extractData({\n model: options.model,\n text,\n outputSchema: options.outputSchema,\n instructions: options.instructions,\n retries: options.retries,\n temperature: options.temperature,\n maxTokens: options.maxTokens,\n providerOptions: options.providerOptions,\n abortSignal: context.abortSignal,\n });\n return result.output;\n });\n }, next.state);\n }\n\n async run(options: PipelineRunOptions<Input>): Promise<PipelineRunResult<Output>> {\n const runId = normalizeRunId(options.runId ?? globalThis.crypto.randomUUID());\n const context: PipelineRunContext = {\n runId,\n pipelineId: this.id,\n runMetadata: options.metadata,\n abortSignal: options.abortSignal,\n observer: options.observer,\n failOnObserverError: options.failOnObserverError === true,\n };\n throwIfAborted(context.abortSignal);\n const output = await this.execute(options.input, context, []);\n throwIfAborted(context.abortSignal);\n return { runId, output };\n }\n\n async runBatch(options: PipelineBatchOptions<Input>): Promise<Array<PipelineBatchItem<Output>>> {\n throwIfAborted(options.abortSignal);\n return mapWithConcurrency([...options.inputs], options.concurrency, async (input) => {\n const runId = globalThis.crypto.randomUUID();\n try {\n const result = await this.run({\n input,\n runId,\n metadata: options.metadata,\n abortSignal: options.abortSignal,\n observer: options.observer,\n failOnObserverError: options.failOnObserverError,\n });\n return { status: \"completed\", ...result } as const;\n } catch (error) {\n if (options.abortSignal?.aborted === true) {\n throw pipelineAbortError(options.abortSignal);\n }\n return { status: \"failed\", runId, error } as const;\n }\n });\n }\n\n graph(): PipelineGraph {\n return cloneGraph(withOutputNode(this.state));\n }\n\n private derive<DerivedOutput>(\n executor: PipelineExecutor<Input, DerivedOutput>,\n state: PipelineState,\n ): Pipeline<Input, DerivedOutput> {\n return createDerivedPipeline(executor, state);\n }\n\n private async execute(\n input: Input,\n context: PipelineRunContext,\n pathPrefix: PipelineNodePath,\n ): Promise<Awaited<Output>> {\n throwIfAborted(context.abortSignal);\n return (await this.executor(input, context, pathPrefix)) as Awaited<Output>;\n }\n}\n\nfunction createDerivedPipeline<Input, Output>(\n executor: PipelineExecutor<Input, Output>,\n state: PipelineState,\n): Pipeline<Input, Output> {\n const options: InternalPipelineOptions<Input, Output> = {\n [internalPipelineOptions]: { executor, state },\n };\n return new Pipeline<Input, Output>(options as unknown as PipelineOptions<Input, Output>);\n}\n\nfunction isInternalPipelineOptions<Input, Output>(\n options: PipelineOptions<Input, Output> | InternalPipelineOptions<Input, Output>,\n): options is InternalPipelineOptions<Input, Output> {\n return internalPipelineOptions in options;\n}\n\nfunction isZodSchema(value: unknown): value is z.ZodType {\n return value instanceof z.ZodType;\n}\n\nfunction normalizePipelineId(id: string): string {\n if (typeof id !== \"string\") {\n throw new TypeError(\"Pipeline id must be a string.\");\n }\n const normalized = id.trim();\n if (normalized.length === 0) {\n throw new TypeError(\"Pipeline id must be a non-empty string.\");\n }\n return normalized;\n}\n\nfunction normalizeRunId(runId: string): string {\n if (typeof runId !== \"string\") {\n throw new TypeError(\"Pipeline runId must be a string.\");\n }\n const normalized = runId.trim();\n if (normalized.length === 0) {\n throw new TypeError(\"Pipeline runId must be a non-empty string.\");\n }\n return normalized;\n}\n\nfunction normalizeParallelBranches<Branch>(\n branches: Readonly<Record<string, Branch>>,\n): Array<readonly [string, Branch]> {\n const entries: Array<readonly [string, Branch]> = [];\n const ids = new Set<string>();\n for (const key of Object.keys(branches)) {\n const pipeline = branches[key] as Branch;\n const id = key.trim();\n if (id.length === 0) {\n throw new TypeError(\"Pipeline parallel branch id must be a non-empty string.\");\n }\n if (ids.has(id)) {\n throw new TypeError(`Pipeline parallel branch id \"${id}\" is already registered.`);\n }\n ids.add(id);\n if (id !== key) {\n throw new TypeError(\"Pipeline parallel branch ids must not contain surrounding whitespace.\");\n }\n entries.push([id, pipeline]);\n }\n return entries;\n}\n","import type { JsonObject } from \"../completion\";\nimport type {\n PipelineGraph,\n PipelineGraphEdge,\n PipelineGraphNode,\n PipelineNodePath,\n PipelineStageKind,\n PipelineStageMetadata,\n PipelineState,\n} from \"./types\";\n\nconst INPUT_ID = \"$input\";\nconst OUTPUT_ID = \"$output\";\nconst RESERVED_STAGE_IDS = new Set([INPUT_ID, OUTPUT_ID]);\n\nexport function initialPipelineState(options: {\n id: string;\n name?: string | undefined;\n description?: string | undefined;\n metadata?: JsonObject | undefined;\n}): PipelineState {\n const input = graphNode(INPUT_ID, [INPUT_ID], \"input\", \"Input\");\n const graph: PipelineGraph = {\n id: options.id,\n nodes: [input],\n edges: [],\n };\n if (options.name !== undefined) graph.name = options.name;\n if (options.description !== undefined) graph.description = options.description;\n if (options.metadata !== undefined) graph.metadata = options.metadata;\n return {\n graph,\n terminalPaths: [input.path],\n stageIds: new Set(),\n nextEdgeIndex: 1,\n };\n}\n\nexport function appendStageNode(\n state: PipelineState,\n kind: PipelineStageKind,\n stage: PipelineStageMetadata,\n options: {\n defaultLabel?: string | undefined;\n agentId?: string | undefined;\n agentName?: string | undefined;\n pipelineId?: string | undefined;\n } = {},\n): { state: PipelineState; node: PipelineGraphNode } {\n const id = validateStageId(stage.id);\n if (state.stageIds.has(id)) {\n throw new TypeError(`Pipeline stage id \"${id}\" is already registered.`);\n }\n const node = graphNode(id, [id], kind, stage.name ?? options.defaultLabel ?? id, {\n description: stage.description,\n metadata: stage.metadata,\n agentId: options.agentId,\n agentName: options.agentName,\n pipelineId: options.pipelineId,\n });\n return {\n node,\n state: appendNode(state, node, state.terminalPaths, [node.path], id),\n };\n}\n\nexport function appendComposedGraph(\n state: PipelineState,\n boundary: PipelineGraphNode,\n child: PipelineGraph,\n): PipelineState {\n return appendChildGraph(state, boundary.path, child);\n}\n\nexport function appendParallelBranch(\n state: PipelineState,\n parallel: PipelineGraphNode,\n branchKey: string,\n child: PipelineGraph,\n): { state: PipelineState; node: PipelineGraphNode; terminalPaths: PipelineNodePath[] } {\n const id = validateStageId(branchKey);\n const path = [...parallel.path, id];\n const node = graphNode(id, path, \"branch\", id, { branchKey: id, pipelineId: child.id });\n const withBranch = appendNode(state, node, [parallel.path], state.terminalPaths);\n const withChild = appendChildGraph(withBranch, node.path, child);\n return { state: withChild, node, terminalPaths: withChild.terminalPaths };\n}\n\nexport function withTerminalPaths(\n state: PipelineState,\n terminalPaths: PipelineNodePath[],\n): PipelineState {\n return { ...state, terminalPaths };\n}\n\nexport function withOutputNode(state: PipelineState): PipelineGraph {\n const graph = cloneGraph(state.graph);\n const outputPath = [OUTPUT_ID];\n if (graph.nodes.some((node) => pathEquals(node.path, outputPath))) {\n return graph;\n }\n graph.nodes.push(graphNode(OUTPUT_ID, outputPath, \"output\", \"Output\"));\n graph.edges.push(\n ...state.terminalPaths.map((source, index) => ({\n id: `edge_${state.nextEdgeIndex + index}`,\n source: [...source],\n target: outputPath,\n })),\n );\n return graph;\n}\n\nexport function cloneGraph(graph: PipelineGraph): PipelineGraph {\n return {\n ...graph,\n nodes: graph.nodes.map((node) => ({ ...node, path: [...node.path] })),\n edges: graph.edges.map((edge) => ({\n ...edge,\n source: [...edge.source],\n target: [...edge.target],\n })),\n };\n}\n\nexport function scopedNode(node: PipelineGraphNode, path: PipelineNodePath): PipelineGraphNode {\n return { ...node, path: [...path] };\n}\n\nfunction appendChildGraph(\n state: PipelineState,\n parentPath: PipelineNodePath,\n child: PipelineGraph,\n): PipelineState {\n const childNodes = child.nodes\n .filter((node) => !isBoundaryPath(node.path))\n .map((node) => scopedNode(node, [...parentPath, ...node.path]));\n const childEdges: PipelineState[\"graph\"][\"edges\"] = [];\n const terminalPaths: PipelineNodePath[] = [];\n let nextEdgeIndex = state.nextEdgeIndex;\n\n for (const edge of child.edges) {\n const sourceIsInput = isInputPath(edge.source);\n const targetIsOutput = isOutputPath(edge.target);\n const source = sourceIsInput ? [...parentPath] : [...parentPath, ...edge.source];\n if (targetIsOutput) {\n terminalPaths.push(source);\n continue;\n }\n const target = [...parentPath, ...edge.target];\n let childEdge: PipelineGraphEdge = {\n id: `edge_${nextEdgeIndex}`,\n source,\n target,\n };\n if (edge.label !== undefined) childEdge = { ...childEdge, label: edge.label };\n childEdges.push(childEdge);\n nextEdgeIndex += 1;\n }\n\n return {\n ...state,\n graph: {\n ...state.graph,\n nodes: [...state.graph.nodes, ...childNodes],\n edges: [...state.graph.edges, ...childEdges],\n },\n terminalPaths: terminalPaths.length === 0 ? [[...parentPath]] : terminalPaths,\n nextEdgeIndex,\n };\n}\n\nfunction appendNode(\n state: PipelineState,\n node: PipelineGraphNode,\n sourcePaths: PipelineNodePath[],\n terminalPaths: PipelineNodePath[],\n stageId?: string,\n): PipelineState {\n const edges = sourcePaths.map((source, index) => ({\n id: `edge_${state.nextEdgeIndex + index}`,\n source: [...source],\n target: [...node.path],\n }));\n const stageIds = new Set(state.stageIds);\n if (stageId !== undefined) stageIds.add(stageId);\n return {\n graph: {\n ...state.graph,\n nodes: [...state.graph.nodes, node],\n edges: [...state.graph.edges, ...edges],\n },\n terminalPaths,\n stageIds,\n nextEdgeIndex: state.nextEdgeIndex + edges.length,\n };\n}\n\nfunction graphNode(\n id: string,\n path: PipelineNodePath,\n kind: PipelineStageKind,\n label: string,\n options: {\n description?: string | undefined;\n metadata?: JsonObject | undefined;\n agentId?: string | undefined;\n agentName?: string | undefined;\n pipelineId?: string | undefined;\n branchKey?: string | undefined;\n } = {},\n): PipelineGraphNode {\n const node: PipelineGraphNode = { id, path: [...path], kind, label };\n if (options.description !== undefined) node.description = options.description;\n if (options.metadata !== undefined) node.metadata = options.metadata;\n if (options.agentId !== undefined) node.agentId = options.agentId;\n if (options.agentName !== undefined) node.agentName = options.agentName;\n if (options.pipelineId !== undefined) node.pipelineId = options.pipelineId;\n if (options.branchKey !== undefined) node.branchKey = options.branchKey;\n return node;\n}\n\nfunction validateStageId(value: string): string {\n if (typeof value !== \"string\") {\n throw new TypeError(\"Pipeline stage id must be a string.\");\n }\n const id = value.trim();\n if (id.length === 0) {\n throw new TypeError(\"Pipeline stage id must be a non-empty string.\");\n }\n if (RESERVED_STAGE_IDS.has(id)) {\n throw new TypeError(`Pipeline stage id \"${id}\" is reserved.`);\n }\n return id;\n}\n\nfunction isBoundaryPath(path: PipelineNodePath): boolean {\n return isInputPath(path) || isOutputPath(path);\n}\n\nfunction isInputPath(path: PipelineNodePath): boolean {\n return path.length === 1 && path[0] === INPUT_ID;\n}\n\nfunction isOutputPath(path: PipelineNodePath): boolean {\n return path.length === 1 && path[0] === OUTPUT_ID;\n}\n\nfunction pathEquals(left: PipelineNodePath, right: PipelineNodePath): boolean {\n return left.length === right.length && left.every((segment, index) => segment === right[index]);\n}\n","import { abortError, throwIfAborted } from \"../internal/abort\";\nimport { scopedNode } from \"./graph\";\nimport type {\n PipelineGraphNode,\n PipelineNodePath,\n PipelineRunContext,\n PipelineRunEvent,\n PipelineStageContext,\n} from \"./types\";\n\nexport async function runNode<Output>(\n context: PipelineRunContext,\n node: PipelineGraphNode,\n path: PipelineNodePath,\n fn: () => Output | Promise<Output>,\n): Promise<Awaited<Output>> {\n throwIfAborted(context.abortSignal);\n const eventNode = scopedNode(node, path);\n const startedAt = Date.now();\n await emitEvent(context, {\n type: \"stage_started\",\n runId: context.runId,\n pipelineId: context.pipelineId,\n path: [...path],\n node: eventNode,\n });\n\n try {\n const output = (await fn()) as Awaited<Output>;\n throwIfAborted(context.abortSignal);\n await emitEvent(context, {\n type: \"stage_completed\",\n runId: context.runId,\n pipelineId: context.pipelineId,\n path: [...path],\n node: eventNode,\n durationMs: Date.now() - startedAt,\n });\n return output;\n } catch (error) {\n const failureEvent: PipelineRunEvent = {\n type: \"stage_failed\",\n runId: context.runId,\n pipelineId: context.pipelineId,\n path: [...path],\n node: eventNode,\n durationMs: Date.now() - startedAt,\n error,\n };\n try {\n await emitEvent(context, failureEvent);\n } catch (observerError) {\n throw new AggregateError(\n [error, observerError],\n `Pipeline stage \"${node.id}\" and its observer both failed.`,\n );\n }\n throw error;\n }\n}\n\nexport function stageContext<Input>(\n input: Input,\n context: PipelineRunContext,\n): PipelineStageContext<Input> {\n return {\n input,\n runId: context.runId,\n pipelineId: context.pipelineId,\n runMetadata: context.runMetadata,\n abortSignal: context.abortSignal,\n };\n}\n\nexport function childContext(\n context: PipelineRunContext,\n abortSignal: AbortSignal | undefined,\n): PipelineRunContext {\n return { ...context, abortSignal };\n}\n\nexport function combineAbortSignals(\n parent: AbortSignal | undefined,\n local: AbortSignal,\n): { signal: AbortSignal; dispose(): void } {\n const controller = new AbortController();\n const abortFromParent = () => controller.abort(parent?.reason);\n const abortFromLocal = () => controller.abort(local.reason);\n\n if (parent?.aborted === true) {\n controller.abort(parent.reason);\n } else if (local.aborted) {\n controller.abort(local.reason);\n } else {\n parent?.addEventListener(\"abort\", abortFromParent, { once: true });\n local.addEventListener(\"abort\", abortFromLocal, { once: true });\n }\n\n return {\n signal: controller.signal,\n dispose() {\n parent?.removeEventListener(\"abort\", abortFromParent);\n local.removeEventListener(\"abort\", abortFromLocal);\n },\n };\n}\n\nexport function pipelineAbortError(signal: AbortSignal | undefined): Error {\n return abortError(signal?.reason);\n}\n\nasync function emitEvent(context: PipelineRunContext, event: PipelineRunEvent): Promise<void> {\n if (context.observer === undefined) return;\n try {\n await context.observer.onEvent(event);\n } catch (error) {\n if (context.failOnObserverError) throw error;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAEO,IAAM,+BAAN,cAA2C,MAAM;AAAA,EACtD,YAAqB,QAA8B;AACjD,UAAM,uDAAuD;AAD1C;AAEnB,SAAK,OAAO;AAAA,EACd;AAAA,EAHqB;AAIvB;;;ACPA,SAAS,SAAS;;;ACWlB,IAAM,WAAW;AACjB,IAAM,YAAY;AAClB,IAAM,qBAAqB,oBAAI,IAAI,CAAC,UAAU,SAAS,C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nB,YAAM,IAAI,UAAU,yDAAyD;AAAA,IAC/E;AACA,QAAI,IAAI,IAAI,EAAE,GAAG;AACf,YAAM,IAAI,UAAU,gCAAgC,EAAE,0BAA0B;AAAA,IAClF;AACA,QAAI,IAAI,EAAE;AACV,QAAI,OAAO,KAAK;AACd,YAAM,IAAI,UAAU,uEAAuE;AAAA,IAC7F;AACA,YAAQ,KAAK,CAAC,IAAI,QAAQ,CAAC;AAAA,EAC7B;AACA,SAAO;AACT;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/pipeline/errors.ts","../../src/pipeline/pipeline.ts","../../src/pipeline/graph.ts","../../src/pipeline/runtime.ts"],"sourcesContent":["import type { AgentInteractionOutcome } from \"../agent/run-types\";\n\nexport class PipelineAgentSuspensionError extends Error {\n constructor(readonly result: AgentInteractionOutcome) {\n super(\"Pipeline agent stage suspended for human interaction.\");\n this.name = \"PipelineAgentSuspensionError\";\n }\n}\n","import { z } from \"zod\";\nimport type { Agent } from \"../agent/agent\";\nimport { AgentRunBlockedError } from \"../agent/errors\";\nimport type { AgentInput, AgentRunOptions, AgentRunSettings } from \"../agent/run-types\";\nimport type { CompletionModel, JsonObject } from \"../completion\";\nimport { type ExtractOptions, extract as extractData } from \"../extractor\";\nimport { throwIfAborted } from \"../internal/abort\";\nimport { mapWithConcurrency } from \"../internal/concurrency\";\nimport { PipelineAgentSuspensionError } from \"./errors\";\nimport {\n appendComposedGraph,\n appendParallelBranch,\n appendStageNode,\n cloneGraph,\n initialPipelineState,\n withOutputNode,\n withTerminalPaths,\n} from \"./graph\";\nimport {\n childContext,\n combineAbortSignals,\n pipelineAbortError,\n runNode,\n stageContext,\n} from \"./runtime\";\nimport type {\n ParallelOutput,\n PipelineBatchItem,\n PipelineBatchOptions,\n PipelineExecutor,\n PipelineGraph,\n PipelineGraphNode,\n PipelineNodePath,\n PipelineOptions,\n PipelineRunContext,\n PipelineRunOptions,\n PipelineRunResult,\n PipelineStageContext,\n PipelineStageMetadata,\n PipelineState,\n} from \"./types\";\n\nconst internalPipelineOptions = Symbol(\"internal-pipeline-options\");\n\ntype RawResponseOf<Model> =\n Model extends CompletionModel<infer RawResponse> ? RawResponse : unknown;\n\ntype PipelineAgentRequest<Output, Model extends CompletionModel> = AgentInput &\n Omit<AgentRunSettings<Output, RawResponseOf<Model>>, \"abortSignal\">;\n\nexport type PipelineStepOptions<Input, Output> = PipelineStageMetadata & {\n run(context: PipelineStageContext<Input>): Output | Promise<Output>;\n};\n\nexport type PipelineComposeOptions<Input, Output> = PipelineStageMetadata & {\n pipeline: Pipeline<Input, Output>;\n};\n\nexport type PipelineParallelOptions<\n Input,\n Branches extends Record<string, Pipeline<Input, unknown>>,\n> = PipelineStageMetadata & {\n branches: Branches;\n};\n\nexport type PipelineAgentOptions<\n Input,\n AgentOutput,\n Model extends CompletionModel,\n> = PipelineStageMetadata & {\n agent: Agent<AgentOutput, Model>;\n request(\n context: PipelineStageContext<Input>,\n ): PipelineAgentRequest<AgentOutput, Model> | Promise<PipelineAgentRequest<AgentOutput, Model>>;\n suspension: \"reject\";\n};\n\nexport type PipelineExtractOptions<\n Input,\n Extracted,\n Model extends CompletionModel,\n> = PipelineStageMetadata &\n Omit<ExtractOptions<Extracted, Model>, \"text\" | \"abortSignal\"> & {\n text(context: PipelineStageContext<Input>): string | Promise<string>;\n };\n\ntype InternalPipelineOptions<Input, Output> = {\n [internalPipelineOptions]: {\n executor: PipelineExecutor<Input, Output>;\n state: PipelineState;\n };\n};\n\n/** Immutable, typed Pipeline with explicit stage and execution boundaries. */\nexport class Pipeline<Input, Output = Input> {\n readonly id: string;\n readonly name: string | undefined;\n readonly description: string | undefined;\n readonly metadata: JsonObject | undefined;\n\n private readonly executor: PipelineExecutor<Input, Output>;\n private readonly state: PipelineState;\n\n constructor(options: PipelineOptions<Input, Output>);\n constructor(options: PipelineOptions<Input, Output> | InternalPipelineOptions<Input, Output>) {\n if (isInternalPipelineOptions(options)) {\n this.executor = options[internalPipelineOptions].executor;\n this.state = options[internalPipelineOptions].state;\n } else {\n const id = normalizePipelineId(options.id);\n if (!isZodSchema(options.inputSchema)) {\n throw new TypeError(\"Pipeline inputSchema must be a Zod schema.\");\n }\n const inputSchema = options.inputSchema;\n this.executor = (async (input, context) => {\n throwIfAborted(context.abortSignal);\n return inputSchema.parseAsync(input) as Promise<Output>;\n }) as PipelineExecutor<Input, Output>;\n this.state = initialPipelineState({\n id,\n name: options.name,\n description: options.description,\n metadata: options.metadata,\n });\n }\n\n const graph = this.state.graph;\n this.id = graph.id;\n this.name = graph.name;\n this.description = graph.description;\n this.metadata = graph.metadata;\n }\n\n step<Next>(options: PipelineStepOptions<Awaited<Output>, Next>): Pipeline<Input, Awaited<Next>> {\n const next = appendStageNode(this.state, \"step\", options);\n const executor = (async (input, context, pathPrefix) => {\n const value = await this.execute(input, context, pathPrefix);\n const path = [...pathPrefix, next.node.id];\n return (await runNode(context, next.node, path, () =>\n options.run(stageContext(value, context)),\n )) as Awaited<Next>;\n }) as PipelineExecutor<Input, Awaited<Next>>;\n return this.derive(executor, next.state);\n }\n\n compose<Next>(\n options: PipelineComposeOptions<Awaited<Output>, Next>,\n ): Pipeline<Input, Awaited<Next>> {\n const boundary = appendStageNode(this.state, \"pipeline\", options, {\n defaultLabel: options.pipeline.name ?? options.pipeline.id,\n pipelineId: options.pipeline.id,\n });\n const state = appendComposedGraph(boundary.state, boundary.node, options.pipeline.graph());\n const executor = (async (input, context, pathPrefix) => {\n const value = await this.execute(input, context, pathPrefix);\n const path = [...pathPrefix, boundary.node.id];\n return (await runNode(context, boundary.node, path, () =>\n options.pipeline.execute(value, context, path),\n )) as Awaited<Next>;\n }) as PipelineExecutor<Input, Awaited<Next>>;\n return this.derive(executor, state);\n }\n\n parallel<Branches extends Record<string, Pipeline<Awaited<Output>, unknown>>>(\n options: PipelineParallelOptions<Awaited<Output>, Branches>,\n ): Pipeline<Input, ParallelOutput<Branches>> {\n const branchEntries = normalizeParallelBranches(options.branches);\n if (branchEntries.length === 0) {\n throw new TypeError(\"Pipeline parallel branches must not be empty.\");\n }\n const parallel = appendStageNode(this.state, \"parallel\", options, {\n defaultLabel: `${branchEntries.length} parallel branches`,\n });\n let nextState = parallel.state;\n const branchNodes = new Map<string, PipelineGraphNode>();\n const terminalPaths: PipelineNodePath[] = [];\n for (const [key, branch] of branchEntries) {\n const appended = appendParallelBranch(nextState, parallel.node, key, branch.graph());\n nextState = appended.state;\n branchNodes.set(key, appended.node);\n terminalPaths.push(...appended.terminalPaths);\n }\n nextState = withTerminalPaths(nextState, terminalPaths);\n\n return this.derive<ParallelOutput<Branches>>(async (input, context, pathPrefix) => {\n const value = await this.execute(input, context, pathPrefix);\n const parallelPath = [...pathPrefix, parallel.node.id];\n return runNode(context, parallel.node, parallelPath, async () => {\n const controller = new AbortController();\n const combined = combineAbortSignals(context.abortSignal, controller.signal);\n const branchContext = childContext(context, combined.signal);\n let firstError: unknown;\n const promises = branchEntries.map(async ([key, branch]) => {\n const node = branchNodes.get(key) as PipelineGraphNode;\n const path = [...parallelPath, node.id];\n try {\n const output = await runNode(branchContext, node, path, () =>\n branch.execute(value, branchContext, path),\n );\n return [key, output] as const;\n } catch (error) {\n if (firstError === undefined) firstError = error;\n if (!controller.signal.aborted) controller.abort(error);\n throw error;\n }\n });\n\n const settled = await Promise.allSettled(promises);\n combined.dispose();\n if (context.abortSignal?.aborted === true) {\n throw pipelineAbortError(context.abortSignal);\n }\n if (firstError !== undefined) throw firstError;\n return Object.fromEntries(\n settled.map(\n (result) => (result as PromiseFulfilledResult<readonly [string, unknown]>).value,\n ),\n ) as ParallelOutput<Branches>;\n });\n }, nextState);\n }\n\n agent<AgentOutput, Model extends CompletionModel>(\n options: PipelineAgentOptions<Awaited<Output>, AgentOutput, Model>,\n ): Pipeline<Input, AgentOutput> {\n if (options.suspension !== \"reject\") {\n throw new TypeError('Pipeline Agent stages require suspension: \"reject\".');\n }\n const next = appendStageNode(this.state, \"agent\", options, {\n defaultLabel: options.agent.name ?? options.agent.id,\n agentId: options.agent.id,\n agentName: options.agent.name,\n });\n return this.derive<AgentOutput>(async (input, context, pathPrefix) => {\n const value = await this.execute(input, context, pathPrefix);\n const path = [...pathPrefix, next.node.id];\n return runNode(context, next.node, path, async () => {\n const request = await options.request(stageContext(value, context));\n const response = await options.agent.generate({\n ...request,\n abortSignal: context.abortSignal,\n } as AgentRunOptions<AgentOutput, RawResponseOf<Model>>);\n if (response.type === \"interaction\") {\n throw new PipelineAgentSuspensionError(response);\n }\n if (response.type === \"blocked\") {\n throw new AgentRunBlockedError(response);\n }\n return response.output;\n });\n }, next.state);\n }\n\n extract<Extracted, Model extends CompletionModel>(\n options: PipelineExtractOptions<Awaited<Output>, Extracted, Model>,\n ): Pipeline<Input, Extracted> {\n const next = appendStageNode(this.state, \"extractor\", options);\n return this.derive<Extracted>(async (input, context, pathPrefix) => {\n const value = await this.execute(input, context, pathPrefix);\n const path = [...pathPrefix, next.node.id];\n return runNode(context, next.node, path, async () => {\n const text = await options.text(stageContext(value, context));\n const result = await extractData({\n model: options.model,\n text,\n outputSchema: options.outputSchema,\n instructions: options.instructions,\n retries: options.retries,\n temperature: options.temperature,\n maxTokens: options.maxTokens,\n providerOptions: options.providerOptions,\n abortSignal: context.abortSignal,\n });\n return result.output;\n });\n }, next.state);\n }\n\n async run(options: PipelineRunOptions<Input>): Promise<PipelineRunResult<Output>> {\n const runId = normalizeRunId(options.runId ?? globalThis.crypto.randomUUID());\n const context: PipelineRunContext = {\n runId,\n pipelineId: this.id,\n runMetadata: options.metadata,\n abortSignal: options.abortSignal,\n observer: options.observer,\n failOnObserverError: options.failOnObserverError === true,\n };\n throwIfAborted(context.abortSignal);\n const output = await this.execute(options.input, context, []);\n throwIfAborted(context.abortSignal);\n return { runId, output };\n }\n\n async runBatch(options: PipelineBatchOptions<Input>): Promise<Array<PipelineBatchItem<Output>>> {\n throwIfAborted(options.abortSignal);\n return mapWithConcurrency([...options.inputs], options.concurrency, async (input) => {\n const runId = globalThis.crypto.randomUUID();\n try {\n const result = await this.run({\n input,\n runId,\n metadata: options.metadata,\n abortSignal: options.abortSignal,\n observer: options.observer,\n failOnObserverError: options.failOnObserverError,\n });\n return { status: \"completed\", ...result } as const;\n } catch (error) {\n if (options.abortSignal?.aborted === true) {\n throw pipelineAbortError(options.abortSignal);\n }\n return { status: \"failed\", runId, error } as const;\n }\n });\n }\n\n graph(): PipelineGraph {\n return cloneGraph(withOutputNode(this.state));\n }\n\n private derive<DerivedOutput>(\n executor: PipelineExecutor<Input, DerivedOutput>,\n state: PipelineState,\n ): Pipeline<Input, DerivedOutput> {\n return createDerivedPipeline(executor, state);\n }\n\n private async execute(\n input: Input,\n context: PipelineRunContext,\n pathPrefix: PipelineNodePath,\n ): Promise<Awaited<Output>> {\n throwIfAborted(context.abortSignal);\n return (await this.executor(input, context, pathPrefix)) as Awaited<Output>;\n }\n}\n\nfunction createDerivedPipeline<Input, Output>(\n executor: PipelineExecutor<Input, Output>,\n state: PipelineState,\n): Pipeline<Input, Output> {\n const options: InternalPipelineOptions<Input, Output> = {\n [internalPipelineOptions]: { executor, state },\n };\n return new Pipeline<Input, Output>(options as unknown as PipelineOptions<Input, Output>);\n}\n\nfunction isInternalPipelineOptions<Input, Output>(\n options: PipelineOptions<Input, Output> | InternalPipelineOptions<Input, Output>,\n): options is InternalPipelineOptions<Input, Output> {\n return internalPipelineOptions in options;\n}\n\nfunction isZodSchema(value: unknown): value is z.ZodType {\n return value instanceof z.ZodType;\n}\n\nfunction normalizePipelineId(id: string): string {\n if (typeof id !== \"string\") {\n throw new TypeError(\"Pipeline id must be a string.\");\n }\n const normalized = id.trim();\n if (normalized.length === 0) {\n throw new TypeError(\"Pipeline id must be a non-empty string.\");\n }\n return normalized;\n}\n\nfunction normalizeRunId(runId: string): string {\n if (typeof runId !== \"string\") {\n throw new TypeError(\"Pipeline runId must be a string.\");\n }\n const normalized = runId.trim();\n if (normalized.length === 0) {\n throw new TypeError(\"Pipeline runId must be a non-empty string.\");\n }\n return normalized;\n}\n\nfunction normalizeParallelBranches<Branch>(\n branches: Readonly<Record<string, Branch>>,\n): Array<readonly [string, Branch]> {\n const entries: Array<readonly [string, Branch]> = [];\n const ids = new Set<string>();\n for (const key of Object.keys(branches)) {\n const pipeline = branches[key] as Branch;\n const id = key.trim();\n if (id.length === 0) {\n throw new TypeError(\"Pipeline parallel branch id must be a non-empty string.\");\n }\n if (ids.has(id)) {\n throw new TypeError(`Pipeline parallel branch id \"${id}\" is already registered.`);\n }\n ids.add(id);\n if (id !== key) {\n throw new TypeError(\"Pipeline parallel branch ids must not contain surrounding whitespace.\");\n }\n entries.push([id, pipeline]);\n }\n return entries;\n}\n","import type { JsonObject } from \"../completion\";\nimport type {\n PipelineGraph,\n PipelineGraphEdge,\n PipelineGraphNode,\n PipelineNodePath,\n PipelineStageKind,\n PipelineStageMetadata,\n PipelineState,\n} from \"./types\";\n\nconst INPUT_ID = \"$input\";\nconst OUTPUT_ID = \"$output\";\nconst RESERVED_STAGE_IDS = new Set([INPUT_ID, OUTPUT_ID]);\n\nexport function initialPipelineState(options: {\n id: string;\n name?: string | undefined;\n description?: string | undefined;\n metadata?: JsonObject | undefined;\n}): PipelineState {\n const input = graphNode(INPUT_ID, [INPUT_ID], \"input\", \"Input\");\n const graph: PipelineGraph = {\n id: options.id,\n nodes: [input],\n edges: [],\n };\n if (options.name !== undefined) graph.name = options.name;\n if (options.description !== undefined) graph.description = options.description;\n if (options.metadata !== undefined) graph.metadata = options.metadata;\n return {\n graph,\n terminalPaths: [input.path],\n stageIds: new Set(),\n nextEdgeIndex: 1,\n };\n}\n\nexport function appendStageNode(\n state: PipelineState,\n kind: PipelineStageKind,\n stage: PipelineStageMetadata,\n options: {\n defaultLabel?: string | undefined;\n agentId?: string | undefined;\n agentName?: string | undefined;\n pipelineId?: string | undefined;\n } = {},\n): { state: PipelineState; node: PipelineGraphNode } {\n const id = validateStageId(stage.id);\n if (state.stageIds.has(id)) {\n throw new TypeError(`Pipeline stage id \"${id}\" is already registered.`);\n }\n const node = graphNode(id, [id], kind, stage.name ?? options.defaultLabel ?? id, {\n description: stage.description,\n metadata: stage.metadata,\n agentId: options.agentId,\n agentName: options.agentName,\n pipelineId: options.pipelineId,\n });\n return {\n node,\n state: appendNode(state, node, state.terminalPaths, [node.path], id),\n };\n}\n\nexport function appendComposedGraph(\n state: PipelineState,\n boundary: PipelineGraphNode,\n child: PipelineGraph,\n): PipelineState {\n return appendChildGraph(state, boundary.path, child);\n}\n\nexport function appendParallelBranch(\n state: PipelineState,\n parallel: PipelineGraphNode,\n branchKey: string,\n child: PipelineGraph,\n): { state: PipelineState; node: PipelineGraphNode; terminalPaths: PipelineNodePath[] } {\n const id = validateStageId(branchKey);\n const path = [...parallel.path, id];\n const node = graphNode(id, path, \"branch\", id, { branchKey: id, pipelineId: child.id });\n const withBranch = appendNode(state, node, [parallel.path], state.terminalPaths);\n const withChild = appendChildGraph(withBranch, node.path, child);\n return { state: withChild, node, terminalPaths: withChild.terminalPaths };\n}\n\nexport function withTerminalPaths(\n state: PipelineState,\n terminalPaths: PipelineNodePath[],\n): PipelineState {\n return { ...state, terminalPaths };\n}\n\nexport function withOutputNode(state: PipelineState): PipelineGraph {\n const graph = cloneGraph(state.graph);\n const outputPath = [OUTPUT_ID];\n if (graph.nodes.some((node) => pathEquals(node.path, outputPath))) {\n return graph;\n }\n graph.nodes.push(graphNode(OUTPUT_ID, outputPath, \"output\", \"Output\"));\n graph.edges.push(\n ...state.terminalPaths.map((source, index) => ({\n id: `edge_${state.nextEdgeIndex + index}`,\n source: [...source],\n target: outputPath,\n })),\n );\n return graph;\n}\n\nexport function cloneGraph(graph: PipelineGraph): PipelineGraph {\n return {\n ...graph,\n nodes: graph.nodes.map((node) => ({ ...node, path: [...node.path] })),\n edges: graph.edges.map((edge) => ({\n ...edge,\n source: [...edge.source],\n target: [...edge.target],\n })),\n };\n}\n\nexport function scopedNode(node: PipelineGraphNode, path: PipelineNodePath): PipelineGraphNode {\n return { ...node, path: [...path] };\n}\n\nfunction appendChildGraph(\n state: PipelineState,\n parentPath: PipelineNodePath,\n child: PipelineGraph,\n): PipelineState {\n const childNodes = child.nodes\n .filter((node) => !isBoundaryPath(node.path))\n .map((node) => scopedNode(node, [...parentPath, ...node.path]));\n const childEdges: PipelineState[\"graph\"][\"edges\"] = [];\n const terminalPaths: PipelineNodePath[] = [];\n let nextEdgeIndex = state.nextEdgeIndex;\n\n for (const edge of child.edges) {\n const sourceIsInput = isInputPath(edge.source);\n const targetIsOutput = isOutputPath(edge.target);\n const source = sourceIsInput ? [...parentPath] : [...parentPath, ...edge.source];\n if (targetIsOutput) {\n terminalPaths.push(source);\n continue;\n }\n const target = [...parentPath, ...edge.target];\n let childEdge: PipelineGraphEdge = {\n id: `edge_${nextEdgeIndex}`,\n source,\n target,\n };\n if (edge.label !== undefined) childEdge = { ...childEdge, label: edge.label };\n childEdges.push(childEdge);\n nextEdgeIndex += 1;\n }\n\n return {\n ...state,\n graph: {\n ...state.graph,\n nodes: [...state.graph.nodes, ...childNodes],\n edges: [...state.graph.edges, ...childEdges],\n },\n terminalPaths: terminalPaths.length === 0 ? [[...parentPath]] : terminalPaths,\n nextEdgeIndex,\n };\n}\n\nfunction appendNode(\n state: PipelineState,\n node: PipelineGraphNode,\n sourcePaths: PipelineNodePath[],\n terminalPaths: PipelineNodePath[],\n stageId?: string,\n): PipelineState {\n const edges = sourcePaths.map((source, index) => ({\n id: `edge_${state.nextEdgeIndex + index}`,\n source: [...source],\n target: [...node.path],\n }));\n const stageIds = new Set(state.stageIds);\n if (stageId !== undefined) stageIds.add(stageId);\n return {\n graph: {\n ...state.graph,\n nodes: [...state.graph.nodes, node],\n edges: [...state.graph.edges, ...edges],\n },\n terminalPaths,\n stageIds,\n nextEdgeIndex: state.nextEdgeIndex + edges.length,\n };\n}\n\nfunction graphNode(\n id: string,\n path: PipelineNodePath,\n kind: PipelineStageKind,\n label: string,\n options: {\n description?: string | undefined;\n metadata?: JsonObject | undefined;\n agentId?: string | undefined;\n agentName?: string | undefined;\n pipelineId?: string | undefined;\n branchKey?: string | undefined;\n } = {},\n): PipelineGraphNode {\n const node: PipelineGraphNode = { id, path: [...path], kind, label };\n if (options.description !== undefined) node.description = options.description;\n if (options.metadata !== undefined) node.metadata = options.metadata;\n if (options.agentId !== undefined) node.agentId = options.agentId;\n if (options.agentName !== undefined) node.agentName = options.agentName;\n if (options.pipelineId !== undefined) node.pipelineId = options.pipelineId;\n if (options.branchKey !== undefined) node.branchKey = options.branchKey;\n return node;\n}\n\nfunction validateStageId(value: string): string {\n if (typeof value !== \"string\") {\n throw new TypeError(\"Pipeline stage id must be a string.\");\n }\n const id = value.trim();\n if (id.length === 0) {\n throw new TypeError(\"Pipeline stage id must be a non-empty string.\");\n }\n if (RESERVED_STAGE_IDS.has(id)) {\n throw new TypeError(`Pipeline stage id \"${id}\" is reserved.`);\n }\n return id;\n}\n\nfunction isBoundaryPath(path: PipelineNodePath): boolean {\n return isInputPath(path) || isOutputPath(path);\n}\n\nfunction isInputPath(path: PipelineNodePath): boolean {\n return path.length === 1 && path[0] === INPUT_ID;\n}\n\nfunction isOutputPath(path: PipelineNodePath): boolean {\n return path.length === 1 && path[0] === OUTPUT_ID;\n}\n\nfunction pathEquals(left: PipelineNodePath, right: PipelineNodePath): boolean {\n return left.length === right.length && left.every((segment, index) => segment === right[index]);\n}\n","import { abortError, throwIfAborted } from \"../internal/abort\";\nimport { scopedNode } from \"./graph\";\nimport type {\n PipelineGraphNode,\n PipelineNodePath,\n PipelineRunContext,\n PipelineRunEvent,\n PipelineStageContext,\n} from \"./types\";\n\nexport async function runNode<Output>(\n context: PipelineRunContext,\n node: PipelineGraphNode,\n path: PipelineNodePath,\n fn: () => Output | Promise<Output>,\n): Promise<Awaited<Output>> {\n throwIfAborted(context.abortSignal);\n const eventNode = scopedNode(node, path);\n const startedAt = Date.now();\n await emitEvent(context, {\n type: \"stage_started\",\n runId: context.runId,\n pipelineId: context.pipelineId,\n path: [...path],\n node: eventNode,\n });\n\n try {\n const output = (await fn()) as Awaited<Output>;\n throwIfAborted(context.abortSignal);\n await emitEvent(context, {\n type: \"stage_completed\",\n runId: context.runId,\n pipelineId: context.pipelineId,\n path: [...path],\n node: eventNode,\n durationMs: Date.now() - startedAt,\n });\n return output;\n } catch (error) {\n const failureEvent: PipelineRunEvent = {\n type: \"stage_failed\",\n runId: context.runId,\n pipelineId: context.pipelineId,\n path: [...path],\n node: eventNode,\n durationMs: Date.now() - startedAt,\n error,\n };\n try {\n await emitEvent(context, failureEvent);\n } catch (observerError) {\n throw new AggregateError(\n [error, observerError],\n `Pipeline stage \"${node.id}\" and its observer both failed.`,\n );\n }\n throw error;\n }\n}\n\nexport function stageContext<Input>(\n input: Input,\n context: PipelineRunContext,\n): PipelineStageContext<Input> {\n return {\n input,\n runId: context.runId,\n pipelineId: context.pipelineId,\n runMetadata: context.runMetadata,\n abortSignal: context.abortSignal,\n };\n}\n\nexport function childContext(\n context: PipelineRunContext,\n abortSignal: AbortSignal | undefined,\n): PipelineRunContext {\n return { ...context, abortSignal };\n}\n\nexport function combineAbortSignals(\n parent: AbortSignal | undefined,\n local: AbortSignal,\n): { signal: AbortSignal; dispose(): void } {\n const controller = new AbortController();\n const abortFromParent = () => controller.abort(parent?.reason);\n const abortFromLocal = () => controller.abort(local.reason);\n\n if (parent?.aborted === true) {\n controller.abort(parent.reason);\n } else if (local.aborted) {\n controller.abort(local.reason);\n } else {\n parent?.addEventListener(\"abort\", abortFromParent, { once: true });\n local.addEventListener(\"abort\", abortFromLocal, { once: true });\n }\n\n return {\n signal: controller.signal,\n dispose() {\n parent?.removeEventListener(\"abort\", abortFromParent);\n local.removeEventListener(\"abort\", abortFromLocal);\n },\n };\n}\n\nexport function pipelineAbortError(signal: AbortSignal | undefined): Error {\n return abortError(signal?.reason);\n}\n\nasync function emitEvent(context: PipelineRunContext, event: PipelineRunEvent): Promise<void> {\n if (context.observer === undefined) return;\n try {\n await context.observer.onEvent(event);\n } catch (error) {\n if (context.failOnObserverError) throw error;\n }\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W,GAAG;AAC3B,UAAM,IAAI,UAAU,4CAA4C;AAAA,EAClE;AACA,SAAO;AACT;AAEA,SAAS,0BACP,UACkC;AAClC,QAAM,UAA4C,CAAC;AACnD,QAAM,MAAM,oBAAI,IAAY;AAC5B,aAAW,OAAO,OAAO,KAAK,QAAQ,GAAG;AACvC,UAAM,WAAW,SAAS,GAAG;AAC7B,UAAM,KAAK,IAAI,KAAK;AACpB,QAAI,GAAG,WAAW,GAAG;AACnB,YAAM,IAAI,UAAU,yDAAyD;AAAA,IAC/E;AACA,QAAI,IAAI,IAAI,EAAE,GAAG;AACf,YAAM,IAAI,UAAU,gCAAgC,EAAE,0BAA0B;AAAA,IAClF;AACA,QAAI,IAAI,EAAE;AACV,QAAI,OAAO,KAAK;AACd,YAAM,IAAI,UAAU,uEAAuE;AAAA,IAC7F;AACA,YAAQ,KAAK,CAAC,IAAI,QAAQ,CAAC;AAAA,EAC7B;AACA,SAAO;AACT;","names":[]}
|
package/dist/skills/index.js
CHANGED
|
@@ -2,12 +2,12 @@ import {
|
|
|
2
2
|
SkillValidationError,
|
|
3
3
|
loadSkills,
|
|
4
4
|
skill
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-IWJK7JB5.js";
|
|
6
6
|
import "../chunk-YK4WAAS4.js";
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-
|
|
9
|
-
import "../chunk-
|
|
10
|
-
import "../chunk-
|
|
7
|
+
import "../chunk-EO2GECYH.js";
|
|
8
|
+
import "../chunk-YFJ4NHV6.js";
|
|
9
|
+
import "../chunk-K5L7R7XM.js";
|
|
10
|
+
import "../chunk-IZNOP6JG.js";
|
|
11
11
|
import "../chunk-QGX73TSQ.js";
|
|
12
12
|
import "../chunk-3XQGVDU5.js";
|
|
13
13
|
import "../chunk-3RWESPUG.js";
|
package/dist/tool/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
embedTools,
|
|
7
7
|
isQuestionTool,
|
|
8
8
|
isToolIndex
|
|
9
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-EO2GECYH.js";
|
|
10
10
|
import {
|
|
11
11
|
ToolCallError,
|
|
12
12
|
ToolJsonError,
|
|
@@ -17,9 +17,9 @@ import {
|
|
|
17
17
|
normalizeToolResultOutput,
|
|
18
18
|
parseToolArgs,
|
|
19
19
|
toolResultContentToText
|
|
20
|
-
} from "../chunk-
|
|
21
|
-
import "../chunk-
|
|
22
|
-
import "../chunk-
|
|
20
|
+
} from "../chunk-YFJ4NHV6.js";
|
|
21
|
+
import "../chunk-K5L7R7XM.js";
|
|
22
|
+
import "../chunk-IZNOP6JG.js";
|
|
23
23
|
import "../chunk-QGX73TSQ.js";
|
|
24
24
|
import "../chunk-3XQGVDU5.js";
|
|
25
25
|
import "../chunk-3RWESPUG.js";
|
|
@@ -2,7 +2,7 @@ import { AgentInteractionRequest, AgentContinuation, AgentInteractionResponse }
|
|
|
2
2
|
import { b as RetrySetting } from './retry-CjvSlKGW.js';
|
|
3
3
|
import { M as Message, g as CompletionResponse, U as Usage, R as ReasoningContentType, u as ToolCallPart, i as CompletionSource, r as ProviderToolCall, G as UserMessage, C as CompletionFinishReason, l as ContextUsage, f as CompletionRequest, z as ToolResultOutput, y as ToolResultContentPart, _ as ToolInteractionResponsePart, Z as ToolCallArgumentsMode, J as JsonObject, V as CompletionModelCapabilities, w as ToolDefinition } from './types-DgvozfPc.js';
|
|
4
4
|
import { d as GuardrailPolicyInput, a as GuardrailDecisionRecord } from './types-DhkodEft.js';
|
|
5
|
-
import { e as MemoryCompactionInfo,
|
|
5
|
+
import { e as MemoryCompactionInfo, A as MemoryScope } from './types-CSYt7-It.js';
|
|
6
6
|
import { D as DeepReadonly, M as MaybePromise } from './type-utils-CtHVDRn_.js';
|
|
7
7
|
import { d as ToolCallStreamEvent } from './tool-BpqpoRSE.js';
|
|
8
8
|
import { A as AgentMiddleware } from './middleware-kcF8AusP.js';
|
|
@@ -104,11 +104,15 @@ type AgentRunSettings<Output = string, RawResponse = unknown> = {
|
|
|
104
104
|
trace?: AgentTraceOptions | undefined;
|
|
105
105
|
};
|
|
106
106
|
type AgentRunOptions<Output = string, RawResponse = unknown> = AgentInput & AgentRunSettings<Output, RawResponse>;
|
|
107
|
+
type AgentMemoryCompactionOptions = {
|
|
108
|
+
session: MemoryScope;
|
|
109
|
+
abortSignal?: AbortSignal | undefined;
|
|
110
|
+
};
|
|
107
111
|
type AgentRunLink = Readonly<{
|
|
108
112
|
runId: string;
|
|
109
113
|
interactionId: string;
|
|
110
114
|
}>;
|
|
111
|
-
type
|
|
115
|
+
type AgentOutcomeBase = {
|
|
112
116
|
runId: string;
|
|
113
117
|
text: string;
|
|
114
118
|
usage: Usage;
|
|
@@ -123,20 +127,22 @@ type AgentResultBase = {
|
|
|
123
127
|
memoryCompaction?: MemoryCompactionInfo | undefined;
|
|
124
128
|
resumedFrom?: AgentRunLink | undefined;
|
|
125
129
|
};
|
|
126
|
-
type AgentResponse<Output = string> =
|
|
127
|
-
|
|
130
|
+
type AgentResponse<Output = string> = AgentOutcomeBase & {
|
|
131
|
+
type: "response";
|
|
128
132
|
output: Output;
|
|
129
133
|
};
|
|
130
|
-
type
|
|
131
|
-
|
|
134
|
+
type AgentBlockedOutcome = AgentOutcomeBase & {
|
|
135
|
+
type: "blocked";
|
|
132
136
|
stage: "input" | "output";
|
|
137
|
+
reason: string;
|
|
138
|
+
message?: string | undefined;
|
|
133
139
|
};
|
|
134
|
-
type
|
|
135
|
-
|
|
140
|
+
type AgentInteractionOutcome = AgentOutcomeBase & {
|
|
141
|
+
type: "interaction";
|
|
136
142
|
interaction: AgentInteractionRequest;
|
|
137
143
|
continuation: AgentContinuation;
|
|
138
144
|
};
|
|
139
|
-
type
|
|
145
|
+
type AgentOutcome<Output = string> = AgentResponse<Output> | AgentBlockedOutcome | AgentInteractionOutcome;
|
|
140
146
|
type AgentDeltaEvent = {
|
|
141
147
|
type: "text_delta";
|
|
142
148
|
delta: string;
|
|
@@ -241,10 +247,7 @@ type AgentChildStreamEventBase<Output = string, RawResponse = unknown> = {
|
|
|
241
247
|
type: "guardrail_decision";
|
|
242
248
|
turn?: number | undefined;
|
|
243
249
|
decision: GuardrailDecisionRecord;
|
|
244
|
-
} | AgentMemoryCompactionEvent | AgentInteractionResponseEvent | AgentSteeringAppliedEvent |
|
|
245
|
-
type: "final";
|
|
246
|
-
result: AgentResult<Output>;
|
|
247
|
-
} | AgentErrorStreamEvent;
|
|
250
|
+
} | AgentMemoryCompactionEvent | AgentInteractionResponseEvent | AgentSteeringAppliedEvent | AgentOutcome<Output> | AgentErrorStreamEvent;
|
|
248
251
|
type AgentChildStreamEvent<Output = string, RawResponse = unknown> = AgentChildStreamEventBase<Output, RawResponse> | AgentToolCallDeltaEvent;
|
|
249
252
|
type AgentToolStreamEvent = {
|
|
250
253
|
type: "agent_tool_event";
|
|
@@ -257,8 +260,13 @@ type AgentToolStreamEvent = {
|
|
|
257
260
|
event: AgentChildStreamEvent<unknown, unknown>;
|
|
258
261
|
};
|
|
259
262
|
type AgentStreamEvent<Output = string, RawResponse = unknown> = AgentChildStreamEvent<Output, RawResponse> | AgentToolStreamEvent;
|
|
260
|
-
interface AgentStream<
|
|
263
|
+
interface AgentStream<Output = string, RawResponse = unknown> extends AsyncIterable<AgentStreamEvent<Output, RawResponse>> {
|
|
264
|
+
readonly events: AsyncIterable<AgentStreamEvent<Output, RawResponse>>;
|
|
265
|
+
readonly textStream: AsyncIterable<string>;
|
|
266
|
+
readonly text: Promise<string>;
|
|
267
|
+
readonly result: Promise<AgentOutcome<Output>>;
|
|
261
268
|
steer(input: AgentSteerInput): AgentSteerReceipt;
|
|
269
|
+
cancel(reason?: string): void;
|
|
262
270
|
}
|
|
263
271
|
|
|
264
272
|
type AgentTraceInfo = {
|
|
@@ -400,4 +408,4 @@ type AgentObservabilityOptions<Observers extends AgentObserverMap = AgentObserve
|
|
|
400
408
|
readonly errorPolicy?: AgentObserverErrorPolicy | undefined;
|
|
401
409
|
};
|
|
402
410
|
|
|
403
|
-
export type {
|
|
411
|
+
export type { AgentBlockedOutcome as A, AgentGenerationModelInfo as B, AgentGenerationObserver as C, AgentGenerationStartArgs as D, AgentGenerationUpdateArgs as E, AgentObservabilityOptions as F, AgentObserver as G, AgentObserverErrorPolicy as H, AgentObserverMap as I, AgentObserverTraceInfo as J, AgentRunEndArgs as K, AgentRunErrorArgs as L, AgentRunEventArgs as M, AgentRunObserver as N, AgentRunPromptRef as O, AgentRunStartArgs as P, AgentToolEndArgs as Q, AgentToolErrorArgs as R, AgentToolObserver as S, AgentToolStartArgs as T, AgentToolStreamEventArgs as U, AgentToolSuspendedArgs as V, AgentTraceInfo as W, AgentTraceOptions as X, AgentChildStreamEvent as a, AgentDeltaEvent as b, AgentErrorEvent as c, AgentErrorStreamEvent as d, AgentFinishEvent as e, AgentInput as f, AgentInteractionOutcome as g, AgentLifecycle as h, AgentMemoryCompactionEvent as i, AgentMemoryCompactionOptions as j, AgentOutcome as k, AgentPrompt as l, AgentResponse as m, AgentRunOptions as n, AgentRunSettings as o, AgentStartEvent as p, AgentSteerInput as q, AgentSteerReceipt as r, AgentStepFinishEvent as s, AgentStream as t, AgentStreamEvent as u, AgentToolCallDeltaEvent as v, AgentToolFinishEvent as w, AgentToolStartEvent as x, AgentGenerationEndArgs as y, AgentGenerationErrorArgs as z };
|
|
@@ -119,6 +119,8 @@ type MemoryCompactorResult = {
|
|
|
119
119
|
usage?: Usage | undefined;
|
|
120
120
|
};
|
|
121
121
|
type MemoryCompactor = (input: MemoryCompactorInput) => Promise<MemoryCompactorResult>;
|
|
122
|
+
/** Counts the approximate or exact model tokens represented by a message list. */
|
|
123
|
+
type MemoryTokenCounter = (messages: readonly Message[]) => number | Promise<number>;
|
|
122
124
|
type CreateSummaryMemoryCompactorOptions = {
|
|
123
125
|
model: CompletionModel;
|
|
124
126
|
instructions?: string | undefined;
|
|
@@ -132,11 +134,12 @@ type MemoryCompactionConflictRetryOptions = {
|
|
|
132
134
|
};
|
|
133
135
|
type MemoryCompactionOptions = {
|
|
134
136
|
trigger: {
|
|
135
|
-
|
|
137
|
+
afterTokens: number;
|
|
136
138
|
};
|
|
137
139
|
retention?: {
|
|
138
|
-
|
|
140
|
+
recentTokens?: number | undefined;
|
|
139
141
|
};
|
|
142
|
+
tokenCounter?: MemoryTokenCounter | undefined;
|
|
140
143
|
compactor: MemoryCompactor;
|
|
141
144
|
conflictRetries?: false | MemoryCompactionConflictRetryOptions | undefined;
|
|
142
145
|
};
|
|
@@ -148,8 +151,20 @@ type MemoryCompactionInfo = {
|
|
|
148
151
|
originalMessageCount: number;
|
|
149
152
|
compactedMessageCount: number;
|
|
150
153
|
retainedMessageCount: number;
|
|
154
|
+
originalTokenCount: number;
|
|
155
|
+
compactedTokenCount: number;
|
|
156
|
+
retainedTokenCount: number;
|
|
157
|
+
resultTokenCount: number;
|
|
151
158
|
attempts: number;
|
|
152
159
|
usage: Usage;
|
|
153
160
|
};
|
|
161
|
+
type MemoryCompactionResult = ({
|
|
162
|
+
type: "compacted";
|
|
163
|
+
} & MemoryCompactionInfo) | {
|
|
164
|
+
type: "skipped";
|
|
165
|
+
reason: "nothing_to_compact";
|
|
166
|
+
originalMessageCount: number;
|
|
167
|
+
originalTokenCount: number;
|
|
168
|
+
};
|
|
154
169
|
|
|
155
|
-
export type {
|
|
170
|
+
export type { MemoryScope as A, MemoryScopeKeyOptions as B, CreateMemoryScopeKeyOptions as C, MemoryScopeKeyResolver as D, MemoryStore as E, MemoryTokenCounter as F, MemoryAppendOptions as M, CreateSummaryMemoryCompactorOptions as a, MemoryClearOptions as b, MemoryCompactionCapability as c, MemoryCompactionConflictRetryOptions as d, MemoryCompactionInfo as e, MemoryCompactionMessage as f, MemoryCompactionMetadata as g, MemoryCompactionOptions as h, MemoryCompactionReplacePrefixOptions as i, MemoryCompactionReplacePrefixResult as j, MemoryCompactionResult as k, MemoryCompactionSnapshot as l, MemoryCompactionSnapshotOptions as m, MemoryCompactor as n, MemoryCompactorInput as o, MemoryCompactorResult as p, MemoryConversation as q, MemoryConversationGetOptions as r, MemoryConversationListOptions as s, MemoryConversationMessage as t, MemoryConversationSummary as u, MemoryErrorOptions as v, MemoryInspector as w, MemoryLoadOptions as x, MemoryOptions as y, MemorySavePolicy as z };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { J as JsonObject } from './types-DgvozfPc.js';
|
|
2
|
+
import { A as AnyTool } from './tool-BpqpoRSE.js';
|
|
3
|
+
|
|
4
|
+
type McpServerInfo = {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly version: string;
|
|
7
|
+
readonly title?: string | undefined;
|
|
8
|
+
readonly description?: string | undefined;
|
|
9
|
+
readonly websiteUrl?: string | undefined;
|
|
10
|
+
readonly icons?: readonly {
|
|
11
|
+
readonly src: string;
|
|
12
|
+
readonly mimeType?: string | undefined;
|
|
13
|
+
readonly sizes?: readonly string[] | undefined;
|
|
14
|
+
readonly theme?: "light" | "dark" | undefined;
|
|
15
|
+
}[];
|
|
16
|
+
};
|
|
17
|
+
type McpTool = AnyTool & {
|
|
18
|
+
readonly mcp: {
|
|
19
|
+
readonly serverName: string;
|
|
20
|
+
readonly remoteName: string;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
type McpServer = {
|
|
24
|
+
readonly name: string;
|
|
25
|
+
readonly tools: readonly McpTool[];
|
|
26
|
+
readonly serverInfo?: McpServerInfo | undefined;
|
|
27
|
+
readonly capabilities?: JsonObject | undefined;
|
|
28
|
+
readonly instructions?: string | undefined;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type { McpTool as M, McpServer as a, McpServerInfo as b };
|
|
@@ -4,9 +4,9 @@ import {
|
|
|
4
4
|
matchesVectorFilter,
|
|
5
5
|
retrieveDocuments,
|
|
6
6
|
vectorFilter
|
|
7
|
-
} from "../chunk-
|
|
8
|
-
import "../chunk-
|
|
9
|
-
import "../chunk-
|
|
7
|
+
} from "../chunk-YFJ4NHV6.js";
|
|
8
|
+
import "../chunk-K5L7R7XM.js";
|
|
9
|
+
import "../chunk-IZNOP6JG.js";
|
|
10
10
|
import "../chunk-QGX73TSQ.js";
|
|
11
11
|
import "../chunk-3XQGVDU5.js";
|
|
12
12
|
import "../chunk-3RWESPUG.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anvia/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Core runtime primitives for context-aware Anvia agents.",
|
|
5
5
|
"author": "anvia",
|
|
6
6
|
"maintainer": "Indra Zulfi",
|
|
@@ -111,18 +111,24 @@
|
|
|
111
111
|
}
|
|
112
112
|
},
|
|
113
113
|
"dependencies": {
|
|
114
|
-
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
115
|
-
"pdfjs-dist": "^6.2.108",
|
|
116
|
-
"undici": "^8.10.0",
|
|
117
114
|
"yaml": "^2.9.0",
|
|
118
115
|
"zod": "^4.4.3"
|
|
119
116
|
},
|
|
120
117
|
"devDependencies": {
|
|
121
118
|
"@types/node": "^24.9.1",
|
|
119
|
+
"pdfjs-dist": "^6.2.108",
|
|
122
120
|
"tsup": "^8.5.0",
|
|
123
121
|
"typescript": "^5.9.3",
|
|
124
122
|
"vitest": "^4.0.8"
|
|
125
123
|
},
|
|
124
|
+
"peerDependencies": {
|
|
125
|
+
"pdfjs-dist": "^6.2.108"
|
|
126
|
+
},
|
|
127
|
+
"peerDependenciesMeta": {
|
|
128
|
+
"pdfjs-dist": {
|
|
129
|
+
"optional": true
|
|
130
|
+
}
|
|
131
|
+
},
|
|
126
132
|
"scripts": {
|
|
127
133
|
"build": "tsup src/index.ts src/agent/index.ts src/agent/interactions/index.ts src/internal/agent.ts src/speech-generation/index.ts src/completion/index.ts src/embeddings/index.ts src/evals/index.ts src/image-generation/index.ts src/documents/index.ts src/extractor/index.ts src/guardrails/index.ts src/mcp/index.ts src/memory/index.ts src/model-listing/index.ts src/observability/index.ts src/pipeline/index.ts src/skills/index.ts src/streaming/index.ts src/tool/index.ts src/transcription/index.ts src/vector-store/index.ts --format esm --dts --sourcemap --clean",
|
|
128
134
|
"test": "vitest run",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/internal/concurrency.ts"],"sourcesContent":["export async function mapWithConcurrency<Input, Output>(\n inputs: readonly Input[],\n concurrency: number,\n mapper: (input: Input) => Promise<Output>,\n): Promise<Output[]> {\n if (!Number.isSafeInteger(concurrency) || concurrency <= 0) {\n throw new RangeError(\"concurrency must be a positive safe integer.\");\n }\n const limit = concurrency;\n const results = new Array<Output>(inputs.length);\n let nextIndex = 0;\n let firstFailure: { error: unknown } | undefined;\n\n async function worker(): Promise<void> {\n while (firstFailure === undefined && nextIndex < inputs.length) {\n const index = nextIndex;\n nextIndex += 1;\n try {\n results[index] = await mapper(inputs[index] as Input);\n } catch (error) {\n firstFailure ??= { error };\n }\n }\n }\n\n await Promise.all(Array.from({ length: Math.min(limit, inputs.length) }, () => worker()));\n if (firstFailure !== undefined) {\n throw firstFailure.error;\n }\n return results;\n}\n"],"mappings":";AAAA,eAAsB,mBACpB,QACA,aACA,QACmB;AACnB,MAAI,CAAC,OAAO,cAAc,WAAW,KAAK,eAAe,GAAG;AAC1D,UAAM,IAAI,WAAW,8CAA8C;AAAA,EACrE;AACA,QAAM,QAAQ;AACd,QAAM,UAAU,IAAI,MAAc,OAAO,MAAM;AAC/C,MAAI,YAAY;AAChB,MAAI;AAEJ,iBAAe,SAAwB;AACrC,WAAO,iBAAiB,UAAa,YAAY,OAAO,QAAQ;AAC9D,YAAM,QAAQ;AACd,mBAAa;AACb,UAAI;AACF,gBAAQ,KAAK,IAAI,MAAM,OAAO,OAAO,KAAK,CAAU;AAAA,MACtD,SAAS,OAAO;AACd,yBAAiB,EAAE,MAAM;AAAA,MAC3B;AAAA,IACF;AAAA,EACF;AAEA,QAAM,QAAQ,IAAI,MAAM,KAAK,EAAE,QAAQ,KAAK,IAAI,OAAO,OAAO,MAAM,EAAE,GAAG,MAAM,OAAO,CAAC,CAAC;AACxF,MAAI,iBAAiB,QAAW;AAC9B,UAAM,aAAa;AAAA,EACrB;AACA,SAAO;AACT;","names":[]}
|