flexinference 1.3.0 → 1.4.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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.4.0
4
+
5
+ Surfaces the router's **`doc_url`** on `FlexInferenceError` as a new `docUrl` field: a deep
6
+ link straight to the docs row for that error's `code` (when the router supplied one), so an
7
+ error caught in code can point a developer -- or an agent reading the message -- at the fix.
8
+ Also enriches the local `start_within` validation messages with concrete examples. Additive;
9
+ no breaking changes.
10
+
3
11
  ## 1.3.0
4
12
 
5
13
  Adds a typed **`PaymentRequiredError`** (a subclass of `FlexInferenceError`) thrown on
package/dist/index.d.ts CHANGED
@@ -60,6 +60,7 @@ export interface FlexErrorBody {
60
60
  type: string;
61
61
  code?: string | null;
62
62
  param?: string | null;
63
+ doc_url?: string | null;
63
64
  };
64
65
  }
65
66
  export declare class FlexInferenceError extends Error {
@@ -67,6 +68,8 @@ export declare class FlexInferenceError extends Error {
67
68
  readonly type: string | undefined;
68
69
  readonly code: string | null | undefined;
69
70
  readonly param: string | null | undefined;
71
+ /** Deep link into the docs for this error's code, when the router supplied one. */
72
+ readonly docUrl: string | null | undefined;
70
73
  constructor(status: number, body: Partial<FlexErrorBody> | undefined, fallback: string);
71
74
  }
72
75
  /**
package/dist/index.js CHANGED
@@ -90,6 +90,8 @@ export class FlexInferenceError extends Error {
90
90
  type;
91
91
  code;
92
92
  param;
93
+ /** Deep link into the docs for this error's code, when the router supplied one. */
94
+ docUrl;
93
95
  constructor(status, body, fallback) {
94
96
  const err = body?.error;
95
97
  super(err?.message ?? fallback);
@@ -98,6 +100,7 @@ export class FlexInferenceError extends Error {
98
100
  this.type = err?.type;
99
101
  this.code = err?.code;
100
102
  this.param = err?.param;
103
+ this.docUrl = err?.doc_url;
101
104
  }
102
105
  }
103
106
  /**
@@ -124,16 +127,18 @@ function assertStartWithin(body) {
124
127
  ? body["start_within"]
125
128
  : undefined;
126
129
  if (value === undefined) {
127
- throw new Error(`FlexInference: \`start_within\` is required. Set it to ${START_WITHIN_VALUES}.`);
130
+ throw new Error(`FlexInference: \`start_within\` is required on every request. Set it to ${START_WITHIN_VALUES}, ` +
131
+ `for example "start_within": "default" for standard-tier behavior or "00h-00m-30s" for a 30-second flex race.`);
128
132
  }
129
133
  if (typeof value !== "string") {
130
- throw new Error(`FlexInference: \`start_within\` must be a string (${START_WITHIN_VALUES}).`);
134
+ throw new Error(`FlexInference: \`start_within\` must be a string (${START_WITHIN_VALUES}), for example "default".`);
131
135
  }
132
136
  if (value === "default" || value === "priority" || value === "auto")
133
137
  return;
134
138
  const match = DURATION_RE.exec(value);
135
139
  if (match === null) {
136
- throw new Error(`FlexInference: \`start_within\` "${value}" is not ${START_WITHIN_VALUES}.`);
140
+ throw new Error(`FlexInference: \`start_within\` "${value}" is not ${START_WITHIN_VALUES}. ` +
141
+ `A duration is two digits each for hours, minutes, and seconds, for example "00h-05m-00s" for a 5-minute deadline.`);
137
142
  }
138
143
  const seconds = Number(match[1]) * SECONDS_PER_HOUR + Number(match[2]) * SECONDS_PER_MINUTE + Number(match[3]);
139
144
  if (seconds < MIN_DEADLINE_SECONDS || seconds > MAX_DEADLINE_SECONDS) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flexinference",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "Official TypeScript SDK for FlexInference - a deadline-aware, OpenAI-compatible inference router.",
5
5
  "license": "MIT",
6
6
  "author": "Aditya Perswal <adityaperswal@gmail.com>",