@opengeni/sdk 0.52.1 → 1.0.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 (300) hide show
  1. package/README.md +1078 -33
  2. package/dist/accounts.d.ts +153 -0
  3. package/dist/accounts.js +307 -0
  4. package/dist/accounts.js.map +1 -0
  5. package/dist/adapters/express.d.ts +31 -0
  6. package/dist/adapters/express.js +87 -0
  7. package/dist/adapters/express.js.map +1 -0
  8. package/dist/adapters/hono.d.ts +16 -0
  9. package/dist/adapters/hono.js +8 -0
  10. package/dist/adapters/hono.js.map +1 -0
  11. package/dist/adapters/next.d.ts +29 -0
  12. package/dist/adapters/next.js +22 -0
  13. package/dist/adapters/next.js.map +1 -0
  14. package/dist/allowance-refusal.d.ts +2 -0
  15. package/dist/allowance-refusal.js +50 -0
  16. package/dist/allowance-refusal.js.map +1 -0
  17. package/dist/artifact-catalog.d.ts +31 -0
  18. package/dist/artifact-client.d.ts +23 -11
  19. package/dist/artifacts.d.ts +1 -1
  20. package/dist/artifacts.js +7 -5
  21. package/dist/automations-client.d.ts +17 -0
  22. package/dist/automations.d.ts +3 -0
  23. package/dist/automations.js +84 -0
  24. package/dist/automations.js.map +1 -0
  25. package/dist/browser.d.ts +11 -0
  26. package/dist/browser.js +47 -0
  27. package/dist/browser.js.map +1 -0
  28. package/dist/chat/fold.d.ts +75 -0
  29. package/dist/chat/handler.d.ts +41 -0
  30. package/dist/chat/http.d.ts +67 -0
  31. package/dist/chat/ids.d.ts +34 -0
  32. package/dist/chat/index.d.ts +9 -0
  33. package/dist/chat/index.js +1694 -0
  34. package/dist/chat/index.js.map +1 -0
  35. package/dist/chat/openai.d.ts +30 -0
  36. package/dist/chat/opengeni.d.ts +128 -0
  37. package/dist/chat/types.d.ts +207 -0
  38. package/dist/chat/vercel.d.ts +49 -0
  39. package/dist/chats.d.ts +8 -0
  40. package/dist/{chunk-KIHGPM7H.js → chunk-2UXZUCEZ.js} +309 -46
  41. package/dist/chunk-2UXZUCEZ.js.map +1 -0
  42. package/dist/chunk-4SMEOV3P.js +246 -0
  43. package/dist/chunk-4SMEOV3P.js.map +1 -0
  44. package/dist/{chunk-FHI4DFIG.js → chunk-AH5D5Q5V.js} +31 -35
  45. package/dist/chunk-AH5D5Q5V.js.map +1 -0
  46. package/dist/chunk-APXVSSSY.js +301 -0
  47. package/dist/chunk-APXVSSSY.js.map +1 -0
  48. package/dist/chunk-DUVIYER4.js +639 -0
  49. package/dist/chunk-DUVIYER4.js.map +1 -0
  50. package/dist/{chunk-ILQZR5N6.js → chunk-FG3OO5LM.js} +3484 -750
  51. package/dist/chunk-FG3OO5LM.js.map +1 -0
  52. package/dist/chunk-GZYZT22T.js +260 -0
  53. package/dist/chunk-GZYZT22T.js.map +1 -0
  54. package/dist/chunk-HMGADJGZ.js +150 -0
  55. package/dist/chunk-HMGADJGZ.js.map +1 -0
  56. package/dist/{chunk-DXDL7EEW.js → chunk-KWADQ227.js} +198 -114
  57. package/dist/chunk-KWADQ227.js.map +1 -0
  58. package/dist/chunk-LY2K6ELJ.js +126 -0
  59. package/dist/chunk-LY2K6ELJ.js.map +1 -0
  60. package/dist/chunk-MOTJYIYL.js +340 -0
  61. package/dist/chunk-MOTJYIYL.js.map +1 -0
  62. package/dist/{chunk-MZWTWOX6.js → chunk-NC57YMUO.js} +447 -3
  63. package/dist/chunk-NC57YMUO.js.map +1 -0
  64. package/dist/chunk-RWKB6YZG.js +1270 -0
  65. package/dist/chunk-RWKB6YZG.js.map +1 -0
  66. package/dist/chunk-U6CV2SXO.js +195 -0
  67. package/dist/chunk-U6CV2SXO.js.map +1 -0
  68. package/dist/chunk-UM4ZXXJR.js +9 -0
  69. package/dist/chunk-UM4ZXXJR.js.map +1 -0
  70. package/dist/chunk-V6GIY62B.js +229 -0
  71. package/dist/chunk-V6GIY62B.js.map +1 -0
  72. package/dist/chunk-WU6GQG25.js +268 -0
  73. package/dist/chunk-WU6GQG25.js.map +1 -0
  74. package/dist/{chunk-VWE2QIVO.js → chunk-XNG7YGR3.js} +23 -6
  75. package/dist/chunk-XNG7YGR3.js.map +1 -0
  76. package/dist/{chunk-FRJFNDIR.js → chunk-YIKA2QT4.js} +37 -2
  77. package/dist/chunk-YIKA2QT4.js.map +1 -0
  78. package/dist/chunk-ZKPY6YAJ.js +135 -0
  79. package/dist/chunk-ZKPY6YAJ.js.map +1 -0
  80. package/dist/client.d.ts +843 -107
  81. package/dist/codex-realtime-controller.d.ts +6 -0
  82. package/dist/codex-realtime-controller.js +2 -2
  83. package/dist/codex-realtime-v3.d.ts +13 -2
  84. package/dist/company-brain.d.ts +22 -0
  85. package/dist/company-profile.d.ts +14 -1
  86. package/dist/core.d.ts +9 -3
  87. package/dist/core.js +28 -9
  88. package/dist/deprecation.d.ts +47 -0
  89. package/dist/desktop.d.ts +8 -0
  90. package/dist/document-authority-client.d.ts +51 -0
  91. package/dist/document-authority.d.ts +2 -0
  92. package/dist/document-authority.js +12 -0
  93. package/dist/document-authority.js.map +1 -0
  94. package/dist/editable-artifacts/browser-session.d.ts +7 -3
  95. package/dist/editable-artifacts/controller.d.ts +4 -1
  96. package/dist/editable-artifacts/errors.d.ts +1 -1
  97. package/dist/editable-artifacts/http-live-transport.d.ts +6 -2
  98. package/dist/editable-artifacts/index.d.ts +2 -0
  99. package/dist/editable-artifacts/open-failure.d.ts +9 -0
  100. package/dist/editable-artifacts/types.d.ts +6 -3
  101. package/dist/editable-artifacts/worker/kernel-adapter.d.ts +1 -1
  102. package/dist/editable-artifacts-worker.js +44 -17
  103. package/dist/editable-artifacts-worker.js.map +1 -1
  104. package/dist/editable-artifacts.js +243 -124
  105. package/dist/editable-artifacts.js.map +1 -1
  106. package/dist/embedding-client.d.ts +129 -0
  107. package/dist/errors.d.ts +36 -1
  108. package/dist/feedback.d.ts +23 -0
  109. package/dist/gateway-realtime-transport.d.ts +1 -0
  110. package/dist/gateway-realtime-transport.js +5 -3
  111. package/dist/github-repositories.d.ts +10 -0
  112. package/dist/github-repositories.js +36 -0
  113. package/dist/github-repositories.js.map +1 -0
  114. package/dist/index.d.ts +61 -12
  115. package/dist/index.js +277 -126
  116. package/dist/index.js.map +1 -1
  117. package/dist/interaction-revision-stream.d.ts +11 -0
  118. package/dist/interaction.d.ts +687 -5
  119. package/dist/interaction.js +32 -1
  120. package/dist/knowledge.d.ts +7 -0
  121. package/dist/knowledge.js +20 -0
  122. package/dist/knowledge.js.map +1 -0
  123. package/dist/message-links.d.ts +68 -0
  124. package/dist/model-context.d.ts +68 -0
  125. package/dist/model-display.d.ts +2 -0
  126. package/dist/model-display.js +15 -0
  127. package/dist/model-display.js.map +1 -0
  128. package/dist/model-picker-order.d.ts +1 -0
  129. package/dist/model-picker-order.js +10 -0
  130. package/dist/model-picker-order.js.map +1 -0
  131. package/dist/organization-integration-policy.d.ts +26 -0
  132. package/dist/organization-integration-policy.js +26 -0
  133. package/dist/organization-integration-policy.js.map +1 -0
  134. package/dist/organization-private-session-settings.d.ts +6 -0
  135. package/dist/organization-private-session-settings.js +22 -0
  136. package/dist/organization-private-session-settings.js.map +1 -0
  137. package/dist/organization-user-setup.d.ts +8 -0
  138. package/dist/organization-user-setup.js +16 -0
  139. package/dist/organization-user-setup.js.map +1 -0
  140. package/dist/pr-review-client.d.ts +16 -0
  141. package/dist/pr-review.d.ts +4 -0
  142. package/dist/pr-review.js +62 -0
  143. package/dist/pr-review.js.map +1 -0
  144. package/dist/preference-registry.d.ts +9 -1
  145. package/dist/proxy.d.ts +7 -5
  146. package/dist/realtime.d.ts +6 -4
  147. package/dist/realtime.js +10 -6
  148. package/dist/realtime.js.map +1 -1
  149. package/dist/retained-artifacts.d.ts +5 -1
  150. package/dist/session-history-import.d.ts +22 -0
  151. package/dist/session-history-import.js +36 -0
  152. package/dist/session-history-import.js.map +1 -0
  153. package/dist/session-list-entries.d.ts +1 -0
  154. package/dist/session-list-entries.js +7 -0
  155. package/dist/session-list-entries.js.map +1 -0
  156. package/dist/session-message-search.d.ts +53 -0
  157. package/dist/session-proxy-client.d.ts +24 -0
  158. package/dist/session-proxy.d.ts +245 -0
  159. package/dist/session-proxy.js +24 -0
  160. package/dist/session-proxy.js.map +1 -0
  161. package/dist/session-titles.d.ts +2 -0
  162. package/dist/site-browser-entry.d.ts +1 -0
  163. package/dist/site-browser-runtime.gen.d.ts +1 -0
  164. package/dist/site-document.d.ts +5 -0
  165. package/dist/site-document.js +20 -0
  166. package/dist/site-document.js.map +1 -0
  167. package/dist/site-document.test.d.ts +1 -0
  168. package/dist/site-http.d.ts +16 -0
  169. package/dist/site-tool-bridge.d.ts +44 -0
  170. package/dist/site.d.ts +101 -0
  171. package/dist/site.js +49 -0
  172. package/dist/site.js.map +1 -0
  173. package/dist/skills.d.ts +75 -0
  174. package/dist/stream.d.ts +2 -0
  175. package/dist/tenant-workspaces.d.ts +47 -0
  176. package/dist/tenant-workspaces.js +8 -0
  177. package/dist/tenant-workspaces.js.map +1 -0
  178. package/dist/tool-auth.d.ts +87 -0
  179. package/dist/tool-auth.js +23 -0
  180. package/dist/tool-auth.js.map +1 -0
  181. package/dist/tool-display-metadata.d.ts +3 -0
  182. package/dist/tools-FXBLUWAE.js +12 -0
  183. package/dist/tools-FXBLUWAE.js.map +1 -0
  184. package/dist/tools.d.ts +61 -0
  185. package/dist/types.d.ts +3048 -406
  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/workspace-artifacts.d.ts +33 -5
  190. package/dist/workspace-instruction-policies.d.ts +24 -2
  191. package/dist/workspace-integrations.d.ts +74 -0
  192. package/dist/workspace-integrations.js +65 -0
  193. package/dist/workspace-integrations.js.map +1 -0
  194. package/dist/workspace-learning.d.ts +124 -0
  195. package/dist/workspace-live-stream.d.ts +14 -0
  196. package/dist/workspace-state.d.ts +8 -71
  197. package/package.json +108 -3
  198. package/src/accounts.ts +443 -0
  199. package/src/adapters/express.ts +136 -0
  200. package/src/adapters/hono.ts +18 -0
  201. package/src/adapters/next.ts +42 -0
  202. package/src/allowance-refusal.ts +5 -0
  203. package/src/artifact-catalog.ts +41 -0
  204. package/src/artifact-client.ts +43 -52
  205. package/src/artifacts.ts +7 -1
  206. package/src/automations-client.ts +124 -0
  207. package/src/automations.ts +15 -0
  208. package/src/browser.ts +54 -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 +87 -0
  214. package/src/chat/openai.ts +439 -0
  215. package/src/chat/opengeni.ts +722 -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 +5162 -792
  220. package/src/codex-realtime-controller.ts +260 -12
  221. package/src/codex-realtime-lifecycle.ts +1 -0
  222. package/src/codex-realtime-v3.ts +162 -31
  223. package/src/codex-realtime.ts +1 -1
  224. package/src/company-brain.ts +59 -0
  225. package/src/company-profile.ts +17 -1
  226. package/src/core.ts +23 -1
  227. package/src/deprecation.ts +149 -0
  228. package/src/desktop.ts +11 -1
  229. package/src/document-authority-client.ts +219 -0
  230. package/src/document-authority.ts +17 -0
  231. package/src/editable-artifacts/browser-session.ts +36 -22
  232. package/src/editable-artifacts/controller.ts +102 -47
  233. package/src/editable-artifacts/errors.ts +2 -0
  234. package/src/editable-artifacts/http-live-transport.ts +62 -37
  235. package/src/editable-artifacts/index.ts +6 -0
  236. package/src/editable-artifacts/open-failure.ts +79 -0
  237. package/src/editable-artifacts/storage.ts +31 -40
  238. package/src/editable-artifacts/types.ts +6 -3
  239. package/src/editable-artifacts/worker/kernel-adapter.ts +23 -7
  240. package/src/editable-artifacts/worker/runtime.ts +26 -13
  241. package/src/editable-artifacts/worker/wire-codec.ts +23 -5
  242. package/src/embedding-client.ts +519 -0
  243. package/src/errors.ts +185 -4
  244. package/src/feedback.ts +20 -0
  245. package/src/gateway-realtime-transport.ts +253 -110
  246. package/src/github-repositories.ts +60 -0
  247. package/src/index.ts +603 -54
  248. package/src/interaction-revision-stream.ts +117 -0
  249. package/src/interaction.ts +1367 -51
  250. package/src/knowledge.ts +72 -0
  251. package/src/message-links.ts +178 -0
  252. package/src/model-context.ts +112 -0
  253. package/src/model-display.ts +10 -0
  254. package/src/model-picker-order.ts +6 -0
  255. package/src/organization-integration-policy.ts +54 -0
  256. package/src/organization-private-session-settings.ts +33 -0
  257. package/src/organization-user-setup.ts +31 -0
  258. package/src/pr-review-client.ts +92 -0
  259. package/src/pr-review.ts +17 -0
  260. package/src/preference-registry.ts +11 -0
  261. package/src/proxy.ts +17 -6
  262. package/src/realtime.ts +15 -4
  263. package/src/retained-artifacts.ts +101 -0
  264. package/src/session-history-import.ts +84 -0
  265. package/src/session-list-entries.ts +1 -0
  266. package/src/session-message-search.ts +47 -0
  267. package/src/session-proxy-client.ts +64 -0
  268. package/src/session-proxy.ts +1473 -0
  269. package/src/session-titles.ts +10 -0
  270. package/src/site-browser-entry.ts +6 -0
  271. package/src/site-browser-runtime.gen.ts +2 -0
  272. package/src/site-document.test.ts +64 -0
  273. package/src/site-document.ts +18 -0
  274. package/src/site-http.ts +162 -0
  275. package/src/site-tool-bridge.ts +146 -0
  276. package/src/site.ts +585 -0
  277. package/src/skills.ts +69 -0
  278. package/src/sse.ts +8 -2
  279. package/src/stream.ts +38 -4
  280. package/src/tenant-workspaces.ts +148 -0
  281. package/src/tool-auth.ts +301 -0
  282. package/src/tool-display-metadata.ts +19 -0
  283. package/src/tools.ts +396 -0
  284. package/src/types.ts +3607 -493
  285. package/src/usage-allowances.ts +189 -0
  286. package/src/workspace-artifacts.ts +40 -6
  287. package/src/workspace-instruction-policies.ts +26 -1
  288. package/src/workspace-integrations.ts +402 -0
  289. package/src/workspace-learning.ts +138 -0
  290. package/src/workspace-live-stream.ts +137 -0
  291. package/src/workspace-state.ts +8 -82
  292. package/dist/chunk-DXDL7EEW.js.map +0 -1
  293. package/dist/chunk-FHI4DFIG.js.map +0 -1
  294. package/dist/chunk-FRJFNDIR.js.map +0 -1
  295. package/dist/chunk-ILQZR5N6.js.map +0 -1
  296. package/dist/chunk-KIHGPM7H.js.map +0 -1
  297. package/dist/chunk-MZWTWOX6.js.map +0 -1
  298. package/dist/chunk-V5F253OG.js +0 -116
  299. package/dist/chunk-V5F253OG.js.map +0 -1
  300. package/dist/chunk-VWE2QIVO.js.map +0 -1
package/src/errors.ts CHANGED
@@ -29,7 +29,7 @@ export class OpenGeniApiError extends Error {
29
29
  const displayMessage =
30
30
  options.displayMessage ??
31
31
  (gatewayFailure && fromResponse
32
- ? (decoded?.message ?? "OpenGeni is temporarily unavailable — retry.")
32
+ ? (decoded?.message ?? "Opengeni is temporarily unavailable — retry.")
33
33
  : `OpenGeni API ${status}: ${message}`);
34
34
  super(correlationId ? `${displayMessage} Reference: ${correlationId}.` : displayMessage);
35
35
  this.name = "OpenGeniApiError";
@@ -41,17 +41,118 @@ export class OpenGeniApiError extends Error {
41
41
  this.retryable = options.retryable ?? decoded?.retryable ?? retryableApiStatus(status);
42
42
  this.correlationId = correlationId;
43
43
  this.outcomeUnknown =
44
- options.outcomeUnknown ?? (gatewayFailure && !!options.mutation && !decoded);
44
+ options.outcomeUnknown ??
45
+ decoded?.outcomeUnknown ??
46
+ (gatewayFailure && !!options.mutation && !decoded);
45
47
  this.body = !fromResponse || decoded ? body : "";
46
48
  this.details = decoded?.details;
47
49
  }
48
50
  }
49
51
 
52
+ /** Deployment or organization setup must be completed before private chats can be created. */
53
+ export class OpenGeniSetupError extends OpenGeniApiError {
54
+ constructor(error: OpenGeniApiError) {
55
+ super(error.status, error.body, {
56
+ code: "OPENGENI_SETUP_REQUIRED",
57
+ retryable: false,
58
+ correlationId: error.correlationId,
59
+ displayMessage:
60
+ "Private chats require organization_private_session_settings.enabled (migration 0323). " +
61
+ "An organization owner or admin can enable Only me chats in the web app under Organization settings > Security & data, " +
62
+ "or use updateOrganizationPrivateSessionSettings from @opengeni/sdk/organization-private-session-settings " +
63
+ "with enabled: true, the current expectedVersion and a stable operationId " +
64
+ "(PATCH /v1/organizations/:organizationId/private-session-settings; an organization key needs workspace:admin). " +
65
+ "If platform readiness is unavailable, ask the deployment operator to activate session tenancy first.",
66
+ });
67
+ this.name = "OpenGeniSetupError";
68
+ }
69
+ }
70
+
71
+ /** A settled usage ceiling refuses the next call; retry after reset or an authorized grant. */
72
+ export class OpenGeniAllowanceExhaustedError extends OpenGeniApiError {
73
+ readonly scope: "workspace" | "member";
74
+ readonly resetsAt: string | null;
75
+ readonly subjectId: string | undefined;
76
+
77
+ constructor(
78
+ status: number,
79
+ body: string,
80
+ options: ConstructorParameters<typeof OpenGeniApiError>[2] = {},
81
+ ) {
82
+ super(status, body, {
83
+ ...options,
84
+ code: "allowance_exhausted",
85
+ retryable: false,
86
+ outcomeUnknown: false,
87
+ });
88
+ this.name = "OpenGeniAllowanceExhaustedError";
89
+ const refusal = allowanceExhaustedFields(body);
90
+ this.scope = refusal?.scope ?? "workspace";
91
+ this.resetsAt = refusal?.resetsAt ?? null;
92
+ this.subjectId = refusal?.subjectId;
93
+ }
94
+ }
95
+
96
+ /** Accept both the API error envelope and the standalone admission refusal. */
97
+ export function allowanceExhaustedFields(body: string): {
98
+ scope: "workspace" | "member";
99
+ resetsAt: string | null;
100
+ subjectId?: string;
101
+ } | null {
102
+ try {
103
+ const parsed: unknown = JSON.parse(body);
104
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
105
+ const root = parsed as Record<string, unknown>;
106
+ const error =
107
+ root.error && typeof root.error === "object" && !Array.isArray(root.error)
108
+ ? (root.error as Record<string, unknown>)
109
+ : root;
110
+ if (error.code !== "allowance_exhausted") return null;
111
+ const fields =
112
+ error.details && typeof error.details === "object" && !Array.isArray(error.details)
113
+ ? (error.details as Record<string, unknown>)
114
+ : error;
115
+ if (fields.scope !== "workspace" && fields.scope !== "member") return null;
116
+ if (fields.resetsAt !== null && typeof fields.resetsAt !== "string") return null;
117
+ return {
118
+ scope: fields.scope,
119
+ resetsAt: fields.resetsAt,
120
+ ...(typeof fields.subjectId === "string" ? { subjectId: fields.subjectId } : {}),
121
+ };
122
+ } catch {
123
+ return null;
124
+ }
125
+ }
126
+
127
+ export type OpenGeniSecureContextRequiredReason = "insecure_context" | "web_crypto_unavailable";
128
+
129
+ /**
130
+ * A browser operation requires secure-context-only platform capabilities.
131
+ * Callers may key UI behavior on the stable `secure_context_required` code;
132
+ * `reason` exists only to keep the human guidance truthful.
133
+ */
134
+ export class OpenGeniSecureContextRequiredError extends Error {
135
+ readonly code = "secure_context_required" as const;
136
+ readonly retryable = false;
137
+ readonly reason: OpenGeniSecureContextRequiredReason;
138
+
139
+ constructor(reason: OpenGeniSecureContextRequiredReason) {
140
+ super(
141
+ reason === "insecure_context"
142
+ ? "Couldn’t attach this file because Opengeni is open over HTTP. Attachments require a secure HTTPS connection. Open the secure site or configure HTTPS for this deployment."
143
+ : "Couldn’t attach this file because secure browser cryptography is unavailable. Attachments require HTTPS and Web Crypto support. Open a secure site in a supported browser or configure HTTPS for this deployment.",
144
+ );
145
+ this.name = "OpenGeniSecureContextRequiredError";
146
+ this.reason = reason;
147
+ }
148
+ }
149
+
50
150
  function decodeApiErrorBody(body: string): {
51
151
  code: string | undefined;
52
152
  message: string | undefined;
53
153
  requestId: string | undefined;
54
154
  retryable: boolean | undefined;
155
+ outcomeUnknown: boolean | undefined;
55
156
  details: Record<string, unknown> | undefined;
56
157
  } | null {
57
158
  if (!body) return null;
@@ -67,13 +168,24 @@ function decodeApiErrorBody(body: string): {
67
168
  const message = boundedApiField(nested.message);
68
169
  const requestId = boundedCorrelationId(nested.requestId);
69
170
  const retryable = typeof nested.retryable === "boolean" ? nested.retryable : undefined;
171
+ const outcomeUnknown =
172
+ typeof nested.outcomeUnknown === "boolean" ? nested.outcomeUnknown : undefined;
70
173
  const details = boundedApiDetails(nested.details);
71
- if (!code && !message && !requestId && retryable === undefined && !details) return null;
174
+ if (
175
+ !code &&
176
+ !message &&
177
+ !requestId &&
178
+ retryable === undefined &&
179
+ outcomeUnknown === undefined &&
180
+ !details
181
+ )
182
+ return null;
72
183
  return {
73
184
  code,
74
185
  message,
75
186
  requestId,
76
187
  retryable,
188
+ outcomeUnknown,
77
189
  details,
78
190
  };
79
191
  } catch {
@@ -114,7 +226,7 @@ function boundedCorrelationId(value: unknown): string | undefined {
114
226
  return value;
115
227
  }
116
228
 
117
- /** A short-lived session-list snapshot cursor can no longer be continued. */
229
+ /** A legacy short-lived session-list snapshot cursor can no longer be continued. */
118
230
  export class OpenGeniSessionListCursorError extends OpenGeniApiError {}
119
231
 
120
232
  /** The browser bundle and API disagree about their state-changing wire contract. */
@@ -138,6 +250,75 @@ export class OpenGeniStreamError extends Error {
138
250
  }
139
251
  }
140
252
 
253
+ /**
254
+ * Brand-neutral end-user copy for a failed SDK operation. Error.message, body,
255
+ * details and typed fields remain unchanged for diagnostics and host policy.
256
+ * Never use this to rewrite user, assistant or tool content.
257
+ */
258
+ export function formatErrorMessage(
259
+ error: unknown,
260
+ fallback = "The request could not be completed.",
261
+ ): string {
262
+ if (error instanceof OpenGeniApiError) {
263
+ let message: string;
264
+ if (error.outcomeUnknown) {
265
+ message = "The request could not be confirmed. Check its status before retrying.";
266
+ } else if (
267
+ error instanceof OpenGeniSetupError ||
268
+ error.code === "OPENGENI_SETUP_REQUIRED" ||
269
+ error.code === "SESSION_TENANCY_NOT_ACTIVATED"
270
+ ) {
271
+ message = "Private conversations are unavailable. Ask an administrator to enable them.";
272
+ } else if (error.code === "allowance_exhausted") {
273
+ message = "Usage limit reached. Wait for the reset or ask an administrator for more usage.";
274
+ } else if (error instanceof OpenGeniSessionListCursorError) {
275
+ message = "The conversation list changed. Refresh and try again.";
276
+ } else if (error.status === 401) {
277
+ message = "Sign in to continue.";
278
+ } else if (error.status === 403) {
279
+ message = "You don’t have permission to do that.";
280
+ } else if (error.status === 404) {
281
+ message = "The requested item is unavailable.";
282
+ } else if (error.status === 402 || error.code === "payment_required") {
283
+ message = "There are not enough credits to continue.";
284
+ } else if (error.status === 429 || error.code === "rate_limited") {
285
+ message = error.retryable
286
+ ? "Too many requests. Wait a moment and try again."
287
+ : "This request is unavailable. Ask an administrator for help.";
288
+ } else if (error.status === 409) {
289
+ message = "The request conflicts with the current state. Refresh and try again.";
290
+ } else if (error.status === 400 || error.status === 422) {
291
+ message = "The request could not be accepted. Check your input and try again.";
292
+ } else if (error.status === 408 || error.status === 425 || error.status === 0) {
293
+ message = error.retryable
294
+ ? "The connection could not be completed. Try again later."
295
+ : fallback;
296
+ } else if (error.status >= 500) {
297
+ message = error.retryable
298
+ ? "The service is temporarily unavailable. Try again later."
299
+ : "The service is unavailable. Ask an administrator for help.";
300
+ } else {
301
+ message = fallback;
302
+ }
303
+ return error.correlationId ? `${message} Reference: ${error.correlationId}.` : message;
304
+ }
305
+ if (
306
+ error instanceof OpenGeniSecureContextRequiredError ||
307
+ (error instanceof Error && "code" in error && error.code === "secure_context_required")
308
+ ) {
309
+ return "reason" in error && error.reason === "insecure_context"
310
+ ? "Attachments require HTTPS. Open this page over a secure connection."
311
+ : "Attachments require secure browser cryptography. Use a supported browser over HTTPS.";
312
+ }
313
+ if (error instanceof OpenGeniApiContractMismatchError) {
314
+ return "This page is out of date. Reload it before trying again.";
315
+ }
316
+ if (error instanceof OpenGeniStreamError) {
317
+ return "The live connection could not be restored. Refresh to check the latest state.";
318
+ }
319
+ return fallback;
320
+ }
321
+
141
322
  export function isAbortError(error: unknown): boolean {
142
323
  return (
143
324
  (error instanceof DOMException && error.name === "AbortError") ||
@@ -0,0 +1,20 @@
1
+ export type FeedbackSentiment = "positive" | "negative";
2
+ export type CreateFeedbackRequest = {
3
+ idempotencyKey: string;
4
+ sessionId?: string | undefined;
5
+ turnId?: string | undefined;
6
+ sentiment?: FeedbackSentiment | undefined;
7
+ comment?: string | undefined;
8
+ };
9
+ export type Feedback = {
10
+ id: string;
11
+ workspaceId: string;
12
+ subjectId: string;
13
+ principalKind: string | null;
14
+ sessionId: string | null;
15
+ turnId: string | null;
16
+ sentiment: FeedbackSentiment | null;
17
+ comment: string | null;
18
+ createdAt: string;
19
+ };
20
+ export type FeedbackSubmissionResponse = { feedback: Feedback; replayed: boolean };