veryfront 0.1.261 → 0.1.262
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/cli/commands/knowledge/command.d.ts.map +1 -1
- package/esm/cli/commands/knowledge/command.js +19 -26
- package/esm/deno.js +1 -1
- package/esm/src/agent/ag-ui-detached-start.d.ts +1 -4
- package/esm/src/agent/ag-ui-detached-start.d.ts.map +1 -1
- package/esm/src/agent/ag-ui-detached-start.js +4 -67
- package/esm/src/agent/ag-ui-handler.d.ts +1 -4
- package/esm/src/agent/ag-ui-handler.d.ts.map +1 -1
- package/esm/src/agent/ag-ui-handler.js +3 -61
- package/esm/src/agent/ag-ui-host-support.d.ts.map +1 -1
- package/esm/src/agent/ag-ui-host-support.js +2 -21
- package/esm/src/agent/ag-ui-request-shared.d.ts +4 -0
- package/esm/src/agent/ag-ui-request-shared.d.ts.map +1 -0
- package/esm/src/agent/ag-ui-request-shared.js +47 -0
- package/esm/src/agent/ag-ui-run-control.d.ts.map +1 -1
- package/esm/src/agent/ag-ui-run-control.js +1 -23
- package/esm/src/agent/ag-ui-runtime-handler.d.ts +1 -5
- package/esm/src/agent/ag-ui-runtime-handler.d.ts.map +1 -1
- package/esm/src/agent/ag-ui-runtime-handler.js +3 -67
- package/esm/src/agent/ag-ui-tool-shared.d.ts +15 -0
- package/esm/src/agent/ag-ui-tool-shared.d.ts.map +1 -0
- package/esm/src/agent/ag-ui-tool-shared.js +47 -0
- package/esm/src/agent/index.d.ts +2 -0
- package/esm/src/agent/index.d.ts.map +1 -1
- package/esm/src/agent/index.js +1 -0
- package/esm/src/agent/runtime-ag-ui-contract.d.ts.map +1 -1
- package/esm/src/agent/runtime-ag-ui-contract.js +2 -21
- package/esm/src/chat/chat-ui-message-helpers.d.ts +18 -0
- package/esm/src/chat/chat-ui-message-helpers.d.ts.map +1 -0
- package/esm/src/chat/chat-ui-message-helpers.js +84 -0
- package/esm/src/chat/index.d.ts +2 -0
- package/esm/src/chat/index.d.ts.map +1 -1
- package/esm/src/chat/index.js +1 -0
- package/esm/src/chat/protocol.d.ts +109 -0
- package/esm/src/chat/protocol.d.ts.map +1 -1
- 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/src/cli/commands/knowledge/command.ts +27 -32
- package/src/deno.js +1 -1
- package/src/src/agent/ag-ui-detached-start.ts +4 -92
- package/src/src/agent/ag-ui-handler.ts +3 -81
- package/src/src/agent/ag-ui-host-support.ts +5 -28
- package/src/src/agent/ag-ui-request-shared.ts +62 -0
- package/src/src/agent/ag-ui-run-control.ts +1 -27
- package/src/src/agent/ag-ui-runtime-handler.ts +3 -86
- package/src/src/agent/ag-ui-tool-shared.ts +77 -0
- package/src/src/agent/index.ts +15 -0
- package/src/src/agent/runtime-ag-ui-contract.ts +5 -28
- package/src/src/chat/chat-ui-message-helpers.ts +114 -0
- package/src/src/chat/index.ts +17 -0
- package/src/src/chat/protocol.ts +148 -0
- package/src/src/utils/version-constant.ts +1 -1
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { ChatMessageMetadata, ChatUiMessageChunk } from "./protocol.js";
|
|
2
|
+
|
|
3
|
+
type StreamChunkMetadataPart = {
|
|
4
|
+
type: string;
|
|
5
|
+
totalUsage?: unknown;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export interface BuildChatStreamChunkMessageMetadataInput {
|
|
9
|
+
agentId: string;
|
|
10
|
+
modelId: string;
|
|
11
|
+
runId?: string;
|
|
12
|
+
streamingMessageId?: string;
|
|
13
|
+
part: StreamChunkMetadataPart;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
17
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function normalizeUsageMetadata(value: unknown): ChatMessageMetadata["usage"] | undefined {
|
|
21
|
+
if (!isRecord(value)) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const usage = {
|
|
26
|
+
...(typeof value.inputTokens === "number" ? { inputTokens: value.inputTokens } : {}),
|
|
27
|
+
...(typeof value.outputTokens === "number" ? { outputTokens: value.outputTokens } : {}),
|
|
28
|
+
...(typeof value.reasoningTokens === "number"
|
|
29
|
+
? { reasoningTokens: value.reasoningTokens }
|
|
30
|
+
: {}),
|
|
31
|
+
...(typeof value.cachedInputTokens === "number"
|
|
32
|
+
? { cachedInputTokens: value.cachedInputTokens }
|
|
33
|
+
: {}),
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
return Object.keys(usage).length > 0 ? usage : undefined;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function normalizeChatMessageMetadata(value: unknown): ChatMessageMetadata {
|
|
40
|
+
if (!isRecord(value)) {
|
|
41
|
+
return {};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const usage = normalizeUsageMetadata(value.usage);
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
...(typeof value.createdAt === "string" ? { createdAt: value.createdAt } : {}),
|
|
48
|
+
...(typeof value.isStopped === "boolean" ? { isStopped: value.isStopped } : {}),
|
|
49
|
+
...(typeof value.isCompleted === "boolean" ? { isCompleted: value.isCompleted } : {}),
|
|
50
|
+
...(typeof value.completedAt === "string" ? { completedAt: value.completedAt } : {}),
|
|
51
|
+
...(typeof value.agentId === "string" ? { agentId: value.agentId } : {}),
|
|
52
|
+
...(typeof value.agentName === "string" ? { agentName: value.agentName } : {}),
|
|
53
|
+
...(typeof value.conversationId === "string" ? { conversationId: value.conversationId } : {}),
|
|
54
|
+
...(typeof value.modelId === "string" ? { modelId: value.modelId } : {}),
|
|
55
|
+
...(typeof value.runId === "string" ? { runId: value.runId } : {}),
|
|
56
|
+
...(typeof value.streamingMessageId === "string"
|
|
57
|
+
? { streamingMessageId: value.streamingMessageId }
|
|
58
|
+
: {}),
|
|
59
|
+
...(usage ? { usage } : {}),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function extractChatMessageMetadata(value: unknown): ChatMessageMetadata | undefined {
|
|
64
|
+
const normalized = normalizeChatMessageMetadata(value);
|
|
65
|
+
return Object.keys(normalized).length > 0 ? normalized : undefined;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function buildChatStreamChunkMessageMetadata(
|
|
69
|
+
input: BuildChatStreamChunkMessageMetadataInput,
|
|
70
|
+
): ChatMessageMetadata {
|
|
71
|
+
const baseMetadata: ChatMessageMetadata = {
|
|
72
|
+
agentId: input.agentId,
|
|
73
|
+
modelId: input.modelId,
|
|
74
|
+
...(input.runId ? { runId: input.runId } : {}),
|
|
75
|
+
...(input.streamingMessageId ? { streamingMessageId: input.streamingMessageId } : {}),
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
if (input.part.type !== "finish" || !input.part.totalUsage) {
|
|
79
|
+
return baseMetadata;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const usage = normalizeUsageMetadata(input.part.totalUsage);
|
|
83
|
+
return usage ? { ...baseMetadata, usage } : baseMetadata;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function normalizeChatUiMessageChunk(
|
|
87
|
+
chunk: ChatUiMessageChunk<unknown>,
|
|
88
|
+
): ChatUiMessageChunk<ChatMessageMetadata> {
|
|
89
|
+
switch (chunk.type) {
|
|
90
|
+
case "start":
|
|
91
|
+
return {
|
|
92
|
+
type: "start",
|
|
93
|
+
...(chunk.messageId ? { messageId: chunk.messageId } : {}),
|
|
94
|
+
...(chunk.messageMetadata !== undefined
|
|
95
|
+
? { messageMetadata: normalizeChatMessageMetadata(chunk.messageMetadata) }
|
|
96
|
+
: {}),
|
|
97
|
+
};
|
|
98
|
+
case "message-metadata":
|
|
99
|
+
return {
|
|
100
|
+
type: "message-metadata",
|
|
101
|
+
messageMetadata: normalizeChatMessageMetadata(chunk.messageMetadata),
|
|
102
|
+
};
|
|
103
|
+
case "finish":
|
|
104
|
+
return {
|
|
105
|
+
type: "finish",
|
|
106
|
+
...(chunk.finishReason ? { finishReason: chunk.finishReason } : {}),
|
|
107
|
+
...(chunk.messageMetadata !== undefined
|
|
108
|
+
? { messageMetadata: normalizeChatMessageMetadata(chunk.messageMetadata) }
|
|
109
|
+
: {}),
|
|
110
|
+
};
|
|
111
|
+
default:
|
|
112
|
+
return chunk;
|
|
113
|
+
}
|
|
114
|
+
}
|
package/src/src/chat/index.ts
CHANGED
|
@@ -212,12 +212,29 @@ export {
|
|
|
212
212
|
type UseChatResult,
|
|
213
213
|
} from "../agent/react/use-chat/index.js";
|
|
214
214
|
|
|
215
|
+
export type {
|
|
216
|
+
ChatMessageMetadata,
|
|
217
|
+
ChatMessageMetadataUsage,
|
|
218
|
+
ChatUiMessageChunk,
|
|
219
|
+
ChildRunAudit,
|
|
220
|
+
ChildRunAuditToolCall,
|
|
221
|
+
ChildRunAuditToolResult,
|
|
222
|
+
} from "./protocol.js";
|
|
223
|
+
|
|
215
224
|
export {
|
|
216
225
|
useAgent,
|
|
217
226
|
type UseAgentOptions,
|
|
218
227
|
type UseAgentResult,
|
|
219
228
|
} from "../agent/react/use-agent.js";
|
|
220
229
|
|
|
230
|
+
export {
|
|
231
|
+
buildChatStreamChunkMessageMetadata,
|
|
232
|
+
type BuildChatStreamChunkMessageMetadataInput,
|
|
233
|
+
extractChatMessageMetadata,
|
|
234
|
+
normalizeChatMessageMetadata,
|
|
235
|
+
normalizeChatUiMessageChunk,
|
|
236
|
+
} from "./chat-ui-message-helpers.js";
|
|
237
|
+
|
|
221
238
|
export {
|
|
222
239
|
useCompletion,
|
|
223
240
|
type UseCompletionOptions,
|
package/src/src/chat/protocol.ts
CHANGED
|
@@ -77,6 +77,52 @@ export interface ChatMessage {
|
|
|
77
77
|
createdAt?: Date | string;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
export interface ChatMessageMetadataUsage {
|
|
81
|
+
inputTokens?: number;
|
|
82
|
+
outputTokens?: number;
|
|
83
|
+
reasoningTokens?: number;
|
|
84
|
+
cachedInputTokens?: number;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface ChildRunAuditToolCall {
|
|
88
|
+
toolName: string;
|
|
89
|
+
toolCallId: string;
|
|
90
|
+
input?: unknown;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export interface ChildRunAuditToolResult {
|
|
94
|
+
toolName: string;
|
|
95
|
+
toolCallId: string;
|
|
96
|
+
input: unknown;
|
|
97
|
+
output: unknown;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface ChildRunAudit {
|
|
101
|
+
status: "completed" | "failed" | "cancelled" | "stopped";
|
|
102
|
+
description?: string;
|
|
103
|
+
steps?: number;
|
|
104
|
+
durationMs?: number;
|
|
105
|
+
toolCalls?: ChildRunAuditToolCall[];
|
|
106
|
+
toolResults?: ChildRunAuditToolResult[];
|
|
107
|
+
terminalErrorCode?: string | null;
|
|
108
|
+
terminalErrorMessage?: string | null;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface ChatMessageMetadata {
|
|
112
|
+
createdAt?: string;
|
|
113
|
+
isStopped?: boolean;
|
|
114
|
+
isCompleted?: boolean;
|
|
115
|
+
completedAt?: string;
|
|
116
|
+
agentId?: string;
|
|
117
|
+
agentName?: string;
|
|
118
|
+
conversationId?: string;
|
|
119
|
+
modelId?: string;
|
|
120
|
+
runId?: string;
|
|
121
|
+
streamingMessageId?: string;
|
|
122
|
+
childRunAudit?: ChildRunAudit;
|
|
123
|
+
usage?: ChatMessageMetadataUsage;
|
|
124
|
+
}
|
|
125
|
+
|
|
80
126
|
export type ChatFinishReason =
|
|
81
127
|
| "stop"
|
|
82
128
|
| "length"
|
|
@@ -208,3 +254,105 @@ export type ChatStreamEvent =
|
|
|
208
254
|
type: "error";
|
|
209
255
|
errorText: string;
|
|
210
256
|
};
|
|
257
|
+
|
|
258
|
+
type MessageLifecycleChunk<TMessageMetadata> =
|
|
259
|
+
| {
|
|
260
|
+
type: "start";
|
|
261
|
+
messageId?: string;
|
|
262
|
+
messageMetadata?: TMessageMetadata;
|
|
263
|
+
}
|
|
264
|
+
| {
|
|
265
|
+
type: "finish";
|
|
266
|
+
finishReason?: string;
|
|
267
|
+
messageMetadata?: TMessageMetadata;
|
|
268
|
+
}
|
|
269
|
+
| {
|
|
270
|
+
type: "message-metadata";
|
|
271
|
+
messageMetadata: TMessageMetadata;
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
type IdChunk<TType extends string> = {
|
|
275
|
+
type: TType;
|
|
276
|
+
id: string;
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
type IdDeltaChunk<TType extends string> = IdChunk<TType> & {
|
|
280
|
+
delta: string;
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
type ToolCallChunk<TType extends string> = {
|
|
284
|
+
type: TType;
|
|
285
|
+
toolCallId: string;
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
type NamedToolCallChunk<TType extends string> = ToolCallChunk<TType> & {
|
|
289
|
+
toolName: string;
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
type ToolInputChunk<TType extends string> = NamedToolCallChunk<TType> & {
|
|
293
|
+
input: unknown;
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
type ToolErrorChunk<TType extends string> = ToolCallChunk<TType> & {
|
|
297
|
+
errorText: string;
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
export type ChatUiMessageChunk<TMessageMetadata = ChatMessageMetadata> =
|
|
301
|
+
| MessageLifecycleChunk<TMessageMetadata>
|
|
302
|
+
| {
|
|
303
|
+
type: "start-step";
|
|
304
|
+
}
|
|
305
|
+
| {
|
|
306
|
+
type: "finish-step";
|
|
307
|
+
}
|
|
308
|
+
| {
|
|
309
|
+
type: "abort";
|
|
310
|
+
}
|
|
311
|
+
| IdChunk<"reasoning-start">
|
|
312
|
+
| IdDeltaChunk<"reasoning-delta">
|
|
313
|
+
| IdChunk<"reasoning-end">
|
|
314
|
+
| IdChunk<"text-start">
|
|
315
|
+
| IdDeltaChunk<"text-delta">
|
|
316
|
+
| IdChunk<"text-end">
|
|
317
|
+
| {
|
|
318
|
+
type: "source-url";
|
|
319
|
+
sourceId: string;
|
|
320
|
+
url: string;
|
|
321
|
+
title?: string;
|
|
322
|
+
}
|
|
323
|
+
| {
|
|
324
|
+
type: "source-document";
|
|
325
|
+
sourceId: string;
|
|
326
|
+
mediaType: string;
|
|
327
|
+
title: string;
|
|
328
|
+
filename?: string;
|
|
329
|
+
}
|
|
330
|
+
| {
|
|
331
|
+
type: "file";
|
|
332
|
+
mediaType: string;
|
|
333
|
+
url: string;
|
|
334
|
+
}
|
|
335
|
+
| NamedToolCallChunk<"tool-input-start">
|
|
336
|
+
| (ToolCallChunk<"tool-input-delta"> & {
|
|
337
|
+
inputTextDelta: string;
|
|
338
|
+
})
|
|
339
|
+
| ToolInputChunk<"tool-input-available">
|
|
340
|
+
| (ToolInputChunk<"tool-input-error"> & {
|
|
341
|
+
errorText: string;
|
|
342
|
+
})
|
|
343
|
+
| (ToolCallChunk<"tool-output-available"> & {
|
|
344
|
+
output: unknown;
|
|
345
|
+
})
|
|
346
|
+
| ToolErrorChunk<"tool-output-error">
|
|
347
|
+
| ToolCallChunk<"tool-output-denied">
|
|
348
|
+
| (ToolCallChunk<"tool-approval-request"> & {
|
|
349
|
+
approvalId: string;
|
|
350
|
+
})
|
|
351
|
+
| {
|
|
352
|
+
type: "error";
|
|
353
|
+
errorText: string;
|
|
354
|
+
}
|
|
355
|
+
| {
|
|
356
|
+
type: `data-${string}`;
|
|
357
|
+
data: unknown;
|
|
358
|
+
};
|