@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.
Files changed (128) hide show
  1. package/CHANGELOG.md +1997 -0
  2. package/README.md +1160 -0
  3. package/package.json +135 -0
  4. package/src/api-registry.ts +95 -0
  5. package/src/auth-storage.ts +2694 -0
  6. package/src/cli.ts +493 -0
  7. package/src/index.ts +42 -0
  8. package/src/model-cache.ts +97 -0
  9. package/src/model-manager.ts +349 -0
  10. package/src/model-thinking.ts +561 -0
  11. package/src/models.json +49439 -0
  12. package/src/models.json.d.ts +9 -0
  13. package/src/models.ts +56 -0
  14. package/src/prompts/turn-aborted-guidance.md +4 -0
  15. package/src/provider-details.ts +81 -0
  16. package/src/provider-models/descriptors.ts +285 -0
  17. package/src/provider-models/google.ts +90 -0
  18. package/src/provider-models/index.ts +4 -0
  19. package/src/provider-models/openai-compat.ts +2074 -0
  20. package/src/provider-models/special.ts +106 -0
  21. package/src/providers/amazon-bedrock.ts +706 -0
  22. package/src/providers/anthropic.ts +1682 -0
  23. package/src/providers/azure-openai-responses.ts +391 -0
  24. package/src/providers/cursor/gen/agent_pb.ts +15274 -0
  25. package/src/providers/cursor/proto/agent.proto +3526 -0
  26. package/src/providers/cursor/proto/buf.gen.yaml +6 -0
  27. package/src/providers/cursor/proto/buf.yaml +17 -0
  28. package/src/providers/cursor.ts +2218 -0
  29. package/src/providers/github-copilot-headers.ts +140 -0
  30. package/src/providers/gitlab-duo.ts +381 -0
  31. package/src/providers/google-gemini-cli.ts +1133 -0
  32. package/src/providers/google-shared.ts +354 -0
  33. package/src/providers/google-vertex.ts +436 -0
  34. package/src/providers/google.ts +381 -0
  35. package/src/providers/kimi.ts +151 -0
  36. package/src/providers/openai-codex/constants.ts +43 -0
  37. package/src/providers/openai-codex/request-transformer.ts +158 -0
  38. package/src/providers/openai-codex/response-handler.ts +81 -0
  39. package/src/providers/openai-codex-responses.ts +2345 -0
  40. package/src/providers/openai-completions-compat.ts +159 -0
  41. package/src/providers/openai-completions.ts +1290 -0
  42. package/src/providers/openai-responses-shared.ts +452 -0
  43. package/src/providers/openai-responses.ts +519 -0
  44. package/src/providers/register-builtins.ts +329 -0
  45. package/src/providers/synthetic.ts +154 -0
  46. package/src/providers/transform-messages.ts +234 -0
  47. package/src/rate-limit-utils.ts +84 -0
  48. package/src/stream.ts +728 -0
  49. package/src/types.ts +546 -0
  50. package/src/usage/claude.ts +337 -0
  51. package/src/usage/gemini.ts +248 -0
  52. package/src/usage/github-copilot.ts +421 -0
  53. package/src/usage/google-antigravity.ts +200 -0
  54. package/src/usage/kimi.ts +286 -0
  55. package/src/usage/minimax-code.ts +31 -0
  56. package/src/usage/openai-codex.ts +387 -0
  57. package/src/usage/zai.ts +247 -0
  58. package/src/usage.ts +130 -0
  59. package/src/utils/abort.ts +36 -0
  60. package/src/utils/anthropic-auth.ts +293 -0
  61. package/src/utils/discovery/antigravity.ts +261 -0
  62. package/src/utils/discovery/codex.ts +371 -0
  63. package/src/utils/discovery/cursor.ts +306 -0
  64. package/src/utils/discovery/gemini.ts +248 -0
  65. package/src/utils/discovery/index.ts +5 -0
  66. package/src/utils/discovery/openai-compatible.ts +224 -0
  67. package/src/utils/event-stream.ts +209 -0
  68. package/src/utils/http-inspector.ts +165 -0
  69. package/src/utils/idle-iterator.ts +176 -0
  70. package/src/utils/json-parse.ts +28 -0
  71. package/src/utils/oauth/alibaba-coding-plan.ts +59 -0
  72. package/src/utils/oauth/anthropic.ts +134 -0
  73. package/src/utils/oauth/api-key-validation.ts +92 -0
  74. package/src/utils/oauth/callback-server.ts +276 -0
  75. package/src/utils/oauth/cerebras.ts +59 -0
  76. package/src/utils/oauth/cloudflare-ai-gateway.ts +48 -0
  77. package/src/utils/oauth/cursor.ts +157 -0
  78. package/src/utils/oauth/github-copilot.ts +358 -0
  79. package/src/utils/oauth/gitlab-duo.ts +123 -0
  80. package/src/utils/oauth/google-antigravity.ts +275 -0
  81. package/src/utils/oauth/google-gemini-cli.ts +334 -0
  82. package/src/utils/oauth/huggingface.ts +62 -0
  83. package/src/utils/oauth/index.ts +512 -0
  84. package/src/utils/oauth/kagi.ts +47 -0
  85. package/src/utils/oauth/kilo.ts +87 -0
  86. package/src/utils/oauth/kimi.ts +251 -0
  87. package/src/utils/oauth/litellm.ts +81 -0
  88. package/src/utils/oauth/lm-studio.ts +40 -0
  89. package/src/utils/oauth/minimax-code.ts +78 -0
  90. package/src/utils/oauth/moonshot.ts +59 -0
  91. package/src/utils/oauth/nanogpt.ts +51 -0
  92. package/src/utils/oauth/nvidia.ts +70 -0
  93. package/src/utils/oauth/oauth.html +199 -0
  94. package/src/utils/oauth/ollama.ts +47 -0
  95. package/src/utils/oauth/openai-codex.ts +190 -0
  96. package/src/utils/oauth/opencode.ts +49 -0
  97. package/src/utils/oauth/parallel.ts +46 -0
  98. package/src/utils/oauth/perplexity.ts +200 -0
  99. package/src/utils/oauth/pkce.ts +18 -0
  100. package/src/utils/oauth/qianfan.ts +58 -0
  101. package/src/utils/oauth/qwen-portal.ts +60 -0
  102. package/src/utils/oauth/synthetic.ts +60 -0
  103. package/src/utils/oauth/tavily.ts +46 -0
  104. package/src/utils/oauth/together.ts +59 -0
  105. package/src/utils/oauth/types.ts +89 -0
  106. package/src/utils/oauth/venice.ts +59 -0
  107. package/src/utils/oauth/vercel-ai-gateway.ts +47 -0
  108. package/src/utils/oauth/vllm.ts +40 -0
  109. package/src/utils/oauth/xiaomi.ts +88 -0
  110. package/src/utils/oauth/zai.ts +60 -0
  111. package/src/utils/oauth/zenmux.ts +51 -0
  112. package/src/utils/overflow.ts +134 -0
  113. package/src/utils/retry-after.ts +110 -0
  114. package/src/utils/retry.ts +93 -0
  115. package/src/utils/schema/CONSTRAINTS.md +160 -0
  116. package/src/utils/schema/adapt.ts +20 -0
  117. package/src/utils/schema/compatibility.ts +397 -0
  118. package/src/utils/schema/dereference.ts +93 -0
  119. package/src/utils/schema/equality.ts +93 -0
  120. package/src/utils/schema/fields.ts +147 -0
  121. package/src/utils/schema/index.ts +9 -0
  122. package/src/utils/schema/normalize-cca.ts +479 -0
  123. package/src/utils/schema/sanitize-google.ts +212 -0
  124. package/src/utils/schema/strict-mode.ts +385 -0
  125. package/src/utils/schema/types.ts +5 -0
  126. package/src/utils/tool-choice.ts +81 -0
  127. package/src/utils/validation.ts +664 -0
  128. package/src/utils.ts +147 -0
@@ -0,0 +1,158 @@
1
+ import type { Effort } from "../../model-thinking";
2
+ import { requireSupportedEffort } from "../../model-thinking";
3
+ import type { Api, Model } from "../../types";
4
+
5
+ export interface ReasoningConfig {
6
+ effort: "none" | "minimal" | "low" | "medium" | "high" | "xhigh";
7
+ summary: "auto" | "concise" | "detailed" | null;
8
+ }
9
+
10
+ export interface CodexRequestOptions {
11
+ reasoningEffort?: ReasoningConfig["effort"];
12
+ reasoningSummary?: ReasoningConfig["summary"] | null;
13
+ textVerbosity?: "low" | "medium" | "high";
14
+ include?: string[];
15
+ }
16
+
17
+ export interface InputItem {
18
+ id?: string | null;
19
+ type?: string | null;
20
+ role?: string;
21
+ content?: unknown;
22
+ call_id?: string | null;
23
+ name?: string;
24
+ output?: unknown;
25
+ arguments?: unknown;
26
+ }
27
+
28
+ export interface RequestBody {
29
+ model: string;
30
+ store?: boolean;
31
+ stream?: boolean;
32
+ instructions?: string;
33
+ input?: InputItem[];
34
+ tools?: unknown;
35
+ tool_choice?: unknown;
36
+ temperature?: number;
37
+ top_p?: number;
38
+ top_k?: number;
39
+ min_p?: number;
40
+ presence_penalty?: number;
41
+ repetition_penalty?: number;
42
+ reasoning?: Partial<ReasoningConfig>;
43
+ text?: {
44
+ verbosity?: "low" | "medium" | "high";
45
+ };
46
+ include?: string[];
47
+ prompt_cache_key?: string;
48
+ prompt_cache_retention?: "in_memory" | "24h";
49
+ max_output_tokens?: number;
50
+ max_completion_tokens?: number;
51
+ [key: string]: unknown;
52
+ }
53
+
54
+ function getReasoningConfig(model: Model<Api>, options: CodexRequestOptions): ReasoningConfig {
55
+ return {
56
+ effort:
57
+ options.reasoningEffort === "none" ? "none" : requireSupportedEffort(model, options.reasoningEffort as Effort),
58
+ summary: options.reasoningSummary ?? "detailed",
59
+ };
60
+ }
61
+
62
+ function filterInput(input: InputItem[] | undefined): InputItem[] | undefined {
63
+ if (!Array.isArray(input)) return input;
64
+
65
+ return input
66
+ .filter(item => item.type !== "item_reference")
67
+ .map(item => {
68
+ if (item.id != null) {
69
+ const { id: _id, ...rest } = item;
70
+ return rest as InputItem;
71
+ }
72
+ return item;
73
+ });
74
+ }
75
+
76
+ export async function transformRequestBody(
77
+ body: RequestBody,
78
+ model: Model<Api>,
79
+ options: CodexRequestOptions = {},
80
+ prompt?: { instructions: string; developerMessages: string[] },
81
+ ): Promise<RequestBody> {
82
+ body.store = false;
83
+ body.stream = true;
84
+
85
+ if (body.input && Array.isArray(body.input)) {
86
+ body.input = filterInput(body.input);
87
+
88
+ if (body.input) {
89
+ const functionCallIds = new Set(
90
+ body.input
91
+ .filter(item => item.type === "function_call" && typeof item.call_id === "string")
92
+ .map(item => item.call_id as string),
93
+ );
94
+
95
+ body.input = body.input.map(item => {
96
+ if (item.type === "function_call_output" && typeof item.call_id === "string") {
97
+ const callId = item.call_id as string;
98
+ if (!functionCallIds.has(callId)) {
99
+ const itemRecord = item as unknown as Record<string, unknown>;
100
+ const toolName = typeof itemRecord.name === "string" ? itemRecord.name : "tool";
101
+ let text = "";
102
+ try {
103
+ const output = itemRecord.output;
104
+ text = typeof output === "string" ? output : JSON.stringify(output);
105
+ } catch {
106
+ text = String(itemRecord.output ?? "");
107
+ }
108
+ if (text.length > 16000) {
109
+ text = `${text.slice(0, 16000)}\n...[truncated]`;
110
+ }
111
+ return {
112
+ type: "message",
113
+ role: "assistant",
114
+ content: `[Previous ${toolName} result; call_id=${callId}]: ${text}`,
115
+ } as InputItem;
116
+ }
117
+ }
118
+ return item;
119
+ });
120
+ }
121
+ }
122
+
123
+ if (prompt?.developerMessages && prompt.developerMessages.length > 0 && Array.isArray(body.input)) {
124
+ const developerMessages = prompt.developerMessages.map(
125
+ text =>
126
+ ({
127
+ type: "message",
128
+ role: "developer",
129
+ content: [{ type: "input_text", text }],
130
+ }) as InputItem,
131
+ );
132
+ body.input = [...developerMessages, ...body.input];
133
+ }
134
+
135
+ if (options.reasoningEffort !== undefined) {
136
+ const reasoningConfig = getReasoningConfig(model, options);
137
+ body.reasoning = {
138
+ ...body.reasoning,
139
+ ...reasoningConfig,
140
+ };
141
+ } else {
142
+ delete body.reasoning;
143
+ }
144
+
145
+ body.text = {
146
+ ...body.text,
147
+ verbosity: options.textVerbosity || "medium",
148
+ };
149
+
150
+ const include = Array.isArray(options.include) ? [...options.include] : [];
151
+ include.push("reasoning.encrypted_content");
152
+ body.include = Array.from(new Set(include));
153
+
154
+ delete body.max_output_tokens;
155
+ delete body.max_completion_tokens;
156
+
157
+ return body;
158
+ }
@@ -0,0 +1,81 @@
1
+ import { toNumber } from "../../utils";
2
+
3
+ export type CodexRateLimit = {
4
+ used_percent?: number;
5
+ window_minutes?: number;
6
+ resets_at?: number;
7
+ };
8
+
9
+ export type CodexRateLimits = {
10
+ primary?: CodexRateLimit;
11
+ secondary?: CodexRateLimit;
12
+ };
13
+
14
+ export type CodexErrorInfo = {
15
+ message: string;
16
+ status: number;
17
+ friendlyMessage?: string;
18
+ rateLimits?: CodexRateLimits;
19
+ raw?: string;
20
+ };
21
+
22
+ export async function parseCodexError(response: Response): Promise<CodexErrorInfo> {
23
+ const raw = await response.text();
24
+ let message = raw || response.statusText || "Request failed";
25
+ let friendlyMessage: string | undefined;
26
+ let rateLimits: CodexRateLimits | undefined;
27
+
28
+ try {
29
+ const parsed = JSON.parse(raw) as { error?: Record<string, unknown> };
30
+ const err = parsed?.error ?? {};
31
+
32
+ const headers = response.headers;
33
+ const primary = {
34
+ used_percent: toNumber(headers.get("x-codex-primary-used-percent")),
35
+ window_minutes: toInt(headers.get("x-codex-primary-window-minutes")),
36
+ resets_at: toInt(headers.get("x-codex-primary-reset-at")),
37
+ };
38
+ const secondary = {
39
+ used_percent: toNumber(headers.get("x-codex-secondary-used-percent")),
40
+ window_minutes: toInt(headers.get("x-codex-secondary-window-minutes")),
41
+ resets_at: toInt(headers.get("x-codex-secondary-reset-at")),
42
+ };
43
+ rateLimits =
44
+ primary.used_percent !== undefined || secondary.used_percent !== undefined
45
+ ? { primary, secondary }
46
+ : undefined;
47
+
48
+ const code = String((err as { code?: string; type?: string }).code ?? (err as { type?: string }).type ?? "");
49
+ const resetsAt = (err as { resets_at?: number }).resets_at ?? primary.resets_at ?? secondary.resets_at;
50
+ const mins = resetsAt ? Math.max(0, Math.round((resetsAt * 1000 - Date.now()) / 60000)) : undefined;
51
+
52
+ if (/usage_limit_reached|usage_not_included/i.test(code)) {
53
+ const planType = (err as { plan_type?: string }).plan_type;
54
+ const plan = planType ? ` (${String(planType).toLowerCase()} plan)` : "";
55
+ const when = mins !== undefined ? ` Try again in ~${mins} min.` : "";
56
+ friendlyMessage = `You have hit your ChatGPT usage limit${plan}.${when}`.trim();
57
+ } else if (/rate_limit_exceeded/i.test(code) || response.status === 429) {
58
+ const when = mins !== undefined ? ` Try again in ~${mins} min.` : "";
59
+ friendlyMessage = `ChatGPT rate limit exceeded.${when}`.trim();
60
+ }
61
+
62
+ const errMessage = (err as { message?: string }).message;
63
+ message = errMessage || friendlyMessage || message;
64
+ } catch {
65
+ // raw body not JSON
66
+ }
67
+
68
+ return {
69
+ message,
70
+ status: response.status,
71
+ friendlyMessage,
72
+ rateLimits,
73
+ raw: raw,
74
+ };
75
+ }
76
+
77
+ function toInt(v: string | null): number | undefined {
78
+ if (v == null) return undefined;
79
+ const n = parseInt(v, 10);
80
+ return Number.isFinite(n) ? n : undefined;
81
+ }