@leitwerk-dev/domain 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/dist/LICENSE +13 -0
- package/dist/actor.d.ts +18 -0
- package/dist/actor.d.ts.map +1 -0
- package/dist/actor.js +72 -0
- package/dist/actor.js.map +1 -0
- package/dist/domain-model.d.ts +472 -0
- package/dist/domain-model.d.ts.map +1 -0
- package/dist/domain-model.js +171 -0
- package/dist/domain-model.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/launcher-recent-values.d.ts +10 -0
- package/dist/launcher-recent-values.d.ts.map +1 -0
- package/dist/launcher-recent-values.js +60 -0
- package/dist/launcher-recent-values.js.map +1 -0
- package/dist/markdown-normalize.d.ts +4 -0
- package/dist/markdown-normalize.d.ts.map +1 -0
- package/dist/markdown-normalize.js +14 -0
- package/dist/markdown-normalize.js.map +1 -0
- package/dist/process-definitions.d.ts +68 -0
- package/dist/process-definitions.d.ts.map +1 -0
- package/dist/process-definitions.js +2 -0
- package/dist/process-definitions.js.map +1 -0
- package/dist/process-model-config.d.ts +24 -0
- package/dist/process-model-config.d.ts.map +1 -0
- package/dist/process-model-config.js +68 -0
- package/dist/process-model-config.js.map +1 -0
- package/dist/process-row-slots.d.ts +17 -0
- package/dist/process-row-slots.d.ts.map +1 -0
- package/dist/process-row-slots.js +45 -0
- package/dist/process-row-slots.js.map +1 -0
- package/dist/process-state-json.d.ts +16 -0
- package/dist/process-state-json.d.ts.map +1 -0
- package/dist/process-state-json.js +102 -0
- package/dist/process-state-json.js.map +1 -0
- package/dist/repo-locator.d.ts +10 -0
- package/dist/repo-locator.d.ts.map +1 -0
- package/dist/repo-locator.js +82 -0
- package/dist/repo-locator.js.map +1 -0
- package/dist/review-subject.d.ts +9 -0
- package/dist/review-subject.d.ts.map +1 -0
- package/dist/review-subject.js +18 -0
- package/dist/review-subject.js.map +1 -0
- package/dist/semantic-entry-refs.d.ts +34 -0
- package/dist/semantic-entry-refs.d.ts.map +1 -0
- package/dist/semantic-entry-refs.js +79 -0
- package/dist/semantic-entry-refs.js.map +1 -0
- package/dist/string-normalize.d.ts +12 -0
- package/dist/string-normalize.d.ts.map +1 -0
- package/dist/string-normalize.js +28 -0
- package/dist/string-normalize.js.map +1 -0
- package/dist/turn-acceptance.d.ts +3 -0
- package/dist/turn-acceptance.d.ts.map +1 -0
- package/dist/turn-acceptance.js +2 -0
- package/dist/turn-acceptance.js.map +1 -0
- package/dist/turn-annotations.d.ts +33 -0
- package/dist/turn-annotations.d.ts.map +1 -0
- package/dist/turn-annotations.js +49 -0
- package/dist/turn-annotations.js.map +1 -0
- package/dist/turn-recovery.d.ts +26 -0
- package/dist/turn-recovery.d.ts.map +1 -0
- package/dist/turn-recovery.js +70 -0
- package/dist/turn-recovery.js.map +1 -0
- package/dist/turn-start-resolution.d.ts +65 -0
- package/dist/turn-start-resolution.d.ts.map +1 -0
- package/dist/turn-start-resolution.js +97 -0
- package/dist/turn-start-resolution.js.map +1 -0
- package/package.json +40 -0
- package/src/actor.ts +78 -0
- package/src/domain-model.ts +739 -0
- package/src/index.ts +211 -0
- package/src/launcher-recent-values.ts +70 -0
- package/src/markdown-normalize.ts +15 -0
- package/src/process-definitions.ts +79 -0
- package/src/process-model-config.ts +110 -0
- package/src/process-row-slots.ts +64 -0
- package/src/process-state-json.ts +155 -0
- package/src/repo-locator.ts +101 -0
- package/src/review-subject.ts +26 -0
- package/src/semantic-entry-refs.ts +118 -0
- package/src/string-normalize.ts +30 -0
- package/src/turn-acceptance.ts +3 -0
- package/src/turn-annotations.ts +93 -0
- package/src/turn-recovery.ts +98 -0
- package/src/turn-start-resolution.ts +188 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
export {
|
|
2
|
+
normalizeActor,
|
|
3
|
+
parseActorOrSystem,
|
|
4
|
+
SERIALIZED_SYSTEM_ACTOR,
|
|
5
|
+
serializeActor,
|
|
6
|
+
} from "./actor.js";
|
|
7
|
+
export type {
|
|
8
|
+
Actor,
|
|
9
|
+
ActorKind,
|
|
10
|
+
CurrentExecutionRef,
|
|
11
|
+
DurableModelSelection,
|
|
12
|
+
ExternalWriteLog,
|
|
13
|
+
ExternalWriteType,
|
|
14
|
+
FutureExecution,
|
|
15
|
+
FutureExecutionBlockReason,
|
|
16
|
+
FutureExecutionKind,
|
|
17
|
+
FutureExecutionScheduleKind,
|
|
18
|
+
InputKind,
|
|
19
|
+
InputSource,
|
|
20
|
+
JsonObject,
|
|
21
|
+
LlmContextMode,
|
|
22
|
+
ModelPolicyFailureCode,
|
|
23
|
+
ModelSelectionKind,
|
|
24
|
+
ModelSelectionProvenance,
|
|
25
|
+
ModelSelectionSource,
|
|
26
|
+
NormalizedQuestion,
|
|
27
|
+
PreparedTurnStart,
|
|
28
|
+
ProcessCustomizableFields,
|
|
29
|
+
ProcessEvent,
|
|
30
|
+
ProcessInput,
|
|
31
|
+
ProcessInputTarget,
|
|
32
|
+
ProcessInstance,
|
|
33
|
+
ProcessLeafOutcomeSnapshot,
|
|
34
|
+
ProcessLeafOutcomeSnapshotStatus,
|
|
35
|
+
ProcessLifecycleStatus,
|
|
36
|
+
ProcessProject,
|
|
37
|
+
ProcessQuestionRequest,
|
|
38
|
+
ProcessSelectedTurnModelSource,
|
|
39
|
+
ProcessTurnRecord,
|
|
40
|
+
ProcessTurnRecordPathType,
|
|
41
|
+
ProcessTurnRecordStatus,
|
|
42
|
+
ProcessTurnType,
|
|
43
|
+
QuestionAnswerDraft,
|
|
44
|
+
ResolvedTurnStart,
|
|
45
|
+
TransitionTrigger,
|
|
46
|
+
TurnFailedPayload,
|
|
47
|
+
TurnFailureCode,
|
|
48
|
+
TurnId,
|
|
49
|
+
TurnOutcomePayload,
|
|
50
|
+
TurnStartContinuation,
|
|
51
|
+
TurnStartKind,
|
|
52
|
+
TurnStartPreparationFailureCode,
|
|
53
|
+
TurnStartRecord,
|
|
54
|
+
TurnStartRecordState,
|
|
55
|
+
WorkerBootstrapReceipt,
|
|
56
|
+
WorkerErrorClass,
|
|
57
|
+
WorkerLease,
|
|
58
|
+
WorkerState,
|
|
59
|
+
} from "./domain-model.js";
|
|
60
|
+
export {
|
|
61
|
+
ADMIN_ACTOR,
|
|
62
|
+
canonicalizeQuestionAnswers,
|
|
63
|
+
emptyQuestionDrafts,
|
|
64
|
+
formatPathTypeLabel,
|
|
65
|
+
isProcessSelectedTurnModelSource,
|
|
66
|
+
isProcessTurnType,
|
|
67
|
+
isTurnFailureCode,
|
|
68
|
+
isWaitingTurnType,
|
|
69
|
+
isWorkerErrorClass,
|
|
70
|
+
isWorkerOwnedTurnType,
|
|
71
|
+
lifecycleStatusForSelectedTurnType,
|
|
72
|
+
normalizeAskQuestionsInput,
|
|
73
|
+
PROCESS_SELECTED_TURN_MODEL_SOURCES,
|
|
74
|
+
PROCESS_TURN_RECORD_PATH_TYPES,
|
|
75
|
+
PROCESS_TURN_TYPES,
|
|
76
|
+
SYSTEM_ACTOR,
|
|
77
|
+
TELEGRAM_ACTOR,
|
|
78
|
+
WORKER_ERROR_CLASSES,
|
|
79
|
+
} from "./domain-model.js";
|
|
80
|
+
export {
|
|
81
|
+
addLauncherRecentValue,
|
|
82
|
+
DEFAULT_LAUNCHER_RECENT_VALUE_LIMIT,
|
|
83
|
+
normalizeLauncherRecentValue,
|
|
84
|
+
normalizeLauncherRecentValues,
|
|
85
|
+
redactCredentialBearingAbsoluteUrl,
|
|
86
|
+
} from "./launcher-recent-values.js";
|
|
87
|
+
export {
|
|
88
|
+
normalizeMarkdownLineEndings,
|
|
89
|
+
normalizeMarkdownText,
|
|
90
|
+
normalizeOptionalMarkdown,
|
|
91
|
+
} from "./markdown-normalize.js";
|
|
92
|
+
export type {
|
|
93
|
+
ProcessFlowEdge,
|
|
94
|
+
ProcessFlowEdgeKind,
|
|
95
|
+
ProcessFlowEndState,
|
|
96
|
+
ProcessFlowNode,
|
|
97
|
+
ProcessFlowNodeRole,
|
|
98
|
+
ProcessFlowView,
|
|
99
|
+
ProcessTurnTerminalLifecycleStatus,
|
|
100
|
+
ProcessTurnTransition,
|
|
101
|
+
SerializedProcessGraph,
|
|
102
|
+
} from "./process-definitions.js";
|
|
103
|
+
export {
|
|
104
|
+
type InstanceTurnConfigInput,
|
|
105
|
+
type InstanceTurnConfigMap,
|
|
106
|
+
type InstanceTurnConfigsJsonError,
|
|
107
|
+
type LaunchModelConfigInput,
|
|
108
|
+
normalizeLaunchModelConfigInput,
|
|
109
|
+
parseStrictInstanceTurnConfigsJson,
|
|
110
|
+
serializeInstanceTurnConfigs,
|
|
111
|
+
} from "./process-model-config.js";
|
|
112
|
+
export {
|
|
113
|
+
buildProcessRowSlot,
|
|
114
|
+
getProcessStatusCategory,
|
|
115
|
+
type ProcessRowSlot,
|
|
116
|
+
sortProcessRows,
|
|
117
|
+
} from "./process-row-slots.js";
|
|
118
|
+
export {
|
|
119
|
+
type ProcessStateJsonParseContext,
|
|
120
|
+
parseProcessStateJsonLenient,
|
|
121
|
+
parseProcessStateJsonStrict,
|
|
122
|
+
parseProductRefsFromStateJsonLenient,
|
|
123
|
+
parseProductRefsFromStateJsonStrict,
|
|
124
|
+
parseProductRefsLenient,
|
|
125
|
+
parseProductRefsStrict,
|
|
126
|
+
parseSemanticEntryRefsFromStateJsonLenient,
|
|
127
|
+
parseSemanticEntryRefsFromStateJsonStrict,
|
|
128
|
+
parseSemanticEntryRefsLenient,
|
|
129
|
+
parseSemanticEntryRefsStrict,
|
|
130
|
+
} from "./process-state-json.js";
|
|
131
|
+
export {
|
|
132
|
+
assertRepoLocator,
|
|
133
|
+
detectRepoLocatorKind,
|
|
134
|
+
isRepoLocator,
|
|
135
|
+
type ParsedRepoLocator,
|
|
136
|
+
parseRepoLocator,
|
|
137
|
+
type RepoLocatorKind,
|
|
138
|
+
} from "./repo-locator.js";
|
|
139
|
+
export {
|
|
140
|
+
createReviewSubject,
|
|
141
|
+
isReviewSubjectKind,
|
|
142
|
+
parseReviewSubject,
|
|
143
|
+
REVIEW_SUBJECT_KINDS,
|
|
144
|
+
type ReviewSubject,
|
|
145
|
+
type ReviewSubjectKind,
|
|
146
|
+
} from "./review-subject.js";
|
|
147
|
+
export {
|
|
148
|
+
assertValidProcessProductName,
|
|
149
|
+
createEmptyProcessProductRefs,
|
|
150
|
+
createEmptyProcessSemanticEntryRefs,
|
|
151
|
+
isProcessSemanticEntryRefKey,
|
|
152
|
+
isValidProcessProductName,
|
|
153
|
+
PROCESS_SEMANTIC_ENTRY_REF_KEYS,
|
|
154
|
+
type ProcessProductRef,
|
|
155
|
+
type ProcessProductRefs,
|
|
156
|
+
type ProcessSemanticEntryRefKey,
|
|
157
|
+
type ProcessSemanticEntryRefs,
|
|
158
|
+
parseProcessProductRefs,
|
|
159
|
+
parseProcessSemanticEntryRefs,
|
|
160
|
+
parseSemanticEntryRef,
|
|
161
|
+
type SemanticEntryRef,
|
|
162
|
+
} from "./semantic-entry-refs.js";
|
|
163
|
+
export {
|
|
164
|
+
humanizeProcessLabel,
|
|
165
|
+
normalizeStringArray,
|
|
166
|
+
trimString,
|
|
167
|
+
trimToNull,
|
|
168
|
+
} from "./string-normalize.js";
|
|
169
|
+
export { TURN_ACCEPTANCE_STATES, type TurnAcceptanceState } from "./turn-acceptance.js";
|
|
170
|
+
export {
|
|
171
|
+
type EntryTurnAnnotationReference,
|
|
172
|
+
type ProcessTurnAnnotation,
|
|
173
|
+
parseTurnAnnotationReference,
|
|
174
|
+
parseTurnAnnotationReferences,
|
|
175
|
+
type SemanticEntryRefTurnAnnotationReference,
|
|
176
|
+
TURN_ANNOTATION_REFERENCE_KINDS,
|
|
177
|
+
type TurnAnnotationReference,
|
|
178
|
+
type TurnAnnotationReferenceKind,
|
|
179
|
+
type TurnAnnotationReferenceRole,
|
|
180
|
+
type TurnRecordAnnotationReference,
|
|
181
|
+
} from "./turn-annotations.js";
|
|
182
|
+
export {
|
|
183
|
+
buildFailedTurnRecoveryMetadata,
|
|
184
|
+
CONTINUE_PROMPT_METADATA_KEY,
|
|
185
|
+
createGenericFailedTurnRecoveryContext,
|
|
186
|
+
DEFAULT_CONTINUE_PROMPT,
|
|
187
|
+
FAILED_TURN_RECOVERY_CODES,
|
|
188
|
+
FAILED_TURN_RECOVERY_METADATA_KEY,
|
|
189
|
+
type FailedTurnRecoveryCode,
|
|
190
|
+
type FailedTurnRecoveryContext,
|
|
191
|
+
isFailedTurnRecoveryCode,
|
|
192
|
+
normalizeContinuePrompt,
|
|
193
|
+
readFailedTurnRecoveryContext,
|
|
194
|
+
} from "./turn-recovery.js";
|
|
195
|
+
export {
|
|
196
|
+
defaultProcessTurnStartSelection,
|
|
197
|
+
type ProcessTurnStartFallback,
|
|
198
|
+
type ProcessTurnStartFromCurrentLeaf,
|
|
199
|
+
type ProcessTurnStartFromEntry,
|
|
200
|
+
type ProcessTurnStartFromProductRef,
|
|
201
|
+
type ProcessTurnStartFromSemanticRef,
|
|
202
|
+
type ProcessTurnStartFromSessionRoot,
|
|
203
|
+
type ProcessTurnStartResolution,
|
|
204
|
+
type ProcessTurnStartSelection,
|
|
205
|
+
type ProcessTurnStartTarget,
|
|
206
|
+
resolveExistingProcessEntryId,
|
|
207
|
+
resolveProcessProductRefEntryId,
|
|
208
|
+
resolveProcessSemanticRefEntryId,
|
|
209
|
+
resolveProcessTurnStartSelection,
|
|
210
|
+
resolveProcessTurnStartTarget,
|
|
211
|
+
} from "./turn-start-resolution.js";
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export const DEFAULT_LAUNCHER_RECENT_VALUE_LIMIT = 5;
|
|
2
|
+
|
|
3
|
+
function hasCredentialBearingAbsoluteUrl(value: string): boolean {
|
|
4
|
+
if (!/^[a-z][a-z0-9+.-]*:\/\//i.test(value)) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
try {
|
|
8
|
+
const url = new URL(value);
|
|
9
|
+
return url.protocol !== "file:" && (url.username !== "" || url.password !== "");
|
|
10
|
+
} catch {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Strip any embedded credentials (`user:pass@`) from an absolute non-`file:` URL,
|
|
17
|
+
* returning the value unchanged when it is not such a URL.
|
|
18
|
+
*/
|
|
19
|
+
export function redactCredentialBearingAbsoluteUrl(value: string): string {
|
|
20
|
+
if (!hasCredentialBearingAbsoluteUrl(value)) {
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
const url = new URL(value);
|
|
24
|
+
url.username = "";
|
|
25
|
+
url.password = "";
|
|
26
|
+
return url.toString();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function normalizeLauncherRecentValue(value: unknown): string | null {
|
|
30
|
+
const normalizedValue = typeof value === "string" ? value.trim() : "";
|
|
31
|
+
if (!normalizedValue) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
if (hasCredentialBearingAbsoluteUrl(normalizedValue)) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
return normalizedValue;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function normalizeLauncherRecentValues(
|
|
41
|
+
values: readonly unknown[],
|
|
42
|
+
limit = DEFAULT_LAUNCHER_RECENT_VALUE_LIMIT,
|
|
43
|
+
): string[] {
|
|
44
|
+
const nextValues: string[] = [];
|
|
45
|
+
const seen = new Set<string>();
|
|
46
|
+
for (const value of values) {
|
|
47
|
+
const normalizedValue = normalizeLauncherRecentValue(value);
|
|
48
|
+
if (!normalizedValue || seen.has(normalizedValue)) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
seen.add(normalizedValue);
|
|
52
|
+
nextValues.push(normalizedValue);
|
|
53
|
+
if (nextValues.length >= limit) {
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return nextValues;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function addLauncherRecentValue(
|
|
61
|
+
existingValues: readonly string[],
|
|
62
|
+
value: string,
|
|
63
|
+
limit = DEFAULT_LAUNCHER_RECENT_VALUE_LIMIT,
|
|
64
|
+
): string[] {
|
|
65
|
+
const normalizedValue = normalizeLauncherRecentValue(value);
|
|
66
|
+
if (!normalizedValue) {
|
|
67
|
+
return normalizeLauncherRecentValues(existingValues, limit);
|
|
68
|
+
}
|
|
69
|
+
return normalizeLauncherRecentValues([normalizedValue, ...existingValues], limit);
|
|
70
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function normalizeMarkdownLineEndings(markdown: string): string {
|
|
2
|
+
return markdown.replace(/\r\n?/g, "\n");
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function normalizeMarkdownText(markdown: string): string {
|
|
6
|
+
return normalizeMarkdownLineEndings(markdown).trim();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function normalizeOptionalMarkdown(value: unknown): string | null {
|
|
10
|
+
if (typeof value !== "string") {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
const normalized = normalizeMarkdownText(value);
|
|
14
|
+
return normalized === "" ? null : normalized;
|
|
15
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { ProcessLifecycleStatus, ProcessTurnType, TurnId } from "./domain-model.js";
|
|
2
|
+
|
|
3
|
+
export type ProcessTurnTerminalLifecycleStatus = Extract<
|
|
4
|
+
ProcessLifecycleStatus,
|
|
5
|
+
"completed" | "aborted"
|
|
6
|
+
>;
|
|
7
|
+
|
|
8
|
+
export interface ProcessTurnTransition {
|
|
9
|
+
nextTurnId?: TurnId;
|
|
10
|
+
lifecycleStatus?: ProcessTurnTerminalLifecycleStatus;
|
|
11
|
+
outcome?: string;
|
|
12
|
+
trigger?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Wire DTO used by HTTP clients that need serialized process graph data. */
|
|
16
|
+
export interface SerializedProcessGraph {
|
|
17
|
+
id: string;
|
|
18
|
+
entryTurnIds: TurnId[];
|
|
19
|
+
reachableTurnIds: TurnId[];
|
|
20
|
+
turnTransitions: Record<TurnId, ProcessTurnTransition[]>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Whether a flow node sits on the declared happy path (`spine`) or hangs off it (`branch`). */
|
|
24
|
+
export type ProcessFlowNodeRole = "spine" | "branch";
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Classification of a flow edge relative to the spine:
|
|
28
|
+
* - `forward`: progresses along the spine toward completion
|
|
29
|
+
* - `loopback`: returns to an earlier or equal spine position (revision/dismiss loops)
|
|
30
|
+
* - `branch`: leaves the spine toward an offshoot node
|
|
31
|
+
* - `terminal`: ends the process with a lifecycle status
|
|
32
|
+
*/
|
|
33
|
+
export type ProcessFlowEdgeKind = "forward" | "loopback" | "branch" | "terminal";
|
|
34
|
+
|
|
35
|
+
export interface ProcessFlowNode {
|
|
36
|
+
turnId: TurnId;
|
|
37
|
+
description: string;
|
|
38
|
+
turnType: ProcessTurnType;
|
|
39
|
+
role: ProcessFlowNodeRole;
|
|
40
|
+
/** Position on the spine when `role === "spine"`, otherwise `null`. */
|
|
41
|
+
spineIndex: number | null;
|
|
42
|
+
/** The spine node this branch hangs off, when derivable. `null` for spine nodes. */
|
|
43
|
+
anchorTurnId: TurnId | null;
|
|
44
|
+
/** True when this turn is a launch entry point. */
|
|
45
|
+
isEntry: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface ProcessFlowEdge {
|
|
49
|
+
from: TurnId;
|
|
50
|
+
/** Target turn for non-terminal edges. */
|
|
51
|
+
to: TurnId | null;
|
|
52
|
+
/** Lifecycle status for `terminal` edges. */
|
|
53
|
+
lifecycleStatus: ProcessTurnTerminalLifecycleStatus | null;
|
|
54
|
+
kind: ProcessFlowEdgeKind;
|
|
55
|
+
/** Optional human-facing edge label derived from outcome/trigger metadata. */
|
|
56
|
+
label: string | null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface ProcessFlowEndState {
|
|
60
|
+
lifecycleStatus: ProcessTurnTerminalLifecycleStatus;
|
|
61
|
+
/**
|
|
62
|
+
* True when the end state is not reached by an explicit graph transition.
|
|
63
|
+
* Abort is always reachable from any active turn, so it is synthesized.
|
|
64
|
+
*/
|
|
65
|
+
synthetic: boolean;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Spine-first projection of a process graph for operator-facing flow diagrams.
|
|
70
|
+
* The `spine` is the happy path; everything else hangs off it as branches and loops.
|
|
71
|
+
*/
|
|
72
|
+
export interface ProcessFlowView {
|
|
73
|
+
processId: string;
|
|
74
|
+
entryTurnIds: TurnId[];
|
|
75
|
+
spine: TurnId[];
|
|
76
|
+
nodes: ProcessFlowNode[];
|
|
77
|
+
edges: ProcessFlowEdge[];
|
|
78
|
+
endStates: ProcessFlowEndState[];
|
|
79
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
import { trimToNull } from "./string-normalize.js";
|
|
3
|
+
|
|
4
|
+
export interface InstanceTurnConfigInput {
|
|
5
|
+
modelProfileId?: string | null;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type InstanceTurnConfigMap = Record<string, InstanceTurnConfigInput>;
|
|
9
|
+
|
|
10
|
+
export interface LaunchModelConfigInput {
|
|
11
|
+
defaultModelProfileId?: string | null;
|
|
12
|
+
turnConfigs?: InstanceTurnConfigMap;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface InstanceTurnConfigsJsonError {
|
|
16
|
+
code: "invalid_turn_configs_json";
|
|
17
|
+
processId: string;
|
|
18
|
+
reason: "invalid_json" | "not_object" | "turn_config_not_object";
|
|
19
|
+
turnId?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const jsonObjectSchema = v.custom<Record<string, unknown>>(
|
|
23
|
+
(value): value is Record<string, unknown> =>
|
|
24
|
+
typeof value === "object" && value !== null && !Array.isArray(value),
|
|
25
|
+
"Expected object",
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const instanceTurnConfigSchema = v.pipe(
|
|
29
|
+
jsonObjectSchema,
|
|
30
|
+
v.object({
|
|
31
|
+
modelProfileId: v.optional(v.unknown()),
|
|
32
|
+
}),
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const strictInstanceTurnConfigsJsonSchema = v.pipe(
|
|
36
|
+
v.string(),
|
|
37
|
+
v.parseJson(),
|
|
38
|
+
jsonObjectSchema,
|
|
39
|
+
v.record(v.string(), instanceTurnConfigSchema),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
function normalizeInstanceTurnConfigs(
|
|
43
|
+
turnConfigs: Record<string, { modelProfileId?: unknown }>,
|
|
44
|
+
): InstanceTurnConfigMap {
|
|
45
|
+
const next: InstanceTurnConfigMap = {};
|
|
46
|
+
for (const [turnId, turnConfig] of Object.entries(turnConfigs)) {
|
|
47
|
+
const modelProfileId = trimToNull(turnConfig.modelProfileId);
|
|
48
|
+
next[turnId] = modelProfileId ? { modelProfileId } : {};
|
|
49
|
+
}
|
|
50
|
+
return next;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function getFirstIssuePathKey(issue: v.BaseIssue<unknown>): string | undefined {
|
|
54
|
+
const pathItem = issue.path?.[0] as { key?: unknown } | undefined;
|
|
55
|
+
return typeof pathItem?.key === "string" ? pathItem.key : undefined;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function parseStrictInstanceTurnConfigsJson(
|
|
59
|
+
processId: string,
|
|
60
|
+
turnConfigsJson: string | null | undefined,
|
|
61
|
+
): { ok: true; value: InstanceTurnConfigMap } | { ok: false; error: InstanceTurnConfigsJsonError } {
|
|
62
|
+
if (!turnConfigsJson) return { ok: true, value: {} };
|
|
63
|
+
const result = v.safeParse(strictInstanceTurnConfigsJsonSchema, turnConfigsJson, {
|
|
64
|
+
abortEarly: true,
|
|
65
|
+
});
|
|
66
|
+
if (!result.success) {
|
|
67
|
+
const issue = result.issues[0];
|
|
68
|
+
if (issue?.type === "parse_json") {
|
|
69
|
+
return {
|
|
70
|
+
ok: false,
|
|
71
|
+
error: { code: "invalid_turn_configs_json", processId, reason: "invalid_json" },
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const turnId = issue ? getFirstIssuePathKey(issue) : undefined;
|
|
75
|
+
return {
|
|
76
|
+
ok: false,
|
|
77
|
+
error: {
|
|
78
|
+
code: "invalid_turn_configs_json",
|
|
79
|
+
processId,
|
|
80
|
+
reason: turnId !== undefined ? "turn_config_not_object" : "not_object",
|
|
81
|
+
...(turnId !== undefined ? { turnId } : {}),
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return { ok: true, value: normalizeInstanceTurnConfigs(result.output) };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function serializeInstanceTurnConfigs(turnConfigs: InstanceTurnConfigMap): string | null {
|
|
89
|
+
const normalizedEntries = Object.entries(turnConfigs)
|
|
90
|
+
.map(([turnId, turnConfig]) => {
|
|
91
|
+
const modelProfileId = trimToNull(turnConfig.modelProfileId);
|
|
92
|
+
return [turnId, modelProfileId ? { modelProfileId } : {}] as const;
|
|
93
|
+
})
|
|
94
|
+
.filter(([, turnConfig]) => Object.keys(turnConfig).length > 0);
|
|
95
|
+
return normalizedEntries.length === 0
|
|
96
|
+
? null
|
|
97
|
+
: JSON.stringify(Object.fromEntries(normalizedEntries));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function normalizeLaunchModelConfigInput(
|
|
101
|
+
input: LaunchModelConfigInput,
|
|
102
|
+
): LaunchModelConfigInput {
|
|
103
|
+
const defaultModelProfileId = trimToNull(input.defaultModelProfileId);
|
|
104
|
+
const nextTurnConfigs: InstanceTurnConfigMap = {};
|
|
105
|
+
for (const [turnId, turnConfig] of Object.entries(input.turnConfigs ?? {})) {
|
|
106
|
+
const modelProfileId = trimToNull(turnConfig.modelProfileId);
|
|
107
|
+
if (modelProfileId) nextTurnConfigs[turnId] = { modelProfileId };
|
|
108
|
+
}
|
|
109
|
+
return { defaultModelProfileId, turnConfigs: nextTurnConfigs };
|
|
110
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { ProcessInstance, ProcessLifecycleStatus, ProcessProject } from "./domain-model.js";
|
|
2
|
+
|
|
3
|
+
export interface ProcessRowSlot {
|
|
4
|
+
instanceId: string;
|
|
5
|
+
processId: string;
|
|
6
|
+
title: string;
|
|
7
|
+
subtitle: string;
|
|
8
|
+
selectedTurnId: string | null;
|
|
9
|
+
lifecycleStatus: ProcessLifecycleStatus;
|
|
10
|
+
statusCategory: "error" | "active" | "waiting" | "terminal" | "discovered";
|
|
11
|
+
projectCount: number;
|
|
12
|
+
externalId: string | null;
|
|
13
|
+
externalLinkCount: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function getProcessStatusCategory(
|
|
17
|
+
lifecycleStatus: ProcessLifecycleStatus,
|
|
18
|
+
): ProcessRowSlot["statusCategory"] {
|
|
19
|
+
if (lifecycleStatus === "error") return "error";
|
|
20
|
+
if (lifecycleStatus === "active") return "active";
|
|
21
|
+
if (lifecycleStatus === "waiting") return "waiting";
|
|
22
|
+
if (lifecycleStatus === "completed" || lifecycleStatus === "aborted") return "terminal";
|
|
23
|
+
return "discovered";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function buildProcessRowSlot(
|
|
27
|
+
process: ProcessInstance,
|
|
28
|
+
projects: ReadonlyArray<ProcessProject>,
|
|
29
|
+
): ProcessRowSlot {
|
|
30
|
+
const externalLinkCount = projects.filter((p) => p.externalId !== null).length;
|
|
31
|
+
|
|
32
|
+
const title = process.title ?? process.externalId ?? process.id;
|
|
33
|
+
const subtitle = `${process.processId} \u00b7 ${projects.length} component${projects.length !== 1 ? "s" : ""}`;
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
instanceId: process.id,
|
|
37
|
+
processId: process.processId,
|
|
38
|
+
title,
|
|
39
|
+
subtitle,
|
|
40
|
+
selectedTurnId: process.selectedTurnId,
|
|
41
|
+
lifecycleStatus: process.lifecycleStatus,
|
|
42
|
+
statusCategory: getProcessStatusCategory(process.lifecycleStatus),
|
|
43
|
+
projectCount: projects.length,
|
|
44
|
+
externalId: process.externalId,
|
|
45
|
+
externalLinkCount,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function sortProcessRows(rows: ProcessRowSlot[]): ProcessRowSlot[] {
|
|
50
|
+
const categoryOrder: Record<string, number> = {
|
|
51
|
+
error: 0,
|
|
52
|
+
active: 1,
|
|
53
|
+
waiting: 2,
|
|
54
|
+
discovered: 3,
|
|
55
|
+
terminal: 4,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
return [...rows].sort((a, b) => {
|
|
59
|
+
const catA = categoryOrder[a.statusCategory] ?? 4;
|
|
60
|
+
const catB = categoryOrder[b.statusCategory] ?? 4;
|
|
61
|
+
if (catA !== catB) return catA - catB;
|
|
62
|
+
return a.title.localeCompare(b.title);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createEmptyProcessProductRefs,
|
|
3
|
+
createEmptyProcessSemanticEntryRefs,
|
|
4
|
+
isValidProcessProductName,
|
|
5
|
+
type ProcessProductRefs,
|
|
6
|
+
type ProcessSemanticEntryRefs,
|
|
7
|
+
parseProcessSemanticEntryRefs,
|
|
8
|
+
parseSemanticEntryRef,
|
|
9
|
+
} from "./semantic-entry-refs.js";
|
|
10
|
+
|
|
11
|
+
export interface ProcessStateJsonParseContext {
|
|
12
|
+
label?: string;
|
|
13
|
+
processId?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function formatMalformedSubject(
|
|
17
|
+
defaultLabel: string,
|
|
18
|
+
context: string | ProcessStateJsonParseContext | undefined,
|
|
19
|
+
): string {
|
|
20
|
+
if (typeof context === "string") {
|
|
21
|
+
return context;
|
|
22
|
+
}
|
|
23
|
+
const label = context?.label ?? defaultLabel;
|
|
24
|
+
return context?.processId ? `${label} for process '${context.processId}'` : label;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function parseProcessStateJsonStrict(
|
|
28
|
+
stateJson: string | null | undefined,
|
|
29
|
+
context?: string | ProcessStateJsonParseContext,
|
|
30
|
+
): Record<string, unknown> {
|
|
31
|
+
if (!stateJson) {
|
|
32
|
+
return {};
|
|
33
|
+
}
|
|
34
|
+
const subject = formatMalformedSubject("stateJson", context);
|
|
35
|
+
let parsed: unknown;
|
|
36
|
+
try {
|
|
37
|
+
parsed = JSON.parse(stateJson);
|
|
38
|
+
} catch (error) {
|
|
39
|
+
throw new Error(
|
|
40
|
+
`Malformed ${subject}: ${error instanceof Error ? error.message : String(error)}`,
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
44
|
+
throw new Error(`Malformed ${subject}: expected a JSON object`);
|
|
45
|
+
}
|
|
46
|
+
return parsed as Record<string, unknown>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function parseProcessStateJsonLenient(
|
|
50
|
+
stateJson: string | null | undefined,
|
|
51
|
+
): Record<string, unknown> {
|
|
52
|
+
try {
|
|
53
|
+
return parseProcessStateJsonStrict(stateJson);
|
|
54
|
+
} catch {
|
|
55
|
+
return {};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function parseSemanticEntryRefsStrict(
|
|
60
|
+
value: unknown,
|
|
61
|
+
context?: ProcessStateJsonParseContext,
|
|
62
|
+
): ProcessSemanticEntryRefs {
|
|
63
|
+
if (value === undefined) {
|
|
64
|
+
return createEmptyProcessSemanticEntryRefs();
|
|
65
|
+
}
|
|
66
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
67
|
+
throw new Error(
|
|
68
|
+
`Malformed ${formatMalformedSubject("semanticEntryRefs", {
|
|
69
|
+
label: "semanticEntryRefs",
|
|
70
|
+
processId: context?.processId,
|
|
71
|
+
})}: expected an object when present`,
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
return parseProcessSemanticEntryRefs(value);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function parseSemanticEntryRefsLenient(value: unknown): ProcessSemanticEntryRefs {
|
|
78
|
+
try {
|
|
79
|
+
return parseSemanticEntryRefsStrict(value);
|
|
80
|
+
} catch {
|
|
81
|
+
return createEmptyProcessSemanticEntryRefs();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function parseProductRefsStrict(
|
|
86
|
+
value: unknown,
|
|
87
|
+
context?: ProcessStateJsonParseContext,
|
|
88
|
+
): ProcessProductRefs {
|
|
89
|
+
if (value === undefined) {
|
|
90
|
+
return createEmptyProcessProductRefs();
|
|
91
|
+
}
|
|
92
|
+
const subject = formatMalformedSubject("productRefs", {
|
|
93
|
+
label: "productRefs",
|
|
94
|
+
processId: context?.processId,
|
|
95
|
+
});
|
|
96
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
97
|
+
throw new Error(`Malformed ${subject}: expected an object when present`);
|
|
98
|
+
}
|
|
99
|
+
const refs: ProcessProductRefs = {};
|
|
100
|
+
for (const [name, rawRef] of Object.entries(value as Record<string, unknown>)) {
|
|
101
|
+
if (!isValidProcessProductName(name)) {
|
|
102
|
+
throw new Error(`Malformed ${subject}: invalid product name '${name}'`);
|
|
103
|
+
}
|
|
104
|
+
const ref = parseSemanticEntryRef(rawRef);
|
|
105
|
+
if (!ref) {
|
|
106
|
+
throw new Error(`Malformed ${subject}: product '${name}' must reference an entry`);
|
|
107
|
+
}
|
|
108
|
+
refs[name] = ref;
|
|
109
|
+
}
|
|
110
|
+
return refs;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function parseProductRefsLenient(value: unknown): ProcessProductRefs {
|
|
114
|
+
try {
|
|
115
|
+
return parseProductRefsStrict(value);
|
|
116
|
+
} catch {
|
|
117
|
+
return createEmptyProcessProductRefs();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function parseSemanticEntryRefsFromStateJsonStrict(
|
|
122
|
+
stateJson: string | null | undefined,
|
|
123
|
+
context?: string | ProcessStateJsonParseContext,
|
|
124
|
+
): ProcessSemanticEntryRefs {
|
|
125
|
+
const stateRecord = parseProcessStateJsonStrict(stateJson, context);
|
|
126
|
+
return parseSemanticEntryRefsStrict(
|
|
127
|
+
stateRecord.semanticEntryRefs,
|
|
128
|
+
typeof context === "string" ? undefined : context,
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function parseSemanticEntryRefsFromStateJsonLenient(
|
|
133
|
+
stateJson: string | null | undefined,
|
|
134
|
+
): ProcessSemanticEntryRefs {
|
|
135
|
+
const stateRecord = parseProcessStateJsonLenient(stateJson);
|
|
136
|
+
return parseSemanticEntryRefsLenient(stateRecord.semanticEntryRefs);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function parseProductRefsFromStateJsonStrict(
|
|
140
|
+
stateJson: string | null | undefined,
|
|
141
|
+
context?: string | ProcessStateJsonParseContext,
|
|
142
|
+
): ProcessProductRefs {
|
|
143
|
+
const stateRecord = parseProcessStateJsonStrict(stateJson, context);
|
|
144
|
+
return parseProductRefsStrict(
|
|
145
|
+
stateRecord.productRefs,
|
|
146
|
+
typeof context === "string" ? undefined : context,
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function parseProductRefsFromStateJsonLenient(
|
|
151
|
+
stateJson: string | null | undefined,
|
|
152
|
+
): ProcessProductRefs {
|
|
153
|
+
const stateRecord = parseProcessStateJsonLenient(stateJson);
|
|
154
|
+
return parseProductRefsLenient(stateRecord.productRefs);
|
|
155
|
+
}
|