veryfront 0.1.252 → 0.1.255

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.
Files changed (32) hide show
  1. package/esm/cli/templates/manifest.d.ts +473 -473
  2. package/esm/cli/templates/manifest.js +521 -521
  3. package/esm/deno.js +1 -1
  4. package/esm/src/agent/conversation-hosted-lifecycle.d.ts +2 -0
  5. package/esm/src/agent/conversation-hosted-lifecycle.d.ts.map +1 -1
  6. package/esm/src/agent/conversation-hosted-lifecycle.js +7 -0
  7. package/esm/src/agent/conversation-run-event-preparation.d.ts +5 -0
  8. package/esm/src/agent/conversation-run-event-preparation.d.ts.map +1 -0
  9. package/esm/src/agent/conversation-run-event-preparation.js +8 -0
  10. package/esm/src/agent/conversation-run-events.d.ts +30 -0
  11. package/esm/src/agent/conversation-run-events.d.ts.map +1 -0
  12. package/esm/src/agent/conversation-run-events.js +198 -0
  13. package/esm/src/agent/conversation-run-stream-mirror.d.ts +21 -0
  14. package/esm/src/agent/conversation-run-stream-mirror.d.ts.map +1 -0
  15. package/esm/src/agent/conversation-run-stream-mirror.js +31 -0
  16. package/esm/src/agent/index.d.ts +4 -1
  17. package/esm/src/agent/index.d.ts.map +1 -1
  18. package/esm/src/agent/index.js +4 -1
  19. package/esm/src/server/dev-ui/manifest.d.ts +17 -17
  20. package/esm/src/server/dev-ui/manifest.js +17 -17
  21. package/esm/src/utils/version-constant.d.ts +1 -1
  22. package/esm/src/utils/version-constant.js +1 -1
  23. package/package.json +1 -1
  24. package/src/cli/templates/manifest.js +521 -521
  25. package/src/deno.js +1 -1
  26. package/src/src/agent/conversation-hosted-lifecycle.ts +14 -0
  27. package/src/src/agent/conversation-run-event-preparation.ts +20 -0
  28. package/src/src/agent/conversation-run-events.ts +234 -0
  29. package/src/src/agent/conversation-run-stream-mirror.ts +59 -0
  30. package/src/src/agent/index.ts +17 -0
  31. package/src/src/server/dev-ui/manifest.js +17 -17
  32. package/src/src/utils/version-constant.ts +1 -1
package/src/deno.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export default {
2
2
  "name": "veryfront",
3
- "version": "0.1.252",
3
+ "version": "0.1.255",
4
4
  "license": "Apache-2.0",
5
5
  "nodeModulesDir": "auto",
6
6
  "workspace": [
@@ -4,11 +4,13 @@ import {
4
4
  type ConversationRunProjection,
5
5
  finalizeConversationAgentRun,
6
6
  } from "./durable.js";
7
+ import { prepareConversationRunStreamEvents } from "./conversation-run-event-preparation.js";
7
8
  import {
8
9
  type InvokeAgentChildRunProgressEvent,
9
10
  type InvokeAgentChildRunProgressInput,
10
11
  publishInvokeAgentChildRunProgress,
11
12
  } from "./invoke-agent-child-runs.js";
13
+ import type { ChatStreamEvent } from "../chat/protocol.js";
12
14
  import type {
13
15
  HostedChildLifecycleAdapter,
14
16
  HostedChildLifecycleTerminalState,
@@ -100,6 +102,18 @@ export function createConversationHostedLifecycleAdapter<TChunk>(
100
102
  };
101
103
  }
102
104
 
105
+ export function createConversationHostedStreamLifecycleAdapter(
106
+ options: Omit<
107
+ CreateConversationHostedLifecycleAdapterOptions<ChatStreamEvent>,
108
+ "mapChunkToEvents"
109
+ >,
110
+ ): HostedLifecycleAdapter<ConversationRunProjection, ChatStreamEvent> {
111
+ return createConversationHostedLifecycleAdapter({
112
+ ...options,
113
+ mapChunkToEvents: (chunk) => prepareConversationRunStreamEvents([chunk]),
114
+ });
115
+ }
116
+
103
117
  export interface ConversationChildLifecycleContext {
104
118
  authToken: string;
105
119
  apiUrl: string;
@@ -0,0 +1,20 @@
1
+ import { type ChatStreamEvent } from "../chat/protocol.js";
2
+ import {
3
+ type ConversationRunEvent,
4
+ ConversationRunEventEncoder,
5
+ encodeConversationRunEvents,
6
+ } from "./conversation-run-events.js";
7
+ import { normalizeConversationRunEvents } from "./conversation-run-event-normalization.js";
8
+
9
+ export function prepareConversationRunStreamEvents(
10
+ events: ChatStreamEvent[],
11
+ encoder = new ConversationRunEventEncoder(),
12
+ ): ConversationRunEvent[] {
13
+ return normalizeConversationRunEvents(encodeConversationRunEvents(events, encoder));
14
+ }
15
+
16
+ export function prepareConversationRunExternalEvents(
17
+ events: ConversationRunEvent[],
18
+ ): ConversationRunEvent[] {
19
+ return normalizeConversationRunEvents(events);
20
+ }
@@ -0,0 +1,234 @@
1
+ import { z } from "zod";
2
+ import { type ChatStreamEvent } from "../chat/protocol.js";
3
+ import { normalizeConversationRunEvents } from "./conversation-run-event-normalization.js";
4
+
5
+ export const conversationRunEventTypes = {
6
+ custom: "CUSTOM",
7
+ textMessageStart: "TEXT_MESSAGE_START",
8
+ textMessageContent: "TEXT_MESSAGE_CONTENT",
9
+ textMessageEnd: "TEXT_MESSAGE_END",
10
+ reasoningMessageStart: "REASONING_MESSAGE_START",
11
+ reasoningMessageContent: "REASONING_MESSAGE_CONTENT",
12
+ reasoningMessageEnd: "REASONING_MESSAGE_END",
13
+ toolCallStart: "TOOL_CALL_START",
14
+ toolCallArgs: "TOOL_CALL_ARGS",
15
+ toolCallEnd: "TOOL_CALL_END",
16
+ toolCallResult: "TOOL_CALL_RESULT",
17
+ } as const;
18
+
19
+ export const ConversationRunEventSchema = z.object({
20
+ type: z.string().min(1),
21
+ }).passthrough();
22
+
23
+ export type ConversationRunEvent = z.infer<typeof ConversationRunEventSchema>;
24
+
25
+ function serializeToolInput(input: unknown): string {
26
+ try {
27
+ return JSON.stringify(input ?? {});
28
+ } catch {
29
+ return "{}";
30
+ }
31
+ }
32
+
33
+ function encodeCustomDataEvent(
34
+ chunk: Extract<ChatStreamEvent, { type: `data-${string}` }>,
35
+ ): ConversationRunEvent[] {
36
+ const name = chunk.type.slice("data-".length);
37
+ if (name.length === 0) {
38
+ return [];
39
+ }
40
+
41
+ return [{
42
+ type: conversationRunEventTypes.custom,
43
+ name,
44
+ value: chunk.data,
45
+ }];
46
+ }
47
+
48
+ export class ConversationRunEventEncoder {
49
+ private readonly streamedToolInputs = new Set<string>();
50
+ private readonly toolInputs = new Map<string, unknown>();
51
+ private activeMessageId: string | null = null;
52
+
53
+ private getToolResultMessageId(toolCallId: string) {
54
+ return this.activeMessageId
55
+ ? `${this.activeMessageId}:tool:${toolCallId}`
56
+ : `tool:${toolCallId}`;
57
+ }
58
+
59
+ private serializeToolResultContent(value: unknown): string {
60
+ if (typeof value === "string") {
61
+ return value;
62
+ }
63
+
64
+ try {
65
+ return JSON.stringify(value ?? null);
66
+ } catch {
67
+ return String(value);
68
+ }
69
+ }
70
+
71
+ encode(chunk: ChatStreamEvent): ConversationRunEvent[] {
72
+ switch (chunk.type) {
73
+ case "start":
74
+ this.activeMessageId = chunk.messageId ?? null;
75
+ return [];
76
+
77
+ case "text-start":
78
+ return [{
79
+ type: conversationRunEventTypes.textMessageStart,
80
+ messageId: chunk.id,
81
+ role: "assistant",
82
+ }];
83
+
84
+ case "text-delta":
85
+ return [{
86
+ type: conversationRunEventTypes.textMessageContent,
87
+ messageId: chunk.id,
88
+ delta: chunk.delta,
89
+ }];
90
+
91
+ case "text-end":
92
+ return [{ type: conversationRunEventTypes.textMessageEnd, messageId: chunk.id }];
93
+
94
+ case "reasoning-start":
95
+ return [{
96
+ type: conversationRunEventTypes.reasoningMessageStart,
97
+ messageId: chunk.id,
98
+ role: "assistant",
99
+ }];
100
+
101
+ case "reasoning-delta":
102
+ return [{
103
+ type: conversationRunEventTypes.reasoningMessageContent,
104
+ messageId: chunk.id,
105
+ delta: chunk.delta,
106
+ }];
107
+
108
+ case "reasoning-end":
109
+ return [{ type: conversationRunEventTypes.reasoningMessageEnd, messageId: chunk.id }];
110
+
111
+ case "tool-input-start":
112
+ return [{
113
+ type: conversationRunEventTypes.toolCallStart,
114
+ toolCallId: chunk.toolCallId,
115
+ toolCallName: chunk.toolName,
116
+ }];
117
+
118
+ case "tool-input-delta":
119
+ this.streamedToolInputs.add(chunk.toolCallId);
120
+ return [{
121
+ type: conversationRunEventTypes.toolCallArgs,
122
+ toolCallId: chunk.toolCallId,
123
+ delta: chunk.inputTextDelta,
124
+ }];
125
+
126
+ case "tool-input-available": {
127
+ this.toolInputs.set(chunk.toolCallId, chunk.input);
128
+ const events: ConversationRunEvent[] = [];
129
+ if (!this.streamedToolInputs.has(chunk.toolCallId)) {
130
+ events.push({
131
+ type: conversationRunEventTypes.toolCallArgs,
132
+ toolCallId: chunk.toolCallId,
133
+ delta: serializeToolInput(chunk.input),
134
+ });
135
+ }
136
+ events.push({ type: conversationRunEventTypes.toolCallEnd, toolCallId: chunk.toolCallId });
137
+ return events;
138
+ }
139
+
140
+ case "tool-input-error": {
141
+ this.toolInputs.set(chunk.toolCallId, chunk.input);
142
+ const events: ConversationRunEvent[] = [];
143
+ if (!this.streamedToolInputs.has(chunk.toolCallId)) {
144
+ events.push({
145
+ type: conversationRunEventTypes.toolCallArgs,
146
+ toolCallId: chunk.toolCallId,
147
+ delta: serializeToolInput(chunk.input),
148
+ });
149
+ }
150
+ events.push({ type: conversationRunEventTypes.toolCallEnd, toolCallId: chunk.toolCallId });
151
+ events.push({
152
+ type: conversationRunEventTypes.toolCallResult,
153
+ messageId: this.getToolResultMessageId(chunk.toolCallId),
154
+ toolCallId: chunk.toolCallId,
155
+ content: this.serializeToolResultContent(chunk.errorText),
156
+ role: "tool",
157
+ ...(this.toolInputs.has(chunk.toolCallId)
158
+ ? { input: this.toolInputs.get(chunk.toolCallId) }
159
+ : {}),
160
+ isError: true,
161
+ });
162
+ this.toolInputs.delete(chunk.toolCallId);
163
+ return events;
164
+ }
165
+
166
+ case "tool-output-available":
167
+ return [{
168
+ type: conversationRunEventTypes.toolCallResult,
169
+ messageId: this.getToolResultMessageId(chunk.toolCallId),
170
+ toolCallId: chunk.toolCallId,
171
+ content: this.serializeToolResultContent(chunk.output),
172
+ role: "tool",
173
+ ...(this.toolInputs.has(chunk.toolCallId)
174
+ ? { input: this.toolInputs.get(chunk.toolCallId) }
175
+ : {}),
176
+ }];
177
+
178
+ case "tool-output-error":
179
+ return [{
180
+ type: conversationRunEventTypes.toolCallResult,
181
+ messageId: this.getToolResultMessageId(chunk.toolCallId),
182
+ toolCallId: chunk.toolCallId,
183
+ content: this.serializeToolResultContent(chunk.errorText),
184
+ role: "tool",
185
+ ...(this.toolInputs.has(chunk.toolCallId)
186
+ ? { input: this.toolInputs.get(chunk.toolCallId) }
187
+ : {}),
188
+ isError: true,
189
+ }];
190
+
191
+ case "tool-output-denied":
192
+ return [{
193
+ type: conversationRunEventTypes.toolCallResult,
194
+ messageId: this.getToolResultMessageId(chunk.toolCallId),
195
+ toolCallId: chunk.toolCallId,
196
+ content: "Tool output denied",
197
+ role: "tool",
198
+ ...(this.toolInputs.has(chunk.toolCallId)
199
+ ? { input: this.toolInputs.get(chunk.toolCallId) }
200
+ : {}),
201
+ isError: true,
202
+ }];
203
+
204
+ case "error":
205
+ case "finish":
206
+ case "abort":
207
+ case "message-metadata":
208
+ case "source-url":
209
+ case "source-document":
210
+ case "file":
211
+ case "tool-approval-request":
212
+ case "start-step":
213
+ case "finish-step":
214
+ return [];
215
+
216
+ default:
217
+ return chunk.type.startsWith("data-") ? encodeCustomDataEvent(chunk) : [];
218
+ }
219
+ }
220
+ }
221
+
222
+ export function encodeConversationRunEvents(
223
+ events: ChatStreamEvent[],
224
+ encoder = new ConversationRunEventEncoder(),
225
+ ): ConversationRunEvent[] {
226
+ return events.flatMap((event) => encoder.encode(event));
227
+ }
228
+
229
+ export function normalizeEncodedConversationRunEvents(
230
+ events: ChatStreamEvent[],
231
+ encoder = new ConversationRunEventEncoder(),
232
+ ): ConversationRunEvent[] {
233
+ return normalizeConversationRunEvents(encodeConversationRunEvents(events, encoder));
234
+ }
@@ -0,0 +1,59 @@
1
+ import { type ChatStreamEvent } from "../chat/protocol.js";
2
+ import {
3
+ type ConversationRunEvent,
4
+ ConversationRunEventEncoder,
5
+ } from "./conversation-run-events.js";
6
+ import {
7
+ type ConversationRunMirror,
8
+ type ConversationRunMirrorRetryScheduledState,
9
+ type ConversationRunMirrorStoppedState,
10
+ createConversationRunMirror,
11
+ } from "./conversation-run-mirror.js";
12
+ import { normalizeConversationRunEvents } from "./conversation-run-event-normalization.js";
13
+ import { type ConversationRunEventQueueController } from "./durable.js";
14
+
15
+ export interface ConversationRunStreamMirror {
16
+ handleStreamEvent(event: ChatStreamEvent): void;
17
+ appendEvents(events: ConversationRunEvent[]): void;
18
+ flush(): Promise<void>;
19
+ getSnapshot(): ReturnType<ConversationRunMirror["getSnapshot"]>;
20
+ dispose(): void;
21
+ }
22
+
23
+ export function createConversationRunStreamMirror(input: {
24
+ queueController: ConversationRunEventQueueController;
25
+ immediateFlushEventCount: number;
26
+ encoder?: ConversationRunEventEncoder;
27
+ flushDelayMs?: number;
28
+ getRetryDelayMs?: (consecutiveFailures: number) => number;
29
+ onRetryScheduled?: (state: ConversationRunMirrorRetryScheduledState) => Promise<void> | void;
30
+ onStopped?: (state: ConversationRunMirrorStoppedState) => Promise<void> | void;
31
+ }): ConversationRunStreamMirror {
32
+ const encoder = input.encoder ?? new ConversationRunEventEncoder();
33
+ const mirror = createConversationRunMirror({
34
+ queueController: input.queueController,
35
+ immediateFlushEventCount: input.immediateFlushEventCount,
36
+ ...(input.flushDelayMs !== undefined ? { flushDelayMs: input.flushDelayMs } : {}),
37
+ ...(input.getRetryDelayMs ? { getRetryDelayMs: input.getRetryDelayMs } : {}),
38
+ ...(input.onRetryScheduled ? { onRetryScheduled: input.onRetryScheduled } : {}),
39
+ ...(input.onStopped ? { onStopped: input.onStopped } : {}),
40
+ });
41
+
42
+ return {
43
+ handleStreamEvent(event) {
44
+ mirror.enqueue(normalizeConversationRunEvents(encoder.encode(event)));
45
+ },
46
+ appendEvents(events) {
47
+ mirror.enqueue(normalizeConversationRunEvents(events));
48
+ },
49
+ flush() {
50
+ return mirror.flush();
51
+ },
52
+ getSnapshot() {
53
+ return mirror.getSnapshot();
54
+ },
55
+ dispose() {
56
+ mirror.dispose();
57
+ },
58
+ };
59
+ }
@@ -210,12 +210,25 @@ export {
210
210
  createConversationChildLifecycleAdapter,
211
211
  createConversationHostedLifecycleAdapter,
212
212
  type CreateConversationHostedLifecycleAdapterOptions,
213
+ createConversationHostedStreamLifecycleAdapter,
213
214
  } from "./conversation-hosted-lifecycle.js";
214
215
  export {
215
216
  getConversationRunEventJsonByteLength,
216
217
  normalizeConversationRunEvent,
217
218
  normalizeConversationRunEvents,
218
219
  } from "./conversation-run-event-normalization.js";
220
+ export {
221
+ type ConversationRunEvent,
222
+ ConversationRunEventEncoder,
223
+ ConversationRunEventSchema,
224
+ conversationRunEventTypes,
225
+ encodeConversationRunEvents,
226
+ normalizeEncodedConversationRunEvents,
227
+ } from "./conversation-run-events.js";
228
+ export {
229
+ prepareConversationRunExternalEvents,
230
+ prepareConversationRunStreamEvents,
231
+ } from "./conversation-run-event-preparation.js";
219
232
  export {
220
233
  type ConversationRunMirror,
221
234
  type ConversationRunMirrorRetryScheduledState,
@@ -223,6 +236,10 @@ export {
223
236
  type ConversationRunMirrorStoppedState,
224
237
  createConversationRunMirror,
225
238
  } from "./conversation-run-mirror.js";
239
+ export {
240
+ type ConversationRunStreamMirror,
241
+ createConversationRunStreamMirror,
242
+ } from "./conversation-run-stream-mirror.js";
226
243
  export {
227
244
  type ActiveConversationRunStatus,
228
245
  appendConversationRunEvents,