stageflow 0.42.0 → 0.44.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 (275) hide show
  1. package/README.md +12 -3
  2. package/dist/agent/activity.d.ts +18 -0
  3. package/dist/agent/claudeAdapter.js +7 -0
  4. package/dist/agent/claudeTools.d.ts +27 -18
  5. package/dist/agent/claudeTools.js +54 -15
  6. package/dist/agent/compactionEvents.d.ts +34 -0
  7. package/dist/agent/compactionEvents.js +37 -0
  8. package/dist/agent/openRouterRouting.d.ts +7 -0
  9. package/dist/agent/openRouterRouting.js +23 -0
  10. package/dist/agent/piAdapter.d.ts +6 -0
  11. package/dist/agent/piAdapter.js +128 -27
  12. package/dist/agent/piSettings.d.ts +7 -0
  13. package/dist/agent/piSettings.js +9 -0
  14. package/dist/agent/sandboxPiTools.d.ts +3 -1
  15. package/dist/agent/sandboxPiTools.js +8 -2
  16. package/dist/agent/stageTurnDriver.d.ts +11 -2
  17. package/dist/agent/stageTurnDriver.js +45 -4
  18. package/dist/agent/toolOutputBudget.d.ts +15 -1
  19. package/dist/agent/toolOutputBudget.js +18 -0
  20. package/dist/agent/toolOutputBudgetExtension.d.ts +2 -0
  21. package/dist/agent/toolOutputBudgetExtension.js +40 -3
  22. package/dist/agents/authorChat.d.ts +1 -0
  23. package/dist/agents/authorChat.js +7 -0
  24. package/dist/agents/authorSessionStore.d.ts +3 -0
  25. package/dist/agents/authorSessionStore.js +17 -2
  26. package/dist/agents/hostContext.d.ts +1 -1
  27. package/dist/agents/runtime/piRuntime.d.ts +5 -1
  28. package/dist/agents/runtime/piRuntime.js +46 -12
  29. package/dist/agents/service.js +3 -2
  30. package/dist/agents/sessions.js +3 -1
  31. package/dist/compaction/directives.d.ts +18 -0
  32. package/dist/compaction/directives.js +119 -0
  33. package/dist/compaction/extension.d.ts +20 -0
  34. package/dist/compaction/extension.js +78 -0
  35. package/dist/compaction/mask.d.ts +18 -0
  36. package/dist/compaction/mask.js +155 -0
  37. package/dist/compaction/pin.d.ts +21 -0
  38. package/dist/compaction/pin.js +270 -0
  39. package/dist/compaction/scrub.d.ts +7 -0
  40. package/dist/compaction/scrub.js +26 -0
  41. package/dist/compaction/sessionWiring.d.ts +22 -0
  42. package/dist/compaction/sessionWiring.js +26 -0
  43. package/dist/compaction/summarize.d.ts +79 -0
  44. package/dist/compaction/summarize.js +171 -0
  45. package/dist/compaction/toolPolicy.d.ts +3 -0
  46. package/dist/compaction/toolPolicy.js +33 -0
  47. package/dist/compaction/types.d.ts +45 -0
  48. package/dist/compaction/types.js +7 -0
  49. package/dist/compaction/workingState.d.ts +56 -0
  50. package/dist/compaction/workingState.js +198 -0
  51. package/dist/config/createPipeline.js +2 -0
  52. package/dist/config/createTrigger.js +7 -1
  53. package/dist/config/ensureCatalogScanRoot.d.ts +2 -0
  54. package/dist/config/ensureCatalogScanRoot.js +6 -0
  55. package/dist/config/evalCatalog.js +30 -2
  56. package/dist/config/githubTriggerAction.d.ts +8 -0
  57. package/dist/config/githubTriggerAction.js +29 -0
  58. package/dist/config/hostConfig.js +2 -0
  59. package/dist/config/loadEval.js +21 -3
  60. package/dist/config/pipelineNeeds.d.ts +2 -0
  61. package/dist/config/pipelineNeeds.js +16 -3
  62. package/dist/config/pipelineRoute.js +5 -4
  63. package/dist/config/validateCatalog.d.ts +1 -1
  64. package/dist/config/validateCatalog.js +12 -0
  65. package/dist/config/validateEval.js +43 -2
  66. package/dist/config/writeEval.js +2 -2
  67. package/dist/envelope/assertEmittedArtifacts.d.ts +12 -0
  68. package/dist/envelope/assertEmittedArtifacts.js +43 -0
  69. package/dist/envelope/preEmitChecks.d.ts +3 -0
  70. package/dist/evals/constants.d.ts +3 -1
  71. package/dist/evals/constants.js +3 -1
  72. package/dist/evals/engine/FakeEngine.d.ts +1 -1
  73. package/dist/evals/engine/FakeEngine.js +2 -1
  74. package/dist/evals/engine/promptfoo/PromptfooEngine.d.ts +1 -1
  75. package/dist/evals/engine/promptfoo/PromptfooEngine.js +2 -1
  76. package/dist/evals/engine/promptfoo/generate.d.ts +1 -1
  77. package/dist/evals/engine/promptfoo/generate.js +11 -8
  78. package/dist/evals/engine/promptfoo/rubricPrompt.d.ts +1 -1
  79. package/dist/evals/engine/promptfoo/rubricPrompt.js +5 -3
  80. package/dist/evals/manager.d.ts +13 -0
  81. package/dist/evals/manager.js +10 -2
  82. package/dist/evals/plan.d.ts +8 -1
  83. package/dist/evals/plan.js +28 -9
  84. package/dist/evals/planInternalAgent.d.ts +19 -0
  85. package/dist/evals/planInternalAgent.js +205 -0
  86. package/dist/evals/read/api.d.ts +12 -0
  87. package/dist/evals/read/api.js +5 -0
  88. package/dist/evals/read/list.js +10 -1
  89. package/dist/evals/read/runs.d.ts +5 -0
  90. package/dist/evals/read/runs.js +7 -1
  91. package/dist/evals/runner/caseRunner.d.ts +2 -1
  92. package/dist/evals/runner/caseRunner.js +16 -5
  93. package/dist/evals/runner/internalAgentCaseRunner.d.ts +6 -0
  94. package/dist/evals/runner/internalAgentCaseRunner.js +250 -0
  95. package/dist/evals/snapshot.d.ts +10 -2
  96. package/dist/evals/snapshot.js +8 -3
  97. package/dist/evals/types.d.ts +12 -2
  98. package/dist/evals/types.js +4 -1
  99. package/dist/guide/cardContract.d.ts +133 -0
  100. package/dist/guide/cardContract.js +156 -0
  101. package/dist/guide/chat.d.ts +45 -0
  102. package/dist/guide/chat.js +378 -0
  103. package/dist/guide/knowledge/index.d.ts +14 -0
  104. package/dist/guide/knowledge/index.js +109 -0
  105. package/dist/guide/knowledge/topics/agents.d.ts +2 -0
  106. package/dist/guide/knowledge/topics/agents.js +58 -0
  107. package/dist/guide/knowledge/topics/bestPractices.d.ts +2 -0
  108. package/dist/guide/knowledge/topics/bestPractices.js +67 -0
  109. package/dist/guide/knowledge/topics/connections.d.ts +2 -0
  110. package/dist/guide/knowledge/topics/connections.js +66 -0
  111. package/dist/guide/knowledge/topics/consoleMap.d.ts +2 -0
  112. package/dist/guide/knowledge/topics/consoleMap.js +55 -0
  113. package/dist/guide/knowledge/topics/evals.d.ts +2 -0
  114. package/dist/guide/knowledge/topics/evals.js +72 -0
  115. package/dist/guide/knowledge/topics/limitations.d.ts +2 -0
  116. package/dist/guide/knowledge/topics/limitations.js +84 -0
  117. package/dist/guide/knowledge/topics/mcpSkillsBrowser.d.ts +2 -0
  118. package/dist/guide/knowledge/topics/mcpSkillsBrowser.js +57 -0
  119. package/dist/guide/knowledge/topics/memories.d.ts +2 -0
  120. package/dist/guide/knowledge/topics/memories.js +63 -0
  121. package/dist/guide/knowledge/topics/modelsAndProviders.d.ts +2 -0
  122. package/dist/guide/knowledge/topics/modelsAndProviders.js +56 -0
  123. package/dist/guide/knowledge/topics/overview.d.ts +2 -0
  124. package/dist/guide/knowledge/topics/overview.js +56 -0
  125. package/dist/guide/knowledge/topics/pipelines.d.ts +2 -0
  126. package/dist/guide/knowledge/topics/pipelines.js +93 -0
  127. package/dist/guide/knowledge/topics/stages.d.ts +2 -0
  128. package/dist/guide/knowledge/topics/stages.js +54 -0
  129. package/dist/guide/knowledge/topics/tasks.d.ts +2 -0
  130. package/dist/guide/knowledge/topics/tasks.js +52 -0
  131. package/dist/guide/knowledge/topics/triggers.d.ts +2 -0
  132. package/dist/guide/knowledge/topics/triggers.js +68 -0
  133. package/dist/guide/knowledge/topics/troubleshooting.d.ts +2 -0
  134. package/dist/guide/knowledge/topics/troubleshooting.js +85 -0
  135. package/dist/guide/knowledgeTools.d.ts +2 -0
  136. package/dist/guide/knowledgeTools.js +56 -0
  137. package/dist/guide/showUi.d.ts +6 -0
  138. package/dist/guide/showUi.js +546 -0
  139. package/dist/guide/threadStore.d.ts +48 -0
  140. package/dist/guide/threadStore.js +189 -0
  141. package/dist/guide/writeRoot.d.ts +11 -0
  142. package/dist/guide/writeRoot.js +70 -0
  143. package/dist/hosted/translate.js +2 -0
  144. package/dist/mcp/agentTools.js +12 -0
  145. package/dist/mcp/catalogTools.js +18 -20
  146. package/dist/mcp/catalogWriteTools.d.ts +8 -0
  147. package/dist/mcp/catalogWriteTools.js +225 -0
  148. package/dist/mcp/connectionTools.d.ts +3 -0
  149. package/dist/mcp/connectionTools.js +85 -0
  150. package/dist/mcp/controlTools.js +34 -1
  151. package/dist/mcp/deps.d.ts +9 -0
  152. package/dist/mcp/evalTools.js +684 -21
  153. package/dist/mcp/memoryHostTools.d.ts +3 -0
  154. package/dist/mcp/memoryHostTools.js +72 -0
  155. package/dist/mcp/pipelineAuthorTools.js +14 -1
  156. package/dist/mcp/server.js +5 -0
  157. package/dist/mcp/tools.js +6 -0
  158. package/dist/mcp/triggerTools.js +77 -31
  159. package/dist/operatorAgent/evalGate.d.ts +22 -0
  160. package/dist/operatorAgent/evalGate.js +77 -0
  161. package/dist/operatorAgent/fakeHost.js +10 -2
  162. package/dist/operatorAgent/host.js +18 -2
  163. package/dist/operatorAgent/index.d.ts +1 -0
  164. package/dist/operatorAgent/index.js +1 -0
  165. package/dist/operatorAgent/internalAgents.d.ts +11 -0
  166. package/dist/operatorAgent/internalAgents.js +13 -0
  167. package/dist/operatorAgent/piModel.d.ts +5 -1
  168. package/dist/operatorAgent/piModel.js +15 -10
  169. package/dist/operatorAgent/profiles/agentAuthor.js +66 -22
  170. package/dist/operatorAgent/profiles/agentAuthorPlaybook.d.ts +1 -1
  171. package/dist/operatorAgent/profiles/agentAuthorPlaybook.js +1 -1
  172. package/dist/operatorAgent/profiles/guideConfirm.d.ts +21 -0
  173. package/dist/operatorAgent/profiles/guideConfirm.js +100 -0
  174. package/dist/operatorAgent/profiles/guideTools.d.ts +7 -0
  175. package/dist/operatorAgent/profiles/guideTools.js +123 -0
  176. package/dist/operatorAgent/profiles/stageflowGuide.d.ts +7 -0
  177. package/dist/operatorAgent/profiles/stageflowGuide.js +132 -0
  178. package/dist/operatorAgent/profiles/workshopAuthor.js +23 -0
  179. package/dist/operatorAgent/profiles/workshopAuthorPlaybook.d.ts +1 -1
  180. package/dist/operatorAgent/profiles/workshopAuthorPlaybook.js +9 -1
  181. package/dist/operatorAgent/profiles/workshopAuthorTools.d.ts +2 -0
  182. package/dist/operatorAgent/profiles/workshopAuthorTools.js +197 -9
  183. package/dist/operatorAgent/types.d.ts +23 -0
  184. package/dist/package-meta.d.ts +1 -1
  185. package/dist/package-meta.js +1 -1
  186. package/dist/runstore/retention.d.ts +2 -1
  187. package/dist/runstore/retention.js +3 -7
  188. package/dist/runstore/runStatusClock.d.ts +17 -0
  189. package/dist/runstore/runStatusClock.js +19 -0
  190. package/dist/runstore/sqlite/SqliteRunStore.d.ts +1 -0
  191. package/dist/runstore/sqlite/SqliteRunStore.js +45 -45
  192. package/dist/runstore/workspaceLayout.js +6 -1
  193. package/dist/runtime/artifactDiskInspect.d.ts +14 -0
  194. package/dist/runtime/artifactDiskInspect.js +52 -0
  195. package/dist/runtime/artifactPath.d.ts +24 -0
  196. package/dist/runtime/artifactPath.js +84 -0
  197. package/dist/runtime/completionCheckRunner.js +15 -43
  198. package/dist/runtime/githubPollSource.d.ts +22 -4
  199. package/dist/runtime/githubPollSource.js +93 -8
  200. package/dist/runtime/priorArtifactGrants.d.ts +8 -0
  201. package/dist/runtime/priorArtifactGrants.js +105 -0
  202. package/dist/runtime/runActionEligibility.d.ts +46 -0
  203. package/dist/runtime/runActionEligibility.js +123 -0
  204. package/dist/runtime/runManager.d.ts +4 -1
  205. package/dist/runtime/runManager.js +52 -10
  206. package/dist/runtime/runRetryCoordinator.d.ts +2 -14
  207. package/dist/runtime/runRetryCoordinator.js +3 -67
  208. package/dist/runtime/sandboxContainer.d.ts +7 -0
  209. package/dist/runtime/sandboxContainer.js +48 -6
  210. package/dist/runtime/sandboxDesk.d.ts +2 -1
  211. package/dist/runtime/sandboxDesk.js +11 -12
  212. package/dist/runtime/stageEnvironment.js +1 -0
  213. package/dist/runtime/stageRoots.d.ts +12 -0
  214. package/dist/runtime/stageSandbox.d.ts +2 -1
  215. package/dist/runtime/stageSandbox.js +18 -2
  216. package/dist/runtime/stageWorker.js +20 -0
  217. package/dist/server/agentAuthorRoutes.js +12 -3
  218. package/dist/server/bootstrap.d.ts +5 -0
  219. package/dist/server/bootstrap.js +14 -1
  220. package/dist/server/evalRoutes.js +38 -9
  221. package/dist/server/guideRoutes.d.ts +5 -0
  222. package/dist/server/guideRoutes.js +166 -0
  223. package/dist/server/http.d.ts +10 -0
  224. package/dist/server/http.js +35 -1
  225. package/dist/server/internalAgentRoutes.d.ts +6 -0
  226. package/dist/server/internalAgentRoutes.js +12 -0
  227. package/dist/server/mcpHost.js +2 -0
  228. package/dist/toolkit/meta.d.ts +1 -1
  229. package/dist/toolkit/meta.js +39 -1
  230. package/dist/toolkit/profiles.d.ts +5 -0
  231. package/dist/toolkit/profiles.js +12 -0
  232. package/dist/tools/askOperator.js +2 -1
  233. package/dist/tools/emitStageEnvelope.d.ts +17 -16
  234. package/dist/tools/emitStageEnvelope.js +46 -32
  235. package/dist/tools/stageToolNames.d.ts +4 -0
  236. package/dist/tools/stageToolNames.js +4 -0
  237. package/dist/tools/workingState.d.ts +40 -0
  238. package/dist/tools/workingState.js +108 -0
  239. package/dist/tools/writeStageArtifact.d.ts +0 -9
  240. package/dist/tools/writeStageArtifact.js +2 -1
  241. package/dist/ui/assets/{MarkdownText-BTrOqu5J.js → MarkdownText-S5C_vemc.js} +2 -2
  242. package/dist/ui/assets/adapters-C0l4ruiR.js +17 -0
  243. package/dist/ui/assets/chat-CjnsmvqR.js +2 -0
  244. package/dist/ui/assets/chat-DFDd4UjS.css +2 -0
  245. package/dist/ui/assets/{main-CHlmTNJe.css → main-Del1GeLf.css} +1 -1
  246. package/dist/ui/assets/main-_yXVqcW9.js +277 -0
  247. package/dist/ui/chat.html +3 -4
  248. package/dist/ui/index.html +3 -4
  249. package/dist/workshop/chatTurn.js +1 -1
  250. package/dist/workshop/workshopPin.d.ts +3 -3
  251. package/dist/workshop/workshopPin.js +16 -15
  252. package/examples/compaction-stress/README.md +30 -0
  253. package/examples/compaction-stress/check-run.mjs +53 -0
  254. package/examples/compaction-stress/collect-evidence.yaml +60 -0
  255. package/examples/compaction-stress/compaction-stress.pipeline.yaml +141 -0
  256. package/examples/compaction-stress/compaction-stress.task.yaml +15 -0
  257. package/examples/compaction-stress/generate-evidence.mjs +110 -0
  258. package/examples/compaction-stress/root-cause.yaml +26 -0
  259. package/examples/compaction-stress/stageflow.yaml +9 -0
  260. package/examples/compaction-stress/write-postmortem.yaml +40 -0
  261. package/examples/evals/README.md +18 -0
  262. package/examples/evals/guide-behavior.dataset.jsonl +15 -0
  263. package/examples/evals/guide-behavior.eval.yaml +35 -0
  264. package/examples/evals/guide-depth.dataset.jsonl +35 -0
  265. package/examples/evals/guide-depth.eval.yaml +169 -0
  266. package/examples/memory/evals/guide-behavior.dataset.jsonl +15 -0
  267. package/examples/memory/evals/guide-behavior.eval.yaml +35 -0
  268. package/examples/memory/evals/guide-depth.dataset.jsonl +35 -0
  269. package/examples/memory/evals/guide-depth.eval.yaml +169 -0
  270. package/package.json +1 -1
  271. package/dist/ui/assets/AssistantRuntimeProvider-qIX1xNoH.js +0 -9
  272. package/dist/ui/assets/ReadonlyStore-BfXqHykm.js +0 -6
  273. package/dist/ui/assets/chat-Df_wCpak.js +0 -5
  274. package/dist/ui/assets/chat-P7KQznHm.css +0 -2
  275. package/dist/ui/assets/main-CvVfxmMd.js +0 -271
@@ -40,7 +40,8 @@ export function computeFingerprint(components) {
40
40
  return sha256Hex(canonicalJson(payload)).slice(0, 8);
41
41
  }
42
42
  export function buildSnapshot(input) {
43
- const agentTarget = "agent_id" in input.target ? input.target : null;
43
+ const internalTarget = "profile_id" in input.target ? input.target : null;
44
+ const agentTarget = !internalTarget && "agent_id" in input.target ? input.target : null;
44
45
  return {
45
46
  snapshot_version: CONFIG_SNAPSHOT_VERSION,
46
47
  eval: {
@@ -50,14 +51,18 @@ export function buildSnapshot(input) {
50
51
  definition: input.evalDefinition,
51
52
  },
52
53
  overrides: input.overrides,
53
- target: agentTarget ? { kind: "agent", ...agentTarget } : { kind: "stage", ...input.target },
54
+ target: internalTarget
55
+ ? { kind: "internal_agent", ...internalTarget }
56
+ : agentTarget
57
+ ? { kind: "agent", ...agentTarget }
58
+ : { kind: "stage", ...input.target },
54
59
  dataset: input.dataset,
55
60
  graders: input.graders,
56
61
  settings: input.settings,
57
62
  engine: {
58
63
  name: input.engine.name,
59
64
  version: input.engine.version,
60
- rubric_prompt_version: agentTarget ? CONVERSATION_RUBRIC_PROMPT_VERSION : RUBRIC_PROMPT_VERSION,
65
+ rubric_prompt_version: agentTarget || internalTarget ? CONVERSATION_RUBRIC_PROMPT_VERSION : RUBRIC_PROMPT_VERSION,
61
66
  node_version: input.engine.nodeVersion,
62
67
  },
63
68
  stageflow_version: input.stageflowVersion,
@@ -24,7 +24,13 @@ export type AgentEvalTarget = {
24
24
  kind: "agent";
25
25
  agent: string;
26
26
  };
27
- export type EvalTarget = StageEvalTarget | AgentEvalTarget;
27
+ export type InternalAgentEvalTarget = {
28
+ kind: "internal_agent";
29
+ profile: string;
30
+ };
31
+ export type EvalTarget = StageEvalTarget | AgentEvalTarget | InternalAgentEvalTarget;
32
+ /** A conversation eval: a project agent or a built-in operator agent. */
33
+ export declare function isConversationTarget(kind: string): boolean;
28
34
  export type ConversationMode = "script" | "simulated";
29
35
  export type ConversationTools = "real" | "read_only" | "mocked";
30
36
  export type ConversationApprovals = "deny" | "auto_approve_read" | "record_only";
@@ -143,7 +149,11 @@ export type AgentTargetRef = {
143
149
  agentId: string;
144
150
  revision?: number;
145
151
  };
146
- export type TargetRef = StageTargetRef | AgentTargetRef;
152
+ export type InternalAgentTargetRef = {
153
+ kind: "internal_agent";
154
+ profileId: string;
155
+ };
156
+ export type TargetRef = StageTargetRef | AgentTargetRef | InternalAgentTargetRef;
147
157
  type ResolvedGraderCommon = {
148
158
  id: string;
149
159
  weight: number;
@@ -1 +1,4 @@
1
- export {};
1
+ /** A conversation eval: a project agent or a built-in operator agent. */
2
+ export function isConversationTarget(kind) {
3
+ return kind === "agent" || kind === "internal_agent";
4
+ }
@@ -0,0 +1,133 @@
1
+ export declare const GUIDE_LINK_KINDS: readonly ["pipeline", "stage", "task", "agent", "trigger", "eval", "eval_run", "dataset", "connection", "memory", "run"];
2
+ export declare const GUIDE_RESOURCE_KINDS: readonly ["agent", "trigger", "eval", "connection", "memory", "task"];
3
+ export declare const GUIDE_UI_COMPONENTS: readonly ["pipeline", "resource", "plan", "choices", "eval_report", "links"];
4
+ export declare const GUIDE_UI_MAX_TEXT = 300;
5
+ export declare const GUIDE_UI_MAX_PLAN_STEPS = 12;
6
+ export declare const GUIDE_UI_MAX_CHOICES = 6;
7
+ export declare const GUIDE_UI_MAX_LINKS = 8;
8
+ export declare const GUIDE_UI_MAX_FAILURES = 5;
9
+ export declare const GUIDE_UI_MAX_MESSAGES = 5;
10
+ export type GuideLinkKind = (typeof GUIDE_LINK_KINDS)[number];
11
+ export type GuideUiComponent = (typeof GUIDE_UI_COMPONENTS)[number];
12
+ export type GuideLink = {
13
+ kind: GuideLinkKind;
14
+ id: string;
15
+ path?: string;
16
+ projectRoot?: string;
17
+ label?: string;
18
+ };
19
+ export type GuidePipelineStage = {
20
+ id: string;
21
+ summary?: string;
22
+ model?: string;
23
+ needs: string[];
24
+ gates: string[];
25
+ channels: string[];
26
+ hasVerify: boolean;
27
+ };
28
+ export type GuideUi = {
29
+ component: "pipeline";
30
+ title: string;
31
+ pipeline: {
32
+ id: string;
33
+ path: string;
34
+ model?: string;
35
+ stages: GuidePipelineStage[];
36
+ memories: string[];
37
+ task?: {
38
+ id: string;
39
+ goal: string;
40
+ };
41
+ };
42
+ validation: {
43
+ ok: boolean;
44
+ errors: number;
45
+ warnings: number;
46
+ messages: string[];
47
+ };
48
+ link: GuideLink;
49
+ } | {
50
+ component: "resource";
51
+ title: string;
52
+ kind: GuideLinkKind;
53
+ fields: Array<{
54
+ label: string;
55
+ value: string;
56
+ }>;
57
+ status?: string;
58
+ link: GuideLink;
59
+ } | {
60
+ component: "plan";
61
+ title: string;
62
+ steps: Array<{
63
+ title: string;
64
+ detail?: string;
65
+ status: "todo" | "current" | "done";
66
+ }>;
67
+ } | {
68
+ component: "choices";
69
+ question: string;
70
+ options: Array<{
71
+ id: string;
72
+ label: string;
73
+ description?: string;
74
+ }>;
75
+ allowOther: boolean;
76
+ } | {
77
+ component: "eval_report";
78
+ title: string;
79
+ evalId: string;
80
+ runId: string;
81
+ status: string;
82
+ passRate: number | null;
83
+ passed: boolean | null;
84
+ cases: number;
85
+ failures: Array<{
86
+ caseId: string;
87
+ reason: string;
88
+ }>;
89
+ costUsd: number | null;
90
+ link: GuideLink;
91
+ } | {
92
+ component: "links";
93
+ title?: string;
94
+ links: GuideLink[];
95
+ };
96
+ export type GuideChoicesUi = Extract<GuideUi, {
97
+ component: "choices";
98
+ }>;
99
+ export type GuidePlanUi = Extract<GuideUi, {
100
+ component: "plan";
101
+ }>;
102
+ export type GuideLinksUi = Extract<GuideUi, {
103
+ component: "links";
104
+ }>;
105
+ export declare class GuideCardError extends Error {
106
+ readonly code: string;
107
+ constructor(code: string);
108
+ }
109
+ /** Structural check for a Guide card payload. Returns the same value when valid. */
110
+ export declare function validateGuideUi(value: unknown): GuideUi | null;
111
+ /** Card payload from a `show_ui` / confirm tool result, or null when the console cannot draw it. */
112
+ export declare function readGuideUi(result: unknown): GuideUi | null;
113
+ export declare function buildChoicesUi(input: {
114
+ question: string;
115
+ options: Array<{
116
+ id: string;
117
+ label: string;
118
+ description?: string;
119
+ }>;
120
+ allowOther?: boolean;
121
+ }): GuideChoicesUi;
122
+ export declare function buildPlanUi(input: {
123
+ title: string;
124
+ steps: Array<{
125
+ title: string;
126
+ detail?: string;
127
+ status: "todo" | "current" | "done";
128
+ }>;
129
+ }): GuidePlanUi;
130
+ export declare function buildLinksUi(input: {
131
+ title?: string;
132
+ links: GuideLink[];
133
+ }): GuideLinksUi;
@@ -0,0 +1,156 @@
1
+ export const GUIDE_LINK_KINDS = [
2
+ "pipeline",
3
+ "stage",
4
+ "task",
5
+ "agent",
6
+ "trigger",
7
+ "eval",
8
+ "eval_run",
9
+ "dataset",
10
+ "connection",
11
+ "memory",
12
+ "run",
13
+ ];
14
+ export const GUIDE_RESOURCE_KINDS = ["agent", "trigger", "eval", "connection", "memory", "task"];
15
+ export const GUIDE_UI_COMPONENTS = ["pipeline", "resource", "plan", "choices", "eval_report", "links"];
16
+ export const GUIDE_UI_MAX_TEXT = 300;
17
+ export const GUIDE_UI_MAX_PLAN_STEPS = 12;
18
+ export const GUIDE_UI_MAX_CHOICES = 6;
19
+ export const GUIDE_UI_MAX_LINKS = 8;
20
+ export const GUIDE_UI_MAX_FAILURES = 5;
21
+ export const GUIDE_UI_MAX_MESSAGES = 5;
22
+ function isRecord(value) {
23
+ return typeof value === "object" && value !== null && !Array.isArray(value);
24
+ }
25
+ function hasArrays(value, keys) {
26
+ return isRecord(value) && keys.every((key) => Array.isArray(value[key]));
27
+ }
28
+ function isLinkKind(value) {
29
+ return typeof value === "string" && GUIDE_LINK_KINDS.includes(value);
30
+ }
31
+ function clipText(value) {
32
+ const trimmed = value.trim();
33
+ if (!trimmed)
34
+ return "";
35
+ return trimmed.length > GUIDE_UI_MAX_TEXT ? `${trimmed.slice(0, GUIDE_UI_MAX_TEXT - 1)}…` : trimmed;
36
+ }
37
+ function requireText(value, code = "guide.ui_invalid_args") {
38
+ const text = clipText(value);
39
+ if (!text)
40
+ throw new GuideCardError(code);
41
+ return text;
42
+ }
43
+ export class GuideCardError extends Error {
44
+ code;
45
+ constructor(code) {
46
+ super(code);
47
+ this.code = code;
48
+ }
49
+ }
50
+ /** Structural check for a Guide card payload. Returns the same value when valid. */
51
+ export function validateGuideUi(value) {
52
+ if (!isRecord(value) || typeof value.component !== "string")
53
+ return null;
54
+ if (!GUIDE_UI_COMPONENTS.includes(value.component))
55
+ return null;
56
+ switch (value.component) {
57
+ case "pipeline": {
58
+ if (!hasArrays(value.pipeline, ["stages"]) || !isRecord(value.validation) || !isRecord(value.link))
59
+ return null;
60
+ const stages = value.pipeline.stages;
61
+ if (!stages.every((stage) => isRecord(stage) && typeof stage.id === "string"))
62
+ return null;
63
+ break;
64
+ }
65
+ case "resource":
66
+ if (!Array.isArray(value.fields) || !isRecord(value.link))
67
+ return null;
68
+ break;
69
+ case "plan":
70
+ if (!Array.isArray(value.steps))
71
+ return null;
72
+ break;
73
+ case "choices":
74
+ if (typeof value.question !== "string" || !Array.isArray(value.options))
75
+ return null;
76
+ if (!value.options.every((option) => isRecord(option) && typeof option.id === "string" && typeof option.label === "string")) {
77
+ return null;
78
+ }
79
+ break;
80
+ case "eval_report":
81
+ if (!Array.isArray(value.failures) || !isRecord(value.link))
82
+ return null;
83
+ break;
84
+ case "links":
85
+ if (!Array.isArray(value.links))
86
+ return null;
87
+ break;
88
+ default:
89
+ return null;
90
+ }
91
+ return value;
92
+ }
93
+ /** Card payload from a `show_ui` / confirm tool result, or null when the console cannot draw it. */
94
+ export function readGuideUi(result) {
95
+ if (!isRecord(result))
96
+ return null;
97
+ return validateGuideUi(result.ui);
98
+ }
99
+ export function buildChoicesUi(input) {
100
+ const question = requireText(input.question);
101
+ if (input.options.length < 1 || input.options.length > GUIDE_UI_MAX_CHOICES) {
102
+ throw new GuideCardError("guide.ui_invalid_args");
103
+ }
104
+ const options = input.options.map((option) => {
105
+ const id = requireText(option.id);
106
+ const label = requireText(option.label);
107
+ const description = option.description !== undefined ? clipText(option.description) : undefined;
108
+ return description ? { id, label, description } : { id, label };
109
+ });
110
+ return {
111
+ component: "choices",
112
+ question,
113
+ options,
114
+ allowOther: input.allowOther ?? false,
115
+ };
116
+ }
117
+ export function buildPlanUi(input) {
118
+ const title = requireText(input.title);
119
+ if (input.steps.length < 1 || input.steps.length > GUIDE_UI_MAX_PLAN_STEPS) {
120
+ throw new GuideCardError("guide.ui_invalid_args");
121
+ }
122
+ return {
123
+ component: "plan",
124
+ title,
125
+ steps: input.steps.map((step) => {
126
+ const detail = step.detail !== undefined ? clipText(step.detail) : undefined;
127
+ return {
128
+ title: requireText(step.title),
129
+ ...(detail ? { detail } : {}),
130
+ status: step.status,
131
+ };
132
+ }),
133
+ };
134
+ }
135
+ export function buildLinksUi(input) {
136
+ if (input.links.length < 1 || input.links.length > GUIDE_UI_MAX_LINKS) {
137
+ throw new GuideCardError("guide.ui_invalid_args");
138
+ }
139
+ const title = input.title !== undefined ? requireText(input.title) : undefined;
140
+ return {
141
+ component: "links",
142
+ ...(title ? { title } : {}),
143
+ links: input.links.map((link) => {
144
+ if (!isLinkKind(link.kind))
145
+ throw new GuideCardError("guide.ui_invalid_args");
146
+ const next = { kind: link.kind, id: requireText(link.id) };
147
+ if (link.path)
148
+ next.path = requireText(link.path);
149
+ if (link.projectRoot)
150
+ next.projectRoot = requireText(link.projectRoot);
151
+ if (link.label)
152
+ next.label = requireText(link.label);
153
+ return next;
154
+ }),
155
+ };
156
+ }
@@ -0,0 +1,45 @@
1
+ import { type OperatorAgentHost } from "../operatorAgent/index.js";
2
+ import { type GuideMessage } from "./threadStore.js";
3
+ export declare const GUIDE_MAX_MESSAGE_CHARS = 8000;
4
+ export declare class GuideError extends Error {
5
+ readonly code: string;
6
+ readonly status: number;
7
+ constructor(code: string, status: number);
8
+ }
9
+ export declare const GUIDE_TOOL_RESULT_MAX_BYTES = 20000;
10
+ export type GuideToolFrame = {
11
+ type: "tool";
12
+ id: string;
13
+ name: string;
14
+ status: "running" | "complete" | "error";
15
+ args?: Record<string, unknown>;
16
+ result?: unknown;
17
+ error?: string;
18
+ };
19
+ export type GuideFrame = {
20
+ type: "delta";
21
+ text: string;
22
+ } | GuideToolFrame | {
23
+ type: "done";
24
+ message: GuideMessage;
25
+ } | {
26
+ type: "error";
27
+ code: string;
28
+ message: string;
29
+ };
30
+ export declare function resetGuideSessionsForTests(): void;
31
+ export declare function guideAgentInfo(host: OperatorAgentHost): {
32
+ name: string;
33
+ greeting: string;
34
+ };
35
+ export declare function isGuideThreadRunning(threadId: string): boolean;
36
+ export declare function abortGuideTurn(threadId: string): boolean;
37
+ export declare function streamGuideTurn(input: {
38
+ host: OperatorAgentHost;
39
+ threadId: string;
40
+ text: string;
41
+ attachments?: unknown;
42
+ model?: string | null;
43
+ storeRoot?: string;
44
+ signal?: AbortSignal;
45
+ }): AsyncGenerator<GuideFrame>;