@anchrd/intel-api 0.14.0 → 0.16.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.
Files changed (60) hide show
  1. package/dist/adapters/cloudflare/cloudflare.js +0 -68
  2. package/dist/adapters/cloudflare/cloudflare.types.d.ts +0 -39
  3. package/dist/adapters/db/db-flows.js +3 -2
  4. package/dist/adapters/db/db-grants.d.ts +1 -1
  5. package/dist/adapters/db/db-grants.js +1 -1
  6. package/dist/adapters/db/db.js +16 -113
  7. package/dist/adapters/openid/openid.js +1 -1
  8. package/dist/adapters/remote-tools/remote-tools.js +1 -1
  9. package/dist/bundle/bundle.js +31 -141
  10. package/dist/bundle/bundle.types.d.ts +1 -1
  11. package/dist/cli/cli.js +18 -11
  12. package/dist/flows/flows.d.ts +1 -1
  13. package/dist/flows/flows.js +1 -1
  14. package/dist/flows/flows.types.d.ts +4 -1
  15. package/dist/http/http.js +43 -238
  16. package/dist/http/http.types.d.ts +0 -8
  17. package/dist/indexing/indexing.js +18 -89
  18. package/dist/intel/intel.js +4 -9
  19. package/dist/intel/intel.types.d.ts +0 -6
  20. package/dist/mcp/mcp.js +84 -361
  21. package/dist/mcp/mcp.types.d.ts +2 -7
  22. package/dist/nodes/document-links/document-links.d.ts +6 -8
  23. package/dist/nodes/document-links/document-links.js +8 -31
  24. package/dist/nodes/nodes.js +24 -890
  25. package/dist/nodes/nodes.types.d.ts +14 -173
  26. package/dist/tools/tool-servers/tool-servers.d.ts +1 -1
  27. package/dist/tools/tool-servers/tool-servers.js +1 -1
  28. package/dist/tools/tools.js +37 -148
  29. package/dist/tools/tools.types.d.ts +1 -22
  30. package/migrations/0018_no_context_policy_at_last.sql +13 -6
  31. package/migrations/0019_one_name_for_the_grants.sql +52 -0
  32. package/package.json +2 -2
  33. package/dist/adapters/cloudflare-api/cloudflare-api.d.ts +0 -22
  34. package/dist/adapters/cloudflare-api/cloudflare-api.js +0 -306
  35. package/dist/adapters/cloudflare-api/cloudflare-api.types.d.ts +0 -64
  36. package/dist/adapters/cloudflare-api/cloudflare-api.types.js +0 -1
  37. package/dist/adapters/gate-applications/gate-applications.d.ts +0 -23
  38. package/dist/adapters/gate-applications/gate-applications.js +0 -88
  39. package/dist/adapters/tool-delegation/tool-delegation.d.ts +0 -22
  40. package/dist/adapters/tool-delegation/tool-delegation.js +0 -90
  41. package/dist/agent-costs/agent-costs.d.ts +0 -16
  42. package/dist/agent-costs/agent-costs.js +0 -105
  43. package/dist/agent-costs/agent-costs.types.d.ts +0 -30
  44. package/dist/agent-costs/agent-costs.types.js +0 -1
  45. package/dist/agent-runtime/agent-runtime.d.ts +0 -16
  46. package/dist/agent-runtime/agent-runtime.js +0 -150
  47. package/dist/agent-runtime/agent-runtime.types.d.ts +0 -122
  48. package/dist/agent-runtime/agent-runtime.types.js +0 -1
  49. package/dist/model-catalog/model-catalog.d.ts +0 -2
  50. package/dist/model-catalog/model-catalog.js +0 -99
  51. package/dist/model-catalog/model-catalog.types.d.ts +0 -15
  52. package/dist/model-catalog/model-catalog.types.js +0 -1
  53. package/dist/nodes/board/board.d.ts +0 -61
  54. package/dist/nodes/board/board.js +0 -826
  55. package/dist/nodes/board/board.types.d.ts +0 -38
  56. package/dist/nodes/board/board.types.js +0 -1
  57. package/migrations/0013_agents_in_the_tree.sql +0 -76
  58. package/migrations/0014_agent_applications.sql +0 -25
  59. package/migrations/0015_tools_delegated_from_a_connection.sql +0 -15
  60. package/migrations/0016_boards_in_the_tree.sql +0 -80
@@ -1,38 +0,0 @@
1
- import type { AddBoardTaskInput, BoardDocument, BoardStatusInput, BoardTask, MoveBoardTaskInput, UpdateBoardTaskInput } from "@anchrd/intel-contract";
2
- export interface BoardDeps {
3
- id(): string;
4
- }
5
- export interface BoardPlacement {
6
- status: string;
7
- parentId: string | null;
8
- afterTaskId: string | null;
9
- beforeTaskId: string | null;
10
- }
11
- export interface BoardOperations {
12
- defaultBoard(): BoardDocument;
13
- configure(board: BoardDocument, statuses: BoardStatusInput[]): BoardDocument;
14
- addTask(board: BoardDocument, input: AddBoardTaskInput): {
15
- board: BoardDocument;
16
- task: BoardTask;
17
- };
18
- updateTask(board: BoardDocument, input: UpdateBoardTaskInput): {
19
- board: BoardDocument;
20
- task: BoardTask;
21
- };
22
- moveTask(board: BoardDocument, input: MoveBoardTaskInput): {
23
- board: BoardDocument;
24
- task: BoardTask;
25
- };
26
- deleteTask(board: BoardDocument, taskId: string): {
27
- board: BoardDocument;
28
- deleted: number;
29
- };
30
- repairTaskIds(board: BoardDocument): {
31
- board: BoardDocument;
32
- renumbered: {
33
- previousId: string;
34
- task: BoardTask;
35
- }[];
36
- };
37
- sorted(tasks: readonly BoardTask[]): BoardTask[];
38
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,76 +0,0 @@
1
- -- #139: a fifth kind in the shared tree — `agent`. It is a node like the other four: same
2
- -- `parent_id`, same folder grants, same immutable `node_versions` rows, same R2 body (ADR-0005 §1).
3
- -- Its body happens to be a JSON definition rather than prose, which the schema neither knows nor
4
- -- needs to: nothing here creates a second content model, only the CHECK has to learn the word.
5
- --
6
- -- SQLite cannot alter a CHECK constraint, so the table is rebuilt — the same rebuild 0005 performed
7
- -- for `table`, written the same long way round for the same two reasons. Both detours below are
8
- -- copied from a file that earned them against a real database, not from caution.
9
- --
10
- -- ⚠️ First detour: the new table is created under the final name rather than built beside the old
11
- -- one and renamed over it. `DROP TABLE` on a parent runs an implicit `DELETE FROM` first, so the
12
- -- moment the old `nodes` goes, every row of `node_versions`, `tree_grants` and `flows` pointing at a
13
- -- node is a foreign-key violation. `defer_foreign_keys` postpones the complaint to COMMIT but does
14
- -- not withdraw it, and `ALTER TABLE ... RENAME` does not settle it either: a rename puts the name
15
- -- back, not the rows. Only inserting the nodes again, under the name the children have referenced
16
- -- all along, does. This is also why the self-reference below reads `REFERENCES nodes(id)` — the
17
- -- final name — which is lesson 2 of the three recorded in `0009_no_context_policy.sql`.
18
- --
19
- -- ⚠️ Second detour: `node_links` is the only child of `nodes` declared ON DELETE CASCADE, so that
20
- -- same implicit delete does not merely flag its rows, it removes them — the migration would commit
21
- -- with every relationship between two documents quietly gone. The rows are carried out of the way
22
- -- first and put back afterwards. That is a rescue, not a decision about the data: nothing is
23
- -- dropped, rewritten or reinterpreted here.
24
- --
25
- -- ⚠️ On an empty database neither detour is visible, because nothing points at anything. That is
26
- -- exactly how 0005's first version passed a green suite and then failed against the first database
27
- -- with content in it, and why the proof for this file is a row count of every referencing table
28
- -- before and after rather than a migration that merely ran.
29
- --
30
- -- `context_policy` is carried over unchanged and still NOT NULL. It is dead for every consumer
31
- -- (#76) and only D1's refusal to drop a column a CHECK names keeps it here; removing it is #86 and
32
- -- deliberately not smuggled into this rebuild.
33
- PRAGMA defer_foreign_keys = TRUE;
34
-
35
- -- Plain holding tables on purpose: no keys, no CHECKs, no foreign keys, and the column set taken
36
- -- from whatever the live table has. Anything enforced here would only be enforced a second time on
37
- -- the way back in, and a holding table that can reject a row is a holding table that can lose one.
38
- CREATE TABLE nodes_carry AS SELECT * FROM nodes;
39
- CREATE TABLE node_links_carry AS SELECT * FROM node_links;
40
-
41
- DROP TABLE nodes;
42
-
43
- CREATE TABLE nodes (
44
- id TEXT PRIMARY KEY NOT NULL,
45
- parent_id TEXT REFERENCES nodes(id),
46
- kind TEXT NOT NULL CHECK (kind IN ('folder', 'document', 'attachment', 'table', 'agent')),
47
- title TEXT NOT NULL CHECK (length(title) BETWEEN 1 AND 240),
48
- description TEXT CHECK (description IS NULL OR length(description) <= 2000),
49
- context_policy TEXT NOT NULL CHECK (context_policy IN ('pinned', 'relevant', 'explicit')),
50
- owner_id TEXT NOT NULL,
51
- current_version_id TEXT,
52
- created_at TEXT NOT NULL,
53
- updated_at TEXT NOT NULL,
54
- archived_at TEXT
55
- );
56
-
57
- INSERT INTO nodes (
58
- id, parent_id, kind, title, description, context_policy, owner_id,
59
- current_version_id, created_at, updated_at, archived_at
60
- )
61
- SELECT
62
- id, parent_id, kind, title, description, context_policy, owner_id,
63
- current_version_id, created_at, updated_at, archived_at
64
- FROM nodes_carry;
65
-
66
- -- `OR IGNORE` because whether the cascade above actually fired is SQLite's business, not this
67
- -- migration's: if it did, this puts the rows back; if it did not, each one is already present under
68
- -- the same primary key and this is a no-op. Either way `node_links` ends up holding exactly what it
69
- -- held before, which is the only outcome this statement is permitted to have.
70
- INSERT OR IGNORE INTO node_links SELECT * FROM node_links_carry;
71
-
72
- DROP TABLE nodes_carry;
73
- DROP TABLE node_links_carry;
74
-
75
- CREATE INDEX nodes_parent_idx ON nodes(parent_id, archived_at, title);
76
- CREATE INDEX nodes_owner_idx ON nodes(owner_id, archived_at);
@@ -1,25 +0,0 @@
1
- -- #182: which Gate Application an agent node runs as. One row per agent that has a principal, and
2
- -- nothing else — the row is a NAME, never a credential.
3
- --
4
- -- ⚠️ The Application KEY has no column here and must never get one (D27). Gate hands a key out once
5
- -- in plain text and keeps only its hash, so there is nothing to store even in principle; the key
6
- -- lives in the runtime's `AGENT_APPLICATION_KEYS` secret and reaches it through the one response
7
- -- that created the agent. A column for it would turn every backup of this database into a set of
8
- -- machine credentials.
9
- --
10
- -- ⚠️ A table rather than a column on `nodes`, for two reasons. The column would be NULL for every
11
- -- folder, document, attachment and table there will ever be, which is a shape that says nothing
12
- -- about four of the five kinds; and adding it would mean rebuilding `nodes` — SQLite cannot alter
13
- -- a table a CHECK constrains — with the two detours `0013_agents_in_the_tree.sql` records. This
14
- -- file writes one new table and touches nothing that exists.
15
- --
16
- -- ⚠️ Deliberately NOT `ON DELETE CASCADE`, unlike `node_links`. Migration 0013 explains what that
17
- -- one cascade cost the rebuild it had to survive: an implicit `DELETE FROM` on the parent removed
18
- -- its rows outright rather than merely flagging them, and they had to be carried out of the way and
19
- -- put back. A second cascading child would hand the next rebuild the same trap twice. Nodes are
20
- -- archived, never deleted, so nothing is being kept alive by leaving the cascade off.
21
- CREATE TABLE agent_applications (
22
- node_id TEXT PRIMARY KEY NOT NULL REFERENCES nodes(id),
23
- application_id TEXT NOT NULL,
24
- created_at TEXT NOT NULL
25
- );
@@ -1,15 +0,0 @@
1
- -- #208 (D30): an agent's tools are whole MCP servers its owner delegated from the owner's own
2
- -- portal connection. Nothing about that selection is stored here — it lives in the agent's
3
- -- definition, versioned in R2 like the rest of the document.
4
- --
5
- -- What this file adds is the one lookup the run path needs and `0014` did not provide: a call
6
- -- arrives authenticated as a Gate Application, and Intel has to answer "which agent is that"
7
- -- before it may read anybody's portal token. `0014` indexed `node_id` only (it is the primary
8
- -- key), so the reverse question was a table scan on every delegated tool call.
9
- --
10
- -- ⚠️ UNIQUE, not just an index. Two agents sharing one Application would make the lookup ambiguous
11
- -- and would hand one agent the other's delegation — the same class of hole `AGENT_APPLICATION_KEYS`
12
- -- refuses a doubly listed id for (D27). The constraint is what makes "one Application per agent"
13
- -- a fact of the database rather than a promise of the code that writes it.
14
- CREATE UNIQUE INDEX agent_applications_application_idx
15
- ON agent_applications(application_id);
@@ -1,80 +0,0 @@
1
- -- #285: a sixth kind in the shared tree — `board`. It is a node like the other five: same
2
- -- `parent_id`, same folder grants, same immutable `node_versions` rows, same R2 body (ADR-0004 §1).
3
- -- Its body happens to be a JSON project board rather than prose, which the schema neither knows nor
4
- -- needs to: nothing here creates a second content model, only the CHECK has to learn the word.
5
- --
6
- -- A board's tasks live INSIDE that one body and get no table of their own. That is the decision the
7
- -- ticket makes: a board with three hundred tasks is one node in the tree, not three hundred, and
8
- -- nothing about the tree has to behave differently because a board is filed in it.
9
- --
10
- -- SQLite cannot alter a CHECK constraint, so the table is rebuilt — the same rebuild 0005 and 0013
11
- -- performed for `table` and `agent`, written the same long way round for the same two reasons. Both
12
- -- detours below are copied from a file that earned them against a real database, not from caution.
13
- --
14
- -- ⚠️ First detour: the new table is created under the final name rather than built beside the old
15
- -- one and renamed over it. `DROP TABLE` on a parent runs an implicit `DELETE FROM` first, so the
16
- -- moment the old `nodes` goes, every row of `node_versions`, `tree_grants` and `flows` pointing at a
17
- -- node is a foreign-key violation. `defer_foreign_keys` postpones the complaint to COMMIT but does
18
- -- not withdraw it, and `ALTER TABLE ... RENAME` does not settle it either: a rename puts the name
19
- -- back, not the rows. Only inserting the nodes again, under the name the children have referenced
20
- -- all along, does. This is also why the self-reference below reads `REFERENCES nodes(id)` — the
21
- -- final name — which is lesson 2 of the three recorded in `0009_no_context_policy.sql`.
22
- --
23
- -- ⚠️ Second detour: `node_links` is the only child of `nodes` declared ON DELETE CASCADE, so that
24
- -- same implicit delete does not merely flag its rows, it removes them — the migration would commit
25
- -- with every relationship between two documents quietly gone. The rows are carried out of the way
26
- -- first and put back afterwards. That is a rescue, not a decision about the data: nothing is
27
- -- dropped, rewritten or reinterpreted here.
28
- --
29
- -- ⚠️ On an empty database neither detour is visible, because nothing points at anything. That is
30
- -- exactly how 0005's first version passed a green suite and then failed against the first database
31
- -- with content in it, and why the proof for this file is a row count of every referencing table
32
- -- before and after rather than a migration that merely ran.
33
- --
34
- -- `context_policy` is carried over unchanged and still NOT NULL. It is dead for every consumer
35
- -- (#76) and only D1's refusal to drop a column a CHECK names keeps it here; removing it is #86 and
36
- -- deliberately not smuggled into this rebuild.
37
- PRAGMA defer_foreign_keys = TRUE;
38
-
39
- -- Plain holding tables on purpose: no keys, no CHECKs, no foreign keys, and the column set taken
40
- -- from whatever the live table has. Anything enforced here would only be enforced a second time on
41
- -- the way back in, and a holding table that can reject a row is a holding table that can lose one.
42
- CREATE TABLE nodes_carry AS SELECT * FROM nodes;
43
- CREATE TABLE node_links_carry AS SELECT * FROM node_links;
44
-
45
- DROP TABLE nodes;
46
-
47
- CREATE TABLE nodes (
48
- id TEXT PRIMARY KEY NOT NULL,
49
- parent_id TEXT REFERENCES nodes(id),
50
- kind TEXT NOT NULL CHECK (kind IN ('folder', 'document', 'attachment', 'table', 'agent', 'board')),
51
- title TEXT NOT NULL CHECK (length(title) BETWEEN 1 AND 240),
52
- description TEXT CHECK (description IS NULL OR length(description) <= 2000),
53
- context_policy TEXT NOT NULL CHECK (context_policy IN ('pinned', 'relevant', 'explicit')),
54
- owner_id TEXT NOT NULL,
55
- current_version_id TEXT,
56
- created_at TEXT NOT NULL,
57
- updated_at TEXT NOT NULL,
58
- archived_at TEXT
59
- );
60
-
61
- INSERT INTO nodes (
62
- id, parent_id, kind, title, description, context_policy, owner_id,
63
- current_version_id, created_at, updated_at, archived_at
64
- )
65
- SELECT
66
- id, parent_id, kind, title, description, context_policy, owner_id,
67
- current_version_id, created_at, updated_at, archived_at
68
- FROM nodes_carry;
69
-
70
- -- `OR IGNORE` because whether the cascade above actually fired is SQLite's business, not this
71
- -- migration's: if it did, this puts the rows back; if it did not, each one is already present under
72
- -- the same primary key and this is a no-op. Either way `node_links` ends up holding exactly what it
73
- -- held before, which is the only outcome this statement is permitted to have.
74
- INSERT OR IGNORE INTO node_links SELECT * FROM node_links_carry;
75
-
76
- DROP TABLE nodes_carry;
77
- DROP TABLE node_links_carry;
78
-
79
- CREATE INDEX nodes_parent_idx ON nodes(parent_id, archived_at, title);
80
- CREATE INDEX nodes_owner_idx ON nodes(owner_id, archived_at);