mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-02 18:41:33 +00:00
* refactor(deadcode): trim auto-reply and CLI exports * refactor(deadcode): trim cron and task exports * refactor(deadcode): trim fleet and process exports * test(deadcode): exercise live task and process seams * test(fleet): cover stream redaction through owner module * refactor(security): trim dead internal exports * refactor(secrets): trim dead internal exports * refactor(deadcode): trim remaining src exports * refactor(deadcode): remove test-only runtime exports * refactor(deadcode): trim pairing test exports * refactor(deadcode): reconcile refreshed baseline * test(auto-reply): deduplicate queue state imports
70 lines
2.3 KiB
TypeScript
70 lines
2.3 KiB
TypeScript
// Transient user-turn transcript context carried through runtime queues.
|
|
import type { AgentMessage } from "../../packages/agent-core/src/types.js";
|
|
import type {
|
|
PersistedUserTurnMessage,
|
|
UserTurnTranscriptRecorder,
|
|
} from "./user-turn-transcript.types.js";
|
|
|
|
const RUNTIME_USER_TURN_TRANSCRIPT_CONTEXT = Symbol.for(
|
|
"openclaw.runtimeUserTurnTranscriptContext",
|
|
);
|
|
const RUNTIME_USER_TURN_TRANSCRIPT_RECORDER = Symbol.for(
|
|
"openclaw.runtimeUserTurnTranscriptRecorder",
|
|
);
|
|
|
|
type RuntimeUserTurnTranscriptContext = {
|
|
message: PersistedUserTurnMessage;
|
|
recorder: UserTurnTranscriptRecorder;
|
|
};
|
|
|
|
/** Carries transcript-only fields with a queued runtime message without exposing them to the model. */
|
|
export function attachRuntimeUserTurnTranscriptContext(
|
|
runtimeMessage: PersistedUserTurnMessage,
|
|
context: RuntimeUserTurnTranscriptContext,
|
|
): PersistedUserTurnMessage {
|
|
Object.defineProperty(runtimeMessage, RUNTIME_USER_TURN_TRANSCRIPT_CONTEXT, {
|
|
configurable: true,
|
|
value: context,
|
|
});
|
|
return runtimeMessage;
|
|
}
|
|
|
|
/** Consumes the transient queued-turn context before the message is serialized. */
|
|
export function takeRuntimeUserTurnTranscriptContext(
|
|
runtimeMessage: AgentMessage,
|
|
): RuntimeUserTurnTranscriptContext | undefined {
|
|
const record = runtimeMessage as unknown as Record<PropertyKey, unknown>;
|
|
const context = record[RUNTIME_USER_TURN_TRANSCRIPT_CONTEXT] as
|
|
| RuntimeUserTurnTranscriptContext
|
|
| undefined;
|
|
if (context) {
|
|
delete record[RUNTIME_USER_TURN_TRANSCRIPT_CONTEXT];
|
|
}
|
|
return context;
|
|
}
|
|
|
|
/** Keeps the queued recorder attached to the exact final message until persistence succeeds. */
|
|
export function attachRuntimeUserTurnTranscriptRecorder(
|
|
runtimeMessage: AgentMessage,
|
|
recorder: UserTurnTranscriptRecorder,
|
|
): AgentMessage {
|
|
Object.defineProperty(runtimeMessage, RUNTIME_USER_TURN_TRANSCRIPT_RECORDER, {
|
|
configurable: true,
|
|
value: recorder,
|
|
});
|
|
return runtimeMessage;
|
|
}
|
|
|
|
export function takeRuntimeUserTurnTranscriptRecorder(
|
|
runtimeMessage: AgentMessage,
|
|
): UserTurnTranscriptRecorder | undefined {
|
|
const record = runtimeMessage as unknown as Record<PropertyKey, unknown>;
|
|
const recorder = record[RUNTIME_USER_TURN_TRANSCRIPT_RECORDER] as
|
|
| UserTurnTranscriptRecorder
|
|
| undefined;
|
|
if (recorder) {
|
|
delete record[RUNTIME_USER_TURN_TRANSCRIPT_RECORDER];
|
|
}
|
|
return recorder;
|
|
}
|