@chenacc/dsh-agentbridge 0.4.8 → 0.4.9

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 (2) hide show
  1. package/lib/index.js +69 -0
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -54,6 +54,21 @@ const name = "agentbridge-dsh-phone";
54
54
  // message rather than blocking the entire plugin.
55
55
  const inject = ["commands", "llm", "agents"];
56
56
 
57
+ /** DSH's permission presets, read the same defensive way as `apiProxy`. */
58
+ function permissionServiceOf(ctx) {
59
+ try {
60
+ const provided = ctx.get?.("permissionPresets");
61
+ if (provided) return provided;
62
+ } catch {
63
+ // No service store on this context.
64
+ }
65
+ try {
66
+ return ctx.permissionPresets ?? null;
67
+ } catch {
68
+ return null;
69
+ }
70
+ }
71
+
57
72
  /** The 0.1.x desktop RPC bridge, when this host still has one. */
58
73
  function apiProxyOf(ctx) {
59
74
  // `ctx.get` reads the service store without an inject requirement and returns
@@ -702,6 +717,7 @@ export class PhoneConnections {
702
717
  provider: agent.options.provider,
703
718
  model: agent.options.model,
704
719
  modelDirectory,
720
+ permissionDirectory: this.permissionDirectory(agent),
705
721
  integrationVersion: INTEGRATION_VERSION,
706
722
  ...(bridgeSessionId ? { bridgeSessionId } : {}),
707
723
  ...(reconnecting ? { reconnect: true } : {}),
@@ -983,6 +999,57 @@ export class PhoneConnections {
983
999
  return await apiProxy.respond({ type: "client-response", rpcId, result });
984
1000
  }
985
1001
 
1002
+ /**
1003
+ * The permission presets this deployment offers, plus the one in force here.
1004
+ *
1005
+ * DSH's "permission" is two knobs — sandbox level and approval policy — bundled as
1006
+ * presets by the `permissionPresets` service. The phone only needs names and labels;
1007
+ * the sandbox level travels along so a reader can tell what a preset actually allows.
1008
+ */
1009
+ permissionDirectory(agent) {
1010
+ const service = permissionServiceOf(this.ctx);
1011
+ const catalog = typeof service?.catalog === "function" ? service.catalog() : [];
1012
+ const current = typeof service?.current === "function" ? service.current(agent.session) : null;
1013
+ const options = catalog.slice(0, 12).map((option) => {
1014
+ const name = clipped(option?.value, 60);
1015
+ if (!name) return null;
1016
+ let spec = null;
1017
+ try {
1018
+ spec = typeof service?.specOf === "function" ? service.specOf(name) : null;
1019
+ } catch {
1020
+ spec = null;
1021
+ }
1022
+ return {
1023
+ name,
1024
+ label: clipped(option?.name, 80) || name,
1025
+ ...(option?.description ? { description: clipped(option.description, 300) } : {}),
1026
+ ...(spec?.sandbox ? { sandbox: clipped(spec.sandbox, 40) } : {}),
1027
+ ...(spec?.approval ? { approval: clipped(spec.approval, 40) } : {}),
1028
+ };
1029
+ }).filter(Boolean);
1030
+ return { current: clipped(current, 60) || null, options };
1031
+ }
1032
+
1033
+ /** Switch this conversation's permission preset, if the deployment exposes them. */
1034
+ async selectPermission(state, command) {
1035
+ const service = permissionServiceOf(this.ctx);
1036
+ if (typeof service?.set !== "function") {
1037
+ await this.reportCommandResult(state, command.requestId, {
1038
+ ok: false,
1039
+ error: "这个 DSH Desktop 版本没有提供权限预设(permissionPresets)",
1040
+ });
1041
+ return;
1042
+ }
1043
+ const name = clipped(command.name, 60);
1044
+ try {
1045
+ service.set(state.agent.session, name);
1046
+ const applied = typeof service.current === "function" ? service.current(state.agent.session) : name;
1047
+ await this.reportCommandResult(state, command.requestId, { ok: true, selected: applied });
1048
+ } catch (error) {
1049
+ await this.reportCommandResult(state, command.requestId, { ok: false, error: textFromError(error) });
1050
+ }
1051
+ }
1052
+
986
1053
  async modelDirectory(agent) {
987
1054
  const current = selectionFromAgent(agent);
988
1055
  try {
@@ -1407,6 +1474,8 @@ export class PhoneConnections {
1407
1474
  }
1408
1475
  } else if (command.kind === "answer-question" || command.kind === "cancel-question") {
1409
1476
  await this.answerQuestion(state, command);
1477
+ } else if (command.kind === "select-permission") {
1478
+ await this.selectPermission(state, command);
1410
1479
  } else if (command.kind === "create-session") {
1411
1480
  await this.createSession(state, command);
1412
1481
  } else if (command.kind === "answer-approval") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chenacc/dsh-agentbridge",
3
- "version": "0.4.8",
3
+ "version": "0.4.9",
4
4
  "description": "AgentBridge for DSH Desktop: run /phone in a conversation to pair a phone console with that exact live Agent.",
5
5
  "license": "MIT",
6
6
  "type": "module",