veryfront 0.1.186 → 0.1.188
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/ag-ui-browser-encoder.d.ts.map +1 -1
- package/esm/src/agent/ag-ui-browser-encoder.js +18 -16
- package/esm/src/agent/index.d.ts +1 -0
- package/esm/src/agent/index.d.ts.map +1 -1
- package/esm/src/agent/index.js +1 -0
- package/esm/src/agent/provider-native-tool-inventory.d.ts +11 -0
- package/esm/src/agent/provider-native-tool-inventory.d.ts.map +1 -0
- package/esm/src/agent/provider-native-tool-inventory.js +39 -0
- package/esm/src/agent/runtime/chat-stream-handler.d.ts.map +1 -1
- package/esm/src/agent/runtime/chat-stream-handler.js +22 -2
- package/esm/src/agent/runtime/model-tool-converter.d.ts.map +1 -1
- package/esm/src/agent/runtime/model-tool-converter.js +15 -17
- package/esm/src/agent/runtime/tool-helpers.d.ts.map +1 -1
- package/esm/src/agent/runtime/tool-helpers.js +9 -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/src/agent/ag-ui-browser-encoder.ts +23 -16
- package/src/src/agent/index.ts +5 -0
- package/src/src/agent/provider-native-tool-inventory.ts +60 -0
- package/src/src/agent/runtime/chat-stream-handler.ts +28 -2
- package/src/src/agent/runtime/model-tool-converter.ts +18 -22
- package/src/src/agent/runtime/tool-helpers.ts +13 -1
- package/src/src/utils/version-constant.ts +1 -1
package/esm/deno.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ag-ui-browser-encoder.d.ts","sourceRoot":"","sources":["../../../src/src/agent/ag-ui-browser-encoder.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC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CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,uBAAuB;IACtC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,EAAE,OAAO,CAAC;IAClB,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,oBAAoB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAClC,gBAAgB,EAAE,OAAO,CAAC;IAC1B,gBAAgB,EAAE,OAAO,CAAC;IAC1B,QAAQ,EAAE,8BAA8B,CAAC;CAC1C;AAED,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,wBAAgB,6BAA6B,IAAI,uBAAuB,CAYvE;AAkLD,wBAAgB,wCAAwC,CACtD,KAAK,EAAE,uBAAuB,EAC9B,KAAK,EAAE,sBAAsB,GAC5B,uBAAuB,EAAE,CAwJ3B;AAED,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,uBAAuB,EAC9B,QAAQ,EAAE,aAAa,GAAG,IAAI,GAC7B,uBAAuB,EAAE,CAmC3B"}
|
|
@@ -129,6 +129,20 @@ function createStepEvent(state, type) {
|
|
|
129
129
|
},
|
|
130
130
|
};
|
|
131
131
|
}
|
|
132
|
+
function createReasoningEvent(state, event, type) {
|
|
133
|
+
const messageId = getReasoningMessageId(state, event);
|
|
134
|
+
return {
|
|
135
|
+
event: type,
|
|
136
|
+
payload: type === "ReasoningMessageStart"
|
|
137
|
+
? { messageId, role: "reasoning" }
|
|
138
|
+
: type === "ReasoningMessageContent"
|
|
139
|
+
? {
|
|
140
|
+
messageId,
|
|
141
|
+
delta: typeof event.delta === "string" ? event.delta : "",
|
|
142
|
+
}
|
|
143
|
+
: { messageId },
|
|
144
|
+
};
|
|
145
|
+
}
|
|
132
146
|
export function mapRuntimeStreamEventToAgUiBrowserEvents(state, event) {
|
|
133
147
|
if (event.type.startsWith("data-")) {
|
|
134
148
|
const name = event.type.slice("data-".length);
|
|
@@ -182,26 +196,14 @@ export function mapRuntimeStreamEventToAgUiBrowserEvents(state, event) {
|
|
|
182
196
|
}
|
|
183
197
|
case "reasoning-start":
|
|
184
198
|
state.sawVisibleOutput = true;
|
|
185
|
-
return [
|
|
186
|
-
event: "ReasoningMessageStart",
|
|
187
|
-
payload: { messageId: getReasoningMessageId(state, event), role: "reasoning" },
|
|
188
|
-
}];
|
|
199
|
+
return [createReasoningEvent(state, event, "ReasoningMessageStart")];
|
|
189
200
|
case "reasoning-delta":
|
|
190
201
|
state.sawVisibleOutput = true;
|
|
191
|
-
return [
|
|
192
|
-
event: "ReasoningMessageContent",
|
|
193
|
-
payload: {
|
|
194
|
-
messageId: getReasoningMessageId(state, event),
|
|
195
|
-
delta: typeof event.delta === "string" ? event.delta : "",
|
|
196
|
-
},
|
|
197
|
-
}];
|
|
202
|
+
return [createReasoningEvent(state, event, "ReasoningMessageContent")];
|
|
198
203
|
case "reasoning-end": {
|
|
199
|
-
const
|
|
204
|
+
const reasoningEvent = createReasoningEvent(state, event, "ReasoningMessageEnd");
|
|
200
205
|
state.reasoningMessageId = null;
|
|
201
|
-
return [
|
|
202
|
-
event: "ReasoningMessageEnd",
|
|
203
|
-
payload: { messageId },
|
|
204
|
-
}];
|
|
206
|
+
return [reasoningEvent];
|
|
205
207
|
}
|
|
206
208
|
case "tool-input-start":
|
|
207
209
|
state.sawVisibleOutput = true;
|
package/esm/src/agent/index.d.ts
CHANGED
|
@@ -86,6 +86,7 @@ export { agentAsTool, createWorkflow, getAgent, getAgentsAsTools, getAllAgentIds
|
|
|
86
86
|
export { agent } from "./factory.js";
|
|
87
87
|
export { type AgUiRuntimeContextItem, AgUiRuntimeContextItemSchema, type AgUiRuntimeInjectedTool, AgUiRuntimeInjectedToolSchema, type AgUiRuntimeMessage, AgUiRuntimeMessageSchema, type AgUiRuntimeRequest, AgUiRuntimeRequestSchema, } from "./runtime-ag-ui-contract.js";
|
|
88
88
|
export { type AgUiBrowserEncodedEvent, type AgUiBrowserEncoderState, type AgUiBrowserRunFinishedMetadata, type AgUiRuntimeStreamEvent, createAgUiBrowserEncoderState, finalizeAgUiBrowserEvents, mapRuntimeStreamEventToAgUiBrowserEvents, } from "./ag-ui-browser-encoder.js";
|
|
89
|
+
export { expandAllowedRemoteToolNames, getProviderNativeToolNames, type ProviderNativeToolInventoryOptions, } from "./provider-native-tool-inventory.js";
|
|
89
90
|
export { type AgUiCancelHandlerOptions, type AgUiResumeHandlerOptions, type AgUiResumeSignal, AgUiResumeSignalSchema, createAgUiCancelHandler, createAgUiResumeHandler, } from "./ag-ui-run-control.js";
|
|
90
91
|
export { type AgUiContextItem, type AgUiHandlerConfigWithAgent, type AgUiHandlerOptions, type AgUiInjectedTool, type AgUiRequest, AgUiRequestSchema, createAgUiHandler, } from "./ag-ui-handler.js";
|
|
91
92
|
export { type HumanInputField, type HumanInputFieldInput, HumanInputFieldSchema, type HumanInputOption, HumanInputOptionSchema, type HumanInputPendingRequest, HumanInputPendingRequestSchema, type HumanInputRequest, type HumanInputRequestInput, HumanInputRequestSchema, type HumanInputResult, HumanInputResultSchema, HumanInputResumeError, InvalidHumanInputResultError, waitForHumanInput, type WaitForHumanInputOptions, } from "./human-input.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/agent/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+EG;AACH,OAAO,yBAAyB,CAAC;AAGjC,YAAY,EACV,KAAK,EACL,WA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4B,CAAC;AACpC,OAAO,EACL,4BAA4B,EAC5B,0BAA0B,EAC1B,KAAK,kCAAkC,GACxC,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,KAAK,wBAAwB,EAC7B,KAAK,wBAAwB,EAC7B,KAAK,gBAAgB,EACrB,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,GACxB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,0BAA0B,EAC/B,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,qBAAqB,EACrB,KAAK,gBAAgB,EACrB,sBAAsB,EACtB,KAAK,wBAAwB,EAC7B,8BAA8B,EAC9B,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,EAC3B,uBAAuB,EACvB,KAAK,gBAAgB,EACrB,sBAAsB,EACtB,qBAAqB,EACrB,4BAA4B,EAC5B,iBAAiB,EACjB,KAAK,wBAAwB,GAC9B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,KAAK,uBAAuB,EAC5B,KAAK,8BAA8B,EACnC,KAAK,6BAA6B,EAClC,KAAK,0BAA0B,EAC/B,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACvB,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,YAAY,EACZ,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,EACvB,KAAK,8BAA8B,EACnC,KAAK,gBAAgB,EACrB,KAAK,wBAAwB,EAC7B,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,oBAAoB,CAAC"}
|
package/esm/src/agent/index.js
CHANGED
|
@@ -85,6 +85,7 @@ export { agentAsTool, createWorkflow, getAgent, getAgentsAsTools, getAllAgentIds
|
|
|
85
85
|
export { agent } from "./factory.js";
|
|
86
86
|
export { AgUiRuntimeContextItemSchema, AgUiRuntimeInjectedToolSchema, AgUiRuntimeMessageSchema, AgUiRuntimeRequestSchema, } from "./runtime-ag-ui-contract.js";
|
|
87
87
|
export { createAgUiBrowserEncoderState, finalizeAgUiBrowserEvents, mapRuntimeStreamEventToAgUiBrowserEvents, } from "./ag-ui-browser-encoder.js";
|
|
88
|
+
export { expandAllowedRemoteToolNames, getProviderNativeToolNames, } from "./provider-native-tool-inventory.js";
|
|
88
89
|
export { AgUiResumeSignalSchema, createAgUiCancelHandler, createAgUiResumeHandler, } from "./ag-ui-run-control.js";
|
|
89
90
|
export { AgUiRequestSchema, createAgUiHandler, } from "./ag-ui-handler.js";
|
|
90
91
|
export { HumanInputFieldSchema, HumanInputOptionSchema, HumanInputPendingRequestSchema, HumanInputRequestSchema, HumanInputResultSchema, HumanInputResumeError, InvalidHumanInputResultError, waitForHumanInput, } from "./human-input.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface ProviderNativeToolInventoryOptions {
|
|
2
|
+
model?: string;
|
|
3
|
+
provider?: string;
|
|
4
|
+
}
|
|
5
|
+
interface ExpandAllowedRemoteToolNamesOptions extends ProviderNativeToolInventoryOptions {
|
|
6
|
+
toolNames: readonly string[];
|
|
7
|
+
}
|
|
8
|
+
export declare function getProviderNativeToolNames(options?: ProviderNativeToolInventoryOptions): string[];
|
|
9
|
+
export declare function expandAllowedRemoteToolNames(options: ExpandAllowedRemoteToolNamesOptions): string[];
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=provider-native-tool-inventory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-native-tool-inventory.d.ts","sourceRoot":"","sources":["../../../src/src/agent/provider-native-tool-inventory.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,kCAAkC;IACjD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,UAAU,mCAAoC,SAAQ,kCAAkC;IACtF,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;CAC9B;AA2BD,wBAAgB,0BAA0B,CACxC,OAAO,CAAC,EAAE,kCAAkC,GAC3C,MAAM,EAAE,CAOV;AAED,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,mCAAmC,GAC3C,MAAM,EAAE,CAOV"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const ANTHROPIC_PROVIDER_NATIVE_TOOL_NAMES = [
|
|
2
|
+
"web_fetch",
|
|
3
|
+
"web_search",
|
|
4
|
+
];
|
|
5
|
+
function resolveHostedProvider(model) {
|
|
6
|
+
if (!model) {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
const [provider, second] = model.split("/", 3);
|
|
10
|
+
if (!provider) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
if (provider === "veryfront-cloud") {
|
|
14
|
+
return second || undefined;
|
|
15
|
+
}
|
|
16
|
+
return provider;
|
|
17
|
+
}
|
|
18
|
+
function resolveProvider(options) {
|
|
19
|
+
if (options?.provider && options.provider.length > 0) {
|
|
20
|
+
return options.provider;
|
|
21
|
+
}
|
|
22
|
+
return resolveHostedProvider(options?.model);
|
|
23
|
+
}
|
|
24
|
+
export function getProviderNativeToolNames(options) {
|
|
25
|
+
switch (resolveProvider(options)) {
|
|
26
|
+
case "anthropic":
|
|
27
|
+
return [...ANTHROPIC_PROVIDER_NATIVE_TOOL_NAMES];
|
|
28
|
+
default:
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export function expandAllowedRemoteToolNames(options) {
|
|
33
|
+
return [
|
|
34
|
+
...new Set([
|
|
35
|
+
...options.toolNames,
|
|
36
|
+
...getProviderNativeToolNames(options),
|
|
37
|
+
]),
|
|
38
|
+
].sort();
|
|
39
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-stream-handler.d.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|
+
{"version":3,"file":"chat-stream-handler.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/runtime/chat-stream-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAqB,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAWtF,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,eAAe;IAC9B,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;IAC1C,WAAW,EAAE,mBAAmB,EAAE,CAAC;IACnC,KAAK,EAAE;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,gBAAgB,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC;CAChF;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE;QAChB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,KAAK,IAAI,CAAC;CACZ;AAoHD,wBAAgB,iBAAiB,IAAI,eAAe,CAQnD;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,mBAAmB,EAC3B,KAAK,EAAE,eAAe,EACtB,UAAU,EAAE,+BAA+B,EAC3C,OAAO,EAAE,WAAW,EACpB,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,SAAS,CAAC,EAAE,mBAAmB,EAC/B,WAAW,CAAC,EAAE,WAAW,GACxB,OAAO,CAAC,IAAI,CAAC,CAqPf"}
|
|
@@ -24,6 +24,24 @@ function normalizeToolInputString(input) {
|
|
|
24
24
|
}
|
|
25
25
|
return JSON.stringify(input ?? null) ?? "null";
|
|
26
26
|
}
|
|
27
|
+
function mergeToolInputDelta(currentArguments, nextDelta) {
|
|
28
|
+
if (currentArguments === "{}" && nextDelta.trimStart().startsWith("{")) {
|
|
29
|
+
return nextDelta;
|
|
30
|
+
}
|
|
31
|
+
return currentArguments + nextDelta;
|
|
32
|
+
}
|
|
33
|
+
function mergeToolCallInput(currentArguments, nextInput) {
|
|
34
|
+
if (currentArguments.length === 0) {
|
|
35
|
+
return nextInput;
|
|
36
|
+
}
|
|
37
|
+
if (nextInput.trim() === "{}" && currentArguments.trim().startsWith("{")) {
|
|
38
|
+
return currentArguments;
|
|
39
|
+
}
|
|
40
|
+
if (currentArguments.trim() === "{}" && nextInput.trim().startsWith("{")) {
|
|
41
|
+
return nextInput;
|
|
42
|
+
}
|
|
43
|
+
return nextInput;
|
|
44
|
+
}
|
|
27
45
|
function normalizeToolInputObject(input) {
|
|
28
46
|
if (isRecord(input)) {
|
|
29
47
|
return input;
|
|
@@ -166,7 +184,7 @@ export function processStream(result, state, controller, encoder, textPartId, ca
|
|
|
166
184
|
const tc = state.toolCalls.get(toolId);
|
|
167
185
|
if (!tc)
|
|
168
186
|
break;
|
|
169
|
-
tc.arguments
|
|
187
|
+
tc.arguments = mergeToolInputDelta(tc.arguments, typedPart.delta);
|
|
170
188
|
sendSSE(controller, encoder, {
|
|
171
189
|
type: "tool-input-delta",
|
|
172
190
|
toolCallId: toolId,
|
|
@@ -178,10 +196,12 @@ export function processStream(result, state, controller, encoder, textPartId, ca
|
|
|
178
196
|
// tool-call fires when the full tool call is available
|
|
179
197
|
const toolId = typedPart.toolCallId;
|
|
180
198
|
const inputStr = normalizeToolInputString(typedPart.input);
|
|
199
|
+
const previousArguments = state.toolCalls.get(toolId)?.arguments ?? "";
|
|
200
|
+
const resolvedArguments = mergeToolCallInput(previousArguments, inputStr);
|
|
181
201
|
state.toolCalls.set(toolId, {
|
|
182
202
|
id: toolId,
|
|
183
203
|
name: typedPart.toolName,
|
|
184
|
-
arguments:
|
|
204
|
+
arguments: resolvedArguments,
|
|
185
205
|
providerExecuted: typedPart.providerExecuted,
|
|
186
206
|
dynamic: typedPart.dynamic,
|
|
187
207
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-tool-converter.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/runtime/model-tool-converter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"model-tool-converter.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/runtime/model-tool-converter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAW9D,MAAM,WAAW,iCAAiC;IAChD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B;AA8BD;;;;;GAKG;AACH,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,cAAc,EAAE,EACvB,OAAO,CAAC,EAAE,iCAAiC,GAC1C,cAAc,GAAG,SAAS,CAwB5B"}
|
|
@@ -1,27 +1,25 @@
|
|
|
1
|
+
import { getProviderNativeToolNames } from "../provider-native-tool-inventory.js";
|
|
1
2
|
import { addRuntimeTool, createRuntimeJsonSchema, createRuntimeTool, } from "./runtime-tool-builder.js";
|
|
2
3
|
import { createAnthropicWebFetchToolSet, createAnthropicWebSearchToolSet, } from "./provider-native-tools.js";
|
|
3
|
-
function resolveHostedProvider(model) {
|
|
4
|
-
if (!model)
|
|
5
|
-
return undefined;
|
|
6
|
-
const [provider, second] = model.split("/", 3);
|
|
7
|
-
if (!provider)
|
|
8
|
-
return undefined;
|
|
9
|
-
if (provider === "veryfront-cloud") {
|
|
10
|
-
return second || undefined;
|
|
11
|
-
}
|
|
12
|
-
return provider;
|
|
13
|
-
}
|
|
14
4
|
function resolveProviderNativeTools(options) {
|
|
15
|
-
|
|
5
|
+
const providerNativeToolNames = new Set(getProviderNativeToolNames({
|
|
6
|
+
model: options?.model,
|
|
7
|
+
}));
|
|
8
|
+
if (providerNativeToolNames.size === 0) {
|
|
16
9
|
return undefined;
|
|
17
10
|
}
|
|
18
|
-
|
|
11
|
+
const allowedProviderNativeToolNames = options?.allowedToolNames?.filter((toolName) => providerNativeToolNames.has(toolName)) ?? [];
|
|
12
|
+
if (allowedProviderNativeToolNames.length === 0) {
|
|
19
13
|
return undefined;
|
|
20
14
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
15
|
+
const toolSet = {};
|
|
16
|
+
if (allowedProviderNativeToolNames.includes("web_search")) {
|
|
17
|
+
Object.assign(toolSet, createAnthropicWebSearchToolSet());
|
|
18
|
+
}
|
|
19
|
+
if (allowedProviderNativeToolNames.includes("web_fetch")) {
|
|
20
|
+
Object.assign(toolSet, createAnthropicWebFetchToolSet());
|
|
21
|
+
}
|
|
22
|
+
return Object.keys(toolSet).length > 0 ? toolSet : undefined;
|
|
25
23
|
}
|
|
26
24
|
/**
|
|
27
25
|
* Convert veryfront tool definitions to the current model-runtime ToolSet.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-helpers.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/runtime/tool-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,IAAI,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAaxG;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;
|
|
1
|
+
{"version":3,"file":"tool-helpers.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/runtime/tool-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,IAAI,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAaxG;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAYD;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACxC,cAAc,CAyBhB;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEnD;AAED;;;GAGG;AAEH,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC;AAqHvD,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,GAAG,SAAS,EAC/D,QAAQ,EAAE,MAAM,GACf,IAAI,GAAG,IAAI,CAmBb;AAED,wBAAsB,qBAAqB,CACzC,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,WAAW,EAAE,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,GAAG,SAAS,EAC/D,OAAO,CAAC,EAAE,oBAAoB,EAC9B,sBAAsB,CAAC,EAAE,MAAM,EAAE,EACjC,iBAAiB,CAAC,EAAE,gBAAgB,EAAE,GACrC,OAAO,CAAC,OAAO,CAAC,CAoClB;AAoBD;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CACrC,WAAW,EAAE,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,GAAG,SAAS,EAC/D,OAAO,CAAC,EAAE;IACR,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,sBAAsB,CAAC,EAAE,MAAM,EAAE,CAAC;IAClC,iBAAiB,CAAC,EAAE,gBAAgB,EAAE,CAAC;IACvC,iBAAiB,CAAC,EAAE,oBAAoB,CAAC;CAC1C,GACA,OAAO,CAAC,cAAc,EAAE,CAAC,CA+E3B"}
|
|
@@ -12,6 +12,13 @@ import { serverLogger } from "../../utils/index.js";
|
|
|
12
12
|
import { createError, toError } from "../../errors/veryfront-error.js";
|
|
13
13
|
import { executeRemoteIntegrationTool, isRemoteIntegrationTool, } from "../../integrations/remote-tools.js";
|
|
14
14
|
const logger = serverLogger.component("agent");
|
|
15
|
+
function stripLeadingEmptyObjectPlaceholder(rawArgs) {
|
|
16
|
+
let normalized = rawArgs.trim();
|
|
17
|
+
while (normalized.startsWith("{}") && normalized.slice(2).trimStart().startsWith("{")) {
|
|
18
|
+
normalized = normalized.slice(2).trimStart();
|
|
19
|
+
}
|
|
20
|
+
return normalized;
|
|
21
|
+
}
|
|
15
22
|
/**
|
|
16
23
|
* Parse tool arguments from raw string or object.
|
|
17
24
|
* Returns parsed args and optional error message.
|
|
@@ -20,10 +27,11 @@ export function parseToolArgs(rawArgs) {
|
|
|
20
27
|
try {
|
|
21
28
|
// Handle empty string or whitespace-only string as empty object
|
|
22
29
|
if (typeof rawArgs === "string") {
|
|
23
|
-
const trimmed = rawArgs
|
|
30
|
+
const trimmed = stripLeadingEmptyObjectPlaceholder(rawArgs);
|
|
24
31
|
if (trimmed === "" || trimmed === "{}") {
|
|
25
32
|
return { args: {} };
|
|
26
33
|
}
|
|
34
|
+
rawArgs = trimmed;
|
|
27
35
|
}
|
|
28
36
|
const parsed = typeof rawArgs === "string" ? JSON.parse(rawArgs) : rawArgs;
|
|
29
37
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.1.
|
|
1
|
+
export declare const VERSION = "0.1.188";
|
|
2
2
|
//# sourceMappingURL=version-constant.d.ts.map
|
package/package.json
CHANGED
package/src/deno.js
CHANGED
|
@@ -200,6 +200,25 @@ function createStepEvent(
|
|
|
200
200
|
};
|
|
201
201
|
}
|
|
202
202
|
|
|
203
|
+
function createReasoningEvent(
|
|
204
|
+
state: AgUiBrowserEncoderState,
|
|
205
|
+
event: AgUiRuntimeStreamEvent,
|
|
206
|
+
type: "ReasoningMessageStart" | "ReasoningMessageContent" | "ReasoningMessageEnd",
|
|
207
|
+
): AgUiBrowserEncodedEvent {
|
|
208
|
+
const messageId = getReasoningMessageId(state, event);
|
|
209
|
+
return {
|
|
210
|
+
event: type,
|
|
211
|
+
payload: type === "ReasoningMessageStart"
|
|
212
|
+
? { messageId, role: "reasoning" }
|
|
213
|
+
: type === "ReasoningMessageContent"
|
|
214
|
+
? {
|
|
215
|
+
messageId,
|
|
216
|
+
delta: typeof event.delta === "string" ? event.delta : "",
|
|
217
|
+
}
|
|
218
|
+
: { messageId },
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
|
|
203
222
|
export function mapRuntimeStreamEventToAgUiBrowserEvents(
|
|
204
223
|
state: AgUiBrowserEncoderState,
|
|
205
224
|
event: AgUiRuntimeStreamEvent,
|
|
@@ -261,28 +280,16 @@ export function mapRuntimeStreamEventToAgUiBrowserEvents(
|
|
|
261
280
|
|
|
262
281
|
case "reasoning-start":
|
|
263
282
|
state.sawVisibleOutput = true;
|
|
264
|
-
return [
|
|
265
|
-
event: "ReasoningMessageStart",
|
|
266
|
-
payload: { messageId: getReasoningMessageId(state, event), role: "reasoning" },
|
|
267
|
-
}];
|
|
283
|
+
return [createReasoningEvent(state, event, "ReasoningMessageStart")];
|
|
268
284
|
|
|
269
285
|
case "reasoning-delta":
|
|
270
286
|
state.sawVisibleOutput = true;
|
|
271
|
-
return [
|
|
272
|
-
event: "ReasoningMessageContent",
|
|
273
|
-
payload: {
|
|
274
|
-
messageId: getReasoningMessageId(state, event),
|
|
275
|
-
delta: typeof event.delta === "string" ? event.delta : "",
|
|
276
|
-
},
|
|
277
|
-
}];
|
|
287
|
+
return [createReasoningEvent(state, event, "ReasoningMessageContent")];
|
|
278
288
|
|
|
279
289
|
case "reasoning-end": {
|
|
280
|
-
const
|
|
290
|
+
const reasoningEvent = createReasoningEvent(state, event, "ReasoningMessageEnd");
|
|
281
291
|
state.reasoningMessageId = null;
|
|
282
|
-
return [
|
|
283
|
-
event: "ReasoningMessageEnd",
|
|
284
|
-
payload: { messageId },
|
|
285
|
-
}];
|
|
292
|
+
return [reasoningEvent];
|
|
286
293
|
}
|
|
287
294
|
|
|
288
295
|
case "tool-input-start":
|
package/src/src/agent/index.ts
CHANGED
|
@@ -160,6 +160,11 @@ export {
|
|
|
160
160
|
finalizeAgUiBrowserEvents,
|
|
161
161
|
mapRuntimeStreamEventToAgUiBrowserEvents,
|
|
162
162
|
} from "./ag-ui-browser-encoder.js";
|
|
163
|
+
export {
|
|
164
|
+
expandAllowedRemoteToolNames,
|
|
165
|
+
getProviderNativeToolNames,
|
|
166
|
+
type ProviderNativeToolInventoryOptions,
|
|
167
|
+
} from "./provider-native-tool-inventory.js";
|
|
163
168
|
export {
|
|
164
169
|
type AgUiCancelHandlerOptions,
|
|
165
170
|
type AgUiResumeHandlerOptions,
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const ANTHROPIC_PROVIDER_NATIVE_TOOL_NAMES = [
|
|
2
|
+
"web_fetch",
|
|
3
|
+
"web_search",
|
|
4
|
+
] as const;
|
|
5
|
+
|
|
6
|
+
export interface ProviderNativeToolInventoryOptions {
|
|
7
|
+
model?: string;
|
|
8
|
+
provider?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface ExpandAllowedRemoteToolNamesOptions extends ProviderNativeToolInventoryOptions {
|
|
12
|
+
toolNames: readonly string[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function resolveHostedProvider(model?: string): string | undefined {
|
|
16
|
+
if (!model) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const [provider, second] = model.split("/", 3);
|
|
21
|
+
if (!provider) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (provider === "veryfront-cloud") {
|
|
26
|
+
return second || undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return provider;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function resolveProvider(options?: ProviderNativeToolInventoryOptions): string | undefined {
|
|
33
|
+
if (options?.provider && options.provider.length > 0) {
|
|
34
|
+
return options.provider;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return resolveHostedProvider(options?.model);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function getProviderNativeToolNames(
|
|
41
|
+
options?: ProviderNativeToolInventoryOptions,
|
|
42
|
+
): string[] {
|
|
43
|
+
switch (resolveProvider(options)) {
|
|
44
|
+
case "anthropic":
|
|
45
|
+
return [...ANTHROPIC_PROVIDER_NATIVE_TOOL_NAMES];
|
|
46
|
+
default:
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function expandAllowedRemoteToolNames(
|
|
52
|
+
options: ExpandAllowedRemoteToolNamesOptions,
|
|
53
|
+
): string[] {
|
|
54
|
+
return [
|
|
55
|
+
...new Set([
|
|
56
|
+
...options.toolNames,
|
|
57
|
+
...getProviderNativeToolNames(options),
|
|
58
|
+
]),
|
|
59
|
+
].sort();
|
|
60
|
+
}
|
|
@@ -66,6 +66,30 @@ function normalizeToolInputString(input: unknown): string {
|
|
|
66
66
|
return JSON.stringify(input ?? null) ?? "null";
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
function mergeToolInputDelta(currentArguments: string, nextDelta: string): string {
|
|
70
|
+
if (currentArguments === "{}" && nextDelta.trimStart().startsWith("{")) {
|
|
71
|
+
return nextDelta;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return currentArguments + nextDelta;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function mergeToolCallInput(currentArguments: string, nextInput: string): string {
|
|
78
|
+
if (currentArguments.length === 0) {
|
|
79
|
+
return nextInput;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (nextInput.trim() === "{}" && currentArguments.trim().startsWith("{")) {
|
|
83
|
+
return currentArguments;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (currentArguments.trim() === "{}" && nextInput.trim().startsWith("{")) {
|
|
87
|
+
return nextInput;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return nextInput;
|
|
91
|
+
}
|
|
92
|
+
|
|
69
93
|
function normalizeToolInputObject(input: unknown): Record<string, unknown> {
|
|
70
94
|
if (isRecord(input)) {
|
|
71
95
|
return input;
|
|
@@ -250,7 +274,7 @@ export function processStream(
|
|
|
250
274
|
const tc = state.toolCalls.get(toolId);
|
|
251
275
|
if (!tc) break;
|
|
252
276
|
|
|
253
|
-
tc.arguments
|
|
277
|
+
tc.arguments = mergeToolInputDelta(tc.arguments, typedPart.delta);
|
|
254
278
|
sendSSE(controller, encoder, {
|
|
255
279
|
type: "tool-input-delta",
|
|
256
280
|
toolCallId: toolId,
|
|
@@ -263,10 +287,12 @@ export function processStream(
|
|
|
263
287
|
// tool-call fires when the full tool call is available
|
|
264
288
|
const toolId = typedPart.toolCallId;
|
|
265
289
|
const inputStr = normalizeToolInputString(typedPart.input);
|
|
290
|
+
const previousArguments = state.toolCalls.get(toolId)?.arguments ?? "";
|
|
291
|
+
const resolvedArguments = mergeToolCallInput(previousArguments, inputStr);
|
|
266
292
|
state.toolCalls.set(toolId, {
|
|
267
293
|
id: toolId,
|
|
268
294
|
name: typedPart.toolName,
|
|
269
|
-
arguments:
|
|
295
|
+
arguments: resolvedArguments,
|
|
270
296
|
providerExecuted: typedPart.providerExecuted,
|
|
271
297
|
dynamic: typedPart.dynamic,
|
|
272
298
|
});
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* @module agent/runtime/model-tool-converter
|
|
8
8
|
*/
|
|
9
9
|
import type { ToolDefinition } from "../../tool/index.js";
|
|
10
|
+
import { getProviderNativeToolNames } from "../provider-native-tool-inventory.js";
|
|
10
11
|
import type { RuntimeToolSet } from "./runtime-tool-types.js";
|
|
11
12
|
import {
|
|
12
13
|
addRuntimeTool,
|
|
@@ -23,37 +24,32 @@ export interface ConvertToolsToRuntimeToolsOptions {
|
|
|
23
24
|
allowedToolNames?: string[];
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
function resolveHostedProvider(model?: string): string | undefined {
|
|
27
|
-
if (!model) return undefined;
|
|
28
|
-
|
|
29
|
-
const [provider, second] = model.split("/", 3);
|
|
30
|
-
if (!provider) return undefined;
|
|
31
|
-
if (provider === "veryfront-cloud") {
|
|
32
|
-
return second || undefined;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return provider;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
27
|
function resolveProviderNativeTools(
|
|
39
28
|
options?: ConvertToolsToRuntimeToolsOptions,
|
|
40
29
|
): RuntimeToolSet | undefined {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
) {
|
|
30
|
+
const providerNativeToolNames = new Set(getProviderNativeToolNames({
|
|
31
|
+
model: options?.model,
|
|
32
|
+
}));
|
|
33
|
+
|
|
34
|
+
if (providerNativeToolNames.size === 0) {
|
|
46
35
|
return undefined;
|
|
47
36
|
}
|
|
48
37
|
|
|
49
|
-
|
|
38
|
+
const allowedProviderNativeToolNames =
|
|
39
|
+
options?.allowedToolNames?.filter((toolName) => providerNativeToolNames.has(toolName)) ?? [];
|
|
40
|
+
if (allowedProviderNativeToolNames.length === 0) {
|
|
50
41
|
return undefined;
|
|
51
42
|
}
|
|
52
43
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
44
|
+
const toolSet: RuntimeToolSet = {};
|
|
45
|
+
if (allowedProviderNativeToolNames.includes("web_search")) {
|
|
46
|
+
Object.assign(toolSet, createAnthropicWebSearchToolSet());
|
|
47
|
+
}
|
|
48
|
+
if (allowedProviderNativeToolNames.includes("web_fetch")) {
|
|
49
|
+
Object.assign(toolSet, createAnthropicWebFetchToolSet());
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return Object.keys(toolSet).length > 0 ? toolSet : undefined;
|
|
57
53
|
}
|
|
58
54
|
|
|
59
55
|
/**
|
|
@@ -27,6 +27,16 @@ export interface ParsedToolArgs {
|
|
|
27
27
|
error?: string;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
function stripLeadingEmptyObjectPlaceholder(rawArgs: string): string {
|
|
31
|
+
let normalized = rawArgs.trim();
|
|
32
|
+
|
|
33
|
+
while (normalized.startsWith("{}") && normalized.slice(2).trimStart().startsWith("{")) {
|
|
34
|
+
normalized = normalized.slice(2).trimStart();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return normalized;
|
|
38
|
+
}
|
|
39
|
+
|
|
30
40
|
/**
|
|
31
41
|
* Parse tool arguments from raw string or object.
|
|
32
42
|
* Returns parsed args and optional error message.
|
|
@@ -37,10 +47,12 @@ export function parseToolArgs(
|
|
|
37
47
|
try {
|
|
38
48
|
// Handle empty string or whitespace-only string as empty object
|
|
39
49
|
if (typeof rawArgs === "string") {
|
|
40
|
-
const trimmed = rawArgs
|
|
50
|
+
const trimmed = stripLeadingEmptyObjectPlaceholder(rawArgs);
|
|
41
51
|
if (trimmed === "" || trimmed === "{}") {
|
|
42
52
|
return { args: {} };
|
|
43
53
|
}
|
|
54
|
+
|
|
55
|
+
rawArgs = trimmed;
|
|
44
56
|
}
|
|
45
57
|
|
|
46
58
|
const parsed = typeof rawArgs === "string" ? JSON.parse(rawArgs) : rawArgs;
|