@undefineds.co/models 0.2.16 → 0.2.19

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.
@@ -13,7 +13,7 @@ export declare const auditResource: import("@undefineds.co/drizzle-solid/dist/co
13
13
  policyVersion: import("@undefineds.co/drizzle-solid/dist/core/schema").ColumnBuilder<"string", null, false, false>;
14
14
  createdAt: import("@undefineds.co/drizzle-solid/dist/core/schema").ColumnBuilder<"datetime", null, true, true>;
15
15
  }>>;
16
- export declare function buildAuditSubjectPath(auditId: string, createdAt?: Date | string | number): string;
16
+ export declare function extractAuditIdFromAuditRef(auditRef: string | null | undefined): string | null;
17
17
  export declare const auditTable: import("@undefineds.co/drizzle-solid/dist/core/schema").PodTableWithColumns<import("@undefineds.co/drizzle-solid/dist/core/schema").ResolvedColumns<{
18
18
  id: import("@undefineds.co/drizzle-solid/dist/core/schema").PodStringColumn<false, false>;
19
19
  action: import("@undefineds.co/drizzle-solid/dist/core/schema").ColumnBuilder<"string", null, true, false>;
@@ -1,4 +1,4 @@
1
- import { podTable, uri, string, timestamp, id } from '@undefineds.co/drizzle-solid';
1
+ import { extractPodResourceTemplateValue, podTable, uri, string, timestamp, id } from '@undefineds.co/drizzle-solid';
2
2
  import { UDFS, DCTerms } from './namespaces.js';
3
3
  // Append-only audit entry resource (separate from Solid inbox notifications).
4
4
  // Audit entries are independent events; session/chat/thread are optional relations,
@@ -29,13 +29,8 @@ export const auditResource = podTable('audit', {
29
29
  namespace: UDFS,
30
30
  subjectTemplate: '{yyyy}/{MM}/{dd}.ttl#{id}',
31
31
  });
32
- export function buildAuditSubjectPath(auditId, createdAt = new Date()) {
33
- const date = createdAt instanceof Date ? createdAt : new Date(createdAt);
34
- const safeDate = Number.isFinite(date.getTime()) ? date : new Date();
35
- const yyyy = String(safeDate.getUTCFullYear());
36
- const mm = String(safeDate.getUTCMonth() + 1).padStart(2, '0');
37
- const dd = String(safeDate.getUTCDate()).padStart(2, '0');
38
- return `/.data/audits/${yyyy}/${mm}/${dd}.ttl#${encodeURIComponent(auditId)}`;
32
+ export function extractAuditIdFromAuditRef(auditRef) {
33
+ return extractPodResourceTemplateValue(auditResource, auditRef);
39
34
  }
40
35
  // Compatibility alias. New model code should prefer `auditResource`.
41
36
  export const auditTable = auditResource;
@@ -1,4 +1,4 @@
1
- export declare const chatRepository: import("./repository").PodRepositoryDescriptor<import("@undefineds.co/drizzle-solid/dist/core/schema").PodTableWithColumns<import("@undefineds.co/drizzle-solid/dist/core/schema").ResolvedColumns<{
1
+ export declare const chatRepository: import("@undefineds.co/drizzle-solid/dist/core/repository").PodRepositoryDescriptor<import("@undefineds.co/drizzle-solid/dist/core/schema").PodTableWithColumns<import("@undefineds.co/drizzle-solid/dist/core/schema").ResolvedColumns<{
2
2
  id: import("@undefineds.co/drizzle-solid/dist/core/schema").PodStringColumn<false, false>;
3
3
  title: import("@undefineds.co/drizzle-solid/dist/core/schema").ColumnBuilder<"string", null, true, false>;
4
4
  description: import("@undefineds.co/drizzle-solid/dist/core/schema").ColumnBuilder<"string", null, false, false>;
@@ -0,0 +1,9 @@
1
+ export declare const toTimestamp: (value: unknown, fallback?: number) => number;
2
+ export interface ChatThreadRef {
3
+ chatId: string | null;
4
+ threadId: string | null;
5
+ }
6
+ export declare function extractChatIdFromChatRef(chatRef: string | null | undefined): string | null;
7
+ export declare function extractThreadIdFromThreadRef(threadRef: string | null | undefined): string | null;
8
+ export declare function extractChatThreadRef(uri: string | null | undefined): ChatThreadRef;
9
+ export declare function resolveThreadChatId(thread: Pick<Record<string, unknown>, 'chat'> | null | undefined): string | null;
@@ -0,0 +1,33 @@
1
+ import { extractPodResourceTemplateValue, parsePodResourceRef } from '@undefineds.co/drizzle-solid';
2
+ import { chatResource } from './chat.schema.js';
3
+ import { threadResource } from './thread.schema.js';
4
+ export const toTimestamp = (value, fallback = 0) => {
5
+ if (value instanceof Date)
6
+ return value.getTime();
7
+ if (typeof value === 'string') {
8
+ const ms = new Date(value).getTime();
9
+ return Number.isNaN(ms) ? fallback : ms;
10
+ }
11
+ if (typeof value === 'number')
12
+ return value;
13
+ return fallback;
14
+ };
15
+ export function extractChatIdFromChatRef(chatRef) {
16
+ return extractPodResourceTemplateValue(threadResource, chatRef, 'chat')
17
+ ?? extractPodResourceTemplateValue(chatResource, chatRef);
18
+ }
19
+ export function extractThreadIdFromThreadRef(threadRef) {
20
+ return extractPodResourceTemplateValue(threadResource, threadRef);
21
+ }
22
+ export function extractChatThreadRef(uri) {
23
+ if (!uri)
24
+ return { chatId: null, threadId: null };
25
+ const parsed = parsePodResourceRef(threadResource, uri);
26
+ return {
27
+ chatId: parsed?.templateValues.chat ?? null,
28
+ threadId: parsed?.templateValues.id ?? null,
29
+ };
30
+ }
31
+ export function resolveThreadChatId(thread) {
32
+ return extractChatIdFromChatRef(typeof thread?.chat === 'string' ? thread.chat : null);
33
+ }
@@ -1,4 +1,4 @@
1
- export declare const contactRepository: import("./repository").PodRepositoryDescriptor<import("@undefineds.co/drizzle-solid/dist/core/schema").PodTableWithColumns<import("@undefineds.co/drizzle-solid/dist/core/schema").ResolvedColumns<{
1
+ export declare const contactRepository: import("@undefineds.co/drizzle-solid/dist/core/repository").PodRepositoryDescriptor<import("@undefineds.co/drizzle-solid/dist/core/schema").PodTableWithColumns<import("@undefineds.co/drizzle-solid/dist/core/schema").ResolvedColumns<{
2
2
  id: import("@undefineds.co/drizzle-solid/dist/core/schema").PodStringColumn<false, false>;
3
3
  name: import("@undefineds.co/drizzle-solid/dist/core/schema").ColumnBuilder<"string", null, true, false>;
4
4
  avatarUrl: import("@undefineds.co/drizzle-solid/dist/core/schema").ColumnBuilder<"uri", null, false, false>;
@@ -5,6 +5,13 @@ export declare const ContactType: {
5
5
  readonly GROUP: "group";
6
6
  };
7
7
  export type ContactTypeValue = typeof ContactType[keyof typeof ContactType];
8
+ export declare const ContactGender: {
9
+ readonly MALE: "male";
10
+ readonly FEMALE: "female";
11
+ readonly BOT: "bot";
12
+ readonly UNKNOWN: "unknown";
13
+ };
14
+ export type ContactGenderValue = typeof ContactGender[keyof typeof ContactGender];
8
15
  export declare const ContactClass: {
9
16
  readonly PERSON: string;
10
17
  readonly AGENT: string;
@@ -17,6 +24,7 @@ type ContactClassifier = {
17
24
  };
18
25
  export declare function isGroupContact(contact: ContactClassifier | null | undefined): boolean;
19
26
  export declare function isAgentContact(contact: ContactClassifier | null | undefined): boolean;
27
+ export declare function normalizeContactGender(value: string | null | undefined, fallback?: ContactGenderValue): ContactGenderValue | undefined;
20
28
  /**
21
29
  * Contact Table - Unified contact index for all contact types.
22
30
  */
@@ -6,6 +6,12 @@ export const ContactType = {
6
6
  AGENT: 'agent',
7
7
  GROUP: 'group',
8
8
  };
9
+ export const ContactGender = {
10
+ MALE: 'male',
11
+ FEMALE: 'female',
12
+ BOT: 'bot',
13
+ UNKNOWN: 'unknown',
14
+ };
9
15
  export const ContactClass = {
10
16
  PERSON: UDFS.PersonContact,
11
17
  AGENT: UDFS.AgentContact,
@@ -17,6 +23,12 @@ export function isGroupContact(contact) {
17
23
  export function isAgentContact(contact) {
18
24
  return contact?.rdfType === ContactClass.AGENT || contact?.contactType === ContactType.AGENT;
19
25
  }
26
+ export function normalizeContactGender(value, fallback) {
27
+ if (value === ContactGender.MALE || value === ContactGender.FEMALE || value === ContactGender.BOT || value === ContactGender.UNKNOWN) {
28
+ return value;
29
+ }
30
+ return fallback;
31
+ }
20
32
  /**
21
33
  * Contact Table - Unified contact index for all contact types.
22
34
  */
@@ -2,7 +2,7 @@ import { id, integer, podTable, string, timestamp, uri } from "@undefineds.co/dr
2
2
  import { XPOD_CREDENTIAL } from "./namespaces.js";
3
3
  export const credentialTable = podTable("credential", {
4
4
  id: id("id"),
5
- provider: uri("provider").predicate(XPOD_CREDENTIAL.provider),
5
+ provider: uri("provider").predicate(XPOD_CREDENTIAL.provider).link("aiProvider"),
6
6
  service: string("service").predicate(XPOD_CREDENTIAL.service).notNull().default("ai"),
7
7
  status: string("status").predicate(XPOD_CREDENTIAL.status).notNull().default("active"),
8
8
  apiKey: string("apiKey").predicate(XPOD_CREDENTIAL.apiKey),
@@ -1,4 +1,3 @@
1
- export declare function buildGrantSubjectPath(grantId: string): string;
2
1
  export declare const grantResource: import("@undefineds.co/drizzle-solid/dist/core/schema").PodTableWithColumns<import("@undefineds.co/drizzle-solid/dist/core/schema").ResolvedColumns<{
3
2
  id: import("@undefineds.co/drizzle-solid/dist/core/schema").PodStringColumn<false, false>;
4
3
  rdfType: import("@undefineds.co/drizzle-solid/dist/core/schema").ColumnBuilder<"array", "uri", true, true>;
@@ -1,8 +1,5 @@
1
1
  import { podTable, uri, string, text, timestamp, id } from '@undefineds.co/drizzle-solid';
2
2
  import { RDF, ODRL, UDFS, DCTerms } from './namespaces.js';
3
- export function buildGrantSubjectPath(grantId) {
4
- return `/settings/autonomy/grants/${encodeURIComponent(grantId)}.ttl`;
5
- }
6
3
  // Persistent delegation grant resource generated by "do not ask again" decisions.
7
4
  // This is the durable "delegation" layer (distinct from one-off approvals and append-only audit entries).
8
5
  export const grantResource = podTable('grant', {
package/dist/index.d.ts CHANGED
@@ -3,10 +3,11 @@ export * from "./vocab";
3
3
  export * from './profile';
4
4
  export * from './profile.repository';
5
5
  export * from './profile.schema';
6
- export { contactTable, ContactClass, ContactType, isAgentContact, isGroupContact, type ContactRow, type ContactInsert, type ContactUpdate, type ContactClassValue, type ContactTypeValue, } from './contact.schema';
6
+ export { ContactGender, contactTable, ContactClass, ContactType, isAgentContact, isGroupContact, normalizeContactGender, type ContactRow, type ContactInsert, type ContactUpdate, type ContactClassValue, type ContactGenderValue, type ContactTypeValue, } from './contact.schema';
7
7
  export { contactRepository } from './contact.repository';
8
8
  export { chatResource, chatTable, type ChatMetadata, type ChatMemberRole, type ChatRow, type ChatInsert, type ChatUpdate, } from './chat.schema';
9
9
  export { chatRepository } from './chat.repository';
10
+ export { extractChatIdFromChatRef, extractChatThreadRef, extractThreadIdFromThreadRef, resolveThreadChatId, toTimestamp, type ChatThreadRef, } from './chat.utils';
10
11
  export { threadResource, threadTable, type ThreadRow, type ThreadInsert, type ThreadUpdate, } from './thread.schema';
11
12
  export { threadRepository } from './thread.repository';
12
13
  export { messageResource, messageTable, type MessageRow, type MessageInsert, type MessageUpdate, } from './message.schema';
@@ -20,11 +21,12 @@ export { settingsTable, SETTING_KEYS, type SettingKey, type SettingsRow, type Se
20
21
  export { agentTable, type AgentRow, type AgentInsert, type AgentUpdate, } from './agent.schema';
21
22
  export { agentRepository } from './agent.repository';
22
23
  export { DEFAULT_AGENT_PROVIDERS, type AgentProviderMetadata, type AgentModelOption, } from './agent.providers';
23
- export { sessionResource, sessionTable, buildSessionSubjectPath, type SessionType, type SessionStatus, type SessionRow, type SessionInsert, type SessionUpdate, } from './session';
24
+ export { sessionResource, sessionTable, buildRuntimeSessionIri, extractRuntimeSessionId, type SessionType, type SessionStatus, type SessionRow, type SessionInsert, type SessionUpdate, } from './session';
24
25
  export { sessionRepository } from './session.repository';
25
- export { approvalResource, approvalTable, buildApprovalSubjectPath, type ApprovalRow, type ApprovalInsert, type ApprovalUpdate, } from './approval.schema';
26
- export { auditResource, auditTable, buildAuditSubjectPath, type AuditRow, type AuditInsert, type AuditUpdate, } from './audit.schema';
27
- export { grantResource, grantTable, buildGrantSubjectPath, type GrantRow, type GrantInsert, type GrantUpdate, } from './grant.schema';
26
+ export { approvalResource, approvalTable, extractApprovalIdFromApprovalRef, type ApprovalRow, type ApprovalInsert, type ApprovalUpdate, } from './approval.schema';
27
+ export { auditResource, auditTable, extractAuditIdFromAuditRef, type AuditRow, type AuditInsert, type AuditUpdate, } from './audit.schema';
28
+ export { buildAuditDetailRecord, buildAuditPresentation, createResolvedAuthTimestampsIndex, formatAuditActorRole, formatInboxStatusLabel, type AuditPresentation, } from './audit.presentation';
29
+ export { grantResource, grantTable, type GrantRow, type GrantInsert, type GrantUpdate, } from './grant.schema';
28
30
  export { inboxNotificationTable, type InboxNotificationRow, type InboxNotificationInsert, type InboxNotificationUpdate, } from './inbox-notification.schema';
29
31
  export { ApprovalVocab, AuditVocab, GrantVocab, InboxNotificationVocab } from './vocab/sidecar.vocab';
30
32
  export * from './sidecar/sidecar-events';
@@ -34,10 +36,10 @@ export { extensionSchema } from './extension';
34
36
  export { credentialTable, type CredentialRow, type CredentialInsert, type CredentialUpdate, } from "./credential.schema";
35
37
  export { aiProviderTable, type AIProviderRow, type AIProviderInsert, type AIProviderUpdate, } from "./ai-provider.schema";
36
38
  export { aiModelTable, type AIModelRow, type AIModelInsert, type AIModelUpdate, } from "./ai-model.schema";
37
- export { aiConfigModelUri, aiConfigProviderUri, buildAIConfigMutationPlan, buildAIConfigProviderStateMap, getAIConfigDefaultBaseUrl, getAIConfigProviderCatalog, getAIConfigProviderFamilyIds, getAIConfigProviderMetadata, getDefaultAIConfigCredentialId, normalizeAIConfigProviderId, normalizeAIConfigResourceId, sameAIConfigProviderFamily, type AIConfigModel, type AIConfigMutationPlan, type AIConfigProviderCatalogEntry, type AIConfigProviderState, type AIConfigUpdate, type BuildAIConfigProviderStateMapOptions, } from './ai-config';
39
+ export { aiConfigModelRef, aiConfigProviderRef, buildAIConfigMutationPlan, buildAIConfigProviderStateMap, getAIConfigDefaultBaseUrl, getAIConfigProviderCatalog, getAIConfigProviderFamilyIds, getAIConfigProviderMetadata, getDefaultAIConfigCredentialId, normalizeAIConfigProviderId, normalizeAIConfigModelId, normalizeAIConfigResourceId, sameAIConfigProviderFamily, type AIConfigModel, type AIConfigMutationPlan, type AIConfigProviderCatalogEntry, type AIConfigProviderState, type AIConfigUpdate, type BuildAIConfigProviderStateMapOptions, } from './ai-config';
38
40
  export { buildAcpPermissionResponse, buildWatchThreadMetadata, buildWatchTranscriptMessages, buildWatchUserInputResponse, createWatchSessionId, detectWatchAuthFailure, formatWatchAutoFallbackMessage, formatWatchBackendAuthMessage, extractWatchSessionIdFromJsonLine, getWatchArchiveRelativePaths, getWatchAuthLoginCommand, looksLikeWatchAuthFailureText, normalizeAcpInteractionRequest, normalizeAcpRequest, normalizeAcpSessionNotification, normalizeCodexAppServerNotification, normalizeCodexAppServerRequest, normalizeWatchCredentialSource, parseWatchClaudeAuthStatus, parseWatchJsonLine, parseWatchJsonProtocolLine, resolveWatchAutoApprovalDecision, resolveWatchCredentialSourceResolution, resolveWatchInteractionAutoResponse, resolveWatchQuestionAnswer, shouldAttemptCloudCredentialProbe, WATCH_EVENTS_FILE_NAME, WATCH_HOME_DIRNAME, WATCH_SESSIONS_DIRNAME, WATCH_SESSION_FILE_NAME, type WatchApprovalDecision, type WatchApprovalRequest, type CreateWatchSessionIdOptions, type WatchAuthFailure, type WatchAuthState, type WatchAuthStatus, type WatchArchiveRelativePaths, type WatchBackend, type WatchCloudCredentialProbe, type WatchCloudCredentialProbeStatus, type WatchCredentialSource, type WatchCredentialSourceResolution, type WatchEventLogEntry, type WatchMode, type WatchNormalizedEvent, type WatchOutputStream, type WatchResolvedCredentialSource, type WatchRuntime, type WatchSessionRecord, type WatchSessionStatus, type WatchThreadMetadata, type WatchTranscriptMessage, type WatchTranscriptMessageRole, type WatchTranscriptMessageSource, } from './watch';
39
41
  export { applySolidComunicaPatches, } from './comunica-patches';
40
- export { createRepositoryDescriptor, definePodRepository, findPodRowByStorageId, initSolidTables, resolveRowId, resolvePodUri, whereByPodStorageId, type AnyPodTable, type PodRepositoryDescriptor, type RepositoryCacheOptions, type RepositoryInvalidations, type RepositoryScope, type SolidDatabase, } from './repository';
42
+ export { createRepositoryDescriptor, definePodRepository, initSolidTables, type AnyPodTable, type PodRepositoryDescriptor, type RepositoryCacheOptions, type RepositoryInvalidations, type RepositoryScope, type SolidDatabase, } from './repository';
41
43
  export { importJobSchema } from './import';
42
44
  export { eq, ne, and, or, drizzle } from '@undefineds.co/drizzle-solid';
43
45
  export { solidResources, solidSchema } from './schema';
package/dist/index.js CHANGED
@@ -20,11 +20,12 @@ export * from './profile.js';
20
20
  export * from './profile.repository.js';
21
21
  export * from './profile.schema.js';
22
22
  // Contact - 联系人 (unified index for Solid users, external users, and AI agents)
23
- export { contactTable, ContactClass, ContactType, isAgentContact, isGroupContact, } from './contact.schema.js';
23
+ export { ContactGender, contactTable, ContactClass, ContactType, isAgentContact, isGroupContact, normalizeContactGender, } from './contact.schema.js';
24
24
  export { contactRepository } from './contact.repository.js';
25
25
  // Chat & Message - 聊天和消息
26
26
  export { chatResource, chatTable, } from './chat.schema.js';
27
27
  export { chatRepository } from './chat.repository.js';
28
+ export { extractChatIdFromChatRef, extractChatThreadRef, extractThreadIdFromThreadRef, resolveThreadChatId, toTimestamp, } from './chat.utils.js';
28
29
  export { threadResource, threadTable, } from './thread.schema.js';
29
30
  export { threadRepository } from './thread.repository.js';
30
31
  export { messageResource, messageTable, } from './message.schema.js';
@@ -49,12 +50,13 @@ export { DEFAULT_AGENT_PROVIDERS, } from './agent.providers.js';
49
50
  // 其他模型
50
51
  // ============================================
51
52
  // Session - 会话管理
52
- export { sessionResource, sessionTable, buildSessionSubjectPath, } from './session/index.js';
53
+ export { sessionResource, sessionTable, buildRuntimeSessionIri, extractRuntimeSessionId, } from './session/index.js';
53
54
  export { sessionRepository } from './session.repository.js';
54
55
  // Approval / Audit / Grant / Inbox Notification
55
- export { approvalResource, approvalTable, buildApprovalSubjectPath, } from './approval.schema.js';
56
- export { auditResource, auditTable, buildAuditSubjectPath, } from './audit.schema.js';
57
- export { grantResource, grantTable, buildGrantSubjectPath, } from './grant.schema.js';
56
+ export { approvalResource, approvalTable, extractApprovalIdFromApprovalRef, } from './approval.schema.js';
57
+ export { auditResource, auditTable, extractAuditIdFromAuditRef, } from './audit.schema.js';
58
+ export { buildAuditDetailRecord, buildAuditPresentation, createResolvedAuthTimestampsIndex, formatAuditActorRole, formatInboxStatusLabel, } from './audit.presentation.js';
59
+ export { grantResource, grantTable, } from './grant.schema.js';
58
60
  export { inboxNotificationTable, } from './inbox-notification.schema.js';
59
61
  // Sidecar vocab + runtime contracts
60
62
  export { ApprovalVocab, AuditVocab, GrantVocab, InboxNotificationVocab } from './vocab/sidecar.vocab.js';
@@ -68,10 +70,10 @@ export { extensionSchema } from './extension/index.js';
68
70
  export { credentialTable, } from "./credential.schema.js";
69
71
  export { aiProviderTable, } from "./ai-provider.schema.js";
70
72
  export { aiModelTable, } from "./ai-model.schema.js";
71
- export { aiConfigModelUri, aiConfigProviderUri, buildAIConfigMutationPlan, buildAIConfigProviderStateMap, getAIConfigDefaultBaseUrl, getAIConfigProviderCatalog, getAIConfigProviderFamilyIds, getAIConfigProviderMetadata, getDefaultAIConfigCredentialId, normalizeAIConfigProviderId, normalizeAIConfigResourceId, sameAIConfigProviderFamily, } from './ai-config/index.js';
73
+ export { aiConfigModelRef, aiConfigProviderRef, buildAIConfigMutationPlan, buildAIConfigProviderStateMap, getAIConfigDefaultBaseUrl, getAIConfigProviderCatalog, getAIConfigProviderFamilyIds, getAIConfigProviderMetadata, getDefaultAIConfigCredentialId, normalizeAIConfigProviderId, normalizeAIConfigModelId, normalizeAIConfigResourceId, sameAIConfigProviderFamily, } from './ai-config/index.js';
72
74
  export { buildAcpPermissionResponse, buildWatchThreadMetadata, buildWatchTranscriptMessages, buildWatchUserInputResponse, createWatchSessionId, detectWatchAuthFailure, formatWatchAutoFallbackMessage, formatWatchBackendAuthMessage, extractWatchSessionIdFromJsonLine, getWatchArchiveRelativePaths, getWatchAuthLoginCommand, looksLikeWatchAuthFailureText, normalizeAcpInteractionRequest, normalizeAcpRequest, normalizeAcpSessionNotification, normalizeCodexAppServerNotification, normalizeCodexAppServerRequest, normalizeWatchCredentialSource, parseWatchClaudeAuthStatus, parseWatchJsonLine, parseWatchJsonProtocolLine, resolveWatchAutoApprovalDecision, resolveWatchCredentialSourceResolution, resolveWatchInteractionAutoResponse, resolveWatchQuestionAnswer, shouldAttemptCloudCredentialProbe, WATCH_EVENTS_FILE_NAME, WATCH_HOME_DIRNAME, WATCH_SESSIONS_DIRNAME, WATCH_SESSION_FILE_NAME, } from './watch/index.js';
73
75
  export { applySolidComunicaPatches, } from './comunica-patches.js';
74
- export { createRepositoryDescriptor, definePodRepository, findPodRowByStorageId, initSolidTables, resolveRowId, resolvePodUri, whereByPodStorageId, } from './repository.js';
76
+ export { createRepositoryDescriptor, definePodRepository, initSolidTables, } from './repository.js';
75
77
  // Import Job - 导入任务
76
78
  export { importJobSchema } from './import/index.js';
77
79
  // ============================================
@@ -1,4 +1,4 @@
1
- export declare const messageRepository: import("./repository").PodRepositoryDescriptor<import("@undefineds.co/drizzle-solid/dist/core/schema").PodTableWithColumns<import("@undefineds.co/drizzle-solid/dist/core/schema").ResolvedColumns<{
1
+ export declare const messageRepository: import("@undefineds.co/drizzle-solid/dist/core/repository").PodRepositoryDescriptor<import("@undefineds.co/drizzle-solid/dist/core/schema").PodTableWithColumns<import("@undefineds.co/drizzle-solid/dist/core/schema").ResolvedColumns<{
2
2
  id: import("@undefineds.co/drizzle-solid/dist/core/schema").PodStringColumn<false, false>;
3
3
  chat: import("@undefineds.co/drizzle-solid/dist/core/schema").ColumnBuilder<"uri", null, true, false>;
4
4
  thread: import("@undefineds.co/drizzle-solid/dist/core/schema").ColumnBuilder<"uri", null, true, false>;
@@ -20,9 +20,9 @@ export declare const profileRepository: {
20
20
  field: "name" | "favorite" | "inbox" | "id" | "nick" | "avatar" | "note" | "email" | "phone" | "region" | "gender";
21
21
  direction: "asc" | "desc";
22
22
  } | undefined;
23
- cache?: import("./repository.js").RepositoryCacheOptions;
24
- invalidations: import("./repository.js").RepositoryInvalidations;
25
- list: (db: import("./repository.js").SolidDatabase, filters?: Record<string, unknown> | undefined) => Promise<{
23
+ cache?: import("@undefineds.co/drizzle-solid/dist/core/repository.js").RepositoryCacheOptions;
24
+ invalidations: import("@undefineds.co/drizzle-solid/dist/core/repository.js").RepositoryInvalidations;
25
+ list: (db: import("@undefineds.co/drizzle-solid/dist/driver.js").SolidDatabase, filters?: Record<string, unknown> | undefined) => Promise<{
26
26
  id: string;
27
27
  name: string;
28
28
  nick: string;
@@ -35,7 +35,7 @@ export declare const profileRepository: {
35
35
  favorite: string;
36
36
  inbox: string;
37
37
  }[]>;
38
- detail: (db: import("./repository.js").SolidDatabase, id: string) => Promise<{
38
+ detail: (db: import("@undefineds.co/drizzle-solid/dist/driver.js").SolidDatabase, id: string) => Promise<{
39
39
  id: string;
40
40
  name: string;
41
41
  nick: string;
@@ -48,7 +48,7 @@ export declare const profileRepository: {
48
48
  favorite: string;
49
49
  inbox: string;
50
50
  } | null>;
51
- create?: ((db: import("./repository.js").SolidDatabase, input: {
51
+ create?: ((db: import("@undefineds.co/drizzle-solid/dist/driver.js").SolidDatabase, input: {
52
52
  id?: string | undefined;
53
53
  name?: string | undefined;
54
54
  nick?: string | undefined;
@@ -73,7 +73,7 @@ export declare const profileRepository: {
73
73
  favorite: string;
74
74
  inbox: string;
75
75
  }>) | undefined;
76
- update?: ((db: import("./repository.js").SolidDatabase, id: string, input: {
76
+ update?: ((db: import("@undefineds.co/drizzle-solid/dist/driver.js").SolidDatabase, id: string, input: {
77
77
  id?: string | null | undefined;
78
78
  name?: string | null | undefined;
79
79
  nick?: string | null | undefined;
@@ -98,7 +98,7 @@ export declare const profileRepository: {
98
98
  favorite: string;
99
99
  inbox: string;
100
100
  }>) | undefined;
101
- remove?: (db: import("./repository.js").SolidDatabase, id: string) => Promise<{
101
+ remove?: (db: import("@undefineds.co/drizzle-solid/dist/driver.js").SolidDatabase, id: string) => Promise<{
102
102
  id: string;
103
103
  }>;
104
104
  };
@@ -1,99 +1 @@
1
- import type { PodTable, InferTableData, InferInsertData, InferUpdateData, QueryCondition } from '@undefineds.co/drizzle-solid';
2
- export interface AnyPodTable {
3
- resolveUri?: (id: string) => string;
4
- config?: {
5
- name?: string;
6
- base?: string;
7
- };
8
- getResourcePath?: () => string;
9
- }
10
- export interface PodExecutableQuery<TRow = unknown> {
11
- where(condition: unknown): PodExecutableQuery<TRow>;
12
- whereByIri?(iri: string | string[]): PodExecutableQuery<TRow>;
13
- orderBy(...args: unknown[]): PodExecutableQuery<TRow>;
14
- execute(): Promise<TRow[]>;
15
- }
16
- export interface PodInsertQuery {
17
- values(values: unknown): {
18
- execute(): Promise<unknown[]>;
19
- };
20
- }
21
- export interface PodUpdateQuery {
22
- set(values: unknown): PodMutationQuery;
23
- }
24
- export interface PodMutationQuery {
25
- where(condition: unknown): PodMutationQuery;
26
- whereByIri?(iri: string): PodMutationQuery;
27
- execute(): Promise<unknown[]>;
28
- }
29
- export interface SolidDatabase<TSchema extends Record<string, unknown> = Record<string, unknown>> {
30
- init?(tables: AnyPodTable[] | AnyPodTable, ...rest: unknown[]): Promise<void>;
31
- select(fields?: unknown): {
32
- from(table: AnyPodTable): PodExecutableQuery;
33
- };
34
- insert(table: AnyPodTable): PodInsertQuery;
35
- update(table: AnyPodTable): PodUpdateQuery;
36
- delete(table: AnyPodTable): PodMutationQuery;
37
- findByIri?<T = unknown>(table: AnyPodTable, iri: string): Promise<T | null>;
38
- updateByIri?<T = unknown>(table: AnyPodTable, iri: string, data: Record<string, unknown>): Promise<T | null>;
39
- deleteByIri?(table: AnyPodTable, iri: string): Promise<unknown>;
40
- subscribe?(table: AnyPodTable, options: unknown): Promise<{
41
- unsubscribe?: () => void;
42
- } | (() => void)>;
43
- }
44
- export declare function initSolidTables(db: SolidDatabase, tables: AnyPodTable[]): Promise<void>;
45
- export declare function resolvePodUri(webId: string, table: {
46
- resolveUri?: (id: string) => string;
47
- }, id: string): string;
48
- export declare function findPodRowByStorageId<T>(db: SolidDatabase, webId: string, table: AnyPodTable, id: string): Promise<T | null>;
49
- export declare function whereByPodStorageId<TTable extends AnyPodTable>(webId: string, table: TTable, query: PodMutationQuery, id: string): PodMutationQuery;
50
- export interface RepositoryCacheOptions {
51
- staleTime?: number;
52
- gcTime?: number;
53
- }
54
- export type RepositoryScope = 'list' | 'detail' | string;
55
- export interface RepositoryInvalidations {
56
- create?: RepositoryScope[];
57
- update?: RepositoryScope[];
58
- remove?: RepositoryScope[];
59
- }
60
- export interface RepositoryFilterContext<TTable extends PodTable<any>, Filters> {
61
- table: TTable;
62
- filters?: Filters;
63
- }
64
- export interface PodRepositoryDescriptor<TTable extends PodTable<any>, Row extends Record<string, unknown> = InferTableData<TTable>, Insert = InferInsertData<TTable>, Update = InferUpdateData<TTable>, Filters extends Record<string, unknown> = Record<string, unknown>> {
65
- namespace: string;
66
- resourcePath: string;
67
- searchableFields?: (keyof Row & string)[];
68
- defaultSort?: {
69
- field: keyof Row & string;
70
- direction: 'asc' | 'desc';
71
- };
72
- cache?: RepositoryCacheOptions;
73
- invalidations: RepositoryInvalidations;
74
- list: (db: SolidDatabase, filters?: Filters) => Promise<Row[]>;
75
- detail: (db: SolidDatabase, id: string) => Promise<Row | null>;
76
- create?: (db: SolidDatabase, input: Insert) => Promise<Row>;
77
- update?: (db: SolidDatabase, id: string, input: Update) => Promise<Row>;
78
- remove?: (db: SolidDatabase, id: string) => Promise<{
79
- id: string;
80
- }>;
81
- }
82
- export interface PodRepositoryOptions<TTable extends PodTable<any>, Row extends Record<string, unknown> = InferTableData<TTable>, Filters extends Record<string, unknown> = Record<string, unknown>> {
83
- namespace: string;
84
- table: TTable;
85
- searchableFields?: (keyof Row & string)[];
86
- searchAccessor?: (filters?: Filters) => string | undefined;
87
- defaultSort?: {
88
- field: keyof Row & string;
89
- direction: 'asc' | 'desc';
90
- };
91
- cache?: RepositoryCacheOptions;
92
- invalidations?: Partial<RepositoryInvalidations>;
93
- transform?: (row: Row) => Row;
94
- filter?: (context: RepositoryFilterContext<TTable, Filters>) => QueryCondition | undefined;
95
- disableMutations?: Partial<Record<'create' | 'update' | 'remove', boolean>>;
96
- }
97
- export declare function resolveRowId(row: Partial<Record<string, unknown>> | null): string | null;
98
- export declare function createRepositoryDescriptor<TTable extends PodTable<any>, Row extends Record<string, unknown> = InferTableData<TTable>, Insert = InferInsertData<TTable>, Update = InferUpdateData<TTable>, Filters extends Record<string, unknown> = Record<string, unknown>>(options: PodRepositoryOptions<TTable, Row, Filters>): PodRepositoryDescriptor<TTable, Row, Insert, Update, Filters>;
99
- export declare const definePodRepository: typeof createRepositoryDescriptor;
1
+ export { createRepositoryDescriptor, definePodRepository, initSolidTables, type AnyPodTable, type PodRepositoryDescriptor, type RepositoryCacheOptions, type RepositoryInvalidations, type RepositoryScope, type SolidDatabase, } from '@undefineds.co/drizzle-solid';
@@ -1,189 +1 @@
1
- import { and, like, or } from '@undefineds.co/drizzle-solid';
2
- export async function initSolidTables(db, tables) {
3
- await db.init?.(tables);
4
- }
5
- export function resolvePodUri(webId, table, id) {
6
- const relativeUri = typeof table.resolveUri === 'function' ? table.resolveUri(id) : id;
7
- if (/^https?:\/\//.test(relativeUri)) {
8
- return relativeUri;
9
- }
10
- return new URL(relativeUri.replace(/^\//, ''), `${resolvePodBaseUrl(webId)}/`).toString();
11
- }
12
- export async function findPodRowByStorageId(db, webId, table, id) {
13
- if (typeof db.findByIri === 'function') {
14
- return await db.findByIri(table, resolvePodUri(webId, table, id));
15
- }
16
- const rows = await db.select().from(table).execute();
17
- return rows.find((row) => row?.id === id) ?? null;
18
- }
19
- export function whereByPodStorageId(webId, table, query, id) {
20
- if (typeof query.whereByIri === 'function') {
21
- return query.whereByIri(resolvePodUri(webId, table, id));
22
- }
23
- return query.where({ id });
24
- }
25
- function resolvePodBaseUrl(webId) {
26
- try {
27
- const target = new URL(webId);
28
- const pathParts = target.pathname.split('/').filter(Boolean);
29
- const ownerSegment = pathParts[0] ?? '';
30
- return `${target.origin}/${ownerSegment}`.replace(/\/+$/, '');
31
- }
32
- catch {
33
- return webId.replace('/profile/card#me', '').replace(/\/$/, '');
34
- }
35
- }
36
- export function resolveRowId(row) {
37
- if (!row)
38
- return null;
39
- // Try @id first (standard RDF format)
40
- const subject = row['@id'] ?? row.subject;
41
- if (typeof subject === 'string' && subject.length > 0)
42
- return subject;
43
- // Try id field
44
- const id = row.id;
45
- if (typeof id === 'string' && id.length > 0)
46
- return id;
47
- // Handle drizzle-solid insert result format: {success: true, source: 'http://...'}
48
- const source = row.source;
49
- if (typeof source === 'string' && source.length > 0)
50
- return source;
51
- return null;
52
- }
53
- export function createRepositoryDescriptor(options) {
54
- const { namespace, table, searchableFields, defaultSort, cache, } = options;
55
- const searchAccessor = options.searchAccessor ?? ((filters) => {
56
- const value = filters ? filters.search : undefined;
57
- return typeof value === 'string' ? value : undefined;
58
- });
59
- const transformRow = options.transform ?? ((row) => row);
60
- const invalidations = {
61
- create: options.invalidations?.create ?? ['list'],
62
- update: options.invalidations?.update ?? ['list', 'detail'],
63
- remove: options.invalidations?.remove ?? ['list', 'detail'],
64
- };
65
- const resolveColumn = (field) => {
66
- const column = table[field];
67
- if (column)
68
- return column;
69
- const tableName = table.config?.name;
70
- return tableName ? `${tableName}.${field}` : field;
71
- };
72
- const buildWhereClause = (filters) => {
73
- const clauses = [];
74
- const term = searchAccessor(filters)?.trim();
75
- if (term && searchableFields?.length) {
76
- const pattern = `%${term}%`;
77
- const searchClauses = searchableFields
78
- .map((field) => like(resolveColumn(field), pattern));
79
- if (searchClauses.length === 1) {
80
- clauses.push(searchClauses[0]);
81
- }
82
- else if (searchClauses.length > 1) {
83
- clauses.push(or(...searchClauses));
84
- }
85
- }
86
- const customFilter = options.filter?.({ table, filters });
87
- if (customFilter) {
88
- clauses.push(customFilter);
89
- }
90
- if (clauses.length === 0)
91
- return undefined;
92
- return clauses.length === 1 ? clauses[0] : and(...clauses);
93
- };
94
- const list = async (db, filters) => {
95
- let query = db.select().from(table);
96
- const whereClause = buildWhereClause(filters);
97
- if (whereClause) {
98
- query = query.where(whereClause);
99
- }
100
- if (defaultSort) {
101
- query = query.orderBy(resolveColumn(defaultSort.field), defaultSort.direction);
102
- }
103
- const rows = await query.execute();
104
- return rows.map((row) => transformRow(row));
105
- };
106
- const detail = async (db, id) => {
107
- const record = typeof db.findByIri === 'function'
108
- ? await db.findByIri(table, id)
109
- : null;
110
- return record ? transformRow(record) : null;
111
- };
112
- const create = options.disableMutations?.create
113
- ? undefined
114
- : async (db, input) => {
115
- // Generate an ID if not provided
116
- const inputId = input.id;
117
- const generatedId = typeof inputId === 'string' && inputId.length > 0
118
- ? inputId
119
- : crypto.randomUUID();
120
- const inputWithId = { ...input, id: generatedId };
121
- const result = await db.insert(table).values(inputWithId).execute();
122
- // drizzle-solid returns [{success, source}] or the created row
123
- const firstResult = Array.isArray(result) ? result?.[0] : result;
124
- // If result is actual row data (not drizzle-solid success format), return it
125
- if (firstResult && typeof firstResult === 'object' && !('success' in firstResult)) {
126
- return transformRow(firstResult);
127
- }
128
- // Handle drizzle-solid format: {success: true, source: "http://..."}
129
- const sourceUrl = firstResult && typeof firstResult === 'object' && 'source' in firstResult
130
- ? firstResult.source
131
- : null;
132
- // Return synthetic row immediately for optimistic update
133
- // The real data will be fetched via invalidateQueries
134
- const baseUrl = sourceUrl ? sourceUrl.replace(/\/[^/]+\.ttl$/, '') : '';
135
- const syntheticId = sourceUrl
136
- ? `${baseUrl}/${generatedId}.ttl`
137
- : generatedId;
138
- return {
139
- ...inputWithId,
140
- id: generatedId,
141
- '@id': syntheticId,
142
- subject: syntheticId,
143
- source: sourceUrl,
144
- };
145
- };
146
- const update = options.disableMutations?.update
147
- ? undefined
148
- : async (db, id, input) => {
149
- const query = db
150
- .update(table)
151
- .set(input);
152
- const scopedQuery = typeof query.whereByIri === 'function'
153
- ? query.whereByIri(id)
154
- : query.where({ '@id': id });
155
- await scopedQuery.execute();
156
- const next = await detail(db, id);
157
- if (!next) {
158
- throw new Error(`Failed to load ${namespace} record after update`);
159
- }
160
- return next;
161
- };
162
- const remove = options.disableMutations?.remove
163
- ? undefined
164
- : async (db, id) => {
165
- const query = db.delete(table);
166
- const scopedQuery = typeof query.whereByIri === 'function'
167
- ? query.whereByIri(id)
168
- : query.where({ '@id': id });
169
- await scopedQuery.execute();
170
- return { id };
171
- };
172
- const resourcePath = typeof table.getResourcePath === 'function'
173
- ? table.getResourcePath()
174
- : (table.config?.base ?? '');
175
- return {
176
- namespace,
177
- resourcePath,
178
- searchableFields,
179
- defaultSort,
180
- cache,
181
- invalidations,
182
- list,
183
- detail,
184
- create,
185
- update,
186
- remove,
187
- };
188
- }
189
- export const definePodRepository = createRepositoryDescriptor;
1
+ export { createRepositoryDescriptor, definePodRepository, initSolidTables, } from '@undefineds.co/drizzle-solid';
@@ -1 +1 @@
1
- export { sessionResource, sessionTable, buildSessionSubjectPath, type SessionType, type SessionStatus, type SessionRow, type SessionInsert, type SessionUpdate, } from './session.schema';
1
+ export { sessionResource, sessionTable, buildRuntimeSessionIri, extractRuntimeSessionId, type SessionType, type SessionStatus, type SessionRow, type SessionInsert, type SessionUpdate, } from './session.schema';
@@ -1 +1 @@
1
- export { sessionResource, sessionTable, buildSessionSubjectPath, } from './session.schema.js';
1
+ export { sessionResource, sessionTable, buildRuntimeSessionIri, extractRuntimeSessionId, } from './session.schema.js';
@@ -1,6 +1,7 @@
1
1
  export type SessionType = 'direct' | 'group' | 'imported-readonly';
2
2
  export type SessionStatus = 'active' | 'paused' | 'completed' | 'error' | 'archived';
3
- export declare function buildSessionSubjectPath(sessionId: string, createdAt?: Date | string | number): string;
3
+ export declare function buildRuntimeSessionIri(sessionId: string): string;
4
+ export declare function extractRuntimeSessionId(sessionRef: string | null | undefined): string | null;
4
5
  /**
5
6
  * Runtime / collaboration session resource.
6
7
  *