refactor: harden msteams lifecycle and attachment flows

This commit is contained in:
Peter Steinberger
2026-03-02 21:18:22 +00:00
parent d98a61a977
commit 866bd91c65
15 changed files with 459 additions and 112 deletions

View File

@@ -13,7 +13,6 @@ import {
classifyMSTeamsSendError,
formatMSTeamsSendErrorHint,
formatUnknownError,
isRevokedProxyError,
} from "./errors.js";
import {
buildConversationReference,
@@ -22,6 +21,7 @@ import {
sendMSTeamsMessages,
} from "./messenger.js";
import type { MSTeamsMonitorLogger } from "./monitor-types.js";
import { withRevokedProxyFallback } from "./revoked-context.js";
import { getMSTeamsRuntime } from "./runtime.js";
import type { MSTeamsTurnContext } from "./sdk-types.js";
@@ -53,23 +53,24 @@ export function createMSTeamsReplyDispatcher(params: {
* the stored conversation reference so the user still sees the "…" bubble.
*/
const sendTypingIndicator = async () => {
try {
await params.context.sendActivity({ type: "typing" });
} catch (err) {
if (!isRevokedProxyError(err)) {
throw err;
}
// Turn context revoked — fall back to proactive typing.
params.log.debug?.("turn context revoked, sending typing via proactive messaging");
const baseRef = buildConversationReference(params.conversationRef);
await params.adapter.continueConversation(
params.appId,
{ ...baseRef, activityId: undefined },
async (ctx) => {
await ctx.sendActivity({ type: "typing" });
},
);
}
await withRevokedProxyFallback({
run: async () => {
await params.context.sendActivity({ type: "typing" });
},
onRevoked: async () => {
const baseRef = buildConversationReference(params.conversationRef);
await params.adapter.continueConversation(
params.appId,
{ ...baseRef, activityId: undefined },
async (ctx) => {
await ctx.sendActivity({ type: "typing" });
},
);
},
onRevokedLog: () => {
params.log.debug?.("turn context revoked, sending typing via proactive messaging");
},
});
};
const typingCallbacks = createTypingCallbacks({