@jettson/sdk 0.1.0
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/LICENSE +21 -0
- package/README.md +249 -0
- package/dist/index.cjs +500 -0
- package/dist/index.d.cts +380 -0
- package/dist/index.d.ts +380 -0
- package/dist/index.js +464 -0
- package/package.json +58 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
interface HttpClientOptions {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
/** Max retries on 429 / 5xx. Total attempts = 1 + maxRetries. */
|
|
5
|
+
maxRetries?: number;
|
|
6
|
+
/** Initial backoff in ms for 5xx (doubles each retry). */
|
|
7
|
+
initialBackoffMs?: number;
|
|
8
|
+
}
|
|
9
|
+
interface RequestOptions {
|
|
10
|
+
method: "GET" | "POST" | "DELETE" | "PUT" | "PATCH";
|
|
11
|
+
path: string;
|
|
12
|
+
query?: Record<string, string | number | boolean | undefined>;
|
|
13
|
+
body?: unknown;
|
|
14
|
+
idempotencyKey?: string;
|
|
15
|
+
}
|
|
16
|
+
declare class HttpClient {
|
|
17
|
+
private readonly apiKey;
|
|
18
|
+
private readonly baseUrl;
|
|
19
|
+
private readonly maxRetries;
|
|
20
|
+
private readonly initialBackoffMs;
|
|
21
|
+
constructor(opts: HttpClientOptions);
|
|
22
|
+
request<T>(req: RequestOptions): Promise<T>;
|
|
23
|
+
private buildUrl;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Public types for the Jettson SDK. Every interface here mirrors a shape
|
|
28
|
+
* the Jettson API actually returns; we don't synthesize anything that the
|
|
29
|
+
* server doesn't ground-truth.
|
|
30
|
+
*/
|
|
31
|
+
type AgentStatus = "spawning" | "running" | "completed" | "error" | "stopped" | "idle";
|
|
32
|
+
type Region = "iad" | "lhr" | "syd";
|
|
33
|
+
type MemorySource = "manual" | "auto_extracted" | "consolidated";
|
|
34
|
+
type MemorySearchMode = "hybrid" | "semantic" | "keyword";
|
|
35
|
+
interface AgentProgressEntry {
|
|
36
|
+
ts: number;
|
|
37
|
+
kind: "info" | "tool_use" | "complete" | "error";
|
|
38
|
+
message: string;
|
|
39
|
+
}
|
|
40
|
+
interface Agent {
|
|
41
|
+
agent_id: string;
|
|
42
|
+
name: string;
|
|
43
|
+
status: AgentStatus;
|
|
44
|
+
task: string | null;
|
|
45
|
+
created_at: string;
|
|
46
|
+
updated_at?: string;
|
|
47
|
+
final_result: string | null;
|
|
48
|
+
progress?: AgentProgressEntry[];
|
|
49
|
+
error: string | null;
|
|
50
|
+
model: string;
|
|
51
|
+
container?: {
|
|
52
|
+
region: string;
|
|
53
|
+
status: string;
|
|
54
|
+
};
|
|
55
|
+
warm_hit?: boolean;
|
|
56
|
+
spawn_time_ms?: number;
|
|
57
|
+
}
|
|
58
|
+
interface AgentListResponse {
|
|
59
|
+
data: Agent[];
|
|
60
|
+
next_cursor: string | null;
|
|
61
|
+
}
|
|
62
|
+
interface Memory {
|
|
63
|
+
memory_id: string;
|
|
64
|
+
key: string;
|
|
65
|
+
namespace: string;
|
|
66
|
+
value: string;
|
|
67
|
+
tags: string[];
|
|
68
|
+
importance: number;
|
|
69
|
+
source: MemorySource;
|
|
70
|
+
access_count: number;
|
|
71
|
+
created_at: number;
|
|
72
|
+
updated_at: number;
|
|
73
|
+
expires_at?: number;
|
|
74
|
+
}
|
|
75
|
+
interface MemorySearchResult {
|
|
76
|
+
memory_id: string;
|
|
77
|
+
key: string;
|
|
78
|
+
namespace: string;
|
|
79
|
+
value: string;
|
|
80
|
+
tags: string[];
|
|
81
|
+
importance: number;
|
|
82
|
+
source: MemorySource;
|
|
83
|
+
score: number;
|
|
84
|
+
breakdown: {
|
|
85
|
+
semantic?: number;
|
|
86
|
+
keyword?: number;
|
|
87
|
+
importance?: number;
|
|
88
|
+
timeDecay?: number;
|
|
89
|
+
};
|
|
90
|
+
created_at: number;
|
|
91
|
+
}
|
|
92
|
+
interface NamespaceInfo {
|
|
93
|
+
namespace: string;
|
|
94
|
+
count: number;
|
|
95
|
+
}
|
|
96
|
+
interface DedupePair {
|
|
97
|
+
kept: string;
|
|
98
|
+
removed: string;
|
|
99
|
+
similarity: number;
|
|
100
|
+
}
|
|
101
|
+
interface DedupeResult {
|
|
102
|
+
removed: number;
|
|
103
|
+
kept: number;
|
|
104
|
+
pairs: DedupePair[];
|
|
105
|
+
}
|
|
106
|
+
interface ConsolidateSummary {
|
|
107
|
+
memory_id: string;
|
|
108
|
+
key: string;
|
|
109
|
+
namespace: string;
|
|
110
|
+
value: string;
|
|
111
|
+
tags: string[];
|
|
112
|
+
importance: number;
|
|
113
|
+
}
|
|
114
|
+
interface ConsolidateResult {
|
|
115
|
+
consolidated: number;
|
|
116
|
+
new_summaries: ConsolidateSummary[];
|
|
117
|
+
}
|
|
118
|
+
interface ImportResult {
|
|
119
|
+
imported: number;
|
|
120
|
+
failed: number;
|
|
121
|
+
errors: Array<{
|
|
122
|
+
index: number;
|
|
123
|
+
key: unknown;
|
|
124
|
+
reason: string;
|
|
125
|
+
}>;
|
|
126
|
+
partial?: boolean;
|
|
127
|
+
}
|
|
128
|
+
/** Subset of `Memory` accepted by `client.memory.import()`. */
|
|
129
|
+
interface MemoryImportInput {
|
|
130
|
+
key: string;
|
|
131
|
+
value: string;
|
|
132
|
+
namespace?: string;
|
|
133
|
+
tags?: string[];
|
|
134
|
+
importance?: number;
|
|
135
|
+
expires_at?: number;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* AgentsResource — every operation on the `/api/v1/agents` surface.
|
|
140
|
+
*
|
|
141
|
+
* The killer feature is `wait()`: spawn → wait → done in three lines.
|
|
142
|
+
* Polling is server-friendly: 1s → 1.5s → 2.25s → up to 5s ceiling.
|
|
143
|
+
*/
|
|
144
|
+
|
|
145
|
+
interface SpawnInput {
|
|
146
|
+
task: string;
|
|
147
|
+
name?: string;
|
|
148
|
+
region?: Region;
|
|
149
|
+
/** Forwarded to the agent's metadata (server reads `metadata.region` too). */
|
|
150
|
+
metadata?: Record<string, unknown>;
|
|
151
|
+
/**
|
|
152
|
+
* Optional client-provided idempotency key. If you retry a spawn with
|
|
153
|
+
* the same key inside a short window, the server returns the existing
|
|
154
|
+
* agent instead of creating a duplicate. (Server-side idempotency is
|
|
155
|
+
* advisory for now — Day 12 deploy adds the full enforcement.)
|
|
156
|
+
*/
|
|
157
|
+
idempotencyKey?: string;
|
|
158
|
+
}
|
|
159
|
+
interface ListInput {
|
|
160
|
+
limit?: number;
|
|
161
|
+
cursor?: string;
|
|
162
|
+
}
|
|
163
|
+
interface WaitInput {
|
|
164
|
+
/** Max wall-clock to wait. Defaults to 5 minutes. */
|
|
165
|
+
timeoutMs?: number;
|
|
166
|
+
/** Initial poll interval. Backs off to `maxPollIntervalMs`. */
|
|
167
|
+
pollIntervalMs?: number;
|
|
168
|
+
/** Ceiling for backoff. Defaults to 5,000 ms. */
|
|
169
|
+
maxPollIntervalMs?: number;
|
|
170
|
+
}
|
|
171
|
+
declare class AgentsResource {
|
|
172
|
+
private readonly http;
|
|
173
|
+
constructor(http: HttpClient);
|
|
174
|
+
/**
|
|
175
|
+
* Spawn a new agent. Returns immediately with `status: "spawning"`.
|
|
176
|
+
* Use `wait()` to block until the agent finishes.
|
|
177
|
+
*/
|
|
178
|
+
spawn(input: SpawnInput): Promise<Agent>;
|
|
179
|
+
/** Fetch one agent by ID. */
|
|
180
|
+
get(agentId: string): Promise<Agent>;
|
|
181
|
+
/** Paginated list of the caller's agents, newest first. */
|
|
182
|
+
list(input?: ListInput): Promise<AgentListResponse>;
|
|
183
|
+
/**
|
|
184
|
+
* Cancel a running agent. Idempotent — terminal agents return 200
|
|
185
|
+
* unchanged.
|
|
186
|
+
*/
|
|
187
|
+
cancel(agentId: string): Promise<void>;
|
|
188
|
+
/**
|
|
189
|
+
* Poll `get(agentId)` until the agent reaches a terminal status, with
|
|
190
|
+
* gentle exponential backoff. Throws `AgentTimeoutError` if the
|
|
191
|
+
* deadline lapses.
|
|
192
|
+
*/
|
|
193
|
+
wait(agentId: string, opts?: WaitInput): Promise<Agent>;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* MemoryResource — every operation on the `/api/v1/memory` surface.
|
|
198
|
+
*
|
|
199
|
+
* Memory is user-scoped (all your agents share the same pool), with
|
|
200
|
+
* (key, namespace) as the natural identity. Hybrid search ranks by
|
|
201
|
+
* semantic similarity + keyword overlap + importance + time decay.
|
|
202
|
+
*/
|
|
203
|
+
|
|
204
|
+
interface MemoryPutInput {
|
|
205
|
+
key: string;
|
|
206
|
+
value: string;
|
|
207
|
+
namespace?: string;
|
|
208
|
+
tags?: string[];
|
|
209
|
+
importance?: number;
|
|
210
|
+
expiresInDays?: number;
|
|
211
|
+
}
|
|
212
|
+
interface MemoryGetOptions {
|
|
213
|
+
namespace?: string;
|
|
214
|
+
}
|
|
215
|
+
interface MemoryDeleteOptions {
|
|
216
|
+
namespace?: string;
|
|
217
|
+
/** Default soft-deletes. Set true for permanent removal. */
|
|
218
|
+
hardDelete?: boolean;
|
|
219
|
+
}
|
|
220
|
+
interface MemorySearchInput {
|
|
221
|
+
query: string;
|
|
222
|
+
namespace?: string;
|
|
223
|
+
tags?: string[];
|
|
224
|
+
limit?: number;
|
|
225
|
+
mode?: MemorySearchMode;
|
|
226
|
+
minScore?: number;
|
|
227
|
+
}
|
|
228
|
+
interface MemoryListInput {
|
|
229
|
+
namespace?: string;
|
|
230
|
+
tags?: string[];
|
|
231
|
+
limit?: number;
|
|
232
|
+
}
|
|
233
|
+
interface DedupeInput {
|
|
234
|
+
namespace?: string;
|
|
235
|
+
similarityThreshold?: number;
|
|
236
|
+
dryRun?: boolean;
|
|
237
|
+
}
|
|
238
|
+
interface ConsolidateInput {
|
|
239
|
+
namespace?: string;
|
|
240
|
+
minClusterSize?: number;
|
|
241
|
+
threshold?: number;
|
|
242
|
+
}
|
|
243
|
+
declare class MemoryResource {
|
|
244
|
+
private readonly http;
|
|
245
|
+
constructor(http: HttpClient);
|
|
246
|
+
put(input: MemoryPutInput): Promise<Memory>;
|
|
247
|
+
/** Returns `null` (not an error) when no memory matches. */
|
|
248
|
+
get(key: string, opts?: MemoryGetOptions): Promise<Memory | null>;
|
|
249
|
+
delete(key: string, opts?: MemoryDeleteOptions): Promise<void>;
|
|
250
|
+
search(input: MemorySearchInput): Promise<MemorySearchResult[]>;
|
|
251
|
+
list(input?: MemoryListInput): Promise<Memory[]>;
|
|
252
|
+
dedupe(input?: DedupeInput): Promise<DedupeResult>;
|
|
253
|
+
consolidate(input?: ConsolidateInput): Promise<ConsolidateResult>;
|
|
254
|
+
namespaces(): Promise<NamespaceInfo[]>;
|
|
255
|
+
export(): Promise<{
|
|
256
|
+
version: number;
|
|
257
|
+
exported_at: number;
|
|
258
|
+
count: number;
|
|
259
|
+
memories: Memory[];
|
|
260
|
+
}>;
|
|
261
|
+
import(memories: MemoryImportInput[]): Promise<ImportResult>;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* SDK error hierarchy.
|
|
266
|
+
*
|
|
267
|
+
* Every HTTP failure response from Jettson lands as one of these. The
|
|
268
|
+
* server's `{ error: { code, message, details } }` envelope maps to
|
|
269
|
+
* specific subclasses based on HTTP status + the `code` field — so
|
|
270
|
+
* callers can `catch (e) { if (e instanceof JettsonRateLimitError) ... }`
|
|
271
|
+
* without parsing the response body.
|
|
272
|
+
*
|
|
273
|
+
* `details` carries the structured context the API surfaces (e.g.
|
|
274
|
+
* `{ used, limit, plan }` on quota errors). It's typed loosely on the
|
|
275
|
+
* base class because each subclass narrows the useful fields.
|
|
276
|
+
*/
|
|
277
|
+
declare class JettsonError extends Error {
|
|
278
|
+
readonly code: string;
|
|
279
|
+
readonly status: number;
|
|
280
|
+
readonly details: Record<string, unknown> | undefined;
|
|
281
|
+
constructor(opts: {
|
|
282
|
+
message: string;
|
|
283
|
+
code: string;
|
|
284
|
+
status: number;
|
|
285
|
+
details?: Record<string, unknown>;
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
/** HTTP 401 — missing, expired, or revoked API key. */
|
|
289
|
+
declare class JettsonAuthError extends JettsonError {
|
|
290
|
+
constructor(opts: {
|
|
291
|
+
message: string;
|
|
292
|
+
code: string;
|
|
293
|
+
details?: Record<string, unknown>;
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
/** HTTP 429 — per-key spawn rate cap exceeded. */
|
|
297
|
+
declare class JettsonRateLimitError extends JettsonError {
|
|
298
|
+
readonly retryAfterSeconds: number;
|
|
299
|
+
constructor(opts: {
|
|
300
|
+
message: string;
|
|
301
|
+
code: string;
|
|
302
|
+
retryAfterSeconds: number;
|
|
303
|
+
details?: Record<string, unknown>;
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
/** HTTP 402 — plan quota hit (memory pool, agent-hours, etc). */
|
|
307
|
+
declare class JettsonQuotaExceededError extends JettsonError {
|
|
308
|
+
readonly used: number;
|
|
309
|
+
readonly limit: number;
|
|
310
|
+
readonly plan: string;
|
|
311
|
+
constructor(opts: {
|
|
312
|
+
message: string;
|
|
313
|
+
code: string;
|
|
314
|
+
used: number;
|
|
315
|
+
limit: number;
|
|
316
|
+
plan: string;
|
|
317
|
+
details?: Record<string, unknown>;
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
/** HTTP 400 — body or query failed validation. */
|
|
321
|
+
declare class JettsonValidationError extends JettsonError {
|
|
322
|
+
constructor(opts: {
|
|
323
|
+
message: string;
|
|
324
|
+
code: string;
|
|
325
|
+
details?: Record<string, unknown>;
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
/** HTTP 404 — resource doesn't exist (or doesn't belong to the caller). */
|
|
329
|
+
declare class JettsonNotFoundError extends JettsonError {
|
|
330
|
+
constructor(opts: {
|
|
331
|
+
message: string;
|
|
332
|
+
code: string;
|
|
333
|
+
details?: Record<string, unknown>;
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
/** HTTP 5xx — transient server-side issue. SDK retries automatically. */
|
|
337
|
+
declare class JettsonServerError extends JettsonError {
|
|
338
|
+
constructor(opts: {
|
|
339
|
+
message: string;
|
|
340
|
+
code: string;
|
|
341
|
+
status: number;
|
|
342
|
+
details?: Record<string, unknown>;
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
/** Network connection failure — could not reach the API at all. */
|
|
346
|
+
declare class JettsonNetworkError extends JettsonError {
|
|
347
|
+
constructor(message: string);
|
|
348
|
+
}
|
|
349
|
+
/** `agents.wait()` timed out without reaching a terminal status. */
|
|
350
|
+
declare class AgentTimeoutError extends JettsonError {
|
|
351
|
+
readonly agentId: string;
|
|
352
|
+
readonly elapsedMs: number;
|
|
353
|
+
constructor(agentId: string, elapsedMs: number);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Jettson SDK for Node.js — top-level export.
|
|
358
|
+
*
|
|
359
|
+
* Build AI agents in 3 lines:
|
|
360
|
+
*
|
|
361
|
+
* const j = new Jettson({ apiKey: process.env.JETTSON_API_KEY! });
|
|
362
|
+
* const a = await j.agents.spawn({ task: "Research linear.app" });
|
|
363
|
+
* const r = await j.agents.wait(a.agent_id);
|
|
364
|
+
*/
|
|
365
|
+
|
|
366
|
+
interface JettsonOptions {
|
|
367
|
+
/** Your Jettson API key (begins with `jett_sk_live_…`). Required. */
|
|
368
|
+
apiKey: string;
|
|
369
|
+
/** Override the API base URL — useful for testing against localhost. */
|
|
370
|
+
baseUrl?: string;
|
|
371
|
+
/** Max automatic retries on 429 + 5xx. Defaults to 3. */
|
|
372
|
+
maxRetries?: number;
|
|
373
|
+
}
|
|
374
|
+
declare class Jettson {
|
|
375
|
+
readonly agents: AgentsResource;
|
|
376
|
+
readonly memory: MemoryResource;
|
|
377
|
+
constructor(options: JettsonOptions);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
export { type Agent, type AgentListResponse, type AgentProgressEntry, type AgentStatus, AgentTimeoutError, AgentsResource, type ConsolidateInput, type ConsolidateResult, type ConsolidateSummary, type DedupeInput, type DedupePair, type DedupeResult, type ImportResult, Jettson, JettsonAuthError, JettsonError, JettsonNetworkError, JettsonNotFoundError, type JettsonOptions, JettsonQuotaExceededError, JettsonRateLimitError, JettsonServerError, JettsonValidationError, type ListInput, type Memory, type MemoryDeleteOptions, type MemoryGetOptions, type MemoryImportInput, type MemoryListInput, type MemoryPutInput, MemoryResource, type MemorySearchInput, type MemorySearchMode, type MemorySearchResult, type MemorySource, type NamespaceInfo, type Region, type SpawnInput, type WaitInput };
|