@lucern/contracts 0.1.1-alpha.1 → 0.1.2-alpha.1

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 (151) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/README.md +3 -0
  3. package/dist/agents/v1.d.ts +2 -0
  4. package/dist/agents/v1.js +3 -0
  5. package/dist/agents/v1.js.map +1 -0
  6. package/dist/api-enums.contract.d.ts +60 -0
  7. package/dist/api-enums.contract.js +160 -0
  8. package/dist/api-enums.contract.js.map +1 -0
  9. package/dist/auth-context.contract.d.ts +2 -0
  10. package/dist/auth-context.contract.js +48 -0
  11. package/dist/auth-context.contract.js.map +1 -0
  12. package/dist/auth-session.contract.d.ts +2 -0
  13. package/dist/auth-session.contract.js +48 -0
  14. package/dist/auth-session.contract.js.map +1 -0
  15. package/dist/auth.contract.d.ts +92 -0
  16. package/dist/auth.contract.js +48 -0
  17. package/dist/auth.contract.js.map +1 -0
  18. package/dist/beliefs/v1.d.ts +2 -0
  19. package/dist/beliefs/v1.js +3 -0
  20. package/dist/beliefs/v1.js.map +1 -0
  21. package/dist/context-pack.contract.d.ts +496 -0
  22. package/dist/context-pack.contract.js +98 -0
  23. package/dist/context-pack.contract.js.map +1 -0
  24. package/dist/convex-admin.contract.d.ts +7 -0
  25. package/dist/convex-admin.contract.js +3 -0
  26. package/dist/convex-admin.contract.js.map +1 -0
  27. package/dist/events-types.contract.d.ts +1 -0
  28. package/dist/events-types.contract.js +136 -0
  29. package/dist/events-types.contract.js.map +1 -0
  30. package/dist/events.contract.d.ts +178 -0
  31. package/dist/events.contract.js +136 -0
  32. package/dist/events.contract.js.map +1 -0
  33. package/dist/evidence/v1.d.ts +2 -0
  34. package/dist/evidence/v1.js +3 -0
  35. package/dist/evidence/v1.js.map +1 -0
  36. package/dist/gateway.contract.d.ts +79 -0
  37. package/dist/gateway.contract.js +12 -0
  38. package/dist/gateway.contract.js.map +1 -0
  39. package/dist/graph/v1.d.ts +2 -0
  40. package/dist/graph/v1.js +3 -0
  41. package/dist/graph/v1.js.map +1 -0
  42. package/dist/ids.contract.d.ts +9 -0
  43. package/{src/ids.contract.ts → dist/ids.contract.js} +10 -17
  44. package/dist/ids.contract.js.map +1 -0
  45. package/dist/index.d.ts +15 -2004
  46. package/dist/index.js +4 -105
  47. package/dist/index.js.map +1 -0
  48. package/dist/lens-filter.contract.d.ts +72 -0
  49. package/dist/lens-filter.contract.js +71 -0
  50. package/dist/lens-filter.contract.js.map +1 -0
  51. package/dist/lens-workflow.contract.d.ts +87 -0
  52. package/dist/lens-workflow.contract.js +123 -0
  53. package/dist/lens-workflow.contract.js.map +1 -0
  54. package/dist/mcp-tools.contract-D8kXcP6d.d.ts +254 -0
  55. package/dist/mcp-tools.contract.d.ts +1 -0
  56. package/dist/mcp-tools.contract.js +2986 -0
  57. package/dist/mcp-tools.contract.js.map +1 -0
  58. package/dist/ontologies/v1.d.ts +2 -0
  59. package/dist/ontologies/v1.js +3 -0
  60. package/dist/ontologies/v1.js.map +1 -0
  61. package/dist/ontology-matching.contract.d.ts +1 -0
  62. package/dist/ontology-matching.contract.js +346 -0
  63. package/dist/ontology-matching.contract.js.map +1 -0
  64. package/dist/prompt.contract.d.ts +26 -0
  65. package/dist/prompt.contract.js +12 -0
  66. package/dist/prompt.contract.js.map +1 -0
  67. package/dist/questions/v1.d.ts +2 -0
  68. package/dist/questions/v1.js +3 -0
  69. package/dist/questions/v1.js.map +1 -0
  70. package/dist/sdk-methods.contract.d.ts +362 -0
  71. package/dist/sdk-methods.contract.js +3 -0
  72. package/dist/sdk-methods.contract.js.map +1 -0
  73. package/dist/sdk-tools.contract-BnV0hKLp.d.ts +150 -0
  74. package/dist/sdk-tools.contract.d.ts +2 -0
  75. package/dist/sdk-tools.contract.js +4222 -0
  76. package/dist/sdk-tools.contract.js.map +1 -0
  77. package/dist/text-matching.contract.d.ts +55 -0
  78. package/{src/text-matching.contract.ts → dist/text-matching.contract.js} +36 -137
  79. package/dist/text-matching.contract.js.map +1 -0
  80. package/dist/topic-scope.contract.d.ts +1 -0
  81. package/{src/v1/topics/v1.ts → dist/topic-scope.contract.js} +13 -38
  82. package/dist/topic-scope.contract.js.map +1 -0
  83. package/dist/topics/v1.d.ts +2 -0
  84. package/dist/topics/v1.js +3 -0
  85. package/dist/topics/v1.js.map +1 -0
  86. package/dist/v1/agents/v1.d.ts +2 -0
  87. package/dist/v1/agents/v1.js +3 -0
  88. package/dist/v1/agents/v1.js.map +1 -0
  89. package/dist/v1/beliefs/v1.d.ts +2 -0
  90. package/dist/v1/beliefs/v1.js +3 -0
  91. package/dist/v1/beliefs/v1.js.map +1 -0
  92. package/dist/v1/evidence/v1.d.ts +2 -0
  93. package/dist/v1/evidence/v1.js +3 -0
  94. package/dist/v1/evidence/v1.js.map +1 -0
  95. package/dist/v1/graph/v1.d.ts +2 -0
  96. package/dist/v1/graph/v1.js +3 -0
  97. package/dist/v1/graph/v1.js.map +1 -0
  98. package/dist/v1/ontologies/v1.d.ts +78 -0
  99. package/dist/v1/ontologies/v1.js +346 -0
  100. package/dist/v1/ontologies/v1.js.map +1 -0
  101. package/dist/v1/questions/v1.d.ts +2 -0
  102. package/dist/v1/questions/v1.js +3 -0
  103. package/dist/v1/questions/v1.js.map +1 -0
  104. package/dist/v1/topics/v1.d.ts +21 -0
  105. package/dist/v1/topics/v1.js +54 -0
  106. package/dist/v1/topics/v1.js.map +1 -0
  107. package/dist/v1/worktrees/v1.d.ts +2 -0
  108. package/dist/v1/worktrees/v1.js +3 -0
  109. package/dist/v1/worktrees/v1.js.map +1 -0
  110. package/dist/workflow-runtime.contract.d.ts +163 -0
  111. package/dist/workflow-runtime.contract.js +245 -0
  112. package/dist/workflow-runtime.contract.js.map +1 -0
  113. package/dist/worktrees/v1.d.ts +2 -0
  114. package/dist/worktrees/v1.js +3 -0
  115. package/dist/worktrees/v1.js.map +1 -0
  116. package/package.json +23 -7
  117. package/src/agents/v1.ts +0 -8
  118. package/src/api-enums.contract.ts +0 -183
  119. package/src/auth-context.contract.ts +0 -9
  120. package/src/auth-session.contract.ts +0 -9
  121. package/src/auth.contract.ts +0 -162
  122. package/src/beliefs/v1.ts +0 -8
  123. package/src/context-pack.contract.ts +0 -704
  124. package/src/convex-admin.contract.ts +0 -14
  125. package/src/events-types.contract.ts +0 -9
  126. package/src/events.contract.ts +0 -376
  127. package/src/evidence/v1.ts +0 -8
  128. package/src/gateway.contract.ts +0 -151
  129. package/src/graph/v1.ts +0 -8
  130. package/src/index.ts +0 -30
  131. package/src/lens-filter.contract.ts +0 -183
  132. package/src/lens-workflow.contract.ts +0 -162
  133. package/src/mcp-tools.contract.ts +0 -3636
  134. package/src/ontologies/v1.ts +0 -8
  135. package/src/ontology-matching.contract.ts +0 -9
  136. package/src/prompt.contract.ts +0 -50
  137. package/src/questions/v1.ts +0 -8
  138. package/src/sdk-methods.contract.ts +0 -522
  139. package/src/sdk-tools.contract.ts +0 -1545
  140. package/src/topic-scope.contract.ts +0 -9
  141. package/src/topics/v1.ts +0 -8
  142. package/src/v1/agents/v1.ts +0 -8
  143. package/src/v1/beliefs/v1.ts +0 -8
  144. package/src/v1/evidence/v1.ts +0 -8
  145. package/src/v1/graph/v1.ts +0 -8
  146. package/src/v1/ontologies/v1.ts +0 -276
  147. package/src/v1/questions/v1.ts +0 -8
  148. package/src/v1/worktrees/v1.ts +0 -8
  149. package/src/workflow-runtime.contract.ts +0 -440
  150. package/src/worktrees/v1.ts +0 -8
  151. package/tsconfig.json +0 -9
@@ -0,0 +1,72 @@
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
+ 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
+ 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
+ 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
+ type LensFilterCriteria = TaxonomyFilterCriteriaV1;
58
+ declare function isLensFilterCriteria(value: unknown): value is LensFilterCriteria;
59
+ declare function isTaxonomyFilterCriteriaV1(value: unknown): value is TaxonomyFilterCriteriaV1;
60
+ 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
+ declare function validateFilterCriteria(value: unknown): FilterValidationResult;
71
+
72
+ export { type EntityTypeFilterV1, type FilterValidationResult, type LensFilterCriteria, type OntologyScope, type TaxonomyFilterCriteriaV1, isLensFilterCriteria, isTaxonomyFilterCriteriaV1, validateFilterCriteria };
@@ -0,0 +1,71 @@
1
+ // src/lens-filter.contract.ts
2
+ function isLensFilterCriteria(value) {
3
+ if (!value || typeof value !== "object") return false;
4
+ const obj = value;
5
+ return typeof obj.version === "number" && typeof obj.kind === "string";
6
+ }
7
+ function isTaxonomyFilterCriteriaV1(value) {
8
+ if (!isLensFilterCriteria(value)) return false;
9
+ return value.version === 1 && value.kind === "taxonomy";
10
+ }
11
+ function validateFilterCriteria(value) {
12
+ if (value === void 0 || value === null) {
13
+ return { valid: true };
14
+ }
15
+ if (!isLensFilterCriteria(value)) {
16
+ return {
17
+ valid: false,
18
+ errors: [
19
+ 'filterCriteria must have numeric "version" and string "kind" fields'
20
+ ]
21
+ };
22
+ }
23
+ if (isTaxonomyFilterCriteriaV1(value)) {
24
+ return validateTaxonomyFilterV1(value);
25
+ }
26
+ const raw = value;
27
+ return {
28
+ valid: false,
29
+ errors: [
30
+ `Unsupported filter criteria: version=${raw.version}, kind=${raw.kind}`
31
+ ]
32
+ };
33
+ }
34
+ function validateTaxonomyFilterV1(criteria) {
35
+ const errors = [];
36
+ if (!Array.isArray(criteria.entityTypeFilters)) {
37
+ errors.push("entityTypeFilters must be an array");
38
+ return { valid: false, errors };
39
+ }
40
+ if (criteria.entityTypeFilters.length === 0) {
41
+ errors.push("entityTypeFilters must contain at least one entry");
42
+ return { valid: false, errors };
43
+ }
44
+ for (let i = 0; i < criteria.entityTypeFilters.length; i++) {
45
+ const filter = criteria.entityTypeFilters[i];
46
+ if (!filter || typeof filter.entityTypeValue !== "string") {
47
+ errors.push(
48
+ `entityTypeFilters[${i}].entityTypeValue must be a non-empty string`
49
+ );
50
+ continue;
51
+ }
52
+ if (filter.entityTypeValue.trim().length === 0) {
53
+ errors.push(
54
+ `entityTypeFilters[${i}].entityTypeValue must be a non-empty string`
55
+ );
56
+ }
57
+ if (filter.subtypeValues !== void 0 && !Array.isArray(filter.subtypeValues)) {
58
+ errors.push(`entityTypeFilters[${i}].subtypeValues must be an array`);
59
+ }
60
+ }
61
+ if (criteria.ontologyScope !== void 0) {
62
+ if (typeof criteria.ontologyScope !== "object" || criteria.ontologyScope === null) {
63
+ errors.push("ontologyScope must be an object");
64
+ }
65
+ }
66
+ return errors.length === 0 ? { valid: true } : { valid: false, errors };
67
+ }
68
+
69
+ export { isLensFilterCriteria, isTaxonomyFilterCriteriaV1, validateFilterCriteria };
70
+ //# sourceMappingURL=lens-filter.contract.js.map
71
+ //# sourceMappingURL=lens-filter.contract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lens-filter.contract.ts"],"names":[],"mappings":";AA4EO,SAAS,qBACd,KAAA,EAC6B;AAC7B,EAAA,IAAI,CAAC,KAAA,IAAS,OAAO,KAAA,KAAU,UAAU,OAAO,KAAA;AAChD,EAAA,MAAM,GAAA,GAAM,KAAA;AACZ,EAAA,OAAO,OAAO,GAAA,CAAI,OAAA,KAAY,QAAA,IAAY,OAAO,IAAI,IAAA,KAAS,QAAA;AAChE;AAEO,SAAS,2BACd,KAAA,EACmC;AACnC,EAAA,IAAI,CAAC,oBAAA,CAAqB,KAAK,CAAA,EAAG,OAAO,KAAA;AACzC,EAAA,OAAO,KAAA,CAAM,OAAA,KAAY,CAAA,IAAK,KAAA,CAAM,IAAA,KAAS,UAAA;AAC/C;AAcO,SAAS,uBACd,KAAA,EACwB;AACxB,EAAA,IAAI,KAAA,KAAU,MAAA,IAAa,KAAA,KAAU,IAAA,EAAM;AACzC,IAAA,OAAO,EAAE,OAAO,IAAA,EAAK;AAAA,EACvB;AAEA,EAAA,IAAI,CAAC,oBAAA,CAAqB,KAAK,CAAA,EAAG;AAChC,IAA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I,MAAA,CAAO,eAAA,CAAgB,IAAA,EAAK,CAAE,WAAW,CAAA,EAAG;AAC9C,MAAA,MAAA,CAAO,IAAA;AAAA,QACL,qBAAqB,CAAC,CAAA,4CAAA;AAAA,OACxB;AAAA,IACF;AACA,IAAA,IACE,MAAA,CAAO,kBAAkB,MAAA,IACzB,CAAC,MAAM,OAAA,CAAQ,MAAA,CAAO,aAAa,CAAA,EACnC;AACA,MAAA,MAAA,CAAO,IAAA,CAAK,CAAA,kBAAA,EAAqB,CAAC,CAAA,gCAAA,CAAkC,CAAA;AAAA,IACtE;AAAA,EACF;AAEA,EAAA,IAAI,QAAA,CAAS,kBAAkB,MAAA,EAAW;AACxC,IAAA,IACE,OAAO,QAAA,CAAS,aAAA,KAAkB,QAAA,IAClC,QAAA,CAAS,kBAAkB,IAAA,EAC3B;AACA,MAAA,MAAA,CAAO,KAAK,iCAAiC,CAAA;AAAA,IAC/C;AAAA,EACF;AAEA,EAAA,OAAO,MAAA,CAAO,MAAA,KAAW,CAAA,GACrB,EAAE,KAAA,EAAO,MAAK,GACd,EAAE,KAAA,EAAO,KAAA,EAAO,MAAA,EAAO;AAC7B","file":"lens-filter.contract.js","sourcesContent":["/**\n * Lens Filter Criteria Contract\n *\n * Version-discriminated filter DSL for lenses. Each filter criteria document\n * carries a `version` and `kind` discriminator so future shapes can coexist\n * without schema migrations. The Convex `filterCriteria` field remains v.any()\n * — all type enforcement happens here at the TypeScript contract layer.\n *\n * Forward-compatibility guarantees:\n * - `version` field: new versions add fields, never remove or rename existing ones\n * - `kind` field: new filter kinds (temporal, confidence-range) can be added\n * without touching taxonomy code paths\n * - `entityTypeFilters` array items are open to extension in future versions\n * - Resolution logic switches on `version` + `kind` to select the right resolver\n *\n * @module lucern/contracts/src/lens-filter\n */\n\n// ---------------------------------------------------------------------------\n// V1: Taxonomy Filter — entity type + subtype matching\n// ---------------------------------------------------------------------------\n\n/**\n * A single entity type filter entry. Matches nodes whose `nodeType` equals\n * `entityTypeValue`, optionally further narrowed by subtype membership.\n *\n * V2 will add `propertyMatchers` here for arbitrary JSON Schema facet queries.\n */\nexport type EntityTypeFilterV1 = {\n /** References ontologyVersion.entityTypes[].value, e.g. \"company\" */\n entityTypeValue: string;\n\n /** Optional subtype narrowing. If omitted or empty, all subtypes match. */\n subtypeValues?: string[];\n};\n\n/**\n * Optional scope to restrict which ontology the filter resolves against.\n * If omitted, resolution uses whatever ontology is active in the workspace.\n */\nexport type OntologyScope = {\n /** Restrict to a specific ontology by key, e.g. \"vc-investment\" */\n ontologyKey?: string;\n};\n\n/**\n * Taxonomy filter criteria v1: entity type + subtype matching over ontology.\n */\nexport type TaxonomyFilterCriteriaV1 = {\n version: 1;\n kind: \"taxonomy\";\n entityTypeFilters: EntityTypeFilterV1[];\n ontologyScope?: OntologyScope;\n};\n\n// ---------------------------------------------------------------------------\n// Union: All filter criteria versions and kinds\n// ---------------------------------------------------------------------------\n\n/**\n * Discriminated union of all supported filter criteria.\n * Resolution logic switches on `version` + `kind`.\n *\n * To add a new filter kind:\n * 1. Define a new type (e.g., TemporalFilterCriteriaV1)\n * 2. Add it to this union\n * 3. Add a resolver in taxonomy-filter.ts\n * 4. No schema migration needed — filterCriteria is v.any()\n */\nexport type LensFilterCriteria = TaxonomyFilterCriteriaV1;\n// Future: | TemporalFilterCriteriaV1 | ConfidenceRangeFilterCriteriaV1 | ...\n\n// ---------------------------------------------------------------------------\n// Type guards\n// ---------------------------------------------------------------------------\n\nexport function isLensFilterCriteria(\n value: unknown\n): value is LensFilterCriteria {\n if (!value || typeof value !== \"object\") return false;\n const obj = value as Record<string, unknown>;\n return typeof obj.version === \"number\" && typeof obj.kind === \"string\";\n}\n\nexport function isTaxonomyFilterCriteriaV1(\n value: unknown\n): value is TaxonomyFilterCriteriaV1 {\n if (!isLensFilterCriteria(value)) return false;\n return value.version === 1 && value.kind === \"taxonomy\";\n}\n\n// ---------------------------------------------------------------------------\n// Validation\n// ---------------------------------------------------------------------------\n\nexport type FilterValidationResult =\n | { valid: true }\n | { valid: false; errors: string[] };\n\n/**\n * Validate a filter criteria document at the contract layer.\n * This runs before persisting to Convex.\n */\nexport function validateFilterCriteria(\n value: unknown\n): FilterValidationResult {\n if (value === undefined || value === null) {\n return { valid: true }; // filterCriteria is optional\n }\n\n if (!isLensFilterCriteria(value)) {\n return {\n valid: false,\n errors: [\n 'filterCriteria must have numeric \"version\" and string \"kind\" fields',\n ],\n };\n }\n\n if (isTaxonomyFilterCriteriaV1(value)) {\n return validateTaxonomyFilterV1(value);\n }\n\n // Cast to access properties — TypeScript narrows to `never` when all union\n // members are exhausted, but at runtime unknown version/kind combos are possible.\n const raw = value as { version: number; kind: string };\n return {\n valid: false,\n errors: [\n `Unsupported filter criteria: version=${raw.version}, kind=${raw.kind}`,\n ],\n };\n}\n\nfunction validateTaxonomyFilterV1(\n criteria: TaxonomyFilterCriteriaV1\n): FilterValidationResult {\n const errors: string[] = [];\n\n if (!Array.isArray(criteria.entityTypeFilters)) {\n errors.push(\"entityTypeFilters must be an array\");\n return { valid: false, errors };\n }\n\n if (criteria.entityTypeFilters.length === 0) {\n errors.push(\"entityTypeFilters must contain at least one entry\");\n return { valid: false, errors };\n }\n\n for (let i = 0; i < criteria.entityTypeFilters.length; i++) {\n const filter = criteria.entityTypeFilters[i];\n if (!filter || typeof filter.entityTypeValue !== \"string\") {\n errors.push(\n `entityTypeFilters[${i}].entityTypeValue must be a non-empty string`\n );\n continue;\n }\n if (filter.entityTypeValue.trim().length === 0) {\n errors.push(\n `entityTypeFilters[${i}].entityTypeValue must be a non-empty string`\n );\n }\n if (\n filter.subtypeValues !== undefined &&\n !Array.isArray(filter.subtypeValues)\n ) {\n errors.push(`entityTypeFilters[${i}].subtypeValues must be an array`);\n }\n }\n\n if (criteria.ontologyScope !== undefined) {\n if (\n typeof criteria.ontologyScope !== \"object\" ||\n criteria.ontologyScope === null\n ) {\n errors.push(\"ontologyScope must be an object\");\n }\n }\n\n return errors.length === 0\n ? { valid: true }\n : { valid: false, errors };\n}\n"]}
@@ -0,0 +1,87 @@
1
+ export { EntityTypeFilterV1, FilterValidationResult, LensFilterCriteria, OntologyScope, TaxonomyFilterCriteriaV1, isLensFilterCriteria, isTaxonomyFilterCriteriaV1, validateFilterCriteria } from './lens-filter.contract.js';
2
+
3
+ /**
4
+ * Canonical lens workflow contract shared across schema, SDK, and MCP surfaces.
5
+ */
6
+
7
+ declare const LENS_PERSPECTIVE_TYPES: readonly ["investigation", "monitoring", "analysis", "comparison", "taxonomy"];
8
+ type LensPerspectiveType = (typeof LENS_PERSPECTIVE_TYPES)[number];
9
+ declare const LENS_STATUSES: readonly ["draft", "active", "archived"];
10
+ type LensStatus = (typeof LENS_STATUSES)[number];
11
+ declare const LENS_TASK_TEMPLATE_PRIORITIES: readonly ["critical", "high", "medium", "low"];
12
+ type LensTaskTemplatePriority = (typeof LENS_TASK_TEMPLATE_PRIORITIES)[number];
13
+ type LensLooseMetadata = Record<string, unknown>;
14
+ type LensPromptTemplateReference = {
15
+ key: string;
16
+ promptRef: string;
17
+ phase?: string;
18
+ role?: string;
19
+ version?: string;
20
+ required?: boolean;
21
+ metadata?: LensLooseMetadata;
22
+ };
23
+ type LensWorkflowStepTemplate = {
24
+ key: string;
25
+ title: string;
26
+ description?: string;
27
+ promptTemplateKey?: string;
28
+ taskTemplateKeys?: string[];
29
+ metadata?: LensLooseMetadata;
30
+ };
31
+ type LensWorkflowTemplate = {
32
+ key: string;
33
+ name: string;
34
+ description?: string;
35
+ steps: LensWorkflowStepTemplate[];
36
+ metadata?: LensLooseMetadata;
37
+ };
38
+ type LensTaskTemplate = {
39
+ key: string;
40
+ title: string;
41
+ description?: string;
42
+ priority?: LensTaskTemplatePriority;
43
+ phase?: string;
44
+ metadata?: LensLooseMetadata;
45
+ };
46
+ type LensQuestionTemplate = {
47
+ key: string;
48
+ text: string;
49
+ priority?: LensTaskTemplatePriority;
50
+ linkedBeliefKey?: string;
51
+ metadata?: LensLooseMetadata;
52
+ };
53
+ type LensBranchMigrationSuggestion = {
54
+ recommendedTool: "create_lens";
55
+ perspectiveType: LensPerspectiveType;
56
+ message: string;
57
+ suggestedPayload: {
58
+ name: string;
59
+ description?: string;
60
+ topicId?: string;
61
+ workspaceId?: string;
62
+ perspectiveType: LensPerspectiveType;
63
+ };
64
+ };
65
+ declare const BRANCH_DEPRECATION_MESSAGE = "Branches are deprecated for operational framing. Create a workspace-scoped lens instead.";
66
+ type DeprecatedBranchMetadata = {
67
+ deprecated: true;
68
+ deprecationMessage: string;
69
+ lensSuggestion: LensBranchMigrationSuggestion;
70
+ };
71
+ declare function inferLensPerspectiveTypeFromBranchSchema(schema?: string | null): LensPerspectiveType;
72
+ declare function migrateBranchToLens(args: {
73
+ name: string;
74
+ description?: string;
75
+ topicId?: string;
76
+ workspaceId?: string;
77
+ schema?: string | null;
78
+ }): LensBranchMigrationSuggestion;
79
+ declare function buildDeprecatedBranchMetadata(args: {
80
+ name: string;
81
+ description?: string;
82
+ topicId?: string;
83
+ workspaceId?: string;
84
+ schema?: string | null;
85
+ }): DeprecatedBranchMetadata;
86
+
87
+ export { BRANCH_DEPRECATION_MESSAGE, type DeprecatedBranchMetadata, LENS_PERSPECTIVE_TYPES, LENS_STATUSES, LENS_TASK_TEMPLATE_PRIORITIES, type LensBranchMigrationSuggestion, type LensLooseMetadata, type LensPerspectiveType, type LensPromptTemplateReference, type LensQuestionTemplate, type LensStatus, type LensTaskTemplate, type LensTaskTemplatePriority, type LensWorkflowStepTemplate, type LensWorkflowTemplate, buildDeprecatedBranchMetadata, inferLensPerspectiveTypeFromBranchSchema, migrateBranchToLens };
@@ -0,0 +1,123 @@
1
+ // src/lens-filter.contract.ts
2
+ function isLensFilterCriteria(value) {
3
+ if (!value || typeof value !== "object") return false;
4
+ const obj = value;
5
+ return typeof obj.version === "number" && typeof obj.kind === "string";
6
+ }
7
+ function isTaxonomyFilterCriteriaV1(value) {
8
+ if (!isLensFilterCriteria(value)) return false;
9
+ return value.version === 1 && value.kind === "taxonomy";
10
+ }
11
+ function validateFilterCriteria(value) {
12
+ if (value === void 0 || value === null) {
13
+ return { valid: true };
14
+ }
15
+ if (!isLensFilterCriteria(value)) {
16
+ return {
17
+ valid: false,
18
+ errors: [
19
+ 'filterCriteria must have numeric "version" and string "kind" fields'
20
+ ]
21
+ };
22
+ }
23
+ if (isTaxonomyFilterCriteriaV1(value)) {
24
+ return validateTaxonomyFilterV1(value);
25
+ }
26
+ const raw = value;
27
+ return {
28
+ valid: false,
29
+ errors: [
30
+ `Unsupported filter criteria: version=${raw.version}, kind=${raw.kind}`
31
+ ]
32
+ };
33
+ }
34
+ function validateTaxonomyFilterV1(criteria) {
35
+ const errors = [];
36
+ if (!Array.isArray(criteria.entityTypeFilters)) {
37
+ errors.push("entityTypeFilters must be an array");
38
+ return { valid: false, errors };
39
+ }
40
+ if (criteria.entityTypeFilters.length === 0) {
41
+ errors.push("entityTypeFilters must contain at least one entry");
42
+ return { valid: false, errors };
43
+ }
44
+ for (let i = 0; i < criteria.entityTypeFilters.length; i++) {
45
+ const filter = criteria.entityTypeFilters[i];
46
+ if (!filter || typeof filter.entityTypeValue !== "string") {
47
+ errors.push(
48
+ `entityTypeFilters[${i}].entityTypeValue must be a non-empty string`
49
+ );
50
+ continue;
51
+ }
52
+ if (filter.entityTypeValue.trim().length === 0) {
53
+ errors.push(
54
+ `entityTypeFilters[${i}].entityTypeValue must be a non-empty string`
55
+ );
56
+ }
57
+ if (filter.subtypeValues !== void 0 && !Array.isArray(filter.subtypeValues)) {
58
+ errors.push(`entityTypeFilters[${i}].subtypeValues must be an array`);
59
+ }
60
+ }
61
+ if (criteria.ontologyScope !== void 0) {
62
+ if (typeof criteria.ontologyScope !== "object" || criteria.ontologyScope === null) {
63
+ errors.push("ontologyScope must be an object");
64
+ }
65
+ }
66
+ return errors.length === 0 ? { valid: true } : { valid: false, errors };
67
+ }
68
+
69
+ // src/lens-workflow.contract.ts
70
+ var LENS_PERSPECTIVE_TYPES = [
71
+ "investigation",
72
+ "monitoring",
73
+ "analysis",
74
+ "comparison",
75
+ "taxonomy"
76
+ ];
77
+ var LENS_STATUSES = ["draft", "active", "archived"];
78
+ var LENS_TASK_TEMPLATE_PRIORITIES = [
79
+ "critical",
80
+ "high",
81
+ "medium",
82
+ "low"
83
+ ];
84
+ var BRANCH_DEPRECATION_MESSAGE = "Branches are deprecated for operational framing. Create a workspace-scoped lens instead.";
85
+ function inferLensPerspectiveTypeFromBranchSchema(schema) {
86
+ const normalized = schema?.trim().toLowerCase();
87
+ if (normalized === "phase") {
88
+ return "monitoring";
89
+ }
90
+ if (normalized === "axis" || normalized === "dimension") {
91
+ return "comparison";
92
+ }
93
+ if (normalized === "track") {
94
+ return "investigation";
95
+ }
96
+ return "analysis";
97
+ }
98
+ function migrateBranchToLens(args) {
99
+ const perspectiveType = inferLensPerspectiveTypeFromBranchSchema(args.schema);
100
+ return {
101
+ recommendedTool: "create_lens",
102
+ perspectiveType,
103
+ message: "Branches are deprecated for operational framing. Create a workspace-scoped lens with the suggested payload instead.",
104
+ suggestedPayload: {
105
+ name: args.name,
106
+ description: args.description,
107
+ topicId: args.topicId,
108
+ workspaceId: args.workspaceId,
109
+ perspectiveType
110
+ }
111
+ };
112
+ }
113
+ function buildDeprecatedBranchMetadata(args) {
114
+ return {
115
+ deprecated: true,
116
+ deprecationMessage: BRANCH_DEPRECATION_MESSAGE,
117
+ lensSuggestion: migrateBranchToLens(args)
118
+ };
119
+ }
120
+
121
+ export { BRANCH_DEPRECATION_MESSAGE, LENS_PERSPECTIVE_TYPES, LENS_STATUSES, LENS_TASK_TEMPLATE_PRIORITIES, buildDeprecatedBranchMetadata, inferLensPerspectiveTypeFromBranchSchema, isLensFilterCriteria, isTaxonomyFilterCriteriaV1, migrateBranchToLens, validateFilterCriteria };
122
+ //# sourceMappingURL=lens-workflow.contract.js.map
123
+ //# sourceMappingURL=lens-workflow.contract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lens-filter.contract.ts","../src/lens-workflow.contract.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A8B,IAAA,EAMjB;AAC3B,EAAA,OAAO;AAAA,IACL,UAAA,EAAY,IAAA;AAAA,IACZ,kBAAA,EAAoB,0BAAA;AAAA,IACpB,cAAA,EAAgB,oBAAoB,IAAI;AAAA,GAC1C;AACF","file":"lens-workflow.contract.js","sourcesContent":["/**\n * Lens Filter Criteria Contract\n *\n * Version-discriminated filter DSL for lenses. Each filter criteria document\n * carries a `version` and `kind` discriminator so future shapes can coexist\n * without schema migrations. The Convex `filterCriteria` field remains v.any()\n * — all type enforcement happens here at the TypeScript contract layer.\n *\n * Forward-compatibility guarantees:\n * - `version` field: new versions add fields, never remove or rename existing ones\n * - `kind` field: new filter kinds (temporal, confidence-range) can be added\n * without touching taxonomy code paths\n * - `entityTypeFilters` array items are open to extension in future versions\n * - Resolution logic switches on `version` + `kind` to select the right resolver\n *\n * @module lucern/contracts/src/lens-filter\n */\n\n// ---------------------------------------------------------------------------\n// V1: Taxonomy Filter — entity type + subtype matching\n// ---------------------------------------------------------------------------\n\n/**\n * A single entity type filter entry. Matches nodes whose `nodeType` equals\n * `entityTypeValue`, optionally further narrowed by subtype membership.\n *\n * V2 will add `propertyMatchers` here for arbitrary JSON Schema facet queries.\n */\nexport type EntityTypeFilterV1 = {\n /** References ontologyVersion.entityTypes[].value, e.g. \"company\" */\n entityTypeValue: string;\n\n /** Optional subtype narrowing. If omitted or empty, all subtypes match. */\n subtypeValues?: string[];\n};\n\n/**\n * Optional scope to restrict which ontology the filter resolves against.\n * If omitted, resolution uses whatever ontology is active in the workspace.\n */\nexport type OntologyScope = {\n /** Restrict to a specific ontology by key, e.g. \"vc-investment\" */\n ontologyKey?: string;\n};\n\n/**\n * Taxonomy filter criteria v1: entity type + subtype matching over ontology.\n */\nexport type TaxonomyFilterCriteriaV1 = {\n version: 1;\n kind: \"taxonomy\";\n entityTypeFilters: EntityTypeFilterV1[];\n ontologyScope?: OntologyScope;\n};\n\n// ---------------------------------------------------------------------------\n// Union: All filter criteria versions and kinds\n// ---------------------------------------------------------------------------\n\n/**\n * Discriminated union of all supported filter criteria.\n * Resolution logic switches on `version` + `kind`.\n *\n * To add a new filter kind:\n * 1. Define a new type (e.g., TemporalFilterCriteriaV1)\n * 2. Add it to this union\n * 3. Add a resolver in taxonomy-filter.ts\n * 4. No schema migration needed — filterCriteria is v.any()\n */\nexport type LensFilterCriteria = TaxonomyFilterCriteriaV1;\n// Future: | TemporalFilterCriteriaV1 | ConfidenceRangeFilterCriteriaV1 | ...\n\n// ---------------------------------------------------------------------------\n// Type guards\n// ---------------------------------------------------------------------------\n\nexport function isLensFilterCriteria(\n value: unknown\n): value is LensFilterCriteria {\n if (!value || typeof value !== \"object\") return false;\n const obj = value as Record<string, unknown>;\n return typeof obj.version === \"number\" && typeof obj.kind === \"string\";\n}\n\nexport function isTaxonomyFilterCriteriaV1(\n value: unknown\n): value is TaxonomyFilterCriteriaV1 {\n if (!isLensFilterCriteria(value)) return false;\n return value.version === 1 && value.kind === \"taxonomy\";\n}\n\n// ---------------------------------------------------------------------------\n// Validation\n// ---------------------------------------------------------------------------\n\nexport type FilterValidationResult =\n | { valid: true }\n | { valid: false; errors: string[] };\n\n/**\n * Validate a filter criteria document at the contract layer.\n * This runs before persisting to Convex.\n */\nexport function validateFilterCriteria(\n value: unknown\n): FilterValidationResult {\n if (value === undefined || value === null) {\n return { valid: true }; // filterCriteria is optional\n }\n\n if (!isLensFilterCriteria(value)) {\n return {\n valid: false,\n errors: [\n 'filterCriteria must have numeric \"version\" and string \"kind\" fields',\n ],\n };\n }\n\n if (isTaxonomyFilterCriteriaV1(value)) {\n return validateTaxonomyFilterV1(value);\n }\n\n // Cast to access properties — TypeScript narrows to `never` when all union\n // members are exhausted, but at runtime unknown version/kind combos are possible.\n const raw = value as { version: number; kind: string };\n return {\n valid: false,\n errors: [\n `Unsupported filter criteria: version=${raw.version}, kind=${raw.kind}`,\n ],\n };\n}\n\nfunction validateTaxonomyFilterV1(\n criteria: TaxonomyFilterCriteriaV1\n): FilterValidationResult {\n const errors: string[] = [];\n\n if (!Array.isArray(criteria.entityTypeFilters)) {\n errors.push(\"entityTypeFilters must be an array\");\n return { valid: false, errors };\n }\n\n if (criteria.entityTypeFilters.length === 0) {\n errors.push(\"entityTypeFilters must contain at least one entry\");\n return { valid: false, errors };\n }\n\n for (let i = 0; i < criteria.entityTypeFilters.length; i++) {\n const filter = criteria.entityTypeFilters[i];\n if (!filter || typeof filter.entityTypeValue !== \"string\") {\n errors.push(\n `entityTypeFilters[${i}].entityTypeValue must be a non-empty string`\n );\n continue;\n }\n if (filter.entityTypeValue.trim().length === 0) {\n errors.push(\n `entityTypeFilters[${i}].entityTypeValue must be a non-empty string`\n );\n }\n if (\n filter.subtypeValues !== undefined &&\n !Array.isArray(filter.subtypeValues)\n ) {\n errors.push(`entityTypeFilters[${i}].subtypeValues must be an array`);\n }\n }\n\n if (criteria.ontologyScope !== undefined) {\n if (\n typeof criteria.ontologyScope !== \"object\" ||\n criteria.ontologyScope === null\n ) {\n errors.push(\"ontologyScope must be an object\");\n }\n }\n\n return errors.length === 0\n ? { valid: true }\n : { valid: false, errors };\n}\n","/**\n * Canonical lens workflow contract shared across schema, SDK, and MCP surfaces.\n */\n\n// Re-export filter criteria types for consumers who import from lens-workflow\nexport type {\n LensFilterCriteria,\n TaxonomyFilterCriteriaV1,\n EntityTypeFilterV1,\n OntologyScope,\n FilterValidationResult,\n} from \"./lens-filter.contract\";\nexport {\n validateFilterCriteria,\n isLensFilterCriteria,\n isTaxonomyFilterCriteriaV1,\n} from \"./lens-filter.contract\";\n\nexport const LENS_PERSPECTIVE_TYPES = [\n \"investigation\",\n \"monitoring\",\n \"analysis\",\n \"comparison\",\n \"taxonomy\",\n] as const;\n\nexport type LensPerspectiveType = (typeof LENS_PERSPECTIVE_TYPES)[number];\n\nexport const LENS_STATUSES = [\"draft\", \"active\", \"archived\"] as const;\n\nexport type LensStatus = (typeof LENS_STATUSES)[number];\n\nexport const LENS_TASK_TEMPLATE_PRIORITIES = [\n \"critical\",\n \"high\",\n \"medium\",\n \"low\",\n] as const;\n\nexport type LensTaskTemplatePriority =\n (typeof LENS_TASK_TEMPLATE_PRIORITIES)[number];\n\nexport type LensLooseMetadata = Record<string, unknown>;\n\nexport type LensPromptTemplateReference = {\n key: string;\n promptRef: string;\n phase?: string;\n role?: string;\n version?: string;\n required?: boolean;\n metadata?: LensLooseMetadata;\n};\n\nexport type LensWorkflowStepTemplate = {\n key: string;\n title: string;\n description?: string;\n promptTemplateKey?: string;\n taskTemplateKeys?: string[];\n metadata?: LensLooseMetadata;\n};\n\nexport type LensWorkflowTemplate = {\n key: string;\n name: string;\n description?: string;\n steps: LensWorkflowStepTemplate[];\n metadata?: LensLooseMetadata;\n};\n\nexport type LensTaskTemplate = {\n key: string;\n title: string;\n description?: string;\n priority?: LensTaskTemplatePriority;\n phase?: string;\n metadata?: LensLooseMetadata;\n};\n\nexport type LensQuestionTemplate = {\n key: string;\n text: string;\n priority?: LensTaskTemplatePriority;\n linkedBeliefKey?: string;\n metadata?: LensLooseMetadata;\n};\n\nexport type LensBranchMigrationSuggestion = {\n recommendedTool: \"create_lens\";\n perspectiveType: LensPerspectiveType;\n message: string;\n suggestedPayload: {\n name: string;\n description?: string;\n topicId?: string;\n workspaceId?: string;\n perspectiveType: LensPerspectiveType;\n };\n};\n\nexport const BRANCH_DEPRECATION_MESSAGE =\n \"Branches are deprecated for operational framing. Create a workspace-scoped lens instead.\";\n\nexport type DeprecatedBranchMetadata = {\n deprecated: true;\n deprecationMessage: string;\n lensSuggestion: LensBranchMigrationSuggestion;\n};\n\nexport function inferLensPerspectiveTypeFromBranchSchema(\n schema?: string | null\n): LensPerspectiveType {\n const normalized = schema?.trim().toLowerCase();\n if (normalized === \"phase\") {\n return \"monitoring\";\n }\n if (normalized === \"axis\" || normalized === \"dimension\") {\n return \"comparison\";\n }\n if (normalized === \"track\") {\n return \"investigation\";\n }\n return \"analysis\";\n}\n\nexport function migrateBranchToLens(args: {\n name: string;\n description?: string;\n topicId?: string;\n workspaceId?: string;\n schema?: string | null;\n}): LensBranchMigrationSuggestion {\n const perspectiveType = inferLensPerspectiveTypeFromBranchSchema(args.schema);\n return {\n recommendedTool: \"create_lens\",\n perspectiveType,\n message:\n \"Branches are deprecated for operational framing. Create a workspace-scoped lens with the suggested payload instead.\",\n suggestedPayload: {\n name: args.name,\n description: args.description,\n topicId: args.topicId,\n workspaceId: args.workspaceId,\n perspectiveType,\n },\n };\n}\n\nexport function buildDeprecatedBranchMetadata(args: {\n name: string;\n description?: string;\n topicId?: string;\n workspaceId?: string;\n schema?: string | null;\n}): DeprecatedBranchMetadata {\n return {\n deprecated: true,\n deprecationMessage: BRANCH_DEPRECATION_MESSAGE,\n lensSuggestion: migrateBranchToLens(args),\n };\n}\n"]}