@exellix/graph-composer 2.0.0
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/.env.example +66 -0
- package/LICENSE +21 -0
- package/README.md +329 -0
- package/dist/aiTaskProfile.d.ts +66 -0
- package/dist/aiTaskProfile.d.ts.map +1 -0
- package/dist/aiTaskProfile.js +179 -0
- package/dist/canonicalGraphDocument.d.ts +8 -0
- package/dist/canonicalGraphDocument.d.ts.map +1 -0
- package/dist/canonicalGraphDocument.js +344 -0
- package/dist/canonicalGraphWarnings.d.ts +6 -0
- package/dist/canonicalGraphWarnings.d.ts.map +1 -0
- package/dist/canonicalGraphWarnings.js +140 -0
- package/dist/catalogMatchAssist.d.ts +20 -0
- package/dist/catalogMatchAssist.d.ts.map +1 -0
- package/dist/catalogMatchAssist.js +203 -0
- package/dist/cataloxCatalogBridge.d.ts +103 -0
- package/dist/cataloxCatalogBridge.d.ts.map +1 -0
- package/dist/cataloxCatalogBridge.js +222 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +43 -0
- package/dist/composeInstructions.d.ts +11 -0
- package/dist/composeInstructions.d.ts.map +1 -0
- package/dist/composeInstructions.js +39 -0
- package/dist/defaultUtilitySkills.d.ts +4 -0
- package/dist/defaultUtilitySkills.d.ts.map +1 -0
- package/dist/defaultUtilitySkills.js +5 -0
- package/dist/exampleGeneration.d.ts +15 -0
- package/dist/exampleGeneration.d.ts.map +1 -0
- package/dist/exampleGeneration.js +72 -0
- package/dist/exampleInputs.d.ts +12 -0
- package/dist/exampleInputs.d.ts.map +1 -0
- package/dist/exampleInputs.js +181 -0
- package/dist/graphComposerActions.d.ts +22 -0
- package/dist/graphComposerActions.d.ts.map +1 -0
- package/dist/graphComposerActions.js +168 -0
- package/dist/graphComposerAgent.d.ts +26 -0
- package/dist/graphComposerAgent.d.ts.map +1 -0
- package/dist/graphComposerAgent.js +175 -0
- package/dist/graphComposerOutputValidation.d.ts +23 -0
- package/dist/graphComposerOutputValidation.d.ts.map +1 -0
- package/dist/graphComposerOutputValidation.js +709 -0
- package/dist/graphConceptPatchMerge.d.ts +10 -0
- package/dist/graphConceptPatchMerge.d.ts.map +1 -0
- package/dist/graphConceptPatchMerge.js +40 -0
- package/dist/graphEngineBridge.d.ts +7 -0
- package/dist/graphEngineBridge.d.ts.map +1 -0
- package/dist/graphEngineBridge.js +5 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/openRouterConnectTimeout.d.ts +3 -0
- package/dist/openRouterConnectTimeout.d.ts.map +1 -0
- package/dist/openRouterConnectTimeout.js +48 -0
- package/dist/packDir.d.ts +7 -0
- package/dist/packDir.d.ts.map +1 -0
- package/dist/packDir.js +23 -0
- package/dist/parseGraphConceptStory.d.ts +21 -0
- package/dist/parseGraphConceptStory.d.ts.map +1 -0
- package/dist/parseGraphConceptStory.js +105 -0
- package/dist/redactForLog.d.ts +2 -0
- package/dist/redactForLog.d.ts.map +1 -0
- package/dist/redactForLog.js +37 -0
- package/dist/runGraphComposer.d.ts +54 -0
- package/dist/runGraphComposer.d.ts.map +1 -0
- package/dist/runGraphComposer.js +444 -0
- package/dist/scopingCatalogHostTypes.d.ts +28 -0
- package/dist/scopingCatalogHostTypes.d.ts.map +1 -0
- package/dist/scopingCatalogHostTypes.js +6 -0
- package/dist/scopingNeedMatchAssist.d.ts +14 -0
- package/dist/scopingNeedMatchAssist.d.ts.map +1 -0
- package/dist/scopingNeedMatchAssist.js +58 -0
- package/dist/taskNodeTaskVariable.d.ts +44 -0
- package/dist/taskNodeTaskVariable.d.ts.map +1 -0
- package/dist/taskNodeTaskVariable.js +347 -0
- package/dist/types.d.ts +174 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/examples/network-vuln-subnet-triage.v2.json +389 -0
- package/functions/graph-composer/meta.json +607 -0
- package/functions/graph-composer/prompts/README.md +46 -0
- package/functions/graph-composer/prompts/action-create.md +51 -0
- package/functions/graph-composer/prompts/action-explain.md +26 -0
- package/functions/graph-composer/prompts/action-modify.md +32 -0
- package/functions/graph-composer/prompts/action-review-concept.md +97 -0
- package/functions/graph-composer/prompts/action-suggest-catalog-creations.md +31 -0
- package/functions/graph-composer/prompts/action-suggest-catalog-resolution.md +42 -0
- package/functions/graph-composer/prompts/action-suggest-concept-objective.md +38 -0
- package/functions/graph-composer/prompts/action-suggest-scoping-map-creation.md +31 -0
- package/functions/graph-composer/prompts/action-suggest-scoping-need-match.md +25 -0
- package/functions/graph-composer/prompts/default-utility-skills.json +22 -0
- package/functions/graph-composer/prompts/judge-rules.md +30 -0
- package/functions/graph-composer/prompts/orchestrator-system.md +21 -0
- package/functions/graph-composer/prompts/shared/graph-format.md +124 -0
- package/functions/graph-composer/prompts/shared/request-context.md +12 -0
- package/functions/graph-composer/prompts/shared/skill-selection.md +6 -0
- package/functions/graph-composer/prompts/shared/structural-validation.md +19 -0
- package/functions/graph-composer/prompts/skill-catalog-ai-header.md +3 -0
- package/functions/graph-composer/prompts/skill-catalog-utility-header.md +3 -0
- package/functions/graph-composer/prompts/skill-mode-extensible.md +7 -0
- package/functions/graph-composer/prompts/skill-mode-locked.md +7 -0
- package/functions/graph-composer/test-cases.json +52 -0
- package/package.json +86 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { runJsonCompletion, isAiJsonError, } from "@x12i/funcx/functions";
|
|
2
|
+
import { GRAPH_COMPOSER_ACTION_REGISTRY, getActionDefinitionByToolName, } from "./graphComposerActions.js";
|
|
3
|
+
import { DEFAULT_UTILITY_SKILLS } from "./defaultUtilitySkills.js";
|
|
4
|
+
import { readGraphComposerPromptFile } from "./packDir.js";
|
|
5
|
+
import { runGraphWorker, getGraphComposerLlmClient, } from "./runGraphComposer.js";
|
|
6
|
+
const PATCH_KEY_ENUM = [
|
|
7
|
+
"primaryIntentType",
|
|
8
|
+
"primaryIntentStatement",
|
|
9
|
+
"businessObjective",
|
|
10
|
+
"primaryOutcome",
|
|
11
|
+
];
|
|
12
|
+
function orchestratorStepSchema() {
|
|
13
|
+
const toolEnum = GRAPH_COMPOSER_ACTION_REGISTRY.map((d) => d.toolName);
|
|
14
|
+
return {
|
|
15
|
+
oneOf: [
|
|
16
|
+
{
|
|
17
|
+
type: "object",
|
|
18
|
+
required: ["kind", "summary"],
|
|
19
|
+
additionalProperties: false,
|
|
20
|
+
properties: {
|
|
21
|
+
kind: { const: "finish" },
|
|
22
|
+
summary: { type: "string", minLength: 1 },
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
type: "object",
|
|
27
|
+
required: ["kind", "tool", "arguments"],
|
|
28
|
+
additionalProperties: false,
|
|
29
|
+
properties: {
|
|
30
|
+
kind: { const: "call_tool" },
|
|
31
|
+
tool: { type: "string", enum: [...toolEnum] },
|
|
32
|
+
arguments: {
|
|
33
|
+
type: "object",
|
|
34
|
+
required: ["intentDescription"],
|
|
35
|
+
additionalProperties: false,
|
|
36
|
+
properties: {
|
|
37
|
+
intentDescription: { type: "string", minLength: 1 },
|
|
38
|
+
focusNodeIds: {
|
|
39
|
+
type: "array",
|
|
40
|
+
items: { type: "string" },
|
|
41
|
+
},
|
|
42
|
+
onlyIfEmpty: {
|
|
43
|
+
type: "array",
|
|
44
|
+
items: { type: "string", enum: [...PATCH_KEY_ENUM] },
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function toolCatalogText() {
|
|
54
|
+
return GRAPH_COMPOSER_ACTION_REGISTRY.map((d) => `- \`${d.toolName}\` → worker action \`${d.action}\`: ${d.toolDescription}`).join("\n");
|
|
55
|
+
}
|
|
56
|
+
function buildWorkerInput(action, args, ctx) {
|
|
57
|
+
const intent = {
|
|
58
|
+
action,
|
|
59
|
+
description: args.intentDescription,
|
|
60
|
+
};
|
|
61
|
+
if (args.focusNodeIds?.length) {
|
|
62
|
+
intent.focusNodeIds = [...args.focusNodeIds];
|
|
63
|
+
}
|
|
64
|
+
if (action === "suggestConceptObjective" && args.onlyIfEmpty?.length) {
|
|
65
|
+
intent.onlyIfEmpty = [...args.onlyIfEmpty];
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
intent,
|
|
69
|
+
existingGraph: ctx.existingGraph,
|
|
70
|
+
analysisContext: ctx.analysisContext,
|
|
71
|
+
skillMode: ctx.skillMode,
|
|
72
|
+
aiSkills: ctx.aiSkills,
|
|
73
|
+
utilitySkills: ctx.utilitySkills,
|
|
74
|
+
constraints: ctx.constraints,
|
|
75
|
+
catalogCandidates: ctx.catalogCandidates,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function normalizeAgentInput(input) {
|
|
79
|
+
const skillMode = input.skillMode ?? "locked";
|
|
80
|
+
const aiSkills = input.aiSkills ?? [];
|
|
81
|
+
const utilitySkills = input.utilitySkills === undefined
|
|
82
|
+
? [...DEFAULT_UTILITY_SKILLS]
|
|
83
|
+
: input.utilitySkills;
|
|
84
|
+
return {
|
|
85
|
+
...input,
|
|
86
|
+
skillMode,
|
|
87
|
+
aiSkills,
|
|
88
|
+
utilitySkills,
|
|
89
|
+
catalogCandidates: input.catalogCandidates,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Orchestrator: chooses registered graph workers via structured JSON steps (`runJsonCompletion`),
|
|
94
|
+
* then runs each selection with `runGraphWorker` (same prompts as direct `runGraphComposer`).
|
|
95
|
+
*/
|
|
96
|
+
export async function runGraphComposerAgent(input, options = {}) {
|
|
97
|
+
const client = getGraphComposerLlmClient(options);
|
|
98
|
+
const normalized = normalizeAgentInput(input);
|
|
99
|
+
const maxSteps = options.maxOrchestratorSteps ?? 8;
|
|
100
|
+
const system = readGraphComposerPromptFile("orchestrator-system.md");
|
|
101
|
+
const schema = orchestratorStepSchema();
|
|
102
|
+
const ctxPayload = {
|
|
103
|
+
existingGraph: normalized.existingGraph,
|
|
104
|
+
analysisContext: normalized.analysisContext,
|
|
105
|
+
skillMode: normalized.skillMode,
|
|
106
|
+
aiSkills: normalized.aiSkills,
|
|
107
|
+
utilitySkills: normalized.utilitySkills,
|
|
108
|
+
constraints: normalized.constraints,
|
|
109
|
+
catalogCandidates: normalized.catalogCandidates,
|
|
110
|
+
};
|
|
111
|
+
const steps = [];
|
|
112
|
+
let transcript = "";
|
|
113
|
+
let lastResult = null;
|
|
114
|
+
for (let i = 0; i < maxSteps; i++) {
|
|
115
|
+
const instruction = [
|
|
116
|
+
"## User goal",
|
|
117
|
+
normalized.goal.trim(),
|
|
118
|
+
"",
|
|
119
|
+
"## Context (JSON)",
|
|
120
|
+
JSON.stringify(ctxPayload),
|
|
121
|
+
"",
|
|
122
|
+
"## Registered tools",
|
|
123
|
+
toolCatalogText(),
|
|
124
|
+
"",
|
|
125
|
+
"## Response schema",
|
|
126
|
+
"Return a single JSON object matching exactly one branch of:",
|
|
127
|
+
'- `{ "kind": "finish", "summary": "<what was achieved or why you stop>" }`',
|
|
128
|
+
'- `{ "kind": "call_tool", "tool": "<tool name>", "arguments": { "intentDescription": "...", "focusNodeIds"?: string[], "onlyIfEmpty"?: string[] } }`',
|
|
129
|
+
"",
|
|
130
|
+
"## Prior tool results",
|
|
131
|
+
transcript.trim() ? transcript : "(none yet)",
|
|
132
|
+
].join("\n");
|
|
133
|
+
const r = await runJsonCompletion({
|
|
134
|
+
instruction,
|
|
135
|
+
options: {
|
|
136
|
+
system,
|
|
137
|
+
client,
|
|
138
|
+
schema,
|
|
139
|
+
model: options.model,
|
|
140
|
+
temperature: options.temperature ?? 0.2,
|
|
141
|
+
maxTokens: options.maxTokens ?? 2048,
|
|
142
|
+
timeoutMs: options.askTimeoutMs,
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
if (isAiJsonError(r)) {
|
|
146
|
+
throw new Error(`Orchestrator step failed: ${r.message} (after ${i} step(s))`);
|
|
147
|
+
}
|
|
148
|
+
const step = r.parsed;
|
|
149
|
+
if (!step || typeof step !== "object") {
|
|
150
|
+
throw new Error("Orchestrator returned empty parsed step");
|
|
151
|
+
}
|
|
152
|
+
if (step.kind === "finish") {
|
|
153
|
+
return {
|
|
154
|
+
orchestration: { summary: step.summary, steps },
|
|
155
|
+
result: lastResult,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
const def = getActionDefinitionByToolName(step.tool);
|
|
159
|
+
if (!def) {
|
|
160
|
+
throw new Error(`Unknown tool "${step.tool}"`);
|
|
161
|
+
}
|
|
162
|
+
const workerInput = buildWorkerInput(def.action, step.arguments, ctxPayload);
|
|
163
|
+
lastResult = await runGraphWorker(workerInput, options);
|
|
164
|
+
steps.push({
|
|
165
|
+
kind: "call_tool",
|
|
166
|
+
tool: step.tool,
|
|
167
|
+
action: def.action,
|
|
168
|
+
});
|
|
169
|
+
const preview = typeof lastResult === "object" && lastResult !== null
|
|
170
|
+
? JSON.stringify(lastResult)
|
|
171
|
+
: String(lastResult);
|
|
172
|
+
transcript += `\n---\nTool ${step.tool} (${def.action}) returned:\n${preview.slice(0, 12_000)}${preview.length > 12_000 ? "\n…(truncated)" : ""}\n`;
|
|
173
|
+
}
|
|
174
|
+
throw new Error(`runGraphComposerAgent exceeded maxOrchestratorSteps (${maxSteps})`);
|
|
175
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { GraphComposerInput } from "./types.js";
|
|
2
|
+
/** Passed to output validators when the worker request is available (e.g. `utilitySkills` for protocol checks). */
|
|
3
|
+
export type OutputValidationContext = {
|
|
4
|
+
input?: GraphComposerInput;
|
|
5
|
+
};
|
|
6
|
+
export type OutputValidator = (out: Record<string, unknown>, ctx?: OutputValidationContext) => void;
|
|
7
|
+
export declare function validateExplainOutput(out: Record<string, unknown>, _ctx?: OutputValidationContext): void;
|
|
8
|
+
export declare function validateReviewConceptOutput(out: Record<string, unknown>, _ctx?: OutputValidationContext): void;
|
|
9
|
+
/**
|
|
10
|
+
* When `existingGraph.metadata.graphConcept.coreTasks` has length N > 0, any
|
|
11
|
+
* `graphConceptPatch` / `suggestedConceptPatch` must include `coreTasks` with
|
|
12
|
+
* the same length (index-aligned). Call after `validateReviewConceptOutput`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function validateReviewConceptOutputAgainstInput(out: Record<string, unknown>, input: {
|
|
15
|
+
existingGraph?: unknown;
|
|
16
|
+
}): void;
|
|
17
|
+
export declare function validateSuggestConceptOutput(out: Record<string, unknown>, _ctx?: OutputValidationContext): void;
|
|
18
|
+
export declare function validateCreateModifyOutput(out: Record<string, unknown>, ctx?: OutputValidationContext): void;
|
|
19
|
+
export declare function validateSuggestCatalogResolutionOutput(out: Record<string, unknown>, _ctx?: OutputValidationContext): void;
|
|
20
|
+
export declare function validateSuggestCatalogCreationsOutput(out: Record<string, unknown>, _ctx?: OutputValidationContext): void;
|
|
21
|
+
export declare function validateSuggestScopingNeedMatchOutput(out: Record<string, unknown>, _ctx?: OutputValidationContext): void;
|
|
22
|
+
export declare function validateSuggestScopingMapCreationOutput(out: Record<string, unknown>, _ctx?: OutputValidationContext): void;
|
|
23
|
+
//# sourceMappingURL=graphComposerOutputValidation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphComposerOutputValidation.d.ts","sourceRoot":"","sources":["../src/graphComposerOutputValidation.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,kBAAkB,EAAwB,MAAM,YAAY,CAAC;AAE3E,mHAAmH;AACnH,MAAM,MAAM,uBAAuB,GAAG;IACpC,KAAK,CAAC,EAAE,kBAAkB,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,CAC5B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,GAAG,CAAC,EAAE,uBAAuB,KAC1B,IAAI,CAAC;AAuBV,wBAAgB,qBAAqB,CACnC,GAAG,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