@gammatech/aijsx 0.4.0-beta.8 → 0.5.0-beta.1
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/dist/{createElement-VpIrgHrz.d.mts → createElement--C_Hwi_c.d.mts} +103 -190
- package/dist/{createElement-VpIrgHrz.d.ts → createElement--C_Hwi_c.d.ts} +103 -190
- package/dist/index.d.mts +391 -9
- package/dist/index.d.ts +391 -9
- package/dist/index.js +912 -361
- package/dist/index.mjs +911 -360
- package/dist/jsx-dev-runtime.d.mts +1 -1
- package/dist/jsx-dev-runtime.d.ts +1 -1
- package/dist/jsx-runtime.d.mts +1 -1
- package/dist/jsx-runtime.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,35 +1,83 @@
|
|
|
1
1
|
import { ZodTypeAny, ZodObject, ZodRawShape } from 'zod';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
interface RenderableStream extends AsyncGenerator<string, void, unknown> {
|
|
5
|
-
[Symbol.asyncIterator]: () => AsyncGenerator<string, void, unknown>;
|
|
3
|
+
interface ChatCompletionRequestPayloads {
|
|
6
4
|
}
|
|
7
|
-
interface
|
|
8
|
-
|
|
5
|
+
interface LogChatCompletionRequest<R extends Record<string, any> = ChatCompletionRequestPayloads[keyof ChatCompletionRequestPayloads]> {
|
|
6
|
+
requestId: string;
|
|
7
|
+
startTime: string;
|
|
8
|
+
model: string;
|
|
9
|
+
providerRegion?: string;
|
|
10
|
+
provider?: string;
|
|
11
|
+
inputMessages: RenderedConversationMessage[];
|
|
12
|
+
request: R;
|
|
9
13
|
}
|
|
10
|
-
interface
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
interface LogChatCompletionResponse<R extends Record<string, any> = ChatCompletionRequestPayloads[keyof ChatCompletionRequestPayloads]> extends LogChatCompletionRequest<R> {
|
|
15
|
+
endTime: string;
|
|
16
|
+
latency: number;
|
|
17
|
+
outputMessage: RenderedConversationMessage;
|
|
18
|
+
finishReason: string;
|
|
19
|
+
tokensUsed: {
|
|
20
|
+
prompt: number;
|
|
21
|
+
completion: number;
|
|
22
|
+
total: number;
|
|
23
|
+
};
|
|
17
24
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
[
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* This can be extended using declare module to add additional providers.
|
|
28
|
+
*/
|
|
29
|
+
type LogLevel = 'error' | 'warn' | 'info' | 'debug';
|
|
30
|
+
type Loggable = string | number | boolean | undefined | null | object;
|
|
31
|
+
type Logger = {
|
|
32
|
+
error: (...msg: Loggable[]) => void;
|
|
33
|
+
warn: (...msg: Loggable[]) => void;
|
|
34
|
+
info: (...msg: Loggable[]) => void;
|
|
35
|
+
debug: (...msg: Loggable[]) => void;
|
|
36
|
+
logException(exception: string | Error): void;
|
|
37
|
+
chatCompletionRequest<K extends keyof ChatCompletionRequestPayloads>(provider: K, payload: LogChatCompletionRequest<ChatCompletionRequestPayloads[K]>): void;
|
|
38
|
+
chatCompletionResponse<K extends keyof ChatCompletionRequestPayloads>(provider: K, payload: LogChatCompletionResponse<ChatCompletionRequestPayloads[K]>): void;
|
|
39
|
+
};
|
|
40
|
+
declare abstract class LogImplementation {
|
|
41
|
+
private readonly loggedExceptions;
|
|
42
|
+
/**
|
|
43
|
+
* @param ctx The current RenderContext
|
|
44
|
+
* @param level The log level, e.g. 'error', 'warn', 'info', 'debug'
|
|
45
|
+
* @param message
|
|
46
|
+
*/
|
|
47
|
+
abstract log(level: LogLevel, message: string): void;
|
|
48
|
+
chatCompletionRequest<K extends keyof ChatCompletionRequestPayloads>(provider: K, payload: LogChatCompletionRequest<ChatCompletionRequestPayloads[K]>): void;
|
|
49
|
+
chatCompletionResponse<K extends keyof ChatCompletionRequestPayloads>(provider: K, payload: LogChatCompletionResponse<ChatCompletionRequestPayloads[K]>): void;
|
|
50
|
+
/**
|
|
51
|
+
* Logs exceptions thrown during an element's render.
|
|
52
|
+
*/
|
|
53
|
+
logException(exception: unknown): void;
|
|
54
|
+
}
|
|
55
|
+
declare class BoundLogger implements Logger {
|
|
56
|
+
private readonly impl;
|
|
57
|
+
constructor(impl: LogImplementation);
|
|
58
|
+
private formatMessage;
|
|
59
|
+
error: (...msgs: Loggable[]) => void;
|
|
60
|
+
warn: (...msgs: Loggable[]) => void;
|
|
61
|
+
info: (...msgs: Loggable[]) => void;
|
|
62
|
+
debug: (...msgs: Loggable[]) => void;
|
|
63
|
+
logException: (exception: string | Error) => void;
|
|
64
|
+
chatCompletionRequest: <K extends keyof ChatCompletionRequestPayloads>(provider: K, payload: LogChatCompletionRequest<ChatCompletionRequestPayloads[K]>) => void;
|
|
65
|
+
chatCompletionResponse: <K extends keyof ChatCompletionRequestPayloads>(provider: K, payload: LogChatCompletionResponse<ChatCompletionRequestPayloads[K]>) => void;
|
|
66
|
+
}
|
|
67
|
+
declare class NoopLogImplementation extends LogImplementation {
|
|
68
|
+
log(level: LogLevel, message: string): void;
|
|
69
|
+
}
|
|
70
|
+
declare class ConsoleLogger extends LogImplementation {
|
|
71
|
+
log(level: LogLevel, message: string): void;
|
|
72
|
+
}
|
|
73
|
+
declare class CombinedLogger extends LogImplementation {
|
|
74
|
+
private readonly loggers;
|
|
75
|
+
constructor(loggers: LogImplementation[]);
|
|
76
|
+
log(...args: Parameters<LogImplementation['log']>): void;
|
|
77
|
+
logException(...args: Parameters<LogImplementation['logException']>): void;
|
|
78
|
+
chatCompletionRequest<_K extends keyof ChatCompletionRequestPayloads>(...args: Parameters<LogImplementation['chatCompletionRequest']>): void;
|
|
79
|
+
chatCompletionResponse<_K extends keyof ChatCompletionRequestPayloads>(...args: Parameters<LogImplementation['chatCompletionResponse']>): void;
|
|
29
80
|
}
|
|
30
|
-
type AINode = Literal | AIElement<any> | AINode[];
|
|
31
|
-
type Renderable = AINode | PromiseLike<Renderable> | RenderableStream;
|
|
32
|
-
type PropsOfAIComponent<T extends AIComponent<any>> = T extends AIComponent<infer P> ? P : never;
|
|
33
81
|
|
|
34
82
|
type EvaluatorPrimitive = string | number | boolean;
|
|
35
83
|
type EvaluatorResult = {
|
|
@@ -80,7 +128,6 @@ interface StreamChain<V extends Record<string, any> = Record<string, any>, R ext
|
|
|
80
128
|
type IsAsyncGenerator<T> = T extends AsyncGenerator<any, any, any> ? true : false;
|
|
81
129
|
type NotAsyncGenerator<T> = IsAsyncGenerator<T> extends true ? never : T;
|
|
82
130
|
|
|
83
|
-
declare const LoggerContext: Context<LogImplementation>;
|
|
84
131
|
type ContextValues = Record<symbol, any>;
|
|
85
132
|
type RenderOptions = {
|
|
86
133
|
preserveTags?: boolean;
|
|
@@ -90,16 +137,7 @@ type RenderOptions = {
|
|
|
90
137
|
};
|
|
91
138
|
};
|
|
92
139
|
};
|
|
93
|
-
type RenderTraceInfo = {
|
|
94
|
-
traceId: string;
|
|
95
|
-
spanId: string;
|
|
96
|
-
parentSpanId: string | null;
|
|
97
|
-
renderType: 'element' | 'chain' | 'prompt' | 'root';
|
|
98
|
-
key: string;
|
|
99
|
-
parent: RenderTraceInfo | null;
|
|
100
|
-
};
|
|
101
140
|
interface RenderContext {
|
|
102
|
-
traceInfo: RenderTraceInfo;
|
|
103
141
|
logger: Logger;
|
|
104
142
|
getContext<T>(context: Context<T>): T;
|
|
105
143
|
render(renderable: Renderable, opts?: RenderOptions): RenderResult;
|
|
@@ -115,161 +153,36 @@ type RenderPromptOptions = {
|
|
|
115
153
|
};
|
|
116
154
|
declare function createContext<T>(defaultValue: T): Context<T>;
|
|
117
155
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
variables: Record<string, any>;
|
|
122
|
-
chainType: 'function' | 'stream';
|
|
123
|
-
}
|
|
124
|
-
interface LogChainComplete {
|
|
125
|
-
startTime: string;
|
|
126
|
-
endTime: string;
|
|
127
|
-
latency: number;
|
|
128
|
-
chainKey: string;
|
|
129
|
-
variables: Record<string, any>;
|
|
130
|
-
chainType: 'function' | 'stream';
|
|
131
|
-
output: any;
|
|
132
|
-
}
|
|
133
|
-
interface LogChainError {
|
|
134
|
-
startTime: string;
|
|
135
|
-
endTime: string;
|
|
136
|
-
latency: number;
|
|
137
|
-
chainKey: string;
|
|
138
|
-
variables: Record<string, any>;
|
|
139
|
-
chainType: 'function' | 'stream';
|
|
140
|
-
error: Error;
|
|
141
|
-
}
|
|
142
|
-
interface LogPromptStart {
|
|
143
|
-
startTime: string;
|
|
144
|
-
promptKey: string;
|
|
145
|
-
variables: Record<string, any>;
|
|
146
|
-
}
|
|
147
|
-
interface LogPromptComplete {
|
|
148
|
-
startTime: string;
|
|
149
|
-
endTime: string;
|
|
150
|
-
latency: number;
|
|
151
|
-
promptKey: string;
|
|
152
|
-
variables: Record<string, any>;
|
|
153
|
-
output: any;
|
|
154
|
-
}
|
|
155
|
-
interface LogPromptError {
|
|
156
|
-
startTime: string;
|
|
157
|
-
endTime: string;
|
|
158
|
-
latency: number;
|
|
159
|
-
promptKey: string;
|
|
160
|
-
variables: Record<string, any>;
|
|
161
|
-
error: Error;
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* This can be extended using declare module to add additional providers.
|
|
165
|
-
*/
|
|
166
|
-
interface ChatCompletionRequestPayloads {
|
|
167
|
-
}
|
|
168
|
-
interface LogChatCompletionRequest<R extends Record<string, any> = ChatCompletionRequestPayloads[keyof ChatCompletionRequestPayloads]> {
|
|
169
|
-
requestId: string;
|
|
170
|
-
startTime: string;
|
|
171
|
-
model: string;
|
|
172
|
-
providerRegion?: string;
|
|
173
|
-
provider?: string;
|
|
174
|
-
inputMessages: RenderedConversationMessage[];
|
|
175
|
-
request: R;
|
|
176
|
-
}
|
|
177
|
-
interface LogChatCompletionResponse<R extends Record<string, any> = ChatCompletionRequestPayloads[keyof ChatCompletionRequestPayloads]> extends LogChatCompletionRequest<R> {
|
|
178
|
-
requestId: string;
|
|
179
|
-
startTime: string;
|
|
180
|
-
endTime: string;
|
|
181
|
-
latency: number;
|
|
182
|
-
outputMessage: RenderedConversationMessage;
|
|
183
|
-
finishReason: string;
|
|
184
|
-
tokensUsed: {
|
|
185
|
-
prompt: number;
|
|
186
|
-
completion: number;
|
|
187
|
-
total: number;
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
type LogLevel = 'error' | 'warn' | 'info' | 'debug';
|
|
191
|
-
type Loggable = string | number | boolean | undefined | null | object;
|
|
192
|
-
type LogContext = {
|
|
193
|
-
renderType: 'element' | 'chain' | 'prompt';
|
|
194
|
-
key: string;
|
|
195
|
-
spanId: string;
|
|
196
|
-
traceId: string;
|
|
197
|
-
parentSpanId: string;
|
|
198
|
-
};
|
|
199
|
-
type Logger = {
|
|
200
|
-
error: (...msg: Loggable[]) => void;
|
|
201
|
-
warn: (...msg: Loggable[]) => void;
|
|
202
|
-
info: (...msg: Loggable[]) => void;
|
|
203
|
-
debug: (...msg: Loggable[]) => void;
|
|
204
|
-
logException: (exception: unknown) => void;
|
|
205
|
-
chainStart(chain: FunctionChain | StreamChain, payload: LogChainStart): void;
|
|
206
|
-
chainComplete(chain: FunctionChain | StreamChain, payload: LogChainComplete): void;
|
|
207
|
-
chainError(chain: FunctionChain | StreamChain, payload: LogChainError): void;
|
|
208
|
-
promptStart(prompt: Prompt, payload: LogPromptStart): void;
|
|
209
|
-
promptComplete(prompt: Prompt, payload: LogPromptComplete): void;
|
|
210
|
-
promptError(prompt: Prompt, payload: LogPromptError): void;
|
|
211
|
-
chatCompletionRequest: <K extends keyof ChatCompletionRequestPayloads>(provider: K, payload: LogChatCompletionRequest<ChatCompletionRequestPayloads[K]>) => void;
|
|
212
|
-
chatCompletionResponse: <K extends keyof ChatCompletionRequestPayloads>(provider: K, payload: LogChatCompletionResponse<ChatCompletionRequestPayloads[K]>) => void;
|
|
213
|
-
};
|
|
214
|
-
declare abstract class LogImplementation {
|
|
215
|
-
protected readonly loggedExceptions: WeakMap<object, boolean>;
|
|
216
|
-
/**
|
|
217
|
-
* @param ctx The current RenderContext
|
|
218
|
-
* @param level The log level, e.g. 'error', 'warn', 'info', 'debug'
|
|
219
|
-
* @param message
|
|
220
|
-
*/
|
|
221
|
-
abstract log(ctx: RenderTraceInfo, level: LogLevel, message: string): void;
|
|
222
|
-
/**
|
|
223
|
-
* Logs exceptions thrown during an element's render.
|
|
224
|
-
*/
|
|
225
|
-
logException(ctx: RenderTraceInfo, exception: unknown): void;
|
|
226
|
-
chainStart(_ctx: RenderTraceInfo, _chain: FunctionChain | StreamChain, _payload: LogChainStart): void;
|
|
227
|
-
chainComplete(_ctx: RenderTraceInfo, _chain: FunctionChain | StreamChain, _payload: LogChainComplete): void;
|
|
228
|
-
chainError(_ctx: RenderTraceInfo, _chain: FunctionChain | StreamChain, _payload: LogChainError): void;
|
|
229
|
-
promptStart(_ctx: RenderTraceInfo, _prompt: Prompt, _payload: LogPromptStart): void;
|
|
230
|
-
promptComplete(_ctx: RenderTraceInfo, _prompt: Prompt, _payload: LogPromptComplete): void;
|
|
231
|
-
promptError(_ctx: RenderTraceInfo, _prompt: Prompt, _payload: LogPromptError): void;
|
|
232
|
-
chatCompletionRequest<K extends keyof ChatCompletionRequestPayloads>(_ctx: RenderTraceInfo, _provider: K, _payload: LogChatCompletionRequest<ChatCompletionRequestPayloads[K]>): void;
|
|
233
|
-
chatCompletionResponse<K extends keyof ChatCompletionRequestPayloads>(_ctx: RenderTraceInfo, _provider: K, _payload: LogChatCompletionResponse<ChatCompletionRequestPayloads[K]>): void;
|
|
234
|
-
}
|
|
235
|
-
declare class BoundLogger implements Logger {
|
|
236
|
-
private readonly impl;
|
|
237
|
-
private readonly ctx;
|
|
238
|
-
constructor(impl: LogImplementation, ctx: RenderTraceInfo);
|
|
239
|
-
chainStart(chain: FunctionChain | StreamChain, payload: LogChainStart): void;
|
|
240
|
-
chainComplete(chain: FunctionChain | StreamChain, payload: LogChainComplete): void;
|
|
241
|
-
chainError(chain: FunctionChain | StreamChain, payload: LogChainError): void;
|
|
242
|
-
promptStart(prompt: Prompt, payload: LogPromptStart): void;
|
|
243
|
-
promptComplete(prompt: Prompt, payload: LogPromptComplete): void;
|
|
244
|
-
promptError(prompt: Prompt, payload: LogPromptError): void;
|
|
245
|
-
private formatMessage;
|
|
246
|
-
error: (...msgs: Loggable[]) => void;
|
|
247
|
-
warn: (...msgs: Loggable[]) => void;
|
|
248
|
-
info: (...msgs: Loggable[]) => void;
|
|
249
|
-
debug: (...msgs: Loggable[]) => void;
|
|
250
|
-
logException: (exception: unknown) => void;
|
|
251
|
-
chatCompletionRequest: <K extends keyof ChatCompletionRequestPayloads>(provider: K, payload: LogChatCompletionRequest<ChatCompletionRequestPayloads[K]>) => void;
|
|
252
|
-
chatCompletionResponse: <K extends keyof ChatCompletionRequestPayloads>(provider: K, payload: LogChatCompletionResponse<ChatCompletionRequestPayloads[K]>) => void;
|
|
156
|
+
type Literal = string | number | null | undefined | boolean;
|
|
157
|
+
interface RenderableStream extends AsyncGenerator<string, void, unknown> {
|
|
158
|
+
[Symbol.asyncIterator]: () => AsyncGenerator<string, void, unknown>;
|
|
253
159
|
}
|
|
254
|
-
|
|
255
|
-
|
|
160
|
+
interface RenderResult extends RenderableStream {
|
|
161
|
+
then: (onResolved: (value: string) => void, onRejected?: (reason?: any) => void) => void;
|
|
256
162
|
}
|
|
257
|
-
|
|
258
|
-
|
|
163
|
+
interface Context<T> {
|
|
164
|
+
Provider: AIComponent<{
|
|
165
|
+
children: AINode;
|
|
166
|
+
value: T;
|
|
167
|
+
}>;
|
|
168
|
+
defaultValue: T;
|
|
169
|
+
key: symbol;
|
|
259
170
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
chatCompletionResponse<_K extends keyof ChatCompletionRequestPayloads>(...args: Parameters<LogImplementation['chatCompletionResponse']>): void;
|
|
171
|
+
type AIComponent<P> = (props: P, context: RenderContext) => Renderable;
|
|
172
|
+
declare const attachedContextSymbol: unique symbol;
|
|
173
|
+
interface AIElement<P> {
|
|
174
|
+
/** The tag associated with this {@link AIElement}. */
|
|
175
|
+
tag: AIComponent<P>;
|
|
176
|
+
/** The component properties. */
|
|
177
|
+
props: P;
|
|
178
|
+
/** A function that renders this {@link AIElement} to a {@link Renderable}. */
|
|
179
|
+
render: (ctx: RenderContext) => Renderable;
|
|
180
|
+
/** The {@link RenderContext} associated with this {@link Element}. */
|
|
181
|
+
[attachedContextSymbol]?: Record<symbol, any>;
|
|
272
182
|
}
|
|
183
|
+
type AINode = Literal | AIElement<any> | AINode[];
|
|
184
|
+
type Renderable = AINode | PromiseLike<Renderable> | RenderableStream;
|
|
185
|
+
type PropsOfAIComponent<T extends AIComponent<any>> = T extends AIComponent<infer P> ? P : never;
|
|
273
186
|
|
|
274
187
|
type ChatCompletionRole = 'user' | 'system' | 'assistant';
|
|
275
188
|
declare const SystemMessage: (props: {
|
|
@@ -292,8 +205,8 @@ declare const computeUsage: (messages: RenderedConversationMessage[]) => {
|
|
|
292
205
|
total: number;
|
|
293
206
|
};
|
|
294
207
|
declare class ChatCompletionError extends Error {
|
|
295
|
-
readonly chatCompletionRequest:
|
|
296
|
-
constructor(message: string, chatCompletionRequest:
|
|
208
|
+
readonly chatCompletionRequest: Record<string, any>;
|
|
209
|
+
constructor(message: string, chatCompletionRequest: Record<string, any>);
|
|
297
210
|
}
|
|
298
211
|
|
|
299
212
|
declare function createAIElement<P extends {
|
|
@@ -306,4 +219,4 @@ declare function AIFragment({ children }: {
|
|
|
306
219
|
children: AINode;
|
|
307
220
|
}): Renderable;
|
|
308
221
|
|
|
309
|
-
export { type AIComponent as A,
|
|
222
|
+
export { type AIComponent as A, BoundLogger as B, type ContextValues as C, type Renderable as D, type EvaluatorFn as E, type FunctionChain as F, type PropsOfAIComponent as G, type PromptRenderResult as H, LogImplementation as L, type NotAsyncGenerator as N, type OutputParser as O, type PromptParsed as P, type RenderContext as R, type StreamChain as S, UserMessage as U, type Prompt as a, type EvaluatorResult as b, type Context as c, type AINode as d, createAIElement as e, AIFragment as f, createContext as g, type ChatCompletionRole as h, SystemMessage as i, AssistantMessage as j, type RenderedConversationMessage as k, computeUsage as l, ChatCompletionError as m, type LogLevel as n, type Logger as o, NoopLogImplementation as p, ConsoleLogger as q, CombinedLogger as r, type ChatCompletionRequestPayloads as s, type LogChatCompletionRequest as t, type LogChatCompletionResponse as u, type Literal as v, type RenderableStream as w, type RenderResult as x, attachedContextSymbol as y, type AIElement as z };
|