veryfront 0.1.437 → 0.1.439

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 (41) hide show
  1. package/esm/deno.js +1 -1
  2. package/esm/extensions/ext-anthropic/src/anthropic-provider.d.ts.map +1 -1
  3. package/esm/extensions/ext-anthropic/src/anthropic-provider.js +23 -5
  4. package/esm/extensions/ext-google/src/google-provider.d.ts.map +1 -1
  5. package/esm/extensions/ext-google/src/google-provider.js +22 -2
  6. package/esm/extensions/ext-openai/src/openai-provider.d.ts.map +1 -1
  7. package/esm/extensions/ext-openai/src/openai-provider.js +23 -2
  8. package/esm/src/agent/runtime/provider-tool-compat.d.ts.map +1 -1
  9. package/esm/src/agent/runtime/provider-tool-compat.js +3 -0
  10. package/esm/src/agent/runtime/text-generation-runtime-message-converter.d.ts.map +1 -1
  11. package/esm/src/agent/runtime/text-generation-runtime-message-converter.js +38 -2
  12. package/esm/src/agent/runtime/text-generation-runtime-message-types.d.ts +7 -1
  13. package/esm/src/agent/runtime/text-generation-runtime-message-types.d.ts.map +1 -1
  14. package/esm/src/agent/runtime-message-file-url-refresh.d.ts.map +1 -1
  15. package/esm/src/agent/runtime-message-file-url-refresh.js +64 -10
  16. package/esm/src/chat/conversation.d.ts.map +1 -1
  17. package/esm/src/chat/conversation.js +8 -5
  18. package/esm/src/provider/runtime-loader.d.ts +14 -1
  19. package/esm/src/provider/runtime-loader.d.ts.map +1 -1
  20. package/esm/src/provider/runtime-loader.js +19 -1
  21. package/esm/src/runtime/runtime-bridge.d.ts.map +1 -1
  22. package/esm/src/runtime/runtime-bridge.js +3 -1
  23. package/esm/src/utils/version-constant.d.ts +1 -1
  24. package/esm/src/utils/version-constant.js +1 -1
  25. package/package.json +1 -1
  26. package/src/deno.js +1 -1
  27. package/src/deps/esm.sh/@types/react-dom@19.2.3/client.d.ts +1 -1
  28. package/src/deps/esm.sh/@types/{react@19.2.14 → react@19.2.3}/global.d.ts +0 -1
  29. package/src/deps/esm.sh/@types/{react@19.2.14 → react@19.2.3}/index.d.ts +24 -93
  30. package/src/deps/esm.sh/react-dom@19.2.4/client.d.ts +1 -1
  31. package/src/extensions/ext-anthropic/src/anthropic-provider.ts +28 -5
  32. package/src/extensions/ext-google/src/google-provider.ts +27 -2
  33. package/src/extensions/ext-openai/src/openai-provider.ts +29 -2
  34. package/src/src/agent/runtime/provider-tool-compat.ts +4 -0
  35. package/src/src/agent/runtime/text-generation-runtime-message-converter.ts +41 -2
  36. package/src/src/agent/runtime/text-generation-runtime-message-types.ts +8 -1
  37. package/src/src/agent/runtime-message-file-url-refresh.ts +78 -12
  38. package/src/src/chat/conversation.ts +15 -9
  39. package/src/src/provider/runtime-loader.ts +46 -3
  40. package/src/src/runtime/runtime-bridge.ts +10 -2
  41. package/src/src/utils/version-constant.ts +1 -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 {@link https://reactjs.org/blog/2019/02/06/react-v16.8.0.html#testing-hooks}
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
- interface UntrackedReactPromise<T> extends PromiseLike<T> {
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
- * change events bubble in React so their target is generally unknown.
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<CurrentTarget = Element, Target = Element> = EventHandler<
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
- // form related Events
2297
- onChange?: ChangeEventHandler<T> | undefined;
2298
- onChangeCapture?: ChangeEventHandler<T> | undefined;
2235
+ // Form Events
2236
+ onChange?: FormEventHandler<T> | undefined;
2237
+ onChangeCapture?: FormEventHandler<T> | undefined;
2299
2238
  onBeforeInput?: InputEventHandler<T> | undefined;
2300
- onBeforeInputCapture?: InputEventHandler<T> | undefined;
2301
- onInput?: InputEventHandler<T> | undefined;
2302
- onInputCapture?: InputEventHandler<T> | undefined;
2303
- onReset?: ReactEventHandler<T> | undefined;
2304
- onResetCapture?: ReactEventHandler<T> | undefined;
2305
- onSubmit?: SubmitEventHandler<T> | undefined;
2306
- onSubmitCapture?: SubmitEventHandler<T> | undefined;
2307
- onInvalid?: ReactEventHandler<T> | undefined;
2308
- onInvalidCapture?: ReactEventHandler<T> | undefined;
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 {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/inert}
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
- // No other element dispatching change events can be nested in a <input>
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
- // No other element dispatching change events can be nested in a <select>
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
- // No other element dispatching change events can be nested in a <textarea>
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.14/index.d.ts");
7
+ import React = require("https://esm.sh/@types/react@19.2.3/index.d.ts");
8
8
 
9
9
  export {};
10
10
 
@@ -26,7 +26,6 @@ import {
26
26
  ProviderRequestError,
27
27
  readProviderOptions,
28
28
  readRecord,
29
- readTextParts,
30
29
  requestJson,
31
30
  requestStream,
32
31
  stringifyJsonValue,
@@ -283,6 +282,33 @@ function pushAnthropicUserContent(
283
282
  });
284
283
  }
285
284
 
285
+ function toAnthropicUserContent(
286
+ parts: Extract<RuntimePromptMessage, { role: "user" }>["content"],
287
+ ): Array<Record<string, unknown>> {
288
+ const content: Array<Record<string, unknown>> = [];
289
+
290
+ for (const part of parts) {
291
+ if (part.type === "text") {
292
+ if (part.text.length > 0) {
293
+ content.push({ type: "text", text: part.text });
294
+ }
295
+ continue;
296
+ }
297
+
298
+ if (part.type === "image" || part.mediaType.startsWith("image/")) {
299
+ content.push({
300
+ type: "image",
301
+ source: {
302
+ type: "url",
303
+ url: part.url,
304
+ },
305
+ });
306
+ }
307
+ }
308
+
309
+ return content;
310
+ }
311
+
286
312
  /**
287
313
  * Resolves a {@link ProviderCacheTtl} into Anthropic's `cache_control` shape.
288
314
  *
@@ -320,10 +346,7 @@ function toAnthropicMessages(
320
346
  }
321
347
  break;
322
348
  case "user":
323
- pushAnthropicUserContent(messages, [{
324
- type: "text",
325
- text: readTextParts(message.content),
326
- }]);
349
+ pushAnthropicUserContent(messages, toAnthropicUserContent(message.content));
327
350
  break;
328
351
  case "assistant":
329
352
  messages.push({
@@ -27,7 +27,6 @@ import {
27
27
  ProviderRequestError,
28
28
  readProviderOptions,
29
29
  readRecord,
30
- readTextParts,
31
30
  requestJson,
32
31
  requestStream,
33
32
  stringifyJsonValue,
@@ -249,7 +248,7 @@ function toGoogleContents(
249
248
  case "user":
250
249
  contents.push({
251
250
  role: "user",
252
- parts: [{ text: readTextParts(message.content) }],
251
+ parts: toGoogleUserParts(message.content),
253
252
  });
254
253
  break;
255
254
  case "assistant": {
@@ -300,6 +299,32 @@ function toGoogleContents(
300
299
  };
301
300
  }
302
301
 
302
+ function toGoogleUserParts(
303
+ parts: Extract<RuntimePromptMessage, { role: "user" }>["content"],
304
+ ): Array<Record<string, unknown>> {
305
+ const content: Array<Record<string, unknown>> = [];
306
+
307
+ for (const part of parts) {
308
+ if (part.type === "text") {
309
+ if (part.text.length > 0) {
310
+ content.push({ text: part.text });
311
+ }
312
+ continue;
313
+ }
314
+
315
+ if (part.type === "image" || part.mediaType.startsWith("image/")) {
316
+ content.push({
317
+ fileData: {
318
+ mimeType: part.mediaType,
319
+ fileUri: part.url,
320
+ },
321
+ });
322
+ }
323
+ }
324
+
325
+ return content;
326
+ }
327
+
303
328
  function toGoogleTools(
304
329
  tools: RuntimeToolDefinition[] | undefined,
305
330
  ): Array<Record<string, unknown>> | undefined {
@@ -27,7 +27,6 @@ import {
27
27
  ProviderRequestError,
28
28
  readProviderOptions,
29
29
  readRecord,
30
- readTextParts,
31
30
  requestJson,
32
31
  requestStream,
33
32
  stringifyJsonValue,
@@ -751,7 +750,7 @@ function toOpenAIResponsesInput(
751
750
  case "user":
752
751
  input.push({
753
752
  role: "user",
754
- content: [{ type: "input_text", text: readTextParts(message.content) }],
753
+ content: toOpenAIResponsesUserContent(message.content),
755
754
  });
756
755
  break;
757
756
  case "assistant": {
@@ -816,6 +815,34 @@ function toOpenAIResponsesInput(
816
815
  };
817
816
  }
818
817
 
818
+ function toOpenAIResponsesUserContent(
819
+ parts: Extract<RuntimePromptMessage, { role: "user" }>["content"],
820
+ ): Array<Record<string, unknown>> {
821
+ const content: Array<Record<string, unknown>> = [];
822
+
823
+ for (const part of parts) {
824
+ if (part.type === "text") {
825
+ if (part.text.length > 0) {
826
+ content.push({ type: "input_text", text: part.text });
827
+ }
828
+ continue;
829
+ }
830
+
831
+ if (part.type === "image" || part.mediaType.startsWith("image/")) {
832
+ content.push({ type: "input_image", image_url: part.url, detail: "auto" });
833
+ continue;
834
+ }
835
+
836
+ content.push({
837
+ type: "input_file",
838
+ file_url: part.url,
839
+ ...(part.filename ? { filename: part.filename } : {}),
840
+ });
841
+ }
842
+
843
+ return content;
844
+ }
845
+
819
846
  /**
820
847
  * Tools on the Responses API differ from Chat Completions: instead of
821
848
  * `{ type: "function", function: { name, parameters } }` the function
@@ -240,6 +240,10 @@ function sanitizeGoogleSchemaValue(value: unknown): unknown {
240
240
  }
241
241
  }
242
242
 
243
+ if (sanitized.type === "array" && !Object.hasOwn(sanitized, "items")) {
244
+ sanitized.items = {};
245
+ }
246
+
243
247
  return sanitized;
244
248
  }
245
249
 
@@ -9,6 +9,7 @@
9
9
 
10
10
  import type {
11
11
  TextGenerationRuntimeAssistantMessage,
12
+ TextGenerationRuntimeFilePart,
12
13
  TextGenerationRuntimeMessage,
13
14
  TextGenerationRuntimeTextPart,
14
15
  TextGenerationRuntimeToolCallPart,
@@ -75,6 +76,26 @@ function getUserTextWithAttachmentContext(parts: Message["parts"]): string {
75
76
  : appendReadableAttachmentContext(text, buildAttachmentContextFromParts(parts));
76
77
  }
77
78
 
79
+ function getUserFileParts(parts: Message["parts"]): TextGenerationRuntimeFilePart[] {
80
+ return parts.flatMap((part) => {
81
+ const type = getStringPartField(part, "type");
82
+ if (type !== "file" && type !== "image") return [];
83
+
84
+ const mediaType = getStringPartField(part, "mediaType");
85
+ const url = getStringPartField(part, "url");
86
+ if (!mediaType || !url || url.startsWith("data:")) return [];
87
+
88
+ return [{
89
+ type,
90
+ mediaType,
91
+ url,
92
+ ...(getStringPartField(part, "filename")
93
+ ? { filename: getStringPartField(part, "filename") }
94
+ : {}),
95
+ }];
96
+ });
97
+ }
98
+
78
99
  /**
79
100
  * Convert a veryfront Message to the current text-generation runtime message format.
80
101
  */
@@ -86,8 +107,26 @@ export function convertToTextGenerationRuntimeMessage(msg: Message): TextGenerat
86
107
  }
87
108
 
88
109
  case "user": {
89
- const text = getUserTextWithAttachmentContext(msg.parts);
90
- return { role: "user", content: text };
110
+ const fileParts = getUserFileParts(msg.parts);
111
+ if (fileParts.length === 0) {
112
+ const text = getUserTextWithAttachmentContext(msg.parts);
113
+ return { role: "user", content: text };
114
+ }
115
+
116
+ const text = getTextFromParts(msg.parts);
117
+ const attachmentContext = text.includes("<uploaded_files>")
118
+ ? ""
119
+ : buildAttachmentContextFromParts(msg.parts);
120
+ return {
121
+ role: "user",
122
+ content: [
123
+ ...(text.length > 0 ? [{ type: "text" as const, text }] : []),
124
+ ...fileParts,
125
+ ...(attachmentContext.length > 0
126
+ ? [{ type: "text" as const, text: attachmentContext.trimStart() }]
127
+ : []),
128
+ ],
129
+ };
91
130
  }
92
131
 
93
132
  case "assistant": {
@@ -11,6 +11,13 @@ export interface TextGenerationRuntimeTextPart {
11
11
  text: string;
12
12
  }
13
13
 
14
+ export interface TextGenerationRuntimeFilePart {
15
+ type: "file" | "image";
16
+ mediaType: string;
17
+ url: string;
18
+ filename?: string;
19
+ }
20
+
14
21
  export interface TextGenerationRuntimeToolCallPart {
15
22
  type: "tool-call";
16
23
  toolCallId: string;
@@ -35,7 +42,7 @@ export interface TextGenerationRuntimeSystemMessage {
35
42
 
36
43
  export interface TextGenerationRuntimeUserMessage {
37
44
  role: "user";
38
- content: string;
45
+ content: string | Array<TextGenerationRuntimeTextPart | TextGenerationRuntimeFilePart>;
39
46
  }
40
47
 
41
48
  export interface TextGenerationRuntimeAssistantMessage {
@@ -1,4 +1,4 @@
1
- import type { ChatFileUiPart, ChatUiMessage, FileUIPartWithUpload } from "../chat/types.js";
1
+ import type { ChatUiMessage, FileUIPartWithUpload } from "../chat/types.js";
2
2
 
3
3
  export type RuntimeFileUrlResolverInput = {
4
4
  uploadId: string;
@@ -18,25 +18,30 @@ export async function resolveRuntimeMessageFileUrls(
18
18
 
19
19
  return Promise.all(
20
20
  messages.map(async (message) => {
21
- if (!message.parts.some((part) => part.type === "file" && part.uploadId)) {
21
+ if (!message.parts.some((part) => getUploadId(part))) {
22
22
  return message;
23
23
  }
24
24
 
25
25
  const parts = await Promise.all(
26
26
  message.parts.map(async (part) => {
27
- if (!isFilePartWithUpload(part)) return part;
27
+ const uploadId = getUploadId(part);
28
+ if (!uploadId) return part;
28
29
 
29
- let urlPromise = urlByUploadId.get(part.uploadId);
30
+ let urlPromise = urlByUploadId.get(uploadId);
30
31
  if (!urlPromise) {
31
- urlPromise = resolveFileUrl({ uploadId: part.uploadId, part, message });
32
- urlByUploadId.set(part.uploadId, urlPromise);
32
+ urlPromise = resolveFileUrl({
33
+ uploadId,
34
+ part: toResolverPart(part, uploadId),
35
+ message,
36
+ });
37
+ urlByUploadId.set(uploadId, urlPromise);
33
38
  }
34
39
 
35
40
  const signedUrl = await urlPromise;
36
- if (!signedUrl || signedUrl === part.url) return part;
41
+ if (!signedUrl) return normalizeUploadedFilePart(part, uploadId);
37
42
 
38
43
  return {
39
- ...part,
44
+ ...normalizeUploadedFilePart(part, uploadId),
40
45
  url: signedUrl,
41
46
  };
42
47
  }),
@@ -47,8 +52,69 @@ export async function resolveRuntimeMessageFileUrls(
47
52
  );
48
53
  }
49
54
 
50
- function isFilePartWithUpload(part: ChatUiMessage["parts"][number]): part is ChatFileUiPart & {
51
- uploadId: string;
52
- } {
53
- return part.type === "file" && typeof part.uploadId === "string" && part.uploadId.length > 0;
55
+ function isRecord(value: unknown): value is Record<string, unknown> {
56
+ return typeof value === "object" && value !== null && !Array.isArray(value);
57
+ }
58
+
59
+ function getStringField(part: unknown, key: string): string | undefined {
60
+ if (!isRecord(part)) return undefined;
61
+
62
+ const value = part[key];
63
+ return typeof value === "string" && value.length > 0 ? value : undefined;
64
+ }
65
+
66
+ function getUploadId(part: unknown): string | undefined {
67
+ if (!isRecord(part) || (part.type !== "file" && part.type !== "image")) {
68
+ return undefined;
69
+ }
70
+
71
+ return getStringField(part, "uploadId") ?? getStringField(part, "upload_id");
72
+ }
73
+
74
+ function getMediaType(part: unknown): string | undefined {
75
+ return getStringField(part, "mediaType") ?? getStringField(part, "media_type");
76
+ }
77
+
78
+ function normalizeUploadedFilePart(
79
+ part: ChatUiMessage["parts"][number],
80
+ uploadId: string,
81
+ ): ChatUiMessage["parts"][number] {
82
+ if (!isRecord(part)) return part;
83
+
84
+ const partRecord: Record<string, unknown> = part;
85
+ const partType = partRecord.type;
86
+ if (partType !== "file" && partType !== "image") return part;
87
+
88
+ const mediaType = getMediaType(part);
89
+ const url = getStringField(part, "url");
90
+ if (!mediaType || !url) return part;
91
+
92
+ const filename = getStringField(part, "filename");
93
+ const uploadPath = getStringField(part, "uploadPath") ?? getStringField(part, "upload_path");
94
+
95
+ return {
96
+ type: partType === "image" ? "image" : "file",
97
+ mediaType,
98
+ url,
99
+ ...(filename ? { filename } : {}),
100
+ uploadId,
101
+ ...(uploadPath ? { uploadPath } : {}),
102
+ } as ChatUiMessage["parts"][number];
103
+ }
104
+
105
+ function toResolverPart(
106
+ part: ChatUiMessage["parts"][number],
107
+ uploadId: string,
108
+ ): FileUIPartWithUpload {
109
+ const normalized = normalizeUploadedFilePart(part, uploadId);
110
+ if (isRecord(normalized) && normalized.type === "file") {
111
+ return normalized as FileUIPartWithUpload;
112
+ }
113
+
114
+ return {
115
+ type: "file",
116
+ mediaType: getMediaType(part) ?? "application/octet-stream",
117
+ url: getStringField(part, "url") ?? "",
118
+ uploadId,
119
+ };
54
120
  }
@@ -515,7 +515,7 @@ function toJsonValue(value: unknown): JsonValue {
515
515
  }
516
516
 
517
517
  function getFilePart(part: unknown): {
518
- type: "file";
518
+ type: "file" | "image";
519
519
  mediaType: string;
520
520
  data: string;
521
521
  url: string;
@@ -523,22 +523,25 @@ function getFilePart(part: unknown): {
523
523
  uploadId?: string;
524
524
  uploadPath?: string;
525
525
  } | null {
526
- if (!isRecord(part) || part.type !== "file") {
526
+ if (!isRecord(part) || (part.type !== "file" && part.type !== "image")) {
527
527
  return null;
528
528
  }
529
529
 
530
- const mediaType = getNonEmptyStringField(part, "mediaType");
530
+ const mediaType = getNonEmptyStringField(part, "mediaType") ??
531
+ getNonEmptyStringField(part, "media_type");
531
532
  const data = getNonEmptyStringField(part, "url");
532
533
  if (!mediaType || !data) {
533
534
  return null;
534
535
  }
535
536
 
536
537
  const filename = getNonEmptyStringField(part, "filename");
537
- const uploadId = getNonEmptyStringField(part, "uploadId");
538
- const uploadPath = getNonEmptyStringField(part, "uploadPath");
538
+ const uploadId = getNonEmptyStringField(part, "uploadId") ??
539
+ getNonEmptyStringField(part, "upload_id");
540
+ const uploadPath = getNonEmptyStringField(part, "uploadPath") ??
541
+ getNonEmptyStringField(part, "upload_path");
539
542
 
540
543
  return {
541
- type: "file",
544
+ type: part.type === "image" ? "image" : "file",
542
545
  mediaType,
543
546
  data,
544
547
  url: data,
@@ -721,10 +724,13 @@ function convertSystemMessage(message: ChatUiMessage): ProviderModelMessage[] {
721
724
  function convertUserMessage(message: ChatUiMessage): ProviderModelMessage[] {
722
725
  const content: Array<
723
726
  { type: "text"; text: string } | {
724
- type: "file";
727
+ type: "file" | "image";
725
728
  mediaType: string;
726
729
  data: string;
730
+ url: string;
727
731
  filename?: string;
732
+ uploadId?: string;
733
+ uploadPath?: string;
728
734
  }
729
735
  > = [];
730
736
 
@@ -757,7 +763,7 @@ function convertAssistantMessage(message: ChatUiMessage): ProviderModelMessage[]
757
763
  const assistantContent: Array<
758
764
  | { type: "text"; text: string }
759
765
  | { type: "reasoning"; text: string }
760
- | { type: "file"; mediaType: string; data: string; filename?: string }
766
+ | { type: "file" | "image"; mediaType: string; data: string; filename?: string }
761
767
  | { type: "tool-call"; toolCallId: string; toolName: string; input: Record<string, unknown> }
762
768
  > = [];
763
769
  const deferredAssistantContent: typeof assistantContent = [];
@@ -806,7 +812,7 @@ function convertAssistantMessage(message: ChatUiMessage): ProviderModelMessage[]
806
812
  part:
807
813
  | { type: "text"; text: string }
808
814
  | { type: "reasoning"; text: string }
809
- | { type: "file"; mediaType: string; data: string; filename?: string }
815
+ | { type: "file" | "image"; mediaType: string; data: string; filename?: string }
810
816
  | { type: "tool-call"; toolCallId: string; toolName: string; input: Record<string, unknown> },
811
817
  ) => {
812
818
  if (toolResults.length > 0) {