@superlinked/sie-sdk 0.6.22 → 0.6.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.cts CHANGED
@@ -879,10 +879,38 @@ interface GenerationUsage {
879
879
  completionTokens: number;
880
880
  totalTokens: number;
881
881
  }
882
+ interface GrammarMetadata {
883
+ /** Optional schema/grammar label used by structured-output backends. */
884
+ label?: string | null;
885
+ /** Optional strictness hint for structured-output backends. */
886
+ strict?: boolean | null;
887
+ }
888
+ /** Constrain native generation to a JSON Schema. */
889
+ type JsonSchemaGrammar = GrammarMetadata & {
890
+ json_schema: Record<string, unknown>;
891
+ regex?: never;
892
+ ebnf?: never;
893
+ };
894
+ /** Constrain native generation to a regular expression. */
895
+ type RegexGrammar = GrammarMetadata & {
896
+ json_schema?: never;
897
+ regex: string;
898
+ ebnf?: never;
899
+ };
900
+ /** Constrain native generation to an EBNF grammar. */
901
+ type EbnfGrammar = GrammarMetadata & {
902
+ json_schema?: never;
903
+ regex?: never;
904
+ ebnf: string;
905
+ };
906
+ /** Native structured-output grammar. Exactly one grammar variant is set. */
907
+ type GenerateGrammar = JsonSchemaGrammar | RegexGrammar | EbnfGrammar;
882
908
  /** Options for the generate operation. */
883
909
  interface GenerateOptions {
884
910
  /** Hard cap on output tokens. Required. */
885
911
  maxNewTokens: number;
912
+ /** Optional native image inputs rendered with the prompt for vision-capable models. */
913
+ images?: (ImageInput | ImageWireFormat)[];
886
914
  /** Sampling temperature. */
887
915
  temperature?: number;
888
916
  /** Nucleus sampling cutoff. */
@@ -893,8 +921,14 @@ interface GenerateOptions {
893
921
  frequencyPenalty?: number;
894
922
  /** OpenAI-compatible presence penalty in [-2, 2]. */
895
923
  presencePenalty?: number;
896
- /** Native structured-output grammar. */
897
- grammar?: Record<string, unknown>;
924
+ /**
925
+ * Native structured-output grammar.
926
+ *
927
+ * The broad record arm preserves the pre-existing SDK input contract for
928
+ * callers that keep valid grammar objects in `Record<string, unknown>`
929
+ * variables. The SDK still validates the exact three-arm shape at runtime.
930
+ */
931
+ grammar?: GenerateGrammar | Record<string, unknown>;
898
932
  /**
899
933
  * Optional per-request sampling seed. Must be a JavaScript safe integer
900
934
  * (-(2^53 - 1) through 2^53 - 1) so JSON serialization preserves it exactly.
@@ -1887,7 +1921,7 @@ declare class SIEClient {
1887
1921
  private detectEndpointType;
1888
1922
  }
1889
1923
 
1890
- declare const SDK_VERSION = "0.6.22";
1924
+ declare const SDK_VERSION = "0.6.24";
1891
1925
 
1892
1926
  /**
1893
1927
  * Helpers for converting SIE encode results to plain JavaScript types.
@@ -2232,4 +2266,4 @@ declare function packMessage(data: unknown): Uint8Array;
2232
2266
  */
2233
2267
  declare function unpackMessage<T = unknown>(data: Uint8Array): T;
2234
2268
 
2235
- export { type AudioInput, type Batch, type BatchList, type BatchRequestCounts, type BatchesNamespace, type CapacityInfo, type ChatChoice, type ChatChunkChoice, type ChatCompletion, type ChatCompletionChunk, type ChatCompletionRequest, type ChatDelta, type ChatFinishReason, type ChatMessage, type ChatUsage, type Classification, type ClusterStatusMessage, type ClusterSummary, type ClusterWorkerInfo, type Connection, type ConnectionCreated, type ConnectionRevoked, type ConnectionsNamespace, type CreatePoolOptions, type DType, type DetectedObject, type EncodeOptions, type EncodeResult, type Entity, type ExtractItem, type ExtractItemError, type ExtractOptions, type ExtractResult, type FileDeleted, type FileUploadInput, type FilesNamespace, type FinishReason, type GPUMetrics, type GenerateChunk, type GenerateOptions, type GenerateResult, type GenerationUsage, type ImageInput, type ImageWireFormat, InputTooLongError, type Item, type JobChunk, type JobFieldMap, type JobItem, type JobPreflight, type JobResultItem, type JobResults, type JobSource, type JobState, type JobStatus, type JobSubmitResult, type JobsNamespace, LoraLoadingError, type ModelCapabilities, type ModelConfig, type ModelDims, type ModelInfo, ModelLoadFailedError, ModelLoadingError, type ModelState, type ModelStatus, type ModelSummary, type OutputType, PoolError, type PoolInfo, type PoolSpec, type PoolStatus, ProvisioningError, type Relation, RequestError, ResourceExhaustedError, type ResponseFormat, SDK_VERSION, SIEClient, type SIEClientOptions, SIEConnectionError, SIEError, type File as SIEFile, SIEStreamError, type ScoreEntry, type ScoreOptions, type ScoreResult, type ScoreUsage, ServerError, type ServerInfo, type SparseResult, type SparseVector, type StatusMessage, type StreamGenerateOptions, type SubmitJobOptions, TERMINAL_JOB_STATES, type TimingInfo, type ToolCall, type ToolCallDelta, type ToolChoice, type ToolSpec, type WorkerInfo, type WorkerStatusMessage, buildJobBody, connectionName, denseEmbedding, detectImageFormat, multivectorEmbedding, normalizeSparseVector, packMessage, sparseEmbedding, sparseEmbeddingMap, toFloat32Array, toImageBytes, toImageWireFormat, toNumberArray, unpackMessage };
2269
+ export { type AudioInput, type Batch, type BatchList, type BatchRequestCounts, type BatchesNamespace, type CapacityInfo, type ChatChoice, type ChatChunkChoice, type ChatCompletion, type ChatCompletionChunk, type ChatCompletionRequest, type ChatDelta, type ChatFinishReason, type ChatMessage, type ChatUsage, type Classification, type ClusterStatusMessage, type ClusterSummary, type ClusterWorkerInfo, type Connection, type ConnectionCreated, type ConnectionRevoked, type ConnectionsNamespace, type CreatePoolOptions, type DType, type DetectedObject, type EbnfGrammar, type EncodeOptions, type EncodeResult, type Entity, type ExtractItem, type ExtractItemError, type ExtractOptions, type ExtractResult, type FileDeleted, type FileUploadInput, type FilesNamespace, type FinishReason, type GPUMetrics, type GenerateChunk, type GenerateGrammar, type GenerateOptions, type GenerateResult, type GenerationUsage, type ImageInput, type ImageWireFormat, InputTooLongError, type Item, type JobChunk, type JobFieldMap, type JobItem, type JobPreflight, type JobResultItem, type JobResults, type JobSource, type JobState, type JobStatus, type JobSubmitResult, type JobsNamespace, type JsonSchemaGrammar, LoraLoadingError, type ModelCapabilities, type ModelConfig, type ModelDims, type ModelInfo, ModelLoadFailedError, ModelLoadingError, type ModelState, type ModelStatus, type ModelSummary, type OutputType, PoolError, type PoolInfo, type PoolSpec, type PoolStatus, ProvisioningError, type RegexGrammar, type Relation, RequestError, ResourceExhaustedError, type ResponseFormat, SDK_VERSION, SIEClient, type SIEClientOptions, SIEConnectionError, SIEError, type File as SIEFile, SIEStreamError, type ScoreEntry, type ScoreOptions, type ScoreResult, type ScoreUsage, ServerError, type ServerInfo, type SparseResult, type SparseVector, type StatusMessage, type StreamGenerateOptions, type SubmitJobOptions, TERMINAL_JOB_STATES, type TimingInfo, type ToolCall, type ToolCallDelta, type ToolChoice, type ToolSpec, type WorkerInfo, type WorkerStatusMessage, buildJobBody, connectionName, denseEmbedding, detectImageFormat, multivectorEmbedding, normalizeSparseVector, packMessage, sparseEmbedding, sparseEmbeddingMap, toFloat32Array, toImageBytes, toImageWireFormat, toNumberArray, unpackMessage };
package/dist/index.d.ts CHANGED
@@ -879,10 +879,38 @@ interface GenerationUsage {
879
879
  completionTokens: number;
880
880
  totalTokens: number;
881
881
  }
882
+ interface GrammarMetadata {
883
+ /** Optional schema/grammar label used by structured-output backends. */
884
+ label?: string | null;
885
+ /** Optional strictness hint for structured-output backends. */
886
+ strict?: boolean | null;
887
+ }
888
+ /** Constrain native generation to a JSON Schema. */
889
+ type JsonSchemaGrammar = GrammarMetadata & {
890
+ json_schema: Record<string, unknown>;
891
+ regex?: never;
892
+ ebnf?: never;
893
+ };
894
+ /** Constrain native generation to a regular expression. */
895
+ type RegexGrammar = GrammarMetadata & {
896
+ json_schema?: never;
897
+ regex: string;
898
+ ebnf?: never;
899
+ };
900
+ /** Constrain native generation to an EBNF grammar. */
901
+ type EbnfGrammar = GrammarMetadata & {
902
+ json_schema?: never;
903
+ regex?: never;
904
+ ebnf: string;
905
+ };
906
+ /** Native structured-output grammar. Exactly one grammar variant is set. */
907
+ type GenerateGrammar = JsonSchemaGrammar | RegexGrammar | EbnfGrammar;
882
908
  /** Options for the generate operation. */
883
909
  interface GenerateOptions {
884
910
  /** Hard cap on output tokens. Required. */
885
911
  maxNewTokens: number;
912
+ /** Optional native image inputs rendered with the prompt for vision-capable models. */
913
+ images?: (ImageInput | ImageWireFormat)[];
886
914
  /** Sampling temperature. */
887
915
  temperature?: number;
888
916
  /** Nucleus sampling cutoff. */
@@ -893,8 +921,14 @@ interface GenerateOptions {
893
921
  frequencyPenalty?: number;
894
922
  /** OpenAI-compatible presence penalty in [-2, 2]. */
895
923
  presencePenalty?: number;
896
- /** Native structured-output grammar. */
897
- grammar?: Record<string, unknown>;
924
+ /**
925
+ * Native structured-output grammar.
926
+ *
927
+ * The broad record arm preserves the pre-existing SDK input contract for
928
+ * callers that keep valid grammar objects in `Record<string, unknown>`
929
+ * variables. The SDK still validates the exact three-arm shape at runtime.
930
+ */
931
+ grammar?: GenerateGrammar | Record<string, unknown>;
898
932
  /**
899
933
  * Optional per-request sampling seed. Must be a JavaScript safe integer
900
934
  * (-(2^53 - 1) through 2^53 - 1) so JSON serialization preserves it exactly.
@@ -1887,7 +1921,7 @@ declare class SIEClient {
1887
1921
  private detectEndpointType;
1888
1922
  }
1889
1923
 
1890
- declare const SDK_VERSION = "0.6.22";
1924
+ declare const SDK_VERSION = "0.6.24";
1891
1925
 
1892
1926
  /**
1893
1927
  * Helpers for converting SIE encode results to plain JavaScript types.
@@ -2232,4 +2266,4 @@ declare function packMessage(data: unknown): Uint8Array;
2232
2266
  */
2233
2267
  declare function unpackMessage<T = unknown>(data: Uint8Array): T;
2234
2268
 
2235
- export { type AudioInput, type Batch, type BatchList, type BatchRequestCounts, type BatchesNamespace, type CapacityInfo, type ChatChoice, type ChatChunkChoice, type ChatCompletion, type ChatCompletionChunk, type ChatCompletionRequest, type ChatDelta, type ChatFinishReason, type ChatMessage, type ChatUsage, type Classification, type ClusterStatusMessage, type ClusterSummary, type ClusterWorkerInfo, type Connection, type ConnectionCreated, type ConnectionRevoked, type ConnectionsNamespace, type CreatePoolOptions, type DType, type DetectedObject, type EncodeOptions, type EncodeResult, type Entity, type ExtractItem, type ExtractItemError, type ExtractOptions, type ExtractResult, type FileDeleted, type FileUploadInput, type FilesNamespace, type FinishReason, type GPUMetrics, type GenerateChunk, type GenerateOptions, type GenerateResult, type GenerationUsage, type ImageInput, type ImageWireFormat, InputTooLongError, type Item, type JobChunk, type JobFieldMap, type JobItem, type JobPreflight, type JobResultItem, type JobResults, type JobSource, type JobState, type JobStatus, type JobSubmitResult, type JobsNamespace, LoraLoadingError, type ModelCapabilities, type ModelConfig, type ModelDims, type ModelInfo, ModelLoadFailedError, ModelLoadingError, type ModelState, type ModelStatus, type ModelSummary, type OutputType, PoolError, type PoolInfo, type PoolSpec, type PoolStatus, ProvisioningError, type Relation, RequestError, ResourceExhaustedError, type ResponseFormat, SDK_VERSION, SIEClient, type SIEClientOptions, SIEConnectionError, SIEError, type File as SIEFile, SIEStreamError, type ScoreEntry, type ScoreOptions, type ScoreResult, type ScoreUsage, ServerError, type ServerInfo, type SparseResult, type SparseVector, type StatusMessage, type StreamGenerateOptions, type SubmitJobOptions, TERMINAL_JOB_STATES, type TimingInfo, type ToolCall, type ToolCallDelta, type ToolChoice, type ToolSpec, type WorkerInfo, type WorkerStatusMessage, buildJobBody, connectionName, denseEmbedding, detectImageFormat, multivectorEmbedding, normalizeSparseVector, packMessage, sparseEmbedding, sparseEmbeddingMap, toFloat32Array, toImageBytes, toImageWireFormat, toNumberArray, unpackMessage };
2269
+ export { type AudioInput, type Batch, type BatchList, type BatchRequestCounts, type BatchesNamespace, type CapacityInfo, type ChatChoice, type ChatChunkChoice, type ChatCompletion, type ChatCompletionChunk, type ChatCompletionRequest, type ChatDelta, type ChatFinishReason, type ChatMessage, type ChatUsage, type Classification, type ClusterStatusMessage, type ClusterSummary, type ClusterWorkerInfo, type Connection, type ConnectionCreated, type ConnectionRevoked, type ConnectionsNamespace, type CreatePoolOptions, type DType, type DetectedObject, type EbnfGrammar, type EncodeOptions, type EncodeResult, type Entity, type ExtractItem, type ExtractItemError, type ExtractOptions, type ExtractResult, type FileDeleted, type FileUploadInput, type FilesNamespace, type FinishReason, type GPUMetrics, type GenerateChunk, type GenerateGrammar, type GenerateOptions, type GenerateResult, type GenerationUsage, type ImageInput, type ImageWireFormat, InputTooLongError, type Item, type JobChunk, type JobFieldMap, type JobItem, type JobPreflight, type JobResultItem, type JobResults, type JobSource, type JobState, type JobStatus, type JobSubmitResult, type JobsNamespace, type JsonSchemaGrammar, LoraLoadingError, type ModelCapabilities, type ModelConfig, type ModelDims, type ModelInfo, ModelLoadFailedError, ModelLoadingError, type ModelState, type ModelStatus, type ModelSummary, type OutputType, PoolError, type PoolInfo, type PoolSpec, type PoolStatus, ProvisioningError, type RegexGrammar, type Relation, RequestError, ResourceExhaustedError, type ResponseFormat, SDK_VERSION, SIEClient, type SIEClientOptions, SIEConnectionError, SIEError, type File as SIEFile, SIEStreamError, type ScoreEntry, type ScoreOptions, type ScoreResult, type ScoreUsage, ServerError, type ServerInfo, type SparseResult, type SparseVector, type StatusMessage, type StreamGenerateOptions, type SubmitJobOptions, TERMINAL_JOB_STATES, type TimingInfo, type ToolCall, type ToolCallDelta, type ToolChoice, type ToolSpec, type WorkerInfo, type WorkerStatusMessage, buildJobBody, connectionName, denseEmbedding, detectImageFormat, multivectorEmbedding, normalizeSparseVector, packMessage, sparseEmbedding, sparseEmbeddingMap, toFloat32Array, toImageBytes, toImageWireFormat, toNumberArray, unpackMessage };
package/dist/index.js CHANGED
@@ -1189,7 +1189,7 @@ function extractDataPayload(block) {
1189
1189
  }
1190
1190
 
1191
1191
  // src/version.ts
1192
- var SDK_VERSION = "0.6.22";
1192
+ var SDK_VERSION = "0.6.24";
1193
1193
 
1194
1194
  // src/client.ts
1195
1195
  function sleep2(ms) {
@@ -1243,6 +1243,33 @@ function validateGenerationSeed(seed) {
1243
1243
  }
1244
1244
  return seed;
1245
1245
  }
1246
+ function validateGenerateGrammar(grammar) {
1247
+ if (typeof grammar !== "object" || grammar === null || Array.isArray(grammar)) {
1248
+ throw new TypeError("grammar must be an object");
1249
+ }
1250
+ const allowed = /* @__PURE__ */ new Set(["json_schema", "regex", "ebnf", "label", "strict"]);
1251
+ const unknown = Object.keys(grammar).filter((key) => !allowed.has(key));
1252
+ if (unknown.length > 0) {
1253
+ throw new TypeError(`grammar contains unsupported field(s): ${unknown.sort().join(", ")}`);
1254
+ }
1255
+ const variants = ["json_schema", "regex", "ebnf"].filter((key) => Object.hasOwn(grammar, key));
1256
+ if (variants.length !== 1) {
1257
+ throw new TypeError("grammar must contain exactly one of json_schema, regex, or ebnf");
1258
+ }
1259
+ const variant = variants[0];
1260
+ const value = grammar[variant];
1261
+ if (variant === "json_schema" ? typeof value !== "object" || value === null || Array.isArray(value) : typeof value !== "string") {
1262
+ throw new TypeError(
1263
+ variant === "json_schema" ? "grammar.json_schema must be an object" : `grammar.${variant} must be a string`
1264
+ );
1265
+ }
1266
+ if (grammar.label !== void 0 && grammar.label !== null && typeof grammar.label !== "string") {
1267
+ throw new TypeError("grammar.label must be a string");
1268
+ }
1269
+ if (grammar.strict !== void 0 && grammar.strict !== null && typeof grammar.strict !== "boolean") {
1270
+ throw new TypeError("grammar.strict must be a boolean");
1271
+ }
1272
+ }
1246
1273
  function applyGenerateOptions(body, options) {
1247
1274
  if (options.temperature !== void 0) body.temperature = options.temperature;
1248
1275
  if (options.topP !== void 0) body.top_p = options.topP;
@@ -1250,7 +1277,10 @@ function applyGenerateOptions(body, options) {
1250
1277
  if (options.stop !== void 0) body.stop = options.stop;
1251
1278
  if (options.frequencyPenalty !== void 0) body.frequency_penalty = options.frequencyPenalty;
1252
1279
  if (options.presencePenalty !== void 0) body.presence_penalty = options.presencePenalty;
1253
- if (options.grammar !== void 0) body.grammar = options.grammar;
1280
+ if (options.grammar !== void 0) {
1281
+ validateGenerateGrammar(options.grammar);
1282
+ body.grammar = options.grammar;
1283
+ }
1254
1284
  if (options.seed !== void 0) body.seed = validateGenerationSeed(options.seed);
1255
1285
  if (options.logitBias !== void 0) body.logit_bias = options.logitBias;
1256
1286
  if (options.routingKey !== void 0) body.routing_key = options.routingKey;
@@ -1290,6 +1320,25 @@ async function imageForWire(image) {
1290
1320
  }
1291
1321
  return toImageWireFormat(image);
1292
1322
  }
1323
+ function imageBytesToBase64(data) {
1324
+ if (typeof Buffer !== "undefined") {
1325
+ return Buffer.from(data.buffer, data.byteOffset, data.byteLength).toString("base64");
1326
+ }
1327
+ let binary = "";
1328
+ const chunkSize = 32768;
1329
+ for (let offset = 0; offset < data.length; offset += chunkSize) {
1330
+ binary += String.fromCharCode(...data.subarray(offset, offset + chunkSize));
1331
+ }
1332
+ return btoa(binary);
1333
+ }
1334
+ async function generationImagesForWire(images) {
1335
+ return Promise.all(
1336
+ images.map(async (image) => {
1337
+ const wire = await imageForWire(image);
1338
+ return { data: imageBytesToBase64(wire.data), format: wire.format };
1339
+ })
1340
+ );
1341
+ }
1293
1342
  async function itemImagesForWire(item) {
1294
1343
  if (!item.images || item.images.length === 0) {
1295
1344
  return item;
@@ -1621,6 +1670,9 @@ var SIEClient = class {
1621
1670
  prompt,
1622
1671
  max_new_tokens: options.maxNewTokens
1623
1672
  };
1673
+ if (options.images !== void 0) {
1674
+ body.images = await generationImagesForWire(options.images);
1675
+ }
1624
1676
  applyGenerateOptions(body, options);
1625
1677
  const { pool, gpu } = this.parseGpuParam(options.gpu);
1626
1678
  const headers = {
@@ -1841,6 +1893,9 @@ var SIEClient = class {
1841
1893
  max_new_tokens: options.maxNewTokens,
1842
1894
  stream: true
1843
1895
  };
1896
+ if (options.images !== void 0) {
1897
+ body.images = await generationImagesForWire(options.images);
1898
+ }
1844
1899
  applyGenerateOptions(body, options);
1845
1900
  if (options.logprobs !== void 0) body.logprobs = options.logprobs;
1846
1901
  if (options.topLogprobs !== void 0) {