@leitwerk-dev/process-sdk 0.1.9 → 0.2.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/dist/{chunk-TRQJ5PRM.js → chunk-TA4KO53Q.js} +1 -5
- package/dist/chunk-TA4KO53Q.js.map +1 -0
- package/dist/{chunk-5RJZ2E7D.js → chunk-WFY2WWZE.js} +2 -6
- package/dist/{chunk-5RJZ2E7D.js.map → chunk-WFY2WWZE.js.map} +1 -1
- package/dist/core-capabilities.d.ts +70 -34
- package/dist/core-capabilities.d.ts.map +1 -1
- package/dist/define-process.d.ts +17 -49
- package/dist/define-process.d.ts.map +1 -1
- package/dist/{extension-api-BBcwktmc.d.ts → extension-api-CcqZCYJx.d.ts} +136 -70
- package/dist/extension-api.d.ts +115 -7
- package/dist/extension-api.d.ts.map +1 -1
- package/dist/external-action-source.d.ts +7 -0
- package/dist/external-action-source.d.ts.map +1 -0
- package/dist/external-source-poll.d.ts +15 -0
- package/dist/external-source-poll.d.ts.map +1 -0
- package/dist/flow.d.ts +80 -104
- package/dist/flow.d.ts.map +1 -1
- package/dist/fs-utils.d.ts +2 -0
- package/dist/fs-utils.d.ts.map +1 -1
- package/dist/git-binary.js +25 -33
- package/dist/git-binary.js.map +1 -1
- package/dist/index.d.ts +21 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4694 -29
- package/dist/index.js.map +1 -1
- package/dist/integration-http.d.ts +21 -0
- package/dist/integration-http.d.ts.map +1 -0
- package/dist/json-data.d.ts +3 -0
- package/dist/json-data.d.ts.map +1 -0
- package/dist/leaf-outcome-renderer.js +74 -64
- package/dist/leaf-outcome-renderer.js.map +1 -1
- package/dist/leaf-outcomes.d.ts.map +1 -1
- package/dist/model-provider.d.ts.map +1 -1
- package/dist/pi-config.d.ts +1 -5
- package/dist/pi-config.d.ts.map +1 -1
- package/dist/pi-config.js +20 -180
- package/dist/pi-config.js.map +1 -1
- package/dist/process-flow-view.d.ts.map +1 -1
- package/dist/process-graph.d.ts.map +1 -1
- package/dist/process-watcher-source.d.ts.map +1 -1
- package/dist/project-binding.d.ts +9 -0
- package/dist/project-binding.d.ts.map +1 -0
- package/dist/registry-utils.d.ts.map +1 -1
- package/dist/repository-feedback.d.ts +29 -0
- package/dist/repository-feedback.d.ts.map +1 -0
- package/dist/repository-git-env.d.ts +2 -0
- package/dist/repository-git-env.d.ts.map +1 -1
- package/dist/repository-http.d.ts +19 -0
- package/dist/repository-http.d.ts.map +1 -0
- package/dist/repository-https.d.ts +3 -0
- package/dist/repository-https.d.ts.map +1 -0
- package/dist/repository-issue-watcher.d.ts +31 -0
- package/dist/repository-issue-watcher.d.ts.map +1 -0
- package/dist/repository-source-config.d.ts +32 -0
- package/dist/repository-source-config.d.ts.map +1 -0
- package/dist/repository-types.d.ts +36 -0
- package/dist/repository-types.d.ts.map +1 -0
- package/dist/review-flow.js +12 -43
- package/dist/review-flow.js.map +1 -1
- package/dist/runtime-internals.js +18 -2
- package/dist/runtime-internals.js.map +1 -1
- package/dist/state-helpers.d.ts +2 -0
- package/dist/state-helpers.d.ts.map +1 -1
- package/dist/subprocess-env.d.ts +1 -0
- package/dist/subprocess-env.d.ts.map +1 -1
- package/dist/tool-arguments.d.ts +7 -0
- package/dist/tool-arguments.d.ts.map +1 -0
- package/dist/turn-semantics.d.ts +5 -6
- package/dist/turn-semantics.d.ts.map +1 -1
- package/dist/types.d.ts +5 -15
- package/dist/types.d.ts.map +1 -1
- package/package.json +6 -5
- package/src/core-capabilities.ts +81 -37
- package/src/define-process.ts +190 -313
- package/src/extension-api.ts +142 -6
- package/src/external-action-source.ts +12 -0
- package/src/external-source-poll.ts +49 -0
- package/src/flow.ts +332 -664
- package/src/fs-utils.ts +17 -2
- package/src/index.ts +54 -13
- package/src/integration-http.ts +58 -0
- package/src/json-data.ts +25 -0
- package/src/leaf-outcomes.ts +1 -9
- package/src/model-provider.ts +10 -23
- package/src/pi-config.ts +1 -6
- package/src/process-flow-view.ts +32 -88
- package/src/process-graph.ts +25 -51
- package/src/process-watcher-source.ts +3 -6
- package/src/project-binding.ts +36 -0
- package/src/registry-utils.ts +1 -5
- package/src/repository-feedback.ts +59 -0
- package/src/repository-git-env.ts +34 -0
- package/src/repository-http.ts +71 -0
- package/src/repository-https.ts +22 -0
- package/src/repository-issue-watcher.ts +92 -0
- package/src/repository-source-config.ts +60 -0
- package/src/repository-types.ts +25 -0
- package/src/state-helpers.ts +8 -4
- package/src/subprocess-env.ts +6 -0
- package/src/tool-arguments.ts +37 -0
- package/src/turn-semantics.ts +31 -75
- package/src/types.ts +5 -15
- package/dist/browser-ui-extension.js +0 -2
- package/dist/browser-ui-extension.js.map +0 -1
- package/dist/capabilities.js +0 -7
- package/dist/capabilities.js.map +0 -1
- package/dist/chunk-TRQJ5PRM.js.map +0 -1
- package/dist/codecs.js +0 -9
- package/dist/codecs.js.map +0 -1
- package/dist/commit-message.js +0 -3
- package/dist/commit-message.js.map +0 -1
- package/dist/core-capabilities.js +0 -6
- package/dist/core-capabilities.js.map +0 -1
- package/dist/define-process.js +0 -1078
- package/dist/define-process.js.map +0 -1
- package/dist/event-bus.js +0 -31
- package/dist/event-bus.js.map +0 -1
- package/dist/extension-api.js +0 -5
- package/dist/extension-api.js.map +0 -1
- package/dist/flow.js +0 -1645
- package/dist/flow.js.map +0 -1
- package/dist/form-contract.js +0 -2
- package/dist/form-contract.js.map +0 -1
- package/dist/fs-utils.js +0 -23
- package/dist/fs-utils.js.map +0 -1
- package/dist/graph-fragments.js +0 -57
- package/dist/graph-fragments.js.map +0 -1
- package/dist/host-capabilities.js +0 -42
- package/dist/host-capabilities.js.map +0 -1
- package/dist/launcher-contract.js +0 -2
- package/dist/launcher-contract.js.map +0 -1
- package/dist/leaf-outcomes.js +0 -52
- package/dist/leaf-outcomes.js.map +0 -1
- package/dist/model-provider.js +0 -171
- package/dist/model-provider.js.map +0 -1
- package/dist/process-definition-internals.js +0 -25
- package/dist/process-definition-internals.js.map +0 -1
- package/dist/process-flow-view.js +0 -418
- package/dist/process-flow-view.js.map +0 -1
- package/dist/process-graph.js +0 -212
- package/dist/process-graph.js.map +0 -1
- package/dist/process-launcher-builder.js +0 -43
- package/dist/process-launcher-builder.js.map +0 -1
- package/dist/process-watcher-builder.js +0 -40
- package/dist/process-watcher-builder.js.map +0 -1
- package/dist/process-watcher-source.js +0 -52
- package/dist/process-watcher-source.js.map +0 -1
- package/dist/registry-utils.js +0 -18
- package/dist/registry-utils.js.map +0 -1
- package/dist/repository-git-env.js +0 -26
- package/dist/repository-git-env.js.map +0 -1
- package/dist/server-events.js +0 -2
- package/dist/server-events.js.map +0 -1
- package/dist/server-process-builder.js +0 -52
- package/dist/server-process-builder.js.map +0 -1
- package/dist/state-helpers.js +0 -18
- package/dist/state-helpers.js.map +0 -1
- package/dist/subprocess-env.js +0 -34
- package/dist/subprocess-env.js.map +0 -1
- package/dist/tool-renderers.js +0 -63
- package/dist/tool-renderers.js.map +0 -1
- package/dist/turn-semantics.js +0 -365
- package/dist/turn-semantics.js.map +0 -1
- package/dist/types.js +0 -23
- package/dist/types.js.map +0 -1
- package/dist/ui-process-builder.js +0 -30
- package/dist/ui-process-builder.js.map +0 -1
- package/dist/worker-process-builder.js +0 -22
- package/dist/worker-process-builder.js.map +0 -1
package/src/define-process.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
assertValidProcessProductName,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
type ProcessInputTarget,
|
|
3
|
+
trimString as normalizeEffectString,
|
|
4
|
+
normalizeStringArray as normalizeEffectStringArray,
|
|
6
5
|
type ProcessInstance,
|
|
7
6
|
type ProcessSemanticEntryRefKey,
|
|
8
7
|
type ProcessTurnStartSelection,
|
|
@@ -12,24 +11,16 @@ import {
|
|
|
12
11
|
type TurnProgressReport,
|
|
13
12
|
} from "@leitwerk-dev/domain";
|
|
14
13
|
import type {
|
|
15
|
-
Codec,
|
|
16
14
|
ExtensionProcessDefinition,
|
|
17
15
|
ExternalActionSource,
|
|
18
16
|
ExternalSourceEffect,
|
|
19
17
|
ExternalSourceResolveContext,
|
|
20
18
|
FormDefinition,
|
|
21
|
-
ProcessLauncherAPI,
|
|
22
19
|
ProcessTurnBinding,
|
|
23
20
|
ProcessTurnOutcomeEvent,
|
|
24
|
-
ProcessWatcherAPI,
|
|
25
|
-
RepositoryCredentialProject,
|
|
26
|
-
RepositoryCredentialRequirement,
|
|
27
|
-
ServerProcessAPI,
|
|
28
21
|
ServerProcessContext,
|
|
29
22
|
ServerTransitionRequest,
|
|
30
|
-
UiProcessAPI,
|
|
31
23
|
WorkerCompleteInput,
|
|
32
|
-
WorkerProcessAPI,
|
|
33
24
|
WorkerProcessContext,
|
|
34
25
|
} from "./extension-api.js";
|
|
35
26
|
import {
|
|
@@ -47,7 +38,6 @@ import type {
|
|
|
47
38
|
PiBuiltInToolName,
|
|
48
39
|
ProcessActionPreviewDefinition,
|
|
49
40
|
ProcessActionSchedulingDefinition,
|
|
50
|
-
ProcessPiConfig,
|
|
51
41
|
TurnAcceptanceState,
|
|
52
42
|
TurnBranchType,
|
|
53
43
|
TurnCompletionMode,
|
|
@@ -62,12 +52,7 @@ type ProcessEmittedEvent = {
|
|
|
62
52
|
data: unknown;
|
|
63
53
|
};
|
|
64
54
|
|
|
65
|
-
type ProcessQueuedInput =
|
|
66
|
-
source: InputSource;
|
|
67
|
-
kind: InputKind;
|
|
68
|
-
bodyMarkdown: string;
|
|
69
|
-
target?: ProcessInputTarget;
|
|
70
|
-
};
|
|
55
|
+
type ProcessQueuedInput = Parameters<ServerProcessContext["queueInput"]>[0];
|
|
71
56
|
|
|
72
57
|
type MaybePromise<T> = T | Promise<T>;
|
|
73
58
|
|
|
@@ -89,6 +74,12 @@ type NormalizedActionRoute = NormalizedRouteTarget & {
|
|
|
89
74
|
export interface ProcessRuntimeTurnContext<TParams = unknown, TState = unknown>
|
|
90
75
|
extends WorkerProcessContext<TParams, TState> {}
|
|
91
76
|
|
|
77
|
+
export interface LlmTurnPreparationContext<TParams = unknown, TState = unknown>
|
|
78
|
+
extends ProcessRuntimeTurnContext<TParams, TState> {
|
|
79
|
+
callIntegrationTool(name: string, args: Record<string, unknown>): Promise<unknown>;
|
|
80
|
+
reportProgress(report: TurnProgressReport): void;
|
|
81
|
+
}
|
|
82
|
+
|
|
92
83
|
export interface ProcessServerRuntimeContext<TParams = unknown, TState = unknown> {
|
|
93
84
|
readonly process: ServerProcessContext<TParams, TState>["process"];
|
|
94
85
|
readonly projects: ServerProcessContext<TParams, TState>["projects"];
|
|
@@ -243,9 +234,9 @@ interface ProcessToolOutcomeBaseSpec<TParams = unknown, TState = unknown> {
|
|
|
243
234
|
publishedProduct?: string;
|
|
244
235
|
/** Outcome parameter whose markdown value is captured as the turn result. */
|
|
245
236
|
turnResultMarkdownParameter?: string;
|
|
237
|
+
/** Outcome parameter containing a concise operator-facing summary. */
|
|
238
|
+
resultSummaryParameter?: string;
|
|
246
239
|
effect?: ProcessOutcomeEffect<TParams, TState>;
|
|
247
|
-
/** Parks the process on this turn after recording the outcome. */
|
|
248
|
-
wait?: true;
|
|
249
240
|
lifecycleIntent?: ProcessOutcomeLifecycleIntent<TParams, TState>;
|
|
250
241
|
}
|
|
251
242
|
|
|
@@ -308,8 +299,12 @@ export interface LlmTurnDefinition<
|
|
|
308
299
|
availableTools: readonly PiBuiltInToolName[];
|
|
309
300
|
/** Server-owned integration tools proxied over authenticated worker IPC. */
|
|
310
301
|
integrationTools?: readonly string[];
|
|
302
|
+
/** Resolve a constrained tool set from validated durable process data at turn start. */
|
|
303
|
+
resolveIntegrationTools?: (params: TParams, state: TState) => readonly string[];
|
|
311
304
|
/** Opt in to the durable, operator-facing ask_questions custom tool. */
|
|
312
305
|
askQuestions?: boolean;
|
|
306
|
+
/** Deterministic worker preparation that must complete before Pi is prompted. */
|
|
307
|
+
prepare?(ctx: LlmTurnPreparationContext<TParams, TState>): MaybePromise<unknown>;
|
|
313
308
|
completionMode?: TurnCompletionMode;
|
|
314
309
|
branchType: TurnBranchType;
|
|
315
310
|
context: TurnContextMode;
|
|
@@ -347,36 +342,6 @@ export interface AutomaticTurnDefinition<
|
|
|
347
342
|
): Promise<WorkerCompleteInput<TOutcome>> | WorkerCompleteInput<TOutcome>;
|
|
348
343
|
}
|
|
349
344
|
|
|
350
|
-
export interface ServerAutomaticTurnRunResult<TOutcome extends string = string, TState = unknown>
|
|
351
|
-
extends WorkerCompleteInput<TOutcome> {
|
|
352
|
-
state?: TState;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
export type ServerAutomaticTurnRestartBehavior = "rerun" | "fail_running";
|
|
356
|
-
|
|
357
|
-
export interface ServerAutomaticTurnDefinition<
|
|
358
|
-
TOutcome extends string = string,
|
|
359
|
-
TParams = unknown,
|
|
360
|
-
TState = unknown,
|
|
361
|
-
> {
|
|
362
|
-
kind: "server_automatic";
|
|
363
|
-
description: string;
|
|
364
|
-
outcomes?: Partial<Record<TOutcome, ProcessToolOutcomeSpec<TParams, TState>>>;
|
|
365
|
-
turnEnd?: ProcessTurnEndSpec<TParams, TState, TOutcome>;
|
|
366
|
-
reviewSemanticRef?: ProcessSemanticEntryRefKey;
|
|
367
|
-
/**
|
|
368
|
-
* Controls startup/drainer behavior when a durable running turn record already exists.
|
|
369
|
-
* The default reruns the deterministic handler. Use fail_running for non-idempotent
|
|
370
|
-
* host side effects that must not be replayed after a server crash/restart.
|
|
371
|
-
*/
|
|
372
|
-
restartBehavior?: ServerAutomaticTurnRestartBehavior;
|
|
373
|
-
run(
|
|
374
|
-
ctx: ProcessServerRuntimeContext<TParams, TState>,
|
|
375
|
-
):
|
|
376
|
-
| Promise<ServerAutomaticTurnRunResult<TOutcome, TState>>
|
|
377
|
-
| ServerAutomaticTurnRunResult<TOutcome, TState>;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
345
|
export interface ExternalSourceTransition<
|
|
381
346
|
TParams = unknown,
|
|
382
347
|
TState = unknown,
|
|
@@ -397,7 +362,6 @@ export interface ExternalTurnDefinition<TParams = unknown, TState = unknown> {
|
|
|
397
362
|
export type TurnDefinition<TParams = unknown, TState = unknown> =
|
|
398
363
|
| LlmTurnDefinition<string, TParams, TState>
|
|
399
364
|
| AutomaticTurnDefinition<string, TParams, TState>
|
|
400
|
-
| ServerAutomaticTurnDefinition<string, TParams, TState>
|
|
401
365
|
| HumanTurnDefinition<TParams, TState>
|
|
402
366
|
| ExternalTurnDefinition<TParams, TState>;
|
|
403
367
|
|
|
@@ -411,28 +375,16 @@ export type ProcessDefinition<TParams = unknown, TState = unknown> = ExtensionPr
|
|
|
411
375
|
TState
|
|
412
376
|
>;
|
|
413
377
|
|
|
414
|
-
export interface DefinedProcessInput<TParams = unknown, TState = unknown>
|
|
415
|
-
|
|
416
|
-
|
|
378
|
+
export interface DefinedProcessInput<TParams = unknown, TState = unknown>
|
|
379
|
+
extends Omit<
|
|
380
|
+
ExtensionProcessDefinition<TParams, TState>,
|
|
381
|
+
"entryTurnId" | "alternateEntryTurnIds" | "turns"
|
|
382
|
+
> {
|
|
417
383
|
/** Primary entry used when a launch does not select a start turn explicitly. */
|
|
418
384
|
entry: TurnId;
|
|
419
385
|
/** Additional entry turns that launchers may select explicitly. */
|
|
420
386
|
alternateEntries?: readonly TurnId[];
|
|
421
|
-
happyPath?: readonly TurnId[];
|
|
422
|
-
paramsCodec: Codec<TParams>;
|
|
423
|
-
stateCodec: Codec<TState>;
|
|
424
|
-
initialState(params: TParams): TState;
|
|
425
|
-
repositoryCredentials?(input: {
|
|
426
|
-
params: TParams;
|
|
427
|
-
projects: readonly RepositoryCredentialProject[];
|
|
428
|
-
}): readonly RepositoryCredentialRequirement[];
|
|
429
|
-
piConfig?: ProcessPiConfig;
|
|
430
387
|
turns: TurnDefinitionRecord<TParams, TState>;
|
|
431
|
-
worker?: (api: WorkerProcessAPI<TParams, TState>) => void;
|
|
432
|
-
server?: (api: ServerProcessAPI<TParams, TState>) => void;
|
|
433
|
-
ui?: (api: UiProcessAPI<TParams, TState>) => void;
|
|
434
|
-
launchers?: (api: ProcessLauncherAPI<TParams>) => void;
|
|
435
|
-
watchers?: (api: ProcessWatcherAPI<TParams>) => void;
|
|
436
388
|
}
|
|
437
389
|
|
|
438
390
|
type CompiledActionRouting<TParams, TState> =
|
|
@@ -454,20 +406,9 @@ type CompiledActionUse<TParams, TState> = {
|
|
|
454
406
|
routing: CompiledActionRouting<TParams, TState>;
|
|
455
407
|
};
|
|
456
408
|
|
|
457
|
-
|
|
458
|
-
|
|
|
459
|
-
|
|
460
|
-
id: TurnId;
|
|
461
|
-
spec: LlmTurnDefinition<string, TParams, TState>;
|
|
462
|
-
}
|
|
463
|
-
| {
|
|
464
|
-
kind: "automatic";
|
|
465
|
-
id: TurnId;
|
|
466
|
-
spec: AutomaticTurnDefinition<string, TParams, TState>;
|
|
467
|
-
};
|
|
468
|
-
|
|
469
|
-
function createTransitionTargetError(context: string, detail: string): Error {
|
|
470
|
-
return new Error(`${context} ${detail}`);
|
|
409
|
+
interface CompiledOutcomeHandlers<TParams, TState> {
|
|
410
|
+
effects: ReadonlyMap<string, ProcessOutcomeEffect<TParams, TState> | undefined>;
|
|
411
|
+
routings: ReadonlyMap<string, CompiledOutcomeRouting<TParams, TState>>;
|
|
471
412
|
}
|
|
472
413
|
|
|
473
414
|
function createProcessTurnBinding<TTurn>(
|
|
@@ -491,14 +432,13 @@ function normalizeStaticRouteTarget(
|
|
|
491
432
|
(target.complete === true ? 1 : 0) +
|
|
492
433
|
(target.lifecycleStatus !== undefined ? 1 : 0);
|
|
493
434
|
if (declaredTargetCount !== 1) {
|
|
494
|
-
throw
|
|
495
|
-
context,
|
|
496
|
-
"must declare exactly one target via 'to', 'complete', or 'lifecycleStatus'",
|
|
435
|
+
throw new Error(
|
|
436
|
+
`${context} must declare exactly one target via 'to', 'complete', or 'lifecycleStatus'`,
|
|
497
437
|
);
|
|
498
438
|
}
|
|
499
439
|
if (target.to !== undefined) {
|
|
500
440
|
if (knownTurnIds && !knownTurnIds.has(target.to)) {
|
|
501
|
-
throw
|
|
441
|
+
throw new Error(`${context} references unknown turn '${target.to}'`);
|
|
502
442
|
}
|
|
503
443
|
return { nextTurnId: target.to };
|
|
504
444
|
}
|
|
@@ -519,9 +459,6 @@ function buildOutcomeTransition<TParams, TState>(
|
|
|
519
459
|
`Turn '${turnId}' outcome '${outcome}' must compile state routing before a static transition`,
|
|
520
460
|
);
|
|
521
461
|
}
|
|
522
|
-
if ("wait" in target && target.wait && hasDeclaredStaticRouteTarget(target)) {
|
|
523
|
-
throw new Error(`Turn '${turnId}' outcome '${outcome}' cannot wait and declare another route`);
|
|
524
|
-
}
|
|
525
462
|
if (!hasDeclaredStaticRouteTarget(target)) {
|
|
526
463
|
return { nextTurnId: turnId };
|
|
527
464
|
}
|
|
@@ -533,35 +470,30 @@ type CompiledOutcomeRouting<TParams, TState> = {
|
|
|
533
470
|
choose: ProcessOutcomeBranchSelector<TParams, TState>;
|
|
534
471
|
};
|
|
535
472
|
|
|
536
|
-
type
|
|
537
|
-
effect?: ProcessOutcomeEffect<TParams, TState>;
|
|
538
|
-
routing?: CompiledOutcomeRouting<TParams, TState>;
|
|
539
|
-
};
|
|
473
|
+
type BranchRouteSpec = StaticRouteTarget & { trigger?: string };
|
|
540
474
|
|
|
541
|
-
function
|
|
542
|
-
|
|
543
|
-
branches: Record<string, ProcessActionBranchSpec>;
|
|
475
|
+
function compileBranchRoutes(input: {
|
|
476
|
+
branches: Record<string, BranchRouteSpec>;
|
|
544
477
|
knownTurnIds?: ReadonlySet<TurnId>;
|
|
478
|
+
targetContext(branchId: string): string;
|
|
479
|
+
emptyBranchError: string;
|
|
480
|
+
duplicateTriggerError(trigger: string): string;
|
|
545
481
|
}): {
|
|
546
|
-
routes:
|
|
547
|
-
transitions:
|
|
482
|
+
routes: Record<string, NormalizedActionRoute>;
|
|
483
|
+
transitions: NormalizedActionRoute[];
|
|
548
484
|
} {
|
|
549
|
-
const entries = Object.entries(input.branches);
|
|
550
|
-
if (entries.length === 0) throw new Error(`${input.subject} must declare at least one branch`);
|
|
551
485
|
const routes: Record<string, NormalizedActionRoute> = {};
|
|
552
486
|
const transitions: NormalizedActionRoute[] = [];
|
|
553
487
|
const usedTriggers = new Set<string>();
|
|
554
|
-
for (const [branchId, branchSpec] of entries) {
|
|
555
|
-
if (branchId.trim() === "") throw new Error(
|
|
488
|
+
for (const [branchId, branchSpec] of Object.entries(input.branches)) {
|
|
489
|
+
if (branchId.trim() === "") throw new Error(input.emptyBranchError);
|
|
556
490
|
const target = normalizeStaticRouteTarget(
|
|
557
|
-
|
|
491
|
+
input.targetContext(branchId),
|
|
558
492
|
branchSpec,
|
|
559
493
|
input.knownTurnIds,
|
|
560
494
|
);
|
|
561
495
|
const trigger = branchSpec.trigger ?? branchId;
|
|
562
|
-
if (usedTriggers.has(trigger))
|
|
563
|
-
throw new Error(`${input.subject} contains duplicate branch trigger '${trigger}'`);
|
|
564
|
-
}
|
|
496
|
+
if (usedTriggers.has(trigger)) throw new Error(input.duplicateTriggerError(trigger));
|
|
565
497
|
usedTriggers.add(trigger);
|
|
566
498
|
const route = { ...target, trigger };
|
|
567
499
|
routes[branchId] = route;
|
|
@@ -579,10 +511,20 @@ function resolveOutcomeRouting<TParams, TState>(input: {
|
|
|
579
511
|
if (!("branches" in input.spec)) {
|
|
580
512
|
return null;
|
|
581
513
|
}
|
|
582
|
-
const
|
|
583
|
-
|
|
514
|
+
const entries = Object.entries(input.spec.branches);
|
|
515
|
+
if (entries.length === 0) {
|
|
516
|
+
throw new Error(
|
|
517
|
+
`Turn '${input.turnId}' outcome '${input.outcome}' must declare at least one branch`,
|
|
518
|
+
);
|
|
519
|
+
}
|
|
520
|
+
const { routes } = compileBranchRoutes({
|
|
584
521
|
branches: input.spec.branches,
|
|
585
522
|
knownTurnIds: input.knownTurnIds,
|
|
523
|
+
targetContext: (branchId) =>
|
|
524
|
+
`Turn '${input.turnId}' outcome '${input.outcome}' branch '${branchId}'`,
|
|
525
|
+
emptyBranchError: `Turn '${input.turnId}' outcome '${input.outcome}' contains an empty branch id`,
|
|
526
|
+
duplicateTriggerError: (trigger) =>
|
|
527
|
+
`Turn '${input.turnId}' outcome '${input.outcome}' contains duplicate branch trigger '${trigger}'`,
|
|
586
528
|
});
|
|
587
529
|
return { routes, choose: input.spec.choose };
|
|
588
530
|
}
|
|
@@ -597,13 +539,27 @@ function resolveActionRouting<TParams, TState>(input: {
|
|
|
597
539
|
transitions: readonly NormalizedActionRoute[];
|
|
598
540
|
} {
|
|
599
541
|
if ("branches" in input.spec) {
|
|
600
|
-
const
|
|
601
|
-
|
|
542
|
+
const entries = Object.entries(input.spec.branches) as Array<[string, ProcessActionBranchSpec]>;
|
|
543
|
+
if (entries.length === 0) {
|
|
544
|
+
throw new Error(
|
|
545
|
+
`Action '${input.actionId}' on turn '${input.turnId}' must declare at least one branch`,
|
|
546
|
+
);
|
|
547
|
+
}
|
|
548
|
+
const { routes, transitions } = compileBranchRoutes({
|
|
602
549
|
branches: input.spec.branches,
|
|
603
550
|
knownTurnIds: input.knownTurnIds,
|
|
551
|
+
targetContext: (branchId) =>
|
|
552
|
+
`Action '${input.actionId}' branch '${branchId}' on turn '${input.turnId}'`,
|
|
553
|
+
emptyBranchError: `Action '${input.actionId}' on turn '${input.turnId}' contains an empty branch id`,
|
|
554
|
+
duplicateTriggerError: (trigger) =>
|
|
555
|
+
`Action '${input.actionId}' on turn '${input.turnId}' contains duplicate branch trigger '${trigger}'`,
|
|
604
556
|
});
|
|
605
557
|
return {
|
|
606
|
-
routing: {
|
|
558
|
+
routing: {
|
|
559
|
+
kind: "branches",
|
|
560
|
+
routes,
|
|
561
|
+
choose: input.spec.choose,
|
|
562
|
+
},
|
|
607
563
|
transitions,
|
|
608
564
|
};
|
|
609
565
|
}
|
|
@@ -626,7 +582,7 @@ function resolveActionRouting<TParams, TState>(input: {
|
|
|
626
582
|
};
|
|
627
583
|
}
|
|
628
584
|
|
|
629
|
-
function
|
|
585
|
+
export function getExternalSourceTransitionId(input: {
|
|
630
586
|
turnId: TurnId;
|
|
631
587
|
source: ExternalActionSource;
|
|
632
588
|
index: number;
|
|
@@ -634,11 +590,14 @@ function externalSourceTransitionId(input: {
|
|
|
634
590
|
return `${input.turnId}:${input.source.kind}:${input.index}`;
|
|
635
591
|
}
|
|
636
592
|
|
|
637
|
-
function
|
|
593
|
+
export function getExternalActionArmingId(input: {
|
|
594
|
+
turnId: TurnId;
|
|
595
|
+
externalActionId: string;
|
|
596
|
+
}): string {
|
|
638
597
|
return `${input.turnId}:${input.externalActionId}`;
|
|
639
598
|
}
|
|
640
599
|
|
|
641
|
-
function
|
|
600
|
+
export function getExternalActionTransitionTrigger(input: { externalActionId: string }): string {
|
|
642
601
|
return `external:${input.externalActionId}`;
|
|
643
602
|
}
|
|
644
603
|
|
|
@@ -664,7 +623,7 @@ function compileExternalSourceTransitions<TParams, TState>(input: {
|
|
|
664
623
|
return {
|
|
665
624
|
...(target.nextTurnId ? { nextTurnId: target.nextTurnId } : {}),
|
|
666
625
|
...(target.lifecycleStatus ? { lifecycleStatus: target.lifecycleStatus } : {}),
|
|
667
|
-
trigger:
|
|
626
|
+
trigger: getExternalSourceTransitionId({
|
|
668
627
|
turnId: input.turnId,
|
|
669
628
|
source: transition.source,
|
|
670
629
|
index,
|
|
@@ -673,25 +632,6 @@ function compileExternalSourceTransitions<TParams, TState>(input: {
|
|
|
673
632
|
});
|
|
674
633
|
}
|
|
675
634
|
|
|
676
|
-
export function getExternalSourceTransitionId(input: {
|
|
677
|
-
turnId: TurnId;
|
|
678
|
-
source: ExternalActionSource;
|
|
679
|
-
index: number;
|
|
680
|
-
}): string {
|
|
681
|
-
return externalSourceTransitionId(input);
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
export function getExternalActionArmingId(input: {
|
|
685
|
-
turnId: TurnId;
|
|
686
|
-
externalActionId: string;
|
|
687
|
-
}): string {
|
|
688
|
-
return externalActionArmingId(input);
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
export function getExternalActionTransitionTrigger(input: { externalActionId: string }): string {
|
|
692
|
-
return externalActionTransitionTrigger(input);
|
|
693
|
-
}
|
|
694
|
-
|
|
695
635
|
function previewMatchesTransition(
|
|
696
636
|
preview: ProcessActionPreviewDefinition,
|
|
697
637
|
transition: NormalizedActionRoute,
|
|
@@ -815,18 +755,6 @@ function mergeProcessEffectPlans<TState>(
|
|
|
815
755
|
};
|
|
816
756
|
}
|
|
817
757
|
|
|
818
|
-
function normalizeEffectString(value: unknown): string {
|
|
819
|
-
return typeof value === "string" ? value.trim() : "";
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
function normalizeEffectStringArray(value: unknown): string[] {
|
|
823
|
-
return Array.isArray(value)
|
|
824
|
-
? value
|
|
825
|
-
.map((entry) => (typeof entry === "string" ? entry.trim() : ""))
|
|
826
|
-
.filter((entry) => entry !== "")
|
|
827
|
-
: [];
|
|
828
|
-
}
|
|
829
|
-
|
|
830
758
|
async function buildSavePlanResultEffect<TParams, TState>(input: {
|
|
831
759
|
intent: SavePlanResultLifecycleIntent<TParams, TState>;
|
|
832
760
|
execution: ProcessOutcomeExecution<TParams, TState>;
|
|
@@ -873,25 +801,21 @@ function resolveOutcomeEffect<TParams, TState>(input: {
|
|
|
873
801
|
spec: ProcessToolOutcomeSpec<TParams, TState> | ProcessTurnEndSpec<TParams, TState, string>;
|
|
874
802
|
}): ProcessOutcomeEffect<TParams, TState> | undefined {
|
|
875
803
|
const lifecycleIntent = "lifecycleIntent" in input.spec ? input.spec.lifecycleIntent : undefined;
|
|
876
|
-
|
|
877
|
-
|
|
804
|
+
if (!lifecycleIntent) {
|
|
805
|
+
return input.spec.effect;
|
|
806
|
+
}
|
|
878
807
|
return async (execution) => {
|
|
879
808
|
const explicitPlan = input.spec.effect ? await input.spec.effect(execution) : undefined;
|
|
880
809
|
let lifecyclePlan: ProcessEffectPlan<TState> | undefined;
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
break;
|
|
889
|
-
}
|
|
810
|
+
switch (lifecycleIntent.kind) {
|
|
811
|
+
case "save_plan_result":
|
|
812
|
+
lifecyclePlan = await buildSavePlanResultEffect({
|
|
813
|
+
intent: lifecycleIntent,
|
|
814
|
+
execution,
|
|
815
|
+
});
|
|
816
|
+
break;
|
|
890
817
|
}
|
|
891
|
-
|
|
892
|
-
return waits
|
|
893
|
-
? mergeProcessEffectPlans(result, { processPatch: { lifecycleStatus: "waiting" } })
|
|
894
|
-
: result;
|
|
818
|
+
return mergeProcessEffectPlans(explicitPlan, lifecyclePlan);
|
|
895
819
|
};
|
|
896
820
|
}
|
|
897
821
|
|
|
@@ -1030,9 +954,8 @@ function compileTurnOutcomeDefinitions<TParams, TState>(input: {
|
|
|
1030
954
|
outcomes?: Partial<Record<string, ProcessToolOutcomeSpec<TParams, TState>>>;
|
|
1031
955
|
turnEnd?: ProcessTurnEndSpec<TParams, TState, string>;
|
|
1032
956
|
knownTurnIds: ReadonlySet<TurnId>;
|
|
1033
|
-
}): {
|
|
957
|
+
}): CompiledOutcomeHandlers<TParams, TState> & {
|
|
1034
958
|
transitions: readonly ProcessTurnTransition[];
|
|
1035
|
-
outcomes: ReadonlyMap<string, CompiledOutcome<TParams, TState>>;
|
|
1036
959
|
} {
|
|
1037
960
|
const outcomeEntries = Object.entries(input.outcomes ?? {}) as Array<
|
|
1038
961
|
[string, ProcessToolOutcomeSpec<TParams, TState>]
|
|
@@ -1049,7 +972,8 @@ function compileTurnOutcomeDefinitions<TParams, TState>(input: {
|
|
|
1049
972
|
}
|
|
1050
973
|
|
|
1051
974
|
const transitions: ProcessTurnTransition[] = [];
|
|
1052
|
-
const
|
|
975
|
+
const effects = new Map<string, ProcessOutcomeEffect<TParams, TState> | undefined>();
|
|
976
|
+
const routings = new Map<string, CompiledOutcomeRouting<TParams, TState>>();
|
|
1053
977
|
for (const [outcome, spec] of outcomeEntries) {
|
|
1054
978
|
if (outcome.trim() === "") {
|
|
1055
979
|
throw new Error(`Turn '${input.turnId}' declares an empty outcome id`);
|
|
@@ -1064,6 +988,7 @@ function compileTurnOutcomeDefinitions<TParams, TState>(input: {
|
|
|
1064
988
|
? null
|
|
1065
989
|
: buildOutcomeTransition(input.turnId, outcome, spec, input.knownTurnIds);
|
|
1066
990
|
if (routing) {
|
|
991
|
+
routings.set(outcome, routing);
|
|
1067
992
|
for (const route of Object.values(routing.routes)) {
|
|
1068
993
|
transitions.push({
|
|
1069
994
|
...(route.nextTurnId ? { nextTurnId: route.nextTurnId } : {}),
|
|
@@ -1079,10 +1004,7 @@ function compileTurnOutcomeDefinitions<TParams, TState>(input: {
|
|
|
1079
1004
|
outcome,
|
|
1080
1005
|
});
|
|
1081
1006
|
}
|
|
1082
|
-
|
|
1083
|
-
effect: resolveOutcomeEffect({ spec }),
|
|
1084
|
-
...(routing ? { routing } : {}),
|
|
1085
|
-
});
|
|
1007
|
+
effects.set(outcome, resolveOutcomeEffect({ spec }));
|
|
1086
1008
|
}
|
|
1087
1009
|
|
|
1088
1010
|
if (input.turnEnd) {
|
|
@@ -1100,12 +1022,14 @@ function compileTurnOutcomeDefinitions<TParams, TState>(input: {
|
|
|
1100
1022
|
...(target.lifecycleStatus ? { lifecycleStatus: target.lifecycleStatus } : {}),
|
|
1101
1023
|
outcome: input.turnEnd.outcome,
|
|
1102
1024
|
});
|
|
1103
|
-
|
|
1104
|
-
effect: resolveOutcomeEffect({ spec: input.turnEnd }),
|
|
1105
|
-
});
|
|
1025
|
+
effects.set(input.turnEnd.outcome, resolveOutcomeEffect({ spec: input.turnEnd }));
|
|
1106
1026
|
}
|
|
1107
1027
|
|
|
1108
|
-
return {
|
|
1028
|
+
return {
|
|
1029
|
+
transitions,
|
|
1030
|
+
effects,
|
|
1031
|
+
routings,
|
|
1032
|
+
};
|
|
1109
1033
|
}
|
|
1110
1034
|
|
|
1111
1035
|
function addActionUse<TParams, TState>(input: {
|
|
@@ -1172,7 +1096,7 @@ function resolveExternalActionRoute<TParams, TState>(input: {
|
|
|
1172
1096
|
return {
|
|
1173
1097
|
...(target.nextTurnId ? { nextTurnId: target.nextTurnId } : {}),
|
|
1174
1098
|
...(target.lifecycleStatus ? { lifecycleStatus: target.lifecycleStatus } : {}),
|
|
1175
|
-
trigger:
|
|
1099
|
+
trigger: getExternalActionTransitionTrigger({ externalActionId: input.externalActionId }),
|
|
1176
1100
|
};
|
|
1177
1101
|
}
|
|
1178
1102
|
|
|
@@ -1235,73 +1159,12 @@ function validateActionPrimaryPrompt(
|
|
|
1235
1159
|
}
|
|
1236
1160
|
}
|
|
1237
1161
|
|
|
1238
|
-
function deriveExternalActions<TParams, TState>(input: {
|
|
1239
|
-
turnId: TurnId;
|
|
1240
|
-
externalActions?: Record<string, ProcessHumanTurnExternalActionSpec<TParams, TState>>;
|
|
1241
|
-
knownTurnIds?: ReadonlySet<TurnId>;
|
|
1242
|
-
turnDefinitionsById?: ReadonlyMap<TurnId, TurnDefinition<unknown, unknown>>;
|
|
1243
|
-
reservedTriggers?: ReadonlyMap<string, string>;
|
|
1244
|
-
}): {
|
|
1245
|
-
externalActions: readonly DerivedHumanTurnExternalAction<TParams, TState>[];
|
|
1246
|
-
transitions: readonly ProcessTurnTransition[];
|
|
1247
|
-
} {
|
|
1248
|
-
const externalActions: DerivedHumanTurnExternalAction<TParams, TState>[] = [];
|
|
1249
|
-
const transitions: ProcessTurnTransition[] = [];
|
|
1250
|
-
const usedTriggers = new Map(input.reservedTriggers);
|
|
1251
|
-
for (const [externalActionId, actionSpec] of Object.entries(input.externalActions ?? {})) {
|
|
1252
|
-
if (actionSpec.publishInput) {
|
|
1253
|
-
assertValidProcessProductName(actionSpec.publishInput.productName);
|
|
1254
|
-
if (actionSpec.publishInput.inputField.trim() === "") {
|
|
1255
|
-
throw new Error(
|
|
1256
|
-
`Turn '${input.turnId}' external action '${externalActionId}' publishInput must declare a non-empty inputField`,
|
|
1257
|
-
);
|
|
1258
|
-
}
|
|
1259
|
-
}
|
|
1260
|
-
validateExternalActionPublishedInputTarget({
|
|
1261
|
-
turnId: input.turnId,
|
|
1262
|
-
externalActionId,
|
|
1263
|
-
spec: actionSpec,
|
|
1264
|
-
turnDefinitionsById: input.turnDefinitionsById,
|
|
1265
|
-
});
|
|
1266
|
-
const transition = resolveExternalActionRoute({
|
|
1267
|
-
turnId: input.turnId,
|
|
1268
|
-
externalActionId,
|
|
1269
|
-
spec: actionSpec,
|
|
1270
|
-
knownTurnIds: input.knownTurnIds,
|
|
1271
|
-
});
|
|
1272
|
-
const existingActionId = usedTriggers.get(transition.trigger);
|
|
1273
|
-
if (existingActionId) {
|
|
1274
|
-
throw new Error(
|
|
1275
|
-
`Turn '${input.turnId}' contains duplicate trigger '${transition.trigger}' across action '${existingActionId}' and external action '${externalActionId}'`,
|
|
1276
|
-
);
|
|
1277
|
-
}
|
|
1278
|
-
usedTriggers.set(transition.trigger, externalActionId);
|
|
1279
|
-
transitions.push({
|
|
1280
|
-
...(transition.nextTurnId ? { nextTurnId: transition.nextTurnId } : {}),
|
|
1281
|
-
...(transition.lifecycleStatus ? { lifecycleStatus: transition.lifecycleStatus } : {}),
|
|
1282
|
-
trigger: transition.trigger,
|
|
1283
|
-
});
|
|
1284
|
-
externalActions.push({
|
|
1285
|
-
externalActionId,
|
|
1286
|
-
actionSpec,
|
|
1287
|
-
transition,
|
|
1288
|
-
view: {
|
|
1289
|
-
id: externalActionArmingId({ turnId: input.turnId, externalActionId }),
|
|
1290
|
-
externalActionId,
|
|
1291
|
-
sourceKind: actionSpec.source.kind,
|
|
1292
|
-
label: actionSpec.label ?? actionSpec.source.label ?? null,
|
|
1293
|
-
description: actionSpec.description ?? actionSpec.source.description ?? null,
|
|
1294
|
-
},
|
|
1295
|
-
});
|
|
1296
|
-
}
|
|
1297
|
-
return { externalActions, transitions };
|
|
1298
|
-
}
|
|
1299
|
-
|
|
1300
1162
|
function deriveHumanTurnActions<TParams, TState>(input: {
|
|
1301
1163
|
turnId: TurnId;
|
|
1302
1164
|
spec: HumanTurnDefinition<TParams, TState>;
|
|
1303
1165
|
knownTurnIds?: ReadonlySet<TurnId>;
|
|
1304
1166
|
turnDefinitionsById?: ReadonlyMap<TurnId, TurnDefinition<unknown, unknown>>;
|
|
1167
|
+
requireHumanActions?: boolean;
|
|
1305
1168
|
}): {
|
|
1306
1169
|
actions: readonly DerivedHumanTurnAction<TParams, TState>[];
|
|
1307
1170
|
externalActions: readonly DerivedHumanTurnExternalAction<TParams, TState>[];
|
|
@@ -1310,7 +1173,7 @@ function deriveHumanTurnActions<TParams, TState>(input: {
|
|
|
1310
1173
|
const actionEntries = Object.entries(input.spec.actions) as Array<
|
|
1311
1174
|
[string, ProcessHumanTurnActionSpec<TParams, TState>]
|
|
1312
1175
|
>;
|
|
1313
|
-
if (actionEntries.length === 0 && input.knownTurnIds) {
|
|
1176
|
+
if (actionEntries.length === 0 && input.knownTurnIds && input.requireHumanActions !== false) {
|
|
1314
1177
|
throw new Error(`Human turn '${input.turnId}' must declare at least one action`);
|
|
1315
1178
|
}
|
|
1316
1179
|
|
|
@@ -1384,17 +1247,68 @@ function deriveHumanTurnActions<TParams, TState>(input: {
|
|
|
1384
1247
|
});
|
|
1385
1248
|
}
|
|
1386
1249
|
|
|
1387
|
-
const
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1250
|
+
const externalActionEntries = Object.entries(input.spec.externalActions ?? {}) as Array<
|
|
1251
|
+
[string, ProcessHumanTurnExternalActionSpec<TParams, TState>]
|
|
1252
|
+
>;
|
|
1253
|
+
const derivedExternalActions: DerivedHumanTurnExternalAction<TParams, TState>[] = [];
|
|
1254
|
+
const externalActionIds = new Set<string>();
|
|
1255
|
+
for (const [externalActionId, actionSpec] of externalActionEntries) {
|
|
1256
|
+
if (externalActionIds.has(externalActionId)) {
|
|
1257
|
+
throw new Error(
|
|
1258
|
+
`Human turn '${input.turnId}' declares duplicate external action '${externalActionId}'`,
|
|
1259
|
+
);
|
|
1260
|
+
}
|
|
1261
|
+
externalActionIds.add(externalActionId);
|
|
1262
|
+
if (actionSpec.publishInput) {
|
|
1263
|
+
assertValidProcessProductName(actionSpec.publishInput.productName);
|
|
1264
|
+
if (actionSpec.publishInput.inputField.trim() === "") {
|
|
1265
|
+
throw new Error(
|
|
1266
|
+
`Human turn '${input.turnId}' external action '${externalActionId}' publishInput must declare a non-empty inputField`,
|
|
1267
|
+
);
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
validateExternalActionPublishedInputTarget({
|
|
1271
|
+
turnId: input.turnId,
|
|
1272
|
+
externalActionId,
|
|
1273
|
+
spec: actionSpec,
|
|
1274
|
+
turnDefinitionsById: input.turnDefinitionsById,
|
|
1275
|
+
});
|
|
1276
|
+
const transition = resolveExternalActionRoute({
|
|
1277
|
+
turnId: input.turnId,
|
|
1278
|
+
externalActionId,
|
|
1279
|
+
spec: actionSpec,
|
|
1280
|
+
knownTurnIds: input.knownTurnIds,
|
|
1281
|
+
});
|
|
1282
|
+
const existingActionId = actionIdByTrigger.get(transition.trigger);
|
|
1283
|
+
if (existingActionId) {
|
|
1284
|
+
throw new Error(
|
|
1285
|
+
`Human turn '${input.turnId}' contains duplicate trigger '${transition.trigger}' across action '${existingActionId}' and external action '${externalActionId}'`,
|
|
1286
|
+
);
|
|
1287
|
+
}
|
|
1288
|
+
actionIdByTrigger.set(transition.trigger, externalActionId);
|
|
1289
|
+
transitions.push({
|
|
1290
|
+
...(transition.nextTurnId ? { nextTurnId: transition.nextTurnId } : {}),
|
|
1291
|
+
...(transition.lifecycleStatus ? { lifecycleStatus: transition.lifecycleStatus } : {}),
|
|
1292
|
+
trigger: transition.trigger,
|
|
1293
|
+
});
|
|
1294
|
+
derivedExternalActions.push({
|
|
1295
|
+
externalActionId,
|
|
1296
|
+
actionSpec,
|
|
1297
|
+
transition,
|
|
1298
|
+
view: {
|
|
1299
|
+
id: getExternalActionArmingId({ turnId: input.turnId, externalActionId }),
|
|
1300
|
+
externalActionId,
|
|
1301
|
+
sourceKind: actionSpec.source.kind,
|
|
1302
|
+
label: actionSpec.label ?? actionSpec.source.label ?? null,
|
|
1303
|
+
description: actionSpec.description ?? actionSpec.source.description ?? null,
|
|
1304
|
+
},
|
|
1305
|
+
});
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1394
1308
|
return {
|
|
1395
1309
|
actions: derivedActions,
|
|
1396
|
-
externalActions:
|
|
1397
|
-
transitions
|
|
1310
|
+
externalActions: derivedExternalActions,
|
|
1311
|
+
transitions,
|
|
1398
1312
|
};
|
|
1399
1313
|
}
|
|
1400
1314
|
|
|
@@ -1468,12 +1382,6 @@ function compileExternalTurn<TParams, TState>(input: {
|
|
|
1468
1382
|
};
|
|
1469
1383
|
}
|
|
1470
1384
|
|
|
1471
|
-
function getTurnEntries<TParams, TState>(
|
|
1472
|
-
turns: TurnDefinitionRecord<TParams, TState>,
|
|
1473
|
-
): Array<[TurnId, TurnDefinition<TParams, TState>]> {
|
|
1474
|
-
return Object.entries(turns) as Array<[TurnId, TurnDefinition<TParams, TState>]>;
|
|
1475
|
-
}
|
|
1476
|
-
|
|
1477
1385
|
function resolveActionRouteForExecution<TParams, TState>(input: {
|
|
1478
1386
|
use: CompiledActionUse<TParams, TState>;
|
|
1479
1387
|
actionId: string;
|
|
@@ -1573,7 +1481,7 @@ function validateHappyPathConnectivity<TParams, TState>(input: {
|
|
|
1573
1481
|
function buildDefinedProcess<TParams, TState>(
|
|
1574
1482
|
input: DefinedProcessInput<TParams, TState>,
|
|
1575
1483
|
): Pick<ExtensionProcessDefinition<TParams, TState>, "turns" | "worker" | "server"> {
|
|
1576
|
-
const turnEntries =
|
|
1484
|
+
const turnEntries = Object.entries(input.turns);
|
|
1577
1485
|
if (turnEntries.length === 0) {
|
|
1578
1486
|
throw new Error(`Process '${input.id}' must declare at least one turn`);
|
|
1579
1487
|
}
|
|
@@ -1618,61 +1526,41 @@ function buildDefinedProcess<TParams, TState>(
|
|
|
1618
1526
|
|
|
1619
1527
|
const turns = new Map<TurnId, ProcessTurnBinding<TurnDefinition<TParams, TState>>>();
|
|
1620
1528
|
const actionUses = new Map<string, CompiledActionUse<TParams, TState>[]>();
|
|
1621
|
-
const
|
|
1529
|
+
const executableTurns = new Map<
|
|
1622
1530
|
TurnId,
|
|
1623
|
-
|
|
1531
|
+
CompiledOutcomeHandlers<TParams, TState> & {
|
|
1532
|
+
spec: RoutableTurnDefinition<string, TParams, TState>;
|
|
1533
|
+
}
|
|
1624
1534
|
>();
|
|
1625
|
-
const executableTurns = new Map<TurnId, CompiledExecutableTurn<TParams, TState>>();
|
|
1626
1535
|
|
|
1627
1536
|
for (const [turnId, turnSpec] of turnEntries) {
|
|
1628
|
-
if (turnSpec.kind === "llm") {
|
|
1629
|
-
const
|
|
1630
|
-
turnId,
|
|
1631
|
-
outcomes: turnSpec.outcomes,
|
|
1632
|
-
turnEnd: turnSpec.turnEnd,
|
|
1633
|
-
knownTurnIds,
|
|
1634
|
-
});
|
|
1635
|
-
turns.set(turnId, createProcessTurnBinding(turnSpec, compiledOutcomes.transitions));
|
|
1636
|
-
compiledOutcomesByTurn.set(turnId, compiledOutcomes.outcomes);
|
|
1637
|
-
executableTurns.set(turnId, {
|
|
1638
|
-
kind: "llm",
|
|
1639
|
-
id: turnId,
|
|
1640
|
-
spec: turnSpec,
|
|
1641
|
-
});
|
|
1642
|
-
continue;
|
|
1643
|
-
}
|
|
1644
|
-
|
|
1645
|
-
if (turnSpec.kind === "automatic" || turnSpec.kind === "server_automatic") {
|
|
1646
|
-
const compiledOutcomes = compileTurnOutcomeDefinitions({
|
|
1537
|
+
if (turnSpec.kind === "llm" || turnSpec.kind === "automatic") {
|
|
1538
|
+
const { transitions, effects, routings } = compileTurnOutcomeDefinitions({
|
|
1647
1539
|
turnId,
|
|
1648
1540
|
outcomes: turnSpec.outcomes,
|
|
1649
1541
|
turnEnd: turnSpec.turnEnd,
|
|
1650
1542
|
knownTurnIds,
|
|
1651
1543
|
});
|
|
1652
1544
|
const externalTransitions =
|
|
1653
|
-
turnSpec.kind === "automatic"
|
|
1654
|
-
?
|
|
1545
|
+
turnSpec.kind === "automatic" && turnSpec.externalActions
|
|
1546
|
+
? deriveHumanTurnActions({
|
|
1655
1547
|
turnId,
|
|
1656
|
-
|
|
1548
|
+
spec: {
|
|
1549
|
+
kind: "human",
|
|
1550
|
+
description: turnSpec.description,
|
|
1551
|
+
actions: {},
|
|
1552
|
+
externalActions: turnSpec.externalActions,
|
|
1553
|
+
},
|
|
1657
1554
|
knownTurnIds,
|
|
1658
1555
|
turnDefinitionsById,
|
|
1556
|
+
requireHumanActions: false,
|
|
1659
1557
|
}).transitions
|
|
1660
1558
|
: [];
|
|
1661
1559
|
turns.set(
|
|
1662
1560
|
turnId,
|
|
1663
|
-
createProcessTurnBinding(turnSpec, [
|
|
1664
|
-
...compiledOutcomes.transitions,
|
|
1665
|
-
...externalTransitions,
|
|
1666
|
-
]),
|
|
1561
|
+
createProcessTurnBinding(turnSpec, [...transitions, ...externalTransitions]),
|
|
1667
1562
|
);
|
|
1668
|
-
|
|
1669
|
-
if (turnSpec.kind === "automatic") {
|
|
1670
|
-
executableTurns.set(turnId, {
|
|
1671
|
-
kind: "automatic",
|
|
1672
|
-
id: turnId,
|
|
1673
|
-
spec: turnSpec,
|
|
1674
|
-
});
|
|
1675
|
-
}
|
|
1563
|
+
executableTurns.set(turnId, { spec: turnSpec, effects, routings });
|
|
1676
1564
|
continue;
|
|
1677
1565
|
}
|
|
1678
1566
|
|
|
@@ -1715,18 +1603,18 @@ function buildDefinedProcess<TParams, TState>(
|
|
|
1715
1603
|
api.turn(turnId, handler);
|
|
1716
1604
|
},
|
|
1717
1605
|
});
|
|
1718
|
-
for (const
|
|
1719
|
-
if (manuallyRegisteredTurns.has(
|
|
1606
|
+
for (const [turnId, { spec }] of executableTurns) {
|
|
1607
|
+
if (manuallyRegisteredTurns.has(turnId)) {
|
|
1720
1608
|
continue;
|
|
1721
1609
|
}
|
|
1722
|
-
if (
|
|
1723
|
-
api.turn(
|
|
1724
|
-
await run.turn(
|
|
1610
|
+
if (spec.kind === "llm") {
|
|
1611
|
+
api.turn(turnId, async (run) => {
|
|
1612
|
+
await run.turn(spec);
|
|
1725
1613
|
});
|
|
1726
1614
|
continue;
|
|
1727
1615
|
}
|
|
1728
|
-
api.turn(
|
|
1729
|
-
await run.complete(await
|
|
1616
|
+
api.turn(turnId, async (run) => {
|
|
1617
|
+
await run.complete(await spec.run(run.ctx));
|
|
1730
1618
|
});
|
|
1731
1619
|
}
|
|
1732
1620
|
};
|
|
@@ -1788,9 +1676,10 @@ function buildDefinedProcess<TParams, TState>(
|
|
|
1788
1676
|
});
|
|
1789
1677
|
}
|
|
1790
1678
|
|
|
1791
|
-
for (const [turnId,
|
|
1679
|
+
for (const [turnId, { effects, routings }] of executableTurns) {
|
|
1792
1680
|
api.onTurnOutcome(turnId, async (event, ctx) => {
|
|
1793
|
-
const
|
|
1681
|
+
const effect = effects.get(event.outcome);
|
|
1682
|
+
const routing = routings.get(event.outcome);
|
|
1794
1683
|
if (!effect && !routing) {
|
|
1795
1684
|
return;
|
|
1796
1685
|
}
|
|
@@ -1840,6 +1729,8 @@ export function defineProcess<TParams = unknown, TState = unknown>(
|
|
|
1840
1729
|
paramsCodec: input.paramsCodec,
|
|
1841
1730
|
stateCodec: input.stateCodec,
|
|
1842
1731
|
initialState: input.initialState,
|
|
1732
|
+
...(input.runtime ? { runtime: { ...input.runtime } } : {}),
|
|
1733
|
+
...(input.resolveStorageSize ? { resolveStorageSize: input.resolveStorageSize } : {}),
|
|
1843
1734
|
...(input.repositoryCredentials ? { repositoryCredentials: input.repositoryCredentials } : {}),
|
|
1844
1735
|
...(input.piConfig ? { piConfig: input.piConfig } : {}),
|
|
1845
1736
|
server: compiled.server,
|
|
@@ -1854,8 +1745,7 @@ export function defineProcess<TParams = unknown, TState = unknown>(
|
|
|
1854
1745
|
|
|
1855
1746
|
type RoutableTurnDefinition<TOutcome extends string, TParams, TState> =
|
|
1856
1747
|
| LlmTurnDefinition<TOutcome, TParams, TState>
|
|
1857
|
-
| AutomaticTurnDefinition<TOutcome, TParams, TState
|
|
1858
|
-
| ServerAutomaticTurnDefinition<TOutcome, TParams, TState>;
|
|
1748
|
+
| AutomaticTurnDefinition<TOutcome, TParams, TState>;
|
|
1859
1749
|
|
|
1860
1750
|
// biome-ignore-start lint/suspicious/noExplicitAny: conditional helper types must match and preserve any routable turn instantiation
|
|
1861
1751
|
type RoutableOutcome<TTurn> =
|
|
@@ -1926,19 +1816,6 @@ export function automaticTurn<
|
|
|
1926
1816
|
};
|
|
1927
1817
|
}
|
|
1928
1818
|
|
|
1929
|
-
export function serverAutomaticTurn<
|
|
1930
|
-
TParams = unknown,
|
|
1931
|
-
TState = unknown,
|
|
1932
|
-
TOutcome extends string = string,
|
|
1933
|
-
>(
|
|
1934
|
-
input: Omit<ServerAutomaticTurnDefinition<TOutcome, TParams, TState>, "kind">,
|
|
1935
|
-
): ServerAutomaticTurnDefinition<TOutcome, TParams, TState> {
|
|
1936
|
-
return {
|
|
1937
|
-
...input,
|
|
1938
|
-
kind: "server_automatic",
|
|
1939
|
-
};
|
|
1940
|
-
}
|
|
1941
|
-
|
|
1942
1819
|
export function humanTurn<TParams = unknown, TState = unknown>(
|
|
1943
1820
|
input: Omit<HumanTurnDefinition<TParams, TState>, "kind">,
|
|
1944
1821
|
): HumanTurnDefinition<TParams, TState> {
|