veryfront 0.1.332 → 0.1.334
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/{framework-message-adapter.d.ts → agent-runtime-message-adapter.d.ts} +15 -15
- package/esm/src/agent/agent-runtime-message-adapter.d.ts.map +1 -0
- package/esm/src/agent/{framework-message-adapter.js → agent-runtime-message-adapter.js} +24 -24
- package/esm/src/agent/fork-runtime-stream.js +2 -2
- package/esm/src/agent/index.d.ts +1 -1
- package/esm/src/agent/index.d.ts.map +1 -1
- package/esm/src/agent/index.js +1 -1
- package/esm/src/chat/message-prep.d.ts +1 -0
- package/esm/src/chat/message-prep.d.ts.map +1 -1
- package/esm/src/chat/message-prep.js +1 -0
- package/esm/src/chat/types.d.ts +2 -1
- package/esm/src/chat/types.d.ts.map +1 -1
- package/esm/src/tool/host-tools.d.ts +18 -8
- package/esm/src/tool/host-tools.d.ts.map +1 -1
- package/esm/src/tool/index.d.ts +2 -2
- package/esm/src/tool/index.d.ts.map +1 -1
- package/esm/src/tool/types.d.ts +7 -0
- package/esm/src/tool/types.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/deno.js +1 -1
- 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/{framework-message-adapter.ts → agent-runtime-message-adapter.ts} +58 -54
- package/src/src/agent/fork-runtime-stream.ts +2 -2
- package/src/src/agent/index.ts +9 -9
- package/src/src/chat/message-prep.ts +2 -0
- package/src/src/chat/types.ts +3 -1
- package/src/src/tool/host-tools.ts +34 -9
- package/src/src/tool/index.ts +6 -1
- package/src/src/tool/types.ts +8 -0
- package/src/src/utils/version-constant.ts +1 -1
- package/esm/src/agent/framework-message-adapter.d.ts.map +0 -1
|
@@ -16,7 +16,6 @@ type NativeKeyboardEvent = KeyboardEvent;
|
|
|
16
16
|
type NativeMouseEvent = MouseEvent;
|
|
17
17
|
type NativeTouchEvent = TouchEvent;
|
|
18
18
|
type NativePointerEvent = PointerEvent;
|
|
19
|
-
type NativeSubmitEvent = SubmitEvent;
|
|
20
19
|
type NativeToggleEvent = ToggleEvent;
|
|
21
20
|
type NativeTransitionEvent = TransitionEvent;
|
|
22
21
|
type NativeUIEvent = UIEvent;
|
|
@@ -226,20 +225,12 @@ declare namespace React {
|
|
|
226
225
|
|
|
227
226
|
type ComponentState = any;
|
|
228
227
|
|
|
229
|
-
interface DO_NOT_USE_OR_YOU_WILL_BE_FIRED_EXPERIMENTAL_KEY_TYPES {}
|
|
230
|
-
|
|
231
228
|
/**
|
|
232
229
|
* A value which uniquely identifies a node among items in an array.
|
|
233
230
|
*
|
|
234
231
|
* @see {@link https://react.dev/learn/rendering-lists#keeping-list-items-in-order-with-key React Docs}
|
|
235
232
|
*/
|
|
236
|
-
type Key =
|
|
237
|
-
| string
|
|
238
|
-
| number
|
|
239
|
-
| bigint
|
|
240
|
-
| DO_NOT_USE_OR_YOU_WILL_BE_FIRED_EXPERIMENTAL_KEY_TYPES[
|
|
241
|
-
keyof DO_NOT_USE_OR_YOU_WILL_BE_FIRED_EXPERIMENTAL_KEY_TYPES
|
|
242
|
-
];
|
|
233
|
+
type Key = string | number | bigint;
|
|
243
234
|
|
|
244
235
|
/**
|
|
245
236
|
* @internal The props any component can receive.
|
|
@@ -1893,7 +1884,7 @@ declare namespace React {
|
|
|
1893
1884
|
*
|
|
1894
1885
|
* @param callback A synchronous, void callback that will execute as a single, complete React commit.
|
|
1895
1886
|
*
|
|
1896
|
-
* @see
|
|
1887
|
+
* @see https://reactjs.org/blog/2019/02/06/react-v16.8.0.html#testing-hooks
|
|
1897
1888
|
*/
|
|
1898
1889
|
// NOTES
|
|
1899
1890
|
// - the order of these signatures matters - typescript will check the signatures in source order.
|
|
@@ -1935,31 +1926,7 @@ declare namespace React {
|
|
|
1935
1926
|
reducer: (state: State, action: Action) => State,
|
|
1936
1927
|
): [State, (action: Action) => void];
|
|
1937
1928
|
|
|
1938
|
-
|
|
1939
|
-
status?: void;
|
|
1940
|
-
}
|
|
1941
|
-
|
|
1942
|
-
export interface PendingReactPromise<T> extends PromiseLike<T> {
|
|
1943
|
-
status: "pending";
|
|
1944
|
-
}
|
|
1945
|
-
|
|
1946
|
-
export interface FulfilledReactPromise<T> extends PromiseLike<T> {
|
|
1947
|
-
status: "fulfilled";
|
|
1948
|
-
value: T;
|
|
1949
|
-
}
|
|
1950
|
-
|
|
1951
|
-
export interface RejectedReactPromise<T> extends PromiseLike<T> {
|
|
1952
|
-
status: "rejected";
|
|
1953
|
-
reason: unknown;
|
|
1954
|
-
}
|
|
1955
|
-
|
|
1956
|
-
export type ReactPromise<T> =
|
|
1957
|
-
| UntrackedReactPromise<T>
|
|
1958
|
-
| PendingReactPromise<T>
|
|
1959
|
-
| FulfilledReactPromise<T>
|
|
1960
|
-
| RejectedReactPromise<T>;
|
|
1961
|
-
|
|
1962
|
-
export type Usable<T> = ReactPromise<T> | Context<T>;
|
|
1929
|
+
export type Usable<T> = PromiseLike<T> | Context<T>;
|
|
1963
1930
|
|
|
1964
1931
|
export function use<T>(usable: Usable<T>): T;
|
|
1965
1932
|
|
|
@@ -2074,28 +2041,15 @@ declare namespace React {
|
|
|
2074
2041
|
target: EventTarget & Target;
|
|
2075
2042
|
}
|
|
2076
2043
|
|
|
2077
|
-
/**
|
|
2078
|
-
* @deprecated FormEvent doesn't actually exist.
|
|
2079
|
-
* You probably meant to use {@link ChangeEvent}, {@link InputEvent}, {@link SubmitEvent}, or just {@link SyntheticEvent} instead
|
|
2080
|
-
* depending on the event type.
|
|
2081
|
-
*/
|
|
2082
2044
|
interface FormEvent<T = Element> extends SyntheticEvent<T> {
|
|
2083
2045
|
}
|
|
2084
2046
|
|
|
2085
2047
|
interface InvalidEvent<T = Element> extends SyntheticEvent<T> {
|
|
2048
|
+
target: EventTarget & T;
|
|
2086
2049
|
}
|
|
2087
2050
|
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
* Only for form elements we know their target type because form events can't
|
|
2091
|
-
* be nested.
|
|
2092
|
-
* This type exists purely to narrow `target` for form elements. It doesn't
|
|
2093
|
-
* reflect a DOM event. Change events are just fired as standard {@link SyntheticEvent}.
|
|
2094
|
-
*/
|
|
2095
|
-
interface ChangeEvent<CurrentTarget = Element, Target = Element> extends SyntheticEvent<CurrentTarget> {
|
|
2096
|
-
// TODO: This is wrong for change event handlers on arbitrary. Should
|
|
2097
|
-
// be EventTarget & Target, but kept for backward compatibility until React 20.
|
|
2098
|
-
target: EventTarget & CurrentTarget;
|
|
2051
|
+
interface ChangeEvent<T = Element> extends SyntheticEvent<T> {
|
|
2052
|
+
target: EventTarget & T;
|
|
2099
2053
|
}
|
|
2100
2054
|
|
|
2101
2055
|
interface InputEvent<T = Element> extends SyntheticEvent<T, NativeInputEvent> {
|
|
@@ -2165,13 +2119,6 @@ declare namespace React {
|
|
|
2165
2119
|
shiftKey: boolean;
|
|
2166
2120
|
}
|
|
2167
2121
|
|
|
2168
|
-
interface SubmitEvent<T = Element> extends SyntheticEvent<T, NativeSubmitEvent> {
|
|
2169
|
-
// `submitter` is available in react@canary
|
|
2170
|
-
// submitter: HTMLElement | null;
|
|
2171
|
-
// SubmitEvents are always targetted at HTMLFormElements.
|
|
2172
|
-
target: EventTarget & HTMLFormElement;
|
|
2173
|
-
}
|
|
2174
|
-
|
|
2175
2122
|
interface TouchEvent<T = Element> extends UIEvent<T, NativeTouchEvent> {
|
|
2176
2123
|
altKey: boolean;
|
|
2177
2124
|
changedTouches: TouchList;
|
|
@@ -2227,19 +2174,11 @@ declare namespace React {
|
|
|
2227
2174
|
type CompositionEventHandler<T = Element> = EventHandler<CompositionEvent<T>>;
|
|
2228
2175
|
type DragEventHandler<T = Element> = EventHandler<DragEvent<T>>;
|
|
2229
2176
|
type FocusEventHandler<T = Element> = EventHandler<FocusEvent<T>>;
|
|
2230
|
-
/**
|
|
2231
|
-
* @deprecated FormEventHandler doesn't actually exist.
|
|
2232
|
-
* You probably meant to use {@link ChangeEventHandler}, {@link InputEventHandler}, {@link SubmitEventHandler}, or just {@link EventHandler} instead
|
|
2233
|
-
* depending on the event type.
|
|
2234
|
-
*/
|
|
2235
2177
|
type FormEventHandler<T = Element> = EventHandler<FormEvent<T>>;
|
|
2236
|
-
type ChangeEventHandler<
|
|
2237
|
-
ChangeEvent<CurrentTarget, Target>
|
|
2238
|
-
>;
|
|
2178
|
+
type ChangeEventHandler<T = Element> = EventHandler<ChangeEvent<T>>;
|
|
2239
2179
|
type InputEventHandler<T = Element> = EventHandler<InputEvent<T>>;
|
|
2240
2180
|
type KeyboardEventHandler<T = Element> = EventHandler<KeyboardEvent<T>>;
|
|
2241
2181
|
type MouseEventHandler<T = Element> = EventHandler<MouseEvent<T>>;
|
|
2242
|
-
type SubmitEventHandler<T = Element> = EventHandler<SubmitEvent<T>>;
|
|
2243
2182
|
type TouchEventHandler<T = Element> = EventHandler<TouchEvent<T>>;
|
|
2244
2183
|
type PointerEventHandler<T = Element> = EventHandler<PointerEvent<T>>;
|
|
2245
2184
|
type UIEventHandler<T = Element> = EventHandler<UIEvent<T>>;
|
|
@@ -2293,19 +2232,19 @@ declare namespace React {
|
|
|
2293
2232
|
onBlur?: FocusEventHandler<T> | undefined;
|
|
2294
2233
|
onBlurCapture?: FocusEventHandler<T> | undefined;
|
|
2295
2234
|
|
|
2296
|
-
//
|
|
2297
|
-
onChange?:
|
|
2298
|
-
onChangeCapture?:
|
|
2235
|
+
// Form Events
|
|
2236
|
+
onChange?: FormEventHandler<T> | undefined;
|
|
2237
|
+
onChangeCapture?: FormEventHandler<T> | undefined;
|
|
2299
2238
|
onBeforeInput?: InputEventHandler<T> | undefined;
|
|
2300
|
-
onBeforeInputCapture?:
|
|
2301
|
-
onInput?:
|
|
2302
|
-
onInputCapture?:
|
|
2303
|
-
onReset?:
|
|
2304
|
-
onResetCapture?:
|
|
2305
|
-
onSubmit?:
|
|
2306
|
-
onSubmitCapture?:
|
|
2307
|
-
onInvalid?:
|
|
2308
|
-
onInvalidCapture?:
|
|
2239
|
+
onBeforeInputCapture?: FormEventHandler<T> | undefined;
|
|
2240
|
+
onInput?: FormEventHandler<T> | undefined;
|
|
2241
|
+
onInputCapture?: FormEventHandler<T> | undefined;
|
|
2242
|
+
onReset?: FormEventHandler<T> | undefined;
|
|
2243
|
+
onResetCapture?: FormEventHandler<T> | undefined;
|
|
2244
|
+
onSubmit?: FormEventHandler<T> | undefined;
|
|
2245
|
+
onSubmitCapture?: FormEventHandler<T> | undefined;
|
|
2246
|
+
onInvalid?: FormEventHandler<T> | undefined;
|
|
2247
|
+
onInvalidCapture?: FormEventHandler<T> | undefined;
|
|
2309
2248
|
|
|
2310
2249
|
// Image Events
|
|
2311
2250
|
onLoad?: ReactEventHandler<T> | undefined;
|
|
@@ -2849,7 +2788,7 @@ declare namespace React {
|
|
|
2849
2788
|
|
|
2850
2789
|
// Living Standard
|
|
2851
2790
|
/**
|
|
2852
|
-
* @see
|
|
2791
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/inert
|
|
2853
2792
|
*/
|
|
2854
2793
|
inert?: boolean | undefined;
|
|
2855
2794
|
/**
|
|
@@ -3312,9 +3251,7 @@ declare namespace React {
|
|
|
3312
3251
|
value?: string | readonly string[] | number | undefined;
|
|
3313
3252
|
width?: number | string | undefined;
|
|
3314
3253
|
|
|
3315
|
-
|
|
3316
|
-
// so we know the target will be a HTMLInputElement.
|
|
3317
|
-
onChange?: ChangeEventHandler<T, HTMLInputElement> | undefined;
|
|
3254
|
+
onChange?: ChangeEventHandler<T> | undefined;
|
|
3318
3255
|
}
|
|
3319
3256
|
|
|
3320
3257
|
interface KeygenHTMLAttributes<T> extends HTMLAttributes<T> {
|
|
@@ -3479,9 +3416,7 @@ declare namespace React {
|
|
|
3479
3416
|
required?: boolean | undefined;
|
|
3480
3417
|
size?: number | undefined;
|
|
3481
3418
|
value?: string | readonly string[] | number | undefined;
|
|
3482
|
-
|
|
3483
|
-
// so we know the target will be a HTMLSelectElement.
|
|
3484
|
-
onChange?: ChangeEventHandler<T, HTMLSelectElement> | undefined;
|
|
3419
|
+
onChange?: ChangeEventHandler<T> | undefined;
|
|
3485
3420
|
}
|
|
3486
3421
|
|
|
3487
3422
|
interface SourceHTMLAttributes<T> extends HTMLAttributes<T> {
|
|
@@ -3533,9 +3468,7 @@ declare namespace React {
|
|
|
3533
3468
|
value?: string | readonly string[] | number | undefined;
|
|
3534
3469
|
wrap?: string | undefined;
|
|
3535
3470
|
|
|
3536
|
-
|
|
3537
|
-
// so we know the target will be a HTMLTextAreaElement.
|
|
3538
|
-
onChange?: ChangeEventHandler<T, HTMLTextAreaElement> | undefined;
|
|
3471
|
+
onChange?: ChangeEventHandler<T> | undefined;
|
|
3539
3472
|
}
|
|
3540
3473
|
|
|
3541
3474
|
interface TdHTMLAttributes<T> extends HTMLAttributes<T> {
|
|
@@ -3607,9 +3540,6 @@ declare namespace React {
|
|
|
3607
3540
|
method?: string | undefined;
|
|
3608
3541
|
min?: number | string | undefined;
|
|
3609
3542
|
name?: string | undefined;
|
|
3610
|
-
nonce?: string | undefined;
|
|
3611
|
-
part?: string | undefined;
|
|
3612
|
-
slot?: string | undefined;
|
|
3613
3543
|
style?: CSSProperties | undefined;
|
|
3614
3544
|
target?: string | undefined;
|
|
3615
3545
|
type?: string | undefined;
|
|
@@ -4127,6 +4057,7 @@ declare namespace React {
|
|
|
4127
4057
|
* Captures which component contained the exception, and its ancestors.
|
|
4128
4058
|
*/
|
|
4129
4059
|
componentStack?: string | null;
|
|
4060
|
+
digest?: string | null;
|
|
4130
4061
|
}
|
|
4131
4062
|
|
|
4132
4063
|
// Keep in sync with JSX namespace in ./jsx-runtime.d.ts and ./jsx-dev-runtime.d.ts
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
// See https://github.com/facebook/react/blob/main/packages/react-dom/client.js to see how the exports are declared,
|
|
6
6
|
|
|
7
|
-
import React = require("https://esm.sh/@types/react@19.2.
|
|
7
|
+
import React = require("https://esm.sh/@types/react@19.2.3/index.d.ts");
|
|
8
8
|
|
|
9
9
|
export {};
|
|
10
10
|
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { isRecord } from "../chat/conversation.js";
|
|
2
2
|
import {
|
|
3
3
|
buildDataFileAnnotation,
|
|
4
|
-
type ChatModelMessage,
|
|
5
4
|
type ChatToolResultPart,
|
|
5
|
+
type ProviderModelMessage,
|
|
6
6
|
type UploadedFileReference,
|
|
7
7
|
} from "../chat/types.js";
|
|
8
8
|
import { toChildRunToolInputRecord } from "./child-run-execution-support.js";
|
|
9
9
|
|
|
10
|
-
type
|
|
10
|
+
type StructuredProviderPart = Exclude<ProviderModelMessage["content"], string>[number];
|
|
11
11
|
|
|
12
12
|
type JsonValue = string | number | boolean | null | JsonValue[] | { [key: string]: JsonValue };
|
|
13
13
|
|
|
14
|
-
type
|
|
14
|
+
type AgentRuntimeMessageLikePart =
|
|
15
15
|
| { type: "text"; text: string }
|
|
16
16
|
| {
|
|
17
17
|
type: string;
|
|
@@ -38,7 +38,7 @@ type FrameworkMessageLikePart =
|
|
|
38
38
|
output: unknown;
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
export type
|
|
41
|
+
export type AgentRuntimeMessagePart =
|
|
42
42
|
| { type: "text"; text: string }
|
|
43
43
|
| {
|
|
44
44
|
type: string;
|
|
@@ -53,32 +53,32 @@ export type FrameworkMessagePart =
|
|
|
53
53
|
result: unknown;
|
|
54
54
|
};
|
|
55
55
|
|
|
56
|
-
export interface
|
|
56
|
+
export interface AgentRuntimeMessage {
|
|
57
57
|
id: string;
|
|
58
|
-
role:
|
|
59
|
-
parts:
|
|
58
|
+
role: ProviderModelMessage["role"];
|
|
59
|
+
parts: AgentRuntimeMessagePart[];
|
|
60
60
|
timestamp: number;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
interface
|
|
64
|
-
textParts:
|
|
65
|
-
toolCallParts:
|
|
63
|
+
interface AgentRuntimeProviderContentParts {
|
|
64
|
+
textParts: ProviderTextPart[];
|
|
65
|
+
toolCallParts: ProviderToolCallPart[];
|
|
66
66
|
toolResultParts: ChatToolResultPart[];
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
type
|
|
69
|
+
type ProviderTextPart = { type: "text"; text: string };
|
|
70
70
|
|
|
71
|
-
type
|
|
71
|
+
type ProviderToolCallPart = {
|
|
72
72
|
type: "tool-call";
|
|
73
73
|
toolCallId: string;
|
|
74
74
|
toolName: string;
|
|
75
75
|
input: Record<string, unknown>;
|
|
76
76
|
};
|
|
77
77
|
|
|
78
|
-
export class
|
|
78
|
+
export class AgentRuntimeMessageConversionError extends Error {
|
|
79
79
|
constructor(message: string) {
|
|
80
80
|
super(message);
|
|
81
|
-
this.name = "
|
|
81
|
+
this.name = "AgentRuntimeMessageConversionError";
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
|
|
@@ -95,18 +95,18 @@ function getOptionalStringField(part: unknown, key: string): string | undefined
|
|
|
95
95
|
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
function
|
|
99
|
-
return `
|
|
98
|
+
function createAgentRuntimeMessageId(message: ProviderModelMessage, index: number): string {
|
|
99
|
+
return `agent-runtime-${message.role}-${index + 1}`;
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
function
|
|
102
|
+
function createTextAgentRuntimePart(text: string): AgentRuntimeMessagePart | null {
|
|
103
103
|
return hasTextContent(text) ? { type: "text", text } : null;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
function convertStructuredPart(part:
|
|
106
|
+
function convertStructuredPart(part: StructuredProviderPart): AgentRuntimeMessagePart | null {
|
|
107
107
|
switch (part.type) {
|
|
108
108
|
case "text":
|
|
109
|
-
return
|
|
109
|
+
return createTextAgentRuntimePart(part.text);
|
|
110
110
|
|
|
111
111
|
case "reasoning":
|
|
112
112
|
return null;
|
|
@@ -133,14 +133,14 @@ function convertStructuredPart(part: StructuredModelPart): FrameworkMessagePart
|
|
|
133
133
|
|
|
134
134
|
default: {
|
|
135
135
|
const exhaustiveCheck: never = part;
|
|
136
|
-
throw new
|
|
137
|
-
`Unsupported
|
|
136
|
+
throw new AgentRuntimeMessageConversionError(
|
|
137
|
+
`Unsupported agent runtime message part: ${String(exhaustiveCheck)}`,
|
|
138
138
|
);
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
function createAttachmentReference(part:
|
|
143
|
+
function createAttachmentReference(part: StructuredProviderPart): UploadedFileReference | null {
|
|
144
144
|
const filename = getOptionalStringField(part, "filename");
|
|
145
145
|
const mediaType = getOptionalStringField(part, "mediaType");
|
|
146
146
|
const uploadId = getOptionalStringField(part, "uploadId");
|
|
@@ -164,7 +164,7 @@ function createAttachmentReference(part: StructuredModelPart): UploadedFileRefer
|
|
|
164
164
|
|
|
165
165
|
function buildAttachmentContextPart(
|
|
166
166
|
attachmentReferences: UploadedFileReference[],
|
|
167
|
-
):
|
|
167
|
+
): AgentRuntimeMessagePart | null {
|
|
168
168
|
if (attachmentReferences.length === 0) {
|
|
169
169
|
return null;
|
|
170
170
|
}
|
|
@@ -177,13 +177,15 @@ function buildAttachmentContextPart(
|
|
|
177
177
|
};
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
-
function
|
|
180
|
+
function convertContentToAgentRuntimeParts(
|
|
181
|
+
message: ProviderModelMessage,
|
|
182
|
+
): AgentRuntimeMessage["parts"] {
|
|
181
183
|
if (typeof message.content === "string") {
|
|
182
|
-
const textPart =
|
|
184
|
+
const textPart = createTextAgentRuntimePart(message.content);
|
|
183
185
|
return textPart ? [textPart] : [];
|
|
184
186
|
}
|
|
185
187
|
|
|
186
|
-
const parts:
|
|
188
|
+
const parts: AgentRuntimeMessage["parts"] = [];
|
|
187
189
|
const attachmentReferences: UploadedFileReference[] = [];
|
|
188
190
|
|
|
189
191
|
for (const part of message.content) {
|
|
@@ -238,13 +240,13 @@ function toToolResultOutput(value: unknown): { type: "json"; value: JsonValue }
|
|
|
238
240
|
};
|
|
239
241
|
}
|
|
240
242
|
|
|
241
|
-
export function
|
|
243
|
+
export function getAgentRuntimeTextPart(part: unknown): { type: "text"; text: string } | null {
|
|
242
244
|
return isRecord(part) && part.type === "text" && typeof part.text === "string"
|
|
243
245
|
? { type: "text", text: part.text }
|
|
244
246
|
: null;
|
|
245
247
|
}
|
|
246
248
|
|
|
247
|
-
export function
|
|
249
|
+
export function getAgentRuntimeToolCallPart(
|
|
248
250
|
part: unknown,
|
|
249
251
|
): { toolCallId: string; toolName: string; input: Record<string, unknown> } | null {
|
|
250
252
|
if (!isRecord(part) || typeof part.type !== "string") {
|
|
@@ -268,7 +270,7 @@ export function getFrameworkToolCallPart(
|
|
|
268
270
|
};
|
|
269
271
|
}
|
|
270
272
|
|
|
271
|
-
export function
|
|
273
|
+
export function getAgentRuntimeToolResultPart(
|
|
272
274
|
part: unknown,
|
|
273
275
|
): { toolCallId: string; toolName: string; output: unknown } | null {
|
|
274
276
|
if (!isRecord(part) || part.type !== "tool-result") {
|
|
@@ -301,31 +303,31 @@ export function createToolResultPart(part: {
|
|
|
301
303
|
};
|
|
302
304
|
}
|
|
303
305
|
|
|
304
|
-
function joinTextParts(textParts: readonly
|
|
306
|
+
function joinTextParts(textParts: readonly ProviderTextPart[]): string {
|
|
305
307
|
return textParts.map((part) => part.text).join("\n\n");
|
|
306
308
|
}
|
|
307
309
|
|
|
308
|
-
function
|
|
309
|
-
parts: ReadonlyArray<
|
|
310
|
-
):
|
|
311
|
-
const textParts:
|
|
312
|
-
const toolCallParts:
|
|
310
|
+
function collectAgentRuntimeProviderContentParts(
|
|
311
|
+
parts: ReadonlyArray<AgentRuntimeMessageLikePart>,
|
|
312
|
+
): AgentRuntimeProviderContentParts {
|
|
313
|
+
const textParts: ProviderTextPart[] = [];
|
|
314
|
+
const toolCallParts: ProviderToolCallPart[] = [];
|
|
313
315
|
const toolResultParts: ChatToolResultPart[] = [];
|
|
314
316
|
|
|
315
317
|
for (const part of parts) {
|
|
316
|
-
const textPart =
|
|
318
|
+
const textPart = getAgentRuntimeTextPart(part);
|
|
317
319
|
if (textPart) {
|
|
318
320
|
textParts.push(textPart);
|
|
319
321
|
continue;
|
|
320
322
|
}
|
|
321
323
|
|
|
322
|
-
const toolResultPart =
|
|
324
|
+
const toolResultPart = getAgentRuntimeToolResultPart(part);
|
|
323
325
|
if (toolResultPart) {
|
|
324
326
|
toolResultParts.push(createToolResultPart(toolResultPart));
|
|
325
327
|
continue;
|
|
326
328
|
}
|
|
327
329
|
|
|
328
|
-
const toolCallPart =
|
|
330
|
+
const toolCallPart = getAgentRuntimeToolCallPart(part);
|
|
329
331
|
if (toolCallPart) {
|
|
330
332
|
toolCallParts.push({
|
|
331
333
|
type: "tool-call",
|
|
@@ -339,10 +341,12 @@ function collectFrameworkModelContentParts(
|
|
|
339
341
|
return { textParts, toolCallParts, toolResultParts };
|
|
340
342
|
}
|
|
341
343
|
|
|
342
|
-
function
|
|
343
|
-
message: Pick<
|
|
344
|
-
|
|
345
|
-
|
|
344
|
+
function createProviderMessageFromAgentRuntimeMessage(
|
|
345
|
+
message: Pick<AgentRuntimeMessage, "role"> & {
|
|
346
|
+
parts: ReadonlyArray<AgentRuntimeMessageLikePart>;
|
|
347
|
+
},
|
|
348
|
+
): ProviderModelMessage | null {
|
|
349
|
+
const { textParts, toolCallParts, toolResultParts } = collectAgentRuntimeProviderContentParts(
|
|
346
350
|
message.parts,
|
|
347
351
|
);
|
|
348
352
|
|
|
@@ -391,8 +395,8 @@ function createModelMessageFromFrameworkMessage(
|
|
|
391
395
|
|
|
392
396
|
default: {
|
|
393
397
|
const exhaustiveCheck: never = message.role;
|
|
394
|
-
throw new
|
|
395
|
-
`Unsupported
|
|
398
|
+
throw new AgentRuntimeMessageConversionError(
|
|
399
|
+
`Unsupported agent runtime message role when converting to provider model message: ${
|
|
396
400
|
String(exhaustiveCheck)
|
|
397
401
|
}`,
|
|
398
402
|
);
|
|
@@ -400,26 +404,26 @@ function createModelMessageFromFrameworkMessage(
|
|
|
400
404
|
}
|
|
401
405
|
}
|
|
402
406
|
|
|
403
|
-
export function
|
|
404
|
-
messages: readonly
|
|
405
|
-
):
|
|
407
|
+
export function convertProviderMessagesToAgentRuntimeMessages(
|
|
408
|
+
messages: readonly ProviderModelMessage[],
|
|
409
|
+
): AgentRuntimeMessage[] {
|
|
406
410
|
return messages.map((message, index) => ({
|
|
407
|
-
id:
|
|
411
|
+
id: createAgentRuntimeMessageId(message, index),
|
|
408
412
|
role: message.role,
|
|
409
|
-
parts:
|
|
413
|
+
parts: convertContentToAgentRuntimeParts(message),
|
|
410
414
|
timestamp: index,
|
|
411
415
|
}));
|
|
412
416
|
}
|
|
413
417
|
|
|
414
|
-
export function
|
|
418
|
+
export function convertAgentRuntimeMessagesToProviderMessages(
|
|
415
419
|
messages: ReadonlyArray<
|
|
416
|
-
Pick<
|
|
420
|
+
Pick<AgentRuntimeMessage, "role"> & { parts: ReadonlyArray<AgentRuntimeMessageLikePart> }
|
|
417
421
|
>,
|
|
418
|
-
):
|
|
419
|
-
const converted:
|
|
422
|
+
): ProviderModelMessage[] {
|
|
423
|
+
const converted: ProviderModelMessage[] = [];
|
|
420
424
|
|
|
421
425
|
for (const message of messages) {
|
|
422
|
-
const convertedMessage =
|
|
426
|
+
const convertedMessage = createProviderMessageFromAgentRuntimeMessage(message);
|
|
423
427
|
if (convertedMessage) {
|
|
424
428
|
converted.push(convertedMessage);
|
|
425
429
|
}
|
|
@@ -472,7 +472,7 @@ export function applyPartToStreamedStepState(state: StreamedStepState, part: For
|
|
|
472
472
|
}
|
|
473
473
|
}
|
|
474
474
|
|
|
475
|
-
function
|
|
475
|
+
function buildFallbackAgentRuntimeMessages(
|
|
476
476
|
baseMessages: readonly AgentMessage[],
|
|
477
477
|
state: StreamedStepState,
|
|
478
478
|
): AgentMessage[] {
|
|
@@ -561,7 +561,7 @@ function buildFallbackAgentResponse(input: {
|
|
|
561
561
|
}): AgentResponse {
|
|
562
562
|
return {
|
|
563
563
|
text: input.state.text,
|
|
564
|
-
messages:
|
|
564
|
+
messages: buildFallbackAgentRuntimeMessages(input.baseMessages, input.state),
|
|
565
565
|
toolCalls: [...input.state.toolCalls.values()].map((toolCall) => ({
|
|
566
566
|
id: toolCall.toolCallId,
|
|
567
567
|
name: toolCall.toolName,
|
package/src/src/agent/index.ts
CHANGED
|
@@ -365,16 +365,16 @@ export {
|
|
|
365
365
|
toChildRunToolInputRecord,
|
|
366
366
|
} from "./child-run-execution-support.js";
|
|
367
367
|
export {
|
|
368
|
-
|
|
369
|
-
|
|
368
|
+
type AgentRuntimeMessage,
|
|
369
|
+
AgentRuntimeMessageConversionError,
|
|
370
|
+
type AgentRuntimeMessagePart,
|
|
371
|
+
convertAgentRuntimeMessagesToProviderMessages,
|
|
372
|
+
convertProviderMessagesToAgentRuntimeMessages,
|
|
370
373
|
createToolResultPart,
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
getFrameworkToolCallPart,
|
|
376
|
-
getFrameworkToolResultPart,
|
|
377
|
-
} from "./framework-message-adapter.js";
|
|
374
|
+
getAgentRuntimeTextPart,
|
|
375
|
+
getAgentRuntimeToolCallPart,
|
|
376
|
+
getAgentRuntimeToolResultPart,
|
|
377
|
+
} from "./agent-runtime-message-adapter.js";
|
|
378
378
|
export {
|
|
379
379
|
type ChildRunExecutionBufferCleanupInput,
|
|
380
380
|
type ChildRunExecutionResourceFinalizeInput,
|
package/src/src/chat/types.ts
CHANGED
|
@@ -245,12 +245,14 @@ export type ChatToolMessage = {
|
|
|
245
245
|
content: ChatToolResultPart[];
|
|
246
246
|
};
|
|
247
247
|
|
|
248
|
-
export type
|
|
248
|
+
export type ProviderModelMessage =
|
|
249
249
|
| ChatSystemMessage
|
|
250
250
|
| ChatUserMessage
|
|
251
251
|
| ChatAssistantMessage
|
|
252
252
|
| ChatToolMessage;
|
|
253
253
|
|
|
254
|
+
export type ChatModelMessage = ProviderModelMessage;
|
|
255
|
+
|
|
254
256
|
export interface DurableRootRunDescriptor {
|
|
255
257
|
runId: string;
|
|
256
258
|
messageId: string;
|
|
@@ -2,15 +2,32 @@ import * as dntShim from "../../_dnt.shims.js";
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { dynamicTool, tool } from "./factory.js";
|
|
4
4
|
import type { JsonSchema } from "./schema/json-schema.js";
|
|
5
|
-
import type { Tool, ToolConfig, ToolExecutionContext } from "./types.js";
|
|
5
|
+
import type { Tool, ToolConfig, ToolExecutionContext, ToolSet } from "./types.js";
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
type HostToolExecute = {
|
|
8
|
+
bivarianceHack: (input: unknown, options?: ToolExecutionContext) => Promise<unknown> | unknown;
|
|
9
|
+
}["bivarianceHack"];
|
|
10
|
+
|
|
11
|
+
export type HostToolDefinition = {
|
|
12
|
+
id?: string;
|
|
13
|
+
type?: Tool["type"];
|
|
14
|
+
title?: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
inputSchema?: unknown;
|
|
10
17
|
inputSchemaJson?: JsonSchema;
|
|
11
|
-
|
|
18
|
+
parameters?: unknown;
|
|
19
|
+
providerOptions?: unknown;
|
|
20
|
+
execute?: Tool["execute"] | HostToolExecute;
|
|
12
21
|
mcp?: ToolConfig["mcp"];
|
|
13
|
-
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type HostToolSet = Record<string, HostToolDefinition>;
|
|
25
|
+
|
|
26
|
+
type RunnableHostToolDefinition = HostToolDefinition & {
|
|
27
|
+
description: string;
|
|
28
|
+
inputSchema: z.ZodSchema<unknown>;
|
|
29
|
+
execute: HostToolExecute;
|
|
30
|
+
};
|
|
14
31
|
|
|
15
32
|
export interface HostToolMaterializationOptions {
|
|
16
33
|
generateToolCallId?: (toolName: string) => string;
|
|
@@ -26,7 +43,7 @@ function isZodSchema(value: unknown): value is z.ZodSchema<unknown> {
|
|
|
26
43
|
return typeof value._def.typeName === "string" || typeof value._def.type === "string";
|
|
27
44
|
}
|
|
28
45
|
|
|
29
|
-
function isHostToolDefinition(value: unknown): value is
|
|
46
|
+
function isHostToolDefinition(value: unknown): value is RunnableHostToolDefinition {
|
|
30
47
|
return (
|
|
31
48
|
isRecord(value) &&
|
|
32
49
|
typeof value.description === "string" &&
|
|
@@ -54,11 +71,19 @@ function normalizeExecutionContext(
|
|
|
54
71
|
};
|
|
55
72
|
}
|
|
56
73
|
|
|
74
|
+
export function createToolsFromHostDefinitions(
|
|
75
|
+
definitions: HostToolSet,
|
|
76
|
+
options?: HostToolMaterializationOptions,
|
|
77
|
+
): ToolSet;
|
|
78
|
+
export function createToolsFromHostDefinitions(
|
|
79
|
+
definitions: Record<string, unknown>,
|
|
80
|
+
options?: HostToolMaterializationOptions,
|
|
81
|
+
): ToolSet;
|
|
57
82
|
export function createToolsFromHostDefinitions(
|
|
58
83
|
definitions: Record<string, unknown>,
|
|
59
84
|
options: HostToolMaterializationOptions = {},
|
|
60
|
-
):
|
|
61
|
-
const tools:
|
|
85
|
+
): ToolSet {
|
|
86
|
+
const tools: ToolSet = {};
|
|
62
87
|
|
|
63
88
|
for (const [toolName, definition] of Object.entries(definitions)) {
|
|
64
89
|
if (!isHostToolDefinition(definition)) continue;
|
package/src/src/tool/index.ts
CHANGED
|
@@ -52,6 +52,7 @@ export type {
|
|
|
52
52
|
ToolDefinition,
|
|
53
53
|
ToolExecutionContext,
|
|
54
54
|
ToolExecutionDataEvent,
|
|
55
|
+
ToolSet,
|
|
55
56
|
} from "./types.js";
|
|
56
57
|
|
|
57
58
|
export { dynamicTool, tool } from "./factory.js";
|
|
@@ -61,7 +62,11 @@ export type { RemoteMCPToolSourceConfig } from "./remote-mcp.js";
|
|
|
61
62
|
export { createContext7ToolSource } from "./context7.js";
|
|
62
63
|
export type { Context7ToolSourceConfig } from "./context7.js";
|
|
63
64
|
export { createToolsFromHostDefinitions } from "./host-tools.js";
|
|
64
|
-
export type {
|
|
65
|
+
export type {
|
|
66
|
+
HostToolDefinition,
|
|
67
|
+
HostToolMaterializationOptions,
|
|
68
|
+
HostToolSet,
|
|
69
|
+
} from "./host-tools.js";
|
|
65
70
|
export {
|
|
66
71
|
createToolsFromRemoteDefinitions,
|
|
67
72
|
loadRemoteToolsFromSource,
|