veryfront 0.1.258 → 0.1.259
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/templates/manifest.d.ts +470 -470
- package/esm/cli/templates/manifest.js +519 -519
- package/esm/deno.js +1 -1
- package/esm/src/agent/ag-ui-browser-finalize-tracker.d.ts +12 -0
- package/esm/src/agent/ag-ui-browser-finalize-tracker.d.ts.map +1 -0
- package/esm/src/agent/ag-ui-browser-finalize-tracker.js +42 -0
- package/esm/src/agent/ag-ui-chunk-encoder-bridge.d.ts +11 -0
- package/esm/src/agent/ag-ui-chunk-encoder-bridge.d.ts.map +1 -0
- package/esm/src/agent/ag-ui-chunk-encoder-bridge.js +9 -0
- package/esm/src/agent/ag-ui-host-support.d.ts +1 -0
- package/esm/src/agent/ag-ui-host-support.d.ts.map +1 -1
- package/esm/src/agent/ag-ui-host-support.js +10 -0
- package/esm/src/agent/ag-ui-runtime-browser-response.d.ts +18 -0
- package/esm/src/agent/ag-ui-runtime-browser-response.d.ts.map +1 -0
- package/esm/src/agent/ag-ui-runtime-browser-response.js +15 -0
- package/esm/src/agent/ag-ui-runtime-event-encoder.d.ts +11 -0
- package/esm/src/agent/ag-ui-runtime-event-encoder.d.ts.map +1 -0
- package/esm/src/agent/ag-ui-runtime-event-encoder.js +37 -0
- package/esm/src/agent/ag-ui-tracked-browser-response.d.ts +9 -0
- package/esm/src/agent/ag-ui-tracked-browser-response.d.ts.map +1 -0
- package/esm/src/agent/ag-ui-tracked-browser-response.js +19 -0
- package/esm/src/agent/hosted-response-stream.d.ts +22 -0
- package/esm/src/agent/hosted-response-stream.d.ts.map +1 -0
- package/esm/src/agent/hosted-response-stream.js +52 -0
- package/esm/src/agent/index.d.ts +8 -2
- package/esm/src/agent/index.d.ts.map +1 -1
- package/esm/src/agent/index.js +8 -2
- package/esm/src/agent/runtime-ag-ui-contract.d.ts +4 -0
- package/esm/src/agent/runtime-ag-ui-contract.d.ts.map +1 -1
- package/esm/src/agent/runtime-ag-ui-contract.js +13 -0
- package/esm/src/server/dev-ui/manifest.d.ts +17 -17
- package/esm/src/server/dev-ui/manifest.js +17 -17
- 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/templates/manifest.js +519 -519
- package/src/deno.js +1 -1
- package/src/src/agent/ag-ui-browser-finalize-tracker.ts +65 -0
- package/src/src/agent/ag-ui-chunk-encoder-bridge.ts +34 -0
- package/src/src/agent/ag-ui-host-support.ts +11 -0
- package/src/src/agent/ag-ui-runtime-browser-response.ts +41 -0
- package/src/src/agent/ag-ui-runtime-event-encoder.ts +71 -0
- package/src/src/agent/ag-ui-tracked-browser-response.ts +42 -0
- package/src/src/agent/hosted-response-stream.ts +87 -0
- package/src/src/agent/index.ts +31 -0
- package/src/src/agent/runtime-ag-ui-contract.ts +22 -0
- package/src/src/server/dev-ui/manifest.js +17 -17
- package/src/src/utils/version-constant.ts +1 -1
package/src/deno.js
CHANGED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AgUiBrowserEncodedEvent,
|
|
3
|
+
type AgUiBrowserRunFinishedMetadata,
|
|
4
|
+
buildAgUiBrowserFinalizeResponse,
|
|
5
|
+
} from "./ag-ui-browser-encoder.js";
|
|
6
|
+
import type { AgentResponse } from "./types.js";
|
|
7
|
+
|
|
8
|
+
export interface AgUiBrowserFinalizeTracker<TChunk> {
|
|
9
|
+
observeChunk: (chunk: TChunk) => void;
|
|
10
|
+
observeEncodedEvents: (events: readonly AgUiBrowserEncodedEvent[]) => void;
|
|
11
|
+
getFinalResponse: () => AgentResponse | null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface CreateAgUiBrowserFinalizeTrackerOptions<TChunk> {
|
|
15
|
+
getMetadataFromChunk: (
|
|
16
|
+
chunk: TChunk,
|
|
17
|
+
) => Partial<AgUiBrowserRunFinishedMetadata> | null | undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function createAgUiBrowserFinalizeTracker<TChunk>(
|
|
21
|
+
options: CreateAgUiBrowserFinalizeTrackerOptions<TChunk>,
|
|
22
|
+
): AgUiBrowserFinalizeTracker<TChunk> {
|
|
23
|
+
let sawRunError = false;
|
|
24
|
+
const metadata: AgUiBrowserRunFinishedMetadata = {};
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
observeChunk: (chunk) => {
|
|
28
|
+
const nextMetadata = options.getMetadataFromChunk(chunk);
|
|
29
|
+
if (!nextMetadata) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (typeof nextMetadata.provider === "string") {
|
|
34
|
+
metadata.provider = nextMetadata.provider;
|
|
35
|
+
}
|
|
36
|
+
if (typeof nextMetadata.model === "string") {
|
|
37
|
+
metadata.model = nextMetadata.model;
|
|
38
|
+
}
|
|
39
|
+
if (typeof nextMetadata.inputTokens === "number") {
|
|
40
|
+
metadata.inputTokens = nextMetadata.inputTokens;
|
|
41
|
+
}
|
|
42
|
+
if (typeof nextMetadata.outputTokens === "number") {
|
|
43
|
+
metadata.outputTokens = nextMetadata.outputTokens;
|
|
44
|
+
}
|
|
45
|
+
if (typeof nextMetadata.totalTokens === "number") {
|
|
46
|
+
metadata.totalTokens = nextMetadata.totalTokens;
|
|
47
|
+
}
|
|
48
|
+
if (typeof nextMetadata.finishReason === "string") {
|
|
49
|
+
metadata.finishReason = nextMetadata.finishReason;
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
observeEncodedEvents: (events) => {
|
|
53
|
+
if (events.some((event) => event.event === "RunError")) {
|
|
54
|
+
sawRunError = true;
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
getFinalResponse: () => {
|
|
58
|
+
if (sawRunError) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return buildAgUiBrowserFinalizeResponse(metadata);
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AgentResponse,
|
|
3
|
+
type AgUiBrowserEncodedEvent,
|
|
4
|
+
type AgUiBrowserEncoderState,
|
|
5
|
+
type AgUiRuntimeStreamEvent,
|
|
6
|
+
createAgUiBrowserEncoderState,
|
|
7
|
+
finalizeAgUiBrowserEvents,
|
|
8
|
+
mapRuntimeStreamEventToAgUiBrowserEvents,
|
|
9
|
+
} from "./index.js";
|
|
10
|
+
|
|
11
|
+
export interface AgUiChunkEncoderBridge<TChunk> {
|
|
12
|
+
encode: (chunk: TChunk) => AgUiBrowserEncodedEvent[];
|
|
13
|
+
finalize: (response: AgentResponse | null) => AgUiBrowserEncodedEvent[];
|
|
14
|
+
state: AgUiBrowserEncoderState;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface CreateAgUiChunkEncoderBridgeOptions<TChunk> {
|
|
18
|
+
getRuntimeEvents: (chunk: TChunk) => readonly AgUiRuntimeStreamEvent[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function createAgUiChunkEncoderBridge<TChunk>(
|
|
22
|
+
options: CreateAgUiChunkEncoderBridgeOptions<TChunk>,
|
|
23
|
+
): AgUiChunkEncoderBridge<TChunk> {
|
|
24
|
+
const state = createAgUiBrowserEncoderState();
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
state,
|
|
28
|
+
encode: (chunk) =>
|
|
29
|
+
options.getRuntimeEvents(chunk).flatMap((event) =>
|
|
30
|
+
mapRuntimeStreamEventToAgUiBrowserEvents(state, event)
|
|
31
|
+
),
|
|
32
|
+
finalize: (response) => finalizeAgUiBrowserEvents(state, response),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -236,3 +236,14 @@ export function createAgUiSseErrorResponse(event: AgUiSseEvent, status: number):
|
|
|
236
236
|
},
|
|
237
237
|
});
|
|
238
238
|
}
|
|
239
|
+
|
|
240
|
+
export function createAgUiSseResponse(stream: ReadableStream<Uint8Array>): Response {
|
|
241
|
+
return new Response(stream, {
|
|
242
|
+
headers: {
|
|
243
|
+
"Content-Type": "text/event-stream; charset=utf-8",
|
|
244
|
+
"Cache-Control": "no-cache, no-transform",
|
|
245
|
+
"Connection": "keep-alive",
|
|
246
|
+
"X-Accel-Buffering": "no",
|
|
247
|
+
},
|
|
248
|
+
});
|
|
249
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AgUiBrowserResponseEncoder,
|
|
3
|
+
type AgUiBrowserResponseExecution,
|
|
4
|
+
createAgUiBrowserResponseStream,
|
|
5
|
+
} from "./ag-ui-browser-response-stream.js";
|
|
6
|
+
import { createAgUiSseResponse } from "./ag-ui-host-support.js";
|
|
7
|
+
import {
|
|
8
|
+
type AgUiRuntimeRequest,
|
|
9
|
+
normalizeAgUiBrowserRuntimeRequest,
|
|
10
|
+
} from "./runtime-ag-ui-contract.js";
|
|
11
|
+
import type { AgentResponse } from "./types.js";
|
|
12
|
+
|
|
13
|
+
export interface CreateAgUiRuntimeBrowserResponseInput<TChunk, TState> {
|
|
14
|
+
agUiInput: AgUiRuntimeRequest;
|
|
15
|
+
defaults?: {
|
|
16
|
+
threadId?: string;
|
|
17
|
+
runId?: string;
|
|
18
|
+
};
|
|
19
|
+
agentId: string;
|
|
20
|
+
execution: AgUiBrowserResponseExecution<TChunk>;
|
|
21
|
+
encoder: AgUiBrowserResponseEncoder<TChunk>;
|
|
22
|
+
initialState: TState;
|
|
23
|
+
onChunk?: (state: TState, chunk: TChunk) => void;
|
|
24
|
+
getFinalResponse?: (state: TState) => AgentResponse | null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function createAgUiRuntimeBrowserResponse<TChunk, TState>(
|
|
28
|
+
input: CreateAgUiRuntimeBrowserResponseInput<TChunk, TState>,
|
|
29
|
+
): Response {
|
|
30
|
+
const stream = createAgUiBrowserResponseStream({
|
|
31
|
+
agUiInput: normalizeAgUiBrowserRuntimeRequest(input.agUiInput, input.defaults),
|
|
32
|
+
agentId: input.agentId,
|
|
33
|
+
execution: input.execution,
|
|
34
|
+
encoder: input.encoder,
|
|
35
|
+
initialState: input.initialState,
|
|
36
|
+
...(input.onChunk ? { onChunk: input.onChunk } : {}),
|
|
37
|
+
...(input.getFinalResponse ? { getFinalResponse: input.getFinalResponse } : {}),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
return createAgUiSseResponse(stream);
|
|
41
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AgentResponse,
|
|
3
|
+
type AgUiBrowserEncodedEvent,
|
|
4
|
+
type AgUiBrowserEncoderState,
|
|
5
|
+
type AgUiBrowserRunFinishedMetadata,
|
|
6
|
+
type AgUiRuntimeStreamEvent,
|
|
7
|
+
createAgUiBrowserEncoderState,
|
|
8
|
+
finalizeAgUiBrowserEvents,
|
|
9
|
+
mapRuntimeStreamEventToAgUiBrowserEvents,
|
|
10
|
+
} from "./index.js";
|
|
11
|
+
|
|
12
|
+
export interface AgUiRuntimeEventEncoder {
|
|
13
|
+
state: AgUiBrowserEncoderState;
|
|
14
|
+
encode: (event: AgUiRuntimeStreamEvent) => AgUiBrowserEncodedEvent[];
|
|
15
|
+
finalize: (response: AgentResponse | null) => AgUiBrowserEncodedEvent[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface CreateAgUiRuntimeEventEncoderOptions {
|
|
19
|
+
initialMetadata?: Partial<AgUiBrowserRunFinishedMetadata>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function createAgUiRuntimeEventEncoder(
|
|
23
|
+
options: CreateAgUiRuntimeEventEncoderOptions = {},
|
|
24
|
+
): AgUiRuntimeEventEncoder {
|
|
25
|
+
const state = createAgUiBrowserEncoderState();
|
|
26
|
+
const toolInputs = new Map<string, unknown>();
|
|
27
|
+
|
|
28
|
+
Object.assign(state.metadata, options.initialMetadata ?? {});
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
state,
|
|
32
|
+
encode: (event) => {
|
|
33
|
+
if (
|
|
34
|
+
(event.type === "tool-input-available" || event.type === "tool-input-error") &&
|
|
35
|
+
typeof event.toolCallId === "string"
|
|
36
|
+
) {
|
|
37
|
+
toolInputs.set(event.toolCallId, event.input);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const encodedEvents = mapRuntimeStreamEventToAgUiBrowserEvents(state, event).map((next) => {
|
|
41
|
+
if (
|
|
42
|
+
next.event !== "ToolCallResult" ||
|
|
43
|
+
typeof next.payload.toolCallId !== "string" ||
|
|
44
|
+
!toolInputs.has(next.payload.toolCallId)
|
|
45
|
+
) {
|
|
46
|
+
return next;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
...next,
|
|
51
|
+
payload: {
|
|
52
|
+
...next.payload,
|
|
53
|
+
input: toolInputs.get(next.payload.toolCallId),
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
if (
|
|
59
|
+
(event.type === "tool-output-available" ||
|
|
60
|
+
event.type === "tool-output-error" ||
|
|
61
|
+
event.type === "tool-output-denied") &&
|
|
62
|
+
typeof event.toolCallId === "string"
|
|
63
|
+
) {
|
|
64
|
+
toolInputs.delete(event.toolCallId);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return encodedEvents;
|
|
68
|
+
},
|
|
69
|
+
finalize: (response) => finalizeAgUiBrowserEvents(state, response),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { AgUiBrowserEncodedEvent } from "./ag-ui-browser-encoder.js";
|
|
2
|
+
import type { AgUiBrowserFinalizeTracker } from "./ag-ui-browser-finalize-tracker.js";
|
|
3
|
+
import type { AgUiChunkEncoderBridge } from "./ag-ui-chunk-encoder-bridge.js";
|
|
4
|
+
import {
|
|
5
|
+
createAgUiRuntimeBrowserResponse,
|
|
6
|
+
type CreateAgUiRuntimeBrowserResponseInput,
|
|
7
|
+
} from "./ag-ui-runtime-browser-response.js";
|
|
8
|
+
import type { AgentResponse } from "./types.js";
|
|
9
|
+
|
|
10
|
+
export interface CreateAgUiTrackedBrowserResponseInput<TChunk> extends
|
|
11
|
+
Omit<
|
|
12
|
+
CreateAgUiRuntimeBrowserResponseInput<TChunk, null>,
|
|
13
|
+
"encoder" | "initialState" | "onChunk" | "getFinalResponse"
|
|
14
|
+
> {
|
|
15
|
+
chunkEncoder: Pick<AgUiChunkEncoderBridge<TChunk>, "encode" | "finalize">;
|
|
16
|
+
finalizeTracker: Pick<
|
|
17
|
+
AgUiBrowserFinalizeTracker<TChunk>,
|
|
18
|
+
"observeChunk" | "observeEncodedEvents" | "getFinalResponse"
|
|
19
|
+
>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function createAgUiTrackedBrowserResponse<TChunk>(
|
|
23
|
+
input: CreateAgUiTrackedBrowserResponseInput<TChunk>,
|
|
24
|
+
): Response {
|
|
25
|
+
return createAgUiRuntimeBrowserResponse({
|
|
26
|
+
...input,
|
|
27
|
+
encoder: {
|
|
28
|
+
encode: (chunk) => {
|
|
29
|
+
const events = input.chunkEncoder.encode(chunk);
|
|
30
|
+
input.finalizeTracker.observeEncodedEvents(events);
|
|
31
|
+
return events;
|
|
32
|
+
},
|
|
33
|
+
finalize: (response: AgentResponse | null): AgUiBrowserEncodedEvent[] =>
|
|
34
|
+
input.chunkEncoder.finalize(response),
|
|
35
|
+
},
|
|
36
|
+
initialState: null,
|
|
37
|
+
onChunk: (_state, chunk) => {
|
|
38
|
+
input.finalizeTracker.observeChunk(chunk);
|
|
39
|
+
},
|
|
40
|
+
getFinalResponse: () => input.finalizeTracker.getFinalResponse(),
|
|
41
|
+
});
|
|
42
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import * as dntShim from "../../_dnt.shims.js";
|
|
2
|
+
import { type HostedLifecycleExecution, runHostedLifecycle } from "./hosted-lifecycle.js";
|
|
3
|
+
|
|
4
|
+
export interface HostedResponseStreamWriter<TChunk> {
|
|
5
|
+
write: (chunk: TChunk) => void;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface HostedResponseStreamHeartbeatState {
|
|
9
|
+
heartbeatCount: number;
|
|
10
|
+
elapsedSeconds: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface HostedResponseStreamHeartbeat<TChunk> {
|
|
14
|
+
intervalMs?: number;
|
|
15
|
+
buildChunk: () => TChunk;
|
|
16
|
+
onBeat?: (state: HostedResponseStreamHeartbeatState) => void;
|
|
17
|
+
onStop?: (state: HostedResponseStreamHeartbeatState) => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface RunHostedResponseStreamWithHeartbeatOptions<TChunk> {
|
|
21
|
+
execution: HostedLifecycleExecution<TChunk>;
|
|
22
|
+
writer: HostedResponseStreamWriter<TChunk>;
|
|
23
|
+
heartbeat?: HostedResponseStreamHeartbeat<TChunk>;
|
|
24
|
+
runId?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function getHeartbeatState(
|
|
28
|
+
startedAt: number,
|
|
29
|
+
heartbeatCount: number,
|
|
30
|
+
): HostedResponseStreamHeartbeatState {
|
|
31
|
+
return {
|
|
32
|
+
heartbeatCount,
|
|
33
|
+
elapsedSeconds: Math.round((Date.now() - startedAt) / 1000),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function startHostedResponseStreamHeartbeat<TChunk>(input: {
|
|
38
|
+
writer: HostedResponseStreamWriter<TChunk>;
|
|
39
|
+
heartbeat: HostedResponseStreamHeartbeat<TChunk>;
|
|
40
|
+
}): { stop: () => void } {
|
|
41
|
+
const startedAt = Date.now();
|
|
42
|
+
let heartbeatCount = 0;
|
|
43
|
+
const interval = dntShim.setInterval(() => {
|
|
44
|
+
heartbeatCount += 1;
|
|
45
|
+
input.heartbeat.onBeat?.(getHeartbeatState(startedAt, heartbeatCount));
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
input.writer.write(input.heartbeat.buildChunk());
|
|
49
|
+
} catch {
|
|
50
|
+
clearInterval(interval);
|
|
51
|
+
}
|
|
52
|
+
}, input.heartbeat.intervalMs ?? 15_000);
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
stop: () => {
|
|
56
|
+
clearInterval(interval);
|
|
57
|
+
input.heartbeat.onStop?.(getHeartbeatState(startedAt, heartbeatCount));
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export async function runHostedResponseStreamWithHeartbeat<TChunk>(
|
|
63
|
+
options: RunHostedResponseStreamWithHeartbeatOptions<TChunk>,
|
|
64
|
+
): Promise<void> {
|
|
65
|
+
const heartbeat = options.heartbeat
|
|
66
|
+
? startHostedResponseStreamHeartbeat({
|
|
67
|
+
writer: options.writer,
|
|
68
|
+
heartbeat: options.heartbeat,
|
|
69
|
+
})
|
|
70
|
+
: null;
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
await runHostedLifecycle({
|
|
74
|
+
abortSignal: new AbortController().signal,
|
|
75
|
+
execution: options.execution,
|
|
76
|
+
adapter: {
|
|
77
|
+
startRun: () => ({ runId: options.runId ?? "response-stream" }),
|
|
78
|
+
appendEvents: (_run, chunk) => {
|
|
79
|
+
options.writer.write(chunk);
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
resolveTerminalState: () => ({ status: "completed" }),
|
|
83
|
+
});
|
|
84
|
+
} finally {
|
|
85
|
+
heartbeat?.stop();
|
|
86
|
+
}
|
|
87
|
+
}
|
package/src/src/agent/index.ts
CHANGED
|
@@ -159,6 +159,7 @@ export {
|
|
|
159
159
|
AgUiRuntimeMessageSchema,
|
|
160
160
|
type AgUiRuntimeRequest,
|
|
161
161
|
AgUiRuntimeRequestSchema,
|
|
162
|
+
normalizeAgUiBrowserRuntimeRequest,
|
|
162
163
|
parseAgUiRuntimeRequest,
|
|
163
164
|
parseAgUiRuntimeRequestOrError,
|
|
164
165
|
} from "./runtime-ag-ui-contract.js";
|
|
@@ -173,6 +174,21 @@ export {
|
|
|
173
174
|
finalizeAgUiBrowserEvents,
|
|
174
175
|
mapRuntimeStreamEventToAgUiBrowserEvents,
|
|
175
176
|
} from "./ag-ui-browser-encoder.js";
|
|
177
|
+
export {
|
|
178
|
+
type AgUiRuntimeEventEncoder,
|
|
179
|
+
createAgUiRuntimeEventEncoder,
|
|
180
|
+
type CreateAgUiRuntimeEventEncoderOptions,
|
|
181
|
+
} from "./ag-ui-runtime-event-encoder.js";
|
|
182
|
+
export {
|
|
183
|
+
type AgUiBrowserFinalizeTracker,
|
|
184
|
+
createAgUiBrowserFinalizeTracker,
|
|
185
|
+
type CreateAgUiBrowserFinalizeTrackerOptions,
|
|
186
|
+
} from "./ag-ui-browser-finalize-tracker.js";
|
|
187
|
+
export {
|
|
188
|
+
type AgUiChunkEncoderBridge,
|
|
189
|
+
createAgUiChunkEncoderBridge,
|
|
190
|
+
type CreateAgUiChunkEncoderBridgeOptions,
|
|
191
|
+
} from "./ag-ui-chunk-encoder-bridge.js";
|
|
176
192
|
export {
|
|
177
193
|
type AgUiBrowserResponseEncoder,
|
|
178
194
|
type AgUiBrowserResponseExecution,
|
|
@@ -180,6 +196,14 @@ export {
|
|
|
180
196
|
createAgUiBrowserResponseStream,
|
|
181
197
|
type CreateAgUiBrowserResponseStreamInput,
|
|
182
198
|
} from "./ag-ui-browser-response-stream.js";
|
|
199
|
+
export {
|
|
200
|
+
createAgUiRuntimeBrowserResponse,
|
|
201
|
+
type CreateAgUiRuntimeBrowserResponseInput,
|
|
202
|
+
} from "./ag-ui-runtime-browser-response.js";
|
|
203
|
+
export {
|
|
204
|
+
createAgUiTrackedBrowserResponse,
|
|
205
|
+
type CreateAgUiTrackedBrowserResponseInput,
|
|
206
|
+
} from "./ag-ui-tracked-browser-response.js";
|
|
183
207
|
export {
|
|
184
208
|
type ConversationRunContext,
|
|
185
209
|
createConversationRunContext,
|
|
@@ -330,6 +354,12 @@ export {
|
|
|
330
354
|
type HostedLifecycleTerminalState,
|
|
331
355
|
runHostedLifecycle,
|
|
332
356
|
} from "./hosted-lifecycle.js";
|
|
357
|
+
export {
|
|
358
|
+
type HostedResponseStreamHeartbeat,
|
|
359
|
+
type HostedResponseStreamHeartbeatState,
|
|
360
|
+
type HostedResponseStreamWriter,
|
|
361
|
+
runHostedResponseStreamWithHeartbeat,
|
|
362
|
+
} from "./hosted-response-stream.js";
|
|
333
363
|
export {
|
|
334
364
|
mergeToolCallInput,
|
|
335
365
|
mergeToolInputDelta,
|
|
@@ -365,6 +395,7 @@ export {
|
|
|
365
395
|
type AgUiSseEvent,
|
|
366
396
|
createAgUiRunErrorEvent,
|
|
367
397
|
createAgUiSseErrorResponse,
|
|
398
|
+
createAgUiSseResponse,
|
|
368
399
|
normalizeAgUiMessages,
|
|
369
400
|
parseAgUiRequest,
|
|
370
401
|
parseAgUiRequestOrError,
|
|
@@ -9,6 +9,10 @@ const MAX_RUNTIME_MESSAGES = 100;
|
|
|
9
9
|
|
|
10
10
|
const encoder = new TextEncoder();
|
|
11
11
|
|
|
12
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
13
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
14
|
+
}
|
|
15
|
+
|
|
12
16
|
function isWithinJsonSizeLimit(value: unknown, maxBytes: number): boolean {
|
|
13
17
|
try {
|
|
14
18
|
return encoder.encode(JSON.stringify(value)).byteLength <= maxBytes;
|
|
@@ -143,6 +147,24 @@ export type AgUiRuntimeContextItem = z.infer<typeof AgUiRuntimeContextItemSchema
|
|
|
143
147
|
export type AgUiRuntimeMessage = z.infer<typeof AgUiRuntimeMessageSchema>;
|
|
144
148
|
export type AgUiRuntimeRequest = z.infer<typeof AgUiRuntimeRequestSchema>;
|
|
145
149
|
|
|
150
|
+
export function normalizeAgUiBrowserRuntimeRequest(
|
|
151
|
+
input: AgUiRuntimeRequest,
|
|
152
|
+
defaults?: {
|
|
153
|
+
threadId?: string;
|
|
154
|
+
runId?: string;
|
|
155
|
+
},
|
|
156
|
+
): AgUiRuntimeRequest {
|
|
157
|
+
const { state, ...rest } = input;
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
...rest,
|
|
161
|
+
threadId: defaults?.threadId ?? input.threadId,
|
|
162
|
+
runId: defaults?.runId ?? input.runId,
|
|
163
|
+
messages: input.messages,
|
|
164
|
+
...(isRecord(state) ? { state } : {}),
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
146
168
|
export async function parseAgUiRuntimeRequest(request: Request): Promise<AgUiRuntimeRequest> {
|
|
147
169
|
return AgUiRuntimeRequestSchema.parse(await request.json());
|
|
148
170
|
}
|