@m8tes/sdk 0.1.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.
- package/CHANGELOG.md +100 -0
- package/LICENSE +21 -0
- package/README.md +160 -0
- package/dist/chunk-UFQQNUFE.js +1083 -0
- package/dist/chunk-UFQQNUFE.js.map +1 -0
- package/dist/fixtures.cjs +297 -0
- package/dist/fixtures.cjs.map +1 -0
- package/dist/fixtures.d.cts +81 -0
- package/dist/fixtures.d.ts +81 -0
- package/dist/fixtures.js +295 -0
- package/dist/fixtures.js.map +1 -0
- package/dist/index.cjs +1783 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +937 -0
- package/dist/index.d.ts +937 -0
- package/dist/index.js +672 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol/index.cjs +1109 -0
- package/dist/protocol/index.cjs.map +1 -0
- package/dist/protocol/index.d.cts +576 -0
- package/dist/protocol/index.d.ts +576 -0
- package/dist/protocol/index.js +3 -0
- package/dist/protocol/index.js.map +1 -0
- package/package.json +64 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,937 @@
|
|
|
1
|
+
import { Normalizer, M8tesStreamEvent, ConversationState } from './protocol/index.cjs';
|
|
2
|
+
export { APIError, Accumulator, ApiErrorFields, ApprovalRequestEvent, ApprovalResolvedEvent, AuthenticationError, BaseEvent, BillingError, CompactBoundaryEvent, CompactPart, ConflictError, ErrorFromResponseOptions, M8tesApiError, M8tesStreamEventType, MateMessage, MatePart, MateStatus, MessageEndEvent, MessageStartEvent, NotFoundError, NoticeEvent, NoticePart, PROTOCOL_VERSION, PermissionDeniedError, PlanDeltaEvent, PlanEndEvent, PlanStartEvent, ProtocolVersion, QuestionEvent, QuestionItem, QuestionOption, RateLimitError, ReasoningDeltaEvent, ReasoningEndEvent, ReasoningStartEvent, RunCancelledEvent, RunErrorCode, RunErrorEvent, RunFailedError, RunFinishEvent, RunMetricsEvent, RunNotStreamingError, RunStartEvent, RunStatus, RunStatusEvent, SandboxPart, SandboxStatusEvent, SseParserOptions, TERMINAL_EVENT_TYPES, TerminalEventType, TextDeltaEvent, TextEndEvent, TextLikeKind, TextPart, TextStartEvent, ToolInputAvailableEvent, ToolInputDeltaEvent, ToolInputStartEvent, ToolOutputAvailableEvent, ToolPart, ToolState, UnknownEvent, ValidationError, accumulate, createAccumulator, createNormalizer, createSseDecoder, errorClassForStatus, errorFromResponse, initialConversationState, isTerminalEvent, parseErrorEnvelope, parseRetryAfter, parseSse, splitConcatenatedJson } from './protocol/index.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Server-side transport for the m8tes V2 API.
|
|
6
|
+
*
|
|
7
|
+
* SECURITY: this module holds the secret `m8_` API key and must NEVER reach a
|
|
8
|
+
* browser bundle. Client-side rendering of an agent goes through
|
|
9
|
+
* `@m8tes/react` + its server proxy, which keeps the key on the server. The
|
|
10
|
+
* bundle-boundary test asserts `dist/protocol/index.js` contains none of this.
|
|
11
|
+
*
|
|
12
|
+
* Retry semantics mirror the Python SDK (`sdk/py/m8tes/_http.py`) exactly so the
|
|
13
|
+
* two languages behave the same under load:
|
|
14
|
+
* - 3 attempts total, 0.5s initial backoff, doubling
|
|
15
|
+
* - retry only 429/500/502/503/504
|
|
16
|
+
* - retry only idempotent methods (GET/HEAD/PUT/DELETE/OPTIONS). A POST that
|
|
17
|
+
* timed out may already have started a billable run, so re-sending it could
|
|
18
|
+
* double-charge; those fail immediately and let the caller decide.
|
|
19
|
+
* - honour `Retry-After` on 429
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/** Canonical hosted API. Includes the `/api/v2` prefix, like the Python SDK's DEFAULT_BASE_URL. */
|
|
23
|
+
declare const DEFAULT_BASE_URL = "https://api.m8tes.ai/api/v2";
|
|
24
|
+
type FetchLike = (input: string, init?: RequestInit) => Promise<Response>;
|
|
25
|
+
interface ClientOptions {
|
|
26
|
+
/** Your `m8_` key. Defaults to `process.env.M8TES_API_KEY`. */
|
|
27
|
+
apiKey?: string;
|
|
28
|
+
/** Override the API host. Must include the `/api/v2` prefix. */
|
|
29
|
+
baseUrl?: string;
|
|
30
|
+
/** Per-request timeout in ms. Default 300_000 (5 min), matching the Python SDK. */
|
|
31
|
+
timeout?: number;
|
|
32
|
+
/** Extra headers on every request. */
|
|
33
|
+
headers?: Record<string, string>;
|
|
34
|
+
/** Pluggable fetch, for tests or a custom agent/proxy. Default `globalThis.fetch`. */
|
|
35
|
+
fetch?: FetchLike;
|
|
36
|
+
/** Reported (not thrown) when a stream frame is unparseable. */
|
|
37
|
+
onMalformed?: (rawPayload: string, error: unknown) => void;
|
|
38
|
+
}
|
|
39
|
+
interface RequestOptions {
|
|
40
|
+
body?: unknown;
|
|
41
|
+
query?: string;
|
|
42
|
+
signal?: AbortSignal;
|
|
43
|
+
headers?: Record<string, string>;
|
|
44
|
+
}
|
|
45
|
+
interface StreamRequestOptions extends RequestOptions {
|
|
46
|
+
/** Reuse a normalizer across reconnects so its dedupe ledger persists. */
|
|
47
|
+
normalizer?: Normalizer;
|
|
48
|
+
}
|
|
49
|
+
interface Http {
|
|
50
|
+
baseUrl: string;
|
|
51
|
+
request<T>(method: string, path: string, opts?: RequestOptions): Promise<T>;
|
|
52
|
+
/** The OK `Response` itself — for binary bodies (file downloads). Retries and
|
|
53
|
+
* typed errors still apply; the caller owns reading the body. */
|
|
54
|
+
raw(method: string, path: string, opts?: RequestOptions): Promise<Response>;
|
|
55
|
+
stream(method: string, path: string, opts?: StreamRequestOptions): AsyncGenerator<M8tesStreamEvent, void, unknown>;
|
|
56
|
+
}
|
|
57
|
+
declare function createHttp(options?: ClientOptions): Http;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Cursor pagination over the V2 `ListResponse` envelope (`{data, has_more}`).
|
|
61
|
+
*
|
|
62
|
+
* Mirrors the Python SDK's `SyncPage` (`sdk/py/m8tes/_types.py`): a page is the
|
|
63
|
+
* raw response plus an async iterator that walks every remaining page for you.
|
|
64
|
+
*
|
|
65
|
+
* The cursor is the last item's `id`, or its `name` for `/apps` (the one resource
|
|
66
|
+
* keyed by name). Same rule as Python, so both SDKs paginate identically.
|
|
67
|
+
*/
|
|
68
|
+
interface ListResponse<T> {
|
|
69
|
+
data: T[];
|
|
70
|
+
hasMore: boolean;
|
|
71
|
+
}
|
|
72
|
+
/** A page of results. `for await (const item of page)` walks ALL pages. */
|
|
73
|
+
declare class Page<T> implements ListResponse<T>, AsyncIterable<T> {
|
|
74
|
+
readonly data: T[];
|
|
75
|
+
readonly hasMore: boolean;
|
|
76
|
+
/** Fetches the next page given a cursor. Absent on a terminal page. */
|
|
77
|
+
private readonly fetchNext?;
|
|
78
|
+
constructor(data: T[], hasMore: boolean, fetchNext?: (startingAfter: string | number) => Promise<Page<T>>);
|
|
79
|
+
/**
|
|
80
|
+
* Auto-paging: yields every item across every page.
|
|
81
|
+
*
|
|
82
|
+
* Stops if the cursor ever fails to advance. A server that returns the same
|
|
83
|
+
* page again with `has_more: true` — a caching layer, a replica lagging, a bug
|
|
84
|
+
* — would otherwise spin forever, re-yielding the same rows and never
|
|
85
|
+
* returning. Terminating is the only safe response: the caller gets the items
|
|
86
|
+
* it did see rather than a hung process.
|
|
87
|
+
*/
|
|
88
|
+
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
89
|
+
/** Every item across every page, collected. Prefer iteration for large sets. */
|
|
90
|
+
all(): Promise<T[]>;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Response types for the resources `@m8tes/sdk` v0.1 covers.
|
|
95
|
+
*
|
|
96
|
+
* Field names are the API's own **snake_case**, exactly as sent — the same names
|
|
97
|
+
* you see in `/docs/api-reference` and in the Python SDK (`sdk/py/m8tes/_types.py`
|
|
98
|
+
* describes these same objects). Nothing is renamed in transit, so what you read
|
|
99
|
+
* in the docs is what you type in TypeScript, and a response object is the raw
|
|
100
|
+
* body. `test/parity.test.ts` asserts these field names against the Python
|
|
101
|
+
* dataclasses so the two SDKs cannot drift.
|
|
102
|
+
*
|
|
103
|
+
* Fields are typed explicitly rather than with an index signature: extra fields
|
|
104
|
+
* the API adds later still arrive at runtime, they just are not typed until this
|
|
105
|
+
* file learns them, which is what keeps autocomplete trustworthy.
|
|
106
|
+
*
|
|
107
|
+
* Every timestamp is an ISO-8601 string, as sent.
|
|
108
|
+
*/
|
|
109
|
+
/** Free-form JSON, e.g. your own `metadata`. Passed through untouched — the SDK
|
|
110
|
+
* never inspects or rewrites keys inside it. */
|
|
111
|
+
type JsonObject = Record<string, unknown>;
|
|
112
|
+
/**
|
|
113
|
+
* The V2 permission modes. NOT the Claude Agent SDK's mode names — the API
|
|
114
|
+
* rejects `"acceptEdits"` / `"bypassPermissions"` with a 422.
|
|
115
|
+
*
|
|
116
|
+
* Deliberately a closed union with no `| string` escape hatch: widening it to
|
|
117
|
+
* `string` would accept every typo silently, which is the mistake this type
|
|
118
|
+
* exists to prevent. If the API gains a mode before this package does, cast at
|
|
119
|
+
* the call site (`"newMode" as PermissionMode`) and open an issue.
|
|
120
|
+
*/
|
|
121
|
+
type PermissionMode = "autonomous" | "approval" | "plan";
|
|
122
|
+
/** An agent (the API resource is `agents`; `Teammate` is a permanent alias). */
|
|
123
|
+
interface Agent {
|
|
124
|
+
id: number;
|
|
125
|
+
name: string;
|
|
126
|
+
instructions: string | null;
|
|
127
|
+
tools: string[];
|
|
128
|
+
role: string | null;
|
|
129
|
+
goals: string | null;
|
|
130
|
+
user_id: string | null;
|
|
131
|
+
metadata: JsonObject | null;
|
|
132
|
+
default_permission_mode: string;
|
|
133
|
+
status: string;
|
|
134
|
+
created_at: string;
|
|
135
|
+
updated_at?: string | null;
|
|
136
|
+
model?: string | null;
|
|
137
|
+
effort?: string | null;
|
|
138
|
+
allowed_senders?: string[] | null;
|
|
139
|
+
inbound_email_enabled?: boolean;
|
|
140
|
+
email_address?: string | null;
|
|
141
|
+
webhook_enabled?: boolean;
|
|
142
|
+
webhook_url?: string | null;
|
|
143
|
+
enable_memory?: boolean | null;
|
|
144
|
+
enable_history?: boolean | null;
|
|
145
|
+
enable_task_setup_tools?: boolean | null;
|
|
146
|
+
enable_feedback?: boolean | null;
|
|
147
|
+
enable_self_improvement?: boolean | null;
|
|
148
|
+
}
|
|
149
|
+
/** Permanent alias — the platform term is "agent", the DB model is `Teammate`. */
|
|
150
|
+
type Teammate = Agent;
|
|
151
|
+
interface RunUsage {
|
|
152
|
+
input_tokens?: number;
|
|
153
|
+
output_tokens?: number;
|
|
154
|
+
total_tokens?: number;
|
|
155
|
+
cost_usd?: string | null;
|
|
156
|
+
}
|
|
157
|
+
interface Run {
|
|
158
|
+
id: number;
|
|
159
|
+
teammate_id: number | null;
|
|
160
|
+
status: string;
|
|
161
|
+
output: string | null;
|
|
162
|
+
error: string | null;
|
|
163
|
+
user_id: string | null;
|
|
164
|
+
metadata: JsonObject | null;
|
|
165
|
+
created_at: string;
|
|
166
|
+
updated_at: string | null;
|
|
167
|
+
task_id?: number | null;
|
|
168
|
+
permission_mode?: string | null;
|
|
169
|
+
error_code?: string | null;
|
|
170
|
+
retryable?: boolean;
|
|
171
|
+
retry_of_run_id?: number | null;
|
|
172
|
+
retry_count?: number;
|
|
173
|
+
output_data?: JsonObject | null;
|
|
174
|
+
usage?: RunUsage | null;
|
|
175
|
+
}
|
|
176
|
+
/** Condensed run result: what happened, without replaying the transcript. */
|
|
177
|
+
interface RunOutcome {
|
|
178
|
+
run_id: number;
|
|
179
|
+
status: string;
|
|
180
|
+
summary: string | null;
|
|
181
|
+
headline: string | null;
|
|
182
|
+
needs_reply: boolean;
|
|
183
|
+
output_data: JsonObject | null;
|
|
184
|
+
message_count: number;
|
|
185
|
+
input_tokens: number;
|
|
186
|
+
output_tokens: number;
|
|
187
|
+
total_tokens: number;
|
|
188
|
+
cost_usd: string | null;
|
|
189
|
+
}
|
|
190
|
+
interface RunFile {
|
|
191
|
+
name: string;
|
|
192
|
+
size: number;
|
|
193
|
+
}
|
|
194
|
+
interface PermissionRequest {
|
|
195
|
+
request_id: string;
|
|
196
|
+
tool_name: string;
|
|
197
|
+
tool_input: JsonObject | null;
|
|
198
|
+
status: string;
|
|
199
|
+
created_at: string;
|
|
200
|
+
resolved_at: string | null;
|
|
201
|
+
auto_resolved?: boolean;
|
|
202
|
+
}
|
|
203
|
+
interface Task {
|
|
204
|
+
id: number;
|
|
205
|
+
teammate_id: number;
|
|
206
|
+
name: string | null;
|
|
207
|
+
instructions: string;
|
|
208
|
+
tools: string[];
|
|
209
|
+
expected_output: string | null;
|
|
210
|
+
goals: string | null;
|
|
211
|
+
user_id: string | null;
|
|
212
|
+
status: string;
|
|
213
|
+
created_at: string;
|
|
214
|
+
updated_at?: string | null;
|
|
215
|
+
email_notifications?: boolean;
|
|
216
|
+
webhook_enabled?: boolean;
|
|
217
|
+
webhook_url?: string | null;
|
|
218
|
+
app_trigger_count?: number;
|
|
219
|
+
enable_memory?: boolean | null;
|
|
220
|
+
enable_history?: boolean | null;
|
|
221
|
+
enable_task_setup_tools?: boolean | null;
|
|
222
|
+
enable_feedback?: boolean | null;
|
|
223
|
+
enable_lessons?: boolean;
|
|
224
|
+
}
|
|
225
|
+
type TriggerType = "schedule" | "webhook" | "email" | "app";
|
|
226
|
+
interface Trigger {
|
|
227
|
+
id: number;
|
|
228
|
+
type: string;
|
|
229
|
+
enabled: boolean;
|
|
230
|
+
cron?: string | null;
|
|
231
|
+
interval_seconds?: number | null;
|
|
232
|
+
timezone?: string;
|
|
233
|
+
next_run?: string | null;
|
|
234
|
+
/** Webhook triggers: the URL to POST to. */
|
|
235
|
+
url?: string | null;
|
|
236
|
+
/** Email triggers: the address that starts a run. */
|
|
237
|
+
address?: string | null;
|
|
238
|
+
app?: string | null;
|
|
239
|
+
trigger_name?: string | null;
|
|
240
|
+
trigger_config?: JsonObject | null;
|
|
241
|
+
}
|
|
242
|
+
/** Toggle result for a webhook or email inbox on an agent or task. */
|
|
243
|
+
interface WebhookToggle {
|
|
244
|
+
enabled: boolean;
|
|
245
|
+
url?: string | null;
|
|
246
|
+
}
|
|
247
|
+
interface EmailInbox {
|
|
248
|
+
enabled: boolean;
|
|
249
|
+
address?: string | null;
|
|
250
|
+
}
|
|
251
|
+
/** One of your end-users. `user_id` is YOUR id for them; it isolates their data. */
|
|
252
|
+
interface EndUser {
|
|
253
|
+
id: number;
|
|
254
|
+
user_id: string;
|
|
255
|
+
name: string | null;
|
|
256
|
+
email: string | null;
|
|
257
|
+
company: string | null;
|
|
258
|
+
metadata: JsonObject | null;
|
|
259
|
+
created_at: string;
|
|
260
|
+
updated_at?: string | null;
|
|
261
|
+
run_limit?: number | null;
|
|
262
|
+
cost_limit_cents?: number | null;
|
|
263
|
+
rate_per_minute?: number | null;
|
|
264
|
+
}
|
|
265
|
+
interface EndUserUsage {
|
|
266
|
+
id: number;
|
|
267
|
+
user_id: string;
|
|
268
|
+
runs_used: number;
|
|
269
|
+
cost_used: string;
|
|
270
|
+
input_tokens: number;
|
|
271
|
+
output_tokens: number;
|
|
272
|
+
total_tokens: number;
|
|
273
|
+
last_active_at: string | null;
|
|
274
|
+
runs_limit: number | null;
|
|
275
|
+
cost_limit_cents: number | null;
|
|
276
|
+
period_end: string;
|
|
277
|
+
rate_per_minute?: number | null;
|
|
278
|
+
}
|
|
279
|
+
interface App {
|
|
280
|
+
name: string;
|
|
281
|
+
display_name: string;
|
|
282
|
+
category: string;
|
|
283
|
+
connected: boolean;
|
|
284
|
+
auth_type?: string;
|
|
285
|
+
}
|
|
286
|
+
/** Returned by `apps.connectOauth()`. Send the user to `authorization_url`, then
|
|
287
|
+
* pass `connection_id` back to `apps.connectComplete()`. */
|
|
288
|
+
interface AppConnectionInitiation {
|
|
289
|
+
authorization_url: string;
|
|
290
|
+
connection_id: string;
|
|
291
|
+
}
|
|
292
|
+
interface AppConnectionResult {
|
|
293
|
+
status: string;
|
|
294
|
+
connected?: boolean;
|
|
295
|
+
message?: string | null;
|
|
296
|
+
}
|
|
297
|
+
interface Webhook {
|
|
298
|
+
id: number;
|
|
299
|
+
url: string;
|
|
300
|
+
events: string[];
|
|
301
|
+
/** Signing secret. Returned on create only — store it, you cannot read it back. */
|
|
302
|
+
secret: string | null;
|
|
303
|
+
active: boolean;
|
|
304
|
+
created_at: string;
|
|
305
|
+
updated_at?: string | null;
|
|
306
|
+
}
|
|
307
|
+
interface WebhookDelivery {
|
|
308
|
+
id: number;
|
|
309
|
+
webhook_endpoint_id: number;
|
|
310
|
+
event_type: string;
|
|
311
|
+
event_id: string;
|
|
312
|
+
run_id: number;
|
|
313
|
+
status: string;
|
|
314
|
+
response_status_code: number | null;
|
|
315
|
+
response_body: string | null;
|
|
316
|
+
attempts: number;
|
|
317
|
+
next_retry_at: string | null;
|
|
318
|
+
created_at: string;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* `client.agents` — the reusable agent personas runs execute as.
|
|
323
|
+
*
|
|
324
|
+
* The V2 resource is `agents`; `client.teammates` is a permanent alias because
|
|
325
|
+
* the DB model and older API docs use that name. Mirrors
|
|
326
|
+
* `sdk/py/m8tes/_resources/teammates.py`.
|
|
327
|
+
*/
|
|
328
|
+
|
|
329
|
+
interface AgentCreateParams {
|
|
330
|
+
name?: string;
|
|
331
|
+
/** The agent's standing instructions: who it is and how it works. */
|
|
332
|
+
instructions?: string;
|
|
333
|
+
/** Tool slugs it may use, e.g. `["gmail", "slack"]`. */
|
|
334
|
+
tools?: string[];
|
|
335
|
+
role?: string;
|
|
336
|
+
goals?: string;
|
|
337
|
+
/** Your id for the end-user who owns this agent. */
|
|
338
|
+
user_id?: string;
|
|
339
|
+
metadata?: JsonObject;
|
|
340
|
+
model?: string;
|
|
341
|
+
effort?: string;
|
|
342
|
+
default_permission_mode?: PermissionMode;
|
|
343
|
+
/** Built-in tool toggles. Omit to inherit the platform default. */
|
|
344
|
+
enable_memory?: boolean;
|
|
345
|
+
enable_history?: boolean;
|
|
346
|
+
enable_task_setup_tools?: boolean;
|
|
347
|
+
enable_feedback?: boolean;
|
|
348
|
+
enable_self_improvement?: boolean;
|
|
349
|
+
/** Give the agent its own email inbox on create. */
|
|
350
|
+
email_inbox?: boolean;
|
|
351
|
+
/** Give the agent a webhook trigger URL on create. */
|
|
352
|
+
webhook?: boolean;
|
|
353
|
+
/** Start from a prebuilt persona, e.g. `"ppc-manager"`. Template improvements
|
|
354
|
+
* keep flowing in on later reads unless you override the field. */
|
|
355
|
+
from_template?: string;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* PATCH /agents/{id} accepts exactly these fields (backend `TeammateUpdate`).
|
|
359
|
+
* Create-only fields are NOT here on purpose: sending `webhook` or `email_inbox`
|
|
360
|
+
* to PATCH returns 200 and silently does nothing, which reads as a working call.
|
|
361
|
+
* Use `enableWebhook()` / `enableEmailInbox()` instead.
|
|
362
|
+
*
|
|
363
|
+
* `null` is meaningful: it CLEARS the field back to the platform default.
|
|
364
|
+
*/
|
|
365
|
+
interface AgentUpdateParams {
|
|
366
|
+
name?: string | null;
|
|
367
|
+
instructions?: string | null;
|
|
368
|
+
tools?: string[] | null;
|
|
369
|
+
role?: string | null;
|
|
370
|
+
goals?: string | null;
|
|
371
|
+
metadata?: JsonObject | null;
|
|
372
|
+
model?: string | null;
|
|
373
|
+
effort?: string | null;
|
|
374
|
+
default_permission_mode?: PermissionMode | null;
|
|
375
|
+
allowed_senders?: string[] | null;
|
|
376
|
+
enable_memory?: boolean | null;
|
|
377
|
+
enable_history?: boolean | null;
|
|
378
|
+
enable_task_setup_tools?: boolean | null;
|
|
379
|
+
enable_feedback?: boolean | null;
|
|
380
|
+
enable_self_improvement?: boolean | null;
|
|
381
|
+
}
|
|
382
|
+
interface AgentListParams {
|
|
383
|
+
user_id?: string;
|
|
384
|
+
limit?: number;
|
|
385
|
+
starting_after?: number;
|
|
386
|
+
}
|
|
387
|
+
interface AgentsResource {
|
|
388
|
+
create(params?: AgentCreateParams): Promise<Agent>;
|
|
389
|
+
list(params?: AgentListParams): Promise<Page<Agent>>;
|
|
390
|
+
get(agentId: number, params?: {
|
|
391
|
+
user_id?: string;
|
|
392
|
+
}): Promise<Agent>;
|
|
393
|
+
update(agentId: number, params: AgentUpdateParams & {
|
|
394
|
+
user_id?: string;
|
|
395
|
+
}): Promise<Agent>;
|
|
396
|
+
delete(agentId: number, params?: {
|
|
397
|
+
user_id?: string;
|
|
398
|
+
}): Promise<void>;
|
|
399
|
+
/** Turn on the webhook trigger; returns the URL to POST to. */
|
|
400
|
+
enableWebhook(agentId: number): Promise<WebhookToggle>;
|
|
401
|
+
disableWebhook(agentId: number): Promise<void>;
|
|
402
|
+
/** Turn on the agent's email inbox; returns the address that starts runs. */
|
|
403
|
+
enableEmailInbox(agentId: number): Promise<EmailInbox>;
|
|
404
|
+
disableEmailInbox(agentId: number): Promise<void>;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* `client.apps` — the tools agents act in, and each end-user's connections to them.
|
|
409
|
+
*
|
|
410
|
+
* Connections are scoped: pass `user_id` and the connection belongs to that
|
|
411
|
+
* end-user, so the agent acts with THEIR Gmail/Stripe/Slack rather than yours.
|
|
412
|
+
* In an embed that matters a lot — an account-level connection means a
|
|
413
|
+
* prompt-injected agent could act on your behalf.
|
|
414
|
+
*
|
|
415
|
+
* Mirrors `sdk/py/m8tes/_resources/apps.py`.
|
|
416
|
+
*/
|
|
417
|
+
|
|
418
|
+
interface AppsResource {
|
|
419
|
+
/**
|
|
420
|
+
* Every available tool, with connection status for the given scope.
|
|
421
|
+
*
|
|
422
|
+
* NOT paginated and NOT cursor-able: `GET /apps/` accepts only `user_id` and
|
|
423
|
+
* returns the whole catalog. Sending `limit` or `starting_after` gets a 422
|
|
424
|
+
* (`unknown_query_parameter`) — verified against a live backend, which is also
|
|
425
|
+
* how the same bug was found in the published Python SDK. A `Page` is still
|
|
426
|
+
* returned so `for await` works uniformly across resources.
|
|
427
|
+
*/
|
|
428
|
+
list(params?: {
|
|
429
|
+
user_id?: string;
|
|
430
|
+
}): Promise<Page<App>>;
|
|
431
|
+
/** True when this app is connected for the given scope. */
|
|
432
|
+
isConnected(appName: string, params?: {
|
|
433
|
+
user_id?: string;
|
|
434
|
+
}): Promise<boolean>;
|
|
435
|
+
/**
|
|
436
|
+
* Start an OAuth connection. Send the user to the returned `authorization_url`,
|
|
437
|
+
* then pass the returned `connection_id` to `connectComplete()`.
|
|
438
|
+
*
|
|
439
|
+
* `redirect_uri` is REQUIRED and is spelled `_uri`, not `_url` — the API 422s
|
|
440
|
+
* on anything else.
|
|
441
|
+
*/
|
|
442
|
+
connectOauth(appName: string, params: {
|
|
443
|
+
redirect_uri: string;
|
|
444
|
+
user_id?: string;
|
|
445
|
+
}): Promise<AppConnectionInitiation>;
|
|
446
|
+
/** Connect an app that authenticates with a key instead of OAuth. */
|
|
447
|
+
connectApiKey(appName: string, params: {
|
|
448
|
+
api_key: string;
|
|
449
|
+
user_id?: string;
|
|
450
|
+
}): Promise<AppConnectionResult>;
|
|
451
|
+
/** Finish an OAuth connection after the user returns. `connection_id` comes
|
|
452
|
+
* from `connectOauth()` and is required. */
|
|
453
|
+
connectComplete(appName: string, params: {
|
|
454
|
+
connection_id: string;
|
|
455
|
+
user_id?: string;
|
|
456
|
+
}): Promise<AppConnectionResult>;
|
|
457
|
+
disconnect(appName: string, params?: {
|
|
458
|
+
user_id?: string;
|
|
459
|
+
}): Promise<void>;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* `RunStream` — the developer-facing view of a streaming run.
|
|
464
|
+
*
|
|
465
|
+
* Mirrors the Python SDK's `RunStream` (`sdk/py/m8tes/_streaming.py`): iterate
|
|
466
|
+
* events, or just await the text. It accumulates as you consume, so after
|
|
467
|
+
* iterating you have `.text`, `.runId`, and `.errors` without a second request.
|
|
468
|
+
*
|
|
469
|
+
* Beyond Python it also exposes `.state` — the full normalized conversation
|
|
470
|
+
* (messages, tool calls, notices) from the shared protocol accumulator. Useful
|
|
471
|
+
* server-side for logging what the agent actually did, not just what it said.
|
|
472
|
+
*
|
|
473
|
+
* Nothing is consumed until you iterate: constructing a RunStream is free, and
|
|
474
|
+
* an un-iterated stream is closed by `close()` without reading the body.
|
|
475
|
+
*/
|
|
476
|
+
|
|
477
|
+
interface RunStreamOptions {
|
|
478
|
+
/**
|
|
479
|
+
* Throw `RunFailedError` once iteration finishes if the run emitted any error
|
|
480
|
+
* event, so a mid-run failure is never mistaken for a successful empty run.
|
|
481
|
+
* Defaults to false, matching the Python SDK.
|
|
482
|
+
*/
|
|
483
|
+
raiseOnError?: boolean;
|
|
484
|
+
}
|
|
485
|
+
declare class RunStream implements AsyncIterable<M8tesStreamEvent> {
|
|
486
|
+
private readonly source;
|
|
487
|
+
private readonly raiseOnError;
|
|
488
|
+
private state;
|
|
489
|
+
private textChunks;
|
|
490
|
+
private errorMessages;
|
|
491
|
+
private runIdValue;
|
|
492
|
+
private consumed;
|
|
493
|
+
constructor(source: AsyncGenerator<M8tesStreamEvent, void, unknown>, options?: RunStreamOptions);
|
|
494
|
+
[Symbol.asyncIterator](): AsyncIterator<M8tesStreamEvent>;
|
|
495
|
+
/** Yield only the assistant's text, in order. The 90% case for a server. */
|
|
496
|
+
iterText(): AsyncGenerator<string, void, unknown>;
|
|
497
|
+
/** Drain the stream and return the full assistant text. */
|
|
498
|
+
text(): Promise<string>;
|
|
499
|
+
/** Accumulated text so far (complete once iteration finishes). */
|
|
500
|
+
get output(): string;
|
|
501
|
+
/** Run id, available as soon as the first `run-start` event arrives. */
|
|
502
|
+
get runId(): number | null;
|
|
503
|
+
/** Error messages the run emitted. Check this, or pass `raiseOnError`. */
|
|
504
|
+
get errors(): string[];
|
|
505
|
+
get hasErrors(): boolean;
|
|
506
|
+
/** Full normalized conversation: messages, tool calls, notices, status. */
|
|
507
|
+
get conversation(): ConversationState;
|
|
508
|
+
/** Close the underlying response without draining it. */
|
|
509
|
+
close(): Promise<void>;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* `client.runs` — start agents, stream what they do, and answer them mid-run.
|
|
514
|
+
*
|
|
515
|
+
* `create()` is the one call most integrations need: it provisions a default
|
|
516
|
+
* agent if the account has none, so a brand-new key can run an agent in one
|
|
517
|
+
* request. Mirrors `sdk/py/m8tes/_resources/runs.py`, field for field.
|
|
518
|
+
*/
|
|
519
|
+
|
|
520
|
+
interface RunCreateParams {
|
|
521
|
+
/** What the agent should do. */
|
|
522
|
+
message: string;
|
|
523
|
+
/** Which agent runs it. Omit to use (or auto-provision) the account default. */
|
|
524
|
+
agent_id?: number;
|
|
525
|
+
/** Permanent legacy alias for `agent_id` — the same wire field. */
|
|
526
|
+
teammate_id?: number;
|
|
527
|
+
/** Your id for the end-user this run belongs to. Isolates their memory, history, and tool connections. */
|
|
528
|
+
user_id?: string;
|
|
529
|
+
/** Tool slugs available for this run. */
|
|
530
|
+
tools?: string[];
|
|
531
|
+
/** One-off system instructions for this run. */
|
|
532
|
+
instructions?: string;
|
|
533
|
+
/** Name a newly auto-created agent. */
|
|
534
|
+
name?: string;
|
|
535
|
+
/** Your own key/value data, echoed back on the Run. */
|
|
536
|
+
metadata?: JsonObject;
|
|
537
|
+
model?: string;
|
|
538
|
+
effort?: string;
|
|
539
|
+
permission_mode?: PermissionMode;
|
|
540
|
+
/** Enable clarifying questions, tool approval, and plan mode. */
|
|
541
|
+
human_in_the_loop?: boolean;
|
|
542
|
+
/** Run-level overrides for the built-in tools. Omit to inherit the agent default. */
|
|
543
|
+
memory?: boolean;
|
|
544
|
+
history?: boolean;
|
|
545
|
+
task_setup_tools?: boolean;
|
|
546
|
+
feedback?: boolean;
|
|
547
|
+
/** Ask for structured output matching this JSON Schema; lands on `run.output_data`. */
|
|
548
|
+
output_schema?: JsonObject;
|
|
549
|
+
/** Give this run's agent an email inbox. */
|
|
550
|
+
email_inbox?: boolean;
|
|
551
|
+
}
|
|
552
|
+
interface RunListParams {
|
|
553
|
+
user_id?: string;
|
|
554
|
+
agent_id?: number;
|
|
555
|
+
teammate_id?: number;
|
|
556
|
+
task_id?: number;
|
|
557
|
+
status?: string;
|
|
558
|
+
limit?: number;
|
|
559
|
+
starting_after?: number;
|
|
560
|
+
}
|
|
561
|
+
interface ApproveParams {
|
|
562
|
+
/** From the `approval-request` event, or `runs.permissions()`. */
|
|
563
|
+
request_id: string;
|
|
564
|
+
decision: "allow" | "deny";
|
|
565
|
+
/**
|
|
566
|
+
* Apply the same decision to matching tool requests for the rest of THIS run.
|
|
567
|
+
* For a policy that outlives the run, use the permissions API instead.
|
|
568
|
+
*/
|
|
569
|
+
remember?: boolean;
|
|
570
|
+
}
|
|
571
|
+
interface AnswerParams {
|
|
572
|
+
/**
|
|
573
|
+
* Question text → the option label you picked. The keys must be the exact
|
|
574
|
+
* `question` strings from the `question` event.
|
|
575
|
+
*/
|
|
576
|
+
answers: Record<string, string>;
|
|
577
|
+
}
|
|
578
|
+
interface RunsResource {
|
|
579
|
+
/** Start a run and stream it. */
|
|
580
|
+
create(params: RunCreateParams, options?: RunStreamOptions): RunStream;
|
|
581
|
+
/** Start a run and return immediately; poll `get()` or use a webhook for the result. */
|
|
582
|
+
createAsync(params: RunCreateParams): Promise<Run>;
|
|
583
|
+
/** Join a run already in flight. Throws `RunNotStreamingError` if it has finished. */
|
|
584
|
+
stream(runId: number, options?: RunStreamOptions): RunStream;
|
|
585
|
+
/** Continue the conversation on an existing run, streaming the reply. */
|
|
586
|
+
reply(runId: number, message: string, options?: RunStreamOptions): RunStream;
|
|
587
|
+
/** GET /runs/{id} takes NO query params — it is already account-scoped, and
|
|
588
|
+
* sending `user_id` returns 422 `unknown_query_parameter`. */
|
|
589
|
+
get(runId: number): Promise<Run>;
|
|
590
|
+
list(params?: RunListParams): Promise<Page<Run>>;
|
|
591
|
+
/** Cancel a running run. Returns the updated Run, like the Python SDK. */
|
|
592
|
+
cancel(runId: number): Promise<Run>;
|
|
593
|
+
/** Approve or deny a pending tool-permission gate. */
|
|
594
|
+
approve(runId: number, params: ApproveParams): Promise<PermissionRequest>;
|
|
595
|
+
/** Answer a pending AskUserQuestion gate, resuming the run. */
|
|
596
|
+
answer(runId: number, params: AnswerParams): Promise<{
|
|
597
|
+
status: string;
|
|
598
|
+
resumed: boolean;
|
|
599
|
+
}>;
|
|
600
|
+
/** Gates currently waiting on a human. */
|
|
601
|
+
permissions(runId: number): Promise<PermissionRequest[]>;
|
|
602
|
+
/** Condensed result: headline, summary, tokens, cost. */
|
|
603
|
+
outcome(runId: number): Promise<RunOutcome>;
|
|
604
|
+
/** Files the agent produced. */
|
|
605
|
+
files(runId: number): Promise<RunFile[]>;
|
|
606
|
+
/** Download one produced file. */
|
|
607
|
+
downloadFile(runId: number, filename: string): Promise<ArrayBuffer>;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
/**
|
|
611
|
+
* `client.settings` — account-level configuration.
|
|
612
|
+
*
|
|
613
|
+
* In v0.1 scope for one concrete reason: strict multi-tenant mode
|
|
614
|
+
* (`require_end_user_id`) is ON by default for API accounts, and when it rejects a
|
|
615
|
+
* request the backend's own 422 message says "turn it off once with
|
|
616
|
+
* client.settings.update(require_end_user_id=False)". Without this resource a
|
|
617
|
+
* TypeScript developer would follow that instruction into a method that does not
|
|
618
|
+
* exist. Found by running the SDK against a real backend.
|
|
619
|
+
*
|
|
620
|
+
* Mirrors `sdk/py/m8tes/_resources/settings.py`.
|
|
621
|
+
*/
|
|
622
|
+
|
|
623
|
+
interface AccountSettings {
|
|
624
|
+
/** Per-end-user monthly run cap. null = uncapped. */
|
|
625
|
+
per_end_user_run_limit: number | null;
|
|
626
|
+
/** Per-end-user monthly metered spend cap, in cents. null = uncapped. */
|
|
627
|
+
per_end_user_cost_limit_cents: number | null;
|
|
628
|
+
/** Per-end-user run-starts per minute. null = unthrottled. */
|
|
629
|
+
per_end_user_rate_per_minute: number | null;
|
|
630
|
+
/** "standard", or "metadata_only" for zero data retention. */
|
|
631
|
+
retention_mode: string;
|
|
632
|
+
/** When true, any request that would fall back to the account scope is rejected. */
|
|
633
|
+
require_end_user_id: boolean;
|
|
634
|
+
}
|
|
635
|
+
interface AccountSettingsUpdateParams {
|
|
636
|
+
/** Pass a number to set, `null` to clear, omit to leave unchanged. */
|
|
637
|
+
per_end_user_run_limit?: number | null;
|
|
638
|
+
per_end_user_cost_limit_cents?: number | null;
|
|
639
|
+
per_end_user_rate_per_minute?: number | null;
|
|
640
|
+
retention_mode?: "standard" | "metadata_only";
|
|
641
|
+
/**
|
|
642
|
+
* Strict multi-tenant mode. ON by default for API accounts: a request that
|
|
643
|
+
* omits `user_id` and would therefore land in the account-level scope is
|
|
644
|
+
* rejected with a 422 rather than silently assuming the global scope.
|
|
645
|
+
*
|
|
646
|
+
* Set false only if you are building for yourself (single-tenant).
|
|
647
|
+
*/
|
|
648
|
+
require_end_user_id?: boolean;
|
|
649
|
+
}
|
|
650
|
+
interface SettingsResource {
|
|
651
|
+
get(): Promise<AccountSettings>;
|
|
652
|
+
update(params: AccountSettingsUpdateParams): Promise<AccountSettings>;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
/**
|
|
656
|
+
* `client.tasks` — reusable work definitions, plus the triggers that fire them.
|
|
657
|
+
*
|
|
658
|
+
* A task is "what to do"; a trigger is "when". `client.tasks.triggers` covers all
|
|
659
|
+
* four kinds (schedule, webhook, email, app event). Mirrors
|
|
660
|
+
* `sdk/py/m8tes/_resources/tasks.py`.
|
|
661
|
+
*/
|
|
662
|
+
|
|
663
|
+
/** A task must belong to an agent: `POST /tasks/` requires `teammate_id`, so the
|
|
664
|
+
* type requires one of the two spellings rather than letting you discover it as
|
|
665
|
+
* a 422. */
|
|
666
|
+
type TaskOwner = {
|
|
667
|
+
agent_id: number;
|
|
668
|
+
teammate_id?: never;
|
|
669
|
+
} | {
|
|
670
|
+
teammate_id: number;
|
|
671
|
+
agent_id?: never;
|
|
672
|
+
};
|
|
673
|
+
type TaskCreateParams = TaskOwner & TaskCreateFields;
|
|
674
|
+
interface TaskCreateFields {
|
|
675
|
+
/** What the agent should do each time this task runs. */
|
|
676
|
+
instructions: string;
|
|
677
|
+
name?: string;
|
|
678
|
+
tools?: string[];
|
|
679
|
+
/** What a good result looks like. */
|
|
680
|
+
expected_output?: string;
|
|
681
|
+
goals?: string;
|
|
682
|
+
user_id?: string;
|
|
683
|
+
/** Email the account owner when a run finishes. Default true. */
|
|
684
|
+
email_notifications?: boolean;
|
|
685
|
+
/** Create a webhook trigger alongside the task. */
|
|
686
|
+
webhook?: boolean;
|
|
687
|
+
/** Cron expression, e.g. `"0 9 * * 1-5"`. Creates a schedule trigger. */
|
|
688
|
+
schedule?: string;
|
|
689
|
+
/** IANA timezone for `schedule`. Default "UTC". */
|
|
690
|
+
schedule_timezone?: string;
|
|
691
|
+
enable_memory?: boolean;
|
|
692
|
+
enable_history?: boolean;
|
|
693
|
+
enable_task_setup_tools?: boolean;
|
|
694
|
+
enable_feedback?: boolean;
|
|
695
|
+
/** Accumulate self-improvement lessons across this task's runs. Default true. */
|
|
696
|
+
enable_lessons?: boolean;
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
* PATCH /tasks/{id} accepts exactly these fields (backend `DevTaskUpdate`).
|
|
700
|
+
* `schedule`, `schedule_timezone`, `webhook`, and the agent id are create-only:
|
|
701
|
+
* sending them to PATCH returns 200 and changes nothing. Change a schedule via
|
|
702
|
+
* `tasks.triggers.update()`, and a webhook via `enableWebhook()`.
|
|
703
|
+
*
|
|
704
|
+
* `null` is meaningful: it CLEARS the field.
|
|
705
|
+
*/
|
|
706
|
+
interface TaskUpdateParams {
|
|
707
|
+
name?: string | null;
|
|
708
|
+
instructions?: string | null;
|
|
709
|
+
tools?: string[] | null;
|
|
710
|
+
expected_output?: string | null;
|
|
711
|
+
goals?: string | null;
|
|
712
|
+
email_notifications?: boolean | null;
|
|
713
|
+
enable_memory?: boolean | null;
|
|
714
|
+
enable_history?: boolean | null;
|
|
715
|
+
enable_task_setup_tools?: boolean | null;
|
|
716
|
+
enable_feedback?: boolean | null;
|
|
717
|
+
enable_lessons?: boolean | null;
|
|
718
|
+
}
|
|
719
|
+
interface TaskListParams {
|
|
720
|
+
user_id?: string;
|
|
721
|
+
agent_id?: number;
|
|
722
|
+
teammate_id?: number;
|
|
723
|
+
status?: string;
|
|
724
|
+
limit?: number;
|
|
725
|
+
starting_after?: number;
|
|
726
|
+
}
|
|
727
|
+
interface TriggerCreateParams {
|
|
728
|
+
type: TriggerType | string;
|
|
729
|
+
/** Schedule triggers: a cron expression. */
|
|
730
|
+
cron?: string;
|
|
731
|
+
/** Schedule triggers: a plain interval instead of cron. */
|
|
732
|
+
interval_seconds?: number;
|
|
733
|
+
/** IANA timezone. Default "UTC". */
|
|
734
|
+
timezone?: string;
|
|
735
|
+
/** App-event triggers: the app slug, e.g. `"github"`. */
|
|
736
|
+
app?: string;
|
|
737
|
+
/** App-event triggers: the event name, e.g. `"pull_request_opened"`. */
|
|
738
|
+
trigger_name?: string;
|
|
739
|
+
trigger_config?: JsonObject;
|
|
740
|
+
user_id?: string;
|
|
741
|
+
/** Email triggers: only these senders may start a run. */
|
|
742
|
+
allowed_senders?: string[];
|
|
743
|
+
}
|
|
744
|
+
interface TriggersResource {
|
|
745
|
+
create(taskId: number, params: TriggerCreateParams): Promise<Trigger>;
|
|
746
|
+
list(taskId: number): Promise<Trigger[]>;
|
|
747
|
+
/** Only the schedule shape and the enabled flag are mutable — a trigger's
|
|
748
|
+
* `type`/`app`/`trigger_name` are fixed at creation and are silently ignored
|
|
749
|
+
* on PATCH. Delete and recreate to change those. */
|
|
750
|
+
update(taskId: number, triggerId: number, params: {
|
|
751
|
+
cron?: string;
|
|
752
|
+
interval_seconds?: number;
|
|
753
|
+
timezone?: string;
|
|
754
|
+
enabled?: boolean;
|
|
755
|
+
}): Promise<Trigger>;
|
|
756
|
+
delete(taskId: number, triggerId: number): Promise<void>;
|
|
757
|
+
}
|
|
758
|
+
interface TasksResource {
|
|
759
|
+
triggers: TriggersResource;
|
|
760
|
+
create(params: TaskCreateParams): Promise<Task>;
|
|
761
|
+
list(params?: TaskListParams): Promise<Page<Task>>;
|
|
762
|
+
get(taskId: number, params?: {
|
|
763
|
+
user_id?: string;
|
|
764
|
+
}): Promise<Task>;
|
|
765
|
+
update(taskId: number, params: TaskUpdateParams & {
|
|
766
|
+
user_id?: string;
|
|
767
|
+
}): Promise<Task>;
|
|
768
|
+
delete(taskId: number, params?: {
|
|
769
|
+
user_id?: string;
|
|
770
|
+
}): Promise<void>;
|
|
771
|
+
/** Run the task now, streaming it. */
|
|
772
|
+
run(taskId: number, params?: {
|
|
773
|
+
user_id?: string;
|
|
774
|
+
}, options?: RunStreamOptions): RunStream;
|
|
775
|
+
/** Run the task now without streaming; poll `runs.get()` for the result. */
|
|
776
|
+
runAsync(taskId: number, params?: {
|
|
777
|
+
user_id?: string;
|
|
778
|
+
}): Promise<Run>;
|
|
779
|
+
enableWebhook(taskId: number): Promise<WebhookToggle>;
|
|
780
|
+
disableWebhook(taskId: number): Promise<void>;
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
/**
|
|
784
|
+
* `client.users` — your end-users, the multi-tenancy boundary.
|
|
785
|
+
*
|
|
786
|
+
* `user_id` is YOUR identifier for a customer; the platform stores it as
|
|
787
|
+
* `end_user_id` and isolates that person's memory, run history, and tool
|
|
788
|
+
* connections strictly. There is no fallback to account-level data.
|
|
789
|
+
*
|
|
790
|
+
* Registering an end-user here is optional — passing `user_id` on a run creates
|
|
791
|
+
* them implicitly. Do it explicitly when you want per-user budgets and rate
|
|
792
|
+
* limits. Mirrors `sdk/py/m8tes/_resources/users.py`.
|
|
793
|
+
*/
|
|
794
|
+
|
|
795
|
+
interface EndUserCreateParams {
|
|
796
|
+
/** Your id for this person. Any stable string. */
|
|
797
|
+
user_id: string;
|
|
798
|
+
name?: string;
|
|
799
|
+
email?: string;
|
|
800
|
+
company?: string;
|
|
801
|
+
metadata?: JsonObject;
|
|
802
|
+
/** Cap this end-user's runs per billing period. */
|
|
803
|
+
run_limit?: number;
|
|
804
|
+
/** Cap this end-user's spend per billing period, in cents. */
|
|
805
|
+
cost_limit_cents?: number;
|
|
806
|
+
/** Cap this end-user's runs per minute. Exceeding it returns 429. */
|
|
807
|
+
rate_per_minute?: number;
|
|
808
|
+
}
|
|
809
|
+
/** `null` CLEARS a cap (inherit the account default); omitting leaves it alone. */
|
|
810
|
+
interface EndUserUpdateParams {
|
|
811
|
+
name?: string | null;
|
|
812
|
+
email?: string | null;
|
|
813
|
+
company?: string | null;
|
|
814
|
+
metadata?: JsonObject | null;
|
|
815
|
+
run_limit?: number | null;
|
|
816
|
+
cost_limit_cents?: number | null;
|
|
817
|
+
rate_per_minute?: number | null;
|
|
818
|
+
}
|
|
819
|
+
interface PageParams {
|
|
820
|
+
limit?: number;
|
|
821
|
+
starting_after?: number;
|
|
822
|
+
}
|
|
823
|
+
interface UsersResource {
|
|
824
|
+
create(params: EndUserCreateParams): Promise<EndUser>;
|
|
825
|
+
list(params?: PageParams): Promise<Page<EndUser>>;
|
|
826
|
+
get(userId: string): Promise<EndUser>;
|
|
827
|
+
update(userId: string, params: EndUserUpdateParams): Promise<EndUser>;
|
|
828
|
+
delete(userId: string): Promise<void>;
|
|
829
|
+
/** Per-end-user token, run, and cost usage against their limits. */
|
|
830
|
+
usage(params?: PageParams & {
|
|
831
|
+
user_id?: string;
|
|
832
|
+
}): Promise<Page<EndUserUsage>>;
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
/**
|
|
836
|
+
* `client.webhooks` — outbound event delivery, plus signature verification.
|
|
837
|
+
*
|
|
838
|
+
* `verifySignature` is the one function every webhook receiver needs, so it is
|
|
839
|
+
* also exported standalone from the package root: verifying does not require a
|
|
840
|
+
* client or an API key. Mirrors `sdk/py/m8tes/_resources/webhooks.py` byte for
|
|
841
|
+
* byte on the signing scheme, so a payload verified by one SDK verifies in the
|
|
842
|
+
* other.
|
|
843
|
+
*
|
|
844
|
+
* Scheme: HMAC-SHA256 over `"{webhook-id}.{webhook-timestamp}.{raw body}"`, hex,
|
|
845
|
+
* prefixed `v1=`, compared in constant time.
|
|
846
|
+
*/
|
|
847
|
+
|
|
848
|
+
interface VerifySignatureOptions {
|
|
849
|
+
/**
|
|
850
|
+
* Reject signatures whose timestamp is older (or newer) than this many
|
|
851
|
+
* seconds — replay protection. Omit to skip the check. 300 is a good default
|
|
852
|
+
* for a public endpoint.
|
|
853
|
+
*/
|
|
854
|
+
toleranceSeconds?: number;
|
|
855
|
+
/** Injectable clock, for tests. Seconds since epoch. */
|
|
856
|
+
now?: () => number;
|
|
857
|
+
}
|
|
858
|
+
/**
|
|
859
|
+
* Verify a m8tes webhook signature.
|
|
860
|
+
*
|
|
861
|
+
* Pass the RAW request body — a parsed-and-restringified object will not match,
|
|
862
|
+
* because JSON.stringify does not preserve key order or spacing.
|
|
863
|
+
*
|
|
864
|
+
* ```ts
|
|
865
|
+
* const raw = await req.text();
|
|
866
|
+
* if (!verifySignature(raw, Object.fromEntries(req.headers), secret, { toleranceSeconds: 300 })) {
|
|
867
|
+
* return new Response("bad signature", { status: 401 });
|
|
868
|
+
* }
|
|
869
|
+
* ```
|
|
870
|
+
*/
|
|
871
|
+
declare function verifySignature(body: string | Uint8Array, headers: Record<string, string | string[] | undefined> | Headers, secret: string, options?: VerifySignatureOptions): boolean;
|
|
872
|
+
interface WebhooksResource {
|
|
873
|
+
verifySignature: typeof verifySignature;
|
|
874
|
+
/** Register an endpoint. The signing secret is returned ONLY here — store it. */
|
|
875
|
+
create(params: {
|
|
876
|
+
url: string;
|
|
877
|
+
events?: string[];
|
|
878
|
+
}): Promise<Webhook>;
|
|
879
|
+
list(params?: {
|
|
880
|
+
limit?: number;
|
|
881
|
+
starting_after?: number;
|
|
882
|
+
}): Promise<Page<Webhook>>;
|
|
883
|
+
get(webhookId: number): Promise<Webhook>;
|
|
884
|
+
update(webhookId: number, params: {
|
|
885
|
+
url?: string;
|
|
886
|
+
events?: string[];
|
|
887
|
+
active?: boolean;
|
|
888
|
+
}): Promise<Webhook>;
|
|
889
|
+
delete(webhookId: number): Promise<void>;
|
|
890
|
+
/** Delivery attempts, for debugging a receiver that is not getting events. */
|
|
891
|
+
listDeliveries(webhookId: number, params?: {
|
|
892
|
+
limit?: number;
|
|
893
|
+
starting_after?: number;
|
|
894
|
+
}): Promise<Page<WebhookDelivery>>;
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
/**
|
|
898
|
+
* `@m8tes/sdk` — TypeScript client for the m8tes API.
|
|
899
|
+
*
|
|
900
|
+
* ```ts
|
|
901
|
+
* import { M8tes } from "@m8tes/sdk";
|
|
902
|
+
*
|
|
903
|
+
* const client = new M8tes(); // reads M8TES_API_KEY
|
|
904
|
+
*
|
|
905
|
+
* const run = client.runs.create({
|
|
906
|
+
* message: "A customer asked to cancel. Draft a warm reply offering to pause instead.",
|
|
907
|
+
* userId: "customer_42", // isolates this end-user's memory, history, and connections
|
|
908
|
+
* });
|
|
909
|
+
* for await (const chunk of run.iterText()) process.stdout.write(chunk);
|
|
910
|
+
* ```
|
|
911
|
+
*
|
|
912
|
+
* SECURITY: this entry point holds your secret `m8_` key and is server-only.
|
|
913
|
+
* Never import it from client-side code. To render an agent in a browser, use
|
|
914
|
+
* `@m8tes/react` plus its server proxy, which keeps the key on your server.
|
|
915
|
+
*
|
|
916
|
+
* The streaming wire protocol lives in `@m8tes/sdk/protocol` (browser-safe, no
|
|
917
|
+
* auth) so this package and `@m8tes/react` share one implementation.
|
|
918
|
+
*/
|
|
919
|
+
|
|
920
|
+
/** Kept in lockstep with package.json "version" — guarded by test/version.test.ts. */
|
|
921
|
+
declare const M8TES_SDK_VERSION = "0.1.0-alpha.1";
|
|
922
|
+
declare class M8tes {
|
|
923
|
+
readonly runs: RunsResource;
|
|
924
|
+
readonly agents: AgentsResource;
|
|
925
|
+
/** Permanent alias for `agents` — the DB model and older docs say "teammate". */
|
|
926
|
+
readonly teammates: AgentsResource;
|
|
927
|
+
readonly tasks: TasksResource;
|
|
928
|
+
readonly users: UsersResource;
|
|
929
|
+
readonly apps: AppsResource;
|
|
930
|
+
readonly webhooks: WebhooksResource;
|
|
931
|
+
readonly settings: SettingsResource;
|
|
932
|
+
/** The underlying transport. Use it to call an endpoint this version does not wrap yet. */
|
|
933
|
+
readonly http: Http;
|
|
934
|
+
constructor(options?: ClientOptions);
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
export { type AccountSettings, type AccountSettingsUpdateParams, type Agent, type AgentCreateParams, type AgentListParams, type AgentUpdateParams, type AgentsResource, type App, type AppConnectionInitiation, type AppConnectionResult, type AppsResource, type ClientOptions, ConversationState, DEFAULT_BASE_URL, type EmailInbox, type EndUser, type EndUserCreateParams, type EndUserUpdateParams, type EndUserUsage, type FetchLike, type Http, type JsonObject, type ListResponse, M8TES_SDK_VERSION, M8tes, M8tesStreamEvent, Normalizer, Page, type PageParams, type PermissionMode, type PermissionRequest, type Run, type RunCreateParams, type RunFile, type RunListParams, type RunOutcome, RunStream, type RunStreamOptions, type RunUsage, type RunsResource, type SettingsResource, type Task, type TaskCreateParams, type TaskListParams, type TaskUpdateParams, type TasksResource, type Teammate, type Trigger, type TriggerCreateParams, type TriggerType, type TriggersResource, type UsersResource, type VerifySignatureOptions, type Webhook, type WebhookDelivery, type WebhookToggle, type WebhooksResource, createHttp, verifySignature };
|