11// Msteams plugin module implements channel behavior.
2- import { describeAccountSnapshot } from "openclaw/plugin-sdk/account-helpers" ;
32import type {
43 ChannelMessageActionAdapter ,
54 ChannelMessageToolDiscovery ,
@@ -18,7 +17,6 @@ import {
1817import {
1918 createChannelDirectoryAdapter ,
2019 createRuntimeDirectoryLiveAdapter ,
21- listDirectoryEntriesFromSources ,
2220} from "openclaw/plugin-sdk/directory-runtime" ;
2321import { normalizeMessagePresentation } from "openclaw/plugin-sdk/interactive-runtime" ;
2422import { createLazyRuntimeNamedExport } from "openclaw/plugin-sdk/lazy-runtime" ;
@@ -28,6 +26,7 @@ import {
2826 normalizeStringEntries ,
2927} from "openclaw/plugin-sdk/string-coerce-runtime" ;
3028import { Type } from "typebox" ;
29+ import { msteamsDirectoryContractPlugin } from "../directory-contract-api.js" ;
3130import type {
3231 ChannelMessageActionName ,
3332 ChannelOutboundAdapter ,
@@ -47,12 +46,8 @@ import {
4746 resolveMSTeamsAutoThreadId ,
4847} from "./action-threading.js" ;
4948import { msTeamsApprovalAuth } from "./approval-auth.js" ;
50- import {
51- msteamsConfigAdapter ,
52- msteamsMeta ,
53- type ResolvedMSTeamsAccount ,
54- } from "./channel-config.js" ;
55- import { MSTeamsChannelConfigSchema } from "./config-schema.js" ;
49+ import type { ResolvedMSTeamsAccount } from "./channel-config.js" ;
50+ import { msteamsSetupPlugin } from "./channel.setup.js" ;
5651import { collectMSTeamsMutableAllowlistWarnings } from "./doctor.js" ;
5752import { resolveMSTeamsGroupToolPolicy } from "./policy.js" ;
5853import { buildMSTeamsPresentationCard , MSTEAMS_PRESENTATION_CAPABILITIES } from "./presentation.js" ;
@@ -72,8 +67,6 @@ import {
7267 resolveMSTeamsUserAllowlist ,
7368} from "./resolve-allowlist.js" ;
7469import { inferMSTeamsTargetChatType , resolveMSTeamsOutboundSessionRoute } from "./session-route.js" ;
75- import { msteamsSetupContract } from "./setup-core.js" ;
76- import { msteamsSetupWizard } from "./setup-surface.js" ;
7770import { resolveMSTeamsCredentials } from "./token.js" ;
7871
7972const TEAMS_GRAPH_PERMISSION_HINTS : Record < string , string > = {
@@ -422,18 +415,7 @@ const msteamsMessageAdapter = createChannelMessageAdapterFromOutbound({
422415export const msteamsPlugin : ChannelPlugin < ResolvedMSTeamsAccount , ProbeMSTeamsResult > =
423416 createChatChannelPlugin ( {
424417 base : {
425- id : "msteams" ,
426- meta : {
427- ...msteamsMeta ,
428- aliases : [ ...msteamsMeta . aliases ] ,
429- } ,
430- setupWizard : msteamsSetupWizard ,
431- capabilities : {
432- chatTypes : [ "direct" , "channel" , "thread" ] ,
433- polls : true ,
434- threads : true ,
435- media : true ,
436- } ,
418+ ...msteamsSetupPlugin ,
437419 streaming : {
438420 blockStreamingCoalesceDefaults : { minChars : 1500 , idleMs : 1000 } ,
439421 } ,
@@ -446,17 +428,6 @@ export const msteamsPlugin: ChannelPlugin<ResolvedMSTeamsAccount, ProbeMSTeamsRe
446428 groups : {
447429 resolveToolPolicy : resolveMSTeamsGroupToolPolicy ,
448430 } ,
449- reload : { configPrefixes : [ "channels.msteams" ] } ,
450- configSchema : MSTeamsChannelConfigSchema ,
451- config : {
452- ...msteamsConfigAdapter ,
453- isConfigured : ( _account , cfg ) => Boolean ( resolveMSTeamsCredentials ( cfg . channels ?. msteams ) ) ,
454- describeAccount : ( account ) =>
455- describeAccountSnapshot ( {
456- account,
457- configured : account . configured ,
458- } ) ,
459- } ,
460431 approvalCapability : msTeamsApprovalAuth ,
461432 doctor : {
462433 dmAllowFromMode : "topOnly" ,
@@ -465,7 +436,6 @@ export const msteamsPlugin: ChannelPlugin<ResolvedMSTeamsAccount, ProbeMSTeamsRe
465436 warnOnEmptyGroupSenderAllowlist : true ,
466437 collectMutableAllowlistWarnings : collectMSTeamsMutableAllowlistWarnings ,
467438 } ,
468- setupContract : msteamsSetupContract ,
469439 messaging : {
470440 targetPrefixes : [ "msteams" , "teams" ] ,
471441 directTargetStyle : "user-prefixed" ,
@@ -479,43 +449,7 @@ export const msteamsPlugin: ChannelPlugin<ResolvedMSTeamsAccount, ProbeMSTeamsRe
479449 } ,
480450 message : msteamsMessageAdapter ,
481451 directory : createChannelDirectoryAdapter ( {
482- self : async ( { cfg } ) => {
483- const creds = resolveMSTeamsCredentials ( cfg . channels ?. msteams ) ;
484- if ( ! creds ) {
485- return null ;
486- }
487- return { kind : "user" as const , id : creds . appId , name : creds . appId } ;
488- } ,
489- listPeers : async ( { cfg, query, limit } ) =>
490- listDirectoryEntriesFromSources ( {
491- kind : "user" ,
492- sources : [
493- cfg . channels ?. msteams ?. allowFrom ?? [ ] ,
494- Object . keys ( cfg . channels ?. msteams ?. dms ?? { } ) ,
495- ] ,
496- query,
497- limit,
498- normalizeId : ( raw ) => {
499- const normalized = normalizeMSTeamsMessagingTarget ( raw ) ?? raw ;
500- const lowered = normalized . toLowerCase ( ) ;
501- if ( lowered . startsWith ( "user:" ) || lowered . startsWith ( "conversation:" ) ) {
502- return normalized ;
503- }
504- return `user:${ normalized } ` ;
505- } ,
506- } ) ,
507- listGroups : async ( { cfg, query, limit } ) =>
508- listDirectoryEntriesFromSources ( {
509- kind : "group" ,
510- sources : [
511- Object . values ( cfg . channels ?. msteams ?. teams ?? { } ) . flatMap ( ( team ) =>
512- Object . keys ( team . channels ?? { } ) ,
513- ) ,
514- ] ,
515- query,
516- limit,
517- normalizeId : ( raw ) => `conversation:${ raw . replace ( / ^ c o n v e r s a t i o n : / i, "" ) . trim ( ) } ` ,
518- } ) ,
452+ ...msteamsDirectoryContractPlugin . directory ,
519453 ...createRuntimeDirectoryLiveAdapter ( {
520454 getRuntime : loadMSTeamsChannelRuntime ,
521455 listPeersLive : ( runtime ) => runtime . listMSTeamsDirectoryPeersLive ,
0 commit comments