agent-contracts 0.6.1 → 0.7.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/dist/index.d.ts CHANGED
@@ -571,6 +571,7 @@ declare const RenderTargetSchema: z.ZodObject<{
571
571
  type RenderTarget = z.infer<typeof RenderTargetSchema>;
572
572
  declare const AgentContractsConfigSchema: z.ZodObject<{
573
573
  dsl: z.ZodString;
574
+ vars: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
574
575
  renders: z.ZodArray<z.ZodObject<{
575
576
  template: z.ZodString;
576
577
  context: z.ZodEnum<{
@@ -599,6 +600,7 @@ interface ResolvedRenderTarget {
599
600
  }
600
601
  interface ResolvedConfig {
601
602
  dsl: string;
603
+ vars?: Record<string, string>;
602
604
  renders: ResolvedRenderTarget[];
603
605
  configDir: string;
604
606
  }
@@ -640,6 +642,12 @@ interface PerArtifactContext {
640
642
  artifact: Artifact & {
641
643
  id: string;
642
644
  };
645
+ relatedTools: Dsl["tools"];
646
+ relatedValidations: Dsl["validations"];
647
+ producerAgents: Dsl["agents"];
648
+ consumerAgents: Dsl["agents"];
649
+ editorAgents: Dsl["agents"];
650
+ createdInWorkflows: string[];
643
651
  dsl: Dsl;
644
652
  [key: string]: unknown;
645
653
  }
@@ -647,6 +655,9 @@ interface PerToolContext {
647
655
  tool: Tool & {
648
656
  id: string;
649
657
  };
658
+ invokableAgents: Dsl["agents"];
659
+ inputArtifactDetails: Dsl["artifacts"];
660
+ outputArtifactDetails: Dsl["artifacts"];
650
661
  dsl: Dsl;
651
662
  [key: string]: unknown;
652
663
  }
@@ -671,6 +682,13 @@ interface PerWorkflowContext {
671
682
  workflow: Workflow & {
672
683
  id: string;
673
684
  };
685
+ relatedAgents: Dsl["agents"];
686
+ relatedTasks: Array<(Task & Record<string, unknown>) & {
687
+ id: string;
688
+ }>;
689
+ relatedTools: Dsl["tools"];
690
+ relatedArtifacts: Dsl["artifacts"];
691
+ relatedValidations: Dsl["validations"];
674
692
  dsl: Dsl;
675
693
  [key: string]: unknown;
676
694
  }
package/dist/index.js CHANGED
@@ -60196,12 +60196,76 @@ function buildTaskContext(dsl, taskId) {
60196
60196
  function buildArtifactContext(dsl, artifactId) {
60197
60197
  const artifactDef = dsl.artifacts[artifactId];
60198
60198
  const artifact = { ...artifactDef, id: artifactId };
60199
- return { artifact, dsl };
60199
+ const relatedTools = {};
60200
+ for (const [id, tool] of Object.entries(dsl.tools)) {
60201
+ if (tool.input_artifacts.includes(artifactId) || tool.output_artifacts.includes(artifactId)) {
60202
+ relatedTools[id] = tool;
60203
+ }
60204
+ }
60205
+ const relatedValidations = {};
60206
+ for (const [id, val] of Object.entries(dsl.validations)) {
60207
+ if (val.target_artifact === artifactId) {
60208
+ relatedValidations[id] = val;
60209
+ }
60210
+ }
60211
+ const pickAgents = (ids) => {
60212
+ const result = {};
60213
+ for (const id of ids) {
60214
+ if (dsl.agents[id]) result[id] = dsl.agents[id];
60215
+ }
60216
+ return result;
60217
+ };
60218
+ const producerAgents = pickAgents(artifactDef.producers);
60219
+ const consumerAgents = pickAgents(artifactDef.consumers);
60220
+ const editorAgents = pickAgents(artifactDef.editors);
60221
+ const createdInWorkflows = [];
60222
+ for (const [_taskId, task] of Object.entries(dsl.tasks)) {
60223
+ if (createdInWorkflows.includes(task.workflow)) continue;
60224
+ const targetAgent = dsl.agents[task.target_agent];
60225
+ if (targetAgent?.can_write_artifacts.includes(artifactId)) {
60226
+ createdInWorkflows.push(task.workflow);
60227
+ continue;
60228
+ }
60229
+ const steps = task.execution_steps ?? [];
60230
+ for (const step of steps) {
60231
+ if (step["produces_artifact"] === artifactId) {
60232
+ createdInWorkflows.push(task.workflow);
60233
+ break;
60234
+ }
60235
+ }
60236
+ }
60237
+ return {
60238
+ artifact,
60239
+ relatedTools,
60240
+ relatedValidations,
60241
+ producerAgents,
60242
+ consumerAgents,
60243
+ editorAgents,
60244
+ createdInWorkflows,
60245
+ dsl
60246
+ };
60200
60247
  }
60201
60248
  function buildToolContext(dsl, toolId) {
60202
60249
  const toolDef = dsl.tools[toolId];
60203
60250
  const tool = { ...toolDef, id: toolId };
60204
- return { tool, dsl };
60251
+ const invokableAgents = {};
60252
+ for (const agentId of toolDef.invokable_by) {
60253
+ if (dsl.agents[agentId]) invokableAgents[agentId] = dsl.agents[agentId];
60254
+ }
60255
+ const pickArtifacts = (ids) => {
60256
+ const result = {};
60257
+ for (const id of ids) {
60258
+ if (dsl.artifacts[id]) result[id] = dsl.artifacts[id];
60259
+ }
60260
+ return result;
60261
+ };
60262
+ return {
60263
+ tool,
60264
+ invokableAgents,
60265
+ inputArtifactDetails: pickArtifacts(toolDef.input_artifacts),
60266
+ outputArtifactDetails: pickArtifacts(toolDef.output_artifacts),
60267
+ dsl
60268
+ };
60205
60269
  }
60206
60270
  function buildValidationContext(dsl, validationId) {
60207
60271
  const validationDef = dsl.validations[validationId];
@@ -60219,7 +60283,76 @@ function buildHandoffTypeContext(dsl, handoffTypeId) {
60219
60283
  function buildWorkflowContext(dsl, workflowId) {
60220
60284
  const wfDef = dsl.workflow[workflowId];
60221
60285
  const workflow = { ...wfDef, id: workflowId };
60222
- return { workflow, dsl };
60286
+ const relatedTasks = Object.entries(dsl.tasks).filter(([, t3]) => t3.workflow === workflowId).map(([id, t3]) => ({ ...t3, id }));
60287
+ const agentIds = /* @__PURE__ */ new Set();
60288
+ for (const task of relatedTasks) {
60289
+ agentIds.add(task.target_agent);
60290
+ for (const fromAgent of task.allowed_from_agents) {
60291
+ agentIds.add(fromAgent);
60292
+ }
60293
+ }
60294
+ for (const step of wfDef.steps) {
60295
+ if (step.type === "handoff" && step.from_agent) {
60296
+ agentIds.add(step.from_agent);
60297
+ }
60298
+ if (step.type === "validation") {
60299
+ const val = dsl.validations[step.validation];
60300
+ if (val?.executor_type === "agent" && val.executor) {
60301
+ agentIds.add(val.executor);
60302
+ }
60303
+ }
60304
+ }
60305
+ const relatedAgents = {};
60306
+ for (const id of agentIds) {
60307
+ if (dsl.agents[id]) relatedAgents[id] = dsl.agents[id];
60308
+ }
60309
+ const toolIds = /* @__PURE__ */ new Set();
60310
+ for (const id of agentIds) {
60311
+ const agent = dsl.agents[id];
60312
+ if (agent) {
60313
+ for (const toolId of agent.can_execute_tools) {
60314
+ toolIds.add(toolId);
60315
+ }
60316
+ }
60317
+ }
60318
+ const relatedTools = {};
60319
+ for (const id of toolIds) {
60320
+ if (dsl.tools[id]) relatedTools[id] = dsl.tools[id];
60321
+ }
60322
+ const artifactIds = /* @__PURE__ */ new Set();
60323
+ for (const task of relatedTasks) {
60324
+ for (const artId of task.input_artifacts) artifactIds.add(artId);
60325
+ }
60326
+ for (const id of agentIds) {
60327
+ const agent = dsl.agents[id];
60328
+ if (agent) {
60329
+ for (const artId of agent.can_read_artifacts) artifactIds.add(artId);
60330
+ for (const artId of agent.can_write_artifacts) artifactIds.add(artId);
60331
+ }
60332
+ }
60333
+ const relatedArtifacts = {};
60334
+ for (const id of artifactIds) {
60335
+ if (dsl.artifacts[id]) relatedArtifacts[id] = dsl.artifacts[id];
60336
+ }
60337
+ const validationIds = /* @__PURE__ */ new Set();
60338
+ for (const step of wfDef.steps) {
60339
+ if (step.type === "validation") {
60340
+ validationIds.add(step.validation);
60341
+ }
60342
+ }
60343
+ const relatedValidations = {};
60344
+ for (const id of validationIds) {
60345
+ if (dsl.validations[id]) relatedValidations[id] = dsl.validations[id];
60346
+ }
60347
+ return {
60348
+ workflow,
60349
+ relatedAgents,
60350
+ relatedTasks,
60351
+ relatedTools,
60352
+ relatedArtifacts,
60353
+ relatedValidations,
60354
+ dsl
60355
+ };
60223
60356
  }
60224
60357
  function buildPolicyContext(dsl, policyId) {
60225
60358
  const policyDef = dsl.policies[policyId];
@@ -60427,6 +60560,72 @@ function toYamlLines(obj, indent) {
60427
60560
  Handlebars.registerHelper("yamlBlock", (obj) => {
60428
60561
  return toYamlLines(obj, 0).join("\n");
60429
60562
  });
60563
+ Handlebars.registerHelper(
60564
+ "join",
60565
+ (arr, separator) => {
60566
+ if (!Array.isArray(arr)) return "";
60567
+ const sep = typeof separator === "string" ? separator : ", ";
60568
+ return arr.join(sep);
60569
+ }
60570
+ );
60571
+ Handlebars.registerHelper("contains", (arr, value) => {
60572
+ if (!Array.isArray(arr)) return false;
60573
+ return arr.includes(value);
60574
+ });
60575
+ Handlebars.registerHelper(
60576
+ "groupBy",
60577
+ (arr, key) => {
60578
+ if (!Array.isArray(arr)) return {};
60579
+ const result = {};
60580
+ for (const item of arr) {
60581
+ const k2 = String(
60582
+ item?.[key] ?? "undefined"
60583
+ );
60584
+ (result[k2] ??= []).push(item);
60585
+ }
60586
+ return result;
60587
+ }
60588
+ );
60589
+ Handlebars.registerHelper(
60590
+ "keys",
60591
+ (obj) => {
60592
+ if (!obj || typeof obj !== "object") return [];
60593
+ return Object.keys(obj);
60594
+ }
60595
+ );
60596
+ Handlebars.registerHelper(
60597
+ "values",
60598
+ (obj) => {
60599
+ if (!obj || typeof obj !== "object") return [];
60600
+ return Object.values(obj);
60601
+ }
60602
+ );
60603
+ Handlebars.registerHelper(
60604
+ "filterByField",
60605
+ (arr, field, value) => {
60606
+ if (!Array.isArray(arr)) return [];
60607
+ return arr.filter(
60608
+ (item) => item?.[field] === value
60609
+ );
60610
+ }
60611
+ );
60612
+ Handlebars.registerHelper("not", (value) => !value);
60613
+ Handlebars.registerHelper("or", (...args) => {
60614
+ const _options = args.pop();
60615
+ return args.some((a3) => !!a3);
60616
+ });
60617
+ Handlebars.registerHelper("and", (...args) => {
60618
+ const _options = args.pop();
60619
+ return args.every((a3) => !!a3);
60620
+ });
60621
+ Handlebars.registerHelper("gt", (a3, b3) => a3 > b3);
60622
+ Handlebars.registerHelper("gte", (a3, b3) => a3 >= b3);
60623
+ Handlebars.registerHelper("lt", (a3, b3) => a3 < b3);
60624
+ Handlebars.registerHelper("size", (obj) => {
60625
+ if (Array.isArray(obj)) return obj.length;
60626
+ if (obj && typeof obj === "object") return Object.keys(obj).length;
60627
+ return 0;
60628
+ });
60430
60629
  function getDslSection(dsl, context) {
60431
60630
  const sectionMap = {
60432
60631
  agent: dsl.agents,
@@ -60574,6 +60773,7 @@ var RenderTargetSchema = z14.object({
60574
60773
  );
60575
60774
  var AgentContractsConfigSchema = z14.object({
60576
60775
  dsl: z14.string(),
60776
+ vars: z14.record(z14.string(), z14.string()).optional(),
60577
60777
  renders: z14.array(RenderTargetSchema).min(1)
60578
60778
  });
60579
60779
 
@@ -60642,6 +60842,7 @@ ${issues}`,
60642
60842
  const config = result.data;
60643
60843
  return {
60644
60844
  dsl: resolve4(configDir, config.dsl),
60845
+ vars: config.vars,
60645
60846
  renders: config.renders.map((r3) => ({
60646
60847
  ...r3,
60647
60848
  template: resolve4(configDir, r3.template),