@gammatech/aijsx 0.9.2-dev.2024-05-30 → 0.10.0-dev.2024-06-04

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/index.d.mts CHANGED
@@ -1,12 +1,12 @@
1
- import { L as LogChatCompletionRequest, A as AINode, C as ChatMessage, R as RenderContext, a as LogImplementation, S as SpanProcessor, b as ContextValues, c as Context, T as Tracer, d as ReadableSpan, e as SpanExporter, f as AIComponent, g as SpanAttributes, P as Prompt, h as ChatCompletionRequestPayloads, D as DebugMessage, E as EvaluatorResult, i as EvaluatorFn, j as PromptParsed, N as NotAsyncGenerator, F as FunctionChain, k as StreamChain, J as JSX } from './jsx-dev-runtime-uCZBuaDe.mjs';
2
- export { G as AIElement, m as AIFragment, B as BoundLogger, o as ChatRole, w as CombinedLogger, v as ConsoleLogger, I as ImagePart, p as ImagePartProps, x as Literal, q as LogChatCompletionResponse, r as LogLevel, s as Logger, u as NoopLogImplementation, Y as OutputParser, K as PropsOfAIComponent, y as RenderResult, H as Renderable, Q as Span, M as SpanContext, U as SpanEvent, O as SpanStatus, W as TracingContext, V as TracingContextKey, X as TracingContextManager, z as attachedContextSymbol, l as createAIElement, n as createContext, t as toDebugMessage } from './jsx-dev-runtime-uCZBuaDe.mjs';
1
+ import { L as LogChatCompletionRequest, A as AINode, C as ChatMessage, R as RenderContext, a as LogImplementation, S as SpanProcessor, b as ContextValues, c as Context, T as Tracer, d as ReadableSpan, e as SpanExporter, f as AIComponent, g as SpanAttributes, P as Prompt, h as ChatCompletionRequestPayloads, D as DebugMessage, E as EvaluatorResult, i as EvaluatorFn, j as PromptParsed, J as JSX } from './jsx-dev-runtime-vXV-PExh.mjs';
2
+ export { y as AIElement, l as AIFragment, B as BoundLogger, n as ChatRole, u as CombinedLogger, s as ConsoleLogger, I as ImagePart, o as ImagePartProps, v as Literal, p as LogChatCompletionResponse, q as LogLevel, r as Logger, N as NoopLogImplementation, V as OutputParser, F as PropsOfAIComponent, w as RenderResult, z as Renderable, K as Span, G as SpanContext, M as SpanEvent, H as SpanStatus, Q as TracingContext, O as TracingContextKey, U as TracingContextManager, x as attachedContextSymbol, k as createAIElement, m as createContext, t as toDebugMessage } from './jsx-dev-runtime-vXV-PExh.mjs';
3
3
  import { ZodObject, ZodRawShape, ZodTypeAny, ZodString, z } from 'zod';
4
4
  import { OpenAI } from 'openai';
5
5
  export { OpenAI as OpenAIClient } from 'openai';
6
6
  import { ChatCompletionSystemMessageParam, ChatCompletionUserMessageParam, ChatCompletionAssistantMessageParam, ChatCompletionCreateParams } from 'openai/resources';
7
7
  import AnthropicClient from '@anthropic-ai/sdk';
8
8
  export { default as AnthropicClient } from '@anthropic-ai/sdk';
9
- import { GenerateContentRequest, VertexAI } from '@google-cloud/vertexai';
9
+ import { PromptFeedback, GenerateContentRequest, VertexAI } from '@google-cloud/vertexai';
10
10
  export { VertexAI } from '@google-cloud/vertexai';
11
11
 
12
12
  declare class ChatCompletionError extends Error {
@@ -85,6 +85,24 @@ declare class AITraceAPI {
85
85
  }
86
86
  declare const tracing: AITraceAPI;
87
87
 
88
+ declare class SpanTree {
89
+ roots: SpanTreeNode[];
90
+ findSpan: any;
91
+ addSpan(span: ReadableSpan): boolean;
92
+ findNode(id: string): SpanTreeNode | null;
93
+ }
94
+ declare class SpanTreeNode {
95
+ readonly id: string;
96
+ readonly name: string;
97
+ readonly parent: SpanTreeNode | null;
98
+ readonly children: SpanTreeNode[];
99
+ readonly attrs: Record<string, any>;
100
+ constructor(id: string, name: string, parent: SpanTreeNode | null, children: SpanTreeNode[], attrs: Record<string, any>);
101
+ addChild(child: SpanTreeNode): void;
102
+ getNearestAttribute<K>(key: string): K | null;
103
+ getRootAttribute<K>(key: string): K | null;
104
+ }
105
+
88
106
  type CostFn = (tokensUsed: {
89
107
  prompt: number;
90
108
  completion: number;
@@ -109,6 +127,7 @@ declare abstract class EnrichingSpanProcessor implements SpanProcessor {
109
127
  }[];
110
128
  protected onAllDonePromise: Promise<void> | null;
111
129
  protected onAllDonePromiseResolve: (() => void) | null;
130
+ protected spanTree: SpanTree;
112
131
  constructor(exporter: SpanExporter);
113
132
  onStart(span: ReadableSpan): Promise<void>;
114
133
  onEnd(span: ReadableSpan): Promise<void>;
@@ -125,6 +144,7 @@ declare class AISpanProcessor extends EnrichingSpanProcessor {
125
144
  };
126
145
  onTraceComplete(rootSpan: ReadableSpan): Promise<void>;
127
146
  enrichSpan(span: ReadableSpan): Promise<ReadableSpan>;
147
+ protected addPromptKeys(span: ReadableSpan): Promise<ReadableSpan>;
128
148
  protected updateCost(span: ReadableSpan): Promise<ReadableSpan>;
129
149
  protected updateUsage(span: ReadableSpan): Promise<ReadableSpan>;
130
150
  protected evaluatePrompt(span: ReadableSpan): Promise<ReadableSpan>;
@@ -151,11 +171,6 @@ declare namespace AISpanAttributes {
151
171
  output: string;
152
172
  parsedOutput?: any;
153
173
  };
154
- type Chain = {
155
- chainKey: string;
156
- chainType: string;
157
- variables: Record<string, any>;
158
- };
159
174
  type ChatCompletion<K extends keyof ChatCompletionRequestPayloads = keyof ChatCompletionRequestPayloads> = {
160
175
  model: string;
161
176
  cost?: number;
@@ -168,6 +183,7 @@ declare namespace AISpanAttributes {
168
183
  finishReason: string | null;
169
184
  output: string;
170
185
  tokensUsed: Usage;
186
+ [key: string]: any;
171
187
  };
172
188
  }
173
189
  declare namespace ProcessedAISpanAttributes {
@@ -177,12 +193,13 @@ declare namespace ProcessedAISpanAttributes {
177
193
  evaluatorError?: string;
178
194
  totalUsage?: Usage;
179
195
  totalCost?: Cost;
196
+ parentPromptKey?: string;
197
+ rootPromptKey?: string;
180
198
  };
181
- type Chain = AISpanAttributes.Chain & {
182
- totalUsage?: Usage;
183
- totalCost?: Cost;
199
+ type ChatCompletion<K extends keyof ChatCompletionRequestPayloads = keyof ChatCompletionRequestPayloads> = AISpanAttributes.ChatCompletion<K> & {
200
+ parentPromptKey?: string;
201
+ rootPromptKey?: string;
184
202
  };
185
- type ChatCompletion<K extends keyof ChatCompletionRequestPayloads = keyof ChatCompletionRequestPayloads> = AISpanAttributes.ChatCompletion<K>;
186
203
  }
187
204
 
188
205
  /**
@@ -207,19 +224,6 @@ declare function createPrompt<K extends string, I extends ZodObject<ZodRawShape>
207
224
  metadata?: Record<string, any>;
208
225
  }): Prompt<z.infer<I>>;
209
226
 
210
- declare function createFunctionChain<I extends ZodObject<ZodRawShape>, R extends NotAsyncGenerator<any>>(chain: {
211
- key: string;
212
- run: (variables: z.infer<I>, context: RenderContext) => R;
213
- outputSchema?: ZodTypeAny;
214
- schema: I;
215
- }): FunctionChain<z.infer<I>, R>;
216
- declare function createStreamChain<I extends ZodObject<ZodRawShape>, M extends ZodTypeAny, R extends AsyncGenerator<any, any, any>>(chain: {
217
- key: string;
218
- run: (variables: z.infer<I>, context: RenderContext) => R;
219
- schema: I;
220
- messageSchema?: M;
221
- }): StreamChain<z.infer<I>, R>;
222
-
223
227
  declare class ParseVariablesError extends Error {
224
228
  }
225
229
  declare class PromptInvalidOutputError extends Error {
@@ -280,6 +284,11 @@ declare module '@gammatech/aijsx' {
280
284
  interface ChatCompletionRequestPayloads {
281
285
  google: GoogleChatCompletionRequest;
282
286
  }
287
+ interface ChatCompletionResponseFields {
288
+ google: {
289
+ promptFeedback?: PromptFeedback;
290
+ };
291
+ }
283
292
  }
284
293
  type ValidGoogleChatModel = 'gemini-1.5-pro' | 'gemini-1.5-flash';
285
294
  declare const GoogleClientContext: Context<() => ChatCompletionClientAndProvider<VertexAI>>;
@@ -293,4 +302,4 @@ type GoogleChatCompletionProps = {
293
302
  };
294
303
  declare function GoogleChatCompletion(props: GoogleChatCompletionProps, ctx: RenderContext): JSX.Element;
295
304
 
296
- export { AIComponent, AINode, AISpanAttributes, AISpanProcessor, AnthropicChatCompletion, type AnthropicChatCompletionRequest, AnthropicClientContext, AssistantMessage, type ChatCompletionClientAndProvider, ChatCompletionError, type ChatCompletionRequestPayloads, ChatMessage, Context, type CostFn, DebugMessage, DefaultMaxRetriesContext, EnrichingSpanProcessor, EvaluatorFn, EvaluatorResult, Fallback, FunctionChain, GoogleChatCompletion, type GoogleChatCompletionRequest, GoogleClientContext, LogChatCompletionRequest, LogImplementation, NotAsyncGenerator, OpenAIChatCompletion, type OpenAIChatCompletionRequest, type OpenAIChatMessage, OpenAIClientContext, ParseVariablesError, ProcessedAISpanAttributes, type Prompt, PromptInvalidOutputError, PromptParsed, ReadableSpan, RenderContext, Retry, RetryCountContext, SpanAttributes, SpanExporter, SpanProcessor, StreamChain, SystemMessage, type TokenizerFn, Trace, Tracer, UserMessage, type ValidAnthropicChatModel, type ValidGoogleChatModel, type ValidOpenAIChatModel, type ValidOpenAIVisionModel, anthropicTokenizer, computeUsage, createFunctionChain, createPrompt, createRenderContext, createStreamChain, evaluatePrompt, openaiTokenizer, tracing };
305
+ export { AIComponent, AINode, AISpanAttributes, AISpanProcessor, AnthropicChatCompletion, type AnthropicChatCompletionRequest, AnthropicClientContext, AssistantMessage, type ChatCompletionClientAndProvider, ChatCompletionError, type ChatCompletionRequestPayloads, ChatMessage, Context, type CostFn, DebugMessage, DefaultMaxRetriesContext, EnrichingSpanProcessor, EvaluatorFn, EvaluatorResult, Fallback, GoogleChatCompletion, type GoogleChatCompletionRequest, GoogleClientContext, LogChatCompletionRequest, LogImplementation, OpenAIChatCompletion, type OpenAIChatCompletionRequest, type OpenAIChatMessage, OpenAIClientContext, ParseVariablesError, ProcessedAISpanAttributes, type Prompt, PromptInvalidOutputError, PromptParsed, ReadableSpan, RenderContext, Retry, RetryCountContext, SpanAttributes, SpanExporter, SpanProcessor, SystemMessage, type TokenizerFn, Trace, Tracer, UserMessage, type ValidAnthropicChatModel, type ValidGoogleChatModel, type ValidOpenAIChatModel, type ValidOpenAIVisionModel, anthropicTokenizer, computeUsage, createPrompt, createRenderContext, evaluatePrompt, openaiTokenizer, tracing };
package/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- import { L as LogChatCompletionRequest, A as AINode, C as ChatMessage, R as RenderContext, a as LogImplementation, S as SpanProcessor, b as ContextValues, c as Context, T as Tracer, d as ReadableSpan, e as SpanExporter, f as AIComponent, g as SpanAttributes, P as Prompt, h as ChatCompletionRequestPayloads, D as DebugMessage, E as EvaluatorResult, i as EvaluatorFn, j as PromptParsed, N as NotAsyncGenerator, F as FunctionChain, k as StreamChain, J as JSX } from './jsx-dev-runtime-uCZBuaDe.js';
2
- export { G as AIElement, m as AIFragment, B as BoundLogger, o as ChatRole, w as CombinedLogger, v as ConsoleLogger, I as ImagePart, p as ImagePartProps, x as Literal, q as LogChatCompletionResponse, r as LogLevel, s as Logger, u as NoopLogImplementation, Y as OutputParser, K as PropsOfAIComponent, y as RenderResult, H as Renderable, Q as Span, M as SpanContext, U as SpanEvent, O as SpanStatus, W as TracingContext, V as TracingContextKey, X as TracingContextManager, z as attachedContextSymbol, l as createAIElement, n as createContext, t as toDebugMessage } from './jsx-dev-runtime-uCZBuaDe.js';
1
+ import { L as LogChatCompletionRequest, A as AINode, C as ChatMessage, R as RenderContext, a as LogImplementation, S as SpanProcessor, b as ContextValues, c as Context, T as Tracer, d as ReadableSpan, e as SpanExporter, f as AIComponent, g as SpanAttributes, P as Prompt, h as ChatCompletionRequestPayloads, D as DebugMessage, E as EvaluatorResult, i as EvaluatorFn, j as PromptParsed, J as JSX } from './jsx-dev-runtime-vXV-PExh.js';
2
+ export { y as AIElement, l as AIFragment, B as BoundLogger, n as ChatRole, u as CombinedLogger, s as ConsoleLogger, I as ImagePart, o as ImagePartProps, v as Literal, p as LogChatCompletionResponse, q as LogLevel, r as Logger, N as NoopLogImplementation, V as OutputParser, F as PropsOfAIComponent, w as RenderResult, z as Renderable, K as Span, G as SpanContext, M as SpanEvent, H as SpanStatus, Q as TracingContext, O as TracingContextKey, U as TracingContextManager, x as attachedContextSymbol, k as createAIElement, m as createContext, t as toDebugMessage } from './jsx-dev-runtime-vXV-PExh.js';
3
3
  import { ZodObject, ZodRawShape, ZodTypeAny, ZodString, z } from 'zod';
4
4
  import { OpenAI } from 'openai';
5
5
  export { OpenAI as OpenAIClient } from 'openai';
6
6
  import { ChatCompletionSystemMessageParam, ChatCompletionUserMessageParam, ChatCompletionAssistantMessageParam, ChatCompletionCreateParams } from 'openai/resources';
7
7
  import AnthropicClient from '@anthropic-ai/sdk';
8
8
  export { default as AnthropicClient } from '@anthropic-ai/sdk';
9
- import { GenerateContentRequest, VertexAI } from '@google-cloud/vertexai';
9
+ import { PromptFeedback, GenerateContentRequest, VertexAI } from '@google-cloud/vertexai';
10
10
  export { VertexAI } from '@google-cloud/vertexai';
11
11
 
12
12
  declare class ChatCompletionError extends Error {
@@ -85,6 +85,24 @@ declare class AITraceAPI {
85
85
  }
86
86
  declare const tracing: AITraceAPI;
87
87
 
88
+ declare class SpanTree {
89
+ roots: SpanTreeNode[];
90
+ findSpan: any;
91
+ addSpan(span: ReadableSpan): boolean;
92
+ findNode(id: string): SpanTreeNode | null;
93
+ }
94
+ declare class SpanTreeNode {
95
+ readonly id: string;
96
+ readonly name: string;
97
+ readonly parent: SpanTreeNode | null;
98
+ readonly children: SpanTreeNode[];
99
+ readonly attrs: Record<string, any>;
100
+ constructor(id: string, name: string, parent: SpanTreeNode | null, children: SpanTreeNode[], attrs: Record<string, any>);
101
+ addChild(child: SpanTreeNode): void;
102
+ getNearestAttribute<K>(key: string): K | null;
103
+ getRootAttribute<K>(key: string): K | null;
104
+ }
105
+
88
106
  type CostFn = (tokensUsed: {
89
107
  prompt: number;
90
108
  completion: number;
@@ -109,6 +127,7 @@ declare abstract class EnrichingSpanProcessor implements SpanProcessor {
109
127
  }[];
110
128
  protected onAllDonePromise: Promise<void> | null;
111
129
  protected onAllDonePromiseResolve: (() => void) | null;
130
+ protected spanTree: SpanTree;
112
131
  constructor(exporter: SpanExporter);
113
132
  onStart(span: ReadableSpan): Promise<void>;
114
133
  onEnd(span: ReadableSpan): Promise<void>;
@@ -125,6 +144,7 @@ declare class AISpanProcessor extends EnrichingSpanProcessor {
125
144
  };
126
145
  onTraceComplete(rootSpan: ReadableSpan): Promise<void>;
127
146
  enrichSpan(span: ReadableSpan): Promise<ReadableSpan>;
147
+ protected addPromptKeys(span: ReadableSpan): Promise<ReadableSpan>;
128
148
  protected updateCost(span: ReadableSpan): Promise<ReadableSpan>;
129
149
  protected updateUsage(span: ReadableSpan): Promise<ReadableSpan>;
130
150
  protected evaluatePrompt(span: ReadableSpan): Promise<ReadableSpan>;
@@ -151,11 +171,6 @@ declare namespace AISpanAttributes {
151
171
  output: string;
152
172
  parsedOutput?: any;
153
173
  };
154
- type Chain = {
155
- chainKey: string;
156
- chainType: string;
157
- variables: Record<string, any>;
158
- };
159
174
  type ChatCompletion<K extends keyof ChatCompletionRequestPayloads = keyof ChatCompletionRequestPayloads> = {
160
175
  model: string;
161
176
  cost?: number;
@@ -168,6 +183,7 @@ declare namespace AISpanAttributes {
168
183
  finishReason: string | null;
169
184
  output: string;
170
185
  tokensUsed: Usage;
186
+ [key: string]: any;
171
187
  };
172
188
  }
173
189
  declare namespace ProcessedAISpanAttributes {
@@ -177,12 +193,13 @@ declare namespace ProcessedAISpanAttributes {
177
193
  evaluatorError?: string;
178
194
  totalUsage?: Usage;
179
195
  totalCost?: Cost;
196
+ parentPromptKey?: string;
197
+ rootPromptKey?: string;
180
198
  };
181
- type Chain = AISpanAttributes.Chain & {
182
- totalUsage?: Usage;
183
- totalCost?: Cost;
199
+ type ChatCompletion<K extends keyof ChatCompletionRequestPayloads = keyof ChatCompletionRequestPayloads> = AISpanAttributes.ChatCompletion<K> & {
200
+ parentPromptKey?: string;
201
+ rootPromptKey?: string;
184
202
  };
185
- type ChatCompletion<K extends keyof ChatCompletionRequestPayloads = keyof ChatCompletionRequestPayloads> = AISpanAttributes.ChatCompletion<K>;
186
203
  }
187
204
 
188
205
  /**
@@ -207,19 +224,6 @@ declare function createPrompt<K extends string, I extends ZodObject<ZodRawShape>
207
224
  metadata?: Record<string, any>;
208
225
  }): Prompt<z.infer<I>>;
209
226
 
210
- declare function createFunctionChain<I extends ZodObject<ZodRawShape>, R extends NotAsyncGenerator<any>>(chain: {
211
- key: string;
212
- run: (variables: z.infer<I>, context: RenderContext) => R;
213
- outputSchema?: ZodTypeAny;
214
- schema: I;
215
- }): FunctionChain<z.infer<I>, R>;
216
- declare function createStreamChain<I extends ZodObject<ZodRawShape>, M extends ZodTypeAny, R extends AsyncGenerator<any, any, any>>(chain: {
217
- key: string;
218
- run: (variables: z.infer<I>, context: RenderContext) => R;
219
- schema: I;
220
- messageSchema?: M;
221
- }): StreamChain<z.infer<I>, R>;
222
-
223
227
  declare class ParseVariablesError extends Error {
224
228
  }
225
229
  declare class PromptInvalidOutputError extends Error {
@@ -280,6 +284,11 @@ declare module '@gammatech/aijsx' {
280
284
  interface ChatCompletionRequestPayloads {
281
285
  google: GoogleChatCompletionRequest;
282
286
  }
287
+ interface ChatCompletionResponseFields {
288
+ google: {
289
+ promptFeedback?: PromptFeedback;
290
+ };
291
+ }
283
292
  }
284
293
  type ValidGoogleChatModel = 'gemini-1.5-pro' | 'gemini-1.5-flash';
285
294
  declare const GoogleClientContext: Context<() => ChatCompletionClientAndProvider<VertexAI>>;
@@ -293,4 +302,4 @@ type GoogleChatCompletionProps = {
293
302
  };
294
303
  declare function GoogleChatCompletion(props: GoogleChatCompletionProps, ctx: RenderContext): JSX.Element;
295
304
 
296
- export { AIComponent, AINode, AISpanAttributes, AISpanProcessor, AnthropicChatCompletion, type AnthropicChatCompletionRequest, AnthropicClientContext, AssistantMessage, type ChatCompletionClientAndProvider, ChatCompletionError, type ChatCompletionRequestPayloads, ChatMessage, Context, type CostFn, DebugMessage, DefaultMaxRetriesContext, EnrichingSpanProcessor, EvaluatorFn, EvaluatorResult, Fallback, FunctionChain, GoogleChatCompletion, type GoogleChatCompletionRequest, GoogleClientContext, LogChatCompletionRequest, LogImplementation, NotAsyncGenerator, OpenAIChatCompletion, type OpenAIChatCompletionRequest, type OpenAIChatMessage, OpenAIClientContext, ParseVariablesError, ProcessedAISpanAttributes, type Prompt, PromptInvalidOutputError, PromptParsed, ReadableSpan, RenderContext, Retry, RetryCountContext, SpanAttributes, SpanExporter, SpanProcessor, StreamChain, SystemMessage, type TokenizerFn, Trace, Tracer, UserMessage, type ValidAnthropicChatModel, type ValidGoogleChatModel, type ValidOpenAIChatModel, type ValidOpenAIVisionModel, anthropicTokenizer, computeUsage, createFunctionChain, createPrompt, createRenderContext, createStreamChain, evaluatePrompt, openaiTokenizer, tracing };
305
+ export { AIComponent, AINode, AISpanAttributes, AISpanProcessor, AnthropicChatCompletion, type AnthropicChatCompletionRequest, AnthropicClientContext, AssistantMessage, type ChatCompletionClientAndProvider, ChatCompletionError, type ChatCompletionRequestPayloads, ChatMessage, Context, type CostFn, DebugMessage, DefaultMaxRetriesContext, EnrichingSpanProcessor, EvaluatorFn, EvaluatorResult, Fallback, GoogleChatCompletion, type GoogleChatCompletionRequest, GoogleClientContext, LogChatCompletionRequest, LogImplementation, OpenAIChatCompletion, type OpenAIChatCompletionRequest, type OpenAIChatMessage, OpenAIClientContext, ParseVariablesError, ProcessedAISpanAttributes, type Prompt, PromptInvalidOutputError, PromptParsed, ReadableSpan, RenderContext, Retry, RetryCountContext, SpanAttributes, SpanExporter, SpanProcessor, SystemMessage, type TokenizerFn, Trace, Tracer, UserMessage, type ValidAnthropicChatModel, type ValidGoogleChatModel, type ValidOpenAIChatModel, type ValidOpenAIVisionModel, anthropicTokenizer, computeUsage, createPrompt, createRenderContext, evaluatePrompt, openaiTokenizer, tracing };