@f5-sales-demo/pi-ai 19.51.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 +1997 -0
- package/README.md +1160 -0
- package/package.json +135 -0
- package/src/api-registry.ts +95 -0
- package/src/auth-storage.ts +2694 -0
- package/src/cli.ts +493 -0
- package/src/index.ts +42 -0
- package/src/model-cache.ts +97 -0
- package/src/model-manager.ts +349 -0
- package/src/model-thinking.ts +561 -0
- package/src/models.json +49439 -0
- package/src/models.json.d.ts +9 -0
- package/src/models.ts +56 -0
- package/src/prompts/turn-aborted-guidance.md +4 -0
- package/src/provider-details.ts +81 -0
- package/src/provider-models/descriptors.ts +285 -0
- package/src/provider-models/google.ts +90 -0
- package/src/provider-models/index.ts +4 -0
- package/src/provider-models/openai-compat.ts +2074 -0
- package/src/provider-models/special.ts +106 -0
- package/src/providers/amazon-bedrock.ts +706 -0
- package/src/providers/anthropic.ts +1682 -0
- package/src/providers/azure-openai-responses.ts +391 -0
- package/src/providers/cursor/gen/agent_pb.ts +15274 -0
- package/src/providers/cursor/proto/agent.proto +3526 -0
- package/src/providers/cursor/proto/buf.gen.yaml +6 -0
- package/src/providers/cursor/proto/buf.yaml +17 -0
- package/src/providers/cursor.ts +2218 -0
- package/src/providers/github-copilot-headers.ts +140 -0
- package/src/providers/gitlab-duo.ts +381 -0
- package/src/providers/google-gemini-cli.ts +1133 -0
- package/src/providers/google-shared.ts +354 -0
- package/src/providers/google-vertex.ts +436 -0
- package/src/providers/google.ts +381 -0
- package/src/providers/kimi.ts +151 -0
- package/src/providers/openai-codex/constants.ts +43 -0
- package/src/providers/openai-codex/request-transformer.ts +158 -0
- package/src/providers/openai-codex/response-handler.ts +81 -0
- package/src/providers/openai-codex-responses.ts +2345 -0
- package/src/providers/openai-completions-compat.ts +159 -0
- package/src/providers/openai-completions.ts +1290 -0
- package/src/providers/openai-responses-shared.ts +452 -0
- package/src/providers/openai-responses.ts +519 -0
- package/src/providers/register-builtins.ts +329 -0
- package/src/providers/synthetic.ts +154 -0
- package/src/providers/transform-messages.ts +234 -0
- package/src/rate-limit-utils.ts +84 -0
- package/src/stream.ts +728 -0
- package/src/types.ts +546 -0
- package/src/usage/claude.ts +337 -0
- package/src/usage/gemini.ts +248 -0
- package/src/usage/github-copilot.ts +421 -0
- package/src/usage/google-antigravity.ts +200 -0
- package/src/usage/kimi.ts +286 -0
- package/src/usage/minimax-code.ts +31 -0
- package/src/usage/openai-codex.ts +387 -0
- package/src/usage/zai.ts +247 -0
- package/src/usage.ts +130 -0
- package/src/utils/abort.ts +36 -0
- package/src/utils/anthropic-auth.ts +293 -0
- package/src/utils/discovery/antigravity.ts +261 -0
- package/src/utils/discovery/codex.ts +371 -0
- package/src/utils/discovery/cursor.ts +306 -0
- package/src/utils/discovery/gemini.ts +248 -0
- package/src/utils/discovery/index.ts +5 -0
- package/src/utils/discovery/openai-compatible.ts +224 -0
- package/src/utils/event-stream.ts +209 -0
- package/src/utils/http-inspector.ts +165 -0
- package/src/utils/idle-iterator.ts +176 -0
- package/src/utils/json-parse.ts +28 -0
- package/src/utils/oauth/alibaba-coding-plan.ts +59 -0
- package/src/utils/oauth/anthropic.ts +134 -0
- package/src/utils/oauth/api-key-validation.ts +92 -0
- package/src/utils/oauth/callback-server.ts +276 -0
- package/src/utils/oauth/cerebras.ts +59 -0
- package/src/utils/oauth/cloudflare-ai-gateway.ts +48 -0
- package/src/utils/oauth/cursor.ts +157 -0
- package/src/utils/oauth/github-copilot.ts +358 -0
- package/src/utils/oauth/gitlab-duo.ts +123 -0
- package/src/utils/oauth/google-antigravity.ts +275 -0
- package/src/utils/oauth/google-gemini-cli.ts +334 -0
- package/src/utils/oauth/huggingface.ts +62 -0
- package/src/utils/oauth/index.ts +512 -0
- package/src/utils/oauth/kagi.ts +47 -0
- package/src/utils/oauth/kilo.ts +87 -0
- package/src/utils/oauth/kimi.ts +251 -0
- package/src/utils/oauth/litellm.ts +81 -0
- package/src/utils/oauth/lm-studio.ts +40 -0
- package/src/utils/oauth/minimax-code.ts +78 -0
- package/src/utils/oauth/moonshot.ts +59 -0
- package/src/utils/oauth/nanogpt.ts +51 -0
- package/src/utils/oauth/nvidia.ts +70 -0
- package/src/utils/oauth/oauth.html +199 -0
- package/src/utils/oauth/ollama.ts +47 -0
- package/src/utils/oauth/openai-codex.ts +190 -0
- package/src/utils/oauth/opencode.ts +49 -0
- package/src/utils/oauth/parallel.ts +46 -0
- package/src/utils/oauth/perplexity.ts +200 -0
- package/src/utils/oauth/pkce.ts +18 -0
- package/src/utils/oauth/qianfan.ts +58 -0
- package/src/utils/oauth/qwen-portal.ts +60 -0
- package/src/utils/oauth/synthetic.ts +60 -0
- package/src/utils/oauth/tavily.ts +46 -0
- package/src/utils/oauth/together.ts +59 -0
- package/src/utils/oauth/types.ts +89 -0
- package/src/utils/oauth/venice.ts +59 -0
- package/src/utils/oauth/vercel-ai-gateway.ts +47 -0
- package/src/utils/oauth/vllm.ts +40 -0
- package/src/utils/oauth/xiaomi.ts +88 -0
- package/src/utils/oauth/zai.ts +60 -0
- package/src/utils/oauth/zenmux.ts +51 -0
- package/src/utils/overflow.ts +134 -0
- package/src/utils/retry-after.ts +110 -0
- package/src/utils/retry.ts +93 -0
- package/src/utils/schema/CONSTRAINTS.md +160 -0
- package/src/utils/schema/adapt.ts +20 -0
- package/src/utils/schema/compatibility.ts +397 -0
- package/src/utils/schema/dereference.ts +93 -0
- package/src/utils/schema/equality.ts +93 -0
- package/src/utils/schema/fields.ts +147 -0
- package/src/utils/schema/index.ts +9 -0
- package/src/utils/schema/normalize-cca.ts +479 -0
- package/src/utils/schema/sanitize-google.ts +212 -0
- package/src/utils/schema/strict-mode.ts +385 -0
- package/src/utils/schema/types.ts +5 -0
- package/src/utils/tool-choice.ts +81 -0
- package/src/utils/validation.ts +664 -0
- package/src/utils.ts +147 -0
package/package.json
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "module",
|
|
3
|
+
"name": "@f5-sales-demo/pi-ai",
|
|
4
|
+
"version": "19.51.2",
|
|
5
|
+
"description": "Unified LLM API with automatic model discovery and provider configuration",
|
|
6
|
+
"homepage": "https://github.com/f5-sales-demo/xcsh",
|
|
7
|
+
"author": "Can Boluk",
|
|
8
|
+
"contributors": [
|
|
9
|
+
"Mario Zechner"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/f5-sales-demo/xcsh.git",
|
|
15
|
+
"directory": "packages/ai"
|
|
16
|
+
},
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/f5-sales-demo/xcsh/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
|
+
"bin": {
|
|
32
|
+
"pi-ai": "./src/cli.ts"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"check": "biome check . && bun run check:types",
|
|
36
|
+
"check:types": "tsgo -p tsconfig.json --noEmit",
|
|
37
|
+
"lint": "biome lint .",
|
|
38
|
+
"test": "bun test",
|
|
39
|
+
"fix": "biome check --write --unsafe .",
|
|
40
|
+
"fmt": "biome format --write .",
|
|
41
|
+
"generate-models": "bun scripts/generate-models.ts"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@anthropic-ai/sdk": "^0.78",
|
|
45
|
+
"@aws-sdk/client-bedrock-runtime": "^3",
|
|
46
|
+
"@bufbuild/protobuf": "^2.11",
|
|
47
|
+
"@google/genai": "^1.43",
|
|
48
|
+
"@f5-sales-demo/pi-utils": "workspace:*",
|
|
49
|
+
"@sinclair/typebox": "^0.34",
|
|
50
|
+
"@smithy/node-http-handler": "^4.4",
|
|
51
|
+
"ajv": "^8.20",
|
|
52
|
+
"ajv-formats": "^3.0",
|
|
53
|
+
"openai": "^6.25",
|
|
54
|
+
"partial-json": "^0.1",
|
|
55
|
+
"zod": "^4.3"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@types/bun": "^1.3"
|
|
59
|
+
},
|
|
60
|
+
"engines": {
|
|
61
|
+
"bun": ">=1.3.7"
|
|
62
|
+
},
|
|
63
|
+
"files": [
|
|
64
|
+
"src",
|
|
65
|
+
"README.md",
|
|
66
|
+
"CHANGELOG.md"
|
|
67
|
+
],
|
|
68
|
+
"exports": {
|
|
69
|
+
".": {
|
|
70
|
+
"types": "./src/index.ts",
|
|
71
|
+
"import": "./src/index.ts"
|
|
72
|
+
},
|
|
73
|
+
"./*": {
|
|
74
|
+
"types": "./src/*.ts",
|
|
75
|
+
"import": "./src/*.ts"
|
|
76
|
+
},
|
|
77
|
+
"./models.json": {
|
|
78
|
+
"types": "./src/models.json.d.ts",
|
|
79
|
+
"import": "./src/models.json"
|
|
80
|
+
},
|
|
81
|
+
"./provider-models": {
|
|
82
|
+
"types": "./src/provider-models/index.ts",
|
|
83
|
+
"import": "./src/provider-models/index.ts"
|
|
84
|
+
},
|
|
85
|
+
"./provider-models/*": {
|
|
86
|
+
"types": "./src/provider-models/*.ts",
|
|
87
|
+
"import": "./src/provider-models/*.ts"
|
|
88
|
+
},
|
|
89
|
+
"./providers/*": {
|
|
90
|
+
"types": "./src/providers/*.ts",
|
|
91
|
+
"import": "./src/providers/*.ts"
|
|
92
|
+
},
|
|
93
|
+
"./providers/cursor/gen/*": {
|
|
94
|
+
"types": "./src/providers/cursor/gen/*.ts",
|
|
95
|
+
"import": "./src/providers/cursor/gen/*.ts"
|
|
96
|
+
},
|
|
97
|
+
"./providers/openai-codex/*": {
|
|
98
|
+
"types": "./src/providers/openai-codex/*.ts",
|
|
99
|
+
"import": "./src/providers/openai-codex/*.ts"
|
|
100
|
+
},
|
|
101
|
+
"./usage/*": {
|
|
102
|
+
"types": "./src/usage/*.ts",
|
|
103
|
+
"import": "./src/usage/*.ts"
|
|
104
|
+
},
|
|
105
|
+
"./utils/*": {
|
|
106
|
+
"types": "./src/utils/*.ts",
|
|
107
|
+
"import": "./src/utils/*.ts"
|
|
108
|
+
},
|
|
109
|
+
"./utils/discovery": {
|
|
110
|
+
"types": "./src/utils/discovery/index.ts",
|
|
111
|
+
"import": "./src/utils/discovery/index.ts"
|
|
112
|
+
},
|
|
113
|
+
"./utils/discovery/*": {
|
|
114
|
+
"types": "./src/utils/discovery/*.ts",
|
|
115
|
+
"import": "./src/utils/discovery/*.ts"
|
|
116
|
+
},
|
|
117
|
+
"./utils/oauth": {
|
|
118
|
+
"types": "./src/utils/oauth/index.ts",
|
|
119
|
+
"import": "./src/utils/oauth/index.ts"
|
|
120
|
+
},
|
|
121
|
+
"./utils/oauth/*": {
|
|
122
|
+
"types": "./src/utils/oauth/*.ts",
|
|
123
|
+
"import": "./src/utils/oauth/*.ts"
|
|
124
|
+
},
|
|
125
|
+
"./utils/schema": {
|
|
126
|
+
"types": "./src/utils/schema/index.ts",
|
|
127
|
+
"import": "./src/utils/schema/index.ts"
|
|
128
|
+
},
|
|
129
|
+
"./utils/schema/*": {
|
|
130
|
+
"types": "./src/utils/schema/*.ts",
|
|
131
|
+
"import": "./src/utils/schema/*.ts"
|
|
132
|
+
},
|
|
133
|
+
"./*.js": "./src/*.ts"
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom API provider registry.
|
|
3
|
+
*
|
|
4
|
+
* Allows extensions to register streaming functions for custom API types
|
|
5
|
+
* (e.g., "vertex-claude-api") that are not built into stream.ts.
|
|
6
|
+
*/
|
|
7
|
+
import type {
|
|
8
|
+
Api,
|
|
9
|
+
AssistantMessageEventStream,
|
|
10
|
+
Context,
|
|
11
|
+
KnownApi,
|
|
12
|
+
Model,
|
|
13
|
+
SimpleStreamOptions,
|
|
14
|
+
StreamOptions,
|
|
15
|
+
} from "./types";
|
|
16
|
+
|
|
17
|
+
const BUILTIN_APIS = new Set<KnownApi>([
|
|
18
|
+
"openai-completions",
|
|
19
|
+
"openai-responses",
|
|
20
|
+
"openai-codex-responses",
|
|
21
|
+
"azure-openai-responses",
|
|
22
|
+
"anthropic-messages",
|
|
23
|
+
"bedrock-converse-stream",
|
|
24
|
+
"google-generative-ai",
|
|
25
|
+
"google-gemini-cli",
|
|
26
|
+
"google-vertex",
|
|
27
|
+
"cursor-agent",
|
|
28
|
+
]);
|
|
29
|
+
|
|
30
|
+
export type CustomStreamFn = (
|
|
31
|
+
model: Model<Api>,
|
|
32
|
+
context: Context,
|
|
33
|
+
options?: StreamOptions,
|
|
34
|
+
) => AssistantMessageEventStream;
|
|
35
|
+
export type CustomStreamSimpleFn = (
|
|
36
|
+
model: Model<Api>,
|
|
37
|
+
context: Context,
|
|
38
|
+
options?: SimpleStreamOptions,
|
|
39
|
+
) => AssistantMessageEventStream;
|
|
40
|
+
|
|
41
|
+
export interface RegisteredCustomApi {
|
|
42
|
+
stream: CustomStreamFn;
|
|
43
|
+
streamSimple: CustomStreamSimpleFn;
|
|
44
|
+
sourceId?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const customApiRegistry = new Map<string, RegisteredCustomApi>();
|
|
48
|
+
|
|
49
|
+
function assertCustomApiName(api: string): void {
|
|
50
|
+
if (BUILTIN_APIS.has(api as KnownApi)) {
|
|
51
|
+
throw new Error(`Cannot register custom API "${api}": built-in API names are reserved.`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Register a custom API streaming function.
|
|
57
|
+
*/
|
|
58
|
+
export function registerCustomApi(
|
|
59
|
+
api: string,
|
|
60
|
+
streamSimple: CustomStreamSimpleFn,
|
|
61
|
+
sourceId?: string,
|
|
62
|
+
stream?: CustomStreamFn,
|
|
63
|
+
): void {
|
|
64
|
+
assertCustomApiName(api);
|
|
65
|
+
customApiRegistry.set(api, {
|
|
66
|
+
stream: stream ?? ((model, context, options) => streamSimple(model, context, options as SimpleStreamOptions)),
|
|
67
|
+
streamSimple,
|
|
68
|
+
sourceId,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Get a custom API provider by API identifier.
|
|
74
|
+
*/
|
|
75
|
+
export function getCustomApi(api: string): RegisteredCustomApi | undefined {
|
|
76
|
+
return customApiRegistry.get(api);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Remove all custom APIs registered by a specific source (e.g., extension path).
|
|
81
|
+
*/
|
|
82
|
+
export function unregisterCustomApis(sourceId: string): void {
|
|
83
|
+
for (const [api, entry] of customApiRegistry.entries()) {
|
|
84
|
+
if (entry.sourceId === sourceId) {
|
|
85
|
+
customApiRegistry.delete(api);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Clear all custom API registrations.
|
|
92
|
+
*/
|
|
93
|
+
export function clearCustomApis(): void {
|
|
94
|
+
customApiRegistry.clear();
|
|
95
|
+
}
|