@opengeni/sdk 0.57.0 → 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 +1017 -26
- 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-JDLDDRNE.js → chunk-2UXZUCEZ.js} +291 -34
- 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-JRPFWI6T.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-PKQ377ED.js → chunk-FG3OO5LM.js} +2686 -611
- 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-YKZME56C.js → chunk-KWADQ227.js} +3 -3
- package/dist/{chunk-YKZME56C.js.map → chunk-KWADQ227.js.map} +1 -1
- 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-ST5DDKJP.js → chunk-NC57YMUO.js} +121 -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-HJ3HHUT5.js → chunk-YIKA2QT4.js} +33 -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 +740 -94
- package/dist/codex-realtime-controller.d.ts +3 -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 +25 -6
- package/dist/deprecation.d.ts +47 -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 +240 -121
- 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.js +1 -1
- 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 +56 -11
- package/dist/index.js +242 -125
- package/dist/index.js.map +1 -1
- package/dist/interaction.d.ts +84 -1
- package/dist/interaction.js +6 -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 +3 -1
- package/dist/realtime.js +6 -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 +2863 -424
- 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-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 +4084 -515
- package/src/codex-realtime-controller.ts +235 -5
- 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/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 +169 -2
- package/src/feedback.ts +20 -0
- package/src/gateway-realtime-transport.ts +3 -3
- package/src/github-repositories.ts +60 -0
- package/src/index.ts +561 -41
- package/src/interaction.ts +276 -4
- 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 +1 -0
- 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 +3346 -501
- 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-state.ts +8 -82
- package/dist/chunk-GU6JF75T.js +0 -119
- package/dist/chunk-GU6JF75T.js.map +0 -1
- package/dist/chunk-HJ3HHUT5.js.map +0 -1
- package/dist/chunk-JDLDDRNE.js.map +0 -1
- package/dist/chunk-JRPFWI6T.js.map +0 -1
- package/dist/chunk-PKQ377ED.js.map +0 -1
- package/dist/chunk-ST5DDKJP.js.map +0 -1
- package/dist/chunk-VWE2QIVO.js.map +0 -1
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Links an agent writes into chat Markdown that point at OpenGeni-owned objects.
|
|
3
|
+
*
|
|
4
|
+
* Agents write these forms (tool receipts and bundled Skills teach them):
|
|
5
|
+
*
|
|
6
|
+
* - `artifact:<file uuid>` — a retained workspace file (exports, published files, images).
|
|
7
|
+
* - `sandbox:<path>[:<line>]` — a file in the session's sandbox or Connected Machine.
|
|
8
|
+
* - `/workspaces/<ws>/artifacts/editable/<32-hex id>` — a live editable document,
|
|
9
|
+
* workbook, or presentation.
|
|
10
|
+
* - `/workspaces/<ws>/artifacts/<uuid>` — a saved Site / published HTML artifact.
|
|
11
|
+
* - `/workspaces/<ws>/artifacts/files/<uuid>` — a retained file (console path form).
|
|
12
|
+
*
|
|
13
|
+
* None of them is a URL a browser can navigate on its own: the `/workspaces/...`
|
|
14
|
+
* forms are OpenGeni console routes, so inside another product they resolve
|
|
15
|
+
* against that product's origin and 404. Parse them with {@link parseOpenGeniLink}
|
|
16
|
+
* and route each target to the host's own UI (download, panel, page).
|
|
17
|
+
*/
|
|
18
|
+
export type OpenGeniLinkTarget =
|
|
19
|
+
| { kind: "file"; fileId: string; workspaceId: string | null; fromSession?: string }
|
|
20
|
+
| { kind: "editable-artifact"; artifactId: string; workspaceId: string; fromSession?: string }
|
|
21
|
+
| { kind: "site"; artifactId: string; workspaceId: string; fromSession?: string }
|
|
22
|
+
| { kind: "sandbox-file"; path: string; line: number | null };
|
|
23
|
+
|
|
24
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/iu;
|
|
25
|
+
const EDITABLE_ID = /^[0-9a-f]{32}$/iu;
|
|
26
|
+
const WORKSPACE_SEGMENT = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/u;
|
|
27
|
+
const SANDBOX_SCHEME = "sandbox:";
|
|
28
|
+
const LEGACY_WORKSPACE_PREFIX = "/workspace/";
|
|
29
|
+
const TRAILING_LINE = /:([0-9]+)$/u;
|
|
30
|
+
const TRAILING_INVALID_LINE = /:-(?:[0-9]+)$|:[0-9]+-[0-9]+$/u;
|
|
31
|
+
const CONTROL_CHARACTER = /[\u0000-\u001f\u007f]/u;
|
|
32
|
+
|
|
33
|
+
/** Application scheme names are case-insensitive, unlike their payloads. */
|
|
34
|
+
export function openGeniLinkScheme(href: string | undefined): "artifact" | "sandbox" | null {
|
|
35
|
+
const scheme = /^([a-z]+):/iu.exec(href ?? "")?.[1]?.toLowerCase();
|
|
36
|
+
return scheme === "artifact" || scheme === "sandbox" ? scheme : null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Reserved references must never fall back to navigation on a host origin. */
|
|
40
|
+
export function isReservedOpenGeniLink(href: string | undefined): boolean {
|
|
41
|
+
if (!href) return false;
|
|
42
|
+
if (openGeniLinkScheme(href) || href.startsWith(LEGACY_WORKSPACE_PREFIX)) return true;
|
|
43
|
+
// Decoding is for reservation only: encoded variants are not valid targets.
|
|
44
|
+
try {
|
|
45
|
+
return /^\/workspaces\/[^/]+\/artifacts(?:\/|[?#]|$)/u.test(decodeURIComponent(href));
|
|
46
|
+
} catch {
|
|
47
|
+
return /^\/workspaces\/[^/]+\/artifacts/u.test(href);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Parse an OpenGeni `sandbox:` href (plus the historical bare `/workspace/...`
|
|
53
|
+
* form). The decoded path is intentionally opaque: target selection, path
|
|
54
|
+
* policy, and filesystem authority belong to the session-aware host.
|
|
55
|
+
*/
|
|
56
|
+
export function parseSandboxLink(
|
|
57
|
+
href: string | undefined,
|
|
58
|
+
): { path: string; line: number | null } | null {
|
|
59
|
+
if (!href) return null;
|
|
60
|
+
const encodedLocation =
|
|
61
|
+
openGeniLinkScheme(href) === "sandbox"
|
|
62
|
+
? href.slice(SANDBOX_SCHEME.length)
|
|
63
|
+
: href.startsWith(LEGACY_WORKSPACE_PREFIX)
|
|
64
|
+
? href
|
|
65
|
+
: null;
|
|
66
|
+
if (!encodedLocation || encodedLocation.includes("?") || encodedLocation.includes("#")) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
if (TRAILING_INVALID_LINE.test(encodedLocation)) return null;
|
|
70
|
+
const lineMatch = TRAILING_LINE.exec(encodedLocation);
|
|
71
|
+
const encodedPath = lineMatch ? encodedLocation.slice(0, -lineMatch[0].length) : encodedLocation;
|
|
72
|
+
const line = lineMatch?.[1] ? Number(lineMatch[1]) : null;
|
|
73
|
+
if (line !== null && (!Number.isSafeInteger(line) || line < 1)) return null;
|
|
74
|
+
if (!encodedPath) return null;
|
|
75
|
+
try {
|
|
76
|
+
const path = decodeURIComponent(encodedPath);
|
|
77
|
+
return path && !CONTROL_CHARACTER.test(path) ? { path, line } : null;
|
|
78
|
+
} catch {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Return the retained-file id of an exact `artifact:<uuid>` reference. */
|
|
84
|
+
export function parseRetainedFileReference(href: string | undefined): string | null {
|
|
85
|
+
if (openGeniLinkScheme(href) !== "artifact") return null;
|
|
86
|
+
if (!href) return null;
|
|
87
|
+
const id = href.slice("artifact:".length);
|
|
88
|
+
return UUID.test(id) ? id.toLowerCase() : null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Classify an agent-authored Markdown href. Returns `null` for ordinary links
|
|
93
|
+
* (`https://…`, `mailto:`, relative host links), which render as-is.
|
|
94
|
+
*
|
|
95
|
+
* Only root-relative console paths are recognized; an absolute URL is always an
|
|
96
|
+
* ordinary link, so a host's own `https://` routes are never reinterpreted.
|
|
97
|
+
* A validated `?fromSession=<uuid>` return hint is preserved.
|
|
98
|
+
*/
|
|
99
|
+
export function parseOpenGeniLink(href: string | undefined): OpenGeniLinkTarget | null {
|
|
100
|
+
if (!href) return null;
|
|
101
|
+
const fileId = parseRetainedFileReference(href);
|
|
102
|
+
if (fileId) return { kind: "file", fileId, workspaceId: null };
|
|
103
|
+
if (openGeniLinkScheme(href) === "sandbox" || href.startsWith(LEGACY_WORKSPACE_PREFIX)) {
|
|
104
|
+
const location = parseSandboxLink(href);
|
|
105
|
+
return location ? { kind: "sandbox-file", ...location } : null;
|
|
106
|
+
}
|
|
107
|
+
if (!href.startsWith("/workspaces/") || href.includes("#")) return null;
|
|
108
|
+
const separator = href.indexOf("?");
|
|
109
|
+
const pathname = separator < 0 ? href : href.slice(0, separator);
|
|
110
|
+
const search = separator < 0 ? undefined : href.slice(separator + 1);
|
|
111
|
+
let fromSession: string | undefined;
|
|
112
|
+
if (search !== undefined) {
|
|
113
|
+
const params = new URLSearchParams(search);
|
|
114
|
+
const keys = [...params.keys()];
|
|
115
|
+
if (keys.some((key) => key !== "fromSession") || keys.length > 1) return null;
|
|
116
|
+
if (!UUID.test(params.get("fromSession") ?? "")) return null;
|
|
117
|
+
fromSession = params.get("fromSession")!.toLowerCase();
|
|
118
|
+
}
|
|
119
|
+
const parts = pathname.split("/");
|
|
120
|
+
const workspaceId = parts[2] ?? "";
|
|
121
|
+
if (parts[1] !== "workspaces" || parts[3] !== "artifacts" || !WORKSPACE_SEGMENT.test(workspaceId))
|
|
122
|
+
return null;
|
|
123
|
+
if (parts.length === 6 && parts[4] === "editable" && EDITABLE_ID.test(parts[5] ?? "")) {
|
|
124
|
+
return {
|
|
125
|
+
kind: "editable-artifact",
|
|
126
|
+
artifactId: parts[5]!.toLowerCase(),
|
|
127
|
+
workspaceId,
|
|
128
|
+
...(fromSession ? { fromSession } : {}),
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
if (parts.length === 6 && parts[4] === "files" && UUID.test(parts[5] ?? "")) {
|
|
132
|
+
return {
|
|
133
|
+
kind: "file",
|
|
134
|
+
fileId: parts[5]!.toLowerCase(),
|
|
135
|
+
workspaceId,
|
|
136
|
+
...(fromSession ? { fromSession } : {}),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
if (parts.length === 5 && UUID.test(parts[4] ?? "")) {
|
|
140
|
+
return {
|
|
141
|
+
kind: "site",
|
|
142
|
+
artifactId: parts[4]!.toLowerCase(),
|
|
143
|
+
workspaceId,
|
|
144
|
+
...(fromSession ? { fromSession } : {}),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** The OpenGeni console route for a target (the form agents write). */
|
|
151
|
+
export function openGeniConsolePath(
|
|
152
|
+
target: OpenGeniLinkTarget,
|
|
153
|
+
workspaceId: string,
|
|
154
|
+
): string | null {
|
|
155
|
+
const workspace = encodeURIComponent(
|
|
156
|
+
target.kind === "sandbox-file" ? workspaceId : (target.workspaceId ?? workspaceId),
|
|
157
|
+
);
|
|
158
|
+
const search =
|
|
159
|
+
target.kind !== "sandbox-file" && target.fromSession && UUID.test(target.fromSession)
|
|
160
|
+
? `?fromSession=${encodeURIComponent(target.fromSession)}`
|
|
161
|
+
: "";
|
|
162
|
+
switch (target.kind) {
|
|
163
|
+
case "file":
|
|
164
|
+
return `/workspaces/${workspace}/artifacts/files/${target.fileId}${search}`;
|
|
165
|
+
case "editable-artifact":
|
|
166
|
+
return `/workspaces/${workspace}/artifacts/editable/${target.artifactId}${search}`;
|
|
167
|
+
case "site":
|
|
168
|
+
return `/workspaces/${workspace}/artifacts/${target.artifactId}${search}`;
|
|
169
|
+
case "sandbox-file":
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Request header naming the session an embedded artifact read belongs to.
|
|
176
|
+
* `createSessionProxyHandler` only serves artifacts OpenGeni lists for it.
|
|
177
|
+
*/
|
|
178
|
+
export const SESSION_SCOPE_HEADER = "x-opengeni-session-id";
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
export type ModelContextInstructionLayerId =
|
|
2
|
+
| "operational_contract"
|
|
3
|
+
| "persona_and_core"
|
|
4
|
+
| "workspace_governance"
|
|
5
|
+
| "session_instructions"
|
|
6
|
+
| "workspace_memory"
|
|
7
|
+
| "skill_catalog"
|
|
8
|
+
| "codemode"
|
|
9
|
+
| "code_search"
|
|
10
|
+
| "git_bindings"
|
|
11
|
+
| "builtin_skills"
|
|
12
|
+
| "genesis_title"
|
|
13
|
+
| "sdk_capability_instructions"
|
|
14
|
+
| "sandbox_preamble"
|
|
15
|
+
| "sandbox_filesystem"
|
|
16
|
+
| "sent_system_instructions"
|
|
17
|
+
| "identity";
|
|
18
|
+
|
|
19
|
+
/** Sections of a modular operational contract, in composition order. */
|
|
20
|
+
export type AgentPromptModuleId =
|
|
21
|
+
| "base_behavior"
|
|
22
|
+
| "runtime_mechanics"
|
|
23
|
+
| "renderer_markdown"
|
|
24
|
+
| "sandbox"
|
|
25
|
+
| "connected_machine"
|
|
26
|
+
| "repositories"
|
|
27
|
+
| "workspace_environment"
|
|
28
|
+
| "rig"
|
|
29
|
+
| "artifacts"
|
|
30
|
+
| "media"
|
|
31
|
+
| "goals"
|
|
32
|
+
| "subagents"
|
|
33
|
+
| "knowledge"
|
|
34
|
+
| "skills"
|
|
35
|
+
| "admin"
|
|
36
|
+
| "attachments";
|
|
37
|
+
|
|
38
|
+
export type ModelContextInstructionModule = {
|
|
39
|
+
id: AgentPromptModuleId;
|
|
40
|
+
chars: number;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type ModelContextInstructionLayer = {
|
|
44
|
+
id: ModelContextInstructionLayerId;
|
|
45
|
+
title: string;
|
|
46
|
+
content: string;
|
|
47
|
+
utf8Bytes: number;
|
|
48
|
+
estimatedTokens: number;
|
|
49
|
+
/** Present on the operational contract of sessions with an agent configuration. */
|
|
50
|
+
modules?: ModelContextInstructionModule[] | undefined;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export type ModelContextToolVisibility = "eager" | "searchable";
|
|
54
|
+
|
|
55
|
+
export type ModelContextTool = {
|
|
56
|
+
name: string;
|
|
57
|
+
type: string;
|
|
58
|
+
visibility: ModelContextToolVisibility;
|
|
59
|
+
description?: string | undefined;
|
|
60
|
+
namespace?: string | undefined;
|
|
61
|
+
schema?: unknown | undefined;
|
|
62
|
+
utf8Bytes: number;
|
|
63
|
+
estimatedTokens: number;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export type ModelContextSkillKind = "preference_descriptor" | "runtime_skill" | "native_tool_skill";
|
|
67
|
+
|
|
68
|
+
export type ModelContextSkill = {
|
|
69
|
+
kind: ModelContextSkillKind;
|
|
70
|
+
name: string;
|
|
71
|
+
description: string;
|
|
72
|
+
source?: string | undefined;
|
|
73
|
+
path?: string | undefined;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export type ModelContextTokenCounts = {
|
|
77
|
+
instructions: number;
|
|
78
|
+
tools: number;
|
|
79
|
+
prefix: number;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export type ModelContextSnapshot = {
|
|
83
|
+
providerRequest?:
|
|
84
|
+
| {
|
|
85
|
+
provider: string;
|
|
86
|
+
body: string | null;
|
|
87
|
+
unavailableReason?: string | undefined;
|
|
88
|
+
parts: {
|
|
89
|
+
key: string;
|
|
90
|
+
estimatedTokens: number | null;
|
|
91
|
+
utf8Bytes: number;
|
|
92
|
+
itemEstimatedTokens?: (number | null)[] | undefined;
|
|
93
|
+
}[];
|
|
94
|
+
}
|
|
95
|
+
| undefined;
|
|
96
|
+
version: 1;
|
|
97
|
+
capturedAt: string;
|
|
98
|
+
source: "model_request";
|
|
99
|
+
requestIndex: number;
|
|
100
|
+
instructions: string;
|
|
101
|
+
layers: ModelContextInstructionLayer[];
|
|
102
|
+
tools: ModelContextTool[];
|
|
103
|
+
skills: ModelContextSkill[];
|
|
104
|
+
tokens: ModelContextTokenCounts;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export type SessionModelContextResponse = {
|
|
108
|
+
sessionId: string;
|
|
109
|
+
attemptId: string | null;
|
|
110
|
+
turnId: string | null;
|
|
111
|
+
snapshot: ModelContextSnapshot | null;
|
|
112
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** One clean model name and maker for every surface outside model settings. */
|
|
2
|
+
export {
|
|
3
|
+
humanizeModelSlug,
|
|
4
|
+
isRawModelLabel,
|
|
5
|
+
modelDisplayName,
|
|
6
|
+
modelSlug,
|
|
7
|
+
modelVendor,
|
|
8
|
+
type ModelDisplayInput,
|
|
9
|
+
type ModelVendor,
|
|
10
|
+
} from "@opengeni/contracts/model-display";
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { OpenGeniClient } from "./client";
|
|
2
|
+
|
|
3
|
+
export type OrganizationIntegrationPolicy = {
|
|
4
|
+
mode: "unrestricted" | "restricted";
|
|
5
|
+
allowedIntegrationKeys: string[];
|
|
6
|
+
revision: number;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type UpdateOrganizationIntegrationPolicyRequest = {
|
|
10
|
+
mode: "unrestricted" | "restricted";
|
|
11
|
+
allowedIntegrationKeys: string[];
|
|
12
|
+
expectedRevision: number;
|
|
13
|
+
operationId: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type PolicyClient = Pick<OpenGeniClient, "requestJson">;
|
|
17
|
+
|
|
18
|
+
export type OrganizationIntegrationCatalog = {
|
|
19
|
+
integrations: Array<{ key: string; label: string; kind: "curated" | "custom" }>;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** Discover stable policy identities; integrations must not guess provider identifiers. */
|
|
23
|
+
export async function getOrganizationIntegrationCatalog(
|
|
24
|
+
client: PolicyClient,
|
|
25
|
+
organizationId: string,
|
|
26
|
+
): Promise<OrganizationIntegrationCatalog> {
|
|
27
|
+
return client.requestJson(
|
|
28
|
+
"GET",
|
|
29
|
+
`/v1/organizations/${encodeURIComponent(organizationId)}/integration-policy/catalog`,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function getOrganizationIntegrationPolicy(
|
|
34
|
+
client: PolicyClient,
|
|
35
|
+
organizationId: string,
|
|
36
|
+
): Promise<OrganizationIntegrationPolicy> {
|
|
37
|
+
return client.requestJson(
|
|
38
|
+
"GET",
|
|
39
|
+
`/v1/organizations/${encodeURIComponent(organizationId)}/integration-policy`,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Retain operationId and the exact request when reconciling an uncertain outcome. */
|
|
44
|
+
export async function updateOrganizationIntegrationPolicy(
|
|
45
|
+
client: PolicyClient,
|
|
46
|
+
organizationId: string,
|
|
47
|
+
request: UpdateOrganizationIntegrationPolicyRequest,
|
|
48
|
+
): Promise<OrganizationIntegrationPolicy> {
|
|
49
|
+
return client.requestJson(
|
|
50
|
+
"PUT",
|
|
51
|
+
`/v1/organizations/${encodeURIComponent(organizationId)}/integration-policy`,
|
|
52
|
+
request,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { OpenGeniClient } from "./client";
|
|
2
|
+
import type {
|
|
3
|
+
OrganizationPrivateSessionSettings,
|
|
4
|
+
UpdateOrganizationPrivateSessionSettingsRequest,
|
|
5
|
+
} from "./types";
|
|
6
|
+
|
|
7
|
+
type OrganizationPrivateSessionSettingsClient = Pick<OpenGeniClient, "requestJson">;
|
|
8
|
+
|
|
9
|
+
function settingsPath(organizationId: string): string {
|
|
10
|
+
return `/v1/organizations/${organizationId}/private-session-settings`;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export async function getOrganizationPrivateSessionSettings(
|
|
14
|
+
client: OrganizationPrivateSessionSettingsClient,
|
|
15
|
+
organizationId: string,
|
|
16
|
+
): Promise<OrganizationPrivateSessionSettings> {
|
|
17
|
+
return await client.requestJson<OrganizationPrivateSessionSettings>(
|
|
18
|
+
"GET",
|
|
19
|
+
settingsPath(organizationId),
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function updateOrganizationPrivateSessionSettings(
|
|
24
|
+
client: OrganizationPrivateSessionSettingsClient,
|
|
25
|
+
organizationId: string,
|
|
26
|
+
request: UpdateOrganizationPrivateSessionSettingsRequest,
|
|
27
|
+
): Promise<OrganizationPrivateSessionSettings> {
|
|
28
|
+
return await client.requestJson<OrganizationPrivateSessionSettings>(
|
|
29
|
+
"PATCH",
|
|
30
|
+
settingsPath(organizationId),
|
|
31
|
+
request,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { OpenGeniClient } from "./client";
|
|
2
|
+
import type {
|
|
3
|
+
OrganizationUserSetupDelivery,
|
|
4
|
+
OrganizationUserSetupPreview,
|
|
5
|
+
PreviewOrganizationUserSetupRequest,
|
|
6
|
+
RetryOrganizationUserSetupDeliveryRequest,
|
|
7
|
+
} from "./types";
|
|
8
|
+
|
|
9
|
+
type OrganizationUserSetupClient = Pick<OpenGeniClient, "requestJson">;
|
|
10
|
+
|
|
11
|
+
/** Safe signed-out projection of the exact organization role and shared access in a setup link. */
|
|
12
|
+
export function previewOrganizationUserSetup(
|
|
13
|
+
client: OrganizationUserSetupClient,
|
|
14
|
+
request: PreviewOrganizationUserSetupRequest,
|
|
15
|
+
): Promise<OrganizationUserSetupPreview> {
|
|
16
|
+
return client.requestJson("POST", "/v1/auth/organization-setup/preview", request);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Retry a failed or explicitly outcome-unknown delivery with its stable provider key. */
|
|
20
|
+
export function retryOrganizationUserSetupDelivery(
|
|
21
|
+
client: OrganizationUserSetupClient,
|
|
22
|
+
organizationId: string,
|
|
23
|
+
invitationId: string,
|
|
24
|
+
request: RetryOrganizationUserSetupDeliveryRequest,
|
|
25
|
+
): Promise<OrganizationUserSetupDelivery> {
|
|
26
|
+
return client.requestJson(
|
|
27
|
+
"POST",
|
|
28
|
+
`/v1/organizations/${organizationId}/invitations/${invitationId}/delivery/retry`,
|
|
29
|
+
request,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { OpenGeniClient as OpenGeniCoreClient } from "./client";
|
|
2
|
+
import type {
|
|
3
|
+
CreatePrReviewAppRegistrationRequest,
|
|
4
|
+
CreatePrReviewRepositoryBindingRequest,
|
|
5
|
+
PrReviewAppRegistration,
|
|
6
|
+
PrReviewRepositoryBinding,
|
|
7
|
+
ListPrReviewConfigurationResponse,
|
|
8
|
+
PrReviewManagedGitHubSetup,
|
|
9
|
+
UpdatePrReviewAppRegistrationRequest,
|
|
10
|
+
UpdatePrReviewRepositoryBindingRequest,
|
|
11
|
+
} from "./types";
|
|
12
|
+
|
|
13
|
+
export type OpenGeniPrReviewTransport = Pick<OpenGeniCoreClient, "requestJson" | "requestVoid">;
|
|
14
|
+
|
|
15
|
+
/** Optional OpenGeni Review Bot API surface, isolated from the eager core client graph. */
|
|
16
|
+
export class OpenGeniPrReviewClient {
|
|
17
|
+
constructor(private readonly client: OpenGeniPrReviewTransport) {}
|
|
18
|
+
|
|
19
|
+
async listConfiguration(workspaceId: string): Promise<ListPrReviewConfigurationResponse> {
|
|
20
|
+
return await this.client.requestJson<ListPrReviewConfigurationResponse>(
|
|
21
|
+
"GET",
|
|
22
|
+
`/v1/workspaces/${workspaceId}/pr-review/registrations`,
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async getManagedGitHubSetup(workspaceId: string): Promise<PrReviewManagedGitHubSetup> {
|
|
27
|
+
return await this.client.requestJson<PrReviewManagedGitHubSetup>(
|
|
28
|
+
"GET",
|
|
29
|
+
`/v1/workspaces/${workspaceId}/pr-review/github`,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async createAppRegistration(
|
|
34
|
+
workspaceId: string,
|
|
35
|
+
request: CreatePrReviewAppRegistrationRequest,
|
|
36
|
+
): Promise<PrReviewAppRegistration> {
|
|
37
|
+
return await this.client.requestJson<PrReviewAppRegistration>(
|
|
38
|
+
"POST",
|
|
39
|
+
`/v1/workspaces/${workspaceId}/pr-review/registrations`,
|
|
40
|
+
request,
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async updateAppRegistration(
|
|
45
|
+
workspaceId: string,
|
|
46
|
+
registrationId: string,
|
|
47
|
+
request: UpdatePrReviewAppRegistrationRequest,
|
|
48
|
+
): Promise<PrReviewAppRegistration> {
|
|
49
|
+
return await this.client.requestJson<PrReviewAppRegistration>(
|
|
50
|
+
"PATCH",
|
|
51
|
+
`/v1/workspaces/${workspaceId}/pr-review/registrations/${encodeURIComponent(registrationId)}`,
|
|
52
|
+
request,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async deleteAppRegistration(workspaceId: string, registrationId: string): Promise<void> {
|
|
57
|
+
await this.client.requestVoid(
|
|
58
|
+
"DELETE",
|
|
59
|
+
`/v1/workspaces/${workspaceId}/pr-review/registrations/${encodeURIComponent(registrationId)}`,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async createRepositoryBinding(
|
|
64
|
+
workspaceId: string,
|
|
65
|
+
request: CreatePrReviewRepositoryBindingRequest,
|
|
66
|
+
): Promise<PrReviewRepositoryBinding> {
|
|
67
|
+
return await this.client.requestJson<PrReviewRepositoryBinding>(
|
|
68
|
+
"POST",
|
|
69
|
+
`/v1/workspaces/${workspaceId}/pr-review/repositories`,
|
|
70
|
+
request,
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async updateRepositoryBinding(
|
|
75
|
+
workspaceId: string,
|
|
76
|
+
bindingId: string,
|
|
77
|
+
request: UpdatePrReviewRepositoryBindingRequest,
|
|
78
|
+
): Promise<PrReviewRepositoryBinding> {
|
|
79
|
+
return await this.client.requestJson<PrReviewRepositoryBinding>(
|
|
80
|
+
"PATCH",
|
|
81
|
+
`/v1/workspaces/${workspaceId}/pr-review/repositories/${encodeURIComponent(bindingId)}`,
|
|
82
|
+
request,
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async deleteRepositoryBinding(workspaceId: string, bindingId: string): Promise<void> {
|
|
87
|
+
await this.client.requestVoid(
|
|
88
|
+
"DELETE",
|
|
89
|
+
`/v1/workspaces/${workspaceId}/pr-review/repositories/${encodeURIComponent(bindingId)}`,
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
}
|
package/src/pr-review.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Optional OpenGeni Review Bot API client; import this entry only where the capability is used. */
|
|
2
|
+
export { OpenGeniPrReviewClient } from "./pr-review-client";
|
|
3
|
+
export type { OpenGeniPrReviewTransport } from "./pr-review-client";
|
|
4
|
+
export type {
|
|
5
|
+
CreatePrReviewAppRegistrationRequest,
|
|
6
|
+
CreatePrReviewRepositoryBindingRequest,
|
|
7
|
+
PrReviewAppRegistration,
|
|
8
|
+
PrReviewCredentialKind,
|
|
9
|
+
PrReviewProvider,
|
|
10
|
+
PrReviewManagedGitHubInstallation,
|
|
11
|
+
PrReviewManagedGitHubSetup,
|
|
12
|
+
PrReviewRepositoryBinding,
|
|
13
|
+
PrReviewWebhookAuthKind,
|
|
14
|
+
ListPrReviewConfigurationResponse,
|
|
15
|
+
UpdatePrReviewAppRegistrationRequest,
|
|
16
|
+
UpdatePrReviewRepositoryBindingRequest,
|
|
17
|
+
} from "./types";
|
|
@@ -10,6 +10,8 @@ export type PreferenceRegistryProvenanceSource =
|
|
|
10
10
|
| "human"
|
|
11
11
|
| "onboarding"
|
|
12
12
|
| "knowledge_proposal"
|
|
13
|
+
| "agent"
|
|
14
|
+
| "portable_skill"
|
|
13
15
|
| "imported_document"
|
|
14
16
|
| "slack"
|
|
15
17
|
| "meeting_transcript"
|
|
@@ -101,6 +103,8 @@ export type PreferenceRegistryEvent = {
|
|
|
101
103
|
createdAt: string;
|
|
102
104
|
};
|
|
103
105
|
|
|
106
|
+
export type PreferenceRegistryActivationAuthority = "human_confirmed" | "automatic";
|
|
107
|
+
|
|
104
108
|
export type PreferenceRegistryDescriptor = {
|
|
105
109
|
id: string;
|
|
106
110
|
stableKey: string;
|
|
@@ -112,6 +116,13 @@ export type PreferenceRegistryDescriptor = {
|
|
|
112
116
|
contentHash: string;
|
|
113
117
|
precedence: PreferenceRegistryPrecedence;
|
|
114
118
|
provenance: PreferenceRegistryDescriptorProvenance;
|
|
119
|
+
/**
|
|
120
|
+
* How the active revision became active. `provenance.trust` stays the frozen
|
|
121
|
+
* creation-time fact; this is the separate activation question. Null when the
|
|
122
|
+
* revision became active outside governed learning, or when the descriptor
|
|
123
|
+
* predates this field.
|
|
124
|
+
*/
|
|
125
|
+
activationAuthority: PreferenceRegistryActivationAuthority | null;
|
|
115
126
|
expiresAt: string | null;
|
|
116
127
|
retrievalHandle: string;
|
|
117
128
|
};
|
package/src/proxy.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { OpenGeniClient } from "./client";
|
|
2
|
-
import type
|
|
2
|
+
import { sessionEventStreamCoveredThrough, type StreamSessionEventsOptions } from "./stream";
|
|
3
3
|
import type { SessionEvent } from "./types";
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -12,12 +12,22 @@ import type { SessionEvent } from "./types";
|
|
|
12
12
|
* OpenGeni's own SSE stream (`id: <sequence>`, `event: <type>`,
|
|
13
13
|
* `data: <event JSON>`), so the browser side can consume it with this same
|
|
14
14
|
* SDK's streaming core (or a plain `EventSource`), including resume via
|
|
15
|
-
* `?after=` / `Last-Event-ID`.
|
|
15
|
+
* `?after=` / `Last-Event-ID`. An ordinary event uses its own sequence as the
|
|
16
|
+
* SSE `id`; a compact event uses the server-owned sequence it covers through.
|
|
16
17
|
*/
|
|
17
18
|
|
|
18
|
-
/** Format one event
|
|
19
|
+
/** Format one event with the exact OpenGeni data and resume-cursor semantics. */
|
|
19
20
|
export function formatSseEvent(event: SessionEvent): string {
|
|
20
|
-
|
|
21
|
+
const streamedCoverage = sessionEventStreamCoveredThrough(event);
|
|
22
|
+
const projectedCoverage = event.coveredThrough;
|
|
23
|
+
const coveredThrough =
|
|
24
|
+
streamedCoverage ??
|
|
25
|
+
(typeof projectedCoverage === "number" &&
|
|
26
|
+
Number.isSafeInteger(projectedCoverage) &&
|
|
27
|
+
projectedCoverage >= event.sequence
|
|
28
|
+
? projectedCoverage
|
|
29
|
+
: event.sequence);
|
|
30
|
+
return `id: ${coveredThrough}\nevent: ${event.type}\ndata: ${JSON.stringify(event)}\n\n`;
|
|
21
31
|
}
|
|
22
32
|
|
|
23
33
|
export type SseReStreamOptions = {
|
|
@@ -115,8 +125,9 @@ export function sessionEventsToSseResponse(
|
|
|
115
125
|
|
|
116
126
|
/**
|
|
117
127
|
* Read the resume cursor a reconnecting SSE client sent: the `after` query
|
|
118
|
-
* parameter, or the standard `Last-Event-ID` header
|
|
119
|
-
*
|
|
128
|
+
* parameter, or the standard `Last-Event-ID` header. Re-emitted streams set
|
|
129
|
+
* `id:` to the event sequence for ordinary events and the covered high-water
|
|
130
|
+
* sequence for compact events. Returns 0 (full replay) when absent.
|
|
120
131
|
*/
|
|
121
132
|
export function resumeSequenceFromRequest(request: Request): number {
|
|
122
133
|
const url = new URL(request.url);
|
package/src/realtime.ts
CHANGED
|
@@ -30,6 +30,7 @@ import type { SessionRealtimeModel, WorkspaceRealtimeModelCatalogResponse } from
|
|
|
30
30
|
export type SessionRealtimeClientLike = CodexRealtimeControllerClient & {
|
|
31
31
|
getWorkspaceRealtimeModelCatalog(
|
|
32
32
|
workspaceId: string,
|
|
33
|
+
options?: { signal?: AbortSignal | undefined },
|
|
33
34
|
): Promise<WorkspaceRealtimeModelCatalogResponse>;
|
|
34
35
|
};
|
|
35
36
|
|