openclaw-multi-auto 1.3.3 → 1.3.6
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/build-info.json +3 -3
- package/dist/canvas-host/a2ui/.bundle.hash +1 -1
- package/dist/plugin-sdk/{accounts-C3m65--E.js → accounts-BJAXxY46.js} +2 -2
- package/dist/plugin-sdk/{accounts-CNCCkdEF.js → accounts-C1j7HSL0.js} +3 -3
- package/dist/plugin-sdk/{accounts-BslAlVYS.js → accounts-DyFCXtHv.js} +2 -2
- package/dist/plugin-sdk/{active-listener-CkPnMUkB.js → active-listener-CftX5jLD.js} +2 -2
- package/dist/plugin-sdk/{api-key-rotation-BXnNsojA.js → api-key-rotation-8nyyt1kx.js} +2 -2
- package/dist/plugin-sdk/{audio-preflight-CtO4fFvp.js → audio-preflight-C_aSAPR1.js} +26 -26
- package/dist/plugin-sdk/{audio-transcription-runner-DnxvOS1-.js → audio-transcription-runner-CB53F7_7.js} +11 -11
- package/dist/plugin-sdk/{audit-membership-runtime-BpfoSk8M.js → audit-membership-runtime-BXndI4LG.js} +2 -2
- package/dist/plugin-sdk/{channel-activity-WJYxcJ3S.js → channel-activity-C5y8AgAV.js} +3 -3
- package/dist/plugin-sdk/{channel-web-dO5k3ubM.js → channel-web-DBTRO03V.js} +18 -18
- package/dist/plugin-sdk/{chrome-CjNTuJML.js → chrome-f00sZkDX.js} +6 -6
- package/dist/plugin-sdk/{commands-registry-CdYjoI0i.js → commands-registry-BJ_NxG2F.js} +4 -4
- package/dist/plugin-sdk/{common-oYc5vPFl.js → common-Cf27Jwxu.js} +2 -2
- package/dist/plugin-sdk/{config-B1z-UxQ3.js → config-CHQrpx-Q.js} +7 -7
- package/dist/plugin-sdk/{deliver-D5_6T567.js → deliver-DNEuetST.js} +10 -10
- package/dist/plugin-sdk/deliver-runtime-BFdqklJM.js +32 -0
- package/dist/plugin-sdk/deps-send-discord.runtime-DuqpYwU0.js +23 -0
- package/dist/plugin-sdk/deps-send-imessage.runtime-CZ2rS8Lb.js +22 -0
- package/dist/plugin-sdk/deps-send-signal.runtime-BdqiWhIh.js +21 -0
- package/dist/plugin-sdk/deps-send-slack.runtime-04s36qiC.js +19 -0
- package/dist/plugin-sdk/deps-send-telegram.runtime-LE5tkPvr.js +24 -0
- package/dist/plugin-sdk/deps-send-whatsapp.runtime-Bz57lobC.js +57 -0
- package/dist/plugin-sdk/{diagnostic-Bxxu0ig-.js → diagnostic-LYUUmjJ5.js} +2 -2
- package/dist/plugin-sdk/discord.js +6 -6
- package/dist/plugin-sdk/{errors-B3cHyZZA.js → errors-CtMWwS2Z.js} +1 -1
- package/dist/plugin-sdk/{fetch-guard-Dcgod0tg.js → fetch-guard-CxYB5Kg6.js} +2 -2
- package/dist/plugin-sdk/{fs-safe-BaKqI3G4.js → fs-safe-DtfhxbrI.js} +3 -3
- package/dist/plugin-sdk/{image-B2mQW9Rb.js → image-BwjYjRHx.js} +6 -6
- package/dist/plugin-sdk/{image-ops-Cbzr4U9l.js → image-ops-BnZKcbd6.js} +2 -2
- package/dist/plugin-sdk/image-runtime-B8twoubs.js +25 -0
- package/dist/plugin-sdk/{ir-ZEmrTr4J.js → ir-Z4hX67TJ.js} +7 -7
- package/dist/plugin-sdk/{local-roots-CIPRxA-4.js → local-roots-KhjQw04O.js} +4 -4
- package/dist/plugin-sdk/{logger-CvPFVOgT.js → logger-DHIIvMxj.js} +2 -2
- package/dist/plugin-sdk/{login-CCTew9bt.js → login-C31642Ld.js} +4 -4
- package/dist/plugin-sdk/{login-qr-BI3Vi_wJ.js → login-qr--y2SG_Ue.js} +5 -5
- package/dist/plugin-sdk/{manager-BEoYPn7R.js → manager-2UZBMCc7.js} +8 -8
- package/dist/plugin-sdk/manager-runtime-CMeLwose.js +15 -0
- package/dist/plugin-sdk/{outbound-ByOw1K6W.js → outbound-Ba0QUI5h.js} +5 -5
- package/dist/plugin-sdk/{outbound-attachment-BzVhxRRw.js → outbound-attachment-B1Laso-8.js} +2 -2
- package/dist/plugin-sdk/{path-alias-guards-sWayacde.js → path-alias-guards-C7Vm5DZ1.js} +1 -1
- package/dist/plugin-sdk/{paths-Dpg3qxcl.js → paths-DopV9PQG.js} +1 -1
- package/dist/plugin-sdk/{pi-embedded-helpers-DIxXkGJf.js → pi-embedded-helpers-DnA_OCzP.js} +16 -16
- package/dist/plugin-sdk/{pi-model-discovery-DM_2uFtj.js → pi-model-discovery-DdPqXk8f.js} +1 -1
- package/dist/plugin-sdk/pi-model-discovery-runtime-D8CJhtJY.js +8 -0
- package/dist/plugin-sdk/{pi-tools.before-tool-call.runtime-w1dqL_ty.js → pi-tools.before-tool-call.runtime-DxFHiLUE.js} +4 -4
- package/dist/plugin-sdk/{plugins-C4USiH29.js → plugins-CbCt4osF.js} +4 -4
- package/dist/plugin-sdk/{proxy-env-ET-rp8eg.js → proxy-env-C63mMdas.js} +1 -1
- package/dist/plugin-sdk/{proxy-fetch-uDXGKG3Z.js → proxy-fetch-Ch95c_Y2.js} +1 -1
- package/dist/plugin-sdk/{pw-ai-CyOt3RDA.js → pw-ai-DpJk62D4.js} +9 -9
- package/dist/plugin-sdk/{qmd-manager-BySdoVR7.js → qmd-manager-Ca-iSfEE.js} +7 -7
- package/dist/plugin-sdk/{query-expansion-C6uS-7lj.js → query-expansion-B_Xe41Ab.js} +4 -4
- package/dist/plugin-sdk/{redact-Bvxt1T_Q.js → redact-hp9TOulW.js} +1 -1
- package/dist/plugin-sdk/{reply-CTCSeQqW.js → reply-CovBlFea.js} +73 -73
- package/dist/plugin-sdk/{resolve-outbound-target-Bw8YNANu.js → resolve-outbound-target-BbrHgyUk.js} +2 -2
- package/dist/plugin-sdk/{run-with-concurrency-C_KCHwvf.js → run-with-concurrency-BR1DXa8T.js} +1 -1
- package/dist/plugin-sdk/runtime-whatsapp-login.runtime-SkO91TZH.js +10 -0
- package/dist/plugin-sdk/runtime-whatsapp-outbound.runtime-B0VWK5hm.js +19 -0
- package/dist/plugin-sdk/{send-C0w6xP2x.js → send-BTztm3D2.js} +6 -6
- package/dist/plugin-sdk/{send-qPyNGSe4.js → send-BXpXBwM_.js} +13 -13
- package/dist/plugin-sdk/{send-BZ6nYFZr.js → send-BvAtLLPl.js} +5 -5
- package/dist/plugin-sdk/{send-CFf-1V89.js → send-CWJUuG0i.js} +8 -8
- package/dist/plugin-sdk/{send-CY-Qfwia.js → send-EcglC4cG.js} +7 -7
- package/dist/plugin-sdk/{session-COrvpvUQ.js → session-k256LJZT.js} +3 -3
- package/dist/plugin-sdk/{skill-commands-DZqhtmiv.js → skill-commands-DoRqLzxm.js} +4 -4
- package/dist/plugin-sdk/{skills-Cw_vXEJb.js → skills-QudILG6e.js} +6 -6
- package/dist/plugin-sdk/slash-commands.runtime-DS6vCNSL.js +13 -0
- package/dist/plugin-sdk/slash-dispatch.runtime-BXrxb2wd.js +52 -0
- package/dist/plugin-sdk/slash-skill-commands.runtime-Bd6qQ2oT.js +16 -0
- package/dist/plugin-sdk/{store-CMHj6IIw.js → store-BbDQw3g6.js} +2 -2
- package/dist/plugin-sdk/subagent-registry-runtime-1uwQbuXj.js +52 -0
- package/dist/plugin-sdk/{tables-CSqrHsKL.js → tables-BhvloMKN.js} +1 -1
- package/dist/plugin-sdk/{thinking-DOnsR_A8.js → thinking-URzkT-3p.js} +7 -7
- package/dist/plugin-sdk/{tokens-BDr0Z9o3.js → tokens-B1PW5Ayy.js} +1 -1
- package/dist/plugin-sdk/{tool-images-eEfOVkzf.js → tool-images-xpqbP6RR.js} +2 -2
- package/dist/plugin-sdk/web-B74yhL2N.js +56 -0
- package/dist/plugin-sdk/{whatsapp-actions-xcleMoMv.js → whatsapp-actions-RcZ6vp61.js} +17 -17
- package/dist/plugin-sdk/whatsapp.js +50 -50
- package/extensions/googlechat/node_modules/.bin/openclaw +2 -2
- package/extensions/memory-core/node_modules/.bin/openclaw +2 -2
- package/package.json +13 -21
- package/scripts/npm_publish.sh +38 -84
- package/dist/plugin-sdk/deliver-runtime-C5dgvvga.js +0 -32
- package/dist/plugin-sdk/deps-send-discord.runtime-Dg4N7PHJ.js +0 -23
- package/dist/plugin-sdk/deps-send-imessage.runtime-0OEwzMQm.js +0 -22
- package/dist/plugin-sdk/deps-send-signal.runtime-BM1jRt3G.js +0 -21
- package/dist/plugin-sdk/deps-send-slack.runtime-1E3BYRdF.js +0 -19
- package/dist/plugin-sdk/deps-send-telegram.runtime-DNCxIflA.js +0 -24
- package/dist/plugin-sdk/deps-send-whatsapp.runtime-OLwr-9c8.js +0 -57
- package/dist/plugin-sdk/image-runtime-BFm45j49.js +0 -25
- package/dist/plugin-sdk/manager-runtime-DxclHQ4U.js +0 -15
- package/dist/plugin-sdk/pi-model-discovery-runtime-BuzvkvNR.js +0 -8
- package/dist/plugin-sdk/runtime-whatsapp-login.runtime-BxgRDkhc.js +0 -10
- package/dist/plugin-sdk/runtime-whatsapp-outbound.runtime-elOqrkfg.js +0 -19
- package/dist/plugin-sdk/slash-commands.runtime-D67JLweo.js +0 -13
- package/dist/plugin-sdk/slash-dispatch.runtime-DvcpvCJ0.js +0 -52
- package/dist/plugin-sdk/slash-skill-commands.runtime-BM1x3azR.js +0 -16
- package/dist/plugin-sdk/subagent-registry-runtime-1lbDyRzz.js +0 -52
- package/dist/plugin-sdk/web-BLyT64pW.js +0 -56
- package/vendor/libsignal-node/.eslintrc.json +0 -31
- package/vendor/libsignal-node/LICENSE +0 -621
- package/vendor/libsignal-node/README.md +0 -64
- package/vendor/libsignal-node/generate-proto.sh +0 -1
- package/vendor/libsignal-node/index.d.ts +0 -55
- package/vendor/libsignal-node/index.js +0 -10
- package/vendor/libsignal-node/node_modules/.bin/acorn +0 -21
- package/vendor/libsignal-node/node_modules/.bin/eslint +0 -21
- package/vendor/libsignal-node/node_modules/.bin/pbjs +0 -21
- package/vendor/libsignal-node/node_modules/.bin/pbts +0 -21
- package/vendor/libsignal-node/package.json +0 -24
- package/vendor/libsignal-node/protos/WhisperTextProtocol.proto +0 -28
- package/vendor/libsignal-node/src/.eslintrc.json +0 -31
- package/vendor/libsignal-node/src/WhisperTextProtocol.js +0 -933
- package/vendor/libsignal-node/src/base_key_type.js +0 -7
- package/vendor/libsignal-node/src/chain_type.js +0 -6
- package/vendor/libsignal-node/src/crypto.d.ts +0 -19
- package/vendor/libsignal-node/src/crypto.js +0 -98
- package/vendor/libsignal-node/src/curve.d.ts +0 -22
- package/vendor/libsignal-node/src/curve.js +0 -142
- package/vendor/libsignal-node/src/errors.js +0 -33
- package/vendor/libsignal-node/src/keyhelper.js +0 -45
- package/vendor/libsignal-node/src/numeric_fingerprint.js +0 -72
- package/vendor/libsignal-node/src/protobufs.js +0 -10
- package/vendor/libsignal-node/src/protocol_address.js +0 -40
- package/vendor/libsignal-node/src/queue_job.js +0 -69
- package/vendor/libsignal-node/src/session_builder.js +0 -164
- package/vendor/libsignal-node/src/session_cipher.js +0 -336
- package/vendor/libsignal-node/src/session_record.js +0 -316
|
@@ -1,316 +0,0 @@
|
|
|
1
|
-
// vim: ts=4:sw=4
|
|
2
|
-
|
|
3
|
-
const BaseKeyType = require('./base_key_type');
|
|
4
|
-
|
|
5
|
-
const CLOSED_SESSIONS_MAX = 40;
|
|
6
|
-
const SESSION_RECORD_VERSION = 'v1';
|
|
7
|
-
|
|
8
|
-
function assertBuffer(value) {
|
|
9
|
-
if (!Buffer.isBuffer(value)) {
|
|
10
|
-
throw new TypeError("Buffer required");
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class SessionEntry {
|
|
16
|
-
|
|
17
|
-
constructor() {
|
|
18
|
-
this._chains = {};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
toString() {
|
|
22
|
-
const baseKey = this.indexInfo && this.indexInfo.baseKey &&
|
|
23
|
-
this.indexInfo.baseKey.toString('base64');
|
|
24
|
-
return `<SessionEntry [baseKey=${baseKey}]>`;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
inspect() {
|
|
28
|
-
return this.toString();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
addChain(key, value) {
|
|
32
|
-
assertBuffer(key);
|
|
33
|
-
const id = key.toString('base64');
|
|
34
|
-
if (this._chains.hasOwnProperty(id)) {
|
|
35
|
-
throw new Error("Overwrite attempt");
|
|
36
|
-
}
|
|
37
|
-
this._chains[id] = value;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
getChain(key) {
|
|
41
|
-
assertBuffer(key);
|
|
42
|
-
return this._chains[key.toString('base64')];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
deleteChain(key) {
|
|
46
|
-
assertBuffer(key);
|
|
47
|
-
const id = key.toString('base64');
|
|
48
|
-
if (!this._chains.hasOwnProperty(id)) {
|
|
49
|
-
throw new ReferenceError("Not Found");
|
|
50
|
-
}
|
|
51
|
-
delete this._chains[id];
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
*chains() {
|
|
55
|
-
for (const [k, v] of Object.entries(this._chains)) {
|
|
56
|
-
yield [Buffer.from(k, 'base64'), v];
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
serialize() {
|
|
61
|
-
const data = {
|
|
62
|
-
registrationId: this.registrationId,
|
|
63
|
-
currentRatchet: {
|
|
64
|
-
ephemeralKeyPair: {
|
|
65
|
-
pubKey: this.currentRatchet.ephemeralKeyPair.pubKey.toString('base64'),
|
|
66
|
-
privKey: this.currentRatchet.ephemeralKeyPair.privKey.toString('base64')
|
|
67
|
-
},
|
|
68
|
-
lastRemoteEphemeralKey: this.currentRatchet.lastRemoteEphemeralKey.toString('base64'),
|
|
69
|
-
previousCounter: this.currentRatchet.previousCounter,
|
|
70
|
-
rootKey: this.currentRatchet.rootKey.toString('base64')
|
|
71
|
-
},
|
|
72
|
-
indexInfo: {
|
|
73
|
-
baseKey: this.indexInfo.baseKey.toString('base64'),
|
|
74
|
-
baseKeyType: this.indexInfo.baseKeyType,
|
|
75
|
-
closed: this.indexInfo.closed,
|
|
76
|
-
used: this.indexInfo.used,
|
|
77
|
-
created: this.indexInfo.created,
|
|
78
|
-
remoteIdentityKey: this.indexInfo.remoteIdentityKey.toString('base64')
|
|
79
|
-
},
|
|
80
|
-
_chains: this._serialize_chains(this._chains)
|
|
81
|
-
};
|
|
82
|
-
if (this.pendingPreKey) {
|
|
83
|
-
data.pendingPreKey = Object.assign({}, this.pendingPreKey);
|
|
84
|
-
data.pendingPreKey.baseKey = this.pendingPreKey.baseKey.toString('base64');
|
|
85
|
-
}
|
|
86
|
-
return data;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
static deserialize(data) {
|
|
90
|
-
const obj = new this();
|
|
91
|
-
obj.registrationId = data.registrationId;
|
|
92
|
-
obj.currentRatchet = {
|
|
93
|
-
ephemeralKeyPair: {
|
|
94
|
-
pubKey: Buffer.from(data.currentRatchet.ephemeralKeyPair.pubKey, 'base64'),
|
|
95
|
-
privKey: Buffer.from(data.currentRatchet.ephemeralKeyPair.privKey, 'base64')
|
|
96
|
-
},
|
|
97
|
-
lastRemoteEphemeralKey: Buffer.from(data.currentRatchet.lastRemoteEphemeralKey, 'base64'),
|
|
98
|
-
previousCounter: data.currentRatchet.previousCounter,
|
|
99
|
-
rootKey: Buffer.from(data.currentRatchet.rootKey, 'base64')
|
|
100
|
-
};
|
|
101
|
-
obj.indexInfo = {
|
|
102
|
-
baseKey: Buffer.from(data.indexInfo.baseKey, 'base64'),
|
|
103
|
-
baseKeyType: data.indexInfo.baseKeyType,
|
|
104
|
-
closed: data.indexInfo.closed,
|
|
105
|
-
used: data.indexInfo.used,
|
|
106
|
-
created: data.indexInfo.created,
|
|
107
|
-
remoteIdentityKey: Buffer.from(data.indexInfo.remoteIdentityKey, 'base64')
|
|
108
|
-
};
|
|
109
|
-
obj._chains = this._deserialize_chains(data._chains);
|
|
110
|
-
if (data.pendingPreKey) {
|
|
111
|
-
obj.pendingPreKey = Object.assign({}, data.pendingPreKey);
|
|
112
|
-
obj.pendingPreKey.baseKey = Buffer.from(data.pendingPreKey.baseKey, 'base64');
|
|
113
|
-
}
|
|
114
|
-
return obj;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
_serialize_chains(chains) {
|
|
118
|
-
const r = {};
|
|
119
|
-
for (const key of Object.keys(chains)) {
|
|
120
|
-
const c = chains[key];
|
|
121
|
-
const messageKeys = {};
|
|
122
|
-
for (const [idx, key] of Object.entries(c.messageKeys)) {
|
|
123
|
-
messageKeys[idx] = key.toString('base64');
|
|
124
|
-
}
|
|
125
|
-
r[key] = {
|
|
126
|
-
chainKey: {
|
|
127
|
-
counter: c.chainKey.counter,
|
|
128
|
-
key: c.chainKey.key && c.chainKey.key.toString('base64')
|
|
129
|
-
},
|
|
130
|
-
chainType: c.chainType,
|
|
131
|
-
messageKeys: messageKeys
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
return r;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
static _deserialize_chains(chains_data) {
|
|
138
|
-
const r = {};
|
|
139
|
-
for (const key of Object.keys(chains_data)) {
|
|
140
|
-
const c = chains_data[key];
|
|
141
|
-
const messageKeys = {};
|
|
142
|
-
for (const [idx, key] of Object.entries(c.messageKeys)) {
|
|
143
|
-
messageKeys[idx] = Buffer.from(key, 'base64');
|
|
144
|
-
}
|
|
145
|
-
r[key] = {
|
|
146
|
-
chainKey: {
|
|
147
|
-
counter: c.chainKey.counter,
|
|
148
|
-
key: c.chainKey.key && Buffer.from(c.chainKey.key, 'base64')
|
|
149
|
-
},
|
|
150
|
-
chainType: c.chainType,
|
|
151
|
-
messageKeys: messageKeys
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
return r;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
const migrations = [{
|
|
161
|
-
version: 'v1',
|
|
162
|
-
migrate: function migrateV1(data) {
|
|
163
|
-
const sessions = data._sessions;
|
|
164
|
-
if (data.registrationId) {
|
|
165
|
-
for (const key in sessions) {
|
|
166
|
-
if (!sessions[key].registrationId) {
|
|
167
|
-
sessions[key].registrationId = data.registrationId;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
} else {
|
|
171
|
-
for (const key in sessions) {
|
|
172
|
-
if (sessions[key].indexInfo.closed === -1) {
|
|
173
|
-
console.error('V1 session storage migration error: registrationId',
|
|
174
|
-
data.registrationId, 'for open session version',
|
|
175
|
-
data.version);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}];
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
class SessionRecord {
|
|
184
|
-
|
|
185
|
-
static createEntry() {
|
|
186
|
-
return new SessionEntry();
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
static migrate(data) {
|
|
190
|
-
let run = (data.version === undefined);
|
|
191
|
-
for (let i = 0; i < migrations.length; ++i) {
|
|
192
|
-
if (run) {
|
|
193
|
-
console.info("Migrating session to:", migrations[i].version);
|
|
194
|
-
migrations[i].migrate(data);
|
|
195
|
-
} else if (migrations[i].version === data.version) {
|
|
196
|
-
run = true;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
if (!run) {
|
|
200
|
-
throw new Error("Error migrating SessionRecord");
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
static deserialize(data) {
|
|
205
|
-
if (data.version !== SESSION_RECORD_VERSION) {
|
|
206
|
-
this.migrate(data);
|
|
207
|
-
}
|
|
208
|
-
const obj = new this();
|
|
209
|
-
if (data._sessions) {
|
|
210
|
-
for (const [key, entry] of Object.entries(data._sessions)) {
|
|
211
|
-
obj.sessions[key] = SessionEntry.deserialize(entry);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
return obj;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
constructor() {
|
|
218
|
-
this.sessions = {};
|
|
219
|
-
this.version = SESSION_RECORD_VERSION;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
serialize() {
|
|
223
|
-
const _sessions = {};
|
|
224
|
-
for (const [key, entry] of Object.entries(this.sessions)) {
|
|
225
|
-
_sessions[key] = entry.serialize();
|
|
226
|
-
}
|
|
227
|
-
return {
|
|
228
|
-
_sessions,
|
|
229
|
-
version: this.version
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
haveOpenSession() {
|
|
234
|
-
const openSession = this.getOpenSession();
|
|
235
|
-
return (!!openSession && typeof openSession.registrationId === 'number');
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
getSession(key) {
|
|
239
|
-
assertBuffer(key);
|
|
240
|
-
const session = this.sessions[key.toString('base64')];
|
|
241
|
-
if (session && session.indexInfo.baseKeyType === BaseKeyType.OURS) {
|
|
242
|
-
throw new Error("Tried to lookup a session using our basekey");
|
|
243
|
-
}
|
|
244
|
-
return session;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
getOpenSession() {
|
|
248
|
-
for (const session of Object.values(this.sessions)) {
|
|
249
|
-
if (!this.isClosed(session)) {
|
|
250
|
-
return session;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
setSession(session) {
|
|
256
|
-
this.sessions[session.indexInfo.baseKey.toString('base64')] = session;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
getSessions() {
|
|
260
|
-
// Return sessions ordered with most recently used first.
|
|
261
|
-
return Array.from(Object.values(this.sessions)).sort((a, b) => {
|
|
262
|
-
const aUsed = a.indexInfo.used || 0;
|
|
263
|
-
const bUsed = b.indexInfo.used || 0;
|
|
264
|
-
return aUsed === bUsed ? 0 : aUsed < bUsed ? 1 : -1;
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
closeSession(session) {
|
|
269
|
-
if (this.isClosed(session)) {
|
|
270
|
-
console.warn("Session already closed", session);
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
console.info("Closing session:", session);
|
|
274
|
-
session.indexInfo.closed = Date.now();
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
openSession(session) {
|
|
278
|
-
if (!this.isClosed(session)) {
|
|
279
|
-
console.warn("Session already open");
|
|
280
|
-
}
|
|
281
|
-
console.info("Opening session:", session);
|
|
282
|
-
session.indexInfo.closed = -1;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
isClosed(session) {
|
|
286
|
-
return session.indexInfo.closed !== -1;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
removeOldSessions() {
|
|
290
|
-
while (Object.keys(this.sessions).length > CLOSED_SESSIONS_MAX) {
|
|
291
|
-
let oldestKey;
|
|
292
|
-
let oldestSession;
|
|
293
|
-
for (const [key, session] of Object.entries(this.sessions)) {
|
|
294
|
-
if (session.indexInfo.closed !== -1 &&
|
|
295
|
-
(!oldestSession || session.indexInfo.closed < oldestSession.indexInfo.closed)) {
|
|
296
|
-
oldestKey = key;
|
|
297
|
-
oldestSession = session;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
if (oldestKey) {
|
|
301
|
-
console.info("Removing old closed session:", oldestSession);
|
|
302
|
-
delete this.sessions[oldestKey];
|
|
303
|
-
} else {
|
|
304
|
-
throw new Error('Corrupt sessions object');
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
deleteAllSessions() {
|
|
310
|
-
for (const key of Object.keys(this.sessions)) {
|
|
311
|
-
delete this.sessions[key];
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
module.exports = SessionRecord;
|