@zespan/sdk 1.3.1 → 1.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -8,13 +8,30 @@ import { BaseCallbackHandler } from '@langchain/core/callbacks/base';
8
8
  import { Serialized } from '@langchain/core/load/serializable';
9
9
  import { SpanProcessor } from '@opentelemetry/sdk-trace-base';
10
10
 
11
- interface ZespanOptions {
11
+ type PiiPreset = "gdpr" | "hipaa" | "ccpa" | "pci-dss" | "soc2" | "finance" | "education" | "transportation";
12
+ type PiiCategory = "personal" | "financial" | "government_ids" | "healthcare" | "digital_identity";
13
+ type PiiRedactionMode = "placeholder" | "mask-middle" | "mask-all";
14
+ interface ZespanPiiConfig {
15
+ piiPreset?: PiiPreset;
16
+ piiCategories?: PiiCategory[];
17
+ piiIncludeNames?: boolean;
18
+ piiIncludeEmails?: boolean;
19
+ piiIncludePhones?: boolean;
20
+ piiIncludeAddresses?: boolean;
21
+ piiConfidenceThreshold?: number;
22
+ piiRedactionMode?: PiiRedactionMode;
23
+ piiWhitelist?: string[];
24
+ piiCustomPatterns?: RegExp[];
25
+ }
26
+ interface ZespanOptions extends ZespanPiiConfig {
12
27
  apiKey: string;
13
28
  endpoint?: string;
14
29
  baseURL?: string;
15
30
  environment?: string;
16
31
  storePrompts?: boolean;
17
32
  redactKeys?: string[];
33
+ /** Pattern-based PII detection via openredaction. OFF by default — must opt in. */
34
+ redactPii?: boolean;
18
35
  sampleRate?: number;
19
36
  debug?: boolean;
20
37
  batchSize?: number;
@@ -53,6 +70,11 @@ interface PromptOptions {
53
70
  version?: number;
54
71
  label?: string;
55
72
  cache?: boolean;
73
+ fallback?: {
74
+ type?: "text" | "chat";
75
+ prompt: any;
76
+ config?: any;
77
+ };
56
78
  }
57
79
  interface Prompt {
58
80
  id: string;
@@ -67,6 +89,11 @@ interface Prompt {
67
89
  createdAt: string;
68
90
  updatedAt: string;
69
91
  promptHash: string;
92
+ isFallback?: boolean;
93
+ }
94
+ interface ChatMessage {
95
+ role: string;
96
+ content: string;
70
97
  }
71
98
  declare class PromptClient {
72
99
  private client;
@@ -99,9 +126,12 @@ declare class PromptClient {
99
126
  */
100
127
  updateLabels(name: string, version: number, labels: string[]): Promise<Prompt>;
101
128
  /**
102
- * Compile a prompt with variables
129
+ * Compile a prompt with `{{var}}` substitution and chat message placeholders.
130
+ * - text prompt -> substituted string.
131
+ * - chat prompt -> message array with placeholders spliced in order
132
+ * (unfilled dropped) and vars substituted across all message contents.
103
133
  */
104
- compile(prompt: Prompt, variables: Record<string, string>): string;
134
+ compile(prompt: Prompt, variables?: Record<string, string>, placeholders?: Record<string, ChatMessage[]>): string | ChatMessage[];
105
135
  /**
106
136
  * Clear cache for a specific prompt or all prompts
107
137
  */
@@ -110,6 +140,40 @@ declare class PromptClient {
110
140
  private invalidateCache;
111
141
  }
112
142
 
143
+ interface DatasetItem {
144
+ id: string;
145
+ datasetId: string;
146
+ input: unknown;
147
+ expectedOutput?: unknown;
148
+ metadata?: Record<string, unknown>;
149
+ }
150
+ interface DatasetRun {
151
+ id: string;
152
+ datasetId: string;
153
+ name: string;
154
+ description: string | null;
155
+ }
156
+ declare class DatasetRunHandle {
157
+ private client;
158
+ private datasetId;
159
+ readonly run: DatasetRun;
160
+ constructor(client: ZespanClient, datasetId: string, run: DatasetRun);
161
+ /** Links a dataset item to this run via the trace your own code just produced. */
162
+ link(datasetItemId: string, traceId: string, observationId?: string): Promise<void>;
163
+ }
164
+ declare class DatasetsClient {
165
+ private client;
166
+ private datasetIdByName;
167
+ constructor(client: ZespanClient);
168
+ private resolveDatasetId;
169
+ /** Lists a dataset's items by dataset name. */
170
+ getItems(datasetName: string): Promise<DatasetItem[]>;
171
+ /** Creates or fetches a named run (idempotent — safe to call every time a job starts). */
172
+ createRun(datasetName: string, runName: string, opts?: {
173
+ description?: string;
174
+ }): Promise<DatasetRunHandle>;
175
+ }
176
+
113
177
  /**
114
178
  * SDK ConfigClient — zero-infra runtime configuration client.
115
179
  *
@@ -246,10 +310,12 @@ declare class ZespanClient {
246
310
  readonly environment: string;
247
311
  readonly storePrompts: boolean;
248
312
  readonly redactKeys: string[];
313
+ readonly redactPii: boolean;
249
314
  readonly sampleRate: number;
250
315
  readonly debug: boolean;
251
316
  readonly enableOTel: boolean;
252
317
  readonly prompts: PromptClient;
318
+ readonly datasets: DatasetsClient;
253
319
  readonly configClient: ConfigClient | null;
254
320
  readonly projectId: string | undefined;
255
321
  private batch;
@@ -258,6 +324,9 @@ declare class ZespanClient {
258
324
  constructor(opts: ZespanOptions);
259
325
  enqueue(event: ZespanEvent): void;
260
326
  redactForStorage(value: unknown): string;
327
+ redactValueAsync(value: unknown): Promise<string>;
328
+ redactTextAsync(text: string): Promise<string>;
329
+ redactObjectAsync(obj: Record<string, unknown>): Promise<Record<string, unknown> | undefined>;
261
330
  private resolveGuardrailsUrl;
262
331
  checkGuardrails(input: GuardrailCheckInput): Promise<GuardrailCheckResponse>;
263
332
  flush(): Promise<void>;
@@ -452,6 +521,8 @@ interface AgentOptions {
452
521
  name: string;
453
522
  role?: string;
454
523
  framework?: string;
524
+ version?: string;
525
+ description?: string;
455
526
  tools?: ToolDefinition[];
456
527
  metadata?: Record<string, unknown>;
457
528
  }
@@ -558,6 +629,8 @@ declare const zespan: {
558
629
  createSpan: typeof createSpan;
559
630
  withSpan: typeof withSpan;
560
631
  PromptClient: typeof PromptClient;
632
+ DatasetsClient: typeof DatasetsClient;
633
+ DatasetRunHandle: typeof DatasetRunHandle;
561
634
  CallbackHandler: typeof ZespanCallbackHandler;
562
635
  ADKCallbackHandler: typeof ZespanADKCallbackHandler;
563
636
  autopatch: typeof autopatch;
@@ -568,4 +641,4 @@ declare const zespan: {
568
641
  ZespanLlamaIndexHandler: typeof ZespanLlamaIndexHandler;
569
642
  };
570
643
 
571
- export { type ADKAgentOptions, type ADKRunnerOptions, AgentContext, type AgentOptions, BaggageSpanProcessor, CREWAI_OTEL_ENV, GuardrailBlockedError, type GuardrailCheckInput, type GuardrailCheckResponse, type GuardrailResult, type InstrumentADKOptions, type OTelConfig, type Prompt, PromptClient, type PromptOptions, type ResolvedWrapperGuardrailsSettings, type WrapperGuardrailsOptions, type WrapperGuardrailsSettings, ZespanADKCallbackHandler, ZespanCallbackHandler, ZespanClient, type ZespanContextOptions, ZespanLlamaIndexHandler, attachTraceToAutoGenMessage, autopatch, createSpan, extractAgentContext, extractAgentContext as extractAutoGenContext, extractTraceFromAutoGenMessage, getCrewAIInstrumentationGuide, getPydanticAIConfig, getTracer, getZespanClient, getZespanVercelTelemetry, init, initOTel, initZespan, injectAgentContext, injectAgentContext as injectAutoGenContext, instrumentADK, instrumentVercelAI, markFrameworkActive, markFrameworkInactive, startSpan, withAgent, withSpan, withZespan, withZespanContext, withZespanTrace, wrapADKAgent, wrapADKRunner, wrapAnthropic, wrapBedrock, wrapGoogle, wrapGoogleGenAI, wrapGroq, wrapLiteLLM, wrapMistral, wrapOpenAI, wrapOpenRouter, wrapZespanADKAgent, zespan };
644
+ export { type ADKAgentOptions, type ADKRunnerOptions, AgentContext, type AgentOptions, BaggageSpanProcessor, CREWAI_OTEL_ENV, type DatasetItem, type DatasetRun, DatasetRunHandle, DatasetsClient, GuardrailBlockedError, type GuardrailCheckInput, type GuardrailCheckResponse, type GuardrailResult, type InstrumentADKOptions, type OTelConfig, type PiiCategory, type PiiPreset, type PiiRedactionMode, type Prompt, PromptClient, type PromptOptions, type ResolvedWrapperGuardrailsSettings, type WrapperGuardrailsOptions, type WrapperGuardrailsSettings, ZespanADKCallbackHandler, ZespanCallbackHandler, ZespanClient, type ZespanContextOptions, ZespanLlamaIndexHandler, type ZespanOptions, type ZespanPiiConfig, attachTraceToAutoGenMessage, autopatch, createSpan, extractAgentContext, extractAgentContext as extractAutoGenContext, extractTraceFromAutoGenMessage, getCrewAIInstrumentationGuide, getPydanticAIConfig, getTracer, getZespanClient, getZespanVercelTelemetry, init, initOTel, initZespan, injectAgentContext, injectAgentContext as injectAutoGenContext, instrumentADK, instrumentVercelAI, markFrameworkActive, markFrameworkInactive, startSpan, withAgent, withSpan, withZespan, withZespanContext, withZespanTrace, wrapADKAgent, wrapADKRunner, wrapAnthropic, wrapBedrock, wrapGoogle, wrapGoogleGenAI, wrapGroq, wrapLiteLLM, wrapMistral, wrapOpenAI, wrapOpenRouter, wrapZespanADKAgent, zespan };
package/dist/index.d.ts CHANGED
@@ -8,13 +8,30 @@ import { BaseCallbackHandler } from '@langchain/core/callbacks/base';
8
8
  import { Serialized } from '@langchain/core/load/serializable';
9
9
  import { SpanProcessor } from '@opentelemetry/sdk-trace-base';
10
10
 
11
- interface ZespanOptions {
11
+ type PiiPreset = "gdpr" | "hipaa" | "ccpa" | "pci-dss" | "soc2" | "finance" | "education" | "transportation";
12
+ type PiiCategory = "personal" | "financial" | "government_ids" | "healthcare" | "digital_identity";
13
+ type PiiRedactionMode = "placeholder" | "mask-middle" | "mask-all";
14
+ interface ZespanPiiConfig {
15
+ piiPreset?: PiiPreset;
16
+ piiCategories?: PiiCategory[];
17
+ piiIncludeNames?: boolean;
18
+ piiIncludeEmails?: boolean;
19
+ piiIncludePhones?: boolean;
20
+ piiIncludeAddresses?: boolean;
21
+ piiConfidenceThreshold?: number;
22
+ piiRedactionMode?: PiiRedactionMode;
23
+ piiWhitelist?: string[];
24
+ piiCustomPatterns?: RegExp[];
25
+ }
26
+ interface ZespanOptions extends ZespanPiiConfig {
12
27
  apiKey: string;
13
28
  endpoint?: string;
14
29
  baseURL?: string;
15
30
  environment?: string;
16
31
  storePrompts?: boolean;
17
32
  redactKeys?: string[];
33
+ /** Pattern-based PII detection via openredaction. OFF by default — must opt in. */
34
+ redactPii?: boolean;
18
35
  sampleRate?: number;
19
36
  debug?: boolean;
20
37
  batchSize?: number;
@@ -53,6 +70,11 @@ interface PromptOptions {
53
70
  version?: number;
54
71
  label?: string;
55
72
  cache?: boolean;
73
+ fallback?: {
74
+ type?: "text" | "chat";
75
+ prompt: any;
76
+ config?: any;
77
+ };
56
78
  }
57
79
  interface Prompt {
58
80
  id: string;
@@ -67,6 +89,11 @@ interface Prompt {
67
89
  createdAt: string;
68
90
  updatedAt: string;
69
91
  promptHash: string;
92
+ isFallback?: boolean;
93
+ }
94
+ interface ChatMessage {
95
+ role: string;
96
+ content: string;
70
97
  }
71
98
  declare class PromptClient {
72
99
  private client;
@@ -99,9 +126,12 @@ declare class PromptClient {
99
126
  */
100
127
  updateLabels(name: string, version: number, labels: string[]): Promise<Prompt>;
101
128
  /**
102
- * Compile a prompt with variables
129
+ * Compile a prompt with `{{var}}` substitution and chat message placeholders.
130
+ * - text prompt -> substituted string.
131
+ * - chat prompt -> message array with placeholders spliced in order
132
+ * (unfilled dropped) and vars substituted across all message contents.
103
133
  */
104
- compile(prompt: Prompt, variables: Record<string, string>): string;
134
+ compile(prompt: Prompt, variables?: Record<string, string>, placeholders?: Record<string, ChatMessage[]>): string | ChatMessage[];
105
135
  /**
106
136
  * Clear cache for a specific prompt or all prompts
107
137
  */
@@ -110,6 +140,40 @@ declare class PromptClient {
110
140
  private invalidateCache;
111
141
  }
112
142
 
143
+ interface DatasetItem {
144
+ id: string;
145
+ datasetId: string;
146
+ input: unknown;
147
+ expectedOutput?: unknown;
148
+ metadata?: Record<string, unknown>;
149
+ }
150
+ interface DatasetRun {
151
+ id: string;
152
+ datasetId: string;
153
+ name: string;
154
+ description: string | null;
155
+ }
156
+ declare class DatasetRunHandle {
157
+ private client;
158
+ private datasetId;
159
+ readonly run: DatasetRun;
160
+ constructor(client: ZespanClient, datasetId: string, run: DatasetRun);
161
+ /** Links a dataset item to this run via the trace your own code just produced. */
162
+ link(datasetItemId: string, traceId: string, observationId?: string): Promise<void>;
163
+ }
164
+ declare class DatasetsClient {
165
+ private client;
166
+ private datasetIdByName;
167
+ constructor(client: ZespanClient);
168
+ private resolveDatasetId;
169
+ /** Lists a dataset's items by dataset name. */
170
+ getItems(datasetName: string): Promise<DatasetItem[]>;
171
+ /** Creates or fetches a named run (idempotent — safe to call every time a job starts). */
172
+ createRun(datasetName: string, runName: string, opts?: {
173
+ description?: string;
174
+ }): Promise<DatasetRunHandle>;
175
+ }
176
+
113
177
  /**
114
178
  * SDK ConfigClient — zero-infra runtime configuration client.
115
179
  *
@@ -246,10 +310,12 @@ declare class ZespanClient {
246
310
  readonly environment: string;
247
311
  readonly storePrompts: boolean;
248
312
  readonly redactKeys: string[];
313
+ readonly redactPii: boolean;
249
314
  readonly sampleRate: number;
250
315
  readonly debug: boolean;
251
316
  readonly enableOTel: boolean;
252
317
  readonly prompts: PromptClient;
318
+ readonly datasets: DatasetsClient;
253
319
  readonly configClient: ConfigClient | null;
254
320
  readonly projectId: string | undefined;
255
321
  private batch;
@@ -258,6 +324,9 @@ declare class ZespanClient {
258
324
  constructor(opts: ZespanOptions);
259
325
  enqueue(event: ZespanEvent): void;
260
326
  redactForStorage(value: unknown): string;
327
+ redactValueAsync(value: unknown): Promise<string>;
328
+ redactTextAsync(text: string): Promise<string>;
329
+ redactObjectAsync(obj: Record<string, unknown>): Promise<Record<string, unknown> | undefined>;
261
330
  private resolveGuardrailsUrl;
262
331
  checkGuardrails(input: GuardrailCheckInput): Promise<GuardrailCheckResponse>;
263
332
  flush(): Promise<void>;
@@ -452,6 +521,8 @@ interface AgentOptions {
452
521
  name: string;
453
522
  role?: string;
454
523
  framework?: string;
524
+ version?: string;
525
+ description?: string;
455
526
  tools?: ToolDefinition[];
456
527
  metadata?: Record<string, unknown>;
457
528
  }
@@ -558,6 +629,8 @@ declare const zespan: {
558
629
  createSpan: typeof createSpan;
559
630
  withSpan: typeof withSpan;
560
631
  PromptClient: typeof PromptClient;
632
+ DatasetsClient: typeof DatasetsClient;
633
+ DatasetRunHandle: typeof DatasetRunHandle;
561
634
  CallbackHandler: typeof ZespanCallbackHandler;
562
635
  ADKCallbackHandler: typeof ZespanADKCallbackHandler;
563
636
  autopatch: typeof autopatch;
@@ -568,4 +641,4 @@ declare const zespan: {
568
641
  ZespanLlamaIndexHandler: typeof ZespanLlamaIndexHandler;
569
642
  };
570
643
 
571
- export { type ADKAgentOptions, type ADKRunnerOptions, AgentContext, type AgentOptions, BaggageSpanProcessor, CREWAI_OTEL_ENV, GuardrailBlockedError, type GuardrailCheckInput, type GuardrailCheckResponse, type GuardrailResult, type InstrumentADKOptions, type OTelConfig, type Prompt, PromptClient, type PromptOptions, type ResolvedWrapperGuardrailsSettings, type WrapperGuardrailsOptions, type WrapperGuardrailsSettings, ZespanADKCallbackHandler, ZespanCallbackHandler, ZespanClient, type ZespanContextOptions, ZespanLlamaIndexHandler, attachTraceToAutoGenMessage, autopatch, createSpan, extractAgentContext, extractAgentContext as extractAutoGenContext, extractTraceFromAutoGenMessage, getCrewAIInstrumentationGuide, getPydanticAIConfig, getTracer, getZespanClient, getZespanVercelTelemetry, init, initOTel, initZespan, injectAgentContext, injectAgentContext as injectAutoGenContext, instrumentADK, instrumentVercelAI, markFrameworkActive, markFrameworkInactive, startSpan, withAgent, withSpan, withZespan, withZespanContext, withZespanTrace, wrapADKAgent, wrapADKRunner, wrapAnthropic, wrapBedrock, wrapGoogle, wrapGoogleGenAI, wrapGroq, wrapLiteLLM, wrapMistral, wrapOpenAI, wrapOpenRouter, wrapZespanADKAgent, zespan };
644
+ export { type ADKAgentOptions, type ADKRunnerOptions, AgentContext, type AgentOptions, BaggageSpanProcessor, CREWAI_OTEL_ENV, type DatasetItem, type DatasetRun, DatasetRunHandle, DatasetsClient, GuardrailBlockedError, type GuardrailCheckInput, type GuardrailCheckResponse, type GuardrailResult, type InstrumentADKOptions, type OTelConfig, type PiiCategory, type PiiPreset, type PiiRedactionMode, type Prompt, PromptClient, type PromptOptions, type ResolvedWrapperGuardrailsSettings, type WrapperGuardrailsOptions, type WrapperGuardrailsSettings, ZespanADKCallbackHandler, ZespanCallbackHandler, ZespanClient, type ZespanContextOptions, ZespanLlamaIndexHandler, type ZespanOptions, type ZespanPiiConfig, attachTraceToAutoGenMessage, autopatch, createSpan, extractAgentContext, extractAgentContext as extractAutoGenContext, extractTraceFromAutoGenMessage, getCrewAIInstrumentationGuide, getPydanticAIConfig, getTracer, getZespanClient, getZespanVercelTelemetry, init, initOTel, initZespan, injectAgentContext, injectAgentContext as injectAutoGenContext, instrumentADK, instrumentVercelAI, markFrameworkActive, markFrameworkInactive, startSpan, withAgent, withSpan, withZespan, withZespanContext, withZespanTrace, wrapADKAgent, wrapADKRunner, wrapAnthropic, wrapBedrock, wrapGoogle, wrapGoogleGenAI, wrapGroq, wrapLiteLLM, wrapMistral, wrapOpenAI, wrapOpenRouter, wrapZespanADKAgent, zespan };