@constal/sdk 6.2.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/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",
@@ -400,45 +236,477 @@ function validateJsonSchema(value, schema, path = "$") {
400
236
  if (typeof rule.maxLength === "number" && value.length > rule.maxLength) return `${path} is too long`;
401
237
  if (typeof rule.pattern === "string" && !new RegExp(rule.pattern, "u").test(value)) return `${path} does not match the required pattern`;
402
238
  }
403
- if (typeof value === "number") {
404
- if (typeof rule.minimum === "number" && value < rule.minimum) return `${path} is below minimum`;
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`;
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;
672
+ }
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));
678
+ }
679
+ if ("bytes" in spec) {
680
+ return cutByWeight(rows, spec.bytes, (row) => encoder2.encode(canonicalJson(row)).byteLength, true);
409
681
  }
410
- if (value && typeof value === "object" && !Array.isArray(value)) {
411
- const record14 = value;
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
- if (Array.isArray(value)) {
430
- if (typeof rule.minItems === "number" && value.length < rule.minItems) return `${path} has too few items`;
431
- if (typeof rule.maxItems === "number" && value.length > rule.maxItems) return `${path} has too many items`;
432
- if (rule.items) for (const [index, item] of value.entries()) {
433
- const error = validateJsonSchema(item, rule.items, `${path}[${index}]`);
434
- if (error) return error;
435
- }
436
- if (rule.uniqueItems === true) {
437
- const values = value.map(canonicalJson);
438
- if (new Set(values).size !== values.length) return `${path} must contain unique items`;
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
- return null;
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 NAME = /^[A-Za-z0-9](?:[-_.A-Za-z0-9]{0,61}[A-Za-z0-9])?$/u;
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 NAME.test(value);
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 && NAME.test(name) && prefix.split(".").every((part) => DNS_LABEL.test(part));
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 === "" || NAME.test(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);
@@ -568,7 +836,9 @@ var RESOURCE_KINDS = [
568
836
  "db",
569
837
  "browser",
570
838
  "sandbox-pool",
571
- "vault"
839
+ "vault",
840
+ "skills",
841
+ "system"
572
842
  ];
573
843
  var PLATFORM_ADDRESS_KINDS = [
574
844
  "analytics",
@@ -583,9 +853,9 @@ var PLATFORM_ADDRESS_KINDS = [
583
853
  "artifact",
584
854
  "deployment"
585
855
  ];
586
- 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"];
587
857
  var POLICY_TARGET_KINDS = [...RESOURCE_KINDS, ...PLATFORM_ADDRESS_KINDS];
588
- function resolveBindingOwner(scope2, context, required2 = true) {
858
+ function resolveBindingOwner(scope2, context, required3 = true) {
589
859
  bindingOwnerScope(scope2);
590
860
  if (!SEGMENT.test(context.environment) || !SEGMENT.test(context.tenant)) throw new TypeError("Binding owner context is invalid");
591
861
  for (const kind of ["principal", "customer"]) {
@@ -598,7 +868,7 @@ function resolveBindingOwner(scope2, context, required2 = true) {
598
868
  if (scope2 === "tenant") return { kind: "tenant", tenant: context.tenant };
599
869
  const name = scope2 === "principal" ? context.principal : context.customer;
600
870
  if (!name) {
601
- if (!required2) return null;
871
+ if (!required3) return null;
602
872
  throw new TypeError(`A ${scope2} is required for this binding`);
603
873
  }
604
874
  const parts = parseResourceName(name);
@@ -611,13 +881,13 @@ function agentSetupRequirements(value, options = {}) {
611
881
  if (!Array.isArray(value) || value.length < 1) throw new TypeError("Agent setup requirements are invalid");
612
882
  const requirements = value.map((raw) => {
613
883
  const item = record2(raw);
614
- if (!item || typeof item.id !== "string" || !NAME2.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))) {
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))) {
615
885
  throw new TypeError("Agent setup requirement is invalid");
616
886
  }
617
887
  const selection = resourceSelector({ resourceKind: item.resourceKind, selector: item.selector === void 0 ? {} : item.selector }, RESOURCE_KINDS);
618
888
  if (item.resourceKind === "credential") {
619
889
  const binding = record2(item.binding);
620
- if (!binding || typeof binding.key !== "string" || !NAME2.test(binding.key) || Object.keys(binding).some((key) => key !== "key" && key !== "owner")) {
890
+ if (!binding || typeof binding.key !== "string" || !NAME3.test(binding.key) || Object.keys(binding).some((key) => key !== "key" && key !== "owner")) {
621
891
  throw new TypeError("Credential setup requires one binding key and an explicit owner scope");
622
892
  }
623
893
  const owner = binding.owner === void 0 && options.allowLegacyTenantOwner ? "tenant" : binding.owner;
@@ -638,7 +908,7 @@ function agentSetupMetadata(value, options = {}) {
638
908
  if (source && Object.keys(source).length === 1 && source.requirements !== void 0) {
639
909
  return { requirements: agentSetupRequirements(source.requirements, options) };
640
910
  }
641
- if (!source || source.protocol !== "constal.setup.v1" || typeof source.agent !== "string" || !NAME2.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))) {
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))) {
642
912
  throw new TypeError("Agent setup metadata is invalid");
643
913
  }
644
914
  return source;
@@ -762,8 +1032,8 @@ var UI_RESOURCE_BOUNDS = Object.freeze({
762
1032
  var ACTION_PATTERN = /^[a-z][a-z0-9-]{0,63}:[a-z][a-z0-9-]{0,63}$/u;
763
1033
  var SEGMENT = /^[a-z0-9][a-z0-9._-]{0,127}$/u;
764
1034
  var PATH = /^[A-Za-z0-9._~/%-]{1,512}$/u;
765
- var NAME2 = /^[a-z0-9][a-z0-9._-]{0,127}$/u;
766
- var OPERATION = /^[A-Za-z][A-Za-z0-9._-]{0,127}$/u;
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;
767
1037
  var VERSION2 = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/u;
768
1038
  var HASH = /^[a-f0-9]{64}$/u;
769
1039
  var KINDS = /* @__PURE__ */ new Set([...RESOURCE_KINDS, ...PLATFORM_ADDRESS_KINDS]);
@@ -778,7 +1048,7 @@ var RESOURCE_CREDENTIAL_BINDING_SCHEMA = {
778
1048
  additionalProperties: false,
779
1049
  properties: {
780
1050
  kind: { const: "scoped" },
781
- key: { type: "string", pattern: NAME2.source },
1051
+ key: { type: "string", pattern: NAME3.source },
782
1052
  owner: { enum: ["tenant", "customer", "principal"] },
783
1053
  required: { type: "boolean" }
784
1054
  }
@@ -789,17 +1059,17 @@ function record2(value) {
789
1059
  return value && typeof value === "object" && !Array.isArray(value) ? value : null;
790
1060
  }
791
1061
  function scopedBindingKey(value) {
792
- if (typeof value !== "string" || !NAME2.test(value)) throw new TypeError("scoped binding key is invalid");
1062
+ if (typeof value !== "string" || !NAME3.test(value)) throw new TypeError("scoped binding key is invalid");
793
1063
  return value;
794
1064
  }
795
1065
  function resourceContractRef(value) {
796
1066
  const candidate = record2(value);
797
- if (!candidate || typeof candidate.id !== "string" || !NAME2.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");
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");
798
1068
  return candidate;
799
1069
  }
800
1070
  function capabilityContractRef(value) {
801
1071
  const candidate = record2(value);
802
- if (!candidate || typeof candidate.id !== "string" || !NAME2.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))) {
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))) {
803
1073
  throw new TypeError("capability contract reference is invalid");
804
1074
  }
805
1075
  return candidate;
@@ -830,7 +1100,7 @@ function modelGatewayBinding(value) {
830
1100
  throw new TypeError("fixed Model Gateway binding is invalid");
831
1101
  }
832
1102
  const parts = parseResourceName(resource.crn);
833
- 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") {
834
1104
  throw new TypeError("Model Gateway must reference a Connection Resource");
835
1105
  }
836
1106
  capabilityContractRef(candidate.contract);
@@ -856,7 +1126,7 @@ function memoryStoreBinding(value) {
856
1126
  throw new TypeError("fixed Memory Store binding is invalid");
857
1127
  }
858
1128
  const parts = parseResourceName(resource.crn);
859
- 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") {
860
1130
  throw new TypeError("Memory Store must reference a Connection Resource");
861
1131
  }
862
1132
  capabilityContractRef(candidate.contract);
@@ -903,7 +1173,7 @@ function invocationCredentialUses(value) {
903
1173
  const result = {};
904
1174
  for (const [slot, raw] of Object.entries(source).sort(([left], [right]) => left.localeCompare(right))) {
905
1175
  const use = record2(raw), consumer = record2(use?.consumer);
906
- if (!NAME2.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");
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");
907
1177
  result[slot] = { binding: resourceCredentialBinding(use.binding), consumer };
908
1178
  }
909
1179
  return result;
@@ -1056,7 +1326,7 @@ function modelAdvertisedPricing(value) {
1056
1326
  return candidate;
1057
1327
  }
1058
1328
  function resourceNeed(need) {
1059
- if (!NAME2.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) => !OPERATION.test(op)))) throw new TypeError("resource need is invalid");
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");
1060
1330
  return need;
1061
1331
  }
1062
1332
  function ipv4(value) {
@@ -1253,12 +1523,12 @@ function authProvider(definition) {
1253
1523
  }
1254
1524
 
1255
1525
  // packages/sdk/src/channel.ts
1256
- function required(value, path) {
1526
+ function required2(value, path) {
1257
1527
  if (typeof value !== "string" || value.trim() === "") throw new TypeError(`${path} must be a non-empty string`);
1258
1528
  }
1259
1529
  function executable(value, path) {
1260
- required(value.id, `${path}.id`);
1261
- required(value.version, `${path}.version`);
1530
+ required2(value.id, `${path}.id`);
1531
+ required2(value.version, `${path}.version`);
1262
1532
  }
1263
1533
  function channel(definition) {
1264
1534
  executable(definition, "channel");
@@ -1291,8 +1561,8 @@ function object(value, message2) {
1291
1561
  if (!value || typeof value !== "object" || Array.isArray(value)) throw new TypeError(message2);
1292
1562
  return value;
1293
1563
  }
1294
- function exactKeys(value, allowed, required2) {
1295
- if (Object.keys(value).some((key) => !allowed.includes(key)) || required2.some((key) => !Object.hasOwn(value, key))) {
1564
+ function exactKeys(value, allowed, required3) {
1565
+ if (Object.keys(value).some((key) => !allowed.includes(key)) || required3.some((key) => !Object.hasOwn(value, key))) {
1296
1566
  throw new TypeError("UI bundle contains unsupported fields");
1297
1567
  }
1298
1568
  }
@@ -1405,7 +1675,7 @@ function uiBundle(value, execution) {
1405
1675
  if (moduleEntries.length < 1 || moduleEntries.length > UI_BUNDLE_BOUNDS.maximumModules || assetEntries.length > UI_BUNDLE_BOUNDS.maximumAssets || !Object.hasOwn(modules, manifest2.runtime.entry)) {
1406
1676
  throw new TypeError("UI bundle file inventory is invalid");
1407
1677
  }
1408
- const paths = /* @__PURE__ */ new Set();
1678
+ const paths2 = /* @__PURE__ */ new Set();
1409
1679
  let expandedBytes = 0;
1410
1680
  const normalizedModules = {};
1411
1681
  for (const [rawPath, rawModule] of moduleEntries.sort(([left], [right]) => left.localeCompare(right))) {
@@ -1417,8 +1687,8 @@ function uiBundle(value, execution) {
1417
1687
  }
1418
1688
  if (module.type !== "esmodule" || typeof module.source !== "string" || SECRET.test(module.source)) throw new TypeError("UI module is invalid or contains secret material");
1419
1689
  const bytes = byteLength(module.source);
1420
- if (bytes > UI_BUNDLE_BOUNDS.maximumFileBytes || paths.has(path)) throw new TypeError("UI module path or size is invalid");
1421
- paths.add(path);
1690
+ if (bytes > UI_BUNDLE_BOUNDS.maximumFileBytes || paths2.has(path)) throw new TypeError("UI module path or size is invalid");
1691
+ paths2.add(path);
1422
1692
  expandedBytes += bytes;
1423
1693
  normalizedModules[path] = { type: "esmodule", source: module.source };
1424
1694
  }
@@ -1427,10 +1697,10 @@ function uiBundle(value, execution) {
1427
1697
  const path = safePath(rawPath, "UI asset path");
1428
1698
  const asset = object(rawAsset, "UI asset is invalid");
1429
1699
  exactKeys(asset, ["bodyBase64", "contentType"], ["bodyBase64", "contentType"]);
1430
- if (typeof asset.bodyBase64 !== "string" || !BASE64.test(asset.bodyBase64) || typeof asset.contentType !== "string" || !CONTENT_TYPE.test(asset.contentType) || paths.has(path)) throw new TypeError("UI asset is invalid");
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");
1431
1701
  const bytes = Math.floor(asset.bodyBase64.length * 3 / 4) - (asset.bodyBase64.endsWith("==") ? 2 : asset.bodyBase64.endsWith("=") ? 1 : 0);
1432
1702
  if (bytes > UI_BUNDLE_BOUNDS.maximumFileBytes) throw new TypeError("UI asset exceeds the file limit");
1433
- paths.add(path);
1703
+ paths2.add(path);
1434
1704
  expandedBytes += bytes;
1435
1705
  normalizedAssets[path] = { bodyBase64: asset.bodyBase64, contentType: asset.contentType };
1436
1706
  }
@@ -1806,9 +2076,9 @@ function setupScreenView(id2 = "setup-screen") {
1806
2076
  function credentialSetupState(requirement, scope2, inventory, binding) {
1807
2077
  const parsed = agentSetupRequirements([requirement])[0];
1808
2078
  if (parsed.resourceKind !== "credential") throw new TypeError("Credential setup requires a Credential requirement");
1809
- const required2 = parsed.optional !== true;
1810
- const owner = resolveBindingOwner(parsed.binding.owner, scope2, required2);
1811
- if (!owner) return { status: "missing", required: required2, credential: null, candidates: [] };
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: [] };
1812
2082
  const candidates = [...new Set(inventory.flatMap((candidate) => {
1813
2083
  if (candidate.available !== true) return [];
1814
2084
  try {
@@ -1827,7 +2097,7 @@ function credentialSetupState(requirement, scope2, inventory, binding) {
1827
2097
  return [];
1828
2098
  }
1829
2099
  }))].sort();
1830
- if (!binding) return { status: candidates.length ? "choose" : "missing", required: required2, credential: null, candidates };
2100
+ if (!binding) return { status: candidates.length ? "choose" : "missing", required: required3, credential: null, candidates };
1831
2101
  const revision = binding.revision;
1832
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)) {
1833
2103
  throw new TypeError("Saved Credential binding does not belong to this setup slot");
@@ -1839,7 +2109,7 @@ function credentialSetupState(requirement, scope2, inventory, binding) {
1839
2109
  const credential = revision.target.crn;
1840
2110
  return {
1841
2111
  status: binding.state === "enabled" && candidates.includes(credential) ? "ready" : "blocked",
1842
- required: required2,
2112
+ required: required3,
1843
2113
  credential,
1844
2114
  candidates
1845
2115
  };
@@ -2212,12 +2482,12 @@ function requiredString2(value, path, _maximum) {
2212
2482
  throw new TypeError(`${path} must be a non-empty string`);
2213
2483
  }
2214
2484
  }
2215
- function exactKeys2(value, allowed, required2, path) {
2216
- if (Object.keys(value).some((key) => !allowed.includes(key)) || required2.some((key) => !Object.hasOwn(value, 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))) {
2217
2487
  throw new TypeError(`${path} has invalid keys`);
2218
2488
  }
2219
2489
  }
2220
- function scalar(value) {
2490
+ function scalar2(value) {
2221
2491
  return value === null || typeof value === "string" || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value);
2222
2492
  }
2223
2493
  function validateGrant(grant, path) {
@@ -2248,7 +2518,7 @@ function validatePolicyConstraint(constraint, path = "constraint") {
2248
2518
  }
2249
2519
  if (constraint.kind === "context") {
2250
2520
  exactKeys2(source, ["kind", "equals"], ["kind", "equals"], path);
2251
- if (!record4(constraint.equals) || Object.keys(constraint.equals).length === 0 || Object.entries(constraint.equals).some(([key, value]) => !key || key.length > 256 || !scalar(value))) {
2521
+ if (!record4(constraint.equals) || Object.keys(constraint.equals).length === 0 || Object.entries(constraint.equals).some(([key, value]) => !key || key.length > 256 || !scalar2(value))) {
2252
2522
  throw new TypeError(`${path}.equals is invalid`);
2253
2523
  }
2254
2524
  return;
@@ -2261,9 +2531,9 @@ function validatePolicyConstraint(constraint, path = "constraint") {
2261
2531
  }
2262
2532
  throw new TypeError(`${path}.kind is invalid`);
2263
2533
  }
2264
- function validateConstraints(value, path, required2) {
2265
- if (value === void 0 && !required2) return [];
2266
- if (!Array.isArray(value) || required2 && value.length === 0) {
2534
+ function validateConstraints(value, path, required3) {
2535
+ if (value === void 0 && !required3) return [];
2536
+ if (!Array.isArray(value) || required3 && value.length === 0) {
2267
2537
  throw new TypeError(`${path} is invalid`);
2268
2538
  }
2269
2539
  value.forEach((constraint, index) => validatePolicyConstraint(constraint, `${path}[${index}]`));
@@ -2376,378 +2646,93 @@ function shareRequest(value) {
2376
2646
  if (Object.hasOwn(source, "actions")) {
2377
2647
  const actions2 = source.actions;
2378
2648
  if (!Array.isArray(actions2) || actions2.length === 0 || actions2.some((item) => !ACTIONS.includes(item))) {
2379
- throw new TypeError("Share actions must name read, evaluate or contribute");
2380
- }
2381
- terms.actions = ACTIONS.filter((item) => actions2.includes(item));
2382
- }
2383
- if (Object.hasOwn(source, "prices")) terms.prices = sharePrices(source.prices);
2384
- if (Object.hasOwn(source, "evaluation")) terms.evaluation = source.evaluation === null ? null : shareEvaluation(source.evaluation);
2385
- if (Object.hasOwn(source, "history")) {
2386
- const history = record5(source.history);
2387
- if (source.history !== null && (!history || Object.keys(history).some((key) => key !== "since") || !Number.isSafeInteger(history.since) || history.since <= 0)) {
2388
- throw new TypeError("Share history must be null or { since: a time in milliseconds }");
2389
- }
2390
- terms.history = history ? { since: history.since } : null;
2391
- }
2392
- if (Object.hasOwn(source, "expiresAt")) {
2393
- if (source.expiresAt !== null && (!Number.isSafeInteger(source.expiresAt) || source.expiresAt <= 0)) {
2394
- throw new TypeError("Share expiresAt must be null or a time in milliseconds");
2395
- }
2396
- terms.expiresAt = source.expiresAt;
2397
- }
2398
- return terms;
2399
- }
2400
- var NAME3 = /^[a-z0-9][a-z0-9._-]{0,127}$/u;
2401
- var HASH2 = /^[a-f0-9]{64}$/u;
2402
- var DECISIONS = ["accept", "request-changes", "reject"];
2403
- function contributionNote(value) {
2404
- if (typeof value !== "string" || new TextEncoder().encode(value).byteLength > 4096) throw new TypeError("note must be text of at most 4096 bytes");
2405
- return value;
2406
- }
2407
- function datasetPin(value, index) {
2408
- const pin = record5(value);
2409
- let kind = null;
2410
- try {
2411
- kind = typeof pin?.crn === "string" ? parseResourceName(pin.crn).kind : null;
2412
- } catch {
2413
- kind = null;
2414
- }
2415
- 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`);
2416
- return { crn: pin.crn, version: pin.version, hash: pin.hash };
2417
- }
2418
- function shareContributionRequest(value) {
2419
- const source = record5(value);
2420
- const unknown = source && Object.keys(source).find((key) => key !== "datasets" && key !== "evaluations" && key !== "note");
2421
- if (!source || unknown) throw new TypeError(unknown ? `Contribution field ${unknown} is not supported` : "Contribution request is invalid");
2422
- const terms = {};
2423
- if (Object.hasOwn(source, "datasets")) {
2424
- if (!Array.isArray(source.datasets) || source.datasets.length > 16) throw new TypeError("datasets must be a list of at most 16 Dataset versions");
2425
- terms.datasets = source.datasets.map(datasetPin);
2426
- }
2427
- if (Object.hasOwn(source, "evaluations")) {
2428
- const evaluations = source.evaluations;
2429
- if (!Array.isArray(evaluations) || evaluations.length > 16 || evaluations.some((item) => typeof item !== "string" || !NAME3.test(item))) {
2430
- throw new TypeError("evaluations must be a list of at most 16 evaluation ids");
2431
- }
2432
- terms.evaluations = evaluations;
2433
- }
2434
- if (Object.hasOwn(source, "note")) terms.note = contributionNote(source.note);
2435
- return terms;
2436
- }
2437
- function shareContributionReview(value) {
2438
- const source = record5(value);
2439
- const unknown = source && Object.keys(source).find((key) => !["decision", "note", "namespace", "targets"].includes(key));
2440
- if (!source || unknown) throw new TypeError(unknown ? `Review field ${unknown} is not supported` : "Review request is invalid");
2441
- if (!DECISIONS.includes(source.decision)) throw new TypeError("Review decision must be accept, request-changes or reject");
2442
- const review = { decision: source.decision };
2443
- if (Object.hasOwn(source, "note")) review.note = contributionNote(source.note);
2444
- if (review.decision !== "accept") {
2445
- if (Object.hasOwn(source, "namespace") || Object.hasOwn(source, "targets")) throw new TypeError("Only an accepting review names a namespace or targets");
2446
- return review;
2447
- }
2448
- if (Object.hasOwn(source, "namespace")) {
2449
- if (typeof source.namespace !== "string" || !NAME3.test(source.namespace)) throw new TypeError("Review namespace is invalid");
2450
- review.namespace = source.namespace;
2451
- }
2452
- if (Object.hasOwn(source, "targets")) {
2453
- const targets = source.targets;
2454
- if (!Array.isArray(targets) || targets.length > 16 || targets.some((item) => item !== null && (typeof item !== "string" || !NAME3.test(item)))) {
2455
- throw new TypeError("Review targets must be at most 16 Dataset ids or nulls");
2456
- }
2457
- review.targets = targets;
2458
- }
2459
- return review;
2460
- }
2461
-
2462
- // packages/sdk/src/table.ts
2463
- var identifier = { type: "string", pattern: "^[a-zA-Z_][a-zA-Z0-9_.-]{0,127}$", maxLength: 128 };
2464
- var tableName = { type: "string", pattern: "^[a-z0-9][a-z0-9._-]{0,127}$", maxLength: 128 };
2465
- var branchName = { type: "string", pattern: "^[a-z0-9][a-z0-9._/-]{0,127}$", maxLength: 128 };
2466
- var hash2 = { type: "string", pattern: "^[a-f0-9]{64}$" };
2467
- var scalar2 = { type: ["string", "number", "integer", "boolean", "null"] };
2468
- var TABLE_DESCRIBE_SCHEMA = {
2469
- type: "object",
2470
- required: ["table"],
2471
- additionalProperties: false,
2472
- properties: {
2473
- table: tableName,
2474
- branch: branchName,
2475
- snapshot: hash2,
2476
- stageId: hash2,
2477
- waitMs: { type: "integer", minimum: 0 }
2478
- }
2479
- };
2480
- var filterSchema = {
2481
- type: "object",
2482
- required: ["field", "op", "value"],
2483
- additionalProperties: false,
2484
- properties: {
2485
- field: identifier,
2486
- op: { type: "string", enum: ["eq", "ne", "gt", "gte", "lt", "lte", "in", "between"] },
2487
- value: { anyOf: [scalar2, { type: "array", minItems: 1, items: scalar2 }] }
2488
- }
2489
- };
2490
- var TABLE_QUERY_SCHEMA = {
2491
- type: "object",
2492
- required: ["table", "snapshot", "query"],
2493
- additionalProperties: false,
2494
- properties: {
2495
- table: tableName,
2496
- branch: branchName,
2497
- snapshot: hash2,
2498
- query: {
2499
- type: "object",
2500
- additionalProperties: false,
2501
- properties: {
2502
- select: { type: "array", uniqueItems: true, items: identifier },
2503
- where: { type: "array", items: filterSchema },
2504
- groupBy: { type: "array", uniqueItems: true, items: identifier },
2505
- aggregates: { type: "array", items: {
2506
- type: "object",
2507
- required: ["fn", "as"],
2508
- additionalProperties: false,
2509
- properties: {
2510
- fn: { type: "string", enum: ["count", "sum", "avg", "min", "max"] },
2511
- field: identifier,
2512
- as: identifier
2513
- }
2514
- } },
2515
- orderBy: { type: "array", items: {
2516
- type: "object",
2517
- required: ["field", "direction"],
2518
- additionalProperties: false,
2519
- properties: { field: identifier, direction: { type: "string", enum: ["asc", "desc"] } }
2520
- } },
2521
- limit: { type: "integer", minimum: 1 }
2522
- }
2523
- }
2524
- }
2525
- };
2526
- function validateStageOutputSpec(value, path = "$.output") {
2527
- if (!value || typeof value !== "object" || Array.isArray(value)) return `${path} must be an object`;
2528
- const output = value;
2529
- const extra = Object.keys(output).find((key) => key !== "schema" && key !== "sortOrder");
2530
- if (extra) return `${path}.${extra} is not allowed`;
2531
- if (!Object.hasOwn(output, "schema")) return `${path}.schema is required`;
2532
- const schemaError = validateJsonSchemaDefinition(output.schema, `${path}.schema`);
2533
- if (schemaError) return schemaError;
2534
- const sortOrder = output.sortOrder ?? [];
2535
- if (!Array.isArray(sortOrder)) return `${path}.sortOrder is invalid`;
2536
- const keys = /* @__PURE__ */ new Set();
2537
- for (const [index, raw] of sortOrder.entries()) {
2538
- if (!raw || typeof raw !== "object" || Array.isArray(raw)) return `${path}.sortOrder[${index}] is invalid`;
2539
- const field2 = raw;
2540
- 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)) {
2541
- return `${path}.sortOrder[${index}] is invalid`;
2542
- }
2543
- keys.add(field2.key);
2544
- }
2545
- return null;
2546
- }
2547
- function stageOutput(value) {
2548
- const error = validateStageOutputSpec(value);
2549
- if (error) throw new TypeError(error);
2550
- return value;
2551
- }
2552
- var tableDescribe = {
2553
- name: "table_describe",
2554
- version: "1",
2555
- description: "Inspect the schema and identity of one exact, queryable Table snapshot before querying it.",
2556
- schema: TABLE_DESCRIBE_SCHEMA,
2557
- maxEffect: "read-only",
2558
- needs: [{ binding: "table_catalog", kind: "service", ops: ["describe"] }],
2559
- async run(args, ctx) {
2560
- return ctx.invoke(ctx.resources.table_catalog, "describe", args);
2561
- }
2562
- };
2563
- var tableQuery = {
2564
- name: "table_query",
2565
- version: "1",
2566
- description: "Query one exact Table snapshot with bounded fields, filters, grouping, aggregates, ordering, and limit.",
2567
- schema: TABLE_QUERY_SCHEMA,
2568
- maxEffect: "read-only",
2569
- needs: [{ binding: "table_catalog", kind: "service", ops: ["query"] }],
2570
- async run(args, ctx) {
2571
- return ctx.invoke(ctx.resources.table_catalog, "query", args);
2649
+ throw new TypeError("Share actions must name read, evaluate or contribute");
2650
+ }
2651
+ terms.actions = ACTIONS.filter((item) => actions2.includes(item));
2572
2652
  }
2573
- };
2574
-
2575
- // packages/sdk/src/tools.ts
2576
- var NAME4 = /^[a-z0-9][a-z0-9._-]{0,127}$/u;
2577
- var OPERATION2 = /^[A-Za-z][A-Za-z0-9._-]{0,127}$/u;
2578
- function opTool(binding, op, override = {}) {
2579
- if (!NAME4.test(binding) || !OPERATION2.test(op)) throw new TypeError("opTool binding or operation is invalid");
2580
- const name = override.name ?? op.replaceAll(".", "_");
2581
- return {
2582
- name,
2583
- ...override.title ? { title: override.title } : {},
2584
- version: "catalog",
2585
- description: override.description ?? `Invoke ${op} on the bound ${binding} resource.`,
2586
- schema: override.schema ?? { type: "object", additionalProperties: false },
2587
- maxEffect: "read-only",
2588
- needs: [],
2589
- ...override.tier ? { tier: override.tier } : {},
2590
- ...override.once ? { once: override.once } : {},
2591
- ...override.guard ? { guard: override.guard } : {},
2592
- ...override.preview ? { preview: override.preview } : {},
2593
- catalog: { binding, op },
2594
- async run() {
2595
- throw new TypeError(`catalog Tool ${binding}#${op} was not resolved by deployment`);
2653
+ if (Object.hasOwn(source, "prices")) terms.prices = sharePrices(source.prices);
2654
+ if (Object.hasOwn(source, "evaluation")) terms.evaluation = source.evaluation === null ? null : shareEvaluation(source.evaluation);
2655
+ if (Object.hasOwn(source, "history")) {
2656
+ const history = record5(source.history);
2657
+ if (source.history !== null && (!history || Object.keys(history).some((key) => key !== "since") || !Number.isSafeInteger(history.since) || history.since <= 0)) {
2658
+ throw new TypeError("Share history must be null or { since: a time in milliseconds }");
2596
2659
  }
2597
- };
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");
2665
+ }
2666
+ terms.expiresAt = source.expiresAt;
2667
+ }
2668
+ return terms;
2598
2669
  }
2599
- function opTools(binding, ops = []) {
2600
- if (ops.length === 0) throw new TypeError("opTools requires pinned operation names at bundle construction");
2601
- return ops.map((op) => opTool(binding, op));
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");
2675
+ return value;
2602
2676
  }
2603
- async function boundResource(ctx, binding) {
2604
- const resource = await ctx.describeResource(binding);
2605
- if (!resource) throw new TypeError(`Resource is not bound: ${binding}`);
2606
- return resource;
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;
2684
+ }
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 };
2607
2687
  }
2608
- var resourceTools = {
2609
- resource_list: {
2610
- name: "resource_list",
2611
- version: "1",
2612
- maxEffect: "read-only",
2613
- needs: [],
2614
- description: "List the Resource bindings accepted by this Run. Inspect a binding with resource_describe to read its public operations.",
2615
- schema: { type: "object", properties: {}, additionalProperties: false },
2616
- run: (_args, ctx) => ctx.step("bound-resource-list", async () => Object.entries(ctx.resources).sort(([left], [right]) => left.localeCompare(right)).map(([binding, crn]) => ({ binding, crn })))
2617
- },
2618
- resource_describe: {
2619
- name: "resource_describe",
2620
- version: "1",
2621
- maxEffect: "read-only",
2622
- needs: [],
2623
- description: "Read a bound Resource's public operations, input/output schemas, and execution semantics. This does not connect or install it.",
2624
- schema: {
2625
- type: "object",
2626
- required: ["binding"],
2627
- additionalProperties: false,
2628
- properties: { binding: { type: "string", minLength: 1 } }
2629
- },
2630
- run: (args, ctx) => boundResource(ctx, args.binding)
2631
- },
2632
- resource_invoke: {
2633
- name: "resource_invoke",
2634
- version: "1",
2635
- maxEffect: "non-idempotent",
2636
- needs: [],
2637
- 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.",
2638
- schema: {
2639
- type: "object",
2640
- required: ["binding", "operation", "arguments"],
2641
- additionalProperties: false,
2642
- properties: { binding: { type: "string", minLength: 1 }, operation: { type: "string", minLength: 1 }, arguments: {} }
2643
- },
2644
- async run(args, ctx) {
2645
- const resource = await boundResource(ctx, args.binding);
2646
- const operation = resource.operations.find((candidate) => candidate.op === args.operation);
2647
- if (!operation) throw new TypeError(`Resource operation is not available: ${args.binding}#${args.operation}`);
2648
- 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");
2649
2701
  }
2702
+ terms.evaluations = evaluations;
2650
2703
  }
2651
- };
2652
- var WEB_FETCH_ARGUMENT_SCHEMA = {
2653
- type: "object",
2654
- required: ["url"],
2655
- additionalProperties: false,
2656
- properties: {
2657
- url: { type: "string", minLength: 1 },
2658
- accept: { type: "string" }
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;
2659
2717
  }
2660
- };
2661
- var WEB_SEARCH_ARGUMENT_SCHEMA = {
2662
- type: "object",
2663
- required: ["query"],
2664
- additionalProperties: false,
2665
- properties: {
2666
- query: {
2667
- type: "string",
2668
- minLength: 1,
2669
- description: "A self-contained description of the information to find."
2670
- },
2671
- searchQueries: {
2672
- type: "array",
2673
- minItems: 1,
2674
- uniqueItems: true,
2675
- description: "Optional concise keyword queries that narrow the search.",
2676
- items: { type: "string", minLength: 1 }
2677
- },
2678
- maximumResults: {
2679
- type: "integer",
2680
- minimum: 1,
2681
- description: "Maximum number of sources to return."
2682
- },
2683
- maximumCharacters: {
2684
- type: "integer",
2685
- minimum: 1,
2686
- description: "Maximum total excerpt characters to return."
2687
- },
2688
- includeDomains: {
2689
- type: "array",
2690
- uniqueItems: true,
2691
- description: "Optional domains to restrict results to.",
2692
- items: { type: "string", minLength: 1 }
2693
- },
2694
- excludeDomains: {
2695
- type: "array",
2696
- uniqueItems: true,
2697
- description: "Optional domains to omit.",
2698
- items: { type: "string", minLength: 1 }
2699
- },
2700
- afterDate: {
2701
- type: "string",
2702
- pattern: "^[0-9]{4}-[0-9]{2}-[0-9]{2}$",
2703
- description: "Optional earliest publication date in YYYY-MM-DD form."
2704
- }
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;
2705
2721
  }
2706
- };
2707
- var webFetch = opTool("web", "get", {
2708
- name: "web_fetch",
2709
- description: "Fetch an HTTPS resource through the bound governed web Resource.",
2710
- schema: WEB_FETCH_ARGUMENT_SCHEMA
2711
- });
2712
- var webSearch = opTool("search", "search", {
2713
- name: "web_search",
2714
- description: "Search the public web through the bound governed search Resource.",
2715
- schema: WEB_SEARCH_ARGUMENT_SCHEMA
2716
- });
2717
- var casTool = {
2718
- name: "cas",
2719
- version: "1",
2720
- description: "Store or load one content-addressed Agent artifact.",
2721
- schema: {
2722
- type: "object",
2723
- required: ["action"],
2724
- additionalProperties: false,
2725
- properties: {
2726
- action: { type: "string", enum: ["put", "get"] },
2727
- value: {},
2728
- ref: { type: "string", pattern: "^[a-f0-9]{64}$" }
2729
- }
2730
- },
2731
- maxEffect: "idempotent",
2732
- needs: [{ binding: "cas", kind: "cas", ops: ["put", "get"] }],
2733
- async run(args, ctx) {
2734
- const input = args && typeof args === "object" && !Array.isArray(args) ? args : {};
2735
- if (input.action === "put") {
2736
- if (!Object.hasOwn(input, "value")) throw new TypeError("cas put requires value");
2737
- return ctx.invoke(ctx.resources.cas, "put", { value: input.value });
2738
- }
2739
- if (input.action === "get") {
2740
- if (typeof input.ref !== "string") throw new TypeError("cas get requires ref");
2741
- 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");
2742
2726
  }
2743
- throw new TypeError("cas action must be put or get");
2727
+ review.targets = targets;
2744
2728
  }
2745
- };
2729
+ return review;
2730
+ }
2746
2731
 
2747
2732
  // packages/sdk/src/memory.ts
2748
2733
  var id = { type: "string", pattern: "^[A-Za-z0-9._~-]{1,256}$", maxLength: 256 };
2749
2734
  var content = { type: "string", minLength: 1 };
2750
- var metadata2 = { type: "object" };
2735
+ var metadata = { type: "object" };
2751
2736
  var scope = { type: "string", pattern: "^[a-f0-9]{64}$", maxLength: 64 };
2752
2737
  var record6 = {
2753
2738
  type: "object",
@@ -2756,7 +2741,7 @@ var record6 = {
2756
2741
  properties: {
2757
2742
  id,
2758
2743
  content,
2759
- metadata: metadata2,
2744
+ metadata,
2760
2745
  createdAt: { type: "integer", minimum: 0 },
2761
2746
  updatedAt: { type: "integer", minimum: 0 },
2762
2747
  expiresAt: { anyOf: [{ type: "integer", minimum: 0 }, { type: "null" }] }
@@ -2766,7 +2751,7 @@ var MEMORY_OPERATION_DECLARATIONS = [
2766
2751
  {
2767
2752
  op: "remember",
2768
2753
  description: "Persist or replace one record in the invocation's authenticated Memory partition.",
2769
- schema: { type: "object", required: ["content"], additionalProperties: false, properties: { id, content, metadata: metadata2, scope } },
2754
+ schema: { type: "object", required: ["content"], additionalProperties: false, properties: { id, content, metadata, scope } },
2770
2755
  resultSchema: record6,
2771
2756
  effect: "idempotent",
2772
2757
  recovery: { kind: "idempotency-key" },
@@ -2875,8 +2860,8 @@ function integrationEgressPolicy(value) {
2875
2860
  }
2876
2861
  const rules = source.rules.map((raw) => {
2877
2862
  const rule = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : null;
2878
- const paths = Number(rule?.pathPrefix !== void 0) + Number(rule?.pathExact !== void 0);
2879
- 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" || paths !== 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))) {
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))) {
2880
2865
  throw new TypeError("integration egress rule is invalid");
2881
2866
  }
2882
2867
  let origin;
@@ -3290,8 +3275,8 @@ var NotAppendOnly = class extends Error {
3290
3275
  function record8(value) {
3291
3276
  return value && typeof value === "object" && !Array.isArray(value) ? value : null;
3292
3277
  }
3293
- function exactKeys3(value, required2, optional = []) {
3294
- return required2.every((key) => Object.hasOwn(value, key)) && Object.keys(value).every((key) => required2.includes(key) || optional.includes(key));
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));
3295
3280
  }
3296
3281
  function tokenList(value, field2) {
3297
3282
  if (!Array.isArray(value) || value.some((token) => !Number.isSafeInteger(token) || token < 0)) throw new TypeError(`${field2} is invalid`);
@@ -3559,10 +3544,42 @@ function sandboxEgressHostMatches(pattern, hostname) {
3559
3544
  const host2 = hostname.toLowerCase().replace(/\.$/u, "");
3560
3545
  return pattern.startsWith("*.") ? host2 === pattern.slice(2) || host2.endsWith(pattern.slice(1)) : host2 === pattern;
3561
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
+ }
3562
3551
  function host(value) {
3563
3552
  const [normalized] = normalizeSandboxDomains([value]);
3564
3553
  return normalized;
3565
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
+ }
3566
3583
  function normalizeSandboxEgressPolicy(value) {
3567
3584
  const input = object4(value);
3568
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") {
@@ -3588,7 +3605,7 @@ function normalizeSandboxEgressCredentialRules(value, options = {}) {
3588
3605
  if (!Array.isArray(value) || value.length > SANDBOX_EGRESS_LIMITS.credentialRules) throw new TypeError("sandbox egress Credential rules are invalid");
3589
3606
  return value.map((raw) => {
3590
3607
  const rule = object4(raw);
3591
- 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"] : []];
3592
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");
3593
3610
  const sources = [rule.slot, rule.binding, rule.use].filter((source) => source !== void 0);
3594
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))) {
@@ -3602,11 +3619,13 @@ function normalizeSandboxEgressCredentialRules(value, options = {}) {
3602
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");
3603
3620
  return {
3604
3621
  hosts: normalizeSandboxDomains(rule.hosts),
3622
+ ...rule.paths !== void 0 ? { paths: paths(rule.paths) } : {},
3605
3623
  ...rule.slot !== void 0 ? { slot: rule.slot } : {},
3606
3624
  ...rule.binding !== void 0 ? { binding: resourceCredentialBinding(rule.binding) } : {},
3607
3625
  ...rule.use !== void 0 ? { use: rule.use } : {},
3608
3626
  header: header.toLowerCase(),
3609
- ...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) } : {}
3610
3629
  };
3611
3630
  });
3612
3631
  }
@@ -4029,8 +4048,8 @@ function gatewayPackageMetadata(value) {
4029
4048
  ...chatFormat2 ? { chatFormat: chatFormat2 } : {}
4030
4049
  };
4031
4050
  }
4032
- function resolveGatewayEgress(metadata3, config) {
4033
- const derived = (metadata3.configEgress ?? []).map((binding) => {
4051
+ function resolveGatewayEgress(metadata2, config) {
4052
+ const derived = (metadata2.configEgress ?? []).map((binding) => {
4034
4053
  let endpoint;
4035
4054
  try {
4036
4055
  endpoint = new URL(String(config[binding.urlProperty] ?? ""));
@@ -4042,7 +4061,7 @@ function resolveGatewayEgress(metadata3, config) {
4042
4061
  }
4043
4062
  return { operations: binding.operations, origin: endpoint.origin, pathExact: endpoint.pathname, methods: binding.methods };
4044
4063
  });
4045
- return integrationEgressPolicy({ rules: [...metadata3.egress.rules, ...derived] });
4064
+ return integrationEgressPolicy({ rules: [...metadata2.egress.rules, ...derived] });
4046
4065
  }
4047
4066
  function gateway(definition) {
4048
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") {
@@ -4081,8 +4100,8 @@ function gateway(definition) {
4081
4100
  if (gateway2.discovery) {
4082
4101
  const property = properties[gateway2.discovery.resultConfigProperty];
4083
4102
  if (!property || property.type !== "array") throw new TypeError("Gateway discovery result config property must be an array");
4084
- const required2 = Array.isArray(configSchema.required) ? configSchema.required : [];
4085
- if (!required2.includes(gateway2.discovery.resultConfigProperty)) {
4103
+ const required3 = Array.isArray(configSchema.required) ? configSchema.required : [];
4104
+ if (!required3.includes(gateway2.discovery.resultConfigProperty)) {
4086
4105
  throw new TypeError("Gateway discovery result config property must be required");
4087
4106
  }
4088
4107
  if (property.readOnly !== true) throw new TypeError("Gateway discovery result config property must be read-only");
@@ -4236,6 +4255,22 @@ function credentialProviderConfigSchema(value) {
4236
4255
  function interactionRecord(value) {
4237
4256
  return value && typeof value === "object" && !Array.isArray(value) ? value : null;
4238
4257
  }
4258
+ var CONFIG_PROPERTY = /^[A-Za-z][A-Za-z0-9._-]{0,127}$/u;
4259
+ function credentialProviderConfigEgress(value) {
4260
+ if (value === void 0) return [];
4261
+ if (!Array.isArray(value)) throw new TypeError("credential provider config egress is invalid");
4262
+ return value.map((raw) => {
4263
+ const item = interactionRecord(raw);
4264
+ if (!item || !CONFIG_PROPERTY.test(String(item.urlProperty ?? "")) || !Array.isArray(item.operations) || item.operations.length === 0 || item.operations.some((operation) => typeof operation !== "string" || operation !== "*" && !/^[A-Za-z][A-Za-z0-9._-]{0,127}$/u.test(operation)) || !Array.isArray(item.methods) || item.methods.length === 0 || item.methods.some((method) => typeof method !== "string" || !/^(?:GET|POST|PUT|PATCH|DELETE)$/u.test(method)) || Object.keys(item).some((key) => !["urlProperty", "operations", "methods"].includes(key))) {
4265
+ throw new TypeError("credential provider config egress is invalid");
4266
+ }
4267
+ return {
4268
+ urlProperty: String(item.urlProperty),
4269
+ operations: [...new Set(item.operations)],
4270
+ methods: [...new Set(item.methods)]
4271
+ };
4272
+ });
4273
+ }
4239
4274
  function exactKeys4(value, allowed) {
4240
4275
  return Object.keys(value).every((key) => allowed.includes(key));
4241
4276
  }
@@ -4408,7 +4443,7 @@ function credentialProvider(definition) {
4408
4443
  }
4409
4444
  const setup = credentialProviderSetupMetadata(definition.setup, definition.credentialSlots);
4410
4445
  const interaction = definition.interaction ?? null;
4411
- if (interaction && (!Array.isArray(interaction.origins) || interaction.origins.length === 0 || new Set(interaction.origins).size !== interaction.origins.length || interaction.origins.some((origin) => {
4446
+ if (interaction && ("urlProperty" in interaction ? "origins" in interaction || !CONFIG_PROPERTY.test(String(interaction.urlProperty)) : !Array.isArray(interaction.origins) || interaction.origins.length === 0 || new Set(interaction.origins).size !== interaction.origins.length || interaction.origins.some((origin) => {
4412
4447
  try {
4413
4448
  const url = new URL(origin);
4414
4449
  return url.protocol !== "https:" || url.origin !== origin;
@@ -4418,6 +4453,17 @@ function credentialProvider(definition) {
4418
4453
  }))) {
4419
4454
  throw new TypeError("credential provider interaction origins are invalid");
4420
4455
  }
4456
+ const configEgress = credentialProviderConfigEgress(definition.configEgress);
4457
+ const properties = interactionRecord(definition.configSchema.properties) ?? {};
4458
+ for (const property of [
4459
+ ...interaction && "urlProperty" in interaction ? [interaction.urlProperty] : [],
4460
+ ...configEgress.map((binding) => binding.urlProperty)
4461
+ ]) {
4462
+ const declaration = interactionRecord(properties[property]);
4463
+ if (declaration?.type !== "string" || declaration.format !== "uri") {
4464
+ throw new TypeError(`credential provider config origin property must be a URI string: ${property}`);
4465
+ }
4466
+ }
4421
4467
  const mintRecovery = definition.mintRecovery ?? { kind: "idempotency-key" };
4422
4468
  if (!["idempotency-key", "outcome-unknown"].includes(mintRecovery.kind)) {
4423
4469
  throw new TypeError("credential provider mint recovery is invalid");
@@ -4425,7 +4471,7 @@ function credentialProvider(definition) {
4425
4471
  if (interaction && (typeof interaction.start !== "function" || typeof interaction.advance !== "function")) {
4426
4472
  throw new TypeError("credential provider interaction is invalid");
4427
4473
  }
4428
- const metadata3 = {
4474
+ const metadata2 = {
4429
4475
  lifecycleVersion: 3,
4430
4476
  displayName: definition.displayName,
4431
4477
  description: definition.description,
@@ -4433,11 +4479,12 @@ function credentialProvider(definition) {
4433
4479
  ...setup ? { setup } : {},
4434
4480
  credentialSlots: [...definition.credentialSlots].sort(),
4435
4481
  credentialConfigSchema: definition.credentialConfigSchema,
4436
- interaction: interaction ? { origins: [...interaction.origins].sort() } : null,
4482
+ interaction: !interaction ? null : "urlProperty" in interaction ? { urlProperty: interaction.urlProperty } : { origins: [...interaction.origins].sort() },
4437
4483
  rotation: definition.rotation,
4438
- egress: integrationEgressPolicy(definition.egress)
4484
+ egress: integrationEgressPolicy(definition.egress),
4485
+ ...configEgress.length ? { configEgress } : {}
4439
4486
  };
4440
- return Object.freeze({ ...definition, mintRecovery, metadata: metadata3 });
4487
+ return Object.freeze({ ...definition, mintRecovery, metadata: metadata2 });
4441
4488
  }
4442
4489
 
4443
4490
  // packages/sdk/src/evaluation.ts
@@ -4891,6 +4938,19 @@ async function scorerDraftHash(definition) {
4891
4938
  }
4892
4939
 
4893
4940
  // packages/sdk/src/judge.ts
4941
+ var GENERAL_QUALITY_JUDGE = {
4942
+ applies: "trajectory",
4943
+ scale: { min: 0, max: 1 },
4944
+ threshold: 0.5,
4945
+ rubric: {
4946
+ instructions: "You are judging one run of an AI agent: what it was asked (its input) and what it did (its reply, and when shown, its turns and the Tool calls they made with their results). Judge the outcome a person who asked would care about. A good run does what the input asked, gets it right, and makes no mistakes along the way. Any approach that achieves this is good: do not expect particular wording, a particular order of Tool calls, or one way of solving the task. When the input cannot be done as asked, a reply that says so clearly, or asks for what is missing, is good.",
4947
+ dimensions: {
4948
+ "did-what-was-asked": { instructions: "It addressed every part of the request, did not do something else instead, and did not stop before finishing." },
4949
+ correct: { instructions: "Every fact, number and claim in the reply is supported by the input or by what its Tool calls returned; nothing is made up." },
4950
+ "no-mistakes": { instructions: "No Tool call with wrong or invented arguments, no action the request did not call for, and no error it ignored or hid." }
4951
+ }
4952
+ }
4953
+ };
4894
4954
  function record13(value) {
4895
4955
  return value && typeof value === "object" && !Array.isArray(value) ? value : null;
4896
4956
  }
@@ -5179,6 +5239,7 @@ export {
5179
5239
  EVALUATION_LIMITS,
5180
5240
  EffectCeilingExceeded,
5181
5241
  EmptyJoin,
5242
+ GENERAL_QUALITY_JUDGE,
5182
5243
  GateExhausted,
5183
5244
  IntegrationRequestNotSent,
5184
5245
  LeaseLost,
@@ -5332,6 +5393,7 @@ export {
5332
5393
  resourceTools,
5333
5394
  runLabels,
5334
5395
  sandboxControls,
5396
+ sandboxEgressCredentialRuleFor,
5335
5397
  sandboxEgressDecision,
5336
5398
  sandboxEgressHostMatches,
5337
5399
  sandboxLimit,