@indigoai-us/hq-cli 5.345.187 → 5.345.188
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/CHANGELOG.md +14 -0
- package/dist/commands/agent-inbox.js +43 -11
- package/dist/commands/agent-mcp.js +5 -2
- package/dist/hq-cloud-sync-runner/bin/sync-runner.js +34414 -49801
- package/dist/hq-cloud-sync-runner/package.json +1 -1
- package/dist/lib/agent-kit/inbox-fetch.d.ts +92 -0
- package/dist/lib/agent-kit/inbox-fetch.js +135 -0
- package/dist/lib/agent-kit/mcp/tools.d.ts +11 -2
- package/dist/lib/agent-kit/mcp/tools.js +17 -3
- package/dist/utils/cognito-session.d.ts +1 -1
- package/dist/utils/cognito-session.js +16 -4
- package/package.json +8 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"hq-cli-daemon-sync-runner","type":"module","version":"6.18.
|
|
1
|
+
{"name":"hq-cli-daemon-sync-runner","type":"module","version":"6.18.107","bundleSha256":"0df48ddf2618cac4801b8abefa1d2a4b4a915f368bf7d1b2823bcdd104044325","formatVersion":1}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bounded, once-retried read of the agent's server inbox.
|
|
3
|
+
*
|
|
4
|
+
* `hq agent inbox` and the `hq_inbox_read` MCP tool used to do one token mint
|
|
5
|
+
* and one GET with no deadline and no retry, so three transient conditions
|
|
6
|
+
* each showed up as a local-mirror fallback that cleared minutes later
|
|
7
|
+
* (feedback 3e376c49, DEV-4065):
|
|
8
|
+
*
|
|
9
|
+
* - the machine-token cache is shared with the kit poller and heartbeat,
|
|
10
|
+
* which re-mint in the same minute each hour; hq-cloud serialises mints
|
|
11
|
+
* behind a 20 s lock and throws "... held by another process ..." when it
|
|
12
|
+
* gives up waiting;
|
|
13
|
+
* - the server bounds its inbox pull at 18 s and answers 503 with
|
|
14
|
+
* `Retry-After: 2` when the listing stalls;
|
|
15
|
+
* - a half-open socket can hang the GET until the OS drops it.
|
|
16
|
+
*
|
|
17
|
+
* Each attempt (mint plus GET) runs under one deadline. A first attempt that
|
|
18
|
+
* fails for one of those reasons is retried exactly once after a short delay
|
|
19
|
+
* (the server's `Retry-After`, capped, when it sent one). The second attempt
|
|
20
|
+
* mints a fresh token, because the first failure may have been the mint. Auth
|
|
21
|
+
* and not-found answers, and a 200 whose body is invalid, are never retried.
|
|
22
|
+
* Pure apart from the injected `sleep`/`random`, so tests drive it with fake
|
|
23
|
+
* timers.
|
|
24
|
+
*/
|
|
25
|
+
import type { MergedInbox } from "./inbox-state.js";
|
|
26
|
+
/** Env override for the per-attempt deadline; values under the floor are raised to it. */
|
|
27
|
+
export declare const AGENT_INBOX_TIMEOUT_ENV = "HQ_AGENT_INBOX_TIMEOUT_MS";
|
|
28
|
+
/** Delay before the one retry when the server sent no usable `Retry-After`. */
|
|
29
|
+
export declare const AGENT_INBOX_RETRY_BASE_MS = 1500;
|
|
30
|
+
/** Jitter added to the base delay, so clients that fail together do not retry together. */
|
|
31
|
+
export declare const AGENT_INBOX_RETRY_JITTER_MS = 500;
|
|
32
|
+
/** Longest wait honoured from a `Retry-After` header. */
|
|
33
|
+
export declare const AGENT_INBOX_RETRY_AFTER_CAP_MS = 5000;
|
|
34
|
+
/** Total attempts: the first read plus one retry. */
|
|
35
|
+
export declare const AGENT_INBOX_MAX_ATTEMPTS = 2;
|
|
36
|
+
export interface InboxFetchResponse {
|
|
37
|
+
status: number;
|
|
38
|
+
/** Decoded JSON body, or `undefined` when it did not decode. Never a raw string of response bytes. */
|
|
39
|
+
body: unknown;
|
|
40
|
+
/** Parsed numeric `Retry-After` header in seconds, when the server sent one. */
|
|
41
|
+
retryAfterSeconds?: number;
|
|
42
|
+
}
|
|
43
|
+
export interface FetchServerInboxDeps {
|
|
44
|
+
/** Mint (or fetch from cache) the machine token. Called again for the retry. */
|
|
45
|
+
mint: (signal: AbortSignal) => Promise<string>;
|
|
46
|
+
/** GET the inbox with `token`. Must not throw on a non-2xx status. */
|
|
47
|
+
fetch: (token: string, signal: AbortSignal) => Promise<InboxFetchResponse>;
|
|
48
|
+
sleep?: (ms: number) => Promise<void>;
|
|
49
|
+
/** Uniform [0, 1) source for the jitter. */
|
|
50
|
+
random?: () => number;
|
|
51
|
+
/** Per-attempt deadline covering mint plus GET. */
|
|
52
|
+
timeoutMs?: number;
|
|
53
|
+
}
|
|
54
|
+
export type FetchServerInboxOutcome = {
|
|
55
|
+
ok: true;
|
|
56
|
+
response: {
|
|
57
|
+
status: number;
|
|
58
|
+
body: unknown;
|
|
59
|
+
};
|
|
60
|
+
attempts: number;
|
|
61
|
+
} | {
|
|
62
|
+
ok: false;
|
|
63
|
+
error: unknown;
|
|
64
|
+
attempts: number;
|
|
65
|
+
};
|
|
66
|
+
/** Per-attempt deadline from the env, defaulting to the kit's request timeout. */
|
|
67
|
+
export declare function resolveAgentInboxTimeoutMs(env?: NodeJS.ProcessEnv): number;
|
|
68
|
+
/** Whether a thrown first attempt is worth one more try. */
|
|
69
|
+
export declare function isRetryableInboxError(err: unknown): boolean;
|
|
70
|
+
export declare function isRetryableInboxStatus(status: number): boolean;
|
|
71
|
+
/** `Retry-After` as seconds, or undefined for a missing, non-numeric or negative value. */
|
|
72
|
+
export declare function parseRetryAfterSeconds(header: string | null | undefined): number | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Read the server inbox with at most AGENT_INBOX_MAX_ATTEMPTS attempts, each
|
|
75
|
+
* bounded by `timeoutMs`. Never throws: the outcome carries either the last
|
|
76
|
+
* response or the last error, plus how many attempts were made.
|
|
77
|
+
*/
|
|
78
|
+
export declare function fetchServerInboxWithRetry(deps: FetchServerInboxDeps): Promise<FetchServerInboxOutcome>;
|
|
79
|
+
/** Suffix added to the degradation note when the retry also failed. */
|
|
80
|
+
export declare const AGENT_INBOX_AFTER_ATTEMPTS_SUFFIX = " (after 2 attempts)";
|
|
81
|
+
export interface AnnotatedInbox extends MergedInbox {
|
|
82
|
+
/** True whenever the answer is not a complete server read. */
|
|
83
|
+
stale: boolean;
|
|
84
|
+
/** Present when more than one attempt was made, so a hard failure is distinct from a single blip. */
|
|
85
|
+
attempts?: number;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Add `stale` and, when a retry happened, `attempts` to a merged inbox. A
|
|
89
|
+
* degraded note after a retry also says so in words.
|
|
90
|
+
*/
|
|
91
|
+
export declare function annotateInboxAttempts(merged: MergedInbox, attempts: number): AnnotatedInbox;
|
|
92
|
+
//# sourceMappingURL=inbox-fetch.d.ts.map
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bounded, once-retried read of the agent's server inbox.
|
|
3
|
+
*
|
|
4
|
+
* `hq agent inbox` and the `hq_inbox_read` MCP tool used to do one token mint
|
|
5
|
+
* and one GET with no deadline and no retry, so three transient conditions
|
|
6
|
+
* each showed up as a local-mirror fallback that cleared minutes later
|
|
7
|
+
* (feedback 3e376c49, DEV-4065):
|
|
8
|
+
*
|
|
9
|
+
* - the machine-token cache is shared with the kit poller and heartbeat,
|
|
10
|
+
* which re-mint in the same minute each hour; hq-cloud serialises mints
|
|
11
|
+
* behind a 20 s lock and throws "... held by another process ..." when it
|
|
12
|
+
* gives up waiting;
|
|
13
|
+
* - the server bounds its inbox pull at 18 s and answers 503 with
|
|
14
|
+
* `Retry-After: 2` when the listing stalls;
|
|
15
|
+
* - a half-open socket can hang the GET until the OS drops it.
|
|
16
|
+
*
|
|
17
|
+
* Each attempt (mint plus GET) runs under one deadline. A first attempt that
|
|
18
|
+
* fails for one of those reasons is retried exactly once after a short delay
|
|
19
|
+
* (the server's `Retry-After`, capped, when it sent one). The second attempt
|
|
20
|
+
* mints a fresh token, because the first failure may have been the mint. Auth
|
|
21
|
+
* and not-found answers, and a 200 whose body is invalid, are never retried.
|
|
22
|
+
* Pure apart from the injected `sleep`/`random`, so tests drive it with fake
|
|
23
|
+
* timers.
|
|
24
|
+
*/
|
|
25
|
+
import { networkTransportErrorCode } from "../../utils/network-transport-error.js";
|
|
26
|
+
import { KIT_REQUEST_TIMEOUT_MIN_MS, KIT_REQUEST_TIMEOUT_MS, KitRequestTimeoutError, withRequestTimeout } from "./run/request-timeout.js";
|
|
27
|
+
/** Env override for the per-attempt deadline; values under the floor are raised to it. */
|
|
28
|
+
export const AGENT_INBOX_TIMEOUT_ENV = "HQ_AGENT_INBOX_TIMEOUT_MS";
|
|
29
|
+
/** Delay before the one retry when the server sent no usable `Retry-After`. */
|
|
30
|
+
export const AGENT_INBOX_RETRY_BASE_MS = 1_500;
|
|
31
|
+
/** Jitter added to the base delay, so clients that fail together do not retry together. */
|
|
32
|
+
export const AGENT_INBOX_RETRY_JITTER_MS = 500;
|
|
33
|
+
/** Longest wait honoured from a `Retry-After` header. */
|
|
34
|
+
export const AGENT_INBOX_RETRY_AFTER_CAP_MS = 5_000;
|
|
35
|
+
/** Total attempts: the first read plus one retry. */
|
|
36
|
+
export const AGENT_INBOX_MAX_ATTEMPTS = 2;
|
|
37
|
+
// 504 is absent on purpose: vaultApiFetch already retries a 504 once
|
|
38
|
+
// (Lambda invoke errors), and a second outer retry would make three GETs.
|
|
39
|
+
const RETRYABLE_STATUSES = new Set([408, 425, 429, 500, 502, 503]);
|
|
40
|
+
const LOCK_HELD_RE = /held by another process/i;
|
|
41
|
+
const TRANSPORT_MESSAGE_RE = /\b(fetch failed|ECONNRESET|ETIMEDOUT|EAI_AGAIN)\b/;
|
|
42
|
+
/** Per-attempt deadline from the env, defaulting to the kit's request timeout. */
|
|
43
|
+
export function resolveAgentInboxTimeoutMs(env = process.env) {
|
|
44
|
+
const raw = env[AGENT_INBOX_TIMEOUT_ENV]?.trim();
|
|
45
|
+
if (!raw)
|
|
46
|
+
return KIT_REQUEST_TIMEOUT_MS;
|
|
47
|
+
const n = Number(raw);
|
|
48
|
+
if (!Number.isFinite(n))
|
|
49
|
+
return KIT_REQUEST_TIMEOUT_MS;
|
|
50
|
+
return Math.max(KIT_REQUEST_TIMEOUT_MIN_MS, Math.floor(n));
|
|
51
|
+
}
|
|
52
|
+
/** Whether a thrown first attempt is worth one more try. */
|
|
53
|
+
export function isRetryableInboxError(err) {
|
|
54
|
+
if (err instanceof KitRequestTimeoutError)
|
|
55
|
+
return true;
|
|
56
|
+
if (!(err instanceof Error))
|
|
57
|
+
return false;
|
|
58
|
+
if (LOCK_HELD_RE.test(err.message))
|
|
59
|
+
return true;
|
|
60
|
+
if (networkTransportErrorCode(err) !== null)
|
|
61
|
+
return true;
|
|
62
|
+
if (err instanceof TypeError && err.message === "fetch failed")
|
|
63
|
+
return true;
|
|
64
|
+
return TRANSPORT_MESSAGE_RE.test(err.message);
|
|
65
|
+
}
|
|
66
|
+
export function isRetryableInboxStatus(status) {
|
|
67
|
+
return RETRYABLE_STATUSES.has(status);
|
|
68
|
+
}
|
|
69
|
+
/** `Retry-After` as seconds, or undefined for a missing, non-numeric or negative value. */
|
|
70
|
+
export function parseRetryAfterSeconds(header) {
|
|
71
|
+
if (header === null || header === undefined)
|
|
72
|
+
return undefined;
|
|
73
|
+
const trimmed = header.trim();
|
|
74
|
+
if (!/^\d+(\.\d+)?$/.test(trimmed))
|
|
75
|
+
return undefined;
|
|
76
|
+
const n = Number(trimmed);
|
|
77
|
+
return Number.isFinite(n) && n >= 0 ? n : undefined;
|
|
78
|
+
}
|
|
79
|
+
function retryDelayMs(retryAfterSeconds, random) {
|
|
80
|
+
if (retryAfterSeconds !== undefined) {
|
|
81
|
+
return Math.min(AGENT_INBOX_RETRY_AFTER_CAP_MS, Math.round(retryAfterSeconds * 1000));
|
|
82
|
+
}
|
|
83
|
+
return AGENT_INBOX_RETRY_BASE_MS + Math.floor(random() * AGENT_INBOX_RETRY_JITTER_MS);
|
|
84
|
+
}
|
|
85
|
+
const defaultSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
86
|
+
/**
|
|
87
|
+
* Read the server inbox with at most AGENT_INBOX_MAX_ATTEMPTS attempts, each
|
|
88
|
+
* bounded by `timeoutMs`. Never throws: the outcome carries either the last
|
|
89
|
+
* response or the last error, plus how many attempts were made.
|
|
90
|
+
*/
|
|
91
|
+
export async function fetchServerInboxWithRetry(deps) {
|
|
92
|
+
const sleep = deps.sleep ?? defaultSleep;
|
|
93
|
+
const random = deps.random ?? Math.random;
|
|
94
|
+
const timeoutMs = deps.timeoutMs ?? KIT_REQUEST_TIMEOUT_MS;
|
|
95
|
+
let attempts = 0;
|
|
96
|
+
for (;;) {
|
|
97
|
+
attempts += 1;
|
|
98
|
+
const last = attempts >= AGENT_INBOX_MAX_ATTEMPTS;
|
|
99
|
+
let retryAfterSeconds;
|
|
100
|
+
try {
|
|
101
|
+
const res = await withRequestTimeout(timeoutMs, undefined, async (signal) => {
|
|
102
|
+
const token = await deps.mint(signal);
|
|
103
|
+
return deps.fetch(token, signal);
|
|
104
|
+
});
|
|
105
|
+
if (last || !isRetryableInboxStatus(res.status)) {
|
|
106
|
+
return { ok: true, response: { status: res.status, body: res.body }, attempts };
|
|
107
|
+
}
|
|
108
|
+
retryAfterSeconds = res.retryAfterSeconds;
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
if (last || !isRetryableInboxError(err))
|
|
112
|
+
return { ok: false, error: err, attempts };
|
|
113
|
+
}
|
|
114
|
+
await sleep(retryDelayMs(retryAfterSeconds, random));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/** Suffix added to the degradation note when the retry also failed. */
|
|
118
|
+
export const AGENT_INBOX_AFTER_ATTEMPTS_SUFFIX = ` (after ${AGENT_INBOX_MAX_ATTEMPTS} attempts)`;
|
|
119
|
+
/**
|
|
120
|
+
* Add `stale` and, when a retry happened, `attempts` to a merged inbox. A
|
|
121
|
+
* degraded note after a retry also says so in words.
|
|
122
|
+
*/
|
|
123
|
+
export function annotateInboxAttempts(merged, attempts) {
|
|
124
|
+
const stale = merged.source !== "server";
|
|
125
|
+
const retried = attempts > 1;
|
|
126
|
+
const note = merged.note && retried && stale ? `${merged.note}${AGENT_INBOX_AFTER_ATTEMPTS_SUFFIX}` : merged.note;
|
|
127
|
+
return {
|
|
128
|
+
entries: merged.entries,
|
|
129
|
+
source: merged.source,
|
|
130
|
+
stale,
|
|
131
|
+
...(note ? { note } : {}),
|
|
132
|
+
...(retried ? { attempts } : {}),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=inbox-fetch.js.map
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* tool result.
|
|
17
17
|
*/
|
|
18
18
|
import type { ExternalMachineCreds } from "../creds.js";
|
|
19
|
+
import { type FetchServerInboxDeps } from "../inbox-fetch.js";
|
|
19
20
|
import type { AgentKitPaths } from "../paths.js";
|
|
20
21
|
import { type McpTool } from "./jsonrpc.js";
|
|
21
22
|
export interface HqRunResult {
|
|
@@ -32,7 +33,8 @@ export interface McpToolClients {
|
|
|
32
33
|
paths: Pick<AgentKitPaths, "inboxDir" | "attachmentsDir">;
|
|
33
34
|
/** Run `hq <args…>` as the machine identity; never throws. */
|
|
34
35
|
runHq: (args: string[]) => Promise<HqRunResult>;
|
|
35
|
-
|
|
36
|
+
/** Machine token; `signal` cancels this caller's wait on a shared mint. */
|
|
37
|
+
getToken: (signal?: AbortSignal) => Promise<string>;
|
|
36
38
|
/**
|
|
37
39
|
* Whether this kit mirrors the vault to disk. Off by default, and it decides
|
|
38
40
|
* what `hq_search` can honestly do: the local qmd index only exists when
|
|
@@ -47,15 +49,22 @@ export interface McpToolClients {
|
|
|
47
49
|
* key through the presign API, as the machine identity.
|
|
48
50
|
*/
|
|
49
51
|
downloadVaultObject: (scopeUid: string, key: string) => Promise<Buffer>;
|
|
50
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* Authenticated JSON call against the control plane. `retryAfterSeconds` is
|
|
54
|
+
* the server's numeric `Retry-After`, when it sent one.
|
|
55
|
+
*/
|
|
51
56
|
apiJson: (token: string, path: string, init?: {
|
|
52
57
|
method?: string;
|
|
53
58
|
body?: Record<string, unknown>;
|
|
54
59
|
query?: Record<string, string>;
|
|
60
|
+
signal?: AbortSignal;
|
|
55
61
|
}) => Promise<{
|
|
56
62
|
status: number;
|
|
57
63
|
body: unknown;
|
|
64
|
+
retryAfterSeconds?: number;
|
|
58
65
|
}>;
|
|
66
|
+
/** Test seam for hq_inbox_read's bounded retry (sleep, jitter source, per-attempt deadline). */
|
|
67
|
+
inboxRetry?: Pick<FetchServerInboxDeps, "sleep" | "random" | "timeoutMs">;
|
|
59
68
|
}
|
|
60
69
|
export declare function clampOutput(text: string, max?: number): string;
|
|
61
70
|
/** Vault paths are company-anchored and must not escape. */
|
|
@@ -19,6 +19,7 @@ import { CLI_VERSION } from "../../../cli-version.js";
|
|
|
19
19
|
import { peekIdToken } from "../../../utils/id-token.js";
|
|
20
20
|
import { PERSON_AGENT_AUDIENCE_MESSAGE, callerMayUseAudience, defaultAudienceFor, isAgentUid, isRecipientUid } from "../../../lib/notify-recipient.js";
|
|
21
21
|
import { tokenIsMachinePrincipal } from "../../../lib/caller-principal.js";
|
|
22
|
+
import { annotateInboxAttempts, fetchServerInboxWithRetry, resolveAgentInboxTimeoutMs } from "../inbox-fetch.js";
|
|
22
23
|
import { redactAgentInboxItem } from "../inbox-redact.js";
|
|
23
24
|
import { markInboxDone, mergeAgentInbox, readDoneIds, summarizeInboxEntry } from "../inbox-state.js";
|
|
24
25
|
import { AttachmentCompanyUnresolvedError, fetchChatAttachment } from "./attachments.js";
|
|
@@ -286,10 +287,21 @@ export function buildAgentMcpTools(clients) {
|
|
|
286
287
|
const limit = int(args, "limit", { min: 1, max: 100, fallback: 20 });
|
|
287
288
|
const includeDone = args.include_done === true;
|
|
288
289
|
const done = readDoneIds(clients.paths);
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
290
|
+
// Same bounded, once-retried server read as `hq agent inbox`.
|
|
291
|
+
let attempts = 1;
|
|
292
|
+
const merged = await mergeAgentInbox(clients.paths, async () => {
|
|
293
|
+
const outcome = await fetchServerInboxWithRetry({
|
|
294
|
+
timeoutMs: resolveAgentInboxTimeoutMs(process.env),
|
|
295
|
+
...clients.inboxRetry,
|
|
296
|
+
mint: (signal) => clients.getToken(signal),
|
|
297
|
+
fetch: (token, signal) => clients.apiJson(token, `/v1/agents/${encodeURIComponent(creds.entityUid)}/inbox`, { signal }),
|
|
298
|
+
});
|
|
299
|
+
attempts = outcome.attempts;
|
|
300
|
+
if (!outcome.ok)
|
|
301
|
+
throw outcome.error;
|
|
302
|
+
return outcome.response;
|
|
292
303
|
});
|
|
304
|
+
const { entries, note: serverNote, source, stale, attempts: attemptsMade } = annotateInboxAttempts(merged, attempts);
|
|
293
305
|
const byId = new Map(entries.map((e) => [e.id, e]));
|
|
294
306
|
const rows = [...byId.values()]
|
|
295
307
|
.filter((e) => includeDone || !done.has(e.id))
|
|
@@ -299,6 +311,8 @@ export function buildAgentMcpTools(clients) {
|
|
|
299
311
|
return textResult(clampOutput(JSON.stringify({
|
|
300
312
|
count: rows.length,
|
|
301
313
|
source,
|
|
314
|
+
stale,
|
|
315
|
+
...(attemptsMade !== undefined ? { attempts: attemptsMade } : {}),
|
|
302
316
|
messages: rows,
|
|
303
317
|
...(serverNote ? { note: serverNote } : {}),
|
|
304
318
|
...(hasFiles ? { attachmentsHint: ATTACHMENTS_HINT } : {}),
|
|
@@ -267,7 +267,7 @@ export declare function buildVaultConfig(authToken: string): VaultServiceConfig;
|
|
|
267
267
|
* means no valid session could be ensured non-interactively; the caller gets a
|
|
268
268
|
* reason string and can decide what to do next. Never opens a browser.
|
|
269
269
|
*/
|
|
270
|
-
type MachineRefreshOptions = Pick<EnsureCognitoTokenOptions, "tokenSource"> & MachineTokenValidityOptions & {
|
|
270
|
+
type MachineRefreshOptions = Pick<EnsureCognitoTokenOptions, "tokenSource" | "signal"> & MachineTokenValidityOptions & {
|
|
271
271
|
/** Refresh the person session even when the cached token is still valid. */
|
|
272
272
|
force?: boolean;
|
|
273
273
|
};
|
|
@@ -780,11 +780,21 @@ function withTokenStateDirSection(fn) {
|
|
|
780
780
|
return run;
|
|
781
781
|
}
|
|
782
782
|
const MAX_MACHINE_TOKEN_MIN_VALIDITY_SECONDS = 1800;
|
|
783
|
-
|
|
783
|
+
/**
|
|
784
|
+
* `signal` cancels only this caller's wait inside hq-cloud (a mint shared with
|
|
785
|
+
* other callers keeps running). Without it a bounded caller such as `hq agent
|
|
786
|
+
* inbox` timed out, retried, and its retry queued behind the orphaned first
|
|
787
|
+
* mint, which still held the lock.
|
|
788
|
+
*/
|
|
789
|
+
async function ensureMachineTokens(minValiditySeconds, signal) {
|
|
784
790
|
const resolverMinimum = minValiditySeconds === undefined
|
|
785
791
|
? undefined
|
|
786
792
|
: Math.min(minValiditySeconds, MAX_MACHINE_TOKEN_MIN_VALIDITY_SECONDS);
|
|
787
|
-
|
|
793
|
+
const resolverOptions = {
|
|
794
|
+
...(resolverMinimum === undefined ? {} : { minValiditySeconds: resolverMinimum }),
|
|
795
|
+
...(signal ? { signal } : {}),
|
|
796
|
+
};
|
|
797
|
+
return withMachineTokenStateDir(() => getValidMachineTokens(DEFAULT_COGNITO, Object.keys(resolverOptions).length === 0 ? undefined : resolverOptions));
|
|
788
798
|
}
|
|
789
799
|
/**
|
|
790
800
|
* Ensure the current machine identity has a valid session and return only the
|
|
@@ -803,7 +813,7 @@ async function ensureMachineTokensMaybeFallback(options = {}) {
|
|
|
803
813
|
if (isDefaultMachineCredsFallback(options)) {
|
|
804
814
|
logDefaultMachineCredsFallback();
|
|
805
815
|
}
|
|
806
|
-
return ensureMachineTokens(options.minValiditySeconds);
|
|
816
|
+
return ensureMachineTokens(options.minValiditySeconds, options.signal);
|
|
807
817
|
}
|
|
808
818
|
/**
|
|
809
819
|
* After a person-cache miss or refresh failure: if the default machine-creds
|
|
@@ -818,7 +828,7 @@ async function tryDefaultMachineCredsFallback(options = {}) {
|
|
|
818
828
|
if (!isMachineIdentity())
|
|
819
829
|
return null;
|
|
820
830
|
logDefaultMachineCredsFallback();
|
|
821
|
-
return ensureMachineTokens(options.minValiditySeconds);
|
|
831
|
+
return ensureMachineTokens(options.minValiditySeconds, options.signal);
|
|
822
832
|
}
|
|
823
833
|
/**
|
|
824
834
|
* True when a person-token refresh failed with a definitive Cognito auth
|
|
@@ -880,6 +890,8 @@ function resolvePersonSessionAfterRefreshRejection(cached) {
|
|
|
880
890
|
* a browser.
|
|
881
891
|
*/
|
|
882
892
|
export async function ensureCognitoToken(options = {}) {
|
|
893
|
+
if (options.signal?.aborted)
|
|
894
|
+
throw options.signal.reason ?? new Error("Token acquisition was aborted");
|
|
883
895
|
if (wantsMachineCognitoTokens(options))
|
|
884
896
|
return ensureCognitoTokenUnserialized(options);
|
|
885
897
|
return withTokenStateDirSection(() => ensureCognitoTokenUnserialized(options));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@indigoai-us/hq-cli",
|
|
3
|
-
"version": "5.345.
|
|
3
|
+
"version": "5.345.188",
|
|
4
4
|
"description": "HQ by Indigo management CLI — modules and cloud sync",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"@aws-sdk/client-iot-data-plane": "^3.1096.0",
|
|
53
53
|
"@aws-sdk/client-s3": "^3.1049.0",
|
|
54
54
|
"@aws-sdk/dsql-signer": "^3.1146.0",
|
|
55
|
-
"@indigoai-us/hq-cloud": "6.18.
|
|
55
|
+
"@indigoai-us/hq-cloud": "6.18.107",
|
|
56
56
|
"@indigoai-us/hq-flags-client": "^0.1.2",
|
|
57
57
|
"@modelcontextprotocol/sdk": "1.29.0",
|
|
58
58
|
"@sentry/node": "^10.49.0",
|
|
@@ -114,11 +114,11 @@
|
|
|
114
114
|
"*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}": "eslint --cache --no-error-on-unmatched-pattern"
|
|
115
115
|
},
|
|
116
116
|
"optionalDependencies": {
|
|
117
|
-
"@indigoai-us/hq-hook-win32-x64": "5.345.
|
|
118
|
-
"@indigoai-us/hq-hook-win32-arm64": "5.345.
|
|
119
|
-
"@indigoai-us/hq-hook-darwin-x64": "5.345.
|
|
120
|
-
"@indigoai-us/hq-hook-darwin-arm64": "5.345.
|
|
121
|
-
"@indigoai-us/hq-hook-linux-x64": "5.345.
|
|
122
|
-
"@indigoai-us/hq-hook-linux-arm64": "5.345.
|
|
117
|
+
"@indigoai-us/hq-hook-win32-x64": "5.345.188",
|
|
118
|
+
"@indigoai-us/hq-hook-win32-arm64": "5.345.188",
|
|
119
|
+
"@indigoai-us/hq-hook-darwin-x64": "5.345.188",
|
|
120
|
+
"@indigoai-us/hq-hook-darwin-arm64": "5.345.188",
|
|
121
|
+
"@indigoai-us/hq-hook-linux-x64": "5.345.188",
|
|
122
|
+
"@indigoai-us/hq-hook-linux-arm64": "5.345.188"
|
|
123
123
|
}
|
|
124
124
|
}
|