@whittlelabs/trivet 0.1.7 → 0.1.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/bin.js +78 -83
- package/bin.js.map +3 -3
- package/package.json +1 -1
package/bin.js
CHANGED
|
@@ -72521,6 +72521,8 @@ var require_device_code = __commonJS({
|
|
|
72521
72521
|
exports2.noPoolRefusal = noPoolRefusal;
|
|
72522
72522
|
exports2.issuedButNotKept = issuedButNotKept;
|
|
72523
72523
|
var os_1 = require("os");
|
|
72524
|
+
var jobs_1 = require_jobs();
|
|
72525
|
+
var keep_1 = require_keep();
|
|
72524
72526
|
var apply_1 = require_apply();
|
|
72525
72527
|
var version_check_1 = require_version_check();
|
|
72526
72528
|
var typed_exit_1 = require_typed_exit();
|
|
@@ -72618,35 +72620,13 @@ var require_device_code = __commonJS({
|
|
|
72618
72620
|
};
|
|
72619
72621
|
}
|
|
72620
72622
|
async function discoverMemberPools(opts) {
|
|
72621
|
-
const
|
|
72622
|
-
|
|
72623
|
-
|
|
72624
|
-
|
|
72625
|
-
|
|
72626
|
-
|
|
72627
|
-
|
|
72628
|
-
})
|
|
72629
|
-
});
|
|
72630
|
-
(0, version_check_1.checkResponseMinVersion)({
|
|
72631
|
-
response: tokenRes,
|
|
72632
|
-
productId: opts.brand.product.id,
|
|
72633
|
-
currentVersion: opts.brand.product.version,
|
|
72634
|
-
packageName: opts.brand.product.packageName
|
|
72635
|
-
});
|
|
72636
|
-
const tokenJson = await readJson(tokenRes);
|
|
72637
|
-
const poolsUrl = `${opts.jobsApiUrl.replace(/\/$/, "")}/api/my/pools`;
|
|
72638
|
-
const poolsRes = await opts.fetcher(poolsUrl, {
|
|
72639
|
-
method: "GET",
|
|
72640
|
-
headers: { Authorization: `Bearer ${tokenJson.data.token}` }
|
|
72641
|
-
});
|
|
72642
|
-
(0, version_check_1.checkResponseMinVersion)({
|
|
72643
|
-
response: poolsRes,
|
|
72644
|
-
productId: opts.brand.product.id,
|
|
72645
|
-
currentVersion: opts.brand.product.version,
|
|
72646
|
-
packageName: opts.brand.product.packageName
|
|
72647
|
-
});
|
|
72648
|
-
const poolsJson = await readJson(poolsRes);
|
|
72649
|
-
return poolsJson.data.pools;
|
|
72623
|
+
const minted = readAnswer(await sendPairing(opts.fetcher, (transport) => (0, keep_1.createClient)({ baseUrl: opts.keepApiUrl, transport }).post("/api/agent-tokens", {
|
|
72624
|
+
body: { clientId: opts.clientId, clientSecret: opts.clientSecret }
|
|
72625
|
+
})), opts.brand);
|
|
72626
|
+
const roster = readAnswer(await sendPairing(opts.fetcher, (transport) => (0, jobs_1.createClient)({ baseUrl: opts.jobsApiUrl, transport }).get("/api/my/pools", {
|
|
72627
|
+
headers: { Authorization: `Bearer ${minted.token}` }
|
|
72628
|
+
})), opts.brand);
|
|
72629
|
+
return roster.pools;
|
|
72650
72630
|
}
|
|
72651
72631
|
function webFirstRemedy(brand, cause) {
|
|
72652
72632
|
const reason = cause instanceof Error ? cause.message : String(cause);
|
|
@@ -72683,90 +72663,105 @@ var require_device_code = __commonJS({
|
|
|
72683
72663
|
return opts.columns ?? process.stdout.columns;
|
|
72684
72664
|
}
|
|
72685
72665
|
async function startDeviceCode(opts) {
|
|
72686
|
-
const
|
|
72687
|
-
|
|
72688
|
-
|
|
72689
|
-
|
|
72690
|
-
body: JSON.stringify({
|
|
72691
|
-
client_id: opts.oauthClientId
|
|
72692
|
-
})
|
|
72693
|
-
});
|
|
72694
|
-
(0, version_check_1.checkResponseMinVersion)({
|
|
72695
|
-
response,
|
|
72696
|
-
productId: opts.brand.product.id,
|
|
72697
|
-
currentVersion: opts.brand.product.version,
|
|
72698
|
-
packageName: opts.brand.product.packageName
|
|
72699
|
-
});
|
|
72700
|
-
const json = await readJson(response);
|
|
72701
|
-
return json.data;
|
|
72666
|
+
const answer = await sendPairing(opts.fetcher, (transport) => (0, keep_1.createClient)({ baseUrl: opts.keepApiUrl, transport }).post("/api/oauth/device", {
|
|
72667
|
+
body: { client_id: opts.oauthClientId }
|
|
72668
|
+
}));
|
|
72669
|
+
return readAnswer(answer, opts.brand);
|
|
72702
72670
|
}
|
|
72703
72671
|
async function pollForToken(opts) {
|
|
72704
|
-
const url = `${opts.keepApiUrl.replace(/\/$/, "")}/api/oauth/device/token`;
|
|
72705
72672
|
const deadline = Date.now() + opts.timeoutMs;
|
|
72706
72673
|
while (Date.now() < deadline) {
|
|
72707
|
-
const
|
|
72708
|
-
|
|
72709
|
-
headers: { "Content-Type": "application/json" },
|
|
72710
|
-
body: JSON.stringify({
|
|
72674
|
+
const answer = await sendPairing(opts.fetcher, (transport) => (0, keep_1.createClient)({ baseUrl: opts.keepApiUrl, transport }).post("/api/oauth/device/token", {
|
|
72675
|
+
body: {
|
|
72711
72676
|
client_id: opts.oauthClientId,
|
|
72712
72677
|
device_code: opts.deviceCode,
|
|
72713
72678
|
display_name: opts.displayName,
|
|
72714
72679
|
hostname: (0, os_1.hostname)(),
|
|
72715
72680
|
os_user: (0, os_1.userInfo)().username
|
|
72716
|
-
}
|
|
72717
|
-
});
|
|
72718
|
-
if (
|
|
72681
|
+
}
|
|
72682
|
+
}));
|
|
72683
|
+
if (answer.status === 202) {
|
|
72719
72684
|
await sleep(opts.intervalMs);
|
|
72720
72685
|
continue;
|
|
72721
72686
|
}
|
|
72722
|
-
if (
|
|
72687
|
+
if (answer.status === 410) {
|
|
72723
72688
|
throw new Error("Pairing code expired before verification.");
|
|
72724
72689
|
}
|
|
72725
|
-
(
|
|
72726
|
-
|
|
72727
|
-
|
|
72728
|
-
|
|
72729
|
-
|
|
72730
|
-
});
|
|
72731
|
-
const json = await readJson(response);
|
|
72732
|
-
return json.data;
|
|
72690
|
+
const issued = readAnswer(answer, opts.brand);
|
|
72691
|
+
if ("status" in issued) {
|
|
72692
|
+
throw new Error(`Pairing endpoint returned status ${answer.status}.`);
|
|
72693
|
+
}
|
|
72694
|
+
return issued;
|
|
72733
72695
|
}
|
|
72734
72696
|
throw new Error("Pairing timed out before verification.");
|
|
72735
72697
|
}
|
|
72736
72698
|
async function redeemPairingCode(opts) {
|
|
72737
|
-
const
|
|
72738
|
-
|
|
72739
|
-
method: "POST",
|
|
72740
|
-
headers: { "Content-Type": "application/json" },
|
|
72741
|
-
body: JSON.stringify({
|
|
72699
|
+
const answer = await sendPairing(opts.fetcher, (transport) => (0, keep_1.createClient)({ baseUrl: opts.keepApiUrl, transport }).post("/api/oauth/device/redeem", {
|
|
72700
|
+
body: {
|
|
72742
72701
|
client_id: opts.oauthClientId,
|
|
72743
72702
|
user_code: opts.userCode,
|
|
72744
72703
|
display_name: opts.displayName,
|
|
72745
72704
|
hostname: (0, os_1.hostname)(),
|
|
72746
72705
|
os_user: (0, os_1.userInfo)().username
|
|
72747
|
-
}
|
|
72706
|
+
}
|
|
72707
|
+
}));
|
|
72708
|
+
return readAnswer(answer, opts.brand);
|
|
72709
|
+
}
|
|
72710
|
+
async function sendPairing(fetcher, send) {
|
|
72711
|
+
let raised;
|
|
72712
|
+
let seen;
|
|
72713
|
+
const result = await send(async (url, init2) => {
|
|
72714
|
+
let response;
|
|
72715
|
+
try {
|
|
72716
|
+
response = await fetcher(url, init2);
|
|
72717
|
+
} catch (err2) {
|
|
72718
|
+
raised = { error: err2 };
|
|
72719
|
+
throw err2;
|
|
72720
|
+
}
|
|
72721
|
+
const text = await response.text().catch(() => void 0);
|
|
72722
|
+
seen = { status: response.status, headers: response.headers, ...readBody(text) };
|
|
72723
|
+
return new Response(text ? text : null, {
|
|
72724
|
+
status: response.status,
|
|
72725
|
+
statusText: response.statusText,
|
|
72726
|
+
headers: response.headers
|
|
72727
|
+
});
|
|
72748
72728
|
});
|
|
72729
|
+
if (raised)
|
|
72730
|
+
throw raised.error;
|
|
72731
|
+
if (!seen)
|
|
72732
|
+
throw new Error("Pairing endpoint gave no answer.");
|
|
72733
|
+
return { result, ...seen };
|
|
72734
|
+
}
|
|
72735
|
+
function readAnswer(answer, brand) {
|
|
72749
72736
|
(0, version_check_1.checkResponseMinVersion)({
|
|
72750
|
-
response,
|
|
72751
|
-
productId:
|
|
72752
|
-
currentVersion:
|
|
72753
|
-
packageName:
|
|
72737
|
+
response: answer,
|
|
72738
|
+
productId: brand.product.id,
|
|
72739
|
+
currentVersion: brand.product.version,
|
|
72740
|
+
packageName: brand.product.packageName
|
|
72754
72741
|
});
|
|
72755
|
-
|
|
72756
|
-
|
|
72742
|
+
if (!answer.json) {
|
|
72743
|
+
throw new Error(`Pairing endpoint returned non-JSON (status ${answer.status}).`);
|
|
72744
|
+
}
|
|
72745
|
+
if (!answer.result.success) {
|
|
72746
|
+
throw new Error(answer.refusalMessage ?? `Pairing endpoint returned status ${answer.status}.`);
|
|
72747
|
+
}
|
|
72748
|
+
return answer.result.data;
|
|
72757
72749
|
}
|
|
72758
|
-
|
|
72750
|
+
function readBody(text) {
|
|
72751
|
+
if (text === void 0)
|
|
72752
|
+
return { json: false, refusalMessage: void 0 };
|
|
72759
72753
|
let body2;
|
|
72760
72754
|
try {
|
|
72761
|
-
body2 =
|
|
72755
|
+
body2 = JSON.parse(text);
|
|
72762
72756
|
} catch {
|
|
72763
|
-
|
|
72757
|
+
return { json: false, refusalMessage: void 0 };
|
|
72764
72758
|
}
|
|
72765
|
-
|
|
72766
|
-
|
|
72767
|
-
|
|
72768
|
-
|
|
72769
|
-
|
|
72759
|
+
const error = isRecord(body2) ? body2.error : void 0;
|
|
72760
|
+
const message = isRecord(error) ? error.message : void 0;
|
|
72761
|
+
return { json: true, refusalMessage: typeof message === "string" ? message : void 0 };
|
|
72762
|
+
}
|
|
72763
|
+
function isRecord(value) {
|
|
72764
|
+
return typeof value === "object" && value !== null;
|
|
72770
72765
|
}
|
|
72771
72766
|
function sleep(ms) {
|
|
72772
72767
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -76407,7 +76402,7 @@ var import_shuttle2 = __toESM(require_dist8());
|
|
|
76407
76402
|
|
|
76408
76403
|
// src/brand.ts
|
|
76409
76404
|
var import_shuttle = __toESM(require_dist8());
|
|
76410
|
-
var buildVersion = true ? "0.1.
|
|
76405
|
+
var buildVersion = true ? "0.1.8" : pkg.version;
|
|
76411
76406
|
var EXECUTORS = ["claude-code"];
|
|
76412
76407
|
var trivetBrand = {
|
|
76413
76408
|
product: {
|