@constal/sdk 3.4.0 → 3.6.0
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 +60 -1
- package/package.json +1 -1
- package/publish/api.json +39 -1
- package/publish/index.d.ts +283 -4
- package/publish/index.js +438 -54
package/publish/index.js
CHANGED
|
@@ -12,8 +12,8 @@ function canonicalJson(value) {
|
|
|
12
12
|
if (typeof value === "string") return JSON.stringify(value);
|
|
13
13
|
if (Array.isArray(value)) return `[${value.map(canonicalJson).join(",")}]`;
|
|
14
14
|
if (typeof value === "object") {
|
|
15
|
-
const
|
|
16
|
-
return `{${Object.keys(
|
|
15
|
+
const record11 = value;
|
|
16
|
+
return `{${Object.keys(record11).sort().filter((key) => record11[key] !== void 0).map((key) => `${JSON.stringify(key)}:${canonicalJson(record11[key])}`).join(",")}}`;
|
|
17
17
|
}
|
|
18
18
|
throw new TypeError(`canonical JSON does not support ${typeof value}`);
|
|
19
19
|
}
|
|
@@ -340,21 +340,21 @@ function validateJsonSchema(value, schema, path = "$") {
|
|
|
340
340
|
if (typeof rule.multipleOf === "number" && Math.abs(value / rule.multipleOf - Math.round(value / rule.multipleOf)) > Number.EPSILON * 8) return `${path} is not a multiple`;
|
|
341
341
|
}
|
|
342
342
|
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
343
|
-
const
|
|
344
|
-
for (const key of Array.isArray(rule.required) ? rule.required : []) if (typeof key === "string" && !(key in
|
|
343
|
+
const record11 = value;
|
|
344
|
+
for (const key of Array.isArray(rule.required) ? rule.required : []) if (typeof key === "string" && !(key in record11)) return `${path}.${key} is required`;
|
|
345
345
|
const properties = rule.properties && typeof rule.properties === "object" && !Array.isArray(rule.properties) ? rule.properties : {};
|
|
346
|
-
if (typeof rule.minProperties === "number" && Object.keys(
|
|
347
|
-
if (typeof rule.maxProperties === "number" && Object.keys(
|
|
346
|
+
if (typeof rule.minProperties === "number" && Object.keys(record11).length < rule.minProperties) return `${path} has too few properties`;
|
|
347
|
+
if (typeof rule.maxProperties === "number" && Object.keys(record11).length > rule.maxProperties) return `${path} has too many properties`;
|
|
348
348
|
if (rule.additionalProperties === false) {
|
|
349
|
-
const extra = Object.keys(
|
|
349
|
+
const extra = Object.keys(record11).find((key) => !(key in properties));
|
|
350
350
|
if (extra) return `${path}.${extra} is not allowed`;
|
|
351
351
|
}
|
|
352
|
-
for (const [key, child] of Object.entries(properties)) if (key in
|
|
353
|
-
const error = validateJsonSchema(
|
|
352
|
+
for (const [key, child] of Object.entries(properties)) if (key in record11) {
|
|
353
|
+
const error = validateJsonSchema(record11[key], child, `${path}.${key}`);
|
|
354
354
|
if (error) return error;
|
|
355
355
|
}
|
|
356
|
-
if (rule.additionalProperties && typeof rule.additionalProperties === "object") for (const key of Object.keys(
|
|
357
|
-
const error = validateJsonSchema(
|
|
356
|
+
if (rule.additionalProperties && typeof rule.additionalProperties === "object") for (const key of Object.keys(record11).filter((candidate) => !(candidate in properties))) {
|
|
357
|
+
const error = validateJsonSchema(record11[key], rule.additionalProperties, `${path}.${key}`);
|
|
358
358
|
if (error) return error;
|
|
359
359
|
}
|
|
360
360
|
}
|
|
@@ -566,6 +566,105 @@ function agentSetupMetadata(value, options = {}) {
|
|
|
566
566
|
}
|
|
567
567
|
return source;
|
|
568
568
|
}
|
|
569
|
+
var AGENT_UI_DEFAULTS = Object.freeze({
|
|
570
|
+
limits: Object.freeze({ requestBodyBytes: 131072, responseBodyBytes: 4194304, cpuMs: 1e3, subrequests: 8 }),
|
|
571
|
+
storage: Object.freeze({
|
|
572
|
+
kind: "sqlite",
|
|
573
|
+
maximumBytes: 268435456,
|
|
574
|
+
maximumRowsReadPerRequest: 1e4,
|
|
575
|
+
maximumRowsWrittenPerRequest: 1e3,
|
|
576
|
+
maximumResultBytes: 1048576
|
|
577
|
+
})
|
|
578
|
+
});
|
|
579
|
+
var AGENT_UI_ID = /^[a-z0-9][a-z0-9-]{0,62}$/u;
|
|
580
|
+
var AGENT_UI_RESERVED_SOURCE_ROOTS = ["dist", "node_modules", ".constal", ".git"];
|
|
581
|
+
function agentUiInvalid(reason) {
|
|
582
|
+
throw new TypeError(`Agent UI declaration is invalid: ${reason}`);
|
|
583
|
+
}
|
|
584
|
+
function agentUiKeys(value, allowed) {
|
|
585
|
+
const unknown = Object.keys(value).find((key) => !allowed.includes(key));
|
|
586
|
+
if (unknown !== void 0) agentUiInvalid(`unknown field ${unknown}`);
|
|
587
|
+
}
|
|
588
|
+
function agentUiBounded(value, defaults, bounds, label) {
|
|
589
|
+
const result = {};
|
|
590
|
+
for (const [key, fallback] of Object.entries(defaults)) {
|
|
591
|
+
const raw = value[key] ?? fallback;
|
|
592
|
+
if (!Number.isSafeInteger(raw) || Number(raw) < bounds[key].minimum || Number(raw) > bounds[key].maximum) agentUiInvalid(`${label}.${key} is out of bounds`);
|
|
593
|
+
result[key] = Number(raw);
|
|
594
|
+
}
|
|
595
|
+
return result;
|
|
596
|
+
}
|
|
597
|
+
function agentUiDeclaration(value) {
|
|
598
|
+
const source = record2(value);
|
|
599
|
+
if (!source) agentUiInvalid("expected an object");
|
|
600
|
+
agentUiKeys(source, ["id", "displayName", "description", "source", "channel", "access", "execution", "limits", "labels"]);
|
|
601
|
+
if (typeof source.id !== "string" || !AGENT_UI_ID.test(source.id)) agentUiInvalid("id");
|
|
602
|
+
if (typeof source.displayName !== "string" || !source.displayName.trim() || source.displayName.length > 128) agentUiInvalid("displayName");
|
|
603
|
+
const description = source.description ?? "";
|
|
604
|
+
if (typeof description !== "string" || description.length > 1024) agentUiInvalid("description");
|
|
605
|
+
const directory = source.source;
|
|
606
|
+
if (typeof directory !== "string" || !directory || directory.length > 128 || directory.startsWith("/") || directory.includes("\\") || directory.split("/").some((part) => part === "" || part === "." || part === "..")) agentUiInvalid("source");
|
|
607
|
+
if (AGENT_UI_RESERVED_SOURCE_ROOTS.includes(directory.split("/")[0])) agentUiInvalid("source is a reserved directory");
|
|
608
|
+
let channel2;
|
|
609
|
+
try {
|
|
610
|
+
channel2 = resourceDependencyRef(source.channel, ["channel"]);
|
|
611
|
+
} catch {
|
|
612
|
+
agentUiInvalid("channel");
|
|
613
|
+
}
|
|
614
|
+
const accessRaw = record2(source.access ?? { mode: "public" });
|
|
615
|
+
if (!accessRaw) agentUiInvalid("access");
|
|
616
|
+
let access;
|
|
617
|
+
if (accessRaw.mode === "public") {
|
|
618
|
+
agentUiKeys(accessRaw, ["mode"]);
|
|
619
|
+
access = { mode: "public" };
|
|
620
|
+
} else if (accessRaw.mode === "authenticated") {
|
|
621
|
+
agentUiKeys(accessRaw, ["mode", "authProvider"]);
|
|
622
|
+
let authProvider2;
|
|
623
|
+
try {
|
|
624
|
+
authProvider2 = resourceDependencyRef(accessRaw.authProvider, ["auth-provider"]);
|
|
625
|
+
} catch {
|
|
626
|
+
agentUiInvalid("access.authProvider");
|
|
627
|
+
}
|
|
628
|
+
access = { mode: "authenticated", authProvider: authProvider2 };
|
|
629
|
+
} else agentUiInvalid("access.mode");
|
|
630
|
+
const executionRaw = record2(source.execution ?? { mode: "stateless" });
|
|
631
|
+
if (!executionRaw) agentUiInvalid("execution");
|
|
632
|
+
let execution;
|
|
633
|
+
if (executionRaw.mode === "stateless") {
|
|
634
|
+
agentUiKeys(executionRaw, ["mode"]);
|
|
635
|
+
execution = { mode: "stateless" };
|
|
636
|
+
} else if (executionRaw.mode === "durable") {
|
|
637
|
+
agentUiKeys(executionRaw, ["mode", "storage"]);
|
|
638
|
+
const storageRaw = record2(executionRaw.storage ?? {});
|
|
639
|
+
if (!storageRaw) agentUiInvalid("execution.storage");
|
|
640
|
+
agentUiKeys(storageRaw, ["kind", "maximumBytes", "maximumRowsReadPerRequest", "maximumRowsWrittenPerRequest", "maximumResultBytes"]);
|
|
641
|
+
if (storageRaw.kind !== void 0 && storageRaw.kind !== "sqlite") agentUiInvalid("execution.storage.kind");
|
|
642
|
+
const { kind: _kind, ...storageDefaults } = AGENT_UI_DEFAULTS.storage;
|
|
643
|
+
const storage = agentUiBounded(storageRaw, storageDefaults, {
|
|
644
|
+
maximumBytes: { minimum: 1, maximum: UI_RESOURCE_BOUNDS.maximumDatabaseBytes },
|
|
645
|
+
maximumRowsReadPerRequest: { minimum: 1, maximum: UI_RESOURCE_BOUNDS.maximumRowsReadPerRequest },
|
|
646
|
+
maximumRowsWrittenPerRequest: { minimum: 1, maximum: UI_RESOURCE_BOUNDS.maximumRowsWrittenPerRequest },
|
|
647
|
+
maximumResultBytes: { minimum: 1, maximum: UI_RESOURCE_BOUNDS.maximumSqlResultBytes }
|
|
648
|
+
}, "execution.storage");
|
|
649
|
+
execution = { mode: "durable", storage: { kind: "sqlite", ...storage } };
|
|
650
|
+
} else agentUiInvalid("execution.mode");
|
|
651
|
+
const limitsRaw = record2(source.limits ?? {});
|
|
652
|
+
if (!limitsRaw) agentUiInvalid("limits");
|
|
653
|
+
agentUiKeys(limitsRaw, ["requestBodyBytes", "responseBodyBytes", "cpuMs", "subrequests"]);
|
|
654
|
+
const limits = agentUiBounded(limitsRaw, AGENT_UI_DEFAULTS.limits, {
|
|
655
|
+
requestBodyBytes: { minimum: 1, maximum: UI_RESOURCE_BOUNDS.maximumRequestBodyBytes },
|
|
656
|
+
responseBodyBytes: { minimum: 1, maximum: UI_RESOURCE_BOUNDS.maximumResponseBodyBytes },
|
|
657
|
+
cpuMs: { minimum: 1, maximum: UI_RESOURCE_BOUNDS.maximumCpuMs },
|
|
658
|
+
subrequests: { minimum: 0, maximum: UI_RESOURCE_BOUNDS.maximumSubrequests }
|
|
659
|
+
}, "limits");
|
|
660
|
+
let labels;
|
|
661
|
+
try {
|
|
662
|
+
labels = resourceLabelMap(source.labels ?? {});
|
|
663
|
+
} catch {
|
|
664
|
+
agentUiInvalid("labels");
|
|
665
|
+
}
|
|
666
|
+
return { id: source.id, displayName: source.displayName, description, source: directory, channel: channel2, access, execution, limits, labels };
|
|
667
|
+
}
|
|
569
668
|
function channelTarget(value) {
|
|
570
669
|
const target = record2(value);
|
|
571
670
|
if (target?.resourceKind !== "channel") return resourceSelector(value, ["agent"]);
|
|
@@ -926,11 +1025,11 @@ function normalizeCidrs(values, allowPrivate) {
|
|
|
926
1025
|
return { network, prefix, last, text: `${ipv4Text(network)}/${prefix}` };
|
|
927
1026
|
}).sort((left, right) => left.network - right.network || left.prefix - right.prefix);
|
|
928
1027
|
const result = [];
|
|
929
|
-
for (const
|
|
930
|
-
if (result.some((prior) =>
|
|
931
|
-
result.push(
|
|
1028
|
+
for (const entry2 of entries) {
|
|
1029
|
+
if (result.some((prior) => entry2.network >= prior.network && entry2.last <= prior.last)) continue;
|
|
1030
|
+
result.push(entry2);
|
|
932
1031
|
}
|
|
933
|
-
return result.map((
|
|
1032
|
+
return result.map((entry2) => entry2.text);
|
|
934
1033
|
}
|
|
935
1034
|
function normalizeDomains(values) {
|
|
936
1035
|
if (!Array.isArray(values) || values.length === 0 || values.length > 20) throw new TypeError("sandbox network domains must contain 1 to 20 entries");
|
|
@@ -1135,10 +1234,10 @@ function uiBundleManifest(value, execution) {
|
|
|
1135
1234
|
exactKeys(runtime, ["contract", "entry"], ["contract", "entry"]);
|
|
1136
1235
|
exactKeys(assets, ["root", "fallback"], ["root", "fallback"]);
|
|
1137
1236
|
if (manifest2.schemaVersion !== 1 || manifest2.kind !== "constal.ui" || runtime.contract !== "constal.ui-handler.v1" || manifest2.contentSecurityPolicy !== "strict") throw new TypeError("UI bundle manifest contract is unsupported");
|
|
1138
|
-
const
|
|
1237
|
+
const entry2 = safePath(runtime.entry, "UI bundle entry");
|
|
1139
1238
|
const root = safePath(assets.root, "UI asset root");
|
|
1140
1239
|
const fallback = safePath(assets.fallback, "UI asset fallback");
|
|
1141
|
-
if (!
|
|
1240
|
+
if (!entry2.endsWith(".mjs") || fallback.startsWith(`${root}/`)) throw new TypeError("UI bundle entry or asset fallback is invalid");
|
|
1142
1241
|
if (byteLength(JSON.stringify(manifest2)) > UI_BUNDLE_BOUNDS.maximumManifestBytes) throw new TypeError("UI bundle manifest exceeds 16 KiB");
|
|
1143
1242
|
let state;
|
|
1144
1243
|
if (execution === "stateless") {
|
|
@@ -1157,12 +1256,61 @@ function uiBundleManifest(value, execution) {
|
|
|
1157
1256
|
return {
|
|
1158
1257
|
schemaVersion: 1,
|
|
1159
1258
|
kind: "constal.ui",
|
|
1160
|
-
runtime: { contract: "constal.ui-handler.v1", entry },
|
|
1259
|
+
runtime: { contract: "constal.ui-handler.v1", entry: entry2 },
|
|
1161
1260
|
...state ? { state } : {},
|
|
1162
1261
|
assets: { root, fallback },
|
|
1163
1262
|
contentSecurityPolicy: "strict"
|
|
1164
1263
|
};
|
|
1165
1264
|
}
|
|
1265
|
+
var UI_ASSET_CONTENT_TYPES = Object.freeze({
|
|
1266
|
+
html: "text/html; charset=utf-8",
|
|
1267
|
+
htm: "text/html; charset=utf-8",
|
|
1268
|
+
js: "text/javascript; charset=utf-8",
|
|
1269
|
+
mjs: "text/javascript; charset=utf-8",
|
|
1270
|
+
css: "text/css; charset=utf-8",
|
|
1271
|
+
json: "application/json; charset=utf-8",
|
|
1272
|
+
map: "application/json; charset=utf-8",
|
|
1273
|
+
txt: "text/plain; charset=utf-8",
|
|
1274
|
+
md: "text/plain; charset=utf-8",
|
|
1275
|
+
xml: "application/xml",
|
|
1276
|
+
svg: "image/svg+xml",
|
|
1277
|
+
png: "image/png",
|
|
1278
|
+
jpg: "image/jpeg",
|
|
1279
|
+
jpeg: "image/jpeg",
|
|
1280
|
+
gif: "image/gif",
|
|
1281
|
+
webp: "image/webp",
|
|
1282
|
+
ico: "image/x-icon",
|
|
1283
|
+
woff: "font/woff",
|
|
1284
|
+
woff2: "font/woff2",
|
|
1285
|
+
ttf: "font/ttf",
|
|
1286
|
+
wasm: "application/wasm",
|
|
1287
|
+
webmanifest: "application/manifest+json",
|
|
1288
|
+
mp3: "audio/mpeg",
|
|
1289
|
+
mp4: "video/mp4"
|
|
1290
|
+
});
|
|
1291
|
+
function uiAssetContentType(path) {
|
|
1292
|
+
const name = path.slice(path.lastIndexOf("/") + 1);
|
|
1293
|
+
const dot = name.lastIndexOf(".");
|
|
1294
|
+
const extension = dot > 0 ? name.slice(dot + 1).toLowerCase() : "";
|
|
1295
|
+
return Object.hasOwn(UI_ASSET_CONTENT_TYPES, extension) ? UI_ASSET_CONTENT_TYPES[extension] : "application/octet-stream";
|
|
1296
|
+
}
|
|
1297
|
+
function agentUiBundleManifest(value, execution) {
|
|
1298
|
+
const partial = object(value, "UI bundle manifest is invalid");
|
|
1299
|
+
exactKeys(partial, ["schemaVersion", "kind", "runtime", "state", "assets", "contentSecurityPolicy"], []);
|
|
1300
|
+
const runtime = partial.runtime === void 0 ? {} : object(partial.runtime, "UI bundle runtime is invalid");
|
|
1301
|
+
const assets = partial.assets === void 0 ? {} : object(partial.assets, "UI bundle assets manifest is invalid");
|
|
1302
|
+
exactKeys(runtime, ["contract", "entry"], []);
|
|
1303
|
+
exactKeys(assets, ["root", "fallback"], []);
|
|
1304
|
+
const state = partial.state !== void 0 ? partial.state : execution === "durable" ? { schemaVersion: 1, compatibleSchemaVersions: { minimum: 1, maximum: 1 } } : void 0;
|
|
1305
|
+
return uiBundleManifest({
|
|
1306
|
+
schemaVersion: partial.schemaVersion ?? 1,
|
|
1307
|
+
kind: partial.kind ?? "constal.ui",
|
|
1308
|
+
runtime: { contract: runtime.contract ?? "constal.ui-handler.v1", entry: runtime.entry ?? "worker.mjs" },
|
|
1309
|
+
...state === void 0 ? {} : { state },
|
|
1310
|
+
assets: { root: assets.root ?? "public", fallback: assets.fallback ?? "index.html" },
|
|
1311
|
+
contentSecurityPolicy: partial.contentSecurityPolicy ?? "strict"
|
|
1312
|
+
}, execution);
|
|
1313
|
+
}
|
|
1166
1314
|
function uiBundle(value, execution) {
|
|
1167
1315
|
const bundle = object(value, "UI bundle is invalid");
|
|
1168
1316
|
exactKeys(bundle, ["manifest", "modules", "assets"], ["manifest", "modules", "assets"]);
|
|
@@ -1316,11 +1464,13 @@ function panel(value) {
|
|
|
1316
1464
|
const provider = text(source.provider, 1024);
|
|
1317
1465
|
const credentialId = text(source.credentialId, 63);
|
|
1318
1466
|
if (!provider || !credentialId || !ID.test(credentialId) || !["connect", "reauthorize", "manage"].includes(String(source.operation)) || source.receipt !== void 0 && !["reference", "evidence"].includes(String(source.receipt)) || source.receipt !== void 0 && base.actions.filter((action3) => action3.intent === "primary").length !== 1 || (source.selection !== void 0 || source.configuration !== void 0) && source.receipt === void 0 || source.configuration !== void 0 && !record3(source.configuration) || !exact(source, ["kind", "id", "title", "description", "actions", "provider", "credentialId", "operation", "receipt", "selection", "configuration"])) return null;
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1467
|
+
if (setupPanelProviderIsCrn(provider)) {
|
|
1468
|
+
try {
|
|
1469
|
+
if (parseResourceName(provider).kind !== "credential-provider") return null;
|
|
1470
|
+
} catch {
|
|
1471
|
+
return null;
|
|
1472
|
+
}
|
|
1473
|
+
} else if (!ID.test(provider)) return null;
|
|
1324
1474
|
let selection;
|
|
1325
1475
|
if (source.selection !== void 0) {
|
|
1326
1476
|
const input = record3(source.selection);
|
|
@@ -1398,6 +1548,9 @@ function panel(value) {
|
|
|
1398
1548
|
}
|
|
1399
1549
|
return null;
|
|
1400
1550
|
}
|
|
1551
|
+
function setupPanelProviderIsCrn(provider) {
|
|
1552
|
+
return provider.startsWith("crn:");
|
|
1553
|
+
}
|
|
1401
1554
|
function setupScreen(value) {
|
|
1402
1555
|
const source = record3(value);
|
|
1403
1556
|
const workflow = record3(source?.workflow);
|
|
@@ -1458,10 +1611,20 @@ function setupCredentialReceipt(value, panel2) {
|
|
|
1458
1611
|
if (!panel2.receipt || !source || source.object !== "constal.setup.credential" || source.version !== 1 || !exact(source, ["object", "version", "credential", "evidence", "binding"]) || !credential || !exact(credential, ["crn", "hash"]) || typeof credential.crn !== "string" || !hash3(credential.hash)) {
|
|
1459
1612
|
throw new TypeError("Setup Credential receipt is invalid");
|
|
1460
1613
|
}
|
|
1461
|
-
const target = parseResourceName(credential.crn),
|
|
1462
|
-
if (target.kind !== "credential"
|
|
1614
|
+
const target = parseResourceName(credential.crn), capability = !setupPanelProviderIsCrn(panel2.provider);
|
|
1615
|
+
if (target.kind !== "credential") throw new TypeError("Setup Credential receipt identity is invalid");
|
|
1616
|
+
if (!capability) {
|
|
1617
|
+
const provider = parseResourceName(panel2.provider);
|
|
1618
|
+
if (target.environment !== provider.environment || provider.tenant !== "platform" && provider.tenant !== target.tenant) {
|
|
1619
|
+
throw new TypeError("Setup Credential receipt identity is invalid");
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1463
1622
|
const evidence = source.evidence === null ? null : credentialEvidence(source.evidence);
|
|
1464
|
-
if (
|
|
1623
|
+
if (capability && evidence) {
|
|
1624
|
+
const provider = parseResourceName(evidence.provider.crn);
|
|
1625
|
+
if (provider.kind !== "credential-provider" || provider.tenant !== "platform" || provider.namespace !== "default" || provider.environment !== target.environment) throw new TypeError("Setup Credential receipt identity is invalid");
|
|
1626
|
+
}
|
|
1627
|
+
if (panel2.receipt === "evidence" && !evidence || panel2.receipt === "reference" && evidence || evidence && (evidence.credential !== credential.crn || !capability && evidence.provider.crn !== panel2.provider)) {
|
|
1465
1628
|
throw new TypeError("Setup Credential evidence does not match its step");
|
|
1466
1629
|
}
|
|
1467
1630
|
if (panel2.selection) {
|
|
@@ -1507,7 +1670,7 @@ function setupAwait(screen) {
|
|
|
1507
1670
|
credential: { type: "string", maxLength: 1024 },
|
|
1508
1671
|
provider: {
|
|
1509
1672
|
...reference,
|
|
1510
|
-
properties: { crn: { const: current.provider }, hash: hash3 }
|
|
1673
|
+
properties: { crn: setupPanelProviderIsCrn(current.provider) ? { const: current.provider } : { type: "string", maxLength: 1024 }, hash: hash3 }
|
|
1511
1674
|
},
|
|
1512
1675
|
version: { type: "integer", minimum: 1 },
|
|
1513
1676
|
expiresAt: { type: ["integer", "null"], minimum: 1 },
|
|
@@ -2795,6 +2958,11 @@ var MODEL_COMPLETION_CAPABILITY = {
|
|
|
2795
2958
|
version: "1",
|
|
2796
2959
|
hash: "0155be6df18b64e7f91ce9939b3c18527813f3dd06260fe65821ed071d94516a"
|
|
2797
2960
|
};
|
|
2961
|
+
var MODEL_EVALUATION_CAPABILITY = {
|
|
2962
|
+
id: "constal.model-evaluation",
|
|
2963
|
+
version: "1",
|
|
2964
|
+
hash: "9c0cc09c17fd5a79be3e1a8f822379f74a5e290d5a12e72104ae7c7eb4be22ee"
|
|
2965
|
+
};
|
|
2798
2966
|
function modelGenerationOptions(source) {
|
|
2799
2967
|
const { maxOutputTokens, temperature, effort } = source;
|
|
2800
2968
|
if (maxOutputTokens !== void 0 && (!Number.isSafeInteger(maxOutputTokens) || maxOutputTokens < 1 || maxOutputTokens > 1048576)) {
|
|
@@ -2872,7 +3040,39 @@ function modelGatewayEndpoint(config) {
|
|
|
2872
3040
|
return endpoint;
|
|
2873
3041
|
}
|
|
2874
3042
|
function modelPrompt(args) {
|
|
2875
|
-
return
|
|
3043
|
+
return canonicalJson({ objective: args.objective ?? null, context: args.context ?? null, feedback: args.feedback ?? [] });
|
|
3044
|
+
}
|
|
3045
|
+
function modelHistory(args) {
|
|
3046
|
+
const history = args.history ?? [];
|
|
3047
|
+
if (!Array.isArray(history)) throw new TypeError("model history must be an array of messages");
|
|
3048
|
+
return history.map((message2) => {
|
|
3049
|
+
const source = record7(message2);
|
|
3050
|
+
if (!source || source.role !== "user" && source.role !== "assistant" || typeof source.content !== "string") {
|
|
3051
|
+
throw new TypeError("model history messages need a user or assistant role and text content");
|
|
3052
|
+
}
|
|
3053
|
+
return { role: source.role, content: source.content };
|
|
3054
|
+
});
|
|
3055
|
+
}
|
|
3056
|
+
function modelMessages(args) {
|
|
3057
|
+
const history = modelHistory(args);
|
|
3058
|
+
if (!history.length) return [{ role: "user", content: modelPrompt(args) }];
|
|
3059
|
+
const feedback = args.feedback ?? [];
|
|
3060
|
+
return [
|
|
3061
|
+
{ role: "user", content: canonicalJson({ objective: args.objective ?? null, context: args.context ?? null }) },
|
|
3062
|
+
...history,
|
|
3063
|
+
...feedback.length ? [{ role: "user", content: canonicalJson({ feedback }) }] : []
|
|
3064
|
+
];
|
|
3065
|
+
}
|
|
3066
|
+
function alternating(messages) {
|
|
3067
|
+
const merged = [];
|
|
3068
|
+
for (const message2 of messages) {
|
|
3069
|
+
const last = merged.at(-1);
|
|
3070
|
+
if (last && last.role === message2.role) last.content = `${last.content}
|
|
3071
|
+
|
|
3072
|
+
${message2.content}`;
|
|
3073
|
+
else merged.push({ ...message2 });
|
|
3074
|
+
}
|
|
3075
|
+
return merged;
|
|
2876
3076
|
}
|
|
2877
3077
|
function modelProtocolRequest(protocol, model, maxOutputTokens, temperature, args) {
|
|
2878
3078
|
const { effort } = modelGenerationOptions(args);
|
|
@@ -2882,11 +3082,11 @@ function modelProtocolRequest(protocol, model, maxOutputTokens, temperature, arg
|
|
|
2882
3082
|
if (args.toolChoice === "required" && !args.tools?.length) {
|
|
2883
3083
|
throw new TypeError("required model Tool choice needs at least one offered Tool");
|
|
2884
3084
|
}
|
|
2885
|
-
const
|
|
3085
|
+
const messages = modelMessages(args);
|
|
2886
3086
|
if (protocol === "anthropic") return {
|
|
2887
3087
|
model,
|
|
2888
3088
|
system: args.system ?? "",
|
|
2889
|
-
messages:
|
|
3089
|
+
messages: alternating(messages),
|
|
2890
3090
|
max_tokens: maxOutputTokens,
|
|
2891
3091
|
...effort === void 0 ? {} : { output_config: { effort } },
|
|
2892
3092
|
...temperature === null ? {} : { temperature },
|
|
@@ -2897,7 +3097,7 @@ function modelProtocolRequest(protocol, model, maxOutputTokens, temperature, arg
|
|
|
2897
3097
|
model,
|
|
2898
3098
|
messages: [
|
|
2899
3099
|
...args.system ? [{ role: "developer", content: args.system }] : [],
|
|
2900
|
-
|
|
3100
|
+
...messages
|
|
2901
3101
|
],
|
|
2902
3102
|
max_completion_tokens: maxOutputTokens,
|
|
2903
3103
|
...effort === void 0 ? {} : { reasoning_effort: effort },
|
|
@@ -3496,32 +3696,199 @@ function credentialProvider(definition) {
|
|
|
3496
3696
|
return Object.freeze({ ...definition, mintRecovery, metadata: metadata3 });
|
|
3497
3697
|
}
|
|
3498
3698
|
|
|
3699
|
+
// packages/sdk/src/evaluation.ts
|
|
3700
|
+
var EVALUATION_LIMITS = {
|
|
3701
|
+
maxQuestions: 512,
|
|
3702
|
+
maxChoiceOptions: 512,
|
|
3703
|
+
maxScoreLevels: 128,
|
|
3704
|
+
maxDepth: 32,
|
|
3705
|
+
/** Bytes of the canonical request body; evaluation models bound state and questions jointly by tokens. */
|
|
3706
|
+
maxRequestBytes: 1048576
|
|
3707
|
+
};
|
|
3708
|
+
var QUESTION_ID = /^[A-Za-z0-9_][A-Za-z0-9_.:-]{0,127}$/u;
|
|
3709
|
+
var MODEL = /^[a-z0-9][a-z0-9._\/-]{0,255}$/u;
|
|
3710
|
+
function record8(value) {
|
|
3711
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
3712
|
+
}
|
|
3713
|
+
function entry(value, field2, depth = 0) {
|
|
3714
|
+
if (depth > EVALUATION_LIMITS.maxDepth) throw new TypeError(`${field2} nests too deeply`);
|
|
3715
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") return value;
|
|
3716
|
+
if (typeof value === "number") {
|
|
3717
|
+
if (!Number.isFinite(value)) throw new TypeError(`${field2} must be a finite number`);
|
|
3718
|
+
return value;
|
|
3719
|
+
}
|
|
3720
|
+
if (Array.isArray(value)) return value.map((item, index) => entry(item, `${field2}[${index}]`, depth + 1));
|
|
3721
|
+
const source = record8(value);
|
|
3722
|
+
const prototype = source ? Object.getPrototypeOf(source) : void 0;
|
|
3723
|
+
if (!source || prototype !== Object.prototype && prototype !== null) throw new TypeError(`${field2} must be JSON text or structure`);
|
|
3724
|
+
const output = {};
|
|
3725
|
+
for (const [key, item] of Object.entries(source)) {
|
|
3726
|
+
if (item === void 0) continue;
|
|
3727
|
+
output[key] = entry(item, `${field2}.${key}`, depth + 1);
|
|
3728
|
+
}
|
|
3729
|
+
return output;
|
|
3730
|
+
}
|
|
3731
|
+
function question(id2, value) {
|
|
3732
|
+
const source = record8(value);
|
|
3733
|
+
if (!source) throw new TypeError(`question ${id2} must be an object`);
|
|
3734
|
+
const type = source.type;
|
|
3735
|
+
if (type !== "choice" && type !== "score" && type !== "noul") throw new TypeError(`question ${id2} type must be choice, score, or noul`);
|
|
3736
|
+
if (source.instructions === void 0) throw new TypeError(`question ${id2} requires instructions`);
|
|
3737
|
+
const instructions = entry(source.instructions, `question ${id2} instructions`);
|
|
3738
|
+
const unknown = Object.keys(source).find((key) => !["type", "instructions", "criteria"].includes(key));
|
|
3739
|
+
if (unknown) throw new TypeError(`question ${id2} has an unknown field ${unknown}`);
|
|
3740
|
+
if (type === "choice") {
|
|
3741
|
+
const criteria2 = record8(source.criteria);
|
|
3742
|
+
const options = criteria2 ? Object.keys(criteria2) : [];
|
|
3743
|
+
if (!criteria2 || options.length < 2) throw new TypeError(`choice question ${id2} needs at least two options`);
|
|
3744
|
+
if (options.length > EVALUATION_LIMITS.maxChoiceOptions) throw new TypeError(`choice question ${id2} offers too many options`);
|
|
3745
|
+
if (options.some((option) => !option.trim() || option.length > 256)) throw new TypeError(`choice question ${id2} has an invalid option key`);
|
|
3746
|
+
return { type, instructions, criteria: Object.fromEntries(options.map((option) => [option, entry(criteria2[option], `choice question ${id2} option ${option}`)])) };
|
|
3747
|
+
}
|
|
3748
|
+
if (type === "score") {
|
|
3749
|
+
const criteria2 = source.criteria;
|
|
3750
|
+
if (!Array.isArray(criteria2) || criteria2.length < 2) throw new TypeError(`score question ${id2} needs at least two ordered levels`);
|
|
3751
|
+
if (criteria2.length > EVALUATION_LIMITS.maxScoreLevels) throw new TypeError(`score question ${id2} has too many levels`);
|
|
3752
|
+
return { type, instructions, criteria: criteria2.map((level, index) => entry(level, `score question ${id2} level ${index}`)) };
|
|
3753
|
+
}
|
|
3754
|
+
if (source.criteria === void 0) return { type, instructions };
|
|
3755
|
+
const criteria = record8(source.criteria);
|
|
3756
|
+
if (!criteria || Object.keys(criteria).some((key) => key !== "true" && key !== "false")) {
|
|
3757
|
+
throw new TypeError(`noul question ${id2} criteria may only describe true and false`);
|
|
3758
|
+
}
|
|
3759
|
+
return { type, instructions, criteria: {
|
|
3760
|
+
...criteria.true === void 0 ? {} : { true: entry(criteria.true, `noul question ${id2} criteria.true`) },
|
|
3761
|
+
...criteria.false === void 0 ? {} : { false: entry(criteria.false, `noul question ${id2} criteria.false`) }
|
|
3762
|
+
} };
|
|
3763
|
+
}
|
|
3764
|
+
function evaluationArguments(value) {
|
|
3765
|
+
const source = record8(value);
|
|
3766
|
+
if (!source) throw new TypeError("evaluation arguments must be an object");
|
|
3767
|
+
if (source.state === void 0) throw new TypeError("evaluation requires a state");
|
|
3768
|
+
const state = entry(source.state, "evaluation state");
|
|
3769
|
+
const questionSource = record8(source.questions);
|
|
3770
|
+
const ids = questionSource ? Object.keys(questionSource) : [];
|
|
3771
|
+
if (!questionSource || ids.length === 0) throw new TypeError("evaluation requires at least one question");
|
|
3772
|
+
if (ids.length > EVALUATION_LIMITS.maxQuestions) throw new TypeError("evaluation asks too many questions");
|
|
3773
|
+
const questions = {};
|
|
3774
|
+
for (const id2 of ids) {
|
|
3775
|
+
if (!QUESTION_ID.test(id2)) throw new TypeError(`question id is invalid: ${id2}`);
|
|
3776
|
+
questions[id2] = question(id2, questionSource[id2]);
|
|
3777
|
+
}
|
|
3778
|
+
const unknown = Object.keys(source).find((key) => !["model", "state", "questions"].includes(key));
|
|
3779
|
+
if (unknown) throw new TypeError(`evaluation arguments have an unknown field ${unknown}`);
|
|
3780
|
+
let model;
|
|
3781
|
+
if (source.model !== void 0) {
|
|
3782
|
+
if (typeof source.model !== "string" || !MODEL.test(source.model)) throw new TypeError("evaluation model identifier is invalid");
|
|
3783
|
+
model = source.model;
|
|
3784
|
+
}
|
|
3785
|
+
const output = { ...model === void 0 ? {} : { model }, state, questions };
|
|
3786
|
+
const bytes = new TextEncoder().encode(JSON.stringify({ state, questions })).byteLength;
|
|
3787
|
+
if (bytes > EVALUATION_LIMITS.maxRequestBytes) throw new TypeError("evaluation state and questions exceed the request size limit");
|
|
3788
|
+
return output;
|
|
3789
|
+
}
|
|
3790
|
+
function evaluationProtocolRequest(protocol, model, args) {
|
|
3791
|
+
if (protocol !== "typesafe") throw new TypeError("evaluation protocol is invalid");
|
|
3792
|
+
return { model, state: args.state, questions: args.questions };
|
|
3793
|
+
}
|
|
3794
|
+
function probability(value, field2) {
|
|
3795
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > 1) throw new TypeError(`${field2} must be a probability`);
|
|
3796
|
+
return value;
|
|
3797
|
+
}
|
|
3798
|
+
function distribution(value, keys, field2) {
|
|
3799
|
+
const source = record8(value);
|
|
3800
|
+
if (!source) throw new TypeError(`${field2} must map every option to a probability`);
|
|
3801
|
+
const output = {};
|
|
3802
|
+
for (const key of keys) output[key] = probability(source[key], `${field2}.${key}`);
|
|
3803
|
+
return output;
|
|
3804
|
+
}
|
|
3805
|
+
function answer(id2, asked, value) {
|
|
3806
|
+
const source = record8(value);
|
|
3807
|
+
if (!source || source.type !== asked.type) throw new TypeError(`answer ${id2} does not match its ${asked.type} question`);
|
|
3808
|
+
if (asked.type === "noul") return { type: "noul", noul: probability(source.noul, `answer ${id2} noul`) };
|
|
3809
|
+
const confidence = probability(source.confidence, `answer ${id2} confidence`);
|
|
3810
|
+
if (asked.type === "choice") {
|
|
3811
|
+
const options = Object.keys(asked.criteria);
|
|
3812
|
+
if (typeof source.choice !== "string" || !options.includes(source.choice)) throw new TypeError(`answer ${id2} chose an unknown option`);
|
|
3813
|
+
return { type: "choice", choice: source.choice, probabilities: distribution(source.probabilities, options, `answer ${id2} probabilities`), confidence };
|
|
3814
|
+
}
|
|
3815
|
+
const levels = asked.criteria.map((_, index) => String(index));
|
|
3816
|
+
if (typeof source.score !== "number" || !Number.isFinite(source.score) || source.score < 0 || source.score > levels.length - 1) {
|
|
3817
|
+
throw new TypeError(`answer ${id2} score is outside its levels`);
|
|
3818
|
+
}
|
|
3819
|
+
const legend = record8(source.legend);
|
|
3820
|
+
return {
|
|
3821
|
+
type: "score",
|
|
3822
|
+
score: source.score,
|
|
3823
|
+
legend: Object.fromEntries(levels.map((level, index) => [level, legend && legend[level] !== void 0 ? legend[level] : asked.criteria[index]])),
|
|
3824
|
+
probabilities: distribution(source.probabilities, levels, `answer ${id2} probabilities`),
|
|
3825
|
+
confidence
|
|
3826
|
+
};
|
|
3827
|
+
}
|
|
3828
|
+
function integer3(value) {
|
|
3829
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : 0;
|
|
3830
|
+
}
|
|
3831
|
+
function evaluationProtocolResult(protocol, raw, provider, model, questions) {
|
|
3832
|
+
if (protocol !== "typesafe") throw new TypeError("evaluation protocol is invalid");
|
|
3833
|
+
const source = record8(raw) ?? {};
|
|
3834
|
+
const answers = record8(source.answers);
|
|
3835
|
+
if (!answers) throw new TypeError("evaluation response has no answers");
|
|
3836
|
+
const output = {};
|
|
3837
|
+
for (const [id2, asked] of Object.entries(questions)) {
|
|
3838
|
+
if (answers[id2] === void 0) throw new TypeError(`evaluation response is missing answer ${id2}`);
|
|
3839
|
+
output[id2] = answer(id2, asked, answers[id2]);
|
|
3840
|
+
}
|
|
3841
|
+
const usage = record8(source.usage) ?? {};
|
|
3842
|
+
const cost = usage.cost;
|
|
3843
|
+
const costUsd = cost === null ? null : typeof cost === "number" && Number.isFinite(cost) && cost >= 0 ? cost : void 0;
|
|
3844
|
+
return {
|
|
3845
|
+
answers: output,
|
|
3846
|
+
provider,
|
|
3847
|
+
model,
|
|
3848
|
+
usage: {
|
|
3849
|
+
input: integer3(usage.input_tokens),
|
|
3850
|
+
output: integer3(usage.output_tokens),
|
|
3851
|
+
cached: 0,
|
|
3852
|
+
...costUsd !== void 0 ? { costUsd } : {},
|
|
3853
|
+
...typeof usage.cost_source === "string" ? { costSource: usage.cost_source } : {},
|
|
3854
|
+
...typeof usage.cost_estimated === "boolean" ? { costEstimated: usage.cost_estimated } : {}
|
|
3855
|
+
}
|
|
3856
|
+
};
|
|
3857
|
+
}
|
|
3858
|
+
function noulDecision(answer2, threshold = 0.5) {
|
|
3859
|
+
if (typeof threshold !== "number" || !Number.isFinite(threshold) || threshold < 0 || threshold > 1) throw new TypeError("threshold must be a probability");
|
|
3860
|
+
return answer2.noul >= threshold;
|
|
3861
|
+
}
|
|
3862
|
+
function scoreLevel(answer2) {
|
|
3863
|
+
return Math.min(Object.keys(answer2.legend).length - 1, Math.max(0, Math.round(answer2.score)));
|
|
3864
|
+
}
|
|
3865
|
+
|
|
3499
3866
|
// packages/sdk/src/mcp.ts
|
|
3500
3867
|
var MCP_PROTOCOL_VERSION = "2025-06-18";
|
|
3501
|
-
function
|
|
3868
|
+
function record9(value) {
|
|
3502
3869
|
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
3503
3870
|
}
|
|
3504
3871
|
function mcpToolDescription(value) {
|
|
3505
|
-
const tool =
|
|
3506
|
-
const outputSchema = tool?.outputSchema === void 0 ? {} :
|
|
3872
|
+
const tool = record9(value), inputSchema = record9(tool?.inputSchema);
|
|
3873
|
+
const outputSchema = tool?.outputSchema === void 0 ? {} : record9(tool.outputSchema);
|
|
3507
3874
|
if (!tool || typeof tool.name !== "string" || !tool.name || tool.description !== void 0 && typeof tool.description !== "string" || !inputSchema || outputSchema === null) throw new TerminalIntegrationFailure("MCP server advertised an invalid tool");
|
|
3508
3875
|
return {
|
|
3509
3876
|
name: tool.name,
|
|
3510
3877
|
description: typeof tool.description === "string" ? tool.description : "",
|
|
3511
3878
|
inputSchema,
|
|
3512
3879
|
outputSchema,
|
|
3513
|
-
annotations:
|
|
3880
|
+
annotations: record9(tool.annotations) ?? {}
|
|
3514
3881
|
};
|
|
3515
3882
|
}
|
|
3516
3883
|
function mcpToolResult(value) {
|
|
3517
|
-
const result =
|
|
3518
|
-
if (!result || result.isError !== void 0 && typeof result.isError !== "boolean" || result?.content !== void 0 && !Array.isArray(result.content) || result?.structuredContent !== void 0 && !
|
|
3884
|
+
const result = record9(value);
|
|
3885
|
+
if (!result || result.isError !== void 0 && typeof result.isError !== "boolean" || result?.content !== void 0 && !Array.isArray(result.content) || result?.structuredContent !== void 0 && !record9(result.structuredContent) || result && result.content === void 0 && result.structuredContent === void 0) {
|
|
3519
3886
|
throw new TerminalIntegrationFailure("MCP tools/call result is invalid");
|
|
3520
3887
|
}
|
|
3521
3888
|
return result;
|
|
3522
3889
|
}
|
|
3523
3890
|
function message(value) {
|
|
3524
|
-
const item =
|
|
3891
|
+
const item = record9(value);
|
|
3525
3892
|
if (!item || item.jsonrpc !== "2.0") throw new TerminalIntegrationFailure("MCP transport returned an invalid JSON-RPC message");
|
|
3526
3893
|
return item;
|
|
3527
3894
|
}
|
|
@@ -3561,7 +3928,7 @@ var McpClient = class {
|
|
|
3561
3928
|
for (; ; ) {
|
|
3562
3929
|
const received = message(await this.transport.receive());
|
|
3563
3930
|
if (received.id === id2) {
|
|
3564
|
-
if (
|
|
3931
|
+
if (record9(received.error)) {
|
|
3565
3932
|
const error = received.error;
|
|
3566
3933
|
throw new TerminalIntegrationFailure(`MCP ${typeof error.code === "number" || typeof error.code === "string" ? error.code : "unknown"}: ${typeof error.message === "string" ? error.message : "request failed"}`);
|
|
3567
3934
|
}
|
|
@@ -3586,7 +3953,7 @@ var McpClient = class {
|
|
|
3586
3953
|
}
|
|
3587
3954
|
async initialize() {
|
|
3588
3955
|
if (this.#protocol) return { protocolVersion: this.#protocol, server: {} };
|
|
3589
|
-
const result =
|
|
3956
|
+
const result = record9(await this.#request("initialize", {
|
|
3590
3957
|
protocolVersion: MCP_PROTOCOL_VERSION,
|
|
3591
3958
|
capabilities: {},
|
|
3592
3959
|
clientInfo: this.options.client ?? { name: "Constal", version: "1.0.0" }
|
|
@@ -3597,7 +3964,7 @@ var McpClient = class {
|
|
|
3597
3964
|
this.#protocol = result.protocolVersion;
|
|
3598
3965
|
await this.transport.negotiated?.(this.#protocol);
|
|
3599
3966
|
await this.#serialized(() => this.transport.send({ jsonrpc: "2.0", method: "notifications/initialized" }));
|
|
3600
|
-
return { protocolVersion: this.#protocol, server:
|
|
3967
|
+
return { protocolVersion: this.#protocol, server: record9(result.serverInfo) ?? {} };
|
|
3601
3968
|
}
|
|
3602
3969
|
async request(method, params) {
|
|
3603
3970
|
if (!this.#protocol) throw new TerminalIntegrationFailure("MCP session is not initialized");
|
|
@@ -3607,8 +3974,8 @@ var McpClient = class {
|
|
|
3607
3974
|
const tools = [], cursors = /* @__PURE__ */ new Set();
|
|
3608
3975
|
let cursor;
|
|
3609
3976
|
do {
|
|
3610
|
-
const result =
|
|
3611
|
-
if (!result || !Array.isArray(result.tools) || result.tools.some((item) => !
|
|
3977
|
+
const result = record9(await this.request("tools/list", cursor ? { cursor } : {}));
|
|
3978
|
+
if (!result || !Array.isArray(result.tools) || result.tools.some((item) => !record9(item))) {
|
|
3612
3979
|
throw new TerminalIntegrationFailure("MCP tools/list result is invalid");
|
|
3613
3980
|
}
|
|
3614
3981
|
tools.push(...result.tools);
|
|
@@ -3638,14 +4005,14 @@ var McpClient = class {
|
|
|
3638
4005
|
function validPointer(value) {
|
|
3639
4006
|
return typeof value === "string" && value.length <= 4096 && (value === "" || value.startsWith("/") && !/~(?:[^01]|$)/u.test(value));
|
|
3640
4007
|
}
|
|
3641
|
-
function
|
|
4008
|
+
function record10(value) {
|
|
3642
4009
|
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
3643
4010
|
}
|
|
3644
4011
|
function exactKeys4(value, allowed) {
|
|
3645
4012
|
return Object.keys(value).every((key) => allowed.includes(key));
|
|
3646
4013
|
}
|
|
3647
4014
|
function scorerRule(value, depth, state) {
|
|
3648
|
-
const rule =
|
|
4015
|
+
const rule = record10(value);
|
|
3649
4016
|
if (!rule || depth > 32 || ++state.rules > 1024 || typeof rule.op !== "string") throw new TypeError("Code Scorer IR is invalid");
|
|
3650
4017
|
if (rule.op === "all" || rule.op === "any") {
|
|
3651
4018
|
if (!exactKeys4(rule, ["op", "rules"]) || !Array.isArray(rule.rules) || rule.rules.length < 1 || rule.rules.length > 128) {
|
|
@@ -3658,7 +4025,7 @@ function scorerRule(value, depth, state) {
|
|
|
3658
4025
|
return { op: "not", rule: scorerRule(rule.rule, depth + 1, state) };
|
|
3659
4026
|
}
|
|
3660
4027
|
if (rule.op === "schema") {
|
|
3661
|
-
if (!exactKeys4(rule, ["op", "path", "schema"]) || !validPointer(rule.path) || !
|
|
4028
|
+
if (!exactKeys4(rule, ["op", "path", "schema"]) || !validPointer(rule.path) || !record10(rule.schema) || validateJsonSchemaDefinition(rule.schema)) throw new TypeError("Code Scorer schema rule is invalid");
|
|
3662
4029
|
return rule;
|
|
3663
4030
|
}
|
|
3664
4031
|
if (rule.op === "regex") {
|
|
@@ -3693,7 +4060,7 @@ function scorerRule(value, depth, state) {
|
|
|
3693
4060
|
throw new TypeError("Code Scorer operation is invalid");
|
|
3694
4061
|
}
|
|
3695
4062
|
function codeScorerIR(value) {
|
|
3696
|
-
const ir =
|
|
4063
|
+
const ir = record10(value);
|
|
3697
4064
|
if (!ir || ir.v !== 1 || !exactKeys4(ir, ["v", "rule"])) throw new TypeError("Code Scorer IR is invalid");
|
|
3698
4065
|
return { v: 1, rule: scorerRule(ir.rule, 0, { rules: 0 }) };
|
|
3699
4066
|
}
|
|
@@ -3706,7 +4073,7 @@ function pointer(value, path) {
|
|
|
3706
4073
|
if (!/^(?:0|[1-9][0-9]*)$/u.test(key) || Number(key) >= current.length) return { found: false, value: void 0 };
|
|
3707
4074
|
current = current[Number(key)];
|
|
3708
4075
|
} else {
|
|
3709
|
-
const source =
|
|
4076
|
+
const source = record10(current);
|
|
3710
4077
|
if (!source || !Object.hasOwn(source, key)) return { found: false, value: void 0 };
|
|
3711
4078
|
current = source[key];
|
|
3712
4079
|
}
|
|
@@ -3740,7 +4107,7 @@ function evaluate(rule, subject) {
|
|
|
3740
4107
|
if (!sources.found || !Array.isArray(sources.value)) return fail(rule.sourcesPath, "citation sources are missing");
|
|
3741
4108
|
const available = new Set(sources.value.flatMap((source, index) => {
|
|
3742
4109
|
if (typeof source === "string") return [source, String(index + 1)];
|
|
3743
|
-
const item =
|
|
4110
|
+
const item = record10(source);
|
|
3744
4111
|
return item ? [String(item.id ?? ""), String(index + 1)].filter(Boolean) : [String(index + 1)];
|
|
3745
4112
|
}));
|
|
3746
4113
|
const citations = [...text2.value.matchAll(/\[([^\]\n]{1,128})\]/gu)].map((match) => match[1].trim());
|
|
@@ -3759,7 +4126,7 @@ function evaluate(rule, subject) {
|
|
|
3759
4126
|
const contains = typeof selected.value === "string" && typeof rule.value === "string" ? selected.value.includes(rule.value) : Array.isArray(selected.value) && selected.value.some((value) => canonicalJson(value) === canonicalJson(rule.value));
|
|
3760
4127
|
return contains ? pass() : fail(rule.path, "value is not contained");
|
|
3761
4128
|
}
|
|
3762
|
-
const names = Array.isArray(selected.value) ? selected.value.map((item) => typeof item === "string" ? item : String(
|
|
4129
|
+
const names = Array.isArray(selected.value) ? selected.value.map((item) => typeof item === "string" ? item : String(record10(item)?.name ?? "")) : [];
|
|
3763
4130
|
const sequence = rule.mode === "exact" ? names.length === rule.expected.length && names.every((name, index) => name === rule.expected[index]) : rule.expected.reduce((cursor, expected) => {
|
|
3764
4131
|
const index = names.indexOf(expected, cursor);
|
|
3765
4132
|
return index < 0 ? Number.POSITIVE_INFINITY : index + 1;
|
|
@@ -3779,9 +4146,9 @@ function evaluateCodeScorer(raw, subject) {
|
|
|
3779
4146
|
|
|
3780
4147
|
// packages/sdk/src/errors.ts
|
|
3781
4148
|
var GateExhausted = class extends Error {
|
|
3782
|
-
constructor(
|
|
4149
|
+
constructor(record11) {
|
|
3783
4150
|
super("turn gate exhausted");
|
|
3784
|
-
this.record =
|
|
4151
|
+
this.record = record11;
|
|
3785
4152
|
this.name = "GateExhausted";
|
|
3786
4153
|
}
|
|
3787
4154
|
record;
|
|
@@ -3813,14 +4180,17 @@ var NondeterministicReplay = class extends Error {
|
|
|
3813
4180
|
actual;
|
|
3814
4181
|
};
|
|
3815
4182
|
var OutcomeUnknown = class extends Error {
|
|
3816
|
-
|
|
3817
|
-
|
|
4183
|
+
/** `detail` is what the platform last heard from the Resource, so the agent learns why the outcome stayed unknown. */
|
|
4184
|
+
constructor(pos, effect, detail = null) {
|
|
4185
|
+
super(`effect outcome is unknown at ${pos}${detail?.message ? `: ${detail.message}` : ""}`);
|
|
3818
4186
|
this.pos = pos;
|
|
3819
4187
|
this.effect = effect;
|
|
4188
|
+
this.detail = detail;
|
|
3820
4189
|
this.name = "OutcomeUnknown";
|
|
3821
4190
|
}
|
|
3822
4191
|
pos;
|
|
3823
4192
|
effect;
|
|
4193
|
+
detail;
|
|
3824
4194
|
};
|
|
3825
4195
|
var LeaseLost = class extends Error {
|
|
3826
4196
|
constructor(message2 = "invocation lease is no longer current") {
|
|
@@ -3955,6 +4325,7 @@ var SessionDeleted = class extends Error {
|
|
|
3955
4325
|
session;
|
|
3956
4326
|
};
|
|
3957
4327
|
export {
|
|
4328
|
+
AGENT_UI_DEFAULTS,
|
|
3958
4329
|
AfterYield,
|
|
3959
4330
|
ApiError,
|
|
3960
4331
|
CONSTAL_API_CAPABILITY,
|
|
@@ -3969,6 +4340,7 @@ export {
|
|
|
3969
4340
|
CredentialRevoked,
|
|
3970
4341
|
CredentialUnavailable,
|
|
3971
4342
|
DirectNetworkDenied,
|
|
4343
|
+
EVALUATION_LIMITS,
|
|
3972
4344
|
EffectCeilingExceeded,
|
|
3973
4345
|
GateExhausted,
|
|
3974
4346
|
IntegrationRequestNotSent,
|
|
@@ -3978,6 +4350,7 @@ export {
|
|
|
3978
4350
|
MEMORY_OPERATION_DECLARATIONS,
|
|
3979
4351
|
MODEL_CHECKPOINT_IMPORT_CAPABILITY,
|
|
3980
4352
|
MODEL_COMPLETION_CAPABILITY,
|
|
4353
|
+
MODEL_EVALUATION_CAPABILITY,
|
|
3981
4354
|
McpClient,
|
|
3982
4355
|
NondeterministicReplay,
|
|
3983
4356
|
OutcomeUnknown,
|
|
@@ -3995,6 +4368,7 @@ export {
|
|
|
3995
4368
|
TRAINING_PROVIDER_CAPABILITY,
|
|
3996
4369
|
TerminalIntegrationFailure,
|
|
3997
4370
|
ToolUnavailable,
|
|
4371
|
+
UI_ASSET_CONTENT_TYPES,
|
|
3998
4372
|
UI_BUNDLE_BOUNDS,
|
|
3999
4373
|
UnknownTool,
|
|
4000
4374
|
WEB_FETCH_ARGUMENT_SCHEMA,
|
|
@@ -4005,6 +4379,8 @@ export {
|
|
|
4005
4379
|
agentResourceBinding,
|
|
4006
4380
|
agentSetupMetadata,
|
|
4007
4381
|
agentSetupRequirements,
|
|
4382
|
+
agentUiBundleManifest,
|
|
4383
|
+
agentUiDeclaration,
|
|
4008
4384
|
analyticsEvent,
|
|
4009
4385
|
approximateTokens,
|
|
4010
4386
|
authProvider,
|
|
@@ -4045,6 +4421,9 @@ export {
|
|
|
4045
4421
|
datasetName,
|
|
4046
4422
|
evaluateCodeScorer,
|
|
4047
4423
|
evaluatePolicyDefinition,
|
|
4424
|
+
evaluationArguments,
|
|
4425
|
+
evaluationProtocolRequest,
|
|
4426
|
+
evaluationProtocolResult,
|
|
4048
4427
|
gateway,
|
|
4049
4428
|
gatewayModelOffer,
|
|
4050
4429
|
gatewayPackageMetadata,
|
|
@@ -4066,6 +4445,7 @@ export {
|
|
|
4066
4445
|
modelGatewayEndpoint,
|
|
4067
4446
|
modelGenerationOptions,
|
|
4068
4447
|
modelLimit,
|
|
4448
|
+
modelMessages,
|
|
4069
4449
|
modelPrompt,
|
|
4070
4450
|
modelProtocolRequest,
|
|
4071
4451
|
modelProtocolResult,
|
|
@@ -4073,6 +4453,7 @@ export {
|
|
|
4073
4453
|
normalizeModelGatewayConfig,
|
|
4074
4454
|
normalizeSandboxNetworkPolicy,
|
|
4075
4455
|
normalizeSandboxWorkspacePath,
|
|
4456
|
+
noulDecision,
|
|
4076
4457
|
opTool,
|
|
4077
4458
|
opTools,
|
|
4078
4459
|
parseResourceName,
|
|
@@ -4097,10 +4478,12 @@ export {
|
|
|
4097
4478
|
scopedBindingKey,
|
|
4098
4479
|
scopedCredentialRef,
|
|
4099
4480
|
scopedResourceRef,
|
|
4481
|
+
scoreLevel,
|
|
4100
4482
|
scorerName,
|
|
4101
4483
|
selectableResourceLabels,
|
|
4102
4484
|
setupAwait,
|
|
4103
4485
|
setupCredentialReceipt,
|
|
4486
|
+
setupPanelProviderIsCrn,
|
|
4104
4487
|
setupScreen,
|
|
4105
4488
|
setupScreenView,
|
|
4106
4489
|
setupSubmission,
|
|
@@ -4114,6 +4497,7 @@ export {
|
|
|
4114
4497
|
trainingProvider,
|
|
4115
4498
|
trainingProviderMetadata,
|
|
4116
4499
|
trainingRecipe,
|
|
4500
|
+
uiAssetContentType,
|
|
4117
4501
|
uiBundle,
|
|
4118
4502
|
uiBundleManifest,
|
|
4119
4503
|
uiLimit,
|