@senpi/runtime 3.0.186 → 3.0.190
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/llm-decision/openclaw-llm-decision.d.ts +1 -1
- package/dist/actions/llm-decision/openclaw-llm-decision.js +1 -1
- package/dist/approvals/telemetry.d.ts +3 -2
- package/dist/approvals/telemetry.d.ts.map +1 -1
- package/dist/approvals/telemetry.js.map +1 -1
- package/dist/approvals/tool-approval-gate.d.ts +9 -3
- package/dist/approvals/tool-approval-gate.d.ts.map +1 -1
- package/dist/approvals/tool-approval-gate.js +18 -5
- package/dist/approvals/tool-approval-gate.js.map +1 -1
- package/dist/approvals/turn-context.d.ts +43 -18
- package/dist/approvals/turn-context.d.ts.map +1 -1
- package/dist/approvals/turn-context.js +67 -24
- package/dist/approvals/turn-context.js.map +1 -1
- package/dist/cli/guide-commands.d.ts.map +1 -1
- package/dist/cli/guide-commands.js +8 -1
- package/dist/cli/guide-commands.js.map +1 -1
- package/dist/cli/senpi-commands.d.ts.map +1 -1
- package/dist/cli/senpi-commands.js +12 -2
- package/dist/cli/senpi-commands.js.map +1 -1
- package/dist/deploy/box-cap.d.ts +7 -0
- package/dist/deploy/box-cap.d.ts.map +1 -0
- package/dist/deploy/box-cap.js +13 -0
- package/dist/deploy/box-cap.js.map +1 -0
- package/dist/deploy/funding.d.ts +13 -1
- package/dist/deploy/funding.d.ts.map +1 -1
- package/dist/deploy/funding.js +13 -4
- package/dist/deploy/funding.js.map +1 -1
- package/dist/deploy/job.d.ts +2 -0
- package/dist/deploy/job.d.ts.map +1 -1
- package/dist/deploy/job.js +2 -2
- package/dist/deploy/job.js.map +1 -1
- package/dist/deploy/messages.d.ts +14 -0
- package/dist/deploy/messages.d.ts.map +1 -1
- package/dist/deploy/messages.js +59 -25
- package/dist/deploy/messages.js.map +1 -1
- package/dist/deploy/orchestrator.d.ts +23 -1
- package/dist/deploy/orchestrator.d.ts.map +1 -1
- package/dist/deploy/orchestrator.js +87 -30
- package/dist/deploy/orchestrator.js.map +1 -1
- package/dist/deploy/package.d.ts +14 -1
- package/dist/deploy/package.d.ts.map +1 -1
- package/dist/deploy/package.js +37 -2
- package/dist/deploy/package.js.map +1 -1
- package/dist/deploy/register.d.ts +3 -0
- package/dist/deploy/register.d.ts.map +1 -1
- package/dist/deploy/register.js +50 -33
- package/dist/deploy/register.js.map +1 -1
- package/dist/dsl/monitor/dsl-failure-events.d.ts +38 -2
- package/dist/dsl/monitor/dsl-failure-events.d.ts.map +1 -1
- package/dist/dsl/monitor/dsl-failure-events.js +67 -4
- package/dist/dsl/monitor/dsl-failure-events.js.map +1 -1
- package/dist/dsl/monitor/process-one-position.d.ts.map +1 -1
- package/dist/dsl/monitor/process-one-position.js +25 -1
- package/dist/dsl/monitor/process-one-position.js.map +1 -1
- package/dist/index.d.ts +9 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +527 -158
- package/dist/index.js.map +1 -1
- package/dist/runtime/auto-update/coordinator.d.ts +19 -2
- package/dist/runtime/auto-update/coordinator.d.ts.map +1 -1
- package/dist/runtime/auto-update/coordinator.js +104 -20
- package/dist/runtime/auto-update/coordinator.js.map +1 -1
- package/dist/runtime/auto-update/gateway-restart.d.ts +2 -2
- package/dist/runtime/auto-update/gateway-restart.js +1 -1
- package/dist/runtime/auto-update/idle-gate.d.ts +45 -9
- package/dist/runtime/auto-update/idle-gate.d.ts.map +1 -1
- package/dist/runtime/auto-update/idle-gate.js +26 -14
- package/dist/runtime/auto-update/idle-gate.js.map +1 -1
- package/dist/runtime/auto-update/register-idle-gate.d.ts +1 -1
- package/dist/runtime/auto-update/register-idle-gate.d.ts.map +1 -1
- package/dist/runtime/auto-update/register-idle-gate.js +8 -4
- package/dist/runtime/auto-update/register-idle-gate.js.map +1 -1
- package/dist/runtime/auto-update/run-update-command.d.ts +1 -1
- package/dist/runtime/auto-update/run-update-command.js +1 -1
- package/dist/runtime/auto-update/types.d.ts +2 -1
- package/dist/runtime/auto-update/types.d.ts.map +1 -1
- package/dist/runtime/auto-update/types.js.map +1 -1
- package/dist/runtime/auto-update/update-schedule.d.ts +14 -4
- package/dist/runtime/auto-update/update-schedule.d.ts.map +1 -1
- package/dist/runtime/auto-update/update-schedule.js +21 -5
- package/dist/runtime/auto-update/update-schedule.js.map +1 -1
- package/dist/runtime/boot-skip.d.ts +18 -0
- package/dist/runtime/boot-skip.d.ts.map +1 -1
- package/dist/runtime/boot-skip.js +25 -0
- package/dist/runtime/boot-skip.js.map +1 -1
- package/dist/runtime/lifecycle-events.d.ts +2 -2
- package/dist/runtime/lifecycle-events.d.ts.map +1 -1
- package/dist/runtime/lifecycle-events.js.map +1 -1
- package/dist/runtime/lifecycle-reaper.d.ts +11 -6
- package/dist/runtime/lifecycle-reaper.d.ts.map +1 -1
- package/dist/runtime/lifecycle-reaper.js +25 -15
- package/dist/runtime/lifecycle-reaper.js.map +1 -1
- package/dist/runtime/notifications.d.ts +10 -0
- package/dist/runtime/notifications.d.ts.map +1 -1
- package/dist/runtime/notifications.js +17 -6
- package/dist/runtime/notifications.js.map +1 -1
- package/dist/runtime/process-state.d.ts +168 -0
- package/dist/runtime/process-state.d.ts.map +1 -0
- package/dist/runtime/process-state.js +81 -0
- package/dist/runtime/process-state.js.map +1 -0
- package/dist/runtime/reconcile-state.d.ts.map +1 -1
- package/dist/runtime/reconcile-state.js +18 -4
- package/dist/runtime/reconcile-state.js.map +1 -1
- package/dist/runtime/runtime.d.ts.map +1 -1
- package/dist/runtime/runtime.js +4 -1
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/strategy-registry.d.ts +16 -0
- package/dist/runtime/strategy-registry.d.ts.map +1 -1
- package/dist/runtime/strategy-registry.js +7 -3
- package/dist/runtime/strategy-registry.js.map +1 -1
- package/dist/runtime/update-apply-deps.d.ts +5 -3
- package/dist/runtime/update-apply-deps.d.ts.map +1 -1
- package/dist/runtime/update-apply-deps.js +15 -3
- package/dist/runtime/update-apply-deps.js.map +1 -1
- package/dist/scanners/external/scaffold/preflight.py +492 -12
- package/dist/senpi/__tests__/helpers/fake-paper-mcp.d.ts +44 -0
- package/dist/senpi/__tests__/helpers/fake-paper-mcp.d.ts.map +1 -0
- package/dist/senpi/__tests__/helpers/fake-paper-mcp.js +129 -0
- package/dist/senpi/__tests__/helpers/fake-paper-mcp.js.map +1 -0
- package/dist/senpi/client.d.ts +40 -2
- package/dist/senpi/client.d.ts.map +1 -1
- package/dist/senpi/client.js +82 -15
- package/dist/senpi/client.js.map +1 -1
- package/dist/senpi/paper.d.ts +28 -0
- package/dist/senpi/paper.d.ts.map +1 -0
- package/dist/senpi/paper.js +35 -0
- package/dist/senpi/paper.js.map +1 -0
- package/dist/senpi/strategy-status.d.ts.map +1 -1
- package/dist/senpi/strategy-status.js +2 -0
- package/dist/senpi/strategy-status.js.map +1 -1
- package/dist/senpi/types.d.ts +8 -1
- package/dist/senpi/types.d.ts.map +1 -1
- package/dist/telemetry/box-memory.d.ts +29 -0
- package/dist/telemetry/box-memory.d.ts.map +1 -0
- package/dist/telemetry/box-memory.js +113 -0
- package/dist/telemetry/box-memory.js.map +1 -0
- package/dist/telemetry/metrics.d.ts +22 -1
- package/dist/telemetry/metrics.d.ts.map +1 -1
- package/dist/telemetry/metrics.js +83 -1
- package/dist/telemetry/metrics.js.map +1 -1
- package/dist/telemetry/spans/span-hooks.d.ts +1 -1
- package/dist/telemetry/spans/span-hooks.d.ts.map +1 -1
- package/dist/telemetry/spans/span-hooks.js +5 -2
- package/dist/telemetry/spans/span-hooks.js.map +1 -1
- package/dist/telemetry/trace-identity.d.ts.map +1 -1
- package/dist/telemetry/trace-identity.js +2 -0
- package/dist/telemetry/trace-identity.js.map +1 -1
- package/dist/test-setup.js +7 -1
- package/dist/test-setup.js.map +1 -1
- package/dist/tool-surface/crib-hook.d.ts.map +1 -1
- package/dist/tool-surface/crib-hook.js +8 -0
- package/dist/tool-surface/crib-hook.js.map +1 -1
- package/dist/tool-surface/crib-sheet.d.ts +1 -1
- package/dist/tool-surface/crib-sheet.js +1 -1
- package/dist/tool-surface/mcp-tool-source.d.ts +1 -1
- package/dist/tool-surface/mcp-tool-source.js +2 -2
- package/dist/universe/package-universe.js +1 -1
- package/dist/universe/package-universe.js.map +1 -1
- package/dist/utils/event-catalog.d.ts +34 -4
- package/dist/utils/event-catalog.d.ts.map +1 -1
- package/dist/utils/event-catalog.js +6 -0
- package/dist/utils/event-catalog.js.map +1 -1
- package/dist/validate/codes.d.ts +2 -0
- package/dist/validate/codes.d.ts.map +1 -1
- package/dist/validate/codes.js +6 -0
- package/dist/validate/codes.js.map +1 -1
- package/dist/validate/live-stage.d.ts +12 -0
- package/dist/validate/live-stage.d.ts.map +1 -1
- package/dist/validate/live-stage.js +16 -0
- package/dist/validate/live-stage.js.map +1 -1
- package/dist/widgets/tool.d.ts +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { isPaperAddress, isPaperStrategyId } from "../../paper.js";
|
|
2
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
3
|
+
function ok(data) {
|
|
4
|
+
return { success: true, data, meta: { tool: "fake" } };
|
|
5
|
+
}
|
|
6
|
+
function refuse(code, message) {
|
|
7
|
+
return { success: false, error: { code, message, retryable: false, details: {} }, meta: { tool: "fake" } };
|
|
8
|
+
}
|
|
9
|
+
function wire(row, paper, flag) {
|
|
10
|
+
return {
|
|
11
|
+
id: row.id,
|
|
12
|
+
strategyWalletAddress: row.strategyWalletAddress,
|
|
13
|
+
status: row.status,
|
|
14
|
+
strategyName: row.strategyName,
|
|
15
|
+
strategyType: "CUSTOM",
|
|
16
|
+
traderAddress: "",
|
|
17
|
+
createdAt: "2026-11-07T00:00:00Z",
|
|
18
|
+
...(row.totalFunded !== undefined ? { totalFunded: row.totalFunded } : {}),
|
|
19
|
+
...(row.skillName ? { strategyMetadata: { skillName: row.skillName } } : {}),
|
|
20
|
+
...(paper && flag ? { paper: true } : {}),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export function createFakePaperMcp(options = {}) {
|
|
24
|
+
const router = options.router ?? true;
|
|
25
|
+
const live = [...(options.live ?? [])];
|
|
26
|
+
const paper = [...(options.paper ?? [])];
|
|
27
|
+
const calls = [];
|
|
28
|
+
const pendingStatuses = new Map();
|
|
29
|
+
let created = 0;
|
|
30
|
+
const currentStatus = (row) => {
|
|
31
|
+
const queue = pendingStatuses.get(row.id);
|
|
32
|
+
if (queue && queue.length > 0) {
|
|
33
|
+
row.status = queue.length > 1 ? queue.shift() : queue[0];
|
|
34
|
+
}
|
|
35
|
+
return row.status;
|
|
36
|
+
};
|
|
37
|
+
function strategyList(args) {
|
|
38
|
+
const ids = args.strategy_ids ?? [];
|
|
39
|
+
const addresses = args.strategy_addresses ?? [];
|
|
40
|
+
if (!router) {
|
|
41
|
+
if (ids.some((id) => !UUID_RE.test(id)))
|
|
42
|
+
return refuse("SERR186", "strategyIds must be UUIDs");
|
|
43
|
+
return ok({ strategies: select(live, ids, addresses).map((r) => wire(r, false, false)) });
|
|
44
|
+
}
|
|
45
|
+
if (args.paper !== undefined && typeof args.paper !== "boolean") {
|
|
46
|
+
return refuse("PAPER_FLAG_INVALID", "paper must be a boolean");
|
|
47
|
+
}
|
|
48
|
+
const filterWorlds = new Set([
|
|
49
|
+
...ids.map((id) => isPaperStrategyId(id)),
|
|
50
|
+
...addresses.map((a) => isPaperAddress(a)),
|
|
51
|
+
]);
|
|
52
|
+
if (filterWorlds.size > 1)
|
|
53
|
+
return refuse("PAPER_IDENTIFIER_MISMATCH", "filter mixes worlds");
|
|
54
|
+
const flag = args.paper === true;
|
|
55
|
+
const [filterWorld] = [...filterWorlds];
|
|
56
|
+
if (filterWorld !== undefined && args.paper !== undefined && filterWorld !== flag) {
|
|
57
|
+
return refuse("PAPER_IDENTIFIER_MISMATCH", "paper flag disagrees with the filter");
|
|
58
|
+
}
|
|
59
|
+
const world = filterWorld ?? flag;
|
|
60
|
+
if (!world)
|
|
61
|
+
return ok({ strategies: select(live, ids, addresses).map((r) => wire(r, false, false)) });
|
|
62
|
+
const rows = select(paper, ids, addresses).map((r) => wire(r, true, !options.unflaggedPaperRows));
|
|
63
|
+
return ok({ paper_routing: true, strategies: rows });
|
|
64
|
+
}
|
|
65
|
+
function select(rows, ids, addresses) {
|
|
66
|
+
const lowered = addresses.map((a) => a.toLowerCase());
|
|
67
|
+
return rows.filter((row) => {
|
|
68
|
+
if (ids.length > 0 && !ids.includes(row.id))
|
|
69
|
+
return false;
|
|
70
|
+
if (lowered.length > 0 && !lowered.includes(row.strategyWalletAddress.toLowerCase()))
|
|
71
|
+
return false;
|
|
72
|
+
currentStatus(row);
|
|
73
|
+
return true;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
function create(args) {
|
|
77
|
+
created += 1;
|
|
78
|
+
const name = typeof args.strategyName === "string" ? args.strategyName : `strategy-${created}`;
|
|
79
|
+
const skillName = typeof args.skillName === "string" ? args.skillName : undefined;
|
|
80
|
+
const funded = typeof args.initialBudget === "number" ? args.initialBudget : undefined;
|
|
81
|
+
if (router && args.paper === true) {
|
|
82
|
+
const statuses = options.paperCreateStatuses ?? ["CREATING", "ACTIVE"];
|
|
83
|
+
const row = {
|
|
84
|
+
id: `paper-0000000${created}-1111-4111-8111-111111111111`,
|
|
85
|
+
strategyWalletAddress: options.paperCreateWallet ?? `0x00000000000000001762460000000abcdef0123${created}`,
|
|
86
|
+
status: statuses[0],
|
|
87
|
+
strategyName: name,
|
|
88
|
+
...(skillName ? { skillName } : {}),
|
|
89
|
+
...(funded !== undefined ? { totalFunded: funded } : {}),
|
|
90
|
+
};
|
|
91
|
+
pendingStatuses.set(row.id, [...statuses]);
|
|
92
|
+
paper.push(row);
|
|
93
|
+
return ok({ strategy: wire(row, true, true), message: "creating" });
|
|
94
|
+
}
|
|
95
|
+
const row = {
|
|
96
|
+
id: `0000000${created}-2222-4222-8222-222222222222`,
|
|
97
|
+
strategyWalletAddress: `0x${String(created).padStart(40, "a")}`,
|
|
98
|
+
status: "ACTIVE",
|
|
99
|
+
strategyName: name,
|
|
100
|
+
...(skillName ? { skillName } : {}),
|
|
101
|
+
...(funded !== undefined ? { totalFunded: funded } : {}),
|
|
102
|
+
};
|
|
103
|
+
live.push(row);
|
|
104
|
+
return ok({ strategy: wire(row, false, false), message: "creating" });
|
|
105
|
+
}
|
|
106
|
+
const transport = async (tool, args) => {
|
|
107
|
+
calls.push({ tool, args: structuredClone(args) });
|
|
108
|
+
switch (tool) {
|
|
109
|
+
case "strategy_list":
|
|
110
|
+
return strategyList(args);
|
|
111
|
+
case "strategy_create_custom_strategy":
|
|
112
|
+
return create(args);
|
|
113
|
+
case "account_get_portfolio":
|
|
114
|
+
return ok({ portfolio: { total_in_hyperliquid: 100000 } });
|
|
115
|
+
case "strategy_close":
|
|
116
|
+
return ok({ success: true });
|
|
117
|
+
default:
|
|
118
|
+
return refuse("NOT_FOUND", `fake MCP has no ${tool}`);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
return {
|
|
122
|
+
transport,
|
|
123
|
+
calls,
|
|
124
|
+
callsTo: (tool) => calls.filter((c) => c.tool === tool).map((c) => c.args),
|
|
125
|
+
live,
|
|
126
|
+
paper,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=fake-paper-mcp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fake-paper-mcp.js","sourceRoot":"","sources":["../../../../src/senpi/__tests__/helpers/fake-paper-mcp.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAoCnE,MAAM,OAAO,GAAG,iEAAiE,CAAC;AAElF,SAAS,EAAE,CAAC,IAA6B;IACvC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,I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ER_CALL_TOOLS: ReadonlySet<string>;
|
|
|
18
18
|
* stops gating it.
|
|
19
19
|
*/
|
|
20
20
|
export declare function isMoneyCallTool(bare: string): boolean;
|
|
21
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Order/close MCP calls currently in flight across every `SenpiClient` in this process. The count
|
|
23
|
+
* lives in the process state, not this module: a 10.x plugin reload evaluates a new copy of this
|
|
24
|
+
* module while the previous copy's calls are still running, and the idle gate must see both.
|
|
25
|
+
*/
|
|
22
26
|
export declare function senpiOrderCallsInFlight(): number;
|
|
23
27
|
/**
|
|
24
28
|
* Typed error thrown by `SenpiClient` mutation methods when the response
|
|
@@ -105,6 +109,13 @@ export declare function isOutcomeUnknownCode(code: string | null | undefined): b
|
|
|
105
109
|
* rather than each re-deriving the rule.
|
|
106
110
|
*/
|
|
107
111
|
export declare function isRetriableMcpError(err: unknown): boolean;
|
|
112
|
+
/**
|
|
113
|
+
* A `strategy_list` reply from the wrong world: a paper call answered without the router's marker,
|
|
114
|
+
* or a live call answered with it. The list is unknown, never empty.
|
|
115
|
+
*/
|
|
116
|
+
export declare class PaperRoutingError extends Error {
|
|
117
|
+
readonly name = "PaperRoutingError";
|
|
118
|
+
}
|
|
108
119
|
export declare class SenpiClient {
|
|
109
120
|
private readonly injectedTransport;
|
|
110
121
|
private readonly config;
|
|
@@ -332,7 +343,13 @@ export declare class SenpiClient {
|
|
|
332
343
|
* created and funded a second wallet beside every live one and then reported `live`. An empty
|
|
333
344
|
* `strategies` array is still a real answer and is returned as one; anything else throws.
|
|
334
345
|
*/
|
|
335
|
-
|
|
346
|
+
/**
|
|
347
|
+
* One world per call (SPEC §6.3). `filters.paper` is always sent. A paper call refuses a reply
|
|
348
|
+
* without `paper_routing: true`, because an MCP with no router drops the flag and answers with
|
|
349
|
+
* live rows; a live call refuses a reply that carries the marker. Rows from the other world are
|
|
350
|
+
* dropped: a paper call keeps only rows with `paper: true`, a live call only rows without it.
|
|
351
|
+
*/
|
|
352
|
+
listStrategies(filters: ListStrategiesFilters, opts?: {
|
|
336
353
|
signal?: AbortSignal;
|
|
337
354
|
}): Promise<StrategySummary[]>;
|
|
338
355
|
/**
|
|
@@ -345,6 +362,27 @@ export declare class SenpiClient {
|
|
|
345
362
|
getStrategyLimits(opts?: {
|
|
346
363
|
signal?: AbortSignal;
|
|
347
364
|
}): Promise<StrategyLimits>;
|
|
365
|
+
/**
|
|
366
|
+
* Strategies for a set of wallets, each asked in its own world: paper wallets on a `paper: true`
|
|
367
|
+
* call, the rest on a live one. A world with no wallets makes no call. Either call failing throws,
|
|
368
|
+
* so a caller never mistakes half an answer for a whole one.
|
|
369
|
+
*/
|
|
370
|
+
listStrategiesForWallets(wallets: readonly string[], opts?: {
|
|
371
|
+
signal?: AbortSignal;
|
|
372
|
+
}): Promise<StrategySummary[]>;
|
|
373
|
+
/**
|
|
374
|
+
* Whether the MCP routes paper calls, asked with the probe id no strategy has (SPEC §6.3). Any
|
|
375
|
+
* answer but an empty-or-not list carrying `paper_routing: true` is `routed: false`, including a
|
|
376
|
+
* transport fault: a caller that cannot prove it reached a paper-aware MCP does not act.
|
|
377
|
+
*/
|
|
378
|
+
probePaperRouting(opts?: {
|
|
379
|
+
signal?: AbortSignal;
|
|
380
|
+
}): Promise<{
|
|
381
|
+
routed: true;
|
|
382
|
+
} | {
|
|
383
|
+
routed: false;
|
|
384
|
+
reason: string;
|
|
385
|
+
}>;
|
|
348
386
|
getOpenOrders(wallet: string): Promise<GetOpenOrdersResult[]>;
|
|
349
387
|
/**
|
|
350
388
|
* Closed-position history from MCP `discovery_get_trader_history`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/senpi/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/senpi/client.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EACV,YAAY,EACZ,iBAAiB,EACjB,qBAAqB,EACrB,oBAA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DtG;AA8LD;;;GAGG;AACH,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAQvF;AA2JD;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,0EAA0E;IAC1E,gBAAgB,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CACnC;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,eAAe,CAgBtE"}
|
package/dist/senpi/client.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
2
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
3
3
|
import { MCP_BASE_URL } from "./constants.js";
|
|
4
|
+
import { isPaperAddress, PAPER_ROUTING_PROBE_ID } from "./paper.js";
|
|
4
5
|
import { isRecord, unwrapEnvelope, asString, asNumber } from "../utils/response.js";
|
|
5
6
|
import { extractMinClearingHouseTime, createClearingHouseStalenessGuard } from "../utils/clearing-house-staleness.js";
|
|
6
7
|
import { normalizeDslCoinDex, reconcileDexFromClearingHouseKey } from "../utils/perp-coin.js";
|
|
@@ -12,6 +13,7 @@ import { SpanKind } from "@opentelemetry/api";
|
|
|
12
13
|
import { GEN_AI, errorTypeOf, setDefinedAttributes, setGenAiContentAttribute, } from "../telemetry/spans/gen-ai.js";
|
|
13
14
|
import { EVENT_NAME, eventAttrs } from "../utils/event-catalog.js";
|
|
14
15
|
import { elapsedSeconds, recordToolCall, recordClearinghouseRetry } from "../telemetry/metrics.js";
|
|
16
|
+
import { runtimeProcessState } from "../runtime/process-state.js";
|
|
15
17
|
const logger = createLogger("[senpi][client]");
|
|
16
18
|
/**
|
|
17
19
|
* MCP tools that move money or change protection: place, change or close an
|
|
@@ -49,10 +51,13 @@ export function isMoneyCallTool(bare) {
|
|
|
49
51
|
moneyCallTools ??= new Set([...ORDER_CALL_TOOLS, ...loadToolApprovalsManifest().tradeTools]);
|
|
50
52
|
return moneyCallTools.has(bare);
|
|
51
53
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Order/close MCP calls currently in flight across every `SenpiClient` in this process. The count
|
|
56
|
+
* lives in the process state, not this module: a 10.x plugin reload evaluates a new copy of this
|
|
57
|
+
* module while the previous copy's calls are still running, and the idle gate must see both.
|
|
58
|
+
*/
|
|
54
59
|
export function senpiOrderCallsInFlight() {
|
|
55
|
-
return orderCallsInFlight;
|
|
60
|
+
return runtimeProcessState().orderCallsInFlight;
|
|
56
61
|
}
|
|
57
62
|
/**
|
|
58
63
|
* Typed error thrown by `SenpiClient` mutation methods when the response
|
|
@@ -335,6 +340,13 @@ function describeToolFailure(data) {
|
|
|
335
340
|
return `tool reported failure: ${extractEngineMessage(rec)}`;
|
|
336
341
|
return `response keys: ${Object.keys(rec).join(", ") || "(none)"}`;
|
|
337
342
|
}
|
|
343
|
+
/**
|
|
344
|
+
* A `strategy_list` reply from the wrong world: a paper call answered without the router's marker,
|
|
345
|
+
* or a live call answered with it. The list is unknown, never empty.
|
|
346
|
+
*/
|
|
347
|
+
export class PaperRoutingError extends Error {
|
|
348
|
+
name = "PaperRoutingError";
|
|
349
|
+
}
|
|
338
350
|
/**
|
|
339
351
|
* The attribution stamp on a `strategy_list` row, tolerant of a JSON-encoded metadata payload.
|
|
340
352
|
*
|
|
@@ -371,6 +383,11 @@ function readSkillName(raw) {
|
|
|
371
383
|
* with a best-effort engine message.
|
|
372
384
|
* 5. Otherwise return the inner data.
|
|
373
385
|
*
|
|
386
|
+
* On 2 and 4 the envelope's / engine's own `error.code` (e.g. `UNAVAILABLE`,
|
|
387
|
+
* `INVALID_ARGUMENT`) also rides `SenpiClientError.upstreamCode`, so telemetry
|
|
388
|
+
* can key on it without parsing the message. It is informational only:
|
|
389
|
+
* `mayHaveExecuted` stays false here, as before.
|
|
390
|
+
*
|
|
374
391
|
* Used by every mutation method (createPosition, editPosition,
|
|
375
392
|
* closePosition, etc.) so DSL/actions can rely on `throw` semantics
|
|
376
393
|
* matching real failures, instead of trusting an outer-envelope-only
|
|
@@ -387,7 +404,9 @@ function requireMutationSuccess(tool, raw) {
|
|
|
387
404
|
const message = (errObj && typeof errObj.message === "string")
|
|
388
405
|
? errObj.message
|
|
389
406
|
: `${tool}: outer envelope reported failure`;
|
|
390
|
-
throw new SenpiClientError("UPSTREAM_ERROR", `${tool}: ${code}: ${message}`, raw
|
|
407
|
+
throw new SenpiClientError("UPSTREAM_ERROR", `${tool}: ${code}: ${message}`, raw, {
|
|
408
|
+
upstreamCode: envelopeErrorCode(errObj),
|
|
409
|
+
});
|
|
391
410
|
}
|
|
392
411
|
const data = unwrapEnvelope(raw) ?? raw;
|
|
393
412
|
if (!isRecord(data)) {
|
|
@@ -395,7 +414,7 @@ function requireMutationSuccess(tool, raw) {
|
|
|
395
414
|
}
|
|
396
415
|
// Inner engine-level success check (only when the field is explicitly boolean).
|
|
397
416
|
if (typeof data.success === "boolean" && data.success === false) {
|
|
398
|
-
throw new SenpiClientError("ENGINE_FAILURE", `${tool}: ${extractEngineMessage(data)}`, data);
|
|
417
|
+
throw new SenpiClientError("ENGINE_FAILURE", `${tool}: ${extractEngineMessage(data)}`, data, { upstreamCode: envelopeErrorCode(data.error) });
|
|
399
418
|
}
|
|
400
419
|
return data;
|
|
401
420
|
}
|
|
@@ -634,12 +653,14 @@ export class SenpiClient {
|
|
|
634
653
|
async callTool(toolName, args, opts) {
|
|
635
654
|
if (!isMoneyCallTool(toolName))
|
|
636
655
|
return this.callToolSpan(toolName, args, opts);
|
|
637
|
-
|
|
656
|
+
// The same object for the decrement as for the increment.
|
|
657
|
+
const processState = runtimeProcessState();
|
|
658
|
+
processState.orderCallsInFlight += 1;
|
|
638
659
|
try {
|
|
639
660
|
return await this.callToolSpan(toolName, args, opts);
|
|
640
661
|
}
|
|
641
662
|
finally {
|
|
642
|
-
orderCallsInFlight -= 1;
|
|
663
|
+
processState.orderCallsInFlight -= 1;
|
|
643
664
|
}
|
|
644
665
|
}
|
|
645
666
|
/** The span-wrapped body of {@link callTool}. */
|
|
@@ -1200,7 +1221,7 @@ export class SenpiClient {
|
|
|
1200
1221
|
async getStrategy(wallet) {
|
|
1201
1222
|
// The backend `strategy_get` tool requires a strategy_id, not a wallet address.
|
|
1202
1223
|
// Look up by wallet via `strategy_list` with an address filter instead.
|
|
1203
|
-
const matches = await this.
|
|
1224
|
+
const matches = await this.listStrategiesForWallets([wallet]);
|
|
1204
1225
|
const match = matches.find((s) => s.strategyWalletAddress.toLowerCase() === wallet.toLowerCase())
|
|
1205
1226
|
?? matches[0];
|
|
1206
1227
|
if (!match || !match.id)
|
|
@@ -1227,15 +1248,21 @@ export class SenpiClient {
|
|
|
1227
1248
|
* created and funded a second wallet beside every live one and then reported `live`. An empty
|
|
1228
1249
|
* `strategies` array is still a real answer and is returned as one; anything else throws.
|
|
1229
1250
|
*/
|
|
1251
|
+
/**
|
|
1252
|
+
* One world per call (SPEC §6.3). `filters.paper` is always sent. A paper call refuses a reply
|
|
1253
|
+
* without `paper_routing: true`, because an MCP with no router drops the flag and answers with
|
|
1254
|
+
* live rows; a live call refuses a reply that carries the marker. Rows from the other world are
|
|
1255
|
+
* dropped: a paper call keeps only rows with `paper: true`, a live call only rows without it.
|
|
1256
|
+
*/
|
|
1230
1257
|
async listStrategies(filters, opts) {
|
|
1231
|
-
const args = {};
|
|
1232
|
-
if (filters
|
|
1258
|
+
const args = { paper: filters.paper };
|
|
1259
|
+
if (filters.strategyAddresses)
|
|
1233
1260
|
args.strategy_addresses = filters.strategyAddresses;
|
|
1234
|
-
if (filters
|
|
1261
|
+
if (filters.status)
|
|
1235
1262
|
args.status = filters.status;
|
|
1236
|
-
if (filters
|
|
1263
|
+
if (filters.strategyIds)
|
|
1237
1264
|
args.strategy_ids = filters.strategyIds;
|
|
1238
|
-
if (filters
|
|
1265
|
+
if (filters.strategyType)
|
|
1239
1266
|
args.strategy_type = filters.strategyType;
|
|
1240
1267
|
const raw = await this.callTool("strategy_list", args, opts);
|
|
1241
1268
|
const data = unwrapEnvelope(raw);
|
|
@@ -1245,8 +1272,18 @@ export class SenpiClient {
|
|
|
1245
1272
|
throw new Error(`strategy_list: no strategies array in the response — the strategy list is UNKNOWN, ` +
|
|
1246
1273
|
`not empty (${detail})`);
|
|
1247
1274
|
}
|
|
1248
|
-
|
|
1249
|
-
|
|
1275
|
+
if ((data.paper_routing === true) !== filters.paper) {
|
|
1276
|
+
throw new PaperRoutingError(filters.paper
|
|
1277
|
+
? `strategy_list {paper: true} was answered without paper_routing: true. This MCP has no ` +
|
|
1278
|
+
`paper router, so its rows are live strategies, not simulations. The simulation list ` +
|
|
1279
|
+
`is UNKNOWN and nothing was done with it.`
|
|
1280
|
+
: `strategy_list for live strategies was answered with paper_routing: true. A live call ` +
|
|
1281
|
+
`never reads a simulation reply, so the live list is UNKNOWN and nothing was done with it.`);
|
|
1282
|
+
}
|
|
1283
|
+
const strategies = data.strategies
|
|
1284
|
+
.filter(isRecord)
|
|
1285
|
+
.filter((s) => (s.paper === true) === filters.paper);
|
|
1286
|
+
return strategies.map((s) => ({
|
|
1250
1287
|
id: asString(s.id) ?? "",
|
|
1251
1288
|
strategyWalletAddress: asString(s.strategyWalletAddress) ?? "",
|
|
1252
1289
|
traderAddress: asString(s.traderAddress) ?? "",
|
|
@@ -1286,6 +1323,35 @@ export class SenpiClient {
|
|
|
1286
1323
|
summary: asString(data.summary) ?? "",
|
|
1287
1324
|
};
|
|
1288
1325
|
}
|
|
1326
|
+
/**
|
|
1327
|
+
* Strategies for a set of wallets, each asked in its own world: paper wallets on a `paper: true`
|
|
1328
|
+
* call, the rest on a live one. A world with no wallets makes no call. Either call failing throws,
|
|
1329
|
+
* so a caller never mistakes half an answer for a whole one.
|
|
1330
|
+
*/
|
|
1331
|
+
async listStrategiesForWallets(wallets, opts) {
|
|
1332
|
+
const paper = wallets.filter((w) => isPaperAddress(w));
|
|
1333
|
+
const live = wallets.filter((w) => !isPaperAddress(w));
|
|
1334
|
+
const rows = [];
|
|
1335
|
+
if (live.length > 0)
|
|
1336
|
+
rows.push(...(await this.listStrategies({ paper: false, strategyAddresses: live }, opts)));
|
|
1337
|
+
if (paper.length > 0)
|
|
1338
|
+
rows.push(...(await this.listStrategies({ paper: true, strategyAddresses: paper }, opts)));
|
|
1339
|
+
return rows;
|
|
1340
|
+
}
|
|
1341
|
+
/**
|
|
1342
|
+
* Whether the MCP routes paper calls, asked with the probe id no strategy has (SPEC §6.3). Any
|
|
1343
|
+
* answer but an empty-or-not list carrying `paper_routing: true` is `routed: false`, including a
|
|
1344
|
+
* transport fault: a caller that cannot prove it reached a paper-aware MCP does not act.
|
|
1345
|
+
*/
|
|
1346
|
+
async probePaperRouting(opts) {
|
|
1347
|
+
try {
|
|
1348
|
+
await this.listStrategies({ paper: true, strategyIds: [PAPER_ROUTING_PROBE_ID] }, opts);
|
|
1349
|
+
return { routed: true };
|
|
1350
|
+
}
|
|
1351
|
+
catch (err) {
|
|
1352
|
+
return { routed: false, reason: err instanceof Error ? err.message : String(err) };
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1289
1355
|
async getOpenOrders(wallet) {
|
|
1290
1356
|
const raw = await this.callTool("strategy_get_open_orders", { strategy_wallet: wallet });
|
|
1291
1357
|
const data = unwrapEnvelope(raw);
|
|
@@ -1368,6 +1434,7 @@ export class SenpiClient {
|
|
|
1368
1434
|
skillVersion: params.skillVersion,
|
|
1369
1435
|
...(params.facts ? { facts: params.facts } : {}),
|
|
1370
1436
|
...(params.catalog ? { catalog: params.catalog } : {}),
|
|
1437
|
+
...(params.paper ? { paper: true } : {}),
|
|
1371
1438
|
}, opts);
|
|
1372
1439
|
const data = unwrapEnvelope(raw);
|
|
1373
1440
|
if (!isRecord(data))
|