@oneie/cli 0.2.0 → 0.2.1

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/src/agent.js CHANGED
@@ -3,6 +3,7 @@ import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs';
3
3
  import { basename, dirname, resolve } from 'node:path';
4
4
  import { homedir } from 'node:os';
5
5
  import { TEMPLATES } from './templates.js';
6
+ import { compileAgent } from '@oneie/sdk/compile';
6
7
  import { watch } from 'fs';
7
8
  const DEFAULT_API = 'https://one.ie';
8
9
  const KEY_FILE = resolve(homedir(), '.config', 'oneie', 'key');
@@ -49,6 +50,7 @@ export function agentCmd() {
49
50
  cmd.command('compile <path>')
50
51
  .description('Compile agent.md to target format')
51
52
  .option('--target <t>', 'Output format: mcp | uagents | skillmd | web | a2a | erc8004', 'mcp')
53
+ .option('--out <file>', 'Write output to file instead of stdout')
52
54
  .action((path, opts) => {
53
55
  if (!existsSync(path)) {
54
56
  out(cmd, { ok: false, error: `not found: ${path}` });
@@ -56,7 +58,14 @@ export function agentCmd() {
56
58
  }
57
59
  const content = readFileSync(path, 'utf8');
58
60
  const result = compileTarget(content, opts.target);
59
- out(cmd, { ok: true, target: opts.target, bytes: result.length });
61
+ if (opts.out) {
62
+ mkdirSync(dirname(opts.out), { recursive: true });
63
+ writeFileSync(opts.out, result);
64
+ out(cmd, { ok: true, target: opts.target, written: opts.out, bytes: result.length });
65
+ }
66
+ else {
67
+ process.stdout.write(result + '\n');
68
+ }
60
69
  });
61
70
  cmd.command('serve <path>')
62
71
  .description('Run agent as local A2A + MCP server on port 8000')
@@ -69,10 +78,12 @@ export function agentCmd() {
69
78
  out(cmd, { ok: true, path, port: Number(opts.port), status: 'listening' });
70
79
  });
71
80
  cmd.command('publish <path>')
72
- .description('Upload agent.md to your workspace at one.ie (or --api <url>)')
73
- .option('--slug <slug>', 'Workspace slug to publish into (required)')
81
+ .description('Upload agent.md to your workspace at one.ie, or deploy to Agentverse with --target agentverse')
82
+ .option('--slug <slug>', 'Workspace slug to publish into (one.ie target)')
74
83
  .option('--api <url>', 'API base URL', DEFAULT_API)
75
- .option('--name <name>', 'Override agent name (defaults to file stem)')
84
+ .option('--name <name>', 'Override agent name (defaults to frontmatter name:)')
85
+ .option('--target <t>', 'Publish target: oneie (default) | agentverse', 'oneie')
86
+ .option('--agentverse-key <key>', 'Agentverse API key (or set AGENTVERSE_API_KEY)')
76
87
  .action(async (path, opts) => {
77
88
  if (!existsSync(path)) {
78
89
  out(cmd, { ok: false, error: `not found: ${path}` });
@@ -83,6 +94,81 @@ export function agentCmd() {
83
94
  out(cmd, { ok: false, errors });
84
95
  return;
85
96
  }
97
+ const content = readFileSync(path, 'utf8');
98
+ const frontmatterName = /^name:\s*(\S+)/m.exec(content)?.[1];
99
+ const agentName = opts.name ?? frontmatterName ?? basename(path, '.md');
100
+ // ── Agentverse deploy path ────────────────────────────────────────────
101
+ if (opts.target === 'agentverse') {
102
+ const avKey = opts.agentverseKey ?? process.env.AGENTVERSE_API_KEY;
103
+ if (!avKey) {
104
+ out(cmd, { ok: false, error: 'Agentverse API key required — pass --agentverse-key or set AGENTVERSE_API_KEY' });
105
+ return;
106
+ }
107
+ // Compile agent.md → Python uAgents
108
+ let python;
109
+ try {
110
+ python = compileAgent(content, { target: 'uagents' });
111
+ }
112
+ catch (err) {
113
+ out(cmd, { ok: false, error: `compile failed: ${err.message}` });
114
+ return;
115
+ }
116
+ const AV = 'https://agentverse.ai/v1';
117
+ const avFetch = async (method, avPath, body) => {
118
+ const res = await fetch(`${AV}${avPath}`, {
119
+ method,
120
+ headers: { Authorization: `Bearer ${avKey}`, 'Content-Type': 'application/json' },
121
+ body: body !== undefined ? JSON.stringify(body) : undefined,
122
+ });
123
+ const text = await res.text();
124
+ if (!res.ok)
125
+ throw new Error(`${method} ${avPath} → ${res.status}: ${text}`);
126
+ return text ? JSON.parse(text) : {};
127
+ };
128
+ try {
129
+ // 1. Create agent
130
+ const created = await avFetch('POST', '/hosting/agents', { name: agentName });
131
+ const address = created.address;
132
+ if (!address)
133
+ throw new Error('Agentverse did not return an agent address');
134
+ // 2. Upload code (double-encoded JSON — Agentverse requirement)
135
+ const codeArray = [{ language: 'python', name: 'agent.py', value: python }];
136
+ await avFetch('PUT', `/hosting/agents/${address}/code`, { code: JSON.stringify(codeArray) });
137
+ // 3. Set API key as secret so agent can call back to ONE
138
+ const oneKey = readApiKey();
139
+ if (oneKey) {
140
+ await avFetch('POST', '/hosting/secrets', { address, name: 'ONEIE_API_KEY', secret: oneKey }).catch(() => { });
141
+ }
142
+ // 4. Start
143
+ await avFetch('POST', `/hosting/agents/${address}/start`, {});
144
+ // 5. Poll for compiled (up to 60s)
145
+ let compiled = false;
146
+ let walletAddress;
147
+ for (let i = 0; i < 12; i++) {
148
+ await new Promise(r => setTimeout(r, 5000));
149
+ const status = await avFetch('GET', `/hosting/agents/${address}`);
150
+ if (status.compiled || status.running) {
151
+ compiled = true;
152
+ walletAddress = status.wallet_address;
153
+ break;
154
+ }
155
+ }
156
+ out(cmd, {
157
+ ok: true,
158
+ target: 'agentverse',
159
+ agentAddress: address,
160
+ walletAddress,
161
+ compiled,
162
+ agentName,
163
+ agentverseUrl: `https://agentverse.ai/agents/details/${address}`,
164
+ });
165
+ }
166
+ catch (err) {
167
+ out(cmd, { ok: false, error: err.message });
168
+ }
169
+ return;
170
+ }
171
+ // ── ONE workspace publish path (default) ─────────────────────────────
86
172
  if (!opts.slug) {
87
173
  out(cmd, { ok: false, error: 'missing --slug <workspace>' });
88
174
  return;
@@ -92,19 +178,12 @@ export function agentCmd() {
92
178
  out(cmd, { ok: false, error: 'no API key — run `oneie auth login --key <key>` or set ONEIE_API_KEY' });
93
179
  return;
94
180
  }
95
- const content = readFileSync(path, 'utf8');
96
- // Derive publish name from frontmatter `name:` first (canonical), then
97
- // --name override, then basename. Convention is `<name>/agent.md` so
98
- // basename alone is rarely right.
99
- const frontmatterName = /^name:\s*(\S+)/m.exec(content)?.[1];
100
- const name = opts.name ?? frontmatterName ?? basename(path, '.md');
101
- // Owner-scoped Bearer convention from /api/agents/* — slug:token
102
181
  const token = `${opts.slug}:${key}`;
103
182
  try {
104
183
  const res = await fetch(`${opts.api.replace(/\/$/, '')}/api/agents/publish`, {
105
184
  method: 'POST',
106
185
  headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
107
- body: JSON.stringify({ slug: opts.slug, name, content }),
186
+ body: JSON.stringify({ slug: opts.slug, name: agentName, content }),
108
187
  });
109
188
  const text = await res.text();
110
189
  const data = text ? JSON.parse(text) : {};
@@ -670,7 +749,7 @@ function compileTarget(content, target) {
670
749
  if (target === 'mcp')
671
750
  return JSON.stringify({ tools: [] }, null, 2);
672
751
  if (target === 'uagents')
673
- return '# Python uAgents output — run oneie-py for full compile\n' + content;
752
+ return compileAgent(content, { target: 'uagents' });
674
753
  if (target === 'web') {
675
754
  // Emit a typed TS module — the web app can import this at build time
676
755
  // instead of parsing .md at request time. Matches the SDK's compileWeb()
@@ -1,4 +1,4 @@
1
- const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_BASE_URL ?? 'https://one.ie';
1
+ const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_BASE_URL ?? 'https://api.one.ie';
2
2
  function apiKey() {
3
3
  return process.env.ONEIE_API_KEY ?? process.env.ONE_API_KEY ?? '';
4
4
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oneie/cli",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "ONE agent CLI",
5
5
  "type": "module",
6
6
  "bin": {
@@ -18,7 +18,8 @@
18
18
  "prepublishOnly": "bun run build"
19
19
  },
20
20
  "dependencies": {
21
- "commander": "^12.0.0"
21
+ "commander": "^12.0.0",
22
+ "@oneie/sdk": "workspace:*"
22
23
  },
23
24
  "devDependencies": {
24
25
  "@types/node": "^25.6.0",