pi2dsh 0.8.0 → 0.10.0
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/README.md +8 -2
- package/README.zh.md +7 -2
- package/dist/{analyzer-CKTsWVzn.mjs → analyzer-CsrBeS8r.mjs} +3 -5
- package/dist/{analyzer-CKTsWVzn.mjs.map → analyzer-CsrBeS8r.mjs.map} +1 -1
- package/dist/cli.mjs +3 -3
- package/dist/cli.mjs.map +1 -1
- package/dist/compat/pi-ai.d.mts +2 -1
- package/dist/compat/pi-ai.d.mts.map +1 -1
- package/dist/compat/pi-ai.mjs +2 -3
- package/dist/compat/pi-coding-agent.d.mts +259 -29
- package/dist/compat/pi-coding-agent.d.mts.map +1 -1
- package/dist/compat/pi-coding-agent.mjs +2 -2
- package/dist/credentials-oauth.mjs +2 -2
- package/dist/{generator-eyViezvs.mjs → generator-CSOv6wYT.mjs} +3 -5
- package/dist/{generator-eyViezvs.mjs.map → generator-CSOv6wYT.mjs.map} +1 -1
- package/dist/host.d.mts +2 -2
- package/dist/host.d.mts.map +1 -1
- package/dist/host.mjs +1 -1
- package/dist/host.mjs.map +1 -1
- package/dist/index.d.mts +6 -5
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +4 -4
- package/dist/index.mjs.map +1 -1
- package/dist/{mcp-config-Dlou-ZA-.mjs → mcp-config-Cn5gWemZ.mjs} +29 -29
- package/dist/mcp-config-Cn5gWemZ.mjs.map +1 -0
- package/dist/{pi-ai-C6Xag6xt.mjs → pi-ai-Dyg4zyLZ.mjs} +196 -85
- package/dist/pi-ai-Dyg4zyLZ.mjs.map +1 -0
- package/dist/{pi-coding-agent-CznNsOnV.mjs → pi-coding-agent-Ctw-BhoY.mjs} +0 -0
- package/dist/pi-coding-agent-Ctw-BhoY.mjs.map +1 -0
- package/dist/{runtime-B-Mun-jX.mjs → runtime-Ce3PTbWU.mjs} +511 -171
- package/dist/runtime-Ce3PTbWU.mjs.map +1 -0
- package/dist/runtime.d.mts +18 -10
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +1 -1
- package/package.json +5 -3
- package/dist/mcp-config-Dlou-ZA-.mjs.map +0 -1
- package/dist/pi-ai-C6Xag6xt.mjs.map +0 -1
- package/dist/pi-coding-agent-CznNsOnV.mjs.map +0 -1
- package/dist/pi-uuid-Db8ShZsK.mjs +0 -47
- package/dist/pi-uuid-Db8ShZsK.mjs.map +0 -1
- package/dist/runtime-B-Mun-jX.mjs.map +0 -1
|
@@ -2,18 +2,199 @@
|
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { Type as Type$1 } from "typebox";
|
|
4
4
|
//#region \0rolldown/runtime.js
|
|
5
|
-
var __defProp = Object.defineProperty;
|
|
6
|
-
var __exportAll = (all, no_symbols) => {
|
|
7
|
-
let target = {};
|
|
8
|
-
for (var name in all) __defProp(target, name, {
|
|
9
|
-
get: all[name],
|
|
10
|
-
enumerable: true
|
|
11
|
-
});
|
|
12
|
-
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
13
|
-
return target;
|
|
14
|
-
};
|
|
15
5
|
var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
|
|
16
6
|
//#endregion
|
|
7
|
+
//#region src/compat/vendor/pi-uuid.ts
|
|
8
|
+
let lastTimestamp = -Infinity;
|
|
9
|
+
let sequence = 0;
|
|
10
|
+
function fillRandomBytes(bytes) {
|
|
11
|
+
if (globalThis.crypto?.getRandomValues) {
|
|
12
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
for (let i = 0; i < bytes.length; i++) bytes[i] = Math.floor(Math.random() * 256);
|
|
16
|
+
}
|
|
17
|
+
/** Generate a time-ordered UUIDv7. */
|
|
18
|
+
function uuidv7() {
|
|
19
|
+
const random = /* @__PURE__ */ new Uint8Array(16);
|
|
20
|
+
fillRandomBytes(random);
|
|
21
|
+
const timestamp = Date.now();
|
|
22
|
+
if (timestamp > lastTimestamp) {
|
|
23
|
+
sequence = random[6] * 16777216 + random[7] * 65536 + random[8] * 256 + random[9];
|
|
24
|
+
lastTimestamp = timestamp;
|
|
25
|
+
} else {
|
|
26
|
+
sequence = sequence + 1 >>> 0;
|
|
27
|
+
if (sequence === 0) lastTimestamp++;
|
|
28
|
+
}
|
|
29
|
+
const bytes = /* @__PURE__ */ new Uint8Array(16);
|
|
30
|
+
bytes[0] = lastTimestamp / 1099511627776 & 255;
|
|
31
|
+
bytes[1] = lastTimestamp / 4294967296 & 255;
|
|
32
|
+
bytes[2] = lastTimestamp / 16777216 & 255;
|
|
33
|
+
bytes[3] = lastTimestamp / 65536 & 255;
|
|
34
|
+
bytes[4] = lastTimestamp / 256 & 255;
|
|
35
|
+
bytes[5] = lastTimestamp & 255;
|
|
36
|
+
bytes[6] = 112 | sequence >>> 28 & 15;
|
|
37
|
+
bytes[7] = sequence >>> 20 & 255;
|
|
38
|
+
bytes[8] = 128 | sequence >>> 14 & 63;
|
|
39
|
+
bytes[9] = sequence >>> 6 & 255;
|
|
40
|
+
bytes[10] = (sequence & 63) << 2 | random[10] & 3;
|
|
41
|
+
bytes[11] = random[11];
|
|
42
|
+
bytes[12] = random[12];
|
|
43
|
+
bytes[13] = random[13];
|
|
44
|
+
bytes[14] = random[14];
|
|
45
|
+
bytes[15] = random[15];
|
|
46
|
+
const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0"));
|
|
47
|
+
return `${hex.slice(0, 4).join("")}-${hex.slice(4, 6).join("")}-${hex.slice(6, 8).join("")}-${hex.slice(8, 10).join("")}-${hex.slice(10, 16).join("")}`;
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/compat/vendor/pi-ai-retry.ts
|
|
51
|
+
function buildProviderErrorPattern(patterns) {
|
|
52
|
+
return new RegExp(patterns.join("|"), "i");
|
|
53
|
+
}
|
|
54
|
+
const NON_RETRYABLE_PROVIDER_LIMIT_ERROR_PATTERN = buildProviderErrorPattern([
|
|
55
|
+
"GoUsageLimitError",
|
|
56
|
+
"FreeUsageLimitError",
|
|
57
|
+
"Monthly usage limit reached",
|
|
58
|
+
"available balance",
|
|
59
|
+
"insufficient_quota",
|
|
60
|
+
"out of budget",
|
|
61
|
+
"quota exceeded",
|
|
62
|
+
"billing"
|
|
63
|
+
]);
|
|
64
|
+
const RETRYABLE_PROVIDER_ERROR_PATTERN = buildProviderErrorPattern([
|
|
65
|
+
"overloaded",
|
|
66
|
+
"rate.?limit",
|
|
67
|
+
"too many requests",
|
|
68
|
+
"429",
|
|
69
|
+
"500",
|
|
70
|
+
"502",
|
|
71
|
+
"503",
|
|
72
|
+
"504",
|
|
73
|
+
"524",
|
|
74
|
+
"service.?unavailable",
|
|
75
|
+
"server.?error",
|
|
76
|
+
"internal.?error",
|
|
77
|
+
"provider.?returned.?error",
|
|
78
|
+
"exceeded request buffer limit while retrying upstream",
|
|
79
|
+
"network.?error",
|
|
80
|
+
"connection.?error",
|
|
81
|
+
"connection.?refused",
|
|
82
|
+
"connection.?lost",
|
|
83
|
+
"other side closed",
|
|
84
|
+
"fetch failed",
|
|
85
|
+
"getaddrinfo",
|
|
86
|
+
"ENOTFOUND",
|
|
87
|
+
"EAI_AGAIN",
|
|
88
|
+
"upstream.?connect",
|
|
89
|
+
"reset before headers",
|
|
90
|
+
"socket hang up",
|
|
91
|
+
"socket connection was closed",
|
|
92
|
+
"timed? out",
|
|
93
|
+
"timeout",
|
|
94
|
+
"terminated",
|
|
95
|
+
"websocket.?closed",
|
|
96
|
+
"websocket.?error",
|
|
97
|
+
"ended without",
|
|
98
|
+
"stream ended before message_stop",
|
|
99
|
+
"stream ended before a terminal response event",
|
|
100
|
+
"http2 request did not get a response",
|
|
101
|
+
"retry delay",
|
|
102
|
+
"you can retry your request",
|
|
103
|
+
"try your request again",
|
|
104
|
+
"please retry your request",
|
|
105
|
+
"ResourceExhausted"
|
|
106
|
+
]);
|
|
107
|
+
var RetrySleepAbortError = class extends Error {
|
|
108
|
+
constructor() {
|
|
109
|
+
super("Aborted");
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
function sleep$1(ms, signal) {
|
|
113
|
+
return new Promise((resolve, reject) => {
|
|
114
|
+
if (signal?.aborted) {
|
|
115
|
+
reject(new RetrySleepAbortError());
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const timeout = setTimeout(resolve, ms);
|
|
119
|
+
signal?.addEventListener("abort", () => {
|
|
120
|
+
clearTimeout(timeout);
|
|
121
|
+
reject(new RetrySleepAbortError());
|
|
122
|
+
}, { once: true });
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Run a single assistant-producing call with bounded retry on transient errors.
|
|
127
|
+
*
|
|
128
|
+
* Behavior:
|
|
129
|
+
* - A successful response is returned immediately. Aborts are terminal and never
|
|
130
|
+
* retried, but reported as unsuccessful if they happen after a retry was scheduled.
|
|
131
|
+
* Aborts during the backoff sleep are normalized to an aborted `AssistantMessage`
|
|
132
|
+
* too, so callers do not need to care when cancellation happened.
|
|
133
|
+
* - A non-retryable error (per {@link isRetryableAssistantError}, including quota/
|
|
134
|
+
* billing exhaustion) is returned immediately so deterministic errors fail fast.
|
|
135
|
+
* - Otherwise retries up to `maxRetries` times with exponential backoff, emitting
|
|
136
|
+
* `onRetryScheduled` before each sleep, `onRetryAttemptStart` after each sleep before
|
|
137
|
+
* the retried call starts, and `onRetryFinished` once at the end (whether the loop
|
|
138
|
+
* ends in success, exhausted retries, or an aborted backoff).
|
|
139
|
+
*
|
|
140
|
+
* When `policy` is undefined or disabled, the first response is returned unchanged
|
|
141
|
+
* (equivalent to calling `produce()` directly).
|
|
142
|
+
*/
|
|
143
|
+
async function retryAssistantCall(produce, policy, signal, callbacks) {
|
|
144
|
+
const maxAttempts = policy?.enabled ? policy.maxRetries : 0;
|
|
145
|
+
let attempt = 0;
|
|
146
|
+
let lastRetry;
|
|
147
|
+
for (;;) {
|
|
148
|
+
const response = await produce();
|
|
149
|
+
if (response.stopReason === "aborted") {
|
|
150
|
+
if (lastRetry) await callbacks?.onRetryFinished?.(false, lastRetry.attempt);
|
|
151
|
+
return response;
|
|
152
|
+
}
|
|
153
|
+
if (response.stopReason !== "error") {
|
|
154
|
+
if (lastRetry) await callbacks?.onRetryFinished?.(true, lastRetry.attempt);
|
|
155
|
+
return response;
|
|
156
|
+
}
|
|
157
|
+
if (attempt >= maxAttempts || !isRetryableAssistantError(response)) {
|
|
158
|
+
if (lastRetry) await callbacks?.onRetryFinished?.(false, lastRetry.attempt, response.errorMessage);
|
|
159
|
+
return response;
|
|
160
|
+
}
|
|
161
|
+
attempt++;
|
|
162
|
+
lastRetry = {
|
|
163
|
+
attempt,
|
|
164
|
+
errorMessage: response.errorMessage || "Unknown error"
|
|
165
|
+
};
|
|
166
|
+
const delayMs = policy.baseDelayMs * 2 ** (attempt - 1);
|
|
167
|
+
await callbacks?.onRetryScheduled?.(attempt, maxAttempts, delayMs, lastRetry.errorMessage);
|
|
168
|
+
try {
|
|
169
|
+
await sleep$1(delayMs, signal);
|
|
170
|
+
} catch (error) {
|
|
171
|
+
await callbacks?.onRetryFinished?.(false, attempt, lastRetry.errorMessage);
|
|
172
|
+
if (error instanceof RetrySleepAbortError) return {
|
|
173
|
+
...response,
|
|
174
|
+
stopReason: "aborted",
|
|
175
|
+
errorMessage: void 0
|
|
176
|
+
};
|
|
177
|
+
throw error;
|
|
178
|
+
}
|
|
179
|
+
await callbacks?.onRetryAttemptStart?.();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Classifies whether a failed assistant message looks like a transient provider
|
|
184
|
+
* or transport error, so callers can decide if the last assistant turn should be
|
|
185
|
+
* restarted.
|
|
186
|
+
*
|
|
187
|
+
* This does not implement retry policy. Callers should first handle context
|
|
188
|
+
* overflow separately, then apply their own retry budget, backoff, and reporting
|
|
189
|
+
* before restarting the assistant turn.
|
|
190
|
+
*/
|
|
191
|
+
function isRetryableAssistantError(message) {
|
|
192
|
+
if (message.stopReason !== "error" || !message.errorMessage) return false;
|
|
193
|
+
const errorMessage = message.errorMessage;
|
|
194
|
+
if (NON_RETRYABLE_PROVIDER_LIMIT_ERROR_PATTERN.test(errorMessage)) return false;
|
|
195
|
+
return RETRYABLE_PROVIDER_ERROR_PATTERN.test(errorMessage);
|
|
196
|
+
}
|
|
197
|
+
//#endregion
|
|
17
198
|
//#region src/compat/vendor/pi-ai-overflow.ts
|
|
18
199
|
/**
|
|
19
200
|
* Regex patterns to detect context overflow errors from different providers.
|
|
@@ -166,79 +347,6 @@ function isRecoverableLength(message, desiredMaxOutput) {
|
|
|
166
347
|
return message.stopReason === "length" && desiredMaxOutput > 0 && message.usage.output < desiredMaxOutput;
|
|
167
348
|
}
|
|
168
349
|
//#endregion
|
|
169
|
-
//#region src/compat/vendor/pi-ai-retry.ts
|
|
170
|
-
function buildProviderErrorPattern(patterns) {
|
|
171
|
-
return new RegExp(patterns.join("|"), "i");
|
|
172
|
-
}
|
|
173
|
-
const NON_RETRYABLE_PROVIDER_LIMIT_ERROR_PATTERN = buildProviderErrorPattern([
|
|
174
|
-
"GoUsageLimitError",
|
|
175
|
-
"FreeUsageLimitError",
|
|
176
|
-
"Monthly usage limit reached",
|
|
177
|
-
"available balance",
|
|
178
|
-
"insufficient_quota",
|
|
179
|
-
"out of budget",
|
|
180
|
-
"quota exceeded",
|
|
181
|
-
"billing"
|
|
182
|
-
]);
|
|
183
|
-
const RETRYABLE_PROVIDER_ERROR_PATTERN = buildProviderErrorPattern([
|
|
184
|
-
"overloaded",
|
|
185
|
-
"rate.?limit",
|
|
186
|
-
"too many requests",
|
|
187
|
-
"429",
|
|
188
|
-
"500",
|
|
189
|
-
"502",
|
|
190
|
-
"503",
|
|
191
|
-
"504",
|
|
192
|
-
"524",
|
|
193
|
-
"service.?unavailable",
|
|
194
|
-
"server.?error",
|
|
195
|
-
"internal.?error",
|
|
196
|
-
"provider.?returned.?error",
|
|
197
|
-
"exceeded request buffer limit while retrying upstream",
|
|
198
|
-
"network.?error",
|
|
199
|
-
"connection.?error",
|
|
200
|
-
"connection.?refused",
|
|
201
|
-
"connection.?lost",
|
|
202
|
-
"other side closed",
|
|
203
|
-
"fetch failed",
|
|
204
|
-
"getaddrinfo",
|
|
205
|
-
"ENOTFOUND",
|
|
206
|
-
"EAI_AGAIN",
|
|
207
|
-
"upstream.?connect",
|
|
208
|
-
"reset before headers",
|
|
209
|
-
"socket hang up",
|
|
210
|
-
"socket connection was closed",
|
|
211
|
-
"timed? out",
|
|
212
|
-
"timeout",
|
|
213
|
-
"terminated",
|
|
214
|
-
"websocket.?closed",
|
|
215
|
-
"websocket.?error",
|
|
216
|
-
"ended without",
|
|
217
|
-
"stream ended before message_stop",
|
|
218
|
-
"stream ended before a terminal response event",
|
|
219
|
-
"http2 request did not get a response",
|
|
220
|
-
"retry delay",
|
|
221
|
-
"you can retry your request",
|
|
222
|
-
"try your request again",
|
|
223
|
-
"please retry your request",
|
|
224
|
-
"ResourceExhausted"
|
|
225
|
-
]);
|
|
226
|
-
/**
|
|
227
|
-
* Classifies whether a failed assistant message looks like a transient provider
|
|
228
|
-
* or transport error, so callers can decide if the last assistant turn should be
|
|
229
|
-
* restarted.
|
|
230
|
-
*
|
|
231
|
-
* This does not implement retry policy. Callers should first handle context
|
|
232
|
-
* overflow separately, then apply their own retry budget, backoff, and reporting
|
|
233
|
-
* before restarting the assistant turn.
|
|
234
|
-
*/
|
|
235
|
-
function isRetryableAssistantError(message) {
|
|
236
|
-
if (message.stopReason !== "error" || !message.errorMessage) return false;
|
|
237
|
-
const errorMessage = message.errorMessage;
|
|
238
|
-
if (NON_RETRYABLE_PROVIDER_LIMIT_ERROR_PATTERN.test(errorMessage)) return false;
|
|
239
|
-
return RETRYABLE_PROVIDER_ERROR_PATTERN.test(errorMessage);
|
|
240
|
-
}
|
|
241
|
-
//#endregion
|
|
242
350
|
//#region src/compat/vendor/pi-ai-event-stream.ts
|
|
243
351
|
var EventStream = class {
|
|
244
352
|
queue = [];
|
|
@@ -2929,6 +3037,9 @@ let activeLlmBridge;
|
|
|
2929
3037
|
function __setPiAiLlmBridge(bridge) {
|
|
2930
3038
|
activeLlmBridge = bridge;
|
|
2931
3039
|
}
|
|
3040
|
+
function __getPiAiLlmBridge() {
|
|
3041
|
+
return activeLlmBridge;
|
|
3042
|
+
}
|
|
2932
3043
|
function requireLlmBridge(api) {
|
|
2933
3044
|
if (activeLlmBridge === void 0) throw new Error(`pi2dsh: pi-ai ${api}() needs a DSH llm service; this composition mounts none, so model calls cannot be routed`);
|
|
2934
3045
|
return activeLlmBridge;
|
|
@@ -2950,6 +3061,6 @@ function StringEnum(values, options = {}) {
|
|
|
2950
3061
|
};
|
|
2951
3062
|
}
|
|
2952
3063
|
//#endregion
|
|
2953
|
-
export {
|
|
3064
|
+
export { pollOAuthDeviceCodeFlow as A, uuidv7 as B, stream as C, anthropicOAuth as D, githubCopilotOAuth as E, AssistantMessageEventStream as F, isContextOverflow as I, isRecoverableLength as L, createProvider as M, lazyApi as N, openaiCodexOAuth as O, lazyStream as P, isRetryableAssistantError as R, registerProvider as S, kimiCodingOAuth as T, loadGitHubCopilotOAuth as _, builtinProviders as a, modelsAreEqual as b, contentText as c, getModel as d, getModels as f, loadAnthropicOAuth as g, getSupportedThinkingLevels as h, __setPiAiLlmBridge as i, ModelsError as j, generatePKCE as k, getApiProvider as l, getProviders as m, Type$1 as n, clampThinkingLevel as o, getProvider as p, __getPiAiLlmBridge as r, complete as s, StringEnum as t, getApiProviders as u, loadKimiCodingOAuth as v, unregisterApiProviders as w, registerApiProvider as x, loadOpenAICodexOAuth as y, retryAssistantCall as z };
|
|
2954
3065
|
|
|
2955
|
-
//# sourceMappingURL=pi-ai-
|
|
3066
|
+
//# sourceMappingURL=pi-ai-Dyg4zyLZ.mjs.map
|