@linxiraos/pi-ai 1.2.1 → 1.3.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/CHANGELOG.md +83 -0
- package/README.md +4 -2
- package/THIRD-PARTY-NOTICES.txt +55 -5
- package/dist/types/auth/cascade.d.ts +5 -3
- package/dist/types/auth/pool.d.ts +3 -3
- package/dist/types/auth/select.d.ts +5 -1
- package/dist/types/auth/types.d.ts +15 -5
- package/dist/types/auth/usage-cache.d.ts +3 -1
- package/dist/types/auth-gateway/clients.d.ts +67 -0
- package/dist/types/auth-gateway/dispatch.d.ts +28 -10
- package/dist/types/auth-gateway/http.d.ts +2 -0
- package/dist/types/auth-gateway/index.d.ts +1 -0
- package/dist/types/auth-gateway/server.d.ts +9 -4
- package/dist/types/auth-gateway/session-state.d.ts +6 -0
- package/dist/types/auth-gateway/types.d.ts +16 -2
- package/dist/types/dialect/coercion.d.ts +6 -0
- package/dist/types/error/classes.d.ts +1 -1
- package/dist/types/error/flags.d.ts +15 -0
- package/dist/types/error/index.d.ts +1 -0
- package/dist/types/error/network-cause.d.ts +40 -0
- package/dist/types/images/shared.d.ts +26 -2
- package/dist/types/index.d.ts +1 -0
- package/dist/types/judgment/native.d.ts +51 -3
- package/dist/types/judgment/systemone.d.ts +9 -2
- package/dist/types/judgment/text.d.ts +11 -5
- package/dist/types/judgment/types.d.ts +5 -1
- package/dist/types/judgment/wire.d.ts +16 -3
- package/dist/types/provider-session-state.d.ts +2 -2
- package/dist/types/providers/anthropic-images.d.ts +7 -0
- package/dist/types/providers/anthropic-signature.d.ts +12 -2
- package/dist/types/providers/anthropic-state.d.ts +7 -0
- package/dist/types/providers/anthropic.d.ts +21 -6
- package/dist/types/providers/connection-prewarm.d.ts +15 -0
- package/dist/types/providers/cursor/exec-modern.d.ts +1 -1
- package/dist/types/providers/cursor-pi-args.d.ts +13 -0
- package/dist/types/providers/cursor.d.ts +7 -0
- package/dist/types/providers/openai-codex-responses.d.ts +6 -0
- package/dist/types/providers/openai-responses.d.ts +9 -0
- package/dist/types/providers/openai-shared.d.ts +30 -0
- package/dist/types/providers/systemone-server.d.ts +7 -3
- package/dist/types/providers/transform-messages.d.ts +26 -5
- package/dist/types/registry/oauth/google-antigravity.d.ts +1 -1
- package/dist/types/stream.d.ts +0 -2
- package/dist/types/types.d.ts +33 -9
- package/dist/types/utils/dsml-leak.d.ts +4 -2
- package/dist/types/utils/narration.d.ts +9 -0
- package/dist/types/utils/openai-http.d.ts +2 -0
- package/dist/types/utils/request-body.d.ts +11 -0
- package/dist/types/utils/request-compression.d.ts +21 -0
- package/dist/types/utils/tool-call-arguments.d.ts +2 -1
- package/dist/types/utils/transport-fetch.d.ts +8 -0
- package/dist/types/utils.d.ts +1 -1
- package/package.json +7 -7
- package/src/auth/cascade.ts +23 -13
- package/src/auth/pool.ts +3 -3
- package/src/auth/refresh.ts +39 -12
- package/src/auth/select.ts +8 -2
- package/src/auth/types.ts +16 -5
- package/src/auth/usage-cache.ts +23 -7
- package/src/auth/usage.ts +2 -4
- package/src/auth-broker/remote-store.ts +31 -6
- package/src/auth-gateway/clients.ts +318 -0
- package/src/auth-gateway/dispatch.ts +66 -35
- package/src/auth-gateway/http.ts +11 -5
- package/src/auth-gateway/index.ts +1 -0
- package/src/auth-gateway/routes/embeddings.ts +4 -10
- package/src/auth-gateway/routes/images.ts +6 -10
- package/src/auth-gateway/routes/rerank.ts +4 -10
- package/src/auth-gateway/routes/speech.ts +10 -10
- package/src/auth-gateway/routes/systemone.ts +22 -12
- package/src/auth-gateway/routes/transcriptions.ts +4 -2
- package/src/auth-gateway/routes/video.ts +12 -15
- package/src/auth-gateway/server.ts +136 -53
- package/src/auth-gateway/session-state.ts +14 -0
- package/src/auth-gateway/types.ts +16 -2
- package/src/dialect/coercion.ts +16 -0
- package/src/dialect/hermes.ts +7 -11
- package/src/dialect/qwen3.ts +3 -11
- package/src/error/classes.ts +3 -2
- package/src/error/flags.ts +24 -3
- package/src/error/index.ts +1 -0
- package/src/error/network-cause.ts +179 -0
- package/src/images/codex-format-directive.md +3 -0
- package/src/images/google-antigravity.ts +2 -1
- package/src/images/google-generative-ai.ts +4 -2
- package/src/images/openai-hosted.ts +25 -2
- package/src/images/openai-images.ts +11 -6
- package/src/images/shared.ts +77 -3
- package/src/index.ts +1 -0
- package/src/judgment/chat.ts +17 -1
- package/src/judgment/native.ts +182 -12
- package/src/judgment/openai-decisions.ts +27 -6
- package/src/judgment/systemone.ts +131 -10
- package/src/judgment/text.ts +20 -7
- package/src/judgment/types.ts +5 -1
- package/src/judgment/wire.ts +17 -3
- package/src/provider-session-state.ts +2 -2
- package/src/providers/amazon-bedrock.ts +4 -1
- package/src/providers/anthropic-client.ts +1 -1
- package/src/providers/anthropic-images.ts +263 -0
- package/src/providers/anthropic-messages-server.ts +84 -1
- package/src/providers/anthropic-signature.ts +35 -8
- package/src/providers/anthropic-state.ts +13 -0
- package/src/providers/anthropic.ts +479 -397
- package/src/providers/connection-prewarm.ts +78 -0
- package/src/providers/cowork-fetch.ts +5 -1
- package/src/providers/cursor/exec-modern.ts +1 -0
- package/src/providers/cursor-pi-args.ts +19 -0
- package/src/providers/cursor.ts +53 -13
- package/src/providers/devin.ts +10 -4
- package/src/providers/factory-droid/gemini.ts +9 -3
- package/src/providers/google-gemini-cli.ts +11 -1
- package/src/providers/google-shared.ts +2 -6
- package/src/providers/images-server.ts +6 -1
- package/src/providers/ollama.ts +15 -5
- package/src/providers/openai-anthropic-shim.ts +1 -0
- package/src/providers/openai-chat-server.ts +29 -0
- package/src/providers/openai-codex/access-programs.ts +2 -1
- package/src/providers/openai-codex-responses.ts +49 -82
- package/src/providers/openai-completions.ts +117 -19
- package/src/providers/openai-responses.ts +25 -2
- package/src/providers/openai-shared.ts +36 -5
- package/src/providers/pi-native-server.ts +1 -0
- package/src/providers/systemone-server.ts +72 -12
- package/src/providers/transform-messages.ts +95 -51
- package/src/registry/oauth/google-antigravity.ts +1 -1
- package/src/stream.ts +13 -73
- package/src/types.ts +33 -9
- package/src/usage/claude.ts +2 -9
- package/src/usage/github-copilot.ts +26 -4
- package/src/usage/openai-codex.ts +13 -7
- package/src/usage/opencode-go.ts +7 -8
- package/src/usage/xai-oauth.ts +2 -9
- package/src/utils/dsml-leak.ts +30 -14
- package/src/utils/leaked-thinking-stream.ts +10 -0
- package/src/utils/narration.ts +18 -0
- package/src/utils/openai-http.ts +27 -18
- package/src/utils/request-body.ts +27 -0
- package/src/utils/request-compression.ts +202 -0
- package/src/utils/request-debug.ts +23 -9
- package/src/utils/schema/dereference.ts +51 -18
- package/src/utils/schema/draft.ts +10 -2
- package/src/utils/schema/json-schema-validator.ts +4 -10
- package/src/utils/schema/normalize.ts +6 -9
- package/src/utils/tool-call-arguments.ts +2 -1
- package/src/utils/transport-fetch.ts +37 -0
- package/src/utils/validation.ts +26 -16
- package/src/utils.ts +38 -23
package/src/utils.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { $env } from "@linxiraos/pi-utils";
|
|
2
2
|
import type { ResponseInput, ResponseInputItem } from "./providers/openai-responses-wire";
|
|
3
3
|
import { isMalformedToolCallName, redactSensitiveCredentials } from "./providers/transform-messages";
|
|
4
|
+
export { normalizeToolCallId } from "./providers/transform-messages";
|
|
4
5
|
import type { CacheRetention, OpenAIResponsesHistoryPayload, ProviderPayload } from "./types";
|
|
6
|
+
import { invalidToolCallArguments } from "./utils/tool-call-arguments";
|
|
5
7
|
|
|
6
8
|
type OpenAIResponsesReplayItem = ResponseInput[number];
|
|
7
9
|
const NON_WHITESPACE_RE = /\S/;
|
|
@@ -33,11 +35,6 @@ export function normalizeSystemPrompts(systemPrompt: readonly string[] | string
|
|
|
33
35
|
.filter(prompt => prompt.trim().length > 0);
|
|
34
36
|
}
|
|
35
37
|
|
|
36
|
-
export function normalizeToolCallId(id: string): string {
|
|
37
|
-
const sanitized = id.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
38
|
-
return sanitized.length > 64 ? sanitized.slice(0, 64) : sanitized;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
38
|
type ResponsesToolItemIdPrefix = "fc" | "ctc";
|
|
42
39
|
|
|
43
40
|
/** Preserve opaque call IDs for Responses replay while normalizing or generating the separate item ID. */
|
|
@@ -561,24 +558,44 @@ export function dropMalformedOpenAIResponsesToolCalls<
|
|
|
561
558
|
}
|
|
562
559
|
|
|
563
560
|
/**
|
|
564
|
-
* Replay history is immutable and re-sanitized on every request, so
|
|
565
|
-
*
|
|
561
|
+
* Replay history is immutable and re-sanitized on every request, so each item
|
|
562
|
+
* remembers the replay `arguments` derived from its stored value instead of
|
|
566
563
|
* re-parsing every historical call (large write/edit payloads) per request.
|
|
564
|
+
* Frozen/sealed caller-owned items are never mutated; they re-parse instead.
|
|
565
|
+
*/
|
|
566
|
+
const kReplayArguments = Symbol("openaiResponses.replayArguments");
|
|
567
|
+
|
|
568
|
+
interface FunctionCallReplayItem extends Record<string, unknown> {
|
|
569
|
+
[kReplayArguments]?: { raw: unknown; replay: string };
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* `arguments` to replay for a native `function_call`: the stored string when it
|
|
574
|
+
* parses, `{}` when absent/blank, else the bounded `{__parseError, __rawJson}`
|
|
575
|
+
* diagnostic the transcript (and the cold replay path) already carries.
|
|
576
|
+
*
|
|
577
|
+
* Unparsable text (stream cut off mid-JSON) 400s the whole request, but dropping
|
|
578
|
+
* the call orphans its recorded tool result into an assistant note that can end
|
|
579
|
+
* the request and 400 it again (#15568).
|
|
567
580
|
*/
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
if (
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
581
|
+
function replayFunctionCallArguments(item: FunctionCallReplayItem): string {
|
|
582
|
+
const raw = item.arguments;
|
|
583
|
+
const cached = item[kReplayArguments];
|
|
584
|
+
if (cached && cached.raw === raw) return cached.replay;
|
|
585
|
+
let replay = "{}";
|
|
586
|
+
if (typeof raw === "string" && raw.trim().length > 0) {
|
|
587
|
+
try {
|
|
588
|
+
JSON.parse(raw);
|
|
589
|
+
replay = raw;
|
|
590
|
+
} catch (error) {
|
|
591
|
+
replay = JSON.stringify(invalidToolCallArguments(raw, error));
|
|
592
|
+
}
|
|
579
593
|
}
|
|
580
|
-
|
|
581
|
-
|
|
594
|
+
// Non-enumerable: the sanitizer's object rest copy must not carry the cache onto wire items.
|
|
595
|
+
if (Object.isExtensible(item)) {
|
|
596
|
+
Object.defineProperty(item, kReplayArguments, { value: { raw, replay }, writable: true });
|
|
597
|
+
}
|
|
598
|
+
return replay;
|
|
582
599
|
}
|
|
583
600
|
|
|
584
601
|
function sanitizeOpenAIResponsesHistoryItemForReplay(
|
|
@@ -592,9 +609,6 @@ function sanitizeOpenAIResponsesHistoryItemForReplay(
|
|
|
592
609
|
if (isMalformedOpenAIResponsesToolCall(item)) {
|
|
593
610
|
return undefined;
|
|
594
611
|
}
|
|
595
|
-
if (item.type === "function_call") {
|
|
596
|
-
if (!hasValidReplayArguments(item)) return undefined;
|
|
597
|
-
}
|
|
598
612
|
if (item.type === "item_reference") return undefined;
|
|
599
613
|
if (item.type === "image_generation_call") return sanitizeOpenAIResponsesImageGenerationCallForReplay(item);
|
|
600
614
|
if (item.type === "reasoning") {
|
|
@@ -602,6 +616,7 @@ function sanitizeOpenAIResponsesHistoryItemForReplay(
|
|
|
602
616
|
}
|
|
603
617
|
const { id: _id, ...sanitizedItem } = item;
|
|
604
618
|
if (item.type === "computer_call" && typeof item.id === "string") sanitizedItem.id = item.id;
|
|
619
|
+
if (item.type === "function_call") sanitizedItem.arguments = replayFunctionCallArguments(item);
|
|
605
620
|
|
|
606
621
|
return clampReplayItemImageDetail(
|
|
607
622
|
sanitizedItem,
|