@anchrd/intel-contract 0.13.0 → 0.15.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 +80 -0
- package/dist/contract/bundle.d.ts +85 -0
- package/dist/contract/bundle.js +63 -0
- package/dist/contract/contract.d.ts +3 -2245
- package/dist/contract/contract.js +24 -1108
- package/dist/contract/flow-run.d.ts +346 -0
- package/dist/contract/flow-run.js +181 -0
- package/dist/contract/flow.d.ts +995 -0
- package/dist/contract/flow.js +417 -0
- package/dist/contract/node.d.ts +402 -0
- package/dist/contract/node.js +310 -0
- package/dist/contract/share.d.ts +142 -0
- package/dist/contract/share.js +67 -0
- package/dist/contract/table.d.ts +162 -0
- package/dist/contract/table.js +117 -0
- package/dist/contract/tool.d.ts +122 -0
- package/dist/contract/tool.js +172 -0
- package/package.json +29 -1
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { IdempotencyKey, IntelId } from "./contract.js";
|
|
3
|
+
import { Node, NodeVersion } from "./node.js";
|
|
4
|
+
const distinctPositions = { error: "Row positions must be distinct" };
|
|
5
|
+
// A table is CSV, and CSV is the whole format: it is what is stored, what is downloaded and what a
|
|
6
|
+
// machine reads. There is no second representation to keep in step with it (#40).
|
|
7
|
+
export const TableMediaType = "text/csv";
|
|
8
|
+
// A column name is the contract between the table and everyone who appends to it, so it is trimmed,
|
|
9
|
+
// non-empty and bounded like a title. Cells are not: a cell is text, and text is what CSV carries.
|
|
10
|
+
export const TableColumn = z.string().trim().min(1).max(120);
|
|
11
|
+
export const TableCell = z.string().max(4_000);
|
|
12
|
+
export const TableRow = z.array(TableCell).min(1).max(64);
|
|
13
|
+
// Writing the header, once. The columns are the contract (#40's comment), which is why this refuses
|
|
14
|
+
// on a table that already has one: changing the header would silently reinterpret every row that
|
|
15
|
+
// was appended under the old one.
|
|
16
|
+
export const DefineTableInput = z.strictObject({
|
|
17
|
+
nodeId: IntelId.describe("Table node whose header is being written. It must not have one yet."),
|
|
18
|
+
columns: z
|
|
19
|
+
.array(TableColumn)
|
|
20
|
+
.describe("The column names, in order. They are the contract every later append is checked against, which is why this refuses on a table that already has a header — changing it would silently reinterpret the stored rows. Use node_table_update for that.")
|
|
21
|
+
.min(1)
|
|
22
|
+
.max(64)
|
|
23
|
+
.refine((columns) => new Set(columns.map((column) => column.toLowerCase())).size === columns.length, { error: "Column names must be distinct" }),
|
|
24
|
+
idempotencyKey: IdempotencyKey,
|
|
25
|
+
});
|
|
26
|
+
// ⚠️ No `baseVersionId`, and that absence is the feature. A document replaces its content and needs
|
|
27
|
+
// to know which content it replaces; an append adds to the end and cannot collide with a second
|
|
28
|
+
// append, so demanding a base version would invent a conflict that does not exist and force the
|
|
29
|
+
// caller to read the whole table first — the exact cost #40 exists to remove.
|
|
30
|
+
export const AppendTableRowsInput = z.strictObject({
|
|
31
|
+
nodeId: IntelId.describe("Table node to append to. It must already have a header."),
|
|
32
|
+
rows: z
|
|
33
|
+
.array(TableRow)
|
|
34
|
+
.min(1)
|
|
35
|
+
.max(1_000)
|
|
36
|
+
.describe("Rows to add at the end, each an array of cell strings in the header's order. No base version is needed: appending collides with nothing, so the table does not have to be read first."),
|
|
37
|
+
idempotencyKey: IdempotencyKey,
|
|
38
|
+
});
|
|
39
|
+
export const GetTableInput = z.strictObject({
|
|
40
|
+
nodeId: IntelId.describe("Table node to read as a grid: header and every row."),
|
|
41
|
+
});
|
|
42
|
+
export const AppendTableRowsResult = z.strictObject({
|
|
43
|
+
node: Node,
|
|
44
|
+
version: NodeVersion,
|
|
45
|
+
appended: z.number().int().positive(),
|
|
46
|
+
});
|
|
47
|
+
// A row's address is its position among the table's current rows, counted from zero and without the
|
|
48
|
+
// header. Deliberately not an ID: rows carry no identity of their own (#135, and the same decision
|
|
49
|
+
// the grid documents), so every mutation instead pins the state its positions refer to.
|
|
50
|
+
export const TableRowPosition = z.number().int().nonnegative();
|
|
51
|
+
// Replacing rows in place (#135). `baseVersionId` is the version the caller read the positions
|
|
52
|
+
// from — required, never nullable, because a position into a table one has not read is a guess.
|
|
53
|
+
// A table that moved on since answers `version_conflict` rather than editing the wrong rows; that
|
|
54
|
+
// is the same optimistic concurrency the document save uses, and the deliberate opposite of
|
|
55
|
+
// `append`, which needs no base because it collides with nothing.
|
|
56
|
+
export const UpdateTableRowsInput = z.strictObject({
|
|
57
|
+
nodeId: IntelId.describe("Table node to change rows in."),
|
|
58
|
+
baseVersionId: IntelId.describe("The `versionId` from the node_table_get whose rows these positions were counted in. Required and never null: a position into a table nobody has read is a guess. If the table has moved on since, the call is refused rather than editing the wrong rows."),
|
|
59
|
+
updates: z
|
|
60
|
+
.array(z.strictObject({
|
|
61
|
+
position: TableRowPosition.describe("Zero-based position of the row to replace, counting data rows and not the header."),
|
|
62
|
+
row: TableRow.describe("The complete replacement row, as cell strings in the header's order."),
|
|
63
|
+
}))
|
|
64
|
+
.describe("Which rows to replace and with what. `position` is zero-based and counts data rows, not the header; `row` is the complete replacement, not a patch.")
|
|
65
|
+
.min(1)
|
|
66
|
+
.max(1_000)
|
|
67
|
+
.refine((updates) => new Set(updates.map((update) => update.position)).size === updates.length, distinctPositions),
|
|
68
|
+
idempotencyKey: IdempotencyKey,
|
|
69
|
+
});
|
|
70
|
+
export const UpdateTableRowsResult = z.strictObject({
|
|
71
|
+
node: Node,
|
|
72
|
+
version: NodeVersion,
|
|
73
|
+
updated: z.number().int().positive(),
|
|
74
|
+
});
|
|
75
|
+
export const DeleteTableRowsInput = z.strictObject({
|
|
76
|
+
nodeId: IntelId.describe("Table node to remove rows from."),
|
|
77
|
+
baseVersionId: IntelId.describe("The `versionId` from the node_table_get these positions were counted in. A table that has moved on since is refused rather than losing the wrong rows."),
|
|
78
|
+
positions: z
|
|
79
|
+
.array(TableRowPosition)
|
|
80
|
+
.describe("Zero-based positions of the data rows to remove. All of them go in one call; the positions are read against the base version, so they do not shift while it runs.")
|
|
81
|
+
.min(1)
|
|
82
|
+
.max(1_000)
|
|
83
|
+
.refine((positions) => new Set(positions).size === positions.length, distinctPositions),
|
|
84
|
+
idempotencyKey: IdempotencyKey,
|
|
85
|
+
});
|
|
86
|
+
export const DeleteTableRowsResult = z.strictObject({
|
|
87
|
+
node: Node,
|
|
88
|
+
version: NodeVersion,
|
|
89
|
+
deleted: z.number().int().positive(),
|
|
90
|
+
});
|
|
91
|
+
// One entry per column the table will have afterwards, in order. `source` names the current column
|
|
92
|
+
// whose cells fill it; `null` adds an empty column, and a current column no entry names is removed
|
|
93
|
+
// together with its cells. Renaming is naming a source under a new name.
|
|
94
|
+
export const RedefineTableColumn = z.strictObject({
|
|
95
|
+
name: TableColumn.describe("What the column is called afterwards."),
|
|
96
|
+
source: TableColumn.nullable()
|
|
97
|
+
.default(null)
|
|
98
|
+
.describe("The current column whose cells fill it, by its current name, or `null` for a new empty column."),
|
|
99
|
+
});
|
|
100
|
+
// Changing the header of a table that has one (#135). The mapping is explicit because it is the
|
|
101
|
+
// whole difference to the blind re-definition `defineTable` keeps refusing: without it a new header
|
|
102
|
+
// would silently reinterpret every stored row under names nobody matched to the old ones.
|
|
103
|
+
export const RedefineTableInput = z.strictObject({
|
|
104
|
+
nodeId: IntelId.describe("Table node whose header is being changed."),
|
|
105
|
+
baseVersionId: IntelId.describe("The `versionId` from the node_table_get this mapping was written against. A table that has moved on since is refused."),
|
|
106
|
+
columns: z
|
|
107
|
+
.array(RedefineTableColumn)
|
|
108
|
+
.describe("The complete new header, in order. Each entry names the current column whose cells fill it, or `null` for a new empty one; a current column that no entry names is removed with its cells. Renaming is naming a source under a new name. The mapping is explicit on purpose — a new header without one would reinterpret every stored row.")
|
|
109
|
+
.min(1)
|
|
110
|
+
.max(64)
|
|
111
|
+
.refine((columns) => new Set(columns.map((column) => column.name.toLowerCase())).size === columns.length, { error: "Column names must be distinct" })
|
|
112
|
+
.refine((columns) => {
|
|
113
|
+
const sources = columns.map((column) => column.source).filter((source) => source !== null);
|
|
114
|
+
return new Set(sources).size === sources.length;
|
|
115
|
+
}, { error: "A current column can fill only one new column" }),
|
|
116
|
+
idempotencyKey: IdempotencyKey,
|
|
117
|
+
});
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* One MCP server as the portal names it. The handle is what the portal puts in front of every tool
|
|
4
|
+
* that server offers (`notion_notion-search` belongs to `notion`), and it is the only identifier
|
|
5
|
+
* Intel can both store and recognise again in a live `tools/list`.
|
|
6
|
+
*
|
|
7
|
+
* ⚠️ A handle is never invented from a tool name. Which servers exist is the portal's answer
|
|
8
|
+
* (`portal_list_servers`), and the prefix is only used to attribute a tool to a server that answer
|
|
9
|
+
* already named — see `packages/api/src/tools/tool-servers` for why splitting on the underscore
|
|
10
|
+
* alone would be ambiguous.
|
|
11
|
+
*/
|
|
12
|
+
export declare const ToolServerHandle: z.ZodString;
|
|
13
|
+
export type ToolServerHandle = z.infer<typeof ToolServerHandle>;
|
|
14
|
+
export declare const ToolSourceUrl: z.ZodURL;
|
|
15
|
+
export declare const ToolName: z.ZodString;
|
|
16
|
+
export declare const ToolAnnotations: z.ZodObject<{
|
|
17
|
+
title: z.ZodOptional<z.ZodString>;
|
|
18
|
+
readOnlyHint: z.ZodOptional<z.ZodBoolean>;
|
|
19
|
+
destructiveHint: z.ZodOptional<z.ZodBoolean>;
|
|
20
|
+
idempotentHint: z.ZodOptional<z.ZodBoolean>;
|
|
21
|
+
openWorldHint: z.ZodOptional<z.ZodBoolean>;
|
|
22
|
+
}, z.core.$strict>;
|
|
23
|
+
export type ToolAnnotations = z.infer<typeof ToolAnnotations>;
|
|
24
|
+
export declare const ToolCapability: z.ZodObject<{
|
|
25
|
+
name: z.ZodString;
|
|
26
|
+
title: z.ZodNullable<z.ZodString>;
|
|
27
|
+
description: z.ZodNullable<z.ZodString>;
|
|
28
|
+
inputSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
29
|
+
outputSchema: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
30
|
+
annotations: z.ZodObject<{
|
|
31
|
+
title: z.ZodOptional<z.ZodString>;
|
|
32
|
+
readOnlyHint: z.ZodOptional<z.ZodBoolean>;
|
|
33
|
+
destructiveHint: z.ZodOptional<z.ZodBoolean>;
|
|
34
|
+
idempotentHint: z.ZodOptional<z.ZodBoolean>;
|
|
35
|
+
openWorldHint: z.ZodOptional<z.ZodBoolean>;
|
|
36
|
+
}, z.core.$strict>;
|
|
37
|
+
fingerprint: z.ZodString;
|
|
38
|
+
}, z.core.$strict>;
|
|
39
|
+
export type ToolCapability = z.infer<typeof ToolCapability>;
|
|
40
|
+
export declare const ToolCatalog: z.ZodObject<{
|
|
41
|
+
portalConnected: z.ZodBoolean;
|
|
42
|
+
items: z.ZodArray<z.ZodObject<{
|
|
43
|
+
name: z.ZodString;
|
|
44
|
+
title: z.ZodNullable<z.ZodString>;
|
|
45
|
+
description: z.ZodNullable<z.ZodString>;
|
|
46
|
+
inputSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
47
|
+
outputSchema: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
48
|
+
annotations: z.ZodObject<{
|
|
49
|
+
title: z.ZodOptional<z.ZodString>;
|
|
50
|
+
readOnlyHint: z.ZodOptional<z.ZodBoolean>;
|
|
51
|
+
destructiveHint: z.ZodOptional<z.ZodBoolean>;
|
|
52
|
+
idempotentHint: z.ZodOptional<z.ZodBoolean>;
|
|
53
|
+
openWorldHint: z.ZodOptional<z.ZodBoolean>;
|
|
54
|
+
}, z.core.$strict>;
|
|
55
|
+
fingerprint: z.ZodString;
|
|
56
|
+
}, z.core.$strict>>;
|
|
57
|
+
reached: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
58
|
+
}, z.core.$strict>;
|
|
59
|
+
export type ToolCatalog = z.infer<typeof ToolCatalog>;
|
|
60
|
+
/**
|
|
61
|
+
* One MCP server the asking user reaches right now, as the portal itself names it (D30).
|
|
62
|
+
*
|
|
63
|
+
* ⚠️ `toolCount` is a fact about this moment and this user, not a size. It exists so a picker can
|
|
64
|
+
* say "9 tools" instead of showing a handle alone, and it must never be read as what an agent will
|
|
65
|
+
* get: the delegated run asks the portal again, with the delegator's token.
|
|
66
|
+
*/
|
|
67
|
+
export declare const ToolServer: z.ZodObject<{
|
|
68
|
+
handle: z.ZodString;
|
|
69
|
+
name: z.ZodString;
|
|
70
|
+
toolCount: z.ZodNumber;
|
|
71
|
+
}, z.core.$strict>;
|
|
72
|
+
export type ToolServer = z.infer<typeof ToolServer>;
|
|
73
|
+
export declare const ToolServerCatalog: z.ZodObject<{
|
|
74
|
+
portalConnected: z.ZodBoolean;
|
|
75
|
+
items: z.ZodArray<z.ZodObject<{
|
|
76
|
+
handle: z.ZodString;
|
|
77
|
+
name: z.ZodString;
|
|
78
|
+
toolCount: z.ZodNumber;
|
|
79
|
+
}, z.core.$strict>>;
|
|
80
|
+
}, z.core.$strict>;
|
|
81
|
+
export type ToolServerCatalog = z.infer<typeof ToolServerCatalog>;
|
|
82
|
+
/**
|
|
83
|
+
* Which of the named servers a tool belongs to, or `null` for none of them.
|
|
84
|
+
*
|
|
85
|
+
* ⚠️ THE TRAP: a tool name does not say where its server name ends.
|
|
86
|
+
*
|
|
87
|
+
* The portal writes `<server>_<tool>`, and both halves may contain underscores — `intel_flow_get`
|
|
88
|
+
* reads equally well as server `intel` with tool `flow_get` and as a server called `intel_flow`
|
|
89
|
+
* with tool `get`. Splitting on the first underscore is therefore a guess that is wrong the day
|
|
90
|
+
* somebody adds a server whose name contains one, and on the API side being wrong means an agent
|
|
91
|
+
* delegated server A quietly reaching server B.
|
|
92
|
+
*
|
|
93
|
+
* So the prefix is never split. It is only ever MATCHED against handles the portal itself named,
|
|
94
|
+
* and the longest match wins: with `intel` and `intel_flow` both declared, `intel_flow_get` belongs
|
|
95
|
+
* to `intel_flow`, which is the only reading in which both declarations stay true.
|
|
96
|
+
*
|
|
97
|
+
* ⚠️ This lives in the contract because HOW A NAME IS READ is a property of the wire, and both
|
|
98
|
+
* surfaces read the same wire: `packages/api` cuts a delegation with it, `packages/ui` groups the
|
|
99
|
+
* tools screen with it (#212). A second implementation in the browser would be the third answer to
|
|
100
|
+
* one question — the underscore rule has already been answered differently in two places once
|
|
101
|
+
* (#106, #107), and the copies disagreed. What deliberately stays OUT of here is everything about
|
|
102
|
+
* reach: which handles are declared, which are enabled, which may be delegated and which one owns
|
|
103
|
+
* the portal's own management tools are decisions with consequences, and they belong to
|
|
104
|
+
* `packages/api/src/tools/tool-servers`. This function only reads a name.
|
|
105
|
+
*/
|
|
106
|
+
export declare function serverOf(toolName: string, handles: Iterable<string>): string | null;
|
|
107
|
+
export declare const TestToolInput: z.ZodObject<{
|
|
108
|
+
name: z.ZodString;
|
|
109
|
+
arguments: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
110
|
+
}, z.core.$strict>;
|
|
111
|
+
export type TestToolInput = z.infer<typeof TestToolInput>;
|
|
112
|
+
export declare const ExecuteToolInput: z.ZodObject<{
|
|
113
|
+
name: z.ZodString;
|
|
114
|
+
arguments: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
115
|
+
}, z.core.$strict>;
|
|
116
|
+
export type ExecuteToolInput = z.infer<typeof ExecuteToolInput>;
|
|
117
|
+
export declare const ToolTestResult: z.ZodObject<{
|
|
118
|
+
isError: z.ZodBoolean;
|
|
119
|
+
content: z.ZodArray<z.ZodUnknown>;
|
|
120
|
+
structuredContent: z.ZodOptional<z.ZodUnknown>;
|
|
121
|
+
}, z.core.$strict>;
|
|
122
|
+
export type ToolTestResult = z.infer<typeof ToolTestResult>;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
function normalizedHostname(url) {
|
|
3
|
+
return url.hostname.toLowerCase().replace(/^\[|\]$/g, "");
|
|
4
|
+
}
|
|
5
|
+
function isPrivateIpv4(hostname) {
|
|
6
|
+
const parts = hostname.split(".").map(Number);
|
|
7
|
+
if (parts.length !== 4 ||
|
|
8
|
+
parts.some((part) => !Number.isInteger(part) || part < 0 || part > 255)) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
const [first = 0, second = 0] = parts;
|
|
12
|
+
return (first === 0 ||
|
|
13
|
+
first === 10 ||
|
|
14
|
+
first === 127 ||
|
|
15
|
+
(first === 100 && second >= 64 && second <= 127) ||
|
|
16
|
+
(first === 169 && second === 254) ||
|
|
17
|
+
(first === 172 && second >= 16 && second <= 31) ||
|
|
18
|
+
(first === 192 && second === 168) ||
|
|
19
|
+
(first === 198 && (second === 18 || second === 19)) ||
|
|
20
|
+
first >= 224);
|
|
21
|
+
}
|
|
22
|
+
function isPublicToolHost(url) {
|
|
23
|
+
const hostname = normalizedHostname(url);
|
|
24
|
+
if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1") {
|
|
25
|
+
return url.protocol === "http:";
|
|
26
|
+
}
|
|
27
|
+
if (!hostname.includes(".") ||
|
|
28
|
+
hostname.endsWith(".local") ||
|
|
29
|
+
hostname.endsWith(".localhost") ||
|
|
30
|
+
hostname.endsWith(".internal") ||
|
|
31
|
+
isPrivateIpv4(hostname) ||
|
|
32
|
+
hostname.includes(":")) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
return url.protocol === "https:";
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* One MCP server as the portal names it. The handle is what the portal puts in front of every tool
|
|
39
|
+
* that server offers (`notion_notion-search` belongs to `notion`), and it is the only identifier
|
|
40
|
+
* Intel can both store and recognise again in a live `tools/list`.
|
|
41
|
+
*
|
|
42
|
+
* ⚠️ A handle is never invented from a tool name. Which servers exist is the portal's answer
|
|
43
|
+
* (`portal_list_servers`), and the prefix is only used to attribute a tool to a server that answer
|
|
44
|
+
* already named — see `packages/api/src/tools/tool-servers` for why splitting on the underscore
|
|
45
|
+
* alone would be ambiguous.
|
|
46
|
+
*/
|
|
47
|
+
export const ToolServerHandle = z
|
|
48
|
+
.string()
|
|
49
|
+
.trim()
|
|
50
|
+
.min(1)
|
|
51
|
+
.max(120)
|
|
52
|
+
.regex(/^[A-Za-z0-9][A-Za-z0-9._-]*$/, "A server handle is the portal's own identifier");
|
|
53
|
+
export const ToolSourceUrl = z.url().refine((value) => {
|
|
54
|
+
try {
|
|
55
|
+
const url = new URL(value);
|
|
56
|
+
return !url.username && !url.password && isPublicToolHost(url);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}, "The portal must use an approved public HTTPS host without embedded credentials");
|
|
62
|
+
// The portal namespaces every upstream tool, so the name alone identifies the target server. The
|
|
63
|
+
// portal is still the one that resolves it and attaches the credentials — Intel never holds an
|
|
64
|
+
// upstream credential. Since D30 Intel does read the namespace for one purpose: attributing a tool
|
|
65
|
+
// to a server the portal's own `portal_list_servers` already named, so a delegation can be cut to
|
|
66
|
+
// whole servers. That is attribution, not routing.
|
|
67
|
+
export const ToolName = z.string().min(1).max(240);
|
|
68
|
+
export const ToolAnnotations = z.strictObject({
|
|
69
|
+
title: z.string().max(240).optional(),
|
|
70
|
+
readOnlyHint: z.boolean().optional(),
|
|
71
|
+
destructiveHint: z.boolean().optional(),
|
|
72
|
+
idempotentHint: z.boolean().optional(),
|
|
73
|
+
openWorldHint: z.boolean().optional(),
|
|
74
|
+
});
|
|
75
|
+
export const ToolCapability = z.strictObject({
|
|
76
|
+
name: ToolName,
|
|
77
|
+
title: z.string().max(240).nullable(),
|
|
78
|
+
description: z.string().max(10_000).nullable(),
|
|
79
|
+
inputSchema: z.record(z.string(), z.unknown()),
|
|
80
|
+
outputSchema: z.record(z.string(), z.unknown()).nullable(),
|
|
81
|
+
annotations: ToolAnnotations,
|
|
82
|
+
fingerprint: z.string().regex(/^[a-f0-9]{64}$/),
|
|
83
|
+
});
|
|
84
|
+
// The catalog reflects one live tools/list for the requesting user. It is never stored as a
|
|
85
|
+
// permission mirror, so there is no per-source state and no Intel-owned connection status.
|
|
86
|
+
export const ToolCatalog = z.strictObject({
|
|
87
|
+
portalConnected: z.boolean(),
|
|
88
|
+
items: z.array(ToolCapability),
|
|
89
|
+
/**
|
|
90
|
+
* Which delegated servers actually contributed a tool to this catalog (#289).
|
|
91
|
+
*
|
|
92
|
+
* ⚠️ Present only where the attribution was actually made — a delegated caller whose catalog was
|
|
93
|
+
* read. It is absent for an ordinary user, and absent as well when the answer comes from one of
|
|
94
|
+
* the short paths that never reach the portal (nothing delegated, no portal sign-in, connection
|
|
95
|
+
* dropped). Absent therefore means "not stated", never "nothing arrived"; `[]` is the second one.
|
|
96
|
+
*
|
|
97
|
+
* That it is missing rather than empty on those paths is deliberate rather than half-finished:
|
|
98
|
+
* the attribution already happens for a delegation — `capabilities` has to make it to cut the
|
|
99
|
+
* list — so naming it costs nothing there, while computing the same thing for an ordinary user
|
|
100
|
+
* would mean a second portal request per call, for a question their screen does not ask.
|
|
101
|
+
*
|
|
102
|
+
* ⚠️ It is the answer to "what arrived", never to "what was granted". A server missing here has
|
|
103
|
+
* been switched off, revoked, or is failing right now; the delegation in the definition is
|
|
104
|
+
* unchanged. Reading it the other way round would turn an outage into a permission change.
|
|
105
|
+
*/
|
|
106
|
+
reached: z.array(ToolServerHandle).optional(),
|
|
107
|
+
});
|
|
108
|
+
/**
|
|
109
|
+
* One MCP server the asking user reaches right now, as the portal itself names it (D30).
|
|
110
|
+
*
|
|
111
|
+
* ⚠️ `toolCount` is a fact about this moment and this user, not a size. It exists so a picker can
|
|
112
|
+
* say "9 tools" instead of showing a handle alone, and it must never be read as what an agent will
|
|
113
|
+
* get: the delegated run asks the portal again, with the delegator's token.
|
|
114
|
+
*/
|
|
115
|
+
export const ToolServer = z.strictObject({
|
|
116
|
+
handle: ToolServerHandle,
|
|
117
|
+
name: z.string().min(1).max(240),
|
|
118
|
+
toolCount: z.number().int().min(0),
|
|
119
|
+
});
|
|
120
|
+
// The same live-query rule as the tool catalog, one level up. `portalConnected: false` is the state
|
|
121
|
+
// of somebody who has not signed into the portal yet, and it is not an error.
|
|
122
|
+
export const ToolServerCatalog = z.strictObject({
|
|
123
|
+
portalConnected: z.boolean(),
|
|
124
|
+
items: z.array(ToolServer),
|
|
125
|
+
});
|
|
126
|
+
/**
|
|
127
|
+
* Which of the named servers a tool belongs to, or `null` for none of them.
|
|
128
|
+
*
|
|
129
|
+
* ⚠️ THE TRAP: a tool name does not say where its server name ends.
|
|
130
|
+
*
|
|
131
|
+
* The portal writes `<server>_<tool>`, and both halves may contain underscores — `intel_flow_get`
|
|
132
|
+
* reads equally well as server `intel` with tool `flow_get` and as a server called `intel_flow`
|
|
133
|
+
* with tool `get`. Splitting on the first underscore is therefore a guess that is wrong the day
|
|
134
|
+
* somebody adds a server whose name contains one, and on the API side being wrong means an agent
|
|
135
|
+
* delegated server A quietly reaching server B.
|
|
136
|
+
*
|
|
137
|
+
* So the prefix is never split. It is only ever MATCHED against handles the portal itself named,
|
|
138
|
+
* and the longest match wins: with `intel` and `intel_flow` both declared, `intel_flow_get` belongs
|
|
139
|
+
* to `intel_flow`, which is the only reading in which both declarations stay true.
|
|
140
|
+
*
|
|
141
|
+
* ⚠️ This lives in the contract because HOW A NAME IS READ is a property of the wire, and both
|
|
142
|
+
* surfaces read the same wire: `packages/api` cuts a delegation with it, `packages/ui` groups the
|
|
143
|
+
* tools screen with it (#212). A second implementation in the browser would be the third answer to
|
|
144
|
+
* one question — the underscore rule has already been answered differently in two places once
|
|
145
|
+
* (#106, #107), and the copies disagreed. What deliberately stays OUT of here is everything about
|
|
146
|
+
* reach: which handles are declared, which are enabled, which may be delegated and which one owns
|
|
147
|
+
* the portal's own management tools are decisions with consequences, and they belong to
|
|
148
|
+
* `packages/api/src/tools/tool-servers`. This function only reads a name.
|
|
149
|
+
*/
|
|
150
|
+
export function serverOf(toolName, handles) {
|
|
151
|
+
let best = null;
|
|
152
|
+
for (const handle of handles) {
|
|
153
|
+
if (!toolName.startsWith(`${handle}_`))
|
|
154
|
+
continue;
|
|
155
|
+
if (best === null || handle.length > best.length)
|
|
156
|
+
best = handle;
|
|
157
|
+
}
|
|
158
|
+
return best;
|
|
159
|
+
}
|
|
160
|
+
export const TestToolInput = z.strictObject({
|
|
161
|
+
name: ToolName.describe("The tool's full name as tool_list reported it, including the server handle it is prefixed with. The portal routes on that prefix, so a bare name reaches nothing."),
|
|
162
|
+
arguments: z
|
|
163
|
+
.record(z.string(), z.unknown())
|
|
164
|
+
.default({})
|
|
165
|
+
.describe("The arguments, shaped by that tool's own inputSchema from tool_list. Validated against it before anything is sent, so a wrong shape is refused here rather than by the far side."),
|
|
166
|
+
});
|
|
167
|
+
export const ExecuteToolInput = TestToolInput;
|
|
168
|
+
export const ToolTestResult = z.strictObject({
|
|
169
|
+
isError: z.boolean(),
|
|
170
|
+
content: z.array(z.unknown()),
|
|
171
|
+
structuredContent: z.unknown().optional(),
|
|
172
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anchrd/intel-contract",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -15,6 +15,34 @@
|
|
|
15
15
|
".": {
|
|
16
16
|
"types": "./dist/contract/contract.d.ts",
|
|
17
17
|
"default": "./dist/contract/contract.js"
|
|
18
|
+
},
|
|
19
|
+
"./bundle": {
|
|
20
|
+
"types": "./dist/contract/bundle.d.ts",
|
|
21
|
+
"default": "./dist/contract/bundle.js"
|
|
22
|
+
},
|
|
23
|
+
"./flow": {
|
|
24
|
+
"types": "./dist/contract/flow.d.ts",
|
|
25
|
+
"default": "./dist/contract/flow.js"
|
|
26
|
+
},
|
|
27
|
+
"./flow-run": {
|
|
28
|
+
"types": "./dist/contract/flow-run.d.ts",
|
|
29
|
+
"default": "./dist/contract/flow-run.js"
|
|
30
|
+
},
|
|
31
|
+
"./node": {
|
|
32
|
+
"types": "./dist/contract/node.d.ts",
|
|
33
|
+
"default": "./dist/contract/node.js"
|
|
34
|
+
},
|
|
35
|
+
"./share": {
|
|
36
|
+
"types": "./dist/contract/share.d.ts",
|
|
37
|
+
"default": "./dist/contract/share.js"
|
|
38
|
+
},
|
|
39
|
+
"./table": {
|
|
40
|
+
"types": "./dist/contract/table.d.ts",
|
|
41
|
+
"default": "./dist/contract/table.js"
|
|
42
|
+
},
|
|
43
|
+
"./tool": {
|
|
44
|
+
"types": "./dist/contract/tool.d.ts",
|
|
45
|
+
"default": "./dist/contract/tool.js"
|
|
18
46
|
}
|
|
19
47
|
},
|
|
20
48
|
"files": [
|