@leitwerk-dev/protocol 0.2.0 → 0.2.1
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/api-token-contracts.d.ts +20 -0
- package/dist/api-token-contracts.d.ts.map +1 -1
- package/dist/{chunk-J4VMD5ST.js → chunk-4AKWRRFS.js} +98 -4
- package/dist/chunk-4AKWRRFS.js.map +1 -0
- package/dist/{chunk-Z4IU6KEN.js → chunk-LTIDCJFK.js} +146 -1
- package/dist/chunk-LTIDCJFK.js.map +1 -0
- package/dist/{chunk-IWVU76M5.js → chunk-RUPDB3WZ.js} +1 -1
- package/dist/chunk-RUPDB3WZ.js.map +1 -0
- package/dist/compact-turn-summary.d.ts +21 -3
- package/dist/compact-turn-summary.d.ts.map +1 -1
- package/dist/config-snapshot-public.d.ts +2 -0
- package/dist/config-snapshot-public.d.ts.map +1 -0
- package/dist/config-snapshot-public.js +1 -0
- package/dist/config-snapshot.d.ts +109 -16
- package/dist/config-snapshot.d.ts.map +1 -1
- package/dist/config-snapshot.js +0 -1
- package/dist/extension-ui-contracts.d.ts +22 -0
- package/dist/extension-ui-contracts.d.ts.map +1 -1
- package/dist/external-review.d.ts +5 -1
- package/dist/external-review.d.ts.map +1 -1
- package/dist/form-contract-public.d.ts +2 -0
- package/dist/form-contract-public.d.ts.map +1 -0
- package/dist/form-contract-public.js +1 -0
- package/dist/form-contract.d.ts +29 -5
- package/dist/form-contract.d.ts.map +1 -1
- package/dist/form-contract.js +0 -1
- package/dist/{http-contracts-ht8DDU4J.d.ts → http-contracts-public-rL4HFcxz.d.ts} +971 -45
- package/dist/http-contracts-public.d.ts +4 -0
- package/dist/http-contracts-public.d.ts.map +1 -0
- package/dist/http-contracts-public.js +10 -0
- package/dist/http-contracts.d.ts +819 -12
- package/dist/http-contracts.d.ts.map +1 -1
- package/dist/http-contracts.js +2 -2
- package/dist/index.d.ts +30 -25
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -75
- package/dist/index.js.map +1 -1
- package/dist/initial-prompt.d.ts +6 -0
- package/dist/initial-prompt.d.ts.map +1 -1
- package/dist/launcher-contract-public.d.ts +2 -0
- package/dist/launcher-contract-public.d.ts.map +1 -0
- package/dist/launcher-contract-public.js +1 -0
- package/dist/launcher-contract-public.js.map +1 -0
- package/dist/launcher-contract.d.ts +26 -1
- package/dist/launcher-contract.d.ts.map +1 -1
- package/dist/launcher-contract.js +0 -1
- package/dist/live-turn-projection.d.ts +29 -0
- package/dist/live-turn-projection.d.ts.map +1 -1
- package/dist/pi-session-message.d.ts +16 -0
- package/dist/pi-session-message.d.ts.map +1 -1
- package/dist/primary-path-snapshot.d.ts +64 -0
- package/dist/primary-path-snapshot.d.ts.map +1 -1
- package/dist/protocol.d.ts +387 -1
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +1 -1
- package/dist/session-entry-tree.d.ts +12 -0
- package/dist/session-entry-tree.d.ts.map +1 -1
- package/dist/streamable-events.d.ts +3 -0
- package/dist/streamable-events.d.ts.map +1 -1
- package/dist/text-preview.d.ts +5 -0
- package/dist/text-preview.d.ts.map +1 -1
- package/dist/ticket-creation-contracts.d.ts +23 -1
- package/dist/ticket-creation-contracts.d.ts.map +1 -1
- package/dist/timeline-projection.d.ts +5 -0
- package/dist/timeline-projection.d.ts.map +1 -1
- package/dist/timestamp-ordering.d.ts +2 -0
- package/dist/timestamp-ordering.d.ts.map +1 -1
- package/dist/tool-renderer-contract-public.d.ts +3 -0
- package/dist/tool-renderer-contract-public.d.ts.map +1 -0
- package/dist/tool-renderer-contract-public.js +9 -0
- package/dist/tool-renderer-contract-public.js.map +1 -0
- package/dist/tool-renderer-contract.d.ts +15 -0
- package/dist/tool-renderer-contract.d.ts.map +1 -1
- package/dist/tool-renderer-contract.js +1 -1
- package/dist/tool-result-truncation.d.ts +4 -0
- package/dist/tool-result-truncation.d.ts.map +1 -1
- package/dist/turn-continuation.d.ts +28 -0
- package/dist/turn-continuation.d.ts.map +1 -1
- package/dist/turn-trace-projection.d.ts +1 -1
- package/dist/turn-trace-projection.d.ts.map +1 -1
- package/dist/usage-by-turn-record.d.ts +2 -0
- package/dist/usage-by-turn-record.d.ts.map +1 -1
- package/dist/usage-snapshot.d.ts +20 -3
- package/dist/usage-snapshot.d.ts.map +1 -1
- package/dist/ws-event-payloads.d.ts +14 -0
- package/dist/ws-event-payloads.d.ts.map +1 -1
- package/package.json +17 -17
- package/src/api-token-contracts.ts +20 -0
- package/src/compact-turn-summary.ts +26 -4
- package/src/config-snapshot-public.ts +12 -0
- package/src/config-snapshot.ts +109 -16
- package/src/extension-ui-contracts.ts +22 -0
- package/src/external-review.ts +5 -1
- package/src/form-contract-public.ts +6 -0
- package/src/form-contract.ts +29 -5
- package/src/http-contracts-public.ts +86 -0
- package/src/http-contracts.ts +926 -40
- package/src/index.ts +184 -25
- package/src/initial-prompt.ts +6 -0
- package/src/launcher-contract-public.ts +8 -0
- package/src/launcher-contract.ts +26 -1
- package/src/live-turn-projection.ts +29 -0
- package/src/pi-session-message.ts +21 -3
- package/src/primary-path-snapshot.ts +64 -0
- package/src/protocol.ts +412 -17
- package/src/session-entry-tree.ts +12 -0
- package/src/streamable-events.ts +3 -0
- package/src/text-preview.ts +5 -0
- package/src/ticket-creation-contracts.ts +31 -3
- package/src/timeline-projection.ts +5 -0
- package/src/timestamp-ordering.ts +2 -0
- package/src/tool-renderer-contract-public.ts +10 -0
- package/src/tool-renderer-contract.ts +15 -0
- package/src/tool-result-truncation.ts +4 -0
- package/src/turn-continuation.ts +28 -0
- package/src/turn-trace-projection.ts +1 -1
- package/src/usage-by-turn-record.ts +2 -0
- package/src/usage-snapshot.ts +20 -3
- package/src/ws-event-payloads.ts +14 -0
- package/dist/chunk-6L4W7WPV.js +0 -1
- package/dist/chunk-AAV3AAOF.js +0 -1
- package/dist/chunk-IEMT3JG4.js +0 -1
- package/dist/chunk-IWVU76M5.js.map +0 -1
- package/dist/chunk-J4VMD5ST.js.map +0 -1
- package/dist/chunk-Z4IU6KEN.js.map +0 -1
- /package/dist/{chunk-6L4W7WPV.js.map → config-snapshot-public.js.map} +0 -0
- /package/dist/{chunk-AAV3AAOF.js.map → form-contract-public.js.map} +0 -0
- /package/dist/{chunk-IEMT3JG4.js.map → http-contracts-public.js.map} +0 -0
|
@@ -1,18 +1,30 @@
|
|
|
1
|
+
/** @internal */
|
|
1
2
|
export interface SessionTreeEntryLike {
|
|
3
|
+
/** @internal */
|
|
2
4
|
id: string;
|
|
5
|
+
/** @internal */
|
|
3
6
|
parentId: string | null;
|
|
7
|
+
/** @internal */
|
|
4
8
|
timestamp: string;
|
|
9
|
+
/** @internal */
|
|
5
10
|
type: string;
|
|
6
11
|
}
|
|
7
12
|
|
|
13
|
+
/** @internal */
|
|
8
14
|
export interface ReadonlyEntryTree<TEntry extends SessionTreeEntryLike> {
|
|
15
|
+
/** @internal */
|
|
9
16
|
entries: TEntry[];
|
|
17
|
+
/** @internal */
|
|
10
18
|
leafId: string | null;
|
|
19
|
+
/** @internal */
|
|
11
20
|
getEntry(id: string): TEntry | undefined;
|
|
21
|
+
/** @internal */
|
|
12
22
|
getChildren(parentId: string): TEntry[];
|
|
23
|
+
/** @internal */
|
|
13
24
|
getBranch(fromId?: string | null): TEntry[];
|
|
14
25
|
}
|
|
15
26
|
|
|
27
|
+
/** @internal */
|
|
16
28
|
export function createReadonlyEntryTree<TEntry extends SessionTreeEntryLike>(
|
|
17
29
|
entries: readonly TEntry[],
|
|
18
30
|
): ReadonlyEntryTree<TEntry> {
|
package/src/streamable-events.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** @internal */
|
|
1
2
|
export const STREAMABLE_WORKER_EVENT_TYPES = [
|
|
2
3
|
"pi.stream.delta",
|
|
3
4
|
"pi.turn.start",
|
|
@@ -13,10 +14,12 @@ export const STREAMABLE_WORKER_EVENT_TYPES = [
|
|
|
13
14
|
"pi.compaction.end",
|
|
14
15
|
] as const;
|
|
15
16
|
|
|
17
|
+
/** @internal */
|
|
16
18
|
export type StreamableWorkerEventType = (typeof STREAMABLE_WORKER_EVENT_TYPES)[number];
|
|
17
19
|
|
|
18
20
|
const STREAMABLE_EVENT_TYPES = new Set<string>(STREAMABLE_WORKER_EVENT_TYPES);
|
|
19
21
|
|
|
22
|
+
/** @internal */
|
|
20
23
|
export function isStreamableEvent(eventType: string): eventType is StreamableWorkerEventType {
|
|
21
24
|
return STREAMABLE_EVENT_TYPES.has(eventType);
|
|
22
25
|
}
|
package/src/text-preview.ts
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
|
+
/** @internal */
|
|
1
2
|
export interface TextPreview {
|
|
3
|
+
/** @internal */
|
|
2
4
|
text: string;
|
|
5
|
+
/** @internal */
|
|
3
6
|
truncated: boolean;
|
|
4
7
|
}
|
|
5
8
|
|
|
9
|
+
/** @internal */
|
|
6
10
|
export function truncateTextPreview(value: string, maxLength: number): TextPreview {
|
|
7
11
|
return value.length <= maxLength
|
|
8
12
|
? { text: value, truncated: false }
|
|
9
13
|
: { text: value.slice(0, maxLength).trimEnd(), truncated: true };
|
|
10
14
|
}
|
|
11
15
|
|
|
16
|
+
/** @internal */
|
|
12
17
|
export function buildTrailingLinePreview(
|
|
13
18
|
value: string,
|
|
14
19
|
lineCount: number,
|
|
@@ -1,34 +1,62 @@
|
|
|
1
1
|
import type { ProcessRelation } from "@leitwerk-dev/domain";
|
|
2
2
|
|
|
3
|
+
/** @internal */
|
|
3
4
|
export interface TicketCreationToolSummary {
|
|
5
|
+
/** @internal */
|
|
4
6
|
name: string;
|
|
7
|
+
/** @internal */
|
|
5
8
|
displayName: string;
|
|
6
9
|
}
|
|
7
10
|
|
|
11
|
+
/** @internal */
|
|
8
12
|
export type TicketResultArtifactLocator =
|
|
9
|
-
| {
|
|
10
|
-
|
|
13
|
+
| {
|
|
14
|
+
/** @internal */
|
|
15
|
+
kind: "turn_result";
|
|
16
|
+
/** @internal */
|
|
17
|
+
turnRecordId: string;
|
|
18
|
+
}
|
|
19
|
+
| {
|
|
20
|
+
/** @internal */
|
|
21
|
+
kind: "leaf_outcome";
|
|
22
|
+
/** @internal */
|
|
23
|
+
leafEntryId: string;
|
|
24
|
+
};
|
|
11
25
|
|
|
26
|
+
/** @internal */
|
|
12
27
|
export interface TicketCreationFocus {
|
|
28
|
+
/** @internal */
|
|
13
29
|
kind: "whole_result" | "excerpt";
|
|
14
|
-
/** Browser-selected normalized text. The server still validates the artifact. */
|
|
30
|
+
/** Browser-selected normalized text. The server still validates the artifact. @internal */
|
|
15
31
|
excerpt?: string;
|
|
16
32
|
}
|
|
17
33
|
|
|
34
|
+
/** @internal */
|
|
18
35
|
export interface LaunchTicketCreationRequestBody {
|
|
36
|
+
/** @internal */
|
|
19
37
|
artifact: TicketResultArtifactLocator;
|
|
38
|
+
/** @internal */
|
|
20
39
|
focus: TicketCreationFocus;
|
|
40
|
+
/** @internal */
|
|
21
41
|
additionalInstructions?: string;
|
|
42
|
+
/** @internal */
|
|
22
43
|
toolName: string;
|
|
44
|
+
/** @internal */
|
|
23
45
|
modelProfileId?: string;
|
|
24
46
|
}
|
|
25
47
|
|
|
48
|
+
/** @internal */
|
|
26
49
|
export interface LaunchTicketCreationResponseBody {
|
|
50
|
+
/** @internal */
|
|
27
51
|
childInstanceId: string;
|
|
52
|
+
/** @internal */
|
|
28
53
|
relation: ProcessRelation;
|
|
29
54
|
}
|
|
30
55
|
|
|
56
|
+
/** @internal */
|
|
31
57
|
export interface ResolveToolApprovalRequestBody {
|
|
58
|
+
/** @internal */
|
|
32
59
|
action: "accept" | "feedback" | "decline";
|
|
60
|
+
/** @internal */
|
|
33
61
|
feedback?: string;
|
|
34
62
|
}
|
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
} from "./http-contracts.js";
|
|
5
5
|
import type { PrimaryPathActiveTurnSnapshot } from "./primary-path-snapshot.js";
|
|
6
6
|
|
|
7
|
+
/** @internal */
|
|
7
8
|
export function timelinePresentationForTurnType(
|
|
8
9
|
turnType: ProcessTimelineTurnSummary["turnType"],
|
|
9
10
|
): ProcessTimelineTurnPresentation {
|
|
@@ -12,14 +13,18 @@ export function timelinePresentationForTurnType(
|
|
|
12
13
|
return turnType === "automatic" ? "automatic_turn" : "llm_turn";
|
|
13
14
|
}
|
|
14
15
|
|
|
16
|
+
/** @internal */
|
|
15
17
|
export function buildActiveTimelineTurnSummary(
|
|
16
18
|
activeTurn: Pick<
|
|
17
19
|
PrimaryPathActiveTurnSnapshot,
|
|
18
20
|
"turnRecordId" | "turnId" | "turnType" | "pathType" | "startedAt" | "assistant"
|
|
19
21
|
>,
|
|
20
22
|
input: {
|
|
23
|
+
/** @internal */
|
|
21
24
|
summary: string;
|
|
25
|
+
/** @internal */
|
|
22
26
|
output: string;
|
|
27
|
+
/** @internal */
|
|
23
28
|
actionSource?: ProcessTimelineTurnSummary["actionSource"];
|
|
24
29
|
} = { summary: `Current step: ${activeTurn.turnId}`, output: activeTurn.assistant.text.trim() },
|
|
25
30
|
): ProcessTimelineTurnSummary {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** @internal */
|
|
1
2
|
export function compareTimestampStrings(left: string, right: string): number {
|
|
2
3
|
const leftMs = Date.parse(left);
|
|
3
4
|
const rightMs = Date.parse(right);
|
|
@@ -7,6 +8,7 @@ export function compareTimestampStrings(left: string, right: string): number {
|
|
|
7
8
|
return left.localeCompare(right);
|
|
8
9
|
}
|
|
9
10
|
|
|
11
|
+
/** @internal */
|
|
10
12
|
export function happenedOnOrAfterStart(entryTimestamp: string, startedAt: string | null): boolean {
|
|
11
13
|
if (!startedAt) {
|
|
12
14
|
return true;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type {
|
|
2
|
+
ToolCallRendererDefinition,
|
|
3
|
+
ToolCallRendererFieldDefinition,
|
|
4
|
+
ToolCallRendererValueKind,
|
|
5
|
+
ToolCallRendererValueSource,
|
|
6
|
+
} from "./tool-renderer-contract.js";
|
|
7
|
+
export {
|
|
8
|
+
TOOL_CALL_RENDERER_VALUE_KINDS,
|
|
9
|
+
TOOL_CALL_RENDERER_VALUE_SOURCES,
|
|
10
|
+
} from "./tool-renderer-contract.js";
|
|
@@ -1,20 +1,34 @@
|
|
|
1
|
+
/** @internal */
|
|
1
2
|
export const TOOL_CALL_RENDERER_VALUE_KINDS = ["markdown", "plaintext", "json"] as const;
|
|
3
|
+
/** @internal */
|
|
2
4
|
export type ToolCallRendererValueKind = (typeof TOOL_CALL_RENDERER_VALUE_KINDS)[number];
|
|
3
5
|
|
|
6
|
+
/** @internal */
|
|
4
7
|
export const TOOL_CALL_RENDERER_VALUE_SOURCES = ["arguments", "result"] as const;
|
|
8
|
+
/** @internal */
|
|
5
9
|
export type ToolCallRendererValueSource = (typeof TOOL_CALL_RENDERER_VALUE_SOURCES)[number];
|
|
6
10
|
|
|
11
|
+
/** @internal */
|
|
7
12
|
export interface ToolCallRendererFieldDefinition {
|
|
13
|
+
/** @internal */
|
|
8
14
|
id: string;
|
|
15
|
+
/** @internal */
|
|
9
16
|
label: string;
|
|
17
|
+
/** @internal */
|
|
10
18
|
kind: ToolCallRendererValueKind;
|
|
19
|
+
/** @internal */
|
|
11
20
|
source: ToolCallRendererValueSource;
|
|
21
|
+
/** @internal */
|
|
12
22
|
path?: string;
|
|
13
23
|
}
|
|
14
24
|
|
|
25
|
+
/** @internal */
|
|
15
26
|
export interface ToolCallRendererDefinition {
|
|
27
|
+
/** @internal */
|
|
16
28
|
toolName: string;
|
|
29
|
+
/** @internal */
|
|
17
30
|
title?: string;
|
|
31
|
+
/** @internal */
|
|
18
32
|
fields: readonly ToolCallRendererFieldDefinition[];
|
|
19
33
|
}
|
|
20
34
|
|
|
@@ -22,6 +36,7 @@ import * as v from "valibot";
|
|
|
22
36
|
|
|
23
37
|
const unknownRecordSchema = v.record(v.string(), v.unknown());
|
|
24
38
|
|
|
39
|
+
/** @internal */
|
|
25
40
|
export function readValueAtPath(value: unknown, path: string | undefined): unknown {
|
|
26
41
|
if (!path || path.trim() === "") {
|
|
27
42
|
return value;
|
|
@@ -80,9 +80,13 @@ function isTruthyTruncationValue(value: unknown): boolean {
|
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
/** @internal */
|
|
83
84
|
export function isToolResultTruncated(input: {
|
|
85
|
+
/** @internal */
|
|
84
86
|
resultText: string | null;
|
|
87
|
+
/** @internal */
|
|
85
88
|
resultDetails: unknown;
|
|
89
|
+
/** @internal */
|
|
86
90
|
resultValue: unknown;
|
|
87
91
|
}): boolean {
|
|
88
92
|
const normalizedText = input.resultText?.toLowerCase() ?? "";
|
package/src/turn-continuation.ts
CHANGED
|
@@ -7,33 +7,51 @@ import {
|
|
|
7
7
|
import type { ReadonlyEntryTree } from "./session-entry-tree.js";
|
|
8
8
|
import { compareTimestampStrings, happenedOnOrAfterStart } from "./timestamp-ordering.js";
|
|
9
9
|
|
|
10
|
+
/** @internal */
|
|
10
11
|
export interface ContinuationTreeEntry {
|
|
12
|
+
/** @internal */
|
|
11
13
|
id: string;
|
|
14
|
+
/** @internal */
|
|
12
15
|
parentId: string | null;
|
|
16
|
+
/** @internal */
|
|
13
17
|
timestamp: string;
|
|
18
|
+
/** @internal */
|
|
14
19
|
type: string;
|
|
20
|
+
/** @internal */
|
|
15
21
|
message?: {
|
|
22
|
+
/** @internal */
|
|
16
23
|
role?: string;
|
|
24
|
+
/** @internal */
|
|
17
25
|
content?: unknown;
|
|
18
26
|
};
|
|
19
27
|
}
|
|
20
28
|
|
|
29
|
+
/** @internal */
|
|
21
30
|
export interface ContinuationTurnRecordLike {
|
|
31
|
+
/** @internal */
|
|
22
32
|
forkPiEntryId?: string | null;
|
|
33
|
+
/** @internal */
|
|
23
34
|
resultPiEntryId?: string | null;
|
|
35
|
+
/** @internal */
|
|
24
36
|
startedAt?: string | null;
|
|
37
|
+
/** @internal */
|
|
25
38
|
status?: string | null;
|
|
26
39
|
}
|
|
27
40
|
|
|
41
|
+
/** @internal */
|
|
28
42
|
export interface ContinuationSliceBounds {
|
|
43
|
+
/** @internal */
|
|
29
44
|
endedAt?: string | null;
|
|
30
45
|
}
|
|
31
46
|
|
|
47
|
+
/** @internal */
|
|
32
48
|
export interface TurnContinuationIndex<TEntry extends ContinuationTreeEntry> {
|
|
49
|
+
/** @internal */
|
|
33
50
|
resolveLeafEntryId(
|
|
34
51
|
turnRecord: ContinuationTurnRecordLike,
|
|
35
52
|
bounds?: ContinuationSliceBounds,
|
|
36
53
|
): string | null;
|
|
54
|
+
/** @internal */
|
|
37
55
|
buildSlice(turnRecord: ContinuationTurnRecordLike, bounds?: ContinuationSliceBounds): TEntry[];
|
|
38
56
|
}
|
|
39
57
|
|
|
@@ -139,6 +157,7 @@ function resolveTurnContinuationLeafEntryIdFromIndex(
|
|
|
139
157
|
});
|
|
140
158
|
}
|
|
141
159
|
|
|
160
|
+
/** @internal */
|
|
142
161
|
export function createTurnContinuationIndex<TEntry extends ContinuationTreeEntry>(
|
|
143
162
|
entries: readonly TEntry[],
|
|
144
163
|
): TurnContinuationIndex<TEntry> {
|
|
@@ -189,6 +208,7 @@ export function createTurnContinuationIndex<TEntry extends ContinuationTreeEntry
|
|
|
189
208
|
return { resolveLeafEntryId, buildSlice };
|
|
190
209
|
}
|
|
191
210
|
|
|
211
|
+
/** @internal */
|
|
192
212
|
export function resolveTurnContinuationLeafEntryId(
|
|
193
213
|
entries: readonly ContinuationTreeEntry[],
|
|
194
214
|
turnRecord: ContinuationTurnRecordLike,
|
|
@@ -197,6 +217,7 @@ export function resolveTurnContinuationLeafEntryId(
|
|
|
197
217
|
return createTurnContinuationIndex(entries).resolveLeafEntryId(turnRecord, bounds);
|
|
198
218
|
}
|
|
199
219
|
|
|
220
|
+
/** @internal */
|
|
200
221
|
export function buildTurnContinuationSliceFromTree<TEntry extends ContinuationTreeEntry>(
|
|
201
222
|
tree: ReadonlyEntryTree<TEntry>,
|
|
202
223
|
turnRecord: ContinuationTurnRecordLike,
|
|
@@ -205,6 +226,7 @@ export function buildTurnContinuationSliceFromTree<TEntry extends ContinuationTr
|
|
|
205
226
|
return createTurnContinuationIndex(tree.entries).buildSlice(turnRecord, bounds);
|
|
206
227
|
}
|
|
207
228
|
|
|
229
|
+
/** @internal */
|
|
208
230
|
export function buildTurnContinuationSlice<TEntry extends ContinuationTreeEntry>(
|
|
209
231
|
entries: readonly TEntry[],
|
|
210
232
|
turnRecord: ContinuationTurnRecordLike,
|
|
@@ -213,11 +235,15 @@ export function buildTurnContinuationSlice<TEntry extends ContinuationTreeEntry>
|
|
|
213
235
|
return createTurnContinuationIndex(entries).buildSlice(turnRecord, bounds);
|
|
214
236
|
}
|
|
215
237
|
|
|
238
|
+
/** @internal */
|
|
216
239
|
export interface BranchUserPromptSnapshot {
|
|
240
|
+
/** @internal */
|
|
217
241
|
text: string | null;
|
|
242
|
+
/** @internal */
|
|
218
243
|
createdAt: string | null;
|
|
219
244
|
}
|
|
220
245
|
|
|
246
|
+
/** @internal */
|
|
221
247
|
export function extractFirstUserPromptOnBranch<TEntry extends ContinuationTreeEntry>(
|
|
222
248
|
tree: ReadonlyEntryTree<TEntry>,
|
|
223
249
|
leafId: string | null | undefined,
|
|
@@ -243,6 +269,7 @@ export function extractFirstUserPromptOnBranch<TEntry extends ContinuationTreeEn
|
|
|
243
269
|
return { text: null, createdAt: null };
|
|
244
270
|
}
|
|
245
271
|
|
|
272
|
+
/** @internal */
|
|
246
273
|
export function resolveTurnContinuationUserPrompt(
|
|
247
274
|
entries: readonly ContinuationTreeEntry[],
|
|
248
275
|
turnRecord: ContinuationTurnRecordLike,
|
|
@@ -265,6 +292,7 @@ export function resolveTurnContinuationUserPrompt(
|
|
|
265
292
|
return promptText !== "" ? promptText : null;
|
|
266
293
|
}
|
|
267
294
|
|
|
295
|
+
/** @internal */
|
|
268
296
|
export function hasTurnContinuationProgress(
|
|
269
297
|
entries: readonly ContinuationTreeEntry[],
|
|
270
298
|
turnRecord: ContinuationTurnRecordLike,
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
import { extractPiSessionMessageText } from "./pi-session-message.js";
|
|
7
7
|
import { isToolResultTruncated } from "./tool-result-truncation.js";
|
|
8
8
|
|
|
9
|
-
/** Share the recorded tool content presentation between live HTTP history and live frames. */
|
|
9
|
+
/** Share the recorded tool content presentation between live HTTP history and live frames. @internal */
|
|
10
10
|
export function snapshotTurnTrace(
|
|
11
11
|
projection: MutableLiveTurnProjection,
|
|
12
12
|
piInput: TurnTraceSnapshot["piInput"] = null,
|
|
@@ -6,8 +6,10 @@ import {
|
|
|
6
6
|
} from "./usage-snapshot.js";
|
|
7
7
|
import { asWsEventPayloadRecord, readWsEventTurnRecordId } from "./ws-event-payloads.js";
|
|
8
8
|
|
|
9
|
+
/** @internal */
|
|
9
10
|
export type UsageSnapshotByTurnRecordId = Record<string, UsageSnapshot>;
|
|
10
11
|
|
|
12
|
+
/** @internal */
|
|
11
13
|
export function buildUsageSnapshotsByTurnRecordId(
|
|
12
14
|
events: readonly ProcessEvent[],
|
|
13
15
|
): UsageSnapshotByTurnRecordId {
|
package/src/usage-snapshot.ts
CHANGED
|
@@ -1,29 +1,43 @@
|
|
|
1
1
|
import { copiedUnknownRecordSchema as unknownRecordSchema } from "@leitwerk-dev/domain";
|
|
2
2
|
import * as v from "valibot";
|
|
3
3
|
|
|
4
|
+
/** @internal */
|
|
4
5
|
export interface UsageCostSnapshot {
|
|
6
|
+
/** @internal */
|
|
5
7
|
input: number;
|
|
8
|
+
/** @internal */
|
|
6
9
|
output: number;
|
|
10
|
+
/** @internal */
|
|
7
11
|
cacheRead: number;
|
|
12
|
+
/** @internal */
|
|
8
13
|
cacheWrite: number;
|
|
14
|
+
/** @internal */
|
|
9
15
|
total: number;
|
|
10
16
|
}
|
|
11
17
|
|
|
18
|
+
/** @internal */
|
|
12
19
|
export interface UsageTokenCounts {
|
|
20
|
+
/** @internal */
|
|
13
21
|
input: number;
|
|
22
|
+
/** @internal */
|
|
14
23
|
output: number;
|
|
15
|
-
/** Provider-reported reasoning/thinking tokens. This is a subset of output tokens. */
|
|
24
|
+
/** Provider-reported reasoning/thinking tokens. This is a subset of output tokens. @internal */
|
|
16
25
|
reasoning?: number;
|
|
26
|
+
/** @internal */
|
|
17
27
|
cacheRead: number;
|
|
28
|
+
/** @internal */
|
|
18
29
|
cacheWrite: number;
|
|
30
|
+
/** @internal */
|
|
19
31
|
totalTokens: number;
|
|
20
32
|
}
|
|
21
33
|
|
|
34
|
+
/** @internal */
|
|
22
35
|
export interface UsageSnapshot extends UsageTokenCounts {
|
|
36
|
+
/** @internal */
|
|
23
37
|
cost: UsageCostSnapshot | null;
|
|
24
|
-
/** Number of model requests represented by this aggregate, when known. */
|
|
38
|
+
/** Number of model requests represented by this aggregate, when known. @internal */
|
|
25
39
|
requestCount?: number;
|
|
26
|
-
/** Largest input-token count for a single represented model request, when known. */
|
|
40
|
+
/** Largest input-token count for a single represented model request, when known. @internal */
|
|
27
41
|
maxInputTokens?: number;
|
|
28
42
|
}
|
|
29
43
|
|
|
@@ -50,6 +64,7 @@ function normalizeUsageCostSnapshot(value: unknown): UsageCostSnapshot | null {
|
|
|
50
64
|
};
|
|
51
65
|
}
|
|
52
66
|
|
|
67
|
+
/** @internal */
|
|
53
68
|
export function cloneUsageSnapshot(usage: UsageSnapshot | null | undefined): UsageSnapshot | null {
|
|
54
69
|
if (!usage) {
|
|
55
70
|
return null;
|
|
@@ -60,6 +75,7 @@ export function cloneUsageSnapshot(usage: UsageSnapshot | null | undefined): Usa
|
|
|
60
75
|
};
|
|
61
76
|
}
|
|
62
77
|
|
|
78
|
+
/** @internal */
|
|
63
79
|
export function normalizeUsageSnapshot(value: unknown): UsageSnapshot | null {
|
|
64
80
|
const parsedValue = v.safeParse(unknownRecordSchema, value);
|
|
65
81
|
if (!parsedValue.success) {
|
|
@@ -93,6 +109,7 @@ export function normalizeUsageSnapshot(value: unknown): UsageSnapshot | null {
|
|
|
93
109
|
};
|
|
94
110
|
}
|
|
95
111
|
|
|
112
|
+
/** @internal */
|
|
96
113
|
export function mergeUsageSnapshots(
|
|
97
114
|
total: UsageSnapshot | null,
|
|
98
115
|
usage: UsageSnapshot | null,
|
package/src/ws-event-payloads.ts
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
import { asUnknownRecord, trimToNull as readWsEventNonEmptyString } from "@leitwerk-dev/domain";
|
|
2
2
|
|
|
3
|
+
/** @internal */
|
|
3
4
|
export interface WsEventPayloadRecord extends Record<string, unknown> {}
|
|
4
5
|
|
|
6
|
+
/** @internal */
|
|
5
7
|
export interface ResolveWsEventToolCallIdOptions {
|
|
8
|
+
/** @internal */
|
|
6
9
|
timestamp: string;
|
|
10
|
+
/** @internal */
|
|
7
11
|
toolName?: string;
|
|
12
|
+
/** @internal */
|
|
8
13
|
ordinal?: number;
|
|
9
14
|
}
|
|
10
15
|
|
|
16
|
+
/** @internal */
|
|
11
17
|
export function asWsEventPayloadRecord(value: unknown): WsEventPayloadRecord {
|
|
12
18
|
return asUnknownRecord(value) ?? {};
|
|
13
19
|
}
|
|
14
20
|
|
|
15
21
|
export { readWsEventNonEmptyString };
|
|
16
22
|
|
|
23
|
+
/** @internal */
|
|
17
24
|
export function readWsEventTimestamp(
|
|
18
25
|
data: WsEventPayloadRecord,
|
|
19
26
|
fallbackTimestamp: string,
|
|
@@ -21,14 +28,17 @@ export function readWsEventTimestamp(
|
|
|
21
28
|
return readWsEventNonEmptyString(data.timestamp) ?? fallbackTimestamp;
|
|
22
29
|
}
|
|
23
30
|
|
|
31
|
+
/** @internal */
|
|
24
32
|
export function readWsEventTurnRecordId(data: WsEventPayloadRecord): string | null {
|
|
25
33
|
return readWsEventNonEmptyString(data.turnRecordId);
|
|
26
34
|
}
|
|
27
35
|
|
|
36
|
+
/** @internal */
|
|
28
37
|
export function readWsEventPiTurnId(data: WsEventPayloadRecord): string | null {
|
|
29
38
|
return readWsEventNonEmptyString(data.turnId);
|
|
30
39
|
}
|
|
31
40
|
|
|
41
|
+
/** @internal */
|
|
32
42
|
export function readWsEventStreamText(data: WsEventPayloadRecord): string | null {
|
|
33
43
|
return typeof data.text === "string"
|
|
34
44
|
? data.text
|
|
@@ -39,20 +49,24 @@ export function readWsEventStreamText(data: WsEventPayloadRecord): string | null
|
|
|
39
49
|
: null;
|
|
40
50
|
}
|
|
41
51
|
|
|
52
|
+
/** @internal */
|
|
42
53
|
export function readWsEventToolName(data: WsEventPayloadRecord): string {
|
|
43
54
|
return readWsEventNonEmptyString(data.name) ?? readWsEventNonEmptyString(data.toolName) ?? "tool";
|
|
44
55
|
}
|
|
45
56
|
|
|
57
|
+
/** @internal */
|
|
46
58
|
export function readWsEventToolArguments(
|
|
47
59
|
data: WsEventPayloadRecord,
|
|
48
60
|
): Record<string, unknown> | null {
|
|
49
61
|
return asUnknownRecord(data.arguments ?? data.args);
|
|
50
62
|
}
|
|
51
63
|
|
|
64
|
+
/** @internal */
|
|
52
65
|
export function readWsEventToolCallId(data: WsEventPayloadRecord): string | null {
|
|
53
66
|
return readWsEventNonEmptyString(data.toolCallId);
|
|
54
67
|
}
|
|
55
68
|
|
|
69
|
+
/** @internal */
|
|
56
70
|
export function resolveWsEventToolCallId(
|
|
57
71
|
data: WsEventPayloadRecord,
|
|
58
72
|
options: ResolveWsEventToolCallIdOptions,
|
package/dist/chunk-6L4W7WPV.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=chunk-6L4W7WPV.js.map
|
package/dist/chunk-AAV3AAOF.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=chunk-AAV3AAOF.js.map
|
package/dist/chunk-IEMT3JG4.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=chunk-IEMT3JG4.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/tool-renderer-contract.ts"],"sourcesContent":["export const TOOL_CALL_RENDERER_VALUE_KINDS = [\"markdown\", \"plaintext\", \"json\"] as const;\nexport type ToolCallRendererValueKind = (typeof TOOL_CALL_RENDERER_VALUE_KINDS)[number];\n\nexport const TOOL_CALL_RENDERER_VALUE_SOURCES = [\"arguments\", \"result\"] as const;\nexport type ToolCallRendererValueSource = (typeof TOOL_CALL_RENDERER_VALUE_SOURCES)[number];\n\nexport interface ToolCallRendererFieldDefinition {\n\tid: string;\n\tlabel: string;\n\tkind: ToolCallRendererValueKind;\n\tsource: ToolCallRendererValueSource;\n\tpath?: string;\n}\n\nexport interface ToolCallRendererDefinition {\n\ttoolName: string;\n\ttitle?: string;\n\tfields: readonly ToolCallRendererFieldDefinition[];\n}\n\nimport * as v from \"valibot\";\n\nconst unknownRecordSchema = v.record(v.string(), v.unknown());\n\nexport function readValueAtPath(value: unknown, path: string | undefined): unknown {\n\tif (!path || path.trim() === \"\") {\n\t\treturn value;\n\t}\n\tlet current: unknown = value;\n\tfor (const segment of path\n\t\t.split(\".\")\n\t\t.map((part) => part.trim())\n\t\t.filter(Boolean)) {\n\t\tconst parsedCurrent = v.safeParse(unknownRecordSchema, current);\n\t\tif (!parsedCurrent.success || !(segment in parsedCurrent.output)) {\n\t\t\treturn undefined;\n\t\t}\n\t\tcurrent = parsedCurrent.output[segment];\n\t}\n\treturn current;\n}\n"],"mappings":";AAoBA,YAAY,OAAO;AApBZ,IAAM,iCAAiC,CAAC,YAAY,aAAa,MAAM;AAGvE,IAAM,mCAAmC,CAAC,aAAa,QAAQ;AAmBtE,IAAM,sBAAwB,SAAS,SAAO,GAAK,UAAQ,CAAC;AAErD,SAAS,gBAAgB,OAAgB,MAAmC;AAClF,MAAI,CAAC,QAAQ,KAAK,KAAK,MAAM,IAAI;AAChC,WAAO;AAAA,EACR;AACA,MAAI,UAAmB;AACvB,aAAW,WAAW,KACpB,MAAM,GAAG,EACT,IAAI,CAAC,SAAS,KAAK,KAAK,CAAC,EACzB,OAAO,OAAO,GAAG;AAClB,UAAM,gBAAkB,YAAU,qBAAqB,OAAO;AAC9D,QAAI,CAAC,cAAc,WAAW,EAAE,WAAW,cAAc,SAAS;AACjE,aAAO;AAAA,IACR;AACA,cAAU,cAAc,OAAO,OAAO;AAAA,EACvC;AACA,SAAO;AACR;","names":[]}
|