docs: document gateway state helpers · openclaw/openclaw@4d85028
steipete
·
2026-06-05
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Gateway chat/agent abort tracking. |
| 2 | +// Registers active run abort controllers and projects in-flight chat state. |
1 | 3 | import { |
2 | 4 | asDateTimestampMs, |
3 | 5 | resolveDateTimestampMs, |
@@ -133,6 +135,8 @@ export function registerChatAbortController(params: {
|
133 | 135 | }; |
134 | 136 | |
135 | 137 | if (!params.sessionKey || params.chatAbortControllers.has(params.runId)) { |
| 138 | +// Duplicate run ids keep their fresh controller for caller cancellation, but |
| 139 | +// do not replace the registered entry that owns active-run projection. |
136 | 140 | return { controller, registered: false, cleanup }; |
137 | 141 | } |
138 | 142 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// OpenResponses output item factories. |
| 2 | +// Keeps assistant/function-call output assembly in schema-compatible shapes. |
1 | 3 | import type { OutputItem } from "./open-responses.schema.js"; |
2 | 4 | |
3 | 5 | // Small OpenResponses output factories keep streamed assistant/function-call |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Gateway WebSocket broadcaster. |
| 2 | +// Applies event scope guards and slow-consumer handling before sending frames. |
1 | 3 | import { logRejectedLargePayload } from "../logging/diagnostic-payload.js"; |
2 | 4 | import { |
3 | 5 | ADMIN_SCOPE, |
@@ -54,6 +56,8 @@ const EVENT_SCOPE_GUARDS: Record<string, string[]> = {
|
54 | 56 | const NODE_ALLOWED_EVENTS = new Set<string>(["voicewake.changed", "voicewake.routing.changed"]); |
55 | 57 | |
56 | 58 | function serializeFrameField(name: "payload" | "stateVersion", value: unknown): string { |
| 59 | +// Serialize one field through JSON.stringify so embedded values keep JSON |
| 60 | +// escaping, then splice it into the shared per-client frame body. |
57 | 61 | const fieldJSON = JSON.stringify({ [name]: value }); |
58 | 62 | const keyJSON = JSON.stringify(name); |
59 | 63 | const prefix = `{${keyJSON}:`; |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Gateway session child-discovery helpers. |
| 2 | +// Finds direct parent/child relationships across canonical and legacy fields. |
1 | 3 | import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce"; |
2 | 4 | import { loadCombinedSessionStoreForGateway } from "../config/sessions/combined-store-gateway.js"; |
3 | 5 | import type { SessionEntry } from "../config/sessions/types.js"; |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Gateway session-history projection state. |
| 2 | +// Tracks transcript sequence windows for paginated chat-history SSE updates. |
1 | 3 | import { asPositiveSafeInteger } from "@openclaw/normalization-core/number-coercion"; |
2 | 4 | import { |
3 | 5 | DEFAULT_CHAT_HISTORY_TEXT_MAX_CHARS, |
@@ -108,6 +110,8 @@ function paginateSessionMessages(
|
108 | 110 | limit: number | undefined, |
109 | 111 | cursor: string | undefined, |
110 | 112 | ): PaginatedSessionHistory { |
| 113 | +// Cursors point at transcript sequence watermarks. The returned page is the |
| 114 | +// window before that cursor, matching "older messages" pagination. |
111 | 115 | const cursorSeq = resolveCursorSeq(cursor); |
112 | 116 | let endExclusive = messages.length; |
113 | 117 | if (typeof cursorSeq === "number") { |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Gateway session lifecycle state projection. |
| 2 | +// Converts agent run lifecycle events into session row/store status updates. |
1 | 3 | import { |
2 | 4 | buildAgentRunTerminalOutcome, |
3 | 5 | type AgentRunTerminalOutcome, |
@@ -129,6 +131,8 @@ export function deriveGatewaySessionLifecycleSnapshot(params: {
|
129 | 131 | |
130 | 132 | const existing = params.session ?? undefined; |
131 | 133 | if (phase === "start") { |
| 134 | +// A start event clears terminal fields from the previous run so UI rows do |
| 135 | +// not show stale runtime/end state while the new run is active. |
132 | 136 | const startedAt = resolveLifecycleStartedAt(existing?.startedAt, params.event); |
133 | 137 | const updatedAt = startedAt ?? existing?.updatedAt; |
134 | 138 | return { |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Gateway sessions.resolve implementation helper. |
| 2 | +// Resolves key/sessionId/label selectors into one canonical session key. |
1 | 3 | import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce"; |
2 | 4 | import { |
3 | 5 | ErrorCodes, |
@@ -119,6 +121,8 @@ export async function resolveSessionKeyFromResolveParams(params: {
|
119 | 121 | } |
120 | 122 | |
121 | 123 | if (hasKey) { |
| 124 | +// Key lookups may hit legacy store aliases. Migrate/prune before returning |
| 125 | +// the canonical key so later calls operate on one store identity. |
122 | 126 | const target = resolveGatewaySessionStoreTarget({ cfg, key }); |
123 | 127 | const store = loadSessionStore(target.storePath); |
124 | 128 | if (store[target.canonicalKey]) { |
@@ -168,6 +172,8 @@ export async function resolveSessionKeyFromResolveParams(params: {
|
168 | 172 | } |
169 | 173 | |
170 | 174 | if (hasSessionId) { |
| 175 | +// sessionId can collide across stores; delegate selection so exact key |
| 176 | +// matches and ambiguity rules stay shared with other session-id callers. |
171 | 177 | const { store } = loadCombinedSessionStoreForGateway(cfg, { agentId: p.agentId }); |
172 | 178 | const matches = findVisibleSessionIdMatches({ cfg, store, p, sessionId }); |
173 | 179 | const selection = resolveSessionIdMatchSelection(matches, sessionId); |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Gateway WebSocket log formatting. |
| 2 | +// Redacts and compacts request/response/event metadata for console diagnostics. |
1 | 3 | import { readStringValue } from "@openclaw/normalization-core/string-coerce"; |
2 | 4 | import chalk from "chalk"; |
3 | 5 | import { resolveSendableOutboundReplyParts } from "openclaw/plugin-sdk/reply-payload"; |
@@ -39,6 +41,8 @@ function collectWsRestMeta(meta?: Record<string, unknown>): string[] {
|
39 | 41 | return restMeta; |
40 | 42 | } |
41 | 43 | for (const [key, value] of Object.entries(meta)) { |
| 44 | +// Core frame fields are rendered elsewhere; this loop only emits extra |
| 45 | +// metadata so logs stay compact and stable. |
42 | 46 | if (value === undefined) { |
43 | 47 | continue; |
44 | 48 | } |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。