veryfront 0.1.151 → 0.1.152

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/esm/deno.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export default {
2
2
  "name": "veryfront",
3
- "version": "0.1.151",
3
+ "version": "0.1.152",
4
4
  "license": "Apache-2.0",
5
5
  "nodeModulesDir": "auto",
6
6
  "exclude": [
@@ -84,6 +84,7 @@ export { getTextFromParts, getToolArguments, hasArgs, hasInput } from "./types.j
84
84
  export { BufferMemory, ConversationMemory, createMemory, createRedisMemory, type Memory, type MemoryPersistence, type MemoryStats, type RedisClient, RedisMemory, type RedisMemoryConfig, SummaryMemory, } from "./memory/index.js";
85
85
  export { agentAsTool, createWorkflow, getAgent, getAgentsAsTools, getAllAgentIds, registerAgent, type WorkflowConfig, type WorkflowResult, type WorkflowStep, } from "./composition/index.js";
86
86
  export { agent } from "./factory.js";
87
+ export { type AgUiRuntimeContextItem, AgUiRuntimeContextItemSchema, type AgUiRuntimeInjectedTool, AgUiRuntimeInjectedToolSchema, type AgUiRuntimeMessage, AgUiRuntimeMessageSchema, type AgUiRuntimeRequest, AgUiRuntimeRequestSchema, } from "./runtime-ag-ui-contract.js";
87
88
  export { type AgUiContextItem, type AgUiHandlerConfigWithAgent, type AgUiHandlerOptions, type AgUiInjectedTool, type AgUiRequest, AgUiRequestSchema, createAgUiHandler, } from "./ag-ui-handler.js";
88
89
  export { type ChatHandlerBeforeStream, type ChatHandlerBeforeStreamContext, type ChatHandlerBeforeStreamResult, type ChatHandlerConfigWithAgent, type ChatHandlerMessageInput, type ChatHandlerOptions, createChatHandler, } from "./chat-handler.js";
89
90
  export { AgentRuntime, RunAlreadyExistsError, RunCancelledError, RunNotActiveError, RunResumeSessionManager, type RunResumeSessionManagerOptions, type RunSessionStatus, type SubmitResumeValueOutcome, WaitConflictError, WaitNotPendingError, } from "./runtime/index.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.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K,6BAA6B,EAClC,KAAK,0BAA0B,EAC/B,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACvB,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,YAAY,EACZ,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,EACvB,KAAK,8BAA8B,EACnC,KAAK,gBAAgB,EACrB,KAAK,wBAAwB,EAC7B,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/agent/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+EG;AACH,OAAO,yBAAyB,CAAC;AAGjC,YAAY,EACV,KAAK,EACL,WAAW,EACX,YAAY,EACZ,eAAe,EACf,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,YAAY,EACZ,OAAO,IAAI,YAAY,EACvB,WAAW,EACX,aAAa,EACb,WAAW,EACX,mBAAmB,EACnB,cAAc,EACd,QAAQ,EACR,YAAY,EACZ,oBAAoB,EACpB,qBAAqB,EACrB,cAAc,GACf,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEnF,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,YAAY,EACZ,iBAAiB,EACjB,KAAK,MAAM,EACX,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,WAAW,EACX,KAAK,iBAAiB,EACtB,aAAa,GACd,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,WAAW,EACX,cAAc,EACd,QAAQ,EACR,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,YAAY,GAClB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EACL,KAAK,sBAAsB,EAC3B,4BAA4B,EAC5B,KAAK,uBAAuB,EAC5B,6BAA6B,EAC7B,KAAK,kBAAkB,EACvB,wBAAwB,EACxB,KAAK,kBAAkB,EACvB,wBAAwB,GACzB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,0BAA0B,EAC/B,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,KAAK,uBAAuB,EAC5B,KAAK,8BAA8B,EACnC,KAAK,6BAA6B,EAClC,KAAK,0BAA0B,EAC/B,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACvB,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,YAAY,EACZ,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,EACvB,KAAK,8BAA8B,EACnC,KAAK,gBAAgB,EACrB,KAAK,wBAAwB,EAC7B,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,oBAAoB,CAAC"}
@@ -83,6 +83,7 @@ export { getTextFromParts, getToolArguments, hasArgs, hasInput } from "./types.j
83
83
  export { BufferMemory, ConversationMemory, createMemory, createRedisMemory, RedisMemory, SummaryMemory, } from "./memory/index.js";
84
84
  export { agentAsTool, createWorkflow, getAgent, getAgentsAsTools, getAllAgentIds, registerAgent, } from "./composition/index.js";
85
85
  export { agent } from "./factory.js";
86
+ export { AgUiRuntimeContextItemSchema, AgUiRuntimeInjectedToolSchema, AgUiRuntimeMessageSchema, AgUiRuntimeRequestSchema, } from "./runtime-ag-ui-contract.js";
86
87
  export { AgUiRequestSchema, createAgUiHandler, } from "./ag-ui-handler.js";
87
88
  export { createChatHandler, } from "./chat-handler.js";
88
89
  export { AgentRuntime, RunAlreadyExistsError, RunCancelledError, RunNotActiveError, RunResumeSessionManager, WaitConflictError, WaitNotPendingError, } from "./runtime/index.js";
@@ -0,0 +1,207 @@
1
+ import { z } from "zod";
2
+ export declare const AgUiRuntimeRunIdSchema: z.ZodString;
3
+ export declare const AgUiRuntimeInjectedToolSchema: z.ZodObject<{
4
+ name: z.ZodString;
5
+ description: z.ZodOptional<z.ZodString>;
6
+ parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
7
+ }, z.core.$strip>;
8
+ export declare const AgUiRuntimeContextItemSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
9
+ type: z.ZodLiteral<"text">;
10
+ title: z.ZodOptional<z.ZodString>;
11
+ text: z.ZodString;
12
+ }, z.core.$strip>, z.ZodObject<{
13
+ type: z.ZodLiteral<"json">;
14
+ title: z.ZodOptional<z.ZodString>;
15
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
16
+ }, z.core.$strip>, z.ZodObject<{
17
+ type: z.ZodLiteral<"resource">;
18
+ title: z.ZodOptional<z.ZodString>;
19
+ uri: z.ZodString;
20
+ mimeType: z.ZodOptional<z.ZodString>;
21
+ text: z.ZodOptional<z.ZodString>;
22
+ }, z.core.$strip>], "type">;
23
+ export declare const AgUiRuntimeToolFunctionCallSchema: z.ZodObject<{
24
+ name: z.ZodString;
25
+ arguments: z.ZodString;
26
+ }, z.core.$strict>;
27
+ export declare const AgUiRuntimeToolCallSchema: z.ZodObject<{
28
+ id: z.ZodString;
29
+ type: z.ZodLiteral<"function">;
30
+ function: z.ZodObject<{
31
+ name: z.ZodString;
32
+ arguments: z.ZodString;
33
+ }, z.core.$strict>;
34
+ }, z.core.$strict>;
35
+ export declare const AgUiRuntimeSystemMessageSchema: z.ZodObject<{
36
+ name: z.ZodOptional<z.ZodString>;
37
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
38
+ createdAt: z.ZodOptional<z.ZodString>;
39
+ id: z.ZodString;
40
+ role: z.ZodLiteral<"system">;
41
+ content: z.ZodString;
42
+ }, z.core.$strict>;
43
+ export declare const AgUiRuntimeUserMessageSchema: z.ZodObject<{
44
+ name: z.ZodOptional<z.ZodString>;
45
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
46
+ createdAt: z.ZodOptional<z.ZodString>;
47
+ id: z.ZodString;
48
+ role: z.ZodLiteral<"user">;
49
+ content: z.ZodString;
50
+ }, z.core.$strict>;
51
+ export declare const AgUiRuntimeAssistantMessageSchema: z.ZodObject<{
52
+ name: z.ZodOptional<z.ZodString>;
53
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
54
+ createdAt: z.ZodOptional<z.ZodString>;
55
+ id: z.ZodString;
56
+ role: z.ZodLiteral<"assistant">;
57
+ content: z.ZodOptional<z.ZodString>;
58
+ toolCalls: z.ZodOptional<z.ZodArray<z.ZodObject<{
59
+ id: z.ZodString;
60
+ type: z.ZodLiteral<"function">;
61
+ function: z.ZodObject<{
62
+ name: z.ZodString;
63
+ arguments: z.ZodString;
64
+ }, z.core.$strict>;
65
+ }, z.core.$strict>>>;
66
+ }, z.core.$strict>;
67
+ export declare const AgUiRuntimeToolMessageSchema: z.ZodObject<{
68
+ name: z.ZodOptional<z.ZodString>;
69
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
70
+ createdAt: z.ZodOptional<z.ZodString>;
71
+ id: z.ZodString;
72
+ role: z.ZodLiteral<"tool">;
73
+ toolCallId: z.ZodString;
74
+ content: z.ZodString;
75
+ error: z.ZodOptional<z.ZodString>;
76
+ }, z.core.$strict>;
77
+ export declare const AgUiRuntimeMessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
78
+ name: z.ZodOptional<z.ZodString>;
79
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
80
+ createdAt: z.ZodOptional<z.ZodString>;
81
+ id: z.ZodString;
82
+ role: z.ZodLiteral<"system">;
83
+ content: z.ZodString;
84
+ }, z.core.$strict>, z.ZodObject<{
85
+ name: z.ZodOptional<z.ZodString>;
86
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
87
+ createdAt: z.ZodOptional<z.ZodString>;
88
+ id: z.ZodString;
89
+ role: z.ZodLiteral<"user">;
90
+ content: z.ZodString;
91
+ }, z.core.$strict>, z.ZodObject<{
92
+ name: z.ZodOptional<z.ZodString>;
93
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
94
+ createdAt: z.ZodOptional<z.ZodString>;
95
+ id: z.ZodString;
96
+ role: z.ZodLiteral<"assistant">;
97
+ content: z.ZodOptional<z.ZodString>;
98
+ toolCalls: z.ZodOptional<z.ZodArray<z.ZodObject<{
99
+ id: z.ZodString;
100
+ type: z.ZodLiteral<"function">;
101
+ function: z.ZodObject<{
102
+ name: z.ZodString;
103
+ arguments: z.ZodString;
104
+ }, z.core.$strict>;
105
+ }, z.core.$strict>>>;
106
+ }, z.core.$strict>, z.ZodObject<{
107
+ name: z.ZodOptional<z.ZodString>;
108
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
109
+ createdAt: z.ZodOptional<z.ZodString>;
110
+ id: z.ZodString;
111
+ role: z.ZodLiteral<"tool">;
112
+ toolCallId: z.ZodString;
113
+ content: z.ZodString;
114
+ error: z.ZodOptional<z.ZodString>;
115
+ }, z.core.$strict>], "role">;
116
+ export declare const AgUiRuntimeContextSchema: z.ZodUnion<readonly [z.ZodObject<{
117
+ description: z.ZodString;
118
+ value: z.ZodString;
119
+ }, z.core.$strip>, z.ZodDiscriminatedUnion<[z.ZodObject<{
120
+ type: z.ZodLiteral<"text">;
121
+ title: z.ZodOptional<z.ZodString>;
122
+ text: z.ZodString;
123
+ }, z.core.$strip>, z.ZodObject<{
124
+ type: z.ZodLiteral<"json">;
125
+ title: z.ZodOptional<z.ZodString>;
126
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
127
+ }, z.core.$strip>, z.ZodObject<{
128
+ type: z.ZodLiteral<"resource">;
129
+ title: z.ZodOptional<z.ZodString>;
130
+ uri: z.ZodString;
131
+ mimeType: z.ZodOptional<z.ZodString>;
132
+ text: z.ZodOptional<z.ZodString>;
133
+ }, z.core.$strip>], "type">]>;
134
+ export declare const AgUiRuntimeRequestSchema: z.ZodObject<{
135
+ threadId: z.ZodString;
136
+ runId: z.ZodString;
137
+ parentRunId: z.ZodOptional<z.ZodString>;
138
+ state: z.ZodOptional<z.ZodUnknown>;
139
+ messages: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
140
+ name: z.ZodOptional<z.ZodString>;
141
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
142
+ createdAt: z.ZodOptional<z.ZodString>;
143
+ id: z.ZodString;
144
+ role: z.ZodLiteral<"system">;
145
+ content: z.ZodString;
146
+ }, z.core.$strict>, z.ZodObject<{
147
+ name: z.ZodOptional<z.ZodString>;
148
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
149
+ createdAt: z.ZodOptional<z.ZodString>;
150
+ id: z.ZodString;
151
+ role: z.ZodLiteral<"user">;
152
+ content: z.ZodString;
153
+ }, z.core.$strict>, z.ZodObject<{
154
+ name: z.ZodOptional<z.ZodString>;
155
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
156
+ createdAt: z.ZodOptional<z.ZodString>;
157
+ id: z.ZodString;
158
+ role: z.ZodLiteral<"assistant">;
159
+ content: z.ZodOptional<z.ZodString>;
160
+ toolCalls: z.ZodOptional<z.ZodArray<z.ZodObject<{
161
+ id: z.ZodString;
162
+ type: z.ZodLiteral<"function">;
163
+ function: z.ZodObject<{
164
+ name: z.ZodString;
165
+ arguments: z.ZodString;
166
+ }, z.core.$strict>;
167
+ }, z.core.$strict>>>;
168
+ }, z.core.$strict>, z.ZodObject<{
169
+ name: z.ZodOptional<z.ZodString>;
170
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
171
+ createdAt: z.ZodOptional<z.ZodString>;
172
+ id: z.ZodString;
173
+ role: z.ZodLiteral<"tool">;
174
+ toolCallId: z.ZodString;
175
+ content: z.ZodString;
176
+ error: z.ZodOptional<z.ZodString>;
177
+ }, z.core.$strict>], "role">>;
178
+ tools: z.ZodDefault<z.ZodArray<z.ZodObject<{
179
+ name: z.ZodString;
180
+ description: z.ZodOptional<z.ZodString>;
181
+ parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
182
+ }, z.core.$strip>>>;
183
+ context: z.ZodDefault<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
184
+ description: z.ZodString;
185
+ value: z.ZodString;
186
+ }, z.core.$strip>, z.ZodDiscriminatedUnion<[z.ZodObject<{
187
+ type: z.ZodLiteral<"text">;
188
+ title: z.ZodOptional<z.ZodString>;
189
+ text: z.ZodString;
190
+ }, z.core.$strip>, z.ZodObject<{
191
+ type: z.ZodLiteral<"json">;
192
+ title: z.ZodOptional<z.ZodString>;
193
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
194
+ }, z.core.$strip>, z.ZodObject<{
195
+ type: z.ZodLiteral<"resource">;
196
+ title: z.ZodOptional<z.ZodString>;
197
+ uri: z.ZodString;
198
+ mimeType: z.ZodOptional<z.ZodString>;
199
+ text: z.ZodOptional<z.ZodString>;
200
+ }, z.core.$strip>], "type">]>>>;
201
+ forwardedProps: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
202
+ }, z.core.$strip>;
203
+ export type AgUiRuntimeInjectedTool = z.infer<typeof AgUiRuntimeInjectedToolSchema>;
204
+ export type AgUiRuntimeContextItem = z.infer<typeof AgUiRuntimeContextItemSchema>;
205
+ export type AgUiRuntimeMessage = z.infer<typeof AgUiRuntimeMessageSchema>;
206
+ export type AgUiRuntimeRequest = z.infer<typeof AgUiRuntimeRequestSchema>;
207
+ //# sourceMappingURL=runtime-ag-ui-contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-ag-ui-contract.d.ts","sourceRoot":"","sources":["../../../src/src/agent/runtime-ag-ui-contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAmBxB,eAAO,MAAM,sBAAsB,aAAqD,CAAC;AAEzF,eAAO,MAAM,6BAA6B;;;;iBAcxC,CAAC;AAEH,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;2BAqBvC,CAAC;AAQH,eAAO,MAAM,iCAAiC;;;kBAGnC,CAAC;AAEZ,eAAO,MAAM,yBAAyB;;;;;;;kBAI3B,CAAC;AAEZ,eAAO,MAAM,8BAA8B;;;;;;;kBAKhC,CAAC;AAEZ,eAAO,MAAM,4BAA4B;;;;;;;kBAK9B,CAAC;AAEZ,eAAO,MAAM,iCAAiC;;;;;;;;;;;;;;;kBAMnC,CAAC;AAEZ,eAAO,MAAM,4BAA4B;;;;;;;;;kBAO9B,CAAC;AAEZ,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BAKnC,CAAC;AAEH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;6BAMnC,CAAC;AAEH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAenC,CAAC;AAEH,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,6BAA6B,CAAC,CAAC;AACpF,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAC;AAClF,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAC1E,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC"}
@@ -0,0 +1,109 @@
1
+ import { z } from "zod";
2
+ const AGENT_ID_PATTERN = /^[a-zA-Z0-9_-]+$/;
3
+ const MAX_TOOL_PARAMETERS_BYTES = 16_384;
4
+ const MAX_CONTEXT_ITEM_BYTES = 16_384;
5
+ const MAX_CONTEXT_TOTAL_BYTES = 65_536;
6
+ const MAX_FORWARDED_PROPS_BYTES = 65_536;
7
+ const MAX_RUNTIME_MESSAGES = 100;
8
+ const encoder = new TextEncoder();
9
+ function isWithinJsonSizeLimit(value, maxBytes) {
10
+ try {
11
+ return encoder.encode(JSON.stringify(value)).byteLength <= maxBytes;
12
+ }
13
+ catch {
14
+ return false;
15
+ }
16
+ }
17
+ export const AgUiRuntimeRunIdSchema = z.string().min(1).max(128).regex(AGENT_ID_PATTERN);
18
+ export const AgUiRuntimeInjectedToolSchema = z.object({
19
+ name: z
20
+ .string()
21
+ .min(1)
22
+ .max(128)
23
+ .regex(/^[a-zA-Z][a-zA-Z0-9._:-]*$/, "Tool names must start with a letter and use a valid client-tool format"),
24
+ description: z.string().max(1024).optional(),
25
+ parameters: z.record(z.string(), z.unknown()).optional().refine((value) => value === undefined || isWithinJsonSizeLimit(value, MAX_TOOL_PARAMETERS_BYTES), { message: "Tool parameters must be less than 16 KB" }),
26
+ });
27
+ export const AgUiRuntimeContextItemSchema = z.discriminatedUnion("type", [
28
+ z.object({
29
+ type: z.literal("text"),
30
+ title: z.string().max(256).optional(),
31
+ text: z.string().max(MAX_CONTEXT_ITEM_BYTES),
32
+ }),
33
+ z.object({
34
+ type: z.literal("json"),
35
+ title: z.string().max(256).optional(),
36
+ data: z.record(z.string(), z.unknown()).refine((value) => isWithinJsonSizeLimit(value, MAX_CONTEXT_ITEM_BYTES), { message: "JSON context item must be less than 16 KB" }),
37
+ }),
38
+ z.object({
39
+ type: z.literal("resource"),
40
+ title: z.string().max(256).optional(),
41
+ uri: z.string().max(2048),
42
+ mimeType: z.string().max(256).optional(),
43
+ text: z.string().max(MAX_CONTEXT_ITEM_BYTES).optional(),
44
+ }),
45
+ ]);
46
+ const RuntimeMessageExtensionFieldsSchema = {
47
+ name: z.string().max(256).optional(),
48
+ metadata: z.record(z.string(), z.unknown()).optional(),
49
+ createdAt: z.string().optional(),
50
+ };
51
+ export const AgUiRuntimeToolFunctionCallSchema = z.object({
52
+ name: AgUiRuntimeInjectedToolSchema.shape.name,
53
+ arguments: z.string().max(MAX_TOOL_PARAMETERS_BYTES),
54
+ }).strict();
55
+ export const AgUiRuntimeToolCallSchema = z.object({
56
+ id: z.string().min(1).max(128),
57
+ type: z.literal("function"),
58
+ function: AgUiRuntimeToolFunctionCallSchema,
59
+ }).strict();
60
+ export const AgUiRuntimeSystemMessageSchema = z.object({
61
+ id: z.string().min(1),
62
+ role: z.literal("system"),
63
+ content: z.string(),
64
+ ...RuntimeMessageExtensionFieldsSchema,
65
+ }).strict();
66
+ export const AgUiRuntimeUserMessageSchema = z.object({
67
+ id: z.string().min(1),
68
+ role: z.literal("user"),
69
+ content: z.string(),
70
+ ...RuntimeMessageExtensionFieldsSchema,
71
+ }).strict();
72
+ export const AgUiRuntimeAssistantMessageSchema = z.object({
73
+ id: z.string().min(1),
74
+ role: z.literal("assistant"),
75
+ content: z.string().optional(),
76
+ toolCalls: z.array(AgUiRuntimeToolCallSchema).optional(),
77
+ ...RuntimeMessageExtensionFieldsSchema,
78
+ }).strict();
79
+ export const AgUiRuntimeToolMessageSchema = z.object({
80
+ id: z.string().min(1),
81
+ role: z.literal("tool"),
82
+ toolCallId: z.string().min(1).max(128),
83
+ content: z.string(),
84
+ error: z.string().optional(),
85
+ ...RuntimeMessageExtensionFieldsSchema,
86
+ }).strict();
87
+ export const AgUiRuntimeMessageSchema = z.discriminatedUnion("role", [
88
+ AgUiRuntimeSystemMessageSchema,
89
+ AgUiRuntimeUserMessageSchema,
90
+ AgUiRuntimeAssistantMessageSchema,
91
+ AgUiRuntimeToolMessageSchema,
92
+ ]);
93
+ export const AgUiRuntimeContextSchema = z.union([
94
+ z.object({
95
+ description: z.string().max(1024),
96
+ value: z.string().max(MAX_CONTEXT_ITEM_BYTES),
97
+ }),
98
+ AgUiRuntimeContextItemSchema,
99
+ ]);
100
+ export const AgUiRuntimeRequestSchema = z.object({
101
+ threadId: z.string().uuid(),
102
+ runId: AgUiRuntimeRunIdSchema,
103
+ parentRunId: AgUiRuntimeRunIdSchema.optional(),
104
+ state: z.unknown().optional(),
105
+ messages: z.array(AgUiRuntimeMessageSchema).max(MAX_RUNTIME_MESSAGES),
106
+ tools: z.array(AgUiRuntimeInjectedToolSchema).max(50).default([]),
107
+ context: z.array(AgUiRuntimeContextSchema).max(10).default([]).refine((value) => isWithinJsonSizeLimit(value, MAX_CONTEXT_TOTAL_BYTES), { message: "context must be less than 64 KB total" }),
108
+ forwardedProps: z.record(z.string(), z.unknown()).optional().refine((value) => value === undefined || isWithinJsonSizeLimit(value, MAX_FORWARDED_PROPS_BYTES), { message: "forwardedProps must be less than 64 KB" }),
109
+ });
@@ -1,7 +1,18 @@
1
1
  import { z } from "zod";
2
+ import { type AgUiRuntimeRequest } from "../agent/runtime-ag-ui-contract.js";
2
3
  export declare const RunIdSchema: z.ZodString;
3
4
  export declare const AgentIdSchema: z.ZodString;
4
- export declare const ClientToolNameSchema: z.ZodString;
5
+ export declare const RuntimeAgentSourceContextSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
6
+ type: z.ZodLiteral<"branch">;
7
+ branch: z.ZodString;
8
+ }, z.core.$strip>, z.ZodObject<{
9
+ type: z.ZodLiteral<"environment">;
10
+ environmentName: z.ZodString;
11
+ releaseId: z.ZodOptional<z.ZodString>;
12
+ }, z.core.$strip>, z.ZodObject<{
13
+ type: z.ZodLiteral<"release">;
14
+ releaseId: z.ZodString;
15
+ }, z.core.$strip>], "type">;
5
16
  export declare const RuntimeInjectedToolSchema: z.ZodObject<{
6
17
  name: z.ZodString;
7
18
  description: z.ZodOptional<z.ZodString>;
@@ -22,71 +33,6 @@ export declare const RuntimeContextItemSchema: z.ZodDiscriminatedUnion<[z.ZodObj
22
33
  mimeType: z.ZodOptional<z.ZodString>;
23
34
  text: z.ZodOptional<z.ZodString>;
24
35
  }, z.core.$strip>], "type">;
25
- export declare const RuntimeAgentSourceContextSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
26
- type: z.ZodLiteral<"branch">;
27
- branch: z.ZodString;
28
- }, z.core.$strip>, z.ZodObject<{
29
- type: z.ZodLiteral<"environment">;
30
- environmentName: z.ZodString;
31
- releaseId: z.ZodOptional<z.ZodString>;
32
- }, z.core.$strip>, z.ZodObject<{
33
- type: z.ZodLiteral<"release">;
34
- releaseId: z.ZodString;
35
- }, z.core.$strip>], "type">;
36
- export declare const RuntimeToolFunctionCallSchema: z.ZodObject<{
37
- name: z.ZodString;
38
- arguments: z.ZodString;
39
- }, z.core.$strict>;
40
- export declare const RuntimeToolCallSchema: z.ZodObject<{
41
- id: z.ZodString;
42
- type: z.ZodLiteral<"function">;
43
- function: z.ZodObject<{
44
- name: z.ZodString;
45
- arguments: z.ZodString;
46
- }, z.core.$strict>;
47
- }, z.core.$strict>;
48
- export declare const RuntimeSystemMessageSchema: z.ZodObject<{
49
- name: z.ZodOptional<z.ZodString>;
50
- metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
51
- createdAt: z.ZodOptional<z.ZodString>;
52
- id: z.ZodString;
53
- role: z.ZodLiteral<"system">;
54
- content: z.ZodString;
55
- }, z.core.$strict>;
56
- export declare const RuntimeUserMessageSchema: z.ZodObject<{
57
- name: z.ZodOptional<z.ZodString>;
58
- metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
59
- createdAt: z.ZodOptional<z.ZodString>;
60
- id: z.ZodString;
61
- role: z.ZodLiteral<"user">;
62
- content: z.ZodString;
63
- }, z.core.$strict>;
64
- export declare const RuntimeAssistantMessageSchema: z.ZodObject<{
65
- name: z.ZodOptional<z.ZodString>;
66
- metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
67
- createdAt: z.ZodOptional<z.ZodString>;
68
- id: z.ZodString;
69
- role: z.ZodLiteral<"assistant">;
70
- content: z.ZodOptional<z.ZodString>;
71
- toolCalls: z.ZodOptional<z.ZodArray<z.ZodObject<{
72
- id: z.ZodString;
73
- type: z.ZodLiteral<"function">;
74
- function: z.ZodObject<{
75
- name: z.ZodString;
76
- arguments: z.ZodString;
77
- }, z.core.$strict>;
78
- }, z.core.$strict>>>;
79
- }, z.core.$strict>;
80
- export declare const RuntimeToolMessageSchema: z.ZodObject<{
81
- name: z.ZodOptional<z.ZodString>;
82
- metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
83
- createdAt: z.ZodOptional<z.ZodString>;
84
- id: z.ZodString;
85
- role: z.ZodLiteral<"tool">;
86
- toolCallId: z.ZodString;
87
- content: z.ZodString;
88
- error: z.ZodOptional<z.ZodString>;
89
- }, z.core.$strict>;
90
36
  export declare const RuntimeMessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
91
37
  name: z.ZodOptional<z.ZodString>;
92
38
  metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
@@ -321,7 +267,7 @@ export declare const InternalAgentStreamRequestSchema: z.ZodObject<{
321
267
  }, z.core.$strip>], "type">>;
322
268
  forwardedProps: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
323
269
  }, z.core.$strip>;
324
- export declare function toRuntimeRunAgentInput(input: z.infer<typeof InternalAgentStreamRequestSchema>): z.infer<typeof RuntimeRunAgentInputSchema>;
270
+ export declare function toRuntimeRunAgentInput(input: z.infer<typeof InternalAgentStreamRequestSchema>): AgUiRuntimeRequest;
325
271
  export declare const ResumeSignalSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
326
272
  type: z.ZodLiteral<"tool_result">;
327
273
  toolCallId: z.ZodString;
@@ -331,7 +277,7 @@ export declare const ResumeSignalSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
331
277
  export type RuntimeInjectedTool = z.infer<typeof RuntimeInjectedToolSchema>;
332
278
  export type RuntimeContextItem = z.infer<typeof RuntimeContextItemSchema>;
333
279
  export type RuntimeAgentSourceContext = z.infer<typeof RuntimeAgentSourceContextSchema>;
334
- export type RuntimeRunAgentInput = z.infer<typeof RuntimeRunAgentInputSchema>;
280
+ export type RuntimeRunAgentInput = AgUiRuntimeRequest;
335
281
  export type InternalAgentStreamRequest = z.infer<typeof InternalAgentStreamRequestSchema>;
336
282
  export type ResumeSignal = z.infer<typeof ResumeSignalSchema>;
337
283
  //# sourceMappingURL=schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/src/internal-agents/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAoBxB,eAAO,MAAM,WAAW,aAAqD,CAAC;AAE9E,eAAO,MAAM,aAAa,aAAqD,CAAC;AAEhF,eAAO,MAAM,oBAAoB,aAO9B,CAAC;AAEJ,eAAO,MAAM,yBAAyB;;;;iBAOpC,CAAC;AAEH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;2BAqBnC,CAAC;AAEH,eAAO,MAAM,+BAA+B;;;;;;;;;;2BAc1C,CAAC;AAQH,eAAO,MAAM,6BAA6B;;;kBAG/B,CAAC;AAEZ,eAAO,MAAM,qBAAqB;;;;;;;kBAIvB,CAAC;AAEZ,eAAO,MAAM,0BAA0B;;;;;;;kBAK5B,CAAC;AAEZ,eAAO,MAAM,wBAAwB;;;;;;;kBAK1B,CAAC;AAEZ,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;kBAM/B,CAAC;AAEZ,eAAO,MAAM,wBAAwB;;;;;;;;;kBAO1B,CAAC;AAEZ,eAAO,MAAM,oBAAoB;;;;;;;;;;;;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kB,CAAC;AACtD,MAAM,MAAM,0BAA0B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gCAAgC,CAAC,CAAC;AAC1F,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
@@ -1,8 +1,6 @@
1
1
  import { z } from "zod";
2
+ import { AgUiRuntimeContextItemSchema, AgUiRuntimeContextSchema, AgUiRuntimeInjectedToolSchema, AgUiRuntimeMessageSchema, AgUiRuntimeRequestSchema, AgUiRuntimeRunIdSchema, } from "../agent/runtime-ag-ui-contract.js";
2
3
  const AGENT_ID_PATTERN = /^[a-zA-Z0-9_-]+$/;
3
- const MAX_TOOL_PARAMETERS_BYTES = 16_384;
4
- const MAX_CONTEXT_ITEM_BYTES = 16_384;
5
- const MAX_CONTEXT_TOTAL_BYTES = 65_536;
6
4
  const MAX_FORWARDED_PROPS_BYTES = 65_536;
7
5
  const MAX_TOOL_RESULT_BYTES = 65_536;
8
6
  const MAX_RUNTIME_MESSAGES = 100;
@@ -15,37 +13,8 @@ function isWithinJsonSizeLimit(value, maxBytes) {
15
13
  return false;
16
14
  }
17
15
  }
18
- export const RunIdSchema = z.string().min(1).max(128).regex(AGENT_ID_PATTERN);
16
+ export const RunIdSchema = AgUiRuntimeRunIdSchema;
19
17
  export const AgentIdSchema = z.string().min(1).max(128).regex(AGENT_ID_PATTERN);
20
- export const ClientToolNameSchema = z
21
- .string()
22
- .min(1)
23
- .max(128)
24
- .regex(/^[a-zA-Z][a-zA-Z0-9._:-]*$/, "Tool names must start with a letter and use a valid client-tool format");
25
- export const RuntimeInjectedToolSchema = z.object({
26
- name: ClientToolNameSchema,
27
- description: z.string().max(1024).optional(),
28
- parameters: z.record(z.string(), z.unknown()).optional().refine((value) => value === undefined || isWithinJsonSizeLimit(value, MAX_TOOL_PARAMETERS_BYTES), { message: "Tool parameters must be less than 16 KB" }),
29
- });
30
- export const RuntimeContextItemSchema = z.discriminatedUnion("type", [
31
- z.object({
32
- type: z.literal("text"),
33
- title: z.string().max(256).optional(),
34
- text: z.string().max(MAX_CONTEXT_ITEM_BYTES),
35
- }),
36
- z.object({
37
- type: z.literal("json"),
38
- title: z.string().max(256).optional(),
39
- data: z.record(z.string(), z.unknown()).refine((value) => isWithinJsonSizeLimit(value, MAX_CONTEXT_ITEM_BYTES), { message: "JSON context item must be less than 16 KB" }),
40
- }),
41
- z.object({
42
- type: z.literal("resource"),
43
- title: z.string().max(256).optional(),
44
- uri: z.string().max(2048),
45
- mimeType: z.string().max(256).optional(),
46
- text: z.string().max(MAX_CONTEXT_ITEM_BYTES).optional(),
47
- }),
48
- ]);
49
18
  export const RuntimeAgentSourceContextSchema = z.discriminatedUnion("type", [
50
19
  z.object({
51
20
  type: z.literal("branch"),
@@ -61,70 +30,11 @@ export const RuntimeAgentSourceContextSchema = z.discriminatedUnion("type", [
61
30
  releaseId: z.string().min(1).max(255),
62
31
  }),
63
32
  ]);
64
- const RuntimeMessageExtensionFieldsSchema = {
65
- name: z.string().max(256).optional(),
66
- metadata: z.record(z.string(), z.unknown()).optional(),
67
- createdAt: z.string().optional(),
68
- };
69
- export const RuntimeToolFunctionCallSchema = z.object({
70
- name: ClientToolNameSchema,
71
- arguments: z.string().max(MAX_TOOL_PARAMETERS_BYTES),
72
- }).strict();
73
- export const RuntimeToolCallSchema = z.object({
74
- id: z.string().min(1).max(128),
75
- type: z.literal("function"),
76
- function: RuntimeToolFunctionCallSchema,
77
- }).strict();
78
- export const RuntimeSystemMessageSchema = z.object({
79
- id: z.string().min(1),
80
- role: z.literal("system"),
81
- content: z.string(),
82
- ...RuntimeMessageExtensionFieldsSchema,
83
- }).strict();
84
- export const RuntimeUserMessageSchema = z.object({
85
- id: z.string().min(1),
86
- role: z.literal("user"),
87
- content: z.string(),
88
- ...RuntimeMessageExtensionFieldsSchema,
89
- }).strict();
90
- export const RuntimeAssistantMessageSchema = z.object({
91
- id: z.string().min(1),
92
- role: z.literal("assistant"),
93
- content: z.string().optional(),
94
- toolCalls: z.array(RuntimeToolCallSchema).optional(),
95
- ...RuntimeMessageExtensionFieldsSchema,
96
- }).strict();
97
- export const RuntimeToolMessageSchema = z.object({
98
- id: z.string().min(1),
99
- role: z.literal("tool"),
100
- toolCallId: z.string().min(1).max(128),
101
- content: z.string(),
102
- error: z.string().optional(),
103
- ...RuntimeMessageExtensionFieldsSchema,
104
- }).strict();
105
- export const RuntimeMessageSchema = z.discriminatedUnion("role", [
106
- RuntimeSystemMessageSchema,
107
- RuntimeUserMessageSchema,
108
- RuntimeAssistantMessageSchema,
109
- RuntimeToolMessageSchema,
110
- ]);
111
- export const RuntimeContextSchema = z.union([
112
- z.object({
113
- description: z.string().max(1024),
114
- value: z.string().max(MAX_CONTEXT_ITEM_BYTES),
115
- }),
116
- RuntimeContextItemSchema,
117
- ]);
118
- export const RuntimeRunAgentInputSchema = z.object({
119
- threadId: z.string().uuid(),
120
- runId: RunIdSchema,
121
- parentRunId: RunIdSchema.optional(),
122
- state: z.unknown().optional(),
123
- messages: z.array(RuntimeMessageSchema).max(MAX_RUNTIME_MESSAGES),
124
- tools: z.array(RuntimeInjectedToolSchema).max(50).default([]),
125
- context: z.array(RuntimeContextSchema).max(10).default([]).refine((value) => isWithinJsonSizeLimit(value, MAX_CONTEXT_TOTAL_BYTES), { message: "context must be less than 64 KB total" }),
126
- forwardedProps: z.record(z.string(), z.unknown()).optional().refine((value) => value === undefined || isWithinJsonSizeLimit(value, MAX_FORWARDED_PROPS_BYTES), { message: "forwardedProps must be less than 64 KB" }),
127
- });
33
+ export const RuntimeInjectedToolSchema = AgUiRuntimeInjectedToolSchema;
34
+ export const RuntimeContextItemSchema = AgUiRuntimeContextItemSchema;
35
+ export const RuntimeMessageSchema = AgUiRuntimeMessageSchema;
36
+ export const RuntimeContextSchema = AgUiRuntimeContextSchema;
37
+ export const RuntimeRunAgentInputSchema = AgUiRuntimeRequestSchema;
128
38
  export const InternalAgentCompatibilityMessageSchema = z.object({
129
39
  id: z.string().min(1),
130
40
  role: z.enum(["user", "assistant", "system", "tool"]),
@@ -140,7 +50,7 @@ export const InternalAgentStreamRequestSchema = z.object({
140
50
  state: z.unknown().optional(),
141
51
  messages: z.array(z.union([RuntimeMessageSchema, InternalAgentCompatibilityMessageSchema])).max(MAX_RUNTIME_MESSAGES),
142
52
  tools: z.array(RuntimeInjectedToolSchema).max(50).default([]),
143
- context: z.array(RuntimeContextSchema).max(10).default([]).refine((value) => isWithinJsonSizeLimit(value, MAX_CONTEXT_TOTAL_BYTES), { message: "context must be less than 64 KB total" }),
53
+ context: z.array(RuntimeContextSchema).max(10).default([]).refine((value) => isWithinJsonSizeLimit(value, 65_536), { message: "context must be less than 64 KB total" }),
144
54
  agentSource: RuntimeAgentSourceContextSchema.optional(),
145
55
  forwardedProps: z.record(z.string(), z.unknown()).optional().refine((value) => value === undefined || isWithinJsonSizeLimit(value, MAX_FORWARDED_PROPS_BYTES), { message: "forwardedProps must be less than 64 KB" }),
146
56
  });
@@ -1 +1 @@
1
- {"version":3,"file":"runtime-loader.d.ts","sourceRoot":"","sources":["../../../src/src/provider/runtime-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,qBAAqB,CAAC;AAC/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEjE,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,OAAO,CAAC,KAAK,CAAC;CAC9B;AAED,MAAM,WAAW,sBAAsB;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,OAAO,CAAC,KAAK,CAAC;C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AK,CAAC,EAAE,OAAO,OAAO,CAAC,KAAK,CAAC;CAC9B;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,OAAO,CAAC,KAAK,CAAC;CAC9B;AAu/CD,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,MAAM,GACd,YAAY,CAkDd;AAED,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,sBAAsB,EAC9B,OAAO,EAAE,MAAM,GACd,YAAY,CA4Dd;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,MAAM,GACd,YAAY,CAkDd;AAED,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,MAAM,GACd,gBAAgB,CA0ClB;AAED,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,MAAM,GACd,gBAAgB,CAgDlB"}
@@ -404,11 +404,11 @@ function buildAnthropicGenerateResult(payload) {
404
404
  usage: extractAnthropicUsage(payload),
405
405
  };
406
406
  }
407
- function parseAnthropicSseChunk(chunk) {
408
- const blocks = chunk.split("\n\n");
407
+ function parseSseChunk(chunk) {
408
+ const blocks = chunk.split(/\r?\n\r?\n/);
409
409
  const remainder = blocks.pop() ?? "";
410
410
  const events = blocks.flatMap((block) => {
411
- const dataLines = block.split("\n")
411
+ const dataLines = block.split(/\r?\n/)
412
412
  .filter((line) => line.startsWith("data:"))
413
413
  .map((line) => line.slice(5).trimStart());
414
414
  if (!dataLines.length) {
@@ -435,7 +435,7 @@ async function* streamAnthropicCompatibleParts(stream) {
435
435
  let usage;
436
436
  for await (const chunk of stream) {
437
437
  buffer += decoder.decode(chunk, { stream: true });
438
- const parsed = parseAnthropicSseChunk(buffer);
438
+ const parsed = parseSseChunk(buffer);
439
439
  buffer = parsed.remainder;
440
440
  for (const event of parsed.events) {
441
441
  if (event === "[DONE]") {
@@ -547,7 +547,7 @@ async function* streamAnthropicCompatibleParts(stream) {
547
547
  }
548
548
  }
549
549
  if (buffer.trim().length > 0) {
550
- const parsed = parseAnthropicSseChunk(`${buffer}\n\n`);
550
+ const parsed = parseSseChunk(`${buffer}\n\n`);
551
551
  for (const event of parsed.events) {
552
552
  if (event === "[DONE]") {
553
553
  continue;
@@ -855,7 +855,7 @@ async function* streamGoogleCompatibleParts(stream) {
855
855
  let usage;
856
856
  for await (const chunk of stream) {
857
857
  buffer += decoder.decode(chunk, { stream: true });
858
- const parsed = parseOpenAISseChunk(buffer);
858
+ const parsed = parseSseChunk(buffer);
859
859
  buffer = parsed.remainder;
860
860
  for (const event of parsed.events) {
861
861
  if (event === "[DONE]") {
@@ -902,7 +902,7 @@ async function* streamGoogleCompatibleParts(stream) {
902
902
  }
903
903
  }
904
904
  if (buffer.trim().length > 0) {
905
- const parsed = parseOpenAISseChunk(`${buffer}\n\n`);
905
+ const parsed = parseSseChunk(`${buffer}\n\n`);
906
906
  for (const event of parsed.events) {
907
907
  if (event === "[DONE]") {
908
908
  continue;
@@ -947,29 +947,6 @@ function buildOpenAIGenerateResult(payload) {
947
947
  usage: extractOpenAIUsage(payload),
948
948
  };
949
949
  }
950
- function parseOpenAISseChunk(chunk) {
951
- const blocks = chunk.split("\n\n");
952
- const remainder = blocks.pop() ?? "";
953
- const events = blocks.flatMap((block) => {
954
- const dataLines = block.split("\n")
955
- .filter((line) => line.startsWith("data:"))
956
- .map((line) => line.slice(5).trimStart());
957
- if (!dataLines.length) {
958
- return [];
959
- }
960
- const payload = dataLines.join("\n").trim();
961
- if (payload === "[DONE]") {
962
- return ["[DONE]"];
963
- }
964
- try {
965
- return [JSON.parse(payload)];
966
- }
967
- catch {
968
- return [];
969
- }
970
- });
971
- return { events, remainder };
972
- }
973
950
  async function* streamOpenAICompatibleParts(stream) {
974
951
  const decoder = new TextDecoder();
975
952
  let buffer = "";
@@ -978,7 +955,7 @@ async function* streamOpenAICompatibleParts(stream) {
978
955
  let usage;
979
956
  for await (const chunk of stream) {
980
957
  buffer += decoder.decode(chunk, { stream: true });
981
- const parsed = parseOpenAISseChunk(buffer);
958
+ const parsed = parseSseChunk(buffer);
982
959
  buffer = parsed.remainder;
983
960
  for (const event of parsed.events) {
984
961
  if (event === "[DONE]") {
@@ -1040,7 +1017,7 @@ async function* streamOpenAICompatibleParts(stream) {
1040
1017
  }
1041
1018
  }
1042
1019
  if (buffer.trim().length > 0) {
1043
- const parsed = parseOpenAISseChunk(`${buffer}\n\n`);
1020
+ const parsed = parseSseChunk(`${buffer}\n\n`);
1044
1021
  for (const event of parsed.events) {
1045
1022
  if (event === "[DONE]") {
1046
1023
  continue;
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.1.151";
1
+ export declare const VERSION = "0.1.152";
2
2
  //# sourceMappingURL=version-constant.d.ts.map
@@ -1,3 +1,3 @@
1
1
  // Keep in sync with deno.json version.
2
2
  // scripts/release.ts updates this constant during releases.
3
- export const VERSION = "0.1.151";
3
+ export const VERSION = "0.1.152";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "veryfront",
3
- "version": "0.1.151",
3
+ "version": "0.1.152",
4
4
  "description": "The simplest way to build AI-powered apps",
5
5
  "keywords": [
6
6
  "react",
package/src/deno.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export default {
2
2
  "name": "veryfront",
3
- "version": "0.1.151",
3
+ "version": "0.1.152",
4
4
  "license": "Apache-2.0",
5
5
  "nodeModulesDir": "auto",
6
6
  "exclude": [
@@ -135,6 +135,16 @@ export {
135
135
  } from "./composition/index.js";
136
136
 
137
137
  export { agent } from "./factory.js";
138
+ export {
139
+ type AgUiRuntimeContextItem,
140
+ AgUiRuntimeContextItemSchema,
141
+ type AgUiRuntimeInjectedTool,
142
+ AgUiRuntimeInjectedToolSchema,
143
+ type AgUiRuntimeMessage,
144
+ AgUiRuntimeMessageSchema,
145
+ type AgUiRuntimeRequest,
146
+ AgUiRuntimeRequestSchema,
147
+ } from "./runtime-ag-ui-contract.js";
138
148
  export {
139
149
  type AgUiContextItem,
140
150
  type AgUiHandlerConfigWithAgent,
@@ -0,0 +1,144 @@
1
+ import { z } from "zod";
2
+
3
+ const AGENT_ID_PATTERN = /^[a-zA-Z0-9_-]+$/;
4
+ const MAX_TOOL_PARAMETERS_BYTES = 16_384;
5
+ const MAX_CONTEXT_ITEM_BYTES = 16_384;
6
+ const MAX_CONTEXT_TOTAL_BYTES = 65_536;
7
+ const MAX_FORWARDED_PROPS_BYTES = 65_536;
8
+ const MAX_RUNTIME_MESSAGES = 100;
9
+
10
+ const encoder = new TextEncoder();
11
+
12
+ function isWithinJsonSizeLimit(value: unknown, maxBytes: number): boolean {
13
+ try {
14
+ return encoder.encode(JSON.stringify(value)).byteLength <= maxBytes;
15
+ } catch {
16
+ return false;
17
+ }
18
+ }
19
+
20
+ export const AgUiRuntimeRunIdSchema = z.string().min(1).max(128).regex(AGENT_ID_PATTERN);
21
+
22
+ export const AgUiRuntimeInjectedToolSchema = z.object({
23
+ name: z
24
+ .string()
25
+ .min(1)
26
+ .max(128)
27
+ .regex(
28
+ /^[a-zA-Z][a-zA-Z0-9._:-]*$/,
29
+ "Tool names must start with a letter and use a valid client-tool format",
30
+ ),
31
+ description: z.string().max(1024).optional(),
32
+ parameters: z.record(z.string(), z.unknown()).optional().refine(
33
+ (value) => value === undefined || isWithinJsonSizeLimit(value, MAX_TOOL_PARAMETERS_BYTES),
34
+ { message: "Tool parameters must be less than 16 KB" },
35
+ ),
36
+ });
37
+
38
+ export const AgUiRuntimeContextItemSchema = z.discriminatedUnion("type", [
39
+ z.object({
40
+ type: z.literal("text"),
41
+ title: z.string().max(256).optional(),
42
+ text: z.string().max(MAX_CONTEXT_ITEM_BYTES),
43
+ }),
44
+ z.object({
45
+ type: z.literal("json"),
46
+ title: z.string().max(256).optional(),
47
+ data: z.record(z.string(), z.unknown()).refine(
48
+ (value) => isWithinJsonSizeLimit(value, MAX_CONTEXT_ITEM_BYTES),
49
+ { message: "JSON context item must be less than 16 KB" },
50
+ ),
51
+ }),
52
+ z.object({
53
+ type: z.literal("resource"),
54
+ title: z.string().max(256).optional(),
55
+ uri: z.string().max(2048),
56
+ mimeType: z.string().max(256).optional(),
57
+ text: z.string().max(MAX_CONTEXT_ITEM_BYTES).optional(),
58
+ }),
59
+ ]);
60
+
61
+ const RuntimeMessageExtensionFieldsSchema = {
62
+ name: z.string().max(256).optional(),
63
+ metadata: z.record(z.string(), z.unknown()).optional(),
64
+ createdAt: z.string().optional(),
65
+ } as const;
66
+
67
+ export const AgUiRuntimeToolFunctionCallSchema = z.object({
68
+ name: AgUiRuntimeInjectedToolSchema.shape.name,
69
+ arguments: z.string().max(MAX_TOOL_PARAMETERS_BYTES),
70
+ }).strict();
71
+
72
+ export const AgUiRuntimeToolCallSchema = z.object({
73
+ id: z.string().min(1).max(128),
74
+ type: z.literal("function"),
75
+ function: AgUiRuntimeToolFunctionCallSchema,
76
+ }).strict();
77
+
78
+ export const AgUiRuntimeSystemMessageSchema = z.object({
79
+ id: z.string().min(1),
80
+ role: z.literal("system"),
81
+ content: z.string(),
82
+ ...RuntimeMessageExtensionFieldsSchema,
83
+ }).strict();
84
+
85
+ export const AgUiRuntimeUserMessageSchema = z.object({
86
+ id: z.string().min(1),
87
+ role: z.literal("user"),
88
+ content: z.string(),
89
+ ...RuntimeMessageExtensionFieldsSchema,
90
+ }).strict();
91
+
92
+ export const AgUiRuntimeAssistantMessageSchema = z.object({
93
+ id: z.string().min(1),
94
+ role: z.literal("assistant"),
95
+ content: z.string().optional(),
96
+ toolCalls: z.array(AgUiRuntimeToolCallSchema).optional(),
97
+ ...RuntimeMessageExtensionFieldsSchema,
98
+ }).strict();
99
+
100
+ export const AgUiRuntimeToolMessageSchema = z.object({
101
+ id: z.string().min(1),
102
+ role: z.literal("tool"),
103
+ toolCallId: z.string().min(1).max(128),
104
+ content: z.string(),
105
+ error: z.string().optional(),
106
+ ...RuntimeMessageExtensionFieldsSchema,
107
+ }).strict();
108
+
109
+ export const AgUiRuntimeMessageSchema = z.discriminatedUnion("role", [
110
+ AgUiRuntimeSystemMessageSchema,
111
+ AgUiRuntimeUserMessageSchema,
112
+ AgUiRuntimeAssistantMessageSchema,
113
+ AgUiRuntimeToolMessageSchema,
114
+ ]);
115
+
116
+ export const AgUiRuntimeContextSchema = z.union([
117
+ z.object({
118
+ description: z.string().max(1024),
119
+ value: z.string().max(MAX_CONTEXT_ITEM_BYTES),
120
+ }),
121
+ AgUiRuntimeContextItemSchema,
122
+ ]);
123
+
124
+ export const AgUiRuntimeRequestSchema = z.object({
125
+ threadId: z.string().uuid(),
126
+ runId: AgUiRuntimeRunIdSchema,
127
+ parentRunId: AgUiRuntimeRunIdSchema.optional(),
128
+ state: z.unknown().optional(),
129
+ messages: z.array(AgUiRuntimeMessageSchema).max(MAX_RUNTIME_MESSAGES),
130
+ tools: z.array(AgUiRuntimeInjectedToolSchema).max(50).default([]),
131
+ context: z.array(AgUiRuntimeContextSchema).max(10).default([]).refine(
132
+ (value) => isWithinJsonSizeLimit(value, MAX_CONTEXT_TOTAL_BYTES),
133
+ { message: "context must be less than 64 KB total" },
134
+ ),
135
+ forwardedProps: z.record(z.string(), z.unknown()).optional().refine(
136
+ (value) => value === undefined || isWithinJsonSizeLimit(value, MAX_FORWARDED_PROPS_BYTES),
137
+ { message: "forwardedProps must be less than 64 KB" },
138
+ ),
139
+ });
140
+
141
+ export type AgUiRuntimeInjectedTool = z.infer<typeof AgUiRuntimeInjectedToolSchema>;
142
+ export type AgUiRuntimeContextItem = z.infer<typeof AgUiRuntimeContextItemSchema>;
143
+ export type AgUiRuntimeMessage = z.infer<typeof AgUiRuntimeMessageSchema>;
144
+ export type AgUiRuntimeRequest = z.infer<typeof AgUiRuntimeRequestSchema>;
@@ -1,9 +1,17 @@
1
1
  import { z } from "zod";
2
+ import {
3
+ AgUiRuntimeContextItemSchema,
4
+ AgUiRuntimeContextSchema,
5
+ AgUiRuntimeInjectedToolSchema,
6
+ type AgUiRuntimeMessage,
7
+ AgUiRuntimeMessageSchema,
8
+ type AgUiRuntimeRequest,
9
+ AgUiRuntimeRequestSchema,
10
+ AgUiRuntimeRunIdSchema,
11
+ AgUiRuntimeToolCallSchema,
12
+ } from "../agent/runtime-ag-ui-contract.js";
2
13
 
3
14
  const AGENT_ID_PATTERN = /^[a-zA-Z0-9_-]+$/;
4
- const MAX_TOOL_PARAMETERS_BYTES = 16_384;
5
- const MAX_CONTEXT_ITEM_BYTES = 16_384;
6
- const MAX_CONTEXT_TOTAL_BYTES = 65_536;
7
15
  const MAX_FORWARDED_PROPS_BYTES = 65_536;
8
16
  const MAX_TOOL_RESULT_BYTES = 65_536;
9
17
  const MAX_RUNTIME_MESSAGES = 100;
@@ -18,51 +26,10 @@ function isWithinJsonSizeLimit(value: unknown, maxBytes: number): boolean {
18
26
  }
19
27
  }
20
28
 
21
- export const RunIdSchema = z.string().min(1).max(128).regex(AGENT_ID_PATTERN);
29
+ export const RunIdSchema = AgUiRuntimeRunIdSchema;
22
30
 
23
31
  export const AgentIdSchema = z.string().min(1).max(128).regex(AGENT_ID_PATTERN);
24
32
 
25
- export const ClientToolNameSchema = z
26
- .string()
27
- .min(1)
28
- .max(128)
29
- .regex(
30
- /^[a-zA-Z][a-zA-Z0-9._:-]*$/,
31
- "Tool names must start with a letter and use a valid client-tool format",
32
- );
33
-
34
- export const RuntimeInjectedToolSchema = z.object({
35
- name: ClientToolNameSchema,
36
- description: z.string().max(1024).optional(),
37
- parameters: z.record(z.string(), z.unknown()).optional().refine(
38
- (value) => value === undefined || isWithinJsonSizeLimit(value, MAX_TOOL_PARAMETERS_BYTES),
39
- { message: "Tool parameters must be less than 16 KB" },
40
- ),
41
- });
42
-
43
- export const RuntimeContextItemSchema = z.discriminatedUnion("type", [
44
- z.object({
45
- type: z.literal("text"),
46
- title: z.string().max(256).optional(),
47
- text: z.string().max(MAX_CONTEXT_ITEM_BYTES),
48
- }),
49
- z.object({
50
- type: z.literal("json"),
51
- title: z.string().max(256).optional(),
52
- data: z.record(z.string(), z.unknown()).refine(
53
- (value) => isWithinJsonSizeLimit(value, MAX_CONTEXT_ITEM_BYTES),
54
- { message: "JSON context item must be less than 16 KB" },
55
- ),
56
- }),
57
- z.object({
58
- type: z.literal("resource"),
59
- title: z.string().max(256).optional(),
60
- uri: z.string().max(2048),
61
- mimeType: z.string().max(256).optional(),
62
- text: z.string().max(MAX_CONTEXT_ITEM_BYTES).optional(),
63
- }),
64
- ]);
65
-
66
33
  export const RuntimeAgentSourceContextSchema = z.discriminatedUnion("type", [
67
34
  z.object({
68
35
  type: z.literal("branch"),
@@ -79,85 +46,11 @@ export const RuntimeAgentSourceContextSchema = z.discriminatedUnion("type", [
79
46
  }),
80
47
  ]);
81
48
 
82
- const RuntimeMessageExtensionFieldsSchema = {
83
- name: z.string().max(256).optional(),
84
- metadata: z.record(z.string(), z.unknown()).optional(),
85
- createdAt: z.string().optional(),
86
- } as const;
87
-
88
- export const RuntimeToolFunctionCallSchema = z.object({
89
- name: ClientToolNameSchema,
90
- arguments: z.string().max(MAX_TOOL_PARAMETERS_BYTES),
91
- }).strict();
92
-
93
- export const RuntimeToolCallSchema = z.object({
94
- id: z.string().min(1).max(128),
95
- type: z.literal("function"),
96
- function: RuntimeToolFunctionCallSchema,
97
- }).strict();
98
-
99
- export const RuntimeSystemMessageSchema = z.object({
100
- id: z.string().min(1),
101
- role: z.literal("system"),
102
- content: z.string(),
103
- ...RuntimeMessageExtensionFieldsSchema,
104
- }).strict();
105
-
106
- export const RuntimeUserMessageSchema = z.object({
107
- id: z.string().min(1),
108
- role: z.literal("user"),
109
- content: z.string(),
110
- ...RuntimeMessageExtensionFieldsSchema,
111
- }).strict();
112
-
113
- export const RuntimeAssistantMessageSchema = z.object({
114
- id: z.string().min(1),
115
- role: z.literal("assistant"),
116
- content: z.string().optional(),
117
- toolCalls: z.array(RuntimeToolCallSchema).optional(),
118
- ...RuntimeMessageExtensionFieldsSchema,
119
- }).strict();
120
-
121
- export const RuntimeToolMessageSchema = z.object({
122
- id: z.string().min(1),
123
- role: z.literal("tool"),
124
- toolCallId: z.string().min(1).max(128),
125
- content: z.string(),
126
- error: z.string().optional(),
127
- ...RuntimeMessageExtensionFieldsSchema,
128
- }).strict();
129
-
130
- export const RuntimeMessageSchema = z.discriminatedUnion("role", [
131
- RuntimeSystemMessageSchema,
132
- RuntimeUserMessageSchema,
133
- RuntimeAssistantMessageSchema,
134
- RuntimeToolMessageSchema,
135
- ]);
136
-
137
- export const RuntimeContextSchema = z.union([
138
- z.object({
139
- description: z.string().max(1024),
140
- value: z.string().max(MAX_CONTEXT_ITEM_BYTES),
141
- }),
142
- RuntimeContextItemSchema,
143
- ]);
144
-
145
- export const RuntimeRunAgentInputSchema = z.object({
146
- threadId: z.string().uuid(),
147
- runId: RunIdSchema,
148
- parentRunId: RunIdSchema.optional(),
149
- state: z.unknown().optional(),
150
- messages: z.array(RuntimeMessageSchema).max(MAX_RUNTIME_MESSAGES),
151
- tools: z.array(RuntimeInjectedToolSchema).max(50).default([]),
152
- context: z.array(RuntimeContextSchema).max(10).default([]).refine(
153
- (value) => isWithinJsonSizeLimit(value, MAX_CONTEXT_TOTAL_BYTES),
154
- { message: "context must be less than 64 KB total" },
155
- ),
156
- forwardedProps: z.record(z.string(), z.unknown()).optional().refine(
157
- (value) => value === undefined || isWithinJsonSizeLimit(value, MAX_FORWARDED_PROPS_BYTES),
158
- { message: "forwardedProps must be less than 64 KB" },
159
- ),
160
- });
49
+ export const RuntimeInjectedToolSchema = AgUiRuntimeInjectedToolSchema;
50
+ export const RuntimeContextItemSchema = AgUiRuntimeContextItemSchema;
51
+ export const RuntimeMessageSchema = AgUiRuntimeMessageSchema;
52
+ export const RuntimeContextSchema = AgUiRuntimeContextSchema;
53
+ export const RuntimeRunAgentInputSchema = AgUiRuntimeRequestSchema;
161
54
 
162
55
  export const InternalAgentCompatibilityMessageSchema = z.object({
163
56
  id: z.string().min(1),
@@ -178,7 +71,7 @@ export const InternalAgentStreamRequestSchema = z.object({
178
71
  ),
179
72
  tools: z.array(RuntimeInjectedToolSchema).max(50).default([]),
180
73
  context: z.array(RuntimeContextSchema).max(10).default([]).refine(
181
- (value) => isWithinJsonSizeLimit(value, MAX_CONTEXT_TOTAL_BYTES),
74
+ (value) => isWithinJsonSizeLimit(value, 65_536),
182
75
  { message: "context must be less than 64 KB total" },
183
76
  ),
184
77
  agentSource: RuntimeAgentSourceContextSchema.optional(),
@@ -188,7 +81,7 @@ export const InternalAgentStreamRequestSchema = z.object({
188
81
  ),
189
82
  });
190
83
 
191
- type RuntimeMessage = z.infer<typeof RuntimeMessageSchema>;
84
+ type RuntimeMessage = AgUiRuntimeMessage;
192
85
  type InternalAgentCompatibilityMessage = z.infer<typeof InternalAgentCompatibilityMessageSchema>;
193
86
 
194
87
  function extractToolArgs(
@@ -243,7 +136,7 @@ function isCanonicalToolCallPart(part: Record<string, unknown>): boolean {
243
136
 
244
137
  function getToolCallShape(
245
138
  part: Record<string, unknown>,
246
- ): z.infer<typeof RuntimeToolCallSchema> | null {
139
+ ): z.infer<typeof AgUiRuntimeToolCallSchema> | null {
247
140
  const id = getPartString(part, "toolCallId", "tool_call_id", "id");
248
141
  const name = getPartString(part, "toolName", "tool_name", "name");
249
142
 
@@ -357,7 +250,7 @@ function toRuntimeMessage(
357
250
 
358
251
  export function toRuntimeRunAgentInput(
359
252
  input: z.infer<typeof InternalAgentStreamRequestSchema>,
360
- ): z.infer<typeof RuntimeRunAgentInputSchema> {
253
+ ): AgUiRuntimeRequest {
361
254
  return {
362
255
  threadId: input.threadId,
363
256
  runId: input.runId,
@@ -385,6 +278,6 @@ export const ResumeSignalSchema = z.discriminatedUnion("type", [
385
278
  export type RuntimeInjectedTool = z.infer<typeof RuntimeInjectedToolSchema>;
386
279
  export type RuntimeContextItem = z.infer<typeof RuntimeContextItemSchema>;
387
280
  export type RuntimeAgentSourceContext = z.infer<typeof RuntimeAgentSourceContextSchema>;
388
- export type RuntimeRunAgentInput = z.infer<typeof RuntimeRunAgentInputSchema>;
281
+ export type RuntimeRunAgentInput = AgUiRuntimeRequest;
389
282
  export type InternalAgentStreamRequest = z.infer<typeof InternalAgentStreamRequestSchema>;
390
283
  export type ResumeSignal = z.infer<typeof ResumeSignalSchema>;
@@ -732,14 +732,14 @@ function buildAnthropicGenerateResult(payload: unknown): {
732
732
  };
733
733
  }
734
734
 
735
- function parseAnthropicSseChunk(chunk: string): {
735
+ function parseSseChunk(chunk: string): {
736
736
  events: Array<unknown | "[DONE]">;
737
737
  remainder: string;
738
738
  } {
739
- const blocks = chunk.split("\n\n");
739
+ const blocks = chunk.split(/\r?\n\r?\n/);
740
740
  const remainder = blocks.pop() ?? "";
741
741
  const events = blocks.flatMap((block) => {
742
- const dataLines = block.split("\n")
742
+ const dataLines = block.split(/\r?\n/)
743
743
  .filter((line) => line.startsWith("data:"))
744
744
  .map((line) => line.slice(5).trimStart());
745
745
 
@@ -773,7 +773,7 @@ async function* streamAnthropicCompatibleParts(
773
773
 
774
774
  for await (const chunk of stream) {
775
775
  buffer += decoder.decode(chunk, { stream: true });
776
- const parsed = parseAnthropicSseChunk(buffer);
776
+ const parsed = parseSseChunk(buffer);
777
777
  buffer = parsed.remainder;
778
778
 
779
779
  for (const event of parsed.events) {
@@ -912,7 +912,7 @@ async function* streamAnthropicCompatibleParts(
912
912
  }
913
913
 
914
914
  if (buffer.trim().length > 0) {
915
- const parsed = parseAnthropicSseChunk(`${buffer}\n\n`);
915
+ const parsed = parseSseChunk(`${buffer}\n\n`);
916
916
  for (const event of parsed.events) {
917
917
  if (event === "[DONE]") {
918
918
  continue;
@@ -1313,7 +1313,7 @@ async function* streamGoogleCompatibleParts(
1313
1313
 
1314
1314
  for await (const chunk of stream) {
1315
1315
  buffer += decoder.decode(chunk, { stream: true });
1316
- const parsed = parseOpenAISseChunk(buffer);
1316
+ const parsed = parseSseChunk(buffer);
1317
1317
  buffer = parsed.remainder;
1318
1318
 
1319
1319
  for (const event of parsed.events) {
@@ -1367,7 +1367,7 @@ async function* streamGoogleCompatibleParts(
1367
1367
  }
1368
1368
 
1369
1369
  if (buffer.trim().length > 0) {
1370
- const parsed = parseOpenAISseChunk(`${buffer}\n\n`);
1370
+ const parsed = parseSseChunk(`${buffer}\n\n`);
1371
1371
  for (const event of parsed.events) {
1372
1372
  if (event === "[DONE]") {
1373
1373
  continue;
@@ -1430,36 +1430,6 @@ function buildOpenAIGenerateResult(payload: unknown): {
1430
1430
  };
1431
1431
  }
1432
1432
 
1433
- function parseOpenAISseChunk(chunk: string): {
1434
- events: Array<unknown | "[DONE]">;
1435
- remainder: string;
1436
- } {
1437
- const blocks = chunk.split("\n\n");
1438
- const remainder = blocks.pop() ?? "";
1439
- const events = blocks.flatMap((block) => {
1440
- const dataLines = block.split("\n")
1441
- .filter((line) => line.startsWith("data:"))
1442
- .map((line) => line.slice(5).trimStart());
1443
-
1444
- if (!dataLines.length) {
1445
- return [];
1446
- }
1447
-
1448
- const payload = dataLines.join("\n").trim();
1449
- if (payload === "[DONE]") {
1450
- return ["[DONE]" as const];
1451
- }
1452
-
1453
- try {
1454
- return [JSON.parse(payload) as unknown];
1455
- } catch {
1456
- return [];
1457
- }
1458
- });
1459
-
1460
- return { events, remainder };
1461
- }
1462
-
1463
1433
  async function* streamOpenAICompatibleParts(
1464
1434
  stream: ReadableStream<Uint8Array>,
1465
1435
  ): AsyncIterable<unknown> {
@@ -1471,7 +1441,7 @@ async function* streamOpenAICompatibleParts(
1471
1441
 
1472
1442
  for await (const chunk of stream) {
1473
1443
  buffer += decoder.decode(chunk, { stream: true });
1474
- const parsed = parseOpenAISseChunk(buffer);
1444
+ const parsed = parseSseChunk(buffer);
1475
1445
  buffer = parsed.remainder;
1476
1446
 
1477
1447
  for (const event of parsed.events) {
@@ -1545,7 +1515,7 @@ async function* streamOpenAICompatibleParts(
1545
1515
  }
1546
1516
 
1547
1517
  if (buffer.trim().length > 0) {
1548
- const parsed = parseOpenAISseChunk(`${buffer}\n\n`);
1518
+ const parsed = parseSseChunk(`${buffer}\n\n`);
1549
1519
  for (const event of parsed.events) {
1550
1520
  if (event === "[DONE]") {
1551
1521
  continue;
@@ -1,3 +1,3 @@
1
1
  // Keep in sync with deno.json version.
2
2
  // scripts/release.ts updates this constant during releases.
3
- export const VERSION = "0.1.151";
3
+ export const VERSION = "0.1.152";