@sentrial/sdk 0.5.0 → 0.6.0

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.cts CHANGED
@@ -1018,15 +1018,32 @@ declare class ValidationError extends SentrialError {
1018
1018
  */
1019
1019
 
1020
1020
  type AnyFunction = (...args: unknown[]) => unknown;
1021
+ type AISDKFunction = (...args: never[]) => unknown;
1021
1022
  type AIModule = {
1022
- generateText?: AnyFunction;
1023
- streamText?: AnyFunction;
1024
- generateObject?: AnyFunction;
1025
- streamObject?: AnyFunction;
1026
- experimental_generateText?: AnyFunction;
1027
- experimental_streamText?: AnyFunction;
1028
- experimental_generateObject?: AnyFunction;
1029
- experimental_streamObject?: AnyFunction;
1023
+ generateText?: AISDKFunction;
1024
+ streamText?: AISDKFunction;
1025
+ generateObject?: AISDKFunction;
1026
+ streamObject?: AISDKFunction;
1027
+ experimental_generateText?: AISDKFunction;
1028
+ experimental_streamText?: AISDKFunction;
1029
+ experimental_generateObject?: AISDKFunction;
1030
+ experimental_streamObject?: AISDKFunction;
1031
+ };
1032
+ type WrappedFunction<T, Stable extends PropertyKey, Experimental extends PropertyKey, Fallback> = T extends Record<Stable, infer F extends AISDKFunction> ? F : T extends Record<Experimental, infer F extends AISDKFunction> ? F : Fallback;
1033
+ type WrappedAISDK<T extends AIModule> = {
1034
+ generateText: WrappedFunction<T, 'generateText', 'experimental_generateText', ReturnType<typeof wrapGenerateText>>;
1035
+ streamText: WrappedFunction<T, 'streamText', 'experimental_streamText', ReturnType<typeof wrapStreamText>>;
1036
+ generateObject: WrappedFunction<T, 'generateObject', 'experimental_generateObject', ReturnType<typeof wrapGenerateObject>>;
1037
+ streamObject: WrappedFunction<T, 'streamObject', 'experimental_streamObject', ReturnType<typeof wrapStreamObject>>;
1038
+ };
1039
+ type WrapAISDKOptions = {
1040
+ client?: SentrialClient;
1041
+ defaultAgent?: string;
1042
+ userId?: StringOrFn;
1043
+ convoId?: StringOrFn;
1044
+ /** Session metadata, including explicit signalActionId / signalWorkflow when known.
1045
+ * Create a separate wrapper for each business action; no identity is inferred. */
1046
+ metadata?: Record<string, unknown>;
1030
1047
  };
1031
1048
  type GenerateTextParams = {
1032
1049
  model: {
@@ -1131,6 +1148,7 @@ type WrapperConfig = {
1131
1148
  defaultAgent?: string;
1132
1149
  userId?: StringOrFn;
1133
1150
  convoId?: StringOrFn;
1151
+ metadata?: Record<string, unknown>;
1134
1152
  };
1135
1153
  /**
1136
1154
  * Configure the Sentrial SDK for Vercel AI SDK integration.
@@ -1182,17 +1200,7 @@ declare function wrapStreamObject(originalFn: AnyFunction, client: SentrialClien
1182
1200
  * const { generateText } = wrapAISDK(ai, { client, defaultAgent: 'my-agent' });
1183
1201
  * ```
1184
1202
  */
1185
- declare function wrapAISDK(ai: AIModule, options?: {
1186
- client?: SentrialClient;
1187
- defaultAgent?: string;
1188
- userId?: StringOrFn;
1189
- convoId?: StringOrFn;
1190
- }): {
1191
- generateText: ReturnType<typeof wrapGenerateText>;
1192
- streamText: ReturnType<typeof wrapStreamText>;
1193
- generateObject: ReturnType<typeof wrapGenerateObject>;
1194
- streamObject: ReturnType<typeof wrapStreamObject>;
1195
- };
1203
+ declare function wrapAISDK<T extends AIModule>(ai: T, options?: WrapAISDKOptions): WrappedAISDK<T>;
1196
1204
 
1197
1205
  /**
1198
1206
  * Options shape accepted by {@link getVariantForAISDK} — a permissive subset of
package/dist/index.d.ts CHANGED
@@ -1018,15 +1018,32 @@ declare class ValidationError extends SentrialError {
1018
1018
  */
1019
1019
 
1020
1020
  type AnyFunction = (...args: unknown[]) => unknown;
1021
+ type AISDKFunction = (...args: never[]) => unknown;
1021
1022
  type AIModule = {
1022
- generateText?: AnyFunction;
1023
- streamText?: AnyFunction;
1024
- generateObject?: AnyFunction;
1025
- streamObject?: AnyFunction;
1026
- experimental_generateText?: AnyFunction;
1027
- experimental_streamText?: AnyFunction;
1028
- experimental_generateObject?: AnyFunction;
1029
- experimental_streamObject?: AnyFunction;
1023
+ generateText?: AISDKFunction;
1024
+ streamText?: AISDKFunction;
1025
+ generateObject?: AISDKFunction;
1026
+ streamObject?: AISDKFunction;
1027
+ experimental_generateText?: AISDKFunction;
1028
+ experimental_streamText?: AISDKFunction;
1029
+ experimental_generateObject?: AISDKFunction;
1030
+ experimental_streamObject?: AISDKFunction;
1031
+ };
1032
+ type WrappedFunction<T, Stable extends PropertyKey, Experimental extends PropertyKey, Fallback> = T extends Record<Stable, infer F extends AISDKFunction> ? F : T extends Record<Experimental, infer F extends AISDKFunction> ? F : Fallback;
1033
+ type WrappedAISDK<T extends AIModule> = {
1034
+ generateText: WrappedFunction<T, 'generateText', 'experimental_generateText', ReturnType<typeof wrapGenerateText>>;
1035
+ streamText: WrappedFunction<T, 'streamText', 'experimental_streamText', ReturnType<typeof wrapStreamText>>;
1036
+ generateObject: WrappedFunction<T, 'generateObject', 'experimental_generateObject', ReturnType<typeof wrapGenerateObject>>;
1037
+ streamObject: WrappedFunction<T, 'streamObject', 'experimental_streamObject', ReturnType<typeof wrapStreamObject>>;
1038
+ };
1039
+ type WrapAISDKOptions = {
1040
+ client?: SentrialClient;
1041
+ defaultAgent?: string;
1042
+ userId?: StringOrFn;
1043
+ convoId?: StringOrFn;
1044
+ /** Session metadata, including explicit signalActionId / signalWorkflow when known.
1045
+ * Create a separate wrapper for each business action; no identity is inferred. */
1046
+ metadata?: Record<string, unknown>;
1030
1047
  };
1031
1048
  type GenerateTextParams = {
1032
1049
  model: {
@@ -1131,6 +1148,7 @@ type WrapperConfig = {
1131
1148
  defaultAgent?: string;
1132
1149
  userId?: StringOrFn;
1133
1150
  convoId?: StringOrFn;
1151
+ metadata?: Record<string, unknown>;
1134
1152
  };
1135
1153
  /**
1136
1154
  * Configure the Sentrial SDK for Vercel AI SDK integration.
@@ -1182,17 +1200,7 @@ declare function wrapStreamObject(originalFn: AnyFunction, client: SentrialClien
1182
1200
  * const { generateText } = wrapAISDK(ai, { client, defaultAgent: 'my-agent' });
1183
1201
  * ```
1184
1202
  */
1185
- declare function wrapAISDK(ai: AIModule, options?: {
1186
- client?: SentrialClient;
1187
- defaultAgent?: string;
1188
- userId?: StringOrFn;
1189
- convoId?: StringOrFn;
1190
- }): {
1191
- generateText: ReturnType<typeof wrapGenerateText>;
1192
- streamText: ReturnType<typeof wrapStreamText>;
1193
- generateObject: ReturnType<typeof wrapGenerateObject>;
1194
- streamObject: ReturnType<typeof wrapStreamObject>;
1195
- };
1203
+ declare function wrapAISDK<T extends AIModule>(ai: T, options?: WrapAISDKOptions): WrappedAISDK<T>;
1196
1204
 
1197
1205
  /**
1198
1206
  * Options shape accepted by {@link getVariantForAISDK} — a permissive subset of
package/dist/index.js CHANGED
@@ -319,7 +319,7 @@ function createContextVar(defaultValue) {
319
319
 
320
320
  // src/pricing.json
321
321
  var pricing_default = {
322
- _comment: "Canonical LLM pricing table, per 1,000,000 tokens (USD). Single source of truth for @sentrial/sdk (src/cost.ts imports this file directly) and the Python sentrial SDK (sentrial/pricing.py holds a per-1K mirror guarded by tests/test_pricing_sync.py). Update prices HERE; the Python drift test fails CI if the mirror falls out of sync. Updated Jan 2026.",
322
+ _comment: "Canonical LLM pricing table, per 1,000,000 tokens (USD). Single source of truth for @sentrial/sdk (src/cost.ts imports this file directly) and the Python sentrial SDK (sentrial/pricing.py holds a per-1K mirror guarded by tests/test_pricing_sync.py). Update prices HERE; the Python drift test fails CI if the mirror falls out of sync. Base table Jan 2026; Claude 4.5 canonical model IDs and standard first-party rates verified Nov 1, 2026 at https://platform.claude.com/docs/en/about-claude/pricing. Estimates exclude batch and regional adjustments.",
323
323
  openai: {
324
324
  "gpt-5.2": {
325
325
  input: 5,
@@ -391,6 +391,18 @@ var pricing_default = {
391
391
  }
392
392
  },
393
393
  anthropic: {
394
+ "claude-haiku-4-5": {
395
+ input: 1,
396
+ output: 5
397
+ },
398
+ "claude-sonnet-4-5": {
399
+ input: 3,
400
+ output: 15
401
+ },
402
+ "claude-opus-4-5": {
403
+ input: 5,
404
+ output: 25
405
+ },
394
406
  "claude-opus-4": {
395
407
  input: 15,
396
408
  output: 75
@@ -2596,7 +2608,7 @@ function buildTrace(spans, resourceAttrs) {
2596
2608
  }
2597
2609
 
2598
2610
  // package.json
2599
- var version = "0.5.0";
2611
+ var version = "0.6.0";
2600
2612
 
2601
2613
  // src/evict.ts
2602
2614
  function evictStaleEntries(map, opts) {
@@ -4340,6 +4352,13 @@ function safeStringify2(value) {
4340
4352
  return safeString3(value);
4341
4353
  }
4342
4354
  }
4355
+ function copyWrapperMetadata(value) {
4356
+ try {
4357
+ return { ...value };
4358
+ } catch {
4359
+ return { _unserializable: true };
4360
+ }
4361
+ }
4343
4362
  var _defaultClient2 = null;
4344
4363
  var _globalConfig = {};
4345
4364
  function configureVercel(config) {
@@ -4507,6 +4526,7 @@ function wrapGenerateText(originalFn, client, config) {
4507
4526
  userId: resolveStringOrFn(config.userId, "anonymous"),
4508
4527
  convoId: resolveStringOrFn(config.convoId),
4509
4528
  metadata: {
4529
+ ...config.metadata,
4510
4530
  model: modelId,
4511
4531
  provider,
4512
4532
  function: "generateText",
@@ -4629,6 +4649,7 @@ function wrapStreamText(originalFn, client, config) {
4629
4649
  userId: resolveStringOrFn(config.userId, "anonymous"),
4630
4650
  convoId: resolveStringOrFn(config.convoId),
4631
4651
  metadata: {
4652
+ ...config.metadata,
4632
4653
  model: modelId,
4633
4654
  provider,
4634
4655
  function: "streamText"
@@ -4822,6 +4843,7 @@ function wrapGenerateObject(originalFn, client, config) {
4822
4843
  userId: resolveStringOrFn(config.userId, "anonymous"),
4823
4844
  convoId: resolveStringOrFn(config.convoId),
4824
4845
  metadata: {
4846
+ ...config.metadata,
4825
4847
  model: modelId,
4826
4848
  provider,
4827
4849
  function: "generateObject"
@@ -4897,6 +4919,7 @@ function wrapStreamObject(originalFn, client, config) {
4897
4919
  userId: resolveStringOrFn(config.userId, "anonymous"),
4898
4920
  convoId: resolveStringOrFn(config.convoId),
4899
4921
  metadata: {
4922
+ ...config.metadata,
4900
4923
  model: modelId,
4901
4924
  provider,
4902
4925
  function: "streamObject"
@@ -5049,7 +5072,8 @@ function wrapAISDK(ai, options) {
5049
5072
  const config = {
5050
5073
  defaultAgent: options?.defaultAgent ?? _globalConfig.defaultAgent,
5051
5074
  userId: options?.userId ?? _globalConfig.userId,
5052
- convoId: options?.convoId ?? _globalConfig.convoId
5075
+ convoId: options?.convoId ?? _globalConfig.convoId,
5076
+ metadata: copyWrapperMetadata(options?.metadata)
5053
5077
  };
5054
5078
  const generateTextFn = ai.generateText ?? ai.experimental_generateText;
5055
5079
  const streamTextFn = ai.streamText ?? ai.experimental_streamText;