@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.
@@ -1,6 +1,5 @@
1
1
  // src/createElement.ts
2
- var parseAsString = (result) => result;
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
- }, string>;
14
+ }>;
16
15
  defaultValue: T;
17
16
  key: symbol;
18
17
  }
19
- interface AIComponentString<P, _Result extends string> {
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<C extends AIComponent<any, any>> {
20
+ interface AIElement<P> {
31
21
  /** The tag associated with this {@link AIElement}. */
32
- tag: C;
22
+ tag: AIComponent<P>;
33
23
  /** The component properties. */
34
- props: PropsOfAIComponent<C>;
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 PropsOfAIComponent<T extends AIComponent<any, any>> = T extends AIComponent<infer P, any> ? P : never;
42
- type ParsedTypeOfAIComponent<T extends AIComponent<any, any>> = T extends AIComponent<any, infer P> ? P : never;
43
- type ParsedTypeOfRenderable<R extends Renderable> = R extends AIElement<infer C> ? C extends AIComponentParsed<any, infer U> ? U : string : string;
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<AIComponent<any, any>>;
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
- renderJson<R extends Renderable>(renderable: R): Promise<ParsedTypeOfRenderable<R>>;
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, T extends AIComponent<P, any>>(tag: T, props: Omit<P, 'children'> | null, children: C[]): AIElement<T>;
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 AIComponentParsed as A, BoundLogger as B, type Context as C, type ParsedTypeOfRenderable as D, type JSONSerializable as J, LogImplementation as L, NoopLogImplementation as N, type PropsOfAIComponent as P, type RenderContext as R, SystemMessage as S, UserMessage as U, type Renderable as a, type AINode as b, createAIElement as c, AIFragment as d, LoggerContext as e, createContext as f, type ChatCompletionRole as g, AssistantMessage as h, type RenderedConversationMessage as i, computeUsage as j, ChatCompletionError as k, type ChatCompletionRequestPayloads as l, type LogChatCompletionRequest as m, type LogChatCompletionResponse as n, type LogLevel as o, type Logger as p, ConsoleLogger as q, CombinedLogger as r, type Literal as s, type RenderableStream as t, type RenderResult as u, type AIComponentString as v, type AIComponent as w, attachedContextSymbol as x, type AIElement as y, type ParsedTypeOfAIComponent as z };
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
- }, string>;
14
+ }>;
16
15
  defaultValue: T;
17
16
  key: symbol;
18
17
  }
19
- interface AIComponentString<P, _Result extends string> {
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<C extends AIComponent<any, any>> {
20
+ interface AIElement<P> {
31
21
  /** The tag associated with this {@link AIElement}. */
32
- tag: C;
22
+ tag: AIComponent<P>;
33
23
  /** The component properties. */
34
- props: PropsOfAIComponent<C>;
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 PropsOfAIComponent<T extends AIComponent<any, any>> = T extends AIComponent<infer P, any> ? P : never;
42
- type ParsedTypeOfAIComponent<T extends AIComponent<any, any>> = T extends AIComponent<any, infer P> ? P : never;
43
- type ParsedTypeOfRenderable<R extends Renderable> = R extends AIElement<infer C> ? C extends AIComponentParsed<any, infer U> ? U : string : string;
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<AIComponent<any, any>>;
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
- renderJson<R extends Renderable>(renderable: R): Promise<ParsedTypeOfRenderable<R>>;
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, T extends AIComponent<P, any>>(tag: T, props: Omit<P, 'children'> | null, children: C[]): AIElement<T>;
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 AIComponentParsed as A, BoundLogger as B, type Context as C, type ParsedTypeOfRenderable as D, type JSONSerializable as J, LogImplementation as L, NoopLogImplementation as N, type PropsOfAIComponent as P, type RenderContext as R, SystemMessage as S, UserMessage as U, type Renderable as a, type AINode as b, createAIElement as c, AIFragment as d, LoggerContext as e, createContext as f, type ChatCompletionRole as g, AssistantMessage as h, type RenderedConversationMessage as i, computeUsage as j, ChatCompletionError as k, type ChatCompletionRequestPayloads as l, type LogChatCompletionRequest as m, type LogChatCompletionResponse as n, type LogLevel as o, type Logger as p, ConsoleLogger as q, CombinedLogger as r, type Literal as s, type RenderableStream as t, type RenderResult as u, type AIComponentString as v, type AIComponent as w, attachedContextSymbol as x, type AIElement as y, type ParsedTypeOfAIComponent as z };
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, R as RenderContext, J as JSONSerializable, a as Renderable, A as AIComponentParsed, C as Context, b as AINode } from './createElement-_dLhPtA-.mjs';
2
- export { w as AIComponent, v as AIComponentString, y as AIElement, d as AIFragment, h as AssistantMessage, B as BoundLogger, k as ChatCompletionError, l as ChatCompletionRequestPayloads, g as ChatCompletionRole, r as CombinedLogger, q as ConsoleLogger, s as Literal, m as LogChatCompletionRequest, n as LogChatCompletionResponse, o as LogLevel, p as Logger, e as LoggerContext, N as NoopLogImplementation, z as ParsedTypeOfAIComponent, D as ParsedTypeOfRenderable, P as PropsOfAIComponent, u as RenderResult, t as RenderableStream, i as RenderedConversationMessage, S as SystemMessage, U as UserMessage, x as attachedContextSymbol, j as computeUsage, c as createAIElement, f as createContext } from './createElement-_dLhPtA-.mjs';
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
- declare function createRenderContext({ logger, rootRenderId, }?: {
11
+ type CreateRenderContextOptions = {
11
12
  logger?: LogImplementation;
12
13
  rootRenderId?: string;
13
- }): RenderContext;
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
- export { AIComponentParsed, AINode, AnthropicChatCompletion, type AnthropicChatCompletionRequest, AnthropicClientContext, ContentTypeImage, Context, JSONSerializable, LogImplementation, OpenAIChatCompletion, type OpenAIChatCompletionRequest, type OpenAIChatMessage, OpenAIClientContext, OpenAIVisionChatCompletion, RenderContext, Renderable, type ValidAnthropicChatModel, type ValidOpenAIChatModel, type ValidOpenAIVisionModel, createAIComponentParsed, createRenderContext, defaultMaxTokens, tokenCountForOpenAIMessage, tokenCountForOpenAIVisionMessage, tokenLimitForChatModel, tokenizer };
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, R as RenderContext, J as JSONSerializable, a as Renderable, A as AIComponentParsed, C as Context, b as AINode } from './createElement-_dLhPtA-.js';
2
- export { w as AIComponent, v as AIComponentString, y as AIElement, d as AIFragment, h as AssistantMessage, B as BoundLogger, k as ChatCompletionError, l as ChatCompletionRequestPayloads, g as ChatCompletionRole, r as CombinedLogger, q as ConsoleLogger, s as Literal, m as LogChatCompletionRequest, n as LogChatCompletionResponse, o as LogLevel, p as Logger, e as LoggerContext, N as NoopLogImplementation, z as ParsedTypeOfAIComponent, D as ParsedTypeOfRenderable, P as PropsOfAIComponent, u as RenderResult, t as RenderableStream, i as RenderedConversationMessage, S as SystemMessage, U as UserMessage, x as attachedContextSymbol, j as computeUsage, c as createAIElement, f as createContext } from './createElement-_dLhPtA-.js';
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
- declare function createRenderContext({ logger, rootRenderId, }?: {
11
+ type CreateRenderContextOptions = {
11
12
  logger?: LogImplementation;
12
13
  rootRenderId?: string;
13
- }): RenderContext;
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
- export { AIComponentParsed, AINode, AnthropicChatCompletion, type AnthropicChatCompletionRequest, AnthropicClientContext, ContentTypeImage, Context, JSONSerializable, LogImplementation, OpenAIChatCompletion, type OpenAIChatCompletionRequest, type OpenAIChatMessage, OpenAIClientContext, OpenAIVisionChatCompletion, RenderContext, Renderable, type ValidAnthropicChatModel, type ValidOpenAIChatModel, type ValidOpenAIVisionModel, createAIComponentParsed, createRenderContext, defaultMaxTokens, tokenCountForOpenAIMessage, tokenCountForOpenAIVisionMessage, tokenLimitForChatModel, tokenizer };
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 };