@whittlelabs/trivet 0.1.7 → 0.1.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/bin.js +78 -95
- package/bin.js.map +3 -3
- package/package.json +1 -1
package/bin.js
CHANGED
|
@@ -59266,18 +59266,6 @@ var require_client2 = __commonJS({
|
|
|
59266
59266
|
body: request
|
|
59267
59267
|
}));
|
|
59268
59268
|
}
|
|
59269
|
-
/**
|
|
59270
|
-
* Mint a pre-authorised device-code (pairing code) bound to an existing
|
|
59271
|
-
* service identity. The Sift "Pair your Sifter" button calls this and
|
|
59272
|
-
* shows `userCode` to the user.
|
|
59273
|
-
*
|
|
59274
|
-
* Requires `keep:service-identities:write`.
|
|
59275
|
-
*/
|
|
59276
|
-
async createDeviceCodePreauth(request) {
|
|
59277
|
-
return answer(await this.api.post("/api/oauth/device-code/preauth", {
|
|
59278
|
-
body: { client_id: request.clientId, boundAgentId: request.boundAgentId, ttlSeconds: request.ttlSeconds }
|
|
59279
|
-
}));
|
|
59280
|
-
}
|
|
59281
59269
|
// ── Hosted Sifter ───────────────────────────────────────────────
|
|
59282
59270
|
/**
|
|
59283
59271
|
* Reveal a person's model-provider key for one hosted dispatch, with the
|
|
@@ -72521,6 +72509,8 @@ var require_device_code = __commonJS({
|
|
|
72521
72509
|
exports2.noPoolRefusal = noPoolRefusal;
|
|
72522
72510
|
exports2.issuedButNotKept = issuedButNotKept;
|
|
72523
72511
|
var os_1 = require("os");
|
|
72512
|
+
var jobs_1 = require_jobs();
|
|
72513
|
+
var keep_1 = require_keep();
|
|
72524
72514
|
var apply_1 = require_apply();
|
|
72525
72515
|
var version_check_1 = require_version_check();
|
|
72526
72516
|
var typed_exit_1 = require_typed_exit();
|
|
@@ -72618,35 +72608,13 @@ var require_device_code = __commonJS({
|
|
|
72618
72608
|
};
|
|
72619
72609
|
}
|
|
72620
72610
|
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;
|
|
72611
|
+
const minted = readAnswer(await sendPairing(opts.fetcher, (transport) => (0, keep_1.createClient)({ baseUrl: opts.keepApiUrl, transport }).post("/api/agent-tokens", {
|
|
72612
|
+
body: { clientId: opts.clientId, clientSecret: opts.clientSecret }
|
|
72613
|
+
})), opts.brand);
|
|
72614
|
+
const roster = readAnswer(await sendPairing(opts.fetcher, (transport) => (0, jobs_1.createClient)({ baseUrl: opts.jobsApiUrl, transport }).get("/api/my/pools", {
|
|
72615
|
+
headers: { Authorization: `Bearer ${minted.token}` }
|
|
72616
|
+
})), opts.brand);
|
|
72617
|
+
return roster.pools;
|
|
72650
72618
|
}
|
|
72651
72619
|
function webFirstRemedy(brand, cause) {
|
|
72652
72620
|
const reason = cause instanceof Error ? cause.message : String(cause);
|
|
@@ -72683,90 +72651,105 @@ var require_device_code = __commonJS({
|
|
|
72683
72651
|
return opts.columns ?? process.stdout.columns;
|
|
72684
72652
|
}
|
|
72685
72653
|
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;
|
|
72654
|
+
const answer = await sendPairing(opts.fetcher, (transport) => (0, keep_1.createClient)({ baseUrl: opts.keepApiUrl, transport }).post("/api/oauth/device", {
|
|
72655
|
+
body: { client_id: opts.oauthClientId }
|
|
72656
|
+
}));
|
|
72657
|
+
return readAnswer(answer, opts.brand);
|
|
72702
72658
|
}
|
|
72703
72659
|
async function pollForToken(opts) {
|
|
72704
|
-
const url = `${opts.keepApiUrl.replace(/\/$/, "")}/api/oauth/device/token`;
|
|
72705
72660
|
const deadline = Date.now() + opts.timeoutMs;
|
|
72706
72661
|
while (Date.now() < deadline) {
|
|
72707
|
-
const
|
|
72708
|
-
|
|
72709
|
-
headers: { "Content-Type": "application/json" },
|
|
72710
|
-
body: JSON.stringify({
|
|
72662
|
+
const answer = await sendPairing(opts.fetcher, (transport) => (0, keep_1.createClient)({ baseUrl: opts.keepApiUrl, transport }).post("/api/oauth/device/token", {
|
|
72663
|
+
body: {
|
|
72711
72664
|
client_id: opts.oauthClientId,
|
|
72712
72665
|
device_code: opts.deviceCode,
|
|
72713
72666
|
display_name: opts.displayName,
|
|
72714
72667
|
hostname: (0, os_1.hostname)(),
|
|
72715
72668
|
os_user: (0, os_1.userInfo)().username
|
|
72716
|
-
}
|
|
72717
|
-
});
|
|
72718
|
-
if (
|
|
72669
|
+
}
|
|
72670
|
+
}));
|
|
72671
|
+
if (answer.status === 202) {
|
|
72719
72672
|
await sleep(opts.intervalMs);
|
|
72720
72673
|
continue;
|
|
72721
72674
|
}
|
|
72722
|
-
if (
|
|
72675
|
+
if (answer.status === 410) {
|
|
72723
72676
|
throw new Error("Pairing code expired before verification.");
|
|
72724
72677
|
}
|
|
72725
|
-
(
|
|
72726
|
-
|
|
72727
|
-
|
|
72728
|
-
|
|
72729
|
-
|
|
72730
|
-
});
|
|
72731
|
-
const json = await readJson(response);
|
|
72732
|
-
return json.data;
|
|
72678
|
+
const issued = readAnswer(answer, opts.brand);
|
|
72679
|
+
if ("status" in issued) {
|
|
72680
|
+
throw new Error(`Pairing endpoint returned status ${answer.status}.`);
|
|
72681
|
+
}
|
|
72682
|
+
return issued;
|
|
72733
72683
|
}
|
|
72734
72684
|
throw new Error("Pairing timed out before verification.");
|
|
72735
72685
|
}
|
|
72736
72686
|
async function redeemPairingCode(opts) {
|
|
72737
|
-
const
|
|
72738
|
-
|
|
72739
|
-
method: "POST",
|
|
72740
|
-
headers: { "Content-Type": "application/json" },
|
|
72741
|
-
body: JSON.stringify({
|
|
72687
|
+
const answer = await sendPairing(opts.fetcher, (transport) => (0, keep_1.createClient)({ baseUrl: opts.keepApiUrl, transport }).post("/api/oauth/device/redeem", {
|
|
72688
|
+
body: {
|
|
72742
72689
|
client_id: opts.oauthClientId,
|
|
72743
72690
|
user_code: opts.userCode,
|
|
72744
72691
|
display_name: opts.displayName,
|
|
72745
72692
|
hostname: (0, os_1.hostname)(),
|
|
72746
72693
|
os_user: (0, os_1.userInfo)().username
|
|
72747
|
-
}
|
|
72694
|
+
}
|
|
72695
|
+
}));
|
|
72696
|
+
return readAnswer(answer, opts.brand);
|
|
72697
|
+
}
|
|
72698
|
+
async function sendPairing(fetcher, send) {
|
|
72699
|
+
let raised;
|
|
72700
|
+
let seen;
|
|
72701
|
+
const result = await send(async (url, init2) => {
|
|
72702
|
+
let response;
|
|
72703
|
+
try {
|
|
72704
|
+
response = await fetcher(url, init2);
|
|
72705
|
+
} catch (err2) {
|
|
72706
|
+
raised = { error: err2 };
|
|
72707
|
+
throw err2;
|
|
72708
|
+
}
|
|
72709
|
+
const text = await response.text().catch(() => void 0);
|
|
72710
|
+
seen = { status: response.status, headers: response.headers, ...readBody(text) };
|
|
72711
|
+
return new Response(text ? text : null, {
|
|
72712
|
+
status: response.status,
|
|
72713
|
+
statusText: response.statusText,
|
|
72714
|
+
headers: response.headers
|
|
72715
|
+
});
|
|
72748
72716
|
});
|
|
72717
|
+
if (raised)
|
|
72718
|
+
throw raised.error;
|
|
72719
|
+
if (!seen)
|
|
72720
|
+
throw new Error("Pairing endpoint gave no answer.");
|
|
72721
|
+
return { result, ...seen };
|
|
72722
|
+
}
|
|
72723
|
+
function readAnswer(answer, brand) {
|
|
72749
72724
|
(0, version_check_1.checkResponseMinVersion)({
|
|
72750
|
-
response,
|
|
72751
|
-
productId:
|
|
72752
|
-
currentVersion:
|
|
72753
|
-
packageName:
|
|
72725
|
+
response: answer,
|
|
72726
|
+
productId: brand.product.id,
|
|
72727
|
+
currentVersion: brand.product.version,
|
|
72728
|
+
packageName: brand.product.packageName
|
|
72754
72729
|
});
|
|
72755
|
-
|
|
72756
|
-
|
|
72730
|
+
if (!answer.json) {
|
|
72731
|
+
throw new Error(`Pairing endpoint returned non-JSON (status ${answer.status}).`);
|
|
72732
|
+
}
|
|
72733
|
+
if (!answer.result.success) {
|
|
72734
|
+
throw new Error(answer.refusalMessage ?? `Pairing endpoint returned status ${answer.status}.`);
|
|
72735
|
+
}
|
|
72736
|
+
return answer.result.data;
|
|
72757
72737
|
}
|
|
72758
|
-
|
|
72738
|
+
function readBody(text) {
|
|
72739
|
+
if (text === void 0)
|
|
72740
|
+
return { json: false, refusalMessage: void 0 };
|
|
72759
72741
|
let body2;
|
|
72760
72742
|
try {
|
|
72761
|
-
body2 =
|
|
72743
|
+
body2 = JSON.parse(text);
|
|
72762
72744
|
} catch {
|
|
72763
|
-
|
|
72764
|
-
}
|
|
72765
|
-
if (!response.ok) {
|
|
72766
|
-
const err2 = body2;
|
|
72767
|
-
throw new Error(err2.error?.message ?? `Pairing endpoint returned status ${response.status}.`);
|
|
72745
|
+
return { json: false, refusalMessage: void 0 };
|
|
72768
72746
|
}
|
|
72769
|
-
|
|
72747
|
+
const error = isRecord(body2) ? body2.error : void 0;
|
|
72748
|
+
const message = isRecord(error) ? error.message : void 0;
|
|
72749
|
+
return { json: true, refusalMessage: typeof message === "string" ? message : void 0 };
|
|
72750
|
+
}
|
|
72751
|
+
function isRecord(value) {
|
|
72752
|
+
return typeof value === "object" && value !== null;
|
|
72770
72753
|
}
|
|
72771
72754
|
function sleep(ms) {
|
|
72772
72755
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -76407,7 +76390,7 @@ var import_shuttle2 = __toESM(require_dist8());
|
|
|
76407
76390
|
|
|
76408
76391
|
// src/brand.ts
|
|
76409
76392
|
var import_shuttle = __toESM(require_dist8());
|
|
76410
|
-
var buildVersion = true ? "0.1.
|
|
76393
|
+
var buildVersion = true ? "0.1.9" : pkg.version;
|
|
76411
76394
|
var EXECUTORS = ["claude-code"];
|
|
76412
76395
|
var trivetBrand = {
|
|
76413
76396
|
product: {
|