@open-everywhere/provider-teams 0.0.0-stage → 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.
Files changed (146) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +21 -0
  3. package/README.md +46 -2
  4. package/agent/channels/teams-bot-name.ts +162 -0
  5. package/agent/channels/teams-catch-up.ts +244 -0
  6. package/agent/channels/teams-connector.ts +183 -0
  7. package/agent/channels/teams-conversation-ref.ts +398 -0
  8. package/agent/channels/teams-directory.ts +193 -0
  9. package/agent/channels/teams-engagement.ts +391 -0
  10. package/agent/channels/teams-fire-eligibility.ts +152 -0
  11. package/agent/channels/teams-front.ts +1404 -0
  12. package/agent/channels/teams-graph-boundary.ts +178 -0
  13. package/agent/channels/teams-graph-team-id.ts +106 -0
  14. package/agent/channels/teams-id-restore.ts +131 -0
  15. package/agent/channels/teams-identity.ts +395 -0
  16. package/agent/channels/teams-input-response.ts +129 -0
  17. package/agent/channels/teams-message-ops.ts +79 -0
  18. package/agent/channels/teams-origin-codec.ts +104 -0
  19. package/agent/channels/teams-post-arm.ts +323 -0
  20. package/agent/channels/teams-reaction-feedback.ts +127 -0
  21. package/agent/channels/teams-read.ts +510 -0
  22. package/agent/channels/teams-roster.ts +136 -0
  23. package/agent/channels/teams-stop.ts +319 -0
  24. package/agent/channels/teams-supervisor.ts +638 -0
  25. package/agent/channels/teams.ts +270 -0
  26. package/agent/contributions.ts +31 -0
  27. package/agent/docs-generated.ts +15 -0
  28. package/agent/ops.ts +129 -0
  29. package/agent/provider-events.ts +69 -0
  30. package/agent/register.ts +219 -0
  31. package/agent/surface-parity.ts +112 -0
  32. package/dist/agent/channels/teams-bot-name.d.ts +36 -0
  33. package/dist/agent/channels/teams-bot-name.d.ts.map +1 -0
  34. package/dist/agent/channels/teams-bot-name.js +141 -0
  35. package/dist/agent/channels/teams-bot-name.js.map +1 -0
  36. package/dist/agent/channels/teams-catch-up.d.ts +53 -0
  37. package/dist/agent/channels/teams-catch-up.d.ts.map +1 -0
  38. package/dist/agent/channels/teams-catch-up.js +221 -0
  39. package/dist/agent/channels/teams-catch-up.js.map +1 -0
  40. package/dist/agent/channels/teams-connector.d.ts +57 -0
  41. package/dist/agent/channels/teams-connector.d.ts.map +1 -0
  42. package/dist/agent/channels/teams-connector.js +132 -0
  43. package/dist/agent/channels/teams-connector.js.map +1 -0
  44. package/dist/agent/channels/teams-conversation-ref.d.ts +123 -0
  45. package/dist/agent/channels/teams-conversation-ref.d.ts.map +1 -0
  46. package/dist/agent/channels/teams-conversation-ref.js +368 -0
  47. package/dist/agent/channels/teams-conversation-ref.js.map +1 -0
  48. package/dist/agent/channels/teams-directory.d.ts +11 -0
  49. package/dist/agent/channels/teams-directory.d.ts.map +1 -0
  50. package/dist/agent/channels/teams-directory.js +179 -0
  51. package/dist/agent/channels/teams-directory.js.map +1 -0
  52. package/dist/agent/channels/teams-engagement.d.ts +174 -0
  53. package/dist/agent/channels/teams-engagement.d.ts.map +1 -0
  54. package/dist/agent/channels/teams-engagement.js +336 -0
  55. package/dist/agent/channels/teams-engagement.js.map +1 -0
  56. package/dist/agent/channels/teams-fire-eligibility.d.ts +26 -0
  57. package/dist/agent/channels/teams-fire-eligibility.d.ts.map +1 -0
  58. package/dist/agent/channels/teams-fire-eligibility.js +126 -0
  59. package/dist/agent/channels/teams-fire-eligibility.js.map +1 -0
  60. package/dist/agent/channels/teams-front.d.ts +249 -0
  61. package/dist/agent/channels/teams-front.d.ts.map +1 -0
  62. package/dist/agent/channels/teams-front.js +1143 -0
  63. package/dist/agent/channels/teams-front.js.map +1 -0
  64. package/dist/agent/channels/teams-graph-boundary.d.ts +45 -0
  65. package/dist/agent/channels/teams-graph-boundary.d.ts.map +1 -0
  66. package/dist/agent/channels/teams-graph-boundary.js +168 -0
  67. package/dist/agent/channels/teams-graph-boundary.js.map +1 -0
  68. package/dist/agent/channels/teams-graph-team-id.d.ts +30 -0
  69. package/dist/agent/channels/teams-graph-team-id.d.ts.map +1 -0
  70. package/dist/agent/channels/teams-graph-team-id.js +89 -0
  71. package/dist/agent/channels/teams-graph-team-id.js.map +1 -0
  72. package/dist/agent/channels/teams-id-restore.d.ts +34 -0
  73. package/dist/agent/channels/teams-id-restore.d.ts.map +1 -0
  74. package/dist/agent/channels/teams-id-restore.js +123 -0
  75. package/dist/agent/channels/teams-id-restore.js.map +1 -0
  76. package/dist/agent/channels/teams-identity.d.ts +148 -0
  77. package/dist/agent/channels/teams-identity.d.ts.map +1 -0
  78. package/dist/agent/channels/teams-identity.js +336 -0
  79. package/dist/agent/channels/teams-identity.js.map +1 -0
  80. package/dist/agent/channels/teams-input-response.d.ts +23 -0
  81. package/dist/agent/channels/teams-input-response.d.ts.map +1 -0
  82. package/dist/agent/channels/teams-input-response.js +102 -0
  83. package/dist/agent/channels/teams-input-response.js.map +1 -0
  84. package/dist/agent/channels/teams-message-ops.d.ts +3 -0
  85. package/dist/agent/channels/teams-message-ops.d.ts.map +1 -0
  86. package/dist/agent/channels/teams-message-ops.js +72 -0
  87. package/dist/agent/channels/teams-message-ops.js.map +1 -0
  88. package/dist/agent/channels/teams-origin-codec.d.ts +16 -0
  89. package/dist/agent/channels/teams-origin-codec.d.ts.map +1 -0
  90. package/dist/agent/channels/teams-origin-codec.js +99 -0
  91. package/dist/agent/channels/teams-origin-codec.js.map +1 -0
  92. package/dist/agent/channels/teams-post-arm.d.ts +37 -0
  93. package/dist/agent/channels/teams-post-arm.d.ts.map +1 -0
  94. package/dist/agent/channels/teams-post-arm.js +280 -0
  95. package/dist/agent/channels/teams-post-arm.js.map +1 -0
  96. package/dist/agent/channels/teams-reaction-feedback.d.ts +22 -0
  97. package/dist/agent/channels/teams-reaction-feedback.d.ts.map +1 -0
  98. package/dist/agent/channels/teams-reaction-feedback.js +108 -0
  99. package/dist/agent/channels/teams-reaction-feedback.js.map +1 -0
  100. package/dist/agent/channels/teams-read.d.ts +127 -0
  101. package/dist/agent/channels/teams-read.d.ts.map +1 -0
  102. package/dist/agent/channels/teams-read.js +424 -0
  103. package/dist/agent/channels/teams-read.js.map +1 -0
  104. package/dist/agent/channels/teams-roster.d.ts +54 -0
  105. package/dist/agent/channels/teams-roster.d.ts.map +1 -0
  106. package/dist/agent/channels/teams-roster.js +121 -0
  107. package/dist/agent/channels/teams-roster.js.map +1 -0
  108. package/dist/agent/channels/teams-stop.d.ts +74 -0
  109. package/dist/agent/channels/teams-stop.d.ts.map +1 -0
  110. package/dist/agent/channels/teams-stop.js +252 -0
  111. package/dist/agent/channels/teams-stop.js.map +1 -0
  112. package/dist/agent/channels/teams-supervisor.d.ts +351 -0
  113. package/dist/agent/channels/teams-supervisor.d.ts.map +1 -0
  114. package/dist/agent/channels/teams-supervisor.js +366 -0
  115. package/dist/agent/channels/teams-supervisor.js.map +1 -0
  116. package/dist/agent/channels/teams.d.ts +5 -0
  117. package/dist/agent/channels/teams.d.ts.map +1 -0
  118. package/dist/agent/channels/teams.js +246 -0
  119. package/dist/agent/channels/teams.js.map +1 -0
  120. package/dist/agent/contributions.d.ts +12 -0
  121. package/dist/agent/contributions.d.ts.map +1 -0
  122. package/dist/agent/contributions.js +31 -0
  123. package/dist/agent/contributions.js.map +1 -0
  124. package/dist/agent/docs-generated.d.ts +3 -0
  125. package/dist/agent/docs-generated.d.ts.map +1 -0
  126. package/dist/agent/docs-generated.js +13 -0
  127. package/dist/agent/docs-generated.js.map +1 -0
  128. package/dist/agent/ops.d.ts +14 -0
  129. package/dist/agent/ops.d.ts.map +1 -0
  130. package/dist/agent/ops.js +122 -0
  131. package/dist/agent/ops.js.map +1 -0
  132. package/dist/agent/provider-events.d.ts +3 -0
  133. package/dist/agent/provider-events.d.ts.map +1 -0
  134. package/dist/agent/provider-events.js +67 -0
  135. package/dist/agent/provider-events.js.map +1 -0
  136. package/dist/agent/register.d.ts +16 -0
  137. package/dist/agent/register.d.ts.map +1 -0
  138. package/dist/agent/register.js +198 -0
  139. package/dist/agent/register.js.map +1 -0
  140. package/dist/agent/surface-parity.d.ts +3 -0
  141. package/dist/agent/surface-parity.d.ts.map +1 -0
  142. package/dist/agent/surface-parity.js +106 -0
  143. package/dist/agent/surface-parity.js.map +1 -0
  144. package/package.json +183 -4
  145. package/tsconfig.build.json +22 -0
  146. package/tsconfig.json +15 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your Exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Tommy Long
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,21 @@
1
+ Open Everywhere
2
+ Copyright 2026 Tommy Long
3
+
4
+ This product is licensed under the Apache License, Version 2.0 (see LICENSE).
5
+
6
+ ---
7
+
8
+ Built on Vercel Eve (https://github.com/vercel/eve), licensed under the
9
+ Apache License, Version 2.0.
10
+
11
+ @open-everywhere/core also ships a patch that modifies Vercel Eve (the file in
12
+ its patches/ directory), with the oe-eve-patch command that applies it to a
13
+ consumer's own installed copy. The patch is licensed under the Apache License,
14
+ Version 2.0. No modified Vercel Eve files are distributed.
15
+
16
+ ---
17
+
18
+ Open Everywhere is an independent, open-source project. It is NOT affiliated
19
+ with, endorsed by, or sponsored by Anthropic. "Claude", "Claude Code", and
20
+ "Claude Tag" are referenced only to describe the prior art Open Everywhere is
21
+ inspired by, and are trademarks of their respective owner.
package/README.md CHANGED
@@ -1,3 +1,47 @@
1
- # Temporary Holding Version
1
+ # @open-everywhere/provider-teams
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Microsoft Teams channel and chat surfaces for Open Everywhere.
4
+
5
+ Part of [Open Everywhere](https://github.com/open-everywhere/open-everywhere) — an open, self-hostable autonomous teammate you tag where your
6
+ team works. This package is the Microsoft Teams provider. It supplies the identity mapper, the capability manifest, the post arm, the wake-origin codec, the Microsoft Graph read adapter, and the proactive routine dispatcher a Teams wake needs.
7
+
8
+ `@open-everywhere/core` owns the runtime — access and approvals, identity, memory, spend, the
9
+ audit chain. This package holds the Microsoft Teams half. The boundary between them is a vendor-coupling
10
+ one, and `packages/core/scripts/boundary-test.ts` checks it per provider: it names one or more
11
+ vendor fingerprint strings, asserts that **at least one** of them appears under this package, and
12
+ asserts that **every** one of them is absent from `packages/core/agent`. For Microsoft Teams those strings are
13
+ the hosts `graph.microsoft.com` and `smba.trafficmanager.net`. Core's registries refuse a provider the deployment has not selected.
14
+
15
+ ## Install
16
+
17
+ ```sh
18
+ npm i @open-everywhere/core @open-everywhere/provider-teams eve@0.54.3
19
+ npx oe-eve-patch
20
+ ```
21
+
22
+ **Both commands are required.** Core refuses to boot on an unpatched `eve`. A registry `eve` carries
23
+ no patch, so `npx oe-eve-patch` applies the copy `@open-everywhere/core` ships.
24
+
25
+ `eve` is a peer dependency, pinned to the exact version above, which is the pin
26
+ `@open-everywhere/core` declares as `peerDependencies.eve`. Node 24 or newer.
27
+
28
+ ## Use
29
+
30
+ One call registers the bundle:
31
+
32
+ ```ts
33
+ import { registerTeamsProvider } from "@open-everywhere/provider-teams/agent/register.js";
34
+
35
+ registerTeamsProvider();
36
+ ```
37
+
38
+ Credentials, the webhook and the Microsoft Teams app setup are in the runbook below.
39
+
40
+ ## Docs
41
+
42
+ - [Microsoft Teams runbook](https://github.com/open-everywhere/open-everywhere/blob/main/docs/deploy/surfaces/teams.md)
43
+ - [Documentation index](https://github.com/open-everywhere/open-everywhere/blob/main/docs/README.md)
44
+
45
+ ## Licence
46
+
47
+ Apache 2.0. The tarball carries `LICENSE` and `NOTICE`.
@@ -0,0 +1,162 @@
1
+ // teams-bot-name — the bot's OWN display name on Teams, read from Microsoft Graph (OPE-587,
2
+ // catalog leg OPE-609). The teams arm of core's per-surface bot-display-name registry
3
+ // (identity/bot-display-name.ts), so a Teams-pinned session introduces the agent by a real name
4
+ // instead of the generic identity line.
5
+ //
6
+ // ── TWO NAMES, TRIED IN ORDER ────────────────────────────────────────────────────────────────
7
+ // 1. THE TEAMS APP-CATALOG NAME — `teamsApps.displayName` — is what the Teams client actually
8
+ // renders beside a message (the manifest's `name.short`). Reading it needs a tenant-admin-
9
+ // consented `AppCatalog.Read.All`; OPE-587 shipped without this leg because that call 403'd
10
+ // (`Missing role permissions`) on the only tenant available at the time. OPE-609 grants that
11
+ // consent, so this arm now tries the catalog first:
12
+ // GET /v1.0/appCatalogs/teamsApps?$filter=externalId eq '{MICROSOFT_APP_ID}'&$expand=appDefinitions
13
+ // NOT RE-MEASURED against a live 200 response as of this change — the consent was granted but a
14
+ // fresh probe of the catalog call itself was not run. The fail-soft path below means a wrong
15
+ // guess about the response shape degrades to the fallback below, never to a broken turn.
16
+ // 2. THE SERVICE PRINCIPAL NAME — the ENTRA APP REGISTRATION display name — is the pre-OPE-609
17
+ // fallback and MEASURED LIVE against the e2e Teams tenant on 2026-08-15:
18
+ // GET /v1.0/servicePrincipals(appId='{MICROSOFT_APP_ID}')?$select=displayName
19
+ // The token carried exactly ONE application role (the RSC grant `Group.Selected`) and this call
20
+ // still returned HTTP 200 — an IMPLICIT self-read of the app's own directory object, needing no
21
+ // directory-read permission at all. `GET /users/{id}?$select=displayName` on the SAME token
22
+ // returned 403, confirming it is not a general directory-read grant. This is the name a
23
+ // deployment gets when `AppCatalog.Read.All` is unconsented, revoked, or the catalog call fails
24
+ // for any other reason — it can differ from the catalog name in case and spacing (measured in
25
+ // the e2e tenant: `open-everywhere` here versus `Open Everywhere` in the catalog / manifest).
26
+ //
27
+ // WHY THE SERVICE PRINCIPAL, NOT `/applications`, FOR LEG 2. `GET /v1.0/applications(appId='…')`
28
+ // answered 200 with the same string in the same probe, so both work for a SINGLE-TENANT bot. They
29
+ // stop being equivalent for a MULTI-TENANT one: the `application` object lives only in the app's
30
+ // HOME tenant, while a `servicePrincipal` exists in EVERY tenant that consented to the app — and
31
+ // the Graph token this arm rides is minted per tenant (`resolveTeamsTenantId`). The service
32
+ // principal is therefore the object that exists wherever the token points. NOT VERIFIED: only one
33
+ // tenant was available, so the foreign-tenant self-read is reasoned, not measured. Either leg fails
34
+ // soft: an unresolvable name renders the generic identity line, which is what a Teams session got
35
+ // before this arm existed.
36
+ //
37
+ // ── CACHING ──────────────────────────────────────────────────────────────────────────────────
38
+ // One memoised promise per instance, matching the slack arm's `botDisplayName()` exactly: the
39
+ // instruction assembler renders the identity line every turn, so an uncached arm would add a Graph
40
+ // round trip per turn and could flip the standing block's bytes mid-session. A rename needs a cold
41
+ // start to take effect. A FAILED resolution is cached too — the same posture — so a deployment
42
+ // missing the token does not re-probe Graph on every turn. The 5s timeout bounds BOTH legs
43
+ // together (one race around the whole two-call chain), not each leg separately — a hung catalog
44
+ // call cannot silently double the turn's worst-case wait by handing the fallback leg its own budget.
45
+
46
+ import { resolveTeamsAppId } from "eve/channels/teams";
47
+ import type { BotDisplayNameArm } from "@open-everywhere/core/agent/adapter-api.js";
48
+ import { liveTeamsGraphRequest, type TeamsGraphRequester } from "./teams-read.js";
49
+
50
+ const GRAPH_BASE = "https://graph.microsoft.com/v1.0";
51
+
52
+ /** The `displayName` field of a Graph directory object. Only a non-empty STRING counts — a response
53
+ * of another shape reads as "no name", never as a fabricated one. */
54
+ interface GraphNamedObject {
55
+ readonly displayName?: unknown;
56
+ }
57
+
58
+ /** A `teamsApps` catalog entry, `$expand=appDefinitions`-shaped: the resource itself carries
59
+ * `displayName` for its current published definition; `appDefinitions[0]` is a fallback for a
60
+ * response shape that omits the top-level field but still carries the expanded array. */
61
+ interface GraphCatalogApp extends GraphNamedObject {
62
+ readonly appDefinitions?: readonly GraphNamedObject[];
63
+ }
64
+
65
+ interface GraphCatalogPage {
66
+ readonly value?: readonly GraphCatalogApp[];
67
+ }
68
+
69
+ /** A Graph `displayName` field reduced to a usable string, or `undefined` for any other shape
70
+ * (absent, non-string, blank) — shared by both name legs so "what counts as a name" is defined
71
+ * exactly once. */
72
+ function trimmedName(value: unknown): string | undefined {
73
+ if (typeof value !== "string") return undefined;
74
+ const trimmed = value.trim();
75
+ return trimmed.length > 0 ? trimmed : undefined;
76
+ }
77
+
78
+ /**
79
+ * The app's own display name from its service principal, or `undefined` when Graph cannot answer.
80
+ * Pure but for the injected `req` — exported (not just the live wrapper below) so the URL, the
81
+ * shape read and the fail-soft rules are unit-testable with a canned requester, no token mint and
82
+ * no network call. Same DI shape as teams-fire-eligibility.ts's probes.
83
+ *
84
+ * FAIL-SOFT on everything: an empty appId, a thrown request (`liveTeamsGraphRequest` throws on a
85
+ * missing token or a non-ok response), a response that is not an object, and a `displayName` that is
86
+ * absent, non-string or blank all read `undefined`.
87
+ */
88
+ export async function teamsBotDisplayNameViaGraph(appId: string, req: TeamsGraphRequester): Promise<string | undefined> {
89
+ if (appId.length === 0) return undefined;
90
+ try {
91
+ const json = (await req(`${GRAPH_BASE}/servicePrincipals(appId='${encodeURIComponent(appId)}')?$select=displayName`)) as GraphNamedObject | null;
92
+ return trimmedName(json?.displayName);
93
+ } catch {
94
+ return undefined; // no token / 401 / 403 / 404 / transport failure ⇒ core renders the generic line
95
+ }
96
+ }
97
+
98
+ /**
99
+ * The Teams app-CATALOG display name (OPE-609) — what the Teams client renders beside a message —
100
+ * or `undefined` when Graph cannot answer. FAIL-SOFT identically to {@link teamsBotDisplayNameViaGraph}:
101
+ * a missing `AppCatalog.Read.All` consent throws a 403 inside `req`, caught here, so an unconsented
102
+ * or de-consented tenant reads `undefined` rather than blocking a turn. An empty `value` array (no
103
+ * catalog entry matches the app id) also reads `undefined`.
104
+ */
105
+ export async function teamsCatalogDisplayNameViaGraph(appId: string, req: TeamsGraphRequester): Promise<string | undefined> {
106
+ if (appId.length === 0) return undefined;
107
+ try {
108
+ const json = (await req(
109
+ `${GRAPH_BASE}/appCatalogs/teamsApps?$filter=externalId eq '${encodeURIComponent(appId)}'&$expand=appDefinitions`,
110
+ )) as GraphCatalogPage | null;
111
+ const entry = Array.isArray(json?.value) ? json.value[0] : undefined;
112
+ return trimmedName(entry?.displayName) ?? trimmedName(entry?.appDefinitions?.[0]?.displayName);
113
+ } catch {
114
+ return undefined; // no consent / 401 / 403 / 404 / transport failure ⇒ fall back to the service principal
115
+ }
116
+ }
117
+
118
+ /**
119
+ * The full resolution order (OPE-609): the catalog name first, the service-principal name second,
120
+ * `undefined` last. Pure but for the injected `req` — one requester serves both legs, so a test can
121
+ * assert exactly how many calls each leg made. Exported so the live arm and its tests share one
122
+ * definition of "what order do the two legs run in."
123
+ */
124
+ export async function resolveTeamsBotDisplayNameViaGraph(appId: string, req: TeamsGraphRequester): Promise<string | undefined> {
125
+ const catalog = await teamsCatalogDisplayNameViaGraph(appId, req);
126
+ if (catalog !== undefined) return catalog;
127
+ return teamsBotDisplayNameViaGraph(appId, req);
128
+ }
129
+
130
+ /** The memoised per-instance promise — see the CACHING note in the header. */
131
+ let displayNamePromise: Promise<string | undefined> | undefined;
132
+
133
+ /** Live arm: {@link resolveTeamsBotDisplayNameViaGraph} through the real app id + Graph transport,
134
+ * resolved once per instance. `resolveTeamsAppId()` throws when MICROSOFT_APP_ID is unset, so it
135
+ * is inside the try — an unconfigured deployment reads `undefined`, never an exception into
136
+ * instruction assembly. */
137
+ export const teamsBotDisplayName: BotDisplayNameArm = () => {
138
+ if (!displayNamePromise) {
139
+ displayNamePromise = (async () => {
140
+ try {
141
+ // The memoised value is a PROMISE and instruction assembly awaits it on every Teams turn,
142
+ // so a hung Graph call would block every turn on the instance, not one. The race bounds
143
+ // it: a stall settles the memo to `undefined` (the generic line), same as any other miss.
144
+ // The bound wraps BOTH legs (see the CACHING header note) — a slow catalog call eats into
145
+ // the same 5s budget the fallback leg would otherwise need.
146
+ const timeout = new Promise<undefined>((resolve) => {
147
+ const t = setTimeout(() => resolve(undefined), 5000);
148
+ t.unref?.();
149
+ });
150
+ return await Promise.race([resolveTeamsBotDisplayNameViaGraph(await resolveTeamsAppId(), liveTeamsGraphRequest), timeout]);
151
+ } catch {
152
+ return undefined;
153
+ }
154
+ })();
155
+ }
156
+ return displayNamePromise;
157
+ };
158
+
159
+ /** Test seam: drop the memoised name so one test cannot inherit another's. */
160
+ export function _resetTeamsBotDisplayNameForTest(): void {
161
+ displayNamePromise = undefined;
162
+ }