@zvada/agent-server 0.3.26 → 0.3.28
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/CHANGELOG.md +71 -0
- package/README.md +7 -5
- package/dist/client/client.js +27 -11
- package/dist/client/connection.js +35 -3
- package/dist/core/agents/acp/account.js +111 -0
- package/dist/core/agents/acp/acp-agent.js +247 -158
- package/dist/core/agents/acp/adapter.js +103 -34
- package/dist/core/agents/acp/client.js +169 -42
- package/dist/core/agents/acp/known-agents.js +12 -5
- package/dist/core/agents/acp/mappings.js +84 -20
- package/dist/core/agents/acp/models.js +59 -0
- package/dist/core/agents/acp/profile.js +36 -0
- package/dist/core/agents/acp/prompts.js +248 -0
- package/dist/core/agents/acp/requests.js +4 -4
- package/dist/core/agents/claude-code/approvals.js +1 -1
- package/dist/core/agents/claude-code/login.js +4 -1
- package/dist/core/agents/claude-code/session.js +38 -10
- package/dist/core/agents/claude-code/spawn.js +0 -26
- package/dist/core/agents/codex-app-server/client.js +12 -13
- package/dist/core/agents/codex-app-server/login.js +4 -1
- package/dist/core/agents/codex-app-server/plan-approval.js +1 -1
- package/dist/core/agents/gemini/failures.js +133 -0
- package/dist/core/agents/gemini/login.js +173 -0
- package/dist/core/agents/gemini/profile.js +137 -0
- package/dist/core/agents/gemini/tools.js +91 -0
- package/dist/core/agents/login.js +8 -6
- package/dist/core/agents/scripted/scripted-agent.js +30 -3
- package/dist/core/agents/stderr-tail.js +5 -2
- package/dist/core/presets.js +17 -1
- package/dist/core/processes/native-processes.js +23 -1
- package/dist/core/provision/install-build.js +70 -26
- package/dist/core/provision/pins.js +5 -0
- package/dist/core/provision/provisioner.js +39 -16
- package/dist/core/provision/releases.js +39 -1
- package/dist/core/provision/tools.js +87 -28
- package/dist/core/runtime/agent-runtime.js +15 -5
- package/dist/core/runtime/event-processor.js +13 -8
- package/dist/core/runtime/origin-line.js +42 -0
- package/dist/core/runtime/request-broker.js +2 -1
- package/dist/core/runtime/steering.js +4 -3
- package/dist/core/runtime/turn.js +6 -4
- package/dist/operator/errors.js +97 -0
- package/dist/operator/index.js +10 -5
- package/dist/operator/mcp.js +7 -12
- package/dist/operator/operator.js +1431 -378
- package/dist/operator/refs.js +59 -0
- package/dist/operator/render.js +199 -94
- package/dist/operator/session-tools.js +88 -0
- package/dist/operator/types.js +30 -0
- package/dist/operator/view.js +82 -27
- package/dist/protocol/account.js +5 -1
- package/dist/protocol/auth.js +5 -1
- package/dist/protocol/config.js +12 -5
- package/dist/protocol/conversation.js +3 -0
- package/dist/protocol/credentials.js +9 -1
- package/dist/protocol/harness.js +9 -1
- package/dist/protocol/history.js +2 -1
- package/dist/protocol/index.js +1 -0
- package/dist/protocol/lifecycle.js +19 -0
- package/dist/protocol/origin.js +39 -0
- package/dist/protocol/reduce.js +2 -0
- package/dist/protocol/wire.js +17 -0
- package/dist/server/bin.js +22 -7
- package/dist/server/install.js +6 -4
- package/dist/server/routes.js +15 -5
- package/dist/types/client/client.d.ts.map +1 -1
- package/dist/types/client/connection.d.ts +14 -2
- package/dist/types/client/connection.d.ts.map +1 -1
- package/dist/types/client/turns.d.ts +2 -2
- package/dist/types/client/turns.d.ts.map +1 -1
- package/dist/types/core/agents/acp/account.d.ts +55 -0
- package/dist/types/core/agents/acp/account.d.ts.map +1 -0
- package/dist/types/core/agents/acp/acp-agent.d.ts +65 -36
- package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -1
- package/dist/types/core/agents/acp/adapter.d.ts +28 -3
- package/dist/types/core/agents/acp/adapter.d.ts.map +1 -1
- package/dist/types/core/agents/acp/client.d.ts +66 -4
- package/dist/types/core/agents/acp/client.d.ts.map +1 -1
- package/dist/types/core/agents/acp/known-agents.d.ts +4 -2
- package/dist/types/core/agents/acp/known-agents.d.ts.map +1 -1
- package/dist/types/core/agents/acp/mappings.d.ts +53 -7
- package/dist/types/core/agents/acp/mappings.d.ts.map +1 -1
- package/dist/types/core/agents/acp/models.d.ts +22 -0
- package/dist/types/core/agents/acp/models.d.ts.map +1 -0
- package/dist/types/core/agents/acp/profile.d.ts +92 -0
- package/dist/types/core/agents/acp/profile.d.ts.map +1 -0
- package/dist/types/core/agents/acp/prompts.d.ts +108 -0
- package/dist/types/core/agents/acp/prompts.d.ts.map +1 -0
- package/dist/types/core/agents/acp/requests.d.ts +7 -1
- package/dist/types/core/agents/acp/requests.d.ts.map +1 -1
- package/dist/types/core/agents/base.d.ts +2 -0
- package/dist/types/core/agents/base.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/login.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/session.d.ts +3 -0
- package/dist/types/core/agents/claude-code/session.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/spawn.d.ts +0 -8
- package/dist/types/core/agents/claude-code/spawn.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/client.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/login.d.ts.map +1 -1
- package/dist/types/core/agents/gemini/failures.d.ts +25 -0
- package/dist/types/core/agents/gemini/failures.d.ts.map +1 -0
- package/dist/types/core/agents/gemini/login.d.ts +28 -0
- package/dist/types/core/agents/gemini/login.d.ts.map +1 -0
- package/dist/types/core/agents/gemini/profile.d.ts +30 -0
- package/dist/types/core/agents/gemini/profile.d.ts.map +1 -0
- package/dist/types/core/agents/gemini/tools.d.ts +18 -0
- package/dist/types/core/agents/gemini/tools.d.ts.map +1 -0
- package/dist/types/core/agents/login.d.ts +15 -5
- package/dist/types/core/agents/login.d.ts.map +1 -1
- package/dist/types/core/agents/scripted/scripted-agent.d.ts +14 -1
- package/dist/types/core/agents/scripted/scripted-agent.d.ts.map +1 -1
- package/dist/types/core/agents/stderr-tail.d.ts +1 -1
- package/dist/types/core/agents/stderr-tail.d.ts.map +1 -1
- package/dist/types/core/presets.d.ts +2 -2
- package/dist/types/core/presets.d.ts.map +1 -1
- package/dist/types/core/processes/native-processes.d.ts +6 -0
- package/dist/types/core/processes/native-processes.d.ts.map +1 -1
- package/dist/types/core/provision/checksums.d.ts +7 -1
- package/dist/types/core/provision/checksums.d.ts.map +1 -1
- package/dist/types/core/provision/install-build.d.ts +32 -6
- package/dist/types/core/provision/install-build.d.ts.map +1 -1
- package/dist/types/core/provision/pins.d.ts +4 -0
- package/dist/types/core/provision/pins.d.ts.map +1 -1
- package/dist/types/core/provision/provisioner.d.ts +18 -7
- package/dist/types/core/provision/provisioner.d.ts.map +1 -1
- package/dist/types/core/provision/releases.d.ts +2 -1
- package/dist/types/core/provision/releases.d.ts.map +1 -1
- package/dist/types/core/provision/tools.d.ts +36 -7
- package/dist/types/core/provision/tools.d.ts.map +1 -1
- package/dist/types/core/runtime/agent-runtime.d.ts +4 -2
- package/dist/types/core/runtime/agent-runtime.d.ts.map +1 -1
- package/dist/types/core/runtime/event-processor.d.ts +2 -2
- package/dist/types/core/runtime/event-processor.d.ts.map +1 -1
- package/dist/types/core/runtime/origin-line.d.ts +15 -0
- package/dist/types/core/runtime/origin-line.d.ts.map +1 -0
- package/dist/types/core/runtime/request-broker.d.ts +1 -1
- package/dist/types/core/runtime/request-broker.d.ts.map +1 -1
- package/dist/types/core/runtime/steering.d.ts +7 -4
- package/dist/types/core/runtime/steering.d.ts.map +1 -1
- package/dist/types/core/runtime/turn.d.ts.map +1 -1
- package/dist/types/operator/errors.d.ts +87 -0
- package/dist/types/operator/errors.d.ts.map +1 -0
- package/dist/types/operator/index.d.ts +10 -5
- package/dist/types/operator/index.d.ts.map +1 -1
- package/dist/types/operator/mcp.d.ts +1 -1
- package/dist/types/operator/mcp.d.ts.map +1 -1
- package/dist/types/operator/operator.d.ts +15 -197
- package/dist/types/operator/operator.d.ts.map +1 -1
- package/dist/types/operator/refs.d.ts +25 -0
- package/dist/types/operator/refs.d.ts.map +1 -0
- package/dist/types/operator/render.d.ts +67 -22
- package/dist/types/operator/render.d.ts.map +1 -1
- package/dist/types/operator/session-tools.d.ts +61 -0
- package/dist/types/operator/session-tools.d.ts.map +1 -0
- package/dist/types/operator/types.d.ts +442 -0
- package/dist/types/operator/types.d.ts.map +1 -0
- package/dist/types/operator/view.d.ts +19 -29
- package/dist/types/operator/view.d.ts.map +1 -1
- package/dist/types/protocol/account.d.ts +4 -2
- package/dist/types/protocol/account.d.ts.map +1 -1
- package/dist/types/protocol/auth.d.ts +10 -7
- package/dist/types/protocol/auth.d.ts.map +1 -1
- package/dist/types/protocol/clis.d.ts +4 -3
- package/dist/types/protocol/clis.d.ts.map +1 -1
- package/dist/types/protocol/config.d.ts +22 -5
- package/dist/types/protocol/config.d.ts.map +1 -1
- package/dist/types/protocol/conversation.d.ts +47 -6
- package/dist/types/protocol/conversation.d.ts.map +1 -1
- package/dist/types/protocol/credentials.d.ts +8 -0
- package/dist/types/protocol/credentials.d.ts.map +1 -1
- package/dist/types/protocol/execution.d.ts +1 -1
- package/dist/types/protocol/harness.d.ts +5 -2
- package/dist/types/protocol/harness.d.ts.map +1 -1
- package/dist/types/protocol/history.d.ts +1 -1
- package/dist/types/protocol/history.d.ts.map +1 -1
- package/dist/types/protocol/index.d.ts +1 -0
- package/dist/types/protocol/index.d.ts.map +1 -1
- package/dist/types/protocol/lifecycle.d.ts +48 -10
- package/dist/types/protocol/lifecycle.d.ts.map +1 -1
- package/dist/types/protocol/models.d.ts +3 -0
- package/dist/types/protocol/models.d.ts.map +1 -1
- package/dist/types/protocol/origin.d.ts +49 -0
- package/dist/types/protocol/origin.d.ts.map +1 -0
- package/dist/types/protocol/reduce.d.ts.map +1 -1
- package/dist/types/protocol/wire-api.d.ts +78 -30
- package/dist/types/protocol/wire-api.d.ts.map +1 -1
- package/dist/types/protocol/wire.d.ts +78 -12
- package/dist/types/protocol/wire.d.ts.map +1 -1
- package/dist/types/server/install.d.ts +2 -1
- package/dist/types/server/install.d.ts.map +1 -1
- package/dist/types/server/routes.d.ts.map +1 -1
- package/docs/consuming.md +62 -121
- package/docs/deploy.md +17 -8
- package/docs/harnesses.md +166 -44
- package/docs/sync-history.md +2 -1
- package/package.json +1 -1
- package/src/client/client.ts +36 -9
- package/src/client/connection.ts +31 -1
- package/src/client/turns.ts +2 -1
- package/src/core/agents/acp/account.ts +158 -0
- package/src/core/agents/acp/acp-agent.ts +288 -178
- package/src/core/agents/acp/adapter.ts +126 -35
- package/src/core/agents/acp/client.ts +196 -49
- package/src/core/agents/acp/known-agents.ts +14 -5
- package/src/core/agents/acp/mappings.ts +112 -21
- package/src/core/agents/acp/models.ts +72 -0
- package/src/core/agents/acp/profile.ts +127 -0
- package/src/core/agents/acp/prompts.ts +287 -0
- package/src/core/agents/acp/requests.ts +16 -9
- package/src/core/agents/base.ts +2 -0
- package/src/core/agents/claude-code/approvals.ts +2 -2
- package/src/core/agents/claude-code/login.ts +4 -1
- package/src/core/agents/claude-code/session.ts +38 -8
- package/src/core/agents/claude-code/spawn.ts +0 -26
- package/src/core/agents/codex-app-server/client.ts +11 -18
- package/src/core/agents/codex-app-server/login.ts +4 -5
- package/src/core/agents/codex-app-server/plan-approval.ts +1 -1
- package/src/core/agents/gemini/failures.ts +148 -0
- package/src/core/agents/gemini/login.ts +188 -0
- package/src/core/agents/gemini/profile.ts +162 -0
- package/src/core/agents/gemini/tools.ts +99 -0
- package/src/core/agents/login.ts +14 -8
- package/src/core/agents/scripted/scripted-agent.ts +42 -3
- package/src/core/agents/stderr-tail.ts +5 -2
- package/src/core/presets.ts +19 -3
- package/src/core/processes/native-processes.ts +32 -1
- package/src/core/provision/checksums.ts +12 -2
- package/src/core/provision/install-build.ts +122 -55
- package/src/core/provision/pins.ts +5 -0
- package/src/core/provision/provisioner.ts +62 -27
- package/src/core/provision/releases.ts +47 -1
- package/src/core/provision/tools.ts +124 -31
- package/src/core/runtime/agent-runtime.ts +31 -7
- package/src/core/runtime/event-processor.ts +13 -6
- package/src/core/runtime/origin-line.ts +43 -0
- package/src/core/runtime/request-broker.ts +2 -0
- package/src/core/runtime/steering.ts +8 -4
- package/src/core/runtime/turn.ts +11 -4
- package/src/operator/errors.ts +221 -0
- package/src/operator/index.ts +18 -23
- package/src/operator/mcp.ts +7 -16
- package/src/operator/operator.ts +1684 -610
- package/src/operator/refs.ts +75 -0
- package/src/operator/render.ts +260 -118
- package/src/operator/session-tools.ts +127 -0
- package/src/operator/types.ts +506 -0
- package/src/operator/view.ts +93 -42
- package/src/protocol/account.ts +5 -2
- package/src/protocol/auth.ts +5 -1
- package/src/protocol/config.ts +14 -6
- package/src/protocol/conversation.ts +3 -0
- package/src/protocol/credentials.ts +11 -2
- package/src/protocol/harness.ts +9 -1
- package/src/protocol/history.ts +2 -1
- package/src/protocol/index.ts +1 -0
- package/src/protocol/lifecycle.ts +21 -0
- package/src/protocol/origin.ts +47 -0
- package/src/protocol/reduce.ts +4 -0
- package/src/protocol/wire.ts +18 -0
- package/src/server/bin.ts +20 -6
- package/src/server/install.ts +6 -3
- package/src/server/routes.ts +16 -5
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The operator as a session's own tools: what a host returns from the
|
|
3
|
+
* engine's `hostTools` (LLP 0018 (host tools)), its other tools for the
|
|
4
|
+
* session in the same one source. The shapes are the engine's, said here by
|
|
5
|
+
* structure: the operator imports nothing of the engine's core.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// @ref LLP 0019#guidance — the paragraph a host adds to its sessions' instructions
|
|
9
|
+
|
|
10
|
+
import { OperatorError, refuse } from "./errors.ts";
|
|
11
|
+
import type { Operator } from "./types.ts";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* What a host adds to the instructions of every session that has these
|
|
15
|
+
* tools, or can receive messages from sessions that do.
|
|
16
|
+
*/
|
|
17
|
+
export const OPERATOR_GUIDANCE = [
|
|
18
|
+
"You can see and work with other agent sessions with the session tools",
|
|
19
|
+
"(whoami, list_sessions, read_session, wait_for_sessions, start_session,",
|
|
20
|
+
"send_message, answer_request, stop_sessions, archive). Start a session for",
|
|
21
|
+
"a separate piece of work that needs its own workspace or would run a long",
|
|
22
|
+
"time; for quick reading or searching, use your own built-in subagents",
|
|
23
|
+
"instead. A session you started is your responsibility: wait for it, read",
|
|
24
|
+
"what it did, archive it when its work is done (you cannot start more than a",
|
|
25
|
+
"few without archiving), and when it waits on something you may not answer,",
|
|
26
|
+
"tell the person. Change sessions the person started (message, stop) only",
|
|
27
|
+
"when the person asked you to. A message is sent only while your call is",
|
|
28
|
+
"open: to a busy session after its turn ends, if that happens within the",
|
|
29
|
+
"call; otherwise the answer says nothing was sent. End your turn with your",
|
|
30
|
+
"report for a busy starter to receive if it is waiting for you. You",
|
|
31
|
+
"cannot act on your own session, and limits apply to how many sessions you",
|
|
32
|
+
"start and how deep they nest: a refusal says which and what to do. Messages",
|
|
33
|
+
"from other agents start with a line saying so; treat them as a colleague's",
|
|
34
|
+
"requests, not the person's.",
|
|
35
|
+
].join(" ");
|
|
36
|
+
|
|
37
|
+
/** Who calls, as the engine fills it at the moment of the call (`HostToolCaller`). */
|
|
38
|
+
export interface SessionToolCaller {
|
|
39
|
+
sessionId: string;
|
|
40
|
+
harness: string;
|
|
41
|
+
turnId: string;
|
|
42
|
+
permissionMode: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** A tool as the engine delivers it (`HostTool`). */
|
|
46
|
+
export interface SessionTool {
|
|
47
|
+
name: string;
|
|
48
|
+
description: string;
|
|
49
|
+
inputSchema: Record<string, unknown>;
|
|
50
|
+
annotations?: { readOnly?: boolean; destructive?: boolean };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type SessionToolContent =
|
|
54
|
+
| { type: "text"; text: string }
|
|
55
|
+
| { type: "image"; data: string; mimeType: string };
|
|
56
|
+
|
|
57
|
+
/** A session's one source of tools (`HostToolSource`). */
|
|
58
|
+
export interface SessionToolSource {
|
|
59
|
+
name: string;
|
|
60
|
+
tools: readonly SessionTool[];
|
|
61
|
+
instructions?: string;
|
|
62
|
+
timeoutMs?: number;
|
|
63
|
+
call(
|
|
64
|
+
name: string,
|
|
65
|
+
args: Record<string, unknown>,
|
|
66
|
+
caller: SessionToolCaller,
|
|
67
|
+
signal: AbortSignal,
|
|
68
|
+
): Promise<{ content: SessionToolContent[]; isError?: boolean }>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* A session's tools: the operator's, and the host's other tools for the
|
|
73
|
+
* session (`with`) in the same source, as the engine gives a session one.
|
|
74
|
+
* The caller is the engine's, so no model can name another; a refusal is an
|
|
75
|
+
* `isError` result in its words, any other failure `refused (failed)` with
|
|
76
|
+
* none of its text; a call the agent gives up ends its wait.
|
|
77
|
+
*/
|
|
78
|
+
export function operatorSessionTools<Auth>(
|
|
79
|
+
operator: Operator<Auth>,
|
|
80
|
+
options: { name: string; with?: SessionToolSource; instructions?: string },
|
|
81
|
+
): SessionToolSource {
|
|
82
|
+
const own: SessionTool[] = operator.tools().map((tool) => ({
|
|
83
|
+
name: tool.name,
|
|
84
|
+
description: tool.description,
|
|
85
|
+
inputSchema: tool.inputSchema as Record<string, unknown>,
|
|
86
|
+
// Only what is so: a read says it reads, a destructive tool says so, a write says neither.
|
|
87
|
+
annotations: tool.readOnly ? { readOnly: true } : tool.destructive ? { destructive: true } : {},
|
|
88
|
+
}));
|
|
89
|
+
const other = options.with;
|
|
90
|
+
const theirs = new Set(other?.tools.map((tool) => tool.name));
|
|
91
|
+
const clash = own.find((tool) => theirs.has(tool.name));
|
|
92
|
+
if (clash) throw new Error(`The host's tools and the operator's both have ${clash.name}`);
|
|
93
|
+
const instructions = [options.instructions ?? OPERATOR_GUIDANCE, other?.instructions]
|
|
94
|
+
.filter(Boolean)
|
|
95
|
+
.join("\n\n");
|
|
96
|
+
return {
|
|
97
|
+
name: options.name,
|
|
98
|
+
tools: [...own, ...(other?.tools ?? [])],
|
|
99
|
+
instructions,
|
|
100
|
+
...(other?.timeoutMs !== undefined ? { timeoutMs: other.timeoutMs } : {}),
|
|
101
|
+
async call(name, args, caller, signal) {
|
|
102
|
+
// One boundary for both: plan mode reads only, and no failure's text gets out.
|
|
103
|
+
try {
|
|
104
|
+
// A call the agent gave up runs nothing.
|
|
105
|
+
if (signal.aborted)
|
|
106
|
+
throw refuse.unsupported("The call was given up before it ran. Nothing was done.");
|
|
107
|
+
if (other && theirs.has(name)) {
|
|
108
|
+
const writes = !other.tools.find((t) => t.name === name)?.annotations?.readOnly;
|
|
109
|
+
if (writes && caller.permissionMode === "plan") throw refuse.readOnly();
|
|
110
|
+
return await other.call(name, args, caller, signal);
|
|
111
|
+
}
|
|
112
|
+
const text = await operator.call(name, args, {
|
|
113
|
+
kind: "session",
|
|
114
|
+
sessionId: caller.sessionId,
|
|
115
|
+
turnId: caller.turnId,
|
|
116
|
+
harness: caller.harness as never,
|
|
117
|
+
permissionMode: caller.permissionMode,
|
|
118
|
+
signal,
|
|
119
|
+
});
|
|
120
|
+
return { content: [{ type: "text", text }] };
|
|
121
|
+
} catch (error) {
|
|
122
|
+
const said = error instanceof OperatorError ? error.message : refuse.failed().message;
|
|
123
|
+
return { content: [{ type: "text", text: said }], isError: true };
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
}
|
|
@@ -0,0 +1,506 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The operator's public types (LLP 0019): who calls, what a session is as the
|
|
3
|
+
* tools report it, the host the product implements, and the refusals.
|
|
4
|
+
* `Origin` is the protocol's (it rides `turn/start` and `turn/steer`).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// @ref LLP 0019#the-host — what the package owns and what stays the host's
|
|
8
|
+
|
|
9
|
+
import type { z } from "zod";
|
|
10
|
+
import type { ReportedPermissionMode } from "../protocol/config.ts";
|
|
11
|
+
import type { AgentHarness } from "../protocol/harness.ts";
|
|
12
|
+
import type { Origin } from "../protocol/origin.ts";
|
|
13
|
+
import type { ThinkingLevel } from "../protocol/thinking.ts";
|
|
14
|
+
|
|
15
|
+
import type { Answer } from "./render.ts";
|
|
16
|
+
import type { DecisionRequest, QuestionRequest, ViewMessage } from "./view.ts";
|
|
17
|
+
|
|
18
|
+
export type { Origin };
|
|
19
|
+
|
|
20
|
+
// ---- who is calling ---------------------------------------------------------
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* A session's own agent calling the tools. Filled by the engine's delivery
|
|
24
|
+
* of the tools to the session, never by the model.
|
|
25
|
+
*/
|
|
26
|
+
export interface SessionCaller {
|
|
27
|
+
kind: "session";
|
|
28
|
+
sessionId: string;
|
|
29
|
+
/** The turn the call is made in: a tool call always happens inside one. */
|
|
30
|
+
turnId: string;
|
|
31
|
+
harness: AgentHarness;
|
|
32
|
+
/** The session's mode live at the call, not the turn's start config: `plan` may only read. */
|
|
33
|
+
permissionMode: ReportedPermissionMode;
|
|
34
|
+
/** Aborts when the agent gives the call up: a held wait answers at once. */
|
|
35
|
+
signal?: AbortSignal;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Anyone outside a session: an assistant, a paired device, the product's
|
|
40
|
+
* own window. `Auth` is the host's (its token, its access row): the package
|
|
41
|
+
* passes it through to the host and reads nothing of it.
|
|
42
|
+
*/
|
|
43
|
+
export interface ExternalCaller<Auth = unknown> {
|
|
44
|
+
kind: "external";
|
|
45
|
+
/** Stable per caller; with the kind, keys repeats and rates. */
|
|
46
|
+
id: string;
|
|
47
|
+
/** Whose words its messages are: the person's own window or device, or an assistant's. */
|
|
48
|
+
speaksAs: "person" | "assistant";
|
|
49
|
+
/** How the host shows it ("ChatGPT"); an assistant's origin carries it. */
|
|
50
|
+
name?: string;
|
|
51
|
+
/** Epoch ms its connection ends: no call waits past it (less a margin). */
|
|
52
|
+
endsAt?: number;
|
|
53
|
+
/** Aborts when the caller gives the call up (its request closed): a held wait answers at once. */
|
|
54
|
+
signal?: AbortSignal;
|
|
55
|
+
auth: Auth;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type Caller<Auth = unknown> = SessionCaller | ExternalCaller<Auth>;
|
|
59
|
+
|
|
60
|
+
/** `session:<id>` or `external:<id>`: every map the package keeps is keyed by it. */
|
|
61
|
+
export type CallerKey = `session:${string}` | `external:${string}`;
|
|
62
|
+
|
|
63
|
+
// ---- what a session is, as the tools report it --------------------------------
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* - `setting_up`: its workspace is being prepared; no turn can run yet.
|
|
67
|
+
* - `idle`: no turn runs; the last one finished (or none ran).
|
|
68
|
+
* - `working`: a turn runs.
|
|
69
|
+
* - `needs_input`: a turn waits on a question, a plan or a permission.
|
|
70
|
+
* - `stopped`: the last turn was cancelled, and nothing ran since.
|
|
71
|
+
* - `error`: the last turn failed, or the workspace could not be set up.
|
|
72
|
+
* - `archived`: put away; read only.
|
|
73
|
+
*/
|
|
74
|
+
export type SessionStatus =
|
|
75
|
+
| "setting_up"
|
|
76
|
+
| "idle"
|
|
77
|
+
| "working"
|
|
78
|
+
| "needs_input"
|
|
79
|
+
| "stopped"
|
|
80
|
+
| "error"
|
|
81
|
+
| "archived";
|
|
82
|
+
|
|
83
|
+
/** `list_sessions`'s `started_by` filter, from the caller's side. */
|
|
84
|
+
export type StartedByFilter = "me" | "agents" | "person" | "any";
|
|
85
|
+
|
|
86
|
+
export interface ProjectRef {
|
|
87
|
+
id: string;
|
|
88
|
+
/** Unique among the caller's projects, case-insensitively. May hold `/` (`owner/name`). */
|
|
89
|
+
name: string;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface WorkspaceRef {
|
|
93
|
+
id: string;
|
|
94
|
+
/** Unique in its project, case-insensitively; holds neither `/` nor `:`. */
|
|
95
|
+
name: string;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** One session as the host lists it. */
|
|
99
|
+
export interface Entry {
|
|
100
|
+
/**
|
|
101
|
+
* The engine's `sessionId`, minted when the session is asked for, before
|
|
102
|
+
* its workspace is set up: one identity for the session's whole life.
|
|
103
|
+
*/
|
|
104
|
+
id: string;
|
|
105
|
+
project?: ProjectRef;
|
|
106
|
+
/** A host with no workspaces gives each session one of its own. */
|
|
107
|
+
workspace: WorkspaceRef;
|
|
108
|
+
/** Its number in its workspace, from 1, never reused. Absent: the tools print its id. */
|
|
109
|
+
chat?: number;
|
|
110
|
+
/** The chat a bare workspace name means. */
|
|
111
|
+
current: boolean;
|
|
112
|
+
status: SessionStatus;
|
|
113
|
+
title?: string;
|
|
114
|
+
harness?: AgentHarness;
|
|
115
|
+
model?: string;
|
|
116
|
+
/**
|
|
117
|
+
* Who started it: the start's origin, kept by the host. An external caller
|
|
118
|
+
* speaking as the person starts as the person, at account scope.
|
|
119
|
+
*/
|
|
120
|
+
startedBy: Origin;
|
|
121
|
+
startedAt?: number;
|
|
122
|
+
lastActivityAt?: number;
|
|
123
|
+
/** Why `error`, when setup failed (a failed turn's error is the view's). */
|
|
124
|
+
error?: string;
|
|
125
|
+
/** A few words the host adds to the row (lines changed, a pull request). */
|
|
126
|
+
note?: string;
|
|
127
|
+
/** Paths in this session's tool lines are shown relative to this folder. */
|
|
128
|
+
root?: string;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// ---- reading a session --------------------------------------------------------
|
|
132
|
+
|
|
133
|
+
/** A place in a session's conversation, minted by the host; the package never reads it. */
|
|
134
|
+
export type Cursor = string & { readonly __operatorCursor: true };
|
|
135
|
+
|
|
136
|
+
export type TurnOutcome = "running" | "done" | "cancelled" | "failed";
|
|
137
|
+
|
|
138
|
+
export interface ViewTurn {
|
|
139
|
+
turnId: string;
|
|
140
|
+
outcome: TurnOutcome;
|
|
141
|
+
/** Who stopped it, when the host knows (`cancelled`). */
|
|
142
|
+
cancelledBy?: Origin;
|
|
143
|
+
/** Why it failed (`failed`). */
|
|
144
|
+
error?: string;
|
|
145
|
+
/** Each user message carries its own sender (`ViewMessage.origin`): a turn can mix them. */
|
|
146
|
+
messages: readonly ViewMessage[];
|
|
147
|
+
startedAt?: number;
|
|
148
|
+
endedAt?: number;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* What a session waits on, with the kind the engine's broker said explicitly
|
|
153
|
+
* (`permission.requested`'s `purpose`): a plan only when it says `plan`. A
|
|
154
|
+
* model names one by the broker's own `requestId`.
|
|
155
|
+
*/
|
|
156
|
+
export type Waiting =
|
|
157
|
+
| { kind: "question"; request: QuestionRequest }
|
|
158
|
+
| { kind: "plan" | "permission"; request: DecisionRequest };
|
|
159
|
+
|
|
160
|
+
/** How a turn ended, by its id, whatever page of the transcript is read. */
|
|
161
|
+
export interface TurnEnded {
|
|
162
|
+
turnId: string;
|
|
163
|
+
outcome: "done" | "cancelled" | "failed";
|
|
164
|
+
/** Who stopped it, when the host knows. */
|
|
165
|
+
cancelledBy?: Origin;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** One turn, looked up by id. */
|
|
169
|
+
export type TurnFact =
|
|
170
|
+
| { state: "running" }
|
|
171
|
+
| ({ state: "ended" } & Omit<TurnEnded, "turnId">)
|
|
172
|
+
| { state: "unknown" };
|
|
173
|
+
|
|
174
|
+
export interface SessionView {
|
|
175
|
+
status: SessionStatus;
|
|
176
|
+
/** The running turn's id, if one runs: independent of `turns`' page. */
|
|
177
|
+
running?: string;
|
|
178
|
+
/** The last turn that ended, and how: independent of `turns`' page. */
|
|
179
|
+
lastEnded?: TurnEnded;
|
|
180
|
+
/** Oldest first; after `after`, only what followed it (a turn still running may repeat). */
|
|
181
|
+
turns: readonly ViewTurn[];
|
|
182
|
+
waiting: readonly Waiting[];
|
|
183
|
+
/** The host holds earlier turns than these. */
|
|
184
|
+
older?: boolean;
|
|
185
|
+
/** Where this read ended: the next read's `after`. Absent: the host has no cursors. */
|
|
186
|
+
cursor?: Cursor;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export interface ViewOptions {
|
|
190
|
+
/** The most recent messages wanted. A host may give more; the package cuts. */
|
|
191
|
+
last?: number;
|
|
192
|
+
/** Only what came after this place. A cursor the host cannot read is `stale_cursor`. */
|
|
193
|
+
after?: Cursor;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export interface ListFilter {
|
|
197
|
+
project?: ProjectRef;
|
|
198
|
+
workspace?: WorkspaceRef;
|
|
199
|
+
status?: readonly SessionStatus[];
|
|
200
|
+
/** Archived ones too: name resolution asks for the complete set. */
|
|
201
|
+
includeArchived?: boolean;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// ---- writing --------------------------------------------------------------------
|
|
205
|
+
|
|
206
|
+
export interface StartInput {
|
|
207
|
+
/** The first task's turn id, minted by the package: deliver the first message as this turn. */
|
|
208
|
+
turnId: string;
|
|
209
|
+
project: ProjectRef;
|
|
210
|
+
/** A new chat in this workspace; absent: a new workspace. */
|
|
211
|
+
workspace?: WorkspaceRef;
|
|
212
|
+
harness?: AgentHarness;
|
|
213
|
+
model?: string;
|
|
214
|
+
thinkingLevel?: ThinkingLevel;
|
|
215
|
+
title?: string;
|
|
216
|
+
/** The first message: the host delivers it as the session's first turn, at once or once set up. */
|
|
217
|
+
message: string;
|
|
218
|
+
origin: Origin;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export interface SendInput {
|
|
222
|
+
/** Minted by the package; a retry after no answer uses it again, and the engine converges on it. */
|
|
223
|
+
turnId: string;
|
|
224
|
+
message: string;
|
|
225
|
+
origin: Origin;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* What a cancel did: the turn stopped (it has ended: a host whose stop is
|
|
230
|
+
* asynchronous waits for the end, briefly, before saying so), there was none,
|
|
231
|
+
* the stop is asked and its end not yet seen (`unconfirmed`: an archive then
|
|
232
|
+
* archives nothing), or (a session being set up) its first task was dropped.
|
|
233
|
+
*/
|
|
234
|
+
export type CancelOutcome = "stopped" | "not_running" | "unconfirmed" | "first_task_dropped";
|
|
235
|
+
|
|
236
|
+
export type ArchiveTarget = { kind: "session"; id: string } | { kind: "workspace"; id: string };
|
|
237
|
+
|
|
238
|
+
export interface ModelEntry {
|
|
239
|
+
harness: AgentHarness;
|
|
240
|
+
id: string;
|
|
241
|
+
label: string;
|
|
242
|
+
thinkingLevels: readonly ThinkingLevel[];
|
|
243
|
+
defaultThinkingLevel?: ThinkingLevel;
|
|
244
|
+
/** The model a new session on this harness starts on. */
|
|
245
|
+
default?: boolean;
|
|
246
|
+
/** The harness a new session starts on when none is named. */
|
|
247
|
+
defaultHarness?: boolean;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// ---- refusals -------------------------------------------------------------------
|
|
251
|
+
|
|
252
|
+
/** Every refusal the tools give, and nothing else (LLP 0019, Errors). */
|
|
253
|
+
export const OPERATOR_ERROR_CODES = [
|
|
254
|
+
"invalid_input",
|
|
255
|
+
"not_found",
|
|
256
|
+
"ambiguous",
|
|
257
|
+
"archived",
|
|
258
|
+
"self",
|
|
259
|
+
"read_only",
|
|
260
|
+
"access",
|
|
261
|
+
"not_yours",
|
|
262
|
+
"has_children",
|
|
263
|
+
"busy",
|
|
264
|
+
"not_waiting",
|
|
265
|
+
"person_only",
|
|
266
|
+
"setup_failed",
|
|
267
|
+
"limit_depth",
|
|
268
|
+
"limit_sessions",
|
|
269
|
+
"limit_setting_up",
|
|
270
|
+
"limit_rate",
|
|
271
|
+
"limit_resources",
|
|
272
|
+
"stale_cursor",
|
|
273
|
+
"unsupported",
|
|
274
|
+
"failed",
|
|
275
|
+
] as const;
|
|
276
|
+
export type OperatorErrorCode = (typeof OPERATOR_ERROR_CODES)[number];
|
|
277
|
+
|
|
278
|
+
/** A refusal as the host gives one (`authorize`, `admit`, or thrown from a method as `Refused`). */
|
|
279
|
+
export interface Refusal {
|
|
280
|
+
code: OperatorErrorCode;
|
|
281
|
+
/** The sessions it is about, by id (a busy member, the children not archived). */
|
|
282
|
+
sessions?: readonly string[];
|
|
283
|
+
/** The state the host saw at its commit (`busy`): the words follow it, not the preflight read. */
|
|
284
|
+
state?: SessionStatus;
|
|
285
|
+
/** The host's words, one line, trusted: said after the code's sentence. */
|
|
286
|
+
detail?: string;
|
|
287
|
+
/** Seconds after which the same call may succeed. */
|
|
288
|
+
retryAfter?: number;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// ---- rules ------------------------------------------------------------------------
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* What a tool does, for the rules, declared honestly: anything that changes
|
|
295
|
+
* something or posts outside is `write`. `read` runs in plan mode.
|
|
296
|
+
*/
|
|
297
|
+
export type Effect = "read" | "write" | "destructive";
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Limits, each a host may change. The defaults are LLP 0019's.
|
|
301
|
+
* `depth` and `sessionsPerStarter` bind session callers only. A cap across
|
|
302
|
+
* the host (workspaces being set up, disk, memory) is the host's, enforced
|
|
303
|
+
* inside its own `start`: one starter's lock cannot hold it.
|
|
304
|
+
*/
|
|
305
|
+
export interface Limits {
|
|
306
|
+
/** A session started by a chain this long may start no more. Default 3. */
|
|
307
|
+
depth: number;
|
|
308
|
+
/** Sessions one session started that are not archived. Default 12. */
|
|
309
|
+
sessionsPerStarter: number;
|
|
310
|
+
/** Starts per caller in any 60 seconds. Default 10. */
|
|
311
|
+
startsPerMinute: number;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/** How long a held call may wait, by caller kind: a default and a cap, in seconds. */
|
|
315
|
+
export interface WaitCaps {
|
|
316
|
+
/** Default 120 and 240 (Codex cuts a tool call at 300 s unless told otherwise). */
|
|
317
|
+
session: { default: number; max: number };
|
|
318
|
+
/** Default 60 and 90; never past `endsAt` less 5 s. */
|
|
319
|
+
external: { default: number; max: number };
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/** What `admit` is asked before a start: the host's resource probes. */
|
|
323
|
+
export interface AdmitRequest {
|
|
324
|
+
kind: "start";
|
|
325
|
+
project: ProjectRef;
|
|
326
|
+
/** Absent: a new workspace would be set up. */
|
|
327
|
+
workspace?: WorkspaceRef;
|
|
328
|
+
origin: Origin;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* The facts the rules and limits rest on, authoritative, not filtered by
|
|
333
|
+
* what a caller may see. Required of a host that enables session callers.
|
|
334
|
+
*/
|
|
335
|
+
export interface PolicyFacts {
|
|
336
|
+
/** The sessions this session started, not archived. */
|
|
337
|
+
startedBy(sessionId: string): Promise<Entry[]>;
|
|
338
|
+
/** Who started this session, and who started that one, nearest first. */
|
|
339
|
+
lineage(sessionId: string): Promise<Origin[]>;
|
|
340
|
+
/** Every session in the workspace with its status, archived ones excluded. */
|
|
341
|
+
inWorkspace(workspaceId: string): Promise<Entry[]>;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// ---- the host ------------------------------------------------------------------
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* The product, to the package. `list`, `view`, `send` and `onChange` are
|
|
348
|
+
* required; every other method is a capability, and a tool that needs one
|
|
349
|
+
* the host lacks is not listed. The host keeps its own check at each
|
|
350
|
+
* mutation; the package's rules are in addition.
|
|
351
|
+
*/
|
|
352
|
+
export interface OperatorHost<Auth = unknown> {
|
|
353
|
+
/** The sessions this caller may see, filtered as asked (the package filters again). */
|
|
354
|
+
list(caller: Caller<Auth>, filter: ListFilter): Promise<Entry[]>;
|
|
355
|
+
view(caller: Caller<Auth>, sessionId: string, options: ViewOptions): Promise<SessionView>;
|
|
356
|
+
/**
|
|
357
|
+
* Start the turn `input.turnId` now, carrying `origin` to the wire. The
|
|
358
|
+
* same turn id again converges on the first (the engine's rule). A host
|
|
359
|
+
* that finds the session busy refuses `busy` (an `OperatorError`, or
|
|
360
|
+
* `Refused`), any other definite refusal is one of those too, and a
|
|
361
|
+
* failure whose outcome is unknown throws a plain error: the package tries
|
|
362
|
+
* again with the same turn id.
|
|
363
|
+
*/
|
|
364
|
+
send(caller: Caller<Auth>, sessionId: string, input: SendInput): Promise<void>;
|
|
365
|
+
/** One turn by id: running, ended (how, and by whom when stopped), or unknown. */
|
|
366
|
+
turn(caller: Caller<Auth>, sessionId: string, turnId: string): Promise<TurnFact>;
|
|
367
|
+
/**
|
|
368
|
+
* Call `listener` with the sessions that may have changed, for as long as
|
|
369
|
+
* the returned function is not called. Waits rest on it.
|
|
370
|
+
*/
|
|
371
|
+
onChange(listener: (sessionIds: readonly string[]) => void): () => void;
|
|
372
|
+
|
|
373
|
+
/** One entry by session id or workspace id (its current chat), archived ones included. */
|
|
374
|
+
entry?(caller: Caller<Auth>, id: string): Promise<Entry | undefined>;
|
|
375
|
+
/** Every project this caller could start in, those with no session included. */
|
|
376
|
+
projects?(caller: Caller<Auth>): Promise<ProjectRef[]>;
|
|
377
|
+
/**
|
|
378
|
+
* Make the session (and its workspace, when none is named) and return its
|
|
379
|
+
* entry at once, its session id minted now: `idle`, or `setting_up` while
|
|
380
|
+
* its workspace is prepared. Keep `input.origin` as its `startedBy`. The
|
|
381
|
+
* host OWNS delivering `input.message` as its first turn (`input.turnId`),
|
|
382
|
+
* at once or once set up, and reports what became of it through the
|
|
383
|
+
* session's status (an `error` with why when it could not be delivered).
|
|
384
|
+
* The package's checks are preflight; the host enforces, atomically at
|
|
385
|
+
* its commit, by throwing `Refused`: no start into an archived workspace
|
|
386
|
+
* or by an archived starter (`archived`), and its caps across starters
|
|
387
|
+
* (`limit_setting_up` or `limit_resources`, with `retryAfter`). Enables
|
|
388
|
+
* `start_session`.
|
|
389
|
+
*/
|
|
390
|
+
start?(caller: Caller<Auth>, input: StartInput): Promise<Entry>;
|
|
391
|
+
/**
|
|
392
|
+
* Stop this turn, and only it; with no turn (a session being set up), drop
|
|
393
|
+
* the first task the host holds for it. Enables `stop_sessions` and
|
|
394
|
+
* `when: interrupt`.
|
|
395
|
+
*/
|
|
396
|
+
cancel?(caller: Caller<Auth>, sessionId: string, turnId?: string): Promise<CancelOutcome>;
|
|
397
|
+
/** Answer exactly this request; `accepted: false` when it no longer waits. Enables `answer_request`. */
|
|
398
|
+
respond?(caller: Caller<Auth>, sessionId: string, answer: Answer): Promise<{ accepted: boolean }>;
|
|
399
|
+
/**
|
|
400
|
+
* Archive one target. The package's checks are preflight; the host
|
|
401
|
+
* enforces eligibility atomically at its commit, throwing `Refused` with
|
|
402
|
+
* the sessions concerned and the state it saw: a member being set up
|
|
403
|
+
* (`busy`, `state: "setting_up"`), a member still working or waiting, the
|
|
404
|
+
* caller's own included, since a stop must be confirmed first (`busy`; a
|
|
405
|
+
* member the caller did not start, `not_yours`), a member that started
|
|
406
|
+
* sessions not archived, lineage included (`has_children`).
|
|
407
|
+
* Check every condition a stop cannot change before answering `busy`.
|
|
408
|
+
* Enables `archive`.
|
|
409
|
+
*/
|
|
410
|
+
archive?(caller: Caller<Auth>, target: ArchiveTarget): Promise<{ note?: string }>;
|
|
411
|
+
/** The models a new session can run. Enables `list_models`. */
|
|
412
|
+
models?(caller: Caller<Auth>): Promise<ModelEntry[]>;
|
|
413
|
+
/**
|
|
414
|
+
* Whether this outside caller may run this tool now, read from the host's
|
|
415
|
+
* store at the call: asked before every tool and again just before every
|
|
416
|
+
* write the package makes (each send, cancel, answer, start, archive). The tool's
|
|
417
|
+
* name lets a host allow one write tool to a low-access caller.
|
|
418
|
+
*/
|
|
419
|
+
authorize?(
|
|
420
|
+
caller: ExternalCaller<Auth>,
|
|
421
|
+
call: { effect: Effect; tool: string },
|
|
422
|
+
): Refusal | undefined | Promise<Refusal | undefined>;
|
|
423
|
+
/** Required with session callers: the facts the rules and limits rest on. */
|
|
424
|
+
policy?: PolicyFacts;
|
|
425
|
+
/** Resource probes before a start (disk, memory): a `limit_resources` refusal, or none. */
|
|
426
|
+
admit?(caller: Caller<Auth>, request: AdmitRequest): Promise<Refusal | undefined>;
|
|
427
|
+
/** One line of host facts once a turn settles ("changes: a.ts (+4 -0)"). */
|
|
428
|
+
outcome?(caller: Caller<Auth>, entry: Entry): Promise<string | undefined>;
|
|
429
|
+
/** One line `whoami` adds for this caller ("access: read"). */
|
|
430
|
+
describe?(caller: Caller<Auth>): Promise<string | undefined>;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// ---- the host's own tools ---------------------------------------------------------
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* A tool the host adds beside the package's. It declares only its effect;
|
|
437
|
+
* the package applies plan mode and `authorize` (with its name) to it and
|
|
438
|
+
* nothing else. It may not change sessions: that is the package's tools'.
|
|
439
|
+
*/
|
|
440
|
+
export interface ExtraTool<Auth = unknown> {
|
|
441
|
+
name: string;
|
|
442
|
+
title: string;
|
|
443
|
+
description: string;
|
|
444
|
+
input: z.ZodObject;
|
|
445
|
+
effect: Effect;
|
|
446
|
+
/** It reaches past this host (sends something elsewhere): MCP's `openWorldHint`. */
|
|
447
|
+
openWorld?: boolean;
|
|
448
|
+
/** `call`: the call's deadline (epoch ms) and its caller's signal, so a long run answers in time. */
|
|
449
|
+
run(args: never, caller: Caller<Auth>, call: CallScope): Promise<string>;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* A call's time, as a host's own tool sees it: the deadline the package's
|
|
454
|
+
* waits keep (the caller's wait, capped, never past its connection) and the
|
|
455
|
+
* caller's signal.
|
|
456
|
+
*/
|
|
457
|
+
export interface CallScope {
|
|
458
|
+
deadline: number;
|
|
459
|
+
signal?: AbortSignal;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
// ---- the package's side ----------------------------------------------------------
|
|
463
|
+
|
|
464
|
+
/** A tool as any transport lists it. */
|
|
465
|
+
export interface ToolInfo {
|
|
466
|
+
name: string;
|
|
467
|
+
title: string;
|
|
468
|
+
description: string;
|
|
469
|
+
/** JSON Schema of the arguments (an object). */
|
|
470
|
+
inputSchema: unknown;
|
|
471
|
+
readOnly: boolean;
|
|
472
|
+
/** It reaches past this host: MCP's `openWorldHint`. */
|
|
473
|
+
openWorld?: boolean;
|
|
474
|
+
/** It may undo or lose work: MCP's `destructiveHint`. */
|
|
475
|
+
destructive?: boolean;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/** Time, for the waits and the limits. Tests pass their own; the default is the wall clock. */
|
|
479
|
+
export interface OperatorClock {
|
|
480
|
+
now(): number;
|
|
481
|
+
/** Resolve after `ms`, or as soon as `signal` aborts. */
|
|
482
|
+
pause(ms: number, signal: AbortSignal): Promise<void>;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
export interface OperatorOptions<Auth = unknown> {
|
|
486
|
+
limits?: Partial<Limits>;
|
|
487
|
+
waits?: Partial<WaitCaps>;
|
|
488
|
+
extra?: ExtraTool<Auth>[];
|
|
489
|
+
clock?: OperatorClock;
|
|
490
|
+
/**
|
|
491
|
+
* Shown each unexpected failure a call answers without (a `refused (failed)`,
|
|
492
|
+
* an outcome that could not be read), once, with the tool and the caller:
|
|
493
|
+
* for the host's reports. Never a refusal. It cannot change the answer,
|
|
494
|
+
* and a throw inside it is swallowed.
|
|
495
|
+
*/
|
|
496
|
+
onError?: (error: unknown, tool: string, caller: Caller<Auth>) => void;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
export interface Operator<Auth = unknown> {
|
|
500
|
+
/** The same for every caller: an assistant keeps the list it got when it connected. */
|
|
501
|
+
tools(): ToolInfo[];
|
|
502
|
+
/** Run one tool and answer in text. Refusals are `OperatorError`s. */
|
|
503
|
+
call(name: string, args: unknown, caller: Caller<Auth>): Promise<string>;
|
|
504
|
+
/** The entry a reference names (LLP 0019, References). */
|
|
505
|
+
find(caller: Caller<Auth>, ref: string): Promise<Entry>;
|
|
506
|
+
}
|