@drakkar.software/octobot-client 0.4.0 → 0.8.0
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 +1 -1
- package/dist/client/adapters/accounts.d.ts +5 -5
- package/dist/client/adapters/accounts.d.ts.map +1 -1
- package/dist/client/adapters/accounts.js +1 -4
- package/dist/client/adapters/accounts.js.map +1 -1
- package/dist/client/adapters/automations.d.ts.map +1 -1
- package/dist/client/adapters/automations.js +3 -2
- package/dist/client/adapters/automations.js.map +1 -1
- package/dist/client/connect/readOnly.d.ts +1 -1
- package/dist/client/connect/readOnly.d.ts.map +1 -1
- package/dist/client/connect/readOnly.js +27 -9
- package/dist/client/connect/readOnly.js.map +1 -1
- package/dist/client/core/views.d.ts +43 -21
- package/dist/client/core/views.d.ts.map +1 -1
- package/dist/client/core/views.js +38 -7
- package/dist/client/core/views.js.map +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/identity/index.d.ts +1 -1
- package/dist/identity/index.d.ts.map +1 -1
- package/dist/identity/index.js +1 -1
- package/dist/identity/index.js.map +1 -1
- package/dist/identity/pairingRequest.d.ts +20 -0
- package/dist/identity/pairingRequest.d.ts.map +1 -1
- package/dist/identity/pairingRequest.js +28 -9
- package/dist/identity/pairingRequest.js.map +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/protocol/index.d.ts +4 -2
- package/dist/protocol/index.d.ts.map +1 -1
- package/dist/protocol/index.js +4 -2
- package/dist/protocol/index.js.map +1 -1
- package/dist/protocol/proposal.d.ts +14 -27
- package/dist/protocol/proposal.d.ts.map +1 -1
- package/dist/protocol/proposal.js +22 -3
- package/dist/protocol/proposal.js.map +1 -1
- package/dist/protocol/proposalSummary.d.ts +23 -0
- package/dist/protocol/proposalSummary.d.ts.map +1 -0
- package/dist/protocol/proposalSummary.js +28 -0
- package/dist/protocol/proposalSummary.js.map +1 -0
- package/dist/protocol/qrFrames.d.ts +146 -0
- package/dist/protocol/qrFrames.d.ts.map +1 -0
- package/dist/protocol/qrFrames.js +307 -0
- package/dist/protocol/qrFrames.js.map +1 -0
- package/dist/protocol/state.d.ts +30 -16
- package/dist/protocol/state.d.ts.map +1 -1
- package/dist/protocol/state.js +67 -28
- package/dist/protocol/state.js.map +1 -1
- package/dist/transport/urls.d.ts +2 -8
- package/dist/transport/urls.d.ts.map +1 -1
- package/dist/transport/urls.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import { keccak_256 } from '@noble/hashes/sha3.js';
|
|
2
|
+
import { toHex } from '../internal/bytes.js';
|
|
3
|
+
/** Generic multi-frame QR transport: splits an oversized string payload into
|
|
4
|
+
* scannable QR frames and reassembles them on the other end. Deliberately
|
|
5
|
+
* payload-agnostic (plain string in, plain string out) — it knows nothing
|
|
6
|
+
* about action proposals or pairing payloads specifically, which is what
|
|
7
|
+
* lets a reassembled payload flow back through whatever generic classifier
|
|
8
|
+
* the caller already uses (`classifyScannedCode`) instead of a
|
|
9
|
+
* codec-specific one.
|
|
10
|
+
*
|
|
11
|
+
* This package never renders a QR image itself, here as everywhere else: it
|
|
12
|
+
* returns the strings to encode and consumes the strings a scanner read. */
|
|
13
|
+
export const QR_FRAME_CODEC = 'OBQR2';
|
|
14
|
+
/** `OBQR2|<kind>|<8 hex>|<2-digit index>|<2-digit total>|` — constant width,
|
|
15
|
+
* so the body can always be recovered with a fixed `slice`, never a
|
|
16
|
+
* `split('|')` (the body is itself often JSON and freely contains `|`). */
|
|
17
|
+
export const QR_FRAME_HEADER_LENGTH = 23;
|
|
18
|
+
/** v11 @ ECL M (a typical QR library default) holds 251 bytes; 11 bytes of
|
|
19
|
+
* slack against a different segmentation choice or a future header field.
|
|
20
|
+
* 61 modules at a ~220pt display box stays comfortably scannable. */
|
|
21
|
+
export const QR_FRAME_MAX_BYTES = 240;
|
|
22
|
+
export const QR_FRAME_BODY_MAX_BYTES = QR_FRAME_MAX_BYTES - QR_FRAME_HEADER_LENGTH;
|
|
23
|
+
/** At or below this, `encodeQrFrames` returns the payload UNFRAMED — no
|
|
24
|
+
* prefix, byte-identical to what a caller would have rendered directly.
|
|
25
|
+
* Keeps every single-frame payload on the exact same path it uses without
|
|
26
|
+
* this module at all. */
|
|
27
|
+
export const QR_SINGLE_FRAME_MAX_BYTES = 300;
|
|
28
|
+
/** ~21.4 KB ceiling (99 * 217 body bytes). */
|
|
29
|
+
export const QR_MAX_FRAMES = 99;
|
|
30
|
+
/** Recommended display cadence for a producer cycling frames: ~4 fps, well
|
|
31
|
+
* above the ~65-130ms a phone camera needs to lock a code, and below the
|
|
32
|
+
* 500ms identical-event throttle scanner libraries commonly apply (which
|
|
33
|
+
* only ever compares against the immediately previous event, so distinct
|
|
34
|
+
* cycling frames are never throttled). */
|
|
35
|
+
export const QR_FRAME_INTERVAL_MS = 250;
|
|
36
|
+
/** How long a partially-collected transfer survives without a new frame
|
|
37
|
+
* before the accumulator drops it, so a walked-away-from transfer cannot
|
|
38
|
+
* poison the next one. Exported, not just defaulted, because a consumer
|
|
39
|
+
* typically needs the same window a second time for its own UI timer (the
|
|
40
|
+
* accumulator only re-checks staleness on the next `accept()` call, so
|
|
41
|
+
* nothing clears a progress indicator that has simply stopped moving) —
|
|
42
|
+
* and a consumer that hardcodes its own copy silently keeps the old window
|
|
43
|
+
* the day this one is retuned. */
|
|
44
|
+
export const QR_FRAME_STALE_MS = 8000;
|
|
45
|
+
/** A frame's kind tag is ADVISORY and opaque to this module: nothing here
|
|
46
|
+
* parses the body or checks that it matches the tag. It exists so a scanner
|
|
47
|
+
* that accepts framed transfers of one kind can drop another kind's
|
|
48
|
+
* transfer at its FIRST frame, instead of collecting every frame and only
|
|
49
|
+
* discovering the mismatch after reassembly. A scanner that accepts
|
|
50
|
+
* everything, or that refuses frames outright, can ignore it entirely. */
|
|
51
|
+
export const QR_FRAME_KIND_UNSPECIFIED = '-';
|
|
52
|
+
export const QR_FRAME_KIND_ACTION_PROPOSAL = 'p';
|
|
53
|
+
export const QR_FRAME_KIND_READ_ONLY_PAIRING = 'r';
|
|
54
|
+
/** One character, so the header stays fixed-width. */
|
|
55
|
+
const KIND_RE = /^[A-Za-z-]$/;
|
|
56
|
+
export class QrPayloadTooLargeError extends Error {
|
|
57
|
+
requiredFrames;
|
|
58
|
+
maxFrames;
|
|
59
|
+
constructor(requiredFrames, maxFrames) {
|
|
60
|
+
super(`Payload requires ${requiredFrames} QR frames, exceeding the ${maxFrames}-frame limit`);
|
|
61
|
+
this.name = 'QrPayloadTooLargeError';
|
|
62
|
+
this.requiredFrames = requiredFrames;
|
|
63
|
+
this.maxFrames = maxFrames;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const FRAME_PREFIX_RE = /^OBQR2\|([A-Za-z-])\|([0-9a-f]{8})\|(\d{2})\|(\d{2})\|/;
|
|
67
|
+
/** First 4 bytes of keccak256(payload) — deterministic (no RNG to stub in
|
|
68
|
+
* tests), and doubles as a free integrity check on reassembly. */
|
|
69
|
+
function transferIdFor(payload) {
|
|
70
|
+
return toHex(keccak_256(new TextEncoder().encode(payload)).slice(0, 4));
|
|
71
|
+
}
|
|
72
|
+
/** UTF-8 byte length of one code point. A lone surrogate (never produced by
|
|
73
|
+
* well-formed `JSON.stringify` output, but handled defensively) is mapped to
|
|
74
|
+
* 3 bytes — the correct WTF-8 length, not just a safety margin. */
|
|
75
|
+
function utf8ByteLengthOfCodePoint(ch) {
|
|
76
|
+
const cp = ch.codePointAt(0) ?? 0;
|
|
77
|
+
if (cp <= 0x7f)
|
|
78
|
+
return 1;
|
|
79
|
+
if (cp <= 0x7ff)
|
|
80
|
+
return 2;
|
|
81
|
+
if (cp <= 0xffff)
|
|
82
|
+
return 3;
|
|
83
|
+
return 4;
|
|
84
|
+
}
|
|
85
|
+
function utf8ByteLength(payload) {
|
|
86
|
+
let n = 0;
|
|
87
|
+
for (const ch of payload)
|
|
88
|
+
n += utf8ByteLengthOfCodePoint(ch);
|
|
89
|
+
return n;
|
|
90
|
+
}
|
|
91
|
+
/** Split by a UTF-8 BYTE budget, iterating with `for...of` — which yields
|
|
92
|
+
* whole code points, so a cut can never land inside a surrogate pair. Byte
|
|
93
|
+
* (not character) budgeting matters too: QR byte-mode capacity is bytes, so
|
|
94
|
+
* a character budget would pass every ASCII test and silently overflow on a
|
|
95
|
+
* French- or CJK-language payload. Only used to find the MINIMUM frame
|
|
96
|
+
* count (a tight greedy pack); the actual split for that count is
|
|
97
|
+
* `splitIntoFrameCount` below, which balances sizes instead of dumping
|
|
98
|
+
* everything short into a near-empty last frame. */
|
|
99
|
+
function splitByUtf8Budget(payload, budgetBytes) {
|
|
100
|
+
const out = [];
|
|
101
|
+
let cur = '';
|
|
102
|
+
let curBytes = 0;
|
|
103
|
+
for (const ch of payload) {
|
|
104
|
+
const n = utf8ByteLengthOfCodePoint(ch);
|
|
105
|
+
if (curBytes + n > budgetBytes) {
|
|
106
|
+
out.push(cur);
|
|
107
|
+
cur = '';
|
|
108
|
+
curBytes = 0;
|
|
109
|
+
}
|
|
110
|
+
cur += ch;
|
|
111
|
+
curBytes += n;
|
|
112
|
+
}
|
|
113
|
+
if (cur)
|
|
114
|
+
out.push(cur);
|
|
115
|
+
return out;
|
|
116
|
+
}
|
|
117
|
+
/** Split into exactly `frameCount` frames, each carrying as near an equal
|
|
118
|
+
* byte share as code-point boundaries allow. Keeps every frame at the same
|
|
119
|
+
* QR version/density: a code that visibly gets sparser on its last frame
|
|
120
|
+
* sends a scanner's autofocus hunting.
|
|
121
|
+
*
|
|
122
|
+
* The target is recomputed from the bytes and frames still OUTSTANDING after
|
|
123
|
+
* each flush, rather than precomputed once per index. That distinction is
|
|
124
|
+
* load-bearing, not a refactor. A frame can only end on a code-point
|
|
125
|
+
* boundary, so it undershoots its target by up to one code point's width;
|
|
126
|
+
* with a fixed target array that shortfall is never reclaimed and every
|
|
127
|
+
* frame repeats it, so the accumulated slack eventually spills past the last
|
|
128
|
+
* planned frame and opens another one. On multi-byte payloads that was the
|
|
129
|
+
* normal outcome, not an edge case: `'日'.repeat(121)` (363 bytes, 2 frames'
|
|
130
|
+
* worth) came out as three frames of 180/180/3 bytes, i.e. exactly the
|
|
131
|
+
* near-empty trailing frame this function exists to avoid, and a 20,996-byte
|
|
132
|
+
* emoji payload was rejected as needing 100 frames when 98 sufficed.
|
|
133
|
+
* Recomputing lets each frame absorb the previous one's shortfall, so the
|
|
134
|
+
* split lands in `frameCount` frames and stays balanced. */
|
|
135
|
+
function splitIntoFrameCount(payload, frameCount) {
|
|
136
|
+
let remainingBytes = utf8ByteLength(payload);
|
|
137
|
+
let remainingFrames = frameCount;
|
|
138
|
+
const targetFor = () => (remainingFrames > 0
|
|
139
|
+
? Math.min(Math.ceil(remainingBytes / remainingFrames), QR_FRAME_BODY_MAX_BYTES)
|
|
140
|
+
: QR_FRAME_BODY_MAX_BYTES);
|
|
141
|
+
const out = [];
|
|
142
|
+
let cur = '';
|
|
143
|
+
let curBytes = 0;
|
|
144
|
+
let target = targetFor();
|
|
145
|
+
for (const ch of payload) {
|
|
146
|
+
const n = utf8ByteLengthOfCodePoint(ch);
|
|
147
|
+
if (curBytes + n > target) {
|
|
148
|
+
out.push(cur);
|
|
149
|
+
remainingBytes -= curBytes;
|
|
150
|
+
remainingFrames -= 1;
|
|
151
|
+
target = targetFor();
|
|
152
|
+
cur = '';
|
|
153
|
+
curBytes = 0;
|
|
154
|
+
}
|
|
155
|
+
cur += ch;
|
|
156
|
+
curBytes += n;
|
|
157
|
+
}
|
|
158
|
+
if (cur)
|
|
159
|
+
out.push(cur);
|
|
160
|
+
return out;
|
|
161
|
+
}
|
|
162
|
+
/** Split an already-encoded string payload into scannable QR frames. Returns
|
|
163
|
+
* `[payload]` UNCHANGED when it fits `QR_SINGLE_FRAME_MAX_BYTES`, so a short
|
|
164
|
+
* payload never gains a prefix and `opts.kind` is simply unused. Throws
|
|
165
|
+
* `QrPayloadTooLargeError` above `QR_MAX_FRAMES`.
|
|
166
|
+
*
|
|
167
|
+
* `opts.kind` is the advisory tag described on `QR_FRAME_KIND_UNSPECIFIED`;
|
|
168
|
+
* it must be a single `[A-Za-z-]` character, because the header is
|
|
169
|
+
* fixed-width. Anything else throws rather than emitting frames that would
|
|
170
|
+
* not re-parse. */
|
|
171
|
+
export function encodeQrFrames(payload, opts) {
|
|
172
|
+
const kind = opts?.kind ?? QR_FRAME_KIND_UNSPECIFIED;
|
|
173
|
+
if (!KIND_RE.test(kind)) {
|
|
174
|
+
throw new Error(`invalid QR frame kind ${JSON.stringify(kind)}: expected a single [A-Za-z-] character`);
|
|
175
|
+
}
|
|
176
|
+
if (utf8ByteLength(payload) <= QR_SINGLE_FRAME_MAX_BYTES)
|
|
177
|
+
return [payload];
|
|
178
|
+
const minFrames = splitByUtf8Budget(payload, QR_FRAME_BODY_MAX_BYTES).length;
|
|
179
|
+
if (minFrames > QR_MAX_FRAMES)
|
|
180
|
+
throw new QrPayloadTooLargeError(minFrames, QR_MAX_FRAMES);
|
|
181
|
+
const bodies = splitIntoFrameCount(payload, minFrames);
|
|
182
|
+
// The balancing split can rarely run one or two frames longer than
|
|
183
|
+
// `minFrames` (see splitIntoFrameCount) — re-check the ceiling against the
|
|
184
|
+
// actual result rather than trusting the estimate.
|
|
185
|
+
if (bodies.length > QR_MAX_FRAMES)
|
|
186
|
+
throw new QrPayloadTooLargeError(bodies.length, QR_MAX_FRAMES);
|
|
187
|
+
const transferId = transferIdFor(payload);
|
|
188
|
+
const total = bodies.length;
|
|
189
|
+
return bodies.map((body, index) => (`${QR_FRAME_CODEC}|${kind}|${transferId}|${String(index).padStart(2, '0')}|${String(total).padStart(2, '0')}|${body}`));
|
|
190
|
+
}
|
|
191
|
+
/** Cheap prefix test — no parse, no throw. A string that passes this but
|
|
192
|
+
* fails `parseQrFrame` is OUR garbage, not an unknown code, so the caller
|
|
193
|
+
* must drop it silently rather than fall through to generic classification. */
|
|
194
|
+
export function isQrFrame(data) {
|
|
195
|
+
return data.startsWith(`${QR_FRAME_CODEC}|`);
|
|
196
|
+
}
|
|
197
|
+
/** Parse one frame. `null` on any malformed header, bad kind, bad hex,
|
|
198
|
+
* non-numeric index/total, `index >= total`, `total === 0`, or empty body.
|
|
199
|
+
* The body is returned verbatim — it is recovered by fixed offset, never
|
|
200
|
+
* `split('|')`, so it may itself contain `|`. */
|
|
201
|
+
export function parseQrFrame(data) {
|
|
202
|
+
const m = FRAME_PREFIX_RE.exec(data);
|
|
203
|
+
if (!m)
|
|
204
|
+
return null;
|
|
205
|
+
const [, kind, transferId, indexStr, totalStr] = m;
|
|
206
|
+
const index = Number(indexStr);
|
|
207
|
+
const total = Number(totalStr);
|
|
208
|
+
if (total === 0 || index >= total)
|
|
209
|
+
return null;
|
|
210
|
+
const body = data.slice(QR_FRAME_HEADER_LENGTH);
|
|
211
|
+
if (!body)
|
|
212
|
+
return null;
|
|
213
|
+
// The encoder never emits a body over this, so one that exceeds it did not
|
|
214
|
+
// come from `encodeQrFrames`. Rejecting here rather than buffering it keeps
|
|
215
|
+
// the ceiling a property of the FORMAT instead of only of the encoder: an
|
|
216
|
+
// accumulator fed from something other than a camera (a deep link, a paste,
|
|
217
|
+
// an NFC read) would otherwise retain an unbounded body per frame slot.
|
|
218
|
+
if (utf8ByteLength(body) > QR_FRAME_BODY_MAX_BYTES)
|
|
219
|
+
return null;
|
|
220
|
+
return { kind, transferId, index, total, body };
|
|
221
|
+
}
|
|
222
|
+
/** Stateful reassembly buffer, one per scanner instance (never a module
|
|
223
|
+
* singleton — several screens may each hold their own scanner). Duplicate
|
|
224
|
+
* frames are the common case (a ~30fps camera reads the same displayed
|
|
225
|
+
* frame several times before it cycles), so duplicate detection is an O(1)
|
|
226
|
+
* `buf[i] !== undefined` check, not an allocation.
|
|
227
|
+
*
|
|
228
|
+
* `acceptKind`, when given, is consulted on every frame BEFORE any state is
|
|
229
|
+
* touched: a refused kind returns `{status:'ignored'}` and buffers nothing,
|
|
230
|
+
* which is what lets a single-purpose scanner sit in front of a producer
|
|
231
|
+
* cycling some other kind without ever filling its buffer. Defaults to
|
|
232
|
+
* accepting every kind. */
|
|
233
|
+
export function createQrFrameAccumulator(opts) {
|
|
234
|
+
const staleMs = opts?.staleMs ?? QR_FRAME_STALE_MS;
|
|
235
|
+
const now = opts?.now ?? Date.now;
|
|
236
|
+
const acceptKind = opts?.acceptKind;
|
|
237
|
+
let state = null;
|
|
238
|
+
return {
|
|
239
|
+
accept(data) {
|
|
240
|
+
if (!isQrFrame(data))
|
|
241
|
+
return { status: 'ignored' };
|
|
242
|
+
const frame = parseQrFrame(data);
|
|
243
|
+
if (!frame)
|
|
244
|
+
return { status: 'discarded' };
|
|
245
|
+
if (acceptKind && !acceptKind(frame.kind))
|
|
246
|
+
return { status: 'ignored' };
|
|
247
|
+
// Captured before the stale-drop below: a timed-out collection still
|
|
248
|
+
// counts as "there was a prior collection being interrupted" for the
|
|
249
|
+
// 'restarted' vs 'progress' distinction.
|
|
250
|
+
const hadPriorState = state !== null;
|
|
251
|
+
if (state && now() - state.lastAcceptedAt > staleMs)
|
|
252
|
+
state = null;
|
|
253
|
+
// `kind` participates in transfer identity even though `transferId` is
|
|
254
|
+
// a hash of the payload alone: the same payload framed under two kinds
|
|
255
|
+
// shares a transferId, and treating those as one transfer would
|
|
256
|
+
// interleave two producers' frames into a single buffer.
|
|
257
|
+
const isSameTransfer = state !== null
|
|
258
|
+
&& state.transferId === frame.transferId
|
|
259
|
+
&& state.kind === frame.kind
|
|
260
|
+
&& state.total === frame.total;
|
|
261
|
+
let s;
|
|
262
|
+
if (isSameTransfer && state) {
|
|
263
|
+
s = state;
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
s = {
|
|
267
|
+
kind: frame.kind,
|
|
268
|
+
transferId: frame.transferId,
|
|
269
|
+
total: frame.total,
|
|
270
|
+
buf: new Array(frame.total).fill(undefined),
|
|
271
|
+
received: 0,
|
|
272
|
+
lastAcceptedAt: now(),
|
|
273
|
+
};
|
|
274
|
+
state = s;
|
|
275
|
+
}
|
|
276
|
+
if (s.buf[frame.index] === undefined) {
|
|
277
|
+
s.buf[frame.index] = frame.body;
|
|
278
|
+
s.received += 1;
|
|
279
|
+
}
|
|
280
|
+
s.lastAcceptedAt = now();
|
|
281
|
+
if (s.received < s.total) {
|
|
282
|
+
const progress = {
|
|
283
|
+
kind: s.kind,
|
|
284
|
+
transferId: s.transferId,
|
|
285
|
+
received: s.received,
|
|
286
|
+
total: s.total,
|
|
287
|
+
};
|
|
288
|
+
return { status: hadPriorState && !isSameTransfer ? 'restarted' : 'progress', progress };
|
|
289
|
+
}
|
|
290
|
+
// Complete — emitted exactly once: state resets before returning,
|
|
291
|
+
// whether the integrity check passes or not.
|
|
292
|
+
const payload = s.buf.join('');
|
|
293
|
+
const intact = transferIdFor(payload) === s.transferId;
|
|
294
|
+
state = null;
|
|
295
|
+
return intact ? { status: 'complete', payload } : { status: 'corrupt' };
|
|
296
|
+
},
|
|
297
|
+
progress() {
|
|
298
|
+
return state
|
|
299
|
+
? { kind: state.kind, transferId: state.transferId, received: state.received, total: state.total }
|
|
300
|
+
: null;
|
|
301
|
+
},
|
|
302
|
+
reset() {
|
|
303
|
+
state = null;
|
|
304
|
+
},
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
//# sourceMappingURL=qrFrames.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qrFrames.js","sourceRoot":"","sources":["../../src/protocol/qrFrames.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAE5C;;;;;;;;;6EAS6E;AAE7E,MAAM,CAAC,MAAM,cAAc,GAAG,OAAO,CAAA;AACrC;;4EAE4E;AAC5E,MAAM,CAAC,MAA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kflowStatus, UserAction, AutomationActionResult, AccountActionResult, Account as ProtocolAccount, ExchangeConfig, DetailedAsset, Strategy as ProtocolStrategy } from '@drakkar.software/octobot-protocol';
|
|
2
2
|
import type { StrategyKind } from './strategy/kinds.js';
|
|
3
|
+
/** A coarse run-status classification for `AutomationView` — never itself on
|
|
4
|
+
* the wire (the real wire enum is `AutomationState.status`'s `WorkflowStatus`,
|
|
5
|
+
* 7 values); this is a client-side categorization, computed fresh by
|
|
6
|
+
* `workflowStatusToAutomationStatus` below, so it stays a local type here
|
|
7
|
+
* rather than living in the protocol package. */
|
|
8
|
+
export type AutomationRunStatus = 'live' | 'draft' | 'stopped';
|
|
3
9
|
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
4
10
|
export declare function cachedByDoc<T>(compute: (doc: Record<string, unknown>) => T, empty: T): (doc: unknown) => T;
|
|
5
11
|
/** Derives a `StrategyKind` from a protocol Strategy's configuration —
|
|
@@ -18,7 +24,6 @@ export declare const parseNodeUserActions: (doc: unknown) => UserAction[];
|
|
|
18
24
|
/** Protocol workflow status → a coarse live/draft/stopped classification.
|
|
19
25
|
* 'canceled', 'failed', 'completed' and any future unknown value map to
|
|
20
26
|
* 'stopped' so a non-running workflow never renders as a live bot. */
|
|
21
|
-
export type AutomationRunStatus = 'live' | 'draft' | 'stopped';
|
|
22
27
|
export declare function workflowStatusToAutomationStatus(status: WorkflowStatus | string | undefined): AutomationRunStatus;
|
|
23
28
|
/** Node-reported failure for an automation: error_message is the protocol
|
|
24
29
|
* enum-ish summary, error the detailed string. */
|
|
@@ -32,16 +37,10 @@ export declare function normalizeNodeAssets(raw: unknown): DetailedAsset[];
|
|
|
32
37
|
export declare function automationHoldings(state: AutomationState): DetailedAsset[];
|
|
33
38
|
export declare const parseNodeAccounts: (doc: unknown) => ProtocolAccount[];
|
|
34
39
|
export declare const parseNodeExchangeConfigs: (doc: unknown) => ExchangeConfig[];
|
|
35
|
-
/**
|
|
36
|
-
*
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
total: number;
|
|
40
|
-
free: number;
|
|
41
|
-
used: number;
|
|
42
|
-
};
|
|
43
|
-
/** Map node-reported asset quantities to a flat holdings list. */
|
|
44
|
-
export declare function accountHoldingsFromNodeState(na: ProtocolAccount): Holding[];
|
|
40
|
+
/** Node-reported asset quantities for an account, flattened. Kept as its own
|
|
41
|
+
* named function (rather than inlining `normalizeNodeAssets(na.assets)`
|
|
42
|
+
* at call sites) so `accountViewOf`'s intent reads clearly. */
|
|
43
|
+
export declare function accountHoldingsFromNodeState(na: ProtocolAccount): DetailedAsset[];
|
|
45
44
|
export declare function automationResultOf(action: UserAction): AutomationActionResult | null;
|
|
46
45
|
export declare function accountResultOf(action: UserAction): AccountActionResult | null;
|
|
47
46
|
export declare function actionErrorDetails(action: UserAction): string | null;
|
|
@@ -71,11 +70,26 @@ export declare function targetAccountIdsOf(action: UserAction): string[];
|
|
|
71
70
|
* with no explicit `account_ids` refreshes every account, so it counts as
|
|
72
71
|
* targeting all of them. */
|
|
73
72
|
export declare function actionTargetsAccount(action: UserAction, accountId: string): boolean;
|
|
74
|
-
/** The strategy (id, version)
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* record. The newest action targeting
|
|
78
|
-
* supersedes the create).
|
|
73
|
+
/** The strategy (id, version) every automation referenced in `actions` runs,
|
|
74
|
+
* recovered from the action history in one pass: node AutomationStates
|
|
75
|
+
* carry no strategy reference — the automation_create / automation_edit
|
|
76
|
+
* configurations are the only wire record. The newest action targeting an
|
|
77
|
+
* automation wins (an edit supersedes the create). Prefer this over calling
|
|
78
|
+
* `automationStrategyRefOf` once per automation against the same `actions`
|
|
79
|
+
* array — that repeats the full scan per automation (O(automations ×
|
|
80
|
+
* actions)); this does the equivalent work once (O(actions)). */
|
|
81
|
+
export declare function automationStrategyRefsOf(actions: UserAction[]): Map<string, {
|
|
82
|
+
id: string;
|
|
83
|
+
version?: string;
|
|
84
|
+
}>;
|
|
85
|
+
/** The strategy (id, version) one automation runs, scanning `actions` once
|
|
86
|
+
* for just that id — a deliberately separate, targeted pass rather than
|
|
87
|
+
* `automationStrategyRefsOf(actions).get(automationId)`, so a single lookup
|
|
88
|
+
* doesn't pay for building a map entry for every OTHER automation in the
|
|
89
|
+
* action history too. Resolving more than one automation against the same
|
|
90
|
+
* `actions` array should call `automationStrategyRefsOf` once instead — this
|
|
91
|
+
* rescans on every call, which is fine for one-off lookups but O(automations
|
|
92
|
+
* × actions) in a loop. */
|
|
79
93
|
export declare function automationStrategyRefOf(actions: UserAction[], automationId: string): {
|
|
80
94
|
id: string;
|
|
81
95
|
version?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/protocol/state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACd,UAAU,EACV,sBAAsB,EACtB,mBAAmB,EAenB,OAAO,IAAI,eAAe,EAC1B,cAAc,EACd,aAAa,EACb,QAAQ,IAAI,gBAAgB,EAC7B,MAAM,oCAAoC,CAAA;AAE3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/protocol/state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACd,UAAU,EACV,sBAAsB,EACtB,mBAAmB,EAenB,OAAO,IAAI,eAAe,EAC1B,cAAc,EACd,aAAa,EACb,QAAQ,IAAI,gBAAgB,EAC7B,MAAM,oCAAoC,CAAA;AAE3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAEvD;;;;kDAIkD;AAClD,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAA;AAQ9D,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzE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ocol/state.js
CHANGED
|
@@ -69,6 +69,9 @@ export const parseNodeUserActions = cachedByDoc((doc) => {
|
|
|
69
69
|
return EMPTY_USER_ACTIONS;
|
|
70
70
|
return doc.user_actions.filter((entry) => isRecord(entry) && typeof entry.id === 'string');
|
|
71
71
|
}, EMPTY_USER_ACTIONS);
|
|
72
|
+
/** Protocol workflow status → a coarse live/draft/stopped classification.
|
|
73
|
+
* 'canceled', 'failed', 'completed' and any future unknown value map to
|
|
74
|
+
* 'stopped' so a non-running workflow never renders as a live bot. */
|
|
72
75
|
export function workflowStatusToAutomationStatus(status) {
|
|
73
76
|
switch (status) {
|
|
74
77
|
case 'scheduled':
|
|
@@ -128,15 +131,11 @@ export const parseNodeExchangeConfigs = cachedByDoc((doc) => {
|
|
|
128
131
|
return EMPTY_EXCHANGE_CONFIGS;
|
|
129
132
|
return doc.exchange_configs.filter((entry) => isRecord(entry) && typeof entry.id === 'string');
|
|
130
133
|
}, EMPTY_EXCHANGE_CONFIGS);
|
|
131
|
-
/**
|
|
134
|
+
/** Node-reported asset quantities for an account, flattened. Kept as its own
|
|
135
|
+
* named function (rather than inlining `normalizeNodeAssets(na.assets)`
|
|
136
|
+
* at call sites) so `accountViewOf`'s intent reads clearly. */
|
|
132
137
|
export function accountHoldingsFromNodeState(na) {
|
|
133
|
-
|
|
134
|
-
return assets.map((a) => ({
|
|
135
|
-
symbol: a.symbol,
|
|
136
|
-
total: a.total,
|
|
137
|
-
free: a.available,
|
|
138
|
-
used: Math.max(0, a.total - a.available),
|
|
139
|
-
}));
|
|
138
|
+
return normalizeNodeAssets(na.assets);
|
|
140
139
|
}
|
|
141
140
|
// ── Typed user-action accessors ──────────────────────────────────────────────
|
|
142
141
|
// Discriminated reads over UserAction.result / .configuration — replace
|
|
@@ -249,34 +248,74 @@ export function actionTargetsAccount(action, accountId) {
|
|
|
249
248
|
return true;
|
|
250
249
|
return targetAccountIdsOf(action).includes(accountId);
|
|
251
250
|
}
|
|
252
|
-
/**
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
251
|
+
/** Pull the (automationId, strategy ref) an `automation_edit`/`automation_create`
|
|
252
|
+
* action carries, if any — the shared per-action extraction both
|
|
253
|
+
* `automationStrategyRefsOf` and `automationStrategyRefOf` scan for, each
|
|
254
|
+
* aggregating it differently (see their own doc comments). */
|
|
255
|
+
function automationStrategyRefFromAction(action) {
|
|
256
|
+
const cfg = action.configuration;
|
|
257
|
+
if (!cfg)
|
|
258
|
+
return null;
|
|
259
|
+
let automationId;
|
|
260
|
+
let ref;
|
|
261
|
+
if (cfg.action_type === 'automation_edit') {
|
|
262
|
+
automationId = cfg.id;
|
|
263
|
+
ref = cfg.configuration?.strategy;
|
|
264
|
+
}
|
|
265
|
+
else if (cfg.action_type === 'automation_create') {
|
|
266
|
+
automationId = createdAutomationIdOf(action) ?? undefined;
|
|
267
|
+
ref = cfg.configuration?.strategy;
|
|
268
|
+
}
|
|
269
|
+
if (!automationId || !ref?.id)
|
|
270
|
+
return null;
|
|
271
|
+
return { automationId, ref: { id: ref.id, version: ref.version } };
|
|
272
|
+
}
|
|
273
|
+
/** The strategy (id, version) every automation referenced in `actions` runs,
|
|
274
|
+
* recovered from the action history in one pass: node AutomationStates
|
|
275
|
+
* carry no strategy reference — the automation_create / automation_edit
|
|
276
|
+
* configurations are the only wire record. The newest action targeting an
|
|
277
|
+
* automation wins (an edit supersedes the create). Prefer this over calling
|
|
278
|
+
* `automationStrategyRefOf` once per automation against the same `actions`
|
|
279
|
+
* array — that repeats the full scan per automation (O(automations ×
|
|
280
|
+
* actions)); this does the equivalent work once (O(actions)). */
|
|
281
|
+
export function automationStrategyRefsOf(actions) {
|
|
282
|
+
const best = new Map();
|
|
283
|
+
const bestAt = new Map();
|
|
260
284
|
for (const action of actions) {
|
|
261
|
-
const
|
|
262
|
-
if (!
|
|
285
|
+
const found = automationStrategyRefFromAction(action);
|
|
286
|
+
if (!found)
|
|
263
287
|
continue;
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
ref = cfg.configuration?.strategy;
|
|
288
|
+
const at = action.updated_at ?? action.created_at ?? '';
|
|
289
|
+
const prevAt = bestAt.get(found.automationId);
|
|
290
|
+
if (prevAt === undefined || at >= prevAt) {
|
|
291
|
+
best.set(found.automationId, found.ref);
|
|
292
|
+
bestAt.set(found.automationId, at);
|
|
270
293
|
}
|
|
271
|
-
|
|
294
|
+
}
|
|
295
|
+
return best;
|
|
296
|
+
}
|
|
297
|
+
/** The strategy (id, version) one automation runs, scanning `actions` once
|
|
298
|
+
* for just that id — a deliberately separate, targeted pass rather than
|
|
299
|
+
* `automationStrategyRefsOf(actions).get(automationId)`, so a single lookup
|
|
300
|
+
* doesn't pay for building a map entry for every OTHER automation in the
|
|
301
|
+
* action history too. Resolving more than one automation against the same
|
|
302
|
+
* `actions` array should call `automationStrategyRefsOf` once instead — this
|
|
303
|
+
* rescans on every call, which is fine for one-off lookups but O(automations
|
|
304
|
+
* × actions) in a loop. */
|
|
305
|
+
export function automationStrategyRefOf(actions, automationId) {
|
|
306
|
+
let best;
|
|
307
|
+
let bestAt;
|
|
308
|
+
for (const action of actions) {
|
|
309
|
+
const found = automationStrategyRefFromAction(action);
|
|
310
|
+
if (!found || found.automationId !== automationId)
|
|
272
311
|
continue;
|
|
273
312
|
const at = action.updated_at ?? action.created_at ?? '';
|
|
274
|
-
if (
|
|
275
|
-
best =
|
|
313
|
+
if (bestAt === undefined || at >= bestAt) {
|
|
314
|
+
best = found.ref;
|
|
276
315
|
bestAt = at;
|
|
277
316
|
}
|
|
278
317
|
}
|
|
279
|
-
return best;
|
|
318
|
+
return best ?? null;
|
|
280
319
|
}
|
|
281
320
|
/** Human-facing name carried by the action's configuration, when one exists.
|
|
282
321
|
* Returns null when the configuration only carries an opaque id (stop /
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/protocol/state.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,mBAAmB,EAAE,6BAA6B,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/protocol/state.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,mBAAmB,EAAE,6BAA6B,EAAE,MAAM,cAAc,CAAA;AAUjF,wEAAwE;AACxE,+EAA+E;AAC/E,0EAA0E;AAC1E,2EAA2E;AAC3E,2EAA2E;AAE3E,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAC7E,CAAC;AAED,8EAA8E;AAC9E,8EAA8E;AAC9E,qEAAqE;AACrE,6EAA6E;AAC7E,0EAA0E;AAC1E,6EAA6E;AAC7E,0EAA0E;AAC1E,8EAA8E;AAC9E,MAAM,UAAU,WAAW,CAAI,OAA4C,EAAE,KAAQ;IACnF,MAAM,KAAK,GAAG,IAAI,OAAO,EAAa,CAAA;IACtC,OAAO,CAAC,GAAY,EAAK,EAAE;QACzB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;YAAE,OAAO,KAAK,CAAA;QAChC,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAC1B,IAAI,GAAG,KAAK,SAAS;YAAE,OAAO,GAAG,CAAA;QACjC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;QACxB,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;QACnB,OAAO,GAAG,CAAA;IACZ,CAAC,CAAA;AACH,CAAC;AAED;;0EAE0E;AAC1E,MAAM,UAAU,oBAAoB,CAAC,aAAgD;IACnF,QAAQ,aAAa,CAAC,kBAAkB,EAAE,CAAC;QACzC,KAAK,eAAe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OAAQ,GAAqC,CAAC,aAAa,EAAE,IAAI,IAAI,IAAI,CAAA;QACnG,KAAK,iBAAiB,CAAC,CAAG,OAAQ,GAAmC,CAAC,aAAa,EAAE,IAAI,IAAI,IAAI,CAAA;QACjG,KAAK,gBAAgB,CAAC;QACtB,KAAK,cAAc,CAAC;QACpB,qEAAqE;QACrE,uEAAuE;QACvE,KAAK,iBAAiB,CAAC;QACvB,KAAK,eAAe,CAAC,CAAC,CAAC;YACrB,MAAM,MAAM,GAAI,GAA6C,CAAC,aAAa,CAAA;YAC3E,OAAO,MAAM,EAAE,IAAI,IAAI,IAAI,CAAA;QAC7B,CAAC;QACD,OAAO,CAAC,CAAC,OAAO,IAAI,CAAA;IACtB,CAAC;AACH,CAAC"}
|
package/dist/transport/urls.d.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* any `{ host, port, secure? }` works. */
|
|
4
|
-
export type NodeEndpoint = {
|
|
5
|
-
host: string;
|
|
6
|
-
port: number;
|
|
7
|
-
secure?: boolean;
|
|
8
|
-
};
|
|
1
|
+
import type { NodeEndpoint } from '@drakkar.software/octobot-protocol';
|
|
2
|
+
export type { NodeEndpoint };
|
|
9
3
|
export declare function nodeBaseUrl(node: NodeEndpoint): string;
|
|
10
4
|
export type NodeAddressSpace = 'loopback' | 'local' | 'public';
|
|
11
5
|
/** Parse a user-typed host string into a canonical { host, port, secure } triple.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urls.d.ts","sourceRoot":"","sources":["../../src/transport/urls.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"urls.d.ts","sourceRoot":"","sources":["../../src/transport/urls.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAA;AAEtE,YAAY,EAAE,YAAY,EAAE,CAAA;AAE5B,wBAAgB,WAAW,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,CAEtD;AAED,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG,OAAO,GAAG,QAAQ,CAAA;AAI9D;;;;qEAIqE;AACrE,wBAAgB,cAAc,CAC5B,GAAG,EAAE,MAAM,EACX,WAAW,SAAoB,GAC9B;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CA+CxD;AAED;;;uFAGuF;AACvF,wBAAgB,eAAe,CAAC,IAAI,EAAE,YAAY,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAQlF;AAED;;;;wDAIwD;AACxD,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,CAoCnE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urls.js","sourceRoot":"","sources":["../../src/transport/urls.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"urls.js","sourceRoot":"","sources":["../../src/transport/urls.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAK9D,MAAM,UAAU,WAAW,CAAC,IAAkB;IAC5C,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,MAAM,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,GAAG,UAAU,EAAE,CAAA;AACrF,CAAC;AAID,MAAM,IAAI,GAAG,8CAA8C,CAAA;AAE3D;;;;qEAIqE;AACrE,MAAM,UAAU,cAAc,CAC5B,GAAW,EACX,WAAW,GAAG,iBAAiB;IAE/B,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,EAAE,CAAA;IAC1B,IAAI,CAAC,OAAO;QAAE,OAAO,IA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