@lingda-ai/dsh-plugin-ledger 0.1.9 → 0.1.10

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/lib/client.js CHANGED
@@ -1112,7 +1112,7 @@ window.__ModuleLoader__.load({
1112
1112
  function createFetchView(ctx) {
1113
1113
  return async function fetchView(sessionId, opts = {}) {
1114
1114
  if (typeof sessionId !== 'string' || sessionId.length === 0) return null
1115
- const files = optionalService(ctx, 'remote')?.workspaceFiles
1115
+ const files = workspaceFilesOf(ctx)
1116
1116
  if (!files || typeof files.stat !== 'function' || typeof files.read !== 'function') {
1117
1117
  return { error: '宿主未提供 workspaceFiles 通道' }
1118
1118
  }
@@ -1168,6 +1168,43 @@ window.__ModuleLoader__.load({
1168
1168
  }
1169
1169
  }
1170
1170
 
1171
+ /**
1172
+ * 取 workspaceFiles remote。
1173
+ *
1174
+ * 真机报错:`cannot get property "remote.workspaceFiles" without inject`。
1175
+ * 原因:remote 是按 `remote.<name>` 为 key 注册的服务,`ctx.remote.workspaceFiles`
1176
+ * 这种点号访问最终会落到 ctx 代理上做 inject 校验——没声明就抛,而它在 apply 之后、
1177
+ * 面板读取时才第一次触发(所以表现为"面板读取失败",不是启动失败)。
1178
+ *
1179
+ * 正确姿势是用 `ctx.get('remote.workspaceFiles')` 这条**不受 inject 约束**的通道
1180
+ * (cordis 自己在服务目录里就把 ctx.get 标成 optional access)。
1181
+ * 逐级兜底,任何一层抛错都当作"没有这条通道"。
1182
+ * @param {any} ctx
1183
+ * @returns {any|null}
1184
+ */
1185
+ function workspaceFilesOf(ctx) {
1186
+ if (typeof ctx?.get === 'function') {
1187
+ try {
1188
+ const direct = ctx.get('remote.workspaceFiles')
1189
+ if (direct) return direct
1190
+ } catch {
1191
+ // 某些版本只注册了命名空间,继续往下试
1192
+ }
1193
+ try {
1194
+ const namespace = ctx.get('remote')
1195
+ const files = namespace?.workspaceFiles
1196
+ if (files) return files
1197
+ } catch {
1198
+ // 命名空间访问同样可能被代理拦,忽略
1199
+ }
1200
+ }
1201
+ try {
1202
+ return ctx?.remote?.workspaceFiles ?? null
1203
+ } catch {
1204
+ return null
1205
+ }
1206
+ }
1207
+
1171
1208
  /** 把任意抛出物变成一句话。 */
1172
1209
  function stringifyError(error) {
1173
1210
  if (error instanceof Error) return error.message
package/lib/client.src.js CHANGED
@@ -142,7 +142,7 @@ import {
142
142
  export function createFetchView(ctx) {
143
143
  return async function fetchView(sessionId, opts = {}) {
144
144
  if (typeof sessionId !== 'string' || sessionId.length === 0) return null
145
- const files = optionalService(ctx, 'remote')?.workspaceFiles
145
+ const files = workspaceFilesOf(ctx)
146
146
  if (!files || typeof files.stat !== 'function' || typeof files.read !== 'function') {
147
147
  return { error: '宿主未提供 workspaceFiles 通道' }
148
148
  }
@@ -198,6 +198,43 @@ export function createFetchView(ctx) {
198
198
  }
199
199
  }
200
200
 
201
+ /**
202
+ * 取 workspaceFiles remote。
203
+ *
204
+ * 真机报错:`cannot get property "remote.workspaceFiles" without inject`。
205
+ * 原因:remote 是按 `remote.<name>` 为 key 注册的服务,`ctx.remote.workspaceFiles`
206
+ * 这种点号访问最终会落到 ctx 代理上做 inject 校验——没声明就抛,而它在 apply 之后、
207
+ * 面板读取时才第一次触发(所以表现为"面板读取失败",不是启动失败)。
208
+ *
209
+ * 正确姿势是用 `ctx.get('remote.workspaceFiles')` 这条**不受 inject 约束**的通道
210
+ * (cordis 自己在服务目录里就把 ctx.get 标成 optional access)。
211
+ * 逐级兜底,任何一层抛错都当作"没有这条通道"。
212
+ * @param {any} ctx
213
+ * @returns {any|null}
214
+ */
215
+ function workspaceFilesOf(ctx) {
216
+ if (typeof ctx?.get === 'function') {
217
+ try {
218
+ const direct = ctx.get('remote.workspaceFiles')
219
+ if (direct) return direct
220
+ } catch {
221
+ // 某些版本只注册了命名空间,继续往下试
222
+ }
223
+ try {
224
+ const namespace = ctx.get('remote')
225
+ const files = namespace?.workspaceFiles
226
+ if (files) return files
227
+ } catch {
228
+ // 命名空间访问同样可能被代理拦,忽略
229
+ }
230
+ }
231
+ try {
232
+ return ctx?.remote?.workspaceFiles ?? null
233
+ } catch {
234
+ return null
235
+ }
236
+ }
237
+
201
238
  /** 把任意抛出物变成一句话。 */
202
239
  function stringifyError(error) {
203
240
  if (error instanceof Error) return error.message
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingda-ai/dsh-plugin-ledger",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "description": "DSH 插件搜索入口:运行时账本(成本/用量观测)。自包含单包,不依赖其他 npm 包,便于从镜像源安装。",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [