@ekanos/sdk 0.17.0 → 0.19.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.
Files changed (61) hide show
  1. package/README.md +2 -2
  2. package/api-report.md +92 -1
  3. package/dist/components/base-activation-dialog.js +2 -2
  4. package/dist/components/base-activation-dialog.js.map +1 -1
  5. package/dist/components/base-activation-form.js +1 -1
  6. package/dist/components/base-activation-form.js.map +1 -1
  7. package/dist/components/base-marketplace-tile.js +1 -1
  8. package/dist/components/base-marketplace-tile.js.map +1 -1
  9. package/dist/components/oauth-activation-form.js +1 -1
  10. package/dist/components/oauth-activation-form.js.map +1 -1
  11. package/dist/components/widgets/ai-prompt-chip.js +3 -3
  12. package/dist/components/widgets/ai-prompt-chip.js.map +1 -1
  13. package/dist/components/widgets/widget-ask-bar.js +2 -2
  14. package/dist/components/widgets/widget-ask-bar.js.map +1 -1
  15. package/dist/components/widgets/widget-state-components.js +7 -7
  16. package/dist/components/widgets/widget-state-components.js.map +1 -1
  17. package/dist/components/widgets/widget.d.ts +2 -2
  18. package/dist/components/widgets/widget.js +30 -18
  19. package/dist/components/widgets/widget.js.map +1 -1
  20. package/dist/contract/derive-contract.d.ts +14 -0
  21. package/dist/contract/derive-contract.js +237 -0
  22. package/dist/contract/derive-contract.js.map +1 -0
  23. package/dist/contract/index.d.ts +8 -0
  24. package/dist/contract/index.js +9 -0
  25. package/dist/contract/index.js.map +1 -0
  26. package/dist/contract/synthesize-example.d.ts +6 -0
  27. package/dist/contract/synthesize-example.js +61 -0
  28. package/dist/contract/synthesize-example.js.map +1 -0
  29. package/dist/contract/to-json-schema.d.ts +19 -0
  30. package/dist/contract/to-json-schema.js +300 -0
  31. package/dist/contract/to-json-schema.js.map +1 -0
  32. package/dist/contract/types.d.ts +39 -0
  33. package/dist/contract/types.js +12 -0
  34. package/dist/contract/types.js.map +1 -0
  35. package/dist/experience/client.d.ts +55 -0
  36. package/dist/experience/client.js +125 -0
  37. package/dist/experience/client.js.map +1 -0
  38. package/dist/experience/define-experience.d.ts +107 -0
  39. package/dist/experience/define-experience.js +107 -0
  40. package/dist/experience/define-experience.js.map +1 -0
  41. package/dist/experience/index.d.ts +12 -0
  42. package/dist/experience/index.js +12 -0
  43. package/dist/experience/index.js.map +1 -0
  44. package/dist/experience/runtime.d.ts +54 -0
  45. package/dist/experience/runtime.js +2 -0
  46. package/dist/experience/runtime.js.map +1 -0
  47. package/dist/experience/server.d.ts +11 -0
  48. package/dist/experience/server.js +47 -0
  49. package/dist/experience/server.js.map +1 -0
  50. package/dist/experience/types.d.ts +76 -0
  51. package/dist/experience/types.js +2 -0
  52. package/dist/experience/types.js.map +1 -0
  53. package/dist/experience/workflow-template.d.ts +103 -0
  54. package/dist/experience/workflow-template.js +132 -0
  55. package/dist/experience/workflow-template.js.map +1 -0
  56. package/dist/types/workspace-target.d.ts +1 -1
  57. package/dist/types/workspace-target.js.map +1 -1
  58. package/eslint.design-preset.mjs +3 -2
  59. package/eslint.design-rules.mjs +288 -4
  60. package/eslint.experience-preset.mjs +85 -0
  61. package/package.json +53 -15
@@ -0,0 +1,14 @@
1
+ import { type Contract } from '@ekanos/integration-schema';
2
+ import { type DeriveContractOptions, type DeriveContractResult } from './types.js';
3
+ /**
4
+ * Derive and seal the contract artifact from a `defineIntegration` result.
5
+ * Non-throwing: returns diagnostics beside the contract (a contract that
6
+ * fails its own `verifyContract` is reported as error diagnostics).
7
+ */
8
+ export declare function analyzeContract(rawDefinition: unknown, options: DeriveContractOptions): DeriveContractResult;
9
+ /**
10
+ * `deriveContract(definition, { packageVersion, contractVersion, previous? })`:
11
+ * the sealed `Contract`; throws `ContractDerivationError` when an error
12
+ * diagnostic exists. Use `analyzeContract` to read warnings too.
13
+ */
14
+ export declare function deriveContract(definition: unknown, options: DeriveContractOptions): Contract;
@@ -0,0 +1,237 @@
1
+ import { compatLine, sealContract, validateAgainstSchema, verifyContract, } from '@ekanos/integration-schema';
2
+ import { synthesizeExample } from './synthesize-example.js';
3
+ import { toJsonSchema } from './to-json-schema.js';
4
+ import { ContractDerivationError, } from './types.js';
5
+ function isRecord(value) {
6
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
7
+ }
8
+ function asRecordOf(value) {
9
+ return isRecord(value) ? value : {};
10
+ }
11
+ function inferConnection(definition) {
12
+ var _a, _b, _c;
13
+ const declared = isRecord(definition.connection) ? definition.connection : {};
14
+ const oauth = isRecord(definition.oauth) ? definition.oauth : null;
15
+ const provider = oauth && isRecord(oauth.provider) ? oauth.provider : null;
16
+ const proposes = isRecord(definition.proposes) ? definition.proposes : {};
17
+ const auth = (_a = declared.auth) !== null && _a !== void 0 ? _a : (oauth ? 'oauth2' : 'none');
18
+ const scopes = (_b = declared.scopes) !== null && _b !== void 0 ? _b : (provider && Array.isArray(provider.scopes)
19
+ ? provider.scopes
20
+ : []);
21
+ const fromModel = proposes.credentialModel === 'user'
22
+ ? ['user']
23
+ : proposes.credentialModel === 'source'
24
+ ? ['source']
25
+ : proposes.scope === 'user'
26
+ ? ['user']
27
+ : ['team'];
28
+ const levels = (_c = declared.levels) !== null && _c !== void 0 ? _c : fromModel;
29
+ return { levels, auth, scopes };
30
+ }
31
+ function opaqueReasonFor(input, output) {
32
+ var _a, _b;
33
+ const parts = [];
34
+ if (input.opaque)
35
+ parts.push(`input: ${(_a = input.reason) !== null && _a !== void 0 ? _a : 'opaque'}`);
36
+ if (output.opaque)
37
+ parts.push(`output: ${(_b = output.reason) !== null && _b !== void 0 ? _b : 'opaque'}`);
38
+ return parts.length > 0 ? parts.join('; ') : undefined;
39
+ }
40
+ /**
41
+ * Derive and seal the contract artifact from a `defineIntegration` result.
42
+ * Non-throwing: returns diagnostics beside the contract (a contract that
43
+ * fails its own `verifyContract` is reported as error diagnostics).
44
+ */
45
+ export function analyzeContract(rawDefinition, options) {
46
+ var _a;
47
+ var _b, _c, _d, _e;
48
+ const definition = isRecord(rawDefinition) ? rawDefinition : {};
49
+ const diagnostics = [];
50
+ const line = compatLine(options.contractVersion);
51
+ const slug = String((_b = definition.slug) !== null && _b !== void 0 ? _b : '');
52
+ const proposes = isRecord(definition.proposes) ? definition.proposes : {};
53
+ const toolClassifications = asRecordOf(proposes.tools);
54
+ const actionClassifications = asRecordOf(proposes.actions);
55
+ const previousSince = new Map(((_c = (_a = options.previous) === null || _a === void 0 ? void 0 : _a.operations) !== null && _c !== void 0 ? _c : []).map((op) => [op.id, op.since]));
56
+ const classify = (key, declared, proposed) => {
57
+ var _a, _b, _c;
58
+ const effect = (_a = declared.effect) !== null && _a !== void 0 ? _a : proposed === null || proposed === void 0 ? void 0 : proposed.effect;
59
+ if (!effect) {
60
+ diagnostics.push({
61
+ rule: 'contract/effect-undeclared',
62
+ severity: 'warn',
63
+ operation: key,
64
+ message: 'no effect declared; treated as a write (fail safe).',
65
+ });
66
+ }
67
+ return {
68
+ effect: effect !== null && effect !== void 0 ? effect : 'write',
69
+ sensitivity: (_c = (_b = declared.sensitivity) !== null && _b !== void 0 ? _b : proposed === null || proposed === void 0 ? void 0 : proposed.sensitivity) !== null && _c !== void 0 ? _c : 'internal',
70
+ };
71
+ };
72
+ const build = (kind, name, parts) => {
73
+ var _a;
74
+ var _b, _c;
75
+ const key = `${kind}/${name}`;
76
+ const id = `${slug}@${line}/${kind}/${name}`;
77
+ if (typeof parts.description !== 'string' ||
78
+ parts.description.length === 0) {
79
+ diagnostics.push({
80
+ rule: 'contract/description-missing',
81
+ severity: 'error',
82
+ operation: key,
83
+ message: 'a description is required.',
84
+ });
85
+ }
86
+ let output;
87
+ if (parts.outputSchema === undefined) {
88
+ output = {
89
+ schema: {},
90
+ opaque: true,
91
+ reason: `the ${kind} declares no runtime output schema`,
92
+ };
93
+ diagnostics.push({
94
+ rule: 'contract/output-schema-missing',
95
+ severity: options.requireOutputSchemas ? 'error' : 'warn',
96
+ operation: key,
97
+ message: `no output schema; the output is opaque and an experience cannot bind to ${key}. Declare ${kind === 'tool' ? '`output`' : '`output`'} as a zod schema.`,
98
+ });
99
+ }
100
+ else {
101
+ output = toJsonSchema(parts.outputSchema, 'output');
102
+ if (output.opaque) {
103
+ diagnostics.push({
104
+ rule: 'contract/output-opaque',
105
+ severity: options.requireOutputSchemas ? 'error' : 'warn',
106
+ operation: key,
107
+ message: `output is opaque: ${output.reason}.`,
108
+ });
109
+ }
110
+ }
111
+ if (parts.input.opaque) {
112
+ diagnostics.push({
113
+ rule: 'contract/input-opaque',
114
+ severity: 'warn',
115
+ operation: key,
116
+ message: `input is opaque: ${parts.input.reason}.`,
117
+ });
118
+ }
119
+ let outputExample = (_b = parts.authoredExample) !== null && _b !== void 0 ? _b : (_a = options.examples) === null || _a === void 0 ? void 0 : _a[key];
120
+ if (outputExample === undefined && !output.opaque) {
121
+ if (parts.classification.effect === 'read') {
122
+ diagnostics.push({
123
+ rule: 'contract/example-missing',
124
+ severity: 'error',
125
+ operation: key,
126
+ message: 'a read operation needs an outputExample (author one or run `ekanos contract --record`).',
127
+ });
128
+ }
129
+ else {
130
+ outputExample = synthesizeExample(output.schema);
131
+ diagnostics.push({
132
+ rule: 'contract/example-synthesized',
133
+ severity: 'warn',
134
+ operation: key,
135
+ message: 'no outputExample; a placeholder was synthesized from the schema.',
136
+ });
137
+ }
138
+ }
139
+ if (outputExample !== undefined && !output.opaque) {
140
+ const problems = validateAgainstSchema(output.schema, outputExample);
141
+ if (problems.length > 0) {
142
+ diagnostics.push({
143
+ rule: 'contract/example-invalid',
144
+ severity: 'error',
145
+ operation: key,
146
+ message: `outputExample does not satisfy output: ${problems[0]}`,
147
+ });
148
+ }
149
+ }
150
+ const reason = opaqueReasonFor(parts.input, output);
151
+ const since = (_c = previousSince.get(id)) !== null && _c !== void 0 ? _c : options.packageVersion;
152
+ return Object.assign(Object.assign(Object.assign({ id,
153
+ kind,
154
+ name, description: typeof parts.description === 'string' ? parts.description : '', effect: parts.classification.effect, sensitivity: parts.classification.sensitivity, input: parts.input.schema, output: output.schema, opaque: { input: parts.input.opaque, output: output.opaque } }, (reason ? { opaqueReason: reason } : {})), (outputExample !== undefined && !output.opaque
155
+ ? { outputExample }
156
+ : {})), { since });
157
+ };
158
+ const operations = [];
159
+ for (const [name, raw] of Object.entries(asRecordOf(definition.actions))) {
160
+ const input = toJsonSchema(raw.input, 'input');
161
+ operations.push(build('action', name, {
162
+ description: raw.description,
163
+ input,
164
+ outputSchema: raw.output,
165
+ authoredExample: raw.outputExample,
166
+ classification: classify(`action/${name}`, {
167
+ effect: raw.effect,
168
+ sensitivity: raw.sensitivity,
169
+ }, actionClassifications[name]),
170
+ }));
171
+ }
172
+ const tools = Array.isArray(definition.tools)
173
+ ? definition.tools
174
+ : [];
175
+ for (const tool of tools) {
176
+ const name = String(tool.name);
177
+ const parameters = isRecord(tool.parameters)
178
+ ? tool.parameters
179
+ : { type: 'object', properties: {} };
180
+ operations.push(build('tool', name, {
181
+ description: tool.description,
182
+ input: { schema: parameters, opaque: false },
183
+ outputSchema: tool.output,
184
+ authoredExample: tool.outputExample,
185
+ classification: classify(`tool/${name}`, {}, toolClassifications[name]),
186
+ }));
187
+ }
188
+ const events = [];
189
+ for (const raw of Array.isArray(definition.agentEvents)
190
+ ? definition.agentEvents
191
+ : []) {
192
+ const converted = raw.payloadSchema === undefined
193
+ ? null
194
+ : toJsonSchema(raw.payloadSchema, 'output');
195
+ if (!converted || converted.opaque) {
196
+ diagnostics.push({
197
+ rule: 'contract/event-schema-missing',
198
+ severity: 'warn',
199
+ operation: String(raw.id),
200
+ message: `event payload is opaque${(converted === null || converted === void 0 ? void 0 : converted.reason) ? `: ${converted.reason}` : ''}.`,
201
+ });
202
+ }
203
+ events.push(Object.assign({ name: String(raw.id), payload: (_d = converted === null || converted === void 0 ? void 0 : converted.schema) !== null && _d !== void 0 ? _d : {}, opaque: (_e = converted === null || converted === void 0 ? void 0 : converted.opaque) !== null && _e !== void 0 ? _e : true }, (raw.examplePayload !== undefined
204
+ ? { payloadExample: raw.examplePayload }
205
+ : {})));
206
+ }
207
+ const contract = sealContract(Object.assign(Object.assign({ schemaVersion: 1, integration: slug, packageVersion: options.packageVersion, contractVersion: options.contractVersion, compatLine: line, connection: inferConnection(definition) }, (definition.health ? { health: true } : {})), { operations,
208
+ events }));
209
+ const { problems } = verifyContract(contract);
210
+ for (const problem of problems) {
211
+ // Example problems were already reported with a friendlier rule.
212
+ if (problem.rule === 'contract.output-example-invalid')
213
+ continue;
214
+ if (problem.rule === 'contract.output-example' &&
215
+ diagnostics.some((d) => { var _a; return d.rule === 'contract/example-missing' &&
216
+ d.operation === ((_a = problem.operation) === null || _a === void 0 ? void 0 : _a.replace(/^[^/]*\//, '')); })) {
217
+ continue;
218
+ }
219
+ diagnostics.push(Object.assign({ rule: problem.rule === 'contract.output-example'
220
+ ? 'contract/example-missing'
221
+ : 'contract/not-sealable', severity: 'error', message: problem.message }, (problem.operation ? { operation: problem.operation } : {})));
222
+ }
223
+ return { contract, diagnostics };
224
+ }
225
+ /**
226
+ * `deriveContract(definition, { packageVersion, contractVersion, previous? })`:
227
+ * the sealed `Contract`; throws `ContractDerivationError` when an error
228
+ * diagnostic exists. Use `analyzeContract` to read warnings too.
229
+ */
230
+ export function deriveContract(definition, options) {
231
+ const { contract, diagnostics } = analyzeContract(definition, options);
232
+ if (diagnostics.some((d) => d.severity === 'error')) {
233
+ throw new ContractDerivationError(diagnostics);
234
+ }
235
+ return contract;
236
+ }
237
+ //# sourceMappingURL=derive-contract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"derive-contract.js","sourceRoot":"","sources":["../../src/contract/derive-contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,UAAU,EACV,YAAY,EACZ,qBAAqB,EACrB,cAAc,GACf,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EACL,uBAAuB,GAIxB,MAAM,SAAS,CAAC;AAOjB,SAAS,QAAQ,CAAC,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W,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,OAAO,CAAC,EAAE,CAAC;QACpD,MAAM,IAAI,uBAAuB,CAAC,WAAW,CAAC,CAAC;IACjD,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import {\n type Contract,\n type ContractEvent,\n type ContractOperation,\n type JsonSchema,\n compatLine,\n sealContract,\n validateAgainstSchema,\n verifyContract,\n} from '@ekanos/integration-schema';\n\nimport { synthesizeExample } from './synthesize-example';\nimport { toJsonSchema } from './to-json-schema';\nimport {\n ContractDerivationError,\n type ContractDiagnostic,\n type DeriveContractOptions,\n type DeriveContractResult,\n} from './types';\n\ntype Loose = Record<string, unknown>;\ntype Effect = 'read' | 'write';\ntype Sensitivity = 'public' | 'internal' | 'pii' | 'financial';\ntype Classification = { effect?: Effect; sensitivity?: Sensitivity };\n\nfunction isRecord(value: unknown): value is Loose {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction asRecordOf<T>(value: unknown): Record<string, T> {\n return isRecord(value) ? (value as Record<string, T>) : {};\n}\n\nfunction inferConnection(definition: Loose): Contract['connection'] {\n const declared = isRecord(definition.connection) ? definition.connection : {};\n const oauth = isRecord(definition.oauth) ? definition.oauth : null;\n const provider = oauth && isRecord(oauth.provider) ? oauth.provider : null;\n const proposes = isRecord(definition.proposes) ? definition.proposes : {};\n\n const auth =\n (declared.auth as Contract['connection']['auth'] | undefined) ??\n (oauth ? 'oauth2' : 'none');\n const scopes =\n (declared.scopes as string[] | undefined) ??\n (provider && Array.isArray(provider.scopes)\n ? (provider.scopes as string[])\n : []);\n const fromModel =\n proposes.credentialModel === 'user'\n ? ['user']\n : proposes.credentialModel === 'source'\n ? ['source']\n : proposes.scope === 'user'\n ? ['user']\n : ['team'];\n const levels =\n (declared.levels as Contract['connection']['levels'] | undefined) ??\n (fromModel as Contract['connection']['levels']);\n return { levels, auth, scopes };\n}\n\nfunction opaqueReasonFor(\n input: { opaque: boolean; reason?: string },\n output: { opaque: boolean; reason?: string },\n): string | undefined {\n const parts: string[] = [];\n if (input.opaque) parts.push(`input: ${input.reason ?? 'opaque'}`);\n if (output.opaque) parts.push(`output: ${output.reason ?? 'opaque'}`);\n return parts.length > 0 ? parts.join('; ') : undefined;\n}\n\n/**\n * Derive and seal the contract artifact from a `defineIntegration` result.\n * Non-throwing: returns diagnostics beside the contract (a contract that\n * fails its own `verifyContract` is reported as error diagnostics).\n */\nexport function analyzeContract(\n rawDefinition: unknown,\n options: DeriveContractOptions,\n): DeriveContractResult {\n const definition = isRecord(rawDefinition) ? rawDefinition : {};\n const diagnostics: ContractDiagnostic[] = [];\n const line = compatLine(options.contractVersion);\n const slug = String(definition.slug ?? '');\n const proposes = isRecord(definition.proposes) ? definition.proposes : {};\n const toolClassifications = asRecordOf<Classification>(proposes.tools);\n const actionClassifications = asRecordOf<Classification>(proposes.actions);\n const previousSince = new Map(\n (options.previous?.operations ?? []).map((op) => [op.id, op.since]),\n );\n\n const classify = (\n key: string,\n declared: Classification,\n proposed: Classification | undefined,\n ): { effect: Effect; sensitivity: Sensitivity } => {\n const effect = declared.effect ?? proposed?.effect;\n if (!effect) {\n diagnostics.push({\n rule: 'contract/effect-undeclared',\n severity: 'warn',\n operation: key,\n message: 'no effect declared; treated as a write (fail safe).',\n });\n }\n return {\n effect: effect ?? 'write',\n sensitivity: declared.sensitivity ?? proposed?.sensitivity ?? 'internal',\n };\n };\n\n const build = (\n kind: 'tool' | 'action',\n name: string,\n parts: {\n description: unknown;\n input: { schema: JsonSchema; opaque: boolean; reason?: string };\n outputSchema: unknown;\n authoredExample: unknown;\n classification: { effect: Effect; sensitivity: Sensitivity };\n },\n ): ContractOperation => {\n const key = `${kind}/${name}`;\n const id = `${slug}@${line}/${kind}/${name}`;\n if (\n typeof parts.description !== 'string' ||\n parts.description.length === 0\n ) {\n diagnostics.push({\n rule: 'contract/description-missing',\n severity: 'error',\n operation: key,\n message: 'a description is required.',\n });\n }\n\n let output: { schema: JsonSchema; opaque: boolean; reason?: string };\n if (parts.outputSchema === undefined) {\n output = {\n schema: {},\n opaque: true,\n reason: `the ${kind} declares no runtime output schema`,\n };\n diagnostics.push({\n rule: 'contract/output-schema-missing',\n severity: options.requireOutputSchemas ? 'error' : 'warn',\n operation: key,\n message: `no output schema; the output is opaque and an experience cannot bind to ${key}. Declare ${kind === 'tool' ? '`output`' : '`output`'} as a zod schema.`,\n });\n } else {\n output = toJsonSchema(parts.outputSchema, 'output');\n if (output.opaque) {\n diagnostics.push({\n rule: 'contract/output-opaque',\n severity: options.requireOutputSchemas ? 'error' : 'warn',\n operation: key,\n message: `output is opaque: ${output.reason}.`,\n });\n }\n }\n if (parts.input.opaque) {\n diagnostics.push({\n rule: 'contract/input-opaque',\n severity: 'warn',\n operation: key,\n message: `input is opaque: ${parts.input.reason}.`,\n });\n }\n\n let outputExample: unknown =\n parts.authoredExample ?? options.examples?.[key];\n if (outputExample === undefined && !output.opaque) {\n if (parts.classification.effect === 'read') {\n diagnostics.push({\n rule: 'contract/example-missing',\n severity: 'error',\n operation: key,\n message:\n 'a read operation needs an outputExample (author one or run `ekanos contract --record`).',\n });\n } else {\n outputExample = synthesizeExample(output.schema);\n diagnostics.push({\n rule: 'contract/example-synthesized',\n severity: 'warn',\n operation: key,\n message:\n 'no outputExample; a placeholder was synthesized from the schema.',\n });\n }\n }\n if (outputExample !== undefined && !output.opaque) {\n const problems = validateAgainstSchema(output.schema, outputExample);\n if (problems.length > 0) {\n diagnostics.push({\n rule: 'contract/example-invalid',\n severity: 'error',\n operation: key,\n message: `outputExample does not satisfy output: ${problems[0]}`,\n });\n }\n }\n\n const reason = opaqueReasonFor(parts.input, output);\n const since = previousSince.get(id) ?? options.packageVersion;\n return {\n id,\n kind,\n name,\n description:\n typeof parts.description === 'string' ? parts.description : '',\n effect: parts.classification.effect,\n sensitivity: parts.classification.sensitivity,\n input: parts.input.schema,\n output: output.schema,\n opaque: { input: parts.input.opaque, output: output.opaque },\n ...(reason ? { opaqueReason: reason } : {}),\n ...(outputExample !== undefined && !output.opaque\n ? { outputExample }\n : {}),\n since,\n } as ContractOperation;\n };\n\n const operations: ContractOperation[] = [];\n\n for (const [name, raw] of Object.entries(\n asRecordOf<Loose>(definition.actions),\n )) {\n const input = toJsonSchema(raw.input, 'input');\n operations.push(\n build('action', name, {\n description: raw.description,\n input,\n outputSchema: raw.output,\n authoredExample: raw.outputExample,\n classification: classify(\n `action/${name}`,\n {\n effect: raw.effect as Effect | undefined,\n sensitivity: raw.sensitivity as Sensitivity | undefined,\n },\n actionClassifications[name],\n ),\n }),\n );\n }\n\n const tools = Array.isArray(definition.tools)\n ? (definition.tools as Loose[])\n : [];\n for (const tool of tools) {\n const name = String(tool.name);\n const parameters = isRecord(tool.parameters)\n ? (tool.parameters as JsonSchema)\n : ({ type: 'object', properties: {} } as JsonSchema);\n operations.push(\n build('tool', name, {\n description: tool.description,\n input: { schema: parameters, opaque: false },\n outputSchema: tool.output,\n authoredExample: tool.outputExample,\n classification: classify(`tool/${name}`, {}, toolClassifications[name]),\n }),\n );\n }\n\n const events: ContractEvent[] = [];\n for (const raw of Array.isArray(definition.agentEvents)\n ? (definition.agentEvents as Loose[])\n : []) {\n const converted =\n raw.payloadSchema === undefined\n ? null\n : toJsonSchema(raw.payloadSchema, 'output');\n if (!converted || converted.opaque) {\n diagnostics.push({\n rule: 'contract/event-schema-missing',\n severity: 'warn',\n operation: String(raw.id),\n message: `event payload is opaque${converted?.reason ? `: ${converted.reason}` : ''}.`,\n });\n }\n events.push({\n name: String(raw.id),\n payload: converted?.schema ?? {},\n opaque: converted?.opaque ?? true,\n ...(raw.examplePayload !== undefined\n ? { payloadExample: raw.examplePayload }\n : {}),\n });\n }\n\n const contract = sealContract({\n schemaVersion: 1,\n integration: slug,\n packageVersion: options.packageVersion,\n contractVersion: options.contractVersion,\n compatLine: line,\n connection: inferConnection(definition),\n ...(definition.health ? { health: true } : {}),\n operations,\n events,\n });\n\n const { problems } = verifyContract(contract);\n for (const problem of problems) {\n // Example problems were already reported with a friendlier rule.\n if (problem.rule === 'contract.output-example-invalid') continue;\n if (\n problem.rule === 'contract.output-example' &&\n diagnostics.some(\n (d) =>\n d.rule === 'contract/example-missing' &&\n d.operation === problem.operation?.replace(/^[^/]*\\//, ''),\n )\n ) {\n continue;\n }\n diagnostics.push({\n rule:\n problem.rule === 'contract.output-example'\n ? 'contract/example-missing'\n : 'contract/not-sealable',\n severity: 'error',\n message: problem.message,\n ...(problem.operation ? { operation: problem.operation } : {}),\n });\n }\n\n return { contract, diagnostics };\n}\n\n/**\n * `deriveContract(definition, { packageVersion, contractVersion, previous? })`:\n * the sealed `Contract`; throws `ContractDerivationError` when an error\n * diagnostic exists. Use `analyzeContract` to read warnings too.\n */\nexport function deriveContract(\n definition: unknown,\n options: DeriveContractOptions,\n): Contract {\n const { contract, diagnostics } = analyzeContract(definition, options);\n if (diagnostics.some((d) => d.severity === 'error')) {\n throw new ContractDerivationError(diagnostics);\n }\n return contract;\n}\n"]}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * `@ekanos/sdk/contract` - build-time, node only. Derives the contract
3
+ * artifact (`contract.json`) from an integration definition.
4
+ */
5
+ export { analyzeContract, deriveContract } from './derive-contract.js';
6
+ export { synthesizeExample } from './synthesize-example.js';
7
+ export { toJsonSchema, type ToJsonSchemaResult } from './to-json-schema.js';
8
+ export { ContractDerivationError, type ContractDiagnostic, type DeriveContractOptions, type DeriveContractResult, type DiagnosticSeverity, } from './types.js';
@@ -0,0 +1,9 @@
1
+ /**
2
+ * `@ekanos/sdk/contract` - build-time, node only. Derives the contract
3
+ * artifact (`contract.json`) from an integration definition.
4
+ */
5
+ export { analyzeContract, deriveContract } from './derive-contract.js';
6
+ export { synthesizeExample } from './synthesize-example.js';
7
+ export { toJsonSchema } from './to-json-schema.js';
8
+ export { ContractDerivationError, } from './types.js';
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/contract/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,YAAY,EAA2B,MAAM,kBAAkB,CAAC;AACzE,OAAO,EACL,uBAAuB,GAKxB,MAAM,SAAS,CAAC","sourcesContent":["/**\n * `@ekanos/sdk/contract` - build-time, node only. Derives the contract\n * artifact (`contract.json`) from an integration definition.\n */\nexport { analyzeContract, deriveContract } from './derive-contract';\nexport { synthesizeExample } from './synthesize-example';\nexport { toJsonSchema, type ToJsonSchemaResult } from './to-json-schema';\nexport {\n ContractDerivationError,\n type ContractDiagnostic,\n type DeriveContractOptions,\n type DeriveContractResult,\n type DiagnosticSeverity,\n} from './types';\n"]}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * A placeholder value that satisfies a schema in the contract dialect. Used
3
+ * only as a last resort for a WRITE operation with no authored or recorded
4
+ * example; `--record` replaces it with a real one.
5
+ */
6
+ export declare function synthesizeExample(schema: unknown, depth?: number): unknown;
@@ -0,0 +1,61 @@
1
+ function isRecord(value) {
2
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
3
+ }
4
+ /**
5
+ * A placeholder value that satisfies a schema in the contract dialect. Used
6
+ * only as a last resort for a WRITE operation with no authored or recorded
7
+ * example; `--record` replaces it with a real one.
8
+ */
9
+ export function synthesizeExample(schema, depth = 0) {
10
+ var _a, _b;
11
+ if (!isRecord(schema) || depth > 8)
12
+ return null;
13
+ if ('const' in schema)
14
+ return schema.const;
15
+ if (Array.isArray(schema.enum) && schema.enum.length > 0)
16
+ return schema.enum[0];
17
+ const alternatives = (_a = schema.anyOf) !== null && _a !== void 0 ? _a : schema.oneOf;
18
+ if (Array.isArray(alternatives) && alternatives.length > 0) {
19
+ return synthesizeExample(alternatives[0], depth + 1);
20
+ }
21
+ const declared = Array.isArray(schema.type) ? schema.type : [schema.type];
22
+ const type = (_b = declared.find((candidate) => candidate !== 'null')) !== null && _b !== void 0 ? _b : declared[0];
23
+ switch (type) {
24
+ case 'string': {
25
+ const min = typeof schema.minLength === 'number' ? schema.minLength : 0;
26
+ if (schema.format === 'date-time')
27
+ return '2026-01-01T00:00:00.000Z';
28
+ if (schema.format === 'uri' || schema.format === 'url')
29
+ return 'https://example.com';
30
+ return 'example'.padEnd(Math.max(min, 7), 'x');
31
+ }
32
+ case 'integer':
33
+ case 'number': {
34
+ const min = typeof schema.minimum === 'number'
35
+ ? schema.minimum
36
+ : typeof schema.exclusiveMinimum === 'number'
37
+ ? schema.exclusiveMinimum + 1
38
+ : 0;
39
+ return type === 'integer' ? Math.ceil(min) : min;
40
+ }
41
+ case 'boolean':
42
+ return false;
43
+ case 'null':
44
+ return null;
45
+ case 'array': {
46
+ const min = typeof schema.minItems === 'number' ? schema.minItems : 1;
47
+ return Array.from({ length: Math.max(min, 1) }, () => synthesizeExample(schema.items, depth + 1));
48
+ }
49
+ case 'object': {
50
+ const properties = isRecord(schema.properties) ? schema.properties : {};
51
+ const out = {};
52
+ for (const [key, child] of Object.entries(properties)) {
53
+ out[key] = synthesizeExample(child, depth + 1);
54
+ }
55
+ return out;
56
+ }
57
+ default:
58
+ return {};
59
+ }
60
+ }
61
+ //# sourceMappingURL=synthesize-example.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"synthesize-example.js","sourceRoot":"","sources":["../../src/contract/synthesize-example.ts"],"names":[],"mappings":"AAIA,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAe,EAAE,KAAK,GAAG,CAAC;;IAC1D,IAAI,CAAC,QAAQ,CAAC,MAA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AAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;gBACtD,GAAG,CAAC,GAAG,CAAC,GAAG,iBAAiB,CAAC,KAAmB,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;YAC/D,CAAC;YACD,OAAO,GAAG,CAAC;QACb,CAAC;QACD;YACE,OAAO,EAAE,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import type { JsonSchema } from '@ekanos/integration-schema';\n\ntype Loose = Record<string, unknown>;\n\nfunction isRecord(value: unknown): value is Loose {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/**\n * A placeholder value that satisfies a schema in the contract dialect. Used\n * only as a last resort for a WRITE operation with no authored or recorded\n * example; `--record` replaces it with a real one.\n */\nexport function synthesizeExample(schema: unknown, depth = 0): unknown {\n if (!isRecord(schema) || depth > 8) return null;\n if ('const' in schema) return schema.const;\n if (Array.isArray(schema.enum) && schema.enum.length > 0)\n return schema.enum[0];\n const alternatives = schema.anyOf ?? schema.oneOf;\n if (Array.isArray(alternatives) && alternatives.length > 0) {\n return synthesizeExample(alternatives[0], depth + 1);\n }\n const declared = Array.isArray(schema.type) ? schema.type : [schema.type];\n const type =\n declared.find((candidate) => candidate !== 'null') ?? declared[0];\n switch (type) {\n case 'string': {\n const min = typeof schema.minLength === 'number' ? schema.minLength : 0;\n if (schema.format === 'date-time') return '2026-01-01T00:00:00.000Z';\n if (schema.format === 'uri' || schema.format === 'url')\n return 'https://example.com';\n return 'example'.padEnd(Math.max(min, 7), 'x');\n }\n case 'integer':\n case 'number': {\n const min =\n typeof schema.minimum === 'number'\n ? schema.minimum\n : typeof schema.exclusiveMinimum === 'number'\n ? schema.exclusiveMinimum + 1\n : 0;\n return type === 'integer' ? Math.ceil(min) : min;\n }\n case 'boolean':\n return false;\n case 'null':\n return null;\n case 'array': {\n const min = typeof schema.minItems === 'number' ? schema.minItems : 1;\n return Array.from({ length: Math.max(min, 1) }, () =>\n synthesizeExample(schema.items, depth + 1),\n );\n }\n case 'object': {\n const properties = isRecord(schema.properties) ? schema.properties : {};\n const out: Loose = {};\n for (const [key, child] of Object.entries(properties)) {\n out[key] = synthesizeExample(child as JsonSchema, depth + 1);\n }\n return out;\n }\n default:\n return {};\n }\n}\n"]}
@@ -0,0 +1,19 @@
1
+ import { type JsonSchema } from '@ekanos/integration-schema';
2
+ export interface ToJsonSchemaResult {
3
+ schema: JsonSchema;
4
+ /** True when the schema could not be represented faithfully. */
5
+ opaque: boolean;
6
+ /** Why, when `opaque`; auto-filled into the contract's `opaqueReason`. */
7
+ reason?: string;
8
+ }
9
+ export type SchemaDirection = 'input' | 'output';
10
+ /**
11
+ * THE one zod-to-JSON-Schema function (Zod 4 native via `z.toJSONSchema`, Zod 3
12
+ * through `zod-to-json-schema`). Nobody else calls a zod converter.
13
+ *
14
+ * A schema is reported `opaque` when it carries something JSON Schema cannot
15
+ * hold (refinement, transform, recursion), when the conversion throws, when it
16
+ * is not a zod schema, or when the result uses a keyword outside the contract
17
+ * dialect. The schema returned for an opaque half is a best-effort description.
18
+ */
19
+ export declare function toJsonSchema(schema: unknown, direction?: SchemaDirection): ToJsonSchemaResult;