dal-code 0.1.1 → 0.1.6
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/PRIVACY.md +1 -1
- package/dist/core/agent-session.d.ts +5 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +7 -0
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-guidance.d.ts.map +1 -1
- package/dist/core/auth-guidance.js +5 -1
- package/dist/core/auth-guidance.js.map +1 -1
- package/dist/core/extensions/types.d.ts +15 -1
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/house-providers.d.ts +81 -0
- package/dist/core/house-providers.d.ts.map +1 -0
- package/dist/core/house-providers.js +128 -0
- package/dist/core/house-providers.js.map +1 -0
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +1 -3
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +11 -0
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +15 -2
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/trust-manager.d.ts.map +1 -1
- package/dist/core/trust-manager.js +7 -0
- package/dist/core/trust-manager.js.map +1 -1
- package/dist/dal/builtins.d.ts +15 -0
- package/dist/dal/builtins.d.ts.map +1 -1
- package/dist/dal/builtins.js +21 -0
- package/dist/dal/builtins.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +3 -1
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +3 -2
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +6 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +81 -42
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/session-share.d.ts.map +1 -1
- package/dist/modes/interactive/session-share.js +6 -5
- package/dist/modes/interactive/session-share.js.map +1 -1
- package/dist/node_modules/@dalcode/dal-bridge/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-gateway/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-gateway/src/index.ts +21 -12
- package/dist/node_modules/@dalcode/dal-guard/package.json +5 -5
- package/dist/node_modules/@dalcode/dal-halo/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-lang/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-lang/src/index.ts +19 -2
- package/dist/node_modules/@dalcode/dal-lsp/package.json +7 -4
- package/dist/node_modules/@dalcode/dal-lsp/src/client.ts +241 -0
- package/dist/node_modules/@dalcode/dal-lsp/src/config.ts +176 -0
- package/dist/node_modules/@dalcode/dal-lsp/src/format.ts +88 -0
- package/dist/node_modules/@dalcode/dal-lsp/src/index.ts +149 -42
- package/dist/node_modules/@dalcode/dal-lsp/src/types.ts +21 -0
- package/dist/node_modules/@dalcode/dal-mcp/package.json +5 -5
- package/dist/node_modules/@dalcode/dal-mcp/src/config.ts +25 -3
- package/dist/node_modules/@dalcode/dal-mcp/src/index.ts +6 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.d.ts +8 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.d.ts.map +1 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.js +77 -4
- package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.js.map +1 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/package.json +1 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/src/i18n.ts +81 -5
- package/dist/node_modules/@dalcode/dal-subagent/package.json +6 -6
- package/dist/node_modules/@dalcode/dal-telemetry/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-telemetry/src/config.ts +31 -8
- package/dist/node_modules/@dalcode/dal-telemetry/src/index.ts +12 -4
- package/dist/node_modules/@dalcode/dal-telemetry/src/reporter.ts +14 -1
- package/dist/node_modules/@dalcode/deepailab/package.json +4 -4
- package/dist/node_modules/@dalcode/deepailab/src/index.ts +111 -21
- package/dist/node_modules/@dalcode/deepailab/src/model-defaults.ts +109 -5
- package/dist/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js +18 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/env-api-keys.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/env-api-keys.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/env-api-keys.js +18 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/env-api-keys.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/index.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/index.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/index.js +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/index.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/baseten.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/huggingface.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode-go.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-client/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-protocol/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +13 -3
- package/package.json +3 -2
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
import { randomUUID } from "node:crypto";
|
|
19
19
|
import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
20
20
|
import { join } from "node:path";
|
|
21
|
+
import { DEFAULT_ENDPOINT } from "./reporter.ts";
|
|
21
22
|
|
|
22
23
|
export interface TelemetryState {
|
|
23
24
|
enabled: boolean;
|
|
@@ -34,7 +35,13 @@ export interface TelemetryDecision {
|
|
|
34
35
|
/** Show the one-time notice before anything is sent. */
|
|
35
36
|
shouldNotify: boolean;
|
|
36
37
|
/** Why it is off, for `/telemetry` to explain rather than just say "off". */
|
|
37
|
-
reason?: "opted-out" | "do-not-track" | "env" | "ci" | "unreadable";
|
|
38
|
+
reason?: "opted-out" | "do-not-track" | "env" | "ci" | "unreadable" | "unconfigured";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The configured collector URL, or undefined when there is none. */
|
|
42
|
+
export function resolveEndpoint(env: NodeJS.ProcessEnv = process.env): string | undefined {
|
|
43
|
+
const raw = env.DAL_TELEMETRY_ENDPOINT ?? DEFAULT_ENDPOINT;
|
|
44
|
+
return raw.length > 0 ? raw : undefined;
|
|
38
45
|
}
|
|
39
46
|
|
|
40
47
|
function isCi(env: NodeJS.ProcessEnv): boolean {
|
|
@@ -92,20 +99,36 @@ export function resolveTelemetry(agentDir: string, env: NodeJS.ProcessEnv = proc
|
|
|
92
99
|
}
|
|
93
100
|
if (isCi(env)) return { state, active: false, shouldNotify: false, reason: "ci" };
|
|
94
101
|
|
|
95
|
-
//
|
|
96
|
-
//
|
|
97
|
-
//
|
|
98
|
-
if (!
|
|
99
|
-
|
|
100
|
-
|
|
102
|
+
// No collector, no collection — and no notice claiming otherwise. Checked
|
|
103
|
+
// after the opt-outs so `/telemetry` still reports the user's own choice in
|
|
104
|
+
// preference to an infrastructure gap.
|
|
105
|
+
if (!resolveEndpoint(env)) return { state, active: false, shouldNotify: false, reason: "unconfigured" };
|
|
106
|
+
|
|
107
|
+
// First run: persist the identity only. `notifiedAt` is written by
|
|
108
|
+
// markNotified(), after the notice has actually been rendered — stamping it
|
|
109
|
+
// here meant a headless first run (`dal -p`, where there is no UI to show it)
|
|
110
|
+
// recorded the user as told while nothing was ever displayed, and every later
|
|
111
|
+
// run then skipped the notice.
|
|
112
|
+
if (!existing) {
|
|
113
|
+
if (!writeState(agentDir, state)) {
|
|
101
114
|
return { state, active: false, shouldNotify: false, reason: "unreadable" };
|
|
102
115
|
}
|
|
103
|
-
return { state: seeded, active: true, shouldNotify: true };
|
|
104
116
|
}
|
|
117
|
+
if (!state.notifiedAt) return { state, active: true, shouldNotify: true };
|
|
105
118
|
|
|
106
119
|
return { state, active: true, shouldNotify: false };
|
|
107
120
|
}
|
|
108
121
|
|
|
122
|
+
/**
|
|
123
|
+
* Records that the one-time notice was shown. Called by the caller that renders
|
|
124
|
+
* it, never by resolveTelemetry — see the comment there.
|
|
125
|
+
*/
|
|
126
|
+
export function markNotified(agentDir: string, state: TelemetryState): TelemetryState {
|
|
127
|
+
const next: TelemetryState = { ...state, notifiedAt: new Date().toISOString() };
|
|
128
|
+
writeState(agentDir, next);
|
|
129
|
+
return next;
|
|
130
|
+
}
|
|
131
|
+
|
|
109
132
|
export function setTelemetryEnabled(agentDir: string, enabled: boolean): TelemetryState {
|
|
110
133
|
const current = readState(telemetryPath(agentDir)) ?? { enabled, anonymousId: randomUUID() };
|
|
111
134
|
const next: TelemetryState = { ...current, enabled, notifiedAt: current.notifiedAt ?? new Date().toISOString() };
|
|
@@ -36,9 +36,9 @@ interface ModelSelectEventShape {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
import { getAgentDir, VERSION } from "@earendil-works/pi-coding-agent";
|
|
39
|
-
import { resolveTelemetry, setTelemetryEnabled } from "./config.ts";
|
|
39
|
+
import { markNotified, resolveEndpoint, resolveTelemetry, setTelemetryEnabled } from "./config.ts";
|
|
40
40
|
import { redactMessage, redactStack, redactToolName } from "./redact.ts";
|
|
41
|
-
import {
|
|
41
|
+
import { TelemetryReporter } from "./reporter.ts";
|
|
42
42
|
|
|
43
43
|
export default function (pi: ExtensionAPI) {
|
|
44
44
|
const agentDir = getAgentDir();
|
|
@@ -70,7 +70,9 @@ export default function (pi: ExtensionAPI) {
|
|
|
70
70
|
if (!decision.active) return;
|
|
71
71
|
|
|
72
72
|
const reporter = new TelemetryReporter({
|
|
73
|
-
|
|
73
|
+
// Non-null: resolveTelemetry returns active:false when there is no
|
|
74
|
+
// endpoint, and we returned above on that.
|
|
75
|
+
endpoint: resolveEndpoint() as string,
|
|
74
76
|
anonymousId: decision.state.anonymousId,
|
|
75
77
|
appVersion: VERSION,
|
|
76
78
|
});
|
|
@@ -79,11 +81,17 @@ export default function (pi: ExtensionAPI) {
|
|
|
79
81
|
let turns = 0;
|
|
80
82
|
|
|
81
83
|
pi.on("session_start", async (event: SessionStartEvent, ctx: ExtensionContext) => {
|
|
82
|
-
if (decision.shouldNotify
|
|
84
|
+
if (decision.shouldNotify) {
|
|
85
|
+
// Nothing is reported until the notice has been seen. A headless run
|
|
86
|
+
// has nowhere to show it, so it stays pending for the next TUI launch
|
|
87
|
+
// rather than being reported behind the user's back.
|
|
88
|
+
if (!ctx.hasUI) return;
|
|
83
89
|
ctx.ui.notify(
|
|
84
90
|
t("DAL 会发送匿名使用统计(不含代码、提示词和文件路径)以改进产品。/telemetry off 可关闭。"),
|
|
85
91
|
"info",
|
|
86
92
|
);
|
|
93
|
+
markNotified(agentDir, decision.state);
|
|
94
|
+
decision.shouldNotify = false;
|
|
87
95
|
}
|
|
88
96
|
reporter.record({ name: "session_start", props: { reason: event.reason } });
|
|
89
97
|
});
|
|
@@ -36,7 +36,20 @@ const MAX_QUEUE = 200;
|
|
|
36
36
|
const UPLOAD_TIMEOUT_MS = 3000;
|
|
37
37
|
const SHUTDOWN_TIMEOUT_MS = 1500;
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Empty until the collector exists.
|
|
41
|
+
*
|
|
42
|
+
* This pointed at `https://telemetry.deepailab.ai/v1/events`, which has never
|
|
43
|
+
* resolved — NXDOMAIN from an unproxied resolver, verified 2026-09-11. Every
|
|
44
|
+
* upload failed and the reporter swallowed it, so the product carried the cost
|
|
45
|
+
* of a consent notice and a PRIVACY.md section while receiving nothing.
|
|
46
|
+
*
|
|
47
|
+
* An unset endpoint now switches telemetry off outright (see config.ts), which
|
|
48
|
+
* is the truthful state: nothing is collected, and nobody is told otherwise.
|
|
49
|
+
* Publishing the DNS record and setting this constant — or DAL_TELEMETRY_ENDPOINT
|
|
50
|
+
* — turns it back on, notice and all.
|
|
51
|
+
*/
|
|
52
|
+
export const DEFAULT_ENDPOINT = "";
|
|
40
53
|
|
|
41
54
|
export class TelemetryReporter {
|
|
42
55
|
private queue: Array<TelemetryEvent & { ts: number }> = [];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dalcode/deepailab",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -19,11 +19,11 @@
|
|
|
19
19
|
]
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@dalcode/dal-pi-kit": "0.1.
|
|
23
|
-
"@earendil-works/pi-ai": "^0.1.
|
|
22
|
+
"@dalcode/dal-pi-kit": "0.1.6",
|
|
23
|
+
"@earendil-works/pi-ai": "^0.1.2"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@earendil-works/pi-coding-agent": "^0.1.
|
|
26
|
+
"@earendil-works/pi-coding-agent": "^0.1.2"
|
|
27
27
|
},
|
|
28
28
|
"peerDependenciesMeta": {
|
|
29
29
|
"@earendil-works/pi-coding-agent": {
|
|
@@ -40,11 +40,17 @@ function toCredentials(tokens: TokenSet, vk: string): OAuthCredentials {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
|
-
* The gateway (Bifrost) authenticates inference with a long-lived virtual key
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
43
|
+
* The gateway (Bifrost) authenticates inference with a long-lived virtual key,
|
|
44
|
+
* not the OIDC bearer. The Bridge mints one from a fresh OIDC access_token; the
|
|
45
|
+
* secret is returned exactly once, so it is stored inside the OAuth credentials
|
|
46
|
+
* and reused until logout.
|
|
47
|
+
*
|
|
48
|
+
* The key travels in `Authorization: Bearer`. An earlier note here said the
|
|
49
|
+
* gateway ignored that header and only honoured `x-bf-vk` (checked 2026-07-04);
|
|
50
|
+
* re-checked live 2026-09-11, both are accepted and return identical
|
|
51
|
+
* completions. Bearer is the one to use — it is what every OpenAI-compatible
|
|
52
|
+
* client sends, so a custom header would lock those clients out of the gateway
|
|
53
|
+
* for no gain.
|
|
48
54
|
*/
|
|
49
55
|
async function createVirtualKey(apiBase: string, accessToken: string): Promise<string> {
|
|
50
56
|
const res = await fetch(`${apiBase}/portal/keys/lifecycle`, {
|
|
@@ -139,11 +145,18 @@ export async function refreshDeepAILab(credentials: OAuthCredentials): Promise<O
|
|
|
139
145
|
return toCredentials(tokens, vk);
|
|
140
146
|
}
|
|
141
147
|
|
|
142
|
-
//
|
|
143
|
-
//
|
|
144
|
-
//
|
|
145
|
-
//
|
|
146
|
-
|
|
148
|
+
// No seed catalog. The gateway's list is the only truth about what can be
|
|
149
|
+
// used, and it needs a credential, so a logged-out user has no models — which
|
|
150
|
+
// is accurate, since they cannot call one either. The UI already says
|
|
151
|
+
// "Use /login to add providers".
|
|
152
|
+
//
|
|
153
|
+
// A hardcoded placeholder was worse than nothing. It went stale twice in one
|
|
154
|
+
// day: it named "glm-5.2" after the gateway namespaced its ids to
|
|
155
|
+
// "aook/glm-5.2", and then named "aook/glm-5.2" after the gateway's published
|
|
156
|
+
// list became deepseek-flash / deepseek-v4-pro / gpt-5.6-sol. Each time it
|
|
157
|
+
// showed a model that could not be selected, and each time the model a user
|
|
158
|
+
// picked before logging in vanished from the list right after.
|
|
159
|
+
const SEED_MODELS: ReturnType<typeof gatewayModelDefaults>[] = [];
|
|
147
160
|
|
|
148
161
|
export default function (pi: ExtensionAPI) {
|
|
149
162
|
const cfg = defaultConfig();
|
|
@@ -171,27 +184,82 @@ export default function (pi: ExtensionAPI) {
|
|
|
171
184
|
});
|
|
172
185
|
|
|
173
186
|
// Refresh the model catalog from the gateway once credentials are available.
|
|
174
|
-
//
|
|
175
|
-
|
|
187
|
+
// Not best-effort any more: with no seed list, a failure here means zero
|
|
188
|
+
// models, so it is reported rather than swallowed.
|
|
189
|
+
//
|
|
190
|
+
// Runs on two events, and needs both. At session_start a returning user is
|
|
191
|
+
// already logged in and gets the full list immediately; a new user is not, so
|
|
192
|
+
// the fetch is skipped and they would sit on the seed model until they
|
|
193
|
+
// restarted. provider_authenticated closes that gap — it fires the moment
|
|
194
|
+
// /login completes, before the model picker opens.
|
|
195
|
+
const refreshCatalog = async (ctx: {
|
|
196
|
+
modelRegistry: { getApiKeyForProvider(id: string): Promise<string | undefined> };
|
|
197
|
+
ui?: { notify(message: string, level: "info" | "warning" | "error"): void };
|
|
198
|
+
}) => {
|
|
199
|
+
// The catalog is the only source of models now that the seed list is gone,
|
|
200
|
+
// so a failure has to be visible. `ui` is optional because refreshCatalog
|
|
201
|
+
// also runs in headless (`dal -p`) sessions, where stderr is the channel.
|
|
202
|
+
const reportFailure = (reason: string): void => {
|
|
203
|
+
const message = `${t("无法获取模型列表")}:${reason}`;
|
|
204
|
+
if (ctx.ui) ctx.ui.notify(message, "error");
|
|
205
|
+
else process.stderr.write(`${message}\n`);
|
|
206
|
+
};
|
|
207
|
+
// Hoisted so the finally below can clear it: declared inside the try, an
|
|
208
|
+
// error thrown by fetch or res.json() left the 20s timer running and
|
|
209
|
+
// delayed `dal -p` exiting.
|
|
210
|
+
//
|
|
211
|
+
// The gateway answers /models in a steady ~5.6s (measured 2026-09-11:
|
|
212
|
+
// 5.64 / 5.58 / 5.66). The previous 5s deadline therefore aborted every
|
|
213
|
+
// single refresh, and the catch below swallowed it — a signed-in user saw
|
|
214
|
+
// nothing on screen to say why. The budget is now well clear of that, and
|
|
215
|
+
// still bounded so an unreachable gateway cannot hang the session.
|
|
216
|
+
const controller = new AbortController();
|
|
217
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
176
218
|
try {
|
|
177
219
|
const token = await ctx.modelRegistry.getApiKeyForProvider("deepailab");
|
|
178
220
|
if (!token) return;
|
|
179
|
-
|
|
180
|
-
const timer = setTimeout(() => controller.abort(), 5000);
|
|
221
|
+
timer = setTimeout(() => controller.abort(), 20_000);
|
|
181
222
|
const res = await fetch(`${cfg.apiBase}/models`, {
|
|
182
223
|
headers: { "x-bf-vk": token, Accept: "application/json" },
|
|
183
224
|
signal: controller.signal,
|
|
184
225
|
});
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
226
|
+
if (!res.ok) {
|
|
227
|
+
// 401/402/429 used to be swallowed here together with the network
|
|
228
|
+
// errors below. With the seed catalog gone a rejected refresh means
|
|
229
|
+
// zero models, so it has to reach the screen.
|
|
230
|
+
reportFailure(`${t("网关拒绝了请求")} (HTTP ${res.status})`);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const body = (await res.json()) as {
|
|
234
|
+
data?: Array<{
|
|
235
|
+
id?: string;
|
|
236
|
+
name?: string;
|
|
237
|
+
display_name?: string;
|
|
238
|
+
context_window?: number;
|
|
239
|
+
max_output_tokens?: number;
|
|
240
|
+
capabilities?: string[];
|
|
241
|
+
reasoning_efforts?: string[];
|
|
242
|
+
pricing?: { input_per_1m?: number; output_per_1m?: number; currency?: string };
|
|
243
|
+
}>;
|
|
244
|
+
};
|
|
188
245
|
// Known ids keep their verified seed config; new catalog entries get
|
|
189
246
|
// per-family defaults (builtin metadata + gateway compat dialect)
|
|
190
247
|
// instead of blind conservative placeholders.
|
|
191
|
-
|
|
248
|
+
// The gateway publishes context window, output cap and capabilities from
|
|
249
|
+
// its sales catalog. Passing them through is what stops the CLI from
|
|
250
|
+
// inferring them off the model name, which had deepseek-flash at 128K
|
|
251
|
+
// against an actual 1M window.
|
|
192
252
|
const models = (body.data ?? [])
|
|
193
253
|
.filter((m) => typeof m.id === "string" && m.id.length > 0)
|
|
194
|
-
.map((m) =>
|
|
254
|
+
.map((m) =>
|
|
255
|
+
gatewayModelDefaults(m.id as string, m.display_name ?? m.name, {
|
|
256
|
+
contextWindow: m.context_window,
|
|
257
|
+
maxTokens: m.max_output_tokens,
|
|
258
|
+
capabilities: m.capabilities,
|
|
259
|
+
reasoningEfforts: m.reasoning_efforts,
|
|
260
|
+
pricing: m.pricing,
|
|
261
|
+
}),
|
|
262
|
+
);
|
|
195
263
|
if (models.length > 0) {
|
|
196
264
|
// Must be the full config: registerProvider validates the incoming
|
|
197
265
|
// object standalone (models require baseUrl + auth to be present).
|
|
@@ -203,9 +271,31 @@ export default function (pi: ExtensionAPI) {
|
|
|
203
271
|
models,
|
|
204
272
|
});
|
|
205
273
|
}
|
|
206
|
-
} catch {
|
|
207
|
-
//
|
|
274
|
+
} catch (error) {
|
|
275
|
+
// There is no seed catalog any more, so this is not a soft degradation:
|
|
276
|
+
// the model picker ends up empty. Name the reason instead.
|
|
277
|
+
const aborted = error instanceof Error && error.name === "AbortError";
|
|
278
|
+
reportFailure(aborted ? t("请求超时") : t("无法连接 DeepAILab 网关"));
|
|
279
|
+
} finally {
|
|
280
|
+
if (timer !== undefined) clearTimeout(timer);
|
|
208
281
|
}
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
// Awaited, deliberately. This used to run in the background because the
|
|
285
|
+
// gateway took ~5.6s to answer, which would have been added to every launch.
|
|
286
|
+
// It now answers in well under a second, and with no seed catalog there is
|
|
287
|
+
// nothing to fall back to: a backgrounded refresh means `dal -p` reaches the
|
|
288
|
+
// model lookup before any model exists and reports "no API key found" to a
|
|
289
|
+
// user who is perfectly well logged in.
|
|
290
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
291
|
+
await refreshCatalog(ctx);
|
|
292
|
+
});
|
|
293
|
+
// After /login it is awaited on purpose. The user has just authenticated and
|
|
294
|
+
// is about to open the model picker; showing them the seed list there is the
|
|
295
|
+
// exact failure this is meant to prevent.
|
|
296
|
+
pi.on("provider_authenticated", async (event, ctx) => {
|
|
297
|
+
if (event.providerId !== "deepailab") return;
|
|
298
|
+
await refreshCatalog(ctx);
|
|
209
299
|
});
|
|
210
300
|
|
|
211
301
|
pi.registerCommand("account", {
|
|
@@ -32,8 +32,48 @@ const GATEWAY_REASONING_COMPAT = {
|
|
|
32
32
|
supportsReasoningEffort: true,
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Applies to every gateway model, reasoning or not.
|
|
37
|
+
*
|
|
38
|
+
* `supportsDeveloperRole` defaults to auto-detection from the base URL, and
|
|
39
|
+
* api.deepailab.ai is not a URL the detector knows, so it assumed the modern
|
|
40
|
+
* `developer` role. The upstreams behind the gateway do not accept it:
|
|
41
|
+
*
|
|
42
|
+
* 400 messages[0].role: unknown variant `developer`,
|
|
43
|
+
* expected one of `system`, `user`, `assistant`, `tool`
|
|
44
|
+
*
|
|
45
|
+
* Every request failed on the first message. Verified live 2026-09-11.
|
|
46
|
+
*/
|
|
47
|
+
const GATEWAY_ROLE_COMPAT = { supportsDeveloperRole: false };
|
|
48
|
+
|
|
35
49
|
const ZERO_COST = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };
|
|
36
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Turns the gateway's published rates into pi's `cost`, which is denominated in
|
|
53
|
+
* dollars per million tokens — the same unit the gateway uses, so the numbers
|
|
54
|
+
* carry across unchanged.
|
|
55
|
+
*
|
|
56
|
+
* Every model used to get ZERO_COST, which meant `/usage` never showed a figure
|
|
57
|
+
* and the compaction hint never showed `(~$X)`: a metered product with no cost
|
|
58
|
+
* visibility in its own terminal.
|
|
59
|
+
*
|
|
60
|
+
* Cache rates are left at zero rather than guessed. The gateway publishes two
|
|
61
|
+
* numbers, and inventing a cache multiplier here would be the same mistake as
|
|
62
|
+
* inferring the context window from the model name.
|
|
63
|
+
*
|
|
64
|
+
* A non-USD catalog is declined rather than converted. `ModelCostRates` has no
|
|
65
|
+
* currency field, so a CNY figure would be rendered with a dollar sign and be
|
|
66
|
+
* wrong by roughly sevenfold — worse than showing nothing.
|
|
67
|
+
*/
|
|
68
|
+
function costFromGateway(pricing: GatewayModelMeta["pricing"]): typeof ZERO_COST | undefined {
|
|
69
|
+
if (!pricing) return undefined;
|
|
70
|
+
const { input_per_1m: input, output_per_1m: output, currency } = pricing;
|
|
71
|
+
if (typeof input !== "number" || typeof output !== "number") return undefined;
|
|
72
|
+
if (!Number.isFinite(input) || !Number.isFinite(output) || input < 0 || output < 0) return undefined;
|
|
73
|
+
if (currency !== undefined && currency.toUpperCase() !== "USD") return undefined;
|
|
74
|
+
return { input, output, cacheRead: 0, cacheWrite: 0 };
|
|
75
|
+
}
|
|
76
|
+
|
|
37
77
|
/**
|
|
38
78
|
* The gateway's WAF rejects the OpenAI SDK's own User-Agent ("OpenAI/JS …")
|
|
39
79
|
* with a bare `403 Your request was blocked.` — no error body, no hint that
|
|
@@ -100,8 +140,12 @@ function familyDefaults(id: string): FamilyDefaults {
|
|
|
100
140
|
function gatewayCompat(id: string, reasoning: boolean): Model<Api>["compat"] | undefined {
|
|
101
141
|
const lower = id.toLowerCase();
|
|
102
142
|
const deepseek = lower.includes("deepseek");
|
|
103
|
-
|
|
143
|
+
// No early return: every model behind this gateway needs the role setting,
|
|
144
|
+
// reasoning or not. Returning undefined here would leave non-reasoning models
|
|
145
|
+
// on the auto-detected `developer` role, which the upstreams reject outright.
|
|
146
|
+
void 0;
|
|
104
147
|
return {
|
|
148
|
+
...GATEWAY_ROLE_COMPAT,
|
|
105
149
|
...(reasoning ? GATEWAY_REASONING_COMPAT : {}),
|
|
106
150
|
...(deepseek ? { supportsStore: false, requiresReasoningContentOnAssistantMessages: true } : {}),
|
|
107
151
|
};
|
|
@@ -111,9 +155,62 @@ function gatewayCompat(id: string, reasoning: boolean): Model<Api>["compat"] | u
|
|
|
111
155
|
* Full model config for a gateway catalog id. Costs are always 0: billing is
|
|
112
156
|
* metered server-side by the gateway (Lago), never computed client-side.
|
|
113
157
|
*/
|
|
114
|
-
|
|
158
|
+
/**
|
|
159
|
+
* What the gateway says about a model, when it says anything. The gateway
|
|
160
|
+
* publishes this from its sales catalog, so it is the only source that is
|
|
161
|
+
* right by construction — guessing from the id got deepseek-flash wrong by a
|
|
162
|
+
* factor of eight (128K inferred, 1M actual), and an eightfold-low context
|
|
163
|
+
* window makes compaction fire eight times too early.
|
|
164
|
+
*/
|
|
165
|
+
export interface GatewayModelMeta {
|
|
166
|
+
contextWindow?: number;
|
|
167
|
+
maxTokens?: number;
|
|
168
|
+
capabilities?: readonly string[];
|
|
169
|
+
/**
|
|
170
|
+
* Boundary reasoning_effort values the gateway measured as accepted.
|
|
171
|
+
* model-probe calls each one for real, so this is evidence rather than
|
|
172
|
+
* inference — and inference was wrong in both directions here: the builtin
|
|
173
|
+
* catalog offered "max" for gpt-5.6-sol, which the gateway answers 400, and
|
|
174
|
+
* hid "xhigh"/"max" for deepseek-flash, which accepts both.
|
|
175
|
+
*/
|
|
176
|
+
reasoningEfforts?: readonly string[];
|
|
177
|
+
/** Per-million-token rates from the gateway's sales catalog. */
|
|
178
|
+
pricing?: { input_per_1m?: number; output_per_1m?: number; currency?: string };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* minimal..high are accepted by every gateway model measured, so only the
|
|
183
|
+
* boundary levels are probed. A level the gateway did not report as accepted is
|
|
184
|
+
* mapped to null, which is how pi's model layer marks a level as unavailable.
|
|
185
|
+
*/
|
|
186
|
+
function thinkingMapFromGateway(efforts: readonly string[] | undefined) {
|
|
187
|
+
if (!efforts) return undefined;
|
|
188
|
+
const accepted = new Set(efforts.map((e) => e.toLowerCase()));
|
|
189
|
+
return {
|
|
190
|
+
xhigh: accepted.has("xhigh") ? "xhigh" : null,
|
|
191
|
+
max: accepted.has("max") ? "max" : null,
|
|
192
|
+
} as Record<string, string | null>;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function metaFromGateway(gateway: GatewayModelMeta | undefined): Partial<FamilyDefaults> {
|
|
196
|
+
if (!gateway) return {};
|
|
197
|
+
const caps = gateway.capabilities;
|
|
198
|
+
return {
|
|
199
|
+
...(typeof gateway.contextWindow === "number" && gateway.contextWindow > 0
|
|
200
|
+
? { contextWindow: gateway.contextWindow }
|
|
201
|
+
: {}),
|
|
202
|
+
...(typeof gateway.maxTokens === "number" && gateway.maxTokens > 0 ? { maxTokens: gateway.maxTokens } : {}),
|
|
203
|
+
// Only ever turns reasoning on. The catalog lists what a model can do, so
|
|
204
|
+
// a missing "Reasoning" is silence rather than a denial, and the family
|
|
205
|
+
// heuristics below know about models the catalog predates.
|
|
206
|
+
...(caps?.some((c) => c.toLowerCase() === "reasoning") ? { reasoning: true } : {}),
|
|
207
|
+
...(caps?.some((c) => c.toLowerCase() === "vision") ? { input: ["text", "image"] as ("text" | "image")[] } : {}),
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export function gatewayModelDefaults(id: string, name?: string, gateway?: GatewayModelMeta): ProviderModelConfig {
|
|
115
212
|
const builtin = lookupBuiltin(id);
|
|
116
|
-
const
|
|
213
|
+
const base: FamilyDefaults = builtin
|
|
117
214
|
? {
|
|
118
215
|
reasoning: builtin.reasoning,
|
|
119
216
|
input: [...builtin.input],
|
|
@@ -121,14 +218,21 @@ export function gatewayModelDefaults(id: string, name?: string): ProviderModelCo
|
|
|
121
218
|
maxTokens: builtin.maxTokens,
|
|
122
219
|
}
|
|
123
220
|
: familyDefaults(id);
|
|
221
|
+
// Gateway first: it knows the deployment, the other two are inference.
|
|
222
|
+
const meta: FamilyDefaults = { ...base, ...metaFromGateway(gateway) };
|
|
124
223
|
return {
|
|
125
224
|
id,
|
|
126
225
|
name: name || builtin?.name || id,
|
|
127
226
|
reasoning: meta.reasoning,
|
|
128
|
-
|
|
227
|
+
// Measured levels win over the builtin catalog's guess for this id.
|
|
228
|
+
...(thinkingMapFromGateway(gateway?.reasoningEfforts)
|
|
229
|
+
? { thinkingLevelMap: thinkingMapFromGateway(gateway?.reasoningEfforts) }
|
|
230
|
+
: builtin?.thinkingLevelMap
|
|
231
|
+
? { thinkingLevelMap: builtin.thinkingLevelMap }
|
|
232
|
+
: {}),
|
|
129
233
|
input: meta.input,
|
|
130
234
|
headers: { ...GATEWAY_HEADERS },
|
|
131
|
-
cost: { ...ZERO_COST },
|
|
235
|
+
cost: costFromGateway(gateway?.pricing) ?? { ...ZERO_COST },
|
|
132
236
|
contextWindow: meta.contextWindow,
|
|
133
237
|
maxTokens: meta.maxTokens,
|
|
134
238
|
...(gatewayCompat(id, meta.reasoning) ? { compat: gatewayCompat(id, meta.reasoning) } : {}),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@earendil-works/pi-agent-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "General-purpose agent with transport abstraction, state management, and attachment support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"README.md"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@earendil-works/pi-ai": "^0.1.
|
|
45
|
-
"@earendil-works/pi-telemetry": "^0.1.
|
|
44
|
+
"@earendil-works/pi-ai": "^0.1.2",
|
|
45
|
+
"@earendil-works/pi-telemetry": "^0.1.2",
|
|
46
46
|
"diff": "8.0.4",
|
|
47
47
|
"ignore": "7.0.5",
|
|
48
48
|
"typebox": "1.3.7",
|