@anvia/core 0.11.1 → 0.11.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.
- package/dist/agent/index.d.ts +13 -31
- package/dist/agent/index.js +12 -34
- package/dist/{agent-DoF-xWGj.d.ts → agent-Bq2KtSaw.d.ts} +8 -125
- package/dist/audio-generation/index.d.ts +2 -1
- package/dist/audio-generation/index.js +1 -1
- package/dist/audio-generation/index.js.map +1 -1
- package/dist/{chunk-T22FYPE2.js → chunk-5EDHXYH5.js} +6 -6
- package/dist/{chunk-M4T4ID34.js → chunk-62RUYGMM.js} +6 -6
- package/dist/chunk-62RUYGMM.js.map +1 -0
- package/dist/{chunk-AREAH2X5.js → chunk-DOS77JZC.js} +3 -239
- package/dist/chunk-DOS77JZC.js.map +1 -0
- package/dist/{chunk-W4DZU6IW.js → chunk-JS5MGVNM.js} +50 -48
- package/dist/chunk-JS5MGVNM.js.map +1 -0
- package/dist/{chunk-XXT2UCAR.js → chunk-M6RPFHG7.js} +2 -2
- package/dist/chunk-M6RPFHG7.js.map +1 -0
- package/dist/chunk-N6REB3DH.js +205 -0
- package/dist/chunk-N6REB3DH.js.map +1 -0
- package/dist/chunk-NPZDYOE6.js +53 -0
- package/dist/chunk-NPZDYOE6.js.map +1 -0
- package/dist/{chunk-VJ7AZVLS.js → chunk-R75SGHCI.js} +4 -4
- package/dist/chunk-R75SGHCI.js.map +1 -0
- package/dist/{chunk-IFQVPV32.js → chunk-SISUMRUX.js} +308 -539
- package/dist/chunk-SISUMRUX.js.map +1 -0
- package/dist/{chunk-246MPVBE.js → chunk-V3WTT7TE.js} +2 -2
- package/dist/{chunk-BVGDCFQW.js → chunk-X3SWV6W6.js} +6 -6
- package/dist/completion/index.d.ts +3 -3
- package/dist/{create-completion-7GNUka0b.d.ts → create-completion-BEbtU5pX.d.ts} +1 -1
- package/dist/embeddings/index.d.ts +6 -5
- package/dist/embeddings/index.js +1 -1
- package/dist/evals/index.d.ts +9 -9
- package/dist/evals/index.js +16 -14
- package/dist/evals/index.js.map +1 -1
- package/dist/extractor/index.d.ts +9 -9
- package/dist/extractor/index.js +12 -10
- package/dist/hooks/index.d.ts +12 -0
- package/dist/hooks/index.js +18 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/image-generation/index.d.ts +2 -1
- package/dist/image-generation/index.js +1 -1
- package/dist/image-generation/index.js.map +1 -1
- package/dist/index-CTNzKidE.d.ts +198 -0
- package/dist/index.d.ts +17 -15
- package/dist/index.js +24 -29
- package/dist/internal/agent.d.ts +9 -9
- package/dist/internal/agent.js +9 -7
- package/dist/loaders/index.d.ts +8 -7
- package/dist/loaders/index.js.map +1 -1
- package/dist/mcp/index.d.ts +4 -4
- package/dist/memory/index.d.ts +4 -40
- package/dist/memory/index.js +1 -1
- package/dist/{middleware-D7nRBusA.d.ts → middleware-CG7l0rR3.d.ts} +4 -4
- package/dist/model-listing/index.d.ts +12 -11
- package/dist/model-listing/index.js +1 -1
- package/dist/model-listing/index.js.map +1 -1
- package/dist/observability/index.d.ts +3 -138
- package/dist/observability/index.js.map +1 -1
- package/dist/pipeline/index.d.ts +9 -9
- package/dist/pipeline/index.js +3 -3
- package/dist/request/index.d.ts +27 -0
- package/dist/request/index.js +23 -0
- package/dist/request/index.js.map +1 -0
- package/dist/skills/index.d.ts +4 -4
- package/dist/skills/index.js +6 -6
- package/dist/{think-tool-DmBR-YzU.d.ts → think-tool-B8Rqw2i_.d.ts} +1 -1
- package/dist/tool/index.d.ts +6 -6
- package/dist/tool/index.js +5 -5
- package/dist/{tool-Hlcb459D.d.ts → tool-BLypI31e.d.ts} +1 -1
- package/dist/transcription/index.d.ts +1 -1
- package/dist/{types-CP3iyh6j.d.ts → types-C8loR4il.d.ts} +1 -1
- package/dist/types-CCxnnJjU.d.ts +114 -0
- package/dist/{types-CiFIAGqq.d.ts → types-CIwm9p4w.d.ts} +2 -2
- package/dist/types-CNfjQ5rB.d.ts +42 -0
- package/dist/{types-DrkBkjzk.d.ts → types-D-YTJdLj.d.ts} +1 -1
- package/dist/{types-IB2e9u5M.d.ts → types-DHHZztGO.d.ts} +1 -1
- package/dist/{types-B0cuzkjP.d.ts → types-KKjICcrA.d.ts} +2 -2
- package/dist/ui/index.d.ts +2 -28
- package/dist/ui/index.js +1 -11
- package/dist/vector-store/index.d.ts +5 -5
- package/dist/vector-store/index.js +4 -4
- package/package.json +10 -2
- package/dist/chunk-AREAH2X5.js.map +0 -1
- package/dist/chunk-IFQVPV32.js.map +0 -1
- package/dist/chunk-M4T4ID34.js.map +0 -1
- package/dist/chunk-VJ7AZVLS.js.map +0 -1
- package/dist/chunk-W4DZU6IW.js.map +0 -1
- package/dist/chunk-XXT2UCAR.js.map +0 -1
- package/dist/types-C2ArxcON.d.ts +0 -65
- /package/dist/{chunk-T22FYPE2.js.map → chunk-5EDHXYH5.js.map} +0 -0
- /package/dist/{chunk-246MPVBE.js.map → chunk-V3WTT7TE.js.map} +0 -0
- /package/dist/{chunk-BVGDCFQW.js.map → chunk-X3SWV6W6.js.map} +0 -0
package/dist/agent/index.d.ts
CHANGED
|
@@ -1,38 +1,20 @@
|
|
|
1
|
-
import { D as DynamicContextOptions,
|
|
2
|
-
export {
|
|
3
|
-
import { M as Message, C as CompletionModel, e as JsonValue, o as ToolChoice } from '../types-CP3iyh6j.js';
|
|
4
|
-
import { d as ToolApprovalRequest, A as AnyTool, e as ToolApprovalsOptions } from '../tool-Hlcb459D.js';
|
|
5
|
-
export { b as ToolApprovalDecision } from '../tool-Hlcb459D.js';
|
|
6
|
-
export { A as AgentChildStreamEvent, a as AgentStreamEvent, P as PromptResponse } from '../types-C2ArxcON.js';
|
|
7
|
-
import { k as ToolSearchDocument, l as ToolSet, A as AgentMiddleware, e as ToolMiddleware } from '../middleware-D7nRBusA.js';
|
|
8
|
-
export { C as CompletionRequestMiddlewareArgs, a as CompletionRequestMiddlewareResult, b as CompletionResponseMiddlewareArgs, c as CompletionResponseMiddlewareResult, T as ToolInputMiddlewareArgs, d as ToolInputMiddlewareResult, f as ToolOutputMiddlewareArgs, g as ToolOutputMiddlewareResult, h as ToolResultMiddlewareArgs, i as createMiddleware, j as createToolMiddleware } from '../middleware-D7nRBusA.js';
|
|
1
|
+
import { D as DynamicContextOptions, a as DynamicToolOptions, b as AgentEventStore, c as AgentEventStoreOptions, A as Agent } from '../agent-Bq2KtSaw.js';
|
|
2
|
+
export { d as AgentEventAppendInput, e as AgentEventRecord, f as AgentEventStoreInclude, g as AgentSession, h as AgentToolOptions } from '../agent-Bq2KtSaw.js';
|
|
9
3
|
import { Z as ZodSchema } from '../zod-schema-C7F4clpm.js';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import { a as
|
|
14
|
-
import {
|
|
15
|
-
import '../types-
|
|
4
|
+
import { C as CompletionModel, e as JsonValue, n as ToolChoice } from '../types-C8loR4il.js';
|
|
5
|
+
import { P as PromptHook } from '../types-CCxnnJjU.js';
|
|
6
|
+
import { a as McpServer } from '../types-CIwm9p4w.js';
|
|
7
|
+
import { M as MemoryStore, a as MemoryOptions } from '../types-CNfjQ5rB.js';
|
|
8
|
+
import { b as AgentObserver, O as ObserveOptions } from '../index-CTNzKidE.js';
|
|
9
|
+
import { a as SkillSet } from '../types-D-YTJdLj.js';
|
|
10
|
+
import { k as ToolSearchDocument, l as ToolSet, A as AgentMiddleware, e as ToolMiddleware } from '../middleware-CG7l0rR3.js';
|
|
11
|
+
import { A as AnyTool, e as ToolApprovalsOptions } from '../tool-BLypI31e.js';
|
|
12
|
+
import { a as VectorSearchIndex } from '../types-KKjICcrA.js';
|
|
16
13
|
import 'zod';
|
|
17
14
|
import '@modelcontextprotocol/sdk/client/sse.js';
|
|
18
15
|
import '@modelcontextprotocol/sdk/client/stdio.js';
|
|
19
16
|
import '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
20
|
-
|
|
21
|
-
declare class MaxTurnsError extends Error {
|
|
22
|
-
readonly maxTurns: number;
|
|
23
|
-
readonly chatHistory: Message[];
|
|
24
|
-
readonly prompt: Message;
|
|
25
|
-
constructor(maxTurns: number, chatHistory: Message[], prompt: Message);
|
|
26
|
-
}
|
|
27
|
-
declare class PromptCancelledError extends Error {
|
|
28
|
-
readonly chatHistory: Message[];
|
|
29
|
-
readonly reason: string;
|
|
30
|
-
constructor(chatHistory: Message[], reason: string);
|
|
31
|
-
}
|
|
32
|
-
declare class ToolApprovalRequiredError extends Error {
|
|
33
|
-
readonly request: ToolApprovalRequest;
|
|
34
|
-
constructor(request: ToolApprovalRequest);
|
|
35
|
-
}
|
|
17
|
+
import '../types-DHHZztGO.js';
|
|
36
18
|
|
|
37
19
|
declare class AgentBuilder<M extends CompletionModel = CompletionModel> {
|
|
38
20
|
private readonly completionModel;
|
|
@@ -94,4 +76,4 @@ declare class AgentBuilder<M extends CompletionModel = CompletionModel> {
|
|
|
94
76
|
private buildInstructions;
|
|
95
77
|
}
|
|
96
78
|
|
|
97
|
-
export { AgentBuilder, AgentEventStore, AgentEventStoreOptions,
|
|
79
|
+
export { Agent, AgentBuilder, AgentEventStore, AgentEventStoreOptions, DynamicContextOptions, DynamicToolOptions };
|
package/dist/agent/index.js
CHANGED
|
@@ -1,43 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AgentBuilder
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
PromptCancelledError,
|
|
7
|
-
ToolApprovalRequiredError,
|
|
8
|
-
cancelPrompt,
|
|
9
|
-
createHook,
|
|
10
|
-
requestToolApproval,
|
|
11
|
-
runControl,
|
|
12
|
-
skipTool,
|
|
13
|
-
toolCallControl
|
|
14
|
-
} from "../chunk-IFQVPV32.js";
|
|
15
|
-
import "../chunk-XUUY2L2D.js";
|
|
16
|
-
import "../chunk-XXT2UCAR.js";
|
|
3
|
+
} from "../chunk-62RUYGMM.js";
|
|
4
|
+
import "../chunk-N6REB3DH.js";
|
|
5
|
+
import "../chunk-SISUMRUX.js";
|
|
17
6
|
import "../chunk-YK4WAAS4.js";
|
|
18
|
-
import
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
import "../chunk-
|
|
23
|
-
import "../chunk-
|
|
7
|
+
import "../chunk-XUUY2L2D.js";
|
|
8
|
+
import "../chunk-X3SWV6W6.js";
|
|
9
|
+
import "../chunk-5EDHXYH5.js";
|
|
10
|
+
import "../chunk-M6RPFHG7.js";
|
|
11
|
+
import "../chunk-JS5MGVNM.js";
|
|
12
|
+
import "../chunk-OIMLU4SF.js";
|
|
24
13
|
import "../chunk-5G3VME2D.js";
|
|
25
14
|
import "../chunk-WJO6NVE2.js";
|
|
26
15
|
import "../chunk-WQKHFADH.js";
|
|
27
|
-
import "../chunk-
|
|
28
|
-
import "../chunk-
|
|
16
|
+
import "../chunk-NPZDYOE6.js";
|
|
17
|
+
import "../chunk-MMHG7WAM.js";
|
|
29
18
|
export {
|
|
30
|
-
AgentBuilder
|
|
31
|
-
MaxTurnsError,
|
|
32
|
-
PromptCancelledError,
|
|
33
|
-
ToolApprovalRequiredError,
|
|
34
|
-
cancelPrompt,
|
|
35
|
-
createHook,
|
|
36
|
-
createMiddleware,
|
|
37
|
-
createToolMiddleware,
|
|
38
|
-
requestToolApproval,
|
|
39
|
-
runControl,
|
|
40
|
-
skipTool,
|
|
41
|
-
toolCallControl
|
|
19
|
+
AgentBuilder
|
|
42
20
|
};
|
|
43
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,127 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
type HookAction = {
|
|
10
|
-
type: "continue";
|
|
11
|
-
} | {
|
|
12
|
-
type: "terminate";
|
|
13
|
-
reason: string;
|
|
14
|
-
};
|
|
15
|
-
type ToolApprovalRequestOptions = {
|
|
16
|
-
reason?: string;
|
|
17
|
-
rejectMessage?: string;
|
|
18
|
-
};
|
|
19
|
-
type ToolCallHookAction = {
|
|
20
|
-
type: "continue";
|
|
21
|
-
} | {
|
|
22
|
-
type: "skip";
|
|
23
|
-
reason: string;
|
|
24
|
-
} | {
|
|
25
|
-
type: "terminate";
|
|
26
|
-
reason: string;
|
|
27
|
-
} | ({
|
|
28
|
-
type: "approval_request";
|
|
29
|
-
} & ToolApprovalRequestOptions);
|
|
30
|
-
type RunControl = {
|
|
31
|
-
continue(): HookAction;
|
|
32
|
-
cancel(reason: string): HookAction;
|
|
33
|
-
};
|
|
34
|
-
type ToolCallControl = {
|
|
35
|
-
run(): ToolCallHookAction;
|
|
36
|
-
skip(reason: string): ToolCallHookAction;
|
|
37
|
-
cancel(reason: string): ToolCallHookAction;
|
|
38
|
-
requestApproval(options?: ToolApprovalRequestOptions): ToolCallHookAction;
|
|
39
|
-
};
|
|
40
|
-
type HookResult = HookAction | undefined;
|
|
41
|
-
type ToolCallHookResult = ToolCallHookAction | undefined;
|
|
42
|
-
type HookCallback<Args> = (args: Args) => HookAction | Promise<HookAction | undefined> | Promise<void> | void;
|
|
43
|
-
type ToolCallHookCallback<Args> = (args: Args) => ToolCallHookAction | Promise<ToolCallHookAction | undefined> | Promise<void> | void;
|
|
44
|
-
type CompletionCallHookArgs = {
|
|
45
|
-
prompt: Message;
|
|
46
|
-
history: Message[];
|
|
47
|
-
run: RunControl;
|
|
48
|
-
};
|
|
49
|
-
type RunStartHookArgs = {
|
|
50
|
-
prompt: Message;
|
|
51
|
-
history: Message[];
|
|
52
|
-
maxTurns: number;
|
|
53
|
-
run: RunControl;
|
|
54
|
-
};
|
|
55
|
-
type RunEndHookArgs = {
|
|
56
|
-
output: string;
|
|
57
|
-
usage: Usage;
|
|
58
|
-
messages: Message[];
|
|
59
|
-
run: RunControl;
|
|
60
|
-
};
|
|
61
|
-
type RunErrorHookArgs = {
|
|
62
|
-
error: unknown;
|
|
63
|
-
usage: Usage;
|
|
64
|
-
messages: Message[];
|
|
65
|
-
run: RunControl;
|
|
66
|
-
};
|
|
67
|
-
type TurnStartHookArgs = {
|
|
68
|
-
turn: number;
|
|
69
|
-
prompt: Message;
|
|
70
|
-
history: Message[];
|
|
71
|
-
run: RunControl;
|
|
72
|
-
};
|
|
73
|
-
type TurnEndHookArgs<RawResponse = unknown> = {
|
|
74
|
-
turn: number;
|
|
75
|
-
response: CompletionResponse<RawResponse>;
|
|
76
|
-
run: RunControl;
|
|
77
|
-
};
|
|
78
|
-
type CompletionResponseHookArgs<RawResponse = unknown> = {
|
|
79
|
-
prompt: Message;
|
|
80
|
-
response: CompletionResponse<RawResponse>;
|
|
81
|
-
run: RunControl;
|
|
82
|
-
};
|
|
83
|
-
type CompletionErrorHookArgs = {
|
|
84
|
-
prompt: Message;
|
|
85
|
-
error: unknown;
|
|
86
|
-
run: RunControl;
|
|
87
|
-
};
|
|
88
|
-
type ToolHookArgs = {
|
|
89
|
-
toolName: string;
|
|
90
|
-
toolCallId?: string;
|
|
91
|
-
internalCallId: string;
|
|
92
|
-
args: string;
|
|
93
|
-
};
|
|
94
|
-
type ToolCallHookArgs = ToolHookArgs & {
|
|
95
|
-
tool: ToolCallControl;
|
|
96
|
-
};
|
|
97
|
-
type ToolResultHookArgs = ToolHookArgs & {
|
|
98
|
-
result: string;
|
|
99
|
-
structuredResult?: ToolResultContent[] | undefined;
|
|
100
|
-
run: RunControl;
|
|
101
|
-
};
|
|
102
|
-
type ToolErrorHookArgs = ToolHookArgs & {
|
|
103
|
-
error: unknown;
|
|
104
|
-
run: RunControl;
|
|
105
|
-
};
|
|
106
|
-
declare function createHook<RawResponse = unknown>(hook: PromptHook<RawResponse>): PromptHook<RawResponse>;
|
|
107
|
-
declare function cancelPrompt(reason: string): HookAction;
|
|
108
|
-
declare function skipTool(reason: string): ToolCallHookAction;
|
|
109
|
-
declare function requestToolApproval(options?: ToolApprovalRequestOptions): ToolCallHookAction;
|
|
110
|
-
declare const runControl: RunControl;
|
|
111
|
-
declare const toolCallControl: ToolCallControl;
|
|
112
|
-
interface PromptHook<RawResponse = unknown> {
|
|
113
|
-
onRunStart?: HookCallback<RunStartHookArgs>;
|
|
114
|
-
onRunEnd?: HookCallback<RunEndHookArgs>;
|
|
115
|
-
onRunError?: HookCallback<RunErrorHookArgs>;
|
|
116
|
-
onTurnStart?: HookCallback<TurnStartHookArgs>;
|
|
117
|
-
onTurnEnd?: HookCallback<TurnEndHookArgs<RawResponse>>;
|
|
118
|
-
onCompletionCall?: HookCallback<CompletionCallHookArgs>;
|
|
119
|
-
onCompletionResponse?: HookCallback<CompletionResponseHookArgs<RawResponse>>;
|
|
120
|
-
onCompletionError?: HookCallback<CompletionErrorHookArgs>;
|
|
121
|
-
onToolCall?: ToolCallHookCallback<ToolCallHookArgs>;
|
|
122
|
-
onToolResult?: HookCallback<ToolResultHookArgs>;
|
|
123
|
-
onToolError?: HookCallback<ToolErrorHookArgs>;
|
|
124
|
-
}
|
|
1
|
+
import { C as CompletionModel, M as Message, D as Document, e as JsonValue, n as ToolChoice, J as JsonObject } from './types-C8loR4il.js';
|
|
2
|
+
import { P as PromptHook } from './types-CCxnnJjU.js';
|
|
3
|
+
import { c as MemoryContext, e as MemoryRegistration, S as SessionOptions } from './types-CNfjQ5rB.js';
|
|
4
|
+
import { c as AgentTraceOptions, P as PromptResponse, a as AgentStreamEvent, d as AgentObserverRegistration } from './index-CTNzKidE.js';
|
|
5
|
+
import { e as ToolApprovalsOptions, T as Tool, A as AnyTool, f as ToolCallContext, N as NormalizedToolOutput } from './tool-BLypI31e.js';
|
|
6
|
+
import { A as AgentMiddleware, e as ToolMiddleware, k as ToolSearchDocument, l as ToolSet } from './middleware-CG7l0rR3.js';
|
|
7
|
+
import { V as VectorFilter, c as VectorSearchResult, a as VectorSearchIndex } from './types-KKjICcrA.js';
|
|
125
8
|
|
|
126
9
|
declare class PromptRequest<M extends CompletionModel = CompletionModel> {
|
|
127
10
|
private readonly agent;
|
|
@@ -316,4 +199,4 @@ declare class AgentSession<M extends CompletionModel = CompletionModel> {
|
|
|
316
199
|
clear(): Promise<void>;
|
|
317
200
|
}
|
|
318
201
|
|
|
319
|
-
export { Agent as A, type
|
|
202
|
+
export { Agent as A, type DynamicContextOptions as D, PromptRequest as P, type DynamicToolOptions as a, type AgentEventStore as b, type AgentEventStoreOptions as c, type AgentEventAppendInput as d, type AgentEventRecord as e, type AgentEventStoreInclude as f, AgentSession as g, type AgentToolOptions as h, type AgentEventStoreRegistration as i, type AgentOptions as j, DEFAULT_MAX_TURNS as k, type DynamicContextRegistration as l, type DynamicToolRegistration as m };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { e as JsonValue } from '../types-
|
|
1
|
+
import { e as JsonValue } from '../types-C8loR4il.js';
|
|
2
2
|
|
|
3
3
|
type AudioGenerationRequest = {
|
|
4
4
|
text: string;
|
|
@@ -16,6 +16,7 @@ interface AudioGenerationModel<RawResponse = unknown> {
|
|
|
16
16
|
readonly defaultModel?: string | undefined;
|
|
17
17
|
audioGeneration(request: AudioGenerationRequest): Promise<AudioGenerationResponse<RawResponse>>;
|
|
18
18
|
}
|
|
19
|
+
|
|
19
20
|
declare class AudioGenerationRequestBuilder<Model extends AudioGenerationModel = AudioGenerationModel> {
|
|
20
21
|
private readonly model;
|
|
21
22
|
private request;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/audio-generation/
|
|
1
|
+
{"version":3,"sources":["../../src/audio-generation/request.ts"],"sourcesContent":["import type { JsonValue } from \"../completion/types\";\nimport type { AudioGenerationModel, AudioGenerationRequest } from \"./types\";\n\nexport class AudioGenerationRequestBuilder<\n Model extends AudioGenerationModel = AudioGenerationModel,\n> {\n private request: AudioGenerationRequest = {\n text: \"\",\n voice: \"\",\n speed: 1,\n };\n\n constructor(private readonly model: Model) {}\n\n text(text: string): this {\n this.request = { ...this.request, text };\n return this;\n }\n\n voice(voice: string): this {\n this.request = { ...this.request, voice };\n return this;\n }\n\n speed(speed: number): this {\n this.request = { ...this.request, speed };\n return this;\n }\n\n additionalParams(additionalParams: JsonValue): this {\n this.request = { ...this.request, additionalParams };\n return this;\n }\n\n build(): AudioGenerationRequest {\n return { ...this.request };\n }\n\n send(): Promise<Awaited<ReturnType<Model[\"audioGeneration\"]>>> {\n return this.model.audioGeneration(this.build()) as Promise<\n Awaited<ReturnType<Model[\"audioGeneration\"]>>\n >;\n }\n}\n\nexport function audioGenerationRequest<Model extends AudioGenerationModel>(\n model: Model,\n): AudioGenerationRequestBuilder<Model> {\n return new AudioGenerationRequestBuilder(model);\n}\n"],"mappings":";AAGO,IAAM,gCAAN,MAEL;AAAA,EAOA,YAA6B,OAAc;AAAd;AAAA,EAAe;AAAA,EAAf;AAAA,EANrB,UAAkC;AAAA,IACxC,MAAM;AAAA,IACN,OAAO;AAAA,IACP,OAAO;AAAA,EACT;AAAA,EAIA,KAAK,MAAoB;AACvB,SAAK,UAAU,EAAE,GAAG,KAAK,SAAS,KAAK;AACvC,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,OAAqB;AACzB,SAAK,UAAU,EAAE,GAAG,KAAK,SAAS,MAAM;AACxC,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,OAAqB;AACzB,SAAK,UAAU,EAAE,GAAG,KAAK,SAAS,MAAM;AACxC,WAAO;AAAA,EACT;AAAA,EAEA,iBAAiB,kBAAmC;AAClD,SAAK,UAAU,EAAE,GAAG,KAAK,SAAS,iBAAiB;AACnD,WAAO;AAAA,EACT;AAAA,EAEA,QAAgC;AAC9B,WAAO,EAAE,GAAG,KAAK,QAAQ;AAAA,EAC3B;AAAA,EAEA,OAA+D;AAC7D,WAAO,KAAK,MAAM,gBAAgB,KAAK,MAAM,CAAC;AAAA,EAGhD;AACF;AAEO,SAAS,uBACd,OACsC;AACtC,SAAO,IAAI,8BAA8B,KAAK;AAChD;","names":[]}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
cosineSimilarity,
|
|
3
|
+
embedText
|
|
4
|
+
} from "./chunk-JS5MGVNM.js";
|
|
4
5
|
import {
|
|
5
6
|
toProviderJsonSchema
|
|
6
7
|
} from "./chunk-WQKHFADH.js";
|
|
7
8
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} from "./chunk-W4DZU6IW.js";
|
|
9
|
+
compact
|
|
10
|
+
} from "./chunk-MMHG7WAM.js";
|
|
11
11
|
|
|
12
12
|
// src/vector-store/index.ts
|
|
13
13
|
import { z } from "zod";
|
|
@@ -325,4 +325,4 @@ export {
|
|
|
325
325
|
InMemoryVectorIndex,
|
|
326
326
|
createVectorSearchTool
|
|
327
327
|
};
|
|
328
|
-
//# sourceMappingURL=chunk-
|
|
328
|
+
//# sourceMappingURL=chunk-5EDHXYH5.js.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Agent,
|
|
3
3
|
normalizeAgentId
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import {
|
|
6
|
-
resolveMemoryOptions
|
|
7
|
-
} from "./chunk-XXT2UCAR.js";
|
|
4
|
+
} from "./chunk-N6REB3DH.js";
|
|
8
5
|
import {
|
|
9
6
|
ToolSet
|
|
10
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-X3SWV6W6.js";
|
|
8
|
+
import {
|
|
9
|
+
resolveMemoryOptions
|
|
10
|
+
} from "./chunk-M6RPFHG7.js";
|
|
11
11
|
import {
|
|
12
12
|
toProviderJsonSchema
|
|
13
13
|
} from "./chunk-WQKHFADH.js";
|
|
@@ -203,4 +203,4 @@ var AgentBuilder = class {
|
|
|
203
203
|
export {
|
|
204
204
|
AgentBuilder
|
|
205
205
|
};
|
|
206
|
-
//# sourceMappingURL=chunk-
|
|
206
|
+
//# sourceMappingURL=chunk-62RUYGMM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/agent/builder.ts"],"sourcesContent":["import type { CompletionModel, Document, JsonObject, JsonValue, ToolChoice } from \"../completion\";\nimport type { PromptHook } from \"../hooks\";\nimport type { McpServer } from \"../mcp\";\nimport { resolveMemoryOptions } from \"../memory/options\";\nimport type { MemoryOptions, MemoryRegistration, MemoryStore } from \"../memory/types\";\nimport type { AgentObserver, AgentObserverRegistration, ObserveOptions } from \"../observability\";\nimport { toProviderJsonSchema, type ZodSchema } from \"../schema/zod-schema\";\nimport type { SkillSet } from \"../skills\";\nimport type { ToolSearchDocument } from \"../tool/dynamic-tools\";\nimport type { AgentMiddleware, ToolMiddleware } from \"../tool/middleware\";\nimport type { AnyTool, ToolApprovalsOptions } from \"../tool/tool\";\nimport { ToolSet } from \"../tool/tool-set\";\nimport type { VectorSearchIndex } from \"../vector-store\";\nimport { Agent } from \"./agent\";\nimport { normalizeAgentId } from \"./ids\";\nimport type {\n AgentEventStore,\n AgentEventStoreOptions,\n AgentEventStoreRegistration,\n DynamicContextOptions,\n DynamicContextRegistration,\n DynamicToolOptions,\n DynamicToolRegistration,\n} from \"./types\";\n\nexport class AgentBuilder<M extends CompletionModel = CompletionModel> {\n private readonly agentId: string;\n private agentName: string | undefined;\n private agentDescription: string | undefined;\n private instructionBlocks: string[] = [];\n private contextDocs: Document[] = [];\n private temp: number | undefined;\n private maxTokenCount: number | undefined;\n private params: JsonValue | undefined;\n private choice: ToolChoice | undefined;\n private turns: number | undefined;\n private requestHook: PromptHook | undefined;\n private schema: JsonObject | undefined;\n private approvalOptions: ToolApprovalsOptions | undefined;\n private skillInstructionBlocks: string[] = [];\n private observerRegistrations: AgentObserverRegistration[] = [];\n private dynamicContextRegistrations: DynamicContextRegistration[] = [];\n private dynamicToolRegistrations: DynamicToolRegistration[] = [];\n private middlewareRegistrations: AgentMiddleware[] = [];\n private memoryRegistration: MemoryRegistration | undefined;\n private eventStoreRegistration: AgentEventStoreRegistration | undefined;\n private activeToolSet = new ToolSet();\n\n constructor(\n agentId: string,\n private readonly completionModel: M,\n ) {\n this.agentId = normalizeAgentId(agentId);\n }\n\n name(name: string): this {\n this.agentName = name;\n return this;\n }\n\n description(description: string): this {\n this.agentDescription = description;\n return this;\n }\n\n instructions(instructions: string): this {\n if (instructions.length > 0) {\n this.instructionBlocks.push(instructions);\n }\n return this;\n }\n\n context(text: string, id = `static_doc_${this.contextDocs.length}`): this {\n this.contextDocs.push({ id, text });\n return this;\n }\n\n dynamicContext<T>(index: VectorSearchIndex<T>, options: DynamicContextOptions<T>): this {\n this.dynamicContextRegistrations.push({ index, options } as DynamicContextRegistration);\n return this;\n }\n\n dynamicTools(index: VectorSearchIndex<ToolSearchDocument>, options: DynamicToolOptions): this {\n this.dynamicToolRegistrations.push({ index, options });\n return this;\n }\n\n tool(tool: AnyTool): this {\n this.activeToolSet.addTool(tool);\n return this;\n }\n\n tools(tools: AnyTool[]): this {\n this.activeToolSet.addTools(tools);\n return this;\n }\n\n mcp(servers: McpServer[]): this {\n for (const server of servers) {\n this.activeToolSet.addTools(server.tools);\n }\n return this;\n }\n\n skills(skillSet: SkillSet): this {\n if (skillSet.instructions.length > 0) {\n this.skillInstructionBlocks.push(skillSet.instructions);\n }\n this.activeToolSet.addTools(skillSet.tools);\n return this;\n }\n\n useToolSet(toolSet: ToolSet): this {\n toolSet.addTools(this.activeToolSet);\n this.activeToolSet = toolSet;\n return this;\n }\n\n temperature(temperature: number): this {\n this.temp = temperature;\n return this;\n }\n\n maxTokens(maxTokens: number): this {\n this.maxTokenCount = maxTokens;\n return this;\n }\n\n additionalParams(params: JsonValue): this {\n this.params = params;\n return this;\n }\n\n toolChoice(toolChoice: ToolChoice): this {\n this.choice = toolChoice;\n return this;\n }\n\n defaultMaxTurns(defaultMaxTurns: number): this {\n this.turns = defaultMaxTurns;\n return this;\n }\n\n hook(hook: PromptHook): this {\n this.requestHook = hook;\n return this;\n }\n\n middleware(middleware: AgentMiddleware): this {\n this.middlewareRegistrations.push(middleware);\n return this;\n }\n\n middlewares(middlewares: AgentMiddleware[]): this {\n this.middlewareRegistrations.push(...middlewares);\n return this;\n }\n\n /**\n * @deprecated Use `middleware` instead.\n */\n toolMiddleware(middleware: ToolMiddleware): this {\n return this.middleware(middleware);\n }\n\n /**\n * @deprecated Use `middlewares` instead.\n */\n toolMiddlewares(middlewares: ToolMiddleware[]): this {\n return this.middlewares(middlewares);\n }\n\n observe(observer: AgentObserver, options: ObserveOptions = {}): this {\n this.observerRegistrations.push({\n observer,\n failOnObserverError: options.failOnObserverError,\n });\n return this;\n }\n\n approvals(options: ToolApprovalsOptions): this {\n this.approvalOptions = options;\n return this;\n }\n\n memory(store: MemoryStore, options: MemoryOptions = {}): this {\n this.memoryRegistration = {\n store,\n options: resolveMemoryOptions(options),\n };\n return this;\n }\n\n eventStore(store: AgentEventStore, options: AgentEventStoreOptions = {}): this {\n this.eventStoreRegistration = {\n store,\n options: {\n include: options.include ?? \"all\",\n },\n };\n return this;\n }\n\n outputSchema(schema: ZodSchema): this {\n this.schema = toProviderJsonSchema(schema);\n return this;\n }\n\n build(): Agent<M> {\n return new Agent({\n id: this.agentId,\n name: this.agentName,\n description: this.agentDescription,\n model: this.completionModel,\n instructions: this.buildInstructions(),\n staticContext: this.contextDocs,\n temperature: this.temp,\n maxTokens: this.maxTokenCount,\n additionalParams: this.params,\n toolSet: this.activeToolSet,\n toolChoice: this.choice,\n defaultMaxTurns: this.turns,\n hook: this.requestHook,\n outputSchema: this.schema,\n observers: this.observerRegistrations,\n approvals: this.approvalOptions,\n dynamicContexts: this.dynamicContextRegistrations,\n dynamicTools: this.dynamicToolRegistrations,\n middlewares: this.middlewareRegistrations,\n memory: this.memoryRegistration,\n eventStore: this.eventStoreRegistration,\n });\n }\n\n private buildInstructions(): string | undefined {\n const parts = [...this.instructionBlocks, ...this.skillInstructionBlocks].filter(\n (part): part is string => part !== undefined && part.length > 0,\n );\n return parts.length === 0 ? undefined : parts.join(\"\\n\\n\");\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAyBO,IAAM,eAAN,MAAgE;AAAA,EAuBrE,YACE,SACiB,iBACjB;AADiB;AAEjB,S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AAO,MAAM,WAAW,IAAI,SAAY,MAAM,KAAK,MAAM;AAAA,EAC3D;AACF;","names":[]}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createCompletionStream
|
|
3
|
-
} from "./chunk-5G3VME2D.js";
|
|
4
1
|
import {
|
|
5
2
|
AssistantContent,
|
|
6
3
|
Message,
|
|
7
4
|
ToolContent,
|
|
8
5
|
UserContent,
|
|
9
6
|
reasoningDisplayText,
|
|
10
|
-
serializeToolResultOutput
|
|
11
|
-
textFromAssistantContent
|
|
7
|
+
serializeToolResultOutput
|
|
12
8
|
} from "./chunk-WJO6NVE2.js";
|
|
13
9
|
|
|
14
10
|
// src/ui/messages.ts
|
|
@@ -262,240 +258,8 @@ function isRecord(value) {
|
|
|
262
258
|
return typeof value === "object" && value !== null;
|
|
263
259
|
}
|
|
264
260
|
|
|
265
|
-
// src/ui/index.ts
|
|
266
|
-
async function* createCompletionUIStream(model, options) {
|
|
267
|
-
const { messages, ...completionOptions } = options;
|
|
268
|
-
yield* completionStreamToUIStream(
|
|
269
|
-
createCompletionStream(model, {
|
|
270
|
-
...completionOptions,
|
|
271
|
-
messages: uiMessagesToCoreMessages(messages)
|
|
272
|
-
})
|
|
273
|
-
);
|
|
274
|
-
}
|
|
275
|
-
async function* createAgentUIStream(agent, options) {
|
|
276
|
-
yield* agentStreamToUIStream(agent.prompt(uiMessagesToCoreMessages(options.messages)).stream());
|
|
277
|
-
}
|
|
278
|
-
async function* completionStreamToUIStream(events, options = {}) {
|
|
279
|
-
const messageId = options.messageId ?? createId2("msg");
|
|
280
|
-
let accumulatedText = "";
|
|
281
|
-
yield messageStart(messageId);
|
|
282
|
-
for await (const event of events) {
|
|
283
|
-
if (event.type === "text_delta") {
|
|
284
|
-
accumulatedText += event.delta;
|
|
285
|
-
yield {
|
|
286
|
-
type: "text_delta",
|
|
287
|
-
messageId,
|
|
288
|
-
partId: textPartId(messageId),
|
|
289
|
-
delta: event.delta
|
|
290
|
-
};
|
|
291
|
-
continue;
|
|
292
|
-
}
|
|
293
|
-
if (event.type === "reasoning_delta") {
|
|
294
|
-
const partId = reasoningPartId(messageId, event.id);
|
|
295
|
-
yield {
|
|
296
|
-
type: "reasoning_delta",
|
|
297
|
-
messageId,
|
|
298
|
-
partId,
|
|
299
|
-
delta: event.delta
|
|
300
|
-
};
|
|
301
|
-
continue;
|
|
302
|
-
}
|
|
303
|
-
if (event.type === "tool_call_delta") {
|
|
304
|
-
const partId = toolPartId2(event.id);
|
|
305
|
-
yield {
|
|
306
|
-
type: "tool_update",
|
|
307
|
-
messageId,
|
|
308
|
-
partId,
|
|
309
|
-
part: {
|
|
310
|
-
id: partId,
|
|
311
|
-
type: "tool",
|
|
312
|
-
toolName: event.name ?? "",
|
|
313
|
-
toolCallId: event.id,
|
|
314
|
-
...event.callId === void 0 ? {} : { callId: event.callId },
|
|
315
|
-
state: "input-streaming",
|
|
316
|
-
...event.argumentsDelta === void 0 ? {} : { input: event.argumentsDelta }
|
|
317
|
-
}
|
|
318
|
-
};
|
|
319
|
-
continue;
|
|
320
|
-
}
|
|
321
|
-
if (event.type === "tool_call") {
|
|
322
|
-
yield {
|
|
323
|
-
type: "tool_update",
|
|
324
|
-
messageId,
|
|
325
|
-
partId: toolPartId2(event.toolCall.id),
|
|
326
|
-
part: {
|
|
327
|
-
id: toolPartId2(event.toolCall.id),
|
|
328
|
-
type: "tool",
|
|
329
|
-
toolName: event.toolCall.function.name,
|
|
330
|
-
toolCallId: event.toolCall.id,
|
|
331
|
-
...event.toolCall.callId === void 0 ? {} : { callId: event.toolCall.callId },
|
|
332
|
-
state: "input-available",
|
|
333
|
-
input: event.toolCall.function.arguments
|
|
334
|
-
}
|
|
335
|
-
};
|
|
336
|
-
continue;
|
|
337
|
-
}
|
|
338
|
-
if (event.type === "final") {
|
|
339
|
-
const finalText = textFromAssistantContent(event.response.choice);
|
|
340
|
-
const missingText = missingTextDelta(accumulatedText, finalText);
|
|
341
|
-
if (missingText !== void 0) {
|
|
342
|
-
accumulatedText += missingText;
|
|
343
|
-
yield {
|
|
344
|
-
type: "text_delta",
|
|
345
|
-
messageId,
|
|
346
|
-
partId: textPartId(messageId),
|
|
347
|
-
delta: missingText
|
|
348
|
-
};
|
|
349
|
-
}
|
|
350
|
-
const endEvent = {
|
|
351
|
-
type: "message_end",
|
|
352
|
-
messageId,
|
|
353
|
-
usage: event.response.usage
|
|
354
|
-
};
|
|
355
|
-
if (event.response.messageId !== void 0) {
|
|
356
|
-
endEvent.metadata = { providerMessageId: event.response.messageId };
|
|
357
|
-
}
|
|
358
|
-
yield endEvent;
|
|
359
|
-
continue;
|
|
360
|
-
}
|
|
361
|
-
if (event.type === "error") {
|
|
362
|
-
yield { type: "error", error: uiError(event.error) };
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
async function* agentStreamToUIStream(events, options = {}) {
|
|
367
|
-
const messageId = options.messageId ?? createId2("msg");
|
|
368
|
-
let accumulatedText = "";
|
|
369
|
-
yield messageStart(messageId);
|
|
370
|
-
for await (const event of events) {
|
|
371
|
-
if (event.type === "text_delta") {
|
|
372
|
-
accumulatedText += event.delta;
|
|
373
|
-
yield {
|
|
374
|
-
type: "text_delta",
|
|
375
|
-
messageId,
|
|
376
|
-
partId: textPartId(messageId),
|
|
377
|
-
delta: event.delta
|
|
378
|
-
};
|
|
379
|
-
continue;
|
|
380
|
-
}
|
|
381
|
-
if (event.type === "reasoning_delta") {
|
|
382
|
-
yield {
|
|
383
|
-
type: "reasoning_delta",
|
|
384
|
-
messageId,
|
|
385
|
-
partId: reasoningPartId(messageId, event.id),
|
|
386
|
-
delta: event.delta
|
|
387
|
-
};
|
|
388
|
-
continue;
|
|
389
|
-
}
|
|
390
|
-
if (event.type === "tool_call") {
|
|
391
|
-
yield {
|
|
392
|
-
type: "tool_update",
|
|
393
|
-
messageId,
|
|
394
|
-
partId: toolPartId2(event.toolCall.id),
|
|
395
|
-
part: {
|
|
396
|
-
id: toolPartId2(event.toolCall.id),
|
|
397
|
-
type: "tool",
|
|
398
|
-
toolName: event.toolCall.function.name,
|
|
399
|
-
toolCallId: event.toolCall.id,
|
|
400
|
-
...event.toolCall.callId === void 0 ? {} : { callId: event.toolCall.callId },
|
|
401
|
-
state: "input-available",
|
|
402
|
-
input: event.toolCall.function.arguments
|
|
403
|
-
}
|
|
404
|
-
};
|
|
405
|
-
continue;
|
|
406
|
-
}
|
|
407
|
-
if (event.type === "tool_result") {
|
|
408
|
-
const toolCallId = event.internalCallId;
|
|
409
|
-
yield {
|
|
410
|
-
type: "tool_update",
|
|
411
|
-
messageId,
|
|
412
|
-
partId: toolPartId2(toolCallId),
|
|
413
|
-
part: {
|
|
414
|
-
id: toolPartId2(toolCallId),
|
|
415
|
-
type: "tool",
|
|
416
|
-
toolName: event.toolName,
|
|
417
|
-
toolCallId,
|
|
418
|
-
...event.toolCallId === void 0 ? {} : { callId: event.toolCallId },
|
|
419
|
-
state: "output-available",
|
|
420
|
-
output: event.structuredResult === void 0 ? event.result : event.structuredResult
|
|
421
|
-
}
|
|
422
|
-
};
|
|
423
|
-
continue;
|
|
424
|
-
}
|
|
425
|
-
if (event.type === "final") {
|
|
426
|
-
const missingText = missingTextDelta(accumulatedText, event.output);
|
|
427
|
-
if (missingText !== void 0) {
|
|
428
|
-
accumulatedText += missingText;
|
|
429
|
-
yield {
|
|
430
|
-
type: "text_delta",
|
|
431
|
-
messageId,
|
|
432
|
-
partId: textPartId(messageId),
|
|
433
|
-
delta: missingText
|
|
434
|
-
};
|
|
435
|
-
}
|
|
436
|
-
yield {
|
|
437
|
-
type: "message_end",
|
|
438
|
-
messageId,
|
|
439
|
-
usage: event.usage,
|
|
440
|
-
metadata: { runId: event.runId }
|
|
441
|
-
};
|
|
442
|
-
continue;
|
|
443
|
-
}
|
|
444
|
-
if (event.type === "error") {
|
|
445
|
-
yield { type: "error", error: uiError(event.error) };
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
function messageStart(messageId) {
|
|
450
|
-
return {
|
|
451
|
-
type: "message_start",
|
|
452
|
-
message: {
|
|
453
|
-
id: messageId,
|
|
454
|
-
role: "assistant",
|
|
455
|
-
parts: []
|
|
456
|
-
}
|
|
457
|
-
};
|
|
458
|
-
}
|
|
459
|
-
function uiError(error) {
|
|
460
|
-
if (error instanceof Error) {
|
|
461
|
-
return { name: error.name, message: error.message };
|
|
462
|
-
}
|
|
463
|
-
return { message: typeof error === "string" ? error : serializeToolResultOutput(error) };
|
|
464
|
-
}
|
|
465
|
-
function missingTextDelta(current, finalText) {
|
|
466
|
-
if (finalText.length === 0 || finalText === current) {
|
|
467
|
-
return void 0;
|
|
468
|
-
}
|
|
469
|
-
if (finalText.startsWith(current)) {
|
|
470
|
-
return finalText.slice(current.length);
|
|
471
|
-
}
|
|
472
|
-
return current.length === 0 ? finalText : void 0;
|
|
473
|
-
}
|
|
474
|
-
function textPartId(messageId) {
|
|
475
|
-
return `${messageId}_text`;
|
|
476
|
-
}
|
|
477
|
-
function reasoningPartId(messageId, id) {
|
|
478
|
-
return id === void 0 ? `${messageId}_reasoning` : `${messageId}_reasoning_${id}`;
|
|
479
|
-
}
|
|
480
|
-
function toolPartId2(toolCallId) {
|
|
481
|
-
return `tool_${toolCallId}`;
|
|
482
|
-
}
|
|
483
|
-
var nextId2 = 0;
|
|
484
|
-
function createId2(prefix) {
|
|
485
|
-
const random = globalThis.crypto?.randomUUID?.();
|
|
486
|
-
if (random !== void 0) {
|
|
487
|
-
return `${prefix}_${random}`;
|
|
488
|
-
}
|
|
489
|
-
nextId2 += 1;
|
|
490
|
-
return `${prefix}_${nextId2.toString(36)}`;
|
|
491
|
-
}
|
|
492
|
-
|
|
493
261
|
export {
|
|
494
262
|
uiMessagesToCoreMessages,
|
|
495
|
-
coreMessagesToUIMessages
|
|
496
|
-
createCompletionUIStream,
|
|
497
|
-
createAgentUIStream,
|
|
498
|
-
completionStreamToUIStream,
|
|
499
|
-
agentStreamToUIStream
|
|
263
|
+
coreMessagesToUIMessages
|
|
500
264
|
};
|
|
501
|
-
//# sourceMappingURL=chunk-
|
|
265
|
+
//# sourceMappingURL=chunk-DOS77JZC.js.map
|