@gakr-gakr/msteams 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api.ts +3 -0
- package/autobot.plugin.json +15 -0
- package/channel-config-api.ts +1 -0
- package/channel-plugin-api.ts +2 -0
- package/config-api.ts +4 -0
- package/contract-api.ts +4 -0
- package/index.ts +20 -0
- package/package.json +72 -0
- package/runtime-api.ts +66 -0
- package/secret-contract-api.ts +5 -0
- package/setup-entry.ts +13 -0
- package/setup-plugin-api.ts +3 -0
- package/src/ai-entity.ts +7 -0
- package/src/approval-auth.ts +44 -0
- package/src/attachments/bot-framework.ts +348 -0
- package/src/attachments/download.ts +328 -0
- package/src/attachments/graph.ts +489 -0
- package/src/attachments/html.ts +122 -0
- package/src/attachments/payload.ts +14 -0
- package/src/attachments/remote-media.ts +86 -0
- package/src/attachments/shared.ts +655 -0
- package/src/attachments/types.ts +47 -0
- package/src/attachments.ts +18 -0
- package/src/channel-api.ts +1 -0
- package/src/channel.runtime.ts +56 -0
- package/src/channel.setup.ts +77 -0
- package/src/channel.ts +1176 -0
- package/src/config-schema.ts +6 -0
- package/src/config-ui-hints.ts +40 -0
- package/src/conversation-store-fs.ts +149 -0
- package/src/conversation-store-helpers.ts +105 -0
- package/src/conversation-store-memory.ts +51 -0
- package/src/conversation-store.ts +71 -0
- package/src/directory-live.ts +111 -0
- package/src/doctor.ts +27 -0
- package/src/errors.ts +270 -0
- package/src/feedback-reflection-prompt.ts +117 -0
- package/src/feedback-reflection-store.ts +113 -0
- package/src/feedback-reflection.ts +271 -0
- package/src/file-consent-helpers.ts +115 -0
- package/src/file-consent-invoke.ts +150 -0
- package/src/file-consent.ts +223 -0
- package/src/graph-chat.ts +36 -0
- package/src/graph-group-management.ts +168 -0
- package/src/graph-members.ts +48 -0
- package/src/graph-messages.ts +534 -0
- package/src/graph-teams.ts +114 -0
- package/src/graph-thread.ts +146 -0
- package/src/graph-upload.ts +531 -0
- package/src/graph-users.ts +29 -0
- package/src/graph.ts +308 -0
- package/src/inbound.ts +148 -0
- package/src/index.ts +4 -0
- package/src/media-helpers.ts +105 -0
- package/src/mentions.ts +114 -0
- package/src/messenger.ts +608 -0
- package/src/monitor-handler/access.ts +136 -0
- package/src/monitor-handler/inbound-media.ts +180 -0
- package/src/monitor-handler/message-handler-mock-support.test-support.ts +28 -0
- package/src/monitor-handler/message-handler.test-support.ts +102 -0
- package/src/monitor-handler/message-handler.ts +1015 -0
- package/src/monitor-handler/reaction-handler.ts +124 -0
- package/src/monitor-handler/thread-session.ts +30 -0
- package/src/monitor-handler.ts +538 -0
- package/src/monitor-handler.types.ts +27 -0
- package/src/monitor-types.ts +6 -0
- package/src/monitor.ts +476 -0
- package/src/oauth.flow.ts +77 -0
- package/src/oauth.shared.ts +37 -0
- package/src/oauth.token.ts +162 -0
- package/src/oauth.ts +130 -0
- package/src/outbound.ts +198 -0
- package/src/pending-uploads-fs.ts +235 -0
- package/src/pending-uploads.ts +121 -0
- package/src/policy.ts +245 -0
- package/src/polls-store-memory.ts +32 -0
- package/src/polls.ts +312 -0
- package/src/presentation.ts +93 -0
- package/src/probe.ts +132 -0
- package/src/reply-dispatcher.ts +523 -0
- package/src/reply-stream-controller.ts +334 -0
- package/src/resolve-allowlist.ts +309 -0
- package/src/revoked-context.ts +17 -0
- package/src/runtime.ts +12 -0
- package/src/sdk-types.ts +59 -0
- package/src/sdk.ts +916 -0
- package/src/secret-contract.ts +49 -0
- package/src/secret-input.ts +7 -0
- package/src/send-context.ts +269 -0
- package/src/send.ts +697 -0
- package/src/sent-message-cache.ts +174 -0
- package/src/session-route.ts +40 -0
- package/src/setup-core.ts +162 -0
- package/src/setup-surface.ts +319 -0
- package/src/sso-token-store.ts +166 -0
- package/src/sso.ts +300 -0
- package/src/storage.ts +25 -0
- package/src/store-fs.ts +42 -0
- package/src/streaming-message.ts +327 -0
- package/src/thread-parent-context.ts +159 -0
- package/src/token-response.ts +11 -0
- package/src/token.ts +194 -0
- package/src/user-agent.ts +53 -0
- package/src/webhook-timeouts.ts +27 -0
- package/src/welcome-card.ts +57 -0
- package/test-api.ts +1 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,523 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildChannelProgressDraftLine,
|
|
3
|
+
buildChannelProgressDraftLineForEntry,
|
|
4
|
+
resolveChannelPreviewStreamMode,
|
|
5
|
+
resolveChannelStreamingBlockEnabled,
|
|
6
|
+
} from "autobot/plugin-sdk/channel-streaming";
|
|
7
|
+
import { normalizeOptionalLowercaseString } from "autobot/plugin-sdk/string-coerce-runtime";
|
|
8
|
+
import {
|
|
9
|
+
createChannelMessageReplyPipeline,
|
|
10
|
+
logTypingFailure,
|
|
11
|
+
resolveChannelMediaMaxBytes,
|
|
12
|
+
type AutoBotConfig,
|
|
13
|
+
type MSTeamsReplyStyle,
|
|
14
|
+
type RuntimeEnv,
|
|
15
|
+
} from "../runtime-api.js";
|
|
16
|
+
import type { MSTeamsAccessTokenProvider } from "./attachments/types.js";
|
|
17
|
+
import type { StoredConversationReference } from "./conversation-store.js";
|
|
18
|
+
import {
|
|
19
|
+
classifyMSTeamsSendError,
|
|
20
|
+
formatMSTeamsSendErrorHint,
|
|
21
|
+
formatUnknownError,
|
|
22
|
+
} from "./errors.js";
|
|
23
|
+
import {
|
|
24
|
+
buildConversationReference,
|
|
25
|
+
type MSTeamsAdapter,
|
|
26
|
+
type MSTeamsRenderedMessage,
|
|
27
|
+
renderReplyPayloadsToMessages,
|
|
28
|
+
sendMSTeamsMessages,
|
|
29
|
+
} from "./messenger.js";
|
|
30
|
+
import type { MSTeamsMonitorLogger } from "./monitor-types.js";
|
|
31
|
+
import { createTeamsReplyStreamController } from "./reply-stream-controller.js";
|
|
32
|
+
import { withRevokedProxyFallback } from "./revoked-context.js";
|
|
33
|
+
import { getMSTeamsRuntime } from "./runtime.js";
|
|
34
|
+
import type { MSTeamsTurnContext } from "./sdk-types.js";
|
|
35
|
+
|
|
36
|
+
export { pickInformativeStatusText } from "./reply-stream-controller.js";
|
|
37
|
+
|
|
38
|
+
export function createMSTeamsReplyDispatcher(params: {
|
|
39
|
+
cfg: AutoBotConfig;
|
|
40
|
+
agentId: string;
|
|
41
|
+
sessionKey: string;
|
|
42
|
+
accountId?: string;
|
|
43
|
+
runtime: RuntimeEnv;
|
|
44
|
+
log: MSTeamsMonitorLogger;
|
|
45
|
+
adapter: MSTeamsAdapter;
|
|
46
|
+
appId: string;
|
|
47
|
+
conversationRef: StoredConversationReference;
|
|
48
|
+
context: MSTeamsTurnContext;
|
|
49
|
+
replyStyle: MSTeamsReplyStyle;
|
|
50
|
+
textLimit: number;
|
|
51
|
+
onSentMessageIds?: (ids: string[]) => void;
|
|
52
|
+
tokenProvider?: MSTeamsAccessTokenProvider;
|
|
53
|
+
sharePointSiteId?: string;
|
|
54
|
+
}) {
|
|
55
|
+
const core = getMSTeamsRuntime();
|
|
56
|
+
const msteamsCfg = params.cfg.channels?.msteams;
|
|
57
|
+
const conversationType = normalizeOptionalLowercaseString(
|
|
58
|
+
params.conversationRef.conversation?.conversationType,
|
|
59
|
+
);
|
|
60
|
+
const isTypingSupported = conversationType === "personal" || conversationType === "groupchat";
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Keepalive cadence for the typing indicator while the bot is running
|
|
64
|
+
* (including long tool chains). Bot Framework 1:1 TurnContext proxies
|
|
65
|
+
* expire after ~30s of inactivity; sending a typing activity every 8s
|
|
66
|
+
* keeps the proxy alive so the post-tool reply can still land via the
|
|
67
|
+
* turn context. Sits in the middle of the 5-10s range recommended in
|
|
68
|
+
* #59731.
|
|
69
|
+
*/
|
|
70
|
+
const TYPING_KEEPALIVE_INTERVAL_MS = 8_000;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* TTL ceiling for the typing keepalive loop. The default in
|
|
74
|
+
* createTypingCallbacks is 60s, which is too short for the Teams long tool
|
|
75
|
+
* chains described in #59731 (60s+ total runs are common). Give tool
|
|
76
|
+
* chains up to 10 minutes before auto-stopping the keepalive.
|
|
77
|
+
*/
|
|
78
|
+
const TYPING_KEEPALIVE_MAX_DURATION_MS = 10 * 60_000;
|
|
79
|
+
|
|
80
|
+
// Forward reference: sendTypingIndicator is built before the stream
|
|
81
|
+
// controller exists, but the keepalive tick needs to check stream state so
|
|
82
|
+
// we don't overlay "..." typing on the visible streaming card. The ref is
|
|
83
|
+
// wired once the stream controller is constructed below.
|
|
84
|
+
const streamActiveRef: { current: () => boolean } = { current: () => false };
|
|
85
|
+
|
|
86
|
+
const rawSendTypingIndicator = async () => {
|
|
87
|
+
await withRevokedProxyFallback({
|
|
88
|
+
run: async () => {
|
|
89
|
+
await params.context.sendActivity({ type: "typing" });
|
|
90
|
+
},
|
|
91
|
+
onRevoked: async () => {
|
|
92
|
+
const baseRef = buildConversationReference(params.conversationRef);
|
|
93
|
+
await params.adapter.continueConversation(
|
|
94
|
+
params.appId,
|
|
95
|
+
{ ...baseRef, activityId: undefined },
|
|
96
|
+
async (ctx) => {
|
|
97
|
+
await ctx.sendActivity({ type: "typing" });
|
|
98
|
+
},
|
|
99
|
+
);
|
|
100
|
+
},
|
|
101
|
+
onRevokedLog: () => {
|
|
102
|
+
params.log.debug?.("turn context revoked, sending typing via proactive messaging");
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const sendTypingIndicator = isTypingSupported
|
|
108
|
+
? async () => {
|
|
109
|
+
// While the streaming card is actively being updated the user
|
|
110
|
+
// already sees a live indicator in the stream — don't overlay a
|
|
111
|
+
// plain "..." typing on top of it. Between segments (tool chain)
|
|
112
|
+
// the stream is finalized, so typing indicators are appropriate
|
|
113
|
+
// and they are what keep the TurnContext alive. See #59731.
|
|
114
|
+
if (streamActiveRef.current()) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
await rawSendTypingIndicator();
|
|
118
|
+
}
|
|
119
|
+
: async () => {};
|
|
120
|
+
|
|
121
|
+
const { onModelSelected, typingCallbacks, ...replyPipeline } = createChannelMessageReplyPipeline({
|
|
122
|
+
cfg: params.cfg,
|
|
123
|
+
agentId: params.agentId,
|
|
124
|
+
channel: "msteams",
|
|
125
|
+
accountId: params.accountId,
|
|
126
|
+
typing: {
|
|
127
|
+
start: sendTypingIndicator,
|
|
128
|
+
keepaliveIntervalMs: TYPING_KEEPALIVE_INTERVAL_MS,
|
|
129
|
+
maxDurationMs: TYPING_KEEPALIVE_MAX_DURATION_MS,
|
|
130
|
+
onStartError: (err) => {
|
|
131
|
+
logTypingFailure({
|
|
132
|
+
log: (message) => params.log.debug?.(message),
|
|
133
|
+
channel: "msteams",
|
|
134
|
+
action: "start",
|
|
135
|
+
error: err,
|
|
136
|
+
});
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
const chunkMode = core.channel.text.resolveChunkMode(params.cfg, "msteams");
|
|
142
|
+
const tableMode = core.channel.text.resolveMarkdownTableMode({
|
|
143
|
+
cfg: params.cfg,
|
|
144
|
+
channel: "msteams",
|
|
145
|
+
});
|
|
146
|
+
const mediaMaxBytes = resolveChannelMediaMaxBytes({
|
|
147
|
+
cfg: params.cfg,
|
|
148
|
+
resolveChannelLimitMb: ({ cfg }) => cfg.channels?.msteams?.mediaMaxMb,
|
|
149
|
+
});
|
|
150
|
+
const feedbackLoopEnabled = params.cfg.channels?.msteams?.feedbackEnabled !== false;
|
|
151
|
+
const streamController = createTeamsReplyStreamController({
|
|
152
|
+
conversationType,
|
|
153
|
+
context: params.context,
|
|
154
|
+
feedbackLoopEnabled,
|
|
155
|
+
log: params.log,
|
|
156
|
+
msteamsConfig: msteamsCfg,
|
|
157
|
+
progressSeed: `${params.accountId ?? "default"}:${params.conversationRef.conversation?.id ?? ""}`,
|
|
158
|
+
});
|
|
159
|
+
// Wire the forward-declared gate used by sendTypingIndicator.
|
|
160
|
+
streamActiveRef.current = () => streamController.isStreamActive();
|
|
161
|
+
|
|
162
|
+
const teamsStreamMode = resolveChannelPreviewStreamMode(msteamsCfg, "partial");
|
|
163
|
+
const resolvedBlockStreamingEnabled =
|
|
164
|
+
teamsStreamMode === "block" ? true : resolveChannelStreamingBlockEnabled(msteamsCfg);
|
|
165
|
+
const blockStreamingEnabled = resolvedBlockStreamingEnabled ?? false;
|
|
166
|
+
const typingIndicatorEnabled =
|
|
167
|
+
typeof msteamsCfg?.typingIndicator === "boolean" ? msteamsCfg.typingIndicator : true;
|
|
168
|
+
|
|
169
|
+
const pendingMessages: MSTeamsRenderedMessage[] = [];
|
|
170
|
+
|
|
171
|
+
const sendMessages = async (messages: MSTeamsRenderedMessage[]): Promise<string[]> => {
|
|
172
|
+
return sendMSTeamsMessages({
|
|
173
|
+
replyStyle: params.replyStyle,
|
|
174
|
+
adapter: params.adapter,
|
|
175
|
+
appId: params.appId,
|
|
176
|
+
conversationRef: params.conversationRef,
|
|
177
|
+
context: params.context,
|
|
178
|
+
messages,
|
|
179
|
+
retry: {},
|
|
180
|
+
onRetry: (event) => {
|
|
181
|
+
params.log.debug?.("retrying send", {
|
|
182
|
+
replyStyle: params.replyStyle,
|
|
183
|
+
...event,
|
|
184
|
+
});
|
|
185
|
+
},
|
|
186
|
+
tokenProvider: params.tokenProvider,
|
|
187
|
+
sharePointSiteId: params.sharePointSiteId,
|
|
188
|
+
mediaMaxBytes,
|
|
189
|
+
feedbackLoopEnabled,
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const queueDeliveryFailureSystemEvent = (failure: {
|
|
194
|
+
failed: number;
|
|
195
|
+
total: number;
|
|
196
|
+
error: unknown;
|
|
197
|
+
}) => {
|
|
198
|
+
const classification = classifyMSTeamsSendError(failure.error);
|
|
199
|
+
const errorText = formatUnknownError(failure.error);
|
|
200
|
+
const failedAll = failure.failed >= failure.total;
|
|
201
|
+
const summary = failedAll
|
|
202
|
+
? "the previous reply was not delivered"
|
|
203
|
+
: `${failure.failed} of ${failure.total} message blocks were not delivered`;
|
|
204
|
+
const sentences = [
|
|
205
|
+
`Microsoft Teams delivery failed: ${summary}.`,
|
|
206
|
+
`The user may not have received ${failedAll ? "that reply" : "the full reply"}.`,
|
|
207
|
+
`Error: ${errorText}.`,
|
|
208
|
+
classification.statusCode != null ? `Status: ${classification.statusCode}.` : undefined,
|
|
209
|
+
classification.kind === "transient" || classification.kind === "throttled"
|
|
210
|
+
? "Retrying later may succeed."
|
|
211
|
+
: undefined,
|
|
212
|
+
].filter(Boolean);
|
|
213
|
+
core.system.enqueueSystemEvent(sentences.join(" "), {
|
|
214
|
+
sessionKey: params.sessionKey,
|
|
215
|
+
contextKey: `msteams:delivery-failure:${params.conversationRef.conversation?.id ?? "unknown"}`,
|
|
216
|
+
});
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const flushPendingMessages = async () => {
|
|
220
|
+
if (pendingMessages.length === 0) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
const toSend = pendingMessages.splice(0);
|
|
224
|
+
const total = toSend.length;
|
|
225
|
+
let ids: string[];
|
|
226
|
+
try {
|
|
227
|
+
ids = await sendMessages(toSend);
|
|
228
|
+
} catch (batchError) {
|
|
229
|
+
ids = [];
|
|
230
|
+
let failed = 0;
|
|
231
|
+
let lastFailedError: unknown = batchError;
|
|
232
|
+
for (const msg of toSend) {
|
|
233
|
+
try {
|
|
234
|
+
const msgIds = await sendMessages([msg]);
|
|
235
|
+
ids.push(...msgIds);
|
|
236
|
+
} catch (msgError) {
|
|
237
|
+
failed += 1;
|
|
238
|
+
lastFailedError = msgError;
|
|
239
|
+
params.log.debug?.("individual message send failed, continuing with remaining blocks");
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
if (failed > 0) {
|
|
243
|
+
params.log.warn?.(`failed to deliver ${failed} of ${total} message blocks`, {
|
|
244
|
+
failed,
|
|
245
|
+
total,
|
|
246
|
+
});
|
|
247
|
+
queueDeliveryFailureSystemEvent({
|
|
248
|
+
failed,
|
|
249
|
+
total,
|
|
250
|
+
error: lastFailedError,
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
if (ids.length > 0) {
|
|
255
|
+
params.onSentMessageIds?.(ids);
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
const {
|
|
260
|
+
dispatcher,
|
|
261
|
+
replyOptions,
|
|
262
|
+
markDispatchIdle: baseMarkDispatchIdle,
|
|
263
|
+
} = core.channel.reply.createReplyDispatcherWithTyping({
|
|
264
|
+
...replyPipeline,
|
|
265
|
+
humanDelay: core.channel.reply.resolveHumanDelayConfig(params.cfg, params.agentId),
|
|
266
|
+
onReplyStart: async () => {
|
|
267
|
+
await streamController.onReplyStart();
|
|
268
|
+
// Always start the typing keepalive loop when typing is enabled and
|
|
269
|
+
// supported by this conversation type. The sendTypingIndicator gate
|
|
270
|
+
// skips actual sends while the stream card is visually active, so
|
|
271
|
+
// during the first text segment the user only sees the streaming UI.
|
|
272
|
+
// Once the stream finalizes (between segments / during tool chains),
|
|
273
|
+
// the loop starts sending typing activities and keeps the Bot Framework
|
|
274
|
+
// TurnContext alive so the post-tool reply can still land. See #59731.
|
|
275
|
+
if (typingIndicatorEnabled) {
|
|
276
|
+
await typingCallbacks?.onReplyStart?.();
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
typingCallbacks,
|
|
280
|
+
deliver: async (payload) => {
|
|
281
|
+
const preparedPayload = await streamController.preparePayload(payload);
|
|
282
|
+
if (!preparedPayload) {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const messages = renderReplyPayloadsToMessages([preparedPayload], {
|
|
287
|
+
textChunkLimit: params.textLimit,
|
|
288
|
+
chunkText: true,
|
|
289
|
+
mediaMode: "split",
|
|
290
|
+
tableMode,
|
|
291
|
+
chunkMode,
|
|
292
|
+
});
|
|
293
|
+
pendingMessages.push(...messages);
|
|
294
|
+
|
|
295
|
+
// When block streaming is enabled, flush immediately so blocks are
|
|
296
|
+
// delivered progressively instead of batching until markDispatchIdle.
|
|
297
|
+
if (blockStreamingEnabled) {
|
|
298
|
+
await flushPendingMessages();
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
onError: (err, info) => {
|
|
302
|
+
const errMsg = formatUnknownError(err);
|
|
303
|
+
const classification = classifyMSTeamsSendError(err);
|
|
304
|
+
const hint = formatMSTeamsSendErrorHint(classification);
|
|
305
|
+
params.runtime.error?.(
|
|
306
|
+
`msteams ${info.kind} reply failed: ${errMsg}${hint ? ` (${hint})` : ""}`,
|
|
307
|
+
);
|
|
308
|
+
params.log.error("reply failed", {
|
|
309
|
+
kind: info.kind,
|
|
310
|
+
error: errMsg,
|
|
311
|
+
classification,
|
|
312
|
+
hint,
|
|
313
|
+
});
|
|
314
|
+
},
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
const markDispatchIdle = (): Promise<void> => {
|
|
318
|
+
return flushPendingMessages()
|
|
319
|
+
.catch((err) => {
|
|
320
|
+
const errMsg = formatUnknownError(err);
|
|
321
|
+
const classification = classifyMSTeamsSendError(err);
|
|
322
|
+
const hint = formatMSTeamsSendErrorHint(classification);
|
|
323
|
+
params.runtime.error?.(`msteams flush reply failed: ${errMsg}${hint ? ` (${hint})` : ""}`);
|
|
324
|
+
params.log.error("flush reply failed", {
|
|
325
|
+
error: errMsg,
|
|
326
|
+
classification,
|
|
327
|
+
hint,
|
|
328
|
+
});
|
|
329
|
+
})
|
|
330
|
+
.then(() => {
|
|
331
|
+
return streamController.finalize().catch((err) => {
|
|
332
|
+
params.log.debug?.("stream finalize failed", { error: formatUnknownError(err) });
|
|
333
|
+
});
|
|
334
|
+
})
|
|
335
|
+
.finally(() => {
|
|
336
|
+
baseMarkDispatchIdle();
|
|
337
|
+
});
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
return {
|
|
341
|
+
dispatcher,
|
|
342
|
+
replyOptions: {
|
|
343
|
+
...replyOptions,
|
|
344
|
+
...(streamController.hasStream()
|
|
345
|
+
? {
|
|
346
|
+
onPartialReply: (payload: { text?: string }) =>
|
|
347
|
+
streamController.onPartialReply(payload),
|
|
348
|
+
onToolStart: async (payload: { name?: string }) => {
|
|
349
|
+
await streamController.noteProgressWork({ toolName: payload.name });
|
|
350
|
+
},
|
|
351
|
+
onItemEvent: async () => {
|
|
352
|
+
await streamController.noteProgressWork();
|
|
353
|
+
},
|
|
354
|
+
onPlanUpdate: async (payload: { phase?: string }) => {
|
|
355
|
+
if (payload.phase === "update") {
|
|
356
|
+
await streamController.noteProgressWork();
|
|
357
|
+
}
|
|
358
|
+
},
|
|
359
|
+
onApprovalEvent: async (payload: { phase?: string }) => {
|
|
360
|
+
if (payload.phase === "requested") {
|
|
361
|
+
await streamController.noteProgressWork();
|
|
362
|
+
}
|
|
363
|
+
},
|
|
364
|
+
onCommandOutput: async (payload: { phase?: string }) => {
|
|
365
|
+
if (payload.phase === "end") {
|
|
366
|
+
await streamController.noteProgressWork();
|
|
367
|
+
}
|
|
368
|
+
},
|
|
369
|
+
onPatchSummary: async (payload: { phase?: string }) => {
|
|
370
|
+
if (payload.phase === "end") {
|
|
371
|
+
await streamController.noteProgressWork();
|
|
372
|
+
}
|
|
373
|
+
},
|
|
374
|
+
}
|
|
375
|
+
: {}),
|
|
376
|
+
...(streamController.shouldSuppressDefaultToolProgressMessages()
|
|
377
|
+
? { suppressDefaultToolProgressMessages: true }
|
|
378
|
+
: {}),
|
|
379
|
+
...(streamController.shouldStreamPreviewToolProgress()
|
|
380
|
+
? {
|
|
381
|
+
onToolStart: async (payload: {
|
|
382
|
+
name?: string;
|
|
383
|
+
phase?: string;
|
|
384
|
+
args?: Record<string, unknown>;
|
|
385
|
+
detailMode?: "explain" | "raw";
|
|
386
|
+
}) => {
|
|
387
|
+
await streamController.pushProgressLine(
|
|
388
|
+
buildChannelProgressDraftLineForEntry(
|
|
389
|
+
msteamsCfg,
|
|
390
|
+
{
|
|
391
|
+
event: "tool",
|
|
392
|
+
name: payload.name,
|
|
393
|
+
phase: payload.phase,
|
|
394
|
+
args: payload.args,
|
|
395
|
+
},
|
|
396
|
+
payload.detailMode ? { detailMode: payload.detailMode } : undefined,
|
|
397
|
+
),
|
|
398
|
+
{ toolName: payload.name },
|
|
399
|
+
);
|
|
400
|
+
},
|
|
401
|
+
onItemEvent: async (payload: {
|
|
402
|
+
itemId?: string;
|
|
403
|
+
kind?: string;
|
|
404
|
+
progressText?: string;
|
|
405
|
+
meta?: string;
|
|
406
|
+
summary?: string;
|
|
407
|
+
title?: string;
|
|
408
|
+
name?: string;
|
|
409
|
+
phase?: string;
|
|
410
|
+
status?: string;
|
|
411
|
+
}) => {
|
|
412
|
+
await streamController.pushProgressLine(
|
|
413
|
+
buildChannelProgressDraftLineForEntry(msteamsCfg, {
|
|
414
|
+
event: "item",
|
|
415
|
+
itemId: payload.itemId,
|
|
416
|
+
itemKind: payload.kind,
|
|
417
|
+
title: payload.title,
|
|
418
|
+
name: payload.name,
|
|
419
|
+
phase: payload.phase,
|
|
420
|
+
status: payload.status,
|
|
421
|
+
summary: payload.summary,
|
|
422
|
+
progressText: payload.progressText,
|
|
423
|
+
meta: payload.meta,
|
|
424
|
+
}),
|
|
425
|
+
);
|
|
426
|
+
},
|
|
427
|
+
onPlanUpdate: async (payload: {
|
|
428
|
+
phase?: string;
|
|
429
|
+
title?: string;
|
|
430
|
+
explanation?: string;
|
|
431
|
+
steps?: string[];
|
|
432
|
+
}) => {
|
|
433
|
+
if (payload.phase !== "update") {
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
await streamController.pushProgressLine(
|
|
437
|
+
buildChannelProgressDraftLine({
|
|
438
|
+
event: "plan",
|
|
439
|
+
phase: payload.phase,
|
|
440
|
+
title: payload.title,
|
|
441
|
+
explanation: payload.explanation,
|
|
442
|
+
steps: payload.steps,
|
|
443
|
+
}),
|
|
444
|
+
);
|
|
445
|
+
},
|
|
446
|
+
onApprovalEvent: async (payload: {
|
|
447
|
+
phase?: string;
|
|
448
|
+
title?: string;
|
|
449
|
+
command?: string;
|
|
450
|
+
reason?: string;
|
|
451
|
+
message?: string;
|
|
452
|
+
}) => {
|
|
453
|
+
if (payload.phase !== "requested") {
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
await streamController.pushProgressLine(
|
|
457
|
+
buildChannelProgressDraftLine({
|
|
458
|
+
event: "approval",
|
|
459
|
+
phase: payload.phase,
|
|
460
|
+
title: payload.title,
|
|
461
|
+
command: payload.command,
|
|
462
|
+
reason: payload.reason,
|
|
463
|
+
message: payload.message,
|
|
464
|
+
}),
|
|
465
|
+
);
|
|
466
|
+
},
|
|
467
|
+
onCommandOutput: async (payload: {
|
|
468
|
+
phase?: string;
|
|
469
|
+
title?: string;
|
|
470
|
+
name?: string;
|
|
471
|
+
status?: string;
|
|
472
|
+
exitCode?: number | null;
|
|
473
|
+
}) => {
|
|
474
|
+
if (payload.phase !== "end") {
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
await streamController.pushProgressLine(
|
|
478
|
+
buildChannelProgressDraftLine({
|
|
479
|
+
event: "command-output",
|
|
480
|
+
phase: payload.phase,
|
|
481
|
+
title: payload.title,
|
|
482
|
+
name: payload.name,
|
|
483
|
+
status: payload.status,
|
|
484
|
+
exitCode: payload.exitCode,
|
|
485
|
+
}),
|
|
486
|
+
);
|
|
487
|
+
},
|
|
488
|
+
onPatchSummary: async (payload: {
|
|
489
|
+
phase?: string;
|
|
490
|
+
summary?: string;
|
|
491
|
+
title?: string;
|
|
492
|
+
name?: string;
|
|
493
|
+
added?: string[];
|
|
494
|
+
modified?: string[];
|
|
495
|
+
deleted?: string[];
|
|
496
|
+
}) => {
|
|
497
|
+
if (payload.phase !== "end") {
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
await streamController.pushProgressLine(
|
|
501
|
+
buildChannelProgressDraftLine({
|
|
502
|
+
event: "patch",
|
|
503
|
+
phase: payload.phase,
|
|
504
|
+
title: payload.title,
|
|
505
|
+
name: payload.name,
|
|
506
|
+
added: payload.added,
|
|
507
|
+
modified: payload.modified,
|
|
508
|
+
deleted: payload.deleted,
|
|
509
|
+
summary: payload.summary,
|
|
510
|
+
}),
|
|
511
|
+
);
|
|
512
|
+
},
|
|
513
|
+
}
|
|
514
|
+
: {}),
|
|
515
|
+
disableBlockStreaming:
|
|
516
|
+
typeof resolvedBlockStreamingEnabled === "boolean"
|
|
517
|
+
? !resolvedBlockStreamingEnabled
|
|
518
|
+
: undefined,
|
|
519
|
+
onModelSelected,
|
|
520
|
+
},
|
|
521
|
+
markDispatchIdle,
|
|
522
|
+
};
|
|
523
|
+
}
|