@skydiveai/pi-extensions 0.1.259-beta.4 → 0.1.259-beta.5
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/dist/index.mjs +58 -3
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -3636,6 +3636,37 @@ var ModelResponse = class {
|
|
|
3636
3636
|
}
|
|
3637
3637
|
};
|
|
3638
3638
|
//#endregion
|
|
3639
|
+
//#region src/extensions/claude-seat-limit.ts
|
|
3640
|
+
/** Overage reasons where the usage-credit cap or balance is the wall. */
|
|
3641
|
+
const OVERAGE_SPEND_REASONS = new Set([
|
|
3642
|
+
"out_of_credits",
|
|
3643
|
+
"seat_tier_zero_credit_limit",
|
|
3644
|
+
"group_zero_credit_limit",
|
|
3645
|
+
"member_zero_credit_limit"
|
|
3646
|
+
]);
|
|
3647
|
+
function limitKind(limit) {
|
|
3648
|
+
if (limit.errorCode === "credits_required") return "credits_required";
|
|
3649
|
+
if (limit.rateLimitType === "overage") return limit.overageDisabledReason !== null && OVERAGE_SPEND_REASONS.has(limit.overageDisabledReason) ? "spend_limit" : "credits_required";
|
|
3650
|
+
if (limit.limitScope !== null) return "spend_limit";
|
|
3651
|
+
return "window";
|
|
3652
|
+
}
|
|
3653
|
+
function limitTag(limit) {
|
|
3654
|
+
const kind = limit === null ? "window" : limitKind(limit);
|
|
3655
|
+
return `[claude-plan-limit kind=${kind}${kind === "window" && limit?.rateLimitType ? ` type=${limit.rateLimitType}` : ""}${kind !== "window" || limit?.resetsAt == null ? "" : ` resets=${limit.resetsAt}`}]`;
|
|
3656
|
+
}
|
|
3657
|
+
/**
|
|
3658
|
+
* The failure message for an assistant message that carries an SDK error.
|
|
3659
|
+
* `text` is the sentence Claude Code put in that message, which is where
|
|
3660
|
+
* variants without a rate-limit event (spend caps, the 1M-context entitlement,
|
|
3661
|
+
* the Fable credits prompt) name themselves.
|
|
3662
|
+
*/
|
|
3663
|
+
function seatAssistantErrorMessage({ assistantError, text, rejectedLimit }) {
|
|
3664
|
+
if (assistantError === "max_output_tokens") return `Claude SDK assistant error: ${assistantError}`;
|
|
3665
|
+
const detail = text.trim();
|
|
3666
|
+
if (rejectedLimit !== null || assistantError === "rate_limit") return `${limitTag(rejectedLimit)} ${detail}`.trim();
|
|
3667
|
+
return detail ? `Claude connection error (${assistantError}): ${detail}` : `Claude connection error (${assistantError})`;
|
|
3668
|
+
}
|
|
3669
|
+
//#endregion
|
|
3639
3670
|
//#region src/extensions/claude-seat-sdk.ts
|
|
3640
3671
|
/**
|
|
3641
3672
|
* Adapts one Claude Code query to one Pi model step. Pi executes every tool;
|
|
@@ -3680,19 +3711,34 @@ var SeatSdkBridge = class {
|
|
|
3680
3711
|
})]).finally(() => preparation.abort());
|
|
3681
3712
|
signal.throwIfAborted();
|
|
3682
3713
|
const query = new SeatQuery(request, this.timeouts);
|
|
3714
|
+
let rejectedLimit = null;
|
|
3683
3715
|
seatQuery = query;
|
|
3684
3716
|
query.bindSignal(signal);
|
|
3685
3717
|
this.queries.add(query);
|
|
3686
3718
|
query.run(this.deps).finally(() => this.queries.delete(query));
|
|
3687
3719
|
while (true) {
|
|
3688
3720
|
const message = await seatQuery.next();
|
|
3689
|
-
if (message.type === "assistant")
|
|
3690
|
-
|
|
3721
|
+
if (message.type === "assistant") {
|
|
3722
|
+
if (message.error === "unknown" && rejectedLimit === null && !message.parent_tool_use_id) log$17.warn({ sessionId: this.deps.sessionId }, "Claude seat assistant error arrived with no rejected rate-limit event first");
|
|
3723
|
+
if (message.error && !message.parent_tool_use_id) throw new Error(seatAssistantErrorMessage({
|
|
3724
|
+
assistantError: message.error,
|
|
3725
|
+
text: message.message.content.flatMap((block) => block.type === "text" ? [block.text] : []).join("\n"),
|
|
3726
|
+
rejectedLimit
|
|
3727
|
+
}));
|
|
3728
|
+
response.assistant(message);
|
|
3729
|
+
} else if (message.type === "stream_event") {
|
|
3691
3730
|
response.partial(message);
|
|
3692
3731
|
if (!message.parent_tool_use_id && message.event.type === "content_block_delta") this.onActivity();
|
|
3693
3732
|
} else if (message.type === "result") {
|
|
3694
3733
|
const hasTools = response.hasTools;
|
|
3695
|
-
if (message.is_error && !(message.subtype === "error_max_turns" && hasTools))
|
|
3734
|
+
if (message.is_error && !(message.subtype === "error_max_turns" && hasTools)) {
|
|
3735
|
+
const text = "errors" in message ? message.errors.join("; ") : message.result;
|
|
3736
|
+
throw new Error(rejectedLimit === null ? text : seatAssistantErrorMessage({
|
|
3737
|
+
assistantError: "unknown",
|
|
3738
|
+
text,
|
|
3739
|
+
rejectedLimit
|
|
3740
|
+
}));
|
|
3741
|
+
}
|
|
3696
3742
|
log$17.info({
|
|
3697
3743
|
sessionId: this.deps.sessionId,
|
|
3698
3744
|
queryUsage: mapUsage(message.usage),
|
|
@@ -3702,6 +3748,15 @@ var SeatSdkBridge = class {
|
|
|
3702
3748
|
return;
|
|
3703
3749
|
} else if (message.type === "rate_limit_event") {
|
|
3704
3750
|
const info = message.rate_limit_info;
|
|
3751
|
+
if (info.status === "allowed") rejectedLimit = null;
|
|
3752
|
+
else if (info.status === "rejected") rejectedLimit = {
|
|
3753
|
+
resetsAt: info.resetsAt ?? null,
|
|
3754
|
+
rateLimitType: info.rateLimitType ?? null,
|
|
3755
|
+
errorCode: info.errorCode ?? null,
|
|
3756
|
+
limitScope: info.limitScope ?? null,
|
|
3757
|
+
overageStatus: info.overageStatus ?? null,
|
|
3758
|
+
overageDisabledReason: info.overageDisabledReason ?? null
|
|
3759
|
+
};
|
|
3705
3760
|
await options.onResponse?.({
|
|
3706
3761
|
status: info.status === "rejected" ? 429 : 200,
|
|
3707
3762
|
headers: {
|