agent-contracts 0.30.2 → 0.30.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1476,6 +1476,10 @@ Templates can use these built-in helpers:
1476
1476
  | `notEmpty` | `{{#if (notEmpty obj)}}` | True when object has at least one key |
1477
1477
  | `inc` | `{{inc @index}}` | Increment number by 1 (for 1-based indexing) |
1478
1478
  | `yamlBlock` | `{{{yamlBlock obj}}}` | Render value as YAML-formatted text |
1479
+ | `jsonBlock` | `{{{jsonBlock obj}}}` | Render value as pretty-printed JSON |
1480
+ | `yamlFrontmatter` | `{{{yamlFrontmatter obj}}}` | Render value as YAML frontmatter (`---` delimiters) |
1481
+ | `handoffPayload` | `(handoffPayload handoffType)` | Resolve handoff payload (`example` or schema skeleton) |
1482
+ | `handoffEnvelope` | `(handoffEnvelope handoffType id=@key)` | Build `{ type, version, payload }` envelope object |
1479
1483
  | `lookupPayloadFields` | `{{#each (lookupPayloadFields schema)}}` | Extract schema field info (name, type, required, enum); resolves `allOf` internally |
1480
1484
  | `join` | `{{join arr ", "}}` | Join array elements with separator |
1481
1485
  | `contains` | `{{#if (contains arr "x")}}` | True when array includes value |
package/dist/cli.js CHANGED
@@ -55025,33 +55025,7 @@ function buildNavigationIndex(dsl) {
55025
55025
  };
55026
55026
  }
55027
55027
 
55028
- // src/renderer/renderer.ts
55029
- Handlebars.registerHelper("eq", (a3, b3) => a3 === b3);
55030
- Handlebars.registerHelper("notEmpty", (obj) => {
55031
- if (!obj || typeof obj !== "object") return false;
55032
- return Object.keys(obj).length > 0;
55033
- });
55034
- Handlebars.registerHelper("inc", (val) => val + 1);
55035
- Handlebars.registerHelper(
55036
- "lookupPayloadFields",
55037
- (schema) => {
55038
- const effective = resolveAllOf(schema ?? {});
55039
- const props = effective["properties"];
55040
- if (!props) return [];
55041
- const requiredSet = new Set(
55042
- effective["required"] ?? []
55043
- );
55044
- return Object.entries(props).map(([name, sub]) => {
55045
- const enumVals = sub["enum"];
55046
- return {
55047
- name,
55048
- type: sub["type"] ?? "any",
55049
- required: requiredSet.has(name),
55050
- enum: enumVals ? enumVals.join(" | ") : void 0
55051
- };
55052
- });
55053
- }
55054
- );
55028
+ // src/renderer/serialization.ts
55055
55029
  function toYamlLines(obj, indent) {
55056
55030
  const pad = " ".repeat(indent);
55057
55031
  if (obj === null || obj === void 0) return [`${pad}null`];
@@ -55118,9 +55092,146 @@ function toYamlLines(obj, indent) {
55118
55092
  }
55119
55093
  return [`${pad}${String(obj)}`];
55120
55094
  }
55121
- Handlebars.registerHelper("yamlBlock", (obj) => {
55095
+ function toYamlString(obj) {
55122
55096
  return toYamlLines(obj, 0).join("\n");
55097
+ }
55098
+ function toJsonString(obj, indent = 2) {
55099
+ return JSON.stringify(obj, null, indent);
55100
+ }
55101
+ function toYamlFrontmatter(obj) {
55102
+ const body = toYamlString(obj);
55103
+ if (!body) return "---\n---\n";
55104
+ return `---
55105
+ ${body}
55106
+ ---
55107
+ `;
55108
+ }
55109
+
55110
+ // src/renderer/handoff-payload.ts
55111
+ function resolveHandoffPayload(handoffType) {
55112
+ if (!handoffType) return {};
55113
+ if (handoffType.example && typeof handoffType.example === "object" && !Array.isArray(handoffType.example)) {
55114
+ return handoffType.example;
55115
+ }
55116
+ if (handoffType.schema && typeof handoffType.schema === "object") {
55117
+ return exampleFromSchema(handoffType.schema);
55118
+ }
55119
+ return {};
55120
+ }
55121
+ function buildHandoffEnvelope(handoffType, idOverride) {
55122
+ if (!handoffType) return {};
55123
+ const type = idOverride ?? handoffType.id;
55124
+ return {
55125
+ ...type ? { type } : {},
55126
+ ...handoffType.version !== void 0 ? { version: handoffType.version } : {},
55127
+ payload: resolveHandoffPayload(handoffType)
55128
+ };
55129
+ }
55130
+ function exampleFromSchema(schema) {
55131
+ const effective = resolveAllOf(schema);
55132
+ if (effective["$ref"] && !effective["properties"] && !effective["type"]) {
55133
+ return {};
55134
+ }
55135
+ return exampleFromJsonSchema(effective);
55136
+ }
55137
+ function exampleFromJsonSchema(schema) {
55138
+ const type = schema["type"];
55139
+ if (type === "object" || schema["properties"]) {
55140
+ return exampleFromObjectSchema(schema);
55141
+ }
55142
+ return {};
55143
+ }
55144
+ function exampleFromObjectSchema(schema) {
55145
+ const props = schema["properties"];
55146
+ if (!props) return {};
55147
+ const required = new Set(
55148
+ schema["required"] ?? []
55149
+ );
55150
+ const result = {};
55151
+ for (const [key, propSchema] of Object.entries(props)) {
55152
+ if (!required.has(key)) continue;
55153
+ result[key] = exampleFromPropertySchema(
55154
+ propSchema,
55155
+ key
55156
+ );
55157
+ }
55158
+ return result;
55159
+ }
55160
+ function exampleFromPropertySchema(schema, propName) {
55161
+ const effective = resolveAllOf(schema);
55162
+ if (effective["example"] !== void 0) return effective["example"];
55163
+ if (effective["const"] !== void 0) return effective["const"];
55164
+ const enumVals = effective["enum"];
55165
+ if (enumVals && enumVals.length > 0) return enumVals[0];
55166
+ const type = effective["type"];
55167
+ if (type === "string" || !type && effective["format"]) {
55168
+ return `<${propName}>`;
55169
+ }
55170
+ if (type === "integer") return 0;
55171
+ if (type === "number") return 0;
55172
+ if (type === "boolean") return false;
55173
+ if (type === "array") {
55174
+ const items = effective["items"];
55175
+ if (items && typeof items === "object") {
55176
+ return [exampleFromPropertySchema(items, "item")];
55177
+ }
55178
+ return [];
55179
+ }
55180
+ if (type === "object" || effective["properties"]) {
55181
+ return exampleFromObjectSchema(effective);
55182
+ }
55183
+ return null;
55184
+ }
55185
+
55186
+ // src/renderer/renderer.ts
55187
+ Handlebars.registerHelper("eq", (a3, b3) => a3 === b3);
55188
+ Handlebars.registerHelper("notEmpty", (obj) => {
55189
+ if (!obj || typeof obj !== "object") return false;
55190
+ return Object.keys(obj).length > 0;
55191
+ });
55192
+ Handlebars.registerHelper("inc", (val) => val + 1);
55193
+ Handlebars.registerHelper(
55194
+ "lookupPayloadFields",
55195
+ (schema) => {
55196
+ const effective = resolveAllOf(schema ?? {});
55197
+ const props = effective["properties"];
55198
+ if (!props) return [];
55199
+ const requiredSet = new Set(
55200
+ effective["required"] ?? []
55201
+ );
55202
+ return Object.entries(props).map(([name, sub]) => {
55203
+ const enumVals = sub["enum"];
55204
+ return {
55205
+ name,
55206
+ type: sub["type"] ?? "any",
55207
+ required: requiredSet.has(name),
55208
+ enum: enumVals ? enumVals.join(" | ") : void 0
55209
+ };
55210
+ });
55211
+ }
55212
+ );
55213
+ Handlebars.registerHelper("yamlBlock", (obj) => {
55214
+ return toYamlString(obj);
55215
+ });
55216
+ Handlebars.registerHelper("jsonBlock", (obj) => {
55217
+ return toJsonString(obj);
55218
+ });
55219
+ Handlebars.registerHelper("yamlFrontmatter", (obj) => {
55220
+ return toYamlFrontmatter(obj);
55123
55221
  });
55222
+ Handlebars.registerHelper(
55223
+ "handoffPayload",
55224
+ (handoffType) => {
55225
+ return resolveHandoffPayload(handoffType ?? void 0);
55226
+ }
55227
+ );
55228
+ Handlebars.registerHelper(
55229
+ "handoffEnvelope",
55230
+ (handoffType, options) => {
55231
+ const idOverride = typeof options?.hash?.id === "string" ? options.hash.id : void 0;
55232
+ return buildHandoffEnvelope(handoffType ?? void 0, idOverride);
55233
+ }
55234
+ );
55124
55235
  Handlebars.registerHelper(
55125
55236
  "join",
55126
55237
  (arr, separator) => {