@combycode/llm-sdk 2.2.2 → 3.0.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 (95) hide show
  1. package/CHANGELOG.md +555 -0
  2. package/MIGRATION.md +130 -0
  3. package/dist/agent/loop-internals.d.ts +4 -0
  4. package/dist/agent/loop.d.ts +35 -0
  5. package/dist/bus/hook-bus.d.ts +13 -3
  6. package/dist/bus/hook-map.d.ts +24 -0
  7. package/dist/{llm/providers → catalog}/builtin-tools.d.ts +1 -1
  8. package/dist/{plugins/model-catalog → catalog}/catalog.d.ts +19 -0
  9. package/dist/helpers/client-pool.d.ts +1 -1
  10. package/dist/helpers/client-resolver.d.ts +22 -3
  11. package/dist/helpers/count-tokens.d.ts +1 -1
  12. package/dist/helpers/engine.d.ts +39 -6
  13. package/dist/helpers/mcp.d.ts +6 -1
  14. package/dist/helpers/models.d.ts +1 -1
  15. package/dist/helpers/one-shot.d.ts +2 -2
  16. package/dist/helpers/select-model.d.ts +1 -1
  17. package/dist/index.browser.js +17611 -4247
  18. package/dist/index.d.ts +5 -5
  19. package/dist/index.js +17611 -4247
  20. package/dist/llm/client-config.d.ts +9 -1
  21. package/dist/llm/client-internal.d.ts +11 -0
  22. package/dist/llm/client.d.ts +6 -0
  23. package/dist/llm/providers/_shared/sse.d.ts +19 -0
  24. package/dist/llm/providers/anthropic/batch.d.ts +13 -2
  25. package/dist/llm/providers/anthropic/constants.d.ts +8 -43
  26. package/dist/llm/providers/anthropic/files.d.ts +13 -2
  27. package/dist/llm/providers/anthropic/messages.d.ts +18 -1
  28. package/dist/llm/providers/google/batch.d.ts +14 -1
  29. package/dist/llm/providers/google/constants.d.ts +6 -15
  30. package/dist/llm/providers/google/embeddings.d.ts +8 -1
  31. package/dist/llm/providers/google/files.d.ts +34 -1
  32. package/dist/llm/providers/google/generate.d.ts +15 -1
  33. package/dist/llm/providers/google/interactions.d.ts +5 -1
  34. package/dist/llm/providers/google/media.d.ts +45 -4
  35. package/dist/llm/providers/google/realtime.d.ts +15 -2
  36. package/dist/llm/providers/openai/batch.d.ts +19 -2
  37. package/dist/llm/providers/openai/completions.d.ts +13 -1
  38. package/dist/llm/providers/openai/embeddings.d.ts +13 -1
  39. package/dist/llm/providers/openai/files.d.ts +13 -2
  40. package/dist/llm/providers/openai/media.d.ts +31 -2
  41. package/dist/llm/providers/openai/moderations.d.ts +11 -1
  42. package/dist/llm/providers/openai/realtime.d.ts +18 -2
  43. package/dist/llm/providers/openai/responses.d.ts +10 -2
  44. package/dist/llm/providers/openai/transcription.d.ts +7 -1
  45. package/dist/llm/providers/openrouter/completions.d.ts +5 -3
  46. package/dist/llm/providers/openrouter/embeddings.d.ts +3 -0
  47. package/dist/llm/providers/openrouter/media.d.ts +14 -4
  48. package/dist/llm/providers/openrouter/responses.d.ts +5 -3
  49. package/dist/llm/providers/xai/batch.d.ts +13 -2
  50. package/dist/llm/providers/xai/completions.d.ts +5 -3
  51. package/dist/llm/providers/xai/files.d.ts +13 -2
  52. package/dist/llm/providers/xai/media.d.ts +28 -10
  53. package/dist/llm/providers/xai/responses.d.ts +5 -3
  54. package/dist/llm/response-shape.d.ts +96 -0
  55. package/dist/llm/server-state.d.ts +1 -1
  56. package/dist/llm/types/options.d.ts +2 -2
  57. package/dist/llm/types/provider.d.ts +6 -0
  58. package/dist/llm/types/request.d.ts +49 -1
  59. package/dist/llm/wire-multipart.d.ts +26 -0
  60. package/dist/llm/wire-transforms.d.ts +28 -0
  61. package/dist/plugins/context-measurer/counter/count-api.d.ts +40 -6
  62. package/dist/plugins/context-measurer/counter/heuristic.d.ts +1 -1
  63. package/dist/plugins/context-measurer/counter/hybrid.d.ts +34 -1
  64. package/dist/plugins/context-measurer/counter/tiktoken.d.ts +7 -0
  65. package/dist/plugins/context-measurer/measurer.d.ts +1 -1
  66. package/dist/plugins/cost-collector/collector.d.ts +1 -1
  67. package/dist/plugins/cost-collector/cost-collector-internal.d.ts +1 -1
  68. package/dist/plugins/cost-collector/cost-collector-types.d.ts +1 -1
  69. package/dist/plugins/files/registry.d.ts +1 -1
  70. package/dist/plugins/files/strategy.d.ts +1 -1
  71. package/dist/plugins/internal-tools/registry.d.ts +1 -1
  72. package/dist/plugins/internal-tools/runner/types.d.ts +1 -1
  73. package/dist/plugins/mcp/sampling.d.ts +23 -1
  74. package/dist/plugins/mcp/transport-http.d.ts +13 -7
  75. package/dist/plugins/mcp/wire-rules.d.ts +21 -0
  76. package/dist/plugins/media/output.d.ts +1 -1
  77. package/dist/plugins/retrieval/document-file.d.ts +15 -0
  78. package/dist/plugins/retrieval/hosted-google.d.ts +8 -3
  79. package/dist/plugins/retrieval/hosted-openai.d.ts +9 -1
  80. package/dist/plugins/retrieval/hosted-xai.d.ts +8 -2
  81. package/dist/plugins/telemetry/telemetry.d.ts +2 -133
  82. package/dist/plugins/telemetry/types.d.ts +139 -0
  83. package/dist/util/hash.d.ts +8 -0
  84. package/dist/{plugins/media → util}/source-image.d.ts +1 -1
  85. package/dist/wire/chat-specs.d.ts +32 -0
  86. package/dist/wire/inherit.d.ts +43 -0
  87. package/dist/wire/interpreter.d.ts +279 -0
  88. package/dist/wire/mcp-specs.d.ts +13 -0
  89. package/dist/wire/media-specs.d.ts +20 -0
  90. package/dist/wire/pins.d.ts +34 -0
  91. package/dist/wire/registry.d.ts +20 -0
  92. package/dist/wire/retrieval-specs.d.ts +14 -0
  93. package/dist/wire/service-specs.d.ts +18 -0
  94. package/dist/wire/utility-specs.d.ts +10 -0
  95. package/package.json +6 -3
@@ -0,0 +1,13 @@
1
+ /** The MCP Streamable-HTTP spec family.
2
+ *
3
+ * A sibling of the provider families, loaded separately for the same reason: an
4
+ * application that never talks to an MCP server should not carry these, and the
5
+ * generated `registry.ts` imports everything.
6
+ *
7
+ * MCP is the case that shows the spec format is about NETWORKING rather than about
8
+ * LLM providers — a JSON-RPC envelope, era-dependent routing headers and a
9
+ * long-lived stream are described by the same six constructs a chat request uses.
10
+ */
11
+ import type { WireSpec } from './interpreter';
12
+ /** Resolve an MCP spec by id, flattening its `extends` chain. */
13
+ export declare function mcpSpec(id: string): WireSpec;
@@ -0,0 +1,20 @@
1
+ /** The media wire specs the RUNTIME loads, resolved and memoised.
2
+ *
3
+ * A sibling of `chat-specs.ts` and separate from it for the same reason that file
4
+ * is separate from `registry.ts`: the generated index imports all 71 specs, so any
5
+ * adapter reaching for it pulls in every family whether or not anything runs them.
6
+ * The runtime loads one family at a time, as each is migrated, so what ships is
7
+ * what executes.
8
+ *
9
+ * Only the leaves are exported — the `*.base` specs exist to be inherited from and
10
+ * are never built directly, so naming one is a mistake worth catching.
11
+ */
12
+ import type { WireSpec } from './interpreter';
13
+ /** The media spec for `id`, with its inheritance chain applied.
14
+ *
15
+ * Throws on an unknown or abstract id rather than substituting something
16
+ * plausible: a quietly wrong endpoint is the failure mode the specs exist to end. */
17
+ export declare function mediaSpec(id: string): WireSpec;
18
+ /** Buildable media spec ids — asserted by the tests so this list and the shipped
19
+ * spec files cannot drift apart unnoticed. */
20
+ export declare const MEDIA_SPEC_IDS: readonly string[];
@@ -0,0 +1,34 @@
1
+ /** Which spec builds a model's request when the catalog has no pin for it.
2
+ *
3
+ * Every catalogued model carries an explicit `wireSpec`, so this only decides for
4
+ * the models the catalog does not know: one released after this build, or an
5
+ * engine running without a catalog at all. That case is not an edge — it is how
6
+ * the SDK works on the day a provider ships something new — so it keeps a real
7
+ * answer rather than a guess.
8
+ *
9
+ * It is DATA, not code, for the same reason the specs are: the Python and Rust
10
+ * ports read this file instead of each re-implementing version arithmetic and
11
+ * drifting from it. Two versions of that arithmetic is exactly how the 2.2.1
12
+ * regression happened.
13
+ *
14
+ * Rules are ordered and the first match wins; `default` answers everything else.
15
+ */
16
+ export interface PinRule {
17
+ /** Anchored regular expression, matched against the model id. */
18
+ match: string;
19
+ spec: string;
20
+ /** Why this band exists. Read by humans, not by the resolver. */
21
+ why?: string;
22
+ }
23
+ export interface ModelPins {
24
+ id: string;
25
+ rules?: PinRule[];
26
+ default: string;
27
+ }
28
+ /** The spec id for `model`, from an ordered rule table.
29
+ *
30
+ * The id is lower-cased and stripped of a `provider/` prefix first, because a
31
+ * caller may legitimately pass either form and a band must not depend on which. */
32
+ export declare function pinFor(model: string, pins: ModelPins): string;
33
+ export declare const ANTHROPIC_MESSAGE_PINS: ModelPins;
34
+ export declare const GOOGLE_GENERATE_PINS: ModelPins;
@@ -0,0 +1,20 @@
1
+ /** Every wire spec the SDK ships, indexed by id.
2
+ *
3
+ * A spec says HOW to talk to a provider API: field names, enum values, defaults,
4
+ * which shape a model version takes. It is deliberately DATA, so the same file
5
+ * is consumed by this SDK and by the Python and Rust ports, and a provider
6
+ * change is one reviewable diff rather than three code changes.
7
+ *
8
+ * GENERATED by scripts/gen-wire-registry.ts — do not hand-edit. Add a spec by
9
+ * dropping the JSON into src/wire/specs/ and running `bun run gen:registry`.
10
+ *
11
+ * This index is what the chain tests and the coverage audit enumerate. The
12
+ * ADAPTERS do not read it: each family has its own loader (chat-specs,
13
+ * media-specs, service-specs, retrieval-specs) so a chat call does not drag
14
+ * every batch and media spec into the bundle.
15
+ */
16
+ import type { SpecDelta } from './inherit';
17
+ /** All shipped specs, keyed by `provider/api@version` id. */
18
+ export declare const WIRE_SPECS: ReadonlyMap<string, SpecDelta>;
19
+ /** Resolve a spec id to its flattened form, walking `extends`. */
20
+ export declare function getWireSpec(id: string): SpecDelta;
@@ -0,0 +1,14 @@
1
+ /** The hosted-retrieval spec family: vector stores, file search stores, collections.
2
+ *
3
+ * A sibling of `chat-specs.ts`, `media-specs.ts` and `service-specs.ts`, split for
4
+ * the same reason: the generated `registry.ts` imports all 118 specs, so anything
5
+ * reaching for it drags every family into the bundle. An application that never
6
+ * builds a corpus should not carry these.
7
+ *
8
+ * Only leaves are buildable. The base specs exist to be inherited from — they
9
+ * carry auth and content-type and produce no endpoint of their own — so naming
10
+ * one is a mistake to catch, not a request to send.
11
+ */
12
+ import type { WireSpec } from './interpreter';
13
+ /** Resolve a retrieval spec by id, flattening its `extends` chain. */
14
+ export declare function retrievalSpec(id: string): WireSpec;
@@ -0,0 +1,18 @@
1
+ /** The remaining runtime spec families: embeddings, realtime, batch, files, and
2
+ * the media adapters that had no builder seam until now.
3
+ *
4
+ * A sibling of `chat-specs.ts` and `media-specs.ts`, split for the same reason:
5
+ * the generated `registry.ts` imports all 71 specs, so an adapter reaching for it
6
+ * drags every family into the bundle whether or not anything executes them. Each
7
+ * file here loads exactly what its adapters run.
8
+ *
9
+ * Only leaves are buildable. The `*.base` specs exist to be inherited from and
10
+ * produce no endpoint of their own, so naming one is a mistake to catch rather
11
+ * than a request to send.
12
+ */
13
+ import type { WireSpec } from './interpreter';
14
+ /** The service spec for `id`, with its inheritance chain applied. Throws on an
15
+ * unknown or abstract id rather than substituting something plausible. */
16
+ export declare function serviceSpec(id: string): WireSpec;
17
+ /** Buildable ids, asserted by the tests so this list cannot drift from the files. */
18
+ export declare const SERVICE_SPEC_IDS: readonly string[];
@@ -0,0 +1,10 @@
1
+ /** The utility spec family: exact token counting, live model listing, file
2
+ * content retrieval, and the provenance check.
3
+ *
4
+ * Four small surfaces that share nothing except being requests. They are loaded
5
+ * together because each is a handful of specs and no consumer reaches one without
6
+ * reaching the layer that owns it.
7
+ */
8
+ import type { WireSpec } from './interpreter';
9
+ /** Resolve a utility spec by id, flattening its `extends` chain. */
10
+ export declare function utilitySpec(id: string): WireSpec;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@combycode/llm-sdk",
3
- "version": "2.2.2",
3
+ "version": "3.0.0",
4
4
  "description": "Unified, pluggable AI SDK for accessing the LLMs of every major provider (Anthropic, OpenAI, Google, xAI, OpenRouter) through one API. Cross-environment: Node, Bun, and the browser.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -43,9 +43,12 @@
43
43
  "format": "biome format --write src tests",
44
44
  "check": "biome check src tests",
45
45
  "check:fix": "biome check --write src tests",
46
- "gate": "node ../../quality-gate/gate.mjs",
46
+ "gen:registry": "bun run scripts/gen-wire-registry.ts",
47
+ "gate": "bun run scripts/gate.ts",
47
48
  "gate:selftest": "node ../../quality-gate/selftest.mjs",
48
- "gate:snapshot": "node ../../quality-gate/gate.mjs --only api-snapshot --update"
49
+ "record:responses": "bun run scripts/record-responses.ts",
50
+ "derive:shapes": "bun run scripts/derive-response-shapes.ts",
51
+ "gate:snapshot": "bun run scripts/gate.ts --only api-snapshot --update"
49
52
  },
50
53
  "devDependencies": {
51
54
  "@biomejs/biome": "^2.4.13",