@dxos/edge-client 0.16.0 → 0.17.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.
@@ -9,6 +9,7 @@ import * as Layer from "effect/Layer";
9
9
  import * as Schema from "effect/Schema";
10
10
  import * as EffectEx from "@dxos/effect/EffectEx";
11
11
  import { invariant } from "@dxos/invariant";
12
+ import { IdentityDid, SpaceId } from "@dxos/keys";
12
13
  import { log } from "@dxos/log";
13
14
  import { EDGE_CLIENT_TAG_HEADER, EDGE_CLIENT_TOO_OLD, EDGE_CLIENT_VERSION_HEADER, EDGE_CLIENT_VERSION_PROTOCOL_PREFIX, EdgeAuthChallengeError, EdgeCallFailedError, EdgeClientTooOldError, EdgeCredentialsHeaderCodec, InboxListResponseSchema, InboxSendResponseSchema } from "@dxos/protocols";
14
15
  import { createUrl } from "@dxos/util";
@@ -27,7 +28,7 @@ import { BaseError } from "@dxos/errors";
27
28
  * This SDK's version, which EDGE checks against the oldest it serves. It releases in lockstep with the rest of the
28
29
  * SDK, and Vite tree-shakes the import to this one field.
29
30
  */
30
- var CLIENT_SDK_VERSION = "0.16.0";
31
+ var CLIENT_SDK_VERSION = "0.17.0";
31
32
  /** Headers advertising {@link CLIENT_SDK_VERSION} on a request of the EDGE connect flow (`/auth` and its fallback). */
32
33
  var clientVersionHeaders = () => ({ [EDGE_CLIENT_VERSION_HEADER]: CLIENT_SDK_VERSION });
33
34
  /** The same advertisement for the WebSocket upgrade, where a browser can set no header but the subprotocol list. */
@@ -622,8 +623,53 @@ var createRetryHandler = ({ retry }) => {
622
623
  //#endregion
623
624
  //#region src/edge-http-client.ts
624
625
  var __dxlog_file = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-http-client.ts";
625
- /** What EDGE answers every brain fact feed route with: the EIDs of the fact feeds the brain indexes. */
626
- var BrainFactFeeds = Schema.Struct({ feeds: Schema.Array(Schema.String) });
626
+ var MB = 1048576;
627
+ /** One line for a CLI: `describe 3200 ms, js 11.5 MB, wasm 0.0 MB`. */
628
+ var formatPluginBundleLoad = ({ describeMs, jsBytes, wasmBytes }) => `describe ${describeMs} ms, js ${(jsBytes / MB).toFixed(1)} MB, wasm ${(wasmBytes / MB).toFixed(1)} MB`;
629
+ /** What EDGE answers `GET /compute/brain/:agent` with, as far as clients read it. */
630
+ var BrainInfo = Schema.Struct({
631
+ identity: Schema.Struct({
632
+ identityDid: Schema.String,
633
+ label: Schema.String,
634
+ defaultSpaceId: Schema.String
635
+ }),
636
+ role: Schema.String
637
+ });
638
+ /** What EDGE answers an added admin with: the identity keys of every admin of the agent. */
639
+ var BrainAdmins = Schema.Struct({ adminKeys: Schema.Array(Schema.String) });
640
+ /** What EDGE answers `GET /compute/brain/:agent/halo` with: what an admin inspects of an agent's identity. */
641
+ var AgentHalo = Schema.Struct({
642
+ identity: Schema.Struct({
643
+ identityDid: Schema.String,
644
+ identityKey: Schema.String,
645
+ agentKey: Schema.String,
646
+ defaultSpaceId: Schema.String,
647
+ homeSpaceId: Schema.String,
648
+ agent: Schema.String,
649
+ label: Schema.String
650
+ }),
651
+ haloSpaceId: Schema.optional(Schema.String),
652
+ /** `null` for an agent provisioned before EDGE kept its admins. */
653
+ adminKeys: Schema.NullOr(Schema.Array(Schema.String)),
654
+ /** The spaces the agent's admins put it in. */
655
+ joinedSpaceIds: Schema.Array(Schema.String),
656
+ /** The spaces the agent holds a feed in, its HALO and default space included. */
657
+ memberSpaceIds: Schema.Array(Schema.String),
658
+ /** Every credential in the agent's HALO, each a base64 `Credential`. */
659
+ credentials: Schema.Array(Schema.String)
660
+ });
661
+ /** What EDGE answers `POST /compute/brain` with: the brain's identity and the caller's membership of its space. */
662
+ var ProvisionedBrain = Schema.Struct({
663
+ identity: Schema.Struct({
664
+ identityDid: IdentityDid,
665
+ identityKey: Schema.String,
666
+ defaultSpaceId: Schema.optional(SpaceId)
667
+ }),
668
+ /** The caller's `SpaceMember` credential for the agent's default space, base64 protobuf. */
669
+ membership: Schema.String
670
+ });
671
+ /** EDGE route of an agent's mailbox. */
672
+ var mailboxPath = (handle) => `/compute/email/mailboxes/${encodeURIComponent(handle)}`;
627
673
  /**
628
674
  * Validates the finalize response rather than asserting its shape.
629
675
  *
@@ -651,7 +697,7 @@ var EdgeHttpClient = class extends BaseHttpClient {
651
697
  log("created", { url: this.baseUrl }, {
652
698
  "~LogMeta": "~LogMeta",
653
699
  F: __dxlog_file,
654
- L: 207,
700
+ L: 297,
655
701
  S: this
656
702
  });
657
703
  }
@@ -676,6 +722,36 @@ var EdgeHttpClient = class extends BaseHttpClient {
676
722
  body
677
723
  });
678
724
  }
725
+ /** Claims the agent's mailbox `handle`, or updates the claim; answers its status. */
726
+ async claimMailbox(ctx, handle, body, args) {
727
+ return this.request(ctx, mailboxPath(handle), {
728
+ ...args,
729
+ method: "PUT",
730
+ body
731
+ });
732
+ }
733
+ /** Releases the mailbox `handle`; answers its status. */
734
+ async releaseMailbox(ctx, handle, args) {
735
+ return this.request(ctx, mailboxPath(handle), {
736
+ ...args,
737
+ method: "DELETE"
738
+ });
739
+ }
740
+ /** The status of the mailbox `handle`. */
741
+ async getMailbox(ctx, handle, args) {
742
+ return this.request(ctx, mailboxPath(handle), {
743
+ ...args,
744
+ method: "GET"
745
+ });
746
+ }
747
+ /** Sends an email from the mailbox `handle`; answers what EDGE sent. */
748
+ async sendMailboxEmail(ctx, handle, body, args) {
749
+ return this.request(ctx, `${mailboxPath(handle)}/send`, {
750
+ ...args,
751
+ method: "POST",
752
+ body
753
+ });
754
+ }
679
755
  createAgent(ctx, body, args) {
680
756
  return this._call(ctx, new URL("/identity/agents/create", this.baseUrl), {
681
757
  ...args,
@@ -725,6 +801,26 @@ var EdgeHttpClient = class extends BaseHttpClient {
725
801
  auth: true
726
802
  });
727
803
  }
804
+ /**
805
+ * Asks edge to migrate a legacy space: edge mints the space root and credentials documents from the
806
+ * chain it already holds and returns the root in force. Idempotent and write-once, so every member
807
+ * that asks is handed the same root.
808
+ */
809
+ async migrateSpaceRoot(ctx, spaceId, args) {
810
+ return this._call(ctx, new URL(`/db/spaces/${spaceId}/root`, this.baseUrl), {
811
+ ...args,
812
+ method: "POST",
813
+ auth: true
814
+ });
815
+ }
816
+ /** The space root edge has in force, or null while the space is still on its control feed. */
817
+ async getSpaceRoot(ctx, spaceId, args) {
818
+ return this._call(ctx, new URL(`/db/spaces/${spaceId}/root`, this.baseUrl), {
819
+ ...args,
820
+ method: "GET",
821
+ auth: true
822
+ });
823
+ }
728
824
  async joinSpaceByInvitation(ctx, spaceId, body, args) {
729
825
  return this._call(ctx, new URL(`/db/spaces/${spaceId}/join`, this.baseUrl), {
730
826
  ...args,
@@ -800,7 +896,7 @@ var EdgeHttpClient = class extends BaseHttpClient {
800
896
  invariant(queueId, "queueId required", {
801
897
  "~LogMeta": "~LogMeta",
802
898
  F: __dxlog_file,
803
- L: 426,
899
+ L: 577,
804
900
  S: this,
805
901
  A: ["queueId", "'queueId required'"]
806
902
  });
@@ -962,10 +1058,15 @@ var EdgeHttpClient = class extends BaseHttpClient {
962
1058
  auth: true
963
1059
  });
964
1060
  }
965
- async forceRunCronTrigger(ctx, spaceId, triggerId) {
1061
+ /**
1062
+ * Runs a cron trigger now. `data` becomes the fire event's `data`, which the trigger's
1063
+ * `{{event.data.*}}` input templates read, and is kept across the run's `runAgain` continuations.
1064
+ */
1065
+ async forceRunCronTrigger(ctx, spaceId, triggerId, { data } = {}) {
966
1066
  return this._call(ctx, new URL(`/compute/functions/${spaceId}/triggers/crons/${triggerId}/run`, this.baseUrl), {
967
1067
  method: "POST",
968
- auth: true
1068
+ auth: true,
1069
+ ...data ? { body: { data } } : {}
969
1070
  });
970
1071
  }
971
1072
  /**
@@ -1002,38 +1103,55 @@ var EdgeHttpClient = class extends BaseHttpClient {
1002
1103
  });
1003
1104
  }
1004
1105
  /**
1005
- * Has an agent's brain index a fact feed (its EID) from now on; answers the feeds it indexes. `agent` names the
1006
- * brain (see plugin-agent's `AgentPresence.brainId`); the caller must be a member of `spaceId`, a space it serves.
1106
+ * The identity EDGE minted for an agent's brain, and the caller's role on it. `agent` is the agent's DID; EDGE answers
1107
+ * 404 to a caller with no role, as for a brain that does not exist.
1007
1108
  */
1008
- async addBrainFactFeed(ctx, spaceId, agent, feed, args) {
1009
- return this.#factFeedsCall(ctx, spaceId, agent, {
1109
+ async getBrain(ctx, agent, args) {
1110
+ const url = new URL(`/compute/brain/${encodeURIComponent(agent)}`, this.baseUrl);
1111
+ const response = await this._call(ctx, url, {
1112
+ ...args,
1113
+ method: "GET",
1114
+ auth: true
1115
+ });
1116
+ return Schema.decodeUnknownSync(BrainInfo)(response);
1117
+ }
1118
+ /** Gives the agent's brain an identity, for a caller who may write to its space; its creator asking again gets the same answer. */
1119
+ async provisionBrain(ctx, body, args) {
1120
+ const response = await this.request(ctx, "/compute/brain", {
1010
1121
  ...args,
1011
1122
  method: "POST",
1012
- body: { feed }
1123
+ body
1013
1124
  });
1125
+ return Schema.decodeUnknownSync(ProvisionedBrain)(response);
1014
1126
  }
1015
- /** Stops an agent's brain indexing a fact feed; the facts it read stay. Answers the feeds it still indexes. */
1016
- async removeBrainFactFeed(ctx, spaceId, agent, feed, args) {
1017
- return this.#factFeedsCall(ctx, spaceId, agent, {
1127
+ /** Puts the agent's brain in a space, which only its admins may do. `agent` is the agent's DID. */
1128
+ async addBrainSpace(ctx, agent, spaceId, args) {
1129
+ await this.request(ctx, `/compute/brain/${encodeURIComponent(agent)}/spaces`, {
1018
1130
  ...args,
1019
- method: "DELETE"
1020
- }, { feed });
1131
+ method: "POST",
1132
+ body: { spaceId }
1133
+ });
1021
1134
  }
1022
- /** The fact feeds an agent's brain indexes. */
1023
- async listBrainFactFeeds(ctx, spaceId, agent, args) {
1024
- return this.#factFeedsCall(ctx, spaceId, agent, {
1135
+ /** Makes an identity an admin of an agent, which only an admin may do; nothing takes it away. Answers every admin. */
1136
+ async addBrainAdmin(ctx, agent, identityKey, args) {
1137
+ const url = new URL(`/compute/brain/${encodeURIComponent(agent)}/admins`, this.baseUrl);
1138
+ const response = await this._call(ctx, url, {
1025
1139
  ...args,
1026
- method: "GET"
1140
+ method: "POST",
1141
+ body: { identityKey },
1142
+ auth: true
1027
1143
  });
1144
+ return Schema.decodeUnknownSync(BrainAdmins)(response);
1028
1145
  }
1029
- async #factFeedsCall(ctx, spaceId, agent, args, query = {}) {
1030
- const url = new URL(`/compute/brain/${spaceId}/${encodeURIComponent(agent)}/fact-feeds`, this.baseUrl);
1031
- for (const [key, value] of Object.entries(query)) url.searchParams.set(key, value);
1146
+ /** The agent's HALO, its admins and its spaces, which only its admins may read; EDGE answers anyone else 404. */
1147
+ async getAgentHalo(ctx, agent, args) {
1148
+ const url = new URL(`/compute/brain/${encodeURIComponent(agent)}/halo`, this.baseUrl);
1032
1149
  const response = await this._call(ctx, url, {
1033
1150
  ...args,
1151
+ method: "GET",
1034
1152
  auth: true
1035
1153
  });
1036
- return Schema.decodeUnknownSync(BrainFactFeeds)(response);
1154
+ return Schema.decodeUnknownSync(AgentHalo)(response);
1037
1155
  }
1038
1156
  async execQuery(ctx, spaceId, body, args) {
1039
1157
  return this._call(ctx, new URL(`/db/spaces/${spaceId}/exec-query`, this.baseUrl), {
@@ -1058,14 +1176,22 @@ var EdgeHttpClient = class extends BaseHttpClient {
1058
1176
  });
1059
1177
  }
1060
1178
  /**
1061
- * Uploads a built plugin bundle to the registry's R2-backed hosting. Authenticated
1062
- * with the caller's hub identity (verifiable presentation) — `setIdentity` must
1063
- * have been called. Returns the canonical `moduleUrl` (the hosted `manifest.json`).
1179
+ * Uploads a built plugin bundle to the registry's R2-backed hosting as `multipart/form-data`, one part per file named
1180
+ * by its path; EDGE streams the parts into storage, so the bundle never has to fit in a worker's memory. Authenticated
1181
+ * with the caller's hub identity (verifiable presentation) — `setIdentity` must have been called. Returns the
1182
+ * canonical `moduleUrl` (the hosted `manifest.json`).
1064
1183
  */
1065
- async uploadPluginBundle(ctx, request, args) {
1066
- return this._call(ctx, new URL("/registry/upload", this.baseUrl), {
1067
- body: request,
1184
+ async uploadPluginBundle(ctx, { slug, version, channel, files }, args) {
1185
+ const url = new URL("/registry/upload/multipart", this.baseUrl);
1186
+ url.searchParams.set("slug", slug);
1187
+ url.searchParams.set("version", version);
1188
+ if (channel) url.searchParams.set("channel", channel);
1189
+ const form = new FormData();
1190
+ for (const { path, content } of files) form.append(path, new Blob([content]), path);
1191
+ return this._call(ctx, url, {
1192
+ body: form,
1068
1193
  method: "POST",
1194
+ json: false,
1069
1195
  auth: true,
1070
1196
  ...args
1071
1197
  });
@@ -1220,6 +1346,6 @@ var EdgeHttpClient = class extends BaseHttpClient {
1220
1346
  };
1221
1347
  var getFileMimeType = (filename) => [".js", ".mjs"].some((ext) => filename.endsWith(ext)) ? "application/javascript+module" : filename.endsWith(".wasm") ? "application/wasm" : "application/octet-stream";
1222
1348
  //#endregion
1223
- export { clientVersionProtocol as C, clientVersionHeaders as S, handleAuthChallenge as _, getEdgeUrlWithProtocol as a, readAuthChallenge as b, withLogging as c, EdgeClientError as d, EdgeConnectionClosedError as f, fetchAuthChallengeInfo as g, fetchAuthChallenge as h, BaseHttpClient as i, withRetry as l, authenticateViaChallengeEndpoint as m, EdgeHttpClient as n, HttpConfig as o, EdgeIdentityChangedError as p, EdgeHttpClientService as r, encodeAuthHeader as s, BrainFactFeeds as t, withRetryConfig as u, parseChallengeHeader as v, readJsonBody as w, assertClientSupported as x, presentCredentialsForChallenge as y };
1349
+ export { presentCredentialsForChallenge as C, clientVersionProtocol as D, clientVersionHeaders as E, readJsonBody as O, parseChallengeHeader as S, assertClientSupported as T, EdgeIdentityChangedError as _, EdgeHttpClientService as a, fetchAuthChallengeInfo as b, BaseHttpClient as c, encodeAuthHeader as d, withLogging as f, EdgeConnectionClosedError as g, EdgeClientError as h, EdgeHttpClient as i, getEdgeUrlWithProtocol as l, withRetryConfig as m, BrainAdmins as n, ProvisionedBrain as o, withRetry as p, BrainInfo as r, formatPluginBundleLoad as s, AgentHalo as t, HttpConfig as u, authenticateViaChallengeEndpoint as v, readAuthChallenge as w, handleAuthChallenge as x, fetchAuthChallenge as y };
1224
1350
 
1225
1351
  //# sourceMappingURL=chunk-edge-http-client.mjs.map