semantic-primitives 0.1.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/LICENSE +201 -0
- package/README.md +449 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25016 -0
- package/dist/llm/client.d.ts +82 -0
- package/dist/llm/client.d.ts.map +1 -0
- package/dist/llm/index.d.ts +11 -0
- package/dist/llm/index.d.ts.map +1 -0
- package/dist/llm/providers/anthropic.d.ts +13 -0
- package/dist/llm/providers/anthropic.d.ts.map +1 -0
- package/dist/llm/providers/google.d.ts +13 -0
- package/dist/llm/providers/google.d.ts.map +1 -0
- package/dist/llm/providers/index.d.ts +7 -0
- package/dist/llm/providers/index.d.ts.map +1 -0
- package/dist/llm/providers/openai.d.ts +13 -0
- package/dist/llm/providers/openai.d.ts.map +1 -0
- package/dist/llm/types.d.ts +91 -0
- package/dist/llm/types.d.ts.map +1 -0
- package/dist/primitives/bigint/bigint.d.ts +197 -0
- package/dist/primitives/bigint/bigint.d.ts.map +1 -0
- package/dist/primitives/bigint/index.d.ts +7 -0
- package/dist/primitives/bigint/index.d.ts.map +1 -0
- package/dist/primitives/bigint/prompts.d.ts +37 -0
- package/dist/primitives/bigint/prompts.d.ts.map +1 -0
- package/dist/primitives/boolean/boolean.d.ts +194 -0
- package/dist/primitives/boolean/boolean.d.ts.map +1 -0
- package/dist/primitives/boolean/evals/from.evals.d.ts +7 -0
- package/dist/primitives/boolean/evals/from.evals.d.ts.map +1 -0
- package/dist/primitives/boolean/evals/index.d.ts +5 -0
- package/dist/primitives/boolean/evals/index.d.ts.map +1 -0
- package/dist/primitives/boolean/index.d.ts +6 -0
- package/dist/primitives/boolean/index.d.ts.map +1 -0
- package/dist/primitives/boolean/prompts.d.ts +29 -0
- package/dist/primitives/boolean/prompts.d.ts.map +1 -0
- package/dist/primitives/index.d.ts +14 -0
- package/dist/primitives/index.d.ts.map +1 -0
- package/dist/primitives/null/index.d.ts +6 -0
- package/dist/primitives/null/index.d.ts.map +1 -0
- package/dist/primitives/null/null.d.ts +181 -0
- package/dist/primitives/null/null.d.ts.map +1 -0
- package/dist/primitives/null/prompts.d.ts +39 -0
- package/dist/primitives/null/prompts.d.ts.map +1 -0
- package/dist/primitives/number/index.d.ts +6 -0
- package/dist/primitives/number/index.d.ts.map +1 -0
- package/dist/primitives/number/number.d.ts +154 -0
- package/dist/primitives/number/number.d.ts.map +1 -0
- package/dist/primitives/number/number.prompts.d.ts +53 -0
- package/dist/primitives/number/number.prompts.d.ts.map +1 -0
- package/dist/primitives/string/evals/classify.evals.d.ts +7 -0
- package/dist/primitives/string/evals/classify.evals.d.ts.map +1 -0
- package/dist/primitives/string/evals/index.d.ts +6 -0
- package/dist/primitives/string/evals/index.d.ts.map +1 -0
- package/dist/primitives/string/evals/semanticallyEquals.evals.d.ts +7 -0
- package/dist/primitives/string/evals/semanticallyEquals.evals.d.ts.map +1 -0
- package/dist/primitives/string/index.d.ts +206 -0
- package/dist/primitives/string/index.d.ts.map +1 -0
- package/dist/primitives/string/string.prompts.d.ts +45 -0
- package/dist/primitives/string/string.prompts.d.ts.map +1 -0
- package/dist/primitives/symbol/index.d.ts +6 -0
- package/dist/primitives/symbol/index.d.ts.map +1 -0
- package/dist/primitives/symbol/symbol.d.ts +176 -0
- package/dist/primitives/symbol/symbol.d.ts.map +1 -0
- package/dist/primitives/symbol/symbol.prompts.d.ts +53 -0
- package/dist/primitives/symbol/symbol.prompts.d.ts.map +1 -0
- package/dist/primitives/undefined/index.d.ts +5 -0
- package/dist/primitives/undefined/index.d.ts.map +1 -0
- package/dist/primitives/undefined/prompts.d.ts +40 -0
- package/dist/primitives/undefined/prompts.d.ts.map +1 -0
- package/dist/primitives/undefined/undefined.d.ts +216 -0
- package/dist/primitives/undefined/undefined.d.ts.map +1 -0
- package/dist/primitives/void/index.d.ts +5 -0
- package/dist/primitives/void/index.d.ts.map +1 -0
- package/dist/primitives/void/prompts.d.ts +37 -0
- package/dist/primitives/void/prompts.d.ts.map +1 -0
- package/dist/primitives/void/void.d.ts +172 -0
- package/dist/primitives/void/void.d.ts.map +1 -0
- package/dist/shared/base-classes.d.ts +331 -0
- package/dist/shared/base-classes.d.ts.map +1 -0
- package/dist/shared/eval-types.d.ts +82 -0
- package/dist/shared/eval-types.d.ts.map +1 -0
- package/dist/shared/index.d.ts +25 -0
- package/dist/shared/index.d.ts.map +1 -0
- package/dist/shared/interfaces.d.ts +799 -0
- package/dist/shared/interfaces.d.ts.map +1 -0
- package/dist/shared/types.d.ts +335 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/dist/types/array/array.d.ts +250 -0
- package/dist/types/array/array.d.ts.map +1 -0
- package/dist/types/array/index.d.ts +6 -0
- package/dist/types/array/index.d.ts.map +1 -0
- package/dist/types/array/prompts.d.ts +63 -0
- package/dist/types/array/prompts.d.ts.map +1 -0
- package/dist/types/blob-file/blob.d.ts +188 -0
- package/dist/types/blob-file/blob.d.ts.map +1 -0
- package/dist/types/blob-file/file.d.ts +144 -0
- package/dist/types/blob-file/file.d.ts.map +1 -0
- package/dist/types/blob-file/index.d.ts +8 -0
- package/dist/types/blob-file/index.d.ts.map +1 -0
- package/dist/types/blob-file/prompts.d.ts +101 -0
- package/dist/types/blob-file/prompts.d.ts.map +1 -0
- package/dist/types/bun/bun.d.ts +266 -0
- package/dist/types/bun/bun.d.ts.map +1 -0
- package/dist/types/bun/index.d.ts +7 -0
- package/dist/types/bun/index.d.ts.map +1 -0
- package/dist/types/bun/prompts.d.ts +93 -0
- package/dist/types/bun/prompts.d.ts.map +1 -0
- package/dist/types/callable/callable.d.ts +200 -0
- package/dist/types/callable/callable.d.ts.map +1 -0
- package/dist/types/callable/index.d.ts +6 -0
- package/dist/types/callable/index.d.ts.map +1 -0
- package/dist/types/callable/prompts.d.ts +45 -0
- package/dist/types/callable/prompts.d.ts.map +1 -0
- package/dist/types/constructable/constructable.d.ts +150 -0
- package/dist/types/constructable/constructable.d.ts.map +1 -0
- package/dist/types/constructable/index.d.ts +5 -0
- package/dist/types/constructable/index.d.ts.map +1 -0
- package/dist/types/constructable/prompts.d.ts +41 -0
- package/dist/types/constructable/prompts.d.ts.map +1 -0
- package/dist/types/date/date.d.ts +258 -0
- package/dist/types/date/date.d.ts.map +1 -0
- package/dist/types/date/index.d.ts +6 -0
- package/dist/types/date/index.d.ts.map +1 -0
- package/dist/types/date/prompts.d.ts +93 -0
- package/dist/types/date/prompts.d.ts.map +1 -0
- package/dist/types/error/error.d.ts +191 -0
- package/dist/types/error/error.d.ts.map +1 -0
- package/dist/types/error/index.d.ts +6 -0
- package/dist/types/error/index.d.ts.map +1 -0
- package/dist/types/error/prompts.d.ts +49 -0
- package/dist/types/error/prompts.d.ts.map +1 -0
- package/dist/types/event-emitter/event-emitter.d.ts +230 -0
- package/dist/types/event-emitter/event-emitter.d.ts.map +1 -0
- package/dist/types/event-emitter/index.d.ts +6 -0
- package/dist/types/event-emitter/index.d.ts.map +1 -0
- package/dist/types/event-emitter/prompts.d.ts +51 -0
- package/dist/types/event-emitter/prompts.d.ts.map +1 -0
- package/dist/types/fetch/headers.d.ts +126 -0
- package/dist/types/fetch/headers.d.ts.map +1 -0
- package/dist/types/fetch/index.d.ts +9 -0
- package/dist/types/fetch/index.d.ts.map +1 -0
- package/dist/types/fetch/prompts.d.ts +139 -0
- package/dist/types/fetch/prompts.d.ts.map +1 -0
- package/dist/types/fetch/request.d.ts +188 -0
- package/dist/types/fetch/request.d.ts.map +1 -0
- package/dist/types/fetch/response.d.ts +155 -0
- package/dist/types/fetch/response.d.ts.map +1 -0
- package/dist/types/form-data/form-data.d.ts +277 -0
- package/dist/types/form-data/form-data.d.ts.map +1 -0
- package/dist/types/form-data/index.d.ts +7 -0
- package/dist/types/form-data/index.d.ts.map +1 -0
- package/dist/types/form-data/prompts.d.ts +80 -0
- package/dist/types/form-data/prompts.d.ts.map +1 -0
- package/dist/types/index.d.ts +29 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/map/index.d.ts +6 -0
- package/dist/types/map/index.d.ts.map +1 -0
- package/dist/types/map/map.d.ts +204 -0
- package/dist/types/map/map.d.ts.map +1 -0
- package/dist/types/map/prompts.d.ts +56 -0
- package/dist/types/map/prompts.d.ts.map +1 -0
- package/dist/types/never/index.d.ts +5 -0
- package/dist/types/never/index.d.ts.map +1 -0
- package/dist/types/never/never.d.ts +220 -0
- package/dist/types/never/never.d.ts.map +1 -0
- package/dist/types/never/prompts.d.ts +50 -0
- package/dist/types/never/prompts.d.ts.map +1 -0
- package/dist/types/object/index.d.ts +6 -0
- package/dist/types/object/index.d.ts.map +1 -0
- package/dist/types/object/object.d.ts +162 -0
- package/dist/types/object/object.d.ts.map +1 -0
- package/dist/types/object/prompts.d.ts +55 -0
- package/dist/types/object/prompts.d.ts.map +1 -0
- package/dist/types/object-literal/index.d.ts +6 -0
- package/dist/types/object-literal/index.d.ts.map +1 -0
- package/dist/types/object-literal/object-literal.d.ts +223 -0
- package/dist/types/object-literal/object-literal.d.ts.map +1 -0
- package/dist/types/object-literal/prompts.d.ts +49 -0
- package/dist/types/object-literal/prompts.d.ts.map +1 -0
- package/dist/types/promise/index.d.ts +6 -0
- package/dist/types/promise/index.d.ts.map +1 -0
- package/dist/types/promise/promise.d.ts +240 -0
- package/dist/types/promise/promise.d.ts.map +1 -0
- package/dist/types/promise/prompts.d.ts +45 -0
- package/dist/types/promise/prompts.d.ts.map +1 -0
- package/dist/types/record/index.d.ts +5 -0
- package/dist/types/record/index.d.ts.map +1 -0
- package/dist/types/record/prompts.d.ts +45 -0
- package/dist/types/record/prompts.d.ts.map +1 -0
- package/dist/types/record/record.d.ts +179 -0
- package/dist/types/record/record.d.ts.map +1 -0
- package/dist/types/regexp/index.d.ts +7 -0
- package/dist/types/regexp/index.d.ts.map +1 -0
- package/dist/types/regexp/prompts.d.ts +56 -0
- package/dist/types/regexp/prompts.d.ts.map +1 -0
- package/dist/types/regexp/regexp.d.ts +160 -0
- package/dist/types/regexp/regexp.d.ts.map +1 -0
- package/dist/types/set/index.d.ts +6 -0
- package/dist/types/set/index.d.ts.map +1 -0
- package/dist/types/set/prompts.d.ts +60 -0
- package/dist/types/set/prompts.d.ts.map +1 -0
- package/dist/types/set/set.d.ts +261 -0
- package/dist/types/set/set.d.ts.map +1 -0
- package/dist/types/streams/index.d.ts +8 -0
- package/dist/types/streams/index.d.ts.map +1 -0
- package/dist/types/streams/prompts.d.ts +53 -0
- package/dist/types/streams/prompts.d.ts.map +1 -0
- package/dist/types/streams/readable-stream.d.ts +148 -0
- package/dist/types/streams/readable-stream.d.ts.map +1 -0
- package/dist/types/streams/transform-stream.d.ts +67 -0
- package/dist/types/streams/transform-stream.d.ts.map +1 -0
- package/dist/types/streams/writable-stream.d.ts +111 -0
- package/dist/types/streams/writable-stream.d.ts.map +1 -0
- package/dist/types/text-codec/index.d.ts +12 -0
- package/dist/types/text-codec/index.d.ts.map +1 -0
- package/dist/types/text-codec/prompts.d.ts +79 -0
- package/dist/types/text-codec/prompts.d.ts.map +1 -0
- package/dist/types/text-codec/text-codec.d.ts +305 -0
- package/dist/types/text-codec/text-codec.d.ts.map +1 -0
- package/dist/types/tuple/index.d.ts +6 -0
- package/dist/types/tuple/index.d.ts.map +1 -0
- package/dist/types/tuple/prompts.d.ts +41 -0
- package/dist/types/tuple/prompts.d.ts.map +1 -0
- package/dist/types/tuple/tuple.d.ts +221 -0
- package/dist/types/tuple/tuple.d.ts.map +1 -0
- package/dist/types/unknown/index.d.ts +5 -0
- package/dist/types/unknown/index.d.ts.map +1 -0
- package/dist/types/unknown/prompts.d.ts +45 -0
- package/dist/types/unknown/prompts.d.ts.map +1 -0
- package/dist/types/unknown/unknown.d.ts +220 -0
- package/dist/types/unknown/unknown.d.ts.map +1 -0
- package/dist/types/url/index.d.ts +7 -0
- package/dist/types/url/index.d.ts.map +1 -0
- package/dist/types/url/prompts.d.ts +93 -0
- package/dist/types/url/prompts.d.ts.map +1 -0
- package/dist/types/url/url.d.ts +270 -0
- package/dist/types/url/url.d.ts.map +1 -0
- package/package.json +73 -0
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SemanticVoid
|
|
3
|
+
* A void type with LLM-powered semantic understanding
|
|
4
|
+
*
|
|
5
|
+
* Provides static methods to analyze void-returning functions,
|
|
6
|
+
* understand their side effects, and validate proper usage patterns.
|
|
7
|
+
*/
|
|
8
|
+
import type { LLMClient } from '../../llm/client.ts';
|
|
9
|
+
import type { AppropriateResult } from '../../shared/types.ts';
|
|
10
|
+
export type { AppropriateResult } from '../../shared/types.ts';
|
|
11
|
+
/** Result of analyzing side effects */
|
|
12
|
+
export interface AnalyzeSideEffectsResult {
|
|
13
|
+
hasSideEffects: boolean;
|
|
14
|
+
effects: string[];
|
|
15
|
+
pure: boolean;
|
|
16
|
+
}
|
|
17
|
+
/** Result of checking if function should return a value */
|
|
18
|
+
export interface ShouldReturnValueResult {
|
|
19
|
+
shouldReturn: boolean;
|
|
20
|
+
reason: string;
|
|
21
|
+
suggestedType?: string;
|
|
22
|
+
}
|
|
23
|
+
/** Result of validating void function usage */
|
|
24
|
+
export interface ValidateUsageResult {
|
|
25
|
+
appropriate: boolean;
|
|
26
|
+
reason: string;
|
|
27
|
+
suggestion?: string;
|
|
28
|
+
}
|
|
29
|
+
/** Result of checking error handling */
|
|
30
|
+
export interface CheckErrorHandlingResult {
|
|
31
|
+
hasErrorHandling: boolean;
|
|
32
|
+
risks: string[];
|
|
33
|
+
recommendation: string;
|
|
34
|
+
}
|
|
35
|
+
/** Result of suggesting improved signature */
|
|
36
|
+
export interface SuggestSignatureResult {
|
|
37
|
+
current: string;
|
|
38
|
+
suggested: string;
|
|
39
|
+
reason: string;
|
|
40
|
+
}
|
|
41
|
+
/** Type for void-returning functions */
|
|
42
|
+
export type VoidFunction = (...args: any[]) => void;
|
|
43
|
+
/**
|
|
44
|
+
* SemanticVoid - Void with LLM-powered semantic understanding
|
|
45
|
+
*
|
|
46
|
+
* Unlike plain void that only represents absence of return,
|
|
47
|
+
* SemanticVoid provides tools to analyze void functions,
|
|
48
|
+
* understand their side effects, and validate proper usage.
|
|
49
|
+
*
|
|
50
|
+
* All methods are static since void cannot be instantiated.
|
|
51
|
+
*/
|
|
52
|
+
export declare class SemanticVoid {
|
|
53
|
+
/**
|
|
54
|
+
* Analyze a void-returning function for its side effects.
|
|
55
|
+
*
|
|
56
|
+
* @param fn - Function to analyze
|
|
57
|
+
* @param client - Optional LLM client for dependency injection
|
|
58
|
+
* @returns Side effect analysis
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* await SemanticVoid.analyzeSideEffects(saveToDatabase)
|
|
62
|
+
* // {
|
|
63
|
+
* // hasSideEffects: true,
|
|
64
|
+
* // effects: ["database write", "logging"],
|
|
65
|
+
* // pure: false
|
|
66
|
+
* // }
|
|
67
|
+
*/
|
|
68
|
+
static analyzeSideEffects(fn: VoidFunction, client?: LLMClient): Promise<AnalyzeSideEffectsResult>;
|
|
69
|
+
/**
|
|
70
|
+
* Check if a function should actually return a value.
|
|
71
|
+
*
|
|
72
|
+
* @param fn - Function to analyze
|
|
73
|
+
* @param context - Context about the function's purpose
|
|
74
|
+
* @param client - Optional LLM client for dependency injection
|
|
75
|
+
* @returns Analysis with recommendation
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* await SemanticVoid.shouldReturnValue(processData, "data processing function")
|
|
79
|
+
* // {
|
|
80
|
+
* // shouldReturn: true,
|
|
81
|
+
* // reason: "Processing functions typically return the processed result",
|
|
82
|
+
* // suggestedType: "ProcessedData"
|
|
83
|
+
* // }
|
|
84
|
+
*/
|
|
85
|
+
static shouldReturnValue(fn: VoidFunction, context?: string, client?: LLMClient): Promise<ShouldReturnValueResult>;
|
|
86
|
+
/**
|
|
87
|
+
* Explain what a void function does.
|
|
88
|
+
*
|
|
89
|
+
* @param fn - Function to explain
|
|
90
|
+
* @param client - Optional LLM client for dependency injection
|
|
91
|
+
* @returns Human-readable explanation
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* await SemanticVoid.explain(sendNotification)
|
|
95
|
+
* // "Sends a notification to the user without returning a result. Side effects: network request, logging."
|
|
96
|
+
*/
|
|
97
|
+
static explain(fn: VoidFunction, client?: LLMClient): Promise<string>;
|
|
98
|
+
/**
|
|
99
|
+
* Validate that a void function is used appropriately.
|
|
100
|
+
*
|
|
101
|
+
* @param fn - Function to validate
|
|
102
|
+
* @param usage - How the function is being used
|
|
103
|
+
* @param client - Optional LLM client for dependency injection
|
|
104
|
+
* @returns Validation result
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* await SemanticVoid.validateUsage(logError, "in array.map()")
|
|
108
|
+
* // {
|
|
109
|
+
* // appropriate: false,
|
|
110
|
+
* // reason: "Void functions in map() lose return value, use forEach() instead"
|
|
111
|
+
* // }
|
|
112
|
+
*/
|
|
113
|
+
static validateUsage(fn: VoidFunction, usage: string, client?: LLMClient): Promise<ValidateUsageResult>;
|
|
114
|
+
/**
|
|
115
|
+
* Detect if a void function is missing error handling.
|
|
116
|
+
*
|
|
117
|
+
* @param fn - Function to analyze
|
|
118
|
+
* @param client - Optional LLM client for dependency injection
|
|
119
|
+
* @returns Error handling assessment
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* await SemanticVoid.checkErrorHandling(saveData)
|
|
123
|
+
* // {
|
|
124
|
+
* // hasErrorHandling: false,
|
|
125
|
+
* // risks: ["Database errors will be silently ignored"],
|
|
126
|
+
* // recommendation: "Add try-catch or return Promise to propagate errors"
|
|
127
|
+
* // }
|
|
128
|
+
*/
|
|
129
|
+
static checkErrorHandling(fn: VoidFunction, client?: LLMClient): Promise<CheckErrorHandlingResult>;
|
|
130
|
+
/**
|
|
131
|
+
* Suggest a better signature for a void function.
|
|
132
|
+
*
|
|
133
|
+
* @param fn - Function to analyze
|
|
134
|
+
* @param client - Optional LLM client for dependency injection
|
|
135
|
+
* @returns Suggested improvements
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* await SemanticVoid.suggestSignature(updateUser)
|
|
139
|
+
* // {
|
|
140
|
+
* // current: "(user: User) => void",
|
|
141
|
+
* // suggested: "(user: User) => Promise<void>",
|
|
142
|
+
* // reason: "Async operations should return Promise for error handling"
|
|
143
|
+
* // }
|
|
144
|
+
*/
|
|
145
|
+
static suggestSignature(fn: VoidFunction, client?: LLMClient): Promise<SuggestSignatureResult>;
|
|
146
|
+
/**
|
|
147
|
+
* List common patterns where void is appropriate.
|
|
148
|
+
*
|
|
149
|
+
* @returns List of appropriate void patterns
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* SemanticVoid.appropriatePatterns()
|
|
153
|
+
* // ["event handlers", "cleanup functions", "logging", "side-effect-only callbacks"]
|
|
154
|
+
*/
|
|
155
|
+
static appropriatePatterns(): string[];
|
|
156
|
+
/**
|
|
157
|
+
* Check if void is the correct return type for a function name.
|
|
158
|
+
*
|
|
159
|
+
* @param fnName - Function name to analyze
|
|
160
|
+
* @param client - Optional LLM client for dependency injection
|
|
161
|
+
* @returns Appropriateness assessment
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* await SemanticVoid.isAppropriateFor("calculateTotal")
|
|
165
|
+
* // { appropriate: false, reason: "Functions starting with 'calculate' should return a value" }
|
|
166
|
+
*
|
|
167
|
+
* await SemanticVoid.isAppropriateFor("logMessage")
|
|
168
|
+
* // { appropriate: true, reason: "Logging functions are typically void" }
|
|
169
|
+
*/
|
|
170
|
+
static isAppropriateFor(fnName: string, client?: LLMClient): Promise<AppropriateResult>;
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=void.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"void.d.ts","sourceRoot":"","sources":["../../../src/primitives/void/void.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,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CAAC;IAcnC;;;;;;;;;;OAUG;WACU,OAAO,CAClB,EAAE,EAAE,YAAY,EAChB,MAAM,CAAC,EAAE,SAAS,GACjB,OAAO,CAAC,MAAM,CAAC;IAelB;;;;;;;;;;;;;;OAcG;WACU,aAAa,CACxB,EAAE,EAAE,YAAY,EAChB,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,SAAS,GACjB,OAAO,CAAC,mBAAmB,CAAC;IAc/B;;;;;;;;;;;;;;OAcG;WACU,kBAAkB,CAC7B,EAAE,EAAE,YAAY,EAChB,MAAM,CAAC,EAAE,SAAS,GACjB,OAAO,CAAC,wBAAwB,CAAC;IAcpC;;;;;;;;;;;;;;OAcG;WACU,gBAAgB,CAC3B,EAAE,EAAE,YAAY,EAChB,MAAM,CAAC,EAAE,SAAS,GACjB,OAAO,CAAC,sBAAsB,CAAC;IAclC;;;;;;;;OAQG;IACH,MAAM,CAAC,mBAAmB,IAAI,MAAM,EAAE;IAetC;;;;;;;;;;;;;OAaG;WACU,gBAAgB,CAC3B,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,SAAS,GACjB,OAAO,CAAC,iBAAiB,CAAC;CAY9B"}
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract base classes for semantic primitives
|
|
3
|
+
*
|
|
4
|
+
* These classes provide common implementation patterns and can be extended
|
|
5
|
+
* by concrete semantic type implementations.
|
|
6
|
+
*/
|
|
7
|
+
import type { LLMClientInterface, Semantic, Comparable, Explainable, Validatable, Summarizable, SemanticAccessible } from './interfaces.ts';
|
|
8
|
+
import type { SemanticEqualsResult, ValidateResult, ConfidenceResult } from './types.ts';
|
|
9
|
+
/**
|
|
10
|
+
* Abstract base class providing common functionality for all semantic wrappers.
|
|
11
|
+
*
|
|
12
|
+
* @template T - The underlying native type being wrapped
|
|
13
|
+
*
|
|
14
|
+
* Provides:
|
|
15
|
+
* - Value storage and retrieval via valueOf()
|
|
16
|
+
* - LLM client injection and access
|
|
17
|
+
* - JSON serialization support
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* class SemanticString extends SemanticBase<string> implements Comparable<string> {
|
|
22
|
+
* constructor(value: string, client?: LLMClientInterface) {
|
|
23
|
+
* super(value, client);
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* async semanticallyEquals(other: string): Promise<SemanticEqualsResult> {
|
|
27
|
+
* // Implementation using this.llmClient
|
|
28
|
+
* }
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare abstract class SemanticBase<T> implements Semantic<T> {
|
|
33
|
+
/** The wrapped native value */
|
|
34
|
+
protected readonly value: T;
|
|
35
|
+
/** The LLM client for AI-powered operations */
|
|
36
|
+
protected readonly llmClient?: LLMClientInterface;
|
|
37
|
+
/**
|
|
38
|
+
* Create a new semantic wrapper.
|
|
39
|
+
*
|
|
40
|
+
* @param value - The value to wrap
|
|
41
|
+
* @param client - Optional LLM client for AI operations
|
|
42
|
+
*/
|
|
43
|
+
constructor(value: T, client?: LLMClientInterface);
|
|
44
|
+
/**
|
|
45
|
+
* Get the underlying native value.
|
|
46
|
+
* @returns The wrapped value
|
|
47
|
+
*/
|
|
48
|
+
valueOf(): T;
|
|
49
|
+
/**
|
|
50
|
+
* Convert to JSON-serializable format.
|
|
51
|
+
* Override in subclasses for custom serialization.
|
|
52
|
+
*/
|
|
53
|
+
toJSON(): unknown;
|
|
54
|
+
/**
|
|
55
|
+
* Get string representation.
|
|
56
|
+
*/
|
|
57
|
+
toString(): string;
|
|
58
|
+
/**
|
|
59
|
+
* Ensure LLM client is available, throw if not.
|
|
60
|
+
* @throws Error if LLM client is not configured
|
|
61
|
+
*/
|
|
62
|
+
protected requireLLMClient(): LLMClientInterface;
|
|
63
|
+
/**
|
|
64
|
+
* Check if LLM client is available.
|
|
65
|
+
*/
|
|
66
|
+
protected hasLLMClient(): boolean;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Abstract base class for semantic types that support equality comparison.
|
|
70
|
+
*
|
|
71
|
+
* @template T - The underlying native type
|
|
72
|
+
*/
|
|
73
|
+
export declare abstract class ComparableSemanticBase<T> extends SemanticBase<T> implements Comparable<T> {
|
|
74
|
+
/**
|
|
75
|
+
* Compare this value with another for semantic equivalence.
|
|
76
|
+
* Must be implemented by subclasses.
|
|
77
|
+
*
|
|
78
|
+
* @param other - The value to compare with
|
|
79
|
+
* @param options - Optional comparison options
|
|
80
|
+
* @returns Equivalence result with confidence
|
|
81
|
+
*/
|
|
82
|
+
abstract semanticallyEquals(other: unknown, options?: Record<string, unknown>): SemanticEqualsResult | Promise<SemanticEqualsResult>;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Abstract base class for semantic types that can explain themselves.
|
|
86
|
+
*
|
|
87
|
+
* @template T - The underlying native type
|
|
88
|
+
*/
|
|
89
|
+
export declare abstract class ExplainableSemanticBase<T> extends ComparableSemanticBase<T> implements Explainable {
|
|
90
|
+
/**
|
|
91
|
+
* Generate a human-readable explanation of this value.
|
|
92
|
+
* Must be implemented by subclasses.
|
|
93
|
+
*
|
|
94
|
+
* @param context - Optional context for more relevant explanation
|
|
95
|
+
* @returns Human-readable description
|
|
96
|
+
*/
|
|
97
|
+
abstract explain(context?: string): string | Promise<string>;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Abstract base class for semantic types that support validation.
|
|
101
|
+
*
|
|
102
|
+
* @template T - The underlying native type
|
|
103
|
+
*/
|
|
104
|
+
export declare abstract class ValidatableSemanticBase<T> extends ExplainableSemanticBase<T> implements Validatable {
|
|
105
|
+
/**
|
|
106
|
+
* Validate the value against semantic rules.
|
|
107
|
+
* Must be implemented by subclasses.
|
|
108
|
+
*
|
|
109
|
+
* @param rules - Natural language validation rules
|
|
110
|
+
* @returns Validation result with issues
|
|
111
|
+
*/
|
|
112
|
+
abstract validate(rules: string[]): ValidateResult | Promise<ValidateResult>;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Abstract base class for semantic collection types (Array, Set).
|
|
116
|
+
*
|
|
117
|
+
* @template T - The element type
|
|
118
|
+
* @template TSelf - The concrete collection type (for fluent returns)
|
|
119
|
+
*/
|
|
120
|
+
export declare abstract class SemanticCollectionBase<T, TSelf> extends SemanticBase<T[]> implements Summarizable {
|
|
121
|
+
/**
|
|
122
|
+
* Get the number of elements in the collection.
|
|
123
|
+
*/
|
|
124
|
+
get length(): number;
|
|
125
|
+
/**
|
|
126
|
+
* Check if the collection is empty.
|
|
127
|
+
*/
|
|
128
|
+
isEmpty(): boolean;
|
|
129
|
+
/**
|
|
130
|
+
* Get an element at a specific index.
|
|
131
|
+
* @param index - The index of the element
|
|
132
|
+
* @returns The element at the index, or undefined if out of bounds
|
|
133
|
+
*/
|
|
134
|
+
at(index: number): T | undefined;
|
|
135
|
+
/**
|
|
136
|
+
* Get all elements as an array.
|
|
137
|
+
* @returns Copy of the underlying array
|
|
138
|
+
*/
|
|
139
|
+
toArray(): T[];
|
|
140
|
+
/**
|
|
141
|
+
* Check if the collection includes a specific element.
|
|
142
|
+
* @param element - The element to search for
|
|
143
|
+
* @returns true if the element is found
|
|
144
|
+
*/
|
|
145
|
+
includes(element: T): boolean;
|
|
146
|
+
/**
|
|
147
|
+
* Generate a summary of the collection contents.
|
|
148
|
+
* Must be implemented by subclasses.
|
|
149
|
+
*
|
|
150
|
+
* @param options - Optional summarization options
|
|
151
|
+
* @returns Human-readable summary
|
|
152
|
+
*/
|
|
153
|
+
abstract summarize(options?: {
|
|
154
|
+
maxLength?: number;
|
|
155
|
+
focus?: string;
|
|
156
|
+
}): string | Promise<string>;
|
|
157
|
+
/**
|
|
158
|
+
* Filter elements using natural language criteria.
|
|
159
|
+
* Must be implemented by subclasses.
|
|
160
|
+
*
|
|
161
|
+
* @param criteria - Natural language filter condition
|
|
162
|
+
* @returns Filtered collection
|
|
163
|
+
*/
|
|
164
|
+
abstract semanticFilter(criteria: string): TSelf | Promise<TSelf>;
|
|
165
|
+
/**
|
|
166
|
+
* Group elements by semantic criteria.
|
|
167
|
+
* Must be implemented by subclasses.
|
|
168
|
+
*
|
|
169
|
+
* @param criteria - Grouping criteria
|
|
170
|
+
* @returns Map of groups
|
|
171
|
+
*/
|
|
172
|
+
abstract semanticGroup(criteria: string): Map<string, TSelf> | Promise<Map<string, TSelf>>;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Abstract base class for semantic key-value collection types (Object, Map, Record).
|
|
176
|
+
*
|
|
177
|
+
* @template K - The key type
|
|
178
|
+
* @template V - The value type
|
|
179
|
+
* @template TSelf - The concrete collection type (for fluent returns)
|
|
180
|
+
*/
|
|
181
|
+
export declare abstract class SemanticKeyValueBase<K, V, TSelf> extends SemanticBase<Map<K, V> | Record<string, V>> implements SemanticAccessible<K, V>, Summarizable {
|
|
182
|
+
/**
|
|
183
|
+
* Get a value using semantic key matching.
|
|
184
|
+
* Must be implemented by subclasses.
|
|
185
|
+
*
|
|
186
|
+
* @param query - Key or semantic query
|
|
187
|
+
* @param context - Optional context
|
|
188
|
+
* @returns Value with match confidence
|
|
189
|
+
*/
|
|
190
|
+
abstract semanticGet(query: string, context?: Record<string, unknown>): {
|
|
191
|
+
value: V | undefined;
|
|
192
|
+
matchedKey: K | undefined;
|
|
193
|
+
confidence: number;
|
|
194
|
+
} | Promise<{
|
|
195
|
+
value: V | undefined;
|
|
196
|
+
matchedKey: K | undefined;
|
|
197
|
+
confidence: number;
|
|
198
|
+
}>;
|
|
199
|
+
/**
|
|
200
|
+
* Generate a summary of the collection contents.
|
|
201
|
+
* Must be implemented by subclasses.
|
|
202
|
+
*/
|
|
203
|
+
abstract summarize(options?: {
|
|
204
|
+
maxLength?: number;
|
|
205
|
+
focus?: string;
|
|
206
|
+
}): string | Promise<string>;
|
|
207
|
+
/**
|
|
208
|
+
* Merge with another collection using semantic key matching.
|
|
209
|
+
* Must be implemented by subclasses.
|
|
210
|
+
*/
|
|
211
|
+
abstract semanticMerge(other: unknown, options?: {
|
|
212
|
+
conflictResolution?: 'prefer-this' | 'prefer-other' | 'combine';
|
|
213
|
+
}): TSelf | Promise<TSelf>;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Abstract base class for semantic callable types (Function, Callable).
|
|
217
|
+
*
|
|
218
|
+
* @template TFn - The function type
|
|
219
|
+
*/
|
|
220
|
+
export declare abstract class SemanticCallableBase<TFn extends (...args: unknown[]) => unknown> extends SemanticBase<TFn> implements Explainable {
|
|
221
|
+
/** Optional description of what the function does */
|
|
222
|
+
protected readonly description?: string;
|
|
223
|
+
/**
|
|
224
|
+
* Create a semantic callable wrapper.
|
|
225
|
+
*
|
|
226
|
+
* @param fn - The function to wrap
|
|
227
|
+
* @param description - Optional description
|
|
228
|
+
* @param client - Optional LLM client
|
|
229
|
+
*/
|
|
230
|
+
constructor(fn: TFn, description?: string, client?: LLMClientInterface);
|
|
231
|
+
/**
|
|
232
|
+
* Call the underlying function.
|
|
233
|
+
*
|
|
234
|
+
* @param args - Arguments to pass to the function
|
|
235
|
+
* @returns The function's return value
|
|
236
|
+
*/
|
|
237
|
+
call(...args: Parameters<TFn>): ReturnType<TFn>;
|
|
238
|
+
/**
|
|
239
|
+
* Generate a human-readable explanation of what the function does.
|
|
240
|
+
* Must be implemented by subclasses.
|
|
241
|
+
*/
|
|
242
|
+
abstract explain(context?: string): string | Promise<string>;
|
|
243
|
+
/**
|
|
244
|
+
* Validate function arguments.
|
|
245
|
+
* Must be implemented by subclasses.
|
|
246
|
+
*/
|
|
247
|
+
abstract validateArgs(args: unknown[], rules?: string[]): ValidateResult | Promise<ValidateResult>;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Abstract base class for semantic absence types (Null, Undefined).
|
|
251
|
+
*
|
|
252
|
+
* @template T - The absence type (null or undefined)
|
|
253
|
+
*/
|
|
254
|
+
export declare abstract class SemanticAbsenceBase<T extends null | undefined> extends SemanticBase<T> {
|
|
255
|
+
/** The reason for the absence, if provided */
|
|
256
|
+
protected readonly reason?: string;
|
|
257
|
+
/**
|
|
258
|
+
* Create a semantic absence wrapper.
|
|
259
|
+
*
|
|
260
|
+
* @param value - The absence value (null or undefined)
|
|
261
|
+
* @param reason - Optional reason for the absence
|
|
262
|
+
* @param client - Optional LLM client
|
|
263
|
+
*/
|
|
264
|
+
constructor(value: T, reason?: string, client?: LLMClientInterface);
|
|
265
|
+
/**
|
|
266
|
+
* Get the reason for absence, if provided.
|
|
267
|
+
*/
|
|
268
|
+
getReason(): string | undefined;
|
|
269
|
+
/**
|
|
270
|
+
* Check if a reason was provided.
|
|
271
|
+
*/
|
|
272
|
+
hasReason(): boolean;
|
|
273
|
+
/**
|
|
274
|
+
* Classify the type of absence.
|
|
275
|
+
* Must be implemented by subclasses.
|
|
276
|
+
*/
|
|
277
|
+
abstract classify(): {
|
|
278
|
+
type: 'not-set' | 'not-applicable' | 'unknown';
|
|
279
|
+
canBeProvided: boolean;
|
|
280
|
+
} | Promise<{
|
|
281
|
+
type: 'not-set' | 'not-applicable' | 'unknown';
|
|
282
|
+
canBeProvided: boolean;
|
|
283
|
+
}>;
|
|
284
|
+
/**
|
|
285
|
+
* Generate a human-readable explanation.
|
|
286
|
+
* Must be implemented by subclasses.
|
|
287
|
+
*/
|
|
288
|
+
abstract explain(fieldName: string): string | Promise<string>;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Builder for creating consistent result objects.
|
|
292
|
+
* Useful for constructing SemanticEqualsResult and similar types.
|
|
293
|
+
*
|
|
294
|
+
* @template T - The result type being built
|
|
295
|
+
*/
|
|
296
|
+
export declare class ResultBuilder<T extends ConfidenceResult> {
|
|
297
|
+
private result;
|
|
298
|
+
/**
|
|
299
|
+
* Set the confidence score.
|
|
300
|
+
*/
|
|
301
|
+
withConfidence(confidence: number): this;
|
|
302
|
+
/**
|
|
303
|
+
* Add a property to the result.
|
|
304
|
+
*/
|
|
305
|
+
with<K extends keyof T>(key: K, value: T[K]): this;
|
|
306
|
+
/**
|
|
307
|
+
* Build the final result object.
|
|
308
|
+
*/
|
|
309
|
+
build(): T;
|
|
310
|
+
/**
|
|
311
|
+
* Create a new builder instance.
|
|
312
|
+
*/
|
|
313
|
+
static create<T extends ConfidenceResult>(): ResultBuilder<T>;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Type guard to check if a value is a Semantic wrapper.
|
|
317
|
+
*/
|
|
318
|
+
export declare function isSemantic<T>(value: unknown): value is Semantic<T>;
|
|
319
|
+
/**
|
|
320
|
+
* Type guard to check if a value is Comparable.
|
|
321
|
+
*/
|
|
322
|
+
export declare function isComparable<T>(value: unknown): value is Comparable<T>;
|
|
323
|
+
/**
|
|
324
|
+
* Type guard to check if a value is Explainable.
|
|
325
|
+
*/
|
|
326
|
+
export declare function isExplainable(value: unknown): value is Explainable;
|
|
327
|
+
/**
|
|
328
|
+
* Type guard to check if a value is Validatable.
|
|
329
|
+
*/
|
|
330
|
+
export declare function isValidatable(value: unknown): value is Validatable;
|
|
331
|
+
//# sourceMappingURL=base-classes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-classes.d.ts","sourceRoot":"","sources":["../../src/shared/base-classes.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,kBAAkB,EAClB,QAAQ,EACR,UAAU,EACV,WAAW,EACX,WAAW,EACX,YAAY,EACZ,kBAAkB,EACnB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EACV,oBAAoB,EACpB,cAAc,EACd,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAMpB;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,8BAAsB,YAAY,CAAC,CAAC,CAAE,YAAW,QAAQ,CAAC,CAAC,CAAC;IAC1D,+BAA+B;IAC/B,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;IAE5B,+CAA+C;IAC/C,SAAS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,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAAC,CAAC,CAAC,CAOlE;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAAC,CAAC,CAAC,CAMtE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAOlE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAOlE"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for evaluation data files
|
|
3
|
+
*
|
|
4
|
+
* These types are used by evaluation datasets in src/primitives/<type>/evals/
|
|
5
|
+
* and src/types/<type>/evals/ directories.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Numeric range for flexible matching of expected values
|
|
9
|
+
*/
|
|
10
|
+
export interface NumericRange {
|
|
11
|
+
min?: number;
|
|
12
|
+
max?: number;
|
|
13
|
+
exact?: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Expected value can be exact, a range, or nested structures
|
|
17
|
+
*/
|
|
18
|
+
export type ExpectedValue = string | number | boolean | null | undefined | NumericRange | ExpectedValue[] | {
|
|
19
|
+
[key: string]: ExpectedValue;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Difficulty levels for test cases
|
|
23
|
+
*/
|
|
24
|
+
export type Difficulty = 'easy' | 'medium' | 'hard';
|
|
25
|
+
/**
|
|
26
|
+
* Input configuration for a test case
|
|
27
|
+
*/
|
|
28
|
+
export interface EvalInput {
|
|
29
|
+
/** Primary value to instantiate the semantic type */
|
|
30
|
+
value: unknown;
|
|
31
|
+
/** Arguments to pass to the method being tested */
|
|
32
|
+
args?: unknown[];
|
|
33
|
+
/** Options/context to pass to the method */
|
|
34
|
+
options?: Record<string, unknown>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A single test case in an evaluation dataset
|
|
38
|
+
*/
|
|
39
|
+
export interface EvalCase {
|
|
40
|
+
/** Unique identifier for the test case */
|
|
41
|
+
id: string;
|
|
42
|
+
/** Human-readable description of what's being tested */
|
|
43
|
+
description: string;
|
|
44
|
+
/** Input configuration */
|
|
45
|
+
input: EvalInput;
|
|
46
|
+
/** Expected output - can be exact values or ranges */
|
|
47
|
+
expected: Record<string, ExpectedValue>;
|
|
48
|
+
/** Criteria for LLM judge evaluation */
|
|
49
|
+
criteria: string[];
|
|
50
|
+
/** Tags for filtering and grouping */
|
|
51
|
+
tags?: string[];
|
|
52
|
+
/** Difficulty level (affects scoring weight) */
|
|
53
|
+
difficulty?: Difficulty;
|
|
54
|
+
/** Skip this case (for WIP or known issues) */
|
|
55
|
+
skip?: boolean;
|
|
56
|
+
/** Reason for skipping */
|
|
57
|
+
skipReason?: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Complete evaluation dataset for a semantic operation
|
|
61
|
+
*/
|
|
62
|
+
export interface EvalDataset {
|
|
63
|
+
/** Dataset name (e.g., 'SemanticString.semanticallyEquals') */
|
|
64
|
+
name: string;
|
|
65
|
+
/** Description of what's being tested */
|
|
66
|
+
description: string;
|
|
67
|
+
/** Version for tracking changes */
|
|
68
|
+
version: string;
|
|
69
|
+
/** Target class name (e.g., 'SemanticString') */
|
|
70
|
+
targetClass: string;
|
|
71
|
+
/** Target method name (e.g., 'semanticallyEquals') */
|
|
72
|
+
targetMethod: string;
|
|
73
|
+
/** Whether the method is static (e.g., 'from') */
|
|
74
|
+
isStaticMethod?: boolean;
|
|
75
|
+
/** Factory method to create instance (defaults to 'from') */
|
|
76
|
+
factoryMethod?: string;
|
|
77
|
+
/** Whether factory method is async */
|
|
78
|
+
factoryAsync?: boolean;
|
|
79
|
+
/** All test cases */
|
|
80
|
+
cases: EvalCase[];
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL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AAC;IACf,0BAA0B;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,+DAA+D;IAC/D,IAAI,EAAE,MAAM,CAAC;IACb,yCAAyC;IACzC,WAAW,EAAE,MAAM,CAAC;IACpB,mCAAmC;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,iDAAiD;IACjD,WAAW,EAAE,MAAM,CAAC;IACpB,sDAAsD;IACtD,YAAY,EAAE,MAAM,CAAC;IACrB,kDAAkD;IAClD,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,6DAA6D;IAC7D,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,sCAAsC;IACtC,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,qBAAqB;IACrB,KAAK,EAAE,QAAQ,EAAE,CAAC;CACnB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared utilities and types
|
|
3
|
+
*/
|
|
4
|
+
export { type ConfidenceResult, type SemanticEqualsResult, type SemanticEqualsResultWithReason, type SemanticEqualsResultWithMappings, } from './types.ts';
|
|
5
|
+
export { type ClassifyResult, type InferTypeResult, type InferPurposeResult, } from './types.ts';
|
|
6
|
+
export { type ValidateResult, type ValidateResultWithWarnings, type ReasonableResult, type AppropriateResult, } from './types.ts';
|
|
7
|
+
export { type Suggestion, type MissingSuggestion, type RelatedSuggestion, type ImprovementSuggestion, type Correction, } from './types.ts';
|
|
8
|
+
export { type SemanticGetResult, type SearchResult, } from './types.ts';
|
|
9
|
+
export { type SeverityLevel, type ExtendedSeverityLevel, type ErrorSeverityLevel, type SafetyResult, type SensitiveResult, } from './types.ts';
|
|
10
|
+
export { type DetectIntentResult, type DetectLanguageResult, type DetectPatternResult, type InferUnitResult, type InferDomainResult, type InferMeaningResult, type InferReasonResult, type InferSchemaResult, } from './types.ts';
|
|
11
|
+
export { type ExplanationResult, type DurationResult, } from './types.ts';
|
|
12
|
+
export { type DetectedIssue, type RootCauseResult, type SuggestedFix, type RecoveryStrategy, } from './types.ts';
|
|
13
|
+
export { type GeneratedTestCase, type RegExpTestCases, } from './types.ts';
|
|
14
|
+
export { type LLMClientInterface, type LLMCompletionOptions, } from './interfaces.ts';
|
|
15
|
+
export { type Semantic, type SemanticFactory, } from './interfaces.ts';
|
|
16
|
+
export { type Comparable, type Explainable, type Describable, type Validatable, type ContextValidatable, type PurposeValidatable, type TypeInferable, type PurposeInferable, type SchemaInferable, type Classifiable, type PatternDetectable, type Suggestible, type Summarizable, type SafetyAssessable, type SensitivityDetectable, } from './interfaces.ts';
|
|
17
|
+
export { type SemanticFilterable, type SemanticSortable, type SemanticGroupable, type SemanticSearchable, type SemanticAccessible, type SemanticSetOperations, type SemanticMergeable, } from './interfaces.ts';
|
|
18
|
+
export { type SemanticAbsence, type SemanticAbsenceFactory, type SemanticCollection, type SemanticKeyValueCollection, type SemanticCallableType, } from './interfaces.ts';
|
|
19
|
+
export { type KeyTransformable, type UnitConvertible, } from './interfaces.ts';
|
|
20
|
+
export { type TestGeneratable, type RegExpTestGeneratable, } from './interfaces.ts';
|
|
21
|
+
export { type SemanticErrorType } from './interfaces.ts';
|
|
22
|
+
export { type SemanticPrimitiveCapabilities, type SemanticPrimitiveExtended, type SemanticReferenceCapabilities, } from './interfaces.ts';
|
|
23
|
+
export { SemanticBase, ComparableSemanticBase, ExplainableSemanticBase, ValidatableSemanticBase, SemanticCollectionBase, SemanticKeyValueBase, SemanticCallableBase, SemanticAbsenceBase, ResultBuilder, } from './base-classes.ts';
|
|
24
|
+
export { isSemantic, isComparable, isExplainable, isValidatable, } from './base-classes.ts';
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,KA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