@voltro/plugin-ai-flows 0.1.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.
- package/CHANGELOG.md +52 -0
- package/LICENSE +57 -0
- package/README.md +26 -0
- package/SECURITY.md +56 -0
- package/THIRD-PARTY-NOTICES.md +5178 -0
- package/dist/cadence-Bt6dPelT.js +40 -0
- package/dist/errors.d.ts +88 -0
- package/dist/errors.js +29 -0
- package/dist/index.d.ts +880 -0
- package/dist/index.js +965 -0
- package/dist/ir.d.ts +279 -0
- package/dist/ir.js +102 -0
- package/dist/rpc.d.ts +7 -0
- package/dist/rpc.js +4 -0
- package/dist/web.d.ts +176 -0
- package/dist/web.js +2 -0
- package/dist/workflow.d.ts +40 -0
- package/dist/workflow.js +23 -0
- package/package.json +76 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,880 @@
|
|
|
1
|
+
import { AppContext } from '@voltro/runtime';
|
|
2
|
+
import { ColumnBuilder } from '@voltro/database';
|
|
3
|
+
import { ColumnDefinition } from '@voltro/database';
|
|
4
|
+
import { Effect } from 'effect';
|
|
5
|
+
import { FieldDefinitions } from '@voltro/database';
|
|
6
|
+
import { ProviderConfig } from '@voltro/ai';
|
|
7
|
+
import { Schema } from 'effect';
|
|
8
|
+
import { Table } from '@voltro/database';
|
|
9
|
+
import { TableLike } from '@voltro/database';
|
|
10
|
+
import { VoltroPlugin } from '@voltro/protocol';
|
|
11
|
+
import { WorkflowEngine } from '@effect/workflow/WorkflowEngine';
|
|
12
|
+
import { WorkflowInstance } from '@effect/workflow/WorkflowEngine';
|
|
13
|
+
|
|
14
|
+
/** An `agent` step's resolved persona. */
|
|
15
|
+
export declare interface AgentResolution {
|
|
16
|
+
readonly system: string;
|
|
17
|
+
readonly model: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** `ai_flow_runs` — one execution. `.reactive()`: the engine patches this row
|
|
21
|
+
* as it progresses and the client's subscription streams the live timeline. */
|
|
22
|
+
export declare const aiFlowRunsTable: Table<"ai_flow_runs", FieldDefinitions<{
|
|
23
|
+
readonly id: ColumnBuilder<string, "id">;
|
|
24
|
+
/** Name (code flow) or id (data flow). Not an FK — no single target. */
|
|
25
|
+
readonly flowRef: ColumnBuilder<string, "text">;
|
|
26
|
+
/** Denormalized flow name — survives a definition delete. */
|
|
27
|
+
readonly flowName: ColumnBuilder<string | null, "text">;
|
|
28
|
+
/** Snapshot of the mode this run executes in. */
|
|
29
|
+
readonly mode: ColumnBuilder<string, "text">;
|
|
30
|
+
/** pending | running | waiting | succeeded | failed | cancelled. */
|
|
31
|
+
readonly status: ColumnBuilder<string, "text">;
|
|
32
|
+
/** manual | cron. */
|
|
33
|
+
readonly source: ColumnBuilder<string | null, "text">;
|
|
34
|
+
/** Correlation + idempotency key (→ the workflow's idempotencyKey). */
|
|
35
|
+
readonly requestId: ColumnBuilder<string, "text">;
|
|
36
|
+
/** Brief values, keyed by `BriefField.key`. */
|
|
37
|
+
readonly input: ColumnBuilder<Record<string, unknown> | null, "json">;
|
|
38
|
+
/** The result bundle: `outputKey → value` (what the UI's result dialog reads). */
|
|
39
|
+
readonly output: ColumnBuilder<Record<string, unknown> | null, "json">;
|
|
40
|
+
/** Live per-step timeline (`RunStep[]`); the engine writes it on every step. */
|
|
41
|
+
readonly steps: ColumnBuilder<readonly {
|
|
42
|
+
readonly id: number;
|
|
43
|
+
readonly output?: {
|
|
44
|
+
readonly text: string;
|
|
45
|
+
} | undefined;
|
|
46
|
+
readonly type: "generate" | "agent" | "structured" | "note" | "human";
|
|
47
|
+
readonly status: "failed" | "running" | "succeeded" | "pending" | "waiting";
|
|
48
|
+
readonly url?: string | undefined;
|
|
49
|
+
readonly description?: string | undefined;
|
|
50
|
+
readonly errorMessage?: string | undefined;
|
|
51
|
+
readonly startedAt?: string | undefined;
|
|
52
|
+
readonly completedAt?: string | undefined;
|
|
53
|
+
readonly title: string;
|
|
54
|
+
readonly costMicroUsd?: number | undefined;
|
|
55
|
+
readonly requestId?: string | undefined;
|
|
56
|
+
readonly review?: {
|
|
57
|
+
readonly prompt: string;
|
|
58
|
+
readonly options?: readonly {
|
|
59
|
+
readonly value: string;
|
|
60
|
+
readonly label: string;
|
|
61
|
+
}[] | undefined;
|
|
62
|
+
readonly mode: "text" | "approve" | "choice";
|
|
63
|
+
} | undefined;
|
|
64
|
+
}[] | null, "json">;
|
|
65
|
+
readonly currentStep: ColumnBuilder<number, "integer">;
|
|
66
|
+
readonly totalSteps: ColumnBuilder<number, "integer">;
|
|
67
|
+
/** The HITL answer, written by `respond`. */
|
|
68
|
+
readonly humanResponse: ColumnBuilder<{
|
|
69
|
+
readonly value?: string | undefined;
|
|
70
|
+
readonly text?: string | undefined;
|
|
71
|
+
readonly decision?: "approve" | "reject" | undefined;
|
|
72
|
+
readonly respondedAt?: string | undefined;
|
|
73
|
+
} | null, "json">;
|
|
74
|
+
/** Staged follow-up when the chain requires confirmation. */
|
|
75
|
+
readonly chainPending: ColumnBuilder<{
|
|
76
|
+
readonly input: {
|
|
77
|
+
readonly [x: string]: unknown;
|
|
78
|
+
};
|
|
79
|
+
readonly status: "pending" | "confirmed" | "dismissed";
|
|
80
|
+
readonly flowRef: string;
|
|
81
|
+
} | null, "json">;
|
|
82
|
+
/** Accumulated cost in micro-USD (app view projects to €/cents). */
|
|
83
|
+
readonly costMicroUsd: ColumnBuilder<number, "integer">;
|
|
84
|
+
readonly durationMs: ColumnBuilder<number | null, "integer">;
|
|
85
|
+
readonly error: ColumnBuilder<string | null, "text">;
|
|
86
|
+
readonly errorMessage: ColumnBuilder<string | null, "text">;
|
|
87
|
+
readonly startedAt: ColumnBuilder<Date | null, "timestamp">;
|
|
88
|
+
readonly completedAt: ColumnBuilder<Date | null, "timestamp">;
|
|
89
|
+
readonly cancelledAt: ColumnBuilder<Date | null, "timestamp">;
|
|
90
|
+
/** Studio session grouping (app concept; soft ref). */
|
|
91
|
+
readonly sessionId: ColumnBuilder<string | null, "text">;
|
|
92
|
+
readonly sessionName: ColumnBuilder<string | null, "text">;
|
|
93
|
+
/** App subject the run is for/by. */
|
|
94
|
+
readonly ownerId: ColumnBuilder<string | null, "text">;
|
|
95
|
+
readonly metadata: ColumnBuilder<Record<string, unknown> | null, "json">;
|
|
96
|
+
}> & {
|
|
97
|
+
tenantId: ColumnDefinition<string>;
|
|
98
|
+
} & {
|
|
99
|
+
readonly createdAt: ColumnDefinition<Date, "timestamp">;
|
|
100
|
+
readonly updatedAt: ColumnDefinition<Date, "timestamp">;
|
|
101
|
+
readonly createdBy: ColumnDefinition<string | null, "reference">;
|
|
102
|
+
readonly updatedBy: ColumnDefinition<string | null, "reference">;
|
|
103
|
+
}, true, never>;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The AI-Flows plugin. Install it in `app.config.ts` `plugins: [...]`. It
|
|
107
|
+
* contributes the canonical `ai_flows` + `ai_flow_runs` tables plus the
|
|
108
|
+
* read-only inspect surface; the durable engine, the client-callable
|
|
109
|
+
* procedures, and the cadence tick ship from this package's subpath exports.
|
|
110
|
+
*/
|
|
111
|
+
export declare const aiFlowsPlugin: (options?: AiFlowsPluginOptions) => VoltroPlugin;
|
|
112
|
+
|
|
113
|
+
/** Options for the AI-Flows plugin. Runtime capabilities (AI generation,
|
|
114
|
+
* storage for media artifacts, notifications) are resolved as injected
|
|
115
|
+
* capabilities as the engine lands — NOT hard plugin-to-plugin deps — so an
|
|
116
|
+
* app can run text-only flows without installing storage. */
|
|
117
|
+
export declare interface AiFlowsPluginOptions {
|
|
118
|
+
/** Namespace for this plugin's routes / inspect endpoints. Default `aiFlows`. */
|
|
119
|
+
readonly alias?: string;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** `ai_flows` — a reusable flow DEFINITION (the data front door persists these;
|
|
123
|
+
* code-first `defineFlow` flows are NOT rows — they register in-process). */
|
|
124
|
+
export declare const aiFlowsTable: Table<"ai_flows", FieldDefinitions<{
|
|
125
|
+
readonly id: ColumnBuilder<string, "id">;
|
|
126
|
+
readonly name: ColumnBuilder<string, "text">;
|
|
127
|
+
readonly description: ColumnBuilder<string | null, "text">;
|
|
128
|
+
/** 'deterministic' | 'agentic' — the execution mode (replaces allowDeviation). */
|
|
129
|
+
readonly mode: ColumnBuilder<string, "text">;
|
|
130
|
+
/** 'draft' | 'active' | 'archived'. */
|
|
131
|
+
readonly status: ColumnBuilder<string, "text">;
|
|
132
|
+
/** 'private' | 'organization' | 'shared'. */
|
|
133
|
+
readonly visibility: ColumnBuilder<string, "text">;
|
|
134
|
+
readonly orchestratorModel: ColumnBuilder<string | null, "text">;
|
|
135
|
+
readonly orchestratorInstructions: ColumnBuilder<string | null, "text">;
|
|
136
|
+
/** Agentic loop bound; clamped [1,100] at run (default 30). */
|
|
137
|
+
readonly maxSteps: ColumnBuilder<number, "integer">;
|
|
138
|
+
/** The ordered plan (`FlowStep[]`); null ≡ empty. */
|
|
139
|
+
readonly steps: ColumnBuilder<readonly {
|
|
140
|
+
readonly id: string;
|
|
141
|
+
readonly type: "generate" | "agent" | "structured" | "note" | "human";
|
|
142
|
+
readonly description?: string | undefined;
|
|
143
|
+
readonly outputKey?: string | undefined;
|
|
144
|
+
readonly schema?: {
|
|
145
|
+
readonly [x: string]: unknown;
|
|
146
|
+
} | undefined;
|
|
147
|
+
readonly title?: string | undefined;
|
|
148
|
+
readonly prompt?: string | undefined;
|
|
149
|
+
readonly modality?: "text" | "image" | "video" | "audio" | undefined;
|
|
150
|
+
readonly model?: string | undefined;
|
|
151
|
+
readonly params?: {
|
|
152
|
+
readonly [x: string]: unknown;
|
|
153
|
+
} | undefined;
|
|
154
|
+
readonly mediaInputs?: {
|
|
155
|
+
readonly [x: string]: {
|
|
156
|
+
readonly from: "upload";
|
|
157
|
+
readonly url: string;
|
|
158
|
+
} | {
|
|
159
|
+
readonly from: "step";
|
|
160
|
+
readonly ref: string;
|
|
161
|
+
};
|
|
162
|
+
} | undefined;
|
|
163
|
+
readonly agentRef?: string | undefined;
|
|
164
|
+
readonly reviewMode?: "text" | "approve" | "choice" | undefined;
|
|
165
|
+
readonly options?: readonly {
|
|
166
|
+
readonly value: string;
|
|
167
|
+
readonly label: string;
|
|
168
|
+
}[] | undefined;
|
|
169
|
+
}[] | null, "json">;
|
|
170
|
+
/** The launch-form brief (`BriefField[]`). */
|
|
171
|
+
readonly inputSchema: ColumnBuilder<readonly {
|
|
172
|
+
readonly key: string;
|
|
173
|
+
readonly type: "number" | "boolean" | "text" | "textarea";
|
|
174
|
+
readonly required?: boolean | undefined;
|
|
175
|
+
readonly label: string;
|
|
176
|
+
readonly placeholder?: string | undefined;
|
|
177
|
+
}[] | null, "json">;
|
|
178
|
+
readonly chainTo: ColumnBuilder<{
|
|
179
|
+
readonly flowRef: string;
|
|
180
|
+
readonly mappings: readonly {
|
|
181
|
+
readonly sourceKey: string;
|
|
182
|
+
readonly targetKey: string;
|
|
183
|
+
}[];
|
|
184
|
+
readonly requireConfirmation?: boolean | undefined;
|
|
185
|
+
} | null, "json">;
|
|
186
|
+
readonly cadence: ColumnBuilder<{
|
|
187
|
+
readonly frequency?: "weekly" | "monthly" | undefined;
|
|
188
|
+
readonly repeats: readonly number[];
|
|
189
|
+
readonly intervalWeeks?: number | undefined;
|
|
190
|
+
readonly anchorDate?: string | undefined;
|
|
191
|
+
readonly weekOfMonth?: 1 | 2 | 3 | 4 | "last" | undefined;
|
|
192
|
+
readonly hour?: number | undefined;
|
|
193
|
+
readonly minute?: 0 | 15 | 30 | 45 | undefined;
|
|
194
|
+
readonly defaultInput?: {
|
|
195
|
+
readonly [x: string]: unknown;
|
|
196
|
+
} | undefined;
|
|
197
|
+
} | null, "json">;
|
|
198
|
+
/** Master on/off — gates scheduling. */
|
|
199
|
+
readonly isEnabled: ColumnBuilder<boolean, "boolean">;
|
|
200
|
+
readonly metadata: ColumnBuilder<Record<string, unknown> | null, "json">;
|
|
201
|
+
readonly icon: ColumnBuilder<string | null, "text">;
|
|
202
|
+
readonly color: ColumnBuilder<string | null, "text">;
|
|
203
|
+
/** Flow avatar as a plain URL (avoids a hard storage-plugin schema dep). */
|
|
204
|
+
readonly avatarUrl: ColumnBuilder<string | null, "text">;
|
|
205
|
+
/** Run counter (incremented on launch). */
|
|
206
|
+
readonly usageCount: ColumnBuilder<number, "integer">;
|
|
207
|
+
/** App subject the flow belongs to (distinct from audit `createdBy` → actors). */
|
|
208
|
+
readonly ownerId: ColumnBuilder<string | null, "text">;
|
|
209
|
+
}> & {
|
|
210
|
+
tenantId: ColumnDefinition<string>;
|
|
211
|
+
} & {
|
|
212
|
+
readonly createdAt: ColumnDefinition<Date, "timestamp">;
|
|
213
|
+
readonly updatedAt: ColumnDefinition<Date, "timestamp">;
|
|
214
|
+
readonly createdBy: ColumnDefinition<string | null, "reference">;
|
|
215
|
+
readonly updatedBy: ColumnDefinition<string | null, "reference">;
|
|
216
|
+
} & {
|
|
217
|
+
readonly deletedAt: ColumnDefinition<Date | null, "timestamp">;
|
|
218
|
+
readonly deletedBy: ColumnDefinition<string | null, "reference">;
|
|
219
|
+
}, true, never>;
|
|
220
|
+
|
|
221
|
+
/** Every table this plugin contributes (fed to `extendSchema`). */
|
|
222
|
+
export declare const aiFlowsTables: ReadonlyArray<TableLike>;
|
|
223
|
+
|
|
224
|
+
/** A launch-form field. The run `input` is keyed by these `key`s. */
|
|
225
|
+
export declare const BriefField: Schema.Struct<{
|
|
226
|
+
key: typeof Schema.String;
|
|
227
|
+
label: typeof Schema.String;
|
|
228
|
+
type: Schema.Literal<["text", "textarea", "number", "boolean"]>;
|
|
229
|
+
required: Schema.optional<typeof Schema.Boolean>;
|
|
230
|
+
placeholder: Schema.optional<typeof Schema.String>;
|
|
231
|
+
}>;
|
|
232
|
+
|
|
233
|
+
export declare type BriefField = typeof BriefField.Type;
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Build the `flow.run` executor over a live `AppContext` + injected capabilities.
|
|
237
|
+
* The consumer's `flow.run.workflow.server.tsx` does:
|
|
238
|
+
* `export default (ctx) => buildFlowRunExecute(ctx, myDeps)`.
|
|
239
|
+
*/
|
|
240
|
+
export declare const buildFlowRunExecute: (ctx: AppContext, deps?: EngineDeps) => (payload: FlowRunPayload, _executionId: string) => Effect.Effect<{
|
|
241
|
+
runId: string;
|
|
242
|
+
status: "cancelled";
|
|
243
|
+
output?: never;
|
|
244
|
+
} | {
|
|
245
|
+
runId: string;
|
|
246
|
+
status: "failed";
|
|
247
|
+
output?: never;
|
|
248
|
+
} | {
|
|
249
|
+
runId: string;
|
|
250
|
+
status: "succeeded";
|
|
251
|
+
output: Record<string, unknown>;
|
|
252
|
+
}, never, WorkflowEngine | WorkflowInstance>;
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Does `cadence` fire at wall-clock `now`? True only on a 15-min slot matching
|
|
256
|
+
* the configured hour/minute, on a configured weekday, and — for interval-weekly
|
|
257
|
+
* or monthly cadences — in the right week/occurrence.
|
|
258
|
+
*/
|
|
259
|
+
export declare const cadenceMatches: (cadence: FlowCadence, now: Date) => boolean;
|
|
260
|
+
|
|
261
|
+
/** Cooperatively cancel a run: flip the row → the engine aborts before its next
|
|
262
|
+
* step (it can't interrupt an in-flight generation). */
|
|
263
|
+
export declare const cancelFlow: (ctx: AppContext, args: {
|
|
264
|
+
runId: string;
|
|
265
|
+
}) => Effect.Effect<{
|
|
266
|
+
runId: string;
|
|
267
|
+
status: RunStatus;
|
|
268
|
+
}, FlowRunNotFound, never>;
|
|
269
|
+
|
|
270
|
+
/** Staged follow-up when `chainTo.requireConfirmation` is set. */
|
|
271
|
+
export declare const ChainPending: Schema.Struct<{
|
|
272
|
+
flowRef: typeof Schema.String;
|
|
273
|
+
input: Schema.Record$<typeof Schema.String, typeof Schema.Unknown>;
|
|
274
|
+
status: Schema.Literal<["pending", "confirmed", "dismissed"]>;
|
|
275
|
+
}>;
|
|
276
|
+
|
|
277
|
+
export declare type ChainPending = typeof ChainPending.Type;
|
|
278
|
+
|
|
279
|
+
export declare const clampMaxSteps: (n: number | null | undefined) => number;
|
|
280
|
+
|
|
281
|
+
/** Clear the registry — test hygiene only. */
|
|
282
|
+
export declare const clearRegistry: () => void;
|
|
283
|
+
|
|
284
|
+
/** Every `{{ref}}` name referenced in `text` (order-preserving, may repeat). */
|
|
285
|
+
export declare const collectRefs: (text: string) => ReadonlyArray<string>;
|
|
286
|
+
|
|
287
|
+
/** Create a flow row. Generates an id when absent; tenant/audit columns are
|
|
288
|
+
* auto-stamped by the runtime. */
|
|
289
|
+
export declare const createFlow: (ctx: AppContext, fields: Record<string, unknown>) => Effect.Effect<Readonly<Record<string, unknown>>, never, never>;
|
|
290
|
+
|
|
291
|
+
/** Deterministic per-slot request id: same flow + same 15-min slot ⇒ same id. */
|
|
292
|
+
export declare const cronRequestId: (flowRef: string, now: Date) => string;
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Declare a code-first flow. Normalizes to the Flow IR, validates its `{{ref}}`
|
|
296
|
+
* graph, registers it (so `launch({ flowRef: name })` runs it), and returns the
|
|
297
|
+
* IR. Call at module load, e.g. in an app `flows/*.flow.ts` file.
|
|
298
|
+
*/
|
|
299
|
+
export declare const defineFlow: (input: DefineFlowInput) => FlowIR;
|
|
300
|
+
|
|
301
|
+
export declare interface DefineFlowInput {
|
|
302
|
+
readonly name: string;
|
|
303
|
+
readonly mode?: FlowMode;
|
|
304
|
+
readonly maxSteps?: number;
|
|
305
|
+
readonly steps: ReadonlyArray<FlowStepDraft | FlowStep>;
|
|
306
|
+
readonly brief?: ReadonlyArray<BriefField>;
|
|
307
|
+
readonly orchestrator?: {
|
|
308
|
+
readonly model?: string;
|
|
309
|
+
readonly instructions?: string;
|
|
310
|
+
};
|
|
311
|
+
readonly chain?: FlowChain;
|
|
312
|
+
readonly cadence?: FlowCadence;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/** Hard-delete a flow row by id. Returns whether a row was removed. */
|
|
316
|
+
export declare const deleteFlow: (ctx: AppContext, args: {
|
|
317
|
+
id: string;
|
|
318
|
+
}) => Effect.Effect<boolean, never, never>;
|
|
319
|
+
|
|
320
|
+
export declare interface EngineDeps {
|
|
321
|
+
/** Resolve an `agent` step's `agentRef` → system prompt + model. Absent →
|
|
322
|
+
* agent steps with an `agentRef` fail with FlowCapabilityMissing. */
|
|
323
|
+
readonly resolveAgent?: (agentRef: string) => Effect.Effect<AgentResolution, FlowNotFound>;
|
|
324
|
+
/** Media generator for image/video/audio steps (task #31 plugs in here). */
|
|
325
|
+
readonly generateMedia?: MediaGenerator;
|
|
326
|
+
/** Fallback model per modality when a step omits `model`. */
|
|
327
|
+
readonly defaultModels?: {
|
|
328
|
+
readonly text?: string;
|
|
329
|
+
readonly image?: string;
|
|
330
|
+
readonly video?: string;
|
|
331
|
+
readonly audio?: string;
|
|
332
|
+
};
|
|
333
|
+
/** Resolve a model string → a provider config. Absent → every call routes to
|
|
334
|
+
* the AI Gateway (`{ name:'gateway', model }`). Supply this to honour a
|
|
335
|
+
* `provider/model` prefix or pin a default provider (e.g. wrap the framework's
|
|
336
|
+
* `providerFromEnv`), so an app WITHOUT a valid gateway key can run the engine. */
|
|
337
|
+
readonly resolveModel?: (model: string) => ProviderConfig;
|
|
338
|
+
/** Lifecycle hook — wire to @voltro/plugin-notifications. Best-effort; a
|
|
339
|
+
* throwing/absent notifier never affects the run. */
|
|
340
|
+
readonly onEvent?: (event: FlowLifecycleEvent) => Effect.Effect<void>;
|
|
341
|
+
/** Long-term-memory prefix prepended to the orchestrator system prompt (wire
|
|
342
|
+
* to the app's ai_user_memories). Best-effort. */
|
|
343
|
+
readonly memoryPrefix?: (ownerId: string | null) => Effect.Effect<string>;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/** The canonical name the launch action starts + the app re-export registers. */
|
|
347
|
+
export declare const FLOW_RUN_WORKFLOW = "flow.run";
|
|
348
|
+
|
|
349
|
+
/** A required brief field was blank at launch. */
|
|
350
|
+
declare class FlowBriefIncomplete extends FlowBriefIncomplete_base {
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
declare const FlowBriefIncomplete_base: Schema.TaggedErrorClass<FlowBriefIncomplete, "FlowBriefIncomplete", {
|
|
354
|
+
readonly _tag: Schema.tag<"FlowBriefIncomplete">;
|
|
355
|
+
} & {
|
|
356
|
+
missing: Schema.Array$<typeof Schema.String>;
|
|
357
|
+
message: typeof Schema.String;
|
|
358
|
+
}>;
|
|
359
|
+
|
|
360
|
+
/** Schedule spec — richer than a single cron expr (weekly interval + anchor,
|
|
361
|
+
* monthly weekOfMonth), evaluated by the shared `cadenceMatches` predicate. */
|
|
362
|
+
export declare const FlowCadence: Schema.Struct<{
|
|
363
|
+
frequency: Schema.optional<Schema.Literal<["weekly", "monthly"]>>;
|
|
364
|
+
/** Weekdays, 0=Monday … 6=Sunday. */
|
|
365
|
+
repeats: Schema.Array$<typeof Schema.Number>;
|
|
366
|
+
/** Weekly cycle length: 1 | 2 | 4 (anchored by anchorDate). */
|
|
367
|
+
intervalWeeks: Schema.optional<typeof Schema.Number>;
|
|
368
|
+
/** ISO YYYY-MM-DD, cycle-0 week (interval > 1). */
|
|
369
|
+
anchorDate: Schema.optional<typeof Schema.String>;
|
|
370
|
+
weekOfMonth: Schema.optional<Schema.Union<[Schema.Literal<[1, 2, 3, 4]>, Schema.Literal<["last"]>]>>;
|
|
371
|
+
/** 0-23, default 9. */
|
|
372
|
+
hour: Schema.optional<typeof Schema.Number>;
|
|
373
|
+
minute: Schema.optional<Schema.Literal<[0, 15, 30, 45]>>;
|
|
374
|
+
/** Brief for unattended cron runs. */
|
|
375
|
+
defaultInput: Schema.optional<Schema.Record$<typeof Schema.String, typeof Schema.Unknown>>;
|
|
376
|
+
}>;
|
|
377
|
+
|
|
378
|
+
export declare type FlowCadence = typeof FlowCadence.Type;
|
|
379
|
+
|
|
380
|
+
/** A generation step required a capability the host did not provide (e.g. a
|
|
381
|
+
* media modality with no configured generator, or storage for the artifact). */
|
|
382
|
+
declare class FlowCapabilityMissing extends FlowCapabilityMissing_base {
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
declare const FlowCapabilityMissing_base: Schema.TaggedErrorClass<FlowCapabilityMissing, "FlowCapabilityMissing", {
|
|
386
|
+
readonly _tag: Schema.tag<"FlowCapabilityMissing">;
|
|
387
|
+
} & {
|
|
388
|
+
capability: typeof Schema.String;
|
|
389
|
+
message: typeof Schema.String;
|
|
390
|
+
}>;
|
|
391
|
+
|
|
392
|
+
/** Follow-up flow spec. On success, map source → the child's brief. */
|
|
393
|
+
export declare const FlowChain: Schema.Struct<{
|
|
394
|
+
/** Child flow id (data) or name (code). */
|
|
395
|
+
flowRef: typeof Schema.String;
|
|
396
|
+
mappings: Schema.Array$<Schema.Struct<{
|
|
397
|
+
targetKey: typeof Schema.String;
|
|
398
|
+
sourceKey: typeof Schema.String;
|
|
399
|
+
}>>;
|
|
400
|
+
requireConfirmation: Schema.optional<typeof Schema.Boolean>;
|
|
401
|
+
}>;
|
|
402
|
+
|
|
403
|
+
export declare type FlowChain = typeof FlowChain.Type;
|
|
404
|
+
|
|
405
|
+
/** The raw flow definition either front door supplies before normalization.
|
|
406
|
+
* Optional fields tolerate explicit `undefined` (row reads produce it). */
|
|
407
|
+
export declare interface FlowDefinitionInput {
|
|
408
|
+
readonly name: string;
|
|
409
|
+
readonly mode?: FlowMode | undefined;
|
|
410
|
+
readonly steps?: ReadonlyArray<FlowStep> | undefined;
|
|
411
|
+
readonly maxSteps?: number | null | undefined;
|
|
412
|
+
readonly brief?: ReadonlyArray<BriefField> | undefined;
|
|
413
|
+
readonly orchestratorModel?: string | null | undefined;
|
|
414
|
+
readonly orchestratorInstructions?: string | null | undefined;
|
|
415
|
+
readonly chain?: FlowChain | null | undefined;
|
|
416
|
+
readonly cadence?: FlowCadence | null | undefined;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/** The single representation the engine interprets, from either front door. */
|
|
420
|
+
export declare interface FlowIR {
|
|
421
|
+
readonly name: string;
|
|
422
|
+
readonly mode: FlowMode;
|
|
423
|
+
readonly steps: ReadonlyArray<FlowStep>;
|
|
424
|
+
readonly maxSteps: number;
|
|
425
|
+
readonly brief: ReadonlyArray<BriefField>;
|
|
426
|
+
readonly orchestrator?: {
|
|
427
|
+
readonly model?: string;
|
|
428
|
+
readonly instructions?: string;
|
|
429
|
+
};
|
|
430
|
+
readonly chain?: FlowChain;
|
|
431
|
+
readonly cadence?: FlowCadence;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/** A lifecycle event the host can turn into a notification (best-effort). */
|
|
435
|
+
export declare interface FlowLifecycleEvent {
|
|
436
|
+
readonly kind: 'succeeded' | 'failed' | 'review-needed';
|
|
437
|
+
readonly runId: string;
|
|
438
|
+
readonly flowName: string;
|
|
439
|
+
readonly ownerId: string | null;
|
|
440
|
+
readonly source: 'manual' | 'cron';
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/** Execution mode. Replaces the legacy `allowDeviation` boolean — a mode is not
|
|
444
|
+
* a boolean. `deterministic` runs the plan verbatim (resumable per step);
|
|
445
|
+
* `agentic` lets an orchestrator LLM adapt the plan via the four tools. */
|
|
446
|
+
export declare const FlowMode: Schema.Literal<["deterministic", "agentic"]>;
|
|
447
|
+
|
|
448
|
+
export declare type FlowMode = typeof FlowMode.Type;
|
|
449
|
+
|
|
450
|
+
/** A run cannot accept a human response in its current state (not `waiting`,
|
|
451
|
+
* already answered, or cancelled). */
|
|
452
|
+
declare class FlowNotAwaitingResponse extends FlowNotAwaitingResponse_base {
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
declare const FlowNotAwaitingResponse_base: Schema.TaggedErrorClass<FlowNotAwaitingResponse, "FlowNotAwaitingResponse", {
|
|
456
|
+
readonly _tag: Schema.tag<"FlowNotAwaitingResponse">;
|
|
457
|
+
} & {
|
|
458
|
+
runId: typeof Schema.String;
|
|
459
|
+
status: typeof Schema.String;
|
|
460
|
+
message: typeof Schema.String;
|
|
461
|
+
}>;
|
|
462
|
+
|
|
463
|
+
/** A flow (definition) could not be resolved by ref (code name or row id). */
|
|
464
|
+
declare class FlowNotFound extends FlowNotFound_base {
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
declare const FlowNotFound_base: Schema.TaggedErrorClass<FlowNotFound, "FlowNotFound", {
|
|
468
|
+
readonly _tag: Schema.tag<"FlowNotFound">;
|
|
469
|
+
} & {
|
|
470
|
+
flowRef: typeof Schema.String;
|
|
471
|
+
message: typeof Schema.String;
|
|
472
|
+
}>;
|
|
473
|
+
|
|
474
|
+
/** A flow run row could not be found. */
|
|
475
|
+
declare class FlowRunNotFound extends FlowRunNotFound_base {
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
declare const FlowRunNotFound_base: Schema.TaggedErrorClass<FlowRunNotFound, "FlowRunNotFound", {
|
|
479
|
+
readonly _tag: Schema.tag<"FlowRunNotFound">;
|
|
480
|
+
} & {
|
|
481
|
+
runId: typeof Schema.String;
|
|
482
|
+
message: typeof Schema.String;
|
|
483
|
+
}>;
|
|
484
|
+
|
|
485
|
+
/** The workflow payload shape (server executor input). */
|
|
486
|
+
export declare interface FlowRunPayload {
|
|
487
|
+
readonly runId: string;
|
|
488
|
+
readonly flowRef: string;
|
|
489
|
+
readonly input: Record<string, unknown>;
|
|
490
|
+
readonly source: 'manual' | 'cron';
|
|
491
|
+
readonly requestId: string;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/** Flow-definition lifecycle. */
|
|
495
|
+
export declare const FlowStatus: Schema.Literal<["draft", "active", "archived"]>;
|
|
496
|
+
|
|
497
|
+
export declare type FlowStatus = typeof FlowStatus.Type;
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* A plan step. This is the AUTHORED shape — stored on `ai_flows.steps` (data
|
|
501
|
+
* front door) or produced by `defineFlow`'s builders (code front door). The
|
|
502
|
+
* engine interprets it; later steps reference an earlier step's deliverable via
|
|
503
|
+
* `{{outputKey}}` in `prompt` / media refs.
|
|
504
|
+
*/
|
|
505
|
+
export declare const FlowStep: Schema.Struct<{
|
|
506
|
+
id: typeof Schema.String;
|
|
507
|
+
title: Schema.optional<typeof Schema.String>;
|
|
508
|
+
/** Informational; shown under the step in the run timeline. */
|
|
509
|
+
description: Schema.optional<typeof Schema.String>;
|
|
510
|
+
type: Schema.Literal<["agent", "generate", "structured", "note", "human"]>;
|
|
511
|
+
/** Sanitized [\w.-]; the result-bundle key + the `{{ref}}` name. */
|
|
512
|
+
outputKey: Schema.optional<typeof Schema.String>;
|
|
513
|
+
/** Template with `{{key}}` placeholders (brief inputs + prior outputKeys). */
|
|
514
|
+
prompt: Schema.optional<typeof Schema.String>;
|
|
515
|
+
modality: Schema.optional<Schema.Literal<["text", "image", "video", "audio"]>>;
|
|
516
|
+
model: Schema.optional<typeof Schema.String>;
|
|
517
|
+
params: Schema.optional<Schema.Record$<typeof Schema.String, typeof Schema.Unknown>>;
|
|
518
|
+
mediaInputs: Schema.optional<Schema.Record$<typeof Schema.String, Schema.Union<[Schema.Struct<{
|
|
519
|
+
from: Schema.Literal<["upload"]>;
|
|
520
|
+
url: typeof Schema.String;
|
|
521
|
+
}>, Schema.Struct<{
|
|
522
|
+
from: Schema.Literal<["step"]>;
|
|
523
|
+
ref: typeof Schema.String;
|
|
524
|
+
}>]>>>;
|
|
525
|
+
/** Allowed sub-agent id/name. The framework resolves a real id; any
|
|
526
|
+
* legacy-numeric bridge stays in the consumer app's mapping. */
|
|
527
|
+
agentRef: Schema.optional<typeof Schema.String>;
|
|
528
|
+
/** JSON Schema of the desired object (adapted to an Effect Schema at run). */
|
|
529
|
+
schema: Schema.optional<Schema.Record$<typeof Schema.String, typeof Schema.Unknown>>;
|
|
530
|
+
reviewMode: Schema.optional<Schema.Literal<["approve", "choice", "text"]>>;
|
|
531
|
+
options: Schema.optional<Schema.Array$<Schema.Struct<{
|
|
532
|
+
value: typeof Schema.String;
|
|
533
|
+
label: typeof Schema.String;
|
|
534
|
+
}>>>;
|
|
535
|
+
}>;
|
|
536
|
+
|
|
537
|
+
export declare type FlowStep = typeof FlowStep.Type;
|
|
538
|
+
|
|
539
|
+
/** Typed builders for each step kind — terser + safer than hand-writing the
|
|
540
|
+
* union. Every builder returns a draft; `defineFlow` assigns the id. */
|
|
541
|
+
export declare const flowStep: {
|
|
542
|
+
/** A text generation. */
|
|
543
|
+
text: (o: {
|
|
544
|
+
title?: string;
|
|
545
|
+
description?: string;
|
|
546
|
+
prompt: string;
|
|
547
|
+
model?: string;
|
|
548
|
+
outputKey?: string;
|
|
549
|
+
}) => FlowStepDraft;
|
|
550
|
+
/** An image/video/audio generation. */
|
|
551
|
+
media: (modality: Modality, o: {
|
|
552
|
+
title?: string;
|
|
553
|
+
description?: string;
|
|
554
|
+
prompt: string;
|
|
555
|
+
model?: string;
|
|
556
|
+
params?: Record<string, unknown>;
|
|
557
|
+
outputKey?: string;
|
|
558
|
+
}) => FlowStepDraft;
|
|
559
|
+
/** Delegate to an allowed sub-agent (text-only). */
|
|
560
|
+
agent: (o: {
|
|
561
|
+
title?: string;
|
|
562
|
+
description?: string;
|
|
563
|
+
agentRef: string;
|
|
564
|
+
prompt: string;
|
|
565
|
+
model?: string;
|
|
566
|
+
outputKey?: string;
|
|
567
|
+
}) => FlowStepDraft;
|
|
568
|
+
/** Return a JSON object validated against a JSON Schema. */
|
|
569
|
+
structured: (o: {
|
|
570
|
+
title?: string;
|
|
571
|
+
description?: string;
|
|
572
|
+
prompt: string;
|
|
573
|
+
schema: Record<string, unknown>;
|
|
574
|
+
model?: string;
|
|
575
|
+
outputKey?: string;
|
|
576
|
+
}) => FlowStepDraft;
|
|
577
|
+
/** Free-text guidance — the interpolated prompt itself is the output. */
|
|
578
|
+
note: (o: {
|
|
579
|
+
title?: string;
|
|
580
|
+
description?: string;
|
|
581
|
+
prompt: string;
|
|
582
|
+
outputKey?: string;
|
|
583
|
+
}) => FlowStepDraft;
|
|
584
|
+
/** Pause for human review. */
|
|
585
|
+
human: (o: {
|
|
586
|
+
title?: string;
|
|
587
|
+
description?: string;
|
|
588
|
+
reviewMode: ReviewMode;
|
|
589
|
+
options?: ReadonlyArray<ReviewOption>;
|
|
590
|
+
prompt?: string;
|
|
591
|
+
outputKey?: string;
|
|
592
|
+
}) => FlowStepDraft;
|
|
593
|
+
};
|
|
594
|
+
|
|
595
|
+
/** A step without its `id` — `defineFlow` assigns stable index-based ids. */
|
|
596
|
+
export declare type FlowStepDraft = Omit<FlowStep, 'id'>;
|
|
597
|
+
|
|
598
|
+
/** One stored flow by id, or undefined (tenant-scoped by the runtime). */
|
|
599
|
+
export declare const getFlow: (ctx: AppContext, args: {
|
|
600
|
+
id: string;
|
|
601
|
+
}) => Effect.Effect<Record<string, unknown> | undefined, never, never>;
|
|
602
|
+
|
|
603
|
+
/** Resolve a code-registered flow by name, or `undefined` for a data flow. */
|
|
604
|
+
export declare const getRegisteredFlow: (name: string) => FlowIR | undefined;
|
|
605
|
+
|
|
606
|
+
/** The signal a `human` step parks on; `respondToFlow` sends it to resume. */
|
|
607
|
+
export declare const HUMAN_RESPONSE_SIGNAL = "flow-human-response";
|
|
608
|
+
|
|
609
|
+
/** The HITL answer, written by `respond`. */
|
|
610
|
+
export declare const HumanResponse: Schema.Struct<{
|
|
611
|
+
decision: Schema.optional<Schema.Literal<["approve", "reject"]>>;
|
|
612
|
+
value: Schema.optional<typeof Schema.String>;
|
|
613
|
+
text: Schema.optional<typeof Schema.String>;
|
|
614
|
+
respondedAt: Schema.optional<typeof Schema.String>;
|
|
615
|
+
}>;
|
|
616
|
+
|
|
617
|
+
export declare type HumanResponse = typeof HumanResponse.Type;
|
|
618
|
+
|
|
619
|
+
/** Replace `{{key}}` with `context[key]` (objects/arrays JSON-stringified; an
|
|
620
|
+
* absent/null value renders empty). */
|
|
621
|
+
export declare const interpolate: (text: string, context: Record<string, unknown>) => string;
|
|
622
|
+
|
|
623
|
+
/** A JSON value (for `params` / `input` / a `structured` step's JSON Schema). */
|
|
624
|
+
export declare const Json: Schema.Record$<typeof Schema.String, typeof Schema.Unknown>;
|
|
625
|
+
|
|
626
|
+
export declare type Json = typeof Json.Type;
|
|
627
|
+
|
|
628
|
+
/** Launch a fresh run of a flow (by code name or row id). Validates the brief,
|
|
629
|
+
* creates the run row, and starts the durable `flow.run` workflow. */
|
|
630
|
+
export declare const launchFlow: (ctx: AppContext, args: {
|
|
631
|
+
flowRef: string;
|
|
632
|
+
input?: Record<string, unknown>;
|
|
633
|
+
source?: "manual" | "cron";
|
|
634
|
+
}) => Effect.Effect<{
|
|
635
|
+
runId: string;
|
|
636
|
+
requestId: string;
|
|
637
|
+
status: RunStatus;
|
|
638
|
+
}, FlowNotFound | FlowBriefIncomplete, never>;
|
|
639
|
+
|
|
640
|
+
/** All stored flows for the caller's tenant. */
|
|
641
|
+
export declare const listFlows: (ctx: AppContext) => Effect.Effect<ReadonlyArray<Record<string, unknown>>>;
|
|
642
|
+
|
|
643
|
+
/** Every code-registered flow (for the inspect surface / cadence enumeration). */
|
|
644
|
+
export declare const listRegisteredFlows: () => ReadonlyArray<FlowIR>;
|
|
645
|
+
|
|
646
|
+
/**
|
|
647
|
+
* Build a `MediaGenerator` from a persistence adapter. Generates via @voltro/ai,
|
|
648
|
+
* persists the artifact, and returns `{ url, costMicroUsd, requestId? }`. Any
|
|
649
|
+
* failure (generation or persistence) surfaces as a typed `FlowCapabilityMissing`
|
|
650
|
+
* so the engine records a clean per-step error.
|
|
651
|
+
*/
|
|
652
|
+
export declare const makeMediaGenerator: (persist: MediaPersist, opts?: {
|
|
653
|
+
readonly resolveModel?: (model: string) => ProviderConfig;
|
|
654
|
+
}) => MediaGenerator;
|
|
655
|
+
|
|
656
|
+
/** Legacy default was 30, clamped to [1,100]. (Distinct from `@voltro/ai`'s
|
|
657
|
+
* own `maxSteps` default of 8 for a single tool loop.) */
|
|
658
|
+
export declare const MAX_STEPS_DEFAULT = 30;
|
|
659
|
+
|
|
660
|
+
export declare const MAX_STEPS_MAX = 100;
|
|
661
|
+
|
|
662
|
+
export declare const MAX_STEPS_MIN = 1;
|
|
663
|
+
|
|
664
|
+
/** Host-supplied media generator for image/video/audio steps — `@voltro/ai`'s
|
|
665
|
+
* first-class media gen (task #31) plugs in here via the app's server re-export. */
|
|
666
|
+
export declare type MediaGenerator = (args: {
|
|
667
|
+
readonly modality: 'image' | 'video' | 'audio';
|
|
668
|
+
readonly model?: string;
|
|
669
|
+
readonly prompt: string;
|
|
670
|
+
readonly params?: Record<string, unknown>;
|
|
671
|
+
readonly inputs?: Record<string, unknown>;
|
|
672
|
+
}) => Effect.Effect<MediaResult, FlowCapabilityMissing>;
|
|
673
|
+
|
|
674
|
+
export declare const MediaInputs: Schema.Record$<typeof Schema.String, Schema.Union<[Schema.Struct<{
|
|
675
|
+
from: Schema.Literal<["upload"]>;
|
|
676
|
+
url: typeof Schema.String;
|
|
677
|
+
}>, Schema.Struct<{
|
|
678
|
+
from: Schema.Literal<["step"]>;
|
|
679
|
+
ref: typeof Schema.String;
|
|
680
|
+
}>]>>;
|
|
681
|
+
|
|
682
|
+
export declare type MediaInputs = typeof MediaInputs.Type;
|
|
683
|
+
|
|
684
|
+
/** A media-input slot for a video `generate` step — either an uploaded URL or a
|
|
685
|
+
* reference to a prior step's output. Keyed by capability slot name
|
|
686
|
+
* (`referenceImageUrl`, `lastFrameImageUrl`, `referenceVideoUrl`, …). */
|
|
687
|
+
export declare const MediaInputSlot: Schema.Union<[Schema.Struct<{
|
|
688
|
+
from: Schema.Literal<["upload"]>;
|
|
689
|
+
url: typeof Schema.String;
|
|
690
|
+
}>, Schema.Struct<{
|
|
691
|
+
from: Schema.Literal<["step"]>;
|
|
692
|
+
ref: typeof Schema.String;
|
|
693
|
+
}>]>;
|
|
694
|
+
|
|
695
|
+
export declare type MediaInputSlot = typeof MediaInputSlot.Type;
|
|
696
|
+
|
|
697
|
+
/** Host-supplied persistence (from @voltro/plugin-storage's StorageService). */
|
|
698
|
+
export declare interface MediaPersist {
|
|
699
|
+
/** Store raw bytes / base64 → a hosted URL (StorageService.put). */
|
|
700
|
+
readonly put: (args: {
|
|
701
|
+
data: Uint8Array | string;
|
|
702
|
+
mediaType: string;
|
|
703
|
+
}) => Promise<StoredMedia>;
|
|
704
|
+
/** Re-host a provider URL (StorageService.ingestUrl). If absent, a provider
|
|
705
|
+
* video URL is used as-is (no re-hosting). */
|
|
706
|
+
readonly ingestUrl?: (url: string) => Promise<StoredMedia>;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
/** Media generation result (the host generator persists the artifact + returns
|
|
710
|
+
* a hosted URL). */
|
|
711
|
+
export declare interface MediaResult {
|
|
712
|
+
readonly url: string;
|
|
713
|
+
readonly costMicroUsd?: number;
|
|
714
|
+
readonly requestId?: string;
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
export declare const Modality: Schema.Literal<["text", "image", "video", "audio"]>;
|
|
718
|
+
|
|
719
|
+
export declare type Modality = typeof Modality.Type;
|
|
720
|
+
|
|
721
|
+
/**
|
|
722
|
+
* The next `count` fire times at/after `from`, by stepping 15-min slots and
|
|
723
|
+
* testing `cadenceMatches`. Bounded to a ~400-day horizon so a never-matching
|
|
724
|
+
* cadence can't loop forever. Returns the fire `Date`s.
|
|
725
|
+
*/
|
|
726
|
+
export declare const nextRuns: (cadence: FlowCadence, from: Date, count?: number) => ReadonlyArray<Date>;
|
|
727
|
+
|
|
728
|
+
/**
|
|
729
|
+
* Lower a raw flow definition (from code or a row) to the normalized IR:
|
|
730
|
+
* default the mode, clamp maxSteps, sanitize outputKeys, drop empties. Pure +
|
|
731
|
+
* browser-safe so the editor can preview exactly what the engine will run.
|
|
732
|
+
*/
|
|
733
|
+
export declare const normalizeFlow: (def: FlowDefinitionInput) => FlowIR;
|
|
734
|
+
|
|
735
|
+
/** Register (or replace) a code-defined flow by its IR name. Called by
|
|
736
|
+
* `defineFlow` when the module is loaded. */
|
|
737
|
+
export declare const registerFlow: (ir: FlowIR) => void;
|
|
738
|
+
|
|
739
|
+
/** Resolve the IR: code registry by name first, else the stored `ai_flows` row. */
|
|
740
|
+
export declare const resolveIr: (ctx: AppContext, flowRef: string) => Effect.Effect<FlowIR, FlowNotFound>;
|
|
741
|
+
|
|
742
|
+
/** Record a human's answer to a `waiting` run + signal the parked workflow to
|
|
743
|
+
* resume. (The park itself lands with the slot-freeing await, task #32/#35.) */
|
|
744
|
+
export declare const respondToFlow: (ctx: AppContext, args: {
|
|
745
|
+
runId: string;
|
|
746
|
+
response: HumanResponse;
|
|
747
|
+
}) => Effect.Effect<{
|
|
748
|
+
runId: string;
|
|
749
|
+
}, FlowRunNotFound | FlowNotAwaitingResponse, never>;
|
|
750
|
+
|
|
751
|
+
/** Re-run a run from its first unfinished step. Reuses the SAME requestId so the
|
|
752
|
+
* workflow's idempotencyKey resolves to the same execution → journal replay
|
|
753
|
+
* resumes (deterministic runs skip already-succeeded steps). */
|
|
754
|
+
export declare const retryFlow: (ctx: AppContext, args: {
|
|
755
|
+
runId: string;
|
|
756
|
+
}) => Effect.Effect<{
|
|
757
|
+
runId: string;
|
|
758
|
+
requestId: string;
|
|
759
|
+
status: RunStatus;
|
|
760
|
+
}, FlowRunNotFound, never>;
|
|
761
|
+
|
|
762
|
+
export declare const ReviewMode: Schema.Literal<["approve", "choice", "text"]>;
|
|
763
|
+
|
|
764
|
+
export declare type ReviewMode = typeof ReviewMode.Type;
|
|
765
|
+
|
|
766
|
+
export declare const ReviewOption: Schema.Struct<{
|
|
767
|
+
value: typeof Schema.String;
|
|
768
|
+
label: typeof Schema.String;
|
|
769
|
+
}>;
|
|
770
|
+
|
|
771
|
+
export declare type ReviewOption = typeof ReviewOption.Type;
|
|
772
|
+
|
|
773
|
+
/**
|
|
774
|
+
* Evaluate every enabled flow's cadence against `now` and start a `flow.run` per
|
|
775
|
+
* match. Returns the started request ids. Idempotent across replicas +
|
|
776
|
+
* re-invocations within a slot (deterministic requestId + the run-row insert
|
|
777
|
+
* tolerates the duplicate). Never throws — a single bad flow can't abort the tick.
|
|
778
|
+
*/
|
|
779
|
+
export declare const runCadenceTick: (ctx: AppContext, now?: Date) => Promise<{
|
|
780
|
+
readonly matched: number;
|
|
781
|
+
readonly started: ReadonlyArray<string>;
|
|
782
|
+
}>;
|
|
783
|
+
|
|
784
|
+
/** Human-review config projected onto a `waiting` run step. */
|
|
785
|
+
export declare const RunReview: Schema.Struct<{
|
|
786
|
+
mode: Schema.Literal<["approve", "choice", "text"]>;
|
|
787
|
+
options: Schema.optional<Schema.Array$<Schema.Struct<{
|
|
788
|
+
value: typeof Schema.String;
|
|
789
|
+
label: typeof Schema.String;
|
|
790
|
+
}>>>;
|
|
791
|
+
prompt: typeof Schema.String;
|
|
792
|
+
}>;
|
|
793
|
+
|
|
794
|
+
export declare type RunReview = typeof RunReview.Type;
|
|
795
|
+
|
|
796
|
+
/** What triggered a run. */
|
|
797
|
+
export declare const RunSource: Schema.Literal<["manual", "cron"]>;
|
|
798
|
+
|
|
799
|
+
export declare type RunSource = typeof RunSource.Type;
|
|
800
|
+
|
|
801
|
+
/** Run status — ONE canonical set (the legacy vocabulary; the Voltro-port
|
|
802
|
+
* additions `awaiting_human`/`completed`/`rejected` are collapsed: `waiting`
|
|
803
|
+
* covers the human pause, `succeeded` is the single terminal-success literal). */
|
|
804
|
+
export declare const RunStatus: Schema.Literal<["pending", "running", "waiting", "succeeded", "failed", "cancelled"]>;
|
|
805
|
+
|
|
806
|
+
export declare type RunStatus = typeof RunStatus.Type;
|
|
807
|
+
|
|
808
|
+
export declare const RunStep: Schema.Struct<{
|
|
809
|
+
id: typeof Schema.Number;
|
|
810
|
+
title: typeof Schema.String;
|
|
811
|
+
description: Schema.optional<typeof Schema.String>;
|
|
812
|
+
type: Schema.Literal<["agent", "generate", "structured", "note", "human"]>;
|
|
813
|
+
status: Schema.Literal<["pending", "running", "waiting", "succeeded", "failed"]>;
|
|
814
|
+
startedAt: Schema.optional<typeof Schema.String>;
|
|
815
|
+
completedAt: Schema.optional<typeof Schema.String>;
|
|
816
|
+
/** Per-step cost in micro-USD (the app view projects to €/cents). */
|
|
817
|
+
costMicroUsd: Schema.optional<typeof Schema.Number>;
|
|
818
|
+
/** Links a media step to its generation/usage record. */
|
|
819
|
+
requestId: Schema.optional<typeof Schema.String>;
|
|
820
|
+
/** Hosted media artifact URL (image/video/audio), via storage. */
|
|
821
|
+
url: Schema.optional<typeof Schema.String>;
|
|
822
|
+
/** Inline text output (rendered as markdown). */
|
|
823
|
+
output: Schema.optional<Schema.Struct<{
|
|
824
|
+
text: typeof Schema.String;
|
|
825
|
+
}>>;
|
|
826
|
+
errorMessage: Schema.optional<typeof Schema.String>;
|
|
827
|
+
review: Schema.optional<Schema.Struct<{
|
|
828
|
+
mode: Schema.Literal<["approve", "choice", "text"]>;
|
|
829
|
+
options: Schema.optional<Schema.Array$<Schema.Struct<{
|
|
830
|
+
value: typeof Schema.String;
|
|
831
|
+
label: typeof Schema.String;
|
|
832
|
+
}>>>;
|
|
833
|
+
prompt: typeof Schema.String;
|
|
834
|
+
}>>;
|
|
835
|
+
}>;
|
|
836
|
+
|
|
837
|
+
export declare type RunStep = typeof RunStep.Type;
|
|
838
|
+
|
|
839
|
+
export declare const RunStepStatus: Schema.Literal<["pending", "running", "waiting", "succeeded", "failed"]>;
|
|
840
|
+
|
|
841
|
+
export declare type RunStepStatus = typeof RunStepStatus.Type;
|
|
842
|
+
|
|
843
|
+
/** Sanitize an outputKey to the `{{ref}}`-safe charset. */
|
|
844
|
+
export declare const sanitizeOutputKey: (key: string) => string;
|
|
845
|
+
|
|
846
|
+
/** The five step types. `generate` fans out to four modalities. */
|
|
847
|
+
export declare const StepType: Schema.Literal<["agent", "generate", "structured", "note", "human"]>;
|
|
848
|
+
|
|
849
|
+
export declare type StepType = typeof StepType.Type;
|
|
850
|
+
|
|
851
|
+
/** A persisted artifact — a hosted URL + optional storage ref id. */
|
|
852
|
+
export declare interface StoredMedia {
|
|
853
|
+
readonly url: string;
|
|
854
|
+
readonly refId?: string;
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
/** The `{{ref}}`s in `text` whose producing key is absent/null in `context` —
|
|
858
|
+
* the agentic/deterministic dependency guard: a non-empty result means a step
|
|
859
|
+
* depends on an output that never materialized (its producer failed/skipped). */
|
|
860
|
+
export declare const unresolvedRefs: (text: string, context: Record<string, unknown>) => ReadonlyArray<string>;
|
|
861
|
+
|
|
862
|
+
/** Patch a flow row by id. Returns the post-image (or null when absent). */
|
|
863
|
+
export declare const updateFlow: (ctx: AppContext, args: {
|
|
864
|
+
id: string;
|
|
865
|
+
patch: Record<string, unknown>;
|
|
866
|
+
}) => Effect.Effect<Readonly<Record<string, unknown>> | null, never, never>;
|
|
867
|
+
|
|
868
|
+
/**
|
|
869
|
+
* Validate that every `{{ref}}` a step's prompt uses resolves to a brief field
|
|
870
|
+
* or an EARLIER step's `outputKey` (order matters). Throws FlowValidationError
|
|
871
|
+
* with all issues so a bad code flow fails at registration, not mid-run.
|
|
872
|
+
*/
|
|
873
|
+
export declare const validateFlow: (ir: FlowIR) => void;
|
|
874
|
+
|
|
875
|
+
/** Gallery scope. `shared` → per-subject share list; `organization` → tenant. */
|
|
876
|
+
export declare const Visibility: Schema.Literal<["private", "organization", "shared"]>;
|
|
877
|
+
|
|
878
|
+
export declare type Visibility = typeof Visibility.Type;
|
|
879
|
+
|
|
880
|
+
export { }
|