@oneie/cli 0.4.0 → 0.5.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/LICENSE +86 -0
- package/dist/src/agent.js +6 -2
- package/dist/src/args.d.ts +9 -0
- package/dist/src/args.js +61 -0
- package/dist/src/catalog.d.ts +1 -2
- package/dist/src/catalog.js +65 -36
- package/dist/src/client.d.ts +0 -1
- package/dist/src/client.js +71 -169
- package/dist/src/compiler.d.ts +15 -19
- package/dist/src/compiler.js +170 -219
- package/dist/src/config.d.ts +24 -0
- package/dist/src/config.js +70 -0
- package/dist/src/coordinate.d.ts +2 -2
- package/dist/src/coordinate.js +47 -61
- package/dist/src/create.d.ts +2 -0
- package/dist/src/create.js +231 -0
- package/dist/src/deploy.d.ts +0 -1
- package/dist/src/deploy.js +8 -35
- package/dist/src/env.d.ts +3 -6
- package/dist/src/env.js +31 -24
- package/dist/src/fn.d.ts +2 -0
- package/dist/src/fn.js +73 -0
- package/dist/src/index.js +18 -8
- package/dist/src/init.d.ts +11 -0
- package/dist/src/init.js +107 -0
- package/dist/src/links.d.ts +5 -0
- package/dist/src/links.js +50 -0
- package/dist/src/push.d.ts +0 -1
- package/dist/src/push.js +44 -99
- package/dist/src/render.d.ts +17 -0
- package/dist/src/render.js +25 -0
- package/dist/src/setup.d.ts +0 -1
- package/dist/src/setup.js +47 -134
- package/dist/src/ship.d.ts +0 -1
- package/dist/src/ship.js +13 -36
- package/dist/src/slug.d.ts +2 -5
- package/dist/src/slug.js +4 -7
- package/dist/src/status.d.ts +0 -1
- package/dist/src/status.js +29 -42
- package/dist/src/trade.d.ts +1 -2
- package/dist/src/trade.js +71 -74
- package/dist/src/trail.d.ts +2 -0
- package/dist/src/trail.js +47 -0
- package/dist/src/validate.d.ts +11 -10
- package/dist/src/validate.js +32 -34
- package/package.json +2 -2
package/dist/src/compiler.js
CHANGED
|
@@ -1,250 +1,201 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import { readSecret } from './env.js';
|
|
11
|
-
/** Minimal TOML parser — supports top-level scalars + array tables ([[section]]). */
|
|
12
|
-
export function parseToml(text) {
|
|
13
|
-
const result = {};
|
|
14
|
-
let currentSection = null;
|
|
15
|
-
for (const rawLine of text.split('\n')) {
|
|
16
|
-
const line = rawLine.split('#')[0].trim();
|
|
17
|
-
if (!line)
|
|
1
|
+
import { readdirSync, readFileSync, statSync, existsSync } from 'node:fs';
|
|
2
|
+
import { join, basename } from 'node:path';
|
|
3
|
+
/** Minimal TOML parser: key="v", key=123, key=true, [section], key=["a","b"] */
|
|
4
|
+
export function parseToml(src) {
|
|
5
|
+
const root = {};
|
|
6
|
+
let current = root;
|
|
7
|
+
for (const rawLine of src.split('\n')) {
|
|
8
|
+
const line = rawLine.trim();
|
|
9
|
+
if (!line || line.startsWith('#'))
|
|
18
10
|
continue;
|
|
19
|
-
if (line.startsWith('[[') && line.endsWith(']]')) {
|
|
20
|
-
currentSection = line.slice(2, -2).trim();
|
|
21
|
-
if (!Array.isArray(result[currentSection]))
|
|
22
|
-
result[currentSection] = [];
|
|
23
|
-
result[currentSection].push({});
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
11
|
if (line.startsWith('[') && line.endsWith(']')) {
|
|
27
|
-
|
|
12
|
+
const key = line.slice(1, -1).trim();
|
|
13
|
+
if (!root[key])
|
|
14
|
+
root[key] = {};
|
|
15
|
+
current = root[key];
|
|
28
16
|
continue;
|
|
29
17
|
}
|
|
30
18
|
const eq = line.indexOf('=');
|
|
31
|
-
if (eq
|
|
19
|
+
if (eq === -1)
|
|
32
20
|
continue;
|
|
33
|
-
const
|
|
21
|
+
const k = line.slice(0, eq).trim();
|
|
34
22
|
const raw = line.slice(eq + 1).trim();
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
val = true;
|
|
38
|
-
else if (raw === 'false')
|
|
39
|
-
val = false;
|
|
40
|
-
else if (!isNaN(Number(raw)) && raw !== '')
|
|
41
|
-
val = Number(raw);
|
|
42
|
-
else if (raw.startsWith('"') && raw.endsWith('"'))
|
|
43
|
-
val = raw.slice(1, -1);
|
|
44
|
-
else if (raw.startsWith("'") && raw.endsWith("'"))
|
|
45
|
-
val = raw.slice(1, -1);
|
|
46
|
-
else if (raw.startsWith('[') && raw.endsWith(']')) {
|
|
47
|
-
val = raw.slice(1, -1)
|
|
48
|
-
.split(',')
|
|
49
|
-
.map(v => v.trim().replace(/^["']|["']$/g, ''))
|
|
50
|
-
.filter(Boolean);
|
|
23
|
+
if (raw.startsWith('[')) {
|
|
24
|
+
current[k] = raw.slice(1, raw.lastIndexOf(']')).split(',').map((s) => s.trim().replace(/^["']|["']$/g, '')).filter(Boolean);
|
|
51
25
|
}
|
|
26
|
+
else if (raw === 'true')
|
|
27
|
+
current[k] = true;
|
|
28
|
+
else if (raw === 'false')
|
|
29
|
+
current[k] = false;
|
|
30
|
+
else if (!Number.isNaN(Number(raw)) && raw !== '')
|
|
31
|
+
current[k] = Number(raw);
|
|
52
32
|
else
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
33
|
+
current[k] = raw.replace(/^["']|["']$/g, '');
|
|
34
|
+
}
|
|
35
|
+
return root;
|
|
36
|
+
}
|
|
37
|
+
function walk(dir, ext) {
|
|
38
|
+
if (!existsSync(dir))
|
|
39
|
+
return [];
|
|
40
|
+
const result = [];
|
|
41
|
+
for (const entry of readdirSync(dir)) {
|
|
42
|
+
const full = join(dir, entry);
|
|
43
|
+
if (statSync(full).isDirectory())
|
|
44
|
+
result.push(...walk(full, ext));
|
|
45
|
+
else if (entry.endsWith(ext) && !entry.startsWith('_'))
|
|
46
|
+
result.push(full);
|
|
62
47
|
}
|
|
63
48
|
return result;
|
|
64
49
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
50
|
+
function frontmatter(md) {
|
|
51
|
+
const m = md.match(/^---\n([\s\S]*?)\n---/);
|
|
52
|
+
if (!m)
|
|
53
|
+
return {};
|
|
54
|
+
const out = {};
|
|
55
|
+
for (const line of m[1].split('\n')) {
|
|
56
|
+
const kv = line.match(/^([A-Za-z_][\w-]*)\s*:\s*(.*)$/);
|
|
57
|
+
if (kv)
|
|
58
|
+
out[kv[1]] = kv[2].trim();
|
|
71
59
|
}
|
|
72
|
-
return
|
|
60
|
+
return out;
|
|
73
61
|
}
|
|
74
|
-
function
|
|
75
|
-
|
|
76
|
-
return [];
|
|
77
|
-
return readdirSync(dir, { withFileTypes: true })
|
|
78
|
-
.filter(e => e.isFile() && pattern.test(e.name))
|
|
79
|
-
.map(e => join(dir, e.name));
|
|
62
|
+
function safeSlug(s) {
|
|
63
|
+
return s.toLowerCase().replace(/[^a-z0-9-]/g, '-').replace(/-+/g, '-').replace(/^-|-$/g, '');
|
|
80
64
|
}
|
|
81
|
-
function
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
65
|
+
function namespaced(agency, name) {
|
|
66
|
+
return `${safeSlug(agency)}--${safeSlug(name)}`;
|
|
67
|
+
}
|
|
68
|
+
/** Merge clientSlug's ai/ + data/ over root items by basename. Client file wins. */
|
|
69
|
+
function mergeClient(base, clientDir, slug, agencySlug) {
|
|
70
|
+
if (!existsSync(clientDir))
|
|
71
|
+
return base;
|
|
72
|
+
const byBase = new Map(base.map((item) => [basename(item.path), item]));
|
|
73
|
+
// Walk client dir for any .md and .toml files
|
|
74
|
+
for (const sub of ['ai/agents', 'ai/skills', 'data/lifecycles', 'data/types']) {
|
|
75
|
+
const dir = join(clientDir, sub);
|
|
76
|
+
if (!existsSync(dir))
|
|
77
|
+
continue;
|
|
78
|
+
for (const f of readdirSync(dir)) {
|
|
79
|
+
if (f.startsWith('_'))
|
|
80
|
+
continue;
|
|
81
|
+
const full = join(dir, f);
|
|
82
|
+
if (!statSync(full).isFile())
|
|
83
|
+
continue;
|
|
84
|
+
const content = readFileSync(full, 'utf8');
|
|
85
|
+
// Build a replacement item for this file
|
|
86
|
+
let item = null;
|
|
87
|
+
if (f.endsWith('.md')) {
|
|
88
|
+
const fm = frontmatter(content);
|
|
89
|
+
if (!fm.name)
|
|
90
|
+
continue;
|
|
91
|
+
const name = namespaced(`${agencySlug}--${safeSlug(slug)}`, fm.name);
|
|
92
|
+
const type = sub.includes('agents') ? 'agent' : 'skill';
|
|
93
|
+
item = { path: full, receiver: 'world:create-thing', payload: { name, type, md: content } };
|
|
94
|
+
}
|
|
95
|
+
else if (f.endsWith('.toml') && sub.includes('lifecycles')) {
|
|
96
|
+
const toml = parseToml(content);
|
|
97
|
+
const lifecycle = String(toml.lifecycle ?? basename(f, '.toml'));
|
|
98
|
+
item = { path: full, receiver: 'lifecycle:save', payload: { slug, lifecycle, def: content } };
|
|
99
|
+
}
|
|
100
|
+
if (item)
|
|
101
|
+
byBase.set(f, item);
|
|
91
102
|
}
|
|
92
103
|
}
|
|
93
|
-
return
|
|
104
|
+
return [...byBase.values()];
|
|
94
105
|
}
|
|
95
|
-
async function
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
+
export async function compileNode(dir, agencySlug, opts) {
|
|
107
|
+
const compiled = [];
|
|
108
|
+
const errors = [];
|
|
109
|
+
// ai/agents/*.md → world:create-thing (agent)
|
|
110
|
+
for (const f of walk(join(dir, 'ai', 'agents'), '.md')) {
|
|
111
|
+
try {
|
|
112
|
+
const md = readFileSync(f, 'utf8');
|
|
113
|
+
const fm = frontmatter(md);
|
|
114
|
+
if (!fm.name) {
|
|
115
|
+
errors.push({ path: f, message: 'frontmatter `name` required' });
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (!fm.description) {
|
|
119
|
+
errors.push({ path: f, message: 'frontmatter `description` required' });
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
compiled.push({ path: f, receiver: 'world:create-thing', payload: { name: namespaced(agencySlug, fm.name), type: 'agent', md } });
|
|
106
123
|
}
|
|
107
|
-
|
|
108
|
-
|
|
124
|
+
catch (e) {
|
|
125
|
+
errors.push({ path: f, message: String(e) });
|
|
109
126
|
}
|
|
110
127
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
instructions: body,
|
|
126
|
-
model: fm['model'] ?? 'openrouter/auto',
|
|
127
|
-
});
|
|
128
|
+
// ai/skills/*/SKILL.md → world:create-thing (skill)
|
|
129
|
+
for (const f of walk(join(dir, 'ai', 'skills'), 'SKILL.md')) {
|
|
130
|
+
try {
|
|
131
|
+
const md = readFileSync(f, 'utf8');
|
|
132
|
+
const fm = frontmatter(md);
|
|
133
|
+
if (!fm.name) {
|
|
134
|
+
errors.push({ path: f, message: 'frontmatter `name` required' });
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
compiled.push({ path: f, receiver: 'world:create-thing', payload: { name: namespaced(agencySlug, fm.name), type: 'skill', md } });
|
|
138
|
+
}
|
|
139
|
+
catch (e) {
|
|
140
|
+
errors.push({ path: f, message: String(e) });
|
|
141
|
+
}
|
|
128
142
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
const name = namespaced(ctx.agencySlug, rawName);
|
|
135
|
-
await askApi(ctx, 'world:create-thing', {
|
|
136
|
-
slug: ctx.slug,
|
|
137
|
-
type: 'skill',
|
|
138
|
-
name,
|
|
139
|
-
description: fm['description'] ?? '',
|
|
140
|
-
instructions: body,
|
|
141
|
-
});
|
|
143
|
+
// ai/context.md → settings:write
|
|
144
|
+
const contextPath = join(dir, 'ai', 'context.md');
|
|
145
|
+
if (existsSync(contextPath)) {
|
|
146
|
+
const value = readFileSync(contextPath, 'utf8');
|
|
147
|
+
compiled.push({ path: contextPath, receiver: 'settings:write', payload: { slug: agencySlug, key: 'company_context', value } });
|
|
142
148
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const value = readFileSync(file, 'utf8').trim();
|
|
149
|
-
await askApi(ctx, 'settings:write', { slug: ctx.slug, key: 'company_context', value });
|
|
150
|
-
}
|
|
151
|
-
async function compileTools(ctx, aiDir) {
|
|
152
|
-
for (const file of glob(join(aiDir, 'tools'), /\.toml$/)) {
|
|
153
|
-
const cfg = parseToml(readFileSync(file, 'utf8'));
|
|
154
|
-
const toolkit = String(cfg['toolkit'] ?? basename(file, '.toml'));
|
|
155
|
-
const mode = String(cfg['mode'] ?? 'api_key');
|
|
156
|
-
if (mode === 'oauth') {
|
|
157
|
-
ctx.skipped.push(`tools:connect ${toolkit} — OAuth; run: one connect ${toolkit} --for ${ctx.slug}`);
|
|
158
|
-
continue;
|
|
149
|
+
// ai/tools/*.toml → tools:connect
|
|
150
|
+
for (const f of walk(join(dir, 'ai', 'tools'), '.toml')) {
|
|
151
|
+
try {
|
|
152
|
+
const toml = parseToml(readFileSync(f, 'utf8'));
|
|
153
|
+
compiled.push({ path: f, receiver: 'tools:connect', payload: { slug: agencySlug, toolkit: String(toml.toolkit ?? basename(f, '.toml')), mode: String(toml.mode ?? 'api') } });
|
|
159
154
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
if (!credential) {
|
|
163
|
-
ctx.skipped.push(`tools:connect ${toolkit} — ${envVar} not set in .env.local or env`);
|
|
164
|
-
continue;
|
|
155
|
+
catch (e) {
|
|
156
|
+
errors.push({ path: f, message: String(e) });
|
|
165
157
|
}
|
|
166
|
-
await askApi(ctx, 'tools:connect', { slug: ctx.slug, toolkit, credentials: { api_key: credential } });
|
|
167
158
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
monotonic: Boolean(raw['monotonic'] ?? true),
|
|
178
|
-
stages: (raw['stages'] ?? []).map(s => ({
|
|
179
|
-
id: String(s['id'] ?? ''),
|
|
180
|
-
label: String(s['label'] ?? ''),
|
|
181
|
-
tag: String(s['tag'] ?? `lifecycle:${lifecycle}:${s['id']}`),
|
|
182
|
-
slot: Number(s['slot'] ?? 0),
|
|
183
|
-
subSteps: (s['sub_steps'] ?? []),
|
|
184
|
-
enter_when: (s['enter_when'] == null || s['enter_when'] === 'null')
|
|
185
|
-
? null : String(s['enter_when']),
|
|
186
|
-
})),
|
|
187
|
-
transitions: (raw['transitions'] ?? []).map(t => ({
|
|
188
|
-
source: String(t['source'] ?? ''),
|
|
189
|
-
target: String(t['target'] ?? ''),
|
|
190
|
-
kind: String(t['kind'] ?? 'forward'),
|
|
191
|
-
})),
|
|
192
|
-
arcs: (raw['arcs'] ?? []).map(a => ({
|
|
193
|
-
row: Number(a['row'] ?? 0),
|
|
194
|
-
label: String(a['label'] ?? ''),
|
|
195
|
-
})),
|
|
196
|
-
};
|
|
197
|
-
await askApi(ctx, 'lifecycle:save', { slug: ctx.slug, lifecycle, def });
|
|
159
|
+
// data/types/*.toml → world:declare-types
|
|
160
|
+
for (const f of walk(join(dir, 'data', 'types'), '.toml')) {
|
|
161
|
+
try {
|
|
162
|
+
const toml = parseToml(readFileSync(f, 'utf8'));
|
|
163
|
+
compiled.push({ path: f, receiver: 'world:declare-types', payload: { slug: agencySlug, types: toml } });
|
|
164
|
+
}
|
|
165
|
+
catch (e) {
|
|
166
|
+
errors.push({ path: f, message: String(e) });
|
|
167
|
+
}
|
|
198
168
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
169
|
+
// data/lifecycles/*.toml → lifecycle:save
|
|
170
|
+
for (const f of walk(join(dir, 'data', 'lifecycles'), '.toml')) {
|
|
171
|
+
try {
|
|
172
|
+
const src = readFileSync(f, 'utf8');
|
|
173
|
+
const toml = parseToml(src);
|
|
174
|
+
const lifecycle = String(toml.lifecycle ?? basename(f, '.toml'));
|
|
175
|
+
compiled.push({ path: f, receiver: 'lifecycle:save', payload: { slug: agencySlug, lifecycle, def: src } });
|
|
176
|
+
}
|
|
177
|
+
catch (e) {
|
|
178
|
+
errors.push({ path: f, message: String(e) });
|
|
179
|
+
}
|
|
204
180
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
slug: opts.targetSlug,
|
|
219
|
-
agencySlug: opts.agencySlug,
|
|
220
|
-
rootDir: opts.rootDir,
|
|
221
|
-
dry: opts.dry,
|
|
222
|
-
pushed: [],
|
|
223
|
-
skipped: [],
|
|
224
|
-
errors: [],
|
|
225
|
-
};
|
|
226
|
-
// Resolve effective dirs — client overrides root when both exist
|
|
227
|
-
const aiDirs = [
|
|
228
|
-
join(opts.rootDir, 'ai'),
|
|
229
|
-
...(opts.clientDir ? [join(opts.clientDir, 'ai')] : []),
|
|
230
|
-
];
|
|
231
|
-
const dataDirs = [
|
|
232
|
-
join(opts.rootDir, 'data'),
|
|
233
|
-
...(opts.clientDir ? [join(opts.clientDir, 'data')] : []),
|
|
234
|
-
];
|
|
235
|
-
for (const aiDir of aiDirs) {
|
|
236
|
-
if (!existsSync(aiDir))
|
|
237
|
-
continue;
|
|
238
|
-
await compileAgents(ctx, aiDir);
|
|
239
|
-
await compileSkills(ctx, aiDir);
|
|
240
|
-
await compileContext(ctx, aiDir);
|
|
241
|
-
await compileTools(ctx, aiDir);
|
|
181
|
+
// data/content/contacts.csv → people:create (batch)
|
|
182
|
+
const contactsPath = join(dir, 'data', 'content', 'contacts.csv');
|
|
183
|
+
if (existsSync(contactsPath)) {
|
|
184
|
+
const csv = readFileSync(contactsPath, 'utf8');
|
|
185
|
+
const [headerLine, ...rows] = csv.trim().split('\n');
|
|
186
|
+
const headers = (headerLine ?? '').split(',').map((h) => h.trim());
|
|
187
|
+
const contacts = rows.map((row) => {
|
|
188
|
+
const vals = row.split(',').map((v) => v.trim());
|
|
189
|
+
return Object.fromEntries(headers.map((h, i) => [h, vals[i] ?? '']));
|
|
190
|
+
});
|
|
191
|
+
if (contacts.length > 0) {
|
|
192
|
+
compiled.push({ path: contactsPath, receiver: 'people:create', payload: { slug: agencySlug, contacts } });
|
|
193
|
+
}
|
|
242
194
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
await compileTypes(ctx, dataDir);
|
|
195
|
+
// Client inheritance: clients/<slug>/ merges over root by basename
|
|
196
|
+
if (opts?.clientSlug) {
|
|
197
|
+
const clientDir = join(dir, 'clients', opts.clientSlug);
|
|
198
|
+
return { compiled: mergeClient(compiled, clientDir, opts.clientSlug, agencySlug), errors };
|
|
248
199
|
}
|
|
249
|
-
return {
|
|
200
|
+
return { compiled, errors };
|
|
250
201
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type Plan = 'free' | 'pro' | 'studio' | 'agency' | 'enterprise';
|
|
2
|
+
export interface AgencyConfig {
|
|
3
|
+
slug: string;
|
|
4
|
+
name: string;
|
|
5
|
+
plan: Plan;
|
|
6
|
+
markup_pct: number;
|
|
7
|
+
brand?: boolean;
|
|
8
|
+
pool?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface ClientConfig {
|
|
11
|
+
name: string;
|
|
12
|
+
slug: string;
|
|
13
|
+
owner?: string;
|
|
14
|
+
plan: Plan;
|
|
15
|
+
markup_pct?: number;
|
|
16
|
+
monthly_cap?: number;
|
|
17
|
+
brand_lock?: boolean;
|
|
18
|
+
credits?: number;
|
|
19
|
+
agents?: string[];
|
|
20
|
+
}
|
|
21
|
+
/** Minimal TOML parser: handles key = "value", key = 123, key = true, [section] headers, key = ["a","b"]. */
|
|
22
|
+
export declare function parseToml(src: string): Record<string, unknown>;
|
|
23
|
+
export declare function readAgency(path?: string): AgencyConfig;
|
|
24
|
+
export declare function readClient(path: string): ClientConfig;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
/** Minimal TOML parser: handles key = "value", key = 123, key = true, [section] headers, key = ["a","b"]. */
|
|
3
|
+
export function parseToml(src) {
|
|
4
|
+
const root = {};
|
|
5
|
+
let current = root;
|
|
6
|
+
for (const rawLine of src.split('\n')) {
|
|
7
|
+
const line = rawLine.trim();
|
|
8
|
+
if (!line || line.startsWith('#'))
|
|
9
|
+
continue;
|
|
10
|
+
if (line.startsWith('[') && line.endsWith(']')) {
|
|
11
|
+
const key = line.slice(1, -1).trim();
|
|
12
|
+
if (!root[key])
|
|
13
|
+
root[key] = {};
|
|
14
|
+
current = root[key];
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
const eq = line.indexOf('=');
|
|
18
|
+
if (eq === -1)
|
|
19
|
+
continue;
|
|
20
|
+
const k = line.slice(0, eq).trim();
|
|
21
|
+
const raw = line.slice(eq + 1).trim();
|
|
22
|
+
if (raw.startsWith('[')) {
|
|
23
|
+
// simple inline array of strings
|
|
24
|
+
current[k] = raw.slice(1, raw.lastIndexOf(']')).split(',').map((s) => s.trim().replace(/^["']|["']$/g, '')).filter(Boolean);
|
|
25
|
+
}
|
|
26
|
+
else if (raw === 'true')
|
|
27
|
+
current[k] = true;
|
|
28
|
+
else if (raw === 'false')
|
|
29
|
+
current[k] = false;
|
|
30
|
+
else if (!Number.isNaN(Number(raw)) && raw !== '')
|
|
31
|
+
current[k] = Number(raw);
|
|
32
|
+
else
|
|
33
|
+
current[k] = raw.replace(/^["']|["']$/g, '');
|
|
34
|
+
}
|
|
35
|
+
return root;
|
|
36
|
+
}
|
|
37
|
+
function readToml(path) {
|
|
38
|
+
if (!existsSync(path))
|
|
39
|
+
throw new Error(`not found: ${path}`);
|
|
40
|
+
return parseToml(readFileSync(path, 'utf8'));
|
|
41
|
+
}
|
|
42
|
+
export function readAgency(path = '_node.toml') {
|
|
43
|
+
const raw = readToml(path);
|
|
44
|
+
if (!raw.slug || !raw.name)
|
|
45
|
+
throw new Error(`${path}: 'slug' and 'name' are required`);
|
|
46
|
+
return {
|
|
47
|
+
slug: String(raw.slug),
|
|
48
|
+
name: String(raw.name),
|
|
49
|
+
plan: raw.plan ?? 'agency',
|
|
50
|
+
markup_pct: Number(raw.markup_pct ?? 0),
|
|
51
|
+
brand: Boolean(raw.brand ?? false),
|
|
52
|
+
pool: raw.pool != null ? Number(raw.pool) : undefined,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export function readClient(path) {
|
|
56
|
+
const raw = readToml(path);
|
|
57
|
+
if (!raw.slug || !raw.name)
|
|
58
|
+
throw new Error(`${path}: 'slug' and 'name' are required`);
|
|
59
|
+
return {
|
|
60
|
+
name: String(raw.name),
|
|
61
|
+
slug: String(raw.slug),
|
|
62
|
+
owner: raw.owner != null ? String(raw.owner) : undefined,
|
|
63
|
+
plan: raw.plan ?? 'studio',
|
|
64
|
+
markup_pct: raw.markup_pct != null ? Number(raw.markup_pct) : undefined,
|
|
65
|
+
monthly_cap: raw.monthly_cap != null ? Number(raw.monthly_cap) : undefined,
|
|
66
|
+
brand_lock: raw.brand_lock != null ? Boolean(raw.brand_lock) : undefined,
|
|
67
|
+
credits: raw.credits != null ? Number(raw.credits) : undefined,
|
|
68
|
+
agents: Array.isArray(raw.agents) ? raw.agents.map(String) : undefined,
|
|
69
|
+
};
|
|
70
|
+
}
|
package/dist/src/coordinate.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/** `one recall|reputation` — memory and reputation commands. */
|
|
2
1
|
import { Command } from 'commander';
|
|
3
|
-
export declare
|
|
2
|
+
export declare const REPUTATION_PENDING: string;
|
|
3
|
+
export declare function coordinateCommands(program: Command): void;
|
package/dist/src/coordinate.js
CHANGED
|
@@ -1,71 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
import { Command } from 'commander';
|
|
3
|
-
const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_BASE_URL ?? 'https://api.one.ie';
|
|
1
|
+
const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://api.one.ie';
|
|
4
2
|
function apiKey() {
|
|
5
3
|
return process.env.ONEIE_API_KEY ?? process.env.ONE_API_KEY ?? '';
|
|
6
4
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
method: 'POST',
|
|
10
|
-
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${apiKey()}` },
|
|
11
|
-
body: JSON.stringify({ data }),
|
|
12
|
-
});
|
|
13
|
-
return res.json();
|
|
5
|
+
function base(opts) {
|
|
6
|
+
return (opts.api ?? DEFAULT_API).replace(/\/$/, '');
|
|
14
7
|
}
|
|
15
|
-
function
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const d = data;
|
|
22
|
-
if (d?.kind === 'result') {
|
|
23
|
-
const r = d.result;
|
|
24
|
-
if (Array.isArray(r)) {
|
|
25
|
-
for (const item of r) {
|
|
26
|
-
process.stdout.write(` ${JSON.stringify(item)}\n`);
|
|
27
|
-
}
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
if (typeof r === 'object' && r !== null) {
|
|
31
|
-
for (const [k, v] of Object.entries(r)) {
|
|
32
|
-
if (typeof v !== 'object')
|
|
33
|
-
process.stdout.write(` ${k}: ${v}\n`);
|
|
34
|
-
}
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
process.stdout.write(JSON.stringify(data, null, 2) + '\n');
|
|
8
|
+
function authHeaders() {
|
|
9
|
+
const h = { 'Content-Type': 'application/json' };
|
|
10
|
+
const k = apiKey();
|
|
11
|
+
if (k)
|
|
12
|
+
h['Authorization'] = `Bearer ${k}`;
|
|
13
|
+
return h;
|
|
39
14
|
}
|
|
40
|
-
export
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
.
|
|
54
|
-
.argument('[uid]', 'Agent uid to commend (omit to show own reputation)')
|
|
55
|
-
.option('--commend', 'Send a commendation signal')
|
|
15
|
+
export const REPUTATION_PENDING = 'reputation: pending — meta:reputation is not yet shipped (agent-first follow-on).\n' +
|
|
16
|
+
' Standing lives in TypeDB paths; until the receiver lands, one shows no score (no stub).';
|
|
17
|
+
function formatRecall(out) {
|
|
18
|
+
const hyps = (out?.hypotheses ?? []);
|
|
19
|
+
if (!hyps.length)
|
|
20
|
+
return ' (no memory yet — recall returns what this caller has learned)';
|
|
21
|
+
return hyps.map((h) => ` · [${h.status}] ${h.claim}${h.confidence != null ? ` (${h.confidence})` : ''}`).join('\n');
|
|
22
|
+
}
|
|
23
|
+
export function coordinateCommands(program) {
|
|
24
|
+
program
|
|
25
|
+
.command('recall')
|
|
26
|
+
.description('Read cross-session memory (meta:recall)')
|
|
27
|
+
.option('--about <term>', 'Filter by keyword')
|
|
28
|
+
.option('--limit <n>', 'Max results', '20')
|
|
56
29
|
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
57
|
-
.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
30
|
+
.option('--json', 'Output raw JSON')
|
|
31
|
+
.action(async (opts) => {
|
|
32
|
+
const payload = { limit: Number(opts.limit) };
|
|
33
|
+
if (opts.about)
|
|
34
|
+
payload.match = opts.about;
|
|
35
|
+
const res = await fetch(`${base(opts)}/api/ask/${encodeURIComponent('meta:recall')}`, {
|
|
36
|
+
method: 'POST',
|
|
37
|
+
headers: authHeaders(),
|
|
38
|
+
body: JSON.stringify({ data: payload }),
|
|
39
|
+
});
|
|
40
|
+
if (!res.ok) {
|
|
41
|
+
process.stderr.write(`meta:recall → ${res.status}\n`);
|
|
42
|
+
process.exit(1);
|
|
62
43
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
out(cmd, result);
|
|
44
|
+
const data = await res.json();
|
|
45
|
+
if (opts.json) {
|
|
46
|
+
process.stdout.write(JSON.stringify(data, null, 2) + '\n');
|
|
47
|
+
return;
|
|
68
48
|
}
|
|
49
|
+
process.stdout.write(formatRecall(data) + '\n');
|
|
50
|
+
});
|
|
51
|
+
program
|
|
52
|
+
.command('reputation')
|
|
53
|
+
.description('Agent reputation standing (pending)')
|
|
54
|
+
.action(() => {
|
|
55
|
+
process.stdout.write(REPUTATION_PENDING + '\n');
|
|
69
56
|
});
|
|
70
|
-
return cmd;
|
|
71
57
|
}
|