veryfront 0.1.581 → 0.1.582
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/internal-agents/run-stream.d.ts.map +1 -1
- package/esm/src/internal-agents/run-stream.js +11 -1
- package/esm/src/server/handlers/request/agent-stream.handler.d.ts.map +1 -1
- package/esm/src/server/handlers/request/agent-stream.handler.js +54 -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/esm/deno.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-stream.d.ts","sourceRoot":"","sources":["../../../src/src/internal-agents/run-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,KAAK,EACV,KAAK,YAAY,IAAI,OAAO,EAC5B,KAAK,aAAa,EAEnB,MAAM,mBAAmB,CAAC;AAa3B,OAAO,EAA0B,KAAK,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC3F,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"run-stream.d.ts","sourceRoot":"","sources":["../../../src/src/internal-agents/run-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,KAAK,EACV,KAAK,YAAY,IAAI,OAAO,EAC5B,KAAK,aAAa,EAEnB,MAAM,mBAAmB,CAAC;AAa3B,OAAO,EAA0B,KAAK,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC3F,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAkBxD,KAAK,+BAA+B,GAAG,oBAAoB,GAAG;IAC5D,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,WAAW,+BAA+B;IAC9C,cAAc,EAAE,sBAAsB,CAAC;IACvC,aAAa,CAAC,EAAE,CACd,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,KAClC;QACH,MAAM,EAAE,CACN,QAAQ,EAAE,OAAO,EAAE,EACnB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,SAAS,CAAC,EAAE;YACV,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,aAAa,KAAK,IAAI,CAAC;SAC9C,EACD,aAAa,CAAC,EAAE,MAAM,EACtB,uBAAuB,CAAC,EAAE,MAAM,EAChC,WAAW,CAAC,EAAE,WAAW,KACtB,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC;KAC1C,CAAC;CACH;AAkJD,wBAAsB,gCAAgC,CACpD,KAAK,EAAE,+BAA+B,EACtC,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,+BAA+B,GACpC,OAAO,CAAC,QAAQ,CAAC,CAyPnB"}
|
|
@@ -9,6 +9,10 @@ import { serverLogger } from "../utils/index.js";
|
|
|
9
9
|
const getAnyObjectSchema = defineSchema((v) => v.record(v.string(), v.unknown()));
|
|
10
10
|
const anyObjectSchema = lazySchema(getAnyObjectSchema);
|
|
11
11
|
const logger = serverLogger.component("internal-agent-run-stream");
|
|
12
|
+
function getAgentAllowedRemoteToolNames(agent) {
|
|
13
|
+
const raw = agent.config.allowedRemoteTools;
|
|
14
|
+
return Array.isArray(raw) && raw.every((toolName) => typeof toolName === "string") ? raw : [];
|
|
15
|
+
}
|
|
12
16
|
function createInjectedStudioTool(runId, toolName, description, parameters, sessionManager) {
|
|
13
17
|
return {
|
|
14
18
|
id: toolName,
|
|
@@ -41,6 +45,7 @@ function buildMergedTools(agent, input, sessionManager, availableForwardedToolNa
|
|
|
41
45
|
if (!agent.config.tools) {
|
|
42
46
|
return Object.keys(injectedTools).length ? injectedTools : undefined;
|
|
43
47
|
}
|
|
48
|
+
const sourceAllowedRemoteToolNames = getAgentAllowedRemoteToolNames(agent);
|
|
44
49
|
if (agent.config.tools === true) {
|
|
45
50
|
const merged = {};
|
|
46
51
|
for (const [toolId] of toolRegistry.getAll()) {
|
|
@@ -49,12 +54,17 @@ function buildMergedTools(agent, input, sessionManager, availableForwardedToolNa
|
|
|
49
54
|
}
|
|
50
55
|
merged[toolId] = true;
|
|
51
56
|
}
|
|
57
|
+
for (const toolName of sourceAllowedRemoteToolNames) {
|
|
58
|
+
merged[toolName] = true;
|
|
59
|
+
}
|
|
52
60
|
return { ...merged, ...injectedTools };
|
|
53
61
|
}
|
|
54
62
|
const merged = {};
|
|
55
63
|
for (const [toolName, entry] of Object.entries(agent.config.tools)) {
|
|
56
64
|
if (entry === true) {
|
|
57
|
-
if (toolRegistry.get(toolName) ||
|
|
65
|
+
if (toolRegistry.get(toolName) ||
|
|
66
|
+
availableForwardedToolNames?.includes(toolName) ||
|
|
67
|
+
sourceAllowedRemoteToolNames.includes(toolName)) {
|
|
58
68
|
merged[toolName] = true;
|
|
59
69
|
}
|
|
60
70
|
continue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-stream.handler.d.ts","sourceRoot":"","sources":["../../../../../src/src/server/handlers/request/agent-stream.handler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"agent-stream.handler.d.ts","sourceRoot":"","sources":["../../../../../src/src/server/handlers/request/agent-stream.handler.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AACpF,OAAO,EAEL,KAAK,+BAA+B,EACrC,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACL,4BAA4B,EAE7B,MAAM,2CAA2C,CAAC;AAwBnD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAmB,aAAa,EAAE,MAAM,aAAa,CAAC;AAUnG,MAAM,WAAW,sBACf,SAAQ,yBAAyB,EAAE,+BAA+B;IAClE,4BAA4B,CAAC,EAAE,OAAO,4BAA4B,CAAC;CACpE;AAyND,qBAAa,kBAAmB,SAAQ,WAAW;IASrC,OAAO,CAAC,QAAQ,CAAC,IAAI;IARjC,QAAQ,EAAE,eAAe,CAMvB;gBAE2B,IAAI,GAAE,sBAAoC;IAIvE,OAAO,CAAC,sBAAsB;IAwBxB,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;CAwJxE"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createRemoteMCPToolSource } from "../../../tool/index.js";
|
|
1
2
|
import { defaultChannelInvokeDeps } from "../../../channels/invoke.js";
|
|
2
3
|
import { createRuntimeAgentStreamResponse, } from "../../../internal-agents/run-stream.js";
|
|
3
4
|
import { resolveRuntimeOwnerInvokeUrl, RUNTIME_OWNER_INVOKE_URL_HEADER, } from "../../../internal-agents/runtime-owner.js";
|
|
@@ -18,6 +19,8 @@ const defaultDeps = {
|
|
|
18
19
|
};
|
|
19
20
|
const logger = serverLogger.component("agent-stream-handler");
|
|
20
21
|
const RUN_STREAM_PATH_REGEX = /^\/api\/control-plane\/runs\/([^/]+)\/stream$/;
|
|
22
|
+
const VERYFRONT_PLATFORM_REMOTE_TOOL_SOURCE_ID = "veryfront-platform-mcp";
|
|
23
|
+
const VERYFRONT_PLATFORM_REMOTE_TOOL_NAMES = new Set(["search_knowledge", "get_file"]);
|
|
21
24
|
// Per-environment env var cache shared across all agent stream requests (60s TTL)
|
|
22
25
|
const _agentEnvVarCache = new EnvironmentVariableCache((environmentId, token, projectSlug) => {
|
|
23
26
|
const apiBaseUrl = getHostEnv("VERYFRONT_API_URL") ?? "https://api.veryfront.org";
|
|
@@ -47,6 +50,52 @@ async function _resolveProductionEnvironmentId(projectSlug, token) {
|
|
|
47
50
|
return null;
|
|
48
51
|
}
|
|
49
52
|
}
|
|
53
|
+
function getRequestedVeryfrontPlatformToolNames(agent) {
|
|
54
|
+
const tools = agent.config.tools;
|
|
55
|
+
if (!tools || tools === true) {
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
58
|
+
return Object.entries(tools)
|
|
59
|
+
.filter(([toolName, entry]) => entry === true && VERYFRONT_PLATFORM_REMOTE_TOOL_NAMES.has(toolName))
|
|
60
|
+
.map(([toolName]) => toolName)
|
|
61
|
+
.sort();
|
|
62
|
+
}
|
|
63
|
+
function mergeAllowedRemoteTools(current, requestedToolNames) {
|
|
64
|
+
const allowed = new Set(Array.isArray(current) && current.every((toolName) => typeof toolName === "string")
|
|
65
|
+
? current
|
|
66
|
+
: []);
|
|
67
|
+
for (const toolName of requestedToolNames) {
|
|
68
|
+
allowed.add(toolName);
|
|
69
|
+
}
|
|
70
|
+
return [...allowed].sort();
|
|
71
|
+
}
|
|
72
|
+
function hasVeryfrontPlatformRemoteToolSource(remoteTools) {
|
|
73
|
+
return remoteTools?.some((source) => source.id === VERYFRONT_PLATFORM_REMOTE_TOOL_SOURCE_ID) ??
|
|
74
|
+
false;
|
|
75
|
+
}
|
|
76
|
+
function withVeryfrontPlatformRemoteTools(input) {
|
|
77
|
+
const requestedToolNames = getRequestedVeryfrontPlatformToolNames(input.agent);
|
|
78
|
+
if (requestedToolNames.length === 0 || !input.token) {
|
|
79
|
+
return input.agent;
|
|
80
|
+
}
|
|
81
|
+
const apiUrl = getHostEnv("VERYFRONT_API_URL") ?? "https://api.veryfront.org";
|
|
82
|
+
const remoteTools = input.agent.config.remoteTools ?? [];
|
|
83
|
+
const platformRemoteToolSource = hasVeryfrontPlatformRemoteToolSource(remoteTools) ? [] : [
|
|
84
|
+
createRemoteMCPToolSource({
|
|
85
|
+
id: VERYFRONT_PLATFORM_REMOTE_TOOL_SOURCE_ID,
|
|
86
|
+
endpoint: `${apiUrl}/mcp`,
|
|
87
|
+
headers: { Authorization: `Bearer ${input.token}` },
|
|
88
|
+
}),
|
|
89
|
+
];
|
|
90
|
+
return {
|
|
91
|
+
...input.agent,
|
|
92
|
+
config: {
|
|
93
|
+
...input.agent.config,
|
|
94
|
+
allowedRemoteTools: mergeAllowedRemoteTools(input.agent.config.allowedRemoteTools, requestedToolNames),
|
|
95
|
+
remoteTools: [...remoteTools, ...platformRemoteToolSource],
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
50
99
|
function buildAgentStreamEnv(input) {
|
|
51
100
|
const apiUrl = getHostEnv("VERYFRONT_API_URL") ?? "https://api.veryfront.org";
|
|
52
101
|
return {
|
|
@@ -178,6 +227,10 @@ export class AgentStreamHandler extends BaseHandler {
|
|
|
178
227
|
return this.respond(builder.json({ error: "Agent not found" }, 404));
|
|
179
228
|
}
|
|
180
229
|
const runtimeInput = toRuntimeRunAgentInput(payload);
|
|
230
|
+
const runtimeAgent = withVeryfrontPlatformRemoteTools({
|
|
231
|
+
agent: agent,
|
|
232
|
+
token: ctx.proxyToken || getHostEnv("VERYFRONT_API_TOKEN") || null,
|
|
233
|
+
});
|
|
181
234
|
// Load project env vars so source-defined MCP tool headers resolve
|
|
182
235
|
// via _getProjectEnv(). Control-plane requests don't go through the proxy and
|
|
183
236
|
// therefore don't carry x-environment-id, so we discover the production env ID
|
|
@@ -196,7 +249,7 @@ export class AgentStreamHandler extends BaseHandler {
|
|
|
196
249
|
});
|
|
197
250
|
}
|
|
198
251
|
}
|
|
199
|
-
const runAgentStream = () => createRuntimeAgentStreamResponse(runtimeInput,
|
|
252
|
+
const runAgentStream = () => createRuntimeAgentStreamResponse(runtimeInput, runtimeAgent, this.deps);
|
|
200
253
|
const shouldIsolateEnv = !!ctx.proxyToken;
|
|
201
254
|
const response = shouldIsolateEnv
|
|
202
255
|
? await runWithProjectEnv(buildAgentStreamEnv({
|