@kodelyth/msteams 2026.5.39 → 2026.5.42

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.
Files changed (208) hide show
  1. package/api.ts +3 -0
  2. package/channel-config-api.ts +1 -0
  3. package/channel-plugin-api.ts +2 -0
  4. package/config-api.ts +4 -0
  5. package/contract-api.ts +4 -0
  6. package/dist/api.js +3 -0
  7. package/dist/channel-BvTXHuGs.js +1161 -0
  8. package/dist/channel-config-api.js +2 -0
  9. package/dist/channel-plugin-api.js +2 -0
  10. package/dist/channel.runtime-NssGKZm5.js +650 -0
  11. package/dist/config-schema-Btk-XCOd.js +43 -0
  12. package/dist/contract-api.js +2 -0
  13. package/dist/graph-users-D-gKCguI.js +1411 -0
  14. package/dist/index.js +22 -0
  15. package/dist/oauth-BUxlphX3.js +114 -0
  16. package/dist/oauth.token-ebId9946.js +116 -0
  17. package/dist/probe-Cj2KsAGF.js +2190 -0
  18. package/dist/runtime-api-BL4DOWXD.js +28 -0
  19. package/dist/runtime-api.js +2 -0
  20. package/dist/secret-contract-Bo7kdUrT.js +35 -0
  21. package/dist/secret-contract-api.js +2 -0
  22. package/dist/setup-entry.js +15 -0
  23. package/dist/setup-plugin-api.js +64 -0
  24. package/dist/setup-surface-COTQDcTQ.js +531 -0
  25. package/dist/src-tvpsGYPV.js +4226 -0
  26. package/dist/test-api.js +2 -0
  27. package/index.ts +20 -0
  28. package/klaw.plugin.json +2 -726
  29. package/package.json +4 -4
  30. package/runtime-api.ts +66 -0
  31. package/secret-contract-api.ts +5 -0
  32. package/setup-entry.ts +13 -0
  33. package/setup-plugin-api.ts +3 -0
  34. package/src/ai-entity.ts +7 -0
  35. package/src/approval-auth.ts +44 -0
  36. package/src/attachments/bot-framework.test.ts +506 -0
  37. package/src/attachments/bot-framework.ts +348 -0
  38. package/src/attachments/download.ts +328 -0
  39. package/src/attachments/graph.test.ts +441 -0
  40. package/src/attachments/graph.ts +489 -0
  41. package/src/attachments/html.ts +122 -0
  42. package/src/attachments/payload.ts +14 -0
  43. package/src/attachments/remote-media.test.ts +187 -0
  44. package/src/attachments/remote-media.ts +86 -0
  45. package/src/attachments/shared.test.ts +547 -0
  46. package/src/attachments/shared.ts +655 -0
  47. package/src/attachments/types.ts +47 -0
  48. package/src/attachments.graph.test.ts +414 -0
  49. package/src/attachments.helpers.test.ts +245 -0
  50. package/src/attachments.test-helpers.ts +17 -0
  51. package/src/attachments.test.ts +754 -0
  52. package/src/attachments.ts +18 -0
  53. package/src/block-streaming-config.test.ts +61 -0
  54. package/src/channel-api.ts +1 -0
  55. package/src/channel.actions.test.ts +797 -0
  56. package/src/channel.directory.test.ts +176 -0
  57. package/src/channel.message-adapter.test.ts +227 -0
  58. package/src/channel.runtime.ts +56 -0
  59. package/src/channel.setup.ts +77 -0
  60. package/src/channel.test.ts +136 -0
  61. package/src/channel.ts +1176 -0
  62. package/src/config-schema.ts +6 -0
  63. package/src/config-ui-hints.ts +40 -0
  64. package/src/conversation-store-fs.test.ts +81 -0
  65. package/src/conversation-store-fs.ts +149 -0
  66. package/src/conversation-store-helpers.test.ts +202 -0
  67. package/src/conversation-store-helpers.ts +105 -0
  68. package/src/conversation-store-memory.ts +51 -0
  69. package/src/conversation-store.shared.test.ts +260 -0
  70. package/src/conversation-store.ts +71 -0
  71. package/src/directory-live.test.ts +156 -0
  72. package/src/directory-live.ts +111 -0
  73. package/src/doctor.ts +27 -0
  74. package/src/errors.test.ts +154 -0
  75. package/src/errors.ts +270 -0
  76. package/src/feedback-reflection-prompt.ts +117 -0
  77. package/src/feedback-reflection-store.ts +113 -0
  78. package/src/feedback-reflection.test.ts +237 -0
  79. package/src/feedback-reflection.ts +268 -0
  80. package/src/file-consent-helpers.test.ts +328 -0
  81. package/src/file-consent-helpers.ts +115 -0
  82. package/src/file-consent-invoke.ts +150 -0
  83. package/src/file-consent.test.ts +378 -0
  84. package/src/file-consent.ts +223 -0
  85. package/src/graph-chat.ts +36 -0
  86. package/src/graph-group-management.test.ts +332 -0
  87. package/src/graph-group-management.ts +168 -0
  88. package/src/graph-members.test.ts +89 -0
  89. package/src/graph-members.ts +48 -0
  90. package/src/graph-messages.actions.test.ts +253 -0
  91. package/src/graph-messages.read.test.ts +391 -0
  92. package/src/graph-messages.search.test.ts +227 -0
  93. package/src/graph-messages.test-helpers.ts +50 -0
  94. package/src/graph-messages.ts +534 -0
  95. package/src/graph-teams.test.ts +222 -0
  96. package/src/graph-teams.ts +114 -0
  97. package/src/graph-thread.test.ts +252 -0
  98. package/src/graph-thread.ts +146 -0
  99. package/src/graph-upload.test.ts +253 -0
  100. package/src/graph-upload.ts +531 -0
  101. package/src/graph-users.ts +29 -0
  102. package/src/graph.test.ts +540 -0
  103. package/src/graph.ts +308 -0
  104. package/src/inbound.test.ts +221 -0
  105. package/src/inbound.ts +148 -0
  106. package/src/index.ts +4 -0
  107. package/src/media-helpers.test.ts +220 -0
  108. package/src/media-helpers.ts +105 -0
  109. package/src/mentions.test.ts +254 -0
  110. package/src/mentions.ts +114 -0
  111. package/src/messenger.test.ts +961 -0
  112. package/src/messenger.ts +608 -0
  113. package/src/monitor-handler/access.ts +136 -0
  114. package/src/monitor-handler/inbound-media.test.ts +314 -0
  115. package/src/monitor-handler/inbound-media.ts +180 -0
  116. package/src/monitor-handler/message-handler-mock-support.test-support.ts +28 -0
  117. package/src/monitor-handler/message-handler.authz.test.ts +739 -0
  118. package/src/monitor-handler/message-handler.dm-media.test.ts +54 -0
  119. package/src/monitor-handler/message-handler.test-support.ts +99 -0
  120. package/src/monitor-handler/message-handler.thread-parent.test.ts +225 -0
  121. package/src/monitor-handler/message-handler.thread-session.test.ts +132 -0
  122. package/src/monitor-handler/message-handler.ts +1003 -0
  123. package/src/monitor-handler/reaction-handler.test.ts +325 -0
  124. package/src/monitor-handler/reaction-handler.ts +122 -0
  125. package/src/monitor-handler/thread-session.ts +30 -0
  126. package/src/monitor-handler.adaptive-card.test.ts +158 -0
  127. package/src/monitor-handler.feedback-authz.test.ts +357 -0
  128. package/src/monitor-handler.file-consent.test.ts +443 -0
  129. package/src/monitor-handler.sso.test.ts +576 -0
  130. package/src/monitor-handler.test-helpers.ts +181 -0
  131. package/src/monitor-handler.ts +538 -0
  132. package/src/monitor-handler.types.ts +27 -0
  133. package/src/monitor-types.ts +6 -0
  134. package/src/monitor.lifecycle.test.ts +457 -0
  135. package/src/monitor.test.ts +119 -0
  136. package/src/monitor.ts +476 -0
  137. package/src/oauth.flow.ts +77 -0
  138. package/src/oauth.shared.ts +37 -0
  139. package/src/oauth.test.ts +350 -0
  140. package/src/oauth.token.ts +162 -0
  141. package/src/oauth.ts +130 -0
  142. package/src/outbound.test.ts +400 -0
  143. package/src/outbound.ts +198 -0
  144. package/src/pending-uploads-fs.test.ts +261 -0
  145. package/src/pending-uploads-fs.ts +235 -0
  146. package/src/pending-uploads.test.ts +186 -0
  147. package/src/pending-uploads.ts +121 -0
  148. package/src/policy.test.ts +156 -0
  149. package/src/policy.ts +245 -0
  150. package/src/polls-store-memory.ts +32 -0
  151. package/src/polls.test.ts +169 -0
  152. package/src/polls.ts +312 -0
  153. package/src/presentation.ts +93 -0
  154. package/src/probe.test.ts +79 -0
  155. package/src/probe.ts +132 -0
  156. package/src/reply-dispatcher.test.ts +543 -0
  157. package/src/reply-dispatcher.ts +523 -0
  158. package/src/reply-stream-controller.test.ts +424 -0
  159. package/src/reply-stream-controller.ts +334 -0
  160. package/src/resolve-allowlist.test.ts +253 -0
  161. package/src/resolve-allowlist.ts +309 -0
  162. package/src/revoked-context.ts +17 -0
  163. package/src/runtime.ts +12 -0
  164. package/src/sdk-types.ts +59 -0
  165. package/src/sdk.test.ts +727 -0
  166. package/src/sdk.ts +916 -0
  167. package/src/secret-contract.ts +49 -0
  168. package/src/secret-input.ts +7 -0
  169. package/src/send-context.test.ts +93 -0
  170. package/src/send-context.ts +269 -0
  171. package/src/send.test.ts +588 -0
  172. package/src/send.ts +697 -0
  173. package/src/sent-message-cache.test.ts +106 -0
  174. package/src/sent-message-cache.ts +174 -0
  175. package/src/session-route.ts +40 -0
  176. package/src/setup-core.ts +162 -0
  177. package/src/setup-surface.test.ts +175 -0
  178. package/src/setup-surface.ts +319 -0
  179. package/src/sso-token-store.test.ts +74 -0
  180. package/src/sso-token-store.ts +166 -0
  181. package/src/sso.ts +300 -0
  182. package/src/storage.ts +25 -0
  183. package/src/store-fs.ts +42 -0
  184. package/src/streaming-message.test.ts +323 -0
  185. package/src/streaming-message.ts +327 -0
  186. package/src/test-runtime.ts +16 -0
  187. package/src/thread-parent-context.test.ts +224 -0
  188. package/src/thread-parent-context.ts +159 -0
  189. package/src/token-response.ts +11 -0
  190. package/src/token.test.ts +268 -0
  191. package/src/token.ts +194 -0
  192. package/src/user-agent.test.ts +121 -0
  193. package/src/user-agent.ts +53 -0
  194. package/src/webhook-timeouts.ts +27 -0
  195. package/src/welcome-card.test.ts +104 -0
  196. package/src/welcome-card.ts +57 -0
  197. package/test-api.ts +1 -0
  198. package/tsconfig.json +16 -0
  199. package/api.js +0 -7
  200. package/channel-config-api.js +0 -7
  201. package/channel-plugin-api.js +0 -7
  202. package/contract-api.js +0 -7
  203. package/index.js +0 -7
  204. package/runtime-api.js +0 -7
  205. package/secret-contract-api.js +0 -7
  206. package/setup-entry.js +0 -7
  207. package/setup-plugin-api.js +0 -7
  208. package/test-api.js +0 -7
@@ -0,0 +1,181 @@
1
+ import { vi } from "vitest";
2
+ import type { KlawConfig, PluginRuntime, RuntimeEnv } from "../runtime-api.js";
3
+ import type { MSTeamsConversationStore } from "./conversation-store.js";
4
+ import type { MSTeamsAdapter } from "./messenger.js";
5
+ import type { MSTeamsActivityHandler, MSTeamsMessageHandlerDeps } from "./monitor-handler.js";
6
+ import type { MSTeamsPollStore } from "./polls.js";
7
+ import { setMSTeamsRuntime } from "./runtime.js";
8
+
9
+ type RuntimeRoutePeer = { peer: { kind: string; id: string } };
10
+
11
+ type MSTeamsTestRuntimeOptions = {
12
+ enqueueSystemEvent?: ReturnType<typeof vi.fn>;
13
+ readAllowFromStore?: ReturnType<typeof vi.fn>;
14
+ upsertPairingRequest?: ReturnType<typeof vi.fn>;
15
+ recordInboundSession?: ReturnType<typeof vi.fn>;
16
+ resolveAgentRoute?: (params: RuntimeRoutePeer) => unknown;
17
+ hasControlCommand?: PluginRuntime["channel"]["text"]["hasControlCommand"];
18
+ resolveTextChunkLimit?: () => number;
19
+ resolveStorePath?: () => string;
20
+ };
21
+
22
+ export function installMSTeamsTestRuntime(options: MSTeamsTestRuntimeOptions = {}): void {
23
+ const runPrepared = vi.fn(
24
+ async (turn: Parameters<PluginRuntime["channel"]["turn"]["runPrepared"]>[0]) => {
25
+ await turn.recordInboundSession({
26
+ storePath: turn.storePath,
27
+ sessionKey: turn.ctxPayload.SessionKey ?? turn.routeSessionKey,
28
+ ctx: turn.ctxPayload,
29
+ groupResolution: turn.record?.groupResolution,
30
+ createIfMissing: turn.record?.createIfMissing,
31
+ updateLastRoute: turn.record?.updateLastRoute,
32
+ onRecordError: turn.record?.onRecordError ?? (() => undefined),
33
+ });
34
+ const dispatchResult = await turn.runDispatch();
35
+ return {
36
+ admission: { kind: "dispatch" as const },
37
+ dispatched: true,
38
+ ctxPayload: turn.ctxPayload,
39
+ routeSessionKey: turn.routeSessionKey,
40
+ dispatchResult,
41
+ };
42
+ },
43
+ );
44
+ const run = vi.fn(async (params: Parameters<PluginRuntime["channel"]["turn"]["run"]>[0]) => {
45
+ const input = await params.adapter.ingest(params.raw);
46
+ if (!input) {
47
+ return { admission: { kind: "drop" as const, reason: "ingest-null" }, dispatched: false };
48
+ }
49
+ const eventClass = (await params.adapter.classify?.(input)) ?? {
50
+ kind: "message" as const,
51
+ canStartAgentTurn: true,
52
+ };
53
+ const preflightResult = await params.adapter.preflight?.(input, eventClass);
54
+ const preflight =
55
+ preflightResult && "kind" in preflightResult
56
+ ? { admission: preflightResult }
57
+ : (preflightResult ?? {});
58
+ const turn = await params.adapter.resolveTurn(input, eventClass, preflight);
59
+ if ("runDispatch" in turn) {
60
+ return await runPrepared(turn);
61
+ }
62
+ throw new Error("msteams test runtime only supports prepared turn dispatch");
63
+ });
64
+ setMSTeamsRuntime({
65
+ logging: { shouldLogVerbose: () => false },
66
+ system: { enqueueSystemEvent: options.enqueueSystemEvent ?? vi.fn() },
67
+ channel: {
68
+ debounce: {
69
+ resolveInboundDebounceMs: () => 0,
70
+ createInboundDebouncer: <T>(params: {
71
+ onFlush: (entries: T[]) => Promise<void>;
72
+ }): { enqueue: (entry: T) => Promise<void> } => ({
73
+ enqueue: async (entry: T) => {
74
+ await params.onFlush([entry]);
75
+ },
76
+ }),
77
+ },
78
+ pairing: {
79
+ readAllowFromStore: options.readAllowFromStore ?? vi.fn(async () => []),
80
+ upsertPairingRequest: options.upsertPairingRequest ?? vi.fn(async () => null),
81
+ },
82
+ text: {
83
+ hasControlCommand: options.hasControlCommand ?? (() => false),
84
+ resolveChunkMode: () => "length",
85
+ resolveMarkdownTableMode: () => "code",
86
+ ...(options.resolveTextChunkLimit
87
+ ? { resolveTextChunkLimit: options.resolveTextChunkLimit }
88
+ : {}),
89
+ },
90
+ routing: {
91
+ resolveAgentRoute:
92
+ options.resolveAgentRoute ??
93
+ (({ peer }: RuntimeRoutePeer) => ({
94
+ sessionKey: `msteams:${peer.kind}:${peer.id}`,
95
+ agentId: "default",
96
+ accountId: "default",
97
+ })),
98
+ },
99
+ reply: {
100
+ createReplyDispatcherWithTyping: () => ({
101
+ dispatcher: {},
102
+ replyOptions: {},
103
+ markDispatchIdle: vi.fn(),
104
+ }),
105
+ formatAgentEnvelope: ({ body }: { body: string }) => body,
106
+ finalizeInboundContext: <T extends Record<string, unknown>>(ctx: T) => ctx,
107
+ resolveHumanDelayConfig: () => undefined,
108
+ },
109
+ session: {
110
+ recordInboundSession: options.recordInboundSession ?? vi.fn(async () => undefined),
111
+ ...(options.resolveStorePath ? { resolveStorePath: options.resolveStorePath } : {}),
112
+ },
113
+ turn: {
114
+ run: run as unknown as PluginRuntime["channel"]["turn"]["run"],
115
+ runPrepared: runPrepared as unknown as PluginRuntime["channel"]["turn"]["runPrepared"],
116
+ },
117
+ },
118
+ } as unknown as PluginRuntime);
119
+ }
120
+
121
+ export function createActivityHandler(
122
+ run = vi.fn(async () => undefined),
123
+ ): MSTeamsActivityHandler & {
124
+ run: NonNullable<MSTeamsActivityHandler["run"]>;
125
+ } {
126
+ let handler: MSTeamsActivityHandler & {
127
+ run: NonNullable<MSTeamsActivityHandler["run"]>;
128
+ };
129
+ handler = {
130
+ onMessage: () => handler,
131
+ onMembersAdded: () => handler,
132
+ onReactionsAdded: () => handler,
133
+ onReactionsRemoved: () => handler,
134
+ run,
135
+ };
136
+ return handler;
137
+ }
138
+
139
+ export function createMSTeamsMessageHandlerDeps(params?: {
140
+ cfg?: KlawConfig;
141
+ runtime?: RuntimeEnv;
142
+ }): MSTeamsMessageHandlerDeps {
143
+ const adapter: MSTeamsAdapter = {
144
+ continueConversation: async () => {},
145
+ process: async () => {},
146
+ updateActivity: async () => {},
147
+ deleteActivity: async () => {},
148
+ };
149
+ const conversationStore: MSTeamsConversationStore = {
150
+ upsert: async () => {},
151
+ get: async () => null,
152
+ list: async () => [],
153
+ remove: async () => false,
154
+ findPreferredDmByUserId: async () => null,
155
+ findByUserId: async () => null,
156
+ };
157
+ const pollStore: MSTeamsPollStore = {
158
+ createPoll: async () => {},
159
+ getPoll: async () => null,
160
+ recordVote: async () => null,
161
+ };
162
+
163
+ return {
164
+ cfg: params?.cfg ?? {},
165
+ runtime: (params?.runtime ?? { error: vi.fn() }) as RuntimeEnv,
166
+ appId: "test-app-id",
167
+ adapter,
168
+ tokenProvider: {
169
+ getAccessToken: async () => "token",
170
+ },
171
+ textLimit: 4000,
172
+ mediaMaxBytes: 8 * 1024 * 1024,
173
+ conversationStore,
174
+ pollStore,
175
+ log: {
176
+ info: vi.fn(),
177
+ error: vi.fn(),
178
+ debug: vi.fn(),
179
+ },
180
+ };
181
+ }