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