@dbx-tools/shared-model-gateway 0.9.36

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.
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Browser-safe model-gateway routing contracts.
3
+ *
4
+ * @module
5
+ */
6
+
7
+ import { model } from "@dbx-tools/shared-model";
8
+ import { z } from "zod";
9
+
10
+ /** Client protocol accepted by the gateway. */
11
+ export const ClientProtocolSchema = z.enum([
12
+ "openai-responses",
13
+ "openai-chat",
14
+ "anthropic-messages",
15
+ "openai-embeddings",
16
+ ]);
17
+ /** Client protocol accepted by the gateway. */
18
+ export type ClientProtocol = z.infer<typeof ClientProtocolSchema>;
19
+
20
+ /** Upstream protocol selected by capability routing. */
21
+ export const UpstreamProtocolSchema = z.enum([
22
+ "databricks-ai-gateway-codex",
23
+ "databricks-responses",
24
+ "databricks-open-responses",
25
+ "databricks-chat",
26
+ "databricks-anthropic",
27
+ "databricks-embeddings",
28
+ "ai-sdk",
29
+ ]);
30
+ /** Upstream protocol selected by capability routing. */
31
+ export type UpstreamProtocol = z.infer<typeof UpstreamProtocolSchema>;
32
+
33
+ /** Capabilities used to determine whether a request can remain on a direct path. */
34
+ export const ModelCapabilitiesSchema = z.object({
35
+ responses: z.boolean(),
36
+ openResponses: z.boolean(),
37
+ chat: z.boolean(),
38
+ anthropic: z.boolean(),
39
+ embeddings: z.boolean(),
40
+ aiGatewayCodex: z.boolean(),
41
+ tools: z.boolean(),
42
+ reasoning: z.boolean(),
43
+ streaming: z.boolean(),
44
+ parallelTools: z.boolean(),
45
+ customTools: z.boolean(),
46
+ structuredOutput: z.boolean(),
47
+ webSearch: z.boolean(),
48
+ });
49
+ /** Capabilities used to determine whether a request can remain on a direct path. */
50
+ export type ModelCapabilities = z.infer<typeof ModelCapabilitiesSchema>;
51
+
52
+ /** One discovered model plus every alias accepted by the gateway. */
53
+ export const ModelTargetSchema = z.object({
54
+ id: z.string().min(1),
55
+ aliases: z.array(z.string().min(1)),
56
+ displayName: z.string().min(1),
57
+ family: z.string().optional(),
58
+ modelServiceName: z.string().optional(),
59
+ endpoint: model.ServingEndpointSummarySchema.optional(),
60
+ capabilities: ModelCapabilitiesSchema,
61
+ reasoningEfforts: z.array(model.ReasoningEffortSchema),
62
+ });
63
+ /** One discovered model plus every alias accepted by the gateway. */
64
+ export type ModelTarget = z.infer<typeof ModelTargetSchema>;
65
+
66
+ /** Request features that constrain direct protocol routes. */
67
+ export const RequestedFeaturesSchema = z.object({
68
+ background: z.boolean(),
69
+ customTools: z.boolean(),
70
+ parallelTools: z.boolean(),
71
+ previousResponse: z.boolean(),
72
+ reasoning: z.boolean(),
73
+ storage: z.boolean(),
74
+ structuredOutput: z.boolean(),
75
+ tools: z.boolean(),
76
+ unsupportedOpenResponsesTools: z.boolean(),
77
+ webSearch: z.boolean(),
78
+ });
79
+ /** Request features that constrain direct protocol routes. */
80
+ export type RequestedFeatures = z.infer<typeof RequestedFeaturesSchema>;
81
+
82
+ /** Deterministic route selected for one gateway request. */
83
+ export const GatewayRouteSchema = z.object({
84
+ clientProtocol: ClientProtocolSchema,
85
+ upstreamProtocol: UpstreamProtocolSchema,
86
+ target: ModelTargetSchema,
87
+ upstreamModel: z.string().min(1),
88
+ translateRequest: z.boolean(),
89
+ translateResponse: z.boolean(),
90
+ });
91
+ /** Deterministic route selected for one gateway request. */
92
+ export type GatewayRoute = z.infer<typeof GatewayRouteSchema>;
93
+
94
+ /** Typed capability changes for one dynamically discovered model. */
95
+ export const ModelCapabilityOverrideSchema = z.object({
96
+ model: z.string().min(1),
97
+ capabilities: ModelCapabilitiesSchema.partial(),
98
+ });
99
+ /** Typed capability changes for one dynamically discovered model. */
100
+ export type ModelCapabilityOverride = z.infer<typeof ModelCapabilityOverrideSchema>;
101
+
102
+ /** Inputs required to select one deterministic gateway route. */
103
+ export const ResolveRouteInputSchema = z.object({
104
+ clientProtocol: ClientProtocolSchema,
105
+ requestedModel: z.string().min(1),
106
+ originator: z.string().optional(),
107
+ features: RequestedFeaturesSchema,
108
+ target: ModelTargetSchema,
109
+ });
110
+ /** Inputs required to select one deterministic gateway route. */
111
+ export type ResolveRouteInput = z.infer<typeof ResolveRouteInputSchema>;
package/src/models.ts ADDED
@@ -0,0 +1,172 @@
1
+ /**
2
+ * Browser-safe HTTP model, embedding, and error payloads.
3
+ *
4
+ * @module
5
+ */
6
+
7
+ import { model } from "@dbx-tools/shared-model";
8
+ import { z } from "zod";
9
+
10
+ /** Capabilities published with an OpenAI-compatible model entry. */
11
+ export const OpenAIModelCapabilitiesSchema = z.object({
12
+ tools: z.boolean(),
13
+ reasoning: z.array(model.ReasoningEffortSchema),
14
+ responses: z.boolean(),
15
+ open_responses: z.boolean(),
16
+ anthropic: z.boolean(),
17
+ embeddings: z.boolean(),
18
+ ai_gateway_codex: z.boolean(),
19
+ streaming: z.boolean(),
20
+ });
21
+ /** Capabilities published with an OpenAI-compatible model entry. */
22
+ export type OpenAIModelCapabilities = z.infer<typeof OpenAIModelCapabilitiesSchema>;
23
+
24
+ /** One OpenAI-compatible model-list entry. */
25
+ export const OpenAIModelSchema = z.object({
26
+ id: z.string().min(1),
27
+ object: z.literal("model"),
28
+ created: z.number().int().nonnegative(),
29
+ owned_by: z.string().min(1),
30
+ name: z.string().min(1),
31
+ task: z.string().optional(),
32
+ status: model.ModelStatusSchema,
33
+ capabilities: OpenAIModelCapabilitiesSchema,
34
+ });
35
+ /** One OpenAI-compatible model-list entry. */
36
+ export type OpenAIModel = z.infer<typeof OpenAIModelSchema>;
37
+
38
+ /** Standard OpenAI model-list response. */
39
+ export const OpenAIModelListResponseSchema = z.object({
40
+ object: z.literal("list"),
41
+ data: z.array(OpenAIModelSchema),
42
+ });
43
+ /** Standard OpenAI model-list response. */
44
+ export type OpenAIModelListResponse = z.infer<typeof OpenAIModelListResponseSchema>;
45
+
46
+ /** Reasoning effort advertised to Codex. */
47
+ export const CodexReasoningLevelSchema = z.object({
48
+ effort: model.ReasoningEffortSchema,
49
+ description: z.string(),
50
+ });
51
+ /** Reasoning effort advertised to Codex. */
52
+ export type CodexReasoningLevel = z.infer<typeof CodexReasoningLevelSchema>;
53
+
54
+ /** Codex client-side transcript truncation policy. */
55
+ export const CodexTruncationPolicySchema = z.object({
56
+ mode: z.enum(["tokens", "bytes"]),
57
+ limit: z.number().int().positive(),
58
+ });
59
+ /** Codex client-side transcript truncation policy. */
60
+ export type CodexTruncationPolicy = z.infer<typeof CodexTruncationPolicySchema>;
61
+
62
+ /** One Codex model-catalog entry. */
63
+ export const CodexModelSchema = z.object({
64
+ slug: z.string().min(1),
65
+ display_name: z.string().min(1),
66
+ description: z.string(),
67
+ base_instructions: z.string(),
68
+ status: model.ModelStatusSchema,
69
+ supported_reasoning_levels: z.array(CodexReasoningLevelSchema),
70
+ default_reasoning_level: model.ReasoningEffortSchema.optional(),
71
+ shell_type: z.string().min(1),
72
+ visibility: z.literal("list"),
73
+ supported_in_api: z.boolean(),
74
+ priority: z.number().int().positive(),
75
+ availability_nux: z.unknown().nullable(),
76
+ upgrade: z.unknown().nullable(),
77
+ support_verbosity: z.boolean(),
78
+ default_verbosity: z.string().nullable(),
79
+ apply_patch_tool_type: z.string().nullable(),
80
+ truncation_policy: CodexTruncationPolicySchema,
81
+ context_window: z.number().int().positive().nullable(),
82
+ experimental_supported_tools: z.array(z.unknown()),
83
+ input_modalities: z.array(z.string()),
84
+ web_search_tool_type: z.string(),
85
+ supports_search_tool: z.boolean(),
86
+ supports_image_detail_original: z.boolean(),
87
+ });
88
+ /** One Codex model-catalog entry. */
89
+ export type CodexModel = z.infer<typeof CodexModelSchema>;
90
+
91
+ /** Codex-native model-list response. */
92
+ export const CodexModelListResponseSchema = z.object({
93
+ models: z.array(CodexModelSchema),
94
+ });
95
+ /** Codex-native model-list response. */
96
+ export type CodexModelListResponse = z.infer<typeof CodexModelListResponseSchema>;
97
+
98
+ /** Model-list response selected by the caller's Originator header. */
99
+ export const ModelListResponseSchema = z.union([
100
+ OpenAIModelListResponseSchema,
101
+ CodexModelListResponseSchema,
102
+ ]);
103
+ /** Model-list response selected by the caller's Originator header. */
104
+ export type ModelListResponse = z.infer<typeof ModelListResponseSchema>;
105
+
106
+ /** OpenAI-compatible embeddings request. */
107
+ export const EmbeddingRequestSchema = z.object({
108
+ model: z.string().min(1),
109
+ input: z.union([z.string(), z.array(z.string())]),
110
+ encoding_format: z.enum(["float", "base64"]).optional(),
111
+ dimensions: z.number().int().positive().optional(),
112
+ user: z.string().optional(),
113
+ });
114
+ /** OpenAI-compatible embeddings request. */
115
+ export type EmbeddingRequest = z.infer<typeof EmbeddingRequestSchema>;
116
+
117
+ /** One embedding vector in an OpenAI-compatible response. */
118
+ export const EmbeddingDataSchema = z.object({
119
+ object: z.literal("embedding"),
120
+ embedding: z.union([z.array(z.number()), z.string()]),
121
+ index: z.number().int().nonnegative(),
122
+ });
123
+ /** One embedding vector in an OpenAI-compatible response. */
124
+ export type EmbeddingData = z.infer<typeof EmbeddingDataSchema>;
125
+
126
+ /** Token usage for an embeddings request. */
127
+ export const EmbeddingUsageSchema = z.object({
128
+ prompt_tokens: z.number().int().nonnegative(),
129
+ total_tokens: z.number().int().nonnegative(),
130
+ });
131
+ /** Token usage for an embeddings request. */
132
+ export type EmbeddingUsage = z.infer<typeof EmbeddingUsageSchema>;
133
+
134
+ /** OpenAI-compatible embeddings response. */
135
+ export const EmbeddingResponseSchema = z.object({
136
+ object: z.literal("list"),
137
+ data: z.array(EmbeddingDataSchema),
138
+ model: z.string(),
139
+ usage: EmbeddingUsageSchema,
140
+ });
141
+ /** OpenAI-compatible embeddings response. */
142
+ export type EmbeddingResponse = z.infer<typeof EmbeddingResponseSchema>;
143
+
144
+ /** OpenAI-compatible error response. */
145
+ export const OpenAIErrorResponseSchema = z.object({
146
+ error: z.object({
147
+ message: z.string(),
148
+ type: z.string(),
149
+ code: z.union([z.string(), z.number(), z.null()]).optional(),
150
+ }),
151
+ });
152
+ /** OpenAI-compatible error response. */
153
+ export type OpenAIErrorResponse = z.infer<typeof OpenAIErrorResponseSchema>;
154
+
155
+ /** Anthropic-compatible error response. */
156
+ export const AnthropicErrorResponseSchema = z.object({
157
+ type: z.literal("error"),
158
+ error: z.object({
159
+ type: z.string(),
160
+ message: z.string(),
161
+ }),
162
+ });
163
+ /** Anthropic-compatible error response. */
164
+ export type AnthropicErrorResponse = z.infer<typeof AnthropicErrorResponseSchema>;
165
+
166
+ /** Error response emitted by any gateway compatibility surface. */
167
+ export const GatewayErrorResponseSchema = z.union([
168
+ OpenAIErrorResponseSchema,
169
+ AnthropicErrorResponseSchema,
170
+ ]);
171
+ /** Error response emitted by any gateway compatibility surface. */
172
+ export type GatewayErrorResponse = z.infer<typeof GatewayErrorResponseSchema>;