@gencow/core 0.1.27 → 0.1.28

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 (83) hide show
  1. package/dist/document-types.d.ts +65 -0
  2. package/dist/document-types.js +15 -0
  3. package/dist/grounded-answer-types.d.ts +62 -0
  4. package/dist/grounded-answer-types.js +6 -0
  5. package/dist/index.d.ts +10 -1
  6. package/dist/index.js +4 -0
  7. package/dist/rag-ingest-types.d.ts +39 -0
  8. package/dist/rag-ingest-types.js +1 -0
  9. package/dist/rag-operations-types.d.ts +81 -0
  10. package/dist/rag-operations-types.js +1 -0
  11. package/dist/rag-schema.d.ts +1557 -0
  12. package/dist/rag-schema.js +87 -0
  13. package/dist/reactive.d.ts +13 -0
  14. package/dist/rls-db.d.ts +9 -2
  15. package/dist/runtime-env-policy.d.ts +5 -0
  16. package/dist/runtime-env-policy.js +56 -0
  17. package/dist/search-types.d.ts +83 -0
  18. package/dist/search-types.js +1 -0
  19. package/dist/server.d.ts +1 -2
  20. package/dist/server.js +0 -1
  21. package/dist/storage-shared.d.ts +36 -0
  22. package/dist/storage-shared.js +39 -0
  23. package/dist/storage.d.ts +2 -26
  24. package/dist/storage.js +19 -15
  25. package/dist/workflow-types.d.ts +3 -1
  26. package/package.json +8 -7
  27. package/src/document-types.ts +95 -0
  28. package/src/grounded-answer-types.ts +78 -0
  29. package/src/index.ts +66 -1
  30. package/src/rag-ingest-types.ts +52 -0
  31. package/src/rag-operations-types.ts +90 -0
  32. package/src/rag-schema.ts +94 -0
  33. package/src/reactive.ts +13 -0
  34. package/src/rls-db.ts +9 -4
  35. package/src/runtime-env-policy.ts +66 -0
  36. package/src/search-types.ts +91 -0
  37. package/src/server.ts +1 -2
  38. package/src/storage-shared.ts +74 -0
  39. package/src/storage.ts +29 -46
  40. package/src/workflow-types.ts +3 -1
  41. package/src/__tests__/auth.test.ts +0 -118
  42. package/src/__tests__/crons.test.ts +0 -83
  43. package/src/__tests__/crud-codegen-integration.test.ts +0 -246
  44. package/src/__tests__/crud-owner-rls.test.ts +0 -387
  45. package/src/__tests__/crud.test.ts +0 -930
  46. package/src/__tests__/dist-exports.test.ts +0 -176
  47. package/src/__tests__/fixtures/basic/auth.ts +0 -32
  48. package/src/__tests__/fixtures/basic/drizzle.config.ts +0 -12
  49. package/src/__tests__/fixtures/basic/index.ts +0 -6
  50. package/src/__tests__/fixtures/basic/migrations/0000_last_warstar.sql +0 -75
  51. package/src/__tests__/fixtures/basic/migrations/meta/0000_snapshot.json +0 -497
  52. package/src/__tests__/fixtures/basic/migrations/meta/_journal.json +0 -13
  53. package/src/__tests__/fixtures/basic/schema.ts +0 -51
  54. package/src/__tests__/fixtures/basic/tasks.ts +0 -15
  55. package/src/__tests__/fixtures/common/auth-schema.ts +0 -67
  56. package/src/__tests__/helpers/basic-rls-fixture.ts +0 -135
  57. package/src/__tests__/helpers/pglite-migrations.ts +0 -32
  58. package/src/__tests__/helpers/pglite-rls-session.ts +0 -51
  59. package/src/__tests__/helpers/seed-like-fill.ts +0 -202
  60. package/src/__tests__/helpers/test-gencow-ctx-rls.ts +0 -50
  61. package/src/__tests__/httpaction.test.ts +0 -122
  62. package/src/__tests__/image-optimization.test.ts +0 -648
  63. package/src/__tests__/load.test.ts +0 -389
  64. package/src/__tests__/network-sim.test.ts +0 -319
  65. package/src/__tests__/reactive.test.ts +0 -479
  66. package/src/__tests__/retry.test.ts +0 -113
  67. package/src/__tests__/rls-crud-basic.test.ts +0 -317
  68. package/src/__tests__/rls-crud-no-owner-rls-pglite.test.ts +0 -117
  69. package/src/__tests__/rls-custom-mutation-handlers.test.ts +0 -142
  70. package/src/__tests__/rls-custom-query-handlers.test.ts +0 -128
  71. package/src/__tests__/rls-db-leased-connection.test.ts +0 -118
  72. package/src/__tests__/rls-session-and-policies.test.ts +0 -228
  73. package/src/__tests__/scheduler-durable-v2.test.ts +0 -288
  74. package/src/__tests__/scheduler-durable.test.ts +0 -173
  75. package/src/__tests__/scheduler-exec.test.ts +0 -328
  76. package/src/__tests__/scheduler.test.ts +0 -187
  77. package/src/__tests__/storage.test.ts +0 -334
  78. package/src/__tests__/tsconfig.json +0 -8
  79. package/src/__tests__/validator.test.ts +0 -323
  80. package/src/__tests__/workflow.test.ts +0 -606
  81. package/src/__tests__/ws-integration.test.ts +0 -309
  82. package/src/__tests__/ws-scale.test.ts +0 -241
  83. package/src/auth.ts +0 -155
@@ -0,0 +1,65 @@
1
+ export type DocumentVisibility = "private" | "shared" | "public";
2
+ export type DocumentConvertMode = "auto" | "text-only" | "no-external-provider" | "prefer-external" | "force-external" | "force-ocr";
3
+ export type DocumentConvertProvider = "auto" | "local_text" | "gemini" | "openai" | "ocr" | "custom_vlm";
4
+ export type DocumentResolvedProvider = Exclude<DocumentConvertProvider, "auto">;
5
+ export type DocumentProviderRoute = "local_text" | "vlm" | "ocr_fallback";
6
+ export type DocumentCacheArtifact = "convert" | "embedding" | "summary" | "rerank";
7
+ export type DocumentConvertInput = {
8
+ storageId: string;
9
+ filename?: string;
10
+ mimeType?: string;
11
+ corpus: string;
12
+ visibility: DocumentVisibility;
13
+ ownerUserId?: string;
14
+ mode?: DocumentConvertMode;
15
+ provider?: DocumentConvertProvider;
16
+ };
17
+ export type DocumentPage = {
18
+ page: number;
19
+ charStart: number;
20
+ charEnd: number;
21
+ previewText?: string;
22
+ };
23
+ export type DocumentSection = {
24
+ id: string;
25
+ title?: string;
26
+ depth: number;
27
+ path: string[];
28
+ pageStart?: number;
29
+ pageEnd?: number;
30
+ charStart: number;
31
+ charEnd: number;
32
+ };
33
+ export type DocumentProviderTrace = {
34
+ provider: DocumentResolvedProvider;
35
+ route: DocumentProviderRoute;
36
+ external: boolean;
37
+ requestId?: string;
38
+ durationMs: number;
39
+ bytes: number;
40
+ };
41
+ export type DocumentConvertResult = {
42
+ text: string;
43
+ markdown: string;
44
+ pages: DocumentPage[];
45
+ sections: DocumentSection[];
46
+ warnings: string[];
47
+ providerTrace: DocumentProviderTrace;
48
+ };
49
+ export interface GencowServicesCtx {
50
+ }
51
+ export interface WorkflowDocumentServicesCtx {
52
+ document: {
53
+ convert(input: DocumentConvertInput): Promise<DocumentConvertResult>;
54
+ };
55
+ }
56
+ export type DocumentCacheKeyInput = {
57
+ appId: string;
58
+ ownerUserId?: string | null;
59
+ corpus: string;
60
+ sourceKey: string;
61
+ checksum: string;
62
+ provider: DocumentResolvedProvider;
63
+ artifact: DocumentCacheArtifact;
64
+ };
65
+ export declare function buildDocumentCacheKey(input: DocumentCacheKeyInput): string;
@@ -0,0 +1,15 @@
1
+ function normalizeCachePart(value) {
2
+ return value.trim() || "unknown";
3
+ }
4
+ export function buildDocumentCacheKey(input) {
5
+ const owner = input.ownerUserId?.trim() ? input.ownerUserId.trim() : "shared";
6
+ return [
7
+ `app:${normalizeCachePart(input.appId)}`,
8
+ `user:${normalizeCachePart(owner)}`,
9
+ `corpus:${normalizeCachePart(input.corpus)}`,
10
+ `source:${normalizeCachePart(input.sourceKey)}`,
11
+ `checksum:${normalizeCachePart(input.checksum)}`,
12
+ `provider:${normalizeCachePart(input.provider)}`,
13
+ `artifact:${normalizeCachePart(input.artifact)}`,
14
+ ].join(":");
15
+ }
@@ -0,0 +1,62 @@
1
+ import type { SearchFilter, SearchScope } from "./search-types.js";
2
+ export type CitationCoverage = "direct" | "partial" | "context";
3
+ export type ClaimSupportStatus = "supported" | "partially_supported" | "insufficient_evidence";
4
+ export type GroundedAnswerMode = "qa" | "compare" | "topic";
5
+ export type Citation = {
6
+ sourceId: string;
7
+ sourceTitle: string;
8
+ sectionId?: string;
9
+ sectionPath?: string[];
10
+ pageStart?: number;
11
+ pageEnd?: number;
12
+ chunkIds: string[];
13
+ snippet: string;
14
+ coverage: CitationCoverage;
15
+ confidence: number;
16
+ };
17
+ export type ClaimEvidenceMap = {
18
+ claimId: string;
19
+ claimText: string;
20
+ status: ClaimSupportStatus;
21
+ citations: Citation[];
22
+ missingEvidenceReasons?: string[];
23
+ };
24
+ export type GroundedAnswer = {
25
+ answer: string;
26
+ claims: ClaimEvidenceMap[];
27
+ citations: Citation[];
28
+ warnings: string[];
29
+ grounded: boolean;
30
+ };
31
+ export type GroundingBudget = {
32
+ maxVerifyLoops: number;
33
+ maxResearchQueriesPerLoop: number;
34
+ maxCitationsPerClaim: number;
35
+ maxClaimsPerAnswer: number;
36
+ };
37
+ export declare const DEFAULT_GROUNDING_BUDGET: GroundingBudget;
38
+ export type GroundedClaimInput = {
39
+ claimId?: string;
40
+ claimText: string;
41
+ requiredTerms?: string[];
42
+ };
43
+ export type GroundedCompareInput = {
44
+ left: string;
45
+ right: string;
46
+ };
47
+ export type GroundedTopicInput = {
48
+ minDistinctSections?: number;
49
+ };
50
+ export type GroundedAnswerInput = {
51
+ question: string;
52
+ scope: SearchScope;
53
+ filters?: SearchFilter;
54
+ claims?: GroundedClaimInput[];
55
+ mode?: GroundedAnswerMode;
56
+ compare?: GroundedCompareInput;
57
+ topic?: GroundedTopicInput;
58
+ budget?: Partial<GroundingBudget>;
59
+ };
60
+ export type GroundingRuntime = {
61
+ answer(input: GroundedAnswerInput): Promise<GroundedAnswer>;
62
+ };
@@ -0,0 +1,6 @@
1
+ export const DEFAULT_GROUNDING_BUDGET = {
2
+ maxVerifyLoops: 2,
3
+ maxResearchQueriesPerLoop: 3,
4
+ maxCitationsPerClaim: 3,
5
+ maxClaimsPerAnswer: 12,
6
+ };
package/dist/index.d.ts CHANGED
@@ -5,8 +5,16 @@
5
5
  * All with Convex-compatible DX patterns.
6
6
  */
7
7
  export type { GencowCtx, AuthCtx, UserIdentity, QueryDef, MutationDef, RealtimeCtx, HttpActionDef, HttpActionRequest, HttpActionResponse, HttpActionHandler, AIContext, AIMessage, AIResult, } from "./reactive.js";
8
+ export type { SearchPrimitive, SearchScope, SearchFilter, SearchOptions, VectorSearchOptions, HybridSearchOptions, SearchHit, SearchResponse, SearchTierConfig, } from "./search-types.js";
9
+ export type { DocumentVisibility, DocumentConvertMode, DocumentConvertProvider, DocumentResolvedProvider, DocumentConvertInput, DocumentPage, DocumentSection, DocumentProviderTrace, DocumentConvertResult, DocumentCacheArtifact, DocumentCacheKeyInput, GencowServicesCtx, WorkflowDocumentServicesCtx, } from "./document-types.js";
10
+ export { buildDocumentCacheKey } from "./document-types.js";
11
+ export type { RagIngestReindexMode, RagIngestInput, RagIngestWorkflowArgs, RagIngestStartResult, RagIngestJobStatus, RagIngestJobRecord, } from "./rag-ingest-types.js";
12
+ export type { CitationCoverage, ClaimSupportStatus, GroundedAnswerMode, Citation, ClaimEvidenceMap, GroundedAnswer, GroundingBudget, GroundedClaimInput, GroundedCompareInput, GroundedTopicInput, GroundedAnswerInput, GroundingRuntime, } from "./grounded-answer-types.js";
13
+ export { DEFAULT_GROUNDING_BUDGET } from "./grounded-answer-types.js";
14
+ export type { RagOperationKind, RagOperationMetricUnit, RagIndexHealth, RagOperationMetric, RagOperationsSummary, RagEvaluationExpectedClaim, RagEvaluationFixture, RagEvaluationFixtureResult, RagEvaluationRunResult, RagReindexMode, RagReindexPlan, } from "./rag-operations-types.js";
15
+ export { ragCorpora, ragSources, ragSections, ragChunks, ragIngestJobs, ragOperationMetrics } from "./rag-schema.js";
8
16
  export { query, mutation, httpAction, buildRealtimeCtx, subscribe, unsubscribe, registerClient, deregisterClient, handleWsMessage, getQueryHandler, getQueryDef, getRegisteredQueries, getRegisteredMutations, getRegisteredHttpActions, } from "./reactive.js";
9
- export type { Storage } from "./storage.js";
17
+ export type { Storage, StoredFile } from "./storage.js";
10
18
  export { createScheduler, getSchedulerInfo } from "./scheduler.js";
11
19
  export type { Scheduler, ScheduleOptions, FailedJob, CreateSchedulerOptions, ScheduledJobRecord, } from "./scheduler.js";
12
20
  export { workflow, getWorkflowDef, getRegisteredWorkflows, getWorkflowResumeActionName, getWorkflowRealtimeKey, createWorkflowRealtimeToken, serializeWorkflowValue, deserializeWorkflowValue, parseWorkflowDurationMs, DEFAULT_WORKFLOW_MAX_DURATION_MS, DEFAULT_WORKFLOW_MAX_RETRIES, WORKFLOW_RESUME_ACTION_PREFIX, WORKFLOW_REALTIME_KEY_PREFIX, } from "./workflow.js";
@@ -17,6 +25,7 @@ export { v, parseArgs, GencowValidationError } from "./v.js";
17
25
  export type { Validator, Infer, InferArgs } from "./v.js";
18
26
  export { withRetry } from "./retry.js";
19
27
  export type { RetryOptions } from "./retry.js";
28
+ export { filterTenantRuntimeEnvVars, isReservedTenantRuntimeEnvKey } from "./runtime-env-policy.js";
20
29
  export { cronJobs } from "./crons.js";
21
30
  export type { CronJobsBuilder, CronJobDef, IntervalOptions, DailyOptions, WeeklyOptions } from "./crons.js";
22
31
  export { defineAuth } from "./auth-config.js";
package/dist/index.js CHANGED
@@ -4,6 +4,9 @@
4
4
  * Provides: query, mutation, storage, scheduler, auth
5
5
  * All with Convex-compatible DX patterns.
6
6
  */
7
+ export { buildDocumentCacheKey } from "./document-types.js";
8
+ export { DEFAULT_GROUNDING_BUDGET } from "./grounded-answer-types.js";
9
+ export { ragCorpora, ragSources, ragSections, ragChunks, ragIngestJobs, ragOperationMetrics } from "./rag-schema.js";
7
10
  export { query, mutation, httpAction, buildRealtimeCtx, subscribe, unsubscribe, registerClient, deregisterClient, handleWsMessage, getQueryHandler, getQueryDef, getRegisteredQueries, getRegisteredMutations, getRegisteredHttpActions, } from "./reactive.js";
8
11
  export { createScheduler, getSchedulerInfo } from "./scheduler.js";
9
12
  export { workflow, getWorkflowDef, getRegisteredWorkflows, getWorkflowResumeActionName, getWorkflowRealtimeKey, createWorkflowRealtimeToken, serializeWorkflowValue, deserializeWorkflowValue, parseWorkflowDurationMs, DEFAULT_WORKFLOW_MAX_DURATION_MS, DEFAULT_WORKFLOW_MAX_RETRIES, WORKFLOW_RESUME_ACTION_PREFIX, WORKFLOW_REALTIME_KEY_PREFIX, } from "./workflow.js";
@@ -11,6 +14,7 @@ export { deriveWorkflowStatus } from "./workflow-types.js";
11
14
  export { loadWorkflowSnapshot } from "./workflows-api.js";
12
15
  export { v, parseArgs, GencowValidationError } from "./v.js";
13
16
  export { withRetry } from "./retry.js";
17
+ export { filterTenantRuntimeEnvVars, isReservedTenantRuntimeEnvKey } from "./runtime-env-policy.js";
14
18
  export { cronJobs } from "./crons.js";
15
19
  export { defineAuth } from "./auth-config.js";
16
20
  // ─── RLS + CRUD Factory ───────────
@@ -0,0 +1,39 @@
1
+ import type { DocumentConvertProvider, DocumentConvertMode, DocumentProviderTrace, DocumentVisibility } from "./document-types.js";
2
+ export type RagIngestReindexMode = "if_changed" | "force";
3
+ export type RagIngestJobStatus = "queued" | "converting" | "chunking" | "embedding" | "upserting" | "completed" | "failed" | "canceled";
4
+ export type RagIngestInput = {
5
+ storageId: string;
6
+ corpus: string;
7
+ visibility: DocumentVisibility;
8
+ ownerUserId?: string;
9
+ sourceKey?: string;
10
+ metadata?: Record<string, unknown>;
11
+ reindexMode?: RagIngestReindexMode;
12
+ mode?: DocumentConvertMode;
13
+ provider?: DocumentConvertProvider;
14
+ };
15
+ export type RagIngestWorkflowArgs = RagIngestInput & {
16
+ jobId: string;
17
+ sourceId: string;
18
+ };
19
+ export type RagIngestStartResult = {
20
+ workflowId: string;
21
+ jobId: string;
22
+ sourceId: string;
23
+ status: "queued";
24
+ };
25
+ export type RagIngestJobRecord = {
26
+ id: string;
27
+ workflowId: string;
28
+ sourceId: string;
29
+ corpus: string;
30
+ visibility: DocumentVisibility;
31
+ ownerUserId: string | null;
32
+ status: RagIngestJobStatus;
33
+ stage: string;
34
+ providerTrace: Partial<DocumentProviderTrace> | Record<string, never>;
35
+ metrics: Record<string, unknown>;
36
+ error: string | null;
37
+ startedAt: string;
38
+ completedAt: string | null;
39
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,81 @@
1
+ import type { SearchScope } from "./search-types.js";
2
+ export type RagOperationKind = "ingest" | "retrieve" | "answer" | "reindex" | "evaluate";
3
+ export type RagOperationMetricUnit = "ms" | "count" | "tokens" | "usd";
4
+ export type RagIndexHealth = "ready" | "empty" | "degraded" | "failed";
5
+ export type RagOperationMetric = {
6
+ id: string;
7
+ appId: string;
8
+ corpus: string;
9
+ visibility: SearchScope["visibility"];
10
+ ownerUserId: string | null;
11
+ operation: RagOperationKind;
12
+ jobId: string | null;
13
+ workflowId: string | null;
14
+ sourceId: string | null;
15
+ metricName: string;
16
+ metricValue: number;
17
+ unit: RagOperationMetricUnit | null;
18
+ metadata: Record<string, unknown>;
19
+ recordedAt: string;
20
+ };
21
+ export type RagOperationsSummary = {
22
+ corpus: string;
23
+ visibility: SearchScope["visibility"];
24
+ ownerUserId: string | null;
25
+ sourceCount: number;
26
+ sectionCount: number;
27
+ chunkCount: number;
28
+ jobCounts: Record<string, number>;
29
+ latestJob: {
30
+ id: string;
31
+ status: string;
32
+ stage: string;
33
+ updatedAt: string;
34
+ } | null;
35
+ recentMetricCounts: Record<string, number>;
36
+ averageLatencyMs: number | null;
37
+ indexHealth: RagIndexHealth;
38
+ };
39
+ export type RagEvaluationExpectedClaim = {
40
+ claim: string;
41
+ verdict: "supported" | "partial" | "unsupported";
42
+ };
43
+ export type RagEvaluationFixture = {
44
+ name: string;
45
+ scope: SearchScope;
46
+ query: string;
47
+ expectedSourceIds?: string[];
48
+ expectedCitationCountMin?: number;
49
+ expectedClaims?: RagEvaluationExpectedClaim[];
50
+ };
51
+ export type RagEvaluationFixtureResult = {
52
+ name: string;
53
+ ok: boolean;
54
+ failures: string[];
55
+ matchedSourceIds: string[];
56
+ citationCount: number;
57
+ claimStatuses: Array<{
58
+ claim: string;
59
+ expected: RagEvaluationExpectedClaim["verdict"];
60
+ actual: string | null;
61
+ }>;
62
+ };
63
+ export type RagEvaluationRunResult = {
64
+ ok: boolean;
65
+ total: number;
66
+ passed: number;
67
+ failed: number;
68
+ results: RagEvaluationFixtureResult[];
69
+ };
70
+ export type RagReindexMode = "source-changed" | "section-changed" | "corpus-policy-changed" | "full-rebuild";
71
+ export type RagReindexPlan = {
72
+ corpus: string;
73
+ visibility: SearchScope["visibility"];
74
+ ownerUserId: string | null;
75
+ mode: RagReindexMode;
76
+ reason: string;
77
+ sourceIds: string[];
78
+ sourceCount: number;
79
+ estimatedChunkCount: number;
80
+ requiresConfirmation: boolean;
81
+ };
@@ -0,0 +1 @@
1
+ export {};