@sjhmars/happy-bridge 0.2.4 → 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 +11 -11
- package/lib/index.js +24 -12
- package/lib/types/session-socket.d.ts +3 -0
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -17,21 +17,21 @@ window.__ModuleLoader__.load({
|
|
|
17
17
|
document.head.appendChild(tag);
|
|
18
18
|
}
|
|
19
19
|
var HappyBridgeCard_module_css_default = {
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"description": "l9rBEq_description",
|
|
25
|
-
"body": "l9rBEq_body",
|
|
20
|
+
"status": "l9rBEq_status",
|
|
21
|
+
"qr": "l9rBEq_qr",
|
|
22
|
+
"select": "l9rBEq_select",
|
|
23
|
+
"row": "l9rBEq_row",
|
|
26
24
|
"name": "l9rBEq_name",
|
|
27
|
-
"
|
|
25
|
+
"body": "l9rBEq_body",
|
|
28
26
|
"label": "l9rBEq_label",
|
|
29
27
|
"header": "l9rBEq_header",
|
|
30
|
-
"
|
|
28
|
+
"chevron": "l9rBEq_chevron",
|
|
31
29
|
"checkbox": "l9rBEq_checkbox",
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
30
|
+
"card": "l9rBEq_card",
|
|
31
|
+
"headText": "l9rBEq_headText",
|
|
32
|
+
"button": "l9rBEq_button",
|
|
33
|
+
"error": "l9rBEq_error",
|
|
34
|
+
"description": "l9rBEq_description"
|
|
35
35
|
};
|
|
36
36
|
//#endregion
|
|
37
37
|
//#region src/client/HappyBridgeCard.tsx
|
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:
|
|
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,16 +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
|
-
|
|
3969
|
-
|
|
3974
|
+
const args = req.reason === void 0 ? {} : { reason: req.reason };
|
|
3975
|
+
const card = happyTool(req.toolName, args);
|
|
3976
|
+
let resolvePhone = () => {};
|
|
3970
3977
|
const phone = new Promise((resolve) => {
|
|
3971
|
-
|
|
3972
|
-
kind: "approval",
|
|
3973
|
-
id,
|
|
3974
|
-
toolName: req.toolName,
|
|
3975
|
-
resolve
|
|
3976
|
-
};
|
|
3978
|
+
resolvePhone = resolve;
|
|
3977
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);
|
|
3978
3990
|
const web = next().then((outcome) => ({
|
|
3979
3991
|
src: "web",
|
|
3980
3992
|
outcome
|
|
@@ -3991,7 +4003,7 @@ var HappyBridge = class {
|
|
|
3991
4003
|
delete link.pendingHuman;
|
|
3992
4004
|
this.clearRequest(link, id, winner.outcome === "allowed-once" ? "approved" : "canceled");
|
|
3993
4005
|
}
|
|
3994
|
-
if (
|
|
4006
|
+
if (link.agent?.status === "running") link.socket.keepAliveNow(true);
|
|
3995
4007
|
return winner.outcome;
|
|
3996
4008
|
}
|
|
3997
4009
|
onAsk(questions, original, request) {
|
|
@@ -4119,8 +4131,8 @@ var HappyBridge = class {
|
|
|
4119
4131
|
const requests = {};
|
|
4120
4132
|
if (pending !== void 0) {
|
|
4121
4133
|
if (pending.kind === "approval") requests[pending.id] = {
|
|
4122
|
-
tool: pending.
|
|
4123
|
-
arguments:
|
|
4134
|
+
tool: pending.happyName,
|
|
4135
|
+
arguments: pending.arguments,
|
|
4124
4136
|
createdAt: Date.now()
|
|
4125
4137
|
};
|
|
4126
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