@synova-cloud/sdk 1.7.0 → 1.9.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.js CHANGED
@@ -105,7 +105,7 @@ var ValidationSynovaError = class extends SynovaError {
105
105
  };
106
106
 
107
107
  // src/version.ts
108
- var SDK_VERSION = "1.7.0" ;
108
+ var SDK_VERSION = "1.9.0" ;
109
109
 
110
110
  // src/utils/http.ts
111
111
  var HttpClient = class {
@@ -340,7 +340,9 @@ var SCHEMA_METADATA_KEYS = {
340
340
  // Array constraints
341
341
  MIN_ITEMS: "synova:schema:minItems",
342
342
  MAX_ITEMS: "synova:schema:maxItems",
343
- UNIQUE_ITEMS: "synova:schema:uniqueItems"
343
+ UNIQUE_ITEMS: "synova:schema:uniqueItems",
344
+ // Object constraints
345
+ ADDITIONAL_PROPERTIES: "synova:schema:additionalProperties"
344
346
  };
345
347
  function createMetadataDecorator(key, value) {
346
348
  return function(target, propertyKey) {
@@ -731,6 +733,12 @@ var ClassSchema = class {
731
733
  propertyName
732
734
  );
733
735
  if (uniqueItems) schema.uniqueItems = uniqueItems;
736
+ const additionalProperties = getSchemaMetadata(
737
+ SCHEMA_METADATA_KEYS.ADDITIONAL_PROPERTIES,
738
+ prototype,
739
+ propertyName
740
+ );
741
+ if (additionalProperties !== void 0) schema.additionalProperties = additionalProperties;
734
742
  }
735
743
  /**
736
744
  * Get required properties (properties without @IsOptional)
@@ -818,6 +826,7 @@ var PromptsResource = class {
818
826
  if (options.metadata !== void 0) body.metadata = options.metadata;
819
827
  if (options.parameters !== void 0) body.parameters = options.parameters;
820
828
  if (options.responseSchema !== void 0) body.responseSchema = options.responseSchema;
829
+ if (options.sessionId !== void 0) body.sessionId = options.sessionId;
821
830
  const response = await this.http.request({
822
831
  method: "POST",
823
832
  path: `/api/v1/prompts/${promptId}/run`,
@@ -1002,6 +1011,137 @@ var FilesResource = class {
1002
1011
  }
1003
1012
  };
1004
1013
 
1014
+ // src/resources/spans.ts
1015
+ var SpansResource = class {
1016
+ constructor(http) {
1017
+ this.http = http;
1018
+ }
1019
+ /**
1020
+ * Create a new span within a trace
1021
+ *
1022
+ * @param traceId - The trace ID to create span in
1023
+ * @param options - Span creation options
1024
+ * @returns Created span
1025
+ */
1026
+ async create(traceId, options) {
1027
+ const body = {
1028
+ type: options.type
1029
+ };
1030
+ if (options.parentSpanId !== void 0) body.parentSpanId = options.parentSpanId;
1031
+ if (options.name !== void 0) body.name = options.name;
1032
+ if (options.input !== void 0) body.input = options.input;
1033
+ if (options.toolName !== void 0) body.toolName = options.toolName;
1034
+ if (options.toolArguments !== void 0) body.toolArguments = options.toolArguments;
1035
+ if (options.metadata !== void 0) body.metadata = options.metadata;
1036
+ return this.http.request({
1037
+ method: "POST",
1038
+ path: `/api/v1/traces/${traceId}/spans`,
1039
+ body
1040
+ });
1041
+ }
1042
+ /**
1043
+ * End/complete a span
1044
+ *
1045
+ * @param spanId - The span ID to end
1046
+ * @param options - Span end options
1047
+ * @returns Updated span
1048
+ */
1049
+ async end(spanId, options) {
1050
+ const body = {};
1051
+ if (options?.status !== void 0) body.status = options.status;
1052
+ if (options?.level !== void 0) body.level = options.level;
1053
+ if (options?.statusMessage !== void 0) body.statusMessage = options.statusMessage;
1054
+ if (options?.output !== void 0) body.output = options.output;
1055
+ if (options?.toolResult !== void 0) body.toolResult = options.toolResult;
1056
+ if (options?.durationMs !== void 0) body.durationMs = options.durationMs;
1057
+ return this.http.request({
1058
+ method: "PATCH",
1059
+ path: `/api/v1/spans/${spanId}`,
1060
+ body
1061
+ });
1062
+ }
1063
+ /**
1064
+ * Wrap an async function with automatic span tracking
1065
+ *
1066
+ * @param options - Span options (traceId, type, name, etc.)
1067
+ * @param input - Input data to record in span
1068
+ * @param fn - Async function to execute
1069
+ * @returns Result of the function
1070
+ *
1071
+ * @example
1072
+ * ```ts
1073
+ * const result = await client.spans.wrap(
1074
+ * { traceId: 'trc_123', type: 'retriever', name: 'vector_search' },
1075
+ * { query: 'how to...', topK: 5 },
1076
+ * async () => vectorDb.search(query),
1077
+ * );
1078
+ * ```
1079
+ */
1080
+ async wrap(options, input, fn) {
1081
+ const span = await this.create(options.traceId, {
1082
+ type: options.type,
1083
+ name: options.name,
1084
+ parentSpanId: options.parentSpanId,
1085
+ input,
1086
+ metadata: options.metadata
1087
+ });
1088
+ try {
1089
+ const result = await fn();
1090
+ await this.end(span.id, {
1091
+ status: "completed",
1092
+ output: result
1093
+ });
1094
+ return result;
1095
+ } catch (error) {
1096
+ await this.end(span.id, {
1097
+ status: "error",
1098
+ statusMessage: error instanceof Error ? error.message : String(error)
1099
+ });
1100
+ throw error;
1101
+ }
1102
+ }
1103
+ /**
1104
+ * Wrap a tool function with automatic span tracking
1105
+ *
1106
+ * @param options - Tool span options (traceId, toolName, etc.)
1107
+ * @param args - Tool arguments to record
1108
+ * @param fn - Tool function to execute
1109
+ * @returns Result of the tool
1110
+ *
1111
+ * @example
1112
+ * ```ts
1113
+ * const weather = await client.spans.wrapTool(
1114
+ * { traceId: 'trc_123', toolName: 'fetch_weather', parentSpanId: 'spn_abc' },
1115
+ * { city: 'NYC' },
1116
+ * async (args) => fetchWeather(args.city),
1117
+ * );
1118
+ * ```
1119
+ */
1120
+ async wrapTool(options, args, fn) {
1121
+ const span = await this.create(options.traceId, {
1122
+ type: "tool",
1123
+ toolName: options.toolName,
1124
+ toolArguments: args,
1125
+ parentSpanId: options.parentSpanId,
1126
+ metadata: options.metadata
1127
+ });
1128
+ try {
1129
+ const result = await fn(args);
1130
+ await this.end(span.id, {
1131
+ status: "completed",
1132
+ toolResult: result
1133
+ });
1134
+ return result;
1135
+ } catch (error) {
1136
+ await this.end(span.id, {
1137
+ status: "error",
1138
+ statusMessage: error instanceof Error ? error.message : String(error)
1139
+ });
1140
+ throw error;
1141
+ }
1142
+ }
1143
+ };
1144
+
1005
1145
  // src/client.ts
1006
1146
  var DEFAULT_BASE_URL = "https://api.synova.cloud";
1007
1147
  var DEFAULT_TIMEOUT = 3e4;
@@ -1022,6 +1162,7 @@ var SynovaCloudSdk = class {
1022
1162
  prompts;
1023
1163
  models;
1024
1164
  files;
1165
+ spans;
1025
1166
  http;
1026
1167
  /**
1027
1168
  * Create a new Synova Cloud SDK client
@@ -1050,6 +1191,7 @@ var SynovaCloudSdk = class {
1050
1191
  this.prompts = new PromptsResource(this.http);
1051
1192
  this.models = new ModelsResource(this.http);
1052
1193
  this.files = new FilesResource(this.http);
1194
+ this.spans = new SpansResource(this.http);
1053
1195
  }
1054
1196
  };
1055
1197