callman-core 1.20.0 → 1.22.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 (129) hide show
  1. package/dist/ai/index.d.ts +13 -0
  2. package/dist/ai/index.d.ts.map +1 -0
  3. package/dist/ai/index.js +19 -0
  4. package/dist/ai/index.js.map +1 -0
  5. package/dist/ai/jsonRepair.d.ts +2 -0
  6. package/dist/ai/jsonRepair.d.ts.map +1 -0
  7. package/dist/ai/jsonRepair.js +61 -0
  8. package/dist/ai/jsonRepair.js.map +1 -0
  9. package/dist/ai/outputSchemas.d.ts +43 -0
  10. package/dist/ai/outputSchemas.d.ts.map +1 -0
  11. package/dist/ai/outputSchemas.js +38 -0
  12. package/dist/ai/outputSchemas.js.map +1 -0
  13. package/dist/ai/parse/diagram.d.ts +3 -0
  14. package/dist/ai/parse/diagram.d.ts.map +1 -0
  15. package/dist/ai/parse/diagram.js +24 -0
  16. package/dist/ai/parse/diagram.js.map +1 -0
  17. package/dist/ai/parse/scenario.d.ts +3 -0
  18. package/dist/ai/parse/scenario.d.ts.map +1 -0
  19. package/dist/ai/parse/scenario.js +23 -0
  20. package/dist/ai/parse/scenario.js.map +1 -0
  21. package/dist/ai/parse/shared.d.ts +5 -0
  22. package/dist/ai/parse/shared.d.ts.map +1 -0
  23. package/dist/ai/parse/shared.js +49 -0
  24. package/dist/ai/parse/shared.js.map +1 -0
  25. package/dist/ai/parse/unified.d.ts +10 -0
  26. package/dist/ai/parse/unified.d.ts.map +1 -0
  27. package/dist/ai/parse/unified.js +105 -0
  28. package/dist/ai/parse/unified.js.map +1 -0
  29. package/dist/ai/prompts/diagram.d.ts +4 -0
  30. package/dist/ai/prompts/diagram.d.ts.map +1 -0
  31. package/dist/ai/prompts/diagram.js +132 -0
  32. package/dist/ai/prompts/diagram.js.map +1 -0
  33. package/dist/ai/prompts/fragments.d.ts +5 -0
  34. package/dist/ai/prompts/fragments.d.ts.map +1 -0
  35. package/dist/ai/prompts/fragments.js +27 -0
  36. package/dist/ai/prompts/fragments.js.map +1 -0
  37. package/dist/ai/prompts/scenario.d.ts +12 -0
  38. package/dist/ai/prompts/scenario.d.ts.map +1 -0
  39. package/dist/ai/prompts/scenario.js +204 -0
  40. package/dist/ai/prompts/scenario.js.map +1 -0
  41. package/dist/ai/prompts/scenarioNodeDefaults.d.ts +3 -0
  42. package/dist/ai/prompts/scenarioNodeDefaults.d.ts.map +1 -0
  43. package/dist/ai/prompts/scenarioNodeDefaults.js +166 -0
  44. package/dist/ai/prompts/scenarioNodeDefaults.js.map +1 -0
  45. package/dist/ai/prompts/unified.d.ts +13 -0
  46. package/dist/ai/prompts/unified.d.ts.map +1 -0
  47. package/dist/ai/prompts/unified.js +123 -0
  48. package/dist/ai/prompts/unified.js.map +1 -0
  49. package/dist/ai/types.d.ts +100 -0
  50. package/dist/ai/types.d.ts.map +1 -0
  51. package/dist/ai/types.js +9 -0
  52. package/dist/ai/types.js.map +1 -0
  53. package/dist/index.d.ts +1 -0
  54. package/dist/index.d.ts.map +1 -1
  55. package/dist/index.js +4 -0
  56. package/dist/index.js.map +1 -1
  57. package/dist/scenario-runner/adapters/ai-executor.d.ts +9 -0
  58. package/dist/scenario-runner/adapters/ai-executor.d.ts.map +1 -0
  59. package/dist/scenario-runner/adapters/ai-executor.js +118 -0
  60. package/dist/scenario-runner/adapters/ai-executor.js.map +1 -0
  61. package/dist/scenario-runner/adapters/helpers/aiExample.d.ts +13 -0
  62. package/dist/scenario-runner/adapters/helpers/aiExample.d.ts.map +1 -0
  63. package/dist/scenario-runner/adapters/helpers/aiExample.js +143 -0
  64. package/dist/scenario-runner/adapters/helpers/aiExample.js.map +1 -0
  65. package/dist/scenario-runner/adapters/index.d.ts +3 -1
  66. package/dist/scenario-runner/adapters/index.d.ts.map +1 -1
  67. package/dist/scenario-runner/adapters/index.js +7 -0
  68. package/dist/scenario-runner/adapters/index.js.map +1 -1
  69. package/dist/scenario-runner/adapters/types.d.ts +14 -0
  70. package/dist/scenario-runner/adapters/types.d.ts.map +1 -1
  71. package/dist/scenario-runner/condition.d.ts.map +1 -1
  72. package/dist/scenario-runner/condition.js +37 -2
  73. package/dist/scenario-runner/condition.js.map +1 -1
  74. package/dist/scenario-runner/graphTraversal.d.ts +6 -0
  75. package/dist/scenario-runner/graphTraversal.d.ts.map +1 -1
  76. package/dist/scenario-runner/graphTraversal.js +7 -0
  77. package/dist/scenario-runner/graphTraversal.js.map +1 -1
  78. package/dist/scenario-runner/nodePolicy.d.ts +2 -2
  79. package/dist/scenario-runner/nodePolicy.d.ts.map +1 -1
  80. package/dist/scenario-runner/nodePolicy.js +2 -0
  81. package/dist/scenario-runner/nodePolicy.js.map +1 -1
  82. package/dist/scenario-runner/runScenario.d.ts.map +1 -1
  83. package/dist/scenario-runner/runScenario.js +28 -0
  84. package/dist/scenario-runner/runScenario.js.map +1 -1
  85. package/dist/scenario-runner/types.d.ts +48 -3
  86. package/dist/scenario-runner/types.d.ts.map +1 -1
  87. package/dist-cjs/ai/index.js +58 -0
  88. package/dist-cjs/ai/index.js.map +1 -0
  89. package/dist-cjs/ai/jsonRepair.js +65 -0
  90. package/dist-cjs/ai/jsonRepair.js.map +1 -0
  91. package/dist-cjs/ai/outputSchemas.js +41 -0
  92. package/dist-cjs/ai/outputSchemas.js.map +1 -0
  93. package/dist-cjs/ai/parse/diagram.js +28 -0
  94. package/dist-cjs/ai/parse/diagram.js.map +1 -0
  95. package/dist-cjs/ai/parse/scenario.js +27 -0
  96. package/dist-cjs/ai/parse/scenario.js.map +1 -0
  97. package/dist-cjs/ai/parse/shared.js +56 -0
  98. package/dist-cjs/ai/parse/shared.js.map +1 -0
  99. package/dist-cjs/ai/parse/unified.js +109 -0
  100. package/dist-cjs/ai/parse/unified.js.map +1 -0
  101. package/dist-cjs/ai/prompts/diagram.js +137 -0
  102. package/dist-cjs/ai/prompts/diagram.js.map +1 -0
  103. package/dist-cjs/ai/prompts/fragments.js +31 -0
  104. package/dist-cjs/ai/prompts/fragments.js.map +1 -0
  105. package/dist-cjs/ai/prompts/scenario.js +209 -0
  106. package/dist-cjs/ai/prompts/scenario.js.map +1 -0
  107. package/dist-cjs/ai/prompts/scenarioNodeDefaults.js +170 -0
  108. package/dist-cjs/ai/prompts/scenarioNodeDefaults.js.map +1 -0
  109. package/dist-cjs/ai/prompts/unified.js +128 -0
  110. package/dist-cjs/ai/prompts/unified.js.map +1 -0
  111. package/dist-cjs/ai/types.js +12 -0
  112. package/dist-cjs/ai/types.js.map +1 -0
  113. package/dist-cjs/index.js +4 -0
  114. package/dist-cjs/index.js.map +1 -1
  115. package/dist-cjs/scenario-runner/adapters/ai-executor.js +122 -0
  116. package/dist-cjs/scenario-runner/adapters/ai-executor.js.map +1 -0
  117. package/dist-cjs/scenario-runner/adapters/helpers/aiExample.js +150 -0
  118. package/dist-cjs/scenario-runner/adapters/helpers/aiExample.js.map +1 -0
  119. package/dist-cjs/scenario-runner/adapters/index.js +13 -1
  120. package/dist-cjs/scenario-runner/adapters/index.js.map +1 -1
  121. package/dist-cjs/scenario-runner/condition.js +37 -2
  122. package/dist-cjs/scenario-runner/condition.js.map +1 -1
  123. package/dist-cjs/scenario-runner/graphTraversal.js +8 -1
  124. package/dist-cjs/scenario-runner/graphTraversal.js.map +1 -1
  125. package/dist-cjs/scenario-runner/nodePolicy.js +2 -0
  126. package/dist-cjs/scenario-runner/nodePolicy.js.map +1 -1
  127. package/dist-cjs/scenario-runner/runScenario.js +28 -0
  128. package/dist-cjs/scenario-runner/runScenario.js.map +1 -1
  129. package/package.json +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scenarioNodeDefaults.js","sourceRoot":"","sources":["../../../src/ai/prompts/scenarioNodeDefaults.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,8EAA8E;AAC9E,8EAA8E;AAC9E,qEAAqE;AACrE,6EAA6E;AAC7E,+EAA+E;AAC/E,6EAA6E;AAE7E,MAAM,aAAa,GAAG;IACpB,SAAS,EAAE,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,EAAE,WAAW,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE;SACtD;KACF;IACD,UAAU,EAAE;QACV,QAAQ,EAAE,gCAAgC;QAC1C,eAAe,EAAE,aAAa;KAC/B;IACD,GAAG,EAAE;QACH,IAAI,EAAE,KAAK;QACX,gBAAgB,EAAE,IAAI;QACtB,cAAc,EAAE,CAAC;QACjB,WAAW,EAAE,IAAI;QACjB,eAAe,EAAE,aAAa;KAC/B;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,IAAY,EAAW,EAAE,CACjE,6BAA6B,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { AiConnectionRef, AiCurrentScript, AiExistingContractRule, AiSchemaField, AiScriptRequestMeta } from "../types.js";
2
+ export declare const buildUnifiedSystemPrompt: () => string;
3
+ export declare const buildUnifiedUserPrompt: ({ instruction, fields, existingRules, currentScripts, connections, requestMeta, statusCode, contentType, }: {
4
+ instruction: string;
5
+ fields?: AiSchemaField[];
6
+ existingRules?: AiExistingContractRule[];
7
+ currentScripts?: AiCurrentScript[];
8
+ connections?: AiConnectionRef[];
9
+ requestMeta?: AiScriptRequestMeta;
10
+ statusCode?: number;
11
+ contentType?: string;
12
+ }) => string;
13
+ //# sourceMappingURL=unified.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unified.d.ts","sourceRoot":"","sources":["../../../src/ai/prompts/unified.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EACV,eAAe,EACf,eAAe,EACf,sBAAsB,EACtB,aAAa,EACb,mBAAmB,EACpB,MAAM,aAAa,CAAC;AAQrB,eAAO,MAAM,wBAAwB,QAAO,MA+D3C,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAAI,4GASpC;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,aAAa,EAAE,CAAC;IACzB,aAAa,CAAC,EAAE,sBAAsB,EAAE,CAAC;IACzC,cAAc,CAAC,EAAE,eAAe,EAAE,CAAC;IACnC,WAAW,CAAC,EAAE,eAAe,EAAE,CAAC;IAChC,WAAW,CAAC,EAAE,mBAAmB,CAAC;IAClC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,KAAG,MAuDH,CAAC"}
@@ -0,0 +1,123 @@
1
+ // The unified request-chat prompt (contract rules + request scripts + plain
2
+ // replies in ONE assistant). Canonical source — ported from the desktop copy,
3
+ // which was ahead of the backend's (it teaches mssql + @p1..@pN SQL Server
4
+ // binding); backend and desktop both consume this now.
5
+ //
6
+ // The prompt must tolerate being PREPENDED to the user prompt (Codex and
7
+ // Cursor CLIs have no system-prompt flag) — it is self-contained prose with no
8
+ // role assumptions.
9
+ import { renderDbQueryReference } from "../../host/db/db-query-reference.js";
10
+ import { renderPmApiReference } from "../../script/pm-api-reference.js";
11
+ import { AI_SCRIPT_STAGES } from "../types.js";
12
+ import { CONTRACT_RULES_SPEC, STAGE_DESCRIPTIONS, truncateForPrompt } from "./fragments.js";
13
+ // ONE prompt for the whole assistant. The model classifies intent itself — the
14
+ // user never picks "contract vs script" or a target stage — and returns a
15
+ // single JSON object that may carry a reply, contract changes, script changes,
16
+ // or any combination.
17
+ export const buildUnifiedSystemPrompt = () => {
18
+ const stageNotes = AI_SCRIPT_STAGES.map((stage) => `- \`${stage}\`: ${STAGE_DESCRIPTIONS[stage]}`).join("\n");
19
+ return [
20
+ "You are Callman's AI assistant inside an API client (like Postman). The user is",
21
+ "editing ONE HTTP request. From their message plus the CONTEXT below, YOU decide",
22
+ "what is needed — the user does NOT pick a mode or a target. Respond with ONE JSON",
23
+ "object ONLY (no markdown, no prose outside JSON), shaped:",
24
+ "",
25
+ '{"reply": string, "contract": {"add": [{"path": string, "rules": {…}}], "remove": [string]} | null, "scripts": [{"stage": "pre-request|post-response|tests|kafka", "code": string}]}',
26
+ "",
27
+ "How to decide (classify intent yourself):",
28
+ "- Assertions about the LAST RESPONSE's shape (a field's type/format/required/value/",
29
+ " length/range) → put them in `contract`. This is the response contract-test engine.",
30
+ "- Anything that must RUN around the request — set a header/token/body, read or write",
31
+ " env/globals, query a DB or Redis, send an extra HTTP call, or assert with pm.test —",
32
+ " → write JavaScript in `scripts` for the RIGHT stage(s).",
33
+ "- A plain question or nothing to change → `reply` only, `contract` null, `scripts` [].",
34
+ "- You MAY combine (e.g. save a token in `pre-request` AND assert it in `tests` AND add",
35
+ " a `contract` rule). Only include a stage you actually wrote.",
36
+ "- `reply` is ALWAYS a short, natural message: what you did, or the answer to a question.",
37
+ "",
38
+ "STAGES (pick the right one; you may target several):",
39
+ stageNotes,
40
+ "",
41
+ "CONTRACT rules:",
42
+ "- `add` = new/updated rules; a path in both `add` and the existing list REPLACES it.",
43
+ " `remove` = existing paths to delete. MERGE when updating: keep existing operators and",
44
+ " add the new one; never drop operators unless asked.",
45
+ "- `path` MUST be one of the response SCHEMA paths (verbatim; array elements use `[]`,",
46
+ " e.g. `data.items[]`). Prefer high-signal checks (type/required/format); do not pin",
47
+ " `equals` to volatile ids/tokens/timestamps unless asked.",
48
+ CONTRACT_RULES_SPEC,
49
+ "",
50
+ "SCRIPTS: plain JavaScript, top-level await allowed. Each `code` is the FULL new script",
51
+ "for that stage and REPLACES it — when extending, keep the shown CURRENT code and add to",
52
+ 'it. Put every assertion inside pm.test("…", () => { … }). Use ONLY the API below; never',
53
+ "use fetch/require/import/process/Buffer. `await` every pm.db.query / pm.redis.command /",
54
+ "pm.sendRequest. Keep {{template}} tokens verbatim.",
55
+ "",
56
+ "CONNECTIONS: for pm.db.query / pm.redis.command, resolve the connection the user means",
57
+ "to its exact `connectionId` from AVAILABLE CONNECTIONS (match by name, case-insensitive)",
58
+ 'and pass it verbatim, e.g. `pm.db.query({ connectionId: "<id>", query: … })`. Match the',
59
+ "query FORMAT to that connection's provider (mongodb → JSON command object; postgresql/",
60
+ "mysql/oracle/mssql → SQL, with SQL Server params bound as @p1..@pN; redis → GET/SET/…).",
61
+ "If the user names no connection and gives no id,",
62
+ "omit `connectionId` so the request's own configured connection is used. Never invent an id.",
63
+ "",
64
+ "Examples (routing only):",
65
+ '- "assert the id is a uuid and status is 200" → contract on the response fields.',
66
+ '- "save the token from the response into an env var" → scripts: post-response (or tests).',
67
+ '- "check the user exists in mongo by email" → scripts: tests, using pm.db.query.',
68
+ '- "sign the body with hmac-sha256 before sending" → scripts: pre-request.',
69
+ '- "is this response ok?" → reply only.',
70
+ "",
71
+ "=== pm.* SCRIPT API ===",
72
+ renderPmApiReference(),
73
+ "",
74
+ "=== DATA ACCESS (DB / Redis query formats) ===",
75
+ renderDbQueryReference(),
76
+ ].join("\n");
77
+ };
78
+ export const buildUnifiedUserPrompt = ({ instruction, fields = [], existingRules = [], currentScripts = [], connections = [], requestMeta, statusCode, contentType, }) => {
79
+ const requestLine = requestMeta && (requestMeta.method || requestMeta.url)
80
+ ? `REQUEST: ${[requestMeta.method, requestMeta.url].filter(Boolean).join(" ")}`
81
+ : null;
82
+ const schemaLines = fields.length
83
+ ? fields
84
+ .map((field) => `${field.path}: ${field.type}${field.sample ? ` e.g. ${truncateForPrompt(field.sample)}` : ""}`)
85
+ .join("\n")
86
+ : "(no response captured)";
87
+ const meta = [
88
+ statusCode ? `HTTP status: ${statusCode}` : null,
89
+ contentType ? `Content-Type: ${contentType}` : null,
90
+ ]
91
+ .filter(Boolean)
92
+ .join("\n");
93
+ const existingLines = existingRules.length
94
+ ? existingRules.map((rule) => `${rule.path}: ${JSON.stringify(rule.rules)}`).join("\n")
95
+ : "(none yet)";
96
+ const currentBlocks = currentScripts
97
+ .filter((script) => script.code.trim().length > 0)
98
+ .map((script) => `--- ${script.stage} (current) ---\n${script.code}`)
99
+ .join("\n\n") || "(all scripts are empty)";
100
+ const connectionLines = connections.length
101
+ ? connections.map((c) => `${c.name} — ${c.provider} — ${c.id}`).join("\n")
102
+ : "(none)";
103
+ return [
104
+ requestLine,
105
+ "RESPONSE SCHEMA:",
106
+ schemaLines,
107
+ meta ? `\n${meta}` : "",
108
+ "",
109
+ "EXISTING CONTRACT RULES (path: operators):",
110
+ existingLines,
111
+ "",
112
+ "AVAILABLE CONNECTIONS (name — provider — connectionId):",
113
+ connectionLines,
114
+ "",
115
+ "CURRENT SCRIPTS:",
116
+ currentBlocks,
117
+ "",
118
+ `INSTRUCTION: ${instruction}`,
119
+ ]
120
+ .filter((line) => line !== null)
121
+ .join("\n");
122
+ };
123
+ //# sourceMappingURL=unified.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unified.js","sourceRoot":"","sources":["../../../src/ai/prompts/unified.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,8EAA8E;AAC9E,2EAA2E;AAC3E,uDAAuD;AACvD,EAAE;AACF,yEAAyE;AACzE,+EAA+E;AAC/E,oBAAoB;AAEpB,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAQxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAE5F,+EAA+E;AAC/E,0EAA0E;AAC1E,+EAA+E;AAC/E,sBAAsB;AACtB,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAW,EAAE;IACnD,MAAM,UAAU,GAAG,gBAAgB,CAAC,GAAG,CACrC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,OAAO,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAC1D,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEb,OAAO;QACL,iFAAiF;QACjF,iFAAiF;QACjF,mFAAmF;QACnF,2DAA2D;QAC3D,EAAE;QACF,sLAAsL;QACtL,EAAE;QACF,2CAA2C;QAC3C,qFAAqF;QACrF,sFAAsF;QACtF,sFAAsF;QACtF,uFAAuF;QACvF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AAC,QAAQ,MAAM,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QAC1E,CAAC,CAAC,QAAQ,CAAC;IAEb,OAAO;QACL,WAAW;QACX,kBAAkB;QAClB,WAAW;QACX,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE;QACvB,EAAE;QACF,4CAA4C;QAC5C,aAAa;QACb,EAAE;QACF,yDAAyD;QACzD,eAAe;QACf,EAAE;QACF,kBAAkB;QAClB,aAAa;QACb,EAAE;QACF,gBAAgB,WAAW,EAAE;KAC9B;SACE,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,IAAI,CAAC;SAC/B,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC,CAAC"}
@@ -0,0 +1,100 @@
1
+ export declare const AI_SCRIPT_STAGES: readonly ["pre-request", "post-response", "tests", "kafka"];
2
+ export type AiScriptStage = (typeof AI_SCRIPT_STAGES)[number];
3
+ export interface AiSchemaField {
4
+ path: string;
5
+ type: string;
6
+ sample?: string;
7
+ }
8
+ export interface AiExistingContractRule {
9
+ path: string;
10
+ rules: Record<string, unknown>;
11
+ }
12
+ export interface AiCurrentScript {
13
+ stage: AiScriptStage;
14
+ code: string;
15
+ }
16
+ export interface AiScriptRequestMeta {
17
+ method?: string;
18
+ url?: string;
19
+ }
20
+ export interface AiConnectionRef {
21
+ id: string;
22
+ name: string;
23
+ provider: string;
24
+ }
25
+ export type AiDiagramMode = "create" | "edit";
26
+ export interface DiagramComponentRef {
27
+ type: string;
28
+ label: string;
29
+ category: string;
30
+ }
31
+ export interface DiagramPromptInput {
32
+ instruction: string;
33
+ mode: AiDiagramMode;
34
+ document?: Record<string, unknown> | null;
35
+ components?: DiagramComponentRef[];
36
+ selection?: string[];
37
+ canvas?: {
38
+ width?: number;
39
+ height?: number;
40
+ };
41
+ }
42
+ export type ScenarioAiMode = "create" | "edit";
43
+ export interface ScenarioAiConnectionRef {
44
+ id: string;
45
+ name: string;
46
+ type: string;
47
+ provider: string;
48
+ }
49
+ export interface ScenarioAiRequestRef {
50
+ id: string;
51
+ collectionName: string;
52
+ name: string;
53
+ method: string;
54
+ url: string;
55
+ }
56
+ export interface ScenarioAiContext {
57
+ connections: ScenarioAiConnectionRef[];
58
+ requests: ScenarioAiRequestRef[];
59
+ }
60
+ export interface ScenarioPromptInput {
61
+ instruction: string;
62
+ mode: ScenarioAiMode;
63
+ document?: {
64
+ name?: string;
65
+ nodes: unknown[];
66
+ edges: unknown[];
67
+ environments?: unknown[];
68
+ } | null;
69
+ context: ScenarioAiContext;
70
+ selection?: string[];
71
+ }
72
+ export interface AiContractRuleProposal {
73
+ path: string;
74
+ rules: Record<string, unknown>;
75
+ }
76
+ export interface AiContractProposal {
77
+ add: AiContractRuleProposal[];
78
+ remove: string[];
79
+ }
80
+ export interface AiScriptProposal {
81
+ stage: AiScriptStage;
82
+ code: string;
83
+ }
84
+ export interface AiUnifiedOutput {
85
+ reply: string;
86
+ /** null when the turn produced no contract change. */
87
+ contract: AiContractProposal | null;
88
+ scripts: AiScriptProposal[];
89
+ }
90
+ export interface AiDiagramOutput {
91
+ reply: string;
92
+ /** Loose on purpose — hosts validate before applying. Null = reply only. */
93
+ diagram: unknown;
94
+ }
95
+ export interface AiScenarioOutput {
96
+ reply: string;
97
+ /** Loose on purpose — hosts sanitize + validate before applying. */
98
+ scenario: Record<string, unknown> | null;
99
+ }
100
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/ai/types.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,gBAAgB,6DAA8D,CAAC;AAC5F,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AAI9D,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,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ED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,oEAAoE;IACpE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;CAC1C"}
@@ -0,0 +1,9 @@
1
+ // Canonical wire-level types for the product's AI assistants. These are the
2
+ // shapes the prompts request and the parsers return — deliberately loose
3
+ // (Record<string, unknown> payloads) so callman-core needs no domain imports;
4
+ // hosts map to their richer domain types at the boundary (backend response
5
+ // DTOs, desktop DiagramDocument / GeneratedScenario / ContractRuleRules).
6
+ // The four request-script slots. Single source — backend zod enums and the
7
+ // desktop stage tables both derive from this.
8
+ export const AI_SCRIPT_STAGES = ["pre-request", "post-response", "tests", "kafka"];
9
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/ai/types.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,yEAAyE;AACzE,8EAA8E;AAC9E,2EAA2E;AAC3E,0EAA0E;AAE1E,2EAA2E;AAC3E,8CAA8C;AAC9C,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,aAAa,EAAE,eAAe,EAAE,OAAO,EAAE,OAAO,CAAU,CAAC"}
package/dist/index.d.ts CHANGED
@@ -26,6 +26,7 @@ export { resolveXPathCandidates, type XPathResolution } from "./contract/xpathRe
26
26
  export { applySoapRequestTransforms, type SoapRequestConfig, type SoapRuntimeRequestLike, } from "./soap/transport.js";
27
27
  export { buildWsSecurityHeader, injectWsSecurityHeader, type WsSecurityConfig, type WsSecurityHeaderParts, } from "./soap/wsSecurity.js";
28
28
  export { SOAP_11_ENVELOPE_TEMPLATE, SOAP_12_ENVELOPE_TEMPLATE, getSoapEnvelopeTemplate, } from "./soap/envelope.js";
29
+ export * from "./ai/index.js";
29
30
  export * from "./scenario-runner/index.js";
30
31
  export * from "./host/index.js";
31
32
  export * from "./types/index.js";
@@ -1 +1 @@
1
- {"version":3,"file":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,OAAO,EACL,yBAAyB,EACzB,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,oBAAoB,CAAC;AAI5B,cAAc,eAAe,CAAC;AAC9B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC"}
package/dist/index.js CHANGED
@@ -25,6 +25,10 @@ export { resolveXPathCandidates } from "./contract/xpathResolver.js";
25
25
  export { applySoapRequestTransforms, } from "./soap/transport.js";
26
26
  export { buildWsSecurityHeader, injectWsSecurityHeader, } from "./soap/wsSecurity.js";
27
27
  export { SOAP_11_ENVELOPE_TEMPLATE, SOAP_12_ENVELOPE_TEMPLATE, getSoapEnvelopeTemplate, } from "./soap/envelope.js";
28
+ // Central AI surface: shared prompts, parsers, output schemas + tolerant JSON
29
+ // extraction (jsonRepair) — one source for backend hosted generation and
30
+ // desktop local-CLI generation.
31
+ export * from "./ai/index.js";
28
32
  export * from "./scenario-runner/index.js";
29
33
  export * from "./host/index.js";
30
34
  export * from "./types/index.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACvB,WAAW,GAKZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,gBAAgB,EAChB,QAAQ,EACR,YAAY,EACZ,kBAAkB,GAEnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,uBAAuB,GAExB,MAAM,qBAAq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L,iBAAiB,EACjB,yBAAyB,EACzB,qBAAqB,GAEtB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,wBAAwB,GAEzB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,yBAAyB,EACzB,iBAAiB,EACjB,gBAAgB,GAEjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,sBAAsB,EAAwB,MAAM,6BAA6B,CAAC;AAC3F,kDAAkD;AAClD,OAAO,EACL,0BAA0B,GAG3B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GAGvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,yBAAyB,EACzB,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,oBAAoB,CAAC;AAC5B,8EAA8E;AAC9E,yEAAyE;AACzE,gCAAgC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { ScenarioAiExecutionInput, ScenarioAiExecutionResult } from "../types.js";
2
+ import type { AiChatTransport } from "./types.js";
3
+ export interface AiExecutorOptions {
4
+ chatTransport?: AiChatTransport;
5
+ /** Upper bound applied on top of the node's own timeoutMs (host budget). */
6
+ nodeTimeoutMs?: number;
7
+ }
8
+ export declare const buildAiExecutor: (options: AiExecutorOptions) => (input: ScenarioAiExecutionInput) => Promise<ScenarioAiExecutionResult>;
9
+ //# sourceMappingURL=ai-executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-executor.d.ts","sourceRoot":"","sources":["../../../src/scenario-runner/adapters/ai-executor.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EAE1B,MAAM,aAAa,CAAC;AAIrB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,MAAM,WAAW,iBAAiB;IAChC,aAAa,CAAC,EAAE,eAAe,CAAC;IAChC,4EAA4E;IAC5E,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAaD,eAAO,MAAM,eAAe,GAC1B,SAAS,iBAAiB,MAEnB,OAAO,wBAAwB,KAAG,OAAO,CAAC,yBAAyB,CA2IzE,CAAC"}
@@ -0,0 +1,118 @@
1
+ // Canonical AI executor — orchestrates an AI scenario node once, identically
2
+ // on every host. Everything provider-agnostic happens here: template-resolve
3
+ // the prompt, parse the response example, assemble the messages, call the
4
+ // host-injected chat transport, tolerantly parse the reply (jsonRepair), and
5
+ // validate it against the schema derived from the example. Hosts differ only
6
+ // in the transport (backend: direct provider call; desktop: backend proxy) —
7
+ // credentials never reach core.
8
+ //
9
+ // Fail-fast rules run BEFORE the transport call so a misconfigured node never
10
+ // burns provider tokens.
11
+ import { extractJsonPayload } from "../../ai/jsonRepair.js";
12
+ import { DEFAULT_AI_MAX_TOKENS, DEFAULT_AI_TIMEOUT_MS, MAX_AI_MAX_TOKENS, MAX_AI_PROMPT_LENGTH, MAX_AI_RESPONSE_EXAMPLE_LENGTH, MAX_AI_TIMEOUT_MS, } from "../graphTraversal.js";
13
+ import { buildScenarioTemplateValues, resolveScenarioTemplateString, } from "../templateResolver.js";
14
+ import { withAbortAndTimeout } from "./helpers/abort.js";
15
+ import { buildAiMessages, parseJsonExample, validateAgainstExample } from "./helpers/aiExample.js";
16
+ const failure = (message, details, durationMs = 0) => ({
17
+ outputData: null,
18
+ details,
19
+ durationMs,
20
+ failureMessage: message,
21
+ });
22
+ export const buildAiExecutor = (options) => async (input) => {
23
+ const config = input.node.data.config;
24
+ const details = {
25
+ connectionId: config.connectionId?.trim() || null,
26
+ provider: null,
27
+ model: null,
28
+ tokensUsed: null,
29
+ resolvedPrompt: null,
30
+ rawText: null,
31
+ };
32
+ if (!options.chatTransport) {
33
+ return failure("This host cannot run AI nodes (transport missing).", details);
34
+ }
35
+ if (!details.connectionId) {
36
+ return failure("AI node needs a managed AI connection.", details);
37
+ }
38
+ // --- Fail-fast validation (no provider call, no tokens burned) --------
39
+ const example = parseJsonExample(config.responseExample ?? "");
40
+ if (example.error || !example.value) {
41
+ return failure(example.error ?? "Response example is invalid.", details);
42
+ }
43
+ if ((config.responseExample ?? "").length > MAX_AI_RESPONSE_EXAMPLE_LENGTH) {
44
+ return failure(`Response example is capped at ${MAX_AI_RESPONSE_EXAMPLE_LENGTH} characters.`, details);
45
+ }
46
+ const templateValues = buildScenarioTemplateValues({
47
+ environment: input.context.environment,
48
+ globals: input.context.globals,
49
+ workflowContext: input.context.workflowContext,
50
+ nodeMetaByLabel: input.context.nodeMetaByLabel,
51
+ responseRoot: input.context.responseRoot,
52
+ dbResult: input.context.dbResult,
53
+ kafkaEvent: input.context.kafkaEvent,
54
+ redisResult: input.context.redisResult,
55
+ });
56
+ const resolvedPrompt = resolveScenarioTemplateString(config.prompt ?? "", templateValues).trim();
57
+ details.resolvedPrompt = resolvedPrompt || null;
58
+ if (!resolvedPrompt) {
59
+ return failure("AI prompt is empty.", details);
60
+ }
61
+ if (resolvedPrompt.length > MAX_AI_PROMPT_LENGTH) {
62
+ return failure(`AI prompt is capped at ${MAX_AI_PROMPT_LENGTH} characters after template resolution.`, details);
63
+ }
64
+ const messages = buildAiMessages({
65
+ resolvedPrompt,
66
+ exampleText: config.responseExample,
67
+ });
68
+ const maxTokens = Math.min(MAX_AI_MAX_TOKENS, Math.max(1, Math.round(config.maxTokens ?? DEFAULT_AI_MAX_TOKENS)));
69
+ const timeoutMs = Math.min(options.nodeTimeoutMs ?? MAX_AI_TIMEOUT_MS, Math.min(MAX_AI_TIMEOUT_MS, Math.max(1000, Math.round(config.timeoutMs ?? DEFAULT_AI_TIMEOUT_MS))));
70
+ // --- Provider call ----------------------------------------------------
71
+ const startedAtMs = Date.now();
72
+ let transportResult;
73
+ try {
74
+ transportResult = await withAbortAndTimeout(options.chatTransport({
75
+ connectionId: details.connectionId,
76
+ messages,
77
+ maxTokens,
78
+ signal: input.signal,
79
+ }), timeoutMs, `AI node ${input.stepId}`, input.signal);
80
+ }
81
+ catch (error) {
82
+ return failure(error instanceof Error ? error.message : "AI provider call failed.", details, Date.now() - startedAtMs);
83
+ }
84
+ const durationMs = Date.now() - startedAtMs;
85
+ details.provider = transportResult.provider ?? null;
86
+ details.model = transportResult.model ?? null;
87
+ details.tokensUsed =
88
+ typeof transportResult.tokensUsed === "number" ? transportResult.tokensUsed : null;
89
+ details.rawText = transportResult.text ?? null;
90
+ const rawText = (transportResult.text ?? "").trim();
91
+ if (!rawText) {
92
+ return failure("AI provider returned an empty reply.", details, durationMs);
93
+ }
94
+ // --- Tolerant parse + schema validation -------------------------------
95
+ let parsed;
96
+ try {
97
+ parsed = JSON.parse(extractJsonPayload(rawText));
98
+ }
99
+ catch {
100
+ return failure("AI reply is not valid JSON (even after repair). See the raw reply in the step result.", details, durationMs);
101
+ }
102
+ // Structural validation WITHOUT ajv — ajv compiles schemas via the
103
+ // Function constructor, which the Electron renderer's CSP (no
104
+ // 'unsafe-eval') refuses, so desktop-local runs would fail on a
105
+ // perfectly good reply.
106
+ const schemaFailures = validateAgainstExample(example.value, parsed);
107
+ if (schemaFailures.length > 0) {
108
+ const summary = schemaFailures.slice(0, 3).join("; ");
109
+ return failure(`AI reply did not match the expected format: ${summary}`, details, durationMs);
110
+ }
111
+ return {
112
+ outputData: parsed,
113
+ details,
114
+ durationMs,
115
+ failureMessage: null,
116
+ };
117
+ };
118
+ //# sourceMappingURL=ai-executor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-executor.js","sourceRoot":"","sources":["../../../src/scenario-runner/adapters/ai-executor.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,6EAA6E;AAC7E,0EAA0E;AAC1E,6EAA6E;AAC7E,6EAA6E;AAC7E,6EAA6E;AAC7E,gCAAgC;AAChC,EAAE;AACF,8EAA8E;AAC9E,yBAAyB;AAEzB,OAAO,EAAE,kBAAkB,EA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0,0 +1,13 @@
1
+ import type { ScenarioAiChatMessage } from "../../types.js";
2
+ export interface ParsedAiExample {
3
+ value: Record<string, unknown> | null;
4
+ error: string | null;
5
+ }
6
+ export declare const parseJsonExample: (exampleText: string) => ParsedAiExample;
7
+ export declare const deriveSchemaFromExample: (example: Record<string, unknown>) => Record<string, unknown>;
8
+ export declare const validateAgainstExample: (example: Record<string, unknown>, value: unknown) => string[];
9
+ export declare const buildAiMessages: ({ resolvedPrompt, exampleText, }: {
10
+ resolvedPrompt: string;
11
+ exampleText: string;
12
+ }) => ScenarioAiChatMessage[];
13
+ //# sourceMappingURL=aiExample.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aiExample.d.ts","sourceRoot":"","sources":["../../../../src/scenario-runner/adapters/helpers/aiExample.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAE5D,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACtC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAED,eAAO,MAAM,gBAAgB,GAAI,aAAa,MAAM,KAAG,eAqBtD,CAAC;AAsBF,eAAO,MAAM,uBAAuB,GAClC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC/B,MAAM,CAAC,MAAM,EAAE,OAAO,CAWxB,CAAC;AAyDF,eAAO,MAAM,sBAAsB,GACjC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,OAAO,OAAO,KACb,MAAM,EAcR,CAAC;AAKF,eAAO,MAAM,eAAe,GAAI,kCAG7B;IACD,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;CACrB,KAAG,qBAAqB,EAWxB,CAAC"}
@@ -0,0 +1,143 @@
1
+ // AI-node response-example helpers, shared by the executor, the condition
2
+ // suggestion builder, and host UIs:
3
+ // - parseJsonExample: tolerant parse of the user-authored JSON example
4
+ // - deriveSchemaFromExample: example -> lenient JSON Schema (top-level keys
5
+ // required, extras allowed; numbers never tighten to integers; nested
6
+ // objects recurse WITHOUT nested `required` so only the contract the
7
+ // downstream `{{Label.field}}` references depend on is enforced)
8
+ // - buildAiMessages: the fixed system instruction + resolved user prompt
9
+ import { extractJsonPayload } from "../../../ai/jsonRepair.js";
10
+ export const parseJsonExample = (exampleText) => {
11
+ const trimmed = (exampleText ?? "").trim();
12
+ if (!trimmed) {
13
+ return { value: null, error: "Response example is required." };
14
+ }
15
+ let parsed;
16
+ try {
17
+ parsed = JSON.parse(extractJsonPayload(trimmed));
18
+ }
19
+ catch {
20
+ return { value: null, error: "Response example is not valid JSON." };
21
+ }
22
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
23
+ return {
24
+ value: null,
25
+ error: "Response example must be a JSON object (e.g. {\"sentiment\": \"positive\"}).",
26
+ };
27
+ }
28
+ return { value: parsed, error: null };
29
+ };
30
+ const deriveValueSchema = (value) => {
31
+ if (value === null || value === undefined) {
32
+ return {}; // no constraint — the example gives no type signal
33
+ }
34
+ if (typeof value === "string")
35
+ return { type: "string" };
36
+ if (typeof value === "boolean")
37
+ return { type: "boolean" };
38
+ // Never "integer": an example value of 1 must not reject a reply of 0.9.
39
+ if (typeof value === "number")
40
+ return { type: "number" };
41
+ if (Array.isArray(value)) {
42
+ return value.length > 0
43
+ ? { type: "array", items: deriveValueSchema(value[0]) }
44
+ : { type: "array" };
45
+ }
46
+ const properties = {};
47
+ for (const [key, nested] of Object.entries(value)) {
48
+ properties[key] = deriveValueSchema(nested);
49
+ }
50
+ return { type: "object", properties, additionalProperties: true };
51
+ };
52
+ export const deriveSchemaFromExample = (example) => {
53
+ const properties = {};
54
+ for (const [key, value] of Object.entries(example)) {
55
+ properties[key] = deriveValueSchema(value);
56
+ }
57
+ return {
58
+ type: "object",
59
+ properties,
60
+ required: Object.keys(example),
61
+ additionalProperties: true,
62
+ };
63
+ };
64
+ // Direct structural validation of a parsed reply against the example — the
65
+ // SAME rules deriveSchemaFromExample encodes, but WITHOUT ajv: Ajv compiles
66
+ // schemas through the Function constructor, which a CSP that bans
67
+ // 'unsafe-eval' (the Electron renderer) refuses. Returns ajv-style failure
68
+ // messages; empty array = valid.
69
+ const validateValueAgainstExample = (path, exampleValue, actual, failures) => {
70
+ if (exampleValue === null || exampleValue === undefined) {
71
+ return; // the example gives no type signal
72
+ }
73
+ if (typeof exampleValue === "string") {
74
+ if (typeof actual !== "string")
75
+ failures.push(`${path} must be string`);
76
+ return;
77
+ }
78
+ if (typeof exampleValue === "boolean") {
79
+ if (typeof actual !== "boolean")
80
+ failures.push(`${path} must be boolean`);
81
+ return;
82
+ }
83
+ // Never integer-strict: an example value of 1 must not reject 0.9.
84
+ if (typeof exampleValue === "number") {
85
+ if (typeof actual !== "number" || !Number.isFinite(actual)) {
86
+ failures.push(`${path} must be number`);
87
+ }
88
+ return;
89
+ }
90
+ if (Array.isArray(exampleValue)) {
91
+ if (!Array.isArray(actual)) {
92
+ failures.push(`${path} must be array`);
93
+ return;
94
+ }
95
+ if (exampleValue.length > 0) {
96
+ actual.forEach((item, index) => validateValueAgainstExample(`${path}/${index}`, exampleValue[0], item, failures));
97
+ }
98
+ return;
99
+ }
100
+ // Nested object: type-check the properties that ARE present; nested keys
101
+ // are never required (mirrors the derived schema's lenient recursion).
102
+ if (typeof actual !== "object" || actual === null || Array.isArray(actual)) {
103
+ failures.push(`${path} must be object`);
104
+ return;
105
+ }
106
+ const record = actual;
107
+ for (const [key, nested] of Object.entries(exampleValue)) {
108
+ if (key in record) {
109
+ validateValueAgainstExample(`${path}/${key}`, nested, record[key], failures);
110
+ }
111
+ }
112
+ };
113
+ export const validateAgainstExample = (example, value) => {
114
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
115
+ return ["(root) must be a JSON object"];
116
+ }
117
+ const failures = [];
118
+ const record = value;
119
+ for (const [key, exampleValue] of Object.entries(example)) {
120
+ if (!(key in record)) {
121
+ failures.push(`(root) must have required property '${key}'`);
122
+ continue;
123
+ }
124
+ validateValueAgainstExample(`/${key}`, exampleValue, record[key], failures);
125
+ }
126
+ return failures;
127
+ };
128
+ // The word "JSON" in the system message also satisfies OpenAI's
129
+ // `response_format: json_object` requirement (it rejects prompts that never
130
+ // mention JSON).
131
+ export const buildAiMessages = ({ resolvedPrompt, exampleText, }) => [
132
+ {
133
+ role: "system",
134
+ content: [
135
+ "You are a step inside an automated API-testing scenario.",
136
+ "Reply with ONLY a single JSON object — no markdown, no code fences, no prose.",
137
+ "The reply must use the same top-level keys and value types as this example (values may differ):",
138
+ exampleText.trim(),
139
+ ].join("\n"),
140
+ },
141
+ { role: "user", content: resolvedPrompt },
142
+ ];
143
+ //# sourceMappingURL=aiExample.js.map