@constal/sdk 6.3.0 → 6.5.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 +16 -20
- package/package.json +1 -1
- package/publish/api.json +2 -6
- package/publish/index.d.ts +38 -39
- package/publish/index.js +642 -623
package/publish/index.js
CHANGED
|
@@ -136,170 +136,6 @@ function bucketFor(value, buckets) {
|
|
|
136
136
|
return murmur3_32(canonicalJson(value)) % buckets;
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
// packages/sdk/src/skills.ts
|
|
140
|
-
function metadata(value) {
|
|
141
|
-
if (!value || typeof value.id !== "string" || !value.id || value.description !== void 0 && typeof value.description !== "string" || value.source !== void 0 && typeof value.source !== "string") {
|
|
142
|
-
throw new TypeError("Skill requires an id and optional description/source strings");
|
|
143
|
-
}
|
|
144
|
-
return {
|
|
145
|
-
id: value.id,
|
|
146
|
-
...value.description === void 0 ? {} : { description: value.description },
|
|
147
|
-
...value.source === void 0 ? {} : { source: value.source }
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
function catalog(values) {
|
|
151
|
-
if (!Array.isArray(values)) throw new TypeError("Skill source must return a list");
|
|
152
|
-
const result = values.map(metadata);
|
|
153
|
-
if (new Set(result.map((value) => value.id)).size !== result.length) throw new TypeError("Skill source contains duplicate ids");
|
|
154
|
-
return result;
|
|
155
|
-
}
|
|
156
|
-
function skills(input) {
|
|
157
|
-
let source;
|
|
158
|
-
if (Array.isArray(input)) {
|
|
159
|
-
const descriptions = catalog(input);
|
|
160
|
-
const entries = new Map(descriptions.map((description, index) => {
|
|
161
|
-
if (typeof input[index].instructions !== "string") throw new TypeError("Skill instructions must be a string");
|
|
162
|
-
return [description.id, { ...description, instructions: input[index].instructions }];
|
|
163
|
-
}));
|
|
164
|
-
source = { list: () => descriptions, load: (id2) => {
|
|
165
|
-
const value = entries.get(id2);
|
|
166
|
-
if (!value) throw new TypeError(`Skill not found: ${id2}`);
|
|
167
|
-
return value;
|
|
168
|
-
} };
|
|
169
|
-
} else {
|
|
170
|
-
source = input;
|
|
171
|
-
if (!source || typeof source.list !== "function" || typeof source.load !== "function") throw new TypeError("Skill source requires list and load functions");
|
|
172
|
-
}
|
|
173
|
-
const list = async (ctx) => catalog(await source.list(ctx));
|
|
174
|
-
const load = async (id2, ctx) => {
|
|
175
|
-
const value = await source.load(id2, ctx);
|
|
176
|
-
const description = metadata(value);
|
|
177
|
-
if (description.id !== id2) throw new TypeError("Skill source returned a different skill");
|
|
178
|
-
if (typeof value.instructions !== "string") throw new TypeError("Skill instructions must be a string");
|
|
179
|
-
const content2 = { ...description, instructions: value.instructions };
|
|
180
|
-
return { ...content2, hash: await hashValue(content2) };
|
|
181
|
-
};
|
|
182
|
-
const access = { needs: source.needs ?? [], maxEffect: source.maxEffect ?? "read-only" };
|
|
183
|
-
return { list, load, tools: {
|
|
184
|
-
list_skills: {
|
|
185
|
-
name: "list_skills",
|
|
186
|
-
version: "1",
|
|
187
|
-
description: "List available skills with their descriptions and source locations.",
|
|
188
|
-
schema: { type: "object", properties: {}, additionalProperties: false },
|
|
189
|
-
...access,
|
|
190
|
-
run: (_args, ctx) => list(ctx)
|
|
191
|
-
},
|
|
192
|
-
read_skill: {
|
|
193
|
-
name: "read_skill",
|
|
194
|
-
version: "1",
|
|
195
|
-
description: "Read a skill's complete instructions and content identity.",
|
|
196
|
-
schema: { type: "object", required: ["id"], properties: { id: { type: "string", minLength: 1 } }, additionalProperties: false },
|
|
197
|
-
...access,
|
|
198
|
-
run: (args, ctx) => load(args.id, ctx)
|
|
199
|
-
}
|
|
200
|
-
} };
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// packages/sdk/src/partition.ts
|
|
204
|
-
var encoder2 = new TextEncoder();
|
|
205
|
-
function positiveSafeInteger(value) {
|
|
206
|
-
return Number.isSafeInteger(value) && Number(value) > 0;
|
|
207
|
-
}
|
|
208
|
-
function validatePartitionSpec(spec) {
|
|
209
|
-
if (!spec || typeof spec !== "object") throw new TypeError("partition spec must be an object");
|
|
210
|
-
if ("rows" in spec) {
|
|
211
|
-
if (!positiveSafeInteger(spec.rows)) throw new TypeError("partition.rows must be a positive safe integer");
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
if ("bytes" in spec) {
|
|
215
|
-
if (!positiveSafeInteger(spec.bytes)) throw new TypeError("partition.bytes must be a positive safe integer");
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
if ("tokens" in spec) {
|
|
219
|
-
if (!positiveSafeInteger(spec.tokens) || typeof spec.of !== "string" || spec.of.length === 0) {
|
|
220
|
-
throw new TypeError("partition.tokens must be positive and partition.of must be a non-empty field");
|
|
221
|
-
}
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
if ("key" in spec) {
|
|
225
|
-
if (typeof spec.key !== "string" || spec.key.length === 0 || !positiveSafeInteger(spec.buckets)) {
|
|
226
|
-
throw new TypeError("partition.key requires a non-empty field and 1..1024 buckets");
|
|
227
|
-
}
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
throw new TypeError("unsupported partition spec");
|
|
231
|
-
}
|
|
232
|
-
function validateBatchSpec(spec) {
|
|
233
|
-
validatePartitionSpec(spec);
|
|
234
|
-
if (!("rows" in spec) && !("tokens" in spec)) throw new TypeError("batch spec must use rows or tokens");
|
|
235
|
-
}
|
|
236
|
-
function field(row, name, purpose) {
|
|
237
|
-
if (!row || typeof row !== "object" || Array.isArray(row) || !Object.hasOwn(row, name)) {
|
|
238
|
-
throw new TypeError(`${purpose} row is missing field ${name}`);
|
|
239
|
-
}
|
|
240
|
-
return row[name];
|
|
241
|
-
}
|
|
242
|
-
function approximateTokens(value) {
|
|
243
|
-
const text2 = typeof value === "string" ? value : canonicalJson(value);
|
|
244
|
-
return Math.max(1, Math.ceil(encoder2.encode(text2).byteLength / 4));
|
|
245
|
-
}
|
|
246
|
-
function cutByWeight(rows, limit2, weight, framing) {
|
|
247
|
-
const partitions = [];
|
|
248
|
-
let current = [];
|
|
249
|
-
let used = framing ? 2 : 0;
|
|
250
|
-
for (const row of rows) {
|
|
251
|
-
const rowWeight = weight(row);
|
|
252
|
-
const added = rowWeight + (framing && current.length > 0 ? 1 : 0);
|
|
253
|
-
if (current.length > 0 && used + added > limit2) {
|
|
254
|
-
partitions.push(current);
|
|
255
|
-
current = [];
|
|
256
|
-
used = framing ? 2 : 0;
|
|
257
|
-
}
|
|
258
|
-
used += rowWeight + (framing && current.length > 0 ? 1 : 0);
|
|
259
|
-
current.push(row);
|
|
260
|
-
}
|
|
261
|
-
if (current.length > 0) partitions.push(current);
|
|
262
|
-
return partitions;
|
|
263
|
-
}
|
|
264
|
-
function cutPartitions(rows, spec) {
|
|
265
|
-
validatePartitionSpec(spec);
|
|
266
|
-
if (rows.length === 0) return [];
|
|
267
|
-
if ("rows" in spec) {
|
|
268
|
-
return Array.from({ length: Math.ceil(rows.length / spec.rows) }, (_, index) => rows.slice(index * spec.rows, (index + 1) * spec.rows));
|
|
269
|
-
}
|
|
270
|
-
if ("bytes" in spec) {
|
|
271
|
-
return cutByWeight(rows, spec.bytes, (row) => encoder2.encode(canonicalJson(row)).byteLength, true);
|
|
272
|
-
}
|
|
273
|
-
if ("tokens" in spec) {
|
|
274
|
-
return cutByWeight(rows, spec.tokens, (row) => approximateTokens(field(row, spec.of, "token partition")), false);
|
|
275
|
-
}
|
|
276
|
-
const partitions = Array.from({ length: spec.buckets }, () => []);
|
|
277
|
-
for (const row of rows) partitions[bucketFor(field(row, spec.key, "key partition"), spec.buckets)].push(row);
|
|
278
|
-
return partitions;
|
|
279
|
-
}
|
|
280
|
-
function cutBatches(rows, spec) {
|
|
281
|
-
validateBatchSpec(spec);
|
|
282
|
-
return cutPartitions(rows, spec);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
// packages/sdk/src/analytics.ts
|
|
286
|
-
var EVENT_ID = /^[a-z][a-z0-9]*(?:[.-][a-z0-9]+)*$/u;
|
|
287
|
-
var FIELD_ID = /^[a-z][a-z0-9_]{0,63}$/u;
|
|
288
|
-
var VERSION = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/u;
|
|
289
|
-
var RESERVED = /* @__PURE__ */ new Set(["system", "platform", "constal", "billing", "security", "audit"]);
|
|
290
|
-
function analyticsEvent(definition) {
|
|
291
|
-
if (typeof definition.id !== "string" || definition.id.length > 128 || !EVENT_ID.test(definition.id)) throw new TypeError("analytics event id is invalid");
|
|
292
|
-
if (RESERVED.has(definition.id.split(/[.-]/u)[0])) throw new TypeError("analytics event id uses a reserved namespace");
|
|
293
|
-
if (typeof definition.version !== "string" || !VERSION.test(definition.version)) throw new TypeError("analytics event version is invalid");
|
|
294
|
-
for (const [kind, fields] of [["dimensions", definition.dimensions], ["metrics", definition.metrics]]) {
|
|
295
|
-
if (!Array.isArray(fields) || fields.some((field2) => typeof field2 !== "string" || !FIELD_ID.test(field2))) throw new TypeError(`analytics event ${kind} are invalid`);
|
|
296
|
-
if (new Set(fields).size !== fields.length) throw new TypeError(`analytics event ${kind} must be unique`);
|
|
297
|
-
}
|
|
298
|
-
const metricNames = new Set(definition.metrics);
|
|
299
|
-
if (definition.dimensions.some((field2) => metricNames.has(field2))) throw new TypeError("analytics dimension and metric names must not overlap");
|
|
300
|
-
return Object.freeze({ ...definition, dimensions: Object.freeze([...definition.dimensions]), metrics: Object.freeze([...definition.metrics]) });
|
|
301
|
-
}
|
|
302
|
-
|
|
303
139
|
// packages/sdk/src/schema.ts
|
|
304
140
|
var KEYWORDS = /* @__PURE__ */ new Set([
|
|
305
141
|
"$schema",
|
|
@@ -376,69 +212,501 @@ function validateJsonSchemaDefinition(schema, path = "$schema", depth = 0) {
|
|
|
376
212
|
if (error) return error;
|
|
377
213
|
}
|
|
378
214
|
}
|
|
379
|
-
if (rule.additionalProperties !== void 0 && typeof rule.additionalProperties !== "boolean") {
|
|
380
|
-
const error = validateJsonSchemaDefinition(rule.additionalProperties, `${path}.additionalProperties`, depth + 1);
|
|
381
|
-
if (error) return error;
|
|
382
|
-
}
|
|
383
|
-
if (rule.uniqueItems !== void 0 && typeof rule.uniqueItems !== "boolean") return `${path}.uniqueItems is invalid`;
|
|
384
|
-
return null;
|
|
215
|
+
if (rule.additionalProperties !== void 0 && typeof rule.additionalProperties !== "boolean") {
|
|
216
|
+
const error = validateJsonSchemaDefinition(rule.additionalProperties, `${path}.additionalProperties`, depth + 1);
|
|
217
|
+
if (error) return error;
|
|
218
|
+
}
|
|
219
|
+
if (rule.uniqueItems !== void 0 && typeof rule.uniqueItems !== "boolean") return `${path}.uniqueItems is invalid`;
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
function validateJsonSchema(value, schema, path = "$") {
|
|
223
|
+
if (schema === true) return null;
|
|
224
|
+
if (schema === false) return `${path} is rejected by the schema`;
|
|
225
|
+
if (!schema || typeof schema !== "object" || Array.isArray(schema)) return `${path} has an invalid schema`;
|
|
226
|
+
const rule = schema;
|
|
227
|
+
if (Array.isArray(rule.anyOf) && !rule.anyOf.some((child) => validateJsonSchema(value, child, path) === null)) {
|
|
228
|
+
return `${path} does not match any allowed schema`;
|
|
229
|
+
}
|
|
230
|
+
const types = typeof rule.type === "string" ? [rule.type] : Array.isArray(rule.type) ? rule.type : [];
|
|
231
|
+
if (types.length && !types.some((type) => type === "object" ? value !== null && typeof value === "object" && !Array.isArray(value) : type === "array" ? Array.isArray(value) : type === "null" ? value === null : type === "integer" ? typeof value === "number" && Number.isInteger(value) : typeof value === type)) return `${path} must be ${types.join(" or ")}`;
|
|
232
|
+
if (Array.isArray(rule.enum) && !rule.enum.some((candidate) => canonicalJson(candidate) === canonicalJson(value))) return `${path} is not allowed`;
|
|
233
|
+
if (Object.hasOwn(rule, "const") && canonicalJson(rule.const) !== canonicalJson(value)) return `${path} does not equal the required value`;
|
|
234
|
+
if (typeof value === "string") {
|
|
235
|
+
if (typeof rule.minLength === "number" && value.length < rule.minLength) return `${path} is too short`;
|
|
236
|
+
if (typeof rule.maxLength === "number" && value.length > rule.maxLength) return `${path} is too long`;
|
|
237
|
+
if (typeof rule.pattern === "string" && !new RegExp(rule.pattern, "u").test(value)) return `${path} does not match the required pattern`;
|
|
238
|
+
}
|
|
239
|
+
if (typeof value === "number") {
|
|
240
|
+
if (typeof rule.minimum === "number" && value < rule.minimum) return `${path} is below minimum`;
|
|
241
|
+
if (typeof rule.maximum === "number" && value > rule.maximum) return `${path} is above maximum`;
|
|
242
|
+
if (typeof rule.exclusiveMinimum === "number" && value <= rule.exclusiveMinimum) return `${path} is below exclusive minimum`;
|
|
243
|
+
if (typeof rule.exclusiveMaximum === "number" && value >= rule.exclusiveMaximum) return `${path} is above exclusive maximum`;
|
|
244
|
+
if (typeof rule.multipleOf === "number" && Math.abs(value / rule.multipleOf - Math.round(value / rule.multipleOf)) > Number.EPSILON * 8) return `${path} is not a multiple`;
|
|
245
|
+
}
|
|
246
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
247
|
+
const record14 = value;
|
|
248
|
+
for (const key of Array.isArray(rule.required) ? rule.required : []) if (typeof key === "string" && !(key in record14)) return `${path}.${key} is required`;
|
|
249
|
+
const properties = rule.properties && typeof rule.properties === "object" && !Array.isArray(rule.properties) ? rule.properties : {};
|
|
250
|
+
if (typeof rule.minProperties === "number" && Object.keys(record14).length < rule.minProperties) return `${path} has too few properties`;
|
|
251
|
+
if (typeof rule.maxProperties === "number" && Object.keys(record14).length > rule.maxProperties) return `${path} has too many properties`;
|
|
252
|
+
if (rule.additionalProperties === false) {
|
|
253
|
+
const extra = Object.keys(record14).find((key) => !(key in properties));
|
|
254
|
+
if (extra) return `${path}.${extra} is not allowed`;
|
|
255
|
+
}
|
|
256
|
+
for (const [key, child] of Object.entries(properties)) if (key in record14) {
|
|
257
|
+
const error = validateJsonSchema(record14[key], child, `${path}.${key}`);
|
|
258
|
+
if (error) return error;
|
|
259
|
+
}
|
|
260
|
+
if (rule.additionalProperties && typeof rule.additionalProperties === "object") for (const key of Object.keys(record14).filter((candidate) => !(candidate in properties))) {
|
|
261
|
+
const error = validateJsonSchema(record14[key], rule.additionalProperties, `${path}.${key}`);
|
|
262
|
+
if (error) return error;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
if (Array.isArray(value)) {
|
|
266
|
+
if (typeof rule.minItems === "number" && value.length < rule.minItems) return `${path} has too few items`;
|
|
267
|
+
if (typeof rule.maxItems === "number" && value.length > rule.maxItems) return `${path} has too many items`;
|
|
268
|
+
if (rule.items) for (const [index, item] of value.entries()) {
|
|
269
|
+
const error = validateJsonSchema(item, rule.items, `${path}[${index}]`);
|
|
270
|
+
if (error) return error;
|
|
271
|
+
}
|
|
272
|
+
if (rule.uniqueItems === true) {
|
|
273
|
+
const values = value.map(canonicalJson);
|
|
274
|
+
if (new Set(values).size !== values.length) return `${path} must contain unique items`;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// packages/sdk/src/table.ts
|
|
281
|
+
var identifier = { type: "string", pattern: "^[a-zA-Z_][a-zA-Z0-9_.-]{0,127}$", maxLength: 128 };
|
|
282
|
+
var tableName = { type: "string", pattern: "^[a-z0-9][a-z0-9._-]{0,127}$", maxLength: 128 };
|
|
283
|
+
var branchName = { type: "string", pattern: "^[a-z0-9][a-z0-9._/-]{0,127}$", maxLength: 128 };
|
|
284
|
+
var hash2 = { type: "string", pattern: "^[a-f0-9]{64}$" };
|
|
285
|
+
var scalar = { type: ["string", "number", "integer", "boolean", "null"] };
|
|
286
|
+
var TABLE_DESCRIBE_SCHEMA = {
|
|
287
|
+
type: "object",
|
|
288
|
+
required: ["table"],
|
|
289
|
+
additionalProperties: false,
|
|
290
|
+
properties: {
|
|
291
|
+
table: tableName,
|
|
292
|
+
branch: branchName,
|
|
293
|
+
snapshot: hash2,
|
|
294
|
+
stageId: hash2,
|
|
295
|
+
waitMs: { type: "integer", minimum: 0 }
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
var filterSchema = {
|
|
299
|
+
type: "object",
|
|
300
|
+
required: ["field", "op", "value"],
|
|
301
|
+
additionalProperties: false,
|
|
302
|
+
properties: {
|
|
303
|
+
field: identifier,
|
|
304
|
+
op: { type: "string", enum: ["eq", "ne", "gt", "gte", "lt", "lte", "in", "between"] },
|
|
305
|
+
value: { anyOf: [scalar, { type: "array", minItems: 1, items: scalar }] }
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
var TABLE_QUERY_SCHEMA = {
|
|
309
|
+
type: "object",
|
|
310
|
+
required: ["table", "snapshot", "query"],
|
|
311
|
+
additionalProperties: false,
|
|
312
|
+
properties: {
|
|
313
|
+
table: tableName,
|
|
314
|
+
branch: branchName,
|
|
315
|
+
snapshot: hash2,
|
|
316
|
+
query: {
|
|
317
|
+
type: "object",
|
|
318
|
+
additionalProperties: false,
|
|
319
|
+
properties: {
|
|
320
|
+
select: { type: "array", uniqueItems: true, items: identifier },
|
|
321
|
+
where: { type: "array", items: filterSchema },
|
|
322
|
+
groupBy: { type: "array", uniqueItems: true, items: identifier },
|
|
323
|
+
aggregates: { type: "array", items: {
|
|
324
|
+
type: "object",
|
|
325
|
+
required: ["fn", "as"],
|
|
326
|
+
additionalProperties: false,
|
|
327
|
+
properties: {
|
|
328
|
+
fn: { type: "string", enum: ["count", "sum", "avg", "min", "max"] },
|
|
329
|
+
field: identifier,
|
|
330
|
+
as: identifier
|
|
331
|
+
}
|
|
332
|
+
} },
|
|
333
|
+
orderBy: { type: "array", items: {
|
|
334
|
+
type: "object",
|
|
335
|
+
required: ["field", "direction"],
|
|
336
|
+
additionalProperties: false,
|
|
337
|
+
properties: { field: identifier, direction: { type: "string", enum: ["asc", "desc"] } }
|
|
338
|
+
} },
|
|
339
|
+
limit: { type: "integer", minimum: 1 }
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
function validateStageOutputSpec(value, path = "$.output") {
|
|
345
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return `${path} must be an object`;
|
|
346
|
+
const output = value;
|
|
347
|
+
const extra = Object.keys(output).find((key) => key !== "schema" && key !== "sortOrder");
|
|
348
|
+
if (extra) return `${path}.${extra} is not allowed`;
|
|
349
|
+
if (!Object.hasOwn(output, "schema")) return `${path}.schema is required`;
|
|
350
|
+
const schemaError = validateJsonSchemaDefinition(output.schema, `${path}.schema`);
|
|
351
|
+
if (schemaError) return schemaError;
|
|
352
|
+
const sortOrder = output.sortOrder ?? [];
|
|
353
|
+
if (!Array.isArray(sortOrder)) return `${path}.sortOrder is invalid`;
|
|
354
|
+
const keys = /* @__PURE__ */ new Set();
|
|
355
|
+
for (const [index, raw] of sortOrder.entries()) {
|
|
356
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return `${path}.sortOrder[${index}] is invalid`;
|
|
357
|
+
const field2 = raw;
|
|
358
|
+
if (Object.keys(field2).some((key) => key !== "key" && key !== "direction") || typeof field2.key !== "string" || !/^[a-zA-Z_][a-zA-Z0-9_.-]{0,127}$/u.test(field2.key) || field2.direction !== "asc" && field2.direction !== "desc" || keys.has(field2.key)) {
|
|
359
|
+
return `${path}.sortOrder[${index}] is invalid`;
|
|
360
|
+
}
|
|
361
|
+
keys.add(field2.key);
|
|
362
|
+
}
|
|
363
|
+
return null;
|
|
364
|
+
}
|
|
365
|
+
function stageOutput(value) {
|
|
366
|
+
const error = validateStageOutputSpec(value);
|
|
367
|
+
if (error) throw new TypeError(error);
|
|
368
|
+
return value;
|
|
369
|
+
}
|
|
370
|
+
var tableDescribe = {
|
|
371
|
+
name: "table_describe",
|
|
372
|
+
version: "1",
|
|
373
|
+
description: "Inspect the schema and identity of one exact, queryable Table snapshot before querying it.",
|
|
374
|
+
schema: TABLE_DESCRIBE_SCHEMA,
|
|
375
|
+
maxEffect: "read-only",
|
|
376
|
+
needs: [{ binding: "table_catalog", kind: "service", ops: ["describe"] }],
|
|
377
|
+
async run(args, ctx) {
|
|
378
|
+
return ctx.invoke(ctx.resources.table_catalog, "describe", args);
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
var tableQuery = {
|
|
382
|
+
name: "table_query",
|
|
383
|
+
version: "1",
|
|
384
|
+
description: "Query one exact Table snapshot with bounded fields, filters, grouping, aggregates, ordering, and limit.",
|
|
385
|
+
schema: TABLE_QUERY_SCHEMA,
|
|
386
|
+
maxEffect: "read-only",
|
|
387
|
+
needs: [{ binding: "table_catalog", kind: "service", ops: ["query"] }],
|
|
388
|
+
async run(args, ctx) {
|
|
389
|
+
return ctx.invoke(ctx.resources.table_catalog, "query", args);
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
// packages/sdk/src/tools.ts
|
|
394
|
+
var NAME = /^[a-z0-9][a-z0-9._-]{0,127}$/u;
|
|
395
|
+
var OPERATION = /^[A-Za-z][A-Za-z0-9._-]{0,127}$/u;
|
|
396
|
+
function opTool(binding, op, override = {}) {
|
|
397
|
+
if (!NAME.test(binding) || !OPERATION.test(op)) throw new TypeError("opTool binding or operation is invalid");
|
|
398
|
+
const name = override.name ?? op.replaceAll(".", "_");
|
|
399
|
+
return {
|
|
400
|
+
name,
|
|
401
|
+
...override.title ? { title: override.title } : {},
|
|
402
|
+
version: "catalog",
|
|
403
|
+
description: override.description ?? `Invoke ${op} on the bound ${binding} resource.`,
|
|
404
|
+
schema: override.schema ?? { type: "object", additionalProperties: false },
|
|
405
|
+
maxEffect: "read-only",
|
|
406
|
+
needs: [],
|
|
407
|
+
...override.tier ? { tier: override.tier } : {},
|
|
408
|
+
...override.once ? { once: override.once } : {},
|
|
409
|
+
...override.guard ? { guard: override.guard } : {},
|
|
410
|
+
...override.preview ? { preview: override.preview } : {},
|
|
411
|
+
catalog: { binding, op },
|
|
412
|
+
async run() {
|
|
413
|
+
throw new TypeError(`catalog Tool ${binding}#${op} was not resolved by deployment`);
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
function opTools(binding, ops = []) {
|
|
418
|
+
if (ops.length === 0) throw new TypeError("opTools requires pinned operation names at bundle construction");
|
|
419
|
+
return ops.map((op) => opTool(binding, op));
|
|
420
|
+
}
|
|
421
|
+
async function boundResource(ctx, binding) {
|
|
422
|
+
const resource = await ctx.describeResource(binding);
|
|
423
|
+
if (!resource) throw new TypeError(`Resource is not bound: ${binding}`);
|
|
424
|
+
return resource;
|
|
425
|
+
}
|
|
426
|
+
var resourceTools = {
|
|
427
|
+
resource_list: {
|
|
428
|
+
name: "resource_list",
|
|
429
|
+
version: "1",
|
|
430
|
+
maxEffect: "read-only",
|
|
431
|
+
needs: [],
|
|
432
|
+
description: "List the Resource bindings accepted by this Run. Inspect a binding with resource_describe to read its public operations.",
|
|
433
|
+
schema: { type: "object", properties: {}, additionalProperties: false },
|
|
434
|
+
run: (_args, ctx) => ctx.step("bound-resource-list", async () => Object.entries(ctx.resources).sort(([left], [right]) => left.localeCompare(right)).map(([binding, crn]) => ({ binding, crn })))
|
|
435
|
+
},
|
|
436
|
+
resource_describe: {
|
|
437
|
+
name: "resource_describe",
|
|
438
|
+
version: "1",
|
|
439
|
+
maxEffect: "read-only",
|
|
440
|
+
needs: [],
|
|
441
|
+
description: "Read a bound Resource's public operations, input/output schemas, and execution semantics. This does not connect or install it.",
|
|
442
|
+
schema: {
|
|
443
|
+
type: "object",
|
|
444
|
+
required: ["binding"],
|
|
445
|
+
additionalProperties: false,
|
|
446
|
+
properties: { binding: { type: "string", minLength: 1 } }
|
|
447
|
+
},
|
|
448
|
+
run: (args, ctx) => boundResource(ctx, args.binding)
|
|
449
|
+
},
|
|
450
|
+
resource_invoke: {
|
|
451
|
+
name: "resource_invoke",
|
|
452
|
+
version: "1",
|
|
453
|
+
maxEffect: "non-idempotent",
|
|
454
|
+
needs: [],
|
|
455
|
+
description: "Invoke a public operation on an already-bound Resource using its described input schema. Policy applies to the invocation. This does not install a Resource or add a binding.",
|
|
456
|
+
schema: {
|
|
457
|
+
type: "object",
|
|
458
|
+
required: ["binding", "operation", "arguments"],
|
|
459
|
+
additionalProperties: false,
|
|
460
|
+
properties: { binding: { type: "string", minLength: 1 }, operation: { type: "string", minLength: 1 }, arguments: {} }
|
|
461
|
+
},
|
|
462
|
+
async run(args, ctx) {
|
|
463
|
+
const resource = await boundResource(ctx, args.binding);
|
|
464
|
+
const operation = resource.operations.find((candidate) => candidate.op === args.operation);
|
|
465
|
+
if (!operation) throw new TypeError(`Resource operation is not available: ${args.binding}#${args.operation}`);
|
|
466
|
+
return operation.async ? ctx.invokeAsync(resource.crn, operation.op, args.arguments) : ctx.invoke(resource.crn, operation.op, args.arguments);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
var WEB_FETCH_ARGUMENT_SCHEMA = {
|
|
471
|
+
type: "object",
|
|
472
|
+
required: ["url"],
|
|
473
|
+
additionalProperties: false,
|
|
474
|
+
properties: {
|
|
475
|
+
url: { type: "string", minLength: 1 },
|
|
476
|
+
accept: { type: "string" }
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
var WEB_SEARCH_ARGUMENT_SCHEMA = {
|
|
480
|
+
type: "object",
|
|
481
|
+
required: ["query"],
|
|
482
|
+
additionalProperties: false,
|
|
483
|
+
properties: {
|
|
484
|
+
query: {
|
|
485
|
+
type: "string",
|
|
486
|
+
minLength: 1,
|
|
487
|
+
description: "A self-contained description of the information to find."
|
|
488
|
+
},
|
|
489
|
+
searchQueries: {
|
|
490
|
+
type: "array",
|
|
491
|
+
minItems: 1,
|
|
492
|
+
uniqueItems: true,
|
|
493
|
+
description: "Optional concise keyword queries that narrow the search.",
|
|
494
|
+
items: { type: "string", minLength: 1 }
|
|
495
|
+
},
|
|
496
|
+
maximumResults: {
|
|
497
|
+
type: "integer",
|
|
498
|
+
minimum: 1,
|
|
499
|
+
description: "Maximum number of sources to return."
|
|
500
|
+
},
|
|
501
|
+
maximumCharacters: {
|
|
502
|
+
type: "integer",
|
|
503
|
+
minimum: 1,
|
|
504
|
+
description: "Maximum total excerpt characters to return."
|
|
505
|
+
},
|
|
506
|
+
includeDomains: {
|
|
507
|
+
type: "array",
|
|
508
|
+
uniqueItems: true,
|
|
509
|
+
description: "Optional domains to restrict results to.",
|
|
510
|
+
items: { type: "string", minLength: 1 }
|
|
511
|
+
},
|
|
512
|
+
excludeDomains: {
|
|
513
|
+
type: "array",
|
|
514
|
+
uniqueItems: true,
|
|
515
|
+
description: "Optional domains to omit.",
|
|
516
|
+
items: { type: "string", minLength: 1 }
|
|
517
|
+
},
|
|
518
|
+
afterDate: {
|
|
519
|
+
type: "string",
|
|
520
|
+
pattern: "^[0-9]{4}-[0-9]{2}-[0-9]{2}$",
|
|
521
|
+
description: "Optional earliest publication date in YYYY-MM-DD form."
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
};
|
|
525
|
+
var webFetch = opTool("web", "get", {
|
|
526
|
+
name: "web_fetch",
|
|
527
|
+
description: "Fetch an HTTPS resource through the bound governed web Resource.",
|
|
528
|
+
schema: WEB_FETCH_ARGUMENT_SCHEMA
|
|
529
|
+
});
|
|
530
|
+
var webSearch = opTool("search", "search", {
|
|
531
|
+
name: "web_search",
|
|
532
|
+
description: "Search the public web through the bound governed search Resource.",
|
|
533
|
+
schema: WEB_SEARCH_ARGUMENT_SCHEMA
|
|
534
|
+
});
|
|
535
|
+
var casTool = {
|
|
536
|
+
name: "cas",
|
|
537
|
+
version: "1",
|
|
538
|
+
description: "Store or load one content-addressed Agent artifact.",
|
|
539
|
+
schema: {
|
|
540
|
+
type: "object",
|
|
541
|
+
required: ["action"],
|
|
542
|
+
additionalProperties: false,
|
|
543
|
+
properties: {
|
|
544
|
+
action: { type: "string", enum: ["put", "get"] },
|
|
545
|
+
value: {},
|
|
546
|
+
ref: { type: "string", pattern: "^[a-f0-9]{64}$" }
|
|
547
|
+
}
|
|
548
|
+
},
|
|
549
|
+
maxEffect: "idempotent",
|
|
550
|
+
needs: [{ binding: "cas", kind: "cas", ops: ["put", "get"] }],
|
|
551
|
+
async run(args, ctx) {
|
|
552
|
+
const input = args && typeof args === "object" && !Array.isArray(args) ? args : {};
|
|
553
|
+
if (input.action === "put") {
|
|
554
|
+
if (!Object.hasOwn(input, "value")) throw new TypeError("cas put requires value");
|
|
555
|
+
return ctx.invoke(ctx.resources.cas, "put", { value: input.value });
|
|
556
|
+
}
|
|
557
|
+
if (input.action === "get") {
|
|
558
|
+
if (typeof input.ref !== "string") throw new TypeError("cas get requires ref");
|
|
559
|
+
return ctx.invoke(ctx.resources.cas, "get", { ref: input.ref });
|
|
560
|
+
}
|
|
561
|
+
throw new TypeError("cas action must be put or get");
|
|
562
|
+
}
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
// packages/sdk/src/skills.ts
|
|
566
|
+
async function required(workspace, skill, cmd, args, timeoutMs) {
|
|
567
|
+
const result = timeoutMs === void 0 ? await workspace.exec({ cmd, args }) : await workspace.exec({ cmd, args, timeoutMs }, { timeoutMs });
|
|
568
|
+
if (result.status !== "completed" || result.exitCode !== 0) {
|
|
569
|
+
throw new Error(`Copying skill ${skill} into the workspace failed: ${cmd} ended ${result.status} with exit code ${result.exitCode}. ${result.stderrPreview}`);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
function skills(binding = "skills", sandbox = "sandbox") {
|
|
573
|
+
const prefix = binding.replaceAll(/[.-]/gu, "_");
|
|
574
|
+
const find = opTool(binding, "find", { name: `${prefix}_find` });
|
|
575
|
+
const read = opTool(binding, "read", { name: `${prefix}_read` });
|
|
576
|
+
const run = {
|
|
577
|
+
name: `${prefix}_run`,
|
|
578
|
+
version: "1",
|
|
579
|
+
description: "Runs one command in the sandbox workspace with its working directory set to a copy of a skill's folder, which holds the skill's SKILL.md and every file it bundles. Returns the folder's path and the command's result: its status, exit code and output.",
|
|
580
|
+
schema: { type: "object", required: ["skill", "cmd"], additionalProperties: false, properties: {
|
|
581
|
+
skill: { type: "string", minLength: 1, description: "The skill's name." },
|
|
582
|
+
cmd: { type: "string", minLength: 1, description: "The program to run." },
|
|
583
|
+
args: { type: "array", items: { type: "string" }, description: "The program's arguments." },
|
|
584
|
+
env: { type: "object", additionalProperties: { type: "string" }, description: "Environment variables for the command." },
|
|
585
|
+
stdin: { type: "string", description: "Text the command reads on its standard input." },
|
|
586
|
+
timeoutMs: { type: "integer", minimum: 1, description: "How long each command may run, in milliseconds: the program, and each command that copies the skill's folder into the workspace." }
|
|
587
|
+
} },
|
|
588
|
+
maxEffect: "reconcilable",
|
|
589
|
+
needs: [{ binding, kind: "skills", ops: ["bundle"] }, { binding: sandbox, kind: "sandbox-pool", ops: ["exec", "putFile"] }],
|
|
590
|
+
async run(args, ctx) {
|
|
591
|
+
const { ref } = await ctx.invoke(ctx.resources[binding], "bundle", { skill: args.skill });
|
|
592
|
+
const workspace = ctx.sandboxPool(ctx.resources[sandbox]).workspace();
|
|
593
|
+
const path = `/workspace/skills/${ref}`;
|
|
594
|
+
const bound = args.timeoutMs === void 0 ? void 0 : { timeoutMs: args.timeoutMs };
|
|
595
|
+
const present = await workspace.exec({ cmd: "test", args: ["-e", path], ...bound }, bound);
|
|
596
|
+
if (present.status !== "completed" || present.exitCode !== 0) {
|
|
597
|
+
const archive = `/workspace/.constal/imports/${ref}.tar.gz`;
|
|
598
|
+
const staging = `/workspace/.constal/staging/${ref}`;
|
|
599
|
+
await required(workspace, args.skill, "mkdir", ["-p", "--", "/workspace/.constal/imports", staging, "/workspace/skills"], args.timeoutMs);
|
|
600
|
+
await workspace.putFile(archive, ref, bound && { invoke: bound });
|
|
601
|
+
await required(workspace, args.skill, "tar", ["-xzf", archive, "-C", staging, "--no-same-owner", "--no-same-permissions"], args.timeoutMs);
|
|
602
|
+
await required(workspace, args.skill, "mv", ["--", staging, path], args.timeoutMs);
|
|
603
|
+
await required(workspace, args.skill, "rm", ["-f", "--", archive], args.timeoutMs);
|
|
604
|
+
}
|
|
605
|
+
const { skill: _skill, ...command } = args;
|
|
606
|
+
return { path, ...await workspace.exec({ ...command, cwd: path }, bound) };
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
return { [find.name]: find, [read.name]: read, [run.name]: run };
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
// packages/sdk/src/partition.ts
|
|
613
|
+
var encoder2 = new TextEncoder();
|
|
614
|
+
function positiveSafeInteger(value) {
|
|
615
|
+
return Number.isSafeInteger(value) && Number(value) > 0;
|
|
616
|
+
}
|
|
617
|
+
function validatePartitionSpec(spec) {
|
|
618
|
+
if (!spec || typeof spec !== "object") throw new TypeError("partition spec must be an object");
|
|
619
|
+
if ("rows" in spec) {
|
|
620
|
+
if (!positiveSafeInteger(spec.rows)) throw new TypeError("partition.rows must be a positive safe integer");
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
if ("bytes" in spec) {
|
|
624
|
+
if (!positiveSafeInteger(spec.bytes)) throw new TypeError("partition.bytes must be a positive safe integer");
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
if ("tokens" in spec) {
|
|
628
|
+
if (!positiveSafeInteger(spec.tokens) || typeof spec.of !== "string" || spec.of.length === 0) {
|
|
629
|
+
throw new TypeError("partition.tokens must be positive and partition.of must be a non-empty field");
|
|
630
|
+
}
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
if ("key" in spec) {
|
|
634
|
+
if (typeof spec.key !== "string" || spec.key.length === 0 || !positiveSafeInteger(spec.buckets)) {
|
|
635
|
+
throw new TypeError("partition.key requires a non-empty field and 1..1024 buckets");
|
|
636
|
+
}
|
|
637
|
+
return;
|
|
638
|
+
}
|
|
639
|
+
throw new TypeError("unsupported partition spec");
|
|
640
|
+
}
|
|
641
|
+
function validateBatchSpec(spec) {
|
|
642
|
+
validatePartitionSpec(spec);
|
|
643
|
+
if (!("rows" in spec) && !("tokens" in spec)) throw new TypeError("batch spec must use rows or tokens");
|
|
644
|
+
}
|
|
645
|
+
function field(row, name, purpose) {
|
|
646
|
+
if (!row || typeof row !== "object" || Array.isArray(row) || !Object.hasOwn(row, name)) {
|
|
647
|
+
throw new TypeError(`${purpose} row is missing field ${name}`);
|
|
648
|
+
}
|
|
649
|
+
return row[name];
|
|
650
|
+
}
|
|
651
|
+
function approximateTokens(value) {
|
|
652
|
+
const text2 = typeof value === "string" ? value : canonicalJson(value);
|
|
653
|
+
return Math.max(1, Math.ceil(encoder2.encode(text2).byteLength / 4));
|
|
654
|
+
}
|
|
655
|
+
function cutByWeight(rows, limit2, weight, framing) {
|
|
656
|
+
const partitions = [];
|
|
657
|
+
let current = [];
|
|
658
|
+
let used = framing ? 2 : 0;
|
|
659
|
+
for (const row of rows) {
|
|
660
|
+
const rowWeight = weight(row);
|
|
661
|
+
const added = rowWeight + (framing && current.length > 0 ? 1 : 0);
|
|
662
|
+
if (current.length > 0 && used + added > limit2) {
|
|
663
|
+
partitions.push(current);
|
|
664
|
+
current = [];
|
|
665
|
+
used = framing ? 2 : 0;
|
|
666
|
+
}
|
|
667
|
+
used += rowWeight + (framing && current.length > 0 ? 1 : 0);
|
|
668
|
+
current.push(row);
|
|
669
|
+
}
|
|
670
|
+
if (current.length > 0) partitions.push(current);
|
|
671
|
+
return partitions;
|
|
385
672
|
}
|
|
386
|
-
function
|
|
387
|
-
|
|
388
|
-
if (
|
|
389
|
-
if (
|
|
390
|
-
|
|
391
|
-
if (Array.isArray(rule.anyOf) && !rule.anyOf.some((child) => validateJsonSchema(value, child, path) === null)) {
|
|
392
|
-
return `${path} does not match any allowed schema`;
|
|
393
|
-
}
|
|
394
|
-
const types = typeof rule.type === "string" ? [rule.type] : Array.isArray(rule.type) ? rule.type : [];
|
|
395
|
-
if (types.length && !types.some((type) => type === "object" ? value !== null && typeof value === "object" && !Array.isArray(value) : type === "array" ? Array.isArray(value) : type === "null" ? value === null : type === "integer" ? typeof value === "number" && Number.isInteger(value) : typeof value === type)) return `${path} must be ${types.join(" or ")}`;
|
|
396
|
-
if (Array.isArray(rule.enum) && !rule.enum.some((candidate) => canonicalJson(candidate) === canonicalJson(value))) return `${path} is not allowed`;
|
|
397
|
-
if (Object.hasOwn(rule, "const") && canonicalJson(rule.const) !== canonicalJson(value)) return `${path} does not equal the required value`;
|
|
398
|
-
if (typeof value === "string") {
|
|
399
|
-
if (typeof rule.minLength === "number" && value.length < rule.minLength) return `${path} is too short`;
|
|
400
|
-
if (typeof rule.maxLength === "number" && value.length > rule.maxLength) return `${path} is too long`;
|
|
401
|
-
if (typeof rule.pattern === "string" && !new RegExp(rule.pattern, "u").test(value)) return `${path} does not match the required pattern`;
|
|
673
|
+
function cutPartitions(rows, spec) {
|
|
674
|
+
validatePartitionSpec(spec);
|
|
675
|
+
if (rows.length === 0) return [];
|
|
676
|
+
if ("rows" in spec) {
|
|
677
|
+
return Array.from({ length: Math.ceil(rows.length / spec.rows) }, (_, index) => rows.slice(index * spec.rows, (index + 1) * spec.rows));
|
|
402
678
|
}
|
|
403
|
-
if (
|
|
404
|
-
|
|
405
|
-
if (typeof rule.maximum === "number" && value > rule.maximum) return `${path} is above maximum`;
|
|
406
|
-
if (typeof rule.exclusiveMinimum === "number" && value <= rule.exclusiveMinimum) return `${path} is below exclusive minimum`;
|
|
407
|
-
if (typeof rule.exclusiveMaximum === "number" && value >= rule.exclusiveMaximum) return `${path} is above exclusive maximum`;
|
|
408
|
-
if (typeof rule.multipleOf === "number" && Math.abs(value / rule.multipleOf - Math.round(value / rule.multipleOf)) > Number.EPSILON * 8) return `${path} is not a multiple`;
|
|
679
|
+
if ("bytes" in spec) {
|
|
680
|
+
return cutByWeight(rows, spec.bytes, (row) => encoder2.encode(canonicalJson(row)).byteLength, true);
|
|
409
681
|
}
|
|
410
|
-
if (
|
|
411
|
-
|
|
412
|
-
for (const key of Array.isArray(rule.required) ? rule.required : []) if (typeof key === "string" && !(key in record14)) return `${path}.${key} is required`;
|
|
413
|
-
const properties = rule.properties && typeof rule.properties === "object" && !Array.isArray(rule.properties) ? rule.properties : {};
|
|
414
|
-
if (typeof rule.minProperties === "number" && Object.keys(record14).length < rule.minProperties) return `${path} has too few properties`;
|
|
415
|
-
if (typeof rule.maxProperties === "number" && Object.keys(record14).length > rule.maxProperties) return `${path} has too many properties`;
|
|
416
|
-
if (rule.additionalProperties === false) {
|
|
417
|
-
const extra = Object.keys(record14).find((key) => !(key in properties));
|
|
418
|
-
if (extra) return `${path}.${extra} is not allowed`;
|
|
419
|
-
}
|
|
420
|
-
for (const [key, child] of Object.entries(properties)) if (key in record14) {
|
|
421
|
-
const error = validateJsonSchema(record14[key], child, `${path}.${key}`);
|
|
422
|
-
if (error) return error;
|
|
423
|
-
}
|
|
424
|
-
if (rule.additionalProperties && typeof rule.additionalProperties === "object") for (const key of Object.keys(record14).filter((candidate) => !(candidate in properties))) {
|
|
425
|
-
const error = validateJsonSchema(record14[key], rule.additionalProperties, `${path}.${key}`);
|
|
426
|
-
if (error) return error;
|
|
427
|
-
}
|
|
682
|
+
if ("tokens" in spec) {
|
|
683
|
+
return cutByWeight(rows, spec.tokens, (row) => approximateTokens(field(row, spec.of, "token partition")), false);
|
|
428
684
|
}
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
685
|
+
const partitions = Array.from({ length: spec.buckets }, () => []);
|
|
686
|
+
for (const row of rows) partitions[bucketFor(field(row, spec.key, "key partition"), spec.buckets)].push(row);
|
|
687
|
+
return partitions;
|
|
688
|
+
}
|
|
689
|
+
function cutBatches(rows, spec) {
|
|
690
|
+
validateBatchSpec(spec);
|
|
691
|
+
return cutPartitions(rows, spec);
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
// packages/sdk/src/analytics.ts
|
|
695
|
+
var EVENT_ID = /^[a-z][a-z0-9]*(?:[.-][a-z0-9]+)*$/u;
|
|
696
|
+
var FIELD_ID = /^[a-z][a-z0-9_]{0,63}$/u;
|
|
697
|
+
var VERSION = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/u;
|
|
698
|
+
var RESERVED = /* @__PURE__ */ new Set(["system", "platform", "constal", "billing", "security", "audit"]);
|
|
699
|
+
function analyticsEvent(definition) {
|
|
700
|
+
if (typeof definition.id !== "string" || definition.id.length > 128 || !EVENT_ID.test(definition.id)) throw new TypeError("analytics event id is invalid");
|
|
701
|
+
if (RESERVED.has(definition.id.split(/[.-]/u)[0])) throw new TypeError("analytics event id uses a reserved namespace");
|
|
702
|
+
if (typeof definition.version !== "string" || !VERSION.test(definition.version)) throw new TypeError("analytics event version is invalid");
|
|
703
|
+
for (const [kind, fields] of [["dimensions", definition.dimensions], ["metrics", definition.metrics]]) {
|
|
704
|
+
if (!Array.isArray(fields) || fields.some((field2) => typeof field2 !== "string" || !FIELD_ID.test(field2))) throw new TypeError(`analytics event ${kind} are invalid`);
|
|
705
|
+
if (new Set(fields).size !== fields.length) throw new TypeError(`analytics event ${kind} must be unique`);
|
|
440
706
|
}
|
|
441
|
-
|
|
707
|
+
const metricNames = new Set(definition.metrics);
|
|
708
|
+
if (definition.dimensions.some((field2) => metricNames.has(field2))) throw new TypeError("analytics dimension and metric names must not overlap");
|
|
709
|
+
return Object.freeze({ ...definition, dimensions: Object.freeze([...definition.dimensions]), metrics: Object.freeze([...definition.metrics]) });
|
|
442
710
|
}
|
|
443
711
|
|
|
444
712
|
// packages/sdk/src/selector.ts
|
|
@@ -450,7 +718,7 @@ var RESOURCE_IDENTITY_LABELS = {
|
|
|
450
718
|
kind: "constal.ai/kind",
|
|
451
719
|
version: "constal.ai/version"
|
|
452
720
|
};
|
|
453
|
-
var
|
|
721
|
+
var NAME2 = /^[A-Za-z0-9](?:[-_.A-Za-z0-9]{0,61}[A-Za-z0-9])?$/u;
|
|
454
722
|
var DNS_LABEL = /^[a-z0-9](?:[-a-z0-9]{0,61}[a-z0-9])?$/u;
|
|
455
723
|
function record(value) {
|
|
456
724
|
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
@@ -458,14 +726,14 @@ function record(value) {
|
|
|
458
726
|
function labelKey(value) {
|
|
459
727
|
if (typeof value !== "string" || value.length > 317) return false;
|
|
460
728
|
const slash = value.indexOf("/");
|
|
461
|
-
if (slash < 0) return
|
|
729
|
+
if (slash < 0) return NAME2.test(value);
|
|
462
730
|
if (slash === 0 || slash !== value.lastIndexOf("/")) return false;
|
|
463
731
|
const prefix = value.slice(0, slash);
|
|
464
732
|
const name = value.slice(slash + 1);
|
|
465
|
-
return prefix.length <= 253 &&
|
|
733
|
+
return prefix.length <= 253 && NAME2.test(name) && prefix.split(".").every((part) => DNS_LABEL.test(part));
|
|
466
734
|
}
|
|
467
735
|
function labelValue(value) {
|
|
468
|
-
return typeof value === "string" && (value === "" ||
|
|
736
|
+
return typeof value === "string" && (value === "" || NAME2.test(value));
|
|
469
737
|
}
|
|
470
738
|
function selectorValue(key, value) {
|
|
471
739
|
return key.startsWith(PROTECTED_RESOURCE_LABEL_PREFIX) ? typeof value === "string" && value.length > 0 && value.length <= 1024 : labelValue(value);
|
|
@@ -569,6 +837,7 @@ var RESOURCE_KINDS = [
|
|
|
569
837
|
"browser",
|
|
570
838
|
"sandbox-pool",
|
|
571
839
|
"vault",
|
|
840
|
+
"skills",
|
|
572
841
|
"system"
|
|
573
842
|
];
|
|
574
843
|
var PLATFORM_ADDRESS_KINDS = [
|
|
@@ -584,9 +853,9 @@ var PLATFORM_ADDRESS_KINDS = [
|
|
|
584
853
|
"artifact",
|
|
585
854
|
"deployment"
|
|
586
855
|
];
|
|
587
|
-
var INVOKABLE_KINDS = ["model", "memory", "cas", "web", "service", "mcp", "db", "browser", "sandbox-pool", "vault"];
|
|
856
|
+
var INVOKABLE_KINDS = ["model", "memory", "cas", "web", "service", "mcp", "db", "browser", "sandbox-pool", "vault", "skills"];
|
|
588
857
|
var POLICY_TARGET_KINDS = [...RESOURCE_KINDS, ...PLATFORM_ADDRESS_KINDS];
|
|
589
|
-
function resolveBindingOwner(scope2, context,
|
|
858
|
+
function resolveBindingOwner(scope2, context, required3 = true) {
|
|
590
859
|
bindingOwnerScope(scope2);
|
|
591
860
|
if (!SEGMENT.test(context.environment) || !SEGMENT.test(context.tenant)) throw new TypeError("Binding owner context is invalid");
|
|
592
861
|
for (const kind of ["principal", "customer"]) {
|
|
@@ -599,7 +868,7 @@ function resolveBindingOwner(scope2, context, required2 = true) {
|
|
|
599
868
|
if (scope2 === "tenant") return { kind: "tenant", tenant: context.tenant };
|
|
600
869
|
const name = scope2 === "principal" ? context.principal : context.customer;
|
|
601
870
|
if (!name) {
|
|
602
|
-
if (!
|
|
871
|
+
if (!required3) return null;
|
|
603
872
|
throw new TypeError(`A ${scope2} is required for this binding`);
|
|
604
873
|
}
|
|
605
874
|
const parts = parseResourceName(name);
|
|
@@ -612,13 +881,13 @@ function agentSetupRequirements(value, options = {}) {
|
|
|
612
881
|
if (!Array.isArray(value) || value.length < 1) throw new TypeError("Agent setup requirements are invalid");
|
|
613
882
|
const requirements = value.map((raw) => {
|
|
614
883
|
const item = record2(raw);
|
|
615
|
-
if (!item || typeof item.id !== "string" || !
|
|
884
|
+
if (!item || typeof item.id !== "string" || !NAME3.test(item.id) || typeof item.title !== "string" || !item.title.trim() || item.description !== void 0 && typeof item.description !== "string" || item.optional !== void 0 && typeof item.optional !== "boolean" || Object.keys(item).some((key) => !["id", "title", "description", "optional", "resourceKind", "selector", "binding"].includes(key))) {
|
|
616
885
|
throw new TypeError("Agent setup requirement is invalid");
|
|
617
886
|
}
|
|
618
887
|
const selection = resourceSelector({ resourceKind: item.resourceKind, selector: item.selector === void 0 ? {} : item.selector }, RESOURCE_KINDS);
|
|
619
888
|
if (item.resourceKind === "credential") {
|
|
620
889
|
const binding = record2(item.binding);
|
|
621
|
-
if (!binding || typeof binding.key !== "string" || !
|
|
890
|
+
if (!binding || typeof binding.key !== "string" || !NAME3.test(binding.key) || Object.keys(binding).some((key) => key !== "key" && key !== "owner")) {
|
|
622
891
|
throw new TypeError("Credential setup requires one binding key and an explicit owner scope");
|
|
623
892
|
}
|
|
624
893
|
const owner = binding.owner === void 0 && options.allowLegacyTenantOwner ? "tenant" : binding.owner;
|
|
@@ -639,7 +908,7 @@ function agentSetupMetadata(value, options = {}) {
|
|
|
639
908
|
if (source && Object.keys(source).length === 1 && source.requirements !== void 0) {
|
|
640
909
|
return { requirements: agentSetupRequirements(source.requirements, options) };
|
|
641
910
|
}
|
|
642
|
-
if (!source || source.protocol !== "constal.setup.v1" || typeof source.agent !== "string" || !
|
|
911
|
+
if (!source || source.protocol !== "constal.setup.v1" || typeof source.agent !== "string" || !NAME3.test(source.agent) || typeof source.session !== "string" || !source.session || source.session.length > 256 || !record2(source.input) || Object.keys(source).some((key) => !["protocol", "agent", "session", "input"].includes(key))) {
|
|
643
912
|
throw new TypeError("Agent setup metadata is invalid");
|
|
644
913
|
}
|
|
645
914
|
return source;
|
|
@@ -763,8 +1032,8 @@ var UI_RESOURCE_BOUNDS = Object.freeze({
|
|
|
763
1032
|
var ACTION_PATTERN = /^[a-z][a-z0-9-]{0,63}:[a-z][a-z0-9-]{0,63}$/u;
|
|
764
1033
|
var SEGMENT = /^[a-z0-9][a-z0-9._-]{0,127}$/u;
|
|
765
1034
|
var PATH = /^[A-Za-z0-9._~/%-]{1,512}$/u;
|
|
766
|
-
var
|
|
767
|
-
var
|
|
1035
|
+
var NAME3 = /^[a-z0-9][a-z0-9._-]{0,127}$/u;
|
|
1036
|
+
var OPERATION2 = /^[A-Za-z][A-Za-z0-9._-]{0,127}$/u;
|
|
768
1037
|
var VERSION2 = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/u;
|
|
769
1038
|
var HASH = /^[a-f0-9]{64}$/u;
|
|
770
1039
|
var KINDS = /* @__PURE__ */ new Set([...RESOURCE_KINDS, ...PLATFORM_ADDRESS_KINDS]);
|
|
@@ -779,7 +1048,7 @@ var RESOURCE_CREDENTIAL_BINDING_SCHEMA = {
|
|
|
779
1048
|
additionalProperties: false,
|
|
780
1049
|
properties: {
|
|
781
1050
|
kind: { const: "scoped" },
|
|
782
|
-
key: { type: "string", pattern:
|
|
1051
|
+
key: { type: "string", pattern: NAME3.source },
|
|
783
1052
|
owner: { enum: ["tenant", "customer", "principal"] },
|
|
784
1053
|
required: { type: "boolean" }
|
|
785
1054
|
}
|
|
@@ -790,17 +1059,17 @@ function record2(value) {
|
|
|
790
1059
|
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
791
1060
|
}
|
|
792
1061
|
function scopedBindingKey(value) {
|
|
793
|
-
if (typeof value !== "string" || !
|
|
1062
|
+
if (typeof value !== "string" || !NAME3.test(value)) throw new TypeError("scoped binding key is invalid");
|
|
794
1063
|
return value;
|
|
795
1064
|
}
|
|
796
1065
|
function resourceContractRef(value) {
|
|
797
1066
|
const candidate = record2(value);
|
|
798
|
-
if (!candidate || typeof candidate.id !== "string" || !
|
|
1067
|
+
if (!candidate || typeof candidate.id !== "string" || !NAME3.test(candidate.id) || typeof candidate.version !== "string" || !VERSION2.test(candidate.version) || typeof candidate.hash !== "string" || !HASH.test(candidate.hash)) throw new TypeError("Resource contract reference is invalid");
|
|
799
1068
|
return candidate;
|
|
800
1069
|
}
|
|
801
1070
|
function capabilityContractRef(value) {
|
|
802
1071
|
const candidate = record2(value);
|
|
803
|
-
if (!candidate || typeof candidate.id !== "string" || !
|
|
1072
|
+
if (!candidate || typeof candidate.id !== "string" || !NAME3.test(candidate.id) || typeof candidate.version !== "string" || !VERSION2.test(candidate.version) || typeof candidate.hash !== "string" || !HASH.test(candidate.hash) || Object.keys(candidate).some((key) => !["id", "version", "hash"].includes(key))) {
|
|
804
1073
|
throw new TypeError("capability contract reference is invalid");
|
|
805
1074
|
}
|
|
806
1075
|
return candidate;
|
|
@@ -831,7 +1100,7 @@ function modelGatewayBinding(value) {
|
|
|
831
1100
|
throw new TypeError("fixed Model Gateway binding is invalid");
|
|
832
1101
|
}
|
|
833
1102
|
const parts = parseResourceName(resource.crn);
|
|
834
|
-
if (!INVOKABLE_KIND_SET.has(parts.kind) || parts.kind === "model" || parts.kind === "memory") {
|
|
1103
|
+
if (!INVOKABLE_KIND_SET.has(parts.kind) || parts.kind === "model" || parts.kind === "memory" || parts.kind === "skills") {
|
|
835
1104
|
throw new TypeError("Model Gateway must reference a Connection Resource");
|
|
836
1105
|
}
|
|
837
1106
|
capabilityContractRef(candidate.contract);
|
|
@@ -857,7 +1126,7 @@ function memoryStoreBinding(value) {
|
|
|
857
1126
|
throw new TypeError("fixed Memory Store binding is invalid");
|
|
858
1127
|
}
|
|
859
1128
|
const parts = parseResourceName(resource.crn);
|
|
860
|
-
if (!INVOKABLE_KIND_SET.has(parts.kind) || parts.kind === "model" || parts.kind === "memory") {
|
|
1129
|
+
if (!INVOKABLE_KIND_SET.has(parts.kind) || parts.kind === "model" || parts.kind === "memory" || parts.kind === "skills") {
|
|
861
1130
|
throw new TypeError("Memory Store must reference a Connection Resource");
|
|
862
1131
|
}
|
|
863
1132
|
capabilityContractRef(candidate.contract);
|
|
@@ -904,7 +1173,7 @@ function invocationCredentialUses(value) {
|
|
|
904
1173
|
const result = {};
|
|
905
1174
|
for (const [slot, raw] of Object.entries(source).sort(([left], [right]) => left.localeCompare(right))) {
|
|
906
1175
|
const use = record2(raw), consumer = record2(use?.consumer);
|
|
907
|
-
if (!
|
|
1176
|
+
if (!NAME3.test(slot) || !use || Object.keys(use).some((key) => key !== "binding" && key !== "consumer") || !consumer || (consumer.kind === "resource" ? Object.keys(consumer).length !== 1 || typeof use.binding === "string" : Object.keys(consumer).some((key) => !["kind", "delivery", "name"].includes(key)) || !(consumer.kind === "process" && (consumer.delivery === "env" || consumer.delivery === "file") || consumer.kind === "egress" && consumer.delivery === "header") || typeof consumer.name !== "string" || !consumer.name || consumer.name.includes("=") || /[\u0000-\u001f\u007f]/u.test(consumer.name))) throw new TypeError("invocation Credential selection is invalid");
|
|
908
1177
|
result[slot] = { binding: resourceCredentialBinding(use.binding), consumer };
|
|
909
1178
|
}
|
|
910
1179
|
return result;
|
|
@@ -1057,7 +1326,7 @@ function modelAdvertisedPricing(value) {
|
|
|
1057
1326
|
return candidate;
|
|
1058
1327
|
}
|
|
1059
1328
|
function resourceNeed(need) {
|
|
1060
|
-
if (!
|
|
1329
|
+
if (!NAME3.test(need.binding) || !RESOURCE_KIND_SET.has(need.kind) || need.ops !== void 0 && (!Array.isArray(need.ops) || need.ops.length === 0 || need.ops.some((op) => !OPERATION2.test(op)))) throw new TypeError("resource need is invalid");
|
|
1061
1330
|
return need;
|
|
1062
1331
|
}
|
|
1063
1332
|
function ipv4(value) {
|
|
@@ -1254,12 +1523,12 @@ function authProvider(definition) {
|
|
|
1254
1523
|
}
|
|
1255
1524
|
|
|
1256
1525
|
// packages/sdk/src/channel.ts
|
|
1257
|
-
function
|
|
1526
|
+
function required2(value, path) {
|
|
1258
1527
|
if (typeof value !== "string" || value.trim() === "") throw new TypeError(`${path} must be a non-empty string`);
|
|
1259
1528
|
}
|
|
1260
1529
|
function executable(value, path) {
|
|
1261
|
-
|
|
1262
|
-
|
|
1530
|
+
required2(value.id, `${path}.id`);
|
|
1531
|
+
required2(value.version, `${path}.version`);
|
|
1263
1532
|
}
|
|
1264
1533
|
function channel(definition) {
|
|
1265
1534
|
executable(definition, "channel");
|
|
@@ -1292,8 +1561,8 @@ function object(value, message2) {
|
|
|
1292
1561
|
if (!value || typeof value !== "object" || Array.isArray(value)) throw new TypeError(message2);
|
|
1293
1562
|
return value;
|
|
1294
1563
|
}
|
|
1295
|
-
function exactKeys(value, allowed,
|
|
1296
|
-
if (Object.keys(value).some((key) => !allowed.includes(key)) ||
|
|
1564
|
+
function exactKeys(value, allowed, required3) {
|
|
1565
|
+
if (Object.keys(value).some((key) => !allowed.includes(key)) || required3.some((key) => !Object.hasOwn(value, key))) {
|
|
1297
1566
|
throw new TypeError("UI bundle contains unsupported fields");
|
|
1298
1567
|
}
|
|
1299
1568
|
}
|
|
@@ -1406,7 +1675,7 @@ function uiBundle(value, execution) {
|
|
|
1406
1675
|
if (moduleEntries.length < 1 || moduleEntries.length > UI_BUNDLE_BOUNDS.maximumModules || assetEntries.length > UI_BUNDLE_BOUNDS.maximumAssets || !Object.hasOwn(modules, manifest2.runtime.entry)) {
|
|
1407
1676
|
throw new TypeError("UI bundle file inventory is invalid");
|
|
1408
1677
|
}
|
|
1409
|
-
const
|
|
1678
|
+
const paths2 = /* @__PURE__ */ new Set();
|
|
1410
1679
|
let expandedBytes = 0;
|
|
1411
1680
|
const normalizedModules = {};
|
|
1412
1681
|
for (const [rawPath, rawModule] of moduleEntries.sort(([left], [right]) => left.localeCompare(right))) {
|
|
@@ -1418,8 +1687,8 @@ function uiBundle(value, execution) {
|
|
|
1418
1687
|
}
|
|
1419
1688
|
if (module.type !== "esmodule" || typeof module.source !== "string" || SECRET.test(module.source)) throw new TypeError("UI module is invalid or contains secret material");
|
|
1420
1689
|
const bytes = byteLength(module.source);
|
|
1421
|
-
if (bytes > UI_BUNDLE_BOUNDS.maximumFileBytes ||
|
|
1422
|
-
|
|
1690
|
+
if (bytes > UI_BUNDLE_BOUNDS.maximumFileBytes || paths2.has(path)) throw new TypeError("UI module path or size is invalid");
|
|
1691
|
+
paths2.add(path);
|
|
1423
1692
|
expandedBytes += bytes;
|
|
1424
1693
|
normalizedModules[path] = { type: "esmodule", source: module.source };
|
|
1425
1694
|
}
|
|
@@ -1428,10 +1697,10 @@ function uiBundle(value, execution) {
|
|
|
1428
1697
|
const path = safePath(rawPath, "UI asset path");
|
|
1429
1698
|
const asset = object(rawAsset, "UI asset is invalid");
|
|
1430
1699
|
exactKeys(asset, ["bodyBase64", "contentType"], ["bodyBase64", "contentType"]);
|
|
1431
|
-
if (typeof asset.bodyBase64 !== "string" || !BASE64.test(asset.bodyBase64) || typeof asset.contentType !== "string" || !CONTENT_TYPE.test(asset.contentType) ||
|
|
1700
|
+
if (typeof asset.bodyBase64 !== "string" || !BASE64.test(asset.bodyBase64) || typeof asset.contentType !== "string" || !CONTENT_TYPE.test(asset.contentType) || paths2.has(path)) throw new TypeError("UI asset is invalid");
|
|
1432
1701
|
const bytes = Math.floor(asset.bodyBase64.length * 3 / 4) - (asset.bodyBase64.endsWith("==") ? 2 : asset.bodyBase64.endsWith("=") ? 1 : 0);
|
|
1433
1702
|
if (bytes > UI_BUNDLE_BOUNDS.maximumFileBytes) throw new TypeError("UI asset exceeds the file limit");
|
|
1434
|
-
|
|
1703
|
+
paths2.add(path);
|
|
1435
1704
|
expandedBytes += bytes;
|
|
1436
1705
|
normalizedAssets[path] = { bodyBase64: asset.bodyBase64, contentType: asset.contentType };
|
|
1437
1706
|
}
|
|
@@ -1807,9 +2076,9 @@ function setupScreenView(id2 = "setup-screen") {
|
|
|
1807
2076
|
function credentialSetupState(requirement, scope2, inventory, binding) {
|
|
1808
2077
|
const parsed = agentSetupRequirements([requirement])[0];
|
|
1809
2078
|
if (parsed.resourceKind !== "credential") throw new TypeError("Credential setup requires a Credential requirement");
|
|
1810
|
-
const
|
|
1811
|
-
const owner = resolveBindingOwner(parsed.binding.owner, scope2,
|
|
1812
|
-
if (!owner) return { status: "missing", required:
|
|
2079
|
+
const required3 = parsed.optional !== true;
|
|
2080
|
+
const owner = resolveBindingOwner(parsed.binding.owner, scope2, required3);
|
|
2081
|
+
if (!owner) return { status: "missing", required: required3, credential: null, candidates: [] };
|
|
1813
2082
|
const candidates = [...new Set(inventory.flatMap((candidate) => {
|
|
1814
2083
|
if (candidate.available !== true) return [];
|
|
1815
2084
|
try {
|
|
@@ -1828,7 +2097,7 @@ function credentialSetupState(requirement, scope2, inventory, binding) {
|
|
|
1828
2097
|
return [];
|
|
1829
2098
|
}
|
|
1830
2099
|
}))].sort();
|
|
1831
|
-
if (!binding) return { status: candidates.length ? "choose" : "missing", required:
|
|
2100
|
+
if (!binding) return { status: candidates.length ? "choose" : "missing", required: required3, credential: null, candidates };
|
|
1832
2101
|
const revision = binding.revision;
|
|
1833
2102
|
if (revision.environment !== scope2.environment || revision.tenant !== scope2.tenant || revision.namespace !== scope2.namespace || revision.targetClass !== "credential" || revision.key !== parsed.binding.key || canonicalJson(revision.owner) !== canonicalJson(owner)) {
|
|
1834
2103
|
throw new TypeError("Saved Credential binding does not belong to this setup slot");
|
|
@@ -1840,7 +2109,7 @@ function credentialSetupState(requirement, scope2, inventory, binding) {
|
|
|
1840
2109
|
const credential = revision.target.crn;
|
|
1841
2110
|
return {
|
|
1842
2111
|
status: binding.state === "enabled" && candidates.includes(credential) ? "ready" : "blocked",
|
|
1843
|
-
required:
|
|
2112
|
+
required: required3,
|
|
1844
2113
|
credential,
|
|
1845
2114
|
candidates
|
|
1846
2115
|
};
|
|
@@ -2213,12 +2482,12 @@ function requiredString2(value, path, _maximum) {
|
|
|
2213
2482
|
throw new TypeError(`${path} must be a non-empty string`);
|
|
2214
2483
|
}
|
|
2215
2484
|
}
|
|
2216
|
-
function exactKeys2(value, allowed,
|
|
2217
|
-
if (Object.keys(value).some((key) => !allowed.includes(key)) ||
|
|
2485
|
+
function exactKeys2(value, allowed, required3, path) {
|
|
2486
|
+
if (Object.keys(value).some((key) => !allowed.includes(key)) || required3.some((key) => !Object.hasOwn(value, key))) {
|
|
2218
2487
|
throw new TypeError(`${path} has invalid keys`);
|
|
2219
2488
|
}
|
|
2220
2489
|
}
|
|
2221
|
-
function
|
|
2490
|
+
function scalar2(value) {
|
|
2222
2491
|
return value === null || typeof value === "string" || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value);
|
|
2223
2492
|
}
|
|
2224
2493
|
function validateGrant(grant, path) {
|
|
@@ -2249,7 +2518,7 @@ function validatePolicyConstraint(constraint, path = "constraint") {
|
|
|
2249
2518
|
}
|
|
2250
2519
|
if (constraint.kind === "context") {
|
|
2251
2520
|
exactKeys2(source, ["kind", "equals"], ["kind", "equals"], path);
|
|
2252
|
-
if (!record4(constraint.equals) || Object.keys(constraint.equals).length === 0 || Object.entries(constraint.equals).some(([key, value]) => !key || key.length > 256 || !
|
|
2521
|
+
if (!record4(constraint.equals) || Object.keys(constraint.equals).length === 0 || Object.entries(constraint.equals).some(([key, value]) => !key || key.length > 256 || !scalar2(value))) {
|
|
2253
2522
|
throw new TypeError(`${path}.equals is invalid`);
|
|
2254
2523
|
}
|
|
2255
2524
|
return;
|
|
@@ -2262,9 +2531,9 @@ function validatePolicyConstraint(constraint, path = "constraint") {
|
|
|
2262
2531
|
}
|
|
2263
2532
|
throw new TypeError(`${path}.kind is invalid`);
|
|
2264
2533
|
}
|
|
2265
|
-
function validateConstraints(value, path,
|
|
2266
|
-
if (value === void 0 && !
|
|
2267
|
-
if (!Array.isArray(value) ||
|
|
2534
|
+
function validateConstraints(value, path, required3) {
|
|
2535
|
+
if (value === void 0 && !required3) return [];
|
|
2536
|
+
if (!Array.isArray(value) || required3 && value.length === 0) {
|
|
2268
2537
|
throw new TypeError(`${path} is invalid`);
|
|
2269
2538
|
}
|
|
2270
2539
|
value.forEach((constraint, index) => validatePolicyConstraint(constraint, `${path}[${index}]`));
|
|
@@ -2388,367 +2657,82 @@ function shareRequest(value) {
|
|
|
2388
2657
|
if (source.history !== null && (!history || Object.keys(history).some((key) => key !== "since") || !Number.isSafeInteger(history.since) || history.since <= 0)) {
|
|
2389
2658
|
throw new TypeError("Share history must be null or { since: a time in milliseconds }");
|
|
2390
2659
|
}
|
|
2391
|
-
terms.history = history ? { since: history.since } : null;
|
|
2392
|
-
}
|
|
2393
|
-
if (Object.hasOwn(source, "expiresAt")) {
|
|
2394
|
-
if (source.expiresAt !== null && (!Number.isSafeInteger(source.expiresAt) || source.expiresAt <= 0)) {
|
|
2395
|
-
throw new TypeError("Share expiresAt must be null or a time in milliseconds");
|
|
2396
|
-
}
|
|
2397
|
-
terms.expiresAt = source.expiresAt;
|
|
2398
|
-
}
|
|
2399
|
-
return terms;
|
|
2400
|
-
}
|
|
2401
|
-
var NAME3 = /^[a-z0-9][a-z0-9._-]{0,127}$/u;
|
|
2402
|
-
var HASH2 = /^[a-f0-9]{64}$/u;
|
|
2403
|
-
var DECISIONS = ["accept", "request-changes", "reject"];
|
|
2404
|
-
function contributionNote(value) {
|
|
2405
|
-
if (typeof value !== "string" || new TextEncoder().encode(value).byteLength > 4096) throw new TypeError("note must be text of at most 4096 bytes");
|
|
2406
|
-
return value;
|
|
2407
|
-
}
|
|
2408
|
-
function datasetPin(value, index) {
|
|
2409
|
-
const pin = record5(value);
|
|
2410
|
-
let kind = null;
|
|
2411
|
-
try {
|
|
2412
|
-
kind = typeof pin?.crn === "string" ? parseResourceName(pin.crn).kind : null;
|
|
2413
|
-
} catch {
|
|
2414
|
-
kind = null;
|
|
2415
|
-
}
|
|
2416
|
-
if (!pin || Object.keys(pin).length !== 3 || kind !== "dataset" || typeof pin.version !== "string" || !pin.version || typeof pin.hash !== "string" || !HASH2.test(pin.hash)) throw new TypeError(`Contribution dataset ${index} is invalid`);
|
|
2417
|
-
return { crn: pin.crn, version: pin.version, hash: pin.hash };
|
|
2418
|
-
}
|
|
2419
|
-
function shareContributionRequest(value) {
|
|
2420
|
-
const source = record5(value);
|
|
2421
|
-
const unknown = source && Object.keys(source).find((key) => key !== "datasets" && key !== "evaluations" && key !== "note");
|
|
2422
|
-
if (!source || unknown) throw new TypeError(unknown ? `Contribution field ${unknown} is not supported` : "Contribution request is invalid");
|
|
2423
|
-
const terms = {};
|
|
2424
|
-
if (Object.hasOwn(source, "datasets")) {
|
|
2425
|
-
if (!Array.isArray(source.datasets) || source.datasets.length > 16) throw new TypeError("datasets must be a list of at most 16 Dataset versions");
|
|
2426
|
-
terms.datasets = source.datasets.map(datasetPin);
|
|
2427
|
-
}
|
|
2428
|
-
if (Object.hasOwn(source, "evaluations")) {
|
|
2429
|
-
const evaluations = source.evaluations;
|
|
2430
|
-
if (!Array.isArray(evaluations) || evaluations.length > 16 || evaluations.some((item) => typeof item !== "string" || !NAME3.test(item))) {
|
|
2431
|
-
throw new TypeError("evaluations must be a list of at most 16 evaluation ids");
|
|
2432
|
-
}
|
|
2433
|
-
terms.evaluations = evaluations;
|
|
2434
|
-
}
|
|
2435
|
-
if (Object.hasOwn(source, "note")) terms.note = contributionNote(source.note);
|
|
2436
|
-
return terms;
|
|
2437
|
-
}
|
|
2438
|
-
function shareContributionReview(value) {
|
|
2439
|
-
const source = record5(value);
|
|
2440
|
-
const unknown = source && Object.keys(source).find((key) => !["decision", "note", "namespace", "targets"].includes(key));
|
|
2441
|
-
if (!source || unknown) throw new TypeError(unknown ? `Review field ${unknown} is not supported` : "Review request is invalid");
|
|
2442
|
-
if (!DECISIONS.includes(source.decision)) throw new TypeError("Review decision must be accept, request-changes or reject");
|
|
2443
|
-
const review = { decision: source.decision };
|
|
2444
|
-
if (Object.hasOwn(source, "note")) review.note = contributionNote(source.note);
|
|
2445
|
-
if (review.decision !== "accept") {
|
|
2446
|
-
if (Object.hasOwn(source, "namespace") || Object.hasOwn(source, "targets")) throw new TypeError("Only an accepting review names a namespace or targets");
|
|
2447
|
-
return review;
|
|
2448
|
-
}
|
|
2449
|
-
if (Object.hasOwn(source, "namespace")) {
|
|
2450
|
-
if (typeof source.namespace !== "string" || !NAME3.test(source.namespace)) throw new TypeError("Review namespace is invalid");
|
|
2451
|
-
review.namespace = source.namespace;
|
|
2452
|
-
}
|
|
2453
|
-
if (Object.hasOwn(source, "targets")) {
|
|
2454
|
-
const targets = source.targets;
|
|
2455
|
-
if (!Array.isArray(targets) || targets.length > 16 || targets.some((item) => item !== null && (typeof item !== "string" || !NAME3.test(item)))) {
|
|
2456
|
-
throw new TypeError("Review targets must be at most 16 Dataset ids or nulls");
|
|
2457
|
-
}
|
|
2458
|
-
review.targets = targets;
|
|
2459
|
-
}
|
|
2460
|
-
return review;
|
|
2461
|
-
}
|
|
2462
|
-
|
|
2463
|
-
// packages/sdk/src/table.ts
|
|
2464
|
-
var identifier = { type: "string", pattern: "^[a-zA-Z_][a-zA-Z0-9_.-]{0,127}$", maxLength: 128 };
|
|
2465
|
-
var tableName = { type: "string", pattern: "^[a-z0-9][a-z0-9._-]{0,127}$", maxLength: 128 };
|
|
2466
|
-
var branchName = { type: "string", pattern: "^[a-z0-9][a-z0-9._/-]{0,127}$", maxLength: 128 };
|
|
2467
|
-
var hash2 = { type: "string", pattern: "^[a-f0-9]{64}$" };
|
|
2468
|
-
var scalar2 = { type: ["string", "number", "integer", "boolean", "null"] };
|
|
2469
|
-
var TABLE_DESCRIBE_SCHEMA = {
|
|
2470
|
-
type: "object",
|
|
2471
|
-
required: ["table"],
|
|
2472
|
-
additionalProperties: false,
|
|
2473
|
-
properties: {
|
|
2474
|
-
table: tableName,
|
|
2475
|
-
branch: branchName,
|
|
2476
|
-
snapshot: hash2,
|
|
2477
|
-
stageId: hash2,
|
|
2478
|
-
waitMs: { type: "integer", minimum: 0 }
|
|
2479
|
-
}
|
|
2480
|
-
};
|
|
2481
|
-
var filterSchema = {
|
|
2482
|
-
type: "object",
|
|
2483
|
-
required: ["field", "op", "value"],
|
|
2484
|
-
additionalProperties: false,
|
|
2485
|
-
properties: {
|
|
2486
|
-
field: identifier,
|
|
2487
|
-
op: { type: "string", enum: ["eq", "ne", "gt", "gte", "lt", "lte", "in", "between"] },
|
|
2488
|
-
value: { anyOf: [scalar2, { type: "array", minItems: 1, items: scalar2 }] }
|
|
2489
|
-
}
|
|
2490
|
-
};
|
|
2491
|
-
var TABLE_QUERY_SCHEMA = {
|
|
2492
|
-
type: "object",
|
|
2493
|
-
required: ["table", "snapshot", "query"],
|
|
2494
|
-
additionalProperties: false,
|
|
2495
|
-
properties: {
|
|
2496
|
-
table: tableName,
|
|
2497
|
-
branch: branchName,
|
|
2498
|
-
snapshot: hash2,
|
|
2499
|
-
query: {
|
|
2500
|
-
type: "object",
|
|
2501
|
-
additionalProperties: false,
|
|
2502
|
-
properties: {
|
|
2503
|
-
select: { type: "array", uniqueItems: true, items: identifier },
|
|
2504
|
-
where: { type: "array", items: filterSchema },
|
|
2505
|
-
groupBy: { type: "array", uniqueItems: true, items: identifier },
|
|
2506
|
-
aggregates: { type: "array", items: {
|
|
2507
|
-
type: "object",
|
|
2508
|
-
required: ["fn", "as"],
|
|
2509
|
-
additionalProperties: false,
|
|
2510
|
-
properties: {
|
|
2511
|
-
fn: { type: "string", enum: ["count", "sum", "avg", "min", "max"] },
|
|
2512
|
-
field: identifier,
|
|
2513
|
-
as: identifier
|
|
2514
|
-
}
|
|
2515
|
-
} },
|
|
2516
|
-
orderBy: { type: "array", items: {
|
|
2517
|
-
type: "object",
|
|
2518
|
-
required: ["field", "direction"],
|
|
2519
|
-
additionalProperties: false,
|
|
2520
|
-
properties: { field: identifier, direction: { type: "string", enum: ["asc", "desc"] } }
|
|
2521
|
-
} },
|
|
2522
|
-
limit: { type: "integer", minimum: 1 }
|
|
2523
|
-
}
|
|
2524
|
-
}
|
|
2525
|
-
}
|
|
2526
|
-
};
|
|
2527
|
-
function validateStageOutputSpec(value, path = "$.output") {
|
|
2528
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return `${path} must be an object`;
|
|
2529
|
-
const output = value;
|
|
2530
|
-
const extra = Object.keys(output).find((key) => key !== "schema" && key !== "sortOrder");
|
|
2531
|
-
if (extra) return `${path}.${extra} is not allowed`;
|
|
2532
|
-
if (!Object.hasOwn(output, "schema")) return `${path}.schema is required`;
|
|
2533
|
-
const schemaError = validateJsonSchemaDefinition(output.schema, `${path}.schema`);
|
|
2534
|
-
if (schemaError) return schemaError;
|
|
2535
|
-
const sortOrder = output.sortOrder ?? [];
|
|
2536
|
-
if (!Array.isArray(sortOrder)) return `${path}.sortOrder is invalid`;
|
|
2537
|
-
const keys = /* @__PURE__ */ new Set();
|
|
2538
|
-
for (const [index, raw] of sortOrder.entries()) {
|
|
2539
|
-
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return `${path}.sortOrder[${index}] is invalid`;
|
|
2540
|
-
const field2 = raw;
|
|
2541
|
-
if (Object.keys(field2).some((key) => key !== "key" && key !== "direction") || typeof field2.key !== "string" || !/^[a-zA-Z_][a-zA-Z0-9_.-]{0,127}$/u.test(field2.key) || field2.direction !== "asc" && field2.direction !== "desc" || keys.has(field2.key)) {
|
|
2542
|
-
return `${path}.sortOrder[${index}] is invalid`;
|
|
2660
|
+
terms.history = history ? { since: history.since } : null;
|
|
2661
|
+
}
|
|
2662
|
+
if (Object.hasOwn(source, "expiresAt")) {
|
|
2663
|
+
if (source.expiresAt !== null && (!Number.isSafeInteger(source.expiresAt) || source.expiresAt <= 0)) {
|
|
2664
|
+
throw new TypeError("Share expiresAt must be null or a time in milliseconds");
|
|
2543
2665
|
}
|
|
2544
|
-
|
|
2666
|
+
terms.expiresAt = source.expiresAt;
|
|
2545
2667
|
}
|
|
2546
|
-
return
|
|
2668
|
+
return terms;
|
|
2547
2669
|
}
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2670
|
+
var NAME4 = /^[a-z0-9][a-z0-9._-]{0,127}$/u;
|
|
2671
|
+
var HASH2 = /^[a-f0-9]{64}$/u;
|
|
2672
|
+
var DECISIONS = ["accept", "request-changes", "reject"];
|
|
2673
|
+
function contributionNote(value) {
|
|
2674
|
+
if (typeof value !== "string" || new TextEncoder().encode(value).byteLength > 4096) throw new TypeError("note must be text of at most 4096 bytes");
|
|
2551
2675
|
return value;
|
|
2552
2676
|
}
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
async run(args, ctx) {
|
|
2561
|
-
return ctx.invoke(ctx.resources.table_catalog, "describe", args);
|
|
2562
|
-
}
|
|
2563
|
-
};
|
|
2564
|
-
var tableQuery = {
|
|
2565
|
-
name: "table_query",
|
|
2566
|
-
version: "1",
|
|
2567
|
-
description: "Query one exact Table snapshot with bounded fields, filters, grouping, aggregates, ordering, and limit.",
|
|
2568
|
-
schema: TABLE_QUERY_SCHEMA,
|
|
2569
|
-
maxEffect: "read-only",
|
|
2570
|
-
needs: [{ binding: "table_catalog", kind: "service", ops: ["query"] }],
|
|
2571
|
-
async run(args, ctx) {
|
|
2572
|
-
return ctx.invoke(ctx.resources.table_catalog, "query", args);
|
|
2677
|
+
function datasetPin(value, index) {
|
|
2678
|
+
const pin = record5(value);
|
|
2679
|
+
let kind = null;
|
|
2680
|
+
try {
|
|
2681
|
+
kind = typeof pin?.crn === "string" ? parseResourceName(pin.crn).kind : null;
|
|
2682
|
+
} catch {
|
|
2683
|
+
kind = null;
|
|
2573
2684
|
}
|
|
2574
|
-
};
|
|
2575
|
-
|
|
2576
|
-
// packages/sdk/src/tools.ts
|
|
2577
|
-
var NAME4 = /^[a-z0-9][a-z0-9._-]{0,127}$/u;
|
|
2578
|
-
var OPERATION2 = /^[A-Za-z][A-Za-z0-9._-]{0,127}$/u;
|
|
2579
|
-
function opTool(binding, op, override = {}) {
|
|
2580
|
-
if (!NAME4.test(binding) || !OPERATION2.test(op)) throw new TypeError("opTool binding or operation is invalid");
|
|
2581
|
-
const name = override.name ?? op.replaceAll(".", "_");
|
|
2582
|
-
return {
|
|
2583
|
-
name,
|
|
2584
|
-
...override.title ? { title: override.title } : {},
|
|
2585
|
-
version: "catalog",
|
|
2586
|
-
description: override.description ?? `Invoke ${op} on the bound ${binding} resource.`,
|
|
2587
|
-
schema: override.schema ?? { type: "object", additionalProperties: false },
|
|
2588
|
-
maxEffect: "read-only",
|
|
2589
|
-
needs: [],
|
|
2590
|
-
...override.tier ? { tier: override.tier } : {},
|
|
2591
|
-
...override.once ? { once: override.once } : {},
|
|
2592
|
-
...override.guard ? { guard: override.guard } : {},
|
|
2593
|
-
...override.preview ? { preview: override.preview } : {},
|
|
2594
|
-
catalog: { binding, op },
|
|
2595
|
-
async run() {
|
|
2596
|
-
throw new TypeError(`catalog Tool ${binding}#${op} was not resolved by deployment`);
|
|
2597
|
-
}
|
|
2598
|
-
};
|
|
2599
|
-
}
|
|
2600
|
-
function opTools(binding, ops = []) {
|
|
2601
|
-
if (ops.length === 0) throw new TypeError("opTools requires pinned operation names at bundle construction");
|
|
2602
|
-
return ops.map((op) => opTool(binding, op));
|
|
2603
|
-
}
|
|
2604
|
-
async function boundResource(ctx, binding) {
|
|
2605
|
-
const resource = await ctx.describeResource(binding);
|
|
2606
|
-
if (!resource) throw new TypeError(`Resource is not bound: ${binding}`);
|
|
2607
|
-
return resource;
|
|
2685
|
+
if (!pin || Object.keys(pin).length !== 3 || kind !== "dataset" || typeof pin.version !== "string" || !pin.version || typeof pin.hash !== "string" || !HASH2.test(pin.hash)) throw new TypeError(`Contribution dataset ${index} is invalid`);
|
|
2686
|
+
return { crn: pin.crn, version: pin.version, hash: pin.hash };
|
|
2608
2687
|
}
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
maxEffect: "read-only",
|
|
2623
|
-
needs: [],
|
|
2624
|
-
description: "Read a bound Resource's public operations, input/output schemas, and execution semantics. This does not connect or install it.",
|
|
2625
|
-
schema: {
|
|
2626
|
-
type: "object",
|
|
2627
|
-
required: ["binding"],
|
|
2628
|
-
additionalProperties: false,
|
|
2629
|
-
properties: { binding: { type: "string", minLength: 1 } }
|
|
2630
|
-
},
|
|
2631
|
-
run: (args, ctx) => boundResource(ctx, args.binding)
|
|
2632
|
-
},
|
|
2633
|
-
resource_invoke: {
|
|
2634
|
-
name: "resource_invoke",
|
|
2635
|
-
version: "1",
|
|
2636
|
-
maxEffect: "non-idempotent",
|
|
2637
|
-
needs: [],
|
|
2638
|
-
description: "Invoke a public operation on an already-bound Resource using its described input schema. Policy applies to the invocation. This does not install a Resource or add a binding.",
|
|
2639
|
-
schema: {
|
|
2640
|
-
type: "object",
|
|
2641
|
-
required: ["binding", "operation", "arguments"],
|
|
2642
|
-
additionalProperties: false,
|
|
2643
|
-
properties: { binding: { type: "string", minLength: 1 }, operation: { type: "string", minLength: 1 }, arguments: {} }
|
|
2644
|
-
},
|
|
2645
|
-
async run(args, ctx) {
|
|
2646
|
-
const resource = await boundResource(ctx, args.binding);
|
|
2647
|
-
const operation = resource.operations.find((candidate) => candidate.op === args.operation);
|
|
2648
|
-
if (!operation) throw new TypeError(`Resource operation is not available: ${args.binding}#${args.operation}`);
|
|
2649
|
-
return operation.async ? ctx.invokeAsync(resource.crn, operation.op, args.arguments) : ctx.invoke(resource.crn, operation.op, args.arguments);
|
|
2688
|
+
function shareContributionRequest(value) {
|
|
2689
|
+
const source = record5(value);
|
|
2690
|
+
const unknown = source && Object.keys(source).find((key) => key !== "datasets" && key !== "evaluations" && key !== "note");
|
|
2691
|
+
if (!source || unknown) throw new TypeError(unknown ? `Contribution field ${unknown} is not supported` : "Contribution request is invalid");
|
|
2692
|
+
const terms = {};
|
|
2693
|
+
if (Object.hasOwn(source, "datasets")) {
|
|
2694
|
+
if (!Array.isArray(source.datasets) || source.datasets.length > 16) throw new TypeError("datasets must be a list of at most 16 Dataset versions");
|
|
2695
|
+
terms.datasets = source.datasets.map(datasetPin);
|
|
2696
|
+
}
|
|
2697
|
+
if (Object.hasOwn(source, "evaluations")) {
|
|
2698
|
+
const evaluations = source.evaluations;
|
|
2699
|
+
if (!Array.isArray(evaluations) || evaluations.length > 16 || evaluations.some((item) => typeof item !== "string" || !NAME4.test(item))) {
|
|
2700
|
+
throw new TypeError("evaluations must be a list of at most 16 evaluation ids");
|
|
2650
2701
|
}
|
|
2702
|
+
terms.evaluations = evaluations;
|
|
2651
2703
|
}
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2704
|
+
if (Object.hasOwn(source, "note")) terms.note = contributionNote(source.note);
|
|
2705
|
+
return terms;
|
|
2706
|
+
}
|
|
2707
|
+
function shareContributionReview(value) {
|
|
2708
|
+
const source = record5(value);
|
|
2709
|
+
const unknown = source && Object.keys(source).find((key) => !["decision", "note", "namespace", "targets"].includes(key));
|
|
2710
|
+
if (!source || unknown) throw new TypeError(unknown ? `Review field ${unknown} is not supported` : "Review request is invalid");
|
|
2711
|
+
if (!DECISIONS.includes(source.decision)) throw new TypeError("Review decision must be accept, request-changes or reject");
|
|
2712
|
+
const review = { decision: source.decision };
|
|
2713
|
+
if (Object.hasOwn(source, "note")) review.note = contributionNote(source.note);
|
|
2714
|
+
if (review.decision !== "accept") {
|
|
2715
|
+
if (Object.hasOwn(source, "namespace") || Object.hasOwn(source, "targets")) throw new TypeError("Only an accepting review names a namespace or targets");
|
|
2716
|
+
return review;
|
|
2660
2717
|
}
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
required: ["query"],
|
|
2665
|
-
additionalProperties: false,
|
|
2666
|
-
properties: {
|
|
2667
|
-
query: {
|
|
2668
|
-
type: "string",
|
|
2669
|
-
minLength: 1,
|
|
2670
|
-
description: "A self-contained description of the information to find."
|
|
2671
|
-
},
|
|
2672
|
-
searchQueries: {
|
|
2673
|
-
type: "array",
|
|
2674
|
-
minItems: 1,
|
|
2675
|
-
uniqueItems: true,
|
|
2676
|
-
description: "Optional concise keyword queries that narrow the search.",
|
|
2677
|
-
items: { type: "string", minLength: 1 }
|
|
2678
|
-
},
|
|
2679
|
-
maximumResults: {
|
|
2680
|
-
type: "integer",
|
|
2681
|
-
minimum: 1,
|
|
2682
|
-
description: "Maximum number of sources to return."
|
|
2683
|
-
},
|
|
2684
|
-
maximumCharacters: {
|
|
2685
|
-
type: "integer",
|
|
2686
|
-
minimum: 1,
|
|
2687
|
-
description: "Maximum total excerpt characters to return."
|
|
2688
|
-
},
|
|
2689
|
-
includeDomains: {
|
|
2690
|
-
type: "array",
|
|
2691
|
-
uniqueItems: true,
|
|
2692
|
-
description: "Optional domains to restrict results to.",
|
|
2693
|
-
items: { type: "string", minLength: 1 }
|
|
2694
|
-
},
|
|
2695
|
-
excludeDomains: {
|
|
2696
|
-
type: "array",
|
|
2697
|
-
uniqueItems: true,
|
|
2698
|
-
description: "Optional domains to omit.",
|
|
2699
|
-
items: { type: "string", minLength: 1 }
|
|
2700
|
-
},
|
|
2701
|
-
afterDate: {
|
|
2702
|
-
type: "string",
|
|
2703
|
-
pattern: "^[0-9]{4}-[0-9]{2}-[0-9]{2}$",
|
|
2704
|
-
description: "Optional earliest publication date in YYYY-MM-DD form."
|
|
2705
|
-
}
|
|
2718
|
+
if (Object.hasOwn(source, "namespace")) {
|
|
2719
|
+
if (typeof source.namespace !== "string" || !NAME4.test(source.namespace)) throw new TypeError("Review namespace is invalid");
|
|
2720
|
+
review.namespace = source.namespace;
|
|
2706
2721
|
}
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
schema: WEB_FETCH_ARGUMENT_SCHEMA
|
|
2712
|
-
});
|
|
2713
|
-
var webSearch = opTool("search", "search", {
|
|
2714
|
-
name: "web_search",
|
|
2715
|
-
description: "Search the public web through the bound governed search Resource.",
|
|
2716
|
-
schema: WEB_SEARCH_ARGUMENT_SCHEMA
|
|
2717
|
-
});
|
|
2718
|
-
var casTool = {
|
|
2719
|
-
name: "cas",
|
|
2720
|
-
version: "1",
|
|
2721
|
-
description: "Store or load one content-addressed Agent artifact.",
|
|
2722
|
-
schema: {
|
|
2723
|
-
type: "object",
|
|
2724
|
-
required: ["action"],
|
|
2725
|
-
additionalProperties: false,
|
|
2726
|
-
properties: {
|
|
2727
|
-
action: { type: "string", enum: ["put", "get"] },
|
|
2728
|
-
value: {},
|
|
2729
|
-
ref: { type: "string", pattern: "^[a-f0-9]{64}$" }
|
|
2730
|
-
}
|
|
2731
|
-
},
|
|
2732
|
-
maxEffect: "idempotent",
|
|
2733
|
-
needs: [{ binding: "cas", kind: "cas", ops: ["put", "get"] }],
|
|
2734
|
-
async run(args, ctx) {
|
|
2735
|
-
const input = args && typeof args === "object" && !Array.isArray(args) ? args : {};
|
|
2736
|
-
if (input.action === "put") {
|
|
2737
|
-
if (!Object.hasOwn(input, "value")) throw new TypeError("cas put requires value");
|
|
2738
|
-
return ctx.invoke(ctx.resources.cas, "put", { value: input.value });
|
|
2739
|
-
}
|
|
2740
|
-
if (input.action === "get") {
|
|
2741
|
-
if (typeof input.ref !== "string") throw new TypeError("cas get requires ref");
|
|
2742
|
-
return ctx.invoke(ctx.resources.cas, "get", { ref: input.ref });
|
|
2722
|
+
if (Object.hasOwn(source, "targets")) {
|
|
2723
|
+
const targets = source.targets;
|
|
2724
|
+
if (!Array.isArray(targets) || targets.length > 16 || targets.some((item) => item !== null && (typeof item !== "string" || !NAME4.test(item)))) {
|
|
2725
|
+
throw new TypeError("Review targets must be at most 16 Dataset ids or nulls");
|
|
2743
2726
|
}
|
|
2744
|
-
|
|
2727
|
+
review.targets = targets;
|
|
2745
2728
|
}
|
|
2746
|
-
|
|
2729
|
+
return review;
|
|
2730
|
+
}
|
|
2747
2731
|
|
|
2748
2732
|
// packages/sdk/src/memory.ts
|
|
2749
2733
|
var id = { type: "string", pattern: "^[A-Za-z0-9._~-]{1,256}$", maxLength: 256 };
|
|
2750
2734
|
var content = { type: "string", minLength: 1 };
|
|
2751
|
-
var
|
|
2735
|
+
var metadata = { type: "object" };
|
|
2752
2736
|
var scope = { type: "string", pattern: "^[a-f0-9]{64}$", maxLength: 64 };
|
|
2753
2737
|
var record6 = {
|
|
2754
2738
|
type: "object",
|
|
@@ -2757,7 +2741,7 @@ var record6 = {
|
|
|
2757
2741
|
properties: {
|
|
2758
2742
|
id,
|
|
2759
2743
|
content,
|
|
2760
|
-
metadata
|
|
2744
|
+
metadata,
|
|
2761
2745
|
createdAt: { type: "integer", minimum: 0 },
|
|
2762
2746
|
updatedAt: { type: "integer", minimum: 0 },
|
|
2763
2747
|
expiresAt: { anyOf: [{ type: "integer", minimum: 0 }, { type: "null" }] }
|
|
@@ -2767,7 +2751,7 @@ var MEMORY_OPERATION_DECLARATIONS = [
|
|
|
2767
2751
|
{
|
|
2768
2752
|
op: "remember",
|
|
2769
2753
|
description: "Persist or replace one record in the invocation's authenticated Memory partition.",
|
|
2770
|
-
schema: { type: "object", required: ["content"], additionalProperties: false, properties: { id, content, metadata
|
|
2754
|
+
schema: { type: "object", required: ["content"], additionalProperties: false, properties: { id, content, metadata, scope } },
|
|
2771
2755
|
resultSchema: record6,
|
|
2772
2756
|
effect: "idempotent",
|
|
2773
2757
|
recovery: { kind: "idempotency-key" },
|
|
@@ -2876,8 +2860,8 @@ function integrationEgressPolicy(value) {
|
|
|
2876
2860
|
}
|
|
2877
2861
|
const rules = source.rules.map((raw) => {
|
|
2878
2862
|
const rule = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : null;
|
|
2879
|
-
const
|
|
2880
|
-
if (!rule || !Array.isArray(rule.operations) || rule.operations.length === 0 || rule.operations.some((operation) => typeof operation !== "string" || operation !== "*" && !OPERATION3.test(operation)) || typeof rule.origin !== "string" ||
|
|
2863
|
+
const paths2 = Number(rule?.pathPrefix !== void 0) + Number(rule?.pathExact !== void 0);
|
|
2864
|
+
if (!rule || !Array.isArray(rule.operations) || rule.operations.length === 0 || rule.operations.some((operation) => typeof operation !== "string" || operation !== "*" && !OPERATION3.test(operation)) || typeof rule.origin !== "string" || paths2 !== 1 || !Array.isArray(rule.methods) || rule.methods.length === 0 || rule.methods.length > 8 || rule.methods.some((method) => typeof method !== "string" || !/^(?:GET|POST|PUT|PATCH|DELETE)$/u.test(method)) || Object.keys(rule).some((key) => !["operations", "origin", "pathPrefix", "pathExact", "methods"].includes(key))) {
|
|
2881
2865
|
throw new TypeError("integration egress rule is invalid");
|
|
2882
2866
|
}
|
|
2883
2867
|
let origin;
|
|
@@ -3291,8 +3275,8 @@ var NotAppendOnly = class extends Error {
|
|
|
3291
3275
|
function record8(value) {
|
|
3292
3276
|
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
3293
3277
|
}
|
|
3294
|
-
function exactKeys3(value,
|
|
3295
|
-
return
|
|
3278
|
+
function exactKeys3(value, required3, optional = []) {
|
|
3279
|
+
return required3.every((key) => Object.hasOwn(value, key)) && Object.keys(value).every((key) => required3.includes(key) || optional.includes(key));
|
|
3296
3280
|
}
|
|
3297
3281
|
function tokenList(value, field2) {
|
|
3298
3282
|
if (!Array.isArray(value) || value.some((token) => !Number.isSafeInteger(token) || token < 0)) throw new TypeError(`${field2} is invalid`);
|
|
@@ -3560,10 +3544,42 @@ function sandboxEgressHostMatches(pattern, hostname) {
|
|
|
3560
3544
|
const host2 = hostname.toLowerCase().replace(/\.$/u, "");
|
|
3561
3545
|
return pattern.startsWith("*.") ? host2 === pattern.slice(2) || host2.endsWith(pattern.slice(1)) : host2 === pattern;
|
|
3562
3546
|
}
|
|
3547
|
+
function sandboxEgressCredentialRuleFor(rules, url) {
|
|
3548
|
+
const target = typeof url === "string" ? new URL(url) : url;
|
|
3549
|
+
return rules.find((rule) => rule.hosts.some((pattern) => sandboxEgressHostMatches(pattern, target.hostname)) && (!rule.paths || rule.paths.some((path) => target.pathname === path || target.pathname.startsWith(`${path}/`))));
|
|
3550
|
+
}
|
|
3563
3551
|
function host(value) {
|
|
3564
3552
|
const [normalized] = normalizeSandboxDomains([value]);
|
|
3565
3553
|
return normalized;
|
|
3566
3554
|
}
|
|
3555
|
+
var SPACE_OR_CONTROL = /[\s\u0000-\u001f\u007f]/u;
|
|
3556
|
+
function paths(value) {
|
|
3557
|
+
if (!Array.isArray(value) || value.length === 0 || value.length > SANDBOX_EGRESS_LIMITS.hostsPerRule) {
|
|
3558
|
+
throw new TypeError("sandbox egress Credential paths are invalid");
|
|
3559
|
+
}
|
|
3560
|
+
return [...new Set(value.map((raw) => {
|
|
3561
|
+
if (typeof raw !== "string" || !raw.startsWith("/") || /[%?#\\]/u.test(raw) || SPACE_OR_CONTROL.test(raw)) {
|
|
3562
|
+
throw new TypeError("sandbox egress Credential path is invalid");
|
|
3563
|
+
}
|
|
3564
|
+
const path = raw.length > 1 && raw.endsWith("/") ? raw.slice(0, -1) : raw;
|
|
3565
|
+
if (path.slice(1).split("/").some((segment) => segment === "" || segment === "." || segment === "..")) {
|
|
3566
|
+
throw new TypeError("sandbox egress Credential path is invalid");
|
|
3567
|
+
}
|
|
3568
|
+
return path;
|
|
3569
|
+
}))].sort();
|
|
3570
|
+
}
|
|
3571
|
+
function gitRefName(ref) {
|
|
3572
|
+
return ref.length > 0 && !ref.includes("..") && !ref.includes("//") && !ref.includes("@{") && !/[~^:?\[\\*]/u.test(ref) && !SPACE_OR_CONTROL.test(ref) && !ref.endsWith("/") && !ref.endsWith(".") && ref.split("/").every((component) => !component.startsWith(".") && !component.endsWith(".lock"));
|
|
3573
|
+
}
|
|
3574
|
+
function pushRefs(value) {
|
|
3575
|
+
if (!Array.isArray(value) || value.length > SANDBOX_EGRESS_LIMITS.hostsPerRule) throw new TypeError("sandbox egress Credential push refs are invalid");
|
|
3576
|
+
return [...new Set(value.map((raw) => {
|
|
3577
|
+
if (typeof raw !== "string" || !raw.startsWith("refs/") || !gitRefName(raw.endsWith("/*") ? raw.slice(0, -2) : raw)) {
|
|
3578
|
+
throw new TypeError("sandbox egress Credential push ref is invalid");
|
|
3579
|
+
}
|
|
3580
|
+
return raw;
|
|
3581
|
+
}))].sort();
|
|
3582
|
+
}
|
|
3567
3583
|
function normalizeSandboxEgressPolicy(value) {
|
|
3568
3584
|
const input = object4(value);
|
|
3569
3585
|
if (!input || Object.keys(input).some((key) => key !== "rules" && key !== "default") || !Array.isArray(input.rules) || input.rules.length > SANDBOX_EGRESS_LIMITS.rules || input.default !== void 0 && input.default !== "allow" && input.default !== "deny") {
|
|
@@ -3589,7 +3605,7 @@ function normalizeSandboxEgressCredentialRules(value, options = {}) {
|
|
|
3589
3605
|
if (!Array.isArray(value) || value.length > SANDBOX_EGRESS_LIMITS.credentialRules) throw new TypeError("sandbox egress Credential rules are invalid");
|
|
3590
3606
|
return value.map((raw) => {
|
|
3591
3607
|
const rule = object4(raw);
|
|
3592
|
-
const allowed = ["hosts", "slot", "header", "value", "basic", ...options.bindings ? ["binding"] : [], ...options.uses ? ["use"] : []];
|
|
3608
|
+
const allowed = ["hosts", "paths", "slot", "header", "value", "basic", "push", ...options.bindings ? ["binding"] : [], ...options.uses ? ["use"] : []];
|
|
3593
3609
|
if (!rule || Object.keys(rule).some((key) => !allowed.includes(key)) || !Array.isArray(rule.hosts) || rule.hosts.length === 0 || rule.hosts.length > SANDBOX_EGRESS_LIMITS.hostsPerRule) throw new TypeError("sandbox egress Credential rule is invalid");
|
|
3594
3610
|
const sources = [rule.slot, rule.binding, rule.use].filter((source) => source !== void 0);
|
|
3595
3611
|
if (sources.length !== 1 || rule.slot !== void 0 && (typeof rule.slot !== "string" || !SLOT.test(rule.slot)) || rule.use !== void 0 && (typeof rule.use !== "string" || !USE.test(rule.use))) {
|
|
@@ -3603,11 +3619,13 @@ function normalizeSandboxEgressCredentialRules(value, options = {}) {
|
|
|
3603
3619
|
if (rule.basic !== void 0 && (!basic || Object.keys(basic).some((key) => key !== "username") || basic.username !== void 0 && (typeof basic.username !== "string" || !basic.username || basic.username.length > 128 || /[:\r\n\0]/u.test(basic.username)))) throw new TypeError("sandbox egress Credential basic auth is invalid");
|
|
3604
3620
|
return {
|
|
3605
3621
|
hosts: normalizeSandboxDomains(rule.hosts),
|
|
3622
|
+
...rule.paths !== void 0 ? { paths: paths(rule.paths) } : {},
|
|
3606
3623
|
...rule.slot !== void 0 ? { slot: rule.slot } : {},
|
|
3607
3624
|
...rule.binding !== void 0 ? { binding: resourceCredentialBinding(rule.binding) } : {},
|
|
3608
3625
|
...rule.use !== void 0 ? { use: rule.use } : {},
|
|
3609
3626
|
header: header.toLowerCase(),
|
|
3610
|
-
...basic ? { basic: basic.username === void 0 ? {} : { username: basic.username } } : { value: rule.value ?? "Bearer {value}" }
|
|
3627
|
+
...basic ? { basic: basic.username === void 0 ? {} : { username: basic.username } } : { value: rule.value ?? "Bearer {value}" },
|
|
3628
|
+
...rule.push !== void 0 ? { push: pushRefs(rule.push) } : {}
|
|
3611
3629
|
};
|
|
3612
3630
|
});
|
|
3613
3631
|
}
|
|
@@ -4030,8 +4048,8 @@ function gatewayPackageMetadata(value) {
|
|
|
4030
4048
|
...chatFormat2 ? { chatFormat: chatFormat2 } : {}
|
|
4031
4049
|
};
|
|
4032
4050
|
}
|
|
4033
|
-
function resolveGatewayEgress(
|
|
4034
|
-
const derived = (
|
|
4051
|
+
function resolveGatewayEgress(metadata2, config) {
|
|
4052
|
+
const derived = (metadata2.configEgress ?? []).map((binding) => {
|
|
4035
4053
|
let endpoint;
|
|
4036
4054
|
try {
|
|
4037
4055
|
endpoint = new URL(String(config[binding.urlProperty] ?? ""));
|
|
@@ -4043,7 +4061,7 @@ function resolveGatewayEgress(metadata3, config) {
|
|
|
4043
4061
|
}
|
|
4044
4062
|
return { operations: binding.operations, origin: endpoint.origin, pathExact: endpoint.pathname, methods: binding.methods };
|
|
4045
4063
|
});
|
|
4046
|
-
return integrationEgressPolicy({ rules: [...
|
|
4064
|
+
return integrationEgressPolicy({ rules: [...metadata2.egress.rules, ...derived] });
|
|
4047
4065
|
}
|
|
4048
4066
|
function gateway(definition) {
|
|
4049
4067
|
if (!/^[a-z0-9][a-z0-9._-]{0,127}$/u.test(definition.id) || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/u.test(definition.version) || !["cas", "web", "service", "mcp", "db", "browser", "sandbox-pool", "vault"].includes(definition.kind) || typeof definition.catalog !== "function" || typeof definition.invoke !== "function" || definition.reconcile !== void 0 && typeof definition.reconcile !== "function" || definition.cancel !== void 0 && typeof definition.cancel !== "function" || definition.release !== void 0 && typeof definition.release !== "function") {
|
|
@@ -4082,8 +4100,8 @@ function gateway(definition) {
|
|
|
4082
4100
|
if (gateway2.discovery) {
|
|
4083
4101
|
const property = properties[gateway2.discovery.resultConfigProperty];
|
|
4084
4102
|
if (!property || property.type !== "array") throw new TypeError("Gateway discovery result config property must be an array");
|
|
4085
|
-
const
|
|
4086
|
-
if (!
|
|
4103
|
+
const required3 = Array.isArray(configSchema.required) ? configSchema.required : [];
|
|
4104
|
+
if (!required3.includes(gateway2.discovery.resultConfigProperty)) {
|
|
4087
4105
|
throw new TypeError("Gateway discovery result config property must be required");
|
|
4088
4106
|
}
|
|
4089
4107
|
if (property.readOnly !== true) throw new TypeError("Gateway discovery result config property must be read-only");
|
|
@@ -4453,7 +4471,7 @@ function credentialProvider(definition) {
|
|
|
4453
4471
|
if (interaction && (typeof interaction.start !== "function" || typeof interaction.advance !== "function")) {
|
|
4454
4472
|
throw new TypeError("credential provider interaction is invalid");
|
|
4455
4473
|
}
|
|
4456
|
-
const
|
|
4474
|
+
const metadata2 = {
|
|
4457
4475
|
lifecycleVersion: 3,
|
|
4458
4476
|
displayName: definition.displayName,
|
|
4459
4477
|
description: definition.description,
|
|
@@ -4466,7 +4484,7 @@ function credentialProvider(definition) {
|
|
|
4466
4484
|
egress: integrationEgressPolicy(definition.egress),
|
|
4467
4485
|
...configEgress.length ? { configEgress } : {}
|
|
4468
4486
|
};
|
|
4469
|
-
return Object.freeze({ ...definition, mintRecovery, metadata:
|
|
4487
|
+
return Object.freeze({ ...definition, mintRecovery, metadata: metadata2 });
|
|
4470
4488
|
}
|
|
4471
4489
|
|
|
4472
4490
|
// packages/sdk/src/evaluation.ts
|
|
@@ -5375,6 +5393,7 @@ export {
|
|
|
5375
5393
|
resourceTools,
|
|
5376
5394
|
runLabels,
|
|
5377
5395
|
sandboxControls,
|
|
5396
|
+
sandboxEgressCredentialRuleFor,
|
|
5378
5397
|
sandboxEgressDecision,
|
|
5379
5398
|
sandboxEgressHostMatches,
|
|
5380
5399
|
sandboxLimit,
|