mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-24 03:15:46 -06:00
refactor(gateway): prepare cron authority at entry
This commit is contained in:
@@ -15,6 +15,6 @@ export type ChatSendExternalAuthorityAdmission = {
|
||||
isReconnectResume: boolean;
|
||||
isSystemGenerated: boolean;
|
||||
turnKind: "btw" | "main";
|
||||
}): Readonly<{ runId: string }> | undefined;
|
||||
}): CronCreatorAuthorityCapability | undefined;
|
||||
run<T>(capability: CronCreatorAuthorityCapability, run: () => T, signal?: AbortSignal): T;
|
||||
};
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { runWithCronCreatorAuthorityCapability } from "../../agents/cron-creator-authority-context.js";
|
||||
import {
|
||||
createCronCreatorAuthorityCapability,
|
||||
runWithCronCreatorAuthorityCapability,
|
||||
} from "../../agents/cron-creator-authority-context.js";
|
||||
import { isIncognitoSessionKey } from "../../routing/session-key.js";
|
||||
import type { ChatSendExternalAuthorityAdmission } from "./chat-send-external-authority-contract.js";
|
||||
import { handleChatSend } from "./chat-send-handler.js";
|
||||
@@ -6,8 +9,8 @@ import { resolveGatewayChatCronCreatorAuthorityAdmission } from "./cron-creator-
|
||||
import type { GatewayRequestHandlerOptions } from "./types.js";
|
||||
|
||||
const externalAuthorityAdmission: ChatSendExternalAuthorityAdmission = {
|
||||
resolve: (params) =>
|
||||
resolveGatewayChatCronCreatorAuthorityAdmission({
|
||||
resolve: (params) => {
|
||||
const authority = resolveGatewayChatCronCreatorAuthorityAdmission({
|
||||
runId: params.runId,
|
||||
resolvedSessionKey: params.sessionKey,
|
||||
spawnedBy: params.spawnedBy,
|
||||
@@ -20,7 +23,9 @@ const externalAuthorityAdmission: ChatSendExternalAuthorityAdmission = {
|
||||
isSystemGenerated: params.isSystemGenerated,
|
||||
turnKind: params.turnKind,
|
||||
isDirectExternalUser: true,
|
||||
}),
|
||||
});
|
||||
return authority ? createCronCreatorAuthorityCapability(authority.runId) : undefined;
|
||||
},
|
||||
run: (capability, run, signal) => runWithCronCreatorAuthorityCapability(capability, run, signal),
|
||||
};
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import {
|
||||
} from "../../../packages/gateway-protocol/src/client-info.js";
|
||||
import { ErrorCodes, errorShape } from "../../../packages/gateway-protocol/src/index.js";
|
||||
import { resolveDefaultAgentId } from "../../agents/agent-scope.js";
|
||||
import { createCronCreatorAuthorityCapability } from "../../agents/cron-creator-authority-context.js";
|
||||
import { resolveProviderIdForAuth } from "../../agents/provider-auth-aliases.js";
|
||||
import { createAgentRunRestartAbortError } from "../../agents/run-termination.js";
|
||||
import { dispatchInboundMessageWithProjectedDispatcher } from "../../auto-reply/dispatch.js";
|
||||
@@ -443,22 +442,18 @@ export async function handleChatSend(
|
||||
}
|
||||
}
|
||||
applyChatSendManagedMedia(ctx, await pluginBoundMediaPromise);
|
||||
const cronCreatorAuthorityCapability = cronCreatorAuthority
|
||||
? createCronCreatorAuthorityCapability(cronCreatorAuthority.runId)
|
||||
: undefined;
|
||||
const dispatchInbound = () =>
|
||||
dispatchInboundMessageWithProjectedDispatcher({
|
||||
ctx,
|
||||
cfg,
|
||||
dispatcherOptions: replyDispatch.dispatcherOptions,
|
||||
onSessionMetadataChanges: (changes) => {
|
||||
for (const change of changes) {
|
||||
emitSessionsChanged(context, change);
|
||||
}
|
||||
},
|
||||
onSessionMetadataChanges: (changes) =>
|
||||
changes.forEach((change) => emitSessionsChanged(context, change)),
|
||||
replyOptions: {
|
||||
runId: clientRunId,
|
||||
...(cronCreatorAuthorityCapability ? { cronCreatorAuthorityCapability } : {}),
|
||||
...(cronCreatorAuthority
|
||||
? { cronCreatorAuthorityCapability: cronCreatorAuthority }
|
||||
: {}),
|
||||
...(isOperatorUiClient(clientInfo)
|
||||
? {
|
||||
promptCacheKey: resolveWebchatPromptCacheKey({
|
||||
@@ -572,10 +567,9 @@ export async function handleChatSend(
|
||||
},
|
||||
},
|
||||
});
|
||||
const dispatchResult = await (cronCreatorAuthorityCapability &&
|
||||
externalAuthorityAdmission
|
||||
const dispatchResult = await (cronCreatorAuthority && externalAuthorityAdmission
|
||||
? externalAuthorityAdmission.run(
|
||||
cronCreatorAuthorityCapability,
|
||||
cronCreatorAuthority,
|
||||
dispatchInbound,
|
||||
activeRunAbort.controller.signal,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user