@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
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { normalizeStringArray, trimToNull } from "./string-normalize.js";
|
|
2
|
+
export const DEFAULT_CONTINUE_PROMPT = "continue";
|
|
3
|
+
export const FAILED_TURN_RECOVERY_CODES = [
|
|
4
|
+
"generic_continue",
|
|
5
|
+
"missing_outcome_tool",
|
|
6
|
+
"missing_markdown_result",
|
|
7
|
+
"missing_required_tool_calls",
|
|
8
|
+
];
|
|
9
|
+
export const FAILED_TURN_RECOVERY_METADATA_KEY = "failedTurnRecovery";
|
|
10
|
+
export const CONTINUE_PROMPT_METADATA_KEY = "continuePrompt";
|
|
11
|
+
export function isFailedTurnRecoveryCode(value) {
|
|
12
|
+
return FAILED_TURN_RECOVERY_CODES.includes(value);
|
|
13
|
+
}
|
|
14
|
+
function normalizeUniqueStringArray(value) {
|
|
15
|
+
const normalized = normalizeStringArray(value);
|
|
16
|
+
return normalized.length > 0 ? [...new Set(normalized)] : undefined;
|
|
17
|
+
}
|
|
18
|
+
function isRecord(value) {
|
|
19
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
20
|
+
}
|
|
21
|
+
export function normalizeContinuePrompt(value) {
|
|
22
|
+
return trimToNull(value);
|
|
23
|
+
}
|
|
24
|
+
export function createGenericFailedTurnRecoveryContext(overrides = {}) {
|
|
25
|
+
return {
|
|
26
|
+
strategy: "continue",
|
|
27
|
+
suggestedContinuePrompt: DEFAULT_CONTINUE_PROMPT,
|
|
28
|
+
failureCode: "generic_continue",
|
|
29
|
+
...overrides,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export function buildFailedTurnRecoveryMetadata(turnRecordId, context = {}) {
|
|
33
|
+
return {
|
|
34
|
+
[FAILED_TURN_RECOVERY_METADATA_KEY]: {
|
|
35
|
+
turnRecordId,
|
|
36
|
+
...createGenericFailedTurnRecoveryContext(context),
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export function readFailedTurnRecoveryContext(metadata, expectedTurnRecordId) {
|
|
41
|
+
if (!metadata) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
const raw = metadata[FAILED_TURN_RECOVERY_METADATA_KEY];
|
|
45
|
+
if (!isRecord(raw)) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
if (expectedTurnRecordId) {
|
|
49
|
+
const turnRecordId = trimToNull(raw.turnRecordId);
|
|
50
|
+
if (turnRecordId !== expectedTurnRecordId) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (raw.strategy !== "continue") {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
const suggestedContinuePrompt = normalizeContinuePrompt(raw.suggestedContinuePrompt);
|
|
58
|
+
const failureCode = trimToNull(raw.failureCode);
|
|
59
|
+
if (!suggestedContinuePrompt || !failureCode || !isFailedTurnRecoveryCode(failureCode)) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
const missingToolNames = normalizeUniqueStringArray(raw.missingToolNames);
|
|
63
|
+
return {
|
|
64
|
+
strategy: "continue",
|
|
65
|
+
suggestedContinuePrompt,
|
|
66
|
+
failureCode,
|
|
67
|
+
...(missingToolNames ? { missingToolNames } : {}),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=turn-recovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"turn-recovery.js","sourceRoot":"","sources":["../src/turn-recovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEzE,MAAM,CAAC,MAAM,uBAAuB,GAAG,UAAU,CAAC;AAElD,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACzC,kBAAkB;IAClB,sBAAsB;IACtB,yBAAyB;IACzB,6BAA6B;CACpB,CAAC;AAaX,MAAM,CAAC,MAAM,iCAAiC,GAAG,oBAAoB,CAAC;AACtE,MAAM,CAAC,MAAM,4BAA4B,GAAG,gBAAgB,CAAC;AAE7D,MAAM,UAAU,wBAAwB,CAAC,KAAa;IACrD,OAAQ,0BAAgD,CAAC,QAAQ,CAAC,KAA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C,YAAY,CAAC,CAAC;QAClD,IAAI,YAAY,KAAK,oBAAoB,EAAE,CAAC;YAC3C,OAAO,IAAI,CAAC;QACb,CAAC;IACF,CAAC;IACD,IAAI,GAAG,CAAC,QAAQ,KAAK,UAAU,EAAE,CAAC;QACjC,OAAO,IAAI,CAAC;IACb,CAAC;IACD,MAAM,uBAAuB,GAAG,uBAAuB,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;IACrF,MAAM,WAAW,GAAG,UAAU,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAChD,IAAI,CAAC,uBAAuB,IAAI,CAAC,WAAW,IAAI,CAAC,wBAAwB,CAAC,WAAW,CAAC,EAAE,CAAC;QACxF,OAAO,IAAI,CAAC;IACb,CAAC;IACD,MAAM,gBAAgB,GAAG,0BAA0B,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAC1E,OAAO;QACN,QAAQ,EAAE,UAAU;QACpB,uBAAuB;QACvB,WAAW;QACX,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACjD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { ProcessTurnRecordPathType } from "./domain-model.js";
|
|
2
|
+
import type { ProcessProductRefs, ProcessSemanticEntryRefKey, ProcessSemanticEntryRefs } from "./semantic-entry-refs.js";
|
|
3
|
+
export interface ProcessTurnStartFromCurrentLeaf {
|
|
4
|
+
kind: "current_leaf";
|
|
5
|
+
}
|
|
6
|
+
export interface ProcessTurnStartFromSessionRoot {
|
|
7
|
+
/** Start with no persisted Pi entry in context. The kickoff entry has parentId null. */
|
|
8
|
+
kind: "session_root";
|
|
9
|
+
}
|
|
10
|
+
export interface ProcessTurnStartFromEntry {
|
|
11
|
+
kind: "entry";
|
|
12
|
+
entryId: string;
|
|
13
|
+
}
|
|
14
|
+
export type ProcessTurnStartFallback = ProcessTurnStartFromCurrentLeaf | ProcessTurnStartFromSessionRoot | ProcessTurnStartFromEntry;
|
|
15
|
+
export interface ProcessTurnStartFromSemanticRef {
|
|
16
|
+
kind: "semantic_ref";
|
|
17
|
+
ref: ProcessSemanticEntryRefKey;
|
|
18
|
+
fallback?: ProcessTurnStartSelection;
|
|
19
|
+
}
|
|
20
|
+
export interface ProcessTurnStartFromProductRef {
|
|
21
|
+
kind: "product_ref";
|
|
22
|
+
productName: string;
|
|
23
|
+
fallback?: ProcessTurnStartSelection;
|
|
24
|
+
}
|
|
25
|
+
export type ProcessTurnStartSelection = ProcessTurnStartFallback | ProcessTurnStartFromSemanticRef | ProcessTurnStartFromProductRef;
|
|
26
|
+
export type ProcessTurnStartTarget = {
|
|
27
|
+
kind: "current_leaf";
|
|
28
|
+
} | {
|
|
29
|
+
kind: "entry";
|
|
30
|
+
entryId: string;
|
|
31
|
+
} | {
|
|
32
|
+
kind: "root";
|
|
33
|
+
};
|
|
34
|
+
export interface ProcessTurnStartResolution {
|
|
35
|
+
forkPiEntryId: string | null;
|
|
36
|
+
startTarget: ProcessTurnStartTarget;
|
|
37
|
+
}
|
|
38
|
+
export declare function defaultProcessTurnStartSelection(branchType: ProcessTurnRecordPathType): ProcessTurnStartFallback;
|
|
39
|
+
export declare function resolveProcessTurnStartSelection(input: {
|
|
40
|
+
branchType: ProcessTurnRecordPathType;
|
|
41
|
+
startFrom?: ProcessTurnStartSelection;
|
|
42
|
+
}): ProcessTurnStartSelection;
|
|
43
|
+
export declare function resolveExistingProcessEntryId(entryId: string | null, entryExists?: ((entryId: string) => boolean) | undefined): string | null;
|
|
44
|
+
export declare function resolveProcessSemanticRefEntryId(input: {
|
|
45
|
+
ref: keyof ProcessSemanticEntryRefs;
|
|
46
|
+
semanticEntryRefs?: ProcessSemanticEntryRefs | null;
|
|
47
|
+
currentLeafId: string | null;
|
|
48
|
+
rootEntryId: string | null;
|
|
49
|
+
entryExists?: (entryId: string) => boolean;
|
|
50
|
+
}): string | null;
|
|
51
|
+
export declare function resolveProcessProductRefEntryId(input: {
|
|
52
|
+
productName: string;
|
|
53
|
+
productRefs?: ProcessProductRefs | null;
|
|
54
|
+
entryExists?: (entryId: string) => boolean;
|
|
55
|
+
}): string | null;
|
|
56
|
+
export declare function resolveProcessTurnStartTarget(input: {
|
|
57
|
+
branchType: ProcessTurnRecordPathType;
|
|
58
|
+
selection: ProcessTurnStartSelection;
|
|
59
|
+
currentLeafId: string | null;
|
|
60
|
+
rootEntryId: string | null;
|
|
61
|
+
semanticEntryRefs?: ProcessSemanticEntryRefs | null;
|
|
62
|
+
productRefs?: ProcessProductRefs | null;
|
|
63
|
+
entryExists?: (entryId: string) => boolean;
|
|
64
|
+
}): ProcessTurnStartResolution;
|
|
65
|
+
//# sourceMappingURL=turn-start-resolution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"turn-start-resolution.d.ts","sourceRoot":"","sources":["../src/turn-start-resolution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,KAAK,EACX,kBAAkB,EAClB,0BAA0B,EAC1B,wBAAwB,EACxB,MAAM,0BAA0B,CAAC;AAElC,MAAM,WAAW,+BAA+B;IAC/C,IAAI,EAAE,cAAc,CAAC;CACrB;AAED,MAAM,WAAW,+BAA+B;IAC/C,wFAAwF;IACxF,IAAI,EAAE,cAAc,CAAC;CACrB;AAED,MAAM,WAAW,yBAAyB;IACzC,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,wBAAwB,GACjC,+BAA+B,GAC/B,+BAA+B,GAC/B,yBAAyB,CAAC;AAE7B,MAAM,WAAW,+BAA+B;IAC/C,IAAI,EAAE,cAAc,CAAC;IACrB,GAAG,EAAE,0BAA0B,CAAC;IAChC,QAAQ,CAAC,EAAE,yBAAyB,CAAC;CACrC;AAED,MAAM,WAAW,8BAA8B;IAC9C,IAAI,E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MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACxC,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC;CAC3C,GAAG,MAAM,GAAG,IAAI,CAShB;AAED,wBAAgB,6BAA6B,CAAC,KAAK,EAAE;IACpD,UAAU,EAAE,yBAAyB,CAAC;IACtC,SAAS,EAAE,yBAAyB,CAAC;IACrC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,iBAAiB,CAAC,EAAE,wBAAwB,GAAG,IAAI,CAAC;IACpD,WAAW,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACxC,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC;CAC3C,GAAG,0BAA0B,CA2D7B"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export function defaultProcessTurnStartSelection(branchType) {
|
|
2
|
+
switch (branchType) {
|
|
3
|
+
case "primary":
|
|
4
|
+
case "leaf_branch":
|
|
5
|
+
return { kind: "current_leaf" };
|
|
6
|
+
case "root_branch":
|
|
7
|
+
return { kind: "session_root" };
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export function resolveProcessTurnStartSelection(input) {
|
|
11
|
+
return input.startFrom ?? defaultProcessTurnStartSelection(input.branchType);
|
|
12
|
+
}
|
|
13
|
+
export function resolveExistingProcessEntryId(entryId, entryExists) {
|
|
14
|
+
if (!entryId) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
return entryExists && !entryExists(entryId) ? null : entryId;
|
|
18
|
+
}
|
|
19
|
+
export function resolveProcessSemanticRefEntryId(input) {
|
|
20
|
+
const fromState = resolveExistingProcessEntryId(input.semanticEntryRefs?.[input.ref]?.entryId ?? null, input.entryExists);
|
|
21
|
+
if (fromState) {
|
|
22
|
+
return fromState;
|
|
23
|
+
}
|
|
24
|
+
if (input.ref === "currentPrimaryPathLeaf") {
|
|
25
|
+
return resolveExistingProcessEntryId(input.currentLeafId, input.entryExists);
|
|
26
|
+
}
|
|
27
|
+
if (input.ref === "rootEntry") {
|
|
28
|
+
return resolveExistingProcessEntryId(input.rootEntryId, input.entryExists);
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
export function resolveProcessProductRefEntryId(input) {
|
|
33
|
+
const productName = input.productName.trim();
|
|
34
|
+
if (!productName) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
return resolveExistingProcessEntryId(input.productRefs?.[productName]?.entryId ?? null, input.entryExists);
|
|
38
|
+
}
|
|
39
|
+
export function resolveProcessTurnStartTarget(input) {
|
|
40
|
+
switch (input.selection.kind) {
|
|
41
|
+
case "current_leaf": {
|
|
42
|
+
return {
|
|
43
|
+
forkPiEntryId: resolveExistingProcessEntryId(input.currentLeafId, input.entryExists),
|
|
44
|
+
startTarget: { kind: "current_leaf" },
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
case "session_root": {
|
|
48
|
+
return {
|
|
49
|
+
forkPiEntryId: null,
|
|
50
|
+
startTarget: { kind: "root" },
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
case "entry": {
|
|
54
|
+
return {
|
|
55
|
+
forkPiEntryId: input.selection.entryId,
|
|
56
|
+
startTarget: { kind: "entry", entryId: input.selection.entryId },
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
case "semantic_ref": {
|
|
60
|
+
const entryId = resolveProcessSemanticRefEntryId({
|
|
61
|
+
ref: input.selection.ref,
|
|
62
|
+
semanticEntryRefs: input.semanticEntryRefs,
|
|
63
|
+
currentLeafId: input.currentLeafId,
|
|
64
|
+
rootEntryId: input.rootEntryId,
|
|
65
|
+
entryExists: input.entryExists,
|
|
66
|
+
});
|
|
67
|
+
if (entryId) {
|
|
68
|
+
return {
|
|
69
|
+
forkPiEntryId: entryId,
|
|
70
|
+
startTarget: { kind: "entry", entryId },
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return resolveProcessTurnStartTarget({
|
|
74
|
+
...input,
|
|
75
|
+
selection: input.selection.fallback ?? defaultProcessTurnStartSelection(input.branchType),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
case "product_ref": {
|
|
79
|
+
const entryId = resolveProcessProductRefEntryId({
|
|
80
|
+
productName: input.selection.productName,
|
|
81
|
+
productRefs: input.productRefs,
|
|
82
|
+
entryExists: input.entryExists,
|
|
83
|
+
});
|
|
84
|
+
if (entryId) {
|
|
85
|
+
return {
|
|
86
|
+
forkPiEntryId: entryId,
|
|
87
|
+
startTarget: { kind: "entry", entryId },
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
return resolveProcessTurnStartTarget({
|
|
91
|
+
...input,
|
|
92
|
+
selection: input.selection.fallback ?? defaultProcessTurnStartSelection(input.branchType),
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=turn-start-resolution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"turn-start-resolution.js","sourceRoot":"","sources":["../src/turn-start-resolution.ts"],"names":[],"mappings":"AAqDA,MAAM,UAAU,gCAAgC,CAC/C,UAAqC;IAErC,QAAQ,UAAU,EAAE,CAAC;QACpB,KAAK,SAAS,CAAC;QACf,KAAK,aAAa;YACjB,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC;QACjC,KAAK,aAAa;YACjB,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC;IAClC,CAAC;AACF,CAAC;AAED,MAAM,UAAU,gCAAgC,CAAC,KAGhD;IACA,OAAO,KAAK,CAAC,SAAS,IAAI,gCAAgC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;AAC9E,CAAC;AAED,MAAM,UAAU,6BAA6B,CAC5C,OAAsB,EACtB,WAAwD;IAExD,I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SAAS,CAAC,WAAW;gBACxC,WAAW,EAAE,KAAK,CAAC,WAAW;gBAC9B,WAAW,EAAE,KAAK,CAAC,WAAW;aAC9B,CAAC,CAAC;YACH,IAAI,OAAO,EAAE,CAAC;gBACb,OAAO;oBACN,aAAa,EAAE,OAAO;oBACtB,WAAW,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE;iBACvC,CAAC;YACH,CAAC;YAED,OAAO,6BAA6B,CAAC;gBACpC,GAAG,KAAK;gBACR,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,QAAQ,IAAI,gCAAgC,CAAC,KAAK,CAAC,UAAU,CAAC;aACzF,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;AACF,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@leitwerk-dev/domain",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/leitwerk-dev/leitwerk.git",
|
|
7
|
+
"directory": "packages/domain"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"source": "./src/index.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsup --silent"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/node": "^22.19.17",
|
|
22
|
+
"tsup": "^8.5.1"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"valibot": "^1.3.1"
|
|
26
|
+
},
|
|
27
|
+
"license": "Apache-2.0",
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=22"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist/**",
|
|
36
|
+
"src/**",
|
|
37
|
+
"!dist/**/*.test.*",
|
|
38
|
+
"!src/**/*.test.ts"
|
|
39
|
+
]
|
|
40
|
+
}
|
package/src/actor.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { type Actor, type ActorKind, SYSTEM_ACTOR } from "./domain-model.js";
|
|
2
|
+
|
|
3
|
+
const ACTOR_KINDS: readonly ActorKind[] = ["user", "channel", "system"];
|
|
4
|
+
const ACTOR_PROVIDERS: ReadonlyArray<NonNullable<Actor["provider"]>> = [
|
|
5
|
+
"forgejo",
|
|
6
|
+
"gitlab",
|
|
7
|
+
"telegram",
|
|
8
|
+
];
|
|
9
|
+
|
|
10
|
+
function isActorKind(value: unknown): value is ActorKind {
|
|
11
|
+
return typeof value === "string" && (ACTOR_KINDS as readonly string[]).includes(value);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function normalizeProvider(value: unknown): Actor["provider"] {
|
|
15
|
+
if (typeof value !== "string") {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
return (ACTOR_PROVIDERS as readonly string[]).includes(value)
|
|
19
|
+
? (value as NonNullable<Actor["provider"]>)
|
|
20
|
+
: null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Builds a validated `Actor`, dropping unknown fields and falling back to
|
|
25
|
+
* defaults for invalid kind/provider. Returns `null` when no stable id is
|
|
26
|
+
* present so callers can decide on a fallback actor.
|
|
27
|
+
*/
|
|
28
|
+
export function normalizeActor(value: unknown): Actor | null {
|
|
29
|
+
if (typeof value !== "object" || value === null) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
const candidate = value as Record<string, unknown>;
|
|
33
|
+
const id = typeof candidate.id === "string" ? candidate.id.trim() : "";
|
|
34
|
+
if (id === "") {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
const kind = isActorKind(candidate.kind) ? candidate.kind : "system";
|
|
38
|
+
const provider = normalizeProvider(candidate.provider);
|
|
39
|
+
const displayName =
|
|
40
|
+
typeof candidate.displayName === "string" && candidate.displayName.trim() !== ""
|
|
41
|
+
? candidate.displayName
|
|
42
|
+
: undefined;
|
|
43
|
+
return {
|
|
44
|
+
id,
|
|
45
|
+
kind,
|
|
46
|
+
provider,
|
|
47
|
+
...(displayName !== undefined ? { displayName } : {}),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Serializes an `Actor` to a stable JSON string for durable storage. */
|
|
52
|
+
export function serializeActor(actor: Actor): string {
|
|
53
|
+
return JSON.stringify({
|
|
54
|
+
id: actor.id,
|
|
55
|
+
kind: actor.kind,
|
|
56
|
+
provider: actor.provider,
|
|
57
|
+
...(actor.displayName !== undefined ? { displayName: actor.displayName } : {}),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Parses a durable actor JSON value, falling back to `SYSTEM_ACTOR` when the
|
|
63
|
+
* stored value is missing or malformed. Used when reading legacy rows that
|
|
64
|
+
* predate actor attribution.
|
|
65
|
+
*/
|
|
66
|
+
export function parseActorOrSystem(value: string | null | undefined): Actor {
|
|
67
|
+
if (value === null || value === undefined || value.trim() === "") {
|
|
68
|
+
return SYSTEM_ACTOR;
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
return normalizeActor(JSON.parse(value)) ?? SYSTEM_ACTOR;
|
|
72
|
+
} catch {
|
|
73
|
+
return SYSTEM_ACTOR;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Canonical serialized form of `SYSTEM_ACTOR`, used as the durable default. */
|
|
78
|
+
export const SERIALIZED_SYSTEM_ACTOR = serializeActor(SYSTEM_ACTOR);
|