@adonis-agora/agent 0.24.0 → 0.25.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/CHANGELOG.md CHANGED
@@ -1,5 +1,38 @@
1
1
  # @adonis-agora/agent
2
2
 
3
+ ## 0.25.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#74](https://github.com/DavideCarvalho/adonis-agora-agent/pull/74) [`9776fdc`](https://github.com/DavideCarvalho/adonis-agora-agent/commit/9776fdce96ab283f76bb24c6a31610e9ea91e17d) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Fix the published migration, which threw against any database the library had already provisioned.
8
+
9
+ `node ace configure @adonis-agora/agent` published `create_agent_tables` as raw DDL —
10
+ `this.schema.createTable('agent_thread', ...)` with no existence guard. But `autoCreateTables`
11
+ defaults to `true`, and the first use of any of the three stores that share those tables (the agent
12
+ store, the pricing store, the governance read-model) provisions them. So in any app that had run the
13
+ agent even once before migrating, `node ace migration:run` died with `table "agent_thread" already
14
+ exists`. Reported from a real consumer upgrade.
15
+
16
+ The stub now delegates to `createAgentTables` / `dropAgentTables` instead of reproducing the DDL, with
17
+ `disableTransactions = true` (the helper takes its own pooled connection, which would otherwise
18
+ deadlock against `pool: { max: 1 }`). Drift stops being something to test for and becomes impossible:
19
+ the migration and the auto-created schema are the same code.
20
+
21
+ The separate `create_agent_run_tracking` stub is gone — one schema, one migration. Its `run_id` columns
22
+ were already inline in the table DDL for a fresh database, and `createAgentTables` now also ALTERs them
23
+ into a database provisioned before run tracking shipped, so collapsing the two loses no upgrade path.
24
+ That repair also fixes `autoCreateTables` on such a database, where the missing columns were previously
25
+ never added at all.
26
+
27
+ `create_agent_rag_chunks` had the same unguarded `createTable`; it now provisions through
28
+ `PgVectorStore.ensureSchema()`.
29
+
30
+ `createAgentTables` now resolves to the list of repairs it applied (it returned nothing before). Callers that only `await` it are unaffected.
31
+
32
+ **No action needed.** Migrations you have already run stay applied; this only changes what `configure`
33
+ generates from here on. If your `migration:run` was failing, re-run `node ace configure` and delete the
34
+ old `create_agent_tables` / `create_agent_run_tracking` files it had published.
35
+
3
36
  ## 0.24.0
4
37
 
5
38
  ### Minor Changes
@@ -13,11 +13,10 @@ import type Configure from '@adonisjs/core/commands/configure';
13
13
  * runtime scan when the barrel is absent);
14
14
  * 4. publishes `config/agent.ts`;
15
15
  * 5. publishes `config/mcp.ts` (the MCP endpoint config; the MCP provider is separate);
16
- * 6. publishes the Lucid migration for the five agent tables (run `node ace migration:run`; delete it
17
- * if you only use the in-memory store);
18
- * 7. publishes the additive run-tracking migration (`agent_run` table + `run_id` columns) — run it
19
- * after the base migration; delete it with the base one if you only use the in-memory store;
20
- * 8. publishes the pgvector migration for the RAG chunk table (Postgres + pgvector only; delete it
16
+ * 6. publishes the Lucid migration for the six agent tables (run `node ace migration:run`; delete it
17
+ * if you only use the in-memory store). It delegates to `createAgentTables`, so it is idempotent
18
+ * and safe to run against a database the library already auto-created;
19
+ * 7. publishes the pgvector migration for the RAG chunk table (Postgres + pgvector only; delete it
21
20
  * unless you use `retrievers.pgvector({...})`).
22
21
  */
23
22
  export declare function configure(command: Configure): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"configure.d.ts","sourceRoot":"","sources":["../configure.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,mCAAmC,CAAC;AAG/D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,SAAS,CAAC,OAAO,EAAE,SAAS,iBAejD"}
1
+ {"version":3,"file":"configure.d.ts","sourceRoot":"","sources":["../configure.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,mCAAmC,CAAC;AAG/D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,SAAS,CAAC,OAAO,EAAE,SAAS,iBAcjD"}
package/dist/configure.js CHANGED
@@ -13,11 +13,10 @@ import { stubsRoot } from './stubs/main.js';
13
13
  * runtime scan when the barrel is absent);
14
14
  * 4. publishes `config/agent.ts`;
15
15
  * 5. publishes `config/mcp.ts` (the MCP endpoint config; the MCP provider is separate);
16
- * 6. publishes the Lucid migration for the five agent tables (run `node ace migration:run`; delete it
17
- * if you only use the in-memory store);
18
- * 7. publishes the additive run-tracking migration (`agent_run` table + `run_id` columns) — run it
19
- * after the base migration; delete it with the base one if you only use the in-memory store;
20
- * 8. publishes the pgvector migration for the RAG chunk table (Postgres + pgvector only; delete it
16
+ * 6. publishes the Lucid migration for the six agent tables (run `node ace migration:run`; delete it
17
+ * if you only use the in-memory store). It delegates to `createAgentTables`, so it is idempotent
18
+ * and safe to run against a database the library already auto-created;
19
+ * 7. publishes the pgvector migration for the RAG chunk table (Postgres + pgvector only; delete it
21
20
  * unless you use `retrievers.pgvector({...})`).
22
21
  */
23
22
  export async function configure(command) {
@@ -31,7 +30,6 @@ export async function configure(command) {
31
30
  await codemods.makeUsingStub(stubsRoot, 'config/agent.stub', {});
32
31
  await codemods.makeUsingStub(stubsRoot, 'config/mcp.stub', {});
33
32
  await codemods.makeUsingStub(stubsRoot, 'database/migrations/create_agent_tables.stub', {});
34
- await codemods.makeUsingStub(stubsRoot, 'database/migrations/create_agent_run_tracking.stub', {});
35
33
  await codemods.makeUsingStub(stubsRoot, 'database/migrations/create_agent_rag_chunks.stub', {});
36
34
  }
37
35
  //# sourceMappingURL=configure.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"configure.js","sourceRoot":"","sources":["../configure.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,OAAkB;IAChD,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,cAAc,EAAE,CAAC;IAEhD,MAAM,QAAQ,CAAC,YAAY,CAAC,CAAC,MAAM,EAAE,EAAE;QACrC,MAAM,CAAC,WAAW,CAAC,oCAAoC,CAAC,CAAC;QACz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,iBAAiB,EAAE,EAAE,CAAC,CAAC;IAC/D,MAAM,QAAQ,CAAC,aAAa,CAAC,SAAS,EAAE,8CAA8C,EAAE,EAAE,CAAC,CAAC;IAC5F,MAAM,QAAQ,CAAC,aAAa,CAAC,SAAS,EAAE,kDAAkD,EAAE,EAAE,CAAC,CAAC;AAClG,CAAC"}
@@ -1,4 +1,4 @@
1
- export declare const VERSION = "0.24.0";
1
+ export declare const VERSION = "0.25.0";
2
2
  export * from './types.js';
3
3
  export * from './spi/tool.js';
4
4
  export * from './base-tool.js';
@@ -57,7 +57,7 @@ export type { RolesPolicy as ToolAuthorizer } from './spi/roles-policy.js';
57
57
  export { InlineAgentRunner } from './runners/inline-agent-runner.js';
58
58
  export { LucidAgentStore } from './stores/lucid.js';
59
59
  export type { LucidAgentStoreOptions, LucidDatabaseLike, LucidClientLike, LucidQueryBuilderLike, LucidInsertBuilderLike, } from './stores/lucid.js';
60
- export { createTableStatements, createAgentTables, ensureAgentTables, AGENT_TABLES, } from './stores/lucid-schema.js';
60
+ export { createTableStatements, createAgentTables, dropTableStatements, dropAgentTables, ensureAgentTables, AGENT_TABLES, } from './stores/lucid-schema.js';
61
61
  export { LedgerQuotaStore } from './stores/ledger-quota.js';
62
62
  export { LucidPricingStore } from './stores/lucid-pricing.js';
63
63
  export { LucidGovernanceQueries } from './stores/lucid-governance-queries.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,WAAW,CAAC;AAEhC,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC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AY,EACV,sBAAsB,EACtB,iBAAiB,EACjB,eAAe,EACf,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,iBAAiB,EACjB,YAAY,GACb,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAG9E,OAAO,EACL,QAAQ,EACR,YAAY,EACZ,kBAAkB,EAClB,sBAAsB,EACtB,mBAAmB,EACnB,WAAW,EACX,aAAa,GACd,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,cAAc,EACd,cAAc,EACd,WAAW,EACX,mBAAmB,EACnB,iBAAiB,EACjB,sBAAsB,EACtB,iBAAiB,EACjB,aAAa,GACd,MAAM,iBAAiB,CAAC;AAKzB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC"}
package/dist/src/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export const VERSION = '0.24.0';
1
+ export const VERSION = '0.25.0';
2
2
  export * from './types.js';
3
3
  export * from './spi/tool.js';
4
4
  export * from './base-tool.js';
@@ -43,7 +43,7 @@ export { AgentService } from './agent-service.js';
43
43
  export { DefaultToolAuthorizer } from './authorizer.js';
44
44
  export { InlineAgentRunner } from './runners/inline-agent-runner.js';
45
45
  export { LucidAgentStore } from './stores/lucid.js';
46
- export { createTableStatements, createAgentTables, ensureAgentTables, AGENT_TABLES, } from './stores/lucid-schema.js';
46
+ export { createTableStatements, createAgentTables, dropTableStatements, dropAgentTables, ensureAgentTables, AGENT_TABLES, } from './stores/lucid-schema.js';
47
47
  export { LedgerQuotaStore } from './stores/ledger-quota.js';
48
48
  export { LucidPricingStore } from './stores/lucid-pricing.js';
49
49
  export { LucidGovernanceQueries } from './stores/lucid-governance-queries.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC;AAEhC,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,mBAAmB,CAAC;AAClC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EACL,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,uBAAuB,CAAC;AAS/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,YAAY,EACZ,kBAAkB,GAGnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,qCAAqC,EACrC,uCAAuC,GACxC,MAAM,iBAAiB,CAAC;AAMzB,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,gFAAgF;AAChF,OAAO,EACL,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AqB,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAQpD,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,iBAAiB,EACjB,YAAY,GACb,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAE9E,gFAAgF;AAChF,OAAO,EACL,QAAQ,EACR,YAAY,EACZ,kBAAkB,EAClB,sBAAsB,EACtB,mBAAmB,EACnB,WAAW,EACX,aAAa,GACd,MAAM,iBAAiB,CAAC;AAYzB,uFAAuF;AACvF,qFAAqF;AACrF,sDAAsD;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC"}
@@ -30,10 +30,29 @@ export declare const AGENT_TABLES: {
30
30
  export declare function createTableStatements(): string[];
31
31
  /**
32
32
  * Idempotently provision the six agent tables through Lucid's async raw runner (`CREATE TABLE IF
33
- * NOT EXISTS`). Works on every Lucid dialect. For an AdonisJS app prefer the published migration
34
- * (`node ace configure @adonis-agora/agent`); this helper is for standalone use, tests and quick-starts.
33
+ * NOT EXISTS`), then additively repair a database that predates run tracking by ALTERing in the
34
+ * `run_id` columns its three older tables are missing.
35
+ *
36
+ * Both halves matter, and for different populations. A fresh database gets everything from the
37
+ * `CREATE TABLE` statements and never reaches a repair branch — which is what makes a non-empty
38
+ * `repairs` result mean "this schema was out of date", not "boot happened". A database created before
39
+ * run tracking shipped has all three tables already, so every `CREATE TABLE IF NOT EXISTS` no-ops and
40
+ * only the repair adds the columns the store now writes on every turn.
41
+ *
42
+ * Returns the `<table>.<column>` repairs actually issued, so a caller can report them. Works on every
43
+ * Lucid dialect. For an AdonisJS app prefer the published migration
44
+ * (`node ace configure @adonis-agora/agent`); this helper is what that migration calls, and what the
45
+ * stores call themselves when `autoCreateTables` is on.
46
+ */
47
+ export declare function createAgentTables(db: LucidDatabaseLike): Promise<string[]>;
48
+ /**
49
+ * `DROP TABLE IF EXISTS` for the six agent tables, in reverse dependency order so a dialect that
50
+ * enforces the `REFERENCES` clauses never refuses a drop for a child that still exists. The mirror of
51
+ * {@link createAgentTables}, and what the published migration's `down()` calls.
35
52
  */
36
- export declare function createAgentTables(db: LucidDatabaseLike): Promise<void>;
53
+ export declare function dropTableStatements(): string[];
54
+ /** Drop the six agent tables. Destructive and irreversible — this erases every thread and every ledger row. */
55
+ export declare function dropAgentTables(db: LucidDatabaseLike): Promise<void>;
37
56
  /**
38
57
  * Idempotently ensure the six agent tables exist, memoized per db client. This is what the stores
39
58
  * call on first use when `autoCreateTables` is on (the default) — whichever store touches the
@@ -1 +1 @@
1
- {"version":3,"file":"lucid-schema.d.ts","sourceRoot":"","sources":["../../../src/stores/lucid-schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD;;;GAGG;AACH,eAAO,MAAM,YAAY;;;;;;;CAOf,CAAC;AAEX;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,EAAE,CAmGhD;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CAAC,EAAE,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAI5E;AAWD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAWtE"}
1
+ {"version":3,"file":"lucid-schema.d.ts","sourceRoot":"","sources":["../../../src/stores/lucid-schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD;;;GAGG;AACH,eAAO,MAAM,YAAY;;;;;;;CAOf,CAAC;AAEX;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,EAAE,CAmGhD;AAiCD;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,iBAAiB,CAAC,EAAE,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAwBhF;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,EAAE,CAK9C;AAED,+GAA+G;AAC/G,wBAAsB,eAAe,CAAC,EAAE,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAI1E;AAWD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAatE"}
@@ -126,13 +126,88 @@ export function createTableStatements() {
126
126
  `CREATE INDEX IF NOT EXISTS "${t.runs}_status_started_idx" ON "${t.runs}" ("status", "started_at")`,
127
127
  ];
128
128
  }
129
+ /**
130
+ * The `run_id` correlation columns run tracking added to three pre-existing tables. They are inline in
131
+ * {@link createTableStatements}, which is all a fresh database needs — but `CREATE TABLE IF NOT EXISTS`
132
+ * cannot add a column to a table that already exists, so a database provisioned before run tracking
133
+ * shipped needs them ALTERed in. Deliberately not DB foreign keys (SQLite cannot add a column WITH a
134
+ * FK constraint), so a row written before run tracking keeps a `null` run_id.
135
+ */
136
+ const RUN_ID_COLUMNS = [
137
+ AGENT_TABLES.messages,
138
+ AGENT_TABLES.toolCalls,
139
+ AGENT_TABLES.tokenUsage,
140
+ ];
141
+ /**
142
+ * Does `table` already have `column`? Probed with a zero-row `SELECT` rather than `information_schema`
143
+ * (absent on SQLite) or a `PRAGMA` (SQLite-only): every dialect rejects an unknown column at parse
144
+ * time, and `WHERE 1 = 0` means no rows are ever read.
145
+ *
146
+ * Deliberately NOT "attempt the ALTER and swallow the error": that pattern also swallows a permission
147
+ * failure, a lock timeout, and a typo, leaving a schema that is still wrong and a migration that
148
+ * reported success.
149
+ */
150
+ async function hasColumn(db, table, column) {
151
+ try {
152
+ await db.rawQuery(`SELECT "${column}" FROM "${table}" WHERE 1 = 0`);
153
+ return true;
154
+ }
155
+ catch {
156
+ return false;
157
+ }
158
+ }
129
159
  /**
130
160
  * Idempotently provision the six agent tables through Lucid's async raw runner (`CREATE TABLE IF
131
- * NOT EXISTS`). Works on every Lucid dialect. For an AdonisJS app prefer the published migration
132
- * (`node ace configure @adonis-agora/agent`); this helper is for standalone use, tests and quick-starts.
161
+ * NOT EXISTS`), then additively repair a database that predates run tracking by ALTERing in the
162
+ * `run_id` columns its three older tables are missing.
163
+ *
164
+ * Both halves matter, and for different populations. A fresh database gets everything from the
165
+ * `CREATE TABLE` statements and never reaches a repair branch — which is what makes a non-empty
166
+ * `repairs` result mean "this schema was out of date", not "boot happened". A database created before
167
+ * run tracking shipped has all three tables already, so every `CREATE TABLE IF NOT EXISTS` no-ops and
168
+ * only the repair adds the columns the store now writes on every turn.
169
+ *
170
+ * Returns the `<table>.<column>` repairs actually issued, so a caller can report them. Works on every
171
+ * Lucid dialect. For an AdonisJS app prefer the published migration
172
+ * (`node ace configure @adonis-agora/agent`); this helper is what that migration calls, and what the
173
+ * stores call themselves when `autoCreateTables` is on.
133
174
  */
134
175
  export async function createAgentTables(db) {
135
- for (const stmt of createTableStatements()) {
176
+ const statements = createTableStatements();
177
+ // Order matters, in three phases rather than one pass. Tables first, then the `run_id` repair, then
178
+ // indexes — because `createTableStatements` includes `CREATE INDEX ... ON "agent_message" ("run_id")`,
179
+ // and on a legacy database that index would be issued against a table whose `run_id` the repair has
180
+ // not added yet. `CREATE INDEX IF NOT EXISTS` does not save it: the guard is on the INDEX existing,
181
+ // not on the column, so the statement still fails to parse with "no such column: run_id".
182
+ for (const stmt of statements) {
183
+ if (stmt.startsWith('CREATE TABLE'))
184
+ await db.rawQuery(stmt);
185
+ }
186
+ const repairs = [];
187
+ for (const table of RUN_ID_COLUMNS) {
188
+ if (await hasColumn(db, table, 'run_id'))
189
+ continue;
190
+ await db.rawQuery(`ALTER TABLE "${table}" ADD COLUMN "run_id" VARCHAR(255) NULL`);
191
+ repairs.push(`${table}.run_id`);
192
+ }
193
+ for (const stmt of statements) {
194
+ if (stmt.startsWith('CREATE INDEX'))
195
+ await db.rawQuery(stmt);
196
+ }
197
+ return repairs;
198
+ }
199
+ /**
200
+ * `DROP TABLE IF EXISTS` for the six agent tables, in reverse dependency order so a dialect that
201
+ * enforces the `REFERENCES` clauses never refuses a drop for a child that still exists. The mirror of
202
+ * {@link createAgentTables}, and what the published migration's `down()` calls.
203
+ */
204
+ export function dropTableStatements() {
205
+ const t = AGENT_TABLES;
206
+ return [t.runs, t.tokenUsage, t.toolCalls, t.messages, t.modelPricing, t.threads].map((table) => `DROP TABLE IF EXISTS "${table}"`);
207
+ }
208
+ /** Drop the six agent tables. Destructive and irreversible — this erases every thread and every ledger row. */
209
+ export async function dropAgentTables(db) {
210
+ for (const stmt of dropTableStatements()) {
136
211
  await db.rawQuery(stmt);
137
212
  }
138
213
  }
@@ -154,7 +229,9 @@ export function ensureAgentTables(db) {
154
229
  const key = db;
155
230
  let ready = provisioned.get(key);
156
231
  if (ready === undefined) {
157
- ready = createAgentTables(db).catch((error) => {
232
+ ready = createAgentTables(db)
233
+ .then(() => undefined)
234
+ .catch((error) => {
158
235
  provisioned.delete(key);
159
236
  throw error;
160
237
  });
@@ -1 +1 @@
1
- {"version":3,"file":"lucid-schema.js","sourceRoot":"","sources":["../../../src/stores/lucid-schema.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,OAAO,EAAE,cAAc;IACvB,QAAQ,EAAE,eAAe;IACzB,SAAS,EAAE,iBAAiB;IAC5B,UAAU,EAAE,mBAAmB;IAC/B,YAAY,EAAE,qBAAqB;IACnC,IAAI,EAAE,WAAW;CACT,CAAC;AAEX;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,qBAAqB;IACnC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,CAAC,CAAC,GAAG,CACnF,CAAC,KAAK,EAAE,EAAE,CAAC,yBAAyB,KAAK,GAAG,CAC7C,CAAC;AACJ,CAAC;AAED,+GAA+G;AAC/G,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,EAAqB;IACzD,KAAK,MAAM,IAAI,IAAI,mBAAmB,EAAE,EAAE,CAAC;QACzC,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,WAAW,GAAG,IAAI,OAAO,EAAyB,CAAC;AAEzD;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,EAAqB;IACrD,MAAM,GAAG,GAAG,EAAuB,CAAC;IACpC,IAAI,KAAK,GAAG,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACjC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,KAAK,GAAG,iBAAiB,CAAC,EAAE,CAAC;aAC1B,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC;aACrB,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACf,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACxB,MAAM,KAAK,CAAC;QACd,CAAC,CAAC,CAAC;QACL,WAAW,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -2,37 +2,42 @@
2
2
  exports({ to: app.migrationsPath(`${new Date().getTime()}_create_agent_rag_chunks.ts`) })
3
3
  }}}
4
4
  import { BaseSchema } from '@adonisjs/lucid/schema'
5
+ import db from '@adonisjs/lucid/services/db'
6
+ import { PgVectorStore } from '@adonis-agora/agent'
5
7
 
6
8
  /**
7
9
  * The pgvector chunk table for the @adonis-agora/agent `retrievers.pgvector({...})` store: one row per
8
10
  * embedded chunk (id `${documentId}#<n>`), the chunk text, an optional citation source, a `jsonb`
9
11
  * metadata column filtered with `@>`, and the `vector(N)` embedding ranked with the `<=>`/`<->`/`<#>`
10
- * operators. Requires the pgvector extension (`CREATE EXTENSION vector`) — Postgres only.
12
+ * operators. Requires the pgvector extension — Postgres only. Delete this file if you do not use
13
+ * pgvector RAG.
11
14
  *
12
- * Set `DIMENSION` to your embedding model's width (e.g. 1536 for text-embedding-3-small) and `OPCLASS`
13
- * to the index operator class matching the store's metric: `vector_cosine_ops` (default),
14
- * `vector_l2_ops`, or `vector_ip_ops`.
15
+ * Like the agent tables migration, this DELEGATES rather than copying DDL: `PgVectorStore` owns the
16
+ * column names and the index operator class its own queries depend on, and it exposes the same
17
+ * provisioning the store runs for itself under `ensureSchema: true`. Every statement is
18
+ * `IF NOT EXISTS`, so this is safe against a database that already has the table.
19
+ *
20
+ * SET THESE to match your retriever config in `config/agent.ts` — they must agree, or the store will
21
+ * query a table shaped differently from the one this created:
22
+ * - `DIMENSION` — your embedding model's width (1536 for text-embedding-3-small).
23
+ * - `METRIC` — 'cosine' (default), 'l2', or 'inner'. Picks the index operator class.
24
+ * - `TABLE` — only if you overrode `table` on the retriever.
15
25
  */
16
26
  const TABLE = 'agent_rag_chunks'
17
27
  const DIMENSION = 1536
18
- const OPCLASS = 'vector_cosine_ops'
28
+ const METRIC = 'cosine'
19
29
 
20
30
  export default class extends BaseSchema {
21
- async up() {
22
- this.schema.raw('CREATE EXTENSION IF NOT EXISTS vector')
31
+ /** Same reason as the agent tables migration: the DDL runs on the manager's own pooled connection. */
32
+ static disableTransactions = true
23
33
 
24
- this.schema.createTable(TABLE, (table) => {
25
- table.text('id').primary()
26
- table.text('text').notNullable()
27
- table.text('source')
28
- table.jsonb('metadata')
29
- table.specificType('embedding', `vector(${DIMENSION})`).notNullable()
34
+ async up() {
35
+ const store = new PgVectorStore(db.connection(this.db.connectionName), {
36
+ table: TABLE,
37
+ dimension: DIMENSION,
38
+ metric: METRIC,
30
39
  })
31
-
32
- // Approximate-nearest-neighbour index for the configured metric. Drop it to fall back to an exact scan.
33
- this.schema.raw(
34
- `CREATE INDEX IF NOT EXISTS ${TABLE}_embedding_idx ON ${TABLE} USING hnsw (embedding ${OPCLASS})`
35
- )
40
+ await store.ensureSchema()
36
41
  }
37
42
 
38
43
  async down() {
@@ -2,112 +2,48 @@
2
2
  exports({ to: app.migrationsPath(`${new Date().getTime()}_create_agent_tables.ts`) })
3
3
  }}}
4
4
  import { BaseSchema } from '@adonisjs/lucid/schema'
5
+ import db from '@adonisjs/lucid/services/db'
6
+ import { createAgentTables, dropAgentTables } from '@adonis-agora/agent'
5
7
 
6
8
  /**
7
- * The five tables for the @adonis-agora/agent `lucid` store: threads, messages, tool calls, token
8
- * usage and model pricing. JSON payloads (tool calls/results, follow-ups, usage, tool input/output)
9
- * are stored as TEXT — the store (de)serializes them — booleans as INTEGER (0/1), and timestamps as
10
- * epoch-ms integers, so the schema is portable across SQLite / Postgres / MySQL. The `agent_tool_call`
11
- * primary key is the model-supplied `toolCallId`, not a generated id.
9
+ * The six tables for the @adonis-agora/agent `lucid` store: threads, messages, tool calls, token
10
+ * usage, model pricing, and the run lifecycle — plus their indexes.
11
+ *
12
+ * This migration DELEGATES to the library instead of reproducing its DDL. The schema belongs to the
13
+ * library: `LucidAgentStore`, the pricing store and the governance read-model all decide together what
14
+ * columns they read and write, so a hand-copied snapshot here can only ever be right until the next
15
+ * release. It was already wrong in two ways. It reproduced `createTable(...)` with no existence guard,
16
+ * which THROWS on a database where the tables are already there — and they usually are, because
17
+ * `autoCreateTables` defaults to `true` and any of those three stores provisions the shared schema on
18
+ * its first use. And it took two files to say what the library says in one: a second additive migration
19
+ * existed purely to ALTER in the `run_id` columns this one had been written before.
20
+ *
21
+ * `createAgentTables` is idempotent (`CREATE TABLE IF NOT EXISTS`) and additive-only: it creates what
22
+ * is missing and ALTERs the `run_id` columns into a database that predates run tracking. So it is safe
23
+ * against an empty database, against one the library already auto-created, and against one left over
24
+ * from an older version — which is exactly the set of states a real app is in.
25
+ *
26
+ * `db` (the `Database` manager from `@adonisjs/lucid/services/db`) rather than `this.db`: the manager
27
+ * checks out its own connection from the pool, which is what keeps the DDL out of the migrator's
28
+ * transaction (see `disableTransactions` below). `this.db` still supplies the connection NAME, so
29
+ * `node ace migration:run --connection=x` provisions the tables on connection `x` and not on the default.
12
30
  */
13
31
  export default class extends BaseSchema {
14
- async up() {
15
- this.schema.createTable('agent_thread', (table) => {
16
- table.string('id').primary()
17
- table.string('actor_ref').notNullable()
18
- table.string('tenant_ref')
19
- table.text('title').notNullable()
20
- table.string('persona').notNullable().defaultTo('default')
21
- table.integer('transient').notNullable().defaultTo(0)
22
- table.bigInteger('pinned_at')
23
- table.text('summary')
24
- table.integer('summary_message_count').notNullable().defaultTo(0)
25
- table.string('active_stream_id')
26
- table.bigInteger('created_at').notNullable()
27
- table.bigInteger('updated_at').notNullable()
28
- table.bigInteger('deleted_at')
29
- table.index(['actor_ref', 'updated_at'], 'agent_thread_actor_updated_idx')
30
- })
31
-
32
- this.schema.createTable('agent_message', (table) => {
33
- table.string('id').primary()
34
- table
35
- .string('thread_id')
36
- .notNullable()
37
- .references('id')
38
- .inTable('agent_thread')
39
- .onDelete('CASCADE')
40
- table.string('role').notNullable()
41
- table.text('content').notNullable()
42
- table.text('tool_calls')
43
- table.text('tool_results')
44
- table.text('attachments')
45
- table.text('follow_ups')
46
- table.text('usage')
47
- table.string('persona')
48
- table.bigInteger('created_at').notNullable()
49
- table.index(['thread_id', 'created_at'], 'agent_message_thread_created_idx')
50
- })
51
-
52
- this.schema.createTable('agent_tool_call', (table) => {
53
- // PK = the model-supplied toolCallId, not a generated id.
54
- table.string('id').primary()
55
- table
56
- .string('message_id')
57
- .notNullable()
58
- .references('id')
59
- .inTable('agent_message')
60
- .onDelete('CASCADE')
61
- table.string('tool_name').notNullable()
62
- table.string('tool_type').notNullable()
63
- table.text('input')
64
- table.text('output')
65
- table.string('status').notNullable()
66
- table.string('executed_by_ref')
67
- table.integer('execution_ms')
68
- table.text('error')
69
- table.bigInteger('created_at').notNullable()
70
- table.bigInteger('executed_at')
71
- })
32
+ /**
33
+ * REQUIRED, not a preference. The DDL below runs on a connection the `Database` manager checks out
34
+ * itself — it is not part of the transaction the migrator would otherwise open for this migration.
35
+ * With `pool: { max: 1 }` (Adonis's own SQLite guidance) that transaction would hold the only
36
+ * connection while `createAgentTables` waited for a free one, and the migration would hang until the
37
+ * acquire timeout. Nothing is lost by opting out: the statements were never inside that transaction
38
+ * anyway, and re-running an interrupted `createAgentTables` is a no-op.
39
+ */
40
+ static disableTransactions = true
72
41
 
73
- this.schema.createTable('agent_token_usage', (table) => {
74
- table.string('id').primary()
75
- table
76
- .string('thread_id')
77
- .notNullable()
78
- .references('id')
79
- .inTable('agent_thread')
80
- .onDelete('CASCADE')
81
- table.string('actor_ref').notNullable()
82
- table.string('message_id')
83
- table.string('model_id').notNullable()
84
- table.string('purpose').notNullable()
85
- table.integer('input_tokens').notNullable()
86
- table.integer('output_tokens').notNullable()
87
- table.integer('cache_write_tokens')
88
- table.integer('cache_read_tokens')
89
- table.double('cost_usd')
90
- table.bigInteger('created_at').notNullable()
91
- table.index(['actor_ref', 'created_at'], 'agent_token_usage_actor_created_idx')
92
- })
93
-
94
- this.schema.createTable('agent_model_pricing', (table) => {
95
- table.string('id').primary()
96
- table.string('model_id').notNullable()
97
- table.double('input_price_per_1m').notNullable()
98
- table.double('output_price_per_1m').notNullable()
99
- table.double('cache_write_price_per_1m')
100
- table.double('cache_read_price_per_1m')
101
- table.bigInteger('effective_from').notNullable()
102
- table.integer('is_current').notNullable()
103
- })
42
+ async up() {
43
+ await createAgentTables(db.connection(this.db.connectionName))
104
44
  }
105
45
 
106
46
  async down() {
107
- this.schema.dropTableIfExists('agent_model_pricing')
108
- this.schema.dropTableIfExists('agent_token_usage')
109
- this.schema.dropTableIfExists('agent_tool_call')
110
- this.schema.dropTableIfExists('agent_message')
111
- this.schema.dropTableIfExists('agent_thread')
47
+ await dropAgentTables(db.connection(this.db.connectionName))
112
48
  }
113
49
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adonis-agora/agent",
3
- "version": "0.24.0",
3
+ "version": "0.25.0",
4
4
  "description": "Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1,80 +0,0 @@
1
- {{{
2
- exports({ to: app.migrationsPath(`${new Date().getTime()}_create_agent_run_tracking.ts`) })
3
- }}}
4
- import { BaseSchema } from '@adonisjs/lucid/schema'
5
-
6
- /**
7
- * Additive migration for @adonis-agora/agent RUN tracking. Adds the `agent_run` table (one row per
8
- * run/turn lifecycle) plus a nullable `run_id` correlation column on `agent_message`,
9
- * `agent_tool_call` and `agent_token_usage`. `run_id` is deliberately NOT a DB foreign key (like the
10
- * reference): it can be `ALTER TABLE ADD COLUMN`-ed portably (SQLite can't add a column WITH a FK
11
- * constraint) and a row written before this shipped keeps a `null` run_id.
12
- *
13
- * Timestamps are epoch-ms integers, booleans INTEGER (0/1) and cost a DOUBLE, matching
14
- * `create_agent_tables` so the schema stays portable across SQLite / Postgres / MySQL. Safe to run on
15
- * an existing deployment: it only creates a new table and adds nullable columns.
16
- */
17
- export default class extends BaseSchema {
18
- async up() {
19
- this.schema.createTable('agent_run', (table) => {
20
- table.string('id').primary()
21
- table
22
- .string('thread_id')
23
- .notNullable()
24
- .references('id')
25
- .inTable('agent_thread')
26
- .onDelete('CASCADE')
27
- table.string('agent_name')
28
- table.string('actor_ref').notNullable()
29
- table.string('tenant_ref')
30
- table.string('status').notNullable()
31
- table.bigInteger('started_at').notNullable()
32
- table.bigInteger('finished_at')
33
- table.integer('step_count').notNullable().defaultTo(0)
34
- table.integer('input_tokens').notNullable().defaultTo(0)
35
- table.integer('output_tokens').notNullable().defaultTo(0)
36
- table.double('cost_usd')
37
- table.text('error')
38
- table.integer('durable').notNullable().defaultTo(0)
39
- table.index(['started_at'], 'agent_run_started_idx')
40
- table.index(['actor_ref', 'started_at'], 'agent_run_actor_started_idx')
41
- table.index(['status', 'started_at'], 'agent_run_status_started_idx')
42
- })
43
-
44
- this.schema.alterTable('agent_message', (table) => {
45
- table.string('run_id')
46
- table.index(['run_id'], 'agent_message_run_idx')
47
- })
48
-
49
- this.schema.alterTable('agent_tool_call', (table) => {
50
- table.string('run_id')
51
- table.index(['run_id'], 'agent_tool_call_run_idx')
52
- table.index(['status', 'created_at'], 'agent_tool_call_status_created_idx')
53
- })
54
-
55
- this.schema.alterTable('agent_token_usage', (table) => {
56
- table.string('run_id')
57
- table.index(['run_id'], 'agent_token_usage_run_idx')
58
- })
59
- }
60
-
61
- async down() {
62
- this.schema.alterTable('agent_token_usage', (table) => {
63
- table.dropIndex(['run_id'], 'agent_token_usage_run_idx')
64
- table.dropColumn('run_id')
65
- })
66
-
67
- this.schema.alterTable('agent_tool_call', (table) => {
68
- table.dropIndex(['status', 'created_at'], 'agent_tool_call_status_created_idx')
69
- table.dropIndex(['run_id'], 'agent_tool_call_run_idx')
70
- table.dropColumn('run_id')
71
- })
72
-
73
- this.schema.alterTable('agent_message', (table) => {
74
- table.dropIndex(['run_id'], 'agent_message_run_idx')
75
- table.dropColumn('run_id')
76
- })
77
-
78
- this.schema.dropTableIfExists('agent_run')
79
- }
80
- }