@herbertgao/pi-extensions 2026.11.18 → 2026.11.20
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 +18 -0
- package/README.md +5 -5
- package/THIRD_PARTY_NOTICES.md +3 -24
- package/node_modules/@estebanforge/pi-antigravity-bridge/CHANGELOG.md +956 -0
- package/node_modules/{pi-antigravity → @estebanforge/pi-antigravity-bridge}/LICENSE +1 -1
- package/node_modules/@estebanforge/pi-antigravity-bridge/README.md +240 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/extensions/index.ts +2117 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/package.json +61 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/connection.ts +644 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/driver.ts +1043 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/events.ts +323 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/home.ts +145 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/jsonrpc.ts +243 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/setup.ts +107 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/usage-estimate.ts +61 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/agents.ts +64 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-install.ts +93 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-paths.ts +30 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-setup.ts +81 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-version.ts +289 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/approval-detect.ts +161 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/approval-gate.ts +233 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/approval-hook.ts +325 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/artifacts-ui.ts +88 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/artifacts.ts +144 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/ask-tool.ts +1221 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/background-watch.ts +225 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/bridge-catalog.ts +197 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/config.ts +523 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/daily-log.ts +196 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/dialog-lock.ts +48 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/diff-render.ts +207 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/driver-types.ts +168 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/driver.ts +907 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/engine-picker.ts +160 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/frame-guard.ts +38 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/handoff-toast.ts +21 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/mcp-registration.ts +376 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/mcp-server.ts +618 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/models.ts +404 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/native-tools.ts +104 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/parked-turn.ts +125 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/patch-cleanup.ts +523 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/poll-fold.ts +55 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/prompt-images.ts +92 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/provider.ts +2214 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/queued-messages.ts +152 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/quota-notice.ts +40 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/redact.ts +27 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/sessions.ts +197 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/skills.ts +207 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/stream-events.ts +161 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/stream-sanitizer.ts +180 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/subagent-roster.ts +245 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/sysprompt-agent.ts +130 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/tasks-ui.ts +90 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/tasks.ts +174 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/usage.ts +174 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/web-tools.ts +320 -0
- package/node_modules/@herbertgao/pi-cc-extensions/CHANGELOG.md +6 -0
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/panel.ts +1 -1
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/shell/prompt-editor.ts +3 -1
- package/node_modules/@herbertgao/pi-cc-extensions/package.json +1 -1
- package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +317 -105
- package/node_modules/@herbertgao/pi-subagents/SECURITY.md +2 -2
- package/node_modules/@herbertgao/pi-subagents/docs/rpc.md +240 -36
- package/node_modules/@herbertgao/pi-subagents/docs/translations.md +63 -0
- package/node_modules/@herbertgao/pi-subagents/docs/workflows.md +1 -1
- package/node_modules/@herbertgao/pi-subagents/package.json +4 -4
- package/node_modules/@herbertgao/pi-subagents/src/agent-file-toggle.ts +2 -0
- package/node_modules/@herbertgao/pi-subagents/src/agent-manager.ts +89 -6
- package/node_modules/@herbertgao/pi-subagents/src/agent-runner.ts +6 -2
- package/node_modules/@herbertgao/pi-subagents/src/agent-types.ts +20 -11
- package/node_modules/@herbertgao/pi-subagents/src/cache-retention.ts +39 -0
- package/node_modules/@herbertgao/pi-subagents/src/completion-outbox.ts +5 -0
- package/node_modules/@herbertgao/pi-subagents/src/cross-extension-rpc.ts +185 -44
- package/node_modules/@herbertgao/pi-subagents/src/custom-agents.ts +7 -0
- package/node_modules/@herbertgao/pi-subagents/src/group-join.ts +9 -0
- package/node_modules/@herbertgao/pi-subagents/src/index.ts +126 -116
- package/node_modules/@herbertgao/pi-subagents/src/mention-clone.ts +3 -2
- package/node_modules/@herbertgao/pi-subagents/src/settings.ts +21 -0
- package/node_modules/@herbertgao/pi-subagents/src/subagent-info.ts +115 -0
- package/node_modules/@herbertgao/pi-subagents/src/types.ts +11 -7
- package/node_modules/@herbertgao/pi-subagents/src/ui/agent-widget.ts +2 -3
- package/node_modules/@herbertgao/pi-subagents/src/ui/conversation-viewer.ts +1 -1
- package/node_modules/@herbertgao/pi-subagents/src/workflow/meta.ts +2 -2
- package/node_modules/@herbertgao/pi-subagents/src/workflow-info.ts +184 -0
- package/node_modules/pi-commandcode-provider/CHANGELOG.md +10 -0
- package/node_modules/pi-commandcode-provider/README.md +3 -2
- package/node_modules/pi-commandcode-provider/index.ts +120 -13
- package/node_modules/pi-commandcode-provider/package.json +4 -3
- package/node_modules/pi-commandcode-provider/src/commandcode-catalog.ts +11 -2
- package/node_modules/pi-commandcode-provider/src/pricing.ts +17 -1
- package/node_modules/pi-commandcode-provider/src/quota-command.ts +3 -2
- package/node_modules/pi-commandcode-provider/src/zdr.ts +163 -0
- package/node_modules/pi-typesafe/README.md +1 -1
- package/node_modules/pi-typesafe/dist/ask.js +6 -3
- package/node_modules/pi-typesafe/dist/auth.d.ts +31 -7
- package/node_modules/pi-typesafe/dist/auth.js +159 -55
- package/node_modules/pi-typesafe/dist/batch.d.ts +16 -2
- package/node_modules/pi-typesafe/dist/batch.js +62 -22
- package/node_modules/pi-typesafe/dist/calibrate.d.ts +38 -11
- package/node_modules/pi-typesafe/dist/calibrate.js +56 -24
- package/node_modules/pi-typesafe/dist/client.d.ts +13 -0
- package/node_modules/pi-typesafe/dist/client.js +67 -27
- package/node_modules/pi-typesafe/dist/errors.d.ts +20 -0
- package/node_modules/pi-typesafe/dist/errors.js +105 -2
- package/node_modules/pi-typesafe/dist/extension.d.ts +106 -0
- package/node_modules/pi-typesafe/dist/extension.js +206 -106
- package/node_modules/pi-typesafe/dist/index.d.ts +8 -8
- package/node_modules/pi-typesafe/dist/index.js +3 -3
- package/node_modules/pi-typesafe/dist/key-prompt.d.ts +20 -0
- package/node_modules/pi-typesafe/dist/key-prompt.js +23 -3
- package/node_modules/pi-typesafe/dist/login.d.ts +58 -1
- package/node_modules/pi-typesafe/dist/login.js +167 -13
- package/node_modules/pi-typesafe/dist/schema.d.ts +3 -0
- package/node_modules/pi-typesafe/dist/schema.js +47 -13
- package/node_modules/pi-typesafe/dist/ui.d.ts +2 -1
- package/node_modules/pi-typesafe/dist/usage.d.ts +53 -0
- package/node_modules/pi-typesafe/dist/usage.js +79 -40
- package/node_modules/pi-typesafe/package.json +3 -3
- package/package.json +12 -15
- package/node_modules/pi-antigravity/README.md +0 -298
- package/node_modules/pi-antigravity/docs/reader-guarantees.md +0 -35
- package/node_modules/pi-antigravity/package.json +0 -87
- package/node_modules/pi-antigravity/src/auth/accounts.ts +0 -327
- package/node_modules/pi-antigravity/src/auth/index.ts +0 -23
- package/node_modules/pi-antigravity/src/auth/oauth.ts +0 -445
- package/node_modules/pi-antigravity/src/client/client.ts +0 -602
- package/node_modules/pi-antigravity/src/client/enterprise.ts +0 -150
- package/node_modules/pi-antigravity/src/client/index.ts +0 -2
- package/node_modules/pi-antigravity/src/diagnostics/diagnostics.ts +0 -104
- package/node_modules/pi-antigravity/src/diagnostics/index.ts +0 -1
- package/node_modules/pi-antigravity/src/features/generate-image.ts +0 -132
- package/node_modules/pi-antigravity/src/features/google-search.ts +0 -72
- package/node_modules/pi-antigravity/src/features/read-url-content.ts +0 -124
- package/node_modules/pi-antigravity/src/image/image.ts +0 -427
- package/node_modules/pi-antigravity/src/image/index.ts +0 -1
- package/node_modules/pi-antigravity/src/image/native.ts +0 -69
- package/node_modules/pi-antigravity/src/index.ts +0 -547
- package/node_modules/pi-antigravity/src/models/discovery.ts +0 -176
- package/node_modules/pi-antigravity/src/models/grouping.ts +0 -487
- package/node_modules/pi-antigravity/src/models/index.ts +0 -3
- package/node_modules/pi-antigravity/src/models/models.ts +0 -647
- package/node_modules/pi-antigravity/src/search/index.ts +0 -1
- package/node_modules/pi-antigravity/src/search/search.ts +0 -967
- package/node_modules/pi-antigravity/src/stream/index.ts +0 -1
- package/node_modules/pi-antigravity/src/stream/stream.ts +0 -1961
- package/node_modules/pi-antigravity/src/types/enums.ts +0 -52
- package/node_modules/pi-antigravity/src/types/index.ts +0 -2
- package/node_modules/pi-antigravity/src/types/types.ts +0 -329
- package/node_modules/pi-antigravity/src/usage/index.ts +0 -1
- package/node_modules/pi-antigravity/src/usage/usage.ts +0 -437
- package/node_modules/pi-antigravity/src/utils/address.ts +0 -180
- package/node_modules/pi-antigravity/src/utils/credits.ts +0 -149
- package/node_modules/pi-antigravity/src/utils/html.ts +0 -31
- package/node_modules/pi-antigravity/src/utils/http.ts +0 -96
- package/node_modules/pi-antigravity/src/utils/index.ts +0 -5
- package/node_modules/pi-antigravity/src/utils/security.ts +0 -278
- package/node_modules/pi-antigravity/src/utils/text.ts +0 -66
- package/node_modules/pi-antigravity/src/utils/util.ts +0 -217
- package/node_modules/pi-antigravity/src/web-fetch/document.ts +0 -83
- package/node_modules/pi-antigravity/src/web-fetch/fences.ts +0 -24
- package/node_modules/pi-antigravity/src/web-fetch/header.ts +0 -97
- package/node_modules/pi-antigravity/src/web-fetch/index.ts +0 -3
- package/node_modules/pi-antigravity/src/web-fetch/inspect.ts +0 -328
- package/node_modules/pi-antigravity/src/web-fetch/limits.ts +0 -4
- package/node_modules/pi-antigravity/src/web-fetch/markdown.ts +0 -744
- package/node_modules/pi-antigravity/src/web-fetch/mdn.ts +0 -164
- package/node_modules/pi-antigravity/src/web-fetch/media.ts +0 -11
- package/node_modules/pi-antigravity/src/web-fetch/metadata.ts +0 -9
- package/node_modules/pi-antigravity/src/web-fetch/representation.ts +0 -93
- package/node_modules/pi-antigravity/src/web-fetch/save.ts +0 -71
- package/node_modules/pi-antigravity/src/web-fetch/sites.ts +0 -138
- package/node_modules/pi-antigravity/src/web-fetch/vendor.d.ts +0 -9
- package/node_modules/pi-antigravity/src/web-fetch/web-fetch.ts +0 -957
- package/node_modules/pi-antigravity/tsconfig.json +0 -21
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { APIError, APIConnectionError, APITimeoutError, APIUserAbortError } from "@typesafe-ai/sdk";
|
|
2
2
|
import { DECISIONS_BACKENDS, TYPESAFE_KEY_ENV, backendConfig } from "./backends.js";
|
|
3
|
+
const INTEGRATION_ERROR_CODES = new Set([
|
|
4
|
+
"configuration", "validation", "budget", "aborted", "timeout", "http", "connection", "response",
|
|
5
|
+
]);
|
|
6
|
+
// Side tables keep extra metadata off error and AskAnswer instances so JSON.stringify and deep-equality shapes stay frozen.
|
|
7
|
+
const RETRY_AFTER = new WeakMap();
|
|
8
|
+
const ASSOCIATED_DISPOSITION = new WeakMap();
|
|
3
9
|
/**
|
|
4
10
|
* Safe to display: never contains upstream bodies, keys, or submitted state. The only header value a message can
|
|
5
11
|
* quote is a numeric Retry-After count in seconds, which cannot carry a secret.
|
|
@@ -13,6 +19,16 @@ export class TypeSafeIntegrationError extends Error {
|
|
|
13
19
|
this.code = code;
|
|
14
20
|
this.status = status;
|
|
15
21
|
}
|
|
22
|
+
get disposition() {
|
|
23
|
+
return classifyError(this);
|
|
24
|
+
}
|
|
25
|
+
get retryable() {
|
|
26
|
+
return this.disposition.retryable;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** Attach a known disposition to a non-throwing envelope (such as a failed AskAnswer) without adding properties to it. */
|
|
30
|
+
export function attachErrorDisposition(envelope, disposition) {
|
|
31
|
+
ASSOCIATED_DISPOSITION.set(envelope, disposition);
|
|
16
32
|
}
|
|
17
33
|
/** A numeric Retry-After delay in seconds; dates, blanks, and anything else stay out of the message. */
|
|
18
34
|
function retryAfterSeconds(error) {
|
|
@@ -22,6 +38,89 @@ function retryAfterSeconds(error) {
|
|
|
22
38
|
const seconds = Number(raw);
|
|
23
39
|
return Number.isSafeInteger(seconds) && seconds >= 0 ? seconds : undefined;
|
|
24
40
|
}
|
|
41
|
+
function parseRetryAfterFromMessage(message) {
|
|
42
|
+
const match = /\bRetry after (\d+) seconds\./.exec(message);
|
|
43
|
+
if (!match?.[1])
|
|
44
|
+
return undefined;
|
|
45
|
+
const seconds = Number(match[1]);
|
|
46
|
+
return Number.isSafeInteger(seconds) && seconds >= 0 ? seconds : undefined;
|
|
47
|
+
}
|
|
48
|
+
function parseHttpStatusFromMessage(message) {
|
|
49
|
+
const match = /\bHTTP (\d{3})\b/.exec(message);
|
|
50
|
+
if (!match?.[1])
|
|
51
|
+
return undefined;
|
|
52
|
+
const status = Number(match[1]);
|
|
53
|
+
return Number.isSafeInteger(status) ? status : undefined;
|
|
54
|
+
}
|
|
55
|
+
function classifyCode(code, status, retryAfter) {
|
|
56
|
+
switch (code) {
|
|
57
|
+
case "timeout":
|
|
58
|
+
case "connection":
|
|
59
|
+
return { status: "transient", retryable: true };
|
|
60
|
+
case "configuration":
|
|
61
|
+
return { status: "permanent", retryable: false, target: "configuration" };
|
|
62
|
+
case "validation":
|
|
63
|
+
return { status: "permanent", retryable: false, target: "validation" };
|
|
64
|
+
case "budget":
|
|
65
|
+
return { status: "permanent", retryable: false, target: "budget" };
|
|
66
|
+
case "aborted":
|
|
67
|
+
return { status: "permanent", retryable: false, target: "cancelled" };
|
|
68
|
+
case "response":
|
|
69
|
+
return { status: "permanent", retryable: false, target: "response" };
|
|
70
|
+
case "http": {
|
|
71
|
+
if (status === 408 || status === 429 || (status !== undefined && status >= 500 && status <= 599)) {
|
|
72
|
+
return {
|
|
73
|
+
status: "transient",
|
|
74
|
+
retryable: true,
|
|
75
|
+
...(retryAfter === undefined ? {} : { retryAfterSeconds: retryAfter }),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
if (status === 401)
|
|
79
|
+
return { status: "permanent", retryable: false, target: "credentials" };
|
|
80
|
+
if (status === 402)
|
|
81
|
+
return { status: "permanent", retryable: false, target: "billing" };
|
|
82
|
+
if (status === 403)
|
|
83
|
+
return { status: "permanent", retryable: false, target: "permission" };
|
|
84
|
+
if (status === 400 || status === 404 || status === 422)
|
|
85
|
+
return { status: "permanent", retryable: false, target: "validation" };
|
|
86
|
+
return { status: "permanent", retryable: false, target: "response" };
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Pure retryability classifier for `TypeSafeIntegrationError`, SDK errors, failed `AskAnswer` envelopes, or unknown
|
|
92
|
+
* throwables. Advises callers whether their own workflow may retry (`transient`) or must address a fixed target (`permanent`).
|
|
93
|
+
*/
|
|
94
|
+
export function classifyError(error) {
|
|
95
|
+
if (error instanceof TypeSafeIntegrationError) {
|
|
96
|
+
const retry = RETRY_AFTER.get(error) ?? parseRetryAfterFromMessage(error.message);
|
|
97
|
+
return classifyCode(error.code, error.status, retry);
|
|
98
|
+
}
|
|
99
|
+
if (error instanceof APIUserAbortError)
|
|
100
|
+
return classifyCode("aborted");
|
|
101
|
+
if (error instanceof APITimeoutError)
|
|
102
|
+
return classifyCode("timeout");
|
|
103
|
+
if (error instanceof APIConnectionError)
|
|
104
|
+
return classifyCode("connection");
|
|
105
|
+
if (error instanceof APIError)
|
|
106
|
+
return classifyCode("http", error.status, retryAfterSeconds(error));
|
|
107
|
+
if (error !== null && typeof error === "object") {
|
|
108
|
+
const associated = ASSOCIATED_DISPOSITION.get(error);
|
|
109
|
+
if (associated !== undefined)
|
|
110
|
+
return associated;
|
|
111
|
+
const raw = error;
|
|
112
|
+
if (raw.ok === false && typeof raw.error === "string") {
|
|
113
|
+
if (typeof raw.errorCode === "string" && INTEGRATION_ERROR_CODES.has(raw.errorCode)) {
|
|
114
|
+
const code = raw.errorCode;
|
|
115
|
+
const status = code === "http" ? parseHttpStatusFromMessage(raw.error) : undefined;
|
|
116
|
+
const retry = code === "http" ? parseRetryAfterFromMessage(raw.error) : undefined;
|
|
117
|
+
return classifyCode(code, status, retry);
|
|
118
|
+
}
|
|
119
|
+
return { status: "permanent", retryable: false, target: "response" };
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return { status: "permanent", retryable: false, target: "response" };
|
|
123
|
+
}
|
|
25
124
|
/**
|
|
26
125
|
* Classify an error into a message safe to display. The subject of every message is the backend that answered — its
|
|
27
126
|
* `label`, or the caller's endpoint label — falling back to TypeSafe when no backend is passed. `backend` also names
|
|
@@ -39,14 +138,18 @@ export function safeError(error, backend) {
|
|
|
39
138
|
if (error instanceof APITimeoutError)
|
|
40
139
|
return new TypeSafeIntegrationError("timeout", `${subject} request timed out; it was not retried and may still be billed.`);
|
|
41
140
|
if (error instanceof APIError) {
|
|
42
|
-
const
|
|
141
|
+
const headerRetry = retryAfterSeconds(error);
|
|
142
|
+
const retry = error.status === 429 ? headerRetry : undefined;
|
|
43
143
|
const advice = error.status === 401 ? `Check ${keyEnv}.`
|
|
44
144
|
: error.status === 402 ? (openrouter ? "Insufficient credits. Add credits at https://openrouter.ai/credits." : "Check your account balance.")
|
|
45
145
|
: error.status === 403 ? "Check your account access and model permissions."
|
|
46
146
|
: error.status === 429 ? `Check your account quota and try again later.${retry === undefined ? "" : ` Retry after ${retry} seconds.`}`
|
|
47
147
|
: error.status === 400 || error.status === 422 ? "Check the question format and model limits."
|
|
48
148
|
: "Try again later or check the service status.";
|
|
49
|
-
|
|
149
|
+
const safe = new TypeSafeIntegrationError("http", `${subject} returned HTTP ${error.status}. ${advice} No automatic retry was made.`, error.status);
|
|
150
|
+
if (headerRetry !== undefined)
|
|
151
|
+
RETRY_AFTER.set(safe, headerRetry);
|
|
152
|
+
return safe;
|
|
50
153
|
}
|
|
51
154
|
if (error instanceof APIConnectionError)
|
|
52
155
|
return new TypeSafeIntegrationError("connection", `Could not complete the ${subject} connection. No automatic retry was made.`);
|
|
@@ -1,3 +1,109 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { ResolvedBackend, TypeSafeBackend } from "./backends.js";
|
|
3
|
+
import type { SpendReport } from "./client.js";
|
|
4
|
+
import type { AuthReport, AuthState } from "./auth.js";
|
|
5
|
+
export interface RouteConsent {
|
|
6
|
+
readonly text: string;
|
|
7
|
+
readonly namesModel: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface ValidSessionRoute {
|
|
10
|
+
readonly status: "valid";
|
|
11
|
+
readonly backend: TypeSafeBackend;
|
|
12
|
+
readonly config: ResolvedBackend;
|
|
13
|
+
readonly model: string | undefined;
|
|
14
|
+
readonly sentModel: string;
|
|
15
|
+
readonly consent: RouteConsent;
|
|
16
|
+
}
|
|
17
|
+
export interface InvalidSessionRoute {
|
|
18
|
+
readonly status: "invalid";
|
|
19
|
+
readonly error: string;
|
|
20
|
+
}
|
|
21
|
+
export type SessionRoute = ValidSessionRoute | InvalidSessionRoute;
|
|
22
|
+
export type ConsentSource = "environment" | "command";
|
|
23
|
+
export type ConsentState = {
|
|
24
|
+
readonly status: "disabled";
|
|
25
|
+
} | {
|
|
26
|
+
readonly status: "enabled";
|
|
27
|
+
readonly source: ConsentSource;
|
|
28
|
+
};
|
|
29
|
+
export type ConsentEvent = {
|
|
30
|
+
readonly type: "session_start";
|
|
31
|
+
readonly envEnabled: boolean;
|
|
32
|
+
} | {
|
|
33
|
+
readonly type: "enable";
|
|
34
|
+
} | {
|
|
35
|
+
readonly type: "disable";
|
|
36
|
+
} | {
|
|
37
|
+
readonly type: "logout";
|
|
38
|
+
readonly isActive: boolean;
|
|
39
|
+
readonly hasEnvKey: boolean;
|
|
40
|
+
};
|
|
41
|
+
export type CalloutState = {
|
|
42
|
+
readonly status: "healthy";
|
|
43
|
+
} | {
|
|
44
|
+
readonly status: "degraded";
|
|
45
|
+
readonly key: string;
|
|
46
|
+
};
|
|
47
|
+
export type CalloutEvent = {
|
|
48
|
+
readonly type: "session_start";
|
|
49
|
+
} | {
|
|
50
|
+
readonly type: "login_succeeded";
|
|
51
|
+
} | {
|
|
52
|
+
readonly type: "evaluate_succeeded";
|
|
53
|
+
} | {
|
|
54
|
+
readonly type: "degrade";
|
|
55
|
+
readonly key: string;
|
|
56
|
+
};
|
|
57
|
+
export interface CalloutTransition {
|
|
58
|
+
readonly state: CalloutState;
|
|
59
|
+
readonly emit: boolean;
|
|
60
|
+
}
|
|
61
|
+
export interface BudgetBlock {
|
|
62
|
+
readonly reason: "session_cap" | "daily_cap";
|
|
63
|
+
readonly message: string;
|
|
64
|
+
}
|
|
65
|
+
export type SessionReadiness = {
|
|
66
|
+
readonly status: "invalid_backend";
|
|
67
|
+
readonly error: string;
|
|
68
|
+
} | {
|
|
69
|
+
readonly status: "disabled";
|
|
70
|
+
readonly route: ValidSessionRoute;
|
|
71
|
+
readonly auth: AuthState;
|
|
72
|
+
readonly authReport: AuthReport;
|
|
73
|
+
readonly budget?: BudgetBlock;
|
|
74
|
+
} | {
|
|
75
|
+
readonly status: "blocked_auth";
|
|
76
|
+
readonly route: ValidSessionRoute;
|
|
77
|
+
readonly auth: AuthState;
|
|
78
|
+
readonly authReport: AuthReport;
|
|
79
|
+
readonly budget?: BudgetBlock;
|
|
80
|
+
} | {
|
|
81
|
+
readonly status: "blocked_budget";
|
|
82
|
+
readonly route: ValidSessionRoute;
|
|
83
|
+
readonly auth: AuthState;
|
|
84
|
+
readonly authReport: AuthReport;
|
|
85
|
+
readonly budget: BudgetBlock;
|
|
86
|
+
} | {
|
|
87
|
+
readonly status: "ready";
|
|
88
|
+
readonly route: ValidSessionRoute;
|
|
89
|
+
readonly auth: AuthState;
|
|
90
|
+
readonly authReport: AuthReport;
|
|
91
|
+
};
|
|
92
|
+
export interface ReadinessInput {
|
|
93
|
+
readonly route: SessionRoute;
|
|
94
|
+
readonly consent: ConsentState;
|
|
95
|
+
readonly auth?: AuthState | undefined;
|
|
96
|
+
readonly spend?: SpendReport | undefined;
|
|
97
|
+
readonly maxRequests?: number | undefined;
|
|
98
|
+
}
|
|
99
|
+
/** Parse route once at load so an invalid PI_TYPESAFE_BACKEND carries no backend id and cannot fall back to api.typesafe.ai. */
|
|
100
|
+
export declare function resolveSessionRoute(env?: NodeJS.ProcessEnv): SessionRoute;
|
|
101
|
+
export declare function initialConsent(env?: NodeJS.ProcessEnv): ConsentState;
|
|
102
|
+
export declare function transitionConsent(state: ConsentState, event: ConsentEvent): ConsentState;
|
|
103
|
+
/** Deduplicate repeated callouts while degraded, and re-arm on session start or recovery so later degradations still surface. */
|
|
104
|
+
export declare function transitionCallout(state: CalloutState, event: CalloutEvent): CalloutTransition;
|
|
105
|
+
/** Client getSpend().blocked covers daily caps only, so surface the per-session attempt cap explicitly here too. */
|
|
106
|
+
export declare function budgetBlockFor(spend: SpendReport | undefined, maxRequests?: number): BudgetBlock | undefined;
|
|
107
|
+
export declare function deriveSessionReadiness(input: ReadinessInput): SessionReadiness;
|
|
2
108
|
/** Native Pi registration; importing the root library does not load this module. */
|
|
3
109
|
export default function typesafeExtension(pi: ExtensionAPI): void;
|