@alvin0/ai-agent-sdk-provider-typesafe 0.1.10 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { CredentialInput, RetryPolicyConfig } from "@alvin0/ai-agent-sdk-core/provider";
2
1
  import { DecisionAdapter, DecisionProviderPlugin } from "@alvin0/ai-agent-sdk-decision-adapter";
3
- //#region src/adapter.d.ts
2
+ import { CredentialInput, RetryPolicyConfig } from "@alvin0/ai-agent-sdk-core/provider";
3
+ //#region src/types.d.ts
4
4
  interface TypesafeAdapterOptions {
5
5
  readonly apiKey: CredentialInput;
6
6
  /** API root including /v1. Default: https://api.typesafe.ai/v1 */
@@ -18,6 +18,8 @@ interface TypesafePluginOptions extends TypesafeAdapterOptions {
18
18
  readonly id?: string;
19
19
  readonly routes?: readonly string[];
20
20
  }
21
+ //#endregion
22
+ //#region src/adapter.d.ts
21
23
  declare function typesafeAdapter(options: TypesafeAdapterOptions): DecisionAdapter;
22
24
  declare function typesafePlugin(options: TypesafePluginOptions): DecisionProviderPlugin;
23
25
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/adapter.ts"],"mappings":";;;UAQiB;WACN,QAAQ;;WAER,mBAAmB;WACnB,eAAe,WAAW;WAC1B,UAAU,SAAS;WACnB;WACA;WACA;WACA,cAAc;;WAEd;;UAEM,8BAA8B;WACpC;WACA;;iBAiRK,gBAAgB,SAAS,yBAAyB;iBAClD,eAAe,SAAS,wBAAwB"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/adapter.ts"],"mappings":";;;UAGiB;WACN,QAAQ;;WAER,mBAAmB;WACnB,eAAe,WAAW;WAC1B,UAAU,SAAS;WACnB;WACA;WACA;WACA,cAAc;;WAEd;;UAGM,8BAA8B;WACpC;WACA;;;;iBCoHK,gBAAgB,SAAS,yBAAyB;iBAGlD,eAAe,SAAS,wBAAwB"}
package/dist/index.js CHANGED
@@ -1,9 +1,50 @@
1
- import { MODEL_ERROR_CODES, ModelError, ProviderRequestId, assertUsableApiKey, attributionHeaders, normalizeModelFailure, resolveRetryPolicy, validateUsageCounters } from "@alvin0/ai-agent-sdk-core";
2
- import { CREDENTIAL_CAPABILITY_API_VERSION } from "@alvin0/ai-agent-sdk-core/provider";
1
+ import { MODEL_ERROR_CODES, ModelError, assertUsableApiKey, resolveRetryPolicy, validateUsageCounters } from "@alvin0/ai-agent-sdk-core";
3
2
  import { DecisionAdapter, defineDecisionProviderPlugin, snapshotDecisionInput, validateDecisionResult } from "@alvin0/ai-agent-sdk-decision-adapter";
4
- import { abortable, throwIfAborted } from "@alvin0/ai-agent-sdk-decision-adapter/transport";
3
+ import { dispatchDecisionHttp } from "@alvin0/ai-agent-sdk-decision-adapter/transport";
4
+ import { CREDENTIAL_CAPABILITY_API_VERSION } from "@alvin0/ai-agent-sdk-core/provider";
5
5
 
6
- //#region src/adapter.ts
6
+ //#region src/response.ts
7
+ function object(value) {
8
+ if (value === null || typeof value !== "object" || Array.isArray(value)) throw new ModelError("TypeSafe returned an invalid response object", MODEL_ERROR_CODES.MALFORMED_RESPONSE);
9
+ return value;
10
+ }
11
+ /** Compare JSON rubric values without depending on object property order. */
12
+ function sameDescription(expected, actual) {
13
+ if (expected === actual) return true;
14
+ if (expected === null || actual === null || typeof expected !== "object" || typeof actual !== "object") return false;
15
+ if (Array.isArray(expected)) return sameArrayDescription(expected, actual);
16
+ if (Array.isArray(actual)) return false;
17
+ const keys = Object.keys(expected);
18
+ return keys.length === Object.keys(actual).length && keys.every((key) => Object.hasOwn(actual, key) && sameDescription(expected[key], actual[key]));
19
+ }
20
+ function responseUsage(value) {
21
+ const raw = object(value).usage;
22
+ if (raw === void 0) return void 0;
23
+ const source = object(raw);
24
+ const counters = {
25
+ ...source.input_tokens === void 0 ? {} : { inputTokens: source.input_tokens },
26
+ ...source.output_tokens === void 0 ? {} : { outputTokens: source.output_tokens }
27
+ };
28
+ const validated = validateUsageCounters(counters);
29
+ if (validated.invalidFields.length || validated.overflow) throw new ModelError("Invalid TypeSafe usage counters", MODEL_ERROR_CODES.MALFORMED_RESPONSE);
30
+ return validated.reported;
31
+ }
32
+ function sameArrayDescription(expected, actual) {
33
+ return Array.isArray(actual) && expected.length === actual.length && expected.every((value, index) => sameDescription(value, actual[index]));
34
+ }
35
+
36
+ //#endregion
37
+ //#region src/dispatch.ts
38
+ function dispatchTypesafe(host, request) {
39
+ return dispatchDecisionHttp({
40
+ ...host,
41
+ label: "TypeSafe",
42
+ readUsage: responseUsage
43
+ }, request);
44
+ }
45
+
46
+ //#endregion
47
+ //#region src/configuration.ts
7
48
  const CAPABILITIES = Object.freeze({
8
49
  questionTypes: Object.freeze([
9
50
  "choice",
@@ -22,19 +63,90 @@ const NULL_LOGGER = Object.freeze({
22
63
  error() {},
23
64
  fatal() {}
24
65
  });
25
- function object(value) {
26
- if (value === null || typeof value !== "object" || Array.isArray(value)) throw new ModelError("TypeSafe returned an invalid response object", MODEL_ERROR_CODES.MALFORMED_RESPONSE);
27
- return value;
66
+ function bound(value, fallback, name) {
67
+ const result = value ?? fallback;
68
+ if (!Number.isSafeInteger(result) || result <= 0 || result > 2147483647) throw new Error(`Invalid TypeSafe ${name}`);
69
+ return result;
28
70
  }
29
- /** Compare JSON rubric values without depending on object property order. */
30
- function sameDescription(expected, actual) {
31
- if (expected === actual) return true;
32
- if (expected === null || actual === null || typeof expected !== "object" || typeof actual !== "object") return false;
33
- if (Array.isArray(expected)) return Array.isArray(actual) && expected.length === actual.length && expected.every((value, index) => sameDescription(value, actual[index]));
34
- if (Array.isArray(actual)) return false;
35
- const keys = Object.keys(expected);
36
- return keys.length === Object.keys(actual).length && keys.every((key) => Object.hasOwn(actual, key) && sameDescription(expected[key], actual[key]));
71
+ function typesafeBaseUrl(options) {
72
+ const url = new URL(options.baseUrl ?? "https://api.typesafe.ai/v1");
73
+ if (url.username || url.password || url.search || url.hash || url.protocol !== "https:" && !(url.protocol === "http:" && options.allowInsecureHttp === true)) throw new Error("TypeSafe requires an HTTPS API root without credentials, query or fragment");
74
+ return url;
75
+ }
76
+ function captureCredential(input) {
77
+ if (typeof input === "string") return assertUsableApiKey(input, "TypeSafe", "apiKey");
78
+ else {
79
+ const source = input;
80
+ if (source?.kind !== "credential-source" || source.apiVersion !== CREDENTIAL_CAPABILITY_API_VERSION || typeof source.resolve !== "function") throw new Error("TypeSafe requires a compatible credential source");
81
+ const resolve = source.resolve.bind(source);
82
+ return async (signal, logger) => assertUsableApiKey(await resolve({
83
+ signal,
84
+ logger
85
+ }), "TypeSafe", "credential source");
86
+ }
87
+ }
88
+
89
+ //#endregion
90
+ //#region src/decode.ts
91
+ function decodeTypesafeResult(value, input) {
92
+ const raw = object(value);
93
+ const rawAnswers = object(raw.answers);
94
+ if (Object.keys(rawAnswers).length !== Object.keys(input.questions).length) throw new ModelError("Unexpected TypeSafe answer ids", MODEL_ERROR_CODES.MALFORMED_RESPONSE);
95
+ const answers = Object.create(null);
96
+ for (const [id, question] of Object.entries(input.questions)) {
97
+ if (!Object.hasOwn(rawAnswers, id)) throw new ModelError("Missing TypeSafe answer", MODEL_ERROR_CODES.MALFORMED_RESPONSE);
98
+ answers[id] = decodeAnswer(question, object(rawAnswers[id]));
99
+ }
100
+ const usage = responseUsage(raw);
101
+ return validateDecisionResult({
102
+ model: raw.model,
103
+ answers,
104
+ ...usage === void 0 ? {} : { usage }
105
+ }, input.questions);
106
+ }
107
+ function decodeAnswer(question, answer) {
108
+ const evidence = {
109
+ probabilitySource: "provider",
110
+ ...answer.confidence === void 0 ? {} : { confidence: answer.confidence }
111
+ };
112
+ switch (question.type) {
113
+ case "choice":
114
+ assertChoiceAnswer(answer);
115
+ return {
116
+ type: "choice",
117
+ choice: answer.choice,
118
+ probabilities: answer.probabilities,
119
+ ...evidence
120
+ };
121
+ case "score":
122
+ assertScoreAnswer(answer, question.levels);
123
+ return {
124
+ type: "score",
125
+ score: answer.score,
126
+ probabilities: answer.probabilities,
127
+ ...evidence
128
+ };
129
+ case "boolean":
130
+ if (answer.type !== "noul") throw new ModelError("Invalid TypeSafe boolean answer", MODEL_ERROR_CODES.MALFORMED_RESPONSE);
131
+ return {
132
+ type: "boolean",
133
+ value: answer.noul >= .5,
134
+ probabilityTrue: answer.noul,
135
+ probabilitySource: "provider"
136
+ };
137
+ }
138
+ }
139
+ function assertChoiceAnswer(answer) {
140
+ if (answer.type !== "choice" || answer.probabilities === void 0 || answer.confidence === void 0) throw new ModelError("Invalid TypeSafe choice answer", MODEL_ERROR_CODES.MALFORMED_RESPONSE);
37
141
  }
142
+ function assertScoreAnswer(answer, levels) {
143
+ if (answer.type !== "score" || answer.probabilities === void 0 || answer.confidence === void 0) throw new ModelError("Invalid TypeSafe score answer", MODEL_ERROR_CODES.MALFORMED_RESPONSE);
144
+ const legend = object(answer.legend);
145
+ if (Object.keys(legend).length !== levels.length || levels.some((level, i) => !Object.hasOwn(legend, String(i)) || !sameDescription(level, legend[String(i)]))) throw new ModelError("Invalid TypeSafe score legend", MODEL_ERROR_CODES.MALFORMED_RESPONSE);
146
+ }
147
+
148
+ //#endregion
149
+ //#region src/adapter.ts
38
150
  function capturePublicHeaders(source) {
39
151
  let headers;
40
152
  try {
@@ -56,67 +168,6 @@ function captureInvocationHeaders(context) {
56
168
  if (context?.providerOptions?.body !== void 0 && Object.keys(context.providerOptions.body).length) throw new ModelError("TypeSafe does not support providerOptions.body overrides", MODEL_ERROR_CODES.INVALID_REQUEST);
57
169
  return capturePublicHeaders(context?.providerOptions?.headers);
58
170
  }
59
- function bound(value, fallback, name) {
60
- const result = value ?? fallback;
61
- if (!Number.isSafeInteger(result) || result <= 0 || result > 2147483647) throw new Error(`Invalid TypeSafe ${name}`);
62
- return result;
63
- }
64
- function responseUsage(value) {
65
- const raw = object(value).usage;
66
- if (raw === void 0) return void 0;
67
- const source = object(raw);
68
- const counters = {
69
- ...source.input_tokens === void 0 ? {} : { inputTokens: source.input_tokens },
70
- ...source.output_tokens === void 0 ? {} : { outputTokens: source.output_tokens }
71
- };
72
- const validated = validateUsageCounters(counters);
73
- if (validated.invalidFields.length || validated.overflow) throw new ModelError("Invalid TypeSafe usage counters", MODEL_ERROR_CODES.MALFORMED_RESPONSE);
74
- return validated.reported;
75
- }
76
- function retryAfter(value) {
77
- if (value === null) return void 0;
78
- const seconds = Number(value);
79
- const delay = Number.isFinite(seconds) ? seconds * 1e3 : Date.parse(value) - Date.now();
80
- return Number.isFinite(delay) && delay > 0 ? delay : void 0;
81
- }
82
- function statusCode(status) {
83
- if (status === 401 || status === 403) return MODEL_ERROR_CODES.AUTH;
84
- if (status === 429) return MODEL_ERROR_CODES.RATE_LIMIT;
85
- if (status >= 500) return MODEL_ERROR_CODES.SERVER;
86
- return MODEL_ERROR_CODES.INVALID_REQUEST;
87
- }
88
- async function readJson(response, maxBytes, signal) {
89
- if (Number(response.headers.get("content-length")) > maxBytes) {
90
- response.body?.cancel().catch(() => {});
91
- throw new ModelError("TypeSafe response exceeds byte limit", MODEL_ERROR_CODES.MALFORMED_RESPONSE);
92
- }
93
- if (!response.body) throw new ModelError("TypeSafe returned an empty response", MODEL_ERROR_CODES.MALFORMED_RESPONSE);
94
- const reader = response.body.getReader();
95
- const decoder = new TextDecoder("utf-8", { fatal: true });
96
- let bytes = 0;
97
- let text = "";
98
- try {
99
- for (;;) {
100
- const item = await abortable(reader.read(), signal);
101
- if (item.done) break;
102
- bytes += item.value.byteLength;
103
- if (bytes > maxBytes) throw new ModelError("TypeSafe response exceeds byte limit", MODEL_ERROR_CODES.MALFORMED_RESPONSE);
104
- text += decoder.decode(item.value, { stream: true });
105
- }
106
- text += decoder.decode();
107
- try {
108
- return JSON.parse(text);
109
- } catch {
110
- throw new ModelError("TypeSafe returned invalid JSON", MODEL_ERROR_CODES.MALFORMED_RESPONSE);
111
- }
112
- } catch (error) {
113
- throwIfAborted(signal);
114
- if (error instanceof ModelError) throw error;
115
- throw new ModelError("TypeSafe returned an unreadable JSON response", MODEL_ERROR_CODES.MALFORMED_RESPONSE);
116
- } finally {
117
- reader.cancel().catch(() => {});
118
- }
119
- }
120
171
  var TypesafeDecisionAdapter = class extends DecisionAdapter {
121
172
  #baseUrl;
122
173
  #credential;
@@ -129,8 +180,7 @@ var TypesafeDecisionAdapter = class extends DecisionAdapter {
129
180
  #rubrics = /* @__PURE__ */ new WeakMap();
130
181
  constructor(options) {
131
182
  super();
132
- const url = new URL(options.baseUrl ?? "https://api.typesafe.ai/v1");
133
- if (url.username || url.password || url.search || url.hash || url.protocol !== "https:" && !(url.protocol === "http:" && options.allowInsecureHttp === true)) throw new Error("TypeSafe requires an HTTPS API root without credentials, query or fragment");
183
+ const url = typesafeBaseUrl(options);
134
184
  this.#baseUrl = url.href.replace(/\/$/, "");
135
185
  this.#fetch = options.fetch ?? globalThis.fetch;
136
186
  this.#headers = capturePublicHeaders(options.headers);
@@ -138,16 +188,7 @@ var TypesafeDecisionAdapter = class extends DecisionAdapter {
138
188
  this.#maxRequest = bound(options.maxRequestBytes, 2097152, "maxRequestBytes");
139
189
  this.#maxResponse = bound(options.maxResponseBytes, 4194304, "maxResponseBytes");
140
190
  this.#retry = options.retryPolicy === void 0 ? void 0 : resolveRetryPolicy(options.retryPolicy, "typesafe.retryPolicy");
141
- if (typeof options.apiKey === "string") this.#credential = assertUsableApiKey(options.apiKey, "TypeSafe", "apiKey");
142
- else {
143
- const source = options.apiKey;
144
- if (source?.kind !== "credential-source" || source.apiVersion !== CREDENTIAL_CAPABILITY_API_VERSION || typeof source.resolve !== "function") throw new Error("TypeSafe requires a compatible credential source");
145
- const resolve = source.resolve.bind(source);
146
- this.#credential = async (signal, logger) => assertUsableApiKey(await resolve({
147
- signal,
148
- logger
149
- }), "TypeSafe", "credential source");
150
- }
191
+ this.#credential = captureCredential(options.apiKey);
151
192
  }
152
193
  providerRetryPolicy() {
153
194
  return this.#retry;
@@ -177,7 +218,14 @@ var TypesafeDecisionAdapter = class extends DecisionAdapter {
177
218
  });
178
219
  }
179
220
  async listModels(provider, signal) {
180
- const models = object((await this.#dispatch(provider, "catalog", "models", void 0, signal)).value).models;
221
+ const result = await this.#dispatch({
222
+ provider,
223
+ model: "catalog",
224
+ path: "models",
225
+ body: void 0,
226
+ ...signal === void 0 ? {} : { callerSignal: signal }
227
+ });
228
+ const models = object(result.value).models;
181
229
  if (!Array.isArray(models) || models.length > 1024) throw new ModelError("Invalid TypeSafe model catalog", MODEL_ERROR_CODES.MALFORMED_RESPONSE);
182
230
  return Object.freeze(models.map((entry) => {
183
231
  const info = object(entry);
@@ -233,184 +281,32 @@ var TypesafeDecisionAdapter = class extends DecisionAdapter {
233
281
  }
234
282
  async #evaluate(captured, context) {
235
283
  const { input, wire, timeout, provider, model } = captured;
236
- const response = await this.#dispatch(provider, model, "systemone", wire, input.signal, context, (value) => {
237
- const raw = object(value);
238
- const rawAnswers = object(raw.answers);
239
- if (Object.keys(rawAnswers).length !== Object.keys(input.questions).length) throw new ModelError("Unexpected TypeSafe answer ids", MODEL_ERROR_CODES.MALFORMED_RESPONSE);
240
- const answers = Object.create(null);
241
- for (const [id, question] of Object.entries(input.questions)) {
242
- if (!Object.hasOwn(rawAnswers, id)) throw new ModelError("Missing TypeSafe answer", MODEL_ERROR_CODES.MALFORMED_RESPONSE);
243
- const answer = object(rawAnswers[id]);
244
- const evidence = {
245
- probabilitySource: "provider",
246
- ...answer.confidence === void 0 ? {} : { confidence: answer.confidence }
247
- };
248
- switch (question.type) {
249
- case "choice":
250
- if (answer.type !== "choice" || answer.probabilities === void 0 || answer.confidence === void 0) throw new ModelError("Invalid TypeSafe choice answer", MODEL_ERROR_CODES.MALFORMED_RESPONSE);
251
- answers[id] = {
252
- type: "choice",
253
- choice: answer.choice,
254
- probabilities: answer.probabilities,
255
- ...evidence
256
- };
257
- break;
258
- case "score": {
259
- if (answer.type !== "score" || answer.probabilities === void 0 || answer.confidence === void 0) throw new ModelError("Invalid TypeSafe score answer", MODEL_ERROR_CODES.MALFORMED_RESPONSE);
260
- const legend = object(answer.legend);
261
- if (Object.keys(legend).length !== question.levels.length || question.levels.some((level, i) => !Object.hasOwn(legend, String(i)) || !sameDescription(level, legend[String(i)]))) throw new ModelError("Invalid TypeSafe score legend", MODEL_ERROR_CODES.MALFORMED_RESPONSE);
262
- answers[id] = {
263
- type: "score",
264
- score: answer.score,
265
- probabilities: answer.probabilities,
266
- ...evidence
267
- };
268
- break;
269
- }
270
- case "boolean":
271
- if (answer.type !== "noul") throw new ModelError("Invalid TypeSafe boolean answer", MODEL_ERROR_CODES.MALFORMED_RESPONSE);
272
- answers[id] = {
273
- type: "boolean",
274
- value: answer.noul >= .5,
275
- probabilityTrue: answer.noul,
276
- probabilitySource: "provider"
277
- };
278
- }
279
- }
280
- const usage = responseUsage(raw);
281
- return validateDecisionResult({
282
- model: raw.model,
283
- answers,
284
- ...usage === void 0 ? {} : { usage }
285
- }, input.questions);
286
- }, timeout, captured.headers);
284
+ const response = await this.#dispatch({
285
+ provider,
286
+ model,
287
+ path: "systemone",
288
+ body: wire,
289
+ ...input.signal === void 0 ? {} : { callerSignal: input.signal },
290
+ ...context === void 0 ? {} : { context },
291
+ decode: (value) => decodeTypesafeResult(value, input),
292
+ timeout,
293
+ publicHeaders: captured.headers
294
+ });
287
295
  const result = response.value;
288
296
  return response.requestId === void 0 ? result : validateDecisionResult({
289
297
  ...result,
290
298
  providerRequestId: response.requestId
291
299
  }, input.questions);
292
300
  }
293
- async #dispatch(provider, model, path, body, callerSignal, context, decode, timeout = this.#timeout, publicHeaders = {}) {
294
- const controller = new AbortController();
295
- const forward = () => controller.abort(callerSignal?.reason ?? new ModelError("TypeSafe call aborted", MODEL_ERROR_CODES.ABORTED));
296
- callerSignal?.addEventListener("abort", forward, { once: true });
297
- if (callerSignal?.aborted) forward();
298
- const timer = setTimeout(() => controller.abort(new ModelError("TypeSafe request timed out", MODEL_ERROR_CODES.TIMEOUT)), timeout);
299
- const signal = controller.signal;
300
- let attempt;
301
- let response;
302
- let sent = false;
303
- let requestId;
304
- let reportedUsage;
305
- const endAttempt = (input) => {
306
- const handle = attempt;
307
- attempt = void 0;
308
- handle?.end(input);
309
- };
310
- try {
311
- throwIfAborted(signal);
312
- const credential = this.#credential;
313
- const key = typeof credential === "string" ? credential : await abortable(credential(signal, context?.logger ?? NULL_LOGGER), signal);
314
- throwIfAborted(signal);
315
- const url = `${this.#baseUrl}/${path}`;
316
- context?.declareProviderAttemptAccounting?.();
317
- attempt = await abortable(Promise.resolve(context?.startProviderAttempt?.({
318
- provider,
319
- model,
320
- method: body === void 0 ? "GET" : "POST",
321
- origin: new URL(url).origin
322
- }, signal)).then((handle) => {
323
- if (signal.aborted) handle?.end({
324
- status: "aborted",
325
- dispatchState: "not-sent"
326
- });
327
- return handle;
328
- }), signal);
329
- throwIfAborted(signal);
330
- const headers = new Headers({
331
- ...this.#headers,
332
- ...publicHeaders,
333
- ...attributionHeaders(),
334
- authorization: `Bearer ${key}`,
335
- accept: "application/json",
336
- "content-type": "application/json"
337
- });
338
- if (attempt) headers.set("traceparent", attempt.traceparent);
339
- response = await abortable(Promise.resolve().then(() => {
340
- throwIfAborted(signal);
341
- sent = true;
342
- return this.#fetch(url, {
343
- method: body === void 0 ? "GET" : "POST",
344
- headers,
345
- ...body === void 0 ? {} : { body },
346
- signal,
347
- redirect: "error"
348
- });
349
- }).then((result) => {
350
- if (signal.aborted) result.body?.cancel().catch(() => {});
351
- return result;
352
- }).catch(() => {
353
- throwIfAborted(signal);
354
- throw new ModelError("TypeSafe transport failed", MODEL_ERROR_CODES.TRANSPORT);
355
- }), signal);
356
- const headerId = response.headers.get("x-request-id") ?? response.headers.get("request-id");
357
- requestId = headerId && headerId.length <= 256 ? headerId : void 0;
358
- if (!response.ok) {
359
- response.body?.cancel().catch(() => {});
360
- const delay = retryAfter(response.headers.get("retry-after"));
361
- throw new ModelError(`TypeSafe HTTP request failed (${response.status})`, statusCode(response.status), {
362
- status: response.status,
363
- ...delay === void 0 ? {} : { providerRetryAfterMs: delay },
364
- ...requestId === void 0 ? {} : { requestId: ProviderRequestId(requestId) }
365
- });
366
- }
367
- const json = await readJson(response, this.#maxResponse, signal);
368
- if (decode !== void 0) reportedUsage = responseUsage(json);
369
- const value = decode ? decode(json) : json;
370
- throwIfAborted(signal);
371
- const usage = reportedUsage;
372
- endAttempt({
373
- status: "success",
374
- dispatchState: "sent",
375
- httpStatus: response.status,
376
- ...requestId === void 0 ? {} : { providerRequestId: requestId },
377
- ...usage === void 0 ? {} : {
378
- reported: usage,
379
- usageFinal: true
380
- }
381
- });
382
- return {
383
- value,
384
- ...requestId === void 0 ? {} : { requestId }
385
- };
386
- } catch (error) {
387
- let failure = error;
388
- if (signal.aborted) try {
389
- throwIfAborted(signal);
390
- } catch (aborted) {
391
- failure = aborted;
392
- }
393
- const normalized = normalizeModelFailure(failure);
394
- endAttempt({
395
- status: normalized.code === MODEL_ERROR_CODES.ABORTED ? "aborted" : "error",
396
- dispatchState: sent ? "sent" : "not-sent",
397
- ...response === void 0 ? {} : { httpStatus: response.status },
398
- ...requestId === void 0 ? {} : { providerRequestId: requestId },
399
- ...reportedUsage === void 0 ? {} : {
400
- reported: reportedUsage,
401
- usageFinal: true
402
- },
403
- error: {
404
- type: "ModelError",
405
- message: "TypeSafe request failed",
406
- code: normalized.code
407
- }
408
- });
409
- throw failure;
410
- } finally {
411
- clearTimeout(timer);
412
- callerSignal?.removeEventListener("abort", forward);
413
- }
301
+ async #dispatch(request) {
302
+ return dispatchTypesafe({
303
+ baseUrl: this.#baseUrl,
304
+ credential: this.#credential,
305
+ fetch: this.#fetch,
306
+ headers: this.#headers,
307
+ maxResponse: this.#maxResponse,
308
+ timeout: this.#timeout
309
+ }, request);
414
310
  }
415
311
  };
416
312
  function typesafeAdapter(options) {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/adapter.ts"],"sourcesContent":["import { assertUsableApiKey, attributionHeaders, ModelError, MODEL_ERROR_CODES, normalizeModelFailure, ProviderRequestId, resolveRetryPolicy, validateUsageCounters, type UsageCounters } from '@alvin0/ai-agent-sdk-core'\nimport { CREDENTIAL_CAPABILITY_API_VERSION, type CredentialInput, type EndProviderAttemptInput, type ModelInvocationContext, type ProviderAttemptHandle, type RetryPolicyConfig, type SdkLogger } from '@alvin0/ai-agent-sdk-core/provider'\nimport { DecisionAdapter, defineDecisionProviderPlugin, snapshotDecisionInput, validateDecisionResult, type DecisionAnswer, type DecisionInput, type DecisionModelInfo, type DecisionProviderPlugin, type DecisionRequest, type DecisionResult, type PreparedDecisionCall } from '@alvin0/ai-agent-sdk-decision-adapter'\nimport { abortable, throwIfAborted } from '@alvin0/ai-agent-sdk-decision-adapter/transport'\n\nconst CAPABILITIES = Object.freeze({ questionTypes: Object.freeze(['choice', 'score', 'boolean'] as const), maxChoiceOptions: 255, maxScoreLevels: 10 })\nconst NULL_LOGGER: SdkLogger = Object.freeze({ child: () => NULL_LOGGER, trace() {}, debug() {}, info() {}, warn() {}, error() {}, fatal() {} })\ninterface CapturedTypesafeRequest { readonly input: DecisionInput; readonly wire: string; readonly timeout: number; readonly provider: string; readonly model: string; readonly headers: Readonly<Record<string, string>> }\nexport interface TypesafeAdapterOptions {\n readonly apiKey: CredentialInput\n /** API root including /v1. Default: https://api.typesafe.ai/v1 */\n readonly baseUrl?: string | URL\n readonly fetch?: typeof globalThis.fetch\n readonly headers?: Readonly<Record<string, string>>\n readonly requestTimeoutMs?: number\n readonly maxRequestBytes?: number\n readonly maxResponseBytes?: number\n readonly retryPolicy?: RetryPolicyConfig\n /** For explicitly configured development endpoints only. */\n readonly allowInsecureHttp?: boolean\n}\nexport interface TypesafePluginOptions extends TypesafeAdapterOptions {\n readonly id?: string\n readonly routes?: readonly string[]\n}\nfunction object(value: unknown): Record<string, unknown> {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) throw new ModelError('TypeSafe returned an invalid response object', MODEL_ERROR_CODES.MALFORMED_RESPONSE)\n return value as Record<string, unknown>\n}\n/** Compare JSON rubric values without depending on object property order. */\nfunction sameDescription(expected: unknown, actual: unknown): boolean {\n if (expected === actual) return true\n if (expected === null || actual === null || typeof expected !== 'object' || typeof actual !== 'object') return false\n if (Array.isArray(expected)) return Array.isArray(actual) && expected.length === actual.length && expected.every((value, index) => sameDescription(value, actual[index]))\n if (Array.isArray(actual)) return false\n const keys = Object.keys(expected)\n return keys.length === Object.keys(actual).length && keys.every(key => Object.hasOwn(actual, key) && sameDescription((expected as Record<string, unknown>)[key], (actual as Record<string, unknown>)[key]))\n}\nfunction capturePublicHeaders(source: Readonly<Record<string, string>> | undefined): Readonly<Record<string, string>> {\n let headers: Readonly<Record<string, string>>\n try { headers = Object.freeze(Object.fromEntries(new Headers(source).entries())) }\n catch { throw new ModelError('Invalid TypeSafe custom headers', MODEL_ERROR_CODES.INVALID_REQUEST) }\n for (const key of Object.keys(headers)) {\n if (['authorization', 'content-type', 'accept', 'host', 'content-length', 'traceparent'].includes(key)) throw new ModelError('TypeSafe custom headers cannot override transport headers', MODEL_ERROR_CODES.INVALID_REQUEST)\n }\n return headers\n}\nfunction captureInvocationHeaders(context?: ModelInvocationContext): Readonly<Record<string, string>> {\n if (context?.providerOptions?.body !== undefined && Object.keys(context.providerOptions.body).length) throw new ModelError('TypeSafe does not support providerOptions.body overrides', MODEL_ERROR_CODES.INVALID_REQUEST)\n return capturePublicHeaders(context?.providerOptions?.headers)\n}\nfunction bound(value: number | undefined, fallback: number, name: string): number {\n const result = value ?? fallback\n if (!Number.isSafeInteger(result) || result <= 0 || result > 2_147_483_647) throw new Error(`Invalid TypeSafe ${name}`)\n return result\n}\nfunction responseUsage(value: unknown): UsageCounters | undefined {\n const raw = object(value).usage\n if (raw === undefined) return undefined\n const source = object(raw)\n const counters = {\n ...(source.input_tokens === undefined ? {} : { inputTokens: source.input_tokens }),\n ...(source.output_tokens === undefined ? {} : { outputTokens: source.output_tokens }),\n }\n const validated = validateUsageCounters(counters)\n if (validated.invalidFields.length || validated.overflow) throw new ModelError('Invalid TypeSafe usage counters', MODEL_ERROR_CODES.MALFORMED_RESPONSE)\n return validated.reported\n}\nfunction retryAfter(value: string | null): number | undefined {\n if (value === null) return undefined\n const seconds = Number(value)\n const delay = Number.isFinite(seconds) ? seconds * 1_000 : Date.parse(value) - Date.now()\n return Number.isFinite(delay) && delay > 0 ? delay : undefined\n}\nfunction statusCode(status: number): string {\n if (status === 401 || status === 403) return MODEL_ERROR_CODES.AUTH\n if (status === 429) return MODEL_ERROR_CODES.RATE_LIMIT\n if (status >= 500) return MODEL_ERROR_CODES.SERVER\n return MODEL_ERROR_CODES.INVALID_REQUEST\n}\nasync function readJson(response: Response, maxBytes: number, signal: AbortSignal): Promise<unknown> {\n const length = Number(response.headers.get('content-length'))\n if (length > maxBytes) {\n void response.body?.cancel().catch(() => {})\n throw new ModelError('TypeSafe response exceeds byte limit', MODEL_ERROR_CODES.MALFORMED_RESPONSE)\n }\n if (!response.body) throw new ModelError('TypeSafe returned an empty response', MODEL_ERROR_CODES.MALFORMED_RESPONSE)\n const reader = response.body.getReader()\n const decoder = new TextDecoder('utf-8', { fatal: true })\n let bytes = 0\n let text = ''\n try {\n for (;;) {\n const item = await abortable(reader.read(), signal)\n if (item.done) break\n bytes += item.value.byteLength\n if (bytes > maxBytes) throw new ModelError('TypeSafe response exceeds byte limit', MODEL_ERROR_CODES.MALFORMED_RESPONSE)\n text += decoder.decode(item.value, { stream: true })\n }\n text += decoder.decode()\n try { return JSON.parse(text) as unknown }\n catch { throw new ModelError('TypeSafe returned invalid JSON', MODEL_ERROR_CODES.MALFORMED_RESPONSE) }\n } catch (error) {\n throwIfAborted(signal)\n if (error instanceof ModelError) throw error\n throw new ModelError('TypeSafe returned an unreadable JSON response', MODEL_ERROR_CODES.MALFORMED_RESPONSE)\n } finally {\n // Do not wait indefinitely for a foreign stream's cancellation hook.\n void reader.cancel().catch(() => {})\n }\n}\nclass TypesafeDecisionAdapter extends DecisionAdapter {\n readonly #baseUrl: string\n readonly #credential: string | ((signal: AbortSignal, logger: SdkLogger) => Promise<string>)\n readonly #fetch: typeof globalThis.fetch\n readonly #headers: Readonly<Record<string, string>>\n readonly #timeout: number\n readonly #maxRequest: number\n readonly #maxResponse: number\n readonly #retry: ReturnType<typeof resolveRetryPolicy> | undefined\n readonly #rubrics = new WeakMap<DecisionInput['questions'], string>()\n constructor(options: TypesafeAdapterOptions) {\n super()\n const url = new URL(options.baseUrl ?? 'https://api.typesafe.ai/v1')\n if (url.username || url.password || url.search || url.hash || (url.protocol !== 'https:' && !(url.protocol === 'http:' && options.allowInsecureHttp === true))) throw new Error('TypeSafe requires an HTTPS API root without credentials, query or fragment')\n this.#baseUrl = url.href.replace(/\\/$/, '')\n this.#fetch = options.fetch ?? globalThis.fetch\n this.#headers = capturePublicHeaders(options.headers)\n this.#timeout = bound(options.requestTimeoutMs, 30_000, 'requestTimeoutMs')\n this.#maxRequest = bound(options.maxRequestBytes, 2_097_152, 'maxRequestBytes')\n this.#maxResponse = bound(options.maxResponseBytes, 4_194_304, 'maxResponseBytes')\n this.#retry = options.retryPolicy === undefined ? undefined : resolveRetryPolicy(options.retryPolicy, 'typesafe.retryPolicy')\n if (typeof options.apiKey === 'string') this.#credential = assertUsableApiKey(options.apiKey, 'TypeSafe', 'apiKey')\n else {\n const source = options.apiKey\n if (source?.kind !== 'credential-source' || source.apiVersion !== CREDENTIAL_CAPABILITY_API_VERSION || typeof source.resolve !== 'function') throw new Error('TypeSafe requires a compatible credential source')\n const resolve = source.resolve.bind(source)\n this.#credential = async (signal, logger) => assertUsableApiKey(await resolve({ signal, logger }), 'TypeSafe', 'credential source')\n }\n }\n override providerRetryPolicy(): ReturnType<typeof resolveRetryPolicy> | undefined { return this.#retry }\n override async resolveModel(provider: string, model: string): Promise<DecisionModelInfo> {\n return Object.freeze({ provider, id: model, name: model, capabilities: CAPABILITIES })\n }\n override async prepareDecisionCall(provider: string, model: string, _signal?: AbortSignal, context?: ModelInvocationContext): Promise<PreparedDecisionCall> {\n const headers = captureInvocationHeaders(context)\n let captured: { readonly request: DecisionRequest; readonly value: CapturedTypesafeRequest } | undefined\n return Object.freeze({ model: await this.resolveModel(provider, model), evaluate: (request: DecisionRequest, invocation = context) => {\n if (request.provider !== provider || request.model !== model) throw new ModelError('Prepared TypeSafe decision target does not match request', MODEL_ERROR_CODES.INVALID_REQUEST)\n if (captured && captured.request !== request) throw new ModelError('Prepared TypeSafe decision call cannot dispatch a different request', MODEL_ERROR_CODES.INVALID_REQUEST)\n captured ??= { request, value: this.#capture(request, invocation === context ? headers : captureInvocationHeaders(invocation)) }\n return this.#evaluate(captured.value, invocation)\n } })\n }\n override async listModels(provider: string, signal?: AbortSignal): Promise<readonly DecisionModelInfo[]> {\n const result = await this.#dispatch(provider, 'catalog', 'models', undefined, signal)\n const models = object(result.value).models\n if (!Array.isArray(models) || models.length > 1_024) throw new ModelError('Invalid TypeSafe model catalog', MODEL_ERROR_CODES.MALFORMED_RESPONSE)\n return Object.freeze(models.map(entry => {\n const info = object(entry)\n if (typeof info.name !== 'string' || !info.name.trim() || info.name.length > 256) throw new ModelError('Invalid TypeSafe model id', MODEL_ERROR_CODES.MALFORMED_RESPONSE)\n return Object.freeze({ provider, id: info.name, name: info.name, capabilities: CAPABILITIES })\n }))\n }\n override async evaluate(request: DecisionRequest, context?: ModelInvocationContext): Promise<DecisionResult> {\n return this.#evaluate(this.#capture(request, captureInvocationHeaders(context)), context)\n }\n #capture(request: DecisionRequest, headers: Readonly<Record<string, string>>): CapturedTypesafeRequest {\n if (typeof request.provider !== 'string' || !request.provider.trim() || typeof request.model !== 'string' || !request.model.trim()) throw new ModelError('TypeSafe requires provider and model identifiers', MODEL_ERROR_CODES.INVALID_REQUEST)\n const input = snapshotDecisionInput(request, CAPABILITIES)\n const timeout = Math.min(this.#timeout, input.timeoutMs ?? this.#timeout)\n let questions = this.#rubrics.get(input.questions)\n if (questions === undefined) {\n questions = JSON.stringify(Object.fromEntries(Object.entries(input.questions).map(([id, question]) => {\n switch (question.type) {\n case 'choice': return [id, { type: 'choice', instructions: question.instructions, criteria: question.options }]\n case 'score': return [id, { type: 'score', instructions: question.instructions, criteria: question.levels }]\n case 'boolean': return [id, { type: 'noul', instructions: question.instructions, ...(question.criteria === undefined ? {} : { criteria: question.criteria }) }]\n }\n })))\n this.#rubrics.set(input.questions, questions)\n }\n const wire = `{\"questions\":${questions},\"model\":${JSON.stringify(request.model)},\"state\":${JSON.stringify(input.state)}}`\n if (new TextEncoder().encode(wire).byteLength > this.#maxRequest) throw new ModelError('TypeSafe request exceeds byte limit', MODEL_ERROR_CODES.INVALID_REQUEST)\n return { input, wire, timeout, provider: request.provider, model: request.model, headers }\n }\n async #evaluate(captured: CapturedTypesafeRequest, context?: ModelInvocationContext): Promise<DecisionResult> {\n const { input, wire, timeout, provider, model } = captured\n const response = await this.#dispatch(provider, model, 'systemone', wire, input.signal, context, value => {\n const raw = object(value)\n const rawAnswers = object(raw.answers)\n // Validate wire identifiers/types BEFORE projecting, so surplus answers cannot disappear.\n if (Object.keys(rawAnswers).length !== Object.keys(input.questions).length) throw new ModelError('Unexpected TypeSafe answer ids', MODEL_ERROR_CODES.MALFORMED_RESPONSE)\n const answers: Record<string, DecisionAnswer> = Object.create(null) as Record<string, DecisionAnswer>\n for (const [id, question] of Object.entries(input.questions)) {\n if (!Object.hasOwn(rawAnswers, id)) throw new ModelError('Missing TypeSafe answer', MODEL_ERROR_CODES.MALFORMED_RESPONSE)\n const answer = object(rawAnswers[id])\n const evidence = { probabilitySource: 'provider' as const, ...(answer.confidence === undefined ? {} : { confidence: answer.confidence as number }) }\n switch (question.type) {\n case 'choice':\n if (answer.type !== 'choice' || answer.probabilities === undefined || answer.confidence === undefined) throw new ModelError('Invalid TypeSafe choice answer', MODEL_ERROR_CODES.MALFORMED_RESPONSE)\n answers[id] = { type: 'choice', choice: answer.choice as string, probabilities: answer.probabilities as Record<string, number>, ...evidence }\n break\n case 'score': {\n if (answer.type !== 'score' || answer.probabilities === undefined || answer.confidence === undefined) throw new ModelError('Invalid TypeSafe score answer', MODEL_ERROR_CODES.MALFORMED_RESPONSE)\n const legend = object(answer.legend)\n if (Object.keys(legend).length !== question.levels.length || question.levels.some((level, i) => !Object.hasOwn(legend, String(i)) || !sameDescription(level, legend[String(i)]))) throw new ModelError('Invalid TypeSafe score legend', MODEL_ERROR_CODES.MALFORMED_RESPONSE)\n answers[id] = { type: 'score', score: answer.score as number, probabilities: answer.probabilities as Record<string, number>, ...evidence }\n break\n }\n case 'boolean':\n if (answer.type !== 'noul') throw new ModelError('Invalid TypeSafe boolean answer', MODEL_ERROR_CODES.MALFORMED_RESPONSE)\n answers[id] = { type: 'boolean', value: (answer.noul as number) >= 0.5, probabilityTrue: answer.noul as number, probabilitySource: 'provider' }\n break\n }\n }\n const usage = responseUsage(raw)\n return validateDecisionResult({\n model: raw.model, answers,\n ...(usage === undefined ? {} : { usage }),\n }, input.questions)\n }, timeout, captured.headers)\n const result = response.value as DecisionResult\n return response.requestId === undefined ? result : validateDecisionResult({ ...result, providerRequestId: response.requestId }, input.questions)\n }\n async #dispatch(provider: string, model: string, path: string, body: string | undefined, callerSignal?: AbortSignal, context?: ModelInvocationContext, decode?: (value: unknown) => DecisionResult, timeout = this.#timeout, publicHeaders: Readonly<Record<string, string>> = {}): Promise<{ value: unknown; requestId?: string }> {\n const controller = new AbortController()\n const forward = () => controller.abort(callerSignal?.reason ?? new ModelError('TypeSafe call aborted', MODEL_ERROR_CODES.ABORTED))\n callerSignal?.addEventListener('abort', forward, { once: true })\n if (callerSignal?.aborted) forward()\n const timer = setTimeout(() => controller.abort(new ModelError('TypeSafe request timed out', MODEL_ERROR_CODES.TIMEOUT)), timeout)\n const signal = controller.signal\n let attempt: ProviderAttemptHandle | undefined\n let response: Response | undefined\n let sent = false\n let requestId: string | undefined\n let reportedUsage: UsageCounters | undefined\n const endAttempt = (input: EndProviderAttemptInput) => {\n // Consume ownership before extension code: a throwing sink must not be called again.\n const handle = attempt\n attempt = undefined\n handle?.end(input)\n }\n try {\n throwIfAborted(signal)\n const credential = this.#credential\n const key = typeof credential === 'string' ? credential : await abortable(credential(signal, context?.logger ?? NULL_LOGGER), signal)\n throwIfAborted(signal)\n const url = `${this.#baseUrl}/${path}`\n context?.declareProviderAttemptAccounting?.()\n attempt = await abortable(Promise.resolve(context?.startProviderAttempt?.({ provider, model, method: body === undefined ? 'GET' : 'POST', origin: new URL(url).origin }, signal)).then(handle => {\n if (signal.aborted) handle?.end({ status: 'aborted', dispatchState: 'not-sent' })\n return handle\n }), signal)\n throwIfAborted(signal)\n const headers = new Headers({ ...this.#headers, ...publicHeaders, ...attributionHeaders(), authorization: `Bearer ${key}`, accept: 'application/json', 'content-type': 'application/json' })\n if (attempt) headers.set('traceparent', attempt.traceparent)\n const received = await abortable<Response>(Promise.resolve().then(() => {\n throwIfAborted(signal)\n sent = true\n return this.#fetch(url, { method: body === undefined ? 'GET' : 'POST', headers, ...(body === undefined ? {} : { body }), signal, redirect: 'error' })\n }).then(result => {\n if (signal.aborted) void result.body?.cancel().catch(() => {})\n return result\n }).catch(() => {\n throwIfAborted(signal)\n throw new ModelError('TypeSafe transport failed', MODEL_ERROR_CODES.TRANSPORT)\n }), signal)\n response = received\n const headerId = response.headers.get('x-request-id') ?? response.headers.get('request-id')\n requestId = headerId && headerId.length <= 256 ? headerId : undefined\n if (!response.ok) {\n void response.body?.cancel().catch(() => {})\n const delay = retryAfter(response.headers.get('retry-after'))\n throw new ModelError(`TypeSafe HTTP request failed (${response.status})`, statusCode(response.status), { status: response.status, ...(delay === undefined ? {} : { providerRetryAfterMs: delay }), ...(requestId === undefined ? {} : { requestId: ProviderRequestId(requestId) }) })\n }\n const json = await readJson(response, this.#maxResponse, signal)\n // Usage is billable evidence even when the decision answers are malformed.\n if (decode !== undefined) reportedUsage = responseUsage(json)\n const value = decode ? decode(json) : json\n throwIfAborted(signal)\n const usage = reportedUsage\n endAttempt({ status: 'success', dispatchState: 'sent', httpStatus: response.status, ...(requestId === undefined ? {} : { providerRequestId: requestId }), ...(usage === undefined ? {} : { reported: usage, usageFinal: true }) })\n return { value, ...(requestId === undefined ? {} : { requestId }) }\n } catch (error) {\n let failure: unknown = error\n if (signal.aborted) { try { throwIfAborted(signal) } catch (aborted) { failure = aborted } }\n const normalized = normalizeModelFailure(failure)\n endAttempt({ status: normalized.code === MODEL_ERROR_CODES.ABORTED ? 'aborted' : 'error', dispatchState: sent ? 'sent' : 'not-sent', ...(response === undefined ? {} : { httpStatus: response.status }), ...(requestId === undefined ? {} : { providerRequestId: requestId }), ...(reportedUsage === undefined ? {} : { reported: reportedUsage, usageFinal: true }), error: { type: 'ModelError', message: 'TypeSafe request failed', code: normalized.code } })\n throw failure\n } finally {\n clearTimeout(timer)\n callerSignal?.removeEventListener('abort', forward)\n }\n }\n}\nexport function typesafeAdapter(options: TypesafeAdapterOptions): DecisionAdapter { return new TypesafeDecisionAdapter(options) }\nexport function typesafePlugin(options: TypesafePluginOptions): DecisionProviderPlugin {\n const adapter = typesafeAdapter(options)\n const routes = Object.freeze([...(options.routes ?? ['typesafe'])])\n return defineDecisionProviderPlugin({ id: options.id ?? 'typesafe', routes, setup(registrar) { const registration = registrar.registerAdapter(routes, adapter); return () => registration.dispose() } })\n}\n"],"mappings":";;;;;;AAKA,MAAM,eAAe,OAAO,OAAO;CAAE,eAAe,OAAO,OAAO;EAAC;EAAU;EAAS;CAAS,CAAU;CAAG,kBAAkB;CAAK,gBAAgB;AAAG,CAAC;AACvJ,MAAM,cAAyB,OAAO,OAAO;CAAE,aAAa;CAAa,QAAQ,CAAC;CAAG,QAAQ,CAAC;CAAG,OAAO,CAAC;CAAG,OAAO,CAAC;CAAG,QAAQ,CAAC;CAAG,QAAQ,CAAC;AAAE,CAAC;AAmB/I,SAAS,OAAO,OAAyC;CACvD,IAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GAAG,MAAM,IAAI,WAAW,gDAAgD,kBAAkB,kBAAkB;CACl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eAAe,SAAwD;CACrF,MAAM,UAAU,gBAAgB,OAAO;CACvC,MAAM,SAAS,OAAO,OAAO,CAAC,GAAI,QAAQ,UAAU,CAAC,UAAU,CAAE,CAAC;CAClE,OAAO,6BAA6B;EAAE,IAAI,QAAQ,MAAM;EAAY;EAAQ,MAAM,WAAW;GAAE,MAAM,eAAe,UAAU,gBAAgB,QAAQ,OAAO;GAAG,aAAa,aAAa,QAAQ;EAAE;CAAE,CAAC;AACzM"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/response.ts","../src/dispatch.ts","../src/configuration.ts","../src/decode.ts","../src/adapter.ts"],"sourcesContent":["import { ModelError, MODEL_ERROR_CODES, validateUsageCounters, type UsageCounters } from '@alvin0/ai-agent-sdk-core'\n\nexport function object(value: unknown): Record<string, unknown> {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) throw new ModelError(\n 'TypeSafe returned an invalid response object', MODEL_ERROR_CODES.MALFORMED_RESPONSE)\n return value as Record<string, unknown>\n}\n\n/** Compare JSON rubric values without depending on object property order. */\nexport function sameDescription(expected: unknown, actual: unknown): boolean {\n if (expected === actual) return true\n if (expected === null || actual === null || typeof expected !== 'object' || typeof actual !== 'object') return false\n if (Array.isArray(expected)) return sameArrayDescription(expected, actual)\n if (Array.isArray(actual)) return false\n const keys = Object.keys(expected)\n return keys.length === Object.keys(actual).length && keys.every(key => Object.hasOwn(actual, key) &&\n sameDescription((expected as Record<string, unknown>)[key], (actual as Record<string, unknown>)[key]))\n}\n\nexport function responseUsage(value: unknown): UsageCounters | undefined {\n const raw = object(value).usage\n if (raw === undefined) return undefined\n const source = object(raw)\n const counters = {\n ...(source.input_tokens === undefined ? {} : { inputTokens: source.input_tokens }),\n ...(source.output_tokens === undefined ? {} : { outputTokens: source.output_tokens }),\n }\n const validated = validateUsageCounters(counters)\n if (validated.invalidFields.length || validated.overflow) throw new ModelError(\n 'Invalid TypeSafe usage counters', MODEL_ERROR_CODES.MALFORMED_RESPONSE)\n return validated.reported\n}\n\n\nfunction sameArrayDescription(expected: readonly unknown[], actual: unknown): boolean {\n return Array.isArray(actual) && expected.length === actual.length\n && expected.every((value, index) => sameDescription(value, actual[index]))\n}\n","import { dispatchDecisionHttp, type DecisionHttpHost, type DecisionHttpRequest }\n from '@alvin0/ai-agent-sdk-decision-adapter/transport'\nimport { responseUsage } from './response.ts'\n\nexport type TypesafeDispatchHost = Omit<DecisionHttpHost, 'label' | 'readUsage'>\nexport type TypesafeDispatchRequest = DecisionHttpRequest\n\nexport function dispatchTypesafe(host: TypesafeDispatchHost, request: TypesafeDispatchRequest) {\n return dispatchDecisionHttp({ ...host, label: 'TypeSafe', readUsage: responseUsage }, request)\n}\n","import { assertUsableApiKey } from '@alvin0/ai-agent-sdk-core'\nimport {\n CREDENTIAL_CAPABILITY_API_VERSION, type CredentialInput, type SdkLogger,\n} from '@alvin0/ai-agent-sdk-core/provider'\nimport type { TypesafeAdapterOptions } from './types.ts'\n\nexport const CAPABILITIES = Object.freeze({\n questionTypes: Object.freeze(['choice', 'score', 'boolean'] as const),\n maxChoiceOptions: 255,\n maxScoreLevels: 10,\n})\nexport const NULL_LOGGER: SdkLogger = Object.freeze({\n child: () => NULL_LOGGER,\n trace() {}, debug() {}, info() {}, warn() {}, error() {}, fatal() {},\n})\n\nexport function bound(value: number | undefined, fallback: number, name: string): number {\n const result = value ?? fallback\n if (!Number.isSafeInteger(result) || result <= 0 || result > 2_147_483_647) throw new Error(\n `Invalid TypeSafe ${name}`)\n return result\n}\n\nexport function typesafeBaseUrl(options: TypesafeAdapterOptions): URL {\n const url = new URL(options.baseUrl ?? 'https://api.typesafe.ai/v1')\n if (url.username || url.password || url.search || url.hash || (url.protocol !== 'https:' && !(\n url.protocol === 'http:' && options.allowInsecureHttp === true))) throw new Error(\n 'TypeSafe requires an HTTPS API root without credentials, query or fragment')\n return url\n}\n\nexport function captureCredential(\n input: CredentialInput,\n): string | ((signal: AbortSignal, logger: SdkLogger) => Promise<string>) {\n if (typeof input === 'string') return assertUsableApiKey(input, 'TypeSafe', 'apiKey')\n else {\n const source = input\n if (source?.kind !== 'credential-source' || source.apiVersion !== CREDENTIAL_CAPABILITY_API_VERSION ||\n typeof source.resolve !== 'function') throw new Error('TypeSafe requires a compatible credential source')\n const resolve = source.resolve.bind(source)\n return async (signal, logger) => assertUsableApiKey(await resolve({ signal, logger }), 'TypeSafe',\n 'credential source')\n }\n}\n","import { ModelError, MODEL_ERROR_CODES } from '@alvin0/ai-agent-sdk-core'\nimport {\n validateDecisionResult, type DecisionAnswer, type DecisionInput, type DecisionResult,\n} from '@alvin0/ai-agent-sdk-decision-adapter'\nimport { object, responseUsage, sameDescription } from './response.ts'\n\nexport function decodeTypesafeResult(value: unknown, input: DecisionInput): DecisionResult {\n const raw = object(value)\n const rawAnswers = object(raw.answers)\n // Validate wire identifiers/types BEFORE projecting, so surplus answers cannot disappear.\n if (Object.keys(rawAnswers).length !== Object.keys(input.questions).length) throw new ModelError(\n 'Unexpected TypeSafe answer ids', MODEL_ERROR_CODES.MALFORMED_RESPONSE)\n const answers: Record<string, DecisionAnswer> = Object.create(null) as Record<string, DecisionAnswer>\n for (const [id, question] of Object.entries(input.questions)) {\n if (!Object.hasOwn(rawAnswers, id)) throw new ModelError('Missing TypeSafe answer',\n MODEL_ERROR_CODES.MALFORMED_RESPONSE)\n const answer = object(rawAnswers[id])\n answers[id] = decodeAnswer(question, answer)\n }\n const usage = responseUsage(raw)\n return validateDecisionResult({\n model: raw.model, answers,\n ...(usage === undefined ? {} : { usage }),\n }, input.questions)\n}\n\nfunction decodeAnswer(\n question: DecisionInput['questions'][string], answer: Record<string, unknown>,\n): DecisionAnswer {\n const evidence = {\n probabilitySource: 'provider' as const,\n ...(answer.confidence === undefined ? {} : { confidence: answer.confidence as number }),\n }\n switch (question.type) {\n case 'choice':\n assertChoiceAnswer(answer)\n return { type: 'choice', choice: answer.choice as string,\n probabilities: answer.probabilities as Record<string, number>, ...evidence }\n case 'score': {\n assertScoreAnswer(answer, question.levels)\n return { type: 'score', score: answer.score as number,\n probabilities: answer.probabilities as Record<string, number>, ...evidence }\n }\n case 'boolean':\n if (answer.type !== 'noul') throw new ModelError('Invalid TypeSafe boolean answer',\n MODEL_ERROR_CODES.MALFORMED_RESPONSE)\n return { type: 'boolean', value: (answer.noul as number) >= 0.5,\n probabilityTrue: answer.noul as number, probabilitySource: 'provider' }\n }\n}\n\nfunction assertChoiceAnswer(answer: Record<string, unknown>): void {\n if (answer.type !== 'choice' || answer.probabilities === undefined ||\n answer.confidence === undefined) throw new ModelError('Invalid TypeSafe choice answer',\n MODEL_ERROR_CODES.MALFORMED_RESPONSE)\n}\n\nfunction assertScoreAnswer(answer: Record<string, unknown>, levels: readonly unknown[]): void {\n if (answer.type !== 'score' || answer.probabilities === undefined ||\n answer.confidence === undefined) throw new ModelError('Invalid TypeSafe score answer',\n MODEL_ERROR_CODES.MALFORMED_RESPONSE)\n const legend = object(answer.legend)\n if (Object.keys(legend).length !== levels.length || levels.some((level, i) => !Object.hasOwn(\n legend, String(i)) || !sameDescription(level, legend[String(i)]))) throw new ModelError(\n 'Invalid TypeSafe score legend', MODEL_ERROR_CODES.MALFORMED_RESPONSE)\n}\n","import { ModelError, MODEL_ERROR_CODES, resolveRetryPolicy } from '@alvin0/ai-agent-sdk-core'\nimport type { ModelInvocationContext, SdkLogger } from '@alvin0/ai-agent-sdk-core/provider'\nimport {\n DecisionAdapter, defineDecisionProviderPlugin, snapshotDecisionInput, validateDecisionResult,\n type DecisionInput, type DecisionModelInfo, type DecisionProviderPlugin, type DecisionRequest,\n type DecisionResult, type PreparedDecisionCall,\n} from '@alvin0/ai-agent-sdk-decision-adapter'\nimport { dispatchTypesafe, type TypesafeDispatchRequest } from './dispatch.ts'\nimport { CAPABILITIES, bound, typesafeBaseUrl, captureCredential } from './configuration.ts'\nimport { decodeTypesafeResult } from './decode.ts'\nimport { object } from './response.ts'\nimport type { CapturedTypesafeRequest, TypesafeAdapterOptions, TypesafePluginOptions } from './types.ts'\n\nexport type { TypesafeAdapterOptions, TypesafePluginOptions } from './types.ts'\n\nfunction capturePublicHeaders(source: Readonly<Record<string, string>> | undefined): Readonly<Record<string, string>> {\n let headers: Readonly<Record<string, string>>\n try { headers = Object.freeze(Object.fromEntries(new Headers(source).entries())) }\n catch { throw new ModelError('Invalid TypeSafe custom headers', MODEL_ERROR_CODES.INVALID_REQUEST) }\n for (const key of Object.keys(headers)) {\n if (['authorization', 'content-type', 'accept', 'host', 'content-length', 'traceparent'].includes(\n key)) throw new ModelError('TypeSafe custom headers cannot override transport headers',\n MODEL_ERROR_CODES.INVALID_REQUEST)\n }\n return headers\n}\nfunction captureInvocationHeaders(context?: ModelInvocationContext): Readonly<Record<string, string>> {\n if (context?.providerOptions?.body !== undefined && Object.keys(\n context.providerOptions.body).length) throw new ModelError(\n 'TypeSafe does not support providerOptions.body overrides', MODEL_ERROR_CODES.INVALID_REQUEST)\n return capturePublicHeaders(context?.providerOptions?.headers)\n}\n\nclass TypesafeDecisionAdapter extends DecisionAdapter {\n readonly #baseUrl: string\n readonly #credential: string | ((signal: AbortSignal, logger: SdkLogger) => Promise<string>)\n readonly #fetch: typeof globalThis.fetch\n readonly #headers: Readonly<Record<string, string>>\n readonly #timeout: number\n readonly #maxRequest: number\n readonly #maxResponse: number\n readonly #retry: ReturnType<typeof resolveRetryPolicy> | undefined\n readonly #rubrics = new WeakMap<DecisionInput['questions'], string>()\n constructor(options: TypesafeAdapterOptions) {\n super()\n const url = typesafeBaseUrl(options)\n this.#baseUrl = url.href.replace(/\\/$/, '')\n this.#fetch = options.fetch ?? globalThis.fetch\n this.#headers = capturePublicHeaders(options.headers)\n this.#timeout = bound(options.requestTimeoutMs, 30_000, 'requestTimeoutMs')\n this.#maxRequest = bound(options.maxRequestBytes, 2_097_152, 'maxRequestBytes')\n this.#maxResponse = bound(options.maxResponseBytes, 4_194_304, 'maxResponseBytes')\n this.#retry = options.retryPolicy === undefined ? undefined : resolveRetryPolicy(options.retryPolicy,\n 'typesafe.retryPolicy')\n this.#credential = captureCredential(options.apiKey)\n }\n override providerRetryPolicy(): ReturnType<typeof resolveRetryPolicy> | undefined { return this.#retry }\n override async resolveModel(provider: string, model: string): Promise<DecisionModelInfo> {\n return Object.freeze({ provider, id: model, name: model, capabilities: CAPABILITIES })\n }\n override async prepareDecisionCall(provider: string, model: string, _signal?: AbortSignal,\n context?: ModelInvocationContext): Promise<PreparedDecisionCall> {\n const headers = captureInvocationHeaders(context)\n let captured: { readonly request: DecisionRequest; readonly value: CapturedTypesafeRequest } | undefined\n return Object.freeze({ model: await this.resolveModel(provider, model), evaluate: (\n request: DecisionRequest, invocation = context) => {\n if (request.provider !== provider || request.model !== model) throw new ModelError(\n 'Prepared TypeSafe decision target does not match request', MODEL_ERROR_CODES.INVALID_REQUEST)\n if (captured && captured.request !== request) throw new ModelError(\n 'Prepared TypeSafe decision call cannot dispatch a different request', MODEL_ERROR_CODES.INVALID_REQUEST)\n captured ??= { request, value: this.#capture(request,\n invocation === context ? headers : captureInvocationHeaders(invocation)) }\n return this.#evaluate(captured.value, invocation)\n } })\n }\n override async listModels(provider: string, signal?: AbortSignal): Promise<readonly DecisionModelInfo[]> {\n const result = await this.#dispatch({ provider, model: 'catalog', path: 'models', body: undefined,\n ...(signal === undefined ? {} : { callerSignal: signal }) })\n const models = object(result.value).models\n if (!Array.isArray(models) || models.length > 1_024) throw new ModelError(\n 'Invalid TypeSafe model catalog', MODEL_ERROR_CODES.MALFORMED_RESPONSE)\n return Object.freeze(models.map(entry => {\n const info = object(entry)\n if (typeof info.name !== 'string' || !info.name.trim() || info.name.length > 256) throw new ModelError(\n 'Invalid TypeSafe model id', MODEL_ERROR_CODES.MALFORMED_RESPONSE)\n return Object.freeze({ provider, id: info.name, name: info.name, capabilities: CAPABILITIES })\n }))\n }\n override async evaluate(request: DecisionRequest, context?: ModelInvocationContext): Promise<DecisionResult> {\n return this.#evaluate(this.#capture(request, captureInvocationHeaders(context)), context)\n }\n #capture(request: DecisionRequest, headers: Readonly<Record<string, string>>): CapturedTypesafeRequest {\n if (typeof request.provider !== 'string' || !request.provider.trim() ||\n typeof request.model !== 'string' || !request.model.trim()) throw new ModelError(\n 'TypeSafe requires provider and model identifiers', MODEL_ERROR_CODES.INVALID_REQUEST)\n const input = snapshotDecisionInput(request, CAPABILITIES)\n const timeout = Math.min(this.#timeout, input.timeoutMs ?? this.#timeout)\n let questions = this.#rubrics.get(input.questions)\n if (questions === undefined) {\n questions = JSON.stringify(Object.fromEntries(Object.entries(input.questions).map(([id, question]) => {\n switch (question.type) {\n case 'choice': return [id, { type: 'choice', instructions: question.instructions,\n criteria: question.options }]\n case 'score': return [id, { type: 'score', instructions: question.instructions, criteria: question.levels }]\n case 'boolean': return [id, { type: 'noul', instructions: question.instructions, ...(\n question.criteria === undefined ? {} : { criteria: question.criteria }) }]\n }\n })))\n this.#rubrics.set(input.questions, questions)\n }\n const wire = `{\"questions\":${questions},\"model\":${JSON.stringify(\n request.model)},\"state\":${JSON.stringify(input.state)}}`\n if (new TextEncoder().encode(wire).byteLength > this.#maxRequest) throw new ModelError(\n 'TypeSafe request exceeds byte limit', MODEL_ERROR_CODES.INVALID_REQUEST)\n return { input, wire, timeout, provider: request.provider, model: request.model, headers }\n }\n async #evaluate(captured: CapturedTypesafeRequest, context?: ModelInvocationContext): Promise<DecisionResult> {\n const { input, wire, timeout, provider, model } = captured\n const response = await this.#dispatch({\n provider, model, path: 'systemone', body: wire,\n ...(input.signal === undefined ? {} : { callerSignal: input.signal }),\n ...(context === undefined ? {} : { context }),\n decode: value => decodeTypesafeResult(value, input), timeout, publicHeaders: captured.headers,\n })\n const result = response.value as DecisionResult\n return response.requestId === undefined ? result : validateDecisionResult({ ...result,\n providerRequestId: response.requestId }, input.questions)\n }\n async #dispatch(request: TypesafeDispatchRequest) {\n return dispatchTypesafe({\n baseUrl: this.#baseUrl, credential: this.#credential, fetch: this.#fetch, headers: this.#headers,\n maxResponse: this.#maxResponse, timeout: this.#timeout,\n }, request)\n }\n}\nexport function typesafeAdapter(options: TypesafeAdapterOptions): DecisionAdapter {\n return new TypesafeDecisionAdapter(options)\n}\nexport function typesafePlugin(options: TypesafePluginOptions): DecisionProviderPlugin {\n const adapter = typesafeAdapter(options)\n const routes = Object.freeze([...(options.routes ?? ['typesafe'])])\n return defineDecisionProviderPlugin({\n id: options.id ?? 'typesafe', routes,\n setup(registrar) {\n const registration = registrar.registerAdapter(routes, adapter)\n return () => registration.dispose()\n },\n })\n}\n"],"mappings":";;;;;;AAEA,SAAgB,OAAO,OAAyC;CAC9D,IAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GAAG,MAAM,IAAI,WACjF,gDAAgD,kBAAkB,kBAAkB;CACtF,OAAO;AACT;;AAGA,SAAgB,gBAAgB,UAAmB,QAA0B;CAC3E,IAAI,aAAa,QAAQ,OAAO;CAChC,IAAI,aAAa,QAAQ,WAAW,QAAQ,OAAO,aAAa,YAAY,OAAO,WAAW,UAAU,OAAO;CAC/G,IAAI,MAAM,QAAQ,QAAQ,GAAG,OAAO,qBAAqB,UAAU,MAAM;CACzE,IAAI,MAAM,QAAQ,MAAM,GAAG,OAAO;CAClC,MAAM,OAAO,OAAO,KAAK,QAAQ;CACjC,OAAO,KAAK,WAAW,OAAO,KAAK,MAAM,CAAC,CAAC,UAAU,KAAK,OAAM,QAAO,OAAO,OAAO,QAAQ,GAAG,KAC9F,gBAAiB,SAAqC,MAAO,OAAmC,IAAI,CAAC;AACzG;AAEA,SAAgB,cAAc,OAA2C;CACvE,MAAM,MAAM,OAAO,KAAK,CAAC,CAAC;CAC1B,IAAI,QAAQ,QAAW,OAAO;CAC9B,MAAM,SAAS,OAAO,GAAG;CACzB,MAAM,WAAW;EACf,GAAI,OAAO,iBAAiB,SAAY,CAAC,IAAI,EAAE,aAAa,OAAO,aAAa;EAChF,GAAI,OAAO,kBAAkB,SAAY,CAAC,IAAI,EAAE,cAAc,OAAO,cAAc;CACrF;CACA,MAAM,YAAY,sBAAs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GAAI,MAAM,WAAW,SAAY,CAAC,IAAI,EAAE,cAAc,MAAM,OAAO;GACnE,GAAI,YAAY,SAAY,CAAC,IAAI,EAAE,QAAQ;GAC3C,SAAQ,UAAS,qBAAqB,OAAO,KAAK;GAAG;GAAS,eAAe,SAAS;EACxF,CAAC;EACD,MAAM,SAAS,SAAS;EACxB,OAAO,SAAS,cAAc,SAAY,SAAS,uBAAuB;GAAE,GAAG;GAC7E,mBAAmB,SAAS;EAAU,GAAG,MAAM,SAAS;CAC5D;CACA,MAAM,UAAU,SAAkC;EAChD,OAAO,iBAAiB;GACtB,SAAS,KAAK;GAAU,YAAY,KAAK;GAAa,OAAO,KAAK;GAAQ,SAAS,KAAK;GACxF,aAAa,KAAK;GAAc,SAAS,KAAK;EAChD,GAAG,OAAO;CACZ;AACF;AACA,SAAgB,gBAAgB,SAAkD;CAChF,OAAO,IAAI,wBAAwB,OAAO;AAC5C;AACA,SAAgB,eAAe,SAAwD;CACrF,MAAM,UAAU,gBAAgB,OAAO;CACvC,MAAM,SAAS,OAAO,OAAO,CAAC,GAAI,QAAQ,UAAU,CAAC,UAAU,CAAE,CAAC;CAClE,OAAO,6BAA6B;EAClC,IAAI,QAAQ,MAAM;EAAY;EAC9B,MAAM,WAAW;GACf,MAAM,eAAe,UAAU,gBAAgB,QAAQ,OAAO;GAC9D,aAAa,aAAa,QAAQ;EACpC;CACF,CAAC;AACH"}
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "name": "alvin0 - chaulamdinhai",
5
5
  "email": "chaulamdinhai@gmail.com"
6
6
  },
7
- "version": "0.1.10",
7
+ "version": "0.1.11",
8
8
  "description": "Universal TypeSafe Jev decision adapter and provider plugin for ai-agent-sdk",
9
9
  "license": "MIT",
10
10
  "repository": {
@@ -38,13 +38,13 @@
38
38
  "provenance": true
39
39
  },
40
40
  "dependencies": {
41
- "@alvin0/ai-agent-sdk-decision-adapter": "^0.1.10"
41
+ "@alvin0/ai-agent-sdk-decision-adapter": "^0.1.11"
42
42
  },
43
43
  "peerDependencies": {
44
- "@alvin0/ai-agent-sdk-core": "^0.1.10"
44
+ "@alvin0/ai-agent-sdk-core": "^0.1.11"
45
45
  },
46
46
  "devDependencies": {
47
- "@alvin0/ai-agent-sdk-core": "^0.1.10",
47
+ "@alvin0/ai-agent-sdk-core": "^0.1.11",
48
48
  "@arethetypeswrong/cli": "0.18.5",
49
49
  "publint": "0.3.24",
50
50
  "tsdown": "0.22.14",