agentic-flow 3.4.3 → 3.5.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/.agents/skills/agentic-flow-ecosystem/SKILL.md +6 -1
- package/.claude/skills/agentic-flow-ecosystem/skill.md +7 -1
- package/CHANGELOG.md +17 -0
- package/README.md +36 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/integrations/index.d.ts +2 -0
- package/dist/integrations/index.d.ts.map +1 -1
- package/dist/integrations/index.js +1 -0
- package/dist/integrations/index.js.map +1 -1
- package/dist/integrations/task-schedule.d.ts +51 -0
- package/dist/integrations/task-schedule.d.ts.map +1 -0
- package/dist/integrations/task-schedule.js +222 -0
- package/dist/integrations/task-schedule.js.map +1 -0
- package/dist/mcp/mcp-policy.js +1 -1
- package/dist/mcp/mcp-policy.js.map +1 -1
- package/dist/mcp/tools/ecosystem-tools.d.ts +5 -1
- package/dist/mcp/tools/ecosystem-tools.d.ts.map +1 -1
- package/dist/mcp/tools/ecosystem-tools.js +30 -1
- package/dist/mcp/tools/ecosystem-tools.js.map +1 -1
- package/dist/transport/index.d.ts +1 -1
- package/dist/transport/index.d.ts.map +1 -1
- package/dist/transport/index.js +1 -1
- package/dist/transport/index.js.map +1 -1
- package/dist/transport/quic-loader.d.ts +31 -10
- package/dist/transport/quic-loader.d.ts.map +1 -1
- package/dist/transport/quic-loader.js +35 -39
- package/dist/transport/quic-loader.js.map +1 -1
- package/dist/transport/quic.d.ts +1 -0
- package/dist/transport/quic.d.ts.map +1 -1
- package/dist/transport/quic.js +10 -1
- package/dist/transport/quic.js.map +1 -1
- package/docs/quic/QUIC-STATUS.md +20 -0
- package/package.json +16 -65
|
@@ -6,6 +6,8 @@ export { scanPromptInjection, promptInjectionEngine, getInjectionPolicy } from '
|
|
|
6
6
|
export type { InjectionScan, InjectionThreat, InjectionPolicy, InjectionSeverity } from './prompt-injection.js';
|
|
7
7
|
export { partitionTaskGraph } from './task-partition.js';
|
|
8
8
|
export type { TaskDependency, TaskPartition } from './task-partition.js';
|
|
9
|
+
export { scheduleTaskGraph } from './task-schedule.js';
|
|
10
|
+
export type { ScheduleTask, ScheduleDependency, TaskSchedule } from './task-schedule.js';
|
|
9
11
|
export { solveLinearSystem, pageRank, loadSublinearCore } from './sublinear.js';
|
|
10
12
|
export type { LinearSolveResult, PageRankResult, PageRankOptions, PageRankEdge, MatrixInput, SparseEntry, SolveMethod, SublinearEngine } from './sublinear.js';
|
|
11
13
|
export { applyAgentBoosterEdit, getAgentBoosterLibrary } from './agent-booster.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/integrations/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACvG,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAChH,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAChF,YAAY,EAAE,iBAAiB,EAAE,cAAc,EAAE,eAAe,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAC/J,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AACnF,YAAY,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC7H,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/integrations/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACvG,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAChH,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,YAAY,EAAE,YAAY,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACzF,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAChF,YAAY,EAAE,iBAAiB,EAAE,cAAc,EAAE,eAAe,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAC/J,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AACnF,YAAY,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC7H,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export { scanPromptInjection, promptInjectionEngine, getInjectionPolicy } from './prompt-injection.js';
|
|
6
6
|
export { partitionTaskGraph } from './task-partition.js';
|
|
7
|
+
export { scheduleTaskGraph } from './task-schedule.js';
|
|
7
8
|
export { solveLinearSystem, pageRank, loadSublinearCore } from './sublinear.js';
|
|
8
9
|
export { applyAgentBoosterEdit, getAgentBoosterLibrary } from './agent-booster.js';
|
|
9
10
|
export { OnnxWasmTextEmbedder, getOnnxWasmEmbedder, loadOnnxWasmModule, onnxWasmModelCached } from './onnx-wasm-embedder.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/integrations/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEvG,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEhF,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAEnF,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC7H,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC","sourcesContent":["/**\n * agentic-flow/integrations — programmatic access to the optional ruvnet\n * package integrations (each with a built-in fallback).\n */\n\nexport { scanPromptInjection, promptInjectionEngine, getInjectionPolicy } from './prompt-injection.js';\nexport type { InjectionScan, InjectionThreat, InjectionPolicy, InjectionSeverity } from './prompt-injection.js';\nexport { partitionTaskGraph } from './task-partition.js';\nexport type { TaskDependency, TaskPartition } from './task-partition.js';\nexport { solveLinearSystem, pageRank, loadSublinearCore } from './sublinear.js';\nexport type { LinearSolveResult, PageRankResult, PageRankOptions, PageRankEdge, MatrixInput, SparseEntry, SolveMethod, SublinearEngine } from './sublinear.js';\nexport { applyAgentBoosterEdit, getAgentBoosterLibrary } from './agent-booster.js';\nexport type { BoosterEditResult } from './agent-booster.js';\nexport { OnnxWasmTextEmbedder, getOnnxWasmEmbedder, loadOnnxWasmModule, onnxWasmModelCached } from './onnx-wasm-embedder.js';\nexport { isOptionalInstalled } from './optional.js';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/integrations/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEvG,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEhF,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAEnF,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC7H,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC","sourcesContent":["/**\n * agentic-flow/integrations — programmatic access to the optional ruvnet\n * package integrations (each with a built-in fallback).\n */\n\nexport { scanPromptInjection, promptInjectionEngine, getInjectionPolicy } from './prompt-injection.js';\nexport type { InjectionScan, InjectionThreat, InjectionPolicy, InjectionSeverity } from './prompt-injection.js';\nexport { partitionTaskGraph } from './task-partition.js';\nexport type { TaskDependency, TaskPartition } from './task-partition.js';\nexport { scheduleTaskGraph } from './task-schedule.js';\nexport type { ScheduleTask, ScheduleDependency, TaskSchedule } from './task-schedule.js';\nexport { solveLinearSystem, pageRank, loadSublinearCore } from './sublinear.js';\nexport type { LinearSolveResult, PageRankResult, PageRankOptions, PageRankEdge, MatrixInput, SparseEntry, SolveMethod, SublinearEngine } from './sublinear.js';\nexport { applyAgentBoosterEdit, getAgentBoosterLibrary } from './agent-booster.js';\nexport type { BoosterEditResult } from './agent-booster.js';\nexport { OnnxWasmTextEmbedder, getOnnxWasmEmbedder, loadOnnxWasmModule, onnxWasmModelCached } from './onnx-wasm-embedder.js';\nexport { isOptionalInstalled } from './optional.js';\n"]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schedule a task-dependency graph: what can run now, what runs in parallel,
|
|
3
|
+
* and which chain of tasks bounds the total time.
|
|
4
|
+
*
|
|
5
|
+
* Input is a DAG where `{ from, to }` means `from` must finish before `to`
|
|
6
|
+
* starts, and each task has a cost (estimated duration, tokens, dollars — any
|
|
7
|
+
* additive unit). Output:
|
|
8
|
+
* - `order`: a dependency-respecting execution order;
|
|
9
|
+
* - `waves`: tasks grouped by dependency depth (input order within a wave), so
|
|
10
|
+
* every task in a wave can be handed to a separate agent at the same time;
|
|
11
|
+
* - `criticalPath`: the most expensive dependency chain. Its cost is the
|
|
12
|
+
* makespan with unlimited agents, and speeding up anything off this path
|
|
13
|
+
* does not shorten the run.
|
|
14
|
+
*
|
|
15
|
+
* Engine: `@ruvector/rudag` (optionalDependency, Rust/WASM topological sort and
|
|
16
|
+
* critical path) when installed; a built-in Kahn sort + longest-path DP
|
|
17
|
+
* otherwise. Both reject cycles and agree on the critical-path cost.
|
|
18
|
+
*
|
|
19
|
+
* Complements `partitionTaskGraph` (task-partition.ts): partition answers
|
|
20
|
+
* "where to split work between two teams", scheduling answers "in what order,
|
|
21
|
+
* how parallel, and what is the bottleneck".
|
|
22
|
+
*/
|
|
23
|
+
export interface ScheduleTask {
|
|
24
|
+
id: string;
|
|
25
|
+
/** Additive cost of the task (time, tokens, ...). Default 1. Finite, >= 0. */
|
|
26
|
+
cost?: number;
|
|
27
|
+
}
|
|
28
|
+
export interface ScheduleDependency {
|
|
29
|
+
/** Must finish before `to` starts. */
|
|
30
|
+
from: string;
|
|
31
|
+
to: string;
|
|
32
|
+
}
|
|
33
|
+
export interface TaskSchedule {
|
|
34
|
+
order: string[];
|
|
35
|
+
waves: string[][];
|
|
36
|
+
criticalPath: {
|
|
37
|
+
tasks: string[];
|
|
38
|
+
cost: number;
|
|
39
|
+
};
|
|
40
|
+
/** Earliest start per task with unlimited parallel agents. */
|
|
41
|
+
earliestStart: Record<string, number>;
|
|
42
|
+
/** Sum of all task costs (the makespan with one agent). */
|
|
43
|
+
totalCost: number;
|
|
44
|
+
/** totalCost / criticalPath.cost: the speed-up ceiling from parallel agents. */
|
|
45
|
+
parallelism: number;
|
|
46
|
+
engine: 'rudag' | 'builtin';
|
|
47
|
+
}
|
|
48
|
+
export declare function scheduleTaskGraph(tasks: Array<string | ScheduleTask>, dependencies: ScheduleDependency[], options?: {
|
|
49
|
+
engine?: 'auto' | 'builtin';
|
|
50
|
+
}): Promise<TaskSchedule>;
|
|
51
|
+
//# sourceMappingURL=task-schedule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task-schedule.d.ts","sourceRoot":"","sources":["../../src/integrations/task-schedule.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAIH,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,8EAA8E;IAC9E,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,kBAAkB;IACjC,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC;IAClB,YAAY,EAAE;QAAE,KAAK,EAAE,MAAM,EAAE,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAChD,8DAA8D;IAC9D,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,2DAA2D;IAC3D,SAAS,EAAE,MAAM,CAAC;IAClB,gFAAgF;IAChF,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,OAAO,GAAG,SAAS,CAAC;CAC7B;AA8HD,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,KAAK,CAAC,MAAM,GAAG,YAAY,CAAC,EACnC,YAAY,EAAE,kBAAkB,EAAE,EAClC,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAO,GAC5C,OAAO,CAAC,YAAY,CAAC,CAyEvB"}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schedule a task-dependency graph: what can run now, what runs in parallel,
|
|
3
|
+
* and which chain of tasks bounds the total time.
|
|
4
|
+
*
|
|
5
|
+
* Input is a DAG where `{ from, to }` means `from` must finish before `to`
|
|
6
|
+
* starts, and each task has a cost (estimated duration, tokens, dollars — any
|
|
7
|
+
* additive unit). Output:
|
|
8
|
+
* - `order`: a dependency-respecting execution order;
|
|
9
|
+
* - `waves`: tasks grouped by dependency depth (input order within a wave), so
|
|
10
|
+
* every task in a wave can be handed to a separate agent at the same time;
|
|
11
|
+
* - `criticalPath`: the most expensive dependency chain. Its cost is the
|
|
12
|
+
* makespan with unlimited agents, and speeding up anything off this path
|
|
13
|
+
* does not shorten the run.
|
|
14
|
+
*
|
|
15
|
+
* Engine: `@ruvector/rudag` (optionalDependency, Rust/WASM topological sort and
|
|
16
|
+
* critical path) when installed; a built-in Kahn sort + longest-path DP
|
|
17
|
+
* otherwise. Both reject cycles and agree on the critical-path cost.
|
|
18
|
+
*
|
|
19
|
+
* Complements `partitionTaskGraph` (task-partition.ts): partition answers
|
|
20
|
+
* "where to split work between two teams", scheduling answers "in what order,
|
|
21
|
+
* how parallel, and what is the bottleneck".
|
|
22
|
+
*/
|
|
23
|
+
import { importOptional } from './optional.js';
|
|
24
|
+
/** rudag's WASM DAG takes integer operator codes; 255 is its user-defined slot. */
|
|
25
|
+
const RUDAG_CUSTOM_OPERATOR = 255;
|
|
26
|
+
function normalize(tasks, deps) {
|
|
27
|
+
const index = new Map();
|
|
28
|
+
const names = [];
|
|
29
|
+
const costs = [];
|
|
30
|
+
const add = (id, cost) => {
|
|
31
|
+
const key = String(id);
|
|
32
|
+
let i = index.get(key);
|
|
33
|
+
if (i === undefined) {
|
|
34
|
+
i = names.length;
|
|
35
|
+
index.set(key, i);
|
|
36
|
+
names.push(key);
|
|
37
|
+
costs.push(1);
|
|
38
|
+
}
|
|
39
|
+
if (cost !== undefined) {
|
|
40
|
+
if (!Number.isFinite(cost) || cost < 0)
|
|
41
|
+
throw new Error(`invalid cost ${cost} for task ${key}`);
|
|
42
|
+
costs[i] = cost;
|
|
43
|
+
}
|
|
44
|
+
return i;
|
|
45
|
+
};
|
|
46
|
+
for (const t of tasks) {
|
|
47
|
+
if (typeof t === 'string')
|
|
48
|
+
add(t);
|
|
49
|
+
else
|
|
50
|
+
add(t.id, t.cost);
|
|
51
|
+
}
|
|
52
|
+
const seen = new Set();
|
|
53
|
+
const edges = [];
|
|
54
|
+
for (const d of deps) {
|
|
55
|
+
const a = add(d.from);
|
|
56
|
+
const b = add(d.to);
|
|
57
|
+
if (a === b)
|
|
58
|
+
throw new Error(`dependency cycle: ${names[a]} -> ${names[a]}`);
|
|
59
|
+
const key = `${a},${b}`;
|
|
60
|
+
if (seen.has(key))
|
|
61
|
+
continue;
|
|
62
|
+
seen.add(key);
|
|
63
|
+
edges.push([a, b]);
|
|
64
|
+
}
|
|
65
|
+
return { names, costs, edges };
|
|
66
|
+
}
|
|
67
|
+
/** Find one cycle among `remaining` vertices (all of which lie on or lead into a cycle). */
|
|
68
|
+
function findCycle(n, edges, remaining) {
|
|
69
|
+
const out = Array.from({ length: n }, () => []);
|
|
70
|
+
for (const [a, b] of edges)
|
|
71
|
+
if (remaining.has(a) && remaining.has(b))
|
|
72
|
+
out[a].push(b);
|
|
73
|
+
const state = new Map();
|
|
74
|
+
const stack = [];
|
|
75
|
+
const visit = (v) => {
|
|
76
|
+
state.set(v, 1);
|
|
77
|
+
stack.push(v);
|
|
78
|
+
for (const w of out[v]) {
|
|
79
|
+
if (state.get(w) === 1)
|
|
80
|
+
return [...stack.slice(stack.indexOf(w)), w];
|
|
81
|
+
if (!state.has(w)) {
|
|
82
|
+
const c = visit(w);
|
|
83
|
+
if (c)
|
|
84
|
+
return c;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
stack.pop();
|
|
88
|
+
state.set(v, 2);
|
|
89
|
+
return null;
|
|
90
|
+
};
|
|
91
|
+
for (const v of remaining) {
|
|
92
|
+
if (!state.has(v)) {
|
|
93
|
+
const c = visit(v);
|
|
94
|
+
if (c)
|
|
95
|
+
return c;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return [];
|
|
99
|
+
}
|
|
100
|
+
function builtinOrder(n, edges) {
|
|
101
|
+
const indeg = new Array(n).fill(0);
|
|
102
|
+
const out = Array.from({ length: n }, () => []);
|
|
103
|
+
for (const [a, b] of edges) {
|
|
104
|
+
out[a].push(b);
|
|
105
|
+
indeg[b]++;
|
|
106
|
+
}
|
|
107
|
+
const queue = [];
|
|
108
|
+
for (let i = 0; i < n; i++)
|
|
109
|
+
if (indeg[i] === 0)
|
|
110
|
+
queue.push(i);
|
|
111
|
+
const order = [];
|
|
112
|
+
for (let h = 0; h < queue.length; h++) {
|
|
113
|
+
const v = queue[h];
|
|
114
|
+
order.push(v);
|
|
115
|
+
for (const w of out[v])
|
|
116
|
+
if (--indeg[w] === 0)
|
|
117
|
+
queue.push(w);
|
|
118
|
+
}
|
|
119
|
+
return order;
|
|
120
|
+
}
|
|
121
|
+
/** Longest (most expensive) path over a topological order; path cost counts node costs. */
|
|
122
|
+
function longestPath(order, costs, edges) {
|
|
123
|
+
const preds = costs.map(() => []);
|
|
124
|
+
for (const [a, b] of edges)
|
|
125
|
+
preds[b].push(a);
|
|
126
|
+
const finish = new Array(costs.length).fill(0);
|
|
127
|
+
const via = new Array(costs.length).fill(-1);
|
|
128
|
+
for (const v of order) {
|
|
129
|
+
let best = 0;
|
|
130
|
+
let bestU = -1;
|
|
131
|
+
for (const u of preds[v]) {
|
|
132
|
+
if (bestU === -1 || finish[u] > best) {
|
|
133
|
+
best = finish[u];
|
|
134
|
+
bestU = u;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
via[v] = bestU;
|
|
138
|
+
finish[v] = best + costs[v];
|
|
139
|
+
}
|
|
140
|
+
let end = -1;
|
|
141
|
+
for (const v of order)
|
|
142
|
+
if (end === -1 || finish[v] > finish[end])
|
|
143
|
+
end = v;
|
|
144
|
+
const path = [];
|
|
145
|
+
for (let v = end; v !== -1; v = via[v])
|
|
146
|
+
path.unshift(v);
|
|
147
|
+
return { path, cost: end === -1 ? 0 : finish[end] };
|
|
148
|
+
}
|
|
149
|
+
export async function scheduleTaskGraph(tasks, dependencies, options = {}) {
|
|
150
|
+
const { names, costs, edges } = normalize(tasks, dependencies);
|
|
151
|
+
const n = names.length;
|
|
152
|
+
let order = null;
|
|
153
|
+
let critical = null;
|
|
154
|
+
let engine = 'builtin';
|
|
155
|
+
if (n > 0 && options.engine !== 'builtin') {
|
|
156
|
+
const mod = await importOptional('@ruvector/rudag');
|
|
157
|
+
if (mod?.RuDag) {
|
|
158
|
+
// storage: null keeps rudag off IndexedDB/the filesystem; one instance per call.
|
|
159
|
+
const dag = await new mod.RuDag({ storage: null, autoSave: false }).init();
|
|
160
|
+
try {
|
|
161
|
+
const ids = costs.map((c) => dag.addNode(RUDAG_CUSTOM_OPERATOR, c));
|
|
162
|
+
let acyclic = true;
|
|
163
|
+
for (const [a, b] of edges) {
|
|
164
|
+
// rudag refuses an edge that would close a cycle.
|
|
165
|
+
if (!dag.addEdge(ids[a], ids[b])) {
|
|
166
|
+
acyclic = false;
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (acyclic) {
|
|
171
|
+
const back = new Map(ids.map((id, i) => [id, i]));
|
|
172
|
+
order = dag.topoSort().map((id) => back.get(id));
|
|
173
|
+
const cp = dag.criticalPath();
|
|
174
|
+
critical = { path: cp.path.map((id) => back.get(id)), cost: cp.cost };
|
|
175
|
+
engine = 'rudag';
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
finally {
|
|
179
|
+
dag.dispose();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (!order) {
|
|
184
|
+
order = builtinOrder(n, edges);
|
|
185
|
+
if (order.length < n) {
|
|
186
|
+
const placed = new Set(order);
|
|
187
|
+
const remaining = new Set(names.map((_, i) => i).filter((i) => !placed.has(i)));
|
|
188
|
+
const cycle = findCycle(n, edges, remaining);
|
|
189
|
+
throw new Error(`dependency cycle: ${cycle.map((i) => names[i]).join(' -> ')}`);
|
|
190
|
+
}
|
|
191
|
+
critical = longestPath(order, costs, edges);
|
|
192
|
+
engine = 'builtin';
|
|
193
|
+
}
|
|
194
|
+
// Earliest start and waves: the same for either engine, given a valid order.
|
|
195
|
+
const preds = names.map(() => []);
|
|
196
|
+
for (const [a, b] of edges)
|
|
197
|
+
preds[b].push(a);
|
|
198
|
+
const start = new Array(n).fill(0);
|
|
199
|
+
const level = new Array(n).fill(0);
|
|
200
|
+
for (const v of order) {
|
|
201
|
+
for (const u of preds[v]) {
|
|
202
|
+
start[v] = Math.max(start[v], start[u] + costs[u]);
|
|
203
|
+
level[v] = Math.max(level[v], level[u] + 1);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
// Within a wave, tasks keep their input order, so both engines return identical waves.
|
|
207
|
+
const waves = [];
|
|
208
|
+
for (let v = 0; v < n; v++)
|
|
209
|
+
(waves[level[v]] ??= []).push(names[v]);
|
|
210
|
+
const totalCost = costs.reduce((s, c) => s + c, 0);
|
|
211
|
+
const cpCost = critical.cost;
|
|
212
|
+
return {
|
|
213
|
+
order: order.map((i) => names[i]),
|
|
214
|
+
waves,
|
|
215
|
+
criticalPath: { tasks: critical.path.map((i) => names[i]), cost: cpCost },
|
|
216
|
+
earliestStart: Object.fromEntries(order.map((i) => [names[i], start[i]])),
|
|
217
|
+
totalCost,
|
|
218
|
+
parallelism: cpCost > 0 ? totalCost / cpCost : n > 0 ? n : 0,
|
|
219
|
+
engine,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
//# sourceMappingURL=task-schedule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task-schedule.js","sourceRoot":"","sources":["../../src/integrations/task-schedule.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AA2B/C,mFAAmF;AACnF,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAclC,SAAS,SAAS,CAAC,KAAmC,EAAE,IAA0B;IAChF,MAAM,KAAK,GAAG,IAAI,GAAG,EAAkB,CAAC;IACxC,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,MAAM,GAAG,GAAG,CAAC,EAAU,EAAE,IAAa,EAAE,EAAE;QACxC,MAAM,GAAG,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;QACvB,IAAI,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACvB,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC;YACpB,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC;YACjB,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;YAClB,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAChB,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAChB,CAAC;QACD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC;gBAAE,MAAM,IAAI,KAAK,CAAC,gBAAgB,IAAI,aAAa,GAAG,EAAE,CAAC,CAAC;YAChG,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CA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chain of tasks bounds the total time.\n *\n * Input is a DAG where `{ from, to }` means `from` must finish before `to`\n * starts, and each task has a cost (estimated duration, tokens, dollars — any\n * additive unit). Output:\n * - `order`: a dependency-respecting execution order;\n * - `waves`: tasks grouped by dependency depth (input order within a wave), so\n * every task in a wave can be handed to a separate agent at the same time;\n * - `criticalPath`: the most expensive dependency chain. Its cost is the\n * makespan with unlimited agents, and speeding up anything off this path\n * does not shorten the run.\n *\n * Engine: `@ruvector/rudag` (optionalDependency, Rust/WASM topological sort and\n * critical path) when installed; a built-in Kahn sort + longest-path DP\n * otherwise. Both reject cycles and agree on the critical-path cost.\n *\n * Complements `partitionTaskGraph` (task-partition.ts): partition answers\n * \"where to split work between two teams\", scheduling answers \"in what order,\n * how parallel, and what is the bottleneck\".\n */\n\nimport { importOptional } from './optional.js';\n\nexport interface ScheduleTask {\n id: string;\n /** Additive cost of the task (time, tokens, ...). Default 1. Finite, >= 0. */\n cost?: number;\n}\n\nexport interface ScheduleDependency {\n /** Must finish before `to` starts. */\n from: string;\n to: string;\n}\n\nexport interface TaskSchedule {\n order: string[];\n waves: string[][];\n criticalPath: { tasks: string[]; cost: number };\n /** Earliest start per task with unlimited parallel agents. */\n earliestStart: Record<string, number>;\n /** Sum of all task costs (the makespan with one agent). */\n totalCost: number;\n /** totalCost / criticalPath.cost: the speed-up ceiling from parallel agents. */\n parallelism: number;\n engine: 'rudag' | 'builtin';\n}\n\n/** rudag's WASM DAG takes integer operator codes; 255 is its user-defined slot. */\nconst RUDAG_CUSTOM_OPERATOR = 255;\n\ninterface RuDagInstance {\n init(): Promise<RuDagInstance>;\n addNode(operator: number, cost: number): number;\n addEdge(from: number, to: number): boolean;\n topoSort(): number[];\n criticalPath(): { path: number[]; cost: number };\n dispose(): void;\n}\ninterface RuDagModule {\n RuDag: new (options: { storage: null; autoSave: false }) => RuDagInstance;\n}\n\nfunction normalize(tasks: Array<string | ScheduleTask>, deps: ScheduleDependency[]) {\n const index = new Map<string, number>();\n const names: string[] = [];\n const costs: number[] = [];\n const add = (id: string, cost?: number) => {\n const key = String(id);\n let i = index.get(key);\n if (i === undefined) {\n i = names.length;\n index.set(key, i);\n names.push(key);\n costs.push(1);\n }\n if (cost !== undefined) {\n if (!Number.isFinite(cost) || cost < 0) throw new Error(`invalid cost ${cost} for task ${key}`);\n costs[i] = cost;\n }\n return i;\n };\n for (const t of tasks) {\n if (typeof t === 'string') add(t);\n else add(t.id, t.cost);\n }\n const seen = new Set<string>();\n const edges: Array<[number, number]> = [];\n for (const d of deps) {\n const a = add(d.from);\n const b = add(d.to);\n if (a === b) throw new Error(`dependency cycle: ${names[a]} -> ${names[a]}`);\n const key = `${a},${b}`;\n if (seen.has(key)) continue;\n seen.add(key);\n edges.push([a, b]);\n }\n return { names, costs, edges };\n}\n\n/** Find one cycle among `remaining` vertices (all of which lie on or lead into a cycle). */\nfunction findCycle(n: number, edges: Array<[number, number]>, remaining: Set<number>): number[] {\n const out: number[][] = Array.from({ length: n }, () => []);\n for (const [a, b] of edges) if (remaining.has(a) && remaining.has(b)) out[a].push(b);\n const state = new Map<number, 1 | 2>();\n const stack: number[] = [];\n const visit = (v: number): number[] | null => {\n state.set(v, 1);\n stack.push(v);\n for (const w of out[v]) {\n if (state.get(w) === 1) return [...stack.slice(stack.indexOf(w)), w];\n if (!state.has(w)) {\n const c = visit(w);\n if (c) return c;\n }\n }\n stack.pop();\n state.set(v, 2);\n return null;\n };\n for (const v of remaining) {\n if (!state.has(v)) {\n const c = visit(v);\n if (c) return c;\n }\n }\n return [];\n}\n\nfunction builtinOrder(n: number, edges: Array<[number, number]>): number[] {\n const indeg = new Array(n).fill(0);\n const out: number[][] = Array.from({ length: n }, () => []);\n for (const [a, b] of edges) {\n out[a].push(b);\n indeg[b]++;\n }\n const queue: number[] = [];\n for (let i = 0; i < n; i++) if (indeg[i] === 0) queue.push(i);\n const order: number[] = [];\n for (let h = 0; h < queue.length; h++) {\n const v = queue[h];\n order.push(v);\n for (const w of out[v]) if (--indeg[w] === 0) queue.push(w);\n }\n return order;\n}\n\n/** Longest (most expensive) path over a topological order; path cost counts node costs. */\nfunction longestPath(order: number[], costs: number[], edges: Array<[number, number]>) {\n const preds: number[][] = costs.map(() => []);\n for (const [a, b] of edges) preds[b].push(a);\n const finish = new Array(costs.length).fill(0);\n const via = new Array(costs.length).fill(-1);\n for (const v of order) {\n let best = 0;\n let bestU = -1;\n for (const u of preds[v]) {\n if (bestU === -1 || finish[u] > best) {\n best = finish[u];\n bestU = u;\n }\n }\n via[v] = bestU;\n finish[v] = best + costs[v];\n }\n let end = -1;\n for (const v of order) if (end === -1 || finish[v] > finish[end]) end = v;\n const path: number[] = [];\n for (let v = end; v !== -1; v = via[v]) path.unshift(v);\n return { path, cost: end === -1 ? 0 : finish[end] };\n}\n\nexport async function scheduleTaskGraph(\n tasks: Array<string | ScheduleTask>,\n dependencies: ScheduleDependency[],\n options: { engine?: 'auto' | 'builtin' } = {},\n): Promise<TaskSchedule> {\n const { names, costs, edges } = normalize(tasks, dependencies);\n const n = names.length;\n let order: number[] | null = null;\n let critical: { path: number[]; cost: number } | null = null;\n let engine: TaskSchedule['engine'] = 'builtin';\n\n if (n > 0 && options.engine !== 'builtin') {\n const mod = await importOptional<RuDagModule>('@ruvector/rudag');\n if (mod?.RuDag) {\n // storage: null keeps rudag off IndexedDB/the filesystem; one instance per call.\n const dag = await new mod.RuDag({ storage: null, autoSave: false }).init();\n try {\n const ids = costs.map((c) => dag.addNode(RUDAG_CUSTOM_OPERATOR, c));\n let acyclic = true;\n for (const [a, b] of edges) {\n // rudag refuses an edge that would close a cycle.\n if (!dag.addEdge(ids[a], ids[b])) {\n acyclic = false;\n break;\n }\n }\n if (acyclic) {\n const back = new Map(ids.map((id, i) => [id, i]));\n order = dag.topoSort().map((id) => back.get(id)!);\n const cp = dag.criticalPath();\n critical = { path: cp.path.map((id) => back.get(id)!), cost: cp.cost };\n engine = 'rudag';\n }\n } finally {\n dag.dispose();\n }\n }\n }\n\n if (!order) {\n order = builtinOrder(n, edges);\n if (order.length < n) {\n const placed = new Set(order);\n const remaining = new Set(names.map((_, i) => i).filter((i) => !placed.has(i)));\n const cycle = findCycle(n, edges, remaining);\n throw new Error(`dependency cycle: ${cycle.map((i) => names[i]).join(' -> ')}`);\n }\n critical = longestPath(order, costs, edges);\n engine = 'builtin';\n }\n\n // Earliest start and waves: the same for either engine, given a valid order.\n const preds: number[][] = names.map(() => []);\n for (const [a, b] of edges) preds[b].push(a);\n const start = new Array(n).fill(0);\n const level = new Array(n).fill(0);\n for (const v of order) {\n for (const u of preds[v]) {\n start[v] = Math.max(start[v], start[u] + costs[u]);\n level[v] = Math.max(level[v], level[u] + 1);\n }\n }\n // Within a wave, tasks keep their input order, so both engines return identical waves.\n const waves: string[][] = [];\n for (let v = 0; v < n; v++) (waves[level[v]] ??= []).push(names[v]);\n\n const totalCost = costs.reduce((s, c) => s + c, 0);\n const cpCost = critical!.cost;\n return {\n order: order.map((i) => names[i]),\n waves,\n criticalPath: { tasks: critical!.path.map((i) => names[i]), cost: cpCost },\n earliestStart: Object.fromEntries(order.map((i) => [names[i], start[i]])),\n totalCost,\n parallelism: cpCost > 0 ? totalCost / cpCost : n > 0 ? n : 0,\n engine,\n };\n}\n"]}
|
package/dist/mcp/mcp-policy.js
CHANGED
|
@@ -4,7 +4,7 @@ const READONLY = [
|
|
|
4
4
|
/^harness_(capabilities|manifest|verify)$/,
|
|
5
5
|
/_(stats|get_profile|list_profiles|benchmark)$/,
|
|
6
6
|
// Ecosystem tools: pure computations over their arguments, no side effects.
|
|
7
|
-
/^(ecosystem_status|swarm_partition_tasks|sublinear_solve|sublinear_pagerank|prompt_injection_scan)$/,
|
|
7
|
+
/^(ecosystem_status|swarm_partition_tasks|swarm_schedule_tasks|sublinear_solve|sublinear_pagerank|prompt_injection_scan)$/,
|
|
8
8
|
];
|
|
9
9
|
const RETRIEVAL = [...READONLY, /search$/, /context$/];
|
|
10
10
|
const LEARNING = [...RETRIEVAL, /^agentic_flow_agent$/, /^agentdb_pattern_store$/, /^sona_/];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-policy.js","sourceRoot":"","sources":["../../src/mcp/mcp-policy.ts"],"names":[],"mappings":"AAEA,MAAM,QAAQ,GAAG;IACf,0DAA0D;IAC1D,gDAAgD;IAChD,0CAA0C;IAC1C,+CAA+C;IAC/C,4EAA4E;IAC5E,
|
|
1
|
+
{"version":3,"file":"mcp-policy.js","sourceRoot":"","sources":["../../src/mcp/mcp-policy.ts"],"names":[],"mappings":"AAEA,MAAM,QAAQ,GAAG;IACf,0DAA0D;IAC1D,gDAAgD;IAChD,0CAA0C;IAC1C,+CAA+C;IAC/C,4EAA4E;IAC5E,0HAA0H;CAC3H,CAAC;AACF,MAAM,SAAS,GAAG,CAAC,GAAG,QAAQ,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;AACvD,MAAM,QAAQ,GAAG,CAAC,GAAG,SAAS,EAAE,sBAAsB,EAAE,yBAAyB,EAAE,QAAQ,CAAC,CAAC;AAE7F,MAAM,UAAU,eAAe,CAAC,KAAyB;IACvD,MAAM,OAAO,GAAG,KAAK,IAAI,UAAU,CAAC;IACpC,IAAI,CAAC,CAAC,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QACtE,MAAM,IAAI,KAAK,CAAC,wBAAwB,OAAO,EAAE,CAAC,CAAC;IACrD,CAAC;IACD,OAAO,OAAqB,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,gBAAgB,CAC9B,IAAY,EACZ,OAAgE;IAEhE,IAAI,IAAI,KAAK,gBAAgB,EAAE,CAAC;QAC9B,OAAO,OAAO,CAAC,OAAO,KAAK,OAAO,IAAI,OAAO,CAAC,oBAAoB,KAAK,IAAI,CAAC;IAC9E,CAAC;IACD,IAAI,OAAO,CAAC,OAAO,KAAK,OAAO;QAAE,OAAO,IAAI,CAAC;IAC7C,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;QACvD,OAAO,CAAC,OAAO,KAAK,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC;IACzD,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,gBAAgB,CAC9B,MAAS,EACT,OAAgE;IAEhE,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC5C,MAAM,CAAC,OAAO,GAAG,CAAC,CAAC,IAAsB,EAAE,EAAE;QAC3C,IAAI,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC;YAAE,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/D,OAAO,SAAS,CAAC;IACnB,CAAC,CAAiB,CAAC;IACnB,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["export type McpProfile = 'readonly' | 'retrieval' | 'learning' | 'admin';\n\nconst READONLY = [\n /^agentic_flow_(list|list_all|agent_info|check_conflicts)/,\n /^agentdb_(stats|pattern_search|pattern_stats)$/,\n /^harness_(capabilities|manifest|verify)$/,\n /_(stats|get_profile|list_profiles|benchmark)$/,\n // Ecosystem tools: pure computations over their arguments, no side effects.\n /^(ecosystem_status|swarm_partition_tasks|swarm_schedule_tasks|sublinear_solve|sublinear_pagerank|prompt_injection_scan)$/,\n];\nconst RETRIEVAL = [...READONLY, /search$/, /context$/];\nconst LEARNING = [...RETRIEVAL, /^agentic_flow_agent$/, /^agentdb_pattern_store$/, /^sona_/];\n\nexport function parseMcpProfile(value: string | undefined): McpProfile {\n const profile = value ?? 'readonly';\n if (!['readonly', 'retrieval', 'learning', 'admin'].includes(profile)) {\n throw new Error(`invalid MCP profile: ${profile}`);\n }\n return profile as McpProfile;\n}\n\nexport function isMcpToolAllowed(\n name: string,\n options: { profile: McpProfile; allowDarwinExecution?: boolean },\n): boolean {\n if (name === 'harness_repair') {\n return options.profile === 'admin' && options.allowDarwinExecution === true;\n }\n if (options.profile === 'admin') return true;\n const rules = options.profile === 'learning' ? LEARNING :\n options.profile === 'retrieval' ? RETRIEVAL : READONLY;\n return rules.some((rule) => rule.test(name));\n}\n\nexport function installMcpPolicy<T extends { addTool: (tool: { name: string }) => unknown }>(\n server: T,\n options: { profile: McpProfile; allowDarwinExecution?: boolean },\n): T {\n const addTool = server.addTool.bind(server);\n server.addTool = ((tool: { name: string }) => {\n if (isMcpToolAllowed(tool.name, options)) return addTool(tool);\n return undefined;\n }) as T['addTool'];\n return server;\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Ecosystem MCP tools: in-process access to the optional ruvnet packages
|
|
3
|
-
* agentic-flow integrates (aidefence, @ruvector/mincut-wasm,
|
|
3
|
+
* agentic-flow integrates (aidefence, @ruvector/mincut-wasm, @ruvector/rudag,
|
|
4
4
|
* @ruvnet/sublinear-core, agent-booster, @ruvector/router,
|
|
5
5
|
* ruvector-onnx-embeddings-wasm).
|
|
6
6
|
*
|
|
@@ -32,6 +32,10 @@ export declare const ECOSYSTEM_PACKAGES: readonly [{
|
|
|
32
32
|
readonly pkg: "@ruvector/mincut-wasm";
|
|
33
33
|
readonly probe: "@ruvector/mincut-wasm";
|
|
34
34
|
readonly powers: "task-graph partitioning (swarm_partition_tasks)";
|
|
35
|
+
}, {
|
|
36
|
+
readonly pkg: "@ruvector/rudag";
|
|
37
|
+
readonly probe: "@ruvector/rudag";
|
|
38
|
+
readonly powers: "task-graph scheduling: execution waves and critical path (swarm_schedule_tasks)";
|
|
35
39
|
}, {
|
|
36
40
|
readonly pkg: "@ruvnet/sublinear-core";
|
|
37
41
|
readonly probe: "@ruvnet/sublinear-core";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ecosystem-tools.d.ts","sourceRoot":"","sources":["../../../src/mcp/tools/ecosystem-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"ecosystem-tools.d.ts","sourceRoot":"","sources":["../../../src/mcp/tools/ecosystem-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,CAAC,CAAC,UAAU,CAAC;IACzB,OAAO,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CAC7C;AAED,oFAAoF;AACpF,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAQrB,CAAC;AAgFX,eAAO,MAAM,eAAe,EAAE,aAAa,EAmE1C,CAAC;AAEF,eAAO,MAAM,oBAAoB,UAAqC,CAAC;AAEvE,wBAAgB,sBAAsB,CAAC,MAAM,EAAE;IAAE,OAAO,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,IAAI,CAAA;CAAE,GAAG,IAAI,CAE/F"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Ecosystem MCP tools: in-process access to the optional ruvnet packages
|
|
3
|
-
* agentic-flow integrates (aidefence, @ruvector/mincut-wasm,
|
|
3
|
+
* agentic-flow integrates (aidefence, @ruvector/mincut-wasm, @ruvector/rudag,
|
|
4
4
|
* @ruvnet/sublinear-core, agent-booster, @ruvector/router,
|
|
5
5
|
* ruvector-onnx-embeddings-wasm).
|
|
6
6
|
*
|
|
@@ -12,6 +12,7 @@ import { z } from 'zod';
|
|
|
12
12
|
import { isOptionalInstalled } from '../../integrations/optional.js';
|
|
13
13
|
import { scanPromptInjection, promptInjectionEngine, getInjectionPolicy } from '../../integrations/prompt-injection.js';
|
|
14
14
|
import { partitionTaskGraph } from '../../integrations/task-partition.js';
|
|
15
|
+
import { scheduleTaskGraph } from '../../integrations/task-schedule.js';
|
|
15
16
|
import { solveLinearSystem, pageRank } from '../../integrations/sublinear.js';
|
|
16
17
|
import { onnxWasmModelCached, onnxWasmDownloadAllowed } from '../../integrations/onnx-wasm-embedder.js';
|
|
17
18
|
/** Optional packages and what they power. `probe` is checked without loading it. */
|
|
@@ -20,6 +21,7 @@ export const ECOSYSTEM_PACKAGES = [
|
|
|
20
21
|
{ pkg: 'agent-booster', probe: 'agent-booster', powers: 'in-process code edits (agent_booster_* tools)' },
|
|
21
22
|
{ pkg: '@ruvector/router', probe: '@ruvector/router', powers: 'native HNSW index for SemanticRouter' },
|
|
22
23
|
{ pkg: '@ruvector/mincut-wasm', probe: '@ruvector/mincut-wasm', powers: 'task-graph partitioning (swarm_partition_tasks)' },
|
|
24
|
+
{ pkg: '@ruvector/rudag', probe: '@ruvector/rudag', powers: 'task-graph scheduling: execution waves and critical path (swarm_schedule_tasks)' },
|
|
23
25
|
{ pkg: '@ruvnet/sublinear-core', probe: '@ruvnet/sublinear-core', powers: 'linear solves, PageRank and personalized PageRank (sublinear_solve, sublinear_pagerank)' },
|
|
24
26
|
{ pkg: 'ruvector-onnx-embeddings-wasm', probe: 'ruvector-onnx-embeddings-wasm', powers: 'all-MiniLM-L6-v2 embeddings (AgentDBFast, EmbeddingService onnx-wasm)' },
|
|
25
27
|
];
|
|
@@ -37,6 +39,24 @@ const partitionParams = z.object({
|
|
|
37
39
|
}))
|
|
38
40
|
.max(50000),
|
|
39
41
|
});
|
|
42
|
+
const scheduleParams = z.object({
|
|
43
|
+
tasks: z
|
|
44
|
+
.array(z.union([
|
|
45
|
+
z.string().min(1).max(200),
|
|
46
|
+
z.object({
|
|
47
|
+
id: z.string().min(1).max(200),
|
|
48
|
+
cost: z.number().nonnegative().finite().optional().describe('Additive cost (minutes, tokens, dollars), default 1'),
|
|
49
|
+
}),
|
|
50
|
+
]))
|
|
51
|
+
.max(5000)
|
|
52
|
+
.describe('Task ids or {id, cost}; tasks only named in dependencies get cost 1'),
|
|
53
|
+
dependencies: z
|
|
54
|
+
.array(z.object({
|
|
55
|
+
from: z.string().min(1).max(200).describe('Runs first'),
|
|
56
|
+
to: z.string().min(1).max(200).describe('Starts after from finishes'),
|
|
57
|
+
}))
|
|
58
|
+
.max(50000),
|
|
59
|
+
});
|
|
40
60
|
const solveParams = z.object({
|
|
41
61
|
matrix: z
|
|
42
62
|
.union([
|
|
@@ -105,6 +125,15 @@ export const ECOSYSTEM_TOOLS = [
|
|
|
105
125
|
return json(await partitionTaskGraph(a.tasks, a.dependencies));
|
|
106
126
|
},
|
|
107
127
|
},
|
|
128
|
+
{
|
|
129
|
+
name: 'swarm_schedule_tasks',
|
|
130
|
+
description: 'Schedule a task-dependency DAG for a swarm: execution order, parallel waves (tasks that can go to separate agents at once), earliest start per task, and the critical path (the cost-weighted chain that bounds the run). Rejects cycles. Uses @ruvector/rudag, built-in Kahn sort + longest path otherwise.',
|
|
131
|
+
parameters: scheduleParams,
|
|
132
|
+
execute: async (raw) => {
|
|
133
|
+
const a = scheduleParams.parse(raw);
|
|
134
|
+
return json(await scheduleTaskGraph(a.tasks, a.dependencies));
|
|
135
|
+
},
|
|
136
|
+
},
|
|
108
137
|
{
|
|
109
138
|
name: 'sublinear_solve',
|
|
110
139
|
description: 'Solve Mx = b for a diagonally dominant or symmetric positive definite matrix. Uses @ruvnet/sublinear-core (Gauss-Seidel / conjugate gradient), verifies the residual max|Mx-b|, and falls back to a built-in Gauss-Seidel. Returns solution, residual, iterations, method and engine.',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ecosystem-tools.js","sourceRoot":"","sources":["../../../src/mcp/tools/ecosystem-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,CAAC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C,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAChC,OAAO,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;QACrD,CAAC;KACF;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAEvE,MAAM,UAAU,sBAAsB,CAAC,MAAkD;IACvF,KAAK,MAAM,IAAI,IAAI,eAAe;QAAE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAC3D,CAAC","sourcesContent":["/**\n * Ecosystem MCP tools: in-process access to the optional ruvnet packages\n * agentic-flow integrates (aidefence, @ruvector/mincut-wasm,\n * @ruvnet/sublinear-core, agent-booster, @ruvector/router,\n * ruvector-onnx-embeddings-wasm).\n *\n * Every tool works without its optional package (built-in fallback) and says\n * which engine answered. All are pure computations with no side effects, so\n * the MCP policy admits them under the default `readonly` profile.\n */\n\nimport { z } from 'zod';\nimport { isOptionalInstalled } from '../../integrations/optional.js';\nimport { scanPromptInjection, promptInjectionEngine, getInjectionPolicy } from '../../integrations/prompt-injection.js';\nimport { partitionTaskGraph, type TaskDependency } from '../../integrations/task-partition.js';\nimport { solveLinearSystem, pageRank, type MatrixInput, type PageRankEdge } from '../../integrations/sublinear.js';\nimport { onnxWasmModelCached, onnxWasmDownloadAllowed } from '../../integrations/onnx-wasm-embedder.js';\n\nexport interface EcosystemTool {\n name: string;\n description: string;\n parameters: z.ZodTypeAny;\n execute: (args: unknown) => Promise<string>;\n}\n\n/** Optional packages and what they power. `probe` is checked without loading it. */\nexport const ECOSYSTEM_PACKAGES = [\n { pkg: 'aidefence', probe: 'aidefence/dist/detection', powers: 'prompt-injection screening (InputValidator, prompt_injection_scan)' },\n { pkg: 'agent-booster', probe: 'agent-booster', powers: 'in-process code edits (agent_booster_* tools)' },\n { pkg: '@ruvector/router', probe: '@ruvector/router', powers: 'native HNSW index for SemanticRouter' },\n { pkg: '@ruvector/mincut-wasm', probe: '@ruvector/mincut-wasm', powers: 'task-graph partitioning (swarm_partition_tasks)' },\n { pkg: '@ruvnet/sublinear-core', probe: '@ruvnet/sublinear-core', powers: 'linear solves, PageRank and personalized PageRank (sublinear_solve, sublinear_pagerank)' },\n { pkg: 'ruvector-onnx-embeddings-wasm', probe: 'ruvector-onnx-embeddings-wasm', powers: 'all-MiniLM-L6-v2 embeddings (AgentDBFast, EmbeddingService onnx-wasm)' },\n] as const;\n\n// The project compiles with strict: false, so zod infers object fields as\n// optional; the schemas themselves require them, hence the casts below.\nconst json = (v: unknown) => JSON.stringify(v, null, 2);\n\nconst statusParams = z.object({}).strict();\nconst partitionParams = z.object({\n tasks: z.array(z.string().min(1).max(200)).max(5000).describe('Task ids; tasks only named in dependencies are added'),\n dependencies: z\n .array(z.object({\n from: z.string().min(1).max(200),\n to: z.string().min(1).max(200),\n weight: z.number().nonnegative().finite().optional().describe('Coupling strength, default 1'),\n }))\n .max(50000),\n});\nconst solveParams = z.object({\n matrix: z\n .union([\n z.array(z.array(z.number().finite())).min(1).max(2000),\n z.object({\n size: z.number().int().positive().max(1_000_000),\n entries: z.array(z.object({ row: z.number().int(), col: z.number().int(), value: z.number().finite() })).max(5_000_000),\n }),\n ])\n .describe('Square matrix: dense rows, or {size, entries:[{row,col,value}]}; diagonally dominant for guaranteed convergence'),\n vector: z.array(z.number().finite()).min(1).describe('Right-hand side b'),\n tolerance: z.number().positive().max(1).optional(),\n maxIterations: z.number().int().positive().max(1_000_000).optional(),\n method: z\n .enum(['auto', 'gauss-seidel', 'conjugate-gradient', 'jacobi', 'neumann'])\n .optional()\n .describe('Default auto: conjugate-gradient for symmetric matrices with a positive diagonal, else gauss-seidel'),\n});\nconst pagerankParams = z.object({\n edges: z.array(z.object({\n from: z.string().min(1).max(200),\n to: z.string().min(1).max(200),\n weight: z.number().nonnegative().finite().optional(),\n })).max(500000),\n nodes: z.array(z.string().min(1).max(200)).max(100000).optional().describe('Extra nodes with no edges'),\n damping: z.number().gt(0).lt(1).optional().describe('Probability of following an edge (1 - restart probability), default 0.85'),\n top: z.number().int().positive().max(10000).optional().describe('Return only the top N (default all)'),\n seeds: z\n .union([\n z.array(z.string().min(1).max(200)).min(1).max(100000),\n z.record(z.string().min(1).max(200), z.number().nonnegative().finite()),\n ])\n .optional()\n .describe('Personalized PageRank: restart at these nodes (equal weight), or {node: weight}'),\n approximate: z\n .boolean()\n .optional()\n .describe('With seeds: local forward push. Work depends on epsilon, not graph size; best with top on large graphs. Returns residualMass (L1 error bound)'),\n epsilon: z.number().positive().max(0.1).optional().describe('Forward-push residual threshold, default 1e-6 (smaller = more accurate)'),\n});\nconst scanParams = z.object({\n text: z.string().max(100000),\n policy: z.enum(['block', 'strict', 'warn']).optional().describe('Override AGENTIC_FLOW_PROMPT_INJECTION for this scan'),\n});\n\nexport const ECOSYSTEM_TOOLS: EcosystemTool[] = [\n {\n name: 'ecosystem_status',\n description: 'List the optional ruvnet packages agentic-flow integrates, whether each is installed, and what it powers. Every integration has a built-in fallback.',\n parameters: statusParams,\n execute: async (raw) => {\n statusParams.parse(raw ?? {});\n return json({\n packages: ECOSYSTEM_PACKAGES.map(({ pkg, probe, powers }) => ({ package: pkg, installed: isOptionalInstalled(probe), powers })),\n promptInjection: { engine: promptInjectionEngine(), policy: getInjectionPolicy() },\n embeddings: { modelCached: onnxWasmModelCached(), downloadAllowed: onnxWasmDownloadAllowed() },\n install: 'npm install agentic-flow (optional packages install by default; --omit=optional skips them)',\n });\n },\n },\n {\n name: 'swarm_partition_tasks',\n description: 'Split a task-dependency graph into two groups with the least coupling (exact global minimum cut) — the seam to hand work to two agent teams. Uses @ruvector/mincut-wasm, built-in Stoer-Wagner otherwise.',\n parameters: partitionParams,\n execute: async (raw) => {\n const a = partitionParams.parse(raw);\n return json(await partitionTaskGraph(a.tasks, a.dependencies as TaskDependency[]));\n },\n },\n {\n name: 'sublinear_solve',\n description: 'Solve Mx = b for a diagonally dominant or symmetric positive definite matrix. Uses @ruvnet/sublinear-core (Gauss-Seidel / conjugate gradient), verifies the residual max|Mx-b|, and falls back to a built-in Gauss-Seidel. Returns solution, residual, iterations, method and engine.',\n parameters: solveParams,\n execute: async (raw) => {\n const a = solveParams.parse(raw);\n return json(await solveLinearSystem(a.matrix as MatrixInput, a.vector, { tolerance: a.tolerance, maxIterations: a.maxIterations, method: a.method }));\n },\n },\n {\n name: 'sublinear_pagerank',\n description: 'PageRank over a directed graph (agents, files, tasks), or personalized PageRank around seeds (what matters to these nodes). Uses @ruvnet/sublinear-core power iteration, or local forward push with approximate: true; results are verified, built-in Gauss-Seidel fallback. Returns scores, a ranking and the engine.',\n parameters: pagerankParams,\n execute: async (raw) => {\n const a = pagerankParams.parse(raw);\n return json(await pageRank(a.edges as PageRankEdge[], {\n damping: a.damping,\n nodes: a.nodes,\n seeds: a.seeds as string[] | Record<string, number> | undefined,\n approximate: a.approximate,\n epsilon: a.epsilon,\n top: a.top,\n }));\n },\n },\n {\n name: 'prompt_injection_scan',\n description: 'Scan text for prompt-injection attempts (instruction override, role switching, prompt exfiltration, jailbreaks) with aidefence, built-in patterns otherwise. Returns threats and the policy decision (allow/warn/block).',\n parameters: scanParams,\n execute: async (raw) => {\n const a = scanParams.parse(raw);\n return json(scanPromptInjection(a.text, a.policy));\n },\n },\n];\n\nexport const ECOSYSTEM_TOOL_NAMES = ECOSYSTEM_TOOLS.map((t) => t.name);\n\nexport function registerEcosystemTools(server: { addTool: (tool: EcosystemTool) => void }): void {\n for (const tool of ECOSYSTEM_TOOLS) server.addTool(tool);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ecosystem-tools.js","sourceRoot":"","sources":["../../../src/mcp/tools/ecosystem-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,m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F;IACD;QACE,IAAI,EAAE,uBAAuB;QAC7B,WAAW,EAAE,0NAA0N;QACvO,UAAU,EAAE,UAAU;QACtB,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;YACrB,MAAM,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAChC,OAAO,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;QACrD,CAAC;KACF;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAEvE,MAAM,UAAU,sBAAsB,CAAC,MAAkD;IACvF,KAAK,MAAM,IAAI,IAAI,eAAe;QAAE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAC3D,CAAC","sourcesContent":["/**\n * Ecosystem MCP tools: in-process access to the optional ruvnet packages\n * agentic-flow integrates (aidefence, @ruvector/mincut-wasm, @ruvector/rudag,\n * @ruvnet/sublinear-core, agent-booster, @ruvector/router,\n * ruvector-onnx-embeddings-wasm).\n *\n * Every tool works without its optional package (built-in fallback) and says\n * which engine answered. All are pure computations with no side effects, so\n * the MCP policy admits them under the default `readonly` profile.\n */\n\nimport { z } from 'zod';\nimport { isOptionalInstalled } from '../../integrations/optional.js';\nimport { scanPromptInjection, promptInjectionEngine, getInjectionPolicy } from '../../integrations/prompt-injection.js';\nimport { partitionTaskGraph, type TaskDependency } from '../../integrations/task-partition.js';\nimport { scheduleTaskGraph, type ScheduleTask, type ScheduleDependency } from '../../integrations/task-schedule.js';\nimport { solveLinearSystem, pageRank, type MatrixInput, type PageRankEdge } from '../../integrations/sublinear.js';\nimport { onnxWasmModelCached, onnxWasmDownloadAllowed } from '../../integrations/onnx-wasm-embedder.js';\n\nexport interface EcosystemTool {\n name: string;\n description: string;\n parameters: z.ZodTypeAny;\n execute: (args: unknown) => Promise<string>;\n}\n\n/** Optional packages and what they power. `probe` is checked without loading it. */\nexport const ECOSYSTEM_PACKAGES = [\n { pkg: 'aidefence', probe: 'aidefence/dist/detection', powers: 'prompt-injection screening (InputValidator, prompt_injection_scan)' },\n { pkg: 'agent-booster', probe: 'agent-booster', powers: 'in-process code edits (agent_booster_* tools)' },\n { pkg: '@ruvector/router', probe: '@ruvector/router', powers: 'native HNSW index for SemanticRouter' },\n { pkg: '@ruvector/mincut-wasm', probe: '@ruvector/mincut-wasm', powers: 'task-graph partitioning (swarm_partition_tasks)' },\n { pkg: '@ruvector/rudag', probe: '@ruvector/rudag', powers: 'task-graph scheduling: execution waves and critical path (swarm_schedule_tasks)' },\n { pkg: '@ruvnet/sublinear-core', probe: '@ruvnet/sublinear-core', powers: 'linear solves, PageRank and personalized PageRank (sublinear_solve, sublinear_pagerank)' },\n { pkg: 'ruvector-onnx-embeddings-wasm', probe: 'ruvector-onnx-embeddings-wasm', powers: 'all-MiniLM-L6-v2 embeddings (AgentDBFast, EmbeddingService onnx-wasm)' },\n] as const;\n\n// The project compiles with strict: false, so zod infers object fields as\n// optional; the schemas themselves require them, hence the casts below.\nconst json = (v: unknown) => JSON.stringify(v, null, 2);\n\nconst statusParams = z.object({}).strict();\nconst partitionParams = z.object({\n tasks: z.array(z.string().min(1).max(200)).max(5000).describe('Task ids; tasks only named in dependencies are added'),\n dependencies: z\n .array(z.object({\n from: z.string().min(1).max(200),\n to: z.string().min(1).max(200),\n weight: z.number().nonnegative().finite().optional().describe('Coupling strength, default 1'),\n }))\n .max(50000),\n});\nconst scheduleParams = z.object({\n tasks: z\n .array(z.union([\n z.string().min(1).max(200),\n z.object({\n id: z.string().min(1).max(200),\n cost: z.number().nonnegative().finite().optional().describe('Additive cost (minutes, tokens, dollars), default 1'),\n }),\n ]))\n .max(5000)\n .describe('Task ids or {id, cost}; tasks only named in dependencies get cost 1'),\n dependencies: z\n .array(z.object({\n from: z.string().min(1).max(200).describe('Runs first'),\n to: z.string().min(1).max(200).describe('Starts after from finishes'),\n }))\n .max(50000),\n});\nconst solveParams = z.object({\n matrix: z\n .union([\n z.array(z.array(z.number().finite())).min(1).max(2000),\n z.object({\n size: z.number().int().positive().max(1_000_000),\n entries: z.array(z.object({ row: z.number().int(), col: z.number().int(), value: z.number().finite() })).max(5_000_000),\n }),\n ])\n .describe('Square matrix: dense rows, or {size, entries:[{row,col,value}]}; diagonally dominant for guaranteed convergence'),\n vector: z.array(z.number().finite()).min(1).describe('Right-hand side b'),\n tolerance: z.number().positive().max(1).optional(),\n maxIterations: z.number().int().positive().max(1_000_000).optional(),\n method: z\n .enum(['auto', 'gauss-seidel', 'conjugate-gradient', 'jacobi', 'neumann'])\n .optional()\n .describe('Default auto: conjugate-gradient for symmetric matrices with a positive diagonal, else gauss-seidel'),\n});\nconst pagerankParams = z.object({\n edges: z.array(z.object({\n from: z.string().min(1).max(200),\n to: z.string().min(1).max(200),\n weight: z.number().nonnegative().finite().optional(),\n })).max(500000),\n nodes: z.array(z.string().min(1).max(200)).max(100000).optional().describe('Extra nodes with no edges'),\n damping: z.number().gt(0).lt(1).optional().describe('Probability of following an edge (1 - restart probability), default 0.85'),\n top: z.number().int().positive().max(10000).optional().describe('Return only the top N (default all)'),\n seeds: z\n .union([\n z.array(z.string().min(1).max(200)).min(1).max(100000),\n z.record(z.string().min(1).max(200), z.number().nonnegative().finite()),\n ])\n .optional()\n .describe('Personalized PageRank: restart at these nodes (equal weight), or {node: weight}'),\n approximate: z\n .boolean()\n .optional()\n .describe('With seeds: local forward push. Work depends on epsilon, not graph size; best with top on large graphs. Returns residualMass (L1 error bound)'),\n epsilon: z.number().positive().max(0.1).optional().describe('Forward-push residual threshold, default 1e-6 (smaller = more accurate)'),\n});\nconst scanParams = z.object({\n text: z.string().max(100000),\n policy: z.enum(['block', 'strict', 'warn']).optional().describe('Override AGENTIC_FLOW_PROMPT_INJECTION for this scan'),\n});\n\nexport const ECOSYSTEM_TOOLS: EcosystemTool[] = [\n {\n name: 'ecosystem_status',\n description: 'List the optional ruvnet packages agentic-flow integrates, whether each is installed, and what it powers. Every integration has a built-in fallback.',\n parameters: statusParams,\n execute: async (raw) => {\n statusParams.parse(raw ?? {});\n return json({\n packages: ECOSYSTEM_PACKAGES.map(({ pkg, probe, powers }) => ({ package: pkg, installed: isOptionalInstalled(probe), powers })),\n promptInjection: { engine: promptInjectionEngine(), policy: getInjectionPolicy() },\n embeddings: { modelCached: onnxWasmModelCached(), downloadAllowed: onnxWasmDownloadAllowed() },\n install: 'npm install agentic-flow (optional packages install by default; --omit=optional skips them)',\n });\n },\n },\n {\n name: 'swarm_partition_tasks',\n description: 'Split a task-dependency graph into two groups with the least coupling (exact global minimum cut) — the seam to hand work to two agent teams. Uses @ruvector/mincut-wasm, built-in Stoer-Wagner otherwise.',\n parameters: partitionParams,\n execute: async (raw) => {\n const a = partitionParams.parse(raw);\n return json(await partitionTaskGraph(a.tasks, a.dependencies as TaskDependency[]));\n },\n },\n {\n name: 'swarm_schedule_tasks',\n description: 'Schedule a task-dependency DAG for a swarm: execution order, parallel waves (tasks that can go to separate agents at once), earliest start per task, and the critical path (the cost-weighted chain that bounds the run). Rejects cycles. Uses @ruvector/rudag, built-in Kahn sort + longest path otherwise.',\n parameters: scheduleParams,\n execute: async (raw) => {\n const a = scheduleParams.parse(raw);\n return json(await scheduleTaskGraph(a.tasks as Array<string | ScheduleTask>, a.dependencies as ScheduleDependency[]));\n },\n },\n {\n name: 'sublinear_solve',\n description: 'Solve Mx = b for a diagonally dominant or symmetric positive definite matrix. Uses @ruvnet/sublinear-core (Gauss-Seidel / conjugate gradient), verifies the residual max|Mx-b|, and falls back to a built-in Gauss-Seidel. Returns solution, residual, iterations, method and engine.',\n parameters: solveParams,\n execute: async (raw) => {\n const a = solveParams.parse(raw);\n return json(await solveLinearSystem(a.matrix as MatrixInput, a.vector, { tolerance: a.tolerance, maxIterations: a.maxIterations, method: a.method }));\n },\n },\n {\n name: 'sublinear_pagerank',\n description: 'PageRank over a directed graph (agents, files, tasks), or personalized PageRank around seeds (what matters to these nodes). Uses @ruvnet/sublinear-core power iteration, or local forward push with approximate: true; results are verified, built-in Gauss-Seidel fallback. Returns scores, a ranking and the engine.',\n parameters: pagerankParams,\n execute: async (raw) => {\n const a = pagerankParams.parse(raw);\n return json(await pageRank(a.edges as PageRankEdge[], {\n damping: a.damping,\n nodes: a.nodes,\n seeds: a.seeds as string[] | Record<string, number> | undefined,\n approximate: a.approximate,\n epsilon: a.epsilon,\n top: a.top,\n }));\n },\n },\n {\n name: 'prompt_injection_scan',\n description: 'Scan text for prompt-injection attempts (instruction override, role switching, prompt exfiltration, jailbreaks) with aidefence, built-in patterns otherwise. Returns threats and the policy decision (allow/warn/block).',\n parameters: scanParams,\n execute: async (raw) => {\n const a = scanParams.parse(raw);\n return json(scanPromptInjection(a.text, a.policy));\n },\n },\n];\n\nexport const ECOSYSTEM_TOOL_NAMES = ECOSYSTEM_TOOLS.map((t) => t.name);\n\nexport function registerEcosystemTools(server: { addTool: (tool: EcosystemTool) => void }): void {\n for (const tool of ECOSYSTEM_TOOLS) server.addTool(tool);\n}\n"]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export * from './quic.js';
|
|
2
|
-
export { loadQuicTransport, isQuicAvailable, getTransportCapabilities, WebSocketFallbackTransport, DEFAULT_STREAM_ID, type AgentTransport, type AgentMessage, type InboundMessageHandler, type OnMessageOptions, type PoolStatistics, type TransportCapabilities, type QuicTransportConfig as LoaderQuicTransportConfig, type TlsConfig, } from './quic-loader.js';
|
|
2
|
+
export { loadQuicTransport, isQuicAvailable, getQuicStatus, QUIC_UNAVAILABLE_REASON, getTransportCapabilities, WebSocketFallbackTransport, DEFAULT_STREAM_ID, type AgentTransport, type AgentMessage, type InboundMessageHandler, type OnMessageOptions, type PoolStatistics, type TransportCapabilities, type QuicStatus, type QuicTransportConfig as LoaderQuicTransportConfig, type TlsConfig, } from './quic-loader.js';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transport/index.ts"],"names":[],"mappings":"AACA,cAAc,WAAW,CAAC;AAC1B,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,wBAAwB,EACxB,0BAA0B,EAC1B,iBAAiB,EACjB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,IAAI,yBAAyB,EACrD,KAAK,SAAS,GACf,MAAM,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transport/index.ts"],"names":[],"mappings":"AACA,cAAc,WAAW,CAAC;AAC1B,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,uBAAuB,EACvB,wBAAwB,EACxB,0BAA0B,EAC1B,iBAAiB,EACjB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,KAAK,UAAU,EACf,KAAK,mBAAmB,IAAI,yBAAyB,EACrD,KAAK,SAAS,GACf,MAAM,kBAAkB,CAAC"}
|
package/dist/transport/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// Transport Layer Exports
|
|
2
2
|
export * from './quic.js';
|
|
3
|
-
export { loadQuicTransport, isQuicAvailable, getTransportCapabilities, WebSocketFallbackTransport, DEFAULT_STREAM_ID, } from './quic-loader.js';
|
|
3
|
+
export { loadQuicTransport, isQuicAvailable, getQuicStatus, QUIC_UNAVAILABLE_REASON, getTransportCapabilities, WebSocketFallbackTransport, DEFAULT_STREAM_ID, } from './quic-loader.js';
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/transport/index.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAC1B,cAAc,WAAW,CAAC;AAC1B,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,wBAAwB,EACxB,0BAA0B,EAC1B,iBAAiB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/transport/index.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAC1B,cAAc,WAAW,CAAC;AAC1B,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,uBAAuB,EACvB,wBAAwB,EACxB,0BAA0B,EAC1B,iBAAiB,GAUlB,MAAM,kBAAkB,CAAC","sourcesContent":["// Transport Layer Exports\nexport * from './quic.js';\nexport {\n loadQuicTransport,\n isQuicAvailable,\n getQuicStatus,\n QUIC_UNAVAILABLE_REASON,\n getTransportCapabilities,\n WebSocketFallbackTransport,\n DEFAULT_STREAM_ID,\n type AgentTransport,\n type AgentMessage,\n type InboundMessageHandler,\n type OnMessageOptions,\n type PoolStatistics,\n type TransportCapabilities,\n type QuicStatus,\n type QuicTransportConfig as LoaderQuicTransportConfig,\n type TlsConfig,\n} from './quic-loader.js';\n"]}
|