notdiamond 2.0.0-rc2 → 2.0.0-rc20

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.
Files changed (147) hide show
  1. package/CHANGELOG.md +185 -0
  2. package/LICENSE +1 -1
  3. package/README.md +261 -168
  4. package/client.d.mts +26 -43
  5. package/client.d.mts.map +1 -1
  6. package/client.d.ts +26 -43
  7. package/client.d.ts.map +1 -1
  8. package/client.js +49 -68
  9. package/client.js.map +1 -1
  10. package/client.mjs +47 -66
  11. package/client.mjs.map +1 -1
  12. package/core/api-promise.d.mts +2 -2
  13. package/core/api-promise.d.ts +2 -2
  14. package/core/error.d.mts +2 -2
  15. package/core/error.d.ts +2 -2
  16. package/core/error.js +4 -4
  17. package/core/error.mjs +2 -2
  18. package/core/resource.d.mts +3 -3
  19. package/core/resource.d.ts +3 -3
  20. package/index.d.mts +3 -3
  21. package/index.d.ts +3 -3
  22. package/index.js +4 -4
  23. package/index.mjs +3 -3
  24. package/internal/parse.d.mts +2 -2
  25. package/internal/parse.d.ts +2 -2
  26. package/internal/shims.js +1 -1
  27. package/internal/shims.mjs +1 -1
  28. package/internal/uploads.d.mts +4 -4
  29. package/internal/uploads.d.ts +4 -4
  30. package/internal/utils/base64.js +2 -2
  31. package/internal/utils/base64.mjs +3 -3
  32. package/internal/utils/env.d.mts.map +1 -1
  33. package/internal/utils/env.d.ts.map +1 -1
  34. package/internal/utils/env.js +4 -2
  35. package/internal/utils/env.js.map +1 -1
  36. package/internal/utils/env.mjs +4 -2
  37. package/internal/utils/env.mjs.map +1 -1
  38. package/internal/utils/log.d.mts +3 -3
  39. package/internal/utils/log.d.ts +3 -3
  40. package/internal/utils/path.js +1 -1
  41. package/internal/utils/path.mjs +2 -2
  42. package/internal/utils/values.js +5 -5
  43. package/internal/utils/values.mjs +6 -6
  44. package/package.json +11 -12
  45. package/resources/custom-router.d.mts +145 -0
  46. package/resources/custom-router.d.mts.map +1 -0
  47. package/resources/custom-router.d.ts +145 -0
  48. package/resources/custom-router.d.ts.map +1 -0
  49. package/resources/custom-router.js +83 -0
  50. package/resources/custom-router.js.map +1 -0
  51. package/resources/custom-router.mjs +79 -0
  52. package/resources/custom-router.mjs.map +1 -0
  53. package/resources/index.d.mts +5 -6
  54. package/resources/index.d.mts.map +1 -1
  55. package/resources/index.d.ts +5 -6
  56. package/resources/index.d.ts.map +1 -1
  57. package/resources/index.js +5 -7
  58. package/resources/index.js.map +1 -1
  59. package/resources/index.mjs +2 -3
  60. package/resources/index.mjs.map +1 -1
  61. package/resources/model-router.d.mts +194 -0
  62. package/resources/model-router.d.mts.map +1 -0
  63. package/resources/model-router.d.ts +194 -0
  64. package/resources/model-router.d.ts.map +1 -0
  65. package/resources/model-router.js +68 -0
  66. package/resources/model-router.js.map +1 -0
  67. package/resources/model-router.mjs +64 -0
  68. package/resources/model-router.mjs.map +1 -0
  69. package/resources/models.d.mts +50 -25
  70. package/resources/models.d.mts.map +1 -1
  71. package/resources/models.d.ts +50 -25
  72. package/resources/models.d.ts.map +1 -1
  73. package/resources/models.js +5 -0
  74. package/resources/models.js.map +1 -1
  75. package/resources/models.mjs +5 -0
  76. package/resources/models.mjs.map +1 -1
  77. package/resources/preferences.d.mts +37 -54
  78. package/resources/preferences.d.mts.map +1 -1
  79. package/resources/preferences.d.ts +37 -54
  80. package/resources/preferences.d.ts.map +1 -1
  81. package/resources/preferences.js +17 -42
  82. package/resources/preferences.js.map +1 -1
  83. package/resources/preferences.mjs +17 -42
  84. package/resources/preferences.mjs.map +1 -1
  85. package/resources/prompt-adaptation.d.mts +340 -249
  86. package/resources/prompt-adaptation.d.mts.map +1 -1
  87. package/resources/prompt-adaptation.d.ts +340 -249
  88. package/resources/prompt-adaptation.d.ts.map +1 -1
  89. package/resources/prompt-adaptation.js +36 -79
  90. package/resources/prompt-adaptation.js.map +1 -1
  91. package/resources/prompt-adaptation.mjs +36 -79
  92. package/resources/prompt-adaptation.mjs.map +1 -1
  93. package/src/client.ts +72 -128
  94. package/src/core/api-promise.ts +4 -4
  95. package/src/core/error.ts +2 -2
  96. package/src/core/resource.ts +3 -3
  97. package/src/index.ts +3 -3
  98. package/src/internal/parse.ts +2 -2
  99. package/src/internal/shims.ts +1 -1
  100. package/src/internal/uploads.ts +5 -5
  101. package/src/internal/utils/base64.ts +3 -3
  102. package/src/internal/utils/env.ts +4 -2
  103. package/src/internal/utils/log.ts +3 -3
  104. package/src/internal/utils/path.ts +2 -2
  105. package/src/internal/utils/values.ts +6 -6
  106. package/src/resources/custom-router.ts +168 -0
  107. package/src/resources/index.ts +20 -32
  108. package/src/resources/model-router.ts +222 -0
  109. package/src/resources/models.ts +55 -32
  110. package/src/resources/preferences.ts +43 -83
  111. package/src/resources/prompt-adaptation.ts +358 -300
  112. package/src/version.ts +1 -1
  113. package/version.d.mts +1 -1
  114. package/version.d.mts.map +1 -1
  115. package/version.d.ts +1 -1
  116. package/version.d.ts.map +1 -1
  117. package/version.js +1 -1
  118. package/version.js.map +1 -1
  119. package/version.mjs +1 -1
  120. package/version.mjs.map +1 -1
  121. package/resources/admin.d.mts +0 -4
  122. package/resources/admin.d.mts.map +0 -1
  123. package/resources/admin.d.ts +0 -4
  124. package/resources/admin.d.ts.map +0 -1
  125. package/resources/admin.js +0 -9
  126. package/resources/admin.js.map +0 -1
  127. package/resources/admin.mjs +0 -5
  128. package/resources/admin.mjs.map +0 -1
  129. package/resources/report.d.mts +0 -245
  130. package/resources/report.d.mts.map +0 -1
  131. package/resources/report.d.ts +0 -245
  132. package/resources/report.d.ts.map +0 -1
  133. package/resources/report.js +0 -86
  134. package/resources/report.js.map +0 -1
  135. package/resources/report.mjs +0 -82
  136. package/resources/report.mjs.map +0 -1
  137. package/resources/routing.d.mts +0 -391
  138. package/resources/routing.d.mts.map +0 -1
  139. package/resources/routing.d.ts +0 -391
  140. package/resources/routing.d.ts.map +0 -1
  141. package/resources/routing.js +0 -163
  142. package/resources/routing.js.map +0 -1
  143. package/resources/routing.mjs +0 -159
  144. package/resources/routing.mjs.map +0 -1
  145. package/src/resources/admin.ts +0 -5
  146. package/src/resources/report.ts +0 -300
  147. package/src/resources/routing.ts +0 -476
@@ -1,6 +1,6 @@
1
1
  import { type RequestOptions } from "./request-options.js";
2
2
  import type { FilePropertyBag, Fetch } from "./builtin-types.js";
3
- import type { NotDiamond } from "../client.js";
3
+ import type { Notdiamond } from "../client.js";
4
4
  export type BlobPart = string | ArrayBuffer | ArrayBufferView | Blob | DataView;
5
5
  type FsReadStream = AsyncIterable<Uint8Array> & {
6
6
  path: string | {
@@ -32,11 +32,11 @@ export declare const isAsyncIterable: (value: any) => value is AsyncIterable<any
32
32
  * Returns a multipart/form-data request if any part of the given request body contains a File / Blob value.
33
33
  * Otherwise returns the request as is.
34
34
  */
35
- export declare const maybeMultipartFormRequestOptions: (opts: RequestOptions, fetch: NotDiamond | Fetch) => Promise<RequestOptions>;
35
+ export declare const maybeMultipartFormRequestOptions: (opts: RequestOptions, fetch: Notdiamond | Fetch) => Promise<RequestOptions>;
36
36
  type MultipartFormRequestOptions = Omit<RequestOptions, 'body'> & {
37
37
  body: unknown;
38
38
  };
39
- export declare const multipartFormRequestOptions: (opts: MultipartFormRequestOptions, fetch: NotDiamond | Fetch) => Promise<RequestOptions>;
40
- export declare const createForm: <T = Record<string, unknown>>(body: T | undefined, fetch: NotDiamond | Fetch) => Promise<FormData>;
39
+ export declare const multipartFormRequestOptions: (opts: MultipartFormRequestOptions, fetch: Notdiamond | Fetch) => Promise<RequestOptions>;
40
+ export declare const createForm: <T = Record<string, unknown>>(body: T | undefined, fetch: Notdiamond | Fetch) => Promise<FormData>;
41
41
  export {};
42
42
  //# sourceMappingURL=uploads.d.ts.map
@@ -16,7 +16,7 @@ const toBase64 = (data) => {
16
16
  if (typeof btoa !== 'undefined') {
17
17
  return btoa(String.fromCharCode.apply(null, data));
18
18
  }
19
- throw new error_1.NotDiamondError('Cannot generate base64 string; Expected `Buffer` or `btoa` to be defined');
19
+ throw new error_1.NotdiamondError('Cannot generate base64 string; Expected `Buffer` or `btoa` to be defined');
20
20
  };
21
21
  exports.toBase64 = toBase64;
22
22
  const fromBase64 = (str) => {
@@ -32,7 +32,7 @@ const fromBase64 = (str) => {
32
32
  }
33
33
  return buf;
34
34
  }
35
- throw new error_1.NotDiamondError('Cannot decode base64 string; Expected `Buffer` or `atob` to be defined');
35
+ throw new error_1.NotdiamondError('Cannot decode base64 string; Expected `Buffer` or `atob` to be defined');
36
36
  };
37
37
  exports.fromBase64 = fromBase64;
38
38
  //# sourceMappingURL=base64.js.map
@@ -1,5 +1,5 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
- import { NotDiamondError } from "../../core/error.mjs";
2
+ import { NotdiamondError } from "../../core/error.mjs";
3
3
  import { encodeUTF8 } from "./bytes.mjs";
4
4
  export const toBase64 = (data) => {
5
5
  if (!data)
@@ -13,7 +13,7 @@ export const toBase64 = (data) => {
13
13
  if (typeof btoa !== 'undefined') {
14
14
  return btoa(String.fromCharCode.apply(null, data));
15
15
  }
16
- throw new NotDiamondError('Cannot generate base64 string; Expected `Buffer` or `btoa` to be defined');
16
+ throw new NotdiamondError('Cannot generate base64 string; Expected `Buffer` or `btoa` to be defined');
17
17
  };
18
18
  export const fromBase64 = (str) => {
19
19
  if (typeof globalThis.Buffer !== 'undefined') {
@@ -28,6 +28,6 @@ export const fromBase64 = (str) => {
28
28
  }
29
29
  return buf;
30
30
  }
31
- throw new NotDiamondError('Cannot decode base64 string; Expected `Buffer` or `atob` to be defined');
31
+ throw new NotdiamondError('Cannot decode base64 string; Expected `Buffer` or `atob` to be defined');
32
32
  };
33
33
  //# sourceMappingURL=base64.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"env.d.mts","sourceRoot":"","sources":["../../src/internal/utils/env.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,eAAO,MAAM,OAAO,GAAI,KAAK,MAAM,KAAG,MAAM,GAAG,SAQ9C,CAAC"}
1
+ {"version":3,"file":"env.d.mts","sourceRoot":"","sources":["../../src/internal/utils/env.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,eAAO,MAAM,OAAO,GAAI,KAAK,MAAM,KAAG,MAAM,GAAG,SAU9C,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/internal/utils/env.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,eAAO,MAAM,OAAO,GAAI,KAAK,MAAM,KAAG,MAAM,GAAG,SAQ9C,CAAC"}
1
+ {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/internal/utils/env.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,eAAO,MAAM,OAAO,GAAI,KAAK,MAAM,KAAG,MAAM,GAAG,SAU9C,CAAC"}
@@ -11,10 +11,12 @@ exports.readEnv = void 0;
11
11
  */
12
12
  const readEnv = (env) => {
13
13
  if (typeof globalThis.process !== 'undefined') {
14
- return globalThis.process.env?.[env]?.trim() ?? undefined;
14
+ const value = globalThis.process.env?.[env]?.trim() ?? undefined;
15
+ return value === '' ? undefined : value;
15
16
  }
16
17
  if (typeof globalThis.Deno !== 'undefined') {
17
- return globalThis.Deno.env?.get?.(env)?.trim();
18
+ const value = globalThis.Deno.env?.get?.(env)?.trim();
19
+ return value === '' ? undefined : value;
18
20
  }
19
21
  return undefined;
20
22
  };
@@ -1 +1 @@
1
- {"version":3,"file":"env.js","sourceRoot":"","sources":["../../src/internal/utils/env.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAEtF;;;;;;GAMG;AACI,MAAM,OAAO,GAAG,CAAC,GAAW,EAAsB,EAAE;IACzD,IAAI,OAAQ,UAAkB,CAAC,OAAO,KAAK,WAAW,EAAE,CAAC;QACvD,OAAQ,UAAkB,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,IAAI,SAAS,CAAC;IACrE,CAAC;IACD,IAAI,OAAQ,UAAkB,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;QACpD,OAAQ,UAAkB,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC;IAC1D,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AARW,QAAA,OAAO,WAQlB"}
1
+ {"version":3,"file":"env.js","sourceRoot":"","sources":["../../src/internal/utils/env.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAEtF;;;;;;GAMG;AACI,MAAM,OAAO,GAAG,CAAC,GAAW,EAAsB,EAAE;IACzD,IAAI,OAAQ,UAAkB,CAAC,OAAO,KAAK,WAAW,EAAE,CAAC;QACvD,MAAM,KAAK,GAAI,UAAkB,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,IAAI,SAAS,CAAC;QAC1E,OAAO,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC;IAC1C,CAAC;IACD,IAAI,OAAQ,UAAkB,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;QACpD,MAAM,KAAK,GAAI,UAAkB,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC;QAC/D,OAAO,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC;IAC1C,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAVW,QAAA,OAAO,WAUlB"}
@@ -8,10 +8,12 @@
8
8
  */
9
9
  export const readEnv = (env) => {
10
10
  if (typeof globalThis.process !== 'undefined') {
11
- return globalThis.process.env?.[env]?.trim() ?? undefined;
11
+ const value = globalThis.process.env?.[env]?.trim() ?? undefined;
12
+ return value === '' ? undefined : value;
12
13
  }
13
14
  if (typeof globalThis.Deno !== 'undefined') {
14
- return globalThis.Deno.env?.get?.(env)?.trim();
15
+ const value = globalThis.Deno.env?.get?.(env)?.trim();
16
+ return value === '' ? undefined : value;
15
17
  }
16
18
  return undefined;
17
19
  };
@@ -1 +1 @@
1
- {"version":3,"file":"env.mjs","sourceRoot":"","sources":["../../src/internal/utils/env.ts"],"names":[],"mappings":"AAAA,sFAAsF;AAEtF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,GAAW,EAAsB,EAAE;IACzD,IAAI,OAAQ,UAAkB,CAAC,OAAO,KAAK,WAAW,EAAE,CAAC;QACvD,OAAQ,UAAkB,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,IAAI,SAAS,CAAC;IACrE,CAAC;IACD,IAAI,OAAQ,UAAkB,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;QACpD,OAAQ,UAAkB,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC;IAC1D,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC"}
1
+ {"version":3,"file":"env.mjs","sourceRoot":"","sources":["../../src/internal/utils/env.ts"],"names":[],"mappings":"AAAA,sFAAsF;AAEtF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,GAAW,EAAsB,EAAE;IACzD,IAAI,OAAQ,UAAkB,CAAC,OAAO,KAAK,WAAW,EAAE,CAAC;QACvD,MAAM,KAAK,GAAI,UAAkB,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,IAAI,SAAS,CAAC;QAC1E,OAAO,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC;IAC1C,CAAC;IACD,IAAI,OAAQ,UAAkB,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;QACpD,MAAM,KAAK,GAAI,UAAkB,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC;QAC/D,OAAO,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC;IAC1C,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC"}
@@ -1,4 +1,4 @@
1
- import { type NotDiamond } from "../../client.mjs";
1
+ import { type Notdiamond } from "../../client.mjs";
2
2
  import { RequestOptions } from "../request-options.mjs";
3
3
  type LogFn = (message: string, ...rest: unknown[]) => void;
4
4
  export type Logger = {
@@ -8,8 +8,8 @@ export type Logger = {
8
8
  debug: LogFn;
9
9
  };
10
10
  export type LogLevel = 'off' | 'error' | 'warn' | 'info' | 'debug';
11
- export declare const parseLogLevel: (maybeLevel: string | undefined, sourceName: string, client: NotDiamond) => LogLevel | undefined;
12
- export declare function loggerFor(client: NotDiamond): Logger;
11
+ export declare const parseLogLevel: (maybeLevel: string | undefined, sourceName: string, client: Notdiamond) => LogLevel | undefined;
12
+ export declare function loggerFor(client: Notdiamond): Logger;
13
13
  export declare const formatRequestDetails: (details: {
14
14
  options?: RequestOptions | undefined;
15
15
  headers?: Headers | Record<string, string> | undefined;
@@ -1,4 +1,4 @@
1
- import { type NotDiamond } from "../../client.js";
1
+ import { type Notdiamond } from "../../client.js";
2
2
  import { RequestOptions } from "../request-options.js";
3
3
  type LogFn = (message: string, ...rest: unknown[]) => void;
4
4
  export type Logger = {
@@ -8,8 +8,8 @@ export type Logger = {
8
8
  debug: LogFn;
9
9
  };
10
10
  export type LogLevel = 'off' | 'error' | 'warn' | 'info' | 'debug';
11
- export declare const parseLogLevel: (maybeLevel: string | undefined, sourceName: string, client: NotDiamond) => LogLevel | undefined;
12
- export declare function loggerFor(client: NotDiamond): Logger;
11
+ export declare const parseLogLevel: (maybeLevel: string | undefined, sourceName: string, client: Notdiamond) => LogLevel | undefined;
12
+ export declare function loggerFor(client: Notdiamond): Logger;
13
13
  export declare const formatRequestDetails: (details: {
14
14
  options?: RequestOptions | undefined;
15
15
  headers?: Headers | Record<string, string> | undefined;
@@ -65,7 +65,7 @@ const createPathTagFunction = (pathEncoder = encodeURIPath) => function path(sta
65
65
  lastEnd = segment.start + segment.length;
66
66
  return acc + spaces + arrows;
67
67
  }, '');
68
- throw new error_1.NotDiamondError(`Path parameters result in path with invalid segments:\n${invalidSegments
68
+ throw new error_1.NotdiamondError(`Path parameters result in path with invalid segments:\n${invalidSegments
69
69
  .map((e) => e.error)
70
70
  .join('\n')}\n${path}\n${underline}`);
71
71
  }
@@ -1,4 +1,4 @@
1
- import { NotDiamondError } from "../../core/error.mjs";
1
+ import { NotdiamondError } from "../../core/error.mjs";
2
2
  /**
3
3
  * Percent-encode everything that isn't safe to have in a path without encoding safe chars.
4
4
  *
@@ -61,7 +61,7 @@ export const createPathTagFunction = (pathEncoder = encodeURIPath) => function p
61
61
  lastEnd = segment.start + segment.length;
62
62
  return acc + spaces + arrows;
63
63
  }, '');
64
- throw new NotDiamondError(`Path parameters result in path with invalid segments:\n${invalidSegments
64
+ throw new NotdiamondError(`Path parameters result in path with invalid segments:\n${invalidSegments
65
65
  .map((e) => e.error)
66
66
  .join('\n')}\n${path}\n${underline}`);
67
67
  }
@@ -40,17 +40,17 @@ function isObj(obj) {
40
40
  }
41
41
  const ensurePresent = (value) => {
42
42
  if (value == null) {
43
- throw new error_1.NotDiamondError(`Expected a value to be given but received ${value} instead.`);
43
+ throw new error_1.NotdiamondError(`Expected a value to be given but received ${value} instead.`);
44
44
  }
45
45
  return value;
46
46
  };
47
47
  exports.ensurePresent = ensurePresent;
48
48
  const validatePositiveInteger = (name, n) => {
49
49
  if (typeof n !== 'number' || !Number.isInteger(n)) {
50
- throw new error_1.NotDiamondError(`${name} must be an integer`);
50
+ throw new error_1.NotdiamondError(`${name} must be an integer`);
51
51
  }
52
52
  if (n < 0) {
53
- throw new error_1.NotDiamondError(`${name} must be a positive integer`);
53
+ throw new error_1.NotdiamondError(`${name} must be a positive integer`);
54
54
  }
55
55
  return n;
56
56
  };
@@ -60,7 +60,7 @@ const coerceInteger = (value) => {
60
60
  return Math.round(value);
61
61
  if (typeof value === 'string')
62
62
  return parseInt(value, 10);
63
- throw new error_1.NotDiamondError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
63
+ throw new error_1.NotdiamondError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
64
64
  };
65
65
  exports.coerceInteger = coerceInteger;
66
66
  const coerceFloat = (value) => {
@@ -68,7 +68,7 @@ const coerceFloat = (value) => {
68
68
  return value;
69
69
  if (typeof value === 'string')
70
70
  return parseFloat(value);
71
- throw new error_1.NotDiamondError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
71
+ throw new error_1.NotdiamondError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
72
72
  };
73
73
  exports.coerceFloat = coerceFloat;
74
74
  const coerceBoolean = (value) => {
@@ -1,5 +1,5 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
- import { NotDiamondError } from "../../core/error.mjs";
2
+ import { NotdiamondError } from "../../core/error.mjs";
3
3
  // https://url.spec.whatwg.org/#url-scheme-string
4
4
  const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
5
5
  export const isAbsoluteURL = (url) => {
@@ -31,16 +31,16 @@ export function isObj(obj) {
31
31
  }
32
32
  export const ensurePresent = (value) => {
33
33
  if (value == null) {
34
- throw new NotDiamondError(`Expected a value to be given but received ${value} instead.`);
34
+ throw new NotdiamondError(`Expected a value to be given but received ${value} instead.`);
35
35
  }
36
36
  return value;
37
37
  };
38
38
  export const validatePositiveInteger = (name, n) => {
39
39
  if (typeof n !== 'number' || !Number.isInteger(n)) {
40
- throw new NotDiamondError(`${name} must be an integer`);
40
+ throw new NotdiamondError(`${name} must be an integer`);
41
41
  }
42
42
  if (n < 0) {
43
- throw new NotDiamondError(`${name} must be a positive integer`);
43
+ throw new NotdiamondError(`${name} must be a positive integer`);
44
44
  }
45
45
  return n;
46
46
  };
@@ -49,14 +49,14 @@ export const coerceInteger = (value) => {
49
49
  return Math.round(value);
50
50
  if (typeof value === 'string')
51
51
  return parseInt(value, 10);
52
- throw new NotDiamondError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
52
+ throw new NotdiamondError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
53
53
  };
54
54
  export const coerceFloat = (value) => {
55
55
  if (typeof value === 'number')
56
56
  return value;
57
57
  if (typeof value === 'string')
58
58
  return parseFloat(value);
59
- throw new NotDiamondError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
59
+ throw new NotdiamondError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
60
60
  };
61
61
  export const coerceBoolean = (value) => {
62
62
  if (typeof value === 'boolean')
package/package.json CHANGED
@@ -1,14 +1,13 @@
1
1
  {
2
2
  "name": "notdiamond",
3
- "version": "2.0.0-rc2",
4
- "description": "The official TypeScript library for the Not Diamond API",
5
- "author": "Not Diamond <d6@notdiamond.ai>",
3
+ "version": "2.0.0-rc20",
4
+ "description": "The official TypeScript library for the Notdiamond API",
5
+ "author": "Notdiamond <contact@notdiamond.ai>",
6
6
  "types": "./index.d.ts",
7
7
  "main": "./index.js",
8
8
  "type": "commonjs",
9
9
  "repository": "github:Not-Diamond/not-diamond-typescript",
10
10
  "license": "Apache-2.0",
11
- "packageManager": "yarn@1.22.22",
12
11
  "files": [
13
12
  "**/*"
14
13
  ],
@@ -16,14 +15,6 @@
16
15
  "publishConfig": {
17
16
  "access": "public"
18
17
  },
19
- "scripts": {
20
- "test": "./scripts/test",
21
- "build": "./scripts/build",
22
- "format": "./scripts/format",
23
- "tsn": "ts-node -r tsconfig-paths/register",
24
- "lint": "./scripts/lint",
25
- "fix": "./scripts/format"
26
- },
27
18
  "dependencies": {},
28
19
  "exports": {
29
20
  ".": {
@@ -134,5 +125,13 @@
134
125
  "./version.mjs": {
135
126
  "default": "./version.mjs"
136
127
  }
128
+ },
129
+ "scripts": {
130
+ "test": "./scripts/test",
131
+ "build": "./scripts/build",
132
+ "format": "./scripts/format",
133
+ "tsn": "ts-node -r tsconfig-paths/register",
134
+ "lint": "./scripts/lint",
135
+ "fix": "./scripts/format"
137
136
  }
138
137
  }
@@ -0,0 +1,145 @@
1
+ import { APIResource } from "../core/resource.mjs";
2
+ import { APIPromise } from "../core/api-promise.mjs";
3
+ import { type Uploadable } from "../core/uploads.mjs";
4
+ import { RequestOptions } from "../internal/request-options.mjs";
5
+ export declare class CustomRouter extends APIResource {
6
+ /**
7
+ * Train a custom router on your evaluation data to optimize routing for your
8
+ * specific use case.
9
+ *
10
+ * This endpoint allows you to train a domain-specific router that learns which
11
+ * models perform best for different types of queries in your application. The
12
+ * router analyzes your evaluation dataset, clusters similar queries, and learns
13
+ * model performance patterns.
14
+ *
15
+ * **Training Process:**
16
+ *
17
+ * 1. Upload a CSV file with your evaluation data
18
+ * 2. Specify which models to route between
19
+ * 3. Define the evaluation metric (score column)
20
+ * 4. The system trains asynchronously and returns a preference_id
21
+ * 5. Use the preference_id in model_select() calls once training completes
22
+ *
23
+ * **Dataset Requirements:**
24
+ *
25
+ * - Format: CSV file
26
+ * - Minimum samples: 25 (more is better for accuracy)
27
+ * - Required columns:
28
+ * - Prompt column (specified in prompt_column parameter)
29
+ * - For each model: `{provider}/{model}/score` and `{provider}/{model}/response`
30
+ *
31
+ * **Example CSV structure:**
32
+ *
33
+ * ```
34
+ * prompt,openai/gpt-4o/score,openai/gpt-4o/response,anthropic/claude-sonnet-4-5-20250929/score,anthropic/claude-sonnet-4-5-20250929/response
35
+ * "Explain quantum computing",0.95,"Quantum computing uses...",0.87,"Quantum computers leverage..."
36
+ * "Write a Python function",0.82,"def my_function()...",0.91,"Here's a Python function..."
37
+ * ```
38
+ *
39
+ * **Model Selection:**
40
+ *
41
+ * - Specify standard models: `{"provider": "openai", "model": "gpt-4o"}`
42
+ * - Or custom models with pricing:
43
+ * `{"provider": "custom", "model": "my-model", "is_custom": true, "input_price": 10.0, "output_price": 30.0, "context_length": 8192, "latency": 1.5}`
44
+ *
45
+ * **Training Time:**
46
+ *
47
+ * - Training is asynchronous and typically takes 5-15 minutes
48
+ * - Larger datasets or more models take longer
49
+ * - You'll receive a preference_id immediately
50
+ * - Check training status by attempting to use the preference_id in model_select()
51
+ *
52
+ * **Best Practices:**
53
+ *
54
+ * 1. Use diverse, representative examples from your production workload
55
+ * 2. Include at least 50-100 samples for best results
56
+ * 3. Ensure consistent evaluation metrics across all models
57
+ * 4. Use the same models you plan to route between in production
58
+ *
59
+ * **Related Documentation:** See
60
+ * https://docs.notdiamond.ai/docs/adapting-prompts-to-new-models for detailed
61
+ * guide.
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * const response =
66
+ * await client.customRouter.trainCustomRouter({
67
+ * dataset_file: fs.createReadStream('path/to/file'),
68
+ * language: 'english',
69
+ * llm_providers:
70
+ * '[{"provider": "openai", "model": "gpt-4o"}, {"provider": "anthropic", "model": "claude-sonnet-4-5-20250929"}]',
71
+ * maximize: true,
72
+ * prompt_column: 'prompt',
73
+ * });
74
+ * ```
75
+ */
76
+ trainCustomRouter(body: CustomRouterTrainCustomRouterParams, options?: RequestOptions): APIPromise<CustomRouterTrainCustomRouterResponse>;
77
+ }
78
+ /**
79
+ * Response model for POST /v2/pzn/trainCustomRouter endpoint.
80
+ *
81
+ * Returned immediately after submitting a custom router training request. The
82
+ * training process runs asynchronously (typically 5-15 minutes), so use the
83
+ * returned preference_id to make routing calls once training completes.
84
+ *
85
+ * **Next steps:**
86
+ *
87
+ * 1. Store the preference_id
88
+ * 2. Wait for training to complete (typically 5-15 minutes)
89
+ * 3. Use this preference_id in POST /v2/modelRouter/modelSelect requests
90
+ * 4. The router will use your custom-trained model to make routing decisions
91
+ *
92
+ * **How to use the preference_id:**
93
+ *
94
+ * - Include it in the 'preference_id' field of model_select() calls
95
+ * - The system automatically uses your custom router once training is complete
96
+ * - No need to poll status - you can start using it immediately (will use default
97
+ * until ready)
98
+ */
99
+ export interface CustomRouterTrainCustomRouterResponse {
100
+ /**
101
+ * Unique identifier for the custom router. Use this in model_select() calls to
102
+ * enable routing with your custom-trained router
103
+ */
104
+ preference_id: string;
105
+ }
106
+ export interface CustomRouterTrainCustomRouterParams {
107
+ /**
108
+ * CSV file containing evaluation data with prompt column and score/response
109
+ * columns for each model
110
+ */
111
+ dataset_file: Uploadable;
112
+ /**
113
+ * Language of the evaluation data. Use 'english' for English-only data or
114
+ * 'multilingual' for multi-language support
115
+ */
116
+ language: string;
117
+ /**
118
+ * JSON string array of LLM providers to train the router on. Format:
119
+ * '[{"provider": "openai", "model": "gpt-4o"}, {"provider": "anthropic", "model":
120
+ * "claude-sonnet-4-5-20250929"}]'
121
+ */
122
+ llm_providers: string;
123
+ /**
124
+ * Whether higher scores are better. Set to true if higher scores indicate better
125
+ * performance, false otherwise
126
+ */
127
+ maximize: boolean;
128
+ /**
129
+ * Name of the column in the CSV file that contains the prompts
130
+ */
131
+ prompt_column: string;
132
+ /**
133
+ * Whether to override an existing custom router for this preference_id
134
+ */
135
+ override?: boolean | null;
136
+ /**
137
+ * Optional preference ID to update an existing router. If not provided, a new
138
+ * preference will be created
139
+ */
140
+ preference_id?: string | null;
141
+ }
142
+ export declare namespace CustomRouter {
143
+ export { type CustomRouterTrainCustomRouterResponse as CustomRouterTrainCustomRouterResponse, type CustomRouterTrainCustomRouterParams as CustomRouterTrainCustomRouterParams, };
144
+ }
145
+ //# sourceMappingURL=custom-router.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"custom-router.d.mts","sourceRoot":"","sources":["../src/resources/custom-router.ts"],"names":[],"mappings":"OAEO,EAAE,WAAW,EAAE;OACf,EAAE,UAAU,EAAE;OACd,EAAE,KAAK,UAAU,EAAE;OACnB,EAAE,cAAc,EAAE;AAGzB,qBAAa,YAAa,SAAQ,WAAW;IAC3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqEG;IACH,iBAAiB,CACf,IAAI,EAAE,mCAAmC,EACzC,OAAO,CAAC,EAAE,cAAc,GACvB,UAAU,CAAC,qCAAqC,CAAC;CAMrD;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,WAAW,qCAAqC;IACpD;;;OAGG;IACH,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,mCAAmC;IAClD;;;OAGG;IACH,YAAY,EAAE,UAAU,CAAC;IAEzB;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;;OAIG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,QAAQ,EAAE,OAAO,CAAC;IAElB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAE1B;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B;AAED,MAAM,CAAC,OAAO,WAAW,YAAY,CAAC;IACpC,OAAO,EACL,KAAK,qCAAqC,IAAI,qCAAqC,EACnF,KAAK,mCAAmC,IAAI,mCAAmC,GAChF,CAAC;CACH"}
@@ -0,0 +1,145 @@
1
+ import { APIResource } from "../core/resource.js";
2
+ import { APIPromise } from "../core/api-promise.js";
3
+ import { type Uploadable } from "../core/uploads.js";
4
+ import { RequestOptions } from "../internal/request-options.js";
5
+ export declare class CustomRouter extends APIResource {
6
+ /**
7
+ * Train a custom router on your evaluation data to optimize routing for your
8
+ * specific use case.
9
+ *
10
+ * This endpoint allows you to train a domain-specific router that learns which
11
+ * models perform best for different types of queries in your application. The
12
+ * router analyzes your evaluation dataset, clusters similar queries, and learns
13
+ * model performance patterns.
14
+ *
15
+ * **Training Process:**
16
+ *
17
+ * 1. Upload a CSV file with your evaluation data
18
+ * 2. Specify which models to route between
19
+ * 3. Define the evaluation metric (score column)
20
+ * 4. The system trains asynchronously and returns a preference_id
21
+ * 5. Use the preference_id in model_select() calls once training completes
22
+ *
23
+ * **Dataset Requirements:**
24
+ *
25
+ * - Format: CSV file
26
+ * - Minimum samples: 25 (more is better for accuracy)
27
+ * - Required columns:
28
+ * - Prompt column (specified in prompt_column parameter)
29
+ * - For each model: `{provider}/{model}/score` and `{provider}/{model}/response`
30
+ *
31
+ * **Example CSV structure:**
32
+ *
33
+ * ```
34
+ * prompt,openai/gpt-4o/score,openai/gpt-4o/response,anthropic/claude-sonnet-4-5-20250929/score,anthropic/claude-sonnet-4-5-20250929/response
35
+ * "Explain quantum computing",0.95,"Quantum computing uses...",0.87,"Quantum computers leverage..."
36
+ * "Write a Python function",0.82,"def my_function()...",0.91,"Here's a Python function..."
37
+ * ```
38
+ *
39
+ * **Model Selection:**
40
+ *
41
+ * - Specify standard models: `{"provider": "openai", "model": "gpt-4o"}`
42
+ * - Or custom models with pricing:
43
+ * `{"provider": "custom", "model": "my-model", "is_custom": true, "input_price": 10.0, "output_price": 30.0, "context_length": 8192, "latency": 1.5}`
44
+ *
45
+ * **Training Time:**
46
+ *
47
+ * - Training is asynchronous and typically takes 5-15 minutes
48
+ * - Larger datasets or more models take longer
49
+ * - You'll receive a preference_id immediately
50
+ * - Check training status by attempting to use the preference_id in model_select()
51
+ *
52
+ * **Best Practices:**
53
+ *
54
+ * 1. Use diverse, representative examples from your production workload
55
+ * 2. Include at least 50-100 samples for best results
56
+ * 3. Ensure consistent evaluation metrics across all models
57
+ * 4. Use the same models you plan to route between in production
58
+ *
59
+ * **Related Documentation:** See
60
+ * https://docs.notdiamond.ai/docs/adapting-prompts-to-new-models for detailed
61
+ * guide.
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * const response =
66
+ * await client.customRouter.trainCustomRouter({
67
+ * dataset_file: fs.createReadStream('path/to/file'),
68
+ * language: 'english',
69
+ * llm_providers:
70
+ * '[{"provider": "openai", "model": "gpt-4o"}, {"provider": "anthropic", "model": "claude-sonnet-4-5-20250929"}]',
71
+ * maximize: true,
72
+ * prompt_column: 'prompt',
73
+ * });
74
+ * ```
75
+ */
76
+ trainCustomRouter(body: CustomRouterTrainCustomRouterParams, options?: RequestOptions): APIPromise<CustomRouterTrainCustomRouterResponse>;
77
+ }
78
+ /**
79
+ * Response model for POST /v2/pzn/trainCustomRouter endpoint.
80
+ *
81
+ * Returned immediately after submitting a custom router training request. The
82
+ * training process runs asynchronously (typically 5-15 minutes), so use the
83
+ * returned preference_id to make routing calls once training completes.
84
+ *
85
+ * **Next steps:**
86
+ *
87
+ * 1. Store the preference_id
88
+ * 2. Wait for training to complete (typically 5-15 minutes)
89
+ * 3. Use this preference_id in POST /v2/modelRouter/modelSelect requests
90
+ * 4. The router will use your custom-trained model to make routing decisions
91
+ *
92
+ * **How to use the preference_id:**
93
+ *
94
+ * - Include it in the 'preference_id' field of model_select() calls
95
+ * - The system automatically uses your custom router once training is complete
96
+ * - No need to poll status - you can start using it immediately (will use default
97
+ * until ready)
98
+ */
99
+ export interface CustomRouterTrainCustomRouterResponse {
100
+ /**
101
+ * Unique identifier for the custom router. Use this in model_select() calls to
102
+ * enable routing with your custom-trained router
103
+ */
104
+ preference_id: string;
105
+ }
106
+ export interface CustomRouterTrainCustomRouterParams {
107
+ /**
108
+ * CSV file containing evaluation data with prompt column and score/response
109
+ * columns for each model
110
+ */
111
+ dataset_file: Uploadable;
112
+ /**
113
+ * Language of the evaluation data. Use 'english' for English-only data or
114
+ * 'multilingual' for multi-language support
115
+ */
116
+ language: string;
117
+ /**
118
+ * JSON string array of LLM providers to train the router on. Format:
119
+ * '[{"provider": "openai", "model": "gpt-4o"}, {"provider": "anthropic", "model":
120
+ * "claude-sonnet-4-5-20250929"}]'
121
+ */
122
+ llm_providers: string;
123
+ /**
124
+ * Whether higher scores are better. Set to true if higher scores indicate better
125
+ * performance, false otherwise
126
+ */
127
+ maximize: boolean;
128
+ /**
129
+ * Name of the column in the CSV file that contains the prompts
130
+ */
131
+ prompt_column: string;
132
+ /**
133
+ * Whether to override an existing custom router for this preference_id
134
+ */
135
+ override?: boolean | null;
136
+ /**
137
+ * Optional preference ID to update an existing router. If not provided, a new
138
+ * preference will be created
139
+ */
140
+ preference_id?: string | null;
141
+ }
142
+ export declare namespace CustomRouter {
143
+ export { type CustomRouterTrainCustomRouterResponse as CustomRouterTrainCustomRouterResponse, type CustomRouterTrainCustomRouterParams as CustomRouterTrainCustomRouterParams, };
144
+ }
145
+ //# sourceMappingURL=custom-router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"custom-router.d.ts","sourceRoot":"","sources":["../src/resources/custom-router.ts"],"names":[],"mappings":"OAEO,EAAE,WAAW,EAAE;OACf,EAAE,UAAU,EAAE;OACd,EAAE,KAAK,UAAU,EAAE;OACnB,EAAE,cAAc,EAAE;AAGzB,qBAAa,YAAa,SAAQ,WAAW;IAC3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqEG;IACH,iBAAiB,CACf,IAAI,EAAE,mCAAmC,EACzC,OAAO,CAAC,EAAE,cAAc,GACvB,UAAU,CAAC,qCAAqC,CAAC;CAMrD;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,WAAW,qCAAqC;IACpD;;;OAGG;IACH,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,mCAAmC;IAClD;;;OAGG;IACH,YAAY,EAAE,UAAU,CAAC;IAEzB;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;;OAIG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,QAAQ,EAAE,OAAO,CAAC;IAElB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAE1B;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B;AAED,MAAM,CAAC,OAAO,WAAW,YAAY,CAAC;IACpC,OAAO,EACL,KAAK,qCAAqC,IAAI,qCAAqC,EACnF,KAAK,mCAAmC,IAAI,mCAAmC,GAChF,CAAC;CACH"}