veryfront 0.1.511 → 0.1.512
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/runtime-agent-definition-files.d.ts +5 -0
- package/esm/src/agent/runtime-agent-definition-files.d.ts.map +1 -1
- package/esm/src/agent/runtime-agent-definition-files.js +37 -9
- package/esm/src/agent/veryfront-cloud-agent-service.d.ts +5 -1
- package/esm/src/agent/veryfront-cloud-agent-service.d.ts.map +1 -1
- package/esm/src/agent/veryfront-cloud-agent-service.js +74 -29
- 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/runtime-agent-definition-files.ts +52 -9
- package/src/src/agent/veryfront-cloud-agent-service.ts +112 -34
- package/src/src/utils/version-constant.ts +1 -1
package/esm/deno.js
CHANGED
|
@@ -6,6 +6,10 @@ export declare const resolveRuntimeAgentDefinitionsDirInputSchema: z.ZodObject<{
|
|
|
6
6
|
fileName: z.ZodOptional<z.ZodString>;
|
|
7
7
|
}, z.core.$strip>;
|
|
8
8
|
export type ResolveRuntimeAgentDefinitionsDirInput = z.infer<typeof resolveRuntimeAgentDefinitionsDirInputSchema>;
|
|
9
|
+
export declare const listRuntimeAgentMarkdownDefinitionIdsInputSchema: z.ZodObject<{
|
|
10
|
+
baseDir: z.ZodString;
|
|
11
|
+
}, z.core.$strip>;
|
|
12
|
+
export type ListRuntimeAgentMarkdownDefinitionIdsInput = z.infer<typeof listRuntimeAgentMarkdownDefinitionIdsInputSchema>;
|
|
9
13
|
export declare const loadRuntimeAgentMarkdownDefinitionFromFileInputSchema: z.ZodObject<{
|
|
10
14
|
agentsDir: z.ZodString;
|
|
11
15
|
id: z.ZodString;
|
|
@@ -13,6 +17,7 @@ export declare const loadRuntimeAgentMarkdownDefinitionFromFileInputSchema: z.Zo
|
|
|
13
17
|
}, z.core.$strip>;
|
|
14
18
|
export type LoadRuntimeAgentMarkdownDefinitionFromFileInput = z.infer<typeof loadRuntimeAgentMarkdownDefinitionFromFileInputSchema>;
|
|
15
19
|
export declare function resolveRuntimeAgentDefinitionsDir(input: ResolveRuntimeAgentDefinitionsDirInput): string;
|
|
20
|
+
export declare function listRuntimeAgentMarkdownDefinitionIds(input: ListRuntimeAgentMarkdownDefinitionIdsInput): string[];
|
|
16
21
|
export declare function resolveRuntimeAgentMarkdownDefinitionFilePath(input: LoadRuntimeAgentMarkdownDefinitionFromFileInput): string;
|
|
17
22
|
export declare function loadRuntimeAgentMarkdownDefinitionFromFile(input: LoadRuntimeAgentMarkdownDefinitionFromFileInput): RuntimeAgentMarkdownDefinition;
|
|
18
23
|
//# sourceMappingURL=runtime-agent-definition-files.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-agent-definition-files.d.ts","sourceRoot":"","sources":["../../../src/src/agent/runtime-agent-definition-files.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAEL,KAAK,8BAA8B,EACpC,MAAM,+BAA+B,CAAC;AAKvC,eAAO,MAAM,4CAA4C;;;;iBAIvD,CAAC;AAEH,MAAM,MAAM,sCAAsC,GAAG,CAAC,CAAC,KAAK,CAC1D,OAAO,4CAA4C,CACpD,CAAC;AAEF,eAAO,MAAM,qDAAqD;;;;iBAIhE,CAAC;AAEH,MAAM,MAAM,+CAA+C,GAAG,CAAC,CAAC,KAAK,CACnE,OAAO,qDAAqD,CAC7D,CAAC;
|
|
1
|
+
{"version":3,"file":"runtime-agent-definition-files.d.ts","sourceRoot":"","sources":["../../../src/src/agent/runtime-agent-definition-files.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAEL,KAAK,8BAA8B,EACpC,MAAM,+BAA+B,CAAC;AAKvC,eAAO,MAAM,4CAA4C;;;;iBAIvD,CAAC;AAEH,MAAM,MAAM,sCAAsC,GAAG,CAAC,CAAC,KAAK,CAC1D,OAAO,4CAA4C,CACpD,CAAC;AAEF,eAAO,MAAM,gDAAgD;;iBAE3D,CAAC;AAEH,MAAM,MAAM,0CAA0C,GAAG,CAAC,CAAC,KAAK,CAC9D,OAAO,gDAAgD,CACxD,CAAC;AAEF,eAAO,MAAM,qDAAqD;;;;iBAIhE,CAAC;AAEH,MAAM,MAAM,+CAA+C,GAAG,CAAC,CAAC,KAAK,CACnE,OAAO,qDAAqD,CAC7D,CAAC;AA0BF,wBAAgB,iCAAiC,CAC/C,KAAK,EAAE,sCAAsC,GAC5C,MAAM,CAWR;AAED,wBAAgB,qCAAqC,CACnD,KAAK,EAAE,0CAA0C,GAChD,MAAM,EAAE,CAwBV;AAED,wBAAgB,6CAA6C,CAC3D,KAAK,EAAE,+CAA+C,GACrD,MAAM,CAOR;AAED,wBAAgB,0CAA0C,CACxD,KAAK,EAAE,+CAA+C,GACrD,8BAA8B,CAQhC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
2
2
|
import { basename, resolve } from "node:path";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { parseRuntimeAgentMarkdownDefinition, } from "./runtime-agent-definition.js";
|
|
@@ -9,6 +9,9 @@ export const resolveRuntimeAgentDefinitionsDirInputSchema = z.object({
|
|
|
9
9
|
id: runtimeAgentDefinitionFileIdSchema,
|
|
10
10
|
fileName: runtimeAgentDefinitionFileNameSchema.optional(),
|
|
11
11
|
});
|
|
12
|
+
export const listRuntimeAgentMarkdownDefinitionIdsInputSchema = z.object({
|
|
13
|
+
baseDir: z.string().min(1),
|
|
14
|
+
});
|
|
12
15
|
export const loadRuntimeAgentMarkdownDefinitionFromFileInputSchema = z.object({
|
|
13
16
|
agentsDir: z.string().min(1),
|
|
14
17
|
id: runtimeAgentDefinitionFileIdSchema,
|
|
@@ -20,23 +23,48 @@ function getRuntimeAgentDefinitionFileName(input) {
|
|
|
20
23
|
function hasRuntimeAgentDefinitionFile(path, fileName) {
|
|
21
24
|
return existsSync(resolve(path, fileName));
|
|
22
25
|
}
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const firstCandidate = resolve(parsedInput.baseDir, "agents");
|
|
27
|
-
const sourceLayoutCandidate = resolve(parsedInput.baseDir, "../agents");
|
|
26
|
+
function getRuntimeAgentDefinitionsDirCandidates(baseDir) {
|
|
27
|
+
const firstCandidate = resolve(baseDir, "agents");
|
|
28
|
+
const sourceLayoutCandidate = resolve(baseDir, "../agents");
|
|
28
29
|
const candidates = [
|
|
29
30
|
firstCandidate,
|
|
30
31
|
sourceLayoutCandidate,
|
|
31
|
-
resolve(
|
|
32
|
-
resolve(
|
|
32
|
+
resolve(baseDir, "../../agents"),
|
|
33
|
+
resolve(baseDir, "../../../agents"),
|
|
33
34
|
];
|
|
35
|
+
return [...new Set(candidates)];
|
|
36
|
+
}
|
|
37
|
+
export function resolveRuntimeAgentDefinitionsDir(input) {
|
|
38
|
+
const parsedInput = resolveRuntimeAgentDefinitionsDirInputSchema.parse(input);
|
|
39
|
+
const fileName = getRuntimeAgentDefinitionFileName(parsedInput);
|
|
40
|
+
const candidates = getRuntimeAgentDefinitionsDirCandidates(parsedInput.baseDir);
|
|
41
|
+
const sourceLayoutCandidate = resolve(parsedInput.baseDir, "../agents");
|
|
34
42
|
const fallbackCandidate = basename(parsedInput.baseDir) === "src"
|
|
35
43
|
? sourceLayoutCandidate
|
|
36
|
-
:
|
|
44
|
+
: resolve(parsedInput.baseDir, "agents");
|
|
37
45
|
return candidates.find((candidate) => hasRuntimeAgentDefinitionFile(candidate, fileName)) ??
|
|
38
46
|
fallbackCandidate;
|
|
39
47
|
}
|
|
48
|
+
export function listRuntimeAgentMarkdownDefinitionIds(input) {
|
|
49
|
+
const parsedInput = listRuntimeAgentMarkdownDefinitionIdsInputSchema.parse(input);
|
|
50
|
+
const ids = new Set();
|
|
51
|
+
for (const dir of getRuntimeAgentDefinitionsDirCandidates(parsedInput.baseDir)) {
|
|
52
|
+
if (!existsSync(dir)) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
56
|
+
if (!entry.isFile()) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const parseResult = runtimeAgentDefinitionFileNameSchema.safeParse(entry.name);
|
|
60
|
+
if (!parseResult.success) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
ids.add(parseResult.data.slice(0, -".md".length));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return [...ids].sort((left, right) => left.localeCompare(right));
|
|
67
|
+
}
|
|
40
68
|
export function resolveRuntimeAgentMarkdownDefinitionFilePath(input) {
|
|
41
69
|
const parsedInput = loadRuntimeAgentMarkdownDefinitionFromFileInputSchema.parse(input);
|
|
42
70
|
return resolve(parsedInput.agentsDir, getRuntimeAgentDefinitionFileName(parsedInput));
|
|
@@ -18,7 +18,11 @@ export declare function veryfrontMcpServer(kind?: VeryfrontMcpServerKind): Agent
|
|
|
18
18
|
type AgentServicePathOption = string | URL;
|
|
19
19
|
export type NodeVeryfrontCloudAgentServiceOptions = {
|
|
20
20
|
serviceName: string;
|
|
21
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Default agent served by requests that do not provide an agent id. When
|
|
23
|
+
* omitted, the service selects the only discovered code or markdown agent.
|
|
24
|
+
*/
|
|
25
|
+
agentId?: string;
|
|
22
26
|
/**
|
|
23
27
|
* Project/discovery root. Defaults to the process cwd when neither baseDir
|
|
24
28
|
* nor an entrypoint URL is provided.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"veryfront-cloud-agent-service.d.ts","sourceRoot":"","sources":["../../../src/src/agent/veryfront-cloud-agent-service.ts"],"names":[],"mappings":"AAIA,OA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+CAA+C,CAAC,CAAC,CAKrF;AAED,wBAAsB,mCAAmC,CACvD,OAAO,EAAE,qCAAqC,GAC7C,OAAO,CAAC,2BAA2B,CAAC,+CAA+C,CAAC,CAAC,CAQvF;AAED,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,qCAAqC,GAC7C,OAAO,CAAC,IAAI,CAAC,CAyCf"}
|
|
@@ -14,12 +14,12 @@ import { buildAgentRunTraceAttributes, buildExecuteToolTraceAttributes, filterAg
|
|
|
14
14
|
import { runAgentServiceMain, } from "./agent-service-bootstrap.js";
|
|
15
15
|
import { loadAgentServiceEnvFiles } from "./agent-service-env-files.js";
|
|
16
16
|
import { createHostedFormInputTool } from "./hosted-form-input-tool.js";
|
|
17
|
-
import { createHostedAgentProjectSteering } from "./hosted-agent-project-steering.js";
|
|
17
|
+
import { createHostedAgentProjectSteering, } from "./hosted-agent-project-steering.js";
|
|
18
18
|
import { createLiveStudioMcpTools } from "./live-studio-mcp-tools.js";
|
|
19
19
|
import { createDefaultHostedChatRuntime, } from "./default-hosted-chat-runtime.js";
|
|
20
20
|
import { createDefaultHostedInvokeAgentTool } from "./default-hosted-invoke-agent-tool.js";
|
|
21
21
|
import { createDefaultHostedProjectSteeringRefresh, fetchDefaultHostedProjectSteering, } from "./default-hosted-project-steering-refresh.js";
|
|
22
|
-
import {
|
|
22
|
+
import { listRuntimeAgentMarkdownDefinitionIds } from "./runtime-agent-definition-files.js";
|
|
23
23
|
import { buildVeryfrontCloudRuntimeInstructions, } from "./veryfront-cloud-runtime-system-messages.js";
|
|
24
24
|
import { createNodeAgentServiceRuntimeInfrastructure, } from "./node-agent-service-runtime-infrastructure.js";
|
|
25
25
|
import { createAgentServiceRuntime, startAgentServiceRuntime, startNodeAgentService, } from "./agent-service-runtime.js";
|
|
@@ -127,20 +127,14 @@ function createNodeVeryfrontCloudAgentServiceContext(options) {
|
|
|
127
127
|
function trace(operationName, operation) {
|
|
128
128
|
return infrastructure.tracer.trace(operationName, operation);
|
|
129
129
|
}
|
|
130
|
-
const projectSteering = createHostedAgentProjectSteering({
|
|
131
|
-
baseDir: resolveBaseDir(options),
|
|
132
|
-
agentId: options.agentId,
|
|
133
|
-
getApiUrl: () => infrastructure.getConfig().VERYFRONT_API_URL,
|
|
134
|
-
logger: infrastructure.logger,
|
|
135
|
-
trace,
|
|
136
|
-
});
|
|
137
130
|
return {
|
|
138
131
|
options,
|
|
139
132
|
processTarget,
|
|
140
133
|
projectDir: resolveProjectDir(options),
|
|
141
134
|
infrastructure,
|
|
142
135
|
trace,
|
|
143
|
-
|
|
136
|
+
defaultAgentId: null,
|
|
137
|
+
projectSteeringByAgentId: new Map(),
|
|
144
138
|
tracker: createDetachedRunTracker(),
|
|
145
139
|
discoveryResult: null,
|
|
146
140
|
agentConfig: null,
|
|
@@ -160,21 +154,11 @@ async function createRuntimeAgentDefinitionFromCodeAgent(codeAgent) {
|
|
|
160
154
|
maxSteps: codeAgent.config.maxSteps,
|
|
161
155
|
};
|
|
162
156
|
}
|
|
163
|
-
function getMarkdownAgentConfig(context) {
|
|
164
|
-
return context.
|
|
157
|
+
function getMarkdownAgentConfig(context, agentId) {
|
|
158
|
+
return getProjectSteering(context, agentId).getAgentConfig();
|
|
165
159
|
}
|
|
166
160
|
function loadMarkdownAgentConfig(context, agentId) {
|
|
167
|
-
|
|
168
|
-
return getMarkdownAgentConfig(context);
|
|
169
|
-
}
|
|
170
|
-
const agentsDir = resolveRuntimeAgentDefinitionsDir({
|
|
171
|
-
baseDir: resolveBaseDir(context.options),
|
|
172
|
-
id: agentId,
|
|
173
|
-
});
|
|
174
|
-
return loadRuntimeAgentMarkdownDefinitionFromFile({
|
|
175
|
-
agentsDir,
|
|
176
|
-
id: agentId,
|
|
177
|
-
});
|
|
161
|
+
return getMarkdownAgentConfig(context, agentId);
|
|
178
162
|
}
|
|
179
163
|
async function resolveAgentConfig(context, agentId) {
|
|
180
164
|
const cachedAgentConfig = context.agentConfigs.get(agentId);
|
|
@@ -213,28 +197,89 @@ async function discoverProjectPrimitives(context) {
|
|
|
213
197
|
});
|
|
214
198
|
context.discoveryResult = await discoverAll(discoveryOptions);
|
|
215
199
|
}
|
|
200
|
+
function getDiscoveredCodeAgentIds(context) {
|
|
201
|
+
return [...(context.discoveryResult?.agents.keys() ?? [])].sort((left, right) => left.localeCompare(right));
|
|
202
|
+
}
|
|
203
|
+
function getDiscoveredMarkdownAgentIds(context) {
|
|
204
|
+
return listRuntimeAgentMarkdownDefinitionIds({
|
|
205
|
+
baseDir: resolveBaseDir(context.options),
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
function describeAgentIdCandidates(input) {
|
|
209
|
+
const ids = [...new Set([...input.codeAgentIds, ...input.markdownAgentIds])]
|
|
210
|
+
.sort((left, right) => left.localeCompare(right));
|
|
211
|
+
return ids.length > 0 ? ids.join(", ") : "none";
|
|
212
|
+
}
|
|
213
|
+
function resolveSingleAgentId(input) {
|
|
214
|
+
if (input.source === "code") {
|
|
215
|
+
return input.codeAgentIds.length === 1 ? input.codeAgentIds[0] ?? null : null;
|
|
216
|
+
}
|
|
217
|
+
if (input.source === "markdown") {
|
|
218
|
+
return input.markdownAgentIds.length === 1 ? input.markdownAgentIds[0] ?? null : null;
|
|
219
|
+
}
|
|
220
|
+
const candidateIds = [...new Set([...input.codeAgentIds, ...input.markdownAgentIds])];
|
|
221
|
+
return candidateIds.length === 1 ? candidateIds[0] ?? null : null;
|
|
222
|
+
}
|
|
223
|
+
function resolveDefaultAgentId(context) {
|
|
224
|
+
if (context.options.agentId) {
|
|
225
|
+
return context.options.agentId;
|
|
226
|
+
}
|
|
227
|
+
const source = context.options.agentSource ?? "auto";
|
|
228
|
+
const codeAgentIds = getDiscoveredCodeAgentIds(context);
|
|
229
|
+
const markdownAgentIds = getDiscoveredMarkdownAgentIds(context);
|
|
230
|
+
const agentId = resolveSingleAgentId({ codeAgentIds, markdownAgentIds, source });
|
|
231
|
+
if (agentId) {
|
|
232
|
+
return agentId;
|
|
233
|
+
}
|
|
234
|
+
throw new Error([
|
|
235
|
+
"agentId is required when agent discovery does not resolve to exactly one agent.",
|
|
236
|
+
`Discovered agents: ${describeAgentIdCandidates({ codeAgentIds, markdownAgentIds })}.`,
|
|
237
|
+
].join(" "));
|
|
238
|
+
}
|
|
216
239
|
async function initializeNodeVeryfrontCloudAgentServiceContext(context) {
|
|
217
240
|
await discoverProjectPrimitives(context);
|
|
218
|
-
context.
|
|
241
|
+
context.defaultAgentId = resolveDefaultAgentId(context);
|
|
242
|
+
context.agentConfig = await resolveAgentConfig(context, context.defaultAgentId);
|
|
243
|
+
}
|
|
244
|
+
function getDefaultAgentId(context) {
|
|
245
|
+
if (!context.defaultAgentId) {
|
|
246
|
+
throw new Error("Agent service context has not been initialized.");
|
|
247
|
+
}
|
|
248
|
+
return context.defaultAgentId;
|
|
249
|
+
}
|
|
250
|
+
function getProjectSteering(context, agentId = getDefaultAgentId(context)) {
|
|
251
|
+
const cachedProjectSteering = context.projectSteeringByAgentId.get(agentId);
|
|
252
|
+
if (cachedProjectSteering) {
|
|
253
|
+
return cachedProjectSteering;
|
|
254
|
+
}
|
|
255
|
+
const projectSteering = createHostedAgentProjectSteering({
|
|
256
|
+
baseDir: resolveBaseDir(context.options),
|
|
257
|
+
agentId,
|
|
258
|
+
getApiUrl: () => context.infrastructure.getConfig().VERYFRONT_API_URL,
|
|
259
|
+
logger: context.infrastructure.logger,
|
|
260
|
+
trace: context.trace,
|
|
261
|
+
});
|
|
262
|
+
context.projectSteeringByAgentId.set(agentId, projectSteering);
|
|
263
|
+
return projectSteering;
|
|
219
264
|
}
|
|
220
265
|
function getDiscoveredHostTools() {
|
|
221
266
|
return Object.fromEntries([...toolRegistry.getAll()].sort(([left], [right]) => left.localeCompare(right)));
|
|
222
267
|
}
|
|
223
268
|
function getProjectInstructions(context, lookup) {
|
|
224
269
|
return context.trace("chat.getProjectInstructions", async () => {
|
|
225
|
-
return await context.
|
|
270
|
+
return await getProjectSteering(context).getProjectInstructions(lookup);
|
|
226
271
|
});
|
|
227
272
|
}
|
|
228
273
|
function getSkillsConfig(context, lookup) {
|
|
229
274
|
return context.trace("chat.getSkillsConfig", async () => {
|
|
230
|
-
return await context.
|
|
275
|
+
return await getProjectSteering(context).getSkillsConfig(lookup);
|
|
231
276
|
});
|
|
232
277
|
}
|
|
233
278
|
function createLoadSkillTool(context, toolContext) {
|
|
234
|
-
return context.
|
|
279
|
+
return getProjectSteering(context).createLoadSkillTool(toolContext);
|
|
235
280
|
}
|
|
236
281
|
async function refreshProjectSkillIds(context, skillContext) {
|
|
237
|
-
await context.
|
|
282
|
+
await getProjectSteering(context).refreshProjectSkillIds(skillContext);
|
|
238
283
|
}
|
|
239
284
|
function setFilteredTraceAttributes(context, attributes) {
|
|
240
285
|
context.infrastructure.setActiveSpanAttributes(filterAgentTraceAttributes(attributes));
|
|
@@ -381,7 +426,7 @@ async function prepareChatExecution(context, req) {
|
|
|
381
426
|
const { userId, authToken, projectId, conversationId, upstreamParentConversationId, upstreamParentRunId, spawnedFromToolCallId, } = req;
|
|
382
427
|
const config = context.infrastructure.getConfig();
|
|
383
428
|
setPrepareChatExecutionStartAttributes(context, { projectId, userId });
|
|
384
|
-
const agentConfig = await resolveAgentConfig(context, req.agentId ?? context
|
|
429
|
+
const agentConfig = await resolveAgentConfig(context, req.agentId ?? getDefaultAgentId(context));
|
|
385
430
|
const { effectiveMessages, rootRunContext, runtime: { agent, runtimeKind, modelId, cleanup }, finalMessages, } = await prepareVeryfrontCloudHostedChatExecution({
|
|
386
431
|
request: req,
|
|
387
432
|
agentConfig,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.1.
|
|
1
|
+
export declare const VERSION = "0.1.512";
|
|
2
2
|
//# sourceMappingURL=version-constant.d.ts.map
|
package/package.json
CHANGED
package/src/deno.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
2
2
|
import { basename, resolve } from "node:path";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import {
|
|
@@ -19,6 +19,14 @@ export type ResolveRuntimeAgentDefinitionsDirInput = z.infer<
|
|
|
19
19
|
typeof resolveRuntimeAgentDefinitionsDirInputSchema
|
|
20
20
|
>;
|
|
21
21
|
|
|
22
|
+
export const listRuntimeAgentMarkdownDefinitionIdsInputSchema = z.object({
|
|
23
|
+
baseDir: z.string().min(1),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export type ListRuntimeAgentMarkdownDefinitionIdsInput = z.infer<
|
|
27
|
+
typeof listRuntimeAgentMarkdownDefinitionIdsInputSchema
|
|
28
|
+
>;
|
|
29
|
+
|
|
22
30
|
export const loadRuntimeAgentMarkdownDefinitionFromFileInputSchema = z.object({
|
|
23
31
|
agentsDir: z.string().min(1),
|
|
24
32
|
id: runtimeAgentDefinitionFileIdSchema,
|
|
@@ -40,27 +48,62 @@ function hasRuntimeAgentDefinitionFile(path: string, fileName: string): boolean
|
|
|
40
48
|
return existsSync(resolve(path, fileName));
|
|
41
49
|
}
|
|
42
50
|
|
|
51
|
+
function getRuntimeAgentDefinitionsDirCandidates(baseDir: string): string[] {
|
|
52
|
+
const firstCandidate = resolve(baseDir, "agents");
|
|
53
|
+
const sourceLayoutCandidate = resolve(baseDir, "../agents");
|
|
54
|
+
const candidates = [
|
|
55
|
+
firstCandidate,
|
|
56
|
+
sourceLayoutCandidate,
|
|
57
|
+
resolve(baseDir, "../../agents"),
|
|
58
|
+
resolve(baseDir, "../../../agents"),
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
return [...new Set(candidates)];
|
|
62
|
+
}
|
|
63
|
+
|
|
43
64
|
export function resolveRuntimeAgentDefinitionsDir(
|
|
44
65
|
input: ResolveRuntimeAgentDefinitionsDirInput,
|
|
45
66
|
): string {
|
|
46
67
|
const parsedInput = resolveRuntimeAgentDefinitionsDirInputSchema.parse(input);
|
|
47
68
|
const fileName = getRuntimeAgentDefinitionFileName(parsedInput);
|
|
48
|
-
const
|
|
69
|
+
const candidates = getRuntimeAgentDefinitionsDirCandidates(parsedInput.baseDir);
|
|
49
70
|
const sourceLayoutCandidate = resolve(parsedInput.baseDir, "../agents");
|
|
50
|
-
const candidates = [
|
|
51
|
-
firstCandidate,
|
|
52
|
-
sourceLayoutCandidate,
|
|
53
|
-
resolve(parsedInput.baseDir, "../../agents"),
|
|
54
|
-
resolve(parsedInput.baseDir, "../../../agents"),
|
|
55
|
-
];
|
|
56
71
|
const fallbackCandidate = basename(parsedInput.baseDir) === "src"
|
|
57
72
|
? sourceLayoutCandidate
|
|
58
|
-
:
|
|
73
|
+
: resolve(parsedInput.baseDir, "agents");
|
|
59
74
|
|
|
60
75
|
return candidates.find((candidate) => hasRuntimeAgentDefinitionFile(candidate, fileName)) ??
|
|
61
76
|
fallbackCandidate;
|
|
62
77
|
}
|
|
63
78
|
|
|
79
|
+
export function listRuntimeAgentMarkdownDefinitionIds(
|
|
80
|
+
input: ListRuntimeAgentMarkdownDefinitionIdsInput,
|
|
81
|
+
): string[] {
|
|
82
|
+
const parsedInput = listRuntimeAgentMarkdownDefinitionIdsInputSchema.parse(input);
|
|
83
|
+
const ids = new Set<string>();
|
|
84
|
+
|
|
85
|
+
for (const dir of getRuntimeAgentDefinitionsDirCandidates(parsedInput.baseDir)) {
|
|
86
|
+
if (!existsSync(dir)) {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
91
|
+
if (!entry.isFile()) {
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const parseResult = runtimeAgentDefinitionFileNameSchema.safeParse(entry.name);
|
|
96
|
+
if (!parseResult.success) {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
ids.add(parseResult.data.slice(0, -".md".length));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return [...ids].sort((left, right) => left.localeCompare(right));
|
|
105
|
+
}
|
|
106
|
+
|
|
64
107
|
export function resolveRuntimeAgentMarkdownDefinitionFilePath(
|
|
65
108
|
input: LoadRuntimeAgentMarkdownDefinitionFromFileInput,
|
|
66
109
|
): string {
|
|
@@ -40,7 +40,10 @@ import {
|
|
|
40
40
|
} from "./agent-service-bootstrap.js";
|
|
41
41
|
import { loadAgentServiceEnvFiles } from "./agent-service-env-files.js";
|
|
42
42
|
import { createHostedFormInputTool } from "./hosted-form-input-tool.js";
|
|
43
|
-
import {
|
|
43
|
+
import {
|
|
44
|
+
createHostedAgentProjectSteering,
|
|
45
|
+
type HostedAgentProjectSteering,
|
|
46
|
+
} from "./hosted-agent-project-steering.js";
|
|
44
47
|
import { type HostedChatRuntimeCreationResult } from "./hosted-chat-runtime-contract.js";
|
|
45
48
|
import type { HostedConversationRootRunContext } from "./conversation-root-run-lifecycle.js";
|
|
46
49
|
import { type AgentRuntimeMessage } from "./agent-runtime-message-adapter.js";
|
|
@@ -65,10 +68,7 @@ import type { AgentServiceMcpServerConfig } from "./agent-service-mcp-server-con
|
|
|
65
68
|
import type { RuntimeLoadSkillToolContext } from "./runtime-load-skill-tool.js";
|
|
66
69
|
import type { RuntimeProjectSteeringLookup } from "./runtime-project-skill-catalog.js";
|
|
67
70
|
import type { RuntimeSkillDefinition } from "./runtime-skill-metadata.js";
|
|
68
|
-
import {
|
|
69
|
-
loadRuntimeAgentMarkdownDefinitionFromFile,
|
|
70
|
-
resolveRuntimeAgentDefinitionsDir,
|
|
71
|
-
} from "./runtime-agent-definition-files.js";
|
|
71
|
+
import { listRuntimeAgentMarkdownDefinitionIds } from "./runtime-agent-definition-files.js";
|
|
72
72
|
import type { RuntimeAgentMarkdownDefinition } from "./runtime-agent-definition.js";
|
|
73
73
|
import {
|
|
74
74
|
buildVeryfrontCloudRuntimeInstructions,
|
|
@@ -132,7 +132,11 @@ type AgentServicePathOption = string | URL;
|
|
|
132
132
|
|
|
133
133
|
export type NodeVeryfrontCloudAgentServiceOptions = {
|
|
134
134
|
serviceName: string;
|
|
135
|
-
|
|
135
|
+
/**
|
|
136
|
+
* Default agent served by requests that do not provide an agent id. When
|
|
137
|
+
* omitted, the service selects the only discovered code or markdown agent.
|
|
138
|
+
*/
|
|
139
|
+
agentId?: string;
|
|
136
140
|
/**
|
|
137
141
|
* Project/discovery root. Defaults to the process cwd when neither baseDir
|
|
138
142
|
* nor an entrypoint URL is provided.
|
|
@@ -310,13 +314,6 @@ function createNodeVeryfrontCloudAgentServiceContext(
|
|
|
310
314
|
): TResult | Promise<TResult> {
|
|
311
315
|
return infrastructure.tracer.trace(operationName, operation);
|
|
312
316
|
}
|
|
313
|
-
const projectSteering = createHostedAgentProjectSteering({
|
|
314
|
-
baseDir: resolveBaseDir(options),
|
|
315
|
-
agentId: options.agentId,
|
|
316
|
-
getApiUrl: () => infrastructure.getConfig().VERYFRONT_API_URL,
|
|
317
|
-
logger: infrastructure.logger,
|
|
318
|
-
trace,
|
|
319
|
-
});
|
|
320
317
|
|
|
321
318
|
return {
|
|
322
319
|
options,
|
|
@@ -324,7 +321,8 @@ function createNodeVeryfrontCloudAgentServiceContext(
|
|
|
324
321
|
projectDir: resolveProjectDir(options),
|
|
325
322
|
infrastructure,
|
|
326
323
|
trace,
|
|
327
|
-
|
|
324
|
+
defaultAgentId: null as string | null,
|
|
325
|
+
projectSteeringByAgentId: new Map<string, HostedAgentProjectSteering>(),
|
|
328
326
|
tracker: createDetachedRunTracker<AgUiResumeValue>(),
|
|
329
327
|
discoveryResult: null as DiscoveryResult | null,
|
|
330
328
|
agentConfig: null as RuntimeAgentMarkdownDefinition | null,
|
|
@@ -351,27 +349,16 @@ async function createRuntimeAgentDefinitionFromCodeAgent(
|
|
|
351
349
|
|
|
352
350
|
function getMarkdownAgentConfig(
|
|
353
351
|
context: NodeVeryfrontCloudAgentServiceContext,
|
|
352
|
+
agentId: string,
|
|
354
353
|
): RuntimeAgentMarkdownDefinition {
|
|
355
|
-
return context.
|
|
354
|
+
return getProjectSteering(context, agentId).getAgentConfig();
|
|
356
355
|
}
|
|
357
356
|
|
|
358
357
|
function loadMarkdownAgentConfig(
|
|
359
358
|
context: NodeVeryfrontCloudAgentServiceContext,
|
|
360
359
|
agentId: string,
|
|
361
360
|
): RuntimeAgentMarkdownDefinition {
|
|
362
|
-
|
|
363
|
-
return getMarkdownAgentConfig(context);
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
const agentsDir = resolveRuntimeAgentDefinitionsDir({
|
|
367
|
-
baseDir: resolveBaseDir(context.options),
|
|
368
|
-
id: agentId,
|
|
369
|
-
});
|
|
370
|
-
|
|
371
|
-
return loadRuntimeAgentMarkdownDefinitionFromFile({
|
|
372
|
-
agentsDir,
|
|
373
|
-
id: agentId,
|
|
374
|
-
});
|
|
361
|
+
return getMarkdownAgentConfig(context, agentId);
|
|
375
362
|
}
|
|
376
363
|
|
|
377
364
|
async function resolveAgentConfig(
|
|
@@ -427,11 +414,102 @@ async function discoverProjectPrimitives(
|
|
|
427
414
|
context.discoveryResult = await discoverAll(discoveryOptions);
|
|
428
415
|
}
|
|
429
416
|
|
|
417
|
+
function getDiscoveredCodeAgentIds(context: NodeVeryfrontCloudAgentServiceContext): string[] {
|
|
418
|
+
return [...(context.discoveryResult?.agents.keys() ?? [])].sort((left, right) =>
|
|
419
|
+
left.localeCompare(right)
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
function getDiscoveredMarkdownAgentIds(context: NodeVeryfrontCloudAgentServiceContext): string[] {
|
|
424
|
+
return listRuntimeAgentMarkdownDefinitionIds({
|
|
425
|
+
baseDir: resolveBaseDir(context.options),
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function describeAgentIdCandidates(input: {
|
|
430
|
+
codeAgentIds: string[];
|
|
431
|
+
markdownAgentIds: string[];
|
|
432
|
+
}): string {
|
|
433
|
+
const ids = [...new Set([...input.codeAgentIds, ...input.markdownAgentIds])]
|
|
434
|
+
.sort((left, right) => left.localeCompare(right));
|
|
435
|
+
|
|
436
|
+
return ids.length > 0 ? ids.join(", ") : "none";
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
function resolveSingleAgentId(input: {
|
|
440
|
+
codeAgentIds: string[];
|
|
441
|
+
markdownAgentIds: string[];
|
|
442
|
+
source: NodeVeryfrontCloudAgentServiceAgentSource;
|
|
443
|
+
}): string | null {
|
|
444
|
+
if (input.source === "code") {
|
|
445
|
+
return input.codeAgentIds.length === 1 ? input.codeAgentIds[0] ?? null : null;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
if (input.source === "markdown") {
|
|
449
|
+
return input.markdownAgentIds.length === 1 ? input.markdownAgentIds[0] ?? null : null;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
const candidateIds = [...new Set([...input.codeAgentIds, ...input.markdownAgentIds])];
|
|
453
|
+
return candidateIds.length === 1 ? candidateIds[0] ?? null : null;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
function resolveDefaultAgentId(context: NodeVeryfrontCloudAgentServiceContext): string {
|
|
457
|
+
if (context.options.agentId) {
|
|
458
|
+
return context.options.agentId;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
const source = context.options.agentSource ?? "auto";
|
|
462
|
+
const codeAgentIds = getDiscoveredCodeAgentIds(context);
|
|
463
|
+
const markdownAgentIds = getDiscoveredMarkdownAgentIds(context);
|
|
464
|
+
const agentId = resolveSingleAgentId({ codeAgentIds, markdownAgentIds, source });
|
|
465
|
+
|
|
466
|
+
if (agentId) {
|
|
467
|
+
return agentId;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
throw new Error(
|
|
471
|
+
[
|
|
472
|
+
"agentId is required when agent discovery does not resolve to exactly one agent.",
|
|
473
|
+
`Discovered agents: ${describeAgentIdCandidates({ codeAgentIds, markdownAgentIds })}.`,
|
|
474
|
+
].join(" "),
|
|
475
|
+
);
|
|
476
|
+
}
|
|
477
|
+
|
|
430
478
|
async function initializeNodeVeryfrontCloudAgentServiceContext(
|
|
431
479
|
context: NodeVeryfrontCloudAgentServiceContext,
|
|
432
480
|
): Promise<void> {
|
|
433
481
|
await discoverProjectPrimitives(context);
|
|
434
|
-
context.
|
|
482
|
+
context.defaultAgentId = resolveDefaultAgentId(context);
|
|
483
|
+
context.agentConfig = await resolveAgentConfig(context, context.defaultAgentId);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
function getDefaultAgentId(context: NodeVeryfrontCloudAgentServiceContext): string {
|
|
487
|
+
if (!context.defaultAgentId) {
|
|
488
|
+
throw new Error("Agent service context has not been initialized.");
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
return context.defaultAgentId;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
function getProjectSteering(
|
|
495
|
+
context: NodeVeryfrontCloudAgentServiceContext,
|
|
496
|
+
agentId: string = getDefaultAgentId(context),
|
|
497
|
+
): HostedAgentProjectSteering {
|
|
498
|
+
const cachedProjectSteering = context.projectSteeringByAgentId.get(agentId);
|
|
499
|
+
if (cachedProjectSteering) {
|
|
500
|
+
return cachedProjectSteering;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
const projectSteering = createHostedAgentProjectSteering({
|
|
504
|
+
baseDir: resolveBaseDir(context.options),
|
|
505
|
+
agentId,
|
|
506
|
+
getApiUrl: () => context.infrastructure.getConfig().VERYFRONT_API_URL,
|
|
507
|
+
logger: context.infrastructure.logger,
|
|
508
|
+
trace: context.trace,
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
context.projectSteeringByAgentId.set(agentId, projectSteering);
|
|
512
|
+
return projectSteering;
|
|
435
513
|
}
|
|
436
514
|
|
|
437
515
|
function getDiscoveredHostTools(): HostToolSet {
|
|
@@ -445,7 +523,7 @@ function getProjectInstructions(
|
|
|
445
523
|
lookup: RuntimeProjectSteeringLookup,
|
|
446
524
|
): Promise<string> {
|
|
447
525
|
return context.trace("chat.getProjectInstructions", async () => {
|
|
448
|
-
return await context.
|
|
526
|
+
return await getProjectSteering(context).getProjectInstructions(lookup);
|
|
449
527
|
});
|
|
450
528
|
}
|
|
451
529
|
|
|
@@ -454,7 +532,7 @@ function getSkillsConfig(
|
|
|
454
532
|
lookup: RuntimeProjectSteeringLookup,
|
|
455
533
|
): Promise<RuntimeSkillDefinition[]> {
|
|
456
534
|
return context.trace("chat.getSkillsConfig", async () => {
|
|
457
|
-
return await context.
|
|
535
|
+
return await getProjectSteering(context).getSkillsConfig(lookup);
|
|
458
536
|
});
|
|
459
537
|
}
|
|
460
538
|
|
|
@@ -462,14 +540,14 @@ function createLoadSkillTool(
|
|
|
462
540
|
context: NodeVeryfrontCloudAgentServiceContext,
|
|
463
541
|
toolContext: RuntimeLoadSkillToolContext,
|
|
464
542
|
) {
|
|
465
|
-
return context.
|
|
543
|
+
return getProjectSteering(context).createLoadSkillTool(toolContext);
|
|
466
544
|
}
|
|
467
545
|
|
|
468
546
|
async function refreshProjectSkillIds(
|
|
469
547
|
context: NodeVeryfrontCloudAgentServiceContext,
|
|
470
548
|
skillContext: HostedProjectSkillIdsContext,
|
|
471
549
|
): Promise<void> {
|
|
472
|
-
await context.
|
|
550
|
+
await getProjectSteering(context).refreshProjectSkillIds(skillContext);
|
|
473
551
|
}
|
|
474
552
|
|
|
475
553
|
function setFilteredTraceAttributes(
|
|
@@ -683,7 +761,7 @@ async function prepareChatExecution(
|
|
|
683
761
|
|
|
684
762
|
setPrepareChatExecutionStartAttributes(context, { projectId, userId });
|
|
685
763
|
|
|
686
|
-
const agentConfig = await resolveAgentConfig(context, req.agentId ?? context
|
|
764
|
+
const agentConfig = await resolveAgentConfig(context, req.agentId ?? getDefaultAgentId(context));
|
|
687
765
|
const {
|
|
688
766
|
effectiveMessages,
|
|
689
767
|
rootRunContext,
|