@dcdr/contracts 1.9.6
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/LICENSE +176 -0
- package/README.md +411 -0
- package/dist/capabilities.contract.d.ts +69 -0
- package/dist/capabilities.contract.d.ts.map +1 -0
- package/dist/capabilities.contract.js +126 -0
- package/dist/control.contract.d.ts +39 -0
- package/dist/control.contract.d.ts.map +1 -0
- package/dist/control.contract.js +2 -0
- package/dist/credentials.contract.d.ts +37 -0
- package/dist/credentials.contract.d.ts.map +1 -0
- package/dist/credentials.contract.js +15 -0
- package/dist/entitlements.contract.d.ts +107 -0
- package/dist/entitlements.contract.d.ts.map +1 -0
- package/dist/entitlements.contract.js +11 -0
- package/dist/errors.contract.d.ts +47 -0
- package/dist/errors.contract.d.ts.map +1 -0
- package/dist/errors.contract.js +48 -0
- package/dist/execution.contract.d.ts +240 -0
- package/dist/execution.contract.d.ts.map +1 -0
- package/dist/execution.contract.js +22 -0
- package/dist/http.contract.d.ts +20 -0
- package/dist/http.contract.d.ts.map +1 -0
- package/dist/http.contract.js +8 -0
- package/dist/implementations.contract.d.ts +120 -0
- package/dist/implementations.contract.d.ts.map +1 -0
- package/dist/implementations.contract.js +2 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/intent.contract.d.ts +137 -0
- package/dist/intent.contract.d.ts.map +1 -0
- package/dist/intent.contract.js +76 -0
- package/dist/logs.contract.d.ts +10 -0
- package/dist/logs.contract.d.ts.map +1 -0
- package/dist/logs.contract.js +2 -0
- package/dist/messages.contract.d.ts +16 -0
- package/dist/messages.contract.d.ts.map +1 -0
- package/dist/messages.contract.js +2 -0
- package/dist/policies.contract.d.ts +253 -0
- package/dist/policies.contract.d.ts.map +1 -0
- package/dist/policies.contract.js +283 -0
- package/dist/prompt-variable-schema.contract.d.ts +75 -0
- package/dist/prompt-variable-schema.contract.d.ts.map +1 -0
- package/dist/prompt-variable-schema.contract.js +572 -0
- package/dist/prompts.contract.d.ts +97 -0
- package/dist/prompts.contract.d.ts.map +1 -0
- package/dist/prompts.contract.js +87 -0
- package/dist/provider.contract.d.ts +477 -0
- package/dist/provider.contract.d.ts.map +1 -0
- package/dist/provider.contract.js +3310 -0
- package/dist/registry.stats.contract.d.ts +39 -0
- package/dist/registry.stats.contract.d.ts.map +1 -0
- package/dist/registry.stats.contract.js +9 -0
- package/dist/runtime.client.d.ts +362 -0
- package/dist/runtime.client.d.ts.map +1 -0
- package/dist/runtime.client.js +545 -0
- package/dist/service-tokens.contract.d.ts +29 -0
- package/dist/service-tokens.contract.d.ts.map +1 -0
- package/dist/service-tokens.contract.js +10 -0
- package/dist/session.contract.d.ts +51 -0
- package/dist/session.contract.d.ts.map +1 -0
- package/dist/session.contract.js +187 -0
- package/dist/subscription.contract.d.ts +37 -0
- package/dist/subscription.contract.d.ts.map +1 -0
- package/dist/subscription.contract.js +45 -0
- package/dist/utils.contract.d.ts +21 -0
- package/dist/utils.contract.d.ts.map +1 -0
- package/dist/utils.contract.js +79 -0
- package/package.json +57 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IntentType = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Supported intent execution types.
|
|
6
|
+
*
|
|
7
|
+
* This defines the type of task the intent performs and which
|
|
8
|
+
* provider capabilities are required.
|
|
9
|
+
*/
|
|
10
|
+
var IntentType;
|
|
11
|
+
(function (IntentType) {
|
|
12
|
+
/**
|
|
13
|
+
* Standard conversational or prompt-response interaction.
|
|
14
|
+
*
|
|
15
|
+
* Examples:
|
|
16
|
+
* - Q&A
|
|
17
|
+
* - summarization
|
|
18
|
+
* - reasoning
|
|
19
|
+
* - structured output generation
|
|
20
|
+
*/
|
|
21
|
+
IntentType["CHAT"] = "CHAT";
|
|
22
|
+
/**
|
|
23
|
+
* Text embedding generation.
|
|
24
|
+
*
|
|
25
|
+
* Examples:
|
|
26
|
+
* - semantic search
|
|
27
|
+
* - vector indexing
|
|
28
|
+
* - similarity comparison
|
|
29
|
+
*/
|
|
30
|
+
IntentType["EMBEDDING"] = "EMBEDDING";
|
|
31
|
+
/**
|
|
32
|
+
* Image generation.
|
|
33
|
+
*
|
|
34
|
+
* Examples:
|
|
35
|
+
* - DALL·E
|
|
36
|
+
* - diffusion models
|
|
37
|
+
*/
|
|
38
|
+
IntentType["IMAGE_GENERATION"] = "IMAGE_GENERATION";
|
|
39
|
+
/**
|
|
40
|
+
* Image understanding / multimodal analysis.
|
|
41
|
+
*
|
|
42
|
+
* Examples:
|
|
43
|
+
* - vision LLMs
|
|
44
|
+
* - OCR-assisted models
|
|
45
|
+
*/
|
|
46
|
+
IntentType["IMAGE_ANALYSIS"] = "IMAGE_ANALYSIS";
|
|
47
|
+
/**
|
|
48
|
+
* Audio transcription.
|
|
49
|
+
*
|
|
50
|
+
* Examples:
|
|
51
|
+
* - Whisper
|
|
52
|
+
* - speech-to-text models
|
|
53
|
+
*/
|
|
54
|
+
IntentType["SPEECH_TO_TEXT"] = "SPEECH_TO_TEXT";
|
|
55
|
+
/**
|
|
56
|
+
* Audio generation / text-to-speech.
|
|
57
|
+
*/
|
|
58
|
+
IntentType["TEXT_TO_SPEECH"] = "TEXT_TO_SPEECH";
|
|
59
|
+
/**
|
|
60
|
+
* Multimodal tasks combining text + images + audio.
|
|
61
|
+
*/
|
|
62
|
+
IntentType["MULTIMODAL"] = "MULTIMODAL";
|
|
63
|
+
/**
|
|
64
|
+
* Deterministic tool execution.
|
|
65
|
+
*
|
|
66
|
+
* Examples:
|
|
67
|
+
* - HTTP calls
|
|
68
|
+
* - scripts
|
|
69
|
+
* - external API connectors
|
|
70
|
+
*/
|
|
71
|
+
IntentType["TOOL"] = "TOOL";
|
|
72
|
+
/**
|
|
73
|
+
* Internal deterministic rule engine.
|
|
74
|
+
*/
|
|
75
|
+
IntentType["RULE_ENGINE"] = "RULE_ENGINE";
|
|
76
|
+
})(IntentType || (exports.IntentType = IntentType = {}));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ExecutionError } from "./errors.contract";
|
|
2
|
+
import { ExecutionReport, ExecutionStatus } from "./execution.contract";
|
|
3
|
+
import { Message } from "./messages.contract";
|
|
4
|
+
export type ExecutionLogEvent = ExecutionReport & {
|
|
5
|
+
status: ExecutionStatus;
|
|
6
|
+
input?: Message[];
|
|
7
|
+
output?: unknown;
|
|
8
|
+
error?: ExecutionError;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=logs.contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logs.contract.d.ts","sourceRoot":"","sources":["../src/logs.contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAoB,eAAe,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC1F,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAI9C,MAAM,MAAM,iBAAiB,GAAG,eAAe,GAAG;IAChD,MAAM,EAAE,eAAe,CAAC;IACxB,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC;IAClB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,cAAc,CAAC;CACxB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supported message roles for chat-style prompts.
|
|
3
|
+
* Keep this provider-agnostic; each provider adapter will map it as needed.
|
|
4
|
+
*/
|
|
5
|
+
export type MessageRole = "system" | "user";
|
|
6
|
+
/**
|
|
7
|
+
* A single prompt message in a provider-agnostic format.
|
|
8
|
+
* - `content` can include `${placeholders}` to be rendered by the gateway.
|
|
9
|
+
* - `name` is optional and mainly used for tool messages or multi-agent style.
|
|
10
|
+
*/
|
|
11
|
+
export interface Message {
|
|
12
|
+
role: MessageRole;
|
|
13
|
+
content: string;
|
|
14
|
+
name?: string;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=messages.contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.contract.d.ts","sourceRoot":"","sources":["../src/messages.contract.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,MAAM,CAAE;AAE7C;;;;GAIG;AACH,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf"}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { IntentProvider } from "./provider.contract";
|
|
2
|
+
/**
|
|
3
|
+
* Retry policy for an intent/model.
|
|
4
|
+
* Keep this stable; it's part of the behavior contract.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Retry policy for an intent/model.
|
|
8
|
+
* Keep this stable; it's part of the behavior contract.
|
|
9
|
+
*/
|
|
10
|
+
export declare class RetryPolicy {
|
|
11
|
+
/**
|
|
12
|
+
* Max total attempts across all candidates (including first try).
|
|
13
|
+
* Example: 3 => try primary + up to 2 more attempts.
|
|
14
|
+
*/
|
|
15
|
+
maxAttempts: number;
|
|
16
|
+
/**
|
|
17
|
+
* Max retries per single candidate before switching to next.
|
|
18
|
+
* Example: 1 => at most 1 attempt per candidate (no local retries).
|
|
19
|
+
* Example: 2 => 2 attempts on same candidate before fallback.
|
|
20
|
+
*/
|
|
21
|
+
maxPerCandidate?: number;
|
|
22
|
+
/**
|
|
23
|
+
* Timeout for a single provider attempt in milliseconds.
|
|
24
|
+
* If not provided, provider adapter default is used.
|
|
25
|
+
*/
|
|
26
|
+
attemptTimeoutMs?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Whether fallback to the next candidate is allowed.
|
|
29
|
+
* If false, fail after exhausting retries of the selected candidate(s).
|
|
30
|
+
*/
|
|
31
|
+
allowFallback: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Whether to do a "repair pass" when output fails JSON/schema validation.
|
|
34
|
+
* Useful for strict JSON intents (format parser, mappers).
|
|
35
|
+
*
|
|
36
|
+
* Repair pass semantics (runtime behavior)
|
|
37
|
+
* - Trigger condition: the previous attempt failed with `PARSE_FAIL` or `SCHEMA_FAIL`.
|
|
38
|
+
* - Structured-only: only applies when the intent is in structured mode (has `outputSchema` and/or
|
|
39
|
+
* `response_format` is `json_object`/`json_schema`).
|
|
40
|
+
* - Effect: the gateway appends one extra *system* instruction message to the existing rendered prompt
|
|
41
|
+
* (marker: `[DCDR_REPAIR_PASS]`) asking the model to re-emit ONLY valid JSON matching the expected schema.
|
|
42
|
+
* - Budgeting: consumes the normal retry budget (must still be within `maxPerCandidate` and `maxAttempts`).
|
|
43
|
+
* - Scope: at most one repair pass is attempted per candidate execution.
|
|
44
|
+
*
|
|
45
|
+
* Notes
|
|
46
|
+
* - This does not change the intent inputs; it only changes the instruction for the next attempt.
|
|
47
|
+
* - If you want repair behavior, you typically enable this AND include `PARSE_FAIL`/`SCHEMA_FAIL` in `retryOn`,
|
|
48
|
+
* but the repair pass itself is allowed even when `retryOn` is empty.
|
|
49
|
+
*/
|
|
50
|
+
repairOnParseFail?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Backoff strategy between attempts.
|
|
53
|
+
* - fixed: always wait retryBackoffMs
|
|
54
|
+
* - exponential: retryBackoffMs * 2^(n-1), capped by retryBackoffCapMs
|
|
55
|
+
*/
|
|
56
|
+
retryBackoffStrategy?: "fixed" | "exponential";
|
|
57
|
+
/**
|
|
58
|
+
* Base backoff delay in milliseconds between attempts (after the first).
|
|
59
|
+
* Defaults can be applied by the engine if undefined.
|
|
60
|
+
*/
|
|
61
|
+
retryBackoffMs?: number;
|
|
62
|
+
/**
|
|
63
|
+
* Maximum backoff delay in milliseconds when using exponential strategy.
|
|
64
|
+
*/
|
|
65
|
+
retryBackoffCapMs?: number;
|
|
66
|
+
/**
|
|
67
|
+
* Adds random jitter [0..retryJitterMs] to backoff to avoid synchronized retries.
|
|
68
|
+
*/
|
|
69
|
+
retryJitterMs?: number;
|
|
70
|
+
/**
|
|
71
|
+
* Error codes that are considered retryable/fallbackable.
|
|
72
|
+
* Keep values stable. Your engine should map real exceptions into these codes.
|
|
73
|
+
*/
|
|
74
|
+
retryOn?: Array<"TIMEOUT" | "RATE_LIMIT" | "UPSTREAM_5XX" | "NETWORK" | "PARSE_FAIL" | "SCHEMA_FAIL">;
|
|
75
|
+
}
|
|
76
|
+
export type ResponseFormat = "json_object" | "json_schema" | "text" | "markdown" | "html";
|
|
77
|
+
export declare class PromptParameters {
|
|
78
|
+
/**
|
|
79
|
+
* Typical range: 0.0–2.0 (default: 0.7)
|
|
80
|
+
*/
|
|
81
|
+
temperature?: number;
|
|
82
|
+
/**
|
|
83
|
+
* Typical range: 0.0–1.0 (default: 1)
|
|
84
|
+
*/
|
|
85
|
+
top_p?: number;
|
|
86
|
+
/**
|
|
87
|
+
* Typical range: 1–100 (default: 50)
|
|
88
|
+
*/
|
|
89
|
+
top_k?: number;
|
|
90
|
+
/**
|
|
91
|
+
* Typical range: 1–4096 (default: 2048)
|
|
92
|
+
*/
|
|
93
|
+
max_tokens?: number;
|
|
94
|
+
/**
|
|
95
|
+
* Any integer (optional, for reproducibility)
|
|
96
|
+
*/
|
|
97
|
+
seed?: number;
|
|
98
|
+
enable_thinking?: boolean;
|
|
99
|
+
response_format?: ResponseFormat;
|
|
100
|
+
/**
|
|
101
|
+
* Typical range: -2.0–2.0 (default: 0.0)
|
|
102
|
+
*/
|
|
103
|
+
presence_penalty?: number;
|
|
104
|
+
/**
|
|
105
|
+
* Typical range: -2.0–2.0 (default: 0.0)
|
|
106
|
+
*/
|
|
107
|
+
frequency_penalty?: number;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Supported execution policy types.
|
|
111
|
+
*
|
|
112
|
+
* These policies decide how the gateway chooses the initial implementation
|
|
113
|
+
* order before retries / fallback logic is applied.
|
|
114
|
+
*
|
|
115
|
+
* Notes:
|
|
116
|
+
* - RetryPolicy is still responsible for retry attempts and failure handling.
|
|
117
|
+
* - ExecutionPolicy is responsible for candidate planning and prioritization.
|
|
118
|
+
*/
|
|
119
|
+
export declare enum ExecutionPolicyType {
|
|
120
|
+
/**
|
|
121
|
+
* Use implementation weights as provided.
|
|
122
|
+
* This is the simplest and most backward-compatible mode.
|
|
123
|
+
*/
|
|
124
|
+
WEIGHTED = "WEIGHTED",
|
|
125
|
+
/**
|
|
126
|
+
* Use a fixed implementation order.
|
|
127
|
+
* The first active/healthy implementation is tried first, then the next one.
|
|
128
|
+
*/
|
|
129
|
+
FALLBACK_CHAIN = "FALLBACK_CHAIN",
|
|
130
|
+
/**
|
|
131
|
+
* Prefer local / office / on-prem implementations first.
|
|
132
|
+
* If none are available, use the remaining implementations.
|
|
133
|
+
*/
|
|
134
|
+
LOCAL_FIRST = "LOCAL_FIRST",
|
|
135
|
+
/**
|
|
136
|
+
* Prefer the cheapest implementations first.
|
|
137
|
+
* Requires each implementation to expose an estimated cost score.
|
|
138
|
+
*/
|
|
139
|
+
CHEAPEST_FIRST = "CHEAPEST_FIRST",
|
|
140
|
+
/**
|
|
141
|
+
* Prefer the fastest implementations first.
|
|
142
|
+
* Requires each implementation to expose an expected latency score.
|
|
143
|
+
*/
|
|
144
|
+
FASTEST_FIRST = "FASTEST_FIRST",
|
|
145
|
+
/**
|
|
146
|
+
* Prefer the highest-quality implementations first.
|
|
147
|
+
* Requires each implementation to expose a quality score.
|
|
148
|
+
*/
|
|
149
|
+
QUALITY_FIRST = "QUALITY_FIRST"
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Optional behavior when the selected policy cannot be fully evaluated.
|
|
153
|
+
*
|
|
154
|
+
* Example:
|
|
155
|
+
* - CHEAPEST_FIRST was requested, but implementations do not provide cost metadata.
|
|
156
|
+
*/
|
|
157
|
+
export declare enum ExecutionPolicyFallbackMode {
|
|
158
|
+
/**
|
|
159
|
+
* Fall back to simple weighted selection.
|
|
160
|
+
*/
|
|
161
|
+
WEIGHTED = "WEIGHTED",
|
|
162
|
+
/**
|
|
163
|
+
* Fall back to the declared implementation order.
|
|
164
|
+
*/
|
|
165
|
+
DECLARED_ORDER = "DECLARED_ORDER",
|
|
166
|
+
/**
|
|
167
|
+
* Fail fast if the policy cannot be evaluated correctly.
|
|
168
|
+
*/
|
|
169
|
+
ERROR = "ERROR"
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Exploration modes for candidate planning.
|
|
173
|
+
*
|
|
174
|
+
* Exploration is always explicit (opt-in) and is applied *after* deterministic ordering.
|
|
175
|
+
*
|
|
176
|
+
* V1 invariant
|
|
177
|
+
* - Do not combine weight-based selection with score-based ordering.
|
|
178
|
+
* - Exploration may reorder which candidate is tried first, but it must not change the underlying score ordering.
|
|
179
|
+
*/
|
|
180
|
+
export declare enum ExplorationMode {
|
|
181
|
+
/**
|
|
182
|
+
* Epsilon-greedy exploration over the top-K candidates.
|
|
183
|
+
*
|
|
184
|
+
* With probability `epsilon`, pick a random candidate in the top-K list.
|
|
185
|
+
* Otherwise, keep the deterministic best candidate.
|
|
186
|
+
*/
|
|
187
|
+
EPSILON_GREEDY_TOP_K = "EPSILON_GREEDY_TOP_K"
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Optional exploration configuration.
|
|
191
|
+
*
|
|
192
|
+
* Notes
|
|
193
|
+
* - This is intended for Cloud/Cloud Pro only; runtime (self-hosted) may reject registries that require it.
|
|
194
|
+
* - Parameters are validated at runtime.
|
|
195
|
+
*/
|
|
196
|
+
export interface ExplorationPolicy {
|
|
197
|
+
/** Exploration mode. */
|
|
198
|
+
mode: ExplorationMode;
|
|
199
|
+
/** Probability of exploring (0..1). */
|
|
200
|
+
epsilon: number;
|
|
201
|
+
/** Max number of top candidates to sample within (>= 1). */
|
|
202
|
+
topK: number;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* A simple execution policy contract for v1.
|
|
206
|
+
*
|
|
207
|
+
* This policy defines how the gateway should prioritize candidate
|
|
208
|
+
* implementations for an intent before executing retries/fallbacks.
|
|
209
|
+
*
|
|
210
|
+
* Design goals:
|
|
211
|
+
* - Simple
|
|
212
|
+
* - Backward-compatible
|
|
213
|
+
* - Easy to store in DB
|
|
214
|
+
* - Easy to render in UI
|
|
215
|
+
*/
|
|
216
|
+
export interface ExecutionPolicy {
|
|
217
|
+
/** Policy type. */
|
|
218
|
+
type: ExecutionPolicyType;
|
|
219
|
+
/**
|
|
220
|
+
* Optional fixed implementation order.
|
|
221
|
+
*
|
|
222
|
+
* Used mainly for:
|
|
223
|
+
* - FALLBACK_CHAIN
|
|
224
|
+
*
|
|
225
|
+
* Values should contain ImplementationContract IDs.
|
|
226
|
+
*/
|
|
227
|
+
implementationOrder?: string[];
|
|
228
|
+
/**
|
|
229
|
+
* Optional provider affinity ordering.
|
|
230
|
+
*
|
|
231
|
+
* Used mainly for:
|
|
232
|
+
* - LOCAL_FIRST
|
|
233
|
+
*
|
|
234
|
+
* Example:
|
|
235
|
+
* [OFFICE, OPEN_AI]
|
|
236
|
+
*/
|
|
237
|
+
preferredProviders?: IntentProvider[];
|
|
238
|
+
/**
|
|
239
|
+
* Secondary fallback mode if the selected policy cannot be fully evaluated.
|
|
240
|
+
*
|
|
241
|
+
* Example:
|
|
242
|
+
* - CHEAPEST_FIRST without cost metadata
|
|
243
|
+
* - FASTEST_FIRST without latency metadata
|
|
244
|
+
*/
|
|
245
|
+
fallbackMode?: ExecutionPolicyFallbackMode;
|
|
246
|
+
/**
|
|
247
|
+
* Optional exploration behavior applied after deterministic ordering.
|
|
248
|
+
*
|
|
249
|
+
* Exploration is never enabled by default; it is only used when this block is present.
|
|
250
|
+
*/
|
|
251
|
+
exploration?: ExplorationPolicy;
|
|
252
|
+
}
|
|
253
|
+
//# sourceMappingURL=policies.contract.d.ts.map
|
|
@@ -0,0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var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ExplorationMode = exports.ExecutionPolicyFallbackMode = exports.ExecutionPolicyType = exports.PromptParameters = exports.RetryPolicy = void 0;
|
|
10
|
+
const class_validator_1 = require("class-validator");
|
|
11
|
+
/**
|
|
12
|
+
* Retry policy for an intent/model.
|
|
13
|
+
* Keep this stable; it's part of the behavior contract.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Retry policy for an intent/model.
|
|
17
|
+
* Keep this stable; it's part of the behavior contract.
|
|
18
|
+
*/
|
|
19
|
+
class RetryPolicy {
|
|
20
|
+
/**
|
|
21
|
+
* Max total attempts across all candidates (including first try).
|
|
22
|
+
* Example: 3 => try primary + up to 2 more attempts.
|
|
23
|
+
*/
|
|
24
|
+
maxAttempts = 1;
|
|
25
|
+
/**
|
|
26
|
+
* Max retries per single candidate before switching to next.
|
|
27
|
+
* Example: 1 => at most 1 attempt per candidate (no local retries).
|
|
28
|
+
* Example: 2 => 2 attempts on same candidate before fallback.
|
|
29
|
+
*/
|
|
30
|
+
maxPerCandidate = 1;
|
|
31
|
+
/**
|
|
32
|
+
* Timeout for a single provider attempt in milliseconds.
|
|
33
|
+
* If not provided, provider adapter default is used.
|
|
34
|
+
*/
|
|
35
|
+
attemptTimeoutMs = 60000; // Default to 60 seconds
|
|
36
|
+
/**
|
|
37
|
+
* Whether fallback to the next candidate is allowed.
|
|
38
|
+
* If false, fail after exhausting retries of the selected candidate(s).
|
|
39
|
+
*/
|
|
40
|
+
allowFallback = true;
|
|
41
|
+
/**
|
|
42
|
+
* Whether to do a "repair pass" when output fails JSON/schema validation.
|
|
43
|
+
* Useful for strict JSON intents (format parser, mappers).
|
|
44
|
+
*
|
|
45
|
+
* Repair pass semantics (runtime behavior)
|
|
46
|
+
* - Trigger condition: the previous attempt failed with `PARSE_FAIL` or `SCHEMA_FAIL`.
|
|
47
|
+
* - Structured-only: only applies when the intent is in structured mode (has `outputSchema` and/or
|
|
48
|
+
* `response_format` is `json_object`/`json_schema`).
|
|
49
|
+
* - Effect: the gateway appends one extra *system* instruction message to the existing rendered prompt
|
|
50
|
+
* (marker: `[DCDR_REPAIR_PASS]`) asking the model to re-emit ONLY valid JSON matching the expected schema.
|
|
51
|
+
* - Budgeting: consumes the normal retry budget (must still be within `maxPerCandidate` and `maxAttempts`).
|
|
52
|
+
* - Scope: at most one repair pass is attempted per candidate execution.
|
|
53
|
+
*
|
|
54
|
+
* Notes
|
|
55
|
+
* - This does not change the intent inputs; it only changes the instruction for the next attempt.
|
|
56
|
+
* - If you want repair behavior, you typically enable this AND include `PARSE_FAIL`/`SCHEMA_FAIL` in `retryOn`,
|
|
57
|
+
* but the repair pass itself is allowed even when `retryOn` is empty.
|
|
58
|
+
*/
|
|
59
|
+
repairOnParseFail = false;
|
|
60
|
+
/**
|
|
61
|
+
* Backoff strategy between attempts.
|
|
62
|
+
* - fixed: always wait retryBackoffMs
|
|
63
|
+
* - exponential: retryBackoffMs * 2^(n-1), capped by retryBackoffCapMs
|
|
64
|
+
*/
|
|
65
|
+
retryBackoffStrategy = "exponential";
|
|
66
|
+
/**
|
|
67
|
+
* Base backoff delay in milliseconds between attempts (after the first).
|
|
68
|
+
* Defaults can be applied by the engine if undefined.
|
|
69
|
+
*/
|
|
70
|
+
retryBackoffMs = 250;
|
|
71
|
+
/**
|
|
72
|
+
* Maximum backoff delay in milliseconds when using exponential strategy.
|
|
73
|
+
*/
|
|
74
|
+
retryBackoffCapMs = 5000;
|
|
75
|
+
/**
|
|
76
|
+
* Adds random jitter [0..retryJitterMs] to backoff to avoid synchronized retries.
|
|
77
|
+
*/
|
|
78
|
+
retryJitterMs = 250;
|
|
79
|
+
/**
|
|
80
|
+
* Error codes that are considered retryable/fallbackable.
|
|
81
|
+
* Keep values stable. Your engine should map real exceptions into these codes.
|
|
82
|
+
*/
|
|
83
|
+
retryOn;
|
|
84
|
+
}
|
|
85
|
+
exports.RetryPolicy = RetryPolicy;
|
|
86
|
+
__decorate([
|
|
87
|
+
(0, class_validator_1.Min)(1),
|
|
88
|
+
(0, class_validator_1.Max)(10)
|
|
89
|
+
], RetryPolicy.prototype, "maxAttempts", void 0);
|
|
90
|
+
__decorate([
|
|
91
|
+
(0, class_validator_1.Min)(1),
|
|
92
|
+
(0, class_validator_1.Max)(10),
|
|
93
|
+
(0, class_validator_1.IsOptional)()
|
|
94
|
+
], RetryPolicy.prototype, "maxPerCandidate", void 0);
|
|
95
|
+
__decorate([
|
|
96
|
+
(0, class_validator_1.Min)(0),
|
|
97
|
+
(0, class_validator_1.Max)(600000) // 10 minutes max timeout
|
|
98
|
+
], RetryPolicy.prototype, "attemptTimeoutMs", void 0);
|
|
99
|
+
__decorate([
|
|
100
|
+
(0, class_validator_1.IsBoolean)()
|
|
101
|
+
], RetryPolicy.prototype, "allowFallback", void 0);
|
|
102
|
+
__decorate([
|
|
103
|
+
(0, class_validator_1.IsOptional)(),
|
|
104
|
+
(0, class_validator_1.IsBoolean)()
|
|
105
|
+
], RetryPolicy.prototype, "repairOnParseFail", void 0);
|
|
106
|
+
__decorate([
|
|
107
|
+
(0, class_validator_1.IsOptional)()
|
|
108
|
+
], RetryPolicy.prototype, "retryBackoffStrategy", void 0);
|
|
109
|
+
__decorate([
|
|
110
|
+
(0, class_validator_1.Min)(0),
|
|
111
|
+
(0, class_validator_1.Max)(600000),
|
|
112
|
+
(0, class_validator_1.IsOptional)()
|
|
113
|
+
], RetryPolicy.prototype, "retryBackoffMs", void 0);
|
|
114
|
+
__decorate([
|
|
115
|
+
(0, class_validator_1.Min)(0),
|
|
116
|
+
(0, class_validator_1.Max)(600000),
|
|
117
|
+
(0, class_validator_1.IsOptional)()
|
|
118
|
+
], RetryPolicy.prototype, "retryBackoffCapMs", void 0);
|
|
119
|
+
__decorate([
|
|
120
|
+
(0, class_validator_1.Min)(0),
|
|
121
|
+
(0, class_validator_1.Max)(600000),
|
|
122
|
+
(0, class_validator_1.IsOptional)()
|
|
123
|
+
], RetryPolicy.prototype, "retryJitterMs", void 0);
|
|
124
|
+
__decorate([
|
|
125
|
+
(0, class_validator_1.IsOptional)()
|
|
126
|
+
], RetryPolicy.prototype, "retryOn", void 0);
|
|
127
|
+
class PromptParameters {
|
|
128
|
+
/**
|
|
129
|
+
* Typical range: 0.0–2.0 (default: 0.7)
|
|
130
|
+
*/
|
|
131
|
+
temperature;
|
|
132
|
+
/**
|
|
133
|
+
* Typical range: 0.0–1.0 (default: 1)
|
|
134
|
+
*/
|
|
135
|
+
top_p;
|
|
136
|
+
/**
|
|
137
|
+
* Typical range: 1–100 (default: 50)
|
|
138
|
+
*/
|
|
139
|
+
top_k;
|
|
140
|
+
/**
|
|
141
|
+
* Typical range: 1–4096 (default: 2048)
|
|
142
|
+
*/
|
|
143
|
+
max_tokens;
|
|
144
|
+
/**
|
|
145
|
+
* Any integer (optional, for reproducibility)
|
|
146
|
+
*/
|
|
147
|
+
seed;
|
|
148
|
+
enable_thinking;
|
|
149
|
+
response_format;
|
|
150
|
+
/**
|
|
151
|
+
* Typical range: -2.0–2.0 (default: 0.0)
|
|
152
|
+
*/
|
|
153
|
+
presence_penalty;
|
|
154
|
+
/**
|
|
155
|
+
* Typical range: -2.0–2.0 (default: 0.0)
|
|
156
|
+
*/
|
|
157
|
+
frequency_penalty;
|
|
158
|
+
}
|
|
159
|
+
exports.PromptParameters = PromptParameters;
|
|
160
|
+
__decorate([
|
|
161
|
+
(0, class_validator_1.Min)(0),
|
|
162
|
+
(0, class_validator_1.Max)(2),
|
|
163
|
+
(0, class_validator_1.IsOptional)()
|
|
164
|
+
], PromptParameters.prototype, "temperature", void 0);
|
|
165
|
+
__decorate([
|
|
166
|
+
(0, class_validator_1.Min)(0),
|
|
167
|
+
(0, class_validator_1.Max)(1),
|
|
168
|
+
(0, class_validator_1.IsOptional)()
|
|
169
|
+
], PromptParameters.prototype, "top_p", void 0);
|
|
170
|
+
__decorate([
|
|
171
|
+
(0, class_validator_1.Min)(1),
|
|
172
|
+
(0, class_validator_1.Max)(100),
|
|
173
|
+
(0, class_validator_1.IsOptional)()
|
|
174
|
+
], PromptParameters.prototype, "top_k", void 0);
|
|
175
|
+
__decorate([
|
|
176
|
+
(0, class_validator_1.Min)(1),
|
|
177
|
+
(0, class_validator_1.Max)(8192),
|
|
178
|
+
(0, class_validator_1.IsOptional)()
|
|
179
|
+
], PromptParameters.prototype, "max_tokens", void 0);
|
|
180
|
+
__decorate([
|
|
181
|
+
(0, class_validator_1.IsOptional)()
|
|
182
|
+
], PromptParameters.prototype, "seed", void 0);
|
|
183
|
+
__decorate([
|
|
184
|
+
(0, class_validator_1.IsOptional)(),
|
|
185
|
+
(0, class_validator_1.IsBoolean)()
|
|
186
|
+
], PromptParameters.prototype, "enable_thinking", void 0);
|
|
187
|
+
__decorate([
|
|
188
|
+
(0, class_validator_1.IsOptional)()
|
|
189
|
+
], PromptParameters.prototype, "response_format", void 0);
|
|
190
|
+
__decorate([
|
|
191
|
+
(0, class_validator_1.Min)(-2),
|
|
192
|
+
(0, class_validator_1.Max)(2),
|
|
193
|
+
(0, class_validator_1.IsOptional)()
|
|
194
|
+
], PromptParameters.prototype, "presence_penalty", void 0);
|
|
195
|
+
__decorate([
|
|
196
|
+
(0, class_validator_1.Min)(-2),
|
|
197
|
+
(0, class_validator_1.Max)(2),
|
|
198
|
+
(0, class_validator_1.IsOptional)()
|
|
199
|
+
], PromptParameters.prototype, "frequency_penalty", void 0);
|
|
200
|
+
;
|
|
201
|
+
/**
|
|
202
|
+
* Supported execution policy types.
|
|
203
|
+
*
|
|
204
|
+
* These policies decide how the gateway chooses the initial implementation
|
|
205
|
+
* order before retries / fallback logic is applied.
|
|
206
|
+
*
|
|
207
|
+
* Notes:
|
|
208
|
+
* - RetryPolicy is still responsible for retry attempts and failure handling.
|
|
209
|
+
* - ExecutionPolicy is responsible for candidate planning and prioritization.
|
|
210
|
+
*/
|
|
211
|
+
var ExecutionPolicyType;
|
|
212
|
+
(function (ExecutionPolicyType) {
|
|
213
|
+
/**
|
|
214
|
+
* Use implementation weights as provided.
|
|
215
|
+
* This is the simplest and most backward-compatible mode.
|
|
216
|
+
*/
|
|
217
|
+
ExecutionPolicyType["WEIGHTED"] = "WEIGHTED";
|
|
218
|
+
/**
|
|
219
|
+
* Use a fixed implementation order.
|
|
220
|
+
* The first active/healthy implementation is tried first, then the next one.
|
|
221
|
+
*/
|
|
222
|
+
ExecutionPolicyType["FALLBACK_CHAIN"] = "FALLBACK_CHAIN";
|
|
223
|
+
/**
|
|
224
|
+
* Prefer local / office / on-prem implementations first.
|
|
225
|
+
* If none are available, use the remaining implementations.
|
|
226
|
+
*/
|
|
227
|
+
ExecutionPolicyType["LOCAL_FIRST"] = "LOCAL_FIRST";
|
|
228
|
+
/**
|
|
229
|
+
* Prefer the cheapest implementations first.
|
|
230
|
+
* Requires each implementation to expose an estimated cost score.
|
|
231
|
+
*/
|
|
232
|
+
ExecutionPolicyType["CHEAPEST_FIRST"] = "CHEAPEST_FIRST";
|
|
233
|
+
/**
|
|
234
|
+
* Prefer the fastest implementations first.
|
|
235
|
+
* Requires each implementation to expose an expected latency score.
|
|
236
|
+
*/
|
|
237
|
+
ExecutionPolicyType["FASTEST_FIRST"] = "FASTEST_FIRST";
|
|
238
|
+
/**
|
|
239
|
+
* Prefer the highest-quality implementations first.
|
|
240
|
+
* Requires each implementation to expose a quality score.
|
|
241
|
+
*/
|
|
242
|
+
ExecutionPolicyType["QUALITY_FIRST"] = "QUALITY_FIRST";
|
|
243
|
+
})(ExecutionPolicyType || (exports.ExecutionPolicyType = ExecutionPolicyType = {}));
|
|
244
|
+
/**
|
|
245
|
+
* Optional behavior when the selected policy cannot be fully evaluated.
|
|
246
|
+
*
|
|
247
|
+
* Example:
|
|
248
|
+
* - CHEAPEST_FIRST was requested, but implementations do not provide cost metadata.
|
|
249
|
+
*/
|
|
250
|
+
var ExecutionPolicyFallbackMode;
|
|
251
|
+
(function (ExecutionPolicyFallbackMode) {
|
|
252
|
+
/**
|
|
253
|
+
* Fall back to simple weighted selection.
|
|
254
|
+
*/
|
|
255
|
+
ExecutionPolicyFallbackMode["WEIGHTED"] = "WEIGHTED";
|
|
256
|
+
/**
|
|
257
|
+
* Fall back to the declared implementation order.
|
|
258
|
+
*/
|
|
259
|
+
ExecutionPolicyFallbackMode["DECLARED_ORDER"] = "DECLARED_ORDER";
|
|
260
|
+
/**
|
|
261
|
+
* Fail fast if the policy cannot be evaluated correctly.
|
|
262
|
+
*/
|
|
263
|
+
ExecutionPolicyFallbackMode["ERROR"] = "ERROR";
|
|
264
|
+
})(ExecutionPolicyFallbackMode || (exports.ExecutionPolicyFallbackMode = ExecutionPolicyFallbackMode = {}));
|
|
265
|
+
/**
|
|
266
|
+
* Exploration modes for candidate planning.
|
|
267
|
+
*
|
|
268
|
+
* Exploration is always explicit (opt-in) and is applied *after* deterministic ordering.
|
|
269
|
+
*
|
|
270
|
+
* V1 invariant
|
|
271
|
+
* - Do not combine weight-based selection with score-based ordering.
|
|
272
|
+
* - Exploration may reorder which candidate is tried first, but it must not change the underlying score ordering.
|
|
273
|
+
*/
|
|
274
|
+
var ExplorationMode;
|
|
275
|
+
(function (ExplorationMode) {
|
|
276
|
+
/**
|
|
277
|
+
* Epsilon-greedy exploration over the top-K candidates.
|
|
278
|
+
*
|
|
279
|
+
* With probability `epsilon`, pick a random candidate in the top-K list.
|
|
280
|
+
* Otherwise, keep the deterministic best candidate.
|
|
281
|
+
*/
|
|
282
|
+
ExplorationMode["EPSILON_GREEDY_TOP_K"] = "EPSILON_GREEDY_TOP_K";
|
|
283
|
+
})(ExplorationMode || (exports.ExplorationMode = ExplorationMode = {}));
|