@kashdao/cli 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +78 -0
- package/CONTRIBUTING.md +159 -0
- package/LICENSE +21 -0
- package/README.md +868 -0
- package/SECURITY.md +110 -0
- package/dist/account-AVFLEM5D.js +90 -0
- package/dist/account-AVFLEM5D.js.map +1 -0
- package/dist/auth-GUJCVKTD.js +239 -0
- package/dist/auth-GUJCVKTD.js.map +1 -0
- package/dist/chunk-BN2CUM42.js +9 -0
- package/dist/chunk-BN2CUM42.js.map +1 -0
- package/dist/chunk-BRK7KJ4O.js +154 -0
- package/dist/chunk-BRK7KJ4O.js.map +1 -0
- package/dist/chunk-KMBMQIZ7.js +393 -0
- package/dist/chunk-KMBMQIZ7.js.map +1 -0
- package/dist/chunk-LBIRQHX5.js +133 -0
- package/dist/chunk-LBIRQHX5.js.map +1 -0
- package/dist/chunk-MIXOZU2S.js +366 -0
- package/dist/chunk-MIXOZU2S.js.map +1 -0
- package/dist/chunk-QJMF73M5.js +129 -0
- package/dist/chunk-QJMF73M5.js.map +1 -0
- package/dist/chunk-UZNSYATZ.js +680 -0
- package/dist/chunk-UZNSYATZ.js.map +1 -0
- package/dist/chunk-VIADBYFY.js +94 -0
- package/dist/chunk-VIADBYFY.js.map +1 -0
- package/dist/chunk-YHCG2SUC.js +159 -0
- package/dist/chunk-YHCG2SUC.js.map +1 -0
- package/dist/chunk-YJX3JJ4M.js +174 -0
- package/dist/chunk-YJX3JJ4M.js.map +1 -0
- package/dist/client-IOM55ZCS.js +14 -0
- package/dist/client-IOM55ZCS.js.map +1 -0
- package/dist/completion-ZZGX5BQC.js +100 -0
- package/dist/completion-ZZGX5BQC.js.map +1 -0
- package/dist/config-XJL5TSYK.js +690 -0
- package/dist/config-XJL5TSYK.js.map +1 -0
- package/dist/config-store-3ZSYGXMQ.js +44 -0
- package/dist/config-store-3ZSYGXMQ.js.map +1 -0
- package/dist/docs-MDKKSJDC.js +102 -0
- package/dist/docs-MDKKSJDC.js.map +1 -0
- package/dist/eoa-IQ72EIHR.js +551 -0
- package/dist/eoa-IQ72EIHR.js.map +1 -0
- package/dist/errors-WMZIEGQI.js +18 -0
- package/dist/errors-WMZIEGQI.js.map +1 -0
- package/dist/explain-H4EH3KH3.js +165 -0
- package/dist/explain-H4EH3KH3.js.map +1 -0
- package/dist/global-options-XOLJUPTT.js +18 -0
- package/dist/global-options-XOLJUPTT.js.map +1 -0
- package/dist/health-VZEIII74.js +98 -0
- package/dist/health-VZEIII74.js.map +1 -0
- package/dist/help-footer-GTANVDNP.js +43 -0
- package/dist/help-footer-GTANVDNP.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +251 -0
- package/dist/index.js.map +1 -0
- package/dist/intro-PQQTYWR7.js +41 -0
- package/dist/intro-PQQTYWR7.js.map +1 -0
- package/dist/markets-C37JZDPE.js +295 -0
- package/dist/markets-C37JZDPE.js.map +1 -0
- package/dist/output-VCBZ3FM7.js +22 -0
- package/dist/output-VCBZ3FM7.js.map +1 -0
- package/dist/portfolio-2AEPIJIG.js +115 -0
- package/dist/portfolio-2AEPIJIG.js.map +1 -0
- package/dist/protocol-XEQXF2GW.js +1572 -0
- package/dist/protocol-XEQXF2GW.js.map +1 -0
- package/dist/quote-I4DVJ7ZB.js +144 -0
- package/dist/quote-I4DVJ7ZB.js.map +1 -0
- package/dist/schema-PIFQ65TS.js +410 -0
- package/dist/schema-PIFQ65TS.js.map +1 -0
- package/dist/setup-USZ6IODD.js +260 -0
- package/dist/setup-USZ6IODD.js.map +1 -0
- package/dist/stdin-YW2CEQXU.js +28 -0
- package/dist/stdin-YW2CEQXU.js.map +1 -0
- package/dist/trace-IZBYTUFO.js +103 -0
- package/dist/trace-IZBYTUFO.js.map +1 -0
- package/dist/trade-IIZSEXEI.js +586 -0
- package/dist/trade-IIZSEXEI.js.map +1 -0
- package/dist/version-JDK3PEP5.js +117 -0
- package/dist/version-JDK3PEP5.js.map +1 -0
- package/dist/version-check-TDCION37.js +138 -0
- package/dist/version-check-TDCION37.js.map +1 -0
- package/dist/webhooks-PTVRKICZ.js +680 -0
- package/dist/webhooks-PTVRKICZ.js.map +1 -0
- package/dist/with-retry-4FIZG3A7.js +223 -0
- package/dist/with-retry-4FIZG3A7.js.map +1 -0
- package/package.json +99 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
colorStatus,
|
|
4
|
+
createTable,
|
|
5
|
+
formatAddress,
|
|
6
|
+
formatDate,
|
|
7
|
+
formatProbability,
|
|
8
|
+
shortId,
|
|
9
|
+
truncate
|
|
10
|
+
} from "./chunk-BRK7KJ4O.js";
|
|
11
|
+
import {
|
|
12
|
+
buildClient
|
|
13
|
+
} from "./chunk-QJMF73M5.js";
|
|
14
|
+
import "./chunk-KMBMQIZ7.js";
|
|
15
|
+
import {
|
|
16
|
+
parseOutcomeIndex
|
|
17
|
+
} from "./chunk-YHCG2SUC.js";
|
|
18
|
+
import "./chunk-BN2CUM42.js";
|
|
19
|
+
import {
|
|
20
|
+
parsePositiveInt,
|
|
21
|
+
readGlobals
|
|
22
|
+
} from "./chunk-LBIRQHX5.js";
|
|
23
|
+
import {
|
|
24
|
+
log,
|
|
25
|
+
print,
|
|
26
|
+
printJson,
|
|
27
|
+
style,
|
|
28
|
+
writeNdjson
|
|
29
|
+
} from "./chunk-VIADBYFY.js";
|
|
30
|
+
import "./chunk-MIXOZU2S.js";
|
|
31
|
+
import {
|
|
32
|
+
CliValidationError,
|
|
33
|
+
toCliError
|
|
34
|
+
} from "./chunk-UZNSYATZ.js";
|
|
35
|
+
|
|
36
|
+
// src/commands/markets/index.ts
|
|
37
|
+
import { Command as Command4 } from "commander";
|
|
38
|
+
|
|
39
|
+
// src/commands/markets/get.ts
|
|
40
|
+
import { Command } from "commander";
|
|
41
|
+
var getMarketCommand = new Command("get").description("Fetch a single market by id.").argument("<id>", "market UUID").addHelpText(
|
|
42
|
+
"after",
|
|
43
|
+
`
|
|
44
|
+
Examples:
|
|
45
|
+
$ kash markets get 9f0b...
|
|
46
|
+
$ kash markets get 9f0b... --json | jq '.outcomes'
|
|
47
|
+
$ kash markets get 9f0b... --json --quiet | jq -r '.outcomes[].label' # agent shape
|
|
48
|
+
$ kash markets get 9f0b... --fields id,status,resolvedOutcomeIndex --json --quiet
|
|
49
|
+
`
|
|
50
|
+
).action(async (id, _opts, cmd) => {
|
|
51
|
+
const globals = readGlobals(cmd);
|
|
52
|
+
let market;
|
|
53
|
+
try {
|
|
54
|
+
const { client } = await buildClient({ requireAuth: true, globals });
|
|
55
|
+
market = await client.markets.get(id);
|
|
56
|
+
} catch (cause) {
|
|
57
|
+
throw toCliError(cause);
|
|
58
|
+
}
|
|
59
|
+
if (globals.json) {
|
|
60
|
+
printJson(market);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
print("");
|
|
64
|
+
print(`${style.bold(market.title ?? "(untitled)")}`);
|
|
65
|
+
print(` ${style.dim("ID ")} ${market.id}`);
|
|
66
|
+
print(` ${style.dim("Contract ")} ${formatAddress(market.contractAddress)}`);
|
|
67
|
+
print(` ${style.dim("Chain ")} ${String(market.chainId)}`);
|
|
68
|
+
print(` ${style.dim("Status ")} ${colorStatus(market.status ?? "UNKNOWN")}`);
|
|
69
|
+
print(` ${style.dim("Outcomes ")} ${String(market.outcomeCount)}`);
|
|
70
|
+
print(` ${style.dim("Created ")} ${formatDate(market.createdAt)}`);
|
|
71
|
+
if (market.expiresAt) {
|
|
72
|
+
print(` ${style.dim("Expires ")} ${formatDate(market.expiresAt)}`);
|
|
73
|
+
}
|
|
74
|
+
if (market.resolvedAt) {
|
|
75
|
+
print(` ${style.dim("Resolved ")} ${formatDate(market.resolvedAt)}`);
|
|
76
|
+
}
|
|
77
|
+
if (market.description) {
|
|
78
|
+
print("");
|
|
79
|
+
print(market.description);
|
|
80
|
+
}
|
|
81
|
+
print("");
|
|
82
|
+
const table = createTable(["#", "Outcome", "Probability"]);
|
|
83
|
+
for (const outcome of market.outcomes) {
|
|
84
|
+
table.push([String(outcome.index), outcome.label, formatProbability(outcome.probability)]);
|
|
85
|
+
}
|
|
86
|
+
print(table.toString());
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// src/commands/markets/list.ts
|
|
90
|
+
import { Command as Command2 } from "commander";
|
|
91
|
+
var ALLOWED_STATUSES = /* @__PURE__ */ new Set(["UNSEEDED", "ACTIVE", "RESOLVED"]);
|
|
92
|
+
var listMarketsCommand = new Command2("list").description("List markets.").option("-s, --status <status>", "filter by status (UNSEEDED | ACTIVE | RESOLVED)").option("-l, --limit <n>", "page size (1-100)", "20").option("-c, --cursor <cursor>", "pagination cursor returned by a previous call").option("-a, --all", "walk every page (use with --json for export)").option(
|
|
93
|
+
"--ndjson",
|
|
94
|
+
"stream results as newline-delimited JSON (one record per line); implies --all"
|
|
95
|
+
).addHelpText(
|
|
96
|
+
"after",
|
|
97
|
+
`
|
|
98
|
+
Examples:
|
|
99
|
+
$ kash markets list --status ACTIVE
|
|
100
|
+
$ kash markets list --json --quiet | jq '.data[].id'
|
|
101
|
+
$ kash markets list --ndjson | while read -r line; do echo "$line" | jq -r .id; done
|
|
102
|
+
$ kash markets list --all --json --quiet > markets.json
|
|
103
|
+
|
|
104
|
+
Notes:
|
|
105
|
+
--ndjson emits one JSON record per line. Consumers must read
|
|
106
|
+
line-by-line (\`while read -r\`, \`jq -c\`, \`split('
|
|
107
|
+
')\`) \u2014 DO NOT
|
|
108
|
+
buffer-then-parse, as the stream may run for arbitrarily many pages.
|
|
109
|
+
`
|
|
110
|
+
).action(async (options, cmd) => {
|
|
111
|
+
const globals = readGlobals(cmd);
|
|
112
|
+
const limit = options.limit === void 0 ? 20 : parsePositiveInt(options.limit, "limit");
|
|
113
|
+
if (limit < 1 || limit > 100) {
|
|
114
|
+
throw new CliValidationError("--limit must be between 1 and 100.", void 0, "limit");
|
|
115
|
+
}
|
|
116
|
+
const status = options.status ? normaliseStatus(options.status) : void 0;
|
|
117
|
+
let response;
|
|
118
|
+
try {
|
|
119
|
+
const { client } = await buildClient({ requireAuth: true, globals });
|
|
120
|
+
response = await client.markets.list({
|
|
121
|
+
limit,
|
|
122
|
+
...status === void 0 ? {} : { status },
|
|
123
|
+
...options.cursor === void 0 ? {} : { cursor: options.cursor }
|
|
124
|
+
});
|
|
125
|
+
if (options.ndjson) {
|
|
126
|
+
for await (const market of response) {
|
|
127
|
+
writeNdjson(market);
|
|
128
|
+
}
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (options.all) {
|
|
132
|
+
const collected = [];
|
|
133
|
+
for await (const market of response) collected.push(market);
|
|
134
|
+
if (globals.json) {
|
|
135
|
+
printJson({
|
|
136
|
+
data: collected,
|
|
137
|
+
pagination: { hasMore: false, cursor: null },
|
|
138
|
+
count: collected.length
|
|
139
|
+
});
|
|
140
|
+
} else {
|
|
141
|
+
renderTable(collected);
|
|
142
|
+
}
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
} catch (cause) {
|
|
146
|
+
throw toCliError(cause);
|
|
147
|
+
}
|
|
148
|
+
if (globals.json) {
|
|
149
|
+
printJson({
|
|
150
|
+
data: response.data,
|
|
151
|
+
pagination: response.pagination,
|
|
152
|
+
count: response.data.length
|
|
153
|
+
});
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (response.data.length === 0) {
|
|
157
|
+
log.info("No markets matched the filter.");
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
renderTable(response.data);
|
|
161
|
+
if (response.pagination.hasMore && response.pagination.cursor) {
|
|
162
|
+
log.detail("Next page", `--cursor ${response.pagination.cursor}`);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
function renderTable(markets) {
|
|
166
|
+
const table = createTable(["ID", "Title", "Status", "Outcomes", "Top outcome", "Created"]);
|
|
167
|
+
for (const market of markets) {
|
|
168
|
+
const outcomes = market.outcomes;
|
|
169
|
+
const top = outcomes.reduce((acc, current) => {
|
|
170
|
+
if (acc === void 0) return current;
|
|
171
|
+
return current.probability > acc.probability ? current : acc;
|
|
172
|
+
}, void 0);
|
|
173
|
+
table.push([
|
|
174
|
+
shortId(market.id),
|
|
175
|
+
truncate(market.title ?? "(untitled)", 42),
|
|
176
|
+
colorStatus(market.status ?? "UNKNOWN"),
|
|
177
|
+
String(market.outcomeCount),
|
|
178
|
+
top ? `${truncate(top.label, 18)} (${formatProbability(top.probability)})` : "-",
|
|
179
|
+
market.createdAt.slice(0, 10)
|
|
180
|
+
]);
|
|
181
|
+
}
|
|
182
|
+
print(table.toString());
|
|
183
|
+
}
|
|
184
|
+
function normaliseStatus(value) {
|
|
185
|
+
const upper = value.toUpperCase();
|
|
186
|
+
if (!ALLOWED_STATUSES.has(upper)) {
|
|
187
|
+
throw new CliValidationError(
|
|
188
|
+
`Unknown market status "${value}".`,
|
|
189
|
+
"Allowed: UNSEEDED, ACTIVE, RESOLVED."
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
return upper;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// src/commands/markets/predictions.ts
|
|
196
|
+
import { Command as Command3 } from "commander";
|
|
197
|
+
var predictionsCommand = new Command3("predictions").description("Recent trades against a market (cursor-paginated, newest first).").argument("<marketId>", "market UUID").option("-s, --side <side>", "filter to a single side: buy | sell").option("-o, --outcome <index>", "filter to a single outcome index (0-based)").option("-l, --limit <n>", "page size (1-100)", "50").option("-c, --cursor <cursor>", "pagination cursor returned by a previous call").option("-a, --all", "walk every page (use with --json for export)").option(
|
|
198
|
+
"--ndjson",
|
|
199
|
+
"stream results as newline-delimited JSON (one record per line); implies --all"
|
|
200
|
+
).addHelpText(
|
|
201
|
+
"after",
|
|
202
|
+
`
|
|
203
|
+
Examples:
|
|
204
|
+
$ kash markets predictions 9f0b...
|
|
205
|
+
$ kash markets predictions 9f0b... --side buy --outcome 0
|
|
206
|
+
$ kash markets predictions 9f0b... --json --quiet | jq -r '.data[].transactionHash'
|
|
207
|
+
$ kash markets predictions 9f0b... --ndjson | head -100
|
|
208
|
+
$ kash markets predictions 9f0b... --all --json --quiet > history.json
|
|
209
|
+
`
|
|
210
|
+
).action(async (marketId, options, cmd) => {
|
|
211
|
+
const globals = readGlobals(cmd);
|
|
212
|
+
const limit = options.limit === void 0 ? 50 : parsePositiveInt(options.limit, "limit");
|
|
213
|
+
if (limit < 1 || limit > 100) {
|
|
214
|
+
throw new CliValidationError("--limit must be between 1 and 100.", void 0, "limit");
|
|
215
|
+
}
|
|
216
|
+
const side = options.side ? validateSide(options.side) : void 0;
|
|
217
|
+
const outcomeIndex = options.outcome ? parseOutcomeIndex(options.outcome) : void 0;
|
|
218
|
+
let response;
|
|
219
|
+
try {
|
|
220
|
+
const { client } = await buildClient({ requireAuth: true, globals });
|
|
221
|
+
response = await client.markets.predictions(marketId, {
|
|
222
|
+
limit,
|
|
223
|
+
...side === void 0 ? {} : { side },
|
|
224
|
+
...outcomeIndex === void 0 ? {} : { outcomeIndex },
|
|
225
|
+
...options.cursor === void 0 ? {} : { cursor: options.cursor }
|
|
226
|
+
});
|
|
227
|
+
if (options.ndjson) {
|
|
228
|
+
for await (const prediction of response) {
|
|
229
|
+
writeNdjson(prediction);
|
|
230
|
+
}
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
if (options.all) {
|
|
234
|
+
const collected = [];
|
|
235
|
+
for await (const prediction of response) collected.push(prediction);
|
|
236
|
+
if (globals.json) {
|
|
237
|
+
printJson({
|
|
238
|
+
data: collected,
|
|
239
|
+
pagination: { hasMore: false, cursor: null },
|
|
240
|
+
count: collected.length
|
|
241
|
+
});
|
|
242
|
+
} else {
|
|
243
|
+
renderTable2(collected);
|
|
244
|
+
}
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
} catch (cause) {
|
|
248
|
+
throw toCliError(cause);
|
|
249
|
+
}
|
|
250
|
+
if (globals.json) {
|
|
251
|
+
printJson({
|
|
252
|
+
data: response.data,
|
|
253
|
+
pagination: response.pagination,
|
|
254
|
+
count: response.data.length
|
|
255
|
+
});
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
if (response.data.length === 0) {
|
|
259
|
+
log.info("No predictions matched the filter.");
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
renderTable2(response.data);
|
|
263
|
+
if (response.pagination.hasMore && response.pagination.cursor) {
|
|
264
|
+
log.detail("Next page", `--cursor ${response.pagination.cursor}`);
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
function renderTable2(predictions) {
|
|
268
|
+
const table = createTable(["Time", "Side", "Out#", "Amount", "Price", "Tx"]);
|
|
269
|
+
for (const p of predictions) {
|
|
270
|
+
const amount = p.side === "buy" ? p.usdcIn ?? "-" : p.tokensIn ?? "-";
|
|
271
|
+
table.push([
|
|
272
|
+
formatDate(p.timestamp),
|
|
273
|
+
p.side,
|
|
274
|
+
String(p.outcomeIndex),
|
|
275
|
+
amount,
|
|
276
|
+
p.price,
|
|
277
|
+
shortId(p.transactionHash)
|
|
278
|
+
]);
|
|
279
|
+
}
|
|
280
|
+
print(table.toString());
|
|
281
|
+
}
|
|
282
|
+
function validateSide(value) {
|
|
283
|
+
const lower = value.toLowerCase();
|
|
284
|
+
if (lower !== "buy" && lower !== "sell") {
|
|
285
|
+
throw new CliValidationError(`Unknown --side "${value}".`, "Allowed: buy, sell.", "side");
|
|
286
|
+
}
|
|
287
|
+
return lower;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// src/commands/markets/index.ts
|
|
291
|
+
var marketsCommand = new Command4("markets").description("List and inspect prediction markets.").addCommand(listMarketsCommand).addCommand(getMarketCommand).addCommand(predictionsCommand);
|
|
292
|
+
export {
|
|
293
|
+
marketsCommand
|
|
294
|
+
};
|
|
295
|
+
//# sourceMappingURL=markets-C37JZDPE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/markets/index.ts","../src/commands/markets/get.ts","../src/commands/markets/list.ts","../src/commands/markets/predictions.ts"],"sourcesContent":["/**\n * `kash markets` — read-only market queries.\n *\n * Subcommands: `list`, `get`, `predictions`. All require an API key\n * with `markets:read` scope (granted by default on every tier). Quotes\n * are a separate command group (`kash quote buy|sell`) under the\n * `markets:quote` scope, split so customers can throttle RPC-heavy\n * quote traffic independently from cheap market reads.\n */\n\nimport { Command } from 'commander';\n\nimport { getMarketCommand } from './get.js';\nimport { listMarketsCommand } from './list.js';\nimport { predictionsCommand } from './predictions.js';\n\nexport const marketsCommand = new Command('markets')\n .description('List and inspect prediction markets.')\n .addCommand(listMarketsCommand)\n .addCommand(getMarketCommand)\n .addCommand(predictionsCommand);\n","/**\n * `kash markets get <id>` — fetch a single market.\n */\n\nimport { Command } from 'commander';\n\nimport { toCliError } from '../../errors.js';\nimport { buildClient } from '../../utils/client.js';\nimport {\n colorStatus,\n createTable,\n formatAddress,\n formatDate,\n formatProbability,\n} from '../../utils/formatting.js';\nimport { readGlobals } from '../../utils/global-options.js';\nimport { print, printJson, style } from '../../utils/output.js';\n\nexport const getMarketCommand = new Command('get')\n .description('Fetch a single market by id.')\n .argument('<id>', 'market UUID')\n .addHelpText(\n 'after',\n `\nExamples:\n $ kash markets get 9f0b...\n $ kash markets get 9f0b... --json | jq '.outcomes'\n $ kash markets get 9f0b... --json --quiet | jq -r '.outcomes[].label' # agent shape\n $ kash markets get 9f0b... --fields id,status,resolvedOutcomeIndex --json --quiet\n`\n )\n .action(async (id: string, _opts, cmd: Command) => {\n const globals = readGlobals(cmd);\n let market;\n try {\n const { client } = await buildClient({ requireAuth: true, globals });\n market = await client.markets.get(id);\n } catch (cause) {\n throw toCliError(cause);\n }\n\n if (globals.json) {\n printJson(market);\n return;\n }\n\n print('');\n print(`${style.bold(market.title ?? '(untitled)')}`);\n print(` ${style.dim('ID ')} ${market.id}`);\n print(` ${style.dim('Contract ')} ${formatAddress(market.contractAddress)}`);\n print(` ${style.dim('Chain ')} ${String(market.chainId)}`);\n print(` ${style.dim('Status ')} ${colorStatus(market.status ?? 'UNKNOWN')}`);\n print(` ${style.dim('Outcomes ')} ${String(market.outcomeCount)}`);\n print(` ${style.dim('Created ')} ${formatDate(market.createdAt)}`);\n if (market.expiresAt) {\n print(` ${style.dim('Expires ')} ${formatDate(market.expiresAt)}`);\n }\n if (market.resolvedAt) {\n print(` ${style.dim('Resolved ')} ${formatDate(market.resolvedAt)}`);\n }\n if (market.description) {\n print('');\n print(market.description);\n }\n\n print('');\n const table = createTable(['#', 'Outcome', 'Probability']);\n for (const outcome of market.outcomes) {\n table.push([String(outcome.index), outcome.label, formatProbability(outcome.probability)]);\n }\n print(table.toString());\n });\n","/**\n * `kash markets list` — page through markets.\n *\n * Default human output is a table of the first page. `--all` walks\n * the SDK's auto-paginator and prints every market — useful for\n * exporting to JSON. Status is uppercased before sending so users\n * don't have to remember the canonical casing.\n */\n\nimport { Command } from 'commander';\n\nimport { CliValidationError, toCliError } from '../../errors.js';\nimport { buildClient } from '../../utils/client.js';\nimport {\n colorStatus,\n createTable,\n formatProbability,\n shortId,\n truncate,\n} from '../../utils/formatting.js';\nimport { parsePositiveInt, readGlobals } from '../../utils/global-options.js';\nimport { log, print, printJson, writeNdjson } from '../../utils/output.js';\n\nimport type { MarketResource, MarketStatus } from '@kashdao/sdk';\n\ntype ListOptions = {\n status?: string;\n limit?: string;\n cursor?: string;\n all?: boolean;\n ndjson?: boolean;\n};\n\nconst ALLOWED_STATUSES: ReadonlySet<MarketStatus> = new Set(['UNSEEDED', 'ACTIVE', 'RESOLVED']);\n\nexport const listMarketsCommand = new Command('list')\n .description('List markets.')\n .option('-s, --status <status>', 'filter by status (UNSEEDED | ACTIVE | RESOLVED)')\n .option('-l, --limit <n>', 'page size (1-100)', '20')\n .option('-c, --cursor <cursor>', 'pagination cursor returned by a previous call')\n .option('-a, --all', 'walk every page (use with --json for export)')\n .option(\n '--ndjson',\n 'stream results as newline-delimited JSON (one record per line); implies --all'\n )\n .addHelpText(\n 'after',\n `\nExamples:\n $ kash markets list --status ACTIVE\n $ kash markets list --json --quiet | jq '.data[].id'\n $ kash markets list --ndjson | while read -r line; do echo \"$line\" | jq -r .id; done\n $ kash markets list --all --json --quiet > markets.json\n\nNotes:\n --ndjson emits one JSON record per line. Consumers must read\n line-by-line (\\`while read -r\\`, \\`jq -c\\`, \\`split('\\n')\\`) — DO NOT\n buffer-then-parse, as the stream may run for arbitrarily many pages.\n`\n )\n .action(async (options: ListOptions, cmd: Command) => {\n const globals = readGlobals(cmd);\n\n const limit = options.limit === undefined ? 20 : parsePositiveInt(options.limit, 'limit');\n if (limit < 1 || limit > 100) {\n throw new CliValidationError('--limit must be between 1 and 100.', undefined, 'limit');\n }\n\n const status = options.status ? normaliseStatus(options.status) : undefined;\n\n let response;\n try {\n const { client } = await buildClient({ requireAuth: true, globals });\n response = await client.markets.list({\n limit,\n ...(status === undefined ? {} : { status }),\n ...(options.cursor === undefined ? {} : { cursor: options.cursor }),\n });\n\n if (options.ndjson) {\n // Stream every record as one line of NDJSON to stdout. Avoids\n // buffering the full result set — the agent reads as we go.\n for await (const market of response) {\n writeNdjson(market);\n }\n return;\n }\n\n if (options.all) {\n const collected: MarketResource[] = [];\n for await (const market of response) collected.push(market);\n if (globals.json) {\n // Canonical list-envelope shape: `{data, pagination, count}`.\n // After walking every page, `pagination.hasMore` is false\n // and `cursor` is null — same fields, terminal values.\n // Agents pin to this single shape across both modes.\n printJson({\n data: collected,\n pagination: { hasMore: false, cursor: null },\n count: collected.length,\n });\n } else {\n renderTable(collected);\n }\n return;\n }\n } catch (cause) {\n throw toCliError(cause);\n }\n\n if (globals.json) {\n printJson({\n data: response.data,\n pagination: response.pagination,\n count: response.data.length,\n });\n return;\n }\n\n if (response.data.length === 0) {\n log.info('No markets matched the filter.');\n return;\n }\n renderTable(response.data);\n\n if (response.pagination.hasMore && response.pagination.cursor) {\n log.detail('Next page', `--cursor ${response.pagination.cursor}`);\n }\n });\n\nfunction renderTable(markets: readonly MarketResource[]): void {\n const table = createTable(['ID', 'Title', 'Status', 'Outcomes', 'Top outcome', 'Created']);\n for (const market of markets) {\n const outcomes = market.outcomes;\n const top = outcomes.reduce<(typeof outcomes)[number] | undefined>((acc, current) => {\n if (acc === undefined) return current;\n return current.probability > acc.probability ? current : acc;\n }, undefined);\n table.push([\n shortId(market.id),\n truncate(market.title ?? '(untitled)', 42),\n colorStatus(market.status ?? 'UNKNOWN'),\n String(market.outcomeCount),\n top ? `${truncate(top.label, 18)} (${formatProbability(top.probability)})` : '-',\n market.createdAt.slice(0, 10),\n ]);\n }\n print(table.toString());\n}\n\nfunction normaliseStatus(value: string): MarketStatus {\n const upper = value.toUpperCase() as MarketStatus;\n if (!ALLOWED_STATUSES.has(upper)) {\n throw new CliValidationError(\n `Unknown market status \"${value}\".`,\n 'Allowed: UNSEEDED, ACTIVE, RESOLVED.'\n );\n }\n return upper;\n}\n","/**\n * `kash markets predictions <market-id>` — paginated feed of recent\n * trades against a single market. Wraps `kash.markets.predictions`.\n *\n * Requires API key with `markets:read` scope (granted by default on every\n * tier). Pagination shape mirrors `kash markets list` and `kash trade list`:\n * default first-page render, `--all` to walk every page, `--ndjson`\n * to stream NDJSON one-record-per-line for agents.\n */\n\nimport { Command } from 'commander';\n\nimport { CliValidationError, toCliError } from '../../errors.js';\nimport { buildClient } from '../../utils/client.js';\nimport { createTable, formatDate, shortId } from '../../utils/formatting.js';\nimport { parsePositiveInt, readGlobals } from '../../utils/global-options.js';\nimport { log, print, printJson, writeNdjson } from '../../utils/output.js';\nimport { parseOutcomeIndex } from '../../utils/trade-input.js';\n\nimport type { PredictionResource } from '@kashdao/sdk';\n\ntype PredictionsOptions = {\n side?: string;\n outcome?: string;\n limit?: string;\n cursor?: string;\n all?: boolean;\n ndjson?: boolean;\n};\n\nexport const predictionsCommand = new Command('predictions')\n .description('Recent trades against a market (cursor-paginated, newest first).')\n .argument('<marketId>', 'market UUID')\n .option('-s, --side <side>', 'filter to a single side: buy | sell')\n .option('-o, --outcome <index>', 'filter to a single outcome index (0-based)')\n .option('-l, --limit <n>', 'page size (1-100)', '50')\n .option('-c, --cursor <cursor>', 'pagination cursor returned by a previous call')\n .option('-a, --all', 'walk every page (use with --json for export)')\n .option(\n '--ndjson',\n 'stream results as newline-delimited JSON (one record per line); implies --all'\n )\n .addHelpText(\n 'after',\n `\nExamples:\n $ kash markets predictions 9f0b...\n $ kash markets predictions 9f0b... --side buy --outcome 0\n $ kash markets predictions 9f0b... --json --quiet | jq -r '.data[].transactionHash'\n $ kash markets predictions 9f0b... --ndjson | head -100\n $ kash markets predictions 9f0b... --all --json --quiet > history.json\n`\n )\n .action(async (marketId: string, options: PredictionsOptions, cmd: Command) => {\n const globals = readGlobals(cmd);\n\n const limit = options.limit === undefined ? 50 : parsePositiveInt(options.limit, 'limit');\n if (limit < 1 || limit > 100) {\n throw new CliValidationError('--limit must be between 1 and 100.', undefined, 'limit');\n }\n\n const side = options.side ? validateSide(options.side) : undefined;\n const outcomeIndex = options.outcome ? parseOutcomeIndex(options.outcome) : undefined;\n\n let response;\n try {\n // Requires API key with `markets:read` scope (granted by default\n // on every tier). Fail fast at build time if no key is configured\n // rather than waiting for the server's 401.\n const { client } = await buildClient({ requireAuth: true, globals });\n response = await client.markets.predictions(marketId, {\n limit,\n ...(side === undefined ? {} : { side }),\n ...(outcomeIndex === undefined ? {} : { outcomeIndex }),\n ...(options.cursor === undefined ? {} : { cursor: options.cursor }),\n });\n\n if (options.ndjson) {\n for await (const prediction of response) {\n writeNdjson(prediction);\n }\n return;\n }\n\n if (options.all) {\n const collected: PredictionResource[] = [];\n for await (const prediction of response) collected.push(prediction);\n if (globals.json) {\n // Canonical `{data, pagination, count}` envelope — matches\n // every other list-shaped command (`markets list`,\n // `trade list`, `webhooks list`). After walking every\n // page, `pagination.hasMore` is false and `cursor` is null.\n printJson({\n data: collected,\n pagination: { hasMore: false, cursor: null },\n count: collected.length,\n });\n } else {\n renderTable(collected);\n }\n return;\n }\n } catch (cause) {\n throw toCliError(cause);\n }\n\n if (globals.json) {\n printJson({\n data: response.data,\n pagination: response.pagination,\n count: response.data.length,\n });\n return;\n }\n\n if (response.data.length === 0) {\n log.info('No predictions matched the filter.');\n return;\n }\n renderTable(response.data);\n\n if (response.pagination.hasMore && response.pagination.cursor) {\n log.detail('Next page', `--cursor ${response.pagination.cursor}`);\n }\n });\n\nfunction renderTable(predictions: readonly PredictionResource[]): void {\n const table = createTable(['Time', 'Side', 'Out#', 'Amount', 'Price', 'Tx']);\n for (const p of predictions) {\n const amount = p.side === 'buy' ? (p.usdcIn ?? '-') : (p.tokensIn ?? '-');\n table.push([\n formatDate(p.timestamp),\n p.side,\n String(p.outcomeIndex),\n amount,\n p.price,\n shortId(p.transactionHash),\n ]);\n }\n print(table.toString());\n}\n\nfunction validateSide(value: string): 'buy' | 'sell' {\n const lower = value.toLowerCase();\n if (lower !== 'buy' && lower !== 'sell') {\n throw new CliValidationError(`Unknown --side \"${value}\".`, 'Allowed: buy, sell.', 'side');\n }\n return lower;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,SAAS,WAAAA,gBAAe;;;ACNxB,SAAS,eAAe;AAcjB,IAAM,mBAAmB,IAAI,QAAQ,KAAK,EAC9C,YAAY,8BAA8B,EAC1C,SAAS,QAAQ,aAAa,EAC9B;AAAA,EACC;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOF,EACC,OAAO,OAAO,IAAY,OAAO,QAAiB;AACjD,QAAM,UAAU,YAAY,GAAG;AAC/B,MAAI;AACJ,MAAI;AACF,UAAM,EAAE,OAAO,IAAI,MAAM,YAAY,EAAE,aAAa,MAAM,QAAQ,CAAC;AACnE,aAAS,MAAM,OAAO,QAAQ,IAAI,EAAE;AAAA,EACtC,SAAS,OAAO;AACd,UAAM,WAAW,KAAK;AAAA,EACxB;AAEA,MAAI,QAAQ,MAAM;AAChB,cAAU,MAAM;AAChB;AAAA,EACF;AAE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AAS,aAAa,OAA+B;AACnD,QAAM,QAAQ,MAAM,YAAY;AAChC,MAAI,UAAU,SAAS,UAAU,QAAQ;AACvC,UAAM,IAAI,mBAAmB,mBAAmB,KAAK,MAAM,uBAAuB,MAAM;AAAA,EAC1F;AACA,SAAO;AACT;;;AHpIO,IAAM,iBAAiB,IAAIC,SAAQ,SAAS,EAChD,YAAY,sCAAsC,EAClD,WAAW,kBAAkB,EAC7B,WAAW,gBAAgB,EAC3B,WAAW,kBAAkB;","names":["Command","Command","Command","Command","Command","renderTable","Command"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
configureOutput,
|
|
4
|
+
isQuiet,
|
|
5
|
+
log,
|
|
6
|
+
print,
|
|
7
|
+
printJson,
|
|
8
|
+
style,
|
|
9
|
+
writeNdjson
|
|
10
|
+
} from "./chunk-VIADBYFY.js";
|
|
11
|
+
import "./chunk-MIXOZU2S.js";
|
|
12
|
+
import "./chunk-UZNSYATZ.js";
|
|
13
|
+
export {
|
|
14
|
+
configureOutput,
|
|
15
|
+
isQuiet,
|
|
16
|
+
log,
|
|
17
|
+
print,
|
|
18
|
+
printJson,
|
|
19
|
+
style,
|
|
20
|
+
writeNdjson
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=output-VCBZ3FM7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
createTable,
|
|
4
|
+
formatAddress,
|
|
5
|
+
formatDate,
|
|
6
|
+
formatUsdcAtomic,
|
|
7
|
+
formatWad,
|
|
8
|
+
shortId
|
|
9
|
+
} from "./chunk-BRK7KJ4O.js";
|
|
10
|
+
import {
|
|
11
|
+
buildClient
|
|
12
|
+
} from "./chunk-QJMF73M5.js";
|
|
13
|
+
import "./chunk-KMBMQIZ7.js";
|
|
14
|
+
import "./chunk-YHCG2SUC.js";
|
|
15
|
+
import "./chunk-BN2CUM42.js";
|
|
16
|
+
import {
|
|
17
|
+
readGlobals
|
|
18
|
+
} from "./chunk-LBIRQHX5.js";
|
|
19
|
+
import {
|
|
20
|
+
log,
|
|
21
|
+
print,
|
|
22
|
+
printJson,
|
|
23
|
+
style
|
|
24
|
+
} from "./chunk-VIADBYFY.js";
|
|
25
|
+
import "./chunk-MIXOZU2S.js";
|
|
26
|
+
import {
|
|
27
|
+
toCliError
|
|
28
|
+
} from "./chunk-UZNSYATZ.js";
|
|
29
|
+
|
|
30
|
+
// src/commands/portfolio/index.ts
|
|
31
|
+
import { Command as Command3 } from "commander";
|
|
32
|
+
|
|
33
|
+
// src/commands/portfolio/positions.ts
|
|
34
|
+
import { Command } from "commander";
|
|
35
|
+
var positionsCommand = new Command("positions").description("List active positions.").option("-m, --market <id>", "filter by market id").addHelpText(
|
|
36
|
+
"after",
|
|
37
|
+
`
|
|
38
|
+
Examples:
|
|
39
|
+
$ kash portfolio positions
|
|
40
|
+
$ kash portfolio positions --market 9f0b...
|
|
41
|
+
$ kash portfolio positions --json --quiet | jq '.data[] | select(.shares != "0")'
|
|
42
|
+
`
|
|
43
|
+
).action(async (options, cmd) => {
|
|
44
|
+
const globals = readGlobals(cmd);
|
|
45
|
+
let positions;
|
|
46
|
+
try {
|
|
47
|
+
const { client } = await buildClient({ requireAuth: true, globals });
|
|
48
|
+
positions = await client.portfolio.positions(
|
|
49
|
+
options.market === void 0 ? {} : { marketId: options.market }
|
|
50
|
+
);
|
|
51
|
+
} catch (cause) {
|
|
52
|
+
throw toCliError(cause);
|
|
53
|
+
}
|
|
54
|
+
if (globals.json) {
|
|
55
|
+
printJson({
|
|
56
|
+
data: positions,
|
|
57
|
+
pagination: { hasMore: false, cursor: null },
|
|
58
|
+
count: positions.length
|
|
59
|
+
});
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (positions.length === 0) {
|
|
63
|
+
log.info("No positions found.");
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const table = createTable(["Market", "Out#", "Shares (WAD)", "Cost basis", "Trades", "Last"]);
|
|
67
|
+
for (const p of positions) {
|
|
68
|
+
table.push([
|
|
69
|
+
shortId(p.marketId),
|
|
70
|
+
String(p.outcomeIndex),
|
|
71
|
+
formatWad(p.shares),
|
|
72
|
+
formatUsdcAtomic(p.costBasisAtomic),
|
|
73
|
+
String(p.tradeCount),
|
|
74
|
+
formatDate(p.lastTradeAt)
|
|
75
|
+
]);
|
|
76
|
+
}
|
|
77
|
+
print(table.toString());
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// src/commands/portfolio/show.ts
|
|
81
|
+
import { Command as Command2 } from "commander";
|
|
82
|
+
var showPortfolioCommand = new Command2("show").description("Show the aggregate portfolio summary.").addHelpText(
|
|
83
|
+
"after",
|
|
84
|
+
`
|
|
85
|
+
Examples:
|
|
86
|
+
$ kash portfolio show
|
|
87
|
+
$ kash portfolio show --json --quiet | jq -r '.smartAccountAddress'
|
|
88
|
+
`
|
|
89
|
+
).action(async (_opts, cmd) => {
|
|
90
|
+
const globals = readGlobals(cmd);
|
|
91
|
+
let portfolio;
|
|
92
|
+
try {
|
|
93
|
+
const { client } = await buildClient({ requireAuth: true, globals });
|
|
94
|
+
portfolio = await client.portfolio.get();
|
|
95
|
+
} catch (cause) {
|
|
96
|
+
throw toCliError(cause);
|
|
97
|
+
}
|
|
98
|
+
if (globals.json) {
|
|
99
|
+
printJson(portfolio);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
print("");
|
|
103
|
+
print(
|
|
104
|
+
` ${style.dim("Smart account ")} ${formatAddress(portfolio.smartAccountAddress, 10, 8)}`
|
|
105
|
+
);
|
|
106
|
+
print(` ${style.dim("Active ")} ${String(portfolio.activePositions)} positions`);
|
|
107
|
+
print(` ${style.dim("Cost basis ")} ${formatUsdcAtomic(portfolio.totalCostBasisAtomic)}`);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// src/commands/portfolio/index.ts
|
|
111
|
+
var portfolioCommand = new Command3("portfolio").description("View your portfolio.").addCommand(showPortfolioCommand).addCommand(positionsCommand);
|
|
112
|
+
export {
|
|
113
|
+
portfolioCommand
|
|
114
|
+
};
|
|
115
|
+
//# sourceMappingURL=portfolio-2AEPIJIG.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/portfolio/index.ts","../src/commands/portfolio/positions.ts","../src/commands/portfolio/show.ts"],"sourcesContent":["/**\n * `kash portfolio` — read-only snapshot of the authenticating user's\n * positions and aggregate cost basis.\n */\n\nimport { Command } from 'commander';\n\nimport { positionsCommand } from './positions.js';\nimport { showPortfolioCommand } from './show.js';\n\nexport const portfolioCommand = new Command('portfolio')\n .description('View your portfolio.')\n .addCommand(showPortfolioCommand)\n .addCommand(positionsCommand);\n","/**\n * `kash portfolio positions` — per-position breakdown for the\n * authenticating user's smart account.\n */\n\nimport { Command } from 'commander';\n\nimport { toCliError } from '../../errors.js';\nimport { buildClient } from '../../utils/client.js';\nimport {\n createTable,\n formatDate,\n formatUsdcAtomic,\n formatWad,\n shortId,\n} from '../../utils/formatting.js';\nimport { readGlobals } from '../../utils/global-options.js';\nimport { log, print, printJson } from '../../utils/output.js';\n\ntype PositionsOptions = {\n market?: string;\n};\n\nexport const positionsCommand = new Command('positions')\n .description('List active positions.')\n .option('-m, --market <id>', 'filter by market id')\n .addHelpText(\n 'after',\n `\nExamples:\n $ kash portfolio positions\n $ kash portfolio positions --market 9f0b...\n $ kash portfolio positions --json --quiet | jq '.data[] | select(.shares != \"0\")'\n`\n )\n .action(async (options: PositionsOptions, cmd: Command) => {\n const globals = readGlobals(cmd);\n let positions;\n try {\n const { client } = await buildClient({ requireAuth: true, globals });\n positions = await client.portfolio.positions(\n options.market === undefined ? {} : { marketId: options.market }\n );\n } catch (cause) {\n throw toCliError(cause);\n }\n\n if (globals.json) {\n // Canonical list-envelope shape `{data, pagination, count}` —\n // matches `markets list / trade list / webhooks list /\n // markets predictions`. Positions is non-paginated server-side\n // (full set returned in one call), so pagination always carries\n // terminal values; the field is present for shape parity so\n // agents can pin one schema across every list-shaped command.\n printJson({\n data: positions,\n pagination: { hasMore: false, cursor: null },\n count: positions.length,\n });\n return;\n }\n\n if (positions.length === 0) {\n log.info('No positions found.');\n return;\n }\n\n const table = createTable(['Market', 'Out#', 'Shares (WAD)', 'Cost basis', 'Trades', 'Last']);\n for (const p of positions) {\n table.push([\n shortId(p.marketId),\n String(p.outcomeIndex),\n formatWad(p.shares),\n formatUsdcAtomic(p.costBasisAtomic),\n String(p.tradeCount),\n formatDate(p.lastTradeAt),\n ]);\n }\n print(table.toString());\n });\n","/**\n * `kash portfolio show` — aggregate summary for the authenticating\n * user's smart account.\n */\n\nimport { Command } from 'commander';\n\nimport { toCliError } from '../../errors.js';\nimport { buildClient } from '../../utils/client.js';\nimport { formatAddress, formatUsdcAtomic } from '../../utils/formatting.js';\nimport { readGlobals } from '../../utils/global-options.js';\nimport { print, printJson, style } from '../../utils/output.js';\n\nexport const showPortfolioCommand = new Command('show')\n .description('Show the aggregate portfolio summary.')\n .addHelpText(\n 'after',\n `\nExamples:\n $ kash portfolio show\n $ kash portfolio show --json --quiet | jq -r '.smartAccountAddress'\n`\n )\n .action(async (_opts, cmd: Command) => {\n const globals = readGlobals(cmd);\n let portfolio;\n try {\n const { client } = await buildClient({ requireAuth: true, globals });\n portfolio = await client.portfolio.get();\n } catch (cause) {\n throw toCliError(cause);\n }\n\n if (globals.json) {\n printJson(portfolio);\n return;\n }\n\n print('');\n print(\n ` ${style.dim('Smart account ')} ${formatAddress(portfolio.smartAccountAddress, 10, 8)}`\n );\n print(` ${style.dim('Active ')} ${String(portfolio.activePositions)} positions`);\n print(` ${style.dim('Cost basis ')} ${formatUsdcAtomic(portfolio.totalCostBasisAtomic)}`);\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;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