@openclaw/typesafe 2026.10.10-beta.5 → 2026.11.5-beta.1

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.
Files changed (86) hide show
  1. package/README.md +28 -2
  2. package/dist/.setup/client-DI7wM7N-.mjs +361 -0
  3. package/dist/.setup/{errors-BZeWj5nc.mjs → errors-BEKARoBh.mjs} +17 -5
  4. package/dist/.source-module-urls/cb128076f461604fb70d7e9adeed8a53c97339bf983a26e3f0598f525dcccb17.json +1 -1
  5. package/dist/index.js +438 -71
  6. package/node_modules/typebox/build/format/duration.d.mts +2 -2
  7. package/node_modules/typebox/build/format/duration.mjs +2 -2
  8. package/node_modules/typebox/build/format/idn_email.d.mts +1 -0
  9. package/node_modules/typebox/build/format/idn_email.mjs +1 -0
  10. package/node_modules/typebox/build/format/idn_hostname.d.mts +1 -1
  11. package/node_modules/typebox/build/format/idn_hostname.mjs +1 -1
  12. package/node_modules/typebox/build/format/ipv4.d.mts +2 -2
  13. package/node_modules/typebox/build/format/ipv4.mjs +2 -2
  14. package/node_modules/typebox/build/format/ipv6.d.mts +1 -1
  15. package/node_modules/typebox/build/format/ipv6.mjs +1 -1
  16. package/node_modules/typebox/build/format/relative_json_pointer.d.mts +2 -2
  17. package/node_modules/typebox/build/format/relative_json_pointer.mjs +2 -2
  18. package/node_modules/typebox/build/schema/build.mjs +1 -0
  19. package/node_modules/typebox/build/schema/engine/_unique.d.mts +4 -2
  20. package/node_modules/typebox/build/schema/engine/_unique.mjs +7 -3
  21. package/node_modules/typebox/build/schema/engine/additionalItems.mjs +3 -3
  22. package/node_modules/typebox/build/schema/engine/additionalProperties.d.mts +0 -3
  23. package/node_modules/typebox/build/schema/engine/additionalProperties.mjs +15 -17
  24. package/node_modules/typebox/build/schema/engine/contains.mjs +3 -3
  25. package/node_modules/typebox/build/schema/engine/index.d.mts +1 -0
  26. package/node_modules/typebox/build/schema/engine/index.mjs +1 -0
  27. package/node_modules/typebox/build/schema/engine/items.mjs +7 -4
  28. package/node_modules/typebox/build/schema/engine/maxContains.mjs +2 -2
  29. package/node_modules/typebox/build/schema/engine/minContains.mjs +3 -3
  30. package/node_modules/typebox/build/schema/engine/oneOf.mjs +2 -2
  31. package/node_modules/typebox/build/schema/engine/patternProperties.mjs +2 -2
  32. package/node_modules/typebox/build/schema/engine/propertyNames.mjs +2 -2
  33. package/node_modules/typebox/build/schema/engine/unevaluatedItems.mjs +2 -2
  34. package/node_modules/typebox/build/schema/engine/unevaluatedProperties.mjs +2 -2
  35. package/node_modules/typebox/build/system/hashing/hash.mjs +63 -34
  36. package/node_modules/typebox/build/system/locale/en_US.mjs +2 -1
  37. package/node_modules/typebox/build/system/memory/assign.d.mts +2 -8
  38. package/node_modules/typebox/build/system/memory/assign.mjs +13 -6
  39. package/node_modules/typebox/build/system/memory/clone.d.mts +4 -5
  40. package/node_modules/typebox/build/system/memory/clone.mjs +8 -96
  41. package/node_modules/typebox/build/system/memory/create.d.mts +1 -5
  42. package/node_modules/typebox/build/system/memory/create.mjs +18 -13
  43. package/node_modules/typebox/build/system/memory/deep.d.mts +2 -0
  44. package/node_modules/typebox/build/system/memory/deep.mjs +108 -0
  45. package/node_modules/typebox/build/system/memory/discard.d.mts +1 -1
  46. package/node_modules/typebox/build/system/memory/discard.mjs +9 -8
  47. package/node_modules/typebox/build/system/memory/finalize.d.mts +4 -0
  48. package/node_modules/typebox/build/system/memory/finalize.mjs +30 -0
  49. package/node_modules/typebox/build/system/memory/keys.d.mts +2 -0
  50. package/node_modules/typebox/build/system/memory/keys.mjs +8 -0
  51. package/node_modules/typebox/build/system/memory/update.d.mts +1 -4
  52. package/node_modules/typebox/build/system/memory/update.mjs +43 -16
  53. package/node_modules/typebox/build/type/engine/call/index.d.mts +1 -0
  54. package/node_modules/typebox/build/type/engine/call/index.mjs +1 -0
  55. package/node_modules/typebox/build/type/engine/evaluate/composite.d.mts +2 -24
  56. package/node_modules/typebox/build/type/engine/evaluate/composite.mjs +2 -29
  57. package/node_modules/typebox/build/type/engine/evaluate/index.d.mts +1 -0
  58. package/node_modules/typebox/build/type/engine/evaluate/index.mjs +1 -0
  59. package/node_modules/typebox/build/type/engine/evaluate/narrow.d.mts +5 -1
  60. package/node_modules/typebox/build/type/engine/evaluate/narrow.mjs +6 -1
  61. package/node_modules/typebox/build/type/engine/evaluate/property.d.mts +30 -0
  62. package/node_modules/typebox/build/type/engine/evaluate/property.mjs +29 -0
  63. package/node_modules/typebox/build/type/engine/immutable/instantiate_add.d.mts +1 -3
  64. package/node_modules/typebox/build/type/engine/immutable/instantiate_add.mjs +1 -4
  65. package/node_modules/typebox/build/type/engine/object/from_intersect.d.mts +2 -2
  66. package/node_modules/typebox/build/type/engine/object/from_intersect.mjs +2 -2
  67. package/node_modules/typebox/build/type/engine/object/from_union.d.mts +2 -2
  68. package/node_modules/typebox/build/type/engine/object/from_union.mjs +2 -2
  69. package/node_modules/typebox/build/type/engine/optional/instantiate_add.d.mts +1 -3
  70. package/node_modules/typebox/build/type/engine/optional/instantiate_add.mjs +1 -4
  71. package/node_modules/typebox/build/type/engine/readonly/instantiate_add.d.mts +1 -3
  72. package/node_modules/typebox/build/type/engine/readonly/instantiate_add.mjs +1 -4
  73. package/node_modules/typebox/build/type/engine/this/index.d.mts +1 -0
  74. package/node_modules/typebox/build/type/engine/this/index.mjs +1 -0
  75. package/node_modules/typebox/build/value/clone/clone.d.mts +4 -3
  76. package/node_modules/typebox/build/value/clone/clone.mjs +5 -7
  77. package/node_modules/typebox/build/value/repair/from_cyclic.d.mts +2 -0
  78. package/node_modules/typebox/build/value/repair/from_cyclic.mjs +6 -0
  79. package/node_modules/typebox/build/value/shared/union_priority_sort.mjs +25 -14
  80. package/node_modules/typebox/package.json +1 -1
  81. package/node_modules/typebox/readme.md +1 -1
  82. package/openclaw.plugin.json +197 -47
  83. package/package.json +5 -5
  84. package/dist/.setup/client-6lXBoHzi.mjs +0 -397
  85. package/node_modules/typebox/build/system/memory/freeze.d.mts +0 -4
  86. package/node_modules/typebox/build/system/memory/freeze.mjs +0 -6
package/dist/index.js CHANGED
@@ -1,11 +1,34 @@
1
- import { i as ConfigSchema, n as decisionFailure, o as runtimeConfig } from "./.setup/errors-BZeWj5nc.mjs";
1
+ import { c as providerBaseUrl, i as ConfigSchema, l as runtimeConfig, n as decisionFailure, o as hasCredentials } from "./.setup/errors-BEKARoBh.mjs";
2
2
  import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
3
+ import { findNormalizedProviderValue } from "openclaw/plugin-sdk/model-ref-parse";
4
+ import { resolveSecretInputString } from "openclaw/plugin-sdk/secret-input";
3
5
  import { getPreparedPluginSecretInput } from "openclaw/plugin-sdk/secret-input-runtime";
6
+ import { randomUUID } from "node:crypto";
7
+ import { decisionBatchV2ToV1, decisionResultV1ToV2, validateDecisionBatchV2 } from "openclaw/plugin-sdk/decisions";
4
8
  import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime";
5
- //#region extensions/typesafe/src/credentials.ts
6
- /** Only host-prepared capability snapshots may supply a credential. Never resolve or cache refs. */
9
+ import { resolveProviderRequestHeaders } from "openclaw/plugin-sdk/provider-http";
10
+ import { omitNullRequestHeaders } from "openclaw/plugin-sdk/provider-request-headers";
11
+ // extensions/typesafe/src/credentials.ts
12
+ /** Read the active host snapshot only; never resolve refs or discover fallback credentials. */
7
13
  function resolveRuntimeConfig(snapshot) {
8
14
  const configured = snapshot.plugins?.entries?.typesafe?.config;
15
+ const provider = findNormalizedProviderValue(snapshot.models?.providers, "typesafe");
16
+ if (provider) {
17
+ const { timeoutMs } = runtimeConfig({ timeoutMs: configured?.timeoutMs });
18
+ const credential = resolveSecretInputString({
19
+ value: provider.apiKey,
20
+ defaults: snapshot.secrets?.defaults,
21
+ path: "models.providers.typesafe.apiKey",
22
+ mode: "inspect"
23
+ });
24
+ return {
25
+ baseUrl: providerBaseUrl(provider.baseUrl),
26
+ providerConfig: provider,
27
+ apiKey: credential.value,
28
+ credentialsUnavailable: credential.status === "configured_unavailable",
29
+ timeoutMs: provider.timeoutSeconds === void 0 ? timeoutMs : provider.timeoutSeconds * 1e3
30
+ };
31
+ }
9
32
  const validated = runtimeConfig(configured);
10
33
  if (validated.baseUrl) return validated;
11
34
  const prepared = getPreparedPluginSecretInput("typesafe", "apiKey");
@@ -14,93 +37,437 @@ function resolveRuntimeConfig(snapshot) {
14
37
  apiKey: prepared.value
15
38
  };
16
39
  }
17
- //#endregion
18
- //#region extensions/typesafe/src/decisions.ts
19
- const loadClient = createLazyRuntimeModule(() => import("./.setup/client-6lXBoHzi.mjs"));
40
+ // extensions/typesafe/openclaw.plugin.json
41
+ var modelCatalog = { "providers": { "typesafe": {
42
+ "models": [
43
+ {
44
+ "id": "jev-latest",
45
+ "name": "Jev",
46
+ "baseUrl": "https://api.typesafe.ai/v1",
47
+ "inference": {
48
+ "chat": false,
49
+ "decision": {
50
+ "protocol": "typesafe-systemone",
51
+ "input": ["text", "image"],
52
+ "questions": {
53
+ "boolean": {
54
+ "probabilities": "boolean",
55
+ "abstention": false
56
+ },
57
+ "choice": {
58
+ "probabilities": "provider-defined",
59
+ "abstention": false,
60
+ "minOptions": 2,
61
+ "maxOptions": 255
62
+ },
63
+ "score": {
64
+ "probabilities": "provider-defined",
65
+ "abstention": false,
66
+ "minOptions": 2,
67
+ "maxOptions": 10
68
+ }
69
+ },
70
+ "reasoning": { "modes": ["auto"] },
71
+ "confidence": "provider-specific",
72
+ "limits": { "image": {
73
+ "maxBytes": 4194304,
74
+ "mimeTypes": ["image/png", "image/jpeg"],
75
+ "remoteUrls": false
76
+ } }
77
+ }
78
+ }
79
+ },
80
+ {
81
+ "id": "jev-preview",
82
+ "name": "Jev Preview",
83
+ "baseUrl": "https://api.typesafe.ai/v1",
84
+ "status": "preview",
85
+ "inference": {
86
+ "chat": false,
87
+ "decision": {
88
+ "protocol": "typesafe-systemone",
89
+ "input": ["text", "image"],
90
+ "questions": {
91
+ "boolean": {
92
+ "probabilities": "boolean",
93
+ "abstention": false
94
+ },
95
+ "choice": {
96
+ "probabilities": "provider-defined",
97
+ "abstention": false,
98
+ "minOptions": 2,
99
+ "maxOptions": 255
100
+ },
101
+ "score": {
102
+ "probabilities": "provider-defined",
103
+ "abstention": false,
104
+ "minOptions": 2,
105
+ "maxOptions": 10
106
+ }
107
+ },
108
+ "reasoning": { "modes": ["auto"] },
109
+ "confidence": "provider-specific",
110
+ "limits": { "image": {
111
+ "maxBytes": 4194304,
112
+ "mimeTypes": ["image/png", "image/jpeg"],
113
+ "remoteUrls": false
114
+ } }
115
+ }
116
+ }
117
+ },
118
+ {
119
+ "id": "jev-1.13.0",
120
+ "name": "Jev 1.13.0",
121
+ "baseUrl": "https://api.typesafe.ai/v1",
122
+ "inference": {
123
+ "chat": false,
124
+ "decision": {
125
+ "protocol": "typesafe-systemone",
126
+ "input": ["text", "image"],
127
+ "questions": {
128
+ "boolean": {
129
+ "probabilities": "boolean",
130
+ "abstention": false
131
+ },
132
+ "choice": {
133
+ "probabilities": "provider-defined",
134
+ "abstention": false,
135
+ "minOptions": 2,
136
+ "maxOptions": 255
137
+ },
138
+ "score": {
139
+ "probabilities": "provider-defined",
140
+ "abstention": false,
141
+ "minOptions": 2,
142
+ "maxOptions": 10
143
+ }
144
+ },
145
+ "reasoning": { "modes": ["auto"] },
146
+ "confidence": "provider-specific",
147
+ "limits": {
148
+ "image": {
149
+ "maxBytes": 4194304,
150
+ "mimeTypes": ["image/png", "image/jpeg"],
151
+ "remoteUrls": false
152
+ },
153
+ "maxRequestTokens": 64e3,
154
+ "maxStateAndQuestionTokens": 32e3
155
+ },
156
+ "billing": {
157
+ "unit": "tokens",
158
+ "source": "provider-docs",
159
+ "usdPerMillion": {
160
+ "input": .042,
161
+ "output": 0
162
+ }
163
+ }
164
+ }
165
+ }
166
+ },
167
+ {
168
+ "id": "kev-latest",
169
+ "name": "Kev (local server)",
170
+ "inference": {
171
+ "chat": false,
172
+ "decision": {
173
+ "protocol": "typesafe-systemone",
174
+ "input": ["text"],
175
+ "questions": {
176
+ "boolean": {
177
+ "probabilities": "boolean",
178
+ "abstention": false
179
+ },
180
+ "choice": {
181
+ "probabilities": "provider-defined",
182
+ "abstention": false,
183
+ "minOptions": 2,
184
+ "maxOptions": 255
185
+ },
186
+ "score": {
187
+ "probabilities": "provider-defined",
188
+ "abstention": false,
189
+ "minOptions": 2,
190
+ "maxOptions": 10
191
+ }
192
+ },
193
+ "reasoning": { "modes": ["auto"] },
194
+ "confidence": "provider-specific"
195
+ }
196
+ }
197
+ }
198
+ ],
199
+ "authScope": "plugin"
200
+ } } };
201
+ // extensions/typesafe/src/decisions.ts
202
+ const loadClient = createLazyRuntimeModule(() => import("./.setup/client-DI7wM7N-.mjs"));
203
+ const models = modelCatalog.providers.typesafe.models;
204
+ const hostedBaseUrl = providerBaseUrl(models[0].baseUrl);
205
+ function effectiveBaseUrl(config) {
206
+ return config.providerConfig ? providerBaseUrl(config.providerConfig.baseUrl) : config.baseUrl ? `${config.baseUrl}/v1` : hostedBaseUrl;
207
+ }
208
+ function bindHostedFacts(inference, id, config) {
209
+ if (!models.find((model) => model.id === id)?.inference.decision || !inference.decision) return inference;
210
+ const configured = config.providerConfig;
211
+ const configuredModel = configured?.models.find((model) => model.id === id);
212
+ const headers = (values) => Object.fromEntries(Object.entries(values ?? {}).flatMap(([name, value]) => {
213
+ if (name.trim().toLowerCase() !== "typesafe-danger-zone-long-context") return [];
214
+ const resolved = resolveSecretInputString({
215
+ value,
216
+ path: `models.providers.typesafe.headers.${name}`,
217
+ mode: "inspect"
218
+ });
219
+ const header = resolved.status === "configured_unavailable" ? "unavailable" : resolved.value;
220
+ return header === void 0 ? [] : [[name, header]];
221
+ }));
222
+ const mergedHeaders = resolveProviderRequestHeaders({
223
+ provider: "typesafe",
224
+ baseUrl: effectiveBaseUrl(config),
225
+ defaultHeaders: headers(configured?.headers),
226
+ callerHeaders: headers(configuredModel?.headers),
227
+ precedence: "caller-wins"
228
+ });
229
+ const effectiveHeaders = resolveProviderRequestHeaders({
230
+ provider: "typesafe",
231
+ baseUrl: effectiveBaseUrl(config),
232
+ defaultHeaders: mergedHeaders,
233
+ request: {
234
+ headers: headers(configured?.request?.headers),
235
+ ...configured?.request?.auth?.mode === "header" && configured.request.auth.headerName.trim().toLowerCase() === "typesafe-danger-zone-long-context" ? { auth: {
236
+ ...configured.request.auth,
237
+ value: resolveSecretInputString({
238
+ value: configured.request.auth.value,
239
+ path: "models.providers.typesafe.request.auth.value",
240
+ mode: "inspect"
241
+ }).value ?? "unavailable"
242
+ } } : {}
243
+ }
244
+ });
245
+ const hosted = effectiveBaseUrl(config) === hostedBaseUrl;
246
+ const contextHeader = new Headers(omitNullRequestHeaders(effectiveHeaders)).get("TypeSafe-Danger-Zone-Long-Context");
247
+ if (hosted && contextHeader !== "true" && contextHeader !== "unavailable") return inference;
248
+ const { billing, limits, ...decision } = inference.decision;
249
+ const { maxRequestTokens: _maxRequestTokens, maxStateAndQuestionTokens: _maxStateAndQuestionTokens, image, ...otherLimits } = limits ?? {};
250
+ return {
251
+ ...inference,
252
+ decision: {
253
+ ...decision,
254
+ ...!hosted ? { input: decision.input.filter((kind) => kind !== "image") } : {},
255
+ ...billing && (hosted || billing.source !== "provider-docs") ? { billing } : {},
256
+ ...Object.keys(otherLimits).length || hosted && image ? { limits: {
257
+ ...otherLimits,
258
+ ...hosted && image ? { image } : {}
259
+ } } : {}
260
+ }
261
+ };
262
+ }
20
263
  /** Translate the host-selected decision contract through the TypeSafe transport. */
21
- function createDecisionProvider(getConfig) {
264
+ function createDecisionEvaluator(getConfig, assets) {
265
+ return async (batch, context) => {
266
+ context.signal.throwIfAborted();
267
+ const { evaluate: evaluateTypeSafe } = await loadClient();
268
+ context.signal.throwIfAborted();
269
+ const config = getConfig();
270
+ if (!hasCredentials(config)) return {
271
+ status: "unavailable",
272
+ reason: "credentials-unavailable"
273
+ };
274
+ const remaining = context.deadlineMonotonicMs - performance.now();
275
+ if (remaining <= 0) return {
276
+ status: "unavailable",
277
+ reason: "transport"
278
+ };
279
+ const questions = Object.fromEntries(Object.entries(batch.questions).map(([id, q]) => [id, q.type === "boolean" ? {
280
+ ...q,
281
+ type: "noul"
282
+ } : q]));
283
+ try {
284
+ const { evaluation } = await evaluateTypeSafe({
285
+ state: batch.state,
286
+ questions,
287
+ model: context.model
288
+ }, {
289
+ ...config,
290
+ timeoutMs: Math.min(config.timeoutMs, remaining)
291
+ }, context.signal, context.deadlineMonotonicMs, () => {
292
+ if (context.isAdmissible && !context.isAdmissible()) return false;
293
+ const current = getConfig();
294
+ return current.baseUrl === config.baseUrl && current.providerConfig === config.providerConfig && current.apiKey === config.apiKey && !current.credentialsUnavailable;
295
+ }, assets);
296
+ context.signal.throwIfAborted();
297
+ const answers = {};
298
+ for (const [id, answer] of Object.entries(evaluation.answers)) if (answer.type === "noul") answers[id] = {
299
+ type: "boolean",
300
+ probabilityTrue: answer.noul
301
+ };
302
+ else if (answer.type === "choice") answers[id] = answer;
303
+ else {
304
+ const question = batch.questions[id];
305
+ if (!question || question.type !== "score") return {
306
+ status: "unavailable",
307
+ reason: "invalid-response"
308
+ };
309
+ answers[id] = {
310
+ type: "score",
311
+ score: answer.score,
312
+ confidence: answer.confidence,
313
+ probabilities: question.criteria.map((_level, i) => answer.probabilities[String(i)])
314
+ };
315
+ }
316
+ return {
317
+ status: "ok",
318
+ result: {
319
+ model: evaluation.model,
320
+ answers,
321
+ usage: {
322
+ inputTokens: evaluation.usage.input_tokens,
323
+ outputTokens: evaluation.usage.output_tokens
324
+ }
325
+ }
326
+ };
327
+ } catch (error) {
328
+ context.signal.throwIfAborted();
329
+ return decisionFailure(error);
330
+ }
331
+ };
332
+ }
333
+ /** Preserve the existing question/result translation; only tagged image state adds assets. */
334
+ function translateBatch(batch) {
335
+ if (!validateDecisionBatchV2(batch)) return;
336
+ if (batch.state.type !== "image") {
337
+ const text = decisionBatchV2ToV1(batch);
338
+ return text ? { batch: text } : void 0;
339
+ }
340
+ const match = /^data:image\/(png|jpeg);base64,/.exec(batch.state.dataUri);
341
+ if (!match || Object.values(batch.questions).some((question) => question.type !== "boolean" && question.type !== "choice" && question.type !== "score")) return;
342
+ const callerText = JSON.stringify([batch.state.text, batch.questions]);
343
+ let ref = randomUUID();
344
+ while (callerText.includes(ref)) ref = randomUUID();
345
+ const translated = decisionBatchV2ToV1({
346
+ state: batch.state.text === void 0 ? {
347
+ type: "text",
348
+ text: ref
349
+ } : {
350
+ type: "json",
351
+ value: [batch.state.text, ref]
352
+ },
353
+ questions: batch.questions
354
+ });
355
+ if (!translated) return;
356
+ return {
357
+ batch: translated,
358
+ assets: { [ref]: {
359
+ type: "image",
360
+ format: match[1] === "png" ? "png" : "jpg",
361
+ data_base64: batch.state.dataUri.slice(match[0].length)
362
+ } }
363
+ };
364
+ }
365
+ /** The shared provider owns the same credential and full configured route as V1. */
366
+ function createPreparedDecisionProvider(getConfig) {
367
+ const common = models[0].inference.decision;
368
+ const inference = {
369
+ chat: false,
370
+ decision: {
371
+ protocol: "typesafe-systemone",
372
+ input: ["text"],
373
+ questions: {
374
+ boolean: {
375
+ probabilities: "boolean",
376
+ abstention: false
377
+ },
378
+ choice: {
379
+ probabilities: "provider-defined",
380
+ abstention: false,
381
+ minOptions: common.questions.choice.minOptions,
382
+ maxOptions: common.questions.choice.maxOptions
383
+ },
384
+ score: {
385
+ probabilities: "provider-defined",
386
+ abstention: false,
387
+ minOptions: common.questions.score.minOptions,
388
+ maxOptions: common.questions.score.maxOptions
389
+ }
390
+ },
391
+ confidence: "provider-specific",
392
+ reasoning: { modes: ["auto"] }
393
+ }
394
+ };
22
395
  return {
23
396
  id: "typesafe",
24
- contractVersion: 1,
25
- isReady: () => {
26
- const config = getConfig();
27
- return Boolean(config.baseUrl || config.apiKey);
397
+ contractVersion: 2,
398
+ provider: {
399
+ label: "TypeSafe AI",
400
+ auth: [],
401
+ authScope: "plugin",
402
+ resolveSyntheticAuth: () => {
403
+ const config = getConfig();
404
+ if (!hasCredentials(config)) return;
405
+ return {
406
+ apiKey: config.apiKey || "typesafe-local",
407
+ source: "typesafe plugin",
408
+ mode: "api-key"
409
+ };
410
+ },
411
+ normalizeTransport: () => {
412
+ return { baseUrl: effectiveBaseUrl(getConfig()) };
413
+ },
414
+ augmentModelCatalog: ({ entries }) => entries.filter((entry) => entry.provider === "typesafe").map((entry) => Object.assign({}, entry, { inference: bindHostedFacts(entry.inference?.decision && entry.inference.decision.protocol !== "decision-v1" ? entry.inference : inference, entry.id, getConfig()) }))
28
415
  },
29
416
  async evaluate(batch, context) {
30
- context.signal.throwIfAborted();
31
- const { evaluate: evaluateTypeSafe } = await loadClient();
32
- context.signal.throwIfAborted();
33
- const config = getConfig();
34
- if (!config.baseUrl && !config.apiKey) return {
417
+ const request = translateBatch(batch);
418
+ if (!request || context.reasoning !== void 0 && context.reasoning !== "auto") return {
35
419
  status: "unavailable",
36
- reason: "credentials-unavailable"
420
+ reason: "unsupported-input"
37
421
  };
38
- const remaining = context.deadlineMonotonicMs - performance.now();
39
- if (remaining <= 0) return {
422
+ const v1 = request.batch;
423
+ if (request.assets && !models.some((model) => model.id === context.model.id && model.inference.decision.input.includes("image"))) return {
40
424
  status: "unavailable",
41
- reason: "transport"
425
+ reason: "unsupported-input"
42
426
  };
43
- const questions = Object.fromEntries(Object.entries(batch.questions).map(([id, q]) => [id, q.type === "boolean" ? {
44
- ...q,
45
- type: "noul"
46
- } : q]));
47
- try {
48
- const { evaluation } = await evaluateTypeSafe({
49
- state: batch.state,
50
- questions,
51
- model: context.model
52
- }, {
53
- ...config,
54
- timeoutMs: Math.min(config.timeoutMs, remaining)
55
- }, context.signal, context.deadlineMonotonicMs, context.isAdmissible);
56
- context.signal.throwIfAborted();
57
- const answers = {};
58
- for (const [id, answer] of Object.entries(evaluation.answers)) if (answer.type === "noul") answers[id] = {
59
- type: "boolean",
60
- probabilityTrue: answer.noul
61
- };
62
- else if (answer.type === "choice") answers[id] = answer;
63
- else {
64
- const question = batch.questions[id];
65
- if (!question || question.type !== "score") return {
66
- status: "unavailable",
67
- reason: "invalid-response"
68
- };
69
- answers[id] = {
70
- type: "score",
71
- score: answer.score,
72
- confidence: answer.confidence,
73
- probabilities: question.criteria.map((_level, i) => answer.probabilities[String(i)])
74
- };
75
- }
76
- return {
77
- status: "ok",
78
- result: {
79
- model: evaluation.model,
80
- answers,
81
- usage: {
82
- inputTokens: evaluation.usage.input_tokens,
83
- outputTokens: evaluation.usage.output_tokens
84
- }
85
- }
427
+ const original = getConfig();
428
+ const providerConfig = original.providerConfig ? {
429
+ ...original.providerConfig,
430
+ baseUrl: context.model.baseUrl ?? original.providerConfig.baseUrl,
431
+ headers: omitNullRequestHeaders(context.model.headers) ?? original.providerConfig.headers
432
+ } : void 0;
433
+ const prepared = {
434
+ ...original,
435
+ providerConfig,
436
+ apiKey: original.baseUrl && !providerConfig ? void 0 : context.auth.apiKey === "typesafe-local" ? void 0 : context.auth.apiKey
437
+ };
438
+ const outcome = await createDecisionEvaluator(() => {
439
+ const current = getConfig();
440
+ return current.baseUrl === original.baseUrl && current.providerConfig === original.providerConfig && current.apiKey === original.apiKey && current.credentialsUnavailable === original.credentialsUnavailable ? prepared : {
441
+ ...current,
442
+ credentialsUnavailable: true
86
443
  };
87
- } catch (error) {
88
- context.signal.throwIfAborted();
89
- return decisionFailure(error);
90
- }
444
+ }, request.assets)(v1, {
445
+ model: context.model.id,
446
+ agentId: context.agentId,
447
+ signal: context.signal,
448
+ deadlineMonotonicMs: context.deadlineMonotonicMs,
449
+ isAdmissible: context.isAdmissible
450
+ });
451
+ if (outcome.status !== "ok") return outcome;
452
+ const result = decisionResultV1ToV2(v1, outcome.result);
453
+ return result ? {
454
+ status: "ok",
455
+ result
456
+ } : {
457
+ status: "unavailable",
458
+ reason: "invalid-response"
459
+ };
91
460
  }
92
461
  };
93
462
  }
94
- //#endregion
95
- //#region extensions/typesafe/index.ts
463
+ // extensions/typesafe/index.ts
96
464
  var typesafe_default = definePluginEntry({
97
465
  id: "typesafe",
98
466
  name: "TypeSafe AI",
99
467
  description: "Typed decision provider for hosted Jev and local System One models.",
100
468
  configSchema: { jsonSchema: { ...ConfigSchema } },
101
469
  register(api) {
102
- api.registerDecisionProvider(createDecisionProvider(() => resolveRuntimeConfig(api.runtime.config.current())));
470
+ api.registerDecisionProvider(createPreparedDecisionProvider(() => resolveRuntimeConfig(api.runtime.config.current())));
103
471
  }
104
472
  });
105
- //#endregion
106
473
  export { typesafe_default as default };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Returns true if the value is a valid ISO-8601 duration.
3
- * @specification https://tools.ietf.org/html/rfc3339
2
+ * Returns true if the value is a valid duration.
3
+ * @specification https://www.rfc-editor.org/rfc/rfc3339.html#appendix-A
4
4
  */
5
5
  export declare function IsDuration(value: string): boolean;
@@ -1,7 +1,7 @@
1
1
  const Duration = /^P((\d+Y(\d+M(\d+D)?)?|\d+M(\d+D)?|\d+D)(T(\d+H(\d+M(\d+S)?)?|\d+M(\d+S)?|\d+S))?|T(\d+H(\d+M(\d+S)?)?|\d+M(\d+S)?|\d+S)|\d+W)$/;
2
2
  /**
3
- * Returns true if the value is a valid ISO-8601 duration.
4
- * @specification https://tools.ietf.org/html/rfc3339
3
+ * Returns true if the value is a valid duration.
4
+ * @specification https://www.rfc-editor.org/rfc/rfc3339.html#appendix-A
5
5
  */
6
6
  export function IsDuration(value) {
7
7
  return Duration.test(value);
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  * Returns true if the value is an IdnEmail
3
3
  * @specification https://datatracker.ietf.org/doc/html/rfc4952
4
+ * @specification https://datatracker.ietf.org/doc/html/rfc6531
4
5
  */
5
6
  export declare function IsIdnEmail(value: string): boolean;
@@ -2,6 +2,7 @@ const IdnEmail = /^(?:[A-Za-z0-9!#$%&'*+\/=?^_`{|}~\u{0080}-\u{10FFFF}-]+(?:\.[A
2
2
  /**
3
3
  * Returns true if the value is an IdnEmail
4
4
  * @specification https://datatracker.ietf.org/doc/html/rfc4952
5
+ * @specification https://datatracker.ietf.org/doc/html/rfc6531
5
6
  */
6
7
  export function IsIdnEmail(value) {
7
8
  return IdnEmail.test(value.normalize('NFC'));
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Returns true if the value is a valid internationalized (IDN) hostname.
3
- * @specification https://tools.ietf.org/html/rfc3490
3
+ * @specification https://datatracker.ietf.org/doc/html/rfc5890
4
4
  * @specification https://tools.ietf.org/html/rfc5891
5
5
  * @specification https://tools.ietf.org/html/rfc5892
6
6
  * @specification https://tools.ietf.org/html/rfc5893
@@ -1,7 +1,7 @@
1
1
  import * as Idna from './idna/index.mjs';
2
2
  /**
3
3
  * Returns true if the value is a valid internationalized (IDN) hostname.
4
- * @specification https://tools.ietf.org/html/rfc3490
4
+ * @specification https://datatracker.ietf.org/doc/html/rfc5890
5
5
  * @specification https://tools.ietf.org/html/rfc5891
6
6
  * @specification https://tools.ietf.org/html/rfc5892
7
7
  * @specification https://tools.ietf.org/html/rfc5893
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Returns true if the value is a IPV4 address
3
- * @specification http://tools.ietf.org/html/rfc2673#section-3.2
2
+ * Returns true if the value is an IPv4 address
3
+ * @specification https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2
4
4
  */
5
5
  export declare function IsIPv4(value: string): boolean;
@@ -1,7 +1,7 @@
1
1
  const IPv4 = /^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/;
2
2
  /**
3
- * Returns true if the value is a IPV4 address
4
- * @specification http://tools.ietf.org/html/rfc2673#section-3.2
3
+ * Returns true if the value is an IPv4 address
4
+ * @specification https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2
5
5
  */
6
6
  export function IsIPv4(value) {
7
7
  return IPv4.test(value);
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * Returns true if the value is an IPv6 address
3
- * @specification http://tools.ietf.org/html/rfc2373#section-2.2
3
+ * @specification https://datatracker.ietf.org/doc/html/rfc4291#section-2.2
4
4
  */
5
5
  export declare function IsIPv6(value: string): boolean;
@@ -1,7 +1,7 @@
1
1
  const IPv6 = /^(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:)?[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)$/i;
2
2
  /**
3
3
  * Returns true if the value is an IPv6 address
4
- * @specification http://tools.ietf.org/html/rfc2373#section-2.2
4
+ * @specification https://datatracker.ietf.org/doc/html/rfc4291#section-2.2
5
5
  */
6
6
  export function IsIPv6(value) {
7
7
  return IPv6.test(value);
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Returns true if the value is a relative json pointer
3
- * @specification https://datatracker.ietf.org/doc/html/rfc6901
2
+ * Returns true if the value is a relative JSON Pointer
3
+ * @specification https://datatracker.ietf.org/doc/html/draft-handrews-relative-json-pointer/
4
4
  * @source https://github.com/ajv-validator/ajv-formats
5
5
  */
6
6
  export declare function IsRelativeJsonPointer(value: string): boolean;
@@ -1,7 +1,7 @@
1
1
  const RelativeJsonPointer = /^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/;
2
2
  /**
3
- * Returns true if the value is a relative json pointer
4
- * @specification https://datatracker.ietf.org/doc/html/rfc6901
3
+ * Returns true if the value is a relative JSON Pointer
4
+ * @specification https://datatracker.ietf.org/doc/html/draft-handrews-relative-json-pointer/
5
5
  * @source https://github.com/ajv-validator/ajv-formats
6
6
  */
7
7
  export function IsRelativeJsonPointer(value) {
@@ -106,6 +106,7 @@ export function Build(...args) {
106
106
  2: (context, schema) => [context, schema],
107
107
  1: (schema) => [{}, schema]
108
108
  });
109
+ Engine.ResetUnique();
109
110
  Engine.ResetExternal();
110
111
  Engine.ResetFunctions();
111
112
  const stack = Engine.Stack(context, schema);