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,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SemanticSet
|
|
3
|
+
* A set type with LLM-powered semantic understanding
|
|
4
|
+
*
|
|
5
|
+
* Implements shared interfaces:
|
|
6
|
+
* - Semantic<Set<T>> - Base semantic wrapper
|
|
7
|
+
* - Comparable<SemanticSet<T>> - Semantic equality comparison
|
|
8
|
+
* - Validatable - Validation against semantic rules
|
|
9
|
+
* - Summarizable - Content summarization
|
|
10
|
+
* - SemanticFilterable - Natural language filtering
|
|
11
|
+
* - SemanticGroupable - Semantic grouping
|
|
12
|
+
* - SemanticSetOperations - Intersection, union, difference
|
|
13
|
+
* - Suggestible - Related value suggestions
|
|
14
|
+
*/
|
|
15
|
+
import type { LLMClient } from '../../llm/client.ts';
|
|
16
|
+
import type { SemanticEqualsResult, RelatedSuggestion, ConfidenceResult } from '../../shared/types.ts';
|
|
17
|
+
import type { Semantic, Comparable } from '../../shared/interfaces.ts';
|
|
18
|
+
/** Result of semantic has operation */
|
|
19
|
+
export interface SemanticHasResult extends ConfidenceResult {
|
|
20
|
+
exists: boolean;
|
|
21
|
+
matchedValue: unknown;
|
|
22
|
+
}
|
|
23
|
+
/** Result of semantic add operation */
|
|
24
|
+
export interface SemanticAddResult extends ConfidenceResult {
|
|
25
|
+
added: boolean;
|
|
26
|
+
existingEquivalent: unknown;
|
|
27
|
+
}
|
|
28
|
+
/** Result of semantic equality with mappings */
|
|
29
|
+
export interface SetSemanticEqualsResult extends SemanticEqualsResult {
|
|
30
|
+
mappings?: [unknown, unknown][];
|
|
31
|
+
}
|
|
32
|
+
/** Options for summarization */
|
|
33
|
+
export interface SetSummarizeOptions {
|
|
34
|
+
maxLength?: number;
|
|
35
|
+
focus?: string;
|
|
36
|
+
}
|
|
37
|
+
/** Validation result with per-value issues */
|
|
38
|
+
export interface SetValidateResult {
|
|
39
|
+
valid: boolean;
|
|
40
|
+
issues: {
|
|
41
|
+
value: unknown;
|
|
42
|
+
problems: string[];
|
|
43
|
+
}[];
|
|
44
|
+
}
|
|
45
|
+
/** Result of theme inference */
|
|
46
|
+
export interface InferThemeResult extends ConfidenceResult {
|
|
47
|
+
theme: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* SemanticSet - Set with LLM-powered semantic understanding
|
|
51
|
+
*
|
|
52
|
+
* Unlike traditional sets that only support exact value matching,
|
|
53
|
+
* semantic sets understand meaning-based membership, equivalence,
|
|
54
|
+
* and operations.
|
|
55
|
+
*
|
|
56
|
+
* @template T - The type of elements in the set
|
|
57
|
+
*/
|
|
58
|
+
export declare class SemanticSet<T> implements Semantic<Set<T>>, Comparable<SemanticSet<T> | Set<T>, SetSemanticEqualsResult> {
|
|
59
|
+
private readonly elements;
|
|
60
|
+
private readonly client;
|
|
61
|
+
private constructor();
|
|
62
|
+
/**
|
|
63
|
+
* Create a SemanticSet from an existing iterable
|
|
64
|
+
*/
|
|
65
|
+
static from<T>(values: Iterable<T>, client?: LLMClient): SemanticSet<T>;
|
|
66
|
+
/**
|
|
67
|
+
* Create an empty SemanticSet
|
|
68
|
+
*/
|
|
69
|
+
static empty<T>(client?: LLMClient): SemanticSet<T>;
|
|
70
|
+
/**
|
|
71
|
+
* Create a SemanticSet from variadic arguments
|
|
72
|
+
*/
|
|
73
|
+
static of<T>(...items: T[]): SemanticSet<T>;
|
|
74
|
+
/**
|
|
75
|
+
* Get the underlying Set value
|
|
76
|
+
*/
|
|
77
|
+
valueOf(): Set<T>;
|
|
78
|
+
/**
|
|
79
|
+
* Get the values as an array (for convenience)
|
|
80
|
+
*/
|
|
81
|
+
toArray(): T[];
|
|
82
|
+
/**
|
|
83
|
+
* Get the size of the set
|
|
84
|
+
*/
|
|
85
|
+
get size(): number;
|
|
86
|
+
/**
|
|
87
|
+
* Check if set has an exact value (standard Set behavior)
|
|
88
|
+
*/
|
|
89
|
+
has(value: T): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Check if the set contains a semantically equivalent value.
|
|
92
|
+
*
|
|
93
|
+
* @param query - Value or semantic query
|
|
94
|
+
* @returns Whether a matching value exists with details
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* colors.semanticHas("crimson") // { exists: true, matchedValue: "red", confidence: 0.92 }
|
|
98
|
+
*/
|
|
99
|
+
semanticHas(query: T | string): Promise<SemanticHasResult>;
|
|
100
|
+
/**
|
|
101
|
+
* Add a value only if no semantic equivalent exists.
|
|
102
|
+
*
|
|
103
|
+
* @param value - Value to add
|
|
104
|
+
* @returns Result indicating if value was added
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* tags.semanticAdd("ML") // { added: false, existingEquivalent: "machine learning", confidence: 0.9 }
|
|
108
|
+
*/
|
|
109
|
+
semanticAdd(value: T): Promise<{
|
|
110
|
+
result: SemanticAddResult;
|
|
111
|
+
set: SemanticSet<T>;
|
|
112
|
+
}>;
|
|
113
|
+
/**
|
|
114
|
+
* Check if two sets are semantically equivalent.
|
|
115
|
+
*
|
|
116
|
+
* @param other - Set to compare with
|
|
117
|
+
* @returns Equivalence result with mappings
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* set1.semanticallyEquals(set2)
|
|
121
|
+
* // { equivalent: true, mappings: [["red", "crimson"]], confidence: 0.9 }
|
|
122
|
+
*/
|
|
123
|
+
semanticallyEquals(other: SemanticSet<T> | Set<T>): Promise<SetSemanticEqualsResult>;
|
|
124
|
+
/**
|
|
125
|
+
* Get semantic intersection with another set.
|
|
126
|
+
*
|
|
127
|
+
* @param other - Set to intersect with
|
|
128
|
+
* @returns Intersection with semantic matching
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* skills1.semanticIntersection(skills2)
|
|
132
|
+
* // Matches "JavaScript" with "JS", "Node.js" with "NodeJS"
|
|
133
|
+
*/
|
|
134
|
+
semanticIntersection(other: SemanticSet<T> | Set<T>): Promise<SemanticSet<T>>;
|
|
135
|
+
/**
|
|
136
|
+
* Get semantic union, merging equivalent values.
|
|
137
|
+
*
|
|
138
|
+
* @param other - Set to union with
|
|
139
|
+
* @returns Union with semantic deduplication
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* tags1.semanticUnion(tags2)
|
|
143
|
+
* // Combines without duplicating "ML" and "machine learning"
|
|
144
|
+
*/
|
|
145
|
+
semanticUnion(other: SemanticSet<T> | Set<T>): Promise<SemanticSet<T>>;
|
|
146
|
+
/**
|
|
147
|
+
* Get semantic difference (values not in other set).
|
|
148
|
+
*
|
|
149
|
+
* @param other - Set to diff against
|
|
150
|
+
* @returns Difference with semantic matching
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* allSkills.semanticDifference(requiredSkills)
|
|
154
|
+
* // Excludes "Python" if required has "Python programming"
|
|
155
|
+
*/
|
|
156
|
+
semanticDifference(other: SemanticSet<T> | Set<T>): Promise<SemanticSet<T>>;
|
|
157
|
+
/**
|
|
158
|
+
* Find values matching semantic criteria.
|
|
159
|
+
*
|
|
160
|
+
* @param criteria - Natural language criteria
|
|
161
|
+
* @returns Matching values as a SemanticSet
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* skills.semanticFilter("backend technologies")
|
|
165
|
+
* // SemanticSet containing ["Node.js", "PostgreSQL", "Redis"]
|
|
166
|
+
*/
|
|
167
|
+
semanticFilter(criteria: string): Promise<SemanticSet<T>>;
|
|
168
|
+
/**
|
|
169
|
+
* Group set values by semantic category.
|
|
170
|
+
*
|
|
171
|
+
* @param criteria - Grouping criteria
|
|
172
|
+
* @returns Grouped values
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* skills.groupBy("technology area")
|
|
176
|
+
* // Map { "frontend": SemanticSet(["React", "CSS"]), "backend": SemanticSet(["Node", "Python"]) }
|
|
177
|
+
*/
|
|
178
|
+
groupBy(criteria: string): Promise<Map<string, SemanticSet<T>>>;
|
|
179
|
+
/**
|
|
180
|
+
* Summarize the set contents.
|
|
181
|
+
*
|
|
182
|
+
* @param options - Summary options
|
|
183
|
+
* @returns Human-readable summary
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* permissions.summarize()
|
|
187
|
+
* // "15 permissions: 8 read, 5 write, 2 admin. Covers user and content management."
|
|
188
|
+
*/
|
|
189
|
+
summarize(options?: SetSummarizeOptions): Promise<string>;
|
|
190
|
+
/**
|
|
191
|
+
* Suggest related values that might belong in this set.
|
|
192
|
+
*
|
|
193
|
+
* @returns Suggested additions
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* skills.suggestRelated()
|
|
197
|
+
* // [{ value: "TypeScript", reason: "Commonly paired with JavaScript" }]
|
|
198
|
+
*/
|
|
199
|
+
suggestRelated(): Promise<RelatedSuggestion[]>;
|
|
200
|
+
/**
|
|
201
|
+
* Validate all values against semantic rules.
|
|
202
|
+
*
|
|
203
|
+
* @param rules - Validation rules
|
|
204
|
+
* @returns Validation result
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* tags.validate(["must be lowercase", "no special characters"])
|
|
208
|
+
*/
|
|
209
|
+
validate(rules: string[]): Promise<SetValidateResult>;
|
|
210
|
+
/**
|
|
211
|
+
* Detect the semantic theme/category of this set.
|
|
212
|
+
*
|
|
213
|
+
* @returns Inferred theme
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* values.inferTheme()
|
|
217
|
+
* // { theme: "programming languages", confidence: 0.92 }
|
|
218
|
+
*/
|
|
219
|
+
inferTheme(): Promise<InferThemeResult>;
|
|
220
|
+
/**
|
|
221
|
+
* Add a value (standard Set behavior)
|
|
222
|
+
*/
|
|
223
|
+
add(value: T): SemanticSet<T>;
|
|
224
|
+
/**
|
|
225
|
+
* Delete a value
|
|
226
|
+
*/
|
|
227
|
+
delete(value: T): SemanticSet<T>;
|
|
228
|
+
/**
|
|
229
|
+
* Clear all values
|
|
230
|
+
*/
|
|
231
|
+
clear(): SemanticSet<T>;
|
|
232
|
+
/**
|
|
233
|
+
* Execute a function for each value
|
|
234
|
+
*/
|
|
235
|
+
forEach(fn: (value: T, value2: T, set: Set<T>) => void): void;
|
|
236
|
+
/**
|
|
237
|
+
* Get an iterator over values
|
|
238
|
+
*/
|
|
239
|
+
values(): IterableIterator<T>;
|
|
240
|
+
/**
|
|
241
|
+
* Get an iterator over keys (same as values for Set)
|
|
242
|
+
*/
|
|
243
|
+
keys(): IterableIterator<T>;
|
|
244
|
+
/**
|
|
245
|
+
* Get an iterator over entries
|
|
246
|
+
*/
|
|
247
|
+
entries(): IterableIterator<[T, T]>;
|
|
248
|
+
/**
|
|
249
|
+
* Iterator support
|
|
250
|
+
*/
|
|
251
|
+
[Symbol.iterator](): Iterator<T>;
|
|
252
|
+
/**
|
|
253
|
+
* Convert to string
|
|
254
|
+
*/
|
|
255
|
+
toString(): string;
|
|
256
|
+
/**
|
|
257
|
+
* Convert to JSON (array representation)
|
|
258
|
+
*/
|
|
259
|
+
toJSON(): T[];
|
|
260
|
+
}
|
|
261
|
+
//# sourceMappingURL=set.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set.d.ts","sourceRoot":"","sources":["../../../src/types/set/set.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,KAAK,EACV,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAiBvE,uCAAuC;AACvC,MAAM,WAAW,iBAAkB,SAAQ,gBAAgB;IACzD,MAAM,EAAE,OAAO,CAAC;IAChB,YAAY,EAAE,OAAO,CAAC;CACvB;AAED,uCAAuC;AACvC,MAAM,WAAW,iBAAkB,SAAQ,gBAAgB;IACzD,KAAK,EAAE,OAAO,CAAC;IACf,kBAAkB,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M-enhanced stream types with semantic understanding
|
|
4
|
+
*/
|
|
5
|
+
export { SemanticReadableStream, type DetectContentTypeResult, type StreamSemanticEqualsResult, type DetectPatternsResult, type InferSchemaResult, type StreamValidationItem, } from './readable-stream.ts';
|
|
6
|
+
export { SemanticWritableStream, type WriteStats, } from './writable-stream.ts';
|
|
7
|
+
export { SemanticTransformStream } from './transform-stream.ts';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/streams/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACL,sBAAsB,EACtB,KAAK,uBAAuB,EAC5B,KAAK,0BAA0B,EAC/B,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,GAC1B,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EACL,sBAAsB,EACtB,KAAK,UAAU,GAChB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompts for Semantic Stream LLM operations
|
|
3
|
+
* These prompts enable intelligent content analysis, pattern detection, and stream processing
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* System prompt for stream analysis tasks
|
|
7
|
+
*/
|
|
8
|
+
export declare const STREAM_SYSTEM_PROMPT = "You are an expert at analyzing streaming data, understanding content types, detecting patterns, and providing semantic insights about data flows.\n\nYou must respond with valid JSON only, no additional text or explanation.\n\nGuidelines:\n- Analyze stream content to understand its structure and meaning\n- Detect patterns, anomalies, and data quality issues\n- Consider common data formats: JSON, NDJSON, CSV, XML, binary, text\n- Provide meaningful, contextual responses about stream content\n- Be precise with confidence scores (0.0 to 1.0)";
|
|
9
|
+
/**
|
|
10
|
+
* Prompt for detecting content type of stream data
|
|
11
|
+
*/
|
|
12
|
+
export declare function createDetectContentTypePrompt(sample: string, description?: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Prompt for summarizing stream contents
|
|
15
|
+
*/
|
|
16
|
+
export declare function createSummarizePrompt(content: string, description?: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Prompt for checking semantic equivalence between two streams
|
|
19
|
+
*/
|
|
20
|
+
export declare function createSemanticEqualsPrompt(content1: string, content2: string, description?: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Prompt for filtering stream data based on criteria
|
|
23
|
+
*/
|
|
24
|
+
export declare function createSemanticFilterPrompt(item: string, criteria: string, description?: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Prompt for transforming stream data
|
|
27
|
+
*/
|
|
28
|
+
export declare function createSemanticTransformPrompt(item: string, instruction: string, description?: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* Prompt for validating stream data against rules
|
|
31
|
+
*/
|
|
32
|
+
export declare function createValidatePrompt(item: string, rules: string[], description?: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Prompt for explaining stream contents
|
|
35
|
+
*/
|
|
36
|
+
export declare function createExplainPrompt(sample: string, description?: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* Prompt for detecting patterns in stream data
|
|
39
|
+
*/
|
|
40
|
+
export declare function createDetectPatternsPrompt(content: string, description?: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* Prompt for inferring schema from stream data
|
|
43
|
+
*/
|
|
44
|
+
export declare function createInferSchemaPrompt(sample: string, description?: string): string;
|
|
45
|
+
/**
|
|
46
|
+
* Prompt for explaining a transform operation
|
|
47
|
+
*/
|
|
48
|
+
export declare function createExplainTransformPrompt(instruction: string): string;
|
|
49
|
+
/**
|
|
50
|
+
* Prompt for validating data before writing to a stream
|
|
51
|
+
*/
|
|
52
|
+
export declare function createWriteValidationPrompt(data: string, rules: string[]): string;
|
|
53
|
+
//# sourceMappingURL=prompts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promp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WAAW,EAAE,MAAM,GAAG,MAAM,CAgBxE;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EAAE,GACd,MAAM,CAkBR"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SemanticReadableStream
|
|
3
|
+
* A ReadableStream wrapper with LLM-powered semantic understanding
|
|
4
|
+
*
|
|
5
|
+
* Enables content analysis, intelligent transformations, and pattern detection on streaming data.
|
|
6
|
+
*/
|
|
7
|
+
import type { LLMClient } from '../../llm/client.ts';
|
|
8
|
+
/** Result of content type detection */
|
|
9
|
+
export interface DetectContentTypeResult {
|
|
10
|
+
type: string;
|
|
11
|
+
format?: string;
|
|
12
|
+
confidence: number;
|
|
13
|
+
}
|
|
14
|
+
/** Result of semantic equality comparison */
|
|
15
|
+
export interface StreamSemanticEqualsResult {
|
|
16
|
+
equivalent: boolean;
|
|
17
|
+
confidence: number;
|
|
18
|
+
reason?: string;
|
|
19
|
+
}
|
|
20
|
+
/** Result of pattern detection */
|
|
21
|
+
export interface DetectPatternsResult {
|
|
22
|
+
patterns: string[];
|
|
23
|
+
anomalies: {
|
|
24
|
+
index: number;
|
|
25
|
+
reason: string;
|
|
26
|
+
}[];
|
|
27
|
+
}
|
|
28
|
+
/** Result of schema inference */
|
|
29
|
+
export interface InferSchemaResult {
|
|
30
|
+
type: string;
|
|
31
|
+
properties?: Record<string, string>;
|
|
32
|
+
confidence: number;
|
|
33
|
+
}
|
|
34
|
+
/** Validation result for stream items */
|
|
35
|
+
export interface StreamValidationItem<T> {
|
|
36
|
+
data: T;
|
|
37
|
+
valid: boolean;
|
|
38
|
+
issues: string[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* SemanticReadableStream - ReadableStream with LLM-powered semantic understanding
|
|
42
|
+
*
|
|
43
|
+
* Wraps a native ReadableStream and adds intelligent content analysis,
|
|
44
|
+
* pattern detection, and transformation capabilities.
|
|
45
|
+
*/
|
|
46
|
+
export declare class SemanticReadableStream<T> {
|
|
47
|
+
readonly [Symbol.toStringTag] = "SemanticReadableStream";
|
|
48
|
+
private _stream;
|
|
49
|
+
private readonly _description?;
|
|
50
|
+
private readonly _client;
|
|
51
|
+
private constructor();
|
|
52
|
+
/**
|
|
53
|
+
* Wrap a ReadableStream with semantic capabilities.
|
|
54
|
+
*
|
|
55
|
+
* @param stream - ReadableStream to wrap
|
|
56
|
+
* @param description - Optional description of stream contents
|
|
57
|
+
* @param client - Optional LLM client
|
|
58
|
+
* @returns SemanticReadableStream instance
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* SemanticReadableStream.from(fetch(url).then(r => r.body), "API response")
|
|
62
|
+
*/
|
|
63
|
+
static from<T>(stream: ReadableStream<T>, description?: string, client?: LLMClient): SemanticReadableStream<T>;
|
|
64
|
+
/**
|
|
65
|
+
* Get the underlying ReadableStream.
|
|
66
|
+
*/
|
|
67
|
+
get stream(): ReadableStream<T>;
|
|
68
|
+
/**
|
|
69
|
+
* Get the description.
|
|
70
|
+
*/
|
|
71
|
+
get description(): string | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Get a reader for the underlying stream.
|
|
74
|
+
*/
|
|
75
|
+
getReader(): ReadableStreamDefaultReader<T>;
|
|
76
|
+
/**
|
|
77
|
+
* Tee the stream into two branches.
|
|
78
|
+
*/
|
|
79
|
+
tee(): [SemanticReadableStream<T>, SemanticReadableStream<T>];
|
|
80
|
+
/**
|
|
81
|
+
* Check if two streams are semantically equivalent.
|
|
82
|
+
* Note: This consumes both streams.
|
|
83
|
+
*
|
|
84
|
+
* @param other - Stream to compare
|
|
85
|
+
* @returns Equivalence result
|
|
86
|
+
*/
|
|
87
|
+
semanticallyEquals(other: ReadableStream<T>): Promise<StreamSemanticEqualsResult>;
|
|
88
|
+
/**
|
|
89
|
+
* Detect the content type of the stream data.
|
|
90
|
+
*
|
|
91
|
+
* @param sampleSize - Bytes to sample for detection
|
|
92
|
+
* @returns Content type detection result
|
|
93
|
+
*/
|
|
94
|
+
detectContentType(sampleSize?: number): Promise<DetectContentTypeResult>;
|
|
95
|
+
/**
|
|
96
|
+
* Summarize the stream contents.
|
|
97
|
+
* Note: This consumes the stream.
|
|
98
|
+
*
|
|
99
|
+
* @returns Content summary
|
|
100
|
+
*/
|
|
101
|
+
summarize(): Promise<string>;
|
|
102
|
+
/**
|
|
103
|
+
* Filter stream data using semantic criteria.
|
|
104
|
+
*
|
|
105
|
+
* @param criteria - Natural language filter
|
|
106
|
+
* @returns Filtered stream
|
|
107
|
+
*/
|
|
108
|
+
semanticFilter(criteria: string): SemanticReadableStream<T>;
|
|
109
|
+
/**
|
|
110
|
+
* Transform stream using natural language instructions.
|
|
111
|
+
*
|
|
112
|
+
* @param instruction - Transformation instruction
|
|
113
|
+
* @returns Transformed stream
|
|
114
|
+
*/
|
|
115
|
+
semanticTransform<U>(instruction: string): SemanticReadableStream<U>;
|
|
116
|
+
/**
|
|
117
|
+
* Validate stream data against semantic rules.
|
|
118
|
+
*
|
|
119
|
+
* @param rules - Validation rules
|
|
120
|
+
* @returns Validation stream
|
|
121
|
+
*/
|
|
122
|
+
validate(rules: string[]): SemanticReadableStream<StreamValidationItem<T>>;
|
|
123
|
+
/**
|
|
124
|
+
* Explain what this stream contains.
|
|
125
|
+
*
|
|
126
|
+
* @param sampleSize - Data to sample for explanation
|
|
127
|
+
* @returns Human-readable explanation
|
|
128
|
+
*/
|
|
129
|
+
explain(sampleSize?: number): Promise<string>;
|
|
130
|
+
/**
|
|
131
|
+
* Detect patterns in stream data.
|
|
132
|
+
* Note: This consumes the stream.
|
|
133
|
+
*
|
|
134
|
+
* @returns Detected patterns
|
|
135
|
+
*/
|
|
136
|
+
detectPatterns(): Promise<DetectPatternsResult>;
|
|
137
|
+
/**
|
|
138
|
+
* Infer the schema of stream elements.
|
|
139
|
+
*
|
|
140
|
+
* @returns Inferred schema
|
|
141
|
+
*/
|
|
142
|
+
inferSchema(): Promise<InferSchemaResult>;
|
|
143
|
+
/**
|
|
144
|
+
* Consume the entire stream as a string.
|
|
145
|
+
*/
|
|
146
|
+
private consumeAsString;
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=readable-stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readable-stream.d.ts","sourceRoot":"","sources":["../../../src/types/streams/readable-stream.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAerD,uCAAuC;AACvC,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,6CAA6C;AAC7C,MAAM,WAAW,0BAA0B;IACzC,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,kCAAkC;AAClC,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,SAAS,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAChD;AAED,iCAAiC;AACjC,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,yCAAyC;AACzC,MAAM,WAAW,oBAAoB,CAAC,CAAC;IACrC,IAAI,EAAE,CAAC,CAAC;IACR,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAID;;;;;GAKG;AACH,qBAAa,sBAAsB,CAAC,CAAC;IACnC,QAAQ,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,4BAA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A4B,GAAG,OAAO,CAAC,MAAM,CAAC;IA4BxE;;;;;OAKG;IACG,cAAc,IAAI,OAAO,CAAC,oBAAoB,CAAC;IAsBrD;;;;OAIG;IACG,WAAW,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAyB/C;;OAEG;YACW,eAAe;CAG9B"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SemanticTransformStream
|
|
3
|
+
* A TransformStream wrapper with LLM-powered semantic understanding
|
|
4
|
+
*
|
|
5
|
+
* Enables intelligent transformations based on natural language instructions.
|
|
6
|
+
*/
|
|
7
|
+
import type { LLMClient } from '../../llm/client.ts';
|
|
8
|
+
/**
|
|
9
|
+
* SemanticTransformStream - TransformStream with LLM-powered semantic understanding
|
|
10
|
+
*
|
|
11
|
+
* Creates a transform stream from natural language instructions.
|
|
12
|
+
*/
|
|
13
|
+
export declare class SemanticTransformStream<I, O> {
|
|
14
|
+
readonly [Symbol.toStringTag] = "SemanticTransformStream";
|
|
15
|
+
private readonly _transformStream;
|
|
16
|
+
private readonly _instruction;
|
|
17
|
+
private readonly _client;
|
|
18
|
+
private _explanation;
|
|
19
|
+
private constructor();
|
|
20
|
+
/**
|
|
21
|
+
* Create a transform stream from natural language instruction.
|
|
22
|
+
*
|
|
23
|
+
* @param instruction - What transformation to perform
|
|
24
|
+
* @param client - Optional LLM client
|
|
25
|
+
* @returns Transform stream
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* SemanticTransformStream.from("parse JSON and extract names")
|
|
29
|
+
*/
|
|
30
|
+
static from<I, O>(instruction: string, client?: LLMClient): SemanticTransformStream<I, O>;
|
|
31
|
+
/**
|
|
32
|
+
* Get the underlying TransformStream.
|
|
33
|
+
*/
|
|
34
|
+
get transformStream(): TransformStream<I, O>;
|
|
35
|
+
/**
|
|
36
|
+
* Get the instruction.
|
|
37
|
+
*/
|
|
38
|
+
get instruction(): string;
|
|
39
|
+
/**
|
|
40
|
+
* Get the readable side of the transform stream.
|
|
41
|
+
*/
|
|
42
|
+
get readable(): ReadableStream<O>;
|
|
43
|
+
/**
|
|
44
|
+
* Get the writable side of the transform stream.
|
|
45
|
+
*/
|
|
46
|
+
get writable(): WritableStream<I>;
|
|
47
|
+
/**
|
|
48
|
+
* Explain what this transform does.
|
|
49
|
+
*
|
|
50
|
+
* @returns Transformation description
|
|
51
|
+
*/
|
|
52
|
+
explain(): string;
|
|
53
|
+
/**
|
|
54
|
+
* Explain what this transform does using LLM.
|
|
55
|
+
*
|
|
56
|
+
* @returns Transformation description
|
|
57
|
+
*/
|
|
58
|
+
explainAsync(): Promise<string>;
|
|
59
|
+
/**
|
|
60
|
+
* Pipe a readable stream through this transform.
|
|
61
|
+
*
|
|
62
|
+
* @param source - Source readable stream
|
|
63
|
+
* @returns Transformed readable stream
|
|
64
|
+
*/
|
|
65
|
+
pipeFrom(source: ReadableStream<I>): ReadableStream<O>;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=transform-stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform-stream.d.ts","sourceRoot":"","sources":["../../../src/types/streams/transform-stream.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAQrD;;;;GAIG;AACH,qBAAa,uBAAuB,CAAC,CAAC,EAAE,CAAC;IACvC,QAAQ,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,6BAA6B;IAE1D,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAwB;IACzD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAY;IACpC,OAAO,CAAC,YAAY,CAAuB;IAE3C,OAAO;IAyCP;;;;;;;;;OASG;IACH,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EACd,WAAW,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,SAAS,GACjB,uBAAuB,CAAC,CAAC,EAAE,CAAC,CAAC;IAIhC;;OAEG;IACH,IAAI,eAAe,IAAI,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,CAE3C;IAED;;OAEG;IACH,IAAI,WAAW,IAAI,MAAM,CAExB;IAED;;OAEG;IACH,IAAI,QAAQ,IAAI,cAAc,CAAC,CAAC,CAAC,CAEhC;IAED;;OAEG;IACH,IAAI,QAAQ,IAAI,cAAc,CAAC,CAAC,CAAC,CAEhC;IAED;;;;OAIG;IACH,OAAO,IAAI,MAAM;IASjB;;;;OAIG;IACG,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC;IAsBrC;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC;CAGvD"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SemanticWritableStream
|
|
3
|
+
* A WritableStream wrapper with LLM-powered semantic understanding
|
|
4
|
+
*
|
|
5
|
+
* Enables intelligent validation and statistics tracking for written data.
|
|
6
|
+
*/
|
|
7
|
+
import type { LLMClient } from '../../llm/client.ts';
|
|
8
|
+
/** Statistics about written data */
|
|
9
|
+
export interface WriteStats {
|
|
10
|
+
chunksWritten: number;
|
|
11
|
+
bytesWritten: number;
|
|
12
|
+
errorCount: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* SemanticWritableStream - WritableStream with LLM-powered semantic understanding
|
|
16
|
+
*
|
|
17
|
+
* Wraps a native WritableStream and adds intelligent validation
|
|
18
|
+
* and statistics tracking capabilities.
|
|
19
|
+
*
|
|
20
|
+
* Note: When using withValidation(), the original instance becomes unusable.
|
|
21
|
+
* Only the returned wrapper should be used for subsequent operations.
|
|
22
|
+
*/
|
|
23
|
+
export declare class SemanticWritableStream<T> {
|
|
24
|
+
readonly [Symbol.toStringTag] = "SemanticWritableStream";
|
|
25
|
+
private readonly _stream;
|
|
26
|
+
private readonly _client;
|
|
27
|
+
private readonly _validationRules;
|
|
28
|
+
private readonly _sharedState;
|
|
29
|
+
private _transferred;
|
|
30
|
+
private constructor();
|
|
31
|
+
/**
|
|
32
|
+
* Wrap a WritableStream with semantic capabilities.
|
|
33
|
+
*
|
|
34
|
+
* @param stream - WritableStream to wrap
|
|
35
|
+
* @param client - Optional LLM client
|
|
36
|
+
* @returns SemanticWritableStream instance
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* SemanticWritableStream.from(new WritableStream({ write(chunk) { ... } }))
|
|
40
|
+
*/
|
|
41
|
+
static from<T>(stream: WritableStream<T>, client?: LLMClient): SemanticWritableStream<T>;
|
|
42
|
+
/**
|
|
43
|
+
* Get the underlying WritableStream.
|
|
44
|
+
*/
|
|
45
|
+
get stream(): WritableStream<T>;
|
|
46
|
+
/**
|
|
47
|
+
* Check if this instance has been transferred to a validation wrapper.
|
|
48
|
+
*/
|
|
49
|
+
get isTransferred(): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Throws if this instance has been transferred.
|
|
52
|
+
*/
|
|
53
|
+
private assertNotTransferred;
|
|
54
|
+
/**
|
|
55
|
+
* Get a writer for the underlying stream.
|
|
56
|
+
*/
|
|
57
|
+
getWriter(): WritableStreamDefaultWriter<T>;
|
|
58
|
+
/**
|
|
59
|
+
* Write a chunk to the stream.
|
|
60
|
+
*
|
|
61
|
+
* @param chunk - Data to write
|
|
62
|
+
*/
|
|
63
|
+
write(chunk: T): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Close the stream.
|
|
66
|
+
*/
|
|
67
|
+
close(): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Abort the stream.
|
|
70
|
+
*/
|
|
71
|
+
abort(reason?: unknown): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Release the writer lock.
|
|
74
|
+
*/
|
|
75
|
+
releaseLock(): void;
|
|
76
|
+
/**
|
|
77
|
+
* Create a new SemanticWritableStream with validation rules.
|
|
78
|
+
*
|
|
79
|
+
* IMPORTANT: After calling this method, the current instance becomes unusable.
|
|
80
|
+
* Only the returned wrapper should be used for subsequent operations.
|
|
81
|
+
* Statistics are shared between all wrappers.
|
|
82
|
+
*
|
|
83
|
+
* @param rules - Validation rules
|
|
84
|
+
* @returns Validating writable stream
|
|
85
|
+
*/
|
|
86
|
+
withValidation(rules: string[]): SemanticWritableStream<T>;
|
|
87
|
+
/**
|
|
88
|
+
* Get statistics about written data.
|
|
89
|
+
* Statistics are shared across all validation wrappers of the same stream.
|
|
90
|
+
*
|
|
91
|
+
* @returns Write statistics
|
|
92
|
+
*/
|
|
93
|
+
getStats(): Promise<WriteStats>;
|
|
94
|
+
/**
|
|
95
|
+
* Validate a chunk against the validation rules.
|
|
96
|
+
*/
|
|
97
|
+
private validateChunk;
|
|
98
|
+
/**
|
|
99
|
+
* Basic validation without LLM.
|
|
100
|
+
*/
|
|
101
|
+
private basicValidation;
|
|
102
|
+
/**
|
|
103
|
+
* Get the byte size of a chunk.
|
|
104
|
+
*/
|
|
105
|
+
private getChunkSize;
|
|
106
|
+
/**
|
|
107
|
+
* Convert a chunk to string for validation.
|
|
108
|
+
*/
|
|
109
|
+
private stringifyChunk;
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=writable-stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writable-stream.d.ts","sourceRoot":"","sources":["../../../src/types/streams/writable-stream.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAIrD,oCAAoC;AACpC,MAAM,WAAW,UAAU;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;CACpB;AAWD;;;;;;;;GAQG;AACH,qBAAa,sBAAsB,CAAC,CAAC;IACnC,QAAQ,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,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