veryfront 0.1.221 → 0.1.223
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.d.ts +0 -3
- package/esm/deno.js +1 -4
- package/esm/src/agent/ag-ui-runtime-handler.d.ts +29 -0
- package/esm/src/agent/ag-ui-runtime-handler.d.ts.map +1 -0
- package/esm/src/agent/ag-ui-runtime-handler.js +291 -0
- package/esm/src/agent/ag-ui-runtime-support.d.ts +4 -0
- package/esm/src/agent/ag-ui-runtime-support.d.ts.map +1 -0
- package/esm/src/agent/ag-ui-runtime-support.js +56 -0
- package/esm/src/agent/index.d.ts +3 -1
- package/esm/src/agent/index.d.ts.map +1 -1
- package/esm/src/agent/index.js +3 -1
- package/esm/src/agent/runtime-ag-ui-contract.d.ts +2 -0
- package/esm/src/agent/runtime-ag-ui-contract.d.ts.map +1 -1
- package/esm/src/agent/runtime-ag-ui-contract.js +26 -0
- package/esm/src/internal-agents/run-stream.d.ts.map +1 -1
- package/esm/src/internal-agents/run-stream.js +2 -54
- package/esm/src/platform/compat/media-types.d.ts.map +1 -1
- package/esm/src/platform/compat/media-types.js +6 -6
- package/esm/src/react/components/chat/theme.d.ts +1 -1
- package/esm/src/react/components/chat/theme.d.ts.map +1 -1
- package/esm/src/react/components/chat/theme.js +1 -1
- package/esm/src/server/handlers/dev/framework-candidates.generated.d.ts.map +1 -1
- package/esm/src/server/handlers/dev/framework-candidates.generated.js +1 -0
- package/esm/src/utils/clsx.d.ts +14 -0
- package/esm/src/utils/clsx.d.ts.map +1 -0
- package/esm/src/utils/clsx.js +32 -0
- package/esm/src/utils/mime-types.d.ts +42 -0
- package/esm/src/utils/mime-types.d.ts.map +1 -0
- package/esm/src/utils/mime-types.js +148 -0
- package/esm/src/utils/version-constant.d.ts +1 -1
- package/esm/src/utils/version-constant.js +1 -1
- package/package.json +1 -3
- package/src/deno.js +1 -4
- package/src/src/agent/ag-ui-runtime-handler.ts +453 -0
- package/src/src/agent/ag-ui-runtime-support.ts +64 -0
- package/src/src/agent/index.ts +11 -0
- package/src/src/agent/runtime-ag-ui-contract.ts +37 -0
- package/src/src/internal-agents/run-stream.ts +2 -57
- package/src/src/platform/compat/media-types.ts +10 -6
- package/src/src/react/components/chat/theme.ts +1 -1
- package/src/src/server/handlers/dev/framework-candidates.generated.ts +1 -0
- package/src/src/utils/clsx.ts +40 -0
- package/src/src/utils/mime-types.ts +155 -0
- package/src/src/utils/version-constant.ts +1 -1
package/esm/deno.d.ts
CHANGED
|
@@ -212,7 +212,6 @@ declare namespace _default {
|
|
|
212
212
|
"@std/fs": string;
|
|
213
213
|
"@std/async": string;
|
|
214
214
|
"@std/front-matter/yaml": string;
|
|
215
|
-
csstype: string;
|
|
216
215
|
"@types/react": string;
|
|
217
216
|
"@types/react-dom": string;
|
|
218
217
|
react: string;
|
|
@@ -241,7 +240,6 @@ declare namespace _default {
|
|
|
241
240
|
"es-module-lexer": string;
|
|
242
241
|
"gray-matter": string;
|
|
243
242
|
zod: string;
|
|
244
|
-
"mime-types": string;
|
|
245
243
|
mdast: string;
|
|
246
244
|
hast: string;
|
|
247
245
|
unist: string;
|
|
@@ -263,7 +261,6 @@ declare namespace _default {
|
|
|
263
261
|
"@babel/generator": string;
|
|
264
262
|
"@babel/types": string;
|
|
265
263
|
"class-variance-authority": string;
|
|
266
|
-
clsx: string;
|
|
267
264
|
"tailwind-merge": string;
|
|
268
265
|
"@kreuzberg/wasm": string;
|
|
269
266
|
"#kreuzberg-wasm-glue": string;
|
package/esm/deno.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export default {
|
|
2
2
|
"name": "veryfront",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.223",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"nodeModulesDir": "auto",
|
|
6
6
|
"workspace": [
|
|
@@ -225,7 +225,6 @@ export default {
|
|
|
225
225
|
"@std/fs": "jsr:@std/fs",
|
|
226
226
|
"@std/async": "jsr:@std/async",
|
|
227
227
|
"@std/front-matter/yaml": "./src/platform/compat/std/front-matter-yaml.ts",
|
|
228
|
-
"csstype": "https://esm.sh/csstype@3.2.3",
|
|
229
228
|
"@types/react": "https://esm.sh/@types/react@18.3.27?deps=csstype@3.2.3",
|
|
230
229
|
"@types/react-dom": "https://esm.sh/@types/react-dom@18.3.7?deps=csstype@3.2.3",
|
|
231
230
|
"react": "https://esm.sh/react@19.2.4?target=es2022&deps=csstype@3.2.3",
|
|
@@ -254,7 +253,6 @@ export default {
|
|
|
254
253
|
"es-module-lexer": "npm:es-module-lexer@2.0.0",
|
|
255
254
|
"gray-matter": "npm:gray-matter@4.0.3",
|
|
256
255
|
"zod": "npm:zod@4.3.6",
|
|
257
|
-
"mime-types": "npm:mime-types@3.0.2",
|
|
258
256
|
"mdast": "npm:@types/mdast@4.0.3",
|
|
259
257
|
"hast": "npm:@types/hast@3.0.3",
|
|
260
258
|
"unist": "npm:@types/unist@3.0.2",
|
|
@@ -276,7 +274,6 @@ export default {
|
|
|
276
274
|
"@babel/generator": "npm:@babel/generator@7.29.1",
|
|
277
275
|
"@babel/types": "npm:@babel/types@7.29.0",
|
|
278
276
|
"class-variance-authority": "npm:class-variance-authority@0.7.1",
|
|
279
|
-
"clsx": "npm:clsx@2.1.1",
|
|
280
277
|
"tailwind-merge": "npm:tailwind-merge@3.5.0",
|
|
281
278
|
"@kreuzberg/wasm": "npm:@kreuzberg/wasm@4.5.2",
|
|
282
279
|
"#kreuzberg-wasm-glue": "npm:@kreuzberg/wasm@4.5.2/dist/pkg/kreuzberg_wasm.js"
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type RunResumeSessionManager } from "./runtime/index.js";
|
|
2
|
+
import type { Agent } from "./types.js";
|
|
3
|
+
import { type AgUiRuntimeRequest } from "./runtime-ag-ui-contract.js";
|
|
4
|
+
type AgUiResumeValue = {
|
|
5
|
+
result: unknown;
|
|
6
|
+
isError: boolean;
|
|
7
|
+
};
|
|
8
|
+
export interface AgUiRuntimeHandlerExecuteInput {
|
|
9
|
+
request: Request;
|
|
10
|
+
agUiInput: AgUiRuntimeRequest;
|
|
11
|
+
context: Record<string, unknown>;
|
|
12
|
+
createDefaultResponse?: () => Promise<Response>;
|
|
13
|
+
}
|
|
14
|
+
export type AgUiRuntimeHandlerExecute = (input: AgUiRuntimeHandlerExecuteInput) => Promise<Response> | Response;
|
|
15
|
+
export interface AgUiRuntimeHandlerOptions {
|
|
16
|
+
context?: Record<string, unknown> | ((request: Request) => Record<string, unknown> | Promise<Record<string, unknown>>);
|
|
17
|
+
sessionManager?: RunResumeSessionManager<AgUiResumeValue>;
|
|
18
|
+
execute?: AgUiRuntimeHandlerExecute;
|
|
19
|
+
}
|
|
20
|
+
export interface AgUiRuntimeHandlerConfigWithAgent extends AgUiRuntimeHandlerOptions {
|
|
21
|
+
agent: Agent;
|
|
22
|
+
}
|
|
23
|
+
export type AgUiRuntimeHandlerConfig = AgUiRuntimeHandlerConfigWithAgent | (AgUiRuntimeHandlerOptions & {
|
|
24
|
+
agent?: undefined;
|
|
25
|
+
execute: AgUiRuntimeHandlerExecute;
|
|
26
|
+
});
|
|
27
|
+
export declare function createAgUiRuntimeHandler(config: AgUiRuntimeHandlerConfig): (requestOrCtx: unknown) => Promise<Response>;
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=ag-ui-runtime-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ag-ui-runtime-handler.d.ts","sourceRoot":"","sources":["../../../src/src/agent/ag-ui-runtime-handler.ts"],"names":[],"mappings":"AAIA,OAAO,EAGL,KAAK,uBAAuB,EAC7B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAEL,KAAK,kBAAkB,EAExB,MAAM,6BAA6B,CAAC;AAgBrC,KAAK,eAAe,GAAG;IAAE,MAAM,EAAE,OAAO,CA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"../tool/index.js";
|
|
5
|
+
import { AgentRuntime, RunAlreadyExistsError, } from "./runtime/index.js";
|
|
6
|
+
import { parseAgUiRuntimeRequestOrError, } from "./runtime-ag-ui-contract.js";
|
|
7
|
+
import { normalizeAgUiRuntimeMessages } from "./ag-ui-runtime-support.js";
|
|
8
|
+
import { createStreamTransformState, finalizeRunEvents, formatAgUiEvent, mapRuntimeEventToAgUi, } from "../internal-agents/ag-ui-sse.js";
|
|
9
|
+
import { streamDataStreamEvents } from "./data-stream.js";
|
|
10
|
+
const AG_UI_HEADERS = {
|
|
11
|
+
"Content-Type": "text/event-stream",
|
|
12
|
+
"Cache-Control": "no-cache",
|
|
13
|
+
Connection: "keep-alive",
|
|
14
|
+
};
|
|
15
|
+
function isRequest(obj) {
|
|
16
|
+
return (typeof obj === "object" &&
|
|
17
|
+
obj !== null &&
|
|
18
|
+
"json" in obj &&
|
|
19
|
+
typeof obj.json === "function" &&
|
|
20
|
+
"url" in obj &&
|
|
21
|
+
typeof obj.url === "string" &&
|
|
22
|
+
"method" in obj &&
|
|
23
|
+
typeof obj.method === "string");
|
|
24
|
+
}
|
|
25
|
+
function isRecord(value) {
|
|
26
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
27
|
+
}
|
|
28
|
+
function extractRequest(requestOrCtx) {
|
|
29
|
+
if (isRequest(requestOrCtx))
|
|
30
|
+
return requestOrCtx;
|
|
31
|
+
if (typeof requestOrCtx === "object" && requestOrCtx !== null && "request" in requestOrCtx) {
|
|
32
|
+
const candidate = requestOrCtx.request;
|
|
33
|
+
if (isRequest(candidate))
|
|
34
|
+
return candidate;
|
|
35
|
+
}
|
|
36
|
+
throw INVALID_ARGUMENT.create({
|
|
37
|
+
detail: "Invalid handler argument: expected Request or APIContext",
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function buildStreamContext(request, baseContext) {
|
|
41
|
+
return {
|
|
42
|
+
...baseContext,
|
|
43
|
+
threadId: request.threadId,
|
|
44
|
+
runId: request.runId,
|
|
45
|
+
agUi: {
|
|
46
|
+
context: request.context,
|
|
47
|
+
forwardedProps: request.forwardedProps,
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function closeController(controller) {
|
|
52
|
+
try {
|
|
53
|
+
controller.close();
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function enqueueEvent(controller, event, payload) {
|
|
60
|
+
try {
|
|
61
|
+
controller.enqueue(formatAgUiEvent(event, payload));
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async function createAgUiRuntimeStreamResponse(options) {
|
|
69
|
+
const { agentId, request, upstreamBody, upstreamStatus, upstreamStatusText, onFinish, onError, onToolCallSeen, } = options;
|
|
70
|
+
const stream = new ReadableStream({
|
|
71
|
+
start: async (controller) => {
|
|
72
|
+
const state = createStreamTransformState();
|
|
73
|
+
const prepareToolResultIfNeeded = (event, payload) => {
|
|
74
|
+
if (event !== "ToolCallStart" && event !== "ToolCallArgs" &&
|
|
75
|
+
event !== "ToolCallEnd") {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const toolCallId = typeof payload.toolCallId === "string" ? payload.toolCallId : null;
|
|
79
|
+
if (toolCallId) {
|
|
80
|
+
onToolCallSeen?.(toolCallId);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
if (!enqueueEvent(controller, "RunStarted", {
|
|
84
|
+
runId: request.runId,
|
|
85
|
+
threadId: request.threadId,
|
|
86
|
+
agentId,
|
|
87
|
+
})) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (!enqueueEvent(controller, "StateSnapshot", {
|
|
91
|
+
snapshot: isRecord(request.state) ? request.state : {},
|
|
92
|
+
})) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (!enqueueEvent(controller, "MessagesSnapshot", {
|
|
96
|
+
messages: normalizeAgUiRuntimeMessages(request.messages),
|
|
97
|
+
})) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
if (!upstreamBody) {
|
|
102
|
+
for (const event of finalizeRunEvents(state, null)) {
|
|
103
|
+
if (!enqueueEvent(controller, event.event, event.payload)) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
onFinish?.();
|
|
108
|
+
closeController(controller);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
for await (const event of streamDataStreamEvents(upstreamBody)) {
|
|
112
|
+
for (const mapped of mapRuntimeEventToAgUi(state, event)) {
|
|
113
|
+
prepareToolResultIfNeeded(mapped.event, mapped.payload);
|
|
114
|
+
if (!enqueueEvent(controller, mapped.event, mapped.payload)) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
for (const event of finalizeRunEvents(state, null)) {
|
|
120
|
+
if (!enqueueEvent(controller, event.event, event.payload)) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
onFinish?.();
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
onError?.(error);
|
|
128
|
+
enqueueEvent(controller, "RunError", {
|
|
129
|
+
message: error instanceof Error ? error.message : "Agent run failed",
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
closeController(controller);
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
return new Response(stream, {
|
|
138
|
+
status: upstreamStatus,
|
|
139
|
+
statusText: upstreamStatusText,
|
|
140
|
+
headers: { ...AG_UI_HEADERS },
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
async function createAgUiRuntimeDirectStreamResponse(agent, request, baseContext) {
|
|
144
|
+
await agent.clearMemory();
|
|
145
|
+
const result = await agent.stream({
|
|
146
|
+
messages: normalizeAgUiRuntimeMessages(request.messages),
|
|
147
|
+
context: buildStreamContext(request, baseContext),
|
|
148
|
+
});
|
|
149
|
+
const upstream = result.toDataStreamResponse();
|
|
150
|
+
return await createAgUiRuntimeStreamResponse({
|
|
151
|
+
agentId: agent.id,
|
|
152
|
+
request,
|
|
153
|
+
upstreamBody: upstream.body,
|
|
154
|
+
upstreamStatus: upstream.status,
|
|
155
|
+
upstreamStatusText: upstream.statusText,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
function createInjectedAgUiTool(runId, tool, sessionManager) {
|
|
159
|
+
return {
|
|
160
|
+
id: tool.name,
|
|
161
|
+
type: "function",
|
|
162
|
+
description: tool.description ?? tool.name,
|
|
163
|
+
inputSchema: z.record(z.string(), z.unknown()),
|
|
164
|
+
inputSchemaJson: (tool.parameters ??
|
|
165
|
+
{ type: "object", properties: {}, additionalProperties: true }),
|
|
166
|
+
execute: async (_input, context) => {
|
|
167
|
+
const toolCallId = typeof context?.toolCallId === "string" ? context.toolCallId : null;
|
|
168
|
+
if (!toolCallId) {
|
|
169
|
+
throw new Error(`Missing toolCallId for injected tool "${tool.name}"`);
|
|
170
|
+
}
|
|
171
|
+
sessionManager.prepareForSignal(runId, toolCallId);
|
|
172
|
+
const submitted = await sessionManager.waitForSignal(runId, toolCallId);
|
|
173
|
+
if (submitted.isError) {
|
|
174
|
+
throw new Error(typeof submitted.result === "string"
|
|
175
|
+
? submitted.result
|
|
176
|
+
: JSON.stringify(submitted.result));
|
|
177
|
+
}
|
|
178
|
+
return submitted.result;
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
function buildMergedTools(agent, request, sessionManager) {
|
|
183
|
+
const injectedTools = Object.fromEntries(request.tools.map((tool) => [
|
|
184
|
+
tool.name,
|
|
185
|
+
createInjectedAgUiTool(request.runId, tool, sessionManager),
|
|
186
|
+
]));
|
|
187
|
+
if (!agent.config.tools) {
|
|
188
|
+
return Object.keys(injectedTools).length > 0 ? injectedTools : undefined;
|
|
189
|
+
}
|
|
190
|
+
if (agent.config.tools === true) {
|
|
191
|
+
const merged = {};
|
|
192
|
+
for (const [toolId] of toolRegistry.getAll()) {
|
|
193
|
+
if (!agent.config.skills && SKILL_TOOL_IDS.has(toolId)) {
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
merged[toolId] = true;
|
|
197
|
+
}
|
|
198
|
+
return { ...merged, ...injectedTools };
|
|
199
|
+
}
|
|
200
|
+
return { ...agent.config.tools, ...injectedTools };
|
|
201
|
+
}
|
|
202
|
+
async function createAgUiRuntimeInjectedToolsStreamResponse(agent, request, baseContext, sessionManager) {
|
|
203
|
+
try {
|
|
204
|
+
sessionManager.startRun({ runId: request.runId, threadId: request.threadId });
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
if (error instanceof RunAlreadyExistsError) {
|
|
208
|
+
return Response.json({ error: "Run already active" }, { status: 409 });
|
|
209
|
+
}
|
|
210
|
+
throw error;
|
|
211
|
+
}
|
|
212
|
+
const runtime = new AgentRuntime(agent.id, {
|
|
213
|
+
...agent.config,
|
|
214
|
+
tools: buildMergedTools(agent, request, sessionManager),
|
|
215
|
+
});
|
|
216
|
+
let upstreamBody;
|
|
217
|
+
try {
|
|
218
|
+
upstreamBody = await runtime.stream(normalizeAgUiRuntimeMessages(request.messages), buildStreamContext(request, baseContext), undefined, undefined, undefined);
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
sessionManager.failRun(request.runId);
|
|
222
|
+
throw error;
|
|
223
|
+
}
|
|
224
|
+
return await createAgUiRuntimeStreamResponse({
|
|
225
|
+
agentId: agent.id,
|
|
226
|
+
request,
|
|
227
|
+
upstreamBody,
|
|
228
|
+
upstreamStatus: 200,
|
|
229
|
+
onFinish: () => {
|
|
230
|
+
sessionManager.completeRun(request.runId);
|
|
231
|
+
},
|
|
232
|
+
onError: () => {
|
|
233
|
+
sessionManager.failRun(request.runId);
|
|
234
|
+
},
|
|
235
|
+
onToolCallSeen: (toolCallId) => {
|
|
236
|
+
sessionManager.prepareForSignal(request.runId, toolCallId);
|
|
237
|
+
},
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
export function createAgUiRuntimeHandler(config) {
|
|
241
|
+
if (!config.agent && !config.execute) {
|
|
242
|
+
throw new Error("createAgUiRuntimeHandler requires either an agent or an execute handler.");
|
|
243
|
+
}
|
|
244
|
+
return async function POST(requestOrCtx) {
|
|
245
|
+
const request = extractRequest(requestOrCtx);
|
|
246
|
+
try {
|
|
247
|
+
const parsed = await parseAgUiRuntimeRequestOrError(request);
|
|
248
|
+
if (parsed instanceof Response) {
|
|
249
|
+
return parsed;
|
|
250
|
+
}
|
|
251
|
+
const context = typeof config.context === "function"
|
|
252
|
+
? await config.context(request)
|
|
253
|
+
: config.context ?? {};
|
|
254
|
+
const createDefaultResponse = config.agent
|
|
255
|
+
? () => parsed.tools.length > 0
|
|
256
|
+
? config.sessionManager
|
|
257
|
+
? createAgUiRuntimeInjectedToolsStreamResponse(config.agent, parsed, context, config.sessionManager)
|
|
258
|
+
: Promise.resolve(Response.json({
|
|
259
|
+
error: "Injected AG-UI tools require a public RunResumeSessionManager on createAgUiRuntimeHandler().",
|
|
260
|
+
}, { status: 501 }))
|
|
261
|
+
: createAgUiRuntimeDirectStreamResponse(config.agent, parsed, context)
|
|
262
|
+
: undefined;
|
|
263
|
+
if (config.execute) {
|
|
264
|
+
return await config.execute({
|
|
265
|
+
request,
|
|
266
|
+
agUiInput: parsed,
|
|
267
|
+
context,
|
|
268
|
+
createDefaultResponse,
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
if (createDefaultResponse) {
|
|
272
|
+
return await createDefaultResponse();
|
|
273
|
+
}
|
|
274
|
+
throw new Error("createAgUiRuntimeHandler configuration became invalid during execution.");
|
|
275
|
+
}
|
|
276
|
+
catch (error) {
|
|
277
|
+
if (error instanceof z.ZodError) {
|
|
278
|
+
return Response.json({
|
|
279
|
+
error: "Invalid AG-UI runtime request",
|
|
280
|
+
details: error.issues.map((issue) => ({
|
|
281
|
+
path: issue.path,
|
|
282
|
+
message: issue.message,
|
|
283
|
+
})),
|
|
284
|
+
}, { status: 400 });
|
|
285
|
+
}
|
|
286
|
+
return Response.json({
|
|
287
|
+
error: error instanceof Error ? error.message : "Internal server error",
|
|
288
|
+
}, { status: 500 });
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Message } from "./types.js";
|
|
2
|
+
import type { AgUiRuntimeRequest } from "./runtime-ag-ui-contract.js";
|
|
3
|
+
export declare function normalizeAgUiRuntimeMessages(messages: AgUiRuntimeRequest["messages"]): Message[];
|
|
4
|
+
//# sourceMappingURL=ag-ui-runtime-support.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ag-ui-runtime-support.d.ts","sourceRoot":"","sources":["../../../src/src/agent/ag-ui-runtime-support.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAetE,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,kBAAkB,CAAC,UAAU,CAAC,GACvC,OAAO,EAAE,CA6CX"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
function isRecord(value) {
|
|
2
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3
|
+
}
|
|
4
|
+
function parseToolArguments(serializedArguments) {
|
|
5
|
+
try {
|
|
6
|
+
const parsed = JSON.parse(serializedArguments);
|
|
7
|
+
return isRecord(parsed) ? parsed : {};
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return {};
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export function normalizeAgUiRuntimeMessages(messages) {
|
|
14
|
+
return messages.map((message) => {
|
|
15
|
+
const parts = [];
|
|
16
|
+
switch (message.role) {
|
|
17
|
+
case "system":
|
|
18
|
+
case "user":
|
|
19
|
+
parts.push({ type: "text", text: message.content });
|
|
20
|
+
break;
|
|
21
|
+
case "assistant":
|
|
22
|
+
if (typeof message.content === "string" && message.content.length > 0) {
|
|
23
|
+
parts.push({ type: "text", text: message.content });
|
|
24
|
+
}
|
|
25
|
+
for (const toolCall of message.toolCalls ?? []) {
|
|
26
|
+
parts.push({
|
|
27
|
+
type: "tool-call",
|
|
28
|
+
toolCallId: toolCall.id,
|
|
29
|
+
toolName: toolCall.function.name,
|
|
30
|
+
args: parseToolArguments(toolCall.function.arguments),
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
break;
|
|
34
|
+
case "tool":
|
|
35
|
+
parts.push({
|
|
36
|
+
type: "tool-result",
|
|
37
|
+
toolCallId: message.toolCallId,
|
|
38
|
+
toolName: "unknown",
|
|
39
|
+
result: message.error
|
|
40
|
+
? {
|
|
41
|
+
content: message.content,
|
|
42
|
+
error: message.error,
|
|
43
|
+
}
|
|
44
|
+
: message.content,
|
|
45
|
+
});
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
id: message.id,
|
|
50
|
+
role: message.role,
|
|
51
|
+
parts,
|
|
52
|
+
...(message.createdAt ? { timestamp: Date.parse(message.createdAt) || undefined } : {}),
|
|
53
|
+
...(message.metadata ? { metadata: message.metadata } : {}),
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
}
|
package/esm/src/agent/index.d.ts
CHANGED
|
@@ -84,7 +84,9 @@ 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
|
|
87
|
+
export { type AgUiRuntimeHandlerConfig, type AgUiRuntimeHandlerConfigWithAgent, type AgUiRuntimeHandlerExecute, type AgUiRuntimeHandlerExecuteInput, type AgUiRuntimeHandlerOptions, createAgUiRuntimeHandler, } from "./ag-ui-runtime-handler.js";
|
|
88
|
+
export { type AgUiRuntimeContextItem, AgUiRuntimeContextItemSchema, type AgUiRuntimeInjectedTool, AgUiRuntimeInjectedToolSchema, type AgUiRuntimeMessage, AgUiRuntimeMessageSchema, type AgUiRuntimeRequest, AgUiRuntimeRequestSchema, parseAgUiRuntimeRequest, parseAgUiRuntimeRequestOrError, } from "./runtime-ag-ui-contract.js";
|
|
89
|
+
export { normalizeAgUiRuntimeMessages } from "./ag-ui-runtime-support.js";
|
|
88
90
|
export { type AgUiBrowserEncodedEvent, type AgUiBrowserEncoderState, type AgUiBrowserRunFinishedMetadata, type AgUiRuntimeStreamEvent, createAgUiBrowserEncoderState, finalizeAgUiBrowserEvents, mapRuntimeStreamEventToAgUiBrowserEvents, } from "./ag-ui-browser-encoder.js";
|
|
89
91
|
export { mergeToolCallInput, mergeToolInputDelta, parseDataStreamSseEvents, parseToolInputObject, streamDataStreamEvents, stripLeadingEmptyObjectPlaceholder, } from "./data-stream.js";
|
|
90
92
|
export { expandAllowedRemoteToolNames, getProviderNativeToolNames, type ProviderNativeToolInventoryOptions, } from "./provider-native-tool-inventory.js";
|
|
@@ -1 +1 @@
|
|
|
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,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,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,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/agent/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+EG;AACH,OAAO,yBAAy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,EACtB,KAAK,sBAAsB,EAC3B,uBAAuB,EACvB,KAAK,gBAAgB,EACrB,sBAAsB,EACtB,qBAAqB,EACrB,4BAA4B,EAC5B,iBAAiB,EACjB,KAAK,wBAAwB,GAC9B,MAAM,kBAAkB,CAAC;AAC1B,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"}
|
package/esm/src/agent/index.js
CHANGED
|
@@ -83,7 +83,9 @@ 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 {
|
|
86
|
+
export { createAgUiRuntimeHandler, } from "./ag-ui-runtime-handler.js";
|
|
87
|
+
export { AgUiRuntimeContextItemSchema, AgUiRuntimeInjectedToolSchema, AgUiRuntimeMessageSchema, AgUiRuntimeRequestSchema, parseAgUiRuntimeRequest, parseAgUiRuntimeRequestOrError, } from "./runtime-ag-ui-contract.js";
|
|
88
|
+
export { normalizeAgUiRuntimeMessages } from "./ag-ui-runtime-support.js";
|
|
87
89
|
export { createAgUiBrowserEncoderState, finalizeAgUiBrowserEvents, mapRuntimeStreamEventToAgUiBrowserEvents, } from "./ag-ui-browser-encoder.js";
|
|
88
90
|
export { mergeToolCallInput, mergeToolInputDelta, parseDataStreamSseEvents, parseToolInputObject, streamDataStreamEvents, stripLeadingEmptyObjectPlaceholder, } from "./data-stream.js";
|
|
89
91
|
export { expandAllowedRemoteToolNames, getProviderNativeToolNames, } from "./provider-native-tool-inventory.js";
|
|
@@ -204,4 +204,6 @@ export type AgUiRuntimeInjectedTool = z.infer<typeof AgUiRuntimeInjectedToolSche
|
|
|
204
204
|
export type AgUiRuntimeContextItem = z.infer<typeof AgUiRuntimeContextItemSchema>;
|
|
205
205
|
export type AgUiRuntimeMessage = z.infer<typeof AgUiRuntimeMessageSchema>;
|
|
206
206
|
export type AgUiRuntimeRequest = z.infer<typeof AgUiRuntimeRequestSchema>;
|
|
207
|
+
export declare function parseAgUiRuntimeRequest(request: Request): Promise<AgUiRuntimeRequest>;
|
|
208
|
+
export declare function parseAgUiRuntimeRequestOrError(request: Request): Promise<AgUiRuntimeRequest | Response>;
|
|
207
209
|
//# sourceMappingURL=runtime-ag-ui-contract.d.ts.map
|
|
@@ -1 +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;;;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,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;AAE1E,wBAAsB,uBAAuB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAE3F;AAED,wBAAsB,8BAA8B,CAClD,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,kBAAkB,GAAG,QAAQ,CAAC,CA6BxC"}
|
|
@@ -107,3 +107,29 @@ export const AgUiRuntimeRequestSchema = z.object({
|
|
|
107
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
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
109
|
});
|
|
110
|
+
export async function parseAgUiRuntimeRequest(request) {
|
|
111
|
+
return AgUiRuntimeRequestSchema.parse(await request.json());
|
|
112
|
+
}
|
|
113
|
+
export async function parseAgUiRuntimeRequestOrError(request) {
|
|
114
|
+
try {
|
|
115
|
+
return await parseAgUiRuntimeRequest(request);
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
if (error instanceof z.ZodError) {
|
|
119
|
+
return Response.json({
|
|
120
|
+
error: "Invalid AG-UI runtime request",
|
|
121
|
+
details: error.issues.map((issue) => ({
|
|
122
|
+
path: issue.path,
|
|
123
|
+
message: issue.message,
|
|
124
|
+
})),
|
|
125
|
+
}, { status: 400 });
|
|
126
|
+
}
|
|
127
|
+
if (error instanceof SyntaxError || error instanceof TypeError) {
|
|
128
|
+
return Response.json({
|
|
129
|
+
error: "Invalid AG-UI runtime request",
|
|
130
|
+
details: [{ path: [], message: "Malformed JSON request body" }],
|
|
131
|
+
}, { status: 400 });
|
|
132
|
+
}
|
|
133
|
+
throw error;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-stream.d.ts","sourceRoot":"","sources":["../../../src/src/internal-agents/run-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,KAAK,EACV,KAAK,YAAY,IAAI,OAAO,EAC5B,KAAK,aAAa,EAEnB,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"run-stream.d.ts","sourceRoot":"","sources":["../../../src/src/internal-agents/run-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,KAAK,EACV,KAAK,YAAY,IAAI,OAAO,EAC5B,KAAK,aAAa,EAEnB,MAAM,mBAAmB,CAAC;AAY3B,OAAO,EAA0B,KAAK,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC3F,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAYxD,MAAM,WAAW,+BAA+B;IAC9C,cAAc,EAAE,sBAAsB,CAAC;IACvC,aAAa,CAAC,EAAE,CACd,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,KAClC;QACH,MAAM,EAAE,CACN,QAAQ,EAAE,OAAO,EAAE,EACnB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,SAAS,CAAC,EAAE;YACV,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,aAAa,KAAK,IAAI,CAAC;SAC9C,EACD,aAAa,CAAC,EAAE,MAAM,EACtB,uBAAuB,CAAC,EAAE,MAAM,EAChC,WAAW,CAAC,EAAE,WAAW,KACtB,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC;KAC1C,CAAC;CACH;AA4FD,wBAAsB,gCAAgC,CACpD,KAAK,EAAE,oBAAoB,EAC3B,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,+BAA+B,GACpC,OAAO,CAAC,QAAQ,CAAC,CA8OnB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AgentRuntime, } from "../agent/index.js";
|
|
2
|
+
import { normalizeAgUiRuntimeMessages } from "../agent/ag-ui-runtime-support.js";
|
|
2
3
|
import { SKILL_TOOL_IDS } from "../skill/types.js";
|
|
3
4
|
import { toolRegistry } from "../tool/index.js";
|
|
4
5
|
import { z } from "zod";
|
|
@@ -54,59 +55,6 @@ function buildMergedTools(agent, input, sessionManager) {
|
|
|
54
55
|
function isRecord(value) {
|
|
55
56
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
56
57
|
}
|
|
57
|
-
function parseToolArguments(serializedArguments) {
|
|
58
|
-
try {
|
|
59
|
-
const parsed = JSON.parse(serializedArguments);
|
|
60
|
-
return isRecord(parsed) ? parsed : {};
|
|
61
|
-
}
|
|
62
|
-
catch {
|
|
63
|
-
return {};
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
function normalizeRuntimeMessages(messages) {
|
|
67
|
-
return messages.map((message) => {
|
|
68
|
-
const parts = [];
|
|
69
|
-
switch (message.role) {
|
|
70
|
-
case "system":
|
|
71
|
-
case "user":
|
|
72
|
-
parts.push({ type: "text", text: message.content });
|
|
73
|
-
break;
|
|
74
|
-
case "assistant":
|
|
75
|
-
if (typeof message.content === "string" && message.content.length > 0) {
|
|
76
|
-
parts.push({ type: "text", text: message.content });
|
|
77
|
-
}
|
|
78
|
-
for (const toolCall of message.toolCalls ?? []) {
|
|
79
|
-
parts.push({
|
|
80
|
-
type: "tool-call",
|
|
81
|
-
toolCallId: toolCall.id,
|
|
82
|
-
toolName: toolCall.function.name,
|
|
83
|
-
args: parseToolArguments(toolCall.function.arguments),
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
break;
|
|
87
|
-
case "tool":
|
|
88
|
-
parts.push({
|
|
89
|
-
type: "tool-result",
|
|
90
|
-
toolCallId: message.toolCallId,
|
|
91
|
-
toolName: "unknown",
|
|
92
|
-
result: message.error
|
|
93
|
-
? {
|
|
94
|
-
content: message.content,
|
|
95
|
-
error: message.error,
|
|
96
|
-
}
|
|
97
|
-
: message.content,
|
|
98
|
-
});
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
return {
|
|
102
|
-
id: message.id,
|
|
103
|
-
role: message.role,
|
|
104
|
-
parts,
|
|
105
|
-
...(message.createdAt ? { timestamp: Date.parse(message.createdAt) || undefined } : {}),
|
|
106
|
-
...(message.metadata ? { metadata: message.metadata } : {}),
|
|
107
|
-
};
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
58
|
function getAllowedRemoteToolNames(forwardedProps) {
|
|
111
59
|
const runtimeOverrides = isRecord(forwardedProps?.runtimeOverrides)
|
|
112
60
|
? forwardedProps.runtimeOverrides
|
|
@@ -148,7 +96,7 @@ export async function createRuntimeAgentStreamResponse(input, agent, deps) {
|
|
|
148
96
|
const runtime = deps.createRuntime?.(runtimeAgent, mergedTools) ??
|
|
149
97
|
new AgentRuntime(runtimeAgent.id, runtimeAgent.config);
|
|
150
98
|
let completedResponse = null;
|
|
151
|
-
const runtimeMessages =
|
|
99
|
+
const runtimeMessages = normalizeAgUiRuntimeMessages(input.messages);
|
|
152
100
|
let runtimeStream;
|
|
153
101
|
let clientAttached = true;
|
|
154
102
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"media-types.d.ts","sourceRoot":"","sources":["../../../../src/src/platform/compat/media-types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"media-types.d.ts","sourceRoot":"","sources":["../../../../src/src/platform/compat/media-types.ts"],"names":[],"mappings":"AAMA,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAQ5D;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAE1D;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEvD;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAExD"}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { charset as mimeCharset, extension as mimeExtension, lookup as mimeLookup, } from "../../utils/mime-types.js";
|
|
2
2
|
export function contentType(path) {
|
|
3
|
-
const type =
|
|
3
|
+
const type = mimeLookup(path);
|
|
4
4
|
if (!type)
|
|
5
5
|
return undefined;
|
|
6
|
-
const cs =
|
|
6
|
+
const cs = mimeCharset(type);
|
|
7
7
|
if (!cs)
|
|
8
8
|
return type;
|
|
9
9
|
return `${type}; charset=${cs}`;
|
|
10
10
|
}
|
|
11
11
|
export function extension(type) {
|
|
12
|
-
return
|
|
12
|
+
return mimeExtension(type) || undefined;
|
|
13
13
|
}
|
|
14
14
|
export function lookup(path) {
|
|
15
|
-
return
|
|
15
|
+
return mimeLookup(path) || undefined;
|
|
16
16
|
}
|
|
17
17
|
export function charset(type) {
|
|
18
|
-
return
|
|
18
|
+
return mimeCharset(type) || undefined;
|
|
19
19
|
}
|