@mastra/code-sdk 1.21.0 → 1.22.0-alpha.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.
@@ -0,0 +1,98 @@
1
+ import type { OpenAICompatibleProvider } from '@ai-sdk/openai-compatible';
2
+ import type { CustomProviderAuthScheme, CustomProviderHeader } from '../onboarding/settings.js';
3
+ export { customProviderHeaderProblem } from '../onboarding/custom-provider-headers.js';
4
+ /** The language model `createCustomProviderChatModel` returns. */
5
+ export type CustomProviderChatModel = ReturnType<OpenAICompatibleProvider['chatModel']>;
6
+ /** Everything needed to call a custom endpoint, with saved secrets already resolved. */
7
+ export interface CustomProviderConnection {
8
+ /**
9
+ * Base URL, such as `https://host/v1`. Paths are appended to it as text, so
10
+ * a query string or fragment (`https://host/v1/?api-version=1`) ends up in
11
+ * the middle of every request path and is not supported.
12
+ */
13
+ url: string;
14
+ apiKey?: string;
15
+ authScheme?: CustomProviderAuthScheme;
16
+ headers?: CustomProviderHeader[];
17
+ }
18
+ /**
19
+ * `fetch` that refuses redirects. Servers call custom endpoints too, and a
20
+ * redirect could aim that call at an address the saved URL never named.
21
+ */
22
+ export declare const fetchWithoutRedirects: typeof fetch;
23
+ /**
24
+ * The custom headers of a connection plus the header that carries its key.
25
+ * The auth header comes last so that nothing can replace it.
26
+ */
27
+ export declare function customProviderRequestHeaders(connection: CustomProviderConnection): Record<string, string>;
28
+ /**
29
+ * The chat model a session uses for a custom endpoint. `requestHeaders` are
30
+ * Mastra's own per-request headers (`x-thread-id`, `x-resource-id`). A custom
31
+ * header may replace them, and nothing replaces the auth header.
32
+ */
33
+ export declare function createCustomProviderChatModel(args: {
34
+ providerId: string;
35
+ connection: CustomProviderConnection;
36
+ modelId: string;
37
+ requestHeaders?: Record<string, string>;
38
+ }): CustomProviderChatModel;
39
+ /** Why a check failed, in terms a user can act on. */
40
+ export interface CustomProviderCheckFailure {
41
+ kind: 'http' | 'network' | 'timeout' | 'redirect' | 'invalid_response';
42
+ /** One line, for example "HTTP 403 Forbidden from https://host/v1/models". */
43
+ message: string;
44
+ status?: number;
45
+ /** Upstream body excerpt as plain text, at most 1,000 characters. */
46
+ detail?: string;
47
+ }
48
+ /** The outcome of {@link listCustomProviderModels}. */
49
+ export type CustomProviderModelsResult = {
50
+ ok: true;
51
+ models: string[];
52
+ latencyMs: number;
53
+ } | {
54
+ ok: false;
55
+ failure: CustomProviderCheckFailure;
56
+ latencyMs: number;
57
+ };
58
+ /** The outcome of {@link testCustomProviderModel}. */
59
+ export type CustomProviderModelTestResult = {
60
+ ok: true;
61
+ reply: string;
62
+ finishReason?: string;
63
+ latencyMs: number;
64
+ } | {
65
+ ok: false;
66
+ failure: CustomProviderCheckFailure;
67
+ latencyMs: number;
68
+ };
69
+ /** Options shared by both checks. */
70
+ export interface CustomProviderCheckOptions {
71
+ /**
72
+ * Deadline for the whole check: 10 s for the model list, 30 s for the test
73
+ * message by default. A value that is not a positive finite number uses the
74
+ * default, a fraction is rounded up to the next millisecond, and a value
75
+ * above the platform timer maximum (2,147,483,647 ms) is capped at it, so a
76
+ * check always has a deadline and never rejects on this option.
77
+ */
78
+ timeoutMs?: number;
79
+ signal?: AbortSignal;
80
+ /** Keep only the upstream error message or page title in `detail`, never raw body text. */
81
+ summaryDetailOnly?: boolean;
82
+ }
83
+ /**
84
+ * Call `GET {url}/models` and return the model ids the endpoint lists, or why
85
+ * it could not. A failure is returned, never thrown.
86
+ */
87
+ export declare function listCustomProviderModels(connection: CustomProviderConnection, options?: CustomProviderCheckOptions): Promise<CustomProviderModelsResult>;
88
+ /**
89
+ * Send one short message to a model on a custom endpoint and return its reply,
90
+ * or why it failed. A failure is returned, never thrown, and the request is
91
+ * made once: a check that retries hides the error the user needs to see.
92
+ */
93
+ export declare function testCustomProviderModel(args: {
94
+ providerId: string;
95
+ connection: CustomProviderConnection;
96
+ modelId: string;
97
+ }, options?: CustomProviderCheckOptions): Promise<CustomProviderModelTestResult>;
98
+ //# sourceMappingURL=custom-provider-check.d.ts.map