@bolloon/bolloon-agent 0.3.30 → 0.3.31

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 (217) hide show
  1. package/dist/agents/pi-sdk-tools.js +128 -0
  2. package/dist/constraint-runtime/_archive_helper.d.ts +1 -0
  3. package/dist/constraint-runtime/_archive_helper.js +9 -0
  4. package/dist/constraint-runtime/agent/coordinator.d.ts +19 -0
  5. package/dist/constraint-runtime/agent/coordinator.js +48 -0
  6. package/dist/constraint-runtime/agent/index.d.ts +1 -0
  7. package/dist/constraint-runtime/agent/index.js +1 -0
  8. package/dist/constraint-runtime/assistant/index.d.ts +11 -0
  9. package/dist/constraint-runtime/assistant/index.js +12 -0
  10. package/dist/constraint-runtime/bootstrap/index.d.ts +11 -0
  11. package/dist/constraint-runtime/bootstrap/index.js +12 -0
  12. package/dist/constraint-runtime/bootstrap_graph.d.ts +4 -0
  13. package/dist/constraint-runtime/bootstrap_graph.js +13 -0
  14. package/dist/constraint-runtime/bridge/index.d.ts +11 -0
  15. package/dist/constraint-runtime/bridge/index.js +12 -0
  16. package/dist/constraint-runtime/buddy/index.d.ts +11 -0
  17. package/dist/constraint-runtime/buddy/index.js +12 -0
  18. package/dist/constraint-runtime/cli/index.d.ts +11 -0
  19. package/dist/constraint-runtime/cli/index.js +12 -0
  20. package/dist/constraint-runtime/command_graph.d.ts +7 -0
  21. package/dist/constraint-runtime/command_graph.js +10 -0
  22. package/dist/constraint-runtime/commands.d.ts +15 -0
  23. package/dist/constraint-runtime/commands.js +60 -0
  24. package/dist/constraint-runtime/components/index.d.ts +11 -0
  25. package/dist/constraint-runtime/components/index.js +12 -0
  26. package/dist/constraint-runtime/constants/index.d.ts +11 -0
  27. package/dist/constraint-runtime/constants/index.js +12 -0
  28. package/dist/constraint-runtime/constraint/budget.d.ts +11 -0
  29. package/dist/constraint-runtime/constraint/budget.js +22 -0
  30. package/dist/constraint-runtime/constraint/index.d.ts +3 -0
  31. package/dist/constraint-runtime/constraint/index.js +2 -0
  32. package/dist/constraint-runtime/constraint/permission.d.ts +9 -0
  33. package/dist/constraint-runtime/constraint/permission.js +20 -0
  34. package/dist/constraint-runtime/context.d.ts +12 -0
  35. package/dist/constraint-runtime/context.js +30 -0
  36. package/dist/constraint-runtime/coordinator/index.d.ts +11 -0
  37. package/dist/constraint-runtime/coordinator/index.js +12 -0
  38. package/dist/constraint-runtime/cost_hook.d.ts +2 -0
  39. package/dist/constraint-runtime/cost_hook.js +4 -0
  40. package/dist/constraint-runtime/cost_tracker.d.ts +5 -0
  41. package/dist/constraint-runtime/cost_tracker.js +8 -0
  42. package/dist/constraint-runtime/deferred_init.d.ts +8 -0
  43. package/dist/constraint-runtime/deferred_init.js +10 -0
  44. package/dist/constraint-runtime/direct_modes.d.ts +7 -0
  45. package/dist/constraint-runtime/direct_modes.js +6 -0
  46. package/dist/constraint-runtime/dynamic-tool-loader.d.ts +13 -0
  47. package/dist/constraint-runtime/dynamic-tool-loader.js +85 -0
  48. package/dist/constraint-runtime/entrypoints/index.d.ts +11 -0
  49. package/dist/constraint-runtime/entrypoints/index.js +12 -0
  50. package/dist/constraint-runtime/execution_registry.d.ts +20 -0
  51. package/dist/constraint-runtime/execution_registry.js +44 -0
  52. package/dist/constraint-runtime/history.d.ts +9 -0
  53. package/dist/constraint-runtime/history.js +9 -0
  54. package/dist/constraint-runtime/hooks/index.d.ts +11 -0
  55. package/dist/constraint-runtime/hooks/index.js +12 -0
  56. package/dist/constraint-runtime/index.d.ts +26 -0
  57. package/dist/constraint-runtime/index.js +26 -0
  58. package/dist/constraint-runtime/ink.d.ts +1 -0
  59. package/dist/constraint-runtime/ink.js +4 -0
  60. package/dist/constraint-runtime/keybindings/index.d.ts +11 -0
  61. package/dist/constraint-runtime/keybindings/index.js +12 -0
  62. package/dist/constraint-runtime/memdir/index.d.ts +11 -0
  63. package/dist/constraint-runtime/memdir/index.js +12 -0
  64. package/dist/constraint-runtime/migrations/index.d.ts +11 -0
  65. package/dist/constraint-runtime/migrations/index.js +12 -0
  66. package/dist/constraint-runtime/models.d.ts +42 -0
  67. package/dist/constraint-runtime/models.js +1 -0
  68. package/dist/constraint-runtime/moreright/index.d.ts +11 -0
  69. package/dist/constraint-runtime/moreright/index.js +12 -0
  70. package/dist/constraint-runtime/native_ts/index.d.ts +11 -0
  71. package/dist/constraint-runtime/native_ts/index.js +12 -0
  72. package/dist/constraint-runtime/output_styles/index.d.ts +11 -0
  73. package/dist/constraint-runtime/output_styles/index.js +12 -0
  74. package/dist/constraint-runtime/parity_audit.d.ts +11 -0
  75. package/dist/constraint-runtime/parity_audit.js +12 -0
  76. package/dist/constraint-runtime/plugins/index.d.ts +11 -0
  77. package/dist/constraint-runtime/plugins/index.js +12 -0
  78. package/dist/constraint-runtime/port_manifest.d.ts +7 -0
  79. package/dist/constraint-runtime/port_manifest.js +11 -0
  80. package/dist/constraint-runtime/prefetch.d.ts +8 -0
  81. package/dist/constraint-runtime/prefetch.js +9 -0
  82. package/dist/constraint-runtime/query.d.ts +6 -0
  83. package/dist/constraint-runtime/query.js +1 -0
  84. package/dist/constraint-runtime/reference_data/archive_surface_snapshot.json +63 -0
  85. package/dist/constraint-runtime/reference_data/commands_snapshot.json +1037 -0
  86. package/dist/constraint-runtime/reference_data/subsystems/assistant.json +8 -0
  87. package/dist/constraint-runtime/reference_data/subsystems/bootstrap.json +8 -0
  88. package/dist/constraint-runtime/reference_data/subsystems/bridge.json +32 -0
  89. package/dist/constraint-runtime/reference_data/subsystems/buddy.json +13 -0
  90. package/dist/constraint-runtime/reference_data/subsystems/cli.json +26 -0
  91. package/dist/constraint-runtime/reference_data/subsystems/components.json +32 -0
  92. package/dist/constraint-runtime/reference_data/subsystems/constants.json +28 -0
  93. package/dist/constraint-runtime/reference_data/subsystems/coordinator.json +8 -0
  94. package/dist/constraint-runtime/reference_data/subsystems/entrypoints.json +15 -0
  95. package/dist/constraint-runtime/reference_data/subsystems/hooks.json +32 -0
  96. package/dist/constraint-runtime/reference_data/subsystems/keybindings.json +21 -0
  97. package/dist/constraint-runtime/reference_data/subsystems/memdir.json +15 -0
  98. package/dist/constraint-runtime/reference_data/subsystems/migrations.json +18 -0
  99. package/dist/constraint-runtime/reference_data/subsystems/moreright.json +8 -0
  100. package/dist/constraint-runtime/reference_data/subsystems/native_ts.json +11 -0
  101. package/dist/constraint-runtime/reference_data/subsystems/outputStyles.json +8 -0
  102. package/dist/constraint-runtime/reference_data/subsystems/plugins.json +9 -0
  103. package/dist/constraint-runtime/reference_data/subsystems/remote.json +11 -0
  104. package/dist/constraint-runtime/reference_data/subsystems/schemas.json +8 -0
  105. package/dist/constraint-runtime/reference_data/subsystems/screens.json +10 -0
  106. package/dist/constraint-runtime/reference_data/subsystems/server.json +10 -0
  107. package/dist/constraint-runtime/reference_data/subsystems/services.json +32 -0
  108. package/dist/constraint-runtime/reference_data/subsystems/skills.json +27 -0
  109. package/dist/constraint-runtime/reference_data/subsystems/state.json +13 -0
  110. package/dist/constraint-runtime/reference_data/subsystems/types.json +18 -0
  111. package/dist/constraint-runtime/reference_data/subsystems/upstreamproxy.json +9 -0
  112. package/dist/constraint-runtime/reference_data/subsystems/utils.json +32 -0
  113. package/dist/constraint-runtime/reference_data/subsystems/vim.json +12 -0
  114. package/dist/constraint-runtime/reference_data/subsystems/voice.json +8 -0
  115. package/dist/constraint-runtime/reference_data/tools_snapshot.json +922 -0
  116. package/dist/constraint-runtime/remote/index.d.ts +11 -0
  117. package/dist/constraint-runtime/remote/index.js +12 -0
  118. package/dist/constraint-runtime/remote_runtime.d.ts +8 -0
  119. package/dist/constraint-runtime/remote_runtime.js +9 -0
  120. package/dist/constraint-runtime/runtime/index.d.ts +1 -0
  121. package/dist/constraint-runtime/runtime/index.js +1 -0
  122. package/dist/constraint-runtime/runtime/session.d.ts +22 -0
  123. package/dist/constraint-runtime/runtime/session.js +35 -0
  124. package/dist/constraint-runtime/schemas/index.d.ts +11 -0
  125. package/dist/constraint-runtime/schemas/index.js +12 -0
  126. package/dist/constraint-runtime/screens/index.d.ts +11 -0
  127. package/dist/constraint-runtime/screens/index.js +12 -0
  128. package/dist/constraint-runtime/server/index.d.ts +11 -0
  129. package/dist/constraint-runtime/server/index.js +12 -0
  130. package/dist/constraint-runtime/services/index.d.ts +11 -0
  131. package/dist/constraint-runtime/services/index.js +12 -0
  132. package/dist/constraint-runtime/session_store.d.ts +8 -0
  133. package/dist/constraint-runtime/session_store.js +22 -0
  134. package/dist/constraint-runtime/setup.d.ts +19 -0
  135. package/dist/constraint-runtime/setup.js +30 -0
  136. package/dist/constraint-runtime/skills/index.d.ts +1 -0
  137. package/dist/constraint-runtime/skills/index.js +1 -0
  138. package/dist/constraint-runtime/skills/skill-registry.d.ts +14 -0
  139. package/dist/constraint-runtime/skills/skill-registry.js +28 -0
  140. package/dist/constraint-runtime/state/index.d.ts +11 -0
  141. package/dist/constraint-runtime/state/index.js +12 -0
  142. package/dist/constraint-runtime/system_init.d.ts +1 -0
  143. package/dist/constraint-runtime/system_init.js +20 -0
  144. package/dist/constraint-runtime/thinking/engine.d.ts +20 -0
  145. package/dist/constraint-runtime/thinking/engine.js +42 -0
  146. package/dist/constraint-runtime/thinking/index.d.ts +1 -0
  147. package/dist/constraint-runtime/thinking/index.js +1 -0
  148. package/dist/constraint-runtime/tool_pool.d.ts +8 -0
  149. package/dist/constraint-runtime/tool_pool.js +8 -0
  150. package/dist/constraint-runtime/tools/OpenCLI/execAdapter.d.ts +9 -0
  151. package/dist/constraint-runtime/tools/OpenCLI/execAdapter.js +7 -0
  152. package/dist/constraint-runtime/tools/OpenCLI/listAdapters.d.ts +5 -0
  153. package/dist/constraint-runtime/tools/OpenCLI/listAdapters.js +7 -0
  154. package/dist/constraint-runtime/tools/OpenCLI/runCommand.d.ts +10 -0
  155. package/dist/constraint-runtime/tools/OpenCLI/runCommand.js +7 -0
  156. package/dist/constraint-runtime/tools/PolymarketSDK/cancelOrder.d.ts +17 -0
  157. package/dist/constraint-runtime/{src/tools → tools}/PolymarketSDK/cancelOrder.js +4 -7
  158. package/dist/constraint-runtime/tools/PolymarketSDK/clobShared.d.ts +50 -0
  159. package/dist/constraint-runtime/tools/PolymarketSDK/clobShared.js +78 -0
  160. package/dist/constraint-runtime/tools/PolymarketSDK/createOrder.d.ts +31 -0
  161. package/dist/constraint-runtime/{src/tools → tools}/PolymarketSDK/createOrder.js +9 -12
  162. package/dist/constraint-runtime/tools/PolymarketSDK/getMarket.d.ts +10 -0
  163. package/dist/constraint-runtime/tools/PolymarketSDK/getMarket.js +16 -0
  164. package/dist/constraint-runtime/tools/PolymarketSDK/getOrders.d.ts +16 -0
  165. package/dist/constraint-runtime/tools/PolymarketSDK/getOrders.js +25 -0
  166. package/dist/constraint-runtime/tools/PolymarketSDK/listMarkets.d.ts +23 -0
  167. package/dist/constraint-runtime/tools/PolymarketSDK/listMarkets.js +24 -0
  168. package/dist/constraint-runtime/tools/SafeSDK/confirmTransaction.d.ts +10 -0
  169. package/dist/constraint-runtime/tools/SafeSDK/confirmTransaction.js +6 -0
  170. package/dist/constraint-runtime/tools/SafeSDK/createTransaction.d.ts +14 -0
  171. package/dist/constraint-runtime/tools/SafeSDK/createTransaction.js +8 -0
  172. package/dist/constraint-runtime/tools/SafeSDK/deploySafe.d.ts +10 -0
  173. package/dist/constraint-runtime/tools/SafeSDK/executeTransaction.d.ts +9 -0
  174. package/dist/constraint-runtime/tools/SafeSDK/executeTransaction.js +6 -0
  175. package/dist/constraint-runtime/tools/SafeSDK/getBalance.d.ts +7 -0
  176. package/dist/constraint-runtime/tools/SafeSDK/getBalance.js +6 -0
  177. package/dist/constraint-runtime/tools/SafeSDK/getPendingTransactions.d.ts +7 -0
  178. package/dist/constraint-runtime/tools/SafeSDK/getPendingTransactions.js +6 -0
  179. package/dist/constraint-runtime/tools/SafeSDK/proposeTransaction.d.ts +11 -0
  180. package/dist/constraint-runtime/tools/SafeSDK/proposeTransaction.js +6 -0
  181. package/dist/constraint-runtime/tools/WalletTools/autoPay.d.ts +26 -0
  182. package/dist/constraint-runtime/tools/WalletTools/createWallet.d.ts +7 -0
  183. package/dist/constraint-runtime/tools/WalletTools/getBalance.d.ts +11 -0
  184. package/dist/constraint-runtime/tools/WalletTools/importWallet.d.ts +10 -0
  185. package/dist/constraint-runtime/tools/WalletTools/sendTransaction.d.ts +20 -0
  186. package/dist/constraint-runtime/tools/WalletTools/signMessage.d.ts +10 -0
  187. package/dist/constraint-runtime/tools/WalletTools/transferToken.d.ts +17 -0
  188. package/dist/constraint-runtime/tools.d.ts +14 -0
  189. package/dist/constraint-runtime/tools.js +80 -0
  190. package/dist/constraint-runtime/transcript.d.ts +8 -0
  191. package/dist/constraint-runtime/transcript.js +19 -0
  192. package/dist/constraint-runtime/types/index.d.ts +11 -0
  193. package/dist/constraint-runtime/types/index.js +12 -0
  194. package/dist/constraint-runtime/upstream_proxy/index.d.ts +11 -0
  195. package/dist/constraint-runtime/upstream_proxy/index.js +12 -0
  196. package/dist/constraint-runtime/utils/index.d.ts +11 -0
  197. package/dist/constraint-runtime/utils/index.js +12 -0
  198. package/dist/constraint-runtime/vim/index.d.ts +11 -0
  199. package/dist/constraint-runtime/vim/index.js +12 -0
  200. package/dist/constraint-runtime/voice/index.d.ts +11 -0
  201. package/dist/constraint-runtime/voice/index.js +12 -0
  202. package/dist/llm/config-store.js +39 -28
  203. package/dist/llm/pi-ai.js +64 -36
  204. package/dist/security/tool-gate.js +2 -0
  205. package/package.json +3 -2
  206. package/dist/constraint-runtime/src/tools/PolymarketSDK/clobShared.js +0 -104
  207. package/dist/constraint-runtime/src/tools/PolymarketSDK/getMarket.js +0 -5
  208. package/dist/constraint-runtime/src/tools/PolymarketSDK/getOrders.js +0 -19
  209. package/dist/constraint-runtime/src/tools/PolymarketSDK/listMarkets.js +0 -4
  210. /package/dist/constraint-runtime/{src/tools → tools}/SafeSDK/deploySafe.js +0 -0
  211. /package/dist/constraint-runtime/{src/tools → tools}/WalletTools/autoPay.js +0 -0
  212. /package/dist/constraint-runtime/{src/tools → tools}/WalletTools/createWallet.js +0 -0
  213. /package/dist/constraint-runtime/{src/tools → tools}/WalletTools/getBalance.js +0 -0
  214. /package/dist/constraint-runtime/{src/tools → tools}/WalletTools/importWallet.js +0 -0
  215. /package/dist/constraint-runtime/{src/tools → tools}/WalletTools/sendTransaction.js +0 -0
  216. /package/dist/constraint-runtime/{src/tools → tools}/WalletTools/signMessage.js +0 -0
  217. /package/dist/constraint-runtime/{src/tools → tools}/WalletTools/transferToken.js +0 -0
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Polymarket 下单/查单/撤单 共享依赖
3
+ *
4
+ * 2026-08-04: 迁移到官方统一 SDK @polymarket/client (替代已弃用的 @polymarket/clob-client + polymarket-sdk)
5
+ * - 公开数据: createPublicClient() → listMarkets / fetchMarket / fetchOrderBook
6
+ * - 交易: createSecureClient({ signer: privateKey(pk) }) → placeLimitOrder / cancelOrder / listOpenOrders
7
+ * - 签名走 SDK 内部 (EIP-712), 无需手动派生 API key
8
+ *
9
+ * chainId = 137 (Polygon), host = https://clob.polymarket.com
10
+ */
11
+ import { createSecureClient, OrderSide } from '@polymarket/client';
12
+ import { privateKey } from '@polymarket/client/viem';
13
+ import { privateKeyToAccount } from 'viem/accounts';
14
+ export const CLOB_HOST = 'https://clob.polymarket.com';
15
+ export const CHAIN_ID = 137;
16
+ export function normalizePrivateKey(pk) {
17
+ const s = pk.startsWith('0x') ? pk : `0x${pk}`;
18
+ return s;
19
+ }
20
+ function safeParseArray(v) {
21
+ if (Array.isArray(v))
22
+ return v;
23
+ if (typeof v === 'string') {
24
+ try {
25
+ const parsed = JSON.parse(v);
26
+ return Array.isArray(parsed) ? parsed : [];
27
+ }
28
+ catch {
29
+ return [];
30
+ }
31
+ }
32
+ return [];
33
+ }
34
+ /**
35
+ * 从 Gamma 取市场元数据: clobTokenIds / outcomes / tickSize / negRisk.
36
+ */
37
+ export async function fetchMarketMeta(marketId) {
38
+ const res = await fetch(`https://gamma-api.polymarket.com/markets/${encodeURIComponent(marketId)}`);
39
+ if (res.ok) {
40
+ const m = await res.json();
41
+ return {
42
+ clobTokenIds: safeParseArray(m.clobTokenIds),
43
+ outcomes: safeParseArray(m.outcomes),
44
+ tickSize: typeof m.tickSize === 'string' ? m.tickSize : '0.01',
45
+ negRisk: !!m.negRisk,
46
+ };
47
+ }
48
+ throw new Error(`Gamma 市场元数据获取失败 (HTTP ${res.status}): ${marketId}`);
49
+ }
50
+ /**
51
+ * 由 outcome (如 "Yes"/"No" 或索引 0/1) 或显式 tokenId 解析出要交易的 tokenID.
52
+ * 都不给 → 默认取第一个 clobTokenId (通常是 "Yes").
53
+ */
54
+ export function resolveTokenId(meta, tokenId, outcome) {
55
+ if (tokenId)
56
+ return tokenId;
57
+ if (!meta.clobTokenIds || meta.clobTokenIds.length === 0)
58
+ return undefined;
59
+ if (outcome === undefined || outcome === null)
60
+ return meta.clobTokenIds[0];
61
+ if (typeof outcome === 'number')
62
+ return meta.clobTokenIds[outcome];
63
+ const idx = meta.outcomes.findIndex((o) => String(o).toLowerCase() === String(outcome).toLowerCase());
64
+ return idx >= 0 ? meta.clobTokenIds[idx] : undefined;
65
+ }
66
+ /**
67
+ * 构造已鉴权的 SecureClient (@polymarket/client 统一 SDK).
68
+ * 签名/鉴权全在 SDK 内部处理, creds (旧式 API key) 参数保留兼容但不再需要.
69
+ */
70
+ export async function buildSecureClient(params) {
71
+ const pk = normalizePrivateKey(params.privateKey);
72
+ const account = privateKeyToAccount(pk);
73
+ const client = await createSecureClient({ signer: privateKey(pk) });
74
+ return { client, address: account.address };
75
+ }
76
+ /** 兼容旧名 (老调用方) */
77
+ export const buildClobClient = buildSecureClient;
78
+ export { OrderSide };
@@ -0,0 +1,31 @@
1
+ export interface CreateOrderParams {
2
+ /** 下单钱包私钥 (0x...), 用于 EIP-712 订单签名 */
3
+ privateKey: string;
4
+ /** 市场 ID (condition id) */
5
+ marketId: string;
6
+ side: 'BUY' | 'SELL';
7
+ /** 限价 0-1, 需符合市场 tickSize */
8
+ price: number;
9
+ /** 数量 (买单=花费 pUSD 份额, 卖单=卖出份额) */
10
+ size: number;
11
+ /** 显式 tokenID (优先于 outcome) */
12
+ tokenId?: string;
13
+ /** outcome: "Yes"/"No" 或索引 0/1, 默认取第一个 (通常是 Yes) */
14
+ outcome?: string | number;
15
+ /** 已存在的 API key (兼容保留, 新 SDK 不需要) */
16
+ apiKey?: string;
17
+ apiSecret?: string;
18
+ apiPassphrase?: string;
19
+ /** 资金地址 (默认 = 私钥地址) */
20
+ funder?: string;
21
+ orderType?: 'GTC' | 'GTD';
22
+ }
23
+ export interface CreateOrderResult {
24
+ success: boolean;
25
+ message?: string;
26
+ orderId?: string;
27
+ status?: string;
28
+ raw?: any;
29
+ }
30
+ /** 限价单下单 (@polymarket/client 统一 SDK placeLimitOrder, 2026-08-04 迁移). */
31
+ export declare function createOrder(params: CreateOrderParams): Promise<CreateOrderResult>;
@@ -1,4 +1,5 @@
1
- import { buildClobClient, fetchMarketMeta, resolveTokenId } from './clobShared.js';
1
+ import { OrderSide, buildSecureClient, fetchMarketMeta, resolveTokenId } from './clobShared.js';
2
+ /** 限价单下单 (@polymarket/client 统一 SDK placeLimitOrder, 2026-08-04 迁移). */
2
3
  export async function createOrder(params) {
3
4
  if (!params.privateKey) {
4
5
  return { success: false, message: '下单需要提供钱包私钥 privateKey (用于 EIP-712 订单签名)' };
@@ -12,21 +13,17 @@ export async function createOrder(params) {
12
13
  if (!tokenID) {
13
14
  return { success: false, message: '无法解析 tokenID (outcome 不匹配或市场无 clobTokenIds)' };
14
15
  }
15
- const { client } = await buildClobClient({
16
- privateKey: params.privateKey,
17
- creds: { apiKey: params.apiKey, apiSecret: params.apiSecret, apiPassphrase: params.apiPassphrase },
18
- funder: params.funder,
19
- });
20
- const resp = await client.createAndPostOrder({
21
- tokenID,
16
+ const { client } = await buildSecureClient({ privateKey: params.privateKey, funder: params.funder });
17
+ const resp = await client.placeLimitOrder({
18
+ tokenId: tokenID,
22
19
  price: Number(params.price),
23
20
  size: Number(params.size),
24
- side: params.side,
25
- }, { tickSize: meta.tickSize, negRisk: meta.negRisk }, (params.orderType ?? 'GTC'));
21
+ side: params.side === 'SELL' ? OrderSide.SELL : OrderSide.BUY,
22
+ });
26
23
  return {
27
24
  success: true,
28
- orderId: resp?.orderID ?? resp?.id,
29
- status: resp?.status,
25
+ orderId: resp?.orderId ?? resp?.id,
26
+ status: resp?.status ?? resp?.orderStatus,
30
27
  raw: resp,
31
28
  };
32
29
  }
@@ -0,0 +1,10 @@
1
+ export interface Market {
2
+ id: string;
3
+ question: string;
4
+ slug: string;
5
+ volume: string;
6
+ active: boolean;
7
+ closed: boolean;
8
+ }
9
+ /** 按市场 id 查询单个市场 (@polymarket/client 统一 SDK, 2026-08-04 迁移). */
10
+ export declare function getMarket(id: string): Promise<Market | null>;
@@ -0,0 +1,16 @@
1
+ import { createPublicClient } from '@polymarket/client';
2
+ /** 按市场 id 查询单个市场 (@polymarket/client 统一 SDK, 2026-08-04 迁移). */
3
+ export async function getMarket(id) {
4
+ const client = createPublicClient();
5
+ const m = await client.fetchMarket({ id });
6
+ if (!m)
7
+ return null;
8
+ return {
9
+ id: m.id,
10
+ question: m.question,
11
+ slug: m.slug,
12
+ volume: m.volume ?? '',
13
+ active: !m.closed,
14
+ closed: m.closed,
15
+ };
16
+ }
@@ -0,0 +1,16 @@
1
+ export interface GetOrdersParams {
2
+ /** 查询订单的钱包私钥 */
3
+ privateKey?: string;
4
+ /** 按市场 ID 过滤 (可选) */
5
+ marketId?: string;
6
+ apiKey?: string;
7
+ apiSecret?: string;
8
+ apiPassphrase?: string;
9
+ funder?: string;
10
+ }
11
+ export interface GetOrdersResult {
12
+ orders: any[];
13
+ message: string;
14
+ }
15
+ /** 查未成交订单 (@polymarket/client 统一 SDK listOpenOrders, 2026-08-04 迁移). */
16
+ export declare function getOrders(params?: GetOrdersParams): Promise<GetOrdersResult>;
@@ -0,0 +1,25 @@
1
+ import { buildSecureClient } from './clobShared.js';
2
+ /** 查未成交订单 (@polymarket/client 统一 SDK listOpenOrders, 2026-08-04 迁移). */
3
+ export async function getOrders(params = {}) {
4
+ if (!params.privateKey) {
5
+ return { orders: [], message: '查询订单需要提供钱包私钥 privateKey' };
6
+ }
7
+ try {
8
+ const { client } = await buildSecureClient({ privateKey: params.privateKey, funder: params.funder });
9
+ const pages = client.listOpenOrders(params.marketId ? { marketId: params.marketId } : {});
10
+ const page = await pages.firstPage();
11
+ const orders = (page.items || []).map((o) => ({
12
+ id: o.orderId ?? o.id,
13
+ status: o.status,
14
+ side: o.side,
15
+ price: o.price,
16
+ size: o.size,
17
+ marketId: o.marketId,
18
+ raw: o,
19
+ }));
20
+ return { orders, message: 'OK' };
21
+ }
22
+ catch (e) {
23
+ return { orders: [], message: `查询失败: ${e?.message || e}` };
24
+ }
25
+ }
@@ -0,0 +1,23 @@
1
+ export interface ListMarketsParams {
2
+ limit?: number;
3
+ offset?: number;
4
+ order?: string;
5
+ ascending?: boolean;
6
+ closed?: boolean;
7
+ }
8
+ export interface Market {
9
+ id: string;
10
+ question: string;
11
+ conditionId: string;
12
+ slug: string;
13
+ volume: string;
14
+ active: boolean;
15
+ closed: boolean;
16
+ outcomes: string;
17
+ outcomePrices: string;
18
+ }
19
+ /**
20
+ * 查询市场列表 (@polymarket/client 统一 SDK, 2026-08-04 迁移).
21
+ * 返回结构与旧 polymarket-sdk 对齐 (id/question/conditionId/slug/volume/active/closed/outcomes/outcomePrices).
22
+ */
23
+ export declare function listMarkets(params?: ListMarketsParams): Promise<Market[]>;
@@ -0,0 +1,24 @@
1
+ import { createPublicClient } from '@polymarket/client';
2
+ /**
3
+ * 查询市场列表 (@polymarket/client 统一 SDK, 2026-08-04 迁移).
4
+ * 返回结构与旧 polymarket-sdk 对齐 (id/question/conditionId/slug/volume/active/closed/outcomes/outcomePrices).
5
+ */
6
+ export async function listMarkets(params = {}) {
7
+ const client = createPublicClient();
8
+ const pages = client.listMarkets({
9
+ closed: params.closed ?? false,
10
+ pageSize: params.limit ?? 20,
11
+ });
12
+ const page = await pages.firstPage();
13
+ return (page.items || []).map((m) => ({
14
+ id: m.id,
15
+ question: m.question,
16
+ conditionId: m.conditionId ?? m.clobTokenIds?.[0] ?? '',
17
+ slug: m.slug,
18
+ volume: m.volume ?? '',
19
+ active: !m.closed,
20
+ closed: m.closed,
21
+ outcomes: Array.isArray(m.outcomes) ? m.outcomes.map((o) => o?.name ?? o).join(',') : String(m.outcomes ?? ''),
22
+ outcomePrices: Array.isArray(m.outcomePrices) ? m.outcomePrices.join(',') : String(m.outcomePrices ?? ''),
23
+ }));
24
+ }
@@ -0,0 +1,10 @@
1
+ export interface ConfirmTransactionParams {
2
+ safeAddress: string;
3
+ safeTxHash: string;
4
+ signerAddress: string;
5
+ signature?: string;
6
+ }
7
+ export declare function confirmTransaction(params: ConfirmTransactionParams): Promise<{
8
+ success: boolean;
9
+ message: string;
10
+ }>;
@@ -0,0 +1,6 @@
1
+ export async function confirmTransaction(params) {
2
+ return {
3
+ success: false,
4
+ message: 'Safe transaction confirmation requires protocol kit with signer configured.',
5
+ };
6
+ }
@@ -0,0 +1,14 @@
1
+ export interface CreateTransactionParams {
2
+ safeAddress: string;
3
+ to: string;
4
+ value: string;
5
+ data: string;
6
+ operation?: number;
7
+ }
8
+ export interface SafeTransaction {
9
+ to: string;
10
+ value: string;
11
+ data: string;
12
+ operation: number;
13
+ }
14
+ export declare function createTransaction(params: CreateTransactionParams): Promise<SafeTransaction>;
@@ -0,0 +1,8 @@
1
+ export async function createTransaction(params) {
2
+ return {
3
+ to: params.to,
4
+ value: params.value,
5
+ data: params.data,
6
+ operation: params.operation ?? 0,
7
+ };
8
+ }
@@ -0,0 +1,10 @@
1
+ export interface DeploySafeParams {
2
+ owners: string[];
3
+ threshold: number;
4
+ saltNonce?: number;
5
+ }
6
+ export declare function deploySafe(params: DeploySafeParams): Promise<{
7
+ success: boolean;
8
+ message: string;
9
+ safeAddress?: string;
10
+ }>;
@@ -0,0 +1,9 @@
1
+ export interface ExecuteTransactionParams {
2
+ safeAddress: string;
3
+ safeTransaction: any;
4
+ signerAddress: string;
5
+ }
6
+ export declare function executeTransaction(params: ExecuteTransactionParams): Promise<{
7
+ success: boolean;
8
+ message: string;
9
+ }>;
@@ -0,0 +1,6 @@
1
+ export async function executeTransaction(params) {
2
+ return {
3
+ success: false,
4
+ message: 'Safe transaction execution requires protocol kit with executor and signer configured.',
5
+ };
6
+ }
@@ -0,0 +1,7 @@
1
+ export interface GetBalanceParams {
2
+ safeAddress: string;
3
+ }
4
+ export declare function getBalance(params: GetBalanceParams): Promise<{
5
+ balance: string;
6
+ message: string;
7
+ }>;
@@ -0,0 +1,6 @@
1
+ export async function getBalance(params) {
2
+ return {
3
+ balance: '0',
4
+ message: 'Balance retrieval requires protocol kit with RPC provider configured.',
5
+ };
6
+ }
@@ -0,0 +1,7 @@
1
+ export interface GetPendingTransactionsParams {
2
+ safeAddress: string;
3
+ }
4
+ export declare function getPendingTransactions(params: GetPendingTransactionsParams): Promise<{
5
+ transactions: any[];
6
+ message: string;
7
+ }>;
@@ -0,0 +1,6 @@
1
+ export async function getPendingTransactions(params) {
2
+ return {
3
+ transactions: [],
4
+ message: 'Pending transaction retrieval requires Safe API Kit with transaction service URL configured.',
5
+ };
6
+ }
@@ -0,0 +1,11 @@
1
+ export interface ProposeTransactionParams {
2
+ safeAddress: string;
3
+ safeTransaction: any;
4
+ safeTxHash: string;
5
+ signerAddress: string;
6
+ origin?: string;
7
+ }
8
+ export declare function proposeSafeTransaction(params: ProposeTransactionParams): Promise<{
9
+ success: boolean;
10
+ message: string;
11
+ }>;
@@ -0,0 +1,6 @@
1
+ export async function proposeSafeTransaction(params) {
2
+ return {
3
+ success: false,
4
+ message: 'Safe transaction proposal requires Safe API Kit with transaction service URL configured.',
5
+ };
6
+ }
@@ -0,0 +1,26 @@
1
+ export interface AutoPayConfig {
2
+ enabled: boolean;
3
+ walletPrivateKey: string;
4
+ rpcUrl: string;
5
+ maxGasPrice?: string;
6
+ whitelist?: string[];
7
+ }
8
+ export interface SetAutoPayParams {
9
+ agentId: string;
10
+ walletPrivateKey: string;
11
+ rpcUrl?: string;
12
+ maxGasPrice?: string;
13
+ whitelist?: string[];
14
+ }
15
+ export interface AutoPayResult {
16
+ agentId: string;
17
+ enabled: boolean;
18
+ walletAddress: string;
19
+ rpcUrl: string;
20
+ }
21
+ export declare function setAutoPay(params: SetAutoPayParams): Promise<AutoPayResult>;
22
+ export declare function getAutoPayConfig(agentId: string): Promise<AutoPayConfig | null>;
23
+ export declare function disableAutoPay(agentId: string): Promise<{
24
+ agentId: string;
25
+ enabled: boolean;
26
+ }>;
@@ -0,0 +1,7 @@
1
+ export interface CreateWalletResult {
2
+ address: string;
3
+ privateKey: string;
4
+ mnemonic: string;
5
+ createdAt: string;
6
+ }
7
+ export declare function createWallet(): Promise<CreateWalletResult>;
@@ -0,0 +1,11 @@
1
+ export interface GetBalanceParams {
2
+ address: string;
3
+ rpcUrl?: string;
4
+ }
5
+ export interface GetBalanceResult {
6
+ address: string;
7
+ balance: string;
8
+ balanceEth: string;
9
+ symbol: string;
10
+ }
11
+ export declare function getBalance(params: GetBalanceParams): Promise<GetBalanceResult>;
@@ -0,0 +1,10 @@
1
+ export interface ImportWalletParams {
2
+ mnemonic?: string;
3
+ privateKey?: string;
4
+ }
5
+ export interface ImportWalletResult {
6
+ address: string;
7
+ privateKey: string;
8
+ source: 'mnemonic' | 'privateKey';
9
+ }
10
+ export declare function importWallet(params: ImportWalletParams): Promise<ImportWalletResult>;
@@ -0,0 +1,20 @@
1
+ export interface SendTransactionParams {
2
+ to: string;
3
+ value: string;
4
+ data?: string;
5
+ gasLimit?: string;
6
+ maxFeePerGas?: string;
7
+ maxPriorityFeePerGas?: string;
8
+ rpcUrl?: string;
9
+ privateKey: string;
10
+ }
11
+ export interface SendTransactionResult {
12
+ hash: string;
13
+ from: string;
14
+ to: string;
15
+ value: string;
16
+ status: 'pending' | 'success' | 'failed';
17
+ blockNumber?: number;
18
+ gasUsed?: string;
19
+ }
20
+ export declare function sendTransaction(params: SendTransactionParams): Promise<SendTransactionResult>;
@@ -0,0 +1,10 @@
1
+ export interface SignMessageParams {
2
+ message: string;
3
+ privateKey: string;
4
+ }
5
+ export interface SignMessageResult {
6
+ address: string;
7
+ message: string;
8
+ signature: string;
9
+ }
10
+ export declare function signMessage(params: SignMessageParams): Promise<SignMessageResult>;
@@ -0,0 +1,17 @@
1
+ export interface TransferTokenParams {
2
+ tokenAddress: string;
3
+ to: string;
4
+ amount: string;
5
+ rpcUrl?: string;
6
+ privateKey: string;
7
+ decimals?: number;
8
+ }
9
+ export interface TransferTokenResult {
10
+ hash: string;
11
+ from: string;
12
+ to: string;
13
+ tokenAddress: string;
14
+ amount: string;
15
+ status: 'pending' | 'success' | 'failed';
16
+ }
17
+ export declare function transferToken(params: TransferTokenParams): Promise<TransferTokenResult>;
@@ -0,0 +1,14 @@
1
+ import { PortingModule } from './models.js';
2
+ export interface ToolExecution {
3
+ name: string;
4
+ sourceHint: string;
5
+ payload: string;
6
+ handled: boolean;
7
+ message: string;
8
+ }
9
+ export declare const PORTED_TOOLS: PortingModule[];
10
+ export { PortingModule };
11
+ export declare function getTool(name: string): PortingModule | undefined;
12
+ export declare function getTools(simpleMode?: boolean): PortingModule[];
13
+ export declare function findTools(query: string, limit?: number): PortingModule[];
14
+ export declare function executeTool(name: string, payload?: string): Promise<ToolExecution>;
@@ -0,0 +1,80 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import { fileURLToPath } from 'url';
4
+ import { executeToolFromSnapshot } from './dynamic-tool-loader.js';
5
+ const __filename = fileURLToPath(import.meta.url);
6
+ const __dirname = path.dirname(__filename);
7
+ const SNAPSHOT_PATH = path.join(__dirname, 'reference_data', 'tools_snapshot.json');
8
+ function loadToolSnapshot() {
9
+ try {
10
+ if (!fs.existsSync(SNAPSHOT_PATH)) {
11
+ console.warn(`[tools] Snapshot not found: ${SNAPSHOT_PATH}, using empty list`);
12
+ return [];
13
+ }
14
+ const raw = JSON.parse(fs.readFileSync(SNAPSHOT_PATH, 'utf-8'));
15
+ return raw.map((e) => ({
16
+ name: e.name,
17
+ responsibility: e.responsibility,
18
+ sourceHint: e.source_hint,
19
+ status: 'mirrored',
20
+ }));
21
+ }
22
+ catch (error) {
23
+ console.warn(`[tools] Failed to load snapshot: ${error}, using empty list`);
24
+ return [];
25
+ }
26
+ }
27
+ export const PORTED_TOOLS = loadToolSnapshot();
28
+ export function getTool(name) {
29
+ const needle = name.toLowerCase();
30
+ return PORTED_TOOLS.find(m => m.name.toLowerCase() === needle);
31
+ }
32
+ export function getTools(simpleMode = false) {
33
+ let tools = [...PORTED_TOOLS];
34
+ if (simpleMode) {
35
+ tools = tools.filter(m => ['BashTool', 'FileReadTool', 'FileEditTool'].includes(m.name));
36
+ }
37
+ return tools;
38
+ }
39
+ export function findTools(query, limit = 20) {
40
+ const needle = query.toLowerCase();
41
+ return PORTED_TOOLS.filter(m => m.name.toLowerCase().includes(needle) || m.sourceHint.toLowerCase().includes(needle)).slice(0, limit);
42
+ }
43
+ export async function executeTool(name, payload = '') {
44
+ const module = getTool(name);
45
+ if (!module) {
46
+ return { name, sourceHint: '', payload, handled: false, message: `Unknown mirrored tool: ${name}` };
47
+ }
48
+ let params = {};
49
+ try {
50
+ params = payload ? JSON.parse(payload) : {};
51
+ }
52
+ catch {
53
+ return {
54
+ name: module.name,
55
+ sourceHint: module.sourceHint,
56
+ payload,
57
+ handled: false,
58
+ message: `Invalid JSON payload for tool '${module.name}'`,
59
+ };
60
+ }
61
+ const result = await executeToolFromSnapshot(module.sourceHint, params);
62
+ if (result.success) {
63
+ return {
64
+ name: module.name,
65
+ sourceHint: module.sourceHint,
66
+ payload: JSON.stringify(result.data),
67
+ handled: true,
68
+ message: `Tool '${module.name}' executed successfully`,
69
+ };
70
+ }
71
+ else {
72
+ return {
73
+ name: module.name,
74
+ sourceHint: module.sourceHint,
75
+ payload,
76
+ handled: false,
77
+ message: `Tool '${module.name}' failed: ${result.error}`,
78
+ };
79
+ }
80
+ }
@@ -0,0 +1,8 @@
1
+ export declare class TranscriptStore {
2
+ entries: string[];
3
+ flushed: boolean;
4
+ append(entry: string): void;
5
+ compact(keepLast?: number): void;
6
+ replay(): string[];
7
+ flush(): void;
8
+ }
@@ -0,0 +1,19 @@
1
+ export class TranscriptStore {
2
+ entries = [];
3
+ flushed = false;
4
+ append(entry) {
5
+ this.entries.push(entry);
6
+ this.flushed = false;
7
+ }
8
+ compact(keepLast = 10) {
9
+ if (this.entries.length > keepLast) {
10
+ this.entries = this.entries.slice(-keepLast);
11
+ }
12
+ }
13
+ replay() {
14
+ return [...this.entries];
15
+ }
16
+ flush() {
17
+ this.flushed = true;
18
+ }
19
+ }
@@ -0,0 +1,11 @@
1
+ export declare const ARCHIVE_NAME: string;
2
+ export declare const MODULE_COUNT: number;
3
+ export declare const SAMPLE_FILES: string[];
4
+ export declare const PORTING_NOTE: string;
5
+ declare const _default: {
6
+ ARCHIVE_NAME: string;
7
+ MODULE_COUNT: number;
8
+ PORTING_NOTE: string;
9
+ SAMPLE_FILES: string[];
10
+ };
11
+ export default _default;
@@ -0,0 +1,12 @@
1
+ import { loadArchiveMetadata } from '../_archive_helper.js';
2
+ const SNAPSHOT = loadArchiveMetadata('types');
3
+ export const ARCHIVE_NAME = SNAPSHOT['archive_name'];
4
+ export const MODULE_COUNT = SNAPSHOT['module_count'];
5
+ export const SAMPLE_FILES = SNAPSHOT['sample_files'];
6
+ export const PORTING_NOTE = `Python placeholder package for '${ARCHIVE_NAME}' with ${MODULE_COUNT} archived module references.`;
7
+ export default {
8
+ ARCHIVE_NAME,
9
+ MODULE_COUNT,
10
+ PORTING_NOTE,
11
+ SAMPLE_FILES,
12
+ };