@ai-sdk/typesafe-ai 3.0.9 → 3.0.11

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,22 @@
1
1
  # @ai-sdk/typesafe-ai
2
2
 
3
+ ## 3.0.11
4
+
5
+ ### Patch Changes
6
+
7
+ - ede5b89: chore: migrate package builds from tsup to tsdown
8
+ - Updated dependencies [ede5b89]
9
+ - @ai-sdk/provider@4.0.20
10
+ - @ai-sdk/provider-utils@5.0.52
11
+
12
+ ## 3.0.10
13
+
14
+ ### Patch Changes
15
+
16
+ - c2511c1: fix: use standards-compliant User-Agent header
17
+ - Updated dependencies [c2511c1]
18
+ - @ai-sdk/provider-utils@5.0.51
19
+
3
20
  ## 3.0.9
4
21
 
5
22
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,23 +1,26 @@
1
- import { ProviderV4, Experimental_EvaluationModelV4 } from '@ai-sdk/provider';
2
- import { FetchFunction } from '@ai-sdk/provider-utils';
3
-
1
+ import { Experimental_EvaluationModelV4, ProviderV4 } from "@ai-sdk/provider";
2
+ import { FetchFunction, WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE } from "@ai-sdk/provider-utils";
3
+ //#region src/typesafe-ai-evaluation-model.d.ts
4
4
  type TypeSafeAiEvaluationModelId = 'jev-latest' | (string & {});
5
-
5
+ //#endregion
6
+ //#region src/typesafe-ai-provider.d.ts
6
7
  /** TypeSafe's experimental evaluation capability, isolated from ProviderV4. */
7
8
  interface TypeSafeAiProvider extends ProviderV4 {
8
- evaluationModel(modelId: TypeSafeAiEvaluationModelId): Experimental_EvaluationModelV4;
9
+ evaluationModel(modelId: TypeSafeAiEvaluationModelId): Experimental_EvaluationModelV4;
9
10
  }
10
11
  interface TypeSafeAiProviderSettings {
11
- /** API key. Defaults to the TYPESAFE_AI_API_KEY environment variable. */
12
- apiKey?: string;
13
- /** API base URL. Defaults to https://api.typesafe.ai/v1. */
14
- baseURL?: string;
15
- headers?: Record<string, string>;
16
- fetch?: FetchFunction;
12
+ /** API key. Defaults to the TYPESAFE_AI_API_KEY environment variable. */
13
+ apiKey?: string;
14
+ /** API base URL. Defaults to https://api.typesafe.ai/v1. */
15
+ baseURL?: string;
16
+ headers?: Record<string, string>;
17
+ fetch?: FetchFunction;
17
18
  }
18
- declare function createTypeSafeAi(options?: TypeSafeAiProviderSettings): TypeSafeAiProvider;
19
- declare const typeSafeAi: TypeSafeAiProvider;
20
-
21
- declare const VERSION: string;
22
-
23
- export { type TypeSafeAiEvaluationModelId as Experimental_TypeSafeAiEvaluationModelId, type TypeSafeAiProvider, type TypeSafeAiProviderSettings, VERSION, createTypeSafeAi, typeSafeAi };
19
+ export declare function createTypeSafeAi(options?: TypeSafeAiProviderSettings): TypeSafeAiProvider;
20
+ export declare const typeSafeAi: TypeSafeAiProvider;
21
+ //#endregion
22
+ //#region src/version.d.ts
23
+ export declare const VERSION: string;
24
+ //#endregion
25
+ export type { TypeSafeAiEvaluationModelId as Experimental_TypeSafeAiEvaluationModelId, TypeSafeAiProvider, TypeSafeAiProviderSettings };
26
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":["EvaluationModelV4"],"sources":["../src/typesafe-ai-evaluation-model.ts","../src/typesafe-ai-provider.ts","../src/version.ts"],"mappings":";;;KAyBY;;;;UCPK,2BAA2B;EAC1C,gBAAgB,SAAS,8BAA8BA;;UAGxC;;EAEf;;EAEA;EACA,UAAU;EACV,QAAQ;;wBAGM,iBACd,UAAS,6BACR;qBAiCU,YAAU;;;qBChEV"}
package/dist/index.js CHANGED
@@ -1,231 +1,185 @@
1
- // src/typesafe-ai-provider.ts
2
- import {
3
- NoSuchModelError
4
- } from "@ai-sdk/provider";
5
- import {
6
- loadApiKey as loadApiKey2,
7
- withoutTrailingSlash,
8
- withUserAgentSuffix as withUserAgentSuffix2
9
- } from "@ai-sdk/provider-utils";
10
-
11
- // src/typesafe-ai-evaluation-model.ts
12
- import {
13
- InvalidArgumentError
14
- } from "@ai-sdk/provider";
15
- import {
16
- combineHeaders,
17
- createJsonResponseHandler,
18
- loadApiKey,
19
- postJsonToApi,
20
- resolve,
21
- serializeModelOptions,
22
- withUserAgentSuffix,
23
- WORKFLOW_SERIALIZE,
24
- WORKFLOW_DESERIALIZE
25
- } from "@ai-sdk/provider-utils";
26
-
27
- // src/typesafe-ai-evaluation-api.ts
28
- import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
1
+ import { InvalidArgumentError, NoSuchModelError } from "@ai-sdk/provider";
2
+ import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, createJsonErrorResponseHandler, createJsonResponseHandler, loadApiKey, postJsonToApi, resolve, serializeModelOptions, withUserAgentSuffix, withoutTrailingSlash } from "@ai-sdk/provider-utils";
29
3
  import * as z from "zod/v4";
30
- var typesafeEvaluationResponseSchema = z.object({
31
- model: z.string().nullish(),
32
- answers: z.record(
33
- z.string(),
34
- z.discriminatedUnion("type", [
35
- z.object({
36
- type: z.literal("choice"),
37
- choice: z.string(),
38
- probabilities: z.record(z.string(), z.number()),
39
- confidence: z.number().nullish()
40
- }),
41
- z.object({
42
- type: z.literal("score"),
43
- score: z.number(),
44
- probabilities: z.record(z.string(), z.number()),
45
- confidence: z.number().nullish()
46
- }),
47
- z.object({ type: z.literal("noul"), noul: z.number() })
48
- ])
49
- ),
50
- usage: z.object({
51
- input_tokens: z.number().nullish(),
52
- output_tokens: z.number().nullish()
53
- }).nullish()
4
+ //#region src/typesafe-ai-evaluation-api.ts
5
+ const typesafeEvaluationResponseSchema = z.object({
6
+ model: z.string().nullish(),
7
+ answers: z.record(z.string(), z.discriminatedUnion("type", [
8
+ z.object({
9
+ type: z.literal("choice"),
10
+ choice: z.string(),
11
+ probabilities: z.record(z.string(), z.number()),
12
+ confidence: z.number().nullish()
13
+ }),
14
+ z.object({
15
+ type: z.literal("score"),
16
+ score: z.number(),
17
+ probabilities: z.record(z.string(), z.number()),
18
+ confidence: z.number().nullish()
19
+ }),
20
+ z.object({
21
+ type: z.literal("noul"),
22
+ noul: z.number()
23
+ })
24
+ ])),
25
+ usage: z.object({
26
+ input_tokens: z.number().nullish(),
27
+ output_tokens: z.number().nullish()
28
+ }).nullish()
54
29
  });
55
- var typesafeFailedResponseHandler = createJsonErrorResponseHandler({
56
- errorSchema: z.object({
57
- message: z.string().nullish(),
58
- detail: z.unknown().nullish(),
59
- error: z.union([z.string(), z.object({ message: z.string().nullish() })]).nullish(),
60
- error_type: z.string().nullish()
61
- }),
62
- errorToMessage: (error) => error.message ?? (typeof error.error === "string" ? error.error : error.error?.message) ?? (typeof error.detail === "string" ? error.detail : JSON.stringify(error.detail)) ?? error.error_type ?? "TypeSafe request failed"
30
+ const typesafeFailedResponseHandler = createJsonErrorResponseHandler({
31
+ errorSchema: z.object({
32
+ message: z.string().nullish(),
33
+ detail: z.unknown().nullish(),
34
+ error: z.union([z.string(), z.object({ message: z.string().nullish() })]).nullish(),
35
+ error_type: z.string().nullish()
36
+ }),
37
+ errorToMessage: (error) => error.message ?? (typeof error.error === "string" ? error.error : error.error?.message) ?? (typeof error.detail === "string" ? error.detail : JSON.stringify(error.detail)) ?? error.error_type ?? "TypeSafe request failed"
63
38
  });
64
-
65
- // src/version.ts
66
- var VERSION = true ? "3.0.9" : "0.0.0-test";
67
-
68
- // src/typesafe-ai-evaluation-model.ts
69
- var EvaluationTypeSafeAiModel = class _EvaluationTypeSafeAiModel {
70
- constructor(modelId, config) {
71
- this.modelId = modelId;
72
- this.config = config;
73
- this.specificationVersion = "v4";
74
- this.supportedQuestionTypes = ["choice", "score", "boolean"];
75
- }
76
- get provider() {
77
- return this.config.provider;
78
- }
79
- static [WORKFLOW_SERIALIZE](model) {
80
- return serializeModelOptions({
81
- modelId: model.modelId,
82
- config: model.config
83
- });
84
- }
85
- static [WORKFLOW_DESERIALIZE](options) {
86
- return new _EvaluationTypeSafeAiModel(options.modelId, options.config);
87
- }
88
- async doEvaluate({
89
- state,
90
- questions,
91
- headers,
92
- abortSignal,
93
- providerOptions
94
- }) {
95
- for (const [id, question] of Object.entries(questions)) {
96
- if (question.type === "choice" && Object.keys(question.criteria).length > 255) {
97
- throw new InvalidArgumentError({
98
- argument: `questions.${id}.criteria`,
99
- message: "TypeSafe Choice questions support at most 255 options."
100
- });
101
- }
102
- if (question.type === "score" && question.criteria.length > 10) {
103
- throw new InvalidArgumentError({
104
- argument: `questions.${id}.criteria`,
105
- message: "TypeSafe Score questions support at most 10 levels."
106
- });
107
- }
108
- }
109
- const warnings = Object.keys(
110
- providerOptions?.typesafe ?? {}
111
- ).map((option) => ({
112
- type: "unsupported",
113
- feature: `providerOptions.typesafe.${option}`
114
- }));
115
- const modelHeaders = this.config.headers === void 0 ? withUserAgentSuffix(
116
- {
117
- Authorization: `Bearer ${loadApiKey({ apiKey: void 0, environmentVariableName: "TYPESAFE_AI_API_KEY", description: "TypeSafe" })}`
118
- },
119
- `ai-sdk/typesafe-ai/${VERSION}`
120
- ) : await resolve(this.config.headers);
121
- const {
122
- value: response,
123
- rawValue,
124
- responseHeaders
125
- } = await postJsonToApi({
126
- url: `${this.config.baseURL}/systemone`,
127
- headers: combineHeaders(modelHeaders, headers),
128
- body: {
129
- model: this.modelId,
130
- state,
131
- questions: Object.fromEntries(
132
- Object.entries(questions).map(([id, question]) => [
133
- id,
134
- question.type === "boolean" ? { ...question, type: "noul" } : question
135
- ])
136
- )
137
- },
138
- abortSignal,
139
- fetch: this.config.fetch,
140
- failedResponseHandler: typesafeFailedResponseHandler,
141
- successfulResponseHandler: createJsonResponseHandler(
142
- typesafeEvaluationResponseSchema
143
- )
144
- });
145
- const confidence = Object.fromEntries(
146
- Object.entries(response.answers).flatMap(
147
- ([id, answer]) => answer.type !== "noul" && answer.confidence != null ? [[id, answer.confidence]] : []
148
- )
149
- );
150
- return {
151
- answers: Object.fromEntries(
152
- Object.entries(response.answers).map(
153
- ([id, answer]) => {
154
- switch (answer.type) {
155
- case "noul":
156
- return [id, { type: "boolean", probability: answer.noul }];
157
- case "choice":
158
- return [
159
- id,
160
- {
161
- type: "choice",
162
- choice: answer.choice,
163
- probabilities: answer.probabilities
164
- }
165
- ];
166
- case "score":
167
- return [
168
- id,
169
- {
170
- type: "score",
171
- score: answer.score,
172
- probabilities: answer.probabilities
173
- }
174
- ];
175
- }
176
- }
177
- )
178
- ),
179
- usage: {
180
- inputTokens: response.usage?.input_tokens ?? void 0,
181
- outputTokens: response.usage?.output_tokens ?? void 0
182
- },
183
- // The API rounds displayed probabilities and scores to two decimal places.
184
- rounding: { probabilityDecimals: 2, scoreDecimals: 2 },
185
- warnings,
186
- providerMetadata: { typesafe: { confidence } },
187
- response: {
188
- modelId: response.model ?? this.modelId,
189
- headers: responseHeaders,
190
- body: rawValue
191
- }
192
- };
193
- }
39
+ //#endregion
40
+ //#region src/version.ts
41
+ const VERSION = "3.0.11";
42
+ //#endregion
43
+ //#region src/typesafe-ai-evaluation-model.ts
44
+ var EvaluationTypeSafeAiModel = class EvaluationTypeSafeAiModel {
45
+ constructor(modelId, config) {
46
+ this.modelId = modelId;
47
+ this.config = config;
48
+ this.specificationVersion = "v4";
49
+ this.supportedQuestionTypes = [
50
+ "choice",
51
+ "score",
52
+ "boolean"
53
+ ];
54
+ }
55
+ get provider() {
56
+ return this.config.provider;
57
+ }
58
+ static [WORKFLOW_SERIALIZE](model) {
59
+ return serializeModelOptions({
60
+ modelId: model.modelId,
61
+ config: model.config
62
+ });
63
+ }
64
+ static [WORKFLOW_DESERIALIZE](options) {
65
+ return new EvaluationTypeSafeAiModel(options.modelId, options.config);
66
+ }
67
+ async doEvaluate({ state, questions, headers, abortSignal, providerOptions }) {
68
+ for (const [id, question] of Object.entries(questions)) {
69
+ if (question.type === "choice" && Object.keys(question.criteria).length > 255) throw new InvalidArgumentError({
70
+ argument: `questions.${id}.criteria`,
71
+ message: "TypeSafe Choice questions support at most 255 options."
72
+ });
73
+ if (question.type === "score" && question.criteria.length > 10) throw new InvalidArgumentError({
74
+ argument: `questions.${id}.criteria`,
75
+ message: "TypeSafe Score questions support at most 10 levels."
76
+ });
77
+ }
78
+ const warnings = Object.keys(providerOptions?.typesafe ?? {}).map((option) => ({
79
+ type: "unsupported",
80
+ feature: `providerOptions.typesafe.${option}`
81
+ }));
82
+ const modelHeaders = this.config.headers === void 0 ? withUserAgentSuffix({ Authorization: `Bearer ${loadApiKey({
83
+ apiKey: void 0,
84
+ environmentVariableName: "TYPESAFE_AI_API_KEY",
85
+ description: "TypeSafe"
86
+ })}` }, `ai-sdk-typesafe-ai/${VERSION}`) : await resolve(this.config.headers);
87
+ const { value: response, rawValue, responseHeaders } = await postJsonToApi({
88
+ url: `${this.config.baseURL}/systemone`,
89
+ headers: combineHeaders(modelHeaders, headers),
90
+ body: {
91
+ model: this.modelId,
92
+ state,
93
+ questions: Object.fromEntries(Object.entries(questions).map(([id, question]) => [id, question.type === "boolean" ? {
94
+ ...question,
95
+ type: "noul"
96
+ } : question]))
97
+ },
98
+ abortSignal,
99
+ fetch: this.config.fetch,
100
+ failedResponseHandler: typesafeFailedResponseHandler,
101
+ successfulResponseHandler: createJsonResponseHandler(typesafeEvaluationResponseSchema)
102
+ });
103
+ const confidence = Object.fromEntries(Object.entries(response.answers).flatMap(([id, answer]) => answer.type !== "noul" && answer.confidence != null ? [[id, answer.confidence]] : []));
104
+ return {
105
+ answers: Object.fromEntries(Object.entries(response.answers).map(([id, answer]) => {
106
+ switch (answer.type) {
107
+ case "noul": return [id, {
108
+ type: "boolean",
109
+ probability: answer.noul
110
+ }];
111
+ case "choice": return [id, {
112
+ type: "choice",
113
+ choice: answer.choice,
114
+ probabilities: answer.probabilities
115
+ }];
116
+ case "score": return [id, {
117
+ type: "score",
118
+ score: answer.score,
119
+ probabilities: answer.probabilities
120
+ }];
121
+ }
122
+ })),
123
+ usage: {
124
+ inputTokens: response.usage?.input_tokens ?? void 0,
125
+ outputTokens: response.usage?.output_tokens ?? void 0
126
+ },
127
+ rounding: {
128
+ probabilityDecimals: 2,
129
+ scoreDecimals: 2
130
+ },
131
+ warnings,
132
+ providerMetadata: { typesafe: { confidence } },
133
+ response: {
134
+ modelId: response.model ?? this.modelId,
135
+ headers: responseHeaders,
136
+ body: rawValue
137
+ }
138
+ };
139
+ }
194
140
  };
195
-
196
- // src/typesafe-ai-provider.ts
141
+ //#endregion
142
+ //#region src/typesafe-ai-provider.ts
197
143
  function createTypeSafeAi(options = {}) {
198
- const baseURL = withoutTrailingSlash(options.baseURL) ?? "https://api.typesafe.ai/v1";
199
- const headers = () => withUserAgentSuffix2(
200
- {
201
- Authorization: `Bearer ${loadApiKey2({ apiKey: options.apiKey, environmentVariableName: "TYPESAFE_AI_API_KEY", description: "TypeSafe" })}`,
202
- ...options.headers
203
- },
204
- `ai-sdk/typesafe-ai/${VERSION}`
205
- );
206
- return {
207
- specificationVersion: "v4",
208
- evaluationModel: (modelId) => new EvaluationTypeSafeAiModel(modelId, {
209
- provider: "typesafe.evaluation",
210
- baseURL,
211
- headers,
212
- fetch: options.fetch
213
- }),
214
- languageModel: (modelId) => {
215
- throw new NoSuchModelError({ modelId, modelType: "languageModel" });
216
- },
217
- embeddingModel: (modelId) => {
218
- throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
219
- },
220
- imageModel: (modelId) => {
221
- throw new NoSuchModelError({ modelId, modelType: "imageModel" });
222
- }
223
- };
144
+ const baseURL = withoutTrailingSlash(options.baseURL) ?? "https://api.typesafe.ai/v1";
145
+ const headers = () => withUserAgentSuffix({
146
+ Authorization: `Bearer ${loadApiKey({
147
+ apiKey: options.apiKey,
148
+ environmentVariableName: "TYPESAFE_AI_API_KEY",
149
+ description: "TypeSafe"
150
+ })}`,
151
+ ...options.headers
152
+ }, `ai-sdk-typesafe-ai/${VERSION}`);
153
+ return {
154
+ specificationVersion: "v4",
155
+ evaluationModel: (modelId) => new EvaluationTypeSafeAiModel(modelId, {
156
+ provider: "typesafe.evaluation",
157
+ baseURL,
158
+ headers,
159
+ fetch: options.fetch
160
+ }),
161
+ languageModel: (modelId) => {
162
+ throw new NoSuchModelError({
163
+ modelId,
164
+ modelType: "languageModel"
165
+ });
166
+ },
167
+ embeddingModel: (modelId) => {
168
+ throw new NoSuchModelError({
169
+ modelId,
170
+ modelType: "embeddingModel"
171
+ });
172
+ },
173
+ imageModel: (modelId) => {
174
+ throw new NoSuchModelError({
175
+ modelId,
176
+ modelType: "imageModel"
177
+ });
178
+ }
179
+ };
224
180
  }
225
- var typeSafeAi = createTypeSafeAi();
226
- export {
227
- VERSION,
228
- createTypeSafeAi,
229
- typeSafeAi
230
- };
181
+ const typeSafeAi = createTypeSafeAi();
182
+ //#endregion
183
+ export { VERSION, createTypeSafeAi, typeSafeAi };
184
+
231
185
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/typesafe-ai-provider.ts","../src/typesafe-ai-evaluation-model.ts","../src/typesafe-ai-evaluation-api.ts","../src/version.ts"],"sourcesContent":["import {\n NoSuchModelError,\n type Experimental_EvaluationModelV4 as EvaluationModelV4,\n type ProviderV4,\n} from '@ai-sdk/provider';\nimport {\n loadApiKey,\n withoutTrailingSlash,\n withUserAgentSuffix,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport {\n EvaluationTypeSafeAiModel,\n type TypeSafeAiEvaluationModelId,\n} from './typesafe-ai-evaluation-model';\nimport { VERSION } from './version';\n\n/** TypeSafe's experimental evaluation capability, isolated from ProviderV4. */\nexport interface TypeSafeAiProvider extends ProviderV4 {\n evaluationModel(modelId: TypeSafeAiEvaluationModelId): EvaluationModelV4;\n}\n\nexport interface TypeSafeAiProviderSettings {\n /** API key. Defaults to the TYPESAFE_AI_API_KEY environment variable. */\n apiKey?: string;\n /** API base URL. Defaults to https://api.typesafe.ai/v1. */\n baseURL?: string;\n headers?: Record<string, string>;\n fetch?: FetchFunction;\n}\n\nexport function createTypeSafeAi(\n options: TypeSafeAiProviderSettings = {},\n): TypeSafeAiProvider {\n const baseURL =\n withoutTrailingSlash(options.baseURL) ?? 'https://api.typesafe.ai/v1';\n const headers = () =>\n withUserAgentSuffix(\n {\n Authorization: `Bearer ${loadApiKey({ apiKey: options.apiKey, environmentVariableName: 'TYPESAFE_AI_API_KEY', description: 'TypeSafe' })}`,\n ...options.headers,\n },\n `ai-sdk/typesafe-ai/${VERSION}`,\n );\n\n return {\n specificationVersion: 'v4',\n evaluationModel: modelId =>\n new EvaluationTypeSafeAiModel(modelId, {\n provider: 'typesafe.evaluation',\n baseURL,\n headers,\n fetch: options.fetch,\n }),\n languageModel: modelId => {\n throw new NoSuchModelError({ modelId, modelType: 'languageModel' });\n },\n embeddingModel: modelId => {\n throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });\n },\n imageModel: modelId => {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n },\n };\n}\n\nexport const typeSafeAi = createTypeSafeAi();\n","import {\n InvalidArgumentError,\n type Experimental_EvaluationModelV4 as EvaluationModelV4,\n type Experimental_EvaluationModelV4Answer as EvaluationModelV4Answer,\n type SharedV4Warning,\n} from '@ai-sdk/provider';\nimport {\n combineHeaders,\n createJsonResponseHandler,\n loadApiKey,\n postJsonToApi,\n resolve,\n serializeModelOptions,\n withUserAgentSuffix,\n WORKFLOW_SERIALIZE,\n WORKFLOW_DESERIALIZE,\n type FetchFunction,\n type Resolvable,\n} from '@ai-sdk/provider-utils';\nimport {\n typesafeEvaluationResponseSchema,\n typesafeFailedResponseHandler,\n} from './typesafe-ai-evaluation-api';\nimport { VERSION } from './version';\n\nexport type TypeSafeAiEvaluationModelId = 'jev-latest' | (string & {});\n\ntype TypeSafeAiEvaluationModelConfig = {\n provider: string;\n baseURL: string;\n headers?: Resolvable<Record<string, string | undefined>>;\n fetch?: FetchFunction;\n};\n\nexport class EvaluationTypeSafeAiModel implements EvaluationModelV4 {\n readonly specificationVersion = 'v4';\n readonly supportedQuestionTypes = ['choice', 'score', 'boolean'] as const;\n\n constructor(\n readonly modelId: TypeSafeAiEvaluationModelId,\n private readonly config: TypeSafeAiEvaluationModelConfig,\n ) {}\n\n get provider() {\n return this.config.provider;\n }\n\n static [WORKFLOW_SERIALIZE](model: EvaluationTypeSafeAiModel) {\n return serializeModelOptions({\n modelId: model.modelId,\n config: model.config,\n });\n }\n\n static [WORKFLOW_DESERIALIZE](options: {\n modelId: TypeSafeAiEvaluationModelId;\n config: TypeSafeAiEvaluationModelConfig;\n }) {\n return new EvaluationTypeSafeAiModel(options.modelId, options.config);\n }\n\n async doEvaluate({\n state,\n questions,\n headers,\n abortSignal,\n providerOptions,\n }: Parameters<EvaluationModelV4['doEvaluate']>[0]): Promise<\n Awaited<ReturnType<EvaluationModelV4['doEvaluate']>>\n > {\n for (const [id, question] of Object.entries(questions)) {\n if (\n question.type === 'choice' &&\n Object.keys(question.criteria).length > 255\n ) {\n throw new InvalidArgumentError({\n argument: `questions.${id}.criteria`,\n message: 'TypeSafe Choice questions support at most 255 options.',\n });\n }\n if (question.type === 'score' && question.criteria.length > 10) {\n throw new InvalidArgumentError({\n argument: `questions.${id}.criteria`,\n message: 'TypeSafe Score questions support at most 10 levels.',\n });\n }\n }\n\n const warnings: SharedV4Warning[] = Object.keys(\n providerOptions?.typesafe ?? {},\n ).map(option => ({\n type: 'unsupported',\n feature: `providerOptions.typesafe.${option}`,\n }));\n const modelHeaders =\n this.config.headers === undefined\n ? withUserAgentSuffix(\n {\n Authorization: `Bearer ${loadApiKey({ apiKey: undefined, environmentVariableName: 'TYPESAFE_AI_API_KEY', description: 'TypeSafe' })}`,\n },\n `ai-sdk/typesafe-ai/${VERSION}`,\n )\n : await resolve(this.config.headers);\n const {\n value: response,\n rawValue,\n responseHeaders,\n } = await postJsonToApi({\n url: `${this.config.baseURL}/systemone`,\n headers: combineHeaders(modelHeaders, headers),\n body: {\n model: this.modelId,\n state,\n questions: Object.fromEntries(\n Object.entries(questions).map(([id, question]) => [\n id,\n question.type === 'boolean'\n ? { ...question, type: 'noul' }\n : question,\n ]),\n ),\n },\n abortSignal,\n fetch: this.config.fetch,\n failedResponseHandler: typesafeFailedResponseHandler,\n successfulResponseHandler: createJsonResponseHandler(\n typesafeEvaluationResponseSchema,\n ),\n });\n\n const confidence = Object.fromEntries(\n Object.entries(response.answers).flatMap(([id, answer]) =>\n answer.type !== 'noul' && answer.confidence != null\n ? [[id, answer.confidence]]\n : [],\n ),\n );\n\n return {\n answers: Object.fromEntries(\n Object.entries(response.answers).map(\n ([id, answer]): [string, EvaluationModelV4Answer] => {\n switch (answer.type) {\n case 'noul':\n return [id, { type: 'boolean', probability: answer.noul }];\n case 'choice':\n return [\n id,\n {\n type: 'choice',\n choice: answer.choice,\n probabilities: answer.probabilities,\n },\n ];\n case 'score':\n return [\n id,\n {\n type: 'score',\n score: answer.score,\n probabilities: answer.probabilities,\n },\n ];\n }\n },\n ),\n ),\n usage: {\n inputTokens: response.usage?.input_tokens ?? undefined,\n outputTokens: response.usage?.output_tokens ?? undefined,\n },\n // The API rounds displayed probabilities and scores to two decimal places.\n rounding: { probabilityDecimals: 2, scoreDecimals: 2 },\n warnings,\n providerMetadata: { typesafe: { confidence } },\n response: {\n modelId: response.model ?? this.modelId,\n headers: responseHeaders,\n body: rawValue,\n },\n };\n }\n}\n","import { createJsonErrorResponseHandler } from '@ai-sdk/provider-utils';\nimport * as z from 'zod/v4';\n\n// Verified against the official SDK at 66880ccded6cb642dc1809620c2b108c33730214.\n// https://github.com/typesafe-ai/typesafe-sdk-js/blob/66880ccded6cb642dc1809620c2b108c33730214/src/types.ts\nexport const typesafeEvaluationResponseSchema = z.object({\n model: z.string().nullish(),\n answers: z.record(\n z.string(),\n z.discriminatedUnion('type', [\n z.object({\n type: z.literal('choice'),\n choice: z.string(),\n probabilities: z.record(z.string(), z.number()),\n confidence: z.number().nullish(),\n }),\n z.object({\n type: z.literal('score'),\n score: z.number(),\n probabilities: z.record(z.string(), z.number()),\n confidence: z.number().nullish(),\n }),\n z.object({ type: z.literal('noul'), noul: z.number() }),\n ]),\n ),\n usage: z\n .object({\n input_tokens: z.number().nullish(),\n output_tokens: z.number().nullish(),\n })\n .nullish(),\n});\n\nexport const typesafeFailedResponseHandler = createJsonErrorResponseHandler({\n errorSchema: z.object({\n message: z.string().nullish(),\n detail: z.unknown().nullish(),\n error: z\n .union([z.string(), z.object({ message: z.string().nullish() })])\n .nullish(),\n error_type: z.string().nullish(),\n }),\n errorToMessage: error =>\n error.message ??\n (typeof error.error === 'string' ? error.error : error.error?.message) ??\n (typeof error.detail === 'string'\n ? error.detail\n : JSON.stringify(error.detail)) ??\n error.error_type ??\n 'TypeSafe request failed',\n});\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n"],"mappings":";AAAA;AAAA,EACE;AAAA,OAGK;AACP;AAAA,EACE,cAAAA;AAAA,EACA;AAAA,EACA,uBAAAC;AAAA,OAEK;;;ACVP;AAAA,EACE;AAAA,OAIK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;;;AClBP,SAAS,sCAAsC;AAC/C,YAAY,OAAO;AAIZ,IAAM,mCAAqC,SAAO;AAAA,EACvD,OAAS,SAAO,EAAE,QAAQ;AAAA,EAC1B,SAAW;AAAA,IACP,SAAO;AAAA,IACP,qBAAmB,QAAQ;AAAA,MACzB,SAAO;AAAA,QACP,MAAQ,UAAQ,QAAQ;AAAA,QACxB,QAAU,SAAO;AAAA,QACjB,eAAiB,SAAS,SAAO,GAAK,SAAO,CAAC;AAAA,QAC9C,YAAc,SAAO,EAAE,QAAQ;AAAA,MACjC,CAAC;AAAA,MACC,SAAO;AAAA,QACP,MAAQ,UAAQ,OAAO;AAAA,QACvB,OAAS,SAAO;AAAA,QAChB,e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rD;AAAA,MACA,kBAAkB,EAAE,UAAU,EAAE,WAAW,EAAE;AAAA,MAC7C,UAAU;AAAA,QACR,SAAS,SAAS,SAAS,KAAK;AAAA,QAChC,SAAS;AAAA,QACT,MAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACF;;;ADvJO,SAAS,iBACd,UAAsC,CAAC,GACnB;AACpB,QAAM,UACJ,qBAAqB,QAAQ,OAAO,KAAK;AAC3C,QAAM,UAAU,MACdC;AAAA,IACE;AAAA,MACE,eAAe,UAAUC,YAAW,EAAE,QAAQ,QAAQ,QAAQ,yBAAyB,uBAAuB,aAAa,WAAW,CAAC,CAAC;AAAA,MACxI,GAAG,QAAQ;AAAA,IACb;AAAA,IACA,sBAAsB,OAAO;AAAA,EAC/B;AAEF,SAAO;AAAA,IACL,sBAAsB;AAAA,IACtB,iBAAiB,aACf,IAAI,0BAA0B,SAAS;AAAA,MACrC,UAAU;AAAA,MACV;AAAA,MACA;AAAA,MACA,OAAO,QAAQ;AAAA,IACjB,CAAC;AAAA,IACH,eAAe,aAAW;AACxB,YAAM,IAAI,iBAAiB,EAAE,SAAS,WAAW,gBAAgB,CAAC;AAAA,IACpE;AAAA,IACA,gBAAgB,aAAW;AACzB,YAAM,IAAI,iBAAiB,EAAE,SAAS,WAAW,iBAAiB,CAAC;AAAA,IACrE;AAAA,IACA,YAAY,aAAW;AACrB,YAAM,IAAI,iBAAiB,EAAE,SAAS,WAAW,aAAa,CAAC;AAAA,IACjE;AAAA,EACF;AACF;AAEO,IAAM,aAAa,iBAAiB;","names":["loadApiKey","withUserAgentSuffix","withUserAgentSuffix","loadApiKey"]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/typesafe-ai-evaluation-api.ts","../src/version.ts","../src/typesafe-ai-evaluation-model.ts","../src/typesafe-ai-provider.ts"],"sourcesContent":["import { createJsonErrorResponseHandler } from '@ai-sdk/provider-utils';\nimport * as z from 'zod/v4';\n\n// Verified against the official SDK at 66880ccded6cb642dc1809620c2b108c33730214.\n// https://github.com/typesafe-ai/typesafe-sdk-js/blob/66880ccded6cb642dc1809620c2b108c33730214/src/types.ts\nexport const typesafeEvaluationResponseSchema = z.object({\n model: z.string().nullish(),\n answers: z.record(\n z.string(),\n z.discriminatedUnion('type', [\n z.object({\n type: z.literal('choice'),\n choice: z.string(),\n probabilities: z.record(z.string(), z.number()),\n confidence: z.number().nullish(),\n }),\n z.object({\n type: z.literal('score'),\n score: z.number(),\n probabilities: z.record(z.string(), z.number()),\n confidence: z.number().nullish(),\n }),\n z.object({ type: z.literal('noul'), noul: z.number() }),\n ]),\n ),\n usage: z\n .object({\n input_tokens: z.number().nullish(),\n output_tokens: z.number().nullish(),\n })\n .nullish(),\n});\n\nexport const typesafeFailedResponseHandler = createJsonErrorResponseHandler({\n errorSchema: z.object({\n message: z.string().nullish(),\n detail: z.unknown().nullish(),\n error: z\n .union([z.string(), z.object({ message: z.string().nullish() })])\n .nullish(),\n error_type: z.string().nullish(),\n }),\n errorToMessage: error =>\n error.message ??\n (typeof error.error === 'string' ? error.error : error.error?.message) ??\n (typeof error.detail === 'string'\n ? error.detail\n : JSON.stringify(error.detail)) ??\n error.error_type ??\n 'TypeSafe request failed',\n});\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n","import {\n InvalidArgumentError,\n type Experimental_EvaluationModelV4 as EvaluationModelV4,\n type Experimental_EvaluationModelV4Answer as EvaluationModelV4Answer,\n type SharedV4Warning,\n} from '@ai-sdk/provider';\nimport {\n combineHeaders,\n createJsonResponseHandler,\n loadApiKey,\n postJsonToApi,\n resolve,\n serializeModelOptions,\n withUserAgentSuffix,\n WORKFLOW_SERIALIZE,\n WORKFLOW_DESERIALIZE,\n type FetchFunction,\n type Resolvable,\n} from '@ai-sdk/provider-utils';\nimport {\n typesafeEvaluationResponseSchema,\n typesafeFailedResponseHandler,\n} from './typesafe-ai-evaluation-api';\nimport { VERSION } from './version';\n\nexport type TypeSafeAiEvaluationModelId = 'jev-latest' | (string & {});\n\ntype TypeSafeAiEvaluationModelConfig = {\n provider: string;\n baseURL: string;\n headers?: Resolvable<Record<string, string | undefined>>;\n fetch?: FetchFunction;\n};\n\nexport class EvaluationTypeSafeAiModel implements EvaluationModelV4 {\n readonly specificationVersion = 'v4';\n readonly supportedQuestionTypes = ['choice', 'score', 'boolean'] as const;\n\n constructor(\n readonly modelId: TypeSafeAiEvaluationModelId,\n private readonly config: TypeSafeAiEvaluationModelConfig,\n ) {}\n\n get provider() {\n return this.config.provider;\n }\n\n static [WORKFLOW_SERIALIZE](model: EvaluationTypeSafeAiModel) {\n return serializeModelOptions({\n modelId: model.modelId,\n config: model.config,\n });\n }\n\n static [WORKFLOW_DESERIALIZE](options: {\n modelId: TypeSafeAiEvaluationModelId;\n config: TypeSafeAiEvaluationModelConfig;\n }) {\n return new EvaluationTypeSafeAiModel(options.modelId, options.config);\n }\n\n async doEvaluate({\n state,\n questions,\n headers,\n abortSignal,\n providerOptions,\n }: Parameters<EvaluationModelV4['doEvaluate']>[0]): Promise<\n Awaited<ReturnType<EvaluationModelV4['doEvaluate']>>\n > {\n for (const [id, question] of Object.entries(questions)) {\n if (\n question.type === 'choice' &&\n Object.keys(question.criteria).length > 255\n ) {\n throw new InvalidArgumentError({\n argument: `questions.${id}.criteria`,\n message: 'TypeSafe Choice questions support at most 255 options.',\n });\n }\n if (question.type === 'score' && question.criteria.length > 10) {\n throw new InvalidArgumentError({\n argument: `questions.${id}.criteria`,\n message: 'TypeSafe Score questions support at most 10 levels.',\n });\n }\n }\n\n const warnings: SharedV4Warning[] = Object.keys(\n providerOptions?.typesafe ?? {},\n ).map(option => ({\n type: 'unsupported',\n feature: `providerOptions.typesafe.${option}`,\n }));\n const modelHeaders =\n this.config.headers === undefined\n ? withUserAgentSuffix(\n {\n Authorization: `Bearer ${loadApiKey({ apiKey: undefined, environmentVariableName: 'TYPESAFE_AI_API_KEY', description: 'TypeSafe' })}`,\n },\n `ai-sdk-typesafe-ai/${VERSION}`,\n )\n : await resolve(this.config.headers);\n const {\n value: response,\n rawValue,\n responseHeaders,\n } = await postJsonToApi({\n url: `${this.config.baseURL}/systemone`,\n headers: combineHeaders(modelHeaders, headers),\n body: {\n model: this.modelId,\n state,\n questions: Object.fromEntries(\n Object.entries(questions).map(([id, question]) => [\n id,\n question.type === 'boolean'\n ? { ...question, type: 'noul' }\n : question,\n ]),\n ),\n },\n abortSignal,\n fetch: this.config.fetch,\n failedResponseHandler: typesafeFailedResponseHandler,\n successfulResponseHandler: createJsonResponseHandler(\n typesafeEvaluationResponseSchema,\n ),\n });\n\n const confidence = Object.fromEntries(\n Object.entries(response.answers).flatMap(([id, answer]) =>\n answer.type !== 'noul' && answer.confidence != null\n ? [[id, answer.confidence]]\n : [],\n ),\n );\n\n return {\n answers: Object.fromEntries(\n Object.entries(response.answers).map(\n ([id, answer]): [string, EvaluationModelV4Answer] => {\n switch (answer.type) {\n case 'noul':\n return [id, { type: 'boolean', probability: answer.noul }];\n case 'choice':\n return [\n id,\n {\n type: 'choice',\n choice: answer.choice,\n probabilities: answer.probabilities,\n },\n ];\n case 'score':\n return [\n id,\n {\n type: 'score',\n score: answer.score,\n probabilities: answer.probabilities,\n },\n ];\n }\n },\n ),\n ),\n usage: {\n inputTokens: response.usage?.input_tokens ?? undefined,\n outputTokens: response.usage?.output_tokens ?? undefined,\n },\n // The API rounds displayed probabilities and scores to two decimal places.\n rounding: { probabilityDecimals: 2, scoreDecimals: 2 },\n warnings,\n providerMetadata: { typesafe: { confidence } },\n response: {\n modelId: response.model ?? this.modelId,\n headers: responseHeaders,\n body: rawValue,\n },\n };\n }\n}\n","import {\n NoSuchModelError,\n type Experimental_EvaluationModelV4 as EvaluationModelV4,\n type ProviderV4,\n} from '@ai-sdk/provider';\nimport {\n loadApiKey,\n withoutTrailingSlash,\n withUserAgentSuffix,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport {\n EvaluationTypeSafeAiModel,\n type TypeSafeAiEvaluationModelId,\n} from './typesafe-ai-evaluation-model';\nimport { VERSION } from './version';\n\n/** TypeSafe's experimental evaluation capability, isolated from ProviderV4. */\nexport interface TypeSafeAiProvider extends ProviderV4 {\n evaluationModel(modelId: TypeSafeAiEvaluationModelId): EvaluationModelV4;\n}\n\nexport interface TypeSafeAiProviderSettings {\n /** API key. Defaults to the TYPESAFE_AI_API_KEY environment variable. */\n apiKey?: string;\n /** API base URL. Defaults to https://api.typesafe.ai/v1. */\n baseURL?: string;\n headers?: Record<string, string>;\n fetch?: FetchFunction;\n}\n\nexport function createTypeSafeAi(\n options: TypeSafeAiProviderSettings = {},\n): TypeSafeAiProvider {\n const baseURL =\n withoutTrailingSlash(options.baseURL) ?? 'https://api.typesafe.ai/v1';\n const headers = () =>\n withUserAgentSuffix(\n {\n Authorization: `Bearer ${loadApiKey({ apiKey: options.apiKey, environmentVariableName: 'TYPESAFE_AI_API_KEY', description: 'TypeSafe' })}`,\n ...options.headers,\n },\n `ai-sdk-typesafe-ai/${VERSION}`,\n );\n\n return {\n specificationVersion: 'v4',\n evaluationModel: modelId =>\n new EvaluationTypeSafeAiModel(modelId, {\n provider: 'typesafe.evaluation',\n baseURL,\n headers,\n fetch: options.fetch,\n }),\n languageModel: modelId => {\n throw new NoSuchModelError({ modelId, modelType: 'languageModel' });\n },\n embeddingModel: modelId => {\n throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });\n },\n imageModel: modelId => {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n },\n };\n}\n\nexport const typeSafeAi = createTypeSafeAi();\n"],"mappings":";;;;AAKA,MAAa,mCAAmC,EAAE,OAAO;CACvD,OAAO,EAAE,OAAO,CAAC,CAAC,QAAQ;CAC1B,SAAS,EAAE,OACT,EAAE,OAAO,GACT,EAAE,mBAAmB,QAAQ;EAC3B,EAAE,OAAO;GACP,MAAM,EAAE,QAAQ,QAAQ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,QAAQ;CACb,GACA,sBAAsB,SACxB;CAEF,OAAO;EACL,sBAAsB;EACtB,kBAAiB,YACf,IAAI,0BAA0B,SAAS;GACrC,UAAU;GACV;GACA;GACA,OAAO,QAAQ;EACjB,CAAC;EACH,gBAAe,YAAW;GACxB,MAAM,IAAI,iBAAiB;IAAE;IAAS,WAAW;GAAgB,CAAC;EACpE;EACA,iBAAgB,YAAW;GACzB,MAAM,IAAI,iBAAiB;IAAE;IAAS,WAAW;GAAiB,CAAC;EACrE;EACA,aAAY,YAAW;GACrB,MAAM,IAAI,iBAAiB;IAAE;IAAS,WAAW;GAAa,CAAC;EACjE;CACF;AACF;AAEA,MAAa,aAAa,iBAAiB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/typesafe-ai",
3
- "version": "3.0.9",
3
+ "version": "3.0.11",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -29,14 +29,14 @@
29
29
  }
30
30
  },
31
31
  "dependencies": {
32
- "@ai-sdk/provider": "4.0.19",
33
- "@ai-sdk/provider-utils": "5.0.50"
32
+ "@ai-sdk/provider": "4.0.20",
33
+ "@ai-sdk/provider-utils": "5.0.52"
34
34
  },
35
35
  "devDependencies": {
36
- "@ai-sdk/test-server": "2.0.2",
36
+ "@ai-sdk/test-server": "2.0.3",
37
37
  "@types/node": "22.19.19",
38
38
  "@vercel/ai-tsconfig": "0.0.0",
39
- "tsup": "^8.5.1",
39
+ "tsdown": "^0.23.0",
40
40
  "typescript": "5.8.3",
41
41
  "zod": "3.25.76",
42
42
  "@edge-runtime/vm": "^5.0.0"
@@ -65,9 +65,9 @@
65
65
  ],
66
66
  "source": "./src/index.ts",
67
67
  "scripts": {
68
- "build": "pnpm clean && tsup --tsconfig tsconfig.build.json",
69
- "build:watch": "pnpm clean && tsup --watch",
70
- "clean": "del-cli dist docs *.tsbuildinfo",
68
+ "build": "pnpm clean && tsdown",
69
+ "build:watch": "pnpm clean && tsdown --watch",
70
+ "clean": "del-cli docs *.tsbuildinfo",
71
71
  "type-check": "tsc --build",
72
72
  "test": "pnpm test:node && pnpm test:edge",
73
73
  "test:update": "pnpm test:node -u",
@@ -98,7 +98,7 @@ export class EvaluationTypeSafeAiModel implements EvaluationModelV4 {
98
98
  {
99
99
  Authorization: `Bearer ${loadApiKey({ apiKey: undefined, environmentVariableName: 'TYPESAFE_AI_API_KEY', description: 'TypeSafe' })}`,
100
100
  },
101
- `ai-sdk/typesafe-ai/${VERSION}`,
101
+ `ai-sdk-typesafe-ai/${VERSION}`,
102
102
  )
103
103
  : await resolve(this.config.headers);
104
104
  const {
@@ -40,7 +40,7 @@ export function createTypeSafeAi(
40
40
  Authorization: `Bearer ${loadApiKey({ apiKey: options.apiKey, environmentVariableName: 'TYPESAFE_AI_API_KEY', description: 'TypeSafe' })}`,
41
41
  ...options.headers,
42
42
  },
43
- `ai-sdk/typesafe-ai/${VERSION}`,
43
+ `ai-sdk-typesafe-ai/${VERSION}`,
44
44
  );
45
45
 
46
46
  return {