@animalabs/agent-framework 0.19.0 → 0.21.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 +1175 -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/conversation-router.d.ts +8 -6
- package/dist/src/mcpl/conversation-router.d.ts.map +1 -1
- package/dist/src/mcpl/conversation-router.js +12 -6
- package/dist/src/mcpl/conversation-router.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/references.d.ts.map +1 -1
- package/dist/src/mcpl/references.js +9 -4
- package/dist/src/mcpl/references.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 +607 -0
- package/dist/src/mcpl/tool-lifecycle.js.map +1 -0
- package/dist/src/mcpl/transport.d.ts +15 -0
- package/dist/src/mcpl/transport.d.ts.map +1 -1
- package/dist/src/mcpl/transport.js +65 -1
- package/dist/src/mcpl/transport.js.map +1 -1
- package/dist/src/mcpl/types.d.ts +68 -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/conversation-router.test.js +33 -19
- package/dist/test/conversation-router.test.js.map +1 -1
- package/dist/test/conversation-routing.test.js +89 -0
- package/dist/test/conversation-routing.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 +158 -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-reference-fields.test.d.ts +2 -0
- package/dist/test/mcpl-reference-fields.test.d.ts.map +1 -0
- package/dist/test/mcpl-reference-fields.test.js +82 -0
- package/dist/test/mcpl-reference-fields.test.js.map +1 -0
- 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/tools-observe-parser-conformance.test.d.ts +2 -0
- package/dist/test/tools-observe-parser-conformance.test.d.ts.map +1 -0
- package/dist/test/tools-observe-parser-conformance.test.js +129 -0
- package/dist/test/tools-observe-parser-conformance.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 +1207 -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/conversation-router.ts +12 -8
- 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/references.ts +11 -3
- 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 +745 -0
- package/src/mcpl/transport.ts +67 -1
- package/src/mcpl/types.ts +71 -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,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-code-point 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,Y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