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,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SemanticTuple
|
|
3
|
+
* A tuple type with LLM-powered semantic understanding
|
|
4
|
+
*
|
|
5
|
+
* Implements shared interfaces:
|
|
6
|
+
* - Semantic<T> - Base semantic wrapper
|
|
7
|
+
* - Comparable<SemanticTuple<T>> - Semantic equality comparison
|
|
8
|
+
* - Explainable - Human-readable explanations
|
|
9
|
+
* - PatternDetectable - Pattern detection
|
|
10
|
+
*/
|
|
11
|
+
import type { LLMClient } from '../../llm/client.ts';
|
|
12
|
+
import type { SemanticEqualsResultWithReason, DetectPatternResult } from '../../shared/types.ts';
|
|
13
|
+
import type { Semantic, Comparable, Explainable } from '../../shared/interfaces.ts';
|
|
14
|
+
export type { SemanticEqualsResultWithReason, DetectPatternResult, } from '../../shared/types.ts';
|
|
15
|
+
/** Result of inferring positional meaning */
|
|
16
|
+
export interface PositionalMeaning {
|
|
17
|
+
meaning: string;
|
|
18
|
+
confidence: number;
|
|
19
|
+
}
|
|
20
|
+
/** Result of inferPositionalMeaning */
|
|
21
|
+
export interface InferPositionalMeaningResult {
|
|
22
|
+
positions: Record<number, PositionalMeaning>;
|
|
23
|
+
overallConfidence: number;
|
|
24
|
+
}
|
|
25
|
+
/** Result of validateRelationship */
|
|
26
|
+
export interface ValidateRelationshipResult {
|
|
27
|
+
valid: boolean;
|
|
28
|
+
violations: string[];
|
|
29
|
+
}
|
|
30
|
+
/** Result of toObject */
|
|
31
|
+
export interface ToObjectResult {
|
|
32
|
+
object: Record<string, unknown>;
|
|
33
|
+
labelsUsed: string[];
|
|
34
|
+
confidence: number;
|
|
35
|
+
}
|
|
36
|
+
/** Result of getByLabel */
|
|
37
|
+
export interface GetByLabelResult<T> {
|
|
38
|
+
value: T | undefined;
|
|
39
|
+
matchedPosition: number | undefined;
|
|
40
|
+
confidence: number;
|
|
41
|
+
}
|
|
42
|
+
/** Issue found during structure validation */
|
|
43
|
+
export interface StructureIssue {
|
|
44
|
+
position: number;
|
|
45
|
+
expected: string;
|
|
46
|
+
actual: string;
|
|
47
|
+
}
|
|
48
|
+
/** Result of validateStructure */
|
|
49
|
+
export interface ValidateStructureResult {
|
|
50
|
+
valid: boolean;
|
|
51
|
+
issues: StructureIssue[];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* SemanticTuple - Tuple with LLM-powered semantic understanding
|
|
55
|
+
*
|
|
56
|
+
* Unlike traditional tuples that only support index-based operations,
|
|
57
|
+
* semantic tuples can understand positional meaning, detect patterns,
|
|
58
|
+
* and validate relationships between elements.
|
|
59
|
+
*
|
|
60
|
+
* @template T - The tuple type
|
|
61
|
+
*/
|
|
62
|
+
export declare class SemanticTuple<T extends unknown[]> implements Semantic<T>, Comparable<SemanticTuple<T> | unknown[], SemanticEqualsResultWithReason>, Explainable {
|
|
63
|
+
private readonly elements;
|
|
64
|
+
private readonly client;
|
|
65
|
+
private readonly labels;
|
|
66
|
+
private constructor();
|
|
67
|
+
/**
|
|
68
|
+
* Create a SemanticTuple from values with optional position labels.
|
|
69
|
+
*
|
|
70
|
+
* @param values - Tuple values
|
|
71
|
+
* @param labels - Optional labels for each position
|
|
72
|
+
* @returns SemanticTuple instance
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* SemanticTuple.from([37.7749, -122.4194], ["latitude", "longitude"])
|
|
76
|
+
* SemanticTuple.from(["John", 30, true], ["name", "age", "active"])
|
|
77
|
+
*/
|
|
78
|
+
static from<T extends unknown[]>(values: T, labels?: string[], client?: LLMClient): SemanticTuple<T>;
|
|
79
|
+
/**
|
|
80
|
+
* Create an empty SemanticTuple
|
|
81
|
+
*/
|
|
82
|
+
static empty<T extends unknown[] = []>(client?: LLMClient): SemanticTuple<T>;
|
|
83
|
+
/**
|
|
84
|
+
* Get the underlying tuple value
|
|
85
|
+
*/
|
|
86
|
+
valueOf(): T;
|
|
87
|
+
/**
|
|
88
|
+
* Get the length of the tuple
|
|
89
|
+
*/
|
|
90
|
+
get length(): number;
|
|
91
|
+
/**
|
|
92
|
+
* Get the labels if provided
|
|
93
|
+
*/
|
|
94
|
+
getLabels(): string[] | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* Get element at index
|
|
97
|
+
*/
|
|
98
|
+
at(index: number): T[number] | undefined;
|
|
99
|
+
/**
|
|
100
|
+
* Check if two tuples are semantically equivalent.
|
|
101
|
+
* Considers position meanings, not just values.
|
|
102
|
+
*
|
|
103
|
+
* @param other - Tuple to compare
|
|
104
|
+
* @returns Equivalence result with confidence and reason
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* SemanticTuple.from([lat, lng]).semanticallyEquals([lat, lng, alt])
|
|
108
|
+
* // { equivalent: false, reason: "Different arity (2 vs 3)" }
|
|
109
|
+
*/
|
|
110
|
+
semanticallyEquals(other: SemanticTuple<T> | unknown[]): Promise<SemanticEqualsResultWithReason>;
|
|
111
|
+
/**
|
|
112
|
+
* Infer the meaning of each position in the tuple.
|
|
113
|
+
*
|
|
114
|
+
* @param context - Optional context to improve inference
|
|
115
|
+
* @returns Position meanings with confidence scores
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* SemanticTuple.from([37.7749, -122.4194]).inferPositionalMeaning()
|
|
119
|
+
* // { positions: { 0: { meaning: "latitude", confidence: 0.9 }, 1: { meaning: "longitude", confidence: 0.9 } } }
|
|
120
|
+
*/
|
|
121
|
+
inferPositionalMeaning(context?: string): Promise<InferPositionalMeaningResult>;
|
|
122
|
+
/**
|
|
123
|
+
* Validate relationships between tuple elements.
|
|
124
|
+
*
|
|
125
|
+
* @param rules - Validation rules
|
|
126
|
+
* @returns Validation result with any violations
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* SemanticTuple.from([startDate, endDate]).validateRelationship([
|
|
130
|
+
* "end should be after start"
|
|
131
|
+
* ])
|
|
132
|
+
* // { valid: true, violations: [] }
|
|
133
|
+
*/
|
|
134
|
+
validateRelationship(rules: string[]): Promise<ValidateRelationshipResult>;
|
|
135
|
+
/**
|
|
136
|
+
* Detect what type of tuple this is (coordinate, range, RGB, etc.).
|
|
137
|
+
*
|
|
138
|
+
* @returns Detected tuple pattern with confidence
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* SemanticTuple.from([255, 128, 0]).detectPattern()
|
|
142
|
+
* // { pattern: "RGB color", confidence: 0.95, suggestedType: "Color" }
|
|
143
|
+
*/
|
|
144
|
+
detectPattern(): Promise<DetectPatternResult>;
|
|
145
|
+
/**
|
|
146
|
+
* Convert tuple to a labeled object.
|
|
147
|
+
*
|
|
148
|
+
* @param labels - Optional custom labels (uses inferred or provided if not specified)
|
|
149
|
+
* @returns Object with labeled properties
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* SemanticTuple.from([37.7749, -122.4194]).toObject()
|
|
153
|
+
* // { latitude: 37.7749, longitude: -122.4194 }
|
|
154
|
+
*/
|
|
155
|
+
toObject(labels?: string[]): Promise<ToObjectResult>;
|
|
156
|
+
/**
|
|
157
|
+
* Access an element by semantic label instead of index.
|
|
158
|
+
*
|
|
159
|
+
* @param label - Semantic label for the position
|
|
160
|
+
* @returns Value at that position with match info
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* coords.getByLabel("latitude") // { value: 37.7749, matchedPosition: 0, confidence: 0.95 }
|
|
164
|
+
*/
|
|
165
|
+
getByLabel(label: string): Promise<GetByLabelResult<T[number]>>;
|
|
166
|
+
/**
|
|
167
|
+
* Validate that the tuple matches expected structure.
|
|
168
|
+
*
|
|
169
|
+
* @param expectedTypes - Expected type for each position
|
|
170
|
+
* @returns Validation result with issues
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* tuple.validateStructure(["string", "number", "boolean"])
|
|
174
|
+
* // { valid: true, issues: [] }
|
|
175
|
+
*/
|
|
176
|
+
validateStructure(expectedTypes: string[]): Promise<ValidateStructureResult>;
|
|
177
|
+
/**
|
|
178
|
+
* Explain what this tuple represents.
|
|
179
|
+
*
|
|
180
|
+
* @param context - Optional context for more relevant explanation
|
|
181
|
+
* @returns Human-readable explanation
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* SemanticTuple.from([200, "OK"]).explain()
|
|
185
|
+
* // "HTTP status response: status code 200 with message 'OK'"
|
|
186
|
+
*/
|
|
187
|
+
explain(context?: string): Promise<string>;
|
|
188
|
+
/**
|
|
189
|
+
* Map elements and return a new SemanticTuple
|
|
190
|
+
*/
|
|
191
|
+
map<U>(fn: (element: T[number], index: number) => U): SemanticTuple<U[]>;
|
|
192
|
+
/**
|
|
193
|
+
* Execute a function for each element
|
|
194
|
+
*/
|
|
195
|
+
forEach(fn: (element: T[number], index: number) => void): void;
|
|
196
|
+
/**
|
|
197
|
+
* Check if some element satisfies the predicate
|
|
198
|
+
*/
|
|
199
|
+
some(predicate: (element: T[number], index: number) => boolean): boolean;
|
|
200
|
+
/**
|
|
201
|
+
* Check if every element satisfies the predicate
|
|
202
|
+
*/
|
|
203
|
+
every(predicate: (element: T[number], index: number) => boolean): boolean;
|
|
204
|
+
/**
|
|
205
|
+
* Reduce the tuple to a single value
|
|
206
|
+
*/
|
|
207
|
+
reduce<U>(fn: (acc: U, element: T[number], index: number) => U, initial: U): U;
|
|
208
|
+
/**
|
|
209
|
+
* Iterator support
|
|
210
|
+
*/
|
|
211
|
+
[Symbol.iterator](): Iterator<T[number]>;
|
|
212
|
+
/**
|
|
213
|
+
* Convert to string
|
|
214
|
+
*/
|
|
215
|
+
toString(): string;
|
|
216
|
+
/**
|
|
217
|
+
* Convert to JSON
|
|
218
|
+
*/
|
|
219
|
+
toJSON(): T;
|
|
220
|
+
}
|
|
221
|
+
//# sourceMappingURL=tuple.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tuple.d.ts","sourceRoot":"","sources":["../../../src/types/tuple/tuple.ts"],"names":[],"mappings":"AAAA;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,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,CAAC;IAI9E;;OAEG;IACH,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAIxC;;OAEG;IACH,QAAQ,IAAI,MAAM;IAIlB;;OAEG;IACH,MAAM,IAAI,CAAC;CAGZ"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SemanticUnknown exports
|
|
3
|
+
*/
|
|
4
|
+
export { SemanticUnknown, type BasicType, type UnknownInferTypeResult, type TypeSuggestion, type ValidateShapeResult, type GenerateTypeGuardResult, type MatchesResult, type NarrowToResult, } from './unknown.ts';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/unknown/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,eAAe,EACf,KAAK,SAAS,EACd,KAAK,sBAAsB,EAC3B,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,uBAAuB,EAC5B,KAAK,aAAa,EAClB,KAAK,cAAc,GACpB,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompts for SemanticUnknown LLM operations
|
|
3
|
+
* These prompts are used to analyze and reason about unknown values
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* System prompt for unknown value interpretation tasks
|
|
7
|
+
*/
|
|
8
|
+
export declare const UNKNOWN_SYSTEM_PROMPT = "You are a semantic type analyzer. Your task is to analyze unknown values, infer their types, and help safely narrow them to proper TypeScript types.\n\nYou must respond with valid JSON only, no additional text or explanation.\n\nKey concepts:\n- \"unknown\" represents type-safe uncertainty\n- Type inference should consider value structure, patterns, and common conventions\n- Type guards help safely narrow unknown values\n- Confidence scores from 0.0 to 1.0 indicate certainty\n\nGuidelines:\n- Analyze value structure to determine probable types\n- Consider common naming patterns and data shapes\n- Suggest practical TypeScript types when possible\n- Generate safe type guard code that checks all necessary conditions\n- Be conservative with confidence scores for ambiguous values";
|
|
9
|
+
/**
|
|
10
|
+
* Prompt template for inferring the type of an unknown value
|
|
11
|
+
*/
|
|
12
|
+
export declare function createInferTypePrompt(value: unknown, context?: {
|
|
13
|
+
source?: string;
|
|
14
|
+
}): string;
|
|
15
|
+
/**
|
|
16
|
+
* Prompt template for suggesting possible TypeScript types
|
|
17
|
+
*/
|
|
18
|
+
export declare function createSuggestTypesPrompt(value: unknown, limit?: number): string;
|
|
19
|
+
/**
|
|
20
|
+
* Prompt template for validating value shape
|
|
21
|
+
*/
|
|
22
|
+
export declare function createValidateShapePrompt(value: unknown, description: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Prompt template for generating a type guard function
|
|
25
|
+
*/
|
|
26
|
+
export declare function createGenerateTypeGuardPrompt(value: unknown): string;
|
|
27
|
+
/**
|
|
28
|
+
* Prompt template for safe property access
|
|
29
|
+
*/
|
|
30
|
+
export declare function createSafeAccessPrompt(value: unknown, path: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* Prompt template for checking if value matches a description
|
|
33
|
+
*/
|
|
34
|
+
export declare function createMatchesPrompt(value: unknown, description: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Prompt template for narrowing to a specific type
|
|
37
|
+
*/
|
|
38
|
+
export declare function createNarrowToPrompt(value: unknown, typeName: string, validator?: string[]): string;
|
|
39
|
+
/**
|
|
40
|
+
* Prompt template for explaining what an unknown value appears to be
|
|
41
|
+
*/
|
|
42
|
+
export declare function createExplainPrompt(value: unknown, context?: {
|
|
43
|
+
source?: string;
|
|
44
|
+
}): string;
|
|
45
|
+
//# sourceMappingURL=prompts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../../src/types/unknown/prompts.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,eAAO,MAAM,qBAAqB,sxBAe4B,CAAC;AAE/D;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5B,MAAM,CAwBR;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,OAAO,EACd,KAAK,SAAI,GACR,MAAM,CAsBR;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,OAAO,EACd,WAAW,EAAE,MAAM,GAClB,MAAM,CAiBR;AAED;;GAEG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAepE;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,MAAM,GACX,MAAM,CAiBR;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,OAAO,EACd,WAAW,EAAE,MAAM,GAClB,MAAM,CAeR;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,MAAM,EAChB,SAAS,CAAC,EAAE,MAAM,EAAE,GACnB,MAAM,CAwBR;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5B,MAAM,CAwBR"}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SemanticUnknown
|
|
3
|
+
* An unknown type with LLM-powered semantic understanding
|
|
4
|
+
*
|
|
5
|
+
* Implements shared interfaces:
|
|
6
|
+
* - Semantic<unknown> - Base semantic wrapper
|
|
7
|
+
* - Explainable - Human-readable explanation
|
|
8
|
+
* - TypeInferable - Type inference capabilities
|
|
9
|
+
*
|
|
10
|
+
* Core Principle: unknown represents type-safe uncertainty - semantic
|
|
11
|
+
* operations help infer types and generate proper type guards.
|
|
12
|
+
*/
|
|
13
|
+
import type { LLMClient } from '../../llm/client.ts';
|
|
14
|
+
import type { Semantic, Explainable, TypeInferable } from '../../shared/interfaces.ts';
|
|
15
|
+
import type { ConfidenceResult, InferTypeResult } from '../../shared/types.ts';
|
|
16
|
+
/** Basic JavaScript types that can be inferred */
|
|
17
|
+
export type BasicType = 'string' | 'number' | 'boolean' | 'object' | 'array' | 'null' | 'undefined' | 'function';
|
|
18
|
+
/** Result of type inference */
|
|
19
|
+
export interface UnknownInferTypeResult extends InferTypeResult {
|
|
20
|
+
type: BasicType;
|
|
21
|
+
shape?: string;
|
|
22
|
+
confidence: number;
|
|
23
|
+
}
|
|
24
|
+
/** Type suggestion with confidence and reason */
|
|
25
|
+
export interface TypeSuggestion extends ConfidenceResult {
|
|
26
|
+
type: string;
|
|
27
|
+
reason?: string;
|
|
28
|
+
}
|
|
29
|
+
/** Result of shape validation */
|
|
30
|
+
export interface ValidateShapeResult {
|
|
31
|
+
matches: boolean;
|
|
32
|
+
missingFields: string[];
|
|
33
|
+
extraFields: string[];
|
|
34
|
+
}
|
|
35
|
+
/** Result of type guard generation */
|
|
36
|
+
export interface GenerateTypeGuardResult {
|
|
37
|
+
code: string;
|
|
38
|
+
typeName: string;
|
|
39
|
+
}
|
|
40
|
+
/** Result of matches check */
|
|
41
|
+
export interface MatchesResult extends ConfidenceResult {
|
|
42
|
+
matches: boolean;
|
|
43
|
+
}
|
|
44
|
+
/** Result of narrowTo operation */
|
|
45
|
+
export type NarrowToResult<T> = {
|
|
46
|
+
success: true;
|
|
47
|
+
value: T;
|
|
48
|
+
} | {
|
|
49
|
+
success: false;
|
|
50
|
+
errors: string[];
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* SemanticUnknown - Unknown with LLM-powered semantic understanding
|
|
54
|
+
*
|
|
55
|
+
* Unlike plain unknown that only represents type uncertainty,
|
|
56
|
+
* SemanticUnknown can infer types, validate shapes, generate type guards,
|
|
57
|
+
* and help safely narrow unknown values to proper types.
|
|
58
|
+
*
|
|
59
|
+
* Implements:
|
|
60
|
+
* - Semantic<unknown> - valueOf() returns the wrapped value
|
|
61
|
+
* - Explainable - explain() for human-readable description
|
|
62
|
+
* - TypeInferable - inferType() for type inference
|
|
63
|
+
*/
|
|
64
|
+
export declare class SemanticUnknown implements Semantic<unknown>, Explainable, TypeInferable {
|
|
65
|
+
private readonly value;
|
|
66
|
+
private readonly context;
|
|
67
|
+
private readonly client;
|
|
68
|
+
private constructor();
|
|
69
|
+
/**
|
|
70
|
+
* Wrap an unknown value with semantic capabilities.
|
|
71
|
+
*
|
|
72
|
+
* @param value - The unknown value
|
|
73
|
+
* @param context - Optional context about the value's source
|
|
74
|
+
* @param client - Optional LLM client for dependency injection
|
|
75
|
+
* @returns SemanticUnknown wrapper
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* SemanticUnknown.from(JSON.parse(data), { source: "API response" })
|
|
79
|
+
*/
|
|
80
|
+
static from(value: unknown, context?: {
|
|
81
|
+
source?: string;
|
|
82
|
+
}, client?: LLMClient): SemanticUnknown;
|
|
83
|
+
/**
|
|
84
|
+
* Infer the most likely type of this unknown value.
|
|
85
|
+
*
|
|
86
|
+
* @returns Type inference with confidence
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* SemanticUnknown.from({ id: 1, name: "test" }).inferType()
|
|
90
|
+
* // {
|
|
91
|
+
* // type: "object",
|
|
92
|
+
* // shape: "{ id: number; name: string }",
|
|
93
|
+
* // confidence: 0.95
|
|
94
|
+
* // }
|
|
95
|
+
*/
|
|
96
|
+
inferType(): Promise<UnknownInferTypeResult>;
|
|
97
|
+
/**
|
|
98
|
+
* Suggest possible TypeScript types this value could be.
|
|
99
|
+
*
|
|
100
|
+
* @param limit - Maximum number of suggestions (default: 3)
|
|
101
|
+
* @returns Type suggestions ranked by likelihood
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* unknownValue.suggestTypes(3)
|
|
105
|
+
* // [
|
|
106
|
+
* // { type: "User", confidence: 0.9, reason: "Has typical user fields" },
|
|
107
|
+
* // { type: "{ name: string; email: string }", confidence: 0.85 }
|
|
108
|
+
* // ]
|
|
109
|
+
*/
|
|
110
|
+
suggestTypes(limit?: number): Promise<TypeSuggestion[]>;
|
|
111
|
+
/**
|
|
112
|
+
* Validate the value has a specific shape.
|
|
113
|
+
*
|
|
114
|
+
* @param description - Natural language description of expected shape
|
|
115
|
+
* @returns Validation result
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* unknownValue.validateShape("user object with name and email")
|
|
119
|
+
* // { matches: true, missingFields: [], extraFields: ["age"] }
|
|
120
|
+
*/
|
|
121
|
+
validateShape(description: string): Promise<ValidateShapeResult>;
|
|
122
|
+
/**
|
|
123
|
+
* Generate a type guard function for this value's inferred type.
|
|
124
|
+
*
|
|
125
|
+
* @returns Generated type guard code
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* unknownValue.generateTypeGuard()
|
|
129
|
+
* // {
|
|
130
|
+
* // code: "function isUser(x: unknown): x is User { ... }",
|
|
131
|
+
* // typeName: "User"
|
|
132
|
+
* // }
|
|
133
|
+
*/
|
|
134
|
+
generateTypeGuard(): Promise<GenerateTypeGuardResult>;
|
|
135
|
+
/**
|
|
136
|
+
* Safely access a property with semantic understanding.
|
|
137
|
+
*
|
|
138
|
+
* @param path - Property path or semantic description
|
|
139
|
+
* @returns Wrapped property value or undefined
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* unknownValue.safeAccess("user's email address")
|
|
143
|
+
* // SemanticUnknown containing the email, or undefined
|
|
144
|
+
*/
|
|
145
|
+
safeAccess(path: string): Promise<SemanticUnknown | undefined>;
|
|
146
|
+
/**
|
|
147
|
+
* Check if the value matches a semantic description.
|
|
148
|
+
*
|
|
149
|
+
* @param description - Description of what the value should be
|
|
150
|
+
* @returns Match result
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* unknownValue.matches("array of user objects")
|
|
154
|
+
* // { matches: true, confidence: 0.92 }
|
|
155
|
+
*/
|
|
156
|
+
matches(description: string): Promise<MatchesResult>;
|
|
157
|
+
/**
|
|
158
|
+
* Narrow the unknown to a specific type with validation.
|
|
159
|
+
*
|
|
160
|
+
* @param typeName - Name of the expected type
|
|
161
|
+
* @param validator - Optional custom validation rules
|
|
162
|
+
* @returns Narrowed value or error
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* unknownValue.narrowTo("User", ["must have email", "id must be positive"])
|
|
166
|
+
*/
|
|
167
|
+
narrowTo<T>(typeName: string, validator?: string[]): Promise<NarrowToResult<T>>;
|
|
168
|
+
/**
|
|
169
|
+
* Explain what this unknown value appears to be.
|
|
170
|
+
*
|
|
171
|
+
* @returns Human-readable explanation
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* unknownValue.explain()
|
|
175
|
+
* // "This appears to be a user profile object with personal information..."
|
|
176
|
+
*/
|
|
177
|
+
explain(): Promise<string>;
|
|
178
|
+
/**
|
|
179
|
+
* Get the underlying unknown value.
|
|
180
|
+
*
|
|
181
|
+
* @returns The wrapped value
|
|
182
|
+
*/
|
|
183
|
+
valueOf(): unknown;
|
|
184
|
+
/**
|
|
185
|
+
* Check if the value is "empty" (null, undefined, empty string/array/object).
|
|
186
|
+
*
|
|
187
|
+
* @returns Whether the value is semantically empty
|
|
188
|
+
*/
|
|
189
|
+
isEmpty(): boolean;
|
|
190
|
+
/**
|
|
191
|
+
* Get the context/source for this unknown value.
|
|
192
|
+
*
|
|
193
|
+
* @returns The context object or undefined
|
|
194
|
+
*/
|
|
195
|
+
getContext(): {
|
|
196
|
+
source?: string;
|
|
197
|
+
} | undefined;
|
|
198
|
+
/**
|
|
199
|
+
* Convert to string representation
|
|
200
|
+
*/
|
|
201
|
+
toString(): string;
|
|
202
|
+
/**
|
|
203
|
+
* Convert to JSON representation
|
|
204
|
+
*/
|
|
205
|
+
toJSON(): {
|
|
206
|
+
value: unknown;
|
|
207
|
+
context?: {
|
|
208
|
+
source?: string;
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* Try direct property access for simple dot-notation paths
|
|
213
|
+
*/
|
|
214
|
+
private tryDirectAccess;
|
|
215
|
+
/**
|
|
216
|
+
* Get simple type without LLM for primitive values
|
|
217
|
+
*/
|
|
218
|
+
private getSimpleType;
|
|
219
|
+
}
|
|
220
|
+
//# sourceMappingURL=unknown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unknown.d.ts","sourceRoot":"","sources":["../../../src/types/unknown/unknown.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,KAAK,EACV,QAAQ,EACR,WAAW,EACX,aAAa,EACd,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAa/E,kDAAkD;AAClD,MAAM,MAAM,SAAS,GACjB,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,QAAQ,GACR,OAAO,GACP,MAAM,GACN,WAAW,GACX,UAAU,CAAC;AAEf,+BAA+B;AAC/B,MAAM,WAAW,sBAAuB,SAAQ,eAAe;IAC7D,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,iDAAiD;AACjD,MAAM,WAAW,cAAe,SAAQ,gBAAgB;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,iCAAiC;AACjC,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,WA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M,GAAG,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC;IA6BpE;;;;;;;;;OASG;IACG,OAAO,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAY1D;;;;;;;;;OASG;IACG,QAAQ,CAAC,CAAC,EACd,QAAQ,EAAE,MAAM,EAChB,SAAS,CAAC,EAAE,MAAM,EAAE,GACnB,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;IAqB7B;;;;;;;;OAQG;IACG,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IAqBhC;;;;OAIG;IACH,OAAO,IAAI,OAAO;IAIlB;;;;OAIG;IACH,OAAO,IAAI,OAAO;IAmBlB;;;;OAIG;IACH,UAAU,IAAI;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS;IAI7C;;OAEG;IACH,QAAQ,IAAI,MAAM;IAclB;;OAEG;IACH,MAAM,IAAI;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE;YAAE,MAAM,CAAC,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE;IAO3D;;OAEG;IACH,OAAO,CAAC,eAAe;IAkBvB;;OAEG;IACH,OAAO,CAAC,aAAa;CA0BtB"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SemanticURL Module
|
|
3
|
+
* LLM-enhanced URL type with semantic understanding
|
|
4
|
+
*/
|
|
5
|
+
export { SemanticURL, type URLSemanticEqualsResult, type URLClassifyResult, type URLValidateForResult, type ParsedQueryParam, type URLLLMClientInterface, } from './url.ts';
|
|
6
|
+
export type { SemanticEqualsResult, ClassifyResult, SafetyResult, RelatedSuggestion, } from '../../shared/types.ts';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/url/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACL,WAAW,EACX,KAAK,uBAAuB,EAC5B,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,GAC3B,MAAM,UAAU,CAAC;AAGlB,YAAY,EACV,oBAAoB,EACpB,cAAc,EACd,YAAY,EACZ,iBAAiB,GAClB,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompts for SemanticURL LLM operations
|
|
3
|
+
* These prompts are used for various semantic URL operations that require LLM understanding
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* System prompt for semantic URL equality comparison
|
|
7
|
+
*/
|
|
8
|
+
export declare const SEMANTIC_EQUALS_SYSTEM = "You are a URL comparison assistant. Your task is to determine if two URLs are semantically equivalent.\n\nConsider these factors when comparing:\n- www prefix differences (www.example.com vs example.com)\n- Trailing slash differences (/path vs /path/)\n- Default port omission (http://example.com:80 vs http://example.com)\n- Protocol differences when appropriate (http vs https)\n- Case sensitivity in paths vs hostnames\n- Query parameter ordering\n- Fragment identifiers\n\nAlways respond with valid JSON only.";
|
|
9
|
+
/**
|
|
10
|
+
* User prompt template for semantic URL equality
|
|
11
|
+
*/
|
|
12
|
+
export declare function semanticEqualsPrompt(url1: string, url2: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* System prompt for URL classification
|
|
15
|
+
*/
|
|
16
|
+
export declare const CLASSIFY_URL_SYSTEM = "You are a URL classification assistant. Your task is to classify URLs by their type and purpose.\n\nConsider these URL types:\n- api-endpoint: REST APIs, GraphQL endpoints, webhooks\n- website: Landing pages, blogs, documentation\n- cdn: Content delivery networks, static assets\n- media: Images, videos, audio files\n- download: File downloads, artifacts\n- authentication: OAuth, SSO, login endpoints\n- social: Social media profiles, posts\n- repository: Git repositories, package registries\n- search: Search engines, query endpoints\n\nAlways respond with valid JSON only.";
|
|
17
|
+
/**
|
|
18
|
+
* User prompt template for URL classification
|
|
19
|
+
*/
|
|
20
|
+
export declare function classifyUrlPrompt(url: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* System prompt for URL validation for purpose
|
|
23
|
+
*/
|
|
24
|
+
export declare const VALIDATE_FOR_SYSTEM = "You are a URL validation assistant. Your task is to validate URLs for specific purposes.\n\nConsider:\n- Security requirements (HTTPS for sensitive operations)\n- API conventions for API endpoints\n- Domain trust for different purposes\n- Path structure expectations\n- Query parameter requirements\n\nAlways respond with valid JSON only.";
|
|
25
|
+
/**
|
|
26
|
+
* User prompt template for purpose validation
|
|
27
|
+
*/
|
|
28
|
+
export declare function validateForPrompt(url: string, purpose: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* System prompt for URL explanation
|
|
31
|
+
*/
|
|
32
|
+
export declare const EXPLAIN_URL_SYSTEM = "You are a URL explanation assistant. Your task is to explain what a URL points to in human-readable terms.\n\nConsider:\n- The domain and its purpose\n- The path structure and what it indicates\n- Query parameters and their meaning\n- Common URL patterns for well-known services\n\nAlways respond with valid JSON only.";
|
|
33
|
+
/**
|
|
34
|
+
* User prompt template for URL explanation
|
|
35
|
+
*/
|
|
36
|
+
export declare function explainUrlPrompt(url: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* System prompt for URL info extraction
|
|
39
|
+
*/
|
|
40
|
+
export declare const EXTRACT_INFO_SYSTEM = "You are a URL information extraction assistant. Your task is to extract semantic information from URL components.\n\nExtract information such as:\n- Service or platform name\n- Resource type being accessed\n- Identifiers (user IDs, post IDs, etc.)\n- Actions or operations\n- Version information\n- Locale or language settings\n\nAlways respond with valid JSON only.";
|
|
41
|
+
/**
|
|
42
|
+
* User prompt template for info extraction
|
|
43
|
+
*/
|
|
44
|
+
export declare function extractInfoPrompt(url: string): string;
|
|
45
|
+
/**
|
|
46
|
+
* System prompt for URL safety assessment
|
|
47
|
+
*/
|
|
48
|
+
export declare const IS_SAFE_SYSTEM = "You are a URL safety assessment assistant. Your task is to assess whether a URL is safe to visit or request.\n\nConsider these safety factors:\n- Known phishing patterns\n- Suspicious domain patterns (typosquatting, lookalike domains)\n- Dangerous file extensions\n- Data exfiltration patterns\n- Suspicious query parameters\n- IP addresses instead of domains\n- Unusual ports\n- Encoded or obfuscated content\n\nSeverity levels:\n- low: Minor concerns, probably safe\n- medium: Caution advised, potential risks\n- high: Significant risk, avoid\n\nAlways respond with valid JSON only.";
|
|
49
|
+
/**
|
|
50
|
+
* User prompt template for safety assessment
|
|
51
|
+
*/
|
|
52
|
+
export declare function isSafePrompt(url: string): string;
|
|
53
|
+
/**
|
|
54
|
+
* System prompt for URL canonicalization
|
|
55
|
+
*/
|
|
56
|
+
export declare const CANONICAL_URL_SYSTEM = "You are a URL canonicalization assistant. Your task is to suggest the canonical (standardized) form of a URL.\n\nCanonicalization rules:\n- Lowercase the hostname\n- Remove default ports (80 for HTTP, 443 for HTTPS)\n- Remove unnecessary trailing slashes (except for root path)\n- Sort query parameters alphabetically\n- Remove empty query parameters\n- Normalize percent encoding\n- Prefer HTTPS over HTTP when appropriate\n- Remove www prefix when not needed\n\nAlways respond with valid JSON only.";
|
|
57
|
+
/**
|
|
58
|
+
* User prompt template for canonicalization
|
|
59
|
+
*/
|
|
60
|
+
export declare function canonicalUrlPrompt(url: string): string;
|
|
61
|
+
/**
|
|
62
|
+
* System prompt for URL variations
|
|
63
|
+
*/
|
|
64
|
+
export declare const VARIATIONS_SYSTEM = "You are a URL variation assistant. Your task is to generate common variations of a URL.\n\nConsider these variations:\n- With and without www prefix\n- HTTP and HTTPS versions\n- With and without trailing slash\n- With and without default port\n- Common path variations\n\nAlways respond with valid JSON only.";
|
|
65
|
+
/**
|
|
66
|
+
* User prompt template for URL variations
|
|
67
|
+
*/
|
|
68
|
+
export declare function variationsPrompt(url: string): string;
|
|
69
|
+
/**
|
|
70
|
+
* System prompt for query parameter parsing
|
|
71
|
+
*/
|
|
72
|
+
export declare const PARSE_QUERY_SYSTEM = "You are a query parameter analysis assistant. Your task is to parse URL query parameters and explain their semantic meaning.\n\nConsider common parameter patterns:\n- Pagination: page, limit, offset, per_page\n- Filtering: filter, q, query, search\n- Sorting: sort, order, orderBy\n- API: api_key, token, version\n- Tracking: utm_*, ref, source\n- Locale: lang, locale, hl\n\nAlways respond with valid JSON only.";
|
|
73
|
+
/**
|
|
74
|
+
* User prompt template for query parsing
|
|
75
|
+
*/
|
|
76
|
+
export declare function parseQueryPrompt(url: string): string;
|
|
77
|
+
/**
|
|
78
|
+
* System prompt for suggesting related URLs
|
|
79
|
+
*/
|
|
80
|
+
export declare const SUGGEST_RELATED_SYSTEM = "You are a URL suggestion assistant. Your task is to suggest related URLs based on the current URL's pattern and purpose.\n\nConsider:\n- Common API endpoint patterns (list, detail, create, update, delete)\n- Related resources in the same domain\n- Parent/child resource relationships\n- Common navigation patterns\n- Alternative actions on the same resource\n\nAlways respond with valid JSON only.";
|
|
81
|
+
/**
|
|
82
|
+
* User prompt template for related URL suggestions
|
|
83
|
+
*/
|
|
84
|
+
export declare function suggestRelatedPrompt(url: string): string;
|
|
85
|
+
/**
|
|
86
|
+
* System prompt for URL pattern matching
|
|
87
|
+
*/
|
|
88
|
+
export declare const MATCHES_PATTERN_SYSTEM = "You are a URL pattern matching assistant. Your task is to determine if a URL matches a semantic pattern description.\n\nPattern types to recognize:\n- API endpoint\n- Image URL\n- Video URL\n- Document URL\n- Download link\n- Authentication endpoint\n- Search URL\n- Social media post\n- Repository URL\n- CDN URL\n\nAlways respond with valid JSON only.";
|
|
89
|
+
/**
|
|
90
|
+
* User prompt template for pattern matching
|
|
91
|
+
*/
|
|
92
|
+
export declare function matchesPatternPrompt(url: string, pattern: string): string;
|
|
93
|
+
//# sourceMappingURL=prompts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../../src/types/url/prompts.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,eAAO,MAAM,sBAAsB,sgBAWE,CAAC;AAEtC;;GAEG;AACH,w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