@gammatech/aijsx 0.3.0-beta.2 → 0.3.0-beta.4
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/{chunk-2JPDWMO2.mjs → chunk-QIA7MVVR.mjs} +16 -8
- package/dist/{createElement-_dLhPtA-.d.mts → createElement-Mo9PV8GD.d.mts} +56 -25
- package/dist/{createElement-_dLhPtA-.d.ts → createElement-Mo9PV8GD.d.ts} +56 -25
- package/dist/index.d.mts +40 -10
- package/dist/index.d.ts +40 -10
- package/dist/index.js +279 -176
- package/dist/index.mjs +268 -171
- package/dist/jsx-dev-runtime.d.mts +2 -1
- package/dist/jsx-dev-runtime.d.ts +2 -1
- package/dist/jsx-dev-runtime.js +2 -5
- package/dist/jsx-dev-runtime.mjs +1 -2
- package/dist/jsx-runtime.d.mts +6 -8
- package/dist/jsx-runtime.d.ts +6 -8
- package/dist/jsx-runtime.js +2 -5
- package/dist/jsx-runtime.mjs +1 -2
- package/package.json +4 -3
- package/dist/chunk-LWRCGF5O.mjs +0 -22
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// src/createElement.ts
|
|
2
|
-
|
|
3
|
-
function createAIElement(tag, props, children) {
|
|
2
|
+
function createAIElement(tag, props, ...children) {
|
|
4
3
|
const propsToPass = {
|
|
5
4
|
...props ?? {},
|
|
6
5
|
...children.length === 0 ? {} : { children: children.length === 1 ? children[0] : children }
|
|
@@ -8,16 +7,12 @@ function createAIElement(tag, props, children) {
|
|
|
8
7
|
const result = {
|
|
9
8
|
tag,
|
|
10
9
|
props: propsToPass,
|
|
11
|
-
parse: "parse" in tag ? tag.parse : parseAsString,
|
|
12
10
|
render: (ctx) => {
|
|
13
11
|
return tag(propsToPass, ctx);
|
|
14
12
|
}
|
|
15
13
|
};
|
|
16
14
|
return result;
|
|
17
15
|
}
|
|
18
|
-
function isParsedAIElement(value) {
|
|
19
|
-
return value !== null && typeof value === "object" && "tag" in value && "parse" in value && "render" in value;
|
|
20
|
-
}
|
|
21
16
|
function isAIElement(value) {
|
|
22
17
|
return value !== null && typeof value === "object" && "tag" in value && "render" in value;
|
|
23
18
|
}
|
|
@@ -29,10 +24,23 @@ function AIFragment({ children }) {
|
|
|
29
24
|
return children;
|
|
30
25
|
}
|
|
31
26
|
|
|
27
|
+
// src/jsx-runtime.ts
|
|
28
|
+
function jsx(type, config, maybeKey) {
|
|
29
|
+
const configWithKey = maybeKey !== void 0 ? { ...config, key: maybeKey } : config;
|
|
30
|
+
const children = config && Array.isArray(config.children) ? config.children : [];
|
|
31
|
+
return createAIElement(type, configWithKey, ...children);
|
|
32
|
+
}
|
|
33
|
+
var jsxDEV = jsx;
|
|
34
|
+
var jsxs = jsx;
|
|
35
|
+
var Fragment = AIFragment;
|
|
36
|
+
|
|
32
37
|
export {
|
|
33
38
|
createAIElement,
|
|
34
|
-
isParsedAIElement,
|
|
35
39
|
isAIElement,
|
|
36
40
|
isLiteral,
|
|
37
|
-
AIFragment
|
|
41
|
+
AIFragment,
|
|
42
|
+
jsx,
|
|
43
|
+
jsxDEV,
|
|
44
|
+
jsxs,
|
|
45
|
+
Fragment
|
|
38
46
|
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
import { ZodTypeAny, ZodObject, ZodRawShape } from 'zod';
|
|
2
|
+
|
|
1
3
|
type Literal = string | number | null | undefined | boolean;
|
|
2
|
-
type JSONSerializable = string | number | boolean | null | JSONSerializable[] | {
|
|
3
|
-
[key: string]: JSONSerializable;
|
|
4
|
-
};
|
|
5
4
|
interface RenderableStream {
|
|
6
5
|
[Symbol.asyncIterator]: () => AsyncGenerator<string, void, unknown>;
|
|
7
6
|
}
|
|
@@ -12,35 +11,59 @@ interface Context<T> {
|
|
|
12
11
|
Provider: AIComponent<{
|
|
13
12
|
children: AINode;
|
|
14
13
|
value: T;
|
|
15
|
-
}
|
|
14
|
+
}>;
|
|
16
15
|
defaultValue: T;
|
|
17
16
|
key: symbol;
|
|
18
17
|
}
|
|
19
|
-
|
|
20
|
-
(props: P, context: RenderContext): Renderable;
|
|
21
|
-
}
|
|
22
|
-
interface AIComponentParsed<P, ParsedResult extends JSONSerializable = string> {
|
|
23
|
-
(props: P, context: RenderContext): Renderable;
|
|
24
|
-
parse: (result: string) => ParsedResult;
|
|
25
|
-
}
|
|
26
|
-
type AINode = Literal | AIElement<AIComponent<any, any>> | AINode[];
|
|
27
|
-
type Renderable = AINode | PromiseLike<Renderable> | RenderableStream;
|
|
28
|
-
type AIComponent<P, R extends string | JSONSerializable> = R extends string ? AIComponentString<P, R> : R extends JSONSerializable ? AIComponentParsed<P, R> : never;
|
|
18
|
+
type AIComponent<P> = (props: P, context: RenderContext) => Renderable;
|
|
29
19
|
declare const attachedContextSymbol: unique symbol;
|
|
30
|
-
interface AIElement<
|
|
20
|
+
interface AIElement<P> {
|
|
31
21
|
/** The tag associated with this {@link AIElement}. */
|
|
32
|
-
tag:
|
|
22
|
+
tag: AIComponent<P>;
|
|
33
23
|
/** The component properties. */
|
|
34
|
-
props:
|
|
24
|
+
props: P;
|
|
35
25
|
/** A function that renders this {@link AIElement} to a {@link Renderable}. */
|
|
36
26
|
render: (ctx: RenderContext) => Renderable;
|
|
37
|
-
parse: (result: string) => ParsedTypeOfAIComponent<C>;
|
|
38
27
|
/** The {@link RenderContext} associated with this {@link Element}. */
|
|
39
28
|
[attachedContextSymbol]?: Record<symbol, any>;
|
|
40
29
|
}
|
|
41
|
-
type
|
|
42
|
-
type
|
|
43
|
-
type
|
|
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
|
+
|
|
34
|
+
type EvaluatorPrimitive = string | number | boolean;
|
|
35
|
+
type EvaluatorResult = {
|
|
36
|
+
key: string;
|
|
37
|
+
result: EvaluatorPrimitive | EvaluatorPrimitive[];
|
|
38
|
+
passes: boolean;
|
|
39
|
+
description?: string;
|
|
40
|
+
debug?: string;
|
|
41
|
+
};
|
|
42
|
+
type EvaluatorFn<V extends Record<string, any> = Record<string, any>, O = any> = (input: {
|
|
43
|
+
promptKey: string;
|
|
44
|
+
variables: V;
|
|
45
|
+
}, result: O) => Promise<EvaluatorResult | EvaluatorResult[]>;
|
|
46
|
+
type OutputParser<O> = {
|
|
47
|
+
schema: ZodTypeAny;
|
|
48
|
+
parse: (result: string) => O;
|
|
49
|
+
};
|
|
50
|
+
interface PromptRenderResult<O> extends RenderableStream {
|
|
51
|
+
then: (onResolved: (value: O) => void, onRejected?: (reason?: any) => void) => void;
|
|
52
|
+
}
|
|
53
|
+
interface Prompt<V extends Record<string, any> = Record<string, any>> {
|
|
54
|
+
key: string;
|
|
55
|
+
component: AIComponent<V>;
|
|
56
|
+
schema: ZodObject<ZodRawShape>;
|
|
57
|
+
evaluators: EvaluatorFn[];
|
|
58
|
+
metadata?: Record<string, any>;
|
|
59
|
+
}
|
|
60
|
+
interface PromptParsed<V extends Record<string, any> = Record<string, any>, O = any> extends Prompt<V> {
|
|
61
|
+
outputParser: OutputParser<O>;
|
|
62
|
+
}
|
|
63
|
+
type Chain<V extends Record<string, any> = Record<string, any>, R = any> = {
|
|
64
|
+
run: (vars: V, context: RenderContext) => R;
|
|
65
|
+
schema: ZodObject<ZodRawShape>;
|
|
66
|
+
};
|
|
44
67
|
|
|
45
68
|
declare const LoggerContext: Context<LogImplementation>;
|
|
46
69
|
type RenderOptions = {
|
|
@@ -53,13 +76,18 @@ type RenderOptions = {
|
|
|
53
76
|
};
|
|
54
77
|
interface RenderContext {
|
|
55
78
|
parentContext: RenderContext | null;
|
|
56
|
-
element: AIElement<
|
|
79
|
+
element: AIElement<any>;
|
|
57
80
|
renderId: string;
|
|
58
81
|
logger: Logger;
|
|
59
82
|
getContext<T>(context: Context<T>): T;
|
|
60
83
|
render(renderable: Renderable, opts?: RenderOptions): RenderResult;
|
|
61
|
-
|
|
84
|
+
render<V extends Record<string, any>, O>(prompt: PromptParsed<V, O>, variables: V, options?: RenderPromptOptions): Promise<O>;
|
|
85
|
+
render<V extends Record<string, any>>(prompt: Prompt<V>, variables: V): RenderResult;
|
|
86
|
+
render<V extends Record<string, any>, O>(chain: Chain<V, O>, variables: V): O;
|
|
62
87
|
}
|
|
88
|
+
type RenderPromptOptions = {
|
|
89
|
+
validateOutput?: boolean;
|
|
90
|
+
};
|
|
63
91
|
declare function createContext<T>(defaultValue: T): Context<T>;
|
|
64
92
|
|
|
65
93
|
/**
|
|
@@ -163,11 +191,14 @@ declare class ChatCompletionError extends Error {
|
|
|
163
191
|
constructor(message: string, chatCompletionRequest: LogChatCompletionRequest);
|
|
164
192
|
}
|
|
165
193
|
|
|
194
|
+
declare function createAIElement<P extends {
|
|
195
|
+
children: C;
|
|
196
|
+
}, C>(tag: AIComponent<P>, props: Omit<P, 'children'> | null, ...children: [C]): AIElement<P>;
|
|
166
197
|
declare function createAIElement<P extends {
|
|
167
198
|
children: C[];
|
|
168
|
-
}, C
|
|
199
|
+
}, C>(tag: AIComponent<P>, props: Omit<P, 'children'> | null, ...children: C[]): AIElement<P>;
|
|
169
200
|
declare function AIFragment({ children }: {
|
|
170
201
|
children: AINode;
|
|
171
202
|
}): Renderable;
|
|
172
203
|
|
|
173
|
-
export { type
|
|
204
|
+
export { type AINode as A, BoundLogger as B, type Context as C, type EvaluatorResult as D, type EvaluatorFn as E, type PromptRenderResult as F, LogImplementation as L, NoopLogImplementation as N, type OutputParser as O, type PromptParsed as P, type RenderContext as R, SystemMessage as S, UserMessage as U, type AIComponent as a, type Prompt as b, type Chain as c, createAIElement as d, AIFragment as e, LoggerContext as f, createContext as g, type ChatCompletionRole as h, AssistantMessage as i, type RenderedConversationMessage as j, computeUsage as k, ChatCompletionError as l, type ChatCompletionRequestPayloads as m, type LogChatCompletionRequest as n, type LogChatCompletionResponse as o, type LogLevel as p, type Logger as q, ConsoleLogger as r, CombinedLogger as s, type Literal as t, type RenderableStream as u, type RenderResult as v, attachedContextSymbol as w, type AIElement as x, type Renderable as y, type PropsOfAIComponent as z };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
import { ZodTypeAny, ZodObject, ZodRawShape } from 'zod';
|
|
2
|
+
|
|
1
3
|
type Literal = string | number | null | undefined | boolean;
|
|
2
|
-
type JSONSerializable = string | number | boolean | null | JSONSerializable[] | {
|
|
3
|
-
[key: string]: JSONSerializable;
|
|
4
|
-
};
|
|
5
4
|
interface RenderableStream {
|
|
6
5
|
[Symbol.asyncIterator]: () => AsyncGenerator<string, void, unknown>;
|
|
7
6
|
}
|
|
@@ -12,35 +11,59 @@ interface Context<T> {
|
|
|
12
11
|
Provider: AIComponent<{
|
|
13
12
|
children: AINode;
|
|
14
13
|
value: T;
|
|
15
|
-
}
|
|
14
|
+
}>;
|
|
16
15
|
defaultValue: T;
|
|
17
16
|
key: symbol;
|
|
18
17
|
}
|
|
19
|
-
|
|
20
|
-
(props: P, context: RenderContext): Renderable;
|
|
21
|
-
}
|
|
22
|
-
interface AIComponentParsed<P, ParsedResult extends JSONSerializable = string> {
|
|
23
|
-
(props: P, context: RenderContext): Renderable;
|
|
24
|
-
parse: (result: string) => ParsedResult;
|
|
25
|
-
}
|
|
26
|
-
type AINode = Literal | AIElement<AIComponent<any, any>> | AINode[];
|
|
27
|
-
type Renderable = AINode | PromiseLike<Renderable> | RenderableStream;
|
|
28
|
-
type AIComponent<P, R extends string | JSONSerializable> = R extends string ? AIComponentString<P, R> : R extends JSONSerializable ? AIComponentParsed<P, R> : never;
|
|
18
|
+
type AIComponent<P> = (props: P, context: RenderContext) => Renderable;
|
|
29
19
|
declare const attachedContextSymbol: unique symbol;
|
|
30
|
-
interface AIElement<
|
|
20
|
+
interface AIElement<P> {
|
|
31
21
|
/** The tag associated with this {@link AIElement}. */
|
|
32
|
-
tag:
|
|
22
|
+
tag: AIComponent<P>;
|
|
33
23
|
/** The component properties. */
|
|
34
|
-
props:
|
|
24
|
+
props: P;
|
|
35
25
|
/** A function that renders this {@link AIElement} to a {@link Renderable}. */
|
|
36
26
|
render: (ctx: RenderContext) => Renderable;
|
|
37
|
-
parse: (result: string) => ParsedTypeOfAIComponent<C>;
|
|
38
27
|
/** The {@link RenderContext} associated with this {@link Element}. */
|
|
39
28
|
[attachedContextSymbol]?: Record<symbol, any>;
|
|
40
29
|
}
|
|
41
|
-
type
|
|
42
|
-
type
|
|
43
|
-
type
|
|
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
|
+
|
|
34
|
+
type EvaluatorPrimitive = string | number | boolean;
|
|
35
|
+
type EvaluatorResult = {
|
|
36
|
+
key: string;
|
|
37
|
+
result: EvaluatorPrimitive | EvaluatorPrimitive[];
|
|
38
|
+
passes: boolean;
|
|
39
|
+
description?: string;
|
|
40
|
+
debug?: string;
|
|
41
|
+
};
|
|
42
|
+
type EvaluatorFn<V extends Record<string, any> = Record<string, any>, O = any> = (input: {
|
|
43
|
+
promptKey: string;
|
|
44
|
+
variables: V;
|
|
45
|
+
}, result: O) => Promise<EvaluatorResult | EvaluatorResult[]>;
|
|
46
|
+
type OutputParser<O> = {
|
|
47
|
+
schema: ZodTypeAny;
|
|
48
|
+
parse: (result: string) => O;
|
|
49
|
+
};
|
|
50
|
+
interface PromptRenderResult<O> extends RenderableStream {
|
|
51
|
+
then: (onResolved: (value: O) => void, onRejected?: (reason?: any) => void) => void;
|
|
52
|
+
}
|
|
53
|
+
interface Prompt<V extends Record<string, any> = Record<string, any>> {
|
|
54
|
+
key: string;
|
|
55
|
+
component: AIComponent<V>;
|
|
56
|
+
schema: ZodObject<ZodRawShape>;
|
|
57
|
+
evaluators: EvaluatorFn[];
|
|
58
|
+
metadata?: Record<string, any>;
|
|
59
|
+
}
|
|
60
|
+
interface PromptParsed<V extends Record<string, any> = Record<string, any>, O = any> extends Prompt<V> {
|
|
61
|
+
outputParser: OutputParser<O>;
|
|
62
|
+
}
|
|
63
|
+
type Chain<V extends Record<string, any> = Record<string, any>, R = any> = {
|
|
64
|
+
run: (vars: V, context: RenderContext) => R;
|
|
65
|
+
schema: ZodObject<ZodRawShape>;
|
|
66
|
+
};
|
|
44
67
|
|
|
45
68
|
declare const LoggerContext: Context<LogImplementation>;
|
|
46
69
|
type RenderOptions = {
|
|
@@ -53,13 +76,18 @@ type RenderOptions = {
|
|
|
53
76
|
};
|
|
54
77
|
interface RenderContext {
|
|
55
78
|
parentContext: RenderContext | null;
|
|
56
|
-
element: AIElement<
|
|
79
|
+
element: AIElement<any>;
|
|
57
80
|
renderId: string;
|
|
58
81
|
logger: Logger;
|
|
59
82
|
getContext<T>(context: Context<T>): T;
|
|
60
83
|
render(renderable: Renderable, opts?: RenderOptions): RenderResult;
|
|
61
|
-
|
|
84
|
+
render<V extends Record<string, any>, O>(prompt: PromptParsed<V, O>, variables: V, options?: RenderPromptOptions): Promise<O>;
|
|
85
|
+
render<V extends Record<string, any>>(prompt: Prompt<V>, variables: V): RenderResult;
|
|
86
|
+
render<V extends Record<string, any>, O>(chain: Chain<V, O>, variables: V): O;
|
|
62
87
|
}
|
|
88
|
+
type RenderPromptOptions = {
|
|
89
|
+
validateOutput?: boolean;
|
|
90
|
+
};
|
|
63
91
|
declare function createContext<T>(defaultValue: T): Context<T>;
|
|
64
92
|
|
|
65
93
|
/**
|
|
@@ -163,11 +191,14 @@ declare class ChatCompletionError extends Error {
|
|
|
163
191
|
constructor(message: string, chatCompletionRequest: LogChatCompletionRequest);
|
|
164
192
|
}
|
|
165
193
|
|
|
194
|
+
declare function createAIElement<P extends {
|
|
195
|
+
children: C;
|
|
196
|
+
}, C>(tag: AIComponent<P>, props: Omit<P, 'children'> | null, ...children: [C]): AIElement<P>;
|
|
166
197
|
declare function createAIElement<P extends {
|
|
167
198
|
children: C[];
|
|
168
|
-
}, C
|
|
199
|
+
}, C>(tag: AIComponent<P>, props: Omit<P, 'children'> | null, ...children: C[]): AIElement<P>;
|
|
169
200
|
declare function AIFragment({ children }: {
|
|
170
201
|
children: AINode;
|
|
171
202
|
}): Renderable;
|
|
172
203
|
|
|
173
|
-
export { type
|
|
204
|
+
export { type AINode as A, BoundLogger as B, type Context as C, type EvaluatorResult as D, type EvaluatorFn as E, type PromptRenderResult as F, LogImplementation as L, NoopLogImplementation as N, type OutputParser as O, type PromptParsed as P, type RenderContext as R, SystemMessage as S, UserMessage as U, type AIComponent as a, type Prompt as b, type Chain as c, createAIElement as d, AIFragment as e, LoggerContext as f, createContext as g, type ChatCompletionRole as h, AssistantMessage as i, type RenderedConversationMessage as j, computeUsage as k, ChatCompletionError as l, type ChatCompletionRequestPayloads as m, type LogChatCompletionRequest as n, type LogChatCompletionResponse as o, type LogLevel as p, type Logger as q, ConsoleLogger as r, CombinedLogger as s, type Literal as t, type RenderableStream as u, type RenderResult as v, attachedContextSymbol as w, type AIElement as x, type Renderable as y, type PropsOfAIComponent as z };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
import { L as LogImplementation,
|
|
2
|
-
export {
|
|
1
|
+
import { R as RenderContext, L as LogImplementation, C as Context, A as AINode, a as AIComponent, E as EvaluatorFn, P as PromptParsed, b as Prompt, c as Chain } from './createElement-Mo9PV8GD.mjs';
|
|
2
|
+
export { x as AIElement, e as AIFragment, i as AssistantMessage, B as BoundLogger, l as ChatCompletionError, m as ChatCompletionRequestPayloads, h as ChatCompletionRole, s as CombinedLogger, r as ConsoleLogger, D as EvaluatorResult, t as Literal, n as LogChatCompletionRequest, o as LogChatCompletionResponse, p as LogLevel, q as Logger, f as LoggerContext, N as NoopLogImplementation, O as OutputParser, F as PromptRenderResult, z as PropsOfAIComponent, v as RenderResult, y as Renderable, u as RenderableStream, j as RenderedConversationMessage, S as SystemMessage, U as UserMessage, w as attachedContextSymbol, k as computeUsage, d as createAIElement, g as createContext } from './createElement-Mo9PV8GD.mjs';
|
|
3
3
|
import { OpenAI } from 'openai';
|
|
4
4
|
export { OpenAI as OpenAIClient } from 'openai';
|
|
5
5
|
import { ChatCompletionSystemMessageParam, ChatCompletionUserMessageParam, ChatCompletionAssistantMessageParam, ChatCompletionCreateParams } from 'openai/resources';
|
|
6
6
|
import AnthropicClient from '@anthropic-ai/sdk';
|
|
7
7
|
export { default as AnthropicClient } from '@anthropic-ai/sdk';
|
|
8
8
|
export { countTokens as countAnthropicTokens } from '@anthropic-ai/tokenizer';
|
|
9
|
+
import { ZodObject, ZodRawShape, ZodTypeAny, ZodString, z } from 'zod';
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
type CreateRenderContextOptions = {
|
|
11
12
|
logger?: LogImplementation;
|
|
12
13
|
rootRenderId?: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
declare function createAIComponentParsed<P, R extends JSONSerializable>(config: {
|
|
16
|
-
render: (props: P, context: RenderContext) => Renderable;
|
|
17
|
-
parse: (result: string) => R;
|
|
18
|
-
}): AIComponentParsed<P, R>;
|
|
14
|
+
};
|
|
15
|
+
declare function createRenderContext({ logger, rootRenderId, }?: CreateRenderContextOptions): RenderContext;
|
|
19
16
|
|
|
20
17
|
type OpenAIChatCompletionRequest = OpenAI.Chat.Completions.ChatCompletionCreateParamsStreaming;
|
|
21
18
|
type OpenAIChatMessage = ChatCompletionSystemMessageParam | ChatCompletionUserMessageParam | ChatCompletionAssistantMessageParam;
|
|
@@ -97,4 +94,37 @@ type AnthropicChatCompletionProps = {
|
|
|
97
94
|
*/
|
|
98
95
|
declare function AnthropicChatCompletion(props: AnthropicChatCompletionProps, { render, logger, getContext }: RenderContext): AsyncGenerator<string, void, unknown>;
|
|
99
96
|
|
|
100
|
-
|
|
97
|
+
/**
|
|
98
|
+
* This is a helper function to create a JsxPrompt type
|
|
99
|
+
*/
|
|
100
|
+
declare function createPrompt<K extends string, I extends ZodObject<ZodRawShape>, O extends ZodTypeAny = ZodString>(config: {
|
|
101
|
+
key: K;
|
|
102
|
+
schema: I;
|
|
103
|
+
component: AIComponent<z.infer<I>>;
|
|
104
|
+
evaluators?: EvaluatorFn<z.infer<I>, z.infer<O>>[];
|
|
105
|
+
metadata?: Record<string, any>;
|
|
106
|
+
outputParser: {
|
|
107
|
+
schema: O;
|
|
108
|
+
parse: (result: string) => z.infer<O>;
|
|
109
|
+
};
|
|
110
|
+
}): PromptParsed<z.infer<I>, z.infer<O>>;
|
|
111
|
+
declare function createPrompt<K extends string, I extends ZodObject<ZodRawShape>>(config: {
|
|
112
|
+
key: K;
|
|
113
|
+
schema: I;
|
|
114
|
+
component: AIComponent<z.infer<I>>;
|
|
115
|
+
evaluators?: EvaluatorFn<z.infer<I>, string>[];
|
|
116
|
+
metadata?: Record<string, any>;
|
|
117
|
+
}): Prompt<z.infer<I>>;
|
|
118
|
+
declare function createChain<I extends ZodObject<ZodRawShape>, R>(config: {
|
|
119
|
+
run: (vars: z.infer<I>, context: RenderContext) => R;
|
|
120
|
+
schema: I;
|
|
121
|
+
}): Chain<z.infer<I>, R>;
|
|
122
|
+
|
|
123
|
+
declare class PromptParseVariablesError extends Error {
|
|
124
|
+
}
|
|
125
|
+
declare class ChainParseVariablesError extends Error {
|
|
126
|
+
}
|
|
127
|
+
declare class PromptInvalidOutputError extends Error {
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export { AIComponent, AINode, AnthropicChatCompletion, type AnthropicChatCompletionRequest, AnthropicClientContext, Chain, ChainParseVariablesError, ContentTypeImage, Context, EvaluatorFn, LogImplementation, OpenAIChatCompletion, type OpenAIChatCompletionRequest, type OpenAIChatMessage, OpenAIClientContext, OpenAIVisionChatCompletion, Prompt, PromptInvalidOutputError, PromptParseVariablesError, PromptParsed, RenderContext, type ValidAnthropicChatModel, type ValidOpenAIChatModel, type ValidOpenAIVisionModel, createChain, createPrompt, createRenderContext, defaultMaxTokens, tokenCountForOpenAIMessage, tokenCountForOpenAIVisionMessage, tokenLimitForChatModel, tokenizer };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
import { L as LogImplementation,
|
|
2
|
-
export {
|
|
1
|
+
import { R as RenderContext, L as LogImplementation, C as Context, A as AINode, a as AIComponent, E as EvaluatorFn, P as PromptParsed, b as Prompt, c as Chain } from './createElement-Mo9PV8GD.js';
|
|
2
|
+
export { x as AIElement, e as AIFragment, i as AssistantMessage, B as BoundLogger, l as ChatCompletionError, m as ChatCompletionRequestPayloads, h as ChatCompletionRole, s as CombinedLogger, r as ConsoleLogger, D as EvaluatorResult, t as Literal, n as LogChatCompletionRequest, o as LogChatCompletionResponse, p as LogLevel, q as Logger, f as LoggerContext, N as NoopLogImplementation, O as OutputParser, F as PromptRenderResult, z as PropsOfAIComponent, v as RenderResult, y as Renderable, u as RenderableStream, j as RenderedConversationMessage, S as SystemMessage, U as UserMessage, w as attachedContextSymbol, k as computeUsage, d as createAIElement, g as createContext } from './createElement-Mo9PV8GD.js';
|
|
3
3
|
import { OpenAI } from 'openai';
|
|
4
4
|
export { OpenAI as OpenAIClient } from 'openai';
|
|
5
5
|
import { ChatCompletionSystemMessageParam, ChatCompletionUserMessageParam, ChatCompletionAssistantMessageParam, ChatCompletionCreateParams } from 'openai/resources';
|
|
6
6
|
import AnthropicClient from '@anthropic-ai/sdk';
|
|
7
7
|
export { default as AnthropicClient } from '@anthropic-ai/sdk';
|
|
8
8
|
export { countTokens as countAnthropicTokens } from '@anthropic-ai/tokenizer';
|
|
9
|
+
import { ZodObject, ZodRawShape, ZodTypeAny, ZodString, z } from 'zod';
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
type CreateRenderContextOptions = {
|
|
11
12
|
logger?: LogImplementation;
|
|
12
13
|
rootRenderId?: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
declare function createAIComponentParsed<P, R extends JSONSerializable>(config: {
|
|
16
|
-
render: (props: P, context: RenderContext) => Renderable;
|
|
17
|
-
parse: (result: string) => R;
|
|
18
|
-
}): AIComponentParsed<P, R>;
|
|
14
|
+
};
|
|
15
|
+
declare function createRenderContext({ logger, rootRenderId, }?: CreateRenderContextOptions): RenderContext;
|
|
19
16
|
|
|
20
17
|
type OpenAIChatCompletionRequest = OpenAI.Chat.Completions.ChatCompletionCreateParamsStreaming;
|
|
21
18
|
type OpenAIChatMessage = ChatCompletionSystemMessageParam | ChatCompletionUserMessageParam | ChatCompletionAssistantMessageParam;
|
|
@@ -97,4 +94,37 @@ type AnthropicChatCompletionProps = {
|
|
|
97
94
|
*/
|
|
98
95
|
declare function AnthropicChatCompletion(props: AnthropicChatCompletionProps, { render, logger, getContext }: RenderContext): AsyncGenerator<string, void, unknown>;
|
|
99
96
|
|
|
100
|
-
|
|
97
|
+
/**
|
|
98
|
+
* This is a helper function to create a JsxPrompt type
|
|
99
|
+
*/
|
|
100
|
+
declare function createPrompt<K extends string, I extends ZodObject<ZodRawShape>, O extends ZodTypeAny = ZodString>(config: {
|
|
101
|
+
key: K;
|
|
102
|
+
schema: I;
|
|
103
|
+
component: AIComponent<z.infer<I>>;
|
|
104
|
+
evaluators?: EvaluatorFn<z.infer<I>, z.infer<O>>[];
|
|
105
|
+
metadata?: Record<string, any>;
|
|
106
|
+
outputParser: {
|
|
107
|
+
schema: O;
|
|
108
|
+
parse: (result: string) => z.infer<O>;
|
|
109
|
+
};
|
|
110
|
+
}): PromptParsed<z.infer<I>, z.infer<O>>;
|
|
111
|
+
declare function createPrompt<K extends string, I extends ZodObject<ZodRawShape>>(config: {
|
|
112
|
+
key: K;
|
|
113
|
+
schema: I;
|
|
114
|
+
component: AIComponent<z.infer<I>>;
|
|
115
|
+
evaluators?: EvaluatorFn<z.infer<I>, string>[];
|
|
116
|
+
metadata?: Record<string, any>;
|
|
117
|
+
}): Prompt<z.infer<I>>;
|
|
118
|
+
declare function createChain<I extends ZodObject<ZodRawShape>, R>(config: {
|
|
119
|
+
run: (vars: z.infer<I>, context: RenderContext) => R;
|
|
120
|
+
schema: I;
|
|
121
|
+
}): Chain<z.infer<I>, R>;
|
|
122
|
+
|
|
123
|
+
declare class PromptParseVariablesError extends Error {
|
|
124
|
+
}
|
|
125
|
+
declare class ChainParseVariablesError extends Error {
|
|
126
|
+
}
|
|
127
|
+
declare class PromptInvalidOutputError extends Error {
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export { AIComponent, AINode, AnthropicChatCompletion, type AnthropicChatCompletionRequest, AnthropicClientContext, Chain, ChainParseVariablesError, ContentTypeImage, Context, EvaluatorFn, LogImplementation, OpenAIChatCompletion, type OpenAIChatCompletionRequest, type OpenAIChatMessage, OpenAIClientContext, OpenAIVisionChatCompletion, Prompt, PromptInvalidOutputError, PromptParseVariablesError, PromptParsed, RenderContext, type ValidAnthropicChatModel, type ValidOpenAIChatModel, type ValidOpenAIVisionModel, createChain, createPrompt, createRenderContext, defaultMaxTokens, tokenCountForOpenAIMessage, tokenCountForOpenAIVisionMessage, tokenLimitForChatModel, tokenizer };
|