@swarmclawai/swarmclaw 1.2.8 → 1.3.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.
Files changed (214) hide show
  1. package/README.md +39 -6
  2. package/package.json +2 -2
  3. package/src/app/agents/[id]/page.tsx +1 -18
  4. package/src/app/api/activity/route.ts +9 -23
  5. package/src/app/api/agents/route.ts +17 -1
  6. package/src/app/api/agents/thread-route.test.ts +0 -1
  7. package/src/app/api/approvals/route.test.ts +6 -22
  8. package/src/app/api/approvals/route.ts +13 -5
  9. package/src/app/api/connectors/route.ts +2 -2
  10. package/src/app/api/credentials/[id]/route.ts +2 -0
  11. package/src/app/api/credentials/route.ts +4 -1
  12. package/src/app/api/goals/[id]/route.ts +28 -0
  13. package/src/app/api/goals/route.ts +33 -0
  14. package/src/app/api/portability/export/route.ts +8 -0
  15. package/src/app/api/portability/import/route.test.ts +80 -0
  16. package/src/app/api/portability/import/route.ts +28 -0
  17. package/src/app/api/protocols/templates/[id]/route.ts +2 -1
  18. package/src/app/api/protocols/templates/route.ts +2 -1
  19. package/src/app/api/settings/route.ts +13 -2
  20. package/src/app/api/wallets/[id]/route.ts +15 -157
  21. package/src/app/api/wallets/generate/route.ts +22 -0
  22. package/src/app/api/wallets/route.test.ts +147 -0
  23. package/src/app/api/wallets/route.ts +13 -95
  24. package/src/app/autonomy/page.tsx +2 -57
  25. package/src/app/home/page.tsx +3 -0
  26. package/src/app/protocols/page.tsx +2 -21
  27. package/src/app/settings/page.tsx +0 -9
  28. package/src/app/wallets/page.tsx +105 -5
  29. package/src/cli/index.js +32 -33
  30. package/src/cli/spec.js +26 -27
  31. package/src/components/agents/agent-sheet.tsx +2 -40
  32. package/src/components/agents/inspector-panel.tsx +0 -83
  33. package/src/components/chat/chat-card.tsx +0 -31
  34. package/src/components/chat/message-bubble.tsx +1 -108
  35. package/src/components/connectors/connector-sheet.tsx +25 -1
  36. package/src/components/layout/sidebar-rail.tsx +6 -10
  37. package/src/components/projects/project-detail.tsx +3 -35
  38. package/src/components/projects/tabs/overview-tab.tsx +3 -59
  39. package/src/components/projects/tabs/work-tab.tsx +7 -77
  40. package/src/components/protocols/structured-session-launcher.tsx +1 -22
  41. package/src/components/shared/connector-platform-icon.tsx +1 -0
  42. package/src/components/tasks/task-card.tsx +4 -34
  43. package/src/components/tasks/task-sheet.tsx +6 -36
  44. package/src/components/wallets/wallet-list.tsx +150 -0
  45. package/src/lib/app/navigation.test.ts +0 -13
  46. package/src/lib/app/navigation.ts +2 -7
  47. package/src/lib/app/view-constants.ts +14 -19
  48. package/src/lib/server/activity/activity-log.ts +16 -1
  49. package/src/lib/server/agents/agent-service.ts +24 -11
  50. package/src/lib/server/agents/agent-thread-session.ts +0 -1
  51. package/src/lib/server/agents/delegation-advisory.test.ts +0 -1
  52. package/src/lib/server/agents/delegation-jobs.test.ts +0 -69
  53. package/src/lib/server/agents/delegation-jobs.ts +0 -25
  54. package/src/lib/server/agents/main-agent-loop.ts +1 -49
  55. package/src/lib/server/agents/subagent-runtime.ts +0 -1
  56. package/src/lib/server/approval-match.ts +14 -85
  57. package/src/lib/server/approvals/approval-hooks.ts +81 -0
  58. package/src/lib/server/approvals.test.ts +6 -6
  59. package/src/lib/server/approvals.ts +11 -6
  60. package/src/lib/server/autonomy/supervisor-reflection.test.ts +0 -1
  61. package/src/lib/server/builtin-extensions.ts +0 -2
  62. package/src/lib/server/capability-router.test.ts +0 -2
  63. package/src/lib/server/chat-execution/chat-execution-tool-events.test.ts +14 -14
  64. package/src/lib/server/chat-execution/chat-execution-types.ts +0 -2
  65. package/src/lib/server/chat-execution/chat-execution-utils.ts +0 -2
  66. package/src/lib/server/chat-execution/chat-streaming-utils.ts +2 -30
  67. package/src/lib/server/chat-execution/chat-turn-finalization.ts +1 -36
  68. package/src/lib/server/chat-execution/chat-turn-preparation.ts +2 -22
  69. package/src/lib/server/chat-execution/iteration-event-handler.ts +0 -24
  70. package/src/lib/server/chat-execution/message-classifier.test.ts +0 -45
  71. package/src/lib/server/chat-execution/message-classifier.ts +1 -16
  72. package/src/lib/server/chat-execution/prompt-builder.test.ts +0 -1
  73. package/src/lib/server/chat-execution/prompt-builder.ts +0 -30
  74. package/src/lib/server/chat-execution/prompt-sections.ts +0 -1
  75. package/src/lib/server/chat-execution/situational-awareness.test.ts +2 -73
  76. package/src/lib/server/chat-execution/situational-awareness.ts +4 -38
  77. package/src/lib/server/chat-execution/stream-agent-chat.test.ts +8 -123
  78. package/src/lib/server/chat-execution/stream-agent-chat.ts +1 -5
  79. package/src/lib/server/chat-execution/stream-continuation.test.ts +4 -52
  80. package/src/lib/server/chat-execution/stream-continuation.ts +6 -48
  81. package/src/lib/server/chatrooms/session-mailbox.ts +0 -10
  82. package/src/lib/server/chats/chat-session-service.ts +3 -5
  83. package/src/lib/server/connectors/connector-inbound.ts +0 -1
  84. package/src/lib/server/connectors/connector-lifecycle.ts +19 -3
  85. package/src/lib/server/connectors/connector-service.ts +39 -9
  86. package/src/lib/server/connectors/swarmdock-bidding.ts +74 -0
  87. package/src/lib/server/connectors/swarmdock-payloads.test.ts +85 -0
  88. package/src/lib/server/connectors/swarmdock-secret.test.ts +128 -0
  89. package/src/lib/server/connectors/swarmdock-secret.ts +152 -0
  90. package/src/lib/server/connectors/swarmdock-tasks.ts +127 -0
  91. package/src/lib/server/connectors/swarmdock.ts +285 -0
  92. package/src/lib/server/execution-brief.test.ts +2 -25
  93. package/src/lib/server/execution-brief.ts +30 -35
  94. package/src/lib/server/execution-engine/task-attempt.ts +0 -1
  95. package/src/lib/server/goals/goal-repository.ts +19 -0
  96. package/src/lib/server/goals/goal-service.ts +143 -0
  97. package/src/lib/server/persistence/storage-context.ts +0 -5
  98. package/src/lib/server/portability/export.ts +109 -0
  99. package/src/lib/server/portability/import.ts +159 -0
  100. package/src/lib/server/protocols/protocol-normalization.ts +0 -4
  101. package/src/lib/server/protocols/protocol-queries.ts +0 -6
  102. package/src/lib/server/protocols/protocol-run-lifecycle.ts +4 -32
  103. package/src/lib/server/protocols/protocol-service.ts +0 -1
  104. package/src/lib/server/protocols/protocol-step-helpers.ts +0 -4
  105. package/src/lib/server/protocols/protocol-step-processors.ts +0 -6
  106. package/src/lib/server/protocols/protocol-swarm.ts +0 -2
  107. package/src/lib/server/protocols/protocol-types.ts +0 -2
  108. package/src/lib/server/provider-health.ts +0 -9
  109. package/src/lib/server/runtime/daemon-state/core.ts +0 -9
  110. package/src/lib/server/runtime/daemon-state.test.ts +0 -35
  111. package/src/lib/server/runtime/heartbeat-service.ts +3 -23
  112. package/src/lib/server/runtime/queue/core.ts +11 -33
  113. package/src/lib/server/runtime/runtime-storage-write-paths.test.ts +6 -6
  114. package/src/lib/server/runtime/scheduler.ts +0 -13
  115. package/src/lib/server/runtime/session-run-manager/drain.ts +0 -24
  116. package/src/lib/server/runtime/session-run-manager/enqueue.ts +0 -1
  117. package/src/lib/server/runtime/session-run-manager/queries.ts +0 -1
  118. package/src/lib/server/runtime/session-run-manager/recovery.ts +0 -1
  119. package/src/lib/server/runtime/session-run-manager.test.ts +0 -28
  120. package/src/lib/server/session-tools/crud.ts +0 -14
  121. package/src/lib/server/session-tools/delegate.ts +0 -4
  122. package/src/lib/server/session-tools/index.ts +0 -4
  123. package/src/lib/server/session-tools/team-context.ts +0 -3
  124. package/src/lib/server/storage-normalization.ts +13 -0
  125. package/src/lib/server/storage.ts +75 -45
  126. package/src/lib/server/tasks/task-checkout.ts +59 -0
  127. package/src/lib/server/tasks/task-lifecycle.ts +2 -0
  128. package/src/lib/server/tasks/task-route-service.ts +4 -26
  129. package/src/lib/server/tasks/task-service.ts +0 -7
  130. package/src/lib/server/tool-aliases.ts +0 -1
  131. package/src/lib/server/tool-capability-policy-advanced.test.ts +4 -4
  132. package/src/lib/server/tool-capability-policy.ts +0 -2
  133. package/src/lib/server/tool-planning.ts +0 -12
  134. package/src/lib/server/universal-tool-access.ts +0 -1
  135. package/src/lib/server/usage/cost-rollup.ts +124 -0
  136. package/src/lib/server/usage/usage-repository.ts +6 -0
  137. package/src/lib/server/wallets/wallet-crypto.ts +33 -0
  138. package/src/lib/server/wallets/wallet-repository.ts +24 -0
  139. package/src/lib/server/wallets/wallet-service.ts +119 -0
  140. package/src/lib/server/working-state/extraction.ts +8 -42
  141. package/src/lib/server/working-state/normalization.ts +10 -103
  142. package/src/lib/server/working-state/service.ts +12 -21
  143. package/src/lib/strip-internal-metadata.test.ts +1 -1
  144. package/src/lib/strip-internal-metadata.ts +1 -1
  145. package/src/lib/tool-definitions.ts +0 -1
  146. package/src/lib/validation/schemas.ts +36 -32
  147. package/src/lib/validation/server-schemas.ts +35 -0
  148. package/src/stores/slices/data-slice.ts +5 -1
  149. package/src/stores/slices/ui-slice.ts +0 -4
  150. package/src/types/agent.ts +10 -84
  151. package/src/types/app-settings.ts +6 -2
  152. package/src/types/approval.ts +3 -2
  153. package/src/types/connector.ts +1 -0
  154. package/src/types/goal.ts +30 -0
  155. package/src/types/index.ts +2 -1
  156. package/src/types/message.ts +0 -1
  157. package/src/types/misc.ts +2 -4
  158. package/src/types/protocol.ts +0 -2
  159. package/src/types/run.ts +0 -3
  160. package/src/types/session.ts +1 -51
  161. package/src/types/swarmdock.ts +29 -0
  162. package/src/types/task.ts +9 -3
  163. package/src/types/working-state.ts +2 -9
  164. package/src/views/settings/section-runtime-loop.tsx +0 -14
  165. package/src/app/api/canvas/[sessionId]/route.ts +0 -35
  166. package/src/app/api/missions/[id]/actions/route.ts +0 -31
  167. package/src/app/api/missions/[id]/events/route.ts +0 -14
  168. package/src/app/api/missions/[id]/route.ts +0 -10
  169. package/src/app/api/missions/route.test.ts +0 -244
  170. package/src/app/api/missions/route.ts +0 -57
  171. package/src/app/api/wallets/[id]/approve/route.ts +0 -79
  172. package/src/app/api/wallets/[id]/balance-history/route.ts +0 -18
  173. package/src/app/api/wallets/[id]/send/route.ts +0 -113
  174. package/src/app/api/wallets/[id]/transactions/route.ts +0 -18
  175. package/src/app/missions/[id]/page.tsx +0 -3
  176. package/src/app/missions/page.tsx +0 -685
  177. package/src/components/canvas/canvas-panel.tsx +0 -267
  178. package/src/components/wallets/wallet-approval-dialog.tsx +0 -107
  179. package/src/components/wallets/wallet-panel.tsx +0 -1010
  180. package/src/components/wallets/wallet-section.tsx +0 -260
  181. package/src/features/missions/queries.ts +0 -23
  182. package/src/lib/canvas-content.test.ts +0 -360
  183. package/src/lib/canvas-content.ts +0 -198
  184. package/src/lib/server/canvas-content.test.ts +0 -32
  185. package/src/lib/server/canvas-content.ts +0 -6
  186. package/src/lib/server/ethereum.ts +0 -591
  187. package/src/lib/server/evm-swap.ts +0 -476
  188. package/src/lib/server/missions/mission-intent.test.ts +0 -63
  189. package/src/lib/server/missions/mission-intent.ts +0 -569
  190. package/src/lib/server/missions/mission-repository.ts +0 -74
  191. package/src/lib/server/missions/mission-service/actions.ts +0 -6
  192. package/src/lib/server/missions/mission-service/bindings.ts +0 -9
  193. package/src/lib/server/missions/mission-service/context.ts +0 -4
  194. package/src/lib/server/missions/mission-service/core.ts +0 -2271
  195. package/src/lib/server/missions/mission-service/queries.ts +0 -12
  196. package/src/lib/server/missions/mission-service/recovery.ts +0 -5
  197. package/src/lib/server/missions/mission-service/ticks.ts +0 -9
  198. package/src/lib/server/missions/mission-service.test.ts +0 -888
  199. package/src/lib/server/missions/mission-service.ts +0 -6
  200. package/src/lib/server/session-tools/canvas.ts +0 -105
  201. package/src/lib/server/session-tools/wallet-tool.test.ts +0 -150
  202. package/src/lib/server/session-tools/wallet.ts +0 -1287
  203. package/src/lib/server/solana.ts +0 -327
  204. package/src/lib/server/wallet/wallet-execution.test.ts +0 -198
  205. package/src/lib/server/wallet/wallet-portfolio.test.ts +0 -98
  206. package/src/lib/server/wallet/wallet-portfolio.ts +0 -772
  207. package/src/lib/server/wallet/wallet-service.test.ts +0 -81
  208. package/src/lib/server/wallet/wallet-service.ts +0 -225
  209. package/src/lib/wallet/wallet-transactions.test.ts +0 -75
  210. package/src/lib/wallet/wallet-transactions.ts +0 -43
  211. package/src/lib/wallet/wallet.test.ts +0 -333
  212. package/src/lib/wallet/wallet.ts +0 -183
  213. package/src/types/mission.ts +0 -185
  214. package/src/views/settings/section-wallets.tsx +0 -35
@@ -1,333 +0,0 @@
1
- import { describe, it } from 'node:test'
2
- import assert from 'node:assert/strict'
3
- import {
4
- normalizeWalletChainInput,
5
- getWalletChainOrDefault,
6
- normalizeAtomicString,
7
- parseDisplayAmountToAtomic,
8
- formatAtomicAmount,
9
- formatWalletAmount,
10
- getWalletChainMeta,
11
- getWalletDefaultLimitAtomic,
12
- getWalletExplorerUrl,
13
- getWalletAssetSymbol,
14
- getWalletAtomicAmount,
15
- getWalletFeeAtomicAmount,
16
- getWalletLimitAtomic,
17
- getWalletBalanceAtomic,
18
- } from '@/lib/wallet/wallet'
19
-
20
- describe('normalizeWalletChainInput', () => {
21
- it('normalizes solana variants', () => {
22
- assert.equal(normalizeWalletChainInput('solana'), 'solana')
23
- assert.equal(normalizeWalletChainInput('Solana'), 'solana')
24
- assert.equal(normalizeWalletChainInput('SOL'), 'solana')
25
- assert.equal(normalizeWalletChainInput('sol'), 'solana')
26
- assert.equal(normalizeWalletChainInput(' sol '), 'solana')
27
- })
28
-
29
- it('normalizes ethereum variants', () => {
30
- assert.equal(normalizeWalletChainInput('ethereum'), 'ethereum')
31
- assert.equal(normalizeWalletChainInput('Ethereum'), 'ethereum')
32
- assert.equal(normalizeWalletChainInput('ETH'), 'ethereum')
33
- assert.equal(normalizeWalletChainInput('eth'), 'ethereum')
34
- assert.equal(normalizeWalletChainInput('evm'), 'ethereum')
35
- assert.equal(normalizeWalletChainInput('EVM'), 'ethereum')
36
- })
37
-
38
- it('returns null for unsupported or empty input', () => {
39
- assert.equal(normalizeWalletChainInput('bitcoin'), null)
40
- assert.equal(normalizeWalletChainInput(''), null)
41
- assert.equal(normalizeWalletChainInput(null), null)
42
- assert.equal(normalizeWalletChainInput(undefined), null)
43
- assert.equal(normalizeWalletChainInput(0), null)
44
- assert.equal(normalizeWalletChainInput(false), null)
45
- })
46
- })
47
-
48
- describe('getWalletChainOrDefault', () => {
49
- it('returns recognized chain', () => {
50
- assert.equal(getWalletChainOrDefault('sol'), 'solana')
51
- assert.equal(getWalletChainOrDefault('eth'), 'ethereum')
52
- })
53
-
54
- it('returns fallback for empty/null/undefined', () => {
55
- assert.equal(getWalletChainOrDefault(''), 'solana')
56
- assert.equal(getWalletChainOrDefault(null), 'solana')
57
- assert.equal(getWalletChainOrDefault(undefined), 'solana')
58
- assert.equal(getWalletChainOrDefault(undefined, 'ethereum'), 'ethereum')
59
- })
60
-
61
- it('throws for unrecognized non-empty value', () => {
62
- assert.throws(() => getWalletChainOrDefault('bitcoin'), /Unsupported wallet chain/)
63
- assert.throws(() => getWalletChainOrDefault('base'), /Unsupported wallet chain or provider: base/)
64
- assert.throws(() => getWalletChainOrDefault('ethereun'), /Unsupported wallet chain or provider: ethereun/)
65
- })
66
- })
67
-
68
- describe('normalizeAtomicString', () => {
69
- it('handles string integers', () => {
70
- assert.equal(normalizeAtomicString('12345'), '12345')
71
- assert.equal(normalizeAtomicString('0'), '0')
72
- assert.equal(normalizeAtomicString('007'), '7')
73
- assert.equal(normalizeAtomicString('0000'), '0')
74
- })
75
-
76
- it('handles bigint', () => {
77
- assert.equal(normalizeAtomicString(BigInt(999)), '999')
78
- assert.equal(normalizeAtomicString(BigInt(0)), '0')
79
- assert.equal(normalizeAtomicString(BigInt(-5)), '0')
80
- assert.equal(normalizeAtomicString(BigInt(-1), 'fallback'), 'fallback')
81
- })
82
-
83
- it('handles number', () => {
84
- assert.equal(normalizeAtomicString(100), '100')
85
- assert.equal(normalizeAtomicString(3.9), '3')
86
- assert.equal(normalizeAtomicString(0), '0')
87
- })
88
-
89
- it('returns fallback for invalid input', () => {
90
- assert.equal(normalizeAtomicString('abc'), '0')
91
- assert.equal(normalizeAtomicString('12.5'), '0')
92
- assert.equal(normalizeAtomicString(-1), '0')
93
- assert.equal(normalizeAtomicString(NaN), '0')
94
- assert.equal(normalizeAtomicString(Infinity), '0')
95
- assert.equal(normalizeAtomicString(null), '0')
96
- assert.equal(normalizeAtomicString(undefined), '0')
97
- assert.equal(normalizeAtomicString(' '), '0')
98
- assert.equal(normalizeAtomicString(null, 'custom'), 'custom')
99
- })
100
-
101
- it('strips leading zeros from strings', () => {
102
- assert.equal(normalizeAtomicString('00100'), '100')
103
- assert.equal(normalizeAtomicString('00'), '0')
104
- })
105
- })
106
-
107
- describe('parseDisplayAmountToAtomic', () => {
108
- it('converts whole numbers (SOL, 9 decimals)', () => {
109
- assert.equal(parseDisplayAmountToAtomic('1', 9), '1000000000')
110
- assert.equal(parseDisplayAmountToAtomic('0', 9), '0')
111
- assert.equal(parseDisplayAmountToAtomic('100', 9), '100000000000')
112
- })
113
-
114
- it('converts fractional numbers (SOL)', () => {
115
- assert.equal(parseDisplayAmountToAtomic('0.1', 9), '100000000')
116
- assert.equal(parseDisplayAmountToAtomic('1.5', 9), '1500000000')
117
- assert.equal(parseDisplayAmountToAtomic('0.000000001', 9), '1')
118
- })
119
-
120
- it('converts with ETH decimals (18)', () => {
121
- assert.equal(parseDisplayAmountToAtomic('1', 18), '1000000000000000000')
122
- assert.equal(parseDisplayAmountToAtomic('0.01', 18), '10000000000000000')
123
- assert.equal(parseDisplayAmountToAtomic('0.000000000000000001', 18), '1')
124
- })
125
-
126
- it('accepts number input', () => {
127
- assert.equal(parseDisplayAmountToAtomic(1.5, 9), '1500000000')
128
- assert.equal(parseDisplayAmountToAtomic(0, 9), '0')
129
- assert.equal(parseDisplayAmountToAtomic(0.000000000000000001, 18), '1')
130
- })
131
-
132
- it('throws for empty amount', () => {
133
- assert.throws(() => parseDisplayAmountToAtomic('', 9), /Amount is required/)
134
- })
135
-
136
- it('throws for non-numeric strings', () => {
137
- assert.throws(() => parseDisplayAmountToAtomic('abc', 9), /Amount must be a positive decimal/)
138
- assert.throws(() => parseDisplayAmountToAtomic('-1', 9), /Amount must be a positive decimal/)
139
- })
140
-
141
- it('throws for too many decimal places', () => {
142
- assert.throws(() => parseDisplayAmountToAtomic('1.0000000001', 9), /up to 9 decimal places/)
143
- })
144
- })
145
-
146
- describe('formatAtomicAmount', () => {
147
- it('formats SOL (9 decimals)', () => {
148
- assert.equal(formatAtomicAmount('1000000000', 9), '1')
149
- assert.equal(formatAtomicAmount('1500000000', 9), '1.5')
150
- assert.equal(formatAtomicAmount('100000000', 9), '0.1')
151
- assert.equal(formatAtomicAmount('1', 9), '0.000000001')
152
- assert.equal(formatAtomicAmount('0', 9), '0')
153
- })
154
-
155
- it('formats ETH (18 decimals)', () => {
156
- assert.equal(formatAtomicAmount('1000000000000000000', 18), '1')
157
- assert.equal(formatAtomicAmount('10000000000000000', 18), '0.01')
158
- })
159
-
160
- it('respects minFractionDigits', () => {
161
- assert.equal(formatAtomicAmount('1000000000', 9, { minFractionDigits: 2 }), '1.00')
162
- assert.equal(formatAtomicAmount('1500000000', 9, { minFractionDigits: 4 }), '1.5000')
163
- })
164
-
165
- it('respects maxFractionDigits', () => {
166
- assert.equal(formatAtomicAmount('1', 9, { maxFractionDigits: 2 }), '0')
167
- assert.equal(formatAtomicAmount('1000000000', 9, { maxFractionDigits: 0 }), '1')
168
- })
169
-
170
- it('handles bigint input', () => {
171
- assert.equal(formatAtomicAmount(BigInt('1000000000'), 9), '1')
172
- })
173
-
174
- it('handles number input', () => {
175
- assert.equal(formatAtomicAmount(1000000000, 9), '1')
176
- })
177
- })
178
-
179
- describe('formatWalletAmount', () => {
180
- it('uses chain-specific decimals', () => {
181
- assert.equal(formatWalletAmount('solana', '1000000000'), '1')
182
- assert.equal(formatWalletAmount('ethereum', '1000000000000000000'), '1')
183
- })
184
- })
185
-
186
- describe('getWalletChainMeta', () => {
187
- it('returns solana metadata', () => {
188
- const meta = getWalletChainMeta('solana')
189
- assert.equal(meta.symbol, 'SOL')
190
- assert.equal(meta.decimals, 9)
191
- assert.equal(meta.chain, 'solana')
192
- })
193
-
194
- it('returns ethereum metadata', () => {
195
- const meta = getWalletChainMeta('ethereum')
196
- assert.equal(meta.symbol, 'ETH')
197
- assert.equal(meta.decimals, 18)
198
- })
199
-
200
- it('falls back to solana for unknown chain', () => {
201
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
202
- const meta = getWalletChainMeta('unknown' as any)
203
- assert.equal(meta.chain, 'solana')
204
- })
205
- })
206
-
207
- describe('getWalletDefaultLimitAtomic', () => {
208
- it('returns perTx and daily defaults', () => {
209
- assert.equal(getWalletDefaultLimitAtomic('solana', 'perTx'), '100000000')
210
- assert.equal(getWalletDefaultLimitAtomic('solana', 'daily'), '1000000000')
211
- assert.equal(getWalletDefaultLimitAtomic('ethereum', 'perTx'), '10000000000000000')
212
- assert.equal(getWalletDefaultLimitAtomic('ethereum', 'daily'), '50000000000000000')
213
- })
214
- })
215
-
216
- describe('getWalletExplorerUrl', () => {
217
- it('builds address explorer URLs', () => {
218
- assert.equal(
219
- getWalletExplorerUrl('solana', 'address', 'abc123'),
220
- 'https://solscan.io/account/abc123',
221
- )
222
- assert.equal(
223
- getWalletExplorerUrl('ethereum', 'address', '0xdef'),
224
- 'https://etherscan.io/address/0xdef',
225
- )
226
- })
227
-
228
- it('builds transaction explorer URLs', () => {
229
- assert.equal(
230
- getWalletExplorerUrl('solana', 'transaction', 'tx1'),
231
- 'https://solscan.io/tx/tx1',
232
- )
233
- assert.equal(
234
- getWalletExplorerUrl('ethereum', 'transaction', '0xtx'),
235
- 'https://etherscan.io/tx/0xtx',
236
- )
237
- })
238
- })
239
-
240
- describe('getWalletAssetSymbol', () => {
241
- it('returns chain symbols', () => {
242
- assert.equal(getWalletAssetSymbol('solana'), 'SOL')
243
- assert.equal(getWalletAssetSymbol('ethereum'), 'ETH')
244
- })
245
- })
246
-
247
- describe('getWalletAtomicAmount', () => {
248
- it('prefers amountAtomic', () => {
249
- assert.equal(getWalletAtomicAmount({ amountAtomic: '500' }), '500')
250
- })
251
-
252
- it('falls back to amountLamports', () => {
253
- assert.equal(getWalletAtomicAmount({ amountLamports: 300 }), '300')
254
- })
255
-
256
- it('returns 0 for null/undefined', () => {
257
- assert.equal(getWalletAtomicAmount(null), '0')
258
- assert.equal(getWalletAtomicAmount(undefined), '0')
259
- })
260
-
261
- it('returns 0 for empty object', () => {
262
- assert.equal(getWalletAtomicAmount({}), '0')
263
- })
264
- })
265
-
266
- describe('getWalletFeeAtomicAmount', () => {
267
- it('prefers feeAtomic', () => {
268
- assert.equal(getWalletFeeAtomicAmount({ feeAtomic: '5000' }), '5000')
269
- })
270
-
271
- it('falls back to feeLamports', () => {
272
- assert.equal(getWalletFeeAtomicAmount({ feeLamports: 5000 }), '5000')
273
- })
274
-
275
- it('returns 0 for null/undefined', () => {
276
- assert.equal(getWalletFeeAtomicAmount(null), '0')
277
- assert.equal(getWalletFeeAtomicAmount(undefined), '0')
278
- })
279
- })
280
-
281
- describe('getWalletLimitAtomic', () => {
282
- it('uses spendingLimitAtomic for perTx', () => {
283
- assert.equal(
284
- getWalletLimitAtomic({ chain: 'solana', spendingLimitAtomic: '50000' }, 'perTx'),
285
- '50000',
286
- )
287
- })
288
-
289
- it('falls back to spendingLimitLamports then default for perTx', () => {
290
- assert.equal(
291
- getWalletLimitAtomic({ chain: 'solana', spendingLimitLamports: 25000 }, 'perTx'),
292
- '25000',
293
- )
294
- assert.equal(
295
- getWalletLimitAtomic({ chain: 'solana' }, 'perTx'),
296
- '100000000',
297
- )
298
- })
299
-
300
- it('uses dailyLimitAtomic for daily', () => {
301
- assert.equal(
302
- getWalletLimitAtomic({ chain: 'ethereum', dailyLimitAtomic: '99999' }, 'daily'),
303
- '99999',
304
- )
305
- })
306
-
307
- it('falls back for daily', () => {
308
- assert.equal(
309
- getWalletLimitAtomic({ chain: 'ethereum' }, 'daily'),
310
- '50000000000000000',
311
- )
312
- })
313
- })
314
-
315
- describe('getWalletBalanceAtomic', () => {
316
- it('prefers balanceAtomic', () => {
317
- assert.equal(getWalletBalanceAtomic({ balanceAtomic: '12345' }), '12345')
318
- })
319
-
320
- it('falls back to balanceLamports', () => {
321
- assert.equal(getWalletBalanceAtomic({ balanceLamports: 9999 }), '9999')
322
- })
323
-
324
- it('returns 0 for null/undefined/empty', () => {
325
- assert.equal(getWalletBalanceAtomic(null), '0')
326
- assert.equal(getWalletBalanceAtomic(undefined), '0')
327
- assert.equal(getWalletBalanceAtomic({}), '0')
328
- })
329
-
330
- it('handles null balanceLamports', () => {
331
- assert.equal(getWalletBalanceAtomic({ balanceLamports: null }), '0')
332
- })
333
- })
@@ -1,183 +0,0 @@
1
- import type { WalletChain } from '@/types'
2
-
3
- export const SUPPORTED_WALLET_CHAINS = ['solana', 'ethereum'] as const
4
-
5
- export interface WalletChainMeta {
6
- chain: WalletChain
7
- label: string
8
- symbol: string
9
- decimals: number
10
- defaultPerTxAtomic: string
11
- defaultDailyAtomic: string
12
- addressExplorerBaseUrl: string
13
- transactionExplorerBaseUrl: string
14
- createDescription: string
15
- fundingInstructions: string[]
16
- }
17
-
18
- const WALLET_CHAIN_META: Record<WalletChain, WalletChainMeta> = {
19
- solana: {
20
- chain: 'solana',
21
- label: 'Solana',
22
- symbol: 'SOL',
23
- decimals: 9,
24
- defaultPerTxAtomic: '100000000',
25
- defaultDailyAtomic: '1000000000',
26
- addressExplorerBaseUrl: 'https://solscan.io/account/',
27
- transactionExplorerBaseUrl: 'https://solscan.io/tx/',
28
- createDescription: 'Create a Solana wallet for agents that need SOL-native transfers and Solana ecosystem access.',
29
- fundingInstructions: [
30
- 'Send SOL to this wallet address from any Solana wallet or exchange.',
31
- 'Make sure you are sending real SOL on Solana mainnet.',
32
- ],
33
- },
34
- ethereum: {
35
- chain: 'ethereum',
36
- label: 'Ethereum',
37
- symbol: 'ETH',
38
- decimals: 18,
39
- defaultPerTxAtomic: '10000000000000000',
40
- defaultDailyAtomic: '50000000000000000',
41
- addressExplorerBaseUrl: 'https://etherscan.io/address/',
42
- transactionExplorerBaseUrl: 'https://etherscan.io/tx/',
43
- createDescription: 'Create an Ethereum-compatible EVM wallet for ETH-native transfers, exchange auth, and EVM ecosystem access.',
44
- fundingInstructions: [
45
- 'Send ETH to this wallet address from any Ethereum-compatible wallet or exchange.',
46
- 'Make sure the sending network matches the wallet network you intend to use before transferring funds.',
47
- ],
48
- },
49
- }
50
-
51
- export function getWalletChainMeta(chain: WalletChain): WalletChainMeta {
52
- return WALLET_CHAIN_META[chain] || WALLET_CHAIN_META.solana
53
- }
54
-
55
- export function normalizeWalletChainInput(value: unknown): WalletChain | null {
56
- const normalized = String(value || '').trim().toLowerCase()
57
- if (!normalized) return null
58
- if (normalized === 'sol' || normalized === 'solana') return 'solana'
59
- if (normalized === 'eth' || normalized === 'ethereum' || normalized === 'evm') {
60
- return 'ethereum'
61
- }
62
- return null
63
- }
64
-
65
- export function getWalletChainOrDefault(value: unknown, fallback: WalletChain = 'solana'): WalletChain {
66
- const normalized = normalizeWalletChainInput(value)
67
- if (normalized) return normalized
68
- const raw = String(value ?? '').trim()
69
- if (raw) {
70
- throw new Error(`Unsupported wallet chain or provider: ${raw}`)
71
- }
72
- return fallback
73
- }
74
-
75
- export function getWalletDefaultLimitAtomic(chain: WalletChain, limit: 'perTx' | 'daily'): string {
76
- const meta = getWalletChainMeta(chain)
77
- return limit === 'perTx' ? meta.defaultPerTxAtomic : meta.defaultDailyAtomic
78
- }
79
-
80
- export function normalizeAtomicString(value: unknown, fallback = '0'): string {
81
- if (typeof value === 'bigint') return value >= BigInt(0) ? value.toString() : fallback
82
- if (typeof value === 'number' && Number.isFinite(value) && value >= 0) return Math.floor(value).toString()
83
- if (typeof value === 'string') {
84
- const trimmed = value.trim()
85
- if (/^\d+$/.test(trimmed)) return trimmed.replace(/^0+(?=\d)/, '') || '0'
86
- }
87
- return fallback
88
- }
89
-
90
- export function parseDisplayAmountToAtomic(value: string | number, decimals: number): string {
91
- const raw = typeof value === 'number'
92
- ? value.toLocaleString('en-US', {
93
- useGrouping: false,
94
- maximumFractionDigits: decimals,
95
- }).trim()
96
- : String(value ?? '').trim()
97
- if (!raw) throw new Error('Amount is required')
98
- if (!/^\d+(\.\d+)?$/.test(raw)) throw new Error('Amount must be a positive decimal number')
99
-
100
- const [whole, fraction = ''] = raw.split('.')
101
- if (fraction.length > decimals) {
102
- throw new Error(`Amount supports up to ${decimals} decimal places`)
103
- }
104
-
105
- const wholePart = BigInt(whole || '0')
106
- const fractionPadded = `${fraction}${'0'.repeat(decimals)}`.slice(0, decimals)
107
- const fractionPart = BigInt(fractionPadded || '0')
108
- const scale = BigInt(10) ** BigInt(decimals)
109
- return ((wholePart * scale) + fractionPart).toString()
110
- }
111
-
112
- export function formatAtomicAmount(
113
- atomicValue: string | number | bigint,
114
- decimals: number,
115
- opts?: { minFractionDigits?: number; maxFractionDigits?: number }
116
- ): string {
117
- const atomic = BigInt(normalizeAtomicString(atomicValue, '0'))
118
- const scale = BigInt(10) ** BigInt(decimals)
119
- const whole = atomic / scale
120
- const fraction = atomic % scale
121
- const maxFractionDigits = Math.max(0, Math.min(decimals, opts?.maxFractionDigits ?? decimals))
122
- const minFractionDigits = Math.max(0, Math.min(maxFractionDigits, opts?.minFractionDigits ?? 0))
123
-
124
- if (maxFractionDigits === 0) return whole.toString()
125
-
126
- let fractionText = fraction.toString().padStart(decimals, '0').slice(0, maxFractionDigits)
127
- if (fractionText.length < minFractionDigits) fractionText = fractionText.padEnd(minFractionDigits, '0')
128
- if (fractionText.length > minFractionDigits) fractionText = fractionText.replace(/0+$/, '')
129
- if (fractionText.length < minFractionDigits) fractionText = fractionText.padEnd(minFractionDigits, '0')
130
-
131
- return fractionText.length > 0 ? `${whole.toString()}.${fractionText}` : whole.toString()
132
- }
133
-
134
- export function formatWalletAmount(
135
- chain: WalletChain,
136
- atomicValue: string | number | bigint,
137
- opts?: { minFractionDigits?: number; maxFractionDigits?: number }
138
- ): string {
139
- return formatAtomicAmount(atomicValue, getWalletChainMeta(chain).decimals, opts)
140
- }
141
-
142
- export function getWalletExplorerUrl(chain: WalletChain, kind: 'address' | 'transaction', value: string): string {
143
- const meta = getWalletChainMeta(chain)
144
- const base = kind === 'address' ? meta.addressExplorerBaseUrl : meta.transactionExplorerBaseUrl
145
- return `${base}${value}`
146
- }
147
-
148
- export function getWalletAssetSymbol(chain: WalletChain): string {
149
- return getWalletChainMeta(chain).symbol
150
- }
151
-
152
- export function getWalletAtomicAmount(value: { amountAtomic?: string; amountLamports?: number } | null | undefined): string {
153
- if (!value) return '0'
154
- return normalizeAtomicString(value.amountAtomic, normalizeAtomicString(value.amountLamports, '0'))
155
- }
156
-
157
- export function getWalletFeeAtomicAmount(value: { feeAtomic?: string; feeLamports?: number } | null | undefined): string {
158
- if (!value) return '0'
159
- return normalizeAtomicString(value.feeAtomic, normalizeAtomicString(value.feeLamports, '0'))
160
- }
161
-
162
- export function getWalletLimitAtomic(
163
- wallet: { chain: WalletChain; spendingLimitAtomic?: string; spendingLimitLamports?: number; dailyLimitAtomic?: string; dailyLimitLamports?: number },
164
- limit: 'perTx' | 'daily',
165
- ): string {
166
- if (limit === 'perTx') {
167
- return normalizeAtomicString(
168
- wallet.spendingLimitAtomic,
169
- normalizeAtomicString(wallet.spendingLimitLamports, getWalletDefaultLimitAtomic(wallet.chain, 'perTx')),
170
- )
171
- }
172
- return normalizeAtomicString(
173
- wallet.dailyLimitAtomic,
174
- normalizeAtomicString(wallet.dailyLimitLamports, getWalletDefaultLimitAtomic(wallet.chain, 'daily')),
175
- )
176
- }
177
-
178
- export function getWalletBalanceAtomic(
179
- wallet: { balanceAtomic?: string; balanceLamports?: number | null } | null | undefined,
180
- ): string {
181
- if (!wallet) return '0'
182
- return normalizeAtomicString(wallet.balanceAtomic, normalizeAtomicString(wallet.balanceLamports, '0'))
183
- }
@@ -1,185 +0,0 @@
1
- export type MissionSource =
2
- | 'chat'
3
- | 'connector'
4
- | 'heartbeat'
5
- | 'main-loop-followup'
6
- | 'task'
7
- | 'schedule'
8
- | 'delegation'
9
- | 'manual'
10
-
11
- export type MissionStatus = 'active' | 'waiting' | 'completed' | 'failed' | 'cancelled'
12
- export type MissionPhase = 'intake' | 'planning' | 'dispatching' | 'executing' | 'verifying' | 'waiting' | 'completed' | 'failed'
13
- export type MissionWaitKind =
14
- | 'human_reply'
15
- | 'approval'
16
- | 'external_dependency'
17
- | 'provider'
18
- | 'blocked_task'
19
- | 'blocked_mission'
20
- | 'scheduled'
21
- | 'other'
22
-
23
- export type MissionPlannerDecision =
24
- | 'dispatch_task'
25
- | 'dispatch_session_turn'
26
- | 'spawn_child_mission'
27
- | 'wait'
28
- | 'verify_now'
29
- | 'complete_candidate'
30
- | 'replan'
31
- | 'fail_terminal'
32
- | 'cancel'
33
-
34
- export type MissionVerificationVerdict =
35
- | 'continue'
36
- | 'waiting'
37
- | 'completed'
38
- | 'failed'
39
- | 'replan'
40
-
41
- export type MissionSourceRef =
42
- | { kind: 'chat'; sessionId: string; messageId?: string | null }
43
- | { kind: 'connector'; sessionId: string; connectorId: string; channelId: string; threadId?: string | null }
44
- | { kind: 'schedule'; scheduleId: string; recurring: boolean }
45
- | { kind: 'task'; taskId: string }
46
- | { kind: 'delegation'; parentMissionId: string; backend?: 'agent' | 'codex' | 'claude' | 'opencode' | 'gemini' | null }
47
- | { kind: 'heartbeat'; sessionId: string }
48
- | { kind: 'manual' }
49
-
50
- export interface MissionWaitState {
51
- kind: MissionWaitKind
52
- reason: string
53
- approvalId?: string | null
54
- untilAt?: number | null
55
- dependencyTaskId?: string | null
56
- dependencyMissionId?: string | null
57
- providerKey?: string | null
58
- }
59
-
60
- export interface MissionControllerState {
61
- leaseId?: string | null
62
- leaseExpiresAt?: number | null
63
- tickRequestedAt?: number | null
64
- tickReason?: string | null
65
- plannerRunId?: string | null
66
- verifierRunId?: string | null
67
- activeRunId?: string | null
68
- currentTaskId?: string | null
69
- currentChildMissionId?: string | null
70
- pendingWakeId?: string | null
71
- attemptCount?: number
72
- lastEvidenceAt?: number | null
73
- }
74
-
75
- export interface MissionPlannerState {
76
- lastDecision?: MissionPlannerDecision | null
77
- lastPlannedAt?: number | null
78
- planSummary?: string | null
79
- }
80
-
81
- export interface MissionVerificationState {
82
- candidate: boolean
83
- requiredTaskIds?: string[]
84
- requiredChildMissionIds?: string[]
85
- requiredArtifacts?: string[]
86
- evidenceSummary?: string | null
87
- lastVerdict?: MissionVerificationVerdict | null
88
- lastVerifiedAt?: number | null
89
- }
90
-
91
- export interface MissionSummary {
92
- id: string
93
- objective: string
94
- status: MissionStatus
95
- phase: MissionPhase
96
- source: MissionSource
97
- currentStep?: string | null
98
- waitingReason?: string | null
99
- sessionId?: string | null
100
- agentId?: string | null
101
- projectId?: string | null
102
- parentMissionId?: string | null
103
- rootMissionId?: string | null
104
- taskIds?: string[]
105
- openTaskCount?: number
106
- completedTaskCount?: number
107
- childCount?: number
108
- sourceRef?: MissionSourceRef
109
- updatedAt: number
110
- }
111
-
112
- export interface Mission {
113
- id: string
114
- source: MissionSource
115
- sourceRef?: MissionSourceRef
116
- objective: string
117
- successCriteria?: string[]
118
- status: MissionStatus
119
- phase: MissionPhase
120
- sessionId?: string | null
121
- agentId?: string | null
122
- projectId?: string | null
123
- rootMissionId?: string | null
124
- parentMissionId?: string | null
125
- childMissionIds?: string[]
126
- dependencyMissionIds?: string[]
127
- dependencyTaskIds?: string[]
128
- taskIds?: string[]
129
- rootTaskId?: string | null
130
- currentStep?: string | null
131
- plannerSummary?: string | null
132
- verifierSummary?: string | null
133
- blockerSummary?: string | null
134
- waitState?: MissionWaitState | null
135
- controllerState?: MissionControllerState
136
- plannerState?: MissionPlannerState
137
- verificationState?: MissionVerificationState
138
- lastRunId?: string | null
139
- sourceRunId?: string | null
140
- sourceMessage?: string | null
141
- createdAt: number
142
- updatedAt: number
143
- lastActiveAt?: number | null
144
- completedAt?: number | null
145
- failedAt?: number | null
146
- cancelledAt?: number | null
147
- }
148
-
149
- export type MissionEventType =
150
- | 'created'
151
- | 'source_triggered'
152
- | 'attached'
153
- | 'planner_decision'
154
- | 'dispatch_started'
155
- | 'task_linked'
156
- | 'task_started'
157
- | 'task_completed'
158
- | 'task_failed'
159
- | 'child_created'
160
- | 'child_completed'
161
- | 'child_failed'
162
- | 'run_result'
163
- | 'verifier_decision'
164
- | 'waiting'
165
- | 'resumed'
166
- | 'replanned'
167
- | 'completed'
168
- | 'failed'
169
- | 'cancelled'
170
- | 'interrupted'
171
- | 'operator_action'
172
- | 'status_change'
173
-
174
- export interface MissionEvent {
175
- id: string
176
- missionId: string
177
- type: MissionEventType
178
- source: MissionSource | 'system'
179
- summary: string
180
- data?: Record<string, unknown> | null
181
- sessionId?: string | null
182
- taskId?: string | null
183
- runId?: string | null
184
- createdAt: number
185
- }