@openrouter/sdk 0.2.9 → 0.3.1
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/esm/funcs/embeddingsGenerate.js +4 -2
- package/esm/lib/config.d.ts +2 -2
- package/esm/lib/config.js +2 -2
- package/esm/models/chatgenerationparams.d.ts +234 -6
- package/esm/models/chatgenerationparams.js +162 -5
- package/esm/models/chatresponsechoice.d.ts +2 -0
- package/esm/models/chatresponsechoice.js +3 -0
- package/esm/models/chatstreamingmessagechunk.d.ts +2 -0
- package/esm/models/chatstreamingmessagechunk.js +3 -0
- package/esm/models/index.d.ts +8 -0
- package/esm/models/index.js +8 -0
- package/esm/models/openairesponsesreasoningeffort.d.ts +1 -0
- package/esm/models/openairesponsesreasoningeffort.js +1 -0
- package/esm/models/openresponsesrequest.d.ts +128 -93
- package/esm/models/openresponsesrequest.js +82 -87
- package/esm/models/operations/createembeddings.d.ts +10 -129
- package/esm/models/operations/createembeddings.js +10 -62
- package/esm/models/operations/getparameters.d.ts +3 -72
- package/esm/models/operations/getparameters.js +3 -71
- package/esm/models/parameter.d.ts +1 -0
- package/esm/models/parameter.js +1 -0
- package/esm/models/pdfparserengine.d.ts +17 -0
- package/esm/models/pdfparserengine.js +15 -0
- package/esm/models/pdfparseroptions.d.ts +19 -0
- package/esm/models/pdfparseroptions.js +13 -0
- package/esm/models/providername.d.ts +3 -0
- package/esm/models/providername.js +3 -0
- package/esm/models/providerpreferences.d.ts +215 -0
- package/esm/models/providerpreferences.js +135 -0
- package/esm/models/providersort.d.ts +0 -6
- package/esm/models/providersort.js +0 -3
- package/esm/models/providersortconfig.d.ts +23 -0
- package/esm/models/providersortconfig.js +22 -0
- package/esm/models/providersortunion.d.ts +10 -0
- package/esm/models/providersortunion.js +12 -0
- package/esm/models/publicendpoint.d.ts +24 -24
- package/esm/models/publicendpoint.js +12 -12
- package/esm/models/publicpricing.d.ts +24 -24
- package/esm/models/publicpricing.js +12 -12
- package/esm/models/schema0.d.ts +83 -0
- package/esm/models/schema0.js +85 -0
- package/esm/models/schema3.d.ts +50 -0
- package/esm/models/schema3.js +60 -0
- package/esm/models/websearchengine.d.ts +16 -0
- package/esm/models/websearchengine.js +14 -0
- package/esm/types/discriminatedUnion.d.ts +25 -0
- package/esm/types/discriminatedUnion.js +57 -0
- package/jsr.json +1 -1
- package/package.json +1 -1
|
@@ -7,18 +7,18 @@ import { safeParse } from "../lib/schemas.js";
|
|
|
7
7
|
/** @internal */
|
|
8
8
|
export const PublicPricing$inboundSchema = z
|
|
9
9
|
.object({
|
|
10
|
-
prompt: z.
|
|
11
|
-
completion: z.
|
|
12
|
-
request: z.
|
|
13
|
-
image: z.
|
|
14
|
-
image_token: z.
|
|
15
|
-
image_output: z.
|
|
16
|
-
audio: z.
|
|
17
|
-
input_audio_cache: z.
|
|
18
|
-
web_search: z.
|
|
19
|
-
internal_reasoning: z.
|
|
20
|
-
input_cache_read: z.
|
|
21
|
-
input_cache_write: z.
|
|
10
|
+
prompt: z.string(),
|
|
11
|
+
completion: z.string(),
|
|
12
|
+
request: z.string().optional(),
|
|
13
|
+
image: z.string().optional(),
|
|
14
|
+
image_token: z.string().optional(),
|
|
15
|
+
image_output: z.string().optional(),
|
|
16
|
+
audio: z.string().optional(),
|
|
17
|
+
input_audio_cache: z.string().optional(),
|
|
18
|
+
web_search: z.string().optional(),
|
|
19
|
+
internal_reasoning: z.string().optional(),
|
|
20
|
+
input_cache_read: z.string().optional(),
|
|
21
|
+
input_cache_write: z.string().optional(),
|
|
22
22
|
discount: z.number().optional(),
|
|
23
23
|
}).transform((v) => {
|
|
24
24
|
return remap$(v, {
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import * as z from "zod/v4";
|
|
2
|
+
import { OpenEnum } from "../types/enums.js";
|
|
3
|
+
export declare const Schema0Enum: {
|
|
4
|
+
readonly Ai21: "AI21";
|
|
5
|
+
readonly AionLabs: "AionLabs";
|
|
6
|
+
readonly Alibaba: "Alibaba";
|
|
7
|
+
readonly AmazonBedrock: "Amazon Bedrock";
|
|
8
|
+
readonly AmazonNova: "Amazon Nova";
|
|
9
|
+
readonly Anthropic: "Anthropic";
|
|
10
|
+
readonly ArceeAI: "Arcee AI";
|
|
11
|
+
readonly AtlasCloud: "AtlasCloud";
|
|
12
|
+
readonly Avian: "Avian";
|
|
13
|
+
readonly Azure: "Azure";
|
|
14
|
+
readonly BaseTen: "BaseTen";
|
|
15
|
+
readonly BytePlus: "BytePlus";
|
|
16
|
+
readonly BlackForestLabs: "Black Forest Labs";
|
|
17
|
+
readonly Cerebras: "Cerebras";
|
|
18
|
+
readonly Chutes: "Chutes";
|
|
19
|
+
readonly Cirrascale: "Cirrascale";
|
|
20
|
+
readonly Clarifai: "Clarifai";
|
|
21
|
+
readonly Cloudflare: "Cloudflare";
|
|
22
|
+
readonly Cohere: "Cohere";
|
|
23
|
+
readonly Crusoe: "Crusoe";
|
|
24
|
+
readonly DeepInfra: "DeepInfra";
|
|
25
|
+
readonly DeepSeek: "DeepSeek";
|
|
26
|
+
readonly Featherless: "Featherless";
|
|
27
|
+
readonly Fireworks: "Fireworks";
|
|
28
|
+
readonly Friendli: "Friendli";
|
|
29
|
+
readonly GMICloud: "GMICloud";
|
|
30
|
+
readonly GoPomelo: "GoPomelo";
|
|
31
|
+
readonly Google: "Google";
|
|
32
|
+
readonly GoogleAIStudio: "Google AI Studio";
|
|
33
|
+
readonly Groq: "Groq";
|
|
34
|
+
readonly Hyperbolic: "Hyperbolic";
|
|
35
|
+
readonly Inception: "Inception";
|
|
36
|
+
readonly InferenceNet: "InferenceNet";
|
|
37
|
+
readonly Infermatic: "Infermatic";
|
|
38
|
+
readonly Inflection: "Inflection";
|
|
39
|
+
readonly Liquid: "Liquid";
|
|
40
|
+
readonly Mara: "Mara";
|
|
41
|
+
readonly Mancer2: "Mancer 2";
|
|
42
|
+
readonly Minimax: "Minimax";
|
|
43
|
+
readonly ModelRun: "ModelRun";
|
|
44
|
+
readonly Mistral: "Mistral";
|
|
45
|
+
readonly Modular: "Modular";
|
|
46
|
+
readonly MoonshotAI: "Moonshot AI";
|
|
47
|
+
readonly Morph: "Morph";
|
|
48
|
+
readonly NCompass: "NCompass";
|
|
49
|
+
readonly Nebius: "Nebius";
|
|
50
|
+
readonly NextBit: "NextBit";
|
|
51
|
+
readonly Novita: "Novita";
|
|
52
|
+
readonly Nvidia: "Nvidia";
|
|
53
|
+
readonly OpenAI: "OpenAI";
|
|
54
|
+
readonly OpenInference: "OpenInference";
|
|
55
|
+
readonly Parasail: "Parasail";
|
|
56
|
+
readonly Perplexity: "Perplexity";
|
|
57
|
+
readonly Phala: "Phala";
|
|
58
|
+
readonly Relace: "Relace";
|
|
59
|
+
readonly SambaNova: "SambaNova";
|
|
60
|
+
readonly SiliconFlow: "SiliconFlow";
|
|
61
|
+
readonly Sourceful: "Sourceful";
|
|
62
|
+
readonly Stealth: "Stealth";
|
|
63
|
+
readonly StreamLake: "StreamLake";
|
|
64
|
+
readonly Switchpoint: "Switchpoint";
|
|
65
|
+
readonly Targon: "Targon";
|
|
66
|
+
readonly Together: "Together";
|
|
67
|
+
readonly Venice: "Venice";
|
|
68
|
+
readonly WandB: "WandB";
|
|
69
|
+
readonly Xiaomi: "Xiaomi";
|
|
70
|
+
readonly XAI: "xAI";
|
|
71
|
+
readonly ZAi: "Z.AI";
|
|
72
|
+
readonly FakeProvider: "FakeProvider";
|
|
73
|
+
};
|
|
74
|
+
export type Schema0Enum = OpenEnum<typeof Schema0Enum>;
|
|
75
|
+
export type Schema0 = Schema0Enum | string;
|
|
76
|
+
/** @internal */
|
|
77
|
+
export declare const Schema0Enum$outboundSchema: z.ZodType<string, Schema0Enum>;
|
|
78
|
+
/** @internal */
|
|
79
|
+
export type Schema0$Outbound = string | string;
|
|
80
|
+
/** @internal */
|
|
81
|
+
export declare const Schema0$outboundSchema: z.ZodType<Schema0$Outbound, Schema0>;
|
|
82
|
+
export declare function schema0ToJSON(schema0: Schema0): string;
|
|
83
|
+
//# sourceMappingURL=schema0.d.ts.map
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
import * as z from "zod/v4";
|
|
5
|
+
import * as openEnums from "../types/enums.js";
|
|
6
|
+
export const Schema0Enum = {
|
|
7
|
+
Ai21: "AI21",
|
|
8
|
+
AionLabs: "AionLabs",
|
|
9
|
+
Alibaba: "Alibaba",
|
|
10
|
+
AmazonBedrock: "Amazon Bedrock",
|
|
11
|
+
AmazonNova: "Amazon Nova",
|
|
12
|
+
Anthropic: "Anthropic",
|
|
13
|
+
ArceeAI: "Arcee AI",
|
|
14
|
+
AtlasCloud: "AtlasCloud",
|
|
15
|
+
Avian: "Avian",
|
|
16
|
+
Azure: "Azure",
|
|
17
|
+
BaseTen: "BaseTen",
|
|
18
|
+
BytePlus: "BytePlus",
|
|
19
|
+
BlackForestLabs: "Black Forest Labs",
|
|
20
|
+
Cerebras: "Cerebras",
|
|
21
|
+
Chutes: "Chutes",
|
|
22
|
+
Cirrascale: "Cirrascale",
|
|
23
|
+
Clarifai: "Clarifai",
|
|
24
|
+
Cloudflare: "Cloudflare",
|
|
25
|
+
Cohere: "Cohere",
|
|
26
|
+
Crusoe: "Crusoe",
|
|
27
|
+
DeepInfra: "DeepInfra",
|
|
28
|
+
DeepSeek: "DeepSeek",
|
|
29
|
+
Featherless: "Featherless",
|
|
30
|
+
Fireworks: "Fireworks",
|
|
31
|
+
Friendli: "Friendli",
|
|
32
|
+
GMICloud: "GMICloud",
|
|
33
|
+
GoPomelo: "GoPomelo",
|
|
34
|
+
Google: "Google",
|
|
35
|
+
GoogleAIStudio: "Google AI Studio",
|
|
36
|
+
Groq: "Groq",
|
|
37
|
+
Hyperbolic: "Hyperbolic",
|
|
38
|
+
Inception: "Inception",
|
|
39
|
+
InferenceNet: "InferenceNet",
|
|
40
|
+
Infermatic: "Infermatic",
|
|
41
|
+
Inflection: "Inflection",
|
|
42
|
+
Liquid: "Liquid",
|
|
43
|
+
Mara: "Mara",
|
|
44
|
+
Mancer2: "Mancer 2",
|
|
45
|
+
Minimax: "Minimax",
|
|
46
|
+
ModelRun: "ModelRun",
|
|
47
|
+
Mistral: "Mistral",
|
|
48
|
+
Modular: "Modular",
|
|
49
|
+
MoonshotAI: "Moonshot AI",
|
|
50
|
+
Morph: "Morph",
|
|
51
|
+
NCompass: "NCompass",
|
|
52
|
+
Nebius: "Nebius",
|
|
53
|
+
NextBit: "NextBit",
|
|
54
|
+
Novita: "Novita",
|
|
55
|
+
Nvidia: "Nvidia",
|
|
56
|
+
OpenAI: "OpenAI",
|
|
57
|
+
OpenInference: "OpenInference",
|
|
58
|
+
Parasail: "Parasail",
|
|
59
|
+
Perplexity: "Perplexity",
|
|
60
|
+
Phala: "Phala",
|
|
61
|
+
Relace: "Relace",
|
|
62
|
+
SambaNova: "SambaNova",
|
|
63
|
+
SiliconFlow: "SiliconFlow",
|
|
64
|
+
Sourceful: "Sourceful",
|
|
65
|
+
Stealth: "Stealth",
|
|
66
|
+
StreamLake: "StreamLake",
|
|
67
|
+
Switchpoint: "Switchpoint",
|
|
68
|
+
Targon: "Targon",
|
|
69
|
+
Together: "Together",
|
|
70
|
+
Venice: "Venice",
|
|
71
|
+
WandB: "WandB",
|
|
72
|
+
Xiaomi: "Xiaomi",
|
|
73
|
+
XAI: "xAI",
|
|
74
|
+
ZAi: "Z.AI",
|
|
75
|
+
FakeProvider: "FakeProvider",
|
|
76
|
+
};
|
|
77
|
+
/** @internal */
|
|
78
|
+
export const Schema0Enum$outboundSchema = openEnums.outboundSchema(Schema0Enum);
|
|
79
|
+
/** @internal */
|
|
80
|
+
export const Schema0$outboundSchema = z
|
|
81
|
+
.union([Schema0Enum$outboundSchema, z.string()]);
|
|
82
|
+
export function schema0ToJSON(schema0) {
|
|
83
|
+
return JSON.stringify(Schema0$outboundSchema.parse(schema0));
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=schema0.js.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as z from "zod/v4";
|
|
2
|
+
import { OpenEnum } from "../types/enums.js";
|
|
3
|
+
import { Result as SafeParseResult } from "../types/fp.js";
|
|
4
|
+
import { SDKValidationError } from "./errors/sdkvalidationerror.js";
|
|
5
|
+
export declare const Schema5: {
|
|
6
|
+
readonly Unknown: "unknown";
|
|
7
|
+
readonly OpenaiResponsesV1: "openai-responses-v1";
|
|
8
|
+
readonly XaiResponsesV1: "xai-responses-v1";
|
|
9
|
+
readonly AnthropicClaudeV1: "anthropic-claude-v1";
|
|
10
|
+
readonly GoogleGeminiV1: "google-gemini-v1";
|
|
11
|
+
};
|
|
12
|
+
export type Schema5 = OpenEnum<typeof Schema5>;
|
|
13
|
+
export type Schema3ReasoningText = {
|
|
14
|
+
type: "reasoning.text";
|
|
15
|
+
text?: string | null | undefined;
|
|
16
|
+
signature?: string | null | undefined;
|
|
17
|
+
id?: string | null | undefined;
|
|
18
|
+
format?: Schema5 | null | undefined;
|
|
19
|
+
index?: number | undefined;
|
|
20
|
+
};
|
|
21
|
+
export type Schema3ReasoningEncrypted = {
|
|
22
|
+
type: "reasoning.encrypted";
|
|
23
|
+
data: string;
|
|
24
|
+
id?: string | null | undefined;
|
|
25
|
+
format?: Schema5 | null | undefined;
|
|
26
|
+
index?: number | undefined;
|
|
27
|
+
};
|
|
28
|
+
export type Schema3ReasoningSummary = {
|
|
29
|
+
type: "reasoning.summary";
|
|
30
|
+
summary: string;
|
|
31
|
+
id?: string | null | undefined;
|
|
32
|
+
format?: Schema5 | null | undefined;
|
|
33
|
+
index?: number | undefined;
|
|
34
|
+
};
|
|
35
|
+
export type Schema3 = Schema3ReasoningSummary | Schema3ReasoningEncrypted | Schema3ReasoningText;
|
|
36
|
+
/** @internal */
|
|
37
|
+
export declare const Schema5$inboundSchema: z.ZodType<Schema5, unknown>;
|
|
38
|
+
/** @internal */
|
|
39
|
+
export declare const Schema3ReasoningText$inboundSchema: z.ZodType<Schema3ReasoningText, unknown>;
|
|
40
|
+
export declare function schema3ReasoningTextFromJSON(jsonString: string): SafeParseResult<Schema3ReasoningText, SDKValidationError>;
|
|
41
|
+
/** @internal */
|
|
42
|
+
export declare const Schema3ReasoningEncrypted$inboundSchema: z.ZodType<Schema3ReasoningEncrypted, unknown>;
|
|
43
|
+
export declare function schema3ReasoningEncryptedFromJSON(jsonString: string): SafeParseResult<Schema3ReasoningEncrypted, SDKValidationError>;
|
|
44
|
+
/** @internal */
|
|
45
|
+
export declare const Schema3ReasoningSummary$inboundSchema: z.ZodType<Schema3ReasoningSummary, unknown>;
|
|
46
|
+
export declare function schema3ReasoningSummaryFromJSON(jsonString: string): SafeParseResult<Schema3ReasoningSummary, SDKValidationError>;
|
|
47
|
+
/** @internal */
|
|
48
|
+
export declare const Schema3$inboundSchema: z.ZodType<Schema3, unknown>;
|
|
49
|
+
export declare function schema3FromJSON(jsonString: string): SafeParseResult<Schema3, SDKValidationError>;
|
|
50
|
+
//# sourceMappingURL=schema3.d.ts.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
import * as z from "zod/v4";
|
|
5
|
+
import { safeParse } from "../lib/schemas.js";
|
|
6
|
+
import * as openEnums from "../types/enums.js";
|
|
7
|
+
export const Schema5 = {
|
|
8
|
+
Unknown: "unknown",
|
|
9
|
+
OpenaiResponsesV1: "openai-responses-v1",
|
|
10
|
+
XaiResponsesV1: "xai-responses-v1",
|
|
11
|
+
AnthropicClaudeV1: "anthropic-claude-v1",
|
|
12
|
+
GoogleGeminiV1: "google-gemini-v1",
|
|
13
|
+
};
|
|
14
|
+
/** @internal */
|
|
15
|
+
export const Schema5$inboundSchema = openEnums
|
|
16
|
+
.inboundSchema(Schema5);
|
|
17
|
+
/** @internal */
|
|
18
|
+
export const Schema3ReasoningText$inboundSchema = z.object({
|
|
19
|
+
type: z.literal("reasoning.text"),
|
|
20
|
+
text: z.nullable(z.string()).optional(),
|
|
21
|
+
signature: z.nullable(z.string()).optional(),
|
|
22
|
+
id: z.nullable(z.string()).optional(),
|
|
23
|
+
format: z.nullable(Schema5$inboundSchema).optional(),
|
|
24
|
+
index: z.number().optional(),
|
|
25
|
+
});
|
|
26
|
+
export function schema3ReasoningTextFromJSON(jsonString) {
|
|
27
|
+
return safeParse(jsonString, (x) => Schema3ReasoningText$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Schema3ReasoningText' from JSON`);
|
|
28
|
+
}
|
|
29
|
+
/** @internal */
|
|
30
|
+
export const Schema3ReasoningEncrypted$inboundSchema = z.object({
|
|
31
|
+
type: z.literal("reasoning.encrypted"),
|
|
32
|
+
data: z.string(),
|
|
33
|
+
id: z.nullable(z.string()).optional(),
|
|
34
|
+
format: z.nullable(Schema5$inboundSchema).optional(),
|
|
35
|
+
index: z.number().optional(),
|
|
36
|
+
});
|
|
37
|
+
export function schema3ReasoningEncryptedFromJSON(jsonString) {
|
|
38
|
+
return safeParse(jsonString, (x) => Schema3ReasoningEncrypted$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Schema3ReasoningEncrypted' from JSON`);
|
|
39
|
+
}
|
|
40
|
+
/** @internal */
|
|
41
|
+
export const Schema3ReasoningSummary$inboundSchema = z.object({
|
|
42
|
+
type: z.literal("reasoning.summary"),
|
|
43
|
+
summary: z.string(),
|
|
44
|
+
id: z.nullable(z.string()).optional(),
|
|
45
|
+
format: z.nullable(Schema5$inboundSchema).optional(),
|
|
46
|
+
index: z.number().optional(),
|
|
47
|
+
});
|
|
48
|
+
export function schema3ReasoningSummaryFromJSON(jsonString) {
|
|
49
|
+
return safeParse(jsonString, (x) => Schema3ReasoningSummary$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Schema3ReasoningSummary' from JSON`);
|
|
50
|
+
}
|
|
51
|
+
/** @internal */
|
|
52
|
+
export const Schema3$inboundSchema = z.union([
|
|
53
|
+
z.lazy(() => Schema3ReasoningSummary$inboundSchema),
|
|
54
|
+
z.lazy(() => Schema3ReasoningEncrypted$inboundSchema),
|
|
55
|
+
z.lazy(() => Schema3ReasoningText$inboundSchema),
|
|
56
|
+
]);
|
|
57
|
+
export function schema3FromJSON(jsonString) {
|
|
58
|
+
return safeParse(jsonString, (x) => Schema3$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Schema3' from JSON`);
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=schema3.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as z from "zod/v4";
|
|
2
|
+
import { OpenEnum } from "../types/enums.js";
|
|
3
|
+
/**
|
|
4
|
+
* The search engine to use for web search.
|
|
5
|
+
*/
|
|
6
|
+
export declare const WebSearchEngine: {
|
|
7
|
+
readonly Native: "native";
|
|
8
|
+
readonly Exa: "exa";
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* The search engine to use for web search.
|
|
12
|
+
*/
|
|
13
|
+
export type WebSearchEngine = OpenEnum<typeof WebSearchEngine>;
|
|
14
|
+
/** @internal */
|
|
15
|
+
export declare const WebSearchEngine$outboundSchema: z.ZodType<string, WebSearchEngine>;
|
|
16
|
+
//# sourceMappingURL=websearchengine.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
import * as openEnums from "../types/enums.js";
|
|
5
|
+
/**
|
|
6
|
+
* The search engine to use for web search.
|
|
7
|
+
*/
|
|
8
|
+
export const WebSearchEngine = {
|
|
9
|
+
Native: "native",
|
|
10
|
+
Exa: "exa",
|
|
11
|
+
};
|
|
12
|
+
/** @internal */
|
|
13
|
+
export const WebSearchEngine$outboundSchema = openEnums.outboundSchema(WebSearchEngine);
|
|
14
|
+
//# sourceMappingURL=websearchengine.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as z from "zod/v4";
|
|
2
|
+
export type Unknown<Discriminator extends string, UnknownValue = "UNKNOWN"> = {
|
|
3
|
+
[K in Discriminator]: UnknownValue;
|
|
4
|
+
} & {
|
|
5
|
+
raw: unknown;
|
|
6
|
+
isUnknown: true;
|
|
7
|
+
};
|
|
8
|
+
export declare function isUnknown<Discriminator extends string>(value: unknown): value is Unknown<Discriminator>;
|
|
9
|
+
/**
|
|
10
|
+
* Forward-compatible discriminated union parser.
|
|
11
|
+
*
|
|
12
|
+
* If the input does not match one of the predefined options, it will be
|
|
13
|
+
* captured and available as `{ raw: <original input>, [discriminator]: "UNKNOWN", isUnknown: true }`.
|
|
14
|
+
*
|
|
15
|
+
* @param inputPropertyName - The discriminator property name in the input payload
|
|
16
|
+
* @param options - Map of discriminator values to their corresponding schemas
|
|
17
|
+
* @param opts - Optional configuration object
|
|
18
|
+
* @param opts.unknownValue - The value to use for the discriminator when the input is unknown (default: "UNKNOWN")
|
|
19
|
+
* @param opts.outputPropertyName - Output property name if the sanitized (camelCase) property name differs from inputPropertyName
|
|
20
|
+
*/
|
|
21
|
+
export declare function discriminatedUnion<InputDiscriminator extends string, TOptions extends Readonly<Record<string, z.ZodType>>, UnknownValue extends string = "UNKNOWN", OutputDiscriminator extends string = InputDiscriminator>(inputPropertyName: InputDiscriminator, options: TOptions, opts?: {
|
|
22
|
+
unknownValue?: UnknownValue;
|
|
23
|
+
outputPropertyName?: OutputDiscriminator;
|
|
24
|
+
}): z.ZodType<z.output<TOptions[keyof TOptions]> | Unknown<OutputDiscriminator, UnknownValue>, unknown>;
|
|
25
|
+
//# sourceMappingURL=discriminatedUnion.d.ts.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
import * as z from "zod/v4";
|
|
5
|
+
import { startCountingUnrecognized } from "./unrecognized.js";
|
|
6
|
+
const UNKNOWN = Symbol("UNKNOWN");
|
|
7
|
+
export function isUnknown(value) {
|
|
8
|
+
return typeof value === "object" && value !== null && UNKNOWN in value;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Forward-compatible discriminated union parser.
|
|
12
|
+
*
|
|
13
|
+
* If the input does not match one of the predefined options, it will be
|
|
14
|
+
* captured and available as `{ raw: <original input>, [discriminator]: "UNKNOWN", isUnknown: true }`.
|
|
15
|
+
*
|
|
16
|
+
* @param inputPropertyName - The discriminator property name in the input payload
|
|
17
|
+
* @param options - Map of discriminator values to their corresponding schemas
|
|
18
|
+
* @param opts - Optional configuration object
|
|
19
|
+
* @param opts.unknownValue - The value to use for the discriminator when the input is unknown (default: "UNKNOWN")
|
|
20
|
+
* @param opts.outputPropertyName - Output property name if the sanitized (camelCase) property name differs from inputPropertyName
|
|
21
|
+
*/
|
|
22
|
+
export function discriminatedUnion(inputPropertyName, options, opts = {}) {
|
|
23
|
+
const { unknownValue = "UNKNOWN", outputPropertyName } = opts;
|
|
24
|
+
return z.unknown().transform((input) => {
|
|
25
|
+
const fallback = Object.defineProperties({
|
|
26
|
+
raw: input,
|
|
27
|
+
[outputPropertyName ?? inputPropertyName]: unknownValue,
|
|
28
|
+
isUnknown: true,
|
|
29
|
+
}, { [UNKNOWN]: { value: true, enumerable: false, configurable: false } });
|
|
30
|
+
const isObject = typeof input === "object" && input !== null;
|
|
31
|
+
if (!isObject)
|
|
32
|
+
return fallback;
|
|
33
|
+
const discriminator = input[inputPropertyName];
|
|
34
|
+
if (typeof discriminator !== "string")
|
|
35
|
+
return fallback;
|
|
36
|
+
if (!(discriminator in options))
|
|
37
|
+
return fallback;
|
|
38
|
+
const schema = options[discriminator];
|
|
39
|
+
if (!schema)
|
|
40
|
+
return fallback;
|
|
41
|
+
// Start counters before parsing to track nested unrecognized/zeroDefault values
|
|
42
|
+
const unrecognizedCtr = startCountingUnrecognized();
|
|
43
|
+
const result = schema.safeParse(input);
|
|
44
|
+
if (!result.success) {
|
|
45
|
+
// Parse failed - don't propagate any counts from the failed attempt
|
|
46
|
+
unrecognizedCtr.end(0);
|
|
47
|
+
return fallback;
|
|
48
|
+
}
|
|
49
|
+
// Parse succeeded - propagate the actual counts
|
|
50
|
+
unrecognizedCtr.end();
|
|
51
|
+
if (outputPropertyName) {
|
|
52
|
+
result.data[outputPropertyName] = discriminator;
|
|
53
|
+
}
|
|
54
|
+
return result.data;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=discriminatedUnion.js.map
|
package/jsr.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openrouter/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"author": "OpenRouter",
|
|
5
5
|
"description": "The OpenRouter TypeScript SDK is a type-safe toolkit for building AI applications with access to 300+ language models through a unified API.",
|
|
6
6
|
"keywords": [
|