@aiam/ciba 0.9.6 → 0.9.8
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 +4 -34
- package/package.json +1 -1
- package/token.mjs +2 -14
package/ciba.mjs
CHANGED
|
@@ -290,7 +290,7 @@ async function runCodeFlow(serverUrl, code, opts) {
|
|
|
290
290
|
log('→ Exchanging code...');
|
|
291
291
|
|
|
292
292
|
// Wait for the default destination token to land via resources map.
|
|
293
|
-
const defaultResource =
|
|
293
|
+
const defaultResource = process.env.CIBA_DEFAULT_RESOURCE || 'webagents';
|
|
294
294
|
const resourcesMap = deviceDoc.getMap('resources');
|
|
295
295
|
|
|
296
296
|
const tokenMapName = await firstInYMap(resourcesMap, () => true, TIMEOUT)
|
|
@@ -438,7 +438,7 @@ function startDaemon(provider, deviceDoc, privateKey, serverUrl) {
|
|
|
438
438
|
dlog(`${req.command} cmd attrs=${JSON.stringify(req.attrs)}`);
|
|
439
439
|
const requests = deviceDoc.getMap('requests');
|
|
440
440
|
const resourcesMap = deviceDoc.getMap('resources');
|
|
441
|
-
const defaultResource =
|
|
441
|
+
const defaultResource = process.env.CIBA_DEFAULT_RESOURCE || 'webagents';
|
|
442
442
|
const attrs = { ...(req.attrs || {}) };
|
|
443
443
|
const requestedResource = attrs.resource ?? defaultResource;
|
|
444
444
|
|
|
@@ -652,7 +652,7 @@ const loginCmd = defineCommand({
|
|
|
652
652
|
const tokenCmd = defineCommand({
|
|
653
653
|
meta: { description: 'Return token (cache-first, no daemon needed)' },
|
|
654
654
|
args: {
|
|
655
|
-
resource: { type: 'string', description: 'Resource
|
|
655
|
+
resource: { type: 'string', description: 'Resource name (default: webagents)' },
|
|
656
656
|
...outputArgs,
|
|
657
657
|
},
|
|
658
658
|
async run({ args }) {
|
|
@@ -671,7 +671,7 @@ const tokenCmd = defineCommand({
|
|
|
671
671
|
const refreshCmd = defineCommand({
|
|
672
672
|
meta: { description: 'Force a fresh token exchange (no re-approval needed)' },
|
|
673
673
|
args: {
|
|
674
|
-
resource: { type: 'string', description: 'Resource
|
|
674
|
+
resource: { type: 'string', description: 'Resource name to refresh (default: webagents)' },
|
|
675
675
|
...outputArgs,
|
|
676
676
|
},
|
|
677
677
|
async run({ args }) {
|
|
@@ -689,35 +689,6 @@ const refreshCmd = defineCommand({
|
|
|
689
689
|
},
|
|
690
690
|
});
|
|
691
691
|
|
|
692
|
-
const inspectCmd = defineCommand({
|
|
693
|
-
meta: { description: 'Open live device doc inspector in browser' },
|
|
694
|
-
args: {
|
|
695
|
-
url: { ...serverArg },
|
|
696
|
-
},
|
|
697
|
-
async run({ args }) {
|
|
698
|
-
const serverUrl = args.url || process.env.CIBA_URL || loadConfig().url || DEFAULT_SERVER_URL;
|
|
699
|
-
const keys = loadOrGenerateEcdhKeys();
|
|
700
|
-
const { jwt: deviceJwt } = signDeviceJwt(keys.privateKey, keys.publicKey);
|
|
701
|
-
|
|
702
|
-
// POST /inspect with device JWT to get a one-time inspect code.
|
|
703
|
-
const res = await fetch(`${serverUrl}/inspect`, {
|
|
704
|
-
method: 'POST',
|
|
705
|
-
headers: { Authorization: `Bearer ${deviceJwt}` },
|
|
706
|
-
});
|
|
707
|
-
if (!res.ok) {
|
|
708
|
-
const err = await res.json().catch(() => ({}));
|
|
709
|
-
process.stderr.write(`Error: ${err.error || res.status}\n`);
|
|
710
|
-
process.exit(1);
|
|
711
|
-
}
|
|
712
|
-
const { code, url } = await res.json();
|
|
713
|
-
process.stderr.write(`→ inspect code: ${code}\n`);
|
|
714
|
-
process.stderr.write(`→ opening: ${url}\n`);
|
|
715
|
-
const cmd = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'start ""' : 'xdg-open';
|
|
716
|
-
exec(`${cmd} "${url}"`);
|
|
717
|
-
process.exit(0);
|
|
718
|
-
},
|
|
719
|
-
});
|
|
720
|
-
|
|
721
692
|
const logoutCmd = defineCommand({
|
|
722
693
|
meta: { description: 'Clear device keys, session and config (next login generates a new device identity)' },
|
|
723
694
|
args: {},
|
|
@@ -793,7 +764,6 @@ const main = defineCommand({
|
|
|
793
764
|
login: loginCmd,
|
|
794
765
|
token: tokenCmd,
|
|
795
766
|
refresh: refreshCmd,
|
|
796
|
-
inspect: inspectCmd,
|
|
797
767
|
stop: stopCmd,
|
|
798
768
|
status: statusCmd,
|
|
799
769
|
logout: logoutCmd,
|
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') ?? process.env.CIBA_DEFAULT_RESOURCE ?? 'webagents';
|
|
34
34
|
const jsonOut = has('--json');
|
|
35
35
|
const envOut = has('--env');
|
|
36
36
|
const isRefresh = has('--refresh');
|
|
@@ -130,17 +130,7 @@ function tryGet(resourcesMap, deviceDoc, res) {
|
|
|
130
130
|
|
|
131
131
|
// ─── Output ───────────────────────────────────────────────────────────────────
|
|
132
132
|
|
|
133
|
-
|
|
134
|
-
// Before doc is synced, fall back to stderr.
|
|
135
|
-
let _logMap = null;
|
|
136
|
-
let _logIdx = 0;
|
|
137
|
-
function log(msg) {
|
|
138
|
-
if (_logMap) {
|
|
139
|
-
_logMap.set(`${Date.now()}-${_logIdx++}`, { ts: new Date().toISOString(), msg });
|
|
140
|
-
} else {
|
|
141
|
-
process.stderr.write(msg + '\n');
|
|
142
|
-
}
|
|
143
|
-
}
|
|
133
|
+
function log(msg) { process.stderr.write(msg + '\n'); }
|
|
144
134
|
|
|
145
135
|
function output(token) {
|
|
146
136
|
if (jsonOut) {
|
|
@@ -180,8 +170,6 @@ await new Promise((resolve, reject) => {
|
|
|
180
170
|
provider.on('authenticationFailed', ({ reason }) => { clearTimeout(t); reject(new Error(reason)); });
|
|
181
171
|
});
|
|
182
172
|
|
|
183
|
-
// Switch logging to Yjs after sync — ciba inspect can now see entries.
|
|
184
|
-
_logMap = deviceDoc.getMap('log');
|
|
185
173
|
log('→ synced');
|
|
186
174
|
|
|
187
175
|
// Write public key
|