@opengeni/sdk 3.3.2-canary.1 → 3.4.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 (295) hide show
  1. package/README.md +1007 -72
  2. package/dist/adapters/express.d.ts +31 -0
  3. package/dist/adapters/express.js +87 -0
  4. package/dist/adapters/express.js.map +1 -0
  5. package/dist/adapters/hono.d.ts +16 -0
  6. package/dist/adapters/hono.js +8 -0
  7. package/dist/adapters/hono.js.map +1 -0
  8. package/dist/adapters/next.d.ts +29 -0
  9. package/dist/adapters/next.js +22 -0
  10. package/dist/adapters/next.js.map +1 -0
  11. package/dist/allowance-refusal.d.ts +2 -0
  12. package/dist/allowance-refusal.js +50 -0
  13. package/dist/allowance-refusal.js.map +1 -0
  14. package/dist/app-links.d.ts +42 -0
  15. package/dist/app-links.js +66 -0
  16. package/dist/app-links.js.map +1 -0
  17. package/dist/artifact-catalog.d.ts +40 -0
  18. package/dist/artifact-client.d.ts +20 -8
  19. package/dist/artifacts.d.ts +1 -1
  20. package/dist/artifacts.js +8 -6
  21. package/dist/automations.js +8 -2
  22. package/dist/automations.js.map +1 -1
  23. package/dist/azure-live-transport.d.ts +32 -0
  24. package/dist/browser.d.ts +6 -2
  25. package/dist/browser.js +25 -5
  26. package/dist/chat/fold.d.ts +75 -0
  27. package/dist/chat/handler.d.ts +41 -0
  28. package/dist/chat/http.d.ts +67 -0
  29. package/dist/chat/ids.d.ts +34 -0
  30. package/dist/chat/index.d.ts +9 -0
  31. package/dist/chat/index.js +1369 -0
  32. package/dist/chat/index.js.map +1 -0
  33. package/dist/chat/openai.d.ts +30 -0
  34. package/dist/chat/opengeni.d.ts +129 -0
  35. package/dist/chat/types.d.ts +207 -0
  36. package/dist/chat/vercel.d.ts +49 -0
  37. package/dist/chats.d.ts +8 -0
  38. package/dist/chunk-4AHR4KGA.js +301 -0
  39. package/dist/chunk-4AHR4KGA.js.map +1 -0
  40. package/dist/chunk-6GYGMLX4.js +332 -0
  41. package/dist/chunk-6GYGMLX4.js.map +1 -0
  42. package/dist/chunk-7EWT3PV6.js +368 -0
  43. package/dist/chunk-7EWT3PV6.js.map +1 -0
  44. package/dist/chunk-FTWVVPR6.js +1665 -0
  45. package/dist/chunk-FTWVVPR6.js.map +1 -0
  46. package/dist/{chunk-VYCTL62C.js → chunk-GZQSWAKD.js} +1 -1
  47. package/dist/chunk-GZQSWAKD.js.map +1 -0
  48. package/dist/chunk-KGEABAID.js +71 -0
  49. package/dist/chunk-KGEABAID.js.map +1 -0
  50. package/dist/{chunk-YKZME56C.js → chunk-KWADQ227.js} +3 -3
  51. package/dist/{chunk-YKZME56C.js.map → chunk-KWADQ227.js.map} +1 -1
  52. package/dist/{chunk-E5BNEG2D.js → chunk-NCU5OAN7.js} +27 -2
  53. package/dist/chunk-NCU5OAN7.js.map +1 -0
  54. package/dist/{chunk-BESZFWMU.js → chunk-OI5YLASH.js} +73 -2
  55. package/dist/chunk-OI5YLASH.js.map +1 -0
  56. package/dist/chunk-OV3POE62.js +359 -0
  57. package/dist/chunk-OV3POE62.js.map +1 -0
  58. package/dist/chunk-P7UWKORG.js +561 -0
  59. package/dist/chunk-P7UWKORG.js.map +1 -0
  60. package/dist/chunk-QGEIL4TR.js +195 -0
  61. package/dist/chunk-QGEIL4TR.js.map +1 -0
  62. package/dist/{chunk-GY6RQPCG.js → chunk-S2NLS3ES.js} +3598 -1278
  63. package/dist/chunk-S2NLS3ES.js.map +1 -0
  64. package/dist/chunk-UM4ZXXJR.js +9 -0
  65. package/dist/chunk-UM4ZXXJR.js.map +1 -0
  66. package/dist/{chunk-TFCLHRZK.js → chunk-UME3X7CP.js} +28 -32
  67. package/dist/chunk-UME3X7CP.js.map +1 -0
  68. package/dist/chunk-VT4YM4XQ.js +210 -0
  69. package/dist/chunk-VT4YM4XQ.js.map +1 -0
  70. package/dist/chunk-WSYYXONG.js +1602 -0
  71. package/dist/chunk-WSYYXONG.js.map +1 -0
  72. package/dist/{chunk-6NEPJ7NC.js → chunk-WVCJRSGJ.js} +119 -14
  73. package/dist/chunk-WVCJRSGJ.js.map +1 -0
  74. package/dist/chunk-X5ITQVXE.js +15 -0
  75. package/dist/chunk-X5ITQVXE.js.map +1 -0
  76. package/dist/chunk-XA7HVIHI.js +126 -0
  77. package/dist/chunk-XA7HVIHI.js.map +1 -0
  78. package/dist/{chunk-QTBAMHEF.js → chunk-YJCHB7R3.js} +60 -12
  79. package/dist/chunk-YJCHB7R3.js.map +1 -0
  80. package/dist/chunk-YKIHNLWD.js +153 -0
  81. package/dist/chunk-YKIHNLWD.js.map +1 -0
  82. package/dist/chunk-ZDUBPV33.js +277 -0
  83. package/dist/chunk-ZDUBPV33.js.map +1 -0
  84. package/dist/client.d.ts +1056 -118
  85. package/dist/codex-realtime-controller.d.ts +13 -0
  86. package/dist/codex-realtime-controller.js +4 -2
  87. package/dist/codex-realtime-v3-wire.d.ts +3 -2
  88. package/dist/codex-realtime.d.ts +5 -1
  89. package/dist/company-brain.d.ts +1 -11
  90. package/dist/core.d.ts +6 -2
  91. package/dist/core.js +23 -6
  92. package/dist/deprecation.d.ts +47 -0
  93. package/dist/document-authority-client.d.ts +24 -2
  94. package/dist/document-authority.js +7 -5
  95. package/dist/editable-artifacts/index.d.ts +1 -1
  96. package/dist/editable-artifacts/types.d.ts +12 -2
  97. package/dist/editable-artifacts.js +19 -3
  98. package/dist/editable-artifacts.js.map +1 -1
  99. package/dist/embedding-client.d.ts +129 -0
  100. package/dist/errors.d.ts +64 -1
  101. package/dist/external-vault-receiver.d.ts +203 -0
  102. package/dist/external-vault-receiver.js +564 -0
  103. package/dist/external-vault-receiver.js.map +1 -0
  104. package/dist/feedback.d.ts +23 -0
  105. package/dist/gateway-realtime-transport.js +1 -1
  106. package/dist/github-repositories.d.ts +10 -0
  107. package/dist/github-repositories.js +36 -0
  108. package/dist/github-repositories.js.map +1 -0
  109. package/dist/index.d.ts +61 -11
  110. package/dist/index.js +555 -338
  111. package/dist/index.js.map +1 -1
  112. package/dist/insights-usage.d.ts +33 -0
  113. package/dist/insights-usage.js +7 -0
  114. package/dist/insights-usage.js.map +1 -0
  115. package/dist/interaction.d.ts +165 -71
  116. package/dist/interaction.js +2 -2
  117. package/dist/knowledge.d.ts +7 -0
  118. package/dist/knowledge.js +20 -0
  119. package/dist/knowledge.js.map +1 -0
  120. package/dist/known-tools.d.ts +4 -0
  121. package/dist/message-links.d.ts +68 -0
  122. package/dist/model-context.d.ts +68 -0
  123. package/dist/model-display.d.ts +2 -0
  124. package/dist/model-display.js +17 -0
  125. package/dist/model-display.js.map +1 -0
  126. package/dist/organization-integration-policy.d.ts +26 -0
  127. package/dist/organization-integration-policy.js +26 -0
  128. package/dist/organization-integration-policy.js.map +1 -0
  129. package/dist/pr-review-client.d.ts +1 -1
  130. package/dist/pr-review.d.ts +1 -1
  131. package/dist/pr-review.js.map +1 -1
  132. package/dist/preference-registry.d.ts +1 -1
  133. package/dist/prepared-mcp-setup.d.ts +5 -0
  134. package/dist/proxy.d.ts +13 -11
  135. package/dist/realtime.d.ts +1 -1
  136. package/dist/realtime.js +253 -7
  137. package/dist/realtime.js.map +1 -1
  138. package/dist/session-history-import.d.ts +22 -0
  139. package/dist/session-history-import.js +36 -0
  140. package/dist/session-history-import.js.map +1 -0
  141. package/dist/session-list-entries.d.ts +1 -0
  142. package/dist/session-list-entries.js +7 -0
  143. package/dist/session-list-entries.js.map +1 -0
  144. package/dist/session-message-search.d.ts +53 -0
  145. package/dist/session-proxy-client.d.ts +28 -0
  146. package/dist/session-proxy.d.ts +334 -0
  147. package/dist/session-proxy.js +24 -0
  148. package/dist/session-proxy.js.map +1 -0
  149. package/dist/session-titles.d.ts +2 -28
  150. package/dist/session-usage-limits.d.ts +10 -0
  151. package/dist/session-usage-limits.js +43 -0
  152. package/dist/session-usage-limits.js.map +1 -0
  153. package/dist/shared-catalog-loader.d.ts +34 -0
  154. package/dist/site-ai.d.ts +35 -0
  155. package/dist/site-bridge-host.d.ts +112 -0
  156. package/dist/site-bridge-host.js +286 -0
  157. package/dist/site-bridge-host.js.map +1 -0
  158. package/dist/site-browser-entry.d.ts +1 -0
  159. package/dist/site-browser-runtime.gen.d.ts +1 -0
  160. package/dist/site-data.d.ts +178 -0
  161. package/dist/site-document.d.ts +5 -0
  162. package/dist/site-document.js +20 -0
  163. package/dist/site-document.js.map +1 -0
  164. package/dist/site-document.test.d.ts +1 -0
  165. package/dist/site-http.d.ts +17 -0
  166. package/dist/site-sql.d.ts +31 -0
  167. package/dist/site-tool-bridge.d.ts +57 -0
  168. package/dist/site.d.ts +186 -0
  169. package/dist/site.js +63 -0
  170. package/dist/site.js.map +1 -0
  171. package/dist/skills.d.ts +75 -0
  172. package/dist/sse.d.ts +1 -1
  173. package/dist/stream.d.ts +2 -0
  174. package/dist/tenant-workspaces.d.ts +47 -0
  175. package/dist/tenant-workspaces.js +8 -0
  176. package/dist/tenant-workspaces.js.map +1 -0
  177. package/dist/tool-auth.d.ts +87 -0
  178. package/dist/tool-auth.js +23 -0
  179. package/dist/tool-auth.js.map +1 -0
  180. package/dist/tool-display-metadata.d.ts +3 -0
  181. package/dist/tools-37DCTCNZ.js +12 -0
  182. package/dist/tools-37DCTCNZ.js.map +1 -0
  183. package/dist/tools.d.ts +81 -0
  184. package/dist/transcription.d.ts +1 -1
  185. package/dist/types.d.ts +2785 -592
  186. package/dist/usage-allowances.d.ts +36 -0
  187. package/dist/usage-allowances.js +80 -0
  188. package/dist/usage-allowances.js.map +1 -0
  189. package/dist/vault-types.d.ts +324 -0
  190. package/dist/vaults-api.d.ts +65 -0
  191. package/dist/workspace-artifacts.d.ts +47 -5
  192. package/dist/workspace-instruction-policies.d.ts +2 -2
  193. package/dist/workspace-integrations.d.ts +74 -0
  194. package/dist/workspace-integrations.js +67 -0
  195. package/dist/workspace-integrations.js.map +1 -0
  196. package/dist/workspace-state.d.ts +8 -71
  197. package/package.json +99 -5
  198. package/src/adapters/express.ts +136 -0
  199. package/src/adapters/hono.ts +18 -0
  200. package/src/adapters/next.ts +42 -0
  201. package/src/allowance-refusal.ts +5 -0
  202. package/src/app-links.ts +117 -0
  203. package/src/artifact-catalog.ts +51 -0
  204. package/src/artifact-client.ts +40 -49
  205. package/src/artifacts.ts +1 -0
  206. package/src/automations-client.ts +8 -2
  207. package/src/azure-live-transport.ts +286 -0
  208. package/src/browser.ts +35 -0
  209. package/src/chat/fold.ts +431 -0
  210. package/src/chat/handler.ts +240 -0
  211. package/src/chat/http.ts +257 -0
  212. package/src/chat/ids.ts +85 -0
  213. package/src/chat/index.ts +88 -0
  214. package/src/chat/openai.ts +439 -0
  215. package/src/chat/opengeni.ts +737 -0
  216. package/src/chat/types.ts +219 -0
  217. package/src/chat/vercel.ts +204 -0
  218. package/src/chats.ts +16 -0
  219. package/src/client.ts +5595 -1847
  220. package/src/codex-realtime-controller.ts +163 -8
  221. package/src/codex-realtime-v3-wire.ts +4 -3
  222. package/src/codex-realtime-v3.ts +12 -3
  223. package/src/codex-realtime.ts +11 -3
  224. package/src/company-brain.ts +0 -40
  225. package/src/core.ts +18 -0
  226. package/src/deprecation.ts +149 -0
  227. package/src/document-authority-client.ts +104 -1
  228. package/src/editable-artifacts/controller.ts +36 -2
  229. package/src/editable-artifacts/index.ts +1 -0
  230. package/src/editable-artifacts/types.ts +29 -16
  231. package/src/embedding-client.ts +519 -0
  232. package/src/errors.ts +281 -5
  233. package/src/external-vault-receiver.ts +914 -0
  234. package/src/feedback.ts +20 -0
  235. package/src/gateway-realtime-transport.ts +3 -3
  236. package/src/github-repositories.ts +60 -0
  237. package/src/index.ts +592 -65
  238. package/src/insights-usage.ts +64 -0
  239. package/src/interaction.ts +315 -93
  240. package/src/knowledge.ts +72 -0
  241. package/src/known-tools.ts +279 -0
  242. package/src/message-links.ts +178 -0
  243. package/src/model-context.ts +113 -0
  244. package/src/model-display.ts +11 -0
  245. package/src/organization-integration-policy.ts +54 -0
  246. package/src/pr-review-client.ts +1 -1
  247. package/src/pr-review.ts +1 -1
  248. package/src/preference-registry.ts +2 -0
  249. package/src/prepared-mcp-setup.ts +123 -0
  250. package/src/proxy.ts +23 -12
  251. package/src/realtime.ts +15 -6
  252. package/src/session-history-import.ts +84 -0
  253. package/src/session-list-entries.ts +1 -0
  254. package/src/session-message-search.ts +47 -0
  255. package/src/session-proxy-client.ts +68 -0
  256. package/src/session-proxy.ts +2098 -0
  257. package/src/session-titles.ts +8 -82
  258. package/src/session-usage-limits.ts +71 -0
  259. package/src/shared-catalog-loader.ts +169 -0
  260. package/src/site-ai.ts +284 -0
  261. package/src/site-bridge-host.ts +422 -0
  262. package/src/site-browser-entry.ts +6 -0
  263. package/src/site-browser-runtime.gen.ts +2 -0
  264. package/src/site-data.ts +372 -0
  265. package/src/site-document.test.ts +64 -0
  266. package/src/site-document.ts +18 -0
  267. package/src/site-http.ts +171 -0
  268. package/src/site-sql.ts +153 -0
  269. package/src/site-tool-bridge.ts +401 -0
  270. package/src/site.ts +878 -0
  271. package/src/skills.ts +69 -0
  272. package/src/sse.ts +9 -3
  273. package/src/stream.ts +33 -10
  274. package/src/tenant-workspaces.ts +148 -0
  275. package/src/tool-auth.ts +301 -0
  276. package/src/tool-display-metadata.ts +27 -0
  277. package/src/tools.ts +452 -0
  278. package/src/transcription.ts +3 -0
  279. package/src/types.ts +3142 -594
  280. package/src/usage-allowances.ts +189 -0
  281. package/src/vault-types.ts +379 -0
  282. package/src/vaults-api.ts +339 -0
  283. package/src/workspace-artifacts.ts +55 -6
  284. package/src/workspace-instruction-policies.ts +2 -1
  285. package/src/workspace-integrations.ts +402 -0
  286. package/src/workspace-state.ts +8 -82
  287. package/dist/chunk-6NEPJ7NC.js.map +0 -1
  288. package/dist/chunk-BESZFWMU.js.map +0 -1
  289. package/dist/chunk-E5BNEG2D.js.map +0 -1
  290. package/dist/chunk-GY6RQPCG.js.map +0 -1
  291. package/dist/chunk-OO5LPTO7.js +0 -132
  292. package/dist/chunk-OO5LPTO7.js.map +0 -1
  293. package/dist/chunk-QTBAMHEF.js.map +0 -1
  294. package/dist/chunk-TFCLHRZK.js.map +0 -1
  295. package/dist/chunk-VYCTL62C.js.map +0 -1
@@ -0,0 +1,519 @@
1
+ import { OpenGeniClient as OpenGeniArtifactClient } from "./artifact-client";
2
+ import type { OpenGeniClientOptions } from "./client";
3
+ import type { AddWorkspaceMemberRequest } from "./types";
4
+ import type {
5
+ ExternalIdentityLink,
6
+ BeginExternalIdentityLinkRequest,
7
+ BeginExternalIdentityLinkResponse,
8
+ ConfirmExternalIdentityLinkRequest,
9
+ ExternalIdentityLinkPreview,
10
+ ExternalIdentityLinkPage,
11
+ } from "@opengeni/contracts/external-identities";
12
+
13
+ /** Non-secret service attribution, serialized as a flat JSON object of at most 2 KiB. */
14
+ export type ServiceContext = Record<string, string | number | boolean>;
15
+
16
+ function hasStaticHeader(options: OpenGeniClientOptions, names: string[]): boolean {
17
+ return (
18
+ typeof options.headers !== "function" &&
19
+ Object.keys(options.headers ?? {}).some((key) => names.includes(key.toLowerCase()))
20
+ );
21
+ }
22
+
23
+ function serializeServiceContext(context: ServiceContext): string {
24
+ if (
25
+ !context ||
26
+ typeof context !== "object" ||
27
+ Array.isArray(context) ||
28
+ (Object.getPrototypeOf(context) !== Object.prototype && Object.getPrototypeOf(context) !== null)
29
+ )
30
+ throw new Error("Invalid service context: expected a flat JSON object");
31
+ const snapshot: ServiceContext = Object.create(null);
32
+ for (const [key, value] of Object.entries(context)) {
33
+ if (
34
+ typeof value !== "string" &&
35
+ typeof value !== "boolean" &&
36
+ !(typeof value === "number" && Number.isFinite(value))
37
+ )
38
+ throw new Error(
39
+ "Invalid service context: values must be strings, finite numbers, or booleans",
40
+ );
41
+ snapshot[key] = value;
42
+ }
43
+ // HTTP Headers require byte strings. JSON escapes preserve Unicode without
44
+ // percent-encoding the object or passing non-byte characters to fetch.
45
+ const json = JSON.stringify(snapshot).replace(
46
+ /[\u007f-\uffff]/g,
47
+ (character) => `\\u${character.charCodeAt(0).toString(16).padStart(4, "0")}`,
48
+ );
49
+ if (new TextEncoder().encode(json).byteLength > 2048)
50
+ throw new Error("Invalid service context: serialized JSON must not exceed 2 KiB");
51
+ return json;
52
+ }
53
+
54
+ /** Public product embedding administration, kept out of the native browser client. */
55
+ export class OpenGeniEmbeddingClient extends OpenGeniArtifactClient {
56
+ /** Read configuration (null means no configured ceiling). Requires admin or organization-key read authority. */
57
+ async getWorkspaceAllowance(
58
+ workspaceId: string,
59
+ ): Promise<import("@opengeni/contracts/usage-allowances").WorkspaceAllowance | null> {
60
+ return this.requestJson("GET", `/v1/workspaces/${encodeURIComponent(workspaceId)}/allowance`);
61
+ }
62
+
63
+ /**
64
+ * Read the lifecycle version even after clear (config=null). version=0 means
65
+ * never configured. Use the returned version to recreate or reconcile a 409;
66
+ * do not guess a CAS version or silently retry a new mutation.
67
+ * Requires the same budget-read authority as getWorkspaceAllowance.
68
+ */
69
+ async getWorkspaceAllowanceState(
70
+ workspaceId: string,
71
+ ): Promise<import("@opengeni/contracts/usage-allowances").WorkspaceAllowanceState> {
72
+ return this.requestJson(
73
+ "GET",
74
+ `/v1/workspaces/${encodeURIComponent(workspaceId)}/allowance/state`,
75
+ );
76
+ }
77
+
78
+ /**
79
+ * Set a USD-micro ceiling with exact-version CAS (0 only for first creation;
80
+ * after clear reuse its returned version or getWorkspaceAllowanceState). Requires
81
+ * organization key-control authority or account:admin, never workspace admin
82
+ * alone. Shares may oversubscribe the pool; actual post-call settlement can
83
+ * overshoot before the next admission check.
84
+ */
85
+ async setWorkspaceAllowance(
86
+ workspaceId: string,
87
+ request: import("@opengeni/contracts/usage-allowances").SetWorkspaceAllowanceRequest,
88
+ ): Promise<import("@opengeni/contracts/usage-allowances").WorkspaceAllowance> {
89
+ return this.requestJson(
90
+ "PUT",
91
+ `/v1/workspaces/${encodeURIComponent(workspaceId)}/allowance`,
92
+ request,
93
+ );
94
+ }
95
+
96
+ /**
97
+ * Clear with the exact version; grants and settled usage are not a billing
98
+ * refund. Supply operationId and replay the exact request after a lost response.
99
+ * Replays recheck authority and conflict after a later lifecycle change.
100
+ * On 409 read getWorkspaceAllowanceState before deciding on a new operation.
101
+ */
102
+ async clearWorkspaceAllowance(
103
+ workspaceId: string,
104
+ request: import("@opengeni/contracts/usage-allowances").ClearWorkspaceAllowanceRequest,
105
+ ): Promise<import("@opengeni/contracts/usage-allowances").ClearWorkspaceAllowanceResponse> {
106
+ return this.requestJson(
107
+ "DELETE",
108
+ `/v1/workspaces/${encodeURIComponent(workspaceId)}/allowance`,
109
+ request,
110
+ );
111
+ }
112
+
113
+ /** Grant USD micros once. Reuse the operationId and exact request after an uncertain response. */
114
+ async grantWorkspaceCredits(
115
+ workspaceId: string,
116
+ request: import("@opengeni/contracts/usage-allowances").GrantWorkspaceCreditsRequest,
117
+ ): Promise<import("@opengeni/contracts/usage-allowances").WorkspaceCreditGrant> {
118
+ return this.requestJson(
119
+ "POST",
120
+ `/v1/workspaces/${encodeURIComponent(workspaceId)}/allowance/grants`,
121
+ request,
122
+ );
123
+ }
124
+
125
+ /**
126
+ * Administer an existing member by canonical subject or external identity.
127
+ * null restores memberDefault; shares >1 are valid ceilings, not reservations.
128
+ * Concurrent calls may exceed the ceiling until their actual cost settles.
129
+ */
130
+ async setMemberAllowance(
131
+ workspaceId: string,
132
+ member: string | { source: string; externalId: string },
133
+ request: import("@opengeni/contracts/usage-allowances").SetMemberAllowanceRequest,
134
+ ): Promise<import("@opengeni/contracts/usage-allowances").MemberAllowance> {
135
+ const path =
136
+ typeof member === "string"
137
+ ? encodeURIComponent(member)
138
+ : `external/${encodeURIComponent(member.source)}/${encodeURIComponent(member.externalId)}`;
139
+ return this.requestJson(
140
+ "PUT",
141
+ `/v1/workspaces/${encodeURIComponent(workspaceId)}/members/${path}/allowance`,
142
+ request,
143
+ );
144
+ }
145
+
146
+ /** Paginated settled usage, current or YYYY-MM. Requires admin or organization-key read authority. */
147
+ async getUsage(
148
+ workspaceId: string,
149
+ query: import("@opengeni/contracts/usage-allowances").GetUsageRequest = {},
150
+ options: import("./client").OpenGeniRequestOptions = {},
151
+ ): Promise<import("@opengeni/contracts/usage-allowances").WorkspaceUsageResponse> {
152
+ return this.requestJson(
153
+ "GET",
154
+ `/v1/workspaces/${encodeURIComponent(workspaceId)}/usage`,
155
+ undefined,
156
+ usageQuery(query),
157
+ options,
158
+ );
159
+ }
160
+
161
+ /** Own usage only. On your backend use asUser(authenticatedUser); subject selectors are not accepted. */
162
+ async getMyUsage(
163
+ workspaceId: string,
164
+ query: import("@opengeni/contracts/usage-allowances").GetMyUsageRequest = {},
165
+ options: import("./client").OpenGeniRequestOptions = {},
166
+ ): Promise<import("@opengeni/contracts/usage-allowances").WorkspaceUsageResponse> {
167
+ return this.requestJson(
168
+ "GET",
169
+ `/v1/workspaces/${encodeURIComponent(workspaceId)}/usage/me`,
170
+ undefined,
171
+ usageQuery(query),
172
+ options,
173
+ );
174
+ }
175
+
176
+ /** Recover this actor's connection creation result without resending secrets.
177
+ * A 404 means no visible committed result, not proof that an in-flight write failed. */
178
+ async getConnectionCreationResult(
179
+ workspaceId: string,
180
+ operationId: string,
181
+ ): Promise<import("./types").ConnectionMetadata> {
182
+ const response = await this.requestJson<import("./types").ConnectionResponse>(
183
+ "GET",
184
+ `/v1/workspaces/${encodeURIComponent(workspaceId)}/connections/operations/${encodeURIComponent(operationId)}`,
185
+ );
186
+ return response.connection;
187
+ }
188
+
189
+ /** Rotate existing inline credentials only while no credential-consuming work
190
+ * is pending or active. Reuse the operation key and exact request to reconcile
191
+ * a lost response. This operation never schedules or retries model work. */
192
+ async rotateSessionMcpCredentials(
193
+ workspaceId: string,
194
+ sessionId: string,
195
+ request: import("./types").RotateSessionMcpCredentialsRequest,
196
+ ): Promise<import("./types").RotateSessionMcpCredentialsReceipt> {
197
+ return this.requestJson(
198
+ "POST",
199
+ `/v1/workspaces/${workspaceId}/sessions/${sessionId}/mcp-credentials/rotate`,
200
+ request,
201
+ );
202
+ }
203
+
204
+ /** Contract-checked successful JSON GET with its headers intact, for same-origin
205
+ * proxies that must forward paging metadata. Non-2xx responses throw. */
206
+ async requestJsonResponse(
207
+ path: string,
208
+ query: Record<string, string> = {},
209
+ options: import("./client").OpenGeniRequestOptions = {},
210
+ ): Promise<import("./client").FetchResponse> {
211
+ return await this.requestResponse("GET", path, query, {
212
+ ...options,
213
+ accept: "application/json",
214
+ });
215
+ }
216
+
217
+ /** Server-side organization-key client scoped to one host-authenticated user.
218
+ * Does not mutate this client, provision workspace membership, or link native
219
+ * identities. The API verifies key and membership authority on each request. */
220
+ asUser(externalId: string, options: { source?: string } = {}): this {
221
+ if (typeof window !== "undefined")
222
+ throw new Error("asUser is a server-side API; keep organization keys on your backend");
223
+ if (
224
+ this.serviceInitiatorHeader !== undefined ||
225
+ hasStaticHeader(this.options, ["x-opengeni-service-initiator", "x-opengeni-service-context"])
226
+ )
227
+ throw new Error(
228
+ "asUser and asService are mutually exclusive; start from the unscoped client",
229
+ );
230
+ const source = options.source ?? "default";
231
+ const validOpaqueText = (value: unknown, maxBytes: number): value is string =>
232
+ typeof value === "string" &&
233
+ value.length > 0 &&
234
+ value.length <= maxBytes &&
235
+ !value.includes("\0") &&
236
+ !/[\uD800-\uDFFF]/u.test(value) &&
237
+ new TextEncoder().encode(value).byteLength <= maxBytes;
238
+ if (!validOpaqueText(externalId, 1024) || !validOpaqueText(source, 200)) {
239
+ throw new Error("Invalid external identity reference");
240
+ }
241
+ const Client = this.constructor as new (options: OpenGeniClientOptions) => this;
242
+ const client = new Client({ ...this.options });
243
+ client.externalActorHeader = encodeURIComponent(
244
+ JSON.stringify({ mode: "external", identity: { externalId, source } }),
245
+ );
246
+ return client;
247
+ }
248
+
249
+ /** Server-side automation attribution under this client's existing credential.
250
+ * Returns a new client of the same class; grants no permissions or human/personal
251
+ * resource authority. Cannot be combined with asUser or asLinkedUser.
252
+ * Reapplying asService replaces the name and context rather than merging them. */
253
+ asService(name: string, context?: ServiceContext): this {
254
+ if (typeof window !== "undefined")
255
+ throw new Error("asService is a server-side API; keep API keys on your backend");
256
+ if (
257
+ this.externalActorHeader !== undefined ||
258
+ hasStaticHeader(this.options, ["x-opengeni-external-actor"])
259
+ )
260
+ throw new Error(
261
+ "asUser and asService are mutually exclusive; start from the unscoped client",
262
+ );
263
+ if (
264
+ typeof name !== "string" ||
265
+ !/^[a-z0-9][a-z0-9:._-]{0,63}$/.test(name) ||
266
+ name.trim() !== name
267
+ )
268
+ throw new Error("Invalid service initiator name");
269
+ const serializedContext = context === undefined ? undefined : serializeServiceContext(context);
270
+ const Client = this.constructor as new (options: OpenGeniClientOptions) => this;
271
+ const client = new Client({ ...this.options });
272
+ client.serviceInitiatorHeader = name;
273
+ client.serviceContextHeader = serializedContext;
274
+ return client;
275
+ }
276
+
277
+ /** Explicitly use a confirmed native delegation. Unlike asUser, new resources
278
+ * belong to the native user. Existing external resources are never reassigned.
279
+ * A stale, expired or revoked link is rejected by the server on every request. */
280
+ asLinkedUser(
281
+ externalId: string,
282
+ options: { source?: string; linkId: string; expectedLinkRevision: number },
283
+ ): this {
284
+ if (
285
+ !/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(options.linkId) ||
286
+ !Number.isSafeInteger(options.expectedLinkRevision) ||
287
+ options.expectedLinkRevision < 1
288
+ )
289
+ throw new Error("A confirmed identity link and its exact revision are required");
290
+ const client = this.asUser(
291
+ externalId,
292
+ options.source === undefined ? {} : { source: options.source },
293
+ );
294
+ const identity = JSON.parse(decodeURIComponent(client.externalActorHeader!)).identity;
295
+ client.externalActorHeader = encodeURIComponent(
296
+ JSON.stringify({
297
+ mode: "linked_native",
298
+ identity,
299
+ linkId: options.linkId,
300
+ expectedLinkRevision: options.expectedLinkRevision,
301
+ }),
302
+ );
303
+ return client;
304
+ }
305
+
306
+ /** Optional native-account delegation. Invoke on a server-side asUser client.
307
+ * Pass the one-time challenge to the native consent screen, never a URL query
308
+ * or analytics event. Ordinary external embedding needs none of this. */
309
+ async beginIdentityLink(
310
+ workspaceId: string,
311
+ input: BeginExternalIdentityLinkRequest,
312
+ ): Promise<BeginExternalIdentityLinkResponse> {
313
+ return this.requestJson(
314
+ "POST",
315
+ `/v1/workspaces/${encodeURIComponent(workspaceId)}/identity-links`,
316
+ input,
317
+ );
318
+ }
319
+
320
+ async getIdentityLink(workspaceId: string, linkId: string): Promise<ExternalIdentityLink> {
321
+ return this.requestJson(
322
+ "GET",
323
+ `/v1/workspaces/${encodeURIComponent(workspaceId)}/identity-links/${encodeURIComponent(linkId)}`,
324
+ );
325
+ }
326
+
327
+ /** Only links belonging to the effective participant; no organization-wide directory. */
328
+ async listIdentityLinks(workspaceId: string, cursor?: string): Promise<ExternalIdentityLinkPage> {
329
+ return this.requestJson(
330
+ "GET",
331
+ `/v1/workspaces/${encodeURIComponent(workspaceId)}/identity-links${cursor ? `?cursor=${encodeURIComponent(cursor)}` : ""}`,
332
+ );
333
+ }
334
+
335
+ /** Requires a canonical native browser session, not an organization API key. */
336
+ async previewIdentityLink(
337
+ workspaceId: string,
338
+ linkId: string,
339
+ challenge: string,
340
+ ): Promise<ExternalIdentityLinkPreview> {
341
+ return this.requestJson(
342
+ "POST",
343
+ `/v1/workspaces/${encodeURIComponent(workspaceId)}/identity-links/${encodeURIComponent(linkId)}/preview`,
344
+ { challenge },
345
+ );
346
+ }
347
+
348
+ async confirmIdentityLink(
349
+ workspaceId: string,
350
+ linkId: string,
351
+ input: ConfirmExternalIdentityLinkRequest,
352
+ ): Promise<ExternalIdentityLink> {
353
+ return this.requestJson(
354
+ "POST",
355
+ `/v1/workspaces/${encodeURIComponent(workspaceId)}/identity-links/${encodeURIComponent(linkId)}/confirm`,
356
+ input,
357
+ );
358
+ }
359
+
360
+ async revokeIdentityLink(
361
+ workspaceId: string,
362
+ linkId: string,
363
+ expectedRevision: number,
364
+ ): Promise<ExternalIdentityLink> {
365
+ return this.requestJson(
366
+ "POST",
367
+ `/v1/workspaces/${encodeURIComponent(workspaceId)}/identity-links/${encodeURIComponent(linkId)}/revoke`,
368
+ { expectedRevision },
369
+ );
370
+ }
371
+
372
+ /** Service-only lifecycle for an external actor's organization membership.
373
+ * A successful reactivation does not restore revoked workspace grants. */
374
+ async updateExternalIdentityMembership(
375
+ organizationId: string,
376
+ membershipId: string,
377
+ request: import("@opengeni/contracts/external-identities").UpdateExternalIdentityMembershipRequest,
378
+ options: { signal?: AbortSignal } = {},
379
+ ): Promise<import("@opengeni/contracts").OrganizationMember> {
380
+ return this.requestJson(
381
+ "PATCH",
382
+ `/v1/organizations/${encodeURIComponent(organizationId)}/external-members/${encodeURIComponent(membershipId)}`,
383
+ request,
384
+ undefined,
385
+ options,
386
+ );
387
+ }
388
+
389
+ /** Non-provisioning, content-free service lookup, including inactive identities. */
390
+ async lookupExternalIdentity(
391
+ organizationId: string,
392
+ identity: import("@opengeni/contracts/external-identities").ExternalIdentityReference,
393
+ ): Promise<import("@opengeni/contracts/external-identities").ExternalIdentityLookup> {
394
+ return this.requestJson(
395
+ "POST",
396
+ `/v1/organizations/${encodeURIComponent(organizationId)}/external-identities/lookup`,
397
+ identity,
398
+ );
399
+ }
400
+
401
+ /** Withdraw an external member's shared-workspace access and fence an exact
402
+ * pending keyed grant. Reuse the exact cancellation body after response loss. */
403
+ async cancelExternalWorkspaceMemberGrant(
404
+ organizationId: string,
405
+ workspaceId: string,
406
+ membershipId: string,
407
+ request: import("@opengeni/contracts/external-identities").CancelExternalWorkspaceMemberGrantRequest,
408
+ ): Promise<
409
+ import("@opengeni/contracts/external-identities").CancelExternalWorkspaceMemberGrantResponse
410
+ > {
411
+ return this.requestJson(
412
+ "POST",
413
+ `/v1/organizations/${encodeURIComponent(organizationId)}/workspaces/${encodeURIComponent(workspaceId)}/members/${encodeURIComponent(membershipId)}/revoke`,
414
+ request,
415
+ );
416
+ }
417
+
418
+ /** Replace an existing external member's permissions in one shared
419
+ * workspace. Keyed by `operationId`: reuse the exact body after response
420
+ * loss. Narrowing makes live authority re-check; nothing is cancelled. */
421
+ async updateExternalWorkspaceMember(
422
+ organizationId: string,
423
+ workspaceId: string,
424
+ membershipId: string,
425
+ request: import("@opengeni/contracts/external-identities").UpdateExternalWorkspaceMemberRequest,
426
+ ): Promise<
427
+ import("@opengeni/contracts/external-identities").UpdateExternalWorkspaceMemberResponse
428
+ > {
429
+ return this.requestJson(
430
+ "PATCH",
431
+ `/v1/organizations/${encodeURIComponent(organizationId)}/workspaces/${encodeURIComponent(workspaceId)}/external-members/${encodeURIComponent(membershipId)}`,
432
+ request,
433
+ );
434
+ }
435
+
436
+ async listConnectProviders(
437
+ workspaceId: string,
438
+ ): Promise<import("@opengeni/contracts/connect").ConnectProvider[]> {
439
+ return this.requestJson("GET", `/v1/workspaces/${workspaceId}/connect/catalog`);
440
+ }
441
+
442
+ async listConnectAccounts(
443
+ workspaceId: string,
444
+ ): Promise<import("@opengeni/contracts/connect").ConnectAccount[]> {
445
+ return this.requestJson("GET", `/v1/workspaces/${workspaceId}/connect/accounts`);
446
+ }
447
+
448
+ async getConnectAttempt(
449
+ workspaceId: string,
450
+ attemptId: string,
451
+ ): Promise<import("@opengeni/contracts/connect").ConnectAttempt> {
452
+ return this.requestJson("GET", `/v1/workspaces/${workspaceId}/connect/attempts/${attemptId}`);
453
+ }
454
+
455
+ async listPendingConnectAttempts(
456
+ workspaceId: string,
457
+ ): Promise<import("@opengeni/contracts/connect").ConnectAttempt[]> {
458
+ return this.requestJson("GET", `/v1/workspaces/${workspaceId}/connect/attempts`);
459
+ }
460
+
461
+ async advanceConnectAttempt(
462
+ workspaceId: string,
463
+ attemptId: string,
464
+ request: {
465
+ expectedRevision: number;
466
+ idempotencyKey: string;
467
+ action: import("@opengeni/contracts/connect").ConnectAdvance;
468
+ },
469
+ ): Promise<import("@opengeni/contracts/connect").ConnectAttempt> {
470
+ return this.requestJson(
471
+ "POST",
472
+ `/v1/workspaces/${workspaceId}/connect/attempts/${attemptId}/advance`,
473
+ request,
474
+ );
475
+ }
476
+
477
+ /** Stops setup; does not revoke already committed provider credentials. */
478
+ async cancelConnectAttempt(
479
+ workspaceId: string,
480
+ attemptId: string,
481
+ request: {
482
+ expectedRevision: number;
483
+ idempotencyKey: string;
484
+ },
485
+ ): Promise<import("@opengeni/contracts/connect").ConnectAttempt> {
486
+ return this.requestJson(
487
+ "POST",
488
+ `/v1/workspaces/${workspaceId}/connect/attempts/${attemptId}/cancel`,
489
+ request,
490
+ );
491
+ }
492
+
493
+ /**
494
+ * Explicit organization-service-key onboarding with chosen permissions. Not
495
+ * needed for the default path: an `asUser` request through a key with
496
+ * `members:manage` adds a missing member with conversation permissions on
497
+ * first use. Change an existing member with `updateExternalWorkspaceMember`.
498
+ */
499
+ async addExternalWorkspaceMember(
500
+ workspaceId: string,
501
+ request: {
502
+ identity: { externalId: string; source?: string };
503
+ permissions: AddWorkspaceMemberRequest["permissions"];
504
+ operationId?: string;
505
+ },
506
+ ): Promise<import("@opengeni/contracts/external-identities").ExternalIdentity> {
507
+ return this.requestJson("POST", `/v1/workspaces/${workspaceId}/external-members`, request);
508
+ }
509
+ }
510
+
511
+ function usageQuery(
512
+ query: import("@opengeni/contracts/usage-allowances").GetUsageRequest,
513
+ ): Record<string, string> {
514
+ return Object.fromEntries(
515
+ Object.entries(query)
516
+ .filter(([, value]) => value !== undefined)
517
+ .map(([key, value]) => [key, String(value)]),
518
+ );
519
+ }