@qlairoslabs/acp-client 0.6.0 → 0.7.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/CONSUMER_GUIDE.md +618 -291
- package/README.md +25 -0
- package/package.json +1 -1
- package/src/agent-session.ts +2188 -96
- package/src/cli/index.ts +33 -5
- package/src/cli/managed.ts +220 -0
- package/src/command-descriptors.ts +22 -0
- package/src/controller.ts +87 -37
- package/src/index.ts +229 -3
- package/src/metering/engine.ts +9 -1
- package/src/metering/record.ts +2 -1
- package/src/persistence/activity-projection.ts +71 -0
- package/src/persistence/audit-log-reader.ts +506 -0
- package/src/persistence/audit-runtime.ts +162 -0
- package/src/persistence/checkpoint.ts +304 -0
- package/src/persistence/config.ts +538 -0
- package/src/persistence/configuration-state.ts +191 -0
- package/src/persistence/deletion.ts +227 -0
- package/src/persistence/file-registry-store.ts +740 -0
- package/src/persistence/integrity.ts +147 -0
- package/src/persistence/legacy-registry-import.ts +240 -0
- package/src/persistence/managed-checkpoint.ts +81 -0
- package/src/persistence/managed-creation.ts +456 -0
- package/src/persistence/managed-load.ts +172 -0
- package/src/persistence/managed-registry.ts +57 -0
- package/src/persistence/migration.ts +298 -0
- package/src/persistence/paths.ts +172 -0
- package/src/persistence/projection.ts +373 -0
- package/src/persistence/reconfiguration.ts +453 -0
- package/src/persistence/records.ts +873 -0
- package/src/persistence/reducer.ts +498 -0
- package/src/persistence/registry.ts +446 -0
- package/src/persistence/restoration.ts +689 -0
- package/src/persistence/session-log-writer.ts +480 -0
- package/src/persistence/state-runtime.ts +176 -0
- package/src/persistence/transcript-reader.ts +980 -0
- package/src/persistence/transcript-runtime.ts +667 -0
- package/src/persistence/transcript-scanner.ts +385 -0
- package/src/persistence/truncation.ts +276 -0
- package/src/repl/agent-session-commands.ts +74 -1
- package/src/repl/commands.ts +1 -1
- package/src/repl/index.ts +7 -1
- package/src/session-manager.ts +257 -7
- package/src/transcript.ts +3 -3
package/src/index.ts
CHANGED
|
@@ -24,6 +24,7 @@ export {
|
|
|
24
24
|
parseJsonOrString,
|
|
25
25
|
formatConfigValue,
|
|
26
26
|
} from "./controller.ts";
|
|
27
|
+
export type { CommandArgumentDescriptor, CommandDescriptor } from "./command-descriptors.ts";
|
|
27
28
|
export type {
|
|
28
29
|
AgentControllerConfig,
|
|
29
30
|
AgentMode,
|
|
@@ -33,9 +34,18 @@ export type {
|
|
|
33
34
|
SetConfigFromStringResult,
|
|
34
35
|
} from "./controller.ts";
|
|
35
36
|
|
|
36
|
-
export {
|
|
37
|
+
export {
|
|
38
|
+
AgentSession,
|
|
39
|
+
AgentSessionPromptBlockedError,
|
|
40
|
+
AdapterMismatchError,
|
|
41
|
+
ContinuationUnavailableError,
|
|
42
|
+
DirectAuditPersistenceUnsupportedError,
|
|
43
|
+
} from "./agent-session.ts";
|
|
37
44
|
export type {
|
|
38
45
|
AgentSessionConfig,
|
|
46
|
+
AgentSessionOpenConfig,
|
|
47
|
+
AgentSessionOpenResult,
|
|
48
|
+
AgentSessionPromptability,
|
|
39
49
|
TranscriptActivityConfig,
|
|
40
50
|
AgentSessionPhase,
|
|
41
51
|
AgentSessionState,
|
|
@@ -46,6 +56,18 @@ export type {
|
|
|
46
56
|
HandoffOptions,
|
|
47
57
|
HandoffResult,
|
|
48
58
|
ProviderSession,
|
|
59
|
+
ConfigurationRestoreStatus,
|
|
60
|
+
ConfigurationMismatchResolution,
|
|
61
|
+
ConfigurationMismatchResolutionResult,
|
|
62
|
+
AgentSessionRecoveryResolution,
|
|
63
|
+
AgentSessionRecoveryResolutionResult,
|
|
64
|
+
ContinuationAttempt,
|
|
65
|
+
ContinuationReport,
|
|
66
|
+
ContinuationStrategy,
|
|
67
|
+
OpenContinuationOptions,
|
|
68
|
+
TranscriptContinuationBuilder,
|
|
69
|
+
TranscriptContinuationBuilderContext,
|
|
70
|
+
PromptBlocker,
|
|
49
71
|
} from "./agent-session.ts";
|
|
50
72
|
|
|
51
73
|
export type {
|
|
@@ -104,8 +126,22 @@ export {
|
|
|
104
126
|
defaultSessionsDir,
|
|
105
127
|
} from "./session-store.ts";
|
|
106
128
|
export type { SessionStore, SessionRecord } from "./session-store.ts";
|
|
107
|
-
export { SessionManager, mergeSessions } from "./session-manager.ts";
|
|
108
|
-
export type { MergedSession, SessionInput } from "./session-manager.ts";
|
|
129
|
+
export { SessionManager, SessionManagerModeError, mergeSessions } from "./session-manager.ts";
|
|
130
|
+
export type { MergedSession, SessionInput, SessionManagerConfig } from "./session-manager.ts";
|
|
131
|
+
export {
|
|
132
|
+
ManagedAgentSessionAuthorityConflictError,
|
|
133
|
+
ManagedAgentSessionDeletedError,
|
|
134
|
+
ManagedAgentSessionNotFoundError,
|
|
135
|
+
} from "./persistence/managed-load.ts";
|
|
136
|
+
export type { ManagedAgentSessionLoadConfig } from "./persistence/managed-load.ts";
|
|
137
|
+
export type {
|
|
138
|
+
GetAgentSessionCheckpointOptions,
|
|
139
|
+
ResolvedAgentSessionCheckpoint,
|
|
140
|
+
} from "./persistence/managed-checkpoint.ts";
|
|
141
|
+
export { AgentSessionPersistenceReconfigurationError } from "./persistence/reconfiguration.ts";
|
|
142
|
+
export type { ReconfigureAgentSessionPersistenceOptions } from "./persistence/reconfiguration.ts";
|
|
143
|
+
export { AgentSessionRestorationError } from "./persistence/restoration.ts";
|
|
144
|
+
export type { RestoreAgentSessionOptions } from "./persistence/restoration.ts";
|
|
109
145
|
|
|
110
146
|
export {
|
|
111
147
|
appendTranscriptLine,
|
|
@@ -127,6 +163,196 @@ export type {
|
|
|
127
163
|
TranscriptRole,
|
|
128
164
|
} from "./transcript.ts";
|
|
129
165
|
|
|
166
|
+
export {
|
|
167
|
+
PersistenceConfigurationError,
|
|
168
|
+
} from "./persistence/config.ts";
|
|
169
|
+
export type {
|
|
170
|
+
AgentSessionPersistenceOptions,
|
|
171
|
+
AuditLogCapturePolicy,
|
|
172
|
+
AuditLogConfig,
|
|
173
|
+
ManagedSessionPersistenceOptions,
|
|
174
|
+
PersistenceLimits,
|
|
175
|
+
SessionConfigurationPersistenceConfig,
|
|
176
|
+
SessionPersistenceConstraints,
|
|
177
|
+
TranscriptCapturePolicy,
|
|
178
|
+
TranscriptConfig,
|
|
179
|
+
TranscriptPreset,
|
|
180
|
+
} from "./persistence/config.ts";
|
|
181
|
+
export {
|
|
182
|
+
PersistenceSerializationError,
|
|
183
|
+
checkpointDigest,
|
|
184
|
+
checkpointDigestMatches,
|
|
185
|
+
} from "./persistence/integrity.ts";
|
|
186
|
+
export type { PersistedMachineCode } from "./persistence/integrity.ts";
|
|
187
|
+
export {
|
|
188
|
+
CheckpointValidationError,
|
|
189
|
+
createAgentSessionCheckpoint,
|
|
190
|
+
validateAgentSessionCheckpoint,
|
|
191
|
+
} from "./persistence/checkpoint.ts";
|
|
192
|
+
export type {
|
|
193
|
+
AgentSessionBoundary,
|
|
194
|
+
AgentSessionCheckpoint,
|
|
195
|
+
AgentSessionCheckpointInput,
|
|
196
|
+
CheckpointIdentityExpectation,
|
|
197
|
+
JsonObject,
|
|
198
|
+
JsonValue,
|
|
199
|
+
PersistedProtocol,
|
|
200
|
+
PersistedSessionConfigSelection,
|
|
201
|
+
SessionConfigurationCheckpoint,
|
|
202
|
+
TransitionKind,
|
|
203
|
+
} from "./persistence/checkpoint.ts";
|
|
204
|
+
export {
|
|
205
|
+
SessionLogRecordValidationError,
|
|
206
|
+
validateAuditLogRecord,
|
|
207
|
+
validateTranscriptRecord,
|
|
208
|
+
} from "./persistence/records.ts";
|
|
209
|
+
export type * from "./persistence/records.ts";
|
|
210
|
+
export {
|
|
211
|
+
AgentSessionRecordValidationError,
|
|
212
|
+
AgentSessionStoreConflictError,
|
|
213
|
+
MaintenanceAlreadyCompletedError,
|
|
214
|
+
SessionMaintenanceInProgressError,
|
|
215
|
+
internalSessionHistoryDigest,
|
|
216
|
+
validateAgentSessionRecord,
|
|
217
|
+
} from "./persistence/registry.ts";
|
|
218
|
+
export type * from "./persistence/registry.ts";
|
|
219
|
+
export {
|
|
220
|
+
AgentSessionRegistryCursorError,
|
|
221
|
+
AgentSessionRegistryError,
|
|
222
|
+
AgentSessionRegistryLockError,
|
|
223
|
+
FileAgentSessionStore,
|
|
224
|
+
MaintenanceOutcomeUnknownError,
|
|
225
|
+
} from "./persistence/file-registry-store.ts";
|
|
226
|
+
export type {
|
|
227
|
+
FileAgentSessionStoreOptions,
|
|
228
|
+
RegistryRecoveryNotice,
|
|
229
|
+
} from "./persistence/file-registry-store.ts";
|
|
230
|
+
export {
|
|
231
|
+
FileSessionLogWriter,
|
|
232
|
+
SessionLogAlreadyExistsError,
|
|
233
|
+
SessionLogInUseError,
|
|
234
|
+
SessionLogRecordTooLargeError,
|
|
235
|
+
SessionLogWriteError,
|
|
236
|
+
} from "./persistence/session-log-writer.ts";
|
|
237
|
+
export type {
|
|
238
|
+
FileSessionLogWriterOptions,
|
|
239
|
+
ResumedTranscriptWriter,
|
|
240
|
+
ResumeTranscriptWriterOptions,
|
|
241
|
+
SessionLogKind,
|
|
242
|
+
} from "./persistence/session-log-writer.ts";
|
|
243
|
+
export {
|
|
244
|
+
projectAuditEvent,
|
|
245
|
+
projectTranscriptEvent,
|
|
246
|
+
} from "./persistence/projection.ts";
|
|
247
|
+
export type {
|
|
248
|
+
AuditProjectionContext,
|
|
249
|
+
NormalizedActivityProjection,
|
|
250
|
+
NormalizedPersistenceEvent,
|
|
251
|
+
TranscriptProjectionContext,
|
|
252
|
+
} from "./persistence/projection.ts";
|
|
253
|
+
export {
|
|
254
|
+
SessionLogTruncationError,
|
|
255
|
+
truncateSessionLogRecord,
|
|
256
|
+
} from "./persistence/truncation.ts";
|
|
257
|
+
export type { SessionLogTruncationOptions } from "./persistence/truncation.ts";
|
|
258
|
+
export {
|
|
259
|
+
EMPTY_HISTORY_DIGEST,
|
|
260
|
+
TranscriptReductionError,
|
|
261
|
+
reduceTranscriptHistory,
|
|
262
|
+
reduceInternalSessionHistory,
|
|
263
|
+
reduceTranscriptState,
|
|
264
|
+
} from "./persistence/reducer.ts";
|
|
265
|
+
export {
|
|
266
|
+
TranscriptCorruptionError,
|
|
267
|
+
TranscriptIdentityError,
|
|
268
|
+
TranscriptNotFoundError,
|
|
269
|
+
TranscriptUnavailableError,
|
|
270
|
+
scanTranscriptContinuation,
|
|
271
|
+
} from "./persistence/transcript-scanner.ts";
|
|
272
|
+
export {
|
|
273
|
+
TranscriptPersistenceRuntime,
|
|
274
|
+
TranscriptRuntimeStateError,
|
|
275
|
+
} from "./persistence/transcript-runtime.ts";
|
|
276
|
+
export type {
|
|
277
|
+
CreateTranscriptRuntimeOptions,
|
|
278
|
+
TranscriptTerminalCheckpointChanges,
|
|
279
|
+
} from "./persistence/transcript-runtime.ts";
|
|
280
|
+
export { persistenceEventFromActivity } from "./persistence/activity-projection.ts";
|
|
281
|
+
export {
|
|
282
|
+
snapshotSessionConfiguration,
|
|
283
|
+
snapshotSessionConfigurationAfterSelection,
|
|
284
|
+
snapshotAcceptedEffectiveConfiguration,
|
|
285
|
+
} from "./persistence/configuration-state.ts";
|
|
286
|
+
export type {
|
|
287
|
+
SnapshotAcceptedEffectiveConfigurationOptions,
|
|
288
|
+
SnapshotSessionConfigurationAfterSelectionOptions,
|
|
289
|
+
SnapshotSessionConfigurationOptions,
|
|
290
|
+
} from "./persistence/configuration-state.ts";
|
|
291
|
+
export type {
|
|
292
|
+
TranscriptContinuationScan,
|
|
293
|
+
TranscriptScanExpectation,
|
|
294
|
+
} from "./persistence/transcript-scanner.ts";
|
|
295
|
+
export {
|
|
296
|
+
TranscriptCursorInvalidError,
|
|
297
|
+
TranscriptReader,
|
|
298
|
+
TranscriptReaderError,
|
|
299
|
+
} from "./persistence/transcript-reader.ts";
|
|
300
|
+
export {
|
|
301
|
+
AuditLogCursorInvalidError,
|
|
302
|
+
AuditLogReader,
|
|
303
|
+
AuditLogReaderError,
|
|
304
|
+
} from "./persistence/audit-log-reader.ts";
|
|
305
|
+
export type {
|
|
306
|
+
AuditLogCursor,
|
|
307
|
+
AuditLogSnapshotCursor,
|
|
308
|
+
ReadAuditLogPageOptions,
|
|
309
|
+
} from "./persistence/audit-log-reader.ts";
|
|
310
|
+
export {
|
|
311
|
+
LegacyTranscriptMigrationError,
|
|
312
|
+
migrateLegacyTranscript,
|
|
313
|
+
} from "./persistence/migration.ts";
|
|
314
|
+
export type {
|
|
315
|
+
LegacyTranscriptMigrationResult,
|
|
316
|
+
MigrateLegacyTranscriptOptions,
|
|
317
|
+
} from "./persistence/migration.ts";
|
|
318
|
+
export { importLegacySessionRegistry } from "./persistence/legacy-registry-import.ts";
|
|
319
|
+
export type {
|
|
320
|
+
LegacyRegistryImportEntry,
|
|
321
|
+
LegacyRegistryImportReason,
|
|
322
|
+
LegacyRegistryImportResult,
|
|
323
|
+
LegacyRegistryImportStatus,
|
|
324
|
+
} from "./persistence/legacy-registry-import.ts";
|
|
325
|
+
export {
|
|
326
|
+
AgentSessionDeletionError,
|
|
327
|
+
deleteManagedAgentSession,
|
|
328
|
+
} from "./persistence/deletion.ts";
|
|
329
|
+
export type { DeleteAgentSessionOptions } from "./persistence/deletion.ts";
|
|
330
|
+
export {
|
|
331
|
+
ManagedAgentSessionCreationError,
|
|
332
|
+
} from "./persistence/managed-creation.ts";
|
|
333
|
+
export type { ManagedAgentSessionCreateConfig } from "./persistence/managed-creation.ts";
|
|
334
|
+
export type {
|
|
335
|
+
ActivityExecutionState,
|
|
336
|
+
ListTranscriptActivitiesOptions,
|
|
337
|
+
PersistedActivityState,
|
|
338
|
+
PersistedActivityStatePage,
|
|
339
|
+
ReadTranscriptPageOptions,
|
|
340
|
+
TranscriptConversationItem,
|
|
341
|
+
TranscriptCursor,
|
|
342
|
+
TranscriptPage,
|
|
343
|
+
TranscriptSnapshotCursor,
|
|
344
|
+
TranscriptTimelineItem,
|
|
345
|
+
TranscriptReadableRecord,
|
|
346
|
+
TranscriptView,
|
|
347
|
+
} from "./persistence/transcript-reader.ts";
|
|
348
|
+
export type {
|
|
349
|
+
PersistenceRepair,
|
|
350
|
+
SessionRecoveryStatus,
|
|
351
|
+
TranscriptHistoryReduction,
|
|
352
|
+
TranscriptReductionResult,
|
|
353
|
+
TranscriptStructuralRecord,
|
|
354
|
+
} from "./persistence/reducer.ts";
|
|
355
|
+
|
|
130
356
|
export {
|
|
131
357
|
MAX_SCALE,
|
|
132
358
|
EMPTY_MONEY_TOTAL,
|
package/src/metering/engine.ts
CHANGED
|
@@ -251,7 +251,15 @@ export class MeteringEngine {
|
|
|
251
251
|
adapterId: this.options.adapterId,
|
|
252
252
|
internalSessionId,
|
|
253
253
|
});
|
|
254
|
-
if (!keep)
|
|
254
|
+
if (!keep) {
|
|
255
|
+
this.baseline = null;
|
|
256
|
+
// The serializable state is a continuation checkpoint, not only accumulated totals.
|
|
257
|
+
// Carrying the replaced thread's baseline here can make a later restore look valid
|
|
258
|
+
// until the controller reconnects, and makes a mode-transition checkpoint lie.
|
|
259
|
+
if (this.state.activeBaseline !== null) {
|
|
260
|
+
this.state = Object.freeze({ ...this.state, activeBaseline: null });
|
|
261
|
+
}
|
|
262
|
+
}
|
|
255
263
|
// A thread we created has counters starting at zero; one we merely loaded does not.
|
|
256
264
|
this.trustedZeroBaseline = created && !keep;
|
|
257
265
|
}
|
package/src/metering/record.ts
CHANGED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { AggregatedRecord } from "../activity.ts";
|
|
2
|
+
import type { ActivityEvent, ToolActivity } from "../types.ts";
|
|
3
|
+
import type { JsonObject, JsonValue } from "./checkpoint.ts";
|
|
4
|
+
import type { NormalizedPersistenceEvent } from "./projection.ts";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Classify an already-folded live activity record into persistence security buckets.
|
|
8
|
+
* This function deliberately does not serialize or hash values: capture projection gets
|
|
9
|
+
* to discard a bucket before the writer ever examines its potentially sensitive content.
|
|
10
|
+
*/
|
|
11
|
+
export function persistenceEventFromActivity(
|
|
12
|
+
record: AggregatedRecord,
|
|
13
|
+
operationId: string,
|
|
14
|
+
): NormalizedPersistenceEvent {
|
|
15
|
+
if (record.event.kind === "thinking") {
|
|
16
|
+
return {
|
|
17
|
+
kind: "reasoning",
|
|
18
|
+
reasoningId: record.recordId,
|
|
19
|
+
reasoningRevision: record.seq,
|
|
20
|
+
operationId,
|
|
21
|
+
text: record.event.text,
|
|
22
|
+
status: record.reason === "settled" || record.reason === "flushed" ? "completed" : "in_progress",
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (record.event.kind === "tool") {
|
|
27
|
+
return {
|
|
28
|
+
kind: "activity",
|
|
29
|
+
activity: toolProjection(record, record.event, operationId),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
kind: "activity",
|
|
35
|
+
activity: {
|
|
36
|
+
activityId: record.recordId,
|
|
37
|
+
activityRevision: record.seq,
|
|
38
|
+
operationId,
|
|
39
|
+
reason: record.reason,
|
|
40
|
+
kind: record.event.kind,
|
|
41
|
+
content: { event: record.event as unknown as JsonValue },
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function toolProjection(
|
|
47
|
+
record: AggregatedRecord,
|
|
48
|
+
event: ToolActivity,
|
|
49
|
+
operationId: string,
|
|
50
|
+
) {
|
|
51
|
+
const content: Record<string, JsonValue> = {
|
|
52
|
+
toolKind: event.toolKind,
|
|
53
|
+
...(event.title === undefined ? {} : { title: event.title }),
|
|
54
|
+
...(event.rawOutput === undefined ? {} : { rawOutput: event.rawOutput as JsonValue }),
|
|
55
|
+
...(event.content === undefined ? {} : { content: event.content as unknown as JsonValue }),
|
|
56
|
+
...(event.locations === undefined ? {} : { locations: event.locations as unknown as JsonValue }),
|
|
57
|
+
};
|
|
58
|
+
return {
|
|
59
|
+
activityId: record.recordId,
|
|
60
|
+
activityRevision: record.seq,
|
|
61
|
+
operationId,
|
|
62
|
+
reason: record.reason,
|
|
63
|
+
kind: "tool",
|
|
64
|
+
status: event.status,
|
|
65
|
+
metadata: { providerActivityId: event.toolCallId },
|
|
66
|
+
...(event.rawInput === undefined
|
|
67
|
+
? {}
|
|
68
|
+
: { input: { value: event.rawInput as JsonValue } as JsonObject }),
|
|
69
|
+
content: content as JsonObject,
|
|
70
|
+
};
|
|
71
|
+
}
|