@openclaw/typesafe 2026.11.3 → 2026.11.5-beta.2

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-28h1nLtb.mjs +364 -0
  3. package/dist/.setup/{errors-BZeWj5nc.mjs → errors-CAxlQL5v.mjs} +15 -1
  4. package/dist/.source-module-urls/cb128076f461604fb70d7e9adeed8a53c97339bf983a26e3f0598f525dcccb17.json +1 -0
  5. package/dist/index.js +436 -65
  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-CAxlQL5v.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";
9
+ import { resolveProviderRequestHeaders } from "openclaw/plugin-sdk/provider-http";
10
+ import { omitNullRequestHeaders } from "openclaw/plugin-sdk/provider-request-headers";
5
11
  //#region extensions/typesafe/src/credentials.ts
6
- /** Only host-prepared capability snapshots may supply a credential. Never resolve or cache refs. */
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");
@@ -15,79 +38,427 @@ function resolveRuntimeConfig(snapshot) {
15
38
  };
16
39
  }
17
40
  //#endregion
41
+ //#region extensions/typesafe/openclaw.plugin.json
42
+ var modelCatalog = { "providers": { "typesafe": {
43
+ "models": [
44
+ {
45
+ "id": "jev-latest",
46
+ "name": "Jev",
47
+ "baseUrl": "https://api.typesafe.ai/v1",
48
+ "inference": {
49
+ "chat": false,
50
+ "decision": {
51
+ "protocol": "typesafe-systemone",
52
+ "input": ["text", "image"],
53
+ "questions": {
54
+ "boolean": {
55
+ "probabilities": "boolean",
56
+ "abstention": false
57
+ },
58
+ "choice": {
59
+ "probabilities": "provider-defined",
60
+ "abstention": false,
61
+ "minOptions": 2,
62
+ "maxOptions": 255
63
+ },
64
+ "score": {
65
+ "probabilities": "provider-defined",
66
+ "abstention": false,
67
+ "minOptions": 2,
68
+ "maxOptions": 10
69
+ }
70
+ },
71
+ "reasoning": { "modes": ["auto"] },
72
+ "confidence": "provider-specific",
73
+ "limits": { "image": {
74
+ "maxBytes": 4194304,
75
+ "mimeTypes": ["image/png", "image/jpeg"],
76
+ "remoteUrls": false
77
+ } }
78
+ }
79
+ }
80
+ },
81
+ {
82
+ "id": "jev-preview",
83
+ "name": "Jev Preview",
84
+ "baseUrl": "https://api.typesafe.ai/v1",
85
+ "status": "preview",
86
+ "inference": {
87
+ "chat": false,
88
+ "decision": {
89
+ "protocol": "typesafe-systemone",
90
+ "input": ["text", "image"],
91
+ "questions": {
92
+ "boolean": {
93
+ "probabilities": "boolean",
94
+ "abstention": false
95
+ },
96
+ "choice": {
97
+ "probabilities": "provider-defined",
98
+ "abstention": false,
99
+ "minOptions": 2,
100
+ "maxOptions": 255
101
+ },
102
+ "score": {
103
+ "probabilities": "provider-defined",
104
+ "abstention": false,
105
+ "minOptions": 2,
106
+ "maxOptions": 10
107
+ }
108
+ },
109
+ "reasoning": { "modes": ["auto"] },
110
+ "confidence": "provider-specific",
111
+ "limits": { "image": {
112
+ "maxBytes": 4194304,
113
+ "mimeTypes": ["image/png", "image/jpeg"],
114
+ "remoteUrls": false
115
+ } }
116
+ }
117
+ }
118
+ },
119
+ {
120
+ "id": "jev-1.13.0",
121
+ "name": "Jev 1.13.0",
122
+ "baseUrl": "https://api.typesafe.ai/v1",
123
+ "inference": {
124
+ "chat": false,
125
+ "decision": {
126
+ "protocol": "typesafe-systemone",
127
+ "input": ["text", "image"],
128
+ "questions": {
129
+ "boolean": {
130
+ "probabilities": "boolean",
131
+ "abstention": false
132
+ },
133
+ "choice": {
134
+ "probabilities": "provider-defined",
135
+ "abstention": false,
136
+ "minOptions": 2,
137
+ "maxOptions": 255
138
+ },
139
+ "score": {
140
+ "probabilities": "provider-defined",
141
+ "abstention": false,
142
+ "minOptions": 2,
143
+ "maxOptions": 10
144
+ }
145
+ },
146
+ "reasoning": { "modes": ["auto"] },
147
+ "confidence": "provider-specific",
148
+ "limits": {
149
+ "image": {
150
+ "maxBytes": 4194304,
151
+ "mimeTypes": ["image/png", "image/jpeg"],
152
+ "remoteUrls": false
153
+ },
154
+ "maxRequestTokens": 64e3,
155
+ "maxStateAndQuestionTokens": 32e3
156
+ },
157
+ "billing": {
158
+ "unit": "tokens",
159
+ "source": "provider-docs",
160
+ "usdPerMillion": {
161
+ "input": .042,
162
+ "output": 0
163
+ }
164
+ }
165
+ }
166
+ }
167
+ },
168
+ {
169
+ "id": "kev-latest",
170
+ "name": "Kev (local server)",
171
+ "inference": {
172
+ "chat": false,
173
+ "decision": {
174
+ "protocol": "typesafe-systemone",
175
+ "input": ["text"],
176
+ "questions": {
177
+ "boolean": {
178
+ "probabilities": "boolean",
179
+ "abstention": false
180
+ },
181
+ "choice": {
182
+ "probabilities": "provider-defined",
183
+ "abstention": false,
184
+ "minOptions": 2,
185
+ "maxOptions": 255
186
+ },
187
+ "score": {
188
+ "probabilities": "provider-defined",
189
+ "abstention": false,
190
+ "minOptions": 2,
191
+ "maxOptions": 10
192
+ }
193
+ },
194
+ "reasoning": { "modes": ["auto"] },
195
+ "confidence": "provider-specific"
196
+ }
197
+ }
198
+ }
199
+ ],
200
+ "authScope": "plugin"
201
+ } } };
202
+ //#endregion
18
203
  //#region extensions/typesafe/src/decisions.ts
19
- const loadClient = createLazyRuntimeModule(() => import("./.setup/client-6lXBoHzi.mjs"));
204
+ const loadClient = createLazyRuntimeModule(() => import("./.setup/client-28h1nLtb.mjs"));
205
+ const models = modelCatalog.providers.typesafe.models;
206
+ const hostedBaseUrl = providerBaseUrl(models[0].baseUrl);
207
+ function effectiveBaseUrl(config) {
208
+ return config.providerConfig ? providerBaseUrl(config.providerConfig.baseUrl) : config.baseUrl ? `${config.baseUrl}/v1` : hostedBaseUrl;
209
+ }
210
+ function bindHostedFacts(inference, id, config) {
211
+ if (!models.find((model) => model.id === id)?.inference.decision || !inference.decision) return inference;
212
+ const configured = config.providerConfig;
213
+ const configuredModel = configured?.models.find((model) => model.id === id);
214
+ const headers = (values) => Object.fromEntries(Object.entries(values ?? {}).flatMap(([name, value]) => {
215
+ if (name.trim().toLowerCase() !== "typesafe-danger-zone-long-context") return [];
216
+ const resolved = resolveSecretInputString({
217
+ value,
218
+ path: `models.providers.typesafe.headers.${name}`,
219
+ mode: "inspect"
220
+ });
221
+ const header = resolved.status === "configured_unavailable" ? "unavailable" : resolved.value;
222
+ return header === void 0 ? [] : [[name, header]];
223
+ }));
224
+ const mergedHeaders = resolveProviderRequestHeaders({
225
+ provider: "typesafe",
226
+ baseUrl: effectiveBaseUrl(config),
227
+ defaultHeaders: headers(configured?.headers),
228
+ callerHeaders: headers(configuredModel?.headers),
229
+ precedence: "caller-wins"
230
+ });
231
+ const effectiveHeaders = resolveProviderRequestHeaders({
232
+ provider: "typesafe",
233
+ baseUrl: effectiveBaseUrl(config),
234
+ defaultHeaders: mergedHeaders,
235
+ request: {
236
+ headers: headers(configured?.request?.headers),
237
+ ...configured?.request?.auth?.mode === "header" && configured.request.auth.headerName.trim().toLowerCase() === "typesafe-danger-zone-long-context" ? { auth: {
238
+ ...configured.request.auth,
239
+ value: resolveSecretInputString({
240
+ value: configured.request.auth.value,
241
+ path: "models.providers.typesafe.request.auth.value",
242
+ mode: "inspect"
243
+ }).value ?? "unavailable"
244
+ } } : {}
245
+ }
246
+ });
247
+ const hosted = effectiveBaseUrl(config) === hostedBaseUrl;
248
+ const contextHeader = new Headers(omitNullRequestHeaders(effectiveHeaders)).get("TypeSafe-Danger-Zone-Long-Context");
249
+ if (hosted && contextHeader !== "true" && contextHeader !== "unavailable") return inference;
250
+ const { billing, limits, ...decision } = inference.decision;
251
+ const { maxRequestTokens: _maxRequestTokens, maxStateAndQuestionTokens: _maxStateAndQuestionTokens, image, ...otherLimits } = limits ?? {};
252
+ return {
253
+ ...inference,
254
+ decision: {
255
+ ...decision,
256
+ ...!hosted ? { input: decision.input.filter((kind) => kind !== "image") } : {},
257
+ ...billing && (hosted || billing.source !== "provider-docs") ? { billing } : {},
258
+ ...Object.keys(otherLimits).length || hosted && image ? { limits: {
259
+ ...otherLimits,
260
+ ...hosted && image ? { image } : {}
261
+ } } : {}
262
+ }
263
+ };
264
+ }
20
265
  /** Translate the host-selected decision contract through the TypeSafe transport. */
21
- function createDecisionProvider(getConfig) {
266
+ function createDecisionEvaluator(getConfig, assets) {
267
+ return async (batch, context) => {
268
+ context.signal.throwIfAborted();
269
+ const { evaluate: evaluateTypeSafe } = await loadClient();
270
+ context.signal.throwIfAborted();
271
+ const config = getConfig();
272
+ if (!hasCredentials(config)) return {
273
+ status: "unavailable",
274
+ reason: "credentials-unavailable"
275
+ };
276
+ const remaining = context.deadlineMonotonicMs - performance.now();
277
+ if (remaining <= 0) return {
278
+ status: "unavailable",
279
+ reason: "transport"
280
+ };
281
+ const questions = Object.fromEntries(Object.entries(batch.questions).map(([id, q]) => [id, q.type === "boolean" ? {
282
+ ...q,
283
+ type: "noul"
284
+ } : q]));
285
+ try {
286
+ const { evaluation } = await evaluateTypeSafe({
287
+ state: batch.state,
288
+ questions,
289
+ model: context.model
290
+ }, {
291
+ ...config,
292
+ timeoutMs: Math.min(config.timeoutMs, remaining)
293
+ }, context.signal, context.deadlineMonotonicMs, () => {
294
+ if (context.isAdmissible && !context.isAdmissible()) return false;
295
+ const current = getConfig();
296
+ return current.baseUrl === config.baseUrl && current.providerConfig === config.providerConfig && current.apiKey === config.apiKey && !current.credentialsUnavailable;
297
+ }, assets);
298
+ context.signal.throwIfAborted();
299
+ const answers = {};
300
+ for (const [id, answer] of Object.entries(evaluation.answers)) if (answer.type === "noul") answers[id] = {
301
+ type: "boolean",
302
+ probabilityTrue: answer.noul
303
+ };
304
+ else if (answer.type === "choice") answers[id] = answer;
305
+ else {
306
+ const question = batch.questions[id];
307
+ if (!question || question.type !== "score") return {
308
+ status: "unavailable",
309
+ reason: "invalid-response"
310
+ };
311
+ answers[id] = {
312
+ type: "score",
313
+ score: answer.score,
314
+ confidence: answer.confidence,
315
+ probabilities: question.criteria.map((_level, i) => answer.probabilities[String(i)])
316
+ };
317
+ }
318
+ return {
319
+ status: "ok",
320
+ result: {
321
+ model: evaluation.model,
322
+ answers,
323
+ usage: {
324
+ inputTokens: evaluation.usage.input_tokens,
325
+ outputTokens: evaluation.usage.output_tokens
326
+ }
327
+ }
328
+ };
329
+ } catch (error) {
330
+ context.signal.throwIfAborted();
331
+ return decisionFailure(error);
332
+ }
333
+ };
334
+ }
335
+ /** Preserve the existing question/result translation; only tagged image state adds assets. */
336
+ function translateBatch(batch) {
337
+ if (!validateDecisionBatchV2(batch)) return;
338
+ if (batch.state.type !== "image") {
339
+ const text = decisionBatchV2ToV1(batch);
340
+ return text ? { batch: text } : void 0;
341
+ }
342
+ const match = /^data:image\/(png|jpeg);base64,/.exec(batch.state.dataUri);
343
+ if (!match || Object.values(batch.questions).some((question) => question.type !== "boolean" && question.type !== "choice" && question.type !== "score")) return;
344
+ const callerText = JSON.stringify([batch.state.text, batch.questions]);
345
+ let ref = randomUUID();
346
+ while (callerText.includes(ref)) ref = randomUUID();
347
+ const translated = decisionBatchV2ToV1({
348
+ state: batch.state.text === void 0 ? {
349
+ type: "text",
350
+ text: ref
351
+ } : {
352
+ type: "json",
353
+ value: [batch.state.text, ref]
354
+ },
355
+ questions: batch.questions
356
+ });
357
+ if (!translated) return;
358
+ return {
359
+ batch: translated,
360
+ assets: { [ref]: {
361
+ type: "image",
362
+ format: match[1] === "png" ? "png" : "jpg",
363
+ data_base64: batch.state.dataUri.slice(match[0].length)
364
+ } }
365
+ };
366
+ }
367
+ /** The shared provider owns the same credential and full configured route as V1. */
368
+ function createPreparedDecisionProvider(getConfig) {
369
+ const common = models[0].inference.decision;
370
+ const inference = {
371
+ chat: false,
372
+ decision: {
373
+ protocol: "typesafe-systemone",
374
+ input: ["text"],
375
+ questions: {
376
+ boolean: {
377
+ probabilities: "boolean",
378
+ abstention: false
379
+ },
380
+ choice: {
381
+ probabilities: "provider-defined",
382
+ abstention: false,
383
+ minOptions: common.questions.choice.minOptions,
384
+ maxOptions: common.questions.choice.maxOptions
385
+ },
386
+ score: {
387
+ probabilities: "provider-defined",
388
+ abstention: false,
389
+ minOptions: common.questions.score.minOptions,
390
+ maxOptions: common.questions.score.maxOptions
391
+ }
392
+ },
393
+ confidence: "provider-specific",
394
+ reasoning: { modes: ["auto"] }
395
+ }
396
+ };
22
397
  return {
23
398
  id: "typesafe",
24
- contractVersion: 1,
25
- isReady: () => {
26
- const config = getConfig();
27
- return Boolean(config.baseUrl || config.apiKey);
399
+ contractVersion: 2,
400
+ provider: {
401
+ label: "TypeSafe AI",
402
+ auth: [],
403
+ authScope: "plugin",
404
+ resolveSyntheticAuth: () => {
405
+ const config = getConfig();
406
+ if (!hasCredentials(config)) return;
407
+ return {
408
+ apiKey: config.apiKey || "typesafe-local",
409
+ source: "typesafe plugin",
410
+ mode: "api-key"
411
+ };
412
+ },
413
+ normalizeTransport: () => {
414
+ return { baseUrl: effectiveBaseUrl(getConfig()) };
415
+ },
416
+ 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
417
  },
29
418
  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 {
419
+ const request = translateBatch(batch);
420
+ if (!request || context.reasoning !== void 0 && context.reasoning !== "auto") return {
35
421
  status: "unavailable",
36
- reason: "credentials-unavailable"
422
+ reason: "unsupported-input"
37
423
  };
38
- const remaining = context.deadlineMonotonicMs - performance.now();
39
- if (remaining <= 0) return {
424
+ const v1 = request.batch;
425
+ if (request.assets && !models.some((model) => model.id === context.model.id && model.inference.decision.input.includes("image"))) return {
40
426
  status: "unavailable",
41
- reason: "transport"
427
+ reason: "unsupported-input"
42
428
  };
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
- }
429
+ const original = getConfig();
430
+ const providerConfig = original.providerConfig ? {
431
+ ...original.providerConfig,
432
+ baseUrl: context.model.baseUrl ?? original.providerConfig.baseUrl,
433
+ headers: omitNullRequestHeaders(context.model.headers) ?? original.providerConfig.headers
434
+ } : void 0;
435
+ const prepared = {
436
+ ...original,
437
+ providerConfig,
438
+ apiKey: original.baseUrl && !providerConfig ? void 0 : context.auth.apiKey === "typesafe-local" ? void 0 : context.auth.apiKey
439
+ };
440
+ const outcome = await createDecisionEvaluator(() => {
441
+ const current = getConfig();
442
+ return current.baseUrl === original.baseUrl && current.providerConfig === original.providerConfig && current.apiKey === original.apiKey && current.credentialsUnavailable === original.credentialsUnavailable ? prepared : {
443
+ ...current,
444
+ credentialsUnavailable: true
86
445
  };
87
- } catch (error) {
88
- context.signal.throwIfAborted();
89
- return decisionFailure(error);
90
- }
446
+ }, request.assets)(v1, {
447
+ model: context.model.id,
448
+ agentId: context.agentId,
449
+ signal: context.signal,
450
+ deadlineMonotonicMs: context.deadlineMonotonicMs,
451
+ isAdmissible: context.isAdmissible
452
+ });
453
+ if (outcome.status !== "ok") return outcome;
454
+ const result = decisionResultV1ToV2(v1, outcome.result);
455
+ return result ? {
456
+ status: "ok",
457
+ result
458
+ } : {
459
+ status: "unavailable",
460
+ reason: "invalid-response"
461
+ };
91
462
  }
92
463
  };
93
464
  }
@@ -99,7 +470,7 @@ var typesafe_default = definePluginEntry({
99
470
  description: "Typed decision provider for hosted Jev and local System One models.",
100
471
  configSchema: { jsonSchema: { ...ConfigSchema } },
101
472
  register(api) {
102
- api.registerDecisionProvider(createDecisionProvider(() => resolveRuntimeConfig(api.runtime.config.current())));
473
+ api.registerDecisionProvider(createPreparedDecisionProvider(() => resolveRuntimeConfig(api.runtime.config.current())));
103
474
  }
104
475
  });
105
476
  //#endregion
@@ -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);
@@ -1,2 +1,4 @@
1
- /** Returns a Unique Variable Name */
2
- export declare function Unique(): string;
1
+ /** Creates a unique variable name */
2
+ export declare function CreateUnique(): string;
3
+ /** Resets the unique variable name counter */
4
+ export declare function ResetUnique(): void;