@adhd/agent-mcp 2.0.1 → 2.1.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.md +236 -0
- package/CHANGELOG.md +115 -0
- package/LICENSE +21 -0
- package/README.md +201 -0
- package/docs/architecture-and-security.md +405 -0
- package/docs/marketing/.catalog/capabilities.md +143 -0
- package/docs/marketing/.catalog/consumer.md +111 -0
- package/docs/marketing/.catalog/distribution.md +223 -0
- package/docs/marketing/.catalog/doc-conformance.md +237 -0
- package/docs/marketing/.catalog/doc-ops.md +98 -0
- package/docs/marketing/.catalog/metrics.md +119 -0
- package/docs/marketing/.catalog/required-tooling.md +224 -0
- package/docs/marketing/.catalog/review.md +164 -0
- package/docs/provider-call-audit.md +254 -0
- package/llms.txt +133 -0
- package/package.json +30 -51
- package/src/__tests__/integration/harness.d.ts +871 -39
- package/src/__tests__/integration/harness.d.ts.map +1 -1
- package/src/__tests__/integration/harness.js +93 -87
- package/src/__tests__/integration/harness.js.map +1 -1
- package/src/__tests__/integration/scripted-provider.d.ts +1 -2
- package/src/__tests__/integration/scripted-provider.d.ts.map +1 -1
- package/src/__tests__/integration/scripted-provider.js +1 -3
- package/src/__tests__/integration/scripted-provider.js.map +1 -1
- package/src/config.d.ts +6 -69
- package/src/config.d.ts.map +1 -1
- package/src/config.js +1 -50
- package/src/config.js.map +1 -1
- package/src/db/client.d.ts +1516 -2
- package/src/db/client.d.ts.map +1 -1
- package/src/db/client.js +4 -2
- package/src/db/client.js.map +1 -1
- package/src/db/migrate-runner.d.ts +0 -28
- package/src/db/migrate-runner.d.ts.map +1 -1
- package/src/db/migrate-runner.js +0 -24
- package/src/db/migrate-runner.js.map +1 -1
- package/src/db/migrate.d.ts +0 -7
- package/src/db/migrate.d.ts.map +1 -1
- package/src/db/migrate.js +0 -7
- package/src/db/migrate.js.map +1 -1
- package/src/db/schema.d.ts +0 -1260
- package/src/db/schema.d.ts.map +1 -1
- package/src/db/schema.js +2 -179
- package/src/db/schema.js.map +1 -1
- package/src/index.d.ts +3 -42
- package/src/index.d.ts.map +1 -1
- package/src/index.js +32 -123
- package/src/index.js.map +1 -1
- package/src/logger.d.ts +0 -8
- package/src/logger.d.ts.map +1 -1
- package/src/logger.js +1 -12
- package/src/logger.js.map +1 -1
- package/src/scripts/agent-mcp-tail.d.ts +3 -0
- package/src/scripts/agent-mcp-tail.d.ts.map +1 -0
- package/src/scripts/agent-mcp-tail.js +227 -0
- package/src/scripts/agent-mcp-tail.js.map +1 -0
- package/src/server.d.ts +13 -34
- package/src/server.d.ts.map +1 -1
- package/src/server.js +234 -326
- package/src/server.js.map +1 -1
- package/src/store/agent-store.d.ts +3 -16
- package/src/store/agent-store.d.ts.map +1 -1
- package/src/store/agent-store.js +38 -41
- package/src/store/agent-store.js.map +1 -1
- package/src/streaming/chat-gateway.d.ts +17 -0
- package/src/streaming/chat-gateway.d.ts.map +1 -0
- package/src/streaming/chat-gateway.js +336 -0
- package/src/streaming/chat-gateway.js.map +1 -0
- package/src/streaming/event-bus.d.ts +4 -0
- package/src/streaming/event-bus.d.ts.map +1 -1
- package/src/streaming/event-bus.js +14 -1
- package/src/streaming/event-bus.js.map +1 -1
- package/src/streaming/sse-server.d.ts +3 -14
- package/src/streaming/sse-server.d.ts.map +1 -1
- package/src/streaming/sse-server.js +37 -37
- package/src/streaming/sse-server.js.map +1 -1
- package/src/utils/load-env.d.ts +0 -14
- package/src/utils/load-env.d.ts.map +1 -1
- package/src/utils/load-env.js +0 -18
- package/src/utils/load-env.js.map +1 -1
- package/drizzle/0000_nifty_sasquatch.sql +0 -55
- package/drizzle/0001_task_usage.sql +0 -16
- package/drizzle/0002_lumpy_silver_centurion.sql +0 -2
- package/drizzle/0003_nifty_shriek.sql +0 -2
- package/drizzle/0004_brief_shocker.sql +0 -4
- package/drizzle/0005_clear_lenny_balinger.sql +0 -25
- package/drizzle/0006_composed_prompts_cache.sql +0 -24
- package/drizzle/meta/0000_snapshot.json +0 -387
- package/drizzle/meta/0001_snapshot.json +0 -495
- package/drizzle/meta/0002_snapshot.json +0 -509
- package/drizzle/meta/0003_snapshot.json +0 -523
- package/drizzle/meta/0004_snapshot.json +0 -551
- package/drizzle/meta/0005_snapshot.json +0 -545
- package/drizzle/meta/0006_snapshot.json +0 -651
- package/drizzle/meta/_journal.json +0 -55
- package/src/clients/http-client.d.ts +0 -24
- package/src/clients/http-client.d.ts.map +0 -1
- package/src/clients/http-client.js +0 -98
- package/src/clients/http-client.js.map +0 -1
- package/src/clients/in-process.d.ts +0 -27
- package/src/clients/in-process.d.ts.map +0 -1
- package/src/clients/in-process.js +0 -37
- package/src/clients/in-process.js.map +0 -1
- package/src/clients/index.d.ts +0 -7
- package/src/clients/index.d.ts.map +0 -1
- package/src/clients/index.js +0 -5
- package/src/clients/index.js.map +0 -1
- package/src/clients/registry.d.ts +0 -54
- package/src/clients/registry.d.ts.map +0 -1
- package/src/clients/registry.js +0 -164
- package/src/clients/registry.js.map +0 -1
- package/src/clients/stdio-client.d.ts +0 -16
- package/src/clients/stdio-client.d.ts.map +0 -1
- package/src/clients/stdio-client.js +0 -97
- package/src/clients/stdio-client.js.map +0 -1
- package/src/clients/tool-naming.d.ts +0 -44
- package/src/clients/tool-naming.d.ts.map +0 -1
- package/src/clients/tool-naming.js +0 -65
- package/src/clients/tool-naming.js.map +0 -1
- package/src/clients/types.d.ts +0 -18
- package/src/clients/types.d.ts.map +0 -1
- package/src/clients/types.js +0 -2
- package/src/clients/types.js.map +0 -1
- package/src/engine/dag-engine.d.ts +0 -62
- package/src/engine/dag-engine.d.ts.map +0 -1
- package/src/engine/dag-engine.js +0 -158
- package/src/engine/dag-engine.js.map +0 -1
- package/src/engine/hooks.d.ts +0 -24
- package/src/engine/hooks.d.ts.map +0 -1
- package/src/engine/hooks.js +0 -50
- package/src/engine/hooks.js.map +0 -1
- package/src/engine/orchestrator.d.ts +0 -40
- package/src/engine/orchestrator.d.ts.map +0 -1
- package/src/engine/orchestrator.js +0 -507
- package/src/engine/orchestrator.js.map +0 -1
- package/src/engine/policy.d.ts +0 -66
- package/src/engine/policy.d.ts.map +0 -1
- package/src/engine/policy.js +0 -112
- package/src/engine/policy.js.map +0 -1
- package/src/engine/prompt-resolver.d.ts +0 -89
- package/src/engine/prompt-resolver.d.ts.map +0 -1
- package/src/engine/prompt-resolver.js +0 -96
- package/src/engine/prompt-resolver.js.map +0 -1
- package/src/engine/queue.d.ts +0 -29
- package/src/engine/queue.d.ts.map +0 -1
- package/src/engine/queue.js +0 -56
- package/src/engine/queue.js.map +0 -1
- package/src/plugins/index.d.ts +0 -2
- package/src/plugins/index.d.ts.map +0 -1
- package/src/plugins/index.js +0 -2
- package/src/plugins/index.js.map +0 -1
- package/src/plugins/loader.d.ts +0 -65
- package/src/plugins/loader.d.ts.map +0 -1
- package/src/plugins/loader.js +0 -222
- package/src/plugins/loader.js.map +0 -1
- package/src/plugins/usage-plugin.d.ts +0 -27
- package/src/plugins/usage-plugin.d.ts.map +0 -1
- package/src/plugins/usage-plugin.js +0 -148
- package/src/plugins/usage-plugin.js.map +0 -1
- package/src/providers/anthropic.d.ts +0 -13
- package/src/providers/anthropic.d.ts.map +0 -1
- package/src/providers/anthropic.js +0 -260
- package/src/providers/anthropic.js.map +0 -1
- package/src/providers/claudecli.d.ts +0 -153
- package/src/providers/claudecli.d.ts.map +0 -1
- package/src/providers/claudecli.js +0 -510
- package/src/providers/claudecli.js.map +0 -1
- package/src/providers/factory.d.ts +0 -10
- package/src/providers/factory.d.ts.map +0 -1
- package/src/providers/factory.js +0 -24
- package/src/providers/factory.js.map +0 -1
- package/src/providers/index.d.ts +0 -6
- package/src/providers/index.d.ts.map +0 -1
- package/src/providers/index.js +0 -5
- package/src/providers/index.js.map +0 -1
- package/src/providers/openai.d.ts +0 -14
- package/src/providers/openai.d.ts.map +0 -1
- package/src/providers/openai.js +0 -162
- package/src/providers/openai.js.map +0 -1
- package/src/providers/types.d.ts +0 -36
- package/src/providers/types.d.ts.map +0 -1
- package/src/providers/types.js +0 -2
- package/src/providers/types.js.map +0 -1
- package/src/store/composed-prompt-store.d.ts +0 -24
- package/src/store/composed-prompt-store.d.ts.map +0 -1
- package/src/store/composed-prompt-store.js +0 -75
- package/src/store/composed-prompt-store.js.map +0 -1
- package/src/store/index.d.ts +0 -5
- package/src/store/index.d.ts.map +0 -1
- package/src/store/index.js +0 -5
- package/src/store/index.js.map +0 -1
- package/src/store/session-store.d.ts +0 -45
- package/src/store/session-store.d.ts.map +0 -1
- package/src/store/session-store.js +0 -197
- package/src/store/session-store.js.map +0 -1
- package/src/store/task-store.d.ts +0 -55
- package/src/store/task-store.d.ts.map +0 -1
- package/src/store/task-store.js +0 -186
- package/src/store/task-store.js.map +0 -1
- package/src/tools/agent-crud.d.ts +0 -15
- package/src/tools/agent-crud.d.ts.map +0 -1
- package/src/tools/agent-crud.js +0 -32
- package/src/tools/agent-crud.js.map +0 -1
- package/src/tools/session.d.ts +0 -33
- package/src/tools/session.d.ts.map +0 -1
- package/src/tools/session.js +0 -73
- package/src/tools/session.js.map +0 -1
- package/src/tools/task.d.ts +0 -86
- package/src/tools/task.d.ts.map +0 -1
- package/src/tools/task.js +0 -406
- package/src/tools/task.js.map +0 -1
- package/src/tools/usage.d.ts +0 -60
- package/src/tools/usage.d.ts.map +0 -1
- package/src/tools/usage.js +0 -174
- package/src/tools/usage.js.map +0 -1
- package/src/types/agent.d.ts +0 -2
- package/src/types/agent.d.ts.map +0 -1
- package/src/types/agent.js +0 -3
- package/src/types/agent.js.map +0 -1
- package/src/types/execution.d.ts +0 -2
- package/src/types/execution.d.ts.map +0 -1
- package/src/types/execution.js +0 -3
- package/src/types/execution.js.map +0 -1
- package/src/types/index.d.ts +0 -2
- package/src/types/index.d.ts.map +0 -1
- package/src/types/index.js +0 -2
- package/src/types/index.js.map +0 -1
- package/src/types/mcp.d.ts +0 -2
- package/src/types/mcp.d.ts.map +0 -1
- package/src/types/mcp.js +0 -3
- package/src/types/mcp.js.map +0 -1
- package/src/types/message.d.ts +0 -2
- package/src/types/message.d.ts.map +0 -1
- package/src/types/message.js +0 -3
- package/src/types/message.js.map +0 -1
- package/src/types/session.d.ts +0 -2
- package/src/types/session.d.ts.map +0 -1
- package/src/types/session.js +0 -3
- package/src/types/session.js.map +0 -1
- package/src/types/task.d.ts +0 -2
- package/src/types/task.d.ts.map +0 -1
- package/src/types/task.js +0 -3
- package/src/types/task.js.map +0 -1
- package/src/utils/ids.d.ts +0 -2
- package/src/utils/ids.d.ts.map +0 -1
- package/src/utils/ids.js +0 -5
- package/src/utils/ids.js.map +0 -1
- package/src/utils/logger.d.ts +0 -2
- package/src/utils/logger.d.ts.map +0 -1
- package/src/utils/logger.js +0 -5
- package/src/utils/logger.js.map +0 -1
- package/src/utils/timestamps.d.ts +0 -2
- package/src/utils/timestamps.d.ts.map +0 -1
- package/src/utils/timestamps.js +0 -4
- package/src/utils/timestamps.js.map +0 -1
- package/src/validation/agent.d.ts +0 -400
- package/src/validation/agent.d.ts.map +0 -1
- package/src/validation/agent.js +0 -251
- package/src/validation/agent.js.map +0 -1
- package/src/validation/agents.d.ts +0 -2
- package/src/validation/agents.d.ts.map +0 -1
- package/src/validation/agents.js +0 -3
- package/src/validation/agents.js.map +0 -1
- package/src/validation/errors.d.ts +0 -32
- package/src/validation/errors.d.ts.map +0 -1
- package/src/validation/errors.js +0 -42
- package/src/validation/errors.js.map +0 -1
- package/src/validation/execution.d.ts +0 -86
- package/src/validation/execution.d.ts.map +0 -1
- package/src/validation/execution.js +0 -28
- package/src/validation/execution.js.map +0 -1
- package/src/validation/index.d.ts +0 -9
- package/src/validation/index.d.ts.map +0 -1
- package/src/validation/index.js +0 -9
- package/src/validation/index.js.map +0 -1
- package/src/validation/mcp.d.ts +0 -42
- package/src/validation/mcp.d.ts.map +0 -1
- package/src/validation/mcp.js +0 -28
- package/src/validation/mcp.js.map +0 -1
- package/src/validation/message.d.ts +0 -43
- package/src/validation/message.d.ts.map +0 -1
- package/src/validation/message.js +0 -23
- package/src/validation/message.js.map +0 -1
- package/src/validation/session.d.ts +0 -49
- package/src/validation/session.d.ts.map +0 -1
- package/src/validation/session.js +0 -34
- package/src/validation/session.js.map +0 -1
- package/src/validation/task.d.ts +0 -146
- package/src/validation/task.d.ts.map +0 -1
- package/src/validation/task.js +0 -95
- package/src/validation/task.js.map +0 -1
- package/src/validation/tasks.d.ts +0 -2
- package/src/validation/tasks.d.ts.map +0 -1
- package/src/validation/tasks.js +0 -3
- package/src/validation/tasks.js.map +0 -1
- package/src/validation/usage.d.ts +0 -89
- package/src/validation/usage.d.ts.map +0 -1
- package/src/validation/usage.js +0 -98
- package/src/validation/usage.js.map +0 -1
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tool-name encoding shared across the registry and the orchestrator.
|
|
3
|
-
*
|
|
4
|
-
* Tools are advertised to the model as `<server>__<tool>`. Many OpenAI-compatible
|
|
5
|
-
* and local models (e.g. LM Studio / qwen) restrict function names to
|
|
6
|
-
* `[A-Za-z0-9_]` and silently rewrite other characters — notably `-` → `_` — so
|
|
7
|
-
* an advertised `agent-mcp__agent` comes back from the model as
|
|
8
|
-
* `agent_mcp__agent`. A literal lookup then fails ("No MCP server config found
|
|
9
|
-
* for server: 'agent_mcp'"), which breaks recursion (the `agent-mcp` key) and any
|
|
10
|
-
* MCP server whose name contains a hyphen. Anthropic preserves the name, so this
|
|
11
|
-
* only bites the OpenAI-compatible providers — but the round-trip must be robust
|
|
12
|
-
* for ALL of them.
|
|
13
|
-
*
|
|
14
|
-
* The fix: index both the advertised name and its normalized form, and normalize
|
|
15
|
-
* the model's returned name the same way before resolving.
|
|
16
|
-
*/
|
|
17
|
-
export const TOOL_NAME_SEPARATOR = "__";
|
|
18
|
-
/** Normalize a tool name to the charset models restrict function names to. */
|
|
19
|
-
export function normalizeToolName(name) {
|
|
20
|
-
return name.replace(/[^A-Za-z0-9_]/g, "_");
|
|
21
|
-
}
|
|
22
|
-
/** Split a name on the first separator into { server, tool } (no resolution). */
|
|
23
|
-
function splitToolName(name) {
|
|
24
|
-
const i = name.indexOf(TOOL_NAME_SEPARATOR);
|
|
25
|
-
return i === -1
|
|
26
|
-
? { server: name, tool: name }
|
|
27
|
-
: { server: name.slice(0, i), tool: name.slice(i + TOOL_NAME_SEPARATOR.length) };
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Resolve a tool name AS RETURNED BY A MODEL into { server, tool }.
|
|
31
|
-
*
|
|
32
|
-
* - A qualified `<server>__<tool>` name splits on the separator (prior behavior).
|
|
33
|
-
* - A **bare** `<tool>` name (no separator) is resolved against the tool names the
|
|
34
|
-
* model was actually advertised: if exactly one advertised tool has that
|
|
35
|
-
* tool-part it is used; if several do, an actionable error lists the qualified
|
|
36
|
-
* candidates; if none do, it falls back to a literal split so downstream
|
|
37
|
-
* "unknown tool / no server config" handling still applies.
|
|
38
|
-
*
|
|
39
|
-
* Background (BACKLOG DEBT-004): capable models frequently emit the bare tool
|
|
40
|
-
* name (`agent` / `task`) instead of the advertised `agent-mcp__agent`, which used
|
|
41
|
-
* to hard-fail the whole task with "Invalid tool name (missing server prefix)".
|
|
42
|
-
* Since the separator is unambiguous in advertised names, a bare name that maps to
|
|
43
|
-
* exactly one advertised tool can be resolved deterministically.
|
|
44
|
-
*
|
|
45
|
-
* @param rawName the tool name the model returned
|
|
46
|
-
* @param advertised the advertised tool names the model was given (`<server>__<tool>`)
|
|
47
|
-
*/
|
|
48
|
-
export function resolveToolCallName(rawName, advertised = []) {
|
|
49
|
-
if (rawName.includes(TOOL_NAME_SEPARATOR))
|
|
50
|
-
return splitToolName(rawName);
|
|
51
|
-
const norm = normalizeToolName(rawName);
|
|
52
|
-
const candidates = Array.from(new Set(advertised)).filter((a) => {
|
|
53
|
-
const { tool } = splitToolName(a);
|
|
54
|
-
return tool === rawName || normalizeToolName(tool) === norm;
|
|
55
|
-
});
|
|
56
|
-
if (candidates.length === 1)
|
|
57
|
-
return splitToolName(candidates[0]);
|
|
58
|
-
if (candidates.length > 1) {
|
|
59
|
-
throw new Error(`Ambiguous tool name '${rawName}': multiple servers expose it — qualify with a server prefix, one of: ${candidates.join(", ")}`);
|
|
60
|
-
}
|
|
61
|
-
// No advertised match — preserve prior split (server = tool = rawName); the
|
|
62
|
-
// registry then surfaces a normal "no server config" / unknown-tool error.
|
|
63
|
-
return splitToolName(rawName);
|
|
64
|
-
}
|
|
65
|
-
//# sourceMappingURL=tool-naming.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tool-naming.js","sourceRoot":"","sources":["../../../../../../packages/ai/agent-mcp/src/clients/tool-naming.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAC;AAExC,8EAA8E;AAC9E,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC1C,OAAO,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,GAAG,CAAC,CAAC;AAC/C,CAAC;AAOD,iFAAiF;AACjF,SAAS,aAAa,CAAC,IAAY;IAC/B,MAAM,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAC5C,OAAO,CAAC,KAAK,CAAC,CAAC;QACX,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE;QAC9B,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,mBAAmB,CAAC,MAAM,CAAC,EAAE,CAAC;AACzF,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAe,EAAE,aAAgC,EAAE;IACnF,IAAI,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAC;QAAE,OAAO,aAAa,CAAC,OAAO,CAAC,CAAC;IAEzE,MAAM,IAAI,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC;IACxC,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE;QAC5D,MAAM,EAAE,IAAI,EAAE,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;QAClC,OAAO,IAAI,KAAK,OAAO,IAAI,iBAAiB,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;IAChE,CAAC,CAAC,CAAC;IAEH,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IACjE,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CACX,wBAAwB,OAAO,yEAAyE,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAClI,CAAC;IACN,CAAC;IACD,4EAA4E;IAC5E,2EAA2E;IAC3E,OAAO,aAAa,CAAC,OAAO,CAAC,CAAC;AAClC,CAAC"}
|
package/src/clients/types.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { ToolDefinition } from "../providers/types.js";
|
|
2
|
-
export interface IMcpClient {
|
|
3
|
-
/** Returns all tools advertised by this MCP server */
|
|
4
|
-
listTools(): Promise<ToolDefinition[]>;
|
|
5
|
-
/**
|
|
6
|
-
* Call a single tool on this server.
|
|
7
|
-
* @param toolName the tool name (without server prefix)
|
|
8
|
-
* @param args the arguments to pass
|
|
9
|
-
* @param signal optional abort signal — when the task is cancelled (or
|
|
10
|
-
* times out) this fires, so an in-flight tool call is
|
|
11
|
-
* interrupted instead of running to completion. Composed
|
|
12
|
-
* with any client-level timeout.
|
|
13
|
-
*/
|
|
14
|
-
callTool(toolName: string, args: unknown, signal?: AbortSignal): Promise<unknown>;
|
|
15
|
-
/** Tear down the client (kill child processes, close connections) */
|
|
16
|
-
close(): Promise<void>;
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../packages/ai/agent-mcp/src/clients/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,WAAW,UAAU;IACvB,sDAAsD;IACtD,SAAS,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;IAEvC;;;;;;;;OAQG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAElF,qEAAqE;IACrE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B"}
|
package/src/clients/types.js
DELETED
package/src/clients/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../packages/ai/agent-mcp/src/clients/types.ts"],"names":[],"mappings":""}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import type { BetterSQLite3Database } from "drizzle-orm/better-sqlite3";
|
|
2
|
-
import type { TaskStore } from "../store/task-store.js";
|
|
3
|
-
import type { BackgroundQueue } from "./queue.js";
|
|
4
|
-
/**
|
|
5
|
-
* DagEngine manages task dependency resolution.
|
|
6
|
-
*
|
|
7
|
-
* Two public methods:
|
|
8
|
-
* - `validateNoCycle()` — synchronous BFS cycle check; called BEFORE row insert.
|
|
9
|
-
* - `dispatchReady()` — post-terminal fan-in dispatch; called in the queue runFn
|
|
10
|
-
* `finally` block so it fires on every terminal event (completed/failed/cancelled).
|
|
11
|
-
*
|
|
12
|
-
* The `dispatchFn` is injected at server startup (built in src/index.ts) to avoid
|
|
13
|
-
* circular imports: DagEngine must NOT import from tools/task.ts.
|
|
14
|
-
*/
|
|
15
|
-
export declare class DagEngine {
|
|
16
|
-
private readonly db;
|
|
17
|
-
private readonly queue;
|
|
18
|
-
private readonly taskStore;
|
|
19
|
-
/**
|
|
20
|
-
* Injected at server startup to avoid circular imports with tools/task.ts.
|
|
21
|
-
* Signature: (taskId: string) => Promise<void>
|
|
22
|
-
* Built in index.ts by closing over the TaskDeps.
|
|
23
|
-
*/
|
|
24
|
-
private readonly dispatchFn;
|
|
25
|
-
constructor(db: BetterSQLite3Database<Record<string, never>>, queue: BackgroundQueue, taskStore: TaskStore,
|
|
26
|
-
/**
|
|
27
|
-
* Injected at server startup to avoid circular imports with tools/task.ts.
|
|
28
|
-
* Signature: (taskId: string) => Promise<void>
|
|
29
|
-
* Built in index.ts by closing over the TaskDeps.
|
|
30
|
-
*/
|
|
31
|
-
dispatchFn: (taskId: string) => Promise<void>);
|
|
32
|
-
/**
|
|
33
|
-
* BFS cycle detection. Call BEFORE inserting the new task row.
|
|
34
|
-
*
|
|
35
|
-
* Walks the existing dependency graph upward from each member of `dependsOn`.
|
|
36
|
-
* If `newTaskId` appears as an ancestor, adding it would create a cycle.
|
|
37
|
-
*
|
|
38
|
-
* Throws ToolError("VALIDATION_ERROR") if a cycle is detected.
|
|
39
|
-
* Does NOT write any rows — purely a read operation.
|
|
40
|
-
*
|
|
41
|
-
* Invariant: [inv:cycle-check-synchronous]
|
|
42
|
-
*/
|
|
43
|
-
validateNoCycle(newTaskId: string, dependsOn: string[]): void;
|
|
44
|
-
/**
|
|
45
|
-
* Called after a task reaches a terminal state (completed/failed/cancelled).
|
|
46
|
-
*
|
|
47
|
-
* Scans all `waiting` tasks for those that include `completedTaskId` in their
|
|
48
|
-
* `depends_on`. For each:
|
|
49
|
-
* - If all deps are in a terminal state, evaluate `on_upstream_failure`:
|
|
50
|
-
* - "fail" (default): mark the downstream as failed immediately.
|
|
51
|
-
* - "skip": dispatch anyway; only include completed upstreams in `inputs`.
|
|
52
|
-
*
|
|
53
|
-
* Uses optimistic locking (`AND status='waiting'` on the UPDATE) to prevent
|
|
54
|
-
* double-enqueue when two concurrent terminal events race for the same fan-in
|
|
55
|
-
* task.
|
|
56
|
-
*
|
|
57
|
-
* Invariants: [inv:waiting-no-queue], [inv:dispatch-on-completion],
|
|
58
|
-
* [inv:inputs-populated-at-dispatch]
|
|
59
|
-
*/
|
|
60
|
-
dispatchReady(completedTaskId: string): Promise<void>;
|
|
61
|
-
}
|
|
62
|
-
//# sourceMappingURL=dag-engine.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dag-engine.d.ts","sourceRoot":"","sources":["../../../../../../packages/ai/agent-mcp/src/engine/dag-engine.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAIxE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAIlD;;;;;;;;;;GAUG;AACH,qBAAa,SAAS;IAEd,OAAO,CAAC,QAAQ,CAAC,EAAE;IACnB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B;;;;OAIG;IACH,OAAO,CAAC,QAAQ,CAAC,UAAU;gBARV,EAAE,EAAE,qBAAqB,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,EAChD,KAAK,EAAE,eAAe,EACtB,SAAS,EAAE,SAAS;IACrC;;;;OAIG;IACc,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC;IAGlE;;;;;;;;;;OAUG;IACH,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI;IAgC7D;;;;;;;;;;;;;;;OAeG;IACG,aAAa,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAkG9D"}
|
package/src/engine/dag-engine.js
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { and, eq, inArray } from "drizzle-orm";
|
|
2
|
-
import { tasksTable } from "../db/schema.js";
|
|
3
|
-
import { logger } from "../logger.js";
|
|
4
|
-
import { ToolError } from "../validation/errors.js";
|
|
5
|
-
import { nowIso } from "../utils/timestamps.js";
|
|
6
|
-
/**
|
|
7
|
-
* DagEngine manages task dependency resolution.
|
|
8
|
-
*
|
|
9
|
-
* Two public methods:
|
|
10
|
-
* - `validateNoCycle()` — synchronous BFS cycle check; called BEFORE row insert.
|
|
11
|
-
* - `dispatchReady()` — post-terminal fan-in dispatch; called in the queue runFn
|
|
12
|
-
* `finally` block so it fires on every terminal event (completed/failed/cancelled).
|
|
13
|
-
*
|
|
14
|
-
* The `dispatchFn` is injected at server startup (built in src/index.ts) to avoid
|
|
15
|
-
* circular imports: DagEngine must NOT import from tools/task.ts.
|
|
16
|
-
*/
|
|
17
|
-
export class DagEngine {
|
|
18
|
-
db;
|
|
19
|
-
queue;
|
|
20
|
-
taskStore;
|
|
21
|
-
dispatchFn;
|
|
22
|
-
constructor(db, queue, taskStore,
|
|
23
|
-
/**
|
|
24
|
-
* Injected at server startup to avoid circular imports with tools/task.ts.
|
|
25
|
-
* Signature: (taskId: string) => Promise<void>
|
|
26
|
-
* Built in index.ts by closing over the TaskDeps.
|
|
27
|
-
*/
|
|
28
|
-
dispatchFn) {
|
|
29
|
-
this.db = db;
|
|
30
|
-
this.queue = queue;
|
|
31
|
-
this.taskStore = taskStore;
|
|
32
|
-
this.dispatchFn = dispatchFn;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* BFS cycle detection. Call BEFORE inserting the new task row.
|
|
36
|
-
*
|
|
37
|
-
* Walks the existing dependency graph upward from each member of `dependsOn`.
|
|
38
|
-
* If `newTaskId` appears as an ancestor, adding it would create a cycle.
|
|
39
|
-
*
|
|
40
|
-
* Throws ToolError("VALIDATION_ERROR") if a cycle is detected.
|
|
41
|
-
* Does NOT write any rows — purely a read operation.
|
|
42
|
-
*
|
|
43
|
-
* Invariant: [inv:cycle-check-synchronous]
|
|
44
|
-
*/
|
|
45
|
-
validateNoCycle(newTaskId, dependsOn) {
|
|
46
|
-
const visited = new Set();
|
|
47
|
-
const queue = [...dependsOn];
|
|
48
|
-
while (queue.length > 0) {
|
|
49
|
-
const id = queue.shift();
|
|
50
|
-
if (id === newTaskId) {
|
|
51
|
-
throw new ToolError("VALIDATION_ERROR", `Dependency cycle detected: task ${newTaskId} would depend on itself via its dependency chain`);
|
|
52
|
-
}
|
|
53
|
-
if (!visited.has(id)) {
|
|
54
|
-
visited.add(id);
|
|
55
|
-
const row = this.db
|
|
56
|
-
.select({ dependsOn: tasksTable.depends_on })
|
|
57
|
-
.from(tasksTable)
|
|
58
|
-
.where(eq(tasksTable.id, id))
|
|
59
|
-
.get();
|
|
60
|
-
const upstreamDeps = row?.dependsOn
|
|
61
|
-
? JSON.parse(row.dependsOn)
|
|
62
|
-
: [];
|
|
63
|
-
queue.push(...upstreamDeps);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Called after a task reaches a terminal state (completed/failed/cancelled).
|
|
69
|
-
*
|
|
70
|
-
* Scans all `waiting` tasks for those that include `completedTaskId` in their
|
|
71
|
-
* `depends_on`. For each:
|
|
72
|
-
* - If all deps are in a terminal state, evaluate `on_upstream_failure`:
|
|
73
|
-
* - "fail" (default): mark the downstream as failed immediately.
|
|
74
|
-
* - "skip": dispatch anyway; only include completed upstreams in `inputs`.
|
|
75
|
-
*
|
|
76
|
-
* Uses optimistic locking (`AND status='waiting'` on the UPDATE) to prevent
|
|
77
|
-
* double-enqueue when two concurrent terminal events race for the same fan-in
|
|
78
|
-
* task.
|
|
79
|
-
*
|
|
80
|
-
* Invariants: [inv:waiting-no-queue], [inv:dispatch-on-completion],
|
|
81
|
-
* [inv:inputs-populated-at-dispatch]
|
|
82
|
-
*/
|
|
83
|
-
async dispatchReady(completedTaskId) {
|
|
84
|
-
// Fetch all waiting tasks in a single query
|
|
85
|
-
const waitingTasks = this.db
|
|
86
|
-
.select()
|
|
87
|
-
.from(tasksTable)
|
|
88
|
-
.where(eq(tasksTable.status, "waiting"))
|
|
89
|
-
.all();
|
|
90
|
-
for (const task of waitingTasks) {
|
|
91
|
-
const deps = task.depends_on
|
|
92
|
-
? JSON.parse(task.depends_on)
|
|
93
|
-
: [];
|
|
94
|
-
// Skip if this task doesn't depend on the just-completed task
|
|
95
|
-
if (!deps.includes(completedTaskId))
|
|
96
|
-
continue;
|
|
97
|
-
// Nothing to dispatch if there are no deps (should not happen for
|
|
98
|
-
// waiting tasks, but guard defensively)
|
|
99
|
-
if (deps.length === 0)
|
|
100
|
-
continue;
|
|
101
|
-
// Check all deps for terminal status
|
|
102
|
-
const depRows = this.db
|
|
103
|
-
.select({
|
|
104
|
-
id: tasksTable.id,
|
|
105
|
-
status: tasksTable.status,
|
|
106
|
-
result: tasksTable.result,
|
|
107
|
-
})
|
|
108
|
-
.from(tasksTable)
|
|
109
|
-
.where(inArray(tasksTable.id, deps))
|
|
110
|
-
.all();
|
|
111
|
-
const terminalStatuses = new Set(["completed", "failed", "cancelled"]);
|
|
112
|
-
const allTerminal = depRows.every(r => terminalStatuses.has(r.status));
|
|
113
|
-
if (!allTerminal)
|
|
114
|
-
continue;
|
|
115
|
-
const policy = (task.on_upstream_failure ?? "fail");
|
|
116
|
-
const failedDep = depRows.find(r => r.status === "failed" || r.status === "cancelled");
|
|
117
|
-
if (failedDep && policy === "fail") {
|
|
118
|
-
// Mark downstream as failed — no enqueue
|
|
119
|
-
logger.info({ taskId: task.id, failedDepId: failedDep.id, status: failedDep.status }, "Propagating upstream failure to waiting task");
|
|
120
|
-
this.taskStore.updateStatus(task.id, "failed", {
|
|
121
|
-
error: `Upstream task ${failedDep.id} ${failedDep.status}`,
|
|
122
|
-
});
|
|
123
|
-
// Recursively dispatch tasks that depend on this now-failed task
|
|
124
|
-
await this.dispatchReady(task.id);
|
|
125
|
-
continue;
|
|
126
|
-
}
|
|
127
|
-
// policy === "skip" or all deps completed:
|
|
128
|
-
// Build inputs from completed upstream results only.
|
|
129
|
-
// Skip-case: omit failed/cancelled upstreams (no result to inject).
|
|
130
|
-
const inputs = {};
|
|
131
|
-
for (const dep of depRows) {
|
|
132
|
-
if (dep.status === "completed" && dep.result != null) {
|
|
133
|
-
inputs[dep.id] = dep.result;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
// Optimistic lock: transition waiting → pending atomically.
|
|
137
|
-
// If another concurrent dispatchReady call already transitioned this
|
|
138
|
-
// row, changes === 0 and we skip enqueue to avoid double-dispatch.
|
|
139
|
-
const updated = this.db
|
|
140
|
-
.update(tasksTable)
|
|
141
|
-
.set({
|
|
142
|
-
status: "pending",
|
|
143
|
-
inputs: JSON.stringify(inputs),
|
|
144
|
-
updatedAt: nowIso(),
|
|
145
|
-
})
|
|
146
|
-
.where(and(eq(tasksTable.id, task.id), eq(tasksTable.status, "waiting")))
|
|
147
|
-
.run();
|
|
148
|
-
if (updated.changes === 0) {
|
|
149
|
-
// Lost the race — another worker already transitioned this task
|
|
150
|
-
logger.debug({ taskId: task.id }, "DagEngine: lost optimistic lock, skipping enqueue");
|
|
151
|
-
continue;
|
|
152
|
-
}
|
|
153
|
-
logger.info({ taskId: task.id, deps, inputs: Object.keys(inputs) }, "DagEngine: dispatching ready task");
|
|
154
|
-
await this.dispatchFn(task.id);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
//# sourceMappingURL=dag-engine.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dag-engine.js","sourceRoot":"","sources":["../../../../../../packages/ai/agent-mcp/src/engine/dag-engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAG/C,OAA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,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC;gBAChC,CAAC;YACL,CAAC;YAED,4DAA4D;YAC5D,qEAAqE;YACrE,mEAAmE;YACnE,MAAM,OAAO,GAAG,IAAI,CAAC,EAAE;iBAClB,MAAM,CAAC,UAAU,CAAC;iBAClB,GAAG,CAAC;gBACD,MAAM,EAAE,SAAS;gBACjB,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;gBAC9B,SAAS,EAAE,MAAM,EAAE;aACtB,CAAC;iBACD,KAAK,CACF,GAAG,CACC,EAAE,CAAC,UAAU,CAAC,EAAE,EAAE,IAAI,CAAC,EAAE,CAAC,EAC1B,EAAE,CAAC,UAAU,CAAC,MAAM,EAAE,SAAS,CAAC,CACnC,CACJ;iBACA,GAAG,EAAE,CAAC;YAEX,IAAI,OAAO,CAAC,OAAO,KAAK,CAAC,EAAE,CAAC;gBACxB,gEAAgE;gBAChE,MAAM,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,EAAE,mDAAmD,CAAC,CAAC;gBACvF,SAAS;YACb,CAAC;YAED,MAAM,CAAC,IAAI,CACP,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,EACtD,mCAAmC,CACtC,CAAC;YAEF,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACnC,CAAC;IACL,CAAC;CACJ"}
|
package/src/engine/hooks.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { HookEvent, HookEventMap, HookHandler, IHookRegistry, EnforcementEvent, EnforcementHandler } from "@adhd/agent-mcp-types";
|
|
2
|
-
/**
|
|
3
|
-
* Concrete implementation of IHookRegistry used by the agent-mcp server.
|
|
4
|
-
*
|
|
5
|
-
* NOTE: A copy of this class also lives in @adhd/agent-mcp-types so plugin
|
|
6
|
-
* authors can instantiate it in their own tests without taking a runtime
|
|
7
|
-
* dependency on the full server package. Keep the two in sync until DEBT-009
|
|
8
|
-
* is resolved (extraction to @adhd/agent-mcp-hooks).
|
|
9
|
-
*
|
|
10
|
-
* Observational handlers registered via register() have their throws swallowed
|
|
11
|
-
* and logged — a buggy plugin never kills a task.
|
|
12
|
-
*
|
|
13
|
-
* Enforcement handlers registered via registerEnforcement() propagate throws
|
|
14
|
-
* so the orchestrator can fail the task with BUDGET_EXCEEDED.
|
|
15
|
-
*/
|
|
16
|
-
export declare class HookRegistry implements IHookRegistry {
|
|
17
|
-
private readonly handlers;
|
|
18
|
-
private readonly enforcementHandlers;
|
|
19
|
-
register<E extends HookEvent>(event: E, handler: HookHandler<E>): void;
|
|
20
|
-
emit<E extends HookEvent>(event: E, payload: HookEventMap[E]): Promise<void>;
|
|
21
|
-
registerEnforcement<E extends EnforcementEvent>(event: E, handler: EnforcementHandler<E>): void;
|
|
22
|
-
enforce<E extends EnforcementEvent>(event: E, payload: HookEventMap[E]): Promise<void>;
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../../../../packages/ai/agent-mcp/src/engine/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,SAAS,EACT,YAAY,EACZ,WAAW,EACX,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EACrB,MAAM,uBAAuB,CAAC;AAE/B;;;;;;;;;;;;;GAaG;AACH,qBAAa,YAAa,YAAW,aAAa;IAC9C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA6D;IACtF,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAuE;IAE3G,QAAQ,CAAC,CAAC,SAAS,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,IAAI;IAMhE,IAAI,CAAC,CAAC,SAAS,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAYlF,mBAAmB,CAAC,CAAC,SAAS,gBAAgB,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAAG,IAAI;IAMzF,OAAO,CAAC,CAAC,SAAS,gBAAgB,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAO/F"}
|
package/src/engine/hooks.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Concrete implementation of IHookRegistry used by the agent-mcp server.
|
|
3
|
-
*
|
|
4
|
-
* NOTE: A copy of this class also lives in @adhd/agent-mcp-types so plugin
|
|
5
|
-
* authors can instantiate it in their own tests without taking a runtime
|
|
6
|
-
* dependency on the full server package. Keep the two in sync until DEBT-009
|
|
7
|
-
* is resolved (extraction to @adhd/agent-mcp-hooks).
|
|
8
|
-
*
|
|
9
|
-
* Observational handlers registered via register() have their throws swallowed
|
|
10
|
-
* and logged — a buggy plugin never kills a task.
|
|
11
|
-
*
|
|
12
|
-
* Enforcement handlers registered via registerEnforcement() propagate throws
|
|
13
|
-
* so the orchestrator can fail the task with BUDGET_EXCEEDED.
|
|
14
|
-
*/
|
|
15
|
-
export class HookRegistry {
|
|
16
|
-
handlers = new Map();
|
|
17
|
-
enforcementHandlers = new Map();
|
|
18
|
-
register(event, handler) {
|
|
19
|
-
const list = this.handlers.get(event) ?? [];
|
|
20
|
-
list.push(handler);
|
|
21
|
-
this.handlers.set(event, list);
|
|
22
|
-
}
|
|
23
|
-
async emit(event, payload) {
|
|
24
|
-
const list = this.handlers.get(event);
|
|
25
|
-
if (!list?.length)
|
|
26
|
-
return;
|
|
27
|
-
for (const handler of list) {
|
|
28
|
-
try {
|
|
29
|
-
await handler(payload);
|
|
30
|
-
}
|
|
31
|
-
catch (err) {
|
|
32
|
-
console.warn("[HookRegistry] hook handler error (swallowed)", { event, err });
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
registerEnforcement(event, handler) {
|
|
37
|
-
const list = this.enforcementHandlers.get(event) ?? [];
|
|
38
|
-
list.push(handler);
|
|
39
|
-
this.enforcementHandlers.set(event, list);
|
|
40
|
-
}
|
|
41
|
-
async enforce(event, payload) {
|
|
42
|
-
const list = this.enforcementHandlers.get(event);
|
|
43
|
-
if (!list?.length)
|
|
44
|
-
return;
|
|
45
|
-
for (const handler of list) {
|
|
46
|
-
await handler(payload);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
//# sourceMappingURL=hooks.js.map
|
package/src/engine/hooks.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../../../../../packages/ai/agent-mcp/src/engine/hooks.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,YAAY;IACJ,QAAQ,GAAc,IAAI,GAAG,EAAuC,CAAC;IACrE,mBAAmB,GAAG,IAAI,GAAG,EAA4D,CAAC;IAE3G,QAAQ,CAAsB,KAAQ,EAAE,OAAuB;QAC3D,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAC5C,IAAI,CAAC,IAAI,CAAC,OAAiC,CAAC,CAAC;QAC7C,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,IAAI,CAAsB,KAAQ,EAAE,OAAwB;QAC9D,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACtC,IAAI,CAAC,IAAI,EAAE,MAAM;YAAE,OAAO;QAC1B,KAAK,MAAM,OAAO,IAAI,IAAI,EAAE,CAAC;YACzB,IAAI,CAAC;gBACD,MAAO,OAA0B,CAAC,OAAO,CAAC,CAAC;YAC/C,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACX,OAAO,CAAC,IAAI,CAAC,+CAA+C,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;YAClF,CAAC;QACL,CAAC;IACL,CAAC;IAED,mBAAmB,CAA6B,KAAQ,EAAE,OAA8B;QACpF,MAAM,IAAI,GAAG,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QACvD,IAAI,CAAC,IAAI,CAAC,OAA+C,CAAC,CAAC;QAC3D,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,OAAO,CAA6B,KAAQ,EAAE,OAAwB;QACxE,MAAM,IAAI,GAAG,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACjD,IAAI,CAAC,IAAI,EAAE,MAAM;YAAE,OAAO;QAC1B,KAAK,MAAM,OAAO,IAAI,IAAI,EAAE,CAAC;YACzB,MAAO,OAAiC,CAAC,OAAO,CAAC,CAAC;QACtD,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { LLMProvider } from "../providers/types.js";
|
|
2
|
-
import type { ExecutionContext, Message } from "../validation/index.js";
|
|
3
|
-
import type { IHookRegistry } from "@adhd/agent-mcp-types";
|
|
4
|
-
import type { McpClientRegistry } from "../clients/registry.js";
|
|
5
|
-
import type { PolicyEngine } from "./policy.js";
|
|
6
|
-
import type { TaskStore } from "../store/task-store.js";
|
|
7
|
-
import type { SessionStore } from "../store/session-store.js";
|
|
8
|
-
/**
|
|
9
|
-
* Resolve a suspended HITL task with the provided user input.
|
|
10
|
-
* Returns `true` if the resolver was found and called; `false` if the
|
|
11
|
-
* process restarted and the in-memory resolver no longer exists.
|
|
12
|
-
*/
|
|
13
|
-
export declare function resolveHitl(taskId: string, userInput: string): boolean;
|
|
14
|
-
export interface OrchestratorRunInput {
|
|
15
|
-
executionContext: ExecutionContext;
|
|
16
|
-
messages: Message[];
|
|
17
|
-
registry: McpClientRegistry;
|
|
18
|
-
provider: LLMProvider;
|
|
19
|
-
policy: PolicyEngine;
|
|
20
|
-
taskStore: TaskStore;
|
|
21
|
-
sessionStore: SessionStore;
|
|
22
|
-
signal: AbortSignal;
|
|
23
|
-
taskId: string;
|
|
24
|
-
hooks?: IHookRegistry;
|
|
25
|
-
/**
|
|
26
|
-
* Set to `true` for ephemeral (one-shot) tasks (agent_name mode).
|
|
27
|
-
* Ephemeral tasks DO persist a tasks row + task_events + task_usage, but
|
|
28
|
-
* have no sessions row and no messages rows. When `true`,
|
|
29
|
-
* `request_human_input` is forbidden because HITL cannot be resumed across
|
|
30
|
-
* a process restart without a durable session context.
|
|
31
|
-
*/
|
|
32
|
-
isEphemeral?: boolean;
|
|
33
|
-
}
|
|
34
|
-
export interface OrchestratorRunResult {
|
|
35
|
-
result: string;
|
|
36
|
-
}
|
|
37
|
-
export declare class Orchestrator {
|
|
38
|
-
run(input: OrchestratorRunInput): Promise<OrchestratorRunResult>;
|
|
39
|
-
}
|
|
40
|
-
//# sourceMappingURL=orchestrator.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"orchestrator.d.ts","sourceRoot":"","sources":["../../../../../../packages/ai/agent-mcp/src/engine/orchestrator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACxE,OAAO,KAAK,EAAE,aAAa,EAAqB,MAAM,uBAAuB,CAAC;AAM9E,OAAO,KAAK,E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