@mantyx/sdk 0.9.1 → 0.10.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/CHANGELOG.md +9 -2
- package/README.md +81 -2
- package/dist/a2a-server.cjs.map +1 -1
- package/dist/a2a-server.d.cts +1 -1
- package/dist/a2a-server.d.ts +1 -1
- package/dist/a2a-server.js +1 -1
- package/dist/{chunk-AE7ZSLBH.js → chunk-XMUCELMH.js} +126 -24
- package/dist/chunk-XMUCELMH.js.map +1 -0
- package/dist/{client-BB6cjfsz.d.cts → client-CZUVldDx.d.cts} +401 -3
- package/dist/{client-BB6cjfsz.d.ts → client-CZUVldDx.d.ts} +401 -3
- package/dist/index.cjs +354 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -93
- package/dist/index.d.ts +3 -93
- package/dist/index.js +227 -2
- package/dist/index.js.map +1 -1
- package/docs/agent-runs-protocol.md +123 -113
- package/docs/oauth.md +356 -0
- package/docs/wire-protocol.md +1102 -0
- package/package.json +1 -1
- package/dist/chunk-AE7ZSLBH.js.map +0 -1
|
@@ -1,5 +1,306 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Error types raised by the MANTYX SDK.
|
|
5
|
+
*/
|
|
6
|
+
declare class MantyxError extends Error {
|
|
7
|
+
readonly code: string;
|
|
8
|
+
readonly status: number | undefined;
|
|
9
|
+
readonly hint: string | undefined;
|
|
10
|
+
constructor(message: string, opts?: {
|
|
11
|
+
code?: string;
|
|
12
|
+
status?: number;
|
|
13
|
+
hint?: string;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
declare class MantyxNetworkError extends MantyxError {
|
|
17
|
+
constructor(message: string, opts?: {
|
|
18
|
+
cause?: unknown;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
declare class MantyxAuthError extends MantyxError {
|
|
22
|
+
constructor(message?: string);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Raised on `403 insufficient_scope`, returned when an OAuth access token
|
|
26
|
+
* is missing one of the scopes a route demands (see
|
|
27
|
+
* `docs/agent-runs-protocol.md` §2.2 for the per-endpoint table).
|
|
28
|
+
*
|
|
29
|
+
* `requiredScopes` carries the verbatim `required` value from the
|
|
30
|
+
* server's response — a single scope for most routes, an array when the
|
|
31
|
+
* route demands more than one. The SDK is expected to surface this so
|
|
32
|
+
* callers can drive a re-consent flow (e.g. "please re-authorise the
|
|
33
|
+
* app with `sessions:write` enabled").
|
|
34
|
+
*
|
|
35
|
+
* Workspace API keys never trip this error — they carry no granular
|
|
36
|
+
* scopes. It is OAuth-only.
|
|
37
|
+
*/
|
|
38
|
+
declare class MantyxScopeError extends MantyxError {
|
|
39
|
+
/**
|
|
40
|
+
* Scope(s) the route demanded. Always at least one entry; usually
|
|
41
|
+
* exactly one. New routes may demand more scopes in the future.
|
|
42
|
+
*/
|
|
43
|
+
readonly requiredScopes: readonly string[];
|
|
44
|
+
constructor(message: string, requiredScopes: readonly string[]);
|
|
45
|
+
}
|
|
46
|
+
declare class MantyxToolError extends MantyxError {
|
|
47
|
+
readonly toolName: string;
|
|
48
|
+
constructor(toolName: string, message: string);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Optional triage attributes the runner attaches to terminal `error`
|
|
52
|
+
* events. Mirrors the wire fields described in
|
|
53
|
+
* `docs/agent-runs-protocol.md` §7 ("error event payload fields") so SDK
|
|
54
|
+
* callers can render structured UI status notes ("model truncated — JSON
|
|
55
|
+
* likely incomplete") and drive retry policy without re-parsing the
|
|
56
|
+
* human-readable `message`.
|
|
57
|
+
*/
|
|
58
|
+
interface MantyxRunErrorInit {
|
|
59
|
+
/**
|
|
60
|
+
* Canonical category of failure. One of `"rate_limit"`, `"overloaded"`,
|
|
61
|
+
* `"server"`, `"context_window"`, `"truncation"`, `"invalid_request"`,
|
|
62
|
+
* `"auth"`, `"timeout"`, `"local_timeout"`, `"upstream_deadline"`,
|
|
63
|
+
* `"unknown"`. New categories may land additively — callers should
|
|
64
|
+
* default-branch to `"unknown"` for unrecognized values.
|
|
65
|
+
*/
|
|
66
|
+
errorClass?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Canonical lowercase stop reason normalized across providers
|
|
69
|
+
* (`"max_tokens"`, `"refusal"`, `"malformed_function_call"`, …). When
|
|
70
|
+
* present, mirrors the value carried on the last `assistant_message`
|
|
71
|
+
* event preceding the failure.
|
|
72
|
+
*/
|
|
73
|
+
finishReason?: string | null;
|
|
74
|
+
/**
|
|
75
|
+
* **Best-effort raw bytes** the model emitted before the failure. For
|
|
76
|
+
* `outputSchema` runs this is likely **incomplete JSON** that will
|
|
77
|
+
* fail `JSON.parse` — treat it as diagnostic data, never as a
|
|
78
|
+
* schema-conformant reply.
|
|
79
|
+
*/
|
|
80
|
+
partialText?: string;
|
|
81
|
+
/**
|
|
82
|
+
* Coarse retry hint inherited from the pipeline's error classifier.
|
|
83
|
+
* Informational; the SDK still owns the actual retry decision.
|
|
84
|
+
*/
|
|
85
|
+
retryable?: boolean;
|
|
86
|
+
}
|
|
87
|
+
declare class MantyxRunError extends MantyxError {
|
|
88
|
+
readonly runId: string;
|
|
89
|
+
readonly subtype: string;
|
|
90
|
+
/** See {@link MantyxRunErrorInit.errorClass}. */
|
|
91
|
+
readonly errorClass: string | undefined;
|
|
92
|
+
/** See {@link MantyxRunErrorInit.finishReason}. */
|
|
93
|
+
readonly finishReason: string | null | undefined;
|
|
94
|
+
/** See {@link MantyxRunErrorInit.partialText}. */
|
|
95
|
+
readonly partialText: string | undefined;
|
|
96
|
+
/** See {@link MantyxRunErrorInit.retryable}. */
|
|
97
|
+
readonly retryable: boolean | undefined;
|
|
98
|
+
constructor(runId: string, subtype: string, message: string, init?: MantyxRunErrorInit);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Thrown by {@link parseRunOutput} when the run's terminal text was supposed
|
|
102
|
+
* to be a JSON document (because `outputSchema` was set on the spec) but
|
|
103
|
+
* either failed to JSON.parse or failed the user-supplied validator.
|
|
104
|
+
*
|
|
105
|
+
* The original `text` is preserved on the `text` field so callers can log
|
|
106
|
+
* the raw model output for debugging.
|
|
107
|
+
*/
|
|
108
|
+
declare class MantyxParseError extends MantyxError {
|
|
109
|
+
readonly text: string;
|
|
110
|
+
constructor(message: string, text: string, opts?: {
|
|
111
|
+
cause?: unknown;
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* MANTYX OAuth 2.0 refresh client: trade a stored refresh token for
|
|
117
|
+
* short-lived access tokens, revoke tokens at sign-out, and expose
|
|
118
|
+
* a {@link TokenSource} the {@link MantyxClient} HTTP layer calls
|
|
119
|
+
* before every request (and again on 401).
|
|
120
|
+
*
|
|
121
|
+
* The library is intentionally **refresh-only**. It assumes the caller
|
|
122
|
+
* already obtained the refresh token through their own sign-in flow
|
|
123
|
+
* (Authorization Code + PKCE in a browser, native redirect, server-
|
|
124
|
+
* side exchange — whatever fits the host application). The SDK does
|
|
125
|
+
* not drive consent, does not initiate auth-code exchanges, and does
|
|
126
|
+
* not bundle PKCE helpers.
|
|
127
|
+
*
|
|
128
|
+
* Wire contract (`docs/oauth.md`):
|
|
129
|
+
*
|
|
130
|
+
* - Token endpoint: `POST <baseUrl>/api/oauth/token`, form-encoded,
|
|
131
|
+
* `grant_type=refresh_token`. Echoes back the same `refresh_token`
|
|
132
|
+
* the client sent (refresh tokens are persistent and non-rotating).
|
|
133
|
+
* - Revoke endpoint: `POST <baseUrl>/api/oauth/revoke`, form-encoded.
|
|
134
|
+
* - Access tokens (`mantyx_at_…`) live 1 hour (`expires_in: 3600`).
|
|
135
|
+
* - Refresh tokens (`mantyx_rt_…`) are long-lived; the caller persists
|
|
136
|
+
* them once at first sign-in (encrypted at rest) and the SDK re-mints
|
|
137
|
+
* access tokens from the same value on demand.
|
|
138
|
+
*/
|
|
139
|
+
|
|
140
|
+
declare const DEFAULT_OAUTH_BASE_URL = "https://app.mantyx.io";
|
|
141
|
+
/** Skew (ms) before `expiresAt` at which a TokenSource will pre-emptively refresh. Default 60s. */
|
|
142
|
+
declare const DEFAULT_REFRESH_SKEW_MS = 60000;
|
|
143
|
+
/**
|
|
144
|
+
* Raised on a non-2xx response from `POST /api/oauth/token` or
|
|
145
|
+
* `POST /api/oauth/revoke`. Carries the RFC 6749 `error` discriminator
|
|
146
|
+
* (`"invalid_grant"`, `"invalid_client"`, `"unsupported_grant_type"`,
|
|
147
|
+
* …) and the optional `error_description` so callers can branch on
|
|
148
|
+
* machine-readable values without parsing the human message.
|
|
149
|
+
*
|
|
150
|
+
* `invalid_grant` from the refresh path specifically signals that the
|
|
151
|
+
* refresh token has been revoked (or the OAuth grant / application
|
|
152
|
+
* was deleted). The SDK never loops on this — callers should route
|
|
153
|
+
* the user back to a fresh sign-in.
|
|
154
|
+
*/
|
|
155
|
+
declare class MantyxOAuthError extends MantyxError {
|
|
156
|
+
readonly oauthError: string;
|
|
157
|
+
readonly oauthErrorDescription: string | undefined;
|
|
158
|
+
constructor(oauthError: string, oauthErrorDescription: string | undefined, status: number);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Decoded `POST /api/oauth/token` response, augmented with an absolute
|
|
162
|
+
* `expiresAt` timestamp the SDK uses to decide when to refresh.
|
|
163
|
+
*
|
|
164
|
+
* On the refresh grant the response's `refreshToken` is identical to
|
|
165
|
+
* the value the client just sent (refresh tokens never rotate). The
|
|
166
|
+
* field is surfaced for symmetry with whatever the calling app's
|
|
167
|
+
* sign-in flow already does.
|
|
168
|
+
*/
|
|
169
|
+
interface OAuthToken {
|
|
170
|
+
readonly accessToken: string;
|
|
171
|
+
readonly refreshToken: string | undefined;
|
|
172
|
+
readonly tokenType: string;
|
|
173
|
+
readonly expiresIn: number;
|
|
174
|
+
/** Absolute Unix-ms timestamp set when the SDK parsed the response. */
|
|
175
|
+
readonly expiresAt: number;
|
|
176
|
+
readonly scope: string | undefined;
|
|
177
|
+
}
|
|
178
|
+
/** Why the SDK asked the {@link TokenSource} for the current access token. */
|
|
179
|
+
type TokenRequestReason = "initial" | "expired" | "unauthorized";
|
|
180
|
+
/**
|
|
181
|
+
* A `TokenSource` produces the current access token on demand. The
|
|
182
|
+
* {@link MantyxClient} HTTP layer calls it before every request. When
|
|
183
|
+
* called with `reason: "unauthorized"` the source MUST force a refresh
|
|
184
|
+
* (do not return a cached value); this is how the SDK recovers from
|
|
185
|
+
* 401s caused by a token that the server already invalidated.
|
|
186
|
+
*
|
|
187
|
+
* Implementations should be safe to call from many concurrent requests.
|
|
188
|
+
*/
|
|
189
|
+
type TokenSource = (reason?: TokenRequestReason) => Promise<string>;
|
|
190
|
+
/** Caller-supplied options for `MantyxOAuthClient`. */
|
|
191
|
+
interface MantyxOAuthClientOptions {
|
|
192
|
+
/**
|
|
193
|
+
* OAuth `client_id` issued at app registration (token prefix
|
|
194
|
+
* `mantyx_oa_`).
|
|
195
|
+
*/
|
|
196
|
+
clientId: string;
|
|
197
|
+
/**
|
|
198
|
+
* OAuth `client_secret` issued at app registration (token prefix
|
|
199
|
+
* `mantyx_oas_`). Every MANTYX OAuth app is a confidential client,
|
|
200
|
+
* so this is always required for token + revoke calls. Treat as a
|
|
201
|
+
* deployment secret — do not bundle into browser builds.
|
|
202
|
+
*/
|
|
203
|
+
clientSecret: string;
|
|
204
|
+
/**
|
|
205
|
+
* Origin of the MANTYX deployment. Defaults to `https://app.mantyx.io`.
|
|
206
|
+
* The OAuth endpoints are mounted at `<baseUrl>/api/oauth/...`.
|
|
207
|
+
*/
|
|
208
|
+
baseUrl?: string;
|
|
209
|
+
/** Optional `fetch` override (e.g. node-fetch wrapper). Default: global `fetch`. */
|
|
210
|
+
fetch?: typeof fetch;
|
|
211
|
+
/** Default per-request timeout in milliseconds. Default: 30s. */
|
|
212
|
+
timeoutMs?: number;
|
|
213
|
+
}
|
|
214
|
+
interface RefreshOptions {
|
|
215
|
+
refreshToken: string;
|
|
216
|
+
/**
|
|
217
|
+
* Optional scope narrowing. Must be a subset of the scopes already
|
|
218
|
+
* granted to the refresh token (server enforces this). Useful when
|
|
219
|
+
* an SDK consumer wants a short-scope access token for a specific
|
|
220
|
+
* sub-operation.
|
|
221
|
+
*/
|
|
222
|
+
scope?: string | readonly string[];
|
|
223
|
+
}
|
|
224
|
+
interface RevokeOptions {
|
|
225
|
+
token: string;
|
|
226
|
+
}
|
|
227
|
+
interface RefreshTokenSourceOptions {
|
|
228
|
+
refreshToken: string;
|
|
229
|
+
/** Optional scope narrowing applied on every refresh. */
|
|
230
|
+
scope?: string | readonly string[];
|
|
231
|
+
/**
|
|
232
|
+
* How many ms before `expiresAt` the source proactively refreshes.
|
|
233
|
+
* Defaults to {@link DEFAULT_REFRESH_SKEW_MS} (60s).
|
|
234
|
+
*/
|
|
235
|
+
refreshSkewMs?: number;
|
|
236
|
+
/**
|
|
237
|
+
* Optional initial access token + expiry to seed the source's cache
|
|
238
|
+
* with (e.g. the token already in hand from the host application's
|
|
239
|
+
* sign-in flow). When omitted, the source mints one on the first
|
|
240
|
+
* call.
|
|
241
|
+
*/
|
|
242
|
+
initialToken?: OAuthToken;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Refresh-only wrapper around the MANTYX OAuth 2.0 authorization-server
|
|
246
|
+
* endpoints. App-scoped (one per `{clientId, clientSecret}` pair);
|
|
247
|
+
* construct independently of {@link MantyxClient}, then either call
|
|
248
|
+
* {@link refresh} / {@link revoke} directly or hand a `TokenSource`
|
|
249
|
+
* produced by {@link refreshTokenSource} to `MantyxClient` for fully
|
|
250
|
+
* transparent refresh on every request.
|
|
251
|
+
*
|
|
252
|
+
* The client deliberately does **not** drive the authorization-code
|
|
253
|
+
* exchange or any other "initiate sign-in" grant. The caller is
|
|
254
|
+
* expected to obtain the refresh token through their own consent flow
|
|
255
|
+
* and persist it before constructing this client.
|
|
256
|
+
*/
|
|
257
|
+
declare class MantyxOAuthClient {
|
|
258
|
+
readonly clientId: string;
|
|
259
|
+
readonly baseUrl: string;
|
|
260
|
+
private readonly clientSecret;
|
|
261
|
+
private readonly fetchImpl;
|
|
262
|
+
private readonly timeoutMs;
|
|
263
|
+
constructor(opts: MantyxOAuthClientOptions);
|
|
264
|
+
/**
|
|
265
|
+
* Mint a fresh access token from a stored refresh token. The
|
|
266
|
+
* returned `refreshToken` is identical to the input — refresh
|
|
267
|
+
* tokens are persistent and non-rotating, so the field is
|
|
268
|
+
* surfaced only for symmetry with the response shape.
|
|
269
|
+
*
|
|
270
|
+
* On `400 invalid_grant` the refresh token has been revoked (or its
|
|
271
|
+
* grant / app was deleted); the SDK surfaces a
|
|
272
|
+
* {@link MantyxOAuthError} and callers must drive a fresh sign-in.
|
|
273
|
+
*/
|
|
274
|
+
refresh(opts: RefreshOptions): Promise<OAuthToken>;
|
|
275
|
+
/**
|
|
276
|
+
* Revoke an access or refresh token (RFC 7009). The server always
|
|
277
|
+
* returns 200, even for unknown tokens. Revoking a **refresh**
|
|
278
|
+
* token kills the refresh and every live access token tied to its
|
|
279
|
+
* grant; revoking an **access** token kills only that one.
|
|
280
|
+
*/
|
|
281
|
+
revoke(opts: RevokeOptions): Promise<void>;
|
|
282
|
+
/**
|
|
283
|
+
* Build a long-lived {@link TokenSource} that re-mints access
|
|
284
|
+
* tokens from the supplied refresh token. Pass the returned source
|
|
285
|
+
* to `new MantyxClient({ tokenSource, workspaceSlug, ... })`. The
|
|
286
|
+
* source caches the access token in-memory and refreshes
|
|
287
|
+
* proactively when the cached value is within `refreshSkewMs` of
|
|
288
|
+
* `expiresAt`, or eagerly when `MantyxClient` reports a 401.
|
|
289
|
+
*
|
|
290
|
+
* Pass `initialToken` if the calling app already has a non-expired
|
|
291
|
+
* access token in hand (e.g. straight out of the sign-in flow) to
|
|
292
|
+
* avoid an extra round-trip on the first request.
|
|
293
|
+
*/
|
|
294
|
+
refreshTokenSource(opts: RefreshTokenSourceOptions): TokenSource;
|
|
295
|
+
/**
|
|
296
|
+
* POST `application/x-www-form-urlencoded` to `/api/oauth/token` and
|
|
297
|
+
* decode the {@link OAuthToken} response. Always injects `client_id`
|
|
298
|
+
* + `client_secret` from the constructor.
|
|
299
|
+
*/
|
|
300
|
+
private token;
|
|
301
|
+
private formPost;
|
|
302
|
+
}
|
|
303
|
+
|
|
3
304
|
/**
|
|
4
305
|
* Public tool helpers for the MANTYX SDK.
|
|
5
306
|
*
|
|
@@ -332,7 +633,64 @@ declare function isLocalMcpServer(t: ToolRef): t is LocalMcpServer;
|
|
|
332
633
|
|
|
333
634
|
declare const DEFAULT_BASE_URL = "https://app.mantyx.io";
|
|
334
635
|
interface MantyxClientOptions {
|
|
335
|
-
|
|
636
|
+
/**
|
|
637
|
+
* Workspace API key (token prefix `mantyx_`) **or** a MANTYX OAuth 2.0
|
|
638
|
+
* access token (token prefix `mantyx_at_`). The server resolves either
|
|
639
|
+
* kind by token-prefix, so the SDK uses a single credential code path.
|
|
640
|
+
*
|
|
641
|
+
* Prefer the {@link accessToken} alias when wiring up an OAuth-based
|
|
642
|
+
* application — the two options are semantically identical (the value
|
|
643
|
+
* is forwarded as `Authorization: Bearer <credential>`), but
|
|
644
|
+
* `accessToken` makes the intent obvious at the call site.
|
|
645
|
+
*
|
|
646
|
+
* Exactly one of `apiKey` / `accessToken` must be set. Passing both —
|
|
647
|
+
* even to the same value — throws `MantyxError` at construction time.
|
|
648
|
+
*
|
|
649
|
+
* See `docs/agent-runs-protocol.md` §2 for the full credential table
|
|
650
|
+
* (including which prefix means what, scope semantics, and the
|
|
651
|
+
* `insufficient_scope` 403 SDKs surface via
|
|
652
|
+
* {@link MantyxScopeError}).
|
|
653
|
+
*/
|
|
654
|
+
apiKey?: string;
|
|
655
|
+
/**
|
|
656
|
+
* MANTYX OAuth 2.0 access token (token prefix `mantyx_at_…`). Exactly
|
|
657
|
+
* one of {@link apiKey} / `accessToken` / {@link tokenSource} must be
|
|
658
|
+
* set; passing more than one throws `MantyxError` at construction
|
|
659
|
+
* time.
|
|
660
|
+
*
|
|
661
|
+
* Functionally identical to {@link apiKey} — the SDK ships either
|
|
662
|
+
* value verbatim on `Authorization: Bearer <credential>` — but using
|
|
663
|
+
* the OAuth-specific name makes scope-driven applications easier to
|
|
664
|
+
* read.
|
|
665
|
+
*
|
|
666
|
+
* OAuth tokens additionally enforce per-route **scopes**
|
|
667
|
+
* (`runs:read`, `runs:write`, `sessions:read`, `sessions:write`,
|
|
668
|
+
* `models:read`, `mantyx.identity:read`); see
|
|
669
|
+
* `docs/agent-runs-protocol.md` §2.2 for the table. Missing scopes
|
|
670
|
+
* land as {@link MantyxScopeError} so callers can route the user
|
|
671
|
+
* back to a re-consent flow.
|
|
672
|
+
*
|
|
673
|
+
* Static `accessToken` values are 1-hour-lived per `docs/oauth.md`
|
|
674
|
+
* §"Token lifetimes & lifecycle" — for long-running processes
|
|
675
|
+
* prefer {@link tokenSource} so the SDK can refresh transparently.
|
|
676
|
+
*/
|
|
677
|
+
accessToken?: string;
|
|
678
|
+
/**
|
|
679
|
+
* Dynamic credential provider. The SDK calls it before every request
|
|
680
|
+
* to obtain the current access token, and again with
|
|
681
|
+
* `reason: "unauthorized"` after a 401 so it can refresh and retry
|
|
682
|
+
* the request exactly once.
|
|
683
|
+
*
|
|
684
|
+
* Build one via `oauthClient.refreshTokenSource({ refreshToken })`
|
|
685
|
+
* or `oauthClient.clientCredentialsTokenSource()` — see
|
|
686
|
+
* [`./oauth.ts`](./oauth.ts) for the helpers, or pass any function
|
|
687
|
+
* matching the {@link TokenSource} signature for full custom
|
|
688
|
+
* control (e.g. tokens minted by an upstream auth proxy).
|
|
689
|
+
*
|
|
690
|
+
* Exactly one of {@link apiKey} / {@link accessToken} / `tokenSource`
|
|
691
|
+
* must be set.
|
|
692
|
+
*/
|
|
693
|
+
tokenSource?: TokenSource;
|
|
336
694
|
workspaceSlug: string;
|
|
337
695
|
/** Defaults to `https://app.mantyx.io`. Override for self-hosted instances. */
|
|
338
696
|
baseUrl?: string;
|
|
@@ -741,9 +1099,28 @@ interface SessionInfo {
|
|
|
741
1099
|
metadata: Record<string, string>;
|
|
742
1100
|
}
|
|
743
1101
|
declare class MantyxClient {
|
|
744
|
-
readonly options: Required<Pick<MantyxClientOptions, "
|
|
1102
|
+
readonly options: Required<Pick<MantyxClientOptions, "workspaceSlug" | "baseUrl">> & {
|
|
1103
|
+
/**
|
|
1104
|
+
* Single resolved bearer credential — either a workspace API key
|
|
1105
|
+
* (token prefix `mantyx_`) or an OAuth access token (`mantyx_at_…`).
|
|
1106
|
+
* The SDK does not need to distinguish them on the wire; the value
|
|
1107
|
+
* is forwarded verbatim on `Authorization: Bearer …`.
|
|
1108
|
+
*
|
|
1109
|
+
* Kept as `apiKey` (instead of e.g. `credential`) for backwards
|
|
1110
|
+
* compatibility — older releases exposed it under this name.
|
|
1111
|
+
*
|
|
1112
|
+
* Empty string when a {@link tokenSource} is configured — every
|
|
1113
|
+
* request resolves the bearer from the source instead.
|
|
1114
|
+
*/
|
|
1115
|
+
apiKey: string;
|
|
745
1116
|
fetch: typeof fetch;
|
|
746
1117
|
timeoutMs: number;
|
|
1118
|
+
/**
|
|
1119
|
+
* Dynamic credential provider when constructed with
|
|
1120
|
+
* `tokenSource` — see {@link MantyxClientOptions.tokenSource}.
|
|
1121
|
+
* `null` for static `apiKey` / `accessToken` clients.
|
|
1122
|
+
*/
|
|
1123
|
+
tokenSource: TokenSource | null;
|
|
747
1124
|
};
|
|
748
1125
|
constructor(opts: MantyxClientOptions);
|
|
749
1126
|
listModels(): Promise<ModelCatalog>;
|
|
@@ -779,6 +1156,26 @@ declare class MantyxClient {
|
|
|
779
1156
|
}): Promise<void>;
|
|
780
1157
|
cancelRun(runId: string): Promise<void>;
|
|
781
1158
|
private absoluteUrl;
|
|
1159
|
+
/**
|
|
1160
|
+
* Resolve the bearer credential to send on the next request. With a
|
|
1161
|
+
* static `apiKey` / `accessToken` this is a synchronous reach into
|
|
1162
|
+
* `options.apiKey`; with a {@link TokenSource} it delegates so the
|
|
1163
|
+
* source can refresh expired access tokens before we hit the wire.
|
|
1164
|
+
*
|
|
1165
|
+
* The `reason` is forwarded to the source verbatim. Pass
|
|
1166
|
+
* `"unauthorized"` immediately after a 401 so the source forces a
|
|
1167
|
+
* refresh rather than handing back its (now-invalid) cached value.
|
|
1168
|
+
*/
|
|
1169
|
+
private resolveBearer;
|
|
1170
|
+
/**
|
|
1171
|
+
* Open an SSE stream against `reqUrl` with at-most-one refresh +
|
|
1172
|
+
* retry on 401. The caller is responsible for the subsequent
|
|
1173
|
+
* `readSseStream` loop; this helper only handles the initial GET.
|
|
1174
|
+
* Mid-stream 401s propagate as `MantyxNetworkError` from the read
|
|
1175
|
+
* loop and trigger a reconnect via the outer `while` in
|
|
1176
|
+
* {@link streamRunEvents}.
|
|
1177
|
+
*/
|
|
1178
|
+
private openSseStream;
|
|
782
1179
|
private authHeaders;
|
|
783
1180
|
request<T>(args: {
|
|
784
1181
|
method: string;
|
|
@@ -786,6 +1183,7 @@ declare class MantyxClient {
|
|
|
786
1183
|
body?: unknown;
|
|
787
1184
|
timeoutMs?: number;
|
|
788
1185
|
}): Promise<T>;
|
|
1186
|
+
private requestWithRetry;
|
|
789
1187
|
private errorFromResponse;
|
|
790
1188
|
}
|
|
791
1189
|
declare class AgentSession {
|
|
@@ -882,4 +1280,4 @@ interface LocalHandlers {
|
|
|
882
1280
|
*/
|
|
883
1281
|
declare function parseRunOutput<T = unknown>(result: RunResult, validator?: (value: unknown) => T): T;
|
|
884
1282
|
|
|
885
|
-
export {
|
|
1283
|
+
export { type RunResult as $, type A2AToolRef as A, MantyxOAuthError as B, type CancelledEvent as C, DEFAULT_BASE_URL as D, type ErrorEvent as E, MantyxParseError as F, type MantyxPluginToolRef as G, MantyxRunError as H, type MantyxRunErrorInit as I, MantyxScopeError as J, MantyxToolError as K, type LocalA2ATool as L, MantyxClient as M, type MantyxToolRef as N, type McpToolRef as O, type ModelCatalog as P, type ModelInfo as Q, type ReasoningLevel as R, type OAuthToken as S, type ToolRef as T, type OutputSchema as U, type RefreshOptions as V, type RefreshTokenSourceOptions as W, type ResultEvent as X, type RevokeOptions as Y, type RunEvent as Z, type RunEventBase as _, AgentSession as a, type RunSpec as a0, type ServerToolResultEvent as a1, type SessionInfo as a2, type SessionSpec as a3, type ThinkingDeltaEvent as a4, type TokenRequestReason as a5, type TokenSource as a6, type ToolBudget as a7, type ToolBudgetExceededEvent as a8, type ToolBudgets as a9, type ZodLikeObject as aa, defineLocalA2A as ab, defineLocalMcp as ac, defineLocalTool as ad, isLocalA2ATool as ae, isLocalMcpServer as af, isLocalTool as ag, mantyxA2A as ah, mantyxMcp as ai, mantyxPluginTool as aj, mantyxTool as ak, parseRunOutput as al, type AgentSpecBase as b, type AssistantDeltaEvent as c, type AssistantMessageEvent as d, DEFAULT_OAUTH_BASE_URL as e, DEFAULT_REFRESH_SKEW_MS as f, type DefineLocalA2AOptions as g, type DefineLocalMcpOptions as h, type DefineLocalToolOptions as i, type LocalHandlers as j, type LocalMcpHttpTransport as k, type LocalMcpServer as l, type LocalMcpStdioTransport as m, type LocalTool as n, type LocalToolCallEvent as o, type LocalToolResultInEvent as p, type LoopDetectedEvent as q, type LoopDetection as r, type MantyxA2AOptions as s, MantyxAuthError as t, type MantyxClientOptions as u, MantyxError as v, type MantyxMcpOptions as w, MantyxNetworkError as x, MantyxOAuthClient as y, type MantyxOAuthClientOptions as z };
|