@aiam/ciba 0.9.7 → 0.9.9
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 +11 -5
- package/package.json +1 -1
- package/token.mjs +16 -16
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
|
|
|
@@ -652,7 +658,7 @@ const loginCmd = defineCommand({
|
|
|
652
658
|
const tokenCmd = defineCommand({
|
|
653
659
|
meta: { description: 'Return token (cache-first, no daemon needed)' },
|
|
654
660
|
args: {
|
|
655
|
-
resource: { type: 'string', description: 'Resource
|
|
661
|
+
resource: { type: 'string', description: 'Resource name (default: webagents)' },
|
|
656
662
|
...outputArgs,
|
|
657
663
|
},
|
|
658
664
|
async run({ args }) {
|
|
@@ -671,7 +677,7 @@ const tokenCmd = defineCommand({
|
|
|
671
677
|
const refreshCmd = defineCommand({
|
|
672
678
|
meta: { description: 'Force a fresh token exchange (no re-approval needed)' },
|
|
673
679
|
args: {
|
|
674
|
-
resource: { type: 'string', description: 'Resource
|
|
680
|
+
resource: { type: 'string', description: 'Resource name to refresh (default: webagents)' },
|
|
675
681
|
...outputArgs,
|
|
676
682
|
},
|
|
677
683
|
async run({ args }) {
|
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');
|
|
@@ -179,25 +179,25 @@ if (meta.get('public_key') !== publicKey) meta.set('public_key', publicKey);
|
|
|
179
179
|
const resourcesMap = deviceDoc.getMap('resources');
|
|
180
180
|
const optionsMap = deviceDoc.getMap('options');
|
|
181
181
|
|
|
182
|
-
// Read server options — resolve
|
|
183
|
-
// options.resources = { webagents: { default: true
|
|
182
|
+
// Read server options — resolve resource name.
|
|
183
|
+
// options.resources = { webagents: { default: true }, a2a: { ... }, ... }
|
|
184
184
|
const serverResources = optionsMap.get('resources') ?? {};
|
|
185
185
|
const resourceNames = Object.keys(serverResources);
|
|
186
186
|
|
|
187
|
-
// Resolve
|
|
188
|
-
// 1.
|
|
189
|
-
// 2.
|
|
190
|
-
// 3.
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
// Use default
|
|
187
|
+
// Resolve:
|
|
188
|
+
// 1. --resource passed and matches a known short name → use it
|
|
189
|
+
// 2. --resource passed as URN → use as-is
|
|
190
|
+
// 3. No --resource → use server default (options.resources[name].default === true)
|
|
191
|
+
// 4. Fallback: first resource name, or 'webagents'
|
|
192
|
+
let resolvedResource;
|
|
193
|
+
if (resource) {
|
|
194
|
+
// Exact match or case-insensitive short name
|
|
195
|
+
const match = resourceNames.find(n => n === resource || n.toLowerCase() === resource.toLowerCase());
|
|
196
|
+
resolvedResource = match ?? resource; // fall back to as-is (URN or unknown)
|
|
197
|
+
} else {
|
|
198
|
+
// Use server default
|
|
199
199
|
const def = resourceNames.find(n => serverResources[n]?.default);
|
|
200
|
-
resolvedResource = def ??
|
|
200
|
+
resolvedResource = def ?? resourceNames[0] ?? 'webagents';
|
|
201
201
|
}
|
|
202
202
|
|
|
203
203
|
log(`→ options: ${JSON.stringify(serverResources)}`);
|