@techis/ai-runtime 0.0.0-stage → 0.3.0-rc.15
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 +122 -0
- package/README.md +56 -3
- package/THIRD_PARTY_NOTICES +34 -0
- package/dist/adapters/gemini.d.ts +3 -0
- package/dist/adapters/gemini.d.ts.map +1 -0
- package/dist/adapters/gemini.js +85 -0
- package/dist/adapters/gemini.js.map +1 -0
- package/dist/adapters/http.d.ts +21 -0
- package/dist/adapters/http.d.ts.map +1 -0
- package/dist/adapters/http.js +86 -0
- package/dist/adapters/http.js.map +1 -0
- package/dist/adapters/mock.d.ts +40 -0
- package/dist/adapters/mock.d.ts.map +1 -0
- package/dist/adapters/mock.js +48 -0
- package/dist/adapters/mock.js.map +1 -0
- package/dist/adapters/moonshot.d.ts +3 -0
- package/dist/adapters/moonshot.d.ts.map +1 -0
- package/dist/adapters/moonshot.js +46 -0
- package/dist/adapters/moonshot.js.map +1 -0
- package/dist/adapters/openai.d.ts +4 -0
- package/dist/adapters/openai.d.ts.map +1 -0
- package/dist/adapters/openai.js +107 -0
- package/dist/adapters/openai.js.map +1 -0
- package/dist/adapters/registry.d.ts +6 -0
- package/dist/adapters/registry.d.ts.map +1 -0
- package/dist/adapters/registry.js +39 -0
- package/dist/adapters/registry.js.map +1 -0
- package/dist/adapters/types.d.ts +60 -0
- package/dist/adapters/types.d.ts.map +1 -0
- package/dist/adapters/types.js +2 -0
- package/dist/adapters/types.js.map +1 -0
- package/dist/adapters/zai.d.ts +27 -0
- package/dist/adapters/zai.d.ts.map +1 -0
- package/dist/adapters/zai.js +111 -0
- package/dist/adapters/zai.js.map +1 -0
- package/dist/bundle-source-factory.d.ts +4 -0
- package/dist/bundle-source-factory.d.ts.map +1 -0
- package/dist/bundle-source-factory.js +5 -0
- package/dist/bundle-source-factory.js.map +1 -0
- package/dist/bundle-source.d.ts +40 -0
- package/dist/bundle-source.d.ts.map +1 -0
- package/dist/bundle-source.js +167 -0
- package/dist/bundle-source.js.map +1 -0
- package/dist/catalog-delivery.d.ts +53 -0
- package/dist/catalog-delivery.d.ts.map +1 -0
- package/dist/catalog-delivery.js +148 -0
- package/dist/catalog-delivery.js.map +1 -0
- package/dist/client.d.ts +33 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +238 -0
- package/dist/client.js.map +1 -0
- package/dist/cost.d.ts +28 -0
- package/dist/cost.d.ts.map +1 -0
- package/dist/cost.js +92 -0
- package/dist/cost.js.map +1 -0
- package/dist/deadline.d.ts +3 -0
- package/dist/deadline.d.ts.map +1 -0
- package/dist/deadline.js +37 -0
- package/dist/deadline.js.map +1 -0
- package/dist/errors.d.ts +61 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +110 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/package-updates.d.ts +24 -0
- package/dist/package-updates.d.ts.map +1 -0
- package/dist/package-updates.js +56 -0
- package/dist/package-updates.js.map +1 -0
- package/dist/reasoning-resolution.d.ts +33 -0
- package/dist/reasoning-resolution.d.ts.map +1 -0
- package/dist/reasoning-resolution.js +89 -0
- package/dist/reasoning-resolution.js.map +1 -0
- package/dist/resolution.d.ts +17 -0
- package/dist/resolution.d.ts.map +1 -0
- package/dist/resolution.js +94 -0
- package/dist/resolution.js.map +1 -0
- package/dist/run.d.ts +45 -0
- package/dist/run.d.ts.map +1 -0
- package/dist/run.js +802 -0
- package/dist/run.js.map +1 -0
- package/dist/scoped-source.d.ts +20 -0
- package/dist/scoped-source.d.ts.map +1 -0
- package/dist/scoped-source.js +112 -0
- package/dist/scoped-source.js.map +1 -0
- package/dist/snapshot.d.ts +40 -0
- package/dist/snapshot.d.ts.map +1 -0
- package/dist/snapshot.js +234 -0
- package/dist/snapshot.js.map +1 -0
- package/dist/types.d.ts +244 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +15 -0
- package/dist/types.js.map +1 -0
- package/dist/version.d.ts +9 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +9 -0
- package/dist/version.js.map +1 -0
- package/package.json +26 -6
- package/third-party-licenses/ajv-formats@3.0.1/LICENSE +21 -0
- package/third-party-licenses/ajv@8.20.0/LICENSE +22 -0
- package/third-party-licenses/fast-deep-equal@3.1.3/LICENSE +21 -0
- package/third-party-licenses/fast-uri@3.1.7/LICENSE +30 -0
- package/third-party-licenses/json-schema-traverse@1.0.0/LICENSE +21 -0
- package/third-party-licenses/require-from-string@2.0.2/license +21 -0
- package/third-party-licenses/typescript@5.9.3/LICENSE.txt +55 -0
- package/third-party-licenses/typescript@5.9.3/ThirdPartyNoticeText.txt +193 -0
- package/third-party-licenses.json +102 -0
package/dist/cost.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/** Character-count heuristic (~4 chars/token) plus a flat per-image allowance. Estimates are labeled, never presented as measured. */
|
|
2
|
+
export function estimateInputTokens(input) {
|
|
3
|
+
const text = typeof input === "string" ? input : (input.text ?? "");
|
|
4
|
+
const images = typeof input === "string" ? 0 : (input.images?.length ?? 0);
|
|
5
|
+
return { tokens: Math.ceil(text.length / 4) + images * 1600, basis: "character-heuristic" };
|
|
6
|
+
}
|
|
7
|
+
export function priceForModel(catalog, manifest, catalogId) {
|
|
8
|
+
const priceRevisionId = manifest.references.priceRevisions[catalogId];
|
|
9
|
+
if (!priceRevisionId)
|
|
10
|
+
return undefined;
|
|
11
|
+
return catalog.prices.find((price) => price.priceRevisionId === priceRevisionId);
|
|
12
|
+
}
|
|
13
|
+
function effectiveRates(price, inputTokens) {
|
|
14
|
+
const tier = price.longContextTiers
|
|
15
|
+
?.slice()
|
|
16
|
+
.sort((a, b) => b.inputTokenThreshold - a.inputTokenThreshold)
|
|
17
|
+
.find((t) => inputTokens > t.inputTokenThreshold);
|
|
18
|
+
const rate = (dimension) => price.schemaVersion === 2 && price.unknownDimensions?.includes(dimension) ? undefined : price[dimension];
|
|
19
|
+
if (!tier)
|
|
20
|
+
return { input: rate("input"), output: rate("output"), cachedInput: rate("cachedInput"), cacheWriteInput: rate("cacheWriteInput") };
|
|
21
|
+
const multiply = (value, multiplier) => value === undefined || multiplier === undefined ? undefined : value * multiplier;
|
|
22
|
+
return {
|
|
23
|
+
input: multiply(rate("input"), tier.inputMultiplier),
|
|
24
|
+
output: multiply(rate("output"), tier.outputMultiplier),
|
|
25
|
+
cachedInput: price.schemaVersion === 2 ? multiply(rate("cachedInput"), tier.cachedInputMultiplier) : price.cachedInput,
|
|
26
|
+
cacheWriteInput: price.schemaVersion === 2 ? multiply(rate("cacheWriteInput"), tier.cacheWriteInputMultiplier) : price.cacheWriteInput
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Conservative preflight ceiling: estimated input plus the full output-token cap. Token
|
|
31
|
+
* pricing and provider metering prevent an exact monetary guarantee; this documents the
|
|
32
|
+
* supported enforcement semantics as estimate-based.
|
|
33
|
+
*/
|
|
34
|
+
export function preflightCostCeiling(price, estimatedInputTokens, maxOutputTokens) {
|
|
35
|
+
if (!price || price.units !== "per-million-tokens") {
|
|
36
|
+
return { currency: price?.currency ?? "USD", priceKnown: false };
|
|
37
|
+
}
|
|
38
|
+
const rates = effectiveRates(price, estimatedInputTokens);
|
|
39
|
+
const parts = [];
|
|
40
|
+
if (rates.input !== undefined)
|
|
41
|
+
parts.push((estimatedInputTokens / 1e6) * rates.input);
|
|
42
|
+
if (rates.output !== undefined)
|
|
43
|
+
parts.push((maxOutputTokens / 1e6) * rates.output);
|
|
44
|
+
if (parts.length < 2 || rates.input === undefined || rates.output === undefined) {
|
|
45
|
+
return { currency: price.currency, priceRevisionId: price.priceRevisionId, priceKnown: false };
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
currency: price.currency,
|
|
49
|
+
amount: parts.reduce((sum, part) => sum + part, 0),
|
|
50
|
+
priceRevisionId: price.priceRevisionId,
|
|
51
|
+
priceKnown: true
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Cost attribution from reported usage. Reasoning tokens are billed as output tokens and
|
|
56
|
+
* are already included in reported outputTokens by the adapters, so they are never added
|
|
57
|
+
* separately (no double counting). Any used dimension without a price makes the whole
|
|
58
|
+
* estimate unknown — unknown is never zero.
|
|
59
|
+
*/
|
|
60
|
+
export function costFromUsage(usage, price) {
|
|
61
|
+
if (!usage)
|
|
62
|
+
return { currency: price?.currency ?? "USD", priceRevisionId: price?.priceRevisionId, priceKnown: false };
|
|
63
|
+
if (!price || price.units !== "per-million-tokens") {
|
|
64
|
+
return { currency: price?.currency ?? "USD", priceKnown: false };
|
|
65
|
+
}
|
|
66
|
+
const rates = effectiveRates(price, usage.inputTokens ?? 0);
|
|
67
|
+
let amount = 0;
|
|
68
|
+
let known = usage.inputTokens !== undefined && usage.outputTokens !== undefined && !(usage.toolCalls && usage.toolCalls > 0);
|
|
69
|
+
const uncachedInput = usage.inputTokens === undefined ? undefined : Math.max(0, usage.inputTokens - (usage.cachedInputTokens ?? 0) - (usage.cacheWriteInputTokens ?? 0));
|
|
70
|
+
const dimensions = [
|
|
71
|
+
[uncachedInput, rates.input],
|
|
72
|
+
[usage.outputTokens, rates.output],
|
|
73
|
+
[usage.cachedInputTokens, rates.cachedInput],
|
|
74
|
+
[usage.cacheWriteInputTokens, rates.cacheWriteInput]
|
|
75
|
+
];
|
|
76
|
+
for (const [tokens, rate] of dimensions) {
|
|
77
|
+
if (tokens === undefined || tokens === 0)
|
|
78
|
+
continue;
|
|
79
|
+
if (rate === undefined) {
|
|
80
|
+
known = false;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
amount += (tokens / 1e6) * rate;
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
currency: price.currency,
|
|
87
|
+
amount: known ? amount : undefined,
|
|
88
|
+
priceRevisionId: price.priceRevisionId,
|
|
89
|
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AAC;IACF,KAAK,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,UAAU,EAAE,CAAC;QACxC,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,CAAC;YAAE,SAAS;QACnD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,KAAK,GAAG,KAAK,CAAC;YACd,SAAS;QACX,CAAC;QACD,MAAM,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC;IAClC,CAAC;IACD,OAAO;QACL,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;QAClC,eAAe,EAAE,KAAK,CAAC,eAAe;QACtC,UAAU,EAAE,KAAK;KAClB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/** Bounds even custom transports/resolvers that ignore cancellation; late settlement is ignored. */
|
|
2
|
+
export declare function withDeadline<T>(work: (signal: AbortSignal) => Promise<T>, milliseconds: number, timeoutError: () => Error, parent?: AbortSignal): Promise<T>;
|
|
3
|
+
//# sourceMappingURL=deadline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deadline.d.ts","sourceRoot":"","sources":["../src/deadline.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,wBAAsB,YAAY,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,MAAM,EACnG,YAAY,EAAE,MAAM,KAAK,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAuB7D"}
|
package/dist/deadline.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** Bounds even custom transports/resolvers that ignore cancellation; late settlement is ignored. */
|
|
2
|
+
export async function withDeadline(work, milliseconds, timeoutError, parent) {
|
|
3
|
+
const controller = new AbortController();
|
|
4
|
+
let timer;
|
|
5
|
+
let abort;
|
|
6
|
+
const expiresAt = performance.now() + milliseconds;
|
|
7
|
+
try {
|
|
8
|
+
return await Promise.race([new Promise((_, reject) => {
|
|
9
|
+
abort = () => { controller.abort(); reject(parent?.reason instanceof Error ? parent.reason : timeoutError()); };
|
|
10
|
+
parent?.addEventListener("abort", abort, { once: true });
|
|
11
|
+
if (parent?.aborted) {
|
|
12
|
+
abort();
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
// No implicit timer for unbounded caller-owned work. Chunk very long durations instead of overflowing Node's timer range.
|
|
16
|
+
const schedule = () => {
|
|
17
|
+
const remaining = expiresAt - performance.now();
|
|
18
|
+
if (remaining <= 0) {
|
|
19
|
+
controller.abort();
|
|
20
|
+
reject(timeoutError());
|
|
21
|
+
}
|
|
22
|
+
else if (Number.isFinite(remaining))
|
|
23
|
+
timer = setTimeout(schedule, Math.min(Math.ceil(remaining), 2_147_483_647));
|
|
24
|
+
};
|
|
25
|
+
schedule();
|
|
26
|
+
}), Promise.resolve().then(() => { if (controller.signal.aborted)
|
|
27
|
+
throw timeoutError(); return work(controller.signal); })]);
|
|
28
|
+
}
|
|
29
|
+
finally {
|
|
30
|
+
if (timer)
|
|
31
|
+
clearTimeout(timer);
|
|
32
|
+
if (abort)
|
|
33
|
+
parent?.removeEventListener("abort", abort);
|
|
34
|
+
controller.abort(); // Reject late queue admissions/dispatches even after the winning promise has settled.
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=deadline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deadline.js","sourceRoot":"","sources":["../src/deadline.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,MAAM,CAAC,KAAK,UAAU,YAAY,CAAI,IAAyC,EAAE,YAAoB,EACnG,YAAyB,EAAE,MAAoB;IAC/C,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC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AC,MAAM,CAAC,OAAO;gBAAE,MAAM,YAAY,EAAE,CAAC,CAAC,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/H,CAAC;YAAS,CAAC;QACT,IAAI,KAAK;YAAE,YAAY,CAAC,KAAK,CAAC,CAAC;QAC/B,IAAI,KAAK;YAAE,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACvD,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC,sFAAsF;IAC5G,CAAC;AACH,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/** Structured error taxonomy for the runtime. Messages are sanitized: no secrets, prompts, outputs, or unrestricted provider bodies. */
|
|
2
|
+
export type ErrorCode = "configuration-invalid" | "configuration-unavailable" | "configuration-revoked" | "unsupported-capability" | "unsupported-adapter" | "credential-unavailable" | "credential-invalid" | "model-unavailable" | "provider-rate-limit" | "provider-timeout" | "provider-server-error" | "provider-invalid-request" | "network-error" | "cancelled" | "invalid-output" | "attempts-exhausted" | "budget-exceeded" | "input-limit-exceeded";
|
|
3
|
+
export declare class AISubsystemError extends Error {
|
|
4
|
+
readonly code: ErrorCode;
|
|
5
|
+
/** True when this error class is eligible for configured retry/fallback. */
|
|
6
|
+
readonly retryable: boolean;
|
|
7
|
+
readonly details?: Record<string, unknown>;
|
|
8
|
+
/**
|
|
9
|
+
* The canonical terminal receipt for the invocation that failed. Set by the run engine
|
|
10
|
+
* before the error surfaces so callers can inspect full terminal evidence after failure.
|
|
11
|
+
*/
|
|
12
|
+
executionReceipt?: import("@techis/ai-contracts").ExecutionReceipt;
|
|
13
|
+
constructor(code: ErrorCode, message: string, retryable?: boolean, details?: Record<string, unknown>);
|
|
14
|
+
}
|
|
15
|
+
export declare class ConfigurationInvalidError extends AISubsystemError {
|
|
16
|
+
constructor(message: string, details?: Record<string, unknown>);
|
|
17
|
+
}
|
|
18
|
+
export declare class ConfigurationUnavailableError extends AISubsystemError {
|
|
19
|
+
constructor(message: string, details?: Record<string, unknown>);
|
|
20
|
+
}
|
|
21
|
+
export declare class ConfigurationRevokedError extends AISubsystemError {
|
|
22
|
+
constructor(message: string, details?: Record<string, unknown>);
|
|
23
|
+
}
|
|
24
|
+
export declare class UnsupportedCapabilityError extends AISubsystemError {
|
|
25
|
+
constructor(message: string, details?: Record<string, unknown>);
|
|
26
|
+
}
|
|
27
|
+
export declare class UnsupportedAdapterError extends AISubsystemError {
|
|
28
|
+
constructor(message: string, details?: Record<string, unknown>);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The stored credential exists but cannot be decrypted or is corrupt: unlike a missing
|
|
32
|
+
* credential (skip the candidate and move forward), this stops the chain with an
|
|
33
|
+
* actionable status because every retry would fail identically.
|
|
34
|
+
*/
|
|
35
|
+
export declare class CredentialInvalidError extends AISubsystemError {
|
|
36
|
+
constructor(message: string);
|
|
37
|
+
}
|
|
38
|
+
export declare class CredentialUnavailableError extends AISubsystemError {
|
|
39
|
+
constructor(message: string, details?: Record<string, unknown>);
|
|
40
|
+
}
|
|
41
|
+
export declare class ProviderCallError extends AISubsystemError {
|
|
42
|
+
readonly status?: number;
|
|
43
|
+
constructor(code: "provider-rate-limit" | "provider-timeout" | "provider-server-error" | "provider-invalid-request" | "network-error" | "model-unavailable", message: string, retryable: boolean, status?: number, details?: Record<string, unknown>);
|
|
44
|
+
}
|
|
45
|
+
export declare class CancellationError extends AISubsystemError {
|
|
46
|
+
constructor(message?: string);
|
|
47
|
+
}
|
|
48
|
+
export declare class InvalidOutputError extends AISubsystemError {
|
|
49
|
+
constructor(message: string, details?: Record<string, unknown>);
|
|
50
|
+
}
|
|
51
|
+
export declare class AttemptsExhaustedError extends AISubsystemError {
|
|
52
|
+
constructor(message: string, details?: Record<string, unknown>);
|
|
53
|
+
}
|
|
54
|
+
export declare class BudgetExceededError extends AISubsystemError {
|
|
55
|
+
constructor(message: string, details?: Record<string, unknown>);
|
|
56
|
+
}
|
|
57
|
+
export declare class InputLimitExceededError extends AISubsystemError {
|
|
58
|
+
constructor(message: string, details?: Record<string, unknown>);
|
|
59
|
+
}
|
|
60
|
+
export declare function toAISubsystemError(error: unknown): AISubsystemError;
|
|
61
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,wIAAwI;AACxI,MAAM,MAAM,SAAS,GACjB,uBAAuB,GACvB,2BAA2B,GAC3B,uBAAuB,GACvB,wBAAwB,GACxB,qBAAqB,GACrB,wBAAwB,GACxB,oBAAoB,GACpB,mBAAmB,GACnB,qBAAqB,GACrB,kBAAkB,GAClB,uBAAuB,GACvB,0BAA0B,GAC1B,eAAe,GACf,WAAW,GACX,gBAAgB,GAChB,oBAAoB,GACpB,iBAAiB,GACjB,sBAAsB,CAAC;AAE3B,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,4EAA4E;IAC5E,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC3C;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,sBAAsB,EAAE,gBAAgB,CAAC;gBAEvD,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,UAAQ,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAOnG;AAED,qBAAa,yBAA0B,SAAQ,gBAAgB;gBACjD,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAI/D;AAED,qBAAa,6BAA8B,SAAQ,gBAAgB;gBACrD,OAAO,EAAE,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AC9C,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAI/D;AAED,qBAAa,mBAAoB,SAAQ,gBAAgB;gBAC3C,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAI/D;AAED,qBAAa,uBAAwB,SAAQ,gBAAgB;gBAC/C,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAI/D;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB,CAInE"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
export class AISubsystemError extends Error {
|
|
2
|
+
code;
|
|
3
|
+
/** True when this error class is eligible for configured retry/fallback. */
|
|
4
|
+
retryable;
|
|
5
|
+
details;
|
|
6
|
+
/**
|
|
7
|
+
* The canonical terminal receipt for the invocation that failed. Set by the run engine
|
|
8
|
+
* before the error surfaces so callers can inspect full terminal evidence after failure.
|
|
9
|
+
*/
|
|
10
|
+
executionReceipt;
|
|
11
|
+
constructor(code, message, retryable = false, details) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = "AISubsystemError";
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.retryable = retryable;
|
|
16
|
+
this.details = details;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export class ConfigurationInvalidError extends AISubsystemError {
|
|
20
|
+
constructor(message, details) {
|
|
21
|
+
super("configuration-invalid", message, false, details);
|
|
22
|
+
this.name = "ConfigurationInvalidError";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export class ConfigurationUnavailableError extends AISubsystemError {
|
|
26
|
+
constructor(message, details) {
|
|
27
|
+
super("configuration-unavailable", message, false, details);
|
|
28
|
+
this.name = "ConfigurationUnavailableError";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export class ConfigurationRevokedError extends AISubsystemError {
|
|
32
|
+
constructor(message, details) {
|
|
33
|
+
super("configuration-revoked", message, false, details);
|
|
34
|
+
this.name = "ConfigurationRevokedError";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export class UnsupportedCapabilityError extends AISubsystemError {
|
|
38
|
+
constructor(message, details) {
|
|
39
|
+
super("unsupported-capability", message, false, details);
|
|
40
|
+
this.name = "UnsupportedCapabilityError";
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export class UnsupportedAdapterError extends AISubsystemError {
|
|
44
|
+
constructor(message, details) {
|
|
45
|
+
super("unsupported-adapter", message, false, details);
|
|
46
|
+
this.name = "UnsupportedAdapterError";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The stored credential exists but cannot be decrypted or is corrupt: unlike a missing
|
|
51
|
+
* credential (skip the candidate and move forward), this stops the chain with an
|
|
52
|
+
* actionable status because every retry would fail identically.
|
|
53
|
+
*/
|
|
54
|
+
export class CredentialInvalidError extends AISubsystemError {
|
|
55
|
+
constructor(message) {
|
|
56
|
+
super("credential-invalid", message, false);
|
|
57
|
+
this.name = "CredentialInvalidError";
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export class CredentialUnavailableError extends AISubsystemError {
|
|
61
|
+
constructor(message, details) {
|
|
62
|
+
super("credential-unavailable", message, false, details);
|
|
63
|
+
this.name = "CredentialUnavailableError";
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export class ProviderCallError extends AISubsystemError {
|
|
67
|
+
status;
|
|
68
|
+
constructor(code, message, retryable, status, details) {
|
|
69
|
+
super(code, message, retryable, { ...details, ...(status !== undefined ? { status } : {}) });
|
|
70
|
+
this.name = "ProviderCallError";
|
|
71
|
+
this.status = status;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export class CancellationError extends AISubsystemError {
|
|
75
|
+
constructor(message = "Execution cancelled by caller") {
|
|
76
|
+
super("cancelled", message, false);
|
|
77
|
+
this.name = "CancellationError";
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
export class InvalidOutputError extends AISubsystemError {
|
|
81
|
+
constructor(message, details) {
|
|
82
|
+
super("invalid-output", message, false, details);
|
|
83
|
+
this.name = "InvalidOutputError";
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
export class AttemptsExhaustedError extends AISubsystemError {
|
|
87
|
+
constructor(message, details) {
|
|
88
|
+
super("attempts-exhausted", message, false, details);
|
|
89
|
+
this.name = "AttemptsExhaustedError";
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
export class BudgetExceededError extends AISubsystemError {
|
|
93
|
+
constructor(message, details) {
|
|
94
|
+
super("budget-exceeded", message, false, details);
|
|
95
|
+
this.name = "BudgetExceededError";
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
export class InputLimitExceededError extends AISubsystemError {
|
|
99
|
+
constructor(message, details) {
|
|
100
|
+
super("input-limit-exceeded", message, false, details);
|
|
101
|
+
this.name = "InputLimitExceededError";
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
export function toAISubsystemError(error) {
|
|
105
|
+
if (error instanceof AISubsystemError)
|
|
106
|
+
return error;
|
|
107
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
108
|
+
return new AISubsystemError("network-error", message, true);
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAqBA,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAChC,IAAI,CAAY;IACzB,4EAA4E;IACnE,SAAS,CAAU;IACnB,OAAO,CAA2B;IAC3C;;;OAGG;IACH,gBAAgB,CAAmD;IAEnE,YAAY,IAAe,EAAE,OAAe,EAAE,SAAS,GAAG,KAAK,EAAE,OAAiC;QAChG,KAAK,CAAC,OAAO,CA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AG,oBAAoB,CAAC;IACnC,CAAC;CACF;AAED,MAAM,OAAO,sBAAuB,SAAQ,gBAAgB;IAC1D,YAAY,OAAe,EAAE,OAAiC;QAC5D,KAAK,CAAC,oBAAoB,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;QACrD,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF;AAED,MAAM,OAAO,mBAAoB,SAAQ,gBAAgB;IACvD,YAAY,OAAe,EAAE,OAAiC;QAC5D,KAAK,CAAC,iBAAiB,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;QAClD,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AAED,MAAM,OAAO,uBAAwB,SAAQ,gBAAgB;IAC3D,YAAY,OAAe,EAAE,OAAiC;QAC5D,KAAK,CAAC,sBAAsB,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;QACvD,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF;AAED,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,IAAI,KAAK,YAAY,gBAAgB;QAAE,OAAO,KAAK,CAAC;IACpD,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvE,OAAO,IAAI,gBAAgB,CAAC,eAAe,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;AAC9D,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export { createAIClient, type CreateAIClientOptions } from "./client.js";
|
|
2
|
+
export { createScopedSnapshotSourceV2, projectScopedSnapshotV2 } from "./scoped-source.js";
|
|
3
|
+
export { loadBundle, projectBundleSnapshot, type LoadBundleOptions } from "./bundle-source.js";
|
|
4
|
+
export { bundleSource } from "./bundle-source-factory.js";
|
|
5
|
+
export { RUNTIME_VERSION } from "./version.js";
|
|
6
|
+
export { createRun, type RunDependencies, type AttemptContext, type AttemptExecutor } from "./run.js";
|
|
7
|
+
export { resolvePersonaToken } from "./resolution.js";
|
|
8
|
+
export { resolveEffectiveReasoning, type EffortResolution } from "./reasoning-resolution.js";
|
|
9
|
+
export { OPERATION_ID_PATTERN } from "./types.js";
|
|
10
|
+
export { estimateInputTokens, preflightCostCeiling, costFromUsage, priceForModel } from "./cost.js";
|
|
11
|
+
export { loadSnapshotDocuments, loadSnapshotFromManagementApi, validateSnapshot, parseRevocations, MANIFEST_POINTER_KEY, MANIFEST_HISTORY_KEY, CATALOG_RELEASE_KEY, PROFILE_REVISION_KEY, PERSONA_REVISION_KEY, ASSIGNMENTS_KEY, REVOCATIONS_KEY, type ManifestRevocation } from "./snapshot.js";
|
|
12
|
+
export * from "./errors.js";
|
|
13
|
+
export type { AIClient, AIWorkflow, InstructionProjection, AIRun, CachePolicy, SnapshotCache, ConfigurationDocumentStore, ConfigurationSnapshot, ConfigurationSource, ConnectionIndex, Credential, CredentialResolver, FetchImpl, GenerateInput, GenerateOptions, OperationSettings, GenerateResult, ImagePart, InlineSource, ManagementApiSource, NormalizedOutput, ResolutionToken, StartRunOptions, StoredDocument, StoreSource, BundleSource } from "./types.js";
|
|
14
|
+
export { envCredentialResolver } from "./types.js";
|
|
15
|
+
export { defaultAdapters, createAdapterRegistry, satisfiesMinVersion } from "./adapters/registry.js";
|
|
16
|
+
export type { AdapterRegistry, AdapterRequest, AdapterResponse, AdapterOutput, NativeSettings, ProviderAdapter } from "./adapters/types.js";
|
|
17
|
+
export { createOpenAiResponsesAdapter } from "./adapters/openai.js";
|
|
18
|
+
export { createZaiChatCompletionsAdapter } from "./adapters/zai.js";
|
|
19
|
+
export { createMoonshotChatCompletionsAdapter } from "./adapters/moonshot.js";
|
|
20
|
+
export { createGeminiGenerateContentAdapter } from "./adapters/gemini.js";
|
|
21
|
+
export { createMockAdapter, type MockAdapterOptions, type MockBehavior, type MockStep } from "./adapters/mock.js";
|
|
22
|
+
export * from "./package-updates.js";
|
|
23
|
+
export * from "./catalog-delivery.js";
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,4BAA4B,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC3F,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,KAAK,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC/F,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,KAAK,eAAe,EAAE,KAAK,cAAc,EAAE,KAAK,eAAe,EAAE,MAAM,UAAU,CAAC;AACtG,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,yBAAyB,EAAE,KAAK,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7F,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AACpG,OAAO,EACL,qBAAqB,EACrB,6BAA6B,EAC7B,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EACf,eAAe,EACf,KAAK,kBAAkB,EACxB,MAAM,eAAe,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,YAAY,EACV,QAAQ,EACR,UAAU,EACV,qBAAqB,EACrB,KAAK,EACL,WAAW,EACX,aAAa,EACb,0BAA0B,EAC1B,qBAAqB,EACrB,mBAAmB,EACnB,eAAe,EACf,UAAU,EACV,kBAAkB,EAClB,SAAS,EACT,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,SAAS,EACT,YAAY,EACZ,mBAAmB,EACnB,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,cAAc,EACd,WAAW,EACX,YAAY,EACb,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AACrG,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,eAAe,EAAE,aAAa,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC5I,OAAO,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAAE,+BAA+B,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,oCAAoC,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAE,kCAAkC,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,KAAK,kBAAkB,EAAE,KAAK,YAAY,EAAE,KAAK,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAClH,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export { createAIClient } from "./client.js";
|
|
2
|
+
export { createScopedSnapshotSourceV2, projectScopedSnapshotV2 } from "./scoped-source.js";
|
|
3
|
+
export { loadBundle, projectBundleSnapshot } from "./bundle-source.js";
|
|
4
|
+
export { bundleSource } from "./bundle-source-factory.js";
|
|
5
|
+
export { RUNTIME_VERSION } from "./version.js";
|
|
6
|
+
export { createRun } from "./run.js";
|
|
7
|
+
export { resolvePersonaToken } from "./resolution.js";
|
|
8
|
+
export { resolveEffectiveReasoning } from "./reasoning-resolution.js";
|
|
9
|
+
export { OPERATION_ID_PATTERN } from "./types.js";
|
|
10
|
+
export { estimateInputTokens, preflightCostCeiling, costFromUsage, priceForModel } from "./cost.js";
|
|
11
|
+
export { loadSnapshotDocuments, loadSnapshotFromManagementApi, validateSnapshot, parseRevocations, MANIFEST_POINTER_KEY, MANIFEST_HISTORY_KEY, CATALOG_RELEASE_KEY, PROFILE_REVISION_KEY, PERSONA_REVISION_KEY, ASSIGNMENTS_KEY, REVOCATIONS_KEY } from "./snapshot.js";
|
|
12
|
+
export * from "./errors.js";
|
|
13
|
+
export { envCredentialResolver } from "./types.js";
|
|
14
|
+
export { defaultAdapters, createAdapterRegistry, satisfiesMinVersion } from "./adapters/registry.js";
|
|
15
|
+
export { createOpenAiResponsesAdapter } from "./adapters/openai.js";
|
|
16
|
+
export { createZaiChatCompletionsAdapter } from "./adapters/zai.js";
|
|
17
|
+
export { createMoonshotChatCompletionsAdapter } from "./adapters/moonshot.js";
|
|
18
|
+
export { createGeminiGenerateContentAdapter } from "./adapters/gemini.js";
|
|
19
|
+
export { createMockAdapter } from "./adapters/mock.js";
|
|
20
|
+
export * from "./package-updates.js";
|
|
21
|
+
export * from "./catalog-delivery.js";
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAA8B,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,4BAA4B,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC3F,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAA0B,MAAM,oBAAoB,CAAC;AAC/F,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAmE,MAAM,UAAU,CAAC;AACtG,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,yBAAyB,EAAyB,MAAM,2BAA2B,CAAC;AAC7F,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AACpG,OAAO,EACL,qBAAqB,EACrB,6BAA6B,EAC7B,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EACf,eAAe,EAEhB,MAAM,eAAe,CAAC;AACvB,cAAc,aAAa,CAAC;AA6B5B,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAErG,OAAO,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAAE,+BAA+B,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,oCAAoC,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAE,kCAAkC,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAA6D,MAAM,oBAAoB,CAAC;AAClH,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type ModelPackageRelease, type ScopedConfigurationSnapshotV2 } from "@techis/ai-contracts";
|
|
2
|
+
export interface PackageAvailabilityNotice {
|
|
3
|
+
kind: "package-available";
|
|
4
|
+
runtimeVersion: string;
|
|
5
|
+
contractsVersion: string;
|
|
6
|
+
releaseId: string;
|
|
7
|
+
advisorySummary: string;
|
|
8
|
+
releaseUri: string;
|
|
9
|
+
}
|
|
10
|
+
export interface PackageAvailabilitySource {
|
|
11
|
+
check(): Promise<PackageAvailabilityNotice[]>;
|
|
12
|
+
}
|
|
13
|
+
/** Local callback surface only. No default source, network client, polling timer, enrollment, installer or adoption authority. */
|
|
14
|
+
export declare function createPackageAvailabilityClient(options: {
|
|
15
|
+
installedRuntimeVersion: string;
|
|
16
|
+
source: PackageAvailabilitySource;
|
|
17
|
+
}): {
|
|
18
|
+
subscribe(listener: (notice: PackageAvailabilityNotice) => void): () => void;
|
|
19
|
+
check(): Promise<PackageAvailabilityNotice[]>;
|
|
20
|
+
};
|
|
21
|
+
export declare function getInstalledModelPackageRelease(): ModelPackageRelease | null;
|
|
22
|
+
export declare function getInstalledCatalogDelivery(): import("@techis/ai-contracts").CatalogDelivery;
|
|
23
|
+
export declare function getModelUpgradeAdvisories(snapshot: ScopedConfigurationSnapshotV2, release?: ModelPackageRelease | null): import("@techis/ai-contracts").ModelUpgradeAdvisory[];
|
|
24
|
+
//# sourceMappingURL=package-updates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-updates.d.ts","sourceRoot":"","sources":["../src/package-updates.ts"],"names":[],"mappings":"AAAA,OAAO,EACW,KAAK,mBAAmB,EAAE,KAAK,6BAA6B,EAAE,MAAM,sBAAsB,CAAC;AAG7G,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,mBAAmB,CAAC;IAC1B,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;CACpB;AACD,MAAM,WAAW,yBAAyB;IAAG,KAAK,IAAI,OAAO,CAAC,yBAAyB,EAAE,CAAC,CAAA;CAAE;AAE5F,kIAAkI;AAClI,wBAAgB,+BAA+B,CAAC,OAAO,EAAE;IAAE,uBAAuB,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,yBAAyB,CAAA;CAAE;wBAMvG,CAAC,MAAM,EAAE,yBAAyB,KAAK,IAAI;aACtD,OAAO,CAAC,yBAAyB,EAAE,CAAC;EAqBhD;AACD,wBAAgB,+BAA+B,IAAI,mBAAmB,GAAG,IAAI,CAI5E;AACD,wBAAgB,2BAA2B,mDAI1C;AACD,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,6BAA6B,EAC/E,OAAO,GAAE,mBAAmB,GAAG,IAAwC,yDAExE"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { getPackagedCatalogDelivery, getPackagedModelRelease, verifyModelPackageRelease, modelUpgradeAdvisoriesForSnapshot, parseSemanticVersion, compareVersions, hashDocumentV2 } from "@techis/ai-contracts";
|
|
2
|
+
import { RUNTIME_VERSION } from "./version.js";
|
|
3
|
+
/** Local callback surface only. No default source, network client, polling timer, enrollment, installer or adoption authority. */
|
|
4
|
+
export function createPackageAvailabilityClient(options) {
|
|
5
|
+
parseSemanticVersion(options.installedRuntimeVersion);
|
|
6
|
+
const listeners = new Set();
|
|
7
|
+
const delivered = new Set();
|
|
8
|
+
let pending;
|
|
9
|
+
return {
|
|
10
|
+
subscribe(listener) { listeners.add(listener); return () => { listeners.delete(listener); }; },
|
|
11
|
+
check() {
|
|
12
|
+
pending ??= (async () => {
|
|
13
|
+
const notices = [];
|
|
14
|
+
for (const raw of await options.source.check()) {
|
|
15
|
+
const notice = structuredClone(raw);
|
|
16
|
+
if (notice.kind !== "package-available" || notice.runtimeVersion !== notice.contractsVersion || !notice.releaseId ||
|
|
17
|
+
!notice.advisorySummary || !/^https:\/\//.test(notice.releaseUri))
|
|
18
|
+
throw new Error("Invalid package-availability notice.");
|
|
19
|
+
// Existing package semver comparison; provider model names and catalog revisions are never ordered here.
|
|
20
|
+
if (compareVersions(notice.runtimeVersion, options.installedRuntimeVersion) <= 0)
|
|
21
|
+
continue;
|
|
22
|
+
const id = hashDocumentV2({ runtimeVersion: notice.runtimeVersion, contractsVersion: notice.contractsVersion,
|
|
23
|
+
releaseId: notice.releaseId });
|
|
24
|
+
if (delivered.has(id))
|
|
25
|
+
continue;
|
|
26
|
+
delivered.add(id);
|
|
27
|
+
notices.push(notice);
|
|
28
|
+
for (const listener of listeners) {
|
|
29
|
+
try {
|
|
30
|
+
listener(structuredClone(notice));
|
|
31
|
+
}
|
|
32
|
+
catch { /* notices cannot affect inference */ }
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return notices;
|
|
36
|
+
})().finally(() => { pending = undefined; });
|
|
37
|
+
return pending;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export function getInstalledModelPackageRelease() {
|
|
42
|
+
const release = getPackagedModelRelease();
|
|
43
|
+
if (release && release.packageVersion !== RUNTIME_VERSION)
|
|
44
|
+
throw new Error("Installed catalog payload does not match its runtime package.");
|
|
45
|
+
return release;
|
|
46
|
+
}
|
|
47
|
+
export function getInstalledCatalogDelivery() {
|
|
48
|
+
const delivery = getPackagedCatalogDelivery();
|
|
49
|
+
if (delivery && delivery.release.packageVersion !== RUNTIME_VERSION)
|
|
50
|
+
throw new Error("Installed delivery/runtime version mismatch.");
|
|
51
|
+
return delivery;
|
|
52
|
+
}
|
|
53
|
+
export function getModelUpgradeAdvisories(snapshot, release = getInstalledModelPackageRelease()) {
|
|
54
|
+
return release ? modelUpgradeAdvisoriesForSnapshot(verifyModelPackageRelease(release), snapshot) : [];
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=package-updates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-updates.js","sourceRoot":"","sources":["../src/package-updates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,yBAAyB,EAAE,iCAAiC,EAAE,oBAAoB,EAAE,eAAe,EAC/J,cAAc,EAAgE,MAAM,sBAAsB,CAAC;AAC7G,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAY/C,kIAAkI;AAClI,MAAM,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ModelDefinition, ModelSettings, NativeReasoningControl } from "@techis/ai-contracts";
|
|
2
|
+
export interface EffortResolution {
|
|
3
|
+
/** The effective control to send to the provider (the slot default when no effort request applied). */
|
|
4
|
+
effective: NativeReasoningControl;
|
|
5
|
+
/** The effort requested for this model after translation, before bounds. */
|
|
6
|
+
requestedEffort?: string;
|
|
7
|
+
/** The native effort level actually sent, after translation and bounds. */
|
|
8
|
+
effectiveEffort?: string;
|
|
9
|
+
/** Human-readable notes for receipts and warnings (for example when bounds applied). */
|
|
10
|
+
notes: string[];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Caller-directed effort resolution for one attempted model.
|
|
14
|
+
*
|
|
15
|
+
* Precedence (implementation plan section 6.3):
|
|
16
|
+
* 1. Start from the slot's configured reasoning control.
|
|
17
|
+
* 2. An exact `effortByModel[catalogId]` value is the requested effort for this model.
|
|
18
|
+
* 3. Otherwise a general `effortHint` resolves through the profile's per-model translations.
|
|
19
|
+
* 4. Without a translation, a hint the model natively supports is used directly.
|
|
20
|
+
* 5. Explicit per-model minimum/maximum bounds clamp the result.
|
|
21
|
+
* 6. The final native level is validated against the catalog.
|
|
22
|
+
*
|
|
23
|
+
* An unsupported, unmapped hint fails before provider I/O — never a nearest-level guess.
|
|
24
|
+
* A hint never re-enables disabled reasoning and never mutates thinking, token-budget, or
|
|
25
|
+
* other non-effort controls; when the slot cannot preserve a hint, the request fails
|
|
26
|
+
* clearly instead.
|
|
27
|
+
*/
|
|
28
|
+
export declare function resolveEffectiveReasoning(model: ModelDefinition, settings: ModelSettings, options: {
|
|
29
|
+
effortHint?: string;
|
|
30
|
+
exactEffort?: string;
|
|
31
|
+
effortPolicy?: ExecutionProfileRevision["effortPolicy"];
|
|
32
|
+
}): EffortResolution;
|
|
33
|
+
//# sourceMappingURL=reasoning-resolution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reasoning-resolution.d.ts","sourceRoot":"","sources":["../src/reasoning-resolution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,eAAe,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAG7H,MAAM,WAAW,gBAAgB;IAC/B,uGAAuG;IACvG,SAAS,EAAE,sBAAsB,CAAC;IAClC,4EAA4E;IAC5E,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,2EAA2E;IAC3E,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,wFAAwF;IACxF,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,eAAe,EACtB,QAAQ,EAAE,aAAa,EACvB,OAAO,EAAE;IAAE,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,wBAAwB,CAAC,cAAc,CAAC,CAAA;CAAE,GAC9G,gBAAgB,CAgFlB"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { UnsupportedCapabilityError } from "./errors.js";
|
|
2
|
+
/**
|
|
3
|
+
* Caller-directed effort resolution for one attempted model.
|
|
4
|
+
*
|
|
5
|
+
* Precedence (implementation plan section 6.3):
|
|
6
|
+
* 1. Start from the slot's configured reasoning control.
|
|
7
|
+
* 2. An exact `effortByModel[catalogId]` value is the requested effort for this model.
|
|
8
|
+
* 3. Otherwise a general `effortHint` resolves through the profile's per-model translations.
|
|
9
|
+
* 4. Without a translation, a hint the model natively supports is used directly.
|
|
10
|
+
* 5. Explicit per-model minimum/maximum bounds clamp the result.
|
|
11
|
+
* 6. The final native level is validated against the catalog.
|
|
12
|
+
*
|
|
13
|
+
* An unsupported, unmapped hint fails before provider I/O — never a nearest-level guess.
|
|
14
|
+
* A hint never re-enables disabled reasoning and never mutates thinking, token-budget, or
|
|
15
|
+
* other non-effort controls; when the slot cannot preserve a hint, the request fails
|
|
16
|
+
* clearly instead.
|
|
17
|
+
*/
|
|
18
|
+
export function resolveEffectiveReasoning(model, settings, options) {
|
|
19
|
+
const configured = settings.reasoning ?? { mode: "provider-default" };
|
|
20
|
+
const notes = [];
|
|
21
|
+
const requested = options.exactEffort ?? options.effortHint;
|
|
22
|
+
if (!requested)
|
|
23
|
+
return { effective: configured, notes };
|
|
24
|
+
const policy = options.effortPolicy;
|
|
25
|
+
if (!policy?.enabled) {
|
|
26
|
+
throw new UnsupportedCapabilityError(`Profile does not accept caller-directed effort (effort policy not enabled); effort request "${requested}" cannot apply to ${model.catalogId}`);
|
|
27
|
+
}
|
|
28
|
+
// An effort request must not mutate non-effort controls: disabled, thinking, token-budget,
|
|
29
|
+
// and combined controls cannot preserve a hint, so the request fails clearly.
|
|
30
|
+
if (configured.mode !== "effort" && configured.mode !== "provider-default") {
|
|
31
|
+
throw new UnsupportedCapabilityError(`${model.catalogId} uses a ${configured.mode} reasoning control; an effort request must not mutate it, and this slot cannot preserve effort hints`);
|
|
32
|
+
}
|
|
33
|
+
const levels = model.nativeReasoning.supportedEffortLevels;
|
|
34
|
+
if (!levels || levels.length === 0 || !model.nativeReasoning.supportedControls.includes("effort")) {
|
|
35
|
+
throw new UnsupportedCapabilityError(`${model.catalogId} does not support effort levels; effort request "${requested}" cannot apply`);
|
|
36
|
+
}
|
|
37
|
+
const rank = (level) => levels.indexOf(level);
|
|
38
|
+
const modelPolicy = policy.byModel?.[model.catalogId];
|
|
39
|
+
let translated;
|
|
40
|
+
if (options.exactEffort !== undefined) {
|
|
41
|
+
// Exact per-model effort must already be a supported native level.
|
|
42
|
+
translated = options.exactEffort;
|
|
43
|
+
if (rank(translated) < 0) {
|
|
44
|
+
throw new UnsupportedCapabilityError(`Exact effort "${translated}" is not a supported level of ${model.catalogId} (supported: ${levels.join(", ")})`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
const mapping = modelPolicy?.translations?.[requested];
|
|
49
|
+
if (mapping !== undefined) {
|
|
50
|
+
translated = mapping;
|
|
51
|
+
if (rank(translated) < 0) {
|
|
52
|
+
throw new UnsupportedCapabilityError(`Effort translation "${requested}" -> "${translated}" targets a level ${model.catalogId} does not support (supported: ${levels.join(", ")})`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else if (rank(requested) >= 0) {
|
|
56
|
+
translated = requested;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
throw new UnsupportedCapabilityError(`Effort request "${requested}" is not a supported level of ${model.catalogId} and has no translation in the profile's effort policy (supported: ${levels.join(", ")})`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
let target = rank(translated);
|
|
63
|
+
const bounded = (kind, level) => {
|
|
64
|
+
if (level === undefined)
|
|
65
|
+
return undefined;
|
|
66
|
+
const at = rank(level);
|
|
67
|
+
if (at < 0) {
|
|
68
|
+
throw new UnsupportedCapabilityError(`Profile effort policy ${kind} "${level}" is not a supported level of ${model.catalogId}`);
|
|
69
|
+
}
|
|
70
|
+
return at;
|
|
71
|
+
};
|
|
72
|
+
const minimum = bounded("minimum", modelPolicy?.minimum);
|
|
73
|
+
const maximum = bounded("maximum", modelPolicy?.maximum);
|
|
74
|
+
if (minimum !== undefined && target < minimum) {
|
|
75
|
+
notes.push(`Effort request "${translated}" raised to policy minimum "${levels[minimum]}" for ${model.catalogId}.`);
|
|
76
|
+
target = minimum;
|
|
77
|
+
}
|
|
78
|
+
if (maximum !== undefined && target > maximum) {
|
|
79
|
+
notes.push(`Effort request "${translated}" lowered to policy maximum "${levels[maximum]}" for ${model.catalogId}.`);
|
|
80
|
+
target = maximum;
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
effective: { mode: "effort", level: levels[target] },
|
|
84
|
+
requestedEffort: translated,
|
|
85
|
+
effectiveEffort: levels[target],
|
|
86
|
+
notes
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=reasoning-resolution.js.map
|