mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
refactor(sessions): remove unused transcript helpers (#105245)
This commit is contained in:
@@ -47,8 +47,6 @@ import {
|
||||
updateSqliteSessionLastRoute,
|
||||
loadExactSqliteSessionEntry,
|
||||
loadLatestSqliteAssistantText,
|
||||
loadLatestSqliteAssistantMessage,
|
||||
loadLatestSqliteMessage,
|
||||
loadSqliteSessionEntry,
|
||||
loadSqliteTranscriptEvents,
|
||||
loadSqliteTranscriptEventsSync,
|
||||
@@ -329,16 +327,6 @@ export type LatestTranscriptAssistantText = {
|
||||
timestamp?: number;
|
||||
};
|
||||
|
||||
export type LatestTranscriptAssistantMessage = {
|
||||
id?: string;
|
||||
message: unknown;
|
||||
};
|
||||
|
||||
export type LatestTranscriptMessage = {
|
||||
id?: string;
|
||||
message: unknown;
|
||||
};
|
||||
|
||||
export type SessionTranscriptWriteLockAccessorContext = {
|
||||
appendMessage: <TMessage>(
|
||||
options: TranscriptMessageAppendOptions<TMessage>,
|
||||
@@ -2370,22 +2358,6 @@ export function readLatestTranscriptAssistantText(
|
||||
return loadLatestSqliteAssistantText(scope, options);
|
||||
}
|
||||
|
||||
/** Reads the latest assistant message payload without materializing the whole transcript. */
|
||||
export function readLatestTranscriptAssistantMessage(
|
||||
scope: SessionTranscriptReadScope,
|
||||
options: { includeTranscriptOnlyOpenClawAssistant?: boolean } = {},
|
||||
): LatestTranscriptAssistantMessage | undefined {
|
||||
return loadLatestSqliteAssistantMessage(scope, options);
|
||||
}
|
||||
|
||||
/** Reads the latest transcript message payload without materializing the whole transcript. */
|
||||
export function readLatestTranscriptMessage(
|
||||
scope: SessionTranscriptReadScope,
|
||||
options: { includeTranscriptOnlyOpenClawAssistant?: boolean } = {},
|
||||
): LatestTranscriptMessage | undefined {
|
||||
return loadLatestSqliteMessage(scope, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends one transcript message with message-id generation and optional
|
||||
* idempotency lookup. The returned message is the redacted persisted value.
|
||||
|
||||
@@ -27,10 +27,7 @@ import {
|
||||
streamSessionTranscriptLinesReverse,
|
||||
} from "./transcript-stream.js";
|
||||
import { isCanonicalSessionTranscriptEntry } from "./transcript-tree.js";
|
||||
import {
|
||||
resolveOwnedSessionTranscriptWriteLockRunner,
|
||||
type OwnedSessionTranscriptPublishedEntry,
|
||||
} from "./transcript-write-context.js";
|
||||
import { resolveOwnedSessionTranscriptWriteLockRunner } from "./transcript-write-context.js";
|
||||
import { CURRENT_SESSION_VERSION } from "./version.js";
|
||||
|
||||
const SESSION_MANAGER_APPEND_MAX_BYTES = 8 * 1024 * 1024;
|
||||
@@ -425,13 +422,6 @@ export type AppendSessionTranscriptMessageResult<TMessage> = {
|
||||
appended: boolean;
|
||||
};
|
||||
|
||||
export type SessionTranscriptAppendTransactionContext = {
|
||||
appendEvent: (event: unknown) => Promise<void>;
|
||||
appendMessage: <TMessage>(
|
||||
params: Omit<AppendSessionTranscriptMessageParams<TMessage>, "config" | "transcriptPath">,
|
||||
) => Promise<AppendSessionTranscriptMessageResult<TMessage> | undefined>;
|
||||
};
|
||||
|
||||
function isTranscriptAgentMessage(value: unknown): value is AgentMessage {
|
||||
return (
|
||||
typeof value === "object" &&
|
||||
@@ -511,57 +501,6 @@ export async function appendSessionTranscriptMessageWithOwnedWriteLock<TMessage>
|
||||
return await activeLockRunner(() => appendSessionTranscriptMessageLocked(params));
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a group of transcript appends through one append queue and write lock.
|
||||
*/
|
||||
export async function runSessionTranscriptAppendTransaction<T>(
|
||||
params: Pick<AppendSessionTranscriptMessageParams, "config" | "transcriptPath">,
|
||||
run: (context: SessionTranscriptAppendTransactionContext) => Promise<T> | T,
|
||||
): Promise<T> {
|
||||
const publishedEntries: OwnedSessionTranscriptPublishedEntry[] = [];
|
||||
const runTransaction = async (): Promise<T> =>
|
||||
await run({
|
||||
appendEvent: async (event) => {
|
||||
const result = await appendSessionTranscriptEventLocked({
|
||||
config: params.config,
|
||||
event,
|
||||
transcriptPath: params.transcriptPath,
|
||||
});
|
||||
publishedEntries.push({ kind: "serialized", serialized: result.serializedEntry });
|
||||
},
|
||||
appendMessage: async (messageParams) => {
|
||||
const result = await appendSessionTranscriptMessageLocked({
|
||||
...messageParams,
|
||||
config: params.config,
|
||||
onHeaderCreated: (header) => {
|
||||
publishedEntries.push({ kind: "header", serialized: header });
|
||||
},
|
||||
transcriptPath: params.transcriptPath,
|
||||
});
|
||||
if (result?.appended === true) {
|
||||
publishedEntries.push({ kind: "id", id: result.messageId });
|
||||
}
|
||||
return result;
|
||||
},
|
||||
});
|
||||
const activeLockRunner = resolveOwnedSessionTranscriptWriteLockRunner({
|
||||
sessionFile: params.transcriptPath,
|
||||
});
|
||||
if (activeLockRunner) {
|
||||
return await activeLockRunner(
|
||||
() => withSessionTranscriptAppendQueue(params.transcriptPath, runTransaction),
|
||||
{
|
||||
publishOwnedWrite: true,
|
||||
resolvePublishedEntries: () => publishedEntries,
|
||||
resolvePublishedEntriesAfterFailure: () => publishedEntries,
|
||||
},
|
||||
);
|
||||
}
|
||||
return await withSessionTranscriptAppendQueue(params.transcriptPath, () =>
|
||||
withSessionTranscriptWriteLock(params, runTransaction),
|
||||
);
|
||||
}
|
||||
|
||||
type AppendSessionTranscriptEventParams = {
|
||||
config?: OpenClawConfig;
|
||||
event: unknown;
|
||||
|
||||
Reference in New Issue
Block a user