@punica/editor 1.0.5 → 1.0.7

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 (69) hide show
  1. package/dist/index.bundle.esm.js +1 -1
  2. package/dist/index.bundle.esm.js.map +1 -1
  3. package/dist/index.bundle.umd.js +1 -1
  4. package/dist/index.bundle.umd.js.map +1 -1
  5. package/package.json +28 -3
  6. package/types/index.d.ts +120 -11
  7. package/types/punica.module.bootstrap.d.ts +45 -0
  8. package/types/punica.module.capability.d.ts +359 -0
  9. package/types/punica.module.extensions.api.d.ts +740 -0
  10. package/types/punica.module.extensions.settings.d.ts +106 -0
  11. package/types/punica.module.flow.agent.d.ts +75 -0
  12. package/types/punica.module.flow.api.d.ts +128 -0
  13. package/types/punica.module.flow.d.ts +490 -0
  14. package/types/punica.module.flow.engine.d.ts +228 -0
  15. package/types/punica.module.flow.mcp.d.ts +26 -0
  16. package/types/punica.module.flow.notebook.d.ts +210 -0
  17. package/types/punica.module.flow.primitives.d.ts +700 -0
  18. package/types/punica.module.flow.shell.d.ts +374 -0
  19. package/types/punica.module.kernel.ai.d.ts +462 -0
  20. package/types/punica.module.kernel.commands.d.ts +49 -0
  21. package/types/punica.module.kernel.events.d.ts +274 -0
  22. package/types/punica.module.kernel.history.d.ts +20 -0
  23. package/types/punica.module.kernel.llm.d.ts +343 -0
  24. package/types/punica.module.kernel.notifications.d.ts +64 -0
  25. package/types/punica.module.kernel.policy.d.ts +273 -0
  26. package/types/punica.module.kernel.tasks.d.ts +107 -0
  27. package/types/punica.module.kernel.timeServer.d.ts +16 -0
  28. package/types/punica.module.runtime.api.d.ts +214 -0
  29. package/types/punica.module.runtime.capabilities.d.ts +175 -0
  30. package/types/punica.module.runtime.compute.d.ts +339 -0
  31. package/types/punica.module.runtime.datasets.d.ts +234 -0
  32. package/types/punica.module.runtime.fs.d.ts +385 -0
  33. package/types/punica.module.runtime.harness.d.ts +246 -0
  34. package/types/punica.module.runtime.host.d.ts +272 -0
  35. package/types/punica.module.runtime.inference.d.ts +164 -0
  36. package/types/punica.module.runtime.lifecycle.d.ts +15 -0
  37. package/types/punica.module.runtime.llm.d.ts +470 -0
  38. package/types/punica.module.runtime.mcp.d.ts +139 -0
  39. package/types/punica.module.runtime.modelRuntimes.d.ts +90 -0
  40. package/types/punica.module.runtime.models.d.ts +254 -0
  41. package/types/punica.module.runtime.search.d.ts +59 -0
  42. package/types/punica.module.runtime.secrets.d.ts +26 -0
  43. package/types/punica.module.runtime.tasks.d.ts +27 -0
  44. package/types/punica.module.runtime.vcs.d.ts +67 -0
  45. package/types/punica.module.runtime.vectors.d.ts +74 -0
  46. package/types/punica.module.runtime.workspace.d.ts +134 -0
  47. package/types/punica.module.shell.activityBar.d.ts +42 -0
  48. package/types/punica.module.shell.components.d.ts +87 -0
  49. package/types/punica.module.shell.contentTabs.d.ts +33 -0
  50. package/types/punica.module.shell.dragDrop.d.ts +25 -0
  51. package/types/punica.module.shell.keyboardShortcuts.d.ts +38 -0
  52. package/types/punica.module.shell.layout.d.ts +106 -0
  53. package/types/punica.module.shell.markdown.d.ts +36 -0
  54. package/types/punica.module.shell.panelTabs.d.ts +48 -0
  55. package/types/punica.module.shell.profile.d.ts +278 -0
  56. package/types/punica.module.shell.statusbar.d.ts +26 -0
  57. package/types/punica.module.shell.view.d.ts +455 -0
  58. package/types/punica.module.shell.views.d.ts +150 -0
  59. package/types/punica.module.test.d.ts +562 -0
  60. package/types/punica.module.activityBar.d.ts +0 -21
  61. package/types/punica.module.commands.d.ts +0 -21
  62. package/types/punica.module.dragDrop.d.ts +0 -23
  63. package/types/punica.module.extensions.d.ts +0 -157
  64. package/types/punica.module.history.d.ts +0 -18
  65. package/types/punica.module.keyboardShortcuts.d.ts +0 -29
  66. package/types/punica.module.layout.d.ts +0 -23
  67. package/types/punica.module.statusbar.d.ts +0 -21
  68. package/types/punica.module.timeServer.d.ts +0 -14
  69. package/types/punica.module.view.d.ts +0 -8
@@ -0,0 +1,490 @@
1
+ /// <reference path="./punica.module.capability.d.ts" />
2
+ /// <reference path="./punica.module.test.d.ts" />
3
+
4
+ declare module 'punica' {
5
+ // eslint-disable-next-line @typescript-eslint/no-namespace
6
+ export namespace flow {
7
+ /**
8
+ * Minimal JSON types (self-contained to keep this experimental surface decoupled).
9
+ */
10
+ export type JSONPrimitive = string | number | boolean | null;
11
+ export type JSONValue =
12
+ | JSONPrimitive
13
+ | JSONValue[]
14
+ | { [key: string]: JSONValue };
15
+ export interface JSONObject {
16
+ [key: string]: JSONValue;
17
+ }
18
+
19
+ /**
20
+ * View metadata (purely UI state).
21
+ */
22
+ export interface ViewMetadata {
23
+ viewport?: { x: number; y: number; zoom: number };
24
+ nodes?: {
25
+ [id: string]: {
26
+ x?: number;
27
+ y?: number;
28
+ collapsed?: boolean;
29
+ [key: string]: JSONValue | undefined;
30
+ };
31
+ };
32
+ [key: string]: unknown;
33
+ }
34
+
35
+ /**
36
+ * Execution policy primitives.
37
+ */
38
+ export type CancellationMode = 'best-effort' | 'hard';
39
+
40
+ export interface RunBudget {
41
+ maxInFlight?: number;
42
+ maxQueueSize?: number;
43
+ totalTimeoutMs?: number;
44
+ cancellationMode?: CancellationMode;
45
+ /**
46
+ * Opt-in fail-fast semantic for parallel execution (D6). When
47
+ * `true`, the executor cancels in-flight siblings on the first
48
+ * node failure within a batch. Default is continue-and-collect
49
+ * so existing flows are not broken by the upgrade.
50
+ */
51
+ failFast?: boolean;
52
+ /**
53
+ * Persistence size budget per run (persistence redaction & budget, F27). Substrate
54
+ * tracks accumulated artifact bytes; writes that would exceed
55
+ * `maxBytes` produce a `redacted: { reason: 'budget' }` sentinel
56
+ * artifact instead of a plaintext payload, so audit traces
57
+ * remain coherent without unbounded disk growth.
58
+ */
59
+ artifactBudget?: ArtifactSizeBudget;
60
+ }
61
+
62
+ /**
63
+ * Persistence size budget (persistence redaction & budget, F27). Substrate honors
64
+ * `maxBytes` as a soft cap — a single artifact never exceeds
65
+ * the cap, and once the run's accumulated artifact bytes are
66
+ * within `maxBytes` of the cap, subsequent writes are redacted
67
+ * to a sentinel. `undefined` (the default) is unbounded — the
68
+ * host's storage policy takes over.
69
+ */
70
+ export interface ArtifactSizeBudget {
71
+ maxBytes?: number;
72
+ }
73
+
74
+ /**
75
+ * Which side of a node's I/O is being persisted (persistence redaction & budget).
76
+ * Substrate threads this through `artifactStore.writeArtifact`
77
+ * so the redaction policy can match against the offending
78
+ * surface (e.g. policy `'output'` redacts only output writes).
79
+ */
80
+ export type ArtifactSurface = 'input' | 'output' | 'meta';
81
+
82
+ /**
83
+ * Sentinel returned by the substrate when a write is redacted
84
+ * (persistence redaction & budget). Persisted in place of the plaintext payload so
85
+ * downstream audit consumers can see WHAT was redacted and WHY
86
+ * (policy match vs. size-budget exhaustion). Substrate refuses
87
+ * to silently drop content — every redaction is a marker.
88
+ */
89
+ export interface RedactionSentinel {
90
+ redacted: true;
91
+ reason: 'policy' | 'budget';
92
+ policy?: RedactionPolicy;
93
+ surface?: ArtifactSurface;
94
+ originalBytes?: number;
95
+ }
96
+
97
+ export interface ExecutionOverride {
98
+ timeoutMs?: number;
99
+ retry?: CapabilityRetryPolicy;
100
+ rateLimit?: CapabilityRateLimitPolicy;
101
+ concurrency?: CapabilityConcurrencyPolicy;
102
+ }
103
+
104
+ /**
105
+ * Standard execution event for observability (runtime-agnostic).
106
+ * Separate from compute.ExecutionEvent which is provider-specific.
107
+ * Used by Flow Engine to emit execution lifecycle events.
108
+ */
109
+ export type ExecutionEvent =
110
+ | {
111
+ type: 'span.start';
112
+ traceId: string;
113
+ spanId: string;
114
+ name: string;
115
+ ts: number;
116
+ data?: unknown;
117
+ }
118
+ | {
119
+ type: 'span.end';
120
+ traceId: string;
121
+ spanId: string;
122
+ ts: number;
123
+ ok: boolean;
124
+ error?: {
125
+ code: string;
126
+ message: string;
127
+ };
128
+ }
129
+ | {
130
+ type: 'retry';
131
+ traceId: string;
132
+ spanId: string;
133
+ attempt: number;
134
+ delayMs: number;
135
+ reason: string;
136
+ }
137
+ | {
138
+ type: 'rate_limited';
139
+ traceId: string;
140
+ spanId: string;
141
+ key: string;
142
+ }
143
+ | {
144
+ type: 'queue';
145
+ runId: string;
146
+ depth: number;
147
+ inFlight: number;
148
+ }
149
+ | {
150
+ type: 'cancelled';
151
+ runId: string;
152
+ mode: CancellationMode;
153
+ reason?: string;
154
+ };
155
+
156
+ export type ValidationSeverity = 'error' | 'warning';
157
+
158
+ export interface ValidationIssue {
159
+ path: string;
160
+ message: string;
161
+ severity: ValidationSeverity;
162
+ code?: string;
163
+ }
164
+
165
+ export interface ValidationResult {
166
+ ok: boolean;
167
+ errors: ValidationIssue[];
168
+ warnings: ValidationIssue[];
169
+ }
170
+
171
+ /**
172
+ * Validator API surface (host/extension implementation).
173
+ * Validates FlowBookDocument.
174
+ *
175
+ * `options.hasCapability` mirrors the top-level
176
+ * `validateFlowBookDocument` Trinity seam — implementers thread it
177
+ * into `flowBookValidator` so registry lookups stay pure and
178
+ * substitutable (capability registry + CONSTITUTION § 0.1).
179
+ */
180
+ export interface Validator {
181
+ validate(
182
+ spec: FlowBookDocument,
183
+ options?: {
184
+ mode?: 'strict' | 'best-effort';
185
+ hasCapability?: CapabilityLookup;
186
+ }
187
+ ): ValidationResult;
188
+ }
189
+
190
+ export const Validator: {
191
+ manager: Validator;
192
+ };
193
+
194
+ /**
195
+ * Validates a FlowBookDocument. Top-level helper exposed on `punica.flow`.
196
+ *
197
+ * Pass `options.hasCapability` to enable Trinity verification — the
198
+ * validator checks every `ivyNode` / `flowBook` `ref.id` against
199
+ * that predicate and emits `WF_UNKNOWN_CAPABILITY` errors (strict)
200
+ * or warnings (best-effort) for any miss. Substrate's
201
+ * `validator.module.ts` wires this to
202
+ * `unifiedCapabilityRegistry.getCapability(...)`. When omitted, the
203
+ * Trinity check is skipped (keeps the validator usable in
204
+ * registry-less unit tests).
205
+ */
206
+ export function validateFlowBookDocument(
207
+ spec: FlowBookDocument,
208
+ options?: {
209
+ mode?: 'strict' | 'best-effort';
210
+ hasCapability?: CapabilityLookup;
211
+ }
212
+ ): ValidationResult;
213
+
214
+ /**
215
+ * Cell-like primitives (portable, notebook-derived wins without "notebook as a product").
216
+ */
217
+ export type CellType = 'code' | 'markdown' | 'raw';
218
+ export type MultilineString = string | string[];
219
+
220
+ export interface CellMetadata {
221
+ ivy?: {
222
+ /**
223
+ * Optional annotation: which capability this cell belongs to (not required).
224
+ * Source-of-truth contract is CapabilityDefinition on IvyNode/FlowBook.
225
+ */
226
+ capability?: {
227
+ id?: CapabilityId;
228
+ version?: string;
229
+ [key: string]: unknown;
230
+ };
231
+ cell?: {
232
+ role?: 'input' | 'compute' | 'output';
233
+ };
234
+ [key: string]: unknown;
235
+ };
236
+ [key: string]: unknown;
237
+ }
238
+
239
+ export interface BaseOutput {
240
+ metadata?: JSONObject;
241
+ }
242
+
243
+ export interface StreamOutput extends BaseOutput {
244
+ output_type: 'stream';
245
+ name: 'stdout' | 'stderr';
246
+ text: MultilineString;
247
+ }
248
+
249
+ export interface DisplayDataOutput extends BaseOutput {
250
+ output_type: 'display_data';
251
+ data: JSONObject;
252
+ }
253
+
254
+ export interface ExecuteResultOutput extends BaseOutput {
255
+ output_type: 'execute_result';
256
+ data: JSONObject;
257
+ execution_count: number;
258
+ }
259
+
260
+ export interface ErrorOutput extends BaseOutput {
261
+ output_type: 'error';
262
+ ename: string;
263
+ evalue: string;
264
+ traceback: string[];
265
+ }
266
+
267
+ export interface ExtendedOutput extends BaseOutput {
268
+ output_type: string;
269
+ status?: 'ok' | 'error';
270
+ comm_id?: string;
271
+ method?: string;
272
+ execution_state?: string;
273
+ name?: string;
274
+ text?: MultilineString;
275
+ value?: JSONValue;
276
+ title?: string;
277
+ isDone?: boolean;
278
+ [key: string]: JSONValue | undefined;
279
+ }
280
+
281
+ export type Output =
282
+ | StreamOutput
283
+ | DisplayDataOutput
284
+ | ExecuteResultOutput
285
+ | ErrorOutput
286
+ | ExtendedOutput;
287
+
288
+ export interface Cell {
289
+ id: string;
290
+ cell_type: CellType;
291
+ source: MultilineString;
292
+ metadata: CellMetadata;
293
+ /**
294
+ * Optional execution fields, mirroring notebook.CodeCell for reuse.
295
+ * These are primarily useful when reusing runtime outputs in ivy graphs.
296
+ */
297
+ execution_count?: number | null;
298
+ outputs?: Output[];
299
+ }
300
+
301
+ export interface Program {
302
+ format: 'cells';
303
+ language: 'python' | string;
304
+ cells: Cell[];
305
+ roles?: {
306
+ inputCellId?: string;
307
+ outputCellId?: string;
308
+ };
309
+ extras?: JSONObject;
310
+ }
311
+
312
+ /**
313
+ * Capability ID (IvyNode and FlowBook are both CapabilityDefinition-based).
314
+ */
315
+ export type CapabilityId = string;
316
+
317
+ /**
318
+ * IvyNode definition (atomic executable building block).
319
+ */
320
+ export interface NodeDefinition extends CapabilityDefinition {
321
+ apiVersion: 'ivy.node/v0.2';
322
+ kind: 'IvyNode';
323
+ program: Program;
324
+ /**
325
+ * Runtime contract for Python or other backends.
326
+ * Concrete runtimes can extend/interpret these fields as needed.
327
+ */
328
+ runtime?: {
329
+ module?: string;
330
+ function?: string;
331
+ config?: JSONObject;
332
+ kind?: string;
333
+ };
334
+ /**
335
+ * Inline test specification for this Ivy node (quality gates / selection).
336
+ * For external test specifications, use testSpecificationIds.
337
+ */
338
+ tests?: TestSpec;
339
+ /**
340
+ * Test specification IDs associated with this node
341
+ * Format: "test.{capabilityId}" (e.g., "test.ivy.node.http.fetch")
342
+ */
343
+ testSpecificationIds?: TestSpecificationId[];
344
+ extras?: JSONObject;
345
+ }
346
+
347
+ /**
348
+ * -------------------------
349
+ * Generic graph IR (the core)
350
+ * -------------------------
351
+ * Used by FlowBook now; intended to be reused by agent/mcp/rest later.
352
+ */
353
+ export type GraphId = string;
354
+ export type NodeId = string;
355
+
356
+ /**
357
+ * Edge mapping uses *Path (string).
358
+ * Convention: dot-path (e.g. "text", "result.value").
359
+ */
360
+ export interface Edge {
361
+ fromId: NodeId;
362
+ toId: NodeId;
363
+ fromPath?: string;
364
+ toPath?: string;
365
+ metadata?: JSONObject;
366
+ }
367
+
368
+ export interface Graph {
369
+ entryNodeId: NodeId;
370
+ nodes: Node[];
371
+ edges: Edge[];
372
+ runBudget?: RunBudget;
373
+ config?: JSONObject;
374
+ }
375
+
376
+ /**
377
+ * Node.defaults are fallback values when no incoming edge provides that field.
378
+ * Precedence (intended): incoming edge value > defaults > undefined
379
+ */
380
+ export interface Node {
381
+ id: NodeId;
382
+ label?: string;
383
+ disabled?: boolean;
384
+ ref: NodeRef;
385
+ defaults?: JSONObject;
386
+ executionOverride?: ExecutionOverride;
387
+ data?: JSONObject;
388
+ /**
389
+ * Per-node redaction policy (persistence redaction & budget). When set, the
390
+ * substrate redacts the matching surface(s) before any
391
+ * artifact persistence write. Intersects with the
392
+ * capability's declared `dataClassification` — substrate
393
+ * picks the strictest of the two so a "sensitive" capability
394
+ * cannot be widened to plaintext by a node-level `'none'`
395
+ * override.
396
+ *
397
+ * - `'none'` — no redaction (substrate default).
398
+ * - `'input'` — redact node input payloads.
399
+ * - `'output'` — redact node output payloads.
400
+ * - `'all'` — redact both.
401
+ */
402
+ redactionPolicy?: RedactionPolicy;
403
+ }
404
+
405
+ /**
406
+ * Reserved pseudo IO node ids (for FlowBook wiring).
407
+ * If edges use these ids, they must exist as nodes in Graph.nodes.
408
+ */
409
+ export type FlowIoNodeId = 'flow-input' | 'flow-output';
410
+
411
+ export interface FlowInputRef {
412
+ kind: 'flowInput';
413
+ }
414
+
415
+ export interface FlowOutputRef {
416
+ kind: 'flowOutput';
417
+ }
418
+
419
+ export interface NodeCapabilityRef {
420
+ kind: 'ivyNode';
421
+ id: CapabilityId;
422
+ version?: string;
423
+ }
424
+
425
+ export interface FlowBookRef {
426
+ kind: 'flowBook';
427
+ id: CapabilityId;
428
+ version?: string;
429
+ /**
430
+ * Optional inline definition for local experiments (no registry publishing).
431
+ */
432
+ inline?: FlowBookDocument;
433
+ }
434
+
435
+ /**
436
+ * Discriminator for substrate-built primitive nodes (flow primitives).
437
+ * The `primitive` field tags the executor; the matching `node.data`
438
+ * payload is one of the `*PrimitiveData` shapes declared alongside
439
+ * `FlowPrimitiveKind` in `punica.module.flow.primitives.d.ts`.
440
+ *
441
+ * Body execution (loop body, try/catch handler, etc.) is wired
442
+ * through `flow.runSubflow` (subflow spawning); 4.C executors evaluate
443
+ * predicates / collections / lambdas + emit decision artifacts and
444
+ * forward-defer the actual body invocation.
445
+ */
446
+ export interface PrimitiveRef {
447
+ kind: 'primitive';
448
+ primitive: FlowPrimitiveKind;
449
+ }
450
+
451
+ export type NodeRef =
452
+ | FlowInputRef
453
+ | FlowOutputRef
454
+ | NodeCapabilityRef
455
+ | FlowBookRef
456
+ | PrimitiveRef;
457
+
458
+ /**
459
+ * GraphDocumentBase: generic capability-backed graph.
460
+ */
461
+ export interface GraphDocumentBase extends CapabilityDefinition {
462
+ graph: Graph;
463
+ view?: ViewMetadata;
464
+ extras?: JSONObject;
465
+ }
466
+
467
+ /**
468
+ * FlowBook = GraphDocumentBase with FlowBook discriminators.
469
+ */
470
+ export interface FlowBookDocument extends GraphDocumentBase {
471
+ apiVersion: 'ivy.flowbook/v0.1';
472
+ kind: 'FlowBook';
473
+ }
474
+
475
+ /**
476
+ * Edge reference used in notebook metadata (metadata.ivy.flow.edges).
477
+ * This is a legacy format used for notebook-based workflows.
478
+ */
479
+ export interface FlowEdgeRef {
480
+ fromId: string;
481
+ toId: string;
482
+ fromProperty?: string;
483
+ toProperty?: string;
484
+ metadata?: JSONObject;
485
+ }
486
+ }
487
+
488
+ // Module-level export for convenience
489
+ export type FlowEdgeRef = flow.FlowEdgeRef;
490
+ }
@@ -0,0 +1,228 @@
1
+ /// <reference path="./punica.module.flow.d.ts" />
2
+
3
+ declare module 'punica' {
4
+ export namespace flow {
5
+ export namespace engine {
6
+ export type RunStatus =
7
+ | 'QUEUED'
8
+ | 'RUNNING'
9
+ | 'WAITING_APPROVAL'
10
+ | 'PAUSED'
11
+ | 'RETRYING'
12
+ | 'COMPLETED'
13
+ | 'FAILED'
14
+ | 'CANCELLED';
15
+
16
+ /**
17
+ * Substrate-pinned terminal `RunStatus` values (run status / checkpoints). A
18
+ * run in any of these states never transitions again; the state
19
+ * machine refuses every outgoing edge from terminal nodes. The
20
+ * literal-union shape is here so consumers can narrow without
21
+ * importing the runtime state machine.
22
+ */
23
+ export type TerminalRunStatus = 'COMPLETED' | 'FAILED' | 'CANCELLED';
24
+
25
+ /**
26
+ * Pure run-status state machine (run status / checkpoints). Substrate's
27
+ * authoritative transition graph — every status mutation must
28
+ * route through `assertTransition` so F21 (invalid transition
29
+ * detection) is enforced uniformly across the engine.
30
+ *
31
+ * - `canTransitionTo(current, next)` — predicate, never throws.
32
+ * - `assertTransition(current, next)` — throws on invalid edge.
33
+ * - `getValidTransitions(current)` — outgoing edges for tooling.
34
+ * - `isTerminal(status)` — short-circuit guard.
35
+ */
36
+ export interface RunStatusStateMachine {
37
+ canTransitionTo(current: RunStatus, next: RunStatus): boolean;
38
+ assertTransition(current: RunStatus, next: RunStatus): void;
39
+ getValidTransitions(current: RunStatus): readonly RunStatus[];
40
+ isTerminal(status: RunStatus): status is TerminalRunStatus;
41
+ }
42
+
43
+ /**
44
+ * Substrate-shipped singleton — pure state machine, no
45
+ * dependencies. Exposed at `punica.flow.engine.statusStateMachine`.
46
+ */
47
+ export const statusStateMachine: RunStatusStateMachine;
48
+
49
+ /**
50
+ * Canvas-facing node status vocabulary produced by
51
+ * `subscribeNodeStatuses` (the single event→status choke point).
52
+ */
53
+ export type NodeCanvasStatus =
54
+ | 'waiting'
55
+ | 'running'
56
+ | 'completed'
57
+ | 'error';
58
+
59
+ export interface NodeStatusUpdate {
60
+ nodeId: string;
61
+ status: NodeCanvasStatus;
62
+ runId: string | null;
63
+ /**
64
+ * True on the first update of a new run — subscribers should reset
65
+ * all their nodes to `waiting` before applying this update.
66
+ */
67
+ isNewRun: boolean;
68
+ /** Raw engine StepStatus (e.g. 'RUNNING', 'SUCCESS'). */
69
+ stepStatus: string;
70
+ }
71
+
72
+ /**
73
+ * Subscribe to live node statuses projected from
74
+ * `workflow.stepStarted/stepUpdated/stepFinished`. Events whose
75
+ * step id is not in `nodeIds` are dropped, so concurrent runs of
76
+ * unrelated flows never cross-update a subscriber. Exposed at
77
+ * `punica.flow.engine.subscribeNodeStatuses`. Returns a disposer.
78
+ */
79
+ export function subscribeNodeStatuses(
80
+ options: { nodeIds: readonly string[] },
81
+ callback: (update: NodeStatusUpdate) => void
82
+ ): () => void;
83
+
84
+ export type StepStatus =
85
+ | 'PENDING'
86
+ | 'RUNNING'
87
+ | 'WAITING_APPROVAL'
88
+ | 'PAUSED'
89
+ | 'RETRYING'
90
+ | 'SUCCESS'
91
+ | 'FAILED'
92
+ | 'CANCELLED'
93
+ | 'SKIPPED';
94
+
95
+ export type ArtifactType = 'text' | 'json' | 'file' | 'patch' | 'log';
96
+
97
+ export interface ArtifactRecord {
98
+ id: string;
99
+ runId: string;
100
+ stepId: string;
101
+ type: ArtifactType;
102
+ createdAtMs: number;
103
+ name?: string;
104
+ mimeType?: string;
105
+ uri?: string;
106
+ preview?: string;
107
+ sizeBytes?: number;
108
+ meta?: Record<string, unknown>;
109
+ }
110
+
111
+ export interface PendingApprovalRecord {
112
+ pendingId: string;
113
+ attemptCorrelationId: string;
114
+ kind: string;
115
+ id: string;
116
+ risk: string;
117
+ approval: string;
118
+ reason?: string;
119
+ workspaceId?: string;
120
+ timestampMs: number;
121
+ }
122
+
123
+ export interface StepRecord {
124
+ stepId: string; // node.id
125
+ nodeId: string;
126
+ nodeType: string; // Derived from flow.NodeRef.kind: 'capability.call' | 'workflow.run' | 'flow.input' | 'flow.output' | 'unknown'
127
+ attempt: number;
128
+ status: StepStatus;
129
+ startedAtMs?: number;
130
+ endedAtMs?: number;
131
+ cellId?: string;
132
+ attemptCorrelationId?: string;
133
+ spanId?: string;
134
+ error?: { message: string; code?: string };
135
+ inputsPreview?: string;
136
+ outputsPreview?: string;
137
+ artifactIds?: string[];
138
+ approval?: {
139
+ pendingId?: string;
140
+ required?: boolean;
141
+ requestedAtMs?: number;
142
+ resolved?: boolean;
143
+ decision?: 'approved' | 'rejected';
144
+ };
145
+ }
146
+
147
+ export interface RunRecord {
148
+ runId: string;
149
+ specVersion: '0.1'; // Legacy field, kept for compatibility
150
+ status: RunStatus;
151
+ createdAtMs: number;
152
+ startedAtMs?: number;
153
+ endedAtMs?: number;
154
+ traceId: string;
155
+ entryNodeId: string;
156
+ metadata?: { title?: string; tags?: string[] };
157
+ currentNodeId?: string;
158
+ error?: { message: string; nodeId?: string; correlationId?: string };
159
+ steps: StepRecord[];
160
+ }
161
+
162
+ export interface RunSummary {
163
+ runId: string;
164
+ status: RunStatus;
165
+ createdAtMs: number;
166
+ startedAtMs?: number;
167
+ endedAtMs?: number;
168
+ traceId: string;
169
+ metadata?: { title?: string };
170
+ }
171
+
172
+ export interface StartRunInput {
173
+ spec: flow.FlowBookDocument;
174
+ workspaceId?: string;
175
+ filePathOrUri?: string;
176
+ /**
177
+ * Optional run-level input payload. Exposed to the graph via the
178
+ * `flowInput` pseudo-node's output, so downstream nodes can read it
179
+ * through edge wiring (`edge.fromId === 'flow-input'`, `fromPath`).
180
+ */
181
+ input?: flow.JSONValue;
182
+ }
183
+
184
+ export interface EngineApi {
185
+ initialize(): void;
186
+ startRun(input: StartRunInput): Promise<{ runId: string }>;
187
+ pauseRun(runId: string): Promise<boolean>;
188
+ resumeRun(runId: string): Promise<boolean>;
189
+ cancelRun(
190
+ runId: string,
191
+ mode?: flow.CancellationMode
192
+ ): Promise<boolean>;
193
+ getRun(runId: string): RunRecord | null;
194
+ /**
195
+ * Read a node's recorded output for a run (e.g. `'flow-output'` for
196
+ * the flow's assembled result). Returns `undefined` for unknown
197
+ * runs/nodes. Full JSON value — unlike `StepRecord.outputsPreview`,
198
+ * which is a truncated display string.
199
+ */
200
+ getNodeOutput(
201
+ runId: string,
202
+ nodeId: string
203
+ ): flow.JSONValue | undefined;
204
+ listRuns(options?: {
205
+ status?: RunStatus;
206
+ limit?: number;
207
+ }): RunSummary[];
208
+ approvePending(input: {
209
+ pendingId: string;
210
+ scope: kernel.ApprovalScope;
211
+ }): boolean;
212
+ rejectPending(input: { pendingId: string }): boolean;
213
+ /**
214
+ * Spawn a child run for a `FlowBookDocument` and await its
215
+ * terminal state (subflow spawning). Substrate enforces
216
+ * `MAX_SUBFLOW_DEPTH` and rejects synchronously when
217
+ * `(parentDepth ?? 0) + 1` exceeds the cap. The child run
218
+ * inherits the parent's `workspaceId` so the policy store's
219
+ * `'once'` approval scope (D5) deduplicates naturally —
220
+ * F33 dedup is structural, not a separate cache.
221
+ */
222
+ runSubflow(input: flow.SubflowInvocation): Promise<flow.SubflowResult>;
223
+ }
224
+
225
+ export const manager: EngineApi;
226
+ }
227
+ }
228
+ }