veryfront 0.1.341 → 0.1.343
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/runtime/index.js +3 -3
- package/esm/src/agent/runtime/runtime-tool-types.d.ts +2 -2
- package/esm/src/agent/runtime/runtime-tool-types.d.ts.map +1 -1
- package/esm/src/agent/runtime/text-generation-runtime-message-converter.d.ts +19 -0
- package/esm/src/agent/runtime/text-generation-runtime-message-converter.d.ts.map +1 -0
- package/esm/src/agent/runtime/{model-message-converter.js → text-generation-runtime-message-converter.js} +18 -15
- package/esm/src/agent/runtime/text-generation-runtime-message-types.d.ts +44 -0
- package/esm/src/agent/runtime/text-generation-runtime-message-types.d.ts.map +1 -0
- package/esm/src/agent/runtime/{model-runtime-types.js → text-generation-runtime-message-types.js} +1 -1
- package/esm/src/chat/conversation.d.ts +7 -3
- package/esm/src/chat/conversation.d.ts.map +1 -1
- package/esm/src/chat/conversation.js +5 -1
- package/esm/src/chat/message-prep.d.ts +19 -12
- package/esm/src/chat/message-prep.d.ts.map +1 -1
- package/esm/src/chat/message-prep.js +14 -7
- package/esm/src/chat/types.d.ts +3 -0
- package/esm/src/chat/types.d.ts.map +1 -1
- package/esm/src/runtime/runtime-bridge.d.ts +3 -3
- package/esm/src/runtime/runtime-bridge.d.ts.map +1 -1
- package/esm/src/tool/index.d.ts +2 -0
- package/esm/src/tool/index.d.ts.map +1 -1
- package/esm/src/tool/index.js +1 -0
- package/esm/src/tool/project-scoped-remote-tools.d.ts +12 -0
- package/esm/src/tool/project-scoped-remote-tools.d.ts.map +1 -0
- package/esm/src/tool/project-scoped-remote-tools.js +46 -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 +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/runtime/index.ts +3 -3
- package/src/src/agent/runtime/runtime-tool-types.ts +2 -2
- package/src/src/agent/runtime/{model-message-converter.ts → text-generation-runtime-message-converter.ts} +33 -25
- package/src/src/agent/runtime/text-generation-runtime-message-types.ts +55 -0
- package/src/src/chat/conversation.ts +14 -7
- package/src/src/chat/message-prep.ts +39 -27
- package/src/src/chat/types.ts +3 -0
- package/src/src/runtime/runtime-bridge.ts +4 -4
- package/src/src/tool/index.ts +6 -0
- package/src/src/tool/project-scoped-remote-tools.ts +86 -0
- package/src/src/utils/version-constant.ts +1 -1
- package/esm/src/agent/runtime/model-message-converter.d.ts +0 -19
- package/esm/src/agent/runtime/model-message-converter.d.ts.map +0 -1
- package/esm/src/agent/runtime/model-runtime-types.d.ts +0 -44
- package/esm/src/agent/runtime/model-runtime-types.d.ts.map +0 -1
- package/src/src/agent/runtime/model-runtime-types.ts +0 -55
|
@@ -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
|
|
|
@@ -33,7 +33,7 @@ import {
|
|
|
33
33
|
setSpanAttributes,
|
|
34
34
|
withSpan,
|
|
35
35
|
} from "../../observability/tracing/index.js";
|
|
36
|
-
import {
|
|
36
|
+
import { convertToTextGenerationRuntimeMessages } from "./text-generation-runtime-message-converter.js";
|
|
37
37
|
import { convertToolsToRuntimeTools } from "./model-tool-converter.js";
|
|
38
38
|
import { resolveProviderOptionsWithDefaults } from "./default-provider-options.js";
|
|
39
39
|
import {
|
|
@@ -789,7 +789,7 @@ export class AgentRuntime {
|
|
|
789
789
|
return generateText({
|
|
790
790
|
model: languageModel,
|
|
791
791
|
system: currentSystemPrompt,
|
|
792
|
-
messages:
|
|
792
|
+
messages: convertToTextGenerationRuntimeMessages(currentMessages),
|
|
793
793
|
tools: convertToolsToRuntimeTools(tools, {
|
|
794
794
|
model: effectiveModel,
|
|
795
795
|
allowedToolNames: allowedRemoteToolNames,
|
|
@@ -1069,7 +1069,7 @@ export class AgentRuntime {
|
|
|
1069
1069
|
const result = streamText({
|
|
1070
1070
|
model: languageModel,
|
|
1071
1071
|
system: currentSystemPrompt,
|
|
1072
|
-
messages:
|
|
1072
|
+
messages: convertToTextGenerationRuntimeMessages(currentMessages),
|
|
1073
1073
|
tools: convertToolsToRuntimeTools(tools, {
|
|
1074
1074
|
model: effectiveModel,
|
|
1075
1075
|
allowedToolNames: allowedRemoteToolNames,
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* boundary. These cover only the shapes the framework consumes today.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type {
|
|
8
|
+
import type { TextGenerationRuntimeMessage } from "./text-generation-runtime-message-types.js";
|
|
9
9
|
|
|
10
10
|
export type RuntimeToolSet = Record<string, unknown>;
|
|
11
11
|
|
|
@@ -47,7 +47,7 @@ export interface RuntimeRepairToolCall {
|
|
|
47
47
|
export interface RuntimeToolCallRepairContext {
|
|
48
48
|
error: unknown;
|
|
49
49
|
inputSchema: (...args: unknown[]) => unknown;
|
|
50
|
-
messages:
|
|
50
|
+
messages: TextGenerationRuntimeMessage[];
|
|
51
51
|
system?: string;
|
|
52
52
|
toolCall: RuntimeRepairToolCall;
|
|
53
53
|
tools: RuntimeToolSet;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Text-Generation Runtime Message Converter
|
|
3
3
|
*
|
|
4
4
|
* Converts between veryfront's internal Message format and the current
|
|
5
|
-
*
|
|
5
|
+
* text-generation runtime message format.
|
|
6
6
|
*
|
|
7
|
-
* @module ai/agent/runtime/
|
|
7
|
+
* @module ai/agent/runtime/text-generation-runtime-message-converter
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import type {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} from "./
|
|
11
|
+
TextGenerationRuntimeAssistantMessage,
|
|
12
|
+
TextGenerationRuntimeMessage,
|
|
13
|
+
TextGenerationRuntimeTextPart,
|
|
14
|
+
TextGenerationRuntimeToolCallPart,
|
|
15
|
+
TextGenerationRuntimeToolMessage,
|
|
16
|
+
} from "./text-generation-runtime-message-types.js";
|
|
17
17
|
import {
|
|
18
18
|
getTextFromParts,
|
|
19
19
|
getToolArguments,
|
|
@@ -23,9 +23,9 @@ import {
|
|
|
23
23
|
} from "../types.js";
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
|
-
* Convert a veryfront Message to the current
|
|
26
|
+
* Convert a veryfront Message to the current text-generation runtime message format.
|
|
27
27
|
*/
|
|
28
|
-
export function
|
|
28
|
+
export function convertToTextGenerationRuntimeMessage(msg: Message): TextGenerationRuntimeMessage {
|
|
29
29
|
switch (msg.role) {
|
|
30
30
|
case "system": {
|
|
31
31
|
const text = getTextFromParts(msg.parts);
|
|
@@ -38,7 +38,7 @@ export function convertToModelMessage(msg: Message): ModelRuntimeMessage {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
case "assistant": {
|
|
41
|
-
const content: Array<
|
|
41
|
+
const content: Array<TextGenerationRuntimeTextPart | TextGenerationRuntimeToolCallPart> = [];
|
|
42
42
|
|
|
43
43
|
for (const part of msg.parts) {
|
|
44
44
|
if (part.type === "text" && "text" in part) {
|
|
@@ -66,12 +66,15 @@ export function convertToModelMessage(msg: Message): ModelRuntimeMessage {
|
|
|
66
66
|
content.push({ type: "text", text: "" });
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
const assistantMessage:
|
|
69
|
+
const assistantMessage: TextGenerationRuntimeAssistantMessage = {
|
|
70
|
+
role: "assistant",
|
|
71
|
+
content,
|
|
72
|
+
};
|
|
70
73
|
return assistantMessage;
|
|
71
74
|
}
|
|
72
75
|
|
|
73
76
|
case "tool": {
|
|
74
|
-
const content:
|
|
77
|
+
const content: TextGenerationRuntimeToolMessage["content"] = [];
|
|
75
78
|
|
|
76
79
|
for (const part of msg.parts) {
|
|
77
80
|
if (part.type !== "tool-result") continue;
|
|
@@ -85,7 +88,7 @@ export function convertToModelMessage(msg: Message): ModelRuntimeMessage {
|
|
|
85
88
|
});
|
|
86
89
|
}
|
|
87
90
|
|
|
88
|
-
const toolMessage:
|
|
91
|
+
const toolMessage: TextGenerationRuntimeToolMessage = { role: "tool", content };
|
|
89
92
|
return toolMessage;
|
|
90
93
|
}
|
|
91
94
|
|
|
@@ -99,7 +102,7 @@ export function convertToModelMessage(msg: Message): ModelRuntimeMessage {
|
|
|
99
102
|
|
|
100
103
|
function convertToolResultPart(
|
|
101
104
|
part: ToolResultPart,
|
|
102
|
-
):
|
|
105
|
+
): TextGenerationRuntimeToolMessage {
|
|
103
106
|
return {
|
|
104
107
|
role: "tool",
|
|
105
108
|
content: [{
|
|
@@ -112,15 +115,17 @@ function convertToolResultPart(
|
|
|
112
115
|
}
|
|
113
116
|
|
|
114
117
|
/**
|
|
115
|
-
* Convert an array of veryfront Messages to the current
|
|
118
|
+
* Convert an array of veryfront Messages to the current text-generation runtime message format.
|
|
116
119
|
*/
|
|
117
|
-
export function
|
|
118
|
-
|
|
120
|
+
export function convertToTextGenerationRuntimeMessages(
|
|
121
|
+
messages: Message[],
|
|
122
|
+
): TextGenerationRuntimeMessage[] {
|
|
123
|
+
const textGenerationRuntimeMessages: TextGenerationRuntimeMessage[] = [];
|
|
119
124
|
const toolResultMessageIndexes = new Map<string, number>();
|
|
120
125
|
|
|
121
126
|
for (const message of messages) {
|
|
122
127
|
if (message.role !== "tool") {
|
|
123
|
-
|
|
128
|
+
textGenerationRuntimeMessages.push(convertToTextGenerationRuntimeMessage(message));
|
|
124
129
|
continue;
|
|
125
130
|
}
|
|
126
131
|
|
|
@@ -129,7 +134,7 @@ export function convertToModelMessages(messages: Message[]): ModelRuntimeMessage
|
|
|
129
134
|
);
|
|
130
135
|
|
|
131
136
|
if (toolResultParts.length === 0) {
|
|
132
|
-
|
|
137
|
+
textGenerationRuntimeMessages.push(convertToTextGenerationRuntimeMessage(message));
|
|
133
138
|
continue;
|
|
134
139
|
}
|
|
135
140
|
|
|
@@ -138,14 +143,17 @@ export function convertToModelMessages(messages: Message[]): ModelRuntimeMessage
|
|
|
138
143
|
const existingIndex = toolResultMessageIndexes.get(toolResultPart.toolCallId);
|
|
139
144
|
|
|
140
145
|
if (existingIndex === undefined) {
|
|
141
|
-
toolResultMessageIndexes.set(
|
|
142
|
-
|
|
146
|
+
toolResultMessageIndexes.set(
|
|
147
|
+
toolResultPart.toolCallId,
|
|
148
|
+
textGenerationRuntimeMessages.length,
|
|
149
|
+
);
|
|
150
|
+
textGenerationRuntimeMessages.push(toolResultMessage);
|
|
143
151
|
continue;
|
|
144
152
|
}
|
|
145
153
|
|
|
146
|
-
|
|
154
|
+
textGenerationRuntimeMessages[existingIndex] = toolResultMessage;
|
|
147
155
|
}
|
|
148
156
|
}
|
|
149
157
|
|
|
150
|
-
return
|
|
158
|
+
return textGenerationRuntimeMessages;
|
|
151
159
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text-Generation Runtime Message Types
|
|
3
|
+
*
|
|
4
|
+
* Framework-owned message types for the current text-generation runtime
|
|
5
|
+
* boundary. These describe the subset of message shapes the runtime uses
|
|
6
|
+
* today without exposing SDK-owned message contracts upward.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export interface TextGenerationRuntimeTextPart {
|
|
10
|
+
type: "text";
|
|
11
|
+
text: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface TextGenerationRuntimeToolCallPart {
|
|
15
|
+
type: "tool-call";
|
|
16
|
+
toolCallId: string;
|
|
17
|
+
toolName: string;
|
|
18
|
+
input: Record<string, unknown>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface TextGenerationRuntimeToolResultPart {
|
|
22
|
+
type: "tool-result";
|
|
23
|
+
toolCallId: string;
|
|
24
|
+
toolName: string;
|
|
25
|
+
output: {
|
|
26
|
+
type: "json";
|
|
27
|
+
value: unknown;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface TextGenerationRuntimeSystemMessage {
|
|
32
|
+
role: "system";
|
|
33
|
+
content: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface TextGenerationRuntimeUserMessage {
|
|
37
|
+
role: "user";
|
|
38
|
+
content: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface TextGenerationRuntimeAssistantMessage {
|
|
42
|
+
role: "assistant";
|
|
43
|
+
content: Array<TextGenerationRuntimeTextPart | TextGenerationRuntimeToolCallPart>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface TextGenerationRuntimeToolMessage {
|
|
47
|
+
role: "tool";
|
|
48
|
+
content: TextGenerationRuntimeToolResultPart[];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type TextGenerationRuntimeMessage =
|
|
52
|
+
| TextGenerationRuntimeSystemMessage
|
|
53
|
+
| TextGenerationRuntimeUserMessage
|
|
54
|
+
| TextGenerationRuntimeAssistantMessage
|
|
55
|
+
| TextGenerationRuntimeToolMessage;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "../../_dnt.polyfills.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import type {
|
|
3
|
+
import type { ChatUiMessage, ChatUiMessagePart, ProviderModelMessage } from "./types.js";
|
|
4
4
|
|
|
5
5
|
const textPartSchema = z.object({ type: z.literal("text"), text: z.string() });
|
|
6
6
|
const imagePartSchema = z.object({
|
|
@@ -470,7 +470,7 @@ export function isReasoningPart(value: unknown): value is ReasoningPartLike {
|
|
|
470
470
|
return isRecord(value) && value.type === "reasoning" && typeof value.text === "string";
|
|
471
471
|
}
|
|
472
472
|
|
|
473
|
-
export function extractTextFromMessage(message:
|
|
473
|
+
export function extractTextFromMessage(message: ProviderModelMessage): string {
|
|
474
474
|
if (!message || !message.content) return "";
|
|
475
475
|
|
|
476
476
|
const { content } = message;
|
|
@@ -704,7 +704,7 @@ function buildToolResultOutput(toolPart: { state: string; output?: unknown; erro
|
|
|
704
704
|
return null;
|
|
705
705
|
}
|
|
706
706
|
|
|
707
|
-
function convertSystemMessage(message: ChatUiMessage):
|
|
707
|
+
function convertSystemMessage(message: ChatUiMessage): ProviderModelMessage[] {
|
|
708
708
|
const content = message.parts.flatMap((part) => (isTextPart(part) ? [part.text] : [])).join("");
|
|
709
709
|
if (content.length === 0) {
|
|
710
710
|
return [];
|
|
@@ -718,7 +718,7 @@ function convertSystemMessage(message: ChatUiMessage): ChatModelMessage[] {
|
|
|
718
718
|
];
|
|
719
719
|
}
|
|
720
720
|
|
|
721
|
-
function convertUserMessage(message: ChatUiMessage):
|
|
721
|
+
function convertUserMessage(message: ChatUiMessage): ProviderModelMessage[] {
|
|
722
722
|
const content: Array<
|
|
723
723
|
{ type: "text"; text: string } | {
|
|
724
724
|
type: "file";
|
|
@@ -752,7 +752,7 @@ function convertUserMessage(message: ChatUiMessage): ChatModelMessage[] {
|
|
|
752
752
|
];
|
|
753
753
|
}
|
|
754
754
|
|
|
755
|
-
function convertAssistantMessage(message: ChatUiMessage):
|
|
755
|
+
function convertAssistantMessage(message: ChatUiMessage): ProviderModelMessage[] {
|
|
756
756
|
const rawToolNamesById = buildRawToolNameMap(message.parts);
|
|
757
757
|
const assistantContent: Array<
|
|
758
758
|
| { type: "text"; text: string }
|
|
@@ -776,7 +776,7 @@ function convertAssistantMessage(message: ChatUiMessage): ChatModelMessage[] {
|
|
|
776
776
|
};
|
|
777
777
|
}> = [];
|
|
778
778
|
const pendingToolCallIds = new Set<string>();
|
|
779
|
-
const messages:
|
|
779
|
+
const messages: ProviderModelMessage[] = [];
|
|
780
780
|
|
|
781
781
|
const flushAssistantMessage = (content: typeof assistantContent) => {
|
|
782
782
|
if (content.length === 0) {
|
|
@@ -915,7 +915,9 @@ function convertAssistantMessage(message: ChatUiMessage): ChatModelMessage[] {
|
|
|
915
915
|
return messages;
|
|
916
916
|
}
|
|
917
917
|
|
|
918
|
-
export function
|
|
918
|
+
export function convertUiMessagesToProviderModelMessages(
|
|
919
|
+
messages: ChatUiMessage[],
|
|
920
|
+
): ProviderModelMessage[] {
|
|
919
921
|
return messages.flatMap((message) => {
|
|
920
922
|
switch (message.role) {
|
|
921
923
|
case "system":
|
|
@@ -929,3 +931,8 @@ export function convertUiMessagesToModelMessages(messages: ChatUiMessage[]): Cha
|
|
|
929
931
|
}
|
|
930
932
|
});
|
|
931
933
|
}
|
|
934
|
+
|
|
935
|
+
/**
|
|
936
|
+
* @deprecated Use convertUiMessagesToProviderModelMessages for provider-facing model payloads.
|
|
937
|
+
*/
|
|
938
|
+
export const convertUiMessagesToModelMessages = convertUiMessagesToProviderModelMessages;
|