@agntk/core 0.1.1 → 0.1.2

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 (37) hide show
  1. package/package.json +2 -2
  2. package/dist/memory/engine.d.ts +0 -130
  3. package/dist/memory/engine.d.ts.map +0 -1
  4. package/dist/memory/engine.js +0 -227
  5. package/dist/memory/engine.js.map +0 -1
  6. package/dist/memory/vectra-store.d.ts +0 -31
  7. package/dist/memory/vectra-store.d.ts.map +0 -1
  8. package/dist/memory/vectra-store.js +0 -122
  9. package/dist/memory/vectra-store.js.map +0 -1
  10. package/dist/prompts/templates.d.ts +0 -11
  11. package/dist/prompts/templates.d.ts.map +0 -1
  12. package/dist/prompts/templates.js +0 -115
  13. package/dist/prompts/templates.js.map +0 -1
  14. package/dist/streaming/data-parts.d.ts +0 -163
  15. package/dist/streaming/data-parts.d.ts.map +0 -1
  16. package/dist/streaming/data-parts.js +0 -14
  17. package/dist/streaming/data-parts.js.map +0 -1
  18. package/dist/streaming/index.d.ts +0 -8
  19. package/dist/streaming/index.d.ts.map +0 -1
  20. package/dist/streaming/index.js +0 -10
  21. package/dist/streaming/index.js.map +0 -1
  22. package/dist/streaming/transient.d.ts +0 -136
  23. package/dist/streaming/transient.d.ts.map +0 -1
  24. package/dist/streaming/transient.js +0 -201
  25. package/dist/streaming/transient.js.map +0 -1
  26. package/dist/tools/provider.d.ts +0 -97
  27. package/dist/tools/provider.d.ts.map +0 -1
  28. package/dist/tools/provider.js +0 -178
  29. package/dist/tools/provider.js.map +0 -1
  30. package/dist/utils/logger.d.ts +0 -35
  31. package/dist/utils/logger.d.ts.map +0 -1
  32. package/dist/utils/logger.js +0 -149
  33. package/dist/utils/logger.js.map +0 -1
  34. package/dist/workflow/durable-agent.d.ts +0 -128
  35. package/dist/workflow/durable-agent.d.ts.map +0 -1
  36. package/dist/workflow/durable-agent.js +0 -323
  37. package/dist/workflow/durable-agent.js.map +0 -1
@@ -1,115 +0,0 @@
1
- /**
2
- * @agntk/core - System Prompt Templates
3
- * Core system prompts for agent behavior
4
- *
5
- * @deprecated Use `presets/role-registry.ts` instead. That module is the canonical
6
- * source of truth for role prompts, used by `createAgent()` via `getRole()`.
7
- * This file is kept for backward compatibility of public exports only.
8
- */
9
- export const systemPrompt = `You are an autonomous agent. Your purpose is to accomplish the user's goal using whatever approach makes sense.
10
-
11
- # Philosophy
12
-
13
- You have a mind and you have tools. Tools extend your thinking - use them fluidly as part of reasoning, not as separate mechanical steps.
14
-
15
- There is no single correct workflow. Match your approach to the problem:
16
- - Reason through it, gather information, reason more, then act
17
- - Act immediately if the path is obvious
18
- - Start one approach, realize it's wrong, switch to another
19
- - Call multiple tools in parallel when they don't depend on each other
20
-
21
- When something doesn't work, adapt. When you need information, go get it. When uncertain, reason carefully. When clear, act directly.
22
-
23
- When errors occur, read them carefully. The error message usually points to the fix.
24
-
25
- # Action
26
-
27
- Do things, don't announce them. Instead of "I'll search for X", just search.
28
-
29
- Be autonomous. Complete tasks without asking permission at every step. Only ask the user when you genuinely need information only they can provide.
30
-
31
- # Thinking Out Loud
32
-
33
- Before each action, briefly state:
34
- - **Goal**: What am I trying to accomplish?
35
- - **Approach**: Why is this the right tool/action?
36
- - **Risk**: What could go wrong?
37
-
38
- Keep it concise (1-2 sentences each). This helps the user understand your decisions.
39
-
40
- # Efficiency
41
-
42
- Complete tasks in the fewest steps possible:
43
- - Think first: What's the most direct path to the goal?
44
- - Use the right tool: Each tool's description explains when to use it
45
- - Chain when independent: Call multiple tools in parallel when they don't depend on each other
46
- - No random exploration: Every action should have a purpose
47
-
48
- # Tools
49
-
50
- You have access to consolidated tools with multiple actions. Use the action parameter to specify what to do:
51
-
52
- **fs** - All file operations (read, write, edit, list, glob, grep, move, delete, info, mkdir)
53
- **shell** - Execute shell commands (with allowlisting for repeated commands)
54
- **web** - Search the internet (search) or fetch page content (fetch)
55
- **memory** - Knowledge graph operations (add, search, episodes, fact, entity, related)
56
-
57
- **delegate** - Parallel work: tool chains (steps), sub-agents (agent), or background processes (background)
58
- **task** - Manage background tasks (status, output, cancel, list, cleanup)
59
-
60
- Additional tools: plan, ask_user, task_complete
61
-
62
- Each tool's description provides detailed guidance on when and how to use it. Read the descriptions to understand capabilities and constraints.
63
-
64
- # Delegation
65
-
66
- For complex work, use the delegate tool:
67
- - **steps**: Execute multiple tool calls in sequence with dependency handling
68
- - **agent**: Spawn a specialized sub-agent (coder/researcher/analyst)
69
- - **background**: Start a long-running shell command
70
-
71
- After delegating, use the task tool to monitor progress and retrieve output.
72
-
73
- # Completion
74
-
75
- Call task_complete when you have fully accomplished what the user asked for.
76
-
77
- Only call task_complete when truly done - not planned, not partially done, but actually complete.
78
- `;
79
- export const rolePrompts = {
80
- generic: systemPrompt,
81
- coder: `${systemPrompt}
82
-
83
- # Specialized Role: Code Implementation
84
-
85
- You are a code implementation specialist. Your focus areas:
86
- - Writing clean, maintainable code
87
- - Following existing patterns in the codebase
88
- - Making minimal, targeted changes
89
- - Running tests to verify your changes work
90
-
91
- Always read relevant code before making changes. Match the existing style.`,
92
- researcher: `${systemPrompt}
93
-
94
- # Specialized Role: Research
95
-
96
- You are a research specialist. Your focus areas:
97
- - Gathering comprehensive information on topics
98
- - Evaluating source credibility
99
- - Synthesizing findings into clear summaries
100
- - Identifying key insights and patterns
101
-
102
- Be thorough but efficient. Focus on actionable information.`,
103
- analyst: `${systemPrompt}
104
-
105
- # Specialized Role: Analysis
106
-
107
- You are an analysis specialist. Your focus areas:
108
- - Breaking down complex problems
109
- - Identifying patterns and relationships
110
- - Evaluating trade-offs and options
111
- - Providing data-driven recommendations
112
-
113
- Be systematic and logical. Support conclusions with evidence.`,
114
- };
115
- //# sourceMappingURL=templates.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"templates.js","sourceRoot":"","sources":["../../src/prompts/templates.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqE3B,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAA2B;IACjD,OAAO,EAAE,YAAY;IAErB,KAAK,EAAE,GAAG,YAAY;;;;;;;;;;2EAUmD;IAEzE,UAAU,EAAE,GAAG,YAAY;;;;;;;;;;4DAU+B;IAE1D,OAAO,EAAE,GAAG,YAAY;;;;;;;;;;8DAUoC;CAC7D,CAAC"}
@@ -1,163 +0,0 @@
1
- /**
2
- * @fileoverview Custom data part types for AI SDK streaming.
3
- * These types define the shape of transient data streamed during agent execution.
4
- *
5
- * Usage with AI SDK:
6
- * ```typescript
7
- * import type { DataStreamWriter } from 'ai';
8
- *
9
- * const writer: DataStreamWriter = ...;
10
- * writer.writeData({ type: 'file-content', data: { path: '/foo.ts', content: '...', truncated: false } });
11
- * ```
12
- */
13
- /**
14
- * Union type of all custom data parts supported by the agent SDK.
15
- * These are streamed transiently and not persisted to conversation context.
16
- */
17
- export type AgentDataParts = {
18
- /**
19
- * Streaming output from a spawned sub-agent.
20
- * Displayed as nested collapsible in UI.
21
- */
22
- 'sub-agent-stream': SubAgentStreamData;
23
- /**
24
- * Search results from grep/glob/codebase search.
25
- */
26
- 'search-result': SearchResultData;
27
- /**
28
- * File content streamed transiently (not added to context).
29
- */
30
- 'file-content': FileContentData;
31
- /**
32
- * Shell command execution output.
33
- */
34
- 'shell-output': ShellOutputData;
35
- /**
36
- * Progress indicator for long-running tools.
37
- */
38
- 'tool-progress': ToolProgressData;
39
- /**
40
- * Reasoning/thinking step from deep reasoning tool.
41
- */
42
- 'reasoning-step': ReasoningStepData;
43
- /**
44
- * Memory retrieval results.
45
- */
46
- 'memory-result': MemoryResultData;
47
- };
48
- /** Sub-agent streaming data. */
49
- export interface SubAgentStreamData {
50
- /** Unique identifier for the sub-agent instance. */
51
- agentId: string;
52
- /** Role of the sub-agent. */
53
- role: string;
54
- /** Streamed text content. */
55
- text: string;
56
- /** Status of the sub-agent stream. */
57
- status: 'streaming' | 'complete' | 'error';
58
- /** Error message if status is 'error'. */
59
- error?: string;
60
- }
61
- /** Search result data from file/code search. */
62
- export interface SearchResultData {
63
- /** File path relative to workspace root. */
64
- path: string;
65
- /** Matched content snippet. */
66
- content: string;
67
- /** Number of matches in the file. */
68
- matches: number;
69
- /** Line number of the first match. */
70
- line?: number;
71
- /** Search pattern used. */
72
- pattern?: string;
73
- }
74
- /** File content data for transient streaming. */
75
- export interface FileContentData {
76
- /** Absolute or relative file path. */
77
- path: string;
78
- /** File content. */
79
- content: string;
80
- /** Whether content was truncated due to size limits. */
81
- truncated: boolean;
82
- /** Total file size in bytes. */
83
- totalBytes?: number;
84
- /** MIME type of the file. */
85
- mimeType?: string;
86
- /** Language identifier for syntax highlighting. */
87
- language?: string;
88
- /** Line range if partial content. */
89
- lineRange?: {
90
- start: number;
91
- end: number;
92
- };
93
- }
94
- /** Shell command output data. */
95
- export interface ShellOutputData {
96
- /** Command that was executed. */
97
- command: string;
98
- /** Command output (stdout + stderr). */
99
- output: string;
100
- /** Exit code of the command. */
101
- exitCode: number;
102
- /** Working directory where command was executed. */
103
- cwd?: string;
104
- /** Whether output was truncated. */
105
- truncated?: boolean;
106
- /** Execution duration in milliseconds. */
107
- durationMs?: number;
108
- }
109
- /** Tool progress indicator data. */
110
- export interface ToolProgressData {
111
- /** Name of the tool being executed. */
112
- toolName: string;
113
- /** Progress percentage (0-100). */
114
- progress: number;
115
- /** Human-readable progress message. */
116
- message: string;
117
- /** Estimated time remaining in milliseconds. */
118
- estimatedRemaining?: number;
119
- /** Current step/total steps format. */
120
- step?: {
121
- current: number;
122
- total: number;
123
- };
124
- }
125
- /** Reasoning step from deep reasoning tool. */
126
- export interface ReasoningStepData {
127
- /** Step number in the reasoning chain. */
128
- stepNumber: number;
129
- /** Total estimated steps. */
130
- totalSteps: number;
131
- /** The reasoning thought content. */
132
- thought: string;
133
- /** Whether this is a revision of a previous thought. */
134
- isRevision?: boolean;
135
- /** Which thought number is being revised. */
136
- revisesThought?: number;
137
- /** Branch identifier for alternative reasoning paths. */
138
- branchId?: string;
139
- }
140
- /** Memory retrieval result data. */
141
- export interface MemoryResultData {
142
- /** Memory entry content. */
143
- content: string;
144
- /** Similarity score (0-1). */
145
- score: number;
146
- /** Metadata associated with the memory. */
147
- metadata?: Record<string, unknown>;
148
- /** When the memory was stored. */
149
- timestamp?: string;
150
- }
151
- /** Type helper to get data type for a specific part type. */
152
- export type DataPartType<K extends keyof AgentDataParts> = AgentDataParts[K];
153
- /** Type helper for creating typed data parts. */
154
- export interface TypedDataPart<K extends keyof AgentDataParts> {
155
- type: K;
156
- id?: string;
157
- data: AgentDataParts[K];
158
- }
159
- /** Union of all possible data parts. */
160
- export type AnyDataPart = {
161
- [K in keyof AgentDataParts]: TypedDataPart<K>;
162
- }[keyof AgentDataParts];
163
- //# sourceMappingURL=data-parts.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"data-parts.d.ts","sourceRoot":"","sources":["../../src/streaming/data-parts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B;;;OAGG;IACH,kBAAkB,EAAE,kBAAkB,CAAC;IAEvC;;OAEG;IACH,eAAe,EAAE,gBAAgB,CAAC;IAElC;;OAEG;IACH,cAAc,EAAE,eAAe,CAAC;IAEhC;;OAEG;IACH,cAAc,EAAE,eAAe,CAAC;IAEhC;;OAEG;IACH,eAAe,EAAE,gBAAgB,CAAC;IAElC;;OAEG;IACH,gBAAgB,EAAE,iBAAiB,CAAC;IAEpC;;OAEG;IACH,eAAe,EAAE,gBAAgB,CAAC;CACnC,CAAC;AAMF,gCAAgC;AAChC,MAAM,WAAW,kBAAkB;IACjC,oDAAoD;IACpD,OAAO,EAAE,MAAM,CAAC;IAEhB,6BAA6B;IAC7B,IAAI,EAAE,MAAM,CAAC;IAEb,6BAA6B;IAC7B,IAAI,EAAE,MAAM,CAAC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AAED,wCAAwC;AACxC,MAAM,MAAM,WAAW,GAAG;KACvB,CAAC,IAAI,MAAM,cAAc,GAAG,aAAa,CAAC,CAAC,CAAC;CAC9C,CAAC,MAAM,cAAc,CAAC,CAAC"}
@@ -1,14 +0,0 @@
1
- /**
2
- * @fileoverview Custom data part types for AI SDK streaming.
3
- * These types define the shape of transient data streamed during agent execution.
4
- *
5
- * Usage with AI SDK:
6
- * ```typescript
7
- * import type { DataStreamWriter } from 'ai';
8
- *
9
- * const writer: DataStreamWriter = ...;
10
- * writer.writeData({ type: 'file-content', data: { path: '/foo.ts', content: '...', truncated: false } });
11
- * ```
12
- */
13
- export {};
14
- //# sourceMappingURL=data-parts.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"data-parts.js","sourceRoot":"","sources":["../../src/streaming/data-parts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG"}
@@ -1,8 +0,0 @@
1
- /**
2
- * @agntk/core - Streaming Module
3
- *
4
- * Exports for transient streaming and custom data parts.
5
- */
6
- export { type AgentDataParts, type SubAgentStreamData, type SearchResultData, type FileContentData, type ShellOutputData, type ToolProgressData, type ReasoningStepData, type MemoryResultData, type DataPartType, type TypedDataPart, type AnyDataPart, } from './data-parts.js';
7
- export { withTransientStreaming, writeTransient, streamTransient, streamFileContent, streamShellOutput, streamSearchResult, streamProgress, streamReasoningStep, streamSubAgent, type TransientStreamWriter, type TransientToolContext, } from './transient.js';
8
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/streaming/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,WAAW,GACjB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,cAAc,EACd,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,GAC1B,MAAM,aAAa,CAAC"}
@@ -1,10 +0,0 @@
1
- /**
2
- * @agntk/core - Streaming Module
3
- *
4
- * Exports for transient streaming and custom data parts.
5
- */
6
- // Data part types
7
- export {} from './data-parts.js';
8
- // Transient streaming
9
- export { withTransientStreaming, writeTransient, streamTransient, streamFileContent, streamShellOutput, streamSearchResult, streamProgress, streamReasoningStep, streamSubAgent, } from './transient.js';
10
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/streaming/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,kBAAkB;AAClB,OAAO,EAYN,MAAM,cAAc,CAAC;AAEtB,sBAAsB;AACtB,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,cAAc,GAGf,MAAM,aAAa,CAAC"}
@@ -1,136 +0,0 @@
1
- /**
2
- * @agntk/core - Transient Streaming Infrastructure
3
- *
4
- * Enables tools to stream data to the UI without persisting to conversation context.
5
- * This keeps the context window lean while providing rich UI feedback.
6
- */
7
- import type { Tool } from 'ai';
8
- import type { ToolContext } from '../types/lifecycle.js';
9
- import type { AgentDataParts } from './data-parts.js';
10
- /**
11
- * Interface for UI stream writer.
12
- * Compatible with AI SDK's DataStreamWriter.
13
- */
14
- export interface TransientStreamWriter {
15
- writeData(data: unknown): void;
16
- }
17
- /**
18
- * Enhanced tool context with transient streaming capabilities.
19
- * Uses intersection type to extend ToolContext without conflicts.
20
- */
21
- export type TransientToolContext = ToolContext & {
22
- /** Helper to stream typed transient data */
23
- stream: <K extends keyof AgentDataParts>(type: K, data: AgentDataParts[K]) => void;
24
- };
25
- /**
26
- * Tool set is a record of tools keyed by name.
27
- */
28
- type ToolSet = Record<string, Tool>;
29
- /**
30
- * Wrap tools to enable transient streaming.
31
- *
32
- * Tools wrapped with this function will have access to a `stream()` helper
33
- * in their context that allows streaming data to the UI without adding
34
- * it to the conversation context.
35
- *
36
- * @param tools - Record of tools to wrap
37
- * @param writer - Stream writer for sending data to the client
38
- * @returns Wrapped tools with transient streaming enabled
39
- *
40
- * @example
41
- * ```typescript
42
- * const wrappedTools = withTransientStreaming(myTools, dataStream);
43
- *
44
- * // Inside a tool's execute function:
45
- * execute: async (input, ctx) => {
46
- * ctx.stream('file-content', {
47
- * path: input.path,
48
- * content: fileContent,
49
- * truncated: false,
50
- * });
51
- * return `Read ${input.path}`;
52
- * }
53
- * ```
54
- */
55
- export declare function withTransientStreaming(tools: ToolSet, writer: TransientStreamWriter): ToolSet;
56
- /**
57
- * Stream typed transient data to the UI.
58
- *
59
- * @param writer - Stream writer instance
60
- * @param type - Data part type
61
- * @param data - Data to stream
62
- */
63
- export declare function writeTransient<K extends keyof AgentDataParts>(writer: TransientStreamWriter, type: K, data: AgentDataParts[K]): void;
64
- /**
65
- * Helper for tools to stream transient data from within their execute function.
66
- *
67
- * @param ctx - Tool context (must have writer)
68
- * @param type - Data part type
69
- * @param data - Data to stream
70
- *
71
- * @example
72
- * ```typescript
73
- * // Inside a tool's execute function:
74
- * streamTransient(ctx, 'shell-output', {
75
- * command: 'npm test',
76
- * output: result.stdout,
77
- * exitCode: result.code,
78
- * });
79
- * ```
80
- */
81
- export declare function streamTransient<K extends keyof AgentDataParts>(ctx: ToolContext, type: K, data: AgentDataParts[K]): void;
82
- /**
83
- * Stream file content transiently.
84
- */
85
- export declare function streamFileContent(ctx: ToolContext, path: string, content: string, options?: {
86
- truncated?: boolean;
87
- totalBytes?: number;
88
- language?: string;
89
- lineRange?: {
90
- start: number;
91
- end: number;
92
- };
93
- }): void;
94
- /**
95
- * Stream shell output transiently.
96
- */
97
- export declare function streamShellOutput(ctx: ToolContext, command: string, output: string, exitCode: number, options?: {
98
- cwd?: string;
99
- truncated?: boolean;
100
- durationMs?: number;
101
- }): void;
102
- /**
103
- * Stream search results transiently.
104
- */
105
- export declare function streamSearchResult(ctx: ToolContext, path: string, content: string, matches: number, options?: {
106
- line?: number;
107
- pattern?: string;
108
- }): void;
109
- /**
110
- * Stream tool progress update transiently.
111
- */
112
- export declare function streamProgress(ctx: ToolContext, toolName: string, progress: number, message: string, options?: {
113
- estimatedRemaining?: number;
114
- step?: {
115
- current: number;
116
- total: number;
117
- };
118
- }): void;
119
- /**
120
- * Stream reasoning step transiently.
121
- *
122
- * @internal Forward-designed for CLI streaming feature. No production callers yet.
123
- */
124
- export declare function streamReasoningStep(ctx: ToolContext, stepNumber: number, totalSteps: number, thought: string, options?: {
125
- isRevision?: boolean;
126
- revisesThought?: number;
127
- branchId?: string;
128
- }): void;
129
- /**
130
- * Stream sub-agent output transiently.
131
- *
132
- * @internal Forward-designed for CLI streaming feature. No production callers yet.
133
- */
134
- export declare function streamSubAgent(ctx: ToolContext, agentId: string, role: string, text: string, status: 'streaming' | 'complete' | 'error', error?: string): void;
135
- export {};
136
- //# sourceMappingURL=transient.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transient.d.ts","sourceRoot":"","sources":["../../src/streaming/transient.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAE/B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,cAAc,EAAe,MAAM,cAAc,CAAC;AAQhE;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;CAChC;AAED;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG,WA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Transient Streaming Infrastructure
3
- *
4
- * Enables tools to stream data to the UI without persisting to conversation context.
5
- * This keeps the context window lean while providing rich UI feedback.
6
- */
7
- import { createLogger } from '@agntk/logger';
8
- const log = createLogger('@agntk/core:streaming');
9
- // ============================================================================
10
- // Main API: withTransientStreaming
11
- // ============================================================================
12
- /**
13
- * Wrap tools to enable transient streaming.
14
- *
15
- * Tools wrapped with this function will have access to a `stream()` helper
16
- * in their context that allows streaming data to the UI without adding
17
- * it to the conversation context.
18
- *
19
- * @param tools - Record of tools to wrap
20
- * @param writer - Stream writer for sending data to the client
21
- * @returns Wrapped tools with transient streaming enabled
22
- *
23
- * @example
24
- * ```typescript
25
- * const wrappedTools = withTransientStreaming(myTools, dataStream);
26
- *
27
- * // Inside a tool's execute function:
28
- * execute: async (input, ctx) => {
29
- * ctx.stream('file-content', {
30
- * path: input.path,
31
- * content: fileContent,
32
- * truncated: false,
33
- * });
34
- * return `Read ${input.path}`;
35
- * }
36
- * ```
37
- */
38
- export function withTransientStreaming(tools, writer) {
39
- const wrappedTools = {};
40
- for (const [name, tool] of Object.entries(tools)) {
41
- wrappedTools[name] = wrapToolWithTransient(tool, writer, name);
42
- }
43
- return wrappedTools;
44
- }
45
- // ============================================================================
46
- // Tool Wrapping
47
- // ============================================================================
48
- /**
49
- * Wrap a single tool with transient streaming capabilities.
50
- */
51
- function wrapToolWithTransient(tool, writer, toolName) {
52
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
53
- const originalExecute = tool.execute;
54
- if (!originalExecute) {
55
- return tool;
56
- }
57
- return {
58
- ...tool,
59
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
60
- execute: async (input, options) => {
61
- // Create enhanced context with streaming helper
62
- const enhancedContext = {
63
- ...(options || {}),
64
- agentId: options?.agentId || 'unknown',
65
- stepNumber: options?.stepNumber || 0,
66
- writer,
67
- stream: (type, data) => {
68
- writeTransient(writer, type, data);
69
- },
70
- };
71
- return originalExecute(input, enhancedContext);
72
- },
73
- };
74
- }
75
- // ============================================================================
76
- // Transient Data Writers
77
- // ============================================================================
78
- /**
79
- * Stream typed transient data to the UI.
80
- *
81
- * @param writer - Stream writer instance
82
- * @param type - Data part type
83
- * @param data - Data to stream
84
- */
85
- export function writeTransient(writer, type, data) {
86
- const dataPart = {
87
- type,
88
- data,
89
- };
90
- writer.writeData({
91
- ...dataPart,
92
- transient: true,
93
- });
94
- }
95
- /**
96
- * Helper for tools to stream transient data from within their execute function.
97
- *
98
- * @param ctx - Tool context (must have writer)
99
- * @param type - Data part type
100
- * @param data - Data to stream
101
- *
102
- * @example
103
- * ```typescript
104
- * // Inside a tool's execute function:
105
- * streamTransient(ctx, 'shell-output', {
106
- * command: 'npm test',
107
- * output: result.stdout,
108
- * exitCode: result.code,
109
- * });
110
- * ```
111
- */
112
- export function streamTransient(ctx, type, data) {
113
- // Cast to TransientStreamWriter - they have compatible interfaces
114
- const writer = ctx.writer;
115
- if (writer) {
116
- writeTransient(writer, type, data);
117
- }
118
- }
119
- // ============================================================================
120
- // Specialized Streamers
121
- // ============================================================================
122
- /**
123
- * Stream file content transiently.
124
- */
125
- export function streamFileContent(ctx, path, content, options = {}) {
126
- streamTransient(ctx, 'file-content', {
127
- path,
128
- content,
129
- truncated: options.truncated ?? false,
130
- totalBytes: options.totalBytes,
131
- language: options.language,
132
- lineRange: options.lineRange,
133
- });
134
- }
135
- /**
136
- * Stream shell output transiently.
137
- */
138
- export function streamShellOutput(ctx, command, output, exitCode, options = {}) {
139
- streamTransient(ctx, 'shell-output', {
140
- command,
141
- output,
142
- exitCode,
143
- cwd: options.cwd,
144
- truncated: options.truncated,
145
- durationMs: options.durationMs,
146
- });
147
- }
148
- /**
149
- * Stream search results transiently.
150
- */
151
- export function streamSearchResult(ctx, path, content, matches, options = {}) {
152
- streamTransient(ctx, 'search-result', {
153
- path,
154
- content,
155
- matches,
156
- line: options.line,
157
- pattern: options.pattern,
158
- });
159
- }
160
- /**
161
- * Stream tool progress update transiently.
162
- */
163
- export function streamProgress(ctx, toolName, progress, message, options = {}) {
164
- streamTransient(ctx, 'tool-progress', {
165
- toolName,
166
- progress,
167
- message,
168
- estimatedRemaining: options.estimatedRemaining,
169
- step: options.step,
170
- });
171
- }
172
- /**
173
- * Stream reasoning step transiently.
174
- *
175
- * @internal Forward-designed for CLI streaming feature. No production callers yet.
176
- */
177
- export function streamReasoningStep(ctx, stepNumber, totalSteps, thought, options = {}) {
178
- streamTransient(ctx, 'reasoning-step', {
179
- stepNumber,
180
- totalSteps,
181
- thought,
182
- isRevision: options.isRevision,
183
- revisesThought: options.revisesThought,
184
- branchId: options.branchId,
185
- });
186
- }
187
- /**
188
- * Stream sub-agent output transiently.
189
- *
190
- * @internal Forward-designed for CLI streaming feature. No production callers yet.
191
- */
192
- export function streamSubAgent(ctx, agentId, role, text, status, error) {
193
- streamTransient(ctx, 'sub-agent-stream', {
194
- agentId,
195
- role,
196
- text,
197
- status,
198
- error,
199
- });
200
- }
201
- //# sourceMappingURL=transient.js.map