@undefineds.co/models 0.1.0

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 (254) hide show
  1. package/README.md +578 -0
  2. package/dist/_drizzle-solid/columns.d.ts +37 -0
  3. package/dist/_drizzle-solid/columns.js +1 -0
  4. package/dist/_drizzle-solid/pod-table.d.ts +3 -0
  5. package/dist/_drizzle-solid/pod-table.js +1 -0
  6. package/dist/_drizzle-solid/types.d.ts +40 -0
  7. package/dist/_drizzle-solid/types.js +1 -0
  8. package/dist/agent.providers.d.ts +13 -0
  9. package/dist/agent.providers.js +69 -0
  10. package/dist/agent.repository.d.ts +85 -0
  11. package/dist/agent.repository.js +7 -0
  12. package/dist/agent.schema.d.ts +1 -0
  13. package/dist/agent.schema.js +1 -0
  14. package/dist/ai-config/index.d.ts +61 -0
  15. package/dist/ai-config/index.js +294 -0
  16. package/dist/ai-config.d.ts +1 -0
  17. package/dist/ai-config.js +1 -0
  18. package/dist/ai-model.schema.d.ts +1 -0
  19. package/dist/ai-model.schema.js +1 -0
  20. package/dist/ai-provider.schema.d.ts +1 -0
  21. package/dist/ai-provider.schema.js +1 -0
  22. package/dist/approval.schema.d.ts +1 -0
  23. package/dist/approval.schema.js +1 -0
  24. package/dist/audit.schema.d.ts +1 -0
  25. package/dist/audit.schema.js +1 -0
  26. package/dist/chat.repository.d.ts +61 -0
  27. package/dist/chat.repository.js +8 -0
  28. package/dist/chat.schema.d.ts +1 -0
  29. package/dist/chat.schema.js +1 -0
  30. package/dist/chat.utils.d.ts +3 -0
  31. package/dist/chat.utils.js +30 -0
  32. package/dist/contact.repository.d.ts +85 -0
  33. package/dist/contact.repository.js +8 -0
  34. package/dist/contact.schema.d.ts +1 -0
  35. package/dist/contact.schema.js +1 -0
  36. package/dist/core/agent-provider.schema.d.ts +1 -0
  37. package/dist/core/agent-provider.schema.js +1 -0
  38. package/dist/core/agent-status.schema.d.ts +12 -0
  39. package/dist/core/agent-status.schema.js +18 -0
  40. package/dist/core/agent.schema.d.ts +72 -0
  41. package/dist/core/agent.schema.js +38 -0
  42. package/dist/core/ai-config.schema.d.ts +11 -0
  43. package/dist/core/ai-config.schema.js +18 -0
  44. package/dist/core/ai-model.schema.d.ts +15 -0
  45. package/dist/core/ai-model.schema.js +21 -0
  46. package/dist/core/ai-provider.schema.d.ts +16 -0
  47. package/dist/core/ai-provider.schema.js +28 -0
  48. package/dist/core/approval.schema.d.ts +21 -0
  49. package/dist/core/approval.schema.js +33 -0
  50. package/dist/core/audit.schema.d.ts +17 -0
  51. package/dist/core/audit.schema.js +29 -0
  52. package/dist/core/chat.schema.d.ts +36 -0
  53. package/dist/core/chat.schema.js +45 -0
  54. package/dist/core/contact.schema.d.ts +47 -0
  55. package/dist/core/contact.schema.js +59 -0
  56. package/dist/core/credential.schema.d.ts +56 -0
  57. package/dist/core/credential.schema.js +40 -0
  58. package/dist/core/extension/extension.schema.d.ts +4 -0
  59. package/dist/core/extension/extension.schema.js +11 -0
  60. package/dist/core/extension/index.d.ts +1 -0
  61. package/dist/core/extension/index.js +1 -0
  62. package/dist/core/extension.d.ts +1 -0
  63. package/dist/core/extension.js +1 -0
  64. package/dist/core/favorite/favorite.schema.d.ts +24 -0
  65. package/dist/core/favorite/favorite.schema.js +34 -0
  66. package/dist/core/favorite/index.d.ts +1 -0
  67. package/dist/core/favorite/index.js +1 -0
  68. package/dist/core/file/file.schema.d.ts +39 -0
  69. package/dist/core/file/file.schema.js +51 -0
  70. package/dist/core/file/index.d.ts +1 -0
  71. package/dist/core/file/index.js +1 -0
  72. package/dist/core/file.d.ts +1 -0
  73. package/dist/core/file.js +1 -0
  74. package/dist/core/grant.schema.d.ts +16 -0
  75. package/dist/core/grant.schema.js +29 -0
  76. package/dist/core/import/import-job.schema.d.ts +5 -0
  77. package/dist/core/import/import-job.schema.js +5 -0
  78. package/dist/core/import/index.d.ts +1 -0
  79. package/dist/core/import/index.js +1 -0
  80. package/dist/core/import.d.ts +1 -0
  81. package/dist/core/import.js +1 -0
  82. package/dist/core/inbox-notification.schema.d.ts +9 -0
  83. package/dist/core/inbox-notification.schema.js +16 -0
  84. package/dist/core/index.d.ts +31 -0
  85. package/dist/core/index.js +32 -0
  86. package/dist/core/knowledge/index.d.ts +1 -0
  87. package/dist/core/knowledge/index.js +1 -0
  88. package/dist/core/knowledge/knowledge-folder.schema.d.ts +7 -0
  89. package/dist/core/knowledge/knowledge-folder.schema.js +6 -0
  90. package/dist/core/knowledge.d.ts +1 -0
  91. package/dist/core/knowledge.js +1 -0
  92. package/dist/core/message.schema.d.ts +33 -0
  93. package/dist/core/message.schema.js +49 -0
  94. package/dist/core/namespaces.d.ts +176 -0
  95. package/dist/core/namespaces.js +289 -0
  96. package/dist/core/profile.d.ts +16 -0
  97. package/dist/core/profile.js +19 -0
  98. package/dist/core/schema.d.ts +304 -0
  99. package/dist/core/schema.js +46 -0
  100. package/dist/core/session/index.d.ts +1 -0
  101. package/dist/core/session/index.js +1 -0
  102. package/dist/core/session/session.schema.d.ts +6 -0
  103. package/dist/core/session/session.schema.js +6 -0
  104. package/dist/core/session.d.ts +1 -0
  105. package/dist/core/session.js +1 -0
  106. package/dist/core/settings/index.d.ts +1 -0
  107. package/dist/core/settings/index.js +1 -0
  108. package/dist/core/settings/settings.schema.d.ts +49 -0
  109. package/dist/core/settings/settings.schema.js +63 -0
  110. package/dist/core/settings.d.ts +1 -0
  111. package/dist/core/settings.js +1 -0
  112. package/dist/core/thread.schema.d.ts +28 -0
  113. package/dist/core/thread.schema.js +36 -0
  114. package/dist/core/types/collaboration-blocks.d.ts +52 -0
  115. package/dist/core/types/collaboration-blocks.js +7 -0
  116. package/dist/core/types/message-block.d.ts +270 -0
  117. package/dist/core/types/message-block.js +125 -0
  118. package/dist/core/vector-store.schema.d.ts +25 -0
  119. package/dist/core/vector-store.schema.js +35 -0
  120. package/dist/core/vocab/_namespaces.d.ts +1 -0
  121. package/dist/core/vocab/_namespaces.js +3 -0
  122. package/dist/core/vocab/chat.vocab.d.ts +16 -0
  123. package/dist/core/vocab/chat.vocab.js +22 -0
  124. package/dist/core/vocab/contact.vocab.d.ts +21 -0
  125. package/dist/core/vocab/contact.vocab.js +22 -0
  126. package/dist/core/vocab/index.d.ts +6 -0
  127. package/dist/core/vocab/index.js +6 -0
  128. package/dist/core/vocab/message.vocab.d.ts +20 -0
  129. package/dist/core/vocab/message.vocab.js +24 -0
  130. package/dist/core/vocab/sidecar.vocab.d.ts +46 -0
  131. package/dist/core/vocab/sidecar.vocab.js +47 -0
  132. package/dist/core/vocab/thread.vocab.d.ts +11 -0
  133. package/dist/core/vocab/thread.vocab.js +14 -0
  134. package/dist/core/vocab/workspace.vocab.d.ts +12 -0
  135. package/dist/core/vocab/workspace.vocab.js +13 -0
  136. package/dist/core/vocab.d.ts +1 -0
  137. package/dist/core/vocab.js +1 -0
  138. package/dist/core/workspace.schema.d.ts +35 -0
  139. package/dist/core/workspace.schema.js +106 -0
  140. package/dist/core.d.ts +1 -0
  141. package/dist/core.js +1 -0
  142. package/dist/credential.schema.d.ts +1 -0
  143. package/dist/credential.schema.js +1 -0
  144. package/dist/discovery/index.d.ts +31 -0
  145. package/dist/discovery/index.js +147 -0
  146. package/dist/discovery/models.json +2623 -0
  147. package/dist/discovery/providers.json +156 -0
  148. package/dist/discovery/types.d.ts +103 -0
  149. package/dist/discovery/types.js +12 -0
  150. package/dist/discovery/vercel.d.ts +25 -0
  151. package/dist/discovery/vercel.js +95 -0
  152. package/dist/discovery.d.ts +1 -0
  153. package/dist/discovery.js +1 -0
  154. package/dist/extension/extension.schema.d.ts +1 -0
  155. package/dist/extension/extension.schema.js +1 -0
  156. package/dist/extension/index.d.ts +1 -0
  157. package/dist/extension/index.js +1 -0
  158. package/dist/extension.d.ts +1 -0
  159. package/dist/extension.js +1 -0
  160. package/dist/favorite/favorite.schema.d.ts +1 -0
  161. package/dist/favorite/favorite.schema.js +1 -0
  162. package/dist/favorite/index.d.ts +2 -0
  163. package/dist/favorite/index.js +7 -0
  164. package/dist/favorite/starred-sync.d.ts +66 -0
  165. package/dist/favorite/starred-sync.js +156 -0
  166. package/dist/favorite.d.ts +1 -0
  167. package/dist/favorite.js +1 -0
  168. package/dist/file/file.schema.d.ts +1 -0
  169. package/dist/file/file.schema.js +1 -0
  170. package/dist/file/index.d.ts +1 -0
  171. package/dist/file/index.js +1 -0
  172. package/dist/file.d.ts +1 -0
  173. package/dist/file.js +1 -0
  174. package/dist/fixtures/contracts-chat-contact.d.ts +13 -0
  175. package/dist/fixtures/contracts-chat-contact.js +76 -0
  176. package/dist/grant.schema.d.ts +1 -0
  177. package/dist/grant.schema.js +1 -0
  178. package/dist/import/import-job.schema.d.ts +5 -0
  179. package/dist/import/import-job.schema.js +5 -0
  180. package/dist/import/index.d.ts +1 -0
  181. package/dist/import/index.js +1 -0
  182. package/dist/import.d.ts +1 -0
  183. package/dist/import.js +1 -0
  184. package/dist/inbox-notification.schema.d.ts +1 -0
  185. package/dist/inbox-notification.schema.js +1 -0
  186. package/dist/index.d.ts +41 -0
  187. package/dist/index.js +83 -0
  188. package/dist/knowledge/index.d.ts +1 -0
  189. package/dist/knowledge/index.js +1 -0
  190. package/dist/knowledge/knowledge-folder.schema.d.ts +1 -0
  191. package/dist/knowledge/knowledge-folder.schema.js +1 -0
  192. package/dist/knowledge.d.ts +1 -0
  193. package/dist/knowledge.js +1 -0
  194. package/dist/message.repository.d.ts +81 -0
  195. package/dist/message.repository.js +8 -0
  196. package/dist/message.schema.d.ts +1 -0
  197. package/dist/message.schema.js +1 -0
  198. package/dist/namespaces.d.ts +1 -0
  199. package/dist/namespaces.js +1 -0
  200. package/dist/profile.d.ts +1 -0
  201. package/dist/profile.js +1 -0
  202. package/dist/repository.d.ts +59 -0
  203. package/dist/repository.js +186 -0
  204. package/dist/schema.d.ts +1 -0
  205. package/dist/schema.js +1 -0
  206. package/dist/session/index.d.ts +1 -0
  207. package/dist/session/index.js +1 -0
  208. package/dist/session/session.schema.d.ts +1 -0
  209. package/dist/session/session.schema.js +1 -0
  210. package/dist/session.d.ts +1 -0
  211. package/dist/session.js +1 -0
  212. package/dist/settings/index.d.ts +1 -0
  213. package/dist/settings/index.js +1 -0
  214. package/dist/settings/settings.schema.d.ts +1 -0
  215. package/dist/settings/settings.schema.js +1 -0
  216. package/dist/settings.d.ts +1 -0
  217. package/dist/settings.js +1 -0
  218. package/dist/sidecar/index.d.ts +2 -0
  219. package/dist/sidecar/index.js +2 -0
  220. package/dist/sidecar/persistence-mapping.d.ts +51 -0
  221. package/dist/sidecar/persistence-mapping.js +44 -0
  222. package/dist/sidecar/sidecar-events.d.ts +632 -0
  223. package/dist/sidecar/sidecar-events.js +133 -0
  224. package/dist/thread.repository.d.ts +41 -0
  225. package/dist/thread.repository.js +8 -0
  226. package/dist/thread.schema.d.ts +1 -0
  227. package/dist/thread.schema.js +1 -0
  228. package/dist/types/collaboration-blocks.d.ts +52 -0
  229. package/dist/types/collaboration-blocks.js +7 -0
  230. package/dist/types/message-block.d.ts +270 -0
  231. package/dist/types/message-block.js +125 -0
  232. package/dist/vocab/_namespaces.d.ts +1 -0
  233. package/dist/vocab/_namespaces.js +3 -0
  234. package/dist/vocab/chat.vocab.d.ts +16 -0
  235. package/dist/vocab/chat.vocab.js +22 -0
  236. package/dist/vocab/contact.vocab.d.ts +21 -0
  237. package/dist/vocab/contact.vocab.js +22 -0
  238. package/dist/vocab/index.d.ts +6 -0
  239. package/dist/vocab/index.js +6 -0
  240. package/dist/vocab/message.vocab.d.ts +20 -0
  241. package/dist/vocab/message.vocab.js +24 -0
  242. package/dist/vocab/sidecar.vocab.d.ts +46 -0
  243. package/dist/vocab/sidecar.vocab.js +47 -0
  244. package/dist/vocab/thread.vocab.d.ts +11 -0
  245. package/dist/vocab/thread.vocab.js +14 -0
  246. package/dist/vocab/workspace.vocab.d.ts +12 -0
  247. package/dist/vocab/workspace.vocab.js +13 -0
  248. package/dist/vocab.d.ts +1 -0
  249. package/dist/vocab.js +1 -0
  250. package/dist/workspace.repository.d.ts +45 -0
  251. package/dist/workspace.repository.js +8 -0
  252. package/dist/workspace.schema.d.ts +1 -0
  253. package/dist/workspace.schema.js +1 -0
  254. package/package.json +68 -0
@@ -0,0 +1,46 @@
1
+ export declare const ApprovalVocab: {
2
+ readonly session: string;
3
+ readonly toolCallId: string;
4
+ readonly toolName: string;
5
+ readonly target: string;
6
+ readonly action: string;
7
+ readonly risk: string;
8
+ readonly status: string;
9
+ readonly assignedTo: string;
10
+ readonly decisionBy: string;
11
+ readonly decisionRole: string;
12
+ readonly onBehalfOf: string;
13
+ readonly reason: string;
14
+ readonly policyVersion: string;
15
+ readonly createdAt: string;
16
+ readonly resolvedAt: string;
17
+ };
18
+ export declare const AuditVocab: {
19
+ readonly action: string;
20
+ readonly actor: string;
21
+ readonly actorRole: string;
22
+ readonly onBehalfOf: string;
23
+ readonly session: string;
24
+ readonly toolCallId: string;
25
+ readonly approval: string;
26
+ readonly context: string;
27
+ readonly policy: string;
28
+ readonly policyVersion: string;
29
+ readonly createdAt: string;
30
+ };
31
+ export declare const GrantVocab: {
32
+ readonly target: string;
33
+ readonly action: string;
34
+ readonly effect: string;
35
+ readonly riskCeiling: string;
36
+ readonly decisionBy: string;
37
+ readonly decisionRole: string;
38
+ readonly onBehalfOf: string;
39
+ readonly createdAt: string;
40
+ readonly revokedAt: string;
41
+ };
42
+ export declare const InboxNotificationVocab: {
43
+ readonly actor: string;
44
+ readonly object: string;
45
+ readonly createdAt: string;
46
+ };
@@ -0,0 +1,47 @@
1
+ import { AS, DCTerms, ODRL, UDFS } from '../namespaces.js';
2
+ export const ApprovalVocab = {
3
+ session: UDFS.session,
4
+ toolCallId: UDFS.toolCallId,
5
+ toolName: UDFS.toolName,
6
+ target: ODRL.target,
7
+ action: ODRL.action,
8
+ risk: UDFS.risk,
9
+ status: UDFS.status,
10
+ assignedTo: UDFS.assignedTo,
11
+ decisionBy: UDFS.decisionBy,
12
+ decisionRole: UDFS.decisionRole,
13
+ onBehalfOf: UDFS.onBehalfOf,
14
+ reason: UDFS.reason,
15
+ policyVersion: UDFS.policyVersion,
16
+ createdAt: DCTerms.created,
17
+ resolvedAt: UDFS.resolvedAt,
18
+ };
19
+ export const AuditVocab = {
20
+ action: UDFS.action,
21
+ actor: UDFS.actor,
22
+ actorRole: UDFS.actorRole,
23
+ onBehalfOf: UDFS.onBehalfOf,
24
+ session: UDFS.session,
25
+ toolCallId: UDFS.toolCallId,
26
+ approval: UDFS.approval,
27
+ context: UDFS.context,
28
+ policy: UDFS.policy,
29
+ policyVersion: UDFS.policyVersion,
30
+ createdAt: DCTerms.created,
31
+ };
32
+ export const GrantVocab = {
33
+ target: ODRL.target,
34
+ action: ODRL.action,
35
+ effect: UDFS.effect,
36
+ riskCeiling: UDFS.riskCeiling,
37
+ decisionBy: UDFS.decisionBy,
38
+ decisionRole: UDFS.decisionRole,
39
+ onBehalfOf: UDFS.onBehalfOf,
40
+ createdAt: DCTerms.created,
41
+ revokedAt: UDFS.revokedAt,
42
+ };
43
+ export const InboxNotificationVocab = {
44
+ actor: AS.actor,
45
+ object: AS.object,
46
+ createdAt: DCTerms.created,
47
+ };
@@ -0,0 +1,11 @@
1
+ export declare const ThreadVocab: {
2
+ readonly chatId: string;
3
+ readonly title: string;
4
+ readonly starred: string;
5
+ readonly status: string;
6
+ readonly metadata: string;
7
+ readonly createdAt: string;
8
+ readonly updatedAt: string;
9
+ readonly workspace: string;
10
+ readonly type: string;
11
+ };
@@ -0,0 +1,14 @@
1
+ import { DCTerms, LINX_CHAT, SIOC, UDFS } from '../namespaces.js';
2
+ export const ThreadVocab = {
3
+ chatId: SIOC.has_parent,
4
+ title: DCTerms.title,
5
+ starred: UDFS.favorite,
6
+ status: UDFS.status,
7
+ metadata: UDFS.metadata,
8
+ createdAt: DCTerms.created,
9
+ updatedAt: DCTerms.modified,
10
+ // Execution context: workspace container (Agent@workspace)
11
+ workspace: LINX_CHAT.workspace,
12
+ // Type marker (for SPARQL convenience)
13
+ type: SIOC.Thread,
14
+ };
@@ -0,0 +1,12 @@
1
+ export declare const WorkspaceVocab: {
2
+ readonly title: string;
3
+ readonly workspaceType: string;
4
+ readonly kind: string;
5
+ readonly rootUri: string;
6
+ readonly repoRootUri: string;
7
+ readonly baseRef: string;
8
+ readonly branch: string;
9
+ readonly createdAt: string;
10
+ readonly updatedAt: string;
11
+ readonly type: string;
12
+ };
@@ -0,0 +1,13 @@
1
+ import { DCTerms, UDFS } from '../namespaces.js';
2
+ export const WorkspaceVocab = {
3
+ title: DCTerms.title,
4
+ workspaceType: UDFS.workspaceType,
5
+ kind: UDFS.workspaceKind,
6
+ rootUri: UDFS.rootUri,
7
+ repoRootUri: UDFS.repoRootUri,
8
+ baseRef: UDFS.baseRef,
9
+ branch: UDFS.branch,
10
+ createdAt: DCTerms.created,
11
+ updatedAt: DCTerms.modified,
12
+ type: UDFS.Workspace,
13
+ };
@@ -0,0 +1 @@
1
+ export * from './vocab/index.js';
@@ -0,0 +1 @@
1
+ export * from './vocab/index.js';
@@ -0,0 +1,35 @@
1
+ export declare const WORKSPACE_TYPES: readonly ["pod", "local"];
2
+ export type WorkspaceType = typeof WORKSPACE_TYPES[number];
3
+ export declare const WORKSPACE_KINDS: readonly ["folder", "git", "worktree"];
4
+ export type WorkspaceKind = typeof WORKSPACE_KINDS[number];
5
+ /**
6
+ * Workspace schema.
7
+ *
8
+ * Only Pod-backed workspace metadata is persisted here.
9
+ * Local workspaces are addressed directly via `linx://{node-id}/path/to/root`.
10
+ */
11
+ export declare const workspaceTable: import("@undefineds.co/models/_drizzle-solid/pod-table").PodTableWithColumns<import("@undefineds.co/models/_drizzle-solid/types").ResolvedColumns<{
12
+ id: import("@undefineds.co/models/_drizzle-solid/columns").PodStringColumn<false, false>;
13
+ title: import("@undefineds.co/models/_drizzle-solid/columns").ColumnBuilder<"string", null, false, false>;
14
+ workspaceType: import("@undefineds.co/models/_drizzle-solid/columns").ColumnBuilder<"string", null, true, true>;
15
+ kind: import("@undefineds.co/models/_drizzle-solid/columns").ColumnBuilder<"string", null, true, true>;
16
+ rootUri: import("@undefineds.co/models/_drizzle-solid/columns").ColumnBuilder<"uri", null, false, false>;
17
+ repoRootUri: import("@undefineds.co/models/_drizzle-solid/columns").ColumnBuilder<"uri", null, false, false>;
18
+ baseRef: import("@undefineds.co/models/_drizzle-solid/columns").ColumnBuilder<"string", null, false, false>;
19
+ branch: import("@undefineds.co/models/_drizzle-solid/columns").ColumnBuilder<"string", null, false, false>;
20
+ createdAt: import("@undefineds.co/models/_drizzle-solid/columns").ColumnBuilder<"datetime", null, true, true>;
21
+ updatedAt: import("@undefineds.co/models/_drizzle-solid/columns").ColumnBuilder<"datetime", null, true, true>;
22
+ }>>;
23
+ export type WorkspaceRow = typeof workspaceTable.$inferSelect;
24
+ export type WorkspaceInsert = typeof workspaceTable.$inferInsert;
25
+ export type WorkspaceUpdate = typeof workspaceTable.$inferUpdate;
26
+ export declare function getWorkspaceContainerPath(workspaceId: string): string;
27
+ export declare function resolveWorkspaceContainerUri(podBaseUrl: string, workspaceId: string): string;
28
+ export declare function parseWorkspaceIdFromContainerUri(workspaceUri?: string | null): string | null;
29
+ export declare function normalizeLocalWorkspacePath(value?: string | null): string | undefined;
30
+ export declare function buildLocalWorkspaceUri(nodeId: string, rootPath: string): string;
31
+ export declare function isLocalWorkspaceUri(workspaceUri?: string | null): boolean;
32
+ export declare function parseLocalWorkspaceUri(workspaceUri?: string | null): {
33
+ nodeId: string;
34
+ path: string;
35
+ } | null;
@@ -0,0 +1,106 @@
1
+ import { id, podTable, string, timestamp, uri } from '@undefineds.co/drizzle-solid';
2
+ import { UDFS, DCTerms } from './namespaces.js';
3
+ export const WORKSPACE_TYPES = ['pod', 'local'];
4
+ export const WORKSPACE_KINDS = ['folder', 'git', 'worktree'];
5
+ const URI_WITH_SLASHES = /^[a-zA-Z][a-zA-Z\d+.-]*:\/\//;
6
+ const WINDOWS_PATH_PREFIX = /^[a-zA-Z]:[\\/]/;
7
+ /**
8
+ * Workspace schema.
9
+ *
10
+ * Only Pod-backed workspace metadata is persisted here.
11
+ * Local workspaces are addressed directly via `linx://{node-id}/path/to/root`.
12
+ */
13
+ export const workspaceTable = podTable('workspace', {
14
+ id: id('id'),
15
+ title: string('title').predicate(DCTerms.title),
16
+ workspaceType: string('workspaceType').predicate(UDFS.workspaceType).notNull().default('pod'),
17
+ kind: string('kind').predicate(UDFS.workspaceKind).notNull().default('folder'),
18
+ rootUri: uri('rootUri').predicate(UDFS.rootUri),
19
+ repoRootUri: uri('repoRootUri').predicate(UDFS.repoRootUri),
20
+ baseRef: string('baseRef').predicate(UDFS.baseRef),
21
+ branch: string('branch').predicate(UDFS.branch),
22
+ createdAt: timestamp('createdAt').predicate(DCTerms.created).notNull().defaultNow(),
23
+ updatedAt: timestamp('updatedAt').predicate(DCTerms.modified).notNull().defaultNow(),
24
+ }, {
25
+ base: '/.data/workspaces/',
26
+ sparqlEndpoint: '/.data/workspaces/-/sparql',
27
+ type: UDFS.Workspace,
28
+ namespace: UDFS,
29
+ subjectTemplate: '{id}/index.ttl#this',
30
+ });
31
+ export function getWorkspaceContainerPath(workspaceId) {
32
+ return `/.data/workspaces/${workspaceId}/`;
33
+ }
34
+ export function resolveWorkspaceContainerUri(podBaseUrl, workspaceId) {
35
+ return `${podBaseUrl.replace(/\/$/, '')}${getWorkspaceContainerPath(workspaceId)}`;
36
+ }
37
+ export function parseWorkspaceIdFromContainerUri(workspaceUri) {
38
+ if (!workspaceUri)
39
+ return null;
40
+ const match = workspaceUri.match(/\/\.data\/workspaces\/([^/]+)\/?$/);
41
+ return match?.[1] ?? null;
42
+ }
43
+ export function normalizeLocalWorkspacePath(value) {
44
+ const trimmed = value?.trim();
45
+ if (!trimmed)
46
+ return undefined;
47
+ if (trimmed.startsWith('file://')) {
48
+ try {
49
+ const url = new URL(trimmed);
50
+ const normalized = decodeURIComponent(url.pathname || '').replace(/\/{2,}/g, '/');
51
+ return normalized.length > 1 ? normalized.replace(/\/$/, '') : normalized;
52
+ }
53
+ catch {
54
+ return trimmed;
55
+ }
56
+ }
57
+ if (trimmed.startsWith('linx://')) {
58
+ return parseLocalWorkspaceUri(trimmed)?.path;
59
+ }
60
+ if (URI_WITH_SLASHES.test(trimmed)) {
61
+ return trimmed;
62
+ }
63
+ if (WINDOWS_PATH_PREFIX.test(trimmed)) {
64
+ return `/${trimmed.replace(/\\/g, '/')}`.replace(/\/{2,}/g, '/');
65
+ }
66
+ const normalized = trimmed.replace(/\\/g, '/').replace(/\/{2,}/g, '/');
67
+ if (normalized.startsWith('/')) {
68
+ return normalized.length > 1 ? normalized.replace(/\/$/, '') : normalized;
69
+ }
70
+ return `/${normalized.replace(/^\/+/, '')}`.replace(/\/$/, '');
71
+ }
72
+ export function buildLocalWorkspaceUri(nodeId, rootPath) {
73
+ const normalizedNodeId = nodeId.trim();
74
+ const normalizedPath = normalizeLocalWorkspacePath(rootPath);
75
+ if (!normalizedNodeId) {
76
+ throw new Error('nodeId is required for local workspace URIs.');
77
+ }
78
+ if (!normalizedPath) {
79
+ throw new Error('rootPath is required for local workspace URIs.');
80
+ }
81
+ const encodedPath = normalizedPath
82
+ .split('/')
83
+ .filter(Boolean)
84
+ .map((segment) => encodeURIComponent(segment))
85
+ .join('/');
86
+ return `linx://${encodeURIComponent(normalizedNodeId)}/${encodedPath}`;
87
+ }
88
+ export function isLocalWorkspaceUri(workspaceUri) {
89
+ return typeof workspaceUri === 'string' && workspaceUri.startsWith('linx://');
90
+ }
91
+ export function parseLocalWorkspaceUri(workspaceUri) {
92
+ if (!workspaceUri || !isLocalWorkspaceUri(workspaceUri))
93
+ return null;
94
+ try {
95
+ const url = new URL(workspaceUri);
96
+ const nodeId = decodeURIComponent(url.host);
97
+ const path = decodeURIComponent(url.pathname || '').replace(/\/{2,}/g, '/');
98
+ return {
99
+ nodeId,
100
+ path: path.length > 1 ? path.replace(/\/$/, '') : path,
101
+ };
102
+ }
103
+ catch {
104
+ return null;
105
+ }
106
+ }
package/dist/core.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './core/index.js';
package/dist/core.js ADDED
@@ -0,0 +1 @@
1
+ export * from './core/index.js';
@@ -0,0 +1 @@
1
+ export { credentialTable, apiKeyCredentialTable, oauthCredentialTable, type CredentialRow, type CredentialInsert, type CredentialUpdate, type ApiKeyCredentialRow, type ApiKeyCredentialInsert, type ApiKeyCredentialUpdate, type OAuthCredentialRow, type OAuthCredentialInsert, type OAuthCredentialUpdate, } from './core.js';
@@ -0,0 +1 @@
1
+ export { credentialTable, apiKeyCredentialTable, oauthCredentialTable, } from './core.js';
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Discovery Service
3
+ *
4
+ * 提供 AI 供应商、模型等元数据的发现服务
5
+ * 支持内置数据 + 远程 API 获取(有 Key 时)
6
+ */
7
+ export * from './types.js';
8
+ import type { ProviderMetadata, ModelMetadata, DiscoveryService } from './types.js';
9
+ declare class BuiltinDiscoveryService implements DiscoveryService {
10
+ getProviders(): Promise<ProviderMetadata[]>;
11
+ getProvider(slug: string): Promise<ProviderMetadata | undefined>;
12
+ getModels(provider?: string): Promise<ModelMetadata[]>;
13
+ getModel(provider: string, modelId: string): Promise<ModelMetadata | undefined>;
14
+ getDefaultModel(provider: string): Promise<ModelMetadata | undefined>;
15
+ }
16
+ export interface SmartDiscoveryOptions {
17
+ getApiKey?: (provider: string) => Promise<string | null>;
18
+ fetchModelsFromApi?: (provider: string, apiKey: string, baseUrl: string) => Promise<ModelMetadata[]>;
19
+ }
20
+ export declare const builtinDiscovery: BuiltinDiscoveryService;
21
+ export declare function createDiscoveryService(options?: SmartDiscoveryOptions): DiscoveryService;
22
+ export declare const getBuiltinProviders: () => ProviderMetadata[];
23
+ export declare const getBuiltinModels: (provider?: string) => ModelMetadata[];
24
+ export declare const getBuiltinProvider: (slug: string) => ProviderMetadata | undefined;
25
+ export declare const getBuiltinModel: (provider: string, modelId: string) => ModelMetadata | undefined;
26
+ export declare const getBuiltinDefaultModel: (provider: string) => ModelMetadata;
27
+ export declare const DISCOVERY_VERSION: {
28
+ providers: string;
29
+ models: string;
30
+ updatedAt: string;
31
+ };
@@ -0,0 +1,147 @@
1
+ /**
2
+ * Discovery Service
3
+ *
4
+ * 提供 AI 供应商、模型等元数据的发现服务
5
+ * 支持内置数据 + 远程 API 获取(有 Key 时)
6
+ */
7
+ export * from './types.js';
8
+ import { extractAIConfigProviderId } from '../ai-config.js';
9
+ // 导入内置数据
10
+ import providersData from './providers.json' with { type: 'json' };
11
+ import modelsData from './models.json' with { type: 'json' };
12
+ // ============================================================================
13
+ // Builtin Data (内置数据)
14
+ // ============================================================================
15
+ const builtinProviders = providersData.providers;
16
+ const builtinModels = modelsData.models;
17
+ function normalizeProviderSlug(slug) {
18
+ return extractAIConfigProviderId(slug);
19
+ }
20
+ function findBuiltinProvider(slug) {
21
+ const normalizedSlug = normalizeProviderSlug(slug);
22
+ if (!normalizedSlug)
23
+ return undefined;
24
+ return builtinProviders.find((provider) => normalizeProviderSlug(provider.slug) === normalizedSlug);
25
+ }
26
+ function filterBuiltinModels(provider) {
27
+ if (!provider) {
28
+ return builtinModels;
29
+ }
30
+ const normalizedProvider = normalizeProviderSlug(provider);
31
+ if (!normalizedProvider) {
32
+ return [];
33
+ }
34
+ return builtinModels.filter((model) => normalizeProviderSlug(model.provider) === normalizedProvider);
35
+ }
36
+ // ============================================================================
37
+ // Discovery Service Implementation
38
+ // ============================================================================
39
+ class BuiltinDiscoveryService {
40
+ // -------------------------------------------------------------------------
41
+ // Providers
42
+ // -------------------------------------------------------------------------
43
+ async getProviders() {
44
+ return builtinProviders;
45
+ }
46
+ async getProvider(slug) {
47
+ return findBuiltinProvider(slug);
48
+ }
49
+ // -------------------------------------------------------------------------
50
+ // Models
51
+ // -------------------------------------------------------------------------
52
+ async getModels(provider) {
53
+ return filterBuiltinModels(provider);
54
+ }
55
+ async getModel(provider, modelId) {
56
+ return filterBuiltinModels(provider).find((model) => model.id === modelId);
57
+ }
58
+ async getDefaultModel(provider) {
59
+ const providerModels = filterBuiltinModels(provider);
60
+ return providerModels.find(m => m.isDefault) || providerModels[0];
61
+ }
62
+ }
63
+ class SmartDiscoveryService {
64
+ constructor(options = {}) {
65
+ this.builtin = new BuiltinDiscoveryService();
66
+ this.modelCache = new Map();
67
+ this.cacheTTL = 5 * 60 * 1000; // 5 minutes
68
+ this.options = options;
69
+ }
70
+ async getProviders() {
71
+ return this.builtin.getProviders();
72
+ }
73
+ async getProvider(slug) {
74
+ return this.builtin.getProvider(slug);
75
+ }
76
+ async getModels(provider) {
77
+ if (!provider) {
78
+ return this.builtin.getModels();
79
+ }
80
+ // 检查缓存
81
+ const cached = this.modelCache.get(provider);
82
+ if (cached && Date.now() - cached.timestamp < this.cacheTTL) {
83
+ return cached.models;
84
+ }
85
+ // 尝试从 API 获取(如果有 Key)
86
+ if (this.options.getApiKey && this.options.fetchModelsFromApi) {
87
+ try {
88
+ const apiKey = await this.options.getApiKey(provider);
89
+ if (apiKey) {
90
+ const providerMeta = await this.builtin.getProvider(provider);
91
+ if (providerMeta) {
92
+ const models = await this.options.fetchModelsFromApi(provider, apiKey, providerMeta.baseUrl);
93
+ if (models.length > 0) {
94
+ this.modelCache.set(provider, { models, timestamp: Date.now() });
95
+ return models;
96
+ }
97
+ }
98
+ }
99
+ }
100
+ catch (error) {
101
+ console.warn(`Failed to fetch models from API for ${provider}, falling back to builtin`, error);
102
+ }
103
+ }
104
+ // Fallback 到内置列表
105
+ return this.builtin.getModels(provider);
106
+ }
107
+ async getModel(provider, modelId) {
108
+ const models = await this.getModels(provider);
109
+ return models.find(m => m.id === modelId);
110
+ }
111
+ async getDefaultModel(provider) {
112
+ const models = await this.getModels(provider);
113
+ return models.find(m => m.isDefault) || models[0];
114
+ }
115
+ clearCache(provider) {
116
+ if (provider) {
117
+ this.modelCache.delete(provider);
118
+ }
119
+ else {
120
+ this.modelCache.clear();
121
+ }
122
+ }
123
+ }
124
+ // ============================================================================
125
+ // Exports
126
+ // ============================================================================
127
+ // 单例实例
128
+ export const builtinDiscovery = new BuiltinDiscoveryService();
129
+ // 创建 Smart Discovery 实例的工厂函数
130
+ export function createDiscoveryService(options) {
131
+ return new SmartDiscoveryService(options);
132
+ }
133
+ // 便捷方法:直接获取内置数据
134
+ export const getBuiltinProviders = () => builtinProviders;
135
+ export const getBuiltinModels = (provider) => filterBuiltinModels(provider);
136
+ export const getBuiltinProvider = (slug) => findBuiltinProvider(slug);
137
+ export const getBuiltinModel = (provider, modelId) => filterBuiltinModels(provider).find(m => m.id === modelId);
138
+ export const getBuiltinDefaultModel = (provider) => {
139
+ const providerModels = filterBuiltinModels(provider);
140
+ return providerModels.find(m => m.isDefault) || providerModels[0];
141
+ };
142
+ // 导出内置数据版本信息
143
+ export const DISCOVERY_VERSION = {
144
+ providers: providersData.version,
145
+ models: modelsData.version,
146
+ updatedAt: providersData.updatedAt,
147
+ };