@sjhmars/happy-bridge 0.2.3 → 0.2.5

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/client.js CHANGED
@@ -17,20 +17,20 @@ window.__ModuleLoader__.load({
17
17
  document.head.appendChild(tag);
18
18
  }
19
19
  var HappyBridgeCard_module_css_default = {
20
- "chevron": "l9rBEq_chevron",
21
- "header": "l9rBEq_header",
22
- "select": "l9rBEq_select",
23
- "headText": "l9rBEq_headText",
24
- "body": "l9rBEq_body",
25
- "name": "l9rBEq_name",
26
- "error": "l9rBEq_error",
27
20
  "status": "l9rBEq_status",
28
- "card": "l9rBEq_card",
29
- "button": "l9rBEq_button",
30
21
  "qr": "l9rBEq_qr",
22
+ "select": "l9rBEq_select",
31
23
  "row": "l9rBEq_row",
24
+ "name": "l9rBEq_name",
25
+ "body": "l9rBEq_body",
32
26
  "label": "l9rBEq_label",
27
+ "header": "l9rBEq_header",
28
+ "chevron": "l9rBEq_chevron",
33
29
  "checkbox": "l9rBEq_checkbox",
30
+ "card": "l9rBEq_card",
31
+ "headText": "l9rBEq_headText",
32
+ "button": "l9rBEq_button",
33
+ "error": "l9rBEq_error",
34
34
  "description": "l9rBEq_description"
35
35
  };
36
36
  //#endregion
package/lib/index.js CHANGED
@@ -2548,17 +2548,23 @@ var HappySessionSocket = class {
2548
2548
  }
2549
2549
  /**
2550
2550
  * Encrypt and push agentState (permission requests).
2551
+ * Retries on version-mismatch the same way metadata does; a dropped bump
2552
+ * leaves the App with empty `requests` and no Yes/No card.
2551
2553
  * @param agentState - plaintext agentState.
2552
2554
  */
2553
2555
  updateState(agentState) {
2554
2556
  const socket = this.socket;
2555
2557
  if (socket === void 0) return;
2558
+ this.emitState(socket, agentState, this.agentStateVersion, 0);
2559
+ }
2560
+ emitState(socket, agentState, expected, attempt) {
2556
2561
  socket.emit("update-state", {
2557
2562
  sid: this.happySessionId,
2558
2563
  agentState: encryptB64(this.crypto, agentState),
2559
- expectedVersion: this.agentStateVersion
2564
+ expectedVersion: expected
2560
2565
  }, (answer) => {
2561
2566
  if (typeof answer?.version === "number") this.agentStateVersion = answer.version;
2567
+ if (answer?.result === "version-mismatch" && attempt < 3 && typeof answer.version === "number") this.emitState(socket, agentState, answer.version, attempt + 1);
2562
2568
  });
2563
2569
  }
2564
2570
  sendAgent(ev, time) {
@@ -3965,15 +3971,22 @@ var HappyBridge = class {
3965
3971
  const id = req.callId;
3966
3972
  const controller = new AbortController();
3967
3973
  req.signal = req.signal === void 0 ? controller.signal : AbortSignal.any([req.signal, controller.signal]);
3968
- this.pushRequests(link);
3974
+ const args = req.reason === void 0 ? {} : { reason: req.reason };
3975
+ const card = happyTool(req.toolName, args);
3976
+ let resolvePhone = () => {};
3969
3977
  const phone = new Promise((resolve) => {
3970
- link.pendingHuman = {
3971
- kind: "approval",
3972
- id,
3973
- toolName: req.toolName,
3974
- resolve
3975
- };
3978
+ resolvePhone = resolve;
3976
3979
  });
3980
+ link.pendingHuman = {
3981
+ kind: "approval",
3982
+ id,
3983
+ toolName: req.toolName,
3984
+ happyName: card.name,
3985
+ arguments: card.args,
3986
+ resolve: resolvePhone
3987
+ };
3988
+ this.pushRequests(link);
3989
+ link.socket.keepAliveNow(true);
3977
3990
  const web = next().then((outcome) => ({
3978
3991
  src: "web",
3979
3992
  outcome
@@ -3990,7 +4003,7 @@ var HappyBridge = class {
3990
4003
  delete link.pendingHuman;
3991
4004
  this.clearRequest(link, id, winner.outcome === "allowed-once" ? "approved" : "canceled");
3992
4005
  }
3993
- if (this.running) link.socket.keepAliveNow(true);
4006
+ if (link.agent?.status === "running") link.socket.keepAliveNow(true);
3994
4007
  return winner.outcome;
3995
4008
  }
3996
4009
  onAsk(questions, original, request) {
@@ -4118,8 +4131,8 @@ var HappyBridge = class {
4118
4131
  const requests = {};
4119
4132
  if (pending !== void 0) {
4120
4133
  if (pending.kind === "approval") requests[pending.id] = {
4121
- tool: pending.toolName,
4122
- arguments: {},
4134
+ tool: pending.happyName,
4135
+ arguments: pending.arguments,
4123
4136
  createdAt: Date.now()
4124
4137
  };
4125
4138
  else if (pending.kind === "plan-review") requests[pending.id] = {
@@ -141,9 +141,12 @@ export declare class HappySessionSocket {
141
141
  private emitMetadata;
142
142
  /**
143
143
  * Encrypt and push agentState (permission requests).
144
+ * Retries on version-mismatch the same way metadata does; a dropped bump
145
+ * leaves the App with empty `requests` and no Yes/No card.
144
146
  * @param agentState - plaintext agentState.
145
147
  */
146
148
  updateState(agentState: unknown): void;
149
+ private emitState;
147
150
  private sendAgent;
148
151
  private emitEnvelope;
149
152
  private onMetadataUpdate;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjhmars/happy-bridge",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "Pair an already-running dsh web/desktop client with Happy App so the phone remote-controls the same harness sessions",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",