@combycode/llm-sdk 1.0.0-rc.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 (228) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/LICENSE +21 -0
  3. package/README.md +103 -0
  4. package/dist/agent/approval-types.d.ts +49 -0
  5. package/dist/agent/context-registry/layers.d.ts +39 -0
  6. package/dist/agent/context-registry/registry-internal.d.ts +14 -0
  7. package/dist/agent/context-registry/registry.d.ts +104 -0
  8. package/dist/agent/context-registry/types.d.ts +110 -0
  9. package/dist/agent/guardrail-types.d.ts +58 -0
  10. package/dist/agent/history-types.d.ts +40 -0
  11. package/dist/agent/history.d.ts +111 -0
  12. package/dist/agent/loop-config.d.ts +67 -0
  13. package/dist/agent/loop-internals.d.ts +46 -0
  14. package/dist/agent/loop-step-state.d.ts +20 -0
  15. package/dist/agent/loop.d.ts +133 -0
  16. package/dist/agent/tool-key.d.ts +3 -0
  17. package/dist/agent/types.d.ts +138 -0
  18. package/dist/bus/agent-bus.d.ts +99 -0
  19. package/dist/bus/async-context.browser.d.ts +13 -0
  20. package/dist/bus/async-context.d.ts +11 -0
  21. package/dist/bus/async-context.types.d.ts +14 -0
  22. package/dist/bus/hook-bus.d.ts +43 -0
  23. package/dist/bus/hook-map.d.ts +592 -0
  24. package/dist/helpers/agent.d.ts +32 -0
  25. package/dist/helpers/batch.d.ts +74 -0
  26. package/dist/helpers/calibration-store.d.ts +27 -0
  27. package/dist/helpers/calibration-types.d.ts +64 -0
  28. package/dist/helpers/chain.d.ts +30 -0
  29. package/dist/helpers/client-pool.d.ts +15 -0
  30. package/dist/helpers/client-resolver.d.ts +62 -0
  31. package/dist/helpers/collection.d.ts +19 -0
  32. package/dist/helpers/consolidate.d.ts +66 -0
  33. package/dist/helpers/content.d.ts +25 -0
  34. package/dist/helpers/conversation-export.d.ts +14 -0
  35. package/dist/helpers/conversation-zip.d.ts +28 -0
  36. package/dist/helpers/count-tokens.d.ts +26 -0
  37. package/dist/helpers/define-tool.d.ts +66 -0
  38. package/dist/helpers/delegate.d.ts +6 -0
  39. package/dist/helpers/embed.d.ts +24 -0
  40. package/dist/helpers/engine.d.ts +121 -0
  41. package/dist/helpers/estimate-types.d.ts +67 -0
  42. package/dist/helpers/estimate.d.ts +45 -0
  43. package/dist/helpers/estimator.d.ts +48 -0
  44. package/dist/helpers/handoff-types.d.ts +18 -0
  45. package/dist/helpers/handoff.d.ts +14 -0
  46. package/dist/helpers/llm.d.ts +24 -0
  47. package/dist/helpers/mcp.d.ts +82 -0
  48. package/dist/helpers/media.d.ts +58 -0
  49. package/dist/helpers/models.d.ts +36 -0
  50. package/dist/helpers/moderate-types.d.ts +73 -0
  51. package/dist/helpers/moderate.d.ts +13 -0
  52. package/dist/helpers/moderation-guardrail.d.ts +29 -0
  53. package/dist/helpers/observer.d.ts +36 -0
  54. package/dist/helpers/one-shot.d.ts +86 -0
  55. package/dist/helpers/parallel.d.ts +16 -0
  56. package/dist/helpers/realtime.d.ts +25 -0
  57. package/dist/helpers/route.d.ts +29 -0
  58. package/dist/helpers/select-model.d.ts +41 -0
  59. package/dist/helpers/server.d.ts +32 -0
  60. package/dist/helpers/transcribe.d.ts +36 -0
  61. package/dist/index.browser.js +38047 -0
  62. package/dist/index.d.ts +275 -0
  63. package/dist/index.js +37974 -0
  64. package/dist/llm/audio/voices.d.ts +7 -0
  65. package/dist/llm/client-config.d.ts +37 -0
  66. package/dist/llm/client-internal.d.ts +28 -0
  67. package/dist/llm/client.d.ts +68 -0
  68. package/dist/llm/providers/_shared/constants.d.ts +5 -0
  69. package/dist/llm/providers/_shared/response-utils.d.ts +8 -0
  70. package/dist/llm/providers/anthropic/batch.d.ts +19 -0
  71. package/dist/llm/providers/anthropic/constants.d.ts +13 -0
  72. package/dist/llm/providers/anthropic/files.d.ts +23 -0
  73. package/dist/llm/providers/anthropic/messages.d.ts +30 -0
  74. package/dist/llm/providers/google/batch.d.ts +20 -0
  75. package/dist/llm/providers/google/constants.d.ts +6 -0
  76. package/dist/llm/providers/google/embeddings.d.ts +15 -0
  77. package/dist/llm/providers/google/files.d.ts +22 -0
  78. package/dist/llm/providers/google/generate.d.ts +27 -0
  79. package/dist/llm/providers/google/interactions.d.ts +30 -0
  80. package/dist/llm/providers/google/media.d.ts +27 -0
  81. package/dist/llm/providers/google/realtime.d.ts +27 -0
  82. package/dist/llm/providers/openai/batch.d.ts +19 -0
  83. package/dist/llm/providers/openai/completions.d.ts +25 -0
  84. package/dist/llm/providers/openai/embeddings.d.ts +16 -0
  85. package/dist/llm/providers/openai/files.d.ts +23 -0
  86. package/dist/llm/providers/openai/media.d.ts +28 -0
  87. package/dist/llm/providers/openai/moderations.d.ts +19 -0
  88. package/dist/llm/providers/openai/realtime.d.ts +24 -0
  89. package/dist/llm/providers/openai/responses.d.ts +29 -0
  90. package/dist/llm/providers/openai/tiers.d.ts +13 -0
  91. package/dist/llm/providers/openai/transcription.d.ts +20 -0
  92. package/dist/llm/providers/openrouter/completions.d.ts +15 -0
  93. package/dist/llm/providers/openrouter/embeddings.d.ts +7 -0
  94. package/dist/llm/providers/openrouter/media.d.ts +25 -0
  95. package/dist/llm/providers/openrouter/responses.d.ts +17 -0
  96. package/dist/llm/providers/xai/batch.d.ts +19 -0
  97. package/dist/llm/providers/xai/completions.d.ts +24 -0
  98. package/dist/llm/providers/xai/files.d.ts +23 -0
  99. package/dist/llm/providers/xai/media.d.ts +27 -0
  100. package/dist/llm/providers/xai/responses.d.ts +20 -0
  101. package/dist/llm/realtime/session.d.ts +34 -0
  102. package/dist/llm/realtime/types.d.ts +66 -0
  103. package/dist/llm/server-state.d.ts +32 -0
  104. package/dist/llm/types/audio.d.ts +18 -0
  105. package/dist/llm/types/messages.d.ts +125 -0
  106. package/dist/llm/types/options.d.ts +51 -0
  107. package/dist/llm/types/provider.d.ts +39 -0
  108. package/dist/llm/types/request.d.ts +51 -0
  109. package/dist/llm/types/response.d.ts +36 -0
  110. package/dist/llm/types/schema-utils.d.ts +8 -0
  111. package/dist/llm/types/stream.d.ts +42 -0
  112. package/dist/llm/types/tiers.d.ts +11 -0
  113. package/dist/llm/types/tools.d.ts +20 -0
  114. package/dist/network/engine.d.ts +87 -0
  115. package/dist/network/errors.d.ts +14 -0
  116. package/dist/network/queue-state-config.d.ts +41 -0
  117. package/dist/network/queue-state.d.ts +45 -0
  118. package/dist/network/rate-limiter.d.ts +49 -0
  119. package/dist/network/realtime-connection.d.ts +40 -0
  120. package/dist/network/request-queue.d.ts +40 -0
  121. package/dist/network/semaphore.d.ts +12 -0
  122. package/dist/network/sse.d.ts +3 -0
  123. package/dist/network/types.d.ts +127 -0
  124. package/dist/plugins/batch/batcher.d.ts +45 -0
  125. package/dist/plugins/batch/strategy.d.ts +20 -0
  126. package/dist/plugins/batch/types.d.ts +54 -0
  127. package/dist/plugins/cache/cache.d.ts +50 -0
  128. package/dist/plugins/cache/file-store.d.ts +15 -0
  129. package/dist/plugins/cache/memory-store.d.ts +10 -0
  130. package/dist/plugins/cache/types.d.ts +28 -0
  131. package/dist/plugins/configuration/configuration.d.ts +71 -0
  132. package/dist/plugins/context-guard/facts.d.ts +14 -0
  133. package/dist/plugins/context-guard/guard.d.ts +27 -0
  134. package/dist/plugins/context-guard/strategies/layered.d.ts +24 -0
  135. package/dist/plugins/context-guard/strategies/truncate.d.ts +19 -0
  136. package/dist/plugins/context-guard/tools.d.ts +50 -0
  137. package/dist/plugins/context-guard/types.d.ts +110 -0
  138. package/dist/plugins/context-measurer/calibration/store.d.ts +19 -0
  139. package/dist/plugins/context-measurer/counter/count-api.d.ts +41 -0
  140. package/dist/plugins/context-measurer/counter/heuristic.d.ts +25 -0
  141. package/dist/plugins/context-measurer/counter/hybrid.d.ts +33 -0
  142. package/dist/plugins/context-measurer/counter/tiktoken.d.ts +13 -0
  143. package/dist/plugins/context-measurer/measurer.d.ts +49 -0
  144. package/dist/plugins/context-measurer/types.d.ts +40 -0
  145. package/dist/plugins/cost-collector/collector.d.ts +42 -0
  146. package/dist/plugins/cost-collector/cost-collector-internal.d.ts +58 -0
  147. package/dist/plugins/cost-collector/cost-collector-types.d.ts +42 -0
  148. package/dist/plugins/embeddings/types.d.ts +23 -0
  149. package/dist/plugins/files/attachment.d.ts +79 -0
  150. package/dist/plugins/files/provider-adapter.d.ts +37 -0
  151. package/dist/plugins/files/registry.d.ts +48 -0
  152. package/dist/plugins/files/strategy.d.ts +38 -0
  153. package/dist/plugins/internal-tools/backends/local.d.ts +12 -0
  154. package/dist/plugins/internal-tools/builtin/builtin.d.ts +21 -0
  155. package/dist/plugins/internal-tools/builtin/clarify.d.ts +12 -0
  156. package/dist/plugins/internal-tools/builtin/classify.d.ts +12 -0
  157. package/dist/plugins/internal-tools/builtin/score.d.ts +13 -0
  158. package/dist/plugins/internal-tools/builtin/structure.d.ts +11 -0
  159. package/dist/plugins/internal-tools/builtin/summarize.d.ts +19 -0
  160. package/dist/plugins/internal-tools/id.d.ts +12 -0
  161. package/dist/plugins/internal-tools/registry.d.ts +24 -0
  162. package/dist/plugins/internal-tools/runner/define.d.ts +7 -0
  163. package/dist/plugins/internal-tools/runner/json-enforcement.d.ts +3 -0
  164. package/dist/plugins/internal-tools/runner/runner.d.ts +47 -0
  165. package/dist/plugins/internal-tools/runner/template.d.ts +10 -0
  166. package/dist/plugins/internal-tools/runner/types.d.ts +57 -0
  167. package/dist/plugins/internal-tools/runner/variants.d.ts +34 -0
  168. package/dist/plugins/internal-tools/types.d.ts +80 -0
  169. package/dist/plugins/logger/console-sink.d.ts +26 -0
  170. package/dist/plugins/logger/logger.d.ts +38 -0
  171. package/dist/plugins/logger/types.d.ts +25 -0
  172. package/dist/plugins/mcp/base-transport.d.ts +58 -0
  173. package/dist/plugins/mcp/client.d.ts +92 -0
  174. package/dist/plugins/mcp/jsonrpc.d.ts +20 -0
  175. package/dist/plugins/mcp/oauth.d.ts +122 -0
  176. package/dist/plugins/mcp/sampling.d.ts +17 -0
  177. package/dist/plugins/mcp/tools.d.ts +20 -0
  178. package/dist/plugins/mcp/transport-http.d.ts +50 -0
  179. package/dist/plugins/mcp/transport-stdio.d.ts +23 -0
  180. package/dist/plugins/mcp/transport-ws.d.ts +32 -0
  181. package/dist/plugins/mcp/transport.d.ts +29 -0
  182. package/dist/plugins/mcp/types.d.ts +202 -0
  183. package/dist/plugins/mcp/url-guard.d.ts +70 -0
  184. package/dist/plugins/mcp/win-spawn.d.ts +20 -0
  185. package/dist/plugins/media/file-store.d.ts +24 -0
  186. package/dist/plugins/media/memory-store.d.ts +17 -0
  187. package/dist/plugins/media/output.d.ts +44 -0
  188. package/dist/plugins/media/source-image.d.ts +36 -0
  189. package/dist/plugins/media/types.d.ts +146 -0
  190. package/dist/plugins/model-catalog/catalog.d.ts +152 -0
  191. package/dist/plugins/permissions/glob.d.ts +6 -0
  192. package/dist/plugins/permissions/matchers.d.ts +7 -0
  193. package/dist/plugins/permissions/policy.d.ts +10 -0
  194. package/dist/plugins/permissions/types.d.ts +22 -0
  195. package/dist/plugins/persistence/file.d.ts +25 -0
  196. package/dist/plugins/persistence/memory.d.ts +23 -0
  197. package/dist/plugins/persistence/types.d.ts +21 -0
  198. package/dist/plugins/retrieval/chunker.d.ts +28 -0
  199. package/dist/plugins/retrieval/hosted-google.d.ts +60 -0
  200. package/dist/plugins/retrieval/hosted-openai.d.ts +45 -0
  201. package/dist/plugins/retrieval/hosted-xai.d.ts +57 -0
  202. package/dist/plugins/retrieval/index.d.ts +70 -0
  203. package/dist/plugins/retrieval/local.d.ts +50 -0
  204. package/dist/plugins/retrieval/types.d.ts +161 -0
  205. package/dist/plugins/retrieval/vector-store.d.ts +70 -0
  206. package/dist/plugins/scheduler/scheduler.d.ts +31 -0
  207. package/dist/plugins/telemetry/telemetry.d.ts +118 -0
  208. package/dist/plugins/tool-catalog/catalog.d.ts +31 -0
  209. package/dist/plugins/tool-catalog/errors.d.ts +22 -0
  210. package/dist/plugins/tool-catalog/types.d.ts +44 -0
  211. package/dist/runtime/runtime.d.ts +20 -0
  212. package/dist/server/auth.d.ts +25 -0
  213. package/dist/server/dispatch.d.ts +35 -0
  214. package/dist/server/loaders.d.ts +26 -0
  215. package/dist/server/oai-adapter.d.ts +30 -0
  216. package/dist/server/oai-types.d.ts +114 -0
  217. package/dist/server/response-store.d.ts +59 -0
  218. package/dist/server/router.d.ts +59 -0
  219. package/dist/server/server.d.ts +61 -0
  220. package/dist/types/request-context.d.ts +46 -0
  221. package/dist/util/async.d.ts +3 -0
  222. package/dist/util/base64.d.ts +8 -0
  223. package/dist/util/duration.d.ts +12 -0
  224. package/dist/util/http.d.ts +9 -0
  225. package/dist/util/image-mime.d.ts +8 -0
  226. package/dist/util/json-schema.d.ts +7 -0
  227. package/dist/util/wav.d.ts +20 -0
  228. package/package.json +95 -0
@@ -0,0 +1,13 @@
1
+ /** OpenAI service-tier mapping — provider-specific, kept here (shared by the
2
+ * responses + completions adapters), never leaked into the SDK core.
3
+ * Request param + response value share the enum: auto|default|flex|scale|priority. */
4
+ import type { ServiceTier } from '../../types/tiers';
5
+ /** Map a unified tier to OpenAI's `service_tier`. Unknown values pass through if
6
+ * OpenAI accepts them, otherwise fall back to `auto`. Undefined → omit. */
7
+ export declare function openaiRequestTier(t?: ServiceTier): string | undefined;
8
+ /** OpenAI billed `service_tier` (response) → {raw, normalized catalog key}.
9
+ * `default` is OpenAI's word for the standard tier. */
10
+ export declare function openaiBilledTier(raw: unknown): {
11
+ serviceTier?: string;
12
+ pricingTier?: string;
13
+ };
@@ -0,0 +1,20 @@
1
+ /** OpenAI transcription adapter — POST /v1/audio/transcriptions (multipart).
2
+ * All HTTP flows through the injected EngineFetch (rawBody multipart, like the
3
+ * batch file upload). gpt-4o-transcribe / whisper return `{ text }`. */
4
+ import type { EngineFetch } from '../../../network/types';
5
+ export interface OpenAITranscriptionAdapterConfig {
6
+ apiKey: string;
7
+ baseURL?: string;
8
+ }
9
+ export interface TranscriptionRequest {
10
+ bytes: Uint8Array;
11
+ mimeType: string;
12
+ model: string;
13
+ language?: string;
14
+ }
15
+ export declare class OpenAITranscriptionAdapter {
16
+ private readonly apiKey;
17
+ private readonly baseURL;
18
+ constructor(config: OpenAITranscriptionAdapterConfig);
19
+ transcribe(req: TranscriptionRequest, fetch: EngineFetch): Promise<string>;
20
+ }
@@ -0,0 +1,15 @@
1
+ /** OpenRouter provider adapter — OpenAI-compatible with extensions. */
2
+ import type { ProviderAdapter, ProviderHttpRequest } from '../../types/provider';
3
+ import type { NormalizedRequest } from '../../types/request';
4
+ import { OpenAIAdapter } from '../openai/completions';
5
+ export interface OpenRouterAdapterConfig {
6
+ apiKey: string;
7
+ baseURL?: string;
8
+ }
9
+ export declare class OpenRouterAdapter extends OpenAIAdapter {
10
+ readonly name: ProviderAdapter['name'];
11
+ constructor(config: OpenRouterAdapterConfig);
12
+ baseURL(): string;
13
+ completionPath(): string;
14
+ buildRequest(req: NormalizedRequest): ProviderHttpRequest;
15
+ }
@@ -0,0 +1,7 @@
1
+ /** OpenRouter embeddings adapter — OpenAI-compatible at openrouter.ai/api/v1. */
2
+ import { OpenAIEmbeddingAdapter, type OpenAIEmbeddingAdapterConfig } from '../openai/embeddings';
3
+ export declare class OpenRouterEmbeddingAdapter extends OpenAIEmbeddingAdapter {
4
+ readonly name: string;
5
+ constructor(config: OpenAIEmbeddingAdapterConfig);
6
+ protected embeddingsPath(): string;
7
+ }
@@ -0,0 +1,25 @@
1
+ /** OpenRouter media adapter. OpenRouter has NO dedicated media endpoints —
2
+ * image (and audio) generation go through `POST /api/v1/chat/completions` with
3
+ * a `modalities` field; output comes back on `message.images[]` /
4
+ * `message.audio`. Cost is the provider-reported `usage.cost`. */
5
+ import type { EngineFetch } from '../../../network/types';
6
+ import type { AudioGenRequest, ImageEditRequest, ImageGenRequest, MediaCapabilities, MediaProviderAdapter, RawMediaResult } from '../../../plugins/media/types';
7
+ export interface OpenRouterMediaAdapterConfig {
8
+ apiKey: string;
9
+ baseURL?: string;
10
+ }
11
+ export declare class OpenRouterMediaAdapter implements MediaProviderAdapter {
12
+ readonly name = "openrouter";
13
+ private readonly apiKey;
14
+ private readonly baseURL;
15
+ constructor(config: OpenRouterMediaAdapterConfig);
16
+ capabilities(): MediaCapabilities;
17
+ private authHeaders;
18
+ generateImage(req: ImageGenRequest, fetch: EngineFetch): Promise<RawMediaResult[]>;
19
+ editImage(req: ImageEditRequest, fetch: EngineFetch): Promise<RawMediaResult[]>;
20
+ generateAudio(req: AudioGenRequest, fetch: EngineFetch): Promise<RawMediaResult>;
21
+ /** image_config from normalized params (aspect_ratio / image_size / strength). */
22
+ private imageConfig;
23
+ private chat;
24
+ private chatImage;
25
+ }
@@ -0,0 +1,17 @@
1
+ /** OpenRouter Responses API adapter.
2
+ * Drop-in replacement for OpenAI Responses API at openrouter.ai/api/v1/responses.
3
+ * Stateless: no previous_response_id support (beta limitation). */
4
+ import type { ProviderAdapter, ProviderHttpRequest } from '../../types/provider';
5
+ import type { NormalizedRequest } from '../../types/request';
6
+ import { OpenAIResponsesAdapter } from '../openai/responses';
7
+ export interface OpenRouterResponsesAdapterConfig {
8
+ apiKey: string;
9
+ baseURL?: string;
10
+ }
11
+ export declare class OpenRouterResponsesAdapter extends OpenAIResponsesAdapter {
12
+ readonly name: ProviderAdapter['name'];
13
+ constructor(config: OpenRouterResponsesAdapterConfig);
14
+ baseURL(): string;
15
+ completionPath(): string;
16
+ buildRequest(req: NormalizedRequest): ProviderHttpRequest;
17
+ }
@@ -0,0 +1,19 @@
1
+ /** xAI batch adapter — create batch, add requests, poll, get results.
2
+ * All HTTP flows through the injected EngineFetch (NetworkEngine queue). */
3
+ import type { EngineFetch } from '../../../network/types';
4
+ import type { BatchProviderAdapter, BatchRequest, BatchResult, BatchStatus } from '../../../plugins/batch/types';
5
+ export interface XAIBatchAdapterConfig {
6
+ apiKey: string;
7
+ baseURL?: string;
8
+ }
9
+ export declare class XAIBatchAdapter implements BatchProviderAdapter {
10
+ readonly name = "xai";
11
+ private readonly apiKey;
12
+ private readonly baseURL;
13
+ constructor(config: XAIBatchAdapterConfig);
14
+ private bearer;
15
+ submit(requests: BatchRequest[], fetch: EngineFetch): Promise<string>;
16
+ getStatus(batchId: string, fetch: EngineFetch): Promise<BatchStatus>;
17
+ getResults(batchId: string, fetch: EngineFetch): Promise<BatchResult[]>;
18
+ cancel(batchId: string, fetch: EngineFetch): Promise<void>;
19
+ }
@@ -0,0 +1,24 @@
1
+ /** xAI (Grok) provider adapter — OpenAI-compatible Chat Completions.
2
+ * Key differences from OpenAI:
3
+ * - Uses max_tokens (not max_completion_tokens)
4
+ * - Reasoning via model variant (grok-*-reasoning), not reasoning param
5
+ * - Returns reasoning_content in message (plain text, unlike OpenAI which hides it)
6
+ */
7
+ import type { SSEEvent } from '../../../network/types';
8
+ import type { ProviderAdapter, ProviderHttpRequest } from '../../types/provider';
9
+ import type { NormalizedRequest } from '../../types/request';
10
+ import type { CompletionResponse } from '../../types/response';
11
+ import type { StreamEvent } from '../../types/stream';
12
+ import { OpenAIAdapter } from '../openai/completions';
13
+ export interface XAIAdapterConfig {
14
+ apiKey: string;
15
+ baseURL?: string;
16
+ }
17
+ export declare class XAIAdapter extends OpenAIAdapter {
18
+ readonly name: ProviderAdapter['name'];
19
+ constructor(config: XAIAdapterConfig);
20
+ baseURL(): string;
21
+ buildRequest(req: NormalizedRequest): ProviderHttpRequest;
22
+ parseResponse(raw: unknown, latencyMs: number): CompletionResponse;
23
+ parseStreamEvent(event: SSEEvent): StreamEvent[];
24
+ }
@@ -0,0 +1,23 @@
1
+ /** xAI file adapter — POST /v1/files (purpose=assistants).
2
+ * All HTTP flows through the injected EngineFetch (NetworkEngine queue). */
3
+ import type { EngineFetch } from '../../../network/types';
4
+ import type { FileAttachment } from '../../../plugins/files/attachment';
5
+ import type { FileProviderAdapter, FileUploadResult, RemoteFileInfo } from '../../../plugins/files/provider-adapter';
6
+ export interface XAIFileAdapterConfig {
7
+ apiKey: string;
8
+ baseURL?: string;
9
+ }
10
+ export declare class XAIFileAdapter implements FileProviderAdapter {
11
+ readonly name = "xai";
12
+ readonly expiresAfter: null;
13
+ readonly maxFileSize = 48000000;
14
+ readonly supportedTypes: string[];
15
+ private readonly apiKey;
16
+ private readonly baseURL;
17
+ constructor(config: XAIFileAdapterConfig);
18
+ private bearer;
19
+ upload(file: FileAttachment, fetch: EngineFetch): Promise<FileUploadResult>;
20
+ delete(remoteId: string, fetch: EngineFetch): Promise<void>;
21
+ getInfo(remoteId: string, fetch: EngineFetch): Promise<RemoteFileInfo | null>;
22
+ list(fetch: EngineFetch): Promise<RemoteFileInfo[]>;
23
+ }
@@ -0,0 +1,27 @@
1
+ /** xAI media adapter — images, TTS, video. All HTTP through EngineFetch. */
2
+ import type { EngineFetch } from '../../../network/types';
3
+ import type { AudioGenRequest, ImageEditRequest, ImageGenRequest, MediaCapabilities, MediaProviderAdapter, RawMediaResult, VideoGenRequest, VideoStatus } from '../../../plugins/media/types';
4
+ export interface XAIMediaAdapterConfig {
5
+ apiKey: string;
6
+ baseURL?: string;
7
+ }
8
+ export declare class XAIMediaAdapter implements MediaProviderAdapter {
9
+ readonly name = "xai";
10
+ private readonly apiKey;
11
+ private readonly baseURL;
12
+ constructor(config: XAIMediaAdapterConfig);
13
+ capabilities(): MediaCapabilities;
14
+ private authHeaders;
15
+ generateImage(req: ImageGenRequest, fetch: EngineFetch): Promise<RawMediaResult[]>;
16
+ /** Image-to-image edit via `/v1/images/edits` (JSON; base64 data-URL or
17
+ * file_id, no multipart, no mask). */
18
+ editImage(req: ImageEditRequest, fetch: EngineFetch): Promise<RawMediaResult[]>;
19
+ /** Parse an images response (b64_json inline or url to download), attaching
20
+ * xAI's provider cost (usage.cost_in_usd_ticks) to the first item. */
21
+ private parseImages;
22
+ generateAudio(req: AudioGenRequest, fetch: EngineFetch): Promise<RawMediaResult>;
23
+ submitVideo(req: VideoGenRequest, fetch: EngineFetch): Promise<string>;
24
+ getVideoStatus(operationId: string, fetch: EngineFetch): Promise<VideoStatus>;
25
+ downloadVideo(operationId: string, fetch: EngineFetch): Promise<RawMediaResult>;
26
+ cancelVideo(operationId: string, fetch: EngineFetch): Promise<void>;
27
+ }
@@ -0,0 +1,20 @@
1
+ /** xAI Responses API adapter.
2
+ * Mirrors OpenAI Responses API at api.x.ai/v1/responses.
3
+ * Differences:
4
+ * - System prompt via role:system in input (not instructions)
5
+ * - Reasoning automatic for reasoning models (no effort param needed)
6
+ * - Encrypted reasoning via include: ["reasoning.encrypted_content"]
7
+ */
8
+ import type { ProviderAdapter, ProviderHttpRequest } from '../../types/provider';
9
+ import type { NormalizedRequest } from '../../types/request';
10
+ import { OpenAIResponsesAdapter } from '../openai/responses';
11
+ export interface XAIResponsesAdapterConfig {
12
+ apiKey: string;
13
+ baseURL?: string;
14
+ }
15
+ export declare class XAIResponsesAdapter extends OpenAIResponsesAdapter {
16
+ readonly name: ProviderAdapter['name'];
17
+ constructor(config: XAIResponsesAdapterConfig);
18
+ baseURL(): string;
19
+ buildRequest(req: NormalizedRequest): ProviderHttpRequest;
20
+ }
@@ -0,0 +1,34 @@
1
+ /** BaseRealtimeSession — wires an engine RealtimeConnection to the normalized
2
+ * RealtimeSession event model. Providers subclass it and implement just the
3
+ * protocol mapping (onOpen handshake, frame → event, input → wire frames). */
4
+ import type { RealtimeConnection, RealtimeFrame } from '../../network/types';
5
+ import type { RealtimeEvent, RealtimeEventType, RealtimeInput, RealtimeSession } from './types';
6
+ export declare abstract class BaseRealtimeSession implements RealtimeSession {
7
+ protected readonly conn: RealtimeConnection;
8
+ private readonly listeners;
9
+ private ready;
10
+ private readonly outbox;
11
+ constructor(conn: RealtimeConnection);
12
+ on<E extends RealtimeEventType>(type: E, cb: (e: Extract<RealtimeEvent, {
13
+ type: E;
14
+ }>) => void): () => void;
15
+ close(): void;
16
+ abstract send(input: RealtimeInput, opts?: {
17
+ turnComplete?: boolean;
18
+ }): void;
19
+ /** Fan an event out to subscribers. */
20
+ protected emit(event: RealtimeEvent): void;
21
+ /** Mark the session ready: flush any buffered sends and emit `open`. Idempotent.
22
+ * Called by the subclass once its handshake is complete (OpenAI: on socket
23
+ * open; Google: on `setupComplete`). */
24
+ protected markReady(): void;
25
+ /** Run a wire-send now if ready, else buffer it until markReady(). Lets callers
26
+ * `createRealtime(...).send(...)` without first awaiting an `open` event. */
27
+ protected whenReady(fn: () => void): void;
28
+ /** Send a JSON object as a text frame (the common wire form for both providers). */
29
+ protected sendJSON(obj: unknown): void;
30
+ /** Provider handshake on socket open (e.g. session.update / setup). */
31
+ protected abstract onOpen(): void;
32
+ /** Map one inbound provider frame onto zero or more normalized events. */
33
+ protected abstract onFrame(frame: RealtimeFrame): void;
34
+ }
@@ -0,0 +1,66 @@
1
+ /** Realtime / live session — the provider-agnostic DX surface.
2
+ *
3
+ * A RealtimeSession normalizes two very different provider protocols (OpenAI's
4
+ * typed event stream, Google's turn-based bidi) onto one event model. Provider
5
+ * adapters own the wire mapping; the engine owns the WebSocket transport
6
+ * (engine.connect — queue-exempt). */
7
+ import type { EngineConnect } from '../../network/types';
8
+ import type { Usage } from '../types/response';
9
+ export type RealtimeModality = 'text' | 'audio';
10
+ export interface RealtimeSessionConfig {
11
+ /** Bare model id (provider is fixed by the adapter). */
12
+ model: string;
13
+ /** Desired output modalities. Default `['text']`. Note: some models are
14
+ * audio-native (Gemini Live streams audio regardless). */
15
+ modalities?: RealtimeModality[];
16
+ /** Voice id for audio output, where the provider supports selection. */
17
+ voice?: string;
18
+ /** System instructions for the session. */
19
+ instructions?: string;
20
+ }
21
+ /** One input turn (or partial turn) from the user. */
22
+ export interface RealtimeInput {
23
+ text?: string;
24
+ /** Raw audio bytes (provider-specific encoding, e.g. PCM16). */
25
+ audio?: Uint8Array;
26
+ }
27
+ /** Normalized session events. Adapters map provider frames onto these. */
28
+ export type RealtimeEvent = {
29
+ type: 'open';
30
+ } | {
31
+ type: 'text';
32
+ delta: string;
33
+ } | {
34
+ type: 'audio';
35
+ chunk: Uint8Array;
36
+ mimeType: string;
37
+ sampleRate?: number;
38
+ } | {
39
+ type: 'turnComplete';
40
+ } | {
41
+ type: 'usage';
42
+ usage: Usage;
43
+ } | {
44
+ type: 'error';
45
+ error: Error;
46
+ } | {
47
+ type: 'close';
48
+ };
49
+ export type RealtimeEventType = RealtimeEvent['type'];
50
+ export interface RealtimeSession {
51
+ /** Send an input turn. `turnComplete` defaults to true (commit + request a
52
+ * response now); pass false to stream a turn across multiple sends. */
53
+ send(input: RealtimeInput, opts?: {
54
+ turnComplete?: boolean;
55
+ }): void;
56
+ /** Subscribe to a normalized event. Returns an unsubscribe function. */
57
+ on<E extends RealtimeEventType>(type: E, cb: (e: Extract<RealtimeEvent, {
58
+ type: E;
59
+ }>) => void): () => void;
60
+ /** Close the underlying socket. */
61
+ close(): void;
62
+ }
63
+ /** Per-provider realtime adapter. Mirrors ProviderAdapter for request/response. */
64
+ export interface RealtimeProviderAdapter {
65
+ connect(config: RealtimeSessionConfig, connect: EngineConnect): RealtimeSession;
66
+ }
@@ -0,0 +1,32 @@
1
+ /** Server-state decision — the unified "send id vs resend history" brain.
2
+ *
3
+ * Several providers keep conversation state server-side (OpenAI Responses
4
+ * `previous_response_id`, xAI, Google Interactions `previous_interaction_id`).
5
+ * When the prior assistant turn carries a server id we produced, we can send
6
+ * just that id + the new turn instead of the whole transcript.
7
+ *
8
+ * Safe by default — reuse only when ALL hold:
9
+ * - the caller didn't opt out (`stateful !== false`),
10
+ * - the prior id was produced by the SAME provider (cross-provider ids are
11
+ * meaningless elsewhere — history stays portable),
12
+ * - the provider/model supports it (catalog),
13
+ * - it's within the retention TTL (catalog duration),
14
+ * - the model matches, OR the provider is not model-bound (catalog).
15
+ * Otherwise we fall back to resending full history (always correct). */
16
+ import type { ModelCatalog } from '../plugins/model-catalog/catalog';
17
+ import type { Message } from './types/messages';
18
+ import type { ProviderName } from './types/provider';
19
+ export interface ServerStateDecision {
20
+ /** Provider-agnostic id to continue from (adapter maps to its own param). */
21
+ previousResponseId?: string;
22
+ /** Messages to actually send: trimmed to the new turn(s) when chaining, else full. */
23
+ messages: Message[];
24
+ }
25
+ export declare function resolveServerState(args: {
26
+ messages: Message[];
27
+ provider: ProviderName;
28
+ model: string;
29
+ catalog: ModelCatalog;
30
+ stateful: boolean;
31
+ now: number;
32
+ }): ServerStateDecision;
@@ -0,0 +1,18 @@
1
+ /** Shared audio types — one shape for voice/format options and raw audio input
2
+ * across complete() / generateAudio() / createRealtime() / transcribe(). */
3
+ export type AudioFormat = 'wav' | 'mp3' | 'pcm16' | 'opus' | 'flac' | 'aac';
4
+ /** Output audio controls. `voice` accepts a provider voice id OR a unified alias
5
+ * (see resolveVoice). */
6
+ export interface AudioOptions {
7
+ voice?: string;
8
+ format?: AudioFormat;
9
+ /** Sample rate (Hz) for raw/PCM output. */
10
+ sampleRate?: number;
11
+ }
12
+ /** Audio input source. A file path is MIME-detected; raw bytes should declare
13
+ * `mimeType` (and `sampleRate` for PCM). */
14
+ export interface AudioInput {
15
+ data: Uint8Array | string;
16
+ mimeType?: string;
17
+ sampleRate?: number;
18
+ }
@@ -0,0 +1,125 @@
1
+ /** Universal message and content types — shared by LLM, Agent, Server. */
2
+ import type { ProviderName } from './provider';
3
+ export type Role = 'system' | 'user' | 'assistant' | 'tool';
4
+ /** Producer-bound provenance for an assistant turn.
5
+ *
6
+ * History is portable across providers, but some state is only valid for the
7
+ * provider that produced it: a server-side conversation id (interaction_id /
8
+ * response_id) and opaque signatures (Gemini thought-signatures, reasoning
9
+ * blobs). Anything here MUST be ignored by a different provider — adapters
10
+ * consume it only when `origin.provider === self`. */
11
+ export interface MessageOrigin {
12
+ /** Provider that produced this assistant turn. The gate for cross-provider use. */
13
+ provider: ProviderName;
14
+ /** Model that produced it (for model-bound server-state checks). */
15
+ model?: string;
16
+ /** Server-side conversation id for stateful continuation (interaction_id / response_id). */
17
+ serverStateId?: string;
18
+ /** Opaque provider signatures to echo back (thought-signature, encrypted reasoning). */
19
+ signatures?: unknown;
20
+ }
21
+ export type ContentPart = TextPart | ImagePart | DocumentPart | AudioPart | VideoPart | ToolCallPart | ToolResultPart | ImageOutputPart | AudioOutputPart | VideoOutputPart;
22
+ export interface TextPart {
23
+ type: 'text';
24
+ text: string;
25
+ cache?: boolean;
26
+ }
27
+ export interface ImagePart {
28
+ type: 'image';
29
+ source: DataSource;
30
+ detail?: 'auto' | 'low' | 'high';
31
+ }
32
+ export interface DocumentPart {
33
+ type: 'document';
34
+ source: DataSource;
35
+ citations?: boolean;
36
+ }
37
+ export interface AudioPart {
38
+ type: 'audio';
39
+ source: DataSource;
40
+ }
41
+ export interface VideoPart {
42
+ type: 'video';
43
+ source: DataSource;
44
+ }
45
+ export interface ToolCallPart {
46
+ type: 'tool_call';
47
+ id: string;
48
+ name: string;
49
+ arguments: Record<string, unknown>;
50
+ /** Provider-specific metadata (e.g. Google thought signatures). */
51
+ _meta?: Record<string, unknown>;
52
+ }
53
+ export interface ToolResultPart {
54
+ type: 'tool_result';
55
+ id: string;
56
+ content: string | ContentPart[];
57
+ isError?: boolean;
58
+ }
59
+ export interface ImageOutputPart {
60
+ type: 'image_output';
61
+ mediaId: string;
62
+ mimeType: string;
63
+ revisedPrompt?: string;
64
+ width?: number;
65
+ height?: number;
66
+ /** Transient: raw base64 from provider. Stripped after storage. */
67
+ _data?: string;
68
+ }
69
+ export interface AudioOutputPart {
70
+ type: 'audio_output';
71
+ mediaId: string;
72
+ mimeType: string;
73
+ durationMs?: number;
74
+ sampleRate?: number;
75
+ _data?: string;
76
+ }
77
+ export interface VideoOutputPart {
78
+ type: 'video_output';
79
+ mediaId: string;
80
+ mimeType: string;
81
+ durationMs?: number;
82
+ width?: number;
83
+ height?: number;
84
+ _data?: string;
85
+ }
86
+ export type MediaOutputPart = ImageOutputPart | AudioOutputPart | VideoOutputPart;
87
+ export type DataSource = {
88
+ type: 'base64';
89
+ mimeType: string;
90
+ data: string;
91
+ } | {
92
+ type: 'url';
93
+ url: string;
94
+ } | {
95
+ type: 'file';
96
+ fileId: string;
97
+ } | {
98
+ type: 'path';
99
+ mimeType: string;
100
+ path: string;
101
+ } | {
102
+ type: 'buffer';
103
+ mimeType: string;
104
+ data: Uint8Array;
105
+ } | {
106
+ type: 'provider_ref';
107
+ mimeType: string;
108
+ refId: string;
109
+ };
110
+ export type Content = string | ContentPart[];
111
+ export interface Message {
112
+ role: Role;
113
+ content: Content;
114
+ cache?: boolean;
115
+ /** Universal message id (ours) — for dedup / referencing / editing. */
116
+ id?: string;
117
+ /** Creation timestamp (ms epoch) — universal; drives server-state TTL checks. */
118
+ createdAt?: number;
119
+ /** Producer-bound provenance (assistant turns). See {@link MessageOrigin}. */
120
+ origin?: MessageOrigin;
121
+ }
122
+ /** Normalize any content to ContentPart array. */
123
+ export declare function contentParts(content: Content): ContentPart[];
124
+ /** Extract plain text from content. */
125
+ export declare function contentText(content: Content): string;
@@ -0,0 +1,51 @@
1
+ /** ExecuteOptions — per-call overrides for client.complete()/.stream(). */
2
+ import type { ConversationHistory } from '../../agent/history';
3
+ import type { RequestContext } from '../../types/request-context';
4
+ import type { AudioOptions } from './audio';
5
+ import type { CacheConfig, ThinkingConfig } from './request';
6
+ import type { ServiceTier } from './tiers';
7
+ import type { Tool, ToolChoice } from './tools';
8
+ export interface ExecuteOptions {
9
+ /** Per-call system prompt. Stacked with LLMClient.system + any role:'system'
10
+ * messages from the input (in this priority order). When AgentLoop calls
11
+ * the client it passes its composed registry-system here so that layered
12
+ * prompts (role / context / facts / chat.facts / context-guard.summary)
13
+ * flow through to the request without depending on the immutable
14
+ * LLMClient.system. */
15
+ system?: string;
16
+ /** Conversation reference, propagated into onMessageResolve so listeners
17
+ * (ContextGuard, FilesRegistry) can route per-conversation. */
18
+ history?: ConversationHistory;
19
+ maxTokens?: number;
20
+ temperature?: number;
21
+ topP?: number;
22
+ stop?: string[];
23
+ tools?: Tool[];
24
+ toolChoice?: ToolChoice;
25
+ structured?: {
26
+ schema: Record<string, unknown>;
27
+ name?: string;
28
+ strict?: boolean;
29
+ };
30
+ audio?: AudioOptions;
31
+ outputModalities?: Array<'text' | 'audio'>;
32
+ thinking?: ThinkingConfig;
33
+ cache?: CacheConfig;
34
+ /** Service tier for this call — 'auto' | 'standard' | 'priority' | 'flex' (or
35
+ * any provider-accepted string). Maps per-provider; unsupported → no-op.
36
+ * `batch` is the separate Batch API, not a value here. */
37
+ serviceTier?: ServiceTier;
38
+ providerOptions?: Record<string, unknown>;
39
+ previousResponseId?: string;
40
+ /** Server-state optimization: when the prior assistant turn carries a usable
41
+ * server id (same provider, within TTL, model ok), send the id + only the new
42
+ * turn instead of the full transcript. Default ON; set false to always resend
43
+ * history (fully portable). Ignored if `previousResponseId` is set manually. */
44
+ stateful?: boolean;
45
+ signal?: AbortSignal;
46
+ timeout?: number;
47
+ cacheKey?: string;
48
+ cacheName?: string;
49
+ configName?: string;
50
+ ctx?: Partial<RequestContext>;
51
+ }
@@ -0,0 +1,39 @@
1
+ /** ProviderAdapter — each provider implements this. The LLMClient calls
2
+ * buildRequest(NormalizedRequest) → ProviderHttpRequest, sends via the
3
+ * injected fetch fn, then parseResponse(raw, latencyMs) → CompletionResponse. */
4
+ import type { SSEEvent } from '../../network/types';
5
+ import type { NormalizedRequest } from './request';
6
+ import type { CompletionResponse } from './response';
7
+ import type { StreamEvent } from './stream';
8
+ export type ProviderName = 'anthropic' | 'openai' | 'google' | 'xai' | 'openrouter';
9
+ export type ApiType = 'completions' | 'responses' | 'messages' | 'interactions' | 'generate';
10
+ export interface ProviderConfig {
11
+ provider: ProviderName;
12
+ apiKey: string;
13
+ baseURL?: string;
14
+ }
15
+ export interface ProviderHttpRequest {
16
+ body: Record<string, unknown>;
17
+ headers?: Record<string, string>;
18
+ /** Override of the default completion path. Used by providers that route
19
+ * per-API or per-modality. */
20
+ path?: string;
21
+ }
22
+ export interface ProviderAdapter {
23
+ readonly name: ProviderName;
24
+ /** Convert universal NormalizedRequest to provider HTTP body. */
25
+ buildRequest(req: NormalizedRequest): ProviderHttpRequest;
26
+ /** Parse provider's raw HTTP response body to a normalized CompletionResponse. */
27
+ parseResponse(raw: unknown, latencyMs: number): CompletionResponse;
28
+ /** Convert one SSE event from the provider stream into zero or more StreamEvents. */
29
+ parseStreamEvent(event: SSEEvent): StreamEvent[];
30
+ /** Auth headers (Bearer / x-api-key / etc.). */
31
+ authHeaders(): Record<string, string>;
32
+ /** Base URL — provider's domain root. */
33
+ baseURL(): string;
34
+ /** Path appended to baseURL for the completion endpoint. */
35
+ completionPath(): string;
36
+ /** Optional: mutate provider request to enable streaming (set stream:true,
37
+ * switch URL, etc.). */
38
+ enableStreaming?(providerReq: ProviderHttpRequest, req: NormalizedRequest): void;
39
+ }
@@ -0,0 +1,51 @@
1
+ /** Internal normalized request — what LLMClient hands to ProviderAdapter.
2
+ *
3
+ * In v2, the public surface is `client.complete(input, options?)` — model
4
+ * and system are fixed at construction. The LLMClient internally builds
5
+ * this `NormalizedRequest` from (input, options, this.model, this.system). */
6
+ import type { AudioOptions } from './audio';
7
+ import type { Message } from './messages';
8
+ import type { ServiceTier } from './tiers';
9
+ import type { Tool, ToolChoice } from './tools';
10
+ export interface NormalizedRequest {
11
+ /** From LLMClientConfig.model — fixed at construction. */
12
+ model: string;
13
+ /** Resolved messages array (input normalized + agent history if applicable). */
14
+ messages: Message[];
15
+ /** From LLMClientConfig.system or per-call override (rare). */
16
+ system?: string;
17
+ maxTokens?: number;
18
+ temperature?: number;
19
+ topP?: number;
20
+ stop?: string[];
21
+ tools?: Tool[];
22
+ toolChoice?: ToolChoice;
23
+ structured?: {
24
+ schema: Record<string, unknown>;
25
+ name?: string;
26
+ strict?: boolean;
27
+ };
28
+ thinking?: ThinkingConfig;
29
+ cache?: CacheConfig;
30
+ serviceTier?: ServiceTier;
31
+ providerOptions?: Record<string, unknown>;
32
+ audio?: AudioOptions;
33
+ outputModalities?: Array<'text' | 'audio'>;
34
+ previousResponseId?: string;
35
+ timeout?: number;
36
+ signal?: AbortSignal;
37
+ }
38
+ export type ThinkingConfig = {
39
+ mode: 'auto';
40
+ effort?: 'low' | 'medium' | 'high' | 'max';
41
+ } | {
42
+ mode: 'on';
43
+ effort?: 'low' | 'medium' | 'high' | 'max';
44
+ } | {
45
+ mode: 'off';
46
+ };
47
+ export type CacheConfig = 'auto' | 'off' | {
48
+ system?: boolean;
49
+ tools?: boolean;
50
+ ttl?: string;
51
+ };