File size: 3,447 Bytes
fc93158 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | import type { OpenClawConfig } from "../../config/config.js";
import type {
SessionAcpIdentity,
AcpSessionRuntimeOptions,
SessionAcpMeta,
SessionEntry,
} from "../../config/sessions/types.js";
import type { AcpRuntimeError } from "../runtime/errors.js";
import { requireAcpRuntimeBackend } from "../runtime/registry.js";
import {
listAcpSessionEntries,
readAcpSessionEntry,
upsertAcpSessionMeta,
} from "../runtime/session-meta.js";
import type {
AcpRuntime,
AcpRuntimeCapabilities,
AcpRuntimeEvent,
AcpRuntimeHandle,
AcpRuntimePromptMode,
AcpRuntimeSessionMode,
AcpRuntimeStatus,
} from "../runtime/types.js";
export type AcpSessionResolution =
| {
kind: "none";
sessionKey: string;
}
| {
kind: "stale";
sessionKey: string;
error: AcpRuntimeError;
}
| {
kind: "ready";
sessionKey: string;
meta: SessionAcpMeta;
};
export type AcpInitializeSessionInput = {
cfg: OpenClawConfig;
sessionKey: string;
agent: string;
mode: AcpRuntimeSessionMode;
resumeSessionId?: string;
cwd?: string;
backendId?: string;
};
export type AcpTurnAttachment = {
mediaType: string;
data: string;
};
export type AcpRunTurnInput = {
cfg: OpenClawConfig;
sessionKey: string;
text: string;
attachments?: AcpTurnAttachment[];
mode: AcpRuntimePromptMode;
requestId: string;
signal?: AbortSignal;
onEvent?: (event: AcpRuntimeEvent) => Promise<void> | void;
};
export type AcpCloseSessionInput = {
cfg: OpenClawConfig;
sessionKey: string;
reason: string;
clearMeta?: boolean;
allowBackendUnavailable?: boolean;
requireAcpSession?: boolean;
};
export type AcpCloseSessionResult = {
runtimeClosed: boolean;
runtimeNotice?: string;
metaCleared: boolean;
};
export type AcpSessionStatus = {
sessionKey: string;
backend: string;
agent: string;
identity?: SessionAcpIdentity;
state: SessionAcpMeta["state"];
mode: AcpRuntimeSessionMode;
runtimeOptions: AcpSessionRuntimeOptions;
capabilities: AcpRuntimeCapabilities;
runtimeStatus?: AcpRuntimeStatus;
lastActivityAt: number;
lastError?: string;
};
export type AcpManagerObservabilitySnapshot = {
runtimeCache: {
activeSessions: number;
idleTtlMs: number;
evictedTotal: number;
lastEvictedAt?: number;
};
turns: {
active: number;
queueDepth: number;
completed: number;
failed: number;
averageLatencyMs: number;
maxLatencyMs: number;
};
errorsByCode: Record<string, number>;
};
export type AcpStartupIdentityReconcileResult = {
checked: number;
resolved: number;
failed: number;
};
export type ActiveTurnState = {
runtime: AcpRuntime;
handle: AcpRuntimeHandle;
abortController: AbortController;
cancelPromise?: Promise<void>;
};
export type TurnLatencyStats = {
completed: number;
failed: number;
totalMs: number;
maxMs: number;
};
export type AcpSessionManagerDeps = {
listAcpSessions: typeof listAcpSessionEntries;
readSessionEntry: typeof readAcpSessionEntry;
upsertSessionMeta: typeof upsertAcpSessionMeta;
requireRuntimeBackend: typeof requireAcpRuntimeBackend;
};
export const DEFAULT_DEPS: AcpSessionManagerDeps = {
listAcpSessions: listAcpSessionEntries,
readSessionEntry: readAcpSessionEntry,
upsertSessionMeta: upsertAcpSessionMeta,
requireRuntimeBackend: requireAcpRuntimeBackend,
};
export type { AcpSessionRuntimeOptions, SessionAcpMeta, SessionEntry };
|