@operator-labs/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/README.md ADDED
@@ -0,0 +1,212 @@
1
+ # @operator-labs/sdk
2
+
3
+ TypeScript SDK for the Operator platform. Manage agents, chat, instances, automations, and webhooks programmatically using a Chat API key.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @operator-labs/sdk
9
+ ```
10
+
11
+ Or link locally during development:
12
+
13
+ ```bash
14
+ cd sdk && npm link
15
+ ```
16
+
17
+ ## Quick Start
18
+
19
+ ```ts
20
+ import { Operator } from "@operator-labs/sdk";
21
+
22
+ const op = new Operator({ apiKey: "ck_live_..." });
23
+
24
+ // Check auth
25
+ const status = await op.health();
26
+ console.log(status.planName, status.email);
27
+
28
+ // Send a message to the AI fleet manager
29
+ const stream = await op.chat.send("List my instances");
30
+ for await (const event of stream) {
31
+ if (event.type === "text-delta") process.stdout.write(event.text);
32
+ }
33
+ console.log();
34
+
35
+ // Or collect the full response
36
+ const { text } = await op.chat.sendAndWait("What's my current plan?");
37
+ console.log(text);
38
+ ```
39
+
40
+ ## Configuration
41
+
42
+ ```ts
43
+ const op = new Operator({
44
+ apiKey: "ck_live_...", // Required — Chat API key from the dashboard
45
+ baseUrl: "https://www.operator.io", // Optional — defaults to production
46
+ });
47
+ ```
48
+
49
+ For local development, set `baseUrl` to `http://localhost:3000`.
50
+
51
+ ## Getting an API Key
52
+
53
+ 1. Go to **Settings > API Keys** in the Operator dashboard
54
+ 2. Click **Create Key**
55
+ 3. Copy the key (starts with `ck_live_` or `ck_dev_`)
56
+
57
+ ## API Reference
58
+
59
+ ### Health
60
+
61
+ ```ts
62
+ const status = await op.health();
63
+ // { authenticated: true, userId: "...", planSlug: "pro", planName: "Pro", ... }
64
+ ```
65
+
66
+ ### Chat
67
+
68
+ ```ts
69
+ // List all chats
70
+ const chats = await op.chat.list();
71
+
72
+ // Get a chat with messages
73
+ const detail = await op.chat.get("chat-uuid");
74
+
75
+ // Send a streaming message
76
+ const stream = await op.chat.send("Create a new instance called my-agent");
77
+ for await (const event of stream) {
78
+ switch (event.type) {
79
+ case "text-delta":
80
+ process.stdout.write(event.text);
81
+ break;
82
+ case "tool-call":
83
+ console.log(`Tool: ${event.toolName}`, event.args);
84
+ break;
85
+ case "tool-result":
86
+ console.log(`Result: ${event.toolName}`, event.result);
87
+ break;
88
+ }
89
+ }
90
+
91
+ // Send and wait for full response
92
+ const { chatId, text } = await op.chat.sendAndWait("Restart instance abc");
93
+
94
+ // Continue a conversation
95
+ const stream2 = await op.chat.send("Now check its logs", { chatId });
96
+
97
+ // Update title / delete
98
+ await op.chat.updateTitle("chat-uuid", "Deployment Chat");
99
+ await op.chat.delete("chat-uuid");
100
+ ```
101
+
102
+ ### Instances
103
+
104
+ ```ts
105
+ // List instances
106
+ const instances = await op.instances.list();
107
+
108
+ // Get instance details
109
+ const instance = await op.instances.get("instance-uuid");
110
+
111
+ // Create a new instance
112
+ const newInstance = await op.instances.create({ name: "my-agent" });
113
+
114
+ // Create from a checkpoint repo
115
+ const cloned = await op.instances.create({
116
+ name: "from-checkpoint",
117
+ checkpointRepo: "owner/repo",
118
+ });
119
+
120
+ // Update instance
121
+ await op.instances.update("instance-uuid", { name: "renamed-agent" });
122
+
123
+ // Restart (syncs config + secrets first)
124
+ await op.instances.restart("instance-uuid");
125
+
126
+ // Get logs
127
+ const logs = await op.instances.logs("instance-uuid");
128
+
129
+ // Config management
130
+ const config = await op.instances.getConfig("instance-uuid");
131
+ await op.instances.updateConfig("instance-uuid", { ...config, name: "updated" });
132
+
133
+ // Delete
134
+ await op.instances.delete("instance-uuid");
135
+ ```
136
+
137
+ ### Automations
138
+
139
+ ```ts
140
+ // List automations
141
+ const automations = await op.automations.list();
142
+
143
+ // Create a scheduled automation
144
+ const automation = await op.automations.create({
145
+ name: "Daily health check",
146
+ prompt: "Check all instances and report any issues",
147
+ cronExpression: "0 9 * * *",
148
+ timezone: "America/New_York",
149
+ });
150
+
151
+ // Update
152
+ await op.automations.update(automation.id, {
153
+ cronExpression: "0 */6 * * *",
154
+ enabled: false,
155
+ });
156
+
157
+ // Delete
158
+ await op.automations.delete(automation.id);
159
+ ```
160
+
161
+ ### Webhooks
162
+
163
+ ```ts
164
+ // List webhooks
165
+ const webhooks = await op.webhooks.list();
166
+
167
+ // Create a webhook
168
+ const webhook = await op.webhooks.create({
169
+ name: "GitHub PR Handler",
170
+ promptTemplate: "A new PR was opened: {{payload}}. Review and summarize it.",
171
+ });
172
+
173
+ // Update
174
+ await op.webhooks.update(webhook.id, { enabled: false });
175
+
176
+ // Delete
177
+ await op.webhooks.delete(webhook.id);
178
+ ```
179
+
180
+ ## Error Handling
181
+
182
+ All API errors throw `OperatorApiError` with `status` and `body`:
183
+
184
+ ```ts
185
+ import { Operator, OperatorApiError } from "@operator-labs/sdk";
186
+
187
+ try {
188
+ await op.instances.get("nonexistent");
189
+ } catch (err) {
190
+ if (err instanceof OperatorApiError) {
191
+ console.error(`HTTP ${err.status}: ${err.message}`);
192
+ }
193
+ }
194
+ ```
195
+
196
+ ## Stream Events
197
+
198
+ When using `op.chat.send()`, the returned `ChatStream` yields these event types:
199
+
200
+ | Type | Fields | Description |
201
+ |------|--------|-------------|
202
+ | `text-delta` | `text` | Incremental text from the AI |
203
+ | `tool-call` | `toolName`, `args` | AI is calling a tool |
204
+ | `tool-result` | `toolName`, `result` | Tool execution result |
205
+ | `step-finish` | | A processing step completed |
206
+ | `finish` | `messages` | Stream finished |
207
+ | `error` | `error` | Error occurred |
208
+
209
+ ## Requirements
210
+
211
+ - Node.js 18+ (uses native `fetch`)
212
+ - A valid Operator Chat API key
@@ -0,0 +1,18 @@
1
+ import { type OperatorOptions } from "./types.js";
2
+ export declare class HttpClient {
3
+ readonly baseUrl: string;
4
+ private readonly apiKey;
5
+ constructor(options: OperatorOptions);
6
+ private headers;
7
+ request<T = unknown>(method: string, path: string, body?: unknown, extraHeaders?: Record<string, string>): Promise<T>;
8
+ get<T = unknown>(path: string): Promise<T>;
9
+ post<T = unknown>(path: string, body?: unknown, extraHeaders?: Record<string, string>): Promise<T>;
10
+ put<T = unknown>(path: string, body?: unknown): Promise<T>;
11
+ patch<T = unknown>(path: string, body?: unknown): Promise<T>;
12
+ delete<T = unknown>(path: string): Promise<T>;
13
+ /**
14
+ * Make a streaming POST request. Returns the raw Response for SSE parsing.
15
+ */
16
+ streamPost(path: string, body: unknown): Promise<Response>;
17
+ }
18
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAIpE,qBAAa,UAAU;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;gBAEpB,OAAO,EAAE,eAAe;IAQpC,OAAO,CAAC,OAAO;IAQT,OAAO,CAAC,CAAC,GAAG,OAAO,EACvB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,OAAO,EACd,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACpC,OAAO,CAAC,CAAC,CAAC;IA+BP,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAI1C,IAAI,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAIlG,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;IAI1D,KAAK,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;IAI5D,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAInD;;OAEG;IACG,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;CA0BjE"}
package/dist/client.js ADDED
@@ -0,0 +1,90 @@
1
+ import { OperatorApiError } from "./types.js";
2
+ const DEFAULT_BASE_URL = "https://www.operator.io";
3
+ export class HttpClient {
4
+ baseUrl;
5
+ apiKey;
6
+ constructor(options) {
7
+ if (!options.apiKey) {
8
+ throw new Error("operator-sdk: apiKey is required");
9
+ }
10
+ this.apiKey = options.apiKey;
11
+ this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
12
+ }
13
+ headers(extra) {
14
+ return {
15
+ Authorization: `Bearer ${this.apiKey}`,
16
+ "Content-Type": "application/json",
17
+ ...extra,
18
+ };
19
+ }
20
+ async request(method, path, body, extraHeaders) {
21
+ const url = `${this.baseUrl}${path}`;
22
+ const init = {
23
+ method,
24
+ headers: this.headers(extraHeaders),
25
+ };
26
+ if (body !== undefined) {
27
+ init.body = JSON.stringify(body);
28
+ }
29
+ const res = await fetch(url, init);
30
+ if (!res.ok) {
31
+ let errorBody;
32
+ try {
33
+ errorBody = await res.json();
34
+ }
35
+ catch {
36
+ errorBody = await res.text().catch(() => null);
37
+ }
38
+ const message = typeof errorBody === "object" &&
39
+ errorBody !== null &&
40
+ "error" in errorBody
41
+ ? String(errorBody.error)
42
+ : `Request failed with status ${res.status}`;
43
+ throw new OperatorApiError(message, res.status, errorBody);
44
+ }
45
+ return res.json();
46
+ }
47
+ async get(path) {
48
+ return this.request("GET", path);
49
+ }
50
+ async post(path, body, extraHeaders) {
51
+ return this.request("POST", path, body, extraHeaders);
52
+ }
53
+ async put(path, body) {
54
+ return this.request("PUT", path, body);
55
+ }
56
+ async patch(path, body) {
57
+ return this.request("PATCH", path, body);
58
+ }
59
+ async delete(path) {
60
+ return this.request("DELETE", path);
61
+ }
62
+ /**
63
+ * Make a streaming POST request. Returns the raw Response for SSE parsing.
64
+ */
65
+ async streamPost(path, body) {
66
+ const url = `${this.baseUrl}${path}`;
67
+ const res = await fetch(url, {
68
+ method: "POST",
69
+ headers: this.headers(),
70
+ body: JSON.stringify(body),
71
+ });
72
+ if (!res.ok) {
73
+ let errorBody;
74
+ try {
75
+ errorBody = await res.json();
76
+ }
77
+ catch {
78
+ errorBody = await res.text().catch(() => null);
79
+ }
80
+ const message = typeof errorBody === "object" &&
81
+ errorBody !== null &&
82
+ "error" in errorBody
83
+ ? String(errorBody.error)
84
+ : `Request failed with status ${res.status}`;
85
+ throw new OperatorApiError(message, res.status, errorBody);
86
+ }
87
+ return res;
88
+ }
89
+ }
90
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAwB,MAAM,YAAY,CAAC;AAEpE,MAAM,gBAAgB,GAAG,yBAAyB,CAAC;AAEnD,MAAM,OAAO,UAAU;IACZ,OAAO,CAAS;IACR,MAAM,CAAS;IAEhC,YAAY,OAAwB;QAClC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;QACtD,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,gBAAgB,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAC3E,CAAC;IAEO,OAAO,CAAC,KAA8B;QAC5C,OAAO;YACL,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AAI,CAAC,CAAC;YACjD,CAAC;YACD,MAAM,OAAO,GACX,OAAO,SAAS,KAAK,QAAQ;gBAC7B,SAAS,KAAK,IAAI;gBAClB,OAAO,IAAI,SAAS;gBAClB,CAAC,CAAC,MAAM,CAAE,SAAgC,CAAC,KAAK,CAAC;gBACjD,CAAC,CAAC,8BAA8B,GAAG,CAAC,MAAM,EAAE,CAAC;YACjD,MAAM,IAAI,gBAAgB,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;QAC7D,CAAC;QAED,OAAO,GAAG,CAAC;IACb,CAAC;CACF"}
@@ -0,0 +1,32 @@
1
+ import { ChatResource } from "./resources/chat.js";
2
+ import { InstancesResource } from "./resources/instances.js";
3
+ import { AutomationsResource } from "./resources/automations.js";
4
+ import { WebhooksResource } from "./resources/webhooks.js";
5
+ import type { OperatorOptions, HealthResponse } from "./types.js";
6
+ export declare class Operator {
7
+ private readonly http;
8
+ /** Chat conversations — send messages, list history, manage threads */
9
+ readonly chat: ChatResource;
10
+ /** Agent instances — create, configure, restart, view logs */
11
+ readonly instances: InstancesResource;
12
+ /** Cron-scheduled automations */
13
+ readonly automations: AutomationsResource;
14
+ /** HTTP webhooks that trigger AI processing */
15
+ readonly webhooks: WebhooksResource;
16
+ private readonly healthResource;
17
+ constructor(options: OperatorOptions);
18
+ /**
19
+ * Check authentication status and plan info.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * const status = await op.health();
24
+ * console.log(status.authenticated, status.planName);
25
+ * ```
26
+ */
27
+ health(): Promise<HealthResponse>;
28
+ }
29
+ export type { OperatorOptions, HealthResponse, Chat, ChatMessage, ChatDetail, MessagePart, SendMessageOptions, SendMessageResponse, StreamEvent, Instance, CreateInstanceOptions, LogEntry, Automation, CreateAutomationOptions, UpdateAutomationOptions, Webhook, CreateWebhookOptions, UpdateWebhookOptions, } from "./types.js";
30
+ export { OperatorApiError } from "./types.js";
31
+ export { ChatStream } from "./stream.js";
32
+ //# source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HttpClient } from "./client.js";
2
+ import { HealthResource } from "./resources/health.js";
3
+ import { ChatResource } from "./resources/chat.js";
4
+ import { InstancesResource } from "./resources/instances.js";
5
+ import { AutomationsResource } from "./resources/automations.js";
6
+ import { WebhooksResource } from "./resources/webhooks.js";
7
+ export class Operator {
8
+ http;
9
+ /** Chat conversations — send messages, list history, manage threads */
10
+ chat;
11
+ /** Agent instances — create, configure, restart, view logs */
12
+ instances;
13
+ /** Cron-scheduled automations */
14
+ automations;
15
+ /** HTTP webhooks that trigger AI processing */
16
+ webhooks;
17
+ healthResource;
18
+ constructor(options) {
19
+ this.http = new HttpClient(options);
20
+ this.chat = new ChatResource(this.http);
21
+ this.instances = new InstancesResource(this.http);
22
+ this.automations = new AutomationsResource(this.http);
23
+ this.webhooks = new WebhooksResource(this.http);
24
+ this.healthResource = new HealthResource(this.http);
25
+ }
26
+ /**
27
+ * Check authentication status and plan info.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * const status = await op.health();
32
+ * console.log(status.authenticated, status.planName);
33
+ * ```
34
+ */
35
+ async health() {
36
+ return this.healthResource.check();
37
+ }
38
+ }
39
+ export { OperatorApiError } from "./types.js";
40
+ export { ChatStream } from "./stream.js";
41
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAG3D,MAAM,OAAO,QAAQ;IACF,IAAI,CAAa;IAElC,uEAAuE;IAC9D,IAAI,CAAe;IAE5B,8DAA8D;IACrD,SAAS,CAAoB;IAEtC,iCAAiC;IACxB,WAAW,CAAsB;IAE1C,+CAA+C;IACtC,QAAQ,CAAmB;IAEnB,cAAc,CAAiB;IAEhD,YAAY,OAAwB;QAClC,IAAI,CAAC,IAAI,GAAG,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC;QACpC,IAAI,CAAC,IAAI,GAAG,IAAI,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACxC,IAAI,CAAC,SAAS,GAAG,IAAI,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAClD,IAAI,CAAC,WAAW,GAAG,IAAI,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACtD,IAAI,CAAC,QAAQ,GAAG,IAAI,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAChD,IAAI,CAAC,cAAc,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,MAAM;QACV,OAAO,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;IACrC,CAAC;CACF;AAwBD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { HttpClient } from "../client.js";
2
+ import type { Automation, CreateAutomationOptions, UpdateAutomationOptions } from "../types.js";
3
+ export declare class AutomationsResource {
4
+ private readonly http;
5
+ constructor(http: HttpClient);
6
+ /**
7
+ * List all automations for the authenticated user.
8
+ */
9
+ list(): Promise<Automation[]>;
10
+ /**
11
+ * Get a single automation by ID.
12
+ */
13
+ get(automationId: string): Promise<Automation>;
14
+ /**
15
+ * Create a new automation with a cron schedule.
16
+ */
17
+ create(options: CreateAutomationOptions): Promise<Automation>;
18
+ /**
19
+ * Update an existing automation.
20
+ */
21
+ update(automationId: string, options: UpdateAutomationOptions): Promise<Automation>;
22
+ /**
23
+ * Delete an automation and its associated schedule.
24
+ */
25
+ delete(automationId: string): Promise<void>;
26
+ }
27
+ //# sourceMappingURL=automations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"automations.d.ts","sourceRoot":"","sources":["../../src/resources/automations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EACV,UAAU,EACV,uBAAuB,EACvB,uBAAuB,EACxB,MAAM,aAAa,CAAC;AAErB,qBAAa,mBAAmB;IAClB,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAE7C;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;IAOnC;;OAEG;IACG,GAAG,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAIpD;;OAEG;IACG,MAAM,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,UAAU,CAAC;IAanE;;OAEG;IACG,MAAM,CACV,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,UAAU,CAAC;IAQtB;;OAEG;IACG,MAAM,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGlD"}
@@ -0,0 +1,45 @@
1
+ export class AutomationsResource {
2
+ http;
3
+ constructor(http) {
4
+ this.http = http;
5
+ }
6
+ /**
7
+ * List all automations for the authenticated user.
8
+ */
9
+ async list() {
10
+ const data = await this.http.get("/api/automations");
11
+ return data.automations;
12
+ }
13
+ /**
14
+ * Get a single automation by ID.
15
+ */
16
+ async get(automationId) {
17
+ return this.http.get(`/api/automations/${automationId}`);
18
+ }
19
+ /**
20
+ * Create a new automation with a cron schedule.
21
+ */
22
+ async create(options) {
23
+ const data = await this.http.post("/api/automations", {
24
+ name: options.name,
25
+ prompt: options.prompt,
26
+ cronExpression: options.cronExpression,
27
+ timezone: options.timezone ?? "UTC",
28
+ });
29
+ return data.automation;
30
+ }
31
+ /**
32
+ * Update an existing automation.
33
+ */
34
+ async update(automationId, options) {
35
+ const data = await this.http.put(`/api/automations/${automationId}`, options);
36
+ return data.automation;
37
+ }
38
+ /**
39
+ * Delete an automation and its associated schedule.
40
+ */
41
+ async delete(automationId) {
42
+ await this.http.delete(`/api/automations/${automationId}`);
43
+ }
44
+ }
45
+ //# sourceMappingURL=automations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"automations.js","sourceRoot":"","sources":["../../src/resources/automations.ts"],"names":[],"mappings":"AAOA,MAAM,OAAO,mBAAmB;IACD;IAA7B,YAA6B,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;IAEjD;;OAEG;IACH,KAAK,CAAC,IAAI;QACR,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAC9B,kBAAkB,CACnB,CAAC;QACF,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,GAAG,CAAC,YAAoB;QAC5B,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAa,oBAAoB,YAAY,EAAE,CAAC,CAAC;IACvE,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM,CAAC,OAAgC;QAC3C,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAC/B,kBAAkB,EAClB;YACE,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,cAAc,EAAE,OAAO,CAAC,cAAc;YACtC,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,KAAK;SACpC,CACF,CAAC;QACF,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM,CACV,YAAoB,EACpB,OAAgC;QAEhC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAC9B,oBAAoB,YAAY,EAAE,EAClC,OAAO,CACR,CAAC;QACF,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM,CAAC,YAAoB;QAC/B,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,oBAAoB,YAAY,EAAE,CAAC,CAAC;IAC7D,CAAC;CACF"}
@@ -0,0 +1,58 @@
1
+ import type { HttpClient } from "../client.js";
2
+ import type { Chat, ChatDetail, SendMessageOptions, SendMessageResponse } from "../types.js";
3
+ import { ChatStream } from "../stream.js";
4
+ export declare class ChatResource {
5
+ private readonly http;
6
+ constructor(http: HttpClient);
7
+ /**
8
+ * List all chats for the authenticated user.
9
+ */
10
+ list(): Promise<Chat[]>;
11
+ /**
12
+ * Get a chat with its messages.
13
+ */
14
+ get(chatId: string): Promise<ChatDetail>;
15
+ /**
16
+ * Delete a chat.
17
+ */
18
+ delete(chatId: string): Promise<void>;
19
+ /**
20
+ * Update a chat's title.
21
+ */
22
+ updateTitle(chatId: string, title: string): Promise<void>;
23
+ /**
24
+ * Send a message and receive the complete AI response as JSON.
25
+ *
26
+ * Waits for the full response (including any tool calls) before returning.
27
+ * Use `stream()` if you need incremental token-by-token output.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * const { chatId, text } = await op.chat.send("List my instances");
32
+ * console.log(text);
33
+ * ```
34
+ *
35
+ * @example Continue a conversation
36
+ * ```ts
37
+ * const first = await op.chat.send("Create an instance called my-agent");
38
+ * const second = await op.chat.send("Now restart it", { chatId: first.chatId });
39
+ * ```
40
+ */
41
+ send(message: string, options?: SendMessageOptions): Promise<SendMessageResponse>;
42
+ /**
43
+ * Send a message and get a real-time streaming response.
44
+ *
45
+ * The returned ChatStream is an async iterable of StreamEvents.
46
+ * Use `stream.textStream()` for text deltas only, or `stream.toText()` to collect.
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * const stream = await op.chat.stream("List my instances");
51
+ * for await (const event of stream) {
52
+ * if (event.type === "text-delta") process.stdout.write(event.text);
53
+ * }
54
+ * ```
55
+ */
56
+ stream(message: string, options?: SendMessageOptions): Promise<ChatStream>;
57
+ }
58
+ //# sourceMappingURL=chat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/resources/chat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EACV,IAAI,EACJ,UAAU,EAEV,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAI1C,qBAAa,YAAY;IACX,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAE7C;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;IAK7B;;OAEG;IACG,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAI9C;;OAEG;IACG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI3C;;OAEG;IACG,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/D;;;;;;;;;;;;;;;;;OAiBG;IACG,IAAI,CACR,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,mBAAmB,CAAC;IAiB/B;;;;;;;;;;;;;OAaG;IACG,MAAM,CACV,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,UAAU,CAAC;CAiBvB"}
@@ -0,0 +1,90 @@
1
+ import { ChatStream } from "../stream.js";
2
+ const JSON_MODE_HEADER = { "x-response-format": "json" };
3
+ export class ChatResource {
4
+ http;
5
+ constructor(http) {
6
+ this.http = http;
7
+ }
8
+ /**
9
+ * List all chats for the authenticated user.
10
+ */
11
+ async list() {
12
+ const data = await this.http.get("/api/chat/history");
13
+ return data.chats;
14
+ }
15
+ /**
16
+ * Get a chat with its messages.
17
+ */
18
+ async get(chatId) {
19
+ return this.http.get(`/api/chat/${chatId}`);
20
+ }
21
+ /**
22
+ * Delete a chat.
23
+ */
24
+ async delete(chatId) {
25
+ await this.http.delete(`/api/chat/${chatId}`);
26
+ }
27
+ /**
28
+ * Update a chat's title.
29
+ */
30
+ async updateTitle(chatId, title) {
31
+ await this.http.patch(`/api/chat/${chatId}`, { title });
32
+ }
33
+ /**
34
+ * Send a message and receive the complete AI response as JSON.
35
+ *
36
+ * Waits for the full response (including any tool calls) before returning.
37
+ * Use `stream()` if you need incremental token-by-token output.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * const { chatId, text } = await op.chat.send("List my instances");
42
+ * console.log(text);
43
+ * ```
44
+ *
45
+ * @example Continue a conversation
46
+ * ```ts
47
+ * const first = await op.chat.send("Create an instance called my-agent");
48
+ * const second = await op.chat.send("Now restart it", { chatId: first.chatId });
49
+ * ```
50
+ */
51
+ async send(message, options) {
52
+ const chatId = options?.chatId ?? crypto.randomUUID();
53
+ const messages = [
54
+ {
55
+ role: "user",
56
+ parts: [{ type: "text", text: message }],
57
+ },
58
+ ];
59
+ return this.http.post("/api/chat", { id: chatId, messages }, JSON_MODE_HEADER);
60
+ }
61
+ /**
62
+ * Send a message and get a real-time streaming response.
63
+ *
64
+ * The returned ChatStream is an async iterable of StreamEvents.
65
+ * Use `stream.textStream()` for text deltas only, or `stream.toText()` to collect.
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * const stream = await op.chat.stream("List my instances");
70
+ * for await (const event of stream) {
71
+ * if (event.type === "text-delta") process.stdout.write(event.text);
72
+ * }
73
+ * ```
74
+ */
75
+ async stream(message, options) {
76
+ const chatId = options?.chatId ?? crypto.randomUUID();
77
+ const messages = [
78
+ {
79
+ role: "user",
80
+ parts: [{ type: "text", text: message }],
81
+ },
82
+ ];
83
+ const response = await this.http.streamPost("/api/chat", {
84
+ id: chatId,
85
+ messages,
86
+ });
87
+ return new ChatStream(response);
88
+ }
89
+ }
90
+ //# sourceMappingURL=chat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat.js","sourceRoot":"","sources":["../../src/resources/chat.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,MAAM,gBAAgB,GAAG,EAAE,mBAAmB,EAAE,MAAM,EAAW,CAAC;AAElE,MAAM,OAAO,YAAY;IACM;IAA7B,YAA6B,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;IAEjD;;OAEG;IACH,KAAK,CAAC,IAAI;QACR,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAoB,mBAAmB,CAAC,CAAC;QACzE,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,GAAG,CAAC,MAAc;QACtB,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAa,aAAa,MAAM,EAAE,CAAC,CAAC;IAC1D,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM,CAAC,MAAc;QACzB,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,MAAM,EAAE,CAAC,CAAC;IAChD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,WAAW,CAAC,MAAc,EAAE,KAAa;QAC7C,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IAC1D,CAAC;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,KAAK,CAAC,IAAI,CACR,OAAe,EACf,OAA4B;QAE5B,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;QAEtD,MAAM,QAAQ,GAAG;YACf;gBACE,IAAI,EAAE,MAAe;gBACrB,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,CAAyB;aACjE;SACF,CAAC;QAEF,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CACnB,WAAW,EACX,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,EACxB,gBAAgB,CACjB,CAAC;IACJ,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,MAAM,CACV,OAAe,EACf,OAA4B;QAE5B,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;QAEtD,MAAM,QAAQ,GAAG;YACf;gBACE,IAAI,EAAE,MAAe;gBACrB,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,CAAyB;aACjE;SACF,CAAC;QAEF,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE;YACvD,EAAE,EAAE,MAAM;YACV,QAAQ;SACT,CAAC,CAAC;QAEH,OAAO,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC;CACF"}
@@ -0,0 +1,11 @@
1
+ import type { HttpClient } from "../client.js";
2
+ import type { HealthResponse } from "../types.js";
3
+ export declare class HealthResource {
4
+ private readonly http;
5
+ constructor(http: HttpClient);
6
+ /**
7
+ * Check authentication status and plan info.
8
+ */
9
+ check(): Promise<HealthResponse>;
10
+ }
11
+ //# sourceMappingURL=health.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../src/resources/health.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,qBAAa,cAAc;IACb,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAE7C;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,cAAc,CAAC;CAGvC"}