@exellix/ai-tasks 9.1.0 → 9.1.1

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 (171) hide show
  1. package/CHANGELOG.md +15 -4
  2. package/README.md +2 -2
  3. package/RUNTASK_REQUEST.md +17 -15
  4. package/dist/compile/compileTaskConfiguration.d.ts.map +1 -1
  5. package/dist/compile/compileTaskConfiguration.js +3 -0
  6. package/dist/compile/compileTaskConfiguration.js.map +1 -1
  7. package/dist/core/task-sdk.d.ts.map +1 -1
  8. package/dist/core/task-sdk.js +112 -166
  9. package/dist/core/task-sdk.js.map +1 -1
  10. package/dist/invocation/types.d.ts +1 -1
  11. package/dist/narrix/narrixUnitExecution.js +2 -2
  12. package/dist/narrix/narrixUnitExecution.js.map +1 -1
  13. package/dist/node-execution/buildRequestFromNodePlan.d.ts +4 -0
  14. package/dist/node-execution/buildRequestFromNodePlan.d.ts.map +1 -1
  15. package/dist/node-execution/buildRequestFromNodePlan.js +4 -13
  16. package/dist/node-execution/buildRequestFromNodePlan.js.map +1 -1
  17. package/dist/node-execution/compileProfessionalAnswerRequest.d.ts +2 -0
  18. package/dist/node-execution/compileProfessionalAnswerRequest.d.ts.map +1 -0
  19. package/dist/node-execution/compileProfessionalAnswerRequest.js +4 -0
  20. package/dist/node-execution/compileProfessionalAnswerRequest.js.map +1 -0
  21. package/dist/node-execution/rejectForbiddenWireFields.d.ts +2 -0
  22. package/dist/node-execution/rejectForbiddenWireFields.d.ts.map +1 -1
  23. package/dist/node-execution/rejectForbiddenWireFields.js +42 -7
  24. package/dist/node-execution/rejectForbiddenWireFields.js.map +1 -1
  25. package/dist/post-steps/audit/auditChecklistFuncxEnvelope.d.ts +19 -3
  26. package/dist/post-steps/audit/auditChecklistFuncxEnvelope.d.ts.map +1 -1
  27. package/dist/post-steps/audit/auditChecklistFuncxEnvelope.js +7 -1
  28. package/dist/post-steps/audit/auditChecklistFuncxEnvelope.js.map +1 -1
  29. package/dist/post-steps/audit/loadAuditTemplates.d.ts +2 -55
  30. package/dist/post-steps/audit/loadAuditTemplates.d.ts.map +1 -1
  31. package/dist/post-steps/audit/loadAuditTemplates.js +3 -38
  32. package/dist/post-steps/audit/loadAuditTemplates.js.map +1 -1
  33. package/dist/post-steps/audit/parseAuditFuncxOutput.d.ts +8 -0
  34. package/dist/post-steps/audit/parseAuditFuncxOutput.d.ts.map +1 -0
  35. package/dist/post-steps/audit/parseAuditFuncxOutput.js +62 -0
  36. package/dist/post-steps/audit/parseAuditFuncxOutput.js.map +1 -0
  37. package/dist/post-steps/audit/parseAuditOutput.d.ts +2 -0
  38. package/dist/post-steps/audit/parseAuditOutput.d.ts.map +1 -1
  39. package/dist/post-steps/audit/parseAuditOutput.js +56 -0
  40. package/dist/post-steps/audit/parseAuditOutput.js.map +1 -1
  41. package/dist/post-steps/audit/runAudit.d.ts.map +1 -1
  42. package/dist/post-steps/audit/runAudit.js +53 -113
  43. package/dist/post-steps/audit/runAudit.js.map +1 -1
  44. package/dist/post-steps/audit/runAuditFuncxCall.d.ts +18 -0
  45. package/dist/post-steps/audit/runAuditFuncxCall.d.ts.map +1 -0
  46. package/dist/post-steps/audit/runAuditFuncxCall.js +59 -0
  47. package/dist/post-steps/audit/runAuditFuncxCall.js.map +1 -0
  48. package/dist/synthesis/resolveSourceMaterial.d.ts.map +1 -1
  49. package/dist/synthesis/resolveSourceMaterial.js +14 -0
  50. package/dist/synthesis/resolveSourceMaterial.js.map +1 -1
  51. package/dist/types/task-types.d.ts +4 -3
  52. package/dist/types/task-types.d.ts.map +1 -1
  53. package/dist/utils/bridgeRunSkillGatewayMemory.d.ts.map +1 -1
  54. package/dist/utils/bridgeRunSkillGatewayMemory.js +1 -0
  55. package/dist/utils/bridgeRunSkillGatewayMemory.js.map +1 -1
  56. package/dist/utils/executionMemoryInputRecord.d.ts +12 -0
  57. package/dist/utils/executionMemoryInputRecord.d.ts.map +1 -0
  58. package/dist/utils/executionMemoryInputRecord.js +28 -0
  59. package/dist/utils/executionMemoryInputRecord.js.map +1 -0
  60. package/dist/utils/resolveAiProfileModel.d.ts +1 -1
  61. package/dist/utils/resolveAiProfileModel.d.ts.map +1 -1
  62. package/dist/utils/skillTemplateVariables.d.ts +3 -2
  63. package/dist/utils/skillTemplateVariables.d.ts.map +1 -1
  64. package/dist/utils/skillTemplateVariables.js +3 -2
  65. package/dist/utils/skillTemplateVariables.js.map +1 -1
  66. package/dist/validation/validateProfessionalAnswerContract.d.ts +8 -0
  67. package/dist/validation/validateProfessionalAnswerContract.d.ts.map +1 -0
  68. package/dist/validation/validateProfessionalAnswerContract.js +45 -0
  69. package/dist/validation/validateProfessionalAnswerContract.js.map +1 -0
  70. package/dist/validation/validateRunTaskConfig.d.ts.map +1 -1
  71. package/dist/validation/validateRunTaskConfig.js +2 -0
  72. package/dist/validation/validateRunTaskConfig.js.map +1 -1
  73. package/documenations/record-and-template-variables.md +21 -13
  74. package/documenations/run-task-execution-flow.md +1 -1
  75. package/documenations/upstream-feature-requests/README.md +9 -5
  76. package/documenations/upstream-feature-requests/ai-skills-orchestrator-invoke-contract-5.9.md +1 -1
  77. package/documenations/upstream-feature-requests/funcx-4.9.13-open-items.md +62 -0
  78. package/documenations/upstream-feature-requests/funcx-gap-analysis-cr-fr.md +401 -0
  79. package/documenations/upstream-feature-requests/funcx-pre-post-sidekick-actions.md +1 -0
  80. package/documenations/upstream-feature-requests/graph-engine-runtask-contract-alignment-investigation.md +370 -0
  81. package/documenations/upstream-feature-requests/xynthesis-ai-profiles-2.1-import-break.md +2 -2
  82. package/documenations/upstream-feature-requests/xynthesis-openrouter-wire-model-double-prefix-bug.md +1 -1
  83. package/documenations/upstream-feature-requests/xynthesis-orchestrator-invoke-contract-4.2.md +1 -1
  84. package/package.json +10 -9
  85. package/.docs/DOWNSTREAM_ENV.md +0 -42
  86. package/.docs/FEEDBACK_TO_CLIENT_DOWNSTREAM_FIXES.md +0 -64
  87. package/.docs/INTERMEDIATE_STEPS.md +0 -82
  88. package/.docs/activity-structure.md +0 -31
  89. package/.docs/ai-task-ai-scoping-spec.md +0 -338
  90. package/.docs/ai-tasks-model-profile-aliases-7x.md +0 -96
  91. package/.docs/blockers-and-issues.md +0 -346
  92. package/.docs/building-runTask-sdk.md +0 -659
  93. package/.docs/building-skill-execution-orchestrator.md +0 -968
  94. package/.docs/code-used-before/run-task.txt +0 -39
  95. package/.docs/code-used-before/task-executor.ts.old +0 -57
  96. package/.docs/code-used-before/test-run-task.ts.old +0 -42
  97. package/.docs/code-used-before/types.txt +0 -23
  98. package/.docs/env-ready-policy.md +0 -40
  99. package/.docs/flow-io/flow-README.md +0 -76
  100. package/.docs/flow-io/narrix.md +0 -124
  101. package/.docs/flow-io/web-scoping.md +0 -135
  102. package/.docs/flow-io/xynthesis-post.md +0 -154
  103. package/.docs/flow-io/xynthesis-pre.md +0 -181
  104. package/.docs/gap-analysis.md +0 -201
  105. package/.docs/integration-facts-ai-tasks.md +0 -109
  106. package/.docs/investigation/ai-skills.md +0 -170
  107. package/.docs/investigation/external-packages-assignments.md +0 -66
  108. package/.docs/investigation/integration-summary.md +0 -20
  109. package/.docs/investigation/narrix-catalox.md +0 -29
  110. package/.docs/investigation/workplan-close-graph-engine-gaps.md +0 -101
  111. package/.docs/logging-stack.md +0 -30
  112. package/.docs/memory-narrix-adapter-developer-guide.md +0 -402
  113. package/.docs/memory-narrix-adapter-requirements.md +0 -112
  114. package/.docs/narrix-context-consumption-gap.md +0 -184
  115. package/.docs/narrix-context-downstream-report.md +0 -30
  116. package/.docs/narrix-ingest-and-packs-library-spec.md +0 -240
  117. package/.docs/narrix-record-input-current-design.md +0 -48
  118. package/.docs/pacakge.md +0 -48
  119. package/.docs/possible-components/README.md +0 -11
  120. package/.docs/possible-components/integration/README.md +0 -10
  121. package/.docs/possible-components/integration/gaps-when-merging.md +0 -16
  122. package/.docs/possible-components/integration/platform.md +0 -54
  123. package/.docs/possible-components/integration/reintegrate-into-ai-tasks.md +0 -26
  124. package/.docs/possible-components/integration/roadmap-and-checklists.md +0 -54
  125. package/.docs/possible-components/post-component/README.md +0 -18
  126. package/.docs/possible-components/post-component/builder-guide.md +0 -175
  127. package/.docs/possible-components/post-component/gaps-and-artifacts.md +0 -52
  128. package/.docs/possible-components/post-component/handler-audit.md +0 -47
  129. package/.docs/possible-components/post-component/handler-polish.md +0 -41
  130. package/.docs/possible-components/post-component/unified-protocol.md +0 -59
  131. package/.docs/possible-components/pre-component/README.md +0 -22
  132. package/.docs/possible-components/pre-component/builder-guide.md +0 -127
  133. package/.docs/possible-components/pre-component/gaps-and-artifacts.md +0 -35
  134. package/.docs/possible-components/pre-component/handler-ai-scoping.md +0 -45
  135. package/.docs/possible-components/pre-component/handler-narrix-preprocessor.md +0 -49
  136. package/.docs/possible-components/pre-component/handler-narrix-system2.md +0 -35
  137. package/.docs/possible-components/pre-component/handler-synthesized-context.md +0 -65
  138. package/.docs/possible-components/pre-component/handler-web-scope.md +0 -29
  139. package/.docs/possible-components/pre-component/unified-protocol.md +0 -89
  140. package/.docs/prefer-openrouter-routing-policy.md +0 -114
  141. package/.docs/questions-for-ai-skills.md +0 -123
  142. package/.docs/realtime-narrixing-gap-analysis.md +0 -40
  143. package/.docs/realtime-narrixing.md +0 -433
  144. package/.docs/run-context-object.md +0 -32
  145. package/.docs/session-id-usage.md +0 -26
  146. package/.docs/skill-library-spec.md +0 -249
  147. package/.docs/synthesized-context-strategy-spec.md +0 -906
  148. package/.docs/upstream-issue/2026-03-21_woroces-ai-tasks_ISSUE-006_web-scope-question-from-cni-entity.md +0 -46
  149. package/.docs/web-scopper-embed.md +0 -93
  150. package/.docs/xynthesis-wiring-and-io.md +0 -12
  151. package/documenations/activix-feature-request-identity.md +0 -123
  152. package/documenations/bug-report-xynthesis-and-synthesis-call.md +0 -217
  153. package/documenations/feature-request-ai-skills-raw-template-access.md +0 -82
  154. package/documenations/feature-request-athenix-core-directive.md +0 -145
  155. package/documenations/feature-request-athenix-token-extraction.md +0 -124
  156. package/documenations/funcx-upstream-github-issues-draft.md +0 -153
  157. package/documenations/identity-metadata-contract.md +0 -165
  158. package/documenations/run-task-single-run-checklist.md +0 -109
  159. package/documenations/sessions/2026-06-08-subnets-model-resolution/CR-1-no-concrete-wire-in-graph-plans.md +0 -93
  160. package/documenations/sessions/2026-06-08-subnets-model-resolution/CR-2-skillModel-profile-only-at-storage.md +0 -88
  161. package/documenations/sessions/2026-06-08-subnets-model-resolution/CR-3-reject-concrete-models-in-catalog-rows.md +0 -76
  162. package/documenations/sessions/2026-06-08-subnets-model-resolution/FR-1-suggested-profile-in-catalogs.md +0 -96
  163. package/documenations/sessions/2026-06-08-subnets-model-resolution/FR-2-graph-engine-failure-phase-attribution.md +0 -92
  164. package/documenations/sessions/2026-06-08-subnets-model-resolution/INVESTIGATION-original-bug.md +0 -182
  165. package/documenations/sessions/2026-06-08-subnets-model-resolution/PROBLEM.md +0 -236
  166. package/documenations/sessions/2026-06-08-subnets-model-resolution/README.md +0 -11
  167. package/documenations/sessions/2026-06-08-subnets-model-resolution/funcx-test-resolveModel.cheapDefaultWireSlug.test.ts +0 -117
  168. package/documenations/upstream-feature-requests/ai-tasks-wrap-up-after-upstream.md +0 -129
  169. package/documenations/upstream-feedback-request-shape-clarification.md +0 -101
  170. package/documenations/web-context-precedence.md +0 -33
  171. package/documenations/xynthesis-activix-telemetry.md +0 -28
@@ -10,6 +10,7 @@ import { buildRunTaskResultMetaFromModelId } from "../invocation/buildRunTaskRes
10
10
  import { logRunTaskInvocationPlan } from "../observability/logLlmProviderInvocation.js";
11
11
  import { registerBuiltInLocalTasks } from "../localTasks/index.js";
12
12
  import { getByPath } from "../utils/jsonPaths.js";
13
+ import { readInvokePayloadRecord } from "../utils/executionMemoryInputRecord.js";
13
14
  import { passthroughJobTemplateVariables } from "../utils/skillTemplateVariables.js";
14
15
  import { emitRunTaskRequestWarnings } from "../utils/runTaskRequestShape.js";
15
16
  import { configureFuncxLogging } from "@x12i/funcx";
@@ -32,14 +33,13 @@ import { getActivixClient } from "../activix/activixClient.js";
32
33
  import { withPhaseRecord } from "../activix/phaseTracking.js";
33
34
  import { activixOuterTier } from "@x12i/activix";
34
35
  import { createDebugTraceCollector, traceWrap } from "../observability/debugTrace.js";
35
- import { loadSynthesisTemplates, buildSynthesisSystemPrompt, buildSynthesisUserPrompt, resolveSourceMaterial, resolveSourceMaterialParts, getRenderedTemplates, buildSynthesizedContextMarkdown, resolveSynthesisQuestion, runStructuredSynthesisGatewayCallRobust, getContextSynthesizer, normalizeAndValidateSynthesizedPayload, discoverTemplateCores, } from "../synthesis/index.js";
36
+ import { resolveSourceMaterial, resolveSourceMaterialParts, getRenderedTemplates, buildSynthesizedContextMarkdown, resolveSynthesisQuestion, runStructuredSynthesisGatewayCallRobust, getContextSynthesizer, normalizeAndValidateSynthesizedPayload, discoverTemplateCores, } from "../synthesis/index.js";
36
37
  import { resolveOutputExpectation as resolveOutputExpectationXynthesis } from "@exellix/xynthesis/ai-actions";
37
38
  import { llmCallEnvPrefix, resolveLlmCall } from "../post-steps/resolvePostStepConfig.js";
38
39
  import { buildXynthesisWorkScopeIdentity } from "../internal/buildXynthesisWorkScopeIdentity.js";
39
40
  import { getPostActionModelFromSlots, prepareMainSkillModelConfigForInvoke, resolvePreActionModel, } from "../utils/routeModelConfigSlots.js";
40
41
  import { assertPhaseModelAlias } from "../errors/modelConfigRequiredError.js";
41
42
  import { isRunTaskModelResolutionError } from "../errors/runTaskModelResolutionError.js";
42
- import { runPostStepLlmCall } from "../internal/runPostStepLlmCall.js";
43
43
  registerBuiltInLocalTasks();
44
44
  const DEFAULT_SYNTH_INPUT_MAX_CHARS = 200_000;
45
45
  function maxSynthesizedInputChars() {
@@ -260,10 +260,13 @@ function coerceTaskMemoryNarrixToAttachment(taskMemoryNarrix) {
260
260
  };
261
261
  }
262
262
  function resolveSynthesisMode(config) {
263
- if (config.synthesisMode === "structured" || config.synthesisMode === "markdown") {
264
- return config.synthesisMode;
263
+ if (config.synthesisMode === "structured") {
264
+ return "structured";
265
265
  }
266
- return "markdown";
266
+ if (config.synthesisMode === "markdown") {
267
+ return "structured";
268
+ }
269
+ return "structured";
267
270
  }
268
271
  function detectedTemplateCoresFromExecutionMemory(executionMemory) {
269
272
  const artifact = executionMemory?.synthesizedContext;
@@ -437,6 +440,18 @@ function buildSynthesizerInputMaterial(strategy, resolveOpts) {
437
440
  const parts = resolveSourceMaterialParts(resolveOpts);
438
441
  return { sourceMaterial, parts };
439
442
  }
443
+ function buildPreSynthesisGateway(request) {
444
+ return {
445
+ aiRequestId: randomUUID(),
446
+ agentId: typeof request.agentId === "string"
447
+ ? request.agentId
448
+ : (request.skillKey ?? "ai-tasks"),
449
+ sessionId: typeof request.taskId === "string" && request.taskId.trim()
450
+ ? request.taskId.trim()
451
+ : randomUUID(),
452
+ temperature: 0.7,
453
+ };
454
+ }
440
455
  function safeResolveSynthesisQuestion(synthesisRequest, config, renderedPrompt) {
441
456
  try {
442
457
  const q = resolveSynthesisQuestion(synthesisRequest, config, renderedPrompt);
@@ -1083,14 +1098,18 @@ export class WorexClientTasks {
1083
1098
  };
1084
1099
  }
1085
1100
  const execMem = (enrichedBundle.executionMemory ?? memoryBundle.executionMemory);
1086
- const recordRaw = isRecord(execMem?.input) ? execMem.input.raw : undefined;
1101
+ const recordRaw = readInvokePayloadRecord(request);
1087
1102
  const recordMd = recordRaw !== undefined
1088
- ? `## Record (executionMemory.input.raw)\n\n\`\`\`json\n${truncate(JSON.stringify(recordRaw, null, 2), maxOutputLength ? Math.min(maxOutputLength, 60_000) : 60_000)}\n\`\`\`\n`
1103
+ ? `## Record (input)\n\n\`\`\`json\n${truncate(JSON.stringify(recordRaw, null, 2), maxOutputLength ? Math.min(maxOutputLength, 60_000) : 60_000)}\n\`\`\`\n`
1089
1104
  : "";
1090
1105
  const webContextEntry = execMem?.webContext;
1091
1106
  const webMd = buildWebContextEvidenceMarkdown(webContextEntry, config.webEvidence);
1092
- const { system: systemTemplate, user: userTemplate } = await loadSynthesisTemplates();
1093
- const systemPrompt = buildSynthesisSystemPrompt(systemTemplate, config.synthesisPromptOverride, config.customSynthesizingGuidelines);
1107
+ const { templateCores } = discoverTemplateCores({
1108
+ templates: [
1109
+ { name: "instructions", content: rawInstructions },
1110
+ { name: "prompt", content: rawPrompt },
1111
+ ],
1112
+ });
1094
1113
  const extractWebEvidence = () => {
1095
1114
  if (!isRecord(webContextEntry))
1096
1115
  return { webUnavailableReason: "webContext missing" };
@@ -1153,58 +1172,48 @@ export class WorexClientTasks {
1153
1172
  if (allowWeb)
1154
1173
  materialParts.push(webMd || "## Web sources (primary evidence)\n\n[unavailable]");
1155
1174
  const perQuestionMaterial = materialParts.join("\n");
1156
- const userPrompt = buildSynthesisUserPrompt(renderedInstructions, renderedPrompt, perQuestionMaterial, userTemplate);
1157
1175
  let synthesisText;
1158
1176
  if (allowWeb && !hasWeb && !allowRecord) {
1159
1177
  const reason = webEvidence.webUnavailableReason ?? "web scoping unavailable";
1160
1178
  synthesisText = `Unknown — web-derived context unavailable (${reason}).`;
1161
1179
  }
1162
1180
  else if (allowRecord && !hasRecord && !allowWeb) {
1163
- synthesisText = `Unknown — record-derived context unavailable (missing executionMemory.input.raw).`;
1181
+ synthesisText = `Unknown — record-derived context unavailable (missing executionMemory.input).`;
1164
1182
  }
1165
1183
  else if (allowRecord && allowWeb && !hasRecord && !hasWeb) {
1166
1184
  const reason = webEvidence.webUnavailableReason ?? "web scoping unavailable";
1167
1185
  synthesisText =
1168
- `Unknown — no inputs available (missing executionMemory.input.raw; web unavailable: ${reason}).`;
1186
+ `Unknown — no inputs available (missing executionMemory.input; web unavailable: ${reason}).`;
1169
1187
  }
1170
1188
  else {
1171
- const res = await runPostStepLlmCall({
1172
- systemPrompt,
1173
- userPrompt,
1174
- llmCall: synthLlmCall,
1175
- stage: "pre-synthesis-question",
1176
- stepId: `questionDriven:${id}`,
1189
+ const payload = await runStructuredSynthesisGatewayCallRobust({
1190
+ templateCores,
1191
+ question: question.trim(),
1192
+ localMarkdown: perQuestionMaterial,
1193
+ supportingMarkdown: "",
1194
+ renderedInstructions,
1195
+ renderedPrompt,
1196
+ model,
1197
+ timeoutMs,
1198
+ maxOutputLength,
1199
+ outputExpectation: synthLlmCall.outputExpectation,
1200
+ reasoningEffort: synthLlmCall.reasoningEffort,
1201
+ topP: synthLlmCall.topP,
1202
+ executionMode: traceCollector ? "trace" : undefined,
1177
1203
  jobId: request.jobId,
1178
1204
  taskId: request.taskId,
1179
1205
  agentId: request.agentId,
1180
- workScopeIdentity,
1181
- traceCollector,
1182
- traceTask: traceCollector
1183
- ? {
1184
- taskType: "pre-execution",
1185
- details: "synthesized-context question call",
1186
- modelUsed: model ?? null,
1187
- metadata: {
1188
- jobId: request.jobId,
1189
- taskId: request.taskId,
1190
- skillKey: request.skillKey,
1191
- phase: "pipeline_pre",
1192
- preStepType: "synthesized-context",
1193
- step: { phase: "pre", type: "synthesized-context", stepId: `questionDriven:${id}` },
1194
- questionId: id,
1195
- },
1196
- }
1197
- : undefined,
1198
- observationSink: synthObservationSink,
1206
+ identity: workScopeIdentity,
1207
+ gateway: buildPreSynthesisGateway(request),
1199
1208
  });
1200
- synthesisText = res.text;
1209
+ synthesisText = buildSynthesizedContextMarkdown(payload);
1201
1210
  }
1202
1211
  answers[id] = {
1203
1212
  question: question.trim(),
1204
1213
  source,
1205
1214
  synthesis: synthesisText,
1206
1215
  evidence: {
1207
- recordPaths: allowRecord ? ["executionMemory.input.raw"] : undefined,
1216
+ recordPaths: allowRecord ? ["executionMemory.input"] : undefined,
1208
1217
  webScopeIds: allowWeb ? webEvidence.webScopeIds : undefined,
1209
1218
  sources: allowWeb ? webEvidence.sources : undefined,
1210
1219
  },
@@ -1231,148 +1240,85 @@ export class WorexClientTasks {
1231
1240
  };
1232
1241
  }
1233
1242
  const synthesisMode = resolveSynthesisMode(config);
1234
- if (synthesisMode === "structured") {
1235
- const parts = sourceMaterialParts;
1236
- const question = safeResolveSynthesisQuestion(synthesisRequest, config, renderedPrompt);
1237
- const { templateCores } = discoverTemplateCores({
1238
- templates: [
1239
- { name: "instructions", content: rawInstructions },
1240
- { name: "prompt", content: rawPrompt },
1241
- ],
1242
- });
1243
- if (templateCores.length === 0) {
1244
- if (!rawInstructions.trim() && !rawPrompt.trim()) {
1245
- throw new Error(`structured synthesized-context could not resolve raw instructions/prompt templates for skillKey: ${request.skillKey}. ` +
1246
- `Ensure ai-skills content registry is available for resolveRawTemplate().`);
1247
- }
1248
- throw new Error(`structured synthesized-context requires at least one template core token in instructions or prompt. skillKey: ${request.skillKey}`);
1243
+ const parts = sourceMaterialParts;
1244
+ const question = safeResolveSynthesisQuestion(synthesisRequest, config, renderedPrompt);
1245
+ const { templateCores } = discoverTemplateCores({
1246
+ templates: [
1247
+ { name: "instructions", content: rawInstructions },
1248
+ { name: "prompt", content: rawPrompt },
1249
+ ],
1250
+ });
1251
+ if (templateCores.length === 0) {
1252
+ if (!rawInstructions.trim() && !rawPrompt.trim()) {
1253
+ throw new Error(`structured synthesized-context could not resolve raw instructions/prompt templates for skillKey: ${request.skillKey}. ` +
1254
+ `Ensure ai-skills content registry is available for resolveRawTemplate().`);
1249
1255
  }
1250
- const validateOpts = {
1251
- expectedTemplateCores: templateCores,
1252
- expectedQuestion: question,
1253
- maxItemsPerSide: config.structuredMaxItemsPerSide,
1254
- maxItemContentChars: config.structuredMaxItemContentChars,
1255
- };
1256
- try {
1257
- const custom = getContextSynthesizer();
1258
- let payload;
1259
- if (custom) {
1260
- payload = await custom.synthesize({
1261
- templateCores,
1262
- question,
1263
- localRaw: parts.localMarkdown,
1264
- supportingRaw: parts.supportingMarkdown,
1265
- metadata: {
1266
- renderedInstructions,
1267
- renderedPrompt,
1268
- templateCores,
1269
- skillKey: request.skillKey,
1270
- jobId: request.jobId,
1271
- taskId: request.taskId,
1272
- },
1273
- });
1274
- payload = normalizeAndValidateSynthesizedPayload(payload, validateOpts);
1275
- }
1276
- else {
1277
- payload = await runStructuredSynthesisGatewayCallRobust({
1278
- question,
1279
- localMarkdown: parts.localMarkdown,
1280
- supportingMarkdown: parts.supportingMarkdown,
1256
+ throw new Error(`structured synthesized-context requires at least one template core token in instructions or prompt. skillKey: ${request.skillKey}`);
1257
+ }
1258
+ const validateOpts = {
1259
+ expectedTemplateCores: templateCores,
1260
+ expectedQuestion: question,
1261
+ maxItemsPerSide: config.structuredMaxItemsPerSide,
1262
+ maxItemContentChars: config.structuredMaxItemContentChars,
1263
+ };
1264
+ try {
1265
+ const custom = getContextSynthesizer();
1266
+ let payload;
1267
+ if (custom) {
1268
+ payload = await custom.synthesize({
1269
+ templateCores,
1270
+ question,
1271
+ localRaw: parts.localMarkdown,
1272
+ supportingRaw: parts.supportingMarkdown,
1273
+ metadata: {
1281
1274
  renderedInstructions,
1282
1275
  renderedPrompt,
1283
- templatesBasePath: config.templatesBasePath,
1284
- synthesisPromptOverride: config.synthesisPromptOverride,
1285
- customSynthesizingGuidelines: config.customSynthesizingGuidelines,
1286
- model: model,
1287
- timeoutMs: timeoutMs,
1288
- maxOutputLength: maxOutputLength,
1289
- // Caller-supplied outputExpectation overrides the per-action default in the structured-repair path.
1290
- outputExpectation: synthLlmCall.outputExpectation,
1291
- reasoningEffort: synthLlmCall.reasoningEffort,
1292
- topP: synthLlmCall.topP,
1293
- // Forward trace mode so the structured gateway returns a `debugTrace` (lifted into observations elsewhere).
1294
- executionMode: traceCollector ? "trace" : undefined,
1276
+ templateCores,
1277
+ skillKey: request.skillKey,
1295
1278
  jobId: request.jobId,
1296
1279
  taskId: request.taskId,
1297
- agentId: request.agentId,
1298
- identity: workScopeIdentity,
1299
- });
1300
- }
1301
- const contextMarkdown = buildSynthesizedContextMarkdown(payload);
1302
- return {
1303
- contextMarkdown,
1304
- artifact: {
1305
- templateCores,
1306
- question,
1307
- mode: synthesisMode,
1308
- payload,
1309
- contextMarkdown,
1310
1280
  },
1311
- synthesizedInput: buildSynthesizedInputArtifact(synthesisMode, sourceMaterial, parts, {
1312
- question,
1313
- templateCores,
1314
- }),
1315
- synthesizedContextLlmCalls: traceCollector ? synthLlmCalls : undefined,
1316
- };
1281
+ });
1282
+ payload = normalizeAndValidateSynthesizedPayload(payload, validateOpts);
1317
1283
  }
1318
- catch (e) {
1319
- if (config.fallbackToDirect === true)
1320
- return {
1321
- contextMarkdown: "",
1322
- synthesizedContextLlmCalls: traceCollector ? synthLlmCalls : undefined,
1323
- };
1324
- throw e;
1284
+ else {
1285
+ payload = await runStructuredSynthesisGatewayCallRobust({
1286
+ templateCores,
1287
+ question,
1288
+ localMarkdown: parts.localMarkdown,
1289
+ supportingMarkdown: parts.supportingMarkdown,
1290
+ renderedInstructions,
1291
+ renderedPrompt,
1292
+ templatesBasePath: config.templatesBasePath,
1293
+ synthesisPromptOverride: config.synthesisPromptOverride,
1294
+ customSynthesizingGuidelines: config.customSynthesizingGuidelines,
1295
+ model: model,
1296
+ timeoutMs: timeoutMs,
1297
+ maxOutputLength: maxOutputLength,
1298
+ // Caller-supplied outputExpectation overrides the per-action default in the structured-repair path.
1299
+ outputExpectation: synthLlmCall.outputExpectation,
1300
+ reasoningEffort: synthLlmCall.reasoningEffort,
1301
+ topP: synthLlmCall.topP,
1302
+ // Forward trace mode so the structured gateway returns a `debugTrace` (lifted into observations elsewhere).
1303
+ executionMode: traceCollector ? "trace" : undefined,
1304
+ jobId: request.jobId,
1305
+ taskId: request.taskId,
1306
+ agentId: request.agentId,
1307
+ identity: workScopeIdentity,
1308
+ gateway: buildPreSynthesisGateway(request),
1309
+ });
1325
1310
  }
1326
- }
1327
- const { system: systemTemplate, user: userTemplate } = await loadSynthesisTemplates();
1328
- const systemPrompt = buildSynthesisSystemPrompt(systemTemplate, config.synthesisPromptOverride, config.customSynthesizingGuidelines);
1329
- const userPrompt = buildSynthesisUserPrompt(renderedInstructions, renderedPrompt, sourceMaterial, userTemplate);
1330
- try {
1331
- const { text: contextMarkdown } = await runPostStepLlmCall({
1332
- systemPrompt,
1333
- userPrompt,
1334
- extraMaterial: sourceMaterial,
1335
- llmCall: synthLlmCall,
1336
- stage: "pre-synthesis-markdown",
1337
- jobId: request.jobId,
1338
- taskId: request.taskId,
1339
- agentId: request.agentId,
1340
- workScopeIdentity,
1341
- traceCollector,
1342
- traceTask: traceCollector
1343
- ? {
1344
- taskType: "pre-execution",
1345
- details: "synthesized-context markdown call",
1346
- modelUsed: model ?? null,
1347
- metadata: {
1348
- jobId: request.jobId,
1349
- taskId: request.taskId,
1350
- skillKey: request.skillKey,
1351
- phase: "pipeline_pre",
1352
- preStepType: "synthesized-context",
1353
- step: { phase: "pre", type: "synthesized-context", stepId: "markdown" },
1354
- },
1355
- }
1356
- : undefined,
1357
- observationSink: synthObservationSink,
1358
- });
1359
- const question = safeResolveSynthesisQuestion(synthesisRequest, config, renderedPrompt);
1360
- const { templateCores } = discoverTemplateCores({
1361
- templates: [
1362
- { name: "instructions", content: rawInstructions },
1363
- { name: "prompt", content: rawPrompt },
1364
- ],
1365
- });
1311
+ const contextMarkdown = buildSynthesizedContextMarkdown(payload);
1366
1312
  return {
1367
1313
  contextMarkdown,
1368
1314
  artifact: {
1369
1315
  templateCores,
1370
1316
  question,
1371
- mode: "markdown",
1372
- payload: { kind: "markdown-synthesis" },
1317
+ mode: synthesisMode,
1318
+ payload,
1373
1319
  contextMarkdown,
1374
1320
  },
1375
- synthesizedInput: buildSynthesizedInputArtifact("markdown", sourceMaterial, sourceMaterialParts, {
1321
+ synthesizedInput: buildSynthesizedInputArtifact(synthesisMode, sourceMaterial, parts, {
1376
1322
  question,
1377
1323
  templateCores,
1378
1324
  }),