@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.
- package/config/cli.json +1 -1
- package/config/cloud.json +54 -22
- package/config/local.json +56 -12
- package/config/resolver.json +10 -2
- package/config/xpod.base.json +50 -0
- package/config/xpod.json +8 -8
- package/dist/agents/config/resolve.js +10 -10
- package/dist/agents/config/resolve.js.map +1 -1
- package/dist/api/chatkit/index.d.ts +1 -1
- package/dist/api/chatkit/index.js.map +1 -1
- package/dist/api/chatkit/pod-store.d.ts +14 -11
- package/dist/api/chatkit/pod-store.js +114 -78
- package/dist/api/chatkit/pod-store.js.map +1 -1
- package/dist/api/chatkit/runtime/AcpAgentRuntime.js +1 -1
- package/dist/api/chatkit/runtime/AcpAgentRuntime.js.map +1 -1
- package/dist/api/chatkit/service.js +1 -1
- package/dist/api/chatkit/service.js.map +1 -1
- package/dist/api/chatkit/types.d.ts +11 -11
- package/dist/api/chatkit/types.js +3 -3
- package/dist/api/chatkit/types.js.map +1 -1
- package/dist/api/container/cloud.js +0 -8
- package/dist/api/container/cloud.js.map +1 -1
- package/dist/api/container/index.js +2 -1
- package/dist/api/container/index.js.map +1 -1
- package/dist/api/container/local.js +0 -7
- package/dist/api/container/local.js.map +1 -1
- package/dist/api/container/routes.js +3 -17
- package/dist/api/container/routes.js.map +1 -1
- package/dist/api/container/types.d.ts +0 -2
- package/dist/api/container/types.js.map +1 -1
- package/dist/api/handlers/PodManagementHandler.d.ts +3 -0
- package/dist/api/handlers/PodManagementHandler.js +71 -1
- package/dist/api/handlers/PodManagementHandler.js.map +1 -1
- package/dist/api/handlers/RunHandler.js +5 -5
- package/dist/api/handlers/RunHandler.js.map +1 -1
- package/dist/api/runs/AgentRuntimeTypes.d.ts +7 -8
- package/dist/api/runs/AgentRuntimeTypes.js.map +1 -1
- package/dist/api/runs/InngestRunExecutionBackend.d.ts +2 -2
- package/dist/api/runs/ManagedRunWorker.d.ts +1 -1
- package/dist/api/runs/ManagedRunWorker.js +6 -6
- package/dist/api/runs/ManagedRunWorker.js.map +1 -1
- package/dist/api/runs/PiAgentRuntimeDriver.d.ts +16 -1
- package/dist/api/runs/PiAgentRuntimeDriver.js +182 -23
- package/dist/api/runs/PiAgentRuntimeDriver.js.map +1 -1
- package/dist/api/runs/RunStateCenter.d.ts +3 -3
- package/dist/api/runs/RunStateCenter.js +13 -13
- package/dist/api/runs/RunStateCenter.js.map +1 -1
- package/dist/api/runs/store.d.ts +4 -4
- package/dist/api/runs/store.js +2 -2
- package/dist/api/runs/store.js.map +1 -1
- package/dist/api/service/VectorStoreService.d.ts +1 -1
- package/dist/api/service/VectorStoreService.js +16 -16
- package/dist/api/service/VectorStoreService.js.map +1 -1
- package/dist/api/tasks/InngestTaskScheduler.d.ts +4 -4
- package/dist/api/tasks/TaskMaterializer.d.ts +3 -3
- package/dist/api/tasks/TaskMaterializer.js +11 -11
- package/dist/api/tasks/TaskMaterializer.js.map +1 -1
- package/dist/api/tasks/TaskService.d.ts +3 -3
- package/dist/api/tasks/TaskService.js +11 -7
- package/dist/api/tasks/TaskService.js.map +1 -1
- package/dist/api/tasks/store.d.ts +10 -4
- package/dist/api/tasks/store.js +14 -4
- package/dist/api/tasks/store.js.map +1 -1
- package/dist/api/workspace/types.d.ts +3 -3
- package/dist/api/workspace/types.js +6 -6
- package/dist/api/workspace/types.js.map +1 -1
- package/dist/cli/commands/config.js +2 -2
- package/dist/cli/commands/config.js.map +1 -1
- package/dist/cli/commands/start.js +9 -3
- package/dist/cli/commands/start.js.map +1 -1
- package/dist/components/components.jsonld +8 -2
- package/dist/components/context.jsonld +308 -51
- package/dist/http/search/SearchHttpHandler.js +8 -8
- package/dist/http/search/SearchHttpHandler.js.map +1 -1
- package/dist/identity/drizzle/PodLookupRepository.d.ts +11 -1
- package/dist/identity/drizzle/PodLookupRepository.js +95 -4
- package/dist/identity/drizzle/PodLookupRepository.js.map +1 -1
- package/dist/identity/drizzle/db.js +4 -43
- package/dist/identity/drizzle/db.js.map +1 -1
- package/dist/identity/drizzle/schema.pg.d.ts +0 -5
- package/dist/identity/drizzle/schema.pg.js +2 -16
- package/dist/identity/drizzle/schema.pg.js.map +1 -1
- package/dist/identity/drizzle/schema.sqlite.d.ts +19 -176
- package/dist/identity/drizzle/schema.sqlite.js +2 -16
- package/dist/identity/drizzle/schema.sqlite.js.map +1 -1
- package/dist/identity/oidc/AutoDetectIdentityProviderHandler.d.ts +4 -4
- package/dist/identity/oidc/AutoDetectIdentityProviderHandler.js +7 -7
- package/dist/identity/oidc/AutoDetectIdentityProviderHandler.js.map +1 -1
- package/dist/identity/oidc/AutoDetectIdentityProviderHandler.jsonld +6 -6
- package/dist/identity/oidc/AutoDetectOidcHandler.d.ts +4 -4
- package/dist/identity/oidc/AutoDetectOidcHandler.js +6 -6
- package/dist/identity/oidc/AutoDetectOidcHandler.js.map +1 -1
- package/dist/identity/oidc/AutoDetectOidcHandler.jsonld +6 -6
- package/dist/identity/oidc/ScopedPickWebIdHandler.d.ts +37 -0
- package/dist/identity/oidc/ScopedPickWebIdHandler.js +211 -0
- package/dist/identity/oidc/ScopedPickWebIdHandler.js.map +1 -0
- package/dist/identity/oidc/ScopedPickWebIdHandler.jsonld +158 -0
- package/dist/index.d.ts +12 -2
- package/dist/index.js +16 -4
- package/dist/index.js.map +1 -1
- package/dist/main.js +8 -2
- package/dist/main.js.map +1 -1
- package/dist/provision/ProvisionPodCreator.d.ts +3 -4
- package/dist/provision/ProvisionPodCreator.js +8 -13
- package/dist/provision/ProvisionPodCreator.js.map +1 -1
- package/dist/provision/ProvisionPodCreator.jsonld +7 -7
- package/dist/runtime/Proxy.d.ts +0 -1
- package/dist/runtime/Proxy.js +0 -9
- package/dist/runtime/Proxy.js.map +1 -1
- package/dist/runtime/bootstrap.d.ts +1 -0
- package/dist/runtime/bootstrap.js +5 -2
- package/dist/runtime/bootstrap.js.map +1 -1
- package/dist/runtime/css-process.d.ts +12 -4
- package/dist/runtime/css-process.js +61 -14
- package/dist/runtime/css-process.js.map +1 -1
- package/dist/runtime/oidc-issuer.d.ts +3 -2
- package/dist/runtime/oidc-issuer.js +3 -2
- package/dist/runtime/oidc-issuer.js.map +1 -1
- package/dist/runtime/runtime-types.d.ts +1 -0
- package/dist/runtime/runtime-types.js.map +1 -1
- package/dist/solidfs/LocalFirstRdfRepresentationResolver.d.ts +21 -0
- package/dist/solidfs/LocalFirstRdfRepresentationResolver.js +38 -0
- package/dist/solidfs/LocalFirstRdfRepresentationResolver.js.map +1 -0
- package/dist/solidfs/LocalSolidFS.d.ts +18 -0
- package/dist/solidfs/LocalSolidFS.js +539 -0
- package/dist/solidfs/LocalSolidFS.js.map +1 -0
- package/dist/solidfs/PodSolidFsHttpClient.d.ts +16 -0
- package/dist/solidfs/PodSolidFsHttpClient.js +93 -0
- package/dist/solidfs/PodSolidFsHttpClient.js.map +1 -0
- package/dist/solidfs/PodSolidFsHydrator.d.ts +27 -0
- package/dist/solidfs/PodSolidFsHydrator.js +127 -0
- package/dist/solidfs/PodSolidFsHydrator.js.map +1 -0
- package/dist/solidfs/PodSolidFsSyncer.d.ts +21 -0
- package/dist/solidfs/PodSolidFsSyncer.js +78 -0
- package/dist/solidfs/PodSolidFsSyncer.js.map +1 -0
- package/dist/solidfs/RdfIndexSolidFsSyncer.d.ts +22 -0
- package/dist/solidfs/RdfIndexSolidFsSyncer.js +131 -0
- package/dist/solidfs/RdfIndexSolidFsSyncer.js.map +1 -0
- package/dist/solidfs/index.d.ts +7 -0
- package/dist/solidfs/index.js +24 -0
- package/dist/solidfs/index.js.map +1 -0
- package/dist/solidfs/types.d.ts +131 -0
- package/dist/solidfs/types.js +19 -0
- package/dist/solidfs/types.js.map +1 -0
- package/dist/storage/RepresentationPartialConvertingStore.js +6 -13
- package/dist/storage/RepresentationPartialConvertingStore.js.map +1 -1
- package/dist/storage/SparqlUpdateResourceStore.d.ts +4 -0
- package/dist/storage/SparqlUpdateResourceStore.js +13 -0
- package/dist/storage/SparqlUpdateResourceStore.js.map +1 -1
- package/dist/storage/SparqlUpdateResourceStore.jsonld +26 -0
- package/dist/storage/accessors/MixDataAccessor.d.ts +85 -4
- package/dist/storage/accessors/MixDataAccessor.js +511 -16
- package/dist/storage/accessors/MixDataAccessor.js.map +1 -1
- package/dist/storage/accessors/MixDataAccessor.jsonld +176 -1
- package/dist/storage/accessors/QuintStoreSparqlDataAccessor.d.ts +7 -0
- package/dist/storage/accessors/QuintStoreSparqlDataAccessor.js +72 -4
- package/dist/storage/accessors/QuintStoreSparqlDataAccessor.js.map +1 -1
- package/dist/storage/accessors/QuintStoreSparqlDataAccessor.jsonld +24 -0
- package/dist/storage/quint/BaseQuintStore.d.ts +3 -0
- package/dist/storage/quint/BaseQuintStore.js +51 -27
- package/dist/storage/quint/BaseQuintStore.js.map +1 -1
- package/dist/storage/quint/PgQuintStore.d.ts +1 -0
- package/dist/storage/quint/PgQuintStore.js +50 -32
- package/dist/storage/quint/PgQuintStore.js.map +1 -1
- package/dist/storage/quint/PgQuintStore.jsonld +4 -3
- package/dist/storage/quint/SqliteQuintStore.d.ts +5 -0
- package/dist/storage/quint/SqliteQuintStore.js +100 -0
- package/dist/storage/quint/SqliteQuintStore.js.map +1 -1
- package/dist/storage/quint/SqliteQuintStore.jsonld +20 -0
- package/dist/storage/quint/types.d.ts +16 -0
- package/dist/storage/quint/types.js.map +1 -1
- package/dist/storage/rdf/Rdf3xTripleIndex.d.ts +55 -0
- package/dist/storage/rdf/Rdf3xTripleIndex.js +1235 -0
- package/dist/storage/rdf/Rdf3xTripleIndex.js.map +1 -0
- package/dist/storage/rdf/RdfContentTypes.d.ts +9 -0
- package/dist/storage/rdf/RdfContentTypes.js +79 -0
- package/dist/storage/rdf/RdfContentTypes.js.map +1 -0
- package/dist/storage/rdf/RdfLocalQueryEngine.d.ts +79 -0
- package/dist/storage/rdf/RdfLocalQueryEngine.js +2705 -0
- package/dist/storage/rdf/RdfLocalQueryEngine.js.map +1 -0
- package/dist/storage/rdf/RdfQuadIndex.d.ts +98 -0
- package/dist/storage/rdf/RdfQuadIndex.js +1840 -0
- package/dist/storage/rdf/RdfQuadIndex.js.map +1 -0
- package/dist/storage/rdf/RdfQuadIndex.jsonld +416 -0
- package/dist/storage/rdf/RdfShadowComparator.d.ts +12 -0
- package/dist/storage/rdf/RdfShadowComparator.js +47 -0
- package/dist/storage/rdf/RdfShadowComparator.js.map +1 -0
- package/dist/storage/rdf/RdfSparqlAdapter.d.ts +147 -0
- package/dist/storage/rdf/RdfSparqlAdapter.js +2420 -0
- package/dist/storage/rdf/RdfSparqlAdapter.js.map +1 -0
- package/dist/storage/rdf/RdfSparqlAdapter.jsonld +414 -0
- package/dist/storage/rdf/RdfTermDictionary.d.ts +27 -0
- package/dist/storage/rdf/RdfTermDictionary.js +352 -0
- package/dist/storage/rdf/RdfTermDictionary.js.map +1 -0
- package/dist/storage/rdf/RdfTermDictionary.jsonld +114 -0
- package/dist/storage/rdf/RdfTermSemantics.d.ts +6 -0
- package/dist/storage/rdf/RdfTermSemantics.js +40 -0
- package/dist/storage/rdf/RdfTermSemantics.js.map +1 -0
- package/dist/storage/rdf/RdfTextIndex.d.ts +23 -0
- package/dist/storage/rdf/RdfTextIndex.js +569 -0
- package/dist/storage/rdf/RdfTextIndex.js.map +1 -0
- package/dist/storage/rdf/RdfVectorIndex.d.ts +22 -0
- package/dist/storage/rdf/RdfVectorIndex.js +631 -0
- package/dist/storage/rdf/RdfVectorIndex.js.map +1 -0
- package/dist/storage/rdf/RdfXmlSerializer.d.ts +2 -0
- package/dist/storage/rdf/RdfXmlSerializer.js +123 -0
- package/dist/storage/rdf/RdfXmlSerializer.js.map +1 -0
- package/dist/storage/rdf/ShadowRdfQuintStore.d.ts +58 -0
- package/dist/storage/rdf/ShadowRdfQuintStore.js +202 -0
- package/dist/storage/rdf/ShadowRdfQuintStore.js.map +1 -0
- package/dist/storage/rdf/ShadowRdfQuintStore.jsonld +308 -0
- package/dist/storage/rdf/SolidRdfEngine.d.ts +56 -0
- package/dist/storage/rdf/SolidRdfEngine.js +292 -0
- package/dist/storage/rdf/SolidRdfEngine.js.map +1 -0
- package/dist/storage/rdf/SolidRdfEngine.jsonld +372 -0
- package/dist/storage/rdf/SolidRdfSparqlEngine.d.ts +92 -0
- package/dist/storage/rdf/SolidRdfSparqlEngine.js +477 -0
- package/dist/storage/rdf/SolidRdfSparqlEngine.js.map +1 -0
- package/dist/storage/rdf/SolidRdfSparqlEngine.jsonld +257 -0
- package/dist/storage/rdf/index.d.ts +15 -0
- package/dist/storage/rdf/index.js +61 -0
- package/dist/storage/rdf/index.js.map +1 -0
- package/dist/storage/rdf/models-benchmark.d.ts +260 -0
- package/dist/storage/rdf/models-benchmark.js +1405 -0
- package/dist/storage/rdf/models-benchmark.js.map +1 -0
- package/dist/storage/rdf/types.d.ts +726 -0
- package/dist/storage/rdf/types.js +3 -0
- package/dist/storage/rdf/types.js.map +1 -0
- package/dist/storage/rdf/types.jsonld +316 -0
- package/dist/storage/vector/VectorIndexingListener.d.ts +5 -5
- package/dist/storage/vector/VectorIndexingListener.js +19 -19
- package/dist/storage/vector/VectorIndexingListener.js.map +1 -1
- package/package.json +3 -2
- package/templates/pod/acp/.acr.hbs +39 -0
- package/templates/pod/acp/README.acr +18 -0
- package/templates/pod/acp/profile/card.acr +22 -0
- package/templates/pod/base/README$.md.hbs +27 -0
- package/templates/pod/base/profile/card$.ttl.hbs +13 -0
- package/templates/pod/wac/.acl.hbs +26 -0
- package/templates/pod/wac/README.acl.hbs +14 -0
- package/templates/pod/wac/profile/card.acl.hbs +19 -0
- package/dist/api/handlers/WebIdProfileHandler.d.ts +0 -16
- package/dist/api/handlers/WebIdProfileHandler.js +0 -423
- package/dist/api/handlers/WebIdProfileHandler.js.map +0 -1
- package/dist/identity/drizzle/WebIdProfileRepository.d.ts +0 -63
- package/dist/identity/drizzle/WebIdProfileRepository.js +0 -168
- package/dist/identity/drizzle/WebIdProfileRepository.js.map +0 -1
- package/dist/identity/drizzle/WebIdProfileRepository.jsonld +0 -112
- 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
|
-
|
|
272
|
-
if (!
|
|
271
|
+
chatSurfaceIdFromResource(chat) {
|
|
272
|
+
if (!chat) {
|
|
273
273
|
return undefined;
|
|
274
274
|
}
|
|
275
275
|
try {
|
|
276
|
-
const url = new URL(
|
|
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(
|
|
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,
|
|
318
|
+
threadRecordToMetadata(record, chatResourceMap) {
|
|
319
319
|
const commandKind = record.commandKind === 'task' ? 'task' : 'chat';
|
|
320
|
-
const surfaceId = record.surfaceId || this.
|
|
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
|
-
|
|
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.
|
|
471
|
+
return (0, store_1.resolveDataResource)(podBaseUrl, resourceId);
|
|
472
472
|
}
|
|
473
|
-
|
|
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 (
|
|
479
|
-
return
|
|
478
|
+
if (resource.startsWith(dataPrefix)) {
|
|
479
|
+
return resource.slice(dataPrefix.length);
|
|
480
480
|
}
|
|
481
481
|
}
|
|
482
482
|
const marker = '/.data/';
|
|
483
|
-
const markerIndex =
|
|
483
|
+
const markerIndex = resource.indexOf(marker);
|
|
484
484
|
if (markerIndex >= 0) {
|
|
485
|
-
return
|
|
485
|
+
return resource.slice(markerIndex + marker.length);
|
|
486
486
|
}
|
|
487
|
-
return
|
|
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
|
|
591
|
-
* drizzle-solid 的
|
|
590
|
+
* 获取或构建 Chat resource -> surface id 的映射缓存。
|
|
591
|
+
* drizzle-solid 的 link(Chat) 字段返回完整资源引用,通过 Chat 的 @id 比对还原路径槽位。
|
|
592
592
|
*/
|
|
593
|
-
async
|
|
594
|
-
if (context.
|
|
595
|
-
return context.
|
|
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.
|
|
613
|
+
context._chatResourceMap = map;
|
|
614
614
|
return map;
|
|
615
615
|
}
|
|
616
616
|
/**
|
|
617
|
-
* 从 Chat
|
|
617
|
+
* 从 Chat resource 还原 surface id。
|
|
618
618
|
* 优先通过 @id 映射;若调用方本来给的是裸 ID,则原样使用。
|
|
619
619
|
*/
|
|
620
|
-
|
|
621
|
-
if (!
|
|
620
|
+
resolveChatSurfaceFromResource(chat, chatResourceMap, defaultSurfaceId) {
|
|
621
|
+
if (!chat)
|
|
622
622
|
return defaultSurfaceId;
|
|
623
|
-
const bare =
|
|
623
|
+
const bare = chatResourceMap.get(chat);
|
|
624
624
|
if (bare)
|
|
625
625
|
return bare;
|
|
626
|
-
const parsed = this.
|
|
626
|
+
const parsed = this.chatSurfaceIdFromResource(chat);
|
|
627
627
|
if (parsed)
|
|
628
628
|
return parsed;
|
|
629
|
-
return
|
|
629
|
+
return chat.includes('/') ? defaultSurfaceId : chat;
|
|
630
630
|
}
|
|
631
|
-
|
|
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
|
-
|
|
640
|
+
parseThreadResource(thread) {
|
|
641
641
|
try {
|
|
642
|
-
const url = new URL(
|
|
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
|
-
|
|
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
|
|
679
|
-
if (this.
|
|
680
|
-
const parsed = this.
|
|
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
|
|
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(
|
|
687
|
+
const parsedResourceId = this.parseThreadResourceId(threadRef);
|
|
688
688
|
if (parsedResourceId) {
|
|
689
|
-
const
|
|
689
|
+
const threadResource = this.resolveDataResource(parsedResourceId.threadId, context);
|
|
690
690
|
this.cacheThreadSurfaceId(context, parsedResourceId.threadId, parsedResourceId.surfaceId);
|
|
691
691
|
return {
|
|
692
692
|
...parsedResourceId,
|
|
693
|
-
|
|
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 "${
|
|
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:
|
|
702
|
+
key: threadRef,
|
|
703
703
|
commandKind,
|
|
704
704
|
surfaceId,
|
|
705
705
|
});
|
|
706
|
-
const
|
|
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
|
-
|
|
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.
|
|
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.
|
|
798
|
+
id: this.baseRelativeIdFromResource(this.parseSparqlBindingValue(binding, 'msg') ?? '', context),
|
|
799
799
|
chat: null,
|
|
800
|
-
thread: resolvedThread.
|
|
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
|
-
|
|
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.
|
|
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
|
|
859
|
-
const metadata = this.threadRecordToMetadata(threadRecord,
|
|
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
|
|
895
|
+
const threadResource = this.resolveDataResource(threadResourceId, context);
|
|
896
896
|
// 检查 Thread 是否存在
|
|
897
|
-
const existing = await db.findByIri(schema_1.Thread,
|
|
897
|
+
const existing = await db.findByIri(schema_1.Thread, threadResource);
|
|
898
898
|
if (existing) {
|
|
899
899
|
// Update
|
|
900
|
-
await db.updateByIri(schema_1.Thread,
|
|
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
|
|
961
|
+
const chatResourceMap = await this.getChatResourceMap(context);
|
|
962
962
|
return {
|
|
963
|
-
data: slice.map((t) => this.threadRecordToMetadata(t,
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
|
1190
|
-
const hashIndex =
|
|
1191
|
-
const resourceUrl = hashIndex >= 0 ?
|
|
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(`<${
|
|
1216
|
-
insertTriples.push(`<${
|
|
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(`<${
|
|
1220
|
-
insertTriples.push(`<${
|
|
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(`<${
|
|
1224
|
-
insertTriples.push(`<${
|
|
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,
|
|
1242
|
-
if (!
|
|
1243
|
-
throw new Error('Cannot delete message without
|
|
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 =
|
|
1250
|
-
const resourceUrl = hashIndex >= 0 ?
|
|
1251
|
-
const sparql = `DELETE WHERE { <${
|
|
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.
|
|
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
|
|
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
|
-
|
|
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.
|
|
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.
|
|
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
|
-
//
|
|
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);
|