Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 


Quelle  route.ts

  Sprache: JAVA
 

Spracherkennung für: .ts vermutete Sprache: Unknown {[0] [0] [0]} [Methode: Schwerpunktbildung, einfache Gewichte, sechs Dimensionen]

import { resolveConfiguredAcpBindingRecord } from "openclaw/plugin-sdk/acp-binding-resolve-runtime";
import type { PluginRuntime } from "openclaw/plugin-sdk/plugin-runtime";
import {
  buildAgentSessionKey,
  deriveLastRoutePolicy,
  resolveAgentIdFromSessionKey,
} from "openclaw/plugin-sdk/routing";
import { getSessionBindingService } from "openclaw/plugin-sdk/session-binding-runtime";
import type { CoreConfig } from "../../types.js";
import { resolveMatrixThreadSessionKeys } from "./threads.js";

type MatrixResolvedRoute = ReturnType<PluginRuntime["channel"]["routing"]["resolveAgentRoute"]>;

function resolveMatrixDmSessionKey(params: {
  accountId: string;
  agentId: string;
  roomId: string;
  dmSessionScope?: "per-user" | "per-room";
  fallbackSessionKey: string;
}): string {
  if (params.dmSessionScope !== "per-room") {
    return params.fallbackSessionKey;
  }
  return buildAgentSessionKey({
    agentId: params.agentId,
    channel: "matrix",
    accountId: params.accountId,
    peer: {
      kind: "channel",
      id: params.roomId,
    },
  });
}

function shouldApplyMatrixPerRoomDmSessionScope(params: {
  isDirectMessage: boolean;
  configuredSessionKey?: string;
}): boolean {
  return params.isDirectMessage && !params.configuredSessionKey;
}

export function resolveMatrixInboundRoute(params: {
  cfg: CoreConfig;
  accountId: string;
  roomId: string;
  senderId: string;
  isDirectMessage: boolean;
  dmSessionScope?: "per-user" | "per-room";
  threadId?: string;
  eventTs?: number;
  resolveAgentRoute: PluginRuntime["channel"]["routing"]["resolveAgentRoute"];
}): {
  route: MatrixResolvedRoute;
  configuredBinding: ReturnType<typeof resolveConfiguredAcpBindingRecord>;
  runtimeBindingId: string | null;
} {
  const baseRoute = params.resolveAgentRoute({
    cfg: params.cfg,
    channel: "matrix",
    accountId: params.accountId,
    peer: {
      kind: params.isDirectMessage ? "direct" : "channel",
      id: params.isDirectMessage ? params.senderId : params.roomId,
    },
    // Matrix DMs are still sender-addressed first, but the room ID remains a
    // useful fallback binding key for generic route matching.
    parentPeer: params.isDirectMessage
      ? {
          kind: "channel",
          id: params.roomId,
        }
      : undefined,
  });
  const bindingConversationId = params.threadId ?? params.roomId;
  const bindingParentConversationId = params.threadId ? params.roomId : undefined;
  const sessionBindingService = getSessionBindingService();
  const runtimeBinding = sessionBindingService.resolveByConversation({
    channel: "matrix",
    accountId: params.accountId,
    conversationId: bindingConversationId,
    parentConversationId: bindingParentConversationId,
  });
  const boundSessionKey = runtimeBinding?.targetSessionKey?.trim();

  if (runtimeBinding && boundSessionKey) {
    return {
      route: {
        ...baseRoute,
        sessionKey: boundSessionKey,
        agentId: resolveAgentIdFromSessionKey(boundSessionKey) || baseRoute.agentId,
        lastRoutePolicy: deriveLastRoutePolicy({
          sessionKey: boundSessionKey,
          mainSessionKey: baseRoute.mainSessionKey,
        }),
        matchedBy: "binding.channel",
      },
      configuredBinding: null,
      runtimeBindingId: runtimeBinding.bindingId,
    };
  }

  const configuredBinding =
    runtimeBinding == null
      ? resolveConfiguredAcpBindingRecord({
          cfg: params.cfg,
          channel: "matrix",
          accountId: params.accountId,
          conversationId: bindingConversationId,
          parentConversationId: bindingParentConversationId,
        })
      : null;
  const configuredSessionKey = configuredBinding?.record.targetSessionKey?.trim();

  const effectiveRoute =
    configuredBinding && configuredSessionKey
      ? {
          ...baseRoute,
          sessionKey: configuredSessionKey,
          agentId:
            resolveAgentIdFromSessionKey(configuredSessionKey) ||
            configuredBinding.spec.agentId ||
            baseRoute.agentId,
          lastRoutePolicy: deriveLastRoutePolicy({
            sessionKey: configuredSessionKey,
            mainSessionKey: baseRoute.mainSessionKey,
          }),
          matchedBy: "binding.channel" as const,
        }
      : baseRoute;

  const dmSessionKey = shouldApplyMatrixPerRoomDmSessionScope({
    isDirectMessage: params.isDirectMessage,
    configuredSessionKey,
  })
    ? resolveMatrixDmSessionKey({
        accountId: params.accountId,
        agentId: effectiveRoute.agentId,
        roomId: params.roomId,
        dmSessionScope: params.dmSessionScope,
        fallbackSessionKey: effectiveRoute.sessionKey,
      })
    : effectiveRoute.sessionKey;
  const routeWithDmScope =
    dmSessionKey === effectiveRoute.sessionKey
      ? effectiveRoute
      : {
          ...effectiveRoute,
          sessionKey: dmSessionKey,
          lastRoutePolicy: "session" as const,
        };

  // When no binding overrides the session key, isolate threads into their own sessions.
  if (!configuredBinding && !configuredSessionKey && params.threadId) {
    const threadKeys = resolveMatrixThreadSessionKeys({
      baseSessionKey: routeWithDmScope.sessionKey,
      threadId: params.threadId,
      parentSessionKey: routeWithDmScope.sessionKey,
    });
    return {
      route: {
        ...routeWithDmScope,
        sessionKey: threadKeys.sessionKey,
        mainSessionKey: threadKeys.parentSessionKey ?? routeWithDmScope.sessionKey,
        lastRoutePolicy: deriveLastRoutePolicy({
          sessionKey: threadKeys.sessionKey,
          mainSessionKey: threadKeys.parentSessionKey ?? routeWithDmScope.sessionKey,
        }),
      },
      configuredBinding,
      runtimeBindingId: null,
    };
  }

  return {
    route: routeWithDmScope,
    configuredBinding,
    runtimeBindingId: null,
  };
}

¤ Dauer der Verarbeitung: 0.19 Sekunden  (vorverarbeitet am  2026-04-27) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Produkte
     Quellcodebibliothek

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Monitoring

Montastic status badge