@gammatech/aijsx 0.16.3-dev.2024-11-17 → 0.16.4-dev.2024-11-24

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,5 +1,5 @@
1
- import { L as LogChatCompletionRequest, A as AINode, C as ChatCompletionUsage, R as RenderContext, a as LogImplementation, S as SpanProcessor, b as ContextValues, c as Context, T as Tracer, d as ReadableSpan, e as SpanAttributes, f as SpanExporter, g as AIComponent, P as Prompt, h as ChatCompletionRequestPayloads, D as DebugMessage, E as EvaluatorResult, i as EvaluatorFn, j as LlmEvaluatorFn, k as PromptParsed, J as JSX } from './jsx-dev-runtime-RvJm3SlM.mjs';
2
- export { F as AIElement, m as AIFragment, B as BoundLogger, o as ChatMessage, p as ChatRole, w as CombinedLogger, v as ConsoleLogger, I as ImagePart, q as ImagePartProps, x as Literal, r as LogChatCompletionResponse, s as LogLevel, u as Logger, N as NoopLogImplementation, X as OutputParser, H as PropsOfAIComponent, y as RenderResult, G as Renderable, O as Span, K as SpanContext, Q as SpanEvent, M as SpanStatus, V as TracingContext, U as TracingContextKey, W as TracingContextManager, z as attachedContextSymbol, l as createAIElement, n as createContext, t as toDebugMessage } from './jsx-dev-runtime-RvJm3SlM.mjs';
1
+ import { L as LogChatCompletionRequest, A as AINode, C as ChatCompletionUsage, R as RenderContext, a as LogImplementation, S as SpanProcessor, b as ContextValues, c as Context, T as Tracer, d as ReadableSpan, e as SpanAttributes, f as SpanExporter, g as AIComponent, P as Prompt, h as ChatCompletionRequestPayloads, D as DebugMessage, E as EvaluatorResult, i as EvaluatorFn, j as LlmEvaluatorFn, k as PromptParsed, J as JSX } from './jsx-dev-runtime-CwVVc96-.mjs';
2
+ export { F as AIElement, m as AIFragment, B as BoundLogger, o as ChatMessage, p as ChatRole, w as CombinedLogger, v as ConsoleLogger, I as ImagePart, q as ImagePartProps, x as Literal, r as LogChatCompletionResponse, s as LogLevel, u as Logger, N as NoopLogImplementation, X as OutputParser, H as PropsOfAIComponent, y as RenderResult, G as Renderable, O as Span, K as SpanContext, Q as SpanEvent, M as SpanStatus, V as TracingContext, U as TracingContextKey, W as TracingContextManager, z as attachedContextSymbol, l as createAIElement, n as createContext, t as toDebugMessage } from './jsx-dev-runtime-CwVVc96-.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';
@@ -121,8 +121,10 @@ declare class SpanTreeNode {
121
121
  addChild(child: SpanTreeNode): void;
122
122
  descendents(fn: (node: SpanTreeNode) => void): void;
123
123
  everyDescendent(fn: (node: SpanTreeNode) => boolean): boolean;
124
+ getRoot(): SpanTreeNode;
124
125
  getRootByName(name: string): SpanTreeNode | null;
125
126
  getNearestAttribute<K>(key: string): K | null;
127
+ getRootSpanId(): string;
126
128
  getRootAttribute<K>(key: string): K | null;
127
129
  }
128
130
 
@@ -151,6 +153,7 @@ declare class AISpanProcessor implements SpanProcessor {
151
153
  shutdown(): Promise<void> | undefined;
152
154
  onRootPromptDone(rootSpan: ReadableSpan): Promise<void>;
153
155
  enrichSpan(span: ReadableSpan): Promise<ReadableSpan>;
156
+ protected addRootSpanId(span: ReadableSpan): Promise<ReadableSpan>;
154
157
  protected addPromptKeys(span: ReadableSpan): Promise<ReadableSpan>;
155
158
  protected evaluatePrompt(span: ReadableSpan): Promise<ReadableSpan>;
156
159
  }
@@ -195,10 +198,12 @@ declare namespace ProcessedAISpanAttributes {
195
198
  totalCost?: Cost;
196
199
  parentPromptKey?: string;
197
200
  rootPromptKey?: string;
201
+ rootSpanId: string;
198
202
  };
199
203
  type ChatCompletion<K extends keyof ChatCompletionRequestPayloads = keyof ChatCompletionRequestPayloads> = AISpanAttributes.ChatCompletion<K> & {
200
204
  parentPromptKey?: string;
201
205
  rootPromptKey?: string;
206
+ rootSpanId: string;
202
207
  };
203
208
  }
204
209
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { L as LogChatCompletionRequest, A as AINode, C as ChatCompletionUsage, R as RenderContext, a as LogImplementation, S as SpanProcessor, b as ContextValues, c as Context, T as Tracer, d as ReadableSpan, e as SpanAttributes, f as SpanExporter, g as AIComponent, P as Prompt, h as ChatCompletionRequestPayloads, D as DebugMessage, E as EvaluatorResult, i as EvaluatorFn, j as LlmEvaluatorFn, k as PromptParsed, J as JSX } from './jsx-dev-runtime-RvJm3SlM.js';
2
- export { F as AIElement, m as AIFragment, B as BoundLogger, o as ChatMessage, p as ChatRole, w as CombinedLogger, v as ConsoleLogger, I as ImagePart, q as ImagePartProps, x as Literal, r as LogChatCompletionResponse, s as LogLevel, u as Logger, N as NoopLogImplementation, X as OutputParser, H as PropsOfAIComponent, y as RenderResult, G as Renderable, O as Span, K as SpanContext, Q as SpanEvent, M as SpanStatus, V as TracingContext, U as TracingContextKey, W as TracingContextManager, z as attachedContextSymbol, l as createAIElement, n as createContext, t as toDebugMessage } from './jsx-dev-runtime-RvJm3SlM.js';
1
+ import { L as LogChatCompletionRequest, A as AINode, C as ChatCompletionUsage, R as RenderContext, a as LogImplementation, S as SpanProcessor, b as ContextValues, c as Context, T as Tracer, d as ReadableSpan, e as SpanAttributes, f as SpanExporter, g as AIComponent, P as Prompt, h as ChatCompletionRequestPayloads, D as DebugMessage, E as EvaluatorResult, i as EvaluatorFn, j as LlmEvaluatorFn, k as PromptParsed, J as JSX } from './jsx-dev-runtime-CwVVc96-.js';
2
+ export { F as AIElement, m as AIFragment, B as BoundLogger, o as ChatMessage, p as ChatRole, w as CombinedLogger, v as ConsoleLogger, I as ImagePart, q as ImagePartProps, x as Literal, r as LogChatCompletionResponse, s as LogLevel, u as Logger, N as NoopLogImplementation, X as OutputParser, H as PropsOfAIComponent, y as RenderResult, G as Renderable, O as Span, K as SpanContext, Q as SpanEvent, M as SpanStatus, V as TracingContext, U as TracingContextKey, W as TracingContextManager, z as attachedContextSymbol, l as createAIElement, n as createContext, t as toDebugMessage } from './jsx-dev-runtime-CwVVc96-.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';
@@ -121,8 +121,10 @@ declare class SpanTreeNode {
121
121
  addChild(child: SpanTreeNode): void;
122
122
  descendents(fn: (node: SpanTreeNode) => void): void;
123
123
  everyDescendent(fn: (node: SpanTreeNode) => boolean): boolean;
124
+ getRoot(): SpanTreeNode;
124
125
  getRootByName(name: string): SpanTreeNode | null;
125
126
  getNearestAttribute<K>(key: string): K | null;
127
+ getRootSpanId(): string;
126
128
  getRootAttribute<K>(key: string): K | null;
127
129
  }
128
130
 
@@ -151,6 +153,7 @@ declare class AISpanProcessor implements SpanProcessor {
151
153
  shutdown(): Promise<void> | undefined;
152
154
  onRootPromptDone(rootSpan: ReadableSpan): Promise<void>;
153
155
  enrichSpan(span: ReadableSpan): Promise<ReadableSpan>;
156
+ protected addRootSpanId(span: ReadableSpan): Promise<ReadableSpan>;
154
157
  protected addPromptKeys(span: ReadableSpan): Promise<ReadableSpan>;
155
158
  protected evaluatePrompt(span: ReadableSpan): Promise<ReadableSpan>;
156
159
  }
@@ -195,10 +198,12 @@ declare namespace ProcessedAISpanAttributes {
195
198
  totalCost?: Cost;
196
199
  parentPromptKey?: string;
197
200
  rootPromptKey?: string;
201
+ rootSpanId: string;
198
202
  };
199
203
  type ChatCompletion<K extends keyof ChatCompletionRequestPayloads = keyof ChatCompletionRequestPayloads> = AISpanAttributes.ChatCompletion<K> & {
200
204
  parentPromptKey?: string;
201
205
  rootPromptKey?: string;
206
+ rootSpanId: string;
202
207
  };
203
208
  }
204
209
 
package/dist/index.js CHANGED
@@ -1767,6 +1767,15 @@ var SpanTreeNode = class {
1767
1767
  });
1768
1768
  return result;
1769
1769
  }
1770
+ getRoot() {
1771
+ let node = this;
1772
+ let found = this;
1773
+ while (node) {
1774
+ found = node;
1775
+ node = node.parent;
1776
+ }
1777
+ return found;
1778
+ }
1770
1779
  getRootByName(name) {
1771
1780
  let node = this;
1772
1781
  let found = null;
@@ -1781,6 +1790,9 @@ var SpanTreeNode = class {
1781
1790
  getNearestAttribute(key) {
1782
1791
  return getNearestAttribute(this.parent, key);
1783
1792
  }
1793
+ getRootSpanId() {
1794
+ return this.getRoot().span.spanContext.spanId;
1795
+ }
1784
1796
  getRootAttribute(key) {
1785
1797
  return getFarthestAttribute(this, key);
1786
1798
  }
@@ -1885,7 +1897,22 @@ var AISpanProcessor = class {
1885
1897
  async enrichSpan(span) {
1886
1898
  const result1 = await this.evaluatePrompt(span);
1887
1899
  const result2 = await this.addPromptKeys(result1);
1888
- return result2;
1900
+ const result3 = await this.addRootSpanId(result2);
1901
+ return result3;
1902
+ }
1903
+ async addRootSpanId(span) {
1904
+ const node = this.spanTree.findNode(span.spanContext.spanId);
1905
+ if (!node) {
1906
+ return span;
1907
+ }
1908
+ const final = {
1909
+ ...span,
1910
+ attributes: {
1911
+ ...span.attributes,
1912
+ rootSpanId: node.getRootSpanId()
1913
+ }
1914
+ };
1915
+ return final;
1889
1916
  }
1890
1917
  async addPromptKeys(span) {
1891
1918
  if (!isChatCompletionSpan(span) && !isPromptSpan(span)) {
@@ -1897,7 +1924,8 @@ var AISpanProcessor = class {
1897
1924
  }
1898
1925
  const extraAttributes = {
1899
1926
  parentPromptKey: node.getNearestAttribute("promptKey"),
1900
- rootPromptKey: node.getRootAttribute("promptKey")
1927
+ rootPromptKey: node.getRootAttribute("promptKey"),
1928
+ rootSpanId: node.getRootSpanId()
1901
1929
  };
1902
1930
  const final = {
1903
1931
  ...span,
package/dist/index.mjs CHANGED
@@ -1666,6 +1666,15 @@ var SpanTreeNode = class {
1666
1666
  });
1667
1667
  return result;
1668
1668
  }
1669
+ getRoot() {
1670
+ let node = this;
1671
+ let found = this;
1672
+ while (node) {
1673
+ found = node;
1674
+ node = node.parent;
1675
+ }
1676
+ return found;
1677
+ }
1669
1678
  getRootByName(name) {
1670
1679
  let node = this;
1671
1680
  let found = null;
@@ -1680,6 +1689,9 @@ var SpanTreeNode = class {
1680
1689
  getNearestAttribute(key) {
1681
1690
  return getNearestAttribute(this.parent, key);
1682
1691
  }
1692
+ getRootSpanId() {
1693
+ return this.getRoot().span.spanContext.spanId;
1694
+ }
1683
1695
  getRootAttribute(key) {
1684
1696
  return getFarthestAttribute(this, key);
1685
1697
  }
@@ -1784,7 +1796,22 @@ var AISpanProcessor = class {
1784
1796
  async enrichSpan(span) {
1785
1797
  const result1 = await this.evaluatePrompt(span);
1786
1798
  const result2 = await this.addPromptKeys(result1);
1787
- return result2;
1799
+ const result3 = await this.addRootSpanId(result2);
1800
+ return result3;
1801
+ }
1802
+ async addRootSpanId(span) {
1803
+ const node = this.spanTree.findNode(span.spanContext.spanId);
1804
+ if (!node) {
1805
+ return span;
1806
+ }
1807
+ const final = {
1808
+ ...span,
1809
+ attributes: {
1810
+ ...span.attributes,
1811
+ rootSpanId: node.getRootSpanId()
1812
+ }
1813
+ };
1814
+ return final;
1788
1815
  }
1789
1816
  async addPromptKeys(span) {
1790
1817
  if (!isChatCompletionSpan(span) && !isPromptSpan(span)) {
@@ -1796,7 +1823,8 @@ var AISpanProcessor = class {
1796
1823
  }
1797
1824
  const extraAttributes = {
1798
1825
  parentPromptKey: node.getNearestAttribute("promptKey"),
1799
- rootPromptKey: node.getRootAttribute("promptKey")
1826
+ rootPromptKey: node.getRootAttribute("promptKey"),
1827
+ rootSpanId: node.getRootSpanId()
1800
1828
  };
1801
1829
  const final = {
1802
1830
  ...span,
@@ -107,10 +107,10 @@ type EvaluatorResult = {
107
107
  debug?: string;
108
108
  };
109
109
  type EvaluatorFn<V extends Record<string, any> = Record<string, any>, O = any> = (variables: V, result: O) => Promise<EvaluatorResult | EvaluatorResult[]>;
110
- type LlmEvaluatorFn<V extends Record<string, any> = Record<string, any>, O = any> = (ctx: RenderContext, options: {
110
+ type LlmEvaluatorFn<V extends Record<string, any> = Record<string, any>, O = any, E = O> = (ctx: RenderContext, options: {
111
111
  variables: V;
112
112
  output: O;
113
- expected?: O;
113
+ expected?: E;
114
114
  }) => Promise<EvaluatorResult | EvaluatorResult[]>;
115
115
  type OutputParser<O> = {
116
116
  schema: ZodTypeAny;
@@ -107,10 +107,10 @@ type EvaluatorResult = {
107
107
  debug?: string;
108
108
  };
109
109
  type EvaluatorFn<V extends Record<string, any> = Record<string, any>, O = any> = (variables: V, result: O) => Promise<EvaluatorResult | EvaluatorResult[]>;
110
- type LlmEvaluatorFn<V extends Record<string, any> = Record<string, any>, O = any> = (ctx: RenderContext, options: {
110
+ type LlmEvaluatorFn<V extends Record<string, any> = Record<string, any>, O = any, E = O> = (ctx: RenderContext, options: {
111
111
  variables: V;
112
112
  output: O;
113
- expected?: O;
113
+ expected?: E;
114
114
  }) => Promise<EvaluatorResult | EvaluatorResult[]>;
115
115
  type OutputParser<O> = {
116
116
  schema: ZodTypeAny;
@@ -1,2 +1,2 @@
1
- export { $ as Fragment, J as JSX, Y as jsx, Z as jsxDEV, _ as jsxs } from './jsx-dev-runtime-RvJm3SlM.mjs';
1
+ export { $ as Fragment, J as JSX, Y as jsx, Z as jsxDEV, _ as jsxs } from './jsx-dev-runtime-CwVVc96-.mjs';
2
2
  import 'zod';
@@ -1,2 +1,2 @@
1
- export { $ as Fragment, J as JSX, Y as jsx, Z as jsxDEV, _ as jsxs } from './jsx-dev-runtime-RvJm3SlM.js';
1
+ export { $ as Fragment, J as JSX, Y as jsx, Z as jsxDEV, _ as jsxs } from './jsx-dev-runtime-CwVVc96-.js';
2
2
  import 'zod';
@@ -1,2 +1,2 @@
1
- export { $ as Fragment, J as JSX, Y as jsx, Z as jsxDEV, _ as jsxs } from './jsx-dev-runtime-RvJm3SlM.mjs';
1
+ export { $ as Fragment, J as JSX, Y as jsx, Z as jsxDEV, _ as jsxs } from './jsx-dev-runtime-CwVVc96-.mjs';
2
2
  import 'zod';
@@ -1,2 +1,2 @@
1
- export { $ as Fragment, J as JSX, Y as jsx, Z as jsxDEV, _ as jsxs } from './jsx-dev-runtime-RvJm3SlM.js';
1
+ export { $ as Fragment, J as JSX, Y as jsx, Z as jsxDEV, _ as jsxs } from './jsx-dev-runtime-CwVVc96-.js';
2
2
  import 'zod';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gammatech/aijsx",
3
- "version": "0.16.3-dev.2024-11-17",
3
+ "version": "0.16.4-dev.2024-11-24",
4
4
  "description": "Rewrite of aijsx",
5
5
  "author": "Jordan Garcia",
6
6
  "license": "MIT",