segmind 0.6.1 → 0.7.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
@@ -1,5 +1,5 @@
1
- import { S as SessionToken, a as SessionTokenProvider } from './errors-CcHEuSmR.cjs';
2
- export { A as APIConnectionError, I as InferenceFailed, b as InferenceTimeout, c as InsufficientCredits, R as RateLimited, d as SegmindError } from './errors-CcHEuSmR.cjs';
1
+ import { S as SessionToken, a as SessionTokenProvider } from './errors-DsVQfts3.cjs';
2
+ export { A as APIConnectionError, I as InferenceFailed, b as InferenceTimeout, c as InsufficientCredits, R as RateLimited, d as SegmindError } from './errors-DsVQfts3.cjs';
3
3
 
4
4
  type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
5
5
  /** Returns the signed-in user's token, or null when there is none. Called before every request. */
@@ -150,15 +150,15 @@ type ChatParams = Params & {
150
150
  messages?: ChatMessage[] | Record<string, unknown>;
151
151
  prompt?: string;
152
152
  };
153
- type Raw = Record<string, unknown>;
153
+ type Raw$1 = Record<string, unknown>;
154
154
  /**
155
155
  * One reply from any chat model. The gateway returns each provider's own JSON
156
156
  * (OpenAI, Anthropic or Gemini shape); this reads the common fields from all
157
157
  * three. `raw` is always the provider's body, untouched.
158
158
  */
159
159
  declare class ChatResponse {
160
- readonly raw: Raw;
161
- constructor(raw: Raw);
160
+ readonly raw: Raw$1;
161
+ constructor(raw: Raw$1);
162
162
  /** The assistant's text. Throws when the body holds none (inspect `raw`). */
163
163
  get text(): string;
164
164
  /** `text` parsed as JSON, for JSON mode and structured outputs. */
@@ -171,6 +171,149 @@ declare class ChatResponse {
171
171
  get toolCalls(): unknown[];
172
172
  }
173
173
 
174
+ /**
175
+ * Decision models answer typed questions about a `state` with probabilities.
176
+ * Every decision model takes the same request and returns the same answer
177
+ * shape, so one body can be sent to several models and compared.
178
+ *
179
+ * An answer is `ok` only when the model gave one. A `refused` or `error`
180
+ * answer carries no number, and the readers on `DecisionResponse` return
181
+ * `undefined` for it, never 0, so a declined question is never read as a "no".
182
+ */
183
+ /** Yes / no, answered with the probability of yes. `criteria` says what each answer means. */
184
+ interface NoulQuestion {
185
+ type: 'noul';
186
+ instructions: string;
187
+ criteria?: {
188
+ true?: string | null;
189
+ false?: string | null;
190
+ };
191
+ }
192
+ /** One of a set of options: a list of keys, or a map of key to description. */
193
+ interface ChoiceQuestion {
194
+ type: 'choice';
195
+ instructions: string;
196
+ options: string[] | Record<string, string | null>;
197
+ }
198
+ /** A level on an ordered scale: a label, or a label with a description. */
199
+ type ScoreLevel = string | {
200
+ label: string;
201
+ description?: string | null;
202
+ };
203
+ /** A point on an ordered scale. `levels` run lowest first. */
204
+ interface ScoreQuestion {
205
+ type: 'score';
206
+ instructions: string;
207
+ levels: ScoreLevel[];
208
+ }
209
+ /** Where something is in the request's image, as edges in [0, 1]. */
210
+ interface BoxQuestion {
211
+ type: 'box';
212
+ instructions: string;
213
+ }
214
+ type Question = NoulQuestion | ChoiceQuestion | ScoreQuestion | BoxQuestion;
215
+ type QuestionType = Question['type'];
216
+ /** Optional features, grouped by what they do. A model that can't honour one ignores it with a warning. */
217
+ interface DecisionOptions {
218
+ /** Reuse a prompt cache across calls that share this key. */
219
+ caching?: {
220
+ key: string;
221
+ };
222
+ /** Keep a run of related calls on the same upstream session. */
223
+ session?: {
224
+ id: string;
225
+ };
226
+ /** How the call is routed upstream. */
227
+ routing?: {
228
+ prefer?: 'latency' | 'price' | 'throughput';
229
+ zero_data_retention?: boolean;
230
+ };
231
+ }
232
+ /** A URL, data URI or base64 string, or a list of them. */
233
+ type MediaInput = string | string[];
234
+ /** A decision request. Any other key is sent to the model unchanged. */
235
+ type DecisionParams = Params & {
236
+ /** What the model judges: text, or a JSON object or array. */
237
+ state: string | Record<string, unknown> | unknown[];
238
+ /** Question key to question. Answers come back under the same keys. */
239
+ questions: Record<string, Question>;
240
+ images?: MediaInput;
241
+ audio?: MediaInput;
242
+ video?: MediaInput;
243
+ files?: MediaInput;
244
+ options?: DecisionOptions;
245
+ };
246
+ type AnswerStatus = 'ok' | 'refused' | 'error';
247
+ interface AnswerBase {
248
+ status: AnswerStatus;
249
+ confidence?: number | null;
250
+ /** Why there is no answer, when `status` is `error`. */
251
+ error?: string;
252
+ }
253
+ interface NoulAnswer extends AnswerBase {
254
+ type: 'noul';
255
+ probability?: number;
256
+ }
257
+ interface ChoiceAnswer extends AnswerBase {
258
+ type: 'choice';
259
+ choice?: string;
260
+ probabilities?: Record<string, number> | null;
261
+ }
262
+ interface ScoreAnswer extends AnswerBase {
263
+ type: 'score';
264
+ /** The expected level index: 0 is the lowest level. */
265
+ score?: number;
266
+ probabilities?: number[] | null;
267
+ labels?: string[];
268
+ }
269
+ interface BoxEdges {
270
+ top: number;
271
+ bottom: number;
272
+ left: number;
273
+ right: number;
274
+ }
275
+ interface BoxAnswer extends AnswerBase {
276
+ type: 'box';
277
+ box?: BoxEdges;
278
+ }
279
+ type DecisionAnswer = NoulAnswer | ChoiceAnswer | ScoreAnswer | BoxAnswer;
280
+ interface DecisionUsage {
281
+ input_tokens: number;
282
+ cached_tokens: number;
283
+ cache_write_tokens: number;
284
+ }
285
+ type Raw = Record<string, unknown>;
286
+ /** One decision model's reply. */
287
+ declare class DecisionResponse {
288
+ /** The decision model that answered. */
289
+ readonly model: string;
290
+ /** Question key to its normalised answer. */
291
+ readonly answers: Record<string, DecisionAnswer>;
292
+ /** The vendor's own answer, for anything the normalised shape leaves out. */
293
+ readonly raw: unknown;
294
+ readonly usage: DecisionUsage | undefined;
295
+ /** What the call was charged. */
296
+ readonly cost: number | undefined;
297
+ /** The model's own time, measured inside the gateway. */
298
+ readonly latencyMs: number | undefined;
299
+ readonly warnings: string[];
300
+ constructor(body: Raw);
301
+ /** The full answer for `key`, whatever its status. Throws for a key no question used. */
302
+ answer(key: string): DecisionAnswer;
303
+ /** `ok`, `refused` or `error`. */
304
+ status(key: string): AnswerStatus;
305
+ /** A yes/no question's probability of yes; undefined unless the model answered. */
306
+ probability(key: string): number | undefined;
307
+ /** A choice question's picked option; undefined unless the model answered. */
308
+ choice(key: string): string | undefined;
309
+ /** A score question's expected level index (0 = lowest); undefined unless answered. */
310
+ score(key: string): number | undefined;
311
+ /** A box question's edges; undefined unless the model answered. */
312
+ box(key: string): BoxEdges | undefined;
313
+ /** A field of an `ok` answer of `type`. A refused or errored answer has none. */
314
+ private read;
315
+ }
316
+
174
317
  /** A file to send: a path (Node only), a `Blob` or `File`, or raw bytes. */
175
318
  type FileInput = string | Blob | ArrayBuffer | Uint8Array;
176
319
 
@@ -664,6 +807,16 @@ declare class Segmind {
664
807
  chatSync(slug: string, params: ChatParams, options?: CallOptions): Promise<ChatResponse>;
665
808
  /** Submits a chat to the v2 queue and returns a `Job` whose result is a `ChatResponse`. */
666
809
  submitChat(slug: string, params: ChatParams, options?: SubmitOptions): Promise<Job<ChatResponse>>;
810
+ /**
811
+ * Ask a decision model typed questions through the v2 queue. Pass `state`
812
+ * and `questions` (see `question` for the builders); the reply carries
813
+ * probabilities, the amount charged and the model's latency.
814
+ */
815
+ decide(slug: string, params: DecisionParams, options?: RunOptions): Promise<DecisionResponse>;
816
+ /** Ask a decision model with one blocking `POST /v1/{slug}`, which suits a model that answers in about a second. */
817
+ decideSync(slug: string, params: DecisionParams, options?: CallOptions): Promise<DecisionResponse>;
818
+ /** Submits a decision to the v2 queue and returns a `Job` whose result is a `DecisionResponse`. */
819
+ submitDecision(slug: string, params: DecisionParams, options?: SubmitOptions): Promise<Job<DecisionResponse>>;
667
820
  private submitJob;
668
821
  }
669
822
  type ModelInput = 'text' | 'image' | 'video' | 'audio';
@@ -793,7 +946,7 @@ declare function imageUrl(input: ImageInput, options?: {
793
946
  mimeType?: string;
794
947
  }): Promise<ImageUrlPart>;
795
948
 
796
- declare const VERSION = "0.6.1";
949
+ declare const VERSION = "0.7.0";
797
950
 
798
951
  /** `new Segmind().run(...)` with the key from `SEGMIND_API_KEY`. */
799
952
  declare const run: (slug: string, params?: Params, options?: RunOptions) => Promise<RunResult>;
@@ -809,6 +962,12 @@ declare const chat: (slug: string, params: ChatParams, options?: RunOptions) =>
809
962
  declare const chatSync: (slug: string, params: ChatParams, options?: CallOptions) => Promise<ChatResponse>;
810
963
  /** `new Segmind().submitChat(...)` with the key from `SEGMIND_API_KEY`. */
811
964
  declare const submitChat: (slug: string, params: ChatParams, options?: SubmitOptions) => Promise<Job<ChatResponse>>;
965
+ /** `new Segmind().decide(...)` with the key from `SEGMIND_API_KEY`. */
966
+ declare const decide: (slug: string, params: DecisionParams, options?: RunOptions) => Promise<DecisionResponse>;
967
+ /** `new Segmind().decideSync(...)` with the key from `SEGMIND_API_KEY`. */
968
+ declare const decideSync: (slug: string, params: DecisionParams, options?: CallOptions) => Promise<DecisionResponse>;
969
+ /** `new Segmind().submitDecision(...)` with the key from `SEGMIND_API_KEY`. */
970
+ declare const submitDecision: (slug: string, params: DecisionParams, options?: SubmitOptions) => Promise<Job<DecisionResponse>>;
812
971
  /** `new Segmind().models` with the key from `SEGMIND_API_KEY`. */
813
972
  declare const models: Pick<Models, 'list' | 'listAll'>;
814
973
  /** `new Segmind().accounts` with the key from `SEGMIND_API_KEY`. */
@@ -829,5 +988,5 @@ declare const webhooks: Pick<Webhooks, 'get' | 'add' | 'update' | 'delete' | 'lo
829
988
  /** `new Segmind().pixelflows` with the key from `SEGMIND_API_KEY`. */
830
989
  declare const pixelflows: Pick<PixelFlows, 'run' | 'submit' | 'getStatus' | 'poll'>;
831
990
 
832
- export { Accounts, ChatResponse, DEFAULT_BASE_URL, DEFAULT_CONSOLE_URL, DEFAULT_SPOT_URL, DEFAULT_WAIT_INTERVAL_MS, DEFAULT_WAIT_TIMEOUT_MS, Files, Generations, Job, Models, PixelFlows, PixelflowJob, Realtime, Segmind, SessionToken, SessionTokenProvider, VERSION, Webhooks, accounts, chat, chatSync, files, generations, imageUrl, job, models, pixelflows, run, runSync, submit, submitChat, webhooks };
833
- export type { AccountCredits, CallOptions, ChatMessage, ChatParams, ClientOptions, CreateSessionTokenOptions, FileInput, Generation, GenerationsListOptions, HistoryOptions, ImageInput, ImageUrlPart, Initiator, InitiatorOptions, JobState, JobStatus, ModelInfo, ModelInput, ModelListParams, ModelOutput, ModelSort, ModelsPage, Page, Params, PixelflowStatus, PixelflowSubmitOptions, PixelflowWaitOptions, PollInterval, RequestRecord, RunOptions, RunResult, SubmitOptions, SubmitResponse, TokenProvider, UploadOptions, UploadedFile, WaitOptions, Webhook, WebhookDelivery, WebhookEventType };
991
+ export { Accounts, ChatResponse, DEFAULT_BASE_URL, DEFAULT_CONSOLE_URL, DEFAULT_SPOT_URL, DEFAULT_WAIT_INTERVAL_MS, DEFAULT_WAIT_TIMEOUT_MS, DecisionResponse, Files, Generations, Job, Models, PixelFlows, PixelflowJob, Realtime, Segmind, SessionToken, SessionTokenProvider, VERSION, Webhooks, accounts, chat, chatSync, decide, decideSync, files, generations, imageUrl, job, models, pixelflows, run, runSync, submit, submitChat, submitDecision, webhooks };
992
+ export type { AccountCredits, AnswerStatus, BoxAnswer, BoxEdges, BoxQuestion, CallOptions, ChatMessage, ChatParams, ChoiceAnswer, ChoiceQuestion, ClientOptions, CreateSessionTokenOptions, DecisionAnswer, DecisionOptions, DecisionParams, DecisionUsage, FileInput, Generation, GenerationsListOptions, HistoryOptions, ImageInput, ImageUrlPart, Initiator, InitiatorOptions, JobState, JobStatus, MediaInput, ModelInfo, ModelInput, ModelListParams, ModelOutput, ModelSort, ModelsPage, NoulAnswer, NoulQuestion, Page, Params, PixelflowStatus, PixelflowSubmitOptions, PixelflowWaitOptions, PollInterval, Question, QuestionType, RequestRecord, RunOptions, RunResult, ScoreAnswer, ScoreLevel, ScoreQuestion, SubmitOptions, SubmitResponse, TokenProvider, UploadOptions, UploadedFile, WaitOptions, Webhook, WebhookDelivery, WebhookEventType };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { S as SessionToken, a as SessionTokenProvider } from './errors-CcHEuSmR.js';
2
- export { A as APIConnectionError, I as InferenceFailed, b as InferenceTimeout, c as InsufficientCredits, R as RateLimited, d as SegmindError } from './errors-CcHEuSmR.js';
1
+ import { S as SessionToken, a as SessionTokenProvider } from './errors-DsVQfts3.js';
2
+ export { A as APIConnectionError, I as InferenceFailed, b as InferenceTimeout, c as InsufficientCredits, R as RateLimited, d as SegmindError } from './errors-DsVQfts3.js';
3
3
 
4
4
  type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
5
5
  /** Returns the signed-in user's token, or null when there is none. Called before every request. */
@@ -150,15 +150,15 @@ type ChatParams = Params & {
150
150
  messages?: ChatMessage[] | Record<string, unknown>;
151
151
  prompt?: string;
152
152
  };
153
- type Raw = Record<string, unknown>;
153
+ type Raw$1 = Record<string, unknown>;
154
154
  /**
155
155
  * One reply from any chat model. The gateway returns each provider's own JSON
156
156
  * (OpenAI, Anthropic or Gemini shape); this reads the common fields from all
157
157
  * three. `raw` is always the provider's body, untouched.
158
158
  */
159
159
  declare class ChatResponse {
160
- readonly raw: Raw;
161
- constructor(raw: Raw);
160
+ readonly raw: Raw$1;
161
+ constructor(raw: Raw$1);
162
162
  /** The assistant's text. Throws when the body holds none (inspect `raw`). */
163
163
  get text(): string;
164
164
  /** `text` parsed as JSON, for JSON mode and structured outputs. */
@@ -171,6 +171,149 @@ declare class ChatResponse {
171
171
  get toolCalls(): unknown[];
172
172
  }
173
173
 
174
+ /**
175
+ * Decision models answer typed questions about a `state` with probabilities.
176
+ * Every decision model takes the same request and returns the same answer
177
+ * shape, so one body can be sent to several models and compared.
178
+ *
179
+ * An answer is `ok` only when the model gave one. A `refused` or `error`
180
+ * answer carries no number, and the readers on `DecisionResponse` return
181
+ * `undefined` for it, never 0, so a declined question is never read as a "no".
182
+ */
183
+ /** Yes / no, answered with the probability of yes. `criteria` says what each answer means. */
184
+ interface NoulQuestion {
185
+ type: 'noul';
186
+ instructions: string;
187
+ criteria?: {
188
+ true?: string | null;
189
+ false?: string | null;
190
+ };
191
+ }
192
+ /** One of a set of options: a list of keys, or a map of key to description. */
193
+ interface ChoiceQuestion {
194
+ type: 'choice';
195
+ instructions: string;
196
+ options: string[] | Record<string, string | null>;
197
+ }
198
+ /** A level on an ordered scale: a label, or a label with a description. */
199
+ type ScoreLevel = string | {
200
+ label: string;
201
+ description?: string | null;
202
+ };
203
+ /** A point on an ordered scale. `levels` run lowest first. */
204
+ interface ScoreQuestion {
205
+ type: 'score';
206
+ instructions: string;
207
+ levels: ScoreLevel[];
208
+ }
209
+ /** Where something is in the request's image, as edges in [0, 1]. */
210
+ interface BoxQuestion {
211
+ type: 'box';
212
+ instructions: string;
213
+ }
214
+ type Question = NoulQuestion | ChoiceQuestion | ScoreQuestion | BoxQuestion;
215
+ type QuestionType = Question['type'];
216
+ /** Optional features, grouped by what they do. A model that can't honour one ignores it with a warning. */
217
+ interface DecisionOptions {
218
+ /** Reuse a prompt cache across calls that share this key. */
219
+ caching?: {
220
+ key: string;
221
+ };
222
+ /** Keep a run of related calls on the same upstream session. */
223
+ session?: {
224
+ id: string;
225
+ };
226
+ /** How the call is routed upstream. */
227
+ routing?: {
228
+ prefer?: 'latency' | 'price' | 'throughput';
229
+ zero_data_retention?: boolean;
230
+ };
231
+ }
232
+ /** A URL, data URI or base64 string, or a list of them. */
233
+ type MediaInput = string | string[];
234
+ /** A decision request. Any other key is sent to the model unchanged. */
235
+ type DecisionParams = Params & {
236
+ /** What the model judges: text, or a JSON object or array. */
237
+ state: string | Record<string, unknown> | unknown[];
238
+ /** Question key to question. Answers come back under the same keys. */
239
+ questions: Record<string, Question>;
240
+ images?: MediaInput;
241
+ audio?: MediaInput;
242
+ video?: MediaInput;
243
+ files?: MediaInput;
244
+ options?: DecisionOptions;
245
+ };
246
+ type AnswerStatus = 'ok' | 'refused' | 'error';
247
+ interface AnswerBase {
248
+ status: AnswerStatus;
249
+ confidence?: number | null;
250
+ /** Why there is no answer, when `status` is `error`. */
251
+ error?: string;
252
+ }
253
+ interface NoulAnswer extends AnswerBase {
254
+ type: 'noul';
255
+ probability?: number;
256
+ }
257
+ interface ChoiceAnswer extends AnswerBase {
258
+ type: 'choice';
259
+ choice?: string;
260
+ probabilities?: Record<string, number> | null;
261
+ }
262
+ interface ScoreAnswer extends AnswerBase {
263
+ type: 'score';
264
+ /** The expected level index: 0 is the lowest level. */
265
+ score?: number;
266
+ probabilities?: number[] | null;
267
+ labels?: string[];
268
+ }
269
+ interface BoxEdges {
270
+ top: number;
271
+ bottom: number;
272
+ left: number;
273
+ right: number;
274
+ }
275
+ interface BoxAnswer extends AnswerBase {
276
+ type: 'box';
277
+ box?: BoxEdges;
278
+ }
279
+ type DecisionAnswer = NoulAnswer | ChoiceAnswer | ScoreAnswer | BoxAnswer;
280
+ interface DecisionUsage {
281
+ input_tokens: number;
282
+ cached_tokens: number;
283
+ cache_write_tokens: number;
284
+ }
285
+ type Raw = Record<string, unknown>;
286
+ /** One decision model's reply. */
287
+ declare class DecisionResponse {
288
+ /** The decision model that answered. */
289
+ readonly model: string;
290
+ /** Question key to its normalised answer. */
291
+ readonly answers: Record<string, DecisionAnswer>;
292
+ /** The vendor's own answer, for anything the normalised shape leaves out. */
293
+ readonly raw: unknown;
294
+ readonly usage: DecisionUsage | undefined;
295
+ /** What the call was charged. */
296
+ readonly cost: number | undefined;
297
+ /** The model's own time, measured inside the gateway. */
298
+ readonly latencyMs: number | undefined;
299
+ readonly warnings: string[];
300
+ constructor(body: Raw);
301
+ /** The full answer for `key`, whatever its status. Throws for a key no question used. */
302
+ answer(key: string): DecisionAnswer;
303
+ /** `ok`, `refused` or `error`. */
304
+ status(key: string): AnswerStatus;
305
+ /** A yes/no question's probability of yes; undefined unless the model answered. */
306
+ probability(key: string): number | undefined;
307
+ /** A choice question's picked option; undefined unless the model answered. */
308
+ choice(key: string): string | undefined;
309
+ /** A score question's expected level index (0 = lowest); undefined unless answered. */
310
+ score(key: string): number | undefined;
311
+ /** A box question's edges; undefined unless the model answered. */
312
+ box(key: string): BoxEdges | undefined;
313
+ /** A field of an `ok` answer of `type`. A refused or errored answer has none. */
314
+ private read;
315
+ }
316
+
174
317
  /** A file to send: a path (Node only), a `Blob` or `File`, or raw bytes. */
175
318
  type FileInput = string | Blob | ArrayBuffer | Uint8Array;
176
319
 
@@ -664,6 +807,16 @@ declare class Segmind {
664
807
  chatSync(slug: string, params: ChatParams, options?: CallOptions): Promise<ChatResponse>;
665
808
  /** Submits a chat to the v2 queue and returns a `Job` whose result is a `ChatResponse`. */
666
809
  submitChat(slug: string, params: ChatParams, options?: SubmitOptions): Promise<Job<ChatResponse>>;
810
+ /**
811
+ * Ask a decision model typed questions through the v2 queue. Pass `state`
812
+ * and `questions` (see `question` for the builders); the reply carries
813
+ * probabilities, the amount charged and the model's latency.
814
+ */
815
+ decide(slug: string, params: DecisionParams, options?: RunOptions): Promise<DecisionResponse>;
816
+ /** Ask a decision model with one blocking `POST /v1/{slug}`, which suits a model that answers in about a second. */
817
+ decideSync(slug: string, params: DecisionParams, options?: CallOptions): Promise<DecisionResponse>;
818
+ /** Submits a decision to the v2 queue and returns a `Job` whose result is a `DecisionResponse`. */
819
+ submitDecision(slug: string, params: DecisionParams, options?: SubmitOptions): Promise<Job<DecisionResponse>>;
667
820
  private submitJob;
668
821
  }
669
822
  type ModelInput = 'text' | 'image' | 'video' | 'audio';
@@ -793,7 +946,7 @@ declare function imageUrl(input: ImageInput, options?: {
793
946
  mimeType?: string;
794
947
  }): Promise<ImageUrlPart>;
795
948
 
796
- declare const VERSION = "0.6.1";
949
+ declare const VERSION = "0.7.0";
797
950
 
798
951
  /** `new Segmind().run(...)` with the key from `SEGMIND_API_KEY`. */
799
952
  declare const run: (slug: string, params?: Params, options?: RunOptions) => Promise<RunResult>;
@@ -809,6 +962,12 @@ declare const chat: (slug: string, params: ChatParams, options?: RunOptions) =>
809
962
  declare const chatSync: (slug: string, params: ChatParams, options?: CallOptions) => Promise<ChatResponse>;
810
963
  /** `new Segmind().submitChat(...)` with the key from `SEGMIND_API_KEY`. */
811
964
  declare const submitChat: (slug: string, params: ChatParams, options?: SubmitOptions) => Promise<Job<ChatResponse>>;
965
+ /** `new Segmind().decide(...)` with the key from `SEGMIND_API_KEY`. */
966
+ declare const decide: (slug: string, params: DecisionParams, options?: RunOptions) => Promise<DecisionResponse>;
967
+ /** `new Segmind().decideSync(...)` with the key from `SEGMIND_API_KEY`. */
968
+ declare const decideSync: (slug: string, params: DecisionParams, options?: CallOptions) => Promise<DecisionResponse>;
969
+ /** `new Segmind().submitDecision(...)` with the key from `SEGMIND_API_KEY`. */
970
+ declare const submitDecision: (slug: string, params: DecisionParams, options?: SubmitOptions) => Promise<Job<DecisionResponse>>;
812
971
  /** `new Segmind().models` with the key from `SEGMIND_API_KEY`. */
813
972
  declare const models: Pick<Models, 'list' | 'listAll'>;
814
973
  /** `new Segmind().accounts` with the key from `SEGMIND_API_KEY`. */
@@ -829,5 +988,5 @@ declare const webhooks: Pick<Webhooks, 'get' | 'add' | 'update' | 'delete' | 'lo
829
988
  /** `new Segmind().pixelflows` with the key from `SEGMIND_API_KEY`. */
830
989
  declare const pixelflows: Pick<PixelFlows, 'run' | 'submit' | 'getStatus' | 'poll'>;
831
990
 
832
- export { Accounts, ChatResponse, DEFAULT_BASE_URL, DEFAULT_CONSOLE_URL, DEFAULT_SPOT_URL, DEFAULT_WAIT_INTERVAL_MS, DEFAULT_WAIT_TIMEOUT_MS, Files, Generations, Job, Models, PixelFlows, PixelflowJob, Realtime, Segmind, SessionToken, SessionTokenProvider, VERSION, Webhooks, accounts, chat, chatSync, files, generations, imageUrl, job, models, pixelflows, run, runSync, submit, submitChat, webhooks };
833
- export type { AccountCredits, CallOptions, ChatMessage, ChatParams, ClientOptions, CreateSessionTokenOptions, FileInput, Generation, GenerationsListOptions, HistoryOptions, ImageInput, ImageUrlPart, Initiator, InitiatorOptions, JobState, JobStatus, ModelInfo, ModelInput, ModelListParams, ModelOutput, ModelSort, ModelsPage, Page, Params, PixelflowStatus, PixelflowSubmitOptions, PixelflowWaitOptions, PollInterval, RequestRecord, RunOptions, RunResult, SubmitOptions, SubmitResponse, TokenProvider, UploadOptions, UploadedFile, WaitOptions, Webhook, WebhookDelivery, WebhookEventType };
991
+ export { Accounts, ChatResponse, DEFAULT_BASE_URL, DEFAULT_CONSOLE_URL, DEFAULT_SPOT_URL, DEFAULT_WAIT_INTERVAL_MS, DEFAULT_WAIT_TIMEOUT_MS, DecisionResponse, Files, Generations, Job, Models, PixelFlows, PixelflowJob, Realtime, Segmind, SessionToken, SessionTokenProvider, VERSION, Webhooks, accounts, chat, chatSync, decide, decideSync, files, generations, imageUrl, job, models, pixelflows, run, runSync, submit, submitChat, submitDecision, webhooks };
992
+ export type { AccountCredits, AnswerStatus, BoxAnswer, BoxEdges, BoxQuestion, CallOptions, ChatMessage, ChatParams, ChoiceAnswer, ChoiceQuestion, ClientOptions, CreateSessionTokenOptions, DecisionAnswer, DecisionOptions, DecisionParams, DecisionUsage, FileInput, Generation, GenerationsListOptions, HistoryOptions, ImageInput, ImageUrlPart, Initiator, InitiatorOptions, JobState, JobStatus, MediaInput, ModelInfo, ModelInput, ModelListParams, ModelOutput, ModelSort, ModelsPage, NoulAnswer, NoulQuestion, Page, Params, PixelflowStatus, PixelflowSubmitOptions, PixelflowWaitOptions, PollInterval, Question, QuestionType, RequestRecord, RunOptions, RunResult, ScoreAnswer, ScoreLevel, ScoreQuestion, SubmitOptions, SubmitResponse, TokenProvider, UploadOptions, UploadedFile, WaitOptions, Webhook, WebhookDelivery, WebhookEventType };
package/dist/index.js CHANGED
@@ -105,6 +105,72 @@ function str(value) {
105
105
  return typeof value === "string" ? value : void 0;
106
106
  }
107
107
 
108
+ // src/decisions.ts
109
+ var DecisionResponse = class {
110
+ constructor(body) {
111
+ const answers = record2(body.answers);
112
+ if (!answers) throw new SegmindError("not a decision reply: it has no answers map", { body });
113
+ this.model = typeof body.model === "string" ? body.model : "";
114
+ this.answers = answers;
115
+ this.raw = body.raw;
116
+ this.usage = record2(body.usage);
117
+ this.cost = num(body.cost);
118
+ this.latencyMs = num(body.latency_ms);
119
+ this.warnings = Array.isArray(body.warnings) ? body.warnings.filter((w) => typeof w === "string") : [];
120
+ }
121
+ /** The full answer for `key`, whatever its status. Throws for a key no question used. */
122
+ answer(key) {
123
+ if (!Object.prototype.hasOwnProperty.call(this.answers, key)) throw new SegmindError(`no answer for "${key}"`);
124
+ return this.answers[key];
125
+ }
126
+ /** `ok`, `refused` or `error`. */
127
+ status(key) {
128
+ return this.answer(key).status;
129
+ }
130
+ /** A yes/no question's probability of yes; undefined unless the model answered. */
131
+ probability(key) {
132
+ return this.read(key, "noul", "probability");
133
+ }
134
+ /** A choice question's picked option; undefined unless the model answered. */
135
+ choice(key) {
136
+ return this.read(key, "choice", "choice");
137
+ }
138
+ /** A score question's expected level index (0 = lowest); undefined unless answered. */
139
+ score(key) {
140
+ return this.read(key, "score", "score");
141
+ }
142
+ /** A box question's edges; undefined unless the model answered. */
143
+ box(key) {
144
+ return this.read(key, "box", "box");
145
+ }
146
+ /** A field of an `ok` answer of `type`. A refused or errored answer has none. */
147
+ read(key, type, field) {
148
+ const a = this.answer(key);
149
+ return a.status === "ok" && a.type === type ? a[field] : void 0;
150
+ }
151
+ };
152
+ function decisionBody(params) {
153
+ const { state, questions } = params;
154
+ if (state == null || typeof state === "string" && !state.trim()) throw new SegmindError("decide: state is required");
155
+ if (!record2(questions) || !Object.keys(questions).length) {
156
+ throw new SegmindError("decide: questions must map at least one key to a question");
157
+ }
158
+ return params;
159
+ }
160
+ function decisionFromRunResult(body) {
161
+ let output = body.output;
162
+ if (typeof output === "string" && output.trim()) output = JSON.parse(output);
163
+ if (record2(output)?.answers) return new DecisionResponse(output);
164
+ if (record2(body.answers)) return new DecisionResponse(body);
165
+ throw new SegmindError("the v2 result has no decision reply; decideSync makes a blocking /v1 call instead", { body });
166
+ }
167
+ function record2(value) {
168
+ return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
169
+ }
170
+ function num(value) {
171
+ return typeof value === "number" && Number.isFinite(value) ? value : void 0;
172
+ }
173
+
108
174
  // src/core/env.ts
109
175
  var g = globalThis;
110
176
  function detectRuntime() {
@@ -758,7 +824,7 @@ var Realtime = class {
758
824
  };
759
825
 
760
826
  // src/version.ts
761
- var VERSION = "0.6.1";
827
+ var VERSION = "0.7.0";
762
828
 
763
829
  // src/webhooks.ts
764
830
  var Webhooks = class {
@@ -959,6 +1025,24 @@ var Segmind = class {
959
1025
  async submitChat(slug, params, options = {}) {
960
1026
  return this.submitJob(slug, chatBody(params), options, chatFromRunResult);
961
1027
  }
1028
+ /**
1029
+ * Ask a decision model typed questions through the v2 queue. Pass `state`
1030
+ * and `questions` (see `question` for the builders); the reply carries
1031
+ * probabilities, the amount charged and the model's latency.
1032
+ */
1033
+ async decide(slug, params, options = {}) {
1034
+ const job2 = await this.submitDecision(slug, params, options);
1035
+ return job2.wait(options);
1036
+ }
1037
+ /** Ask a decision model with one blocking `POST /v1/{slug}`, which suits a model that answers in about a second. */
1038
+ async decideSync(slug, params, options = {}) {
1039
+ const response = await this.runSync(slug, decisionBody(params), options);
1040
+ return new DecisionResponse(await readJson(response));
1041
+ }
1042
+ /** Submits a decision to the v2 queue and returns a `Job` whose result is a `DecisionResponse`. */
1043
+ async submitDecision(slug, params, options = {}) {
1044
+ return this.submitJob(slug, decisionBody(params), options, decisionFromRunResult);
1045
+ }
962
1046
  async submitJob(slug, params, options, transform) {
963
1047
  const url = `${this.baseURL}/v2/${path(slug)}`;
964
1048
  const maxRetries = this.http.config.maxRetries;
@@ -1139,6 +1223,9 @@ var job = (requestId) => client().job(requestId);
1139
1223
  var chat = (slug, params, options) => client().chat(slug, params, options);
1140
1224
  var chatSync = (slug, params, options) => client().chatSync(slug, params, options);
1141
1225
  var submitChat = (slug, params, options) => client().submitChat(slug, params, options);
1226
+ var decide = (slug, params, options) => client().decide(slug, params, options);
1227
+ var decideSync = (slug, params, options) => client().decideSync(slug, params, options);
1228
+ var submitDecision = (slug, params, options) => client().submitDecision(slug, params, options);
1142
1229
  var models = {
1143
1230
  list: (params, options) => client().models.list(params, options),
1144
1231
  listAll: (params, options) => client().models.listAll(params, options)
@@ -1180,6 +1267,7 @@ export {
1180
1267
  DEFAULT_SPOT_URL,
1181
1268
  DEFAULT_WAIT_INTERVAL_MS,
1182
1269
  DEFAULT_WAIT_TIMEOUT_MS,
1270
+ DecisionResponse,
1183
1271
  Files,
1184
1272
  Generations,
1185
1273
  InferenceFailed,
@@ -1198,6 +1286,8 @@ export {
1198
1286
  accounts,
1199
1287
  chat,
1200
1288
  chatSync,
1289
+ decide,
1290
+ decideSync,
1201
1291
  files,
1202
1292
  generations,
1203
1293
  imageUrl,
@@ -1208,6 +1298,7 @@ export {
1208
1298
  runSync,
1209
1299
  submit,
1210
1300
  submitChat,
1301
+ submitDecision,
1211
1302
  webhooks
1212
1303
  };
1213
1304
  //# sourceMappingURL=index.js.map