@centerforagenticai/pi-multi-account 0.1.5 → 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/README.md +17 -3
- package/package.json +5 -5
- package/packages/pi-anthropic-oauth/package.json +2 -2
- package/packages/pi-anthropic-oauth/src/stream.ts +18 -8
- package/packages/pi-anthropic-oauth/src/transport-activity.ts +59 -0
- package/packages/pi-antigravity/package.json +2 -2
- package/packages/pi-antigravity/src/models/discovery.ts +2 -1
- package/packages/pi-antigravity/src/models/grouping.ts +12 -10
- package/packages/pi-antigravity/src/models/models.ts +11 -4
- package/src/account-group-failure.ts +149 -0
- package/src/account-group-members.ts +139 -0
- package/src/anthropic-adaptive-stream.ts +18 -9
- package/src/anthropic-alias-stream.ts +13 -68
- package/src/codex-adapter.ts +5 -51
- package/src/commands.ts +3 -3
- package/src/config.ts +46 -2
- package/src/diagnostic-store.ts +17 -15
- package/src/diagnostics.ts +97 -35
- package/src/host-final-stop-message.ts +18 -128
- package/src/index.ts +436 -88
- package/src/logical-dispatch.ts +12 -13
- package/src/logical-provider.ts +1208 -407
- package/src/models-declaration.ts +15 -8
- package/src/public-assistant-projection.ts +163 -0
- package/src/recovery-engine.ts +311 -59
- package/src/routing.ts +4 -8
- package/src/runtime-state.ts +7 -0
- package/src/upstream-anthropic.ts +12 -4
- package/src/upstream-antigravity.ts +2 -38
|
@@ -1,136 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
isContextOverflow,
|
|
3
|
-
isRetryableAssistantError,
|
|
4
|
-
type AssistantMessage,
|
|
5
|
-
} from "@earendil-works/pi-ai";
|
|
6
|
-
import { sanitizeDiagnosticText } from "./diagnostics.js";
|
|
1
|
+
import { isContextOverflow, isRetryableAssistantError, type AssistantMessage } from "@earendil-works/pi-ai";
|
|
7
2
|
|
|
8
|
-
/** Fixed
|
|
3
|
+
/** Fixed public reasons: provider prose and unknown reason payloads are never retained. */
|
|
9
4
|
export const REFUSAL_FALLBACK_MESSAGE = "The model refused to complete the request";
|
|
10
|
-
export const UNKNOWN_STOP_FALLBACK_MESSAGE =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Appended when a reworded unknown stop reason omits words a host predicate acts
|
|
15
|
-
* on, so the published reason does not read as complete. Neither pinned
|
|
16
|
-
* predicate matches it, and the marked message is probed again before use.
|
|
17
|
-
*/
|
|
5
|
+
export const UNKNOWN_STOP_FALLBACK_MESSAGE = "Provider stopped with an unrecognized stop reason";
|
|
6
|
+
// Kept for source compatibility; reasons are now entirely withheld, not reworded.
|
|
18
7
|
export const PARTLY_WITHHELD_MARKER = " (partly withheld)";
|
|
19
8
|
|
|
20
|
-
/**
|
|
21
|
-
const MAX_NAMED_REASON_LENGTH = 64;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Whether the pinned host would re-dispatch an error terminal carrying `text`.
|
|
25
|
-
*
|
|
26
|
-
* The host re-dispatches when either retry predicate matches the prose:
|
|
27
|
-
* `AgentSession._isRetryableError` runs pi-ai `isRetryableAssistantError`, and
|
|
28
|
-
* `_checkCompaction` runs `isContextOverflow` before compacting and retrying once
|
|
29
|
-
* (pi-coding-agent dist/core/agent-session.js, both from `@earendil-works/pi-ai`).
|
|
30
|
-
* An unreadable predicate result counts as a match, so the caller keeps looking
|
|
31
|
-
* for a safer form.
|
|
32
|
-
*/
|
|
9
|
+
/** Probe pinned host predicates without publishing the provider DTO. */
|
|
33
10
|
export function hostWouldRedispatch(message: AssistantMessage, text: string): boolean {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function namedReasonMessage(reason: string): string {
|
|
43
|
-
return `Provider stopped (reason: ${reason})`;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Normalizes a bounded, sanitized raw stop reason into plain words: every run of
|
|
48
|
-
* non-alphanumeric characters (underscores included) becomes one space, and the
|
|
49
|
-
* result is capped at a word boundary where possible.
|
|
50
|
-
*/
|
|
51
|
-
function normalizedReasonWords(rawStopReason: unknown): string[] {
|
|
52
|
-
if (typeof rawStopReason !== "string") return [];
|
|
53
|
-
const words = sanitizeDiagnosticText(rawStopReason)
|
|
54
|
-
.replace(/[^A-Za-z0-9]+/g, " ")
|
|
55
|
-
.trim()
|
|
56
|
-
.split(" ")
|
|
57
|
-
.filter((word) => word.length > 0);
|
|
58
|
-
const kept: string[] = [];
|
|
59
|
-
let length = 0;
|
|
60
|
-
for (const word of words) {
|
|
61
|
-
const next = length === 0 ? word.length : length + 1 + word.length;
|
|
62
|
-
if (next > MAX_NAMED_REASON_LENGTH) {
|
|
63
|
-
if (kept.length === 0) kept.push(word.slice(0, MAX_NAMED_REASON_LENGTH));
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
kept.push(word);
|
|
67
|
-
length = next;
|
|
68
|
-
}
|
|
69
|
-
return kept;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Names an unknown stop reason in a message neither host predicate acts on.
|
|
74
|
-
*
|
|
75
|
-
* The first form keeps every normalized word. When that still matches a host
|
|
76
|
-
* predicate (a reason containing "overloaded" or "timeout", say), the second
|
|
77
|
-
* form admits words in order and drops each one whose addition would make the
|
|
78
|
-
* message match. When any word was dropped the result ends with
|
|
79
|
-
* `PARTLY_WITHHELD_MARKER`; that marked text is probed too, and an unsafe or
|
|
80
|
-
* empty result yields `undefined`.
|
|
81
|
-
*/
|
|
82
|
-
function unknownStopNamingReason(
|
|
83
|
-
message: AssistantMessage,
|
|
84
|
-
rawStopReason: unknown,
|
|
85
|
-
): string | undefined {
|
|
86
|
-
const words = normalizedReasonWords(rawStopReason);
|
|
87
|
-
if (words.length === 0) return undefined;
|
|
88
|
-
const reworded = namedReasonMessage(words.join(" "));
|
|
89
|
-
if (!hostWouldRedispatch(message, reworded)) return reworded;
|
|
90
|
-
const kept: string[] = [];
|
|
91
|
-
for (const word of words) {
|
|
92
|
-
const tentative = namedReasonMessage([...kept, word].join(" "));
|
|
93
|
-
if (!hostWouldRedispatch(message, tentative)) kept.push(word);
|
|
94
|
-
}
|
|
95
|
-
if (kept.length === 0) return undefined;
|
|
96
|
-
const named = namedReasonMessage(kept.join(" "));
|
|
97
|
-
if (kept.length === words.length) return named;
|
|
98
|
-
const marked = `${named}${PARTLY_WITHHELD_MARKER}`;
|
|
99
|
-
return hostWouldRedispatch(message, marked) ? undefined : marked;
|
|
11
|
+
try {
|
|
12
|
+
// Private predicate probe only; this object is never published or retained.
|
|
13
|
+
const probe = { ...message, errorMessage: text };
|
|
14
|
+
return isRetryableAssistantError(probe) || isContextOverflow(probe, 0);
|
|
15
|
+
} catch { return true; }
|
|
100
16
|
}
|
|
101
17
|
|
|
102
|
-
/**
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
* only when neither host predicate would act on it. An unknown stop is then
|
|
111
|
-
* reworded so it still names its reason, and only when no reworded form is safe
|
|
112
|
-
* is a fixed fallback published. A refusal whose explanation is unsafe publishes
|
|
113
|
-
* its fixed fallback directly. A message without the structured code, or that is
|
|
114
|
-
* not an error terminal, yields `undefined` and must be published unchanged.
|
|
115
|
-
*/
|
|
116
|
-
export function hostFinalStopMessage(
|
|
117
|
-
message: AssistantMessage,
|
|
118
|
-
): { readonly errorMessage: string } | undefined {
|
|
119
|
-
const code = (message as { code?: unknown }).code;
|
|
120
|
-
if (message.stopReason !== "error") return undefined;
|
|
121
|
-
if (code !== "refusal" && code !== "unknown_stop") return undefined;
|
|
122
|
-
const candidate = message.errorMessage;
|
|
123
|
-
if (
|
|
124
|
-
typeof candidate === "string" &&
|
|
125
|
-
candidate.length > 0 &&
|
|
126
|
-
!hostWouldRedispatch(message, candidate)
|
|
127
|
-
) {
|
|
128
|
-
return { errorMessage: candidate };
|
|
129
|
-
}
|
|
130
|
-
if (code === "refusal") return { errorMessage: REFUSAL_FALLBACK_MESSAGE };
|
|
131
|
-
return {
|
|
132
|
-
errorMessage:
|
|
133
|
-
unknownStopNamingReason(message, message.rawStopReason) ??
|
|
134
|
-
UNKNOWN_STOP_FALLBACK_MESSAGE,
|
|
135
|
-
};
|
|
18
|
+
/** A structured stop is an answer, never retry/overflow evidence or a prose retention permission. */
|
|
19
|
+
export function hostFinalStopMessage(message: AssistantMessage): {
|
|
20
|
+
readonly errorMessage: string;
|
|
21
|
+
readonly rawStopReason: "refusal" | "unknown_stop";
|
|
22
|
+
} | undefined {
|
|
23
|
+
const code = Object.getOwnPropertyDescriptor(message, "code")?.value;
|
|
24
|
+
if (message.stopReason !== "error" || (code !== "refusal" && code !== "unknown_stop")) return undefined;
|
|
25
|
+
return { errorMessage: code === "refusal" ? REFUSAL_FALLBACK_MESSAGE : UNKNOWN_STOP_FALLBACK_MESSAGE, rawStopReason: code };
|
|
136
26
|
}
|