@agentic-kit/run-log 0.7.0 → 0.8.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/esm/index.d.ts CHANGED
@@ -20,7 +20,7 @@ export { type AppendOptions, cursorAfter, MemoryRunLogStore, type RunLogAppendSt
20
20
  export { assertTranscriptEntry, type TranscriptEntry } from './transcripts/entry';
21
21
  export { type BashEvent, type CustomEvent, type ModelResponseEvent, type SessionStartEvent, type SummaryEvent, type TextEvent, type ThinkingEvent, type ToolCallEvent, type ToolResultEvent, type TranscriptEvent, type TranscriptEventBase, type TranscriptUsage, type UnknownEvent } from './transcripts/event';
22
22
  export { assertTranscriptFormat, PI_TRANSCRIPT_FORMAT, SUPPORTED_PI_TRANSCRIPT_VERSION, type TranscriptFormat } from './transcripts/format';
23
- export { assertPiSessionEntry, contentText, isAssistantMessage, isPiBranchSummaryEntry, isPiCompactionEntry, isPiMessageEntry, isPiSessionHeader, isToolResultMessage, type PiAssistantMessage, type PiBashExecutionMessage, type PiBranchSummaryEntry, type PiCompactionEntry, type PiContent, type PiCustomMessage, type PiEntryBase, type PiImageContent, type PiMessage, type PiMessageEntry, type PiOtherEntry, type PiSessionEntry, type PiSessionHeader, type PiSummaryMessage, type PiTextContent, type PiThinkingContent, type PiToolCallContent, type PiToolResultMessage, type PiUsage, type PiUsageCost, type PiUserMessage, toolCalls } from './transcripts/pi-entry';
23
+ export { assertPiSessionEntry, contentText, isAssistantMessage, isPiBranchSummaryEntry, isPiCompactionEntry, isPiMessageEntry, isPiSessionHeader, isToolResultMessage, type PiAssistantMessage, type PiBashExecutionMessage, type PiBranchSummaryEntry, type PiCompactionEntry, type PiContent, type PiCustomMessage, type PiEntryBase, type PiImageContent, type PiMessage, type PiMessageEntry, type PiOtherEntry, type PiSessionEntry, type PiSessionHeader, type PiSummaryMessage, type PiSystemMessage, type PiTextContent, type PiThinkingContent, type PiToolCallContent, type PiToolDeclaration, type PiToolResultMessage, type PiUsage, type PiUsageCost, type PiUserMessage, toolCalls } from './transcripts/pi-entry';
24
24
  export { piEntryToEvents, piTranscriptReader } from './transcripts/pi-reader';
25
25
  export { passthroughReader, type TranscriptReader, TranscriptReaderRegistry } from './transcripts/reader';
26
26
  export { defaultTranscriptReaders, transcriptReaders } from './transcripts/registry';
@@ -31,6 +31,12 @@ const close = (span, seq, at) => {
31
31
  if (duration !== undefined)
32
32
  span.durationMs = duration;
33
33
  };
34
+ /** A pending or deferred response has not arrived yet, so its turn has not ended. */
35
+ const modelStatus = (stopReason) => {
36
+ if (stopReason === 'pending' || stopReason === 'deferred')
37
+ return 'open';
38
+ return stopReason === 'error' ? 'error' : 'ok';
39
+ };
34
40
  const detailsOf = (value) => typeof value === 'object' && value !== null ? value : {};
35
41
  const firstTimestamp = (events) => events.find((event) => typeof event.at === 'string')?.at;
36
42
  /**
@@ -67,10 +73,8 @@ export function projectSpans(records, options = {}) {
67
73
  // no previous entry the interval is unknown and the span is a point.
68
74
  startedAt: previous ?? at,
69
75
  startSeq: seq,
70
- endSeq: seq,
71
- endedAt: at,
72
76
  timing: 'bounded',
73
- status: event.stopReason === 'error' ? 'error' : 'ok',
77
+ status: modelStatus(event.stopReason),
74
78
  ...(event.model ? { model: event.model } : {}),
75
79
  ...(event.provider ? { provider: event.provider } : {}),
76
80
  ...(event.responseId ? { responseId: event.responseId } : {}),
@@ -78,9 +82,8 @@ export function projectSpans(records, options = {}) {
78
82
  ...(event.usage ? { usage: event.usage } : {}),
79
83
  ...(event.errorMessage ? { errorMessage: event.errorMessage } : {})
80
84
  };
81
- const duration = ms(span.startedAt, at);
82
- if (duration !== undefined)
83
- span.durationMs = duration;
85
+ if (span.status !== 'open')
86
+ close(span, seq, at);
84
87
  modelSpan = span;
85
88
  spans.push(span);
86
89
  continue;
@@ -47,6 +47,24 @@ export interface PiToolCallContent {
47
47
  arguments?: Record<string, unknown>;
48
48
  }
49
49
  export type PiContent = PiTextContent | PiThinkingContent | PiImageContent | PiToolCallContent;
50
+ export interface PiToolDeclaration {
51
+ name: string;
52
+ [key: string]: unknown;
53
+ }
54
+ /**
55
+ * The prompt and tool loadout. The first request of a session persists one with
56
+ * every section and tool; later ones patch `sections` by name (`null` removes
57
+ * one) and list the tools added or removed.
58
+ */
59
+ export interface PiSystemMessage {
60
+ role: 'system';
61
+ content: string | PiTextContent[];
62
+ sections?: Record<string, string | null>;
63
+ toolsAdded?: PiToolDeclaration[];
64
+ toolsRemoved?: PiToolDeclaration[];
65
+ timestamp?: number;
66
+ [key: string]: unknown;
67
+ }
50
68
  export interface PiUserMessage {
51
69
  role: 'user';
52
70
  content: string | PiContent[];
@@ -60,7 +78,7 @@ export interface PiAssistantMessage {
60
78
  provider?: string;
61
79
  model?: string;
62
80
  usage?: PiUsage;
63
- stopReason?: 'stop' | 'length' | 'toolUse' | 'error' | 'aborted';
81
+ stopReason?: 'pending' | 'stop' | 'length' | 'toolUse' | 'error' | 'aborted' | 'deferred';
64
82
  errorMessage?: string;
65
83
  timestamp?: number;
66
84
  [key: string]: unknown;
@@ -101,7 +119,7 @@ export interface PiSummaryMessage {
101
119
  timestamp?: number;
102
120
  [key: string]: unknown;
103
121
  }
104
- export type PiMessage = PiUserMessage | PiAssistantMessage | PiToolResultMessage | PiBashExecutionMessage | PiCustomMessage | PiSummaryMessage;
122
+ export type PiMessage = PiSystemMessage | PiUserMessage | PiAssistantMessage | PiToolResultMessage | PiBashExecutionMessage | PiCustomMessage | PiSummaryMessage;
105
123
  export interface PiSessionHeader {
106
124
  type: 'session';
107
125
  version: number;
@@ -40,6 +40,9 @@ export function piEntryToEvents(entry) {
40
40
  return [{ kind: 'unknown', entryType: pi.type, entry, ...base }];
41
41
  }
42
42
  const message = pi.message;
43
+ // The full prompt and tool schemas: context for the model, not part of the transcript.
44
+ if (message.role === 'system')
45
+ return [];
43
46
  if (message.role === 'user') {
44
47
  return [{ kind: 'text', role: 'user', text: contentText(message.content), ...base }];
45
48
  }
package/index.d.ts CHANGED
@@ -20,7 +20,7 @@ export { type AppendOptions, cursorAfter, MemoryRunLogStore, type RunLogAppendSt
20
20
  export { assertTranscriptEntry, type TranscriptEntry } from './transcripts/entry';
21
21
  export { type BashEvent, type CustomEvent, type ModelResponseEvent, type SessionStartEvent, type SummaryEvent, type TextEvent, type ThinkingEvent, type ToolCallEvent, type ToolResultEvent, type TranscriptEvent, type TranscriptEventBase, type TranscriptUsage, type UnknownEvent } from './transcripts/event';
22
22
  export { assertTranscriptFormat, PI_TRANSCRIPT_FORMAT, SUPPORTED_PI_TRANSCRIPT_VERSION, type TranscriptFormat } from './transcripts/format';
23
- export { assertPiSessionEntry, contentText, isAssistantMessage, isPiBranchSummaryEntry, isPiCompactionEntry, isPiMessageEntry, isPiSessionHeader, isToolResultMessage, type PiAssistantMessage, type PiBashExecutionMessage, type PiBranchSummaryEntry, type PiCompactionEntry, type PiContent, type PiCustomMessage, type PiEntryBase, type PiImageContent, type PiMessage, type PiMessageEntry, type PiOtherEntry, type PiSessionEntry, type PiSessionHeader, type PiSummaryMessage, type PiTextContent, type PiThinkingContent, type PiToolCallContent, type PiToolResultMessage, type PiUsage, type PiUsageCost, type PiUserMessage, toolCalls } from './transcripts/pi-entry';
23
+ export { assertPiSessionEntry, contentText, isAssistantMessage, isPiBranchSummaryEntry, isPiCompactionEntry, isPiMessageEntry, isPiSessionHeader, isToolResultMessage, type PiAssistantMessage, type PiBashExecutionMessage, type PiBranchSummaryEntry, type PiCompactionEntry, type PiContent, type PiCustomMessage, type PiEntryBase, type PiImageContent, type PiMessage, type PiMessageEntry, type PiOtherEntry, type PiSessionEntry, type PiSessionHeader, type PiSummaryMessage, type PiSystemMessage, type PiTextContent, type PiThinkingContent, type PiToolCallContent, type PiToolDeclaration, type PiToolResultMessage, type PiUsage, type PiUsageCost, type PiUserMessage, toolCalls } from './transcripts/pi-entry';
24
24
  export { piEntryToEvents, piTranscriptReader } from './transcripts/pi-reader';
25
25
  export { passthroughReader, type TranscriptReader, TranscriptReaderRegistry } from './transcripts/reader';
26
26
  export { defaultTranscriptReaders, transcriptReaders } from './transcripts/registry';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentic-kit/run-log",
3
- "version": "0.7.0",
3
+ "version": "0.8.1",
4
4
  "author": "Constructive <developers@constructive.io>",
5
5
  "description": "The append-only agent run log — pi session entries stored verbatim under a run/seq wrapper, with projections for transcript, usage, tool state and resumable sessions",
6
6
  "main": "index.js",
@@ -35,5 +35,5 @@
35
35
  "run-log",
36
36
  "constructive"
37
37
  ],
38
- "gitHead": "baa84094b8541eb5000701b0060aa5b298032dc7"
38
+ "gitHead": "08e422d3cbe4bc9c39b3194f923b3ded0de282dd"
39
39
  }
@@ -34,6 +34,12 @@ const close = (span, seq, at) => {
34
34
  if (duration !== undefined)
35
35
  span.durationMs = duration;
36
36
  };
37
+ /** A pending or deferred response has not arrived yet, so its turn has not ended. */
38
+ const modelStatus = (stopReason) => {
39
+ if (stopReason === 'pending' || stopReason === 'deferred')
40
+ return 'open';
41
+ return stopReason === 'error' ? 'error' : 'ok';
42
+ };
37
43
  const detailsOf = (value) => typeof value === 'object' && value !== null ? value : {};
38
44
  const firstTimestamp = (events) => events.find((event) => typeof event.at === 'string')?.at;
39
45
  /**
@@ -70,10 +76,8 @@ function projectSpans(records, options = {}) {
70
76
  // no previous entry the interval is unknown and the span is a point.
71
77
  startedAt: previous ?? at,
72
78
  startSeq: seq,
73
- endSeq: seq,
74
- endedAt: at,
75
79
  timing: 'bounded',
76
- status: event.stopReason === 'error' ? 'error' : 'ok',
80
+ status: modelStatus(event.stopReason),
77
81
  ...(event.model ? { model: event.model } : {}),
78
82
  ...(event.provider ? { provider: event.provider } : {}),
79
83
  ...(event.responseId ? { responseId: event.responseId } : {}),
@@ -81,9 +85,8 @@ function projectSpans(records, options = {}) {
81
85
  ...(event.usage ? { usage: event.usage } : {}),
82
86
  ...(event.errorMessage ? { errorMessage: event.errorMessage } : {})
83
87
  };
84
- const duration = ms(span.startedAt, at);
85
- if (duration !== undefined)
86
- span.durationMs = duration;
88
+ if (span.status !== 'open')
89
+ close(span, seq, at);
87
90
  modelSpan = span;
88
91
  spans.push(span);
89
92
  continue;
@@ -47,6 +47,24 @@ export interface PiToolCallContent {
47
47
  arguments?: Record<string, unknown>;
48
48
  }
49
49
  export type PiContent = PiTextContent | PiThinkingContent | PiImageContent | PiToolCallContent;
50
+ export interface PiToolDeclaration {
51
+ name: string;
52
+ [key: string]: unknown;
53
+ }
54
+ /**
55
+ * The prompt and tool loadout. The first request of a session persists one with
56
+ * every section and tool; later ones patch `sections` by name (`null` removes
57
+ * one) and list the tools added or removed.
58
+ */
59
+ export interface PiSystemMessage {
60
+ role: 'system';
61
+ content: string | PiTextContent[];
62
+ sections?: Record<string, string | null>;
63
+ toolsAdded?: PiToolDeclaration[];
64
+ toolsRemoved?: PiToolDeclaration[];
65
+ timestamp?: number;
66
+ [key: string]: unknown;
67
+ }
50
68
  export interface PiUserMessage {
51
69
  role: 'user';
52
70
  content: string | PiContent[];
@@ -60,7 +78,7 @@ export interface PiAssistantMessage {
60
78
  provider?: string;
61
79
  model?: string;
62
80
  usage?: PiUsage;
63
- stopReason?: 'stop' | 'length' | 'toolUse' | 'error' | 'aborted';
81
+ stopReason?: 'pending' | 'stop' | 'length' | 'toolUse' | 'error' | 'aborted' | 'deferred';
64
82
  errorMessage?: string;
65
83
  timestamp?: number;
66
84
  [key: string]: unknown;
@@ -101,7 +119,7 @@ export interface PiSummaryMessage {
101
119
  timestamp?: number;
102
120
  [key: string]: unknown;
103
121
  }
104
- export type PiMessage = PiUserMessage | PiAssistantMessage | PiToolResultMessage | PiBashExecutionMessage | PiCustomMessage | PiSummaryMessage;
122
+ export type PiMessage = PiSystemMessage | PiUserMessage | PiAssistantMessage | PiToolResultMessage | PiBashExecutionMessage | PiCustomMessage | PiSummaryMessage;
105
123
  export interface PiSessionHeader {
106
124
  type: 'session';
107
125
  version: number;
@@ -44,6 +44,9 @@ function piEntryToEvents(entry) {
44
44
  return [{ kind: 'unknown', entryType: pi.type, entry, ...base }];
45
45
  }
46
46
  const message = pi.message;
47
+ // The full prompt and tool schemas: context for the model, not part of the transcript.
48
+ if (message.role === 'system')
49
+ return [];
47
50
  if (message.role === 'user') {
48
51
  return [{ kind: 'text', role: 'user', text: (0, pi_entry_1.contentText)(message.content), ...base }];
49
52
  }