@k9o/core 1.2.0 → 1.3.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/dist/index.js CHANGED
@@ -2,15 +2,17 @@ import "./chunk-YEYRP6PG.js";
2
2
  import {
3
3
  request,
4
4
  requestStream
5
- } from "./chunk-O2ZTV6YN.js";
5
+ } from "./chunk-KC4EDMBF.js";
6
6
  import {
7
+ DEFAULT_BASE_URL,
7
8
  orgPath,
9
+ parseApiHost,
8
10
  platformPath,
9
11
  projectPath,
10
12
  resolveBaseUrl,
11
13
  validateBaseUrl,
12
14
  validateSlug
13
- } from "./chunk-2NDFTHUB.js";
15
+ } from "./chunk-UL53GNYM.js";
14
16
  import {
15
17
  KError,
16
18
  kerrorFromWire
@@ -278,7 +280,7 @@ function makeProjectsNamespace(config) {
278
280
  * Create a new project under the caller's active org.
279
281
  */
280
282
  async create(input) {
281
- validateSlug(input.slug, "project");
283
+ if (input.slug !== void 0) validateSlug(input.slug, "project");
282
284
  return request(config, {
283
285
  method: "POST",
284
286
  path: orgPath("projects"),
@@ -292,7 +294,7 @@ function makeProjectsNamespace(config) {
292
294
  validateSlug(slug, "project");
293
295
  return request(config, {
294
296
  method: "GET",
295
- path: projectPath(slug, "project")
297
+ path: orgPath(`projects/${slug}`)
296
298
  });
297
299
  },
298
300
  /**
@@ -302,7 +304,7 @@ function makeProjectsNamespace(config) {
302
304
  validateSlug(slug, "project");
303
305
  return request(config, {
304
306
  method: "PATCH",
305
- path: projectPath(slug, "project"),
307
+ path: orgPath(`projects/${slug}`),
306
308
  body: patch
307
309
  });
308
310
  }
@@ -385,7 +387,7 @@ function makeBucketHandle(config, bucket) {
385
387
  return request(config, { method: "POST", path: bucketPath(config, bucket, "/objects"), body: form });
386
388
  },
387
389
  /**
388
- * A pre-authenticated GET URL for one object. `POST …/objects/sign`. `expiresIn` is required.
390
+ * A pre-authenticated GET URL for one object. `POST …/objects/sign`. `expiresIn` is required; the URL lives at most 900 seconds.
389
391
  * (A signed PUT is not offered: the gateway has no route for it yet.)
390
392
  */
391
393
  async createSignedUrl(path, options) {
@@ -543,79 +545,8 @@ function makeStorageNamespace(config) {
543
545
  };
544
546
  }
545
547
 
546
- // src/metadata.ts
547
- var METADATA_OPERATORS = [
548
- "eq",
549
- "neq",
550
- "gt",
551
- "gte",
552
- "lt",
553
- "lte",
554
- "contains",
555
- "startsWith",
556
- "endsWith",
557
- "in",
558
- "notIn",
559
- "and",
560
- "or",
561
- "not"
562
- ];
563
- function requireProjectSlug3(config) {
564
- if (config.projectSlug === void 0 || config.projectSlug.length === 0) {
565
- throw new KError({
566
- code: "K9O_MISSING_PROJECT_CONTEXT",
567
- message: "client.metadata requires a bound projectSlug (project data-plane resource,)",
568
- context: {},
569
- recommendation: "Pass projectSlug when constructing the client."
570
- });
571
- }
572
- return config.projectSlug;
573
- }
574
- function makeBuilder(config, surfaces, where, limit, cursorValue) {
575
- return {
576
- where(field, op, value) {
577
- return makeBuilder(config, surfaces, [...where, { field, op, value }], limit, cursorValue);
578
- },
579
- limit(n) {
580
- return makeBuilder(config, surfaces, where, n, cursorValue);
581
- },
582
- cursor(c) {
583
- return makeBuilder(config, surfaces, where, limit, c);
584
- },
585
- async execute() {
586
- return request(config, {
587
- method: "POST",
588
- path: projectPath(requireProjectSlug3(config), "metadata/query"),
589
- body: {
590
- surfaces,
591
- where,
592
- ...limit !== void 0 ? { limit } : {},
593
- cursor: cursorValue
594
- }
595
- });
596
- }
597
- };
598
- }
599
- function makeMetadataNamespace(config) {
600
- return {
601
- /** Start a cross-surface metadata query against one or more surfaces. */
602
- from(surface) {
603
- const surfaces = Array.isArray(surface) ? surface : [surface];
604
- if (surfaces.length === 0) {
605
- throw new KError({
606
- code: "K9O_UNKNOWN_SURFACE",
607
- message: "client.metadata.from(...) requires at least one surface label.",
608
- context: {},
609
- recommendation: "Pass a surface like 'collection:posts', 'storage:images', or 'telemetry:auth.session.created'."
610
- });
611
- }
612
- return makeBuilder(config, surfaces, [], void 0, null);
613
- }
614
- };
615
- }
616
-
617
548
  // src/migrations.ts
618
- function requireProjectSlug4(config) {
549
+ function requireProjectSlug3(config) {
619
550
  if (typeof config.projectSlug !== "string" || config.projectSlug.length === 0) {
620
551
  throw new Error("migrations operations require projectSlug bound on the client");
621
552
  }
@@ -625,7 +556,7 @@ function makeMigrationsNamespace(config) {
625
556
  return {
626
557
  /** Apply migrations immediately (PROJECT_ADMIN minimum). */
627
558
  async apply(input) {
628
- const slug = requireProjectSlug4(config);
559
+ const slug = requireProjectSlug3(config);
629
560
  return request(config, {
630
561
  method: "POST",
631
562
  path: projectPath(slug, "migrations/apply"),
@@ -634,7 +565,7 @@ function makeMigrationsNamespace(config) {
634
565
  },
635
566
  /** List applied migrations on the project. */
636
567
  async list() {
637
- const slug = requireProjectSlug4(config);
568
+ const slug = requireProjectSlug3(config);
638
569
  return request(config, {
639
570
  method: "GET",
640
571
  path: projectPath(slug, "migrations")
@@ -642,7 +573,7 @@ function makeMigrationsNamespace(config) {
642
573
  },
643
574
  /** Get a single applied migration by version. */
644
575
  async get(version) {
645
- const slug = requireProjectSlug4(config);
576
+ const slug = requireProjectSlug3(config);
646
577
  return request(config, {
647
578
  method: "GET",
648
579
  path: projectPath(slug, `migrations/${encodeURIComponent(String(version))}`)
@@ -650,19 +581,20 @@ function makeMigrationsNamespace(config) {
650
581
  },
651
582
  /** Queue migrations for maker-checker approval. */
652
583
  async queue(input) {
653
- const slug = requireProjectSlug4(config);
584
+ const slug = requireProjectSlug3(config);
654
585
  return request(config, {
655
586
  method: "POST",
656
587
  path: projectPath(slug, "migrations/queue"),
657
588
  body: input
658
589
  });
659
590
  },
660
- /** List pending (queued, not yet approved) migrations. */
661
- async listPending() {
662
- const slug = requireProjectSlug4(config);
591
+ /** List pending migrations: `queued` ones by default, or those with the given `status`. */
592
+ async listPending(opts) {
593
+ const slug = requireProjectSlug3(config);
663
594
  return request(config, {
664
595
  method: "GET",
665
- path: projectPath(slug, "migrations/pending")
596
+ path: projectPath(slug, "migrations/pending"),
597
+ query: opts
666
598
  });
667
599
  },
668
600
  /**
@@ -672,7 +604,7 @@ function makeMigrationsNamespace(config) {
672
604
  * needs its own approval flow, not this call).
673
605
  */
674
606
  async applyPending(pendingId) {
675
- const slug = requireProjectSlug4(config);
607
+ const slug = requireProjectSlug3(config);
676
608
  return request(config, {
677
609
  method: "POST",
678
610
  path: projectPath(slug, `migrations/pending/${encodeURIComponent(pendingId)}/apply`)
@@ -680,7 +612,7 @@ function makeMigrationsNamespace(config) {
680
612
  },
681
613
  /** Reject a pending migration (transitions to rejected; does not apply). */
682
614
  async rejectPending(pendingId, input) {
683
- const slug = requireProjectSlug4(config);
615
+ const slug = requireProjectSlug3(config);
684
616
  return request(config, {
685
617
  method: "POST",
686
618
  path: projectPath(slug, `migrations/pending/${encodeURIComponent(pendingId)}/reject`),
@@ -689,7 +621,7 @@ function makeMigrationsNamespace(config) {
689
621
  },
690
622
  /** Delete a pending migration from the queue. */
691
623
  async deletePending(pendingId) {
692
- const slug = requireProjectSlug4(config);
624
+ const slug = requireProjectSlug3(config);
693
625
  return request(config, {
694
626
  method: "DELETE",
695
627
  path: projectPath(slug, `migrations/pending/${encodeURIComponent(pendingId)}`)
@@ -699,7 +631,7 @@ function makeMigrationsNamespace(config) {
699
631
  }
700
632
 
701
633
  // src/functions.ts
702
- function requireProjectSlug5(config) {
634
+ function requireProjectSlug4(config) {
703
635
  if (typeof config.projectSlug !== "string" || config.projectSlug.length === 0) {
704
636
  throw new Error("functions operations require projectSlug bound on the client");
705
637
  }
@@ -707,9 +639,23 @@ function requireProjectSlug5(config) {
707
639
  }
708
640
  function makeFunctionsNamespace(config) {
709
641
  return {
710
- /** Deploy or redeploy a function. Returns the function record with status. */
642
+ /**
643
+ * Upload a function artifact and get back its content-addressed `artifactKey`, to pass to `deploy`.
644
+ * `POST /@<projectSlug>/functions/artifacts` with the raw bytes: a WebAssembly module for the gateway tier (up to
645
+ * 16 MiB) or an OCI image archive for the sandbox tier (up to 256 MiB). Uploading the same bytes again returns the same key.
646
+ */
647
+ async uploadArtifact(bytes, kind) {
648
+ const slug = requireProjectSlug4(config);
649
+ return request(config, {
650
+ method: "POST",
651
+ path: projectPath(slug, "functions/artifacts"),
652
+ rawBody: bytes,
653
+ headers: { "content-type": kind === "wasm" ? "application/wasm" : "application/x-tar" }
654
+ });
655
+ },
656
+ /** Deploy or redeploy a function from an uploaded artifact. Returns the function record with status. */
711
657
  async deploy(input) {
712
- const slug = requireProjectSlug5(config);
658
+ const slug = requireProjectSlug4(config);
713
659
  return request(config, {
714
660
  method: "POST",
715
661
  path: projectPath(slug, "functions"),
@@ -718,7 +664,7 @@ function makeFunctionsNamespace(config) {
718
664
  },
719
665
  /** List deployed functions (cursor pagination). */
720
666
  async list(opts) {
721
- const slug = requireProjectSlug5(config);
667
+ const slug = requireProjectSlug4(config);
722
668
  return request(config, {
723
669
  method: "GET",
724
670
  path: projectPath(slug, "functions"),
@@ -727,43 +673,40 @@ function makeFunctionsNamespace(config) {
727
673
  },
728
674
  /** Get a function by name. */
729
675
  async get(name) {
730
- const slug = requireProjectSlug5(config);
676
+ const slug = requireProjectSlug4(config);
731
677
  return request(config, {
732
678
  method: "GET",
733
679
  path: projectPath(slug, `functions/${encodeURIComponent(name)}`)
734
680
  });
735
681
  },
736
- /** Retire a function. Returns confirmation; the function name enters a 24h cooldown. */
682
+ /** Retire a function. Returns the retired record; the function name enters a 24h cooldown. */
737
683
  async delete(name) {
738
- const slug = requireProjectSlug5(config);
684
+ const slug = requireProjectSlug4(config);
739
685
  return request(config, {
740
686
  method: "DELETE",
741
687
  path: projectPath(slug, `functions/${encodeURIComponent(name)}`)
742
688
  });
743
689
  },
744
690
  /**
745
- * Invoke a function. The `payload` is passed to the function runtime
746
- * verbatim; the gateway returns whatever the function returns wrapped
747
- * in the standard envelope.
748
- *
749
- * Per: invoke authority is per-function (declared in the
750
- * function manifest). Per: streaming responses use the
751
- * subscription/async-iterator pattern; this method covers the
691
+ * Invoke a function. The `payload` is sent as the `payload` field of
692
+ * the request body and passed to the function runtime verbatim; the
693
+ * gateway returns whatever the function returns wrapped in the standard
694
+ * envelope. Invoke authority is per function. This method covers the
752
695
  * request-response variant only.
753
696
  */
754
- async invoke(name, payload) {
755
- const slug = requireProjectSlug5(config);
697
+ async invoke(name, payload, options) {
698
+ const slug = requireProjectSlug4(config);
756
699
  return request(config, {
757
700
  method: "POST",
758
701
  path: projectPath(slug, `functions/${encodeURIComponent(name)}/invoke`),
759
- body: payload
702
+ body: { ...payload !== void 0 ? { payload } : {}, ...options ?? {} }
760
703
  });
761
704
  }
762
705
  };
763
706
  }
764
707
 
765
708
  // src/policies.ts
766
- function requireProjectSlug6(config) {
709
+ function requireProjectSlug5(config) {
767
710
  if (typeof config.projectSlug !== "string" || config.projectSlug.length === 0) {
768
711
  throw new Error("policies operations require projectSlug bound on the client");
769
712
  }
@@ -773,15 +716,15 @@ function makePoliciesNamespace(config) {
773
716
  return {
774
717
  /** Return the currently-active policy for the project. */
775
718
  async current() {
776
- const slug = requireProjectSlug6(config);
719
+ const slug = requireProjectSlug5(config);
777
720
  return request(config, {
778
721
  method: "GET",
779
722
  path: projectPath(slug, "policy")
780
723
  });
781
724
  },
782
- /** List all policy bundles (draft + published + deactivated). */
725
+ /** List all policy bundles (draft + published + superseded). */
783
726
  async list(opts) {
784
- const slug = requireProjectSlug6(config);
727
+ const slug = requireProjectSlug5(config);
785
728
  return request(config, {
786
729
  method: "GET",
787
730
  path: projectPath(slug, "policies"),
@@ -790,16 +733,16 @@ function makePoliciesNamespace(config) {
790
733
  },
791
734
  /** Create a draft policy bundle. */
792
735
  async create(input) {
793
- const slug = requireProjectSlug6(config);
736
+ const slug = requireProjectSlug5(config);
794
737
  return request(config, {
795
738
  method: "POST",
796
739
  path: projectPath(slug, "policies"),
797
740
  body: input
798
741
  });
799
742
  },
800
- /** Lint a candidate rule set without persisting. */
743
+ /** Lint a candidate policy document without persisting. */
801
744
  async validate(input) {
802
- const slug = requireProjectSlug6(config);
745
+ const slug = requireProjectSlug5(config);
803
746
  return request(config, {
804
747
  method: "POST",
805
748
  path: projectPath(slug, "policies/validate"),
@@ -808,42 +751,47 @@ function makePoliciesNamespace(config) {
808
751
  },
809
752
  /** Get a single bundle by id. */
810
753
  async get(bundleId) {
811
- const slug = requireProjectSlug6(config);
754
+ const slug = requireProjectSlug5(config);
812
755
  return request(config, {
813
756
  method: "GET",
814
757
  path: projectPath(slug, `policies/${encodeURIComponent(bundleId)}`)
815
758
  });
816
759
  },
817
- /** Patch a draft bundle. Cannot patch published bundles (publish→republish flow). */
760
+ /** Replace a draft bundle's policy document. Cannot patch published bundles (publish→republish flow). */
818
761
  async update(bundleId, patch) {
819
- const slug = requireProjectSlug6(config);
762
+ const slug = requireProjectSlug5(config);
820
763
  return request(config, {
821
764
  method: "PATCH",
822
765
  path: projectPath(slug, `policies/${encodeURIComponent(bundleId)}`),
823
766
  body: patch
824
767
  });
825
768
  },
826
- /** Delete a draft bundle. Cannot delete published bundles. */
769
+ /** Delete a draft bundle. Cannot delete published bundles. The gateway answers 204 with no body. */
827
770
  async delete(bundleId) {
828
- const slug = requireProjectSlug6(config);
771
+ const slug = requireProjectSlug5(config);
829
772
  return request(config, {
830
773
  method: "DELETE",
831
774
  path: projectPath(slug, `policies/${encodeURIComponent(bundleId)}`)
832
775
  });
833
776
  },
834
- /** Publish a draft bundle — transitions to `published` + becomes active for the project. */
835
- async publish(bundleId) {
836
- const slug = requireProjectSlug6(config);
777
+ /**
778
+ * Publish a draft bundle. The gateway answers 202 with `{ pendingChangeId, bundleId }`: the publish waits for
779
+ * approval, then the bundle becomes active. Pass `acknowledgeSelfLockout: true` to proceed when the bundle
780
+ * would remove your own read access to a collection.
781
+ */
782
+ async publish(bundleId, options) {
783
+ const slug = requireProjectSlug5(config);
837
784
  return request(config, {
838
785
  method: "POST",
839
- path: projectPath(slug, `policies/${encodeURIComponent(bundleId)}/publish`)
786
+ path: projectPath(slug, `policies/${encodeURIComponent(bundleId)}/publish`),
787
+ ...options !== void 0 ? { body: options } : {}
840
788
  });
841
789
  }
842
790
  };
843
791
  }
844
792
 
845
793
  // src/audit.ts
846
- function requireProjectSlug7(config) {
794
+ function requireProjectSlug6(config) {
847
795
  if (typeof config.projectSlug !== "string" || config.projectSlug.length === 0) {
848
796
  throw new Error("audit operations require projectSlug bound on the client");
849
797
  }
@@ -855,12 +803,11 @@ function makeAuditNamespace(config) {
855
803
  * Query the audit log. Returns reverse-chronological events matching
856
804
  * all supplied filters (AND composition).
857
805
  *
858
- * Per RBAC: requires `AUDIT_READER` role minimum; Custodian-
859
- * class roles inherit. Project-level audit is project-scoped (this
860
- * endpoint); platform-level audit is admin-only (separate surface).
806
+ * Requires the `AUDIT_READER` role at minimum. This endpoint is
807
+ * project-scoped.
861
808
  */
862
809
  async query(opts) {
863
- const slug = requireProjectSlug7(config);
810
+ const slug = requireProjectSlug6(config);
864
811
  return request(config, {
865
812
  method: "GET",
866
813
  path: projectPath(slug, "audit-log"),
@@ -869,17 +816,16 @@ function makeAuditNamespace(config) {
869
816
  },
870
817
  /**
871
818
  * Convenience: live-tail recent events. Currently single-shot read
872
- * with `since` defaulted to "1 minute ago"; subscription-mode tail
873
- * (SSE) lands when the streaming layer ships pattern.
819
+ * with `after` defaulted to "1 minute ago".
874
820
  */
875
821
  async tail(opts) {
876
- const slug = requireProjectSlug7(config);
822
+ const slug = requireProjectSlug6(config);
877
823
  const minutes = opts?.sinceMinutes ?? 1;
878
824
  const since = new Date(Date.now() - minutes * 6e4).toISOString();
879
825
  return request(config, {
880
826
  method: "GET",
881
827
  path: projectPath(slug, "audit-log"),
882
- query: { since, limit: opts?.limit ?? 100 }
828
+ query: { after: since, limit: opts?.limit ?? 100 }
883
829
  });
884
830
  }
885
831
  };
@@ -923,19 +869,18 @@ function makeOrgsNamespace(config) {
923
869
  // src/org.ts
924
870
  function makeMembersNamespace(config) {
925
871
  return {
926
- /** GET /members (org-plane LIST). */
872
+ /** GET /members (org-plane LIST). The route is not paged; it filters by userId, role, acceptanceStatus, status and state. */
927
873
  async list(opts) {
928
874
  return request(config, { method: "GET", path: orgPath("members"), query: opts });
929
875
  },
930
- /** POST /members — invite a new org member by email. */
876
+ /**
877
+ * POST /members — add a member by email. An existing user becomes a member at once (201, the member row);
878
+ * an unknown email gets an invitation (202, `{ invitation, delivery }`).
879
+ */
931
880
  async invite(input) {
932
881
  return request(config, { method: "POST", path: orgPath("members"), body: input });
933
882
  },
934
- /** GET /members/<userId> — single-read (existing endpoint). */
935
- async get(userId) {
936
- return request(config, { method: "GET", path: orgPath(`members/${encodeURIComponent(userId)}`) });
937
- },
938
- /** DELETE /members/<userId> — remove a member from the org. */
883
+ /** DELETE /members/<userId> — remove a member from the org. The gateway answers 204 with no body. */
939
884
  async remove(userId) {
940
885
  return request(config, { method: "DELETE", path: orgPath(`members/${encodeURIComponent(userId)}`) });
941
886
  }
@@ -947,84 +892,63 @@ function makeGroupsNamespace(config) {
947
892
  async list(opts) {
948
893
  return request(config, { method: "GET", path: orgPath("groups"), query: opts });
949
894
  },
950
- /** POST /groups — create a new group. */
951
- async create(input) {
952
- return request(config, { method: "POST", path: orgPath("groups"), body: input });
953
- },
954
- /** GET /groups/<groupId> — single-read (pre-cement existing endpoint). */
895
+ /** GET /groups/<groupId> — single-read. */
955
896
  async get(groupId) {
956
897
  return request(config, { method: "GET", path: orgPath(`groups/${encodeURIComponent(groupId)}`) });
957
- },
958
- /** DELETE /groups/<groupId> — remove a group. */
959
- async delete(groupId) {
960
- return request(config, { method: "DELETE", path: orgPath(`groups/${encodeURIComponent(groupId)}`) });
961
898
  }
962
899
  };
963
900
  }
964
901
  function makeOrgAuditLogNamespace(config) {
965
902
  return {
966
903
  /**
967
- * GET /audit-log (org-plane).
968
- * Distinct from project-plane `client.audit.query()` which routes to
969
- * `@<projectSlug>/audit-log`. Org-plane events cover the 6-event family
970
- * (member_invited/removed/role_granted/revoked/
971
- * idp_config_changed/settings_updated).
904
+ * GET /audit-log (org-plane), newest first. The route reads `type` and `limit` (1 to 500, default 100) only.
905
+ * Distinct from project-plane `client.audit.query()` which routes to `@<projectSlug>/audit-log`.
972
906
  */
973
907
  async query(opts) {
974
908
  return request(config, { method: "GET", path: orgPath("audit-log"), query: opts });
975
- },
976
- /** Convenience: recent events (defaults to 5 minute window). */
977
- async tail(opts) {
978
- const minutes = opts?.sinceMinutes ?? 5;
979
- const since = new Date(Date.now() - minutes * 6e4).toISOString();
980
- return request(config, {
981
- method: "GET",
982
- path: orgPath("audit-log"),
983
- query: { since, limit: opts?.limit ?? 100 }
984
- });
985
909
  }
986
910
  };
987
911
  }
988
912
  function makeOrgGateNamespace(config) {
989
913
  return {
990
914
  roles: {
991
- /** GET /org-role-grants — list active grants ask 4. */
992
- async list(opts) {
993
- return request(config, { method: "GET", path: orgPath("org-role-grants"), query: opts });
915
+ /** GET /role-grants — list role grants. */
916
+ async list() {
917
+ return request(config, { method: "GET", path: orgPath("role-grants") });
994
918
  },
995
- /** POST /org-role-grants — grant an ORG_ADMIN or ORG_BILLING_ADMIN role. */
919
+ /** POST /role-grants — grant an org role. */
996
920
  async grant(input) {
997
- return request(config, { method: "POST", path: orgPath("org-role-grants"), body: input });
921
+ return request(config, { method: "POST", path: orgPath("role-grants"), body: input });
998
922
  },
999
- /** GET /org-role-grants/<grantId> — single-read. */
923
+ /** GET /role-grants/<grantId> — single-read. */
1000
924
  async get(grantId) {
1001
- return request(config, { method: "GET", path: orgPath(`org-role-grants/${encodeURIComponent(grantId)}`) });
925
+ return request(config, { method: "GET", path: orgPath(`role-grants/${encodeURIComponent(grantId)}`) });
1002
926
  },
1003
- /** DELETE /org-role-grants/<grantId> — revoke a grant (soft delete; sets revokedAt). */
1004
- async revoke(grantId) {
1005
- return request(config, { method: "DELETE", path: orgPath(`org-role-grants/${encodeURIComponent(grantId)}`) });
927
+ /** DELETE /role-grants/<grantId> — revoke a grant (soft delete; sets revokedAt). */
928
+ async revoke(grantId, opts) {
929
+ return request(config, { method: "DELETE", path: orgPath(`role-grants/${encodeURIComponent(grantId)}`), ...opts ? { body: opts } : {} });
1006
930
  }
1007
931
  },
1008
932
  idpProviders: {
1009
- /** GET /idp-providers — list configured org operator IdP providers ask 7. */
933
+ /** GET /identity-providers — list configured identity providers. */
1010
934
  async list() {
1011
- return request(config, { method: "GET", path: orgPath("idp-providers") });
935
+ return request(config, { method: "GET", path: orgPath("identity-providers") });
1012
936
  },
1013
- /** POST /idp-providers — create a new IdP integration. */
937
+ /** POST /identity-providers — create a new IdP integration. */
1014
938
  async create(input) {
1015
- return request(config, { method: "POST", path: orgPath("idp-providers"), body: input });
939
+ return request(config, { method: "POST", path: orgPath("identity-providers"), body: input });
1016
940
  },
1017
- /** GET /idp-providers/<idpId>. */
941
+ /** GET /identity-providers/<idpId>. */
1018
942
  async get(idpId) {
1019
- return request(config, { method: "GET", path: orgPath(`idp-providers/${encodeURIComponent(idpId)}`) });
943
+ return request(config, { method: "GET", path: orgPath(`identity-providers/${encodeURIComponent(idpId)}`) });
1020
944
  },
1021
- /** PATCH /idp-providers/<idpId> — update config or enable/disable. */
945
+ /** PATCH /identity-providers/<idpId> — update settings or enable/disable. */
1022
946
  async configure(idpId, patch) {
1023
- return request(config, { method: "PATCH", path: orgPath(`idp-providers/${encodeURIComponent(idpId)}`), body: patch });
947
+ return request(config, { method: "PATCH", path: orgPath(`identity-providers/${encodeURIComponent(idpId)}`), body: patch });
1024
948
  },
1025
- /** DELETE /idp-providers/<idpId>. */
949
+ /** DELETE /identity-providers/<idpId>. */
1026
950
  async delete(idpId) {
1027
- return request(config, { method: "DELETE", path: orgPath(`idp-providers/${encodeURIComponent(idpId)}`) });
951
+ return request(config, { method: "DELETE", path: orgPath(`identity-providers/${encodeURIComponent(idpId)}`) });
1028
952
  }
1029
953
  }
1030
954
  };
@@ -1032,18 +956,8 @@ function makeOrgGateNamespace(config) {
1032
956
  function makeSmtpNamespace(config) {
1033
957
  return {
1034
958
  /**
1035
- * GET /org/smtp — read current SMTP config.
1036
- * Returns null when no org-level SMTP is configured (falls back to
1037
- * platform SMTP 3-tier cascade).
1038
- */
1039
- async get() {
1040
- return request(config, { method: "GET", path: orgPath("org/smtp") });
1041
- },
1042
- /**
1043
- * PATCH /orgs/<orgSlug> with `smtpConfig` body — set or update SMTP.
1044
- * PATCH on the org resource accepts smtpConfig.
1045
- * Passwords route through Kibo enclave — SDK accepts plaintext at
1046
- * the SDK boundary; gateway stores the reference.
959
+ * PATCH /org with `smtpConfig` body — set or update SMTP. Answers the org record.
960
+ * The body carries `passwordRef` (a reference to the stored password), not the password.
1047
961
  */
1048
962
  async set(config_) {
1049
963
  return request(config, { method: "PATCH", path: orgPath("org"), body: { smtpConfig: config_ } });
@@ -1056,7 +970,7 @@ function makeSmtpNamespace(config) {
1056
970
  async test(input) {
1057
971
  return request(config, { method: "POST", path: orgPath("org/smtp/test-email"), body: input });
1058
972
  },
1059
- /** PATCH /orgs/<orgSlug> with `smtpConfig: null` — clear org-level SMTP. */
973
+ /** PATCH /org with `smtpConfig: null` — clear org-level SMTP. Answers the org record. */
1060
974
  async unset() {
1061
975
  return request(config, { method: "PATCH", path: orgPath("org"), body: { smtpConfig: null } });
1062
976
  }
@@ -1065,39 +979,38 @@ function makeSmtpNamespace(config) {
1065
979
  function makeDefaultLlmNamespace(config) {
1066
980
  return {
1067
981
  /**
1068
- * GET /org/default-llm — read the org-default LLM model id
1069
- *. Returns `null` when no explicit default is set (gateway
1070
- * falls back to `mistral-7b`). ORG_ADMIN read; tier-gated.
982
+ * GET /default-llm — read the org-default LLM model id.
983
+ * Any accepted member of the org may read it.
1071
984
  */
1072
985
  async get() {
1073
- return request(config, { method: "GET", path: orgPath("org/default-llm") });
986
+ return request(config, { method: "GET", path: orgPath("default-llm") });
1074
987
  },
1075
988
  /**
1076
- * PATCH /org/default-llm — set the org-default LLM.
1077
- * ORG_ADMIN only. The model must be available to the org's tier per
989
+ * PATCH /default-llm — set the org-default LLM.
990
+ * ORG_ADMIN or ORG_OWNER only. The model must be available to the org's tier
1078
991
  * or the gateway returns K9O_TIER_FEATURE_GATED.
1079
992
  */
1080
993
  async set(input) {
1081
- return request(config, { method: "PATCH", path: orgPath("org/default-llm"), body: input });
994
+ return request(config, { method: "PATCH", path: orgPath("default-llm"), body: input });
1082
995
  }
1083
996
  };
1084
997
  }
1085
998
  function makeOrgNamespace(config) {
1086
999
  return {
1087
- /** Member lifecycle — list / invite / get / remove. */
1000
+ /** Member lifecycle — list / invite / remove. */
1088
1001
  members: makeMembersNamespace(config),
1089
- /** Group lifecycle — list / create / get / delete. */
1002
+ /** Groups — list / get (read-only). */
1090
1003
  groups: makeGroupsNamespace(config),
1091
- /** Org-plane audit log — query / tail. Distinct from project-plane `client.audit`. */
1004
+ /** Org-plane audit log — query. Distinct from project-plane `client.audit`. */
1092
1005
  auditLog: makeOrgAuditLogNamespace(config),
1093
1006
  /** Gate (IAK) org-level surfaces — role-grants + IdP-providers. */
1094
1007
  gate: makeOrgGateNamespace(config),
1095
- /** Org-level SMTP config — get / set / test / unset. */
1008
+ /** Org-level SMTP config — set / test / unset. */
1096
1009
  smtp: makeSmtpNamespace(config),
1097
1010
  /** Org-default LLM — get / set (ORG_ADMIN). */
1098
1011
  defaultLLM: makeDefaultLlmNamespace(config),
1099
1012
  /**
1100
- * GET /org — read the current org (slug + name + status + settings).
1013
+ * GET /org — read the current org (slug, displayName, products, billing tier, your role).
1101
1014
  * Mirrors `client.orgs.current()` for symmetry; `client.org.get()` is
1102
1015
  * the singular-namespace convention for use within an org-bound client.
1103
1016
  */
@@ -1115,7 +1028,7 @@ function makeMeNamespace(config) {
1115
1028
  async get() {
1116
1029
  return request(config, { method: "GET", path: orgPath("me") });
1117
1030
  },
1118
- /** PATCH /me — update mutable profile fields (displayName). */
1031
+ /** PATCH /me — update mutable profile fields (displayName, locale, timezone). */
1119
1032
  async update(patch) {
1120
1033
  return request(config, { method: "PATCH", path: orgPath("me"), body: patch });
1121
1034
  }
@@ -1125,19 +1038,16 @@ function makeMeNamespace(config) {
1125
1038
  async list() {
1126
1039
  return request(config, { method: "GET", path: orgPath("me/sessions") });
1127
1040
  },
1128
- /** DELETE /me/sessions/<sessionId> — revoke a specific session. */
1041
+ /** POST /auth/sessions/<sessionId>/revoke — revoke a specific session. */
1129
1042
  async revoke(sessionId) {
1130
- return request(config, { method: "DELETE", path: orgPath(`me/sessions/${encodeURIComponent(sessionId)}`) });
1043
+ return request(config, { method: "POST", path: orgPath(`auth/sessions/${encodeURIComponent(sessionId)}/revoke`) });
1131
1044
  },
1132
- /** DELETE /me/sessions (no path) — revoke all sessions except the current one. */
1045
+ /** POST /me/sessions/revoke-all — revoke all of the operator's sessions except the current one. */
1133
1046
  async revokeAll() {
1134
- return request(config, { method: "DELETE", path: orgPath("me/sessions") });
1047
+ return request(config, { method: "POST", path: orgPath("me/sessions/revoke-all") });
1135
1048
  }
1136
1049
  },
1137
- /**
1138
- * API tokens for personal scripting. The gateway endpoints are not available yet,
1139
- * so these methods return K9O_NOT_FOUND until they ship.
1140
- */
1050
+ /** Personal access tokens for scripting. */
1141
1051
  apiTokens: {
1142
1052
  async list() {
1143
1053
  return request(config, { method: "GET", path: orgPath("me/api-tokens") });
@@ -1148,43 +1058,6 @@ function makeMeNamespace(config) {
1148
1058
  async delete(tokenId) {
1149
1059
  return request(config, { method: "DELETE", path: orgPath(`me/api-tokens/${encodeURIComponent(tokenId)}`) });
1150
1060
  }
1151
- },
1152
- /**
1153
- * Notifications — operator-targeted (account-level events). Forward-
1154
- * cycle substrate; methods route correctly when gateway ships.
1155
- */
1156
- notifications: {
1157
- async list(opts) {
1158
- return request(config, { method: "GET", path: orgPath("me/notifications"), query: opts });
1159
- },
1160
- async markRead(notificationId) {
1161
- return request(config, { method: "PATCH", path: orgPath(`me/notifications/${encodeURIComponent(notificationId)}`), body: { read: true } });
1162
- },
1163
- async markAllRead() {
1164
- return request(config, { method: "PATCH", path: orgPath("me/notifications"), body: { read: true } });
1165
- }
1166
- },
1167
- /**
1168
- * Operator-self audit log — actions performed BY this operator across
1169
- * orgs. Distinct from `client.audit` (project-plane) and
1170
- * `client.org.auditLog` (org-plane).
1171
- */
1172
- auditLog: {
1173
- async query(opts) {
1174
- return request(config, { method: "GET", path: orgPath("me/audit-log"), query: opts });
1175
- }
1176
- },
1177
- /**
1178
- * Personal data export per GDPR-style requests. Returns a job id
1179
- * the operator polls for completion.
1180
- */
1181
- dataExport: {
1182
- async request(input) {
1183
- return request(config, { method: "POST", path: orgPath("me/data-export"), body: input ?? {} });
1184
- },
1185
- async status(jobId) {
1186
- return request(config, { method: "GET", path: orgPath(`me/data-export/${encodeURIComponent(jobId)}`) });
1187
- }
1188
1061
  }
1189
1062
  };
1190
1063
  }
@@ -1198,7 +1071,7 @@ var WORKFLOW_ERROR_CODES = {
1198
1071
  RUN_NOT_CANCELLABLE: "K9O_WORKFLOW_RUN_NOT_CANCELLABLE",
1199
1072
  WEBHOOK_SIGNATURE_INVALID: "K9O_WORKFLOW_WEBHOOK_SIGNATURE_INVALID"
1200
1073
  };
1201
- function requireProjectSlug8(config) {
1074
+ function requireProjectSlug7(config) {
1202
1075
  if (typeof config.projectSlug !== "string" || config.projectSlug.length === 0) {
1203
1076
  throw new Error("studio.workflows operations require projectSlug bound on the client");
1204
1077
  }
@@ -1208,7 +1081,7 @@ function makeRunsNamespace(config) {
1208
1081
  return {
1209
1082
  /** GET /@<slug>/workflows/<wfl-id>/runs — cursor-paginated runs list. */
1210
1083
  async list(workflowId, filters) {
1211
- const slug = requireProjectSlug8(config);
1084
+ const slug = requireProjectSlug7(config);
1212
1085
  return request(config, {
1213
1086
  method: "GET",
1214
1087
  path: projectPath(slug, `workflows/${encodeURIComponent(workflowId)}/runs`),
@@ -1217,7 +1090,7 @@ function makeRunsNamespace(config) {
1217
1090
  },
1218
1091
  /** GET /@<slug>/workflows/<wfl-id>/runs/<wfr-id> — run detail (per-step + cost). */
1219
1092
  async read(workflowId, runId) {
1220
- const slug = requireProjectSlug8(config);
1093
+ const slug = requireProjectSlug7(config);
1221
1094
  return request(config, {
1222
1095
  method: "GET",
1223
1096
  path: projectPath(slug, `workflows/${encodeURIComponent(workflowId)}/runs/${encodeURIComponent(runId)}`)
@@ -1225,7 +1098,7 @@ function makeRunsNamespace(config) {
1225
1098
  },
1226
1099
  /** POST /@<slug>/workflows/<wfl-id>/runs/<wfr-id>/cancel — cancel pending or running run. */
1227
1100
  async cancel(workflowId, runId) {
1228
- const slug = requireProjectSlug8(config);
1101
+ const slug = requireProjectSlug7(config);
1229
1102
  return request(config, {
1230
1103
  method: "POST",
1231
1104
  path: projectPath(slug, `workflows/${encodeURIComponent(workflowId)}/runs/${encodeURIComponent(runId)}/cancel`)
@@ -1237,17 +1110,17 @@ function makeWorkflowsNamespace(config) {
1237
1110
  return {
1238
1111
  /** GET /@<slug>/workflows — list workflows (cursor pagination). */
1239
1112
  async list(filters) {
1240
- const slug = requireProjectSlug8(config);
1113
+ const slug = requireProjectSlug7(config);
1241
1114
  return request(config, { method: "GET", path: projectPath(slug, "workflows"), query: filters });
1242
1115
  },
1243
1116
  /** POST /@<slug>/workflows — create a workflow. Requires PROJECT_AUTHOR. */
1244
1117
  async create(workflow) {
1245
- const slug = requireProjectSlug8(config);
1118
+ const slug = requireProjectSlug7(config);
1246
1119
  return request(config, { method: "POST", path: projectPath(slug, "workflows"), body: workflow });
1247
1120
  },
1248
1121
  /** GET /@<slug>/workflows/<wfl-id> — read a workflow. */
1249
1122
  async read(workflowId) {
1250
- const slug = requireProjectSlug8(config);
1123
+ const slug = requireProjectSlug7(config);
1251
1124
  return request(config, {
1252
1125
  method: "GET",
1253
1126
  path: projectPath(slug, `workflows/${encodeURIComponent(workflowId)}`)
@@ -1255,7 +1128,7 @@ function makeWorkflowsNamespace(config) {
1255
1128
  },
1256
1129
  /** PATCH /@<slug>/workflows/<wfl-id> — update a workflow. Requires PROJECT_AUTHOR. */
1257
1130
  async update(workflowId, updates) {
1258
- const slug = requireProjectSlug8(config);
1131
+ const slug = requireProjectSlug7(config);
1259
1132
  return request(config, {
1260
1133
  method: "PATCH",
1261
1134
  path: projectPath(slug, `workflows/${encodeURIComponent(workflowId)}`),
@@ -1264,7 +1137,7 @@ function makeWorkflowsNamespace(config) {
1264
1137
  },
1265
1138
  /** DELETE /@<slug>/workflows/<wfl-id> — delete a workflow. Requires PROJECT_AUTHOR. */
1266
1139
  async delete(workflowId) {
1267
- const slug = requireProjectSlug8(config);
1140
+ const slug = requireProjectSlug7(config);
1268
1141
  return request(config, {
1269
1142
  method: "DELETE",
1270
1143
  path: projectPath(slug, `workflows/${encodeURIComponent(workflowId)}`)
@@ -1273,14 +1146,14 @@ function makeWorkflowsNamespace(config) {
1273
1146
  /**
1274
1147
  * POST /@<slug>/workflows/<wfl-id>/runs — manual-trigger a run.
1275
1148
  * Valid only for `triggerType: 'manual'` workflows.
1276
- * Requires PROJECT_AUTHOR. Returns the materialised WorkflowRun.
1149
+ * Requires PROJECT_AUTHOR. The argument is sent as `{ triggerContext }`. Returns the materialised WorkflowRun.
1277
1150
  */
1278
1151
  async trigger(workflowId, triggerContext = {}) {
1279
- const slug = requireProjectSlug8(config);
1152
+ const slug = requireProjectSlug7(config);
1280
1153
  return request(config, {
1281
1154
  method: "POST",
1282
1155
  path: projectPath(slug, `workflows/${encodeURIComponent(workflowId)}/runs`),
1283
- body: triggerContext
1156
+ body: { triggerContext }
1284
1157
  });
1285
1158
  },
1286
1159
  /** Run sub-namespace — list / read / cancel runs of a workflow. */
@@ -1293,7 +1166,7 @@ var DASHBOARD_ERROR_CODES = {
1293
1166
  NOT_FOUND: "K9O_DASHBOARD_NOT_FOUND",
1294
1167
  WIDGET_INVALID: "K9O_DASHBOARD_WIDGET_INVALID"
1295
1168
  };
1296
- function requireProjectSlug9(config) {
1169
+ function requireProjectSlug8(config) {
1297
1170
  if (typeof config.projectSlug !== "string" || config.projectSlug.length === 0) {
1298
1171
  throw new Error("studio.dashboards operations require projectSlug bound on the client");
1299
1172
  }
@@ -1303,17 +1176,17 @@ function makeDashboardsNamespace(config) {
1303
1176
  return {
1304
1177
  /** GET /@<slug>/dashboards — list dashboards (cursor pagination). */
1305
1178
  async list(filters) {
1306
- const slug = requireProjectSlug9(config);
1179
+ const slug = requireProjectSlug8(config);
1307
1180
  return request(config, { method: "GET", path: projectPath(slug, "dashboards"), query: filters });
1308
1181
  },
1309
1182
  /** POST /@<slug>/dashboards — create a dashboard. Requires PROJECT_AUTHOR. */
1310
1183
  async create(dashboard) {
1311
- const slug = requireProjectSlug9(config);
1184
+ const slug = requireProjectSlug8(config);
1312
1185
  return request(config, { method: "POST", path: projectPath(slug, "dashboards"), body: dashboard });
1313
1186
  },
1314
1187
  /** GET /@<slug>/dashboards/<dsh-id> — read a dashboard. */
1315
1188
  async read(dashboardId) {
1316
- const slug = requireProjectSlug9(config);
1189
+ const slug = requireProjectSlug8(config);
1317
1190
  return request(config, {
1318
1191
  method: "GET",
1319
1192
  path: projectPath(slug, `dashboards/${encodeURIComponent(dashboardId)}`)
@@ -1321,7 +1194,7 @@ function makeDashboardsNamespace(config) {
1321
1194
  },
1322
1195
  /** PATCH /@<slug>/dashboards/<dsh-id> — update a dashboard. Requires PROJECT_AUTHOR. */
1323
1196
  async update(dashboardId, updates) {
1324
- const slug = requireProjectSlug9(config);
1197
+ const slug = requireProjectSlug8(config);
1325
1198
  return request(config, {
1326
1199
  method: "PATCH",
1327
1200
  path: projectPath(slug, `dashboards/${encodeURIComponent(dashboardId)}`),
@@ -1330,7 +1203,7 @@ function makeDashboardsNamespace(config) {
1330
1203
  },
1331
1204
  /** DELETE /@<slug>/dashboards/<dsh-id> — delete a dashboard. Requires PROJECT_AUTHOR. */
1332
1205
  async delete(dashboardId) {
1333
- const slug = requireProjectSlug9(config);
1206
+ const slug = requireProjectSlug8(config);
1334
1207
  return request(config, {
1335
1208
  method: "DELETE",
1336
1209
  path: projectPath(slug, `dashboards/${encodeURIComponent(dashboardId)}`)
@@ -1338,7 +1211,7 @@ function makeDashboardsNamespace(config) {
1338
1211
  },
1339
1212
  /** POST /@<slug>/dashboards/<dsh-id>/pin — pin to Workspace sidebar. Requires PROJECT_AUTHOR. */
1340
1213
  async pin(dashboardId) {
1341
- const slug = requireProjectSlug9(config);
1214
+ const slug = requireProjectSlug8(config);
1342
1215
  return request(config, {
1343
1216
  method: "POST",
1344
1217
  path: projectPath(slug, `dashboards/${encodeURIComponent(dashboardId)}/pin`)
@@ -1346,7 +1219,7 @@ function makeDashboardsNamespace(config) {
1346
1219
  },
1347
1220
  /** POST /@<slug>/dashboards/<dsh-id>/unpin — unpin. Requires PROJECT_AUTHOR. */
1348
1221
  async unpin(dashboardId) {
1349
- const slug = requireProjectSlug9(config);
1222
+ const slug = requireProjectSlug8(config);
1350
1223
  return request(config, {
1351
1224
  method: "POST",
1352
1225
  path: projectPath(slug, `dashboards/${encodeURIComponent(dashboardId)}/unpin`)
@@ -1424,10 +1297,13 @@ function decodePayload(payload) {
1424
1297
  }
1425
1298
 
1426
1299
  // src/compute/llms.ts
1300
+ function invokeBody(input) {
1301
+ return { prompt: input.prompt, ...input.params };
1302
+ }
1427
1303
  var LLM_ERROR_CODES = {
1428
1304
  PROVIDER_UNAVAILABLE: "K9O_LLM_PROVIDER_UNAVAILABLE"
1429
1305
  };
1430
- function requireProjectSlug10(config) {
1306
+ function requireProjectSlug9(config) {
1431
1307
  if (typeof config.projectSlug !== "string" || config.projectSlug.length === 0) {
1432
1308
  throw new Error("compute.llms operations require projectSlug bound on the client");
1433
1309
  }
@@ -1437,12 +1313,12 @@ function makeLlmsNamespace(config) {
1437
1313
  return {
1438
1314
  /** GET /@<slug>/compute/llms — list models available to the project tier. */
1439
1315
  async list(opts) {
1440
- const slug = requireProjectSlug10(config);
1316
+ const slug = requireProjectSlug9(config);
1441
1317
  return request(config, { method: "GET", path: projectPath(slug, "compute/llms"), query: opts });
1442
1318
  },
1443
1319
  /** GET /@<slug>/compute/llms/<model-id> — read single model metadata + cost. */
1444
1320
  async read(modelId) {
1445
- const slug = requireProjectSlug10(config);
1321
+ const slug = requireProjectSlug9(config);
1446
1322
  return request(config, {
1447
1323
  method: "GET",
1448
1324
  path: projectPath(slug, `compute/llms/${encodeURIComponent(modelId)}`)
@@ -1453,27 +1329,26 @@ function makeLlmsNamespace(config) {
1453
1329
  * Requires PROJECT_AUTHOR or PROJECT_ADMIN (LLM cost gate).
1454
1330
  */
1455
1331
  async invoke(modelId, input) {
1456
- const slug = requireProjectSlug10(config);
1332
+ const slug = requireProjectSlug9(config);
1457
1333
  return request(config, {
1458
1334
  method: "POST",
1459
1335
  path: projectPath(slug, `compute/llms/${encodeURIComponent(modelId)}/invoke`),
1460
- body: { prompt: input.prompt, params: input.params }
1336
+ body: invokeBody(input)
1461
1337
  });
1462
1338
  },
1463
1339
  /**
1464
1340
  * POST /@<slug>/compute/llms/<model-id>/invoke-stream — streaming
1465
- * inference (SSE; per-token delta for low-latency UX).
1341
+ * inference (SSE; the model server's OpenAI-style chunks).
1466
1342
  * Returns an async iterable of `LLMStreamChunk` — caller writes
1467
1343
  * `for await (const chunk of client.compute.llms.invokeStream(...))`.
1468
- * The SDK handles SSE framing internally per
1469
- * `feedback_sdk_abstracted_primitive_default_to_richer_interaction.md`.
1344
+ * The SDK handles SSE framing internally.
1470
1345
  */
1471
1346
  async *invokeStream(modelId, input) {
1472
- const slug = requireProjectSlug10(config);
1347
+ const slug = requireProjectSlug9(config);
1473
1348
  const response = await requestStream(config, {
1474
1349
  method: "POST",
1475
1350
  path: projectPath(slug, `compute/llms/${encodeURIComponent(modelId)}/invoke-stream`),
1476
- body: { prompt: input.prompt, params: input.params },
1351
+ body: invokeBody(input),
1477
1352
  accept: "text/event-stream"
1478
1353
  });
1479
1354
  yield* parseSseStream(response.body);
@@ -1482,13 +1357,13 @@ function makeLlmsNamespace(config) {
1482
1357
  }
1483
1358
  function makeComputeNamespace(config) {
1484
1359
  return {
1485
- /** LLM registry + inference — `client.compute.llms.*`. */
1360
+ /** LLM registry + inference — `client.compute.llms.*` . */
1486
1361
  llms: makeLlmsNamespace(config)
1487
1362
  };
1488
1363
  }
1489
1364
 
1490
1365
  // src/ai.ts
1491
- function requireProjectSlug11(config) {
1366
+ function requireProjectSlug10(config) {
1492
1367
  if (typeof config.projectSlug !== "string" || config.projectSlug.length === 0) {
1493
1368
  throw new Error("ai operations require projectSlug bound on the client");
1494
1369
  }
@@ -1498,7 +1373,7 @@ function makeAiNamespace(config) {
1498
1373
  return {
1499
1374
  /** POST /@<slug>/ai/embeddings — embed one or more strings. */
1500
1375
  async embed(input) {
1501
- const slug = requireProjectSlug11(config);
1376
+ const slug = requireProjectSlug10(config);
1502
1377
  const body = {
1503
1378
  input: typeof input.input === "string" ? input.input : [...input.input]
1504
1379
  };
@@ -1535,80 +1410,14 @@ var realtimeTopic = {
1535
1410
  return `audit.org.${eventFamily}`;
1536
1411
  }
1537
1412
  };
1538
- function requireProjectSlug12(config) {
1413
+ function requireProjectSlug11(config) {
1539
1414
  if (typeof config.projectSlug !== "string" || config.projectSlug.length === 0) {
1540
1415
  throw new Error("realtime operations require projectSlug bound on the client");
1541
1416
  }
1542
1417
  return config.projectSlug;
1543
1418
  }
1544
- function selectTransport(forced) {
1545
- if (forced) return forced;
1546
- if (typeof globalThis.WebSocket === "function") return "websocket";
1547
- return "sse";
1548
- }
1549
- function toWebSocketUrl(baseUrl, path, query) {
1550
- const trimmed = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
1551
- const wsBase = trimmed.replace(/^http/, "ws");
1552
- const qs = new URLSearchParams(query).toString();
1553
- return `${wsBase}${path}${qs ? `?${qs}` : ""}`;
1554
- }
1555
- async function* websocketTransport(config, topic, options, closed) {
1556
- const slug = requireProjectSlug12(config);
1557
- const query = { topic };
1558
- if (options.filter) query.filter = JSON.stringify(options.filter);
1559
- if (config.apiKey) query.access_token = config.apiKey;
1560
- const url = toWebSocketUrl(config.baseUrl, projectPath(slug, "realtime/subscribe"), query);
1561
- const WS = globalThis.WebSocket;
1562
- const socket = new WS(url);
1563
- const queue = [];
1564
- let resolveNext = null;
1565
- let socketClosed = false;
1566
- let socketError = null;
1567
- const wake = () => {
1568
- if (resolveNext) {
1569
- resolveNext();
1570
- resolveNext = null;
1571
- }
1572
- };
1573
- socket.onmessage = (ev) => {
1574
- try {
1575
- queue.push(JSON.parse(typeof ev.data === "string" ? ev.data : String(ev.data)));
1576
- } catch {
1577
- }
1578
- wake();
1579
- };
1580
- socket.onerror = () => {
1581
- socketError = new Error("realtime websocket transport error");
1582
- wake();
1583
- };
1584
- socket.onclose = () => {
1585
- socketClosed = true;
1586
- wake();
1587
- };
1588
- options.signal?.addEventListener("abort", () => socket.close());
1589
- try {
1590
- while (!closed.value) {
1591
- if (queue.length > 0) {
1592
- yield queue.shift();
1593
- continue;
1594
- }
1595
- if (socketClosed) {
1596
- if (socketError) throw socketError;
1597
- return;
1598
- }
1599
- await new Promise((resolve) => {
1600
- resolveNext = resolve;
1601
- });
1602
- }
1603
- } finally {
1604
- try {
1605
- socket.close();
1606
- } catch {
1607
- }
1608
- }
1609
- }
1610
1419
  async function* sseTransport(config, topic, options, closed) {
1611
- const slug = requireProjectSlug12(config);
1420
+ const slug = requireProjectSlug11(config);
1612
1421
  const query = { topic };
1613
1422
  if (options.filter) query.filter = JSON.stringify(options.filter);
1614
1423
  const response = await requestStream(config, {
@@ -1619,63 +1428,31 @@ async function* sseTransport(config, topic, options, closed) {
1619
1428
  });
1620
1429
  for await (const event of parseSseStream(response.body)) {
1621
1430
  if (closed.value || options.signal?.aborted) return;
1431
+ if (typeof event.eventType !== "string") continue;
1622
1432
  yield event;
1623
1433
  }
1624
1434
  }
1625
- async function* pollTransport(config, topic, options, closed) {
1626
- const slug = requireProjectSlug12(config);
1627
- const interval = options.pollIntervalMs ?? 2e3;
1628
- let cursor = 0;
1629
- while (!closed.value && !options.signal?.aborted) {
1630
- const { data } = await request(config, {
1631
- method: "POST",
1632
- path: projectPath(slug, "realtime/replay"),
1633
- body: { topic, filter: options.filter, fromSequence: cursor }
1634
- });
1635
- for (const event of data ?? []) {
1636
- if (closed.value || options.signal?.aborted) return;
1637
- cursor = Math.max(cursor, event.sequence + 1);
1638
- yield event;
1639
- }
1640
- if (closed.value || options.signal?.aborted) return;
1641
- await new Promise((resolve) => setTimeout(resolve, interval));
1642
- }
1643
- }
1644
1435
  function makeRealtimeNamespace(config) {
1645
1436
  return {
1646
1437
  /**
1647
1438
  * Subscribe to a topic. Returns a `RealtimeSubscription` — an async
1648
- * iterable of `RealtimeEvent`s. The SDK selects the richest available
1649
- * transport (WebSocket → SSE → poll); the caller's
1650
- * `for await` loop is transport-agnostic.
1439
+ * iterable of `RealtimeEvent`s over SSE.
1651
1440
  *
1652
1441
  * ```ts
1653
1442
  * const sub = client.realtime.subscribe(
1654
1443
  * realtimeTopic.dashboardRefresh("dsh_abc"),
1655
1444
  * );
1656
1445
  * for await (const event of sub) {
1657
- * if (event.type === "dashboard.widget.data_refreshed") rerender(event.payload);
1446
+ * if (event.eventType === "dashboard.widget.data_refreshed") rerender(event.payload);
1658
1447
  * }
1659
1448
  * ```
1660
1449
  */
1661
1450
  subscribe(topic, options = {}) {
1662
- requireProjectSlug12(config);
1663
- const transport = selectTransport(options.transport);
1451
+ requireProjectSlug11(config);
1664
1452
  const closed = { value: false };
1665
- const iterate = () => {
1666
- switch (transport) {
1667
- case "websocket":
1668
- return websocketTransport(config, topic, options, closed);
1669
- case "poll":
1670
- return pollTransport(config, topic, options, closed);
1671
- case "sse":
1672
- default:
1673
- return sseTransport(config, topic, options, closed);
1674
- }
1675
- };
1453
+ const iterate = () => sseTransport(config, topic, options, closed);
1676
1454
  let active = null;
1677
1455
  return {
1678
- transport,
1679
1456
  [Symbol.asyncIterator]() {
1680
1457
  active = iterate();
1681
1458
  return active;
@@ -1685,34 +1462,6 @@ function makeRealtimeNamespace(config) {
1685
1462
  void active?.return(void 0);
1686
1463
  }
1687
1464
  };
1688
- },
1689
- /**
1690
- * One-shot historical replay — catch up on missed
1691
- * events from `fromSequence`. Capped at 10k events server-side;
1692
- * paginate via the returned events' `sequence`. Use the highest
1693
- * `sequence` you've seen as the next `fromSequence`.
1694
- */
1695
- async replay(input) {
1696
- const slug = requireProjectSlug12(config);
1697
- if (!Number.isInteger(input.fromSequence) || input.fromSequence < 0) {
1698
- throw new KError({
1699
- code: "K9O_INVALID_FILTER",
1700
- message: "replay fromSequence must be a non-negative integer",
1701
- context: { fromSequence: input.fromSequence },
1702
- recommendation: "Pass the highest sequence number you have already observed (or 0 to replay from the start)."
1703
- });
1704
- }
1705
- return request(config, {
1706
- method: "POST",
1707
- path: projectPath(slug, "realtime/replay"),
1708
- body: {
1709
- topic: input.topic,
1710
- filter: input.filter,
1711
- fromSequence: input.fromSequence,
1712
- untilSequence: input.untilSequence,
1713
- limit: input.limit
1714
- }
1715
- });
1716
1465
  }
1717
1466
  };
1718
1467
  }
@@ -1855,7 +1604,6 @@ function createClient(options) {
1855
1604
  from: makeFromFactory(config),
1856
1605
  projects: makeProjectsNamespace(config),
1857
1606
  storage: makeStorageNamespace(config),
1858
- metadata: makeMetadataNamespace(config),
1859
1607
  migrations: makeMigrationsNamespace(config),
1860
1608
  functions: makeFunctionsNamespace(config),
1861
1609
  policies: makePoliciesNamespace(config),
@@ -1885,9 +1633,9 @@ export {
1885
1633
  BYOS_CRED_VAULT_NAME_PREFIX,
1886
1634
  BYOS_PROVIDER_SCHEME,
1887
1635
  DASHBOARD_ERROR_CODES,
1636
+ DEFAULT_BASE_URL,
1888
1637
  KError,
1889
1638
  LLM_ERROR_CODES,
1890
- METADATA_OPERATORS,
1891
1639
  WORKFLOW_ERROR_CODES,
1892
1640
  assertProviderRegion,
1893
1641
  byosCredVaultName,
@@ -1897,6 +1645,7 @@ export {
1897
1645
  isProviderRegion,
1898
1646
  kerrorFromWire,
1899
1647
  orgPath,
1648
+ parseApiHost,
1900
1649
  platformPath,
1901
1650
  projectPath,
1902
1651
  realtimeTopic,