@vedmalex/ai-connect 0.10.1 → 0.12.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 (59) hide show
  1. package/README.md +61 -7
  2. package/dist/browser/index.js +592 -290
  3. package/dist/browser/index.js.map +3 -3
  4. package/dist/bun/index.js +1260 -448
  5. package/dist/bun/index.js.map +4 -4
  6. package/dist/bun/local.js +1256 -448
  7. package/dist/bun/local.js.map +4 -4
  8. package/dist/bun/registry-fs.js +865 -0
  9. package/dist/bun/registry-fs.js.map +7 -0
  10. package/dist/node/index.js +1260 -448
  11. package/dist/node/index.js.map +4 -4
  12. package/dist/node/local.js +1256 -448
  13. package/dist/node/local.js.map +4 -4
  14. package/dist/node/registry-fs.js +865 -0
  15. package/dist/node/registry-fs.js.map +7 -0
  16. package/dist/registry/index.js +1063 -0
  17. package/dist/registry/index.js.map +7 -0
  18. package/dist/types/acp.d.ts.map +1 -1
  19. package/dist/types/cli.d.ts +8 -0
  20. package/dist/types/cli.d.ts.map +1 -1
  21. package/dist/types/client-tools-mcp.d.ts +82 -0
  22. package/dist/types/client-tools-mcp.d.ts.map +1 -0
  23. package/dist/types/client-tools-text-protocol.d.ts +70 -0
  24. package/dist/types/client-tools-text-protocol.d.ts.map +1 -0
  25. package/dist/types/client.d.ts +20 -0
  26. package/dist/types/client.d.ts.map +1 -1
  27. package/dist/types/config.d.ts +8 -1
  28. package/dist/types/config.d.ts.map +1 -1
  29. package/dist/types/default-handlers.d.ts.map +1 -1
  30. package/dist/types/index.browser.d.ts +2 -2
  31. package/dist/types/index.browser.d.ts.map +1 -1
  32. package/dist/types/index.d.ts +2 -2
  33. package/dist/types/index.d.ts.map +1 -1
  34. package/dist/types/mock-gateway.d.ts +20 -0
  35. package/dist/types/mock-gateway.d.ts.map +1 -1
  36. package/dist/types/model-reference.d.ts +25 -10
  37. package/dist/types/model-reference.d.ts.map +1 -1
  38. package/dist/types/registry/compile.d.ts +24 -0
  39. package/dist/types/registry/compile.d.ts.map +1 -0
  40. package/dist/types/registry/convert-v1.d.ts +21 -0
  41. package/dist/types/registry/convert-v1.d.ts.map +1 -0
  42. package/dist/types/registry/fs.d.ts +59 -0
  43. package/dist/types/registry/fs.d.ts.map +1 -0
  44. package/dist/types/registry/index.d.ts +13 -0
  45. package/dist/types/registry/index.d.ts.map +1 -0
  46. package/dist/types/registry/merge.d.ts +26 -0
  47. package/dist/types/registry/merge.d.ts.map +1 -0
  48. package/dist/types/registry/parse.d.ts +26 -0
  49. package/dist/types/registry/parse.d.ts.map +1 -0
  50. package/dist/types/registry/types.d.ts +168 -0
  51. package/dist/types/registry/types.d.ts.map +1 -0
  52. package/dist/types/router.d.ts.map +1 -1
  53. package/dist/types/server.d.ts.map +1 -1
  54. package/dist/types/transport-runtime.d.ts +30 -0
  55. package/dist/types/transport-runtime.d.ts.map +1 -1
  56. package/dist/types/types.d.ts +102 -4
  57. package/dist/types/types.d.ts.map +1 -1
  58. package/package.json +15 -2
  59. package/schema/connections.v2.json +395 -0
package/README.md CHANGED
@@ -611,6 +611,60 @@ Three error codes are intentionally **hard-terminal**: they never rotate, retry,
611
611
 
612
612
  All other normalized error codes (`rate_limit`, `quota_exhausted`, `temporary_unavailable`, etc.) remain eligible for the rotation/retry/fallback chain you configure under `routing.fallback`.
613
613
 
614
+ ## Connection Registry (`connections.json`)
615
+
616
+ Instead of hand-writing `defineConfig(...)`, you can declare your whole topology — endpoints,
617
+ aliases (ordered failover chains), auth, and defaults — in a single **v2 registry document** and
618
+ compile it into the exact config the client already consumes, plus ready-made `routeHints` per
619
+ alias. It ships as two subpaths: `@vedmalex/ai-connect/registry` (pure, browser-safe:
620
+ `parseRegistry` / `compileRegistry` / `convertV1Registry` / `mergeRegistries`) and
621
+ `@vedmalex/ai-connect/registry/fs` (node/bun loader: `loadConnectionRegistry` / `loadV1Pair`).
622
+
623
+ ```json
624
+ {
625
+ "$schema": "https://raw.githubusercontent.com/vedmalex/ai-connect/main/schema/connections.v2.json",
626
+ "version": 2,
627
+ "defaults": { "alias": "fast" },
628
+ "endpoints": [
629
+ {
630
+ "id": "openai-main",
631
+ "provider": "openai",
632
+ "transport": "api",
633
+ "baseUrl": "https://api.openai.com/v1",
634
+ "auth": { "tokenEnv": "OPENAI_API_KEY" },
635
+ "models": ["gpt-4.1"],
636
+ "defaultModel": "gpt-4.1"
637
+ }
638
+ ],
639
+ "aliases": [{ "id": "fast", "chain": [{ "endpointId": "openai-main" }] }]
640
+ }
641
+ ```
642
+
643
+ ```ts
644
+ import { loadConnectionRegistry } from "@vedmalex/ai-connect/registry/fs";
645
+ import { compileRegistry } from "@vedmalex/ai-connect/registry";
646
+ import { createLocalClient } from "@vedmalex/ai-connect";
647
+
648
+ const loaded = await loadConnectionRegistry(); // layered: user → project → AI_CONNECT_CONNECTIONS
649
+ const compiled = compileRegistry(loaded.registry, { env: (name) => process.env[name] });
650
+ const client = createLocalClient(compiled.config);
651
+
652
+ const fast = compiled.aliases["fast"];
653
+ if (!fast?.usable) throw new Error('alias "fast" is not usable'); // never dispatch on usable:false
654
+
655
+ const result = await client.generate({
656
+ messages: [{ role: "user", content: "Summarize this design brief." }],
657
+ routeHints: fast.routeHints, // ordered failover pool
658
+ });
659
+ console.log(result.text);
660
+ ```
661
+
662
+ The loader layers `~/.config/ai-connect/connections.json` (user) under
663
+ `<cwd>/.config/ai-connect/connections.json` (project) under `$AI_CONNECT_CONNECTIONS`, each with
664
+ a sibling `connections.secrets.json` overlay, and auto-converts legacy v1 (`rag-endpoints.json` +
665
+ `rag-aliases.json`) pairs. Full format, layering, failure-taxonomy, and v1-migration guide:
666
+ [docs/connection-registry.md](./docs/connection-registry.md).
667
+
614
668
  ## Cancellation, Pause, and Timeouts
615
669
 
616
670
  `generate(request, opts?)` and `stream(request, opts?)` accept an optional second argument:
@@ -1207,12 +1261,10 @@ ACP routes are treated as harness-owned connections:
1207
1261
  Tool semantics are intentionally split:
1208
1262
 
1209
1263
  - `api` routes support tool schema passthrough via `parameters.tools`
1210
- - `api` routes also support client-managed tools through `clientTools`
1211
- - `clientTools` are executed locally by `ai-connect` after the provider returns tool calls
1212
1264
  - `parameters.tools` remains the right path for upstream-managed tool schemas that are not executed by `ai-connect`
1213
1265
  - `acp` routes support harness-owned tool execution
1214
1266
  - `acp` routes do not currently forward request-defined tool schema from `parameters.tools`
1215
- - `cli` and current built-in `server` routes do not support tool schema passthrough or tool execution
1267
+ - client-managed tools (`clientTools`) are executed locally by `ai-connect` and work on **all four transports** (since 0.11.0): natively on `api`, via an in-process loopback MCP bridge on `acp` (`session/new.mcpServers`; the agent must advertise HTTP MCP support), and via a shared text-based round protocol on `cli` / `server`
1216
1268
 
1217
1269
  That distinction is also reflected in route capabilities:
1218
1270
 
@@ -1257,11 +1309,13 @@ const result = await client.generate({
1257
1309
  });
1258
1310
  ```
1259
1311
 
1260
- Current limits:
1312
+ `clientTools` semantics (as of 0.11.0 — see `docs/whats-new-0.11.md` for the full matrix):
1261
1313
 
1262
- - `clientTools` are supported only for `generate()`
1263
- - `clientTools` are currently supported only for text requests without attachments/image options
1264
- - built-in local execution of `clientTools` is implemented for built-in API handlers: `openai`, `anthropic`, `gemini`
1314
+ - work in both `generate()` and `stream()` (streaming runs a full multi-round tool loop and emits additive `tool-call` / `tool-result` stream events)
1315
+ - combine with `attachments`/image input on `text`-operation requests: round 1 carries the attachments, follow-up rounds rely on message history; routing is capability-gated (`supportsClientToolExecution` AND `supportsImageInput`/`supportsFileUpload`), an incapable route pool fails fast with `unsupported_capability`
1316
+ - `operation: "image"` / `"file"` combined with `clientTools` is rejected up front with `unsupported_capability` (tool-loop semantics exist only for `text`)
1317
+ - built-in local execution on `api` routes covers the built-in handlers (`openai`, `anthropic`, `gemini`); `acp`/`cli`/`server` execute through their transport bridges (see the tool-semantics list above)
1318
+ - per-model capability hints (curated `MODEL_REFERENCE`) can narrow route capabilities per model — e.g. an embeddings model on a vision-capable provider no longer advertises image input in `listCandidateModels()`
1265
1319
 
1266
1320
  ### Context and MCP Semantics
1267
1321