veryfront 0.1.435 → 0.1.437
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/index.d.ts +2 -1
- package/esm/src/agent/index.d.ts.map +1 -1
- package/esm/src/agent/index.js +2 -1
- package/esm/src/agent/runtime/index.d.ts +1 -0
- package/esm/src/agent/runtime/index.d.ts.map +1 -1
- package/esm/src/agent/runtime/index.js +1 -0
- package/esm/src/agent/runtime/model-tool-converter.d.ts.map +1 -1
- package/esm/src/agent/runtime/model-tool-converter.js +6 -2
- package/esm/src/agent/runtime/provider-tool-compat.d.ts +17 -0
- package/esm/src/agent/runtime/provider-tool-compat.d.ts.map +1 -0
- package/esm/src/agent/runtime/provider-tool-compat.js +191 -0
- package/esm/src/agent/runtime-project-skill-catalog.d.ts +26 -0
- package/esm/src/agent/runtime-project-skill-catalog.d.ts.map +1 -0
- package/esm/src/agent/runtime-project-skill-catalog.js +148 -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.3 → react@19.2.14}/global.d.ts +1 -0
- package/src/deps/esm.sh/@types/{react@19.2.3 → react@19.2.14}/index.d.ts +93 -24
- package/src/deps/esm.sh/react-dom@19.2.4/client.d.ts +1 -1
- package/src/src/agent/index.ts +15 -0
- package/src/src/agent/runtime/index.ts +9 -0
- package/src/src/agent/runtime/model-tool-converter.ts +11 -2
- package/src/src/agent/runtime/provider-tool-compat.ts +254 -0
- package/src/src/agent/runtime-project-skill-catalog.ts +238 -0
- package/src/src/utils/version-constant.ts +1 -1
|
@@ -18,6 +18,7 @@ interface KeyboardEvent extends Event {}
|
|
|
18
18
|
interface MouseEvent extends Event {}
|
|
19
19
|
interface TouchEvent extends Event {}
|
|
20
20
|
interface PointerEvent extends Event {}
|
|
21
|
+
interface SubmitEvent extends Event {}
|
|
21
22
|
interface ToggleEvent extends Event {}
|
|
22
23
|
interface TransitionEvent extends Event {}
|
|
23
24
|
interface UIEvent extends Event {}
|
|
@@ -16,6 +16,7 @@ type NativeKeyboardEvent = KeyboardEvent;
|
|
|
16
16
|
type NativeMouseEvent = MouseEvent;
|
|
17
17
|
type NativeTouchEvent = TouchEvent;
|
|
18
18
|
type NativePointerEvent = PointerEvent;
|
|
19
|
+
type NativeSubmitEvent = SubmitEvent;
|
|
19
20
|
type NativeToggleEvent = ToggleEvent;
|
|
20
21
|
type NativeTransitionEvent = TransitionEvent;
|
|
21
22
|
type NativeUIEvent = UIEvent;
|
|
@@ -225,12 +226,20 @@ declare namespace React {
|
|
|
225
226
|
|
|
226
227
|
type ComponentState = any;
|
|
227
228
|
|
|
229
|
+
interface DO_NOT_USE_OR_YOU_WILL_BE_FIRED_EXPERIMENTAL_KEY_TYPES {}
|
|
230
|
+
|
|
228
231
|
/**
|
|
229
232
|
* A value which uniquely identifies a node among items in an array.
|
|
230
233
|
*
|
|
231
234
|
* @see {@link https://react.dev/learn/rendering-lists#keeping-list-items-in-order-with-key React Docs}
|
|
232
235
|
*/
|
|
233
|
-
type Key =
|
|
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
|
+
];
|
|
234
243
|
|
|
235
244
|
/**
|
|
236
245
|
* @internal The props any component can receive.
|
|
@@ -1884,7 +1893,7 @@ declare namespace React {
|
|
|
1884
1893
|
*
|
|
1885
1894
|
* @param callback A synchronous, void callback that will execute as a single, complete React commit.
|
|
1886
1895
|
*
|
|
1887
|
-
* @see https://reactjs.org/blog/2019/02/06/react-v16.8.0.html#testing-hooks
|
|
1896
|
+
* @see {@link https://reactjs.org/blog/2019/02/06/react-v16.8.0.html#testing-hooks}
|
|
1888
1897
|
*/
|
|
1889
1898
|
// NOTES
|
|
1890
1899
|
// - the order of these signatures matters - typescript will check the signatures in source order.
|
|
@@ -1926,7 +1935,31 @@ declare namespace React {
|
|
|
1926
1935
|
reducer: (state: State, action: Action) => State,
|
|
1927
1936
|
): [State, (action: Action) => void];
|
|
1928
1937
|
|
|
1929
|
-
|
|
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>;
|
|
1930
1963
|
|
|
1931
1964
|
export function use<T>(usable: Usable<T>): T;
|
|
1932
1965
|
|
|
@@ -2041,15 +2074,28 @@ declare namespace React {
|
|
|
2041
2074
|
target: EventTarget & Target;
|
|
2042
2075
|
}
|
|
2043
2076
|
|
|
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
|
+
*/
|
|
2044
2082
|
interface FormEvent<T = Element> extends SyntheticEvent<T> {
|
|
2045
2083
|
}
|
|
2046
2084
|
|
|
2047
2085
|
interface InvalidEvent<T = Element> extends SyntheticEvent<T> {
|
|
2048
|
-
target: EventTarget & T;
|
|
2049
2086
|
}
|
|
2050
2087
|
|
|
2051
|
-
|
|
2052
|
-
|
|
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;
|
|
2053
2099
|
}
|
|
2054
2100
|
|
|
2055
2101
|
interface InputEvent<T = Element> extends SyntheticEvent<T, NativeInputEvent> {
|
|
@@ -2119,6 +2165,13 @@ declare namespace React {
|
|
|
2119
2165
|
shiftKey: boolean;
|
|
2120
2166
|
}
|
|
2121
2167
|
|
|
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
|
+
|
|
2122
2175
|
interface TouchEvent<T = Element> extends UIEvent<T, NativeTouchEvent> {
|
|
2123
2176
|
altKey: boolean;
|
|
2124
2177
|
changedTouches: TouchList;
|
|
@@ -2174,11 +2227,19 @@ declare namespace React {
|
|
|
2174
2227
|
type CompositionEventHandler<T = Element> = EventHandler<CompositionEvent<T>>;
|
|
2175
2228
|
type DragEventHandler<T = Element> = EventHandler<DragEvent<T>>;
|
|
2176
2229
|
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
|
+
*/
|
|
2177
2235
|
type FormEventHandler<T = Element> = EventHandler<FormEvent<T>>;
|
|
2178
|
-
type ChangeEventHandler<
|
|
2236
|
+
type ChangeEventHandler<CurrentTarget = Element, Target = Element> = EventHandler<
|
|
2237
|
+
ChangeEvent<CurrentTarget, Target>
|
|
2238
|
+
>;
|
|
2179
2239
|
type InputEventHandler<T = Element> = EventHandler<InputEvent<T>>;
|
|
2180
2240
|
type KeyboardEventHandler<T = Element> = EventHandler<KeyboardEvent<T>>;
|
|
2181
2241
|
type MouseEventHandler<T = Element> = EventHandler<MouseEvent<T>>;
|
|
2242
|
+
type SubmitEventHandler<T = Element> = EventHandler<SubmitEvent<T>>;
|
|
2182
2243
|
type TouchEventHandler<T = Element> = EventHandler<TouchEvent<T>>;
|
|
2183
2244
|
type PointerEventHandler<T = Element> = EventHandler<PointerEvent<T>>;
|
|
2184
2245
|
type UIEventHandler<T = Element> = EventHandler<UIEvent<T>>;
|
|
@@ -2232,19 +2293,19 @@ declare namespace React {
|
|
|
2232
2293
|
onBlur?: FocusEventHandler<T> | undefined;
|
|
2233
2294
|
onBlurCapture?: FocusEventHandler<T> | undefined;
|
|
2234
2295
|
|
|
2235
|
-
//
|
|
2236
|
-
onChange?:
|
|
2237
|
-
onChangeCapture?:
|
|
2296
|
+
// form related Events
|
|
2297
|
+
onChange?: ChangeEventHandler<T> | undefined;
|
|
2298
|
+
onChangeCapture?: ChangeEventHandler<T> | undefined;
|
|
2238
2299
|
onBeforeInput?: InputEventHandler<T> | undefined;
|
|
2239
|
-
onBeforeInputCapture?:
|
|
2240
|
-
onInput?:
|
|
2241
|
-
onInputCapture?:
|
|
2242
|
-
onReset?:
|
|
2243
|
-
onResetCapture?:
|
|
2244
|
-
onSubmit?:
|
|
2245
|
-
onSubmitCapture?:
|
|
2246
|
-
onInvalid?:
|
|
2247
|
-
onInvalidCapture?:
|
|
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;
|
|
2248
2309
|
|
|
2249
2310
|
// Image Events
|
|
2250
2311
|
onLoad?: ReactEventHandler<T> | undefined;
|
|
@@ -2788,7 +2849,7 @@ declare namespace React {
|
|
|
2788
2849
|
|
|
2789
2850
|
// Living Standard
|
|
2790
2851
|
/**
|
|
2791
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/inert
|
|
2852
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/inert}
|
|
2792
2853
|
*/
|
|
2793
2854
|
inert?: boolean | undefined;
|
|
2794
2855
|
/**
|
|
@@ -3251,7 +3312,9 @@ declare namespace React {
|
|
|
3251
3312
|
value?: string | readonly string[] | number | undefined;
|
|
3252
3313
|
width?: number | string | undefined;
|
|
3253
3314
|
|
|
3254
|
-
|
|
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;
|
|
3255
3318
|
}
|
|
3256
3319
|
|
|
3257
3320
|
interface KeygenHTMLAttributes<T> extends HTMLAttributes<T> {
|
|
@@ -3416,7 +3479,9 @@ declare namespace React {
|
|
|
3416
3479
|
required?: boolean | undefined;
|
|
3417
3480
|
size?: number | undefined;
|
|
3418
3481
|
value?: string | readonly string[] | number | undefined;
|
|
3419
|
-
|
|
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;
|
|
3420
3485
|
}
|
|
3421
3486
|
|
|
3422
3487
|
interface SourceHTMLAttributes<T> extends HTMLAttributes<T> {
|
|
@@ -3468,7 +3533,9 @@ declare namespace React {
|
|
|
3468
3533
|
value?: string | readonly string[] | number | undefined;
|
|
3469
3534
|
wrap?: string | undefined;
|
|
3470
3535
|
|
|
3471
|
-
|
|
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;
|
|
3472
3539
|
}
|
|
3473
3540
|
|
|
3474
3541
|
interface TdHTMLAttributes<T> extends HTMLAttributes<T> {
|
|
@@ -3540,6 +3607,9 @@ declare namespace React {
|
|
|
3540
3607
|
method?: string | undefined;
|
|
3541
3608
|
min?: number | string | undefined;
|
|
3542
3609
|
name?: string | undefined;
|
|
3610
|
+
nonce?: string | undefined;
|
|
3611
|
+
part?: string | undefined;
|
|
3612
|
+
slot?: string | undefined;
|
|
3543
3613
|
style?: CSSProperties | undefined;
|
|
3544
3614
|
target?: string | undefined;
|
|
3545
3615
|
type?: string | undefined;
|
|
@@ -4057,7 +4127,6 @@ declare namespace React {
|
|
|
4057
4127
|
* Captures which component contained the exception, and its ancestors.
|
|
4058
4128
|
*/
|
|
4059
4129
|
componentStack?: string | null;
|
|
4060
|
-
digest?: string | null;
|
|
4061
4130
|
}
|
|
4062
4131
|
|
|
4063
4132
|
// 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.14/index.d.ts");
|
|
8
8
|
|
|
9
9
|
export {};
|
|
10
10
|
|
package/src/src/agent/index.ts
CHANGED
|
@@ -766,6 +766,14 @@ export {
|
|
|
766
766
|
type RuntimeProjectSkillLoaderLogger,
|
|
767
767
|
type RuntimeProjectSkillLoaderOptions,
|
|
768
768
|
} from "./runtime-project-skill-loader.js";
|
|
769
|
+
export {
|
|
770
|
+
getRuntimeProjectInstructions,
|
|
771
|
+
getRuntimeProjectSkillCatalog,
|
|
772
|
+
loadRuntimeBuiltinSkillCatalog,
|
|
773
|
+
type RuntimeProjectInstructionsOptions,
|
|
774
|
+
type RuntimeProjectSkillCatalogOptions,
|
|
775
|
+
type RuntimeProjectSteeringLookup,
|
|
776
|
+
} from "./runtime-project-skill-catalog.js";
|
|
769
777
|
export {
|
|
770
778
|
buildRuntimeLoadedSkillResponse,
|
|
771
779
|
buildRuntimeSkillDefinition,
|
|
@@ -1161,12 +1169,19 @@ export {
|
|
|
1161
1169
|
} from "./chat-handler.js";
|
|
1162
1170
|
export {
|
|
1163
1171
|
AgentRuntime,
|
|
1172
|
+
getProviderToolProfile,
|
|
1173
|
+
type ProviderToolCompatOptions,
|
|
1174
|
+
type ProviderToolCompatProvider,
|
|
1175
|
+
type ProviderToolProfile,
|
|
1164
1176
|
RunAlreadyExistsError,
|
|
1165
1177
|
RunCancelledError,
|
|
1166
1178
|
RunNotActiveError,
|
|
1167
1179
|
RunResumeSessionManager,
|
|
1168
1180
|
type RunResumeSessionManagerOptions,
|
|
1169
1181
|
type RunSessionStatus,
|
|
1182
|
+
sanitizeProviderToolSchema,
|
|
1183
|
+
selectProviderCompatibleToolNames,
|
|
1184
|
+
selectProviderCompatibleTools,
|
|
1170
1185
|
type SubmitResumeValueOutcome,
|
|
1171
1186
|
WaitConflictError,
|
|
1172
1187
|
WaitNotPendingError,
|
|
@@ -74,6 +74,15 @@ export {
|
|
|
74
74
|
parseToolArgs,
|
|
75
75
|
} from "./tool-helpers.js";
|
|
76
76
|
export type { ParsedToolArgs, ToolConfigEntry } from "./tool-helpers.js";
|
|
77
|
+
export {
|
|
78
|
+
getProviderToolProfile,
|
|
79
|
+
type ProviderToolCompatOptions,
|
|
80
|
+
type ProviderToolCompatProvider,
|
|
81
|
+
type ProviderToolProfile,
|
|
82
|
+
sanitizeProviderToolSchema,
|
|
83
|
+
selectProviderCompatibleToolNames,
|
|
84
|
+
selectProviderCompatibleTools,
|
|
85
|
+
} from "./provider-tool-compat.js";
|
|
77
86
|
export { accumulateUsage, getMaxSteps, normalizeInput } from "./input-utils.js";
|
|
78
87
|
export { createStreamState, processStream } from "./chat-stream-handler.js";
|
|
79
88
|
export type {
|
|
@@ -18,6 +18,10 @@ import {
|
|
|
18
18
|
createAnthropicWebFetchToolSet,
|
|
19
19
|
createAnthropicWebSearchToolSet,
|
|
20
20
|
} from "./provider-native-tools.js";
|
|
21
|
+
import {
|
|
22
|
+
sanitizeProviderToolSchema,
|
|
23
|
+
selectProviderCompatibleTools,
|
|
24
|
+
} from "./provider-tool-compat.js";
|
|
21
25
|
|
|
22
26
|
export interface ConvertToolsToRuntimeToolsOptions {
|
|
23
27
|
model?: string;
|
|
@@ -63,14 +67,19 @@ export function convertToolsToRuntimeTools(
|
|
|
63
67
|
options?: ConvertToolsToRuntimeToolsOptions,
|
|
64
68
|
): RuntimeToolSet | undefined {
|
|
65
69
|
const toolSet: RuntimeToolSet = {};
|
|
70
|
+
const compatibleTools = selectProviderCompatibleTools(tools, {
|
|
71
|
+
model: options?.model,
|
|
72
|
+
});
|
|
66
73
|
|
|
67
|
-
for (const def of
|
|
74
|
+
for (const def of compatibleTools) {
|
|
68
75
|
addRuntimeTool(
|
|
69
76
|
toolSet,
|
|
70
77
|
def.name,
|
|
71
78
|
createRuntimeTool({
|
|
72
79
|
description: def.description,
|
|
73
|
-
inputSchema: createRuntimeJsonSchema(
|
|
80
|
+
inputSchema: createRuntimeJsonSchema(
|
|
81
|
+
sanitizeProviderToolSchema(def.parameters, { model: options?.model }),
|
|
82
|
+
),
|
|
74
83
|
}),
|
|
75
84
|
);
|
|
76
85
|
}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import type { ToolDefinition } from "../../tool/index.js";
|
|
2
|
+
import type { JsonSchema } from "../../tool/schema/index.js";
|
|
3
|
+
|
|
4
|
+
export type ProviderToolCompatProvider =
|
|
5
|
+
| "anthropic"
|
|
6
|
+
| "google"
|
|
7
|
+
| "moonshot"
|
|
8
|
+
| "openai"
|
|
9
|
+
| "unknown";
|
|
10
|
+
|
|
11
|
+
export interface ProviderToolProfile {
|
|
12
|
+
provider: ProviderToolCompatProvider;
|
|
13
|
+
maxTools?: number;
|
|
14
|
+
sanitizeSchema: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ProviderToolCompatOptions {
|
|
18
|
+
model?: string;
|
|
19
|
+
requiredToolNames?: readonly string[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const OPENAI_MAX_TOOLS = 128;
|
|
23
|
+
const GOOGLE_UNSUPPORTED_SCHEMA_KEYS = new Set([
|
|
24
|
+
"$id",
|
|
25
|
+
"$ref",
|
|
26
|
+
"$schema",
|
|
27
|
+
"additionalProperties",
|
|
28
|
+
"allOf",
|
|
29
|
+
"default",
|
|
30
|
+
"exclusiveMaximum",
|
|
31
|
+
"exclusiveMinimum",
|
|
32
|
+
"oneOf",
|
|
33
|
+
"prefixItems",
|
|
34
|
+
]);
|
|
35
|
+
|
|
36
|
+
function normalizeModel(model?: string): string {
|
|
37
|
+
return model?.trim().toLowerCase() ?? "";
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function getProviderToolProfile(model?: string): ProviderToolProfile {
|
|
41
|
+
const normalized = normalizeModel(model);
|
|
42
|
+
const parts = normalized.split("/").filter(Boolean);
|
|
43
|
+
const provider = parts[0] === "veryfront-cloud" ? parts[1] : parts[0];
|
|
44
|
+
|
|
45
|
+
if (provider === "openai") {
|
|
46
|
+
return { provider: "openai", maxTools: OPENAI_MAX_TOOLS, sanitizeSchema: false };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (provider === "google" || provider === "google-ai-studio") {
|
|
50
|
+
return { provider: "google", sanitizeSchema: true };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (provider === "anthropic") {
|
|
54
|
+
return { provider: "anthropic", sanitizeSchema: false };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (provider === "moonshot") {
|
|
58
|
+
return { provider: "moonshot", sanitizeSchema: false };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return { provider: "unknown", sanitizeSchema: false };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function uniqueInOrder(values: readonly string[]): string[] {
|
|
65
|
+
const seen = new Set<string>();
|
|
66
|
+
const result: string[] = [];
|
|
67
|
+
|
|
68
|
+
for (const value of values) {
|
|
69
|
+
if (seen.has(value)) continue;
|
|
70
|
+
seen.add(value);
|
|
71
|
+
result.push(value);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function selectProviderCompatibleToolNames(
|
|
78
|
+
toolNames: readonly string[],
|
|
79
|
+
options: ProviderToolCompatOptions = {},
|
|
80
|
+
): string[] {
|
|
81
|
+
const profile = getProviderToolProfile(options.model);
|
|
82
|
+
const orderedToolNames = uniqueInOrder(toolNames);
|
|
83
|
+
|
|
84
|
+
if (profile.maxTools === undefined || orderedToolNames.length <= profile.maxTools) {
|
|
85
|
+
return orderedToolNames;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const available = new Set(orderedToolNames);
|
|
89
|
+
const requiredToolNames = uniqueInOrder(options.requiredToolNames ?? [])
|
|
90
|
+
.filter((toolName) => available.has(toolName));
|
|
91
|
+
const selected = [...requiredToolNames];
|
|
92
|
+
const selectedSet = new Set(selected);
|
|
93
|
+
|
|
94
|
+
for (const toolName of orderedToolNames) {
|
|
95
|
+
if (selected.length >= profile.maxTools) break;
|
|
96
|
+
if (selectedSet.has(toolName)) continue;
|
|
97
|
+
selected.push(toolName);
|
|
98
|
+
selectedSet.add(toolName);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return selected.slice(0, profile.maxTools);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function selectProviderCompatibleTools(
|
|
105
|
+
tools: readonly ToolDefinition[],
|
|
106
|
+
options: ProviderToolCompatOptions = {},
|
|
107
|
+
): ToolDefinition[] {
|
|
108
|
+
const toolsByName = new Map<string, ToolDefinition>();
|
|
109
|
+
for (const tool of tools) {
|
|
110
|
+
if (!toolsByName.has(tool.name)) toolsByName.set(tool.name, tool);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const selectedToolNames = selectProviderCompatibleToolNames(
|
|
114
|
+
[...toolsByName.keys()],
|
|
115
|
+
options,
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
return selectedToolNames
|
|
119
|
+
.map((toolName) => toolsByName.get(toolName))
|
|
120
|
+
.filter((tool): tool is ToolDefinition => tool !== undefined);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function isPlainRecord(value: unknown): value is Record<string, unknown> {
|
|
124
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function getLiteralType(value: unknown): JsonSchema["type"] | undefined {
|
|
128
|
+
switch (typeof value) {
|
|
129
|
+
case "string":
|
|
130
|
+
return "string";
|
|
131
|
+
case "number":
|
|
132
|
+
return Number.isInteger(value) ? "integer" : "number";
|
|
133
|
+
case "boolean":
|
|
134
|
+
return "boolean";
|
|
135
|
+
default:
|
|
136
|
+
return value === null ? "null" : undefined;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function getEnumValuesFromAnyOf(anyOf: unknown): unknown[] | undefined {
|
|
141
|
+
if (!Array.isArray(anyOf)) return undefined;
|
|
142
|
+
|
|
143
|
+
const values: unknown[] = [];
|
|
144
|
+
for (const option of anyOf) {
|
|
145
|
+
if (!isPlainRecord(option)) return undefined;
|
|
146
|
+
if ("const" in option) {
|
|
147
|
+
values.push(option.const);
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (Array.isArray(option.enum) && option.enum.length > 0) {
|
|
151
|
+
values.push(...option.enum);
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
return undefined;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return values.length > 0 ? uniqueUnknownValues(values) : undefined;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function uniqueUnknownValues(values: unknown[]): unknown[] {
|
|
161
|
+
const result: unknown[] = [];
|
|
162
|
+
for (const value of values) {
|
|
163
|
+
if (result.some((existing) => Object.is(existing, value))) continue;
|
|
164
|
+
result.push(value);
|
|
165
|
+
}
|
|
166
|
+
return result;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function getSharedLiteralType(values: readonly unknown[]): JsonSchema["type"] | undefined {
|
|
170
|
+
const literalTypes = values.map((value) => getLiteralType(value));
|
|
171
|
+
const firstType = literalTypes[0];
|
|
172
|
+
|
|
173
|
+
if (!firstType || literalTypes.some((literalType) => literalType !== firstType)) {
|
|
174
|
+
return undefined;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return firstType;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function getGoogleCompatibleSchemaType(type: unknown): unknown {
|
|
181
|
+
if (!Array.isArray(type)) return type;
|
|
182
|
+
|
|
183
|
+
const nonNullTypes = type.filter((value) => value !== "null");
|
|
184
|
+
return nonNullTypes.length === 1 ? nonNullTypes[0] : undefined;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function sanitizeGoogleSchemaValue(value: unknown): unknown {
|
|
188
|
+
if (Array.isArray(value)) {
|
|
189
|
+
return value.map((item) => sanitizeGoogleSchemaValue(item));
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (!isPlainRecord(value)) {
|
|
193
|
+
return value;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const sanitized: Record<string, unknown> = {};
|
|
197
|
+
const enumFromAnyOf = getEnumValuesFromAnyOf(value.anyOf);
|
|
198
|
+
const constValue = value.const;
|
|
199
|
+
|
|
200
|
+
for (const [key, child] of Object.entries(value)) {
|
|
201
|
+
if (key === "const" || key === "anyOf" || GOOGLE_UNSUPPORTED_SCHEMA_KEYS.has(key)) {
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (key === "type") {
|
|
206
|
+
const compatibleType = getGoogleCompatibleSchemaType(child);
|
|
207
|
+
if (compatibleType !== undefined) sanitized.type = compatibleType;
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (key === "properties" && isPlainRecord(child)) {
|
|
212
|
+
sanitized.properties = Object.fromEntries(
|
|
213
|
+
Object.entries(child).map(([propertyName, propertySchema]) => [
|
|
214
|
+
propertyName,
|
|
215
|
+
sanitizeGoogleSchemaValue(propertySchema),
|
|
216
|
+
]),
|
|
217
|
+
);
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (key === "items") {
|
|
222
|
+
sanitized.items = sanitizeGoogleSchemaValue(child);
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
sanitized[key] = sanitizeGoogleSchemaValue(child);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (enumFromAnyOf) {
|
|
230
|
+
sanitized.enum = enumFromAnyOf;
|
|
231
|
+
if (!sanitized.type) {
|
|
232
|
+
const sharedType = getSharedLiteralType(enumFromAnyOf);
|
|
233
|
+
if (sharedType) sanitized.type = sharedType;
|
|
234
|
+
}
|
|
235
|
+
} else if ("const" in value) {
|
|
236
|
+
sanitized.enum = [constValue];
|
|
237
|
+
if (!sanitized.type) {
|
|
238
|
+
const literalType = getLiteralType(constValue);
|
|
239
|
+
if (literalType) sanitized.type = literalType;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return sanitized;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export function sanitizeProviderToolSchema(
|
|
247
|
+
schema: JsonSchema,
|
|
248
|
+
options: Pick<ProviderToolCompatOptions, "model"> = {},
|
|
249
|
+
): JsonSchema {
|
|
250
|
+
const profile = getProviderToolProfile(options.model);
|
|
251
|
+
if (!profile.sanitizeSchema) return schema;
|
|
252
|
+
|
|
253
|
+
return sanitizeGoogleSchemaValue(schema) as JsonSchema;
|
|
254
|
+
}
|