pi-tsgw 0.0.6 → 0.0.7

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 CHANGED
@@ -85,6 +85,11 @@ global whitelist: models matching neither list remain available. To register
85
85
  only selected models, use `"excludeModels": ["*"]` and pull them back through
86
86
  `includeModels`.
87
87
 
88
+ Opening `/model` refreshes the gateway catalog in the background, with a
89
+ five-minute cache to avoid repeated requests. Run `/tsgw-refresh` to bypass the
90
+ cache and force an immediate refresh without restarting or reloading Pi. If a
91
+ refresh fails, the last successful model list remains active.
92
+
88
93
  ## Development
89
94
 
90
95
  ```bash
@@ -1,11 +1,9 @@
1
1
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
2
  import {
3
- CONFIG_DIR_NAME,
4
3
  getAgentDir,
5
4
  readStoredCredential,
6
5
  } from "@earendil-works/pi-coding-agent";
7
6
  import { readFileSync } from "node:fs";
8
- import { homedir } from "node:os";
9
7
  import { join } from "node:path";
10
8
  import { randomUUID } from "node:crypto";
11
9
  import {
@@ -124,9 +122,21 @@ function gatewayHasModel(gatewayIds: ReadonlySet<string>, id: string): boolean {
124
122
  return false;
125
123
  }
126
124
 
127
- /** 模型缓存文件:~/.pi/tsgw/models-cache.json(CONFIG_DIR_NAME 跟随 piConfig 覆盖)。 */
125
+ /** 模型缓存文件:<agent-dir>/tsgw/models-cache.json。 */
128
126
  function gatewayModelCachePath(): string {
129
- return join(homedir(), CONFIG_DIR_NAME, "tsgw", "models-cache.json");
127
+ return join(getAgentDir(), "tsgw", "models-cache.json");
128
+ }
129
+
130
+ function effectiveModelsForGateway(
131
+ root: string,
132
+ filter: ModelFilter | undefined,
133
+ gatewayIds: ReadonlySet<string> | undefined,
134
+ ): ReturnType<typeof modelsForRoot> {
135
+ const staticModels = modelsForRoot(root);
136
+ const intersected = gatewayIds
137
+ ? staticModels.filter((model) => gatewayHasModel(gatewayIds, model.id))
138
+ : staticModels;
139
+ return filterModels(intersected, filter);
130
140
  }
131
141
 
132
142
  /**
@@ -136,12 +146,11 @@ function gatewayModelCachePath(): string {
136
146
  async function resolveEffectiveModels(
137
147
  root: string,
138
148
  filter: ModelFilter | undefined,
149
+ cacheFilePath: string,
139
150
  ): Promise<{
140
151
  models: ReturnType<typeof modelsForRoot>;
141
152
  gatewayIds: ReadonlySet<string> | undefined;
142
153
  }> {
143
- const staticModels = modelsForRoot(root);
144
-
145
154
  // 凭据解析失败不阻塞:无凭据时直接跳过网关层。
146
155
  let apiKey = "";
147
156
  try {
@@ -155,24 +164,24 @@ async function resolveEffectiveModels(
155
164
  if (apiKey) {
156
165
  try {
157
166
  const gateway = await getGatewayModelIds(root, apiKey, {
158
- cacheFilePath: gatewayModelCachePath(),
167
+ cacheFilePath,
159
168
  });
160
169
  if (gateway.ok) gatewayIds = new Set(gateway.ids);
161
170
  else
162
171
  console.warn(
163
172
  `TSGW: gateway model list unavailable (${gateway.reason ?? "unknown"}); using static catalog.`,
164
173
  );
165
- } catch (error) {
174
+ } catch {
166
175
  console.warn(
167
176
  `TSGW: gateway model list load failed; using static catalog.`,
168
177
  );
169
178
  }
170
179
  }
171
180
 
172
- const intersected = gatewayIds
173
- ? staticModels.filter((model) => gatewayHasModel(gatewayIds, model.id))
174
- : staticModels;
175
- return { models: filterModels(intersected, filter), gatewayIds };
181
+ return {
182
+ models: effectiveModelsForGateway(root, filter, gatewayIds),
183
+ gatewayIds,
184
+ };
176
185
  }
177
186
 
178
187
  export default async function registerTsgw(pi: ExtensionAPI): Promise<void> {
@@ -187,6 +196,7 @@ export default async function registerTsgw(pi: ExtensionAPI): Promise<void> {
187
196
  include: settings.includeModels,
188
197
  exclude: settings.excludeModels,
189
198
  };
199
+ const cacheFilePath = gatewayModelCachePath();
190
200
  let requestState: RequestState | undefined;
191
201
 
192
202
  const refreshRequestState = (ctx: {
@@ -200,13 +210,99 @@ export default async function registerTsgw(pi: ExtensionAPI): Promise<void> {
200
210
  const { models, gatewayIds } = await resolveEffectiveModels(
201
211
  root,
202
212
  modelFilter,
213
+ cacheFilePath,
203
214
  );
215
+ let latestModels = models;
204
216
  pi.registerProvider(PROVIDER_ID, {
205
217
  name: "TSGW",
206
218
  baseUrl: `${root}/v1`,
207
219
  api: "openai-completions",
208
220
  apiKey: "$TSGW_API_KEY",
209
221
  models,
222
+ async refreshModels(context) {
223
+ if (!context.allowNetwork) return latestModels;
224
+ context.signal.throwIfAborted();
225
+ const credential = context.credential;
226
+ if (credential?.type !== "api_key" || !credential.key)
227
+ throw new Error("TSGW API key is unavailable for model refresh.");
228
+
229
+ const gateway = await getGatewayModelIds(root, credential.key, {
230
+ cacheFilePath,
231
+ force: context.force === true,
232
+ signal: context.signal,
233
+ });
234
+ context.signal.throwIfAborted();
235
+ if (!gateway.ok)
236
+ throw new Error(
237
+ `TSGW gateway model refresh failed (${gateway.reason}).`,
238
+ );
239
+ if (gateway.stale)
240
+ throw new Error(
241
+ `TSGW gateway model refresh failed (${gateway.fallbackReason ?? "unknown"}); keeping the last successful catalog.`,
242
+ );
243
+
244
+ latestModels = effectiveModelsForGateway(
245
+ root,
246
+ modelFilter,
247
+ new Set(gateway.ids),
248
+ );
249
+ return latestModels;
250
+ },
251
+ });
252
+
253
+ pi.registerCommand("tsgw-refresh", {
254
+ description: "Force-refresh the TSGW gateway model catalog",
255
+ handler: async (_args, ctx) => {
256
+ await ctx.waitForIdle();
257
+ if (!ctx.modelRegistry.getProviderAuthStatus(PROVIDER_ID).configured) {
258
+ ctx.ui.notify(
259
+ "TSGW model refresh skipped: configure an API key with /login first.",
260
+ "warning",
261
+ );
262
+ return;
263
+ }
264
+ const count = (): number =>
265
+ ctx.modelRegistry
266
+ .getAvailable()
267
+ .filter((model) => model.provider === PROVIDER_ID).length;
268
+ const before = count();
269
+ try {
270
+ // Pi 0.84+ returns cancellation/errors; older supported Pi versions
271
+ // resolve void, so treat missing result metadata as success.
272
+ const result = (await ctx.modelRegistry.refresh({
273
+ providers: [PROVIDER_ID],
274
+ force: true,
275
+ })) as
276
+ | {
277
+ aborted?: boolean;
278
+ errors?: ReadonlyMap<string, Error>;
279
+ }
280
+ | undefined;
281
+ const after = count();
282
+ const error = result?.errors?.get(PROVIDER_ID);
283
+ if (result?.aborted) {
284
+ ctx.ui.notify(
285
+ `TSGW model refresh cancelled (${before} → ${after}).`,
286
+ "warning",
287
+ );
288
+ } else if (error) {
289
+ ctx.ui.notify(
290
+ `TSGW model refresh failed (${before} → ${after}): ${error.message}`,
291
+ "error",
292
+ );
293
+ } else {
294
+ ctx.ui.notify(
295
+ `TSGW models refreshed (${before} → ${after}).`,
296
+ "info",
297
+ );
298
+ }
299
+ } catch (error) {
300
+ ctx.ui.notify(
301
+ `TSGW model refresh failed (${before} → ${count()}): ${error instanceof Error ? error.message : String(error)}`,
302
+ "error",
303
+ );
304
+ }
305
+ },
210
306
  });
211
307
 
212
308
  // ts_search 条件注册:固定白名单后端与可用模型列表有交集才注册,
@@ -14,6 +14,7 @@ export const DEFAULT_GATEWAY_MODEL_CACHE_TTL_MS = 5 * 60 * 1_000;
14
14
  export type GatewayModelFailureReason =
15
15
  | "http"
16
16
  | "timeout"
17
+ | "aborted"
17
18
  | "network"
18
19
  | "invalid-json"
19
20
  | "invalid-data"
@@ -27,10 +28,12 @@ export type GatewayFetch = (
27
28
  export interface FetchGatewayModelIdsOptions {
28
29
  timeoutMs?: number;
29
30
  fetcher?: GatewayFetch;
31
+ signal?: AbortSignal;
30
32
  }
31
33
 
32
34
  export interface GetGatewayModelIdsOptions extends FetchGatewayModelIdsOptions {
33
35
  cacheFilePath?: string;
36
+ force?: boolean;
34
37
  }
35
38
 
36
39
  export type FetchGatewayModelIdsResult =
@@ -94,8 +97,12 @@ export async function fetchGatewayModelIds(
94
97
  ): Promise<FetchGatewayModelIdsResult> {
95
98
  const timeoutMs = opts.timeoutMs ?? DEFAULT_GATEWAY_MODEL_TIMEOUT_MS;
96
99
  const fetcher = opts.fetcher ?? globalThis.fetch;
100
+ if (opts.signal?.aborted) return { ok: false, reason: "aborted" };
101
+
97
102
  const controller = new AbortController();
98
103
  let timedOut = false;
104
+ const abortFromCaller = (): void => controller.abort(opts.signal?.reason);
105
+ opts.signal?.addEventListener("abort", abortFromCaller, { once: true });
99
106
  const timeout = setTimeout(
100
107
  () => {
101
108
  timedOut = true;
@@ -113,9 +120,9 @@ export async function fetchGatewayModelIds(
113
120
  signal: controller.signal,
114
121
  });
115
122
  } catch (error) {
116
- return timedOut
117
- ? { ok: false, reason: "timeout" }
118
- : { ok: false, reason: "network", detail: errorDetail(error) };
123
+ if (timedOut) return { ok: false, reason: "timeout" };
124
+ if (opts.signal?.aborted) return { ok: false, reason: "aborted" };
125
+ return { ok: false, reason: "network", detail: errorDetail(error) };
119
126
  }
120
127
 
121
128
  if (!response.ok) {
@@ -126,9 +133,9 @@ export async function fetchGatewayModelIds(
126
133
  try {
127
134
  payload = await response.json();
128
135
  } catch (error) {
129
- return timedOut
130
- ? { ok: false, reason: "timeout" }
131
- : { ok: false, reason: "invalid-json", detail: errorDetail(error) };
136
+ if (timedOut) return { ok: false, reason: "timeout" };
137
+ if (opts.signal?.aborted) return { ok: false, reason: "aborted" };
138
+ return { ok: false, reason: "invalid-json", detail: errorDetail(error) };
132
139
  }
133
140
 
134
141
  if (!payload || typeof payload !== "object")
@@ -140,6 +147,7 @@ export async function fetchGatewayModelIds(
140
147
  return { ok: true, ids };
141
148
  } finally {
142
149
  clearTimeout(timeout);
150
+ opts.signal?.removeEventListener("abort", abortFromCaller);
143
151
  }
144
152
  }
145
153
 
@@ -269,7 +277,7 @@ export async function getGatewayModelIds(
269
277
  ): Promise<GetGatewayModelIdsResult> {
270
278
  const key = baseUrl.replace(/\/+$/, "");
271
279
  const cache = cacheFor(key);
272
- if (cache.isFresh(now)) {
280
+ if (!opts.force && cache.isFresh(now)) {
273
281
  const entry = cache.get();
274
282
  if (entry) return { ok: true, ids: entry.ids, cached: true, stale: false };
275
283
  }
@@ -278,6 +286,7 @@ export async function getGatewayModelIds(
278
286
  ? readGatewayModelCacheEntry(opts.cacheFilePath)
279
287
  : undefined;
280
288
  if (
289
+ !opts.force &&
281
290
  diskEntry &&
282
291
  isCacheEntryFresh(diskEntry, now, DEFAULT_GATEWAY_MODEL_CACHE_TTL_MS)
283
292
  ) {
@@ -290,20 +299,27 @@ export async function getGatewayModelIds(
290
299
  };
291
300
  }
292
301
 
293
- let request = inFlightRequests.get(key);
302
+ const requestKey = `${key}\0${opts.force ? "force" : "normal"}`;
303
+ // A shared request cannot safely inherit one caller's AbortSignal: Pi may
304
+ // supersede that refresh while a newer caller is still waiting. Only
305
+ // signal-free calls share in-flight work; abortable calls own their fetch.
306
+ const shareRequest = opts.signal === undefined;
307
+ let request = shareRequest ? inFlightRequests.get(requestKey) : undefined;
294
308
  if (!request) {
295
309
  request = fetchGatewayModelIds(key, apiKey, {
296
310
  fetcher: opts.fetcher,
297
311
  timeoutMs: opts.timeoutMs,
312
+ signal: opts.signal,
298
313
  });
299
- inFlightRequests.set(key, request);
314
+ if (shareRequest) inFlightRequests.set(requestKey, request);
300
315
  }
301
316
 
302
317
  let fetched: FetchGatewayModelIdsResult;
303
318
  try {
304
319
  fetched = await request;
305
320
  } finally {
306
- if (inFlightRequests.get(key) === request) inFlightRequests.delete(key);
321
+ if (shareRequest && inFlightRequests.get(requestKey) === request)
322
+ inFlightRequests.delete(requestKey);
307
323
  }
308
324
 
309
325
  if (fetched.ok) {
@@ -12,7 +12,6 @@ import {
12
12
  type ThinkingApplier,
13
13
  } from "./_tools.ts";
14
14
  import { applyBuiltinSearchTool } from "./web-search.ts";
15
- import { deepseekThinking } from "./vendors/deepseek.ts";
16
15
  import { geminiThinking } from "./vendors/gemini.ts";
17
16
  import { glmThinking } from "./vendors/glm.ts";
18
17
  import { grokThinking } from "./vendors/grok.ts";
@@ -27,7 +26,6 @@ import { qwenThinking } from "./vendors/qwen.ts";
27
26
  const TSGW_PROVIDER = "tsgw";
28
27
 
29
28
  const THINKING_STRATEGIES: Record<string, ThinkingApplier> = {
30
- ...deepseekThinking,
31
29
  ...glmThinking,
32
30
  ...mimoThinking,
33
31
  ...minimaxThinking,
@@ -1,46 +1,65 @@
1
1
  import type { ProviderModelConfig } from "@earendil-works/pi-coding-agent";
2
- import { OPENAI_COMPLETIONS_COMPAT } from "./_protocols.ts";
3
- import { isMaximum, type PayloadWriter, type ThinkingApplier, type ThinkingLevel } from "../_tools.ts";
4
2
 
5
- // DeepSeek 在 openai-completions 协议基础上,要求 DeepSeek 特有 thinking 格式,
6
- // 且多轮(尤其工具调用)必须保留 reasoning_content。
7
- const DEEPSEEK_COMPAT = {
8
- ...OPENAI_COMPLETIONS_COMPAT,
9
- thinkingFormat: "deepseek" as const,
10
- requiresReasoningContentOnAssistantMessages: true,
3
+ // DeepSeek Responses 将 developer role 当作 user,且不支持 OpenAI 的
4
+ // prompt_cache_retention;其余 reasoning 字段交给 Pi 的 Responses adapter。
5
+ const DEEPSEEK_RESPONSES_COMPAT = {
6
+ supportsDeveloperRole: false,
7
+ supportsLongCacheRetention: false,
11
8
  };
12
9
 
13
10
  /**
14
11
  * DeepSeek(深度求索)V4 系列。
15
- * 官方文档:https://api-docs.deepseek.com/
12
+ * 官方文档:https://api-docs.deepseek.com/guides/responses_api
16
13
  */
17
14
  export function deepseekModels(root: string): ProviderModelConfig[] {
18
15
  const v1 = `${root}/v1`;
19
16
  return [
17
+ {
18
+ id: "deepseek-flash",
19
+ name: "DeepSeek V4.1 Flash",
20
+ api: "openai-responses",
21
+ baseUrl: v1,
22
+ reasoning: true,
23
+ input: ["text", "image"],
24
+ cost: { input: 0.1475, output: 0.295, cacheRead: 0.00295, cacheWrite: 0 },
25
+ contextWindow: 1000000,
26
+ maxTokens: 384000,
27
+ compat: DEEPSEEK_RESPONSES_COMPAT,
28
+ thinkingLevelMap: {
29
+ off: "none",
30
+ minimal: "low",
31
+ low: "low",
32
+ medium: "high",
33
+ high: "high",
34
+ xhigh: "high",
35
+ max: "max",
36
+ },
37
+ },
20
38
  {
21
39
  id: "deepseek-v4-flash",
22
- name: "DeepSeek V4 Flash",
23
- api: "openai-completions",
40
+ name: "DeepSeek V4 Flash (Legacy Alias)",
41
+ api: "openai-responses",
24
42
  baseUrl: v1,
25
43
  reasoning: true,
26
- input: ["text"],
44
+ input: ["text", "image"],
27
45
  cost: { input: 0.1475, output: 0.295, cacheRead: 0.00295, cacheWrite: 0 },
28
46
  contextWindow: 1000000,
29
47
  maxTokens: 384000,
30
- compat: DEEPSEEK_COMPAT,
48
+ compat: DEEPSEEK_RESPONSES_COMPAT,
31
49
  thinkingLevelMap: {
32
- minimal: null,
33
- low: null,
34
- medium: null,
50
+ off: "none",
51
+ minimal: "low",
52
+ low: "low",
53
+ medium: "high",
35
54
  high: "high",
36
- xhigh: "max",
55
+ xhigh: "high",
37
56
  max: "max",
38
57
  },
39
58
  },
40
59
  {
41
60
  id: "deepseek-v4-pro",
42
61
  name: "DeepSeek V4 Pro",
43
- api: "openai-completions",
62
+ api: "openai-responses",
44
63
  baseUrl: v1,
45
64
  reasoning: true,
46
65
  input: ["text"],
@@ -52,31 +71,16 @@ export function deepseekModels(root: string): ProviderModelConfig[] {
52
71
  },
53
72
  contextWindow: 1000000,
54
73
  maxTokens: 384000,
55
- compat: DEEPSEEK_COMPAT,
74
+ compat: DEEPSEEK_RESPONSES_COMPAT,
56
75
  thinkingLevelMap: {
57
- minimal: null,
58
- low: null,
59
- medium: null,
76
+ off: "none",
77
+ minimal: "low",
78
+ low: "low",
79
+ medium: "high",
60
80
  high: "high",
61
- xhigh: "max",
81
+ xhigh: "high",
62
82
  max: "max",
63
83
  },
64
84
  },
65
85
  ];
66
86
  }
67
-
68
- // DeepSeek 思维链:`thinking.type` + `reasoning_effort`(high/max 两档)。
69
- function applyDeepSeek(writer: PayloadWriter, level: ThinkingLevel): void {
70
- writer.remove("reasoning_effort");
71
- if (level === "off") {
72
- writer.setThinking({ type: "disabled" });
73
- return;
74
- }
75
- writer.setThinking({ type: "enabled" });
76
- writer.set("reasoning_effort", isMaximum(level) ? "max" : "high");
77
- }
78
-
79
- export const deepseekThinking: Record<string, ThinkingApplier> = {
80
- "deepseek-v4-flash": (w, c) => applyDeepSeek(w, c.thinkingLevel),
81
- "deepseek-v4-pro": (w, c) => applyDeepSeek(w, c.thinkingLevel),
82
- };
@@ -9,9 +9,8 @@ export function openaiModels(root: string): ProviderModelConfig[] {
9
9
  const v1 = `${root}/v1`;
10
10
  return [
11
11
  {
12
- // 参数与 GPT 5.6 Sol 一致。
13
- id: "hack",
14
- name: "日站专用",
12
+ id: "gpt-6-astra",
13
+ name: "GPT-6 Astra",
15
14
  api: "openai-responses",
16
15
  baseUrl: v1,
17
16
  reasoning: true,
@@ -23,8 +22,8 @@ export function openaiModels(root: string): ProviderModelConfig[] {
23
22
  max: "max",
24
23
  },
25
24
  input: ["text", "image"],
26
- cost: { input: 5, output: 30, cacheRead: 0.5, cacheWrite: 6.25 },
27
- contextWindow: 372000,
25
+ cost: { input: 10, output: 50, cacheRead: 1, cacheWrite: 12.5 },
26
+ contextWindow: 1050000,
28
27
  maxTokens: 128000,
29
28
  },
30
29
  {
@@ -98,150 +97,6 @@ export function openaiModels(root: string): ProviderModelConfig[] {
98
97
  contextWindow: 272000,
99
98
  maxTokens: 128000,
100
99
  },
101
- {
102
- id: "gpt-5.3-codex-spark",
103
- name: "GPT-5.3 Codex Spark",
104
- api: "openai-responses",
105
- baseUrl: v1,
106
- reasoning: true,
107
- thinkingLevelMap: {
108
- low: "low",
109
- medium: "medium",
110
- high: "high",
111
- xhigh: "xhigh",
112
- },
113
- input: ["text"],
114
- cost: { input: 1.75, output: 14, cacheRead: 0.175, cacheWrite: 0 },
115
- contextWindow: 128000,
116
- maxTokens: 32000,
117
- },
118
- {
119
- id: "gpt-5.6",
120
- name: "GPT-5.6",
121
- api: "openai-responses",
122
- baseUrl: v1,
123
- reasoning: true,
124
- thinkingLevelMap: {
125
- low: "low",
126
- medium: "medium",
127
- high: "high",
128
- xhigh: "xhigh",
129
- max: "max",
130
- },
131
- input: ["text", "image"],
132
- cost: { input: 5, output: 30, cacheRead: 0.5, cacheWrite: 6.25 },
133
- contextWindow: 1050000,
134
- maxTokens: 128000,
135
- },
136
- {
137
- id: "gpt-5.4",
138
- name: "GPT-5.4",
139
- api: "openai-responses",
140
- baseUrl: v1,
141
- reasoning: true,
142
- thinkingLevelMap: {
143
- low: "low",
144
- medium: "medium",
145
- high: "high",
146
- xhigh: "xhigh",
147
- max: "max",
148
- },
149
- input: ["text", "image"],
150
- cost: { input: 2.5, output: 15, cacheRead: 0.25, cacheWrite: 0 },
151
- contextWindow: 1050000,
152
- maxTokens: 128000,
153
- },
154
- {
155
- id: "gpt-5.4-mini",
156
- name: "GPT-5.4 mini",
157
- api: "openai-responses",
158
- baseUrl: v1,
159
- reasoning: true,
160
- thinkingLevelMap: {
161
- low: "low",
162
- medium: "medium",
163
- high: "high",
164
- xhigh: "xhigh",
165
- max: "max",
166
- },
167
- input: ["text", "image"],
168
- cost: { input: 0.75, output: 4.5, cacheRead: 0.075, cacheWrite: 0 },
169
- contextWindow: 400000,
170
- maxTokens: 128000,
171
- },
172
- {
173
- id: "gpt-5.2",
174
- name: "GPT-5.2",
175
- api: "openai-responses",
176
- baseUrl: v1,
177
- reasoning: true,
178
- thinkingLevelMap: {
179
- low: "low",
180
- medium: "medium",
181
- high: "high",
182
- xhigh: "xhigh",
183
- max: "max",
184
- },
185
- input: ["text", "image"],
186
- cost: { input: 1.75, output: 14, cacheRead: 0.175, cacheWrite: 0 },
187
- contextWindow: 400000,
188
- maxTokens: 128000,
189
- },
190
- {
191
- id: "gpt-5.2-pro",
192
- name: "GPT-5.2 Pro",
193
- api: "openai-responses",
194
- baseUrl: v1,
195
- reasoning: true,
196
- thinkingLevelMap: {
197
- low: "low",
198
- medium: "medium",
199
- high: "high",
200
- xhigh: "xhigh",
201
- max: "max",
202
- },
203
- input: ["text", "image"],
204
- // 官方未公布缓存价,置 0。
205
- cost: { input: 21, output: 168, cacheRead: 0, cacheWrite: 0 },
206
- contextWindow: 400000,
207
- maxTokens: 128000,
208
- },
209
- {
210
- id: "gpt-5.1",
211
- name: "GPT-5.1",
212
- api: "openai-responses",
213
- baseUrl: v1,
214
- reasoning: true,
215
- thinkingLevelMap: {
216
- low: "low",
217
- medium: "medium",
218
- high: "high",
219
- xhigh: "xhigh",
220
- max: "max",
221
- },
222
- input: ["text", "image"],
223
- cost: { input: 1.25, output: 10, cacheRead: 0.125, cacheWrite: 0 },
224
- contextWindow: 400000,
225
- maxTokens: 128000,
226
- },
227
- {
228
- id: "gpt-5",
229
- name: "GPT-5",
230
- api: "openai-responses",
231
- baseUrl: v1,
232
- reasoning: true,
233
- thinkingLevelMap: {
234
- low: "low",
235
- medium: "medium",
236
- high: "high",
237
- xhigh: "xhigh",
238
- max: "max",
239
- },
240
- input: ["text", "image"],
241
- cost: { input: 1.25, output: 10, cacheRead: 0.125, cacheWrite: 0 },
242
- contextWindow: 400000,
243
- maxTokens: 128000,
244
- },
245
100
  ];
246
101
  }
247
102
 
@@ -253,18 +108,10 @@ function applyOpenAIResponses(writer: PayloadWriter, modelId: string): void {
253
108
  writer.setTextVerbosity(verbosity);
254
109
  }
255
110
 
256
- export const openaiThinking: Record<string, ThinkingApplier> = {
257
- "hack": (w, c) => applyOpenAIResponses(w, c.modelId),
111
+ export const openaiThinking = {
112
+ "gpt-6-astra": (w, c) => applyOpenAIResponses(w, c.modelId),
258
113
  "gpt-5.6-sol": (w, c) => applyOpenAIResponses(w, c.modelId),
259
114
  "gpt-5.6-terra": (w, c) => applyOpenAIResponses(w, c.modelId),
260
115
  "gpt-5.6-luna": (w, c) => applyOpenAIResponses(w, c.modelId),
261
116
  "gpt-5.5": (w, c) => applyOpenAIResponses(w, c.modelId),
262
- "gpt-5.3-codex-spark": (w, c) => applyOpenAIResponses(w, c.modelId),
263
- "gpt-5.6": (w, c) => applyOpenAIResponses(w, c.modelId),
264
- "gpt-5.4": (w, c) => applyOpenAIResponses(w, c.modelId),
265
- "gpt-5.4-mini": (w, c) => applyOpenAIResponses(w, c.modelId),
266
- "gpt-5.2": (w, c) => applyOpenAIResponses(w, c.modelId),
267
- "gpt-5.2-pro": (w, c) => applyOpenAIResponses(w, c.modelId),
268
- "gpt-5.1": (w, c) => applyOpenAIResponses(w, c.modelId),
269
- "gpt-5": (w, c) => applyOpenAIResponses(w, c.modelId),
270
- };
117
+ } satisfies Record<string, ThinkingApplier>;
@@ -12,13 +12,19 @@
12
12
  * 独立的 ts_search 工具(所有模型可用)单独实现,与内置查询注入分离。
13
13
  */
14
14
 
15
- import { isPlainObject, PayloadWriter, type WebSearchMode } from "./_tools.ts";
15
+ import {
16
+ isPlainObject,
17
+ type Payload,
18
+ PayloadWriter,
19
+ type WebSearchMode,
20
+ } from "./_tools.ts";
16
21
 
17
22
  const OPENAI_RESPONSES = "openai-responses";
18
23
  const OPENAI_COMPLETIONS = "openai-completions";
19
24
 
20
25
  // 支持内置查询的模型名单(GPT Responses 系列)。
21
26
  const BUILTIN_SEARCH_MODELS = new Set([
27
+ "gpt-6-astra",
22
28
  "gpt-5.6-sol",
23
29
  "gpt-5.6-terra",
24
30
  "gpt-5.6-luna",
@@ -42,7 +48,7 @@ function isExistingWebSearchTool(tools: readonly unknown[]): boolean {
42
48
  });
43
49
  }
44
50
 
45
- function hasGrokSearchFields(payload: Record<string, unknown>): boolean {
51
+ function hasGrokSearchFields(payload: Payload): boolean {
46
52
  return (
47
53
  Object.hasOwn(payload, "search_parameters") ||
48
54
  Object.hasOwn(payload, "web_search_options")
@@ -76,12 +82,12 @@ function applyGrokSearch(writer: PayloadWriter): void {
76
82
  * preserved. Pi drops requested sources, so GPT injection deliberately does
77
83
  * not request them.
78
84
  */
79
- export function applyBuiltinSearchTool(
80
- payload: unknown,
85
+ export function applyBuiltinSearchTool<T>(
86
+ payload: T,
81
87
  modelId: string,
82
88
  api: string,
83
89
  mode: WebSearchMode,
84
- ): unknown {
90
+ ): T | Payload {
85
91
  if (!isPlainObject(payload) || mode === "off") return payload;
86
92
  const writer = new PayloadWriter(payload);
87
93
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-tsgw",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "Pi extension for the TOSSP AIH gateway: per-vendor model catalog and thinking operations for openai-completions, openai-responses, anthropic-messages, and google-generative-ai wire protocols.",
5
5
  "type": "module",
6
6
  "keywords": [