@linxiraos/pi-ai 1.0.0 → 1.0.2
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 +123 -30
- package/package.json +135 -136
- package/src/auth/sqlite-credential-store.ts +0 -56
- package/src/auth-retry.ts +5 -4
- package/src/auth-storage.ts +122 -112
- package/src/dialect/owned-stream.ts +3 -0
- package/src/error/auth-classify.ts +7 -6
- package/src/error/aws.ts +5 -1
- package/src/error/flags.ts +25 -1
- package/src/error/provider.ts +6 -5
- package/src/error/rate-limit.ts +71 -1
- package/src/providers/amazon-bedrock.ts +38 -0
- package/src/providers/anthropic-client.ts +6 -10
- package/src/providers/anthropic.ts +107 -259
- package/src/providers/aws-credentials.ts +222 -29
- package/src/providers/azure-openai-responses.ts +1 -0
- package/src/providers/cursor/exec-modern.ts +1 -0
- package/src/providers/cursor-pi-args.ts +22 -0
- package/src/providers/cursor.ts +81 -1
- package/src/providers/devin.ts +3 -3
- package/src/providers/google-antigravity-forced-tool.md +1 -0
- package/src/providers/google-gemini-cli.ts +83 -40
- package/src/providers/google-shared.ts +22 -8
- package/src/providers/ollama.ts +15 -3
- package/src/providers/openai-codex/request-transformer.ts +47 -21
- package/src/providers/openai-codex-responses.ts +3 -3
- package/src/providers/openai-reasoning-fallback.ts +21 -8
- package/src/providers/openai-responses.ts +77 -12
- package/src/providers/openai-shared.ts +114 -15
- package/src/providers/pi-native-server.ts +1 -0
- package/src/providers/register-builtins.ts +18 -14
- package/src/providers/vision-guard.ts +15 -3
- package/src/registry/amazon-bedrock.ts +9 -14
- package/src/registry/api-key-login.ts +26 -12
- package/src/registry/aws.ts +16 -8
- package/src/registry/cloudflare-ai-gateway.ts +10 -29
- package/src/registry/kagi.ts +11 -29
- package/src/registry/litellm.ts +11 -29
- package/src/registry/llama-cpp.ts +11 -21
- package/src/registry/lm-studio.ts +9 -20
- package/src/registry/oauth/callback-server.ts +93 -5
- package/src/registry/oauth/google-antigravity.ts +99 -44
- package/src/registry/oauth/perplexity.ts +32 -4
- package/src/registry/parallel.ts +10 -28
- package/src/registry/tavily.ts +9 -27
- package/src/registry/together.ts +7 -3
- package/src/registry/vercel-ai-gateway.ts +10 -28
- package/src/registry/vllm.ts +11 -21
- package/src/stream.ts +459 -53
- package/src/types.ts +23 -0
- package/src/usage/alibaba-token-plan.ts +8 -15
- package/src/usage/claude.ts +12 -19
- package/src/usage/cursor.ts +179 -59
- package/src/usage/gemini.ts +4 -3
- package/src/usage/github-copilot.ts +3 -2
- package/src/usage/google-antigravity.ts +10 -17
- package/src/usage/kimi.ts +35 -17
- package/src/usage/minimax-code.ts +7 -27
- package/src/usage/openai-codex-reset.ts +3 -2
- package/src/usage/openai-codex.ts +5 -5
- package/src/usage/opencode-go.ts +170 -60
- package/src/usage/shared.ts +33 -10
- package/src/usage/synthetic.ts +4 -11
- package/src/usage/umans.ts +2 -2
- package/src/usage/xai-oauth.ts +62 -34
- package/src/usage/zai.ts +4 -6
- package/src/usage.ts +0 -20
- package/src/utils/aws-profile.ts +39 -1
- package/src/utils/block-symbols.ts +18 -0
- package/src/utils/empty-completion-retry.ts +4 -1
- package/src/utils/leaked-thinking-stream.ts +3 -0
- package/src/utils/openrouter-headers.ts +4 -4
- package/src/utils/thinking-loop.ts +17 -38
- package/dist/types/api-registry.d.ts +0 -30
- package/dist/types/auth/sqlite-credential-store.d.ts +0 -117
- package/dist/types/auth-broker/client.d.ts +0 -93
- package/dist/types/auth-broker/discover.d.ts +0 -39
- package/dist/types/auth-broker/index.d.ts +0 -7
- package/dist/types/auth-broker/refresher.d.ts +0 -25
- package/dist/types/auth-broker/remote-store.d.ts +0 -136
- package/dist/types/auth-broker/server.d.ts +0 -48
- package/dist/types/auth-broker/snapshot-cache.d.ts +0 -17
- package/dist/types/auth-broker/types.d.ts +0 -152
- package/dist/types/auth-broker/wire-schema-resource.d.ts +0 -53
- package/dist/types/auth-broker/wire-schemas.d.ts +0 -5
- package/dist/types/auth-gateway/http.d.ts +0 -56
- package/dist/types/auth-gateway/index.d.ts +0 -3
- package/dist/types/auth-gateway/server.d.ts +0 -36
- package/dist/types/auth-gateway/types.d.ts +0 -127
- package/dist/types/auth-retry.d.ts +0 -150
- package/dist/types/auth-storage.d.ts +0 -1258
- package/dist/types/dialect/anthropic.d.ts +0 -15
- package/dist/types/dialect/catalog.d.ts +0 -3
- package/dist/types/dialect/coercion.d.ts +0 -23
- package/dist/types/dialect/deepseek.d.ts +0 -14
- package/dist/types/dialect/demotion.d.ts +0 -30
- package/dist/types/dialect/examples.d.ts +0 -18
- package/dist/types/dialect/factory.d.ts +0 -3
- package/dist/types/dialect/fenced-thinking.d.ts +0 -53
- package/dist/types/dialect/gemini.d.ts +0 -17
- package/dist/types/dialect/gemma.d.ts +0 -15
- package/dist/types/dialect/glm.d.ts +0 -9
- package/dist/types/dialect/harmony.d.ts +0 -8
- package/dist/types/dialect/hermes.d.ts +0 -9
- package/dist/types/dialect/history.d.ts +0 -3
- package/dist/types/dialect/index.d.ts +0 -11
- package/dist/types/dialect/inventory.d.ts +0 -9
- package/dist/types/dialect/kimi.d.ts +0 -14
- package/dist/types/dialect/minimax.d.ts +0 -3
- package/dist/types/dialect/owned-stream.d.ts +0 -4
- package/dist/types/dialect/qwen3.d.ts +0 -9
- package/dist/types/dialect/rendering.d.ts +0 -54
- package/dist/types/dialect/thinking.d.ts +0 -6
- package/dist/types/dialect/types.d.ts +0 -68
- package/dist/types/dialect/xml.d.ts +0 -9
- package/dist/types/error/abort.d.ts +0 -14
- package/dist/types/error/auth-classify.d.ts +0 -20
- package/dist/types/error/auth.d.ts +0 -27
- package/dist/types/error/aws.d.ts +0 -27
- package/dist/types/error/classes.d.ts +0 -106
- package/dist/types/error/finalize.d.ts +0 -39
- package/dist/types/error/flags.d.ts +0 -94
- package/dist/types/error/format.d.ts +0 -20
- package/dist/types/error/gateway.d.ts +0 -20
- package/dist/types/error/index.d.ts +0 -14
- package/dist/types/error/oauth.d.ts +0 -43
- package/dist/types/error/provider.d.ts +0 -42
- package/dist/types/error/rate-limit.d.ts +0 -80
- package/dist/types/error/retryable.d.ts +0 -27
- package/dist/types/error/validation.d.ts +0 -32
- package/dist/types/index.d.ts +0 -51
- package/dist/types/provider-details.d.ts +0 -24
- package/dist/types/providers/amazon-bedrock.d.ts +0 -39
- package/dist/types/providers/anthropic-client.d.ts +0 -106
- package/dist/types/providers/anthropic-messages-server-schema.d.ts +0 -937
- package/dist/types/providers/anthropic-messages-server.d.ts +0 -17
- package/dist/types/providers/anthropic-wire.d.ts +0 -345
- package/dist/types/providers/anthropic.d.ts +0 -261
- package/dist/types/providers/aws-credentials.d.ts +0 -48
- package/dist/types/providers/aws-eventstream.d.ts +0 -39
- package/dist/types/providers/aws-sigv4.d.ts +0 -55
- package/dist/types/providers/azure-openai-responses.d.ts +0 -16
- package/dist/types/providers/bedrock-mantle.d.ts +0 -13
- package/dist/types/providers/claude-code-fingerprint.d.ts +0 -19
- package/dist/types/providers/cowork-fetch.d.ts +0 -3
- package/dist/types/providers/cursor/exec-modern.d.ts +0 -98
- package/dist/types/providers/cursor-pi-args.d.ts +0 -105
- package/dist/types/providers/cursor.d.ts +0 -221
- package/dist/types/providers/devin.d.ts +0 -12
- package/dist/types/providers/error-message.d.ts +0 -25
- package/dist/types/providers/github-copilot-headers.d.ts +0 -40
- package/dist/types/providers/gitlab-duo-workflow.d.ts +0 -254
- package/dist/types/providers/gitlab-duo.d.ts +0 -27
- package/dist/types/providers/google-auth.d.ts +0 -24
- package/dist/types/providers/google-gemini-cli.d.ts +0 -120
- package/dist/types/providers/google-shared.d.ts +0 -203
- package/dist/types/providers/google-types.d.ts +0 -155
- package/dist/types/providers/google-vertex.d.ts +0 -7
- package/dist/types/providers/google.d.ts +0 -4
- package/dist/types/providers/grammar.d.ts +0 -1
- package/dist/types/providers/kimi.d.ts +0 -27
- package/dist/types/providers/mock.d.ts +0 -179
- package/dist/types/providers/ollama.d.ts +0 -8
- package/dist/types/providers/openai-anthropic-shim.d.ts +0 -35
- package/dist/types/providers/openai-chat-server-schema.d.ts +0 -1311
- package/dist/types/providers/openai-chat-server.d.ts +0 -16
- package/dist/types/providers/openai-chat-wire.d.ts +0 -669
- package/dist/types/providers/openai-codex/request-transformer.d.ts +0 -109
- package/dist/types/providers/openai-codex/response-handler.d.ts +0 -26
- package/dist/types/providers/openai-codex-responses.d.ts +0 -238
- package/dist/types/providers/openai-completions.d.ts +0 -48
- package/dist/types/providers/openai-reasoning-fallback.d.ts +0 -25
- package/dist/types/providers/openai-responses-server-schema.d.ts +0 -1314
- package/dist/types/providers/openai-responses-server.d.ts +0 -17
- package/dist/types/providers/openai-responses-wire.d.ts +0 -6099
- package/dist/types/providers/openai-responses.d.ts +0 -131
- package/dist/types/providers/openai-shared.d.ts +0 -624
- package/dist/types/providers/pi-native-client.d.ts +0 -13
- package/dist/types/providers/pi-native-server.d.ts +0 -69
- package/dist/types/providers/register-builtins.d.ts +0 -37
- package/dist/types/providers/synthetic.d.ts +0 -26
- package/dist/types/providers/transform-messages.d.ts +0 -32
- package/dist/types/providers/vision-guard.d.ts +0 -20
- package/dist/types/registry/aiand.d.ts +0 -7
- package/dist/types/registry/aimlapi.d.ts +0 -4
- package/dist/types/registry/alibaba-coding-plan.d.ts +0 -8
- package/dist/types/registry/alibaba-token-plan.d.ts +0 -18
- package/dist/types/registry/amazon-bedrock.d.ts +0 -5
- package/dist/types/registry/anthropic.d.ts +0 -10
- package/dist/types/registry/api-key-login.d.ts +0 -42
- package/dist/types/registry/api-key-validation.d.ts +0 -43
- package/dist/types/registry/aws.d.ts +0 -13
- package/dist/types/registry/azure.d.ts +0 -4
- package/dist/types/registry/baseten.d.ts +0 -7
- package/dist/types/registry/bedrock-mantle.d.ts +0 -22
- package/dist/types/registry/cerebras.d.ts +0 -7
- package/dist/types/registry/cloudflare-ai-gateway.d.ts +0 -13
- package/dist/types/registry/coreweave.d.ts +0 -7
- package/dist/types/registry/cursor.d.ts +0 -7
- package/dist/types/registry/deepseek.d.ts +0 -8
- package/dist/types/registry/derived.d.ts +0 -5
- package/dist/types/registry/devin.d.ts +0 -8
- package/dist/types/registry/exa.d.ts +0 -8
- package/dist/types/registry/firepass.d.ts +0 -16
- package/dist/types/registry/fireworks.d.ts +0 -7
- package/dist/types/registry/github-copilot.d.ts +0 -7
- package/dist/types/registry/gitlab-duo-workflow.d.ts +0 -10
- package/dist/types/registry/gitlab-duo.d.ts +0 -9
- package/dist/types/registry/gmi-cloud.d.ts +0 -7
- package/dist/types/registry/google-antigravity.d.ts +0 -9
- package/dist/types/registry/google-gemini-cli.d.ts +0 -9
- package/dist/types/registry/google-vertex.d.ts +0 -5
- package/dist/types/registry/google.d.ts +0 -4
- package/dist/types/registry/groq.d.ts +0 -4
- package/dist/types/registry/huggingface.d.ts +0 -7
- package/dist/types/registry/index.d.ts +0 -4
- package/dist/types/registry/kagi.d.ts +0 -14
- package/dist/types/registry/kilo.d.ts +0 -7
- package/dist/types/registry/kimi-code.d.ts +0 -7
- package/dist/types/registry/litellm.d.ts +0 -13
- package/dist/types/registry/llama-cpp.d.ts +0 -8
- package/dist/types/registry/lm-studio.d.ts +0 -8
- package/dist/types/registry/meta.d.ts +0 -7
- package/dist/types/registry/minimax-code-cn.d.ts +0 -6
- package/dist/types/registry/minimax-code.d.ts +0 -6
- package/dist/types/registry/minimax.d.ts +0 -4
- package/dist/types/registry/mistral.d.ts +0 -4
- package/dist/types/registry/moonshot.d.ts +0 -7
- package/dist/types/registry/nanogpt.d.ts +0 -7
- package/dist/types/registry/novita.d.ts +0 -6
- package/dist/types/registry/nvidia.d.ts +0 -7
- package/dist/types/registry/oauth/anthropic-constants.d.ts +0 -12
- package/dist/types/registry/oauth/anthropic.d.ts +0 -24
- package/dist/types/registry/oauth/callback-server.d.ts +0 -74
- package/dist/types/registry/oauth/cursor.d.ts +0 -16
- package/dist/types/registry/oauth/device-code.d.ts +0 -25
- package/dist/types/registry/oauth/devin.d.ts +0 -5
- package/dist/types/registry/oauth/github-copilot.d.ts +0 -30
- package/dist/types/registry/oauth/gitlab-duo-workflow.d.ts +0 -6
- package/dist/types/registry/oauth/gitlab-duo.d.ts +0 -3
- package/dist/types/registry/oauth/google-antigravity.d.ts +0 -11
- package/dist/types/registry/oauth/google-gemini-cli.d.ts +0 -22
- package/dist/types/registry/oauth/google-oauth-shared.d.ts +0 -56
- package/dist/types/registry/oauth/index.d.ts +0 -45
- package/dist/types/registry/oauth/kimi.d.ts +0 -21
- package/dist/types/registry/oauth/minimax-code.d.ts +0 -27
- package/dist/types/registry/oauth/openai-codex.d.ts +0 -33
- package/dist/types/registry/oauth/opencode.d.ts +0 -18
- package/dist/types/registry/oauth/perplexity.d.ts +0 -9
- package/dist/types/registry/oauth/pkce.d.ts +0 -8
- package/dist/types/registry/oauth/types.d.ts +0 -87
- package/dist/types/registry/oauth/wafer.d.ts +0 -1
- package/dist/types/registry/oauth/xai-oauth.d.ts +0 -46
- package/dist/types/registry/oauth/xiaomi.d.ts +0 -25
- package/dist/types/registry/oauth/zai.d.ts +0 -25
- package/dist/types/registry/ollama-cloud.d.ts +0 -7
- package/dist/types/registry/ollama.d.ts +0 -12
- package/dist/types/registry/openai-codex-device.d.ts +0 -8
- package/dist/types/registry/openai-codex.d.ts +0 -9
- package/dist/types/registry/openai.d.ts +0 -4
- package/dist/types/registry/opencode-go.d.ts +0 -6
- package/dist/types/registry/opencode-zen.d.ts +0 -6
- package/dist/types/registry/openrouter.d.ts +0 -13
- package/dist/types/registry/parallel.d.ts +0 -14
- package/dist/types/registry/perplexity.d.ts +0 -7
- package/dist/types/registry/qianfan.d.ts +0 -7
- package/dist/types/registry/qwen-portal.d.ts +0 -7
- package/dist/types/registry/registry.d.ts +0 -367
- package/dist/types/registry/sakana.d.ts +0 -7
- package/dist/types/registry/siliconflow-cn.d.ts +0 -7
- package/dist/types/registry/siliconflow.d.ts +0 -7
- package/dist/types/registry/synthetic.d.ts +0 -6
- package/dist/types/registry/tavily.d.ts +0 -14
- package/dist/types/registry/together.d.ts +0 -6
- package/dist/types/registry/types.d.ts +0 -75
- package/dist/types/registry/umans.d.ts +0 -7
- package/dist/types/registry/venice.d.ts +0 -13
- package/dist/types/registry/vercel-ai-gateway.d.ts +0 -7
- package/dist/types/registry/vllm.d.ts +0 -7
- package/dist/types/registry/wafer-serverless.d.ts +0 -6
- package/dist/types/registry/xai-oauth.d.ts +0 -7
- package/dist/types/registry/xai.d.ts +0 -7
- package/dist/types/registry/xiaomi-token-plan-ams.d.ts +0 -6
- package/dist/types/registry/xiaomi-token-plan-cn.d.ts +0 -6
- package/dist/types/registry/xiaomi-token-plan-sgp.d.ts +0 -6
- package/dist/types/registry/xiaomi.d.ts +0 -6
- package/dist/types/registry/zai.d.ts +0 -15
- package/dist/types/registry/zenmux.d.ts +0 -7
- package/dist/types/registry/zhipu-coding-plan.d.ts +0 -7
- package/dist/types/stream.d.ts +0 -46
- package/dist/types/types.d.ts +0 -1064
- package/dist/types/usage/alibaba-token-plan.d.ts +0 -3
- package/dist/types/usage/claude.d.ts +0 -4
- package/dist/types/usage/cursor.d.ts +0 -4
- package/dist/types/usage/gemini.d.ts +0 -2
- package/dist/types/usage/github-copilot.d.ts +0 -7
- package/dist/types/usage/google-antigravity.d.ts +0 -15
- package/dist/types/usage/kimi.d.ts +0 -2
- package/dist/types/usage/minimax-code.d.ts +0 -3
- package/dist/types/usage/ollama.d.ts +0 -5
- package/dist/types/usage/openai-codex-base-url.d.ts +0 -18
- package/dist/types/usage/openai-codex-reset.d.ts +0 -88
- package/dist/types/usage/openai-codex.d.ts +0 -10
- package/dist/types/usage/opencode-go.d.ts +0 -2
- package/dist/types/usage/shared.d.ts +0 -1
- package/dist/types/usage/synthetic.d.ts +0 -2
- package/dist/types/usage/umans.d.ts +0 -2
- package/dist/types/usage/xai-oauth.d.ts +0 -12
- package/dist/types/usage/zai.d.ts +0 -3
- package/dist/types/usage.d.ts +0 -527
- package/dist/types/utils/abort.d.ts +0 -25
- package/dist/types/utils/anthropic-auth.d.ts +0 -35
- package/dist/types/utils/aws-profile.d.ts +0 -17
- package/dist/types/utils/block-symbols.d.ts +0 -62
- package/dist/types/utils/deterministic-id.d.ts +0 -16
- package/dist/types/utils/empty-completion-retry.d.ts +0 -21
- package/dist/types/utils/event-stream.d.ts +0 -39
- package/dist/types/utils/foundry.d.ts +0 -1
- package/dist/types/utils/google-validation.d.ts +0 -2
- package/dist/types/utils/harmony-leak.d.ts +0 -135
- package/dist/types/utils/http-inspector.d.ts +0 -49
- package/dist/types/utils/idle-iterator.d.ts +0 -149
- package/dist/types/utils/leaked-thinking-stream.d.ts +0 -33
- package/dist/types/utils/openai-http.d.ts +0 -48
- package/dist/types/utils/openrouter-headers.d.ts +0 -1
- package/dist/types/utils/parse-bind.d.ts +0 -23
- package/dist/types/utils/provider-response.d.ts +0 -3
- package/dist/types/utils/proxy.d.ts +0 -39
- package/dist/types/utils/request-debug.d.ts +0 -29
- package/dist/types/utils/retry-after.d.ts +0 -4
- package/dist/types/utils/retry.d.ts +0 -14
- package/dist/types/utils/schema/adapt.d.ts +0 -24
- package/dist/types/utils/schema/compatibility.d.ts +0 -30
- package/dist/types/utils/schema/dereference.d.ts +0 -11
- package/dist/types/utils/schema/draft.d.ts +0 -10
- package/dist/types/utils/schema/equality.d.ts +0 -4
- package/dist/types/utils/schema/fields.d.ts +0 -54
- package/dist/types/utils/schema/index.d.ts +0 -14
- package/dist/types/utils/schema/json-schema-validator.d.ts +0 -20
- package/dist/types/utils/schema/meta-validator.d.ts +0 -2
- package/dist/types/utils/schema/normalize.d.ts +0 -153
- package/dist/types/utils/schema/spill.d.ts +0 -8
- package/dist/types/utils/schema/stamps.d.ts +0 -17
- package/dist/types/utils/schema/strict-tool-validation.d.ts +0 -16
- package/dist/types/utils/schema/types.d.ts +0 -4
- package/dist/types/utils/schema/typescript.d.ts +0 -24
- package/dist/types/utils/schema/wire.d.ts +0 -52
- package/dist/types/utils/sdk-stream-timeout.d.ts +0 -33
- package/dist/types/utils/sse-debug.d.ts +0 -5
- package/dist/types/utils/stream-markup-healing.d.ts +0 -87
- package/dist/types/utils/thinking-loop.d.ts +0 -102
- package/dist/types/utils/tool-call-loop-guard.d.ts +0 -26
- package/dist/types/utils/tool-choice.d.ts +0 -52
- package/dist/types/utils/validation.d.ts +0 -28
- package/dist/types/utils.d.ts +0 -57
package/package.json
CHANGED
|
@@ -1,138 +1,137 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
2
|
+
"type": "module",
|
|
3
|
+
"name": "@linxiraos/pi-ai",
|
|
4
|
+
"version": "1.0.2",
|
|
5
|
+
"description": "Unified LLM API with automatic model discovery and provider configuration",
|
|
6
|
+
"homepage": "https://linxira-os.github.io",
|
|
7
|
+
"author": "Can Boluk",
|
|
8
|
+
"contributors": [
|
|
9
|
+
"Mario Zechner"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/Linxira-OS/linxira-zeta.git",
|
|
15
|
+
"directory": "packages/ai"
|
|
16
|
+
},
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/can1357/oh-my-pi/issues"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"ai",
|
|
22
|
+
"llm",
|
|
23
|
+
"openai",
|
|
24
|
+
"anthropic",
|
|
25
|
+
"gemini",
|
|
26
|
+
"unified",
|
|
27
|
+
"api"
|
|
28
|
+
],
|
|
29
|
+
"main": "./src/index.ts",
|
|
30
|
+
"types": "./src/index.ts",
|
|
31
|
+
"scripts": {
|
|
32
|
+
"check": "biome check . && bun run check:types",
|
|
33
|
+
"check:types": "tsgo -p tsconfig.json --noEmit",
|
|
34
|
+
"lint": "biome lint .",
|
|
35
|
+
"test": "bun test --parallel",
|
|
36
|
+
"fix": "biome check --write --unsafe .",
|
|
37
|
+
"fmt": "biome format --write ."
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@bufbuild/protobuf": "catalog:",
|
|
41
|
+
"@linxiraos/pi-omptype": "catalog:",
|
|
42
|
+
"@linxiraos/pi-catalog": "catalog:",
|
|
43
|
+
"@linxiraos/pi-utils": "catalog:",
|
|
44
|
+
"@linxiraos/pi-wire": "catalog:"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@bufbuild/protoc-gen-es": "catalog:",
|
|
48
|
+
"@types/bun": "catalog:"
|
|
49
|
+
},
|
|
50
|
+
"engines": {
|
|
51
|
+
"bun": ">=1.3.14"
|
|
52
|
+
},
|
|
53
|
+
"files": [
|
|
54
|
+
"src",
|
|
55
|
+
"README.md",
|
|
56
|
+
"CHANGELOG.md"
|
|
57
|
+
],
|
|
58
|
+
"exports": {
|
|
59
|
+
".": {
|
|
60
|
+
"types": "./src/index.ts",
|
|
61
|
+
"import": "./src/index.ts"
|
|
62
|
+
},
|
|
63
|
+
"./error": {
|
|
64
|
+
"types": "./src/error/index.ts",
|
|
65
|
+
"import": "./src/error/index.ts"
|
|
66
|
+
},
|
|
67
|
+
"./*": {
|
|
68
|
+
"types": "./src/*.ts",
|
|
69
|
+
"import": "./src/*.ts"
|
|
70
|
+
},
|
|
71
|
+
"./auth-broker": {
|
|
72
|
+
"types": "./src/auth-broker/index.ts",
|
|
73
|
+
"import": "./src/auth-broker/index.ts"
|
|
74
|
+
},
|
|
75
|
+
"./auth-broker/*": {
|
|
76
|
+
"types": "./src/auth-broker/*.ts",
|
|
77
|
+
"import": "./src/auth-broker/*.ts"
|
|
78
|
+
},
|
|
79
|
+
"./auth-gateway": {
|
|
80
|
+
"types": "./src/auth-gateway/index.ts",
|
|
81
|
+
"import": "./src/auth-gateway/index.ts"
|
|
82
|
+
},
|
|
83
|
+
"./auth-gateway/*": {
|
|
84
|
+
"types": "./src/auth-gateway/*.ts",
|
|
85
|
+
"import": "./src/auth-gateway/*.ts"
|
|
86
|
+
},
|
|
87
|
+
"./providers/*": {
|
|
88
|
+
"types": "./src/providers/*.ts",
|
|
89
|
+
"import": "./src/providers/*.ts"
|
|
90
|
+
},
|
|
91
|
+
"./providers/openai-codex/*": {
|
|
92
|
+
"types": "./src/providers/openai-codex/*.ts",
|
|
93
|
+
"import": "./src/providers/openai-codex/*.ts"
|
|
94
|
+
},
|
|
95
|
+
"./usage/*": {
|
|
96
|
+
"types": "./src/usage/*.ts",
|
|
97
|
+
"import": "./src/usage/*.ts"
|
|
98
|
+
},
|
|
99
|
+
"./utils/harmony-leak": {
|
|
100
|
+
"types": "./src/utils/harmony-leak.ts",
|
|
101
|
+
"import": "./src/utils/harmony-leak.ts"
|
|
102
|
+
},
|
|
103
|
+
"./dialect": {
|
|
104
|
+
"types": "./src/dialect/index.ts",
|
|
105
|
+
"import": "./src/dialect/index.ts"
|
|
106
|
+
},
|
|
107
|
+
"./utils/*": {
|
|
108
|
+
"types": "./src/utils/*.ts",
|
|
109
|
+
"import": "./src/utils/*.ts"
|
|
110
|
+
},
|
|
111
|
+
"./oauth": {
|
|
112
|
+
"types": "./src/registry/oauth/index.ts",
|
|
113
|
+
"import": "./src/registry/oauth/index.ts"
|
|
114
|
+
},
|
|
115
|
+
"./oauth/*": {
|
|
116
|
+
"types": "./src/registry/oauth/*.ts",
|
|
117
|
+
"import": "./src/registry/oauth/*.ts"
|
|
118
|
+
},
|
|
119
|
+
"./registry": {
|
|
120
|
+
"types": "./src/registry/index.ts",
|
|
121
|
+
"import": "./src/registry/index.ts"
|
|
122
|
+
},
|
|
123
|
+
"./registry/oauth": {
|
|
124
|
+
"types": "./src/registry/oauth/index.ts",
|
|
125
|
+
"import": "./src/registry/oauth/index.ts"
|
|
126
|
+
},
|
|
127
|
+
"./utils/schema": {
|
|
128
|
+
"types": "./src/utils/schema/index.ts",
|
|
129
|
+
"import": "./src/utils/schema/index.ts"
|
|
130
|
+
},
|
|
131
|
+
"./utils/schema/*": {
|
|
132
|
+
"types": "./src/utils/schema/*.ts",
|
|
133
|
+
"import": "./src/utils/schema/*.ts"
|
|
134
|
+
},
|
|
135
|
+
"./*.js": "./src/*.ts"
|
|
136
|
+
}
|
|
138
137
|
}
|
|
@@ -25,8 +25,6 @@ import type {
|
|
|
25
25
|
ClientProviderUsage,
|
|
26
26
|
ClientUsageReport,
|
|
27
27
|
ClientUsageSummary,
|
|
28
|
-
UsageCostHistoryEntry,
|
|
29
|
-
UsageCostHistoryQuery,
|
|
30
28
|
UsageHistoryEntry,
|
|
31
29
|
UsageHistoryQuery,
|
|
32
30
|
} from "../usage";
|
|
@@ -387,8 +385,6 @@ export class SqliteAuthCredentialStore implements AuthCredentialStore {
|
|
|
387
385
|
#releaseCredentialRefreshLeaseStmt: Statement;
|
|
388
386
|
#credentialBlockReconcileAfter: Map<string, number> = new Map();
|
|
389
387
|
#insertUsageHistoryStmt: Statement;
|
|
390
|
-
#insertUsageCostStmt: Statement;
|
|
391
|
-
#listUsageCostsStmt: Statement;
|
|
392
388
|
#lastUsageHistoryStmt: Statement;
|
|
393
389
|
#listUsageHistoryStmt: Statement;
|
|
394
390
|
#updateUsageHistoryStmt: Statement;
|
|
@@ -516,12 +512,6 @@ export class SqliteAuthCredentialStore implements AuthCredentialStore {
|
|
|
516
512
|
this.#listUsageHistoryStmt = this.#db.prepare(
|
|
517
513
|
"SELECT recorded_at, provider, account_key, email, account_id, limit_id, label, window_label, used_fraction, status, resets_at FROM usage_history WHERE recorded_at >= ? AND (? IS NULL OR provider = ?) ORDER BY recorded_at ASC",
|
|
518
514
|
);
|
|
519
|
-
this.#insertUsageCostStmt = this.#db.prepare(
|
|
520
|
-
"INSERT INTO usage_cost_history (recorded_at, provider, account_key, cost_usd) VALUES (?, ?, ?, ?)",
|
|
521
|
-
);
|
|
522
|
-
this.#listUsageCostsStmt = this.#db.prepare(
|
|
523
|
-
"SELECT recorded_at, provider, account_key, cost_usd FROM usage_cost_history WHERE recorded_at >= ? AND (? IS NULL OR provider = ?) AND (? IS NULL OR account_key = ?) ORDER BY recorded_at ASC",
|
|
524
|
-
);
|
|
525
515
|
}
|
|
526
516
|
|
|
527
517
|
static async open(dbPath: string = getAgentDbPath()): Promise<SqliteAuthCredentialStore> {
|
|
@@ -634,14 +624,6 @@ export class SqliteAuthCredentialStore implements AuthCredentialStore {
|
|
|
634
624
|
resets_at INTEGER
|
|
635
625
|
);
|
|
636
626
|
CREATE INDEX IF NOT EXISTS idx_usage_history_series ON usage_history(provider, account_key, limit_id, recorded_at);
|
|
637
|
-
CREATE TABLE IF NOT EXISTS usage_cost_history (
|
|
638
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
639
|
-
recorded_at INTEGER NOT NULL,
|
|
640
|
-
provider TEXT NOT NULL,
|
|
641
|
-
account_key TEXT NOT NULL,
|
|
642
|
-
cost_usd REAL NOT NULL
|
|
643
|
-
);
|
|
644
|
-
CREATE INDEX IF NOT EXISTS idx_usage_cost_history_lookup ON usage_cost_history(provider, account_key, recorded_at);
|
|
645
627
|
CREATE INDEX IF NOT EXISTS idx_usage_history_recorded ON usage_history(recorded_at);
|
|
646
628
|
CREATE TABLE IF NOT EXISTS clients (
|
|
647
629
|
install_id TEXT PRIMARY KEY,
|
|
@@ -1769,42 +1751,6 @@ export class SqliteAuthCredentialStore implements AuthCredentialStore {
|
|
|
1769
1751
|
return [];
|
|
1770
1752
|
}
|
|
1771
1753
|
}
|
|
1772
|
-
recordUsageCosts(entries: UsageCostHistoryEntry[]): void {
|
|
1773
|
-
try {
|
|
1774
|
-
for (const entry of entries) {
|
|
1775
|
-
this.#insertUsageCostStmt.run(entry.recordedAt, entry.provider, entry.accountKey, entry.costUsd);
|
|
1776
|
-
}
|
|
1777
|
-
} catch {
|
|
1778
|
-
// Cost history is best-effort; never break request persistence.
|
|
1779
|
-
}
|
|
1780
|
-
}
|
|
1781
|
-
|
|
1782
|
-
listUsageCosts(query?: UsageCostHistoryQuery): UsageCostHistoryEntry[] {
|
|
1783
|
-
try {
|
|
1784
|
-
const provider = query?.provider ?? null;
|
|
1785
|
-
const accountKey = query?.accountKey ?? null;
|
|
1786
|
-
const rows = this.#listUsageCostsStmt.all(
|
|
1787
|
-
query?.sinceMs ?? 0,
|
|
1788
|
-
provider,
|
|
1789
|
-
provider,
|
|
1790
|
-
accountKey,
|
|
1791
|
-
accountKey,
|
|
1792
|
-
) as Array<{
|
|
1793
|
-
recorded_at: number;
|
|
1794
|
-
provider: string;
|
|
1795
|
-
account_key: string;
|
|
1796
|
-
cost_usd: number;
|
|
1797
|
-
}>;
|
|
1798
|
-
return rows.map(row => ({
|
|
1799
|
-
recordedAt: row.recorded_at,
|
|
1800
|
-
provider: row.provider as Provider,
|
|
1801
|
-
accountKey: row.account_key,
|
|
1802
|
-
costUsd: row.cost_usd,
|
|
1803
|
-
}));
|
|
1804
|
-
} catch {
|
|
1805
|
-
return [];
|
|
1806
|
-
}
|
|
1807
|
-
}
|
|
1808
1754
|
|
|
1809
1755
|
recordClientUsage(report: ClientUsageReport): void {
|
|
1810
1756
|
const now = Date.now();
|
|
@@ -2051,8 +1997,6 @@ export class SqliteAuthCredentialStore implements AuthCredentialStore {
|
|
|
2051
1997
|
this.#lastUsageHistoryStmt.finalize();
|
|
2052
1998
|
this.#listUsageHistoryStmt.finalize();
|
|
2053
1999
|
this.#updateUsageHistoryStmt.finalize();
|
|
2054
|
-
this.#insertUsageCostStmt.finalize();
|
|
2055
|
-
this.#listUsageCostsStmt.finalize();
|
|
2056
2000
|
this.#updateIfMatchesStmt.finalize();
|
|
2057
2001
|
this.#updateIfMatchesWithLeaseStmt.finalize();
|
|
2058
2002
|
this.#deleteIfMatchesWithLeaseStmt.finalize();
|
package/src/auth-retry.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { extractHttpStatusFromError } from "@linxiraos/pi-utils";
|
|
|
2
2
|
import type { OAuthAccess } from "./auth-storage";
|
|
3
3
|
import * as AIError from "./error";
|
|
4
4
|
import { isAuthRetryableError, isInvalidatedOAuthTokenError } from "./error/auth-classify";
|
|
5
|
-
import { isUsageLimit } from "./error/flags";
|
|
5
|
+
import { isAccountPolicyError, isUsageLimit } from "./error/flags";
|
|
6
6
|
import { isConcurrencyCapExclusion, isUsageLimitOutcome } from "./error/rate-limit";
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -19,9 +19,9 @@ import { isConcurrencyCapExclusion, isUsageLimitOutcome } from "./error/rate-lim
|
|
|
19
19
|
* (invalidate/usage-limit the current credential and rotate to a sibling).
|
|
20
20
|
*
|
|
21
21
|
* Current drivers preserve that bounded a/b/c sequence for ordinary 401/auth
|
|
22
|
-
* failures.
|
|
23
|
-
* until the resolver returns `undefined`,
|
|
24
|
-
* {@link AUTH_RETRY_MAX_ATTEMPTS}.
|
|
22
|
+
* failures. Account-scoped policy denials, 403s, and usage-limit failures skip
|
|
23
|
+
* refresh and may repeat step (c) until the resolver returns `undefined`,
|
|
24
|
+
* cycles, or hits {@link AUTH_RETRY_MAX_ATTEMPTS}.
|
|
25
25
|
*/
|
|
26
26
|
export interface ApiKeyResolveContext {
|
|
27
27
|
/** True when the resolver should rotate to a sibling credential. */
|
|
@@ -91,6 +91,7 @@ export const AUTH_RETRY_STEPS: readonly boolean[] = [false, true];
|
|
|
91
91
|
export const AUTH_RETRY_MAX_ATTEMPTS = 64;
|
|
92
92
|
|
|
93
93
|
function isDirectCredentialRotationError(error: unknown): boolean {
|
|
94
|
+
if (isAccountPolicyError(error)) return true;
|
|
94
95
|
if (isUsageLimit(error) || isInvalidatedOAuthTokenError(error)) return true;
|
|
95
96
|
const status = AIError.status(error);
|
|
96
97
|
const message = error instanceof Error ? error.message : typeof error === "string" ? error : undefined;
|