@openclaw/typesafe 2026.11.5-beta.4 → 2026.11.10-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.
- package/dist/.setup/{client-28h1nLtb.mjs → client-S5DvfIJa.mjs} +74 -205
- package/dist/.setup/decision-codec-BJkpuJSs.mjs +136 -0
- package/dist/.source-module-urls/cb128076f461604fb70d7e9adeed8a53c97339bf983a26e3f0598f525dcccb17.json +1 -1
- package/dist/index.js +14 -147
- package/node_modules/typebox/build/format/date_time.d.mts +2 -1
- package/node_modules/typebox/build/format/date_time.mjs +12 -3
- package/node_modules/typebox/package.json +1 -1
- package/package.json +5 -5
- package/dist/.setup/errors-CAxlQL5v.mjs +0 -94
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { responseWithRelease, shouldUseEnvHttpProxyForUrl, withTrustedEnvProxyGuardedFetchMode } from "openclaw/plugin-sdk/fetch-runtime";
|
|
6
|
-
import { readResponseWithLimit } from "openclaw/plugin-sdk/response-limit-runtime";
|
|
7
|
-
import { parseRetryAfterHeaderSeconds } from "openclaw/plugin-sdk/retry-runtime";
|
|
1
|
+
import { c as providerBaseUrl, n as encodeTypeSafeLocalInput, o as HOSTED_ORIGIN, r as restoreTypeSafeLocalLegends, t as decodeTypeSafeDecisionResult, u as usesHostedEndpoint } from "./decision-codec-BJkpuJSs.mjs";
|
|
2
|
+
import { encodeSystemOneQuestions } from "openclaw/plugin-sdk/decisions";
|
|
3
|
+
import { evaluateDecisionHttp } from "openclaw/plugin-sdk/decisions-http-runtime";
|
|
4
|
+
import { isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
8
5
|
import { isDeepStrictEqual } from "node:util";
|
|
9
|
-
|
|
6
|
+
// extensions/typesafe/src/schema-validator.generated.js
|
|
10
7
|
/*!
|
|
11
8
|
TypeBox
|
|
12
9
|
|
|
@@ -89,8 +86,7 @@ var isEvaluationQuestion = (() => {
|
|
|
89
86
|
], check_0 = (value) => typeof value == "object" && value !== null && !Array.isArray(value) && "type" in value && Object.getOwnPropertyNames(value).every((unique_0, unique_1) => External[0].test(unique_0) || !1) && typeof value.type == "string" && value.type === "noul" && (value.instructions === void 0 || !("instructions" in value) || typeof value.instructions == "string" || typeof value.instructions == "object" && value.instructions !== null && !Array.isArray(value.instructions) && Object.getOwnPropertyNames(value.instructions).every((unique_2, unique_3) => External[1].test(unique_2) || !0) && !0 || Array.isArray(value.instructions) && value.instructions.every((unique_4, index) => !0) || value.instructions === null) && (value.criteria === void 0 || !("criteria" in value) || typeof value.criteria == "object" && value.criteria !== null && !Array.isArray(value.criteria) && Object.getOwnPropertyNames(value.criteria).every((unique_5, unique_6) => External[2].test(unique_5) || !1) && (value.criteria.true === void 0 || !("true" in value.criteria) || typeof value.criteria.true == "string" || typeof value.criteria.true == "object" && value.criteria.true !== null && !Array.isArray(value.criteria.true) && Object.getOwnPropertyNames(value.criteria.true).every((unique_7, unique_8) => External[3].test(unique_7) || !0) && !0 || Array.isArray(value.criteria.true) && value.criteria.true.every((unique_9, index) => !0) || value.criteria.true === null) && (value.criteria.false === void 0 || !("false" in value.criteria) || typeof value.criteria.false == "string" || typeof value.criteria.false == "object" && value.criteria.false !== null && !Array.isArray(value.criteria.false) && Object.getOwnPropertyNames(value.criteria.false).every((unique_10, unique_11) => External[4].test(unique_10) || !0) && !0 || Array.isArray(value.criteria.false) && value.criteria.false.every((unique_12, index) => !0) || value.criteria.false === null) || value.criteria === null) || typeof value == "object" && value !== null && !Array.isArray(value) && "type" in value && "criteria" in value && Object.getOwnPropertyNames(value).every((unique_13, unique_14) => External[5].test(unique_13) || !1) && typeof value.type == "string" && value.type === "choice" && (value.instructions === void 0 || !("instructions" in value) || typeof value.instructions == "string" || typeof value.instructions == "object" && value.instructions !== null && !Array.isArray(value.instructions) && Object.getOwnPropertyNames(value.instructions).every((unique_15, unique_16) => External[6].test(unique_15) || !0) && !0 || Array.isArray(value.instructions) && value.instructions.every((unique_17, index) => !0) || value.instructions === null) && typeof value.criteria == "object" && value.criteria !== null && !Array.isArray(value.criteria) && Object.getOwnPropertyNames(value.criteria).every((unique_18, unique_19) => External[7].test(unique_18) || typeof value.criteria[unique_18] == "string" || typeof value.criteria[unique_18] == "object" && value.criteria[unique_18] !== null && !Array.isArray(value.criteria[unique_18]) && Object.getOwnPropertyNames(value.criteria[unique_18]).every((unique_20, unique_21) => External[8].test(unique_20) || !0) && !0 || Array.isArray(value.criteria[unique_18]) && value.criteria[unique_18].every((unique_22, index) => !0) || value.criteria[unique_18] === null) && Object.getOwnPropertyNames(value.criteria).length >= 2 && Object.getOwnPropertyNames(value.criteria).length <= 255 || typeof value == "object" && value !== null && !Array.isArray(value) && "type" in value && "criteria" in value && Object.getOwnPropertyNames(value).every((unique_23, unique_24) => External[9].test(unique_23) || !1) && typeof value.type == "string" && value.type === "score" && (value.instructions === void 0 || !("instructions" in value) || typeof value.instructions == "string" || typeof value.instructions == "object" && value.instructions !== null && !Array.isArray(value.instructions) && Object.getOwnPropertyNames(value.instructions).every((unique_25, unique_26) => External[10].test(unique_25) || !0) && !0 || Array.isArray(value.instructions) && value.instructions.every((unique_27, index) => !0) || value.instructions === null) && Array.isArray(value.criteria) && value.criteria.every((unique_28, index) => typeof unique_28 == "string" || typeof unique_28 == "object" && unique_28 !== null && !Array.isArray(unique_28) && Object.getOwnPropertyNames(unique_28).every((unique_29, unique_30) => External[11].test(unique_29) || !0) && !0 || Array.isArray(unique_28) && unique_28.every((unique_31, index2) => !0) || unique_28 === null) && value.criteria.length >= 2 && value.criteria.length <= 10;
|
|
90
87
|
return (value) => check_0(value);
|
|
91
88
|
})();
|
|
92
|
-
|
|
93
|
-
//#region extensions/typesafe/src/schema.ts
|
|
89
|
+
// extensions/typesafe/src/schema.ts
|
|
94
90
|
const MAX_JSON_BYTES = 4194304;
|
|
95
91
|
const MAX_JSON_NODES = 262144;
|
|
96
92
|
const MAX_JSON_DEPTH = 64;
|
|
@@ -98,18 +94,18 @@ const MAX_JSON_DEPTH = 64;
|
|
|
98
94
|
function assertBoundedJson(value) {
|
|
99
95
|
let nodes = 0;
|
|
100
96
|
const visit = (node, depth) => {
|
|
101
|
-
if (++nodes > MAX_JSON_NODES || depth > MAX_JSON_DEPTH) throw new
|
|
97
|
+
if (++nodes > MAX_JSON_NODES || depth > MAX_JSON_DEPTH) throw new Error("TypeSafe JSON exceeds resource limits (262144 nodes or depth 64).");
|
|
102
98
|
if (node === null || typeof node === "string" || typeof node === "boolean") return;
|
|
103
99
|
if (typeof node === "number" && Number.isFinite(node)) return;
|
|
104
|
-
if (typeof node !== "object" || !node) throw new
|
|
100
|
+
if (typeof node !== "object" || !node) throw new Error("TypeSafe input must be JSON.");
|
|
105
101
|
const array = Array.isArray(node);
|
|
106
102
|
const prototype = Object.getPrototypeOf(node);
|
|
107
|
-
if (array ? prototype !== Array.prototype : prototype !== Object.prototype && prototype !== null) throw new
|
|
103
|
+
if (array ? prototype !== Array.prototype : prototype !== Object.prototype && prototype !== null) throw new Error("TypeSafe input must be plain JSON.");
|
|
108
104
|
if (array) {
|
|
109
|
-
if (node.length > MAX_JSON_NODES || Object.keys(node).length !== node.length || Object.hasOwn(node, "toJSON")) throw new
|
|
105
|
+
if (node.length > MAX_JSON_NODES || Object.keys(node).length !== node.length || Object.hasOwn(node, "toJSON")) throw new Error("TypeSafe input must be a bounded JSON array.");
|
|
110
106
|
for (let index = 0; index < node.length; index++) {
|
|
111
107
|
const descriptor = Object.getOwnPropertyDescriptor(node, index);
|
|
112
|
-
if (!descriptor?.enumerable || !("value" in descriptor)) throw new
|
|
108
|
+
if (!descriptor?.enumerable || !("value" in descriptor)) throw new Error("TypeSafe input must be plain JSON.");
|
|
113
109
|
visit(descriptor.value, depth + 1);
|
|
114
110
|
}
|
|
115
111
|
return;
|
|
@@ -119,14 +115,14 @@ function assertBoundedJson(value) {
|
|
|
119
115
|
"__proto__",
|
|
120
116
|
"constructor",
|
|
121
117
|
"prototype"
|
|
122
|
-
].includes(key)) throw new
|
|
118
|
+
].includes(key)) throw new Error("TypeSafe input contains a reserved key.");
|
|
123
119
|
const descriptor = Object.getOwnPropertyDescriptor(node, key);
|
|
124
|
-
if (!descriptor?.enumerable || !("value" in descriptor)) throw new
|
|
120
|
+
if (!descriptor?.enumerable || !("value" in descriptor)) throw new Error("TypeSafe input must be plain JSON.");
|
|
125
121
|
visit(descriptor.value, depth + 1);
|
|
126
122
|
}
|
|
127
123
|
};
|
|
128
124
|
visit(value, 0);
|
|
129
|
-
if (Buffer.byteLength(JSON.stringify(value), "utf8") > 4194304) throw new
|
|
125
|
+
if (Buffer.byteLength(JSON.stringify(value), "utf8") > 4194304) throw new Error("TypeSafe JSON exceeds the plugin resource limit of 4 MiB.");
|
|
130
126
|
}
|
|
131
127
|
/** Validate without including supplied state in diagnostics. */
|
|
132
128
|
function parseInput(value) {
|
|
@@ -136,10 +132,10 @@ function parseInput(value) {
|
|
|
136
132
|
for (const [index, q] of Object.values(value.questions).entries()) if (!isEvaluationQuestion(q)) {
|
|
137
133
|
const kind = q && typeof q === "object" && "type" in q ? q.type : void 0;
|
|
138
134
|
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.";
|
|
139
|
-
throw new
|
|
135
|
+
throw new Error(`Invalid TypeSafe questions entry #${index + 1}: ${hint} Instructions/descriptions accept text, object, array, or null; no extra question fields.`);
|
|
140
136
|
}
|
|
141
137
|
}
|
|
142
|
-
throw new
|
|
138
|
+
throw new Error("Invalid TypeSafe evaluation input: supply state (text/object/array/null), a nonempty questions map, and optionally a valid model ID; no extra fields.");
|
|
143
139
|
}
|
|
144
140
|
return value;
|
|
145
141
|
}
|
|
@@ -167,198 +163,71 @@ function parseResult(value, input) {
|
|
|
167
163
|
throw new Error("TypeSafe returned an invalid evaluation response.");
|
|
168
164
|
}
|
|
169
165
|
}
|
|
170
|
-
|
|
171
|
-
//#region extensions/typesafe/src/client.ts
|
|
166
|
+
// extensions/typesafe/src/client.ts
|
|
172
167
|
const IMAGE_OPT_IN_HEADER = "TypeSafe-Danger-Zone-Images";
|
|
173
168
|
const API_BASE_URL = `${HOSTED_ORIGIN}/v1`;
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
const parsedMilliseconds = milliseconds?.trim() ? Number(milliseconds) : NaN;
|
|
179
|
-
const seconds = parseRetryAfterHeaderSeconds(response.headers.get("retry-after"));
|
|
180
|
-
const retryAfterMs = Number.isFinite(parsedMilliseconds) && parsedMilliseconds >= 0 ? parsedMilliseconds : seconds === void 0 ? void 0 : seconds * 1e3;
|
|
181
|
-
return new EvaluationError("TypeSafe rate limit reached; retry later.", "rate-limited", retryAfterMs);
|
|
182
|
-
}
|
|
183
|
-
if (response.status === 400 || response.status === 413 || response.status === 422) return new EvaluationError("TypeSafe rejected the supplied input.", "unsupported-input");
|
|
184
|
-
return new EvaluationError("TypeSafe service rejected the evaluation request.", "transport");
|
|
185
|
-
}
|
|
169
|
+
const unsupported = {
|
|
170
|
+
status: "unavailable",
|
|
171
|
+
reason: "unsupported-input"
|
|
172
|
+
};
|
|
186
173
|
/** Evaluate explicit state without ambient credentials, retries, or vendor diagnostics. */
|
|
187
|
-
async function
|
|
188
|
-
|
|
189
|
-
const parsed = parseInput(input);
|
|
190
|
-
const model = parsed.model;
|
|
191
|
-
if (!model) throw new EvaluationError("TypeSafe requires a host-selected model.", "unsupported-input");
|
|
174
|
+
async function evaluateTypeSafeDecision(batch, assets, context, config) {
|
|
175
|
+
const model = context.model.id;
|
|
192
176
|
const hosted = usesHostedEndpoint(config);
|
|
193
|
-
if (model === "kev-latest" && hosted)
|
|
194
|
-
|
|
177
|
+
if (model === "kev-latest" && hosted) return unsupported;
|
|
178
|
+
let parsed;
|
|
179
|
+
let baseUrl;
|
|
195
180
|
try {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
const instructions = question.instructions ?? null;
|
|
201
|
-
if (question.type === "score") questions[id] = {
|
|
202
|
-
...question,
|
|
203
|
-
instructions,
|
|
204
|
-
criteria: question.criteria.map((level) => typeof level === "string" ? level : level === null ? "" : JSON.stringify(level))
|
|
205
|
-
};
|
|
206
|
-
else questions[id] = {
|
|
207
|
-
...question,
|
|
208
|
-
instructions
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
wireInput = {
|
|
212
|
-
...parsed,
|
|
213
|
-
questions
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
const baseUrl = config.providerConfig ? providerBaseUrl(config.providerConfig.baseUrl) : localBaseUrl(config.baseUrl);
|
|
217
|
-
const apiBaseUrl = config.providerConfig ? baseUrl : baseUrl ? `${baseUrl}/v1` : API_BASE_URL;
|
|
218
|
-
if (assets && apiBaseUrl !== API_BASE_URL) throw new EvaluationError("TypeSafe images require hosted Jev at /v1.", "unsupported-input");
|
|
219
|
-
let resolved;
|
|
220
|
-
let configuredRequest;
|
|
221
|
-
try {
|
|
222
|
-
configuredRequest = sanitizeConfiguredModelProviderRequest(config.providerConfig?.request);
|
|
223
|
-
const headers = {};
|
|
224
|
-
for (const [name, value] of Object.entries(config.providerConfig?.headers ?? {})) {
|
|
225
|
-
const headerValue = normalizeResolvedSecretInputString({
|
|
226
|
-
value,
|
|
227
|
-
path: `models.providers.typesafe.headers.${name}`
|
|
228
|
-
});
|
|
229
|
-
if (headerValue !== void 0) headers[name] = headerValue;
|
|
230
|
-
}
|
|
231
|
-
const credential = !baseUrl || config.providerConfig ? config.apiKey : void 0;
|
|
232
|
-
resolved = resolveProviderHttpRequestConfigWithOriginTrust({
|
|
233
|
-
provider: "typesafe",
|
|
234
|
-
capability: "other",
|
|
235
|
-
transport: "http",
|
|
236
|
-
baseUrl: apiBaseUrl,
|
|
237
|
-
defaultBaseUrl: API_BASE_URL,
|
|
238
|
-
defaultHeaders: {
|
|
239
|
-
...credential && config.providerConfig?.authHeader !== false ? { Authorization: `Bearer ${credential}` } : {},
|
|
240
|
-
Accept: "application/json",
|
|
241
|
-
"Content-Type": "application/json",
|
|
242
|
-
...headers
|
|
243
|
-
},
|
|
244
|
-
request: configuredRequest
|
|
245
|
-
});
|
|
246
|
-
} catch {
|
|
247
|
-
throw new EvaluationError("TypeSafe provider credentials or request settings are unavailable.", "credentials-unavailable");
|
|
248
|
-
}
|
|
249
|
-
resolved.headers.delete(IMAGE_OPT_IN_HEADER);
|
|
250
|
-
const reflectsCredential = createProviderCredentialMatcher({
|
|
251
|
-
headers: resolved.headers,
|
|
252
|
-
request: configuredRequest,
|
|
253
|
-
configuredHeaderNames: Object.keys(config.providerConfig?.headers ?? {}),
|
|
254
|
-
defaultAuthHeader: "Authorization",
|
|
255
|
-
defaultAuthPrefix: "Bearer "
|
|
256
|
-
});
|
|
257
|
-
if (assets) resolved.headers.set(IMAGE_OPT_IN_HEADER, "true");
|
|
258
|
-
const endpoint = `${resolved.baseUrl}/systemone`;
|
|
259
|
-
const policy = baseUrl ? resolveProviderTransportSsrFPolicy({
|
|
260
|
-
baseUrl: resolved.baseUrl,
|
|
261
|
-
url: endpoint,
|
|
262
|
-
allowPrivateNetwork: resolved.allowPrivateNetwork,
|
|
263
|
-
trustConfiguredBaseUrlOrigin: resolved.trustConfiguredBaseUrlOrigin
|
|
264
|
-
}) : void 0;
|
|
265
|
-
const body = JSON.stringify({
|
|
266
|
-
...wireInput,
|
|
267
|
-
model,
|
|
268
|
-
...assets ? { assets } : {}
|
|
181
|
+
parsed = parseInput({
|
|
182
|
+
state: batch.state.type === "text" ? batch.state.text : batch.state.value,
|
|
183
|
+
questions: encodeSystemOneQuestions(batch),
|
|
184
|
+
model
|
|
269
185
|
});
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
init: {
|
|
303
|
-
method: "POST",
|
|
304
|
-
headers: resolved.headers,
|
|
305
|
-
body
|
|
306
|
-
}
|
|
307
|
-
};
|
|
308
|
-
const guarded = await fetchWithProviderHttpGuard(!baseUrl && !resolved.dispatcherPolicy && shouldUseEnvHttpProxyForUrl(endpoint) ? withTrustedEnvProxyGuardedFetchMode(request) : request);
|
|
309
|
-
let releasePromise;
|
|
310
|
-
const release = () => releasePromise ??= Promise.resolve().then(() => guarded.release());
|
|
311
|
-
let payload;
|
|
312
|
-
try {
|
|
313
|
-
const response = responseWithRelease(guarded.response, release);
|
|
314
|
-
if (!response.ok) {
|
|
315
|
-
await response.body?.cancel();
|
|
316
|
-
throw httpError(response);
|
|
317
|
-
}
|
|
318
|
-
const bytes = await readResponseWithLimit(response, MAX_JSON_BYTES, {
|
|
319
|
-
signal,
|
|
320
|
-
onOverflow: () => new EvaluationError("TypeSafe response exceeds its limit.", "invalid-response")
|
|
321
|
-
});
|
|
322
|
-
let text;
|
|
323
|
-
try {
|
|
324
|
-
text = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
325
|
-
payload = JSON.parse(text);
|
|
326
|
-
} catch {
|
|
327
|
-
throw new EvaluationError("TypeSafe returned invalid JSON.", "invalid-response");
|
|
186
|
+
baseUrl = config.providerConfig ? providerBaseUrl(context.model.baseUrl ?? config.providerConfig.baseUrl) : config.baseUrl ? `${config.baseUrl}/v1` : API_BASE_URL;
|
|
187
|
+
} catch {
|
|
188
|
+
return unsupported;
|
|
189
|
+
}
|
|
190
|
+
const local = !assets && !hosted;
|
|
191
|
+
const wireInput = local ? encodeTypeSafeLocalInput(parsed) : parsed;
|
|
192
|
+
const body = JSON.stringify({
|
|
193
|
+
...wireInput,
|
|
194
|
+
model,
|
|
195
|
+
...assets ? { assets } : {}
|
|
196
|
+
});
|
|
197
|
+
if (assets && baseUrl !== API_BASE_URL || Buffer.byteLength(body) > (assets ? 33554432 : 4194304)) return unsupported;
|
|
198
|
+
const sendsCredential = (!config.baseUrl || Boolean(config.providerConfig)) && config.providerConfig?.authHeader !== false;
|
|
199
|
+
return evaluateDecisionHttp({
|
|
200
|
+
...context,
|
|
201
|
+
deadlineMonotonicMs: Math.min(context.deadlineMonotonicMs, performance.now() + config.timeoutMs)
|
|
202
|
+
}, {
|
|
203
|
+
provider: "typesafe",
|
|
204
|
+
baseUrl,
|
|
205
|
+
endpointPath: "systemone",
|
|
206
|
+
body,
|
|
207
|
+
requestHeaders: { [IMAGE_OPT_IN_HEADER]: assets ? "true" : null },
|
|
208
|
+
authHeaders: (apiKey) => sendsCredential && apiKey !== "typesafe-local" ? { Authorization: `Bearer ${apiKey}` } : {},
|
|
209
|
+
maxResponseBytes: MAX_JSON_BYTES,
|
|
210
|
+
decode: (payload) => {
|
|
211
|
+
let value = payload;
|
|
212
|
+
if (local) {
|
|
213
|
+
if (!isRecord(value)) throw new Error("Invalid local System One response.");
|
|
214
|
+
if ("latency_ms" in value) {
|
|
215
|
+
const { latency_ms, ...rest } = value;
|
|
216
|
+
if (typeof latency_ms !== "number" || !Number.isFinite(latency_ms) || latency_ms < 0) throw new Error("Invalid local System One latency metadata.");
|
|
217
|
+
value = rest;
|
|
328
218
|
}
|
|
329
|
-
const decodedText = JSON.stringify(payload);
|
|
330
|
-
if (reflectsCredential(text) || decodedText !== text && reflectsCredential(decodedText)) throw new EvaluationError("TypeSafe evaluation failed or returned an invalid response.", "invalid-response");
|
|
331
|
-
} finally {
|
|
332
|
-
await release();
|
|
333
219
|
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
abortSignal?.throwIfAborted();
|
|
345
|
-
if (!assets && !hosted) {
|
|
346
|
-
if (!responsePayload || typeof responsePayload !== "object" || Array.isArray(responsePayload)) throw new Error("Invalid local System One response.");
|
|
347
|
-
if ("latency_ms" in responsePayload) {
|
|
348
|
-
const { latency_ms, ...payload } = responsePayload;
|
|
349
|
-
if (typeof latency_ms !== "number" || !Number.isFinite(latency_ms) || latency_ms < 0) throw new Error("Invalid local System One latency metadata.");
|
|
350
|
-
responsePayload = payload;
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
const evaluation = parseResult(responsePayload, wireInput);
|
|
354
|
-
if (!assets && !hosted) for (const [id, question] of Object.entries(parsed.questions)) {
|
|
355
|
-
const answer = evaluation.answers[id];
|
|
356
|
-
if (question.type === "score" && answer?.type === "score") answer.legend = Object.fromEntries(question.criteria.map((level, index) => [String(index), level]));
|
|
220
|
+
const evaluation = parseResult(value, wireInput);
|
|
221
|
+
if (local) restoreTypeSafeLocalLegends(evaluation, parsed);
|
|
222
|
+
const result = decodeTypeSafeDecisionResult(batch, evaluation);
|
|
223
|
+
return result ? {
|
|
224
|
+
status: "ok",
|
|
225
|
+
result
|
|
226
|
+
} : {
|
|
227
|
+
status: "unavailable",
|
|
228
|
+
reason: "invalid-response"
|
|
229
|
+
};
|
|
357
230
|
}
|
|
358
|
-
|
|
359
|
-
} catch (error) {
|
|
360
|
-
throw evaluationError(error, abortSignal?.aborted ?? false);
|
|
361
|
-
}
|
|
231
|
+
});
|
|
362
232
|
}
|
|
363
|
-
|
|
364
|
-
export { evaluate };
|
|
233
|
+
export { evaluateTypeSafeDecision };
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { Type } from "typebox";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { decodeSystemOneResponse, isDecisionBatchV1Representable, validateDecisionBatchV2, validateDecisionResultV2 } from "openclaw/plugin-sdk/decisions";
|
|
4
|
+
// extensions/typesafe/src/config.ts
|
|
5
|
+
const LOCAL_BASE_URL_PATTERN = "^https?://(?:localhost|127\\.0\\.0\\.1|\\[::1\\])(?::[0-9]{1,5})?/?$";
|
|
6
|
+
const localBaseUrlPattern = new RegExp(LOCAL_BASE_URL_PATTERN);
|
|
7
|
+
const ConfigSchema = Type.Object({
|
|
8
|
+
baseUrl: Type.Optional(Type.String({
|
|
9
|
+
maxLength: 128,
|
|
10
|
+
pattern: LOCAL_BASE_URL_PATTERN
|
|
11
|
+
})),
|
|
12
|
+
apiKey: Type.Optional(Type.Object({
|
|
13
|
+
source: Type.Union([
|
|
14
|
+
Type.Literal("env"),
|
|
15
|
+
Type.Literal("store"),
|
|
16
|
+
Type.Literal("file"),
|
|
17
|
+
Type.Literal("exec")
|
|
18
|
+
]),
|
|
19
|
+
provider: Type.String({
|
|
20
|
+
minLength: 1,
|
|
21
|
+
maxLength: 128
|
|
22
|
+
}),
|
|
23
|
+
id: Type.String({
|
|
24
|
+
minLength: 1,
|
|
25
|
+
maxLength: 1024
|
|
26
|
+
})
|
|
27
|
+
}, { additionalProperties: false })),
|
|
28
|
+
timeoutMs: Type.Optional(Type.Integer({
|
|
29
|
+
minimum: 1e3,
|
|
30
|
+
maximum: 6e4,
|
|
31
|
+
default: 3e4
|
|
32
|
+
}))
|
|
33
|
+
}, { additionalProperties: false });
|
|
34
|
+
const HOSTED_ORIGIN = "https://api.typesafe.ai";
|
|
35
|
+
/** Model providers configure the API root; origin-only System One URLs imply /v1. */
|
|
36
|
+
function providerBaseUrl(value) {
|
|
37
|
+
const parsed = value ? URL.parse(value) : null;
|
|
38
|
+
if (!parsed || !["http:", "https:"].includes(parsed.protocol) || parsed.username || parsed.password || parsed.search || parsed.hash) throw new Error("Invalid models.providers.typesafe.baseUrl; use an HTTP(S) API base URL without credentials, query, or fragment.");
|
|
39
|
+
parsed.pathname = parsed.pathname.replace(/\/+$/, "") || "/v1";
|
|
40
|
+
return parsed.toString().replace(/\/+$/, "");
|
|
41
|
+
}
|
|
42
|
+
function usesHostedEndpoint(config) {
|
|
43
|
+
return !config.baseUrl || new URL(config.baseUrl).origin === "https://api.typesafe.ai";
|
|
44
|
+
}
|
|
45
|
+
function hasCredentials(config) {
|
|
46
|
+
return !config.credentialsUnavailable && Boolean(config.baseUrl || config.apiKey);
|
|
47
|
+
}
|
|
48
|
+
/** A configured endpoint grants access to one loopback origin, never arbitrary private hosts. */
|
|
49
|
+
function localBaseUrl(value) {
|
|
50
|
+
if (value === void 0) return;
|
|
51
|
+
const parsed = typeof value === "string" && value === value.trim() && localBaseUrlPattern.test(value) ? URL.parse(value) : null;
|
|
52
|
+
if (!parsed) throw new Error("Invalid TypeSafe baseUrl; use an http(s) loopback origin without a path, credentials, query, or fragment.");
|
|
53
|
+
return parsed.origin;
|
|
54
|
+
}
|
|
55
|
+
/** Validate runtime settings and recognize materialized credentials without resolving inputs. */
|
|
56
|
+
function runtimeConfig(config) {
|
|
57
|
+
const baseUrl = localBaseUrl(config?.baseUrl);
|
|
58
|
+
const timeoutMs = config?.timeoutMs ?? 3e4;
|
|
59
|
+
if (typeof timeoutMs !== "number" || !Number.isInteger(timeoutMs) || timeoutMs < 1e3 || timeoutMs > 6e4) throw new Error("Invalid TypeSafe configuration; check plugin Settings.");
|
|
60
|
+
if (baseUrl) return {
|
|
61
|
+
baseUrl,
|
|
62
|
+
timeoutMs
|
|
63
|
+
};
|
|
64
|
+
const key = config?.apiKey;
|
|
65
|
+
return {
|
|
66
|
+
apiKey: typeof key === "string" && key.trim() ? key : void 0,
|
|
67
|
+
timeoutMs
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
// extensions/typesafe/src/decision-codec.ts
|
|
71
|
+
function decodeTypeSafeDecisionResult(batch, evaluation) {
|
|
72
|
+
const result = decodeSystemOneResponse(batch, {
|
|
73
|
+
model: evaluation.model,
|
|
74
|
+
answers: evaluation.answers,
|
|
75
|
+
usage: {
|
|
76
|
+
input_tokens: evaluation.usage.input_tokens,
|
|
77
|
+
output_tokens: evaluation.usage.output_tokens
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return validateDecisionResultV2(batch, result) ? result : void 0;
|
|
81
|
+
}
|
|
82
|
+
/** Preserve the admitted native subset; tagged image state adds referenced assets. */
|
|
83
|
+
function translateTypeSafeDecisionBatch(batch) {
|
|
84
|
+
if (!validateDecisionBatchV2(batch)) return;
|
|
85
|
+
if (batch.state.type !== "image") return isDecisionBatchV1Representable(batch) ? { batch } : void 0;
|
|
86
|
+
const match = /^data:image\/(png|jpeg);base64,/.exec(batch.state.dataUri);
|
|
87
|
+
if (!match || Object.values(batch.questions).some((question) => question.type !== "boolean" && question.type !== "choice" && question.type !== "score")) return;
|
|
88
|
+
const callerText = JSON.stringify([batch.state.text, batch.questions]);
|
|
89
|
+
let ref = randomUUID();
|
|
90
|
+
while (callerText.includes(ref)) ref = randomUUID();
|
|
91
|
+
const translated = {
|
|
92
|
+
state: batch.state.text === void 0 ? {
|
|
93
|
+
type: "text",
|
|
94
|
+
text: ref
|
|
95
|
+
} : {
|
|
96
|
+
type: "json",
|
|
97
|
+
value: [batch.state.text, ref]
|
|
98
|
+
},
|
|
99
|
+
questions: batch.questions
|
|
100
|
+
};
|
|
101
|
+
if (!isDecisionBatchV1Representable(translated)) return;
|
|
102
|
+
return {
|
|
103
|
+
batch: translated,
|
|
104
|
+
assets: { [ref]: {
|
|
105
|
+
type: "image",
|
|
106
|
+
format: match[1] === "png" ? "png" : "jpg",
|
|
107
|
+
data_base64: batch.state.dataUri.slice(match[0].length)
|
|
108
|
+
} }
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function encodeTypeSafeLocalInput(parsed) {
|
|
112
|
+
const questions = {};
|
|
113
|
+
for (const [id, question] of Object.entries(parsed.questions)) {
|
|
114
|
+
const instructions = question.instructions ?? null;
|
|
115
|
+
if (question.type === "score") questions[id] = {
|
|
116
|
+
...question,
|
|
117
|
+
instructions,
|
|
118
|
+
criteria: question.criteria.map((level) => typeof level === "string" ? level : level === null ? "" : JSON.stringify(level))
|
|
119
|
+
};
|
|
120
|
+
else questions[id] = {
|
|
121
|
+
...question,
|
|
122
|
+
instructions
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
...parsed,
|
|
127
|
+
questions
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function restoreTypeSafeLocalLegends(evaluation, parsed) {
|
|
131
|
+
for (const [id, question] of Object.entries(parsed.questions)) {
|
|
132
|
+
const answer = evaluation.answers[id];
|
|
133
|
+
if (question.type === "score" && answer?.type === "score") answer.legend = Object.fromEntries(question.criteria.map((level, index) => [String(index), level]));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
export { ConfigSchema as a, providerBaseUrl as c, translateTypeSafeDecisionBatch as i, runtimeConfig as l, encodeTypeSafeLocalInput as n, HOSTED_ORIGIN as o, restoreTypeSafeLocalLegends as r, hasCredentials as s, decodeTypeSafeDecisionResult as t, usesHostedEndpoint as u };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"entries":[{"output":"index.js","source":"extensions/typesafe/index.ts"}],"chunks":[{"output":".setup/client-
|
|
1
|
+
{"version":3,"entries":[{"output":"index.js","source":"extensions/typesafe/index.ts"}],"chunks":[{"output":".setup/client-S5DvfIJa.mjs","sha256":"71b3d3dc84ed1ee241c6252914a76361b96cbcacaa9d384c3d8cc024232fe208","facadeSource":"extensions/typesafe/src/client.ts","sources":["extensions/typesafe/src/client.ts","extensions/typesafe/src/schema-validator.generated.js","extensions/typesafe/src/schema.ts"]},{"output":".setup/decision-codec-BJkpuJSs.mjs","sha256":"ab79ff75ba5f1f57b5a6817d7ca385750aa17ce775858f2fac4d93689945bc97","facadeSource":null,"sources":["extensions/typesafe/src/config.ts","extensions/typesafe/src/decision-codec.ts"]},{"output":"index.js","sha256":"3413c5cc0bef353332ab7a7481f1949708689a30517a1141970f2649e5606741","facadeSource":"extensions/typesafe/index.ts","sources":["extensions/typesafe/index.ts","extensions/typesafe/openclaw.plugin.json","extensions/typesafe/src/credentials.ts","extensions/typesafe/src/decisions.ts"]}],"unrenderedSources":[]}
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import { c as providerBaseUrl, i as
|
|
1
|
+
import { a as ConfigSchema, c as providerBaseUrl, i as translateTypeSafeDecisionBatch, l as runtimeConfig, s as hasCredentials } from "./.setup/decision-codec-BJkpuJSs.mjs";
|
|
2
2
|
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
|
|
3
3
|
import { findNormalizedProviderValue } from "openclaw/plugin-sdk/model-ref-parse";
|
|
4
4
|
import { resolveSecretInputString } from "openclaw/plugin-sdk/secret-input";
|
|
5
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";
|
|
8
6
|
import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime";
|
|
9
7
|
import { resolveProviderRequestHeaders } from "openclaw/plugin-sdk/provider-http";
|
|
10
8
|
import { omitNullRequestHeaders } from "openclaw/plugin-sdk/provider-request-headers";
|
|
11
|
-
|
|
9
|
+
// extensions/typesafe/src/credentials.ts
|
|
12
10
|
/** Read the active host snapshot only; never resolve refs or discover fallback credentials. */
|
|
13
11
|
function resolveRuntimeConfig(snapshot) {
|
|
14
12
|
const configured = snapshot.plugins?.entries?.typesafe?.config;
|
|
@@ -37,8 +35,7 @@ function resolveRuntimeConfig(snapshot) {
|
|
|
37
35
|
apiKey: prepared.value
|
|
38
36
|
};
|
|
39
37
|
}
|
|
40
|
-
|
|
41
|
-
//#region extensions/typesafe/openclaw.plugin.json
|
|
38
|
+
// extensions/typesafe/openclaw.plugin.json
|
|
42
39
|
var modelCatalog = { "providers": { "typesafe": {
|
|
43
40
|
"models": [
|
|
44
41
|
{
|
|
@@ -199,9 +196,8 @@ var modelCatalog = { "providers": { "typesafe": {
|
|
|
199
196
|
],
|
|
200
197
|
"authScope": "plugin"
|
|
201
198
|
} } };
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
const loadClient = createLazyRuntimeModule(() => import("./.setup/client-28h1nLtb.mjs"));
|
|
199
|
+
// extensions/typesafe/src/decisions.ts
|
|
200
|
+
const loadClient = createLazyRuntimeModule(() => import("./.setup/client-S5DvfIJa.mjs"));
|
|
205
201
|
const models = modelCatalog.providers.typesafe.models;
|
|
206
202
|
const hostedBaseUrl = providerBaseUrl(models[0].baseUrl);
|
|
207
203
|
function effectiveBaseUrl(config) {
|
|
@@ -262,108 +258,6 @@ function bindHostedFacts(inference, id, config) {
|
|
|
262
258
|
}
|
|
263
259
|
};
|
|
264
260
|
}
|
|
265
|
-
/** Translate the host-selected decision contract through the TypeSafe transport. */
|
|
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
261
|
/** The shared provider owns the same credential and full configured route as V1. */
|
|
368
262
|
function createPreparedDecisionProvider(getConfig) {
|
|
369
263
|
const common = models[0].inference.decision;
|
|
@@ -417,54 +311,28 @@ function createPreparedDecisionProvider(getConfig) {
|
|
|
417
311
|
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()) }))
|
|
418
312
|
},
|
|
419
313
|
async evaluate(batch, context) {
|
|
420
|
-
const request =
|
|
314
|
+
const request = translateTypeSafeDecisionBatch(batch);
|
|
421
315
|
if (!request || context.reasoning !== void 0 && context.reasoning !== "auto") return {
|
|
422
316
|
status: "unavailable",
|
|
423
317
|
reason: "unsupported-input"
|
|
424
318
|
};
|
|
425
|
-
const v1 = request.batch;
|
|
426
319
|
if (request.assets && !models.some((model) => model.id === context.model.id && model.inference.decision.input.includes("image"))) return {
|
|
427
320
|
status: "unavailable",
|
|
428
321
|
reason: "unsupported-input"
|
|
429
322
|
};
|
|
430
|
-
|
|
431
|
-
const
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
} : void 0;
|
|
436
|
-
const prepared = {
|
|
437
|
-
...original,
|
|
438
|
-
providerConfig,
|
|
439
|
-
apiKey: original.baseUrl && !providerConfig ? void 0 : context.auth.apiKey === "typesafe-local" ? void 0 : context.auth.apiKey
|
|
440
|
-
};
|
|
441
|
-
const outcome = await createDecisionEvaluator(() => {
|
|
442
|
-
const current = getConfig();
|
|
443
|
-
return current.baseUrl === original.baseUrl && current.providerConfig === original.providerConfig && current.apiKey === original.apiKey && current.credentialsUnavailable === original.credentialsUnavailable ? prepared : {
|
|
444
|
-
...current,
|
|
445
|
-
credentialsUnavailable: true
|
|
446
|
-
};
|
|
447
|
-
}, request.assets)(v1, {
|
|
448
|
-
model: context.model.id,
|
|
449
|
-
agentId: context.agentId,
|
|
450
|
-
signal: context.signal,
|
|
451
|
-
deadlineMonotonicMs: context.deadlineMonotonicMs,
|
|
452
|
-
isAdmissible: context.isAdmissible
|
|
453
|
-
});
|
|
454
|
-
if (outcome.status !== "ok") return outcome;
|
|
455
|
-
const result = decisionResultV1ToV2(v1, outcome.result);
|
|
456
|
-
return result ? {
|
|
457
|
-
status: "ok",
|
|
458
|
-
result
|
|
459
|
-
} : {
|
|
323
|
+
context.signal.throwIfAborted();
|
|
324
|
+
const { evaluateTypeSafeDecision } = await loadClient();
|
|
325
|
+
context.signal.throwIfAborted();
|
|
326
|
+
const config = getConfig();
|
|
327
|
+
if (!hasCredentials(config)) return {
|
|
460
328
|
status: "unavailable",
|
|
461
|
-
reason: "
|
|
329
|
+
reason: "credentials-unavailable"
|
|
462
330
|
};
|
|
331
|
+
return evaluateTypeSafeDecision(request.batch, request.assets, context, config);
|
|
463
332
|
}
|
|
464
333
|
};
|
|
465
334
|
}
|
|
466
|
-
|
|
467
|
-
//#region extensions/typesafe/index.ts
|
|
335
|
+
// extensions/typesafe/index.ts
|
|
468
336
|
var typesafe_default = definePluginEntry({
|
|
469
337
|
id: "typesafe",
|
|
470
338
|
name: "TypeSafe AI",
|
|
@@ -474,5 +342,4 @@ var typesafe_default = definePluginEntry({
|
|
|
474
342
|
api.registerDecisionProvider(createPreparedDecisionProvider(() => resolveRuntimeConfig(api.runtime.config.current())));
|
|
475
343
|
}
|
|
476
344
|
});
|
|
477
|
-
//#endregion
|
|
478
345
|
export { typesafe_default as default };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Returns true if the
|
|
2
|
+
* Returns true if the string is an [RFC 3339](https://datatracker.ietf.org/doc/html/rfc3339) date-time with optional [RFC 9557](https://datatracker.ietf.org/doc/html/rfc9557) suffix.
|
|
3
3
|
* @specification https://datatracker.ietf.org/doc/html/rfc3339
|
|
4
|
+
* @specification https://datatracker.ietf.org/doc/html/rfc9557
|
|
4
5
|
* @example `2020-12-12T20:20:40+00:00`
|
|
5
6
|
*/
|
|
6
7
|
export declare function IsDateTime(value: string): boolean;
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import { IsDate } from './date.mjs';
|
|
2
2
|
import { IsTime } from './time.mjs';
|
|
3
|
+
// ------------------------------------------------------------------
|
|
4
|
+
// RFC 9557 DATE_TIME_SUFFIX
|
|
5
|
+
// ------------------------------------------------------------------
|
|
6
|
+
const DATE_TIME_SUFFIX = /^(?:\[!?(?:(?!\.{1,2}[/\]])[A-Za-z._][A-Za-z._0-9+-]{0,13}(?:\/(?!\.{1,2}[/\]])[A-Za-z._][A-Za-z._0-9+-]{0,13})*|[+-](?:[01][0-9]|2[0-3]):[0-5][0-9])\](?:\[!?[a-z_][a-z_0-9-]*=[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*\])*|(?:\[!?[a-z_][a-z_0-9-]*=[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*\])*)$/;
|
|
3
7
|
/**
|
|
4
|
-
* Returns true if the
|
|
8
|
+
* Returns true if the string is an [RFC 3339](https://datatracker.ietf.org/doc/html/rfc3339) date-time with optional [RFC 9557](https://datatracker.ietf.org/doc/html/rfc9557) suffix.
|
|
5
9
|
* @specification https://datatracker.ietf.org/doc/html/rfc3339
|
|
10
|
+
* @specification https://datatracker.ietf.org/doc/html/rfc9557
|
|
6
11
|
* @example `2020-12-12T20:20:40+00:00`
|
|
7
12
|
*/
|
|
8
13
|
export function IsDateTime(value) {
|
|
9
|
-
const
|
|
10
|
-
|
|
14
|
+
const index = value.indexOf('[');
|
|
15
|
+
const datetime = index === -1 ? value : value.slice(0, index);
|
|
16
|
+
if (index !== -1 && !DATE_TIME_SUFFIX.test(value.slice(index)))
|
|
17
|
+
return false;
|
|
18
|
+
const split = datetime.split(/T/i);
|
|
19
|
+
return split.length === 2 && IsDate(split[0]) && IsTime(split[1]);
|
|
11
20
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openclaw/typesafe",
|
|
3
|
-
"version": "2026.11.
|
|
3
|
+
"version": "2026.11.10-beta.1",
|
|
4
4
|
"description": "OpenClaw TypeSafe typed decision provider",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"type": "module",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"typebox": "1.4.
|
|
11
|
+
"typebox": "1.4.3"
|
|
12
12
|
},
|
|
13
13
|
"openclaw": {
|
|
14
14
|
"extensions": [
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
"minHostVersion": ">=2026.9.6"
|
|
22
22
|
},
|
|
23
23
|
"compat": {
|
|
24
|
-
"pluginApi": ">=2026.11.
|
|
24
|
+
"pluginApi": ">=2026.11.10-beta.1"
|
|
25
25
|
},
|
|
26
26
|
"build": {
|
|
27
27
|
"bundledDist": false,
|
|
28
|
-
"openclawVersion": "2026.11.
|
|
28
|
+
"openclawVersion": "2026.11.10-beta.1"
|
|
29
29
|
},
|
|
30
30
|
"release": {
|
|
31
31
|
"publishToClawHub": true,
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"assets/activity.svg"
|
|
44
44
|
],
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"openclaw": ">=2026.11.
|
|
46
|
+
"openclaw": ">=2026.11.10-beta.1"
|
|
47
47
|
},
|
|
48
48
|
"peerDependenciesMeta": {
|
|
49
49
|
"openclaw": {
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { Type } from "typebox";
|
|
2
|
-
//#region extensions/typesafe/src/config.ts
|
|
3
|
-
const LOCAL_BASE_URL_PATTERN = "^https?://(?:localhost|127\\.0\\.0\\.1|\\[::1\\])(?::[0-9]{1,5})?/?$";
|
|
4
|
-
const localBaseUrlPattern = new RegExp(LOCAL_BASE_URL_PATTERN);
|
|
5
|
-
const ConfigSchema = Type.Object({
|
|
6
|
-
baseUrl: Type.Optional(Type.String({
|
|
7
|
-
maxLength: 128,
|
|
8
|
-
pattern: LOCAL_BASE_URL_PATTERN
|
|
9
|
-
})),
|
|
10
|
-
apiKey: Type.Optional(Type.Object({
|
|
11
|
-
source: Type.Union([
|
|
12
|
-
Type.Literal("env"),
|
|
13
|
-
Type.Literal("store"),
|
|
14
|
-
Type.Literal("file"),
|
|
15
|
-
Type.Literal("exec")
|
|
16
|
-
]),
|
|
17
|
-
provider: Type.String({
|
|
18
|
-
minLength: 1,
|
|
19
|
-
maxLength: 128
|
|
20
|
-
}),
|
|
21
|
-
id: Type.String({
|
|
22
|
-
minLength: 1,
|
|
23
|
-
maxLength: 1024
|
|
24
|
-
})
|
|
25
|
-
}, { additionalProperties: false })),
|
|
26
|
-
timeoutMs: Type.Optional(Type.Integer({
|
|
27
|
-
minimum: 1e3,
|
|
28
|
-
maximum: 6e4,
|
|
29
|
-
default: 3e4
|
|
30
|
-
}))
|
|
31
|
-
}, { additionalProperties: false });
|
|
32
|
-
const HOSTED_ORIGIN = "https://api.typesafe.ai";
|
|
33
|
-
/** Model providers configure the API root; origin-only System One URLs imply /v1. */
|
|
34
|
-
function providerBaseUrl(value) {
|
|
35
|
-
const parsed = value ? URL.parse(value) : null;
|
|
36
|
-
if (!parsed || !["http:", "https:"].includes(parsed.protocol) || parsed.username || parsed.password || parsed.search || parsed.hash) throw new Error("Invalid models.providers.typesafe.baseUrl; use an HTTP(S) API base URL without credentials, query, or fragment.");
|
|
37
|
-
parsed.pathname = parsed.pathname.replace(/\/+$/, "") || "/v1";
|
|
38
|
-
return parsed.toString().replace(/\/+$/, "");
|
|
39
|
-
}
|
|
40
|
-
function usesHostedEndpoint(config) {
|
|
41
|
-
return !config.baseUrl || new URL(config.baseUrl).origin === "https://api.typesafe.ai";
|
|
42
|
-
}
|
|
43
|
-
function hasCredentials(config) {
|
|
44
|
-
return !config.credentialsUnavailable && Boolean(config.baseUrl || config.apiKey);
|
|
45
|
-
}
|
|
46
|
-
/** A configured endpoint grants access to one loopback origin, never arbitrary private hosts. */
|
|
47
|
-
function localBaseUrl(value) {
|
|
48
|
-
if (value === void 0) return;
|
|
49
|
-
const parsed = typeof value === "string" && value === value.trim() && localBaseUrlPattern.test(value) ? URL.parse(value) : null;
|
|
50
|
-
if (!parsed) throw new Error("Invalid TypeSafe baseUrl; use an http(s) loopback origin without a path, credentials, query, or fragment.");
|
|
51
|
-
return parsed.origin;
|
|
52
|
-
}
|
|
53
|
-
/** Validate runtime settings and recognize materialized credentials without resolving inputs. */
|
|
54
|
-
function runtimeConfig(config) {
|
|
55
|
-
const baseUrl = localBaseUrl(config?.baseUrl);
|
|
56
|
-
const timeoutMs = config?.timeoutMs ?? 3e4;
|
|
57
|
-
if (typeof timeoutMs !== "number" || !Number.isInteger(timeoutMs) || timeoutMs < 1e3 || timeoutMs > 6e4) throw new Error("Invalid TypeSafe configuration; check plugin Settings.");
|
|
58
|
-
if (baseUrl) return {
|
|
59
|
-
baseUrl,
|
|
60
|
-
timeoutMs
|
|
61
|
-
};
|
|
62
|
-
const key = config?.apiKey;
|
|
63
|
-
return {
|
|
64
|
-
apiKey: typeof key === "string" && key.trim() ? key : void 0,
|
|
65
|
-
timeoutMs
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
//#endregion
|
|
69
|
-
//#region extensions/typesafe/src/errors.ts
|
|
70
|
-
var EvaluationError = class extends Error {
|
|
71
|
-
constructor(message, reason, retryAfterMs) {
|
|
72
|
-
super(message);
|
|
73
|
-
this.reason = reason;
|
|
74
|
-
this.retryAfterMs = retryAfterMs;
|
|
75
|
-
this.name = "EvaluationError";
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
/** Only fixed plugin diagnostics cross the provider boundary; raw causes stay discarded. */
|
|
79
|
-
function evaluationError(error, aborted) {
|
|
80
|
-
if (aborted) return new EvaluationError("TypeSafe evaluation cancelled.", "transport");
|
|
81
|
-
if (error instanceof EvaluationError) return error;
|
|
82
|
-
return new EvaluationError("TypeSafe evaluation failed or returned an invalid response.", "invalid-response");
|
|
83
|
-
}
|
|
84
|
-
/** Unexpected failures reject without retaining raw credentials or submitted state. */
|
|
85
|
-
function decisionFailure(error) {
|
|
86
|
-
if (error instanceof EvaluationError) return {
|
|
87
|
-
status: "unavailable",
|
|
88
|
-
reason: error.reason,
|
|
89
|
-
...error.retryAfterMs !== void 0 ? { retryAfterMs: error.retryAfterMs } : {}
|
|
90
|
-
};
|
|
91
|
-
throw new Error("TypeSafe decision adapter contract failure.");
|
|
92
|
-
}
|
|
93
|
-
//#endregion
|
|
94
|
-
export { HOSTED_ORIGIN as a, providerBaseUrl as c, ConfigSchema as i, runtimeConfig as l, decisionFailure as n, hasCredentials as o, evaluationError as r, localBaseUrl as s, EvaluationError as t, usesHostedEndpoint as u };
|