@leitwerk-dev/protocol 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.
Files changed (100) hide show
  1. package/dist/api-token-contracts.d.ts +25 -0
  2. package/dist/api-token-contracts.d.ts.map +1 -0
  3. package/dist/{chunk-SKQG5SE3.js → chunk-J4VMD5ST.js} +17 -26
  4. package/dist/chunk-J4VMD5ST.js.map +1 -0
  5. package/dist/{chunk-J7LXDQAN.js → chunk-Z4IU6KEN.js} +40 -6
  6. package/dist/chunk-Z4IU6KEN.js.map +1 -0
  7. package/dist/compact-turn-summary.d.ts +31 -0
  8. package/dist/compact-turn-summary.d.ts.map +1 -0
  9. package/dist/config-snapshot.d.ts +2 -0
  10. package/dist/config-snapshot.d.ts.map +1 -1
  11. package/dist/config-snapshot.js +1 -1
  12. package/dist/config-snapshot.js.map +1 -1
  13. package/dist/extension-ui-contracts.d.ts +27 -0
  14. package/dist/extension-ui-contracts.d.ts.map +1 -0
  15. package/dist/form-contract.js +1 -1
  16. package/dist/form-contract.js.map +1 -1
  17. package/dist/{http-contracts-DP9P_2YM.d.ts → http-contracts-ht8DDU4J.d.ts} +163 -37
  18. package/dist/http-contracts.d.ts +109 -38
  19. package/dist/http-contracts.d.ts.map +1 -1
  20. package/dist/http-contracts.js +32 -432
  21. package/dist/http-contracts.js.map +1 -1
  22. package/dist/index.d.ts +5 -0
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +1196 -20
  25. package/dist/index.js.map +1 -1
  26. package/dist/initial-prompt.d.ts.map +1 -1
  27. package/dist/launcher-contract.js +1 -1
  28. package/dist/launcher-contract.js.map +1 -1
  29. package/dist/live-turn-projection.d.ts +1 -1
  30. package/dist/live-turn-projection.d.ts.map +1 -1
  31. package/dist/protocol.d.ts +63 -16
  32. package/dist/protocol.d.ts.map +1 -1
  33. package/dist/protocol.js +37 -259
  34. package/dist/protocol.js.map +1 -1
  35. package/dist/streamable-events.d.ts +1 -1
  36. package/dist/streamable-events.d.ts.map +1 -1
  37. package/dist/ticket-creation-contracts.d.ts +33 -0
  38. package/dist/ticket-creation-contracts.d.ts.map +1 -0
  39. package/dist/timeline-projection.d.ts +1 -1
  40. package/dist/timeline-projection.d.ts.map +1 -1
  41. package/dist/tool-renderer-contract.js +10 -21
  42. package/dist/tool-renderer-contract.js.map +1 -1
  43. package/dist/tool-result-truncation.d.ts +6 -0
  44. package/dist/tool-result-truncation.d.ts.map +1 -0
  45. package/dist/turn-continuation.d.ts +1 -1
  46. package/dist/turn-continuation.d.ts.map +1 -1
  47. package/dist/turn-trace-projection.d.ts +5 -0
  48. package/dist/turn-trace-projection.d.ts.map +1 -0
  49. package/dist/usage-snapshot.d.ts +3 -1
  50. package/dist/usage-snapshot.d.ts.map +1 -1
  51. package/dist/ws-event-payloads.d.ts +2 -1
  52. package/dist/ws-event-payloads.d.ts.map +1 -1
  53. package/package.json +3 -3
  54. package/src/api-token-contracts.ts +24 -0
  55. package/src/compact-turn-summary.ts +119 -0
  56. package/src/config-snapshot.ts +2 -0
  57. package/src/extension-ui-contracts.ts +45 -0
  58. package/src/http-contracts.ts +139 -68
  59. package/src/index.ts +5 -0
  60. package/src/initial-prompt.ts +3 -6
  61. package/src/live-turn-projection.ts +41 -113
  62. package/src/protocol.ts +52 -12
  63. package/src/streamable-events.ts +2 -0
  64. package/src/ticket-creation-contracts.ts +34 -0
  65. package/src/timeline-projection.ts +5 -4
  66. package/src/tool-result-truncation.ts +94 -0
  67. package/src/turn-continuation.ts +22 -46
  68. package/src/turn-trace-projection.ts +42 -0
  69. package/src/usage-snapshot.ts +25 -59
  70. package/src/ws-event-payloads.ts +5 -14
  71. package/dist/chunk-J7LXDQAN.js.map +0 -1
  72. package/dist/chunk-SKQG5SE3.js.map +0 -1
  73. package/dist/external-review.js +0 -2
  74. package/dist/external-review.js.map +0 -1
  75. package/dist/initial-prompt.js +0 -103
  76. package/dist/initial-prompt.js.map +0 -1
  77. package/dist/live-turn-projection.js +0 -395
  78. package/dist/live-turn-projection.js.map +0 -1
  79. package/dist/pi-session-message.js +0 -27
  80. package/dist/pi-session-message.js.map +0 -1
  81. package/dist/primary-path-snapshot.js +0 -2
  82. package/dist/primary-path-snapshot.js.map +0 -1
  83. package/dist/session-entry-tree.js +0 -42
  84. package/dist/session-entry-tree.js.map +0 -1
  85. package/dist/streamable-events.js +0 -17
  86. package/dist/streamable-events.js.map +0 -1
  87. package/dist/text-preview.js +0 -23
  88. package/dist/text-preview.js.map +0 -1
  89. package/dist/timeline-projection.js +0 -33
  90. package/dist/timeline-projection.js.map +0 -1
  91. package/dist/timestamp-ordering.js +0 -15
  92. package/dist/timestamp-ordering.js.map +0 -1
  93. package/dist/turn-continuation.js +0 -179
  94. package/dist/turn-continuation.js.map +0 -1
  95. package/dist/usage-by-turn-record.js +0 -25
  96. package/dist/usage-by-turn-record.js.map +0 -1
  97. package/dist/usage-snapshot.js +0 -120
  98. package/dist/usage-snapshot.js.map +0 -1
  99. package/dist/ws-event-payloads.js +0 -47
  100. package/dist/ws-event-payloads.js.map +0 -1
@@ -0,0 +1,119 @@
1
+ import type {
2
+ PrimaryPathActiveTurnSnapshot,
3
+ PrimaryPathToolCallSnapshot,
4
+ } from "./primary-path-snapshot.js";
5
+ import {
6
+ mergeUsageSnapshots,
7
+ normalizeUsageSnapshot,
8
+ type UsageSnapshot,
9
+ } from "./usage-snapshot.js";
10
+ import {
11
+ readWsEventStreamText,
12
+ readWsEventTimestamp,
13
+ readWsEventToolCallId,
14
+ readWsEventToolName,
15
+ } from "./ws-event-payloads.js";
16
+
17
+ export const REASONING_PREVIEW_MAX_CHARS = 1_024;
18
+
19
+ export interface CompactTurnSummary {
20
+ assistant: { text: string; thinking: string; lastUpdatedAt: string | null };
21
+ currentTool: Pick<
22
+ PrimaryPathToolCallSnapshot,
23
+ "toolCallId" | "toolName" | "status" | "isError"
24
+ > | null;
25
+ usage: UsageSnapshot | null;
26
+ toolCallCount: number;
27
+ traceItemCount: number;
28
+ /** The last persisted event incorporated into this projection. */
29
+ throughEventSequence: number;
30
+ lastTraceKind: "thinking" | "tool_call" | "operational_event" | null;
31
+ }
32
+
33
+ /** Initial-page state. It never contains trace items, tool arguments or results. */
34
+ export interface CompactActiveTurnSnapshot
35
+ extends CompactTurnSummary,
36
+ Pick<
37
+ PrimaryPathActiveTurnSnapshot,
38
+ "turnRecordId" | "turnId" | "turnType" | "pathType" | "startedAt"
39
+ > {
40
+ summaryPending: boolean;
41
+ }
42
+
43
+ export function emptyCompactTurnSummary(): CompactTurnSummary {
44
+ return {
45
+ assistant: { text: "", thinking: "", lastUpdatedAt: null },
46
+ currentTool: null,
47
+ usage: null,
48
+ toolCallCount: 0,
49
+ traceItemCount: 0,
50
+ throughEventSequence: 0,
51
+ lastTraceKind: null,
52
+ };
53
+ }
54
+
55
+ /** Retain paragraph context; wrapping and blank-line removal belong to the preview viewport. */
56
+ export function reasoningPreviewTail(text: string): string {
57
+ const normalized = text.replace(/\r\n?/g, "\n");
58
+ const lines = normalized.split("\n").filter((line) => line.trim() !== "");
59
+ const separator = /\n[^\S\n]*$/.test(normalized) ? "\n" : "";
60
+ return (lines.join("\n") + separator).slice(-REASONING_PREVIEW_MAX_CHARS);
61
+ }
62
+
63
+ export function applyEventToCompactTurnSummary(
64
+ previous: CompactTurnSummary,
65
+ event: {
66
+ eventType: string;
67
+ data: Record<string, unknown>;
68
+ createdAt: string;
69
+ eventSequence: number;
70
+ },
71
+ ): CompactTurnSummary {
72
+ if (event.eventSequence <= previous.throughEventSequence) return previous;
73
+ const next = {
74
+ ...previous,
75
+ assistant: { ...previous.assistant },
76
+ throughEventSequence: event.eventSequence,
77
+ };
78
+ const { eventType, data } = event;
79
+ if (eventType === "pi.stream.delta") {
80
+ const text = readWsEventStreamText(data);
81
+ const key = data.streamType === "thinking" ? "thinking" : "text";
82
+ next.assistant[key] = reasoningPreviewTail(next.assistant[key] + text);
83
+ if (text) next.assistant.lastUpdatedAt = readWsEventTimestamp(data, event.createdAt);
84
+ if (key === "thinking" && text) {
85
+ if (next.lastTraceKind !== "thinking") next.traceItemCount++;
86
+ next.lastTraceKind = "thinking";
87
+ }
88
+ } else if (eventType === "pi.tool.call" || eventType === "pi.tool.result") {
89
+ const isResult = eventType === "pi.tool.result";
90
+ const toolCallId = (readWsEventToolCallId(data) ?? `tool-${event.eventSequence}`).slice(0, 256);
91
+ if (!isResult) {
92
+ next.toolCallCount++;
93
+ next.traceItemCount++;
94
+ next.lastTraceKind = "tool_call";
95
+ }
96
+ if (!isResult || !next.currentTool || next.currentTool.toolCallId === toolCallId) {
97
+ next.currentTool = {
98
+ toolCallId: toolCallId.slice(0, 256),
99
+ toolName: readWsEventToolName(data).slice(0, 256),
100
+ status: isResult ? "completed" : "running",
101
+ isError: data.isError === true,
102
+ };
103
+ }
104
+ } else if (eventType === "pi.usage") {
105
+ next.usage = mergeUsageSnapshots(next.usage, normalizeUsageSnapshot(data));
106
+ } else if (
107
+ [
108
+ "pi.error",
109
+ "pi.retry.start",
110
+ "pi.retry.end",
111
+ "pi.compaction.start",
112
+ "pi.compaction.end",
113
+ ].includes(eventType)
114
+ ) {
115
+ next.traceItemCount++;
116
+ next.lastTraceKind = "operational_event";
117
+ }
118
+ return next;
119
+ }
@@ -144,6 +144,8 @@ export interface ProcessConfigSnapshot {
144
144
  * selection. Must reference a configured `worker_runtime_profiles` entry.
145
145
  */
146
146
  worker_runtime_profile?: string;
147
+ /** Server-only process-volume capacity override, for example 128Mi or 1Gi. */
148
+ storage_size?: string;
147
149
  pi?: ProcessPiConfigSnapshot;
148
150
  turn_configs: Record<string, ProcessTurnConfigSnapshot>;
149
151
  /** Extension-owned watcher configuration, keyed by code-defined watcher id. */
@@ -0,0 +1,45 @@
1
+ import { isUnknownRecord } from "@leitwerk-dev/domain";
2
+ import * as v from "valibot";
3
+
4
+ // Wire shape only; the catalog validates manifests and hosts check supported versions.
5
+ const recordSchema = v.custom<Record<string, unknown>>(isUnknownRecord);
6
+ const versionSchema = v.custom<number>((value) => typeof value === "number");
7
+
8
+ export const leafOutcomeRendererDescriptorSchema = v.pipe(
9
+ recordSchema,
10
+ v.object({
11
+ ok: v.literal(true),
12
+ rendererId: v.string(),
13
+ kind: v.literal("custom_element"),
14
+ tagName: v.string(),
15
+ modulePath: v.string(),
16
+ rendererApiVersion: versionSchema,
17
+ extensionManifestId: v.string(),
18
+ moduleUrl: v.string(),
19
+ }),
20
+ );
21
+ export type LeafOutcomeRendererDescriptor = v.InferOutput<
22
+ typeof leafOutcomeRendererDescriptorSchema
23
+ >;
24
+
25
+ export const leafOutcomeRendererFailureSchema = v.pipe(
26
+ recordSchema,
27
+ v.object({
28
+ ok: v.literal(false),
29
+ rendererId: v.string(),
30
+ code: v.string(),
31
+ message: v.string(),
32
+ }),
33
+ );
34
+ export type LeafOutcomeRendererFailure = v.InferOutput<typeof leafOutcomeRendererFailureSchema>;
35
+
36
+ export const browserUiExtensionDescriptorSchema = v.pipe(
37
+ recordSchema,
38
+ v.object({
39
+ extensionManifestId: v.string(),
40
+ modulePath: v.string(),
41
+ moduleUrl: v.string(),
42
+ browserApiVersion: versionSchema,
43
+ }),
44
+ );
45
+ export type BrowserUiExtensionDescriptor = v.InferOutput<typeof browserUiExtensionDescriptorSchema>;
@@ -4,6 +4,7 @@ import {
4
4
  type FutureExecutionBlockReason,
5
5
  type InstanceTurnConfigMap,
6
6
  type LaunchModelConfigInput,
7
+ type LaunchRun,
7
8
  normalizeActor,
8
9
  normalizeLaunchModelConfigInput,
9
10
  type ProcessEvent,
@@ -15,6 +16,7 @@ import {
15
16
  type ProcessQuestionRequest,
16
17
  type ProcessRowSlot,
17
18
  type ProcessSelectedTurnModelSource,
19
+ type ProcessToolApprovalRequest,
18
20
  type ProcessTurnAnnotation,
19
21
  type ProcessTurnRecord,
20
22
  type ProcessTurnType,
@@ -25,6 +27,7 @@ import {
25
27
  type WorkerLease,
26
28
  } from "@leitwerk-dev/domain";
27
29
  import * as v from "valibot";
30
+ import type { CompactActiveTurnSnapshot } from "./compact-turn-summary.js";
28
31
  import type {
29
32
  ActionFormDefinition,
30
33
  ActionFormFieldDefinition,
@@ -49,12 +52,32 @@ import {
49
52
  unknownRecordSchema,
50
53
  } from "./protocol.js";
51
54
  import type { ToolCallRendererDefinition } from "./tool-renderer-contract.js";
55
+ import type { UsageCostSnapshot, UsageTokenCounts } from "./usage-snapshot.js";
56
+
57
+ export interface StartLaunchRunResponseBody {
58
+ launchRunId: string;
59
+ instanceId: string | null;
60
+ }
61
+
62
+ export interface LaunchRunResponseBody {
63
+ launchRun: LaunchRun;
64
+ }
65
+
66
+ export interface ProcessLaunchRunsResponseBody {
67
+ launchRuns: LaunchRun[];
68
+ }
52
69
 
53
70
  export interface AuthMeResponseBody {
54
71
  authEnabled: boolean;
55
72
  actor: Actor | null;
56
73
  }
57
74
 
75
+ export interface SessionTransferOperationView {
76
+ attemptId: string;
77
+ phase: string;
78
+ blocksManualTurns: boolean;
79
+ }
80
+
58
81
  export interface ProcessListItem {
59
82
  process: ProcessInstance;
60
83
  projects: ProcessProject[];
@@ -351,21 +374,8 @@ export interface ProcessLaunchConfigurationView {
351
374
  projects: readonly ProcessLaunchConfigurationProjectView[];
352
375
  }
353
376
 
354
- export interface PiSessionUsageSnapshot {
355
- input: number;
356
- output: number;
357
- /** Provider-reported reasoning/thinking tokens. This is a subset of output tokens. */
358
- reasoning?: number;
359
- cacheRead: number;
360
- cacheWrite: number;
361
- totalTokens: number;
362
- cost?: {
363
- input: number;
364
- output: number;
365
- cacheRead: number;
366
- cacheWrite: number;
367
- total: number;
368
- };
377
+ export interface PiSessionUsageSnapshot extends UsageTokenCounts {
378
+ cost?: UsageCostSnapshot;
369
379
  }
370
380
 
371
381
  export type PiSessionTextContentBlock = { type: "text"; text: string };
@@ -530,27 +540,34 @@ export interface SkillRepositorySummary {
530
540
  error: string | null;
531
541
  }
532
542
 
533
- export interface SkillCatalogSummary {
543
+ export interface SkillCatalogItem {
544
+ repositoryId: string;
534
545
  id: string;
535
546
  label: string;
536
547
  description: string | null;
537
- updateAvailable: boolean;
538
- modelInvocable: boolean;
539
- usage: SkillUsageSummary;
540
- }
541
-
542
- export interface SkillCatalogItem extends SkillCatalogSummary {
543
- repositoryId: string;
544
548
  sourcePath: string;
545
549
  sourceRevision: string;
546
550
  registered: boolean;
551
+ updateAvailable: boolean;
552
+ conflict: boolean;
547
553
  stale: boolean;
554
+ modelInvocable: boolean;
555
+ usage: SkillUsageSummary;
548
556
  }
549
557
 
550
- export interface InstalledSkillCatalogItem extends SkillCatalogSummary {
558
+ export type SkillRegistrationKind = "configuration" | "catalog";
559
+
560
+ export interface InstalledSkillCatalogItem {
561
+ id: string;
562
+ label: string;
563
+ description: string | null;
551
564
  activeRevisionId: string;
552
565
  activeSourceRevision: string | null;
566
+ registrationKind: SkillRegistrationKind;
553
567
  sourceRepositoryId: string | null;
568
+ updateAvailable: boolean;
569
+ modelInvocable: boolean;
570
+ usage: SkillUsageSummary;
554
571
  }
555
572
 
556
573
  export interface SkillRevisionSummary {
@@ -596,16 +613,9 @@ export interface ProcessOverviewItem extends ProcessRowSlot {
596
613
  closedAt: string | null;
597
614
  }
598
615
 
599
- interface FutureExecutionOverviewItemBase {
600
- id: string;
601
- scheduleKind: "once" | "cron";
602
- processId: string;
603
- nextRunAt: string;
604
- cronExpression: string | null;
605
- title: string;
616
+ interface FutureExecutionOverviewItemBase
617
+ extends Omit<FutureExecutionBaseSummary, "kind" | "subtitle" | "modelSelection"> {
606
618
  initialPromptPreview: string | null;
607
- status?: "scheduled" | "blocked";
608
- blockedReason?: FutureExecutionBlockReason | null;
609
619
  }
610
620
 
611
621
  export interface FutureLaunchOverviewItem extends FutureExecutionOverviewItemBase {
@@ -715,6 +725,10 @@ export interface ProcessTimelineTurnSummary {
715
725
  summary: string;
716
726
  output: string;
717
727
  turnResultMarkdown: string;
728
+ resultSummary?: string;
729
+ reviewedTurnRecordId?: string;
730
+ resources?: import("@leitwerk-dev/domain").TurnProgressLink[];
731
+ transition?: { selectedTurnId: string; targetTurnRecordId?: string; accepted: boolean };
718
732
  pathType: ProcessTurnRecord["pathType"];
719
733
  createdAt: string;
720
734
  presentation: ProcessTimelineTurnPresentation;
@@ -727,6 +741,7 @@ export interface ProcessTimelineTurnSummary {
727
741
  endedAt: string | null;
728
742
  actionSource: "ui" | "external" | "scheduled" | null;
729
743
  progress?: TurnProgressReport | null;
744
+ progressRecordedAt?: string;
730
745
  }
731
746
 
732
747
  export type ProcessTimelineInputSummary = Pick<
@@ -734,7 +749,18 @@ export type ProcessTimelineInputSummary = Pick<
734
749
  "id" | "sequence" | "source" | "kind" | "bodyMarkdown" | "receivedAt" | "consumedAt"
735
750
  >;
736
751
 
752
+ export interface ProcessExternalObservation {
753
+ summary: string;
754
+ links?: import("@leitwerk-dev/domain").TurnProgressLink[];
755
+ observedAt: string;
756
+ subject: string;
757
+ revision: string;
758
+ }
759
+
737
760
  export interface ProcessExternalTriggerSignal {
761
+ observation?: ProcessExternalObservation;
762
+ refreshError?: string | null;
763
+ refreshedAt?: string;
738
764
  triggerId: string;
739
765
  state: "error" | "armed" | "triggered" | "waiting";
740
766
  occurredAt: string | null;
@@ -773,6 +799,39 @@ export interface StartupRecoverySummary extends CurrentErrorSummary {
773
799
  providerOptions: Record<string, string>;
774
800
  }
775
801
 
802
+ export type StartupAttemptStatus = "starting" | "failed" | "succeeded" | "recovered" | "superseded";
803
+
804
+ export interface StartupAttemptStepSummary {
805
+ /** Observed phase interval; absent for older servers or unavailable evidence. */
806
+ startedAt?: string | null;
807
+ endedAt?: string | null;
808
+ detail?: string;
809
+ id: "start_worker" | "connect_worker" | "prepare_workspace" | "start_first_turn";
810
+ label: string;
811
+ status: "pending" | "in_progress" | "completed" | "failed" | "superseded";
812
+ occurredAt: string | null;
813
+ }
814
+
815
+ /** Worker-start history derived from correlated start, lease, readiness, and turn records. */
816
+ export interface StartupAttemptSummary {
817
+ startRecordId: string;
818
+ workerLeaseId: string | null;
819
+ status: StartupAttemptStatus;
820
+ startedAt: string;
821
+ readyAt: string | null;
822
+ durationMs: number | null;
823
+ summary: string | null;
824
+ recoveredByStartRecordId: string | null;
825
+ steps: StartupAttemptStepSummary[];
826
+ }
827
+
828
+ export interface ProcessStartupSummary {
829
+ workerStarts?: import("@leitwerk-dev/domain").PhysicalWorkerStart[];
830
+ authoritativeAttemptId: string | null;
831
+ attempts: StartupAttemptSummary[];
832
+ recovery: StartupRecoverySummary | null;
833
+ }
834
+
776
835
  export type CurrentProcessErrorSummary = CurrentErrorSummary;
777
836
 
778
837
  export interface ProcessUsageEstimateSnapshot {
@@ -785,7 +844,11 @@ export interface ProcessUsageEstimateSnapshot {
785
844
  isPartial: boolean;
786
845
  }
787
846
 
788
- export interface PrimaryPathUiSnapshot extends PrimaryPathSnapshot {
847
+ export interface PrimaryPathUiSnapshot extends Omit<PrimaryPathSnapshot, "turnState"> {
848
+ throughEventSequence: number;
849
+ turnState: Omit<PrimaryPathSnapshot["turnState"], "activeTurn"> & {
850
+ activeTurn: CompactActiveTurnSnapshot | null;
851
+ };
789
852
  entryCount: number;
790
853
  entriesOmitted: true;
791
854
  }
@@ -814,8 +877,11 @@ export type ProcessUiSnapshotProcess = Pick<
814
877
  */
815
878
  export interface ProcessDetailUiSnapshotResponseBody {
816
879
  process: ProcessUiSnapshotProcess;
880
+ /** Next turn on the declared happy path, including human decisions. */
881
+ plannedNextTurn?: Pick<ProcessSelectedTurnSummary, "turnId" | "description"> | null;
817
882
  /** Durable requests in Chronicle order; at most one is open for the current turn. */
818
883
  questionRequests: ProcessQuestionRequest[];
884
+ toolApprovalRequests: ProcessToolApprovalRequest[];
819
885
  leafOutcomeSnapshots: ProcessLeafOutcomeSnapshot[];
820
886
  processDisplayName: string | null;
821
887
  processFlow: ProcessFlowView;
@@ -831,11 +897,15 @@ export interface ProcessDetailUiSnapshotResponseBody {
831
897
  timeline: ProcessTimelineSnapshot;
832
898
  instanceTree: ProcessInstanceTreeResponseBody;
833
899
  recovery: CurrentTurnRecoverySummary | null;
900
+ /** Authoritative startup history and current remediation. */
901
+ startup: ProcessStartupSummary;
902
+ /** Compatibility alias for startup.recovery. */
834
903
  startupRecovery: StartupRecoverySummary | null;
835
904
  processError: CurrentProcessErrorSummary | null;
836
905
  usageEstimate: ProcessUsageEstimateSnapshot | null;
837
906
  persistedModelSelectionWarning: string | null;
838
907
  session: { signature: string | null };
908
+ sessionTransfer: SessionTransferOperationView | null;
839
909
  }
840
910
 
841
911
  export type InstanceTreeTurnResultState = "succeeded" | "failed" | "aborted" | "pending";
@@ -867,6 +937,8 @@ export interface ProcessInstanceTreeResponseBody {
867
937
  }
868
938
 
869
939
  export interface TurnReasoningDetailResponseBody {
940
+ state: "live" | "committed";
941
+ throughEventSequence: number;
870
942
  instanceId: string;
871
943
  turnRecordId: string;
872
944
  sessionSignature: string | null;
@@ -920,6 +992,12 @@ export interface LauncherMutationResponseBody {
920
992
  error?: string | null;
921
993
  }
922
994
 
995
+ export interface FutureLaunchMutationResponseBody {
996
+ kind: "scheduled";
997
+ futureExecution: FutureLaunchSummary | null;
998
+ error?: string | null;
999
+ }
1000
+
923
1001
  export type ScheduledActionMutationResponseBody = {
924
1002
  kind?: "scheduled";
925
1003
  scheduledAction?: ScheduledActionDetail | null;
@@ -936,7 +1014,7 @@ export type PrimaryPathSnapshotResponseBody = PrimaryPathSnapshot;
936
1014
 
937
1015
  export type CronPreviewResponseBody = { nextRunAt: string };
938
1016
 
939
- type ParsedLauncherRequestBody = {
1017
+ export type ParsedLauncherRequestBody = {
940
1018
  title: string | null;
941
1019
  titleProvided: boolean;
942
1020
  launcherInput: Record<string, unknown>;
@@ -948,7 +1026,7 @@ type ParsedLauncherRequestBody = {
948
1026
  scheduleProvided: boolean;
949
1027
  };
950
1028
 
951
- type ParsedActionRequestBody = {
1029
+ export type ParsedActionRequestBody = {
952
1030
  input: Record<string, unknown>;
953
1031
  inputProvided: boolean;
954
1032
  nextTurnModelProfileId?: string | null;
@@ -1060,12 +1138,6 @@ type FutureLaunchPayloadBase = v.InferOutput<typeof futureLaunchPayloadInputSche
1060
1138
  type FutureActionPayloadBase = v.InferOutput<typeof futureActionPayloadInputSchema>;
1061
1139
  const cloneUnknownRecord = (value?: Record<string, unknown> | null) =>
1062
1140
  value ? { ...value } : null;
1063
- const cloneTurnConfigMap = (turnConfigs: InstanceTurnConfigMap = {}) =>
1064
- Object.fromEntries(
1065
- Object.entries(turnConfigs as Record<string, InstanceTurnConfigMap[string]>).map(
1066
- ([turnId, turnConfig]) => [turnId, { ...turnConfig }],
1067
- ),
1068
- ) as InstanceTurnConfigMap;
1069
1141
  const normalizeFutureLaunchPayload = (payload: FutureLaunchPayloadBase) => {
1070
1142
  const modelConfig = normalizeLaunchModelConfigInput(
1071
1143
  (payload.modelConfig ?? {}) as LaunchModelConfigInput,
@@ -1074,7 +1146,7 @@ const normalizeFutureLaunchPayload = (payload: FutureLaunchPayloadBase) => {
1074
1146
  launcherInput: cloneUnknownRecord(payload.launcherInput) ?? {},
1075
1147
  modelConfig: {
1076
1148
  defaultModelProfileId: modelConfig.defaultModelProfileId ?? null,
1077
- turnConfigs: cloneTurnConfigMap(modelConfig.turnConfigs),
1149
+ turnConfigs: { ...modelConfig.turnConfigs },
1078
1150
  },
1079
1151
  actor: normalizeActor(payload.actor),
1080
1152
  selectedSkillIds: [
@@ -1130,10 +1202,6 @@ const normalizeFutureActionPayload = (payload: FutureActionPayloadBase) => ({
1130
1202
  export type FutureLaunchPayload = ReturnType<typeof normalizeFutureLaunchPayload>;
1131
1203
  export type FutureActionPayload = ReturnType<typeof normalizeFutureActionPayload>;
1132
1204
 
1133
- function hasOwn(object: Record<string, unknown>, key: string): boolean {
1134
- return Object.hasOwn(object, key);
1135
- }
1136
-
1137
1205
  function parseJsonPayload(payloadJson: string, context: string): ParseResult<unknown> {
1138
1206
  try {
1139
1207
  return ok(JSON.parse(payloadJson));
@@ -1262,7 +1330,7 @@ export function parseLauncherModelConfigInput(
1262
1330
  }
1263
1331
  const defaultModelProfileId = trimToNull(record.value.defaultModelProfileId);
1264
1332
  if (
1265
- hasOwn(record.value, "defaultModelProfileId") &&
1333
+ Object.hasOwn(record.value, "defaultModelProfileId") &&
1266
1334
  record.value.defaultModelProfileId !== null &&
1267
1335
  typeof record.value.defaultModelProfileId !== "string"
1268
1336
  ) {
@@ -1283,7 +1351,11 @@ export function parseLauncherModelConfigInput(
1283
1351
  }
1284
1352
 
1285
1353
  function hasInlineScheduleFields(object: Record<string, unknown>): boolean {
1286
- return hasOwn(object, "mode") || hasOwn(object, "runAt") || hasOwn(object, "cronExpression");
1354
+ return (
1355
+ Object.hasOwn(object, "mode") ||
1356
+ Object.hasOwn(object, "runAt") ||
1357
+ Object.hasOwn(object, "cronExpression")
1358
+ );
1287
1359
  }
1288
1360
 
1289
1361
  export function parseLauncherRequestBody(value: unknown): ParseResult<ParsedLauncherRequestBody> {
@@ -1304,7 +1376,7 @@ export function parseLauncherRequestBody(value: unknown): ParseResult<ParsedLaun
1304
1376
  return record;
1305
1377
  }
1306
1378
  if (
1307
- hasOwn(record.value, "title") ||
1379
+ Object.hasOwn(record.value, "title") ||
1308
1380
  record.value.launcherInput !== undefined ||
1309
1381
  record.value.skillIds !== undefined ||
1310
1382
  record.value.modelConfig !== undefined ||
@@ -1312,12 +1384,7 @@ export function parseLauncherRequestBody(value: unknown): ParseResult<ParsedLaun
1312
1384
  ) {
1313
1385
  if (
1314
1386
  Object.keys(record.value).some(
1315
- (key) =>
1316
- key !== "title" &&
1317
- key !== "launcherInput" &&
1318
- key !== "skillIds" &&
1319
- key !== "modelConfig" &&
1320
- key !== "schedule",
1387
+ (key) => !Object.hasOwn(launcherStructuredBodySchema.entries, key),
1321
1388
  )
1322
1389
  ) {
1323
1390
  return err(
@@ -1342,14 +1409,14 @@ export function parseLauncherRequestBody(value: unknown): ParseResult<ParsedLaun
1342
1409
  }
1343
1410
  return ok({
1344
1411
  title: parsed.value.title ?? null,
1345
- titleProvided: hasOwn(record.value, "title"),
1412
+ titleProvided: Object.hasOwn(record.value, "title"),
1346
1413
  launcherInput: parsed.value.launcherInput ?? {},
1347
- launcherInputProvided: hasOwn(record.value, "launcherInput"),
1348
- ...(hasOwn(record.value, "skillIds") ? { skillIds: [...skillIds] } : {}),
1414
+ launcherInputProvided: Object.hasOwn(record.value, "launcherInput"),
1415
+ ...(Object.hasOwn(record.value, "skillIds") ? { skillIds: [...skillIds] } : {}),
1349
1416
  modelConfig: modelConfig.value,
1350
- modelConfigProvided: hasOwn(record.value, "modelConfig"),
1417
+ modelConfigProvided: Object.hasOwn(record.value, "modelConfig"),
1351
1418
  schedule: schedule.value,
1352
- scheduleProvided: hasOwn(record.value, "schedule"),
1419
+ scheduleProvided: Object.hasOwn(record.value, "schedule"),
1353
1420
  });
1354
1421
  }
1355
1422
  const modelConfig = parseLauncherModelConfigInput(record.value, "modelConfig");
@@ -1386,7 +1453,7 @@ export function parseActionRequestBody(value: unknown): ParseResult<ParsedAction
1386
1453
  if (!record.ok) {
1387
1454
  return record;
1388
1455
  }
1389
- const nextTurnModelProfileIdProvided = hasOwn(record.value, "nextTurnModelProfileId");
1456
+ const nextTurnModelProfileIdProvided = Object.hasOwn(record.value, "nextTurnModelProfileId");
1390
1457
  if (
1391
1458
  record.value.input !== undefined ||
1392
1459
  nextTurnModelProfileIdProvided ||
@@ -1394,7 +1461,7 @@ export function parseActionRequestBody(value: unknown): ParseResult<ParsedAction
1394
1461
  ) {
1395
1462
  if (
1396
1463
  Object.keys(record.value).some(
1397
- (key) => key !== "input" && key !== "nextTurnModelProfileId" && key !== "schedule",
1464
+ (key) => !Object.hasOwn(actionStructuredBodySchema.entries, key),
1398
1465
  )
1399
1466
  ) {
1400
1467
  return err("action request body must use { input, nextTurnModelProfileId }");
@@ -1409,10 +1476,10 @@ export function parseActionRequestBody(value: unknown): ParseResult<ParsedAction
1409
1476
  }
1410
1477
  return ok({
1411
1478
  input: parsed.value.input ?? {},
1412
- inputProvided: hasOwn(record.value, "input"),
1479
+ inputProvided: Object.hasOwn(record.value, "input"),
1413
1480
  nextTurnModelProfileIdProvided,
1414
1481
  schedule: schedule.value,
1415
- scheduleProvided: hasOwn(record.value, "schedule"),
1482
+ scheduleProvided: Object.hasOwn(record.value, "schedule"),
1416
1483
  ...(nextTurnModelProfileIdProvided
1417
1484
  ? { nextTurnModelProfileId: parsed.value.nextTurnModelProfileId ?? null }
1418
1485
  : {}),
@@ -1428,9 +1495,6 @@ export function parseActionRequestBody(value: unknown): ParseResult<ParsedAction
1428
1495
  nextTurnModelProfileIdProvided,
1429
1496
  schedule: schedule.value,
1430
1497
  scheduleProvided: hasInlineScheduleFields(record.value),
1431
- ...(nextTurnModelProfileIdProvided
1432
- ? { nextTurnModelProfileId: trimToNull(record.value.nextTurnModelProfileId) }
1433
- : {}),
1434
1498
  });
1435
1499
  }
1436
1500
 
@@ -1471,3 +1535,10 @@ export function parseFutureActionPayloadJson(
1471
1535
  const parsed = parseJsonPayload(payloadJson, "Scheduled action payload");
1472
1536
  return parsed.ok ? parseFutureActionPayloadObject(parsed.value) : parsed;
1473
1537
  }
1538
+
1539
+ export type {
1540
+ ApiTokenMetadata,
1541
+ ApiTokenPolicy,
1542
+ ApiTokensResponseBody,
1543
+ CreateApiTokenResponseBody,
1544
+ } from "./api-token-contracts.js";
package/src/index.ts CHANGED
@@ -1,4 +1,6 @@
1
+ export * from "./compact-turn-summary.js";
1
2
  export * from "./config-snapshot.js";
3
+ export * from "./extension-ui-contracts.js";
2
4
  export * from "./external-review.js";
3
5
  export * from "./form-contract.js";
4
6
  export * from "./http-contracts.js";
@@ -11,10 +13,13 @@ export * from "./protocol.js";
11
13
  export * from "./session-entry-tree.js";
12
14
  export * from "./streamable-events.js";
13
15
  export * from "./text-preview.js";
16
+ export * from "./ticket-creation-contracts.js";
14
17
  export * from "./timeline-projection.js";
15
18
  export * from "./timestamp-ordering.js";
16
19
  export * from "./tool-renderer-contract.js";
20
+ export * from "./tool-result-truncation.js";
17
21
  export * from "./turn-continuation.js";
22
+ export * from "./turn-trace-projection.js";
18
23
  export * from "./usage-by-turn-record.js";
19
24
  export * from "./usage-snapshot.js";
20
25
  export * from "./ws-event-payloads.js";
@@ -1,3 +1,4 @@
1
+ import { isUnknownRecord as isRecord } from "@leitwerk-dev/domain";
1
2
  import type { FutureExecutionOverviewItem, FutureExecutionSummary } from "./http-contracts.js";
2
3
 
3
4
  // Best-effort extraction of an operator-facing prompt/command from launch params
@@ -20,10 +21,6 @@ export const INITIAL_PROMPT_FIELD_PRIORITY = [
20
21
  "description",
21
22
  ] as const;
22
23
 
23
- function isRecord(value: unknown): value is Record<string, unknown> {
24
- return typeof value === "object" && value !== null && !Array.isArray(value);
25
- }
26
-
27
24
  function normalizePromptValue(value: string): string | null {
28
25
  const normalized = value.replace(/\s+/g, " ").trim();
29
26
  return normalized.length > 0 ? normalized : null;
@@ -42,7 +39,7 @@ export function truncatePromptPreview(
42
39
  function readStringField(record: Record<string, unknown>, fieldName: string): string | null {
43
40
  const exact = record[fieldName];
44
41
  if (typeof exact === "string") {
45
- return normalizePromptValue(exact);
42
+ return exact.trim() ? exact : null;
46
43
  }
47
44
 
48
45
  const normalizedFieldName = fieldName.toLowerCase();
@@ -50,7 +47,7 @@ function readStringField(record: Record<string, unknown>, fieldName: string): st
50
47
  if (key.toLowerCase() !== normalizedFieldName || typeof value !== "string") {
51
48
  continue;
52
49
  }
53
- return normalizePromptValue(value);
50
+ return value.trim() ? value : null;
54
51
  }
55
52
 
56
53
  return null;