pi-tsgw 1.0.0 → 1.0.1

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
@@ -83,8 +83,9 @@ pi install npm:pi-tsgw
83
83
  `~/.pi/agent/auth.json` 中(推荐方式)。
84
84
  2. **`TSGW_API_KEY` 环境变量** — 未存储凭据时由 Pi 回退使用。
85
85
 
86
- 启动时的发现使用 Pi 的已存储凭据 API;后续目录刷新使用 Pi 提供的凭据。
87
- 如果仅通过环境变量认证,初始目录可能回退到静态模型,直到 Pi 刷新目录。
86
+ 初始化通过 Pi 的已存储凭据 API 校验并读取本地目录;后续刷新使用宿主提供的凭据。
87
+ 两条解析路径不保证完全等价:仅通过环境变量认证时,初始化可能先登记零模型,
88
+ 会话就绪后再由宿主解析凭据并恢复目录,不回退静态模型。
88
89
 
89
90
  ### 选项
90
91
 
@@ -161,27 +162,49 @@ GLM 5.3 仅支持文本。注册并不证明网关支持推理或工具调用。
161
162
  请保留 `MiniMax-*` 的大小写。网关目录可用时,先与静态目录取交集,再应用过滤。
162
163
  纳入规则无法添加未知或不可用的 ID。
163
164
 
164
- 插件启动时复用 **7 天**内的缓存;缓存过期才联网刷新。工具调用复用 **24 小时**内的缓存。
165
- 宿主额外的非强制后台同步沿用已登记目录,不追加联网请求;需要获取新目录时调用工具
166
- 或强制刷新。所有入口使用同一份缓存,命中缓存和
167
- 失败回退均不更新原始获取时间。单次联网超时 **5 秒**;仅启动时无有效作用域缓存
168
- 允许失败后重试一次,其余情况不自动重试。
169
- 启动有旧缓存时刷新失败会沿用缓存;无缓存且两次失败时正常加载,但 TSGW 登记零个模型,
170
- 不回退静态目录。启动失败提示通过宿主 `ui.notify` 发出(Pi Web Toast),提醒择机强制刷新;
171
- 非 UI 模式仍可使用且保留状态诊断。缺少可解析凭据时不联网、不登记模型。
172
- 运行 `/tsgw-refresh` 可绕过缓存立即强制刷新,无需重启或重新加载 Pi;成功后可恢复目录。
173
- 动态刷新失败保留最近已登记的列表。
165
+ 插件初始化只读取本地缓存、完成 provider 注册,**不等待网络**:有可用缓存就先加载,
166
+ 包括过期缓存;无有效缓存则先登记零个模型,不回退静态目录,也不阻塞宿主启动。
167
+ 所有入口统一使用 **24 小时**新鲜窗口;内存与磁盘同时存在时选择获取时间更新的快照,
168
+ 命中缓存和失败回退均不更新原始获取时间。
169
+
170
+ 会话就绪且宿主允许联网后,缺少缓存或缓存过期时后台获取目录。单次请求超时 **5 秒**,
171
+ 失败后间隔 **5 秒**重试;整轮请求与等待合计最多 **60 秒**。同进程的实例共用恢复轮次与重试序列,
172
+ 后来加入不延长共享截止;每个实例仍以自身启动的一分钟窗口约束本地准备、等待与登记。
173
+ 获取始终通过仍活跃实例的宿主服务执行,以保留联网许可和凭据解析。成功后各实例通过宿主同步自己的模型登记,
174
+ 停止重试并清除异常状态。缺少凭据或认证失败直接提示,不等待一分钟;宿主禁止联网时不绕过许可。
175
+ 一分钟内仍未获取成功则停止自动请求,通过 `ui.notify(..., "error")` 发出红色 Pi Web Toast,
176
+ 同时保留红色异常状态。有旧目录时提示正在沿用缓存,无缓存时提示当前无可用模型。
177
+ 同一轮失败只提醒一次;Toast 不代表用户已读,非 UI 模式使用安全日志提示。
178
+ 会话退出或实例替换时取消恢复;不建立常驻轮询,不自动重试推理。
179
+
180
+ 运行 `/tsgw-refresh` 可绕过缓存强制刷新,无需重启或重新加载 Pi;手动刷新不自动重试。
181
+ 单个插件实例发起的后台恢复、命令和工具刷新共用一个登记调度器:同类请求合并;普通获取已经联网时,
182
+ 后来的强制刷新复用同一请求,不再重复 GET;尚未决定读取缓存时,强制意图提升本轮网络阶段。
183
+ 已命中缓存并完成的普通获取不能满足新的强制刷新。实际获取层也合并已进入插件的宿主回调,
184
+ 一个调用方取消只退出自己的等待,仍有其他调用方等待时不取消共享任务。
185
+ Pi Web 多会话和后台 runtime 可分别加载插件;同一 JS 全局环境、同一 agent-dir 的实例
186
+ 通过进程级服务共用原始目录与实际 GET,即使模块被重新导入也不重复建立获取任务。
187
+ 各实例仍分别应用模型过滤与宿主能力、同步自己的登记和 UI;退出一个实例不取消其他实例的等待。
188
+ 仅共享获取不代表所有宿主登记入口已全局串行。宿主在首次回调之前
189
+ 自行进行的刷新重组不属于插件可观察的队列。
190
+ Pi Web 的目录刷新入口与聊天会话使用独立 runtime;并发获取在共享服务合并,
191
+ 结果分别登记到对应 runtime,不把两者假设成同一个宿主刷新队列。
192
+ 动态刷新失败保留原目录。旧版宿主若不转发强制刷新参数,未确认实际联网时只提示未完成刷新,
193
+ 不误报成功;不提高聊天最低宿主版本。另一个会话更新缓存后,当前会话在下次目录检查时吸收更新,
194
+ 不提供跨会话实时广播。
174
195
 
175
196
  模型可通过 codemode 调用 `tools.tsgw_refresh_models({})` 自动获取,
176
197
  或 `tools.tsgw_refresh_models({ force: true })` 强制刷新。
177
198
  工具返回 `cacheFilePath`、`count` 与 `storedAt`,随后读取该文件的 `ids` 即为完整网关列表,
178
199
  包括尚未静态登记的型号;不会把完整列表重复塞入工具返回值,也不会自动登记未知型号。
179
- 工具确认文件符合当前缓存窗口;强制刷新时要求本次写入。取消、刷新失败或未确认落盘时
180
- 不会把旧文件报成本次刷新成功。
181
-
182
- 内存和磁盘缓存通过 SHA-256 摘要限定在网关根地址与凭据对应的作用域内;不存储明文凭据。
183
- 磁盘缓存仅有一个槽位,位于 `<agent-dir>/tsgw/models-cache.json`:改变作用域可能需要
184
- 重新获取。旧版无作用域缓存文件会被忽略,并在获取成功后替换。
200
+ 工具每次都经宿主刷新流程同步当前目录,缓存是否可用统一由 provider 判断。
201
+ 返回的文件必须属于当前配置且对应已应用的完整快照;强制刷新时要求本次写入。
202
+ 取消、获取失败或未确认落盘时,不会把旧文件报成本次刷新成功。
203
+
204
+ 插件仅注册一个 `tsgw` provider,使用一个当前密钥。缓存文件固定为
205
+ `<agent-dir>/tsgw/models-cache.json`,不提供多配置或多槽位管理。
206
+ 网关地址与密钥仅以 SHA-256 摘要校验,避免更换配置后误用旧缓存,不存储明文凭据。
207
+ 旧版无摘要缓存会被忽略,并在获取成功后替换。
185
208
  进程内请求排序可防止较晚返回的结果覆盖更新的缓存写入;这不是跨进程锁机制。
186
209
 
187
210
  ## 原生图片生成
@@ -253,7 +276,7 @@ text(result.stopReason === "stop" ? result.answers : { error: result.errorMessag
253
276
 
254
277
  - **`TSGW · N`**(`/tsgw`):在同一菜单中**刷新模型目录**和**查看诊断信息**。
255
278
  数量表示过滤后已注册的聊天、图片与分类目录条目数,而非健康推理端点的数量。
256
- 🟢 表示新鲜的目录结果;🟡 表示静态/过期目录或刷新失败;⚠️ 表示缺少凭据或网关配置;
279
+ 🟢 表示新鲜的目录结果;🟡 表示静态/过期目录;🔴 表示获取失败;⚠️ 表示缺少凭据或网关配置;
257
280
  ⏳ 表示正在刷新。
258
281
  - **内置联网**(`/tsgw-search`):GPT 仅为当前会话提供 `cached / live`,默认为 `live`。
259
282
  受支持的 Grok 模型固定使用实时搜索:此命令只显示提示,不提供选择器,也不改变 GPT
@@ -0,0 +1,120 @@
1
+ import type { GatewayCatalogOutcome } from "./gateway-catalog-service.ts";
2
+
3
+ export const CATALOG_RECOVERY_WINDOW_MS = 60_000;
4
+ export const CATALOG_RECOVERY_DELAY_MS = 5_000;
5
+
6
+ function cancelled(): Error {
7
+ const error = new Error("TSGW 模型目录获取已取消。");
8
+ error.name = "AbortError";
9
+ return error;
10
+ }
11
+
12
+ interface RecoveryParticipant {
13
+ request(signal: AbortSignal): Promise<GatewayCatalogOutcome>;
14
+ }
15
+
16
+ interface RecoveryRound {
17
+ controller: AbortController;
18
+ waiters: number;
19
+ participants: Set<RecoveryParticipant>;
20
+ promise: Promise<GatewayCatalogOutcome>;
21
+ }
22
+
23
+ /** 进程共享服务内的一轮恢复;新加入者不延长截止,手动获取不触发重试。 */
24
+ export function createGatewayCatalogRecovery(options: { onIdle?(): void } = {}) {
25
+ let active: RecoveryRound | undefined;
26
+ return {
27
+ stop() { active?.controller.abort(); active = undefined; options.onIdle?.(); },
28
+ hasParticipants: () => !!active && !active.controller.signal.aborted && active.waiters > 0,
29
+ join(
30
+ request: (signal: AbortSignal) => Promise<GatewayCatalogOutcome>,
31
+ fallback: () => GatewayCatalogOutcome,
32
+ signal?: AbortSignal,
33
+ ): Promise<GatewayCatalogOutcome> {
34
+ if (signal?.aborted) return Promise.reject(cancelled());
35
+ if (active?.controller.signal.aborted) active = undefined;
36
+ if (!active) {
37
+ const round: RecoveryRound = { controller: new AbortController(), waiters: 0, participants: new Set(),
38
+ promise: Promise.resolve({ networkAttempted: false, networkSucceeded: false, failed: true, retryable: true }) };
39
+ active = round;
40
+ let deadline: ReturnType<typeof setTimeout> | undefined;
41
+ let wake: ReturnType<typeof setTimeout> | undefined;
42
+ let cancelWait: (() => void) | undefined;
43
+ let deadlineReached = false;
44
+ let abort!: () => void;
45
+ const end = new Promise<GatewayCatalogOutcome>((resolve, reject) => {
46
+ abort = () => {
47
+ options.onIdle?.();
48
+ if (!deadlineReached) reject(cancelled());
49
+ };
50
+ round.controller.signal.addEventListener("abort", abort, { once: true });
51
+ deadline = setTimeout(() => {
52
+ deadlineReached = true;
53
+ try { resolve({ ...fallback(), failed: true }); }
54
+ catch { resolve({ networkAttempted: false, networkSucceeded: false, failed: true, retryable: true }); }
55
+ finally { round.controller.abort(); }
56
+ }, CATALOG_RECOVERY_WINDOW_MS);
57
+ deadline.unref?.();
58
+ });
59
+ const wait = (): Promise<void> => new Promise(resolve => {
60
+ cancelWait = resolve;
61
+ wake = setTimeout(() => { cancelWait = undefined; resolve(); }, CATALOG_RECOVERY_DELAY_MS);
62
+ wake.unref?.();
63
+ });
64
+ const run = Promise.resolve().then(async () => {
65
+ while (!round.controller.signal.aborted) {
66
+ try {
67
+ const participant = round.participants.values().next().value;
68
+ if (!participant) throw cancelled();
69
+ const outcome = await participant.request(round.controller.signal);
70
+ if (!outcome.failed || !outcome.retryable) return outcome;
71
+ } catch {
72
+ // 不外传获取器原始异常;取消立即结束,其他异常在本轮短间隔重试。
73
+ if (round.controller.signal.aborted) throw cancelled();
74
+ }
75
+ if (round.controller.signal.aborted) throw cancelled();
76
+ await wait();
77
+ }
78
+ throw cancelled();
79
+ });
80
+ round.promise = Promise.race([run, end]).finally(() => {
81
+ clearTimeout(deadline);
82
+ clearTimeout(wake);
83
+ cancelWait?.();
84
+ round.controller.signal.removeEventListener("abort", abort);
85
+ if (active === round) { active = undefined; options.onIdle?.(); }
86
+ });
87
+ }
88
+ const round = active;
89
+ const participant = { request };
90
+ round.participants.add(participant);
91
+ round.waiters++;
92
+ return new Promise((resolve, reject) => {
93
+ let done = false;
94
+ const finish = (): boolean => {
95
+ if (done) return false;
96
+ done = true;
97
+ signal?.removeEventListener("abort", abort);
98
+ round.waiters--;
99
+ round.participants.delete(participant);
100
+ return true;
101
+ };
102
+ const abort = (): void => {
103
+ if (!finish()) return;
104
+ if (round.waiters === 0) round.controller.abort();
105
+ reject(cancelled());
106
+ };
107
+ round.promise.then(
108
+ outcome => {
109
+ if (finish()) resolve({ ...outcome, ...(outcome.snapshot ? {
110
+ snapshot: { ...outcome.snapshot, ids: [...outcome.snapshot.ids] },
111
+ } : {}) });
112
+ },
113
+ error => { if (finish()) reject(error); },
114
+ );
115
+ if (signal?.aborted) abort();
116
+ else signal?.addEventListener("abort", abort, { once: true });
117
+ });
118
+ },
119
+ };
120
+ }
@@ -0,0 +1,217 @@
1
+ import { resolve } from "node:path";
2
+ import { createGatewayCatalogRecovery } from "./gateway-catalog-recovery.ts";
3
+ import {
4
+ DEFAULT_GATEWAY_MODEL_CACHE_TTL_MS,
5
+ gatewayModelCacheScope,
6
+ getCachedGatewayModelIds,
7
+ getGatewayModelIds,
8
+ readGatewayModelCacheSummary,
9
+ type ModelCacheEntry,
10
+ } from "./gateway-catalog.ts";
11
+
12
+ export interface GatewayCatalogSnapshot extends ModelCacheEntry {
13
+ source: "cache" | "network";
14
+ }
15
+
16
+ export interface GatewayCatalogOutcome {
17
+ snapshot?: GatewayCatalogSnapshot;
18
+ networkAttempted: boolean;
19
+ networkSucceeded: boolean;
20
+ retryable: boolean;
21
+ failed: boolean;
22
+ }
23
+
24
+ interface FetchTask {
25
+ controller: AbortController;
26
+ force: boolean;
27
+ networkStarted: boolean;
28
+ cacheSelected: boolean;
29
+ waiters: number;
30
+ promise: Promise<GatewayCatalogOutcome>;
31
+ }
32
+
33
+ export function catalogCancelledError(): Error {
34
+ const error = new Error("TSGW 模型目录获取已取消。");
35
+ error.name = "AbortError";
36
+ return error;
37
+ }
38
+
39
+ const copy = (entry: GatewayCatalogSnapshot): GatewayCatalogSnapshot => ({ ...entry, ids: [...entry.ids] });
40
+ const fresh = (entry: ModelCacheEntry): boolean =>
41
+ Math.max(0, Date.now() - entry.storedAt) < DEFAULT_GATEWAY_MODEL_CACHE_TTL_MS;
42
+
43
+ /** 等待者独立取消;不把某个宿主回调的 signal 作为整个进程的获取信号。 */
44
+ function waitForTask(task: FetchTask, signal: AbortSignal | undefined, valid: () => boolean,
45
+ keepAlive: () => boolean): Promise<GatewayCatalogOutcome> {
46
+ task.waiters++;
47
+ return new Promise((resolve, reject) => {
48
+ let done = false;
49
+ const finish = (): boolean => {
50
+ if (done) return false;
51
+ done = true;
52
+ signal?.removeEventListener("abort", abort);
53
+ task.waiters--;
54
+ return true;
55
+ };
56
+ const abort = (): void => {
57
+ if (!finish()) return;
58
+ if (task.waiters === 0 && !task.cacheSelected && !keepAlive()) task.controller.abort();
59
+ reject(catalogCancelledError());
60
+ };
61
+ task.promise.then(
62
+ result => {
63
+ if (!finish()) return;
64
+ if (task.controller.signal.aborted || !valid()) reject(catalogCancelledError());
65
+ else resolve({ ...result, ...(result.snapshot ? { snapshot: copy(result.snapshot) } : {}) });
66
+ },
67
+ error => { if (finish()) reject(error); },
68
+ );
69
+ if (signal?.aborted) abort();
70
+ else signal?.addEventListener("abort", abort, { once: true });
71
+ });
72
+ }
73
+
74
+ /** 原始目录的共享服务,不保存 UI、过滤配置、宿主 context 或常驻明文密钥。 */
75
+ function createService(root: string, scope: string, cacheFilePath: string) {
76
+ let valid = true;
77
+ let snapshot: GatewayCatalogSnapshot | undefined;
78
+ let task: FetchTask | undefined;
79
+ const recovery = createGatewayCatalogRecovery({ onIdle: () => {
80
+ if (task?.waiters === 0 && !task.cacheSelected) task.controller.abort();
81
+ } });
82
+
83
+ const check = (key: string): void => {
84
+ if (!valid || gatewayModelCacheScope(root, key) !== scope) throw catalogCancelledError();
85
+ };
86
+ const read = (key: string): GatewayCatalogSnapshot | undefined => {
87
+ check(key);
88
+ const local = getCachedGatewayModelIds(root, key, { cacheFilePath });
89
+ if (local && (!snapshot || local.storedAt > snapshot.storedAt))
90
+ snapshot = { ids: [...local.ids], storedAt: local.storedAt, source: "cache" };
91
+ return snapshot ? copy(snapshot) : undefined;
92
+ };
93
+ const currentOutcome = (networkAttempted: boolean, networkSucceeded: boolean,
94
+ failed = false, retryable = true): GatewayCatalogOutcome => ({
95
+ ...(snapshot ? { snapshot: copy(snapshot) } : {}),
96
+ networkAttempted, networkSucceeded, failed, retryable,
97
+ });
98
+
99
+ const api = {
100
+ scope,
101
+ valid: () => valid,
102
+ read,
103
+ fetching: () => !!task?.networkStarted && !task.controller.signal.aborted,
104
+ refreshKind: () => task && !task.controller.signal.aborted ? (task.force ? "force" : "normal") : undefined,
105
+ summary(minimumStoredAt = 0, applied = snapshot) {
106
+ if (!valid || !applied) return undefined;
107
+ const result = readGatewayModelCacheSummary(cacheFilePath, minimumStoredAt, scope, applied.ids);
108
+ return result?.storedAt === applied.storedAt ? result : undefined;
109
+ },
110
+ invalidate() {
111
+ valid = false;
112
+ recovery.stop();
113
+ task?.controller.abort();
114
+ task = undefined;
115
+ snapshot = undefined;
116
+ },
117
+ /** 后台通过仍活跃实例的宿主服务发起单次获取,联网许可和凭据仍交宿主。 */
118
+ recoverUsing(run: (signal: AbortSignal) => Promise<GatewayCatalogOutcome>, signal?: AbortSignal): Promise<GatewayCatalogOutcome> {
119
+ if (!valid) return Promise.reject(catalogCancelledError());
120
+ return recovery.join(run, () => currentOutcome(false, false, true), signal).then(outcome => {
121
+ if (!valid || signal?.aborted) throw catalogCancelledError();
122
+ return outcome;
123
+ });
124
+ },
125
+ peek: () => snapshot ? copy(snapshot) : undefined,
126
+ recover(key: string, signal?: AbortSignal): Promise<GatewayCatalogOutcome> {
127
+ try { check(key); } catch (error) { return Promise.reject(error); }
128
+ return recovery.join(
129
+ input => api.request(key, { allowNetwork: true, signal: input }),
130
+ () => currentOutcome(false, false, true), signal,
131
+ ).then(outcome => { check(key); if (signal?.aborted) throw catalogCancelledError(); return outcome; });
132
+ },
133
+ request(key: string, options: { force?: boolean; allowNetwork: boolean; signal?: AbortSignal }): Promise<GatewayCatalogOutcome> {
134
+ if (options.signal?.aborted) return Promise.reject(catalogCancelledError());
135
+ try { check(key); } catch (error) { return Promise.reject(error); }
136
+ // 本地读取不加入联网任务,不延迟启动,也绝不取消已有 GET。
137
+ if (!options.allowNetwork) {
138
+ read(key);
139
+ return Promise.resolve(currentOutcome(false, false));
140
+ }
141
+ if (task?.controller.signal.aborted) task = undefined;
142
+ if (task?.cacheSelected && options.force) {
143
+ // 缓存决定已经完成;这次 force 不能被旧缓存结果吞掉。
144
+ return task.promise.then(() => api.request(key, options));
145
+ }
146
+ if (task) {
147
+ task.force ||= options.force === true;
148
+ return waitForTask(task, options.signal, () => valid, recovery.hasParticipants);
149
+ }
150
+ const controller = new AbortController();
151
+ const active: FetchTask = { controller, force: options.force === true,
152
+ networkStarted: false, cacheSelected: false, waiters: 0, promise: Promise.resolve(currentOutcome(false, false)) };
153
+ task = active;
154
+ // 微任务内才决定缓存/网络,使同批 force 能提升尚未决策的 normal。
155
+ const execute = Promise.resolve().then(async () => {
156
+ controller.signal.throwIfAborted();
157
+ const cached = read(key);
158
+ if (!active.force && cached && fresh(cached)) {
159
+ active.cacheSelected = true;
160
+ return currentOutcome(false, false);
161
+ }
162
+ active.networkStarted = true;
163
+ const result = await getGatewayModelIds(root, key, {
164
+ cacheFilePath, force: true, signal: controller.signal,
165
+ });
166
+ if (!valid || task !== active || controller.signal.aborted) throw catalogCancelledError();
167
+ if (!result.ok || result.stale) {
168
+ read(key);
169
+ const code = result.ok ? result.fallbackStatus : result.status;
170
+ return currentOutcome(true, false, true, code !== 401 && code !== 403);
171
+ }
172
+ if (!snapshot || result.storedAt >= snapshot.storedAt)
173
+ snapshot = { ids: [...result.ids], storedAt: result.storedAt, source: result.cached ? "cache" : "network" };
174
+ return currentOutcome(true, !result.cached);
175
+ });
176
+ // 即使底层忽略取消,取消仍立即释放共享槽;迟到结果不能提交。
177
+ let onAbort: (() => void) | undefined;
178
+ const aborted = new Promise<never>((_, reject) => {
179
+ onAbort = () => { reject(catalogCancelledError()); };
180
+ controller.signal.addEventListener("abort", onAbort, { once: true });
181
+ });
182
+ active.promise = Promise.race([execute, aborted]).finally(() => {
183
+ if (onAbort) controller.signal.removeEventListener("abort", onAbort);
184
+ if (task === active) task = undefined;
185
+ });
186
+ return waitForTask(active, options.signal, () => valid, recovery.hasParticipants);
187
+ },
188
+ };
189
+ return api;
190
+ }
191
+
192
+ export type GatewayCatalogService = ReturnType<typeof createService>;
193
+
194
+ interface ServiceRegistry {
195
+ version: 4;
196
+ /** 每个 agent-dir 的唯一缓存路径一个当前槽,不按密钥维护多个目录。 */
197
+ slots: Map<string, GatewayCatalogService>;
198
+ }
199
+
200
+ const REGISTRY = Symbol.for("pi-tsgw:gateway-catalog");
201
+
202
+ /** 跨工厂调用与 jiti 重导入复用;不同 agent-dir 仅作宿主存储边界隔离。 */
203
+ export function getGatewayCatalogService(root: string, key: string, cacheFilePath: string): GatewayCatalogService {
204
+ const globals = globalThis as typeof globalThis & { [REGISTRY]?: ServiceRegistry };
205
+ let registry = globals[REGISTRY];
206
+ if (registry && registry.version !== 4) throw new Error("TSGW 目录共享状态版本不兼容,请重启宿主。");
207
+ registry ??= globals[REGISTRY] = { version: 4, slots: new Map() };
208
+ const path = resolve(cacheFilePath);
209
+ const scope = gatewayModelCacheScope(root, key);
210
+ let service = registry.slots.get(path);
211
+ if (!service || service.scope !== scope || !service.valid()) {
212
+ service?.invalidate();
213
+ service = createService(root, scope, path);
214
+ registry.slots.set(path, service);
215
+ }
216
+ return service;
217
+ }