@adhd/agent-core-provider 2.1.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 (64) hide show
  1. package/drizzle/0000_providers_and_models.sql +23 -0
  2. package/drizzle/0001_model_platform_bindings.sql +8 -0
  3. package/drizzle/0002_provider_tool_formats.sql +10 -0
  4. package/drizzle/meta/0000_snapshot.json +149 -0
  5. package/drizzle/meta/0001_snapshot.json +190 -0
  6. package/drizzle/meta/0002_snapshot.json +245 -0
  7. package/drizzle/meta/_journal.json +27 -0
  8. package/package.json +53 -0
  9. package/src/adapter/provider-adapter.d.ts +21 -0
  10. package/src/adapter/provider-adapter.d.ts.map +1 -0
  11. package/src/adapter/provider-adapter.js +38 -0
  12. package/src/adapter/provider-adapter.js.map +1 -0
  13. package/src/db/client.d.ts +7 -0
  14. package/src/db/client.d.ts.map +1 -0
  15. package/src/db/client.js +19 -0
  16. package/src/db/client.js.map +1 -0
  17. package/src/db/migrate-runner.d.ts +30 -0
  18. package/src/db/migrate-runner.d.ts.map +1 -0
  19. package/src/db/migrate-runner.js +34 -0
  20. package/src/db/migrate-runner.js.map +1 -0
  21. package/src/db/migrate.d.ts +9 -0
  22. package/src/db/migrate.d.ts.map +1 -0
  23. package/src/db/migrate.js +13 -0
  24. package/src/db/migrate.js.map +1 -0
  25. package/src/db/schema.d.ts +475 -0
  26. package/src/db/schema.d.ts.map +1 -0
  27. package/src/db/schema.js +79 -0
  28. package/src/db/schema.js.map +1 -0
  29. package/src/index.d.ts +17 -0
  30. package/src/index.d.ts.map +1 -0
  31. package/src/index.js +15 -0
  32. package/src/index.js.map +1 -0
  33. package/src/runtime/emit-tools.d.ts +91 -0
  34. package/src/runtime/emit-tools.d.ts.map +1 -0
  35. package/src/runtime/emit-tools.js +98 -0
  36. package/src/runtime/emit-tools.js.map +1 -0
  37. package/src/seed/bindings.d.ts +16 -0
  38. package/src/seed/bindings.d.ts.map +1 -0
  39. package/src/seed/bindings.js +65 -0
  40. package/src/seed/bindings.js.map +1 -0
  41. package/src/seed/index.d.ts +13 -0
  42. package/src/seed/index.d.ts.map +1 -0
  43. package/src/seed/index.js +29 -0
  44. package/src/seed/index.js.map +1 -0
  45. package/src/seed/models.d.ts +22 -0
  46. package/src/seed/models.d.ts.map +1 -0
  47. package/src/seed/models.js +68 -0
  48. package/src/seed/models.js.map +1 -0
  49. package/src/seed/providers.d.ts +11 -0
  50. package/src/seed/providers.d.ts.map +1 -0
  51. package/src/seed/providers.js +65 -0
  52. package/src/seed/providers.js.map +1 -0
  53. package/src/store/model-store.d.ts +69 -0
  54. package/src/store/model-store.d.ts.map +1 -0
  55. package/src/store/model-store.js +130 -0
  56. package/src/store/model-store.js.map +1 -0
  57. package/src/store/provider-store.d.ts +39 -0
  58. package/src/store/provider-store.d.ts.map +1 -0
  59. package/src/store/provider-store.js +88 -0
  60. package/src/store/provider-store.js.map +1 -0
  61. package/src/store/tool-format-store.d.ts +58 -0
  62. package/src/store/tool-format-store.d.ts.map +1 -0
  63. package/src/store/tool-format-store.js +93 -0
  64. package/src/store/tool-format-store.js.map +1 -0
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@adhd/agent-core-provider",
3
+ "version": "2.1.0",
4
+ "description": "Provider registry: adapters, model catalog, and tool-format emitter for @adhd/agent-mcp",
5
+ "type": "module",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "files": [
10
+ "src",
11
+ "drizzle"
12
+ ],
13
+ "exports": {
14
+ ".": {
15
+ "types": "./src/index.d.ts",
16
+ "default": "./src/index.js"
17
+ }
18
+ },
19
+ "scripts": {
20
+ "build": "nx build agent-provider",
21
+ "dev": "nx build agent-provider --watch",
22
+ "typecheck": "tsc -p tsconfig.lib.json --noEmit",
23
+ "db:generate": "drizzle-kit generate",
24
+ "db:migrate": "drizzle-kit migrate"
25
+ },
26
+ "dependencies": {
27
+ "better-sqlite3": "12.10.0",
28
+ "drizzle-orm": "0.45.2",
29
+ "@adhd/agent-base-types": "^2.1.0"
30
+ },
31
+ "devDependencies": {
32
+ "@types/better-sqlite3": "^7.6.13",
33
+ "@vitest/coverage-v8": "^1.0.4",
34
+ "drizzle-kit": "^0.31.10",
35
+ "tslib": "^2.6.0",
36
+ "typescript": "^5.5.0",
37
+ "vite": "~5.0.13",
38
+ "vite-plugin-dts": "~3.8.3",
39
+ "vitest": "^1.6.0"
40
+ },
41
+ "license": "MIT",
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "git+https://github.com/PseudoSky/adhd.git",
45
+ "directory": "packages/agent/agent-core-provider"
46
+ },
47
+ "homepage": "https://github.com/PseudoSky/adhd/tree/main/packages/agent/agent-core-provider#readme",
48
+ "bugs": {
49
+ "url": "https://github.com/PseudoSky/adhd/issues"
50
+ },
51
+ "module": "./src/index.js",
52
+ "main": "./src/index.js"
53
+ }
@@ -0,0 +1,21 @@
1
+ import type { Message, ToolDefinition, StreamChunk, ProviderAdapter as IProviderAdapter } from '@adhd/agent-base-types';
2
+ import { ModelStore } from '../store/model-store.js';
3
+ export declare class ProviderAdapterImpl implements IProviderAdapter {
4
+ private readonly store;
5
+ private readonly platform;
6
+ constructor(store: ModelStore, platform: string);
7
+ /**
8
+ * Resolve the canonical model id to a per-platform string via the binding
9
+ * table, then yield a single informational chunk.
10
+ *
11
+ * The resolved id is surfaced in the first (and only) text chunk so that
12
+ * tests can assert the correct resolution without live API calls.
13
+ */
14
+ stream(_messages: Message[], _tools: ToolDefinition[] | undefined, model: string): AsyncIterable<StreamChunk>;
15
+ /**
16
+ * Expose the resolved model id without consuming the stream.
17
+ * Convenience method for tests to assert resolution directly.
18
+ */
19
+ resolveModelId(canonicalId: string): string;
20
+ }
21
+ //# sourceMappingURL=provider-adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-adapter.d.ts","sourceRoot":"","sources":["../../../../../../packages/agent/agent-core-provider/src/adapter/provider-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,cAAc,EACd,WAAW,EACX,eAAe,IAAI,gBAAgB,EACpC,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAcrD,qBAAa,mBAAoB,YAAW,gBAAgB;IAC1D,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAa;IACnC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;gBAEtB,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM;IAK/C;;;;;;OAMG;IACI,MAAM,CACX,SAAS,EAAE,OAAO,EAAE,EACpB,MAAM,EAAE,cAAc,EAAE,GAAG,SAAS,EACpC,KAAK,EAAE,MAAM,GACZ,aAAa,CAAC,WAAW,CAAC;IAK7B;;;OAGG;IACH,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM;CAG5C"}
@@ -0,0 +1,38 @@
1
+ // ──────────────────────────────────────────────────────────────────────────────
2
+ // ProviderAdapter — thin implementation
3
+ //
4
+ // The class IMPLEMENTS `ProviderAdapter` (from @adhd/agent-base-types) — it
5
+ // does NOT re-declare the interface here. Dependency direction:
6
+ // agent-mcp-types ← agent-provider ← agent-mcp
7
+ //
8
+ // The stream() body is intentionally a minimal stub: the contract this state
9
+ // tests is MODEL RESOLUTION through the binding table, not live LLM streaming.
10
+ // Concrete streaming is delivered by a later plan state.
11
+ // ──────────────────────────────────────────────────────────────────────────────
12
+ export class ProviderAdapterImpl {
13
+ store;
14
+ platform;
15
+ constructor(store, platform) {
16
+ this.store = store;
17
+ this.platform = platform;
18
+ }
19
+ /**
20
+ * Resolve the canonical model id to a per-platform string via the binding
21
+ * table, then yield a single informational chunk.
22
+ *
23
+ * The resolved id is surfaced in the first (and only) text chunk so that
24
+ * tests can assert the correct resolution without live API calls.
25
+ */
26
+ async *stream(_messages, _tools, model) {
27
+ const resolvedModelId = this.store.resolveModelId(model, this.platform);
28
+ yield { type: 'text', text: resolvedModelId };
29
+ }
30
+ /**
31
+ * Expose the resolved model id without consuming the stream.
32
+ * Convenience method for tests to assert resolution directly.
33
+ */
34
+ resolveModelId(canonicalId) {
35
+ return this.store.resolveModelId(canonicalId, this.platform);
36
+ }
37
+ }
38
+ //# sourceMappingURL=provider-adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-adapter.js","sourceRoot":"","sources":["../../../../../../packages/agent/agent-core-provider/src/adapter/provider-adapter.ts"],"names":[],"mappings":"AASA,iFAAiF;AACjF,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,iEAAiE;AACjE,iDAAiD;AACjD,EAAE;AACF,6EAA6E;AAC7E,+EAA+E;AAC/E,yDAAyD;AACzD,iFAAiF;AAEjF,MAAM,OAAO,mBAAmB;IACb,KAAK,CAAa;IAClB,QAAQ,CAAS;IAElC,YAAY,KAAiB,EAAE,QAAgB;QAC7C,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,CAAC,MAAM,CACX,SAAoB,EACpB,MAAoC,EACpC,KAAa;QAEb,MAAM,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QACxE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC;IAChD,CAAC;IAED;;;OAGG;IACH,cAAc,CAAC,WAAmB;QAChC,OAAO,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC/D,CAAC;CACF"}
@@ -0,0 +1,7 @@
1
+ import Database from 'better-sqlite3';
2
+ import * as schema from './schema.js';
3
+ export declare const sqlite: Database.Database;
4
+ export declare const db: import("drizzle-orm/better-sqlite3").BetterSQLite3Database<typeof schema> & {
5
+ $client: Database.Database;
6
+ };
7
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../../packages/agent/agent-core-provider/src/db/client.ts"],"names":[],"mappings":"AAIA,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAGtC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AActC,eAAO,MAAM,MAAM,EAAE,QAAQ,CAAC,QAAqC,CAAC;AAKpE,eAAO,MAAM,EAAE;;CAA8B,CAAC"}
@@ -0,0 +1,19 @@
1
+ import fs from 'node:fs';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ import Database from 'better-sqlite3';
5
+ import { drizzle } from 'drizzle-orm/better-sqlite3';
6
+ import * as schema from './schema.js';
7
+ const databasePath = process.env['DATABASE_PATH'] || path.join(os.homedir(), '.adhd', 'agent-core-provider', 'agents.db');
8
+ const resolvedPath = path.resolve(databasePath);
9
+ const directory = path.dirname(resolvedPath);
10
+ if (!fs.existsSync(directory)) {
11
+ fs.mkdirSync(directory, {
12
+ recursive: true,
13
+ });
14
+ }
15
+ export const sqlite = new Database(resolvedPath);
16
+ sqlite.pragma('journal_mode = WAL');
17
+ sqlite.pragma('foreign_keys = ON');
18
+ export const db = drizzle(sqlite, { schema });
19
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../../../../packages/agent/agent-core-provider/src/db/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAErD,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAEtC,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,qBAAqB,EAAE,WAAW,CAAC,CAAC;AAE1H,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;AAEhD,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;AAE7C,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;IAC9B,EAAE,CAAC,SAAS,CAAC,SAAS,EAAE;QACtB,SAAS,EAAE,IAAI;KAChB,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,MAAM,MAAM,GAAsB,IAAI,QAAQ,CAAC,YAAY,CAAC,CAAC;AAEpE,MAAM,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC;AACpC,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAEnC,MAAM,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC"}
@@ -0,0 +1,30 @@
1
+ import { migrate } from 'drizzle-orm/better-sqlite3/migrator';
2
+ /**
3
+ * Folder holding the drizzle-kit generated migrations (../../drizzle relative
4
+ * to this compiled module). Kept here — with no `client.js` import — so test
5
+ * harnesses can reuse the FK-safe runner without dragging in the production
6
+ * singleton connection (which opens a DB file at import time).
7
+ */
8
+ export declare const MIGRATIONS_FOLDER: string;
9
+ /**
10
+ * Minimal structural type for the bits of a better-sqlite3 connection we need.
11
+ * Avoids importing the better-sqlite3 type just to call `pragma`.
12
+ */
13
+ interface PragmaConn {
14
+ pragma(source: string, options?: {
15
+ simple: boolean;
16
+ }): unknown;
17
+ }
18
+ /**
19
+ * Run Drizzle migrations against an explicit connection with foreign-key
20
+ * enforcement disabled for the duration of the run.
21
+ *
22
+ * WHY THIS WRAPPER EXISTS: SQLite silently ignores `PRAGMA foreign_keys`
23
+ * **inside a transaction**, and drizzle's migrator wraps each migration file in
24
+ * one. The only way to toggle FK enforcement for the whole migration run is to
25
+ * disable it on the connection *before* migrate() — while no transaction is
26
+ * open — then restore the prior setting afterwards.
27
+ */
28
+ export declare function runMigrationsOn(conn: PragmaConn, drizzleDb: Parameters<typeof migrate>[0], migrationsFolder?: string): void;
29
+ export {};
30
+ //# sourceMappingURL=migrate-runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate-runner.d.ts","sourceRoot":"","sources":["../../../../../../packages/agent/agent-core-provider/src/db/migrate-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qCAAqC,CAAC;AAE9D;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,QACnB,CAAC;AAEZ;;;GAGG;AACH,UAAU,UAAU;IAClB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,MAAM,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC;CAChE;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,UAAU,EAChB,SAAS,EAAE,UAAU,CAAC,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC,EACxC,gBAAgB,GAAE,MAA0B,GAC3C,IAAI,CAcN"}
@@ -0,0 +1,34 @@
1
+ import { migrate } from 'drizzle-orm/better-sqlite3/migrator';
2
+ /**
3
+ * Folder holding the drizzle-kit generated migrations (../../drizzle relative
4
+ * to this compiled module). Kept here — with no `client.js` import — so test
5
+ * harnesses can reuse the FK-safe runner without dragging in the production
6
+ * singleton connection (which opens a DB file at import time).
7
+ */
8
+ export const MIGRATIONS_FOLDER = new URL('../../drizzle', import.meta.url)
9
+ .pathname;
10
+ /**
11
+ * Run Drizzle migrations against an explicit connection with foreign-key
12
+ * enforcement disabled for the duration of the run.
13
+ *
14
+ * WHY THIS WRAPPER EXISTS: SQLite silently ignores `PRAGMA foreign_keys`
15
+ * **inside a transaction**, and drizzle's migrator wraps each migration file in
16
+ * one. The only way to toggle FK enforcement for the whole migration run is to
17
+ * disable it on the connection *before* migrate() — while no transaction is
18
+ * open — then restore the prior setting afterwards.
19
+ */
20
+ export function runMigrationsOn(conn, drizzleDb, migrationsFolder = MIGRATIONS_FOLDER) {
21
+ const fkWasOn = conn.pragma('foreign_keys', { simple: true }) === 1;
22
+ if (fkWasOn) {
23
+ conn.pragma('foreign_keys = OFF');
24
+ }
25
+ try {
26
+ migrate(drizzleDb, { migrationsFolder });
27
+ }
28
+ finally {
29
+ if (fkWasOn) {
30
+ conn.pragma('foreign_keys = ON');
31
+ }
32
+ }
33
+ }
34
+ //# sourceMappingURL=migrate-runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate-runner.js","sourceRoot":"","sources":["../../../../../../packages/agent/agent-core-provider/src/db/migrate-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qCAAqC,CAAC;AAE9D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC,eAAe,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;KACvE,QAAQ,CAAC;AAUZ;;;;;;;;;GASG;AACH,MAAM,UAAU,eAAe,CAC7B,IAAgB,EAChB,SAAwC,EACxC,mBAA2B,iBAAiB;IAE5C,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC;IAEpE,IAAI,OAAO,EAAE,CAAC;QACZ,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC;IACpC,CAAC;IAED,IAAI,CAAC;QACH,OAAO,CAAC,SAAS,EAAE,EAAE,gBAAgB,EAAE,CAAC,CAAC;IAC3C,CAAC;YAAS,CAAC;QACT,IAAI,OAAO,EAAE,CAAC;YACZ,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Runs pending Drizzle migrations synchronously before the server starts.
3
+ * Migrations are read from the ./drizzle folder (generated by drizzle-kit).
4
+ *
5
+ * Delegates to the FK-safe {@link runMigrationsOn} runner (see that module for
6
+ * why foreign-key enforcement must be toggled around the migration run).
7
+ */
8
+ export declare function runMigrations(): void;
9
+ //# sourceMappingURL=migrate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../../../../../../packages/agent/agent-core-provider/src/db/migrate.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,wBAAgB,aAAa,IAAI,IAAI,CAEpC"}
@@ -0,0 +1,13 @@
1
+ import { db, sqlite } from './client.js';
2
+ import { runMigrationsOn } from './migrate-runner.js';
3
+ /**
4
+ * Runs pending Drizzle migrations synchronously before the server starts.
5
+ * Migrations are read from the ./drizzle folder (generated by drizzle-kit).
6
+ *
7
+ * Delegates to the FK-safe {@link runMigrationsOn} runner (see that module for
8
+ * why foreign-key enforcement must be toggled around the migration run).
9
+ */
10
+ export function runMigrations() {
11
+ runMigrationsOn(sqlite, db);
12
+ }
13
+ //# sourceMappingURL=migrate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate.js","sourceRoot":"","sources":["../../../../../../packages/agent/agent-core-provider/src/db/migrate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD;;;;;;GAMG;AACH,MAAM,UAAU,aAAa;IAC3B,eAAe,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AAC9B,CAAC"}