@opengeni/sdk 3.3.2 → 3.7.0-canary.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 (76) hide show
  1. package/README.md +80 -6
  2. package/dist/artifact-client.d.ts +4 -2
  3. package/dist/artifacts.d.ts +1 -1
  4. package/dist/artifacts.js +6 -6
  5. package/dist/browser.d.ts +5 -2
  6. package/dist/browser.js +14 -4
  7. package/dist/{chunk-YXQX7RQT.js → chunk-2E2BFEEN.js} +2 -2
  8. package/dist/{chunk-JUS2UYRP.js → chunk-3QDQTYOE.js} +3 -1
  9. package/dist/chunk-3QDQTYOE.js.map +1 -0
  10. package/dist/{chunk-C2H7HBNP.js → chunk-7S2MZ65L.js} +6 -6
  11. package/dist/chunk-FMLDFJ2Q.js +246 -0
  12. package/dist/chunk-FMLDFJ2Q.js.map +1 -0
  13. package/dist/{chunk-TRNI7KEO.js → chunk-IQTEPOI3.js} +228 -26
  14. package/dist/chunk-IQTEPOI3.js.map +1 -0
  15. package/dist/chunk-IRAEPLXG.js +350 -0
  16. package/dist/chunk-IRAEPLXG.js.map +1 -0
  17. package/dist/{chunk-QT3KFVDP.js → chunk-MPGVC7EO.js} +10 -2
  18. package/dist/chunk-MPGVC7EO.js.map +1 -0
  19. package/dist/{chunk-C4DJPZRU.js → chunk-OO5LPTO7.js} +14 -1
  20. package/dist/chunk-OO5LPTO7.js.map +1 -0
  21. package/dist/{chunk-KKRO2VCP.js → chunk-QTBAMHEF.js} +2 -2
  22. package/dist/client.d.ts +51 -11
  23. package/dist/codex-realtime-controller.js +2 -2
  24. package/dist/core.d.ts +5 -2
  25. package/dist/core.js +17 -7
  26. package/dist/document-authority.js +5 -5
  27. package/dist/editable-artifacts.js +4 -4
  28. package/dist/errors.d.ts +12 -0
  29. package/dist/github-repositories.d.ts +10 -0
  30. package/dist/github-repositories.js +36 -0
  31. package/dist/github-repositories.js.map +1 -0
  32. package/dist/index.d.ts +13 -6
  33. package/dist/index.js +99 -52
  34. package/dist/index.js.map +1 -1
  35. package/dist/interaction.js +2 -2
  36. package/dist/model-context.d.ts +49 -0
  37. package/dist/model-picker-order.d.ts +1 -0
  38. package/dist/model-picker-order.js +10 -0
  39. package/dist/model-picker-order.js.map +1 -0
  40. package/dist/proxy.d.ts +7 -5
  41. package/dist/realtime.js +2 -2
  42. package/dist/session-titles.d.ts +2 -28
  43. package/dist/site.d.ts +93 -0
  44. package/dist/site.js +35 -0
  45. package/dist/site.js.map +1 -0
  46. package/dist/stream.d.ts +2 -0
  47. package/dist/tools-FSTY4FAY.js +12 -0
  48. package/dist/tools-FSTY4FAY.js.map +1 -0
  49. package/dist/tools.d.ts +61 -0
  50. package/dist/types.d.ts +231 -9
  51. package/dist/workspace-artifacts.d.ts +26 -1
  52. package/package.json +14 -2
  53. package/src/artifact-client.ts +16 -1
  54. package/src/artifacts.ts +1 -0
  55. package/src/browser.ts +16 -0
  56. package/src/client.ts +332 -22
  57. package/src/core.ts +16 -0
  58. package/src/errors.ts +23 -0
  59. package/src/github-repositories.ts +60 -0
  60. package/src/index.ts +94 -1
  61. package/src/model-context.ts +69 -0
  62. package/src/model-picker-order.ts +6 -0
  63. package/src/proxy.ts +17 -6
  64. package/src/session-titles.ts +8 -82
  65. package/src/site.ts +544 -0
  66. package/src/stream.ts +29 -8
  67. package/src/tools.ts +396 -0
  68. package/src/types.ts +287 -10
  69. package/src/workspace-artifacts.ts +33 -2
  70. package/dist/chunk-C4DJPZRU.js.map +0 -1
  71. package/dist/chunk-JUS2UYRP.js.map +0 -1
  72. package/dist/chunk-QT3KFVDP.js.map +0 -1
  73. package/dist/chunk-TRNI7KEO.js.map +0 -1
  74. /package/dist/{chunk-YXQX7RQT.js.map → chunk-2E2BFEEN.js.map} +0 -0
  75. /package/dist/{chunk-C2H7HBNP.js.map → chunk-7S2MZ65L.js.map} +0 -0
  76. /package/dist/{chunk-KKRO2VCP.js.map → chunk-QTBAMHEF.js.map} +0 -0
@@ -1,3 +1,7 @@
1
+ import {
2
+ OpenGeniInteractionClient,
3
+ decodeComputerFrameMetadataHeader
4
+ } from "./chunk-QTBAMHEF.js";
1
5
  import {
2
6
  COMPUTER_SCREENSHOT_MAX_BYTES,
3
7
  GENERATED_VIDEO_MAX_BYTES,
@@ -5,19 +9,16 @@ import {
5
9
  OPENGENI_API_CONTRACT_REVISION,
6
10
  OPENGENI_CORRELATION_HEADER,
7
11
  RETAINED_OUTPUT_MAX_PAGE_BYTES
8
- } from "./chunk-JUS2UYRP.js";
9
- import {
10
- OpenGeniInteractionClient,
11
- decodeComputerFrameMetadataHeader
12
- } from "./chunk-KKRO2VCP.js";
12
+ } from "./chunk-3QDQTYOE.js";
13
13
  import {
14
14
  OpenGeniApiContractMismatchError,
15
15
  OpenGeniApiError,
16
+ OpenGeniSecureContextRequiredError,
16
17
  OpenGeniSessionListCursorError,
17
18
  OpenGeniStreamError,
18
19
  isAbortError,
19
20
  isRetryableStreamError
20
- } from "./chunk-C4DJPZRU.js";
21
+ } from "./chunk-OO5LPTO7.js";
21
22
 
22
23
  // src/sse.ts
23
24
  async function* parseSseStream(stream) {
@@ -89,6 +90,9 @@ async function* parseSseStream(stream) {
89
90
  }
90
91
 
91
92
  // src/stream.ts
93
+ var SESSION_EVENT_STREAM_COVERAGE = Symbol.for(
94
+ "@opengeni/sdk/session-event-stream-covered-through"
95
+ );
92
96
  async function* streamSessionEvents(transport, options = {}) {
93
97
  const signal = options.signal;
94
98
  const reconnect = options.reconnect ?? true;
@@ -127,7 +131,8 @@ async function* streamSessionEvents(transport, options = {}) {
127
131
  if (!event) {
128
132
  continue;
129
133
  }
130
- const coveredSequence = eventResumeSequence(event);
134
+ const coveredSequence = trustedSseSequence(message.id, event.sequence);
135
+ markSessionEventStreamCoverage(event, coveredSequence);
131
136
  if (coveredSequence <= cursor) continue;
132
137
  if (event.sequence > cursor + 1) {
133
138
  for await (const missed of backfillEvents(transport, cursor, event.sequence - 1)) {
@@ -265,12 +270,22 @@ function parseSessionEvent(data) {
265
270
  }
266
271
  return parsed;
267
272
  }
268
- function eventResumeSequence(event) {
269
- if (!event.payload || typeof event.payload !== "object" || Array.isArray(event.payload)) {
270
- return event.sequence;
271
- }
272
- const covered = Number(event.payload.coalescedUntil);
273
- return Math.max(event.sequence, Number.isFinite(covered) ? Math.floor(covered) : event.sequence);
273
+ function sessionEventStreamCoveredThrough(event) {
274
+ const covered = event[SESSION_EVENT_STREAM_COVERAGE];
275
+ return typeof covered === "number" && Number.isSafeInteger(covered) && covered >= event.sequence ? covered : null;
276
+ }
277
+ function trustedSseSequence(id, sequence) {
278
+ if (id === void 0 || !/^\d+$/.test(id)) return sequence;
279
+ const covered = Number(id);
280
+ return Number.isSafeInteger(covered) && covered >= sequence ? covered : sequence;
281
+ }
282
+ function markSessionEventStreamCoverage(event, covered) {
283
+ Object.defineProperty(event, SESSION_EVENT_STREAM_COVERAGE, {
284
+ value: covered,
285
+ enumerable: false,
286
+ configurable: false,
287
+ writable: false
288
+ });
274
289
  }
275
290
  async function sleep(delayMs, signal) {
276
291
  if (signal?.aborted || delayMs <= 0) {
@@ -810,6 +825,43 @@ function normalizeScheduledTaskMachineTarget(request) {
810
825
  }
811
826
  };
812
827
  }
828
+ function createLazyToolsFacade(transport) {
829
+ return {
830
+ forWorkspace(workspaceId) {
831
+ const normalizedWorkspaceId = workspaceId.trim();
832
+ if (!normalizedWorkspaceId) throw new TypeError("workspaceId is required");
833
+ let workspaceTools;
834
+ const load = () => workspaceTools ??= import("./tools-FSTY4FAY.js").then(
835
+ ({ OpenGeniToolsClient }) => new OpenGeniToolsClient(transport).forWorkspace(normalizedWorkspaceId)
836
+ );
837
+ const node = (path) => new Proxy(
838
+ async (...args) => {
839
+ let target = await load();
840
+ for (const segment of path) {
841
+ target = target[segment];
842
+ }
843
+ if (typeof target !== "function")
844
+ throw new TypeError("OpenGeni tool path is not callable");
845
+ return await Reflect.apply(target, void 0, args);
846
+ },
847
+ {
848
+ get: (_target, property) => {
849
+ if (property === "then") return void 0;
850
+ if (typeof property !== "string") return void 0;
851
+ return node([...path, property]);
852
+ }
853
+ }
854
+ );
855
+ return new Proxy(/* @__PURE__ */ Object.create(null), {
856
+ get: (_target, property) => {
857
+ if (property === "then") return void 0;
858
+ if (typeof property !== "string") return void 0;
859
+ return node([property]);
860
+ }
861
+ });
862
+ }
863
+ };
864
+ }
813
865
  var OpenGeniClient = class {
814
866
  baseUrl;
815
867
  options;
@@ -820,6 +872,8 @@ var OpenGeniClient = class {
820
872
  queued = /* @__PURE__ */ new Map();
821
873
  /** Resource-oriented Browser/Computer facade over this exact authenticated client. */
822
874
  interaction;
875
+ /** Dynamic typed tool facade backed by the canonical workspace gateway. */
876
+ tools;
823
877
  constructor(options) {
824
878
  this.baseUrl = options.baseUrl.replace(/\/+$/, "");
825
879
  this.options = options;
@@ -830,6 +884,7 @@ var OpenGeniClient = class {
830
884
  }
831
885
  this.sessionCommandTimeoutMs = sessionCommandTimeoutMs;
832
886
  this.interaction = new OpenGeniInteractionClient(this);
887
+ this.tools = createLazyToolsFacade(this);
833
888
  }
834
889
  // --- Session lifecycle ---------------------------------------------------
835
890
  /** Make one finalization attempt for a recording; callers may retry retained audio. */
@@ -1036,6 +1091,13 @@ var OpenGeniClient = class {
1036
1091
  options
1037
1092
  );
1038
1093
  }
1094
+ /** Exact model-visible prefix captured from the latest provider request. */
1095
+ async getSessionModelContext(workspaceId, sessionId) {
1096
+ return await this.requestJson(
1097
+ "GET",
1098
+ `/v1/workspaces/${workspaceId}/sessions/${sessionId}/model-context`
1099
+ );
1100
+ }
1039
1101
  async updateSession(workspaceId, sessionId, request) {
1040
1102
  return await this.requestJson(
1041
1103
  "PATCH",
@@ -3019,6 +3081,113 @@ var OpenGeniClient = class {
3019
3081
  options
3020
3082
  );
3021
3083
  }
3084
+ /** List workspace-owned unpinned Vercel AI Gateway model slugs. */
3085
+ async listWorkspaceGatewayCustomModels(workspaceId) {
3086
+ return await this.requestJson(
3087
+ "GET",
3088
+ `/v1/workspaces/${workspaceId}/gateway-custom-models`
3089
+ );
3090
+ }
3091
+ /** Add one exact upstream Vercel AI Gateway slug. */
3092
+ async createWorkspaceGatewayCustomModel(workspaceId, request) {
3093
+ return await this.requestJson(
3094
+ "POST",
3095
+ `/v1/workspaces/${workspaceId}/gateway-custom-models`,
3096
+ request
3097
+ );
3098
+ }
3099
+ /** Remove one workspace custom Gateway model by its stable row id. */
3100
+ async deleteWorkspaceGatewayCustomModel(workspaceId, customModelId, request) {
3101
+ if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu.test(
3102
+ customModelId
3103
+ )) {
3104
+ throw new TypeError("customModelId must be a UUID");
3105
+ }
3106
+ await this.requestVoid(
3107
+ "DELETE",
3108
+ `/v1/workspaces/${workspaceId}/gateway-custom-models/${encodeURIComponent(customModelId)}`,
3109
+ request
3110
+ );
3111
+ }
3112
+ /** List workspace-owned unpinned OpenRouter model slugs. */
3113
+ async listWorkspaceOpenRouterCustomModels(workspaceId) {
3114
+ return await this.requestJson(
3115
+ "GET",
3116
+ `/v1/workspaces/${workspaceId}/openrouter-custom-models`
3117
+ );
3118
+ }
3119
+ /** Add one exact upstream OpenRouter slug. */
3120
+ async createWorkspaceOpenRouterCustomModel(workspaceId, request) {
3121
+ return await this.requestJson(
3122
+ "POST",
3123
+ `/v1/workspaces/${workspaceId}/openrouter-custom-models`,
3124
+ request
3125
+ );
3126
+ }
3127
+ /** Remove one workspace custom OpenRouter model by its stable row id. */
3128
+ async deleteWorkspaceOpenRouterCustomModel(workspaceId, customModelId, request) {
3129
+ if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu.test(
3130
+ customModelId
3131
+ )) {
3132
+ throw new TypeError("customModelId must be a UUID");
3133
+ }
3134
+ await this.requestVoid(
3135
+ "DELETE",
3136
+ `/v1/workspaces/${workspaceId}/openrouter-custom-models/${encodeURIComponent(customModelId)}`,
3137
+ request
3138
+ );
3139
+ }
3140
+ /** Read metadata for one organization-owned model-provider connection. */
3141
+ async getOrganizationModelProviderConnection(organizationId, providerKind) {
3142
+ return await this.requestJson(
3143
+ "GET",
3144
+ `/v1/organizations/${organizationId}/model-providers/${providerKind}`
3145
+ );
3146
+ }
3147
+ /** Connect or rotate one organization-owned provider credential. */
3148
+ async upsertOrganizationModelProviderConnection(organizationId, providerKind, request) {
3149
+ return await this.requestJson(
3150
+ "PUT",
3151
+ `/v1/organizations/${organizationId}/model-providers/${providerKind}`,
3152
+ request
3153
+ );
3154
+ }
3155
+ /** Revoke one organization-owned provider credential. */
3156
+ async revokeOrganizationModelProviderConnection(organizationId, providerKind, request) {
3157
+ return await this.requestJson(
3158
+ "DELETE",
3159
+ `/v1/organizations/${organizationId}/model-providers/${providerKind}`,
3160
+ request
3161
+ );
3162
+ }
3163
+ /** List organization-owned exact upstream model slugs. */
3164
+ async listOrganizationProviderCustomModels(organizationId, providerKind) {
3165
+ return await this.requestJson(
3166
+ "GET",
3167
+ `/v1/organizations/${organizationId}/model-providers/${providerKind}/custom-models`
3168
+ );
3169
+ }
3170
+ /** Add one organization-owned exact upstream model slug. */
3171
+ async createOrganizationProviderCustomModel(organizationId, providerKind, request) {
3172
+ return await this.requestJson(
3173
+ "POST",
3174
+ `/v1/organizations/${organizationId}/model-providers/${providerKind}/custom-models`,
3175
+ request
3176
+ );
3177
+ }
3178
+ /** Retire one organization-owned custom model. */
3179
+ async deleteOrganizationProviderCustomModel(organizationId, providerKind, customModelId, request) {
3180
+ if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu.test(
3181
+ customModelId
3182
+ )) {
3183
+ throw new TypeError("customModelId must be a UUID");
3184
+ }
3185
+ return await this.requestJson(
3186
+ "DELETE",
3187
+ `/v1/organizations/${organizationId}/model-providers/${providerKind}/custom-models/${encodeURIComponent(customModelId)}`,
3188
+ request
3189
+ );
3190
+ }
3022
3191
  /** Read the workspace's hard provider/model allowlist. */
3023
3192
  async getWorkspaceModelAccessPolicy(workspaceId) {
3024
3193
  return await this.requestJson(
@@ -3087,6 +3256,14 @@ var OpenGeniClient = class {
3087
3256
  async createOrganization(request) {
3088
3257
  return await this.requestJson("POST", "/v1/organizations", request);
3089
3258
  }
3259
+ /** Create another organization owned by the current managed human. */
3260
+ async createAdditionalOrganization(request) {
3261
+ return await this.requestJson(
3262
+ "POST",
3263
+ "/v1/organizations/additional",
3264
+ request
3265
+ );
3266
+ }
3090
3267
  /** Pending and historical invitations addressed to the current managed human. */
3091
3268
  async listOrganizationInvitations(options = {}) {
3092
3269
  const query = new URLSearchParams();
@@ -3147,7 +3324,7 @@ var OpenGeniClient = class {
3147
3324
  `/v1/organizations/${organizationId}/overview`
3148
3325
  );
3149
3326
  }
3150
- /** Create a shared workspace without implicitly granting the actor access. */
3327
+ /** Create a shared workspace and grant its creator explicit workspace-admin access. */
3151
3328
  async createOrganizationWorkspace(organizationId, request) {
3152
3329
  return await this.requestJson(
3153
3330
  "POST",
@@ -3170,6 +3347,13 @@ var OpenGeniClient = class {
3170
3347
  request
3171
3348
  );
3172
3349
  }
3350
+ /** Delete a shared workspace through organization-administrator authority. */
3351
+ async deleteOrganizationWorkspace(organizationId, workspaceId) {
3352
+ await this.requestVoid(
3353
+ "DELETE",
3354
+ `/v1/organizations/${organizationId}/workspaces/${workspaceId}`
3355
+ );
3356
+ }
3173
3357
  async putOrganizationWorkspaceMember(organizationId, workspaceId, membershipId, request) {
3174
3358
  return await this.requestJson(
3175
3359
  "PUT",
@@ -3390,11 +3574,12 @@ var OpenGeniClient = class {
3390
3574
  `/v1/workspaces/${workspaceId}/instruction-policies/${encodeURIComponent(revisionId)}`
3391
3575
  );
3392
3576
  }
3393
- async createWorkspaceInstructionPolicyDraft(workspaceId, request) {
3394
- return await this.requestJson(
3577
+ async createWorkspaceInstructionPolicyDraft(workspaceId, request, options = {}) {
3578
+ return await this.requestSessionCommand(
3395
3579
  "POST",
3396
3580
  `/v1/workspaces/${workspaceId}/instruction-policies/drafts`,
3397
- request
3581
+ request,
3582
+ options
3398
3583
  );
3399
3584
  }
3400
3585
  /** List the newest immutable onboarding proposals and their inactive policy drafts. */
@@ -3433,11 +3618,12 @@ var OpenGeniClient = class {
3433
3618
  `/v1/workspaces/${workspaceId}/instruction-policies/diff?${params}`
3434
3619
  );
3435
3620
  }
3436
- async activateWorkspaceInstructionPolicyRevision(workspaceId, revisionId, request) {
3437
- return await this.requestJson(
3621
+ async activateWorkspaceInstructionPolicyRevision(workspaceId, revisionId, request, options = {}) {
3622
+ return await this.requestSessionCommand(
3438
3623
  "POST",
3439
3624
  `/v1/workspaces/${workspaceId}/instruction-policies/${encodeURIComponent(revisionId)}/activate`,
3440
- request
3625
+ request,
3626
+ options
3441
3627
  );
3442
3628
  }
3443
3629
  async rollbackWorkspaceInstructionPolicyRevision(workspaceId, request) {
@@ -3992,6 +4178,7 @@ var OpenGeniClient = class {
3992
4178
  if (input.timeoutMs !== void 0 && (!Number.isFinite(input.timeoutMs) || input.timeoutMs <= 0)) {
3993
4179
  throw new Error("File upload timeout must be a positive number");
3994
4180
  }
4181
+ assertBrowserFileUploadSecureContext();
3995
4182
  const withTimeout = async (timeoutMs, operation) => {
3996
4183
  const controller = new AbortController();
3997
4184
  let timeout;
@@ -5308,14 +5495,18 @@ var OpenGeniClient = class {
5308
5495
  throw error;
5309
5496
  }
5310
5497
  assertApiContractResponse(response);
5311
- if (!response.ok) {
5312
- throw await apiErrorFromResponse(response, { method, correlationId });
5313
- }
5314
- await assertJsonResponse(response, { method, correlationId });
5315
5498
  try {
5316
- return await response.json();
5499
+ if (!response.ok) {
5500
+ throw await awaitWithAbort(
5501
+ apiErrorFromResponse(response, { method, correlationId }),
5502
+ abort.signal
5503
+ );
5504
+ }
5505
+ await awaitWithAbort(assertJsonResponse(response, { method, correlationId }), abort.signal);
5506
+ return await awaitWithAbort(response.json(), abort.signal);
5317
5507
  } catch (error) {
5318
5508
  if (options.signal?.aborted) throw error;
5509
+ if (error instanceof OpenGeniApiError) throw error;
5319
5510
  if (isMutationMethod(method)) {
5320
5511
  throw mutationTransportError(correlationId);
5321
5512
  }
@@ -5538,6 +5729,16 @@ function mutationTransportError(correlationId) {
5538
5729
  displayMessage: "OpenGeni could not confirm the request \u2014 reconcile before retrying."
5539
5730
  });
5540
5731
  }
5732
+ function assertBrowserFileUploadSecureContext() {
5733
+ const secureContext = typeof window !== "undefined" ? window.isSecureContext : typeof globalThis.isSecureContext === "boolean" ? globalThis.isSecureContext : void 0;
5734
+ if (secureContext === void 0) return;
5735
+ if (!secureContext) {
5736
+ throw new OpenGeniSecureContextRequiredError("insecure_context");
5737
+ }
5738
+ if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.digest !== "function") {
5739
+ throw new OpenGeniSecureContextRequiredError("web_crypto_unavailable");
5740
+ }
5741
+ }
5541
5742
  async function sha256ForUpload(body) {
5542
5743
  const bytes = typeof body === "string" ? new TextEncoder().encode(body) : body instanceof Blob ? new Uint8Array(await body.arrayBuffer()) : new Uint8Array(body);
5543
5744
  const digest = await globalThis.crypto.subtle.digest("SHA-256", bytes);
@@ -5635,6 +5836,7 @@ async function readBoundedResponseBytes(response, maxBytes, expectedBytes) {
5635
5836
  export {
5636
5837
  parseSseStream,
5637
5838
  streamSessionEvents,
5839
+ sessionEventStreamCoveredThrough,
5638
5840
  streamWorkspaceControlEvents,
5639
5841
  streamWorkspaceInteractionRevisions,
5640
5842
  streamWorkspaceLiveEvents,
@@ -5649,4 +5851,4 @@ export {
5649
5851
  parseMediaGenerationResult,
5650
5852
  OpenGeniClient
5651
5853
  };
5652
- //# sourceMappingURL=chunk-TRNI7KEO.js.map
5854
+ //# sourceMappingURL=chunk-IQTEPOI3.js.map