@dxos/edge-client 0.8.4-staging.60fe92afc8 → 0.9.1-main.c7dcc2e112

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
  2. package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +7 -0
  3. package/dist/lib/neutral/cors-proxy.mjs +1 -0
  4. package/dist/lib/neutral/edge-ws-muxer.mjs +1 -0
  5. package/dist/lib/neutral/index.mjs +82 -7
  6. package/dist/lib/neutral/index.mjs.map +3 -3
  7. package/dist/lib/neutral/meta.json +1 -1
  8. package/dist/lib/neutral/service/index.mjs +134 -0
  9. package/dist/lib/neutral/service/index.mjs.map +7 -0
  10. package/dist/lib/neutral/testing/index.mjs +1 -0
  11. package/dist/lib/neutral/testing/index.mjs.map +1 -1
  12. package/dist/types/src/edge-ai-http-client.d.ts +39 -0
  13. package/dist/types/src/edge-ai-http-client.d.ts.map +1 -1
  14. package/dist/types/src/edge-ai-http-client.test.d.ts +2 -0
  15. package/dist/types/src/edge-ai-http-client.test.d.ts.map +1 -0
  16. package/dist/types/src/edge-http-client.d.ts +17 -2
  17. package/dist/types/src/edge-http-client.d.ts.map +1 -1
  18. package/dist/types/src/hub-http-client.d.ts +8 -1
  19. package/dist/types/src/hub-http-client.d.ts.map +1 -1
  20. package/dist/types/src/service/Image.d.ts +25 -0
  21. package/dist/types/src/service/Image.d.ts.map +1 -0
  22. package/dist/types/src/service/edge-service.d.ts +36 -0
  23. package/dist/types/src/service/edge-service.d.ts.map +1 -0
  24. package/dist/types/src/service/edge-service.test.d.ts +2 -0
  25. package/dist/types/src/service/edge-service.test.d.ts.map +1 -0
  26. package/dist/types/src/service/image-service.e2e.test.d.ts +2 -0
  27. package/dist/types/src/service/image-service.e2e.test.d.ts.map +1 -0
  28. package/dist/types/src/service/index.d.ts +3 -0
  29. package/dist/types/src/service/index.d.ts.map +1 -0
  30. package/dist/types/tsconfig.tsbuildinfo +1 -1
  31. package/package.json +20 -15
  32. package/src/edge-ai-http-client.test.ts +37 -0
  33. package/src/edge-ai-http-client.ts +87 -2
  34. package/src/edge-http-client.ts +18 -6
  35. package/src/hub-http-client.ts +20 -0
  36. package/src/service/Image.ts +61 -0
  37. package/src/service/edge-service.test.ts +151 -0
  38. package/src/service/edge-service.ts +139 -0
  39. package/src/service/image-service.e2e.test.ts +53 -0
  40. package/src/service/index.ts +7 -0
@@ -0,0 +1,10 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ export {
8
+ __export
9
+ };
10
+ //# sourceMappingURL=chunk-J5LGTIGS.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  proxyFetchLegacy
3
3
  } from "./chunk-WQKMEZJR.mjs";
4
+ import "./chunk-J5LGTIGS.mjs";
4
5
  export {
5
6
  proxyFetchLegacy
6
7
  };
@@ -3,6 +3,7 @@ import {
3
3
  CLOUDFLARE_RPC_MAX_BYTES,
4
4
  WebSocketMuxer
5
5
  } from "./chunk-L5ZHLJ4B.mjs";
6
+ import "./chunk-J5LGTIGS.mjs";
6
7
  export {
7
8
  CLOUDFLARE_MESSAGE_MAX_BYTES,
8
9
  CLOUDFLARE_RPC_MAX_BYTES,
@@ -10,6 +10,7 @@ import {
10
10
  protocol,
11
11
  toUint8Array
12
12
  } from "./chunk-L5ZHLJ4B.mjs";
13
+ import "./chunk-J5LGTIGS.mjs";
13
14
 
14
15
  // src/index.ts
15
16
  export * from "@dxos/protocols/buf/dxos/edge/messenger_pb";
@@ -934,7 +935,46 @@ var ByokError = class extends BaseError.extend("ByokError", "BYOK authentication
934
935
  });
935
936
  }
936
937
  };
938
+ var UsageQuotaExceededError = class extends BaseError.extend("UsageQuotaExceededError", "Usage quota exceeded") {
939
+ };
937
940
  var requestInitTagKey = "@effect/platform/FetchHttpClient/FetchOptions";
941
+ var isUserDefinedAnthropicTool = (tool) => tool.input_schema != null && typeof tool.input_schema === "object";
942
+ var patchAnthropicMessagesRequestBody = (body) => {
943
+ if (body == null) {
944
+ return body;
945
+ }
946
+ const decodeBody = () => {
947
+ if (typeof body === "string") {
948
+ return body;
949
+ }
950
+ if (body instanceof Uint8Array) {
951
+ return new TextDecoder().decode(body);
952
+ }
953
+ return void 0;
954
+ };
955
+ const text = decodeBody();
956
+ if (text == null) {
957
+ return body;
958
+ }
959
+ try {
960
+ const payload = JSON.parse(text);
961
+ if (!Array.isArray(payload.tools)) {
962
+ return body;
963
+ }
964
+ payload.tools = payload.tools.map((tool) => isUserDefinedAnthropicTool(tool) ? {
965
+ ...tool,
966
+ eager_input_streaming: true
967
+ } : tool);
968
+ const patched = JSON.stringify(payload);
969
+ return typeof body === "string" ? patched : new TextEncoder().encode(patched);
970
+ } catch {
971
+ return body;
972
+ }
973
+ };
974
+ var readStreamBody = (stream) => Effect2.promise(async () => {
975
+ const response = new Response(stream);
976
+ return await response.text();
977
+ });
938
978
  var EdgeAiHttpClient = class _EdgeAiHttpClient {
939
979
  static make = (getClient) => HttpClient.make((request, url, signal, fiber) => {
940
980
  const edgeClient = getClient();
@@ -947,13 +987,13 @@ var EdgeAiHttpClient = class _EdgeAiHttpClient {
947
987
  ...options,
948
988
  method: request.method,
949
989
  headers,
950
- body,
990
+ body: patchAnthropicMessagesRequestBody(body),
951
991
  signal
952
992
  })),
953
993
  catch: (cause) => {
954
994
  log5.error("Failed to fetch", {
955
995
  cause
956
- }, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 60, S: this });
996
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 106, S: this });
957
997
  return new HttpClientError.RequestError({
958
998
  request,
959
999
  reason: "Transport",
@@ -977,6 +1017,19 @@ var EdgeAiHttpClient = class _EdgeAiHttpClient {
977
1017
  })
978
1018
  }))));
979
1019
  }
1020
+ if (!carriedByok && response.status === 429) {
1021
+ return Effect2.tryPromise({
1022
+ try: () => response.clone().json(),
1023
+ catch: () => void 0
1024
+ }).pipe(Effect2.orElseSucceed(() => void 0), Effect2.flatMap((body2) => Effect2.fail(new HttpClientError.ResponseError({
1025
+ request,
1026
+ response: httpResponse,
1027
+ reason: "StatusCode",
1028
+ cause: new UsageQuotaExceededError({
1029
+ message: body2?.error?.message
1030
+ })
1031
+ }))));
1032
+ }
980
1033
  return Effect2.succeed(httpResponse);
981
1034
  }));
982
1035
  switch (request.body._tag) {
@@ -986,7 +1039,7 @@ var EdgeAiHttpClient = class _EdgeAiHttpClient {
986
1039
  case "FormData":
987
1040
  return send(request.body.formData);
988
1041
  case "Stream":
989
- return Stream.toReadableStreamEffect(request.body.stream).pipe(Effect2.flatMap(send));
1042
+ return Stream.toReadableStreamEffect(request.body.stream).pipe(Effect2.flatMap((readable) => readStreamBody(readable)), Effect2.flatMap((text) => send(text)));
990
1043
  }
991
1044
  return send(void 0);
992
1045
  });
@@ -1240,10 +1293,17 @@ var EdgeHttpClient = class extends BaseHttpClient {
1240
1293
  method: "GET"
1241
1294
  });
1242
1295
  }
1243
- async getRegistryPluginVersions(ctx, repo, args) {
1244
- return this._call(ctx, new URL(`/registry/plugins/${encodeURIComponent(repo)}/versions`, this.baseUrl), {
1245
- ...args,
1246
- method: "GET"
1296
+ /**
1297
+ * Uploads a built plugin bundle to the registry's R2-backed hosting. Authenticated
1298
+ * with the caller's hub identity (verifiable presentation) — `setIdentity` must
1299
+ * have been called. Returns the canonical `moduleUrl` (the hosted `manifest.json`).
1300
+ */
1301
+ async uploadPluginBundle(ctx, request, args) {
1302
+ return this._call(ctx, new URL("/registry/upload", this.baseUrl), {
1303
+ body: request,
1304
+ method: "POST",
1305
+ auth: true,
1306
+ ...args
1247
1307
  });
1248
1308
  }
1249
1309
  //
@@ -1334,6 +1394,7 @@ var getFileMimeType = (filename) => [
1334
1394
  ].some((ext) => filename.endsWith(ext)) ? "application/javascript+module" : filename.endsWith(".wasm") ? "application/wasm" : "application/octet-stream";
1335
1395
 
1336
1396
  // src/hub-http-client.ts
1397
+ import { createUrl as createUrl2 } from "@dxos/util";
1337
1398
  var HubHttpClient = class extends BaseHttpClient {
1338
1399
  constructor(hubUrl, options) {
1339
1400
  super(hubUrl, options);
@@ -1414,6 +1475,18 @@ var HubHttpClient = class extends BaseHttpClient {
1414
1475
  method: "POST"
1415
1476
  });
1416
1477
  }
1478
+ /**
1479
+ * Rolling-window usage and effective limits for the authenticated identity.
1480
+ * Served from the per-user metering DO; optional `windowSeconds` defaults to the largest limit window.
1481
+ */
1482
+ async getProfileUsage(ctx, query, args) {
1483
+ return this._call(ctx, createUrl2(new URL("/api/metering/profile/usage", this.baseUrl), {
1484
+ windowSeconds: query?.windowSeconds
1485
+ }), {
1486
+ ...args,
1487
+ method: "GET"
1488
+ });
1489
+ }
1417
1490
  };
1418
1491
  export {
1419
1492
  BaseHttpClient,
@@ -1428,6 +1501,7 @@ export {
1428
1501
  HttpConfig,
1429
1502
  HubHttpClient,
1430
1503
  Protocol,
1504
+ UsageQuotaExceededError,
1431
1505
  WebSocketMuxer,
1432
1506
  createChainEdgeIdentity,
1433
1507
  createDeviceEdgeIdentity,
@@ -1437,6 +1511,7 @@ export {
1437
1511
  encodeAuthHeader,
1438
1512
  getTypename,
1439
1513
  handleAuthChallenge,
1514
+ patchAnthropicMessagesRequestBody,
1440
1515
  protocol,
1441
1516
  proxyFetchLegacy,
1442
1517
  requestInitTagKey,