@animalabs/agent-framework 0.19.0 → 0.20.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/README.md +29 -0
- package/dist/src/agent.d.ts +22 -0
- package/dist/src/agent.d.ts.map +1 -1
- package/dist/src/agent.js +128 -10
- package/dist/src/agent.js.map +1 -1
- package/dist/src/api/types.d.ts +1 -1
- package/dist/src/api/types.d.ts.map +1 -1
- package/dist/src/code-execution/py-runner.d.ts +10 -1
- package/dist/src/code-execution/py-runner.d.ts.map +1 -1
- package/dist/src/code-execution/py-runner.js +27 -2
- package/dist/src/code-execution/py-runner.js.map +1 -1
- package/dist/src/code-execution/tool-definition.d.ts +21 -0
- package/dist/src/code-execution/tool-definition.d.ts.map +1 -1
- package/dist/src/code-execution/tool-definition.js +34 -0
- package/dist/src/code-execution/tool-definition.js.map +1 -1
- package/dist/src/framework.d.ts +153 -2
- package/dist/src/framework.d.ts.map +1 -1
- package/dist/src/framework.js +1169 -76
- package/dist/src/framework.js.map +1 -1
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/mcpl/capability-grant.d.ts +1 -1
- package/dist/src/mcpl/capability-grant.d.ts.map +1 -1
- package/dist/src/mcpl/capability-grant.js +49 -5
- package/dist/src/mcpl/capability-grant.js.map +1 -1
- package/dist/src/mcpl/channel-registry.d.ts +59 -2
- package/dist/src/mcpl/channel-registry.d.ts.map +1 -1
- package/dist/src/mcpl/channel-registry.js +106 -6
- package/dist/src/mcpl/channel-registry.js.map +1 -1
- package/dist/src/mcpl/index.d.ts +3 -0
- package/dist/src/mcpl/index.d.ts.map +1 -1
- package/dist/src/mcpl/index.js +3 -0
- package/dist/src/mcpl/index.js.map +1 -1
- package/dist/src/mcpl/push-coalescer.d.ts +318 -0
- package/dist/src/mcpl/push-coalescer.d.ts.map +1 -0
- package/dist/src/mcpl/push-coalescer.js +709 -0
- package/dist/src/mcpl/push-coalescer.js.map +1 -0
- package/dist/src/mcpl/push-handler.d.ts +7 -2
- package/dist/src/mcpl/push-handler.d.ts.map +1 -1
- package/dist/src/mcpl/push-handler.js +43 -4
- package/dist/src/mcpl/push-handler.js.map +1 -1
- package/dist/src/mcpl/server-connection.d.ts +18 -0
- package/dist/src/mcpl/server-connection.d.ts.map +1 -1
- package/dist/src/mcpl/server-connection.js +44 -1
- package/dist/src/mcpl/server-connection.js.map +1 -1
- package/dist/src/mcpl/tool-classes.d.ts +71 -0
- package/dist/src/mcpl/tool-classes.d.ts.map +1 -0
- package/dist/src/mcpl/tool-classes.js +170 -0
- package/dist/src/mcpl/tool-classes.js.map +1 -0
- package/dist/src/mcpl/tool-glob.d.ts +16 -0
- package/dist/src/mcpl/tool-glob.d.ts.map +1 -0
- package/dist/src/mcpl/tool-glob.js +41 -0
- package/dist/src/mcpl/tool-glob.js.map +1 -0
- package/dist/src/mcpl/tool-lifecycle.d.ts +253 -0
- package/dist/src/mcpl/tool-lifecycle.d.ts.map +1 -0
- package/dist/src/mcpl/tool-lifecycle.js +592 -0
- package/dist/src/mcpl/tool-lifecycle.js.map +1 -0
- package/dist/src/mcpl/transport.d.ts +12 -0
- package/dist/src/mcpl/transport.d.ts.map +1 -1
- package/dist/src/mcpl/transport.js +33 -1
- package/dist/src/mcpl/transport.js.map +1 -1
- package/dist/src/mcpl/types.d.ts +66 -1
- package/dist/src/mcpl/types.d.ts.map +1 -1
- package/dist/src/mcpl/types.js +6 -0
- package/dist/src/mcpl/types.js.map +1 -1
- package/dist/src/modules/discord/index.js +1 -1
- package/dist/src/modules/discord/index.js.map +1 -1
- package/dist/src/modules/history/index.d.ts +85 -0
- package/dist/src/modules/history/index.d.ts.map +1 -1
- package/dist/src/modules/history/index.js +1019 -24
- package/dist/src/modules/history/index.js.map +1 -1
- package/dist/src/modules/history/semantic.d.ts +202 -0
- package/dist/src/modules/history/semantic.d.ts.map +1 -0
- package/dist/src/modules/history/semantic.js +418 -0
- package/dist/src/modules/history/semantic.js.map +1 -0
- package/dist/src/modules/index.d.ts +2 -1
- package/dist/src/modules/index.d.ts.map +1 -1
- package/dist/src/modules/index.js.map +1 -1
- package/dist/src/tool-result-guard.d.ts +82 -0
- package/dist/src/tool-result-guard.d.ts.map +1 -0
- package/dist/src/tool-result-guard.js +306 -0
- package/dist/src/tool-result-guard.js.map +1 -0
- package/dist/src/types/agent.d.ts +14 -0
- package/dist/src/types/agent.d.ts.map +1 -1
- package/dist/src/types/framework.d.ts +21 -0
- package/dist/src/types/framework.d.ts.map +1 -1
- package/dist/src/types/trace.d.ts +17 -0
- package/dist/src/types/trace.d.ts.map +1 -1
- package/dist/test/channel-registry-routing.test.js +59 -0
- package/dist/test/channel-registry-routing.test.js.map +1 -1
- package/dist/test/code-execution.test.js +139 -0
- package/dist/test/code-execution.test.js.map +1 -1
- package/dist/test/helpers/coalescing-fixture.d.ts +72 -0
- package/dist/test/helpers/coalescing-fixture.d.ts.map +1 -0
- package/dist/test/helpers/coalescing-fixture.js +145 -0
- package/dist/test/helpers/coalescing-fixture.js.map +1 -0
- package/dist/test/helpers/coalescing-kill-child.d.ts +2 -0
- package/dist/test/helpers/coalescing-kill-child.d.ts.map +1 -0
- package/dist/test/helpers/coalescing-kill-child.js +24 -0
- package/dist/test/helpers/coalescing-kill-child.js.map +1 -0
- package/dist/test/history-module-realstore.test.d.ts +2 -0
- package/dist/test/history-module-realstore.test.d.ts.map +1 -0
- package/dist/test/history-module-realstore.test.js +363 -0
- package/dist/test/history-module-realstore.test.js.map +1 -0
- package/dist/test/history-module-semantic.test.d.ts +2 -0
- package/dist/test/history-module-semantic.test.d.ts.map +1 -0
- package/dist/test/history-module-semantic.test.js +213 -0
- package/dist/test/history-module-semantic.test.js.map +1 -0
- package/dist/test/history-module-ux.test.d.ts +2 -0
- package/dist/test/history-module-ux.test.d.ts.map +1 -0
- package/dist/test/history-module-ux.test.js +304 -0
- package/dist/test/history-module-ux.test.js.map +1 -0
- package/dist/test/history-module.test.js +25 -1
- package/dist/test/history-module.test.js.map +1 -1
- package/dist/test/history-semantic-review-findings.test.d.ts +2 -0
- package/dist/test/history-semantic-review-findings.test.d.ts.map +1 -0
- package/dist/test/history-semantic-review-findings.test.js +338 -0
- package/dist/test/history-semantic-review-findings.test.js.map +1 -0
- package/dist/test/history-semantic-sync-converges.test.d.ts +2 -0
- package/dist/test/history-semantic-sync-converges.test.d.ts.map +1 -0
- package/dist/test/history-semantic-sync-converges.test.js +109 -0
- package/dist/test/history-semantic-sync-converges.test.js.map +1 -0
- package/dist/test/mcpl-capability-grant.test.js +3 -1
- package/dist/test/mcpl-capability-grant.test.js.map +1 -1
- package/dist/test/mcpl-child-env.test.d.ts +2 -0
- package/dist/test/mcpl-child-env.test.d.ts.map +1 -0
- package/dist/test/mcpl-child-env.test.js +69 -0
- package/dist/test/mcpl-child-env.test.js.map +1 -0
- package/dist/test/mcpl-coalescing.test.d.ts +2 -0
- package/dist/test/mcpl-coalescing.test.d.ts.map +1 -0
- package/dist/test/mcpl-coalescing.test.js +1050 -0
- package/dist/test/mcpl-coalescing.test.js.map +1 -0
- package/dist/test/mcpl-list-status.test.js +4 -0
- package/dist/test/mcpl-list-status.test.js.map +1 -1
- package/dist/test/mcpl-tool-class-listing.test.d.ts +2 -0
- package/dist/test/mcpl-tool-class-listing.test.d.ts.map +1 -0
- package/dist/test/mcpl-tool-class-listing.test.js +147 -0
- package/dist/test/mcpl-tool-class-listing.test.js.map +1 -0
- package/dist/test/mcpl-tool-classes.test.d.ts +7 -0
- package/dist/test/mcpl-tool-classes.test.d.ts.map +1 -0
- package/dist/test/mcpl-tool-classes.test.js +80 -0
- package/dist/test/mcpl-tool-classes.test.js.map +1 -0
- package/dist/test/mcpl-tool-lifecycle-e2e.test.d.ts +2 -0
- package/dist/test/mcpl-tool-lifecycle-e2e.test.d.ts.map +1 -0
- package/dist/test/mcpl-tool-lifecycle-e2e.test.js +237 -0
- package/dist/test/mcpl-tool-lifecycle-e2e.test.js.map +1 -0
- package/dist/test/mcpl-tool-lifecycle-emitter.test.d.ts +11 -0
- package/dist/test/mcpl-tool-lifecycle-emitter.test.d.ts.map +1 -0
- package/dist/test/mcpl-tool-lifecycle-emitter.test.js +307 -0
- package/dist/test/mcpl-tool-lifecycle-emitter.test.js.map +1 -0
- package/dist/test/mcpl-tool-lifecycle.test.d.ts +11 -0
- package/dist/test/mcpl-tool-lifecycle.test.d.ts.map +1 -0
- package/dist/test/mcpl-tool-lifecycle.test.js +270 -0
- package/dist/test/mcpl-tool-lifecycle.test.js.map +1 -0
- package/dist/test/silent-heartbeat.test.d.ts +2 -0
- package/dist/test/silent-heartbeat.test.d.ts.map +1 -0
- package/dist/test/silent-heartbeat.test.js +154 -0
- package/dist/test/silent-heartbeat.test.js.map +1 -0
- package/dist/test/tool-result-guard.test.d.ts +2 -0
- package/dist/test/tool-result-guard.test.d.ts.map +1 -0
- package/dist/test/tool-result-guard.test.js +1081 -0
- package/dist/test/tool-result-guard.test.js.map +1 -0
- package/dist/test/trunk-channel-routing.test.js +67 -0
- package/dist/test/trunk-channel-routing.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/agent.ts +128 -10
- package/src/api/types.ts +2 -0
- package/src/code-execution/py-runner.ts +34 -2
- package/src/code-execution/tool-definition.ts +46 -0
- package/src/framework.ts +1201 -80
- package/src/index.ts +13 -0
- package/src/mcpl/capability-grant.ts +54 -6
- package/src/mcpl/channel-registry.ts +115 -7
- package/src/mcpl/index.ts +29 -0
- package/src/mcpl/push-coalescer.ts +821 -0
- package/src/mcpl/push-handler.ts +40 -4
- package/src/mcpl/server-connection.ts +48 -2
- package/src/mcpl/tool-classes.ts +188 -0
- package/src/mcpl/tool-glob.ts +36 -0
- package/src/mcpl/tool-lifecycle.ts +730 -0
- package/src/mcpl/transport.ts +35 -1
- package/src/mcpl/types.ts +69 -1
- package/src/modules/discord/index.ts +1 -1
- package/src/modules/history/index.ts +1089 -24
- package/src/modules/history/semantic.ts +473 -0
- package/src/modules/index.ts +2 -1
- package/src/tool-result-guard.ts +318 -0
- package/src/types/agent.ts +15 -0
- package/src/types/framework.ts +23 -0
- package/src/types/trace.ts +17 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool classes (MCPL RFC-008) — a coarse, fixed vocabulary for what a tool
|
|
3
|
+
* DOES, used as a key for host policy (RFC-007's argument exclusions today;
|
|
4
|
+
* approvals, audit grouping and caps later).
|
|
5
|
+
*
|
|
6
|
+
* A class is a HINT at the tier of MCP `annotations`, never a grant: it
|
|
7
|
+
* confers no authority, gates no method, and never changes what the model
|
|
8
|
+
* sees. The providing server declares it on its MCP tool definition as
|
|
9
|
+
* `_meta["mcpl/class"]`; the host computes an EFFECTIVE class per tool from
|
|
10
|
+
* (in precedence order, first source that yields a class wins entirely):
|
|
11
|
+
*
|
|
12
|
+
* 1. operator override (FrameworkConfig.toolClassOverrides),
|
|
13
|
+
* 2. the host's own knowledge of tools it implements (BUILTIN_TOOL_CLASSES
|
|
14
|
+
* plus FrameworkConfig.hostToolClasses for an embedding host's modules),
|
|
15
|
+
* 3. the server's declaration.
|
|
16
|
+
*
|
|
17
|
+
* An UNCLASSED tool is handled as the most restrictive class for every
|
|
18
|
+
* question asked of it (RFC-008 §5.2): classing is how a tool earns looser
|
|
19
|
+
* handling, never how it is denied. A tool with several classes gets the
|
|
20
|
+
* union of their restrictions (§5.3).
|
|
21
|
+
*/
|
|
22
|
+
export declare const TOOL_CLASSES: readonly ["comms", "memory", "notes", "files", "shell", "web", "computer", "media", "body", "control"];
|
|
23
|
+
export type ToolClass = (typeof TOOL_CLASSES)[number];
|
|
24
|
+
export declare function isToolClass(value: unknown): value is ToolClass;
|
|
25
|
+
/** The `_meta` key a server declares a tool's class under (RFC-008 §3). */
|
|
26
|
+
export declare const TOOL_CLASS_META_KEY = "mcpl/class";
|
|
27
|
+
/**
|
|
28
|
+
* Classes whose arguments are ordinarily safe to show an observer (RFC-007
|
|
29
|
+
* §4.3's recommended default `inputs` policy). `memory`, `notes` and
|
|
30
|
+
* `control` are left to explicit operator choice; `comms` is never a choice.
|
|
31
|
+
*/
|
|
32
|
+
export declare const DEFAULT_INPUT_CLASSES: readonly ToolClass[];
|
|
33
|
+
/**
|
|
34
|
+
* Classes of the tools this framework implements itself — the host's own
|
|
35
|
+
* knowledge (RFC-008 §5.1 source 2). Keys use the RFC-007 §6.2 pattern
|
|
36
|
+
* grammar over the model-facing tool name. Anything not listed here, not
|
|
37
|
+
* overridden and not declared by its server is UNCLASSED, which is the
|
|
38
|
+
* restrictive answer — so an omission here fails closed.
|
|
39
|
+
*/
|
|
40
|
+
export declare const BUILTIN_TOOL_CLASSES: Readonly<Record<string, readonly ToolClass[]>>;
|
|
41
|
+
/**
|
|
42
|
+
* Read a server's class declaration from a tool definition's `_meta`.
|
|
43
|
+
* Returns the known classes it names (deduplicated, in order), or undefined
|
|
44
|
+
* when it names none — which makes the tool unclassed. Unknown strings are
|
|
45
|
+
* ignored for policy and logged (RFC-008 §3, vectors 3 and 4); a non-array
|
|
46
|
+
* value is malformed and ignored the same way.
|
|
47
|
+
*/
|
|
48
|
+
export declare function parseDeclaredClasses(meta: unknown, toolName?: string): ToolClass[] | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Validate a pattern → classes table from configuration. Unknown class
|
|
51
|
+
* strings are dropped with a diagnostic; an entry left with no class is
|
|
52
|
+
* dropped entirely (it cannot classify anything).
|
|
53
|
+
*/
|
|
54
|
+
export declare function normalizeClassTable(table: Record<string, readonly string[]> | undefined, label: string): Array<[string, ToolClass[]]>;
|
|
55
|
+
export type ToolClassSource = 'override' | 'host' | 'server' | 'none';
|
|
56
|
+
export interface EffectiveToolClass {
|
|
57
|
+
/** Empty for an unclassed tool. */
|
|
58
|
+
classes: ToolClass[];
|
|
59
|
+
source: ToolClassSource;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Compute a tool's effective class (RFC-008 §5.1). `overrides` and `host`
|
|
63
|
+
* are ordered pattern tables (first matching pattern wins within a source);
|
|
64
|
+
* the first SOURCE that yields a class wins entirely — sources never merge,
|
|
65
|
+
* so an override can tighten or correct a server's declaration.
|
|
66
|
+
*/
|
|
67
|
+
export declare function resolveToolClass(toolName: string, declared: readonly ToolClass[] | undefined, tables: {
|
|
68
|
+
overrides: ReadonlyArray<readonly [string, readonly ToolClass[]]>;
|
|
69
|
+
host: ReadonlyArray<readonly [string, readonly ToolClass[]]>;
|
|
70
|
+
}): EffectiveToolClass;
|
|
71
|
+
//# sourceMappingURL=tool-classes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-classes.d.ts","sourceRoot":"","sources":["../../../src/mcpl/tool-classes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH,eAAO,MAAM,YAAY,wGAWf,CAAC;AAEX,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AAItD,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,CAE9D;AAED,2EAA2E;AAC3E,eAAO,MAAM,mBAAmB,eAAe,CAAC;AAEhD;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,EAAE,SAAS,SAAS,EAOrD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,SAAS,EAAE,CAAC,CAmC/E,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,SAAc,GAAG,SAAS,EAAE,GAAG,SAAS,CAiBnG;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,GAAG,SAAS,EACpD,KAAK,EAAE,MAAM,GACZ,KAAK,CAAC,CAAC,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC,CAe9B;AAED,MAAM,MAAM,eAAe,GAAG,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC;AAEtE,MAAM,WAAW,kBAAkB;IACjC,mCAAmC;IACnC,OAAO,EAAE,SAAS,EAAE,CAAC;IACrB,MAAM,EAAE,eAAe,CAAC;CACzB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,SAAS,SAAS,EAAE,GAAG,SAAS,EAC1C,MAAM,EAAE;IACN,SAAS,EAAE,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,SAAS,EAAE,CAAC,CAAC,CAAC;IAClE,IAAI,EAAE,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,SAAS,EAAE,CAAC,CAAC,CAAC;CAC9D,GACA,kBAAkB,CASpB"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool classes (MCPL RFC-008) — a coarse, fixed vocabulary for what a tool
|
|
3
|
+
* DOES, used as a key for host policy (RFC-007's argument exclusions today;
|
|
4
|
+
* approvals, audit grouping and caps later).
|
|
5
|
+
*
|
|
6
|
+
* A class is a HINT at the tier of MCP `annotations`, never a grant: it
|
|
7
|
+
* confers no authority, gates no method, and never changes what the model
|
|
8
|
+
* sees. The providing server declares it on its MCP tool definition as
|
|
9
|
+
* `_meta["mcpl/class"]`; the host computes an EFFECTIVE class per tool from
|
|
10
|
+
* (in precedence order, first source that yields a class wins entirely):
|
|
11
|
+
*
|
|
12
|
+
* 1. operator override (FrameworkConfig.toolClassOverrides),
|
|
13
|
+
* 2. the host's own knowledge of tools it implements (BUILTIN_TOOL_CLASSES
|
|
14
|
+
* plus FrameworkConfig.hostToolClasses for an embedding host's modules),
|
|
15
|
+
* 3. the server's declaration.
|
|
16
|
+
*
|
|
17
|
+
* An UNCLASSED tool is handled as the most restrictive class for every
|
|
18
|
+
* question asked of it (RFC-008 §5.2): classing is how a tool earns looser
|
|
19
|
+
* handling, never how it is denied. A tool with several classes gets the
|
|
20
|
+
* union of their restrictions (§5.3).
|
|
21
|
+
*/
|
|
22
|
+
import { globMatch } from './tool-glob.js';
|
|
23
|
+
export const TOOL_CLASSES = [
|
|
24
|
+
'comms',
|
|
25
|
+
'memory',
|
|
26
|
+
'notes',
|
|
27
|
+
'files',
|
|
28
|
+
'shell',
|
|
29
|
+
'web',
|
|
30
|
+
'computer',
|
|
31
|
+
'media',
|
|
32
|
+
'body',
|
|
33
|
+
'control',
|
|
34
|
+
];
|
|
35
|
+
const CLASS_SET = new Set(TOOL_CLASSES);
|
|
36
|
+
export function isToolClass(value) {
|
|
37
|
+
return typeof value === 'string' && CLASS_SET.has(value);
|
|
38
|
+
}
|
|
39
|
+
/** The `_meta` key a server declares a tool's class under (RFC-008 §3). */
|
|
40
|
+
export const TOOL_CLASS_META_KEY = 'mcpl/class';
|
|
41
|
+
/**
|
|
42
|
+
* Classes whose arguments are ordinarily safe to show an observer (RFC-007
|
|
43
|
+
* §4.3's recommended default `inputs` policy). `memory`, `notes` and
|
|
44
|
+
* `control` are left to explicit operator choice; `comms` is never a choice.
|
|
45
|
+
*/
|
|
46
|
+
export const DEFAULT_INPUT_CLASSES = [
|
|
47
|
+
'computer',
|
|
48
|
+
'shell',
|
|
49
|
+
'files',
|
|
50
|
+
'web',
|
|
51
|
+
'media',
|
|
52
|
+
'body',
|
|
53
|
+
];
|
|
54
|
+
/**
|
|
55
|
+
* Classes of the tools this framework implements itself — the host's own
|
|
56
|
+
* knowledge (RFC-008 §5.1 source 2). Keys use the RFC-007 §6.2 pattern
|
|
57
|
+
* grammar over the model-facing tool name. Anything not listed here, not
|
|
58
|
+
* overridden and not declared by its server is UNCLASSED, which is the
|
|
59
|
+
* restrictive answer — so an omission here fails closed.
|
|
60
|
+
*/
|
|
61
|
+
export const BUILTIN_TOOL_CLASSES = {
|
|
62
|
+
// Synthesized channel tools: speech to and from people (RFC-008 §4:
|
|
63
|
+
// speech that reaches a person is comms, wherever it goes).
|
|
64
|
+
'channel_*': ['comms'],
|
|
65
|
+
// Deliberately staying silent in a conversation is still about that
|
|
66
|
+
// conversation; its reason text can quote it.
|
|
67
|
+
skip_reply: ['comms'],
|
|
68
|
+
// The agent's private interior.
|
|
69
|
+
think: ['memory'],
|
|
70
|
+
journal: ['memory'],
|
|
71
|
+
// Host and agent settings, wake policy, routing help.
|
|
72
|
+
utils: ['control'],
|
|
73
|
+
agent_settings: ['control'],
|
|
74
|
+
gate_status: ['control'],
|
|
75
|
+
tune_out: ['control'],
|
|
76
|
+
sleep: ['control'],
|
|
77
|
+
wake: ['control'],
|
|
78
|
+
wake_add_rule: ['control'],
|
|
79
|
+
wake_remove_rule: ['control'],
|
|
80
|
+
event_tags: ['control'],
|
|
81
|
+
prose_help: ['control'],
|
|
82
|
+
// Files and blobs in the agent's own stores.
|
|
83
|
+
save_recent_image: ['files'],
|
|
84
|
+
read_image: ['files'],
|
|
85
|
+
// RFC-005 references resolve to the agent's own or private documents, not
|
|
86
|
+
// the public network (RFC-008 §4: private fetches are files/notes).
|
|
87
|
+
fetch_reference: ['files'],
|
|
88
|
+
// Runs code that may do anything: the class describes the tool.
|
|
89
|
+
code_execution: ['shell'],
|
|
90
|
+
// Built-in modules.
|
|
91
|
+
'discord--*': ['comms'],
|
|
92
|
+
'history--*': ['memory'],
|
|
93
|
+
'workspace--*': ['files'],
|
|
94
|
+
'health--*': ['control'],
|
|
95
|
+
'api--*': ['control'],
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Read a server's class declaration from a tool definition's `_meta`.
|
|
99
|
+
* Returns the known classes it names (deduplicated, in order), or undefined
|
|
100
|
+
* when it names none — which makes the tool unclassed. Unknown strings are
|
|
101
|
+
* ignored for policy and logged (RFC-008 §3, vectors 3 and 4); a non-array
|
|
102
|
+
* value is malformed and ignored the same way.
|
|
103
|
+
*/
|
|
104
|
+
export function parseDeclaredClasses(meta, toolName = '(unnamed)') {
|
|
105
|
+
if (!meta || typeof meta !== 'object')
|
|
106
|
+
return undefined;
|
|
107
|
+
const raw = meta[TOOL_CLASS_META_KEY];
|
|
108
|
+
if (raw === undefined)
|
|
109
|
+
return undefined;
|
|
110
|
+
if (!Array.isArray(raw)) {
|
|
111
|
+
console.error(`[mcpl] ${toolName}: _meta["${TOOL_CLASS_META_KEY}"] is not an array — treated as unclassed`);
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
const out = [];
|
|
115
|
+
for (const value of raw) {
|
|
116
|
+
if (isToolClass(value)) {
|
|
117
|
+
if (!out.includes(value))
|
|
118
|
+
out.push(value);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
console.error(`[mcpl] ${toolName}: unknown tool class ${JSON.stringify(value)} ignored (RFC-008 §3)`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return out.length > 0 ? out : undefined;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Validate a pattern → classes table from configuration. Unknown class
|
|
128
|
+
* strings are dropped with a diagnostic; an entry left with no class is
|
|
129
|
+
* dropped entirely (it cannot classify anything).
|
|
130
|
+
*/
|
|
131
|
+
export function normalizeClassTable(table, label) {
|
|
132
|
+
if (!table)
|
|
133
|
+
return [];
|
|
134
|
+
const out = [];
|
|
135
|
+
for (const [pattern, classes] of Object.entries(table)) {
|
|
136
|
+
const known = [];
|
|
137
|
+
for (const c of Array.isArray(classes) ? classes : []) {
|
|
138
|
+
if (isToolClass(c)) {
|
|
139
|
+
if (!known.includes(c))
|
|
140
|
+
known.push(c);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
console.error(`[mcpl] ${label}["${pattern}"]: unknown tool class ${JSON.stringify(c)} ignored`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (known.length > 0)
|
|
147
|
+
out.push([pattern, known]);
|
|
148
|
+
}
|
|
149
|
+
return out;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Compute a tool's effective class (RFC-008 §5.1). `overrides` and `host`
|
|
153
|
+
* are ordered pattern tables (first matching pattern wins within a source);
|
|
154
|
+
* the first SOURCE that yields a class wins entirely — sources never merge,
|
|
155
|
+
* so an override can tighten or correct a server's declaration.
|
|
156
|
+
*/
|
|
157
|
+
export function resolveToolClass(toolName, declared, tables) {
|
|
158
|
+
for (const [pattern, classes] of tables.overrides) {
|
|
159
|
+
if (globMatch(pattern, toolName))
|
|
160
|
+
return { classes: [...classes], source: 'override' };
|
|
161
|
+
}
|
|
162
|
+
for (const [pattern, classes] of tables.host) {
|
|
163
|
+
if (globMatch(pattern, toolName))
|
|
164
|
+
return { classes: [...classes], source: 'host' };
|
|
165
|
+
}
|
|
166
|
+
if (declared && declared.length > 0)
|
|
167
|
+
return { classes: [...declared], source: 'server' };
|
|
168
|
+
return { classes: [], source: 'none' };
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=tool-classes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-classes.js","sourceRoot":"","sources":["../../../src/mcpl/tool-classes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,OAAO;IACP,QAAQ;IACR,OAAO;IACP,OAAO;IACP,OAAO;IACP,KAAK;IACL,UAAU;IACV,OAAO;IACP,MAAM;IACN,SAAS;CACD,CAAC;AAIX,MAAM,SAAS,GAAwB,IAAI,GAAG,CAAC,YAAY,CAAC,CAAC;AAE7D,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AAC3D,CAAC;AAED,2EA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,QAAQ,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,EAAE,OAAO,EAAE,CAAC,GAAG,QAAQ,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;IACzF,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The portable pattern grammar of MCPL RFC-007 §6.2, used for `tools/observe`
|
|
3
|
+
* filters and (RFC-007 §17 open question 2) for this host's own tool-lifecycle
|
|
4
|
+
* narrowing and tool-class tables:
|
|
5
|
+
*
|
|
6
|
+
* - `*` matches any sequence of zero or more characters;
|
|
7
|
+
* - every other character matches itself (no escapes, no other metachars);
|
|
8
|
+
* - matching is against the whole string, case-sensitive.
|
|
9
|
+
*
|
|
10
|
+
* Patterns are server-supplied, so matching must not backtrack without bound
|
|
11
|
+
* (RFC-007 §10 "Matching cost"). This is the classic two-pointer wildcard
|
|
12
|
+
* match: it remembers only the most recent `*`, so it runs in
|
|
13
|
+
* O(pattern × subject) worst case and never recurses.
|
|
14
|
+
*/
|
|
15
|
+
export declare function globMatch(pattern: string, subject: string): boolean;
|
|
16
|
+
//# sourceMappingURL=tool-glob.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-glob.d.ts","sourceRoot":"","sources":["../../../src/mcpl/tool-glob.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAqBnE"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The portable pattern grammar of MCPL RFC-007 §6.2, used for `tools/observe`
|
|
3
|
+
* filters and (RFC-007 §17 open question 2) for this host's own tool-lifecycle
|
|
4
|
+
* narrowing and tool-class tables:
|
|
5
|
+
*
|
|
6
|
+
* - `*` matches any sequence of zero or more characters;
|
|
7
|
+
* - every other character matches itself (no escapes, no other metachars);
|
|
8
|
+
* - matching is against the whole string, case-sensitive.
|
|
9
|
+
*
|
|
10
|
+
* Patterns are server-supplied, so matching must not backtrack without bound
|
|
11
|
+
* (RFC-007 §10 "Matching cost"). This is the classic two-pointer wildcard
|
|
12
|
+
* match: it remembers only the most recent `*`, so it runs in
|
|
13
|
+
* O(pattern × subject) worst case and never recurses.
|
|
14
|
+
*/
|
|
15
|
+
export function globMatch(pattern, subject) {
|
|
16
|
+
let p = 0;
|
|
17
|
+
let s = 0;
|
|
18
|
+
let star = -1;
|
|
19
|
+
let mark = 0;
|
|
20
|
+
while (s < subject.length) {
|
|
21
|
+
if (p < pattern.length && pattern[p] !== '*' && pattern[p] === subject[s]) {
|
|
22
|
+
p++;
|
|
23
|
+
s++;
|
|
24
|
+
}
|
|
25
|
+
else if (p < pattern.length && pattern[p] === '*') {
|
|
26
|
+
star = p++;
|
|
27
|
+
mark = s;
|
|
28
|
+
}
|
|
29
|
+
else if (star !== -1) {
|
|
30
|
+
p = star + 1;
|
|
31
|
+
s = ++mark;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
while (p < pattern.length && pattern[p] === '*')
|
|
38
|
+
p++;
|
|
39
|
+
return p === pattern.length;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=tool-glob.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-glob.js","sourceRoot":"","sources":["../../../src/mcpl/tool-glob.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,SAAS,CAAC,OAAe,EAAE,OAAe;IACxD,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,IAAI,IAAI,GAAG,CAAC,CAAC,CAAC;IACd,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;QAC1B,IAAI,CAAC,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;YAC1E,CAAC,EAAE,CAAC;YACJ,CAAC,EAAE,CAAC;QACN,CAAC;aAAM,IAAI,CAAC,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;YACpD,IAAI,GAAG,CAAC,EAAE,CAAC;YACX,IAAI,GAAG,CAAC,CAAC;QACX,CAAC;aAAM,IAAI,IAAI,KAAK,CAAC,CAAC,EAAE,CAAC;YACvB,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC;YACb,CAAC,GAAG,EAAE,IAAI,CAAC;QACb,CAAC;aAAM,CAAC;YACN,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IACD,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG;QAAE,CAAC,EAAE,CAAC;IACrD,OAAO,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC;AAC9B,CAAC"}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool lifecycle (MCPL RFC-007): `tools/lifecycle` notifications about the
|
|
3
|
+
* agent's tool calls, and the `tools/observe` filter a server sets on them.
|
|
4
|
+
*
|
|
5
|
+
* Authority is the grant plus host narrowing; a server's filter is interest
|
|
6
|
+
* and only ever narrows. Per call and connection the host decides, in order
|
|
7
|
+
* (RFC-007 §6.4):
|
|
8
|
+
*
|
|
9
|
+
* 1. reported at all? grant `toolLifecycle.observe` + its narrowing
|
|
10
|
+
* 2. reported to this server? filter: first matching rule and its `report`
|
|
11
|
+
* (no filter → yes)
|
|
12
|
+
* 3. arguments requested? that rule's `input` (no filter → NO)
|
|
13
|
+
* 4. arguments allowed? grant `toolLifecycle.inputs` + its narrowing,
|
|
14
|
+
* and never for `comms` or unclassed tools
|
|
15
|
+
* 5. which fields, how large? the rule's field selection, then the bound
|
|
16
|
+
*
|
|
17
|
+
* Tool RESULTS are never carried — no field for them exists here.
|
|
18
|
+
*
|
|
19
|
+
* Delivery is best-effort like `inference/lifecycle` (SPEC §10.5): one
|
|
20
|
+
* terminal is attempted per opened call, to exactly the connections the
|
|
21
|
+
* opening went to, unless their grant or narrowing no longer covers the call
|
|
22
|
+
* (RFC-007 §4.5). A filter change never suppresses a terminal (§6.5).
|
|
23
|
+
*/
|
|
24
|
+
import { CapabilityGrant } from './capability-grant.js';
|
|
25
|
+
import { type ToolClass } from './tool-classes.js';
|
|
26
|
+
export declare const TOOL_LIFECYCLE_OBSERVE = "toolLifecycle.observe";
|
|
27
|
+
export declare const TOOL_LIFECYCLE_INPUTS = "toolLifecycle.inputs";
|
|
28
|
+
export type ToolPhase = 'pending' | 'started' | 'completed' | 'failed' | 'aborted';
|
|
29
|
+
/** `tools/lifecycle` params (Host → Server, Notification). RFC-007 §3. */
|
|
30
|
+
export interface ToolLifecycleParams {
|
|
31
|
+
toolCallId: string;
|
|
32
|
+
inferenceId: string;
|
|
33
|
+
conversationId: string;
|
|
34
|
+
tool: string;
|
|
35
|
+
class: ToolClass[];
|
|
36
|
+
serverId?: string;
|
|
37
|
+
serverTool?: string;
|
|
38
|
+
phase: ToolPhase;
|
|
39
|
+
input?: Record<string, unknown>;
|
|
40
|
+
inputAltered?: boolean;
|
|
41
|
+
inputWithheld?: boolean;
|
|
42
|
+
isError?: boolean;
|
|
43
|
+
durationMs?: number;
|
|
44
|
+
}
|
|
45
|
+
export interface ToolObserveMatch {
|
|
46
|
+
tool?: string;
|
|
47
|
+
serverTool?: string;
|
|
48
|
+
serverId?: string;
|
|
49
|
+
conversationId?: string;
|
|
50
|
+
class?: ToolClass;
|
|
51
|
+
}
|
|
52
|
+
/** One normalized `tools/observe` rule (RFC-007 §6.1). */
|
|
53
|
+
export interface ToolObserveRule {
|
|
54
|
+
match: ToolObserveMatch;
|
|
55
|
+
report: boolean;
|
|
56
|
+
/** false = metadata only; true = all arguments; string[] = field paths. */
|
|
57
|
+
input: boolean | string[];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A narrowing attached to one `toolLifecycle.*` grant entry (RFC-007 §4.3).
|
|
61
|
+
* A call is inside it when it satisfies EVERY key stated. Patterns use the
|
|
62
|
+
* RFC-007 §6.2 grammar.
|
|
63
|
+
*/
|
|
64
|
+
export interface ToolLifecycleNarrowing {
|
|
65
|
+
/** Patterns over the model-facing tool name (`computer--*`). */
|
|
66
|
+
tools?: string[];
|
|
67
|
+
/** The tool's effective class must intersect this set. `'default'` is
|
|
68
|
+
* DEFAULT_INPUT_CLASSES (computer, shell, files, web, media, body). */
|
|
69
|
+
classes?: ToolClass[] | 'default';
|
|
70
|
+
/** Patterns over `conversationId` (the agent name in this host). */
|
|
71
|
+
conversations?: string[];
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Per-server tool-lifecycle policy (`McplServerConfig.toolLifecycle`).
|
|
75
|
+
*
|
|
76
|
+
* Both capability paths are DENIED BY DEFAULT. Stating `observe` (even as
|
|
77
|
+
* `{}`) or `inputs` here is the operator's explicit grant of that path, as
|
|
78
|
+
* is naming it in `enabledCapabilities`. `inputs` is never unconditional:
|
|
79
|
+
* without at least one `tools` or `classes` term it delivers no arguments
|
|
80
|
+
* (RFC-007 §4.3).
|
|
81
|
+
*/
|
|
82
|
+
export interface ToolLifecycleConfig {
|
|
83
|
+
observe?: ToolLifecycleNarrowing;
|
|
84
|
+
inputs?: ToolLifecycleNarrowing;
|
|
85
|
+
/** Serialized-size bound for `input` per notification. Default 16 KiB. */
|
|
86
|
+
maxInputBytes?: number;
|
|
87
|
+
}
|
|
88
|
+
export declare const DEFAULT_MAX_INPUT_BYTES: number;
|
|
89
|
+
/** Accepted sizes for a `tools/observe` request (RFC-007 §6.6 asks hosts to
|
|
90
|
+
* accept at least 64 rules, 64 paths per rule, 256-character strings). */
|
|
91
|
+
export declare const TOOL_OBSERVE_LIMITS: {
|
|
92
|
+
readonly rules: 256;
|
|
93
|
+
readonly pathsPerRule: 256;
|
|
94
|
+
readonly stringLength: 256;
|
|
95
|
+
};
|
|
96
|
+
export type ToolObserveParseResult = {
|
|
97
|
+
ok: true;
|
|
98
|
+
rules: ToolObserveRule[] | null;
|
|
99
|
+
} | {
|
|
100
|
+
ok: false;
|
|
101
|
+
message: string;
|
|
102
|
+
data?: Record<string, unknown>;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Validate `tools/observe` params. `rules` absent or null clears the filter
|
|
106
|
+
* (`{ok, rules: null}`); `[]` is a valid filter that reports nothing. Unknown
|
|
107
|
+
* members are REJECTED, not ignored: ignoring an unknown `match` member would
|
|
108
|
+
* make a rule match more than its author wrote.
|
|
109
|
+
*/
|
|
110
|
+
export declare function parseToolObserveParams(params: unknown): ToolObserveParseResult;
|
|
111
|
+
/** What the host knows about one call, shared by every connection. */
|
|
112
|
+
export interface ToolCallDescriptor {
|
|
113
|
+
/** Host-unique on every connection (RFC-007 §3). */
|
|
114
|
+
toolCallId: string;
|
|
115
|
+
inferenceId: string;
|
|
116
|
+
conversationId: string;
|
|
117
|
+
tool: string;
|
|
118
|
+
class: ToolClass[];
|
|
119
|
+
serverId?: string;
|
|
120
|
+
serverTool?: string;
|
|
121
|
+
input: unknown;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* `observe` narrowing: absent means no narrowing (the grant is enough). A
|
|
125
|
+
* value that is not a narrowing object (`false`, `null`, a string) admits
|
|
126
|
+
* nothing: a setting that looks like "off" must never read as "everything".
|
|
127
|
+
*/
|
|
128
|
+
export declare function observeAdmits(config: ToolLifecycleConfig | undefined, call: ToolCallDescriptor): boolean;
|
|
129
|
+
/**
|
|
130
|
+
* Does `inputs` narrowing say this call has no tool/class term at all? Such
|
|
131
|
+
* an entry is unconditional and therefore treated as narrowed to NO tools
|
|
132
|
+
* (RFC-007 §4.3 — the widest form is not producible by omission).
|
|
133
|
+
*/
|
|
134
|
+
export declare function inputsNarrowingIsUnconditional(n: ToolLifecycleNarrowing | undefined): boolean;
|
|
135
|
+
/** Class exclusions that no narrowing overrides (RFC-007 §4.3, §5.4). */
|
|
136
|
+
export declare function inputsExcludedByClass(call: ToolCallDescriptor): boolean;
|
|
137
|
+
export declare function inputsAdmit(config: ToolLifecycleConfig | undefined, call: ToolCallDescriptor): boolean;
|
|
138
|
+
export declare function ruleMatches(match: ToolObserveMatch, call: ToolCallDescriptor): boolean;
|
|
139
|
+
/**
|
|
140
|
+
* Select field paths from an arguments object. `.` descends into nested
|
|
141
|
+
* objects; a path ending on an object or array selects it whole; a path that
|
|
142
|
+
* passes through a non-object or names a missing member selects nothing.
|
|
143
|
+
* Selected members keep their place in the structure. Only OWN properties
|
|
144
|
+
* are read and the output is built from null-prototype objects, so a path
|
|
145
|
+
* like `__proto__.x` can neither read nor write a prototype.
|
|
146
|
+
*/
|
|
147
|
+
export declare function selectFields(input: Record<string, unknown>, paths: readonly string[]): Record<string, unknown>;
|
|
148
|
+
/**
|
|
149
|
+
* Bound `value` to `maxBytes` of serialized JSON (RFC-007 §5.2): first by
|
|
150
|
+
* replacing the longest strings with prefixes of themselves, then by removing
|
|
151
|
+
* the largest members. The result is always a JSON object. Returns null when
|
|
152
|
+
* nothing meaningful fits — the caller withholds instead.
|
|
153
|
+
*/
|
|
154
|
+
export declare function boundInput(value: Record<string, unknown>, maxBytes: number): {
|
|
155
|
+
value: Record<string, unknown>;
|
|
156
|
+
altered: boolean;
|
|
157
|
+
} | null;
|
|
158
|
+
/** What the emitter needs from a connection. */
|
|
159
|
+
export interface ToolLifecycleObserver {
|
|
160
|
+
id: string;
|
|
161
|
+
grant?: CapabilityGrant;
|
|
162
|
+
toolObserveFilter?: ToolObserveRule[] | null;
|
|
163
|
+
/** Increments at every transport boundary (reconnect). Terminals go only
|
|
164
|
+
* to the epoch the opening went to. Absent = 0. */
|
|
165
|
+
transportEpoch?: number;
|
|
166
|
+
sendToolLifecycle(params: ToolLifecycleParams): void;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* The opening notification (`pending` or `started`) this connection should
|
|
170
|
+
* receive for `call`, or null when it receives nothing. Steps 1–5 of
|
|
171
|
+
* RFC-007 §6.4.
|
|
172
|
+
*/
|
|
173
|
+
export declare function openingFor(observer: ToolLifecycleObserver, config: ToolLifecycleConfig | undefined, call: ToolCallDescriptor, phase: 'pending' | 'started'): ToolLifecycleParams | null;
|
|
174
|
+
/** Does this connection still get the terminal for a call it was opened to? */
|
|
175
|
+
export declare function terminalStillAllowed(observer: ToolLifecycleObserver, config: ToolLifecycleConfig | undefined, call: ToolCallDescriptor): boolean;
|
|
176
|
+
export interface ToolLifecycleHost {
|
|
177
|
+
/** Every live connection that might observe. */
|
|
178
|
+
observers(): Iterable<ToolLifecycleObserver>;
|
|
179
|
+
/** Host policy for one connection. */
|
|
180
|
+
configFor(serverId: string): ToolLifecycleConfig | undefined;
|
|
181
|
+
/** Class and provider for a model-facing tool name. */
|
|
182
|
+
describe(tool: string): {
|
|
183
|
+
class: ToolClass[];
|
|
184
|
+
serverId?: string;
|
|
185
|
+
serverTool?: string;
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
export declare class ToolLifecycleEmitter {
|
|
189
|
+
private readonly host;
|
|
190
|
+
private readonly now;
|
|
191
|
+
/** Opened calls awaiting their terminal, keyed by (agent, model call id). */
|
|
192
|
+
private readonly calls;
|
|
193
|
+
private readonly recentIds;
|
|
194
|
+
private readonly recentOrder;
|
|
195
|
+
private mintSeq;
|
|
196
|
+
constructor(host: ToolLifecycleHost, now?: () => number);
|
|
197
|
+
/** Nothing observes: skip all work on the hot path. */
|
|
198
|
+
private anyObserver;
|
|
199
|
+
/**
|
|
200
|
+
* A host-unique id for a call (RFC-007 §3): the model's own only where the
|
|
201
|
+
* provider guarantees it unique and it was not reported recently; minted
|
|
202
|
+
* otherwise. Minted ids carry a per-process counter, so they never repeat.
|
|
203
|
+
*/
|
|
204
|
+
private hostCallId;
|
|
205
|
+
/**
|
|
206
|
+
* A model-issued call is about to be dispatched. Recorded, keyed by
|
|
207
|
+
* (agent, model call id) — never matched through the trace stream, so two
|
|
208
|
+
* agents' identical short ids cannot cross — but nothing is sent yet: the
|
|
209
|
+
* host may still refuse it (refuse()) before it executes.
|
|
210
|
+
*/
|
|
211
|
+
register(agentName: string, inferenceId: string, call: {
|
|
212
|
+
id: string;
|
|
213
|
+
name: string;
|
|
214
|
+
input: unknown;
|
|
215
|
+
}): void;
|
|
216
|
+
/**
|
|
217
|
+
* The host refused the call before executing it — its provider is gone,
|
|
218
|
+
* host tool policy denies it, a conversation-bound agent reached outside
|
|
219
|
+
* its channel. Called from the refusal site itself, synchronously within
|
|
220
|
+
* dispatch, so the call is forgotten before open() would send anything:
|
|
221
|
+
* a refused call produces no events (RFC-007 §3).
|
|
222
|
+
*/
|
|
223
|
+
refuse(agentName: string, callId: string): void;
|
|
224
|
+
/**
|
|
225
|
+
* Dispatch returned and the call was not refused: execution has begun.
|
|
226
|
+
* Send `started` to every connection that should see it. Refusal sites
|
|
227
|
+
* run synchronously inside dispatch, before this.
|
|
228
|
+
*/
|
|
229
|
+
open(agentName: string, callId: string): void;
|
|
230
|
+
/**
|
|
231
|
+
* The host could not obtain a result for this call (its dispatch threw,
|
|
232
|
+
* the provider's transport failed, the request timed out). Its terminal
|
|
233
|
+
* will be `failed`. An error RESULT returned by the tool is not this: it
|
|
234
|
+
* is `completed` with `isError` (RFC-007 §3).
|
|
235
|
+
*/
|
|
236
|
+
markDispatchFailure(agentName: string, callId: string): void;
|
|
237
|
+
private terminate;
|
|
238
|
+
/** A tool result reached the host: the call's terminal. */
|
|
239
|
+
onResult(agentName: string, callId: string, result: {
|
|
240
|
+
success?: boolean;
|
|
241
|
+
isError?: boolean;
|
|
242
|
+
} | undefined): void;
|
|
243
|
+
/**
|
|
244
|
+
* A stream ended: its calls still open were cancelled before a result.
|
|
245
|
+
* Scoped to the inference ids that stream minted, so a successor stream
|
|
246
|
+
* for the same agent (a budget restart overlapping this one's teardown)
|
|
247
|
+
* keeps its live calls. A result arriving later finds nothing.
|
|
248
|
+
*/
|
|
249
|
+
abortOpen(agentName: string, inferenceIds: Iterable<string>): void;
|
|
250
|
+
/** For tests and diagnostics. */
|
|
251
|
+
get openCount(): number;
|
|
252
|
+
}
|
|
253
|
+
//# sourceMappingURL=tool-lifecycle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-lifecycle.d.ts","sourceRoot":"","sources":["../../../src/mcpl/tool-lifecycle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,EAAsC,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEvF,eAAO,MAAM,sBAAsB,0BAA0B,CAAC;AAC9D,eAAO,MAAM,qBAAqB,yBAAyB,CAAC;AAM5D,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEnF,0EAA0E;AAC1E,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,SAAS,EAAE,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,SAAS,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,aAA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