@constal/sdk 2.0.0 → 2.1.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/package.json +1 -1
- package/publish/api.json +32 -1
- package/publish/index.d.ts +811 -4
- package/publish/index.js +475 -96
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 record9 = value;
|
|
16
|
+
return `{${Object.keys(record9).sort().filter((key) => record9[key] !== void 0).map((key) => `${JSON.stringify(key)}:${canonicalJson(record9[key])}`).join(",")}}`;
|
|
17
17
|
}
|
|
18
18
|
throw new TypeError(`canonical JSON does not support ${typeof value}`);
|
|
19
19
|
}
|
|
@@ -107,8 +107,8 @@ function field(row, name, purpose) {
|
|
|
107
107
|
return row[name];
|
|
108
108
|
}
|
|
109
109
|
function approximateTokens(value) {
|
|
110
|
-
const
|
|
111
|
-
return Math.max(1, Math.ceil(encoder2.encode(
|
|
110
|
+
const text2 = typeof value === "string" ? value : canonicalJson(value);
|
|
111
|
+
return Math.max(1, Math.ceil(encoder2.encode(text2).byteLength / 4));
|
|
112
112
|
}
|
|
113
113
|
function cutByWeight(rows, limit2, weight, framing) {
|
|
114
114
|
const partitions = [];
|
|
@@ -276,21 +276,21 @@ function validateJsonSchema(value, schema, path = "$") {
|
|
|
276
276
|
if (typeof rule.multipleOf === "number" && Math.abs(value / rule.multipleOf - Math.round(value / rule.multipleOf)) > Number.EPSILON * 8) return `${path} is not a multiple`;
|
|
277
277
|
}
|
|
278
278
|
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
279
|
-
const
|
|
280
|
-
for (const key of Array.isArray(rule.required) ? rule.required : []) if (typeof key === "string" && !(key in
|
|
279
|
+
const record9 = value;
|
|
280
|
+
for (const key of Array.isArray(rule.required) ? rule.required : []) if (typeof key === "string" && !(key in record9)) return `${path}.${key} is required`;
|
|
281
281
|
const properties = rule.properties && typeof rule.properties === "object" && !Array.isArray(rule.properties) ? rule.properties : {};
|
|
282
|
-
if (typeof rule.minProperties === "number" && Object.keys(
|
|
283
|
-
if (typeof rule.maxProperties === "number" && Object.keys(
|
|
282
|
+
if (typeof rule.minProperties === "number" && Object.keys(record9).length < rule.minProperties) return `${path} has too few properties`;
|
|
283
|
+
if (typeof rule.maxProperties === "number" && Object.keys(record9).length > rule.maxProperties) return `${path} has too many properties`;
|
|
284
284
|
if (rule.additionalProperties === false) {
|
|
285
|
-
const extra = Object.keys(
|
|
285
|
+
const extra = Object.keys(record9).find((key) => !(key in properties));
|
|
286
286
|
if (extra) return `${path}.${extra} is not allowed`;
|
|
287
287
|
}
|
|
288
|
-
for (const [key, child] of Object.entries(properties)) if (key in
|
|
289
|
-
const error = validateJsonSchema(
|
|
288
|
+
for (const [key, child] of Object.entries(properties)) if (key in record9) {
|
|
289
|
+
const error = validateJsonSchema(record9[key], child, `${path}.${key}`);
|
|
290
290
|
if (error) return error;
|
|
291
291
|
}
|
|
292
|
-
if (rule.additionalProperties && typeof rule.additionalProperties === "object") for (const key of Object.keys(
|
|
293
|
-
const error = validateJsonSchema(
|
|
292
|
+
if (rule.additionalProperties && typeof rule.additionalProperties === "object") for (const key of Object.keys(record9).filter((candidate) => !(candidate in properties))) {
|
|
293
|
+
const error = validateJsonSchema(record9[key], rule.additionalProperties, `${path}.${key}`);
|
|
294
294
|
if (error) return error;
|
|
295
295
|
}
|
|
296
296
|
}
|
|
@@ -1001,6 +1001,363 @@ function uiBundle(value, execution) {
|
|
|
1001
1001
|
return { manifest, modules: normalizedModules, assets: normalizedAssets };
|
|
1002
1002
|
}
|
|
1003
1003
|
|
|
1004
|
+
// src/setup-workflow.ts
|
|
1005
|
+
var ID = /^[a-z0-9][a-z0-9-]{0,62}$/u;
|
|
1006
|
+
var CRN = /^crn:constal:[a-z0-9-]+:[a-z0-9-]+:[a-z0-9-]+:credential-provider\/[A-Za-z0-9._~/%-]{1,512}$/u;
|
|
1007
|
+
var MAX_SCREEN_BYTES = 262144;
|
|
1008
|
+
function record3(value) {
|
|
1009
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
1010
|
+
}
|
|
1011
|
+
function text(value, maximum, allowEmpty = false) {
|
|
1012
|
+
return typeof value === "string" && value.length <= maximum && (allowEmpty || value.trim().length > 0) ? value : null;
|
|
1013
|
+
}
|
|
1014
|
+
function exact(value, fields) {
|
|
1015
|
+
return Object.keys(value).every((key) => fields.includes(key));
|
|
1016
|
+
}
|
|
1017
|
+
function action2(value) {
|
|
1018
|
+
const source = record3(value);
|
|
1019
|
+
const id2 = text(source?.id, 63);
|
|
1020
|
+
const label = text(source?.label, 128);
|
|
1021
|
+
if (!source || !id2 || !ID.test(id2) || !label || !["primary", "secondary", "danger"].includes(String(source.intent)) || !exact(source, ["id", "label", "intent"])) return null;
|
|
1022
|
+
return { id: id2, label, intent: source.intent };
|
|
1023
|
+
}
|
|
1024
|
+
function actions(value) {
|
|
1025
|
+
if (!Array.isArray(value) || value.length > 8) return null;
|
|
1026
|
+
const parsed = value.map(action2);
|
|
1027
|
+
if (parsed.some((item) => !item) || new Set(parsed.map((item) => item.id)).size !== parsed.length) return null;
|
|
1028
|
+
return parsed;
|
|
1029
|
+
}
|
|
1030
|
+
function panelBase(source) {
|
|
1031
|
+
const id2 = text(source.id, 63);
|
|
1032
|
+
const title = text(source.title, 256);
|
|
1033
|
+
const description = text(source.description, 4096, true);
|
|
1034
|
+
const parsedActions = actions(source.actions);
|
|
1035
|
+
return id2 && ID.test(id2) && title && description !== null && parsedActions ? { id: id2, title, description, actions: parsedActions } : null;
|
|
1036
|
+
}
|
|
1037
|
+
function panel(value) {
|
|
1038
|
+
const source = record3(value);
|
|
1039
|
+
if (!source) return null;
|
|
1040
|
+
const base = panelBase(source);
|
|
1041
|
+
if (!base) return null;
|
|
1042
|
+
if (source.kind === "form") {
|
|
1043
|
+
const schema = record3(source.schema);
|
|
1044
|
+
const initialValues = source.initialValues === void 0 ? void 0 : record3(source.initialValues);
|
|
1045
|
+
if (!schema || validateJsonSchemaDefinition(schema, "$setup.current.schema") || schema.type !== "object" || schema.additionalProperties !== false || Object.keys(record3(schema.properties) ?? {}).length > 64 || initialValues === null || initialValues && validateJsonSchema(initialValues, schema) || !exact(source, ["kind", "id", "title", "description", "actions", "schema", "initialValues"])) return null;
|
|
1046
|
+
return { ...base, kind: "form", schema, ...initialValues ? { initialValues } : {} };
|
|
1047
|
+
}
|
|
1048
|
+
if (source.kind === "credential-interaction") {
|
|
1049
|
+
const provider = text(source.provider, 1024);
|
|
1050
|
+
const credentialId = text(source.credentialId, 63);
|
|
1051
|
+
if (!provider || !CRN.test(provider) || !credentialId || !ID.test(credentialId) || !["connect", "reauthorize", "manage"].includes(String(source.operation)) || !exact(source, ["kind", "id", "title", "description", "actions", "provider", "credentialId", "operation"])) return null;
|
|
1052
|
+
return {
|
|
1053
|
+
...base,
|
|
1054
|
+
kind: "credential-interaction",
|
|
1055
|
+
provider,
|
|
1056
|
+
credentialId,
|
|
1057
|
+
operation: source.operation
|
|
1058
|
+
};
|
|
1059
|
+
}
|
|
1060
|
+
if (source.kind === "review") {
|
|
1061
|
+
if (!Array.isArray(source.sections) || source.sections.length > 32 || !exact(source, ["kind", "id", "title", "description", "actions", "sections"])) return null;
|
|
1062
|
+
const sections = [];
|
|
1063
|
+
for (const rawSection of source.sections) {
|
|
1064
|
+
const section = record3(rawSection);
|
|
1065
|
+
const id2 = text(section?.id, 63);
|
|
1066
|
+
const title = text(section?.title, 256);
|
|
1067
|
+
if (!section || !id2 || !ID.test(id2) || !title || !Array.isArray(section.rows) || section.rows.length > 64 || !exact(section, ["id", "title", "rows"])) return null;
|
|
1068
|
+
const rows = [];
|
|
1069
|
+
for (const rawRow of section.rows) {
|
|
1070
|
+
const row = record3(rawRow);
|
|
1071
|
+
const label = text(row?.label, 256);
|
|
1072
|
+
const rowValue = text(row?.value, 8192, true);
|
|
1073
|
+
if (!row || !label || rowValue === null || row.tone !== void 0 && !["default", "muted", "warning"].includes(String(row.tone)) || !exact(row, ["label", "value", "tone"])) return null;
|
|
1074
|
+
rows.push({ label, value: rowValue, ...row.tone ? { tone: row.tone } : {} });
|
|
1075
|
+
}
|
|
1076
|
+
sections.push({ id: id2, title, rows });
|
|
1077
|
+
}
|
|
1078
|
+
return { ...base, kind: "review", sections };
|
|
1079
|
+
}
|
|
1080
|
+
if (source.kind === "progress") {
|
|
1081
|
+
if (!Array.isArray(source.progress) || source.progress.length > 64 || !exact(source, ["kind", "id", "title", "description", "actions", "progress"])) return null;
|
|
1082
|
+
const progress = [];
|
|
1083
|
+
for (const rawItem of source.progress) {
|
|
1084
|
+
const item = record3(rawItem);
|
|
1085
|
+
const id2 = text(item?.id, 63);
|
|
1086
|
+
const label = text(item?.label, 256);
|
|
1087
|
+
const detail = item?.detail === void 0 ? void 0 : text(item.detail, 4096, true);
|
|
1088
|
+
if (!item || !id2 || !ID.test(id2) || !label || detail === null || !["pending", "running", "complete", "failed"].includes(String(item.status)) || !exact(item, ["id", "label", "status", "detail"])) return null;
|
|
1089
|
+
progress.push({ id: id2, label, status: item.status, ...detail === void 0 ? {} : { detail } });
|
|
1090
|
+
}
|
|
1091
|
+
return { ...base, kind: "progress", progress };
|
|
1092
|
+
}
|
|
1093
|
+
if (source.kind === "complete" || source.kind === "blocked") {
|
|
1094
|
+
const summary = text(source.summary, 8192);
|
|
1095
|
+
const details = source.details === void 0 ? [] : source.details;
|
|
1096
|
+
if (!summary || !Array.isArray(details) || details.length > 64 || !exact(source, ["kind", "id", "title", "description", "actions", "summary", "details"])) return null;
|
|
1097
|
+
const parsedDetails = [];
|
|
1098
|
+
for (const rawDetail of details) {
|
|
1099
|
+
const detail = record3(rawDetail);
|
|
1100
|
+
const label = text(detail?.label, 256);
|
|
1101
|
+
const detailValue = text(detail?.value, 8192, true);
|
|
1102
|
+
if (!detail || !label || detailValue === null || !exact(detail, ["label", "value"])) return null;
|
|
1103
|
+
parsedDetails.push({ label, value: detailValue });
|
|
1104
|
+
}
|
|
1105
|
+
return { ...base, kind: source.kind, summary, ...parsedDetails.length ? { details: parsedDetails } : {} };
|
|
1106
|
+
}
|
|
1107
|
+
return null;
|
|
1108
|
+
}
|
|
1109
|
+
function setupScreen(value) {
|
|
1110
|
+
const source = record3(value);
|
|
1111
|
+
const workflow = record3(source?.workflow);
|
|
1112
|
+
const current = panel(source?.current);
|
|
1113
|
+
if (!source || source.object !== "constal.setup.screen" || source.version !== 1 || !workflow || !current || !ID.test(String(workflow.id ?? "")) || !text(workflow.version, 64) || !ID.test(String(workflow.targetAgent ?? "")) || !Number.isSafeInteger(source.revision) || Number(source.revision) < 1 || !["active", "blocked", "complete", "cancelled"].includes(String(source.status)) || !text(source.title, 256) || text(source.description, 4096, true) === null || !Array.isArray(source.steps) || source.steps.length < 1 || source.steps.length > 64 || source.waitLabel !== null && !text(source.waitLabel, 256) || !exact(workflow, ["id", "version", "targetAgent"]) || !exact(source, ["object", "version", "workflow", "revision", "status", "title", "description", "steps", "current", "waitLabel"])) {
|
|
1114
|
+
throw new TypeError("Setup screen is invalid");
|
|
1115
|
+
}
|
|
1116
|
+
const parsedSteps = [];
|
|
1117
|
+
for (const rawStep of source.steps) {
|
|
1118
|
+
const step = record3(rawStep);
|
|
1119
|
+
const id2 = text(step?.id, 63);
|
|
1120
|
+
const label = text(step?.label, 128);
|
|
1121
|
+
if (!step || !id2 || !ID.test(id2) || !label || !["pending", "current", "complete", "blocked"].includes(String(step.status)) || step.optional !== void 0 && typeof step.optional !== "boolean" || !exact(step, ["id", "label", "status", "optional"])) throw new TypeError("Setup screen step is invalid");
|
|
1122
|
+
parsedSteps.push({ id: id2, label, status: step.status, ...step.optional === void 0 ? {} : { optional: step.optional } });
|
|
1123
|
+
}
|
|
1124
|
+
if (new Set(parsedSteps.map(({ id: id2 }) => id2)).size !== parsedSteps.length || parsedSteps.filter(({ status }) => status === "current").length > 1 || source.status === "active" && parsedSteps.filter(({ status }) => status === "current").length !== 1 || source.status === "active" && !source.waitLabel || source.status !== "active" && source.waitLabel !== null || source.status === "complete" && current.kind !== "complete" || source.status === "blocked" && current.kind !== "blocked") throw new TypeError("Setup screen state is inconsistent");
|
|
1125
|
+
const normalized = {
|
|
1126
|
+
object: "constal.setup.screen",
|
|
1127
|
+
version: 1,
|
|
1128
|
+
workflow: { id: String(workflow.id), version: String(workflow.version), targetAgent: String(workflow.targetAgent) },
|
|
1129
|
+
revision: Number(source.revision),
|
|
1130
|
+
status: source.status,
|
|
1131
|
+
title: String(source.title),
|
|
1132
|
+
description: String(source.description),
|
|
1133
|
+
steps: parsedSteps,
|
|
1134
|
+
current,
|
|
1135
|
+
waitLabel: source.waitLabel === null ? null : String(source.waitLabel)
|
|
1136
|
+
};
|
|
1137
|
+
if (new TextEncoder().encode(canonicalJson(normalized)).byteLength > MAX_SCREEN_BYTES) throw new TypeError("Setup screen exceeds 256 KiB");
|
|
1138
|
+
return normalized;
|
|
1139
|
+
}
|
|
1140
|
+
function setupSubmission(value, screen) {
|
|
1141
|
+
const source = record3(value);
|
|
1142
|
+
const values = source?.values === void 0 ? void 0 : record3(source.values);
|
|
1143
|
+
if (!source || source.object !== "constal.setup.submission" || source.version !== 1 || source.workflow !== screen.workflow.id || source.revision !== screen.revision || source.step !== screen.current.id || !screen.current.actions.some(({ id: id2 }) => id2 === source.action) || values === null || !exact(source, ["object", "version", "workflow", "revision", "step", "action", "values"])) {
|
|
1144
|
+
throw new TypeError("Setup submission is stale or invalid");
|
|
1145
|
+
}
|
|
1146
|
+
if (screen.current.kind === "form" && source.action === screen.current.actions.find(({ intent }) => intent === "primary")?.id) {
|
|
1147
|
+
const error = validateJsonSchema(values ?? {}, screen.current.schema, "$setup.submission.values");
|
|
1148
|
+
if (error) throw new TypeError(error);
|
|
1149
|
+
}
|
|
1150
|
+
return {
|
|
1151
|
+
object: "constal.setup.submission",
|
|
1152
|
+
version: 1,
|
|
1153
|
+
workflow: String(source.workflow),
|
|
1154
|
+
revision: Number(source.revision),
|
|
1155
|
+
step: String(source.step),
|
|
1156
|
+
action: String(source.action),
|
|
1157
|
+
...values ? { values } : {}
|
|
1158
|
+
};
|
|
1159
|
+
}
|
|
1160
|
+
function setupAwait(screen) {
|
|
1161
|
+
if (screen.status !== "active" || !screen.waitLabel) throw new TypeError("Only an active Setup screen can open a wait");
|
|
1162
|
+
return { maxBytes: 262144, schema: {
|
|
1163
|
+
type: "object",
|
|
1164
|
+
additionalProperties: false,
|
|
1165
|
+
required: ["object", "version", "workflow", "revision", "step", "action"],
|
|
1166
|
+
properties: {
|
|
1167
|
+
object: { const: "constal.setup.submission" },
|
|
1168
|
+
version: { const: 1 },
|
|
1169
|
+
workflow: { const: screen.workflow.id },
|
|
1170
|
+
revision: { const: screen.revision },
|
|
1171
|
+
step: { const: screen.current.id },
|
|
1172
|
+
action: { enum: screen.current.actions.map(({ id: id2 }) => id2) },
|
|
1173
|
+
values: { type: "object", additionalProperties: true }
|
|
1174
|
+
}
|
|
1175
|
+
} };
|
|
1176
|
+
}
|
|
1177
|
+
function setupScreenView(id2 = "setup-screen") {
|
|
1178
|
+
if (!ID.test(id2)) throw new TypeError("Setup view id is invalid");
|
|
1179
|
+
return {
|
|
1180
|
+
id: id2,
|
|
1181
|
+
version: "1",
|
|
1182
|
+
over: "facts",
|
|
1183
|
+
init: () => null,
|
|
1184
|
+
apply(state, fact) {
|
|
1185
|
+
const artifact = record3(fact.artifact);
|
|
1186
|
+
if (artifact?.object !== "constal.setup.screen") return state;
|
|
1187
|
+
return setupScreen(artifact);
|
|
1188
|
+
}
|
|
1189
|
+
};
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
// src/constal-api.ts
|
|
1193
|
+
var CONSTAL_API_CAPABILITY = "constal.api";
|
|
1194
|
+
var CONSTAL_API_VERSION = "1";
|
|
1195
|
+
var CONSTAL_API_OPERATIONS = [
|
|
1196
|
+
"describe",
|
|
1197
|
+
"query",
|
|
1198
|
+
"get",
|
|
1199
|
+
"relations",
|
|
1200
|
+
"explainPolicy",
|
|
1201
|
+
"plan",
|
|
1202
|
+
"apply",
|
|
1203
|
+
"observe"
|
|
1204
|
+
];
|
|
1205
|
+
var CONSTAL_API_BOUNDS = {
|
|
1206
|
+
defaultPageSize: 50,
|
|
1207
|
+
maximumPageSize: 200,
|
|
1208
|
+
maximumRelationDepth: 3,
|
|
1209
|
+
maximumPlanOperations: 64,
|
|
1210
|
+
maximumInputBytes: 1048576,
|
|
1211
|
+
planTtlMs: 15 * 6e4
|
|
1212
|
+
};
|
|
1213
|
+
var boundedNameSchema = { type: "string", minLength: 1, maxLength: 128, pattern: "^[A-Za-z][A-Za-z0-9._-]{0,127}$" };
|
|
1214
|
+
var actionSchema = { type: "string", pattern: ACTION_PATTERN.source };
|
|
1215
|
+
var boundedIdSchema = { type: "string", minLength: 1, maxLength: 256, pattern: "^[A-Za-z0-9][A-Za-z0-9._~:-]{0,255}$" };
|
|
1216
|
+
var hashSchema = { type: "string", pattern: "^[a-f0-9]{64}$" };
|
|
1217
|
+
var stringListSchema = { type: "array", maxItems: 128, items: { type: "string", minLength: 1, maxLength: 256 } };
|
|
1218
|
+
var scopeSchema = { anyOf: [
|
|
1219
|
+
{
|
|
1220
|
+
type: "object",
|
|
1221
|
+
required: ["kind", "namespace"],
|
|
1222
|
+
additionalProperties: false,
|
|
1223
|
+
properties: { kind: { const: "namespace" }, namespace: boundedNameSchema }
|
|
1224
|
+
},
|
|
1225
|
+
{ type: "object", required: ["kind"], additionalProperties: false, properties: { kind: { const: "tenant" } } }
|
|
1226
|
+
] };
|
|
1227
|
+
var objectRefSchema = { type: "object", additionalProperties: false, properties: {
|
|
1228
|
+
kind: { type: "string", maxLength: 128 },
|
|
1229
|
+
id: { type: "string", maxLength: 512 },
|
|
1230
|
+
crn: { type: ["string", "null"], maxLength: 2048 },
|
|
1231
|
+
hash: { anyOf: [{ type: "null" }, hashSchema] },
|
|
1232
|
+
namespace: { type: ["string", "null"], maxLength: 128 },
|
|
1233
|
+
version: { type: ["string", "null"], maxLength: 128 }
|
|
1234
|
+
} };
|
|
1235
|
+
var CONSTAL_API_OPERATION_SCHEMAS = {
|
|
1236
|
+
describe: { type: "object", additionalProperties: false, properties: {
|
|
1237
|
+
domains: stringListSchema,
|
|
1238
|
+
kinds: stringListSchema,
|
|
1239
|
+
operations: stringListSchema,
|
|
1240
|
+
include: {
|
|
1241
|
+
type: "array",
|
|
1242
|
+
maxItems: 5,
|
|
1243
|
+
uniqueItems: true,
|
|
1244
|
+
items: { enum: ["objects", "operations", "relations", "schemas", "docs"] }
|
|
1245
|
+
},
|
|
1246
|
+
cursor: { type: "string", maxLength: 4096 },
|
|
1247
|
+
limit: { type: "integer", minimum: 1, maximum: CONSTAL_API_BOUNDS.maximumPageSize }
|
|
1248
|
+
} },
|
|
1249
|
+
query: { type: "object", required: ["kind", "scope"], additionalProperties: false, properties: {
|
|
1250
|
+
kind: boundedNameSchema,
|
|
1251
|
+
scope: scopeSchema,
|
|
1252
|
+
filter: { type: "object" },
|
|
1253
|
+
search: { type: "string", maxLength: 512 },
|
|
1254
|
+
order: { type: "array", maxItems: 8, items: {
|
|
1255
|
+
type: "object",
|
|
1256
|
+
required: ["field", "direction"],
|
|
1257
|
+
additionalProperties: false,
|
|
1258
|
+
properties: { field: boundedNameSchema, direction: { enum: ["ascending", "descending"] } }
|
|
1259
|
+
} },
|
|
1260
|
+
fields: stringListSchema,
|
|
1261
|
+
limit: { type: "integer", minimum: 1, maximum: CONSTAL_API_BOUNDS.maximumPageSize },
|
|
1262
|
+
cursor: { type: "string", maxLength: 4096 },
|
|
1263
|
+
asOf: { type: "integer", minimum: 0 },
|
|
1264
|
+
range: { type: "object", required: ["start", "end"], additionalProperties: false, properties: {
|
|
1265
|
+
start: { type: "integer", minimum: 0 },
|
|
1266
|
+
end: { type: "integer", minimum: 0 }
|
|
1267
|
+
} }
|
|
1268
|
+
} },
|
|
1269
|
+
get: { type: "object", required: ["ref"], additionalProperties: false, properties: {
|
|
1270
|
+
ref: { anyOf: [objectRefSchema, {
|
|
1271
|
+
type: "object",
|
|
1272
|
+
required: ["crn"],
|
|
1273
|
+
additionalProperties: false,
|
|
1274
|
+
properties: { crn: { type: "string", minLength: 1, maxLength: 2048 }, hash: hashSchema }
|
|
1275
|
+
}] },
|
|
1276
|
+
fields: stringListSchema,
|
|
1277
|
+
page: { type: "object", additionalProperties: false, properties: {
|
|
1278
|
+
cursor: { type: "string", maxLength: 4096 },
|
|
1279
|
+
limit: { type: "integer", minimum: 1, maximum: 500 }
|
|
1280
|
+
} }
|
|
1281
|
+
} },
|
|
1282
|
+
relations: { type: "object", required: ["start"], additionalProperties: false, properties: {
|
|
1283
|
+
start: { anyOf: [objectRefSchema, {
|
|
1284
|
+
type: "object",
|
|
1285
|
+
required: ["crn"],
|
|
1286
|
+
additionalProperties: false,
|
|
1287
|
+
properties: { crn: { type: "string", minLength: 1, maxLength: 2048 }, hash: hashSchema }
|
|
1288
|
+
}] },
|
|
1289
|
+
direction: { enum: ["outgoing", "incoming", "both"] },
|
|
1290
|
+
types: stringListSchema,
|
|
1291
|
+
depth: { type: "integer", minimum: 1, maximum: CONSTAL_API_BOUNDS.maximumRelationDepth },
|
|
1292
|
+
limit: { type: "integer", minimum: 1, maximum: CONSTAL_API_BOUNDS.maximumPageSize },
|
|
1293
|
+
cursor: { type: "string", maxLength: 4096 }
|
|
1294
|
+
} },
|
|
1295
|
+
explainPolicy: { type: "object", required: ["action", "resource"], additionalProperties: false, properties: {
|
|
1296
|
+
principal: { anyOf: [
|
|
1297
|
+
{ type: "string", maxLength: 2048 },
|
|
1298
|
+
{ type: "object", required: ["roles", "scopes"], additionalProperties: false, properties: {
|
|
1299
|
+
name: { type: "string", maxLength: 2048 },
|
|
1300
|
+
roles: {
|
|
1301
|
+
type: "array",
|
|
1302
|
+
maxItems: 64,
|
|
1303
|
+
uniqueItems: true,
|
|
1304
|
+
items: { type: "string", minLength: 1, maxLength: 2048 }
|
|
1305
|
+
},
|
|
1306
|
+
scopes: {
|
|
1307
|
+
type: "array",
|
|
1308
|
+
maxItems: 256,
|
|
1309
|
+
uniqueItems: true,
|
|
1310
|
+
items: { type: "string", pattern: "^(?:\\*|[a-z][a-z0-9-]{0,63}:(?:[a-z][a-z0-9-]{0,63}|\\*))$" }
|
|
1311
|
+
}
|
|
1312
|
+
} }
|
|
1313
|
+
] },
|
|
1314
|
+
action: actionSchema,
|
|
1315
|
+
resource: { type: "string", minLength: 1, maxLength: 2048 },
|
|
1316
|
+
context: { type: "object" },
|
|
1317
|
+
arguments: {},
|
|
1318
|
+
at: { type: "object", required: ["run"], additionalProperties: false, properties: {
|
|
1319
|
+
run: {
|
|
1320
|
+
type: "object",
|
|
1321
|
+
required: ["namespace", "agent", "session", "run"],
|
|
1322
|
+
additionalProperties: false,
|
|
1323
|
+
properties: {
|
|
1324
|
+
namespace: boundedNameSchema,
|
|
1325
|
+
agent: { type: "string", minLength: 1, maxLength: 63, pattern: "^[a-z0-9][a-z0-9-]{0,62}$" },
|
|
1326
|
+
session: boundedIdSchema,
|
|
1327
|
+
run: boundedIdSchema
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
} }
|
|
1331
|
+
} },
|
|
1332
|
+
plan: { type: "object", required: ["objective", "operations"], additionalProperties: false, properties: {
|
|
1333
|
+
objective: { type: "string", minLength: 1, maxLength: 8192 },
|
|
1334
|
+
validateOnly: { type: "boolean" },
|
|
1335
|
+
operations: {
|
|
1336
|
+
type: "array",
|
|
1337
|
+
minItems: 1,
|
|
1338
|
+
maxItems: CONSTAL_API_BOUNDS.maximumPlanOperations,
|
|
1339
|
+
items: { type: "object", required: ["operation", "input"], additionalProperties: false, properties: {
|
|
1340
|
+
id: boundedIdSchema,
|
|
1341
|
+
operation: boundedNameSchema,
|
|
1342
|
+
target: { type: "string", maxLength: 2048 },
|
|
1343
|
+
input: {},
|
|
1344
|
+
expectedCurrentHash: { anyOf: [{ type: "null" }, hashSchema] },
|
|
1345
|
+
dependsOn: { type: "array", maxItems: 64, items: boundedIdSchema }
|
|
1346
|
+
} }
|
|
1347
|
+
}
|
|
1348
|
+
} },
|
|
1349
|
+
apply: { type: "object", required: ["plan", "eventId"], additionalProperties: false, properties: {
|
|
1350
|
+
plan: {
|
|
1351
|
+
type: "object",
|
|
1352
|
+
required: ["id", "hash"],
|
|
1353
|
+
additionalProperties: false,
|
|
1354
|
+
properties: { id: boundedIdSchema, hash: hashSchema }
|
|
1355
|
+
},
|
|
1356
|
+
eventId: boundedIdSchema
|
|
1357
|
+
} },
|
|
1358
|
+
observe: { type: "object", required: ["id"], additionalProperties: false, properties: { id: boundedIdSchema } }
|
|
1359
|
+
};
|
|
1360
|
+
|
|
1004
1361
|
// src/policy-governance.ts
|
|
1005
1362
|
var SANDBOX_CONTRACT = {
|
|
1006
1363
|
id: "constal.sandbox-pool",
|
|
@@ -1081,7 +1438,7 @@ var MAX_OUTCOME_BYTES = 65536;
|
|
|
1081
1438
|
var MAX_REASON_BYTES = 1024;
|
|
1082
1439
|
var DENIAL_CODE = /^[a-z][a-z0-9._-]{0,127}$/u;
|
|
1083
1440
|
var encoder3 = new TextEncoder();
|
|
1084
|
-
function
|
|
1441
|
+
function record4(value) {
|
|
1085
1442
|
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
1086
1443
|
}
|
|
1087
1444
|
function requiredString2(value, path, maximum = 1024) {
|
|
@@ -1098,7 +1455,7 @@ function scalar(value) {
|
|
|
1098
1455
|
return value === null || typeof value === "string" || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value);
|
|
1099
1456
|
}
|
|
1100
1457
|
function validateGrant(grant, path) {
|
|
1101
|
-
if (!
|
|
1458
|
+
if (!record4(grant) || !Array.isArray(grant.actions) || grant.actions.length === 0 || grant.actions.length > 256 || !Array.isArray(grant.resources) || grant.resources.length === 0 || grant.resources.length > 256 || !Number.isSafeInteger(grant.ttlMs) || grant.ttlMs < 1 || grant.ttlMs > 864e5) {
|
|
1102
1459
|
throw new TypeError(`${path} is invalid`);
|
|
1103
1460
|
}
|
|
1104
1461
|
exactKeys2(grant, ["actions", "resources", "ttlMs"], ["actions", "resources", "ttlMs"], path);
|
|
@@ -1120,12 +1477,12 @@ function validatePolicyConstraint(constraint, path = "constraint") {
|
|
|
1120
1477
|
}
|
|
1121
1478
|
if (constraint.kind === "arguments") {
|
|
1122
1479
|
exactKeys2(source, ["kind", "schema"], ["kind", "schema"], path);
|
|
1123
|
-
if (!
|
|
1480
|
+
if (!record4(constraint.schema) || validateJsonSchemaDefinition(constraint.schema)) throw new TypeError(`${path}.schema is invalid`);
|
|
1124
1481
|
return;
|
|
1125
1482
|
}
|
|
1126
1483
|
if (constraint.kind === "context") {
|
|
1127
1484
|
exactKeys2(source, ["kind", "equals"], ["kind", "equals"], path);
|
|
1128
|
-
if (!
|
|
1485
|
+
if (!record4(constraint.equals) || Object.keys(constraint.equals).length === 0 || Object.keys(constraint.equals).length > 64 || Object.entries(constraint.equals).some(([key, value]) => !key || key.length > 256 || !scalar(value))) {
|
|
1129
1486
|
throw new TypeError(`${path}.equals is invalid`);
|
|
1130
1487
|
}
|
|
1131
1488
|
return;
|
|
@@ -1147,7 +1504,7 @@ function validateConstraints(value, path, required2) {
|
|
|
1147
1504
|
return value;
|
|
1148
1505
|
}
|
|
1149
1506
|
function policyOutcome(value) {
|
|
1150
|
-
if (!
|
|
1507
|
+
if (!record4(value) || typeof value.kind !== "string") throw new TypeError("Policy outcome is invalid");
|
|
1151
1508
|
if (value.kind === "allow") exactKeys2(value, ["kind"], ["kind"], "Policy allow outcome");
|
|
1152
1509
|
else if (value.kind === "deny") {
|
|
1153
1510
|
exactKeys2(value, ["kind", "code", "reason"], ["kind", "code"], "Policy deny outcome");
|
|
@@ -1173,10 +1530,10 @@ function policyOutcome(value) {
|
|
|
1173
1530
|
}
|
|
1174
1531
|
|
|
1175
1532
|
// src/policy.ts
|
|
1176
|
-
var
|
|
1533
|
+
var ID2 = /^[a-z0-9][a-z0-9-]{0,62}$/u;
|
|
1177
1534
|
var VERSION3 = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/u;
|
|
1178
1535
|
function policy(definition) {
|
|
1179
|
-
if (!definition || typeof definition !== "object" || Array.isArray(definition) || Object.keys(definition).some((key) => !["id", "version", "evaluate"].includes(key)) || !
|
|
1536
|
+
if (!definition || typeof definition !== "object" || Array.isArray(definition) || Object.keys(definition).some((key) => !["id", "version", "evaluate"].includes(key)) || !ID2.test(definition.id) || !VERSION3.test(definition.version) || typeof definition.evaluate !== "function") throw new TypeError("Policy definition is invalid");
|
|
1180
1537
|
return Object.freeze(definition);
|
|
1181
1538
|
}
|
|
1182
1539
|
async function evaluatePolicyDefinition(definition, input) {
|
|
@@ -1381,7 +1738,12 @@ var WEB_SEARCH_ARGUMENT_SCHEMA = {
|
|
|
1381
1738
|
type: "string",
|
|
1382
1739
|
pattern: "^[0-9]{4}-[0-9]{2}-[0-9]{2}$",
|
|
1383
1740
|
description: "Optional earliest publication date in YYYY-MM-DD form."
|
|
1384
|
-
}
|
|
1741
|
+
},
|
|
1742
|
+
searchDepth: { type: "string", enum: ["basic", "advanced"], description: "Provider search depth when supported." },
|
|
1743
|
+
includeAnswer: { type: "boolean", description: "Request a provider-synthesized answer when supported." },
|
|
1744
|
+
includeRawContent: { type: "boolean", description: "Include bounded raw source content when supported." },
|
|
1745
|
+
includeImages: { type: "boolean", description: "Include relevant image results when supported." },
|
|
1746
|
+
includeImageDescriptions: { type: "boolean", description: "Include image descriptions when supported." }
|
|
1385
1747
|
}
|
|
1386
1748
|
};
|
|
1387
1749
|
var webFetch = opTool("web", "get", {
|
|
@@ -1428,7 +1790,8 @@ var casTool = {
|
|
|
1428
1790
|
var id = { type: "string", pattern: "^[A-Za-z0-9._~-]{1,256}$", maxLength: 256 };
|
|
1429
1791
|
var content = { type: "string", minLength: 1, maxLength: 65536 };
|
|
1430
1792
|
var metadata = { type: "object", maxProperties: 64 };
|
|
1431
|
-
var
|
|
1793
|
+
var scope = { type: "string", pattern: "^[a-f0-9]{64}$", maxLength: 64 };
|
|
1794
|
+
var record5 = {
|
|
1432
1795
|
type: "object",
|
|
1433
1796
|
required: ["id", "content", "metadata", "createdAt", "updatedAt", "expiresAt"],
|
|
1434
1797
|
additionalProperties: false,
|
|
@@ -1445,8 +1808,8 @@ var MEMORY_OPERATION_DECLARATIONS = [
|
|
|
1445
1808
|
{
|
|
1446
1809
|
op: "remember",
|
|
1447
1810
|
description: "Persist or replace one record in the invocation's authenticated Memory partition.",
|
|
1448
|
-
schema: { type: "object", required: ["content"], additionalProperties: false, properties: { id, content, metadata } },
|
|
1449
|
-
resultSchema:
|
|
1811
|
+
schema: { type: "object", required: ["content"], additionalProperties: false, properties: { id, content, metadata, scope } },
|
|
1812
|
+
resultSchema: record5,
|
|
1450
1813
|
effect: "idempotent",
|
|
1451
1814
|
recovery: { kind: "idempotency-key" },
|
|
1452
1815
|
async: false,
|
|
@@ -1459,16 +1822,16 @@ var MEMORY_OPERATION_DECLARATIONS = [
|
|
|
1459
1822
|
type: "object",
|
|
1460
1823
|
required: ["query"],
|
|
1461
1824
|
additionalProperties: false,
|
|
1462
|
-
properties: { query: { type: "string", minLength: 1, maxLength: 8192 }, limit: { type: "integer", minimum: 1, maximum: 100 } }
|
|
1825
|
+
properties: { query: { type: "string", minLength: 1, maxLength: 8192 }, limit: { type: "integer", minimum: 1, maximum: 100 }, scope }
|
|
1463
1826
|
},
|
|
1464
1827
|
resultSchema: {
|
|
1465
1828
|
type: "object",
|
|
1466
1829
|
required: ["hits"],
|
|
1467
1830
|
additionalProperties: false,
|
|
1468
1831
|
properties: { hits: { type: "array", maxItems: 100, items: {
|
|
1469
|
-
...
|
|
1470
|
-
required: [...
|
|
1471
|
-
properties: { ...
|
|
1832
|
+
...record5,
|
|
1833
|
+
required: [...record5.required, "score"],
|
|
1834
|
+
properties: { ...record5.properties, score: { type: "number", minimum: 0, maximum: 1 } }
|
|
1472
1835
|
} } }
|
|
1473
1836
|
},
|
|
1474
1837
|
effect: "read-only",
|
|
@@ -1480,7 +1843,7 @@ var MEMORY_OPERATION_DECLARATIONS = [
|
|
|
1480
1843
|
op: "get",
|
|
1481
1844
|
description: "Read one record from the invocation's authenticated Memory partition.",
|
|
1482
1845
|
schema: { type: "object", required: ["id"], additionalProperties: false, properties: { id } },
|
|
1483
|
-
resultSchema: { anyOf: [
|
|
1846
|
+
resultSchema: { anyOf: [record5, { type: "null" }] },
|
|
1484
1847
|
effect: "read-only",
|
|
1485
1848
|
recovery: { kind: "repeat" },
|
|
1486
1849
|
async: false,
|
|
@@ -1577,7 +1940,7 @@ var TRAINING_PROVIDER_CAPABILITY = {
|
|
|
1577
1940
|
version: "1",
|
|
1578
1941
|
hash: "c23ed69afdb42e0bdafdeb716067d1f4a506fc5180894854d18200df23a0f5da"
|
|
1579
1942
|
};
|
|
1580
|
-
function
|
|
1943
|
+
function record6(value) {
|
|
1581
1944
|
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
1582
1945
|
}
|
|
1583
1946
|
function integer(value, field2, minimum, maximum) {
|
|
@@ -1593,7 +1956,7 @@ function finite(value, field2, minimum, maximum) {
|
|
|
1593
1956
|
return value;
|
|
1594
1957
|
}
|
|
1595
1958
|
function providerPin(value) {
|
|
1596
|
-
const candidate =
|
|
1959
|
+
const candidate = record6(value);
|
|
1597
1960
|
if (!candidate || typeof candidate.crn !== "string" || typeof candidate.hash !== "string" || !HASH2.test(candidate.hash) || Object.keys(candidate).some((key) => !["crn", "hash"].includes(key))) throw new TypeError("training provider pin is invalid");
|
|
1598
1961
|
const parts = parseResourceName(candidate.crn);
|
|
1599
1962
|
if (["model", "memory"].includes(parts.kind)) throw new TypeError("training provider pin is invalid");
|
|
@@ -1601,21 +1964,21 @@ function providerPin(value) {
|
|
|
1601
1964
|
}
|
|
1602
1965
|
function resumePoint(value) {
|
|
1603
1966
|
if (value === null) return null;
|
|
1604
|
-
const candidate =
|
|
1967
|
+
const candidate = record6(value);
|
|
1605
1968
|
if (!candidate || typeof candidate.job !== "string" || !JOB_ID.test(candidate.job) || !Number.isSafeInteger(candidate.step) || Number(candidate.step) < 0 || typeof candidate.ref !== "string" || !HASH2.test(candidate.ref) || Object.keys(candidate).some((key) => !["job", "step", "ref"].includes(key))) {
|
|
1606
1969
|
throw new TypeError("training resume point is invalid");
|
|
1607
1970
|
}
|
|
1608
1971
|
return candidate;
|
|
1609
1972
|
}
|
|
1610
1973
|
function trainingProviderMetadata(value) {
|
|
1611
|
-
const candidate =
|
|
1612
|
-
const checkpoints =
|
|
1974
|
+
const candidate = record6(value);
|
|
1975
|
+
const checkpoints = record6(candidate?.checkpoints);
|
|
1613
1976
|
if (!candidate || candidate.lifecycleVersion !== 1 || !Array.isArray(candidate.methods) || candidate.methods.length === 0 || candidate.methods.length > 2 || candidate.methods.some((method) => method !== "sft" && method !== "rl") || new Set(candidate.methods).size !== candidate.methods.length || !Array.isArray(candidate.models) || candidate.models.length > 512 || !checkpoints || !Array.isArray(checkpoints.formats) || checkpoints.formats.length === 0 || checkpoints.formats.length > 32 || checkpoints.formats.some((format) => typeof format !== "string" || !/^[a-z0-9][a-z0-9._+-]{0,63}$/u.test(format)) || new Set(checkpoints.formats).size !== checkpoints.formats.length || typeof checkpoints.resume !== "boolean" || typeof checkpoints.fork !== "boolean" || Object.keys(checkpoints).some((key) => !["formats", "resume", "fork"].includes(key)) || Object.keys(candidate).some((key) => !["lifecycleVersion", "methods", "models", "checkpoints"].includes(key))) {
|
|
1614
1977
|
throw new TypeError("Training Provider metadata is invalid");
|
|
1615
1978
|
}
|
|
1616
1979
|
const models = candidate.models.map((raw) => {
|
|
1617
|
-
const model =
|
|
1618
|
-
const pricing =
|
|
1980
|
+
const model = record6(raw);
|
|
1981
|
+
const pricing = record6(model?.pricing);
|
|
1619
1982
|
if (!model || typeof model.id !== "string" || !JOB_ID.test(model.id) || typeof model.name !== "string" || !model.name || model.name.length > 128 || typeof model.providerModel !== "string" || !PROVIDER_MODEL_ID.test(model.providerModel) || !Number.isSafeInteger(model.contextTokens) || Number(model.contextTokens) < 1 || !pricing || pricing.currency !== "USD" || pricing.unit !== "million_tokens" || ["prefillMicroUsd", "cachedPrefillMicroUsd", "sampleMicroUsd", "trainMicroUsd"].some((key) => !Number.isSafeInteger(pricing[key]) || Number(pricing[key]) < 0) || Object.keys(pricing).some((key) => !["currency", "unit", "prefillMicroUsd", "cachedPrefillMicroUsd", "sampleMicroUsd", "trainMicroUsd"].includes(key)) || Object.keys(model).some((key) => !["id", "name", "providerModel", "contextTokens", "pricing"].includes(key))) {
|
|
1620
1983
|
throw new TypeError("Training Provider model offer is invalid");
|
|
1621
1984
|
}
|
|
@@ -1632,21 +1995,21 @@ function trainingProviderMetadata(value) {
|
|
|
1632
1995
|
};
|
|
1633
1996
|
}
|
|
1634
1997
|
function datasetRef(value, field2) {
|
|
1635
|
-
const candidate =
|
|
1998
|
+
const candidate = record6(value);
|
|
1636
1999
|
if (!candidate || typeof candidate.crn !== "string" || parseResourceName(datasetName(candidate.crn)).kind !== "dataset" || typeof candidate.version !== "string" || !VERSION4.test(candidate.version) || typeof candidate.hash !== "string" || !HASH2.test(candidate.hash) || Object.keys(candidate).some((key) => !["crn", "version", "hash"].includes(key))) {
|
|
1637
2000
|
throw new TypeError(`${field2} is invalid`);
|
|
1638
2001
|
}
|
|
1639
2002
|
return candidate;
|
|
1640
2003
|
}
|
|
1641
2004
|
function scorerRef(value, field2) {
|
|
1642
|
-
const candidate =
|
|
2005
|
+
const candidate = record6(value);
|
|
1643
2006
|
if (!candidate || typeof candidate.crn !== "string" || parseResourceName(scorerName(candidate.crn)).kind !== "scorer" || typeof candidate.version !== "string" || !VERSION4.test(candidate.version) || typeof candidate.hash !== "string" || !HASH2.test(candidate.hash) || Object.keys(candidate).some((key) => !["crn", "version", "hash"].includes(key))) {
|
|
1644
2007
|
throw new TypeError(`${field2} is invalid`);
|
|
1645
2008
|
}
|
|
1646
2009
|
return candidate;
|
|
1647
2010
|
}
|
|
1648
2011
|
function trainingRecipe(value) {
|
|
1649
|
-
const candidate =
|
|
2012
|
+
const candidate = record6(value);
|
|
1650
2013
|
const allowed = [
|
|
1651
2014
|
"method",
|
|
1652
2015
|
"baseModel",
|
|
@@ -1690,7 +2053,7 @@ function trainingRecipe(value) {
|
|
|
1690
2053
|
return recipe;
|
|
1691
2054
|
}
|
|
1692
2055
|
function startTrainingRequest(value) {
|
|
1693
|
-
const candidate =
|
|
2056
|
+
const candidate = record6(value);
|
|
1694
2057
|
if (!candidate || candidate.jobId !== void 0 && (typeof candidate.jobId !== "string" || !JOB_ID.test(candidate.jobId)) || typeof candidate.outputModelId !== "string" || !MODEL_ID.test(candidate.outputModelId) || Object.keys(candidate).some((key) => !["jobId", "provider", "resumeFrom", "recipe", "outputModelId"].includes(key))) {
|
|
1695
2058
|
throw new TypeError("training request is invalid");
|
|
1696
2059
|
}
|
|
@@ -1703,12 +2066,12 @@ function startTrainingRequest(value) {
|
|
|
1703
2066
|
};
|
|
1704
2067
|
}
|
|
1705
2068
|
function renderTrainingCompletion(input, expected) {
|
|
1706
|
-
const
|
|
2069
|
+
const text2 = (value) => typeof value === "string" ? value : canonicalJson(value);
|
|
1707
2070
|
return { prompt: `Input:
|
|
1708
|
-
${
|
|
2071
|
+
${text2(input)}
|
|
1709
2072
|
|
|
1710
2073
|
Response:
|
|
1711
|
-
`, completion: expected === void 0 || expected === null ? null :
|
|
2074
|
+
`, completion: expected === void 0 || expected === null ? null : text2(expected) };
|
|
1712
2075
|
}
|
|
1713
2076
|
|
|
1714
2077
|
// src/gateway.ts
|
|
@@ -2057,20 +2420,20 @@ function credentialInteractionEvent(value) {
|
|
|
2057
2420
|
return event;
|
|
2058
2421
|
}
|
|
2059
2422
|
function credentialInteractionPrimaryAction(value, origins) {
|
|
2060
|
-
const
|
|
2061
|
-
const event = interactionRecord(
|
|
2062
|
-
if (!
|
|
2423
|
+
const action3 = interactionRecord(value);
|
|
2424
|
+
const event = interactionRecord(action3?.event);
|
|
2425
|
+
if (!action3 || !event || !boundedText(action3.label, 64) || !exactKeys3(event, ["kind"]) || event.kind !== "continue") {
|
|
2063
2426
|
throw new TypeError("credential interaction primary action is invalid");
|
|
2064
2427
|
}
|
|
2065
|
-
if (
|
|
2066
|
-
if (!exactKeys3(
|
|
2067
|
-
} else if (
|
|
2068
|
-
if (!exactKeys3(
|
|
2428
|
+
if (action3.kind === "continue") {
|
|
2429
|
+
if (!exactKeys3(action3, ["kind", "label", "event"])) throw new TypeError("credential interaction primary action is invalid");
|
|
2430
|
+
} else if (action3.kind === "open-url") {
|
|
2431
|
+
if (!exactKeys3(action3, ["kind", "label", "url", "event"]) || !boundedText(action3.url, 4096)) {
|
|
2069
2432
|
throw new TypeError("credential interaction primary action is invalid");
|
|
2070
2433
|
}
|
|
2071
2434
|
let url;
|
|
2072
2435
|
try {
|
|
2073
|
-
url = new URL(
|
|
2436
|
+
url = new URL(action3.url);
|
|
2074
2437
|
} catch {
|
|
2075
2438
|
throw new TypeError("credential interaction primary action URL is invalid");
|
|
2076
2439
|
}
|
|
@@ -2078,52 +2441,52 @@ function credentialInteractionPrimaryAction(value, origins) {
|
|
|
2078
2441
|
throw new TypeError("credential interaction primary action URL is not authorized");
|
|
2079
2442
|
}
|
|
2080
2443
|
} else throw new TypeError("credential interaction primary action is invalid");
|
|
2081
|
-
return
|
|
2444
|
+
return action3;
|
|
2082
2445
|
}
|
|
2083
2446
|
function credentialInteractionAction(value, origins, state, sessionExpiresAt) {
|
|
2084
|
-
const
|
|
2085
|
-
if (!
|
|
2447
|
+
const action3 = interactionRecord(value);
|
|
2448
|
+
if (!action3 || !["redirect", "form", "display", "wait", "complete"].includes(String(action3.kind ?? ""))) {
|
|
2086
2449
|
throw new TypeError("credential interaction action is invalid");
|
|
2087
2450
|
}
|
|
2088
|
-
const expiresAt =
|
|
2451
|
+
const expiresAt = action3.kind === "complete" ? null : interactionExpiry(action3.expiresAt, sessionExpiresAt);
|
|
2089
2452
|
if (Number.isNaN(expiresAt)) throw new TypeError("credential interaction action expiry is invalid");
|
|
2090
|
-
if (
|
|
2091
|
-
if (!exactKeys3(
|
|
2453
|
+
if (action3.kind === "redirect") {
|
|
2454
|
+
if (!exactKeys3(action3, ["kind", "url", "expiresAt"]) || !boundedText(action3.url, 4096)) {
|
|
2092
2455
|
throw new TypeError("credential interaction redirect is invalid");
|
|
2093
2456
|
}
|
|
2094
2457
|
let url;
|
|
2095
2458
|
try {
|
|
2096
|
-
url = new URL(
|
|
2459
|
+
url = new URL(action3.url);
|
|
2097
2460
|
} catch {
|
|
2098
2461
|
throw new TypeError("credential interaction redirect is invalid");
|
|
2099
2462
|
}
|
|
2100
2463
|
if (url.protocol !== "https:" || url.username || url.password || url.hash || !origins.includes(url.origin) || url.searchParams.getAll("state").length !== 1 || url.searchParams.get("state") !== state) {
|
|
2101
2464
|
throw new TypeError("credential interaction redirect is not authorized");
|
|
2102
2465
|
}
|
|
2103
|
-
} else if (
|
|
2104
|
-
if (!exactKeys3(
|
|
2466
|
+
} else if (action3.kind === "form") {
|
|
2467
|
+
if (!exactKeys3(action3, ["kind", "schema", "title", "description", "submitLabel", "expiresAt"]) || action3.title !== void 0 && !boundedText(action3.title, 128) || action3.description !== void 0 && !boundedText(action3.description, 1024) || action3.submitLabel !== void 0 && !boundedText(action3.submitLabel, 64)) {
|
|
2105
2468
|
throw new TypeError("credential interaction form is invalid");
|
|
2106
2469
|
}
|
|
2107
|
-
const schemaError = validateJsonSchemaDefinition(
|
|
2108
|
-
const formSchema = interactionRecord(
|
|
2109
|
-
if (schemaError || !formSchema || formSchema.type !== "object" || formSchema.additionalProperties !== false || new TextEncoder().encode(canonicalJson(
|
|
2470
|
+
const schemaError = validateJsonSchemaDefinition(action3.schema, "$interaction.form.schema");
|
|
2471
|
+
const formSchema = interactionRecord(action3.schema);
|
|
2472
|
+
if (schemaError || !formSchema || formSchema.type !== "object" || formSchema.additionalProperties !== false || new TextEncoder().encode(canonicalJson(action3.schema)).byteLength > 65536) {
|
|
2110
2473
|
throw new TypeError(`credential interaction form schema is invalid${schemaError ? `: ${schemaError}` : ""}`);
|
|
2111
2474
|
}
|
|
2112
|
-
} else if (
|
|
2113
|
-
if (!exactKeys3(
|
|
2475
|
+
} else if (action3.kind === "display") {
|
|
2476
|
+
if (!exactKeys3(action3, ["kind", "instructions", "title", "userCode", "primaryAction", "expiresAt"]) || !boundedText(action3.instructions, 4096) || action3.title !== void 0 && !boundedText(action3.title, 128) || action3.userCode !== void 0 && !boundedText(action3.userCode, 512)) {
|
|
2114
2477
|
throw new TypeError("credential interaction display is invalid");
|
|
2115
2478
|
}
|
|
2116
|
-
credentialInteractionPrimaryAction(
|
|
2117
|
-
} else if (
|
|
2118
|
-
if (!exactKeys3(
|
|
2479
|
+
credentialInteractionPrimaryAction(action3.primaryAction, origins);
|
|
2480
|
+
} else if (action3.kind === "wait") {
|
|
2481
|
+
if (!exactKeys3(action3, ["kind", "resume", "expiresAt", "pollAfterMs"]) || !["callback", "poll"].includes(String(action3.resume ?? "")) || expiresAt === null || action3.pollAfterMs !== void 0 && (!Number.isSafeInteger(action3.pollAfterMs) || Number(action3.pollAfterMs) < 1e3 || Number(action3.pollAfterMs) > 3e5) || action3.resume === "poll" && action3.pollAfterMs === void 0 || action3.resume === "callback" && action3.pollAfterMs !== void 0) {
|
|
2119
2482
|
throw new TypeError("credential interaction wait action is invalid");
|
|
2120
2483
|
}
|
|
2121
2484
|
} else {
|
|
2122
|
-
if (!exactKeys3(
|
|
2485
|
+
if (!exactKeys3(action3, ["kind", "material", "expiresAt"]) || !boundedText(action3.material, 1048576) || action3.expiresAt !== void 0 && action3.expiresAt !== null && (!Number.isSafeInteger(action3.expiresAt) || Number(action3.expiresAt) <= Date.now())) {
|
|
2123
2486
|
throw new TypeError("credential interaction completion is invalid");
|
|
2124
2487
|
}
|
|
2125
2488
|
}
|
|
2126
|
-
return
|
|
2489
|
+
return action3;
|
|
2127
2490
|
}
|
|
2128
2491
|
function credentialInteractionResult(value, origins, state, sessionExpiresAt) {
|
|
2129
2492
|
const result = interactionRecord(value);
|
|
@@ -2235,17 +2598,17 @@ function credentialProvider(definition) {
|
|
|
2235
2598
|
var NAME4 = /^[a-z0-9][a-z0-9._-]{0,127}$/u;
|
|
2236
2599
|
var HEADER = /^[a-z0-9][a-z0-9-]{0,63}$/u;
|
|
2237
2600
|
var RESERVED_HEADERS = /* @__PURE__ */ new Set(["connection", "content-type", "host", "anthropic-version", "proxy-authorization", "transfer-encoding"]);
|
|
2238
|
-
function
|
|
2601
|
+
function record7(value) {
|
|
2239
2602
|
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
2240
2603
|
}
|
|
2241
2604
|
function credentialHeader(value, name) {
|
|
2242
2605
|
if (value === null || value === void 0) return null;
|
|
2243
|
-
const source =
|
|
2606
|
+
const source = record7(value);
|
|
2244
2607
|
if (!source || typeof source.slot !== "string" || !NAME4.test(source.slot) || typeof source.header !== "string" || !HEADER.test(source.header.toLowerCase()) || RESERVED_HEADERS.has(source.header.toLowerCase()) || source.header.toLowerCase().startsWith("cf-") || source.scheme !== "bearer" && source.scheme !== "raw") throw new TypeError(`${name} is invalid`);
|
|
2245
2608
|
return { slot: source.slot, header: source.header.toLowerCase(), scheme: source.scheme };
|
|
2246
2609
|
}
|
|
2247
2610
|
function normalizeModelGatewayConfig(value) {
|
|
2248
|
-
const source =
|
|
2611
|
+
const source = record7(value);
|
|
2249
2612
|
if (!source || typeof source.baseUrl !== "string" || source.baseUrl.length > 2048 || source.protocol !== "anthropic" && source.protocol !== "openai" || typeof source.model !== "string" || source.model.length === 0 || source.model.length > 256) {
|
|
2250
2613
|
throw new TypeError("model gateway config is invalid");
|
|
2251
2614
|
}
|
|
@@ -2295,6 +2658,12 @@ function modelPrompt(args) {
|
|
|
2295
2658
|
return JSON.stringify({ objective: args.objective ?? null, context: args.context ?? null, feedback: args.feedback ?? [] });
|
|
2296
2659
|
}
|
|
2297
2660
|
function modelProtocolRequest(protocol, model, maxOutputTokens, temperature, args) {
|
|
2661
|
+
if (args.toolChoice !== void 0 && args.toolChoice !== "auto" && args.toolChoice !== "required") {
|
|
2662
|
+
throw new TypeError("model Tool choice is invalid");
|
|
2663
|
+
}
|
|
2664
|
+
if (args.toolChoice === "required" && !args.tools?.length) {
|
|
2665
|
+
throw new TypeError("required model Tool choice needs at least one offered Tool");
|
|
2666
|
+
}
|
|
2298
2667
|
const prompt = modelPrompt(args);
|
|
2299
2668
|
if (protocol === "anthropic") return {
|
|
2300
2669
|
model,
|
|
@@ -2302,7 +2671,8 @@ function modelProtocolRequest(protocol, model, maxOutputTokens, temperature, arg
|
|
|
2302
2671
|
messages: [{ role: "user", content: prompt }],
|
|
2303
2672
|
max_tokens: maxOutputTokens,
|
|
2304
2673
|
...temperature === null ? {} : { temperature },
|
|
2305
|
-
...args.tools?.length ? { tools: args.tools.map((tool) => ({ name: tool.name, description: tool.description, input_schema: tool.schema })) } : {}
|
|
2674
|
+
...args.tools?.length ? { tools: args.tools.map((tool) => ({ name: tool.name, description: tool.description, input_schema: tool.schema })) } : {},
|
|
2675
|
+
...args.toolChoice === void 0 ? {} : { tool_choice: { type: args.toolChoice === "required" ? "any" : "auto" } }
|
|
2306
2676
|
};
|
|
2307
2677
|
if (protocol === "openai") return {
|
|
2308
2678
|
model,
|
|
@@ -2315,7 +2685,8 @@ function modelProtocolRequest(protocol, model, maxOutputTokens, temperature, arg
|
|
|
2315
2685
|
...args.tools?.length ? { tools: args.tools.map((tool) => ({
|
|
2316
2686
|
type: "function",
|
|
2317
2687
|
function: { name: tool.name, description: tool.description, parameters: tool.schema }
|
|
2318
|
-
})) } : {}
|
|
2688
|
+
})) } : {},
|
|
2689
|
+
...args.toolChoice === void 0 ? {} : { tool_choice: args.toolChoice }
|
|
2319
2690
|
};
|
|
2320
2691
|
throw new TypeError("model gateway protocol is invalid");
|
|
2321
2692
|
}
|
|
@@ -2332,21 +2703,21 @@ function costMetadata(usage) {
|
|
|
2332
2703
|
};
|
|
2333
2704
|
}
|
|
2334
2705
|
function modelProtocolResult(protocol, raw, provider, model) {
|
|
2335
|
-
const source =
|
|
2706
|
+
const source = record7(raw) ?? {};
|
|
2336
2707
|
const toolCalls = [];
|
|
2337
2708
|
let content2 = "";
|
|
2338
2709
|
let usage;
|
|
2339
2710
|
if (protocol === "anthropic") {
|
|
2340
2711
|
const blocks = Array.isArray(source.content) ? source.content : [];
|
|
2341
2712
|
content2 = blocks.map((candidate) => {
|
|
2342
|
-
const block =
|
|
2713
|
+
const block = record7(candidate);
|
|
2343
2714
|
if (block?.type === "text" && typeof block.text === "string") return block.text;
|
|
2344
2715
|
if (block?.type === "tool_use" && typeof block.id === "string" && typeof block.name === "string") {
|
|
2345
2716
|
toolCalls.push({ id: block.id, name: block.name, args: block.input ?? {} });
|
|
2346
2717
|
}
|
|
2347
2718
|
return "";
|
|
2348
2719
|
}).join("");
|
|
2349
|
-
const values =
|
|
2720
|
+
const values = record7(source.usage) ?? {};
|
|
2350
2721
|
const cached = integer2(values.cache_read_input_tokens);
|
|
2351
2722
|
usage = {
|
|
2352
2723
|
input: integer2(values.input_tokens) + integer2(values.cache_creation_input_tokens) + cached,
|
|
@@ -2355,12 +2726,12 @@ function modelProtocolResult(protocol, raw, provider, model) {
|
|
|
2355
2726
|
...costMetadata(values)
|
|
2356
2727
|
};
|
|
2357
2728
|
} else if (protocol === "openai") {
|
|
2358
|
-
const choice =
|
|
2359
|
-
const message =
|
|
2729
|
+
const choice = record7(Array.isArray(source.choices) ? source.choices[0] : null) ?? {};
|
|
2730
|
+
const message = record7(choice.message) ?? {};
|
|
2360
2731
|
content2 = typeof message.content === "string" ? message.content : "";
|
|
2361
2732
|
for (const candidate of Array.isArray(message.tool_calls) ? message.tool_calls : []) {
|
|
2362
|
-
const call =
|
|
2363
|
-
const fn =
|
|
2733
|
+
const call = record7(candidate);
|
|
2734
|
+
const fn = record7(call?.function);
|
|
2364
2735
|
if (typeof call?.id !== "string" || typeof fn?.name !== "string" || typeof fn.arguments !== "string") continue;
|
|
2365
2736
|
let args;
|
|
2366
2737
|
try {
|
|
@@ -2370,11 +2741,11 @@ function modelProtocolResult(protocol, raw, provider, model) {
|
|
|
2370
2741
|
}
|
|
2371
2742
|
toolCalls.push({ id: call.id, name: fn.name, args });
|
|
2372
2743
|
}
|
|
2373
|
-
const values =
|
|
2744
|
+
const values = record7(source.usage) ?? {};
|
|
2374
2745
|
usage = {
|
|
2375
2746
|
input: integer2(values.prompt_tokens),
|
|
2376
2747
|
output: integer2(values.completion_tokens),
|
|
2377
|
-
cached: integer2(
|
|
2748
|
+
cached: integer2(record7(values.prompt_tokens_details)?.cached_tokens),
|
|
2378
2749
|
...costMetadata(values)
|
|
2379
2750
|
};
|
|
2380
2751
|
} else throw new TypeError("model gateway protocol is invalid");
|
|
@@ -2386,14 +2757,14 @@ function modelProtocolResult(protocol, raw, provider, model) {
|
|
|
2386
2757
|
function validPointer(value) {
|
|
2387
2758
|
return typeof value === "string" && value.length <= 4096 && (value === "" || value.startsWith("/") && !/~(?:[^01]|$)/u.test(value));
|
|
2388
2759
|
}
|
|
2389
|
-
function
|
|
2760
|
+
function record8(value) {
|
|
2390
2761
|
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
2391
2762
|
}
|
|
2392
2763
|
function exactKeys4(value, allowed) {
|
|
2393
2764
|
return Object.keys(value).every((key) => allowed.includes(key));
|
|
2394
2765
|
}
|
|
2395
2766
|
function scorerRule(value, depth, state) {
|
|
2396
|
-
const rule =
|
|
2767
|
+
const rule = record8(value);
|
|
2397
2768
|
if (!rule || depth > 32 || ++state.rules > 1024 || typeof rule.op !== "string") throw new TypeError("Code Scorer IR is invalid");
|
|
2398
2769
|
if (rule.op === "all" || rule.op === "any") {
|
|
2399
2770
|
if (!exactKeys4(rule, ["op", "rules"]) || !Array.isArray(rule.rules) || rule.rules.length < 1 || rule.rules.length > 128) {
|
|
@@ -2406,7 +2777,7 @@ function scorerRule(value, depth, state) {
|
|
|
2406
2777
|
return { op: "not", rule: scorerRule(rule.rule, depth + 1, state) };
|
|
2407
2778
|
}
|
|
2408
2779
|
if (rule.op === "schema") {
|
|
2409
|
-
if (!exactKeys4(rule, ["op", "path", "schema"]) || !validPointer(rule.path) || !
|
|
2780
|
+
if (!exactKeys4(rule, ["op", "path", "schema"]) || !validPointer(rule.path) || !record8(rule.schema) || validateJsonSchemaDefinition(rule.schema)) throw new TypeError("Code Scorer schema rule is invalid");
|
|
2410
2781
|
return rule;
|
|
2411
2782
|
}
|
|
2412
2783
|
if (rule.op === "regex") {
|
|
@@ -2441,7 +2812,7 @@ function scorerRule(value, depth, state) {
|
|
|
2441
2812
|
throw new TypeError("Code Scorer operation is invalid");
|
|
2442
2813
|
}
|
|
2443
2814
|
function codeScorerIR(value) {
|
|
2444
|
-
const ir =
|
|
2815
|
+
const ir = record8(value);
|
|
2445
2816
|
if (!ir || ir.v !== 1 || !exactKeys4(ir, ["v", "rule"])) throw new TypeError("Code Scorer IR is invalid");
|
|
2446
2817
|
return { v: 1, rule: scorerRule(ir.rule, 0, { rules: 0 }) };
|
|
2447
2818
|
}
|
|
@@ -2454,7 +2825,7 @@ function pointer(value, path) {
|
|
|
2454
2825
|
if (!/^(?:0|[1-9][0-9]*)$/u.test(key) || Number(key) >= current.length) return { found: false, value: void 0 };
|
|
2455
2826
|
current = current[Number(key)];
|
|
2456
2827
|
} else {
|
|
2457
|
-
const source =
|
|
2828
|
+
const source = record8(current);
|
|
2458
2829
|
if (!source || !Object.hasOwn(source, key)) return { found: false, value: void 0 };
|
|
2459
2830
|
current = source[key];
|
|
2460
2831
|
}
|
|
@@ -2482,16 +2853,16 @@ function evaluate(rule, subject) {
|
|
|
2482
2853
|
return value.pass ? fail("", "negated rule passed") : { pass: true, checks: value.checks, failures: [] };
|
|
2483
2854
|
}
|
|
2484
2855
|
if (rule.op === "citations-in-source") {
|
|
2485
|
-
const
|
|
2856
|
+
const text2 = pointer(subject, rule.textPath);
|
|
2486
2857
|
const sources = pointer(subject, rule.sourcesPath);
|
|
2487
|
-
if (!
|
|
2858
|
+
if (!text2.found || typeof text2.value !== "string") return fail(rule.textPath, "citation text is missing");
|
|
2488
2859
|
if (!sources.found || !Array.isArray(sources.value)) return fail(rule.sourcesPath, "citation sources are missing");
|
|
2489
2860
|
const available = new Set(sources.value.flatMap((source, index) => {
|
|
2490
2861
|
if (typeof source === "string") return [source, String(index + 1)];
|
|
2491
|
-
const item =
|
|
2862
|
+
const item = record8(source);
|
|
2492
2863
|
return item ? [String(item.id ?? ""), String(index + 1)].filter(Boolean) : [String(index + 1)];
|
|
2493
2864
|
}));
|
|
2494
|
-
const citations = [...
|
|
2865
|
+
const citations = [...text2.value.matchAll(/\[([^\]\n]{1,128})\]/gu)].map((match) => match[1].trim());
|
|
2495
2866
|
return citations.length > 0 && citations.every((citation) => available.has(citation)) ? pass() : fail(rule.textPath, "citation is absent or not in sources");
|
|
2496
2867
|
}
|
|
2497
2868
|
const selected = pointer(subject, rule.path);
|
|
@@ -2507,7 +2878,7 @@ function evaluate(rule, subject) {
|
|
|
2507
2878
|
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));
|
|
2508
2879
|
return contains ? pass() : fail(rule.path, "value is not contained");
|
|
2509
2880
|
}
|
|
2510
|
-
const names = Array.isArray(selected.value) ? selected.value.map((item) => typeof item === "string" ? item : String(
|
|
2881
|
+
const names = Array.isArray(selected.value) ? selected.value.map((item) => typeof item === "string" ? item : String(record8(item)?.name ?? "")) : [];
|
|
2511
2882
|
const sequence = rule.mode === "exact" ? names.length === rule.expected.length && names.every((name, index) => name === rule.expected[index]) : rule.expected.reduce((cursor, expected) => {
|
|
2512
2883
|
const index = names.indexOf(expected, cursor);
|
|
2513
2884
|
return index < 0 ? Number.POSITIVE_INFINITY : index + 1;
|
|
@@ -2527,9 +2898,9 @@ function evaluateCodeScorer(raw, subject) {
|
|
|
2527
2898
|
|
|
2528
2899
|
// src/errors.ts
|
|
2529
2900
|
var GateExhausted = class extends Error {
|
|
2530
|
-
constructor(
|
|
2901
|
+
constructor(record9) {
|
|
2531
2902
|
super("turn gate exhausted");
|
|
2532
|
-
this.record =
|
|
2903
|
+
this.record = record9;
|
|
2533
2904
|
this.name = "GateExhausted";
|
|
2534
2905
|
}
|
|
2535
2906
|
record;
|
|
@@ -2705,6 +3076,10 @@ var SessionDeleted = class extends Error {
|
|
|
2705
3076
|
export {
|
|
2706
3077
|
AfterYield,
|
|
2707
3078
|
ApiError,
|
|
3079
|
+
CONSTAL_API_CAPABILITY,
|
|
3080
|
+
CONSTAL_API_OPERATIONS,
|
|
3081
|
+
CONSTAL_API_OPERATION_SCHEMAS,
|
|
3082
|
+
CONSTAL_API_VERSION,
|
|
2708
3083
|
CommitConflict,
|
|
2709
3084
|
CommitGateRejected,
|
|
2710
3085
|
CredentialRevoked,
|
|
@@ -2812,6 +3187,10 @@ export {
|
|
|
2812
3187
|
scopedCredentialRef,
|
|
2813
3188
|
scopedResourceRef,
|
|
2814
3189
|
scorerName,
|
|
3190
|
+
setupAwait,
|
|
3191
|
+
setupScreen,
|
|
3192
|
+
setupScreenView,
|
|
3193
|
+
setupSubmission,
|
|
2815
3194
|
sha256Hex,
|
|
2816
3195
|
stageOutput,
|
|
2817
3196
|
startTrainingRequest,
|