@qorejs/qore 0.7.0 → 0.7.2
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/README.md +170 -52
- package/dist/src/core/iterable.d.ts +1 -0
- package/dist/src/core/iterable.js +17 -0
- package/dist/src/core/response-runtime.d.ts +2 -0
- package/dist/src/core/response-runtime.js +233 -0
- package/dist/src/core/response-state.d.ts +3 -0
- package/dist/src/core/response-state.js +37 -0
- package/dist/src/core/response-types.d.ts +73 -0
- package/dist/src/core/response-types.js +1 -0
- package/dist/src/core/response.d.ts +4 -0
- package/dist/src/core/response.js +26 -0
- package/dist/src/core/signal-context.d.ts +10 -0
- package/dist/src/core/signal-context.js +69 -0
- package/dist/src/core/signal-nodes.d.ts +45 -0
- package/dist/src/core/signal-nodes.js +197 -0
- package/dist/src/core/signal-scheduler.d.ts +2 -0
- package/dist/src/core/signal-scheduler.js +19 -0
- package/dist/src/core/signal-types.d.ts +19 -0
- package/dist/src/core/signal-types.js +1 -0
- package/dist/src/core/signal.d.ts +19 -0
- package/dist/src/core/signal.js +41 -0
- package/dist/src/core/stream-backpressure.d.ts +3 -0
- package/dist/src/core/stream-backpressure.js +36 -0
- package/dist/src/core/stream-buffer.d.ts +17 -0
- package/dist/src/core/stream-buffer.js +162 -0
- package/dist/src/core/stream-iterator.d.ts +6 -0
- package/dist/src/core/stream-iterator.js +14 -0
- package/dist/src/core/stream-lifecycle.d.ts +10 -0
- package/dist/src/core/stream-lifecycle.js +28 -0
- package/dist/src/core/stream-queue.d.ts +17 -0
- package/dist/src/core/stream-queue.js +62 -0
- package/dist/src/core/stream-runtime.d.ts +2 -0
- package/dist/src/core/stream-runtime.js +127 -0
- package/dist/src/core/stream-source.d.ts +2 -0
- package/dist/src/core/stream-source.js +28 -0
- package/dist/src/core/stream-state.d.ts +4 -0
- package/dist/src/core/stream-state.js +20 -0
- package/dist/src/core/stream-types.d.ts +61 -0
- package/dist/src/core/stream-types.js +1 -0
- package/dist/src/core/stream.d.ts +11 -0
- package/dist/src/core/stream.js +90 -0
- package/dist/src/dom/app.d.ts +38 -0
- package/dist/src/dom/app.js +102 -0
- package/dist/src/dom/dom.d.ts +13 -0
- package/dist/src/dom/dom.js +197 -0
- package/dist/src/dom/properties.d.ts +3 -0
- package/dist/src/dom/properties.js +147 -0
- package/dist/src/dom/reactive.d.ts +6 -0
- package/dist/src/dom/reactive.js +14 -0
- package/dist/src/dom/response-view.d.ts +4 -0
- package/dist/src/dom/response-view.js +37 -0
- package/dist/src/dom/scope.d.ts +10 -0
- package/dist/src/dom/scope.js +49 -0
- package/dist/src/dom/types.d.ts +34 -0
- package/dist/src/dom/types.js +1 -0
- package/dist/src/index.d.ts +16 -0
- package/dist/src/index.js +10 -0
- package/dist/src/providers/anthropic.d.ts +2 -0
- package/dist/src/providers/anthropic.js +102 -0
- package/dist/src/providers/openai.d.ts +2 -0
- package/dist/src/providers/openai.js +96 -0
- package/dist/src/providers/sse-adapter.d.ts +2 -0
- package/dist/src/providers/sse-adapter.js +83 -0
- package/dist/src/providers/sse-env.d.ts +4 -0
- package/dist/src/providers/sse-env.js +33 -0
- package/dist/src/providers/sse-parser.d.ts +5 -0
- package/dist/src/providers/sse-parser.js +99 -0
- package/dist/src/providers/sse.d.ts +4 -0
- package/dist/src/providers/sse.js +3 -0
- package/dist/src/providers/types.d.ts +94 -0
- package/dist/src/providers/types.js +1 -0
- package/dist/src/shared/utils.d.ts +2 -0
- package/dist/src/shared/utils.js +32 -0
- package/package.json +25 -11
- package/src/anthropic.js +0 -122
- package/src/app.js +0 -123
- package/src/dom.js +0 -527
- package/src/index.d.ts +0 -405
- package/src/index.js +0 -10
- package/src/iterable.js +0 -20
- package/src/openai.js +0 -112
- package/src/response.js +0 -312
- package/src/signal.js +0 -328
- package/src/sse.js +0 -264
- package/src/stream.js +0 -582
- package/src/utils.js +0 -39
package/src/index.d.ts
DELETED
|
@@ -1,405 +0,0 @@
|
|
|
1
|
-
export type MaybePromise<T> = T | Promise<T>;
|
|
2
|
-
export type ResponseStatus = 'idle' | 'pending' | 'streaming' | 'completed' | 'error' | 'aborted';
|
|
3
|
-
export type OverflowStrategy = 'wait' | 'drop-oldest' | 'drop-newest' | 'error';
|
|
4
|
-
|
|
5
|
-
type GlobalNode = typeof globalThis extends { Node: infer T } ? T : unknown;
|
|
6
|
-
type GlobalElement = typeof globalThis extends { Element: infer T } ? T : unknown;
|
|
7
|
-
type GlobalText = typeof globalThis extends { Text: infer T } ? T : unknown;
|
|
8
|
-
type GlobalDocumentFragment = typeof globalThis extends { DocumentFragment: infer T } ? T : unknown;
|
|
9
|
-
type GlobalAbortSignal = typeof globalThis extends { AbortSignal: infer T }
|
|
10
|
-
? T extends { prototype: infer P }
|
|
11
|
-
? P
|
|
12
|
-
: unknown
|
|
13
|
-
: { aborted: boolean; reason?: unknown };
|
|
14
|
-
|
|
15
|
-
export interface SubscribeOptions {
|
|
16
|
-
immediate?: boolean;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface ReadonlySignal<T> {
|
|
20
|
-
(): T;
|
|
21
|
-
peek(): T;
|
|
22
|
-
subscribe(listener: (value: T) => void, options?: SubscribeOptions): () => void;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface Signal<T> extends ReadonlySignal<T> {
|
|
26
|
-
(nextValue: T): T;
|
|
27
|
-
set(nextValue: T): T;
|
|
28
|
-
update(updater: (currentValue: T) => T): T;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface ComputedSignal<T> extends ReadonlySignal<T> {
|
|
32
|
-
stop(): void;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function signal<T>(initialValue: T): Signal<T>;
|
|
36
|
-
export function computed<T>(getter: () => T): ComputedSignal<T>;
|
|
37
|
-
export function effect(fn: () => void | (() => void)): () => void;
|
|
38
|
-
export function batch<T>(fn: () => T): T;
|
|
39
|
-
export function untrack<T>(fn: () => T): T;
|
|
40
|
-
export function isSignal<T = unknown>(value: unknown): value is ReadonlySignal<T>;
|
|
41
|
-
|
|
42
|
-
export interface ResponseSnapshot<TChunk = unknown, TValue = unknown> {
|
|
43
|
-
status: ResponseStatus;
|
|
44
|
-
value: TValue;
|
|
45
|
-
error: Error | null;
|
|
46
|
-
chunks: TChunk[];
|
|
47
|
-
startedAt: number | null;
|
|
48
|
-
finishedAt: number | null;
|
|
49
|
-
chunkCount: number;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export interface ResponseRunOptions<TValue> {
|
|
53
|
-
resetValue?: boolean;
|
|
54
|
-
nextSeed?: TValue;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export interface ResponseConsumeContext<TChunk, TValue> {
|
|
58
|
-
signal: GlobalAbortSignal;
|
|
59
|
-
response: ResponseState<TChunk, TValue>;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export interface ResponseExecutorContext<TChunk, TValue> {
|
|
63
|
-
readonly signal: GlobalAbortSignal;
|
|
64
|
-
response: ResponseState<TChunk, TValue>;
|
|
65
|
-
push(chunk: TChunk): TValue;
|
|
66
|
-
complete(): TValue;
|
|
67
|
-
fail(reason?: unknown): Error | TValue;
|
|
68
|
-
abort(reason?: unknown): TValue;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export type SourceLike<T> = T | Iterable<T> | AsyncIterable<T> | null | undefined;
|
|
72
|
-
export type ResponseSourceFactory<TChunk, TValue> = (
|
|
73
|
-
context: ResponseConsumeContext<TChunk, TValue>
|
|
74
|
-
) => MaybePromise<SourceLike<TChunk>>;
|
|
75
|
-
export type ResponseSource<TChunk, TValue> = SourceLike<TChunk> | ResponseSourceFactory<TChunk, TValue>;
|
|
76
|
-
|
|
77
|
-
export interface ResponseState<TChunk = unknown, TValue = unknown> {
|
|
78
|
-
status: Signal<ResponseStatus>;
|
|
79
|
-
value: Signal<TValue>;
|
|
80
|
-
error: Signal<Error | null>;
|
|
81
|
-
chunks: Signal<TChunk[]>;
|
|
82
|
-
startedAt: Signal<number | null>;
|
|
83
|
-
finishedAt: Signal<number | null>;
|
|
84
|
-
pending: ComputedSignal<boolean>;
|
|
85
|
-
streaming: ComputedSignal<boolean>;
|
|
86
|
-
completed: ComputedSignal<boolean>;
|
|
87
|
-
failed: ComputedSignal<boolean>;
|
|
88
|
-
aborted: ComputedSignal<boolean>;
|
|
89
|
-
chunkCount: ComputedSignal<number>;
|
|
90
|
-
reset(nextSeed?: TValue): TValue;
|
|
91
|
-
push(chunk: TChunk): TValue;
|
|
92
|
-
complete(): TValue;
|
|
93
|
-
fail(reason?: unknown): Error | TValue;
|
|
94
|
-
abort(reason?: unknown): TValue;
|
|
95
|
-
run(
|
|
96
|
-
executor: (context: ResponseExecutorContext<TChunk, TValue>) => MaybePromise<unknown>,
|
|
97
|
-
options?: ResponseRunOptions<TValue>
|
|
98
|
-
): Promise<TValue>;
|
|
99
|
-
consume(source: ResponseSource<TChunk, TValue>, options?: ResponseRunOptions<TValue>): Promise<TValue>;
|
|
100
|
-
snapshot(): ResponseSnapshot<TChunk, TValue>;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export interface ResponseFactory {
|
|
104
|
-
create<TChunk, TValue>(options: {
|
|
105
|
-
seed: TValue;
|
|
106
|
-
reduce: (currentValue: TValue, chunk: TChunk, index: number) => TValue;
|
|
107
|
-
}): ResponseState<TChunk, TValue>;
|
|
108
|
-
text<TChunk = string>(seed?: string): ResponseState<TChunk, string>;
|
|
109
|
-
list<TChunk>(seed?: TChunk[]): ResponseState<TChunk, TChunk[]>;
|
|
110
|
-
latest<TChunk>(seed?: TChunk | null): ResponseState<TChunk, TChunk | null>;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export function createResponse<TChunk, TValue>(options: {
|
|
114
|
-
seed: TValue;
|
|
115
|
-
reduce: (currentValue: TValue, chunk: TChunk, index: number) => TValue;
|
|
116
|
-
}): ResponseState<TChunk, TValue>;
|
|
117
|
-
export const response: ResponseFactory;
|
|
118
|
-
|
|
119
|
-
export interface BackpressureOptions {
|
|
120
|
-
interval?: number;
|
|
121
|
-
buffer?: number;
|
|
122
|
-
overflow?: OverflowStrategy;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export interface StreamOptions<TChunk = unknown, TValue = string> {
|
|
126
|
-
seed?: TValue;
|
|
127
|
-
reduce?: (currentValue: TValue, chunk: TChunk, index: number) => TValue;
|
|
128
|
-
backpressure?: number | BackpressureOptions | null;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export interface StreamController<TChunk = unknown, TValue = string> {
|
|
132
|
-
readonly signal: GlobalAbortSignal;
|
|
133
|
-
push(chunk: TChunk): Promise<TValue>;
|
|
134
|
-
done(): TValue;
|
|
135
|
-
fail(error?: unknown): Error | TValue;
|
|
136
|
-
abort(reason?: unknown): TValue;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export type StreamSetup<TChunk, TValue> = (
|
|
140
|
-
controller: StreamController<TChunk, TValue>
|
|
141
|
-
) => MaybePromise<void | SourceLike<TChunk>>;
|
|
142
|
-
export type StreamInput<TChunk, TValue> = SourceLike<TChunk> | StreamSetup<TChunk, TValue>;
|
|
143
|
-
|
|
144
|
-
export interface QoreStream<TChunk = unknown, TValue = string> extends ReadonlySignal<TValue>, AsyncIterable<TChunk> {
|
|
145
|
-
status: Signal<ResponseStatus>;
|
|
146
|
-
error: Signal<Error | null>;
|
|
147
|
-
chunks: Signal<TChunk[]>;
|
|
148
|
-
startedAt: Signal<number | null>;
|
|
149
|
-
finishedAt: Signal<number | null>;
|
|
150
|
-
pending: ComputedSignal<boolean>;
|
|
151
|
-
streaming: ComputedSignal<boolean>;
|
|
152
|
-
completed: ComputedSignal<boolean>;
|
|
153
|
-
failed: ComputedSignal<boolean>;
|
|
154
|
-
aborted: ComputedSignal<boolean>;
|
|
155
|
-
chunkCount: ComputedSignal<number>;
|
|
156
|
-
buffered: ReadonlySignal<number>;
|
|
157
|
-
dropped: ReadonlySignal<number>;
|
|
158
|
-
snapshot(): ResponseSnapshot<TChunk, TValue>;
|
|
159
|
-
ready: Promise<TValue>;
|
|
160
|
-
abort(reason?: unknown): TValue;
|
|
161
|
-
readonly signal?: GlobalAbortSignal | null;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export function createStream<TChunk, TValue = string>(
|
|
165
|
-
sourceOrSetup: StreamInput<TChunk, TValue>,
|
|
166
|
-
options?: StreamOptions<TChunk, TValue>
|
|
167
|
-
): QoreStream<TChunk, TValue>;
|
|
168
|
-
|
|
169
|
-
export function stream<TChunk = unknown>(
|
|
170
|
-
sourceOrSetup: StreamInput<TChunk, string>,
|
|
171
|
-
options?: StreamOptions<TChunk, string>
|
|
172
|
-
): QoreStream<TChunk, string>;
|
|
173
|
-
export namespace stream {
|
|
174
|
-
function create<TChunk, TValue = string>(
|
|
175
|
-
sourceOrSetup: StreamInput<TChunk, TValue>,
|
|
176
|
-
options?: StreamOptions<TChunk, TValue>
|
|
177
|
-
): QoreStream<TChunk, TValue>;
|
|
178
|
-
function text<TChunk = unknown>(
|
|
179
|
-
sourceOrSetup: StreamInput<TChunk, string>,
|
|
180
|
-
options?: StreamOptions<TChunk, string>
|
|
181
|
-
): QoreStream<TChunk, string>;
|
|
182
|
-
function list<TChunk>(
|
|
183
|
-
sourceOrSetup: StreamInput<TChunk, TChunk[]>,
|
|
184
|
-
options?: StreamOptions<TChunk, TChunk[]>
|
|
185
|
-
): QoreStream<TChunk, TChunk[]>;
|
|
186
|
-
function latest<TChunk>(
|
|
187
|
-
sourceOrSetup: StreamInput<TChunk, TChunk | null>,
|
|
188
|
-
options?: StreamOptions<TChunk, TChunk | null>
|
|
189
|
-
): QoreStream<TChunk, TChunk | null>;
|
|
190
|
-
function withBackpressure<TChunk = unknown, TValue = string>(
|
|
191
|
-
sourceOrSetup: StreamInput<TChunk, TValue>,
|
|
192
|
-
backpressure: number | BackpressureOptions,
|
|
193
|
-
options?: StreamOptions<TChunk, TValue>
|
|
194
|
-
): QoreStream<TChunk, TValue>;
|
|
195
|
-
function paced<TChunk = unknown, TValue = string>(
|
|
196
|
-
sourceOrSetup: StreamInput<TChunk, TValue>,
|
|
197
|
-
interval: number,
|
|
198
|
-
options?: StreamOptions<TChunk, TValue>
|
|
199
|
-
): QoreStream<TChunk, TValue>;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
export function from<TChunk, TValue = string>(
|
|
203
|
-
source: SourceLike<TChunk>,
|
|
204
|
-
options?: StreamOptions<TChunk, TValue> & { delay?: number }
|
|
205
|
-
): QoreStream<TChunk, TValue>;
|
|
206
|
-
export function mapStream<TInput, TOutput, TValue = string>(
|
|
207
|
-
source: SourceLike<TInput>,
|
|
208
|
-
mapper: (chunk: TInput, index: number) => MaybePromise<TOutput>,
|
|
209
|
-
options?: StreamOptions<TOutput, TValue>
|
|
210
|
-
): QoreStream<TOutput, TValue>;
|
|
211
|
-
export function scanStream<TInput, TOutput>(
|
|
212
|
-
source: SourceLike<TInput>,
|
|
213
|
-
reducer: (currentValue: TOutput, chunk: TInput, index: number) => MaybePromise<TOutput>,
|
|
214
|
-
seed: TOutput,
|
|
215
|
-
options?: Omit<StreamOptions<TOutput, TOutput>, 'seed' | 'reduce'>
|
|
216
|
-
): QoreStream<TOutput, TOutput>;
|
|
217
|
-
export function toAsyncIterable<T>(source: SourceLike<T>): AsyncIterable<T>;
|
|
218
|
-
|
|
219
|
-
export type ReactiveValue<T> = T | ReadonlySignal<T> | (() => T);
|
|
220
|
-
export type QoreChild =
|
|
221
|
-
| GlobalNode
|
|
222
|
-
| string
|
|
223
|
-
| number
|
|
224
|
-
| bigint
|
|
225
|
-
| boolean
|
|
226
|
-
| null
|
|
227
|
-
| undefined
|
|
228
|
-
| ReactiveValue<unknown>
|
|
229
|
-
| QoreChild[];
|
|
230
|
-
|
|
231
|
-
export interface ResponseRenderState<TChunk = unknown, TValue = unknown> {
|
|
232
|
-
response: ResponseState<TChunk, TValue>;
|
|
233
|
-
status: ResponseStatus;
|
|
234
|
-
value: TValue;
|
|
235
|
-
error: Error | null;
|
|
236
|
-
chunks: TChunk[];
|
|
237
|
-
startedAt: number | null;
|
|
238
|
-
finishedAt: number | null;
|
|
239
|
-
pending: boolean;
|
|
240
|
-
streaming: boolean;
|
|
241
|
-
completed: boolean;
|
|
242
|
-
failed: boolean;
|
|
243
|
-
aborted: boolean;
|
|
244
|
-
chunkCount: number;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
export function fragment(...children: QoreChild[]): GlobalDocumentFragment;
|
|
248
|
-
export function dynamic<T>(
|
|
249
|
-
source: ReactiveValue<T>,
|
|
250
|
-
render?: (value: T) => QoreChild
|
|
251
|
-
): GlobalDocumentFragment;
|
|
252
|
-
export function show<T>(
|
|
253
|
-
source: ReactiveValue<T>,
|
|
254
|
-
render?: (value: T) => QoreChild,
|
|
255
|
-
fallback?: QoreChild | ((value: T) => QoreChild)
|
|
256
|
-
): GlobalDocumentFragment;
|
|
257
|
-
export function list<T>(
|
|
258
|
-
source: ReactiveValue<Iterable<T> | ArrayLike<T> | null | undefined>,
|
|
259
|
-
render: (item: T, index: number) => QoreChild,
|
|
260
|
-
options?: { fallback?: QoreChild | ((items: T[]) => QoreChild) }
|
|
261
|
-
): GlobalDocumentFragment;
|
|
262
|
-
export function renderResponse<TChunk, TValue>(
|
|
263
|
-
responseState: ResponseState<TChunk, TValue>,
|
|
264
|
-
views?: Partial<Record<ResponseStatus | 'default', QoreChild | ((state: ResponseRenderState<TChunk, TValue>) => QoreChild)>>
|
|
265
|
-
): GlobalDocumentFragment;
|
|
266
|
-
export function h(tag: string, props?: Record<string, unknown> | null, ...children: QoreChild[]): GlobalElement;
|
|
267
|
-
export function h<TProps extends Record<string, unknown>>(
|
|
268
|
-
tag: (props: TProps & { children: QoreChild[] }) => QoreChild,
|
|
269
|
-
props?: TProps | null,
|
|
270
|
-
...children: QoreChild[]
|
|
271
|
-
): QoreChild;
|
|
272
|
-
export function text(valueOrGetter: ReactiveValue<unknown>): GlobalText;
|
|
273
|
-
export function mount(root: string | GlobalElement, view: QoreChild | (() => QoreChild)): () => GlobalElement;
|
|
274
|
-
|
|
275
|
-
export interface AppContext<Props extends Record<string, unknown> = Record<string, unknown>> {
|
|
276
|
-
app: QoreApp<Props>;
|
|
277
|
-
root: GlobalElement;
|
|
278
|
-
props: Props;
|
|
279
|
-
signal: typeof signal;
|
|
280
|
-
computed: typeof computed;
|
|
281
|
-
effect: typeof effect;
|
|
282
|
-
batch: typeof batch;
|
|
283
|
-
untrack: typeof untrack;
|
|
284
|
-
stream: typeof stream;
|
|
285
|
-
from: typeof from;
|
|
286
|
-
mapStream: typeof mapStream;
|
|
287
|
-
scanStream: typeof scanStream;
|
|
288
|
-
response: typeof response;
|
|
289
|
-
h: typeof h;
|
|
290
|
-
text: typeof text;
|
|
291
|
-
dynamic: typeof dynamic;
|
|
292
|
-
show: typeof show;
|
|
293
|
-
list: typeof list;
|
|
294
|
-
fragment: typeof fragment;
|
|
295
|
-
renderResponse: typeof renderResponse;
|
|
296
|
-
onCleanup(handler: () => void): () => void;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
export type AppSetupResult =
|
|
300
|
-
| QoreChild
|
|
301
|
-
| {
|
|
302
|
-
view?: QoreChild | (() => QoreChild);
|
|
303
|
-
onMount?: (root: GlobalElement) => void;
|
|
304
|
-
};
|
|
305
|
-
|
|
306
|
-
export interface QoreApp<Props extends Record<string, unknown> = Record<string, unknown>> {
|
|
307
|
-
mount(target: string | GlobalElement, props?: Props): GlobalElement;
|
|
308
|
-
unmount(): QoreApp<Props>;
|
|
309
|
-
readonly root: GlobalElement | null;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
export function createApp<Props extends Record<string, unknown> = Record<string, unknown>>(
|
|
313
|
-
setup: (context: AppContext<Props>) => AppSetupResult
|
|
314
|
-
): QoreApp<Props>;
|
|
315
|
-
|
|
316
|
-
export interface ProviderRequestOptions {
|
|
317
|
-
signal?: GlobalAbortSignal;
|
|
318
|
-
headers?: Record<string, string>;
|
|
319
|
-
[key: string]: unknown;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
export interface SSEEvent<TData = unknown> {
|
|
323
|
-
event: string;
|
|
324
|
-
id: string | null;
|
|
325
|
-
retry: number | null;
|
|
326
|
-
data: TData;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
export interface SSEAdapterOptions<TRequest = Record<string, unknown>, TChatInput = unknown, TData = unknown> {
|
|
330
|
-
name?: string;
|
|
331
|
-
url?: string;
|
|
332
|
-
method?: string;
|
|
333
|
-
headers?: Record<string, string>;
|
|
334
|
-
fetch?: (...args: any[]) => Promise<any>;
|
|
335
|
-
buildRequest?: (
|
|
336
|
-
request: TRequest,
|
|
337
|
-
requestOptions?: ProviderRequestOptions
|
|
338
|
-
) => MaybePromise<TRequest | string | { url?: string; method?: string; headers?: Record<string, string>; signal?: GlobalAbortSignal; body?: unknown; [key: string]: unknown }>;
|
|
339
|
-
buildChatRequest?: (input: TChatInput, requestOptions?: ProviderRequestOptions) => TRequest;
|
|
340
|
-
parse?: (data: string, event: SSEEvent<string>) => MaybePromise<TData>;
|
|
341
|
-
isError?: (event: SSEEvent<TData>) => MaybePromise<boolean>;
|
|
342
|
-
getError?: (event: SSEEvent<TData>, name: string) => MaybePromise<string>;
|
|
343
|
-
eventToText?: (event: SSEEvent<TData>, request: TRequest, requestOptions?: ProviderRequestOptions) => MaybePromise<string | undefined>;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
export interface SSEAdapter<TRequest = Record<string, unknown>, TChatInput = unknown, TData = unknown> {
|
|
347
|
-
stream(request?: TRequest, requestOptions?: ProviderRequestOptions): AsyncIterable<SSEEvent<TData>>;
|
|
348
|
-
streamText(request?: TRequest, requestOptions?: ProviderRequestOptions): AsyncIterable<string>;
|
|
349
|
-
chat(input: TChatInput, requestOptions?: ProviderRequestOptions): AsyncIterable<string>;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
export function createSSEAdapter<TRequest = Record<string, unknown>, TChatInput = unknown, TData = unknown>(
|
|
353
|
-
options?: SSEAdapterOptions<TRequest, TChatInput, TData>
|
|
354
|
-
): SSEAdapter<TRequest, TChatInput, TData>;
|
|
355
|
-
|
|
356
|
-
export interface OpenAIEvent {
|
|
357
|
-
type: string;
|
|
358
|
-
[key: string]: unknown;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
export interface OpenAIOptions {
|
|
362
|
-
apiKey?: string;
|
|
363
|
-
baseURL?: string;
|
|
364
|
-
model?: string;
|
|
365
|
-
headers?: Record<string, string>;
|
|
366
|
-
fetch?: (...args: any[]) => Promise<any>;
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
export interface OpenAIAdapter {
|
|
370
|
-
responses: {
|
|
371
|
-
stream(request: Record<string, unknown>, requestOptions?: ProviderRequestOptions): AsyncIterable<OpenAIEvent>;
|
|
372
|
-
};
|
|
373
|
-
streamText(input: string | Record<string, unknown>, requestOptions?: ProviderRequestOptions): AsyncIterable<string>;
|
|
374
|
-
chat(input: string | Record<string, unknown> | Array<Record<string, unknown>>, requestOptions?: ProviderRequestOptions): AsyncIterable<string>;
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
export function createOpenAI(options?: OpenAIOptions): OpenAIAdapter;
|
|
378
|
-
|
|
379
|
-
export interface AnthropicEvent {
|
|
380
|
-
type: string;
|
|
381
|
-
[key: string]: unknown;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
export interface AnthropicOptions {
|
|
385
|
-
apiKey?: string;
|
|
386
|
-
baseURL?: string;
|
|
387
|
-
model?: string;
|
|
388
|
-
version?: string;
|
|
389
|
-
maxTokens?: number;
|
|
390
|
-
headers?: Record<string, string>;
|
|
391
|
-
fetch?: (...args: any[]) => Promise<any>;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
export interface AnthropicAdapter {
|
|
395
|
-
messages: {
|
|
396
|
-
stream(request: Record<string, unknown>, requestOptions?: ProviderRequestOptions): AsyncIterable<AnthropicEvent>;
|
|
397
|
-
};
|
|
398
|
-
streamText(messages: string | Record<string, unknown>, requestOptions?: ProviderRequestOptions): AsyncIterable<string>;
|
|
399
|
-
chat(input: string | Record<string, unknown> | Array<Record<string, unknown>>, requestOptions?: ProviderRequestOptions): AsyncIterable<string>;
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
export function createAnthropic(options?: AnthropicOptions): AnthropicAdapter;
|
|
403
|
-
|
|
404
|
-
export function normalizeError(error: unknown): Error;
|
|
405
|
-
export function sleep(ms: number, signal?: GlobalAbortSignal): Promise<void>;
|
package/src/index.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
// Re-export the public runtime surface from a single module entrypoint.
|
|
2
|
-
export { signal, computed, effect, batch, untrack, isSignal } from './signal.js';
|
|
3
|
-
export { stream, createStream, from, mapStream, scanStream, toAsyncIterable } from './stream.js';
|
|
4
|
-
export { createResponse, response } from './response.js';
|
|
5
|
-
export { createApp } from './app.js';
|
|
6
|
-
export { dynamic, fragment, h, list, mount, renderResponse, show, text } from './dom.js';
|
|
7
|
-
export { createAnthropic } from './anthropic.js';
|
|
8
|
-
export { createOpenAI } from './openai.js';
|
|
9
|
-
export { createSSEAdapter } from './sse.js';
|
|
10
|
-
export { normalizeError, sleep } from './utils.js';
|
package/src/iterable.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// Normalize values, iterables, and async iterables into one async iterable shape.
|
|
2
|
-
export function toAsyncIterable(source) {
|
|
3
|
-
if (source == null) {
|
|
4
|
-
return (async function* empty() {})();
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
if (typeof source[Symbol.asyncIterator] === 'function') {
|
|
8
|
-
return source;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
if (typeof source[Symbol.iterator] === 'function') {
|
|
12
|
-
return (async function* fromIterable() {
|
|
13
|
-
yield* source;
|
|
14
|
-
})();
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return (async function* fromValue() {
|
|
18
|
-
yield source;
|
|
19
|
-
})();
|
|
20
|
-
}
|
package/src/openai.js
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { createSSEAdapter, readEnv } from './sse.js';
|
|
2
|
-
|
|
3
|
-
const DEFAULT_BASE_URL = 'https://api.openai.com/v1';
|
|
4
|
-
const DEFAULT_MODEL = 'gpt-5';
|
|
5
|
-
|
|
6
|
-
// Treat plain chat text as one user message so callers can start from a single string.
|
|
7
|
-
function normalizeChatInput(input) {
|
|
8
|
-
if (typeof input === 'string') {
|
|
9
|
-
return [{ role: 'user', content: input }];
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if (Array.isArray(input)) {
|
|
13
|
-
return input;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (input && typeof input === 'object' && 'role' in input) {
|
|
17
|
-
return [input];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return input;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Keep provider setup explicit because real API keys should stay off the client.
|
|
24
|
-
export function createOpenAI(options = {}) {
|
|
25
|
-
const {
|
|
26
|
-
apiKey,
|
|
27
|
-
baseURL = DEFAULT_BASE_URL,
|
|
28
|
-
model = DEFAULT_MODEL,
|
|
29
|
-
headers: defaultHeaders = {},
|
|
30
|
-
fetch: fetchImpl = globalThis.fetch
|
|
31
|
-
} = options;
|
|
32
|
-
const resolvedApiKey = apiKey ?? readEnv('OPENAI_API_KEY');
|
|
33
|
-
|
|
34
|
-
if (!resolvedApiKey) {
|
|
35
|
-
throw new Error('Qore OpenAI adapter requires an API key. Pass apiKey or set OPENAI_API_KEY.');
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const transport = createSSEAdapter({
|
|
39
|
-
name: 'OpenAI',
|
|
40
|
-
url: `${baseURL}/responses`,
|
|
41
|
-
headers: {
|
|
42
|
-
Authorization: `Bearer ${resolvedApiKey}`,
|
|
43
|
-
'Content-Type': 'application/json',
|
|
44
|
-
...defaultHeaders
|
|
45
|
-
},
|
|
46
|
-
fetch: fetchImpl,
|
|
47
|
-
buildRequest(request, requestOptions = {}) {
|
|
48
|
-
const { signal, headers = {}, ...overrides } = requestOptions;
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
method: 'POST',
|
|
52
|
-
signal,
|
|
53
|
-
headers,
|
|
54
|
-
body: JSON.stringify({
|
|
55
|
-
model,
|
|
56
|
-
stream: true,
|
|
57
|
-
...request,
|
|
58
|
-
...overrides
|
|
59
|
-
})
|
|
60
|
-
};
|
|
61
|
-
},
|
|
62
|
-
parse: JSON.parse,
|
|
63
|
-
isError: (event) => event.data?.type === 'error',
|
|
64
|
-
getError: (event) => event.data?.error?.message ?? 'OpenAI streaming error',
|
|
65
|
-
eventToText: (event) => event.data?.type === 'response.output_text.delta' && typeof event.data.delta === 'string'
|
|
66
|
-
? event.data.delta
|
|
67
|
-
: undefined
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
async function* streamEvents(request, requestOptions = {}) {
|
|
71
|
-
for await (const event of transport.stream(request, requestOptions)) {
|
|
72
|
-
yield event.data;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
async function* streamText(input, requestOptions = {}) {
|
|
77
|
-
const request = input && typeof input === 'object' && 'input' in input
|
|
78
|
-
? input
|
|
79
|
-
: { input };
|
|
80
|
-
|
|
81
|
-
for await (const chunk of transport.streamText(request, requestOptions)) {
|
|
82
|
-
yield chunk;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return {
|
|
87
|
-
// Stream typed semantic events from the Responses API.
|
|
88
|
-
responses: {
|
|
89
|
-
stream: streamEvents
|
|
90
|
-
},
|
|
91
|
-
|
|
92
|
-
// Stream only text deltas for the common chat-response case.
|
|
93
|
-
streamText(input, requestOptions = {}) {
|
|
94
|
-
return streamText(input, requestOptions);
|
|
95
|
-
},
|
|
96
|
-
|
|
97
|
-
// Match the Qore narrative directly: stream(openai.chat(prompt)).
|
|
98
|
-
chat(input, requestOptions = {}) {
|
|
99
|
-
const {
|
|
100
|
-
signal,
|
|
101
|
-
headers,
|
|
102
|
-
...request
|
|
103
|
-
} = requestOptions;
|
|
104
|
-
|
|
105
|
-
if (!('input' in request)) {
|
|
106
|
-
request.input = normalizeChatInput(input);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return streamText(request, { signal, headers });
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
}
|