promptgun 0.0.2-development

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.md ADDED
@@ -0,0 +1,13 @@
1
+ # Proprietary License
2
+
3
+ Copyright © 2025 David Duwaer
4
+
5
+ All rights reserved.
6
+
7
+ This software is licensed, not sold. Unauthorized copying, modification, distribution, or use of this software is strictly prohibited, except as expressly permitted in writing by the copyright holder.
8
+
9
+ The licensee is granted a non-transferable, non-exclusive license to use the software solely for internal purposes.
10
+
11
+ This software may not be reverse engineered, decompiled, or disassembled.
12
+
13
+ For licensing inquiries, contact: @davidduwaer on X
package/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # Promptgun
2
+
3
+ The world's most intuitive library for advanced LLM prompting.
4
+
5
+ ```typescript
6
+ const greeting = await promptAI()
7
+ .completeChat(() => `Hi! How are you?`)
8
+ console.log(greeting) // Hello! The AI's answer is in the logs
9
+ ```
10
+
11
+ ```typescript
12
+ const restaurants = await promptAI()
13
+ .completeChat(() => `What are the top 5 restaurants in New York City?`)
14
+ .outputJson(o => o
15
+ .canBeArray(e => e
16
+ .canBeObject(o => o
17
+ .hasString('name')
18
+ .hasString('address')
19
+ .hasString('styleOfFood')
20
+ )
21
+ )
22
+ )
23
+ // restaurants is now a strongly typed array with restaurant data
24
+ ```
25
+
26
+ You can also work with incoming JSON while it is still streaming:
27
+ ```typescript
28
+ await promptAI()
29
+ .completeChat(() => `What are the top 5 restaurants in New York City?`)
30
+ .outputJson(o => o
31
+ .canBeArray(e => e
32
+ .canBeObject(o => o
33
+ .hasString('name')
34
+ .hasString('address')
35
+ .hasString('styleOfFood')
36
+ )
37
+ )
38
+ )
39
+ .onElement(restaurant => restaurant
40
+ .onCompleteAs(restaurant => {
41
+ console.log('restaurant:', restaurant)
42
+ })
43
+ )
44
+ ```
45
+
46
+ ## Setup
47
+ Before you do any prompts, do:
48
+ ```typescript
49
+ setupPromptGun(/* your PromptGrid API key */)
50
+ ```
51
+
52
+ Get your API key for free at <a href="https://promptgrid.ai">Promptgrid.ai</a>.
@@ -0,0 +1,263 @@
1
+ import { Flux } from 'monoflux';
2
+
3
+ export declare type AccessTokens = {
4
+ openAi?: string | undefined;
5
+ };
6
+
7
+ export declare class AIClient {
8
+ handshakeData: Promise<HandshakeData>;
9
+ constructor(handshakeData: Promise<HandshakeData>);
10
+ promptLLM<T>(args: T, toPrompt: (args: T) => Prompt, opts?: Opts): Flux<string>;
11
+ promptLLM<T>(args: T, toPrompt: (args: T) => Prompt, json: true, opts?: Opts): StreamedJsonRootElement;
12
+ promptLLM<T>(args: T, toPrompt: (args: T) => Prompt, json?: boolean, opts?: Opts): Flux<string> | StreamedJsonRootElement;
13
+ }
14
+
15
+ export declare type AnyJson = string | null | boolean | number | JsonArray | JsonObject;
16
+
17
+ export declare type ArrayType = BaseType<'array'> & {
18
+ elementType: Type[];
19
+ };
20
+
21
+ export declare type AssistantMessage = {
22
+ system?: undefined;
23
+ user?: undefined;
24
+ assistant: string;
25
+ };
26
+
27
+ export declare type BaseType<TT extends TypeType> = {
28
+ type: TT;
29
+ };
30
+
31
+ export declare class BasicPrompt<PSArgs> implements AsyncGenerator<string>, Promise<string> {
32
+ private aiClient;
33
+ private promptSupplier;
34
+ private promptSupplierArgs;
35
+ private readonly generator;
36
+ constructor(aiClient: AIClient, promptSupplier: (args: PSArgs) => Prompt, promptSupplierArgs: PSArgs);
37
+ next(...[value]: [] | [any]): Promise<IteratorResult<string, any>>;
38
+ return(value: any): Promise<IteratorResult<string, any>>;
39
+ throw(e: any): Promise<IteratorResult<string, any>>;
40
+ [Symbol.asyncIterator](): AsyncGenerator<string, any, any>;
41
+ then<TResult1 = string, TResult2 = never>(onfulfilled?: ((value: string) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
42
+ catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null | undefined): Promise<string | TResult>;
43
+ finally(onfinally?: (() => void) | null | undefined): Promise<string>;
44
+ get [Symbol.toStringTag](): string;
45
+ outputJson<Json extends AnyJson = AnyJson>(type?: (value: TypeSpec<unknown>) => TypeSpec<Json>): JsonPrompt<PSArgs, Json>;
46
+ private getResponseAsString;
47
+ }
48
+
49
+ export declare type BooleanType = BaseType<'boolean'>;
50
+
51
+ export declare type Combine<Current, New> = unknown extends Current ? New : (Current & New) extends never ? Current | New : (Current & New);
52
+
53
+ export declare type ConstantType<Value extends (string | number | boolean)> = BaseType<'constant'> & {
54
+ value: Value;
55
+ };
56
+
57
+ export declare type Consumer<T> = (value: T) => void;
58
+
59
+ export declare type HandshakeData = {
60
+ apiKeys: AccessTokens;
61
+ withinQuotum: boolean;
62
+ };
63
+
64
+ export declare type JsonArray = AnyJson[];
65
+
66
+ export declare type JsonExcerpt = {
67
+ token?: Token;
68
+ source?: string;
69
+ };
70
+
71
+ export declare type JsonObject = {
72
+ [key: string]: AnyJson;
73
+ };
74
+
75
+ export declare class JsonPrompt<PSArgs, Json extends AnyJson = AnyJson> extends StreamedJsonChildElement implements AsyncGenerator<AnyJson>, Promise<Json> {
76
+ private aiClient;
77
+ private promptSupplier;
78
+ private promptSupplierArgs;
79
+ private jsonTypeSupplier;
80
+ private readonly stringGenerator;
81
+ private readonly partialJsonGenerator;
82
+ constructor(aiClient: AIClient, promptSupplier: (args: PSArgs) => Prompt, promptSupplierArgs: PSArgs, jsonTypeSupplier: ((value: TypeSpec<unknown>) => TypeSpec<Json>) | undefined);
83
+ next(...[value]: [] | [any]): Promise<IteratorResult<AnyJson, any>>;
84
+ return(value: any): Promise<IteratorResult<AnyJson, any>>;
85
+ throw(e: any): Promise<IteratorResult<AnyJson, any>>;
86
+ [Symbol.asyncIterator](): AsyncGenerator<AnyJson, any, any>;
87
+ then<TResult1 = Json, TResult2 = never>(onfulfilled?: ((value: Json) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
88
+ catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null | undefined): Promise<Json | TResult>;
89
+ finally(onfinally?: (() => void) | null | undefined): Promise<Json>;
90
+ get [Symbol.toStringTag](): string;
91
+ private getResponse;
92
+ private getResponseAsString;
93
+ }
94
+
95
+ export declare type Message = SystemMessage | UserMessage | AssistantMessage;
96
+
97
+ export declare class ModelNotSupportedError extends Error {
98
+ }
99
+
100
+ export declare class NoAiCredientialsError extends Error {
101
+ }
102
+
103
+ export declare type NullType = BaseType<'null'>;
104
+
105
+ export declare type NumberType = BaseType<'number'>;
106
+
107
+ export declare type ObjectType = BaseType<'object'> & {
108
+ props: Record<string, {
109
+ optional: boolean;
110
+ type: Type[];
111
+ }>;
112
+ };
113
+
114
+ export declare type Opts = {
115
+ model?: 'gpt-4o';
116
+ };
117
+
118
+ export declare type Prompt = string | Message | Message[];
119
+
120
+ export declare function promptAI(client?: AIClient): PromptBase;
121
+
122
+ export declare class PromptBase {
123
+ private aiClient;
124
+ constructor(aiClient: AIClient);
125
+ completeChat<T extends undefined>(toPrompt: (args?: T) => Prompt): BasicPrompt<T>;
126
+ completeChat<T>(toPrompt: (args: T) => Prompt, args: T): BasicPrompt<T>;
127
+ completeChat<T = undefined>(toPrompt: (args?: T) => Prompt, args?: T): BasicPrompt<T>;
128
+ }
129
+
130
+ export declare function promptLLM<T>(args: T, toPrompt: (args: T) => Prompt): Flux<string>;
131
+
132
+ export declare function promptLLM<T>(args: T, toPrompt: (args: T) => Prompt, json: true): StreamedJsonRootElement;
133
+
134
+ export declare function promptLLM<T>(args: T, toPrompt: (args: T) => Prompt, json?: boolean): Flux<string> | StreamedJsonRootElement;
135
+
136
+ export declare type RequireThatOpts = {
137
+ ignoreUnknownProps?: boolean;
138
+ logValueIfWrong?: boolean;
139
+ errorMessage?: string;
140
+ };
141
+
142
+ export declare function setupPromptGun(apiKey: string): AIClient;
143
+
144
+ export declare class StreamedJsonChildElement extends StreamedJsonElement {
145
+ constructor();
146
+ }
147
+
148
+ export declare abstract class StreamedJsonElement {
149
+ protected readonly receivedJson: string[];
150
+ private readonly propertyCallbacks;
151
+ private onElementCallbacks;
152
+ private onCompleteCallbacks;
153
+ private onEachExcerptCallbacks;
154
+ private currentToken?;
155
+ private state;
156
+ private receivedExcerpts;
157
+ onElement(callback: Consumer<StreamedJsonElement>): StreamedJsonElement;
158
+ onProperty(propertyName: string, callback: (element: StreamedJsonElement) => void): StreamedJsonElement;
159
+ /**
160
+ * @deprecated Does not work right now because FIELD_NAME
161
+ * token comes after string value is already streaming
162
+ */
163
+ onJsonStringProperty(propertyName: string, callback: (element: StreamedJsonElement) => void): StreamedJsonElement;
164
+ onEachExcerpt(callback: Consumer<JsonExcerpt>): StreamedJsonElement;
165
+ /**
166
+ * @param onComplete - a callback that will receive the complete JSON
167
+ * string for this element once it's done streaming
168
+ */
169
+ onComplete(onComplete: Consumer<string>): void;
170
+ private _onComplete;
171
+ onCompleteAsync(onComplete: (value: string) => Promise<void>): void;
172
+ onCompleteAs<T>(onComplete: Consumer<T>): void;
173
+ onCompleteAsAsync<T>(onComplete: (value: T) => Promise<void>): void;
174
+ onCompleteAsString(onComplete: Consumer<string>): void;
175
+ onCompleteAsStringAsync(onComplete: (value: string) => Promise<void>): void;
176
+ onCompleteAsInt(onComplete: Consumer<number>): void;
177
+ onCompleteAsIntAsync(onComplete: (value: number) => Promise<void>): void;
178
+ onCompleteAsNumber(onComplete: Consumer<number>): void;
179
+ onCompleteAsNumberAsync(onComplete: (value: number) => Promise<void>): void;
180
+ onCompleteAsBoolean(onComplete: Consumer<boolean>): void;
181
+ onCompleteAsBooleanAsync(onComplete: (value: boolean) => Promise<void>): void;
182
+ whenComplete(): Promise<string>;
183
+ asJsonFlux(): Flux<string>;
184
+ whenCompleteAs<T>(): Promise<T>;
185
+ push(excerpt: JsonExcerpt): Promise<void>;
186
+ protected end(): Promise<void>;
187
+ private isState;
188
+ private endsOnUnevenNumberOfBackslashes;
189
+ private toAsync;
190
+ }
191
+
192
+ export declare class StreamedJsonRootElement extends StreamedJsonElement {
193
+ protected readonly jsonTokenFlux: Flux<JsonExcerpt>;
194
+ constructor(jsonTokenFlux: Flux<JsonExcerpt>);
195
+ whenComplete(): Promise<string>;
196
+ asJsonFlux(): Flux<string>;
197
+ }
198
+
199
+ export declare type StringType = BaseType<'string'>;
200
+
201
+ export declare type SystemMessage = {
202
+ system: string;
203
+ user?: undefined;
204
+ assistant?: undefined;
205
+ };
206
+
207
+ export declare class Token {
208
+ type: TokenType;
209
+ source: string;
210
+ value?: string | number | undefined;
211
+ fieldName?: string | undefined;
212
+ maybeIncomplete: boolean;
213
+ constructor(type: TokenType, source: string, value?: string | number | undefined, fieldName?: string | undefined, maybeIncomplete?: boolean);
214
+ }
215
+
216
+ export declare enum TokenType {
217
+ START_OBJECT = "START_OBJECT",
218
+ END_OBJECT = "END_OBJECT",
219
+ START_ARRAY = "START_ARRAY",
220
+ END_ARRAY = "END_ARRAY",
221
+ FIELD_NAME = "FIELD_NAME",
222
+ VALUE_STRING = "VALUE_STRING",
223
+ VALUE_NUMBER_INT = "VALUE_NUMBER_INT",
224
+ VALUE_NUMBER_FLOAT = "VALUE_NUMBER_FLOAT",
225
+ VALUE_TRUE = "VALUE_TRUE",
226
+ VALUE_FALSE = "VALUE_FALSE",
227
+ VALUE_NULL = "VALUE_NULL"
228
+ }
229
+
230
+ export declare type Type = UndefinedType | NullType | BooleanType | StringType | NumberType | ObjectType | ArrayType | ConstantType<any>;
231
+
232
+ export declare class TypeSpec<T> {
233
+ readonly type: Type[];
234
+ private readonly value;
235
+ constructor(type: Type[] | undefined, value: unknown);
236
+ canBeArray<T_arr = unknown>(assertTypeOfArray: (arg: TypeSpec<unknown>) => TypeSpec<T_arr>): TypeSpec<Combine<T, T_arr[]>>;
237
+ canBeObject<T_obj extends {}>(assertTypeOfObject: (arg: TypeSpec<{}>) => TypeSpec<T_obj>): TypeSpec<Combine<T, T_obj>>;
238
+ hasString<Key extends string>(propertyName: Key): TypeSpec<Combine<T, Record<Key, string>>>;
239
+ canHaveProperty<Key extends string, T_prop>(propertyName: Key, assertTypeOfProperty: (arg: TypeSpec<unknown>) => TypeSpec<T_prop | undefined>): TypeSpec<Combine<T, Partial<Record<Key, T_prop>>>>;
240
+ hasProperty<Key extends string, T_prop>(propertyName: Key, assertTypeOfProperty: (arg: TypeSpec<unknown>) => TypeSpec<T_prop>, optional: false): TypeSpec<Combine<T, Partial<Record<Key, T_prop>>>>;
241
+ hasProperty<Key extends string, T_prop>(propertyName: Key, assertTypeOfProperty: (arg: TypeSpec<unknown>) => TypeSpec<T_prop>, optional?: boolean): TypeSpec<Combine<T, Record<Key, T_prop>>>;
242
+ canBeString(): TypeSpec<Combine<T, string>>;
243
+ canBeNumber(): TypeSpec<Combine<T, number>>;
244
+ canBeBoolean(): TypeSpec<Combine<T, boolean>>;
245
+ canBeConstant<Value extends (string | number | boolean)>(value: Value): TypeSpec<Combine<T, Value>>;
246
+ canBeNull(): TypeSpec<Combine<T, null>>;
247
+ canBeUndefined(): TypeSpec<Combine<T, undefined>>;
248
+ andNothingElse(opts?: RequireThatOpts): T;
249
+ orDefaultTo<Value>(value: Value, opts?: RequireThatOpts): T | Value;
250
+ describe(): string;
251
+ }
252
+
253
+ export declare type TypeType = 'undefined' | 'null' | 'boolean' | 'string' | 'number' | 'object' | 'array' | 'constant';
254
+
255
+ export declare type UndefinedType = BaseType<'undefined'>;
256
+
257
+ export declare type UserMessage = {
258
+ system?: undefined;
259
+ user: string;
260
+ assistant?: undefined;
261
+ };
262
+
263
+ export { }
package/build/index.js ADDED
@@ -0,0 +1,2 @@
1
+ var t=Object.create,e=Object.defineProperty,r=Object.getOwnPropertyDescriptor,s=Object.getOwnPropertyNames,i=Object.getPrototypeOf,n={}.hasOwnProperty,o=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),a=(o,a,l)=>(l=null!=o?t(i(o)):{},((t,i,o,a)=>{if(i&&"object"==typeof i||"function"==typeof i)for(let o of s(i))!n.call(t,o)&&void 0!==o&&e(t,o,{get:()=>i[o],enumerable:!(a=r(i,o))||a.enumerable});return t})(!a&&o&&o.t?l:e(l,"default",{value:o,enumerable:!0}),o)),l=o((t=>{"use strict";Object.defineProperty(t,"t",{value:!0}),t.Flux=void 0;var e=class t{generator;upstream;handleCancel;i=!1;constructor(t,e,s){let i=this;this.generator=async function*(){try{yield*t}catch(t){throw yield r,t}finally{i.i=!0}}(),this.upstream=e,this.handleCancel=s}[Symbol.asyncIterator](){return this}async next(...t){let e=await this.generator.next(t);return e.value!==r?e:await this.next(t)}return(t){return this.generator.return(t)}throw(t){return this.generator.throw(t)}async cancel(t){if(!this.closed){if(void 0!==this.upstream)return this.upstream.cancel(t);void 0!==this.handleCancel?this.handleCancel(t):await this.throw(t)}}async then(t,e){try{let e=await this.asList();return null!=t?await t(e):e}catch(t){if(null!=e)return e(t);throw t}}async catch(t){try{return this.asList()}catch(e){if(null!=t)return t(e);throw e}}async finally(t){let e=await this.asList();return t?.(),e}get[Symbol.toStringTag](){return"Flux"}subscribe(t){let e=void 0!==t?this.doOnEach(t):this,r=()=>{e.next().then((t=>{t.done||r()})).catch((t=>{}))};return r(),{unsubscribe:()=>this.return()}}filter(e){let r=this;return t.constructFromGeneratorFunction((async function*(){for await(let t of r)e(t)&&(yield t)}),this)}untilExcl(e){let r=this;return t.constructFromGeneratorFunction((async function*(){for await(let t of r){if(e(t))break;yield t}}),this)}doOnEach(e){let r=this;return t.constructFromGeneratorFunction((async function*(){for await(let t of r)e(t),yield t}),this)}doAfterLast(e){let r=this,s=[];return t.constructFromGeneratorFunction((async function*(){for await(let t of r)s.push(t),yield t;await e(s)}),this)}map(e){let r=this;return t.constructFromGeneratorFunction((async function*(){for await(let t of r)yield e(t)}),this)}take(e){let r=this;return t.constructFromGeneratorFunction((async function*(){let t=0;for await(let s of r){if(t>=e){r.cancel();break}t++,yield s}}),this)}flatMap(e){let r=this;return t.constructFromGeneratorFunction((async function*(){for await(let t of r){let r=e(t);if(Array.isArray(r))for(let t of r)yield t;else yield await r}}),this)}transform(e){let r=e(this);return t.constructFromGeneratorFunction((async function*(){for await(let t of r)yield t}),this)}async reduce(t,e){let r=e;for await(let e of this)r=t(r,e);return r}async asList(){let t=[];for await(let e of this)t.push(e);return t}async whenComplete(){for await(let t of this);}static create(e){let r,s=[],i=[],n=!1,o=()=>{for(n=!0;i.length>0;)i.shift().resolve({done:!0,value:void 0})};return e((t=>{if(n)throw Error("Cannot push to a completed generator");i.length>0?i.shift().resolve({done:!1,value:t}):s.push(t)}),o),t.fromGenerator({[Symbol.asyncIterator](){return this},next(...t){if(r){let t=r.value;return r=void 0,Promise.reject(t)}if(s.length>0){let t=s.shift();return Promise.resolve({done:!1,value:t})}return n?Promise.resolve({done:!0,value:void 0}):new Promise(((t,e)=>{i.push({resolve:t,reject:e})}))},return:()=>(o(),Promise.resolve({done:!0,value:void 0})),throw:t=>(r=t,i.length>0&&i.shift()?.reject(),Promise.reject(t))})}static fromArray(e){return t.fromGeneratorFunction((async function*(){for(let t of e)yield t}))}static constructFromGeneratorFunction(e,r,s){return new t(e(),r,s)}static fromGeneratorFunction(e,r){return t.constructFromGeneratorFunction(e,void 0,r)}static fromGenerator(e,r){return new t(e,void 0,r)}static fromReadableStream(e,r){return t.fromGeneratorFunction((async function*(){let t=e.getReader();try{let e;for(;!(e=await t.read()).done;)yield e.value}finally{await t.cancel()}}),r)}get closed(){return this.i}};t.Flux=e;var r={}})),h=o((t=>{"use strict";Object.defineProperty(t,"t",{value:!0}),t.Flux=void 0;var e=l();Object.defineProperty(t,"Flux",{enumerable:!0,get:function(){return e.Flux}})})),u=a(h(),1),c=a(h(),1),p=new TextDecoder,f=class extends Error{data;httpStatus=400;constructor(t,e){let r=t.map((t=>{if(t.expectedProp)return{expectedProp:(t.path+".").replace(/^root\./,"")+t.expectedProp};if(t.expectedType)return{expectedType:t.expectedType.map(v).join(" | "),path:t.path,insteadGot:t.value};if(t.unknownProp)return{unknownProp:(t.path+".").replace(/^root\./,"")+t.unknownProp};throw Error("illegal state")}));super(e??"Value is of the wrong format: "+JSON.stringify(r,null,2)),this.data=r}};function w(t){return new E([],t)}function d(t,e,r,s){let i=e.map((e=>function(t,e,r,s){let{ignoreUnknownProps:i=!0}=s;switch(e.type){case"array":return Array.isArray(t)?0===t.length?[]:d(t[0],e.elementType,r+"[..]",s):[{expectedType:[e],path:r,value:t}];case"boolean":return"boolean"!=typeof t?[{expectedType:[e],path:r,value:t}]:[];case"undefined":return void 0===t?[]:[{expectedType:[e],path:r,value:t}];case"object":{if("object"!=typeof t||null===t)return[{expectedType:[e],path:r,value:t}];let n=[];for(let i in e.props){let o=e.props[i];if(!(i in t)){o.optional||n.push({expectedProp:i,path:r,value:t});continue}let a=o.optional?[...o.type,{type:"undefined"}]:o.type;n.push(...d(t[i],a,r+"."+i,s))}if(!i)for(let s in t)s in e.props||n.push({unknownProp:s,path:r,value:t});return n}case"string":return"string"==typeof t?[]:[{expectedType:[e],path:r,value:t}];case"null":return null===t?[]:[{expectedType:[e],path:r,value:t}];case"number":return"number"==typeof t?[]:[{expectedType:[e],path:r,value:t}];case"constant":return t===e.value?[]:[{expectedType:[e],path:r,value:t}]}}(t,e,r,s)));if(i.some((t=>0===t.length)))return[];{let e=i.flatMap((t=>t.filter((t=>void 0!==t.expectedType&&t.path===r))));return e.length>0?[{expectedType:e.flatMap((t=>t.expectedType)),path:r,value:t}]:i.flatMap((t=>t))}}var y,E=class t{type;value;constructor(t=[],e){this.type=t,this.value=e}canBeArray(e){let r=e(new t([{type:"array",elementType:[]}],this.value));return new t([...this.type,...r.type],this.value)}canBeObject(e){let r=e(new t([{type:"object",props:{}}],this.value));return new t([...this.type,...r.type],this.value)}hasString(t){return this.hasProperty(t,(t=>t.canBeString()))}canHaveProperty(t,e){return this.hasProperty(t,e,!0)}hasProperty(e,r,s=!1){let i=1===this.type.length?this.type[0]:void 0;if(void 0===i||"object"!==i.type)throw Error("illegal state");let{type:n}=r(new t([],this.value));return new t([{...i,props:{...i.props,[e]:{optional:s,type:n}}}],this.value)}canBeString(){return new t([...this.type,{type:"string"}],this.value)}canBeNumber(){return new t([...this.type,{type:"number"}],this.value)}canBeBoolean(){return new t([...this.type,{type:"boolean"}],this.value)}canBeConstant(e){return new t([...this.type,{type:"constant",value:e}],this.value)}canBeNull(){return new t([...this.type,{type:"null"}],this.value)}canBeUndefined(){return new t([...this.type,{type:"undefined"}],this.value)}andNothingElse(t={}){let e=d(this.value,this.type,"root",t);if(e.length>0)throw new f(e,t.errorMessage);return this.value}orDefaultTo(t,e={}){return d(this.value,this.type,"root",e).length>0?t:this.value}describe(){return A(this.type)}};function A(t,e=0){if(Array.isArray(t))return t.map((t=>A(t,e))).join(" | ");switch(t.type){case"array":return A(t.elementType)+"[]\n";case"boolean":return"boolean";case"undefined":return"undefined";case"object":return`{\n${function(t){let e="";for(let r=0;r<t;r++)e+=" ";return e}(e+1)}${Object.keys(t.props).map((e=>`${e}: ${A(t.props[e].type)}\n`)).join(", ")}}`;case"string":return"string";case"null":return"null";case"number":return"number";case"constant":return`"${t.value}"`}}function v(t){return"constant"===t.type?`'${t.value}'`:t.type}var m=class{constructor(t,e,r,s,i=!1){this.type=t,this.source=e,this.value=r,this.fieldName=s,this.maybeIncomplete=i}},L=class t{jsonBuffer="";highestOffsetParsed=-1;static toJsonTokenFlux(e){return(new t).processDataBuffer(e)}processDataBuffer(t){return t.flatMap((t=>this.getExcerpts(t)))}getExcerpts(t){this.jsonBuffer+=t;let e,r=[],s=new _(this.jsonBuffer);for(;e=this.nextToken(s);)s.currentTokenLocation().getCharOffset()>this.highestOffsetParsed&&(r.push({token:e}),this.highestOffsetParsed=s.currentTokenLocation().getCharOffset());return r.push({source:t}),r}nextToken(t){let e=t.nextToken();return"string"!=typeof e?e:void 0}},_=class{constructor(t){this.content=t}position=0;currentTokenType;parentFieldName;currentValue=null;nextToken(){let t=this.position;if(this.position>=this.content.length)return"string-ended";for(;this.position<this.content.length&&/\s/.test(this.content[this.position]);)this.position++;if(this.position>=this.content.length)return"string-ended";let e=t=>{let e=t;for(;e<this.content.length&&/\s/.test(this.content[e]);)e++;return","===this.content[e]?e+1:void 0},r=e=>this.content.substring(t,e),s=this.content[this.position];switch(s){case"{":return this.position++,this.currentTokenType="START_OBJECT",new m(this.currentTokenType,r(this.position),void 0,this.parentFieldName);case"}":{this.position++,this.currentTokenType="END_OBJECT",this.position=e(this.position)??this.position;let t=new m(this.currentTokenType,r(this.position),void 0,this.parentFieldName);return this.parentFieldName=void 0,t}case"[":return this.position++,this.currentTokenType="START_ARRAY",new m(this.currentTokenType,r(this.position),void 0,this.parentFieldName);case"]":{this.position++,this.currentTokenType="END_ARRAY",this.position=e(this.position)??this.position;let t=new m(this.currentTokenType,r(this.position),void 0,this.parentFieldName);return this.parentFieldName=void 0,t}case'"':let t=++this.position,i=this.content.indexOf('"',t);for(;i>0&&"\\"===this.content[i-1];)i=this.content.indexOf('"',i+1);if(-1===i)return"token-incomplete";let n=this.content.substring(t,i);this.position=i+1;let o=this.position;for(;o<this.content.length&&/\s/.test(this.content[o]);)o++;if(this.currentTokenType=o<this.content.length&&":"===this.content[o]?"FIELD_NAME":"VALUE_STRING","FIELD_NAME"===this.currentTokenType){this.position=o+1,this.position=e(this.position)??this.position;let t=new m(this.currentTokenType,r(this.position),n,void 0);return this.parentFieldName=n,t}{this.currentValue=n,this.position=e(this.position)??this.position;let t=new m(this.currentTokenType,r(this.position),n,"VALUE_STRING"===this.currentTokenType?this.parentFieldName:void 0);return this.parentFieldName=void 0,t}case"t":{let t=this.content.substring(this.position,this.position+4);if("true"===t)return this.position+=4,this.position=e(this.position)??this.position,this.currentTokenType="VALUE_TRUE",this.currentValue=!0,new m(this.currentTokenType,r(this.position),this.currentValue,this.parentFieldName);if(t.length<4)return"token-incomplete";break}case"f":{let t=this.content.substring(this.position,this.position+5);if("false"===t)return this.position+=5,this.position=e(this.position)??this.position,this.currentTokenType="VALUE_FALSE",this.currentValue=!1,new m(this.currentTokenType,r(this.position),this.currentValue,this.parentFieldName);if(t.length<5)return"token-incomplete";break}case"n":{let t=this.content.substring(this.position,this.position+4);if("null"===t)return this.position+=4,this.position=e(this.position)??this.position,this.currentTokenType="VALUE_NULL",this.currentValue=null,new m(this.currentTokenType,r(this.position),this.currentValue,this.parentFieldName);if(t.length<4)return"token-incomplete";break}default:if(/[0-9-]/.test(s)){let t="",s=!1;for(;this.position<this.content.length&&(/[0-9]/.test(this.content[this.position])||"-"===this.content[this.position]||"."===this.content[this.position]||"e"===this.content[this.position]||"E"===this.content[this.position]||"+"===this.content[this.position]);)"."===this.content[this.position]&&(s=!0),t+=this.content[this.position++];s?(this.currentTokenType="VALUE_NUMBER_FLOAT",this.currentValue=parseFloat(t)):(this.currentTokenType="VALUE_NUMBER_INT",this.currentValue=parseInt(t,10));let i=this.position>=this.content.length;return this.position=e(this.position)??this.position,new m(this.currentTokenType,r(this.position),this.currentValue,this.parentFieldName,i)}}throw new U("Invalid JSON at position "+this.position)}currentTokenLocation(){return{getCharOffset:()=>this.position}}},U=class extends Error{constructor(t){super(t),this.name="JsonParseException"}},T=a(h(),1),N=class{receivedJson=[];propertyCallbacks=new Map;onElementCallbacks=new Set;onCompleteCallbacks=new Set;onEachExcerptCallbacks=new Set;currentToken;state=new g;receivedExcerpts=[];onElement(t){return this.onElementCallbacks.add(t),this}onProperty(t,e){return this.propertyCallbacks.has(t)||this.propertyCallbacks.set(t,[]),this.propertyCallbacks.get(t).push(e),this}onJsonStringProperty(t,e){return this.propertyCallbacks.has(t)||this.propertyCallbacks.set(t,[]),this.propertyCallbacks.get(t).push((t=>{let r=new C,s=[],i=new B;t.onEachExcerpt((t=>{void 0!==t.source&&s.push(t.source);let e=s.join(""),n=this.endsOnUnevenNumberOfBackslashes(e)?e.substring(0,e.length-1):e;s.length=0;let o=n.replace(/\\"/g,'"').substring(1),a=null!=t.token?o.substring(0,o.length-1):o;r.getExcerpts(a).forEach((t=>i.push(t)))})),e(i)})),this}onEachExcerpt(t){return this.onEachExcerptCallbacks.add(t),this.receivedExcerpts.forEach(t),this}onComplete(t){this.o(this.toAsync(t),void 0)}o(t,e){this.onCompleteCallbacks.add({consumer:t,expectedTokenType:e})}onCompleteAsync(t){this.o(t,void 0)}onCompleteAs(t){this.onCompleteAsAsync(this.toAsync(t))}onCompleteAsAsync(t){this.o((e=>{let r=JSON.parse(e.replace(/,$/,""));return t(r)}),void 0)}onCompleteAsString(t){this.o(this.toAsync(t),new Set(["VALUE_STRING","VALUE_NULL"]))}onCompleteAsStringAsync(t){this.o(t,new Set(["VALUE_STRING","VALUE_NULL"]))}onCompleteAsInt(t){this.o(this.toAsync(t),new Set(["VALUE_NUMBER_INT","VALUE_NULL"]))}onCompleteAsIntAsync(t){this.o(t,new Set(["VALUE_NUMBER_INT","VALUE_NULL"]))}onCompleteAsNumber(t){this.o(this.toAsync(t),new Set(["VALUE_NUMBER_INT","VALUE_NUMBER_FLOAT","VALUE_NULL"]))}onCompleteAsNumberAsync(t){this.o(t,new Set(["VALUE_NUMBER_INT","VALUE_NUMBER_FLOAT","VALUE_NULL"]))}onCompleteAsBoolean(t){this.o(this.toAsync(t),new Set(["VALUE_TRUE","VALUE_FALSE","VALUE_NULL"]))}onCompleteAsBooleanAsync(t){this.o(t,new Set(["VALUE_TRUE","VALUE_FALSE","VALUE_NULL"]))}whenComplete(){return new Promise((t=>{this.onComplete((e=>t(e)))}))}asJsonFlux(){return T.Flux.create(((t,e)=>{this.onEachExcerpt((e=>{e.source&&t(e.source)})),this.o((async()=>e()))}))}whenCompleteAs(){return new Promise((t=>{this.onCompleteAs(t)}))}async push(t){let e=t.token;if(this.onEachExcerptCallbacks.forEach((e=>e(t))),this.isState(S))return this.state.child.push(t);if(!e)return;let r=e.type;if(this.currentToken=e,this.isState(g))switch(r){case"START_OBJECT":if(this.onElementCallbacks.size>0)throw Error("registered onElement for object");return this.state=new V,void this.receivedJson.push(e.source);case"START_ARRAY":if(this.propertyCallbacks.size>0)throw Error("registered onProperty for array");return this.state=new R,void this.receivedJson.push(e.source);case"VALUE_STRING":case"VALUE_NUMBER_INT":case"VALUE_NUMBER_FLOAT":case"VALUE_TRUE":case"VALUE_FALSE":case"VALUE_NULL":return this.receivedJson.push(e.source),this.end();default:throw new P(e)}else if(this.isState(V))switch(r){case"FIELD_NAME":return void this.receivedJson.push(e.source);case"END_OBJECT":return this.receivedJson.push(e.source),this.end();case"START_OBJECT":case"START_ARRAY":case"VALUE_STRING":case"VALUE_NUMBER_INT":case"VALUE_NUMBER_FLOAT":case"VALUE_TRUE":case"VALUE_FALSE":case"VALUE_NULL":{let r=new B;return r.onComplete((t=>{this.receivedJson.push(t),this.state=new V})),this.state=new O(r),this.propertyCallbacks.get(e.fieldName)?.forEach((t=>t(r))),r.push(t)}default:throw new P(e)}else if(this.isState(R))switch(r){case"END_ARRAY":return this.receivedJson.push(e.source),this.end();case"START_OBJECT":case"START_ARRAY":case"VALUE_STRING":case"VALUE_NUMBER_INT":case"VALUE_NUMBER_FLOAT":case"VALUE_TRUE":case"VALUE_FALSE":case"VALUE_NULL":{let e=new B;return e.onComplete((t=>{this.receivedJson.push(t),this.state=new R})),this.onElementCallbacks.forEach((t=>t(e))),this.state=new x(e),e.push(t)}default:throw new P(e)}throw Error("Unknown state")}async end(){if(void 0===this.currentToken)throw Error("Illegal state");await T.Flux.fromArray([...this.onCompleteCallbacks]).flatMap((t=>{let e=t.expectedTokenType,r=(()=>{if(void 0===e)return this.receivedJson.join("");if(!e.has(this.currentToken.type))throw Error(`Expected token type ${Array.from(e).join(", ")} but got ${this.currentToken.type}`);return this.currentToken.value})();return t.consumer(r)}))}isState(t){return this.state instanceof t}endsOnUnevenNumberOfBackslashes(t){let e=0;for(let r=t.length-1;r>=0&&"\\"===t[r];r--)e++;return e%2==1}toAsync(t){return async e=>{t(e)}}},b=class{},S=class extends b{constructor(t){super(),this.child=t}},g=class extends b{},R=class extends b{},x=class extends S{constructor(t){super(t)}},V=class extends b{},O=class extends S{constructor(t){super(t)}},P=class extends Error{constructor(t){super("Unexpected token: "+t.type),this.name="UnexpectedTokenException"}},C=class{getExcerpts(t){return[{source:t}]}},B=class extends N{constructor(){super()}},k=a(h(),1),I=class extends N{jsonTokenFlux;constructor(t){super();let e=this;this.jsonTokenFlux=k.Flux.fromGeneratorFunction((async function*(){let r;for await(let s of t)void 0!==s.token&&(r?.token?.maybeIncomplete&&r.token.type===s.token.type&&!s.token.maybeIncomplete&&await e.push(s),r=s.token),(void 0===s.token||!s.token.maybeIncomplete)&&await e.push(s),yield s;r?.token?.maybeIncomplete&&await e.push(r)}))}whenComplete(){return this.jsonTokenFlux.then((()=>this.receivedJson.join("")))}asJsonFlux(){return this.jsonTokenFlux.map((t=>t.source)).filter((t=>void 0!==t))}},j=class{parse(t){return new I(t)}};function J(t){if(""===t.trim())return;let e=[],r=!1,s=t=>e.push(t),i=(...t)=>{let r=e[e.length-1];if(void 0===r||!t.includes(r))throw Error("illegal state");e.pop()},n=()=>Error(`Illegal state (json: ${t})`);for(let o of t){let t=e.length>0?e[e.length-1]:null,a=!1;if('"'===o)if(null===t)s('"value');else if("["===t)s('"value');else if("{"===t)s('"prop');else if('"prop":'===t)i('"prop":'),s('"value');else if('"prop'===t)r||(i('"prop'),s('"prop"'));else{if('"value'!==t)throw n();r||i('"value')}else if("["===o){if(null===t)s("[");else if("["===t)s("[");else if('"prop":'===t)s("[");else if('"prop'!==t&&'"value'!==t)throw n()}else if("{"===o){if(null!==t&&"["!==t&&'"prop":'!==t)throw n();s("{")}else if("\\"===o){if('"prop'!==t&&'"value'!==t)throw n();r||(a=!0)}else if(":"===o){if('"prop"'===t)i('"prop"'),s('"prop":');else if('"prop'!==t&&'"value'!==t)throw n()}else if("n"===o){if('"prop":'===t)i('"prop":'),s("n");else if('"prop'!==t&&'"value'!==t)throw n()}else if("u"===o){if("n"===t)i("n"),s("nu");else if("tr"===t)i("tr"),s("tru");else if('"prop'!==t&&'"value'!==t)throw n()}else if("l"===o){if("nu"===t)i("nu"),s("nul");else if("nul"===t)i("nul");else if("fa"===t)i("fa"),s("fal");else if('"prop'!==t&&'"value'!==t)throw n()}else if("t"===o){if('"prop":'===t)i('"prop":'),s("t");else if('"prop'!==t&&'"value'!==t)throw n()}else if("r"===o){if("t"===t)i("t"),s("tr");else if('"prop'!==t&&'"value'!==t)throw n()}else if("e"===o){if("tru"===t)i("tru");else if("fals"===t)i("fals");else if('"prop'!==t&&'"value'!==t)throw n()}else if("f"===o){if('"prop":'===t)i('"prop":'),s("f");else if('"prop'!==t&&'"value'!==t)throw n()}else if("a"===o){if("f"===t)i("f"),s("fa");else if('"prop'!==t&&'"value'!==t)throw n()}else if("s"===o){if("fal"===t)i("fal"),s("fals");else if('"prop'!==t&&'"value'!==t)throw n()}else if("."===o){if('"prop":'===t)i('"prop":'),s("number.");else if('"prop'!==t&&'"value'!==t)throw n()}else if(o.match(/[0-9]/)){if("number."===t)i("number.");else if('"prop'!==t&&'"value'!==t){if('"prop":'!==t)throw n();i('"prop":')}}else if("}"===o){if("{"===t)i("{");else if('"prop'!==t&&'"value'!==t)throw n()}else if("]"===o)if("["===t)i("[");else if('"prop'!==t&&'"value'!==t)throw n();r=a}let o=e.reverse().map((t=>{switch(t){case"{":return"}";case"[":return"]";case'"prop':return'": null';case'"prop"':return": null";case'"prop":':return" null";case"n":return"ull";case"nu":return"ll";case"nul":return"l";case"t":return"rue";case"tr":return"ue";case"tru":case"fals":return"e";case"f":return"alse";case"fa":return"lse";case"fal":return"se";case'"value':return'"';case"number.":return"0";default:throw n()}})).join(""),a=(r?t.substring(0,t.length-1):t).replace(/( |\n|,)+$/,"")+o;try{return JSON.parse(a)}catch(t){throw t}}function M(t){return null!=t}function F(t){if(void 0===t)throw Error("Value is undefined");return t}var G,$=class{constructor(t){this.handshakeData=t}promptLLM(t,e,r,s){return Z(this,t,e,r,s)}};function D(t){if("string"!=typeof t)throw Error("Please provide a valid API key; got "+t);let e=new $((async()=>{let e=await fetch(function(){if(!y){let t=function(){let t="t";t+="ps",t="ht"+t,t+=":",t+="/",t+="/ap",t+="i.pr";let e="i";return e="d.a"+e,e="gri"+e,t+="ompt",t+e}();y=w(t).canBeString().andNothingElse({errorMessage:"PromptGrid API URL invalid: "+t})}return y}()+"/handshake",{method:"POST",headers:{"Content-Type":"application/json","User-Agent":"promptgun",Authorization:"Bearer "+t}});if(200!==e.status){let t=await e.text();throw Error(`Handshake failed with status ${e.status}, body: ${t}`)}return await e.json()})());return G=e,e}function Y(t,e,r,s){if(void 0===G)throw Error("No LLM set up. Call setupLLM first: ```import { setupPromptGun } from 'promptgun';\n\nsetupPromptGun({openAI: \"YOUR_OPENAI_API_KEY\"});\n```");return Z(G,t,e,r,s)}function K(t){let e=t??G;if(void 0===e)throw Error("No LLM set up. Call setupPromptGun first: ```import { setupPromptGun } from 'promptgun';\n\nsetupPromptGun({openAI: \"YOUR_OPENAI_API_KEY\"});\n```");return new q(e)}var q=class{constructor(t){this.aiClient=t}completeChat(t,e){return new z(this.aiClient,t,e)}},z=class{constructor(t,e,r){this.aiClient=t,this.promptSupplier=e,this.promptSupplierArgs=r,this.generator=async function*(){yield*await W(t,void 0,e(r),!1)}()}generator;next(...[t]){return this.generator.next(t)}return(t){return this.generator.return(t)}throw(t){return this.generator.throw(t)}[Symbol.asyncIterator](){return this}async then(t,e){try{let e=await this.getResponseAsString();return M(t)?await t(e):e}catch(t){if(M(e))return await e(t);throw t}}async catch(t){try{return await this.getResponseAsString()}catch(e){if(M(t))return t(e);throw e}}async finally(t){try{return await this.getResponseAsString()}finally{t?.()}}get[Symbol.toStringTag](){return"BasicPrompt"}outputJson(t){return new H(this.aiClient,this.promptSupplier,this.promptSupplierArgs,t)}async getResponseAsString(){let t="";for await(let e of this)t+=e;return t}},H=class extends B{constructor(t,e,r,s){let i=async function*(){yield*await W(t,void 0,e(r),void 0!==s&&s(w(void 0)))}(),n=u.Flux.fromGenerator(i),o=(new L).processDataBuffer(n);super(),this.aiClient=t,this.promptSupplier=e,this.promptSupplierArgs=r,this.jsonTypeSupplier=s;let a=this,l=(new j).parse(o);l.onProperty("result",(t=>t.onEachExcerpt((t=>{void 0!==t.token&&this.push(t)})))),this.stringGenerator=async function*(){for await(let t of o)void 0!==t.token?l.push(t):void 0!==t.source&&(yield t.source)}(),this.partialJsonGenerator=async function*(){let t="";for await(let e of a.stringGenerator)t+=e,yield J(t).result}()}stringGenerator;partialJsonGenerator;next(...[t]){return this.partialJsonGenerator.next(t)}return(t){return this.partialJsonGenerator.return(t)}throw(t){return this.partialJsonGenerator.throw(t)}[Symbol.asyncIterator](){return this.partialJsonGenerator}async then(t,e){try{let e=await this.getResponse();return M(t)?await t(e):e}catch(t){if(M(e))return await e(t);throw t}}async catch(t){try{return await this.getResponse()}catch(e){if(M(t))return t(e);throw e}}async finally(t){try{return await this.getResponse()}finally{t?.()}}get[Symbol.toStringTag](){return"BasicPrompt"}async getResponse(){let t=await this.getResponseAsString(),e=JSON.parse(t)?.result,r=this.jsonTypeSupplier;return void 0===r?e:r(w(e)).andNothingElse()}async getResponseAsString(){let t="";for await(let e of this.stringGenerator)t+=e;return t}};function Q(t){return t??"gpt-4o"}async function*W(t,e,r,s){let i=await t.handshakeData,{apiKeys:n}=i;if(void 0===n.openAi)throw new tt("No OpenAI access token set");let o=function(t){let e=t=>({role:void 0!==t.user?"user":void 0!==t.system?"system":"assistant",content:F(t.user??t.system??t.assistant)});return"string"==typeof t?[{role:"user",content:t}]:Array.isArray(t)?t.map(e):[e(t)]}(r),a=s?[...o,{role:"system",content:X(0,s)}]:o;yield*function({model:t,prompt:e,apiToken:r,requireJsonResponse:s}){return c.Flux.fromGeneratorFunction((async function*(){let i=new AbortController;if("llama-2-7b-chat"===t)throw Error("illegal state");let n=await fetch("https://api.openai.com/v1/chat/completions",{headers:{"Content-Type":"application/json",Accept:"application/json",Authorization:"Bearer "+r},method:"POST",signal:i.signal,body:JSON.stringify({model:t,messages:e,stream:!0,response_format:s?{type:"json_object"}:void 0})});if(n.status<200||n.status>=300){let t=function(t){try{return JSON.parse(t).error.message}catch{return t}}(await n.text());throw Error("OpenAPI reported: "+t)}if(null===n.body)throw Error("illegal state");let o="";yield*c.Flux.fromReadableStream(n.body,(()=>i.abort())).map((t=>p.decode(t,{stream:!0}))).flatMap((t=>t.replaceAll("data: [DONE]","").replace(/^data: /,"").split("data: "))).map((t=>t.replace(/[\n ]*$/,"").trim())).flatMap((t=>{o+=t;try{let t=JSON.parse(o);return o="",[t]}catch{return[]}})).map((t=>t.choices[0])).untilExcl((t=>null!=t.finish_reason)).map((t=>t.delta.content)).filter((t=>void 0!==t))}))}({model:Q(e),prompt:a,apiToken:n.openAi,requireJsonResponse:!1!==s})}function X(t,e){return!0===e?"Respond with JSON":"Respond with JSON matching the following type spec (note: everything is nonnullable unless explicitly stated otherwise): "+new E([{type:"object",props:{}}],void 0).hasProperty("result",(()=>e)).describe()}function Z(t,e,r,s,i){let n="object"!=typeof s&&(s??!1),o="object"==typeof s?s:i??{model:"gpt-4o"},a=u.Flux.fromGeneratorFunction((async function*(){let{model:s}=o,i=r(e);if("gpt-4o"!==s)throw new et(`Model ${s} not supported`);yield*await W(t,s,i,n)}));if(!n)return a;let l=L.toJsonTokenFlux(a);return(new j).parse(l)}var tt=class extends Error{},et=class extends Error{};export{$ as AIClient,z as BasicPrompt,H as JsonPrompt,et as ModelNotSupportedError,tt as NoAiCredientialsError,q as PromptBase,B as StreamedJsonChildElement,I as StreamedJsonRootElement,K as promptAI,Y as promptLLM,D as setupPromptGun};
2
+ //# sourceMappingURL=index.js.map
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "promptgun",
3
+ "version": "0.0.2-development",
4
+ "type": "module",
5
+ "exports": "./build/index.js",
6
+ "types": "./build/index.d.ts",
7
+ "license": "See license in LICENSE.md",
8
+ "engines": {
9
+ "node": "^23.5.0",
10
+ "npm": "^10.9.2"
11
+ },
12
+ "volta": {
13
+ "node": "23.5.0",
14
+ "npm": "10.9.2"
15
+ },
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "scripts": {
20
+ "build": "node --disable-warning=ExperimentalWarning --experimental-strip-types ./scripts/build.ts",
21
+ "build:prod": "NODE_ENV=production node --disable-warning=ExperimentalWarning --experimental-strip-types ./scripts/build.ts",
22
+ "clean": "rimraf build coverage build-integration-tests",
23
+ "type:check": "tsc --noEmit",
24
+ "lint": "biome check . --write --unsafe",
25
+ "lint:check": "biome ci .",
26
+ "test": "tsx --no-warnings --disable-warning=ExperimentalWarning ./scripts/test.ts test",
27
+ "test:watch": "node --no-warnings --disable-warning=ExperimentalWarning --experimental-strip-types ./scripts/test.ts test:watch",
28
+ "test:coverage": "node --no-warnings --disable-warning=ExperimentalWarning --experimental-strip-types ./scripts/test.ts test:coverage",
29
+ "test:integration": "npm run build:prod && tsx --test --no-warnings --disable-warning=ExperimentalWarning integration-tests/index.test.ts",
30
+ "spell:check": "cspell \"{README.md,CODE_OF_CONDUCT.md,CONTRIBUTING.md,.github/*.md,src/**/*.ts}\"",
31
+ "cz": "cz",
32
+ "semantic-release": "semantic-release"
33
+ },
34
+ "devDependencies": {
35
+ "@biomejs/biome": "^1.9.4",
36
+ "@microsoft/api-extractor": "^7.52.1",
37
+ "@ryansonshine/commitizen": "^4.2.8",
38
+ "@ryansonshine/cz-conventional-changelog": "^3.3.4",
39
+ "@semantic-release/changelog": "^6.0.3",
40
+ "@semantic-release/commit-analyzer": "^13.0.1",
41
+ "@semantic-release/github": "^11.0.1",
42
+ "@semantic-release/npm": "^12.0.1",
43
+ "@semantic-release/release-notes-generator": "^14.0.3",
44
+ "@types/node": "^22.13.11",
45
+ "@types/prompts": "^2.4.9",
46
+ "c8": "^10.1.3",
47
+ "cspell": "^8.17.5",
48
+ "dotenv": "^16.4.7",
49
+ "esbuild": "^0.24.2",
50
+ "is-main": "^0.4.0",
51
+ "rimraf": "^6.0.1",
52
+ "semantic-release": "^24.2.3",
53
+ "terser": "^5.39.0",
54
+ "tsx": "^4.19.3",
55
+ "typescript": "^5.8.2"
56
+ },
57
+ "dependencies": {
58
+ "monoflux": "^1.4.0",
59
+ "uuid": "^11.1.0"
60
+ }
61
+ }