@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
@@ -1,397 +0,0 @@
1
- import { a as localBaseUrl, r as evaluationError, t as EvaluationError } from "./errors-BZeWj5nc.mjs";
2
- import { Type } from "typebox";
3
- import { isDeepStrictEqual } from "node:util";
4
- import { Compile } from "typebox/compile";
5
- import { Check } from "typebox/value";
6
- import { buildTimeoutAbortSignal } from "openclaw/plugin-sdk/extension-shared";
7
- import { responseWithRelease, shouldUseEnvHttpProxyForUrl, withTrustedEnvProxyGuardedFetchMode } from "openclaw/plugin-sdk/fetch-runtime";
8
- import { parseRetryAfterHeaderSeconds } from "openclaw/plugin-sdk/retry-runtime";
9
- import { fetchWithSsrFGuard } from "openclaw/plugin-sdk/ssrf-runtime";
10
- const MAX_JSON_NODES = 262144;
11
- const MAX_JSON_DEPTH = 64;
12
- const MAX_CHOICE_OPTIONS = 255;
13
- const MAX_SCORE_LEVELS = 10;
14
- function map(value, options = {}) {
15
- return Type.Unsafe({
16
- type: "object",
17
- properties: {},
18
- additionalProperties: value,
19
- ...options
20
- });
21
- }
22
- const entry = Type.Union([
23
- Type.String(),
24
- map(Type.Unknown()),
25
- Type.Array(Type.Unknown()),
26
- Type.Null()
27
- ], { description: "Text, a JSON object or array, or null. Nested values must be finite JSON. Use structure for rules, examples, and exclusions." });
28
- const instructions = Type.Optional(Type.Union(entry.anyOf, { description: "The complete judgment to make; question IDs are not read by the model. Text, structured object/array, or null. May be omitted when criteria express the judgment." }));
29
- const model = Type.String({
30
- minLength: 1,
31
- maxLength: 128,
32
- pattern: "^[a-zA-Z0-9._/-]+$"
33
- });
34
- const probability = Type.Number({
35
- minimum: 0,
36
- maximum: 1
37
- });
38
- const objectOptions = { additionalProperties: false };
39
- const noulQuestion = Type.Object({
40
- type: Type.Literal("noul"),
41
- instructions,
42
- criteria: Type.Optional(Type.Union([Type.Object({
43
- true: Type.Optional(entry),
44
- false: Type.Optional(entry)
45
- }, objectOptions), Type.Null()], { description: "Optional true (yes) and false (no) outcome definitions; each accepts text, object, array, or null." }))
46
- }, {
47
- ...objectOptions,
48
- description: "Probability of yes (0–1), not intensity; no separate confidence. Use separate Nouls for independent labels."
49
- });
50
- const choiceQuestion = Type.Object({
51
- type: Type.Literal("choice"),
52
- instructions,
53
- criteria: map(entry, {
54
- minProperties: 2,
55
- maxProperties: MAX_CHOICE_OPTIONS,
56
- description: "2–255 competing labels mapped to descriptions. Labels may include spaces, punctuation, or Unicode. Null leaves a label undescribed. Include a no-match option when needed."
57
- })
58
- }, {
59
- ...objectOptions,
60
- description: "Choose one alternative; returns its label, full probability distribution, and confidence."
61
- });
62
- const scoreQuestion = Type.Object({
63
- type: Type.Literal("score"),
64
- instructions,
65
- criteria: Type.Array(entry, {
66
- minItems: 2,
67
- maxItems: MAX_SCORE_LEVELS,
68
- description: "2–10 ordered rubric levels, indexed from zero. Returns a fractional probability-weighted position, not an integer category or a normalized 0–1 score."
69
- })
70
- }, objectOptions);
71
- const question = Type.Union([
72
- noulQuestion,
73
- choiceQuestion,
74
- scoreQuestion
75
- ]);
76
- /** Explicit shared state; independently evaluated questions never see other answers. */
77
- const EvaluateInput = Type.Object({
78
- state: Type.Union(entry.anyOf, { description: "Shared evidence/context for every question. Only supplied state is sent; no ambient conversation is collected." }),
79
- questions: map(question, {
80
- minProperties: 1,
81
- description: "Nonempty map of question IDs to Choice, Score, or Noul questions. Mix types in one call. IDs only match answers; put all meaning in instructions/criteria. Questions are independent. The server enforces token limits; plugin JSON guard is 4 MiB."
82
- }),
83
- model: Type.Optional(Type.String({
84
- ...model,
85
- description: "Host-selected System One model ID or alias. A local Kev server uses its loaded checkpoint regardless of this label."
86
- }))
87
- }, objectOptions);
88
- const inputValidator = Compile(EvaluateInput);
89
- const distribution = map(probability, {
90
- minProperties: 2,
91
- maxProperties: MAX_CHOICE_OPTIONS
92
- });
93
- const Answer = Type.Union([
94
- Type.Object({
95
- type: Type.Literal("noul"),
96
- noul: probability
97
- }, objectOptions),
98
- Type.Object({
99
- type: Type.Literal("choice"),
100
- choice: Type.String(),
101
- confidence: probability,
102
- probabilities: distribution
103
- }, objectOptions),
104
- Type.Object({
105
- type: Type.Literal("score"),
106
- score: Type.Number({
107
- minimum: 0,
108
- maximum: 9
109
- }),
110
- confidence: probability,
111
- probabilities: distribution,
112
- legend: map(entry, {
113
- minProperties: 2,
114
- maxProperties: MAX_SCORE_LEVELS
115
- })
116
- }, objectOptions)
117
- ]);
118
- const VendorResult = Type.Object({
119
- model,
120
- answers: map(Answer, { minProperties: 1 }),
121
- usage: Type.Object({
122
- input_tokens: Type.Integer({
123
- minimum: 0,
124
- maximum: Number.MAX_SAFE_INTEGER
125
- }),
126
- output_tokens: Type.Integer({
127
- minimum: 0,
128
- maximum: Number.MAX_SAFE_INTEGER
129
- })
130
- }, objectOptions)
131
- }, objectOptions);
132
- const resultValidator = Compile(VendorResult);
133
- /** Reject non-JSON values and excessive structure before schema walking or serialization. */
134
- function assertBoundedJson(value) {
135
- let nodes = 0;
136
- const visit = (node, depth) => {
137
- if (++nodes > MAX_JSON_NODES || depth > MAX_JSON_DEPTH) throw new EvaluationError("TypeSafe JSON exceeds resource limits (262144 nodes or depth 64).", "unsupported-input");
138
- if (node === null || typeof node === "string" || typeof node === "boolean") return;
139
- if (typeof node === "number" && Number.isFinite(node)) return;
140
- if (typeof node !== "object" || !node) throw new EvaluationError("TypeSafe input must be JSON.", "unsupported-input");
141
- const array = Array.isArray(node);
142
- const prototype = Object.getPrototypeOf(node);
143
- if (array ? prototype !== Array.prototype : prototype !== Object.prototype && prototype !== null) throw new EvaluationError("TypeSafe input must be plain JSON.", "unsupported-input");
144
- if (array) {
145
- if (node.length > MAX_JSON_NODES || Object.keys(node).length !== node.length || Object.hasOwn(node, "toJSON")) throw new EvaluationError("TypeSafe input must be a bounded JSON array.", "unsupported-input");
146
- for (let index = 0; index < node.length; index++) {
147
- const descriptor = Object.getOwnPropertyDescriptor(node, index);
148
- if (!descriptor?.enumerable || !("value" in descriptor)) throw new EvaluationError("TypeSafe input must be plain JSON.", "unsupported-input");
149
- visit(descriptor.value, depth + 1);
150
- }
151
- return;
152
- }
153
- for (const key of Object.getOwnPropertyNames(node)) {
154
- if ([
155
- "__proto__",
156
- "constructor",
157
- "prototype"
158
- ].includes(key)) throw new EvaluationError("TypeSafe input contains a reserved key.", "unsupported-input");
159
- const descriptor = Object.getOwnPropertyDescriptor(node, key);
160
- if (!descriptor?.enumerable || !("value" in descriptor)) throw new EvaluationError("TypeSafe input must be plain JSON.", "unsupported-input");
161
- visit(descriptor.value, depth + 1);
162
- }
163
- };
164
- visit(value, 0);
165
- if (Buffer.byteLength(JSON.stringify(value), "utf8") > 4194304) throw new EvaluationError("TypeSafe JSON exceeds the plugin resource limit of 4 MiB.", "unsupported-input");
166
- }
167
- /** Validate without including supplied state in diagnostics. */
168
- function parseInput(value) {
169
- assertBoundedJson(value);
170
- if (!inputValidator.Check(value)) {
171
- if (value && typeof value === "object" && "questions" in value && value.questions && typeof value.questions === "object" && !Array.isArray(value.questions)) {
172
- for (const [index, q] of Object.values(value.questions).entries()) if (!Check(question, q)) {
173
- const kind = q && typeof q === "object" && "type" in q ? q.type : void 0;
174
- const hint = kind === "choice" ? "Choice requires 2–255 criteria descriptions." : kind === "score" ? "Score requires 2–10 ordered criteria descriptions." : kind === "noul" ? "Noul criteria may contain only true/false descriptions, or null." : "type must be choice, score, or noul.";
175
- throw new EvaluationError(`Invalid TypeSafe questions entry #${index + 1}: ${hint} Instructions/descriptions accept text, object, array, or null; no extra question fields.`, "unsupported-input");
176
- }
177
- }
178
- throw new EvaluationError("Invalid TypeSafe evaluation input: supply state (text/object/array/null), a nonempty questions map, and optionally a valid model ID; no extra fields.", "unsupported-input");
179
- }
180
- return value;
181
- }
182
- /** Check the response schema and correspondence to this exact question batch. */
183
- function parseResult(value, input) {
184
- try {
185
- assertBoundedJson(value);
186
- if (!resultValidator.Check(value)) throw new Error();
187
- const questions = Object.entries(input.questions);
188
- if (Object.keys(value.answers).length !== questions.length) throw new Error();
189
- for (const [id, expected] of questions) {
190
- const answer = value.answers[id];
191
- if (!answer || answer.type !== expected.type) throw new Error();
192
- if (answer.type === "noul") continue;
193
- const labels = expected.type === "score" ? expected.criteria.map((_, index) => String(index)) : expected.type === "choice" ? Object.keys(expected.criteria) : [];
194
- if (Object.keys(answer.probabilities).length !== labels.length || labels.some((label) => !Object.hasOwn(answer.probabilities, label))) throw new Error();
195
- if (!(Object.values(answer.probabilities).reduce((sum, item) => sum + item, 0) > 0)) throw new Error();
196
- if (answer.type === "choice" && !labels.includes(answer.choice)) throw new Error();
197
- if (answer.type === "score" && expected.type === "score") {
198
- if (answer.score > labels.length - 1 || Object.keys(answer.legend).length !== labels.length || labels.some((label, index) => !isDeepStrictEqual(answer.legend[label], expected.criteria[index]))) throw new Error();
199
- }
200
- }
201
- return value;
202
- } catch {
203
- throw new Error("TypeSafe returned an invalid evaluation response.");
204
- }
205
- }
206
- //#endregion
207
- //#region extensions/typesafe/src/local.ts
208
- function localInput(input) {
209
- const questions = {};
210
- for (const [id, question] of Object.entries(input.questions)) {
211
- const instructions = question.instructions ?? null;
212
- if (question.type === "score") questions[id] = {
213
- ...question,
214
- instructions,
215
- criteria: question.criteria.map((level) => typeof level === "string" ? level : level === null ? "" : JSON.stringify(level))
216
- };
217
- else questions[id] = {
218
- ...question,
219
- instructions
220
- };
221
- }
222
- return {
223
- ...input,
224
- questions
225
- };
226
- }
227
- function parseLocalResult(value, wireInput, originalInput) {
228
- if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("Invalid local System One response.");
229
- let result = value;
230
- if ("latency_ms" in value) {
231
- const { latency_ms, ...payload } = value;
232
- if (typeof latency_ms !== "number" || !Number.isFinite(latency_ms) || latency_ms < 0) throw new Error("Invalid local System One latency metadata.");
233
- result = payload;
234
- }
235
- const evaluation = parseResult(result, wireInput);
236
- for (const [id, question] of Object.entries(originalInput.questions)) {
237
- const answer = evaluation.answers[id];
238
- if (question.type === "score" && answer?.type === "score") answer.legend = Object.fromEntries(question.criteria.map((level, index) => [String(index), level]));
239
- }
240
- return evaluation;
241
- }
242
- //#endregion
243
- //#region extensions/typesafe/src/transport.ts
244
- const ENDPOINT = "https://api.typesafe.ai/v1/systemone";
245
- function httpError(response) {
246
- if (response.status === 401 || response.status === 403) return new EvaluationError("TypeSafe authentication failed; check the configured credential and account access.", "authentication");
247
- if (response.status === 429) {
248
- const milliseconds = response.headers.get("retry-after-ms");
249
- const parsedMilliseconds = milliseconds?.trim() ? Number(milliseconds) : NaN;
250
- const seconds = parseRetryAfterHeaderSeconds(response.headers.get("retry-after"));
251
- const retryAfterMs = Number.isFinite(parsedMilliseconds) && parsedMilliseconds >= 0 ? parsedMilliseconds : seconds === void 0 ? void 0 : seconds * 1e3;
252
- return new EvaluationError("TypeSafe rate limit reached; retry later.", "rate-limited", retryAfterMs);
253
- }
254
- if (response.status === 400 || response.status === 413 || response.status === 422) return new EvaluationError("TypeSafe rejected the supplied input.", "unsupported-input");
255
- return new EvaluationError("TypeSafe service rejected the evaluation request.", "transport");
256
- }
257
- async function readBody(response, signal) {
258
- const reader = response.body?.getReader();
259
- if (!reader) {
260
- signal?.throwIfAborted();
261
- return Buffer.alloc(0);
262
- }
263
- let cancellation;
264
- const cancel = () => {
265
- cancellation ??= reader.cancel().catch(() => {});
266
- };
267
- signal?.addEventListener("abort", cancel, { once: true });
268
- const chunks = [];
269
- let length = 0;
270
- try {
271
- while (true) {
272
- signal?.throwIfAborted();
273
- const chunk = await reader.read();
274
- signal?.throwIfAborted();
275
- if (chunk.done) break;
276
- length += chunk.value.byteLength;
277
- if (length > 4194304) throw new EvaluationError("TypeSafe response exceeds its limit.", "invalid-response");
278
- chunks.push(chunk.value);
279
- }
280
- return Buffer.concat(chunks, length);
281
- } catch (error) {
282
- cancel();
283
- throw error;
284
- } finally {
285
- signal?.removeEventListener("abort", cancel);
286
- await cancellation;
287
- reader.releaseLock();
288
- }
289
- }
290
- async function requestEvaluation(params) {
291
- const baseUrl = localBaseUrl(params.baseUrl);
292
- const endpoint = baseUrl ? `${baseUrl}/v1/systemone` : ENDPOINT;
293
- const body = JSON.stringify(params.body);
294
- if (Buffer.byteLength(body) > 4194304) throw new EvaluationError("TypeSafe request exceeds its limit.", "unsupported-input");
295
- const timeoutMs = params.deadlineMonotonicMs === void 0 ? params.timeoutMs : Math.min(params.timeoutMs, params.deadlineMonotonicMs - performance.now());
296
- if (timeoutMs <= 0) throw new EvaluationError("TypeSafe evaluation timed out.", "transport");
297
- const { signal, cleanup } = buildTimeoutAbortSignal({
298
- signal: params.signal,
299
- timeoutMs,
300
- operation: "TypeSafe evaluation"
301
- });
302
- const assertActive = () => {
303
- signal?.throwIfAborted();
304
- if (params.deadlineMonotonicMs !== void 0 && performance.now() >= params.deadlineMonotonicMs) throw new EvaluationError("TypeSafe evaluation timed out.", "transport");
305
- if (params.isAdmissible && !params.isAdmissible()) throw new EvaluationError("TypeSafe evaluation is no longer admitted.", "transport");
306
- };
307
- try {
308
- assertActive();
309
- const request = {
310
- url: endpoint,
311
- fetchImpl: globalThis.fetch,
312
- requireHttps: !baseUrl,
313
- ...baseUrl ? { policy: { allowedOrigins: [baseUrl] } } : {},
314
- ...baseUrl && new URL(baseUrl).hostname === "localhost" ? { lookupFn: async () => [{
315
- address: "127.0.0.1",
316
- family: 4
317
- }, {
318
- address: "::1",
319
- family: 6
320
- }] } : {},
321
- maxRedirects: 0,
322
- signal,
323
- beforeRequest: assertActive,
324
- init: {
325
- method: "POST",
326
- headers: {
327
- ...!baseUrl ? { Authorization: `Bearer ${params.apiKey}` } : {},
328
- Accept: "application/json",
329
- "Content-Type": "application/json"
330
- },
331
- body
332
- }
333
- };
334
- const guarded = await fetchWithSsrFGuard(!baseUrl && shouldUseEnvHttpProxyForUrl(endpoint) ? withTrustedEnvProxyGuardedFetchMode(request) : request);
335
- let releasePromise;
336
- const release = () => releasePromise ??= Promise.resolve().then(() => guarded.release());
337
- let payload;
338
- try {
339
- const response = responseWithRelease(guarded.response, release);
340
- if (!response.ok) {
341
- await response.body?.cancel();
342
- throw httpError(response);
343
- }
344
- const bytes = await readBody(response, signal);
345
- try {
346
- payload = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
347
- } catch {
348
- throw new EvaluationError("TypeSafe returned invalid JSON.", "invalid-response");
349
- }
350
- } finally {
351
- await release();
352
- }
353
- signal?.throwIfAborted();
354
- return payload;
355
- } catch (error) {
356
- if (params.signal?.aborted) throw new EvaluationError("TypeSafe evaluation cancelled.", "transport");
357
- if (signal?.aborted) throw new EvaluationError("TypeSafe evaluation timed out.", "transport");
358
- if (error instanceof EvaluationError) throw error;
359
- throw new EvaluationError("TypeSafe transport unavailable.", "transport");
360
- } finally {
361
- cleanup();
362
- }
363
- }
364
- //#endregion
365
- //#region extensions/typesafe/src/client.ts
366
- /** Evaluate explicit state without ambient credentials, retries, or vendor diagnostics. */
367
- async function evaluate(input, config, signal, deadlineMonotonicMs, isAdmissible) {
368
- if (signal?.aborted) throw evaluationError(void 0, true);
369
- const parsed = parseInput(input);
370
- const model = parsed.model;
371
- if (!model) throw new EvaluationError("TypeSafe requires a host-selected model.", "unsupported-input");
372
- if (model === "kev-latest" && !config.baseUrl) throw new EvaluationError("Kev requires a local System One server. Configure baseUrl in TypeSafe plugin Settings.", "unsupported-input");
373
- if (!config.baseUrl && !config.apiKey) throw new Error("TypeSafe API key is missing. Configure a SecretRef in plugin Settings.");
374
- try {
375
- const wireInput = config.baseUrl ? localInput(parsed) : parsed;
376
- const response = await requestEvaluation({
377
- body: {
378
- ...wireInput,
379
- model
380
- },
381
- apiKey: config.baseUrl ? void 0 : config.apiKey,
382
- baseUrl: config.baseUrl,
383
- timeoutMs: config.timeoutMs,
384
- signal,
385
- deadlineMonotonicMs,
386
- isAdmissible
387
- });
388
- signal?.throwIfAborted();
389
- const evaluation = config.baseUrl ? parseLocalResult(response, wireInput, parsed) : parseResult(response, parsed);
390
- if (!config.baseUrl && config.apiKey && JSON.stringify(evaluation).includes(config.apiKey)) throw new Error("Invalid TypeSafe response.");
391
- return { evaluation };
392
- } catch (error) {
393
- throw evaluationError(error, signal?.aborted ?? false);
394
- }
395
- }
396
- //#endregion
397
- export { evaluate };
@@ -1,4 +0,0 @@
1
- type ObjectLike = Record<PropertyKey, any>;
2
- /** Conditionally freezes the value if `immutableTypes` is true, otherwise no action. */
3
- export declare function Freeze(value: ObjectLike): ObjectLike;
4
- export {};
@@ -1,6 +0,0 @@
1
- // deno-lint-ignore-file no-explicit-any
2
- import { Settings } from '../settings/index.mjs';
3
- /** Conditionally freezes the value if `immutableTypes` is true, otherwise no action. */
4
- export function Freeze(value) {
5
- return Settings.Get().immutableTypes ? Object.freeze(value) : value;
6
- }