@drakkar.software/octobot-client 0.4.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 +140 -0
- package/dist/client/adapters/accounts.d.ts +66 -0
- package/dist/client/adapters/accounts.d.ts.map +1 -0
- package/dist/client/adapters/accounts.js +214 -0
- package/dist/client/adapters/accounts.js.map +1 -0
- package/dist/client/adapters/actionHandle.d.ts +29 -0
- package/dist/client/adapters/actionHandle.d.ts.map +1 -0
- package/dist/client/adapters/actionHandle.js +34 -0
- package/dist/client/adapters/actionHandle.js.map +1 -0
- package/dist/client/adapters/automations.d.ts +31 -0
- package/dist/client/adapters/automations.d.ts.map +1 -0
- package/dist/client/adapters/automations.js +79 -0
- package/dist/client/adapters/automations.js.map +1 -0
- package/dist/client/adapters/documents.d.ts +55 -0
- package/dist/client/adapters/documents.d.ts.map +1 -0
- package/dist/client/adapters/documents.js +66 -0
- package/dist/client/adapters/documents.js.map +1 -0
- package/dist/client/adapters/nodeApi.d.ts +25 -0
- package/dist/client/adapters/nodeApi.d.ts.map +1 -0
- package/dist/client/adapters/nodeApi.js +81 -0
- package/dist/client/adapters/nodeApi.js.map +1 -0
- package/dist/client/adapters/settings.d.ts +16 -0
- package/dist/client/adapters/settings.d.ts.map +1 -0
- package/dist/client/adapters/settings.js +43 -0
- package/dist/client/adapters/settings.js.map +1 -0
- package/dist/client/adapters/strategies.d.ts +17 -0
- package/dist/client/adapters/strategies.d.ts.map +1 -0
- package/dist/client/adapters/strategies.js +75 -0
- package/dist/client/adapters/strategies.js.map +1 -0
- package/dist/client/connect/connect.d.ts +40 -0
- package/dist/client/connect/connect.d.ts.map +1 -0
- package/dist/client/connect/connect.js +133 -0
- package/dist/client/connect/connect.js.map +1 -0
- package/dist/client/connect/readOnly.d.ts +97 -0
- package/dist/client/connect/readOnly.d.ts.map +1 -0
- package/dist/client/connect/readOnly.js +167 -0
- package/dist/client/connect/readOnly.js.map +1 -0
- package/dist/client/core/errors.d.ts +80 -0
- package/dist/client/core/errors.d.ts.map +1 -0
- package/dist/client/core/errors.js +154 -0
- package/dist/client/core/errors.js.map +1 -0
- package/dist/client/core/options.d.ts +44 -0
- package/dist/client/core/options.d.ts.map +1 -0
- package/dist/client/core/options.js +2 -0
- package/dist/client/core/options.js.map +1 -0
- package/dist/client/core/session.d.ts +90 -0
- package/dist/client/core/session.d.ts.map +1 -0
- package/dist/client/core/session.js +72 -0
- package/dist/client/core/session.js.map +1 -0
- package/dist/client/core/views.d.ts +40 -0
- package/dist/client/core/views.d.ts.map +1 -0
- package/dist/client/core/views.js +32 -0
- package/dist/client/core/views.js.map +1 -0
- package/dist/client/index.d.ts +16 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +9 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/mirror/collections.d.ts +125 -0
- package/dist/client/mirror/collections.d.ts.map +1 -0
- package/dist/client/mirror/collections.js +118 -0
- package/dist/client/mirror/collections.js.map +1 -0
- package/dist/client/mirror/index.d.ts +4 -0
- package/dist/client/mirror/index.d.ts.map +1 -0
- package/dist/client/mirror/index.js +4 -0
- package/dist/client/mirror/index.js.map +1 -0
- package/dist/client/mirror/writer.d.ts +39 -0
- package/dist/client/mirror/writer.d.ts.map +1 -0
- package/dist/client/mirror/writer.js +50 -0
- package/dist/client/mirror/writer.js.map +1 -0
- package/dist/client/pairing/mirrorGrant.d.ts +91 -0
- package/dist/client/pairing/mirrorGrant.d.ts.map +1 -0
- package/dist/client/pairing/mirrorGrant.js +99 -0
- package/dist/client/pairing/mirrorGrant.js.map +1 -0
- package/dist/client/pairing/mirrorReader.d.ts +99 -0
- package/dist/client/pairing/mirrorReader.d.ts.map +1 -0
- package/dist/client/pairing/mirrorReader.js +117 -0
- package/dist/client/pairing/mirrorReader.js.map +1 -0
- package/dist/client/pairing/pairingGrantExchange.d.ts +135 -0
- package/dist/client/pairing/pairingGrantExchange.d.ts.map +1 -0
- package/dist/client/pairing/pairingGrantExchange.js +186 -0
- package/dist/client/pairing/pairingGrantExchange.js.map +1 -0
- package/dist/client/pairing/pairingRequest.d.ts +82 -0
- package/dist/client/pairing/pairingRequest.d.ts.map +1 -0
- package/dist/client/pairing/pairingRequest.js +120 -0
- package/dist/client/pairing/pairingRequest.js.map +1 -0
- package/dist/client/strategy.d.ts +36 -0
- package/dist/client/strategy.d.ts.map +1 -0
- package/dist/client/strategy.js +26 -0
- package/dist/client/strategy.js.map +1 -0
- package/dist/collections/index.d.ts +3 -0
- package/dist/collections/index.d.ts.map +1 -0
- package/dist/collections/index.js +3 -0
- package/dist/collections/index.js.map +1 -0
- package/dist/collections/nodeCollections.d.ts +57 -0
- package/dist/collections/nodeCollections.d.ts.map +1 -0
- package/dist/collections/nodeCollections.js +40 -0
- package/dist/collections/nodeCollections.js.map +1 -0
- package/dist/collections/paths.d.ts +7 -0
- package/dist/collections/paths.d.ts.map +1 -0
- package/dist/collections/paths.js +13 -0
- package/dist/collections/paths.js.map +1 -0
- package/dist/crypto/collectionKeys.d.ts +28 -0
- package/dist/crypto/collectionKeys.d.ts.map +1 -0
- package/dist/crypto/collectionKeys.js +53 -0
- package/dist/crypto/collectionKeys.js.map +1 -0
- package/dist/crypto/hkdf.d.ts +14 -0
- package/dist/crypto/hkdf.d.ts.map +1 -0
- package/dist/crypto/hkdf.js +19 -0
- package/dist/crypto/hkdf.js.map +1 -0
- package/dist/crypto/index.d.ts +5 -0
- package/dist/crypto/index.d.ts.map +1 -0
- package/dist/crypto/index.js +5 -0
- package/dist/crypto/index.js.map +1 -0
- package/dist/crypto/secretEncryptor.d.ts +20 -0
- package/dist/crypto/secretEncryptor.d.ts.map +1 -0
- package/dist/crypto/secretEncryptor.js +82 -0
- package/dist/crypto/secretEncryptor.js.map +1 -0
- package/dist/crypto/wireConstants.d.ts +14 -0
- package/dist/crypto/wireConstants.d.ts.map +1 -0
- package/dist/crypto/wireConstants.js +17 -0
- package/dist/crypto/wireConstants.js.map +1 -0
- package/dist/identity/address.d.ts +3 -0
- package/dist/identity/address.d.ts.map +1 -0
- package/dist/identity/address.js +17 -0
- package/dist/identity/address.js.map +1 -0
- package/dist/identity/bip39-wordlist.d.ts +2 -0
- package/dist/identity/bip39-wordlist.d.ts.map +1 -0
- package/dist/identity/bip39-wordlist.js +2051 -0
- package/dist/identity/bip39-wordlist.js.map +1 -0
- package/dist/identity/capProvider.d.ts +45 -0
- package/dist/identity/capProvider.d.ts.map +1 -0
- package/dist/identity/capProvider.js +80 -0
- package/dist/identity/capProvider.js.map +1 -0
- package/dist/identity/derivationSchemes.d.ts +25 -0
- package/dist/identity/derivationSchemes.d.ts.map +1 -0
- package/dist/identity/derivationSchemes.js +34 -0
- package/dist/identity/derivationSchemes.js.map +1 -0
- package/dist/identity/evm.d.ts +8 -0
- package/dist/identity/evm.d.ts.map +1 -0
- package/dist/identity/evm.js +78 -0
- package/dist/identity/evm.js.map +1 -0
- package/dist/identity/index.d.ts +10 -0
- package/dist/identity/index.d.ts.map +1 -0
- package/dist/identity/index.js +10 -0
- package/dist/identity/index.js.map +1 -0
- package/dist/identity/keys.d.ts +17 -0
- package/dist/identity/keys.d.ts.map +1 -0
- package/dist/identity/keys.js +36 -0
- package/dist/identity/keys.js.map +1 -0
- package/dist/identity/mnemonic.d.ts +4 -0
- package/dist/identity/mnemonic.d.ts.map +1 -0
- package/dist/identity/mnemonic.js +93 -0
- package/dist/identity/mnemonic.js.map +1 -0
- package/dist/identity/pairing.d.ts +45 -0
- package/dist/identity/pairing.d.ts.map +1 -0
- package/dist/identity/pairing.js +91 -0
- package/dist/identity/pairing.js.map +1 -0
- package/dist/identity/pairingRequest.d.ts +99 -0
- package/dist/identity/pairingRequest.d.ts.map +1 -0
- package/dist/identity/pairingRequest.js +217 -0
- package/dist/identity/pairingRequest.js.map +1 -0
- package/dist/identity/secret.d.ts +32 -0
- package/dist/identity/secret.d.ts.map +1 -0
- package/dist/identity/secret.js +54 -0
- package/dist/identity/secret.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/bytes.d.ts +11 -0
- package/dist/internal/bytes.d.ts.map +1 -0
- package/dist/internal/bytes.js +38 -0
- package/dist/internal/bytes.js.map +1 -0
- package/dist/node-api/dexPair.d.ts +24 -0
- package/dist/node-api/dexPair.d.ts.map +1 -0
- package/dist/node-api/dexPair.js +39 -0
- package/dist/node-api/dexPair.js.map +1 -0
- package/dist/node-api/dsl.d.ts +10 -0
- package/dist/node-api/dsl.d.ts.map +1 -0
- package/dist/node-api/dsl.js +7 -0
- package/dist/node-api/dsl.js.map +1 -0
- package/dist/node-api/exchanges.d.ts +49 -0
- package/dist/node-api/exchanges.d.ts.map +1 -0
- package/dist/node-api/exchanges.js +32 -0
- package/dist/node-api/exchanges.js.map +1 -0
- package/dist/node-api/index.d.ts +12 -0
- package/dist/node-api/index.d.ts.map +1 -0
- package/dist/node-api/index.js +12 -0
- package/dist/node-api/index.js.map +1 -0
- package/dist/node-api/marketMaking.d.ts +39 -0
- package/dist/node-api/marketMaking.d.ts.map +1 -0
- package/dist/node-api/marketMaking.js +44 -0
- package/dist/node-api/marketMaking.js.map +1 -0
- package/dist/node-api/octobots.d.ts +14 -0
- package/dist/node-api/octobots.d.ts.map +1 -0
- package/dist/node-api/octobots.js +16 -0
- package/dist/node-api/octobots.js.map +1 -0
- package/dist/node-api/orderBookPreview.d.ts +11 -0
- package/dist/node-api/orderBookPreview.d.ts.map +1 -0
- package/dist/node-api/orderBookPreview.js +7 -0
- package/dist/node-api/orderBookPreview.js.map +1 -0
- package/dist/node-api/pairing.d.ts +39 -0
- package/dist/node-api/pairing.d.ts.map +1 -0
- package/dist/node-api/pairing.js +61 -0
- package/dist/node-api/pairing.js.map +1 -0
- package/dist/node-api/pairs.d.ts +32 -0
- package/dist/node-api/pairs.d.ts.map +1 -0
- package/dist/node-api/pairs.js +72 -0
- package/dist/node-api/pairs.js.map +1 -0
- package/dist/node-api/requiredFunds.d.ts +11 -0
- package/dist/node-api/requiredFunds.d.ts.map +1 -0
- package/dist/node-api/requiredFunds.js +7 -0
- package/dist/node-api/requiredFunds.js.map +1 -0
- package/dist/node-api/setup.d.ts +25 -0
- package/dist/node-api/setup.d.ts.map +1 -0
- package/dist/node-api/setup.js +13 -0
- package/dist/node-api/setup.js.map +1 -0
- package/dist/node-api/wallet.d.ts +55 -0
- package/dist/node-api/wallet.d.ts.map +1 -0
- package/dist/node-api/wallet.js +87 -0
- package/dist/node-api/wallet.js.map +1 -0
- package/dist/protocol/actions.d.ts +40 -0
- package/dist/protocol/actions.d.ts.map +1 -0
- package/dist/protocol/actions.js +118 -0
- package/dist/protocol/actions.js.map +1 -0
- package/dist/protocol/documents.d.ts +25 -0
- package/dist/protocol/documents.d.ts.map +1 -0
- package/dist/protocol/documents.js +2 -0
- package/dist/protocol/documents.js.map +1 -0
- package/dist/protocol/index.d.ts +10 -0
- package/dist/protocol/index.d.ts.map +1 -0
- package/dist/protocol/index.js +12 -0
- package/dist/protocol/index.js.map +1 -0
- package/dist/protocol/orchestration/createAutomation.d.ts +61 -0
- package/dist/protocol/orchestration/createAutomation.d.ts.map +1 -0
- package/dist/protocol/orchestration/createAutomation.js +71 -0
- package/dist/protocol/orchestration/createAutomation.js.map +1 -0
- package/dist/protocol/poll.d.ts +4 -0
- package/dist/protocol/poll.d.ts.map +1 -0
- package/dist/protocol/poll.js +4 -0
- package/dist/protocol/poll.js.map +1 -0
- package/dist/protocol/proposal.d.ts +36 -0
- package/dist/protocol/proposal.d.ts.map +1 -0
- package/dist/protocol/proposal.js +39 -0
- package/dist/protocol/proposal.js.map +1 -0
- package/dist/protocol/state.d.ts +87 -0
- package/dist/protocol/state.d.ts.map +1 -0
- package/dist/protocol/state.js +303 -0
- package/dist/protocol/state.js.map +1 -0
- package/dist/protocol/strategy/build.d.ts +44 -0
- package/dist/protocol/strategy/build.d.ts.map +1 -0
- package/dist/protocol/strategy/build.js +50 -0
- package/dist/protocol/strategy/build.js.map +1 -0
- package/dist/protocol/strategy/builders.d.ts +252 -0
- package/dist/protocol/strategy/builders.d.ts.map +1 -0
- package/dist/protocol/strategy/builders.js +382 -0
- package/dist/protocol/strategy/builders.js.map +1 -0
- package/dist/protocol/strategy/index.d.ts +5 -0
- package/dist/protocol/strategy/index.d.ts.map +1 -0
- package/dist/protocol/strategy/index.js +4 -0
- package/dist/protocol/strategy/index.js.map +1 -0
- package/dist/protocol/strategy/kinds.d.ts +2 -0
- package/dist/protocol/strategy/kinds.d.ts.map +1 -0
- package/dist/protocol/strategy/kinds.js +2 -0
- package/dist/protocol/strategy/kinds.js.map +1 -0
- package/dist/protocol/strategy/patch.d.ts +59 -0
- package/dist/protocol/strategy/patch.d.ts.map +1 -0
- package/dist/protocol/strategy/patch.js +253 -0
- package/dist/protocol/strategy/patch.js.map +1 -0
- package/dist/protocol/symbols.d.ts +8 -0
- package/dist/protocol/symbols.d.ts.map +1 -0
- package/dist/protocol/symbols.js +11 -0
- package/dist/protocol/symbols.js.map +1 -0
- package/dist/transport/constants.d.ts +8 -0
- package/dist/transport/constants.d.ts.map +1 -0
- package/dist/transport/constants.js +8 -0
- package/dist/transport/constants.js.map +1 -0
- package/dist/transport/documents.d.ts +27 -0
- package/dist/transport/documents.d.ts.map +1 -0
- package/dist/transport/documents.js +34 -0
- package/dist/transport/documents.js.map +1 -0
- package/dist/transport/index.d.ts +8 -0
- package/dist/transport/index.d.ts.map +1 -0
- package/dist/transport/index.js +8 -0
- package/dist/transport/index.js.map +1 -0
- package/dist/transport/probe.d.ts +44 -0
- package/dist/transport/probe.d.ts.map +1 -0
- package/dist/transport/probe.js +121 -0
- package/dist/transport/probe.js.map +1 -0
- package/dist/transport/rendezvous.d.ts +116 -0
- package/dist/transport/rendezvous.d.ts.map +1 -0
- package/dist/transport/rendezvous.js +139 -0
- package/dist/transport/rendezvous.js.map +1 -0
- package/dist/transport/rest.d.ts +35 -0
- package/dist/transport/rest.d.ts.map +1 -0
- package/dist/transport/rest.js +58 -0
- package/dist/transport/rest.js.map +1 -0
- package/dist/transport/syncClient.d.ts +14 -0
- package/dist/transport/syncClient.d.ts.map +1 -0
- package/dist/transport/syncClient.js +30 -0
- package/dist/transport/syncClient.js.map +1 -0
- package/dist/transport/urls.d.ts +35 -0
- package/dist/transport/urls.d.ts.map +1 -0
- package/dist/transport/urls.js +126 -0
- package/dist/transport/urls.js.map +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createAutomation.d.ts","sourceRoot":"","sources":["../../../src/protocol/orchestration/createAutomation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAA;AAC7F,OAAO,EAA0D,KAAK,oBAAoB,EAAE,MAAM,eAAe,CAAA;AAIjH;;;;;wEAKwE;AACxE,MAAM,MAAM,aAAa,GAAG;IAC1B,8EAA8E;IAC9E,IAAI,EAAE,CAAC,aAAa,EAAE,uBAAuB,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;IACjE;;qBAEiB;IACjB,IAAI,EAAE,MAAM,OAAO,CAAC,UAAU,EAAE,CAAC,CAAA;CAClC,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG,oBAAoB,CAAA;AAExD,MAAM,MAAM,wBAAwB,GAAG;IAAE,KAAK,EAAE,UAAU,GAAG,YAAY,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAAA;AAE1F,MAAM,MAAM,uBAAuB,GAAG;IACpC,uDAAuD;IACvD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,2EAA2E;IAC3E,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAA;IACvC,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,UAAU,CAAC,EAAE,CAAC,CAAC,EAAE,wBAAwB,KAAK,IAAI,CAAA;CACnD,CAAA;AAED;qDACqD;AACrD,qBAAa,2BAA4B,SAAQ,KAAK;IACpD,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,YAAY,CAAA;IACzC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;gBAClB,KAAK,EAAE,UAAU,GAAG,YAAY,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;CAMpE;AAED;wEACwE;AACxE,qBAAa,sBAAuB,SAAQ,KAAK;IAC/C,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,YAAY,CAAA;gBAC7B,KAAK,EAAE,UAAU,GAAG,YAAY;CAK7C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,mBAAmB,CACvC,EAAE,EAAE,aAAa,EACjB,KAAK,EAAE,qBAAqB,EAC5B,IAAI,GAAE,uBAA4B,GACjC,OAAO,CAAC;IAAE,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC,CA6B1C"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { buildCreateStrategyConfig, buildCreateAutomationConfig } from '../actions.js';
|
|
2
|
+
import { actionErrorDetails, createdAutomationIdOf } from '../state.js';
|
|
3
|
+
import { sleep, pollDelay } from '../poll.js';
|
|
4
|
+
/** A specific action the node executed and rejected. Not retriable by
|
|
5
|
+
* resubmitting the same configuration unchanged. */
|
|
6
|
+
export class AutomationActionFailedError extends Error {
|
|
7
|
+
phase;
|
|
8
|
+
detail;
|
|
9
|
+
constructor(phase, detail) {
|
|
10
|
+
super(`${phase} action failed${detail ? `: ${detail}` : ''}`);
|
|
11
|
+
this.name = 'AutomationActionFailedError';
|
|
12
|
+
this.phase = phase;
|
|
13
|
+
this.detail = detail;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/** Neither phase failed outright — the node just never confirmed within the
|
|
17
|
+
* budget. Worth a fresh `runCreateAutomation` call, not a resubmit. */
|
|
18
|
+
export class AutomationTimeoutError extends Error {
|
|
19
|
+
phase;
|
|
20
|
+
constructor(phase) {
|
|
21
|
+
super(`${phase} action not confirmed within the timeout budget`);
|
|
22
|
+
this.name = 'AutomationTimeoutError';
|
|
23
|
+
this.phase = phase;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Two-phase sequenced automation creation: emits `strategy_create`, polls the
|
|
28
|
+
* node until it confirms, then emits `automation_create` and polls until the
|
|
29
|
+
* node reports a result.
|
|
30
|
+
*
|
|
31
|
+
* This eliminates a concurrent-execution race: the node executes queued
|
|
32
|
+
* actions concurrently, and `automation_create` resolves its strategy by
|
|
33
|
+
* (id, version) — if it ran before `strategy_create` registered that
|
|
34
|
+
* strategy in the node's StrategyProvider, it would fail non-retriably with
|
|
35
|
+
* `strategy_not_found`. Sequencing guarantees the strategy exists first.
|
|
36
|
+
*
|
|
37
|
+
* Callers enforcing an account's automation cap (a product policy the node
|
|
38
|
+
* itself does not know about) must check it BEFORE calling this — it is not
|
|
39
|
+
* part of the protocol and this function does not re-derive it.
|
|
40
|
+
*/
|
|
41
|
+
export async function runCreateAutomation(io, input, opts = {}) {
|
|
42
|
+
const { timeoutMs = 60_000, pollDelay: nextDelay = pollDelay, signal, onProgress } = opts;
|
|
43
|
+
const deadline = Date.now() + timeoutMs;
|
|
44
|
+
async function runPhase(phase, configuration) {
|
|
45
|
+
onProgress?.({ phase, done: false });
|
|
46
|
+
const actionId = await io.emit(configuration);
|
|
47
|
+
for (let attempt = 0;; attempt++) {
|
|
48
|
+
if (signal?.aborted)
|
|
49
|
+
throw new DOMException('Aborted', 'AbortError');
|
|
50
|
+
if (Date.now() >= deadline)
|
|
51
|
+
throw new AutomationTimeoutError(phase);
|
|
52
|
+
await sleep(nextDelay(attempt));
|
|
53
|
+
if (signal?.aborted)
|
|
54
|
+
throw new DOMException('Aborted', 'AbortError');
|
|
55
|
+
if (Date.now() >= deadline)
|
|
56
|
+
throw new AutomationTimeoutError(phase);
|
|
57
|
+
const actions = await io.poll();
|
|
58
|
+
const action = actions.find((a) => a.id === actionId);
|
|
59
|
+
if (action?.status === 'failed')
|
|
60
|
+
throw new AutomationActionFailedError(phase, actionErrorDetails(action));
|
|
61
|
+
if (action?.status === 'completed') {
|
|
62
|
+
onProgress?.({ phase, done: true });
|
|
63
|
+
return action;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
await runPhase('strategy', buildCreateStrategyConfig(input.strategy));
|
|
68
|
+
const autoAction = await runPhase('automation', buildCreateAutomationConfig(input));
|
|
69
|
+
return { automationId: createdAutomationIdOf(autoAction) };
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=createAutomation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createAutomation.js","sourceRoot":"","sources":["../../../src/protocol/orchestration/createAutomation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,2BAA2B,EAA6B,MAAM,eAAe,CAAA;AACjH,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AACvE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AA8B7C;qDACqD;AACrD,MAAM,OAAO,2BAA4B,SAAQ,KAAK;IAC3C,KAAK,CAA2B;IAChC,MAAM,CAAe;IAC9B,YAAY,KAAgC,EAAE,MAAqB;QACjE,KAAK,CAAC,GAAG,KAAK,iBAAiB,MAAM,CAAC,CAAC,CAAC,KAAK,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;QAC7D,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAA;QACzC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;CACF;AAED;wEACwE;AACxE,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IACtC,KAAK,CAA2B;IACzC,YAAY,KAAgC;QAC1C,KAAK,CAAC,GAAG,KAAK,iDAAiD,CAAC,CAAA;QAChE,IAA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C,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,QAAQ,CAAC,CAAA;YAErD,IAAI,MAAM,EAAE,MAAM,KAAK,QAAQ;gBAAE,MAAM,IAAI,2BAA2B,CAAC,KAAK,EAAE,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAA;YACzG,IAAI,MAAM,EAAE,MAAM,KAAK,WAAW,EAAE,CAAC;gBACnC,UAAU,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;gBACnC,OAAO,MAAM,CAAA;YACf,CAAC;QACH,CAAC;IACH,CAAC;IAED,MAAM,QAAQ,CAAC,UAAU,EAAE,yBAAyB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAA;IACrE,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAC,YAAY,EAAE,2BAA2B,CAAC,KAAK,CAAC,CAAC,CAAA;IACnF,OAAO,EAAE,YAAY,EAAE,qBAAqB,CAAC,UAAU,CAAC,EAAE,CAAA;AAC5D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"poll.d.ts","sourceRoot":"","sources":["../../src/protocol/poll.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,eAAO,MAAM,KAAK,GAAI,IAAI,MAAM,kBAAgD,CAAA;AAChF,eAAO,MAAM,SAAS,GAAI,GAAG,MAAM,WAAoC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"poll.js","sourceRoot":"","sources":["../../src/protocol/poll.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAO,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;AAChF,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,GAAG,IAAI,EAAE,IAAI,CAAC,CAAA"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { UserActionConfiguration } from '@drakkar.software/octobot-protocol';
|
|
2
|
+
/** One built-but-unsent action inside a proposal. `after: 'previous-confirmed'`
|
|
3
|
+
* marks an action that must not be appended until the PRIOR entry in the
|
|
4
|
+
* array has been confirmed by the node — the only case this applies to
|
|
5
|
+
* today is `automations.create()`'s `strategy_create` → `automation_create`
|
|
6
|
+
* race (see `orchestration/createAutomation.ts`). A privileged executor
|
|
7
|
+
* (one that actually has append rights) must honor this ordering; a
|
|
8
|
+
* read-only proposer never appends anything itself, so it just carries the
|
|
9
|
+
* constraint as data. */
|
|
10
|
+
export type ProposedActionEntry = {
|
|
11
|
+
configuration: UserActionConfiguration;
|
|
12
|
+
after?: 'previous-confirmed';
|
|
13
|
+
};
|
|
14
|
+
/** A batch of built-but-unsent user actions, QR-encodable. Produced by a
|
|
15
|
+
* read-only-connected client's write methods instead of appending; consumed
|
|
16
|
+
* by a privileged client (one with real append rights) to actually execute
|
|
17
|
+
* them after a human reviews and confirms. */
|
|
18
|
+
export interface ActionProposal {
|
|
19
|
+
v: 1;
|
|
20
|
+
kind: 'octobot-action-proposal';
|
|
21
|
+
actions: ProposedActionEntry[];
|
|
22
|
+
/** Human-readable summary for a confirm screen, when the generic
|
|
23
|
+
* per-action `configuration.name`/`action_type` derivation isn't enough
|
|
24
|
+
* (e.g. a multi-action batch). */
|
|
25
|
+
label?: string;
|
|
26
|
+
createdAt: string;
|
|
27
|
+
}
|
|
28
|
+
export declare function encodeActionProposal(actions: ProposedActionEntry[], opts?: {
|
|
29
|
+
label?: string;
|
|
30
|
+
}): string;
|
|
31
|
+
/** Parse and structurally validate a scanned/pasted action-proposal payload.
|
|
32
|
+
* Throws on anything that isn't shaped like one — callers doing QR
|
|
33
|
+
* classification should catch and fall through to the next candidate
|
|
34
|
+
* parser rather than propagate. */
|
|
35
|
+
export declare function decodeActionProposal(payload: string): ActionProposal;
|
|
36
|
+
//# sourceMappingURL=proposal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proposal.d.ts","sourceRoot":"","sources":["../../src/protocol/proposal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAA;AAEjF;;;;;;;0BAO0B;AAC1B,MAAM,MAAM,mBAAmB,GAAG;IAChC,aAAa,EAAE,uBAAuB,CAAA;IACtC,KAAK,CAAC,EAAE,oBAAoB,CAAA;CAC7B,CAAA;AAED;;;+CAG+C;AAC/C,MAAM,WAAW,cAAc;IAC7B,CAAC,EAAE,CAAC,CAAA;IACJ,IAAI,EAAE,yBAAyB,CAAA;IAC/B,OAAO,EAAE,mBAAmB,EAAE,CAAA;IAC9B;;uCAEmC;IACnC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,mBAAmB,EAAE,EAAE,IAAI,CAAC,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAStG;AAED;;;oCAGoC;AACpC,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,cAAc,CAkBpE"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export function encodeActionProposal(actions, opts) {
|
|
2
|
+
const proposal = {
|
|
3
|
+
v: 1,
|
|
4
|
+
kind: 'octobot-action-proposal',
|
|
5
|
+
actions,
|
|
6
|
+
...(opts?.label ? { label: opts.label } : {}),
|
|
7
|
+
createdAt: new Date().toISOString(),
|
|
8
|
+
};
|
|
9
|
+
return JSON.stringify(proposal);
|
|
10
|
+
}
|
|
11
|
+
/** Parse and structurally validate a scanned/pasted action-proposal payload.
|
|
12
|
+
* Throws on anything that isn't shaped like one — callers doing QR
|
|
13
|
+
* classification should catch and fall through to the next candidate
|
|
14
|
+
* parser rather than propagate. */
|
|
15
|
+
export function decodeActionProposal(payload) {
|
|
16
|
+
let parsed;
|
|
17
|
+
try {
|
|
18
|
+
parsed = JSON.parse(payload);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
throw new Error('not valid JSON');
|
|
22
|
+
}
|
|
23
|
+
if (typeof parsed !== 'object' || parsed === null)
|
|
24
|
+
throw new Error('not an object');
|
|
25
|
+
const p = parsed;
|
|
26
|
+
if (p.v !== 1 || p.kind !== 'octobot-action-proposal')
|
|
27
|
+
throw new Error('not an action proposal payload');
|
|
28
|
+
if (!Array.isArray(p.actions) || p.actions.length === 0)
|
|
29
|
+
throw new Error('malformed action proposal: actions');
|
|
30
|
+
for (const entry of p.actions) {
|
|
31
|
+
if (typeof entry !== 'object' || entry === null || !('configuration' in entry)) {
|
|
32
|
+
throw new Error('malformed action proposal: entry');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (typeof p.createdAt !== 'string')
|
|
36
|
+
throw new Error('malformed action proposal: createdAt');
|
|
37
|
+
return p;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=proposal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proposal.js","sourceRoot":"","sources":["../../src/protocol/proposal.ts"],"names":[],"mappings":"AA8BA,MAAM,UAAU,oBAAoB,CAAC,OAA8B,EAAE,IAAyB;IAC5F,MAAM,QAAQ,GAAmB;QAC/B,CAAC,EAAE,CAAC;QACJ,IAAI,EAAE,yBAAyB;QAC/B,OAAO;QACP,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7C,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KACpC,CAAA;IACD,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAA;AACjC,CAAC;AAED;;;oCAGoC;AACpC,MAAM,UAAU,oBAAoB,CAAC,OAAe;IAClD,IAAI,MAAe,CAAA;IACnB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IAC9B,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAA;IACnC,CAAC;IACD,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAA;IACnF,MAAM,CAAC,GAAG,MAAiC,CAAA;IAC3C,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,yBAAyB;QAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAA;IACxG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAA;IAC9G,KAAK,MAAM,KAAK,IAAI,CAAC,CAAC,OAAoB,EAAE,CAAC;QAC3C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,CAAC,eAAe,IAAI,KAAK,CAAC,EAAE,CAAC;YAC/E,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAA;QACrD,CAAC;IACH,CAAC;IACD,IAAI,OAAO,CAAC,CAAC,SAAS,KAAK,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAA;IAC5F,OAAO,CAA8B,CAAA;AACvC,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { AutomationState, WorkflowStatus, UserAction, AutomationActionResult, AccountActionResult, Account as ProtocolAccount, ExchangeConfig, DetailedAsset, Strategy as ProtocolStrategy } from '@drakkar.software/octobot-protocol';
|
|
2
|
+
import type { StrategyKind } from './strategy/kinds.js';
|
|
3
|
+
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
4
|
+
export declare function cachedByDoc<T>(compute: (doc: Record<string, unknown>) => T, empty: T): (doc: unknown) => T;
|
|
5
|
+
/** Derives a `StrategyKind` from a protocol Strategy's configuration —
|
|
6
|
+
* for callers reconstructing a strategy from raw node data that need to tag
|
|
7
|
+
* it with the same kind derivation a local persisted doc would carry. */
|
|
8
|
+
export declare function protocolStrategyKind(configuration: ProtocolStrategy['configuration']): StrategyKind;
|
|
9
|
+
/** Node-reported automation states from a pulled user-data document. Excludes
|
|
10
|
+
* any entry carrying a `kind` field — that marks a caller's own local
|
|
11
|
+
* mirror unioned into the same array, not node state. */
|
|
12
|
+
export declare const parseNodeAutomationStates: (doc: unknown) => AutomationState[];
|
|
13
|
+
/** Node-reported user actions (with execution status + result) from a pulled
|
|
14
|
+
* user-data document. Pulling the append-only `actions` collection itself
|
|
15
|
+
* always returns empty — the node reports execution state through
|
|
16
|
+
* user-data, not through the queue collection. */
|
|
17
|
+
export declare const parseNodeUserActions: (doc: unknown) => UserAction[];
|
|
18
|
+
/** Protocol workflow status → a coarse live/draft/stopped classification.
|
|
19
|
+
* 'canceled', 'failed', 'completed' and any future unknown value map to
|
|
20
|
+
* 'stopped' so a non-running workflow never renders as a live bot. */
|
|
21
|
+
export type AutomationRunStatus = 'live' | 'draft' | 'stopped';
|
|
22
|
+
export declare function workflowStatusToAutomationStatus(status: WorkflowStatus | string | undefined): AutomationRunStatus;
|
|
23
|
+
/** Node-reported failure for an automation: error_message is the protocol
|
|
24
|
+
* enum-ish summary, error the detailed string. */
|
|
25
|
+
export declare function automationErrorOf(state: AutomationState): string | null;
|
|
26
|
+
/** Normalize a raw node `assets` value (either flat `DetailedAsset[]` or
|
|
27
|
+
* nested `DetailedAssetsForTradingType[]`) into a flat `DetailedAsset[]`.
|
|
28
|
+
* The 0.4.0 schema declares the nested shape but the node serializes flat
|
|
29
|
+
* items (bypasses pydantic validation when filling) — accept both. */
|
|
30
|
+
export declare function normalizeNodeAssets(raw: unknown): DetailedAsset[];
|
|
31
|
+
/** Holdings from an AutomationState, normalized. */
|
|
32
|
+
export declare function automationHoldings(state: AutomationState): DetailedAsset[];
|
|
33
|
+
export declare const parseNodeAccounts: (doc: unknown) => ProtocolAccount[];
|
|
34
|
+
export declare const parseNodeExchangeConfigs: (doc: unknown) => ExchangeConfig[];
|
|
35
|
+
/** A protocol-shaped account holding: no fiat value (a caller with its own
|
|
36
|
+
* pricing owns that), no display-only decoration. */
|
|
37
|
+
export type Holding = {
|
|
38
|
+
symbol: string;
|
|
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[];
|
|
45
|
+
export declare function automationResultOf(action: UserAction): AutomationActionResult | null;
|
|
46
|
+
export declare function accountResultOf(action: UserAction): AccountActionResult | null;
|
|
47
|
+
export declare function actionErrorDetails(action: UserAction): string | null;
|
|
48
|
+
/** The automation id a completed automation_create produced. */
|
|
49
|
+
export declare function createdAutomationIdOf(action: UserAction): string | null;
|
|
50
|
+
/** The account id an `account_create` carries. Unlike automations, account
|
|
51
|
+
* ids are client-assigned and reused verbatim by the node, so the creating
|
|
52
|
+
* action alone identifies the account it will produce. */
|
|
53
|
+
export declare function createdAccountIdOf(action: UserAction): string | null;
|
|
54
|
+
/** Which domain a user action belongs to, purely from its wire `action_type`. */
|
|
55
|
+
export type UserActionDomain = 'accounts' | 'automations';
|
|
56
|
+
/** Null for action types with no owning domain (a future protocol action
|
|
57
|
+
* added here before its domain is wired in degrades to "belongs nowhere"
|
|
58
|
+
* rather than crashing a domain filter). */
|
|
59
|
+
export declare function actionDomainOf(action: UserAction): UserActionDomain | null;
|
|
60
|
+
/** The automation an action targets — explicit id for edit/stop/signal, the
|
|
61
|
+
* node-reported created id for create. */
|
|
62
|
+
export declare function targetAutomationIdOf(action: UserAction): string | null;
|
|
63
|
+
/** Every account id an action targets. `account_create`/`_edit`/`_delete`
|
|
64
|
+
* carry the account id directly; `account_auth_*`/`exchange_config_*` carry
|
|
65
|
+
* an `auth_*`/`cfg_*` id derived from it and are reversed back to the
|
|
66
|
+
* account id. `accounts_refresh` with no explicit `account_ids` targets
|
|
67
|
+
* every account — callers should treat that case as "matches any account"
|
|
68
|
+
* rather than reading an empty array from here. */
|
|
69
|
+
export declare function targetAccountIdsOf(action: UserAction): string[];
|
|
70
|
+
/** Whether a queued action targets the given account — an `accounts_refresh`
|
|
71
|
+
* with no explicit `account_ids` refreshes every account, so it counts as
|
|
72
|
+
* targeting all of them. */
|
|
73
|
+
export declare function actionTargetsAccount(action: UserAction, accountId: string): boolean;
|
|
74
|
+
/** The strategy (id, version) an automation runs, recovered from the action
|
|
75
|
+
* history: node AutomationStates carry no strategy reference — the
|
|
76
|
+
* automation_create / automation_edit configurations are the only wire
|
|
77
|
+
* record. The newest action targeting the automation wins (an edit
|
|
78
|
+
* supersedes the create). */
|
|
79
|
+
export declare function automationStrategyRefOf(actions: UserAction[], automationId: string): {
|
|
80
|
+
id: string;
|
|
81
|
+
version?: string;
|
|
82
|
+
} | null;
|
|
83
|
+
/** Human-facing name carried by the action's configuration, when one exists.
|
|
84
|
+
* Returns null when the configuration only carries an opaque id (stop /
|
|
85
|
+
* delete actions) — callers fall back to their own type label. */
|
|
86
|
+
export declare function actionDisplayName(action: UserAction): string | null;
|
|
87
|
+
//# sourceMappingURL=state.d.ts.map
|
|
@@ -0,0 +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,aAA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wBAAgB,uBAAuB,CACrC,OAAO,EAAE,UAAU,EAAE,EACrB,YAAY,EAAE,MAAM,GACnB;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAoBzC;AAED;;mEAEmE;AACnE,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI,CAiBnE"}
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { accountIdFromAuthId, accountIdFromExchangeConfigId } from './actions.js';
|
|
2
|
+
// The node computes `users/{identity}/data` on every pull as a protocol
|
|
3
|
+
// UserDataState { automations: AutomationState[], user_actions: UserAction[] }
|
|
4
|
+
// (snake_case pydantic JSON). This is bidirectional wire state — parse it
|
|
5
|
+
// READ-TIME with the tolerant functions below; a caller with its own local
|
|
6
|
+
// mirror (tombstones, CRDT merge) reconciles the two itself, one layer up.
|
|
7
|
+
export function isRecord(value) {
|
|
8
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
9
|
+
}
|
|
10
|
+
// Every parser below is cached per input document reference: a caller reading
|
|
11
|
+
// through `useSyncExternalStore`-style selectors needs a stable reference for
|
|
12
|
+
// the same input, or a fresh .filter()/.map() per call trips React's
|
|
13
|
+
// "getSnapshot should be cached" infinite-loop guard. A store write replaces
|
|
14
|
+
// the data object, so a new reference recomputes. Exported (not just used
|
|
15
|
+
// internally) so a caller building its own local-merge layer on top of these
|
|
16
|
+
// parsers — see docs/10-advanced-primitives.md — can give its own derived
|
|
17
|
+
// values the same reference-stability guarantee instead of reimplementing it.
|
|
18
|
+
export function cachedByDoc(compute, empty) {
|
|
19
|
+
const cache = new WeakMap();
|
|
20
|
+
return (doc) => {
|
|
21
|
+
if (!isRecord(doc))
|
|
22
|
+
return empty;
|
|
23
|
+
const hit = cache.get(doc);
|
|
24
|
+
if (hit !== undefined)
|
|
25
|
+
return hit;
|
|
26
|
+
const out = compute(doc);
|
|
27
|
+
cache.set(doc, out);
|
|
28
|
+
return out;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** Derives a `StrategyKind` from a protocol Strategy's configuration —
|
|
32
|
+
* for callers reconstructing a strategy from raw node data that need to tag
|
|
33
|
+
* it with the same kind derivation a local persisted doc would carry. */
|
|
34
|
+
export function protocolStrategyKind(configuration) {
|
|
35
|
+
switch (configuration.configuration_type) {
|
|
36
|
+
case 'market_making': return 'mm';
|
|
37
|
+
case 'copy': return 'copy';
|
|
38
|
+
case 'generic_process': return 'custom';
|
|
39
|
+
case 'generic_workflow': return 'ai-agents';
|
|
40
|
+
case 'trading_tentacles': {
|
|
41
|
+
const name = configuration.name;
|
|
42
|
+
if (name === 'GridTradingMode')
|
|
43
|
+
return 'grid';
|
|
44
|
+
if (name === 'DCATradingMode')
|
|
45
|
+
return 'dca';
|
|
46
|
+
if (name === 'IndexTradingMode')
|
|
47
|
+
return 'basket';
|
|
48
|
+
return 'custom';
|
|
49
|
+
}
|
|
50
|
+
default: return 'custom';
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const EMPTY_AUTOMATION_STATES = [];
|
|
54
|
+
const EMPTY_USER_ACTIONS = [];
|
|
55
|
+
/** Node-reported automation states from a pulled user-data document. Excludes
|
|
56
|
+
* any entry carrying a `kind` field — that marks a caller's own local
|
|
57
|
+
* mirror unioned into the same array, not node state. */
|
|
58
|
+
export const parseNodeAutomationStates = cachedByDoc((doc) => {
|
|
59
|
+
if (!Array.isArray(doc.automations))
|
|
60
|
+
return EMPTY_AUTOMATION_STATES;
|
|
61
|
+
return doc.automations.filter((entry) => isRecord(entry) && typeof entry.id === 'string' && !('kind' in entry));
|
|
62
|
+
}, EMPTY_AUTOMATION_STATES);
|
|
63
|
+
/** Node-reported user actions (with execution status + result) from a pulled
|
|
64
|
+
* user-data document. Pulling the append-only `actions` collection itself
|
|
65
|
+
* always returns empty — the node reports execution state through
|
|
66
|
+
* user-data, not through the queue collection. */
|
|
67
|
+
export const parseNodeUserActions = cachedByDoc((doc) => {
|
|
68
|
+
if (!Array.isArray(doc.user_actions))
|
|
69
|
+
return EMPTY_USER_ACTIONS;
|
|
70
|
+
return doc.user_actions.filter((entry) => isRecord(entry) && typeof entry.id === 'string');
|
|
71
|
+
}, EMPTY_USER_ACTIONS);
|
|
72
|
+
export function workflowStatusToAutomationStatus(status) {
|
|
73
|
+
switch (status) {
|
|
74
|
+
case 'scheduled':
|
|
75
|
+
case 'periodic':
|
|
76
|
+
case 'running':
|
|
77
|
+
return 'live';
|
|
78
|
+
case 'pending':
|
|
79
|
+
return 'draft';
|
|
80
|
+
default:
|
|
81
|
+
return 'stopped';
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/** Node-reported failure for an automation: error_message is the protocol
|
|
85
|
+
* enum-ish summary, error the detailed string. */
|
|
86
|
+
export function automationErrorOf(state) {
|
|
87
|
+
return state.error_message ?? state.error ?? null;
|
|
88
|
+
}
|
|
89
|
+
/** Normalize a raw node `assets` value (either flat `DetailedAsset[]` or
|
|
90
|
+
* nested `DetailedAssetsForTradingType[]`) into a flat `DetailedAsset[]`.
|
|
91
|
+
* The 0.4.0 schema declares the nested shape but the node serializes flat
|
|
92
|
+
* items (bypasses pydantic validation when filling) — accept both. */
|
|
93
|
+
export function normalizeNodeAssets(raw) {
|
|
94
|
+
if (!Array.isArray(raw))
|
|
95
|
+
return [];
|
|
96
|
+
const out = [];
|
|
97
|
+
for (const entry of raw) {
|
|
98
|
+
if (!isRecord(entry))
|
|
99
|
+
continue;
|
|
100
|
+
if (typeof entry.symbol === 'string') {
|
|
101
|
+
out.push(entry);
|
|
102
|
+
}
|
|
103
|
+
else if (Array.isArray(entry.assets)) {
|
|
104
|
+
for (const nested of entry.assets) {
|
|
105
|
+
if (isRecord(nested) && typeof nested.symbol === 'string')
|
|
106
|
+
out.push(nested);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return out;
|
|
111
|
+
}
|
|
112
|
+
/** Holdings from an AutomationState, normalized. */
|
|
113
|
+
export function automationHoldings(state) {
|
|
114
|
+
return normalizeNodeAssets(state.assets);
|
|
115
|
+
}
|
|
116
|
+
// The accounts collection is node-owned and pull-only: a client push is
|
|
117
|
+
// dead-lettered into opaque storage and every pull returns the node's
|
|
118
|
+
// AccountsState { accounts, exchange_configs }.
|
|
119
|
+
const EMPTY_NODE_ACCOUNTS = [];
|
|
120
|
+
const EMPTY_EXCHANGE_CONFIGS = [];
|
|
121
|
+
export const parseNodeAccounts = cachedByDoc((doc) => {
|
|
122
|
+
if (!Array.isArray(doc.accounts))
|
|
123
|
+
return EMPTY_NODE_ACCOUNTS;
|
|
124
|
+
return doc.accounts.filter((entry) => isRecord(entry) && typeof entry.id === 'string');
|
|
125
|
+
}, EMPTY_NODE_ACCOUNTS);
|
|
126
|
+
export const parseNodeExchangeConfigs = cachedByDoc((doc) => {
|
|
127
|
+
if (!Array.isArray(doc.exchange_configs))
|
|
128
|
+
return EMPTY_EXCHANGE_CONFIGS;
|
|
129
|
+
return doc.exchange_configs.filter((entry) => isRecord(entry) && typeof entry.id === 'string');
|
|
130
|
+
}, EMPTY_EXCHANGE_CONFIGS);
|
|
131
|
+
/** Map node-reported asset quantities to a flat holdings list. */
|
|
132
|
+
export function accountHoldingsFromNodeState(na) {
|
|
133
|
+
const assets = normalizeNodeAssets(na.assets);
|
|
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
|
+
}));
|
|
140
|
+
}
|
|
141
|
+
// ── Typed user-action accessors ──────────────────────────────────────────────
|
|
142
|
+
// Discriminated reads over UserAction.result / .configuration — replace
|
|
143
|
+
// ad-hoc `as X` casts.
|
|
144
|
+
export function automationResultOf(action) {
|
|
145
|
+
return action.result?.result_type === 'automation' ? action.result : null;
|
|
146
|
+
}
|
|
147
|
+
export function accountResultOf(action) {
|
|
148
|
+
return action.result?.result_type === 'account' ? action.result : null;
|
|
149
|
+
}
|
|
150
|
+
export function actionErrorDetails(action) {
|
|
151
|
+
// Every 0.4.0 result variant (automation, account, account_auth,
|
|
152
|
+
// exchange_config, strategy) carries the same optional error_details slot
|
|
153
|
+
// plus a structured error_message enum (e.g. 'strategy_not_found'). Both
|
|
154
|
+
// are optional — fall back to the enum so a failure is never blank.
|
|
155
|
+
const result = action.result;
|
|
156
|
+
return result?.error_details ?? result?.error_message ?? null;
|
|
157
|
+
}
|
|
158
|
+
/** The automation id a completed automation_create produced. */
|
|
159
|
+
export function createdAutomationIdOf(action) {
|
|
160
|
+
return automationResultOf(action)?.created_automation_id ?? null;
|
|
161
|
+
}
|
|
162
|
+
/** The account id an `account_create` carries. Unlike automations, account
|
|
163
|
+
* ids are client-assigned and reused verbatim by the node, so the creating
|
|
164
|
+
* action alone identifies the account it will produce. */
|
|
165
|
+
export function createdAccountIdOf(action) {
|
|
166
|
+
const cfg = action.configuration;
|
|
167
|
+
if (cfg?.action_type !== 'account_create')
|
|
168
|
+
return null;
|
|
169
|
+
return cfg.configuration?.id ?? null;
|
|
170
|
+
}
|
|
171
|
+
const ACTION_TYPE_DOMAIN = {
|
|
172
|
+
account_create: 'accounts',
|
|
173
|
+
account_edit: 'accounts',
|
|
174
|
+
account_delete: 'accounts',
|
|
175
|
+
account_auth_create: 'accounts',
|
|
176
|
+
account_auth_edit: 'accounts',
|
|
177
|
+
account_auth_delete: 'accounts',
|
|
178
|
+
exchange_config_create: 'accounts',
|
|
179
|
+
exchange_config_edit: 'accounts',
|
|
180
|
+
exchange_config_delete: 'accounts',
|
|
181
|
+
accounts_refresh: 'accounts',
|
|
182
|
+
automation_create: 'automations',
|
|
183
|
+
automation_edit: 'automations',
|
|
184
|
+
automation_stop: 'automations',
|
|
185
|
+
automation_signal: 'automations',
|
|
186
|
+
// A strategy only exists to back an automation — same domain.
|
|
187
|
+
strategy_create: 'automations',
|
|
188
|
+
strategy_edit: 'automations',
|
|
189
|
+
strategy_delete: 'automations',
|
|
190
|
+
};
|
|
191
|
+
/** Null for action types with no owning domain (a future protocol action
|
|
192
|
+
* added here before its domain is wired in degrades to "belongs nowhere"
|
|
193
|
+
* rather than crashing a domain filter). */
|
|
194
|
+
export function actionDomainOf(action) {
|
|
195
|
+
const type = action.configuration?.action_type;
|
|
196
|
+
return type ? ACTION_TYPE_DOMAIN[type] ?? null : null;
|
|
197
|
+
}
|
|
198
|
+
/** The automation an action targets — explicit id for edit/stop/signal, the
|
|
199
|
+
* node-reported created id for create. */
|
|
200
|
+
export function targetAutomationIdOf(action) {
|
|
201
|
+
const cfg = action.configuration;
|
|
202
|
+
if (!cfg)
|
|
203
|
+
return null;
|
|
204
|
+
switch (cfg.action_type) {
|
|
205
|
+
case 'automation_edit': return cfg.id;
|
|
206
|
+
case 'automation_stop': return cfg.id;
|
|
207
|
+
case 'automation_signal': return cfg.automation_id;
|
|
208
|
+
case 'automation_create': return createdAutomationIdOf(action);
|
|
209
|
+
default: return null;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/** Every account id an action targets. `account_create`/`_edit`/`_delete`
|
|
213
|
+
* carry the account id directly; `account_auth_*`/`exchange_config_*` carry
|
|
214
|
+
* an `auth_*`/`cfg_*` id derived from it and are reversed back to the
|
|
215
|
+
* account id. `accounts_refresh` with no explicit `account_ids` targets
|
|
216
|
+
* every account — callers should treat that case as "matches any account"
|
|
217
|
+
* rather than reading an empty array from here. */
|
|
218
|
+
export function targetAccountIdsOf(action) {
|
|
219
|
+
const cfg = action.configuration;
|
|
220
|
+
if (!cfg)
|
|
221
|
+
return [];
|
|
222
|
+
switch (cfg.action_type) {
|
|
223
|
+
case 'account_create': {
|
|
224
|
+
const id = createdAccountIdOf(action);
|
|
225
|
+
return id ? [id] : [];
|
|
226
|
+
}
|
|
227
|
+
case 'account_edit': return [cfg.id];
|
|
228
|
+
case 'account_delete': return [cfg.id];
|
|
229
|
+
case 'accounts_refresh': return cfg.account_ids ?? [];
|
|
230
|
+
case 'account_auth_create':
|
|
231
|
+
return [accountIdFromAuthId(cfg.configuration.id)];
|
|
232
|
+
case 'account_auth_edit': return [accountIdFromAuthId(cfg.id)];
|
|
233
|
+
case 'account_auth_delete': return [accountIdFromAuthId(cfg.id)];
|
|
234
|
+
case 'exchange_config_create':
|
|
235
|
+
return [accountIdFromExchangeConfigId(cfg.configuration.id)];
|
|
236
|
+
case 'exchange_config_edit':
|
|
237
|
+
return [accountIdFromExchangeConfigId(cfg.id)];
|
|
238
|
+
case 'exchange_config_delete':
|
|
239
|
+
return [accountIdFromExchangeConfigId(cfg.id)];
|
|
240
|
+
default: return [];
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
/** Whether a queued action targets the given account — an `accounts_refresh`
|
|
244
|
+
* with no explicit `account_ids` refreshes every account, so it counts as
|
|
245
|
+
* targeting all of them. */
|
|
246
|
+
export function actionTargetsAccount(action, accountId) {
|
|
247
|
+
const cfg = action.configuration;
|
|
248
|
+
if (cfg?.action_type === 'accounts_refresh' && !cfg.account_ids)
|
|
249
|
+
return true;
|
|
250
|
+
return targetAccountIdsOf(action).includes(accountId);
|
|
251
|
+
}
|
|
252
|
+
/** The strategy (id, version) an automation runs, recovered from the action
|
|
253
|
+
* history: node AutomationStates carry no strategy reference — the
|
|
254
|
+
* automation_create / automation_edit configurations are the only wire
|
|
255
|
+
* record. The newest action targeting the automation wins (an edit
|
|
256
|
+
* supersedes the create). */
|
|
257
|
+
export function automationStrategyRefOf(actions, automationId) {
|
|
258
|
+
let best = null;
|
|
259
|
+
let bestAt = '';
|
|
260
|
+
for (const action of actions) {
|
|
261
|
+
const cfg = action.configuration;
|
|
262
|
+
if (!cfg)
|
|
263
|
+
continue;
|
|
264
|
+
let ref;
|
|
265
|
+
if (cfg.action_type === 'automation_edit' && cfg.id === automationId) {
|
|
266
|
+
ref = cfg.configuration?.strategy;
|
|
267
|
+
}
|
|
268
|
+
else if (cfg.action_type === 'automation_create' && createdAutomationIdOf(action) === automationId) {
|
|
269
|
+
ref = cfg.configuration?.strategy;
|
|
270
|
+
}
|
|
271
|
+
if (!ref?.id)
|
|
272
|
+
continue;
|
|
273
|
+
const at = action.updated_at ?? action.created_at ?? '';
|
|
274
|
+
if (best === null || at >= bestAt) {
|
|
275
|
+
best = { id: ref.id, version: ref.version };
|
|
276
|
+
bestAt = at;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return best;
|
|
280
|
+
}
|
|
281
|
+
/** Human-facing name carried by the action's configuration, when one exists.
|
|
282
|
+
* Returns null when the configuration only carries an opaque id (stop /
|
|
283
|
+
* delete actions) — callers fall back to their own type label. */
|
|
284
|
+
export function actionDisplayName(action) {
|
|
285
|
+
const cfg = action.configuration;
|
|
286
|
+
if (!cfg)
|
|
287
|
+
return null;
|
|
288
|
+
switch (cfg.action_type) {
|
|
289
|
+
case 'automation_create': return cfg.configuration?.name ?? null;
|
|
290
|
+
case 'automation_edit': return cfg.configuration?.name ?? null;
|
|
291
|
+
case 'account_create':
|
|
292
|
+
case 'account_edit':
|
|
293
|
+
// Strategy actions carry the strategy's display name — the likeliest
|
|
294
|
+
// failure in the inbox (a strategy race) should not title generically.
|
|
295
|
+
case 'strategy_create':
|
|
296
|
+
case 'strategy_edit': {
|
|
297
|
+
const config = cfg.configuration;
|
|
298
|
+
return config?.name ?? null;
|
|
299
|
+
}
|
|
300
|
+
default: return null;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +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;AAGjF,wEAAwE;AACxE,+EAA+E;AAC/E,0EAA0E;AAC1E,2EAA2E;AAC3E,2EAA2E;AAE3E,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO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