@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.
- package/README.md +1078 -33
- package/dist/accounts.d.ts +153 -0
- package/dist/accounts.js +307 -0
- package/dist/accounts.js.map +1 -0
- package/dist/adapters/express.d.ts +31 -0
- package/dist/adapters/express.js +87 -0
- package/dist/adapters/express.js.map +1 -0
- package/dist/adapters/hono.d.ts +16 -0
- package/dist/adapters/hono.js +8 -0
- package/dist/adapters/hono.js.map +1 -0
- package/dist/adapters/next.d.ts +29 -0
- package/dist/adapters/next.js +22 -0
- package/dist/adapters/next.js.map +1 -0
- package/dist/allowance-refusal.d.ts +2 -0
- package/dist/allowance-refusal.js +50 -0
- package/dist/allowance-refusal.js.map +1 -0
- package/dist/artifact-catalog.d.ts +31 -0
- package/dist/artifact-client.d.ts +23 -11
- package/dist/artifacts.d.ts +1 -1
- package/dist/artifacts.js +7 -5
- package/dist/automations-client.d.ts +17 -0
- package/dist/automations.d.ts +3 -0
- package/dist/automations.js +84 -0
- package/dist/automations.js.map +1 -0
- package/dist/browser.d.ts +11 -0
- package/dist/browser.js +47 -0
- package/dist/browser.js.map +1 -0
- package/dist/chat/fold.d.ts +75 -0
- package/dist/chat/handler.d.ts +41 -0
- package/dist/chat/http.d.ts +67 -0
- package/dist/chat/ids.d.ts +34 -0
- package/dist/chat/index.d.ts +9 -0
- package/dist/chat/index.js +1694 -0
- package/dist/chat/index.js.map +1 -0
- package/dist/chat/openai.d.ts +30 -0
- package/dist/chat/opengeni.d.ts +128 -0
- package/dist/chat/types.d.ts +207 -0
- package/dist/chat/vercel.d.ts +49 -0
- package/dist/chats.d.ts +8 -0
- package/dist/{chunk-KIHGPM7H.js → chunk-2UXZUCEZ.js} +309 -46
- package/dist/chunk-2UXZUCEZ.js.map +1 -0
- package/dist/chunk-4SMEOV3P.js +246 -0
- package/dist/chunk-4SMEOV3P.js.map +1 -0
- package/dist/{chunk-FHI4DFIG.js → chunk-AH5D5Q5V.js} +31 -35
- package/dist/chunk-AH5D5Q5V.js.map +1 -0
- package/dist/chunk-APXVSSSY.js +301 -0
- package/dist/chunk-APXVSSSY.js.map +1 -0
- package/dist/chunk-DUVIYER4.js +639 -0
- package/dist/chunk-DUVIYER4.js.map +1 -0
- package/dist/{chunk-ILQZR5N6.js → chunk-FG3OO5LM.js} +3484 -750
- package/dist/chunk-FG3OO5LM.js.map +1 -0
- package/dist/chunk-GZYZT22T.js +260 -0
- package/dist/chunk-GZYZT22T.js.map +1 -0
- package/dist/chunk-HMGADJGZ.js +150 -0
- package/dist/chunk-HMGADJGZ.js.map +1 -0
- package/dist/{chunk-DXDL7EEW.js → chunk-KWADQ227.js} +198 -114
- package/dist/chunk-KWADQ227.js.map +1 -0
- package/dist/chunk-LY2K6ELJ.js +126 -0
- package/dist/chunk-LY2K6ELJ.js.map +1 -0
- package/dist/chunk-MOTJYIYL.js +340 -0
- package/dist/chunk-MOTJYIYL.js.map +1 -0
- package/dist/{chunk-MZWTWOX6.js → chunk-NC57YMUO.js} +447 -3
- package/dist/chunk-NC57YMUO.js.map +1 -0
- package/dist/chunk-RWKB6YZG.js +1270 -0
- package/dist/chunk-RWKB6YZG.js.map +1 -0
- package/dist/chunk-U6CV2SXO.js +195 -0
- package/dist/chunk-U6CV2SXO.js.map +1 -0
- package/dist/chunk-UM4ZXXJR.js +9 -0
- package/dist/chunk-UM4ZXXJR.js.map +1 -0
- package/dist/chunk-V6GIY62B.js +229 -0
- package/dist/chunk-V6GIY62B.js.map +1 -0
- package/dist/chunk-WU6GQG25.js +268 -0
- package/dist/chunk-WU6GQG25.js.map +1 -0
- package/dist/{chunk-VWE2QIVO.js → chunk-XNG7YGR3.js} +23 -6
- package/dist/chunk-XNG7YGR3.js.map +1 -0
- package/dist/{chunk-FRJFNDIR.js → chunk-YIKA2QT4.js} +37 -2
- package/dist/chunk-YIKA2QT4.js.map +1 -0
- package/dist/chunk-ZKPY6YAJ.js +135 -0
- package/dist/chunk-ZKPY6YAJ.js.map +1 -0
- package/dist/client.d.ts +843 -107
- package/dist/codex-realtime-controller.d.ts +6 -0
- package/dist/codex-realtime-controller.js +2 -2
- package/dist/codex-realtime-v3.d.ts +13 -2
- package/dist/company-brain.d.ts +22 -0
- package/dist/company-profile.d.ts +14 -1
- package/dist/core.d.ts +9 -3
- package/dist/core.js +28 -9
- package/dist/deprecation.d.ts +47 -0
- package/dist/desktop.d.ts +8 -0
- package/dist/document-authority-client.d.ts +51 -0
- package/dist/document-authority.d.ts +2 -0
- package/dist/document-authority.js +12 -0
- package/dist/document-authority.js.map +1 -0
- package/dist/editable-artifacts/browser-session.d.ts +7 -3
- package/dist/editable-artifacts/controller.d.ts +4 -1
- package/dist/editable-artifacts/errors.d.ts +1 -1
- package/dist/editable-artifacts/http-live-transport.d.ts +6 -2
- package/dist/editable-artifacts/index.d.ts +2 -0
- package/dist/editable-artifacts/open-failure.d.ts +9 -0
- package/dist/editable-artifacts/types.d.ts +6 -3
- package/dist/editable-artifacts/worker/kernel-adapter.d.ts +1 -1
- package/dist/editable-artifacts-worker.js +44 -17
- package/dist/editable-artifacts-worker.js.map +1 -1
- package/dist/editable-artifacts.js +243 -124
- package/dist/editable-artifacts.js.map +1 -1
- package/dist/embedding-client.d.ts +129 -0
- package/dist/errors.d.ts +36 -1
- package/dist/feedback.d.ts +23 -0
- package/dist/gateway-realtime-transport.d.ts +1 -0
- package/dist/gateway-realtime-transport.js +5 -3
- package/dist/github-repositories.d.ts +10 -0
- package/dist/github-repositories.js +36 -0
- package/dist/github-repositories.js.map +1 -0
- package/dist/index.d.ts +61 -12
- package/dist/index.js +277 -126
- package/dist/index.js.map +1 -1
- package/dist/interaction-revision-stream.d.ts +11 -0
- package/dist/interaction.d.ts +687 -5
- package/dist/interaction.js +32 -1
- package/dist/knowledge.d.ts +7 -0
- package/dist/knowledge.js +20 -0
- package/dist/knowledge.js.map +1 -0
- package/dist/message-links.d.ts +68 -0
- package/dist/model-context.d.ts +68 -0
- package/dist/model-display.d.ts +2 -0
- package/dist/model-display.js +15 -0
- package/dist/model-display.js.map +1 -0
- package/dist/model-picker-order.d.ts +1 -0
- package/dist/model-picker-order.js +10 -0
- package/dist/model-picker-order.js.map +1 -0
- package/dist/organization-integration-policy.d.ts +26 -0
- package/dist/organization-integration-policy.js +26 -0
- package/dist/organization-integration-policy.js.map +1 -0
- package/dist/organization-private-session-settings.d.ts +6 -0
- package/dist/organization-private-session-settings.js +22 -0
- package/dist/organization-private-session-settings.js.map +1 -0
- package/dist/organization-user-setup.d.ts +8 -0
- package/dist/organization-user-setup.js +16 -0
- package/dist/organization-user-setup.js.map +1 -0
- package/dist/pr-review-client.d.ts +16 -0
- package/dist/pr-review.d.ts +4 -0
- package/dist/pr-review.js +62 -0
- package/dist/pr-review.js.map +1 -0
- package/dist/preference-registry.d.ts +9 -1
- package/dist/proxy.d.ts +7 -5
- package/dist/realtime.d.ts +6 -4
- package/dist/realtime.js +10 -6
- package/dist/realtime.js.map +1 -1
- package/dist/retained-artifacts.d.ts +5 -1
- package/dist/session-history-import.d.ts +22 -0
- package/dist/session-history-import.js +36 -0
- package/dist/session-history-import.js.map +1 -0
- package/dist/session-list-entries.d.ts +1 -0
- package/dist/session-list-entries.js +7 -0
- package/dist/session-list-entries.js.map +1 -0
- package/dist/session-message-search.d.ts +53 -0
- package/dist/session-proxy-client.d.ts +24 -0
- package/dist/session-proxy.d.ts +245 -0
- package/dist/session-proxy.js +24 -0
- package/dist/session-proxy.js.map +1 -0
- package/dist/session-titles.d.ts +2 -0
- package/dist/site-browser-entry.d.ts +1 -0
- package/dist/site-browser-runtime.gen.d.ts +1 -0
- package/dist/site-document.d.ts +5 -0
- package/dist/site-document.js +20 -0
- package/dist/site-document.js.map +1 -0
- package/dist/site-document.test.d.ts +1 -0
- package/dist/site-http.d.ts +16 -0
- package/dist/site-tool-bridge.d.ts +44 -0
- package/dist/site.d.ts +101 -0
- package/dist/site.js +49 -0
- package/dist/site.js.map +1 -0
- package/dist/skills.d.ts +75 -0
- package/dist/stream.d.ts +2 -0
- package/dist/tenant-workspaces.d.ts +47 -0
- package/dist/tenant-workspaces.js +8 -0
- package/dist/tenant-workspaces.js.map +1 -0
- package/dist/tool-auth.d.ts +87 -0
- package/dist/tool-auth.js +23 -0
- package/dist/tool-auth.js.map +1 -0
- package/dist/tool-display-metadata.d.ts +3 -0
- package/dist/tools-FXBLUWAE.js +12 -0
- package/dist/tools-FXBLUWAE.js.map +1 -0
- package/dist/tools.d.ts +61 -0
- package/dist/types.d.ts +3048 -406
- package/dist/usage-allowances.d.ts +36 -0
- package/dist/usage-allowances.js +80 -0
- package/dist/usage-allowances.js.map +1 -0
- package/dist/workspace-artifacts.d.ts +33 -5
- package/dist/workspace-instruction-policies.d.ts +24 -2
- package/dist/workspace-integrations.d.ts +74 -0
- package/dist/workspace-integrations.js +65 -0
- package/dist/workspace-integrations.js.map +1 -0
- package/dist/workspace-learning.d.ts +124 -0
- package/dist/workspace-live-stream.d.ts +14 -0
- package/dist/workspace-state.d.ts +8 -71
- package/package.json +108 -3
- package/src/accounts.ts +443 -0
- package/src/adapters/express.ts +136 -0
- package/src/adapters/hono.ts +18 -0
- package/src/adapters/next.ts +42 -0
- package/src/allowance-refusal.ts +5 -0
- package/src/artifact-catalog.ts +41 -0
- package/src/artifact-client.ts +43 -52
- package/src/artifacts.ts +7 -1
- package/src/automations-client.ts +124 -0
- package/src/automations.ts +15 -0
- package/src/browser.ts +54 -0
- package/src/chat/fold.ts +431 -0
- package/src/chat/handler.ts +240 -0
- package/src/chat/http.ts +257 -0
- package/src/chat/ids.ts +85 -0
- package/src/chat/index.ts +87 -0
- package/src/chat/openai.ts +439 -0
- package/src/chat/opengeni.ts +722 -0
- package/src/chat/types.ts +219 -0
- package/src/chat/vercel.ts +204 -0
- package/src/chats.ts +16 -0
- package/src/client.ts +5162 -792
- package/src/codex-realtime-controller.ts +260 -12
- package/src/codex-realtime-lifecycle.ts +1 -0
- package/src/codex-realtime-v3.ts +162 -31
- package/src/codex-realtime.ts +1 -1
- package/src/company-brain.ts +59 -0
- package/src/company-profile.ts +17 -1
- package/src/core.ts +23 -1
- package/src/deprecation.ts +149 -0
- package/src/desktop.ts +11 -1
- package/src/document-authority-client.ts +219 -0
- package/src/document-authority.ts +17 -0
- package/src/editable-artifacts/browser-session.ts +36 -22
- package/src/editable-artifacts/controller.ts +102 -47
- package/src/editable-artifacts/errors.ts +2 -0
- package/src/editable-artifacts/http-live-transport.ts +62 -37
- package/src/editable-artifacts/index.ts +6 -0
- package/src/editable-artifacts/open-failure.ts +79 -0
- package/src/editable-artifacts/storage.ts +31 -40
- package/src/editable-artifacts/types.ts +6 -3
- package/src/editable-artifacts/worker/kernel-adapter.ts +23 -7
- package/src/editable-artifacts/worker/runtime.ts +26 -13
- package/src/editable-artifacts/worker/wire-codec.ts +23 -5
- package/src/embedding-client.ts +519 -0
- package/src/errors.ts +185 -4
- package/src/feedback.ts +20 -0
- package/src/gateway-realtime-transport.ts +253 -110
- package/src/github-repositories.ts +60 -0
- package/src/index.ts +603 -54
- package/src/interaction-revision-stream.ts +117 -0
- package/src/interaction.ts +1367 -51
- package/src/knowledge.ts +72 -0
- package/src/message-links.ts +178 -0
- package/src/model-context.ts +112 -0
- package/src/model-display.ts +10 -0
- package/src/model-picker-order.ts +6 -0
- package/src/organization-integration-policy.ts +54 -0
- package/src/organization-private-session-settings.ts +33 -0
- package/src/organization-user-setup.ts +31 -0
- package/src/pr-review-client.ts +92 -0
- package/src/pr-review.ts +17 -0
- package/src/preference-registry.ts +11 -0
- package/src/proxy.ts +17 -6
- package/src/realtime.ts +15 -4
- package/src/retained-artifacts.ts +101 -0
- package/src/session-history-import.ts +84 -0
- package/src/session-list-entries.ts +1 -0
- package/src/session-message-search.ts +47 -0
- package/src/session-proxy-client.ts +64 -0
- package/src/session-proxy.ts +1473 -0
- package/src/session-titles.ts +10 -0
- package/src/site-browser-entry.ts +6 -0
- package/src/site-browser-runtime.gen.ts +2 -0
- package/src/site-document.test.ts +64 -0
- package/src/site-document.ts +18 -0
- package/src/site-http.ts +162 -0
- package/src/site-tool-bridge.ts +146 -0
- package/src/site.ts +585 -0
- package/src/skills.ts +69 -0
- package/src/sse.ts +8 -2
- package/src/stream.ts +38 -4
- package/src/tenant-workspaces.ts +148 -0
- package/src/tool-auth.ts +301 -0
- package/src/tool-display-metadata.ts +19 -0
- package/src/tools.ts +396 -0
- package/src/types.ts +3607 -493
- package/src/usage-allowances.ts +189 -0
- package/src/workspace-artifacts.ts +40 -6
- package/src/workspace-instruction-policies.ts +26 -1
- package/src/workspace-integrations.ts +402 -0
- package/src/workspace-learning.ts +138 -0
- package/src/workspace-live-stream.ts +137 -0
- package/src/workspace-state.ts +8 -82
- package/dist/chunk-DXDL7EEW.js.map +0 -1
- package/dist/chunk-FHI4DFIG.js.map +0 -1
- package/dist/chunk-FRJFNDIR.js.map +0 -1
- package/dist/chunk-ILQZR5N6.js.map +0 -1
- package/dist/chunk-KIHGPM7H.js.map +0 -1
- package/dist/chunk-MZWTWOX6.js.map +0 -1
- package/dist/chunk-V5F253OG.js +0 -116
- package/dist/chunk-V5F253OG.js.map +0 -1
- 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 ?? "
|
|
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 ??
|
|
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 (
|
|
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") ||
|
package/src/feedback.ts
ADDED
|
@@ -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 };
|