@namzu/sdk 0.1.2 → 0.1.4-rc.1
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/README.md +19 -1
- package/dist/advisory/context.d.ts +23 -0
- package/dist/advisory/context.d.ts.map +1 -0
- package/dist/advisory/context.js +33 -0
- package/dist/advisory/context.js.map +1 -0
- package/dist/advisory/evaluator.d.ts +14 -0
- package/dist/advisory/evaluator.d.ts.map +1 -0
- package/dist/advisory/evaluator.js +87 -0
- package/dist/advisory/evaluator.js.map +1 -0
- package/dist/advisory/executor.d.ts +40 -0
- package/dist/advisory/executor.d.ts.map +1 -0
- package/dist/advisory/executor.js +132 -0
- package/dist/advisory/executor.js.map +1 -0
- package/dist/advisory/index.d.ts +6 -0
- package/dist/advisory/index.d.ts.map +1 -0
- package/dist/advisory/index.js +5 -0
- package/dist/advisory/index.js.map +1 -0
- package/dist/advisory/registry.d.ts +14 -0
- package/dist/advisory/registry.d.ts.map +1 -0
- package/dist/advisory/registry.js +36 -0
- package/dist/advisory/registry.js.map +1 -0
- package/dist/agents/SupervisorAgent.d.ts.map +1 -1
- package/dist/agents/SupervisorAgent.js +11 -1
- package/dist/agents/SupervisorAgent.js.map +1 -1
- package/dist/compaction/extractor.d.ts +7 -0
- package/dist/compaction/extractor.d.ts.map +1 -0
- package/dist/compaction/extractor.js +131 -0
- package/dist/compaction/extractor.js.map +1 -0
- package/dist/compaction/index.d.ts +6 -0
- package/dist/compaction/index.d.ts.map +1 -0
- package/dist/compaction/index.js +5 -0
- package/dist/compaction/index.js.map +1 -0
- package/dist/compaction/manager.d.ts +22 -0
- package/dist/compaction/manager.d.ts.map +1 -0
- package/dist/compaction/manager.js +91 -0
- package/dist/compaction/manager.js.map +1 -0
- package/dist/compaction/serializer.d.ts +3 -0
- package/dist/compaction/serializer.d.ts.map +1 -0
- package/dist/compaction/serializer.js +67 -0
- package/dist/compaction/serializer.js.map +1 -0
- package/dist/compaction/types.d.ts +40 -0
- package/dist/compaction/types.d.ts.map +1 -0
- package/dist/compaction/types.js +2 -0
- package/dist/compaction/types.js.map +1 -0
- package/dist/compaction/verifier.d.ts +6 -0
- package/dist/compaction/verifier.d.ts.map +1 -0
- package/dist/compaction/verifier.js +68 -0
- package/dist/compaction/verifier.js.map +1 -0
- package/dist/config/runtime.d.ts +193 -0
- package/dist/config/runtime.d.ts.map +1 -1
- package/dist/config/runtime.js +29 -0
- package/dist/config/runtime.js.map +1 -1
- package/dist/constants/advisory/index.d.ts +8 -0
- package/dist/constants/advisory/index.d.ts.map +1 -0
- package/dist/constants/advisory/index.js +8 -0
- package/dist/constants/advisory/index.js.map +1 -0
- package/dist/constants/compaction/index.d.ts +17 -0
- package/dist/constants/compaction/index.d.ts.map +1 -0
- package/dist/constants/compaction/index.js +17 -0
- package/dist/constants/compaction/index.js.map +1 -0
- package/dist/constants/index.d.ts +2 -0
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/constants/index.js +2 -0
- package/dist/constants/index.js.map +1 -1
- package/dist/contracts/schemas.d.ts +20 -20
- package/dist/index.d.ts +13 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/persona/assembler.d.ts +2 -1
- package/dist/persona/assembler.d.ts.map +1 -1
- package/dist/persona/assembler.js +23 -0
- package/dist/persona/assembler.js.map +1 -1
- package/dist/registry/tool/execute.d.ts +3 -0
- package/dist/registry/tool/execute.d.ts.map +1 -1
- package/dist/registry/tool/execute.js +45 -11
- package/dist/registry/tool/execute.js.map +1 -1
- package/dist/router/index.d.ts +2 -0
- package/dist/router/index.d.ts.map +1 -0
- package/dist/router/index.js +2 -0
- package/dist/router/index.js.map +1 -0
- package/dist/router/task-router.d.ts +8 -0
- package/dist/router/task-router.d.ts.map +1 -0
- package/dist/router/task-router.js +19 -0
- package/dist/router/task-router.js.map +1 -0
- package/dist/runtime/query/executor.d.ts +1 -0
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +19 -1
- package/dist/runtime/query/executor.js.map +1 -1
- package/dist/runtime/query/index.d.ts +2 -0
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/prompt.d.ts.map +1 -1
- package/dist/runtime/query/prompt.js +4 -0
- package/dist/runtime/query/prompt.js.map +1 -1
- package/dist/tools/advisory/index.d.ts +7 -0
- package/dist/tools/advisory/index.d.ts.map +1 -0
- package/dist/tools/advisory/index.js +125 -0
- package/dist/tools/advisory/index.js.map +1 -0
- package/dist/tools/defineTool.d.ts +1 -0
- package/dist/tools/defineTool.d.ts.map +1 -1
- package/dist/tools/defineTool.js +1 -0
- package/dist/tools/defineTool.js.map +1 -1
- package/dist/types/advisory/config.d.ts +33 -0
- package/dist/types/advisory/config.d.ts.map +1 -0
- package/dist/types/advisory/config.js +2 -0
- package/dist/types/advisory/config.js.map +1 -0
- package/dist/types/advisory/index.d.ts +4 -0
- package/dist/types/advisory/index.d.ts.map +1 -0
- package/dist/types/advisory/index.js +2 -0
- package/dist/types/advisory/index.js.map +1 -0
- package/dist/types/advisory/result.d.ts +35 -0
- package/dist/types/advisory/result.d.ts.map +1 -0
- package/dist/types/advisory/result.js +2 -0
- package/dist/types/advisory/result.js.map +1 -0
- package/dist/types/advisory/trigger.d.ts +44 -0
- package/dist/types/advisory/trigger.d.ts.map +1 -0
- package/dist/types/advisory/trigger.js +2 -0
- package/dist/types/advisory/trigger.js.map +1 -0
- package/dist/types/agent/factory.d.ts +2 -0
- package/dist/types/agent/factory.d.ts.map +1 -1
- package/dist/types/agent/supervisor.d.ts +2 -0
- package/dist/types/agent/supervisor.d.ts.map +1 -1
- package/dist/types/ids/index.d.ts +2 -0
- package/dist/types/ids/index.d.ts.map +1 -1
- package/dist/types/persona/index.d.ts +9 -0
- package/dist/types/persona/index.d.ts.map +1 -1
- package/dist/types/router/index.d.ts +2 -0
- package/dist/types/router/index.d.ts.map +1 -0
- package/dist/types/router/index.js +2 -0
- package/dist/types/router/index.js.map +1 -0
- package/dist/types/router/task-router.d.ts +12 -0
- package/dist/types/router/task-router.d.ts.map +1 -0
- package/dist/types/router/task-router.js +2 -0
- package/dist/types/router/task-router.js.map +1 -0
- package/dist/types/tool/index.d.ts +13 -0
- package/dist/types/tool/index.d.ts.map +1 -1
- package/dist/utils/id.d.ts +3 -1
- package/dist/utils/id.d.ts.map +1 -1
- package/dist/utils/id.js +6 -0
- package/dist/utils/id.js.map +1 -1
- package/dist/utils/shell-compress.d.ts +13 -0
- package/dist/utils/shell-compress.d.ts.map +1 -0
- package/dist/utils/shell-compress.js +97 -0
- package/dist/utils/shell-compress.js.map +1 -0
- package/package.json +9 -5
- package/src/advisory/context.ts +47 -0
- package/src/advisory/evaluator.ts +98 -0
- package/src/advisory/executor.ts +187 -0
- package/src/advisory/index.ts +5 -0
- package/src/advisory/registry.ts +42 -0
- package/src/agents/SupervisorAgent.ts +12 -1
- package/src/compaction/extractor.ts +149 -0
- package/src/compaction/index.ts +21 -0
- package/src/compaction/manager.ts +107 -0
- package/src/compaction/serializer.ts +88 -0
- package/src/compaction/types.ts +37 -0
- package/src/compaction/verifier.ts +91 -0
- package/src/config/runtime.ts +33 -0
- package/src/constants/advisory/index.ts +7 -0
- package/src/constants/compaction/index.ts +20 -0
- package/src/constants/index.ts +2 -0
- package/src/index.ts +50 -2
- package/src/persona/assembler.ts +36 -1
- package/src/registry/tool/execute.ts +51 -11
- package/src/router/index.ts +1 -0
- package/src/router/task-router.ts +24 -0
- package/src/runtime/query/executor.ts +22 -1
- package/src/runtime/query/index.ts +3 -0
- package/src/runtime/query/prompt.ts +5 -0
- package/src/tools/advisory/index.ts +157 -0
- package/src/tools/defineTool.ts +2 -0
- package/src/types/advisory/config.ts +35 -0
- package/src/types/advisory/index.ts +18 -0
- package/src/types/advisory/result.ts +34 -0
- package/src/types/advisory/trigger.ts +39 -0
- package/src/types/agent/factory.ts +3 -0
- package/src/types/agent/supervisor.ts +3 -0
- package/src/types/ids/index.ts +2 -0
- package/src/types/persona/index.ts +11 -0
- package/src/types/router/index.ts +1 -0
- package/src/types/router/task-router.ts +20 -0
- package/src/types/tool/index.ts +15 -0
- package/src/utils/id.ts +10 -0
- package/src/utils/shell-compress.ts +137 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
const STACK_FRAME_RE = /^\s+at\s+|^\s+File\s+"[^"]+",\s+line\s+\d+|^\s+at\s+[\w.$]+\(|^\s+\d+:\s+\w|^\s+from\s+\//;
|
|
2
|
+
const PASS_LINE_RE = /[\s✓✔√●∙·►▸▹]+\s*(PASS|pass|ok|OK|✓|✔|√)\s|^\s*(PASS|ok)\s+[\w/.-]+|^ok\s+\d+\s|PASSED\s*$|^---\s*PASS:|^test\s+\S+\s+\.\.\.\s+ok\s*$/;
|
|
3
|
+
const NOISE_RE = /^\s*[\\\/|─━░▓█▒■□◻◼⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏⣾⣽⣻⢿⡿⣟⣯⣷]+\s*$|^\s*\d+%\s*[|█▓░]+|^(Downloading|Fetching|Installing|Resolving|Compiling)\b.*\.\.\./;
|
|
4
|
+
const DEFAULT_MIN_LINES = 20;
|
|
5
|
+
const DEFAULT_MIN_REDUCTION = 0.1;
|
|
6
|
+
const DEFAULT_MAX_STACK_FRAMES = 5;
|
|
7
|
+
const DEFAULT_MAX_PASS_LINES = 3;
|
|
8
|
+
function normalizeLine(line) {
|
|
9
|
+
return line.replace(/^\s*\d+[\s:.|)]+/, '').replace(/\d+/g, 'N');
|
|
10
|
+
}
|
|
11
|
+
function collapseRepeated(lines) {
|
|
12
|
+
const result = [];
|
|
13
|
+
let prevNorm = '';
|
|
14
|
+
let repeatCount = 0;
|
|
15
|
+
for (const line of lines) {
|
|
16
|
+
const norm = normalizeLine(line);
|
|
17
|
+
if (norm === prevNorm && norm.trim().length > 0) {
|
|
18
|
+
repeatCount++;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
if (repeatCount > 0) {
|
|
22
|
+
result.push(`... ${repeatCount} similar line${repeatCount === 1 ? '' : 's'} omitted`);
|
|
23
|
+
}
|
|
24
|
+
result.push(line);
|
|
25
|
+
prevNorm = norm;
|
|
26
|
+
repeatCount = 0;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (repeatCount > 0) {
|
|
30
|
+
result.push(`... ${repeatCount} similar line${repeatCount === 1 ? '' : 's'} omitted`);
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
export function compressShellOutputFull(raw, options) {
|
|
35
|
+
const minLines = options?.minLines ?? DEFAULT_MIN_LINES;
|
|
36
|
+
const minReduction = options?.minReductionPercent ?? DEFAULT_MIN_REDUCTION;
|
|
37
|
+
const maxStackFrames = options?.maxStackFrames ?? DEFAULT_MAX_STACK_FRAMES;
|
|
38
|
+
const maxPassLines = options?.maxPassLines ?? DEFAULT_MAX_PASS_LINES;
|
|
39
|
+
const lines = raw.split('\n');
|
|
40
|
+
if (lines.length < minLines) {
|
|
41
|
+
return { text: raw, original: null };
|
|
42
|
+
}
|
|
43
|
+
// Pass 1: stack frame compression, pass test suppression, noise removal
|
|
44
|
+
const pass1 = [];
|
|
45
|
+
let stackCount = 0;
|
|
46
|
+
let passCount = 0;
|
|
47
|
+
for (const line of lines) {
|
|
48
|
+
// Noise removal
|
|
49
|
+
if (NOISE_RE.test(line)) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
// Stack frame compression
|
|
53
|
+
if (STACK_FRAME_RE.test(line)) {
|
|
54
|
+
stackCount++;
|
|
55
|
+
if (stackCount <= maxStackFrames) {
|
|
56
|
+
pass1.push(line);
|
|
57
|
+
}
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (stackCount > maxStackFrames) {
|
|
61
|
+
pass1.push(`... ${stackCount - maxStackFrames} more frames`);
|
|
62
|
+
}
|
|
63
|
+
stackCount = 0;
|
|
64
|
+
// Pass test suppression
|
|
65
|
+
if (PASS_LINE_RE.test(line)) {
|
|
66
|
+
passCount++;
|
|
67
|
+
if (passCount <= maxPassLines) {
|
|
68
|
+
pass1.push(line);
|
|
69
|
+
}
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (passCount > maxPassLines) {
|
|
73
|
+
pass1.push(`... ${passCount - maxPassLines} passing tests omitted`);
|
|
74
|
+
}
|
|
75
|
+
passCount = 0;
|
|
76
|
+
pass1.push(line);
|
|
77
|
+
}
|
|
78
|
+
// Flush trailing counters
|
|
79
|
+
if (stackCount > maxStackFrames) {
|
|
80
|
+
pass1.push(`... ${stackCount - maxStackFrames} more frames`);
|
|
81
|
+
}
|
|
82
|
+
if (passCount > maxPassLines) {
|
|
83
|
+
pass1.push(`... ${passCount - maxPassLines} passing tests omitted`);
|
|
84
|
+
}
|
|
85
|
+
// Pass 2: collapse repeated lines
|
|
86
|
+
const pass2 = collapseRepeated(pass1);
|
|
87
|
+
const compressed = pass2.join('\n');
|
|
88
|
+
const reduction = 1 - compressed.length / raw.length;
|
|
89
|
+
if (reduction < minReduction) {
|
|
90
|
+
return { text: raw, original: null };
|
|
91
|
+
}
|
|
92
|
+
return { text: compressed, original: raw };
|
|
93
|
+
}
|
|
94
|
+
export function compressShellOutput(raw, options) {
|
|
95
|
+
return compressShellOutputFull(raw, options).text;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=shell-compress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell-compress.js","sourceRoot":"","sources":["../../src/utils/shell-compress.ts"],"names":[],"mappings":"AAAA,MAAM,cAAc,GACnB,2FAA2F,CAAA;AAE5F,MAAM,YAAY,GACjB,uIAAuI,CAAA;AAExI,MAAM,QAAQ,GACb,kIAAkI,CAAA;AAEnI,MAAM,iBAAiB,GAAG,EAAE,CAAA;AAC5B,MAAM,qBAAqB,GAAG,GAAG,CAAA;AACjC,MAAM,wBAAwB,GAAG,CAAC,CAAA;AAClC,MAAM,sBAAs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.1",
|
|
4
|
+
"description": "Open-source AI agent framework — multi-model, multi-tenant, MCP + A2A native",
|
|
4
5
|
"license": "FSL-1.1-MIT",
|
|
5
6
|
"type": "module",
|
|
6
7
|
"packageManager": "pnpm@10.33.0",
|
|
@@ -12,12 +13,12 @@
|
|
|
12
13
|
"bugs": {
|
|
13
14
|
"url": "https://github.com/cogitave/namzu/issues"
|
|
14
15
|
},
|
|
15
|
-
"main": "./
|
|
16
|
-
"types": "./
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
17
18
|
"exports": {
|
|
18
19
|
".": {
|
|
19
|
-
"import": "./
|
|
20
|
-
"types": "./
|
|
20
|
+
"import": "./dist/index.js",
|
|
21
|
+
"types": "./dist/index.d.ts"
|
|
21
22
|
}
|
|
22
23
|
},
|
|
23
24
|
"files": [
|
|
@@ -43,6 +44,9 @@
|
|
|
43
44
|
"release:patch": "bash scripts/release.sh patch",
|
|
44
45
|
"release:minor": "bash scripts/release.sh minor",
|
|
45
46
|
"release:major": "bash scripts/release.sh major",
|
|
47
|
+
"release:rc": "bash scripts/release.sh rc",
|
|
48
|
+
"release:beta": "bash scripts/release.sh beta",
|
|
49
|
+
"release:stable": "bash scripts/release.sh stable",
|
|
46
50
|
"release:dry": "bash scripts/release.sh patch --dry-run",
|
|
47
51
|
"prepublishOnly": "pnpm lint && pnpm typecheck && pnpm build"
|
|
48
52
|
},
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { AdvisoryBudget, AdvisoryCallRecord } from '../types/advisory/index.js'
|
|
2
|
+
import type { TriggerEvaluator } from './evaluator.js'
|
|
3
|
+
import type { AdvisoryExecutor } from './executor.js'
|
|
4
|
+
import type { AdvisorRegistry } from './registry.js'
|
|
5
|
+
|
|
6
|
+
export class AdvisoryContext {
|
|
7
|
+
readonly registry: AdvisorRegistry
|
|
8
|
+
readonly executor: AdvisoryExecutor
|
|
9
|
+
readonly evaluator: TriggerEvaluator
|
|
10
|
+
readonly callHistory: AdvisoryCallRecord[] = []
|
|
11
|
+
|
|
12
|
+
private readonly budget: AdvisoryBudget | undefined
|
|
13
|
+
|
|
14
|
+
constructor(
|
|
15
|
+
registry: AdvisorRegistry,
|
|
16
|
+
executor: AdvisoryExecutor,
|
|
17
|
+
evaluator: TriggerEvaluator,
|
|
18
|
+
budget?: AdvisoryBudget,
|
|
19
|
+
) {
|
|
20
|
+
this.registry = registry
|
|
21
|
+
this.executor = executor
|
|
22
|
+
this.evaluator = evaluator
|
|
23
|
+
this.budget = budget
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
recordCall(record: AdvisoryCallRecord): void {
|
|
27
|
+
this.callHistory.push(record)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
getBudgetStatus(): { remaining: number | undefined; total: number | undefined; used: number } {
|
|
31
|
+
const used = this.callHistory.length
|
|
32
|
+
const total = this.budget?.maxCallsPerRun
|
|
33
|
+
const remaining = total !== undefined ? total - used : undefined
|
|
34
|
+
return { remaining, total, used }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
checkBudget(): { allowed: boolean; reason?: string } {
|
|
38
|
+
const { remaining, total } = this.getBudgetStatus()
|
|
39
|
+
if (remaining !== undefined && remaining <= 0) {
|
|
40
|
+
return {
|
|
41
|
+
allowed: false,
|
|
42
|
+
reason: `Advisory budget exhausted: ${total} calls used of ${total} allowed per run`,
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return { allowed: true }
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AdvisoryBudget,
|
|
3
|
+
AdvisoryTrigger,
|
|
4
|
+
TriggerCondition,
|
|
5
|
+
TriggerEvaluationState,
|
|
6
|
+
} from '../types/advisory/index.js'
|
|
7
|
+
|
|
8
|
+
function assertNever(value: never): never {
|
|
9
|
+
throw new Error(`Unhandled trigger condition type: ${(value as TriggerCondition).type}`)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class TriggerEvaluator {
|
|
13
|
+
private readonly triggers: AdvisoryTrigger[]
|
|
14
|
+
private readonly budget: AdvisoryBudget | undefined
|
|
15
|
+
private readonly lastFiredMap: Map<string, number> = new Map()
|
|
16
|
+
private callCount = 0
|
|
17
|
+
|
|
18
|
+
constructor(triggers: AdvisoryTrigger[], budget?: AdvisoryBudget) {
|
|
19
|
+
this.triggers = triggers
|
|
20
|
+
.filter((t) => t.enabled !== false)
|
|
21
|
+
.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0))
|
|
22
|
+
this.budget = budget
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
evaluate(state: TriggerEvaluationState): AdvisoryTrigger[] {
|
|
26
|
+
if (this.isBudgetExhausted()) {
|
|
27
|
+
return []
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const fired: AdvisoryTrigger[] = []
|
|
31
|
+
for (const trigger of this.triggers) {
|
|
32
|
+
if (!this.isCooldownSatisfied(trigger, state.iteration)) {
|
|
33
|
+
continue
|
|
34
|
+
}
|
|
35
|
+
if (this.matchesCondition(trigger.condition, state)) {
|
|
36
|
+
fired.push(trigger)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return fired
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
recordFiring(triggerId: string, iteration: number): void {
|
|
43
|
+
this.lastFiredMap.set(triggerId, iteration)
|
|
44
|
+
this.callCount++
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private isBudgetExhausted(): boolean {
|
|
48
|
+
if (this.budget?.maxCallsPerRun === undefined) {
|
|
49
|
+
return false
|
|
50
|
+
}
|
|
51
|
+
return this.callCount >= this.budget.maxCallsPerRun
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
private isCooldownSatisfied(trigger: AdvisoryTrigger, currentIteration: number): boolean {
|
|
55
|
+
if (trigger.cooldownIterations === undefined) {
|
|
56
|
+
return true
|
|
57
|
+
}
|
|
58
|
+
const lastFired = this.lastFiredMap.get(trigger.id)
|
|
59
|
+
if (lastFired === undefined) {
|
|
60
|
+
return true
|
|
61
|
+
}
|
|
62
|
+
return currentIteration - lastFired >= trigger.cooldownIterations
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private matchesCondition(condition: TriggerCondition, state: TriggerEvaluationState): boolean {
|
|
66
|
+
switch (condition.type) {
|
|
67
|
+
case 'on_error': {
|
|
68
|
+
if (state.lastError === undefined) return false
|
|
69
|
+
if (condition.categories && condition.categories.length > 0) {
|
|
70
|
+
return condition.categories.some((cat) => state.lastError?.includes(cat))
|
|
71
|
+
}
|
|
72
|
+
return true
|
|
73
|
+
}
|
|
74
|
+
case 'on_iteration': {
|
|
75
|
+
return state.iteration % condition.everyN === 0
|
|
76
|
+
}
|
|
77
|
+
case 'on_context_percent': {
|
|
78
|
+
return state.contextWindowPercent >= condition.threshold
|
|
79
|
+
}
|
|
80
|
+
case 'on_tool_category': {
|
|
81
|
+
if (state.lastToolCategory === undefined) return false
|
|
82
|
+
return condition.categories.includes(state.lastToolCategory)
|
|
83
|
+
}
|
|
84
|
+
case 'on_cost_percent': {
|
|
85
|
+
if (state.costBudgetPercent === undefined) return false
|
|
86
|
+
return state.costBudgetPercent >= condition.threshold
|
|
87
|
+
}
|
|
88
|
+
case 'on_complexity': {
|
|
89
|
+
return state.totalToolCalls >= condition.toolCallThreshold
|
|
90
|
+
}
|
|
91
|
+
case 'custom': {
|
|
92
|
+
return condition.predicate(state)
|
|
93
|
+
}
|
|
94
|
+
default:
|
|
95
|
+
return assertNever(condition)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { assembleSystemPrompt } from '../persona/assembler.js'
|
|
2
|
+
import type { AdvisorDefinition } from '../types/advisory/config.js'
|
|
3
|
+
import type { AdvisoryRequest, AdvisoryResult } from '../types/advisory/result.js'
|
|
4
|
+
import type { CostInfo, TokenUsage } from '../types/common/index.js'
|
|
5
|
+
import type { Message } from '../types/message/index.js'
|
|
6
|
+
import { createSystemMessage, createUserMessage } from '../types/message/index.js'
|
|
7
|
+
import type { LLMToolSchema } from '../types/tool/index.js'
|
|
8
|
+
import type { Logger } from '../utils/logger.js'
|
|
9
|
+
import { getRootLogger } from '../utils/logger.js'
|
|
10
|
+
|
|
11
|
+
export interface AdvisoryCallContext {
|
|
12
|
+
readonly messages: Message[]
|
|
13
|
+
readonly workingStateSummary?: string
|
|
14
|
+
readonly toolCatalog?: LLMToolSchema[]
|
|
15
|
+
readonly iteration: number
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface AdvisoryExecutionResult {
|
|
19
|
+
readonly result: AdvisoryResult
|
|
20
|
+
readonly usage: TokenUsage
|
|
21
|
+
readonly cost: CostInfo
|
|
22
|
+
readonly durationMs: number
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class AdvisoryExecutor {
|
|
26
|
+
private readonly logger: Logger
|
|
27
|
+
|
|
28
|
+
constructor(logger?: Logger) {
|
|
29
|
+
this.logger = (logger ?? getRootLogger()).child({ component: 'AdvisoryExecutor' })
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async consult(
|
|
33
|
+
advisor: AdvisorDefinition,
|
|
34
|
+
request: AdvisoryRequest,
|
|
35
|
+
callCtx: AdvisoryCallContext,
|
|
36
|
+
): Promise<AdvisoryExecutionResult> {
|
|
37
|
+
const startMs = Date.now()
|
|
38
|
+
|
|
39
|
+
const systemPrompt = this.buildSystemPrompt(advisor)
|
|
40
|
+
const contextMessages = this.buildContext(advisor, request, callCtx)
|
|
41
|
+
|
|
42
|
+
const messages: Message[] = [
|
|
43
|
+
createSystemMessage(systemPrompt),
|
|
44
|
+
...contextMessages,
|
|
45
|
+
createUserMessage(request.question),
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
this.logger.debug('advisory call starting', {
|
|
49
|
+
advisorId: advisor.id,
|
|
50
|
+
model: advisor.model,
|
|
51
|
+
messageCount: messages.length,
|
|
52
|
+
urgency: request.urgency,
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
const response = await advisor.provider.chat({
|
|
56
|
+
model: advisor.model,
|
|
57
|
+
messages,
|
|
58
|
+
temperature: advisor.temperature,
|
|
59
|
+
maxTokens: advisor.maxResponseTokens,
|
|
60
|
+
toolChoice: 'none',
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
const durationMs = Date.now() - startMs
|
|
64
|
+
|
|
65
|
+
const result = this.parseResult(response.message.content ?? '')
|
|
66
|
+
|
|
67
|
+
const cost = this.computeCost(response.usage)
|
|
68
|
+
|
|
69
|
+
this.logger.info('advisory call completed', {
|
|
70
|
+
advisorId: advisor.id,
|
|
71
|
+
model: advisor.model,
|
|
72
|
+
durationMs,
|
|
73
|
+
totalTokens: response.usage.totalTokens,
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
result,
|
|
78
|
+
usage: response.usage,
|
|
79
|
+
cost,
|
|
80
|
+
durationMs,
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
private buildSystemPrompt(advisor: AdvisorDefinition): string {
|
|
85
|
+
if (advisor.systemPrompt) {
|
|
86
|
+
return advisor.systemPrompt
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (advisor.persona) {
|
|
90
|
+
return assembleSystemPrompt(advisor.persona)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return [
|
|
94
|
+
`You are ${advisor.name}, an advisory agent.`,
|
|
95
|
+
advisor.domains && advisor.domains.length > 0
|
|
96
|
+
? `Your domains of expertise: ${advisor.domains.join(', ')}.`
|
|
97
|
+
: undefined,
|
|
98
|
+
'Provide concise, actionable advice. Focus on what the agent should do next.',
|
|
99
|
+
]
|
|
100
|
+
.filter(Boolean)
|
|
101
|
+
.join('\n\n')
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private buildContext(
|
|
105
|
+
advisor: AdvisorDefinition,
|
|
106
|
+
request: AdvisoryRequest,
|
|
107
|
+
callCtx: AdvisoryCallContext,
|
|
108
|
+
): Message[] {
|
|
109
|
+
if (request.includeContext === false) {
|
|
110
|
+
return []
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const contextParts: string[] = []
|
|
114
|
+
|
|
115
|
+
if (callCtx.workingStateSummary) {
|
|
116
|
+
contextParts.push(`## Working State\n${callCtx.workingStateSummary}`)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (callCtx.toolCatalog && callCtx.toolCatalog.length > 0) {
|
|
120
|
+
const toolNames = callCtx.toolCatalog.map((t) => t.function.name)
|
|
121
|
+
contextParts.push(`## Available Tools\n${toolNames.join(', ')}`)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const messagesToInclude = this.truncateMessages(callCtx.messages, advisor.maxContextTokens)
|
|
125
|
+
|
|
126
|
+
if (messagesToInclude.length > 0) {
|
|
127
|
+
const conversationSummary = messagesToInclude
|
|
128
|
+
.map((m) => `[${m.role}]: ${m.content ?? '(tool calls)'}`)
|
|
129
|
+
.join('\n')
|
|
130
|
+
contextParts.push(`## Conversation Context\n${conversationSummary}`)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (contextParts.length === 0) {
|
|
134
|
+
return []
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return [createUserMessage(contextParts.join('\n\n'))]
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private truncateMessages(messages: Message[], maxTokens: number | undefined): Message[] {
|
|
141
|
+
if (!maxTokens) {
|
|
142
|
+
return messages
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Rough heuristic: 1 token ~= 4 characters
|
|
146
|
+
const charBudget = maxTokens * 4
|
|
147
|
+
let totalChars = 0
|
|
148
|
+
const result: Message[] = []
|
|
149
|
+
|
|
150
|
+
// Walk from most recent to oldest, accumulate until budget exhausted
|
|
151
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
152
|
+
const msg = messages[i] as Message
|
|
153
|
+
const msgChars = (msg.content ?? '').length
|
|
154
|
+
if (totalChars + msgChars > charBudget) break
|
|
155
|
+
totalChars += msgChars
|
|
156
|
+
result.unshift(msg)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return result
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Parses the raw LLM response into an AdvisoryResult.
|
|
164
|
+
*
|
|
165
|
+
* Phase 1: text-only extraction. Structured parsing comes later.
|
|
166
|
+
*/
|
|
167
|
+
private parseResult(rawContent: string): AdvisoryResult {
|
|
168
|
+
return {
|
|
169
|
+
advice: rawContent,
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Computes cost from token usage.
|
|
175
|
+
*
|
|
176
|
+
* Returns zero-value cost since pricing is provider-specific.
|
|
177
|
+
* Callers with pricing data can recompute via calculateCost().
|
|
178
|
+
*/
|
|
179
|
+
private computeCost(_usage: TokenUsage): CostInfo {
|
|
180
|
+
return {
|
|
181
|
+
inputCostPer1M: 0,
|
|
182
|
+
outputCostPer1M: 0,
|
|
183
|
+
totalCost: 0,
|
|
184
|
+
cacheDiscount: 0,
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { AdvisorRegistry } from './registry.js'
|
|
2
|
+
export { AdvisoryExecutor } from './executor.js'
|
|
3
|
+
export type { AdvisoryCallContext, AdvisoryExecutionResult } from './executor.js'
|
|
4
|
+
export { TriggerEvaluator } from './evaluator.js'
|
|
5
|
+
export { AdvisoryContext } from './context.js'
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Registry } from '../registry/Registry.js'
|
|
2
|
+
import type { AdvisorDefinition } from '../types/advisory/index.js'
|
|
3
|
+
|
|
4
|
+
export class AdvisorRegistry extends Registry<AdvisorDefinition> {
|
|
5
|
+
private readonly defaultId: string | undefined
|
|
6
|
+
|
|
7
|
+
constructor(advisors: AdvisorDefinition[], defaultId?: string) {
|
|
8
|
+
super()
|
|
9
|
+
for (const advisor of advisors) {
|
|
10
|
+
this.register(advisor.id, advisor)
|
|
11
|
+
}
|
|
12
|
+
this.defaultId = defaultId
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Resolves the advisor for a given request.
|
|
17
|
+
*
|
|
18
|
+
* Priority: explicit ID > domain match > default > first registered.
|
|
19
|
+
*/
|
|
20
|
+
resolve(advisorId?: string, domain?: string): AdvisorDefinition | undefined {
|
|
21
|
+
if (advisorId) {
|
|
22
|
+
return this.get(advisorId)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (domain) {
|
|
26
|
+
const all = this.getAll()
|
|
27
|
+
const match = all.find((a) => a.domains?.some((d) => d === domain))
|
|
28
|
+
if (match) return match
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (this.defaultId) {
|
|
32
|
+
return this.get(this.defaultId)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const all = this.getAll()
|
|
36
|
+
return all.length > 0 ? all[0] : undefined
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
listAll(): AdvisorDefinition[] {
|
|
40
|
+
return this.getAll()
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -49,6 +49,17 @@ export class SupervisorAgent extends AbstractAgent<SupervisorAgentConfig, Superv
|
|
|
49
49
|
if (config.gateway) {
|
|
50
50
|
gateway = config.gateway
|
|
51
51
|
} else if (config.agentManager) {
|
|
52
|
+
const mergedFactoryOptions = config.factoryOptions
|
|
53
|
+
? {
|
|
54
|
+
...config.factoryOptions,
|
|
55
|
+
taskRouter: config.taskRouter ?? config.factoryOptions.taskRouter,
|
|
56
|
+
}
|
|
57
|
+
: config.taskRouter
|
|
58
|
+
? ({
|
|
59
|
+
taskRouter: config.taskRouter,
|
|
60
|
+
} as import('../types/agent/index.js').AgentFactoryOptions)
|
|
61
|
+
: undefined
|
|
62
|
+
|
|
52
63
|
const taskContext: AgentTaskContext = {
|
|
53
64
|
parentRunId: runId,
|
|
54
65
|
parentAgentId: this.metadata.id,
|
|
@@ -58,7 +69,7 @@ export class SupervisorAgent extends AbstractAgent<SupervisorAgentConfig, Superv
|
|
|
58
69
|
total: config.tokenBudget,
|
|
59
70
|
remaining: config.tokenBudget,
|
|
60
71
|
},
|
|
61
|
-
factoryOptions:
|
|
72
|
+
factoryOptions: mergedFactoryOptions,
|
|
62
73
|
threadId: config.threadId as ThreadId,
|
|
63
74
|
}
|
|
64
75
|
gateway = new LocalTaskGateway(config.agentManager, taskContext, listener, input)
|