@gammatech/aijsx 0.3.0-beta.1 → 0.3.0-beta.11

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,37 +11,77 @@ 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> = (variables: V, result: O) => Promise<EvaluatorResult | EvaluatorResult[]>;
43
+ type OutputParser<O> = {
44
+ schema: ZodTypeAny;
45
+ parse: (result: string) => O;
46
+ };
47
+ interface PromptRenderResult<O> extends RenderableStream {
48
+ then: (onResolved: (value: O) => void, onRejected?: (reason?: any) => void) => void;
49
+ }
50
+ interface Prompt<V extends Record<string, any> = Record<string, any>> {
51
+ key: string;
52
+ component: AIComponent<V>;
53
+ schema: ZodObject<ZodRawShape>;
54
+ evaluators: EvaluatorFn<V>[];
55
+ messageSchema: ZodTypeAny | null;
56
+ outputSchema: ZodTypeAny;
57
+ metadata: Record<string, any>;
58
+ }
59
+ interface PromptParsed<V extends Record<string, any> = Record<string, any>, O = any> extends Prompt<V> {
60
+ evaluators: EvaluatorFn<V, O>[];
61
+ messageSchema: null;
62
+ parse: (result: string) => O;
63
+ }
64
+ interface FunctionChain<V extends Record<string, any> = Record<string, any>, R extends NotAsyncGenerator<any> = any> {
65
+ key: string;
66
+ type: 'function';
67
+ run: (vars: V, context: RenderContext) => R;
68
+ schema: ZodObject<ZodRawShape>;
69
+ messageSchema: null;
70
+ outputSchema: ZodTypeAny;
71
+ }
72
+ interface StreamChain<V extends Record<string, any> = Record<string, any>, R extends AsyncGenerator<any, any, any> = AsyncGenerator<any, any, any>> {
73
+ key: string;
74
+ type: 'stream';
75
+ run: (vars: V, context: RenderContext) => R;
76
+ schema: ZodObject<ZodRawShape>;
77
+ messageSchema: ZodTypeAny;
78
+ outputSchema: null;
79
+ }
80
+ type IsAsyncGenerator<T> = T extends AsyncGenerator<any, any, any> ? true : false;
81
+ type NotAsyncGenerator<T> = IsAsyncGenerator<T> extends true ? never : T;
44
82
 
45
83
  declare const LoggerContext: Context<LogImplementation>;
84
+ type ContextValues = Record<symbol, any>;
46
85
  type RenderOptions = {
47
86
  preserveTags?: boolean;
48
87
  renderedProps?: {
@@ -53,13 +92,21 @@ type RenderOptions = {
53
92
  };
54
93
  interface RenderContext {
55
94
  parentContext: RenderContext | null;
56
- element: AIElement<AIComponent<any, any>>;
95
+ element: AIElement<any>;
57
96
  renderId: string;
58
97
  logger: Logger;
59
98
  getContext<T>(context: Context<T>): T;
60
99
  render(renderable: Renderable, opts?: RenderOptions): RenderResult;
61
- renderJson<R extends Renderable>(renderable: R): Promise<ParsedTypeOfRenderable<R>>;
62
- }
100
+ render<V extends Record<string, any>, O>(prompt: PromptParsed<V, O>, variables: V, options?: RenderPromptOptions): Promise<O>;
101
+ render<V extends Record<string, any>>(prompt: Prompt<V>, variables: V): RenderResult;
102
+ render<V extends Record<string, any>, O extends AsyncGenerator<any>>(chain: StreamChain<V, O>, variables: V): AsyncGenerator<O, void>;
103
+ render<V extends Record<string, any>, O>(chain: FunctionChain<V, O>, variables: V): O;
104
+ runChain<V extends Record<string, any>, R>(chain: FunctionChain<V, R>, variables: V): R;
105
+ runChain<V extends Record<string, any>, R extends AsyncGenerator<any>>(chain: StreamChain<V, R>, variables: V): R;
106
+ }
107
+ type RenderPromptOptions = {
108
+ validateOutput?: boolean;
109
+ };
63
110
  declare function createContext<T>(defaultValue: T): Context<T>;
64
111
 
65
112
  /**
@@ -163,11 +210,14 @@ declare class ChatCompletionError extends Error {
163
210
  constructor(message: string, chatCompletionRequest: LogChatCompletionRequest);
164
211
  }
165
212
 
213
+ declare function createAIElement<P extends {
214
+ children: C;
215
+ }, C>(tag: AIComponent<P>, props: Omit<P, 'children'> | null, ...children: [C]): AIElement<P>;
166
216
  declare function createAIElement<P extends {
167
217
  children: C[];
168
- }, C, T extends AIComponent<P, any>>(tag: T, props: Omit<P, 'children'> | null, children: C[]): AIElement<T>;
218
+ }, C>(tag: AIComponent<P>, props: Omit<P, 'children'> | null, ...children: C[]): AIElement<P>;
169
219
  declare function AIFragment({ children }: {
170
220
  children: AINode;
171
221
  }): Renderable;
172
222
 
173
- export { type AINode 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, AIFragment as a, LoggerContext as b, createAIElement as c, createContext as d, type ChatCompletionRole as e, AssistantMessage as f, type RenderedConversationMessage as g, computeUsage as h, ChatCompletionError as i, type ChatCompletionRequestPayloads as j, type LogChatCompletionRequest as k, type LogChatCompletionResponse as l, type LogLevel as m, type Logger as n, ConsoleLogger as o, CombinedLogger as p, type Literal as q, type RenderableStream as r, type RenderResult as s, type AIComponentString as t, type AIComponentParsed as u, type Renderable as v, type AIComponent as w, attachedContextSymbol as x, type AIElement as y, type ParsedTypeOfAIComponent as z };
223
+ 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 EvaluatorResult as H, type PromptRenderResult as I, 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 Context as b, type AINode as c, createAIElement as d, AIFragment as e, LoggerContext 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 ChatCompletionRequestPayloads as n, type LogChatCompletionRequest as o, type LogChatCompletionResponse as p, type LogLevel as q, type Logger as r, NoopLogImplementation as s, ConsoleLogger as t, CombinedLogger as u, type Literal as v, type RenderableStream as w, type RenderResult as x, attachedContextSymbol as y, type AIElement 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,37 +11,77 @@ 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> = (variables: V, result: O) => Promise<EvaluatorResult | EvaluatorResult[]>;
43
+ type OutputParser<O> = {
44
+ schema: ZodTypeAny;
45
+ parse: (result: string) => O;
46
+ };
47
+ interface PromptRenderResult<O> extends RenderableStream {
48
+ then: (onResolved: (value: O) => void, onRejected?: (reason?: any) => void) => void;
49
+ }
50
+ interface Prompt<V extends Record<string, any> = Record<string, any>> {
51
+ key: string;
52
+ component: AIComponent<V>;
53
+ schema: ZodObject<ZodRawShape>;
54
+ evaluators: EvaluatorFn<V>[];
55
+ messageSchema: ZodTypeAny | null;
56
+ outputSchema: ZodTypeAny;
57
+ metadata: Record<string, any>;
58
+ }
59
+ interface PromptParsed<V extends Record<string, any> = Record<string, any>, O = any> extends Prompt<V> {
60
+ evaluators: EvaluatorFn<V, O>[];
61
+ messageSchema: null;
62
+ parse: (result: string) => O;
63
+ }
64
+ interface FunctionChain<V extends Record<string, any> = Record<string, any>, R extends NotAsyncGenerator<any> = any> {
65
+ key: string;
66
+ type: 'function';
67
+ run: (vars: V, context: RenderContext) => R;
68
+ schema: ZodObject<ZodRawShape>;
69
+ messageSchema: null;
70
+ outputSchema: ZodTypeAny;
71
+ }
72
+ interface StreamChain<V extends Record<string, any> = Record<string, any>, R extends AsyncGenerator<any, any, any> = AsyncGenerator<any, any, any>> {
73
+ key: string;
74
+ type: 'stream';
75
+ run: (vars: V, context: RenderContext) => R;
76
+ schema: ZodObject<ZodRawShape>;
77
+ messageSchema: ZodTypeAny;
78
+ outputSchema: null;
79
+ }
80
+ type IsAsyncGenerator<T> = T extends AsyncGenerator<any, any, any> ? true : false;
81
+ type NotAsyncGenerator<T> = IsAsyncGenerator<T> extends true ? never : T;
44
82
 
45
83
  declare const LoggerContext: Context<LogImplementation>;
84
+ type ContextValues = Record<symbol, any>;
46
85
  type RenderOptions = {
47
86
  preserveTags?: boolean;
48
87
  renderedProps?: {
@@ -53,13 +92,21 @@ type RenderOptions = {
53
92
  };
54
93
  interface RenderContext {
55
94
  parentContext: RenderContext | null;
56
- element: AIElement<AIComponent<any, any>>;
95
+ element: AIElement<any>;
57
96
  renderId: string;
58
97
  logger: Logger;
59
98
  getContext<T>(context: Context<T>): T;
60
99
  render(renderable: Renderable, opts?: RenderOptions): RenderResult;
61
- renderJson<R extends Renderable>(renderable: R): Promise<ParsedTypeOfRenderable<R>>;
62
- }
100
+ render<V extends Record<string, any>, O>(prompt: PromptParsed<V, O>, variables: V, options?: RenderPromptOptions): Promise<O>;
101
+ render<V extends Record<string, any>>(prompt: Prompt<V>, variables: V): RenderResult;
102
+ render<V extends Record<string, any>, O extends AsyncGenerator<any>>(chain: StreamChain<V, O>, variables: V): AsyncGenerator<O, void>;
103
+ render<V extends Record<string, any>, O>(chain: FunctionChain<V, O>, variables: V): O;
104
+ runChain<V extends Record<string, any>, R>(chain: FunctionChain<V, R>, variables: V): R;
105
+ runChain<V extends Record<string, any>, R extends AsyncGenerator<any>>(chain: StreamChain<V, R>, variables: V): R;
106
+ }
107
+ type RenderPromptOptions = {
108
+ validateOutput?: boolean;
109
+ };
63
110
  declare function createContext<T>(defaultValue: T): Context<T>;
64
111
 
65
112
  /**
@@ -163,11 +210,14 @@ declare class ChatCompletionError extends Error {
163
210
  constructor(message: string, chatCompletionRequest: LogChatCompletionRequest);
164
211
  }
165
212
 
213
+ declare function createAIElement<P extends {
214
+ children: C;
215
+ }, C>(tag: AIComponent<P>, props: Omit<P, 'children'> | null, ...children: [C]): AIElement<P>;
166
216
  declare function createAIElement<P extends {
167
217
  children: C[];
168
- }, C, T extends AIComponent<P, any>>(tag: T, props: Omit<P, 'children'> | null, children: C[]): AIElement<T>;
218
+ }, C>(tag: AIComponent<P>, props: Omit<P, 'children'> | null, ...children: C[]): AIElement<P>;
169
219
  declare function AIFragment({ children }: {
170
220
  children: AINode;
171
221
  }): Renderable;
172
222
 
173
- export { type AINode 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, AIFragment as a, LoggerContext as b, createAIElement as c, createContext as d, type ChatCompletionRole as e, AssistantMessage as f, type RenderedConversationMessage as g, computeUsage as h, ChatCompletionError as i, type ChatCompletionRequestPayloads as j, type LogChatCompletionRequest as k, type LogChatCompletionResponse as l, type LogLevel as m, type Logger as n, ConsoleLogger as o, CombinedLogger as p, type Literal as q, type RenderableStream as r, type RenderResult as s, type AIComponentString as t, type AIComponentParsed as u, type Renderable as v, type AIComponent as w, attachedContextSymbol as x, type AIElement as y, type ParsedTypeOfAIComponent as z };
223
+ 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 EvaluatorResult as H, type PromptRenderResult as I, 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 Context as b, type AINode as c, createAIElement as d, AIFragment as e, LoggerContext 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 ChatCompletionRequestPayloads as n, type LogChatCompletionRequest as o, type LogChatCompletionResponse as p, type LogLevel as q, type Logger as r, NoopLogImplementation as s, ConsoleLogger as t, CombinedLogger as u, type Literal as v, type RenderableStream as w, type RenderResult as x, attachedContextSymbol as y, type AIElement as z };
package/dist/index.d.mts CHANGED
@@ -1,5 +1,6 @@
1
- import { L as LogImplementation, R as RenderContext, C as Context, A as AINode } from './createElement-jIxJ-zr7.mjs';
2
- export { w as AIComponent, u as AIComponentParsed, t as AIComponentString, y as AIElement, a as AIFragment, f as AssistantMessage, B as BoundLogger, i as ChatCompletionError, j as ChatCompletionRequestPayloads, e as ChatCompletionRole, p as CombinedLogger, o as ConsoleLogger, J as JSONSerializable, q as Literal, k as LogChatCompletionRequest, l as LogChatCompletionResponse, m as LogLevel, n as Logger, b as LoggerContext, N as NoopLogImplementation, z as ParsedTypeOfAIComponent, D as ParsedTypeOfRenderable, P as PropsOfAIComponent, s as RenderResult, v as Renderable, r as RenderableStream, g as RenderedConversationMessage, S as SystemMessage, U as UserMessage, x as attachedContextSymbol, h as computeUsage, c as createAIElement, d as createContext } from './createElement-jIxJ-zr7.mjs';
1
+ import { R as RenderContext, L as LogImplementation, C as ContextValues, A as AIComponent, E as EvaluatorFn, P as PromptParsed, a as Prompt, N as NotAsyncGenerator, F as FunctionChain, S as StreamChain, b as Context, c as AINode } from './createElement-SURWK7y8.mjs';
2
+ export { z as AIElement, e as AIFragment, j as AssistantMessage, B as BoundLogger, m as ChatCompletionError, n as ChatCompletionRequestPayloads, h as ChatCompletionRole, u as CombinedLogger, t as ConsoleLogger, H as EvaluatorResult, v as Literal, o as LogChatCompletionRequest, p as LogChatCompletionResponse, q as LogLevel, r as Logger, f as LoggerContext, s as NoopLogImplementation, O as OutputParser, I as PromptRenderResult, G as PropsOfAIComponent, x as RenderResult, D as Renderable, w as RenderableStream, k as RenderedConversationMessage, i as SystemMessage, U as UserMessage, y as attachedContextSymbol, l as computeUsage, d as createAIElement, g as createContext } from './createElement-SURWK7y8.mjs';
3
+ import { ZodObject, ZodRawShape, ZodTypeAny, ZodString, z } from 'zod';
3
4
  import { OpenAI } from 'openai';
4
5
  export { OpenAI as OpenAIClient } from 'openai';
5
6
  import { ChatCompletionSystemMessageParam, ChatCompletionUserMessageParam, ChatCompletionAssistantMessageParam, ChatCompletionCreateParams } from 'openai/resources';
@@ -7,10 +8,54 @@ import AnthropicClient from '@anthropic-ai/sdk';
7
8
  export { default as AnthropicClient } from '@anthropic-ai/sdk';
8
9
  export { countTokens as countAnthropicTokens } from '@anthropic-ai/tokenizer';
9
10
 
10
- declare function createRenderContext({ logger, rootRenderId, }?: {
11
+ type CreateRenderContextOptions = {
11
12
  logger?: LogImplementation;
12
13
  rootRenderId?: string;
13
- }): RenderContext;
14
+ contextValues?: ContextValues;
15
+ };
16
+ declare function createRenderContext({ logger, rootRenderId, contextValues, }?: CreateRenderContextOptions): RenderContext;
17
+
18
+ /**
19
+ * This is a helper function to create a JsxPrompt type
20
+ */
21
+ declare function createPrompt<K extends string, I extends ZodObject<ZodRawShape>, O extends ZodTypeAny = ZodString>(config: {
22
+ key: K;
23
+ schema: I;
24
+ component: AIComponent<z.infer<I>>;
25
+ evaluators?: EvaluatorFn<z.infer<I>, z.infer<O>>[];
26
+ metadata?: Record<string, any>;
27
+ outputParser: {
28
+ schema: O;
29
+ parse: (result: string) => z.infer<O>;
30
+ };
31
+ }): PromptParsed<z.infer<I>, z.infer<O>>;
32
+ declare function createPrompt<K extends string, I extends ZodObject<ZodRawShape>>(config: {
33
+ key: K;
34
+ schema: I;
35
+ component: AIComponent<z.infer<I>>;
36
+ evaluators?: EvaluatorFn<z.infer<I>, string>[];
37
+ metadata?: Record<string, any>;
38
+ }): Prompt<z.infer<I>>;
39
+
40
+ declare function createFunctionChain<I extends ZodObject<ZodRawShape>, R extends NotAsyncGenerator<any>>(chain: {
41
+ key: string;
42
+ run: (variables: z.infer<I>, context: RenderContext) => R;
43
+ outputSchema?: ZodTypeAny;
44
+ schema: I;
45
+ }): FunctionChain<z.infer<I>, R>;
46
+ declare function createStreamChain<I extends ZodObject<ZodRawShape>, M extends ZodTypeAny, R extends AsyncGenerator<any, any, any>>(chain: {
47
+ key: string;
48
+ run: (variables: z.infer<I>, context: RenderContext) => R;
49
+ schema: I;
50
+ messageSchema?: M;
51
+ }): StreamChain<z.infer<I>, R>;
52
+
53
+ declare class PromptParseVariablesError extends Error {
54
+ }
55
+ declare class ChainParseVariablesError extends Error {
56
+ }
57
+ declare class PromptInvalidOutputError extends Error {
58
+ }
14
59
 
15
60
  type OpenAIChatCompletionRequest = OpenAI.Chat.Completions.ChatCompletionCreateParamsStreaming;
16
61
  type OpenAIChatMessage = ChatCompletionSystemMessageParam | ChatCompletionUserMessageParam | ChatCompletionAssistantMessageParam;
@@ -92,4 +137,4 @@ type AnthropicChatCompletionProps = {
92
137
  */
93
138
  declare function AnthropicChatCompletion(props: AnthropicChatCompletionProps, { render, logger, getContext }: RenderContext): AsyncGenerator<string, void, unknown>;
94
139
 
95
- export { AINode, AnthropicChatCompletion, type AnthropicChatCompletionRequest, AnthropicClientContext, ContentTypeImage, Context, LogImplementation, OpenAIChatCompletion, type OpenAIChatCompletionRequest, type OpenAIChatMessage, OpenAIClientContext, OpenAIVisionChatCompletion, RenderContext, type ValidAnthropicChatModel, type ValidOpenAIChatModel, type ValidOpenAIVisionModel, createRenderContext, defaultMaxTokens, tokenCountForOpenAIMessage, tokenCountForOpenAIVisionMessage, tokenLimitForChatModel, tokenizer };
140
+ export { AIComponent, AINode, AnthropicChatCompletion, type AnthropicChatCompletionRequest, AnthropicClientContext, ChainParseVariablesError, ContentTypeImage, Context, EvaluatorFn, FunctionChain, LogImplementation, NotAsyncGenerator, OpenAIChatCompletion, type OpenAIChatCompletionRequest, type OpenAIChatMessage, OpenAIClientContext, OpenAIVisionChatCompletion, Prompt, PromptInvalidOutputError, PromptParseVariablesError, PromptParsed, RenderContext, StreamChain, type ValidAnthropicChatModel, type ValidOpenAIChatModel, type ValidOpenAIVisionModel, createFunctionChain, createPrompt, createRenderContext, createStreamChain, defaultMaxTokens, tokenCountForOpenAIMessage, tokenCountForOpenAIVisionMessage, tokenLimitForChatModel, tokenizer };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { L as LogImplementation, R as RenderContext, C as Context, A as AINode } from './createElement-jIxJ-zr7.js';
2
- export { w as AIComponent, u as AIComponentParsed, t as AIComponentString, y as AIElement, a as AIFragment, f as AssistantMessage, B as BoundLogger, i as ChatCompletionError, j as ChatCompletionRequestPayloads, e as ChatCompletionRole, p as CombinedLogger, o as ConsoleLogger, J as JSONSerializable, q as Literal, k as LogChatCompletionRequest, l as LogChatCompletionResponse, m as LogLevel, n as Logger, b as LoggerContext, N as NoopLogImplementation, z as ParsedTypeOfAIComponent, D as ParsedTypeOfRenderable, P as PropsOfAIComponent, s as RenderResult, v as Renderable, r as RenderableStream, g as RenderedConversationMessage, S as SystemMessage, U as UserMessage, x as attachedContextSymbol, h as computeUsage, c as createAIElement, d as createContext } from './createElement-jIxJ-zr7.js';
1
+ import { R as RenderContext, L as LogImplementation, C as ContextValues, A as AIComponent, E as EvaluatorFn, P as PromptParsed, a as Prompt, N as NotAsyncGenerator, F as FunctionChain, S as StreamChain, b as Context, c as AINode } from './createElement-SURWK7y8.js';
2
+ export { z as AIElement, e as AIFragment, j as AssistantMessage, B as BoundLogger, m as ChatCompletionError, n as ChatCompletionRequestPayloads, h as ChatCompletionRole, u as CombinedLogger, t as ConsoleLogger, H as EvaluatorResult, v as Literal, o as LogChatCompletionRequest, p as LogChatCompletionResponse, q as LogLevel, r as Logger, f as LoggerContext, s as NoopLogImplementation, O as OutputParser, I as PromptRenderResult, G as PropsOfAIComponent, x as RenderResult, D as Renderable, w as RenderableStream, k as RenderedConversationMessage, i as SystemMessage, U as UserMessage, y as attachedContextSymbol, l as computeUsage, d as createAIElement, g as createContext } from './createElement-SURWK7y8.js';
3
+ import { ZodObject, ZodRawShape, ZodTypeAny, ZodString, z } from 'zod';
3
4
  import { OpenAI } from 'openai';
4
5
  export { OpenAI as OpenAIClient } from 'openai';
5
6
  import { ChatCompletionSystemMessageParam, ChatCompletionUserMessageParam, ChatCompletionAssistantMessageParam, ChatCompletionCreateParams } from 'openai/resources';
@@ -7,10 +8,54 @@ import AnthropicClient from '@anthropic-ai/sdk';
7
8
  export { default as AnthropicClient } from '@anthropic-ai/sdk';
8
9
  export { countTokens as countAnthropicTokens } from '@anthropic-ai/tokenizer';
9
10
 
10
- declare function createRenderContext({ logger, rootRenderId, }?: {
11
+ type CreateRenderContextOptions = {
11
12
  logger?: LogImplementation;
12
13
  rootRenderId?: string;
13
- }): RenderContext;
14
+ contextValues?: ContextValues;
15
+ };
16
+ declare function createRenderContext({ logger, rootRenderId, contextValues, }?: CreateRenderContextOptions): RenderContext;
17
+
18
+ /**
19
+ * This is a helper function to create a JsxPrompt type
20
+ */
21
+ declare function createPrompt<K extends string, I extends ZodObject<ZodRawShape>, O extends ZodTypeAny = ZodString>(config: {
22
+ key: K;
23
+ schema: I;
24
+ component: AIComponent<z.infer<I>>;
25
+ evaluators?: EvaluatorFn<z.infer<I>, z.infer<O>>[];
26
+ metadata?: Record<string, any>;
27
+ outputParser: {
28
+ schema: O;
29
+ parse: (result: string) => z.infer<O>;
30
+ };
31
+ }): PromptParsed<z.infer<I>, z.infer<O>>;
32
+ declare function createPrompt<K extends string, I extends ZodObject<ZodRawShape>>(config: {
33
+ key: K;
34
+ schema: I;
35
+ component: AIComponent<z.infer<I>>;
36
+ evaluators?: EvaluatorFn<z.infer<I>, string>[];
37
+ metadata?: Record<string, any>;
38
+ }): Prompt<z.infer<I>>;
39
+
40
+ declare function createFunctionChain<I extends ZodObject<ZodRawShape>, R extends NotAsyncGenerator<any>>(chain: {
41
+ key: string;
42
+ run: (variables: z.infer<I>, context: RenderContext) => R;
43
+ outputSchema?: ZodTypeAny;
44
+ schema: I;
45
+ }): FunctionChain<z.infer<I>, R>;
46
+ declare function createStreamChain<I extends ZodObject<ZodRawShape>, M extends ZodTypeAny, R extends AsyncGenerator<any, any, any>>(chain: {
47
+ key: string;
48
+ run: (variables: z.infer<I>, context: RenderContext) => R;
49
+ schema: I;
50
+ messageSchema?: M;
51
+ }): StreamChain<z.infer<I>, R>;
52
+
53
+ declare class PromptParseVariablesError extends Error {
54
+ }
55
+ declare class ChainParseVariablesError extends Error {
56
+ }
57
+ declare class PromptInvalidOutputError extends Error {
58
+ }
14
59
 
15
60
  type OpenAIChatCompletionRequest = OpenAI.Chat.Completions.ChatCompletionCreateParamsStreaming;
16
61
  type OpenAIChatMessage = ChatCompletionSystemMessageParam | ChatCompletionUserMessageParam | ChatCompletionAssistantMessageParam;
@@ -92,4 +137,4 @@ type AnthropicChatCompletionProps = {
92
137
  */
93
138
  declare function AnthropicChatCompletion(props: AnthropicChatCompletionProps, { render, logger, getContext }: RenderContext): AsyncGenerator<string, void, unknown>;
94
139
 
95
- export { AINode, AnthropicChatCompletion, type AnthropicChatCompletionRequest, AnthropicClientContext, ContentTypeImage, Context, LogImplementation, OpenAIChatCompletion, type OpenAIChatCompletionRequest, type OpenAIChatMessage, OpenAIClientContext, OpenAIVisionChatCompletion, RenderContext, type ValidAnthropicChatModel, type ValidOpenAIChatModel, type ValidOpenAIVisionModel, createRenderContext, defaultMaxTokens, tokenCountForOpenAIMessage, tokenCountForOpenAIVisionMessage, tokenLimitForChatModel, tokenizer };
140
+ export { AIComponent, AINode, AnthropicChatCompletion, type AnthropicChatCompletionRequest, AnthropicClientContext, ChainParseVariablesError, ContentTypeImage, Context, EvaluatorFn, FunctionChain, LogImplementation, NotAsyncGenerator, OpenAIChatCompletion, type OpenAIChatCompletionRequest, type OpenAIChatMessage, OpenAIClientContext, OpenAIVisionChatCompletion, Prompt, PromptInvalidOutputError, PromptParseVariablesError, PromptParsed, RenderContext, StreamChain, type ValidAnthropicChatModel, type ValidOpenAIChatModel, type ValidOpenAIVisionModel, createFunctionChain, createPrompt, createRenderContext, createStreamChain, defaultMaxTokens, tokenCountForOpenAIMessage, tokenCountForOpenAIVisionMessage, tokenLimitForChatModel, tokenizer };