@anvia/core 1.0.0-rc.8 → 1.0.0

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.
Files changed (41) hide show
  1. package/README.md +99 -77
  2. package/dist/agent/index.d.ts +11 -16
  3. package/dist/agent/index.js +4 -4
  4. package/dist/{agent-XPQBM4rX.d.ts → agent-qRKa3ibC.d.ts} +11 -7
  5. package/dist/{chunk-YA2655FX.js → chunk-3ZLM6OAZ.js} +304 -100
  6. package/dist/chunk-3ZLM6OAZ.js.map +1 -0
  7. package/dist/{chunk-X4LK4ODN.js → chunk-AHLKV6KP.js} +1 -1
  8. package/dist/chunk-AHLKV6KP.js.map +1 -0
  9. package/dist/chunk-J6LVLV6P.js +13 -0
  10. package/dist/chunk-J6LVLV6P.js.map +1 -0
  11. package/dist/{chunk-QOUPWOGW.js → chunk-SPD4XVR7.js} +1 -1
  12. package/dist/{chunk-5C6B6ZRH.js → chunk-YA7BMX7D.js} +50 -3
  13. package/dist/chunk-YA7BMX7D.js.map +1 -0
  14. package/dist/documents/index.js +26 -1
  15. package/dist/documents/index.js.map +1 -1
  16. package/dist/evals/index.d.ts +5 -5
  17. package/dist/evals/index.js +3 -3
  18. package/dist/evals/index.js.map +1 -1
  19. package/dist/index.d.ts +7 -12
  20. package/dist/index.js +7 -5
  21. package/dist/internal/agent.d.ts +4 -9
  22. package/dist/internal/agent.js +4 -4
  23. package/dist/mcp/index.d.ts +3 -17
  24. package/dist/mcp/index.js +1 -15
  25. package/dist/memory/index.d.ts +6 -3
  26. package/dist/memory/index.js +4 -2
  27. package/dist/observability/index.d.ts +2 -2
  28. package/dist/pipeline/index.d.ts +6 -11
  29. package/dist/pipeline/index.js +3 -3
  30. package/dist/pipeline/index.js.map +1 -1
  31. package/dist/{types-Sue2hb_L.d.ts → types-CLCLFpAL.d.ts} +23 -15
  32. package/dist/{types-DKOXVTcq.d.ts → types-CSYt7-It.d.ts} +18 -3
  33. package/dist/types-DjqRHeAi.d.ts +31 -0
  34. package/package.json +10 -4
  35. package/dist/chunk-5C6B6ZRH.js.map +0 -1
  36. package/dist/chunk-76JLMBVT.js +0 -716
  37. package/dist/chunk-76JLMBVT.js.map +0 -1
  38. package/dist/chunk-X4LK4ODN.js.map +0 -1
  39. package/dist/chunk-YA2655FX.js.map +0 -1
  40. package/dist/client-DTPl0hZv.d.ts +0 -84
  41. /package/dist/{chunk-QOUPWOGW.js.map → chunk-SPD4XVR7.js.map} +0 -0
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export { A as Agent, a as AgentContextInput, b as AgentMemory, c as AgentMemoryOptions, d as AgentOptions, e as AgentToolInput, f as AgentToolOptions, C as CreateHybridVectorContextOptions, g as CreateVectorContextOptions, V as VectorContext, h as VectorContextBaseOptions, i as createVectorContext, j as isVectorContext } from './agent-XPQBM4rX.js';
1
+ export { A as Agent, a as AgentContextInput, b as AgentMemory, c as AgentMemoryOptions, d as AgentOptions, e as AgentToolInput, f as AgentToolOptions, C as CreateHybridVectorContextOptions, g as CreateVectorContextOptions, V as VectorContext, h as VectorContextBaseOptions, i as createVectorContext, j as isVectorContext } from './agent-qRKa3ibC.js';
2
2
  export { AgentRunBlockedError, AgentRunCancelledError, AgentStreamClosedError, AgentStructuredOutputError, AgentStructuredOutputFormat, AgentStructuredOutputPhase, AgentToolSuspensionError, MaxTurnsError } from './agent/index.js';
3
- export { A as AgentBlockedResult, a as AgentChildStreamEvent, b as AgentDeltaEvent, c as AgentErrorEvent, d as AgentErrorStreamEvent, e as AgentFinishEvent, f as AgentInput, g as AgentLifecycle, h as AgentMemoryCompactionEvent, i as AgentPrompt, j as AgentResponse, k as AgentResult, l as AgentRunOptions, m as AgentRunSettings, n as AgentStartEvent, o as AgentSteerInput, p as AgentSteerReceipt, q as AgentStepFinishEvent, r as AgentStream, s as AgentStreamEvent, t as AgentSuspendedResult, u as AgentToolCallDeltaEvent, v as AgentToolFinishEvent, w as AgentToolStartEvent } from './types-Sue2hb_L.js';
3
+ export { A as AgentBlockedOutcome, a as AgentChildStreamEvent, b as AgentDeltaEvent, c as AgentErrorEvent, d as AgentErrorStreamEvent, e as AgentFinishEvent, f as AgentInput, g as AgentInteractionOutcome, h as AgentLifecycle, i as AgentMemoryCompactionEvent, j as AgentMemoryCompactionOptions, k as AgentOutcome, l as AgentPrompt, m as AgentResponse, n as AgentRunOptions, o as AgentRunSettings, p as AgentStartEvent, q as AgentSteerInput, r as AgentSteerReceipt, s as AgentStepFinishEvent, t as AgentStream, u as AgentStreamEvent, v as AgentToolCallDeltaEvent, w as AgentToolFinishEvent, x as AgentToolStartEvent } from './types-CLCLFpAL.js';
4
4
  export { M as ModelCallOptions } from './model-call-options-CZkSw_xN.js';
5
5
  export { R as RetryContext, a as RetryOptions, b as RetrySetting } from './retry-CjvSlKGW.js';
6
6
  export { A as AssistantContentPart, a as AssistantGenerationMetadata, b as AssistantMessage, C as CompletionFinishReason, c as CompletionModel, d as CompletionModelInfo, e as CompletionModelStreamEvent, f as CompletionRequest, g as CompletionResponse, h as CompletionResult, i as CompletionSource, j as CompletionStreamEvent, k as CompletionTool, l as ContextUsage, D as Document, F as FileData, m as FilePart, I as ImageDetail, n as ImagePart, J as JsonObject, o as JsonPrimitive, p as JsonValue, M as Message, q as ModelContextLimits, P as ProviderTool, r as ProviderToolCall, R as ReasoningContentType, s as ReasoningDetail, t as ReasoningPart, S as SystemMessage, T as TextPart, u as ToolCallPart, v as ToolChoice, w as ToolDefinition, x as ToolMessage, y as ToolResultContentPart, z as ToolResultOutput, B as ToolResultPart, U as Usage, E as UserContentPart, G as UserMessage, H as calculateContextUsage, K as getAssistantGenerationMetadata, L as isProviderTool, N as resolveModelContextLimits, O as withContextUsage } from './types-DgvozfPc.js';
@@ -8,8 +8,8 @@ export { C as COMPLETION_PROVIDER_OUTPUT_ERROR_CODE, a as CompletionBaseOptions,
8
8
  export { a as allow, b as block, d as defineGuardrailPolicy, c as defineInputGuardrail, e as defineOutputGuardrail, g as guardrails } from './text-ZLECpQE7.js';
9
9
  export { G as GuardrailBoundary, a as GuardrailDecisionRecord, b as GuardrailMode, c as GuardrailPolicy, d as GuardrailPolicyInput, e as GuardrailPolicyOptions, I as InputGuardrail, f as InputGuardrailActions, g as InputGuardrailContext, O as OutputGuardrail, h as OutputGuardrailActions, i as OutputGuardrailContext } from './types-DhkodEft.js';
10
10
  export { GenerateImageOptions, GeneratedImage, ImageGenerationModel, ImageGenerationRequest, ImageGenerationResult, generateImage } from './image-generation/index.js';
11
- export { MemoryCompactionConflictError, MemoryCompactionError, createMemoryScopeKey, createSummaryMemoryCompactor, isMemoryCompactionMessage } from './memory/index.js';
12
- export { C as CreateMemoryScopeKeyOptions, a as CreateSummaryMemoryCompactorOptions, M as MemoryAppendOptions, b as MemoryClearOptions, c as MemoryCompactionCapability, d as MemoryCompactionConflictRetryOptions, e as MemoryCompactionInfo, f as MemoryCompactionMessage, g as MemoryCompactionMetadata, h as MemoryCompactionOptions, i as MemoryCompactionReplacePrefixOptions, j as MemoryCompactionReplacePrefixResult, k as MemoryCompactionSnapshot, l as MemoryCompactionSnapshotOptions, m as MemoryCompactor, n as MemoryCompactorInput, o as MemoryCompactorResult, p as MemoryConversation, q as MemoryConversationGetOptions, r as MemoryConversationListOptions, s as MemoryConversationMessage, t as MemoryConversationSummary, u as MemoryErrorOptions, v as MemoryInspector, w as MemoryLoadOptions, x as MemoryOptions, y as MemorySavePolicy, z as MemoryScope, A as MemoryScopeKeyOptions, B as MemoryScopeKeyResolver, D as MemoryStore } from './types-DKOXVTcq.js';
11
+ export { MemoryCompactionConflictError, MemoryCompactionError, createMemoryScopeKey, createSummaryMemoryCompactor, estimateMemoryTokens, isMemoryCompactionMessage } from './memory/index.js';
12
+ export { C as CreateMemoryScopeKeyOptions, a as CreateSummaryMemoryCompactorOptions, M as MemoryAppendOptions, b as MemoryClearOptions, c as MemoryCompactionCapability, d as MemoryCompactionConflictRetryOptions, e as MemoryCompactionInfo, f as MemoryCompactionMessage, g as MemoryCompactionMetadata, h as MemoryCompactionOptions, i as MemoryCompactionReplacePrefixOptions, j as MemoryCompactionReplacePrefixResult, k as MemoryCompactionResult, l as MemoryCompactionSnapshot, m as MemoryCompactionSnapshotOptions, n as MemoryCompactor, o as MemoryCompactorInput, p as MemoryCompactorResult, q as MemoryConversation, r as MemoryConversationGetOptions, s as MemoryConversationListOptions, t as MemoryConversationMessage, u as MemoryConversationSummary, v as MemoryErrorOptions, w as MemoryInspector, x as MemoryLoadOptions, y as MemoryOptions, z as MemorySavePolicy, A as MemoryScope, B as MemoryScopeKeyOptions, D as MemoryScopeKeyResolver, E as MemoryStore, F as MemoryTokenCounter } from './types-CSYt7-It.js';
13
13
  export { Z as ZodSchema } from './zod-schema-C7F4clpm.js';
14
14
  export { loadSkills, skill } from './skills/index.js';
15
15
  export { S as SkillValidationError } from './types-DC1U1XwW.js';
@@ -18,15 +18,10 @@ export { C as CreateToolOptions, c as createQuestionTool, a as createThinkTool,
18
18
  export { A as AnyTool, T as Tool, a as ToolApprovalContext, b as ToolApprovalRequirement, c as ToolCallContext, d as ToolCallStreamEvent, e as ToolRequiresApproval } from './tool-BpqpoRSE.js';
19
19
  export { A as AgentMiddleware, C as CompletionRequestMiddlewareArgs, a as CompletionRequestMiddlewareResult, b as CompletionResponseMiddlewareArgs, c as CompletionResponseMiddlewareResult, T as ToolInputMiddlewareArgs, d as ToolInputMiddlewareResult, e as ToolOutputMiddlewareArgs, f as ToolOutputMiddlewareResult, g as ToolResultMiddlewareArgs, h as createMiddleware } from './middleware-kcF8AusP.js';
20
20
  export { TranscribeOptions, TranscriptionAudio, TranscriptionModel, TranscriptionRequest, TranscriptionResult, transcribe } from './transcription/index.js';
21
- import './client-DTPl0hZv.js';
22
- import 'node:child_process';
23
- import 'node:stream';
24
- import '@modelcontextprotocol/sdk/client/auth.js';
25
- import '@modelcontextprotocol/sdk/client/streamableHttp.js';
26
- import '@modelcontextprotocol/sdk/shared/transport.js';
21
+ import './types-DjqRHeAi.js';
22
+ import './agent/interactions/index.js';
23
+ import 'zod';
27
24
  import './dynamic-tools-aIZlg5x1.js';
28
25
  import './types-Cr4uiYo5.js';
29
26
  import './types-CXNE592e.js';
30
- import './agent/interactions/index.js';
31
- import 'zod';
32
27
  import './type-utils-CtHVDRn_.js';
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  } from "./chunk-I3Q7XSBB.js";
10
10
  import {
11
11
  createMemoryScopeKey
12
- } from "./chunk-QOUPWOGW.js";
12
+ } from "./chunk-SPD4XVR7.js";
13
13
  import {
14
14
  SkillValidationError,
15
15
  loadSkills,
@@ -19,15 +19,16 @@ import {
19
19
  Agent,
20
20
  createVectorContext,
21
21
  isVectorContext
22
- } from "./chunk-YA2655FX.js";
22
+ } from "./chunk-3ZLM6OAZ.js";
23
23
  import "./chunk-OJBFDBLG.js";
24
- import "./chunk-76JLMBVT.js";
24
+ import "./chunk-J6LVLV6P.js";
25
25
  import {
26
26
  MemoryCompactionConflictError,
27
27
  MemoryCompactionError,
28
28
  createSummaryMemoryCompactor,
29
+ estimateMemoryTokens,
29
30
  isMemoryCompactionMessage
30
- } from "./chunk-5C6B6ZRH.js";
31
+ } from "./chunk-YA7BMX7D.js";
31
32
  import "./chunk-6BBOCFHV.js";
32
33
  import "./chunk-YK4WAAS4.js";
33
34
  import {
@@ -45,7 +46,7 @@ import {
45
46
  AgentStructuredOutputError,
46
47
  AgentToolSuspensionError,
47
48
  MaxTurnsError
48
- } from "./chunk-X4LK4ODN.js";
49
+ } from "./chunk-AHLKV6KP.js";
49
50
  import "./chunk-ZA564323.js";
50
51
  import "./chunk-3RM57ZT2.js";
51
52
  import "./chunk-D4PACGPA.js";
@@ -112,6 +113,7 @@ export {
112
113
  defineGuardrailPolicy,
113
114
  defineInputGuardrail,
114
115
  defineOutputGuardrail,
116
+ estimateMemoryTokens,
115
117
  generateCompletion,
116
118
  generateImage,
117
119
  generateSpeech,
@@ -1,20 +1,15 @@
1
- import { R as ResolvedAgentOptions, A as Agent } from '../agent-XPQBM4rX.js';
1
+ import { R as ResolvedAgentOptions, A as Agent } from '../agent-qRKa3ibC.js';
2
2
  import { c as CompletionModel, P as ProviderTool, M as Message, U as Usage, g as CompletionResponse, y as ToolResultContentPart } from '../types-DgvozfPc.js';
3
3
  import { T as ToolIndex } from '../dynamic-tools-aIZlg5x1.js';
4
4
  import { A as AnyTool } from '../tool-BpqpoRSE.js';
5
- import { e as MemoryCompactionInfo } from '../types-DKOXVTcq.js';
5
+ import { e as MemoryCompactionInfo } from '../types-CSYt7-It.js';
6
6
  import '../retry-CjvSlKGW.js';
7
7
  import '../zod-schema-C7F4clpm.js';
8
8
  import 'zod';
9
9
  import '../types-DhkodEft.js';
10
10
  import '../type-utils-CtHVDRn_.js';
11
- import '../client-DTPl0hZv.js';
12
- import 'node:child_process';
13
- import 'node:stream';
14
- import '@modelcontextprotocol/sdk/client/auth.js';
15
- import '@modelcontextprotocol/sdk/client/streamableHttp.js';
16
- import '@modelcontextprotocol/sdk/shared/transport.js';
17
- import '../types-Sue2hb_L.js';
11
+ import '../types-DjqRHeAi.js';
12
+ import '../types-CLCLFpAL.js';
18
13
  import '../agent/interactions/index.js';
19
14
  import '../middleware-kcF8AusP.js';
20
15
  import '../types-DC1U1XwW.js';
@@ -4,15 +4,15 @@ import {
4
4
  getAgentToolState,
5
5
  markResolvedAgentOptions,
6
6
  withInternalAgentRunOptions
7
- } from "../chunk-YA2655FX.js";
7
+ } from "../chunk-3ZLM6OAZ.js";
8
8
  import "../chunk-OJBFDBLG.js";
9
- import "../chunk-76JLMBVT.js";
10
- import "../chunk-5C6B6ZRH.js";
9
+ import "../chunk-J6LVLV6P.js";
10
+ import "../chunk-YA7BMX7D.js";
11
11
  import "../chunk-6BBOCFHV.js";
12
12
  import "../chunk-YK4WAAS4.js";
13
13
  import "../chunk-SJMSS5SI.js";
14
14
  import "../chunk-EMZKPRE6.js";
15
- import "../chunk-X4LK4ODN.js";
15
+ import "../chunk-AHLKV6KP.js";
16
16
  import "../chunk-ZA564323.js";
17
17
  import "../chunk-3RM57ZT2.js";
18
18
  import "../chunk-D4PACGPA.js";
@@ -1,23 +1,9 @@
1
- import { M as McpClient, a as McpServer, b as McpClientGroupConnectOptions, c as McpTool } from '../client-DTPl0hZv.js';
2
- export { d as McpClientOptions, e as McpClientTransport, f as McpConnectOptions, g as McpCustomTransport, h as McpServerInfo, i as McpStdioTransport, j as McpStreamableHttpTransport, k as McpTransport } from '../client-DTPl0hZv.js';
3
- import 'node:child_process';
4
- import 'node:stream';
5
- import '@modelcontextprotocol/sdk/client/auth.js';
6
- import '@modelcontextprotocol/sdk/client/streamableHttp.js';
7
- import '@modelcontextprotocol/sdk/shared/transport.js';
1
+ import { M as McpTool } from '../types-DjqRHeAi.js';
2
+ export { a as McpServer, b as McpServerInfo } from '../types-DjqRHeAi.js';
8
3
  import '../types-DgvozfPc.js';
9
4
  import '../model-call-options-CZkSw_xN.js';
10
5
  import '../tool-BpqpoRSE.js';
11
6
 
12
- declare class McpClientGroup {
13
- #private;
14
- readonly clients: readonly McpClient[];
15
- readonly servers: readonly McpServer[];
16
- private constructor();
17
- static connect(options: McpClientGroupConnectOptions): Promise<McpClientGroup>;
18
- close(): Promise<void>;
19
- }
20
-
21
7
  declare function isMcpTool(tool: unknown): tool is McpTool;
22
8
 
23
- export { McpClient, McpClientGroup, McpClientGroupConnectOptions, McpServer, McpTool, isMcpTool };
9
+ export { McpTool, isMcpTool };
package/dist/mcp/index.js CHANGED
@@ -1,21 +1,7 @@
1
1
  import {
2
- McpClient,
3
- McpClientGroup,
4
2
  isMcpTool
5
- } from "../chunk-76JLMBVT.js";
6
- import "../chunk-SJMSS5SI.js";
7
- import "../chunk-EMZKPRE6.js";
8
- import "../chunk-ZA564323.js";
9
- import "../chunk-3RM57ZT2.js";
10
- import "../chunk-D4PACGPA.js";
11
- import "../chunk-7PHMK7W4.js";
12
- import "../chunk-7JLAIN6E.js";
13
- import "../chunk-QGX73TSQ.js";
14
- import "../chunk-3XQGVDU5.js";
15
- import "../chunk-3RWESPUG.js";
3
+ } from "../chunk-J6LVLV6P.js";
16
4
  export {
17
- McpClient,
18
- McpClientGroup,
19
5
  isMcpTool
20
6
  };
21
7
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,6 @@
1
1
  import { M as Message, U as Usage } from '../types-DgvozfPc.js';
2
- import { a as CreateSummaryMemoryCompactorOptions, m as MemoryCompactor, f as MemoryCompactionMessage, C as CreateMemoryScopeKeyOptions } from '../types-DKOXVTcq.js';
3
- export { M as MemoryAppendOptions, b as MemoryClearOptions, c as MemoryCompactionCapability, d as MemoryCompactionConflictRetryOptions, e as MemoryCompactionInfo, g as MemoryCompactionMetadata, h as MemoryCompactionOptions, i as MemoryCompactionReplacePrefixOptions, j as MemoryCompactionReplacePrefixResult, k as MemoryCompactionSnapshot, l as MemoryCompactionSnapshotOptions, n as MemoryCompactorInput, o as MemoryCompactorResult, p as MemoryConversation, q as MemoryConversationGetOptions, r as MemoryConversationListOptions, s as MemoryConversationMessage, t as MemoryConversationSummary, u as MemoryErrorOptions, v as MemoryInspector, w as MemoryLoadOptions, x as MemoryOptions, y as MemorySavePolicy, z as MemoryScope, A as MemoryScopeKeyOptions, B as MemoryScopeKeyResolver, D as MemoryStore } from '../types-DKOXVTcq.js';
2
+ import { a as CreateSummaryMemoryCompactorOptions, n as MemoryCompactor, f as MemoryCompactionMessage, C as CreateMemoryScopeKeyOptions } from '../types-CSYt7-It.js';
3
+ export { M as MemoryAppendOptions, b as MemoryClearOptions, c as MemoryCompactionCapability, d as MemoryCompactionConflictRetryOptions, e as MemoryCompactionInfo, g as MemoryCompactionMetadata, h as MemoryCompactionOptions, i as MemoryCompactionReplacePrefixOptions, j as MemoryCompactionReplacePrefixResult, k as MemoryCompactionResult, l as MemoryCompactionSnapshot, m as MemoryCompactionSnapshotOptions, o as MemoryCompactorInput, p as MemoryCompactorResult, q as MemoryConversation, r as MemoryConversationGetOptions, s as MemoryConversationListOptions, t as MemoryConversationMessage, u as MemoryConversationSummary, v as MemoryErrorOptions, w as MemoryInspector, x as MemoryLoadOptions, y as MemoryOptions, z as MemorySavePolicy, A as MemoryScope, B as MemoryScopeKeyOptions, D as MemoryScopeKeyResolver, E as MemoryStore, F as MemoryTokenCounter } from '../types-CSYt7-It.js';
4
4
  import '../model-call-options-CZkSw_xN.js';
5
5
  import '../retry-CjvSlKGW.js';
6
6
 
@@ -17,6 +17,9 @@ declare class MemoryCompactionConflictError extends MemoryCompactionError {
17
17
  constructor(attempts: number, usage?: Usage);
18
18
  }
19
19
 
20
+ /** Lightweight provider-neutral estimate used when no model-specific counter is supplied. */
21
+ declare function estimateMemoryTokens(messages: readonly Message[]): number;
22
+
20
23
  declare function createMemoryScopeKey(options: CreateMemoryScopeKeyOptions): string;
21
24
 
22
- export { CreateMemoryScopeKeyOptions, CreateSummaryMemoryCompactorOptions, MemoryCompactionConflictError, MemoryCompactionError, MemoryCompactionMessage, MemoryCompactor, createMemoryScopeKey, createSummaryMemoryCompactor, isMemoryCompactionMessage };
25
+ export { CreateMemoryScopeKeyOptions, CreateSummaryMemoryCompactorOptions, MemoryCompactionConflictError, MemoryCompactionError, MemoryCompactionMessage, MemoryCompactor, createMemoryScopeKey, createSummaryMemoryCompactor, estimateMemoryTokens, isMemoryCompactionMessage };
@@ -1,12 +1,13 @@
1
1
  import {
2
2
  createMemoryScopeKey
3
- } from "../chunk-QOUPWOGW.js";
3
+ } from "../chunk-SPD4XVR7.js";
4
4
  import {
5
5
  MemoryCompactionConflictError,
6
6
  MemoryCompactionError,
7
7
  createSummaryMemoryCompactor,
8
+ estimateMemoryTokens,
8
9
  isMemoryCompactionMessage
9
- } from "../chunk-5C6B6ZRH.js";
10
+ } from "../chunk-YA7BMX7D.js";
10
11
  import "../chunk-7PHMK7W4.js";
11
12
  import "../chunk-7JLAIN6E.js";
12
13
  import "../chunk-QGX73TSQ.js";
@@ -17,6 +18,7 @@ export {
17
18
  MemoryCompactionError,
18
19
  createMemoryScopeKey,
19
20
  createSummaryMemoryCompactor,
21
+ estimateMemoryTokens,
20
22
  isMemoryCompactionMessage
21
23
  };
22
24
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,4 @@
1
- export { x as AgentGenerationEndArgs, y as AgentGenerationErrorArgs, z as AgentGenerationModelInfo, B as AgentGenerationObserver, C as AgentGenerationStartArgs, D as AgentGenerationUpdateArgs, E as AgentObservabilityOptions, F as AgentObserver, G as AgentObserverErrorPolicy, H as AgentObserverMap, I as AgentObserverTraceInfo, J as AgentRunEndArgs, K as AgentRunErrorArgs, L as AgentRunEventArgs, M as AgentRunObserver, N as AgentRunPromptRef, O as AgentRunStartArgs, P as AgentToolEndArgs, Q as AgentToolErrorArgs, R as AgentToolObserver, S as AgentToolStartArgs, T as AgentToolStreamEventArgs, U as AgentToolSuspendedArgs, V as AgentTraceInfo, W as AgentTraceOptions } from '../types-Sue2hb_L.js';
1
+ export { y as AgentGenerationEndArgs, z as AgentGenerationErrorArgs, B as AgentGenerationModelInfo, C as AgentGenerationObserver, D as AgentGenerationStartArgs, E as AgentGenerationUpdateArgs, F as AgentObservabilityOptions, G as AgentObserver, H as AgentObserverErrorPolicy, I as AgentObserverMap, J as AgentObserverTraceInfo, K as AgentRunEndArgs, L as AgentRunErrorArgs, M as AgentRunEventArgs, N as AgentRunObserver, O as AgentRunPromptRef, P as AgentRunStartArgs, Q as AgentToolEndArgs, R as AgentToolErrorArgs, S as AgentToolObserver, T as AgentToolStartArgs, U as AgentToolStreamEventArgs, V as AgentToolSuspendedArgs, W as AgentTraceInfo, X as AgentTraceOptions } from '../types-CLCLFpAL.js';
2
2
  import '../agent/interactions/index.js';
3
3
  import 'zod';
4
4
  import '../types-DgvozfPc.js';
@@ -6,7 +6,7 @@ import '../model-call-options-CZkSw_xN.js';
6
6
  import '../retry-CjvSlKGW.js';
7
7
  import '../types-DhkodEft.js';
8
8
  import '../type-utils-CtHVDRn_.js';
9
- import '../types-DKOXVTcq.js';
9
+ import '../types-CSYt7-It.js';
10
10
  import '../tool-BpqpoRSE.js';
11
11
  import '../middleware-kcF8AusP.js';
12
12
 
@@ -1,5 +1,5 @@
1
- import { t as AgentSuspendedResult, f as AgentInput, m as AgentRunSettings } from '../types-Sue2hb_L.js';
2
- import { A as Agent } from '../agent-XPQBM4rX.js';
1
+ import { g as AgentInteractionOutcome, f as AgentInput, o as AgentRunSettings } from '../types-CLCLFpAL.js';
2
+ import { A as Agent } from '../agent-qRKa3ibC.js';
3
3
  import { J as JsonObject, c as CompletionModel } from '../types-DgvozfPc.js';
4
4
  import { ExtractOptions } from '../extractor/index.js';
5
5
  import { z } from 'zod';
@@ -7,16 +7,11 @@ import '../agent/interactions/index.js';
7
7
  import '../retry-CjvSlKGW.js';
8
8
  import '../types-DhkodEft.js';
9
9
  import '../type-utils-CtHVDRn_.js';
10
- import '../types-DKOXVTcq.js';
10
+ import '../types-CSYt7-It.js';
11
11
  import '../tool-BpqpoRSE.js';
12
12
  import '../middleware-kcF8AusP.js';
13
13
  import '../zod-schema-C7F4clpm.js';
14
- import '../client-DTPl0hZv.js';
15
- import 'node:child_process';
16
- import 'node:stream';
17
- import '@modelcontextprotocol/sdk/client/auth.js';
18
- import '@modelcontextprotocol/sdk/client/streamableHttp.js';
19
- import '@modelcontextprotocol/sdk/shared/transport.js';
14
+ import '../types-DjqRHeAi.js';
20
15
  import '../types-DC1U1XwW.js';
21
16
  import '../dynamic-tools-aIZlg5x1.js';
22
17
  import '../types-Cr4uiYo5.js';
@@ -24,8 +19,8 @@ import '../model-call-options-CZkSw_xN.js';
24
19
  import '../types-CXNE592e.js';
25
20
 
26
21
  declare class PipelineAgentSuspensionError extends Error {
27
- readonly result: AgentSuspendedResult;
28
- constructor(result: AgentSuspendedResult);
22
+ readonly result: AgentInteractionOutcome;
23
+ constructor(result: AgentInteractionOutcome);
29
24
  }
30
25
 
31
26
  type PipelineMetadata = {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  AgentRunBlockedError
3
- } from "../chunk-X4LK4ODN.js";
3
+ } from "../chunk-AHLKV6KP.js";
4
4
  import {
5
5
  mapWithConcurrency
6
6
  } from "../chunk-3RM57ZT2.js";
@@ -433,10 +433,10 @@ var Pipeline = class {
433
433
  ...request,
434
434
  abortSignal: context.abortSignal
435
435
  });
436
- if (response.status === "suspended") {
436
+ if (response.type === "interaction") {
437
437
  throw new PipelineAgentSuspensionError(response);
438
438
  }
439
- if (response.status === "blocked") {
439
+ if (response.type === "blocked") {
440
440
  throw new AgentRunBlockedError(response);
441
441
  }
442
442
  return response.output;
@@ -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 (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C9B,MAAI,WAAW,WAAW,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":[]}
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 }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAEO,IAAM,+BAAN,cAA2C,MAAM;AAAA,EACtD,YAAqB,QAAiC;AACpD,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,CAAC;AAEjD,SAAS,qBAAqB,SAKnB;AAChB,QAAM,QAAQ,UAAU,UAAU,CAAC,QAAQ,GAAG,SAAS,OAAO;AAC9D,QAAM,QAAuB;AAAA,IAC3B,IAAI,QAAQ;AAAA,IACZ,OAAO,CAAC,KAAK;AAAA,IACb,OAAO,CAAC;AAAA,EACV;AACA,MAAI,QAAQ,SAAS,OAAW,OAAM,OAAO,QAAQ;AACrD,MAAI,QAAQ,gBAAgB,OAAW,OAAM,cAAc,QAAQ;AACnE,MAAI,QAAQ,aAAa,OAAW,OAAM,WAAW,QAAQ;AAC7D,SAAO;AAAA,IACL;AAAA,IACA,eAAe,CAAC,MAAM,IAAI;AAAA,IAC1B,UAAU,oBAAI,IAAI;AAAA,IAClB,eAAe;AAAA,EACjB;AACF;AAEO,SAAS,gBACd,OACA,MACA,OACA,UAKI,CAAC,GAC8C;AACnD,QAAM,KAAK,gBAAgB,MAAM,EAAE;AACnC,MAAI,MAAM,SAAS,IAAI,EAAE,GAAG;AAC1B,UAAM,IAAI,UAAU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AAU,+BAA+B;AAAA,EACrD;AACA,QAAM,aAAa,GAAG,KAAK;AAC3B,MAAI,WAAW,WAAW,GAAG;AAC3B,UAAM,IAAI,UAAU,yCAAyC;AAAA,EAC/D;AACA,SAAO;AACT;AAEA,SAAS,eAAe,OAAuB;AAC7C,MAAI,OAAO,UAAU,UAAU;AAC7B,UAAM,IAAI,UAAU,kCAAkC;AAAA,EACxD;AACA,QAAM,aAAa,MAAM,KAAK;AAC9B,MAAI,WAAW,WAAW,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":[]}
@@ -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, z as MemoryScope } from './types-DKOXVTcq.js';
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 AgentResultBase = {
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> = AgentResultBase & {
127
- status: "completed";
130
+ type AgentResponse<Output = string> = AgentOutcomeBase & {
131
+ type: "response";
128
132
  output: Output;
129
133
  };
130
- type AgentBlockedResult = AgentResultBase & {
131
- status: "blocked";
134
+ type AgentBlockedOutcome = AgentOutcomeBase & {
135
+ type: "blocked";
132
136
  stage: "input" | "output";
137
+ reason: string;
138
+ message?: string | undefined;
133
139
  };
134
- type AgentSuspendedResult = AgentResultBase & {
135
- status: "suspended";
140
+ type AgentInteractionOutcome = AgentOutcomeBase & {
141
+ type: "interaction";
136
142
  interaction: AgentInteractionRequest;
137
143
  continuation: AgentContinuation;
138
144
  };
139
- type AgentResult<Output = string> = AgentResponse<Output> | AgentBlockedResult | AgentSuspendedResult;
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<Event = AgentStreamEvent> extends AsyncIterable<Event> {
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 { AgentBlockedResult as A, AgentGenerationObserver as B, AgentGenerationStartArgs as C, AgentGenerationUpdateArgs as D, AgentObservabilityOptions as E, AgentObserver as F, AgentObserverErrorPolicy as G, AgentObserverMap as H, AgentObserverTraceInfo as I, AgentRunEndArgs as J, AgentRunErrorArgs as K, AgentRunEventArgs as L, AgentRunObserver as M, AgentRunPromptRef as N, AgentRunStartArgs as O, AgentToolEndArgs as P, AgentToolErrorArgs as Q, AgentToolObserver as R, AgentToolStartArgs as S, AgentToolStreamEventArgs as T, AgentToolSuspendedArgs as U, AgentTraceInfo as V, AgentTraceOptions as W, AgentChildStreamEvent as a, AgentDeltaEvent as b, AgentErrorEvent as c, AgentErrorStreamEvent as d, AgentFinishEvent as e, AgentInput as f, AgentLifecycle as g, AgentMemoryCompactionEvent as h, AgentPrompt as i, AgentResponse as j, AgentResult as k, AgentRunOptions as l, AgentRunSettings as m, AgentStartEvent as n, AgentSteerInput as o, AgentSteerReceipt as p, AgentStepFinishEvent as q, AgentStream as r, AgentStreamEvent as s, AgentSuspendedResult as t, AgentToolCallDeltaEvent as u, AgentToolFinishEvent as v, AgentToolStartEvent as w, AgentGenerationEndArgs as x, AgentGenerationErrorArgs as y, AgentGenerationModelInfo as z };
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 };