@anchrd/intel-contract 0.12.0 → 0.14.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.
@@ -0,0 +1,142 @@
1
+ import { z } from "zod";
2
+ export declare const ResourceVerb: z.ZodEnum<{
3
+ read: "read";
4
+ write: "write";
5
+ execute: "execute";
6
+ share: "share";
7
+ }>;
8
+ export type ResourceVerb = z.infer<typeof ResourceVerb>;
9
+ export declare const SharePrincipal: z.ZodDiscriminatedUnion<[z.ZodObject<{
10
+ type: z.ZodLiteral<"user">;
11
+ id: z.ZodString;
12
+ }, z.core.$strict>, z.ZodObject<{
13
+ type: z.ZodLiteral<"email">;
14
+ email: z.ZodEmail;
15
+ }, z.core.$strict>, z.ZodObject<{
16
+ type: z.ZodLiteral<"organization">;
17
+ }, z.core.$strict>], "type">;
18
+ export type SharePrincipal = z.infer<typeof SharePrincipal>;
19
+ export declare const ListGrantsInput: z.ZodObject<{
20
+ resourceId: z.ZodString;
21
+ }, z.core.$strict>;
22
+ export type ListGrantsInput = z.infer<typeof ListGrantsInput>;
23
+ export declare const ResourceGrant: z.ZodObject<{
24
+ id: z.ZodString;
25
+ resourceId: z.ZodString;
26
+ principal: z.ZodDiscriminatedUnion<[z.ZodObject<{
27
+ type: z.ZodLiteral<"user">;
28
+ id: z.ZodString;
29
+ }, z.core.$strict>, z.ZodObject<{
30
+ type: z.ZodLiteral<"email">;
31
+ email: z.ZodEmail;
32
+ }, z.core.$strict>, z.ZodObject<{
33
+ type: z.ZodLiteral<"organization">;
34
+ }, z.core.$strict>], "type">;
35
+ verb: z.ZodEnum<{
36
+ read: "read";
37
+ write: "write";
38
+ execute: "execute";
39
+ share: "share";
40
+ }>;
41
+ expiresAt: z.ZodNullable<z.ZodISODateTime>;
42
+ createdBy: z.ZodString;
43
+ createdAt: z.ZodISODateTime;
44
+ }, z.core.$strict>;
45
+ export type ResourceGrant = z.infer<typeof ResourceGrant>;
46
+ export declare const ShareInput: z.ZodObject<{
47
+ resourceId: z.ZodString;
48
+ principal: z.ZodDiscriminatedUnion<[z.ZodObject<{
49
+ type: z.ZodLiteral<"user">;
50
+ id: z.ZodString;
51
+ }, z.core.$strict>, z.ZodObject<{
52
+ type: z.ZodLiteral<"email">;
53
+ email: z.ZodEmail;
54
+ }, z.core.$strict>, z.ZodObject<{
55
+ type: z.ZodLiteral<"organization">;
56
+ }, z.core.$strict>], "type">;
57
+ verb: z.ZodEnum<{
58
+ read: "read";
59
+ write: "write";
60
+ execute: "execute";
61
+ share: "share";
62
+ }>;
63
+ expiresAt: z.ZodDefault<z.ZodNullable<z.ZodISODateTime>>;
64
+ idempotencyKey: z.ZodString;
65
+ }, z.core.$strict>;
66
+ export type ShareInput = z.infer<typeof ShareInput>;
67
+ export declare const RevokeGrantInput: z.ZodObject<{
68
+ resourceId: z.ZodString;
69
+ grantId: z.ZodString;
70
+ idempotencyKey: z.ZodString;
71
+ }, z.core.$strict>;
72
+ export type RevokeGrantInput = z.infer<typeof RevokeGrantInput>;
73
+ export declare const UnreadableNodes: z.ZodObject<{
74
+ titles: z.ZodArray<z.ZodString>;
75
+ hidden: z.ZodNumber;
76
+ }, z.core.$strict>;
77
+ export type UnreadableNodes = z.infer<typeof UnreadableNodes>;
78
+ export declare const ShareResult: z.ZodObject<{
79
+ grant: z.ZodObject<{
80
+ id: z.ZodString;
81
+ resourceId: z.ZodString;
82
+ principal: z.ZodDiscriminatedUnion<[z.ZodObject<{
83
+ type: z.ZodLiteral<"user">;
84
+ id: z.ZodString;
85
+ }, z.core.$strict>, z.ZodObject<{
86
+ type: z.ZodLiteral<"email">;
87
+ email: z.ZodEmail;
88
+ }, z.core.$strict>, z.ZodObject<{
89
+ type: z.ZodLiteral<"organization">;
90
+ }, z.core.$strict>], "type">;
91
+ verb: z.ZodEnum<{
92
+ read: "read";
93
+ write: "write";
94
+ execute: "execute";
95
+ share: "share";
96
+ }>;
97
+ expiresAt: z.ZodNullable<z.ZodISODateTime>;
98
+ createdBy: z.ZodString;
99
+ createdAt: z.ZodISODateTime;
100
+ }, z.core.$strict>;
101
+ unreadable: z.ZodObject<{
102
+ titles: z.ZodArray<z.ZodString>;
103
+ hidden: z.ZodNumber;
104
+ }, z.core.$strict>;
105
+ }, z.core.$strict>;
106
+ export type ShareResult = z.infer<typeof ShareResult>;
107
+ export declare const ResourceGrantList: z.ZodObject<{
108
+ resourceId: z.ZodString;
109
+ applicableVerbs: z.ZodArray<z.ZodEnum<{
110
+ read: "read";
111
+ write: "write";
112
+ execute: "execute";
113
+ share: "share";
114
+ }>>;
115
+ items: z.ZodArray<z.ZodObject<{
116
+ id: z.ZodString;
117
+ resourceId: z.ZodString;
118
+ principal: z.ZodDiscriminatedUnion<[z.ZodObject<{
119
+ type: z.ZodLiteral<"user">;
120
+ id: z.ZodString;
121
+ }, z.core.$strict>, z.ZodObject<{
122
+ type: z.ZodLiteral<"email">;
123
+ email: z.ZodEmail;
124
+ }, z.core.$strict>, z.ZodObject<{
125
+ type: z.ZodLiteral<"organization">;
126
+ }, z.core.$strict>], "type">;
127
+ verb: z.ZodEnum<{
128
+ read: "read";
129
+ write: "write";
130
+ execute: "execute";
131
+ share: "share";
132
+ }>;
133
+ expiresAt: z.ZodNullable<z.ZodISODateTime>;
134
+ createdBy: z.ZodString;
135
+ createdAt: z.ZodISODateTime;
136
+ }, z.core.$strict>>;
137
+ }, z.core.$strict>;
138
+ export type ResourceGrantList = z.infer<typeof ResourceGrantList>;
139
+ export declare const RevokeGrantResult: z.ZodObject<{
140
+ revoked: z.ZodBoolean;
141
+ }, z.core.$strict>;
142
+ export type RevokeGrantResult = z.infer<typeof RevokeGrantResult>;
@@ -0,0 +1,67 @@
1
+ import { z } from "zod";
2
+ import { IdempotencyKey, IntelId, IsoDateTime } from "./contract.js";
3
+ // ⚠️ There is no `ContextPolicy`, and it is not coming back in this shape (#76). It said whether a
4
+ // document should be pinned into a context, be found by relevance, or be named explicitly — an
5
+ // instruction to a retrieval Intel does not perform. Intel hands out references and the agent
6
+ // fetches what it needs (D24), so nothing here could ever have read it, and nothing did.
7
+ //
8
+ // Semantic search stays: as an MCP tool the agent calls, over everything or over one area.
9
+ // One verb per grant, granted independently (ADR-0004 §2). Not a ladder: seeing a process must be
10
+ // separable from being allowed to start it, and `execute` is meaningful only where a flow can live.
11
+ export const ResourceVerb = z.enum(["read", "write", "execute", "share"]);
12
+ export const SharePrincipal = z.discriminatedUnion("type", [
13
+ z.strictObject({ type: z.literal("user"), id: IntelId }),
14
+ z.strictObject({ type: z.literal("email"), email: z.email() }),
15
+ z.strictObject({ type: z.literal("organization") }),
16
+ ]);
17
+ export const ListGrantsInput = z.strictObject({
18
+ resourceId: IntelId.describe("Node whose direct grants to list. Access inherited from a folder above is not a grant on this node and is not listed here."),
19
+ });
20
+ export const ResourceGrant = z.strictObject({
21
+ id: IntelId,
22
+ resourceId: IntelId,
23
+ principal: SharePrincipal,
24
+ verb: ResourceVerb,
25
+ expiresAt: IsoDateTime.nullable(),
26
+ createdBy: IntelId,
27
+ createdAt: IsoDateTime,
28
+ });
29
+ export const ShareInput = z.strictObject({
30
+ resourceId: IntelId.describe("Node to grant access to. A grant on a folder is inherited by everything beneath it, which is the usual way to share a whole area."),
31
+ principal: SharePrincipal.describe("Who gets the access: a Gate user by id, someone by verified email address, or the whole organization."),
32
+ verb: ResourceVerb.describe("What they may do. Each verb is granted on its own and none implies another: `read` reads, `write` writes, `execute` runs a flow, `share` passes access on. Seeing a process is deliberately separable from being allowed to start it."),
33
+ expiresAt: IsoDateTime.nullable()
34
+ .default(null)
35
+ .describe("When the grant stops working, or `null` for one that does not expire on its own."),
36
+ idempotencyKey: IdempotencyKey,
37
+ });
38
+ export const RevokeGrantInput = z.strictObject({
39
+ resourceId: IntelId.describe("Node the grant sits on. Named alongside the grant id so access is decided on the node."),
40
+ grantId: IntelId.describe("The grant to withdraw, from node_grant_list."),
41
+ idempotencyKey: IdempotencyKey,
42
+ });
43
+ // What a grant does not cover, reported to whoever just made it. A flow in the shared folder may
44
+ // read a document outside it, and the run is re-authorized against the person running it — so the
45
+ // grant can be complete and the flow still stop for them (ADR-0004 §4).
46
+ //
47
+ // ⚠️ `titles` holds only the documents the sharer may see; everything else is in `hidden` as a
48
+ // number. A warning must not become a way of reading titles out of the tree.
49
+ export const UnreadableNodes = z.strictObject({
50
+ titles: z.array(z.string().min(1).max(240)),
51
+ hidden: z.number().int().nonnegative(),
52
+ });
53
+ // The grant is in the answer, so the warning cannot be mistaken for a refusal: it is written first
54
+ // and described afterwards. Blocking would force everyone who uses a central policy document to
55
+ // duplicate it, which is the opposite of what one tree is for (ADR-0004 §4).
56
+ export const ShareResult = z.strictObject({
57
+ grant: ResourceGrant,
58
+ unreadable: UnreadableNodes,
59
+ });
60
+ // `applicableVerbs` travels with the list because the answer is the business layer's, not the
61
+ // screen's: a document has nothing to execute, so `execute` is not offered on one (ADR-0004 §2).
62
+ export const ResourceGrantList = z.strictObject({
63
+ resourceId: IntelId,
64
+ applicableVerbs: z.array(ResourceVerb).min(1),
65
+ items: z.array(ResourceGrant),
66
+ });
67
+ export const RevokeGrantResult = z.strictObject({ revoked: z.boolean() });
@@ -0,0 +1,162 @@
1
+ import { z } from "zod";
2
+ export declare const TableMediaType = "text/csv";
3
+ export declare const TableColumn: z.ZodString;
4
+ export declare const TableCell: z.ZodString;
5
+ export declare const TableRow: z.ZodArray<z.ZodString>;
6
+ export declare const DefineTableInput: z.ZodObject<{
7
+ nodeId: z.ZodString;
8
+ columns: z.ZodArray<z.ZodString>;
9
+ idempotencyKey: z.ZodString;
10
+ }, z.core.$strict>;
11
+ export type DefineTableInput = z.infer<typeof DefineTableInput>;
12
+ export declare const AppendTableRowsInput: z.ZodObject<{
13
+ nodeId: z.ZodString;
14
+ rows: z.ZodArray<z.ZodArray<z.ZodString>>;
15
+ idempotencyKey: z.ZodString;
16
+ }, z.core.$strict>;
17
+ export type AppendTableRowsInput = z.infer<typeof AppendTableRowsInput>;
18
+ export declare const GetTableInput: z.ZodObject<{
19
+ nodeId: z.ZodString;
20
+ }, z.core.$strict>;
21
+ export type GetTableInput = z.infer<typeof GetTableInput>;
22
+ export declare const AppendTableRowsResult: z.ZodObject<{
23
+ node: z.ZodObject<{
24
+ id: z.ZodString;
25
+ parentId: z.ZodNullable<z.ZodString>;
26
+ kind: z.ZodEnum<{
27
+ folder: "folder";
28
+ document: "document";
29
+ table: "table";
30
+ attachment: "attachment";
31
+ }>;
32
+ title: z.ZodString;
33
+ description: z.ZodNullable<z.ZodString>;
34
+ ownerId: z.ZodString;
35
+ currentVersionId: z.ZodNullable<z.ZodString>;
36
+ createdAt: z.ZodISODateTime;
37
+ updatedAt: z.ZodISODateTime;
38
+ archivedAt: z.ZodNullable<z.ZodISODateTime>;
39
+ }, z.core.$strict>;
40
+ version: z.ZodObject<{
41
+ id: z.ZodString;
42
+ nodeId: z.ZodString;
43
+ sequence: z.ZodNumber;
44
+ contentKey: z.ZodString;
45
+ mediaType: z.ZodString;
46
+ contentHash: z.ZodString;
47
+ size: z.ZodNumber;
48
+ segment: z.ZodNullable<z.ZodEnum<{
49
+ append: "append";
50
+ snapshot: "snapshot";
51
+ }>>;
52
+ createdBy: z.ZodString;
53
+ createdAt: z.ZodISODateTime;
54
+ }, z.core.$strict>;
55
+ appended: z.ZodNumber;
56
+ }, z.core.$strict>;
57
+ export type AppendTableRowsResult = z.infer<typeof AppendTableRowsResult>;
58
+ export declare const TableRowPosition: z.ZodNumber;
59
+ export declare const UpdateTableRowsInput: z.ZodObject<{
60
+ nodeId: z.ZodString;
61
+ baseVersionId: z.ZodString;
62
+ updates: z.ZodArray<z.ZodObject<{
63
+ position: z.ZodNumber;
64
+ row: z.ZodArray<z.ZodString>;
65
+ }, z.core.$strict>>;
66
+ idempotencyKey: z.ZodString;
67
+ }, z.core.$strict>;
68
+ export type UpdateTableRowsInput = z.infer<typeof UpdateTableRowsInput>;
69
+ export declare const UpdateTableRowsResult: z.ZodObject<{
70
+ node: z.ZodObject<{
71
+ id: z.ZodString;
72
+ parentId: z.ZodNullable<z.ZodString>;
73
+ kind: z.ZodEnum<{
74
+ folder: "folder";
75
+ document: "document";
76
+ table: "table";
77
+ attachment: "attachment";
78
+ }>;
79
+ title: z.ZodString;
80
+ description: z.ZodNullable<z.ZodString>;
81
+ ownerId: z.ZodString;
82
+ currentVersionId: z.ZodNullable<z.ZodString>;
83
+ createdAt: z.ZodISODateTime;
84
+ updatedAt: z.ZodISODateTime;
85
+ archivedAt: z.ZodNullable<z.ZodISODateTime>;
86
+ }, z.core.$strict>;
87
+ version: z.ZodObject<{
88
+ id: z.ZodString;
89
+ nodeId: z.ZodString;
90
+ sequence: z.ZodNumber;
91
+ contentKey: z.ZodString;
92
+ mediaType: z.ZodString;
93
+ contentHash: z.ZodString;
94
+ size: z.ZodNumber;
95
+ segment: z.ZodNullable<z.ZodEnum<{
96
+ append: "append";
97
+ snapshot: "snapshot";
98
+ }>>;
99
+ createdBy: z.ZodString;
100
+ createdAt: z.ZodISODateTime;
101
+ }, z.core.$strict>;
102
+ updated: z.ZodNumber;
103
+ }, z.core.$strict>;
104
+ export type UpdateTableRowsResult = z.infer<typeof UpdateTableRowsResult>;
105
+ export declare const DeleteTableRowsInput: z.ZodObject<{
106
+ nodeId: z.ZodString;
107
+ baseVersionId: z.ZodString;
108
+ positions: z.ZodArray<z.ZodNumber>;
109
+ idempotencyKey: z.ZodString;
110
+ }, z.core.$strict>;
111
+ export type DeleteTableRowsInput = z.infer<typeof DeleteTableRowsInput>;
112
+ export declare const DeleteTableRowsResult: z.ZodObject<{
113
+ node: z.ZodObject<{
114
+ id: z.ZodString;
115
+ parentId: z.ZodNullable<z.ZodString>;
116
+ kind: z.ZodEnum<{
117
+ folder: "folder";
118
+ document: "document";
119
+ table: "table";
120
+ attachment: "attachment";
121
+ }>;
122
+ title: z.ZodString;
123
+ description: z.ZodNullable<z.ZodString>;
124
+ ownerId: z.ZodString;
125
+ currentVersionId: z.ZodNullable<z.ZodString>;
126
+ createdAt: z.ZodISODateTime;
127
+ updatedAt: z.ZodISODateTime;
128
+ archivedAt: z.ZodNullable<z.ZodISODateTime>;
129
+ }, z.core.$strict>;
130
+ version: z.ZodObject<{
131
+ id: z.ZodString;
132
+ nodeId: z.ZodString;
133
+ sequence: z.ZodNumber;
134
+ contentKey: z.ZodString;
135
+ mediaType: z.ZodString;
136
+ contentHash: z.ZodString;
137
+ size: z.ZodNumber;
138
+ segment: z.ZodNullable<z.ZodEnum<{
139
+ append: "append";
140
+ snapshot: "snapshot";
141
+ }>>;
142
+ createdBy: z.ZodString;
143
+ createdAt: z.ZodISODateTime;
144
+ }, z.core.$strict>;
145
+ deleted: z.ZodNumber;
146
+ }, z.core.$strict>;
147
+ export type DeleteTableRowsResult = z.infer<typeof DeleteTableRowsResult>;
148
+ export declare const RedefineTableColumn: z.ZodObject<{
149
+ name: z.ZodString;
150
+ source: z.ZodDefault<z.ZodNullable<z.ZodString>>;
151
+ }, z.core.$strict>;
152
+ export type RedefineTableColumn = z.infer<typeof RedefineTableColumn>;
153
+ export declare const RedefineTableInput: z.ZodObject<{
154
+ nodeId: z.ZodString;
155
+ baseVersionId: z.ZodString;
156
+ columns: z.ZodArray<z.ZodObject<{
157
+ name: z.ZodString;
158
+ source: z.ZodDefault<z.ZodNullable<z.ZodString>>;
159
+ }, z.core.$strict>>;
160
+ idempotencyKey: z.ZodString;
161
+ }, z.core.$strict>;
162
+ export type RedefineTableInput = z.infer<typeof RedefineTableInput>;
@@ -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>;