@effect/chat-teams 0.0.0-stage → 4.1.5

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 (162) hide show
  1. package/AGENTS.md +434 -0
  2. package/CLAUDE.md +434 -0
  3. package/LICENSE +21 -0
  4. package/README.md +115 -2
  5. package/ai-docs/README.md +44 -0
  6. package/ai-docs/package.json +36 -0
  7. package/ai-docs/src/01_effect/01_basics/01_effect-gen.ts +30 -0
  8. package/ai-docs/src/01_effect/01_basics/02_effect-fn.ts +52 -0
  9. package/ai-docs/src/01_effect/01_basics/10_creating-effects.ts +74 -0
  10. package/ai-docs/src/01_effect/01_basics/index.md +7 -0
  11. package/ai-docs/src/01_effect/02_schema/10_schema-basics.ts +43 -0
  12. package/ai-docs/src/01_effect/02_schema/index.md +7 -0
  13. package/ai-docs/src/01_effect/03_services/01_service.ts +45 -0
  14. package/ai-docs/src/01_effect/03_services/10_reference.ts +10 -0
  15. package/ai-docs/src/01_effect/03_services/20_layer-composition.ts +70 -0
  16. package/ai-docs/src/01_effect/03_services/20_layer-unwrap.ts +66 -0
  17. package/ai-docs/src/01_effect/03_services/index.md +5 -0
  18. package/ai-docs/src/01_effect/04_errors/01_error-handling.ts +30 -0
  19. package/ai-docs/src/01_effect/04_errors/10_catch-tags.ts +24 -0
  20. package/ai-docs/src/01_effect/04_errors/20_reason-errors.ts +64 -0
  21. package/ai-docs/src/01_effect/04_errors/index.md +1 -0
  22. package/ai-docs/src/01_effect/05_resources/10_acquire-release.ts +105 -0
  23. package/ai-docs/src/01_effect/05_resources/20_layer-side-effects.ts +31 -0
  24. package/ai-docs/src/01_effect/05_resources/30_layer-map.ts +86 -0
  25. package/ai-docs/src/01_effect/05_resources/index.md +3 -0
  26. package/ai-docs/src/01_effect/06_running/10_run-main.ts +30 -0
  27. package/ai-docs/src/01_effect/06_running/20_layer-launch.ts +27 -0
  28. package/ai-docs/src/01_effect/06_running/index.md +1 -0
  29. package/ai-docs/src/01_effect/07_pubsub/10_pubsub.ts +56 -0
  30. package/ai-docs/src/01_effect/07_pubsub/index.md +3 -0
  31. package/ai-docs/src/03_stream/10_creating-streams.ts +103 -0
  32. package/ai-docs/src/03_stream/20_consuming-streams.ts +137 -0
  33. package/ai-docs/src/03_stream/30_encoding.ts +163 -0
  34. package/ai-docs/src/03_stream/index.md +4 -0
  35. package/ai-docs/src/04_integration/10_managed-runtime.ts +129 -0
  36. package/ai-docs/src/04_integration/index.md +5 -0
  37. package/ai-docs/src/05_batching/10_request-resolver.ts +89 -0
  38. package/ai-docs/src/05_batching/index.md +3 -0
  39. package/ai-docs/src/06_schedule/10_schedules.ts +111 -0
  40. package/ai-docs/src/06_schedule/index.md +3 -0
  41. package/ai-docs/src/07_datetime/10_creating-and-formatting.ts +30 -0
  42. package/ai-docs/src/07_datetime/20_time-zones.ts +44 -0
  43. package/ai-docs/src/07_datetime/index.md +5 -0
  44. package/ai-docs/src/08_observability/10_logging.ts +66 -0
  45. package/ai-docs/src/08_observability/20_otlp-tracing.ts +95 -0
  46. package/ai-docs/src/08_observability/index.md +7 -0
  47. package/ai-docs/src/09_testing/10_effect-tests.ts +55 -0
  48. package/ai-docs/src/09_testing/20_layer-tests.ts +138 -0
  49. package/ai-docs/src/09_testing/index.md +1 -0
  50. package/ai-docs/src/10_predicate/01_basics.ts +14 -0
  51. package/ai-docs/src/10_predicate/index.md +9 -0
  52. package/ai-docs/src/40_sql/10_basics.ts +175 -0
  53. package/ai-docs/src/40_sql/index.md +6 -0
  54. package/ai-docs/src/50_http-client/10_basics.ts +102 -0
  55. package/ai-docs/src/50_http-client/index.md +3 -0
  56. package/ai-docs/src/51_http-server/10_basics.ts +118 -0
  57. package/ai-docs/src/51_http-server/20_testing.ts +100 -0
  58. package/ai-docs/src/51_http-server/fixtures/api/Api.ts +14 -0
  59. package/ai-docs/src/51_http-server/fixtures/api/Authorization.ts +36 -0
  60. package/ai-docs/src/51_http-server/fixtures/api/System.ts +10 -0
  61. package/ai-docs/src/51_http-server/fixtures/api/Users.ts +107 -0
  62. package/ai-docs/src/51_http-server/fixtures/domain/User.ts +21 -0
  63. package/ai-docs/src/51_http-server/fixtures/domain/UserErrors.ts +22 -0
  64. package/ai-docs/src/51_http-server/fixtures/server/Authorization.ts +37 -0
  65. package/ai-docs/src/51_http-server/fixtures/server/Users/http.ts +80 -0
  66. package/ai-docs/src/51_http-server/fixtures/server/Users.ts +183 -0
  67. package/ai-docs/src/51_http-server/index.md +3 -0
  68. package/ai-docs/src/52_graphql/10_basics.ts +117 -0
  69. package/ai-docs/src/52_graphql/20_testing.ts +45 -0
  70. package/ai-docs/src/52_graphql/30_batching.ts +118 -0
  71. package/ai-docs/src/52_graphql/40_aliased-batching.ts +124 -0
  72. package/ai-docs/src/52_graphql/50_errors-and-retries.ts +74 -0
  73. package/ai-docs/src/52_graphql/index.md +6 -0
  74. package/ai-docs/src/60_child-process/10_working-with-child-processes.ts +117 -0
  75. package/ai-docs/src/60_child-process/index.md +3 -0
  76. package/ai-docs/src/70_cli/10_basics.ts +162 -0
  77. package/ai-docs/src/70_cli/index.md +5 -0
  78. package/ai-docs/src/71_ai/10_language-model.ts +156 -0
  79. package/ai-docs/src/71_ai/20_tools.ts +226 -0
  80. package/ai-docs/src/71_ai/30_chat.ts +158 -0
  81. package/ai-docs/src/71_ai/fixtures/domain/LaunchPlan.ts +9 -0
  82. package/ai-docs/src/71_ai/index.md +5 -0
  83. package/ai-docs/src/80_cluster/10_entities.ts +97 -0
  84. package/ai-docs/src/80_cluster/index.md +4 -0
  85. package/ai-docs/src/index.md +10 -0
  86. package/ai-docs/tsconfig.json +28 -0
  87. package/dist/TeamsChat.d.ts +318 -0
  88. package/dist/TeamsChat.d.ts.map +1 -0
  89. package/dist/TeamsChat.js +316 -0
  90. package/dist/TeamsChat.js.map +1 -0
  91. package/dist/index.d.ts +10 -0
  92. package/dist/index.d.ts.map +1 -0
  93. package/dist/index.js +11 -0
  94. package/dist/index.js.map +1 -0
  95. package/dist/internal/adapter.d.ts +2 -0
  96. package/dist/internal/adapter.d.ts.map +1 -0
  97. package/dist/internal/adapter.js +300 -0
  98. package/dist/internal/adapter.js.map +1 -0
  99. package/dist/internal/address.d.ts +2 -0
  100. package/dist/internal/address.d.ts.map +1 -0
  101. package/dist/internal/address.js +52 -0
  102. package/dist/internal/address.js.map +1 -0
  103. package/dist/internal/auth.d.ts +2 -0
  104. package/dist/internal/auth.d.ts.map +1 -0
  105. package/dist/internal/auth.js +142 -0
  106. package/dist/internal/auth.js.map +1 -0
  107. package/dist/internal/connector.d.ts +2 -0
  108. package/dist/internal/connector.d.ts.map +1 -0
  109. package/dist/internal/connector.js +173 -0
  110. package/dist/internal/connector.js.map +1 -0
  111. package/dist/internal/download.d.ts +5 -0
  112. package/dist/internal/download.d.ts.map +1 -0
  113. package/dist/internal/download.js +183 -0
  114. package/dist/internal/download.js.map +1 -0
  115. package/dist/internal/envelope.d.ts +2 -0
  116. package/dist/internal/envelope.d.ts.map +1 -0
  117. package/dist/internal/envelope.js +337 -0
  118. package/dist/internal/envelope.js.map +1 -0
  119. package/dist/internal/errors.d.ts +2 -0
  120. package/dist/internal/errors.d.ts.map +1 -0
  121. package/dist/internal/errors.js +113 -0
  122. package/dist/internal/errors.js.map +1 -0
  123. package/dist/internal/interactions.d.ts +2 -0
  124. package/dist/internal/interactions.d.ts.map +1 -0
  125. package/dist/internal/interactions.js +288 -0
  126. package/dist/internal/interactions.js.map +1 -0
  127. package/dist/internal/length.d.ts +2 -0
  128. package/dist/internal/length.d.ts.map +1 -0
  129. package/dist/internal/length.js +147 -0
  130. package/dist/internal/length.js.map +1 -0
  131. package/dist/internal/normalize.d.ts +2 -0
  132. package/dist/internal/normalize.d.ts.map +1 -0
  133. package/dist/internal/normalize.js +224 -0
  134. package/dist/internal/normalize.js.map +1 -0
  135. package/dist/internal/parse.d.ts +2 -0
  136. package/dist/internal/parse.d.ts.map +1 -0
  137. package/dist/internal/parse.js +33 -0
  138. package/dist/internal/parse.js.map +1 -0
  139. package/dist/internal/render.d.ts +2 -0
  140. package/dist/internal/render.d.ts.map +1 -0
  141. package/dist/internal/render.js +316 -0
  142. package/dist/internal/render.js.map +1 -0
  143. package/dist/internal/webhook.d.ts +2 -0
  144. package/dist/internal/webhook.d.ts.map +1 -0
  145. package/dist/internal/webhook.js +88 -0
  146. package/dist/internal/webhook.js.map +1 -0
  147. package/package.json +58 -3
  148. package/src/TeamsChat.ts +470 -0
  149. package/src/index.ts +12 -0
  150. package/src/internal/adapter.ts +351 -0
  151. package/src/internal/address.ts +67 -0
  152. package/src/internal/auth.ts +192 -0
  153. package/src/internal/connector.ts +253 -0
  154. package/src/internal/download.ts +277 -0
  155. package/src/internal/envelope.ts +427 -0
  156. package/src/internal/errors.ts +94 -0
  157. package/src/internal/interactions.ts +294 -0
  158. package/src/internal/length.ts +170 -0
  159. package/src/internal/normalize.ts +232 -0
  160. package/src/internal/parse.ts +41 -0
  161. package/src/internal/render.ts +318 -0
  162. package/src/internal/webhook.ts +117 -0
@@ -0,0 +1,28 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "../tsconfig.base.json",
4
+ "include": ["src/**/*.ts", "src/**/*.tsx"],
5
+ "compilerOptions": {
6
+ "rootDir": ".",
7
+ "noEmit": true,
8
+ "declaration": false,
9
+ "declarationMap": false,
10
+ "composite": false,
11
+ "incremental": false,
12
+ "types": ["node"],
13
+ "plugins": [
14
+ {
15
+ "name": "@effect/language-service",
16
+ "effectFn": ["untraced"],
17
+ "namespaceImportPackages": [],
18
+ "diagnosticSeverity": {
19
+ "floatingEffect": "off",
20
+ "globalJson": "off",
21
+ "globalJsonInEffect": "off",
22
+ "unstableApiUsage": "off",
23
+ "effectFnOpportunity": "error"
24
+ }
25
+ }
26
+ ]
27
+ }
28
+ }
@@ -0,0 +1,318 @@
1
+ import { Registry } from "effect/chat/ChatAdapter";
2
+ import type { ChatError } from "effect/chat/ChatError";
3
+ import type { ChatEvent } from "effect/chat/ChatEvent";
4
+ import { ChatHandler } from "effect/chat/ChatHandler";
5
+ import type { ParseMention } from "effect/chat/ChatTest";
6
+ import type { ChatThread } from "effect/chat/ChatThread";
7
+ import * as Context from "effect/Context";
8
+ import type * as Digest from "effect/crypto/Digest";
9
+ import type * as Mac from "effect/crypto/Mac";
10
+ import type * as Signature from "effect/crypto/Signature";
11
+ import type * as DateTime from "effect/DateTime";
12
+ import * as Duration from "effect/Duration";
13
+ import * as Effect from "effect/Effect";
14
+ import * as HttpClient from "effect/http/HttpClient";
15
+ import * as HttpRouter from "effect/http/HttpRouter";
16
+ import type { SecretJwk } from "effect/jose/Jwk";
17
+ import * as Layer from "effect/Layer";
18
+ import * as Option from "effect/Option";
19
+ import type * as Redacted from "effect/Redacted";
20
+ import type * as Schema from "effect/Schema";
21
+ /**
22
+ * The endpoints and host allowlists of one Microsoft cloud.
23
+ *
24
+ * **Details**
25
+ *
26
+ * - `connectorUrl` is where thread ops go. Ops tied to an inbound activity
27
+ * (an invoke's answer, a command's answer, `followUp`) go to that
28
+ * activity's `serviceUrl`, which must be `https:` on the default port
29
+ * with a host exactly in `connectorHosts`, checked before a token is
30
+ * attached. There is no fallback from one to the other.
31
+ * - `openIdMetadataUrl` and `issuer` check inbound tokens. The metadata's
32
+ * `jwks_uri` must be on the metadata's own host.
33
+ * - `fileHostSuffixes` and `redirectHosts` bound downloads.
34
+ *
35
+ * @stability unstable
36
+ * @category models
37
+ * @since 4.1.5
38
+ */
39
+ export interface Cloud {
40
+ /** The Connector base for thread ops, such as `https://smba.trafficmanager.net/teams`. */
41
+ readonly connectorUrl: string;
42
+ /** The exact hosts an activity's `serviceUrl` may name. */
43
+ readonly connectorHosts: ReadonlyArray<string>;
44
+ /** Bot Framework's OpenID metadata. Its `jwks_uri` must be on the same host. */
45
+ readonly openIdMetadataUrl: string;
46
+ /** The `iss` of an inbound token. */
47
+ readonly issuer: string;
48
+ /** The Entra authority, without the tenant: `https://login.microsoftonline.com`. */
49
+ readonly loginUrl: string;
50
+ /** The scope of a Connector token. */
51
+ readonly connectorScope: string;
52
+ /** The host suffixes of a personal chat's pre-authorised file URL, matched at a label boundary. */
53
+ readonly fileHostSuffixes: ReadonlyArray<string>;
54
+ /** Extra exact hosts a download may be redirected to. */
55
+ readonly redirectHosts: ReadonlyArray<string>;
56
+ }
57
+ /**
58
+ * The public Azure cloud: Connector `smba.trafficmanager.net`, Bot
59
+ * Framework's OpenID metadata, Entra at `login.microsoftonline.com`, and
60
+ * `sharepoint.com` for files. No extra redirect hosts.
61
+ *
62
+ * @stability unstable
63
+ * @category constants
64
+ * @since 4.1.5
65
+ */
66
+ export declare const publicCloud: Cloud;
67
+ /**
68
+ * How the adapter gets its Connector token: the bot's client secret, for
69
+ * client credentials against the tenant, or a provider that gets a token
70
+ * for a scope, for certificates or managed identities.
71
+ *
72
+ * **Details**
73
+ *
74
+ * A token is cached until five minutes before `expiresAt`. A token
75
+ * without `expiresAt` is not cached, and the provider is called for every
76
+ * request.
77
+ *
78
+ * @stability unstable
79
+ * @category models
80
+ * @since 4.1.5
81
+ */
82
+ export type Credentials = Redacted.Redacted<string> | ((scope: string) => Effect.Effect<{
83
+ readonly token: Redacted.Redacted<string>;
84
+ readonly expiresAt?: DateTime.DateTime | undefined;
85
+ }, ChatError>);
86
+ /**
87
+ * Capabilities whose live checks have not passed. Each is off by default
88
+ * and, when off, is absent from the descriptor and its op fails
89
+ * `Unsupported`.
90
+ *
91
+ * **Details**
92
+ *
93
+ * - `buttons`: buttons and link buttons on a card. Needs
94
+ * `interactionKeys`. Selects are never supported.
95
+ * - `modals`: dialogs opened by the buttons named in `modalButtons`, with
96
+ * field errors. Needs `buttons`.
97
+ * - `commands`: agent slash commands, answered in private or in public,
98
+ * and `followUp` for 24 hours. Also turns on `ephemeral`.
99
+ * - `startThread`: the reply chain under a channel post.
100
+ * - `download`: files on inbound messages.
101
+ *
102
+ * @stability unstable
103
+ * @category models
104
+ * @since 4.1.5
105
+ */
106
+ export interface Unverified {
107
+ readonly buttons?: boolean | undefined;
108
+ readonly modals?: boolean | undefined;
109
+ readonly commands?: boolean | undefined;
110
+ readonly startThread?: boolean | undefined;
111
+ readonly download?: boolean | undefined;
112
+ }
113
+ declare const TeamsChat_base: Context.ServiceClass<TeamsChat, "@effect/chat-teams/TeamsChat", {
114
+ readonly appId: string;
115
+ readonly tenantId: string;
116
+ readonly cloud: Cloud;
117
+ readonly call: (method: "GET" | "POST" | "PUT" | "DELETE", path: string, body?: unknown, options?: {
118
+ readonly write?: boolean | undefined;
119
+ readonly serviceUrl?: string | undefined;
120
+ readonly query?: Readonly<Record<string, string>> | undefined;
121
+ }) => Effect.Effect<Schema.Json | undefined, ChatError>;
122
+ }>;
123
+ /**
124
+ * The Teams side of the adapter.
125
+ *
126
+ * **Details**
127
+ *
128
+ * - `call` sends one Connector request, with the bot's token, for what the
129
+ * adapter has no op for. `path` starts with `/v3/` and has its segments
130
+ * encoded. A `serviceUrl` routes it to an inbound activity's Connector,
131
+ * after the allowlist check. A write is never retried once sent, and a
132
+ * failure that may have landed is `uncertain`.
133
+ *
134
+ * @stability unstable
135
+ * @category services
136
+ * @since 4.1.5
137
+ */
138
+ export declare class TeamsChat extends TeamsChat_base {
139
+ }
140
+ /**
141
+ * Registers the Teams adapter in the `Registry`, for one tenant.
142
+ *
143
+ * **Details**
144
+ *
145
+ * - `post` and `edit` without elements send the Markdown as `text` with
146
+ * `textFormat: "extendedmarkdown"`, with every `<` and `&` as an entity,
147
+ * so no HTML and no `<at>` mention forms, and every `$` outside code as
148
+ * `\$`, so Teams reads no math. Mentions notify nobody.
149
+ * - With elements, the message is one Adaptive Card and no `text`:
150
+ * `TextBlock`, `CodeBlock` and `Table` elements from the Markdown, then
151
+ * `ActionSet` rows. An `edit` may switch between the two forms.
152
+ * - `limits.messageLength` is a budget, not Microsoft's number. It is the
153
+ * provisional size `Edge` (50,000 UTF-16 units of activity JSON, half of
154
+ * the 100 KB Microsoft documents, until a live check sets it) less a fixed
155
+ * reservation `R` for the card's structure, the auxiliary members and
156
+ * 4,000 units of mention entities: 44,288 today. `measure` prices each
157
+ * unit by what escaping and card structure can make of it.
158
+ * - A button carries a signed token (HS256 JWT) under the card data key
159
+ * `effect`, bound to the app, the tenant and the conversation. It is
160
+ * signed, not encrypted: anyone who sees the card can read the id and
161
+ * value. A token has no replay protection: a click can be sent again
162
+ * while the conversation exists. A dialog token also binds the user and
163
+ * expires after an hour.
164
+ * - The adapter's own caps, as Teams publishes none: 6 elements per
165
+ * message, 10 fields per modal, and two caps counted as the signed token
166
+ * that carries the data, envelope included. `actionDataLength` is 1,000
167
+ * units of button token, about 500 ASCII characters of id plus value with
168
+ * a GUID app and tenant. `modalMetadataLength` is 4,000 units of dialog
169
+ * token, and the whole token counts: the modal's id, metadata, title,
170
+ * labels, options and texts together get about 1,880 bytes of JSON. A
171
+ * modal over it is refused `TooLarge` before anything opens.
172
+ * A message with every element at its cap still fits `messageLength`.
173
+ * - The `HttpClient` must add no credentials of its own and follow no
174
+ * redirects. The adapter decides per request which host gets the bot's
175
+ * token, asks Fetch for `redirect: "manual"` and fails a response from
176
+ * any other URL than the one it sent to. A client other than
177
+ * `FetchHttpClient`, or middleware that rewrites requests, must keep
178
+ * that.
179
+ * - `getUser` needs `in`, the thread whose roster to read: without it
180
+ * it fails `InvalidRequest` with `thread_required`. A user's id is the
181
+ * Entra object id when Teams sends one, and the Connector id (`29:…`,
182
+ * `28:…`) otherwise; `raw` keeps the Connector record.
183
+ * - The layer provides `TeamsChat` beside registering the adapter. It
184
+ * needs `Mac` and `Digest` for the interaction tokens; the adapter
185
+ * never calls `crypto.subtle` itself.
186
+ *
187
+ * @stability unstable
188
+ * @category layers
189
+ * @since 4.1.5
190
+ */
191
+ export declare const layer: (options: {
192
+ readonly appId: string;
193
+ readonly tenantId: string;
194
+ readonly credentials: Credentials;
195
+ readonly cloud?: Cloud | undefined;
196
+ /**
197
+ * The keys that sign button and dialog tokens. The first signs, and any
198
+ * verifies by its `kid`, so a rotation adds a key in front and drops the
199
+ * old one later. Each needs a distinct `kid` of 1 to 16 characters from
200
+ * `[A-Za-z0-9_-]` and at least 32 bytes. Without keys, there are no
201
+ * buttons or modals.
202
+ */
203
+ readonly interactionKeys?: readonly [Redacted.Redacted<SecretJwk>, ...Array<Redacted.Redacted<SecretJwk>>] | undefined;
204
+ /** The ids of the buttons that open a dialog. Only these may answer `OpenModal`. */
205
+ readonly modalButtons?: ReadonlyArray<string> | undefined;
206
+ readonly unverified?: Unverified | undefined;
207
+ }) => Layer.Layer<TeamsChat, never, HttpClient.HttpClient | Registry | Mac.Mac | Digest.Digest>;
208
+ /**
209
+ * `POST {path}`: the bot's messaging endpoint.
210
+ *
211
+ * **Details**
212
+ *
213
+ * - Checks the bearer token: RS256 with a key from Bot Framework's key set
214
+ * that is endorsed for `msteams`, the cloud's issuer, the app id as
215
+ * audience, five minutes of skew and an `exp`. Then the token's
216
+ * `serviceurl` must equal the activity's `serviceUrl`, `channelId`
217
+ * must be `msteams` and the tenant the layer's. Any failure is 403. A
218
+ * key set that can't be read is 503.
219
+ * - A targeted activity, one only the bot can see, is classified before
220
+ * anything else, whatever its type. A targeted message takes the command
221
+ * path: its first word names the command and the rest is its `text`. One
222
+ * that names no registered command is acked and nothing is sent. A
223
+ * targeted invoke goes to the interaction handler. Any other targeted
224
+ * activity is answered 200 and dropped. None reaches the `ChatHandler`,
225
+ * `onUnhandled`, or anything public.
226
+ * - Invokes go to `ChatInteraction.Handler` within `interactionDeadline`
227
+ * (4 seconds by default). Without a `Handler` in context, every invoke
228
+ * and every targeted message gets an empty 200.
229
+ * - Other activities go through `normalize` to the `ChatHandler`: 200
230
+ * when it succeeds, 503 when it fails `NotAccepted` or a message can't
231
+ * be normalised. An activity with no event goes to `onUnhandled` and is
232
+ * answered 200. Past `deadline` (10 seconds by default) the handler is
233
+ * interrupted and the answer is 503. Each 503 is logged with its reason.
234
+ * - Answers 413 past `maxBodyBytes` (1 MiB by default), and 400 for a body
235
+ * that can't be read or is not a JSON object, both before the token is
236
+ * checked. `maxBodyBytes` must be a non-negative safe integer; another
237
+ * value is a defect when the layer is built.
238
+ *
239
+ * The metadata and the key set are fetched with redirects off, and the
240
+ * metadata is read up to 64 KiB. A metadata document or `jwks_uri` that
241
+ * can't be read is 503. The `HttpClient` has the same requirements as for
242
+ * `layer`.
243
+ *
244
+ * Token checks need the `Signature` service. Importing the key set's
245
+ * public keys goes through `Jwk.importPublic`, which needs a `WebCrypto`
246
+ * reference whatever crypto backend provides `Signature`.
247
+ *
248
+ * @stability unstable
249
+ * @category layers
250
+ * @since 4.1.5
251
+ */
252
+ export declare const layerWebhook: (options: {
253
+ readonly path: `/${string}`;
254
+ readonly deadline?: Duration.Input | undefined;
255
+ readonly interactionDeadline?: Duration.Input | undefined;
256
+ readonly maxBodyBytes?: number | undefined;
257
+ readonly onUnhandled?: ((activity: Schema.Json) => Effect.Effect<void>) | undefined;
258
+ }) => Layer.Layer<never, never, HttpRouter.HttpRouter | TeamsChat | ChatHandler | HttpClient.HttpClient | Signature.Signature>;
259
+ /**
260
+ * The address of a Teams conversation: the Bot Framework conversation id as
261
+ * it is. A channel thread is the channel's id followed by
262
+ * `;messageid={root}`.
263
+ *
264
+ * @stability unstable
265
+ * @category constructors
266
+ * @since 4.1.5
267
+ */
268
+ export declare const thread: (conversationId: string) => ChatThread;
269
+ /**
270
+ * The parts of a Teams address, or `None` for another platform's or a
271
+ * malformed one.
272
+ *
273
+ * @stability unstable
274
+ * @category destructors
275
+ * @since 4.1.5
276
+ */
277
+ export declare const parts: (thread: ChatThread) => Option.Option<{
278
+ readonly conversationId: string;
279
+ readonly base: string;
280
+ readonly root?: string | undefined;
281
+ }>;
282
+ /**
283
+ * The normaliser, for a consumer's own transport. It checks no token: that
284
+ * is the transport's job.
285
+ *
286
+ * **Details**
287
+ *
288
+ * - Pure: takes an activity, gives zero or more events.
289
+ * - A `message` gives a `MessageCreated`. Its `text` is Teams' `text` as
290
+ * delivered, with `<at>…</at>` for each mention, where `mentions` point.
291
+ * A channel post is addressed to the channel, a reply to the post's
292
+ * thread.
293
+ * - `messageReaction` gives a `ReactionAdded` or `ReactionRemoved` per
294
+ * reaction. The six types Teams documents are Unicode emoji; any other is
295
+ * `custom:{type}`.
296
+ * - A targeted activity, a card submit and anything else give none.
297
+ * - `raw` is the activity.
298
+ *
299
+ * @stability unstable
300
+ * @category normalization
301
+ * @since 4.1.5
302
+ */
303
+ export declare const normalize: (activity: unknown, context: {
304
+ readonly appId: string;
305
+ readonly cloud?: Cloud | undefined;
306
+ }) => ReadonlyArray<ChatEvent>;
307
+ /**
308
+ * Reads one Teams mention, `<at>…</at>`, for `ChatTest`. The tag holds a
309
+ * display name and no id, so this is always `None`; a message's
310
+ * `mentions` come from its entities.
311
+ *
312
+ * @stability unstable
313
+ * @category testing
314
+ * @since 4.1.5
315
+ */
316
+ export declare const parseMention: ParseMention;
317
+ export {};
318
+ //# sourceMappingURL=TeamsChat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TeamsChat.d.ts","sourceRoot":"","sources":["../src/TeamsChat.ts"],"names":[],"mappings":"AA2BA,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAErD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,KAAK,MAAM,MAAM,sBAAsB,CAAA;AACnD,OAAO,KAAK,KAAK,GAAG,MAAM,mBAAmB,CAAA;AAC7C,OAAO,KAAK,KAAK,SAAS,MAAM,yBAAyB,CAAA;AACzD,OAAO,KAAK,KAAK,Q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,SAAS,CAAA;CACpF,KAAG,KAAK,CAAC,KAAK,CACb,KAAK,EACL,KAAK,EACL,UAAU,CAAC,UAAU,GAAG,SAAS,GAAG,WAAW,GAAG,UAAU,CAAC,UAAU,GAAG,SAAS,CAAC,SAAS,CAoD1F,CAAA;AAEL;;;;;;;;GAQG;AACH,eAAO,MAAM,MAAM,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,UAA2B,CAAA;AAE5E;;;;;;;GAOG;AACH,eAAO,MAAM,KAAK,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,MAAM,CAAC,MAAM,CAAC;IACxD,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACnC,CAAiB,CAAA;AAElB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,SAAS,aACV,OAAO,WACR;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,SAAS,CAAA;CAAE,KACtE,aAAa,CAAC,SAAS,CAOzB,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,EAAE,YAAkC,CAAA"}
@@ -0,0 +1,316 @@
1
+ /**
2
+ * The Microsoft Teams adapter for `effect/chat`, over the Bot Framework
3
+ * Connector: the `Registry` layer, the messaging endpoint, the pure
4
+ * normaliser and address helpers.
5
+ *
6
+ * **Details**
7
+ *
8
+ * - One layer serves one Entra tenant, with a single-tenant Azure Bot
9
+ * registration. The cloud's endpoints and host allowlists come as a unit
10
+ * from `publicCloud` or a `Cloud` of the consumer's own. They are
11
+ * privileged configuration and never read from an activity.
12
+ * - Nothing here has run against a real tenant yet, the default
13
+ * capabilities included. Live testing is follow-up work, and the README
14
+ * lists its checks. Until a check passes, what it covers is unverified.
15
+ * - Implemented but unverified, and off by default: `buttons`, `modals`,
16
+ * `modalErrors`, `commands`, `ephemeral`, `startThread` and
17
+ * `download`, each behind an `unverified` option. Turning one on
18
+ * advertises a capability no tenant has confirmed.
19
+ * - Not implemented in this version, whatever the options: reading
20
+ * messages (`fetchMessage`, `history`, `opener`, which need Microsoft
21
+ * Graph), `replyTo`, files, native streams and selects. They are
22
+ * `Unsupported`.
23
+ *
24
+ * @stability unstable
25
+ * @since 4.1.5
26
+ */
27
+ import * as ByteSize from "effect/ByteSize";
28
+ import { Registry } from "effect/chat/ChatAdapter";
29
+ import { ChatHandler } from "effect/chat/ChatHandler";
30
+ import * as ChatInteraction from "effect/chat/ChatInteraction";
31
+ import * as Context from "effect/Context";
32
+ import * as Duration from "effect/Duration";
33
+ import * as Effect from "effect/Effect";
34
+ import * as HttpClient from "effect/http/HttpClient";
35
+ import * as HttpRouter from "effect/http/HttpRouter";
36
+ import * as Layer from "effect/Layer";
37
+ import * as Option from "effect/Option";
38
+ import * as Adapter from "./internal/adapter.js";
39
+ import * as Address from "./internal/address.js";
40
+ import * as Auth from "./internal/auth.js";
41
+ import * as Connector from "./internal/connector.js";
42
+ import * as Envelope from "./internal/envelope.js";
43
+ import * as Interactions from "./internal/interactions.js";
44
+ import * as Normalize from "./internal/normalize.js";
45
+ import * as Webhook from "./internal/webhook.js";
46
+ /**
47
+ * The public Azure cloud: Connector `smba.trafficmanager.net`, Bot
48
+ * Framework's OpenID metadata, Entra at `login.microsoftonline.com`, and
49
+ * `sharepoint.com` for files. No extra redirect hosts.
50
+ *
51
+ * @stability unstable
52
+ * @category constants
53
+ * @since 4.1.5
54
+ */
55
+ export const publicCloud = Connector.publicCloud;
56
+ /**
57
+ * The Teams side of the adapter.
58
+ *
59
+ * **Details**
60
+ *
61
+ * - `call` sends one Connector request, with the bot's token, for what the
62
+ * adapter has no op for. `path` starts with `/v3/` and has its segments
63
+ * encoded. A `serviceUrl` routes it to an inbound activity's Connector,
64
+ * after the allowlist check. A write is never retried once sent, and a
65
+ * failure that may have landed is `uncertain`.
66
+ *
67
+ * @stability unstable
68
+ * @category services
69
+ * @since 4.1.5
70
+ */
71
+ export class TeamsChat extends /*#__PURE__*/Context.Service()("@effect/chat-teams/TeamsChat") {}
72
+ /**
73
+ * Registers the Teams adapter in the `Registry`, for one tenant.
74
+ *
75
+ * **Details**
76
+ *
77
+ * - `post` and `edit` without elements send the Markdown as `text` with
78
+ * `textFormat: "extendedmarkdown"`, with every `<` and `&` as an entity,
79
+ * so no HTML and no `<at>` mention forms, and every `$` outside code as
80
+ * `\$`, so Teams reads no math. Mentions notify nobody.
81
+ * - With elements, the message is one Adaptive Card and no `text`:
82
+ * `TextBlock`, `CodeBlock` and `Table` elements from the Markdown, then
83
+ * `ActionSet` rows. An `edit` may switch between the two forms.
84
+ * - `limits.messageLength` is a budget, not Microsoft's number. It is the
85
+ * provisional size `Edge` (50,000 UTF-16 units of activity JSON, half of
86
+ * the 100 KB Microsoft documents, until a live check sets it) less a fixed
87
+ * reservation `R` for the card's structure, the auxiliary members and
88
+ * 4,000 units of mention entities: 44,288 today. `measure` prices each
89
+ * unit by what escaping and card structure can make of it.
90
+ * - A button carries a signed token (HS256 JWT) under the card data key
91
+ * `effect`, bound to the app, the tenant and the conversation. It is
92
+ * signed, not encrypted: anyone who sees the card can read the id and
93
+ * value. A token has no replay protection: a click can be sent again
94
+ * while the conversation exists. A dialog token also binds the user and
95
+ * expires after an hour.
96
+ * - The adapter's own caps, as Teams publishes none: 6 elements per
97
+ * message, 10 fields per modal, and two caps counted as the signed token
98
+ * that carries the data, envelope included. `actionDataLength` is 1,000
99
+ * units of button token, about 500 ASCII characters of id plus value with
100
+ * a GUID app and tenant. `modalMetadataLength` is 4,000 units of dialog
101
+ * token, and the whole token counts: the modal's id, metadata, title,
102
+ * labels, options and texts together get about 1,880 bytes of JSON. A
103
+ * modal over it is refused `TooLarge` before anything opens.
104
+ * A message with every element at its cap still fits `messageLength`.
105
+ * - The `HttpClient` must add no credentials of its own and follow no
106
+ * redirects. The adapter decides per request which host gets the bot's
107
+ * token, asks Fetch for `redirect: "manual"` and fails a response from
108
+ * any other URL than the one it sent to. A client other than
109
+ * `FetchHttpClient`, or middleware that rewrites requests, must keep
110
+ * that.
111
+ * - `getUser` needs `in`, the thread whose roster to read: without it
112
+ * it fails `InvalidRequest` with `thread_required`. A user's id is the
113
+ * Entra object id when Teams sends one, and the Connector id (`29:…`,
114
+ * `28:…`) otherwise; `raw` keeps the Connector record.
115
+ * - The layer provides `TeamsChat` beside registering the adapter. It
116
+ * needs `Mac` and `Digest` for the interaction tokens; the adapter
117
+ * never calls `crypto.subtle` itself.
118
+ *
119
+ * @stability unstable
120
+ * @category layers
121
+ * @since 4.1.5
122
+ */
123
+ export const layer = options => Layer.effect(TeamsChat, Effect.gen(function* () {
124
+ const http = yield* HttpClient.HttpClient;
125
+ const registry = yield* Registry;
126
+ const cloud = options.cloud ?? publicCloud;
127
+ const tokens = Connector.makeTokens({
128
+ http,
129
+ cloud,
130
+ appId: options.appId,
131
+ tenantId: options.tenantId,
132
+ credentials: options.credentials
133
+ });
134
+ const connector = Connector.make({
135
+ http,
136
+ cloud,
137
+ token: tokens
138
+ });
139
+ const envelope = options.interactionKeys === undefined ? undefined : yield* Envelope.make({
140
+ appId: options.appId,
141
+ tenantId: options.tenantId,
142
+ keys: options.interactionKeys
143
+ });
144
+ const modalButtons = new Set(options.modalButtons ?? []);
145
+ const {
146
+ adapter,
147
+ answer
148
+ } = Adapter.make({
149
+ connector,
150
+ http,
151
+ cloud,
152
+ appId: options.appId,
153
+ tenantId: options.tenantId,
154
+ envelope,
155
+ unverified: options.unverified ?? {},
156
+ token: tokens(cloud.connectorScope),
157
+ modalButtons
158
+ });
159
+ yield* registry.register(adapter);
160
+ const service = TeamsChat.of({
161
+ appId: options.appId,
162
+ tenantId: options.tenantId,
163
+ cloud,
164
+ call: connector.call
165
+ });
166
+ Adapter.internals.set(service, {
167
+ capabilities: adapter.descriptor.capabilities,
168
+ envelope,
169
+ modalButtons,
170
+ answer
171
+ });
172
+ return service;
173
+ }));
174
+ /**
175
+ * `POST {path}`: the bot's messaging endpoint.
176
+ *
177
+ * **Details**
178
+ *
179
+ * - Checks the bearer token: RS256 with a key from Bot Framework's key set
180
+ * that is endorsed for `msteams`, the cloud's issuer, the app id as
181
+ * audience, five minutes of skew and an `exp`. Then the token's
182
+ * `serviceurl` must equal the activity's `serviceUrl`, `channelId`
183
+ * must be `msteams` and the tenant the layer's. Any failure is 403. A
184
+ * key set that can't be read is 503.
185
+ * - A targeted activity, one only the bot can see, is classified before
186
+ * anything else, whatever its type. A targeted message takes the command
187
+ * path: its first word names the command and the rest is its `text`. One
188
+ * that names no registered command is acked and nothing is sent. A
189
+ * targeted invoke goes to the interaction handler. Any other targeted
190
+ * activity is answered 200 and dropped. None reaches the `ChatHandler`,
191
+ * `onUnhandled`, or anything public.
192
+ * - Invokes go to `ChatInteraction.Handler` within `interactionDeadline`
193
+ * (4 seconds by default). Without a `Handler` in context, every invoke
194
+ * and every targeted message gets an empty 200.
195
+ * - Other activities go through `normalize` to the `ChatHandler`: 200
196
+ * when it succeeds, 503 when it fails `NotAccepted` or a message can't
197
+ * be normalised. An activity with no event goes to `onUnhandled` and is
198
+ * answered 200. Past `deadline` (10 seconds by default) the handler is
199
+ * interrupted and the answer is 503. Each 503 is logged with its reason.
200
+ * - Answers 413 past `maxBodyBytes` (1 MiB by default), and 400 for a body
201
+ * that can't be read or is not a JSON object, both before the token is
202
+ * checked. `maxBodyBytes` must be a non-negative safe integer; another
203
+ * value is a defect when the layer is built.
204
+ *
205
+ * The metadata and the key set are fetched with redirects off, and the
206
+ * metadata is read up to 64 KiB. A metadata document or `jwks_uri` that
207
+ * can't be read is 503. The `HttpClient` has the same requirements as for
208
+ * `layer`.
209
+ *
210
+ * Token checks need the `Signature` service. Importing the key set's
211
+ * public keys goes through `Jwk.importPublic`, which needs a `WebCrypto`
212
+ * reference whatever crypto backend provides `Signature`.
213
+ *
214
+ * @stability unstable
215
+ * @category layers
216
+ * @since 4.1.5
217
+ */
218
+ export const layerWebhook = options => HttpRouter.use(Effect.fnUntraced(function* (router) {
219
+ const teams = yield* TeamsChat;
220
+ const internals = Adapter.internals.get(teams);
221
+ if (internals === undefined) return yield* Effect.die(new Error("TeamsChat.layerWebhook needs TeamsChat.layer"));
222
+ const handler = yield* ChatHandler;
223
+ const interactionHandler = yield* Effect.serviceOption(ChatInteraction.Handler);
224
+ const interactionRegistry = yield* Effect.serviceOption(ChatInteraction.Registry);
225
+ const verify = yield* Auth.makeVerifier({
226
+ cloud: teams.cloud,
227
+ appId: teams.appId,
228
+ tenantId: teams.tenantId
229
+ });
230
+ const interactionOptions = {
231
+ capabilities: internals.capabilities,
232
+ envelope: internals.envelope,
233
+ modalButtons: internals.modalButtons,
234
+ answer: internals.answer,
235
+ deadline: options.interactionDeadline === undefined ? Interactions.defaultDeadline : Duration.fromInputUnsafe(options.interactionDeadline)
236
+ };
237
+ const webhookOptions = {
238
+ verify,
239
+ context: {
240
+ appId: teams.appId,
241
+ connectorHosts: new Set(teams.cloud.connectorHosts),
242
+ fileHostSuffixes: teams.cloud.fileHostSuffixes
243
+ },
244
+ handle: handler.handle,
245
+ onUnhandled: options.onUnhandled ?? (() => Effect.void),
246
+ invoke: activity => Option.isNone(interactionHandler) ? Effect.succeed({
247
+ status: 200
248
+ }) : Effect.provideService(Interactions.invoke(activity, interactionOptions), ChatInteraction.Handler, interactionHandler.value),
249
+ command: activity => Option.isNone(interactionHandler) || Option.isNone(interactionRegistry) ? Effect.void : Effect.provideService(Interactions.command(activity, {
250
+ ...interactionOptions,
251
+ isRegistered: id => Effect.map(interactionRegistry.value.get(id), entry => entry?.definition.kind === "command")
252
+ }), ChatInteraction.Handler, interactionHandler.value),
253
+ deadline: options.deadline ?? Duration.seconds(10),
254
+ maxBodySize: ByteSize.bytes(options.maxBodyBytes ?? 1024 * 1024)
255
+ };
256
+ yield* router.add("POST", options.path, request => Webhook.handleRequest(request, webhookOptions));
257
+ }));
258
+ /**
259
+ * The address of a Teams conversation: the Bot Framework conversation id as
260
+ * it is. A channel thread is the channel's id followed by
261
+ * `;messageid={root}`.
262
+ *
263
+ * @stability unstable
264
+ * @category constructors
265
+ * @since 4.1.5
266
+ */
267
+ export const thread = Address.thread;
268
+ /**
269
+ * The parts of a Teams address, or `None` for another platform's or a
270
+ * malformed one.
271
+ *
272
+ * @stability unstable
273
+ * @category destructors
274
+ * @since 4.1.5
275
+ */
276
+ export const parts = Address.parts;
277
+ /**
278
+ * The normaliser, for a consumer's own transport. It checks no token: that
279
+ * is the transport's job.
280
+ *
281
+ * **Details**
282
+ *
283
+ * - Pure: takes an activity, gives zero or more events.
284
+ * - A `message` gives a `MessageCreated`. Its `text` is Teams' `text` as
285
+ * delivered, with `<at>…</at>` for each mention, where `mentions` point.
286
+ * A channel post is addressed to the channel, a reply to the post's
287
+ * thread.
288
+ * - `messageReaction` gives a `ReactionAdded` or `ReactionRemoved` per
289
+ * reaction. The six types Teams documents are Unicode emoji; any other is
290
+ * `custom:{type}`.
291
+ * - A targeted activity, a card submit and anything else give none.
292
+ * - `raw` is the activity.
293
+ *
294
+ * @stability unstable
295
+ * @category normalization
296
+ * @since 4.1.5
297
+ */
298
+ export const normalize = (activity, context) => {
299
+ const cloud = context.cloud ?? publicCloud;
300
+ return Normalize.normalize(activity, {
301
+ appId: context.appId,
302
+ connectorHosts: new Set(cloud.connectorHosts),
303
+ fileHostSuffixes: cloud.fileHostSuffixes
304
+ });
305
+ };
306
+ /**
307
+ * Reads one Teams mention, `<at>…</at>`, for `ChatTest`. The tag holds a
308
+ * display name and no id, so this is always `None`; a message's
309
+ * `mentions` come from its entities.
310
+ *
311
+ * @stability unstable
312
+ * @category testing
313
+ * @since 4.1.5
314
+ */
315
+ export const parseMention = () => Option.none();
316
+ //# sourceMappingURL=TeamsChat.js.map