agentex-creator-sdk 1.0.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 +36 -0
- package/LICENSE +21 -0
- package/README.md +195 -0
- package/dist/packages/contracts/src/deployer-investigation.d.ts +1015 -0
- package/dist/packages/contracts/src/deployer-investigation.js +101 -0
- package/dist/packages/contracts/src/index.d.ts +1701 -0
- package/dist/packages/contracts/src/index.js +380 -0
- package/dist/packages/contracts/src/indexed-activity.d.ts +684 -0
- package/dist/packages/contracts/src/indexed-activity.js +71 -0
- package/dist/packages/contracts/src/indexed-agents.d.ts +299 -0
- package/dist/packages/contracts/src/indexed-agents.js +131 -0
- package/dist/packages/contracts/src/inspection.d.ts +906 -0
- package/dist/packages/contracts/src/inspection.js +114 -0
- package/dist/packages/contracts/src/kinds.d.ts +5398 -0
- package/dist/packages/contracts/src/kinds.js +156 -0
- package/dist/packages/contracts/src/report-presentation.d.ts +346 -0
- package/dist/packages/contracts/src/report-presentation.js +120 -0
- package/dist/packages/contracts/src/solana-inspection.d.ts +451 -0
- package/dist/packages/contracts/src/solana-inspection.js +94 -0
- package/dist/packages/contracts/src/token-market.d.ts +193 -0
- package/dist/packages/contracts/src/token-market.js +335 -0
- package/dist/packages/contracts/src/wallet-analysis.d.ts +866 -0
- package/dist/packages/contracts/src/wallet-analysis.js +89 -0
- package/dist/packages/contracts/src/watchtower.d.ts +1141 -0
- package/dist/packages/contracts/src/watchtower.js +196 -0
- package/dist/packages/contracts/src/workflow.d.ts +1568 -0
- package/dist/packages/contracts/src/workflow.js +651 -0
- package/dist/packages/inspector/src/decode.d.ts +23 -0
- package/dist/packages/inspector/src/decode.js +150 -0
- package/dist/packages/inspector/src/scope.d.ts +87 -0
- package/dist/packages/inspector/src/scope.js +64 -0
- package/dist/packages/model/src/analysis.d.ts +149 -0
- package/dist/packages/model/src/analysis.js +387 -0
- package/dist/packages/model/src/pricing.d.ts +38 -0
- package/dist/packages/model/src/pricing.js +49 -0
- package/dist/packages/model/src/retry.d.ts +20 -0
- package/dist/packages/model/src/retry.js +31 -0
- package/dist/packages/model/src/schema.d.ts +10 -0
- package/dist/packages/model/src/schema.js +51 -0
- package/dist/packages/model/src/summary.d.ts +91 -0
- package/dist/packages/model/src/summary.js +177 -0
- package/dist/packages/model/src/types.d.ts +81 -0
- package/dist/packages/model/src/types.js +19 -0
- package/dist/packages/monitoring/src/delivery.d.ts +32 -0
- package/dist/packages/monitoring/src/delivery.js +53 -0
- package/dist/packages/providers/src/chain-transport.d.ts +42 -0
- package/dist/packages/providers/src/chain-transport.js +57 -0
- package/dist/packages/providers/src/coverage.d.ts +105 -0
- package/dist/packages/providers/src/coverage.js +260 -0
- package/dist/packages/providers/src/health.d.ts +273 -0
- package/dist/packages/providers/src/health.js +505 -0
- package/dist/packages/providers/src/keyed.d.ts +96 -0
- package/dist/packages/providers/src/keyed.js +240 -0
- package/dist/packages/providers/src/snapshot.d.ts +61 -0
- package/dist/packages/providers/src/snapshot.js +77 -0
- package/dist/packages/publication/src/fixtures.d.ts +45 -0
- package/dist/packages/publication/src/fixtures.js +350 -0
- package/dist/packages/research/src/index.d.ts +188 -0
- package/dist/packages/research/src/index.js +829 -0
- package/dist/packages/runtime/src/checkpoints.d.ts +65 -0
- package/dist/packages/runtime/src/checkpoints.js +214 -0
- package/dist/packages/runtime/src/policy.d.ts +57 -0
- package/dist/packages/runtime/src/policy.js +296 -0
- package/dist/packages/sdk/src/bin/agentex-buyer.d.ts +2 -0
- package/dist/packages/sdk/src/bin/agentex-buyer.js +4 -0
- package/dist/packages/sdk/src/bin/agentex.d.ts +2 -0
- package/dist/packages/sdk/src/bin/agentex.js +3 -0
- package/dist/packages/sdk/src/buyer-cli.d.ts +10 -0
- package/dist/packages/sdk/src/buyer-cli.js +210 -0
- package/dist/packages/sdk/src/buyer.d.ts +534 -0
- package/dist/packages/sdk/src/buyer.js +441 -0
- package/dist/packages/sdk/src/cli.d.ts +14 -0
- package/dist/packages/sdk/src/cli.js +149 -0
- package/dist/packages/sdk/src/errors.d.ts +31 -0
- package/dist/packages/sdk/src/errors.js +24 -0
- package/dist/packages/sdk/src/index.d.ts +236 -0
- package/dist/packages/sdk/src/index.js +150 -0
- package/dist/packages/sdk/src/local.d.ts +11 -0
- package/dist/packages/sdk/src/local.js +110 -0
- package/dist/packages/sdk/src/rails.d.ts +59 -0
- package/dist/packages/sdk/src/rails.js +96 -0
- package/dist/packages/sdk/src/report.d.ts +121 -0
- package/dist/packages/sdk/src/report.js +114 -0
- package/dist/packages/sdk/src/version.d.ts +2 -0
- package/dist/packages/sdk/src/version.js +2 -0
- package/dist/packages/watchtower/src/index.d.ts +150 -0
- package/dist/packages/watchtower/src/index.js +786 -0
- package/dist/packages/workflow/src/registry.d.ts +61 -0
- package/dist/packages/workflow/src/registry.js +76 -0
- package/examples/README.md +34 -0
- package/examples/cli-usage.sh +30 -0
- package/examples/fixtures/base-weth-input.json +4 -0
- package/examples/focused-researcher.json +127 -0
- package/examples/pay-with-eth-robinhood.mts +37 -0
- package/examples/pay-with-usdc.mts +41 -0
- package/examples/quickstart.mts +73 -0
- package/package.json +50 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const BUYER_HELP = "AGENTEX buyer CLI 1.0.0 (reads AGENTEX_API_KEY and never prints it)\n agentex-buyer key\n agentex-buyer catalog [--q TEXT] [--chain solana|ethereum|base|robinhood] [--topic TOPIC] [--asset sol|usdc|eth]\n [--sort newest|name|price] [--limit N] [--cursor CURSOR]\n agentex-buyer agent --listing LISTING_ID\n agentex-buyer quote --listing LISTING_ID INPUT [--result-policy complete_only|canonical_metadata]\n agentex-buyer accept --quote QUOTE_ID --contract-hash HASH --idempotency-key KEY --confirm\n agentex-buyer research --listing LISTING_ID INPUT --max-debit AMOUNT --confirm [--idempotency-key KEY] [--timeout SECONDS]\n agentex-buyer status --run RUN_ID [--wait] [--timeout SECONDS]\n agentex-buyer report --run RUN_ID\n agentex-buyer result --run RUN_ID [--out result.json]\n agentex-buyer billing --run RUN_ID\n agentex-buyer receipt --run RUN_ID [--wait] [--timeout SECONDS]\n agentex-buyer cancel --run RUN_ID\n agentex-buyer monitor create --file monitor.json | list | get --monitor ID | stop --monitor ID | notifications | ack --notification ID\n agentex-buyer version\n\nINPUT is one of: --chain CHAIN --value NAME=VALUE ... (research workflows, for example --chain solana --value mint=<mint>),\n --chain CHAIN --address ADDRESS (Token Researcher), or --input input.json (any agent's exact input object).\nCommon: [--api ORIGIN] (default AGENTEX_API_ORIGIN or https://agentex.sh),\n [--asset sol|usdc|eth|ASSET_ID] (default AGENTEX_ASSET, else the key's own asset; SOL is solana:mainnet-beta/native).\n --profile sim|local_custody|solana_sol|solana_usdc (or AGENTEX_PROFILE) is still accepted; --asset is preferred.\nA key pays in one asset: SOL or USDC keys belong to Solana accounts, ETH (Robinhood Chain) keys to EVM accounts.\naccept and research spend under the key's budget: review the quote, pass --confirm, and reuse the same idempotency key to retry.\nresearch refuses a quote above --max-debit, given in the payment currency (for example --max-debit 0.02 for 0.02 SOL).\n";
|
|
2
|
+
export interface BuyerCliIO {
|
|
3
|
+
env: Record<string, string | undefined>;
|
|
4
|
+
stdout: (text: string) => void;
|
|
5
|
+
stderr: (text: string) => void;
|
|
6
|
+
fetch?: typeof fetch;
|
|
7
|
+
cwd?: string;
|
|
8
|
+
}
|
|
9
|
+
/** Runs one buyer subcommand and returns the process exit code. Output is JSON on stdout; errors are one line on stderr. */
|
|
10
|
+
export declare function runBuyerCli(argv: readonly string[], io: BuyerCliIO): Promise<number>;
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { parseArgs } from 'node:util';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { AgentexApiError, createBuyerClient, DEFAULT_API_ORIGIN, IdempotencyKeySchema, parseAmount, workflowInput } from './buyer.js';
|
|
4
|
+
import { readCreatorFile, writeCreatorFile } from './local.js';
|
|
5
|
+
import { SDK_VERSION } from './version.js';
|
|
6
|
+
export const BUYER_HELP = `AGENTEX buyer CLI ${SDK_VERSION} (reads AGENTEX_API_KEY and never prints it)
|
|
7
|
+
agentex-buyer key
|
|
8
|
+
agentex-buyer catalog [--q TEXT] [--chain solana|ethereum|base|robinhood] [--topic TOPIC] [--asset sol|usdc|eth]
|
|
9
|
+
[--sort newest|name|price] [--limit N] [--cursor CURSOR]
|
|
10
|
+
agentex-buyer agent --listing LISTING_ID
|
|
11
|
+
agentex-buyer quote --listing LISTING_ID INPUT [--result-policy complete_only|canonical_metadata]
|
|
12
|
+
agentex-buyer accept --quote QUOTE_ID --contract-hash HASH --idempotency-key KEY --confirm
|
|
13
|
+
agentex-buyer research --listing LISTING_ID INPUT --max-debit AMOUNT --confirm [--idempotency-key KEY] [--timeout SECONDS]
|
|
14
|
+
agentex-buyer status --run RUN_ID [--wait] [--timeout SECONDS]
|
|
15
|
+
agentex-buyer report --run RUN_ID
|
|
16
|
+
agentex-buyer result --run RUN_ID [--out result.json]
|
|
17
|
+
agentex-buyer billing --run RUN_ID
|
|
18
|
+
agentex-buyer receipt --run RUN_ID [--wait] [--timeout SECONDS]
|
|
19
|
+
agentex-buyer cancel --run RUN_ID
|
|
20
|
+
agentex-buyer monitor create --file monitor.json | list | get --monitor ID | stop --monitor ID | notifications | ack --notification ID
|
|
21
|
+
agentex-buyer version
|
|
22
|
+
|
|
23
|
+
INPUT is one of: --chain CHAIN --value NAME=VALUE ... (research workflows, for example --chain solana --value mint=<mint>),
|
|
24
|
+
--chain CHAIN --address ADDRESS (Token Researcher), or --input input.json (any agent's exact input object).
|
|
25
|
+
Common: [--api ORIGIN] (default AGENTEX_API_ORIGIN or ${DEFAULT_API_ORIGIN}),
|
|
26
|
+
[--asset sol|usdc|eth|ASSET_ID] (default AGENTEX_ASSET, else the key's own asset; SOL is solana:mainnet-beta/native).
|
|
27
|
+
--profile sim|local_custody|solana_sol|solana_usdc (or AGENTEX_PROFILE) is still accepted; --asset is preferred.
|
|
28
|
+
A key pays in one asset: SOL or USDC keys belong to Solana accounts, ETH (Robinhood Chain) keys to EVM accounts.
|
|
29
|
+
accept and research spend under the key's budget: review the quote, pass --confirm, and reuse the same idempotency key to retry.
|
|
30
|
+
research refuses a quote above --max-debit, given in the payment currency (for example --max-debit 0.02 for 0.02 SOL).
|
|
31
|
+
`;
|
|
32
|
+
const specifications = {
|
|
33
|
+
api: { type: 'string' }, profile: { type: 'string' }, asset: { type: 'string' }, listing: { type: 'string' }, chain: { type: 'string' }, address: { type: 'string' },
|
|
34
|
+
value: { type: 'string', multiple: true }, input: { type: 'string' }, 'result-policy': { type: 'string' }, quote: { type: 'string' }, 'contract-hash': { type: 'string' },
|
|
35
|
+
'idempotency-key': { type: 'string' }, confirm: { type: 'boolean' }, 'max-debit': { type: 'string' }, run: { type: 'string' }, wait: { type: 'boolean' }, timeout: { type: 'string' },
|
|
36
|
+
out: { type: 'string' }, monitor: { type: 'string' }, notification: { type: 'string' }, file: { type: 'string' }, q: { type: 'string' }, topic: { type: 'string' },
|
|
37
|
+
sort: { type: 'string' }, limit: { type: 'string' }, cursor: { type: 'string' }, help: { type: 'boolean' },
|
|
38
|
+
};
|
|
39
|
+
const common = ['api', 'profile', 'asset'];
|
|
40
|
+
const inputOptions = ['chain', 'address', 'value', 'input'];
|
|
41
|
+
const allowed = {
|
|
42
|
+
key: [], catalog: ['q', 'chain', 'topic', 'sort', 'limit', 'cursor'], agent: ['listing'], quote: ['listing', ...inputOptions, 'result-policy'],
|
|
43
|
+
accept: ['quote', 'contract-hash', 'idempotency-key', 'confirm'], research: ['listing', ...inputOptions, 'result-policy', 'max-debit', 'confirm', 'idempotency-key', 'timeout'],
|
|
44
|
+
status: ['run', 'wait', 'timeout'], report: ['run'], result: ['run', 'out'], billing: ['run'], receipt: ['run', 'wait', 'timeout'], cancel: ['run'],
|
|
45
|
+
'monitor create': ['file'], 'monitor list': [], 'monitor get': ['monitor'], 'monitor stop': ['monitor'], 'monitor notifications': [], 'monitor ack': ['notification'],
|
|
46
|
+
};
|
|
47
|
+
class CliUsageError extends Error {
|
|
48
|
+
}
|
|
49
|
+
const required = (value, name) => { if (!value)
|
|
50
|
+
throw new CliUsageError(`--${name} is required.`); return value; };
|
|
51
|
+
const scalar = (raw) => raw === 'true' ? true : raw === 'false' ? false : /^-?(0|[1-9][0-9]{0,14})$/.test(raw) ? Number(raw) : raw;
|
|
52
|
+
const seconds = (raw) => raw === undefined ? undefined : Number(z.string().regex(/^[1-9][0-9]{0,4}$/).parse(raw)) * 1000;
|
|
53
|
+
/** The run input from --input FILE, --chain with --value NAME=VALUE pairs (a research workflow), or --chain with --address (Token Researcher). */
|
|
54
|
+
async function quoteInput(values, cwd) {
|
|
55
|
+
const forms = [values.input !== undefined, values.value !== undefined, values.address !== undefined].filter(Boolean).length;
|
|
56
|
+
if (forms !== 1)
|
|
57
|
+
throw new CliUsageError('Give the run input one way: --input input.json, --chain with --value NAME=VALUE, or --chain with --address.');
|
|
58
|
+
if (values.input !== undefined) {
|
|
59
|
+
if (values.chain !== undefined)
|
|
60
|
+
throw new CliUsageError('--input already contains the chain; drop --chain.');
|
|
61
|
+
const raw = await readCreatorFile(values.input, cwd);
|
|
62
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
63
|
+
throw new CliUsageError('--input must be a JSON object.');
|
|
64
|
+
return raw;
|
|
65
|
+
}
|
|
66
|
+
const chain = required(values.chain, 'chain');
|
|
67
|
+
if (values.address !== undefined)
|
|
68
|
+
return { chain, address: values.address };
|
|
69
|
+
const entries = values.value.map(pair => {
|
|
70
|
+
const match = /^([A-Za-z][A-Za-z0-9_]{0,63})=(.{1,500})$/.exec(pair);
|
|
71
|
+
if (!match)
|
|
72
|
+
throw new CliUsageError('Each --value is NAME=VALUE, for example --value mint=<mint address>.');
|
|
73
|
+
return [match[1], scalar(match[2])];
|
|
74
|
+
});
|
|
75
|
+
if (new Set(entries.map(([name]) => name)).size !== entries.length)
|
|
76
|
+
throw new CliUsageError('Each --value name may appear once.');
|
|
77
|
+
return workflowInput(z.enum(['ethereum', 'base', 'robinhood', 'solana']).parse(chain), Object.fromEntries(entries));
|
|
78
|
+
}
|
|
79
|
+
/** Runs one buyer subcommand and returns the process exit code. Output is JSON on stdout; errors are one line on stderr. */
|
|
80
|
+
export async function runBuyerCli(argv, io) {
|
|
81
|
+
try {
|
|
82
|
+
const [first, second] = argv;
|
|
83
|
+
if (!first || first === 'help' || first === '--help') {
|
|
84
|
+
io.stdout(BUYER_HELP);
|
|
85
|
+
return 0;
|
|
86
|
+
}
|
|
87
|
+
if (first === 'version' || first === '--version') {
|
|
88
|
+
io.stdout(`${SDK_VERSION}\n`);
|
|
89
|
+
return 0;
|
|
90
|
+
}
|
|
91
|
+
const command = first === 'monitor' ? `monitor ${second ?? ''}` : first;
|
|
92
|
+
if (!Object.hasOwn(allowed, command))
|
|
93
|
+
throw new CliUsageError('Unsupported buyer command. Run `agentex-buyer help`.');
|
|
94
|
+
const { values, tokens } = parseArgs({ args: argv.slice(first === 'monitor' ? 2 : 1), options: specifications, strict: true, allowPositionals: false, tokens: true });
|
|
95
|
+
const names = tokens.filter(token => token.kind === 'option').map(token => token.name);
|
|
96
|
+
const repeatable = new Set(['value']);
|
|
97
|
+
if (new Set(names.filter(name => !repeatable.has(name))).size !== names.filter(name => !repeatable.has(name)).length || names.some(name => name !== 'help' && !common.includes(name) && !allowed[command].includes(name)))
|
|
98
|
+
throw new CliUsageError('Duplicate or unsupported options for this command.');
|
|
99
|
+
if (values.help) {
|
|
100
|
+
io.stdout(BUYER_HELP);
|
|
101
|
+
return 0;
|
|
102
|
+
}
|
|
103
|
+
const apiKey = io.env.AGENTEX_API_KEY;
|
|
104
|
+
if (!apiKey)
|
|
105
|
+
throw new CliUsageError('Set AGENTEX_API_KEY to a key created at https://agentex.sh/developers.');
|
|
106
|
+
const profileText = values.profile ?? io.env.AGENTEX_PROFILE;
|
|
107
|
+
const profile = profileText === undefined || profileText === '' ? undefined : z.enum(['sim', 'local_custody', 'solana_sol', 'solana_usdc']).parse(profileText);
|
|
108
|
+
const asset = values.asset ?? (io.env.AGENTEX_ASSET || undefined);
|
|
109
|
+
const client = createBuyerClient({ origin: values.api ?? (io.env.AGENTEX_API_ORIGIN || DEFAULT_API_ORIGIN), apiKey, ...(profile ? { profile } : {}), ...(asset ? { assetId: asset } : {}), ...(io.fetch ? { fetch: io.fetch } : {}) });
|
|
110
|
+
const timeoutMs = seconds(values.timeout);
|
|
111
|
+
let output;
|
|
112
|
+
switch (command) {
|
|
113
|
+
case 'key':
|
|
114
|
+
output = { key: await client.key() };
|
|
115
|
+
break;
|
|
116
|
+
case 'catalog':
|
|
117
|
+
output = await client.listAgents({ ...(values.q ? { q: values.q } : {}), ...(values.chain ? { chain: values.chain } : {}), ...(values.topic ? { topic: values.topic } : {}),
|
|
118
|
+
...(asset ? { assetId: asset } : {}), ...(values.sort ? { sort: z.enum(['newest', 'name', 'price']).parse(values.sort) } : {}), ...(values.cursor ? { cursor: values.cursor } : {}),
|
|
119
|
+
...(values.limit ? { limit: Number(z.string().regex(/^[1-9][0-9]?$/).parse(values.limit)) } : {}) });
|
|
120
|
+
break;
|
|
121
|
+
case 'agent':
|
|
122
|
+
output = { agent: await client.getAgent(required(values.listing, 'listing')) };
|
|
123
|
+
break;
|
|
124
|
+
case 'quote': {
|
|
125
|
+
const quote = await client.createQuote({ listingId: required(values.listing, 'listing'), input: await quoteInput(values, io.cwd),
|
|
126
|
+
...(values['result-policy'] ? { resultPolicy: z.enum(['complete_only', 'canonical_metadata']).parse(values['result-policy']) } : {}) });
|
|
127
|
+
output = { quote, next: `Review the quote, then: agentex-buyer accept --quote ${quote.id} --contract-hash ${quote.contractHash} --idempotency-key <stable-key> --confirm` };
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
case 'accept':
|
|
131
|
+
if (!values.confirm)
|
|
132
|
+
throw new CliUsageError('Accepting spends under the key budget. Review the quote and pass --confirm.');
|
|
133
|
+
output = await client.acceptQuote({ quoteId: required(values.quote, 'quote'), contractHash: required(values['contract-hash'], 'contract-hash'), idempotencyKey: IdempotencyKeySchema.parse(required(values['idempotency-key'], 'idempotency-key')) });
|
|
134
|
+
break;
|
|
135
|
+
case 'research': {
|
|
136
|
+
if (!values.confirm)
|
|
137
|
+
throw new CliUsageError('research accepts a quote and spends under the key budget. Pass --max-debit and --confirm.');
|
|
138
|
+
const payment = await client.paymentAsset();
|
|
139
|
+
if (payment.decimals === null)
|
|
140
|
+
throw new CliUsageError('This asset has unknown decimals; use quote and accept instead.');
|
|
141
|
+
const maxDebitAtomic = parseAmount(required(values['max-debit'], 'max-debit'), payment.decimals);
|
|
142
|
+
const outcome = await client.research({ listingId: required(values.listing, 'listing'), input: await quoteInput(values, io.cwd), maxDebitAtomic,
|
|
143
|
+
...(values['result-policy'] ? { resultPolicy: z.enum(['complete_only', 'canonical_metadata']).parse(values['result-policy']) } : {}),
|
|
144
|
+
...(values['idempotency-key'] ? { idempotencyKey: IdempotencyKeySchema.parse(values['idempotency-key']) } : {}), ...(timeoutMs ? { wait: { timeoutMs } } : {}) });
|
|
145
|
+
const { raw: _raw, ...report } = outcome.report;
|
|
146
|
+
output = { run: { id: outcome.run.id, status: outcome.run.status }, quote: { id: outcome.quote.id, maximumBuyerDebitAtomic: outcome.quote.maximumBuyerDebitAtomic, expiresAt: outcome.quote.expiresAt },
|
|
147
|
+
payment: outcome.payment, idempotencyKey: outcome.idempotencyKey, report, next: `agentex-buyer receipt --run ${outcome.run.id} --wait` };
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
case 'status':
|
|
151
|
+
output = values.wait ? await client.waitForRun(required(values.run, 'run'), timeoutMs ? { timeoutMs } : {}) : await client.getRun(required(values.run, 'run'));
|
|
152
|
+
break;
|
|
153
|
+
case 'report': {
|
|
154
|
+
const { raw: _raw, ...report } = await client.getReport(required(values.run, 'run'));
|
|
155
|
+
output = report;
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
case 'result': {
|
|
159
|
+
const result = await client.getResult(required(values.run, 'run'));
|
|
160
|
+
if (values.out) {
|
|
161
|
+
await writeCreatorFile(values.out, result, io.cwd);
|
|
162
|
+
output = { output: 'written', artifactId: result.artifactId, status: result.run.status };
|
|
163
|
+
}
|
|
164
|
+
else
|
|
165
|
+
output = result;
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
case 'billing':
|
|
169
|
+
output = await client.getBilling(required(values.run, 'run'));
|
|
170
|
+
break;
|
|
171
|
+
case 'receipt':
|
|
172
|
+
output = await client.getReceipt(required(values.run, 'run'), values.wait ? { waitForSettlement: timeoutMs ? { timeoutMs } : true } : {});
|
|
173
|
+
break;
|
|
174
|
+
case 'cancel':
|
|
175
|
+
output = { run: await client.cancelRun(required(values.run, 'run')) };
|
|
176
|
+
break;
|
|
177
|
+
case 'monitor create':
|
|
178
|
+
output = await client.createMonitor(await readCreatorFile(required(values.file, 'file'), io.cwd));
|
|
179
|
+
break;
|
|
180
|
+
case 'monitor list':
|
|
181
|
+
output = { monitors: await client.listMonitors() };
|
|
182
|
+
break;
|
|
183
|
+
case 'monitor get':
|
|
184
|
+
output = await client.getMonitor(required(values.monitor, 'monitor'));
|
|
185
|
+
break;
|
|
186
|
+
case 'monitor stop':
|
|
187
|
+
output = { monitor: await client.stopMonitor(required(values.monitor, 'monitor')) };
|
|
188
|
+
break;
|
|
189
|
+
case 'monitor notifications':
|
|
190
|
+
output = { notifications: await client.listNotifications() };
|
|
191
|
+
break;
|
|
192
|
+
case 'monitor ack':
|
|
193
|
+
output = { notification: await client.acknowledgeNotification(required(values.notification, 'notification')) };
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
io.stdout(`${JSON.stringify(output, null, 2)}\n`);
|
|
197
|
+
return 0;
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
if (error instanceof AgentexApiError)
|
|
201
|
+
io.stderr(`Buyer command failed (${error.status === null ? error.code : `HTTP ${error.status} ${error.code}`}): ${error.message}${error.runId ? ` Run ${error.runId}.` : ''}\n`);
|
|
202
|
+
else if (error instanceof CliUsageError)
|
|
203
|
+
io.stderr(`${error.message}\n`);
|
|
204
|
+
else if (error instanceof z.ZodError)
|
|
205
|
+
io.stderr('Validation failed: an option or JSON file does not match the buyer contract.\n');
|
|
206
|
+
else
|
|
207
|
+
io.stderr('Buyer command failed. Check options, JSON files (inside the working directory, never overwritten) and the API origin.\n');
|
|
208
|
+
return 1;
|
|
209
|
+
}
|
|
210
|
+
}
|