pi-tsgw 0.4.2 → 0.5.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/README.md
CHANGED
|
@@ -124,9 +124,23 @@ GLM 5.3 仅支持文本。注册并不证明网关支持推理或工具调用。
|
|
|
124
124
|
请保留 `MiniMax-*` 的大小写。网关目录可用时,先与静态目录取交集,再应用过滤。
|
|
125
125
|
纳入规则无法添加未知或不可用的 ID。
|
|
126
126
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
127
|
+
插件启动时复用 **7 天**内的缓存;缓存过期才联网刷新。工具调用复用 **24 小时**内的缓存。
|
|
128
|
+
宿主额外的非强制后台同步沿用已登记目录,不追加联网请求;需要获取新目录时调用工具
|
|
129
|
+
或强制刷新。所有入口使用同一份缓存,命中缓存和
|
|
130
|
+
失败回退均不更新原始获取时间。单次联网超时 **5 秒**;仅启动时无有效作用域缓存
|
|
131
|
+
允许失败后重试一次,其余情况不自动重试。
|
|
132
|
+
启动有旧缓存时刷新失败会沿用缓存;无缓存且两次失败时正常加载,但 TSGW 登记零个模型,
|
|
133
|
+
不回退静态目录。启动失败提示通过宿主 `ui.notify` 发出(Pi Web Toast),提醒择机强制刷新;
|
|
134
|
+
非 UI 模式仍可使用且保留状态诊断。缺少可解析凭据时不联网、不登记模型。
|
|
135
|
+
运行 `/tsgw-refresh` 可绕过缓存立即强制刷新,无需重启或重新加载 Pi;成功后可恢复目录。
|
|
136
|
+
动态刷新失败保留最近已登记的列表。
|
|
137
|
+
|
|
138
|
+
模型可通过 codemode 调用 `tools.tsgw_refresh_models({})` 自动获取,
|
|
139
|
+
或 `tools.tsgw_refresh_models({ force: true })` 强制刷新。
|
|
140
|
+
工具返回 `cacheFilePath`、`count` 与 `storedAt`,随后读取该文件的 `ids` 即为完整网关列表,
|
|
141
|
+
包括尚未静态登记的型号;不会把完整列表重复塞入工具返回值,也不会自动登记未知型号。
|
|
142
|
+
工具确认文件符合当前缓存窗口;强制刷新时要求本次写入。取消、刷新失败或未确认落盘时
|
|
143
|
+
不会把旧文件报成本次刷新成功。
|
|
130
144
|
|
|
131
145
|
内存和磁盘缓存通过 SHA-256 摘要限定在网关根地址与凭据对应的作用域内;不存储明文凭据。
|
|
132
146
|
磁盘缓存仅有一个槽位,位于 `<agent-dir>/tsgw/models-cache.json`:改变作用域可能需要
|
|
@@ -9,7 +9,8 @@ import {
|
|
|
9
9
|
import { dirname, resolve } from "node:path";
|
|
10
10
|
|
|
11
11
|
export const DEFAULT_GATEWAY_MODEL_TIMEOUT_MS = 5_000;
|
|
12
|
-
export const DEFAULT_GATEWAY_MODEL_CACHE_TTL_MS =
|
|
12
|
+
export const DEFAULT_GATEWAY_MODEL_CACHE_TTL_MS = 24 * 60 * 60 * 1_000;
|
|
13
|
+
export const STARTUP_GATEWAY_MODEL_CACHE_TTL_MS = 7 * DEFAULT_GATEWAY_MODEL_CACHE_TTL_MS;
|
|
13
14
|
|
|
14
15
|
export type GatewayModelFailureReason =
|
|
15
16
|
| "http"
|
|
@@ -34,6 +35,10 @@ export interface FetchGatewayModelIdsOptions {
|
|
|
34
35
|
export interface GetGatewayModelIdsOptions extends FetchGatewayModelIdsOptions {
|
|
35
36
|
cacheFilePath?: string;
|
|
36
37
|
force?: boolean;
|
|
38
|
+
/** 各入口独立判断新鲜度,但共用原始获取时间与缓存。 */
|
|
39
|
+
ttlMs?: number;
|
|
40
|
+
/** 仅启动无有效作用域缓存时允许失败后重试一次。 */
|
|
41
|
+
retryWithoutCache?: boolean;
|
|
37
42
|
}
|
|
38
43
|
|
|
39
44
|
export type FetchGatewayModelIdsResult =
|
|
@@ -187,10 +192,9 @@ export function gatewayModelCacheScope(baseUrl: string, apiKey: string): string
|
|
|
187
192
|
.digest("hex");
|
|
188
193
|
}
|
|
189
194
|
|
|
190
|
-
function
|
|
195
|
+
function readGatewayModelCacheSnapshot(
|
|
191
196
|
filePath: string,
|
|
192
|
-
|
|
193
|
-
): ModelCacheEntry | undefined {
|
|
197
|
+
): (ModelCacheEntry & { scope: string }) | undefined {
|
|
194
198
|
try {
|
|
195
199
|
const payload: unknown = JSON.parse(readFileSync(filePath, "utf8"));
|
|
196
200
|
if (!payload || typeof payload !== "object") return undefined;
|
|
@@ -200,15 +204,16 @@ function readGatewayModelCacheEntry(
|
|
|
200
204
|
ids?: unknown;
|
|
201
205
|
};
|
|
202
206
|
if (
|
|
203
|
-
|
|
207
|
+
typeof storedScope !== "string" || !storedScope ||
|
|
204
208
|
typeof storedAt !== "number" ||
|
|
205
209
|
!Number.isFinite(storedAt) ||
|
|
206
210
|
storedAt < 0 ||
|
|
207
|
-
!Array.isArray(ids) ||
|
|
211
|
+
!Array.isArray(ids) || ids.length === 0 ||
|
|
208
212
|
!ids.every((id) => typeof id === "string" && id.trim())
|
|
209
213
|
)
|
|
210
214
|
return undefined;
|
|
211
215
|
return {
|
|
216
|
+
scope: storedScope,
|
|
212
217
|
storedAt,
|
|
213
218
|
ids: Array.from(new Set(ids.map((id) => id.trim()))),
|
|
214
219
|
};
|
|
@@ -217,6 +222,27 @@ function readGatewayModelCacheEntry(
|
|
|
217
222
|
}
|
|
218
223
|
}
|
|
219
224
|
|
|
225
|
+
function readGatewayModelCacheEntry(
|
|
226
|
+
filePath: string,
|
|
227
|
+
scope: string,
|
|
228
|
+
): ModelCacheEntry | undefined {
|
|
229
|
+
const snapshot = readGatewayModelCacheSnapshot(filePath);
|
|
230
|
+
if (!scope || snapshot?.scope !== scope) return undefined;
|
|
231
|
+
return { storedAt: snapshot.storedAt, ids: snapshot.ids };
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** 刷新后的文件摘要;只确认可读性与获取时间,不用于恢复目录或认证作用域。 */
|
|
235
|
+
export function readGatewayModelCacheSummary(
|
|
236
|
+
cacheFilePath: string,
|
|
237
|
+
minimumStoredAt: number,
|
|
238
|
+
): { cacheFilePath: string; count: number; storedAt: number } | undefined {
|
|
239
|
+
if (!Number.isFinite(minimumStoredAt) || minimumStoredAt < 0) return undefined;
|
|
240
|
+
const snapshot = readGatewayModelCacheSnapshot(cacheFilePath);
|
|
241
|
+
if (!snapshot || !snapshot.ids.length || snapshot.storedAt < minimumStoredAt)
|
|
242
|
+
return undefined;
|
|
243
|
+
return { cacheFilePath, count: snapshot.ids.length, storedAt: snapshot.storedAt };
|
|
244
|
+
}
|
|
245
|
+
|
|
220
246
|
function isCacheEntryFresh(
|
|
221
247
|
entry: ModelCacheEntry,
|
|
222
248
|
now: number,
|
|
@@ -289,7 +315,7 @@ function cacheFor(key: string): ModelCache {
|
|
|
289
315
|
}
|
|
290
316
|
|
|
291
317
|
/**
|
|
292
|
-
* 加载网关模型 ID
|
|
318
|
+
* 加载网关模型 ID,默认有效期为 24 小时;启动入口可指定 7 天。
|
|
293
319
|
*
|
|
294
320
|
* 缓存未过期时直接返回,不进行输入输出。刷新失败时,若有过期缓存则回退使用;
|
|
295
321
|
* 否则返回获取失败的结果。
|
|
@@ -302,9 +328,12 @@ export async function getGatewayModelIds(
|
|
|
302
328
|
): Promise<GetGatewayModelIdsResult> {
|
|
303
329
|
if (opts.signal?.aborted) return { ok: false, reason: "aborted" };
|
|
304
330
|
const key = gatewayModelCacheScope(baseUrl, apiKey);
|
|
331
|
+
const ttlMs = opts.ttlMs ?? DEFAULT_GATEWAY_MODEL_CACHE_TTL_MS;
|
|
332
|
+
if (!Number.isFinite(ttlMs) || ttlMs < 0) throw new RangeError("ttlMs 必须是非负有限数值");
|
|
305
333
|
const cache = cacheFor(key);
|
|
306
|
-
|
|
307
|
-
|
|
334
|
+
const memoryEntryBefore = cache.get();
|
|
335
|
+
if (!opts.force && memoryEntryBefore && isCacheEntryFresh(memoryEntryBefore, now, ttlMs)) {
|
|
336
|
+
const entry = memoryEntryBefore;
|
|
308
337
|
if (entry)
|
|
309
338
|
return {
|
|
310
339
|
ok: true,
|
|
@@ -321,7 +350,7 @@ export async function getGatewayModelIds(
|
|
|
321
350
|
if (
|
|
322
351
|
!opts.force &&
|
|
323
352
|
diskEntry &&
|
|
324
|
-
isCacheEntryFresh(diskEntry, now,
|
|
353
|
+
isCacheEntryFresh(diskEntry, now, ttlMs)
|
|
325
354
|
) {
|
|
326
355
|
cache.set(diskEntry.ids, diskEntry.storedAt);
|
|
327
356
|
return {
|
|
@@ -333,7 +362,8 @@ export async function getGatewayModelIds(
|
|
|
333
362
|
};
|
|
334
363
|
}
|
|
335
364
|
|
|
336
|
-
const
|
|
365
|
+
const retry = opts.retryWithoutCache === true && !memoryEntryBefore && !diskEntry;
|
|
366
|
+
const requestKey = `${key}\0${opts.force ? "force" : "normal"}\0${retry}\0${opts.timeoutMs ?? DEFAULT_GATEWAY_MODEL_TIMEOUT_MS}`;
|
|
337
367
|
// 共享请求无法安全地继承某个调用者的 AbortSignal:较新的调用者仍在等待时,
|
|
338
368
|
// Pi 可能已替换该次刷新。只有不带信号的调用共享进行中的请求;
|
|
339
369
|
// 可取消的调用独立发起获取请求。
|
|
@@ -345,11 +375,11 @@ export async function getGatewayModelIds(
|
|
|
345
375
|
request = {
|
|
346
376
|
revision: requestRevision,
|
|
347
377
|
storedAt: now,
|
|
348
|
-
promise:
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
}),
|
|
378
|
+
promise: (async () => {
|
|
379
|
+
const first = await fetchGatewayModelIds(baseUrl, apiKey, opts);
|
|
380
|
+
if (first.ok || !retry || first.reason === "aborted" || opts.signal?.aborted) return first;
|
|
381
|
+
return fetchGatewayModelIds(baseUrl, apiKey, opts);
|
|
382
|
+
})(),
|
|
353
383
|
};
|
|
354
384
|
if (shareRequest) inFlightRequests.set(requestKey, request);
|
|
355
385
|
}
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
normalizeRoot,
|
|
20
20
|
type ModelFilter,
|
|
21
21
|
} from "../models/catalog.ts";
|
|
22
|
-
import { getGatewayModelIds } from "../models/gateway-catalog.ts";
|
|
22
|
+
import { getGatewayModelIds, STARTUP_GATEWAY_MODEL_CACHE_TTL_MS } from "../models/gateway-catalog.ts";
|
|
23
23
|
import { applyModelOperations } from "../models/operations.ts";
|
|
24
24
|
import { registerSearch } from "../search/index.ts";
|
|
25
25
|
import { IMAGE_API, imageModelsForRoot, supportsImageModels } from "../images/models.ts";
|
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
} from "./status.ts";
|
|
33
33
|
import type { ThinkingLevel, WebSearchMode } from "../models/_tools.ts";
|
|
34
34
|
import type { TsgwSettings } from "./config.ts";
|
|
35
|
+
import { registerRefreshTool } from "./refresh-tool.ts";
|
|
35
36
|
|
|
36
37
|
/**
|
|
37
38
|
* 在生命周期上下文仍有效时,复制供应商钩子所需的数据。
|
|
@@ -121,13 +122,13 @@ function effectiveModelsForGateway(
|
|
|
121
122
|
];
|
|
122
123
|
const intersected = gatewayIds
|
|
123
124
|
? staticModels.filter((model) => gatewayHasModel(gatewayIds, model.id))
|
|
124
|
-
:
|
|
125
|
+
: [];
|
|
125
126
|
return filterModels(intersected, filter);
|
|
126
127
|
}
|
|
127
128
|
|
|
128
129
|
/**
|
|
129
130
|
* 三层模型过滤:静态目录 ∩ 网关实际列表 ∩ 用户黑白名单。
|
|
130
|
-
*
|
|
131
|
+
* 无网关目录时不登记模型,避免将静态登记误认为网关可用。
|
|
131
132
|
*/
|
|
132
133
|
async function resolveEffectiveModels(
|
|
133
134
|
root: string,
|
|
@@ -139,7 +140,7 @@ async function resolveEffectiveModels(
|
|
|
139
140
|
gatewayIds: ReadonlySet<string> | undefined;
|
|
140
141
|
catalog: CatalogStatus;
|
|
141
142
|
}> {
|
|
142
|
-
//
|
|
143
|
+
// 凭据解析失败不阻塞插件加载,但不登记未经网关确认的模型。
|
|
143
144
|
let apiKey = "";
|
|
144
145
|
try {
|
|
145
146
|
const credential = readStoredCredential(PROVIDER_ID);
|
|
@@ -149,11 +150,15 @@ async function resolveEffectiveModels(
|
|
|
149
150
|
}
|
|
150
151
|
|
|
151
152
|
let gatewayIds: ReadonlySet<string> | undefined;
|
|
152
|
-
let catalog: CatalogStatus = { count: 0, source: "
|
|
153
|
+
let catalog: CatalogStatus = { count: 0, source: "empty", loading: false,
|
|
154
|
+
ttlMs: STARTUP_GATEWAY_MODEL_CACHE_TTL_MS,
|
|
155
|
+
error: "模型目录获取失败,当前无可用模型;请配置凭据后择机强制刷新。" };
|
|
153
156
|
if (apiKey) {
|
|
154
157
|
try {
|
|
155
158
|
const gateway = await getGatewayModelIds(root, apiKey, {
|
|
156
159
|
cacheFilePath,
|
|
160
|
+
ttlMs: STARTUP_GATEWAY_MODEL_CACHE_TTL_MS,
|
|
161
|
+
retryWithoutCache: true,
|
|
157
162
|
});
|
|
158
163
|
if (gateway.ok) {
|
|
159
164
|
gatewayIds = new Set(gateway.ids);
|
|
@@ -162,11 +167,11 @@ async function resolveEffectiveModels(
|
|
|
162
167
|
source: gateway.cached ? "cache" : "network",
|
|
163
168
|
storedAt: gateway.storedAt,
|
|
164
169
|
error: gateway.stale
|
|
165
|
-
?
|
|
170
|
+
? "模型目录刷新失败,已沿用缓存,请择机强制刷新。" : undefined,
|
|
166
171
|
};
|
|
167
|
-
} else catalog.error =
|
|
172
|
+
} else catalog.error = "模型目录获取失败,当前无可用模型,请择机强制刷新。";
|
|
168
173
|
} catch {
|
|
169
|
-
catalog.error = "
|
|
174
|
+
catalog.error = "模型目录获取失败,当前无可用模型,请择机强制刷新。";
|
|
170
175
|
}
|
|
171
176
|
}
|
|
172
177
|
if (catalog.error) console.warn(`TSGW: ${catalog.error}`);
|
|
@@ -189,6 +194,7 @@ export async function registerTsgwProvider(
|
|
|
189
194
|
exclude: settings.excludeModels,
|
|
190
195
|
};
|
|
191
196
|
const cacheFilePath = gatewayModelCachePath();
|
|
197
|
+
registerRefreshTool(pi, cacheFilePath);
|
|
192
198
|
let requestState: RequestState | undefined;
|
|
193
199
|
|
|
194
200
|
const refreshRequestState = (ctx: {
|
|
@@ -208,6 +214,7 @@ export async function registerTsgwProvider(
|
|
|
208
214
|
const { models } = initial;
|
|
209
215
|
let latestModels = models;
|
|
210
216
|
let catalog = initial.catalog;
|
|
217
|
+
let startupNotice = initial.catalog.error;
|
|
211
218
|
let credentialConfigured = false;
|
|
212
219
|
let publishStatus: (() => void) | undefined;
|
|
213
220
|
let refreshRevision = 0;
|
|
@@ -247,7 +254,9 @@ export async function registerTsgwProvider(
|
|
|
247
254
|
models,
|
|
248
255
|
...(imagesEnabled ? { images: { [IMAGE_API]: { generateImages } } } : {}),
|
|
249
256
|
async refreshModels(context) {
|
|
250
|
-
|
|
257
|
+
// 启动获取已完成;宿主的额外自动同步不再追加联网请求。
|
|
258
|
+
// 工具检查 24 小时窗口,必要时与命令一样显式传入 force。
|
|
259
|
+
if (!context.allowNetwork || context.force !== true) return latestModels;
|
|
251
260
|
context.signal.throwIfAborted();
|
|
252
261
|
const revision = ++refreshRevision;
|
|
253
262
|
catalog = { ...catalog, loading: true };
|
|
@@ -263,11 +272,10 @@ export async function registerTsgwProvider(
|
|
|
263
272
|
signal: context.signal,
|
|
264
273
|
});
|
|
265
274
|
context.signal.throwIfAborted();
|
|
266
|
-
if (!gateway.ok)
|
|
267
|
-
throw new Error(`TSGW 网关模型刷新失败(${gateway.reason})。`);
|
|
268
|
-
if (gateway.stale)
|
|
275
|
+
if (!gateway.ok || gateway.stale)
|
|
269
276
|
throw new Error("TSGW 刷新失败;保留上次成功获取的目录。");
|
|
270
277
|
if (revision === refreshRevision) {
|
|
278
|
+
startupNotice = undefined;
|
|
271
279
|
latestModels = effectiveModelsForGateway(root, modelFilter, new Set(gateway.ids), imagesEnabled);
|
|
272
280
|
search.sync();
|
|
273
281
|
catalog = {
|
|
@@ -370,6 +378,10 @@ export async function registerTsgwProvider(
|
|
|
370
378
|
refreshRequestState(ctx);
|
|
371
379
|
search.sync();
|
|
372
380
|
bindStatus(ctx);
|
|
381
|
+
if (startupNotice && ctx.hasUI) {
|
|
382
|
+
ctx.ui.notify(startupNotice, "warning");
|
|
383
|
+
startupNotice = undefined;
|
|
384
|
+
}
|
|
373
385
|
});
|
|
374
386
|
pi.on("agent_start", (_event, ctx) => {
|
|
375
387
|
refreshRequestState(ctx);
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { Type } from "typebox";
|
|
3
|
+
import { PROVIDER_ID } from "../models/catalog.ts";
|
|
4
|
+
import { DEFAULT_GATEWAY_MODEL_CACHE_TTL_MS, readGatewayModelCacheSummary } from "../models/gateway-catalog.ts";
|
|
5
|
+
|
|
6
|
+
/** 默认检查缓存时间;需要联网时复用宿主 provider 的强制刷新。 */
|
|
7
|
+
export function registerRefreshTool(pi: ExtensionAPI, cacheFilePath: string): void {
|
|
8
|
+
pi.registerTool({
|
|
9
|
+
name: "tsgw_refresh_models",
|
|
10
|
+
label: "刷新 TSGW 模型目录",
|
|
11
|
+
description: "获取 AIH 网关可用模型,默认复用 24 小时内的缓存;force=true 忽略有效期强制联网刷新。单次联网超时 5 秒,不发推理请求、不修改配置、不自动重试。返回缓存文件路径、网关模型数与获取时间;随后读取该文件的 ids 获取完整列表(含插件尚未登记的型号)。不自动登记未知型号。",
|
|
12
|
+
parameters: Type.Object({
|
|
13
|
+
force: Type.Optional(Type.Boolean({ description: "忽略缓存有效期强制联网刷新,默认 false。" })),
|
|
14
|
+
}),
|
|
15
|
+
outputSchema: Type.Object({
|
|
16
|
+
cacheFilePath: Type.String(), count: Type.Integer(), storedAt: Type.Number(),
|
|
17
|
+
}),
|
|
18
|
+
exposure: "codemode",
|
|
19
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true },
|
|
20
|
+
async execute(_id, params, signal, _onUpdate, ctx) {
|
|
21
|
+
const caller = signal && ctx.signal && signal !== ctx.signal
|
|
22
|
+
? AbortSignal.any([signal, ctx.signal]) : signal ?? ctx.signal;
|
|
23
|
+
const registry = ctx.modelRegistry;
|
|
24
|
+
const startedAt = Date.now();
|
|
25
|
+
let details;
|
|
26
|
+
let refreshed;
|
|
27
|
+
try {
|
|
28
|
+
caller?.throwIfAborted();
|
|
29
|
+
if (!registry.getProviderAuthStatus(PROVIDER_ID).configured) throw new Error("缺少凭据");
|
|
30
|
+
if (params.force !== true)
|
|
31
|
+
details = readGatewayModelCacheSummary(cacheFilePath, startedAt - DEFAULT_GATEWAY_MODEL_CACHE_TTL_MS + 1);
|
|
32
|
+
if (!details) {
|
|
33
|
+
refreshed = await registry.refresh({ providers: [PROVIDER_ID], force: true, signal: caller });
|
|
34
|
+
caller?.throwIfAborted();
|
|
35
|
+
}
|
|
36
|
+
} catch {
|
|
37
|
+
throw new Error(caller?.aborted ? "TSGW 模型刷新已取消。" : "TSGW 模型刷新失败;请检查宿主凭据、网关与网络。未输出原始错误。");
|
|
38
|
+
}
|
|
39
|
+
if (refreshed?.aborted) throw new Error("TSGW 模型刷新已取消。");
|
|
40
|
+
if (refreshed?.errors?.has(PROVIDER_ID))
|
|
41
|
+
throw new Error("TSGW 模型刷新失败,保留原目录;请检查宿主凭据、网关与网络。");
|
|
42
|
+
details ??= readGatewayModelCacheSummary(cacheFilePath, startedAt);
|
|
43
|
+
if (!details)
|
|
44
|
+
throw new Error("未确认本次完整网关目录已写入缓存文件;不能将旧文件当作本次刷新结果。provider 可能已经更新。");
|
|
45
|
+
return { content: [{ type: "text", text: JSON.stringify(details) }], details, structuredContent: details };
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
}
|
|
@@ -3,7 +3,9 @@ import { DEFAULT_GATEWAY_MODEL_CACHE_TTL_MS } from "../models/gateway-catalog.ts
|
|
|
3
3
|
|
|
4
4
|
export interface CatalogStatus {
|
|
5
5
|
count: number;
|
|
6
|
-
source: "static" | "cache" | "network";
|
|
6
|
+
source: "static" | "empty" | "cache" | "network";
|
|
7
|
+
/** 当前入口采用的新鲜度窗口;启动为 7 天,运行时为 24 小时。 */
|
|
8
|
+
ttlMs?: number;
|
|
7
9
|
/** 网关目录真实获取时间;从缓存读取时保留原值,不重置为读取时间。 */
|
|
8
10
|
storedAt?: number;
|
|
9
11
|
loading: boolean;
|
|
@@ -13,6 +15,7 @@ export interface CatalogStatus {
|
|
|
13
15
|
|
|
14
16
|
const SOURCE_LABELS = {
|
|
15
17
|
static: "内置静态",
|
|
18
|
+
empty: "无可用目录",
|
|
16
19
|
cache: "缓存",
|
|
17
20
|
network: "网关",
|
|
18
21
|
} as const;
|
|
@@ -20,7 +23,7 @@ const SOURCE_LABELS = {
|
|
|
20
23
|
function fetchedAt(state: CatalogStatus): number | undefined {
|
|
21
24
|
const time = state.storedAt;
|
|
22
25
|
if (
|
|
23
|
-
state.source === "static" ||
|
|
26
|
+
(state.source === "static" || state.source === "empty") ||
|
|
24
27
|
time === undefined ||
|
|
25
28
|
!Number.isFinite(time) ||
|
|
26
29
|
time < 0 ||
|
|
@@ -33,7 +36,7 @@ function freshness(state: CatalogStatus, now: number): "新鲜" | "过期" | "
|
|
|
33
36
|
const time = fetchedAt(state);
|
|
34
37
|
if (time === undefined || !Number.isFinite(now)) return "未知";
|
|
35
38
|
// 与目录缓存一致:时钟回拨不判过期,达到 TTL 则过期。
|
|
36
|
-
return Math.max(0, now - time) < DEFAULT_GATEWAY_MODEL_CACHE_TTL_MS
|
|
39
|
+
return Math.max(0, now - time) < (state.ttlMs ?? DEFAULT_GATEWAY_MODEL_CACHE_TTL_MS)
|
|
37
40
|
? "新鲜"
|
|
38
41
|
: "过期";
|
|
39
42
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-tsgw",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "面向 TOSSP AIH gateway 的 Pi 扩展:按厂商维护聊天与图片模型目录及思考策略,支持四种聊天协议与图片生成、编辑工具。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
]
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
|
-
"test": "tsc -p tsconfig.test.json && node dist/extensions/provider/index.test.js && node dist/extensions/prompts.test.js && node dist/extensions/provider/status.test.js && node dist/extensions/search/index.test.js && node dist/extensions/search/proxy.test.js && node dist/extensions/search/host-integration.test.js && node dist/extensions/provider/status-integration.test.js && node dist/extensions/models/gateway-catalog-metadata.test.js && node dist/extensions/models/operations.test.js && node dist/extensions/models/catalog.test.js && node dist/extensions/models/web-search.test.js && node dist/extensions/models/gateway-catalog.test.js && node dist/extensions/models/gateway-catalog-isolation.test.js && node dist/extensions/models/vendor-strategies.test.js && node dist/extensions/images/models.test.js && node dist/extensions/images/parameters.test.js && node dist/extensions/images/input-budget.test.js && node dist/extensions/images/edit-request.test.js && node dist/extensions/images/image-data.test.js && node dist/extensions/images/response.test.js && node dist/extensions/images/stream-response.test.js && node dist/extensions/images/adapter.test.js && node dist/extensions/images/tool-files.test.js && node dist/extensions/images/tools.test.js && node dist/extensions/images/host-integration.test.js && node dist/extensions/images/tools-host.test.js && node dist/index.test.js && node dist/extensions/skills.test.js && node dist/extensions/skill-resources.test.js && node dist/extensions/upload/protocol.test.js && node dist/extensions/upload/schema.test.js && node dist/extensions/upload/uploader.test.js && node dist/extensions/upload/transport.test.js && node dist/extensions/upload/host-integration.test.js && node dist/extensions/upload/readiness-host.test.js",
|
|
27
|
+
"test": "tsc -p tsconfig.test.json && node dist/extensions/provider/index.test.js && node dist/extensions/provider/refresh-tool.test.js && node dist/extensions/provider/startup-catalog.test.js && node dist/extensions/prompts.test.js && node dist/extensions/provider/status.test.js && node dist/extensions/search/index.test.js && node dist/extensions/search/proxy.test.js && node dist/extensions/search/host-integration.test.js && node dist/extensions/provider/status-integration.test.js && node dist/extensions/models/gateway-catalog-metadata.test.js && node dist/extensions/models/gateway-catalog-policy.test.js && node dist/extensions/models/operations.test.js && node dist/extensions/models/catalog.test.js && node dist/extensions/models/web-search.test.js && node dist/extensions/models/gateway-catalog.test.js && node dist/extensions/models/gateway-catalog-isolation.test.js && node dist/extensions/models/vendor-strategies.test.js && node dist/extensions/images/models.test.js && node dist/extensions/images/parameters.test.js && node dist/extensions/images/input-budget.test.js && node dist/extensions/images/edit-request.test.js && node dist/extensions/images/image-data.test.js && node dist/extensions/images/response.test.js && node dist/extensions/images/stream-response.test.js && node dist/extensions/images/adapter.test.js && node dist/extensions/images/tool-files.test.js && node dist/extensions/images/tools.test.js && node dist/extensions/images/host-integration.test.js && node dist/extensions/images/tools-host.test.js && node dist/index.test.js && node dist/extensions/skills.test.js && node dist/extensions/skill-resources.test.js && node dist/extensions/upload/protocol.test.js && node dist/extensions/upload/schema.test.js && node dist/extensions/upload/uploader.test.js && node dist/extensions/upload/transport.test.js && node dist/extensions/upload/host-integration.test.js && node dist/extensions/upload/readiness-host.test.js",
|
|
28
28
|
"test:upload:live": "tsc -p tsconfig.test.json && node dist/extensions/upload/live.test.js"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|