ai-database 2.1.1 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +47 -1
- package/README.md +1063 -186
- package/dist/actions.d.ts +2 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +1 -1
- package/dist/actions.js.map +1 -1
- package/dist/ai-promise-db.d.ts +52 -23
- package/dist/ai-promise-db.d.ts.map +1 -1
- package/dist/ai-promise-db.js +185 -164
- package/dist/ai-promise-db.js.map +1 -1
- package/dist/authorization.d.ts.map +1 -1
- package/dist/authorization.js +38 -30
- package/dist/authorization.js.map +1 -1
- package/dist/cascade-orchestrator.d.ts +404 -0
- package/dist/cascade-orchestrator.d.ts.map +1 -0
- package/dist/cascade-orchestrator.js +828 -0
- package/dist/cascade-orchestrator.js.map +1 -0
- package/dist/cascade-write-strategy.d.ts +584 -0
- package/dist/cascade-write-strategy.d.ts.map +1 -0
- package/dist/cascade-write-strategy.js +590 -0
- package/dist/cascade-write-strategy.js.map +1 -0
- package/dist/ch-adapter.d.ts +358 -0
- package/dist/ch-adapter.d.ts.map +1 -0
- package/dist/ch-adapter.js +929 -0
- package/dist/ch-adapter.js.map +1 -0
- package/dist/client/index.d.ts +42 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +43 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client.d.ts +266 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +81 -0
- package/dist/client.js.map +1 -0
- package/dist/constants.d.ts +64 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +52 -2
- package/dist/constants.js.map +1 -1
- package/dist/dataloader.d.ts +99 -0
- package/dist/dataloader.d.ts.map +1 -0
- package/dist/dataloader.js +225 -0
- package/dist/dataloader.js.map +1 -0
- package/dist/db-provider-port.d.ts +501 -0
- package/dist/db-provider-port.d.ts.map +1 -0
- package/dist/db-provider-port.js +113 -0
- package/dist/db-provider-port.js.map +1 -0
- package/dist/digital-objects-provider.d.ts +49 -0
- package/dist/digital-objects-provider.d.ts.map +1 -0
- package/dist/digital-objects-provider.js +55 -0
- package/dist/digital-objects-provider.js.map +1 -0
- package/dist/do-sqlite-adapter.d.ts +402 -0
- package/dist/do-sqlite-adapter.d.ts.map +1 -0
- package/dist/do-sqlite-adapter.js +745 -0
- package/dist/do-sqlite-adapter.js.map +1 -0
- package/dist/docs-rels/custom-types.d.ts +134 -0
- package/dist/docs-rels/custom-types.d.ts.map +1 -0
- package/dist/docs-rels/custom-types.js +70 -0
- package/dist/docs-rels/custom-types.js.map +1 -0
- package/dist/docs-rels/index.d.ts +16 -0
- package/dist/docs-rels/index.d.ts.map +1 -0
- package/dist/docs-rels/index.js +16 -0
- package/dist/docs-rels/index.js.map +1 -0
- package/dist/docs-rels/migrations/index.d.ts +30 -0
- package/dist/docs-rels/migrations/index.d.ts.map +1 -0
- package/dist/docs-rels/migrations/index.js +128 -0
- package/dist/docs-rels/migrations/index.js.map +1 -0
- package/dist/docs-rels/schema.d.ts +2961 -0
- package/dist/docs-rels/schema.d.ts.map +1 -0
- package/dist/docs-rels/schema.js +244 -0
- package/dist/docs-rels/schema.js.map +1 -0
- package/dist/durable-clickhouse.d.ts.map +1 -1
- package/dist/durable-clickhouse.js +16 -13
- package/dist/durable-clickhouse.js.map +1 -1
- package/dist/durable-promise.d.ts.map +1 -1
- package/dist/durable-promise.js +34 -15
- package/dist/durable-promise.js.map +1 -1
- package/dist/errors.d.ts +127 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +210 -0
- package/dist/errors.js.map +1 -0
- package/dist/eventbridge.d.ts +117 -0
- package/dist/eventbridge.d.ts.map +1 -0
- package/dist/eventbridge.js +238 -0
- package/dist/eventbridge.js.map +1 -0
- package/dist/events.d.ts +2 -2
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +1 -1
- package/dist/events.js.map +1 -1
- package/dist/execution-queue.d.ts.map +1 -1
- package/dist/execution-queue.js +4 -5
- package/dist/execution-queue.js.map +1 -1
- package/dist/index.d.ts +37 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +112 -6
- package/dist/index.js.map +1 -1
- package/dist/linguistic.d.ts +3 -108
- package/dist/linguistic.d.ts.map +1 -1
- package/dist/linguistic.js +3 -372
- package/dist/linguistic.js.map +1 -1
- package/dist/logger.d.ts +132 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +137 -0
- package/dist/logger.js.map +1 -0
- package/dist/memory-provider.d.ts +129 -0
- package/dist/memory-provider.d.ts.map +1 -1
- package/dist/memory-provider.js +592 -257
- package/dist/memory-provider.js.map +1 -1
- package/dist/pg-adapter.d.ts +424 -0
- package/dist/pg-adapter.d.ts.map +1 -0
- package/dist/pg-adapter.js +921 -0
- package/dist/pg-adapter.js.map +1 -0
- package/dist/pipelines-iceberg-emitter.d.ts +327 -0
- package/dist/pipelines-iceberg-emitter.d.ts.map +1 -0
- package/dist/pipelines-iceberg-emitter.js +351 -0
- package/dist/pipelines-iceberg-emitter.js.map +1 -0
- package/dist/provider-capabilities.d.ts +146 -0
- package/dist/provider-capabilities.d.ts.map +1 -0
- package/dist/provider-capabilities.js +214 -0
- package/dist/provider-capabilities.js.map +1 -0
- package/dist/rdb-provider-adapter.d.ts +195 -0
- package/dist/rdb-provider-adapter.d.ts.map +1 -0
- package/dist/rdb-provider-adapter.js +291 -0
- package/dist/rdb-provider-adapter.js.map +1 -0
- package/dist/schema/cascade.d.ts +49 -10
- package/dist/schema/cascade.d.ts.map +1 -1
- package/dist/schema/cascade.js +491 -273
- package/dist/schema/cascade.js.map +1 -1
- package/dist/schema/definition-caches.d.ts +24 -0
- package/dist/schema/definition-caches.d.ts.map +1 -0
- package/dist/schema/definition-caches.js +26 -0
- package/dist/schema/definition-caches.js.map +1 -0
- package/dist/schema/dependency-graph.d.ts +45 -0
- package/dist/schema/dependency-graph.d.ts.map +1 -0
- package/dist/schema/dependency-graph.js +47 -0
- package/dist/schema/dependency-graph.js.map +1 -0
- package/dist/schema/diff.d.ts +103 -0
- package/dist/schema/diff.d.ts.map +1 -0
- package/dist/schema/diff.js +329 -0
- package/dist/schema/diff.js.map +1 -0
- package/dist/schema/entity-operations.d.ts +99 -0
- package/dist/schema/entity-operations.d.ts.map +1 -0
- package/dist/schema/entity-operations.js +818 -0
- package/dist/schema/entity-operations.js.map +1 -0
- package/dist/schema/generation-context.d.ts +202 -0
- package/dist/schema/generation-context.d.ts.map +1 -0
- package/dist/schema/generation-context.js +393 -0
- package/dist/schema/generation-context.js.map +1 -0
- package/dist/schema/index.d.ts +32 -34
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +462 -519
- package/dist/schema/index.js.map +1 -1
- package/dist/schema/migration.d.ts +205 -0
- package/dist/schema/migration.d.ts.map +1 -0
- package/dist/schema/migration.js +327 -0
- package/dist/schema/migration.js.map +1 -0
- package/dist/schema/nl-query-generator.d.ts +68 -0
- package/dist/schema/nl-query-generator.d.ts.map +1 -0
- package/dist/schema/nl-query-generator.js +362 -0
- package/dist/schema/nl-query-generator.js.map +1 -0
- package/dist/schema/nl-query.d.ts +65 -0
- package/dist/schema/nl-query.d.ts.map +1 -0
- package/dist/schema/nl-query.js +178 -0
- package/dist/schema/nl-query.js.map +1 -0
- package/dist/schema/parse.d.ts.map +1 -1
- package/dist/schema/parse.js +152 -89
- package/dist/schema/parse.js.map +1 -1
- package/dist/schema/provider.d.ts +38 -0
- package/dist/schema/provider.d.ts.map +1 -1
- package/dist/schema/provider.js +15 -7
- package/dist/schema/provider.js.map +1 -1
- package/dist/schema/resolve.d.ts +46 -5
- package/dist/schema/resolve.d.ts.map +1 -1
- package/dist/schema/resolve.js +334 -117
- package/dist/schema/resolve.js.map +1 -1
- package/dist/schema/search-utils.d.ts +76 -0
- package/dist/schema/search-utils.d.ts.map +1 -0
- package/dist/schema/search-utils.js +86 -0
- package/dist/schema/search-utils.js.map +1 -0
- package/dist/schema/seed.d.ts +53 -0
- package/dist/schema/seed.d.ts.map +1 -0
- package/dist/schema/seed.js +94 -0
- package/dist/schema/seed.js.map +1 -0
- package/dist/schema/semantic.d.ts +11 -0
- package/dist/schema/semantic.d.ts.map +1 -1
- package/dist/schema/semantic.js +262 -68
- package/dist/schema/semantic.js.map +1 -1
- package/dist/schema/sub-apis.d.ts +52 -0
- package/dist/schema/sub-apis.d.ts.map +1 -0
- package/dist/schema/sub-apis.js +216 -0
- package/dist/schema/sub-apis.js.map +1 -0
- package/dist/schema/system-entities.d.ts +42 -0
- package/dist/schema/system-entities.d.ts.map +1 -0
- package/dist/schema/system-entities.js +101 -0
- package/dist/schema/system-entities.js.map +1 -0
- package/dist/schema/types.d.ts +91 -9
- package/dist/schema/types.d.ts.map +1 -1
- package/dist/schema/union-fallback.d.ts +219 -0
- package/dist/schema/union-fallback.d.ts.map +1 -0
- package/dist/schema/union-fallback.js +331 -0
- package/dist/schema/union-fallback.js.map +1 -0
- package/dist/schema/value-generators/ai.d.ts +54 -0
- package/dist/schema/value-generators/ai.d.ts.map +1 -0
- package/dist/schema/value-generators/ai.js +136 -0
- package/dist/schema/value-generators/ai.js.map +1 -0
- package/dist/schema/value-generators/index.d.ts +126 -0
- package/dist/schema/value-generators/index.d.ts.map +1 -0
- package/dist/schema/value-generators/index.js +219 -0
- package/dist/schema/value-generators/index.js.map +1 -0
- package/dist/schema/value-generators/placeholder.d.ts +52 -0
- package/dist/schema/value-generators/placeholder.d.ts.map +1 -0
- package/dist/schema/value-generators/placeholder.js +328 -0
- package/dist/schema/value-generators/placeholder.js.map +1 -0
- package/dist/schema/value-generators/types.d.ts +116 -0
- package/dist/schema/value-generators/types.d.ts.map +1 -0
- package/dist/schema/value-generators/types.js +11 -0
- package/dist/schema/value-generators/types.js.map +1 -0
- package/dist/schema/verb-derivation.d.ts +167 -0
- package/dist/schema/verb-derivation.d.ts.map +1 -0
- package/dist/schema/verb-derivation.js +281 -0
- package/dist/schema/verb-derivation.js.map +1 -0
- package/dist/schema/version.d.ts +111 -0
- package/dist/schema/version.d.ts.map +1 -0
- package/dist/schema/version.js +190 -0
- package/dist/schema/version.js.map +1 -0
- package/dist/schema.d.ts +1095 -23
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +2854 -38
- package/dist/schema.js.map +1 -1
- package/dist/semantic-vectors.d.ts +39 -0
- package/dist/semantic-vectors.d.ts.map +1 -0
- package/dist/semantic-vectors.js +334 -0
- package/dist/semantic-vectors.js.map +1 -0
- package/dist/semantic.d.ts +29 -1
- package/dist/semantic.d.ts.map +1 -1
- package/dist/semantic.js +26 -16
- package/dist/semantic.js.map +1 -1
- package/dist/telemetry.d.ts +128 -0
- package/dist/telemetry.d.ts.map +1 -0
- package/dist/telemetry.js +305 -0
- package/dist/telemetry.js.map +1 -0
- package/dist/tests.d.ts.map +1 -1
- package/dist/tests.js +30 -22
- package/dist/tests.js.map +1 -1
- package/dist/type-guards.d.ts +212 -0
- package/dist/type-guards.d.ts.map +1 -0
- package/dist/type-guards.js +318 -0
- package/dist/type-guards.js.map +1 -0
- package/dist/types.d.ts +33 -245
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +62 -72
- package/dist/types.js.map +1 -1
- package/dist/validation.d.ts +165 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +639 -0
- package/dist/validation.js.map +1 -0
- package/dist/worker/db-provider.d.ts +168 -0
- package/dist/worker/db-provider.d.ts.map +1 -0
- package/dist/worker/db-provider.js +277 -0
- package/dist/worker/db-provider.js.map +1 -0
- package/dist/worker/index.d.ts +35 -0
- package/dist/worker/index.d.ts.map +1 -0
- package/dist/worker/index.js +37 -0
- package/dist/worker/index.js.map +1 -0
- package/dist/worker.d.ts +779 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +2786 -0
- package/dist/worker.js.map +1 -0
- package/package.json +38 -8
- package/src/docs-rels/migrations/0001-init.sql +125 -0
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Union Type Fallback Search
|
|
3
|
+
*
|
|
4
|
+
* Implements fallback search behavior for union types in backward fuzzy (<~) operators.
|
|
5
|
+
* When searching `<~Type1|Type2|Type3`, searches types in order and falls back to
|
|
6
|
+
* the next type if no match is found or threshold not met.
|
|
7
|
+
*
|
|
8
|
+
* Supports two search modes:
|
|
9
|
+
* - `ordered`: Search types sequentially, stop on first match (default)
|
|
10
|
+
* - `parallel`: Search all types concurrently, return best match
|
|
11
|
+
*
|
|
12
|
+
* @packageDocumentation
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Match result from a union type search
|
|
16
|
+
*/
|
|
17
|
+
export interface UnionMatch {
|
|
18
|
+
/** Unique identifier of the matched entity */
|
|
19
|
+
$id: string;
|
|
20
|
+
/** Similarity score (0-1) */
|
|
21
|
+
$score: number;
|
|
22
|
+
/** Type that was matched */
|
|
23
|
+
$type: string;
|
|
24
|
+
/** Additional match data */
|
|
25
|
+
[key: string]: unknown;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Error that occurred during search
|
|
29
|
+
*/
|
|
30
|
+
export interface SearchError {
|
|
31
|
+
/** Type that failed to search */
|
|
32
|
+
type: string;
|
|
33
|
+
/** Error message */
|
|
34
|
+
message: string;
|
|
35
|
+
/** Original error */
|
|
36
|
+
error?: Error;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Result of a union type search operation
|
|
40
|
+
*/
|
|
41
|
+
export interface UnionSearchResult {
|
|
42
|
+
/** Matches found (empty array if no matches) */
|
|
43
|
+
matches: UnionMatch[];
|
|
44
|
+
/** Types that were searched */
|
|
45
|
+
searchedTypes: string[];
|
|
46
|
+
/** Order in which types were searched */
|
|
47
|
+
searchOrder: string[];
|
|
48
|
+
/** Whether fallback was triggered (searched more than first type) */
|
|
49
|
+
fallbackTriggered: boolean;
|
|
50
|
+
/** Whether all types were exhausted without finding a match */
|
|
51
|
+
allTypesExhausted: boolean;
|
|
52
|
+
/** The type that matched (first match in ordered mode, best in parallel) */
|
|
53
|
+
matchedType?: string;
|
|
54
|
+
/** Overall confidence score (highest match score) */
|
|
55
|
+
confidence?: number;
|
|
56
|
+
/** Matches that were below threshold (for debugging) */
|
|
57
|
+
belowThresholdMatches?: UnionMatch[];
|
|
58
|
+
/** Errors that occurred during search */
|
|
59
|
+
errors?: SearchError[];
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Searcher function type for searching a single type
|
|
63
|
+
*/
|
|
64
|
+
export type UnionSearcher = (type: string, query: string, options?: {
|
|
65
|
+
threshold?: number;
|
|
66
|
+
limit?: number;
|
|
67
|
+
}) => Promise<UnionMatch[]>;
|
|
68
|
+
/**
|
|
69
|
+
* Options for union type fallback search
|
|
70
|
+
*/
|
|
71
|
+
export interface FallbackSearchOptions {
|
|
72
|
+
/**
|
|
73
|
+
* Search mode:
|
|
74
|
+
* - `ordered`: Search types sequentially, stop on first match above threshold
|
|
75
|
+
* - `parallel`: Search all types concurrently, return best match(es)
|
|
76
|
+
*/
|
|
77
|
+
mode: 'ordered' | 'parallel';
|
|
78
|
+
/**
|
|
79
|
+
* Global similarity threshold (0-1)
|
|
80
|
+
* Matches below this threshold are ignored (unless includeBelowThreshold is true)
|
|
81
|
+
*/
|
|
82
|
+
threshold?: number;
|
|
83
|
+
/**
|
|
84
|
+
* Per-type thresholds
|
|
85
|
+
* Overrides the global threshold for specific types
|
|
86
|
+
*/
|
|
87
|
+
thresholds?: Record<string, number>;
|
|
88
|
+
/**
|
|
89
|
+
* Searcher function to perform the actual search
|
|
90
|
+
* Called with (type, query, options) for each type being searched
|
|
91
|
+
*/
|
|
92
|
+
searcher: UnionSearcher;
|
|
93
|
+
/**
|
|
94
|
+
* In parallel mode, return all matches sorted by score (default: false, return only best)
|
|
95
|
+
*/
|
|
96
|
+
returnAll?: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Include matches below threshold in result for debugging (stored in belowThresholdMatches)
|
|
99
|
+
*/
|
|
100
|
+
includeBelowThreshold?: boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Error handling mode:
|
|
103
|
+
* - `throw`: Throw on first error (default in ordered mode)
|
|
104
|
+
* - `continue`: Continue searching remaining types on error
|
|
105
|
+
*/
|
|
106
|
+
onError?: 'throw' | 'continue';
|
|
107
|
+
/**
|
|
108
|
+
* Maximum number of results to return per type
|
|
109
|
+
*/
|
|
110
|
+
limit?: number;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Parse union type string into array of individual types
|
|
114
|
+
*
|
|
115
|
+
* Handles various formats:
|
|
116
|
+
* - `Type1|Type2|Type3` - Standard pipe-separated union
|
|
117
|
+
* - `Type1 | Type2 | Type3` - With spaces around pipes
|
|
118
|
+
* - `Type1|Type2(0.8)|Type3` - With threshold syntax (stripped from result)
|
|
119
|
+
*
|
|
120
|
+
* @param typeSpec - The union type specification string
|
|
121
|
+
* @returns Array of individual type names in declaration order
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```ts
|
|
125
|
+
* parseUnionTypes('Document|Video|Expert')
|
|
126
|
+
* // => ['Document', 'Video', 'Expert']
|
|
127
|
+
*
|
|
128
|
+
* parseUnionTypes('Type1 | Type2(0.8) | Type3')
|
|
129
|
+
* // => ['Type1', 'Type2', 'Type3']
|
|
130
|
+
*
|
|
131
|
+
* parseUnionTypes('SingleType')
|
|
132
|
+
* // => ['SingleType']
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
export declare function parseUnionTypes(typeSpec: string): string[];
|
|
136
|
+
/**
|
|
137
|
+
* Parse per-type thresholds from union type specification
|
|
138
|
+
*
|
|
139
|
+
* Extracts threshold values from syntax like `Type1|Type2(0.8)|Type3(0.6)`
|
|
140
|
+
*
|
|
141
|
+
* @param typeSpec - The union type specification string
|
|
142
|
+
* @returns Record mapping type names to their thresholds
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts
|
|
146
|
+
* parseUnionThresholds('Type1|Type2(0.8)|Type3(0.6)')
|
|
147
|
+
* // => { Type2: 0.8, Type3: 0.6 }
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
export declare function parseUnionThresholds(typeSpec: string): Record<string, number>;
|
|
151
|
+
/**
|
|
152
|
+
* Search union types with fallback behavior
|
|
153
|
+
*
|
|
154
|
+
* Searches multiple types either sequentially (ordered) or concurrently (parallel),
|
|
155
|
+
* with support for per-type thresholds and graceful error handling.
|
|
156
|
+
*
|
|
157
|
+
* @param types - Array of type names to search (in priority order)
|
|
158
|
+
* @param query - The search query
|
|
159
|
+
* @param options - Search options including mode, thresholds, and searcher
|
|
160
|
+
* @returns Search result with matches and metadata
|
|
161
|
+
*
|
|
162
|
+
* @example Ordered mode (stops on first match)
|
|
163
|
+
* ```ts
|
|
164
|
+
* const result = await searchUnionTypes(
|
|
165
|
+
* ['Document', 'Video', 'Expert'],
|
|
166
|
+
* 'machine learning tutorial',
|
|
167
|
+
* {
|
|
168
|
+
* mode: 'ordered',
|
|
169
|
+
* threshold: 0.75,
|
|
170
|
+
* searcher: async (type, query) => {
|
|
171
|
+
* return provider.semanticSearch(type, query)
|
|
172
|
+
* }
|
|
173
|
+
* }
|
|
174
|
+
* )
|
|
175
|
+
* ```
|
|
176
|
+
*
|
|
177
|
+
* @example Parallel mode (searches all, returns best)
|
|
178
|
+
* ```ts
|
|
179
|
+
* const result = await searchUnionTypes(
|
|
180
|
+
* ['Document', 'Video', 'Expert'],
|
|
181
|
+
* 'machine learning tutorial',
|
|
182
|
+
* {
|
|
183
|
+
* mode: 'parallel',
|
|
184
|
+
* returnAll: true,
|
|
185
|
+
* searcher: async (type, query) => {
|
|
186
|
+
* return provider.semanticSearch(type, query)
|
|
187
|
+
* }
|
|
188
|
+
* }
|
|
189
|
+
* )
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
export declare function searchUnionTypes(types: readonly string[], query: string, options: FallbackSearchOptions): Promise<UnionSearchResult>;
|
|
193
|
+
/**
|
|
194
|
+
* Create a searcher function that wraps a semantic search provider
|
|
195
|
+
*
|
|
196
|
+
* @param provider - The database provider with semanticSearch method
|
|
197
|
+
* @returns A searcher function compatible with searchUnionTypes
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```ts
|
|
201
|
+
* const searcher = createProviderSearcher(provider)
|
|
202
|
+
* const result = await searchUnionTypes(
|
|
203
|
+
* ['Document', 'Video'],
|
|
204
|
+
* 'tutorial',
|
|
205
|
+
* { mode: 'ordered', searcher }
|
|
206
|
+
* )
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
export declare function createProviderSearcher(provider: {
|
|
210
|
+
semanticSearch: (type: string, query: string, options?: {
|
|
211
|
+
minScore?: number;
|
|
212
|
+
limit?: number;
|
|
213
|
+
}) => Promise<Array<{
|
|
214
|
+
$id: string;
|
|
215
|
+
$score: number;
|
|
216
|
+
[key: string]: unknown;
|
|
217
|
+
}>>;
|
|
218
|
+
}): UnionSearcher;
|
|
219
|
+
//# sourceMappingURL=union-fallback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"union-fallback.d.ts","sourceRoot":"","sources":["../../src/schema/union-fallback.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,8CAA8C;IAC9C,GAAG,EAAE,MAAM,CAAA;IACX,6BAA6B;IAC7B,MAAM,EAAE,MAAM,CAAA;IACd,4BAA4B;IAC5B,KAAK,EAAE,MAAM,CAAA;IACb,4BAA4B;IAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,iCAAiC;IACjC,IAAI,EAAE,MAAM,CAAA;IACZ,oBAAoB;IACpB,OAAO,EAAE,MAAM,CAAA;IACf,qBAAqB;IACrB,KAAK,CAAC,EAAE,KAAK,CAAA;CACd;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,gDAAg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AAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAoB1D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAmB7E;AAwCD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,iBAAiB,CAAC,CAyB5B;AAqJD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE;IAC/C,cAAc,EAAE,CACd,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,KAC5C,OAAO,CAAC,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC,CAAC,CAAA;CAC7E,GAAG,aAAa,CAahB"}
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Union Type Fallback Search
|
|
3
|
+
*
|
|
4
|
+
* Implements fallback search behavior for union types in backward fuzzy (<~) operators.
|
|
5
|
+
* When searching `<~Type1|Type2|Type3`, searches types in order and falls back to
|
|
6
|
+
* the next type if no match is found or threshold not met.
|
|
7
|
+
*
|
|
8
|
+
* Supports two search modes:
|
|
9
|
+
* - `ordered`: Search types sequentially, stop on first match (default)
|
|
10
|
+
* - `parallel`: Search all types concurrently, return best match
|
|
11
|
+
*
|
|
12
|
+
* @packageDocumentation
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Parse union type string into array of individual types
|
|
16
|
+
*
|
|
17
|
+
* Handles various formats:
|
|
18
|
+
* - `Type1|Type2|Type3` - Standard pipe-separated union
|
|
19
|
+
* - `Type1 | Type2 | Type3` - With spaces around pipes
|
|
20
|
+
* - `Type1|Type2(0.8)|Type3` - With threshold syntax (stripped from result)
|
|
21
|
+
*
|
|
22
|
+
* @param typeSpec - The union type specification string
|
|
23
|
+
* @returns Array of individual type names in declaration order
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* parseUnionTypes('Document|Video|Expert')
|
|
28
|
+
* // => ['Document', 'Video', 'Expert']
|
|
29
|
+
*
|
|
30
|
+
* parseUnionTypes('Type1 | Type2(0.8) | Type3')
|
|
31
|
+
* // => ['Type1', 'Type2', 'Type3']
|
|
32
|
+
*
|
|
33
|
+
* parseUnionTypes('SingleType')
|
|
34
|
+
* // => ['SingleType']
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export function parseUnionTypes(typeSpec) {
|
|
38
|
+
if (!typeSpec || typeSpec.trim() === '') {
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
// Split by pipe and process each type
|
|
42
|
+
const types = typeSpec.split('|').map((t) => {
|
|
43
|
+
let type = t.trim();
|
|
44
|
+
// Strip threshold syntax: Type(0.8) -> Type
|
|
45
|
+
const thresholdMatch = type.match(/^([A-Za-z][A-Za-z0-9_]*)\s*\([^)]*\)$/);
|
|
46
|
+
if (thresholdMatch) {
|
|
47
|
+
type = thresholdMatch[1];
|
|
48
|
+
}
|
|
49
|
+
return type;
|
|
50
|
+
});
|
|
51
|
+
// Filter out empty strings (from cases like "Type1||Type2")
|
|
52
|
+
return types.filter((t) => t.length > 0);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Parse per-type thresholds from union type specification
|
|
56
|
+
*
|
|
57
|
+
* Extracts threshold values from syntax like `Type1|Type2(0.8)|Type3(0.6)`
|
|
58
|
+
*
|
|
59
|
+
* @param typeSpec - The union type specification string
|
|
60
|
+
* @returns Record mapping type names to their thresholds
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* parseUnionThresholds('Type1|Type2(0.8)|Type3(0.6)')
|
|
65
|
+
* // => { Type2: 0.8, Type3: 0.6 }
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export function parseUnionThresholds(typeSpec) {
|
|
69
|
+
const thresholds = {};
|
|
70
|
+
if (!typeSpec)
|
|
71
|
+
return thresholds;
|
|
72
|
+
const parts = typeSpec.split('|');
|
|
73
|
+
for (const part of parts) {
|
|
74
|
+
const match = part.trim().match(/^([A-Za-z][A-Za-z0-9_]*)\s*\(([0-9.]+)\)$/);
|
|
75
|
+
if (match) {
|
|
76
|
+
const [, typeName, thresholdStr] = match;
|
|
77
|
+
const threshold = parseFloat(thresholdStr);
|
|
78
|
+
if (!isNaN(threshold) && threshold >= 0 && threshold <= 1) {
|
|
79
|
+
thresholds[typeName] = threshold;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return thresholds;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Get the effective threshold for a type
|
|
87
|
+
*
|
|
88
|
+
* @param type - The type name
|
|
89
|
+
* @param options - Search options containing global and per-type thresholds
|
|
90
|
+
* @returns The threshold to use for this type
|
|
91
|
+
*/
|
|
92
|
+
function getThresholdForType(type, options) {
|
|
93
|
+
// Per-type threshold takes precedence
|
|
94
|
+
if (options.thresholds && type in options.thresholds) {
|
|
95
|
+
return options.thresholds[type];
|
|
96
|
+
}
|
|
97
|
+
// Fall back to global threshold, default to 0 (accept all)
|
|
98
|
+
return options.threshold ?? 0;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Filter matches by threshold
|
|
102
|
+
*/
|
|
103
|
+
function filterByThreshold(matches, threshold, includeBelowThreshold) {
|
|
104
|
+
const above = [];
|
|
105
|
+
const below = [];
|
|
106
|
+
for (const match of matches) {
|
|
107
|
+
if (match.$score >= threshold) {
|
|
108
|
+
above.push(match);
|
|
109
|
+
}
|
|
110
|
+
else if (includeBelowThreshold) {
|
|
111
|
+
below.push(match);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return { above, below };
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Search union types with fallback behavior
|
|
118
|
+
*
|
|
119
|
+
* Searches multiple types either sequentially (ordered) or concurrently (parallel),
|
|
120
|
+
* with support for per-type thresholds and graceful error handling.
|
|
121
|
+
*
|
|
122
|
+
* @param types - Array of type names to search (in priority order)
|
|
123
|
+
* @param query - The search query
|
|
124
|
+
* @param options - Search options including mode, thresholds, and searcher
|
|
125
|
+
* @returns Search result with matches and metadata
|
|
126
|
+
*
|
|
127
|
+
* @example Ordered mode (stops on first match)
|
|
128
|
+
* ```ts
|
|
129
|
+
* const result = await searchUnionTypes(
|
|
130
|
+
* ['Document', 'Video', 'Expert'],
|
|
131
|
+
* 'machine learning tutorial',
|
|
132
|
+
* {
|
|
133
|
+
* mode: 'ordered',
|
|
134
|
+
* threshold: 0.75,
|
|
135
|
+
* searcher: async (type, query) => {
|
|
136
|
+
* return provider.semanticSearch(type, query)
|
|
137
|
+
* }
|
|
138
|
+
* }
|
|
139
|
+
* )
|
|
140
|
+
* ```
|
|
141
|
+
*
|
|
142
|
+
* @example Parallel mode (searches all, returns best)
|
|
143
|
+
* ```ts
|
|
144
|
+
* const result = await searchUnionTypes(
|
|
145
|
+
* ['Document', 'Video', 'Expert'],
|
|
146
|
+
* 'machine learning tutorial',
|
|
147
|
+
* {
|
|
148
|
+
* mode: 'parallel',
|
|
149
|
+
* returnAll: true,
|
|
150
|
+
* searcher: async (type, query) => {
|
|
151
|
+
* return provider.semanticSearch(type, query)
|
|
152
|
+
* }
|
|
153
|
+
* }
|
|
154
|
+
* )
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
export async function searchUnionTypes(types, query, options) {
|
|
158
|
+
// Initialize result
|
|
159
|
+
const result = {
|
|
160
|
+
matches: [],
|
|
161
|
+
searchedTypes: [],
|
|
162
|
+
searchOrder: [],
|
|
163
|
+
fallbackTriggered: false,
|
|
164
|
+
allTypesExhausted: false,
|
|
165
|
+
errors: [],
|
|
166
|
+
};
|
|
167
|
+
if (options.includeBelowThreshold) {
|
|
168
|
+
result.belowThresholdMatches = [];
|
|
169
|
+
}
|
|
170
|
+
// Handle empty types array
|
|
171
|
+
if (!types || types.length === 0) {
|
|
172
|
+
result.allTypesExhausted = true;
|
|
173
|
+
return result;
|
|
174
|
+
}
|
|
175
|
+
if (options.mode === 'parallel') {
|
|
176
|
+
return searchParallel(types, query, options, result);
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
return searchOrdered(types, query, options, result);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Search types in order, stopping on first match
|
|
184
|
+
*/
|
|
185
|
+
async function searchOrdered(types, query, options, result) {
|
|
186
|
+
const { searcher, includeBelowThreshold, onError = 'throw' } = options;
|
|
187
|
+
for (let i = 0; i < types.length; i++) {
|
|
188
|
+
const type = types[i];
|
|
189
|
+
const threshold = getThresholdForType(type, options);
|
|
190
|
+
result.searchedTypes.push(type);
|
|
191
|
+
result.searchOrder.push(type);
|
|
192
|
+
if (i > 0) {
|
|
193
|
+
result.fallbackTriggered = true;
|
|
194
|
+
}
|
|
195
|
+
try {
|
|
196
|
+
const searchOpts = { threshold };
|
|
197
|
+
if (options.limit !== undefined)
|
|
198
|
+
searchOpts.limit = options.limit;
|
|
199
|
+
const matches = await searcher(type, query, searchOpts);
|
|
200
|
+
// Filter by threshold
|
|
201
|
+
const { above, below } = filterByThreshold(matches, threshold, includeBelowThreshold);
|
|
202
|
+
// Collect below-threshold matches for debugging
|
|
203
|
+
if (includeBelowThreshold && below.length > 0) {
|
|
204
|
+
result.belowThresholdMatches.push(...below);
|
|
205
|
+
}
|
|
206
|
+
// If we found matches above threshold, stop searching
|
|
207
|
+
if (above.length > 0) {
|
|
208
|
+
result.matches = above;
|
|
209
|
+
result.matchedType = type;
|
|
210
|
+
result.confidence = Math.max(...above.map((m) => m.$score));
|
|
211
|
+
return result;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
if (onError === 'throw') {
|
|
216
|
+
throw error;
|
|
217
|
+
}
|
|
218
|
+
// Continue mode: record error and try next type
|
|
219
|
+
const searchError = {
|
|
220
|
+
type,
|
|
221
|
+
message: error instanceof Error ? error.message : String(error),
|
|
222
|
+
};
|
|
223
|
+
if (error instanceof Error)
|
|
224
|
+
searchError.error = error;
|
|
225
|
+
result.errors.push(searchError);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
// No matches found in any type
|
|
229
|
+
result.allTypesExhausted = true;
|
|
230
|
+
return result;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Search all types in parallel, return best match(es)
|
|
234
|
+
*/
|
|
235
|
+
async function searchParallel(types, query, options, result) {
|
|
236
|
+
const { searcher, returnAll = false, includeBelowThreshold, onError = 'continue' } = options;
|
|
237
|
+
// Mark all types as searched
|
|
238
|
+
result.searchedTypes = [...types];
|
|
239
|
+
result.searchOrder = [...types];
|
|
240
|
+
// Search all types in parallel
|
|
241
|
+
const searchPromises = types.map(async (type) => {
|
|
242
|
+
const threshold = getThresholdForType(type, options);
|
|
243
|
+
try {
|
|
244
|
+
const searchOpts = { threshold };
|
|
245
|
+
if (options.limit !== undefined)
|
|
246
|
+
searchOpts.limit = options.limit;
|
|
247
|
+
const matches = await searcher(type, query, searchOpts);
|
|
248
|
+
return { type, matches, error: null };
|
|
249
|
+
}
|
|
250
|
+
catch (error) {
|
|
251
|
+
return {
|
|
252
|
+
type,
|
|
253
|
+
matches: [],
|
|
254
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
const results = await Promise.all(searchPromises);
|
|
259
|
+
// Collect all matches and errors
|
|
260
|
+
const allMatches = [];
|
|
261
|
+
const allBelowThreshold = [];
|
|
262
|
+
for (const { type, matches, error } of results) {
|
|
263
|
+
if (error) {
|
|
264
|
+
if (onError === 'throw') {
|
|
265
|
+
throw error;
|
|
266
|
+
}
|
|
267
|
+
result.errors.push({
|
|
268
|
+
type,
|
|
269
|
+
message: error.message,
|
|
270
|
+
error,
|
|
271
|
+
});
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
const threshold = getThresholdForType(type, options);
|
|
275
|
+
const { above, below } = filterByThreshold(matches, threshold, includeBelowThreshold);
|
|
276
|
+
allMatches.push(...above);
|
|
277
|
+
if (includeBelowThreshold) {
|
|
278
|
+
allBelowThreshold.push(...below);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
// Sort by score descending
|
|
282
|
+
allMatches.sort((a, b) => b.$score - a.$score);
|
|
283
|
+
result.belowThresholdMatches = allBelowThreshold;
|
|
284
|
+
if (allMatches.length === 0) {
|
|
285
|
+
result.allTypesExhausted = true;
|
|
286
|
+
return result;
|
|
287
|
+
}
|
|
288
|
+
// Return all matches or just the best one
|
|
289
|
+
if (returnAll) {
|
|
290
|
+
result.matches = allMatches;
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
result.matches = [allMatches[0]];
|
|
294
|
+
}
|
|
295
|
+
result.matchedType = result.matches[0].$type;
|
|
296
|
+
result.confidence = result.matches[0].$score;
|
|
297
|
+
// Fallback triggered if the best match isn't from the first type
|
|
298
|
+
result.fallbackTriggered = result.matchedType !== types[0];
|
|
299
|
+
return result;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Create a searcher function that wraps a semantic search provider
|
|
303
|
+
*
|
|
304
|
+
* @param provider - The database provider with semanticSearch method
|
|
305
|
+
* @returns A searcher function compatible with searchUnionTypes
|
|
306
|
+
*
|
|
307
|
+
* @example
|
|
308
|
+
* ```ts
|
|
309
|
+
* const searcher = createProviderSearcher(provider)
|
|
310
|
+
* const result = await searchUnionTypes(
|
|
311
|
+
* ['Document', 'Video'],
|
|
312
|
+
* 'tutorial',
|
|
313
|
+
* { mode: 'ordered', searcher }
|
|
314
|
+
* )
|
|
315
|
+
* ```
|
|
316
|
+
*/
|
|
317
|
+
export function createProviderSearcher(provider) {
|
|
318
|
+
return async (type, query, options) => {
|
|
319
|
+
const searchOpts = {
|
|
320
|
+
limit: options?.limit ?? 10,
|
|
321
|
+
};
|
|
322
|
+
if (options?.threshold !== undefined)
|
|
323
|
+
searchOpts.minScore = options.threshold;
|
|
324
|
+
const results = await provider.semanticSearch(type, query, searchOpts);
|
|
325
|
+
return results.map((r) => ({
|
|
326
|
+
...r,
|
|
327
|
+
$type: type,
|
|
328
|
+
}));
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
//# sourceMappingURL=union-fallback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"union-fallback.js","sourceRoot":"","sources":["../../src/schema/union-fallback.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAiHH;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,eAAe,CAAC,QAAgB;IAC9C,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACxC,OAAO,EAAE,CAAA;IACX,CAAC;IAED,sCAAsC;IACtC,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QAC1C,IAAI,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,CAAA;QAEnB,4CAA4C;QAC5C,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,uCAAuC,CAAC,CAAA;QAC1E,IAAI,cAAc,EAAE,CAAC;YACnB,IAAI,GAAG,cAAc,CAAC,CAAC,CAAE,CAA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;;GAeG;AACH,MAAM,UAAU,sBAAsB,CAAC,QAMtC;IACC,OAAO,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;QACpC,MAAM,UAAU,GAA0C;YACxD,KAAK,EAAE,OAAO,EAAE,KAAK,IAAI,EAAE;SAC5B,CAAA;QACD,IAAI,OAAO,EAAE,SAAS,KAAK,SAAS;YAAE,UAAU,CAAC,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAA;QAC7E,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,cAAc,CAAC,IAAI,EAAE,KAAK,EAAE,UAAU,CAAC,CAAA;QAEtE,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACzB,GAAG,CAAC;YACJ,KAAK,EAAE,IAAI;SACZ,CAAC,CAAiB,CAAA;IACrB,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AIValueGenerator Implementation
|
|
3
|
+
*
|
|
4
|
+
* Generates values using AI/LLM integration for production use.
|
|
5
|
+
* Supports context-aware generation with parent chain and array context.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
import type { ValueGenerator, GenerationRequest, GenerationResult, AIFunction } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Configuration for AIValueGenerator
|
|
12
|
+
*/
|
|
13
|
+
export interface AIValueGeneratorConfig {
|
|
14
|
+
/** AI function for generating values */
|
|
15
|
+
aiFunction: AIFunction;
|
|
16
|
+
/** Model to use for generation */
|
|
17
|
+
model?: string;
|
|
18
|
+
/** Maximum tokens for generation */
|
|
19
|
+
maxTokens?: number;
|
|
20
|
+
/** Temperature for generation */
|
|
21
|
+
temperature?: number;
|
|
22
|
+
/** Whether to fall back to placeholder on AI errors */
|
|
23
|
+
fallbackToPlaceholder?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* AIValueGenerator
|
|
27
|
+
*
|
|
28
|
+
* Generates values using an AI function for production use.
|
|
29
|
+
* Builds rich context from parent chain, previous generations, and array context.
|
|
30
|
+
*/
|
|
31
|
+
export declare class AIValueGenerator implements ValueGenerator {
|
|
32
|
+
private aiFunction;
|
|
33
|
+
private model?;
|
|
34
|
+
private maxTokens?;
|
|
35
|
+
private temperature?;
|
|
36
|
+
private fallbackToPlaceholder;
|
|
37
|
+
private placeholderGenerator;
|
|
38
|
+
constructor(config: AIValueGeneratorConfig);
|
|
39
|
+
/**
|
|
40
|
+
* Generate a value using AI
|
|
41
|
+
*
|
|
42
|
+
* @param request - The generation request
|
|
43
|
+
* @returns Promise resolving to the generated value with metadata
|
|
44
|
+
*/
|
|
45
|
+
generate(request: GenerationRequest): Promise<GenerationResult>;
|
|
46
|
+
/**
|
|
47
|
+
* Build a prompt from the generation request
|
|
48
|
+
*
|
|
49
|
+
* Combines field info, context, hints, and generation context
|
|
50
|
+
* into a comprehensive prompt for the AI.
|
|
51
|
+
*/
|
|
52
|
+
private buildPrompt;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=ai.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai.d.ts","sourceRoot":"","sources":["../../../src/schema/value-generators/ai.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAGjG;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,wCAAwC;IACxC,UAAU,EAAE,UAAU,CAAA;IACtB,kCAAkC;IAClC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,oCAAoC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,iCAAiC;IACjC,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,uDAAuD;IACvD,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAChC;AAED;;;;;GAKG;AACH,qBAAa,gBAAiB,YAAW,cAAc;IACrD,OAAO,CAAC,UAAU,CAAY;IAC9B,OAAO,CAAC,KAAK,CAAC,CAAQ;IACtB,OAAO,CAAC,SAAS,CAAC,CAAQ;IAC1B,OAAO,CAAC,WAAW,CAAC,CAAQ;IAC5B,OAAO,CAAC,qBAAqB,CAAS;IACtC,OAAO,CAAC,oBAAoB,CAA2B;gBAE3C,MAAM,EAAE,sBAAsB;IAS1C;;;;;OAKG;IACG,QAAQ,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA6BrE;;;;;OAKG;IACH,OAAO,CAAC,WAAW;CAsEpB"}
|