@lucern/sdk 0.2.0-alpha.6 → 0.2.0-alpha.7

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 (206) hide show
  1. package/.turbo/turbo-build.log +7 -0
  2. package/.turbo/turbo-typecheck.log +4 -0
  3. package/CHANGELOG.md +13 -0
  4. package/examples/README.md +69 -0
  5. package/examples/contradiction.ts +94 -0
  6. package/examples/investigation-context.ts +118 -0
  7. package/examples/questions-and-tasks.ts +55 -0
  8. package/examples/quickstart.ts +97 -0
  9. package/examples/shared.ts +318 -0
  10. package/examples/strict-public-types.ts +143 -0
  11. package/examples/worktree-lifecycle.ts +79 -0
  12. package/package.json +16 -58
  13. package/src/README.md +6 -0
  14. package/src/adminClient.ts +789 -0
  15. package/{dist/lib/platform/sdk/answersClient.d.ts → src/answersClient.ts} +17 -4
  16. package/src/audiencesClient.ts +209 -0
  17. package/src/auditClient.ts +50 -0
  18. package/src/beliefsClient.ts +319 -0
  19. package/src/client.ts +2647 -0
  20. package/src/contextClient.ts +130 -0
  21. package/{dist/lib/platform/sdk/contextFacade.d.ts → src/contextFacade.ts} +6 -1
  22. package/src/contextPackCompiler.ts +828 -0
  23. package/src/contextPackSchema.ts +251 -0
  24. package/src/contextTypes.ts +153 -0
  25. package/src/contracts/api-enums.contract.ts +202 -0
  26. package/src/contracts/auth-session.contract.ts +109 -0
  27. package/src/contracts/context-pack.contract.ts +700 -0
  28. package/src/contracts/contextPack.ts +1 -0
  29. package/src/contracts/index.ts +10 -0
  30. package/src/contracts/lens-filter.contract.ts +183 -0
  31. package/src/contracts/lens-workflow.contract.ts +162 -0
  32. package/src/contracts/lensFilter.ts +1 -0
  33. package/src/contracts/lensWorkflow.ts +1 -0
  34. package/src/contracts/mcp-tools.contract.ts +3636 -0
  35. package/src/contracts/mcpTools.ts +1 -0
  36. package/src/contracts/prompt.contract.ts +50 -0
  37. package/src/contracts/prompt.ts +1 -0
  38. package/src/contracts/sdk-tools.contract.ts +1457 -0
  39. package/src/contracts/sdkTools.ts +1 -0
  40. package/src/contracts/workflow-runtime.contract.ts +440 -0
  41. package/src/contracts/workflowRuntime.ts +1 -0
  42. package/src/controlObjectOwnership.ts +286 -0
  43. package/src/coreClient.ts +570 -0
  44. package/src/customTools.ts +398 -0
  45. package/src/decisionsClient.ts +286 -0
  46. package/src/domainContext.ts +15 -0
  47. package/src/events.ts +531 -0
  48. package/src/eventsCore.ts +168 -0
  49. package/src/facade/beliefs.ts +83 -0
  50. package/src/facade/context.ts +110 -0
  51. package/src/facade/contradictions.ts +29 -0
  52. package/src/facade/edges.ts +30 -0
  53. package/src/facade/events.ts +23 -0
  54. package/src/facade/evidence.ts +41 -0
  55. package/src/facade/graph.ts +38 -0
  56. package/src/facade/identity.ts +16 -0
  57. package/src/facade/ontologies.ts +34 -0
  58. package/src/facade/questions.ts +59 -0
  59. package/src/facade/search.ts +16 -0
  60. package/src/facade/tasks.ts +37 -0
  61. package/src/facade/topics.ts +42 -0
  62. package/src/facade/webhooks.ts +58 -0
  63. package/src/facade/worktrees.ts +51 -0
  64. package/src/gatewayFacades.ts +1666 -0
  65. package/src/graphClient.ts +529 -0
  66. package/src/harnessClient.ts +585 -0
  67. package/src/identityClient.ts +278 -0
  68. package/src/learningClient.ts +95 -0
  69. package/src/mcpParityClient.ts +240 -0
  70. package/src/mcpParitySurface.ts +70 -0
  71. package/src/ontologyClient.ts +275 -0
  72. package/src/packRuntime.ts +3 -0
  73. package/src/packsClient.ts +260 -0
  74. package/src/policyClient.ts +572 -0
  75. package/src/realtime/index.ts +51 -0
  76. package/src/realtime/refs.ts +17 -0
  77. package/src/reportsClient.ts +99 -0
  78. package/src/schemaClient.ts +129 -0
  79. package/src/sdkSurface.ts +190 -0
  80. package/src/topicsClient.ts +243 -0
  81. package/src/types.ts +807 -0
  82. package/src/workflowClient.ts +826 -0
  83. package/tsconfig.json +9 -0
  84. package/dist/.generated +0 -2
  85. package/dist/index.d.ts +0 -3
  86. package/dist/index.js +0 -3
  87. package/dist/lib/platform/auth/credentials.d.ts +0 -5
  88. package/dist/lib/platform/auth/credentials.js +0 -40
  89. package/dist/lib/platform/sdk/adminClient.d.ts +0 -404
  90. package/dist/lib/platform/sdk/adminClient.js +0 -384
  91. package/dist/lib/platform/sdk/answersClient.js +0 -21
  92. package/dist/lib/platform/sdk/audiencesClient.d.ts +0 -93
  93. package/dist/lib/platform/sdk/audiencesClient.js +0 -111
  94. package/dist/lib/platform/sdk/auditClient.d.ts +0 -24
  95. package/dist/lib/platform/sdk/auditClient.js +0 -21
  96. package/dist/lib/platform/sdk/beliefsClient.d.ts +0 -157
  97. package/dist/lib/platform/sdk/beliefsClient.js +0 -124
  98. package/dist/lib/platform/sdk/client.d.ts +0 -2369
  99. package/dist/lib/platform/sdk/client.js +0 -1831
  100. package/dist/lib/platform/sdk/contextClient.d.ts +0 -21
  101. package/dist/lib/platform/sdk/contextClient.js +0 -86
  102. package/dist/lib/platform/sdk/contextFacade.js +0 -10
  103. package/dist/lib/platform/sdk/contextPackCompiler.d.ts +0 -100
  104. package/dist/lib/platform/sdk/contextPackCompiler.js +0 -534
  105. package/dist/lib/platform/sdk/contextTypes.d.ts +0 -133
  106. package/dist/lib/platform/sdk/contextTypes.js +0 -1
  107. package/dist/lib/platform/sdk/controlObjectOwnership.d.ts +0 -308
  108. package/dist/lib/platform/sdk/controlObjectOwnership.js +0 -220
  109. package/dist/lib/platform/sdk/coreClient.d.ts +0 -139
  110. package/dist/lib/platform/sdk/coreClient.js +0 -366
  111. package/dist/lib/platform/sdk/customTools.d.ts +0 -83
  112. package/dist/lib/platform/sdk/customTools.js +0 -247
  113. package/dist/lib/platform/sdk/decisionsClient.d.ts +0 -106
  114. package/dist/lib/platform/sdk/decisionsClient.js +0 -129
  115. package/dist/lib/platform/sdk/domainContext.d.ts +0 -1
  116. package/dist/lib/platform/sdk/domainContext.js +0 -1
  117. package/dist/lib/platform/sdk/events.d.ts +0 -176
  118. package/dist/lib/platform/sdk/events.js +0 -261
  119. package/dist/lib/platform/sdk/eventsCore.d.ts +0 -13
  120. package/dist/lib/platform/sdk/eventsCore.js +0 -13
  121. package/dist/lib/platform/sdk/gatewayFacades.d.ts +0 -586
  122. package/dist/lib/platform/sdk/gatewayFacades.js +0 -845
  123. package/dist/lib/platform/sdk/graphClient.d.ts +0 -266
  124. package/dist/lib/platform/sdk/graphClient.js +0 -235
  125. package/dist/lib/platform/sdk/harnessClient.d.ts +0 -309
  126. package/dist/lib/platform/sdk/harnessClient.js +0 -219
  127. package/dist/lib/platform/sdk/identityClient.d.ts +0 -134
  128. package/dist/lib/platform/sdk/identityClient.js +0 -131
  129. package/dist/lib/platform/sdk/index.js +0 -49
  130. package/dist/lib/platform/sdk/learningClient.d.ts +0 -40
  131. package/dist/lib/platform/sdk/learningClient.js +0 -53
  132. package/dist/lib/platform/sdk/mcpParityClient.d.ts +0 -69
  133. package/dist/lib/platform/sdk/mcpParityClient.js +0 -196
  134. package/dist/lib/platform/sdk/mcpParitySurface.d.ts +0 -10
  135. package/dist/lib/platform/sdk/mcpParitySurface.js +0 -57
  136. package/dist/lib/platform/sdk/ontologyClient.d.ts +0 -131
  137. package/dist/lib/platform/sdk/ontologyClient.js +0 -161
  138. package/dist/lib/platform/sdk/packRuntime.d.ts +0 -1
  139. package/dist/lib/platform/sdk/packRuntime.js +0 -1
  140. package/dist/lib/platform/sdk/packsClient.d.ts +0 -126
  141. package/dist/lib/platform/sdk/packsClient.js +0 -157
  142. package/dist/lib/platform/sdk/policyClient.d.ts +0 -293
  143. package/dist/lib/platform/sdk/policyClient.js +0 -277
  144. package/dist/lib/platform/sdk/promptCatalog.js +0 -1
  145. package/dist/lib/platform/sdk/reportsClient.d.ts +0 -34
  146. package/dist/lib/platform/sdk/reportsClient.js +0 -64
  147. package/dist/lib/platform/sdk/schemaClient.d.ts +0 -59
  148. package/dist/lib/platform/sdk/schemaClient.js +0 -71
  149. package/dist/lib/platform/sdk/sdkSurface.d.ts +0 -56
  150. package/dist/lib/platform/sdk/sdkSurface.js +0 -140
  151. package/dist/lib/platform/sdk/topicsClient.d.ts +0 -78
  152. package/dist/lib/platform/sdk/topicsClient.js +0 -118
  153. package/dist/lib/platform/sdk/types.d.ts +0 -692
  154. package/dist/lib/platform/sdk/types.js +0 -1
  155. package/dist/lib/platform/sdk/version.d.ts +0 -2
  156. package/dist/lib/platform/sdk/workflowClient.d.ts +0 -313
  157. package/dist/lib/platform/sdk/workflowClient.js +0 -366
  158. package/dist/lucern/contracts/src/api-enums.contract.d.ts +0 -58
  159. package/dist/lucern/contracts/src/api-enums.contract.js +0 -147
  160. package/dist/lucern/contracts/src/auth-context.contract.d.ts +0 -8
  161. package/dist/lucern/contracts/src/auth-context.contract.js +0 -8
  162. package/dist/lucern/contracts/src/auth-session.contract.d.ts +0 -8
  163. package/dist/lucern/contracts/src/auth-session.contract.js +0 -8
  164. package/dist/lucern/contracts/src/auth.contract.d.ts +0 -88
  165. package/dist/lucern/contracts/src/auth.contract.js +0 -57
  166. package/dist/lucern/contracts/src/context-pack.contract.d.ts +0 -494
  167. package/dist/lucern/contracts/src/context-pack.contract.js +0 -169
  168. package/dist/lucern/contracts/src/convex-admin.contract.d.ts +0 -5
  169. package/dist/lucern/contracts/src/convex-admin.contract.js +0 -1
  170. package/dist/lucern/contracts/src/events-types.contract.d.ts +0 -8
  171. package/dist/lucern/contracts/src/events-types.contract.js +0 -8
  172. package/dist/lucern/contracts/src/events.contract.d.ts +0 -176
  173. package/dist/lucern/contracts/src/events.contract.js +0 -159
  174. package/dist/lucern/contracts/src/gateway.contract.d.ts +0 -74
  175. package/dist/lucern/contracts/src/gateway.contract.js +0 -19
  176. package/dist/lucern/contracts/src/ids.contract.d.ts +0 -7
  177. package/dist/lucern/contracts/src/ids.contract.js +0 -24
  178. package/dist/lucern/contracts/src/index.d.ts +0 -29
  179. package/dist/lucern/contracts/src/index.js +0 -29
  180. package/dist/lucern/contracts/src/lens-filter.contract.d.ts +0 -70
  181. package/dist/lucern/contracts/src/lens-filter.contract.js +0 -95
  182. package/dist/lucern/contracts/src/lens-workflow.contract.d.ts +0 -84
  183. package/dist/lucern/contracts/src/lens-workflow.contract.js +0 -54
  184. package/dist/lucern/contracts/src/mcp-tools.contract.d.ts +0 -151
  185. package/dist/lucern/contracts/src/mcp-tools.contract.js +0 -3281
  186. package/dist/lucern/contracts/src/ontology-matching.contract.d.ts +0 -8
  187. package/dist/lucern/contracts/src/ontology-matching.contract.js +0 -8
  188. package/dist/lucern/contracts/src/prompt.contract.d.ts +0 -24
  189. package/dist/lucern/contracts/src/prompt.contract.js +0 -24
  190. package/dist/lucern/contracts/src/sdk-methods.contract.d.ts +0 -358
  191. package/dist/lucern/contracts/src/sdk-methods.contract.js +0 -19
  192. package/dist/lucern/contracts/src/sdk-tools.contract.d.ts +0 -92
  193. package/dist/lucern/contracts/src/sdk-tools.contract.js +0 -1398
  194. package/dist/lucern/contracts/src/text-matching.contract.d.ts +0 -53
  195. package/dist/lucern/contracts/src/text-matching.contract.js +0 -277
  196. package/dist/lucern/contracts/src/topic-scope.contract.d.ts +0 -8
  197. package/dist/lucern/contracts/src/topic-scope.contract.js +0 -8
  198. package/dist/lucern/contracts/src/workflow-runtime.contract.d.ts +0 -161
  199. package/dist/lucern/contracts/src/workflow-runtime.contract.js +0 -257
  200. package/dist/realtime-refs.d.ts +0 -1
  201. package/dist/realtime-refs.js +0 -1
  202. package/dist/realtime.d.ts +0 -1
  203. package/dist/realtime.js +0 -1
  204. /package/{dist/lib/platform/sdk/index.d.ts → src/index.ts} +0 -0
  205. /package/{dist/lib/platform/sdk/promptCatalog.d.ts → src/promptCatalog.ts} +0 -0
  206. /package/{dist/lib/platform/sdk/version.js → src/version.ts} +0 -0
@@ -1,176 +0,0 @@
1
- /**
2
- * @lucern/contracts — events (canonical support contract)
3
- *
4
- * Consolidated flat support surface for Lucern's domain event stream:
5
- * - Event type definitions, constants, and shared enums
6
- * - Event construction + cursor helpers
7
- *
8
- * Consolidated from the former split type-definition module
9
- * and the prior src/events.contract.ts (helpers) in EK-16 T1 PR 3b.
10
- * Compat shim remains at the old events-types path until Lucern 1.0.0 (D12).
11
- */
12
- export declare const DOMAIN_EVENT_VERSION: "1.0";
13
- export declare const EVENT_RETENTION_DEFAULT_DAYS = 30;
14
- export declare const WEBHOOK_MAX_ATTEMPTS = 5;
15
- export declare const WEBHOOK_RETRY_DELAYS_MS: readonly [1000, 5000, 30000, 300000];
16
- export declare const DOMAIN_EVENT_TYPES: readonly ["belief.created", "belief.forked", "belief.confidence_updated", "belief.archived", "belief.refined", "belief.contract_created", "belief.contract_evaluated", "belief.lineage_queried", "evidence.created", "evidence.linked", "evidence.search_executed", "question.created", "question.answered", "question.refined", "question.status_updated", "question.archived", "edge.created", "contradiction.flagged", "worktree.created", "worktree.activated", "worktree.merged", "worktree.targets_updated", "worktree.metadata_updated", "topic.created", "topic.updated", "topic.archived", "task.created", "task.completed", "task.updated", "ontology.bound", "context.compiled", "identity.key_created", "identity.key_rotated", "identity.key_revoked", "webhook.test"];
17
- export type DomainEventType = (typeof DOMAIN_EVENT_TYPES)[number];
18
- export type DomainResourceType = "belief" | "evidence" | "question" | "edge" | "contradiction" | "worktree" | "topic" | "task" | "ontology" | "context" | "identity" | "webhook";
19
- export type DomainActorType = "human" | "agent" | "service";
20
- export type DomainEventData = Record<string, unknown>;
21
- export type DomainEvent = {
22
- eventId: string;
23
- type: DomainEventType | string;
24
- version: typeof DOMAIN_EVENT_VERSION;
25
- timestamp: number;
26
- tenantId?: string;
27
- workspaceId?: string;
28
- topicId: string;
29
- resourceId: string;
30
- resourceType: DomainResourceType | string;
31
- actorId: string;
32
- actorType: DomainActorType;
33
- data: DomainEventData;
34
- correlationId?: string;
35
- expiresAt: number;
36
- };
37
- export type CreateDomainEventInput = {
38
- eventId?: string;
39
- timestamp?: number;
40
- tenantId?: string;
41
- workspaceId?: string;
42
- topicId: string;
43
- type: DomainEventType | string;
44
- resourceId: string;
45
- resourceType: DomainResourceType | string;
46
- actorId: string;
47
- actorType: DomainActorType;
48
- data?: DomainEventData;
49
- correlationId?: string;
50
- retentionDays?: number;
51
- };
52
- export type EventCursor = {
53
- timestamp: number;
54
- eventId: string;
55
- };
56
- export type EventListQuery = {
57
- topicId?: string;
58
- after?: string;
59
- types?: string[];
60
- startTime?: number;
61
- endTime?: number;
62
- limit?: number;
63
- };
64
- export type EventListResult = {
65
- events: DomainEvent[];
66
- nextCursor: string | null;
67
- };
68
- export type WebhookSecretMode = "configured";
69
- export type WebhookRecord = {
70
- id: string;
71
- webhookId: string;
72
- tenantId?: string;
73
- workspaceId?: string;
74
- topicId?: string;
75
- url: string;
76
- events: string[];
77
- active: boolean;
78
- secretConfigured: boolean;
79
- createdAt: number;
80
- updatedAt: number;
81
- createdBy: string;
82
- updatedBy: string;
83
- lastDeliveryAt?: number;
84
- lastSuccessfulDeliveryAt?: number;
85
- };
86
- export type WebhookCreateInput = {
87
- url: string;
88
- events: string[];
89
- secret: string;
90
- topicId?: string;
91
- active?: boolean;
92
- };
93
- export type WebhookUpdateInput = {
94
- url?: string;
95
- events?: string[];
96
- secret?: string;
97
- topicId?: string | null;
98
- active?: boolean;
99
- };
100
- export type WebhookDeliveryStatus = "pending" | "delivering" | "succeeded" | "failed" | "dead_letter";
101
- export type WebhookDeliveryRecord = {
102
- id: string;
103
- deliveryId: string;
104
- webhookId: string;
105
- eventId: string;
106
- eventType: string;
107
- topicId: string;
108
- status: WebhookDeliveryStatus;
109
- attemptCount: number;
110
- maxAttempts: number;
111
- nextAttemptAt?: number;
112
- lastAttemptAt?: number;
113
- lastStatusCode?: number;
114
- lastError?: string;
115
- deliveredAt?: number;
116
- createdAt: number;
117
- updatedAt: number;
118
- };
119
- export type WebhookDeliveryAttemptRecord = {
120
- id: string;
121
- attemptId: string;
122
- deliveryId: string;
123
- webhookId: string;
124
- eventId: string;
125
- eventType: string;
126
- attemptNumber: number;
127
- status: "succeeded" | "failed";
128
- statusCode?: number;
129
- error?: string;
130
- responseBody?: string;
131
- durationMs?: number;
132
- createdAt: number;
133
- };
134
- export type WebhookDeliveriesResult = {
135
- deliveries: Array<WebhookDeliveryRecord & {
136
- attempts?: WebhookDeliveryAttemptRecord[];
137
- }>;
138
- };
139
- export type WebhookHealthResult = {
140
- webhookId: string;
141
- totalAttempts: number;
142
- successfulAttempts: number;
143
- failedAttempts: number;
144
- successRate: number;
145
- pendingDeliveries: number;
146
- deadLetterDeliveries: number;
147
- lastDeliveryAt?: number;
148
- lastSuccessfulDeliveryAt?: number;
149
- };
150
- export type WebhookTestResult = {
151
- webhookId: string;
152
- deliveryId: string;
153
- status: WebhookDeliveryStatus;
154
- attempts: number;
155
- };
156
- export type ReplayEventsInput = EventListQuery & {
157
- webhookId?: string;
158
- };
159
- export type ReplayEventsResult = EventListResult & {
160
- replayedDeliveries?: number;
161
- replayedWebhookId?: string;
162
- };
163
- export declare function createEventId(): string;
164
- export declare function normalizeRetentionDays(value: number | undefined): number;
165
- export declare function buildDomainEvent(input: CreateDomainEventInput): DomainEvent;
166
- export declare function compareEventCursor(left: EventCursor, right: EventCursor): number;
167
- export declare function encodeEventCursor(cursor: EventCursor): string;
168
- export declare function decodeEventCursor(cursor: string | undefined): EventCursor | null;
169
- export declare function isAfterCursor(event: Pick<DomainEvent, "timestamp" | "eventId">, cursor: EventCursor | null): boolean;
170
- export declare function sortEventsByCursor<T extends Pick<DomainEvent, "timestamp" | "eventId">>(events: readonly T[]): T[];
171
- export declare function inferActorType(args: {
172
- sessionType?: "agent" | "user";
173
- authMode?: string;
174
- principalType?: string;
175
- }): DomainActorType;
176
- export declare function emitDomainEvent(invokeMutation: (reference: any, args: CreateDomainEventInput) => Promise<unknown>, input: CreateDomainEventInput): Promise<unknown>;
@@ -1,159 +0,0 @@
1
- /**
2
- * @lucern/contracts — events (canonical support contract)
3
- *
4
- * Consolidated flat support surface for Lucern's domain event stream:
5
- * - Event type definitions, constants, and shared enums
6
- * - Event construction + cursor helpers
7
- *
8
- * Consolidated from the former split type-definition module
9
- * and the prior src/events.contract.ts (helpers) in EK-16 T1 PR 3b.
10
- * Compat shim remains at the old events-types path until Lucern 1.0.0 (D12).
11
- */
12
- // =============================================================================
13
- // EVENT TYPE DEFINITIONS & CONSTANTS
14
- // (Formerly the split events type-definition module)
15
- // =============================================================================
16
- export const DOMAIN_EVENT_VERSION = "1.0";
17
- export const EVENT_RETENTION_DEFAULT_DAYS = 30;
18
- export const WEBHOOK_MAX_ATTEMPTS = 5;
19
- export const WEBHOOK_RETRY_DELAYS_MS = [1_000, 5_000, 30_000, 300_000];
20
- export const DOMAIN_EVENT_TYPES = [
21
- "belief.created",
22
- "belief.forked",
23
- "belief.confidence_updated",
24
- "belief.archived",
25
- "belief.refined",
26
- "belief.contract_created",
27
- "belief.contract_evaluated",
28
- "belief.lineage_queried",
29
- "evidence.created",
30
- "evidence.linked",
31
- "evidence.search_executed",
32
- "question.created",
33
- "question.answered",
34
- "question.refined",
35
- "question.status_updated",
36
- "question.archived",
37
- "edge.created",
38
- "contradiction.flagged",
39
- "worktree.created",
40
- "worktree.activated",
41
- "worktree.merged",
42
- "worktree.targets_updated",
43
- "worktree.metadata_updated",
44
- "topic.created",
45
- "topic.updated",
46
- "topic.archived",
47
- "task.created",
48
- "task.completed",
49
- "task.updated",
50
- "ontology.bound",
51
- "context.compiled",
52
- "identity.key_created",
53
- "identity.key_rotated",
54
- "identity.key_revoked",
55
- "webhook.test",
56
- ];
57
- // =============================================================================
58
- // EVENT HELPERS
59
- // (Formerly the body of src/events.contract.ts)
60
- // =============================================================================
61
- function toBase64(value) {
62
- if (typeof Buffer !== "undefined") {
63
- return Buffer.from(value, "utf8").toString("base64url");
64
- }
65
- return btoa(unescape(encodeURIComponent(value)))
66
- .replace(/\+/g, "-")
67
- .replace(/\//g, "_")
68
- .replace(/=+$/g, "");
69
- }
70
- function fromBase64(value) {
71
- if (typeof Buffer !== "undefined") {
72
- return Buffer.from(value, "base64url").toString("utf8");
73
- }
74
- const normalized = value.replace(/-/g, "+").replace(/_/g, "/");
75
- return decodeURIComponent(escape(atob(normalized)));
76
- }
77
- export function createEventId() {
78
- const random = crypto.randomUUID().replace(/-/g, "");
79
- return `evt_${random}`;
80
- }
81
- export function normalizeRetentionDays(value) {
82
- if (!Number.isFinite(value) || typeof value !== "number" || value <= 0) {
83
- return EVENT_RETENTION_DEFAULT_DAYS;
84
- }
85
- return Math.max(1, Math.trunc(value));
86
- }
87
- export function buildDomainEvent(input) {
88
- const timestamp = input.timestamp ?? Date.now();
89
- const retentionDays = normalizeRetentionDays(input.retentionDays);
90
- return {
91
- eventId: input.eventId?.trim() || createEventId(),
92
- type: input.type.trim(),
93
- version: DOMAIN_EVENT_VERSION,
94
- timestamp,
95
- tenantId: input.tenantId?.trim() || undefined,
96
- workspaceId: input.workspaceId?.trim() || undefined,
97
- topicId: input.topicId.trim(),
98
- resourceId: input.resourceId.trim(),
99
- resourceType: input.resourceType.trim(),
100
- actorId: input.actorId.trim(),
101
- actorType: input.actorType,
102
- data: input.data ?? {},
103
- correlationId: input.correlationId?.trim() || undefined,
104
- expiresAt: timestamp + retentionDays * 24 * 60 * 60 * 1000,
105
- };
106
- }
107
- export function compareEventCursor(left, right) {
108
- if (left.timestamp !== right.timestamp) {
109
- return left.timestamp - right.timestamp;
110
- }
111
- return left.eventId.localeCompare(right.eventId);
112
- }
113
- export function encodeEventCursor(cursor) {
114
- return toBase64(JSON.stringify(cursor));
115
- }
116
- export function decodeEventCursor(cursor) {
117
- if (!cursor || cursor.trim().length === 0) {
118
- return null;
119
- }
120
- try {
121
- const parsed = JSON.parse(fromBase64(cursor.trim()));
122
- if (typeof parsed.timestamp !== "number" ||
123
- !Number.isFinite(parsed.timestamp) ||
124
- typeof parsed.eventId !== "string" ||
125
- parsed.eventId.trim().length === 0) {
126
- return null;
127
- }
128
- return {
129
- timestamp: parsed.timestamp,
130
- eventId: parsed.eventId.trim(),
131
- };
132
- }
133
- catch {
134
- return null;
135
- }
136
- }
137
- export function isAfterCursor(event, cursor) {
138
- if (!cursor) {
139
- return true;
140
- }
141
- return compareEventCursor(event, cursor) > 0;
142
- }
143
- export function sortEventsByCursor(events) {
144
- return [...events].sort((left, right) => compareEventCursor(left, right));
145
- }
146
- export function inferActorType(args) {
147
- if (args.sessionType === "agent") {
148
- return "agent";
149
- }
150
- if (args.authMode === "service_principal" ||
151
- args.authMode === "tenant_api_key" ||
152
- args.principalType === "service") {
153
- return "service";
154
- }
155
- return "human";
156
- }
157
- export async function emitDomainEvent(invokeMutation, input) {
158
- return await invokeMutation("events:recordEvent", input);
159
- }
@@ -1,74 +0,0 @@
1
- /**
2
- * Gateway contract types — shared between Stack's gateway middleware and
3
- * Lucern's server-core / gateway route handlers.
4
- *
5
- * These types describe the authenticated request context that flows from
6
- * the gateway into Lucern route handlers. The gateway (Stack-side) creates
7
- * the context; Lucern consumes it read-only.
8
- *
9
- * @module @lucern/contracts/src/gateway
10
- */
11
- import type { SessionAuthMode, SessionDelegationHop, SessionPrincipalType } from "./auth-session.contract";
12
- export type PlatformApiErrorCode = "AUTH_REQUIRED" | "AUTHENTICATION_REQUIRED" | "AUTH_TOKEN_MISSING" | "INVALID_REQUEST" | "IDEMPOTENCY_KEY_REQUIRED" | "FORBIDDEN" | "SCOPE_INSUFFICIENT" | "ENVIRONMENT_MISMATCH" | "KEY_EXPIRED" | "KEY_REVOKED" | "RATE_LIMIT_EXCEEDED" | "NOT_FOUND" | "CONFLICT" | "UPSTREAM_ERROR" | "INTERNAL_ERROR";
13
- export type GatewayScope = {
14
- tenantId?: string;
15
- workspaceId?: string;
16
- };
17
- export type GatewayEnvironment = "sandbox" | "production";
18
- export type GatewayAuthMode = "interactive_user" | "service_principal" | "tenant_api_key" | "session_token";
19
- export type KeyLifecycleStatus = "active" | "rotating" | "rotated" | "expired" | "revoked";
20
- export type CutoverDomain = "graph" | "schema" | "identity" | "policy" | "audit" | "admin" | "agent" | "tool" | "prompt" | "intelligence";
21
- export type CutoverFlagState = "legacy" | "cutover" | "disabled";
22
- /**
23
- * Authenticated request context created by the gateway middleware.
24
- * Lucern route handlers receive this as a read-only parameter.
25
- *
26
- * The `convex` field is typed as `unknown` in the contract because Lucern
27
- * consumers should not use the gateway's Convex client directly — they
28
- * have their own kernel client. The gateway (Stack-side) narrows this to
29
- * `ConvexHttpClient` at the construction site.
30
- */
31
- export type GatewayAuthContext = {
32
- userId: string;
33
- convexToken?: string;
34
- /** Opaque in contract — narrowed to ConvexHttpClient at the gateway. */
35
- convex: any;
36
- authMode: GatewayAuthMode;
37
- principalId?: string;
38
- principalType?: SessionPrincipalType;
39
- tenantId?: string;
40
- workspaceId?: string;
41
- roles?: string[];
42
- sessionId?: string;
43
- sessionAuthMode?: SessionAuthMode;
44
- sessionExpiresAt?: number;
45
- delegationChain?: SessionDelegationHop[];
46
- servicePrincipalId?: string;
47
- servicePrincipalKeyId?: string;
48
- servicePrincipalTenantId?: string;
49
- servicePrincipalWorkspaceId?: string;
50
- requestEnvironment: GatewayEnvironment;
51
- keyEnvironment?: GatewayEnvironment;
52
- keyStatus: KeyLifecycleStatus | "unknown";
53
- grantedScopes: Set<string>;
54
- cutoverDomain: CutoverDomain;
55
- cutoverState: CutoverFlagState;
56
- };
57
- export type GatewayErrorArgs = {
58
- code: PlatformApiErrorCode;
59
- message: string;
60
- status: number;
61
- correlationId: string;
62
- policyTraceId?: string;
63
- invariant?: string;
64
- suggestion?: string;
65
- details?: unknown;
66
- headers?: HeadersInit;
67
- };
68
- export type GatewaySuccessArgs = {
69
- status?: number;
70
- correlationId: string;
71
- policyTraceId?: string;
72
- idempotentReplay?: boolean;
73
- };
74
- export declare function requireActorPrincipalId(authContext: GatewayAuthContext): string;
@@ -1,19 +0,0 @@
1
- /**
2
- * Gateway contract types — shared between Stack's gateway middleware and
3
- * Lucern's server-core / gateway route handlers.
4
- *
5
- * These types describe the authenticated request context that flows from
6
- * the gateway into Lucern route handlers. The gateway (Stack-side) creates
7
- * the context; Lucern consumes it read-only.
8
- *
9
- * @module @lucern/contracts/src/gateway
10
- */
11
- export function requireActorPrincipalId(authContext) {
12
- const principalId = typeof authContext.principalId === "string"
13
- ? authContext.principalId.trim()
14
- : "";
15
- if (principalId.length > 0) {
16
- return principalId;
17
- }
18
- throw new Error("Access denied: federated principal context required.");
19
- }
@@ -1,7 +0,0 @@
1
- export type DecodedPrefixedId = {
2
- prefix: string;
3
- value: string;
4
- };
5
- export declare function encodePrefixedId(prefix: string, value: string): string;
6
- export declare function decodePrefixedId(id: string): DecodedPrefixedId;
7
- export declare function hasPrefixedIdPrefix(id: string, prefix: string): boolean;
@@ -1,24 +0,0 @@
1
- const PREFIXED_ID_PATTERN = /^([a-z][a-z0-9]*)_(.+)$/;
2
- export function encodePrefixedId(prefix, value) {
3
- const normalizedPrefix = prefix.trim();
4
- const normalizedValue = value.trim();
5
- if (!normalizedPrefix || !normalizedValue) {
6
- throw new Error("Both prefix and value are required to encode a prefixed ID.");
7
- }
8
- return `${normalizedPrefix}_${normalizedValue}`;
9
- }
10
- export function decodePrefixedId(id) {
11
- const normalized = id.trim();
12
- const match = PREFIXED_ID_PATTERN.exec(normalized);
13
- if (!match) {
14
- throw new Error(`Invalid prefixed ID: ${id}`);
15
- }
16
- return {
17
- prefix: match[1],
18
- value: match[2],
19
- };
20
- }
21
- export function hasPrefixedIdPrefix(id, prefix) {
22
- const decoded = decodePrefixedId(id);
23
- return decoded.prefix === prefix.trim();
24
- }
@@ -1,29 +0,0 @@
1
- /**
2
- * Lucern Platform Contracts
3
- *
4
- * Machine-readable source of truth for all external API surfaces.
5
- * Enforcement hierarchy: MCP/API (co-equal) → SDK (derived) → Schema (internal).
6
- *
7
- * These contracts are consumed by:
8
- * - MCP tool registration (learning-loop module)
9
- * - API route validation (platform gateway)
10
- * - SDK type generation (@lucern/sdk-* packages)
11
- * - Contract lint gates (CI)
12
- */
13
- export * from "./api-enums.contract";
14
- export * from "./auth-session.contract";
15
- export * from "./auth-context.contract";
16
- export * from "./convex-admin.contract";
17
- export * from "./gateway.contract";
18
- export * from "./context-pack.contract";
19
- export * from "./events.contract";
20
- export * from "./events-types.contract";
21
- export * from "./ids.contract";
22
- export * as mcpToolsContract from "./mcp-tools.contract";
23
- export * from "./ontology-matching.contract";
24
- export * from "./prompt.contract";
25
- export * from "./sdk-methods.contract";
26
- export * as sdkToolsContract from "./sdk-tools.contract";
27
- export * from "./text-matching.contract";
28
- export * from "./topic-scope.contract";
29
- export * from "./workflow-runtime.contract";
@@ -1,29 +0,0 @@
1
- /**
2
- * Lucern Platform Contracts
3
- *
4
- * Machine-readable source of truth for all external API surfaces.
5
- * Enforcement hierarchy: MCP/API (co-equal) → SDK (derived) → Schema (internal).
6
- *
7
- * These contracts are consumed by:
8
- * - MCP tool registration (learning-loop module)
9
- * - API route validation (platform gateway)
10
- * - SDK type generation (@lucern/sdk-* packages)
11
- * - Contract lint gates (CI)
12
- */
13
- export * from "./api-enums.contract.js";
14
- export * from "./auth-session.contract.js";
15
- export * from "./auth-context.contract.js";
16
- export * from "./convex-admin.contract.js";
17
- export * from "./gateway.contract.js";
18
- export * from "./context-pack.contract.js";
19
- export * from "./events.contract.js";
20
- export * from "./events-types.contract.js";
21
- export * from "./ids.contract.js";
22
- export * as mcpToolsContract from "./mcp-tools.contract.js";
23
- export * from "./ontology-matching.contract.js";
24
- export * from "./prompt.contract.js";
25
- export * from "./sdk-methods.contract.js";
26
- export * as sdkToolsContract from "./sdk-tools.contract.js";
27
- export * from "./text-matching.contract.js";
28
- export * from "./topic-scope.contract.js";
29
- export * from "./workflow-runtime.contract.js";
@@ -1,70 +0,0 @@
1
- /**
2
- * Lens Filter Criteria Contract
3
- *
4
- * Version-discriminated filter DSL for lenses. Each filter criteria document
5
- * carries a `version` and `kind` discriminator so future shapes can coexist
6
- * without schema migrations. The Convex `filterCriteria` field remains v.any()
7
- * — all type enforcement happens here at the TypeScript contract layer.
8
- *
9
- * Forward-compatibility guarantees:
10
- * - `version` field: new versions add fields, never remove or rename existing ones
11
- * - `kind` field: new filter kinds (temporal, confidence-range) can be added
12
- * without touching taxonomy code paths
13
- * - `entityTypeFilters` array items are open to extension in future versions
14
- * - Resolution logic switches on `version` + `kind` to select the right resolver
15
- *
16
- * @module lucern/contracts/src/lens-filter
17
- */
18
- /**
19
- * A single entity type filter entry. Matches nodes whose `nodeType` equals
20
- * `entityTypeValue`, optionally further narrowed by subtype membership.
21
- *
22
- * V2 will add `propertyMatchers` here for arbitrary JSON Schema facet queries.
23
- */
24
- export type EntityTypeFilterV1 = {
25
- /** References ontologyVersion.entityTypes[].value, e.g. "company" */
26
- entityTypeValue: string;
27
- /** Optional subtype narrowing. If omitted or empty, all subtypes match. */
28
- subtypeValues?: string[];
29
- };
30
- /**
31
- * Optional scope to restrict which ontology the filter resolves against.
32
- * If omitted, resolution uses whatever ontology is active in the workspace.
33
- */
34
- export type OntologyScope = {
35
- /** Restrict to a specific ontology by key, e.g. "vc-investment" */
36
- ontologyKey?: string;
37
- };
38
- /**
39
- * Taxonomy filter criteria v1: entity type + subtype matching over ontology.
40
- */
41
- export type TaxonomyFilterCriteriaV1 = {
42
- version: 1;
43
- kind: "taxonomy";
44
- entityTypeFilters: EntityTypeFilterV1[];
45
- ontologyScope?: OntologyScope;
46
- };
47
- /**
48
- * Discriminated union of all supported filter criteria.
49
- * Resolution logic switches on `version` + `kind`.
50
- *
51
- * To add a new filter kind:
52
- * 1. Define a new type (e.g., TemporalFilterCriteriaV1)
53
- * 2. Add it to this union
54
- * 3. Add a resolver in taxonomy-filter.ts
55
- * 4. No schema migration needed — filterCriteria is v.any()
56
- */
57
- export type LensFilterCriteria = TaxonomyFilterCriteriaV1;
58
- export declare function isLensFilterCriteria(value: unknown): value is LensFilterCriteria;
59
- export declare function isTaxonomyFilterCriteriaV1(value: unknown): value is TaxonomyFilterCriteriaV1;
60
- export type FilterValidationResult = {
61
- valid: true;
62
- } | {
63
- valid: false;
64
- errors: string[];
65
- };
66
- /**
67
- * Validate a filter criteria document at the contract layer.
68
- * This runs before persisting to Convex.
69
- */
70
- export declare function validateFilterCriteria(value: unknown): FilterValidationResult;