veryfront 0.1.682 → 0.1.683
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/current-run-tool-state.d.ts +23 -1
- package/esm/src/agent/runtime/current-run-tool-state.d.ts.map +1 -1
- package/esm/src/agent/runtime/current-run-tool-state.js +186 -7
- package/esm/src/agent/runtime/index.d.ts.map +1 -1
- package/esm/src/agent/runtime/index.js +22 -5
- 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
|
@@ -16,6 +16,10 @@ export type RecordCurrentRunToolResultInput = {
|
|
|
16
16
|
result: unknown;
|
|
17
17
|
now?: Date;
|
|
18
18
|
};
|
|
19
|
+
export type CurrentRunToolStateHydrationMessage = {
|
|
20
|
+
role?: string;
|
|
21
|
+
parts?: readonly unknown[];
|
|
22
|
+
};
|
|
19
23
|
export declare function createToolInputFingerprint(input: unknown): string;
|
|
20
24
|
export declare function summarizeToolResultForCurrentRunState(toolName: string, result: unknown): {
|
|
21
25
|
summary: unknown;
|
|
@@ -23,14 +27,32 @@ export declare function summarizeToolResultForCurrentRunState(toolName: string,
|
|
|
23
27
|
};
|
|
24
28
|
export declare function createCurrentRunToolState(): CurrentRunToolState;
|
|
25
29
|
export declare function recordCurrentRunToolResult(state: CurrentRunToolState, input: RecordCurrentRunToolResultInput): void;
|
|
30
|
+
export declare function hydrateCurrentRunToolStateFromMessages(state: CurrentRunToolState, messages: readonly CurrentRunToolStateHydrationMessage[], options?: {
|
|
31
|
+
now?: Date;
|
|
32
|
+
}): void;
|
|
26
33
|
export declare function hasCurrentRunToolState(state: CurrentRunToolState): boolean;
|
|
27
34
|
type PromptToolState = Record<string, {
|
|
28
35
|
calls: Record<string, {
|
|
29
36
|
status: ToolStatus;
|
|
30
37
|
summary: unknown;
|
|
31
38
|
}>;
|
|
39
|
+
semanticCalls?: Record<string, PromptSemanticToolCall>;
|
|
32
40
|
}>;
|
|
33
|
-
|
|
41
|
+
type PromptSemanticToolCall = {
|
|
42
|
+
status: ToolStatus;
|
|
43
|
+
callCount: number;
|
|
44
|
+
parameters: Record<string, string>;
|
|
45
|
+
summary: unknown;
|
|
46
|
+
};
|
|
47
|
+
type PromptRunState = {
|
|
48
|
+
tools: PromptToolState;
|
|
49
|
+
actions?: Record<string, {
|
|
50
|
+
status: ToolStatus;
|
|
51
|
+
source: string;
|
|
52
|
+
summary: unknown;
|
|
53
|
+
}>;
|
|
54
|
+
};
|
|
55
|
+
export declare function projectCurrentRunToolStateForPrompt(state: CurrentRunToolState): PromptRunState;
|
|
34
56
|
export declare function appendCurrentRunToolStateToSystemPrompt(systemPrompt: string, state: CurrentRunToolState): string;
|
|
35
57
|
export {};
|
|
36
58
|
//# sourceMappingURL=current-run-tool-state.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"current-run-tool-state.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/runtime/current-run-tool-state.ts"],"names":[],"mappings":"AAIA,KAAK,UAAU,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,CAAC;AAEhD,MAAM,MAAM,uBAAuB,GAAG;IACpC,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,UAAU,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,MAAM,CACtC,MAAM,EACN;IAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAA;CAAE,CACnD,CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG;IAC5C,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;IAChB,GAAG,CAAC,EAAE,IAAI,CAAC;CACZ,CAAC;AAyBF,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEjE;AAmMD,wBAAgB,qCAAqC,CACnD,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,OAAO,GACd;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,UAAU,CAAA;CAAE,CAY1C;AAED,wBAAgB,yBAAyB,IAAI,mBAAmB,CAE/D;AAED,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,mBAAmB,EAC1B,KAAK,EAAE,+BAA+B,GACrC,IAAI,CAgBN;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAI1E;AAED,KAAK,eAAe,GAAG,MAAM,CAC3B,MAAM,EACN;
|
|
1
|
+
{"version":3,"file":"current-run-tool-state.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/runtime/current-run-tool-state.ts"],"names":[],"mappings":"AAIA,KAAK,UAAU,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,CAAC;AAEhD,MAAM,MAAM,uBAAuB,GAAG;IACpC,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,UAAU,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,MAAM,CACtC,MAAM,EACN;IAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAA;CAAE,CACnD,CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG;IAC5C,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;IAChB,GAAG,CAAC,EAAE,IAAI,CAAC;CACZ,CAAC;AAEF,M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AC,EAAE,MAAM,CACd,MAAM,EACN;QACE,MAAM,EAAE,UAAU,CAAC;QACnB,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,OAAO,CAAC;KAClB,CACF,CAAC;CACH,CAAC;AAmFF,wBAAgB,mCAAmC,CACjD,KAAK,EAAE,mBAAmB,GACzB,cAAc,CAwChB;AAED,wBAAgB,uCAAuC,CACrD,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,mBAAmB,GACzB,MAAM,CAOR"}
|
|
@@ -220,27 +220,206 @@ export function recordCurrentRunToolResult(state, input) {
|
|
|
220
220
|
};
|
|
221
221
|
state[input.toolName] = toolBucket;
|
|
222
222
|
}
|
|
223
|
+
function parseJsonRecord(value) {
|
|
224
|
+
try {
|
|
225
|
+
const parsed = JSON.parse(value);
|
|
226
|
+
return isRecord(parsed) ? parsed : null;
|
|
227
|
+
}
|
|
228
|
+
catch {
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
function getToolCallInput(part) {
|
|
233
|
+
if (isRecord(part.args))
|
|
234
|
+
return part.args;
|
|
235
|
+
if (isRecord(part.input))
|
|
236
|
+
return part.input;
|
|
237
|
+
if (typeof part.args === "string")
|
|
238
|
+
return parseJsonRecord(part.args) ?? part.args;
|
|
239
|
+
if (typeof part.input === "string")
|
|
240
|
+
return parseJsonRecord(part.input) ?? part.input;
|
|
241
|
+
if (typeof part.inputText === "string")
|
|
242
|
+
return parseJsonRecord(part.inputText) ?? part.inputText;
|
|
243
|
+
return {};
|
|
244
|
+
}
|
|
245
|
+
function getToolResultValue(part) {
|
|
246
|
+
if ("result" in part)
|
|
247
|
+
return part.result;
|
|
248
|
+
if ("output" in part)
|
|
249
|
+
return part.output;
|
|
250
|
+
return undefined;
|
|
251
|
+
}
|
|
252
|
+
function getToolCallIdentity(part) {
|
|
253
|
+
if (!isRecord(part))
|
|
254
|
+
return null;
|
|
255
|
+
const toolCallId = typeof part.toolCallId === "string"
|
|
256
|
+
? part.toolCallId
|
|
257
|
+
: typeof part.tool_call_id === "string"
|
|
258
|
+
? part.tool_call_id
|
|
259
|
+
: typeof part.id === "string"
|
|
260
|
+
? part.id
|
|
261
|
+
: null;
|
|
262
|
+
const toolName = typeof part.toolName === "string"
|
|
263
|
+
? part.toolName
|
|
264
|
+
: typeof part.tool_name === "string"
|
|
265
|
+
? part.tool_name
|
|
266
|
+
: typeof part.name === "string"
|
|
267
|
+
? part.name
|
|
268
|
+
: null;
|
|
269
|
+
return toolCallId && toolName ? { toolCallId, toolName } : null;
|
|
270
|
+
}
|
|
271
|
+
function isToolCallPart(part) {
|
|
272
|
+
if (!isRecord(part))
|
|
273
|
+
return false;
|
|
274
|
+
const type = typeof part.type === "string" ? part.type : "";
|
|
275
|
+
if (type === "tool-result" || type === "tool_result")
|
|
276
|
+
return false;
|
|
277
|
+
if (type === "tool-call" || type === "tool_call" || type.startsWith("tool-")) {
|
|
278
|
+
return getToolCallIdentity(part) !== null;
|
|
279
|
+
}
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
function isToolResultLikePart(part) {
|
|
283
|
+
if (!isRecord(part))
|
|
284
|
+
return false;
|
|
285
|
+
const type = typeof part.type === "string" ? part.type : "";
|
|
286
|
+
if (type !== "tool-result" && type !== "tool_result")
|
|
287
|
+
return false;
|
|
288
|
+
return getToolCallIdentity(part) !== null && ("result" in part || "output" in part);
|
|
289
|
+
}
|
|
290
|
+
export function hydrateCurrentRunToolStateFromMessages(state, messages, options) {
|
|
291
|
+
const toolCallInputs = new Map();
|
|
292
|
+
for (const message of messages) {
|
|
293
|
+
for (const part of message.parts ?? []) {
|
|
294
|
+
if (isToolCallPart(part)) {
|
|
295
|
+
const identity = getToolCallIdentity(part);
|
|
296
|
+
if (!identity)
|
|
297
|
+
continue;
|
|
298
|
+
toolCallInputs.set(identity.toolCallId, {
|
|
299
|
+
toolName: identity.toolName,
|
|
300
|
+
input: getToolCallInput(part),
|
|
301
|
+
});
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
if (!isToolResultLikePart(part))
|
|
305
|
+
continue;
|
|
306
|
+
const identity = getToolCallIdentity(part);
|
|
307
|
+
if (!identity)
|
|
308
|
+
continue;
|
|
309
|
+
const call = toolCallInputs.get(identity.toolCallId);
|
|
310
|
+
recordCurrentRunToolResult(state, {
|
|
311
|
+
toolCallId: identity.toolCallId,
|
|
312
|
+
toolName: identity.toolName,
|
|
313
|
+
input: call?.input ?? {},
|
|
314
|
+
result: getToolResultValue(part),
|
|
315
|
+
now: options?.now,
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
223
320
|
export function hasCurrentRunToolState(state) {
|
|
224
321
|
return Object.keys(state).some((toolName) => Object.keys(state[toolName]?.calls ?? {}).length > 0);
|
|
225
322
|
}
|
|
323
|
+
function compactStringParameter(value) {
|
|
324
|
+
if (typeof value === "string" && value.trim().length > 0) {
|
|
325
|
+
return value.trim();
|
|
326
|
+
}
|
|
327
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
328
|
+
return String(value);
|
|
329
|
+
}
|
|
330
|
+
return null;
|
|
331
|
+
}
|
|
332
|
+
function getSemanticToolCall(input) {
|
|
333
|
+
if (!isRecord(input.call.input))
|
|
334
|
+
return null;
|
|
335
|
+
switch (input.toolName) {
|
|
336
|
+
case "load_skill": {
|
|
337
|
+
const skillId = compactStringParameter(input.call.input.skillId) ??
|
|
338
|
+
compactStringParameter(input.call.input.skill_id);
|
|
339
|
+
return skillId ? { key: `skill:${skillId}`, parameters: { skillId } } : null;
|
|
340
|
+
}
|
|
341
|
+
case "invoke_agent": {
|
|
342
|
+
const agentId = compactStringParameter(input.call.input.agent_id) ??
|
|
343
|
+
compactStringParameter(input.call.input.agentId);
|
|
344
|
+
if (!agentId)
|
|
345
|
+
return null;
|
|
346
|
+
const stepId = compactStringParameter(input.call.input.step_id) ??
|
|
347
|
+
compactStringParameter(input.call.input.stepId);
|
|
348
|
+
const idempotencyKey = compactStringParameter(input.call.input.idempotency_key) ??
|
|
349
|
+
compactStringParameter(input.call.input.idempotencyKey);
|
|
350
|
+
const keySuffix = stepId
|
|
351
|
+
? `:step:${stepId}`
|
|
352
|
+
: idempotencyKey
|
|
353
|
+
? `:idempotency:${idempotencyKey}`
|
|
354
|
+
: "";
|
|
355
|
+
const parameters = { agent_id: agentId };
|
|
356
|
+
if (stepId)
|
|
357
|
+
parameters.step_id = stepId;
|
|
358
|
+
if (idempotencyKey)
|
|
359
|
+
parameters.idempotency_key = idempotencyKey;
|
|
360
|
+
return { key: `agent:${agentId}${keySuffix}`, parameters };
|
|
361
|
+
}
|
|
362
|
+
case "studio_todo_write": {
|
|
363
|
+
const taskId = compactStringParameter(input.call.input.taskId) ??
|
|
364
|
+
compactStringParameter(input.call.input.task_id);
|
|
365
|
+
return taskId ? { key: `todo:${taskId}`, parameters: { taskId } } : null;
|
|
366
|
+
}
|
|
367
|
+
default:
|
|
368
|
+
return null;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
function mergeSemanticToolCall(existing, call, parameters) {
|
|
372
|
+
return {
|
|
373
|
+
status: call.status,
|
|
374
|
+
callCount: (existing?.callCount ?? 0) + call.toolCallIds.length,
|
|
375
|
+
parameters: existing?.parameters ?? parameters,
|
|
376
|
+
summary: call.summary,
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
function usesSemanticPromptKeys(toolName) {
|
|
380
|
+
return toolName === "load_skill" ||
|
|
381
|
+
toolName === "invoke_agent" ||
|
|
382
|
+
toolName === "studio_todo_write";
|
|
383
|
+
}
|
|
384
|
+
function createPromptCallKey(input) {
|
|
385
|
+
return usesSemanticPromptKeys(input.toolName) ? `call:${input.index + 1}` : input.fingerprint;
|
|
386
|
+
}
|
|
226
387
|
export function projectCurrentRunToolStateForPrompt(state) {
|
|
227
|
-
const
|
|
388
|
+
const tools = {};
|
|
389
|
+
const actions = {};
|
|
228
390
|
for (const [toolName, bucket] of Object.entries(state)) {
|
|
229
391
|
const calls = {};
|
|
230
|
-
|
|
231
|
-
|
|
392
|
+
const semanticCalls = {};
|
|
393
|
+
for (const [index, [fingerprint, call]] of Object.entries(bucket.calls).entries()) {
|
|
394
|
+
calls[createPromptCallKey({ toolName, fingerprint, index })] = {
|
|
232
395
|
status: call.status,
|
|
233
396
|
summary: call.summary,
|
|
234
397
|
};
|
|
398
|
+
const semantic = getSemanticToolCall({ toolName, call });
|
|
399
|
+
if (semantic) {
|
|
400
|
+
semanticCalls[semantic.key] = mergeSemanticToolCall(semanticCalls[semantic.key], call, semantic.parameters);
|
|
401
|
+
actions[`${toolName}:${semantic.key}`] = {
|
|
402
|
+
status: call.status,
|
|
403
|
+
source: `tools.${toolName}.semanticCalls.${semantic.key}`,
|
|
404
|
+
summary: call.summary,
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
if (Object.keys(calls).length > 0) {
|
|
409
|
+
tools[toolName] = {
|
|
410
|
+
calls,
|
|
411
|
+
...(Object.keys(semanticCalls).length > 0 ? { semanticCalls } : {}),
|
|
412
|
+
};
|
|
235
413
|
}
|
|
236
|
-
if (Object.keys(calls).length > 0)
|
|
237
|
-
projected[toolName] = { calls };
|
|
238
414
|
}
|
|
239
|
-
return
|
|
415
|
+
return {
|
|
416
|
+
tools,
|
|
417
|
+
...(Object.keys(actions).length > 0 ? { actions } : {}),
|
|
418
|
+
};
|
|
240
419
|
}
|
|
241
420
|
export function appendCurrentRunToolStateToSystemPrompt(systemPrompt, state) {
|
|
242
421
|
if (!hasCurrentRunToolState(state))
|
|
243
422
|
return systemPrompt;
|
|
244
423
|
const promptState = projectCurrentRunToolStateForPrompt(state);
|
|
245
|
-
return `${systemPrompt}\n\n<
|
|
424
|
+
return `${systemPrompt}\n\n<run_state current_run=\"true\">\n${JSON.stringify(promptState)}\n</run_state>`;
|
|
246
425
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../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sage, getMaxSteps, normalizeInput } from "./input-utils.js";
|
|
|
44
44
|
import { filterToolsForSkill, isToolAllowedBySkill, validateAllowedToolPatterns, } from "../../skill/allowed-tools.js";
|
|
45
45
|
import { resolveConfiguredAgentModel, resolveRuntimeModel } from "./model-resolution.js";
|
|
46
46
|
import { stringifyToolError, throwIfAborted } from "./error-utils.js";
|
|
47
|
-
import { appendCurrentRunToolStateToSystemPrompt, createCurrentRunToolState, recordCurrentRunToolResult, } from "./current-run-tool-state.js";
|
|
47
|
+
import { appendCurrentRunToolStateToSystemPrompt, createCurrentRunToolState, hydrateCurrentRunToolStateFromMessages, recordCurrentRunToolResult, } from "./current-run-tool-state.js";
|
|
48
48
|
import { applySkillDelegationOverridesToToolInput, extractSkillDelegationOverrides, } from "./skill-delegation-overrides.js";
|
|
49
49
|
const logger = serverLogger.component("agent");
|
|
50
50
|
const LOAD_SKILL_TOOL_ID = "load_skill";
|
|
@@ -292,6 +292,19 @@ export function materializeStreamedToolCall(tc) {
|
|
|
292
292
|
function isToolResultPart(part) {
|
|
293
293
|
return part.type === "tool-result" && "result" in part;
|
|
294
294
|
}
|
|
295
|
+
function hydrateActiveSkillStateFromMessages(messages) {
|
|
296
|
+
let activeSkillPolicy;
|
|
297
|
+
let activeSkillDelegationOverrides;
|
|
298
|
+
for (const message of messages) {
|
|
299
|
+
for (const part of message.parts) {
|
|
300
|
+
if (!isToolResultPart(part) || part.toolName !== LOAD_SKILL_TOOL_ID)
|
|
301
|
+
continue;
|
|
302
|
+
activeSkillPolicy = extractSkillPolicy(part.result);
|
|
303
|
+
activeSkillDelegationOverrides = extractSkillDelegationOverrides(part.result);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return { activeSkillPolicy, activeSkillDelegationOverrides };
|
|
307
|
+
}
|
|
295
308
|
/**
|
|
296
309
|
* Extract and validate the skill policy from a load_skill tool result.
|
|
297
310
|
* Returns `[]` (no tools allowed) for invalid/missing policies instead of
|
|
@@ -580,6 +593,7 @@ export class AgentRuntime {
|
|
|
580
593
|
const toolCalls = [];
|
|
581
594
|
const currentMessages = [...messages];
|
|
582
595
|
const currentRunToolState = createCurrentRunToolState();
|
|
596
|
+
hydrateCurrentRunToolStateFromMessages(currentRunToolState, currentMessages);
|
|
583
597
|
const totalUsage = { promptTokens: 0, completionTokens: 0, totalTokens: 0 };
|
|
584
598
|
// Local models can't reliably do function calling — skip tools gracefully.
|
|
585
599
|
const isLocal = isLocalModelRuntime(languageModel);
|
|
@@ -587,8 +601,9 @@ export class AgentRuntime {
|
|
|
587
601
|
warnLocalToolSkipping(this.id, effectiveModel);
|
|
588
602
|
}
|
|
589
603
|
// Request-scoped skill policy (not class-level mutable state)
|
|
590
|
-
|
|
591
|
-
let
|
|
604
|
+
const hydratedSkillState = hydrateActiveSkillStateFromMessages(currentMessages);
|
|
605
|
+
let activeSkillPolicy = hydratedSkillState.activeSkillPolicy;
|
|
606
|
+
let activeSkillDelegationOverrides = hydratedSkillState.activeSkillDelegationOverrides;
|
|
592
607
|
const allowedRemoteToolNames = getRuntimeAllowedRemoteTools(this.config);
|
|
593
608
|
const providerTools = getRuntimeProviderTools(this.config);
|
|
594
609
|
const forwardedRemoteToolDefinitions = getRuntimeForwardedIntegrationToolDefs(this.config);
|
|
@@ -826,6 +841,7 @@ export class AgentRuntime {
|
|
|
826
841
|
const toolCalls = [];
|
|
827
842
|
const currentMessages = [...messages];
|
|
828
843
|
const currentRunToolState = createCurrentRunToolState();
|
|
844
|
+
hydrateCurrentRunToolStateFromMessages(currentRunToolState, currentMessages);
|
|
829
845
|
const totalUsage = { promptTokens: 0, completionTokens: 0, totalTokens: 0 };
|
|
830
846
|
// Local models can't reliably do function calling — skip tools gracefully.
|
|
831
847
|
const isLocalStreaming = isLocalModelRuntime(languageModel);
|
|
@@ -833,8 +849,9 @@ export class AgentRuntime {
|
|
|
833
849
|
warnLocalToolSkipping(this.id, effectiveModel);
|
|
834
850
|
}
|
|
835
851
|
// Request-scoped skill policy (not class-level mutable state)
|
|
836
|
-
|
|
837
|
-
let
|
|
852
|
+
const hydratedSkillState = hydrateActiveSkillStateFromMessages(currentMessages);
|
|
853
|
+
let activeSkillPolicy = hydratedSkillState.activeSkillPolicy;
|
|
854
|
+
let activeSkillDelegationOverrides = hydratedSkillState.activeSkillDelegationOverrides;
|
|
838
855
|
let finalFinishReason;
|
|
839
856
|
let latestAssistantText = "";
|
|
840
857
|
const allowedRemoteToolNames = getRuntimeAllowedRemoteTools(this.config);
|