veryfront 0.1.658 → 0.1.660
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/extensions/ext-llm-anthropic/src/anthropic-stream.d.ts.map +1 -1
- package/esm/extensions/ext-llm-anthropic/src/anthropic-stream.js +7 -1
- package/esm/src/agent/runtime/load-skill-tool.d.ts.map +1 -1
- package/esm/src/agent/runtime/load-skill-tool.js +39 -2
- package/esm/src/chat/provider-errors.d.ts.map +1 -1
- package/esm/src/chat/provider-errors.js +11 -0
- package/esm/src/tool/remote-mcp.d.ts.map +1 -1
- package/esm/src/tool/remote-mcp.js +87 -15
- 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/esm/deno.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic-stream.d.ts","sourceRoot":"","sources":["../../../../src/extensions/ext-llm-anthropic/src/anthropic-stream.ts"],"names":[],"mappings":"AAOA,KAAK,YAAY,GAAG;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B,CAAC;
|
|
1
|
+
{"version":3,"file":"anthropic-stream.d.ts","sourceRoot":"","sources":["../../../../src/extensions/ext-llm-anthropic/src/anthropic-stream.ts"],"names":[],"mappings":"AAOA,KAAK,YAAY,GAAG;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B,CAAC;AAsBF,wBAAgB,8BAA8B,CAC5C,GAAG,EAAE,OAAO,GACX,MAAM,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAgBlD;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,YAAY,GAAG,SAAS,CAsBhF;AAED,wBAAuB,8BAA8B,CACnD,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,GACjC,aAAa,CAAC,OAAO,CAAC,CA0PxB"}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { mergeUsage, parseSseChunk, readRecord, stringifyJsonValue, } from "../../../src/provider/shared/index.js";
|
|
2
|
+
function isEmptyRecord(value) {
|
|
3
|
+
return Boolean(value &&
|
|
4
|
+
typeof value === "object" &&
|
|
5
|
+
!Array.isArray(value) &&
|
|
6
|
+
Object.keys(value).length === 0);
|
|
7
|
+
}
|
|
2
8
|
export function normalizeAnthropicFinishReason(raw) {
|
|
3
9
|
if (typeof raw !== "string") {
|
|
4
10
|
return null;
|
|
@@ -115,7 +121,7 @@ export async function* streamAnthropicCompatibleParts(stream) {
|
|
|
115
121
|
...(providerExecuted ? { providerExecuted } : {}),
|
|
116
122
|
};
|
|
117
123
|
const initialInput = contentBlock.input;
|
|
118
|
-
if (initialInput !== undefined) {
|
|
124
|
+
if (initialInput !== undefined && !isEmptyRecord(initialInput)) {
|
|
119
125
|
const serializedInput = stringifyJsonValue(initialInput);
|
|
120
126
|
current.input += serializedInput;
|
|
121
127
|
yield {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-skill-tool.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/runtime/load-skill-tool.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAEpE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAchD,OAAO,KAAK,EAEV,0BAA0B,EAC1B,yBAAyB,EA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AA0B,GAC1B,mCAAmC,GACnC,2BAA2B,CAAC;AAqJhC,sCAAsC;AACtC,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,2BAA2B,GACnC,IAAI,CAAC,yBAAyB,EAAE,0BAA0B,CAAC,CAmC7D"}
|
|
@@ -65,6 +65,43 @@ function buildMissingSkillError(options, skillId) {
|
|
|
65
65
|
error: `Skill not found: ${skillId}. Available skills: ${available}`,
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
|
+
function buildRuntimeLoadSkillDescription(options) {
|
|
69
|
+
if (options.description) {
|
|
70
|
+
return options.description;
|
|
71
|
+
}
|
|
72
|
+
if (!options.context.availableSkillIds && !options.builtinSkillIds) {
|
|
73
|
+
return RUNTIME_LOAD_SKILL_DESCRIPTION;
|
|
74
|
+
}
|
|
75
|
+
const knownIds = new Set([
|
|
76
|
+
...(options.context.availableSkillIds ?? []),
|
|
77
|
+
...(options.builtinSkillIds ?? []),
|
|
78
|
+
]);
|
|
79
|
+
const available = [...knownIds].sort().join(", ") || "none";
|
|
80
|
+
return `${RUNTIME_LOAD_SKILL_DESCRIPTION} Available skill IDs: ${available}. Do not invent skill IDs. Only call load_skill with one of these IDs.`;
|
|
81
|
+
}
|
|
82
|
+
function getKnownRuntimeSkillIds(options) {
|
|
83
|
+
if (!options.context.availableSkillIds && !options.builtinSkillIds) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
return [
|
|
87
|
+
...new Set([
|
|
88
|
+
...(options.context.availableSkillIds ?? []),
|
|
89
|
+
...(options.builtinSkillIds ?? []),
|
|
90
|
+
]),
|
|
91
|
+
].sort();
|
|
92
|
+
}
|
|
93
|
+
function buildRuntimeLoadSkillInputSchema(options) {
|
|
94
|
+
const knownIds = getKnownRuntimeSkillIds(options);
|
|
95
|
+
if (!knownIds || knownIds.length === 0) {
|
|
96
|
+
return runtimeLoadSkillToolInputSchema;
|
|
97
|
+
}
|
|
98
|
+
const [first, ...rest] = knownIds;
|
|
99
|
+
const enumValues = [first, ...rest];
|
|
100
|
+
return defineSchema((v) => v.object({
|
|
101
|
+
skillId: v.enum(enumValues).describe(`The skill ID to load. Available skill IDs: ${knownIds.join(", ")}`),
|
|
102
|
+
file: v.string().optional().describe('Optional reference file to load (e.g. "references/quickstart.md")'),
|
|
103
|
+
}))();
|
|
104
|
+
}
|
|
68
105
|
async function loadRuntimeSkillReferenceFile(options, skillId, file) {
|
|
69
106
|
const normalizedFile = normalizeRuntimeSkillReferencePath(file);
|
|
70
107
|
if (!normalizedFile) {
|
|
@@ -88,8 +125,8 @@ export function createRuntimeLoadSkillTool(options) {
|
|
|
88
125
|
const builtinStore = getBuiltinStore(options);
|
|
89
126
|
return tool({
|
|
90
127
|
id: "load_skill",
|
|
91
|
-
description: options
|
|
92
|
-
inputSchema:
|
|
128
|
+
description: buildRuntimeLoadSkillDescription(options),
|
|
129
|
+
inputSchema: buildRuntimeLoadSkillInputSchema(options),
|
|
93
130
|
execute: async ({ skillId, file }) => {
|
|
94
131
|
if (file) {
|
|
95
132
|
return await loadRuntimeSkillReferenceFile(options, skillId, file);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-errors.d.ts","sourceRoot":"","sources":["../../../src/src/chat/provider-errors.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,OAAO,yBAAyB,CAAC;AAEjC,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;
|
|
1
|
+
{"version":3,"file":"provider-errors.d.ts","sourceRoot":"","sources":["../../../src/src/chat/provider-errors.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,OAAO,yBAAyB,CAAC;AAEjC,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAiBD,4CAA4C;AAC5C,MAAM,MAAM,mBAAmB,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC;AAE7F,0CAA0C;AAC1C,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,mBAAmB,CAMhE;AAgBD,iCAAiC;AACjC,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,OAAO,GAAG,mBAAmB,GAAG,IAAI,CA0B/E;AAED,yCAAyC;AACzC,wBAAgB,oBAAoB,CAAC,iBAAiB,EAAE,MAAM,GAAG,OAAO,CAOvE;AAgFD,sCAAsC;AACtC,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,mBAAmB,CAEtE"}
|
|
@@ -3,6 +3,10 @@ const DEFAULT_EXTERNAL_SERVICE_ERROR = {
|
|
|
3
3
|
code: "EXTERNAL_SERVICE_ERROR",
|
|
4
4
|
message: "LLM provider service error",
|
|
5
5
|
};
|
|
6
|
+
const PROJECT_SCHEMA_ERROR = {
|
|
7
|
+
code: "PROJECT_SCHEMA_ERROR",
|
|
8
|
+
message: "Project code has an invalid Veryfront schema. Update the schema to use defineSchema(), then run the agent again.",
|
|
9
|
+
};
|
|
6
10
|
function isErrorRecord(value) {
|
|
7
11
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8
12
|
}
|
|
@@ -133,6 +137,10 @@ function parseProviderErrorInner(error, seen) {
|
|
|
133
137
|
}
|
|
134
138
|
const responseBody = extractResponseBody(error);
|
|
135
139
|
if (responseBody) {
|
|
140
|
+
const normalizedResponseBody = responseBody.toLowerCase();
|
|
141
|
+
if (normalizedResponseBody.includes("invalid veryfront schema")) {
|
|
142
|
+
return PROJECT_SCHEMA_ERROR;
|
|
143
|
+
}
|
|
136
144
|
const parsedBody = parseErrorJson(responseBody);
|
|
137
145
|
const parsedError = parseKnownProviderBody(parsedBody);
|
|
138
146
|
if (parsedError) {
|
|
@@ -182,6 +190,9 @@ function parseProviderErrorInner(error, seen) {
|
|
|
182
190
|
normalizedMessage.includes("too many tokens")) {
|
|
183
191
|
return { code: "CONTEXT_LENGTH_EXCEEDED", message: "Conversation is too long" };
|
|
184
192
|
}
|
|
193
|
+
if (normalizedMessage.includes("invalid veryfront schema")) {
|
|
194
|
+
return PROJECT_SCHEMA_ERROR;
|
|
195
|
+
}
|
|
185
196
|
}
|
|
186
197
|
return DEFAULT_EXTERNAL_SERVICE_ERROR;
|
|
187
198
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote-mcp.d.ts","sourceRoot":"","sources":["../../../src/src/tool/remote-mcp.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAkB,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEzF,KAAK,eAAe,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,EAAE,oBAAoB,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;AAEnF,oDAAoD;AACpD,MAAM,WAAW,yBAAyB;IACxC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;IAClC,OAAO,CAAC,EAAE,eAAe,CAAC,WAAW,GAAG,SAAS,CAAC,CAAC;IACnD,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;
|
|
1
|
+
{"version":3,"file":"remote-mcp.d.ts","sourceRoot":"","sources":["../../../src/src/tool/remote-mcp.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAkB,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEzF,KAAK,eAAe,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,EAAE,oBAAoB,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;AAEnF,oDAAoD;AACpD,MAAM,WAAW,yBAAyB;IACxC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;IAClC,OAAO,CAAC,EAAE,eAAe,CAAC,WAAW,GAAG,SAAS,CAAC,CAAC;IACnD,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAgYD,qCAAqC;AACrC,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,yBAAyB,GAChC,gBAAgB,CA4DlB"}
|
|
@@ -71,6 +71,63 @@ function parseJsonText(text) {
|
|
|
71
71
|
return undefined;
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
+
function isOauthInvalidGrantMessage(value) {
|
|
75
|
+
const text = typeof value === "string" ? value : JSON.stringify(value);
|
|
76
|
+
const normalized = text.toLowerCase();
|
|
77
|
+
return normalized.includes("invalid_grant");
|
|
78
|
+
}
|
|
79
|
+
function getIntegrationIdFromToolName(toolName) {
|
|
80
|
+
const separatorIndex = toolName.indexOf("__");
|
|
81
|
+
const rawIntegration = separatorIndex > 0 ? toolName.slice(0, separatorIndex) : toolName;
|
|
82
|
+
return rawIntegration || "integration";
|
|
83
|
+
}
|
|
84
|
+
function formatIntegrationName(integration) {
|
|
85
|
+
return integration
|
|
86
|
+
.split(/[_-]+/)
|
|
87
|
+
.filter((part) => part.length > 0)
|
|
88
|
+
.map((part) => `${part.charAt(0).toUpperCase()}${part.slice(1)}`)
|
|
89
|
+
.join(" ") || "Integration";
|
|
90
|
+
}
|
|
91
|
+
function buildOauthConnectUrl(endpoint, integration, context) {
|
|
92
|
+
const encodedIntegration = encodeURIComponent(integration);
|
|
93
|
+
const projectId = typeof context?.projectId === "string" && context.projectId.length > 0
|
|
94
|
+
? context.projectId
|
|
95
|
+
: null;
|
|
96
|
+
try {
|
|
97
|
+
const url = new URL(`/oauth/connect/${encodedIntegration}`, endpoint);
|
|
98
|
+
if (projectId) {
|
|
99
|
+
url.searchParams.set("projectId", projectId);
|
|
100
|
+
}
|
|
101
|
+
return url.toString();
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return projectId
|
|
105
|
+
? `/oauth/connect/${encodedIntegration}?projectId=${encodeURIComponent(projectId)}`
|
|
106
|
+
: `/oauth/connect/${encodedIntegration}`;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function normalizeKnownToolError(value, toolName, endpoint, context) {
|
|
110
|
+
if (!isOauthInvalidGrantMessage(value)) {
|
|
111
|
+
return value;
|
|
112
|
+
}
|
|
113
|
+
const integration = getIntegrationIdFromToolName(toolName);
|
|
114
|
+
const label = formatIntegrationName(integration);
|
|
115
|
+
return {
|
|
116
|
+
error: "reconnect_required",
|
|
117
|
+
code: "OAUTH_TOKEN_EXPIRED",
|
|
118
|
+
integration,
|
|
119
|
+
connectUrl: buildOauthConnectUrl(endpoint, integration, context),
|
|
120
|
+
message: `${label} needs to be reconnected before this tool can run.`,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function isReconnectRequiredToolOutput(value) {
|
|
124
|
+
return isRecord(value) && value.error === "reconnect_required";
|
|
125
|
+
}
|
|
126
|
+
function normalizeKnownToolException(error, toolName, endpoint, context) {
|
|
127
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
128
|
+
const normalized = normalizeKnownToolError(message, toolName, endpoint, context);
|
|
129
|
+
return isReconnectRequiredToolOutput(normalized) ? normalized : null;
|
|
130
|
+
}
|
|
74
131
|
function extractJsonRpcErrorMessage(payload) {
|
|
75
132
|
const rawError = payload.error;
|
|
76
133
|
if (!isRecord(rawError))
|
|
@@ -182,24 +239,25 @@ function getJsonRpcResult(payload) {
|
|
|
182
239
|
}
|
|
183
240
|
return payload.result;
|
|
184
241
|
}
|
|
185
|
-
function normalizeCallToolResult(
|
|
242
|
+
function normalizeCallToolResult(input) {
|
|
243
|
+
const result = input.result;
|
|
186
244
|
if (!isRecord(result))
|
|
187
245
|
return result;
|
|
188
246
|
const rawContent = result.content;
|
|
189
247
|
if (Array.isArray(rawContent)) {
|
|
190
248
|
const text = joinCallToolText(rawContent.filter((item) => isRecord(item)));
|
|
191
249
|
if ("structuredContent" in result) {
|
|
192
|
-
return result.structuredContent;
|
|
250
|
+
return normalizeKnownToolError(result.structuredContent, input.toolName, input.endpoint, input.context);
|
|
193
251
|
}
|
|
194
252
|
if (hasToolExecutionErrorMarker(result)) {
|
|
195
|
-
return parseJsonText(text) ?? { error: "tool_error", message: text };
|
|
253
|
+
return normalizeKnownToolError(parseJsonText(text) ?? { error: "tool_error", message: text }, input.toolName, input.endpoint, input.context);
|
|
196
254
|
}
|
|
197
255
|
return parseJsonText(text) ?? text;
|
|
198
256
|
}
|
|
199
257
|
if ("structuredContent" in result) {
|
|
200
|
-
return result.structuredContent;
|
|
258
|
+
return normalizeKnownToolError(result.structuredContent, input.toolName, input.endpoint, input.context);
|
|
201
259
|
}
|
|
202
|
-
return result;
|
|
260
|
+
return normalizeKnownToolError(result, input.toolName, input.endpoint, input.context);
|
|
203
261
|
}
|
|
204
262
|
/** Create remote MCP tool source. */
|
|
205
263
|
export function createRemoteMCPToolSource(config) {
|
|
@@ -221,16 +279,30 @@ export function createRemoteMCPToolSource(config) {
|
|
|
221
279
|
async executeTool(toolName, args, context) {
|
|
222
280
|
const endpoint = await resolveValue(config.endpoint, context);
|
|
223
281
|
const headers = await resolveHeaders(config.headers, context);
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
282
|
+
try {
|
|
283
|
+
const payload = await postJsonRpc(endpoint, headers, {
|
|
284
|
+
jsonrpc: "2.0",
|
|
285
|
+
id: `${id}:tools:call:${toolName}`,
|
|
286
|
+
method: callMethod,
|
|
287
|
+
params: {
|
|
288
|
+
name: toolName,
|
|
289
|
+
arguments: args,
|
|
290
|
+
},
|
|
291
|
+
}, config.fetch ?? globalThis.fetch);
|
|
292
|
+
return normalizeCallToolResult({
|
|
293
|
+
result: getJsonRpcResult(payload),
|
|
294
|
+
toolName,
|
|
295
|
+
endpoint,
|
|
296
|
+
context,
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
catch (error) {
|
|
300
|
+
const normalizedError = normalizeKnownToolException(error, toolName, endpoint, context);
|
|
301
|
+
if (normalizedError) {
|
|
302
|
+
return normalizedError;
|
|
303
|
+
}
|
|
304
|
+
throw error;
|
|
305
|
+
}
|
|
234
306
|
},
|
|
235
307
|
};
|
|
236
308
|
}
|