veryfront 0.1.480 → 0.1.482
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/README.md +1 -1
- package/esm/deno.js +4 -4
- package/esm/src/agent/default-hosted-chat-runtime.d.ts +64 -0
- package/esm/src/agent/default-hosted-chat-runtime.d.ts.map +1 -0
- package/esm/src/agent/default-hosted-chat-runtime.js +168 -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 +2 -0
- package/esm/src/agent/prepared-hosted-chat-execution.d.ts +27 -0
- package/esm/src/agent/prepared-hosted-chat-execution.d.ts.map +1 -0
- package/esm/src/agent/prepared-hosted-chat-execution.js +102 -0
- 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/deno.js +4 -4
- package/src/deps/esm.sh/@types/react-dom@19.2.3/client.d.ts +1 -1
- package/src/deps/esm.sh/@types/{react@19.2.14 → react@19.2.3}/global.d.ts +0 -1
- package/src/deps/esm.sh/@types/{react@19.2.14 → react@19.2.3}/index.d.ts +24 -93
- package/src/deps/esm.sh/react-dom@19.2.4/client.d.ts +1 -1
- package/src/src/agent/default-hosted-chat-runtime.ts +326 -0
- package/src/src/agent/index.ts +21 -0
- package/src/src/agent/prepared-hosted-chat-execution.ts +188 -0
- package/src/src/utils/version-constant.ts +1 -1
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import type { AgentTraceAttributes } from "./agent-trace-attributes.js";
|
|
2
|
+
import { createAgUiChatUiTrackedBrowserResponse } from "./ag-ui-chat-ui-chunk-browser-encoder.js";
|
|
3
|
+
import {
|
|
4
|
+
type BootstrappedHostedChatExecutionRuntime,
|
|
5
|
+
createBootstrappedHostedChatExecutionRuntime,
|
|
6
|
+
type CreateBootstrappedHostedChatExecutionRuntimeInput,
|
|
7
|
+
} from "./hosted-chat-execution-runtime.js";
|
|
8
|
+
import { runHostedLifecycle } from "./hosted-lifecycle.js";
|
|
9
|
+
import type { AgUiRuntimeRequest } from "./runtime-ag-ui-contract.js";
|
|
10
|
+
|
|
11
|
+
export type PreparedHostedChatExecution =
|
|
12
|
+
& Omit<
|
|
13
|
+
CreateBootstrappedHostedChatExecutionRuntimeInput,
|
|
14
|
+
| "apiUrl"
|
|
15
|
+
| "abortSignal"
|
|
16
|
+
| "responseMessageId"
|
|
17
|
+
| "tracer"
|
|
18
|
+
| "resolveProvider"
|
|
19
|
+
| "traceStream"
|
|
20
|
+
| "logger"
|
|
21
|
+
| "spanName"
|
|
22
|
+
| "terminalErrorCode"
|
|
23
|
+
| "incompleteToolCallsPartErrorText"
|
|
24
|
+
| "createRootStreamWatchdog"
|
|
25
|
+
| "createTerminalAdapter"
|
|
26
|
+
>
|
|
27
|
+
& {
|
|
28
|
+
runtimeKind?: string;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type PreparedHostedChatExecutionRuntimeOptions =
|
|
32
|
+
& Pick<
|
|
33
|
+
CreateBootstrappedHostedChatExecutionRuntimeInput,
|
|
34
|
+
| "tracer"
|
|
35
|
+
| "resolveProvider"
|
|
36
|
+
| "traceStream"
|
|
37
|
+
| "logger"
|
|
38
|
+
| "spanName"
|
|
39
|
+
| "terminalErrorCode"
|
|
40
|
+
| "incompleteToolCallsPartErrorText"
|
|
41
|
+
| "createRootStreamWatchdog"
|
|
42
|
+
| "createTerminalAdapter"
|
|
43
|
+
>
|
|
44
|
+
& {
|
|
45
|
+
apiUrl: string | URL;
|
|
46
|
+
trace?: <TResult>(operationName: string, operation: () => Promise<TResult>) => Promise<TResult>;
|
|
47
|
+
setActiveSpanAttributes?: (attributes: AgentTraceAttributes) => void;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export type PreparedHostedChatExecutionStreamInput<
|
|
51
|
+
TExecution extends PreparedHostedChatExecution = PreparedHostedChatExecution,
|
|
52
|
+
> = TExecution & {
|
|
53
|
+
requestAbortSignal: AbortSignal;
|
|
54
|
+
agUiInput: AgUiRuntimeRequest;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export type PreparedHostedChatExecutionDetachedInput<
|
|
58
|
+
TExecution extends PreparedHostedChatExecution = PreparedHostedChatExecution,
|
|
59
|
+
> = TExecution & {
|
|
60
|
+
abortSignal: AbortSignal;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
function tracePreparedHostedChatExecution<TResult>(input: {
|
|
64
|
+
spanName: string;
|
|
65
|
+
execution: PreparedHostedChatExecution;
|
|
66
|
+
runtime: PreparedHostedChatExecutionRuntimeOptions;
|
|
67
|
+
run: () => Promise<TResult>;
|
|
68
|
+
}): Promise<TResult> {
|
|
69
|
+
const run = async () => {
|
|
70
|
+
input.runtime.setActiveSpanAttributes?.({
|
|
71
|
+
"conversation.id": input.execution.conversationId,
|
|
72
|
+
"project.id": input.execution.projectId ?? "none",
|
|
73
|
+
"agent.runtime.kind": input.execution.runtimeKind,
|
|
74
|
+
});
|
|
75
|
+
return await input.run();
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
if (!input.runtime.trace) {
|
|
79
|
+
return run();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return input.runtime.trace(input.spanName, run);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function createBootstrappedPreparedHostedChatExecutionRuntime(input: {
|
|
86
|
+
execution: PreparedHostedChatExecution;
|
|
87
|
+
abortSignal: AbortSignal;
|
|
88
|
+
runtime: PreparedHostedChatExecutionRuntimeOptions;
|
|
89
|
+
responseMessageId?: string;
|
|
90
|
+
}): Promise<BootstrappedHostedChatExecutionRuntime> {
|
|
91
|
+
return createBootstrappedHostedChatExecutionRuntime({
|
|
92
|
+
...input.execution,
|
|
93
|
+
apiUrl: input.runtime.apiUrl.toString(),
|
|
94
|
+
abortSignal: input.abortSignal,
|
|
95
|
+
tracer: input.runtime.tracer,
|
|
96
|
+
resolveProvider: input.runtime.resolveProvider,
|
|
97
|
+
traceStream: input.runtime.traceStream,
|
|
98
|
+
logger: input.runtime.logger,
|
|
99
|
+
spanName: input.runtime.spanName,
|
|
100
|
+
terminalErrorCode: input.runtime.terminalErrorCode,
|
|
101
|
+
incompleteToolCallsPartErrorText: input.runtime.incompleteToolCallsPartErrorText,
|
|
102
|
+
createRootStreamWatchdog: input.runtime.createRootStreamWatchdog,
|
|
103
|
+
createTerminalAdapter: input.runtime.createTerminalAdapter,
|
|
104
|
+
...(input.responseMessageId ? { responseMessageId: input.responseMessageId } : {}),
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export async function streamPreparedHostedChatExecutionToAgUiResponse<
|
|
109
|
+
TExecution extends PreparedHostedChatExecution,
|
|
110
|
+
>(input: {
|
|
111
|
+
execution: PreparedHostedChatExecutionStreamInput<TExecution>;
|
|
112
|
+
runtime: PreparedHostedChatExecutionRuntimeOptions;
|
|
113
|
+
}): Promise<Response> {
|
|
114
|
+
return await tracePreparedHostedChatExecution({
|
|
115
|
+
spanName: "chat.streamToAgUiResponse",
|
|
116
|
+
execution: input.execution,
|
|
117
|
+
runtime: input.runtime,
|
|
118
|
+
run: async () => {
|
|
119
|
+
const agUiRunId = input.execution.agUiInput.runId ??
|
|
120
|
+
input.execution.rootRunContext.durableRootRun?.runId;
|
|
121
|
+
const { execution } = await createBootstrappedPreparedHostedChatExecutionRuntime({
|
|
122
|
+
execution: input.execution,
|
|
123
|
+
abortSignal: input.execution.requestAbortSignal,
|
|
124
|
+
runtime: input.runtime,
|
|
125
|
+
...(agUiRunId ? { responseMessageId: `${agUiRunId}:assistant` } : {}),
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
return createAgUiChatUiTrackedBrowserResponse({
|
|
129
|
+
agUiInput: input.execution.agUiInput,
|
|
130
|
+
defaults: {
|
|
131
|
+
...(input.execution.conversationId ? { threadId: input.execution.conversationId } : {}),
|
|
132
|
+
...(agUiRunId ? { runId: agUiRunId } : {}),
|
|
133
|
+
},
|
|
134
|
+
agentId: input.execution.agentId,
|
|
135
|
+
modelId: input.execution.modelId,
|
|
136
|
+
execution,
|
|
137
|
+
});
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export async function runPreparedHostedChatExecutionDetached<
|
|
143
|
+
TExecution extends PreparedHostedChatExecution,
|
|
144
|
+
>(input: {
|
|
145
|
+
execution: PreparedHostedChatExecutionDetachedInput<TExecution>;
|
|
146
|
+
runtime: PreparedHostedChatExecutionRuntimeOptions;
|
|
147
|
+
}): Promise<void> {
|
|
148
|
+
await tracePreparedHostedChatExecution({
|
|
149
|
+
spanName: "chat.runDetached",
|
|
150
|
+
execution: input.execution,
|
|
151
|
+
runtime: input.runtime,
|
|
152
|
+
run: async () => {
|
|
153
|
+
const { agentRunSpan, execution } =
|
|
154
|
+
await createBootstrappedPreparedHostedChatExecutionRuntime({
|
|
155
|
+
execution: input.execution,
|
|
156
|
+
abortSignal: input.execution.abortSignal,
|
|
157
|
+
runtime: input.runtime,
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
try {
|
|
161
|
+
await agentRunSpan.withContext(async () => {
|
|
162
|
+
await runHostedLifecycle({
|
|
163
|
+
abortSignal: input.execution.abortSignal,
|
|
164
|
+
execution: {
|
|
165
|
+
stream: execution.agentUIStream,
|
|
166
|
+
waitForFinish: execution.waitForFinish,
|
|
167
|
+
},
|
|
168
|
+
adapter: {
|
|
169
|
+
startRun: () => ({
|
|
170
|
+
runId: input.execution.rootRunContext.durableRootRun?.runId ?? "detached-run",
|
|
171
|
+
}),
|
|
172
|
+
},
|
|
173
|
+
resolveTerminalState: () => ({
|
|
174
|
+
status: input.execution.abortSignal.aborted ? "cancelled" : "completed",
|
|
175
|
+
}),
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
} catch (error) {
|
|
179
|
+
input.runtime.logger?.error("Detached durable chat execution failed", {
|
|
180
|
+
conversationId: input.execution.conversationId,
|
|
181
|
+
runId: input.execution.rootRunContext.durableRootRun?.runId,
|
|
182
|
+
error: error instanceof Error ? error.message : String(error),
|
|
183
|
+
});
|
|
184
|
+
await execution.fail(error);
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
}
|