@x12i/ai-dispatcher 2.4.1 → 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.
package/dist/index.d.cts CHANGED
@@ -3,6 +3,8 @@ export { ReasoningEffort, ReasoningOutcome, registerHostIntents } from '@x12i/ai
3
3
  import * as _x12i_openrouter_runtime from '@x12i/openrouter-runtime';
4
4
  import { RuntimeToolExecutor, RuntimeLogger, RuntimeRequest, RuntimeResponse, RuntimeUsage, RuntimeStreamEvent, CompiledOpenRouterRequest, OpenRouterRuntimeOptions } from '@x12i/openrouter-runtime';
5
5
  export { CompiledOpenRouterRequest, METADATA_NORMALIZATION_MAP, NormalizedMetadataKey, OpenRouterRuntimeOptions, RuntimeDefaults, RuntimeLogger, RuntimeMessage, RuntimeRequest, RuntimeResponse, RuntimeServerToolsPolicy, RuntimeStreamEvent, canonicalMetadataKey, decodeProviderMetadata, normalizeMetadata } from '@x12i/openrouter-runtime';
6
+ import { CapabilityApproval } from '@x12i/ai-input/core';
7
+ export { CapabilityApproval } from '@x12i/ai-input/core';
6
8
  import { CompiledBedrockRequest, BedrockRuntimeOptions } from '@x12i/bedrock-runtime';
7
9
  export { BedrockClientLike, BedrockCredentials, BedrockRuntimeOptions, CompiledBedrockRequest } from '@x12i/bedrock-runtime';
8
10
 
@@ -93,6 +95,52 @@ interface OpenAiRuntimeOptions {
93
95
  logger?: RuntimeLogger;
94
96
  }
95
97
 
98
+ /** Compact and readable write outline. Raw is `JSON.stringify` or the original string. */
99
+ type AiInputMode = "compact" | "readable" | "raw";
100
+ /** Wire codec chosen for one prepared value. Compact and readable default to `outline`. */
101
+ type AiInputCodec = "json" | "toon" | "text" | "outline";
102
+ /** `auto` stays on outline, JSON, or text until a matching approval and a tokenizer allow an alternate. */
103
+ type AiInputCodecChoice = "auto" | AiInputCodec;
104
+ type AiInputReadableFormat = "auto" | "json" | "toon" | "outline";
105
+ type AiInputSharing = "auto" | "off";
106
+ /** `raw` is the model body. `self-describing` adds the `@ai-input/1` header. */
107
+ type AiInputFraming = "self-describing" | "raw";
108
+ /** Optional `gpt-tokenizer` encodings. The package is not installed by the dispatcher. */
109
+ type AiInputTokenizer = "none" | "gpt:o200k_base" | "gpt:cl100k_base" | "gpt:p50k_base" | "gpt:p50k_edit" | "gpt:r50k_base";
110
+ /**
111
+ * How one dispatcher prepares model-visible input.
112
+ * Omitted fields use compact mode, `codec: "auto"`, `sharing: "auto"`, raw framing, and no tokenizer.
113
+ * Compact writes outline for structured values. `codec: "json"` keeps compact JSON. `mode: "raw"` keeps `JSON.stringify`.
114
+ */
115
+ interface AiInputSettings {
116
+ mode?: AiInputMode;
117
+ codec?: AiInputCodecChoice;
118
+ readableFormat?: AiInputReadableFormat;
119
+ sharing?: AiInputSharing;
120
+ framing?: AiInputFraming;
121
+ /**
122
+ * Approval lookup id. Defaults to the effective model for the call.
123
+ * Does not change the model sent to the provider.
124
+ */
125
+ model?: string;
126
+ tokenizer?: AiInputTokenizer;
127
+ /** Caller approvals. The dispatcher ships none. */
128
+ approvals?: readonly CapabilityApproval[];
129
+ }
130
+ /**
131
+ * What preparation did for one call.
132
+ * Omitted when preparation stayed on the unchanged JSON or text baseline.
133
+ */
134
+ interface InputResolution {
135
+ enabled: boolean;
136
+ /** Approval lookup id. Omitted when preparation is off or the call has no model id. */
137
+ model?: string;
138
+ mode?: AiInputMode;
139
+ codec?: AiInputCodec;
140
+ representation?: "value" | "shared-v1";
141
+ approvalSource?: "none" | "registry" | "explicit-caller" | "baseline";
142
+ changed: boolean;
143
+ }
96
144
  /** Caller role stamp. Omitted or blank fields are not stored. */
97
145
  interface RoleStamp {
98
146
  role?: string;
@@ -194,6 +242,13 @@ interface AiDispatcherRequest extends RuntimeRequest {
194
242
  * `endpoint` wins over `apiMode`. Stripped before the provider request is compiled.
195
243
  */
196
244
  cloudflare?: CloudflareRequestOptions;
245
+ /**
246
+ * Input preparation for this call.
247
+ * Omit it to use the dispatcher default. `false` skips preparation.
248
+ * A settings object overrides the dispatcher default for this call, including turning it back on.
249
+ * Stripped before the provider payload is built. This is not the Responses `input` field.
250
+ */
251
+ aiInput?: false | AiInputSettings;
197
252
  }
198
253
  interface DispatcherMcpTool {
199
254
  name: string;
@@ -237,6 +292,11 @@ interface AiDispatcherOptions {
237
292
  */
238
293
  metadataPriority?: readonly string[];
239
294
  logger?: RuntimeLogger;
295
+ /**
296
+ * Default input preparation. Omit it and every call uses compact `@x12i/ai-input`.
297
+ * `false` skips preparation unless a call passes settings.
298
+ */
299
+ aiInput?: false | AiInputSettings;
240
300
  }
241
301
  interface CompiledOpenAiRequest {
242
302
  provider: "openai";
@@ -248,6 +308,7 @@ interface CompiledOpenAiRequest {
248
308
  effectiveModel: string;
249
309
  reasoningResolution?: ReasoningResolution;
250
310
  cacheResolution?: CacheResolution;
311
+ inputResolution?: InputResolution;
251
312
  }
252
313
  interface CompiledCloudflareRequest {
253
314
  provider: "cloudflare";
@@ -261,6 +322,7 @@ interface CompiledCloudflareRequest {
261
322
  effectiveModel: string;
262
323
  reasoningResolution?: ReasoningResolution;
263
324
  cacheResolution?: CacheResolution;
325
+ inputResolution?: InputResolution;
264
326
  }
265
327
  type CompiledAiRequest = (CompiledOpenRouterRequest & {
266
328
  provider: "openrouter";
@@ -268,12 +330,14 @@ type CompiledAiRequest = (CompiledOpenRouterRequest & {
268
330
  effectiveModel: string;
269
331
  reasoningResolution?: ReasoningResolution;
270
332
  cacheResolution?: CacheResolution;
333
+ inputResolution?: InputResolution;
271
334
  }) | (CompiledBedrockRequest & {
272
335
  provider: "bedrock";
273
336
  requestedModel: string;
274
337
  effectiveModel: string;
275
338
  reasoningResolution?: ReasoningResolution;
276
339
  cacheResolution?: CacheResolution;
340
+ inputResolution?: InputResolution;
277
341
  }) | CompiledOpenAiRequest | CompiledCloudflareRequest;
278
342
  interface AiDispatcherUsage extends RuntimeUsage {
279
343
  /** Tokens read from a prompt cache. Omitted when the provider did not report any. */
@@ -286,6 +350,7 @@ interface AiDispatcherResponse extends RuntimeResponse {
286
350
  reasoningText?: string;
287
351
  reasoningResolution?: ReasoningResolution;
288
352
  cacheResolution?: CacheResolution;
353
+ inputResolution?: InputResolution;
289
354
  usage?: AiDispatcherUsage;
290
355
  }
291
356
  interface ProviderCallOptions {
@@ -309,7 +374,7 @@ interface CompiledOpenAiWireShape {
309
374
  interface AiDispatcher {
310
375
  run(request: AiDispatcherRequest): Promise<AiDispatcherResponse>;
311
376
  executeStreamingChat(request: AiDispatcherRequest): AsyncIterable<RuntimeStreamEvent>;
312
- compile(request: AiDispatcherRequest): CompiledAiRequest;
377
+ compile(request: AiDispatcherRequest): Promise<CompiledAiRequest>;
313
378
  /** Relists servers that implement `listTools`. Other servers stay as registered. */
314
379
  refreshMcp(): Promise<void>;
315
380
  readonly provider: AiProviderId;
@@ -334,4 +399,4 @@ declare function stripReasoningHistoryFields<T>(message: T, paths: readonly stri
334
399
 
335
400
  declare function resolveProvider(requestProvider: AiProviderId | undefined, defaultProvider: AiProviderId): ImplementedAiProvider;
336
401
 
337
- export { type AiDispatcher, AiDispatcherError, type AiDispatcherOptions, type AiDispatcherRequest, type AiDispatcherResponse, type AiDispatcherUsage, type AiProviderAdapter, type AiProviderId, type CacheMode, type CacheOutcome, type CachePolicy, type CacheResolution, type CacheTtl, type CloudflareBackoff, type CloudflareCallContext, type CloudflareEndpoint, type CloudflareEndpointChoice, type CloudflareGatewayControls, type CloudflareRequestOptions, type CloudflareRunOptions, type CloudflareRuntimeOptions, type CloudflareWebhookFormat, type CompiledAiRequest, type CompiledCloudflareRequest, type CompiledOpenAiRequest, DEFAULT_METADATA_PRIORITY, type DispatcherMcpOptions, type DispatcherMcpServer, type DispatcherMcpTool, IMPLEMENTED_AI_PROVIDERS, type ImplementedAiProvider, type OpenAiRuntimeOptions, type ReasoningResolution, type RoleStamp, createAiDispatcher, isImplementedAiProvider, providerNotImplemented, resolveProvider, stripReasoningHistoryFields };
402
+ export { type AiDispatcher, AiDispatcherError, type AiDispatcherOptions, type AiDispatcherRequest, type AiDispatcherResponse, type AiDispatcherUsage, type AiInputCodec, type AiInputCodecChoice, type AiInputFraming, type AiInputMode, type AiInputReadableFormat, type AiInputSettings, type AiInputSharing, type AiInputTokenizer, type AiProviderAdapter, type AiProviderId, type CacheMode, type CacheOutcome, type CachePolicy, type CacheResolution, type CacheTtl, type CloudflareBackoff, type CloudflareCallContext, type CloudflareEndpoint, type CloudflareEndpointChoice, type CloudflareGatewayControls, type CloudflareRequestOptions, type CloudflareRunOptions, type CloudflareRuntimeOptions, type CloudflareWebhookFormat, type CompiledAiRequest, type CompiledCloudflareRequest, type CompiledOpenAiRequest, DEFAULT_METADATA_PRIORITY, type DispatcherMcpOptions, type DispatcherMcpServer, type DispatcherMcpTool, IMPLEMENTED_AI_PROVIDERS, type ImplementedAiProvider, type InputResolution, type OpenAiRuntimeOptions, type ReasoningResolution, type RoleStamp, createAiDispatcher, isImplementedAiProvider, providerNotImplemented, resolveProvider, stripReasoningHistoryFields };
package/dist/index.d.ts CHANGED
@@ -3,6 +3,8 @@ export { ReasoningEffort, ReasoningOutcome, registerHostIntents } from '@x12i/ai
3
3
  import * as _x12i_openrouter_runtime from '@x12i/openrouter-runtime';
4
4
  import { RuntimeToolExecutor, RuntimeLogger, RuntimeRequest, RuntimeResponse, RuntimeUsage, RuntimeStreamEvent, CompiledOpenRouterRequest, OpenRouterRuntimeOptions } from '@x12i/openrouter-runtime';
5
5
  export { CompiledOpenRouterRequest, METADATA_NORMALIZATION_MAP, NormalizedMetadataKey, OpenRouterRuntimeOptions, RuntimeDefaults, RuntimeLogger, RuntimeMessage, RuntimeRequest, RuntimeResponse, RuntimeServerToolsPolicy, RuntimeStreamEvent, canonicalMetadataKey, decodeProviderMetadata, normalizeMetadata } from '@x12i/openrouter-runtime';
6
+ import { CapabilityApproval } from '@x12i/ai-input/core';
7
+ export { CapabilityApproval } from '@x12i/ai-input/core';
6
8
  import { CompiledBedrockRequest, BedrockRuntimeOptions } from '@x12i/bedrock-runtime';
7
9
  export { BedrockClientLike, BedrockCredentials, BedrockRuntimeOptions, CompiledBedrockRequest } from '@x12i/bedrock-runtime';
8
10
 
@@ -93,6 +95,52 @@ interface OpenAiRuntimeOptions {
93
95
  logger?: RuntimeLogger;
94
96
  }
95
97
 
98
+ /** Compact and readable write outline. Raw is `JSON.stringify` or the original string. */
99
+ type AiInputMode = "compact" | "readable" | "raw";
100
+ /** Wire codec chosen for one prepared value. Compact and readable default to `outline`. */
101
+ type AiInputCodec = "json" | "toon" | "text" | "outline";
102
+ /** `auto` stays on outline, JSON, or text until a matching approval and a tokenizer allow an alternate. */
103
+ type AiInputCodecChoice = "auto" | AiInputCodec;
104
+ type AiInputReadableFormat = "auto" | "json" | "toon" | "outline";
105
+ type AiInputSharing = "auto" | "off";
106
+ /** `raw` is the model body. `self-describing` adds the `@ai-input/1` header. */
107
+ type AiInputFraming = "self-describing" | "raw";
108
+ /** Optional `gpt-tokenizer` encodings. The package is not installed by the dispatcher. */
109
+ type AiInputTokenizer = "none" | "gpt:o200k_base" | "gpt:cl100k_base" | "gpt:p50k_base" | "gpt:p50k_edit" | "gpt:r50k_base";
110
+ /**
111
+ * How one dispatcher prepares model-visible input.
112
+ * Omitted fields use compact mode, `codec: "auto"`, `sharing: "auto"`, raw framing, and no tokenizer.
113
+ * Compact writes outline for structured values. `codec: "json"` keeps compact JSON. `mode: "raw"` keeps `JSON.stringify`.
114
+ */
115
+ interface AiInputSettings {
116
+ mode?: AiInputMode;
117
+ codec?: AiInputCodecChoice;
118
+ readableFormat?: AiInputReadableFormat;
119
+ sharing?: AiInputSharing;
120
+ framing?: AiInputFraming;
121
+ /**
122
+ * Approval lookup id. Defaults to the effective model for the call.
123
+ * Does not change the model sent to the provider.
124
+ */
125
+ model?: string;
126
+ tokenizer?: AiInputTokenizer;
127
+ /** Caller approvals. The dispatcher ships none. */
128
+ approvals?: readonly CapabilityApproval[];
129
+ }
130
+ /**
131
+ * What preparation did for one call.
132
+ * Omitted when preparation stayed on the unchanged JSON or text baseline.
133
+ */
134
+ interface InputResolution {
135
+ enabled: boolean;
136
+ /** Approval lookup id. Omitted when preparation is off or the call has no model id. */
137
+ model?: string;
138
+ mode?: AiInputMode;
139
+ codec?: AiInputCodec;
140
+ representation?: "value" | "shared-v1";
141
+ approvalSource?: "none" | "registry" | "explicit-caller" | "baseline";
142
+ changed: boolean;
143
+ }
96
144
  /** Caller role stamp. Omitted or blank fields are not stored. */
97
145
  interface RoleStamp {
98
146
  role?: string;
@@ -194,6 +242,13 @@ interface AiDispatcherRequest extends RuntimeRequest {
194
242
  * `endpoint` wins over `apiMode`. Stripped before the provider request is compiled.
195
243
  */
196
244
  cloudflare?: CloudflareRequestOptions;
245
+ /**
246
+ * Input preparation for this call.
247
+ * Omit it to use the dispatcher default. `false` skips preparation.
248
+ * A settings object overrides the dispatcher default for this call, including turning it back on.
249
+ * Stripped before the provider payload is built. This is not the Responses `input` field.
250
+ */
251
+ aiInput?: false | AiInputSettings;
197
252
  }
198
253
  interface DispatcherMcpTool {
199
254
  name: string;
@@ -237,6 +292,11 @@ interface AiDispatcherOptions {
237
292
  */
238
293
  metadataPriority?: readonly string[];
239
294
  logger?: RuntimeLogger;
295
+ /**
296
+ * Default input preparation. Omit it and every call uses compact `@x12i/ai-input`.
297
+ * `false` skips preparation unless a call passes settings.
298
+ */
299
+ aiInput?: false | AiInputSettings;
240
300
  }
241
301
  interface CompiledOpenAiRequest {
242
302
  provider: "openai";
@@ -248,6 +308,7 @@ interface CompiledOpenAiRequest {
248
308
  effectiveModel: string;
249
309
  reasoningResolution?: ReasoningResolution;
250
310
  cacheResolution?: CacheResolution;
311
+ inputResolution?: InputResolution;
251
312
  }
252
313
  interface CompiledCloudflareRequest {
253
314
  provider: "cloudflare";
@@ -261,6 +322,7 @@ interface CompiledCloudflareRequest {
261
322
  effectiveModel: string;
262
323
  reasoningResolution?: ReasoningResolution;
263
324
  cacheResolution?: CacheResolution;
325
+ inputResolution?: InputResolution;
264
326
  }
265
327
  type CompiledAiRequest = (CompiledOpenRouterRequest & {
266
328
  provider: "openrouter";
@@ -268,12 +330,14 @@ type CompiledAiRequest = (CompiledOpenRouterRequest & {
268
330
  effectiveModel: string;
269
331
  reasoningResolution?: ReasoningResolution;
270
332
  cacheResolution?: CacheResolution;
333
+ inputResolution?: InputResolution;
271
334
  }) | (CompiledBedrockRequest & {
272
335
  provider: "bedrock";
273
336
  requestedModel: string;
274
337
  effectiveModel: string;
275
338
  reasoningResolution?: ReasoningResolution;
276
339
  cacheResolution?: CacheResolution;
340
+ inputResolution?: InputResolution;
277
341
  }) | CompiledOpenAiRequest | CompiledCloudflareRequest;
278
342
  interface AiDispatcherUsage extends RuntimeUsage {
279
343
  /** Tokens read from a prompt cache. Omitted when the provider did not report any. */
@@ -286,6 +350,7 @@ interface AiDispatcherResponse extends RuntimeResponse {
286
350
  reasoningText?: string;
287
351
  reasoningResolution?: ReasoningResolution;
288
352
  cacheResolution?: CacheResolution;
353
+ inputResolution?: InputResolution;
289
354
  usage?: AiDispatcherUsage;
290
355
  }
291
356
  interface ProviderCallOptions {
@@ -309,7 +374,7 @@ interface CompiledOpenAiWireShape {
309
374
  interface AiDispatcher {
310
375
  run(request: AiDispatcherRequest): Promise<AiDispatcherResponse>;
311
376
  executeStreamingChat(request: AiDispatcherRequest): AsyncIterable<RuntimeStreamEvent>;
312
- compile(request: AiDispatcherRequest): CompiledAiRequest;
377
+ compile(request: AiDispatcherRequest): Promise<CompiledAiRequest>;
313
378
  /** Relists servers that implement `listTools`. Other servers stay as registered. */
314
379
  refreshMcp(): Promise<void>;
315
380
  readonly provider: AiProviderId;
@@ -334,4 +399,4 @@ declare function stripReasoningHistoryFields<T>(message: T, paths: readonly stri
334
399
 
335
400
  declare function resolveProvider(requestProvider: AiProviderId | undefined, defaultProvider: AiProviderId): ImplementedAiProvider;
336
401
 
337
- export { type AiDispatcher, AiDispatcherError, type AiDispatcherOptions, type AiDispatcherRequest, type AiDispatcherResponse, type AiDispatcherUsage, type AiProviderAdapter, type AiProviderId, type CacheMode, type CacheOutcome, type CachePolicy, type CacheResolution, type CacheTtl, type CloudflareBackoff, type CloudflareCallContext, type CloudflareEndpoint, type CloudflareEndpointChoice, type CloudflareGatewayControls, type CloudflareRequestOptions, type CloudflareRunOptions, type CloudflareRuntimeOptions, type CloudflareWebhookFormat, type CompiledAiRequest, type CompiledCloudflareRequest, type CompiledOpenAiRequest, DEFAULT_METADATA_PRIORITY, type DispatcherMcpOptions, type DispatcherMcpServer, type DispatcherMcpTool, IMPLEMENTED_AI_PROVIDERS, type ImplementedAiProvider, type OpenAiRuntimeOptions, type ReasoningResolution, type RoleStamp, createAiDispatcher, isImplementedAiProvider, providerNotImplemented, resolveProvider, stripReasoningHistoryFields };
402
+ export { type AiDispatcher, AiDispatcherError, type AiDispatcherOptions, type AiDispatcherRequest, type AiDispatcherResponse, type AiDispatcherUsage, type AiInputCodec, type AiInputCodecChoice, type AiInputFraming, type AiInputMode, type AiInputReadableFormat, type AiInputSettings, type AiInputSharing, type AiInputTokenizer, type AiProviderAdapter, type AiProviderId, type CacheMode, type CacheOutcome, type CachePolicy, type CacheResolution, type CacheTtl, type CloudflareBackoff, type CloudflareCallContext, type CloudflareEndpoint, type CloudflareEndpointChoice, type CloudflareGatewayControls, type CloudflareRequestOptions, type CloudflareRunOptions, type CloudflareRuntimeOptions, type CloudflareWebhookFormat, type CompiledAiRequest, type CompiledCloudflareRequest, type CompiledOpenAiRequest, DEFAULT_METADATA_PRIORITY, type DispatcherMcpOptions, type DispatcherMcpServer, type DispatcherMcpTool, IMPLEMENTED_AI_PROVIDERS, type ImplementedAiProvider, type InputResolution, type OpenAiRuntimeOptions, type ReasoningResolution, type RoleStamp, createAiDispatcher, isImplementedAiProvider, providerNotImplemented, resolveProvider, stripReasoningHistoryFields };