@librechat/agents 3.1.67-dev.4 → 3.1.68
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/dist/cjs/agents/AgentContext.cjs +3 -23
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/common/enum.cjs +0 -16
- package/dist/cjs/common/enum.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +0 -91
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +36 -0
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
- package/dist/cjs/main.cjs +1 -53
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/messages/format.cjs +12 -74
- package/dist/cjs/messages/format.cjs.map +1 -1
- package/dist/cjs/run.cjs +0 -111
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/summarization/index.cjs +41 -0
- package/dist/cjs/summarization/index.cjs.map +1 -1
- package/dist/cjs/summarization/node.cjs +121 -63
- package/dist/cjs/summarization/node.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +140 -304
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/esm/agents/AgentContext.mjs +3 -23
- package/dist/esm/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/common/enum.mjs +1 -15
- package/dist/esm/common/enum.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +0 -91
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs +36 -0
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
- package/dist/esm/main.mjs +2 -13
- package/dist/esm/main.mjs.map +1 -1
- package/dist/esm/messages/format.mjs +4 -66
- package/dist/esm/messages/format.mjs.map +1 -1
- package/dist/esm/run.mjs +0 -111
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/summarization/index.mjs +41 -1
- package/dist/esm/summarization/index.mjs.map +1 -1
- package/dist/esm/summarization/node.mjs +121 -63
- package/dist/esm/summarization/node.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +142 -306
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/types/agents/AgentContext.d.ts +0 -6
- package/dist/types/common/enum.d.ts +1 -10
- package/dist/types/graphs/Graph.d.ts +0 -2
- package/dist/types/graphs/MultiAgentGraph.d.ts +12 -0
- package/dist/types/index.d.ts +0 -8
- package/dist/types/messages/format.d.ts +1 -2
- package/dist/types/run.d.ts +0 -1
- package/dist/types/summarization/index.d.ts +2 -0
- package/dist/types/summarization/node.d.ts +0 -2
- package/dist/types/tools/ToolNode.d.ts +2 -24
- package/dist/types/types/graph.d.ts +2 -61
- package/dist/types/types/index.d.ts +0 -1
- package/dist/types/types/run.d.ts +0 -20
- package/dist/types/types/tools.d.ts +1 -38
- package/package.json +1 -5
- package/src/agents/AgentContext.ts +2 -26
- package/src/common/enum.ts +0 -15
- package/src/graphs/Graph.ts +0 -113
- package/src/graphs/MultiAgentGraph.ts +39 -0
- package/src/graphs/__tests__/MultiAgentGraph.test.ts +91 -0
- package/src/index.ts +0 -10
- package/src/messages/format.ts +4 -74
- package/src/run.ts +0 -126
- package/src/summarization/__tests__/node.test.ts +42 -0
- package/src/summarization/__tests__/trigger.test.ts +100 -1
- package/src/summarization/index.ts +47 -0
- package/src/summarization/node.ts +149 -77
- package/src/tools/ToolNode.ts +169 -391
- package/src/tools/__tests__/ToolNode.session.test.ts +12 -12
- package/src/types/graph.ts +1 -80
- package/src/types/index.ts +0 -1
- package/src/types/run.ts +0 -20
- package/src/types/tools.ts +1 -41
- package/dist/cjs/hooks/HookRegistry.cjs +0 -162
- package/dist/cjs/hooks/HookRegistry.cjs.map +0 -1
- package/dist/cjs/hooks/executeHooks.cjs +0 -276
- package/dist/cjs/hooks/executeHooks.cjs.map +0 -1
- package/dist/cjs/hooks/matchers.cjs +0 -256
- package/dist/cjs/hooks/matchers.cjs.map +0 -1
- package/dist/cjs/hooks/types.cjs +0 -27
- package/dist/cjs/hooks/types.cjs.map +0 -1
- package/dist/cjs/tools/BashExecutor.cjs +0 -175
- package/dist/cjs/tools/BashExecutor.cjs.map +0 -1
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs +0 -296
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs.map +0 -1
- package/dist/cjs/tools/ReadFile.cjs +0 -43
- package/dist/cjs/tools/ReadFile.cjs.map +0 -1
- package/dist/cjs/tools/SkillTool.cjs +0 -50
- package/dist/cjs/tools/SkillTool.cjs.map +0 -1
- package/dist/cjs/tools/SubagentTool.cjs +0 -92
- package/dist/cjs/tools/SubagentTool.cjs.map +0 -1
- package/dist/cjs/tools/skillCatalog.cjs +0 -84
- package/dist/cjs/tools/skillCatalog.cjs.map +0 -1
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs +0 -511
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +0 -1
- package/dist/esm/hooks/HookRegistry.mjs +0 -160
- package/dist/esm/hooks/HookRegistry.mjs.map +0 -1
- package/dist/esm/hooks/executeHooks.mjs +0 -273
- package/dist/esm/hooks/executeHooks.mjs.map +0 -1
- package/dist/esm/hooks/matchers.mjs +0 -251
- package/dist/esm/hooks/matchers.mjs.map +0 -1
- package/dist/esm/hooks/types.mjs +0 -25
- package/dist/esm/hooks/types.mjs.map +0 -1
- package/dist/esm/tools/BashExecutor.mjs +0 -169
- package/dist/esm/tools/BashExecutor.mjs.map +0 -1
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs +0 -287
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs.map +0 -1
- package/dist/esm/tools/ReadFile.mjs +0 -38
- package/dist/esm/tools/ReadFile.mjs.map +0 -1
- package/dist/esm/tools/SkillTool.mjs +0 -45
- package/dist/esm/tools/SkillTool.mjs.map +0 -1
- package/dist/esm/tools/SubagentTool.mjs +0 -85
- package/dist/esm/tools/SubagentTool.mjs.map +0 -1
- package/dist/esm/tools/skillCatalog.mjs +0 -82
- package/dist/esm/tools/skillCatalog.mjs.map +0 -1
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +0 -505
- package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +0 -1
- package/dist/types/hooks/HookRegistry.d.ts +0 -56
- package/dist/types/hooks/executeHooks.d.ts +0 -79
- package/dist/types/hooks/index.d.ts +0 -6
- package/dist/types/hooks/matchers.d.ts +0 -95
- package/dist/types/hooks/types.d.ts +0 -320
- package/dist/types/tools/BashExecutor.d.ts +0 -45
- package/dist/types/tools/BashProgrammaticToolCalling.d.ts +0 -72
- package/dist/types/tools/ReadFile.d.ts +0 -28
- package/dist/types/tools/SkillTool.d.ts +0 -40
- package/dist/types/tools/SubagentTool.d.ts +0 -36
- package/dist/types/tools/skillCatalog.d.ts +0 -19
- package/dist/types/tools/subagent/SubagentExecutor.d.ts +0 -137
- package/dist/types/tools/subagent/index.d.ts +0 -2
- package/dist/types/types/skill.d.ts +0 -9
- package/src/hooks/HookRegistry.ts +0 -208
- package/src/hooks/__tests__/HookRegistry.test.ts +0 -190
- package/src/hooks/__tests__/compactHooks.test.ts +0 -214
- package/src/hooks/__tests__/executeHooks.test.ts +0 -1013
- package/src/hooks/__tests__/integration.test.ts +0 -337
- package/src/hooks/__tests__/matchers.test.ts +0 -238
- package/src/hooks/__tests__/toolHooks.test.ts +0 -669
- package/src/hooks/executeHooks.ts +0 -375
- package/src/hooks/index.ts +0 -57
- package/src/hooks/matchers.ts +0 -280
- package/src/hooks/types.ts +0 -404
- package/src/messages/formatAgentMessages.skills.test.ts +0 -334
- package/src/scripts/multi-agent-subagent.ts +0 -246
- package/src/scripts/subagent-event-driven-debug.ts +0 -190
- package/src/scripts/subagent-tools-debug.ts +0 -160
- package/src/specs/subagent.test.ts +0 -305
- package/src/tools/BashExecutor.ts +0 -205
- package/src/tools/BashProgrammaticToolCalling.ts +0 -397
- package/src/tools/ReadFile.ts +0 -39
- package/src/tools/SkillTool.ts +0 -46
- package/src/tools/SubagentTool.ts +0 -100
- package/src/tools/__tests__/ReadFile.test.ts +0 -44
- package/src/tools/__tests__/SkillTool.test.ts +0 -442
- package/src/tools/__tests__/SubagentExecutor.test.ts +0 -1148
- package/src/tools/__tests__/SubagentTool.test.ts +0 -149
- package/src/tools/__tests__/skillCatalog.test.ts +0 -161
- package/src/tools/__tests__/subagentHooks.test.ts +0 -215
- package/src/tools/skillCatalog.ts +0 -126
- package/src/tools/subagent/SubagentExecutor.ts +0 -676
- package/src/tools/subagent/index.ts +0 -13
- package/src/types/skill.ts +0 -11
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var _enum = require('../common/enum.cjs');
|
|
4
|
-
|
|
5
|
-
const SubagentToolName = _enum.Constants.SUBAGENT;
|
|
6
|
-
const SubagentToolDescription = `Delegate a task to a specialized subagent that runs in an isolated context window. The subagent executes independently and returns only its final text result — all intermediate tool calls, reasoning, and context stay isolated.
|
|
7
|
-
|
|
8
|
-
WHEN TO USE:
|
|
9
|
-
- The task is self-contained and can be described in a single prompt.
|
|
10
|
-
- You want to offload verbose or exploratory work without bloating your own context.
|
|
11
|
-
- A specialized subagent is available for the task domain.
|
|
12
|
-
|
|
13
|
-
WHAT HAPPENS:
|
|
14
|
-
- A fresh agent is created with the task description as its only input.
|
|
15
|
-
- The subagent runs to completion using its own tools and context.
|
|
16
|
-
- Only the final text response is returned to you.
|
|
17
|
-
|
|
18
|
-
CONSTRAINTS:
|
|
19
|
-
- subagent_type must match one of the available types listed below.
|
|
20
|
-
- The subagent cannot see your conversation history.`;
|
|
21
|
-
const DESCRIPTION_PROP_DESCRIPTION = 'Complete task description for the subagent. This is the ONLY information it receives — include all necessary context, requirements, and constraints.';
|
|
22
|
-
const SUBAGENT_TYPE_PROP_DESCRIPTION = 'Which subagent type to delegate to. Must be one of the available types.';
|
|
23
|
-
const SubagentToolSchema = {
|
|
24
|
-
type: 'object',
|
|
25
|
-
properties: {
|
|
26
|
-
description: {
|
|
27
|
-
type: 'string',
|
|
28
|
-
description: DESCRIPTION_PROP_DESCRIPTION,
|
|
29
|
-
},
|
|
30
|
-
subagent_type: {
|
|
31
|
-
type: 'string',
|
|
32
|
-
description: SUBAGENT_TYPE_PROP_DESCRIPTION,
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
required: ['description', 'subagent_type'],
|
|
36
|
-
};
|
|
37
|
-
const SubagentToolDefinition = {
|
|
38
|
-
name: SubagentToolName,
|
|
39
|
-
description: SubagentToolDescription,
|
|
40
|
-
parameters: SubagentToolSchema,
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* Build the name, schema, and description params for `tool()` from available configs.
|
|
44
|
-
* Used by `Graph.createAgentNode()` when constructing the runtime tool instance.
|
|
45
|
-
* Extends `SubagentToolSchema` by populating `subagent_type.enum` dynamically.
|
|
46
|
-
*/
|
|
47
|
-
function buildSubagentToolParams(configs) {
|
|
48
|
-
const types = configs.map((c) => c.type);
|
|
49
|
-
const typeDescriptions = configs
|
|
50
|
-
.map((c) => `- "${c.type}" (${c.name}): ${c.description}`)
|
|
51
|
-
.join('\n');
|
|
52
|
-
return {
|
|
53
|
-
name: SubagentToolName,
|
|
54
|
-
schema: {
|
|
55
|
-
type: 'object',
|
|
56
|
-
properties: {
|
|
57
|
-
description: {
|
|
58
|
-
type: 'string',
|
|
59
|
-
description: DESCRIPTION_PROP_DESCRIPTION,
|
|
60
|
-
},
|
|
61
|
-
subagent_type: {
|
|
62
|
-
type: 'string',
|
|
63
|
-
enum: types,
|
|
64
|
-
description: `${SUBAGENT_TYPE_PROP_DESCRIPTION} Available: ${types.join(', ')}.`,
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
required: ['description', 'subagent_type'],
|
|
68
|
-
},
|
|
69
|
-
description: `${SubagentToolDescription}\n\nAvailable types:\n${typeDescriptions}`,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Create a SubagentTool LCTool definition with dynamic enum and description
|
|
74
|
-
* populated from the available subagent configs.
|
|
75
|
-
* Used for the tool registry in event-driven mode.
|
|
76
|
-
*/
|
|
77
|
-
function createSubagentToolDefinition(configs) {
|
|
78
|
-
const params = buildSubagentToolParams(configs);
|
|
79
|
-
return {
|
|
80
|
-
name: params.name,
|
|
81
|
-
description: params.description,
|
|
82
|
-
parameters: params.schema,
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
exports.SubagentToolDefinition = SubagentToolDefinition;
|
|
87
|
-
exports.SubagentToolDescription = SubagentToolDescription;
|
|
88
|
-
exports.SubagentToolName = SubagentToolName;
|
|
89
|
-
exports.SubagentToolSchema = SubagentToolSchema;
|
|
90
|
-
exports.buildSubagentToolParams = buildSubagentToolParams;
|
|
91
|
-
exports.createSubagentToolDefinition = createSubagentToolDefinition;
|
|
92
|
-
//# sourceMappingURL=SubagentTool.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SubagentTool.cjs","sources":["../../../src/tools/SubagentTool.ts"],"sourcesContent":["import { Constants } from '@/common';\nimport type { SubagentConfig } from '@/types';\nimport type { JsonSchemaType, LCTool } from '@/types/tools';\n\nexport const SubagentToolName = Constants.SUBAGENT;\n\nexport const SubagentToolDescription = `Delegate a task to a specialized subagent that runs in an isolated context window. The subagent executes independently and returns only its final text result — all intermediate tool calls, reasoning, and context stay isolated.\n\nWHEN TO USE:\n- The task is self-contained and can be described in a single prompt.\n- You want to offload verbose or exploratory work without bloating your own context.\n- A specialized subagent is available for the task domain.\n\nWHAT HAPPENS:\n- A fresh agent is created with the task description as its only input.\n- The subagent runs to completion using its own tools and context.\n- Only the final text response is returned to you.\n\nCONSTRAINTS:\n- subagent_type must match one of the available types listed below.\n- The subagent cannot see your conversation history.`;\n\nconst DESCRIPTION_PROP_DESCRIPTION =\n 'Complete task description for the subagent. This is the ONLY information it receives — include all necessary context, requirements, and constraints.';\n\nconst SUBAGENT_TYPE_PROP_DESCRIPTION =\n 'Which subagent type to delegate to. Must be one of the available types.';\n\nexport const SubagentToolSchema = {\n type: 'object',\n properties: {\n description: {\n type: 'string',\n description: DESCRIPTION_PROP_DESCRIPTION,\n },\n subagent_type: {\n type: 'string',\n description: SUBAGENT_TYPE_PROP_DESCRIPTION,\n },\n },\n required: ['description', 'subagent_type'] as string[],\n} as const;\n\nexport const SubagentToolDefinition: LCTool = {\n name: SubagentToolName,\n description: SubagentToolDescription,\n parameters: SubagentToolSchema,\n};\n\n/**\n * Build the name, schema, and description params for `tool()` from available configs.\n * Used by `Graph.createAgentNode()` when constructing the runtime tool instance.\n * Extends `SubagentToolSchema` by populating `subagent_type.enum` dynamically.\n */\nexport function buildSubagentToolParams(configs: SubagentConfig[]): {\n name: string;\n schema: JsonSchemaType;\n description: string;\n} {\n const types = configs.map((c) => c.type);\n const typeDescriptions = configs\n .map((c) => `- \"${c.type}\" (${c.name}): ${c.description}`)\n .join('\\n');\n\n return {\n name: SubagentToolName,\n schema: {\n type: 'object',\n properties: {\n description: {\n type: 'string',\n description: DESCRIPTION_PROP_DESCRIPTION,\n },\n subagent_type: {\n type: 'string',\n enum: types,\n description: `${SUBAGENT_TYPE_PROP_DESCRIPTION} Available: ${types.join(', ')}.`,\n },\n },\n required: ['description', 'subagent_type'],\n },\n description: `${SubagentToolDescription}\\n\\nAvailable types:\\n${typeDescriptions}`,\n };\n}\n\n/**\n * Create a SubagentTool LCTool definition with dynamic enum and description\n * populated from the available subagent configs.\n * Used for the tool registry in event-driven mode.\n */\nexport function createSubagentToolDefinition(\n configs: SubagentConfig[]\n): LCTool {\n const params = buildSubagentToolParams(configs);\n return {\n name: params.name,\n description: params.description,\n parameters: params.schema,\n };\n}\n"],"names":["Constants"],"mappings":";;;;AAIO,MAAM,gBAAgB,GAAGA,eAAS,CAAC;AAEnC,MAAM,uBAAuB,GAAG,CAAA;;;;;;;;;;;;;;;AAgBvC,MAAM,4BAA4B,GAChC,sJAAsJ;AAExJ,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AI,CAAC,IAAI,CAAC,CAAA,CAAA,CAAG;AACjF,iBAAA;AACF,aAAA;AACD,YAAA,QAAQ,EAAE,CAAC,aAAa,EAAE,eAAe,CAAC;AAC3C,SAAA;AACD,QAAA,WAAW,EAAE,CAAA,EAAG,uBAAuB,CAAA,sBAAA,EAAyB,gBAAgB,CAAA,CAAE;KACnF;AACH;AAEA;;;;AAIG;AACG,SAAU,4BAA4B,CAC1C,OAAyB,EAAA;AAEzB,IAAA,MAAM,MAAM,GAAG,uBAAuB,CAAC,OAAO,CAAC;IAC/C,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,UAAU,EAAE,MAAM,CAAC,MAAM;KAC1B;AACH;;;;;;;;;"}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const HEADER = '## Available Skills';
|
|
4
|
-
const DEFAULT_CONTEXT_WINDOW_TOKENS = 200_000;
|
|
5
|
-
const DEFAULT_BUDGET_PERCENT = 0.01;
|
|
6
|
-
const DEFAULT_MAX_ENTRY_CHARS = 250;
|
|
7
|
-
const DEFAULT_MIN_DESC_LENGTH = 20;
|
|
8
|
-
const DEFAULT_CHARS_PER_TOKEN = 4;
|
|
9
|
-
/**
|
|
10
|
-
* Formats a skill catalog for injection into agent context.
|
|
11
|
-
* Uses a truncation ladder: full descriptions, proportional truncation, names-only.
|
|
12
|
-
* Returns empty string for empty input.
|
|
13
|
-
*/
|
|
14
|
-
function formatSkillCatalog(skills, opts) {
|
|
15
|
-
if (skills.length === 0)
|
|
16
|
-
return '';
|
|
17
|
-
const contextWindowTokens = opts?.contextWindowTokens ?? DEFAULT_CONTEXT_WINDOW_TOKENS;
|
|
18
|
-
const budgetPercent = opts?.budgetPercent ?? DEFAULT_BUDGET_PERCENT;
|
|
19
|
-
const maxEntryChars = Math.max(1, opts?.maxEntryChars ?? DEFAULT_MAX_ENTRY_CHARS);
|
|
20
|
-
const minDescLength = opts?.minDescLength ?? DEFAULT_MIN_DESC_LENGTH;
|
|
21
|
-
const charsPerToken = opts?.charsPerToken ?? DEFAULT_CHARS_PER_TOKEN;
|
|
22
|
-
const budgetChars = Math.floor(contextWindowTokens * budgetPercent * charsPerToken);
|
|
23
|
-
const capped = skills.map((s) => ({
|
|
24
|
-
name: s.name,
|
|
25
|
-
description: s.description.length > maxEntryChars
|
|
26
|
-
? s.description.slice(0, maxEntryChars - 1) + '\u2026'
|
|
27
|
-
: s.description,
|
|
28
|
-
}));
|
|
29
|
-
const fullOutput = formatEntries(capped);
|
|
30
|
-
if (fullOutput.length <= budgetChars)
|
|
31
|
-
return fullOutput;
|
|
32
|
-
const headerLen = HEADER.length + 2;
|
|
33
|
-
const newlineChars = capped.length > 1 ? capped.length - 1 : 0;
|
|
34
|
-
const availableChars = budgetChars - headerLen - newlineChars;
|
|
35
|
-
const perEntryOverhead = 4;
|
|
36
|
-
const nameCharsTotal = capped.reduce((sum, s) => sum + s.name.length + perEntryOverhead, 0);
|
|
37
|
-
const availableForDescs = availableChars - nameCharsTotal;
|
|
38
|
-
if (availableForDescs <= 0) {
|
|
39
|
-
return fitNamesOnly(capped, budgetChars);
|
|
40
|
-
}
|
|
41
|
-
const maxDescPerEntry = Math.floor(availableForDescs / capped.length);
|
|
42
|
-
if (maxDescPerEntry < minDescLength) {
|
|
43
|
-
return fitNamesOnly(capped, budgetChars);
|
|
44
|
-
}
|
|
45
|
-
const truncated = capped.map((s) => ({
|
|
46
|
-
name: s.name,
|
|
47
|
-
description: s.description.length > maxDescPerEntry
|
|
48
|
-
? s.description.slice(0, maxDescPerEntry - 1) + '\u2026'
|
|
49
|
-
: s.description,
|
|
50
|
-
}));
|
|
51
|
-
const result = formatEntries(truncated);
|
|
52
|
-
if (result.length <= budgetChars)
|
|
53
|
-
return result;
|
|
54
|
-
return fitNamesOnly(capped, budgetChars);
|
|
55
|
-
}
|
|
56
|
-
function formatEntries(entries) {
|
|
57
|
-
const lines = entries.map((e) => e.description ? `- ${e.name}: ${e.description}` : `- ${e.name}`);
|
|
58
|
-
return `${HEADER}\n\n${lines.join('\n')}`;
|
|
59
|
-
}
|
|
60
|
-
/** Names-only fallback that drops trailing entries if the list still exceeds budget. */
|
|
61
|
-
function fitNamesOnly(entries, budgetChars) {
|
|
62
|
-
// Format: "HEADER\n\n- name1\n- name2\n..."
|
|
63
|
-
// Running sum avoids O(n²) repeated string construction.
|
|
64
|
-
const prefix = HEADER.length + 2; // "HEADER\n\n"
|
|
65
|
-
const entryOverhead = 2; // "- "
|
|
66
|
-
let total = prefix;
|
|
67
|
-
let fitCount = 0;
|
|
68
|
-
for (let i = 0; i < entries.length; i++) {
|
|
69
|
-
const added = (i > 0 ? 1 : 0) + entryOverhead + entries[i].name.length;
|
|
70
|
-
if (total + added > budgetChars)
|
|
71
|
-
break;
|
|
72
|
-
total += added;
|
|
73
|
-
fitCount = i + 1;
|
|
74
|
-
}
|
|
75
|
-
if (fitCount === 0)
|
|
76
|
-
return '';
|
|
77
|
-
const namesOnly = entries
|
|
78
|
-
.slice(0, fitCount)
|
|
79
|
-
.map((s) => ({ name: s.name, description: '' }));
|
|
80
|
-
return formatEntries(namesOnly);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
exports.formatSkillCatalog = formatSkillCatalog;
|
|
84
|
-
//# sourceMappingURL=skillCatalog.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"skillCatalog.cjs","sources":["../../../src/tools/skillCatalog.ts"],"sourcesContent":["// src/tools/skillCatalog.ts\nimport type { SkillCatalogEntry } from '@/types';\n\nconst HEADER = '## Available Skills';\nconst DEFAULT_CONTEXT_WINDOW_TOKENS = 200_000;\nconst DEFAULT_BUDGET_PERCENT = 0.01;\nconst DEFAULT_MAX_ENTRY_CHARS = 250;\nconst DEFAULT_MIN_DESC_LENGTH = 20;\nconst DEFAULT_CHARS_PER_TOKEN = 4;\n\nexport type SkillCatalogOptions = {\n /** Total context window in tokens. Default: 200_000 */\n contextWindowTokens?: number;\n /** Fraction of context budget for catalog. Default: 0.01 (1%) */\n budgetPercent?: number;\n /** Max chars per entry description. Default: 250 */\n maxEntryChars?: number;\n /** Descriptions below this length trigger names-only fallback. Default: 20 */\n minDescLength?: number;\n /** Approximate chars per token for budget calculation. Default: 4 */\n charsPerToken?: number;\n};\n\n/**\n * Formats a skill catalog for injection into agent context.\n * Uses a truncation ladder: full descriptions, proportional truncation, names-only.\n * Returns empty string for empty input.\n */\nexport function formatSkillCatalog(\n skills: SkillCatalogEntry[],\n opts?: SkillCatalogOptions\n): string {\n if (skills.length === 0) return '';\n\n const contextWindowTokens =\n opts?.contextWindowTokens ?? DEFAULT_CONTEXT_WINDOW_TOKENS;\n const budgetPercent = opts?.budgetPercent ?? DEFAULT_BUDGET_PERCENT;\n const maxEntryChars = Math.max(\n 1,\n opts?.maxEntryChars ?? DEFAULT_MAX_ENTRY_CHARS\n );\n const minDescLength = opts?.minDescLength ?? DEFAULT_MIN_DESC_LENGTH;\n const charsPerToken = opts?.charsPerToken ?? DEFAULT_CHARS_PER_TOKEN;\n\n const budgetChars = Math.floor(\n contextWindowTokens * budgetPercent * charsPerToken\n );\n\n const capped = skills.map((s) => ({\n name: s.name,\n description:\n s.description.length > maxEntryChars\n ? s.description.slice(0, maxEntryChars - 1) + '\\u2026'\n : s.description,\n }));\n\n const fullOutput = formatEntries(capped);\n if (fullOutput.length <= budgetChars) return fullOutput;\n\n const headerLen = HEADER.length + 2;\n const newlineChars = capped.length > 1 ? capped.length - 1 : 0;\n const availableChars = budgetChars - headerLen - newlineChars;\n const perEntryOverhead = 4;\n const nameCharsTotal = capped.reduce(\n (sum, s) => sum + s.name.length + perEntryOverhead,\n 0\n );\n const availableForDescs = availableChars - nameCharsTotal;\n\n if (availableForDescs <= 0) {\n return fitNamesOnly(capped, budgetChars);\n }\n\n const maxDescPerEntry = Math.floor(availableForDescs / capped.length);\n\n if (maxDescPerEntry < minDescLength) {\n return fitNamesOnly(capped, budgetChars);\n }\n\n const truncated = capped.map((s) => ({\n name: s.name,\n description:\n s.description.length > maxDescPerEntry\n ? s.description.slice(0, maxDescPerEntry - 1) + '\\u2026'\n : s.description,\n }));\n\n const result = formatEntries(truncated);\n if (result.length <= budgetChars) return result;\n return fitNamesOnly(capped, budgetChars);\n}\n\nfunction formatEntries(\n entries: { name: string; description: string }[]\n): string {\n const lines = entries.map((e) =>\n e.description ? `- ${e.name}: ${e.description}` : `- ${e.name}`\n );\n return `${HEADER}\\n\\n${lines.join('\\n')}`;\n}\n\n/** Names-only fallback that drops trailing entries if the list still exceeds budget. */\nfunction fitNamesOnly(\n entries: { name: string }[],\n budgetChars: number\n): string {\n // Format: \"HEADER\\n\\n- name1\\n- name2\\n...\"\n // Running sum avoids O(n²) repeated string construction.\n const prefix = HEADER.length + 2; // \"HEADER\\n\\n\"\n const entryOverhead = 2; // \"- \"\n let total = prefix;\n let fitCount = 0;\n\n for (let i = 0; i < entries.length; i++) {\n const added = (i > 0 ? 1 : 0) + entryOverhead + entries[i].name.length;\n if (total + added > budgetChars) break;\n total += added;\n fitCount = i + 1;\n }\n\n if (fitCount === 0) return '';\n const namesOnly = entries\n .slice(0, fitCount)\n .map((s) => ({ name: s.name, description: '' }));\n return formatEntries(namesOnly);\n}\n"],"names":[],"mappings":";;AAGA,MAAM,MAAM,GAAG,qBAAqB;AACpC,MAAM,6BAA6B,GAAG,OAAO;AAC7C,MAAM,sBAAsB,GAAG,IAAI;AACnC,MAAM,uBAAuB,GAAG,GAAG;AACnC,MAAM,uBAAuB,GAAG,EAAE;AAClC,MAAM,uBAAuB,GAAG,CAAC;AAejC;;;;AAIG;AACG,SAAU,kBAAkB,CAChC,MAA2B,EAC3B,IAA0B,EAAA;AAE1B,IAAA,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;AAAE,QAAA,OAAO,EAAE;AAElC,IAAA,MAAM,mBAAmB,GACvB,IAAI,EAAE,mBAAmB,IAAI,6BAA6B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