@x12i/ai-dispatcher 2.1.0 → 2.3.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/README.md +12 -10
- package/dist/index.cjs +39 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -6
- package/dist/index.d.ts +20 -6
- package/dist/index.js +41 -2
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { ReasoningEffort, ReasoningOutcome } from '@x12i/ai-profiles';
|
|
2
|
+
export { ReasoningEffort, ReasoningOutcome, registerHostIntents } from '@x12i/ai-profiles';
|
|
1
3
|
import * as _x12i_openrouter_runtime from '@x12i/openrouter-runtime';
|
|
2
4
|
import { RuntimeToolExecutor, RuntimeLogger, RuntimeRequest, RuntimeResponse, RuntimeUsage, RuntimeStreamEvent, CompiledOpenRouterRequest, OpenRouterRuntimeOptions } from '@x12i/openrouter-runtime';
|
|
3
|
-
export { CompiledOpenRouterRequest, OpenRouterRuntimeOptions, RuntimeDefaults, RuntimeLogger, RuntimeMessage, RuntimeRequest, RuntimeResponse, RuntimeServerToolsPolicy, RuntimeStreamEvent, decodeProviderMetadata } from '@x12i/openrouter-runtime';
|
|
4
|
-
import { ReasoningEffort, ReasoningOutcome } from '@x12i/ai-profiles';
|
|
5
|
-
export { ReasoningEffort, ReasoningOutcome } from '@x12i/ai-profiles';
|
|
5
|
+
export { CompiledOpenRouterRequest, METADATA_NORMALIZATION_MAP, NormalizedMetadataKey, OpenRouterRuntimeOptions, RuntimeDefaults, RuntimeLogger, RuntimeMessage, RuntimeRequest, RuntimeResponse, RuntimeServerToolsPolicy, RuntimeStreamEvent, canonicalMetadataKey, decodeProviderMetadata, normalizeMetadata } from '@x12i/openrouter-runtime';
|
|
6
6
|
import { CompiledBedrockRequest, BedrockRuntimeOptions } from '@x12i/bedrock-runtime';
|
|
7
7
|
export { BedrockClientLike, BedrockCredentials, BedrockRuntimeOptions, CompiledBedrockRequest } from '@x12i/bedrock-runtime';
|
|
8
8
|
|
|
@@ -93,6 +93,13 @@ interface OpenAiRuntimeOptions {
|
|
|
93
93
|
logger?: RuntimeLogger;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
/** Caller role stamp. Omitted or blank fields are not stored. */
|
|
97
|
+
interface RoleStamp {
|
|
98
|
+
role?: string;
|
|
99
|
+
roleLayer?: string;
|
|
100
|
+
roleDigest?: string;
|
|
101
|
+
profileChoice?: string;
|
|
102
|
+
}
|
|
96
103
|
/**
|
|
97
104
|
* Catalog resolution for one call.
|
|
98
105
|
* `outcome` is present only when the catalog resolver ran.
|
|
@@ -152,6 +159,12 @@ interface AiDispatcherRequest extends RuntimeRequest {
|
|
|
152
159
|
* Caller skill id. Stored in the one provider metadata record as `skillId`.
|
|
153
160
|
*/
|
|
154
161
|
skillId?: string;
|
|
162
|
+
/**
|
|
163
|
+
* Role resolution stamp. Expanded into the metadata record as `role`, `roleLayer`,
|
|
164
|
+
* `roleDigest`, and `profileChoice`. A set field wins over the same key in `metadata`.
|
|
165
|
+
* Stripped before the provider payload is built.
|
|
166
|
+
*/
|
|
167
|
+
role?: RoleStamp;
|
|
155
168
|
/**
|
|
156
169
|
* Provider-neutral reasoning intent. The bundled catalog chooses the wire action.
|
|
157
170
|
* An explicit provider control on the same request wins and the catalog is not called.
|
|
@@ -219,7 +232,8 @@ interface AiDispatcherOptions {
|
|
|
219
232
|
* Highest priority first for the one metadata record.
|
|
220
233
|
* Listed keys are kept ahead of keys that are not in the list.
|
|
221
234
|
* The dispatcher trims on every call and adds a `METADATA_RECORD_TRIMMED` warning when it drops keys.
|
|
222
|
-
* The default keeps `agentId`, `orgId`, `stepId`, `skillId`, `
|
|
235
|
+
* The default keeps `agentId`, `orgId`, `stepId`, `skillId`, `role`, `roleLayer`,
|
|
236
|
+
* `roleDigest`, `profileChoice`, `recordId`, and `objectType`.
|
|
223
237
|
*/
|
|
224
238
|
metadataPriority?: readonly string[];
|
|
225
239
|
logger?: RuntimeLogger;
|
|
@@ -302,7 +316,7 @@ interface AiDispatcher {
|
|
|
302
316
|
}
|
|
303
317
|
|
|
304
318
|
/** Identity keys stay when a record has to be trimmed. Earlier entries are kept ahead of later ones. */
|
|
305
|
-
declare const DEFAULT_METADATA_PRIORITY: readonly ["agentId", "orgId", "stepId", "skillId", "recordId", "objectType"];
|
|
319
|
+
declare const DEFAULT_METADATA_PRIORITY: readonly ["agentId", "orgId", "stepId", "skillId", "role", "roleLayer", "roleDigest", "profileChoice", "recordId", "objectType"];
|
|
306
320
|
declare function createAiDispatcher(options?: AiDispatcherOptions): AiDispatcher;
|
|
307
321
|
|
|
308
322
|
declare class AiDispatcherError extends Error {
|
|
@@ -320,4 +334,4 @@ declare function stripReasoningHistoryFields<T>(message: T, paths: readonly stri
|
|
|
320
334
|
|
|
321
335
|
declare function resolveProvider(requestProvider: AiProviderId | undefined, defaultProvider: AiProviderId): ImplementedAiProvider;
|
|
322
336
|
|
|
323
|
-
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, createAiDispatcher, isImplementedAiProvider, providerNotImplemented, resolveProvider, stripReasoningHistoryFields };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { ReasoningEffort, ReasoningOutcome } from '@x12i/ai-profiles';
|
|
2
|
+
export { ReasoningEffort, ReasoningOutcome, registerHostIntents } from '@x12i/ai-profiles';
|
|
1
3
|
import * as _x12i_openrouter_runtime from '@x12i/openrouter-runtime';
|
|
2
4
|
import { RuntimeToolExecutor, RuntimeLogger, RuntimeRequest, RuntimeResponse, RuntimeUsage, RuntimeStreamEvent, CompiledOpenRouterRequest, OpenRouterRuntimeOptions } from '@x12i/openrouter-runtime';
|
|
3
|
-
export { CompiledOpenRouterRequest, OpenRouterRuntimeOptions, RuntimeDefaults, RuntimeLogger, RuntimeMessage, RuntimeRequest, RuntimeResponse, RuntimeServerToolsPolicy, RuntimeStreamEvent, decodeProviderMetadata } from '@x12i/openrouter-runtime';
|
|
4
|
-
import { ReasoningEffort, ReasoningOutcome } from '@x12i/ai-profiles';
|
|
5
|
-
export { ReasoningEffort, ReasoningOutcome } from '@x12i/ai-profiles';
|
|
5
|
+
export { CompiledOpenRouterRequest, METADATA_NORMALIZATION_MAP, NormalizedMetadataKey, OpenRouterRuntimeOptions, RuntimeDefaults, RuntimeLogger, RuntimeMessage, RuntimeRequest, RuntimeResponse, RuntimeServerToolsPolicy, RuntimeStreamEvent, canonicalMetadataKey, decodeProviderMetadata, normalizeMetadata } from '@x12i/openrouter-runtime';
|
|
6
6
|
import { CompiledBedrockRequest, BedrockRuntimeOptions } from '@x12i/bedrock-runtime';
|
|
7
7
|
export { BedrockClientLike, BedrockCredentials, BedrockRuntimeOptions, CompiledBedrockRequest } from '@x12i/bedrock-runtime';
|
|
8
8
|
|
|
@@ -93,6 +93,13 @@ interface OpenAiRuntimeOptions {
|
|
|
93
93
|
logger?: RuntimeLogger;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
/** Caller role stamp. Omitted or blank fields are not stored. */
|
|
97
|
+
interface RoleStamp {
|
|
98
|
+
role?: string;
|
|
99
|
+
roleLayer?: string;
|
|
100
|
+
roleDigest?: string;
|
|
101
|
+
profileChoice?: string;
|
|
102
|
+
}
|
|
96
103
|
/**
|
|
97
104
|
* Catalog resolution for one call.
|
|
98
105
|
* `outcome` is present only when the catalog resolver ran.
|
|
@@ -152,6 +159,12 @@ interface AiDispatcherRequest extends RuntimeRequest {
|
|
|
152
159
|
* Caller skill id. Stored in the one provider metadata record as `skillId`.
|
|
153
160
|
*/
|
|
154
161
|
skillId?: string;
|
|
162
|
+
/**
|
|
163
|
+
* Role resolution stamp. Expanded into the metadata record as `role`, `roleLayer`,
|
|
164
|
+
* `roleDigest`, and `profileChoice`. A set field wins over the same key in `metadata`.
|
|
165
|
+
* Stripped before the provider payload is built.
|
|
166
|
+
*/
|
|
167
|
+
role?: RoleStamp;
|
|
155
168
|
/**
|
|
156
169
|
* Provider-neutral reasoning intent. The bundled catalog chooses the wire action.
|
|
157
170
|
* An explicit provider control on the same request wins and the catalog is not called.
|
|
@@ -219,7 +232,8 @@ interface AiDispatcherOptions {
|
|
|
219
232
|
* Highest priority first for the one metadata record.
|
|
220
233
|
* Listed keys are kept ahead of keys that are not in the list.
|
|
221
234
|
* The dispatcher trims on every call and adds a `METADATA_RECORD_TRIMMED` warning when it drops keys.
|
|
222
|
-
* The default keeps `agentId`, `orgId`, `stepId`, `skillId`, `
|
|
235
|
+
* The default keeps `agentId`, `orgId`, `stepId`, `skillId`, `role`, `roleLayer`,
|
|
236
|
+
* `roleDigest`, `profileChoice`, `recordId`, and `objectType`.
|
|
223
237
|
*/
|
|
224
238
|
metadataPriority?: readonly string[];
|
|
225
239
|
logger?: RuntimeLogger;
|
|
@@ -302,7 +316,7 @@ interface AiDispatcher {
|
|
|
302
316
|
}
|
|
303
317
|
|
|
304
318
|
/** Identity keys stay when a record has to be trimmed. Earlier entries are kept ahead of later ones. */
|
|
305
|
-
declare const DEFAULT_METADATA_PRIORITY: readonly ["agentId", "orgId", "stepId", "skillId", "recordId", "objectType"];
|
|
319
|
+
declare const DEFAULT_METADATA_PRIORITY: readonly ["agentId", "orgId", "stepId", "skillId", "role", "roleLayer", "roleDigest", "profileChoice", "recordId", "objectType"];
|
|
306
320
|
declare function createAiDispatcher(options?: AiDispatcherOptions): AiDispatcher;
|
|
307
321
|
|
|
308
322
|
declare class AiDispatcherError extends Error {
|
|
@@ -320,4 +334,4 @@ declare function stripReasoningHistoryFields<T>(message: T, paths: readonly stri
|
|
|
320
334
|
|
|
321
335
|
declare function resolveProvider(requestProvider: AiProviderId | undefined, defaultProvider: AiProviderId): ImplementedAiProvider;
|
|
322
336
|
|
|
323
|
-
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, createAiDispatcher, isImplementedAiProvider, providerNotImplemented, resolveProvider, stripReasoningHistoryFields };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import {
|
|
2
|
+
import { registerHostIntents } from "@x12i/ai-profiles";
|
|
3
|
+
import {
|
|
4
|
+
decodeProviderMetadata,
|
|
5
|
+
METADATA_NORMALIZATION_MAP,
|
|
6
|
+
canonicalMetadataKey,
|
|
7
|
+
normalizeMetadata
|
|
8
|
+
} from "@x12i/openrouter-runtime";
|
|
3
9
|
|
|
4
10
|
// src/create-dispatcher.ts
|
|
5
11
|
import { createMetadataPacker } from "@x12i/provider-metadata";
|
|
@@ -2323,6 +2329,7 @@ function isRecord5(value) {
|
|
|
2323
2329
|
// src/prepare-request.ts
|
|
2324
2330
|
function prepareDispatchRequest(params) {
|
|
2325
2331
|
const cloned = cloneRequest(params.request);
|
|
2332
|
+
applyRoleStamp(cloned);
|
|
2326
2333
|
applyDispatchIdentity(cloned);
|
|
2327
2334
|
absorbOverrideMetadata(cloned);
|
|
2328
2335
|
const provider = params.provider;
|
|
@@ -2630,6 +2637,23 @@ function defaultModelFor(provider, options) {
|
|
|
2630
2637
|
return options.openai?.defaultModel;
|
|
2631
2638
|
}
|
|
2632
2639
|
var DISPATCH_IDENTITY_FIELDS = ["orgId", "stepId", "skillId"];
|
|
2640
|
+
var ROLE_STAMP_FIELDS = ["role", "roleLayer", "roleDigest", "profileChoice"];
|
|
2641
|
+
function applyRoleStamp(request) {
|
|
2642
|
+
const stamp = request.role;
|
|
2643
|
+
delete request.role;
|
|
2644
|
+
if (!isRecord6(stamp)) return;
|
|
2645
|
+
const identity = {};
|
|
2646
|
+
for (const field of ROLE_STAMP_FIELDS) {
|
|
2647
|
+
const value = stamp[field];
|
|
2648
|
+
if (typeof value !== "string") continue;
|
|
2649
|
+
const trimmed = value.trim();
|
|
2650
|
+
if (trimmed) identity[field] = trimmed;
|
|
2651
|
+
}
|
|
2652
|
+
if (!Object.keys(identity).length) return;
|
|
2653
|
+
const rest = { ...request.metadata ?? {} };
|
|
2654
|
+
for (const key of Object.keys(identity)) delete rest[key];
|
|
2655
|
+
request.metadata = { ...identity, ...rest };
|
|
2656
|
+
}
|
|
2633
2657
|
function absorbOverrideMetadata(request) {
|
|
2634
2658
|
const overrides = request.rawOpenRouterOverrides;
|
|
2635
2659
|
if (!isRecord6(overrides) || !Object.prototype.hasOwnProperty.call(overrides, "metadata")) return;
|
|
@@ -3505,7 +3529,18 @@ function resolveProvider(requestProvider, defaultProvider) {
|
|
|
3505
3529
|
|
|
3506
3530
|
// src/create-dispatcher.ts
|
|
3507
3531
|
var SECRET_HEADERS = /* @__PURE__ */ new Set(["authorization", "x-api-key", "api-key"]);
|
|
3508
|
-
var DEFAULT_METADATA_PRIORITY = [
|
|
3532
|
+
var DEFAULT_METADATA_PRIORITY = [
|
|
3533
|
+
"agentId",
|
|
3534
|
+
"orgId",
|
|
3535
|
+
"stepId",
|
|
3536
|
+
"skillId",
|
|
3537
|
+
"role",
|
|
3538
|
+
"roleLayer",
|
|
3539
|
+
"roleDigest",
|
|
3540
|
+
"profileChoice",
|
|
3541
|
+
"recordId",
|
|
3542
|
+
"objectType"
|
|
3543
|
+
];
|
|
3509
3544
|
function createAiDispatcher(options = {}) {
|
|
3510
3545
|
const packer = createMetadataPacker({ priority: options.metadataPriority ?? DEFAULT_METADATA_PRIORITY });
|
|
3511
3546
|
const defaultProvider = resolveProvider(options.provider, "openrouter");
|
|
@@ -3663,10 +3698,14 @@ export {
|
|
|
3663
3698
|
AiDispatcherError,
|
|
3664
3699
|
DEFAULT_METADATA_PRIORITY,
|
|
3665
3700
|
IMPLEMENTED_AI_PROVIDERS,
|
|
3701
|
+
METADATA_NORMALIZATION_MAP,
|
|
3702
|
+
canonicalMetadataKey,
|
|
3666
3703
|
createAiDispatcher,
|
|
3667
3704
|
decodeProviderMetadata,
|
|
3668
3705
|
isImplementedAiProvider,
|
|
3706
|
+
normalizeMetadata,
|
|
3669
3707
|
providerNotImplemented,
|
|
3708
|
+
registerHostIntents,
|
|
3670
3709
|
resolveProvider,
|
|
3671
3710
|
stripReasoningHistoryFields
|
|
3672
3711
|
};
|