@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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/edge-client",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "description": "EDGE Client",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -59,25 +59,25 @@
59
59
  ],
60
60
  "dependencies": {
61
61
  "@bufbuild/protobuf": "2.11.0",
62
+ "@dxos/async": "0.17.0",
63
+ "@dxos/context": "0.17.0",
64
+ "@dxos/credentials": "0.17.0",
65
+ "@dxos/crypto": "0.17.0",
66
+ "@dxos/effect": "0.17.0",
67
+ "@dxos/errors": "0.17.0",
68
+ "@dxos/invariant": "0.17.0",
69
+ "@dxos/keyring": "0.17.0",
70
+ "@dxos/keys": "0.17.0",
71
+ "@dxos/log": "0.17.0",
72
+ "@dxos/node-std": "0.17.0",
73
+ "@dxos/protocols": "0.17.0",
74
+ "@dxos/tracing": "0.17.0",
75
+ "@dxos/util": "0.17.0",
62
76
  "isomorphic-ws": "^5.0.0",
63
- "ws": "^8.17.1",
64
- "@dxos/async": "0.16.0",
65
- "@dxos/context": "0.16.0",
66
- "@dxos/credentials": "0.16.0",
67
- "@dxos/crypto": "0.16.0",
68
- "@dxos/effect": "0.16.0",
69
- "@dxos/errors": "0.16.0",
70
- "@dxos/invariant": "0.16.0",
71
- "@dxos/keyring": "0.16.0",
72
- "@dxos/keys": "0.16.0",
73
- "@dxos/log": "0.16.0",
74
- "@dxos/node-std": "0.16.0",
75
- "@dxos/protocols": "0.16.0",
76
- "@dxos/tracing": "0.16.0",
77
- "@dxos/util": "0.16.0"
77
+ "ws": "^8.17.1"
78
78
  },
79
79
  "devDependencies": {
80
- "@dxos/test-utils": "0.16.0"
80
+ "@dxos/test-utils": "0.17.0"
81
81
  },
82
82
  "peerDependencies": {
83
83
  "effect": "4.0.4"
@@ -25,6 +25,7 @@ import {
25
25
  } from '@dxos/protocols/buf/dxos/client/services_pb';
26
26
  import { type Message } from '@dxos/protocols/buf/dxos/edge/messenger_pb';
27
27
  import { trace } from '@dxos/tracing';
28
+ import { markMilestone } from '@dxos/util';
28
29
 
29
30
  import {
30
31
  authenticateViaChallengeEndpoint,
@@ -330,6 +331,7 @@ export class EdgeClient extends Resource implements EdgeConnection {
330
331
  return;
331
332
  }
332
333
  this._networkingStarted = true;
334
+ markMilestone('network.started');
333
335
  this._persistentLifecycle.open().catch((err) => {
334
336
  log.warn('Error while opening connection', { err });
335
337
  });
@@ -414,6 +416,7 @@ export class EdgeClient extends Resource implements EdgeConnection {
414
416
  {
415
417
  onConnected: () => {
416
418
  if (this._isActive(connection)) {
419
+ markMilestone('network.connected');
417
420
  this._ready.wake();
418
421
  this._notifyReconnected();
419
422
  } else {
@@ -6,12 +6,11 @@ import { create } from '@bufbuild/protobuf';
6
6
  import { afterEach, describe, it, test, vi } from 'vitest';
7
7
 
8
8
  import { Context } from '@dxos/context';
9
- import { SpaceId } from '@dxos/keys';
10
9
  import { EDGE_CLIENT_TOO_OLD, EdgeClientTooOldError, EdgeResponse } from '@dxos/protocols';
11
10
  import { type Presentation, PresentationSchema } from '@dxos/protocols/buf/dxos/halo/credentials_pb';
12
11
 
13
12
  import { createEphemeralEdgeIdentity } from './auth.ts';
14
- import { EdgeHttpClient } from './edge-http-client.ts';
13
+ import { EdgeHttpClient, formatPluginBundleLoad } from './edge-http-client.ts';
15
14
  import { type EdgeIdentity } from './edge-identity.ts';
16
15
 
17
16
  // TODO(burdon): Factor out config.
@@ -620,6 +619,46 @@ describe('EdgeHttpClient api key', () => {
620
619
  expect((uploadCall![1]?.headers as Record<string, string>).Authorization).toBe('Bearer secret-key');
621
620
  });
622
621
 
622
+ test('uploadPluginBundle streams the bundle as multipart, one part per file named by its path', async ({
623
+ expect,
624
+ }) => {
625
+ const fetchMock = vi.fn(
626
+ async (_input: any, _init?: RequestInit) =>
627
+ new Response(JSON.stringify({ success: true, data: { moduleUrl: 'url' } }), {
628
+ status: 200,
629
+ headers: { 'Content-Type': 'application/json' },
630
+ }),
631
+ );
632
+ vi.stubGlobal('fetch', fetchMock);
633
+
634
+ const client = new EdgeHttpClient('https://edge.example.com', { apiKey: 'secret-key' });
635
+ const content = new TextEncoder().encode('{}');
636
+ await client.uploadPluginBundle(
637
+ Context.default(),
638
+ {
639
+ slug: 'org.example.plugin',
640
+ version: '1.0.0',
641
+ channel: 'beta',
642
+ files: [{ path: 'vendor/manifest.json', content }],
643
+ },
644
+ { auth: false },
645
+ );
646
+
647
+ const [input, init] = fetchMock.mock.calls.find((call) => String(call[0]).includes('/registry/upload')) ?? [];
648
+ const url = new URL(String(input));
649
+ expect(url.pathname).toBe('/registry/upload/multipart');
650
+ expect(Object.fromEntries(url.searchParams)).toEqual({
651
+ slug: 'org.example.plugin',
652
+ version: '1.0.0',
653
+ channel: 'beta',
654
+ });
655
+ const body = init?.body;
656
+ expect(body).toBeInstanceOf(FormData);
657
+ const part = body instanceof FormData ? body.get('vendor/manifest.json') : null;
658
+ expect(part).toBeInstanceOf(Blob);
659
+ expect(part instanceof Blob ? await part.text() : undefined).toBe('{}');
660
+ });
661
+
623
662
  test('uploadPrivatePluginBundle posts to the private route with the key as a Bearer header', async ({ expect }) => {
624
663
  const fetchMock = vi.fn(
625
664
  async (_input: any, _init?: RequestInit) =>
@@ -736,63 +775,10 @@ describe('EdgeHttpClient inbox', () => {
736
775
  });
737
776
  });
738
777
 
739
- describe('EdgeHttpClient brain fact feeds', () => {
740
- afterEach(() => {
741
- vi.unstubAllGlobals();
742
- });
743
-
744
- const SPACE_ID = SpaceId.random();
745
- const FEED = `echo://${SPACE_ID}/01J00000000000000000000000`;
746
-
747
- test('calls the fact feed routes and decodes the feeds', async ({ expect }) => {
748
- const calls: { method?: string; path: string; body?: unknown }[] = [];
749
- vi.stubGlobal(
750
- 'fetch',
751
- vi.fn(async (input: any, init?: RequestInit) => {
752
- const url = new URL(String(input instanceof URL ? input : (input.url ?? input)));
753
- if (url.pathname === '/auth') {
754
- return new Response(null, { status: 200 });
755
- }
756
- calls.push({
757
- method: init?.method,
758
- path: `${url.pathname}${url.search}`,
759
- body: typeof init?.body === 'string' ? JSON.parse(init.body) : undefined,
760
- });
761
- return new Response(JSON.stringify({ success: true, data: { feeds: [FEED] } }), {
762
- status: 200,
763
- headers: { 'Content-Type': 'application/json' },
764
- });
765
- }),
766
- );
767
- const client = new EdgeHttpClient('https://edge.example.com');
768
- const ctx = Context.default();
769
- const agent = 'did:key:z6Mk';
770
- const base = `/compute/brain/${SPACE_ID}/${encodeURIComponent(agent)}/fact-feeds`;
771
-
772
- expect(await client.addBrainFactFeed(ctx, SPACE_ID, agent, FEED)).toEqual({ feeds: [FEED] });
773
- expect(await client.listBrainFactFeeds(ctx, SPACE_ID, agent)).toEqual({ feeds: [FEED] });
774
- await client.removeBrainFactFeed(ctx, SPACE_ID, agent, FEED);
775
-
776
- expect(calls.map(({ method, path }) => `${method} ${path}`)).toEqual([
777
- `POST ${base}`,
778
- `GET ${base}`,
779
- `DELETE ${base}?${new URLSearchParams({ feed: FEED })}`,
780
- ]);
781
- expect(calls[0].body).toEqual({ feed: FEED });
782
- });
783
-
784
- test('rejects a malformed answer', async ({ expect }) => {
785
- vi.stubGlobal(
786
- 'fetch',
787
- vi.fn(
788
- async () =>
789
- new Response(JSON.stringify({ success: true, data: { feeds: 'none' } }), {
790
- status: 200,
791
- headers: { 'Content-Type': 'application/json' },
792
- }),
793
- ),
778
+ describe('formatPluginBundleLoad', () => {
779
+ test('reports describe time and the JavaScript and WebAssembly bytes apart, in MB', ({ expect }) => {
780
+ expect(formatPluginBundleLoad({ describeMs: 3200, jsBytes: 11.5 * 1024 * 1024, wasmBytes: 2 * 1024 * 1024 })).toBe(
781
+ 'describe 3200 ms, js 11.5 MB, wasm 2.0 MB',
794
782
  );
795
- const client = new EdgeHttpClient('https://edge.example.com');
796
- await expect(client.listBrainFactFeeds(Context.default(), SPACE_ID, 'agent-1')).rejects.toThrow();
797
783
  });
798
784
  });
@@ -14,7 +14,7 @@ import * as Schema from 'effect/Schema';
14
14
  import { type Context } from '@dxos/context';
15
15
  import * as EffectEx from '@dxos/effect/EffectEx';
16
16
  import { invariant } from '@dxos/invariant';
17
- import { type SpaceId } from '@dxos/keys';
17
+ import { IdentityDid, SpaceId } from '@dxos/keys';
18
18
  import { log } from '@dxos/log';
19
19
  import { type ProcessProtocol } from '@dxos/protocols';
20
20
  import {
@@ -80,8 +80,48 @@ export type UploadPluginBundleRequest = {
80
80
  slug: string;
81
81
  version: string;
82
82
  files: { path: string; content: string }[];
83
+ /** A channel EDGE moves to this version besides `latest`, like an npm dist-tag. */
84
+ channel?: string;
83
85
  };
84
86
 
87
+ /** A built plugin bundle as bytes, one entry per file by its path in the bundle (`manifest.json`, `vendor/...`). */
88
+ export type PluginBundleUpload = {
89
+ slug: string;
90
+ version: string;
91
+ files: readonly { path: string; content: Uint8Array<ArrayBuffer> }[];
92
+ /** A channel EDGE moves to this version besides `latest`, like an npm dist-tag. */
93
+ channel?: string;
94
+ };
95
+
96
+ /** What loading a plugin bundle on EDGE cost when the registry described it. */
97
+ export type PluginBundleLoad = {
98
+ /** Milliseconds from EDGE asking Worker Loader for the isolate to the catalog arriving: compilation and activation. */
99
+ describeMs: number;
100
+ /** UTF-8 bytes of the JavaScript modules EDGE loads, after pruning what the bundle's EDGE modules never import. */
101
+ jsBytes: number;
102
+ /** Bytes of the WebAssembly modules EDGE loads. */
103
+ wasmBytes: number;
104
+ };
105
+
106
+ /** The registry's answer to a plugin bundle upload. */
107
+ export type PluginBundleUploadResult = {
108
+ moduleUrl: string;
109
+ /** What the EDGE index made of the bundle; absent for a bundle EDGE does not run, or a registry with no index. */
110
+ edge?: {
111
+ hash: string;
112
+ channels: string[];
113
+ operations: number;
114
+ /** Absent when the registry did not describe the bundle again: the same files were already uploaded. */
115
+ load?: PluginBundleLoad;
116
+ };
117
+ };
118
+
119
+ const MB = 1024 * 1024;
120
+
121
+ /** One line for a CLI: `describe 3200 ms, js 11.5 MB, wasm 0.0 MB`. */
122
+ export const formatPluginBundleLoad = ({ describeMs, jsBytes, wasmBytes }: PluginBundleLoad): string =>
123
+ `describe ${describeMs} ms, js ${(jsBytes / MB).toFixed(1)} MB, wasm ${(wasmBytes / MB).toFixed(1)} MB`;
124
+
85
125
  export type CreateApiTokenRequest = {
86
126
  label: string;
87
127
  /** Epoch milliseconds; the token never expires when omitted. */
@@ -153,9 +193,57 @@ export type EdgeHttpClientOptions = BaseHttpClientOptions;
153
193
  /** What `finalize` reports back: the content-addressed key the bytes landed under, and their size. */
154
194
  export type FinalizedUpload = { key: string; size: number; contentType?: string };
155
195
 
156
- /** What EDGE answers every brain fact feed route with: the EIDs of the fact feeds the brain indexes. */
157
- export const BrainFactFeeds = Schema.Struct({ feeds: Schema.Array(Schema.String) });
158
- export type BrainFactFeeds = Schema.Schema.Type<typeof BrainFactFeeds>;
196
+ /** What EDGE answers `GET /compute/brain/:agent` with, as far as clients read it. */
197
+ export const BrainInfo = Schema.Struct({
198
+ identity: Schema.Struct({ identityDid: Schema.String, label: Schema.String, defaultSpaceId: Schema.String }),
199
+ role: Schema.String,
200
+ });
201
+ export type BrainInfo = Schema.Schema.Type<typeof BrainInfo>;
202
+
203
+ /** What EDGE answers an added admin with: the identity keys of every admin of the agent. */
204
+ export const BrainAdmins = Schema.Struct({ adminKeys: Schema.Array(Schema.String) });
205
+ export type BrainAdmins = Schema.Schema.Type<typeof BrainAdmins>;
206
+
207
+ /** What EDGE answers `GET /compute/brain/:agent/halo` with: what an admin inspects of an agent's identity. */
208
+ export const AgentHalo = Schema.Struct({
209
+ identity: Schema.Struct({
210
+ identityDid: Schema.String,
211
+ identityKey: Schema.String,
212
+ agentKey: Schema.String,
213
+ defaultSpaceId: Schema.String,
214
+ homeSpaceId: Schema.String,
215
+ agent: Schema.String,
216
+ label: Schema.String,
217
+ }),
218
+ haloSpaceId: Schema.optional(Schema.String),
219
+ /** `null` for an agent provisioned before EDGE kept its admins. */
220
+ adminKeys: Schema.NullOr(Schema.Array(Schema.String)),
221
+ /** The spaces the agent's admins put it in. */
222
+ joinedSpaceIds: Schema.Array(Schema.String),
223
+ /** The spaces the agent holds a feed in, its HALO and default space included. */
224
+ memberSpaceIds: Schema.Array(Schema.String),
225
+ /** Every credential in the agent's HALO, each a base64 `Credential`. */
226
+ credentials: Schema.Array(Schema.String),
227
+ });
228
+ export type AgentHalo = Schema.Schema.Type<typeof AgentHalo>;
229
+
230
+ /** What a client asks `POST /compute/brain` for: an identity for the agent with this entity id. */
231
+ export type ProvisionBrainRequest = { agent: string; homeSpaceId: SpaceId; label: string };
232
+
233
+ /** What EDGE answers `POST /compute/brain` with: the brain's identity and the caller's membership of its space. */
234
+ export const ProvisionedBrain = Schema.Struct({
235
+ identity: Schema.Struct({
236
+ identityDid: IdentityDid,
237
+ identityKey: Schema.String,
238
+ defaultSpaceId: Schema.optional(SpaceId),
239
+ }),
240
+ /** The caller's `SpaceMember` credential for the agent's default space, base64 protobuf. */
241
+ membership: Schema.String,
242
+ });
243
+ export type ProvisionedBrain = Schema.Schema.Type<typeof ProvisionedBrain>;
244
+
245
+ /** EDGE route of an agent's mailbox. */
246
+ const mailboxPath = (handle: string): string => `/compute/email/mailboxes/${encodeURIComponent(handle)}`;
159
247
 
160
248
  /**
161
249
  * Validates the finalize response rather than asserting its shape.
@@ -199,7 +287,9 @@ export type EdgeAiService =
199
287
  | 'deepseek'
200
288
  | 'typesafe'
201
289
  /** TypeSafe's System One wire, answered by Workers AI's `typesafe/jev` on EDGE's Cloudflare account. */
202
- | 'workers-ai/typesafe';
290
+ | 'workers-ai/typesafe'
291
+ /** Cloudflare's Clairic extraction model on Workers AI, on EDGE's Cloudflare account. */
292
+ | 'workers-ai/clairic';
203
293
 
204
294
  export class EdgeHttpClient extends BaseHttpClient {
205
295
  constructor(baseUrl: string, options?: EdgeHttpClientOptions) {
@@ -229,6 +319,37 @@ export class EdgeHttpClient extends BaseHttpClient {
229
319
  return this._call<unknown>(ctx, new URL(path, this.baseUrl), { auth: true, ...rest, method, body });
230
320
  }
231
321
 
322
+ //
323
+ // Agent mailboxes
324
+ //
325
+ // The mailbox answers are plugin-agent's to decode (`AgentMailbox.MailboxStatus`, `AgentMailbox.SendResult`).
326
+ //
327
+
328
+ /** Claims the agent's mailbox `handle`, or updates the claim; answers its status. */
329
+ public async claimMailbox(ctx: Context, handle: string, body: unknown, args?: EdgeHttpCallArgs): Promise<unknown> {
330
+ return this.request(ctx, mailboxPath(handle), { ...args, method: 'PUT', body });
331
+ }
332
+
333
+ /** Releases the mailbox `handle`; answers its status. */
334
+ public async releaseMailbox(ctx: Context, handle: string, args?: EdgeHttpCallArgs): Promise<unknown> {
335
+ return this.request(ctx, mailboxPath(handle), { ...args, method: 'DELETE' });
336
+ }
337
+
338
+ /** The status of the mailbox `handle`. */
339
+ public async getMailbox(ctx: Context, handle: string, args?: EdgeHttpCallArgs): Promise<unknown> {
340
+ return this.request(ctx, mailboxPath(handle), { ...args, method: 'GET' });
341
+ }
342
+
343
+ /** Sends an email from the mailbox `handle`; answers what EDGE sent. */
344
+ public async sendMailboxEmail(
345
+ ctx: Context,
346
+ handle: string,
347
+ body: unknown,
348
+ args?: EdgeHttpCallArgs,
349
+ ): Promise<unknown> {
350
+ return this.request(ctx, `${mailboxPath(handle)}/send`, { ...args, method: 'POST', body });
351
+ }
352
+
232
353
  //
233
354
  // Agents
234
355
  //
@@ -318,6 +439,36 @@ export class EdgeHttpClient extends BaseHttpClient {
318
439
  });
319
440
  }
320
441
 
442
+ /**
443
+ * Asks edge to migrate a legacy space: edge mints the space root and credentials documents from the
444
+ * chain it already holds and returns the root in force. Idempotent and write-once, so every member
445
+ * that asks is handed the same root.
446
+ */
447
+ public async migrateSpaceRoot(
448
+ ctx: Context,
449
+ spaceId: SpaceId,
450
+ args?: EdgeHttpCallArgs,
451
+ ): Promise<{ rootDocumentUrl: string }> {
452
+ return this._call(ctx, new URL(`/db/spaces/${spaceId}/root`, this.baseUrl), {
453
+ ...args,
454
+ method: 'POST',
455
+ auth: true,
456
+ });
457
+ }
458
+
459
+ /** The space root edge has in force, or null while the space is still on its control feed. */
460
+ public async getSpaceRoot(
461
+ ctx: Context,
462
+ spaceId: SpaceId,
463
+ args?: EdgeHttpCallArgs,
464
+ ): Promise<{ rootDocumentUrl: string | null }> {
465
+ return this._call(ctx, new URL(`/db/spaces/${spaceId}/root`, this.baseUrl), {
466
+ ...args,
467
+ method: 'GET',
468
+ auth: true,
469
+ });
470
+ }
471
+
321
472
  //
322
473
  // Invitations (space join)
323
474
  //
@@ -672,10 +823,20 @@ export class EdgeHttpClient extends BaseHttpClient {
672
823
  });
673
824
  }
674
825
 
675
- public async forceRunCronTrigger(ctx: Context, spaceId: SpaceId, triggerId: ObjectId) {
826
+ /**
827
+ * Runs a cron trigger now. `data` becomes the fire event's `data`, which the trigger's
828
+ * `{{event.data.*}}` input templates read, and is kept across the run's `runAgain` continuations.
829
+ */
830
+ public async forceRunCronTrigger(
831
+ ctx: Context,
832
+ spaceId: SpaceId,
833
+ triggerId: ObjectId,
834
+ { data }: { data?: Record<string, unknown> } = {},
835
+ ) {
676
836
  return this._call(ctx, new URL(`/compute/functions/${spaceId}/triggers/crons/${triggerId}/run`, this.baseUrl), {
677
837
  method: 'POST',
678
838
  auth: true,
839
+ ...(data ? { body: { data } } : {}),
679
840
  });
680
841
  }
681
842
 
@@ -721,57 +882,55 @@ export class EdgeHttpClient extends BaseHttpClient {
721
882
  }
722
883
 
723
884
  //
724
- // Brain fact feeds
885
+ // Brains
725
886
  //
726
887
 
727
888
  /**
728
- * Has an agent's brain index a fact feed (its EID) from now on; answers the feeds it indexes. `agent` names the
729
- * brain (see plugin-agent's `AgentPresence.brainId`); the caller must be a member of `spaceId`, a space it serves.
889
+ * The identity EDGE minted for an agent's brain, and the caller's role on it. `agent` is the agent's DID; EDGE answers
890
+ * 404 to a caller with no role, as for a brain that does not exist.
730
891
  */
731
- public async addBrainFactFeed(
732
- ctx: Context,
733
- spaceId: SpaceId,
734
- agent: string,
735
- feed: string,
736
- args?: EdgeHttpCallArgs,
737
- ): Promise<BrainFactFeeds> {
738
- return this.#factFeedsCall(ctx, spaceId, agent, { ...args, method: 'POST', body: { feed } });
892
+ public async getBrain(ctx: Context, agent: string, args?: EdgeHttpCallArgs): Promise<BrainInfo> {
893
+ const url = new URL(`/compute/brain/${encodeURIComponent(agent)}`, this.baseUrl);
894
+ const response = await this._call(ctx, url, { ...args, method: 'GET', auth: true });
895
+ return Schema.decodeUnknownSync(BrainInfo)(response);
739
896
  }
740
897
 
741
- /** Stops an agent's brain indexing a fact feed; the facts it read stay. Answers the feeds it still indexes. */
742
- public async removeBrainFactFeed(
898
+ /** Gives the agent's brain an identity, for a caller who may write to its space; its creator asking again gets the same answer. */
899
+ public async provisionBrain(
743
900
  ctx: Context,
744
- spaceId: SpaceId,
745
- agent: string,
746
- feed: string,
901
+ body: ProvisionBrainRequest,
747
902
  args?: EdgeHttpCallArgs,
748
- ): Promise<BrainFactFeeds> {
749
- return this.#factFeedsCall(ctx, spaceId, agent, { ...args, method: 'DELETE' }, { feed });
903
+ ): Promise<ProvisionedBrain> {
904
+ const response = await this.request(ctx, '/compute/brain', { ...args, method: 'POST', body });
905
+ return Schema.decodeUnknownSync(ProvisionedBrain)(response);
750
906
  }
751
907
 
752
- /** The fact feeds an agent's brain indexes. */
753
- public async listBrainFactFeeds(
908
+ /** Puts the agent's brain in a space, which only its admins may do. `agent` is the agent's DID. */
909
+ public async addBrainSpace(ctx: Context, agent: string, spaceId: SpaceId, args?: EdgeHttpCallArgs): Promise<void> {
910
+ await this.request(ctx, `/compute/brain/${encodeURIComponent(agent)}/spaces`, {
911
+ ...args,
912
+ method: 'POST',
913
+ body: { spaceId },
914
+ });
915
+ }
916
+
917
+ /** Makes an identity an admin of an agent, which only an admin may do; nothing takes it away. Answers every admin. */
918
+ public async addBrainAdmin(
754
919
  ctx: Context,
755
- spaceId: SpaceId,
756
920
  agent: string,
921
+ identityKey: string,
757
922
  args?: EdgeHttpCallArgs,
758
- ): Promise<BrainFactFeeds> {
759
- return this.#factFeedsCall(ctx, spaceId, agent, { ...args, method: 'GET' });
923
+ ): Promise<BrainAdmins> {
924
+ const url = new URL(`/compute/brain/${encodeURIComponent(agent)}/admins`, this.baseUrl);
925
+ const response = await this._call(ctx, url, { ...args, method: 'POST', body: { identityKey }, auth: true });
926
+ return Schema.decodeUnknownSync(BrainAdmins)(response);
760
927
  }
761
928
 
762
- async #factFeedsCall(
763
- ctx: Context,
764
- spaceId: SpaceId,
765
- agent: string,
766
- args: EdgeHttpCallArgs & { method: string; body?: unknown },
767
- query: Record<string, string> = {},
768
- ): Promise<BrainFactFeeds> {
769
- const url = new URL(`/compute/brain/${spaceId}/${encodeURIComponent(agent)}/fact-feeds`, this.baseUrl);
770
- for (const [key, value] of Object.entries(query)) {
771
- url.searchParams.set(key, value);
772
- }
773
- const response = await this._call(ctx, url, { ...args, auth: true });
774
- return Schema.decodeUnknownSync(BrainFactFeeds)(response);
929
+ /** The agent's HALO, its admins and its spaces, which only its admins may read; EDGE answers anyone else 404. */
930
+ public async getAgentHalo(ctx: Context, agent: string, args?: EdgeHttpCallArgs): Promise<AgentHalo> {
931
+ const url = new URL(`/compute/brain/${encodeURIComponent(agent)}/halo`, this.baseUrl);
932
+ const response = await this._call(ctx, url, { ...args, method: 'GET', auth: true });
933
+ return Schema.decodeUnknownSync(AgentHalo)(response);
775
934
  }
776
935
 
777
936
  //
@@ -810,21 +969,27 @@ export class EdgeHttpClient extends BaseHttpClient {
810
969
  }
811
970
 
812
971
  /**
813
- * Uploads a built plugin bundle to the registry's R2-backed hosting. Authenticated
814
- * with the caller's hub identity (verifiable presentation) — `setIdentity` must
815
- * have been called. Returns the canonical `moduleUrl` (the hosted `manifest.json`).
972
+ * Uploads a built plugin bundle to the registry's R2-backed hosting as `multipart/form-data`, one part per file named
973
+ * by its path; EDGE streams the parts into storage, so the bundle never has to fit in a worker's memory. Authenticated
974
+ * with the caller's hub identity (verifiable presentation) — `setIdentity` must have been called. Returns the
975
+ * canonical `moduleUrl` (the hosted `manifest.json`).
816
976
  */
817
977
  public async uploadPluginBundle(
818
978
  ctx: Context,
819
- request: UploadPluginBundleRequest,
979
+ { slug, version, channel, files }: PluginBundleUpload,
820
980
  args?: EdgeHttpCallArgs,
821
- ): Promise<{ moduleUrl: string }> {
822
- return this._call(ctx, new URL('/registry/upload', this.baseUrl), {
823
- body: request,
824
- method: 'POST',
825
- auth: true,
826
- ...args,
827
- });
981
+ ): Promise<PluginBundleUploadResult> {
982
+ const url = new URL('/registry/upload/multipart', this.baseUrl);
983
+ url.searchParams.set('slug', slug);
984
+ url.searchParams.set('version', version);
985
+ if (channel) {
986
+ url.searchParams.set('channel', channel);
987
+ }
988
+ const form = new FormData();
989
+ for (const { path, content } of files) {
990
+ form.append(path, new Blob([content]), path);
991
+ }
992
+ return this._call(ctx, url, { body: form, method: 'POST', json: false, auth: true, ...args });
828
993
  }
829
994
 
830
995
  /**