veryfront 0.1.800 → 0.1.801
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 +1 -1
- package/esm/src/agent/ag-ui/host-support.d.ts.map +1 -1
- package/esm/src/agent/ag-ui/host-support.js +16 -7
- package/esm/src/agent/ag-ui/runtime-support.d.ts.map +1 -1
- package/esm/src/agent/ag-ui/runtime-support.js +4 -1
- package/esm/src/channels/invoke.d.ts.map +1 -1
- package/esm/src/channels/invoke.js +26 -11
- package/esm/src/utils/version-constant.d.ts +1 -1
- package/esm/src/utils/version-constant.js +1 -1
- package/package.json +1 -1
package/esm/deno.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host-support.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/ag-ui/host-support.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAEpE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAa3C,mCAAmC;AACnC,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAgBD,eAAO,MAAM,yBAAyB;;;;GASrC,CAAC;AAEF,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;GAuBpC,CAAC;AAuBF,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiBhC,CAAC;AAEF,kDAAkD;AAClD,eAAO,MAAM,sBAAsB;;;;GAAwC,CAAC;AAC5E,iDAAiD;AACjD,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;GAAuC,CAAC;AAC1E;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAAmC,CAAC;AAElE,mDAAmD;AACnD,MAAM,MAAM,gBAAg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AAM,eAAe,GAAG,WAAW,CAAC,UAAU,CAAC,OAAO,wBAAwB,CAAC,CAAC,CAAC;AACvF,iCAAiC;AACjC,MAAM,MAAM,WAAW,GAAG,WAAW,CAAC,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC,CAAC;AAE/E,MAAM,WAAW,4BAA4B;IAC3C,sBAAsB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC5C;AA8ND,uCAAuC;AACvC,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC,CAE7E;AAED,8CAA8C;AAC9C,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,WAAW,GAAG,QAAQ,CAAC,CAKjC;AAED,iCAAiC;AACjC,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,WAAW,CAAC,UAAU,CAAC,EACjC,OAAO,GAAE,4BAAiC,GACzC,OAAO,EAAE,CAsCX;AAED,gDAAgD;AAChD,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,YAAY,CAQpF;AAED,mDAAmD;AACnD,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,GAAG,QAAQ,CAUxF;AAED,6CAA6C;AAC7C,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,QAAQ,CASlF"}
|
|
@@ -126,7 +126,7 @@ function shouldKeepProviderVisibleToolPart(part, providerOwnedToolNames, provide
|
|
|
126
126
|
}
|
|
127
127
|
return false;
|
|
128
128
|
}
|
|
129
|
-
function normalizeMessagePart(part) {
|
|
129
|
+
function normalizeMessagePart(part, toolNamesById = new Map()) {
|
|
130
130
|
if (part.type === "text" && typeof part.text === "string" &&
|
|
131
131
|
part.text.length <= MAX_TEXT_PART_LENGTH) {
|
|
132
132
|
return { type: "text", text: part.text };
|
|
@@ -165,7 +165,9 @@ function normalizeMessagePart(part) {
|
|
|
165
165
|
return {
|
|
166
166
|
type: "tool-result",
|
|
167
167
|
toolCallId: part.tool_call_id,
|
|
168
|
-
toolName: typeof part.tool_name === "string"
|
|
168
|
+
toolName: typeof part.tool_name === "string"
|
|
169
|
+
? part.tool_name
|
|
170
|
+
: toolNamesById.get(part.tool_call_id) ?? "unknown",
|
|
169
171
|
result: "output" in part ? part.output : undefined,
|
|
170
172
|
};
|
|
171
173
|
}
|
|
@@ -173,7 +175,9 @@ function normalizeMessagePart(part) {
|
|
|
173
175
|
return {
|
|
174
176
|
type: "tool-result",
|
|
175
177
|
toolCallId: part.toolCallId,
|
|
176
|
-
toolName: typeof part.toolName === "string"
|
|
178
|
+
toolName: typeof part.toolName === "string"
|
|
179
|
+
? part.toolName
|
|
180
|
+
: toolNamesById.get(part.toolCallId) ?? "unknown",
|
|
177
181
|
result: "result" in part ? part.result : undefined,
|
|
178
182
|
};
|
|
179
183
|
}
|
|
@@ -185,7 +189,7 @@ function buildMessageMetadataFields(message) {
|
|
|
185
189
|
...(message.metadata ? { metadata: message.metadata } : {}),
|
|
186
190
|
};
|
|
187
191
|
}
|
|
188
|
-
function normalizeAssistantMessage(message, providerOwnedToolNames, providerOwnedToolCallIds) {
|
|
192
|
+
function normalizeAssistantMessage(message, providerOwnedToolNames, providerOwnedToolCallIds, toolNamesById) {
|
|
189
193
|
const messages = [];
|
|
190
194
|
const metadataFields = buildMessageMetadataFields(message);
|
|
191
195
|
let segmentParts = [];
|
|
@@ -203,9 +207,12 @@ function normalizeAssistantMessage(message, providerOwnedToolNames, providerOwne
|
|
|
203
207
|
segmentIndex += 1;
|
|
204
208
|
};
|
|
205
209
|
for (const part of message.parts) {
|
|
206
|
-
const normalizedPart = normalizeMessagePart(part);
|
|
210
|
+
const normalizedPart = normalizeMessagePart(part, toolNamesById);
|
|
207
211
|
if (!normalizedPart)
|
|
208
212
|
continue;
|
|
213
|
+
if (normalizedPart.type !== "tool-result" && "toolCallId" in normalizedPart) {
|
|
214
|
+
toolNamesById.set(normalizedPart.toolCallId, normalizedPart.toolName);
|
|
215
|
+
}
|
|
209
216
|
if (!shouldKeepProviderVisibleToolPart(normalizedPart, providerOwnedToolNames, providerOwnedToolCallIds)) {
|
|
210
217
|
continue;
|
|
211
218
|
}
|
|
@@ -241,18 +248,20 @@ export async function parseAgUiRequestOrError(request) {
|
|
|
241
248
|
export function normalizeAgUiMessages(messages, options = {}) {
|
|
242
249
|
const providerOwnedToolNames = new Set(options.providerOwnedToolNames ?? []);
|
|
243
250
|
const providerOwnedToolCallIds = new Set();
|
|
251
|
+
const toolNamesById = new Map();
|
|
244
252
|
return messages.flatMap((message) => {
|
|
245
253
|
if (message.role === "user" || message.role === "system") {
|
|
246
254
|
providerOwnedToolCallIds.clear();
|
|
255
|
+
toolNamesById.clear();
|
|
247
256
|
}
|
|
248
257
|
if (message.role === "assistant") {
|
|
249
|
-
return normalizeAssistantMessage(message, providerOwnedToolNames, providerOwnedToolCallIds);
|
|
258
|
+
return normalizeAssistantMessage(message, providerOwnedToolNames, providerOwnedToolCallIds, toolNamesById);
|
|
250
259
|
}
|
|
251
260
|
const normalizedMessage = {
|
|
252
261
|
id: message.id,
|
|
253
262
|
role: message.role,
|
|
254
263
|
parts: message.parts
|
|
255
|
-
.map((part) => normalizeMessagePart(part))
|
|
264
|
+
.map((part) => normalizeMessagePart(part, toolNamesById))
|
|
256
265
|
.filter((part) => part !== null)
|
|
257
266
|
.filter((part) => shouldKeepProviderVisibleToolPart(part, providerOwnedToolNames, providerOwnedToolCallIds)),
|
|
258
267
|
...buildMessageMetadataFields(message),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-support.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/ag-ui/runtime-support.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAevE,yCAAyC;AACzC,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,kBAAkB,CAAC,UAAU,CAAC,GACvC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"runtime-support.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/ag-ui/runtime-support.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAevE,yCAAyC;AACzC,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,kBAAkB,CAAC,UAAU,CAAC,GACvC,OAAO,EAAE,CAiDX"}
|
|
@@ -12,11 +12,13 @@ function parseToolArguments(serializedArguments) {
|
|
|
12
12
|
}
|
|
13
13
|
/** Normalizes AG-UI runtime messages. */
|
|
14
14
|
export function normalizeAgUiRuntimeMessages(messages) {
|
|
15
|
+
const toolNamesById = new Map();
|
|
15
16
|
return messages.map((message) => {
|
|
16
17
|
const parts = [];
|
|
17
18
|
switch (message.role) {
|
|
18
19
|
case "system":
|
|
19
20
|
case "user":
|
|
21
|
+
toolNamesById.clear();
|
|
20
22
|
parts.push({ type: "text", text: message.content });
|
|
21
23
|
break;
|
|
22
24
|
case "assistant":
|
|
@@ -30,13 +32,14 @@ export function normalizeAgUiRuntimeMessages(messages) {
|
|
|
30
32
|
toolName: toolCall.function.name,
|
|
31
33
|
args: parseToolArguments(toolCall.function.arguments),
|
|
32
34
|
});
|
|
35
|
+
toolNamesById.set(toolCall.id, toolCall.function.name);
|
|
33
36
|
}
|
|
34
37
|
break;
|
|
35
38
|
case "tool":
|
|
36
39
|
parts.push({
|
|
37
40
|
type: "tool-result",
|
|
38
41
|
toolCallId: message.toolCallId,
|
|
39
|
-
toolName: "unknown",
|
|
42
|
+
toolName: toolNamesById.get(message.toolCallId) ?? "unknown",
|
|
40
43
|
result: message.error
|
|
41
44
|
? {
|
|
42
45
|
content: message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CAAC,CACrD,CAAC;AACF,+CAA+C;AAC/C,MAAM,MAAM,yBAAyB,GAAG,WAAW,CACjD,UAAU,CAAC,OAAO,kCAAkC,CAAC,CACtD,CAAC;AAEF,qDAAqD;AACrD,KAAK,mBAAmB,GAAG,WAAW,CAAC,UAAU,CAAC,OAAO,4BAA4B,CAAC,CAAC,CAAC;AACxF,mDAAmD;AACnD,MAAM,WAAW,iBAAkB,SAAQ,yBAAyB;CAAG;AAEvE,gDAAgD;AAChD,eAAO,MAAM,wBAAwB,EAAE,iBAItC,CAAC;AAEF,+BAA+B;AAC/B,wBAAsB,qBAAqB,CACzC,GAAG,EAAE,cAAc,EACnB,IAAI,EAAE,iBAAiB,GACtB,OAAO,CAAC,yBAAyB,CAAC,CAYpC;AACD,OAAO,EAAE,iBAAiB,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAwCnF,mDAAmD;AACnD,wBAAgB,sCAAsC,CACpD,QAAQ,EAAE,oBAAoB,CAAC,qBAAqB,CAAC,GACpD,OAAO,EAAE,CA4BX;AAED,qCAAqC;AACrC,wBAAgB,yBAAyB,CACvC,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,IAAI,CAAC,iBAAiB,EAAE,UAAU,CAAC,GACxC,KAAK,GAAG,SAAS,CAEnB;AAsDD,qCAAqC;AACrC,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,aAAa,GAAG,mBAAmB,EAAE,CAiDxF;AAgBD,8BAA8B;AAC9B,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,oBAAoB,EAC7B,GAAG,EAAE,cAAc,EACnB,IAAI,EAAE,iBAAiB,GACtB,OAAO,CAAC,qBAAqB,CAAC,CAkEhC"}
|
|
@@ -144,7 +144,7 @@ export async function listChannelAssistants(ctx, deps) {
|
|
|
144
144
|
return ChannelAssistantsResponseSchema.parse({ assistants });
|
|
145
145
|
}
|
|
146
146
|
export { verifyDispatchJws, verifyDispatchJwsSignature } from "./control-plane.js";
|
|
147
|
-
function normalizeConversationPart(part) {
|
|
147
|
+
function normalizeConversationPart(part, toolNamesById = new Map()) {
|
|
148
148
|
if (part.type === "text" && typeof part.text === "string") {
|
|
149
149
|
return { type: "text", text: part.text };
|
|
150
150
|
}
|
|
@@ -165,7 +165,9 @@ function normalizeConversationPart(part) {
|
|
|
165
165
|
return {
|
|
166
166
|
type: "tool-result",
|
|
167
167
|
toolCallId: part.tool_call_id,
|
|
168
|
-
toolName: typeof part.tool_name === "string"
|
|
168
|
+
toolName: typeof part.tool_name === "string"
|
|
169
|
+
? part.tool_name
|
|
170
|
+
: toolNamesById.get(part.tool_call_id) ?? "unknown",
|
|
169
171
|
result: "output" in part ? part.output : undefined,
|
|
170
172
|
};
|
|
171
173
|
}
|
|
@@ -173,15 +175,28 @@ function normalizeConversationPart(part) {
|
|
|
173
175
|
}
|
|
174
176
|
/** Normalizes conversation history for runtime. */
|
|
175
177
|
export function normalizeConversationHistoryForRuntime(messages) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
role
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
178
|
+
const toolNamesById = new Map();
|
|
179
|
+
return messages.map((message) => {
|
|
180
|
+
if (message.role === "user" || message.role === "system") {
|
|
181
|
+
toolNamesById.clear();
|
|
182
|
+
}
|
|
183
|
+
const parts = message.parts
|
|
184
|
+
.map((part) => {
|
|
185
|
+
const normalizedPart = normalizeConversationPart(part, toolNamesById);
|
|
186
|
+
if (normalizedPart?.type !== "tool-result" && normalizedPart && "toolCallId" in normalizedPart) {
|
|
187
|
+
toolNamesById.set(normalizedPart.toolCallId, normalizedPart.toolName);
|
|
188
|
+
}
|
|
189
|
+
return normalizedPart;
|
|
190
|
+
})
|
|
191
|
+
.filter((part) => part !== null);
|
|
192
|
+
return {
|
|
193
|
+
id: message.id,
|
|
194
|
+
role: message.role,
|
|
195
|
+
parts,
|
|
196
|
+
...(message.createdAt ? { timestamp: Date.parse(message.createdAt) || undefined } : {}),
|
|
197
|
+
...(message.metadata ? { metadata: message.metadata } : {}),
|
|
198
|
+
};
|
|
199
|
+
});
|
|
185
200
|
}
|
|
186
201
|
/** Resolves channel invoke agent. */
|
|
187
202
|
export function resolveChannelInvokeAgent(assistantId, deps) {
|