ai-database 2.1.3 → 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 +35 -1
- package/README.md +880 -669
- 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 +49 -23
- package/dist/ai-promise-db.d.ts.map +1 -1
- package/dist/ai-promise-db.js +91 -63
- 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 +35 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +106 -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 +128 -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 +48 -17
- package/dist/schema/cascade.d.ts.map +1 -1
- package/dist/schema/cascade.js +477 -278
- 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 +21 -109
- package/dist/schema/dependency-graph.d.ts.map +1 -1
- package/dist/schema/dependency-graph.js +25 -333
- package/dist/schema/dependency-graph.js.map +1 -1
- 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/index.d.ts +28 -34
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +454 -521
- 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 +144 -89
- package/dist/schema/parse.js.map +1 -1
- package/dist/schema/provider.d.ts +37 -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 +237 -95
- 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 +10 -0
- package/dist/schema/semantic.d.ts.map +1 -1
- package/dist/schema/semantic.js +192 -86
- 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.map +1 -1
- package/dist/schema/union-fallback.js +21 -15
- package/dist/schema/union-fallback.js.map +1 -1
- 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/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 -24
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +2852 -40
- 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 +50 -5
- package/dist/type-guards.d.ts.map +1 -1
- package/dist/type-guards.js +87 -16
- package/dist/type-guards.js.map +1 -1
- 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 +2 -5
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +65 -93
- package/dist/validation.js.map +1 -1
- 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 +46 -16
- package/src/docs-rels/migrations/0001-init.sql +125 -0
- package/LICENSE +0 -21
|
@@ -162,9 +162,11 @@ export async function searchUnionTypes(types, query, options) {
|
|
|
162
162
|
searchOrder: [],
|
|
163
163
|
fallbackTriggered: false,
|
|
164
164
|
allTypesExhausted: false,
|
|
165
|
-
belowThresholdMatches: options.includeBelowThreshold ? [] : undefined,
|
|
166
165
|
errors: [],
|
|
167
166
|
};
|
|
167
|
+
if (options.includeBelowThreshold) {
|
|
168
|
+
result.belowThresholdMatches = [];
|
|
169
|
+
}
|
|
168
170
|
// Handle empty types array
|
|
169
171
|
if (!types || types.length === 0) {
|
|
170
172
|
result.allTypesExhausted = true;
|
|
@@ -191,10 +193,10 @@ async function searchOrdered(types, query, options, result) {
|
|
|
191
193
|
result.fallbackTriggered = true;
|
|
192
194
|
}
|
|
193
195
|
try {
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
limit
|
|
197
|
-
|
|
196
|
+
const searchOpts = { threshold };
|
|
197
|
+
if (options.limit !== undefined)
|
|
198
|
+
searchOpts.limit = options.limit;
|
|
199
|
+
const matches = await searcher(type, query, searchOpts);
|
|
198
200
|
// Filter by threshold
|
|
199
201
|
const { above, below } = filterByThreshold(matches, threshold, includeBelowThreshold);
|
|
200
202
|
// Collect below-threshold matches for debugging
|
|
@@ -214,11 +216,13 @@ async function searchOrdered(types, query, options, result) {
|
|
|
214
216
|
throw error;
|
|
215
217
|
}
|
|
216
218
|
// Continue mode: record error and try next type
|
|
217
|
-
|
|
219
|
+
const searchError = {
|
|
218
220
|
type,
|
|
219
221
|
message: error instanceof Error ? error.message : String(error),
|
|
220
|
-
|
|
221
|
-
|
|
222
|
+
};
|
|
223
|
+
if (error instanceof Error)
|
|
224
|
+
searchError.error = error;
|
|
225
|
+
result.errors.push(searchError);
|
|
222
226
|
}
|
|
223
227
|
}
|
|
224
228
|
// No matches found in any type
|
|
@@ -237,10 +241,10 @@ async function searchParallel(types, query, options, result) {
|
|
|
237
241
|
const searchPromises = types.map(async (type) => {
|
|
238
242
|
const threshold = getThresholdForType(type, options);
|
|
239
243
|
try {
|
|
240
|
-
const
|
|
241
|
-
|
|
242
|
-
limit
|
|
243
|
-
|
|
244
|
+
const searchOpts = { threshold };
|
|
245
|
+
if (options.limit !== undefined)
|
|
246
|
+
searchOpts.limit = options.limit;
|
|
247
|
+
const matches = await searcher(type, query, searchOpts);
|
|
244
248
|
return { type, matches, error: null };
|
|
245
249
|
}
|
|
246
250
|
catch (error) {
|
|
@@ -312,10 +316,12 @@ async function searchParallel(types, query, options, result) {
|
|
|
312
316
|
*/
|
|
313
317
|
export function createProviderSearcher(provider) {
|
|
314
318
|
return async (type, query, options) => {
|
|
315
|
-
const
|
|
316
|
-
minScore: options?.threshold,
|
|
319
|
+
const searchOpts = {
|
|
317
320
|
limit: options?.limit ?? 10,
|
|
318
|
-
}
|
|
321
|
+
};
|
|
322
|
+
if (options?.threshold !== undefined)
|
|
323
|
+
searchOpts.minScore = options.threshold;
|
|
324
|
+
const results = await provider.semanticSearch(type, query, searchOpts);
|
|
319
325
|
return results.map((r) => ({
|
|
320
326
|
...r,
|
|
321
327
|
$type: type,
|
|
@@ -1 +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,CAAA;QAC3B,CAAC;QAED,OAAO,IAAI,CAAA;IACb,CAAC,CAAC,CAAA;IAEF,4DAA4D;IAC5D,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;AAC1C,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,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,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"}
|
|
@@ -0,0 +1,136 @@
|
|
|
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 { PlaceholderValueGenerator } from './placeholder.js';
|
|
10
|
+
/**
|
|
11
|
+
* AIValueGenerator
|
|
12
|
+
*
|
|
13
|
+
* Generates values using an AI function for production use.
|
|
14
|
+
* Builds rich context from parent chain, previous generations, and array context.
|
|
15
|
+
*/
|
|
16
|
+
export class AIValueGenerator {
|
|
17
|
+
aiFunction;
|
|
18
|
+
model;
|
|
19
|
+
maxTokens;
|
|
20
|
+
temperature;
|
|
21
|
+
fallbackToPlaceholder;
|
|
22
|
+
placeholderGenerator;
|
|
23
|
+
constructor(config) {
|
|
24
|
+
this.aiFunction = config.aiFunction;
|
|
25
|
+
if (config.model !== undefined)
|
|
26
|
+
this.model = config.model;
|
|
27
|
+
if (config.maxTokens !== undefined)
|
|
28
|
+
this.maxTokens = config.maxTokens;
|
|
29
|
+
if (config.temperature !== undefined)
|
|
30
|
+
this.temperature = config.temperature;
|
|
31
|
+
this.fallbackToPlaceholder = config.fallbackToPlaceholder ?? false;
|
|
32
|
+
this.placeholderGenerator = new PlaceholderValueGenerator();
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Generate a value using AI
|
|
36
|
+
*
|
|
37
|
+
* @param request - The generation request
|
|
38
|
+
* @returns Promise resolving to the generated value with metadata
|
|
39
|
+
*/
|
|
40
|
+
async generate(request) {
|
|
41
|
+
try {
|
|
42
|
+
const prompt = this.buildPrompt(request);
|
|
43
|
+
const response = await this.aiFunction(prompt);
|
|
44
|
+
const metadata = {
|
|
45
|
+
source: 'ai',
|
|
46
|
+
};
|
|
47
|
+
if (this.model !== undefined)
|
|
48
|
+
metadata.model = this.model;
|
|
49
|
+
if (response.usage?.tokens !== undefined)
|
|
50
|
+
metadata.tokens = response.usage.tokens;
|
|
51
|
+
return {
|
|
52
|
+
value: response.text,
|
|
53
|
+
metadata,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
if (this.fallbackToPlaceholder) {
|
|
58
|
+
const placeholderResult = await this.placeholderGenerator.generate(request);
|
|
59
|
+
return {
|
|
60
|
+
value: placeholderResult.value,
|
|
61
|
+
metadata: {
|
|
62
|
+
source: 'placeholder',
|
|
63
|
+
fallback: true,
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Build a prompt from the generation request
|
|
72
|
+
*
|
|
73
|
+
* Combines field info, context, hints, and generation context
|
|
74
|
+
* into a comprehensive prompt for the AI.
|
|
75
|
+
*/
|
|
76
|
+
buildPrompt(request) {
|
|
77
|
+
const parts = [];
|
|
78
|
+
// Add field and type context
|
|
79
|
+
parts.push(`Generate a value for field "${request.fieldName}" on type "${request.type}".`);
|
|
80
|
+
// Add full context if available
|
|
81
|
+
if (request.fullContext) {
|
|
82
|
+
parts.push(`Context: ${request.fullContext}`);
|
|
83
|
+
}
|
|
84
|
+
// Add hint if available
|
|
85
|
+
if (request.hint) {
|
|
86
|
+
parts.push(`Hint: ${request.hint}`);
|
|
87
|
+
}
|
|
88
|
+
// Add parent data context
|
|
89
|
+
if (request.parentData && Object.keys(request.parentData).length > 0) {
|
|
90
|
+
const parentEntries = Object.entries(request.parentData)
|
|
91
|
+
.filter(([key, value]) => !key.startsWith('$') && !key.startsWith('_') && typeof value === 'string')
|
|
92
|
+
.map(([key, value]) => `${key}: ${value}`)
|
|
93
|
+
.join(', ');
|
|
94
|
+
if (parentEntries) {
|
|
95
|
+
parts.push(`Parent data: ${parentEntries}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// Add generation context if available
|
|
99
|
+
const genCtx = request.generationContext;
|
|
100
|
+
if (genCtx) {
|
|
101
|
+
// Add parent chain context
|
|
102
|
+
if (genCtx.parentChain && genCtx.parentChain.length > 0) {
|
|
103
|
+
const chainInfo = genCtx.parentChain
|
|
104
|
+
.map((entity) => {
|
|
105
|
+
const name = entity['name'] || entity['title'] || entity.$id;
|
|
106
|
+
return `${entity.$type}: ${name}`;
|
|
107
|
+
})
|
|
108
|
+
.join(' > ');
|
|
109
|
+
parts.push(`Parent chain: ${chainInfo}`);
|
|
110
|
+
}
|
|
111
|
+
// Add previously generated entities
|
|
112
|
+
if (genCtx.previouslyGenerated && genCtx.previouslyGenerated.length > 0) {
|
|
113
|
+
const prevInfo = genCtx.previouslyGenerated
|
|
114
|
+
.map((entity) => {
|
|
115
|
+
const name = entity['name'] || entity['title'] || entity.$id;
|
|
116
|
+
return `${entity.$type}: ${name}`;
|
|
117
|
+
})
|
|
118
|
+
.join(', ');
|
|
119
|
+
parts.push(`Previously generated: ${prevInfo}`);
|
|
120
|
+
}
|
|
121
|
+
// Add array context
|
|
122
|
+
if (genCtx.arrayContext) {
|
|
123
|
+
const { fieldName, previousItems, index } = genCtx.arrayContext;
|
|
124
|
+
parts.push(`Array field: ${fieldName}, generating item ${index + 1}`);
|
|
125
|
+
if (previousItems.length > 0) {
|
|
126
|
+
const prevItemsInfo = previousItems
|
|
127
|
+
.map((item) => item['name'] || item['title'] || item.$id)
|
|
128
|
+
.join(', ');
|
|
129
|
+
parts.push(`Previous items: ${prevItemsInfo}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return parts.join('\n');
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=ai.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai.js","sourceRoot":"","sources":["../../../src/schema/value-generators/ai.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAA;AAkB5D;;;;;GAKG;AACH,MAAM,OAAO,gBAAgB;IACnB,UAAU,CAAY;IACtB,KAAK,CAAS;IACd,SAAS,CAAS;IAClB,WAAW,CAAS;IACpB,qBAAqB,CAAS;IAC9B,oBAAoB,CAA2B;IAEvD,YAAY,MAA8B;QACxC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAA;QACnC,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS;YAAE,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAA;QACzD,IAAI,MAAM,CAAC,SAAS,KAAK,SAAS;YAAE,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAA;QACrE,IAAI,MAAM,CAAC,WAAW,KAAK,SAAS;YAAE,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAA;QAC3E,IAAI,CAAC,qBAAqB,GAAG,MAAM,CAAC,qBAAqB,IAAI,KAAK,CAAA;QAClE,IAAI,CAAC,oBAAoB,GAAG,IAAI,yBAAyB,EAAE,CAAA;IAC7D,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,QAAQ,CAAC,OAA0B;QACvC,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;YACxC,MAAM,QAAQ,GAAG,MAAM,I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|
|
1
|
+
/**
|
|
2
|
+
* ValueGenerator Module
|
|
3
|
+
*
|
|
4
|
+
* Strategy pattern for value generation during entity creation.
|
|
5
|
+
* Supports both placeholder (deterministic test fixtures) and
|
|
6
|
+
* AI-powered (production) generation.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Use placeholder generator for testing
|
|
11
|
+
* const generator = createValueGenerator({ type: 'placeholder' })
|
|
12
|
+
* const result = await generator.generate({
|
|
13
|
+
* fieldName: 'name',
|
|
14
|
+
* type: 'Person',
|
|
15
|
+
* fullContext: 'tech entrepreneur startup',
|
|
16
|
+
* })
|
|
17
|
+
*
|
|
18
|
+
* // Configure global generator for AI in production
|
|
19
|
+
* configureValueGenerator({
|
|
20
|
+
* type: 'ai',
|
|
21
|
+
* aiFunction: async (prompt) => ({ text: await callAI(prompt) }),
|
|
22
|
+
* })
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @packageDocumentation
|
|
26
|
+
*/
|
|
27
|
+
export type { GenerationRequest, GenerationResult, GenerationMetadata, ValueGenerator, ValueGeneratorConfig, AIFunction, ArrayContext, GenerationContextData, } from './types.js';
|
|
28
|
+
export { PlaceholderValueGenerator } from './placeholder.js';
|
|
29
|
+
export { AIValueGenerator } from './ai.js';
|
|
30
|
+
export type { AIValueGeneratorConfig } from './ai.js';
|
|
31
|
+
import type { ValueGenerator, ValueGeneratorConfig } from './types.js';
|
|
32
|
+
/**
|
|
33
|
+
* Create a ValueGenerator based on configuration
|
|
34
|
+
*
|
|
35
|
+
* @param config - Generator configuration
|
|
36
|
+
* @returns A new ValueGenerator instance
|
|
37
|
+
* @throws Error if AI type is specified without aiFunction
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* // Create placeholder generator (default)
|
|
42
|
+
* const placeholderGen = createValueGenerator()
|
|
43
|
+
*
|
|
44
|
+
* // Create placeholder generator explicitly
|
|
45
|
+
* const placeholderGen = createValueGenerator({ type: 'placeholder' })
|
|
46
|
+
*
|
|
47
|
+
* // Create AI generator
|
|
48
|
+
* const aiGen = createValueGenerator({
|
|
49
|
+
* type: 'ai',
|
|
50
|
+
* aiFunction: async (prompt) => ({ text: 'AI response' }),
|
|
51
|
+
* })
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function createValueGenerator(config?: ValueGeneratorConfig): ValueGenerator;
|
|
55
|
+
/**
|
|
56
|
+
* Configure the global default value generator
|
|
57
|
+
*
|
|
58
|
+
* Call this at application startup to set the default generator
|
|
59
|
+
* that will be used throughout the application.
|
|
60
|
+
*
|
|
61
|
+
* @param config - Generator configuration
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* // Use placeholder for testing
|
|
66
|
+
* configureValueGenerator({ type: 'placeholder' })
|
|
67
|
+
*
|
|
68
|
+
* // Use AI for production
|
|
69
|
+
* configureValueGenerator({
|
|
70
|
+
* type: 'ai',
|
|
71
|
+
* aiFunction: myAIFunction,
|
|
72
|
+
* model: 'claude-3',
|
|
73
|
+
* fallbackToPlaceholder: true,
|
|
74
|
+
* })
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export declare function configureValueGenerator(config: ValueGeneratorConfig): void;
|
|
78
|
+
/**
|
|
79
|
+
* Get the current global value generator
|
|
80
|
+
*
|
|
81
|
+
* Returns the configured generator instance, creating one if needed.
|
|
82
|
+
* Use this to get the generator configured via configureValueGenerator.
|
|
83
|
+
*
|
|
84
|
+
* @returns The current ValueGenerator instance
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const generator = getValueGenerator()
|
|
89
|
+
* const result = await generator.generate({
|
|
90
|
+
* fieldName: 'description',
|
|
91
|
+
* type: 'Product',
|
|
92
|
+
* })
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export declare function getValueGenerator(): ValueGenerator;
|
|
96
|
+
/**
|
|
97
|
+
* Generate a context-aware value for a field
|
|
98
|
+
*
|
|
99
|
+
* This is a convenience function that uses the global generator.
|
|
100
|
+
* Equivalent to calling `getValueGenerator().generate(request)`.
|
|
101
|
+
*
|
|
102
|
+
* @deprecated Use `getValueGenerator().generate()` instead
|
|
103
|
+
*
|
|
104
|
+
* @param fieldName - The name of the field being generated
|
|
105
|
+
* @param type - The entity type name
|
|
106
|
+
* @param fullContext - Combined context string
|
|
107
|
+
* @param hint - Optional hint text for guiding generation
|
|
108
|
+
* @param parentData - Parent entity data for context inheritance
|
|
109
|
+
* @returns A generated string value
|
|
110
|
+
*/
|
|
111
|
+
export declare function generateContextAwareValue(fieldName: string, type: string, fullContext: string, hint: string | undefined, parentData?: Record<string, unknown>): Promise<string>;
|
|
112
|
+
/**
|
|
113
|
+
* Synchronous wrapper for generateContextAwareValue
|
|
114
|
+
*
|
|
115
|
+
* Uses the PlaceholderValueGenerator directly for synchronous calls.
|
|
116
|
+
* This maintains backward compatibility with existing cascade.ts code.
|
|
117
|
+
*
|
|
118
|
+
* @param fieldName - The name of the field being generated
|
|
119
|
+
* @param type - The entity type name
|
|
120
|
+
* @param fullContext - Combined context string
|
|
121
|
+
* @param hint - Optional hint text for guiding generation
|
|
122
|
+
* @param parentData - Parent entity data for context inheritance
|
|
123
|
+
* @returns A generated string value
|
|
124
|
+
*/
|
|
125
|
+
export declare function generateContextAwareValueSync(fieldName: string, type: string, fullContext: string, hint: string | undefined, parentData?: Record<string, unknown>): string;
|
|
126
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/schema/value-generators/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAGH,YAAY,EACV,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,EACd,oBAAoB,EACpB,UAAU,EACV,YAAY,EACZ,qBAAqB,GACtB,MAAM,YAAY,CAAA;AAGnB,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAA;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAC1C,YAAY,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AAErD,OAAO,KAAK,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AActE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,GAAE,oBAAyB,GAAG,cAAc,CAmBtF;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,oBAAoB,GAAG,IAAI,CAG1E;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iBAAiB,IAAI,cAAc,CAKlD;AAMD;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,yBAAyB,CAC7C,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,UAAU,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GACvC,OAAO,CAAC,MAAM,CAAC,CAWjB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,UAAU,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GACvC,MAAM,CA8CR"}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ValueGenerator Module
|
|
3
|
+
*
|
|
4
|
+
* Strategy pattern for value generation during entity creation.
|
|
5
|
+
* Supports both placeholder (deterministic test fixtures) and
|
|
6
|
+
* AI-powered (production) generation.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Use placeholder generator for testing
|
|
11
|
+
* const generator = createValueGenerator({ type: 'placeholder' })
|
|
12
|
+
* const result = await generator.generate({
|
|
13
|
+
* fieldName: 'name',
|
|
14
|
+
* type: 'Person',
|
|
15
|
+
* fullContext: 'tech entrepreneur startup',
|
|
16
|
+
* })
|
|
17
|
+
*
|
|
18
|
+
* // Configure global generator for AI in production
|
|
19
|
+
* configureValueGenerator({
|
|
20
|
+
* type: 'ai',
|
|
21
|
+
* aiFunction: async (prompt) => ({ text: await callAI(prompt) }),
|
|
22
|
+
* })
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @packageDocumentation
|
|
26
|
+
*/
|
|
27
|
+
// Re-export implementations
|
|
28
|
+
export { PlaceholderValueGenerator } from './placeholder.js';
|
|
29
|
+
export { AIValueGenerator } from './ai.js';
|
|
30
|
+
import { PlaceholderValueGenerator } from './placeholder.js';
|
|
31
|
+
import { AIValueGenerator } from './ai.js';
|
|
32
|
+
// =============================================================================
|
|
33
|
+
// Global Generator Configuration
|
|
34
|
+
// =============================================================================
|
|
35
|
+
/** Current global generator instance */
|
|
36
|
+
let currentGenerator = null;
|
|
37
|
+
/** Current configuration */
|
|
38
|
+
let currentConfig = { type: 'placeholder' };
|
|
39
|
+
/**
|
|
40
|
+
* Create a ValueGenerator based on configuration
|
|
41
|
+
*
|
|
42
|
+
* @param config - Generator configuration
|
|
43
|
+
* @returns A new ValueGenerator instance
|
|
44
|
+
* @throws Error if AI type is specified without aiFunction
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* // Create placeholder generator (default)
|
|
49
|
+
* const placeholderGen = createValueGenerator()
|
|
50
|
+
*
|
|
51
|
+
* // Create placeholder generator explicitly
|
|
52
|
+
* const placeholderGen = createValueGenerator({ type: 'placeholder' })
|
|
53
|
+
*
|
|
54
|
+
* // Create AI generator
|
|
55
|
+
* const aiGen = createValueGenerator({
|
|
56
|
+
* type: 'ai',
|
|
57
|
+
* aiFunction: async (prompt) => ({ text: 'AI response' }),
|
|
58
|
+
* })
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export function createValueGenerator(config = {}) {
|
|
62
|
+
const type = config.type ?? 'placeholder';
|
|
63
|
+
if (type === 'ai') {
|
|
64
|
+
if (!config.aiFunction) {
|
|
65
|
+
throw new Error('aiFunction is required when creating an AI value generator');
|
|
66
|
+
}
|
|
67
|
+
const aiConfig = {
|
|
68
|
+
aiFunction: config.aiFunction,
|
|
69
|
+
};
|
|
70
|
+
if (config.model !== undefined)
|
|
71
|
+
aiConfig.model = config.model;
|
|
72
|
+
if (config.maxTokens !== undefined)
|
|
73
|
+
aiConfig.maxTokens = config.maxTokens;
|
|
74
|
+
if (config.temperature !== undefined)
|
|
75
|
+
aiConfig.temperature = config.temperature;
|
|
76
|
+
if (config.fallbackToPlaceholder !== undefined)
|
|
77
|
+
aiConfig.fallbackToPlaceholder = config.fallbackToPlaceholder;
|
|
78
|
+
return new AIValueGenerator(aiConfig);
|
|
79
|
+
}
|
|
80
|
+
return new PlaceholderValueGenerator();
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Configure the global default value generator
|
|
84
|
+
*
|
|
85
|
+
* Call this at application startup to set the default generator
|
|
86
|
+
* that will be used throughout the application.
|
|
87
|
+
*
|
|
88
|
+
* @param config - Generator configuration
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* // Use placeholder for testing
|
|
93
|
+
* configureValueGenerator({ type: 'placeholder' })
|
|
94
|
+
*
|
|
95
|
+
* // Use AI for production
|
|
96
|
+
* configureValueGenerator({
|
|
97
|
+
* type: 'ai',
|
|
98
|
+
* aiFunction: myAIFunction,
|
|
99
|
+
* model: 'claude-3',
|
|
100
|
+
* fallbackToPlaceholder: true,
|
|
101
|
+
* })
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
export function configureValueGenerator(config) {
|
|
105
|
+
currentConfig = { ...config };
|
|
106
|
+
currentGenerator = null; // Reset so next getValueGenerator creates a new instance
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get the current global value generator
|
|
110
|
+
*
|
|
111
|
+
* Returns the configured generator instance, creating one if needed.
|
|
112
|
+
* Use this to get the generator configured via configureValueGenerator.
|
|
113
|
+
*
|
|
114
|
+
* @returns The current ValueGenerator instance
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* const generator = getValueGenerator()
|
|
119
|
+
* const result = await generator.generate({
|
|
120
|
+
* fieldName: 'description',
|
|
121
|
+
* type: 'Product',
|
|
122
|
+
* })
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
export function getValueGenerator() {
|
|
126
|
+
if (!currentGenerator) {
|
|
127
|
+
currentGenerator = createValueGenerator(currentConfig);
|
|
128
|
+
}
|
|
129
|
+
return currentGenerator;
|
|
130
|
+
}
|
|
131
|
+
// =============================================================================
|
|
132
|
+
// Legacy Compatibility
|
|
133
|
+
// =============================================================================
|
|
134
|
+
/**
|
|
135
|
+
* Generate a context-aware value for a field
|
|
136
|
+
*
|
|
137
|
+
* This is a convenience function that uses the global generator.
|
|
138
|
+
* Equivalent to calling `getValueGenerator().generate(request)`.
|
|
139
|
+
*
|
|
140
|
+
* @deprecated Use `getValueGenerator().generate()` instead
|
|
141
|
+
*
|
|
142
|
+
* @param fieldName - The name of the field being generated
|
|
143
|
+
* @param type - The entity type name
|
|
144
|
+
* @param fullContext - Combined context string
|
|
145
|
+
* @param hint - Optional hint text for guiding generation
|
|
146
|
+
* @param parentData - Parent entity data for context inheritance
|
|
147
|
+
* @returns A generated string value
|
|
148
|
+
*/
|
|
149
|
+
export async function generateContextAwareValue(fieldName, type, fullContext, hint, parentData = {}) {
|
|
150
|
+
const generator = getValueGenerator();
|
|
151
|
+
const request = {
|
|
152
|
+
fieldName,
|
|
153
|
+
type,
|
|
154
|
+
fullContext,
|
|
155
|
+
parentData,
|
|
156
|
+
};
|
|
157
|
+
if (hint !== undefined)
|
|
158
|
+
request.hint = hint;
|
|
159
|
+
const result = await generator.generate(request);
|
|
160
|
+
return result.value;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Synchronous wrapper for generateContextAwareValue
|
|
164
|
+
*
|
|
165
|
+
* Uses the PlaceholderValueGenerator directly for synchronous calls.
|
|
166
|
+
* This maintains backward compatibility with existing cascade.ts code.
|
|
167
|
+
*
|
|
168
|
+
* @param fieldName - The name of the field being generated
|
|
169
|
+
* @param type - The entity type name
|
|
170
|
+
* @param fullContext - Combined context string
|
|
171
|
+
* @param hint - Optional hint text for guiding generation
|
|
172
|
+
* @param parentData - Parent entity data for context inheritance
|
|
173
|
+
* @returns A generated string value
|
|
174
|
+
*/
|
|
175
|
+
export function generateContextAwareValueSync(fieldName, type, fullContext, hint, parentData = {}) {
|
|
176
|
+
// Use placeholder generator directly for sync calls
|
|
177
|
+
const generator = new PlaceholderValueGenerator();
|
|
178
|
+
// Access the private generateValue method via the generate interface
|
|
179
|
+
// Since we know PlaceholderValueGenerator.generate is sync-compatible
|
|
180
|
+
const request = {
|
|
181
|
+
fieldName,
|
|
182
|
+
type,
|
|
183
|
+
fullContext,
|
|
184
|
+
parentData,
|
|
185
|
+
};
|
|
186
|
+
if (hint !== undefined)
|
|
187
|
+
request.hint = hint;
|
|
188
|
+
// We can safely synchronously return since PlaceholderValueGenerator
|
|
189
|
+
// doesn't actually do any async work in its current implementation
|
|
190
|
+
let result = '';
|
|
191
|
+
void generator.generate(request).then((r) => {
|
|
192
|
+
result = r.value;
|
|
193
|
+
});
|
|
194
|
+
// For true sync behavior, we need to inline the logic
|
|
195
|
+
// This duplicates the logic but maintains backward compatibility
|
|
196
|
+
const value = parentData[fieldName];
|
|
197
|
+
if (typeof value === 'string' && value) {
|
|
198
|
+
return value;
|
|
199
|
+
}
|
|
200
|
+
if (!fullContext || fullContext.trim() === '') {
|
|
201
|
+
return `Generated ${fieldName} for ${type}`;
|
|
202
|
+
}
|
|
203
|
+
const contextLower = fullContext.toLowerCase();
|
|
204
|
+
const hintLower = (hint || '').toLowerCase();
|
|
205
|
+
// Minimal subset of field handlers for common cases
|
|
206
|
+
// Full logic is in PlaceholderValueGenerator
|
|
207
|
+
if (fieldName === 'name') {
|
|
208
|
+
if (hintLower.includes('philosopher') || contextLower.includes('philosopher'))
|
|
209
|
+
return 'Aristotle';
|
|
210
|
+
if (hintLower.includes('tech entrepreneur') || hintLower.includes('startup'))
|
|
211
|
+
return 'Alex Chen';
|
|
212
|
+
if (hint && hint.trim())
|
|
213
|
+
return `${type}: ${hint}`;
|
|
214
|
+
return `Generated ${fieldName} for ${type}`;
|
|
215
|
+
}
|
|
216
|
+
// For all other fields, use a basic fallback
|
|
217
|
+
return `${fieldName}: ${fullContext}`;
|
|
218
|
+
}
|
|
219
|
+
//# sourceMappingURL=index.js.map
|