@yu_robotics/remote-cli-router 1.6.184 → 1.6.189
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/README.md +32 -0
- package/dist/binding/BindingManager.d.ts +21 -59
- package/dist/binding/BindingManager.d.ts.map +1 -1
- package/dist/binding/BindingManager.js +131 -155
- package/dist/binding/BindingManager.js.map +1 -1
- package/dist/binding/ThreadSelectionManager.d.ts +46 -0
- package/dist/binding/ThreadSelectionManager.d.ts.map +1 -0
- package/dist/binding/ThreadSelectionManager.js +130 -0
- package/dist/binding/ThreadSelectionManager.js.map +1 -0
- package/dist/feishu/ApprovalCards.d.ts +1 -1
- package/dist/feishu/ApprovalCards.d.ts.map +1 -1
- package/dist/feishu/ApprovalCards.js +3 -1
- package/dist/feishu/ApprovalCards.js.map +1 -1
- package/dist/feishu/FeishuLongConnHandler.d.ts +17 -10
- package/dist/feishu/FeishuLongConnHandler.d.ts.map +1 -1
- package/dist/feishu/FeishuLongConnHandler.js +142 -64
- package/dist/feishu/FeishuLongConnHandler.js.map +1 -1
- package/dist/server.d.ts +9 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +277 -82
- package/dist/server.js.map +1 -1
- package/dist/storage/JsonStore.d.ts +40 -64
- package/dist/storage/JsonStore.d.ts.map +1 -1
- package/dist/storage/JsonStore.js +380 -178
- package/dist/storage/JsonStore.js.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -457,6 +457,8 @@ Thread switch panels show `Reply from:` with the reply's full thread name and wo
|
|
|
457
457
|
|
|
458
458
|
From Router 1.6.174, completed cards show thread-switch buttons and **+ New** directly, without a folding panel or an extra expand click. The reply-source caption remains visible, and thread selection keeps the existing routing and permission checks. Cards use a 180-tagged-node budget, including nested controls and reserved completion elements; size and table limits still apply. This presentation change requires a Router upgrade and does not change the CLI wire protocol. Previously sent cards are not automatically rewritten by an upgrade.
|
|
459
459
|
|
|
460
|
+
From Router 1.6.189, the selected thread for new top-level messages is stored per Feishu user and bound device, so Router restarts and device A→B→A switches restore it without resetting native sessions. A device with no saved selection keeps the existing default behavior. Replies to known cards remain independent of that selection; unknown or expired parent cards return an error instead of silently using selected/default. A confirmed deleted selection resets with a Feishu notice, and the failed message is never replayed. If a saved preference is corrupt, `/thread list` is a narrow read-only recovery path that refreshes selection controls from the bound CLI; arbitrary work still blocks. Continuation-card thread controls and replies retain the same provenance, and New Thread adoption requires a validated complete catalog. This requires only a Router upgrade and remains compatible with older CLIs over protocol v1.
|
|
461
|
+
|
|
460
462
|
From CLI 1.6.172, Codex threads support native goals through `/goal` (status), `/goal <objective>` (start), `/goal pause`, `/goal resume`, and `/goal clear`. Start or resume only when the thread and queue are idle, with managed delegation explicitly disabled using `/delegation off`. This initial restriction does not disable Codex's native subagents. Optional `--budget <tokens>` on start or resume sets an explicit positive token budget; omitting it does not invent a budget. For example:
|
|
461
463
|
|
|
462
464
|
```text
|
|
@@ -510,6 +512,36 @@ From CLI 1.6.165, Pi connection and detach confirmations exclude simultaneous se
|
|
|
510
512
|
|
|
511
513
|
For full documentation, see the [project README](https://github.com/Yu-Robotics/remote-cli#readme).
|
|
512
514
|
|
|
515
|
+
## Upgrade compatibility
|
|
516
|
+
|
|
517
|
+
Router 1.6.185 retains protocol-v1 compatibility with existing CLIs, including
|
|
518
|
+
legacy registration and response formats. Task output must belong to the
|
|
519
|
+
connected device's bound user; binding requests and heartbeats remain available
|
|
520
|
+
before binding. Device binding changes are serialized and persistence failures
|
|
521
|
+
are reported rather than acknowledged as saved. Existing binding records keep
|
|
522
|
+
their JSON format. Malformed binding files are preserved and stop initialization
|
|
523
|
+
instead of being replaced with empty records. If a file replacement succeeds but
|
|
524
|
+
its durability cannot be confirmed, binding reads and writes stop until the
|
|
525
|
+
storage issue is resolved and the Router restarts to reconcile the saved file.
|
|
526
|
+
|
|
527
|
+
The ACP permission-error and Codex turn-start cleanup fixes are CLI-side changes:
|
|
528
|
+
upgrade the CLI to receive them. Older CLIs can continue using the updated Router
|
|
529
|
+
while retaining their previous local behavior. Legacy credentialless device
|
|
530
|
+
identification keeps its existing trust limitations; this release does not
|
|
531
|
+
require every older CLI to enroll a signed device key.
|
|
532
|
+
|
|
533
|
+
If Codex cannot confirm that its previous process stopped, the thread stays busy
|
|
534
|
+
and does not start queued work. Retry `/abort` to confirm termination and release
|
|
535
|
+
the thread. An unsuccessful retry reports the uncertainty and keeps the thread
|
|
536
|
+
blocked; it does not replay the failed prompt.
|
|
537
|
+
|
|
538
|
+
From Router 1.6.187, binding files must have a supported version and valid record
|
|
539
|
+
structure before they are loaded or migrated. Invalid files are preserved
|
|
540
|
+
without replacement, and the rejected store instance blocks reads and writes.
|
|
541
|
+
Correct or restore the file before restarting the Router. Valid version-1 files
|
|
542
|
+
and versionless single-device files, including empty legacy collections, remain
|
|
543
|
+
supported. The binding schema and protocol-v1 flow for existing CLIs are unchanged.
|
|
544
|
+
|
|
513
545
|
## License
|
|
514
546
|
|
|
515
547
|
MIT
|
|
@@ -1,76 +1,38 @@
|
|
|
1
|
-
import { DeviceBinding, UserBinding } from '../types';
|
|
1
|
+
import { BindingCode, DeviceBinding, UserBinding } from '../types';
|
|
2
2
|
import { JsonStore } from '../storage/JsonStore';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
export interface BindingRedemption {
|
|
4
|
+
bindingCode: BindingCode;
|
|
5
|
+
alreadyBound: boolean;
|
|
6
|
+
isFirstDevice: boolean;
|
|
7
|
+
}
|
|
8
|
+
/** Serializes ownership mutations sharing one JsonStore, including key callbacks. */
|
|
8
9
|
export declare class BindingManager {
|
|
9
10
|
private store;
|
|
11
|
+
private mutationTail;
|
|
10
12
|
constructor(store: JsonStore);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
* @param deviceName Device name
|
|
15
|
-
* @returns Binding code object
|
|
16
|
-
*/
|
|
17
|
-
generateBindingCode(deviceId: string, deviceName: string, devicePublicKey?: string): Promise<import('../types').BindingCode>;
|
|
18
|
-
/**
|
|
19
|
-
* Verify binding code
|
|
20
|
-
* @param code Binding code
|
|
21
|
-
* @returns Binding code object, returns null if invalid or expired
|
|
22
|
-
*/
|
|
23
|
-
verifyBindingCode(code: string): Promise<import('../types').BindingCode | null>;
|
|
13
|
+
private mutate;
|
|
14
|
+
generateBindingCode(deviceId: string, deviceName: string, devicePublicKey?: string): Promise<BindingCode>;
|
|
15
|
+
verifyBindingCode(code: string): Promise<BindingCode | null>;
|
|
24
16
|
consumeBindingCode(code: string): Promise<void>;
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
* First device becomes active; subsequent devices are added as inactive.
|
|
28
|
-
*/
|
|
17
|
+
/** Validate, assign, enroll, and consume without admitting competing mutations. */
|
|
18
|
+
redeemBindingCode(openId: string, code: string, deviceName: string, approveDeviceKey?: (openId: string, deviceId: string, publicKey: string) => Promise<void>): Promise<BindingRedemption | null>;
|
|
29
19
|
bindUser(openId: string, deviceId: string, deviceName: string): Promise<void>;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
20
|
+
private bindUserLocked;
|
|
21
|
+
/** Detect conflicting records rather than silently choosing or repairing an owner. */
|
|
22
|
+
private assertOwnership;
|
|
33
23
|
getUserBinding(openId: string): Promise<UserBinding | null>;
|
|
34
24
|
listBoundUserIds(): Promise<string[]>;
|
|
35
|
-
/**
|
|
36
|
-
* Get all devices for a user
|
|
37
|
-
*/
|
|
38
25
|
getUserDevices(openId: string): Promise<DeviceBinding[]>;
|
|
39
|
-
/**
|
|
40
|
-
* Get the active device for a user
|
|
41
|
-
*/
|
|
42
26
|
getActiveDevice(openId: string): Promise<DeviceBinding | null>;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
*/
|
|
27
|
+
getThreadSelection(openId: string, deviceId: string): import("../storage/JsonStore").DeviceThreadSelection;
|
|
28
|
+
selectThread(openId: string, deviceId: string, threadId: string, guard?: () => boolean): Promise<boolean>;
|
|
29
|
+
clearThreadSelection(openId: string, deviceId: string, expectedThreadId: string, guard?: () => boolean): Promise<boolean>;
|
|
47
30
|
switchActiveDevice(openId: string, deviceId: string): Promise<boolean>;
|
|
48
|
-
|
|
49
|
-
* Unbind a specific device from a user
|
|
50
|
-
* If the active device is removed, promotes the first remaining device.
|
|
51
|
-
* If no devices remain, removes the entire user binding.
|
|
52
|
-
* @returns true if device was found and removed
|
|
53
|
-
*/
|
|
54
|
-
unbindDevice(openId: string, deviceId: string): Promise<boolean>;
|
|
55
|
-
/**
|
|
56
|
-
* Get device binding information via reverse lookup
|
|
57
|
-
*/
|
|
31
|
+
unbindDevice(openId: string, deviceId: string, beforeUnbind?: (deviceId: string) => Promise<void>): Promise<boolean>;
|
|
58
32
|
getDeviceBinding(deviceId: string): Promise<UserBinding | null>;
|
|
59
|
-
|
|
60
|
-
* Unbind all devices for a user
|
|
61
|
-
*/
|
|
62
|
-
unbindUser(openId: string): Promise<void>;
|
|
63
|
-
/**
|
|
64
|
-
* Update user last active time
|
|
65
|
-
*/
|
|
33
|
+
unbindUser(openId: string, beforeUnbind?: (deviceId: string) => Promise<void>): Promise<void>;
|
|
66
34
|
updateLastActive(openId: string): Promise<void>;
|
|
67
|
-
/**
|
|
68
|
-
* Generate random binding code (format: XXX-XXX-XXX)
|
|
69
|
-
*/
|
|
70
35
|
private generateRandomCode;
|
|
71
|
-
/**
|
|
72
|
-
* Close and flush data
|
|
73
|
-
*/
|
|
74
36
|
close(): Promise<void>;
|
|
75
37
|
}
|
|
76
38
|
//# sourceMappingURL=BindingManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BindingManager.d.ts","sourceRoot":"","sources":["../../src/binding/BindingManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;
|
|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AAI,OAAO,CAAC,IAAI,CAAC;CAI7B"}
|
|
@@ -2,224 +2,200 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BindingManager = void 0;
|
|
4
4
|
const crypto_1 = require("crypto");
|
|
5
|
-
/**
|
|
6
|
-
* Binding Manager
|
|
7
|
-
* Responsible for managing user and device binding relationships
|
|
8
|
-
* Supports multiple devices per user with one active device
|
|
9
|
-
*/
|
|
5
|
+
/** Serializes ownership mutations sharing one JsonStore, including key callbacks. */
|
|
10
6
|
class BindingManager {
|
|
11
7
|
store;
|
|
8
|
+
mutationTail = Promise.resolve();
|
|
12
9
|
constructor(store) {
|
|
13
10
|
this.store = store;
|
|
14
11
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
*/
|
|
12
|
+
mutate(operation) {
|
|
13
|
+
const result = this.mutationTail.then(operation);
|
|
14
|
+
this.mutationTail = result.then(() => undefined, () => undefined);
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
21
17
|
async generateBindingCode(deviceId, deviceName, devicePublicKey) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Verify binding code
|
|
38
|
-
* @param code Binding code
|
|
39
|
-
* @returns Binding code object, returns null if invalid or expired
|
|
40
|
-
*/
|
|
18
|
+
return this.mutate(async () => {
|
|
19
|
+
const code = this.generateRandomCode();
|
|
20
|
+
const now = Date.now();
|
|
21
|
+
const bindingCode = {
|
|
22
|
+
code,
|
|
23
|
+
deviceId,
|
|
24
|
+
...(devicePublicKey ? { devicePublicKey } : {}),
|
|
25
|
+
createdAt: now,
|
|
26
|
+
expiresAt: now + 5 * 60 * 1000,
|
|
27
|
+
};
|
|
28
|
+
await this.store.setBindingCode(code, bindingCode);
|
|
29
|
+
return bindingCode;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
41
32
|
async verifyBindingCode(code) {
|
|
42
33
|
return this.store.getBindingCode(code);
|
|
43
34
|
}
|
|
44
35
|
async consumeBindingCode(code) {
|
|
45
|
-
|
|
36
|
+
return this.mutate(() => this.store.deleteBindingCode(code));
|
|
37
|
+
}
|
|
38
|
+
/** Validate, assign, enroll, and consume without admitting competing mutations. */
|
|
39
|
+
async redeemBindingCode(openId, code, deviceName, approveDeviceKey) {
|
|
40
|
+
return this.mutate(async () => {
|
|
41
|
+
const bindingCode = this.store.getBindingCode(code);
|
|
42
|
+
if (!bindingCode)
|
|
43
|
+
return null;
|
|
44
|
+
if (bindingCode.devicePublicKey && !approveDeviceKey)
|
|
45
|
+
throw new Error('Secure device enrollment is unavailable.');
|
|
46
|
+
this.assertOwnership(bindingCode.deviceId, openId);
|
|
47
|
+
const existingDevices = this.store.getUserBinding(openId)?.devices ?? [];
|
|
48
|
+
const alreadyBound = existingDevices.some(device => device.deviceId === bindingCode.deviceId);
|
|
49
|
+
if (alreadyBound && !bindingCode.devicePublicKey) {
|
|
50
|
+
return { bindingCode, alreadyBound, isFirstDevice: existingDevices.length === 0 };
|
|
51
|
+
}
|
|
52
|
+
await this.bindUserLocked(openId, bindingCode.deviceId, deviceName);
|
|
53
|
+
if (bindingCode.devicePublicKey) {
|
|
54
|
+
await approveDeviceKey(openId, bindingCode.deviceId, bindingCode.devicePublicKey);
|
|
55
|
+
}
|
|
56
|
+
await this.store.deleteBindingCode(code);
|
|
57
|
+
return { bindingCode, alreadyBound, isFirstDevice: existingDevices.length === 0 };
|
|
58
|
+
});
|
|
46
59
|
}
|
|
47
|
-
/**
|
|
48
|
-
* Bind user and device (supports multi-device)
|
|
49
|
-
* First device becomes active; subsequent devices are added as inactive.
|
|
50
|
-
*/
|
|
51
60
|
async bindUser(openId, deviceId, deviceName) {
|
|
61
|
+
return this.mutate(() => this.bindUserLocked(openId, deviceId, deviceName));
|
|
62
|
+
}
|
|
63
|
+
async bindUserLocked(openId, deviceId, deviceName) {
|
|
64
|
+
this.assertOwnership(deviceId, openId);
|
|
52
65
|
const now = Date.now();
|
|
53
|
-
|
|
54
|
-
// This prevents cross-user data leakage and routing confusion
|
|
55
|
-
const existingOwner = this.store.getUserByDeviceId(deviceId);
|
|
56
|
-
if (existingOwner && existingOwner !== openId) {
|
|
57
|
-
throw new Error(`Device ${deviceId} is already bound to another user. ` +
|
|
58
|
-
`Please unbind it first or use a different device ID.`);
|
|
59
|
-
}
|
|
60
|
-
const existingBinding = await this.getUserBinding(openId);
|
|
66
|
+
const existingBinding = this.store.getUserBinding(openId);
|
|
61
67
|
if (existingBinding) {
|
|
62
|
-
|
|
63
|
-
const deviceIndex = existingBinding.devices.findIndex(d => d.deviceId === deviceId);
|
|
68
|
+
const deviceIndex = existingBinding.devices.findIndex(device => device.deviceId === deviceId);
|
|
64
69
|
if (deviceIndex >= 0) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
70
|
+
existingBinding.devices[deviceIndex] = {
|
|
71
|
+
...existingBinding.devices[deviceIndex], deviceName, lastActiveAt: now,
|
|
72
|
+
};
|
|
68
73
|
}
|
|
69
74
|
else {
|
|
70
|
-
|
|
71
|
-
existingBinding.devices.push({
|
|
72
|
-
deviceId,
|
|
73
|
-
deviceName,
|
|
74
|
-
boundAt: now,
|
|
75
|
-
lastActiveAt: now,
|
|
76
|
-
isActive: false,
|
|
77
|
-
});
|
|
75
|
+
existingBinding.devices.push({ deviceId, deviceName, boundAt: now, lastActiveAt: now, isActive: false });
|
|
78
76
|
}
|
|
79
77
|
existingBinding.updatedAt = now;
|
|
80
78
|
await this.store.setUserBinding(openId, existingBinding);
|
|
81
79
|
}
|
|
82
80
|
else {
|
|
83
|
-
// First device for this user - set as active
|
|
84
81
|
const binding = {
|
|
85
82
|
openId,
|
|
86
|
-
devices: [{
|
|
87
|
-
deviceId,
|
|
88
|
-
deviceName,
|
|
89
|
-
boundAt: now,
|
|
90
|
-
lastActiveAt: now,
|
|
91
|
-
isActive: true,
|
|
92
|
-
}],
|
|
83
|
+
devices: [{ deviceId, deviceName, boundAt: now, lastActiveAt: now, isActive: true }],
|
|
93
84
|
activeDeviceId: deviceId,
|
|
94
85
|
createdAt: now,
|
|
95
86
|
updatedAt: now,
|
|
96
87
|
};
|
|
97
88
|
await this.store.setUserBinding(openId, binding);
|
|
98
89
|
}
|
|
99
|
-
// Update device-to-user reverse mapping to ensure consistency
|
|
100
90
|
await this.store.setDeviceToUserMap(deviceId, openId);
|
|
101
91
|
}
|
|
102
|
-
/**
|
|
103
|
-
|
|
104
|
-
|
|
92
|
+
/** Detect conflicting records rather than silently choosing or repairing an owner. */
|
|
93
|
+
assertOwnership(deviceId, openId) {
|
|
94
|
+
const owners = [];
|
|
95
|
+
for (const candidate of this.store.listBoundUserIds()) {
|
|
96
|
+
if (this.store.getUserBinding(candidate)?.devices.some(device => device.deviceId === deviceId))
|
|
97
|
+
owners.push(candidate);
|
|
98
|
+
}
|
|
99
|
+
const mapped = this.store.getUserByDeviceId(deviceId);
|
|
100
|
+
const ambiguous = owners.length > 1 || Boolean(mapped && owners.length > 0 && !owners.includes(mapped));
|
|
101
|
+
if (ambiguous) {
|
|
102
|
+
throw new Error(`Device ${deviceId} has ambiguous historical ownership. Repair the binding records manually before changing them.`);
|
|
103
|
+
}
|
|
104
|
+
const owner = mapped ?? owners[0];
|
|
105
|
+
if (owner && owner !== openId) {
|
|
106
|
+
throw new Error(`Device ${deviceId} is already bound to another user. Please unbind it first or use a different device ID.`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
105
109
|
async getUserBinding(openId) {
|
|
106
110
|
return this.store.getUserBinding(openId);
|
|
107
111
|
}
|
|
108
112
|
async listBoundUserIds() {
|
|
109
113
|
return this.store.listBoundUserIds();
|
|
110
114
|
}
|
|
111
|
-
/**
|
|
112
|
-
* Get all devices for a user
|
|
113
|
-
*/
|
|
114
115
|
async getUserDevices(openId) {
|
|
115
|
-
|
|
116
|
-
return binding?.devices || [];
|
|
116
|
+
return this.store.getUserBinding(openId)?.devices ?? [];
|
|
117
117
|
}
|
|
118
|
-
/**
|
|
119
|
-
* Get the active device for a user
|
|
120
|
-
*/
|
|
121
118
|
async getActiveDevice(openId) {
|
|
122
119
|
const binding = this.store.getUserBinding(openId);
|
|
123
|
-
if (!binding
|
|
120
|
+
if (!binding?.activeDeviceId)
|
|
124
121
|
return null;
|
|
125
|
-
|
|
126
|
-
|
|
122
|
+
return binding.devices.find(device => device.deviceId === binding.activeDeviceId) ?? null;
|
|
123
|
+
}
|
|
124
|
+
getThreadSelection(openId, deviceId) {
|
|
125
|
+
return this.store.getDeviceThreadSelection(openId, deviceId);
|
|
126
|
+
}
|
|
127
|
+
async selectThread(openId, deviceId, threadId, guard = () => true) {
|
|
128
|
+
return this.mutate(async () => {
|
|
129
|
+
if (!guard())
|
|
130
|
+
return false;
|
|
131
|
+
this.assertOwnership(deviceId, openId);
|
|
132
|
+
return this.store.setDeviceThreadSelection(openId, deviceId, threadId, { requireActive: true, guard });
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
async clearThreadSelection(openId, deviceId, expectedThreadId, guard = () => true) {
|
|
136
|
+
return this.mutate(async () => {
|
|
137
|
+
if (!guard())
|
|
138
|
+
return false;
|
|
139
|
+
this.assertOwnership(deviceId, openId);
|
|
140
|
+
return this.store.setDeviceThreadSelection(openId, deviceId, null, { expectedThreadId, guard });
|
|
141
|
+
});
|
|
127
142
|
}
|
|
128
|
-
/**
|
|
129
|
-
* Switch the active device for a user
|
|
130
|
-
* @returns true if switch was successful
|
|
131
|
-
*/
|
|
132
143
|
async switchActiveDevice(openId, deviceId) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
// Update isActive flags
|
|
142
|
-
for (const device of binding.devices) {
|
|
143
|
-
device.isActive = device.deviceId === deviceId;
|
|
144
|
-
}
|
|
145
|
-
binding.activeDeviceId = deviceId;
|
|
146
|
-
binding.updatedAt = Date.now();
|
|
147
|
-
await this.store.setUserBinding(openId, binding);
|
|
148
|
-
return true;
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Unbind a specific device from a user
|
|
152
|
-
* If the active device is removed, promotes the first remaining device.
|
|
153
|
-
* If no devices remain, removes the entire user binding.
|
|
154
|
-
* @returns true if device was found and removed
|
|
155
|
-
*/
|
|
156
|
-
async unbindDevice(openId, deviceId) {
|
|
157
|
-
const binding = this.store.getUserBinding(openId);
|
|
158
|
-
if (!binding) {
|
|
159
|
-
return false;
|
|
160
|
-
}
|
|
161
|
-
const deviceIndex = binding.devices.findIndex(d => d.deviceId === deviceId);
|
|
162
|
-
if (deviceIndex < 0) {
|
|
163
|
-
return false;
|
|
164
|
-
}
|
|
165
|
-
// Remove device
|
|
166
|
-
binding.devices.splice(deviceIndex, 1);
|
|
167
|
-
await this.store.removeDeviceToUserMap(deviceId);
|
|
168
|
-
if (binding.devices.length === 0) {
|
|
169
|
-
// No devices left, delete the entire binding
|
|
170
|
-
await this.store.deleteUserBinding(openId);
|
|
144
|
+
return this.mutate(async () => {
|
|
145
|
+
const binding = this.store.getUserBinding(openId);
|
|
146
|
+
if (!binding?.devices.some(device => device.deviceId === deviceId))
|
|
147
|
+
return false;
|
|
148
|
+
binding.devices = binding.devices.map(device => ({ ...device, isActive: device.deviceId === deviceId }));
|
|
149
|
+
binding.activeDeviceId = deviceId;
|
|
150
|
+
binding.updatedAt = Date.now();
|
|
151
|
+
await this.store.setUserBinding(openId, binding);
|
|
171
152
|
return true;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
binding
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
async unbindDevice(openId, deviceId, beforeUnbind) {
|
|
156
|
+
return this.mutate(async () => {
|
|
157
|
+
const binding = this.store.getUserBinding(openId);
|
|
158
|
+
const deviceIndex = binding?.devices.findIndex(device => device.deviceId === deviceId) ?? -1;
|
|
159
|
+
if (!binding || deviceIndex < 0)
|
|
160
|
+
return false;
|
|
161
|
+
this.assertOwnership(deviceId, openId);
|
|
162
|
+
await beforeUnbind?.(deviceId);
|
|
163
|
+
return this.store.unbindDevice(openId, deviceId);
|
|
164
|
+
});
|
|
181
165
|
}
|
|
182
|
-
/**
|
|
183
|
-
* Get device binding information via reverse lookup
|
|
184
|
-
*/
|
|
185
166
|
async getDeviceBinding(deviceId) {
|
|
186
167
|
const openId = this.store.getUserByDeviceId(deviceId);
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
return this.
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
168
|
+
return openId ? this.store.getUserBinding(openId) : null;
|
|
169
|
+
}
|
|
170
|
+
async unbindUser(openId, beforeUnbind) {
|
|
171
|
+
return this.mutate(async () => {
|
|
172
|
+
const binding = this.store.getUserBinding(openId);
|
|
173
|
+
if (!binding)
|
|
174
|
+
return;
|
|
175
|
+
for (const device of binding.devices)
|
|
176
|
+
this.assertOwnership(device.deviceId, openId);
|
|
177
|
+
if (beforeUnbind)
|
|
178
|
+
for (const device of binding.devices)
|
|
179
|
+
await beforeUnbind(device.deviceId);
|
|
180
|
+
await this.store.deleteUserBinding(openId);
|
|
181
|
+
});
|
|
197
182
|
}
|
|
198
|
-
/**
|
|
199
|
-
* Update user last active time
|
|
200
|
-
*/
|
|
201
183
|
async updateLastActive(openId) {
|
|
202
|
-
|
|
184
|
+
return this.mutate(() => this.store.updateLastActive(openId));
|
|
203
185
|
}
|
|
204
|
-
/**
|
|
205
|
-
* Generate random binding code (format: XXX-XXX-XXX)
|
|
206
|
-
*/
|
|
207
186
|
generateRandomCode() {
|
|
208
187
|
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
|
209
188
|
const segments = [];
|
|
210
189
|
for (let i = 0; i < 3; i++) {
|
|
211
190
|
let segment = '';
|
|
212
|
-
for (let j = 0; j < 3; j++)
|
|
191
|
+
for (let j = 0; j < 3; j++)
|
|
213
192
|
segment += chars.charAt((0, crypto_1.randomInt)(chars.length));
|
|
214
|
-
}
|
|
215
193
|
segments.push(segment);
|
|
216
194
|
}
|
|
217
195
|
return segments.join('-');
|
|
218
196
|
}
|
|
219
|
-
/**
|
|
220
|
-
* Close and flush data
|
|
221
|
-
*/
|
|
222
197
|
async close() {
|
|
198
|
+
await this.mutationTail;
|
|
223
199
|
await this.store.flush();
|
|
224
200
|
}
|
|
225
201
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BindingManager.js","sourceRoot":"","sources":["../../src/binding/BindingManager.ts"],"names":[],"mappings":";;;AAEA,mCAAmC;
|
|
1
|
+
{"version":3,"file":"BindingManager.js","sourceRoot":"","sources":["../../src/binding/BindingManager.ts"],"names":[],"mappings":";;;AAEA,mCAAmC;AAQnC,qFAAqF;AACrF,MAAa,cAAc;IACjB,KAAK,CAAY;IACjB,YAAY,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;IAExD,YAAY,KAAgB;QAC1B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAEO,MAAM,CAAI,SAA2B;QAC3C,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACjD,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAClE,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,mBAAmB,CAAC,QAAgB,EAAE,UAAkB,EAAE,eAAwB;QACtF,OAAO,IAAI,CAAC,MAAM,C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CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC;IAChE,CAAC;IAEO,kBAAkB;QACxB,MAAM,KAAK,GAAG,sCAAsC,CAAC;QACrD,MAAM,QAAQ,GAAG,EAAE,CAAC;QACpB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YAC3B,IAAI,OAAO,GAAG,EAAE,CAAC;YACjB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;gBAAE,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,IAAA,kBAAS,EAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;YAC7E,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACzB,CAAC;QACD,OAAO,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,KAAK;QACT,MAAM,IAAI,CAAC,YAAY,CAAC;QACxB,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IAC3B,CAAC;CACF;AAhND,wCAgNC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { BindingManager } from './BindingManager';
|
|
2
|
+
import type { ThreadSummary } from '../types';
|
|
3
|
+
/** A protocol catalog always contains the default thread and unique, bounded entries. */
|
|
4
|
+
export declare function isCompleteThreadCatalog(value: unknown): value is ThreadSummary[];
|
|
5
|
+
export interface SelectionFence {
|
|
6
|
+
openId: string;
|
|
7
|
+
deviceId: string;
|
|
8
|
+
revision: number;
|
|
9
|
+
epoch: number;
|
|
10
|
+
}
|
|
11
|
+
interface ThreadSelectionOptions {
|
|
12
|
+
names(openId: string, deviceId: string, threadId: string): string | undefined;
|
|
13
|
+
notify?(openId: string, text: string): Promise<unknown>;
|
|
14
|
+
}
|
|
15
|
+
/** Router-owned UI selection with per-user intent and per-device ownership fences. */
|
|
16
|
+
export declare class ThreadSelectionManager {
|
|
17
|
+
private readonly bindings;
|
|
18
|
+
private readonly options;
|
|
19
|
+
private readonly revisions;
|
|
20
|
+
private readonly epochs;
|
|
21
|
+
private readonly names;
|
|
22
|
+
constructor(bindings: BindingManager, options: ThreadSelectionOptions);
|
|
23
|
+
private key;
|
|
24
|
+
private revision;
|
|
25
|
+
private epoch;
|
|
26
|
+
capture(openId: string, deviceId: string): SelectionFence;
|
|
27
|
+
beginIntent(openId: string, deviceId: string): SelectionFence;
|
|
28
|
+
reserveIntent(openId: string): number;
|
|
29
|
+
intent(openId: string, deviceId: string, revision: number): SelectionFence;
|
|
30
|
+
isCurrent(fence: SelectionFence): boolean;
|
|
31
|
+
isOwnershipCurrent(openId: string, deviceId: string, epoch: number): boolean;
|
|
32
|
+
invalidateDevice(openId: string, deviceId: string): void;
|
|
33
|
+
private current;
|
|
34
|
+
resolve(openId: string, deviceId: string): Promise<{
|
|
35
|
+
threadId: string;
|
|
36
|
+
threadName: string;
|
|
37
|
+
} | undefined>;
|
|
38
|
+
select(openId: string, deviceId: string, threadId: string, threadName?: string, fence?: SelectionFence): Promise<'selected' | 'stale'>;
|
|
39
|
+
completeNew(fence: SelectionFence, threadId: string, current?: () => boolean): Promise<'selected' | 'stale'>;
|
|
40
|
+
private commit;
|
|
41
|
+
observeCatalog(openId: string, deviceId: string, fence: SelectionFence, threads: ThreadSummary[], current?: () => boolean): Promise<'none' | 'deleted' | 'stale' | 'failed'>;
|
|
42
|
+
handleMissingThread(openId: string, deviceId: string, fence: SelectionFence, threadId: string, current?: () => boolean): Promise<'none' | 'deleted' | 'stale' | 'failed'>;
|
|
43
|
+
private clearDeleted;
|
|
44
|
+
}
|
|
45
|
+
export {};
|
|
46
|
+
//# sourceMappingURL=ThreadSelectionManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ThreadSelectionManager.d.ts","sourceRoot":"","sources":["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