@yefengr/remote-pi 0.7.2 → 0.7.4
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/dist/actions/handlers.d.ts +1 -1
- package/dist/actions/handlers.js +2 -1
- package/dist/actions/handlers.js.map +1 -1
- package/dist/index.d.ts +14 -1
- package/dist/index.js +76 -15
- package/dist/index.js.map +1 -1
- package/dist/protocol/v2/schemas.d.ts +0 -2
- package/dist/protocol/v2/schemas.js +2 -2
- package/dist/protocol/v2/schemas.js.map +1 -1
- package/dist/timeline/runtime.js +1 -1
- package/dist/timeline/runtime.js.map +1 -1
- package/dist/timeline/v2_service.d.ts +7 -1
- package/dist/timeline/v2_service.js +21 -4
- package/dist/timeline/v2_service.js.map +1 -1
- package/package.json +1 -1
|
@@ -114,7 +114,7 @@ type ThinkingSetMsg = Extract<ClientMessage, {
|
|
|
114
114
|
type ListModelsMsg = Extract<ClientMessage, {
|
|
115
115
|
type: "list_models";
|
|
116
116
|
}>;
|
|
117
|
-
export declare function handleSessionCompact(ctx: ActionCtx | null, sender: ActionReplySender, msg: SessionCompactMsg): void;
|
|
117
|
+
export declare function handleSessionCompact(ctx: ActionCtx | null, sender: ActionReplySender, msg: SessionCompactMsg, onSettled?: () => void): void;
|
|
118
118
|
export declare function handleSessionNew(ctx: ActionCtx | null, sender: ActionReplySender, msg: SessionNewMsg, onReplaced?: (freshCtx: ActionCtx) => void): Promise<boolean>;
|
|
119
119
|
export declare function handleThinkingSet(pi: ActionPi, sender: ActionReplySender, msg: ThinkingSetMsg): void;
|
|
120
120
|
export declare function handleModelSet(pi: ActionPi, ctx: ActionCtx | null, reg: ActionModelRegistry, sender: ActionReplySender, msg: ModelSetMsg, onPersist?: (provider: string, modelId: string) => void): Promise<void>;
|
package/dist/actions/handlers.js
CHANGED
|
@@ -65,7 +65,7 @@ async function runAsync(sender, msg, action, body) {
|
|
|
65
65
|
return false;
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
-
export function handleSessionCompact(ctx, sender, msg) {
|
|
68
|
+
export function handleSessionCompact(ctx, sender, msg, onSettled) {
|
|
69
69
|
runSync(sender, msg, "session_compact", () => {
|
|
70
70
|
if (!ctx?.compact)
|
|
71
71
|
throw new Error("compact unavailable (no active session ctx)");
|
|
@@ -75,6 +75,7 @@ export function handleSessionCompact(ctx, sender, msg) {
|
|
|
75
75
|
// compaction prompt (best-effort: the model writes the summary).
|
|
76
76
|
ctx.compact({
|
|
77
77
|
customInstructions: "Always write the compaction summary in English, even if the conversation is in another language.",
|
|
78
|
+
...(onSettled ? { onComplete: onSettled, onError: onSettled } : {}),
|
|
78
79
|
});
|
|
79
80
|
});
|
|
80
81
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../src/actions/handlers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AA2FH;wDACwD;AACxD,MAAM,UAAU,aAAa,CAAC,KAAiB;IAC7C,OAAO;QACL,EAAE,EAAE,KAAK,CAAC,EAAE;QACZ,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,cAAc,EAAE,KAAK,CAAC,aAAa;QACnC,gEAAgE;QAChE,2EAA2E;QAC3E,wDAAwD;QACxD,MAAM,EAAE,KAAK,CAAC,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAK;KAChD,CAAC;AACJ,CAAC;AAED,8EAA8E;AAE9E,SAAS,EAAE,CAAC,MAAyB,EAAE,GAAmB,EAAE,MAAkB;IAC5E,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;AAClE,CAAC;AAED,SAAS,IAAI,CACX,MAAyB,EACzB,GAAmB,EACnB,MAAkB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AW,IAAI,CAAC,aAAa,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IAC3F,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;AAC7E,CAAC;AAED,MAAM,UAAU,gBAAgB,CAC9B,GAAqB,EACrB,GAAwB,EACxB,MAAyB,EACzB,GAAkB;IAElB,yEAAyE;IACzE,6DAA6D;IAC7D,IAAI,CAAC;QACH,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;IACxF,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,CAAC,IAAI,CAAC;YACV,IAAI,EAAE,OAAO;YACb,WAAW,EAAE,GAAG,CAAC,EAAE;YACnB,IAAI,EAAE,gBAAgB;YACtB,OAAO,EAAE,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;SACpD,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -44,6 +44,19 @@ export type RelayConnectivity = "connected" | "reconnecting" | "disconnected";
|
|
|
44
44
|
* transcript entry. Starts with NUL so it can't collide with real user input
|
|
45
45
|
* and doesn't begin with "/" (which would route to the command parser). */
|
|
46
46
|
export declare const CTRL_PREFIX = "\0remote-pi-ctrl:";
|
|
47
|
+
/**
|
|
48
|
+
* Owners currently connected via the relay. Key = app peer pubkey (Ed25519,
|
|
49
|
+
* base64 standard); value = the dedicated PlainPeerChannel routing messages
|
|
50
|
+
* to/from that owner.
|
|
51
|
+
*
|
|
52
|
+
* Operational notes:
|
|
53
|
+
* - Adding/removing entries is exclusively in `_attachPeerChannel` and
|
|
54
|
+
* `_detachPeerChannel` (or `_goIdle` for the bulk teardown). Don't mutate
|
|
55
|
+
* directly elsewhere — those helpers keep the footer/log/state in sync.
|
|
56
|
+
* - `paired` UX state is `_activePeers.size > 0`. The footer and the
|
|
57
|
+
* `/remote-pi status` output both derive from this.
|
|
58
|
+
*/
|
|
59
|
+
type ClientMessageSender = Pick<PlainPeerChannel, "send" | "getPeerId">;
|
|
47
60
|
type BufferMsg = {
|
|
48
61
|
role: "user" | "assistant" | "toolResult" | string;
|
|
49
62
|
content?: unknown;
|
|
@@ -165,7 +178,7 @@ declare const extension: ExtensionFactory;
|
|
|
165
178
|
export default extension;
|
|
166
179
|
/** Test-only entry point for verifying mesh-to-agent delivery semantics. */
|
|
167
180
|
export declare function _deliverMeshMessageToAgentForTest(env: MeshEnvelope): void;
|
|
168
|
-
export declare function _routeClientMessageFrom(sender:
|
|
181
|
+
export declare function _routeClientMessageFrom(sender: ClientMessageSender, msg: ClientMessage, ctx: Pick<ExtensionContext, "abort">): void;
|
|
169
182
|
/**
|
|
170
183
|
* Backward-compatible shim for legacy callers + tests that didn't track
|
|
171
184
|
* a specific sender channel. Routes to the most recently attached owner,
|
package/dist/index.js
CHANGED
|
@@ -77,20 +77,9 @@ let _lastRelayStatus = null;
|
|
|
77
77
|
* and doesn't begin with "/" (which would route to the command parser). */
|
|
78
78
|
export const CTRL_PREFIX = "\x00remote-pi-ctrl:";
|
|
79
79
|
let _relayUrl = null; // URL used by current _relay connection
|
|
80
|
-
/**
|
|
81
|
-
* Owners currently connected via the relay. Key = app peer pubkey (Ed25519,
|
|
82
|
-
* base64 standard); value = the dedicated PlainPeerChannel routing messages
|
|
83
|
-
* to/from that owner.
|
|
84
|
-
*
|
|
85
|
-
* Operational notes:
|
|
86
|
-
* - Adding/removing entries is exclusively in `_attachPeerChannel` and
|
|
87
|
-
* `_detachPeerChannel` (or `_goIdle` for the bulk teardown). Don't mutate
|
|
88
|
-
* directly elsewhere — those helpers keep the footer/log/state in sync.
|
|
89
|
-
* - `paired` UX state is `_activePeers.size > 0`. The footer and the
|
|
90
|
-
* `/remote-pi status` output both derive from this.
|
|
91
|
-
*/
|
|
92
80
|
const _activePeers = new Map();
|
|
93
81
|
const _v2ActivePeers = new Map();
|
|
82
|
+
let _sessionActionInFlight = null;
|
|
94
83
|
let _peerShort = ""; // shortid of the most recently attached peer (UX hint only)
|
|
95
84
|
const REMOTE_PI_RECEIVED_IMAGE_TYPE = "remote-pi:received-image";
|
|
96
85
|
const RECEIVED_IMAGE_MAX_BYTES = 10 * 1024 * 1024;
|
|
@@ -772,12 +761,72 @@ function _ensureV2Service(senderRef) {
|
|
|
772
761
|
_trackPendingSteer(frame.client_request_id, frame.text);
|
|
773
762
|
return true;
|
|
774
763
|
},
|
|
775
|
-
onCancel: (
|
|
764
|
+
onCancel: () => _abortCurrentTurn(_lastEventCtx ?? _lastCtx ?? undefined),
|
|
765
|
+
onAction: (frame) => _routeV2ActionFrame(senderRef, frame),
|
|
776
766
|
onQueuedMessageClear: (targetId) => _clearV2QueuedUserMessages(senderRef, targetId),
|
|
777
767
|
onListModels: () => getModelsList((_lastEventCtx ?? _lastCtx), ensureModelRegistry((_lastEventCtx ?? _lastCtx)), _currentModel),
|
|
778
768
|
});
|
|
779
769
|
return service;
|
|
780
770
|
}
|
|
771
|
+
function _finishSessionAction(requestId) {
|
|
772
|
+
if (requestId && _sessionActionInFlight?.id !== requestId)
|
|
773
|
+
return;
|
|
774
|
+
_sessionActionInFlight = null;
|
|
775
|
+
}
|
|
776
|
+
function _v2ActionSender(senderRef, channel, targetChannelId, onReply) {
|
|
777
|
+
const sender = {
|
|
778
|
+
send(message) {
|
|
779
|
+
if (message.type === "action_ok") {
|
|
780
|
+
channel.sendV2({
|
|
781
|
+
protocol_version: 2,
|
|
782
|
+
type: "action_ok",
|
|
783
|
+
target_channel_id: targetChannelId,
|
|
784
|
+
in_reply_to: message.in_reply_to,
|
|
785
|
+
action: message.action,
|
|
786
|
+
});
|
|
787
|
+
}
|
|
788
|
+
else if (message.type === "action_error") {
|
|
789
|
+
channel.sendV2({
|
|
790
|
+
protocol_version: 2,
|
|
791
|
+
type: "action_error",
|
|
792
|
+
target_channel_id: targetChannelId,
|
|
793
|
+
in_reply_to: message.in_reply_to,
|
|
794
|
+
action: message.action,
|
|
795
|
+
error: message.error,
|
|
796
|
+
});
|
|
797
|
+
}
|
|
798
|
+
if (message.type === "action_ok" || message.type === "action_error")
|
|
799
|
+
onReply?.(message);
|
|
800
|
+
},
|
|
801
|
+
};
|
|
802
|
+
return { ...sender, getPeerId: () => senderRef };
|
|
803
|
+
}
|
|
804
|
+
function _routeV2ActionFrame(senderRef, frame) {
|
|
805
|
+
const binding = _v2ActivePeers.get(senderRef);
|
|
806
|
+
if (!binding)
|
|
807
|
+
return;
|
|
808
|
+
const sessionAction = frame.type === "session_new" || frame.type === "session_compact";
|
|
809
|
+
const sender = _v2ActionSender(senderRef, binding.channel, frame.channel_id, (message) => {
|
|
810
|
+
if (!sessionAction)
|
|
811
|
+
return;
|
|
812
|
+
if (message.type === "action_error" || frame.type === "session_new")
|
|
813
|
+
_finishSessionAction(frame.id);
|
|
814
|
+
});
|
|
815
|
+
if (sessionAction && (_sessionActionInFlight || _agentRunActive || _isBusyForQueueDrain())) {
|
|
816
|
+
sender.send({
|
|
817
|
+
type: "action_error",
|
|
818
|
+
in_reply_to: frame.id,
|
|
819
|
+
action: frame.type,
|
|
820
|
+
error: _sessionActionInFlight
|
|
821
|
+
? "Another session action is still in progress."
|
|
822
|
+
: "Agent is working; stop or wait before changing the session.",
|
|
823
|
+
});
|
|
824
|
+
return;
|
|
825
|
+
}
|
|
826
|
+
if (sessionAction)
|
|
827
|
+
_sessionActionInFlight = { id: frame.id, action: frame.type, senderRef };
|
|
828
|
+
_routeClientMessageFrom(sender, frame, (_lastEventCtx ?? _lastCtx ?? _noopCtx));
|
|
829
|
+
}
|
|
781
830
|
function _routeV2ClientFrameFrom(senderRef, frame) {
|
|
782
831
|
let binding = _v2ActivePeers.get(senderRef);
|
|
783
832
|
if (!binding) {
|
|
@@ -1665,6 +1714,7 @@ function _goIdle(byeReason) {
|
|
|
1665
1714
|
_v2ActivePeers.clear();
|
|
1666
1715
|
_peerShort = "";
|
|
1667
1716
|
_currentTurnId = null;
|
|
1717
|
+
_sessionActionInFlight = null;
|
|
1668
1718
|
_pendingReceivedImagePreviews.length = 0;
|
|
1669
1719
|
_pendingSteers = [];
|
|
1670
1720
|
_lastConsumedSteerText = null;
|
|
@@ -2602,6 +2652,8 @@ const extension = (pi) => {
|
|
|
2602
2652
|
_broadcastToActive({ type: "compaction", summary, tokens_before: tokensBefore, ts });
|
|
2603
2653
|
// (3) Working ends.
|
|
2604
2654
|
_publishWorking(false);
|
|
2655
|
+
if (_sessionActionInFlight?.action === "session_compact")
|
|
2656
|
+
_finishSessionAction(_sessionActionInFlight.id);
|
|
2605
2657
|
_maybeDrainQueuedItem();
|
|
2606
2658
|
_scheduleV2QueuedUserDrain();
|
|
2607
2659
|
});
|
|
@@ -4602,8 +4654,17 @@ export function _routeClientMessageFrom(sender, msg, ctx) {
|
|
|
4602
4654
|
_extensionUiBridge?.respond(msg);
|
|
4603
4655
|
return;
|
|
4604
4656
|
}
|
|
4605
|
-
if (!_pi)
|
|
4657
|
+
if (!_pi) {
|
|
4658
|
+
if (msg.type === "session_new" || msg.type === "session_compact" || msg.type === "model_set" || msg.type === "thinking_set") {
|
|
4659
|
+
sender.send({
|
|
4660
|
+
type: "action_error",
|
|
4661
|
+
in_reply_to: msg.id,
|
|
4662
|
+
action: msg.type,
|
|
4663
|
+
error: "Pi session is unavailable.",
|
|
4664
|
+
});
|
|
4665
|
+
}
|
|
4606
4666
|
return;
|
|
4667
|
+
}
|
|
4607
4668
|
switch (msg.type) {
|
|
4608
4669
|
case "queued_message_set": {
|
|
4609
4670
|
const text = msg.text.trim();
|
|
@@ -4720,7 +4781,7 @@ export function _routeClientMessageFrom(sender, msg, ctx) {
|
|
|
4720
4781
|
// a prior New session. compact() is a base-ctx method, so the
|
|
4721
4782
|
// session_start ctx suffices. Fall back to _lastCtx defensively if no
|
|
4722
4783
|
// session_start has landed yet (keeps the pre-replacement happy path).
|
|
4723
|
-
handleSessionCompact((_lastEventCtx ?? _lastCtx), sender, msg);
|
|
4784
|
+
handleSessionCompact((_lastEventCtx ?? _lastCtx), sender, msg, () => _finishSessionAction(msg.id));
|
|
4724
4785
|
break;
|
|
4725
4786
|
case "session_new": {
|
|
4726
4787
|
const actionCtx = _lastCtx;
|