oneie 4.2.0 → 4.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/README.md +36 -0
- package/dist/package.json +2 -2
- package/dist/src/compiler.js +29 -1
- package/dist/src/endpoint.d.ts +2 -0
- package/dist/src/endpoint.js +250 -0
- package/dist/src/index.js +4 -0
- package/dist/src/lib/shop-init.d.ts +62 -0
- package/dist/src/lib/shop-init.js +63 -0
- package/dist/src/shop.d.ts +10 -0
- package/dist/src/shop.js +73 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -130,8 +130,44 @@ one social list --group G | create --group G ... # draft/publish/list socia
|
|
|
130
130
|
one fn run <name> '{json}' | list # call an allowlisted analytics/routing RPC
|
|
131
131
|
one coordinate recall [about] | reputation [uid] # cross-session memory and reputation
|
|
132
132
|
one group bulk-create --csv # idempotent batch client provisioning
|
|
133
|
+
one shop init [--facts F] [--workspace S] # seed the twelve-page shop pack; a fact left out stays a VISIBLE placeholder
|
|
133
134
|
```
|
|
134
135
|
|
|
136
|
+
## Your own endpoints — a tenant's HTTPS, called by a workflow
|
|
137
|
+
|
|
138
|
+
Register an HTTPS endpoint you own and let a workflow `tool` step call it. The
|
|
139
|
+
URL is SSRF-checked when you register it **and again on every call** — the
|
|
140
|
+
check is not a one-time gate at the door.
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
one endpoint add <name> <url> [--method POST] [--returns json|url|bytes]
|
|
144
|
+
[--auth-header Authorization] [--secret-env VAR] # the secret is read from the ENV, never from argv, which the shell records
|
|
145
|
+
[--timeout 20000] [--max-bytes 5242880] # clamped 1000-120000 and to 10485760
|
|
146
|
+
one endpoint list [--workspace S] # the sealed secret has NO read door — the column says yes or no, never the value
|
|
147
|
+
one endpoint test <name> # run the SSRF guard WITHOUT spending a request; the refusal comes back by name
|
|
148
|
+
one endpoint call <name> --input '{json}' # the same door a workflow `tool` step uses
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
`--workspace` on any of these is a workspace you must already control: one you
|
|
152
|
+
may not write is **refused**, never silently downgraded to your own.
|
|
153
|
+
|
|
154
|
+
An endpoint is reachable **two** ways, and the second one is why an outside
|
|
155
|
+
agent can join at all. A workflow `tool` step names it —
|
|
156
|
+
`{ receiver: "endpoint:call", args: { endpoint: "<name>", input: {…} } }` — and
|
|
157
|
+
takes any request and response shape you like; in `bytes` or `url` mode the
|
|
158
|
+
result is filed in the media library and you get the reader URL back. And an
|
|
159
|
+
agent whose frontmatter says `model: endpoint/<name>` is *served by* your
|
|
160
|
+
service: it gets an actor id, a chat UI renders it, and `agent:run` invokes it,
|
|
161
|
+
with none of your code running on anyone's machine. That second path needs your
|
|
162
|
+
service to speak **OpenAI chat completions**, because that is the shape every
|
|
163
|
+
other provider branch already constructs; a service with its own shape belongs
|
|
164
|
+
on the first path, which cares about neither.
|
|
165
|
+
|
|
166
|
+
`endpoint/<name>/<model>` overrides the model id sent in the request body. A
|
|
167
|
+
handle registered by another workspace is **not found**, never borrowed, and an
|
|
168
|
+
endpoint that cannot be served **refuses** rather than quietly answering from a
|
|
169
|
+
different model.
|
|
170
|
+
|
|
135
171
|
## Media — the library an agent can reach
|
|
136
172
|
|
|
137
173
|
```bash
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oneie",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.1",
|
|
4
4
|
"description": "ONE agent CLI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"@oneie/sdk": "^0.16.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@oneie/evals": "^0.
|
|
26
|
+
"@oneie/evals": "^0.2.0",
|
|
27
27
|
"@types/node": "^25.6.0",
|
|
28
28
|
"tsx": "^4.0.0",
|
|
29
29
|
"typescript": "^5.4.0",
|
package/dist/src/compiler.js
CHANGED
|
@@ -164,6 +164,12 @@ export async function compileNode(dir, agencySlug, opts) {
|
|
|
164
164
|
// ai/agents/*.md → world:create-thing (agent)
|
|
165
165
|
for (const f of walk(join(dir, 'ai', 'agents'), '.md')) {
|
|
166
166
|
try {
|
|
167
|
+
// A README is documentation ABOUT the agents beside it, never an agent.
|
|
168
|
+
// `ai/agents/templates/README.md` explains the starter org chart, has no
|
|
169
|
+
// frontmatter, and was reported as `frontmatter \`name\` required` on every
|
|
170
|
+
// push — an error the author cannot fix without deleting the explanation.
|
|
171
|
+
if (basename(f).toLowerCase() === 'readme.md')
|
|
172
|
+
continue;
|
|
167
173
|
const md = readFileSync(f, 'utf8');
|
|
168
174
|
const fm = frontmatter(md);
|
|
169
175
|
if (!fm.name) {
|
|
@@ -223,6 +229,18 @@ export async function compileNode(dir, agencySlug, opts) {
|
|
|
223
229
|
string: 'text', url: 'text', number: 'number', currency: 'currency', date: 'date',
|
|
224
230
|
tags: 'tags', select: 'select', image: 'image', markdown: 'markdown', relation: 'relation', bool: 'select',
|
|
225
231
|
};
|
|
232
|
+
// ONE call carrying EVERY type, not one call per file. `world:declare-types`
|
|
233
|
+
// REPLACES the whole manifest (world-receivers.ts:1953 — `INSERT … ON CONFLICT
|
|
234
|
+
// DO UPDATE SET manifest = excluded.manifest`), and push.ts sends compiled
|
|
235
|
+
// items sequentially, so a per-file call made every type after the first
|
|
236
|
+
// delete the one before it. Measured 2026-09-22 on a two-file fixture:
|
|
237
|
+
// `declare-types calls emitted: 2 → ["order"], ["product"]`, push reports
|
|
238
|
+
// `Pushed 2/2 item(s).`, and the workspace keeps ONE type. Silent, and it is
|
|
239
|
+
// the exact path baas-features.md sells as "declare your types, a full admin
|
|
240
|
+
// appears" — so a starter could never ship a type SET. Files are walked in a
|
|
241
|
+
// stable order and the batch keeps it, so the manifest order is the file order.
|
|
242
|
+
const declaredTypes = [];
|
|
243
|
+
const typeFiles = [];
|
|
226
244
|
for (const f of walk(join(dir, 'data', 'types'), '.toml')) {
|
|
227
245
|
try {
|
|
228
246
|
const toml = parseToml(readFileSync(f, 'utf8'));
|
|
@@ -244,12 +262,22 @@ export async function compileNode(dir, agencySlug, opts) {
|
|
|
244
262
|
columns: cols,
|
|
245
263
|
fields: cols,
|
|
246
264
|
};
|
|
247
|
-
|
|
265
|
+
declaredTypes.push(type);
|
|
266
|
+
typeFiles.push(f);
|
|
248
267
|
}
|
|
249
268
|
catch (e) {
|
|
250
269
|
errors.push({ path: f, message: String(e) });
|
|
251
270
|
}
|
|
252
271
|
}
|
|
272
|
+
if (declaredTypes.length > 0) {
|
|
273
|
+
// `path` names every file that fed the batch — a dry-run must still say which
|
|
274
|
+
// TOMLs are in play, and an error must be traceable to more than "data/types".
|
|
275
|
+
compiled.push({
|
|
276
|
+
path: typeFiles.join(', '),
|
|
277
|
+
receiver: 'world:declare-types',
|
|
278
|
+
payload: { group: agencySlug, types: declaredTypes },
|
|
279
|
+
});
|
|
280
|
+
}
|
|
253
281
|
// data/lifecycles/*.toml → lifecycle:save
|
|
254
282
|
// Build the LifecycleDef that the receiver's saveDef() persists. The TOML authors the
|
|
255
283
|
// human bits {id,label,tags,description,[[stages]]}; the rest is derived deterministically:
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { authHeaders, jsonMode, resolveBase } from './lib/client.js';
|
|
3
|
+
import { askPath } from './lib/api-path.js';
|
|
4
|
+
// `one endpoint` — enter your OWN https endpoints once, then name them from a
|
|
5
|
+
// workflow step.
|
|
6
|
+
//
|
|
7
|
+
// WHY A SUBCOMMAND RATHER THAN `one ask endpoint:register`. Three things a raw
|
|
8
|
+
// ask cannot do, and each one is a mistake a creator would otherwise make:
|
|
9
|
+
//
|
|
10
|
+
// add a SECRET is a credential, and pasting it into a shell as JSON puts it
|
|
11
|
+
// in the shell history. `--secret-env VAR` reads it from the environment
|
|
12
|
+
// instead, and the printed row never echoes it back.
|
|
13
|
+
// test `endpoint:call --dryRun` answers the GUARD question without spending a
|
|
14
|
+
// request. A creator's first failure is almost always the url, not the
|
|
15
|
+
// payload, and this names the reason — https_required, ip_literal,
|
|
16
|
+
// private_hostname, dns_unresolved, blocked_address.
|
|
17
|
+
// list the sealed secret has no read door anywhere, so the renderer prints
|
|
18
|
+
// `secret=yes|no`. A raw ask would print the same JSON; the point is that
|
|
19
|
+
// there is nothing else to print, and the column says so out loud.
|
|
20
|
+
//
|
|
21
|
+
// call IS here too, because a creator who cannot call his own endpoint from the
|
|
22
|
+
// terminal cannot tell a broken endpoint from a broken workflow.
|
|
23
|
+
const DEFAULT_API = 'https://api.one.ie';
|
|
24
|
+
function asker(api) {
|
|
25
|
+
const base = resolveBase({ api }, DEFAULT_API);
|
|
26
|
+
return async (receiver, data) => {
|
|
27
|
+
const res = await fetch(askPath(base, receiver), {
|
|
28
|
+
method: 'POST',
|
|
29
|
+
headers: authHeaders(),
|
|
30
|
+
body: JSON.stringify({ data }),
|
|
31
|
+
});
|
|
32
|
+
const text = await res.text();
|
|
33
|
+
let body;
|
|
34
|
+
try {
|
|
35
|
+
body = text ? JSON.parse(text) : undefined;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
throw new Error(`${receiver} → ${res.status} ${text.slice(0, 200)}`);
|
|
39
|
+
}
|
|
40
|
+
if (!res.ok && !(body && typeof body === 'object' && 'outcome' in body)) {
|
|
41
|
+
throw new Error(`${receiver} → ${res.status} ${text.slice(0, 200)}`);
|
|
42
|
+
}
|
|
43
|
+
if (!body || typeof body !== 'object')
|
|
44
|
+
throw new Error(`${receiver}: empty response`);
|
|
45
|
+
const o = body;
|
|
46
|
+
if ('outcome' in o) {
|
|
47
|
+
if (o.outcome === 'result')
|
|
48
|
+
return o.result ?? {};
|
|
49
|
+
const inner = o.result;
|
|
50
|
+
if (inner && typeof inner === 'object' && ('ok' in inner || 'error' in inner)) {
|
|
51
|
+
return { ok: false, ...inner, error: inner.error ?? String(o.outcome) };
|
|
52
|
+
}
|
|
53
|
+
throw new Error(`${receiver}: ${String(o.outcome)}`);
|
|
54
|
+
}
|
|
55
|
+
if ('result' in o)
|
|
56
|
+
return o.result ?? {};
|
|
57
|
+
return o;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function fail(msg) {
|
|
61
|
+
process.stderr.write(`${msg}\n`);
|
|
62
|
+
process.exitCode = 1;
|
|
63
|
+
}
|
|
64
|
+
function renderRows(rows) {
|
|
65
|
+
const w = process.stdout;
|
|
66
|
+
if (!rows.length) {
|
|
67
|
+
w.write('no endpoints registered\n');
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
w.write(`${rows.length} endpoint${rows.length === 1 ? '' : 's'}\n\n`);
|
|
71
|
+
for (const r of rows) {
|
|
72
|
+
w.write(`${r.name} ${r.method} ${r.url}\n` +
|
|
73
|
+
` returns=${r.returnMode} timeout=${r.timeoutMs}ms max=${r.maxBytes}B ` +
|
|
74
|
+
`secret=${r.hasSecret ? `yes (${r.authHeader})` : 'no'} status=${r.status}` +
|
|
75
|
+
`${r.lastStatus ? ` last=${r.lastStatus}` : ''}\n`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function parseJsonOption(raw) {
|
|
79
|
+
if (raw === undefined)
|
|
80
|
+
return undefined;
|
|
81
|
+
try {
|
|
82
|
+
const v = JSON.parse(raw);
|
|
83
|
+
if (!v || typeof v !== 'object' || Array.isArray(v))
|
|
84
|
+
return 'bad';
|
|
85
|
+
return v;
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return 'bad';
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
export function endpointCmd() {
|
|
92
|
+
const cmd = new Command('endpoint').description('Your own https endpoints — register one under a handle, then name it from a workflow `tool` step ' +
|
|
93
|
+
'(config: { receiver: "endpoint:call", args: { endpoint: "<handle>", input: {…} } })');
|
|
94
|
+
cmd
|
|
95
|
+
.command('add <name> <url>')
|
|
96
|
+
.description('Register or update an endpoint. The url is SSRF-checked here and again on every call.')
|
|
97
|
+
.option('--workspace <slug>', 'Group slug (default: your own). A workspace you may not write is REFUSED, never downgraded.')
|
|
98
|
+
.option('--method <m>', 'GET | POST | PUT | PATCH', 'POST')
|
|
99
|
+
.option('--returns <mode>', 'json (the answer) | url (a link we fetch and file) | bytes (an image we file)', 'json')
|
|
100
|
+
.option('--auth-header <name>', 'Header NAME the secret travels in, e.g. Authorization')
|
|
101
|
+
.option('--secret-env <VAR>', 'Read the secret from this environment variable — never from the command line, which the shell records')
|
|
102
|
+
.option('--timeout <ms>', 'Per-call timeout. Default 20000, clamped 1000–120000.')
|
|
103
|
+
.option('--max-bytes <n>', 'Response byte ceiling. Default 5242880, clamped to 10485760.')
|
|
104
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
105
|
+
.option('--json', 'Print the raw response')
|
|
106
|
+
.action(async (name, url, opts, sub) => {
|
|
107
|
+
let secret;
|
|
108
|
+
if (opts.secretEnv) {
|
|
109
|
+
secret = process.env[opts.secretEnv];
|
|
110
|
+
// An unset variable is a REFUSAL, not an unauthenticated registration —
|
|
111
|
+
// silently registering without the credential would send an anonymous
|
|
112
|
+
// request to a host that answers 401, and the creator would debug the url.
|
|
113
|
+
if (!secret)
|
|
114
|
+
return fail(`--secret-env ${opts.secretEnv} is unset or empty in this environment`);
|
|
115
|
+
if (!opts.authHeader)
|
|
116
|
+
return fail('--secret-env needs --auth-header (the header the secret travels in)');
|
|
117
|
+
}
|
|
118
|
+
const data = {
|
|
119
|
+
name,
|
|
120
|
+
url,
|
|
121
|
+
method: opts.method.toUpperCase(),
|
|
122
|
+
returnMode: opts.returns,
|
|
123
|
+
...(opts.workspace ? { workspace: opts.workspace } : {}),
|
|
124
|
+
...(opts.authHeader ? { authHeader: opts.authHeader } : {}),
|
|
125
|
+
...(secret ? { secret } : {}),
|
|
126
|
+
...(opts.timeout ? { timeoutMs: Number(opts.timeout) } : {}),
|
|
127
|
+
...(opts.maxBytes ? { maxBytes: Number(opts.maxBytes) } : {}),
|
|
128
|
+
};
|
|
129
|
+
let res;
|
|
130
|
+
try {
|
|
131
|
+
res = (await asker(opts.api)('endpoint:register', data));
|
|
132
|
+
}
|
|
133
|
+
catch (e) {
|
|
134
|
+
return fail(e instanceof Error ? e.message : String(e));
|
|
135
|
+
}
|
|
136
|
+
if (jsonMode(sub))
|
|
137
|
+
process.stdout.write(JSON.stringify(res, null, 2) + '\n');
|
|
138
|
+
else if (res.ok !== false && res.endpoint)
|
|
139
|
+
renderRows([res.endpoint]);
|
|
140
|
+
if (res.ok === false)
|
|
141
|
+
fail(res.error ?? 'endpoint:register failed');
|
|
142
|
+
});
|
|
143
|
+
cmd
|
|
144
|
+
.command('list')
|
|
145
|
+
.description('List registered endpoints. The sealed secret has no read door — the column says yes or no.')
|
|
146
|
+
.option('--workspace <slug>', 'Group slug (default: your own)')
|
|
147
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
148
|
+
.option('--json', 'Print the raw response')
|
|
149
|
+
.action(async (opts, sub) => {
|
|
150
|
+
let res;
|
|
151
|
+
try {
|
|
152
|
+
res = (await asker(opts.api)('endpoint:list', opts.workspace ? { workspace: opts.workspace } : {}));
|
|
153
|
+
}
|
|
154
|
+
catch (e) {
|
|
155
|
+
return fail(e instanceof Error ? e.message : String(e));
|
|
156
|
+
}
|
|
157
|
+
if (jsonMode(sub))
|
|
158
|
+
process.stdout.write(JSON.stringify(res, null, 2) + '\n');
|
|
159
|
+
else if (res.ok !== false)
|
|
160
|
+
renderRows(res.endpoints ?? []);
|
|
161
|
+
if (res.ok === false)
|
|
162
|
+
fail(res.error ?? 'endpoint:list failed');
|
|
163
|
+
});
|
|
164
|
+
cmd
|
|
165
|
+
.command('test <name>')
|
|
166
|
+
.description('Run the SSRF guard against a registered endpoint without spending a request — the reason comes back by name')
|
|
167
|
+
.option('--workspace <slug>', 'Group slug (default: your own)')
|
|
168
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
169
|
+
.option('--json', 'Print the raw response')
|
|
170
|
+
.action(async (name, opts, sub) => {
|
|
171
|
+
let res;
|
|
172
|
+
try {
|
|
173
|
+
res = (await asker(opts.api)('endpoint:call', {
|
|
174
|
+
endpoint: name,
|
|
175
|
+
dryRun: true,
|
|
176
|
+
...(opts.workspace ? { workspace: opts.workspace } : {}),
|
|
177
|
+
}));
|
|
178
|
+
}
|
|
179
|
+
catch (e) {
|
|
180
|
+
return fail(e instanceof Error ? e.message : String(e));
|
|
181
|
+
}
|
|
182
|
+
if (jsonMode(sub))
|
|
183
|
+
process.stdout.write(JSON.stringify(res, null, 2) + '\n');
|
|
184
|
+
else if (res.ok !== false)
|
|
185
|
+
process.stdout.write(`guard ${res.guard ?? 'passed'} ${res.url ?? ''}\n`);
|
|
186
|
+
if (res.ok === false)
|
|
187
|
+
fail(res.error ?? 'endpoint:call failed');
|
|
188
|
+
});
|
|
189
|
+
cmd
|
|
190
|
+
.command('call <name>')
|
|
191
|
+
.description('Call a registered endpoint for real — the same door a workflow `tool` step uses')
|
|
192
|
+
.option('--input <json>', 'The JSON object sent to your endpoint. The ONLY thing that crosses, beside its own sealed credential.')
|
|
193
|
+
.option('--returns <mode>', 'Override the row: json | url | bytes')
|
|
194
|
+
.option('--workspace <slug>', 'Group slug (default: your own)')
|
|
195
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
196
|
+
.option('--json', 'Print the raw response')
|
|
197
|
+
.action(async (name, opts, sub) => {
|
|
198
|
+
const input = parseJsonOption(opts.input);
|
|
199
|
+
if (input === 'bad')
|
|
200
|
+
return fail('--input must be a JSON object, e.g. \'{"title":"hello"}\'');
|
|
201
|
+
let res;
|
|
202
|
+
try {
|
|
203
|
+
res = (await asker(opts.api)('endpoint:call', {
|
|
204
|
+
endpoint: name,
|
|
205
|
+
...(input ? { input } : {}),
|
|
206
|
+
...(opts.returns ? { returnMode: opts.returns } : {}),
|
|
207
|
+
...(opts.workspace ? { workspace: opts.workspace } : {}),
|
|
208
|
+
}));
|
|
209
|
+
}
|
|
210
|
+
catch (e) {
|
|
211
|
+
return fail(e instanceof Error ? e.message : String(e));
|
|
212
|
+
}
|
|
213
|
+
if (jsonMode(sub) || res.ok === false) {
|
|
214
|
+
process.stdout.write(JSON.stringify(res, null, 2) + '\n');
|
|
215
|
+
}
|
|
216
|
+
else if (res.url) {
|
|
217
|
+
process.stdout.write(`${res.url} ${res.contentType ?? ''} ${res.size ?? '?'}B\n`);
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
process.stdout.write(JSON.stringify(res.json ?? res.text ?? res, null, 2) + '\n');
|
|
221
|
+
}
|
|
222
|
+
if (res.ok === false)
|
|
223
|
+
fail(String(res.error ?? 'endpoint:call failed'));
|
|
224
|
+
});
|
|
225
|
+
cmd
|
|
226
|
+
.command('rm <name>')
|
|
227
|
+
.description('Delete a registered endpoint. Deleting something absent answers not_found, never a quiet success.')
|
|
228
|
+
.option('--workspace <slug>', 'Group slug (default: your own)')
|
|
229
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
230
|
+
.option('--json', 'Print the raw response')
|
|
231
|
+
.action(async (name, opts, sub) => {
|
|
232
|
+
let res;
|
|
233
|
+
try {
|
|
234
|
+
res = (await asker(opts.api)('endpoint:remove', {
|
|
235
|
+
name,
|
|
236
|
+
...(opts.workspace ? { workspace: opts.workspace } : {}),
|
|
237
|
+
}));
|
|
238
|
+
}
|
|
239
|
+
catch (e) {
|
|
240
|
+
return fail(e instanceof Error ? e.message : String(e));
|
|
241
|
+
}
|
|
242
|
+
if (jsonMode(sub))
|
|
243
|
+
process.stdout.write(JSON.stringify(res, null, 2) + '\n');
|
|
244
|
+
else if (res.ok !== false)
|
|
245
|
+
process.stdout.write(`removed ${name}\n`);
|
|
246
|
+
if (res.ok === false)
|
|
247
|
+
fail(res.error ?? 'endpoint:remove failed');
|
|
248
|
+
});
|
|
249
|
+
return cmd;
|
|
250
|
+
}
|
package/dist/src/index.js
CHANGED
|
@@ -35,6 +35,8 @@ import { pluginCmd } from './plugin.js';
|
|
|
35
35
|
import { workflowCmd } from './workflow.js';
|
|
36
36
|
import { tasksCmd } from './tasks.js';
|
|
37
37
|
import { mediaCmd } from './media.js';
|
|
38
|
+
import { endpointCmd } from './endpoint.js';
|
|
39
|
+
import { shopCmd } from './shop.js';
|
|
38
40
|
import { readFileSync } from 'node:fs';
|
|
39
41
|
import { fileURLToPath } from 'node:url';
|
|
40
42
|
import { resolve, dirname } from 'node:path';
|
|
@@ -82,6 +84,8 @@ program.addCommand(pluginCmd());
|
|
|
82
84
|
program.addCommand(workflowCmd());
|
|
83
85
|
program.addCommand(tasksCmd());
|
|
84
86
|
program.addCommand(mediaCmd());
|
|
87
|
+
program.addCommand(endpointCmd());
|
|
88
|
+
program.addCommand(shopCmd());
|
|
85
89
|
// Bare `oneie` (no args, no --help/--version): route the audience to its
|
|
86
90
|
// journey instead of commander's default help dump. Never an interactive
|
|
87
91
|
// prompt — agent env and human TTY both get a printed block (contract #10).
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `one shop init` — the terminal half of the shop pack.
|
|
3
|
+
*
|
|
4
|
+
* Pure on purpose: every round trip arrives through `deps.ask`, so the whole
|
|
5
|
+
* command is exercised without a network and without a key. `src/shop.ts` is
|
|
6
|
+
* the commander wiring and holds no logic of its own.
|
|
7
|
+
*
|
|
8
|
+
* TWO RECEIVERS, ONE OF WHICH MAY NOT BE THERE YET.
|
|
9
|
+
* `pages:instantiate-shop-pack` ships. `pages:fill-shop-pack` is C9.3 of
|
|
10
|
+
* `text/ecommerce-site-todo.md` and lands in parallel with this — and an
|
|
11
|
+
* unknown receiver DISSOLVES, which answers HTTP 200. So the fill leg is read
|
|
12
|
+
* for its outcome and reported separately: `seeded` and `filled` are two facts,
|
|
13
|
+
* and a shop whose pages exist but carry no facts must not report as either a
|
|
14
|
+
* clean success or a total failure.
|
|
15
|
+
*/
|
|
16
|
+
export interface AskEnvelope {
|
|
17
|
+
outcome?: string;
|
|
18
|
+
result?: {
|
|
19
|
+
ok?: boolean;
|
|
20
|
+
slug?: string;
|
|
21
|
+
error?: string;
|
|
22
|
+
pages?: Array<{
|
|
23
|
+
pageSlug?: string;
|
|
24
|
+
slug?: string;
|
|
25
|
+
}>;
|
|
26
|
+
filled?: number;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export interface ShopInitDeps {
|
|
30
|
+
ask(receiver: string, data: unknown): Promise<AskEnvelope>;
|
|
31
|
+
}
|
|
32
|
+
export interface ShopInitResult {
|
|
33
|
+
ok: boolean;
|
|
34
|
+
workspace: string;
|
|
35
|
+
/** The page slugs the seed reported, first one first. */
|
|
36
|
+
pages: string[];
|
|
37
|
+
/** Was a fill asked for, and did it happen. */
|
|
38
|
+
filled: boolean;
|
|
39
|
+
fillRequested: boolean;
|
|
40
|
+
error?: string;
|
|
41
|
+
fillError?: string;
|
|
42
|
+
}
|
|
43
|
+
/** One reading of an `/api/ask` answer. A dissolve and a refusal both arrive as 200. */
|
|
44
|
+
export declare function readEnvelope(env: AskEnvelope, receiver: string): {
|
|
45
|
+
ok: true;
|
|
46
|
+
result: NonNullable<AskEnvelope['result']>;
|
|
47
|
+
} | {
|
|
48
|
+
ok: false;
|
|
49
|
+
error: string;
|
|
50
|
+
};
|
|
51
|
+
/** Parse a facts file. A file that is not an object is refused by name, never coerced. */
|
|
52
|
+
export declare function parseFacts(raw: string): {
|
|
53
|
+
ok: true;
|
|
54
|
+
facts: Record<string, unknown>;
|
|
55
|
+
} | {
|
|
56
|
+
ok: false;
|
|
57
|
+
error: string;
|
|
58
|
+
};
|
|
59
|
+
export declare function shopInit(deps: ShopInitDeps, opts: {
|
|
60
|
+
workspace: string;
|
|
61
|
+
facts?: Record<string, unknown>;
|
|
62
|
+
}): Promise<ShopInitResult>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `one shop init` — the terminal half of the shop pack.
|
|
3
|
+
*
|
|
4
|
+
* Pure on purpose: every round trip arrives through `deps.ask`, so the whole
|
|
5
|
+
* command is exercised without a network and without a key. `src/shop.ts` is
|
|
6
|
+
* the commander wiring and holds no logic of its own.
|
|
7
|
+
*
|
|
8
|
+
* TWO RECEIVERS, ONE OF WHICH MAY NOT BE THERE YET.
|
|
9
|
+
* `pages:instantiate-shop-pack` ships. `pages:fill-shop-pack` is C9.3 of
|
|
10
|
+
* `text/ecommerce-site-todo.md` and lands in parallel with this — and an
|
|
11
|
+
* unknown receiver DISSOLVES, which answers HTTP 200. So the fill leg is read
|
|
12
|
+
* for its outcome and reported separately: `seeded` and `filled` are two facts,
|
|
13
|
+
* and a shop whose pages exist but carry no facts must not report as either a
|
|
14
|
+
* clean success or a total failure.
|
|
15
|
+
*/
|
|
16
|
+
/** One reading of an `/api/ask` answer. A dissolve and a refusal both arrive as 200. */
|
|
17
|
+
export function readEnvelope(env, receiver) {
|
|
18
|
+
if (env.outcome && env.outcome !== 'result')
|
|
19
|
+
return { ok: false, error: `${receiver} ${env.outcome}` };
|
|
20
|
+
const result = env.result;
|
|
21
|
+
if (!result?.ok)
|
|
22
|
+
return { ok: false, error: result?.error ?? `${receiver} returned no result` };
|
|
23
|
+
return { ok: true, result };
|
|
24
|
+
}
|
|
25
|
+
/** Parse a facts file. A file that is not an object is refused by name, never coerced. */
|
|
26
|
+
export function parseFacts(raw) {
|
|
27
|
+
let parsed;
|
|
28
|
+
try {
|
|
29
|
+
parsed = JSON.parse(raw);
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
return { ok: false, error: `facts file is not valid JSON: ${e.message}` };
|
|
33
|
+
}
|
|
34
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
35
|
+
return { ok: false, error: 'facts file must be a JSON object of ShopBusinessFacts' };
|
|
36
|
+
}
|
|
37
|
+
return { ok: true, facts: parsed };
|
|
38
|
+
}
|
|
39
|
+
export async function shopInit(deps, opts) {
|
|
40
|
+
const fillRequested = opts.facts !== undefined;
|
|
41
|
+
const base = { ok: false, workspace: opts.workspace, pages: [], filled: false, fillRequested };
|
|
42
|
+
if (!opts.workspace)
|
|
43
|
+
return { ...base, error: 'no workspace — pass --workspace <slug>' };
|
|
44
|
+
const seedEnv = await deps.ask('pages:instantiate-shop-pack', { slug: opts.workspace });
|
|
45
|
+
const seed = readEnvelope(seedEnv, 'pages:instantiate-shop-pack');
|
|
46
|
+
if (!seed.ok)
|
|
47
|
+
return { ...base, error: seed.error };
|
|
48
|
+
// Today the receiver answers with ONE page; C9.1 answers with the whole pack.
|
|
49
|
+
// Read both rather than making this command wait on that cycle.
|
|
50
|
+
const listed = Array.isArray(seed.result.pages) ? seed.result.pages : [];
|
|
51
|
+
const pages = listed.map(p => p.slug).filter((s) => typeof s === 'string' && s.length > 0);
|
|
52
|
+
if (!pages.length && seed.result.slug)
|
|
53
|
+
pages.push(seed.result.slug);
|
|
54
|
+
if (!pages.length)
|
|
55
|
+
return { ...base, error: 'the pack seeded no pages' };
|
|
56
|
+
if (!fillRequested)
|
|
57
|
+
return { ...base, ok: true, pages };
|
|
58
|
+
const fillEnv = await deps.ask('pages:fill-shop-pack', { slug: opts.workspace, facts: opts.facts });
|
|
59
|
+
const fill = readEnvelope(fillEnv, 'pages:fill-shop-pack');
|
|
60
|
+
if (!fill.ok)
|
|
61
|
+
return { ...base, ok: true, pages, fillError: fill.error };
|
|
62
|
+
return { ...base, ok: true, pages, filled: true };
|
|
63
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
/**
|
|
3
|
+
* `one shop init` — twelve draft pages, and the seller's own facts written into
|
|
4
|
+
* them, from the terminal. A thin wrapper over two receivers (no new route):
|
|
5
|
+
* `pages:instantiate-shop-pack` then `pages:fill-shop-pack`. The receivers walk
|
|
6
|
+
* authority server-side; the API key identifies the caller.
|
|
7
|
+
*
|
|
8
|
+
* The logic lives in `lib/shop-init.ts` so it is tested without a network.
|
|
9
|
+
*/
|
|
10
|
+
export declare function shopCmd(): Command;
|
package/dist/src/shop.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { authHeaders, out, resolveBase } from './lib/client.js';
|
|
4
|
+
import { askPath } from './lib/api-path.js';
|
|
5
|
+
import { parseFacts, shopInit } from './lib/shop-init.js';
|
|
6
|
+
const DEFAULT_API = resolveBase({}, 'https://one.ie');
|
|
7
|
+
/**
|
|
8
|
+
* `one shop init` — twelve draft pages, and the seller's own facts written into
|
|
9
|
+
* them, from the terminal. A thin wrapper over two receivers (no new route):
|
|
10
|
+
* `pages:instantiate-shop-pack` then `pages:fill-shop-pack`. The receivers walk
|
|
11
|
+
* authority server-side; the API key identifies the caller.
|
|
12
|
+
*
|
|
13
|
+
* The logic lives in `lib/shop-init.ts` so it is tested without a network.
|
|
14
|
+
*/
|
|
15
|
+
export function shopCmd() {
|
|
16
|
+
const cmd = new Command('shop').description('Build a shop from the twelve-page pack');
|
|
17
|
+
cmd
|
|
18
|
+
.command('init')
|
|
19
|
+
.description('Seed the shop pack into a workspace, and fill it from a facts file')
|
|
20
|
+
.option('--facts <path>', 'JSON file of ShopBusinessFacts — a fact left out stays a visible placeholder')
|
|
21
|
+
.option('--workspace <slug>', 'Workspace to seed (defaults to ONEIE_WORKSPACE)')
|
|
22
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
23
|
+
.action(async (opts) => {
|
|
24
|
+
const workspace = opts.workspace ?? process.env.ONEIE_WORKSPACE ?? '';
|
|
25
|
+
if (!workspace) {
|
|
26
|
+
out(cmd, { ok: false, error: 'no workspace — pass --workspace <slug> or set ONEIE_WORKSPACE' });
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
let facts;
|
|
30
|
+
if (opts.facts) {
|
|
31
|
+
if (!existsSync(opts.facts)) {
|
|
32
|
+
out(cmd, { ok: false, error: `facts file not found: ${opts.facts}` });
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const parsed = parseFacts(readFileSync(opts.facts, 'utf8'));
|
|
36
|
+
if (!parsed.ok) {
|
|
37
|
+
out(cmd, { ok: false, error: parsed.error });
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
facts = parsed.facts;
|
|
41
|
+
}
|
|
42
|
+
const base = opts.api.replace(/\/$/, '');
|
|
43
|
+
const ask = async (receiver, data) => {
|
|
44
|
+
const res = await fetch(askPath(base, receiver), {
|
|
45
|
+
method: 'POST',
|
|
46
|
+
headers: { 'content-type': 'application/json', ...authHeaders() },
|
|
47
|
+
body: JSON.stringify({ data }),
|
|
48
|
+
});
|
|
49
|
+
// A transport-level failure is its own outcome — never a silent success.
|
|
50
|
+
if (!res.ok)
|
|
51
|
+
return { outcome: `http_${res.status}` };
|
|
52
|
+
return (await res.json());
|
|
53
|
+
};
|
|
54
|
+
const r = await shopInit({ ask }, { workspace, facts });
|
|
55
|
+
if (!r.ok) {
|
|
56
|
+
out(cmd, { ok: false, error: r.error ?? 'shop init failed' });
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
out(cmd, {
|
|
60
|
+
ok: true,
|
|
61
|
+
workspace: r.workspace,
|
|
62
|
+
pages: r.pages,
|
|
63
|
+
open: `/p/${r.pages[0]}`,
|
|
64
|
+
filled: r.filled,
|
|
65
|
+
...(r.fillError ? { fillError: r.fillError } : {}),
|
|
66
|
+
});
|
|
67
|
+
// The pages exist; the facts did not land. Both are true, and the exit
|
|
68
|
+
// code has to carry the half the caller asked for and did not get.
|
|
69
|
+
if (r.fillRequested && !r.filled)
|
|
70
|
+
process.exitCode = 1;
|
|
71
|
+
});
|
|
72
|
+
return cmd;
|
|
73
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oneie",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.1",
|
|
4
4
|
"description": "ONE agent CLI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"@oneie/sdk": "^0.16.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@oneie/evals": "^0.
|
|
26
|
+
"@oneie/evals": "^0.2.0",
|
|
27
27
|
"@types/node": "^25.6.0",
|
|
28
28
|
"tsx": "^4.0.0",
|
|
29
29
|
"typescript": "^5.4.0",
|