poad 2.42.0 → 2.45.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/global/ai/index.js +279 -0
- package/global/ai/list.js +5 -0
- package/global/ai/login.js +5 -0
- package/global/ai/logout.js +5 -0
- package/global/ai/models.js +5 -0
- package/global/ai/use.js +5 -0
- package/global/cli.js +8 -0
- package/global/run.js +7 -0
- package/global/start.js +17 -0
- package/global/stop.js +1 -0
- package/package.json +1 -1
- package/poad.js +12 -8
- package/project/cli.js +1 -1
- package/project/logs.js +3 -0
- package/project/setup.js +2 -0
- package/test/ai-catalog.test.js +117 -0
- package/test/ai.test.js +187 -0
- package/test/console-services.test.js +90 -0
- package/test/fixtures-permalink-ai.json +233 -0
- package/test/help.test.js +7 -0
- package/utils/ai-catalog.js +148 -0
- package/utils/ai.js +178 -0
- package/utils/console-services.js +70 -0
- package/utils/keycloak.js +46 -0
- package/utils/logline.js +43 -5
- package/utils/mail.js +1 -0
package/test/ai.test.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
// poad ai : clés de la machine (~/.poad/ai.json, 0600), réglages [ai], filtres et rendu de poad logs ai.
|
|
2
|
+
// Sans réseau ni Docker : la commande tourne avec test/help-stub.js (tout appel à Docker, au réseau ou à un
|
|
3
|
+
// processus est refusé et noté) et un HOME à part. Fausses clés seulement.
|
|
4
|
+
const test = require('node:test');
|
|
5
|
+
const assert = require('node:assert');
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const { spawnSync } = require('child_process');
|
|
9
|
+
const { tmpdir } = require('./helpers');
|
|
10
|
+
const ai = require('../utils/ai');
|
|
11
|
+
const { attrConditions, formatLine } = require('../utils/logline');
|
|
12
|
+
|
|
13
|
+
const POAD = path.join(__dirname, '..', 'poad.js');
|
|
14
|
+
const STUB = path.join(__dirname, 'help-stub.js');
|
|
15
|
+
const FAKE = 'sk-ant-FAKE-test-key-0000000000wxyz';
|
|
16
|
+
const plain = new Proxy(function () {}, { get: () => plain, apply: (t, self, [s]) => String(s) });
|
|
17
|
+
|
|
18
|
+
function sandbox(t) {
|
|
19
|
+
const dir = tmpdir(t);
|
|
20
|
+
const home = path.join(dir, 'home');
|
|
21
|
+
fs.mkdirSync(home);
|
|
22
|
+
// Pas de vérification de version (npm view) pendant l'essai
|
|
23
|
+
fs.writeFileSync(path.join(home, '.poad_last_check.json'), JSON.stringify({ date: new Date(), version: require('../package.json').version }));
|
|
24
|
+
return { dir, home, calls: path.join(dir, 'calls.log'), file: path.join(home, '.poad', 'ai.json') };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const poad = (box, args, input = '') =>
|
|
28
|
+
spawnSync(process.execPath, ['--require', STUB, POAD, ...args], {
|
|
29
|
+
cwd: box.dir,
|
|
30
|
+
encoding: 'utf8',
|
|
31
|
+
input,
|
|
32
|
+
timeout: 15000,
|
|
33
|
+
env: { ...process.env, HOME: box.home, POAD_TEST_CALLS: box.calls, NODE_OPTIONS: '', POAD_AI_KEYS_FILE: '' },
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('ai login : clé lue sur l’entrée standard, fichier 0600 dans un dossier 0700, jamais affichée', (t) => {
|
|
37
|
+
const box = sandbox(t);
|
|
38
|
+
const r = poad(box, ['ai', 'login', 'anthropic'], `${FAKE}\n`);
|
|
39
|
+
assert.strictEqual(r.status, 0, r.stderr);
|
|
40
|
+
assert.match(r.stdout, /key saved for this machine \(…wxyz\)/);
|
|
41
|
+
assert.ok(!r.stdout.includes(FAKE) && !r.stderr.includes(FAKE), 'la clé ne s’affiche jamais');
|
|
42
|
+
assert.strictEqual(fs.statSync(box.file).mode & 0o777, 0o600);
|
|
43
|
+
assert.strictEqual(fs.statSync(path.dirname(box.file)).mode & 0o777, 0o700);
|
|
44
|
+
assert.strictEqual(JSON.parse(fs.readFileSync(box.file, 'utf8')).providers.anthropic.key, FAKE);
|
|
45
|
+
assert.ok(!fs.existsSync(box.calls), 'ni Docker, ni réseau, ni processus');
|
|
46
|
+
|
|
47
|
+
const list = poad(box, ['ai', 'list']);
|
|
48
|
+
assert.match(list.stdout, /anthropic\s+…wxyz/);
|
|
49
|
+
assert.match(list.stdout, /openai\s+no key/);
|
|
50
|
+
assert.ok(!list.stdout.includes(FAKE));
|
|
51
|
+
|
|
52
|
+
const out = poad(box, ['ai', 'logout', 'anthropic']);
|
|
53
|
+
assert.match(out.stdout, /removed/);
|
|
54
|
+
assert.deepStrictEqual(JSON.parse(fs.readFileSync(box.file, 'utf8')).providers, {});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('ai login : refus d’une clé vide ou mal formée, d’un fournisseur inconnu ; une clé en argument est signalée', (t) => {
|
|
58
|
+
const box = sandbox(t);
|
|
59
|
+
assert.match(poad(box, ['ai', 'login', 'openai'], 'a b c d e f g h\n').stdout, /Key refused \(a key has no spaces\)/);
|
|
60
|
+
assert.match(poad(box, ['ai', 'login', 'openai'], '').stdout, /Key refused \(empty key\)/);
|
|
61
|
+
assert.ok(!fs.existsSync(box.file));
|
|
62
|
+
assert.match(poad(box, ['ai', 'login', 'llama']).stdout, /Usage: poad ai login/);
|
|
63
|
+
const arg = poad(box, ['ai', 'login', FAKE]);
|
|
64
|
+
assert.match(arg.stdout, /Never pass a key as an argument/);
|
|
65
|
+
assert.ok(!arg.stdout.includes(FAKE));
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('ai use : hors d’un projet, le dit sans rien appeler', (t) => {
|
|
69
|
+
const box = sandbox(t);
|
|
70
|
+
poad(box, ['ai', 'login', 'mistral'], 'mistral-fake-key-123456\n');
|
|
71
|
+
const r = poad(box, ['ai', 'use', 'mistral']);
|
|
72
|
+
assert.match(r.stdout, /not in a poad project/);
|
|
73
|
+
assert.ok(!fs.existsSync(box.calls));
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('readKeys : un fichier lisible par d’autres est ramené à 0600 ; un fichier abîmé est signalé sans contenu', (t) => {
|
|
77
|
+
const box = sandbox(t);
|
|
78
|
+
fs.mkdirSync(path.dirname(box.file), { recursive: true });
|
|
79
|
+
fs.writeFileSync(box.file, JSON.stringify({ providers: { gemini: { key: 'AIzaFAKEFAKEFAKE1234' } } }), { mode: 0o644 });
|
|
80
|
+
fs.chmodSync(box.file, 0o644);
|
|
81
|
+
const k = ai.readKeys(box.file);
|
|
82
|
+
assert.strictEqual(k.fixed, true);
|
|
83
|
+
assert.strictEqual(fs.statSync(box.file).mode & 0o777, 0o600);
|
|
84
|
+
assert.strictEqual(k.providers.gemini.key, 'AIzaFAKEFAKEFAKE1234');
|
|
85
|
+
fs.writeFileSync(box.file, `{ "providers": ${FAKE}`);
|
|
86
|
+
const broken = ai.readKeys(box.file);
|
|
87
|
+
assert.match(broken.broken, /not valid JSON/);
|
|
88
|
+
assert.ok(!broken.broken.includes(FAKE));
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('masque et forme des clés', () => {
|
|
92
|
+
assert.strictEqual(ai.mask(FAKE), '…wxyz');
|
|
93
|
+
assert.strictEqual(ai.mask('court'), '…');
|
|
94
|
+
assert.strictEqual(ai.mask(''), '');
|
|
95
|
+
assert.strictEqual(ai.keyProblem(FAKE), null);
|
|
96
|
+
assert.match(ai.keyProblem('abc'), /8 to 512/);
|
|
97
|
+
assert.match(ai.keyProblem('clé-é-é-é-é'), /ASCII/);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('[ai] de config.toml → variables de l’engine ; une valeur fausse est dite et pas transmise', () => {
|
|
101
|
+
const { env, warnings } = ai.engineEnv({
|
|
102
|
+
ai: { default_provider: 'mistral', default_model: 'mistral-small-latest', max_tokens: 2048, monthly_budget_usd: 12.5, log_content: true, prices: { 'openai/gpt-x': { input: 1, output: 2 } } },
|
|
103
|
+
});
|
|
104
|
+
assert.deepStrictEqual(env, [
|
|
105
|
+
'POAD_AI_DEFAULT_PROVIDER=mistral',
|
|
106
|
+
'POAD_AI_DEFAULT_MODEL=mistral-small-latest',
|
|
107
|
+
'POAD_AI_MAX_TOKENS=2048',
|
|
108
|
+
'POAD_AI_MONTHLY_BUDGET_USD=12.5',
|
|
109
|
+
'POAD_AI_LOG_CONTENT=true',
|
|
110
|
+
'POAD_AI_PRICES={"openai/gpt-x":{"input":1,"output":2}}',
|
|
111
|
+
]);
|
|
112
|
+
assert.deepStrictEqual(warnings, []);
|
|
113
|
+
const bad = ai.engineEnv({ ai: { default_provider: 'llama', max_tokens: -1, monthly_budget_usd: 'beaucoup', default_model: 'a b' } });
|
|
114
|
+
assert.deepStrictEqual(bad.env, []);
|
|
115
|
+
assert.strictEqual(bad.warnings.length, 4);
|
|
116
|
+
assert.deepStrictEqual(ai.engineEnv({}), { env: [], warnings: [] });
|
|
117
|
+
assert.strictEqual(ai.supportsAi({ engine: '0.30.0' }), true);
|
|
118
|
+
assert.strictEqual(ai.supportsAi({ engine: '0.30.0-ai.1' }), true);
|
|
119
|
+
assert.strictEqual(ai.supportsAi({ engine: '0.29.2' }), false);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test('logs : provider= et model= portent sur les attributs du même nom', () => {
|
|
123
|
+
const r = attrConditions({ provider: 'openai', model: 'gpt-5', outcome: 'budget_exceeded' });
|
|
124
|
+
assert.deepStrictEqual(r.conditions, [
|
|
125
|
+
["attrs->>'outcome' = ?", 'budget_exceeded'],
|
|
126
|
+
["attrs->>'provider' = ?", 'openai'],
|
|
127
|
+
["attrs->>'model' = ?", 'gpt-5'],
|
|
128
|
+
]);
|
|
129
|
+
assert.match(attrConditions({ provider: true }).error, /provider=<name>: a value is expected, such as provider=anthropic/);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test('logs : rendu d’une ligne ai (résultat, jetons, coût estimé ; une seule durée)', () => {
|
|
133
|
+
const line = formatLine(
|
|
134
|
+
{
|
|
135
|
+
ts: '2026-11-25T10:00:00.000Z',
|
|
136
|
+
level: 'info',
|
|
137
|
+
service: 'ai',
|
|
138
|
+
request_id: 'abcdef1234567890',
|
|
139
|
+
msg: 'chat anthropic/claude-opus-5-5 ok (812 ms)',
|
|
140
|
+
attrs: { provider: 'anthropic', model: 'claude-opus-5-5', outcome: 'ok', input_tokens: 1000, output_tokens: 500, cost_usd: 0.014, duration_ms: 812, function: 'resume' },
|
|
141
|
+
},
|
|
142
|
+
plain,
|
|
143
|
+
);
|
|
144
|
+
assert.match(line, /ai\s+info\s+\[resume\] chat anthropic\/claude-opus-5-5 ok \(812 ms\) 1000→500 tok ~\$0\.0140 ·abcdef12$/);
|
|
145
|
+
const refused = formatLine(
|
|
146
|
+
{ ts: '2026-11-25T10:00:00.000Z', level: 'warn', service: 'ai', msg: 'chat openai/gpt-5 provider_error (40 ms)', attrs: { outcome: 'provider_error', provider_status: 401, error_code: 'provider_error', error: 'openai refused the call (HTTP 401)', duration_ms: 40 } },
|
|
147
|
+
plain,
|
|
148
|
+
);
|
|
149
|
+
assert.match(refused, /provider_error \(40 ms\) HTTP 401 provider_error: openai refused the call \(HTTP 401\)$/);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test('logs : un appel ai sans prix connu dit « cost unknown », jamais $0', () => {
|
|
153
|
+
const line = formatLine(
|
|
154
|
+
{ ts: '2026-11-25T10:00:00.000Z', level: 'info', service: 'ai', msg: 'chat mistral/mistral-large-latest ok (9 ms)', attrs: { outcome: 'ok', input_tokens: 10, output_tokens: 5, cost_usd: null, price: 'unknown' } },
|
|
155
|
+
plain,
|
|
156
|
+
);
|
|
157
|
+
assert.match(line, /10→5 tok cost unknown \(no price: \[ai\.prices\]\)$/);
|
|
158
|
+
assert.ok(!line.includes('$0'));
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test('ai login : un ~/.poad déjà là en 0755 est ramené à 0700, ses autres fichiers gardent leurs droits', (t) => {
|
|
162
|
+
const box = sandbox(t);
|
|
163
|
+
const dir = path.dirname(box.file);
|
|
164
|
+
fs.mkdirSync(dir, { mode: 0o755 });
|
|
165
|
+
fs.chmodSync(dir, 0o755);
|
|
166
|
+
const other = path.join(dir, 'engine-latest.json');
|
|
167
|
+
fs.writeFileSync(other, '{}', { mode: 0o644 });
|
|
168
|
+
fs.chmodSync(other, 0o644);
|
|
169
|
+
const r = poad(box, ['ai', 'login', 'openai'], 'sk-proj-abcdefghijklmnopqrstuvwxyz\n');
|
|
170
|
+
assert.strictEqual(r.status, 0, r.stderr);
|
|
171
|
+
assert.strictEqual(fs.statSync(dir).mode & 0o777, 0o700);
|
|
172
|
+
assert.strictEqual(fs.statSync(box.file).mode & 0o777, 0o600);
|
|
173
|
+
assert.strictEqual(fs.statSync(other).mode & 0o777, 0o644);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test('coût : un montant positif sous 0,0001 $ s’écrit « < $0.0001 », jamais $0.0000', () => {
|
|
177
|
+
assert.strictEqual(ai.usdText(0.000018), '< $0.0001');
|
|
178
|
+
assert.strictEqual(ai.usdText(0.0002), '~$0.0002');
|
|
179
|
+
assert.strictEqual(ai.usdText(0), '~$0.0000');
|
|
180
|
+
assert.strictEqual(ai.usdText(null), null);
|
|
181
|
+
const line = formatLine(
|
|
182
|
+
{ ts: '2026-11-25T10:00:00.000Z', level: 'info', service: 'ai', msg: 'chat mistral/mistral-large-4 ok (1 ms)', attrs: { outcome: 'ok', input_tokens: 11, output_tokens: 5, cost_usd: 0.000018 } },
|
|
183
|
+
plain,
|
|
184
|
+
);
|
|
185
|
+
assert.match(line, /11→5 tok < \$0\.0001$/);
|
|
186
|
+
assert.ok(!line.includes('0.0000'));
|
|
187
|
+
});
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// Groupe « Services » de la console locale : poad/data/console/services.json
|
|
2
|
+
// liste Mailpit et Keycloak seulement s'ils sont activés dans config.toml, avec
|
|
3
|
+
// les ports de cette machine, sans aucun secret.
|
|
4
|
+
const test = require('node:test');
|
|
5
|
+
const assert = require('node:assert');
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const { tmpdir } = require('./helpers');
|
|
9
|
+
const services = require('../utils/console-services');
|
|
10
|
+
const shared = require('../utils/keycloak-shared');
|
|
11
|
+
|
|
12
|
+
const project = (t) => {
|
|
13
|
+
const dir = tmpdir(t);
|
|
14
|
+
fs.mkdirSync(path.join(dir, 'poad'));
|
|
15
|
+
const root = path.join(dir, 'poad', 'config.toml');
|
|
16
|
+
fs.writeFileSync(root, '');
|
|
17
|
+
return root;
|
|
18
|
+
};
|
|
19
|
+
const base = (extra = {}) => ({ project_id: 'demo', project_uuid: 'poad-test-not-a-container', db: { port: 54322 }, mail: { port: 54324 }, ...extra });
|
|
20
|
+
const DB = { id: 'db', port: 54322 };
|
|
21
|
+
const MAIL = { id: 'mail', url: 'http://localhost:54324/', smtp: 'mail:1025' };
|
|
22
|
+
const ids = (list) => list.map((s) => s.id);
|
|
23
|
+
|
|
24
|
+
test('projet neuf : PostgreSQL et Mailpit (pas de [smtp]), ni Keycloak ni Valkey', (t) => {
|
|
25
|
+
assert.deepStrictEqual(services.list(project(t), base()), [DB, MAIL]);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('Valkey configuré : port de la machine et adresse vue depuis l’engine', (t) => {
|
|
29
|
+
assert.deepStrictEqual(services.list(project(t), base({ valkey: { port: 6390 } })).at(-1), { id: 'valkey', port: 6390, engine_url: 'redis://valkey:6379' });
|
|
30
|
+
assert.deepStrictEqual(ids(services.list(project(t), base({ valkey: { autostart: true } }))), ['db', 'mail']);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('un vrai serveur SMTP ([smtp] host) : pas de serveur de mail à ouvrir', (t) => {
|
|
34
|
+
assert.deepStrictEqual(services.list(project(t), base({ smtp: { host: 'smtp.example.com', pass: 'x' } })), [DB]);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('Keycloak configuré (port) : console d’administration sur le realm du projet', (t) => {
|
|
38
|
+
const out = services.list(project(t), base({ keycloak: { port: 8081 } }));
|
|
39
|
+
assert.deepStrictEqual(out, [DB, MAIL, { id: 'keycloak', url: 'http://localhost:8081/admin/master/console/#/demo', realm: 'demo', shared: false }]);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('[keycloak] sans port ni shared (jamais lancé) : absent', (t) => {
|
|
43
|
+
assert.deepStrictEqual(ids(services.list(project(t), base({ keycloak: { autostart: false } }))), ['db', 'mail']);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('Keycloak partagé : port de la machine, realm propre au projet ; absent tant que le partagé n’a pas de port', (t) => {
|
|
47
|
+
const real = shared.readState;
|
|
48
|
+
t.after(() => (shared.readState = real));
|
|
49
|
+
shared.readState = () => ({ port: 8099, admin_password: 'NeSortJamais' });
|
|
50
|
+
const root = project(t);
|
|
51
|
+
const out = services.list(root, base({ keycloak: { shared: true } }));
|
|
52
|
+
const realm = shared.realmFor({ project_uuid: 'poad-test-not-a-container' }, 'demo');
|
|
53
|
+
assert.deepStrictEqual(out[2], { id: 'keycloak', url: `http://localhost:8099/admin/master/console/#/${realm}`, realm, shared: true });
|
|
54
|
+
assert.ok(!JSON.stringify(out).includes('NeSortJamais'));
|
|
55
|
+
shared.readState = () => null;
|
|
56
|
+
assert.deepStrictEqual(ids(services.list(root, base({ keycloak: { shared: true } }))), ['db', 'mail']);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('write : data/console/services.json, sans secret, réécrit à chaque appel', (t) => {
|
|
60
|
+
const root = project(t);
|
|
61
|
+
const config = base({ keycloak: { port: 8081 }, auth: { secret: 'jwt-secret-x', service: 'svc-key-x', anon: 'anon-x' } });
|
|
62
|
+
assert.ok(services.write(root, config));
|
|
63
|
+
const file = path.join(path.dirname(root), 'data', 'console', 'services.json');
|
|
64
|
+
assert.strictEqual(services.file(root), file);
|
|
65
|
+
const text = fs.readFileSync(file, 'utf8');
|
|
66
|
+
for (const secret of ['jwt-secret-x', 'svc-key-x', 'anon-x']) assert.ok(!text.includes(secret));
|
|
67
|
+
assert.deepStrictEqual(ids(JSON.parse(text)), ['db', 'mail', 'keycloak']);
|
|
68
|
+
assert.ok(!/password|secret/i.test(text));
|
|
69
|
+
services.write(root, base({ smtp: { host: 'smtp.example.com' } }));
|
|
70
|
+
assert.deepStrictEqual(JSON.parse(fs.readFileSync(file, 'utf8')), [DB]);
|
|
71
|
+
assert.deepStrictEqual(fs.readdirSync(path.dirname(file)), ['services.json']);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('Keycloak partagé : mot de passe recopié dans data/keycloak/shared-admin.json (0600), retiré ensuite', (t) => {
|
|
75
|
+
const kc = require('../utils/keycloak');
|
|
76
|
+
const root = project(t);
|
|
77
|
+
kc.writeSharedAdmin(root, 'AbcDef123456');
|
|
78
|
+
const file = kc.sharedAdminFile(root);
|
|
79
|
+
assert.strictEqual(file, path.join(path.dirname(root), 'data', 'keycloak', 'shared-admin.json'));
|
|
80
|
+
assert.deepStrictEqual(JSON.parse(fs.readFileSync(file, 'utf8')), { admin_password: 'AbcDef123456' });
|
|
81
|
+
assert.strictEqual(fs.statSync(file).mode & 0o777, 0o600);
|
|
82
|
+
kc.removeSharedAdmin(root);
|
|
83
|
+
assert.ok(!fs.existsSync(file));
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('sessions longues du realm master : 30 jours et « Se souvenir de moi »', () => {
|
|
87
|
+
const { MASTER_SESSIONS } = require('../utils/keycloak');
|
|
88
|
+
assert.strictEqual(MASTER_SESSIONS.rememberMe, true);
|
|
89
|
+
for (const k of ['ssoSessionIdleTimeout', 'ssoSessionMaxLifespan', 'ssoSessionIdleTimeoutRememberMe', 'ssoSessionMaxLifespanRememberMe']) assert.strictEqual(MASTER_SESSIONS[k], 30 * 24 * 3600);
|
|
90
|
+
});
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
{
|
|
2
|
+
"engine": {
|
|
3
|
+
"stable": "0.30.0"
|
|
4
|
+
},
|
|
5
|
+
"ai": {
|
|
6
|
+
"schema": 1,
|
|
7
|
+
"checked_on": "2026-11-25",
|
|
8
|
+
"sources": {
|
|
9
|
+
"anthropic": "https://platform.claude.com/docs/en/about-claude/pricing",
|
|
10
|
+
"openai": "https://developers.openai.com/api/docs/pricing",
|
|
11
|
+
"mistral": "https://docs.mistral.ai/inference/pricing?currency=usd",
|
|
12
|
+
"gemini": "https://aistudio.google.com/docs/pricing"
|
|
13
|
+
},
|
|
14
|
+
"providers": {
|
|
15
|
+
"anthropic": {
|
|
16
|
+
"default": "claude-opus-5-5",
|
|
17
|
+
"models": [
|
|
18
|
+
{
|
|
19
|
+
"id": "claude-fable-5-2",
|
|
20
|
+
"label": "Claude Fable 5.2",
|
|
21
|
+
"input": 8,
|
|
22
|
+
"output": 40
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"id": "claude-opus-5-5",
|
|
26
|
+
"label": "Claude Opus 5.5",
|
|
27
|
+
"input": 4,
|
|
28
|
+
"output": 20
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"id": "claude-opus-5",
|
|
32
|
+
"label": "Claude Opus 5",
|
|
33
|
+
"input": 5,
|
|
34
|
+
"output": 25
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"id": "claude-opus-4-8",
|
|
38
|
+
"label": "Claude Opus 4.8",
|
|
39
|
+
"input": 5,
|
|
40
|
+
"output": 25
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"id": "claude-sonnet-5-5",
|
|
44
|
+
"label": "Claude Sonnet 5.5",
|
|
45
|
+
"input": 2,
|
|
46
|
+
"output": 10
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"id": "claude-sonnet-5",
|
|
50
|
+
"label": "Claude Sonnet 5",
|
|
51
|
+
"input": 2,
|
|
52
|
+
"output": 10
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"id": "claude-sonnet-4-6",
|
|
56
|
+
"label": "Claude Sonnet 4.6",
|
|
57
|
+
"input": 3,
|
|
58
|
+
"output": 15
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"id": "claude-haiku-5-5",
|
|
62
|
+
"label": "Claude Haiku 5.5",
|
|
63
|
+
"input": 0.1,
|
|
64
|
+
"output": 0.5
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"id": "claude-haiku-4-5",
|
|
68
|
+
"label": "Claude Haiku 4.5",
|
|
69
|
+
"input": 1,
|
|
70
|
+
"output": 5
|
|
71
|
+
}
|
|
72
|
+
]
|
|
73
|
+
},
|
|
74
|
+
"openai": {
|
|
75
|
+
"default": "gpt-6.2-sol",
|
|
76
|
+
"models": [
|
|
77
|
+
{
|
|
78
|
+
"id": "gpt-6.2-astra",
|
|
79
|
+
"label": "GPT-6.2 Astra",
|
|
80
|
+
"input": 8,
|
|
81
|
+
"output": 40
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"id": "gpt-6.2-sol",
|
|
85
|
+
"label": "GPT-6.2 Sol",
|
|
86
|
+
"input": 2,
|
|
87
|
+
"output": 10
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"id": "gpt-6.1-sol",
|
|
91
|
+
"label": "GPT-6.1 Sol",
|
|
92
|
+
"input": 2,
|
|
93
|
+
"output": 10
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"id": "gpt-6.1-terra",
|
|
97
|
+
"label": "GPT-6.1 Terra",
|
|
98
|
+
"input": 1,
|
|
99
|
+
"output": 5
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"id": "gpt-6-luna",
|
|
103
|
+
"label": "GPT-6 Luna",
|
|
104
|
+
"input": 0.1,
|
|
105
|
+
"output": 0.5
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"id": "gpt-5.5",
|
|
109
|
+
"label": "GPT-5.5",
|
|
110
|
+
"input": 5,
|
|
111
|
+
"output": 30
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"id": "gpt-5.4",
|
|
115
|
+
"label": "GPT-5.4",
|
|
116
|
+
"input": 2.5,
|
|
117
|
+
"output": 15
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"id": "gpt-5.4-mini",
|
|
121
|
+
"label": "GPT-5.4 mini",
|
|
122
|
+
"input": 0.75,
|
|
123
|
+
"output": 4.5
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"id": "gpt-5",
|
|
127
|
+
"label": "GPT-5",
|
|
128
|
+
"input": 1.25,
|
|
129
|
+
"output": 10
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
"id": "gpt-5-mini",
|
|
133
|
+
"label": "GPT-5 mini",
|
|
134
|
+
"input": 0.25,
|
|
135
|
+
"output": 2
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
"id": "gpt-4.1",
|
|
139
|
+
"label": "GPT-4.1",
|
|
140
|
+
"input": 2,
|
|
141
|
+
"output": 8
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
"id": "gpt-4o-mini",
|
|
145
|
+
"label": "GPT-4o mini",
|
|
146
|
+
"input": 0.15,
|
|
147
|
+
"output": 0.6
|
|
148
|
+
}
|
|
149
|
+
]
|
|
150
|
+
},
|
|
151
|
+
"mistral": {
|
|
152
|
+
"default": "mistral-large-4",
|
|
153
|
+
"models": [
|
|
154
|
+
{
|
|
155
|
+
"id": "mistral-large-4",
|
|
156
|
+
"label": "Mistral Large 4",
|
|
157
|
+
"input": 0.7,
|
|
158
|
+
"output": 2.1,
|
|
159
|
+
"status": "preview"
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
"id": "mistral-small-2603",
|
|
163
|
+
"label": "Mistral Small 4",
|
|
164
|
+
"input": 0.15,
|
|
165
|
+
"output": 0.6
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
"id": "mistral-small-latest",
|
|
169
|
+
"label": "Mistral Small (latest)",
|
|
170
|
+
"input": 0.15,
|
|
171
|
+
"output": 0.6
|
|
172
|
+
}
|
|
173
|
+
]
|
|
174
|
+
},
|
|
175
|
+
"gemini": {
|
|
176
|
+
"default": "gemini-4-neon",
|
|
177
|
+
"models": [
|
|
178
|
+
{
|
|
179
|
+
"id": "gemini-4-neon",
|
|
180
|
+
"label": "Gemini 4 Neon",
|
|
181
|
+
"input": 3,
|
|
182
|
+
"output": 15
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
"id": "gemini-4-hydrogen",
|
|
186
|
+
"label": "Gemini 4 Hydrogen",
|
|
187
|
+
"input": 1.5,
|
|
188
|
+
"output": 7.5
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
"id": "gemini-3.5-flash-lite",
|
|
192
|
+
"label": "Gemini 3.5 Flash-Lite",
|
|
193
|
+
"input": 0.3,
|
|
194
|
+
"output": 2.5
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
"id": "gemini-3.1-pro-preview",
|
|
198
|
+
"label": "Gemini 3.1 Pro (preview)",
|
|
199
|
+
"input": 2,
|
|
200
|
+
"output": 12,
|
|
201
|
+
"status": "preview"
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
"id": "gemini-3.1-flash-lite",
|
|
205
|
+
"label": "Gemini 3.1 Flash-Lite",
|
|
206
|
+
"input": 0.25,
|
|
207
|
+
"output": 1.5
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
"id": "gemini-2.5-pro",
|
|
211
|
+
"label": "Gemini 2.5 Pro",
|
|
212
|
+
"input": 1.25,
|
|
213
|
+
"output": 10,
|
|
214
|
+
"status": "deprecated"
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
"id": "gemini-2.5-flash",
|
|
218
|
+
"label": "Gemini 2.5 Flash",
|
|
219
|
+
"input": 0.3,
|
|
220
|
+
"output": 2.5,
|
|
221
|
+
"status": "deprecated"
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
"id": "gemini-2.5-flash-lite",
|
|
225
|
+
"label": "Gemini 2.5 Flash-Lite",
|
|
226
|
+
"input": 0.1,
|
|
227
|
+
"output": 0.4
|
|
228
|
+
}
|
|
229
|
+
]
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
package/test/help.test.js
CHANGED
|
@@ -122,3 +122,10 @@ test('unknown command with --help: error and command list, exit 1', (t) => {
|
|
|
122
122
|
assert.match(r.stdout + r.stderr, /Unknown command : nope/);
|
|
123
123
|
assert.ok(!fs.existsSync(box.calls));
|
|
124
124
|
});
|
|
125
|
+
|
|
126
|
+
test('--help : une description qui contient [section] plus loin n’est pas coupée (start, create)', (t) => {
|
|
127
|
+
const box = sandbox(t);
|
|
128
|
+
const r = poad(box, ['--help']);
|
|
129
|
+
assert.match(r.stdout, /start \.+\s+Start the project, apply migrations/);
|
|
130
|
+
assert.match(r.stdout, /create \.+\s+Create a poad project/);
|
|
131
|
+
});
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// Catalogue des modèles d'IA (engine 0.31.0+) : par fournisseur, le modèle par défaut et les modèles proposés,
|
|
2
|
+
// avec leur prix (USD par million de jetons) et leur statut. Il vit dans poadio/permalink (poad.json, public),
|
|
3
|
+
// sous la clé « ai » : on y ajoute un modèle sans republier le CLI ni l'engine. Un CLI plus ancien ne lit que
|
|
4
|
+
// la clé « engine » et ignore celle-ci.
|
|
5
|
+
//
|
|
6
|
+
// { "engine": { … },
|
|
7
|
+
// "ai": { "schema": 1, "checked_on": "2026-11-25",
|
|
8
|
+
// "providers": { "anthropic": { "default": "claude-opus-5-5",
|
|
9
|
+
// "models": [{ "id": "claude-opus-5-5", "label": "Claude Opus 5.5",
|
|
10
|
+
// "input": 4, "output": 20, "status": "preview" }] } } } }
|
|
11
|
+
//
|
|
12
|
+
// L'engine ne va jamais sur internet : poad start écrit le catalogue dans poad/data/ai/catalog.json (monté en
|
|
13
|
+
// /data), que le service ai valide à son tour ; sans fichier, la table de l'engine sert. Cache de 6 h dans
|
|
14
|
+
// ~/.poad/ai-catalog.json ; hors ligne, le dernier catalogue connu.
|
|
15
|
+
const fs = require('fs');
|
|
16
|
+
const os = require('os');
|
|
17
|
+
const path = require('path');
|
|
18
|
+
|
|
19
|
+
const PERMALINK_URL = 'https://raw.githubusercontent.com/poadio/permalink/main/poad.json';
|
|
20
|
+
const SCHEMA = 1;
|
|
21
|
+
const CACHE_TTL = 6 * 3600 * 1000;
|
|
22
|
+
const PROVIDERS = ['anthropic', 'openai', 'mistral', 'gemini'];
|
|
23
|
+
const MODEL_ID_RE = /^[A-Za-z0-9._:-]{1,100}$/;
|
|
24
|
+
const STATUSES = ['preview', 'deprecated'];
|
|
25
|
+
|
|
26
|
+
const isObj = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
27
|
+
const priceOk = (n) => typeof n === 'number' && Number.isFinite(n) && n >= 0 && n < 100000;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Catalogue validé tiré de la clé « ai » de poad.json, mêmes règles que l'engine (services/ai/src/catalog.ts) :
|
|
31
|
+
* { catalog, warnings } ; catalog null si le schéma est inconnu ou si aucun fournisseur n'est utilisable.
|
|
32
|
+
*/
|
|
33
|
+
const parseCatalog = (raw) => {
|
|
34
|
+
const warnings = [];
|
|
35
|
+
if (!isObj(raw)) return { catalog: null, warnings: ['no "ai" key in poad.json'] };
|
|
36
|
+
if (raw.schema !== SCHEMA) return { catalog: null, warnings: [`AI catalog schema ${JSON.stringify(raw.schema)} is not supported by this CLI (expected ${SCHEMA}): update poad`] };
|
|
37
|
+
if (!isObj(raw.providers)) return { catalog: null, warnings: ['AI catalog: providers must be an object'] };
|
|
38
|
+
const providers = {};
|
|
39
|
+
for (const [p, v] of Object.entries(raw.providers)) {
|
|
40
|
+
if (!PROVIDERS.includes(p)) {
|
|
41
|
+
warnings.push(`unknown provider "${p.slice(0, 40)}" ignored`);
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (!isObj(v) || !Array.isArray(v.models) || typeof v.default !== 'string') {
|
|
45
|
+
warnings.push(`${p}: { default, models } expected, ignored`);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const models = [];
|
|
49
|
+
for (const m of v.models.slice(0, 200)) {
|
|
50
|
+
if (!isObj(m) || typeof m.id !== 'string' || !MODEL_ID_RE.test(m.id) || !priceOk(m.input) || !priceOk(m.output)) {
|
|
51
|
+
warnings.push(`${p}: a model without a valid id, input or output is ignored`);
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (m.status !== undefined && !STATUSES.includes(m.status)) {
|
|
55
|
+
warnings.push(`${p}/${m.id}: status must be preview or deprecated, ignored`);
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (models.some((x) => x.id === m.id)) continue;
|
|
59
|
+
const label = typeof m.label === 'string' && m.label.trim() ? m.label.trim().slice(0, 80) : m.id;
|
|
60
|
+
models.push({ id: m.id, label, input: m.input, output: m.output, ...(m.status ? { status: m.status } : {}) });
|
|
61
|
+
}
|
|
62
|
+
if (!models.some((m) => m.id === v.default)) {
|
|
63
|
+
warnings.push(`${p}: default "${String(v.default).slice(0, 80)}" is not in its models, ignored`);
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
providers[p] = { default: v.default, models };
|
|
67
|
+
}
|
|
68
|
+
if (!Object.keys(providers).length) return { catalog: null, warnings: [...warnings, 'AI catalog: no usable provider'] };
|
|
69
|
+
const checked = typeof raw.checked_on === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(raw.checked_on) ? raw.checked_on : null;
|
|
70
|
+
return { catalog: { schema: SCHEMA, checked_on: checked, providers }, warnings };
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const cacheFile = () => process.env.POAD_AI_CATALOG_CACHE || path.join(os.homedir(), '.poad', 'ai-catalog.json');
|
|
74
|
+
|
|
75
|
+
const readCache = () => {
|
|
76
|
+
try {
|
|
77
|
+
const c = JSON.parse(fs.readFileSync(cacheFile(), 'utf8'));
|
|
78
|
+
return c && typeof c.at === 'number' && c.catalog ? c : null;
|
|
79
|
+
} catch {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const writeCache = (catalog) => {
|
|
85
|
+
try {
|
|
86
|
+
fs.mkdirSync(path.dirname(cacheFile()), { recursive: true, mode: 0o700 });
|
|
87
|
+
fs.writeFileSync(cacheFile(), JSON.stringify({ at: Date.now(), catalog }));
|
|
88
|
+
} catch {
|
|
89
|
+
// cache facultatif
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/** Corps de poad.json, ou null (hors ligne, illisible) */
|
|
94
|
+
const fetchPermalink = async (timeout) => {
|
|
95
|
+
try {
|
|
96
|
+
const res = await fetch(PERMALINK_URL, { signal: AbortSignal.timeout(timeout), headers: { 'cache-control': 'no-cache' } });
|
|
97
|
+
return res.ok ? await res.json() : null;
|
|
98
|
+
} catch {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* { catalog, source, fetched_at, warnings } ; source : permalink (lu à l'instant), cache, ou none (rien de
|
|
105
|
+
* connu : l'engine prendra sa table). fresh : ignorer le cache récent. fetcher : pour les essais.
|
|
106
|
+
*/
|
|
107
|
+
const loadCatalog = async ({ fresh = false, timeout = 2500, fetcher = fetchPermalink } = {}) => {
|
|
108
|
+
const cached = readCache();
|
|
109
|
+
if (!fresh && cached && Date.now() - cached.at < CACHE_TTL) return { catalog: cached.catalog, source: 'cache', fetched_at: new Date(cached.at).toISOString(), warnings: [] };
|
|
110
|
+
const body = await fetcher(timeout);
|
|
111
|
+
if (body) {
|
|
112
|
+
const { catalog, warnings } = parseCatalog(isObj(body) ? body.ai : null);
|
|
113
|
+
if (catalog) {
|
|
114
|
+
writeCache(catalog);
|
|
115
|
+
return { catalog, source: 'permalink', fetched_at: new Date().toISOString(), warnings };
|
|
116
|
+
}
|
|
117
|
+
if (cached) return { catalog: cached.catalog, source: 'cache', fetched_at: new Date(cached.at).toISOString(), warnings };
|
|
118
|
+
return { catalog: null, source: 'none', fetched_at: null, warnings };
|
|
119
|
+
}
|
|
120
|
+
if (cached) return { catalog: cached.catalog, source: 'cache', fetched_at: new Date(cached.at).toISOString(), warnings: [] };
|
|
121
|
+
return { catalog: null, source: 'none', fetched_at: null, warnings: [] };
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/** poad/data/ai/catalog.json du projet (monté en /data/ai/catalog.json dans l'engine) */
|
|
125
|
+
const engineFile = (root) => path.join(path.dirname(root), 'data', 'ai', 'catalog.json');
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Écrit le catalogue pour l'engine (remplacement atomique), ou retire le fichier s'il n'y a pas de catalogue :
|
|
129
|
+
* l'engine prend alors sa table. Rend le chemin écrit, ou null.
|
|
130
|
+
*/
|
|
131
|
+
const writeForEngine = (root, loaded) => {
|
|
132
|
+
const file = engineFile(root);
|
|
133
|
+
if (!loaded || !loaded.catalog) {
|
|
134
|
+
try {
|
|
135
|
+
fs.unlinkSync(file);
|
|
136
|
+
} catch {
|
|
137
|
+
// rien à retirer
|
|
138
|
+
}
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
142
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
143
|
+
fs.writeFileSync(tmp, `${JSON.stringify({ ...loaded.catalog, fetched_at: loaded.fetched_at }, null, 2)}\n`);
|
|
144
|
+
fs.renameSync(tmp, file);
|
|
145
|
+
return file;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
module.exports = { PERMALINK_URL, SCHEMA, parseCatalog, loadCatalog, writeForEngine, engineFile, cacheFile };
|