The Open Framework for Building Agents
fix(eve): harden Teams HITL submissions (#754)
Ruid1942434c25f
diff --git a/.changeset/tame-teams-hitl.md b/.changeset/tame-teams-hitl.mdnew file mode 100644index 000000000..c9104a8e8--- /dev/null+++ b/.changeset/tame-teams-hitl.md@@ -0,0 +1,5 @@+---+"eve": patch+---++Fix Microsoft Teams HITL cards to show tool arguments, resume the recorded channel thread for message and invoke submissions, and authorize submissions as the Teams user who clicked the card.diff --git a/docs/channels/teams.mdx b/docs/channels/teams.mdxindex 4f60d3b2a..48b9ecede 100644--- a/docs/channels/teams.mdx+++ b/docs/channels/teams.mdx@@ -45,7 +45,11 @@ Replies post as Markdown (`textFormat: "markdown"`), with oversized text split a### Human-in-the-loop (HITL)-A human-in-the-loop (HITL) `input.requested` event renders as an Adaptive Card. Buttons and options map to `Action.Submit`, selects to `Input.ChoiceSet`, and freeform to `Input.Text`. When the user submits, the activity converts to eve `inputResponses` for you. For invokes that aren't HITL, handle them in `onInvoke(ctx, activity)`.+A human-in-the-loop (HITL) `input.requested` event renders as an Adaptive Card. Approval cards show the tool input in the card and fallback text. Buttons and options map to `Action.Submit`, selects to `Input.ChoiceSet`, and freeform to `Input.Text`. Teams may return a submission as a message or invoke; eve handles both before the normal message mention gate and resumes the thread recorded in the card.++By default, submissions use the Teams identity of the user who clicked the card. If you customize `onMessage` for an allowlist, configure the same policy in `onInputResponse`; eve otherwise rejects HITL submissions rather than bypassing the message gate.++For invokes that aren't HITL, handle them in `onInvoke(ctx, activity)`.### Proactive sessionsdiff --git a/packages/eve/src/public/channels/teams/api.test.ts b/packages/eve/src/public/channels/teams/api.test.tsindex 45870c2a7..d29f07d17 100644--- a/packages/eve/src/public/channels/teams/api.test.ts+++ b/packages/eve/src/public/channels/teams/api.test.ts@@ -6,6 +6,7 @@ import {resolveTeamsAccessToken,sendTeamsActivity,splitTeamsMessageText,+ normalizeTeamsContinuationAddress,teamsContinuationToken,triggerTeamsTypingIndicator,updateTeamsActivity,@@ -22,6 +23,24 @@ describe("Teams Connector API wrapper", () => {).toBe("T%201:19%3Aabc%40thread.skype:A%3A1");});+ it("normalizes channel thread suffixes before building continuation tokens", () => {+ expect(+ normalizeTeamsContinuationAddress({+ conversationId: "19:[email protected];messageid=THREAD_ROOT",+ replyToActivityId: "VOLATILE_ACTIVITY",+ }),+ ).toEqual({+ conversationId: "19:[email protected]",+ replyToActivityId: "THREAD_ROOT",+ });+ expect(+ teamsContinuationToken({+ conversationId: "19:[email protected];messageid=THREAD_ROOT",+ tenantId: "TENANT",+ }),+ ).toBe("TENANT:19%3Aabc%40thread.tacv2:THREAD_ROOT");+ });+it("requests and caches Bot Connector access tokens", async () => {const apiFetch = vi.fn(async (_url: string | URL | Request, _init?: RequestInit) =>Response.json({ access_token: "token-1", expires_in: 3600 }),diff --git a/packages/eve/src/public/channels/teams/api.ts b/packages/eve/src/public/channels/teams/api.tsindex 5affd1c8b..d1176f0a1 100644--- a/packages/eve/src/public/channels/teams/api.ts+++ b/packages/eve/src/public/channels/teams/api.ts@@ -135,11 +135,34 @@ export function teamsContinuationToken(input: {readonly replyToActivityId?: string | null;readonly tenantId?: string | null;}): string {- return [input.tenantId ?? "_", input.conversationId, input.replyToActivityId ?? ""]+ const address = normalizeTeamsContinuationAddress(input);+ return [input.tenantId ?? "_", address.conversationId, address.replyToActivityId ?? ""].map((component) => encodeURIComponent(component)).join(":");}+/** Normalizes the thread suffix that Teams inconsistently includes in channel conversation ids. */+export function normalizeTeamsContinuationAddress(input: {+ readonly conversationId: string;+ readonly replyToActivityId?: string | null;+}): { readonly conversationId: string; readonly replyToActivityId: string | null } {+ const marker = ";messageid=";+ const markerIndex = input.conversationId.lastIndexOf(marker);+ if (markerIndex < 0) {+ return {+ conversationId: input.conversationId,+ replyToActivityId: input.replyToActivityId ?? null,+ };+ }++ const conversationId = input.conversationId.slice(0, markerIndex);+ const threadRoot = input.conversationId.slice(markerIndex + marker.length);+ return {+ conversationId,+ replyToActivityId: threadRoot || input.replyToActivityId || null,+ };+}+/** Resolves a Teams app id, falling back to `MICROSOFT_APP_ID` then `TEAMS_APP_ID`. */export async function resolveTeamsAppId(appId?: TeamsAppId): Promise<string> {const source = appId ?? process.env.MICROSOFT_APP_ID ?? process.env.TEAMS_APP_ID;diff --git a/packages/eve/src/public/channels/teams/defaults.ts b/packages/eve/src/public/channels/teams/defaults.tsindex 4d9f63a08..32c2a6e15 100644--- a/packages/eve/src/public/channels/teams/defaults.ts+++ b/packages/eve/src/public/channels/teams/defaults.ts@@ -7,7 +7,7 @@ import {renderAnsweredInputRequestMessage,renderInputRequestMessage,} from "#public/channels/teams/hitl.js";-import type { TeamsMessageActivity } from "#public/channels/teams/inbound.js";+import type { TeamsInvokeActivity, TeamsMessageActivity } from "#public/channels/teams/inbound.js";import type {TeamsChannelEvents,TeamsContext,@@ -16,7 +16,9 @@ import type {import { parseJsonObject } from "#shared/json.js";/** Default auth projection for Teams message actors. */-export function defaultTeamsAuth(message: TeamsMessageActivity): SessionAuthContext {+export function defaultTeamsAuth(+ message: TeamsMessageActivity | TeamsInvokeActivity,+): SessionAuthContext {const tenantId = message.tenantId;const attributes: Record<string, string> = {activity_id: message.id,@@ -69,6 +71,7 @@ export const defaultEvents: TeamsChannelEvents = {await channel.thread.post(renderInputRequestMessage(request, {adaptiveCardVersion: channel.adaptiveCardVersion,+ replyToActivityId: channel.teams.replyToActivityId,}),);}diff --git a/packages/eve/src/public/channels/teams/hitl.test.ts b/packages/eve/src/public/channels/teams/hitl.test.tsindex 893cc544e..42ac93b0b 100644--- a/packages/eve/src/public/channels/teams/hitl.test.ts+++ b/packages/eve/src/public/channels/teams/hitl.test.ts@@ -2,9 +2,8 @@ import { describe, expect, it } from "vitest";import {deriveTeamsInputResponses,- isTeamsInputResponseActivity,+ readTeamsInputReplyToActivityId,renderInputRequestMessage,- teamsInvokeResponse,TEAMS_HITL_CHOICE_INPUT_ID,TEAMS_HITL_DATA_KEY,TEAMS_HITL_FREEFORM_INPUT_ID,@@ -13,13 +12,32 @@ import { parseTeamsActivity } from "#public/channels/teams/inbound.js";import type { InputRequest } from "#runtime/input/types.js";describe("Teams HITL helpers", () => {- it("renders option buttons as Adaptive Card submit actions", () => {- const body = renderInputRequestMessage(request());- const card = body.attachments?.[0]?.content as { actions?: unknown[] };- expect(card.actions).toHaveLength(2);- expect(card.actions?.[0]).toMatchObject({- data: { [TEAMS_HITL_DATA_KEY]: { optionId: "approve", requestId: "REQ" } },- type: "Action.Submit",+ it("renders approval tool input in the card and fallback text", () => {+ const body = renderInputRequestMessage({+ ...request(),+ action: {+ callId: "TC",+ input: { campaign: "summer", dailyBudget: 500 },+ kind: "tool-call",+ toolName: "set_campaign_budget",+ },+ });+ const card = body.attachments?.[0]?.content as {+ body?: Array<{ text?: string }>;+ };++ expect(card.body?.[1]?.text).toContain('"campaign": "summer"');+ expect(body.text).toContain('"dailyBudget": 500');+ });++ it("carries the continuation token in submit actions", () => {+ const body = renderInputRequestMessage(request(), { replyToActivityId: "ROOT" });+ const card = body.attachments?.[0]?.content as {+ actions?: Array<{ data?: Record<string, unknown> }>;+ };++ expect(card.actions?.[0]?.data).toMatchObject({+ [TEAMS_HITL_DATA_KEY]: { replyToActivityId: "ROOT" },});});@@ -29,20 +47,22 @@ describe("Teams HITL helpers", () => {expect(card.body?.some((entry) => entry.id === TEAMS_HITL_CHOICE_INPUT_ID)).toBe(true);});- it("decodes message activity submit values", () => {- const activity = parseTeamsActivity(+ it("decodes message and invoke submission values", () => {+ const message = parseTeamsActivity(activityWithValue({- [TEAMS_HITL_DATA_KEY]: { requestId: "REQ", optionId: "deny" },+ [TEAMS_HITL_DATA_KEY]: {+ replyToActivityId: "ROOT",+ optionId: "deny",+ requestId: "REQ",+ },}),);- expect(activity && isTeamsInputResponseActivity(activity)).toBe(true);- expect(activity ? deriveTeamsInputResponses(activity) : []).toEqual([+ expect(message ? deriveTeamsInputResponses(message) : []).toEqual([{ optionId: "deny", requestId: "REQ" },]);- });+ expect(message ? readTeamsInputReplyToActivityId(message) : null).toBe("ROOT");- it("decodes adaptiveCard/action invoke values with freeform text", () => {- const activity = parseTeamsActivity({+ const invoke = parseTeamsActivity({...activityWithValue(undefined),name: "adaptiveCard/action",type: "invoke",@@ -55,18 +75,10 @@ describe("Teams HITL helpers", () => {},},});- expect(activity ? deriveTeamsInputResponses(activity) : []).toEqual([+ expect(invoke ? deriveTeamsInputResponses(invoke) : []).toEqual([{ requestId: "REQ", text: "freeform" },]);});-- it("builds Teams invoke responses", () => {- expect(teamsInvokeResponse({ message: "ok" })).toEqual({- statusCode: 200,- type: "application/vnd.microsoft.activity.message",- value: "ok",- });- });});function request(): InputRequest {diff --git a/packages/eve/src/public/channels/teams/hitl.ts b/packages/eve/src/public/channels/teams/hitl.tsindex 8e831b6dc..56983a734 100644--- a/packages/eve/src/public/channels/teams/hitl.ts+++ b/packages/eve/src/public/channels/teams/hitl.ts@@ -33,11 +33,16 @@ export const TEAMS_HITL_FREEFORM_INPUT_ID = "eve_freeform_text";/** Renders one input request as a Teams message body containing an Adaptive Card. */export function renderInputRequestMessage(request: InputRequest,- options: { readonly adaptiveCardVersion?: string } = {},+ options: {+ readonly adaptiveCardVersion?: string;+ readonly replyToActivityId?: string;+ } = {},): TeamsMessageBody {+ const details = formatApprovalInput(request);+ const renderedDetails = details ? truncate(details, TEAMS_ADAPTIVE_CARD_TEXT_MAX_LENGTH) : null;return {attachments: [renderInputRequestAttachment(request, options)],- text: request.prompt,+ text: renderedDetails ? `${request.prompt}\n\nTool input:\n${renderedDetails}` : request.prompt,};}@@ -48,17 +53,31 @@ export function renderInputRequestMessage(*/export function renderInputRequestAttachment(request: InputRequest,- options: { readonly adaptiveCardVersion?: string } = {},+ options: {+ readonly adaptiveCardVersion?: string;+ readonly replyToActivityId?: string;+ } = {},): TeamsAttachment {+ const details = formatApprovalInput(request);const card: Record<string, unknown> = {$schema: "http://adaptivecards.io/schemas/adaptive-card.json",- actions: renderActions(request),+ actions: renderActions(request, options.replyToActivityId),body: [{text: truncate(request.prompt, TEAMS_ADAPTIVE_CARD_TEXT_MAX_LENGTH),type: "TextBlock",wrap: true,},+ ...(details+ ? [+ {+ fontType: "Monospace",+ text: truncate(details, TEAMS_ADAPTIVE_CARD_TEXT_MAX_LENGTH),+ type: "TextBlock",+ wrap: true,+ },+ ]+ : []),...renderInputs(request),],type: "AdaptiveCard",@@ -145,6 +164,16 @@ export function deriveTeamsInputResponses(activity: TeamsActivity): readonly Inp* Defaults to statusCode 200 and message "Answer received."; `type` is always* the Teams activity-message content type.*/+/** Reads the recorded thread root carried by an eve HITL card submission. */+export function readTeamsInputReplyToActivityId(activity: TeamsActivity): string | null {+ const value = readActivityValue(activity);+ if (!value) return null;+ const payload = readHitlPayload(value);+ return payload && typeof payload.replyToActivityId === "string"+ ? payload.replyToActivityId+ : null;+}+export function teamsInvokeResponse(input: {readonly message?: string;@@ -188,15 +217,21 @@ function renderInputs(request: InputRequest): readonly Record<string, unknown>[]return [];}-function renderActions(request: InputRequest): readonly Record<string, unknown>[] {+function renderActions(+ request: InputRequest,+ replyToActivityId: string | undefined,+): readonly Record<string, unknown>[] {+ const payload = (optionId?: string): Record<string, unknown> => {+ const value: Record<string, unknown> = { requestId: request.requestId };+ if (replyToActivityId !== undefined) value.replyToActivityId = replyToActivityId;+ if (optionId !== undefined) value.optionId = optionId;+ return value;+ };const options = request.options;if (options && options.length > 0 && request.display !== "select") {return options.slice(0, TEAMS_ADAPTIVE_CARD_ACTION_LIMIT).map((option) => ({data: {- [TEAMS_HITL_DATA_KEY]: {- optionId: option.id,- requestId: request.requestId,- },+ [TEAMS_HITL_DATA_KEY]: payload(option.id),},title: truncate(option.label, TEAMS_ADAPTIVE_CARD_ACTION_TITLE_MAX_LENGTH),type: "Action.Submit",@@ -206,9 +241,7 @@ function renderActions(request: InputRequest): readonly Record<string, unknown>[return [{data: {- [TEAMS_HITL_DATA_KEY]: {- requestId: request.requestId,- },+ [TEAMS_HITL_DATA_KEY]: payload(),},title: "Submit",type: "Action.Submit",@@ -243,6 +276,19 @@ function readHitlPayload(value: Record<string, unknown>): Record<string, unknownreturn isObject(nested) ? nested : null;}+function formatApprovalInput(request: InputRequest): string | null {+ if (+ request.display !== "confirmation" ||+ request.options?.length !== 2 ||+ request.options[0]?.id !== "approve" ||+ request.options[1]?.id !== "deny"+ ) {+ return null;+ }+ const json = JSON.stringify(request.action.input, null, 2);+ return json === "{}" ? null : json;+}+function truncate(value: string, maxLength: number): string {if (value.length <= maxLength) return value;const sliceLength = Math.max(0, maxLength - 3);diff --git a/packages/eve/src/public/channels/teams/index.ts b/packages/eve/src/public/channels/teams/index.tsindex 7e8867ca4..f84f0b707 100644--- a/packages/eve/src/public/channels/teams/index.ts+++ b/packages/eve/src/public/channels/teams/index.ts@@ -24,6 +24,7 @@ export {type TeamsHandle,type TeamsInboundResult,type TeamsInboundResultOrPromise,+ type TeamsInputResponseResult,type TeamsInvokeResult,type TeamsInvokeResultOrPromise,type TeamsReceiveTarget,diff --git a/packages/eve/src/public/channels/teams/teamsChannel.test.ts b/packages/eve/src/public/channels/teams/teamsChannel.test.tsindex 69c1f5ee9..5c9851b62 100644--- a/packages/eve/src/public/channels/teams/teamsChannel.test.ts+++ b/packages/eve/src/public/channels/teams/teamsChannel.test.ts@@ -108,16 +108,21 @@ describe("teamsChannel", () => {expect(send).not.toHaveBeenCalled();});- it("handles Adaptive Card invoke HITL responses", async () => {+ it("resumes invoke HITL responses with the clicker's auth and recorded thread", async () => {const channel = teamsChannel({ credentials: { webhookVerifier: () => true } });const { response, send } = await firePost(channel, {...baseActivity({ conversationType: "channel" }),+ from: { aadObjectId: "AAD_USER", id: "USER", name: "Ada" },name: "adaptiveCard/action",type: "invoke",value: {action: {data: {- eve_input: { requestId: "REQ", optionId: "approve" },+ eve_input: {+ replyToActivityId: "THREAD_ROOT",+ requestId: "REQ",+ optionId: "approve",+ },},},},@@ -127,12 +132,81 @@ describe("teamsChannel", () => {expect(send).toHaveBeenCalledWith({ inputResponses: [{ optionId: "approve", requestId: "REQ" }] },expect.objectContaining({- auth: null,- continuationToken: "TENANT:CONV:ACTIVITY_1",+ auth: expect.objectContaining({ subject: "AAD_USER" }),+ continuationToken: "TENANT:CONV:THREAD_ROOT",}),);});+ it("handles unmentioned message-form HITL responses before the mention gate", async () => {+ const onMessage = vi.fn(() => null);+ const raw = messageActivity({ conversationType: "channel" });+ raw.entities = [];+ raw.text = "";+ raw.value = {+ eve_input: {+ replyToActivityId: "THREAD_ROOT",+ requestId: "REQ",+ optionId: "deny",+ },+ };+ const channel = teamsChannel({+ credentials: { webhookVerifier: () => true },+ onInputResponse: () => ({ auth: null }),+ onMessage,+ });++ const { send } = await firePost(channel, raw);++ expect(onMessage).not.toHaveBeenCalled();+ expect(send).toHaveBeenCalledWith(+ { inputResponses: [{ optionId: "deny", requestId: "REQ" }] },+ expect.objectContaining({ continuationToken: "TENANT:CONV:THREAD_ROOT" }),+ );+ });++ it("rejects HITL responses when a custom message gate has no input gate", async () => {+ const channel = teamsChannel({+ credentials: { webhookVerifier: () => true },+ onMessage: () => ({ auth: null }),+ });+ const { send } = await firePost(channel, {+ ...baseActivity({ conversationType: "channel" }),+ name: "adaptiveCard/action",+ type: "invoke",+ value: {+ action: {+ data: {+ eve_input: {+ replyToActivityId: "THREAD_ROOT",+ requestId: "REQ",+ optionId: "approve",+ },+ },+ },+ },+ });++ expect(send).not.toHaveBeenCalled();+ });++ it("normalizes suffixed channel conversation ids", async () => {+ const channel = teamsChannel({+ credentials: { webhookVerifier: () => true },+ onMessage: () => ({ auth: null }),+ });+ const raw = messageActivity({ conversationType: "channel" });+ raw.conversation = { conversationType: "channel", id: "CONV;messageid=THREAD_ROOT" };+ raw.replyToId = "VOLATILE_ACTIVITY";++ const { send } = await firePost(channel, raw);++ expect(send.mock.calls[0]![1]).toMatchObject({+ continuationToken: "TENANT:CONV:THREAD_ROOT",+ state: { replyToActivityId: "THREAD_ROOT" },+ });+ });+it("receive starts proactive sessions and anchors initial channel messages", async () => {const requests: Array<{ body: unknown; url: string }> = [];const channel = teamsChannel({diff --git a/packages/eve/src/public/channels/teams/teamsChannel.ts b/packages/eve/src/public/channels/teams/teamsChannel.tsindex 1be203e76..406dd7de6 100644--- a/packages/eve/src/public/channels/teams/teamsChannel.ts+++ b/packages/eve/src/public/channels/teams/teamsChannel.ts@@ -16,6 +16,7 @@ import {} from "#public/channels/teams/attachments.js";import {callTeamsConnectorApi,+ normalizeTeamsContinuationAddress,normalizeTeamsPostInput,replyToTeamsActivity,sendTeamsActivity,@@ -34,11 +35,13 @@ import {import {defaultEvents,defaultOnMessage,+ defaultTeamsAuth,teamsMentionUser,} from "#public/channels/teams/defaults.js";import {deriveTeamsInputResponses,isTeamsInputResponseActivity,+ readTeamsInputReplyToActivityId,teamsInvokeResponse,} from "#public/channels/teams/hitl.js";import {@@ -131,6 +134,9 @@ export type TeamsInboundResult = {/** Sync or async {@link TeamsInboundResult}. */export type TeamsInboundResultOrPromise = TeamsInboundResult | Promise<TeamsInboundResult>;+/** Result of a Teams HITL submission authorization hook. Return `null` to reject. */+export type TeamsInputResponseResult = { readonly auth: SessionAuthContext | null } | null;+/** Result of a non-HITL Teams invoke hook. A `Response` returns verbatim, a plain object is JSON-encoded as the body, and `null`/`undefined` yields a 200 OK. */export type TeamsInvokeResult = Record<string, unknown> | Response | null | undefined;@@ -183,6 +189,12 @@ export interface TeamsChannelConfig {/** Inbound message hook. Defaults to user-scoped auth and mention-gated dispatch outside personal chats. */onMessage?(ctx: TeamsContext, message: TeamsMessageActivity): TeamsInboundResultOrPromise;+ /** Authorizes HITL card submissions. Defaults to the submitting Teams user. */+ onInputResponse?(+ ctx: TeamsContext,+ activity: TeamsInvokeActivity | TeamsMessageActivity,+ ): TeamsInputResponseResult | Promise<TeamsInputResponseResult>;+/** Handler for non-HITL Teams invoke activities. Return a body, a Response, or `null`/`undefined` for a 200 OK. */onInvoke?(ctx: TeamsContext, activity: TeamsInvokeActivity): TeamsInvokeResultOrPromise;}@@ -246,6 +258,9 @@ export interface TeamsChannel extends Channel<export function teamsChannel(config: TeamsChannelConfig = {}): TeamsChannel {const filesPolicy = normalizeTeamsFilesPolicy(config.files);const onMessage = config.onMessage ?? defaultOnMessage;+ const onInputResponse =+ config.onInputResponse ??+ (config.onMessage === undefined ? defaultOnInputResponse : rejectInput);const mergedEvents: TeamsChannelEvents = { ...defaultEvents, ...config.events };return defineChannel<@@ -285,13 +300,15 @@ export function teamsChannel(config: TeamsChannelConfig = {}): TeamsChannel {if (activity.type === "message") {waitUntil(- dispatchMessage({- activity,- config,- filesPolicy,- onMessage,- send,- }),+ isTeamsInputResponseActivity(activity)+ ? dispatchInputResponses({ activity, config, onInputResponse, send })+ : dispatchMessage({+ activity,+ config,+ filesPolicy,+ onMessage,+ send,+ }),);return teamsOk();}@@ -300,6 +317,7 @@ export function teamsChannel(config: TeamsChannelConfig = {}): TeamsChannel {return handleInvoke({activity,config,+ onInputResponse,send,waitUntil,});@@ -585,6 +603,7 @@ async function dispatchMessage(input: {async function handleInvoke(input: {readonly activity: TeamsInvokeActivity;readonly config: TeamsChannelConfig;+ readonly onInputResponse: NonNullable<TeamsChannelConfig["onInputResponse"]>;readonly send: SendFn<TeamsChannelState>;readonly waitUntil: (task: Promise<unknown>) => void;}): Promise<Response> {@@ -592,6 +611,8 @@ async function handleInvoke(input: {input.waitUntil(dispatchInputResponses({activity: input.activity,+ config: input.config,+ onInputResponse: input.onInputResponse,send: input.send,}),);@@ -608,17 +629,28 @@ async function handleInvoke(input: {async function dispatchInputResponses(input: {readonly activity: TeamsInvokeActivity | TeamsMessageActivity;+ readonly config: TeamsChannelConfig;+ readonly onInputResponse: NonNullable<TeamsChannelConfig["onInputResponse"]>;readonly send: SendFn<TeamsChannelState>;}): Promise<void> {const inputResponses = deriveTeamsInputResponses(input.activity as TeamsActivity);if (inputResponses.length === 0) return;const state = stateFromActivity(input.activity);+ const ctx = buildTeamsBinding({ config: input.config, state });+ let result: TeamsInputResponseResult;+ try {+ result = await input.onInputResponse(ctx, input.activity);+ } catch (error) {+ log.error("Teams input response authorization failed", { error });+ return;+ }+ if (result === null) return;try {await input.send({ inputResponses },{- auth: null,- continuationToken: stateToken(state),+ auth: result.auth,+ continuationToken: resolveInputContinuationToken(input.activity, state),state,},);@@ -630,13 +662,17 @@ async function dispatchInputResponses(input: {function stateFromActivity(activity: TeamsMessageActivity | TeamsInvokeActivity,): TeamsChannelState {+ const address = normalizeTeamsContinuationAddress({+ conversationId: activity.conversation.id,+ replyToActivityId: teamsThreadRootActivityId(activity),+ });return {bot: activity.recipient,channelId: activity.teamsChannelId ?? null,conversationId: activity.conversation.id,conversationType: activity.conversationType ?? activity.scope,pendingAuthActivityId: null,- replyToActivityId: teamsThreadRootActivityId(activity),+ replyToActivityId: address.replyToActivityId,serviceUrl: activity.serviceUrl,teamId: activity.teamId ?? null,tenantId: activity.tenantId ?? null,@@ -644,6 +680,30 @@ function stateFromActivity(};}+function resolveInputContinuationToken(+ activity: TeamsMessageActivity | TeamsInvokeActivity,+ state: TeamsChannelState,+): string {+ const replyToActivityId = readTeamsInputReplyToActivityId(activity);+ if (replyToActivityId === null) return stateToken(state);+ return teamsContinuationToken({+ conversationId: activity.conversation.id,+ replyToActivityId,+ tenantId: activity.tenantId,+ });+}++function defaultOnInputResponse(+ _ctx: TeamsContext,+ activity: TeamsInvokeActivity | TeamsMessageActivity,+): TeamsInputResponseResult {+ return { auth: defaultTeamsAuth(activity) };+}++function rejectInput(): null {+ return null;+}+function initialTeamsState(): TeamsChannelState {return {bot: null,