mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-05 09:41:35 +00:00
refactor(gateway): share conversation registry scope (#113977)
This commit is contained in:
committed by
GitHub
parent
f90cef67c8
commit
aee5c0ae08
@@ -1,7 +1,9 @@
|
||||
import { normalizeOptionalLowercaseString } from "@openclaw/normalization-core/string-coerce";
|
||||
import { executeSqliteQuerySync } from "../../infra/kysely-sync.js";
|
||||
import { openOpenClawAgentDatabase } from "../../state/openclaw-agent-db.js";
|
||||
import type { OpenClawConfig } from "../types.openclaw.js";
|
||||
import type { ConversationIdentity, ConversationKind } from "./conversation-identity.js";
|
||||
import { resolveStorePath } from "./paths.js";
|
||||
import { upsertConversationIdentity } from "./session-accessor.sqlite-conversation.js";
|
||||
import {
|
||||
getSessionKysely,
|
||||
@@ -36,6 +38,19 @@ export type ConversationRegistryScope = {
|
||||
storePath?: string;
|
||||
};
|
||||
|
||||
export function resolveConversationRegistryScope(params: {
|
||||
agentId: string;
|
||||
config: OpenClawConfig;
|
||||
}): ConversationRegistryScope {
|
||||
const configuredStore = params.config.session?.store;
|
||||
return {
|
||||
agentId: params.agentId,
|
||||
...(configuredStore
|
||||
? { storePath: resolveStorePath(configuredStore, { agentId: params.agentId }) }
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeConversationRef(value: string): string {
|
||||
const normalized = value.trim().toLowerCase();
|
||||
if (!CONVERSATION_REF_PATTERN.test(normalized)) {
|
||||
|
||||
@@ -10,10 +10,10 @@ import {
|
||||
import {
|
||||
listConversations,
|
||||
registerConversationAddresses,
|
||||
resolveConversationRegistryScope,
|
||||
type ConversationRecord,
|
||||
type ConversationRegistryScope,
|
||||
} from "../config/sessions/conversation-registry.js";
|
||||
import { resolveStorePath } from "../config/sessions/paths.js";
|
||||
import type { OpenClawConfig } from "../config/types.openclaw.js";
|
||||
import { formatErrorMessage } from "../infra/errors.js";
|
||||
import { resolveOutboundChannelPlugin } from "../infra/outbound/channel-resolution.js";
|
||||
@@ -37,19 +37,6 @@ const defaultDeps: ConversationListDeps = {
|
||||
resolveOutboundSessionRoute,
|
||||
};
|
||||
|
||||
function resolveConversationScope(params: {
|
||||
agentId: string;
|
||||
config: OpenClawConfig;
|
||||
}): ConversationRegistryScope {
|
||||
const configuredStore = params.config.session?.store;
|
||||
return {
|
||||
agentId: params.agentId,
|
||||
...(configuredStore
|
||||
? { storePath: resolveStorePath(configuredStore, { agentId: params.agentId }) }
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
|
||||
function presentConversation(conversation: ConversationRecord): ConversationListItem {
|
||||
return {
|
||||
conversationRef: conversation.conversationRef,
|
||||
@@ -233,7 +220,7 @@ export async function runGatewayConversationList(
|
||||
},
|
||||
deps: ConversationListDeps = defaultDeps,
|
||||
): Promise<ConversationListResult> {
|
||||
const scope = resolveConversationScope(params);
|
||||
const scope = resolveConversationRegistryScope(params);
|
||||
const query = params.query?.trim() || undefined;
|
||||
const discovery = params.channel
|
||||
? await discoverChannelAddresses({
|
||||
|
||||
@@ -5,9 +5,8 @@ import {
|
||||
} from "../config/sessions/conversation-delivery-store.js";
|
||||
import {
|
||||
resolveConversation,
|
||||
type ConversationRegistryScope,
|
||||
resolveConversationRegistryScope,
|
||||
} from "../config/sessions/conversation-registry.js";
|
||||
import { resolveStorePath } from "../config/sessions/paths.js";
|
||||
import type { OpenClawConfig } from "../config/types.openclaw.js";
|
||||
import {
|
||||
ConversationDeliveryRejectedError,
|
||||
@@ -29,19 +28,6 @@ const defaultDeps: ConversationSendDeps = {
|
||||
resolveConversation,
|
||||
};
|
||||
|
||||
function resolveConversationScope(params: {
|
||||
agentId: string;
|
||||
config: OpenClawConfig;
|
||||
}): ConversationRegistryScope {
|
||||
const configuredStore = params.config.session?.store;
|
||||
return {
|
||||
agentId: params.agentId,
|
||||
...(configuredStore
|
||||
? { storePath: resolveStorePath(configuredStore, { agentId: params.agentId }) }
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
|
||||
function resultForCompletedOperation(
|
||||
operation: ConversationDeliveryRecord,
|
||||
): ConversationSendResult | undefined {
|
||||
@@ -94,7 +80,7 @@ export async function runGatewayConversationSend(
|
||||
},
|
||||
deps: ConversationSendDeps = defaultDeps,
|
||||
): Promise<ConversationSendResult> {
|
||||
const scope = resolveConversationScope(params);
|
||||
const scope = resolveConversationRegistryScope(params);
|
||||
try {
|
||||
const prior = deps.getOperation(scope, params.operationId);
|
||||
let operation: ConversationDeliveryRecord | undefined;
|
||||
|
||||
@@ -3,10 +3,10 @@ import type { ChannelId } from "../channels/plugins/types.public.js";
|
||||
import { ConversationDeliveryInputError } from "../config/sessions/conversation-delivery-store.js";
|
||||
import {
|
||||
resolveConversation,
|
||||
resolveConversationRegistryScope,
|
||||
type ConversationRecord,
|
||||
type ConversationRegistryScope,
|
||||
} from "../config/sessions/conversation-registry.js";
|
||||
import { resolveStorePath } from "../config/sessions/paths.js";
|
||||
import type { OpenClawConfig } from "../config/types.openclaw.js";
|
||||
import { resolveOutboundChannelPlugin } from "../infra/outbound/channel-resolution.js";
|
||||
import {
|
||||
@@ -53,19 +53,6 @@ const defaultDeps: ConversationTurnDeps = {
|
||||
resolveOutboundSessionRoute,
|
||||
};
|
||||
|
||||
function resolveConversationScope(params: {
|
||||
agentId: string;
|
||||
config: OpenClawConfig;
|
||||
}): ConversationRegistryScope {
|
||||
const configuredStore = params.config.session?.store;
|
||||
return {
|
||||
agentId: params.agentId,
|
||||
...(configuredStore
|
||||
? { storePath: resolveStorePath(configuredStore, { agentId: params.agentId }) }
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
|
||||
function resultForCompletedOperation(params: {
|
||||
operation: ReturnType<ConversationDeliveryDeps["beginOperation"]>["record"];
|
||||
}): ConversationTurnResult | undefined {
|
||||
@@ -227,7 +214,7 @@ export async function runGatewayConversationTurn(
|
||||
},
|
||||
deps: ConversationTurnDeps = defaultDeps,
|
||||
): Promise<ConversationTurnResult> {
|
||||
const scope = resolveConversationScope(params);
|
||||
const scope = resolveConversationRegistryScope(params);
|
||||
const prior = deps.getOperation(scope, params.turnId);
|
||||
let begun: ReturnType<ConversationDeliveryDeps["beginOperation"]> | undefined;
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user