@aiam/ciba 0.9.8 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ciba.mjs +9 -3
- package/package.json +1 -1
- package/token.mjs +18 -19
package/ciba.mjs
CHANGED
|
@@ -289,8 +289,11 @@ async function runCodeFlow(serverUrl, code, opts) {
|
|
|
289
289
|
|
|
290
290
|
log('→ Exchanging code...');
|
|
291
291
|
|
|
292
|
-
// Wait for the default destination token
|
|
293
|
-
const
|
|
292
|
+
// Wait for the default destination token — resolve from server options.
|
|
293
|
+
const optionsMap2 = deviceDoc.getMap('options');
|
|
294
|
+
const srvRes2 = optionsMap2.get('resources') ?? {};
|
|
295
|
+
const defaultResource = Object.keys(srvRes2).find(n => srvRes2[n]?.default)
|
|
296
|
+
?? process.env.CIBA_DEFAULT_RESOURCE ?? 'webagents';
|
|
294
297
|
const resourcesMap = deviceDoc.getMap('resources');
|
|
295
298
|
|
|
296
299
|
const tokenMapName = await firstInYMap(resourcesMap, () => true, TIMEOUT)
|
|
@@ -438,7 +441,10 @@ function startDaemon(provider, deviceDoc, privateKey, serverUrl) {
|
|
|
438
441
|
dlog(`${req.command} cmd attrs=${JSON.stringify(req.attrs)}`);
|
|
439
442
|
const requests = deviceDoc.getMap('requests');
|
|
440
443
|
const resourcesMap = deviceDoc.getMap('resources');
|
|
441
|
-
const
|
|
444
|
+
const optionsMap = deviceDoc.getMap('options');
|
|
445
|
+
const serverResources = optionsMap.get('resources') ?? {};
|
|
446
|
+
const defaultResource = Object.keys(serverResources).find(n => serverResources[n]?.default)
|
|
447
|
+
?? process.env.CIBA_DEFAULT_RESOURCE ?? 'webagents';
|
|
442
448
|
const attrs = { ...(req.attrs || {}) };
|
|
443
449
|
const requestedResource = attrs.resource ?? defaultResource;
|
|
444
450
|
|
package/package.json
CHANGED
package/token.mjs
CHANGED
|
@@ -30,7 +30,7 @@ const args = process.argv.slice(2);
|
|
|
30
30
|
const get = (flag) => { const i = args.indexOf(flag); return i !== -1 ? args[i + 1] : undefined; };
|
|
31
31
|
const has = (flag) => args.includes(flag);
|
|
32
32
|
|
|
33
|
-
const resource = get('--resource') ??
|
|
33
|
+
const resource = get('--resource') ?? null; // null = resolve from server options after sync
|
|
34
34
|
const jsonOut = has('--json');
|
|
35
35
|
const envOut = has('--env');
|
|
36
36
|
const isRefresh = has('--refresh');
|
|
@@ -130,7 +130,7 @@ function tryGet(resourcesMap, deviceDoc, res) {
|
|
|
130
130
|
|
|
131
131
|
// ─── Output ───────────────────────────────────────────────────────────────────
|
|
132
132
|
|
|
133
|
-
function log(msg) { process.stderr.write(msg + '\n'); }
|
|
133
|
+
function log(msg) { if (!jsonOut && !envOut) process.stderr.write(msg + '\n'); }
|
|
134
134
|
|
|
135
135
|
function output(token) {
|
|
136
136
|
if (jsonOut) {
|
|
@@ -147,7 +147,6 @@ function output(token) {
|
|
|
147
147
|
const { jwt: deviceJwt, deviceId } = signDeviceJwt(privateKey, publicKey);
|
|
148
148
|
log(`→ device: ${deviceId}`);
|
|
149
149
|
log(`→ server: ${serverUrl}`);
|
|
150
|
-
log(`→ resource: ${resource}`);
|
|
151
150
|
log('');
|
|
152
151
|
|
|
153
152
|
const cliUA = `ciba-cli/token (${process.platform} ${process.arch}; node ${process.version})`;
|
|
@@ -179,29 +178,29 @@ if (meta.get('public_key') !== publicKey) meta.set('public_key', publicKey);
|
|
|
179
178
|
const resourcesMap = deviceDoc.getMap('resources');
|
|
180
179
|
const optionsMap = deviceDoc.getMap('options');
|
|
181
180
|
|
|
182
|
-
// Read server options — resolve
|
|
183
|
-
// options.resources = { webagents: { default: true
|
|
181
|
+
// Read server options — resolve resource name.
|
|
182
|
+
// options.resources = { webagents: { default: true }, a2a: { ... }, ... }
|
|
184
183
|
const serverResources = optionsMap.get('resources') ?? {};
|
|
185
184
|
const resourceNames = Object.keys(serverResources);
|
|
186
185
|
|
|
187
|
-
// Resolve
|
|
188
|
-
// 1.
|
|
189
|
-
// 2.
|
|
190
|
-
// 3.
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
// Use default
|
|
186
|
+
// Resolve:
|
|
187
|
+
// 1. --resource passed and matches a known short name → use it
|
|
188
|
+
// 2. --resource passed as URN → use as-is
|
|
189
|
+
// 3. No --resource → use server default (options.resources[name].default === true)
|
|
190
|
+
// 4. Fallback: first resource name, or 'webagents'
|
|
191
|
+
let resolvedResource;
|
|
192
|
+
if (resource) {
|
|
193
|
+
// Exact match or case-insensitive short name
|
|
194
|
+
const match = resourceNames.find(n => n === resource || n.toLowerCase() === resource.toLowerCase());
|
|
195
|
+
resolvedResource = match ?? resource; // fall back to as-is (URN or unknown)
|
|
196
|
+
} else {
|
|
197
|
+
// Use server default
|
|
199
198
|
const def = resourceNames.find(n => serverResources[n]?.default);
|
|
200
|
-
resolvedResource = def ??
|
|
199
|
+
resolvedResource = def ?? resourceNames[0] ?? 'webagents';
|
|
201
200
|
}
|
|
202
201
|
|
|
203
202
|
log(`→ options: ${JSON.stringify(serverResources)}`);
|
|
204
|
-
log(`→
|
|
203
|
+
log(`→ resource: ${resolvedResource}`);
|
|
205
204
|
log(`→ resources: ${JSON.stringify([...resourcesMap.entries()])}`);
|
|
206
205
|
|
|
207
206
|
// Refresh mode: write request and exit immediately.
|