@undefineds.co/xpod 0.3.6 → 0.3.15

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 (249) hide show
  1. package/config/cli.json +1 -1
  2. package/config/cloud.json +54 -22
  3. package/config/local.json +56 -12
  4. package/config/resolver.json +10 -2
  5. package/config/xpod.base.json +50 -0
  6. package/config/xpod.json +8 -8
  7. package/dist/agents/config/resolve.js +10 -10
  8. package/dist/agents/config/resolve.js.map +1 -1
  9. package/dist/api/chatkit/index.d.ts +1 -1
  10. package/dist/api/chatkit/index.js.map +1 -1
  11. package/dist/api/chatkit/pod-store.d.ts +14 -11
  12. package/dist/api/chatkit/pod-store.js +114 -78
  13. package/dist/api/chatkit/pod-store.js.map +1 -1
  14. package/dist/api/chatkit/runtime/AcpAgentRuntime.js +1 -1
  15. package/dist/api/chatkit/runtime/AcpAgentRuntime.js.map +1 -1
  16. package/dist/api/chatkit/service.js +1 -1
  17. package/dist/api/chatkit/service.js.map +1 -1
  18. package/dist/api/chatkit/types.d.ts +11 -11
  19. package/dist/api/chatkit/types.js +3 -3
  20. package/dist/api/chatkit/types.js.map +1 -1
  21. package/dist/api/container/cloud.js +0 -8
  22. package/dist/api/container/cloud.js.map +1 -1
  23. package/dist/api/container/index.js +2 -1
  24. package/dist/api/container/index.js.map +1 -1
  25. package/dist/api/container/local.js +0 -7
  26. package/dist/api/container/local.js.map +1 -1
  27. package/dist/api/container/routes.js +3 -17
  28. package/dist/api/container/routes.js.map +1 -1
  29. package/dist/api/container/types.d.ts +0 -2
  30. package/dist/api/container/types.js.map +1 -1
  31. package/dist/api/handlers/PodManagementHandler.d.ts +3 -0
  32. package/dist/api/handlers/PodManagementHandler.js +71 -1
  33. package/dist/api/handlers/PodManagementHandler.js.map +1 -1
  34. package/dist/api/handlers/RunHandler.js +5 -5
  35. package/dist/api/handlers/RunHandler.js.map +1 -1
  36. package/dist/api/runs/AgentRuntimeTypes.d.ts +7 -8
  37. package/dist/api/runs/AgentRuntimeTypes.js.map +1 -1
  38. package/dist/api/runs/InngestRunExecutionBackend.d.ts +2 -2
  39. package/dist/api/runs/ManagedRunWorker.d.ts +1 -1
  40. package/dist/api/runs/ManagedRunWorker.js +6 -6
  41. package/dist/api/runs/ManagedRunWorker.js.map +1 -1
  42. package/dist/api/runs/PiAgentRuntimeDriver.d.ts +16 -1
  43. package/dist/api/runs/PiAgentRuntimeDriver.js +182 -23
  44. package/dist/api/runs/PiAgentRuntimeDriver.js.map +1 -1
  45. package/dist/api/runs/RunStateCenter.d.ts +3 -3
  46. package/dist/api/runs/RunStateCenter.js +13 -13
  47. package/dist/api/runs/RunStateCenter.js.map +1 -1
  48. package/dist/api/runs/store.d.ts +4 -4
  49. package/dist/api/runs/store.js +2 -2
  50. package/dist/api/runs/store.js.map +1 -1
  51. package/dist/api/service/VectorStoreService.d.ts +1 -1
  52. package/dist/api/service/VectorStoreService.js +16 -16
  53. package/dist/api/service/VectorStoreService.js.map +1 -1
  54. package/dist/api/tasks/InngestTaskScheduler.d.ts +4 -4
  55. package/dist/api/tasks/TaskMaterializer.d.ts +3 -3
  56. package/dist/api/tasks/TaskMaterializer.js +11 -11
  57. package/dist/api/tasks/TaskMaterializer.js.map +1 -1
  58. package/dist/api/tasks/TaskService.d.ts +3 -3
  59. package/dist/api/tasks/TaskService.js +11 -7
  60. package/dist/api/tasks/TaskService.js.map +1 -1
  61. package/dist/api/tasks/store.d.ts +10 -4
  62. package/dist/api/tasks/store.js +14 -4
  63. package/dist/api/tasks/store.js.map +1 -1
  64. package/dist/api/workspace/types.d.ts +3 -3
  65. package/dist/api/workspace/types.js +6 -6
  66. package/dist/api/workspace/types.js.map +1 -1
  67. package/dist/cli/commands/config.js +2 -2
  68. package/dist/cli/commands/config.js.map +1 -1
  69. package/dist/cli/commands/start.js +9 -3
  70. package/dist/cli/commands/start.js.map +1 -1
  71. package/dist/components/components.jsonld +8 -2
  72. package/dist/components/context.jsonld +308 -51
  73. package/dist/http/search/SearchHttpHandler.js +8 -8
  74. package/dist/http/search/SearchHttpHandler.js.map +1 -1
  75. package/dist/identity/drizzle/PodLookupRepository.d.ts +11 -1
  76. package/dist/identity/drizzle/PodLookupRepository.js +95 -4
  77. package/dist/identity/drizzle/PodLookupRepository.js.map +1 -1
  78. package/dist/identity/drizzle/db.js +4 -43
  79. package/dist/identity/drizzle/db.js.map +1 -1
  80. package/dist/identity/drizzle/schema.pg.d.ts +0 -5
  81. package/dist/identity/drizzle/schema.pg.js +2 -16
  82. package/dist/identity/drizzle/schema.pg.js.map +1 -1
  83. package/dist/identity/drizzle/schema.sqlite.d.ts +19 -176
  84. package/dist/identity/drizzle/schema.sqlite.js +2 -16
  85. package/dist/identity/drizzle/schema.sqlite.js.map +1 -1
  86. package/dist/identity/oidc/AutoDetectIdentityProviderHandler.d.ts +4 -4
  87. package/dist/identity/oidc/AutoDetectIdentityProviderHandler.js +7 -7
  88. package/dist/identity/oidc/AutoDetectIdentityProviderHandler.js.map +1 -1
  89. package/dist/identity/oidc/AutoDetectIdentityProviderHandler.jsonld +6 -6
  90. package/dist/identity/oidc/AutoDetectOidcHandler.d.ts +4 -4
  91. package/dist/identity/oidc/AutoDetectOidcHandler.js +6 -6
  92. package/dist/identity/oidc/AutoDetectOidcHandler.js.map +1 -1
  93. package/dist/identity/oidc/AutoDetectOidcHandler.jsonld +6 -6
  94. package/dist/identity/oidc/ScopedPickWebIdHandler.d.ts +37 -0
  95. package/dist/identity/oidc/ScopedPickWebIdHandler.js +211 -0
  96. package/dist/identity/oidc/ScopedPickWebIdHandler.js.map +1 -0
  97. package/dist/identity/oidc/ScopedPickWebIdHandler.jsonld +158 -0
  98. package/dist/index.d.ts +12 -2
  99. package/dist/index.js +16 -4
  100. package/dist/index.js.map +1 -1
  101. package/dist/main.js +8 -2
  102. package/dist/main.js.map +1 -1
  103. package/dist/provision/ProvisionPodCreator.d.ts +3 -4
  104. package/dist/provision/ProvisionPodCreator.js +8 -13
  105. package/dist/provision/ProvisionPodCreator.js.map +1 -1
  106. package/dist/provision/ProvisionPodCreator.jsonld +7 -7
  107. package/dist/runtime/Proxy.d.ts +0 -1
  108. package/dist/runtime/Proxy.js +0 -9
  109. package/dist/runtime/Proxy.js.map +1 -1
  110. package/dist/runtime/bootstrap.d.ts +1 -0
  111. package/dist/runtime/bootstrap.js +5 -2
  112. package/dist/runtime/bootstrap.js.map +1 -1
  113. package/dist/runtime/css-process.d.ts +12 -4
  114. package/dist/runtime/css-process.js +61 -14
  115. package/dist/runtime/css-process.js.map +1 -1
  116. package/dist/runtime/oidc-issuer.d.ts +3 -2
  117. package/dist/runtime/oidc-issuer.js +3 -2
  118. package/dist/runtime/oidc-issuer.js.map +1 -1
  119. package/dist/runtime/runtime-types.d.ts +1 -0
  120. package/dist/runtime/runtime-types.js.map +1 -1
  121. package/dist/solidfs/LocalFirstRdfRepresentationResolver.d.ts +21 -0
  122. package/dist/solidfs/LocalFirstRdfRepresentationResolver.js +38 -0
  123. package/dist/solidfs/LocalFirstRdfRepresentationResolver.js.map +1 -0
  124. package/dist/solidfs/LocalSolidFS.d.ts +18 -0
  125. package/dist/solidfs/LocalSolidFS.js +539 -0
  126. package/dist/solidfs/LocalSolidFS.js.map +1 -0
  127. package/dist/solidfs/PodSolidFsHttpClient.d.ts +16 -0
  128. package/dist/solidfs/PodSolidFsHttpClient.js +93 -0
  129. package/dist/solidfs/PodSolidFsHttpClient.js.map +1 -0
  130. package/dist/solidfs/PodSolidFsHydrator.d.ts +27 -0
  131. package/dist/solidfs/PodSolidFsHydrator.js +127 -0
  132. package/dist/solidfs/PodSolidFsHydrator.js.map +1 -0
  133. package/dist/solidfs/PodSolidFsSyncer.d.ts +21 -0
  134. package/dist/solidfs/PodSolidFsSyncer.js +78 -0
  135. package/dist/solidfs/PodSolidFsSyncer.js.map +1 -0
  136. package/dist/solidfs/RdfIndexSolidFsSyncer.d.ts +22 -0
  137. package/dist/solidfs/RdfIndexSolidFsSyncer.js +131 -0
  138. package/dist/solidfs/RdfIndexSolidFsSyncer.js.map +1 -0
  139. package/dist/solidfs/index.d.ts +7 -0
  140. package/dist/solidfs/index.js +24 -0
  141. package/dist/solidfs/index.js.map +1 -0
  142. package/dist/solidfs/types.d.ts +131 -0
  143. package/dist/solidfs/types.js +19 -0
  144. package/dist/solidfs/types.js.map +1 -0
  145. package/dist/storage/RepresentationPartialConvertingStore.js +6 -13
  146. package/dist/storage/RepresentationPartialConvertingStore.js.map +1 -1
  147. package/dist/storage/SparqlUpdateResourceStore.d.ts +4 -0
  148. package/dist/storage/SparqlUpdateResourceStore.js +13 -0
  149. package/dist/storage/SparqlUpdateResourceStore.js.map +1 -1
  150. package/dist/storage/SparqlUpdateResourceStore.jsonld +26 -0
  151. package/dist/storage/accessors/MixDataAccessor.d.ts +85 -4
  152. package/dist/storage/accessors/MixDataAccessor.js +511 -16
  153. package/dist/storage/accessors/MixDataAccessor.js.map +1 -1
  154. package/dist/storage/accessors/MixDataAccessor.jsonld +176 -1
  155. package/dist/storage/accessors/QuintStoreSparqlDataAccessor.d.ts +7 -0
  156. package/dist/storage/accessors/QuintStoreSparqlDataAccessor.js +72 -4
  157. package/dist/storage/accessors/QuintStoreSparqlDataAccessor.js.map +1 -1
  158. package/dist/storage/accessors/QuintStoreSparqlDataAccessor.jsonld +24 -0
  159. package/dist/storage/quint/BaseQuintStore.d.ts +3 -0
  160. package/dist/storage/quint/BaseQuintStore.js +51 -27
  161. package/dist/storage/quint/BaseQuintStore.js.map +1 -1
  162. package/dist/storage/quint/PgQuintStore.d.ts +1 -0
  163. package/dist/storage/quint/PgQuintStore.js +50 -32
  164. package/dist/storage/quint/PgQuintStore.js.map +1 -1
  165. package/dist/storage/quint/PgQuintStore.jsonld +4 -3
  166. package/dist/storage/quint/SqliteQuintStore.d.ts +5 -0
  167. package/dist/storage/quint/SqliteQuintStore.js +100 -0
  168. package/dist/storage/quint/SqliteQuintStore.js.map +1 -1
  169. package/dist/storage/quint/SqliteQuintStore.jsonld +20 -0
  170. package/dist/storage/quint/types.d.ts +16 -0
  171. package/dist/storage/quint/types.js.map +1 -1
  172. package/dist/storage/rdf/Rdf3xTripleIndex.d.ts +55 -0
  173. package/dist/storage/rdf/Rdf3xTripleIndex.js +1235 -0
  174. package/dist/storage/rdf/Rdf3xTripleIndex.js.map +1 -0
  175. package/dist/storage/rdf/RdfContentTypes.d.ts +9 -0
  176. package/dist/storage/rdf/RdfContentTypes.js +79 -0
  177. package/dist/storage/rdf/RdfContentTypes.js.map +1 -0
  178. package/dist/storage/rdf/RdfLocalQueryEngine.d.ts +79 -0
  179. package/dist/storage/rdf/RdfLocalQueryEngine.js +2705 -0
  180. package/dist/storage/rdf/RdfLocalQueryEngine.js.map +1 -0
  181. package/dist/storage/rdf/RdfQuadIndex.d.ts +98 -0
  182. package/dist/storage/rdf/RdfQuadIndex.js +1840 -0
  183. package/dist/storage/rdf/RdfQuadIndex.js.map +1 -0
  184. package/dist/storage/rdf/RdfQuadIndex.jsonld +416 -0
  185. package/dist/storage/rdf/RdfShadowComparator.d.ts +12 -0
  186. package/dist/storage/rdf/RdfShadowComparator.js +47 -0
  187. package/dist/storage/rdf/RdfShadowComparator.js.map +1 -0
  188. package/dist/storage/rdf/RdfSparqlAdapter.d.ts +147 -0
  189. package/dist/storage/rdf/RdfSparqlAdapter.js +2420 -0
  190. package/dist/storage/rdf/RdfSparqlAdapter.js.map +1 -0
  191. package/dist/storage/rdf/RdfSparqlAdapter.jsonld +414 -0
  192. package/dist/storage/rdf/RdfTermDictionary.d.ts +27 -0
  193. package/dist/storage/rdf/RdfTermDictionary.js +352 -0
  194. package/dist/storage/rdf/RdfTermDictionary.js.map +1 -0
  195. package/dist/storage/rdf/RdfTermDictionary.jsonld +114 -0
  196. package/dist/storage/rdf/RdfTermSemantics.d.ts +6 -0
  197. package/dist/storage/rdf/RdfTermSemantics.js +40 -0
  198. package/dist/storage/rdf/RdfTermSemantics.js.map +1 -0
  199. package/dist/storage/rdf/RdfTextIndex.d.ts +23 -0
  200. package/dist/storage/rdf/RdfTextIndex.js +569 -0
  201. package/dist/storage/rdf/RdfTextIndex.js.map +1 -0
  202. package/dist/storage/rdf/RdfVectorIndex.d.ts +22 -0
  203. package/dist/storage/rdf/RdfVectorIndex.js +631 -0
  204. package/dist/storage/rdf/RdfVectorIndex.js.map +1 -0
  205. package/dist/storage/rdf/RdfXmlSerializer.d.ts +2 -0
  206. package/dist/storage/rdf/RdfXmlSerializer.js +123 -0
  207. package/dist/storage/rdf/RdfXmlSerializer.js.map +1 -0
  208. package/dist/storage/rdf/ShadowRdfQuintStore.d.ts +58 -0
  209. package/dist/storage/rdf/ShadowRdfQuintStore.js +202 -0
  210. package/dist/storage/rdf/ShadowRdfQuintStore.js.map +1 -0
  211. package/dist/storage/rdf/ShadowRdfQuintStore.jsonld +308 -0
  212. package/dist/storage/rdf/SolidRdfEngine.d.ts +56 -0
  213. package/dist/storage/rdf/SolidRdfEngine.js +292 -0
  214. package/dist/storage/rdf/SolidRdfEngine.js.map +1 -0
  215. package/dist/storage/rdf/SolidRdfEngine.jsonld +372 -0
  216. package/dist/storage/rdf/SolidRdfSparqlEngine.d.ts +92 -0
  217. package/dist/storage/rdf/SolidRdfSparqlEngine.js +477 -0
  218. package/dist/storage/rdf/SolidRdfSparqlEngine.js.map +1 -0
  219. package/dist/storage/rdf/SolidRdfSparqlEngine.jsonld +257 -0
  220. package/dist/storage/rdf/index.d.ts +15 -0
  221. package/dist/storage/rdf/index.js +61 -0
  222. package/dist/storage/rdf/index.js.map +1 -0
  223. package/dist/storage/rdf/models-benchmark.d.ts +260 -0
  224. package/dist/storage/rdf/models-benchmark.js +1405 -0
  225. package/dist/storage/rdf/models-benchmark.js.map +1 -0
  226. package/dist/storage/rdf/types.d.ts +726 -0
  227. package/dist/storage/rdf/types.js +3 -0
  228. package/dist/storage/rdf/types.js.map +1 -0
  229. package/dist/storage/rdf/types.jsonld +316 -0
  230. package/dist/storage/vector/VectorIndexingListener.d.ts +5 -5
  231. package/dist/storage/vector/VectorIndexingListener.js +19 -19
  232. package/dist/storage/vector/VectorIndexingListener.js.map +1 -1
  233. package/package.json +3 -2
  234. package/templates/pod/acp/.acr.hbs +39 -0
  235. package/templates/pod/acp/README.acr +18 -0
  236. package/templates/pod/acp/profile/card.acr +22 -0
  237. package/templates/pod/base/README$.md.hbs +27 -0
  238. package/templates/pod/base/profile/card$.ttl.hbs +13 -0
  239. package/templates/pod/wac/.acl.hbs +26 -0
  240. package/templates/pod/wac/README.acl.hbs +14 -0
  241. package/templates/pod/wac/profile/card.acl.hbs +19 -0
  242. package/dist/api/handlers/WebIdProfileHandler.d.ts +0 -16
  243. package/dist/api/handlers/WebIdProfileHandler.js +0 -423
  244. package/dist/api/handlers/WebIdProfileHandler.js.map +0 -1
  245. package/dist/identity/drizzle/WebIdProfileRepository.d.ts +0 -63
  246. package/dist/identity/drizzle/WebIdProfileRepository.js +0 -168
  247. package/dist/identity/drizzle/WebIdProfileRepository.js.map +0 -1
  248. package/dist/identity/drizzle/WebIdProfileRepository.jsonld +0 -112
  249. package/dist/storage/quint/BaseQuintStore.jsonld +0 -257
@@ -268,12 +268,12 @@ class PodChatKitStore {
268
268
  const match = chatId.match(/^([^/]+)\/index\.ttl#this$/);
269
269
  return match ? decodeURIComponent(match[1]) : undefined;
270
270
  }
271
- chatSurfaceIdFromIri(chatIri) {
272
- if (!chatIri) {
271
+ chatSurfaceIdFromResource(chat) {
272
+ if (!chat) {
273
273
  return undefined;
274
274
  }
275
275
  try {
276
- const url = new URL(chatIri);
276
+ const url = new URL(chat);
277
277
  const match = url.pathname.match(/\/\.data\/chat\/([^/]+)\/index\.ttl$/);
278
278
  if (match && url.hash === '#this') {
279
279
  return decodeURIComponent(match[1]);
@@ -282,7 +282,7 @@ class PodChatKitStore {
282
282
  catch {
283
283
  // Fall through to base-relative parsing.
284
284
  }
285
- return this.chatSurfaceIdFromResourceId(chatIri);
285
+ return this.chatSurfaceIdFromResourceId(chat);
286
286
  }
287
287
  /**
288
288
  * 确保 Chat 容器存在,如果不存在则创建
@@ -315,9 +315,9 @@ class PodChatKitStore {
315
315
  * 将 ThreadRecord 转为 ThreadMetadata
316
316
  * ChatKit 边界继续暴露 metadata.chat_id;内部同一值叫 surface_id。
317
317
  */
318
- threadRecordToMetadata(record, chatUriMap) {
318
+ threadRecordToMetadata(record, chatResourceMap) {
319
319
  const commandKind = record.commandKind === 'task' ? 'task' : 'chat';
320
- const surfaceId = record.surfaceId || this.resolveChatSurfaceFromUri(record.chat, chatUriMap, PodChatKitStore.DEFAULT_CHAT_ID);
320
+ const surfaceId = record.surfaceId || this.resolveChatSurfaceFromResource(record.chat, chatResourceMap, PodChatKitStore.DEFAULT_CHAT_ID);
321
321
  const extra = this.parseJsonObject(record.metadata);
322
322
  return {
323
323
  id: record.id,
@@ -459,7 +459,7 @@ class PodChatKitStore {
459
459
  const { yyyy, MM, dd } = this.datePathFromTimestamp(input.createdAt);
460
460
  return `${input.commandKind}/${input.surfaceId}/${yyyy}/${MM}/${dd}/messages.ttl#${(0, store_1.extractResourceLocalId)(input.key)}`;
461
461
  }
462
- resolveDataResourceUriFromId(resourceId, context) {
462
+ resolveDataResource(resourceId, context) {
463
463
  if (/^https?:\/\//.test(resourceId)) {
464
464
  return resourceId;
465
465
  }
@@ -468,23 +468,23 @@ class PodChatKitStore {
468
468
  if (!podBaseUrl) {
469
469
  throw new Error(`Cannot resolve Pod base URL for resource id: ${resourceId}`);
470
470
  }
471
- return (0, store_1.resolveDataResourceIri)(podBaseUrl, resourceId);
471
+ return (0, store_1.resolveDataResource)(podBaseUrl, resourceId);
472
472
  }
473
- baseRelativeIdFromSubjectUri(subjectUri, context) {
473
+ baseRelativeIdFromResource(resource, context) {
474
474
  const podBaseUrl = this.getCachedPodBaseUrl(context)
475
475
  ?? this.derivePodBaseUrl(this.getWebId(context));
476
476
  if (podBaseUrl) {
477
477
  const dataPrefix = `${podBaseUrl.replace(/\/$/, '')}/.data/`;
478
- if (subjectUri.startsWith(dataPrefix)) {
479
- return subjectUri.slice(dataPrefix.length);
478
+ if (resource.startsWith(dataPrefix)) {
479
+ return resource.slice(dataPrefix.length);
480
480
  }
481
481
  }
482
482
  const marker = '/.data/';
483
- const markerIndex = subjectUri.indexOf(marker);
483
+ const markerIndex = resource.indexOf(marker);
484
484
  if (markerIndex >= 0) {
485
- return subjectUri.slice(markerIndex + marker.length);
485
+ return resource.slice(markerIndex + marker.length);
486
486
  }
487
- return subjectUri;
487
+ return resource;
488
488
  }
489
489
  runRecordToData(record) {
490
490
  return {
@@ -587,12 +587,12 @@ class PodChatKitStore {
587
587
  }
588
588
  }
589
589
  /**
590
- * 获取或构建 Chat IRI -> surface id 的映射缓存。
591
- * drizzle-solid 的 uri().link(Chat) 字段返回完整 URI,通过 Chat 的 @id 比对还原路径槽位。
590
+ * 获取或构建 Chat resource -> surface id 的映射缓存。
591
+ * drizzle-solid 的 link(Chat) 字段返回完整资源引用,通过 Chat 的 @id 比对还原路径槽位。
592
592
  */
593
- async getChatUriMap(context) {
594
- if (context._chatUriMap) {
595
- return context._chatUriMap;
593
+ async getChatResourceMap(context) {
594
+ if (context._chatResourceMap) {
595
+ return context._chatResourceMap;
596
596
  }
597
597
  const db = await this.getDb(context);
598
598
  const map = new Map();
@@ -610,25 +610,25 @@ class PodChatKitStore {
610
610
  // ignore
611
611
  }
612
612
  }
613
- context._chatUriMap = map;
613
+ context._chatResourceMap = map;
614
614
  return map;
615
615
  }
616
616
  /**
617
- * 从 Chat URI 还原 surface id。
617
+ * 从 Chat resource 还原 surface id。
618
618
  * 优先通过 @id 映射;若调用方本来给的是裸 ID,则原样使用。
619
619
  */
620
- resolveChatSurfaceFromUri(chatUri, chatUriMap, defaultSurfaceId) {
621
- if (!chatUri)
620
+ resolveChatSurfaceFromResource(chat, chatResourceMap, defaultSurfaceId) {
621
+ if (!chat)
622
622
  return defaultSurfaceId;
623
- const bare = chatUriMap.get(chatUri);
623
+ const bare = chatResourceMap.get(chat);
624
624
  if (bare)
625
625
  return bare;
626
- const parsed = this.chatSurfaceIdFromIri(chatUri);
626
+ const parsed = this.chatSurfaceIdFromResource(chat);
627
627
  if (parsed)
628
628
  return parsed;
629
- return chatUri.includes('/') ? defaultSurfaceId : chatUri;
629
+ return chat.includes('/') ? defaultSurfaceId : chat;
630
630
  }
631
- isAbsoluteHttpIri(value) {
631
+ isAbsoluteHttpResource(value) {
632
632
  try {
633
633
  const url = new URL(value);
634
634
  return url.protocol === 'http:' || url.protocol === 'https:';
@@ -637,9 +637,9 @@ class PodChatKitStore {
637
637
  return false;
638
638
  }
639
639
  }
640
- parseThreadIri(threadIri) {
640
+ parseThreadResource(thread) {
641
641
  try {
642
- const url = new URL(threadIri);
642
+ const url = new URL(thread);
643
643
  const match = url.pathname.match(/\/\.data\/(chat|task)\/([^/]+)\/index\.ttl$/);
644
644
  const localThreadId = url.hash.startsWith('#') ? decodeURIComponent(url.hash.slice(1)) : '';
645
645
  if (!match || !localThreadId) {
@@ -651,7 +651,7 @@ class PodChatKitStore {
651
651
  threadId: `${commandKind}/${surfaceId}/index.ttl#${localThreadId}`,
652
652
  commandKind,
653
653
  surfaceId,
654
- threadUri: url.toString(),
654
+ thread: url.toString(),
655
655
  };
656
656
  }
657
657
  catch {
@@ -675,41 +675,41 @@ class PodChatKitStore {
675
675
  };
676
676
  }
677
677
  async resolveThreadRef(thread, context) {
678
- const threadIdOrIri = thread.thread_id;
679
- if (this.isAbsoluteHttpIri(threadIdOrIri)) {
680
- const parsed = this.parseThreadIri(threadIdOrIri);
678
+ const threadRef = thread.thread_id;
679
+ if (this.isAbsoluteHttpResource(threadRef)) {
680
+ const parsed = this.parseThreadResource(threadRef);
681
681
  if (!parsed) {
682
- throw new Error(`Invalid thread IRI: ${threadIdOrIri}`);
682
+ throw new Error(`Invalid thread resource: ${threadRef}`);
683
683
  }
684
684
  this.cacheThreadSurfaceId(context, parsed.threadId, parsed.surfaceId);
685
685
  return parsed;
686
686
  }
687
- const parsedResourceId = this.parseThreadResourceId(threadIdOrIri);
687
+ const parsedResourceId = this.parseThreadResourceId(threadRef);
688
688
  if (parsedResourceId) {
689
- const threadUri = this.resolveDataResourceUriFromId(parsedResourceId.threadId, context);
689
+ const threadResource = this.resolveDataResource(parsedResourceId.threadId, context);
690
690
  this.cacheThreadSurfaceId(context, parsedResourceId.threadId, parsedResourceId.surfaceId);
691
691
  return {
692
692
  ...parsedResourceId,
693
- threadUri,
693
+ thread: threadResource,
694
694
  };
695
695
  }
696
696
  if (!('chat_id' in thread) || !thread.chat_id) {
697
- throw new Error(`chat_id is required when thread_id "${threadIdOrIri}" is not a full thread resource id`);
697
+ throw new Error(`chat_id is required when thread_id "${threadRef}" is not a full thread resource id`);
698
698
  }
699
699
  const surfaceId = thread.chat_id;
700
700
  const commandKind = 'chat';
701
701
  const threadId = this.generateThreadResourceId({
702
- key: threadIdOrIri,
702
+ key: threadRef,
703
703
  commandKind,
704
704
  surfaceId,
705
705
  });
706
- const threadUri = this.resolveDataResourceUriFromId(threadId, context);
706
+ const threadResource = this.resolveDataResource(threadId, context);
707
707
  this.cacheThreadSurfaceId(context, threadId, surfaceId);
708
708
  return {
709
709
  threadId,
710
710
  commandKind,
711
711
  surfaceId,
712
- threadUri,
712
+ thread: threadResource,
713
713
  };
714
714
  }
715
715
  /**
@@ -765,7 +765,7 @@ class PodChatKitStore {
765
765
  SELECT ?msg ?maker ?messageType ?legacyRole ?content ?messageStatus ?legacyStatus ?createdAt ?legacyCreatedAt ?toolName ?toolCallId ?metadata
766
766
  WHERE {
767
767
  ?msg a meeting:Message ;
768
- sioc:has_container <${resolvedThread.threadUri}> .
768
+ sioc:has_container <${resolvedThread.thread}> .
769
769
  OPTIONAL { ?msg foaf:maker ?maker . }
770
770
  OPTIONAL { ?msg udfs:messageType ?messageType . }
771
771
  OPTIONAL { ?msg udfs:role ?legacyRole . }
@@ -795,9 +795,9 @@ class PodChatKitStore {
795
795
  const json = await response.json();
796
796
  const bindings = json.results?.bindings ?? [];
797
797
  return bindings.map((binding) => ({
798
- id: this.baseRelativeIdFromSubjectUri(this.parseSparqlBindingValue(binding, 'msg') ?? '', context),
798
+ id: this.baseRelativeIdFromResource(this.parseSparqlBindingValue(binding, 'msg') ?? '', context),
799
799
  chat: null,
800
- thread: resolvedThread.threadUri,
800
+ thread: resolvedThread.thread,
801
801
  maker: this.parseSparqlBindingValue(binding, 'maker'),
802
802
  role: this.parseSparqlBindingValue(binding, 'messageType') ?? this.parseSparqlBindingValue(binding, 'legacyRole'),
803
803
  content: this.parseSparqlBindingValue(binding, 'content'),
@@ -806,7 +806,7 @@ class PodChatKitStore {
806
806
  toolName: this.parseSparqlBindingValue(binding, 'toolName'),
807
807
  toolCallId: this.parseSparqlBindingValue(binding, 'toolCallId'),
808
808
  metadata: this.parseSparqlBindingValue(binding, 'metadata'),
809
- subjectUri: this.parseSparqlBindingValue(binding, 'msg'),
809
+ resource: this.parseSparqlBindingValue(binding, 'msg'),
810
810
  }));
811
811
  }
812
812
  datePathFromTimestamp(timestamp) {
@@ -851,12 +851,12 @@ class PodChatKitStore {
851
851
  throw new Error('Cannot access Pod: invalid credentials');
852
852
  }
853
853
  const resolvedThread = await this.resolveThreadRef(thread, context);
854
- const threadRecord = await db.findByIri(schema_1.Thread, resolvedThread.threadUri);
854
+ const threadRecord = await db.findByIri(schema_1.Thread, resolvedThread.thread);
855
855
  if (!threadRecord) {
856
856
  throw new Error(`Thread not found: ${resolvedThread.threadId}`);
857
857
  }
858
- const chatUriMap = await this.getChatUriMap(context);
859
- const metadata = this.threadRecordToMetadata(threadRecord, chatUriMap);
858
+ const chatResourceMap = await this.getChatResourceMap(context);
859
+ const metadata = this.threadRecordToMetadata(threadRecord, chatResourceMap);
860
860
  // 缓存结果
861
861
  this.cacheThreadMetadata(context, metadata);
862
862
  this.cacheThreadSurfaceId(context, metadata.id, resolvedThread.surfaceId);
@@ -892,12 +892,12 @@ class PodChatKitStore {
892
892
  });
893
893
  thread.id = threadResourceId;
894
894
  this.cacheThreadSurfaceId(context, thread.id, surfaceId);
895
- const threadUri = this.resolveDataResourceUriFromId(threadResourceId, context);
895
+ const threadResource = this.resolveDataResource(threadResourceId, context);
896
896
  // 检查 Thread 是否存在
897
- const existing = await db.findByIri(schema_1.Thread, threadUri);
897
+ const existing = await db.findByIri(schema_1.Thread, threadResource);
898
898
  if (existing) {
899
899
  // Update
900
- await db.updateByIri(schema_1.Thread, threadUri, {
900
+ await db.updateByIri(schema_1.Thread, threadResource, {
901
901
  commandKind,
902
902
  surfaceId,
903
903
  chat: commandKind === 'chat' ? this.buildChatResourceId(surfaceId) : null,
@@ -958,9 +958,9 @@ class PodChatKitStore {
958
958
  }
959
959
  const slice = threads.slice(startIndex, startIndex + limit);
960
960
  const hasMore = startIndex + limit < threads.length;
961
- const chatUriMap = await this.getChatUriMap(context);
961
+ const chatResourceMap = await this.getChatResourceMap(context);
962
962
  return {
963
- data: slice.map((t) => this.threadRecordToMetadata(t, chatUriMap)),
963
+ data: slice.map((t) => this.threadRecordToMetadata(t, chatResourceMap)),
964
964
  has_more: hasMore,
965
965
  after: slice.length > 0 ? slice[slice.length - 1].id : undefined,
966
966
  };
@@ -978,7 +978,7 @@ class PodChatKitStore {
978
978
  }
979
979
  // 删除关联到此 Thread 的消息
980
980
  try {
981
- await db.delete(schema_1.Message).where((0, drizzle_solid_1.eq)(schema_1.Message.thread, resolvedThread.threadUri));
981
+ await db.delete(schema_1.Message).where((0, drizzle_solid_1.eq)(schema_1.Message.thread, resolvedThread.thread));
982
982
  }
983
983
  catch (err) {
984
984
  if (!err.message?.includes('404') && !err.message?.includes('Could not retrieve') && !err.message?.includes('Parse error')) {
@@ -988,7 +988,7 @@ class PodChatKitStore {
988
988
  }
989
989
  // 删除 Thread
990
990
  try {
991
- await db.deleteByIri(schema_1.Thread, resolvedThread.threadUri);
991
+ await db.deleteByIri(schema_1.Thread, resolvedThread.thread);
992
992
  }
993
993
  catch (err) {
994
994
  if (!err.message?.includes('404') && !err.message?.includes('Could not retrieve') && !err.message?.includes('Parse error')) {
@@ -1097,7 +1097,7 @@ class PodChatKitStore {
1097
1097
  commandKind: resolvedThread.commandKind,
1098
1098
  surfaceId: resolvedThread.surfaceId,
1099
1099
  chat: resolvedThread.commandKind === 'chat' ? this.buildChatResourceId(resolvedThread.surfaceId) : null,
1100
- thread: resolvedThread.threadUri,
1100
+ thread: resolvedThread.thread,
1101
1101
  maker: role === schema_1.MessageRole.USER ? webId : null,
1102
1102
  role,
1103
1103
  content,
@@ -1186,9 +1186,9 @@ class PodChatKitStore {
1186
1186
  if (!cachedFetch) {
1187
1187
  throw new Error('No cached session for direct PATCH - call getDb first');
1188
1188
  }
1189
- const subjectUri = this.resolveDataResourceUriFromId(messageResourceId, context);
1190
- const hashIndex = subjectUri.lastIndexOf('#');
1191
- const resourceUrl = hashIndex >= 0 ? subjectUri.slice(0, hashIndex) : subjectUri;
1189
+ const messageResource = this.resolveDataResource(messageResourceId, context);
1190
+ const hashIndex = messageResource.lastIndexOf('#');
1191
+ const resourceUrl = hashIndex >= 0 ? messageResource.slice(0, hashIndex) : messageResource;
1192
1192
  // 构建 SPARQL UPDATE:删除旧值,插入新值
1193
1193
  const deletePatterns = [];
1194
1194
  const insertTriples = [];
@@ -1212,16 +1212,16 @@ class PodChatKitStore {
1212
1212
  return `"${value.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`;
1213
1213
  };
1214
1214
  // Content 更新
1215
- deletePatterns.push(`<${subjectUri}> <http://rdfs.org/sioc/ns#content> ?oldContent .`);
1216
- insertTriples.push(`<${subjectUri}> <http://rdfs.org/sioc/ns#content> ${escapeForSparql(content)} .`);
1215
+ deletePatterns.push(`<${messageResource}> <http://rdfs.org/sioc/ns#content> ?oldContent .`);
1216
+ insertTriples.push(`<${messageResource}> <http://rdfs.org/sioc/ns#content> ${escapeForSparql(content)} .`);
1217
1217
  // Status 更新
1218
1218
  if (status) {
1219
- deletePatterns.push(`<${subjectUri}> <https://undefineds.co/ns#messageStatus> ?oldStatus .`);
1220
- insertTriples.push(`<${subjectUri}> <https://undefineds.co/ns#messageStatus> "${status}" .`);
1219
+ deletePatterns.push(`<${messageResource}> <https://undefineds.co/ns#messageStatus> ?oldStatus .`);
1220
+ insertTriples.push(`<${messageResource}> <https://undefineds.co/ns#messageStatus> "${status}" .`);
1221
1221
  }
1222
1222
  if (metadata) {
1223
- deletePatterns.push(`<${subjectUri}> <https://undefineds.co/ns#metadata> ?oldMetadata .`);
1224
- insertTriples.push(`<${subjectUri}> <https://undefineds.co/ns#metadata> ${escapeForSparql(JSON.stringify(metadata))} .`);
1223
+ deletePatterns.push(`<${messageResource}> <https://undefineds.co/ns#metadata> ?oldMetadata .`);
1224
+ insertTriples.push(`<${messageResource}> <https://undefineds.co/ns#metadata> ${escapeForSparql(JSON.stringify(metadata))} .`);
1225
1225
  }
1226
1226
  const sparql = `
1227
1227
  DELETE { ${deletePatterns.join(' ')} }
@@ -1238,17 +1238,17 @@ WHERE { ${deletePatterns.join(' ')} }
1238
1238
  throw new Error(`Direct PATCH failed: ${response.status} ${response.statusText} - ${text}`);
1239
1239
  }
1240
1240
  }
1241
- async directDeleteMessage(context, subjectUri) {
1242
- if (!subjectUri) {
1243
- throw new Error('Cannot delete message without subject URI');
1241
+ async directDeleteMessage(context, resource) {
1242
+ if (!resource) {
1243
+ throw new Error('Cannot delete message without resource');
1244
1244
  }
1245
1245
  const cachedFetch = context._cachedFetch;
1246
1246
  if (!cachedFetch) {
1247
1247
  throw new Error('No cached session for direct DELETE - call getDb first');
1248
1248
  }
1249
- const hashIndex = subjectUri.lastIndexOf('#');
1250
- const resourceUrl = hashIndex >= 0 ? subjectUri.slice(0, hashIndex) : subjectUri;
1251
- const sparql = `DELETE WHERE { <${subjectUri}> ?p ?o . }`;
1249
+ const hashIndex = resource.lastIndexOf('#');
1250
+ const resourceUrl = hashIndex >= 0 ? resource.slice(0, hashIndex) : resource;
1251
+ const sparql = `DELETE WHERE { <${resource}> ?p ?o . }`;
1252
1252
  const response = await cachedFetch(resourceUrl, {
1253
1253
  method: 'PATCH',
1254
1254
  headers: { 'Content-Type': 'application/sparql-update' },
@@ -1278,7 +1278,7 @@ WHERE { ${deletePatterns.join(' ')} }
1278
1278
  if (!target) {
1279
1279
  return;
1280
1280
  }
1281
- await this.directDeleteMessage(context, target.subjectUri);
1281
+ await this.directDeleteMessage(context, target.resource);
1282
1282
  }
1283
1283
  // =========================================================================
1284
1284
  // Attachment Operations (存 Pod 文件)
@@ -1402,7 +1402,7 @@ WHERE { ${deletePatterns.join(' ')} }
1402
1402
  if (!(0, store_1.isRunResourceId)(runId)) {
1403
1403
  throw new Error(`loadRunSteps requires a base-relative Run id: ${runId}`);
1404
1404
  }
1405
- // runId is a local query field; RunStep.run remains the semantic RDF URI relation.
1405
+ // runId is a local query field; RunStep.run remains the semantic RDF relation.
1406
1406
  const records = await db.select().from(schema_2.RunStep).where((0, drizzle_solid_1.eq)(schema_2.RunStep.runId, runId));
1407
1407
  return records
1408
1408
  .map((record) => this.runStepRecordToData(record))
@@ -1590,7 +1590,7 @@ WHERE { ${deletePatterns.join(' ')} }
1590
1590
  }
1591
1591
  models.push(item);
1592
1592
  }
1593
- resolvePodResourceIri(context, resource) {
1593
+ resolvePodResource(context, resource) {
1594
1594
  if (/^https?:\/\//.test(resource)) {
1595
1595
  return resource;
1596
1596
  }
@@ -1605,13 +1605,13 @@ WHERE { ${deletePatterns.join(' ')} }
1605
1605
  const candidates = new Set();
1606
1606
  candidates.add(providerRef);
1607
1607
  if (!/^https?:\/\//.test(providerRef)) {
1608
- candidates.add(this.resolvePodResourceIri(context, providerRef));
1608
+ candidates.add(this.resolvePodResource(context, providerRef));
1609
1609
  }
1610
1610
  const providerId = (0, models_1.normalizeAIConfigProviderId)(providerRef);
1611
1611
  if (providerId) {
1612
1612
  candidates.add(providerId);
1613
1613
  candidates.add(`/settings/providers/${providerId}.ttl`);
1614
- candidates.add(this.resolvePodResourceIri(context, `/settings/providers/${providerId}.ttl`));
1614
+ candidates.add(this.resolvePodResource(context, `/settings/providers/${providerId}.ttl`));
1615
1615
  }
1616
1616
  for (const candidate of candidates) {
1617
1617
  try {
@@ -1628,6 +1628,42 @@ WHERE { ${deletePatterns.join(' ')} }
1628
1628
  }
1629
1629
  return null;
1630
1630
  }
1631
+ sortAiCredentialCandidates(credentials) {
1632
+ return [...credentials].sort((left, right) => {
1633
+ const defaultDelta = Number(this.isTruthyValue(right.isDefault)) - Number(this.isTruthyValue(left.isDefault));
1634
+ if (defaultDelta !== 0) {
1635
+ return defaultDelta;
1636
+ }
1637
+ const leftLastUsedAt = this.timestampValue(left.lastUsedAt);
1638
+ const rightLastUsedAt = this.timestampValue(right.lastUsedAt);
1639
+ if (leftLastUsedAt !== rightLastUsedAt) {
1640
+ return leftLastUsedAt - rightLastUsedAt;
1641
+ }
1642
+ const leftFailCount = typeof left.failCount === 'number' && Number.isFinite(left.failCount) ? left.failCount : 0;
1643
+ const rightFailCount = typeof right.failCount === 'number' && Number.isFinite(right.failCount) ? right.failCount : 0;
1644
+ if (leftFailCount !== rightFailCount) {
1645
+ return leftFailCount - rightFailCount;
1646
+ }
1647
+ return (0, models_1.normalizeAIConfigResourceId)(left.id ?? '')
1648
+ .localeCompare((0, models_1.normalizeAIConfigResourceId)(right.id ?? ''));
1649
+ });
1650
+ }
1651
+ isTruthyValue(value) {
1652
+ return value === true || value === 'true' || value === 1 || value === '1';
1653
+ }
1654
+ timestampValue(value) {
1655
+ if (value instanceof Date) {
1656
+ return value.getTime();
1657
+ }
1658
+ if (typeof value === 'number' && Number.isFinite(value)) {
1659
+ return value;
1660
+ }
1661
+ if (typeof value === 'string' && value.trim()) {
1662
+ const timestamp = Date.parse(value);
1663
+ return Number.isFinite(timestamp) ? timestamp : 0;
1664
+ }
1665
+ return 0;
1666
+ }
1631
1667
  async getAiConfig(context) {
1632
1668
  const db = await this.getDb(context);
1633
1669
  if (!db) {
@@ -1641,8 +1677,8 @@ WHERE { ${deletePatterns.join(' ')} }
1641
1677
  if (credentials.length === 0) {
1642
1678
  return undefined;
1643
1679
  }
1644
- // 遍历凭据,找到有效的 Provider
1645
- for (const cred of credentials) {
1680
+ // Select deterministically; RDF document serialization order is not config semantics.
1681
+ for (const cred of this.sortAiCredentialCandidates(credentials)) {
1646
1682
  if (!cred.provider)
1647
1683
  continue;
1648
1684
  const provider = await this.findProviderForCredential(db, context, cred.provider);