@linxin666/dsh-remote-bridge 0.4.21 → 0.4.22

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/lib/index.js CHANGED
@@ -11913,16 +11913,39 @@ function makePairTokenRoute(deps) {
11913
11913
  };
11914
11914
  }
11915
11915
  //#endregion
11916
- //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-typert-protocol@0.2.2-rc.3_@deepseek-ai+cordis@4.1.0/node_modules/@deepseek-ai/dsh-typert-protocol/lib/index.js
11916
+ //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-error@0.2.3-alpha.2_@deepseek-ai+cordis@4.2.0-alpha.1/node_modules/@deepseek-ai/dsh-error/lib/index.js
11917
+ /**
11918
+ * Harness error base with a stable machine-routable code and chained cause.
11919
+ * Package errors extend it so tool results and replay can retain failure class.
11920
+ * @module @deepseek-ai/dsh-error
11921
+ */
11922
+ /**
11923
+ * Base class for all harness errors. Carries a `code` (stable, programmatic —
11924
+ * e.g. `NO_ADAPTER`, `INVALID_ARGS`) distinct from the
11925
+ * human-readable `message`, and supports `cause` chaining via the standard
11926
+ * `ErrorOptions`. `name` defaults to the subclass constructor name.
11927
+ */
11928
+ var HarnessError = class extends Error {
11929
+ /** Stable machine-routable failure class (e.g. `RATE_LIMIT`); route on this, never by parsing `message`. */
11930
+ code;
11931
+ constructor(message, code, options) {
11932
+ super(message, options);
11933
+ this.code = code;
11934
+ this.name = new.target.name;
11935
+ }
11936
+ };
11937
+ //#endregion
11938
+ //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-typert-protocol@0.2.3-alpha.2_@deepseek-ai+cordis@4.2.0-alpha.1_@deeps_6153b0a06151bba505d5f32876686bf8/node_modules/@deepseek-ai/dsh-typert-protocol/lib/index.js
11917
11939
  /** The one Remote failure class shared by owners, the Gateway, and consumers. */
11918
11940
  /**
11919
- * One Remote call failure: a real Error carrying its stable code and typed
11941
+ * One Remote call failure: a `HarnessError` carrying its stable code and typed
11920
11942
  * details. Owners throw it at the failure point; the Host Gateway encodes it
11921
11943
  * onto the wire unchanged; the Client face rebuilds an instance for the
11922
11944
  * `RemoteResult` error branch, so `throw result.error` keeps throw semantics.
11923
- * Discrimination is always by `code`, never by instanceof.
11945
+ * A tool body that throws it records `name: 'RemoteError'` and its Remote code
11946
+ * on `tool/result`. Discrimination is always by `code`, never by instanceof.
11924
11947
  */
11925
- var RemoteError = class extends Error {
11948
+ var RemoteError = class extends HarnessError {
11926
11949
  code;
11927
11950
  details;
11928
11951
  /** Structural marker: cross-realm/bundle identification never uses instanceof. */
@@ -11934,7 +11957,7 @@ var RemoteError = class extends Error {
11934
11957
  * @param options - standard Error options (`cause` survives in-process only).
11935
11958
  */
11936
11959
  constructor(code, message, details, options) {
11937
- super(message, options);
11960
+ super(message, code, options);
11938
11961
  this.code = code;
11939
11962
  this.details = details;
11940
11963
  this.name = "RemoteError";
@@ -12000,8 +12023,8 @@ var TypertRemoteService = class extends Service {
12000
12023
  * tree registers it on the root, where it outlives any one Service.
12001
12024
  */
12002
12025
  function provideInvocationAccessor(ctx) {
12003
- if (Object.hasOwn(ctx.root.reflect.props, "invocation")) return;
12004
- ctx.root.accessor("invocation", { get: () => void 0 });
12026
+ if (Object.hasOwn(ctx[Context.root].reflect.props, "invocation")) return;
12027
+ ctx[Context.root].accessor("invocation", { get: () => void 0 });
12005
12028
  }
12006
12029
  function Remote(methodExportOrOptions, context) {
12007
12030
  if (typeof methodExportOrOptions === "string") {
@@ -12095,7 +12118,7 @@ function validateName(subject, value) {
12095
12118
  if (!isTypertRemoteSegment(value)) throw new TypeError(`typert-protocol: ${subject} must contain only RPC endpoint segment characters`);
12096
12119
  }
12097
12120
  //#endregion
12098
- //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-util-values@0.2.2-rc.3_@deepseek-ai+cordis@4.1.0/node_modules/@deepseek-ai/dsh-util-values/lib/index.js
12121
+ //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-util-values@0.2.3-alpha.2_@deepseek-ai+cordis@4.2.0-alpha.1/node_modules/@deepseek-ai/dsh-util-values/lib/index.js
12099
12122
  /**
12100
12123
  * Lazily scanned view of one JSON object's top-level fields, built from text
12101
12124
  * that may still be streaming or from an already parsed object. Nothing is
@@ -12914,7 +12937,7 @@ function deepFreeze(value) {
12914
12937
  return value;
12915
12938
  }
12916
12939
  //#endregion
12917
- //#region ../../node_modules/.pnpm/@deepseek-ai+cosmokit@1.9.0/node_modules/@deepseek-ai/cosmokit/lib/index.js
12940
+ //#region ../../node_modules/.pnpm/@deepseek-ai+cosmokit@1.10.0-alpha.1/node_modules/@deepseek-ai/cosmokit/lib/index.js
12918
12941
  /** Return true when a value is `null` or `undefined`. */
12919
12942
  function isNullable(value) {
12920
12943
  return value === null || value === void 0;
@@ -13168,7 +13191,7 @@ var Time;
13168
13191
  Time.template = template;
13169
13192
  })(Time || (Time = {}));
13170
13193
  //#endregion
13171
- //#region ../../node_modules/.pnpm/@deepseek-ai+schemastery@3.19.0/node_modules/@deepseek-ai/schemastery/lib/index.mjs
13194
+ //#region ../../node_modules/.pnpm/@deepseek-ai+schemastery@3.20.0-alpha.1/node_modules/@deepseek-ai/schemastery/lib/index.mjs
13172
13195
  const kSchema = Symbol.for("schemastery");
13173
13196
  const kValidationError = Symbol.for("ValidationError");
13174
13197
  globalThis.__schemastery_index__ ??= 0;
@@ -13801,41 +13824,11 @@ defineMethod("transform", [
13801
13824
  "preserve"
13802
13825
  ], ({ inner }, isInner) => inner.toString(isInner));
13803
13826
  //#endregion
13804
- //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-timeout@0.2.2-rc.3_@deepseek-ai+cordis@4.1.0/node_modules/@deepseek-ai/dsh-timeout/lib/index.js
13827
+ //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-timeout@0.2.3-alpha.2_@deepseek-ai+cordis@4.2.0-alpha.1/node_modules/@deepseek-ai/dsh-timeout/lib/index.js
13805
13828
  /** Largest delay Node schedules without clamping it to one millisecond. */
13806
13829
  const MAX_TIMER_DELAY_MS = 2147483647;
13807
13830
  //#endregion
13808
- //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-error@0.2.2-rc.3_@deepseek-ai+cordis@4.1.0/node_modules/@deepseek-ai/dsh-error/lib/index.js
13809
- /**
13810
- * Harness error base with a stable machine-routable code and chained cause.
13811
- * Package errors extend it so tool results and replay can retain failure class.
13812
- * @module @deepseek-ai/dsh-error
13813
- */
13814
- /**
13815
- * Base class for all harness errors. Carries a `code` (stable, programmatic —
13816
- * e.g. `NO_ADAPTER`, `INVALID_ARGS`) distinct from the
13817
- * human-readable `message`, and supports `cause` chaining via the standard
13818
- * `ErrorOptions`. `name` defaults to the subclass constructor name.
13819
- */
13820
- var HarnessError = class extends Error {
13821
- /** Stable machine-routable failure class (e.g. `RATE_LIMIT`); route on this, never by parsing `message`. */
13822
- code;
13823
- constructor(message, code, options) {
13824
- super(message, options);
13825
- this.code = code;
13826
- this.name = new.target.name;
13827
- }
13828
- };
13829
- //#endregion
13830
- //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-llm@0.2.2-rc.3_@deepseek-ai+cordis@4.1.0_@deepseek-ai+dsh-error@0.2.2-rc.3_@deepseek-ai+cordis@4.1.0_/node_modules/@deepseek-ai/dsh-llm/lib/index.js
13831
- /**
13832
- * Detach and deep-freeze a message whose identity already exists.
13833
- * @param message - complete message, including its stable identity.
13834
- * @returns an immutable snapshot that preserves the identity.
13835
- */
13836
- function freezeMessage(message) {
13837
- return deepFreeze(structuredClone(message));
13838
- }
13831
+ //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-llm@0.2.3-alpha.2_@deepseek-ai+cordis@4.2.0-alpha.1_@deepseek-ai+dsh-e_3734babba1c9d85ae3e99b1bc6b8c6ed/node_modules/@deepseek-ai/dsh-llm/lib/index.js
13839
13832
  /**
13840
13833
  * LLM failure codes and helpers over the shared Harness error base. The base
13841
13834
  * class lives in `@deepseek-ai/dsh-error` and is re-exported here, so both
@@ -13854,6 +13847,7 @@ const LLM_FAILURE_CODES = {
13854
13847
  ACCOUNT_TOKEN_INVALID: {},
13855
13848
  AUTH: {},
13856
13849
  CLIENT_UPGRADE_REQUIRED: {},
13850
+ CONTENT_REFUSED: {},
13857
13851
  CONTEXT_WINDOW_EXCEEDED: {},
13858
13852
  DISCOVERY_FAILED: {},
13859
13853
  DISCOVERY_UNSUPPORTED: {},
@@ -13917,6 +13911,14 @@ new RegExp(String.raw`(?:^|[^a-z0-9])context[\s_-](?:length|window)[\s_-]` + Str
13917
13911
  new RegExp(String.raw`\b(?:request|prompt|input|messages?)\s+(?:is\s+|are\s+)?` + String.raw`too\s+(?:large|long)\s+for\s+(?:(?:this|the)\s+)?` + String.raw`(?:model(?:'s)?\s+)?context(?:\s+window)?\b`, "i");
13918
13912
  new RegExp(String.raw`\b(?:input|prompt|request|messages?)\b.{0,40}` + String.raw`\b(?:exceed(?:s|ed)?|overflows?|is\s+larger\s+than)\b.{0,40}` + String.raw`\b(?:the\s+)?(?:model(?:'s)?\s+)?context(?:\s+(?:length|window))?\b`, "i");
13919
13913
  /**
13914
+ * Detach and deep-freeze a message whose identity already exists.
13915
+ * @param message - complete message, including its stable identity.
13916
+ * @returns an immutable snapshot that preserves the identity.
13917
+ */
13918
+ function freezeMessage(message) {
13919
+ return deepFreeze(structuredClone(message));
13920
+ }
13921
+ /**
13920
13922
  * Provider-owned request-retry policy configuration and resolution.
13921
13923
  *
13922
13924
  * Adapters expose one resolved policy per registered provider route; the
@@ -14110,10 +14112,11 @@ function failureSnapshot(value) {
14110
14112
  }
14111
14113
  /** Read an SDK error message without letting an accessor replace the primary failure. */
14112
14114
  function errorMessage(error) {
14115
+ let message;
14113
14116
  try {
14114
- const message = error.message;
14115
- if (typeof message === "string" && message.length > 0) return message;
14117
+ message = error.message;
14116
14118
  } catch (_sdkMessageGetter) {}
14119
+ if (typeof message === "string" && message.length > 0) return message;
14117
14120
  return "LLM adapter failed";
14118
14121
  }
14119
14122
  /** Trust only Harness-owned codes; third-party SDK codes are not our taxonomy. */
@@ -14723,7 +14726,7 @@ var LlmError = class LlmError extends HarnessError {
14723
14726
  * @param provider - registered provider route.
14724
14727
  * @param model - exact model id.
14725
14728
  * @param image - normalized image reference.
14726
- * @returns dimensions and byte target used by the adapter's request serializer.
14729
+ * @returns maximum dimensions and byte budgets used by the request serializer; readImageRequest returns the actual encoded dimensions.
14727
14730
  */
14728
14731
  imageRequestTarget(provider, model, image) {
14729
14732
  return this.registration(provider).adapter.imageRequestTarget(provider, model, image);
@@ -15096,7 +15099,7 @@ function detachDirectoryEntry(entry) {
15096
15099
  };
15097
15100
  }
15098
15101
  //#endregion
15099
- //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-tools@0.2.2-rc.3_c6df380a2007cdef080fa53578fb6f5f/node_modules/@deepseek-ai/dsh-tools/lib/shared-DGx6D7zk.js
15102
+ //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-tools@0.2.3-alpha.2_fe5258332cf8d58c43bca084c938026e/node_modules/@deepseek-ai/dsh-tools/lib/shared-DGx6D7zk.js
15100
15103
  /** The selected provider is missing or unloaded; another provider must not take its calls. */
15101
15104
  var ToolExecutorUnavailableError = class extends HarnessError {
15102
15105
  constructor() {
@@ -15633,7 +15636,7 @@ var ToolActivationError = class extends HarnessError {
15633
15636
  }
15634
15637
  };
15635
15638
  //#endregion
15636
- //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-scope@0.2.2-rc.3_@deepseek-ai+cordis@4.1.0/node_modules/@deepseek-ai/dsh-scope/lib/index.js
15639
+ //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-scope@0.2.3-alpha.2_@deepseek-ai+cordis@4.2.0-alpha.1/node_modules/@deepseek-ai/dsh-scope/lib/index.js
15637
15640
  /**
15638
15641
  * Shared insertion-ordered storage and effect ownership for scope-aware registries.
15639
15642
  *
@@ -15886,7 +15889,7 @@ function scopeOf(ctx) {
15886
15889
  return ctx[kScope];
15887
15890
  }
15888
15891
  //#endregion
15889
- //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-tools@0.2.2-rc.3_c6df380a2007cdef080fa53578fb6f5f/node_modules/@deepseek-ai/dsh-tools/lib/index.js
15892
+ //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-tools@0.2.3-alpha.2_fe5258332cf8d58c43bca084c938026e/node_modules/@deepseek-ai/dsh-tools/lib/index.js
15890
15893
  /** Unified JSON-value schema DSL, inference, compilation, and tool definition helpers. @module dsh-tools/schema */
15891
15894
  const ANNOTATION_KEYS = [
15892
15895
  "description",
@@ -16462,6 +16465,7 @@ var GuardLayer = class {
16462
16465
  /**
16463
16466
  * Provide the executor for the calling scope; an unscoped contribution is the deployment default.
16464
16467
  * Rendering any executor-owned section requires the viewing scope's selection to remain available.
16468
+ * Disposal retires its sections; a replacement's same-name sections supersede those notices.
16465
16469
  * @param executor - initialized provider owned by the contributing plugin.
16466
16470
  * @returns the effect disposer. Unloading leaves the selection unavailable until it is replaced.
16467
16471
  */
@@ -28433,7 +28437,7 @@ var require_negotiator = /* @__PURE__ */ __commonJSMin(((exports, module) => {
28433
28437
  Negotiator.prototype.preferredMediaTypes = Negotiator.prototype.mediaTypes;
28434
28438
  }));
28435
28439
  //#endregion
28436
- //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-host-webserver@0.2.2-rc.3_@deepseek-ai+cordis@4.1.0_supports-color@7.2.0/node_modules/@deepseek-ai/dsh-host-webserver/lib/index.js
28440
+ //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-host-webserver@0.2.3-alpha.2_@deepseek-ai+cordis@4.2.0-alpha.1_supports-color@7.2.0/node_modules/@deepseek-ai/dsh-host-webserver/lib/index.js
28437
28441
  var lib_exports = /* @__PURE__ */ __exportAll({
28438
28442
  WebServer: () => WebServer,
28439
28443
  bindUrlHost: () => bindUrlHost,
@@ -28542,6 +28546,8 @@ function renderIndexInjections(html, rows) {
28542
28546
  * Route handlers retain direct response ownership; a route or the fallback may
28543
28547
  * instead give a resource, which maps a Fetch `Request` to a `Response` and
28544
28548
  * also answers in-process reads.
28549
+ * WebServer events use the instance as their subject: ordinary listeners follow
28550
+ * its webServer isolation, while explicitly global listeners receive every instance.
28545
28551
  */
28546
28552
  const DEFAULT_COMPRESSION = "none";
28547
28553
  const DEFAULT_COMPRESSION_LEVEL = 1;
@@ -28728,7 +28734,8 @@ async function writeResponse(res, response, head, signal) {
28728
28734
  * initialization, and the boot process reports the failed fiber. Route
28729
28735
  * registration order does not affect requests because configured named routes
28730
28736
  * must be distinct, and a request no named route matches is answered 404
28731
- * until the fallback owner registers.
28737
+ * until the fallback owner registers. HTTP and upgrade admission refusals
28738
+ * carry `Cache-Control: no-store`.
28732
28739
  */
28733
28740
  var WebServer = class extends Service {
28734
28741
  config;
@@ -28834,12 +28841,12 @@ var WebServer = class extends Service {
28834
28841
  * composition). One owner only — a second registration throws, because two
28835
28842
  * fallbacks cannot compose.
28836
28843
  * @param fallback - a handler owning the full response lifecycle of
28837
- * unmatched requests, or `{ resource }` answering them.
28844
+ * unmatched requests, or an object declaring `handler` or `resource` and auth.
28838
28845
  * @returns the disposer releasing the seat.
28839
28846
  */
28840
28847
  registerFallback(fallback) {
28841
28848
  if (this.fallback !== void 0) throw new Error("webserver: fallback already registered");
28842
- this.fallback = fallback;
28849
+ this.fallback = typeof fallback === "function" ? { handler: fallback } : fallback;
28843
28850
  return () => {
28844
28851
  this.fallback = void 0;
28845
28852
  };
@@ -28850,6 +28857,7 @@ var WebServer = class extends Service {
28850
28857
  * path picks the responder by the HTTP match order — exact, longest prefix,
28851
28858
  * then the fallback — and only a resource answers. This method checks no
28852
28859
  * cookie, Host, or Origin: the caller admits the reader before reading.
28860
+ * A resolved deny policy returns 403 even for an explicitly admitted Peer.
28853
28861
  * @param request - the read; its URL path selects the responder.
28854
28862
  * @param peer - the Peer the read speaks for, passed to the resource.
28855
28863
  * @returns the resource's response, without a body for HEAD as over HTTP;
@@ -28864,8 +28872,16 @@ var WebServer = class extends Service {
28864
28872
  status: 405,
28865
28873
  headers: { allow: RESOURCE_METHODS }
28866
28874
  });
28867
- const responder = this.responderFor(new URL(request.url).pathname);
28868
- if (typeof responder !== "object" || !("resource" in responder)) return new Response(null, { status: 404 });
28875
+ const url = new URL(request.url);
28876
+ const responder = this.responderFor(url.pathname);
28877
+ if (responder === void 0 || !("resource" in responder)) return new Response(null, { status: 404 });
28878
+ if (this.authPolicy(responder.auth, {
28879
+ headers: request.headers,
28880
+ method: request.method,
28881
+ url,
28882
+ transport: "http",
28883
+ signal: request.signal
28884
+ }) === "deny") return new Response(null, { status: 403 });
28869
28885
  const response = await responder.resource(request, peer);
28870
28886
  if (request.method === "GET") return response;
28871
28887
  await response.body?.cancel();
@@ -28901,13 +28917,45 @@ var WebServer = class extends Service {
28901
28917
  res.end();
28902
28918
  return;
28903
28919
  }
28904
- if (typeof responder === "function") await responder(req, res);
28905
- else if ("resource" in responder) await this.serveResource(req, res, target, responder.resource);
28906
- else await responder.handler(req, res);
28920
+ const abort = new AbortController();
28921
+ const cleanup = () => {
28922
+ res.off("close", onClose);
28923
+ res.off("finish", cleanup);
28924
+ };
28925
+ const onClose = () => {
28926
+ abort.abort();
28927
+ cleanup();
28928
+ };
28929
+ res.once("close", onClose);
28930
+ res.once("finish", cleanup);
28931
+ try {
28932
+ const request = {
28933
+ headers: req.headers,
28934
+ method: req.method,
28935
+ url: target,
28936
+ transport: "http",
28937
+ signal: abort.signal,
28938
+ socket: req.socket
28939
+ };
28940
+ const admission = this.authorize(request, responder.auth);
28941
+ if (abort.signal.aborted || request.socket?.destroyed) return;
28942
+ if (admission.kind === "deny") {
28943
+ res.writeHead(admission.status, { "Cache-Control": "no-store" });
28944
+ res.end(admission.status === 401 ? "unauthorized" : admission.status === 503 ? "authentication unavailable" : "forbidden");
28945
+ return;
28946
+ }
28947
+ if ("resource" in responder) await this.serveResource(req, res, target, responder.resource, abort.signal, admission.peer);
28948
+ else await responder.handler(req, res, admission.peer);
28949
+ } finally {
28950
+ if (res.writableEnded || abort.signal.aborted) cleanup();
28951
+ }
28907
28952
  };
28908
28953
  const listener = (req, res) => {
28909
28954
  const next = () => {
28910
- handle(req, res).catch((err) => {
28955
+ const dispatch = async () => {
28956
+ await this.ctx.waterfall(this, "webserver/request", req, res, () => handle(req, res));
28957
+ };
28958
+ dispatch().catch((err) => {
28911
28959
  this.ctx.logger.warn(err instanceof Error ? err : new Error(String(err)));
28912
28960
  if (res.headersSent) {
28913
28961
  res.destroy();
@@ -28953,9 +29001,11 @@ var WebServer = class extends Service {
28953
29001
  this.upgradedSockets.delete(socket);
28954
29002
  });
28955
29003
  let route;
29004
+ let target;
28956
29005
  try {
28957
29006
  /* v8 ignore next -- node:http always sets url on server requests. */
28958
- route = this.upgrades.get(new URL(req.url ?? "/", "http://x").pathname);
29007
+ target = new URL(req.url ?? "/", "http://x");
29008
+ route = this.upgrades.get(target.pathname);
28959
29009
  } catch (error) {
28960
29010
  this.ctx.logger.warn(error instanceof Error ? error : new Error(String(error)));
28961
29011
  socket.destroy();
@@ -28966,8 +29016,36 @@ var WebServer = class extends Service {
28966
29016
  return;
28967
29017
  }
28968
29018
  this.upgradedSockets.add(socket);
29019
+ const abort = new AbortController();
29020
+ socket.once("close", () => {
29021
+ abort.abort();
29022
+ });
28969
29023
  try {
28970
- Promise.resolve(route.handler(req, socket, head)).catch((error) => {
29024
+ const admission = this.authorize({
29025
+ headers: req.headers,
29026
+ method: req.method,
29027
+ url: target,
29028
+ transport: "upgrade",
29029
+ signal: abort.signal,
29030
+ socket
29031
+ }, route.auth);
29032
+ if (abort.signal.aborted || socket.destroyed) return;
29033
+ if (admission.kind === "deny") {
29034
+ const reason = {
29035
+ 401: "Unauthorized",
29036
+ 403: "Forbidden",
29037
+ 503: "Service Unavailable"
29038
+ }[admission.status];
29039
+ const body = reason.toLowerCase();
29040
+ socket.end(`HTTP/1.1 ${String(admission.status)} ${reason}\r\nConnection: close\r\nCache-Control: no-store\r\nContent-Type: text/plain; charset=utf-8\r\nContent-Length: ${String(Buffer.byteLength(body))}\r\n\r\n${body}`);
29041
+ return;
29042
+ }
29043
+ const dispatch = async () => {
29044
+ await this.ctx.waterfall(this, "webserver/upgrade", req, socket, head, admission.peer, async () => {
29045
+ if (!socket.destroyed) await route.handler(req, socket, head, admission.peer);
29046
+ });
29047
+ };
29048
+ dispatch().catch((error) => {
28971
29049
  this.ctx.logger.warn(error instanceof Error ? error : new Error(String(error)));
28972
29050
  socket.destroy();
28973
29051
  });
@@ -29011,6 +29089,31 @@ var WebServer = class extends Service {
29011
29089
  responderFor(pathname) {
29012
29090
  return this.match(pathname) ?? this.fallback;
29013
29091
  }
29092
+ authPolicy(auth, request) {
29093
+ return typeof auth === "function" ? auth(request) : auth ?? "required";
29094
+ }
29095
+ authorize(request, auth) {
29096
+ const policy = this.authPolicy(auth, request);
29097
+ if (policy === "deny") return {
29098
+ kind: "deny",
29099
+ status: 403
29100
+ };
29101
+ const admission = this.ctx.bail(this, "webserver/authorize", request, policy) ?? (policy === "anonymous" ? { kind: "allow" } : {
29102
+ kind: "deny",
29103
+ status: 503
29104
+ });
29105
+ if (admission.kind === "allow") {
29106
+ if (policy === "required" && admission.peer === void 0) return {
29107
+ kind: "deny",
29108
+ status: 503
29109
+ };
29110
+ if (admission.peer?.signal.aborted) return {
29111
+ kind: "deny",
29112
+ status: 401
29113
+ };
29114
+ }
29115
+ return admission;
29116
+ }
29014
29117
  /** Longest-prefix-wins over the prefix table after an exact-table miss. */
29015
29118
  match(pathname) {
29016
29119
  const exact = this.exact.get(pathname);
@@ -29025,13 +29128,13 @@ var WebServer = class extends Service {
29025
29128
  /**
29026
29129
  * Answer one HTTP exchange from a resource. Only GET and HEAD reach it;
29027
29130
  * any other method receives 405 and its request body is never read. The
29028
- * request becomes a Fetch `Request` without a Peer whose URL is the request
29131
+ * request becomes a Fetch `Request` whose URL is the request
29029
29132
  * target resolved against a placeholder origin, as the match reads it; the
29030
29133
  * client's authority stays only in the `host` header. The connection
29031
29134
  * closing before this method ends the response aborts the request signal
29032
29135
  * and cancels the response body.
29033
29136
  */
29034
- async serveResource(req, res, target, resource) {
29137
+ async serveResource(req, res, target, resource, signal, peer) {
29035
29138
  if (req.method !== "GET" && req.method !== "HEAD") {
29036
29139
  res.writeHead(405, { allow: RESOURCE_METHODS });
29037
29140
  res.end();
@@ -29039,25 +29142,12 @@ var WebServer = class extends Service {
29039
29142
  }
29040
29143
  const headers = new Headers();
29041
29144
  for (const [name, value] of Object.entries(req.headers)) for (const item of typeof value === "string" ? [value] : value ?? []) headers.append(name, item);
29042
- const abort = new AbortController();
29043
- let ended = false;
29044
- const onClose = () => {
29045
- if (!ended) abort.abort();
29046
- };
29047
- res.on("close", onClose);
29048
- try {
29049
- await writeResponse(res, await resource(new Request(target, {
29050
- method: req.method,
29051
- headers,
29052
- signal: abort.signal
29053
- })), req.method === "HEAD", abort.signal);
29054
- if (!abort.signal.aborted) {
29055
- ended = true;
29056
- res.end();
29057
- }
29058
- } finally {
29059
- res.off("close", onClose);
29060
- }
29145
+ await writeResponse(res, await resource(new Request(target, {
29146
+ method: req.method,
29147
+ headers,
29148
+ signal
29149
+ }), peer), req.method === "HEAD", signal);
29150
+ if (!signal.aborted) res.end();
29061
29151
  }
29062
29152
  /**
29063
29153
  * Run an index.html body through the registered taps in registration order
@@ -29080,7 +29170,7 @@ var WebServer = class extends Service {
29080
29170
  */
29081
29171
  collectIndexInjections(peer) {
29082
29172
  const table = [];
29083
- this.ctx.emit("webserver/index-inject", table, peer);
29173
+ this.ctx.emit(this, "webserver/index-inject", table, peer);
29084
29174
  return table;
29085
29175
  }
29086
29176
  /**
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@linxin666/dsh-remote-bridge",
3
3
  "description": "DSH remote bridge: the host half serves protocol v1 over one exact /ios/v1 WebSocket route — session roster, history baseline, prompting, live turn increments with tool activity, interrupt, and in-process agent approval — to a device paired by a one-shot bootstrap token and a P-256 challenge-response, with the token endpoint admitted only from this machine; the browser half adds one sidebar-foot panel that shows that same one-shot token as a QR symbol and draws an interactive card inside the tool row without answering it, and adds no wire surface",
4
- "version": "0.4.21",
4
+ "version": "0.4.22",
5
5
  "icon": "./icon.svg",
6
6
  "type": "module",
7
7
  "engines": {
8
- "node": ">=24.9.0"
8
+ "node": "^24.22.3 || >=26.13.1"
9
9
  },
10
10
  "main": "lib/index.js",
11
11
  "types": "lib/types/index.d.ts",
@@ -37,7 +37,7 @@
37
37
  "license": "Apache-2.0",
38
38
  "dsh": {
39
39
  "engines": {
40
- "dsh": ">=0.2.2-rc.3"
40
+ "dsh": ">=0.2.3-alpha.2"
41
41
  },
42
42
  "bundle": {
43
43
  "patch": "./cordis.patch.yml"
@@ -57,23 +57,23 @@
57
57
  "yaml": "^2.8.2"
58
58
  },
59
59
  "peerDependencies": {
60
- "@deepseek-ai/dsh": ">=0.2.2-rc.3",
60
+ "@deepseek-ai/dsh": ">=0.2.3-alpha.2",
61
61
  "react": "^18.2.0",
62
62
  "react-dom": "^18.2.0"
63
63
  },
64
64
  "devDependencies": {
65
- "@deepseek-ai/cordis": "^4.1.0",
66
- "@deepseek-ai/dsh-api-gateway": "^0.2.2-rc.3",
67
- "@deepseek-ai/dsh-client-locale": "^0.2.2-rc.3",
68
- "@deepseek-ai/dsh-client-ui-primitives": "^0.2.2-rc.3",
69
- "@deepseek-ai/dsh-client-ui-renderer": "^0.2.2-rc.3",
70
- "@deepseek-ai/dsh-client-ui-sidebar": "^0.2.2-rc.3",
71
- "@deepseek-ai/dsh-client-ui-slots": "^0.2.2-rc.3",
72
- "@deepseek-ai/dsh-host-webserver": "^0.2.2-rc.3",
73
- "@deepseek-ai/dsh-session": "^0.2.2-rc.3",
74
- "@deepseek-ai/dsh-tools": "^0.2.2-rc.3",
75
- "@deepseek-ai/dsh-typert-protocol": "^0.2.2-rc.3",
76
- "@deepseek-ai/dsh-user-approval": "^0.2.2-rc.3",
65
+ "@deepseek-ai/cordis": "~4.2.0-alpha.1",
66
+ "@deepseek-ai/dsh-api-gateway": "^0.2.3-alpha.2",
67
+ "@deepseek-ai/dsh-client-locale": "^0.2.3-alpha.2",
68
+ "@deepseek-ai/dsh-client-ui-primitives": "^0.2.3-alpha.2",
69
+ "@deepseek-ai/dsh-client-ui-renderer": "^0.2.3-alpha.2",
70
+ "@deepseek-ai/dsh-client-ui-sidebar": "^0.2.3-alpha.2",
71
+ "@deepseek-ai/dsh-client-ui-slots": "^0.2.3-alpha.2",
72
+ "@deepseek-ai/dsh-host-webserver": "^0.2.3-alpha.2",
73
+ "@deepseek-ai/dsh-session": "^0.2.3-alpha.2",
74
+ "@deepseek-ai/dsh-tools": "^0.2.3-alpha.2",
75
+ "@deepseek-ai/dsh-typert-protocol": "^0.2.3-alpha.2",
76
+ "@deepseek-ai/dsh-user-approval": "^0.2.3-alpha.2",
77
77
  "@testing-library/dom": "^10.4.1",
78
78
  "@testing-library/react": "^16.3.2",
79
79
  "@types/node": "^22.20.0",