@noetic-tools/core 5.20.0-next.1 → 5.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/dist/adapters/openrouter.d.ts +1 -48
- package/dist/adapters/openrouter.js +3 -204
- package/dist/builders/acp-agent-checks.d.ts +20 -0
- package/dist/builders/acp-agent-checks.js +68 -0
- package/dist/builders/acp-agent-tool.d.ts +4 -3
- package/dist/builders/acp-agent-tool.js +5 -2
- package/dist/builders/connection-ceiling.d.ts +13 -0
- package/dist/builders/connection-ceiling.js +17 -0
- package/dist/builders/document-entries.d.ts +13 -0
- package/dist/builders/document-entries.js +18 -0
- package/dist/builders/dynamic-workflow.d.ts +53 -8
- package/dist/builders/dynamic-workflow.js +53 -25
- package/dist/builders/mcp-url-pattern.d.ts +13 -0
- package/dist/builders/mcp-url-pattern.js +85 -0
- package/dist/builders/step-builders.d.ts +14 -6
- package/dist/builders/step-builders.js +25 -2
- package/dist/builders/workflow-acp-grants.d.ts +42 -0
- package/dist/builders/workflow-acp-grants.js +224 -0
- package/dist/builders/workflow-child-nodes.js +8 -0
- package/dist/builders/workflow-connection-nodes.d.ts +13 -3
- package/dist/builders/workflow-connection-nodes.js +129 -3
- package/dist/builders/workflow-connections.js +2 -1
- package/dist/builders/workflow-hydrator.d.ts +24 -1
- package/dist/builders/workflow-hydrator.js +8 -167
- package/dist/builders/workflow-mcp-servers.d.ts +44 -0
- package/dist/builders/workflow-mcp-servers.js +327 -0
- package/dist/builders/workflow-tool-entries.d.ts +84 -0
- package/dist/builders/workflow-tool-entries.js +216 -0
- package/dist/connections/durability.d.ts +11 -1
- package/dist/connections/durability.js +34 -0
- package/dist/connections/entries.d.ts +33 -0
- package/dist/connections/entries.js +118 -0
- package/dist/connections/errors.d.ts +6 -0
- package/dist/connections/errors.js +12 -0
- package/dist/connections/harness-wiring.d.ts +4 -4
- package/dist/connections/harness-wiring.js +1 -1
- package/dist/connections/in-memory-connection.d.ts +2 -0
- package/dist/connections/in-memory-connection.js +5 -0
- package/dist/connections/model-tools.d.ts +35 -12
- package/dist/connections/model-tools.js +348 -202
- package/dist/connections/registry-types.d.ts +7 -0
- package/dist/connections/registry.d.ts +35 -6
- package/dist/connections/registry.js +183 -39
- package/dist/connections/step-tools.d.ts +64 -0
- package/dist/connections/step-tools.js +154 -0
- package/dist/connections/views.d.ts +3 -2
- package/dist/connections/views.js +15 -6
- package/dist/harness/agent-harness.d.ts +11 -1
- package/dist/harness/agent-harness.js +69 -8
- package/dist/harness/connection-gate.d.ts +49 -8
- package/dist/harness/connection-gate.js +137 -26
- package/dist/harness/deps/interpreter.d.ts +3 -3
- package/dist/harness/deps/interpreter.js +3 -3
- package/dist/harness/harness-options.d.ts +4 -3
- package/dist/harness/model-request.js +3 -1
- package/dist/harness/model-schema.d.ts +1 -19
- package/dist/harness/model-schema.js +0 -28
- package/dist/harness/model-tool-round.js +2 -2
- package/dist/index.d.ts +5 -5
- package/dist/index.js +1 -1
- package/dist/interpreter/acp-events.d.ts +25 -1
- package/dist/interpreter/acp-events.js +53 -1
- package/dist/interpreter/acp-layers.d.ts +20 -0
- package/dist/interpreter/acp-layers.js +55 -0
- package/dist/interpreter/acp-tools.d.ts +108 -0
- package/dist/interpreter/acp-tools.js +462 -0
- package/dist/interpreter/collect-tools.d.ts +28 -0
- package/dist/interpreter/collect-tools.js +112 -15
- package/dist/interpreter/connection-steps.d.ts +0 -2
- package/dist/interpreter/connection-steps.js +30 -8
- package/dist/interpreter/execute-acp-agent.js +263 -72
- package/dist/interpreter/execute-action.d.ts +76 -1
- package/dist/interpreter/execute-action.js +35 -42
- package/dist/interpreter/execute.d.ts +2 -0
- package/dist/interpreter/execute.js +24 -1
- package/dist/interpreter/verify-host.js +2 -1
- package/dist/runtime/tool-call.d.ts +67 -0
- package/dist/runtime/tool-call.js +244 -0
- package/dist/runtime/tool-context.d.ts +1 -2
- package/dist/runtime/tool-context.js +6 -2
- package/dist/schemas/workflow.d.ts +1 -1
- package/dist/types/connection-entry.d.ts +22 -0
- package/dist/types/connection-entry.js +8 -0
- package/dist/util/harness-internals.d.ts +2 -0
- package/dist/util/root-context.d.ts +3 -0
- package/dist/util/root-context.js +8 -0
- package/dist/util/tool-name.d.ts +8 -0
- package/dist/util/tool-name.js +10 -0
- package/package.json +3 -3
- package/schema/noetic-workflow.schema.json +498 -128
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A node's `tools` entries as live step tools (spec 26 § Tools). `{ type }` is
|
|
3
|
+
* a registered client tool or an `openrouter:*` server tool; `{ connection,
|
|
4
|
+
* ops? }` picks a harness or turn connection's model tools; `{ mcp }` is an
|
|
5
|
+
* MCP server the step attaches, built from the host's `mcp` allowlist. A
|
|
6
|
+
* document never sets a connection's policy, and under a `connections`
|
|
7
|
+
* allowlist a pick never reaches past the operations it grants.
|
|
8
|
+
*/
|
|
9
|
+
import type { ConnectionAllowlist, ConnectionConfig, ConnectionPick, McpAllowlist, Spawn, Step, StepToolEntry, Tool, WorkflowDocument, WorkflowStepConnectionEntry, WorkflowToolEntry } from '@noetic-tools/types';
|
|
10
|
+
import type { ConnectionManifestEntries } from './workflow-connections.js';
|
|
11
|
+
/** What hydrating a node's `tools` needs from the host. */
|
|
12
|
+
export interface ToolEntryHosts {
|
|
13
|
+
readonly tools: ReadonlyMap<string, Tool>;
|
|
14
|
+
/** What the document may use of each connection; absent allows every connection. */
|
|
15
|
+
readonly allowlist?: ConnectionAllowlist;
|
|
16
|
+
readonly mcp?: McpAllowlist;
|
|
17
|
+
/** Where a stdio `{ mcp }` server starts: the node's ACP agent's machine. Absent starts it here. */
|
|
18
|
+
readonly spawn?: Spawn;
|
|
19
|
+
/** The connections the node's document declares; its `{ mcp }` entries are the document's own servers. */
|
|
20
|
+
readonly connections?: ConnectionManifestEntries;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The step tools a `callModel` or `acp-agent` node stands for. Under a
|
|
24
|
+
* connections allowlist a node gets exactly what it lists; a node with no
|
|
25
|
+
* `tools` has none, and `withCeiling` bounds the connections it is offered.
|
|
26
|
+
* Without an allowlist an empty list is no list.
|
|
27
|
+
*
|
|
28
|
+
* @throws `NoeticConfigError` as `stepTools`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function nodeTools(node: {
|
|
31
|
+
readonly id: string;
|
|
32
|
+
readonly tools?: ReadonlyArray<WorkflowToolEntry>;
|
|
33
|
+
}, hosts: ToolEntryHosts): StepToolEntry[] | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Records on `built`, the step for a node with no `tools` under a
|
|
36
|
+
* connections allowlist, the most of the turn's connections it may be
|
|
37
|
+
* offered: each granted connection with exactly its granted operations, plus
|
|
38
|
+
* the MCP servers its document's `connections` attach — never every
|
|
39
|
+
* connection the harness holds. Its other tools are those of any step with no
|
|
40
|
+
* `tools`. Returns `built`.
|
|
41
|
+
*/
|
|
42
|
+
export declare function withCeiling<S extends object>(built: S, node: {
|
|
43
|
+
readonly tools?: ReadonlyArray<WorkflowToolEntry>;
|
|
44
|
+
}, hosts: Pick<ToolEntryHosts, 'allowlist' | 'connections'>): S;
|
|
45
|
+
/**
|
|
46
|
+
* The step tools a `callModel` node's `tools` entries stand for.
|
|
47
|
+
*
|
|
48
|
+
* @throws `NoeticConfigError` `UNKNOWN_TOOL_REFERENCE` for a tool the registry does not hold; the errors of `connectionEntries`.
|
|
49
|
+
*/
|
|
50
|
+
export declare function stepTools(nodeId: string, entries: ReadonlyArray<WorkflowToolEntry>, hosts: ToolEntryHosts): StepToolEntry[];
|
|
51
|
+
/**
|
|
52
|
+
* The connection entries and picks a node's `{ connection }` and `{ mcp }`
|
|
53
|
+
* entries stand for. A stdio `{ mcp }` server starts through `hosts.spawn`
|
|
54
|
+
* when given: where the node's ACP agent runs.
|
|
55
|
+
*
|
|
56
|
+
* @throws `NoeticConfigError` `CONNECTION_NOT_ALLOWED` for a server or operation the host does not grant; `CONNECTION_INVALID` when the host gives no `mcp.provider`.
|
|
57
|
+
*/
|
|
58
|
+
export declare function connectionEntries(nodeId: string, entries: ReadonlyArray<WorkflowStepConnectionEntry>, hosts: Pick<ToolEntryHosts, 'allowlist' | 'mcp' | 'spawn' | 'connections'>): Array<ConnectionPick | ConnectionConfig>;
|
|
59
|
+
/**
|
|
60
|
+
* Records the `{ "mcp" }` entries of a document's `connections` on the step
|
|
61
|
+
* built for it, so the turn attaches them when the document runs, by the
|
|
62
|
+
* names the document gives them.
|
|
63
|
+
*
|
|
64
|
+
* @throws `NoeticConfigError` as `mcpEntry`.
|
|
65
|
+
*/
|
|
66
|
+
export declare function recordDocumentConnections(root: Step, doc: WorkflowDocument, mcp: McpAllowlist | undefined): void;
|
|
67
|
+
/**
|
|
68
|
+
* Checks every `{ connection }` tool entry against the host's allowlist: it
|
|
69
|
+
* names an allowed connection, and each of its `ops` globs stays inside the
|
|
70
|
+
* operations the allowlist grants. Without `ops` the pick takes exactly the
|
|
71
|
+
* granted operations. A pick of an MCP server the document's own
|
|
72
|
+
* `connections` attach answers to the `mcp` allowlist instead.
|
|
73
|
+
*
|
|
74
|
+
* @throws `NoeticConfigError` `CONNECTION_NOT_ALLOWED` for a connection or operation glob the allowlist does not grant.
|
|
75
|
+
*/
|
|
76
|
+
export declare function checkToolConnections(doc: WorkflowDocument, allowlist: ConnectionAllowlist): void;
|
|
77
|
+
/** A complete sentence naming what is registered, for a hint. */
|
|
78
|
+
export declare function registeredSentence(noun: string, names: Iterable<string>): string;
|
|
79
|
+
/**
|
|
80
|
+
* Resolves tool names against the registry.
|
|
81
|
+
*
|
|
82
|
+
* @throws `NoeticConfigError` `UNKNOWN_TOOL_REFERENCE` for a name it does not hold.
|
|
83
|
+
*/
|
|
84
|
+
export declare function resolveTools(names: ReadonlyArray<string>, registry: ReadonlyMap<string, Tool>): Tool[];
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A node's `tools` entries as live step tools (spec 26 § Tools). `{ type }` is
|
|
3
|
+
* a registered client tool or an `openrouter:*` server tool; `{ connection,
|
|
4
|
+
* ops? }` picks a harness or turn connection's model tools; `{ mcp }` is an
|
|
5
|
+
* MCP server the step attaches, built from the host's `mcp` allowlist. A
|
|
6
|
+
* document never sets a connection's policy, and under a `connections`
|
|
7
|
+
* allowlist a pick never reaches past the operations it grants.
|
|
8
|
+
*/
|
|
9
|
+
import { isServerToolSpec, NoeticConfigError, walkWorkflow } from '@noetic-tools/types';
|
|
10
|
+
import { setConnectionCeiling } from './connection-ceiling.js';
|
|
11
|
+
import { setDocumentEntries } from './document-entries.js';
|
|
12
|
+
import { globMatches } from './workflow-connections.js';
|
|
13
|
+
import { DOCUMENT_WHERE, documentServers, mcpEntry } from './workflow-mcp-servers.js';
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region Public API
|
|
16
|
+
/**
|
|
17
|
+
* The step tools a `callModel` or `acp-agent` node stands for. Under a
|
|
18
|
+
* connections allowlist a node gets exactly what it lists; a node with no
|
|
19
|
+
* `tools` has none, and `withCeiling` bounds the connections it is offered.
|
|
20
|
+
* Without an allowlist an empty list is no list.
|
|
21
|
+
*
|
|
22
|
+
* @throws `NoeticConfigError` as `stepTools`.
|
|
23
|
+
*/
|
|
24
|
+
export function nodeTools(node, hosts) {
|
|
25
|
+
if (node.tools === undefined) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
const tools = stepTools(node.id, node.tools, hosts);
|
|
29
|
+
return hosts.allowlist === undefined && tools.length === 0 ? undefined : tools;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Records on `built`, the step for a node with no `tools` under a
|
|
33
|
+
* connections allowlist, the most of the turn's connections it may be
|
|
34
|
+
* offered: each granted connection with exactly its granted operations, plus
|
|
35
|
+
* the MCP servers its document's `connections` attach — never every
|
|
36
|
+
* connection the harness holds. Its other tools are those of any step with no
|
|
37
|
+
* `tools`. Returns `built`.
|
|
38
|
+
*/
|
|
39
|
+
export function withCeiling(built, node, hosts) {
|
|
40
|
+
if (node.tools === undefined && hosts.allowlist !== undefined) {
|
|
41
|
+
setConnectionCeiling(built, grantedPicks(hosts.allowlist, hosts.connections));
|
|
42
|
+
}
|
|
43
|
+
return built;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The step tools a `callModel` node's `tools` entries stand for.
|
|
47
|
+
*
|
|
48
|
+
* @throws `NoeticConfigError` `UNKNOWN_TOOL_REFERENCE` for a tool the registry does not hold; the errors of `connectionEntries`.
|
|
49
|
+
*/
|
|
50
|
+
export function stepTools(nodeId, entries, hosts) {
|
|
51
|
+
const typed = entries.filter(isTypedEntry);
|
|
52
|
+
return [
|
|
53
|
+
...resolveTools(typed.filter((entry) => !isServerToolSpec(entry)).map((entry) => entry.type), hosts.tools),
|
|
54
|
+
...typed.filter(isServerToolSpec),
|
|
55
|
+
...connectionEntries(nodeId, entries.filter(isConnectionEntry), hosts),
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The connection entries and picks a node's `{ connection }` and `{ mcp }`
|
|
60
|
+
* entries stand for. A stdio `{ mcp }` server starts through `hosts.spawn`
|
|
61
|
+
* when given: where the node's ACP agent runs.
|
|
62
|
+
*
|
|
63
|
+
* @throws `NoeticConfigError` `CONNECTION_NOT_ALLOWED` for a server or operation the host does not grant; `CONNECTION_INVALID` when the host gives no `mcp.provider`.
|
|
64
|
+
*/
|
|
65
|
+
export function connectionEntries(nodeId, entries, hosts) {
|
|
66
|
+
return entries.map((entry) => 'mcp' in entry
|
|
67
|
+
? mcpEntry(`Node '${nodeId}'`, entry.mcp, {
|
|
68
|
+
allowlist: hosts.mcp,
|
|
69
|
+
spawn: hosts.spawn,
|
|
70
|
+
})
|
|
71
|
+
: connectionPick(nodeId, entry, hosts));
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Records the `{ "mcp" }` entries of a document's `connections` on the step
|
|
75
|
+
* built for it, so the turn attaches them when the document runs, by the
|
|
76
|
+
* names the document gives them.
|
|
77
|
+
*
|
|
78
|
+
* @throws `NoeticConfigError` as `mcpEntry`.
|
|
79
|
+
*/
|
|
80
|
+
export function recordDocumentConnections(root, doc, mcp) {
|
|
81
|
+
setDocumentEntries(root, documentServers(doc).map((server) => ({
|
|
82
|
+
name: server.name,
|
|
83
|
+
config: mcpEntry(DOCUMENT_WHERE, server, {
|
|
84
|
+
allowlist: mcp,
|
|
85
|
+
}),
|
|
86
|
+
scope: 'turn',
|
|
87
|
+
where: 'document connections',
|
|
88
|
+
})));
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Checks every `{ connection }` tool entry against the host's allowlist: it
|
|
92
|
+
* names an allowed connection, and each of its `ops` globs stays inside the
|
|
93
|
+
* operations the allowlist grants. Without `ops` the pick takes exactly the
|
|
94
|
+
* granted operations. A pick of an MCP server the document's own
|
|
95
|
+
* `connections` attach answers to the `mcp` allowlist instead.
|
|
96
|
+
*
|
|
97
|
+
* @throws `NoeticConfigError` `CONNECTION_NOT_ALLOWED` for a connection or operation glob the allowlist does not grant.
|
|
98
|
+
*/
|
|
99
|
+
export function checkToolConnections(doc, allowlist) {
|
|
100
|
+
const own = ownServers(doc.connections);
|
|
101
|
+
for (const node of walkWorkflow(doc.root)) {
|
|
102
|
+
if (node.kind !== 'callModel' && node.kind !== 'acp-agent') {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
for (const entry of node.tools ?? []) {
|
|
106
|
+
if ('connection' in entry && !own.has(entry.connection)) {
|
|
107
|
+
allowedOps(node.id, entry, allowlist);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
//#endregion
|
|
113
|
+
//#region Helpers
|
|
114
|
+
/**
|
|
115
|
+
* The MCP servers a document's own `connections` attach. A pick of one answers
|
|
116
|
+
* to the `mcp` allowlist, which granted the server, not to `connections`.
|
|
117
|
+
*/
|
|
118
|
+
function ownServers(manifest) {
|
|
119
|
+
return new Set(Object.entries(manifest ?? {})
|
|
120
|
+
.filter(([, entry]) => entry.mcp !== undefined)
|
|
121
|
+
.map(([name]) => name));
|
|
122
|
+
}
|
|
123
|
+
function grantedPicks(allowlist, manifest) {
|
|
124
|
+
const granted = Object.entries(allowlist).map(([connection, entry]) => ({
|
|
125
|
+
kind: 'connection-pick',
|
|
126
|
+
connection,
|
|
127
|
+
ops: entry.ops ?? [],
|
|
128
|
+
}));
|
|
129
|
+
const own = Object.entries(manifest ?? {})
|
|
130
|
+
.filter(([name, entry]) => entry.mcp !== undefined && !Object.hasOwn(allowlist, name))
|
|
131
|
+
.map(([connection]) => ({
|
|
132
|
+
kind: 'connection-pick',
|
|
133
|
+
connection,
|
|
134
|
+
}));
|
|
135
|
+
return [
|
|
136
|
+
...granted,
|
|
137
|
+
...own,
|
|
138
|
+
];
|
|
139
|
+
}
|
|
140
|
+
function isTypedEntry(entry) {
|
|
141
|
+
return 'type' in entry;
|
|
142
|
+
}
|
|
143
|
+
function isConnectionEntry(entry) {
|
|
144
|
+
return !isTypedEntry(entry);
|
|
145
|
+
}
|
|
146
|
+
function connectionPick(nodeId, entry, hosts) {
|
|
147
|
+
const { allowlist } = hosts;
|
|
148
|
+
const own = ownServers(hosts.connections).has(entry.connection);
|
|
149
|
+
const ops = allowlist && !own ? allowedOps(nodeId, entry, allowlist) : entry.ops;
|
|
150
|
+
return {
|
|
151
|
+
kind: 'connection-pick',
|
|
152
|
+
connection: entry.connection,
|
|
153
|
+
...(ops
|
|
154
|
+
? {
|
|
155
|
+
ops,
|
|
156
|
+
}
|
|
157
|
+
: {}),
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* The operation globs a pick may use under the allowlist: its own, each inside
|
|
162
|
+
* a granted glob, or with none the granted ones.
|
|
163
|
+
*
|
|
164
|
+
* @throws `NoeticConfigError` `CONNECTION_NOT_ALLOWED` when the connection or a glob is not granted.
|
|
165
|
+
*/
|
|
166
|
+
function allowedOps(nodeId, entry, allowlist) {
|
|
167
|
+
const granted = allowlist[entry.connection]?.ops;
|
|
168
|
+
if (!Object.hasOwn(allowlist, entry.connection)) {
|
|
169
|
+
throw notAllowed(`Node '${nodeId}' lists the tools of connection '${entry.connection}', which the host does not allow.`, `Allowed connections: ${Object.keys(allowlist).join(', ') || '(none)'}.`);
|
|
170
|
+
}
|
|
171
|
+
if (entry.ops === undefined) {
|
|
172
|
+
return granted ?? [];
|
|
173
|
+
}
|
|
174
|
+
for (const glob of entry.ops) {
|
|
175
|
+
// A glob read as plain text matches a granted glob only when every
|
|
176
|
+
// operation it matches does too: its `*` can only meet a granted `*`.
|
|
177
|
+
if ((granted ?? []).some((pattern) => globMatches(pattern, glob))) {
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
throw notAllowed(`Node '${nodeId}' picks operations '${glob}' of '${entry.connection}', which the host does not allow.`, `Allowed operations: ${(granted ?? []).join(', ') || '(none)'}.`);
|
|
181
|
+
}
|
|
182
|
+
return entry.ops;
|
|
183
|
+
}
|
|
184
|
+
function notAllowed(message, hint) {
|
|
185
|
+
return new NoeticConfigError({
|
|
186
|
+
code: 'CONNECTION_NOT_ALLOWED',
|
|
187
|
+
message,
|
|
188
|
+
hint,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
/** A complete sentence naming what is registered, for a hint. */
|
|
192
|
+
export function registeredSentence(noun, names) {
|
|
193
|
+
const list = [
|
|
194
|
+
...names,
|
|
195
|
+
];
|
|
196
|
+
return list.length > 0 ? `Registered ${noun}: ${list.join(', ')}.` : `No ${noun} are registered.`;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Resolves tool names against the registry.
|
|
200
|
+
*
|
|
201
|
+
* @throws `NoeticConfigError` `UNKNOWN_TOOL_REFERENCE` for a name it does not hold.
|
|
202
|
+
*/
|
|
203
|
+
export function resolveTools(names, registry) {
|
|
204
|
+
return names.map((name) => {
|
|
205
|
+
const tool = registry.get(name);
|
|
206
|
+
if (!tool) {
|
|
207
|
+
throw new NoeticConfigError({
|
|
208
|
+
code: 'UNKNOWN_TOOL_REFERENCE',
|
|
209
|
+
message: `Tool '${name}' referenced in workflow is not registered.`,
|
|
210
|
+
hint: `Register '${name}' in HydrationContext.tools before hydrating. ${registeredSentence('tools', registry.keys())}`,
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
return tool;
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
//#endregion
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* An epoch change alone (a hot reload) keeps refs and results. A connection
|
|
17
17
|
* that declares no determinism is treated as `'unsafe'`.
|
|
18
18
|
*/
|
|
19
|
-
import type { ConnectionIdentity, ConnectionLease, Determinism } from '@noetic-tools/types';
|
|
19
|
+
import type { ConnectionIdentity, ConnectionLease, Context, Determinism } from '@noetic-tools/types';
|
|
20
20
|
/**
|
|
21
21
|
* What a `call` or `wait` records before it reaches a server, so a resumed
|
|
22
22
|
* step against the same identity picks up where it was.
|
|
@@ -44,6 +44,16 @@ export type ResumeDecision =
|
|
|
44
44
|
| 'reset'
|
|
45
45
|
/** Replaced and unsafe to drive again: stop with `connection_resume_refused`. */
|
|
46
46
|
| 'refuse';
|
|
47
|
+
/** The ledger path of the step running on `ctx`, when it runs on a lane. */
|
|
48
|
+
export declare function stepPathOf(ctx: Context): string | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* An id for a tool call that brings none — a step running a tool directly, or
|
|
51
|
+
* an agent call with no id: the step's place in the run and the call's place
|
|
52
|
+
* among the calls `owner` gave ids in that step. A resumed step makes its
|
|
53
|
+
* calls in the same order, so it gets the same ids, and two equal calls get
|
|
54
|
+
* two ids.
|
|
55
|
+
*/
|
|
56
|
+
export declare function orderedCallId(owner: object, ctx: Context, stepId?: string): string;
|
|
47
57
|
/** The idempotency key of a step's call: the run and the step's ledger key. */
|
|
48
58
|
export declare function stepIdempotencyKey(executionId: string, ledgerKey: string): string;
|
|
49
59
|
/** The idempotency key of a model tool call: the turn's execution and the tool call id. */
|
|
@@ -16,8 +16,42 @@
|
|
|
16
16
|
* An epoch change alone (a hot reload) keeps refs and results. A connection
|
|
17
17
|
* that declares no determinism is treated as `'unsafe'`.
|
|
18
18
|
*/
|
|
19
|
+
import { ContextImpl } from '../runtime/context-impl.js';
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region Helpers
|
|
22
|
+
/** Calls each owner gave an id, by step. */
|
|
23
|
+
const CALL_COUNTS = new WeakMap();
|
|
24
|
+
/** FNV-1a over `text`, as 8 hex digits: a short, stable digest. */
|
|
25
|
+
function digest(text) {
|
|
26
|
+
let hash = 0x811c9dc5;
|
|
27
|
+
for (let i = 0; i < text.length; i++) {
|
|
28
|
+
hash ^= text.charCodeAt(i);
|
|
29
|
+
hash = Math.imul(hash, 0x01000193);
|
|
30
|
+
}
|
|
31
|
+
return (hash >>> 0).toString(16).padStart(8, '0');
|
|
32
|
+
}
|
|
19
33
|
//#endregion
|
|
20
34
|
//#region Public API
|
|
35
|
+
/** The ledger path of the step running on `ctx`, when it runs on a lane. */
|
|
36
|
+
export function stepPathOf(ctx) {
|
|
37
|
+
const path = ctx instanceof ContextImpl ? ctx.currentPath() : '';
|
|
38
|
+
return path.length > 0 ? path : undefined;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* An id for a tool call that brings none — a step running a tool directly, or
|
|
42
|
+
* an agent call with no id: the step's place in the run and the call's place
|
|
43
|
+
* among the calls `owner` gave ids in that step. A resumed step makes its
|
|
44
|
+
* calls in the same order, so it gets the same ids, and two equal calls get
|
|
45
|
+
* two ids.
|
|
46
|
+
*/
|
|
47
|
+
export function orderedCallId(owner, ctx, stepId) {
|
|
48
|
+
const step = stepPathOf(ctx) ?? stepId ?? ctx.id;
|
|
49
|
+
const counts = CALL_COUNTS.get(owner) ?? new Map();
|
|
50
|
+
CALL_COUNTS.set(owner, counts);
|
|
51
|
+
const order = counts.get(step) ?? 0;
|
|
52
|
+
counts.set(step, order + 1);
|
|
53
|
+
return `derived-${digest(`${step}\u0000${order}`)}`;
|
|
54
|
+
}
|
|
21
55
|
/** The idempotency key of a step's call: the run and the step's ledger key. */
|
|
22
56
|
export function stepIdempotencyKey(executionId, ledgerKey) {
|
|
23
57
|
return `${executionId}:${ledgerKey}`;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Connection entries and their names (spec 35 § Attaching connections). An
|
|
3
|
+
* entry is named by its record key, by its provider's `name`, or by both when
|
|
4
|
+
* they agree. A name is the entry's identity: the same name in a scope and an
|
|
5
|
+
* outer one (harness, then turn, then step) must carry the same provider and
|
|
6
|
+
* options, or it is `CONNECTION_NAME_TAKEN`.
|
|
7
|
+
*/
|
|
8
|
+
import type { ConnectionConfig, ConnectionEntries, ConnectionEntry } from '@noetic-tools/types';
|
|
9
|
+
import type { NamedEntry } from '../types/connection-entry.js';
|
|
10
|
+
/** The name an entry carries on its provider, if any. */
|
|
11
|
+
export declare function entryName(entry: ConnectionEntry): string | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Names every entry of a `connections` option and folds repeats of one entry.
|
|
14
|
+
*
|
|
15
|
+
* @throws NoeticConfigError `CONNECTION_INVALID` for an unnamed list entry or a
|
|
16
|
+
* record key its provider's name disagrees with; `CONNECTION_NAME_TAKEN` when
|
|
17
|
+
* two entries share a name but not a provider and options.
|
|
18
|
+
*/
|
|
19
|
+
export declare function namedEntries(entries: ConnectionEntries | undefined, where: string): NamedEntry[];
|
|
20
|
+
/**
|
|
21
|
+
* Names one entry of a list: its provider's `name`.
|
|
22
|
+
*
|
|
23
|
+
* @throws NoeticConfigError `CONNECTION_INVALID` when it has none.
|
|
24
|
+
*/
|
|
25
|
+
export declare function namedFromList(entry: ConnectionEntry, where: string): NamedEntry;
|
|
26
|
+
/**
|
|
27
|
+
* Checks an entry before the registry holds it: a valid name, a provider, and a known `expose`.
|
|
28
|
+
*
|
|
29
|
+
* @throws NoeticConfigError `CONNECTION_INVALID` for any of them.
|
|
30
|
+
*/
|
|
31
|
+
export declare function checkEntry(name: string, config: ConnectionConfig): void;
|
|
32
|
+
/** Whether two entries are the same connection: one provider, equal options. */
|
|
33
|
+
export declare function sameConfig(a: ConnectionConfig, b: ConnectionConfig): boolean;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Connection entries and their names (spec 35 § Attaching connections). An
|
|
3
|
+
* entry is named by its record key, by its provider's `name`, or by both when
|
|
4
|
+
* they agree. A name is the entry's identity: the same name in a scope and an
|
|
5
|
+
* outer one (harness, then turn, then step) must carry the same provider and
|
|
6
|
+
* options, or it is `CONNECTION_NAME_TAKEN`.
|
|
7
|
+
*/
|
|
8
|
+
import { isConnectionProvider, normalizeConnectionEntry } from '@noetic-tools/types';
|
|
9
|
+
import { invalidConnectionError, nameTakenError } from './errors.js';
|
|
10
|
+
import { CONNECTION_NAME_PATTERN } from './handle.js';
|
|
11
|
+
//#region Helpers
|
|
12
|
+
const EXPOSE_VALUES = new Set([
|
|
13
|
+
'eager',
|
|
14
|
+
'all',
|
|
15
|
+
'call',
|
|
16
|
+
'none',
|
|
17
|
+
]);
|
|
18
|
+
const OPTION_KEYS = [
|
|
19
|
+
'pool',
|
|
20
|
+
'policy',
|
|
21
|
+
'expose',
|
|
22
|
+
'look',
|
|
23
|
+
];
|
|
24
|
+
/** JSON with object keys sorted, so two equal option objects compare equal. */
|
|
25
|
+
function stable(value) {
|
|
26
|
+
return JSON.stringify(value, (_key, inner) => {
|
|
27
|
+
if (typeof inner !== 'object' || inner === null || Array.isArray(inner)) {
|
|
28
|
+
return inner;
|
|
29
|
+
}
|
|
30
|
+
return Object.fromEntries(Object.entries(inner).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)));
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function namedFromKey(key, entry, where) {
|
|
34
|
+
const config = normalizeConnectionEntry(entry);
|
|
35
|
+
const own = config.provider?.name;
|
|
36
|
+
if (own !== undefined && own !== key) {
|
|
37
|
+
throw invalidConnectionError(`${where} key '${key}' names a provider called '${own}'.`, `Use one name: the key '${key}' or mcp({ name: '${own}' }), or make them agree.`);
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
name: key,
|
|
41
|
+
config,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region Public API
|
|
46
|
+
/** The name an entry carries on its provider, if any. */
|
|
47
|
+
export function entryName(entry) {
|
|
48
|
+
return normalizeConnectionEntry(entry).provider?.name;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Names every entry of a `connections` option and folds repeats of one entry.
|
|
52
|
+
*
|
|
53
|
+
* @throws NoeticConfigError `CONNECTION_INVALID` for an unnamed list entry or a
|
|
54
|
+
* record key its provider's name disagrees with; `CONNECTION_NAME_TAKEN` when
|
|
55
|
+
* two entries share a name but not a provider and options.
|
|
56
|
+
*/
|
|
57
|
+
export function namedEntries(entries, where) {
|
|
58
|
+
if (entries === undefined) {
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
const named = Array.isArray(entries)
|
|
62
|
+
? entries.map((entry) => namedFromList(entry, where))
|
|
63
|
+
: Object.entries(entries).map(([key, entry]) => namedFromKey(key, entry, where));
|
|
64
|
+
const byName = new Map();
|
|
65
|
+
for (const entry of named) {
|
|
66
|
+
const held = byName.get(entry.name);
|
|
67
|
+
if (!held) {
|
|
68
|
+
byName.set(entry.name, entry);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (!sameConfig(held.config, entry.config)) {
|
|
72
|
+
throw nameTakenError(entry.name, where, where);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return [
|
|
76
|
+
...byName.values(),
|
|
77
|
+
];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Names one entry of a list: its provider's `name`.
|
|
81
|
+
*
|
|
82
|
+
* @throws NoeticConfigError `CONNECTION_INVALID` when it has none.
|
|
83
|
+
*/
|
|
84
|
+
export function namedFromList(entry, where) {
|
|
85
|
+
const config = normalizeConnectionEntry(entry);
|
|
86
|
+
const name = config.provider?.name;
|
|
87
|
+
if (name === undefined) {
|
|
88
|
+
throw invalidConnectionError(`${where} lists a connection with no name.`, "Name it on the provider (mcp({ name: 'linear', … })), or pass connections as a record keyed by name.");
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
name,
|
|
92
|
+
config,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Checks an entry before the registry holds it: a valid name, a provider, and a known `expose`.
|
|
97
|
+
*
|
|
98
|
+
* @throws NoeticConfigError `CONNECTION_INVALID` for any of them.
|
|
99
|
+
*/
|
|
100
|
+
export function checkEntry(name, config) {
|
|
101
|
+
if (!CONNECTION_NAME_PATTERN.test(name)) {
|
|
102
|
+
throw invalidConnectionError(`Connection name '${name}' is not valid.`, 'Start with a letter and use only letters, digits, _ and -.');
|
|
103
|
+
}
|
|
104
|
+
if (!isConnectionProvider(config.provider)) {
|
|
105
|
+
throw invalidConnectionError(`Connection '${name}' has no provider.`, 'Pass mcp(…), a source, or any ConnectionProvider (an object with connect()).');
|
|
106
|
+
}
|
|
107
|
+
if (config.expose !== undefined && !EXPOSE_VALUES.has(config.expose)) {
|
|
108
|
+
throw invalidConnectionError(`Connection '${name}' has expose '${String(config.expose)}'.`, "Use expose: 'eager', 'all', 'call' or 'none'.");
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/** Whether two entries are the same connection: one provider, equal options. */
|
|
112
|
+
export function sameConfig(a, b) {
|
|
113
|
+
if (a.provider !== b.provider) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
return OPTION_KEYS.every((key) => stable(a[key]) === stable(b[key]));
|
|
117
|
+
}
|
|
118
|
+
//#endregion
|
|
@@ -14,6 +14,12 @@ export declare function invalidConnectionError(message: string, hint: string): N
|
|
|
14
14
|
export declare function notAllowedConnectionError(message: string, hint: string): NoeticConfigError;
|
|
15
15
|
/** `CONNECTION_TOOL_COLLISION`: two operations would reach the model under one tool name. */
|
|
16
16
|
export declare function toolCollisionError(toolName: string, first: string, second: string): NoeticConfigError;
|
|
17
|
+
/**
|
|
18
|
+
* `CONNECTION_NAME_TAKEN`: an entry names a connection already attached in its
|
|
19
|
+
* scope or an outer one (harness, then turn, then step) with a different
|
|
20
|
+
* provider or options.
|
|
21
|
+
*/
|
|
22
|
+
export declare function nameTakenError(name: string, where: string, holder: string): NoeticConfigError;
|
|
17
23
|
/** `connection_unavailable`. */
|
|
18
24
|
export declare function unavailableError(connection: string, reason: string): NoeticErrorImpl;
|
|
19
25
|
/** `connection_failed`. */
|
|
@@ -39,6 +39,18 @@ export function toolCollisionError(toolName, first, second) {
|
|
|
39
39
|
hint: "Rename one connection, or set `expose: 'none'` (or `'eager'`) on one of them.",
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* `CONNECTION_NAME_TAKEN`: an entry names a connection already attached in its
|
|
44
|
+
* scope or an outer one (harness, then turn, then step) with a different
|
|
45
|
+
* provider or options.
|
|
46
|
+
*/
|
|
47
|
+
export function nameTakenError(name, where, holder) {
|
|
48
|
+
return new NoeticConfigError({
|
|
49
|
+
code: ConnectionConfigErrorCode.NameTaken,
|
|
50
|
+
message: `${where} names connection '${name}', which the ${holder} already attaches with a different provider or options.`,
|
|
51
|
+
hint: `Pass the same entry the ${holder} uses, or give this one another name.`,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
42
54
|
//#endregion
|
|
43
55
|
//#region Run-time errors
|
|
44
56
|
/** `connection_unavailable`. */
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* Construction is synchronous and validates the configuration; providers
|
|
8
8
|
* connect and triggers start listening in `start()`.
|
|
9
9
|
*/
|
|
10
|
-
import type { ArtifactStore,
|
|
10
|
+
import type { ArtifactStore, ConnectionEntries, ConnectionTrigger, Context, ContextLayer, ExecuteInput, ExecuteOptions, SecretResolver, SessionScope, SteeringDecision, StorageAdapter, Tool, ToolApprover } from '@noetic-tools/types';
|
|
11
11
|
import type { EventBroadcaster } from '../runtime/event-broadcaster.js';
|
|
12
12
|
import type { ConnectionRuntime } from './registry.js';
|
|
13
13
|
/** The harness surface the wiring calls back into. */
|
|
@@ -23,7 +23,7 @@ export interface WiredHarness {
|
|
|
23
23
|
/** `createHarnessConnections` options. */
|
|
24
24
|
export interface HarnessConnectionsOptions {
|
|
25
25
|
readonly harness: WiredHarness;
|
|
26
|
-
readonly connections?:
|
|
26
|
+
readonly connections?: ConnectionEntries;
|
|
27
27
|
readonly triggers?: ReadonlyArray<ConnectionTrigger>;
|
|
28
28
|
readonly storage: StorageAdapter;
|
|
29
29
|
readonly artifacts: ArtifactStore;
|
|
@@ -40,8 +40,8 @@ export interface HarnessConnections {
|
|
|
40
40
|
start(): Promise<void>;
|
|
41
41
|
/** Stops triggers and releases every connection. */
|
|
42
42
|
close(): Promise<void>;
|
|
43
|
-
/**
|
|
44
|
-
tools(): Tool[];
|
|
43
|
+
/** A turn's connection tools: the harness's, and the ones attached under `rootId`. */
|
|
44
|
+
tools(rootId?: string): Tool[];
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
47
|
* Builds a harness's connections from its options.
|
|
@@ -50,6 +50,8 @@ export interface InMemoryEventType extends Omit<ConnectionEventInfo, 'name' | 'r
|
|
|
50
50
|
}
|
|
51
51
|
/** `createInMemoryConnection()` options. */
|
|
52
52
|
export interface InMemoryConnectionOptions {
|
|
53
|
+
/** The connection name, so the provider can be listed in `connections: [...]`. */
|
|
54
|
+
readonly name?: string;
|
|
53
55
|
readonly id?: string;
|
|
54
56
|
readonly surface?: string;
|
|
55
57
|
/**
|
|
@@ -557,6 +557,11 @@ export function createInMemoryConnection(options = {}) {
|
|
|
557
557
|
let connects = 0;
|
|
558
558
|
const provisioned = [];
|
|
559
559
|
const provider = {
|
|
560
|
+
...(options.name === undefined
|
|
561
|
+
? {}
|
|
562
|
+
: {
|
|
563
|
+
name: options.name,
|
|
564
|
+
}),
|
|
560
565
|
get connection() {
|
|
561
566
|
return current;
|
|
562
567
|
},
|