@openclaw/typesafe 2026.11.3 → 2026.11.5-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -2
- package/dist/.setup/client-28h1nLtb.mjs +364 -0
- package/dist/.setup/{errors-BZeWj5nc.mjs → errors-CAxlQL5v.mjs} +15 -1
- package/dist/.source-module-urls/cb128076f461604fb70d7e9adeed8a53c97339bf983a26e3f0598f525dcccb17.json +1 -0
- package/dist/index.js +436 -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-6lXBoHzi.mjs +0 -397
- package/node_modules/typebox/build/system/memory/freeze.d.mts +0 -4
- package/node_modules/typebox/build/system/memory/freeze.mjs +0 -6
package/README.md
CHANGED
|
@@ -7,8 +7,11 @@ decision-model API. Core supplies the provider-neutral `decision_evaluate` agent
|
|
|
7
7
|
tool when the agent has an effective `decisionModel` selection, subject to normal
|
|
8
8
|
tool policy and harness capabilities. No separate tool enablement is required.
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
2026.
|
|
10
|
+
This adapter requires the prepared Decision V2 API. Released OpenClaw
|
|
11
|
+
`2026.10.4` exposes V1 only. For development, use a matching source checkout
|
|
12
|
+
containing the prepared V2 runtime and this plugin. Packaged use requires a
|
|
13
|
+
supporting paired host/plugin release; the older installation floor alone does
|
|
14
|
+
not establish V2 compatibility.
|
|
12
15
|
|
|
13
16
|
```sh
|
|
14
17
|
openclaw plugins install @openclaw/typesafe
|
|
@@ -26,6 +29,29 @@ server's loopback origin, such as `http://127.0.0.1:8009`, omit `apiKey`, and se
|
|
|
26
29
|
Start the server separately with your chosen checkpoint; the decision-model
|
|
27
30
|
selection labels requests and does not download or load a model.
|
|
28
31
|
|
|
32
|
+
For a separate inference host or HTTPS reverse proxy, use the standard
|
|
33
|
+
`models.providers.typesafe` configuration with `baseUrl`, optional `apiKey`,
|
|
34
|
+
`models: []`, and the shared `request` settings for auth, private-network policy,
|
|
35
|
+
proxy, and TLS. This route never inherits the legacy hosted plugin credential.
|
|
36
|
+
Evaluations send user content to the configured server; use HTTPS and select
|
|
37
|
+
a server you trust. Set the server's routing model ID as `decisionModel`.
|
|
38
|
+
|
|
29
39
|
See the [TypeSafe AI setup guide](https://docs.openclaw.ai/plugins/typesafe) and
|
|
30
40
|
[decision-model documentation](https://docs.openclaw.ai/concepts/decision-models)
|
|
31
41
|
for configuration, rubrics, and API semantics.
|
|
42
|
+
|
|
43
|
+
## Live adapter test
|
|
44
|
+
|
|
45
|
+
From a matching source checkout, inject a TypeSafe-issued `TYPESAFE_API_KEY`
|
|
46
|
+
through your secret manager, then run:
|
|
47
|
+
|
|
48
|
+
```sh
|
|
49
|
+
OPENCLAW_LIVE_TEST=1 node scripts/run-vitest.mjs --config test/vitest/vitest.live.config.ts extensions/typesafe/src/decisions.live.test.ts
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The test sends two synthetic Boolean/Choice/Score batches (text and a generated
|
|
53
|
+
320 × 320 PNG) to hosted Jev and consumes the account's allowance. It skips without both the opt-in flag and key. It checks
|
|
54
|
+
the registered V2 adapter and real transport with an isolated prepared credential;
|
|
55
|
+
it does not test host credential discovery or change any model selection. When
|
|
56
|
+
HTTPS proxy environment settings are present, the test explicitly selects the
|
|
57
|
+
shared environment-proxy transport (including protected-key egress).
|
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
import { a as HOSTED_ORIGIN, c as providerBaseUrl, o as hasCredentials, r as evaluationError, s as localBaseUrl, t as EvaluationError, u as usesHostedEndpoint } from "./errors-CAxlQL5v.mjs";
|
|
2
|
+
import { normalizeResolvedSecretInputString } from "openclaw/plugin-sdk/secret-input";
|
|
3
|
+
import { createProviderCredentialMatcher, fetchWithProviderHttpGuard, resolveProviderHttpRequestConfigWithOriginTrust, resolveProviderTransportSsrFPolicy, sanitizeConfiguredModelProviderRequest } from "openclaw/plugin-sdk/provider-http";
|
|
4
|
+
import { buildTimeoutAbortSignal } from "openclaw/plugin-sdk/extension-shared";
|
|
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";
|
|
8
|
+
import { isDeepStrictEqual } from "node:util";
|
|
9
|
+
//#region extensions/typesafe/src/schema-validator.generated.js
|
|
10
|
+
/*!
|
|
11
|
+
TypeBox
|
|
12
|
+
|
|
13
|
+
The MIT License (MIT)
|
|
14
|
+
|
|
15
|
+
Copyright (c) 2017-2026 Haydn Paterson
|
|
16
|
+
|
|
17
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
18
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
19
|
+
in the Software without restriction, including without limitation the rights
|
|
20
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
21
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
22
|
+
furnished to do so, subject to the following conditions:
|
|
23
|
+
|
|
24
|
+
The above copyright notice and this permission notice shall be included in
|
|
25
|
+
all copies or substantial portions of the Software.
|
|
26
|
+
|
|
27
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
28
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
29
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
30
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
31
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
32
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
33
|
+
THE SOFTWARE.
|
|
34
|
+
*/
|
|
35
|
+
function CodePointCount(value) {
|
|
36
|
+
let result = 0, index = 0, prev = 0;
|
|
37
|
+
for (; index < value.length;) {
|
|
38
|
+
let next = value.charCodeAt(index++) >> 10;
|
|
39
|
+
result += +((prev << 8 | next) !== 13879), prev = next;
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
var isEvaluationInput = (() => {
|
|
44
|
+
let External = [
|
|
45
|
+
/(^state$|^questions$|^model$)/u,
|
|
46
|
+
/(?!)/u,
|
|
47
|
+
/(?!)/u,
|
|
48
|
+
/(^type$|^instructions$|^criteria$)/u,
|
|
49
|
+
/(?!)/u,
|
|
50
|
+
/(^true$|^false$)/u,
|
|
51
|
+
/(?!)/u,
|
|
52
|
+
/(?!)/u,
|
|
53
|
+
/(^type$|^instructions$|^criteria$)/u,
|
|
54
|
+
/(?!)/u,
|
|
55
|
+
/(?!)/u,
|
|
56
|
+
/(?!)/u,
|
|
57
|
+
/(^type$|^instructions$|^criteria$)/u,
|
|
58
|
+
/(?!)/u,
|
|
59
|
+
/(?!)/u,
|
|
60
|
+
/^[a-zA-Z0-9._/-]+$/u
|
|
61
|
+
], check_0 = (value) => typeof value == "object" && value !== null && !Array.isArray(value) && "state" in value && "questions" in value && Object.getOwnPropertyNames(value).every((unique_0, unique_1) => External[0].test(unique_0) || !1) && (typeof value.state == "string" || typeof value.state == "object" && value.state !== null && !Array.isArray(value.state) && Object.getOwnPropertyNames(value.state).every((unique_2, unique_3) => External[1].test(unique_2) || !0) && !0 || Array.isArray(value.state) && value.state.every((unique_4, index) => !0) || value.state === null) && typeof value.questions == "object" && value.questions !== null && !Array.isArray(value.questions) && Object.getOwnPropertyNames(value.questions).every((unique_5, unique_6) => External[2].test(unique_5) || typeof value.questions[unique_5] == "object" && value.questions[unique_5] !== null && !Array.isArray(value.questions[unique_5]) && "type" in value.questions[unique_5] && Object.getOwnPropertyNames(value.questions[unique_5]).every((unique_7, unique_8) => External[3].test(unique_7) || !1) && typeof value.questions[unique_5].type == "string" && value.questions[unique_5].type === "noul" && (value.questions[unique_5].instructions === void 0 || !("instructions" in value.questions[unique_5]) || typeof value.questions[unique_5].instructions == "string" || typeof value.questions[unique_5].instructions == "object" && value.questions[unique_5].instructions !== null && !Array.isArray(value.questions[unique_5].instructions) && Object.getOwnPropertyNames(value.questions[unique_5].instructions).every((unique_9, unique_10) => External[4].test(unique_9) || !0) && !0 || Array.isArray(value.questions[unique_5].instructions) && value.questions[unique_5].instructions.every((unique_11, index) => !0) || value.questions[unique_5].instructions === null) && (value.questions[unique_5].criteria === void 0 || !("criteria" in value.questions[unique_5]) || typeof value.questions[unique_5].criteria == "object" && value.questions[unique_5].criteria !== null && !Array.isArray(value.questions[unique_5].criteria) && Object.getOwnPropertyNames(value.questions[unique_5].criteria).every((unique_12, unique_13) => External[5].test(unique_12) || !1) && (value.questions[unique_5].criteria.true === void 0 || !("true" in value.questions[unique_5].criteria) || typeof value.questions[unique_5].criteria.true == "string" || typeof value.questions[unique_5].criteria.true == "object" && value.questions[unique_5].criteria.true !== null && !Array.isArray(value.questions[unique_5].criteria.true) && Object.getOwnPropertyNames(value.questions[unique_5].criteria.true).every((unique_14, unique_15) => External[6].test(unique_14) || !0) && !0 || Array.isArray(value.questions[unique_5].criteria.true) && value.questions[unique_5].criteria.true.every((unique_16, index) => !0) || value.questions[unique_5].criteria.true === null) && (value.questions[unique_5].criteria.false === void 0 || !("false" in value.questions[unique_5].criteria) || typeof value.questions[unique_5].criteria.false == "string" || typeof value.questions[unique_5].criteria.false == "object" && value.questions[unique_5].criteria.false !== null && !Array.isArray(value.questions[unique_5].criteria.false) && Object.getOwnPropertyNames(value.questions[unique_5].criteria.false).every((unique_17, unique_18) => External[7].test(unique_17) || !0) && !0 || Array.isArray(value.questions[unique_5].criteria.false) && value.questions[unique_5].criteria.false.every((unique_19, index) => !0) || value.questions[unique_5].criteria.false === null) || value.questions[unique_5].criteria === null) || typeof value.questions[unique_5] == "object" && value.questions[unique_5] !== null && !Array.isArray(value.questions[unique_5]) && "type" in value.questions[unique_5] && "criteria" in value.questions[unique_5] && Object.getOwnPropertyNames(value.questions[unique_5]).every((unique_20, unique_21) => External[8].test(unique_20) || !1) && typeof value.questions[unique_5].type == "string" && value.questions[unique_5].type === "choice" && (value.questions[unique_5].instructions === void 0 || !("instructions" in value.questions[unique_5]) || typeof value.questions[unique_5].instructions == "string" || typeof value.questions[unique_5].instructions == "object" && value.questions[unique_5].instructions !== null && !Array.isArray(value.questions[unique_5].instructions) && Object.getOwnPropertyNames(value.questions[unique_5].instructions).every((unique_22, unique_23) => External[9].test(unique_22) || !0) && !0 || Array.isArray(value.questions[unique_5].instructions) && value.questions[unique_5].instructions.every((unique_24, index) => !0) || value.questions[unique_5].instructions === null) && typeof value.questions[unique_5].criteria == "object" && value.questions[unique_5].criteria !== null && !Array.isArray(value.questions[unique_5].criteria) && Object.getOwnPropertyNames(value.questions[unique_5].criteria).every((unique_25, unique_26) => External[10].test(unique_25) || typeof value.questions[unique_5].criteria[unique_25] == "string" || typeof value.questions[unique_5].criteria[unique_25] == "object" && value.questions[unique_5].criteria[unique_25] !== null && !Array.isArray(value.questions[unique_5].criteria[unique_25]) && Object.getOwnPropertyNames(value.questions[unique_5].criteria[unique_25]).every((unique_27, unique_28) => External[11].test(unique_27) || !0) && !0 || Array.isArray(value.questions[unique_5].criteria[unique_25]) && value.questions[unique_5].criteria[unique_25].every((unique_29, index) => !0) || value.questions[unique_5].criteria[unique_25] === null) && Object.getOwnPropertyNames(value.questions[unique_5].criteria).length >= 2 && Object.getOwnPropertyNames(value.questions[unique_5].criteria).length <= 255 || typeof value.questions[unique_5] == "object" && value.questions[unique_5] !== null && !Array.isArray(value.questions[unique_5]) && "type" in value.questions[unique_5] && "criteria" in value.questions[unique_5] && Object.getOwnPropertyNames(value.questions[unique_5]).every((unique_30, unique_31) => External[12].test(unique_30) || !1) && typeof value.questions[unique_5].type == "string" && value.questions[unique_5].type === "score" && (value.questions[unique_5].instructions === void 0 || !("instructions" in value.questions[unique_5]) || typeof value.questions[unique_5].instructions == "string" || typeof value.questions[unique_5].instructions == "object" && value.questions[unique_5].instructions !== null && !Array.isArray(value.questions[unique_5].instructions) && Object.getOwnPropertyNames(value.questions[unique_5].instructions).every((unique_32, unique_33) => External[13].test(unique_32) || !0) && !0 || Array.isArray(value.questions[unique_5].instructions) && value.questions[unique_5].instructions.every((unique_34, index) => !0) || value.questions[unique_5].instructions === null) && Array.isArray(value.questions[unique_5].criteria) && value.questions[unique_5].criteria.every((unique_35, index) => typeof unique_35 == "string" || typeof unique_35 == "object" && unique_35 !== null && !Array.isArray(unique_35) && Object.getOwnPropertyNames(unique_35).every((unique_36, unique_37) => External[14].test(unique_36) || !0) && !0 || Array.isArray(unique_35) && unique_35.every((unique_38, index2) => !0) || unique_35 === null) && value.questions[unique_5].criteria.length >= 2 && value.questions[unique_5].criteria.length <= 10) && Object.getOwnPropertyNames(value.questions).length >= 1 && (value.model === void 0 || !("model" in value) || typeof value.model == "string" && (value.model.length >= 2 || value.model.length >= 1 && CodePointCount(value.model) >= 1) && (value.model.length <= 128 || value.model.length <= 256 && CodePointCount(value.model) <= 128) && External[15].test(value.model));
|
|
62
|
+
return (value) => check_0(value);
|
|
63
|
+
})();
|
|
64
|
+
var isEvaluation = (() => {
|
|
65
|
+
let External = [
|
|
66
|
+
/^[a-zA-Z0-9._/-]+$/u,
|
|
67
|
+
/(?!)/u,
|
|
68
|
+
/(?!)/u,
|
|
69
|
+
/(?!)/u,
|
|
70
|
+
/(?!)/u,
|
|
71
|
+
/(?!)/u
|
|
72
|
+
], check_0 = (value) => typeof value == "object" && value !== null && !Array.isArray(value) && "model" in value && "answers" in value && "usage" in value && typeof value.model == "string" && (value.model.length >= 2 || value.model.length >= 1 && CodePointCount(value.model) >= 1) && (value.model.length <= 128 || value.model.length <= 256 && CodePointCount(value.model) <= 128) && External[0].test(value.model) && typeof value.answers == "object" && value.answers !== null && !Array.isArray(value.answers) && Object.getOwnPropertyNames(value.answers).every((unique_0, unique_1) => External[1].test(unique_0) || typeof value.answers[unique_0] == "object" && value.answers[unique_0] !== null && !Array.isArray(value.answers[unique_0]) && "type" in value.answers[unique_0] && "noul" in value.answers[unique_0] && Object.getOwnPropertyNames(value.answers[unique_0]).length === 2 && typeof value.answers[unique_0].type == "string" && value.answers[unique_0].type === "noul" && Number.isFinite(value.answers[unique_0].noul) && value.answers[unique_0].noul >= 0 && value.answers[unique_0].noul <= 1 || typeof value.answers[unique_0] == "object" && value.answers[unique_0] !== null && !Array.isArray(value.answers[unique_0]) && "type" in value.answers[unique_0] && "choice" in value.answers[unique_0] && "confidence" in value.answers[unique_0] && "probabilities" in value.answers[unique_0] && Object.getOwnPropertyNames(value.answers[unique_0]).length === 4 && typeof value.answers[unique_0].type == "string" && value.answers[unique_0].type === "choice" && typeof value.answers[unique_0].choice == "string" && Number.isFinite(value.answers[unique_0].confidence) && value.answers[unique_0].confidence >= 0 && value.answers[unique_0].confidence <= 1 && typeof value.answers[unique_0].probabilities == "object" && value.answers[unique_0].probabilities !== null && !Array.isArray(value.answers[unique_0].probabilities) && Object.getOwnPropertyNames(value.answers[unique_0].probabilities).every((unique_2, unique_3) => External[2].test(unique_2) || Number.isFinite(value.answers[unique_0].probabilities[unique_2]) && value.answers[unique_0].probabilities[unique_2] >= 0 && value.answers[unique_0].probabilities[unique_2] <= 1) && Object.getOwnPropertyNames(value.answers[unique_0].probabilities).length >= 2 && Object.getOwnPropertyNames(value.answers[unique_0].probabilities).length <= 255 || typeof value.answers[unique_0] == "object" && value.answers[unique_0] !== null && !Array.isArray(value.answers[unique_0]) && "type" in value.answers[unique_0] && "score" in value.answers[unique_0] && "confidence" in value.answers[unique_0] && "probabilities" in value.answers[unique_0] && "legend" in value.answers[unique_0] && Object.getOwnPropertyNames(value.answers[unique_0]).length === 5 && typeof value.answers[unique_0].type == "string" && value.answers[unique_0].type === "score" && Number.isFinite(value.answers[unique_0].score) && value.answers[unique_0].score >= 0 && value.answers[unique_0].score <= 9 && Number.isFinite(value.answers[unique_0].confidence) && value.answers[unique_0].confidence >= 0 && value.answers[unique_0].confidence <= 1 && typeof value.answers[unique_0].probabilities == "object" && value.answers[unique_0].probabilities !== null && !Array.isArray(value.answers[unique_0].probabilities) && Object.getOwnPropertyNames(value.answers[unique_0].probabilities).every((unique_4, unique_5) => External[3].test(unique_4) || Number.isFinite(value.answers[unique_0].probabilities[unique_4]) && value.answers[unique_0].probabilities[unique_4] >= 0 && value.answers[unique_0].probabilities[unique_4] <= 1) && Object.getOwnPropertyNames(value.answers[unique_0].probabilities).length >= 2 && Object.getOwnPropertyNames(value.answers[unique_0].probabilities).length <= 255 && typeof value.answers[unique_0].legend == "object" && value.answers[unique_0].legend !== null && !Array.isArray(value.answers[unique_0].legend) && Object.getOwnPropertyNames(value.answers[unique_0].legend).every((unique_6, unique_7) => External[4].test(unique_6) || typeof value.answers[unique_0].legend[unique_6] == "string" || typeof value.answers[unique_0].legend[unique_6] == "object" && value.answers[unique_0].legend[unique_6] !== null && !Array.isArray(value.answers[unique_0].legend[unique_6]) && Object.getOwnPropertyNames(value.answers[unique_0].legend[unique_6]).every((unique_8, unique_9) => External[5].test(unique_8) || !0) && !0 || Array.isArray(value.answers[unique_0].legend[unique_6]) && value.answers[unique_0].legend[unique_6].every((unique_10, index) => !0) || value.answers[unique_0].legend[unique_6] === null) && Object.getOwnPropertyNames(value.answers[unique_0].legend).length >= 2 && Object.getOwnPropertyNames(value.answers[unique_0].legend).length <= 10) && Object.getOwnPropertyNames(value.answers).length >= 1 && typeof value.usage == "object" && value.usage !== null && !Array.isArray(value.usage) && "input_tokens" in value.usage && "output_tokens" in value.usage && Number.isInteger(value.usage.input_tokens) && (!(Number.isFinite(value.usage.input_tokens) || typeof value.usage.input_tokens == "bigint") || value.usage.input_tokens >= 0 && value.usage.input_tokens <= 9007199254740991) && Number.isInteger(value.usage.output_tokens) && (!(Number.isFinite(value.usage.output_tokens) || typeof value.usage.output_tokens == "bigint") || value.usage.output_tokens >= 0 && value.usage.output_tokens <= 9007199254740991);
|
|
73
|
+
return (value) => check_0(value);
|
|
74
|
+
})();
|
|
75
|
+
var isEvaluationQuestion = (() => {
|
|
76
|
+
let External = [
|
|
77
|
+
/(^type$|^instructions$|^criteria$)/u,
|
|
78
|
+
/(?!)/u,
|
|
79
|
+
/(^true$|^false$)/u,
|
|
80
|
+
/(?!)/u,
|
|
81
|
+
/(?!)/u,
|
|
82
|
+
/(^type$|^instructions$|^criteria$)/u,
|
|
83
|
+
/(?!)/u,
|
|
84
|
+
/(?!)/u,
|
|
85
|
+
/(?!)/u,
|
|
86
|
+
/(^type$|^instructions$|^criteria$)/u,
|
|
87
|
+
/(?!)/u,
|
|
88
|
+
/(?!)/u
|
|
89
|
+
], 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
|
+
return (value) => check_0(value);
|
|
91
|
+
})();
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region extensions/typesafe/src/schema.ts
|
|
94
|
+
const MAX_JSON_BYTES = 4194304;
|
|
95
|
+
const MAX_JSON_NODES = 262144;
|
|
96
|
+
const MAX_JSON_DEPTH = 64;
|
|
97
|
+
/** Reject non-JSON values and excessive structure before schema validation or serialization. */
|
|
98
|
+
function assertBoundedJson(value) {
|
|
99
|
+
let nodes = 0;
|
|
100
|
+
const visit = (node, depth) => {
|
|
101
|
+
if (++nodes > MAX_JSON_NODES || depth > MAX_JSON_DEPTH) throw new EvaluationError("TypeSafe JSON exceeds resource limits (262144 nodes or depth 64).", "unsupported-input");
|
|
102
|
+
if (node === null || typeof node === "string" || typeof node === "boolean") return;
|
|
103
|
+
if (typeof node === "number" && Number.isFinite(node)) return;
|
|
104
|
+
if (typeof node !== "object" || !node) throw new EvaluationError("TypeSafe input must be JSON.", "unsupported-input");
|
|
105
|
+
const array = Array.isArray(node);
|
|
106
|
+
const prototype = Object.getPrototypeOf(node);
|
|
107
|
+
if (array ? prototype !== Array.prototype : prototype !== Object.prototype && prototype !== null) throw new EvaluationError("TypeSafe input must be plain JSON.", "unsupported-input");
|
|
108
|
+
if (array) {
|
|
109
|
+
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");
|
|
110
|
+
for (let index = 0; index < node.length; index++) {
|
|
111
|
+
const descriptor = Object.getOwnPropertyDescriptor(node, index);
|
|
112
|
+
if (!descriptor?.enumerable || !("value" in descriptor)) throw new EvaluationError("TypeSafe input must be plain JSON.", "unsupported-input");
|
|
113
|
+
visit(descriptor.value, depth + 1);
|
|
114
|
+
}
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
for (const key of Object.getOwnPropertyNames(node)) {
|
|
118
|
+
if ([
|
|
119
|
+
"__proto__",
|
|
120
|
+
"constructor",
|
|
121
|
+
"prototype"
|
|
122
|
+
].includes(key)) throw new EvaluationError("TypeSafe input contains a reserved key.", "unsupported-input");
|
|
123
|
+
const descriptor = Object.getOwnPropertyDescriptor(node, key);
|
|
124
|
+
if (!descriptor?.enumerable || !("value" in descriptor)) throw new EvaluationError("TypeSafe input must be plain JSON.", "unsupported-input");
|
|
125
|
+
visit(descriptor.value, depth + 1);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
visit(value, 0);
|
|
129
|
+
if (Buffer.byteLength(JSON.stringify(value), "utf8") > 4194304) throw new EvaluationError("TypeSafe JSON exceeds the plugin resource limit of 4 MiB.", "unsupported-input");
|
|
130
|
+
}
|
|
131
|
+
/** Validate without including supplied state in diagnostics. */
|
|
132
|
+
function parseInput(value) {
|
|
133
|
+
assertBoundedJson(value);
|
|
134
|
+
if (!isEvaluationInput(value)) {
|
|
135
|
+
if (value && typeof value === "object" && "questions" in value && value.questions && typeof value.questions === "object" && !Array.isArray(value.questions)) {
|
|
136
|
+
for (const [index, q] of Object.values(value.questions).entries()) if (!isEvaluationQuestion(q)) {
|
|
137
|
+
const kind = q && typeof q === "object" && "type" in q ? q.type : void 0;
|
|
138
|
+
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 EvaluationError(`Invalid TypeSafe questions entry #${index + 1}: ${hint} Instructions/descriptions accept text, object, array, or null; no extra question fields.`, "unsupported-input");
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
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");
|
|
143
|
+
}
|
|
144
|
+
return value;
|
|
145
|
+
}
|
|
146
|
+
/** Check the response schema and correspondence to this exact question batch. */
|
|
147
|
+
function parseResult(value, input) {
|
|
148
|
+
try {
|
|
149
|
+
assertBoundedJson(value);
|
|
150
|
+
if (!isEvaluation(value)) throw new Error();
|
|
151
|
+
const questions = Object.entries(input.questions);
|
|
152
|
+
if (Object.keys(value.answers).length !== questions.length) throw new Error();
|
|
153
|
+
for (const [id, expected] of questions) {
|
|
154
|
+
const answer = value.answers[id];
|
|
155
|
+
if (!answer || answer.type !== expected.type) throw new Error();
|
|
156
|
+
if (answer.type === "noul") continue;
|
|
157
|
+
const labels = expected.type === "score" ? expected.criteria.map((_, index) => String(index)) : expected.type === "choice" ? Object.keys(expected.criteria) : [];
|
|
158
|
+
if (Object.keys(answer.probabilities).length !== labels.length || labels.some((label) => !Object.hasOwn(answer.probabilities, label))) throw new Error();
|
|
159
|
+
if (!(Object.values(answer.probabilities).reduce((sum, item) => sum + item, 0) > 0)) throw new Error();
|
|
160
|
+
if (answer.type === "choice" && !labels.includes(answer.choice)) throw new Error();
|
|
161
|
+
if (answer.type === "score" && expected.type === "score") {
|
|
162
|
+
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();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return value;
|
|
166
|
+
} catch {
|
|
167
|
+
throw new Error("TypeSafe returned an invalid evaluation response.");
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region extensions/typesafe/src/client.ts
|
|
172
|
+
const IMAGE_OPT_IN_HEADER = "TypeSafe-Danger-Zone-Images";
|
|
173
|
+
const API_BASE_URL = `${HOSTED_ORIGIN}/v1`;
|
|
174
|
+
function httpError(response) {
|
|
175
|
+
if (response.status === 401 || response.status === 403) return new EvaluationError("TypeSafe authentication failed; check the configured credential and account access.", "authentication");
|
|
176
|
+
if (response.status === 429) {
|
|
177
|
+
const milliseconds = response.headers.get("retry-after-ms");
|
|
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
|
+
}
|
|
186
|
+
/** Evaluate explicit state without ambient credentials, retries, or vendor diagnostics. */
|
|
187
|
+
async function evaluate(input, config, abortSignal, deadlineMonotonicMs, isAdmissible, assets) {
|
|
188
|
+
if (abortSignal?.aborted) throw evaluationError(void 0, true);
|
|
189
|
+
const parsed = parseInput(input);
|
|
190
|
+
const model = parsed.model;
|
|
191
|
+
if (!model) throw new EvaluationError("TypeSafe requires a host-selected model.", "unsupported-input");
|
|
192
|
+
const hosted = usesHostedEndpoint(config);
|
|
193
|
+
if (model === "kev-latest" && hosted) throw new EvaluationError("Kev requires a local System One server. Configure baseUrl in TypeSafe plugin Settings.", "unsupported-input");
|
|
194
|
+
if (!hasCredentials(config)) throw new Error("TypeSafe API key is missing. Configure a SecretRef in plugin Settings.");
|
|
195
|
+
try {
|
|
196
|
+
let wireInput = parsed;
|
|
197
|
+
if (!assets && !hosted) {
|
|
198
|
+
const questions = {};
|
|
199
|
+
for (const [id, question] of Object.entries(parsed.questions)) {
|
|
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 } : {}
|
|
269
|
+
});
|
|
270
|
+
if (Buffer.byteLength(body) > (assets ? 33554432 : 4194304)) throw new EvaluationError("TypeSafe request exceeds its limit.", "unsupported-input");
|
|
271
|
+
const timeoutMs = deadlineMonotonicMs === void 0 ? config.timeoutMs : Math.min(config.timeoutMs, deadlineMonotonicMs - performance.now());
|
|
272
|
+
if (timeoutMs <= 0) throw new EvaluationError("TypeSafe evaluation timed out.", "transport");
|
|
273
|
+
const { signal, cleanup } = buildTimeoutAbortSignal({
|
|
274
|
+
signal: abortSignal,
|
|
275
|
+
timeoutMs,
|
|
276
|
+
operation: "TypeSafe evaluation"
|
|
277
|
+
});
|
|
278
|
+
const assertActive = () => {
|
|
279
|
+
signal?.throwIfAborted();
|
|
280
|
+
if (deadlineMonotonicMs !== void 0 && performance.now() >= deadlineMonotonicMs) throw new EvaluationError("TypeSafe evaluation timed out.", "transport");
|
|
281
|
+
if (isAdmissible && !isAdmissible()) throw new EvaluationError("TypeSafe evaluation is no longer admitted.", "transport");
|
|
282
|
+
};
|
|
283
|
+
let responsePayload;
|
|
284
|
+
try {
|
|
285
|
+
assertActive();
|
|
286
|
+
const request = {
|
|
287
|
+
url: endpoint,
|
|
288
|
+
fetchImpl: globalThis.fetch,
|
|
289
|
+
requireHttps: !baseUrl || new URL(baseUrl).protocol === "https:",
|
|
290
|
+
policy,
|
|
291
|
+
dispatcherPolicy: resolved.dispatcherPolicy,
|
|
292
|
+
...baseUrl && new URL(baseUrl).hostname === "localhost" ? { lookupFn: async () => [{
|
|
293
|
+
address: "127.0.0.1",
|
|
294
|
+
family: 4
|
|
295
|
+
}, {
|
|
296
|
+
address: "::1",
|
|
297
|
+
family: 6
|
|
298
|
+
}] } : {},
|
|
299
|
+
maxRedirects: 0,
|
|
300
|
+
signal,
|
|
301
|
+
beforeRequest: assertActive,
|
|
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");
|
|
328
|
+
}
|
|
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
|
+
}
|
|
334
|
+
signal?.throwIfAborted();
|
|
335
|
+
responsePayload = payload;
|
|
336
|
+
} catch (error) {
|
|
337
|
+
if (abortSignal?.aborted) throw new EvaluationError("TypeSafe evaluation cancelled.", "transport");
|
|
338
|
+
if (signal?.aborted) throw new EvaluationError("TypeSafe evaluation timed out.", "transport");
|
|
339
|
+
if (error instanceof EvaluationError) throw error;
|
|
340
|
+
throw new EvaluationError("TypeSafe transport unavailable.", "transport");
|
|
341
|
+
} finally {
|
|
342
|
+
cleanup();
|
|
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]));
|
|
357
|
+
}
|
|
358
|
+
return { evaluation };
|
|
359
|
+
} catch (error) {
|
|
360
|
+
throw evaluationError(error, abortSignal?.aborted ?? false);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
//#endregion
|
|
364
|
+
export { evaluate };
|
|
@@ -29,6 +29,20 @@ const ConfigSchema = Type.Object({
|
|
|
29
29
|
default: 3e4
|
|
30
30
|
}))
|
|
31
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
|
+
}
|
|
32
46
|
/** A configured endpoint grants access to one loopback origin, never arbitrary private hosts. */
|
|
33
47
|
function localBaseUrl(value) {
|
|
34
48
|
if (value === void 0) return;
|
|
@@ -77,4 +91,4 @@ function decisionFailure(error) {
|
|
|
77
91
|
throw new Error("TypeSafe decision adapter contract failure.");
|
|
78
92
|
}
|
|
79
93
|
//#endregion
|
|
80
|
-
export {
|
|
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 };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"entries":[{"output":"index.js","source":"extensions/typesafe/index.ts"}],"chunks":[{"output":".setup/client-28h1nLtb.mjs","sha256":"c2e0db4d6cb47bcda8344d8e566cf0b9bb3359e58cbc41bc7d5678bdf9be945e","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/errors-CAxlQL5v.mjs","sha256":"f6305d81e1570cef8ef01ac9c437653ecd74e6fe010c8285cd617b406542d0d9","facadeSource":null,"sources":["extensions/typesafe/src/config.ts","extensions/typesafe/src/errors.ts"]},{"output":"index.js","sha256":"268977472d78374b80e56692520c30f62352b7f93678ffdf015cf34e156fb117","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":[]}
|