claude-triggers 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 +174 -0
- package/SKILL.md +175 -0
- package/dist/cli.d.ts +6 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +410 -0
- package/dist/cli.js.map +1 -0
- package/dist/client.d.ts +113 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +463 -0
- package/dist/client.js.map +1 -0
- package/dist/credentials.d.ts +39 -0
- package/dist/credentials.d.ts.map +1 -0
- package/dist/credentials.js +279 -0
- package/dist/credentials.js.map +1 -0
- package/dist/cron.d.ts +39 -0
- package/dist/cron.d.ts.map +1 -0
- package/dist/cron.js +257 -0
- package/dist/cron.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +184 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +22 -0
- package/dist/types.js.map +1 -0
- package/package.json +58 -0
package/dist/client.js
ADDED
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Triggers API client.
|
|
3
|
+
*
|
|
4
|
+
* Full implementation of the trigger, environment, session, and files APIs
|
|
5
|
+
* reverse-engineered from Claude Code v2.1.81.
|
|
6
|
+
*
|
|
7
|
+
* Includes features the CLI doesn't expose:
|
|
8
|
+
* - Direct session creation (POST /v1/sessions)
|
|
9
|
+
* - Session event streaming via SSE
|
|
10
|
+
* - File upload for seed bundles
|
|
11
|
+
* - GitHub token sync check
|
|
12
|
+
* - Session outcomes/branches extraction
|
|
13
|
+
*/
|
|
14
|
+
import { getCredentials, getCredentialsSync, clearCredentialCache } from "./credentials.js";
|
|
15
|
+
import { TriggerApiError, AuthError, } from "./types.js";
|
|
16
|
+
import { validateCron } from "./cron.js";
|
|
17
|
+
// ─── Constants (from Claude Code v2.1.81) ───
|
|
18
|
+
const DEFAULT_BASE_URL = "https://api.anthropic.com";
|
|
19
|
+
const ANTHROPIC_VERSION = "2023-06-01";
|
|
20
|
+
const TRIGGERS_BETA = "ccr-triggers-2026-01-30";
|
|
21
|
+
const CCR_BETA = "ccr-byoc-2025-07-29";
|
|
22
|
+
const FILES_BETA = "files-api-2025-04-14";
|
|
23
|
+
const DEFAULT_TIMEOUT = 20_000;
|
|
24
|
+
const DEFAULT_MAX_RETRIES = 3;
|
|
25
|
+
const DEFAULT_TOOLS = ["Bash", "Read", "Write", "Edit", "Glob", "Grep"];
|
|
26
|
+
const DEFAULT_MODEL = "claude-sonnet-4-6";
|
|
27
|
+
// ─── Client ───
|
|
28
|
+
export class ClaudeTriggersClient {
|
|
29
|
+
accessToken;
|
|
30
|
+
refreshToken = null;
|
|
31
|
+
orgUUID;
|
|
32
|
+
baseUrl;
|
|
33
|
+
timeout;
|
|
34
|
+
maxRetries;
|
|
35
|
+
constructor(options = {}) {
|
|
36
|
+
this.baseUrl = options.baseUrl ?? DEFAULT_BASE_URL;
|
|
37
|
+
this.timeout = options.timeout ?? DEFAULT_TIMEOUT;
|
|
38
|
+
this.maxRetries = options.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
39
|
+
this.orgUUID = options.orgUUID ?? null;
|
|
40
|
+
if (options.accessToken) {
|
|
41
|
+
this.accessToken = options.accessToken;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
const creds = getCredentialsSync();
|
|
45
|
+
if (!creds) {
|
|
46
|
+
throw new AuthError("No Claude Code credentials found. Run `claude` to authenticate first.");
|
|
47
|
+
}
|
|
48
|
+
this.accessToken = creds.accessToken;
|
|
49
|
+
this.refreshToken = creds.refreshToken;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Async initialization — refreshes token if needed, fetches org UUID.
|
|
54
|
+
* Call this before making API requests.
|
|
55
|
+
*/
|
|
56
|
+
async init() {
|
|
57
|
+
const creds = await getCredentials();
|
|
58
|
+
if (creds) {
|
|
59
|
+
this.accessToken = creds.accessToken;
|
|
60
|
+
this.refreshToken = creds.refreshToken;
|
|
61
|
+
}
|
|
62
|
+
await this.ensureOrgUUID();
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Create a pre-initialized client. Preferred over constructor + init().
|
|
67
|
+
*/
|
|
68
|
+
static async create(options = {}) {
|
|
69
|
+
const client = new ClaudeTriggersClient(options);
|
|
70
|
+
await client.init();
|
|
71
|
+
return client;
|
|
72
|
+
}
|
|
73
|
+
// ─── HTTP layer ───
|
|
74
|
+
headers(beta) {
|
|
75
|
+
const h = {
|
|
76
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
77
|
+
"Content-Type": "application/json",
|
|
78
|
+
"anthropic-version": ANTHROPIC_VERSION,
|
|
79
|
+
"anthropic-beta": beta,
|
|
80
|
+
};
|
|
81
|
+
if (this.orgUUID) {
|
|
82
|
+
h["x-organization-uuid"] = this.orgUUID;
|
|
83
|
+
}
|
|
84
|
+
return h;
|
|
85
|
+
}
|
|
86
|
+
async request(method, path, beta, body) {
|
|
87
|
+
const url = `${this.baseUrl}${path}`;
|
|
88
|
+
for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
|
|
89
|
+
const controller = new AbortController();
|
|
90
|
+
const timer = setTimeout(() => controller.abort(), this.timeout);
|
|
91
|
+
try {
|
|
92
|
+
const resp = await fetch(url, {
|
|
93
|
+
method,
|
|
94
|
+
headers: this.headers(beta),
|
|
95
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
96
|
+
signal: controller.signal,
|
|
97
|
+
});
|
|
98
|
+
// 401 — try token refresh once
|
|
99
|
+
if (resp.status === 401 && attempt === 0) {
|
|
100
|
+
clearCredentialCache();
|
|
101
|
+
const creds = await getCredentials(true);
|
|
102
|
+
if (creds) {
|
|
103
|
+
this.accessToken = creds.accessToken;
|
|
104
|
+
this.refreshToken = creds.refreshToken;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// 429/529 — retry with backoff
|
|
109
|
+
if ((resp.status === 429 || resp.status === 529) && attempt < this.maxRetries) {
|
|
110
|
+
const retryAfter = resp.headers.get("retry-after");
|
|
111
|
+
const delay = retryAfter
|
|
112
|
+
? parseInt(retryAfter, 10) * 1000
|
|
113
|
+
: (attempt + 1) * 2000;
|
|
114
|
+
await new Promise((r) => setTimeout(r, delay));
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
let data;
|
|
118
|
+
const contentType = resp.headers.get("content-type") ?? "";
|
|
119
|
+
if (contentType.includes("application/json")) {
|
|
120
|
+
data = (await resp.json());
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
data = (await resp.text());
|
|
124
|
+
}
|
|
125
|
+
if (!resp.ok) {
|
|
126
|
+
throw new TriggerApiError(`${method} ${path} failed: ${resp.status} ${resp.statusText}`, resp.status, data);
|
|
127
|
+
}
|
|
128
|
+
return { status: resp.status, data };
|
|
129
|
+
}
|
|
130
|
+
catch (e) {
|
|
131
|
+
if (e instanceof TriggerApiError)
|
|
132
|
+
throw e;
|
|
133
|
+
if (e instanceof Error && e.name === "AbortError") {
|
|
134
|
+
throw new TriggerApiError(`Request timeout after ${this.timeout}ms`, 0);
|
|
135
|
+
}
|
|
136
|
+
throw e;
|
|
137
|
+
}
|
|
138
|
+
finally {
|
|
139
|
+
clearTimeout(timer);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
throw new TriggerApiError("Max retries exceeded", 0);
|
|
143
|
+
}
|
|
144
|
+
// ─── Profile / Org UUID ───
|
|
145
|
+
async fetchProfile() {
|
|
146
|
+
const resp = await fetch(`${this.baseUrl}/api/oauth/profile`, {
|
|
147
|
+
headers: {
|
|
148
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
149
|
+
"Content-Type": "application/json",
|
|
150
|
+
},
|
|
151
|
+
signal: AbortSignal.timeout(10_000),
|
|
152
|
+
});
|
|
153
|
+
if (!resp.ok) {
|
|
154
|
+
throw new TriggerApiError(`Profile fetch failed: ${resp.status}`, resp.status, await resp.json().catch(() => null));
|
|
155
|
+
}
|
|
156
|
+
const profile = (await resp.json());
|
|
157
|
+
this.orgUUID = profile.organization.uuid;
|
|
158
|
+
return profile;
|
|
159
|
+
}
|
|
160
|
+
async ensureOrgUUID() {
|
|
161
|
+
if (this.orgUUID)
|
|
162
|
+
return this.orgUUID;
|
|
163
|
+
const profile = await this.fetchProfile();
|
|
164
|
+
return profile.organization.uuid;
|
|
165
|
+
}
|
|
166
|
+
getOrgUUID() {
|
|
167
|
+
return this.orgUUID;
|
|
168
|
+
}
|
|
169
|
+
// ─── Environments ───
|
|
170
|
+
async listEnvironments() {
|
|
171
|
+
await this.ensureOrgUUID();
|
|
172
|
+
const resp = await this.request("GET", "/v1/environment_providers", CCR_BETA);
|
|
173
|
+
return resp.data.environments;
|
|
174
|
+
}
|
|
175
|
+
async createEnvironment(name = "claude-code-default", config) {
|
|
176
|
+
await this.ensureOrgUUID();
|
|
177
|
+
const resp = await this.request("POST", "/v1/environment_providers/cloud/create", CCR_BETA, {
|
|
178
|
+
name,
|
|
179
|
+
kind: "anthropic_cloud",
|
|
180
|
+
description: "",
|
|
181
|
+
config: {
|
|
182
|
+
environment_type: "anthropic",
|
|
183
|
+
cwd: "/home/user",
|
|
184
|
+
init_script: null,
|
|
185
|
+
environment: {},
|
|
186
|
+
languages: [
|
|
187
|
+
{ name: "python", version: "3.11" },
|
|
188
|
+
{ name: "node", version: "20" },
|
|
189
|
+
],
|
|
190
|
+
network_config: {
|
|
191
|
+
allowed_hosts: [],
|
|
192
|
+
allow_default_hosts: true,
|
|
193
|
+
},
|
|
194
|
+
...config,
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
return resp.data;
|
|
198
|
+
}
|
|
199
|
+
async ensureEnvironment() {
|
|
200
|
+
const envs = await this.listEnvironments();
|
|
201
|
+
if (envs.length > 0)
|
|
202
|
+
return envs[0];
|
|
203
|
+
return this.createEnvironment();
|
|
204
|
+
}
|
|
205
|
+
// ─── Triggers ───
|
|
206
|
+
async listTriggers() {
|
|
207
|
+
await this.ensureOrgUUID();
|
|
208
|
+
const resp = await this.request("GET", "/v1/code/triggers", TRIGGERS_BETA);
|
|
209
|
+
return resp.data;
|
|
210
|
+
}
|
|
211
|
+
async getTrigger(triggerId) {
|
|
212
|
+
await this.ensureOrgUUID();
|
|
213
|
+
const resp = await this.request("GET", `/v1/code/triggers/${triggerId}`, TRIGGERS_BETA);
|
|
214
|
+
return resp.data.trigger;
|
|
215
|
+
}
|
|
216
|
+
async createTrigger(body) {
|
|
217
|
+
// Validate cron before sending
|
|
218
|
+
const cronError = validateCron(body.cron_expression);
|
|
219
|
+
if (cronError)
|
|
220
|
+
throw new Error(cronError);
|
|
221
|
+
await this.ensureOrgUUID();
|
|
222
|
+
const resp = await this.request("POST", "/v1/code/triggers", TRIGGERS_BETA, body);
|
|
223
|
+
return resp.data.trigger;
|
|
224
|
+
}
|
|
225
|
+
async updateTrigger(triggerId, body) {
|
|
226
|
+
if (body.cron_expression) {
|
|
227
|
+
const cronError = validateCron(body.cron_expression);
|
|
228
|
+
if (cronError)
|
|
229
|
+
throw new Error(cronError);
|
|
230
|
+
}
|
|
231
|
+
await this.ensureOrgUUID();
|
|
232
|
+
const resp = await this.request("POST", `/v1/code/triggers/${triggerId}`, TRIGGERS_BETA, body);
|
|
233
|
+
return resp.data.trigger;
|
|
234
|
+
}
|
|
235
|
+
async runTrigger(triggerId) {
|
|
236
|
+
await this.ensureOrgUUID();
|
|
237
|
+
const resp = await this.request("POST", `/v1/code/triggers/${triggerId}/run`, TRIGGERS_BETA, {});
|
|
238
|
+
return resp.data;
|
|
239
|
+
}
|
|
240
|
+
async enableTrigger(triggerId) {
|
|
241
|
+
return this.updateTrigger(triggerId, { enabled: true });
|
|
242
|
+
}
|
|
243
|
+
async disableTrigger(triggerId) {
|
|
244
|
+
return this.updateTrigger(triggerId, { enabled: false });
|
|
245
|
+
}
|
|
246
|
+
// ─── Sessions (beyond what /schedule exposes) ───
|
|
247
|
+
async listSessions() {
|
|
248
|
+
await this.ensureOrgUUID();
|
|
249
|
+
const resp = await this.request("GET", "/v1/sessions", CCR_BETA);
|
|
250
|
+
return resp.data;
|
|
251
|
+
}
|
|
252
|
+
async getSession(sessionId) {
|
|
253
|
+
await this.ensureOrgUUID();
|
|
254
|
+
const resp = await this.request("GET", `/v1/sessions/${sessionId}`, CCR_BETA);
|
|
255
|
+
return resp.data;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Create a remote CCR session directly.
|
|
259
|
+
* This is what triggers spawn under the hood — exposed here
|
|
260
|
+
* for direct session creation without a trigger/cron schedule.
|
|
261
|
+
*
|
|
262
|
+
* Note: Claude Code creates sessions with events:[] (empty),
|
|
263
|
+
* then sends the initial prompt via sendSessionEvent() after
|
|
264
|
+
* the session is provisioned. This method follows the same pattern.
|
|
265
|
+
*/
|
|
266
|
+
async createSession(opts) {
|
|
267
|
+
await this.ensureOrgUUID();
|
|
268
|
+
const sources = [];
|
|
269
|
+
if (opts.repoUrl) {
|
|
270
|
+
sources.push({
|
|
271
|
+
type: "git_repository",
|
|
272
|
+
url: opts.repoUrl,
|
|
273
|
+
...(opts.revision ? { revision: opts.revision } : {}),
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
// Session create always sends events:[] — prompt goes via sendSessionEvent
|
|
277
|
+
const body = {
|
|
278
|
+
title: opts.title ?? "Remote session",
|
|
279
|
+
events: [],
|
|
280
|
+
session_context: {
|
|
281
|
+
sources,
|
|
282
|
+
...(opts.seedBundleFileId
|
|
283
|
+
? { seed_bundle_file_id: opts.seedBundleFileId }
|
|
284
|
+
: {}),
|
|
285
|
+
outcomes: [],
|
|
286
|
+
environment_variables: {
|
|
287
|
+
CLAUDE_CODE_OAUTH_TOKEN: this.accessToken,
|
|
288
|
+
...opts.environmentVariables,
|
|
289
|
+
},
|
|
290
|
+
},
|
|
291
|
+
environment_id: opts.environmentId,
|
|
292
|
+
};
|
|
293
|
+
const resp = await this.request("POST", "/v1/sessions", CCR_BETA, body);
|
|
294
|
+
const sessionId = resp.data.id;
|
|
295
|
+
const title = resp.data.title ?? opts.title ?? "Remote session";
|
|
296
|
+
// Send initial prompt if provided
|
|
297
|
+
if (opts.prompt) {
|
|
298
|
+
await this.sendSessionEvent(sessionId, opts.prompt);
|
|
299
|
+
}
|
|
300
|
+
return { id: sessionId, title };
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Fetch events from a session. Supports pagination via afterId.
|
|
304
|
+
* Returns the conversation history: user messages, assistant responses, tool calls.
|
|
305
|
+
*/
|
|
306
|
+
async getSessionEvents(sessionId, afterId) {
|
|
307
|
+
await this.ensureOrgUUID();
|
|
308
|
+
const allEvents = [];
|
|
309
|
+
let cursor = afterId;
|
|
310
|
+
const MAX_PAGES = 50;
|
|
311
|
+
for (let i = 0; i < MAX_PAGES; i++) {
|
|
312
|
+
const url = cursor
|
|
313
|
+
? `/v1/sessions/${sessionId}/events?after_id=${cursor}`
|
|
314
|
+
: `/v1/sessions/${sessionId}/events`;
|
|
315
|
+
const resp = await this.request("GET", url, CCR_BETA);
|
|
316
|
+
const events = resp.data.data ?? [];
|
|
317
|
+
if (events.length === 0)
|
|
318
|
+
break;
|
|
319
|
+
allEvents.push(...events);
|
|
320
|
+
if (!resp.data.has_more)
|
|
321
|
+
break;
|
|
322
|
+
cursor = resp.data.last_event_id ?? events[events.length - 1].id;
|
|
323
|
+
}
|
|
324
|
+
return allEvents;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Send a user message to a running session.
|
|
328
|
+
*/
|
|
329
|
+
async sendSessionEvent(sessionId, content, uuid) {
|
|
330
|
+
await this.ensureOrgUUID();
|
|
331
|
+
return this.request("POST", `/v1/sessions/${sessionId}/events`, CCR_BETA, {
|
|
332
|
+
events: [
|
|
333
|
+
{
|
|
334
|
+
uuid: uuid ?? crypto.randomUUID(),
|
|
335
|
+
session_id: sessionId,
|
|
336
|
+
type: "user",
|
|
337
|
+
parent_tool_use_id: null,
|
|
338
|
+
message: { role: "user", content },
|
|
339
|
+
},
|
|
340
|
+
],
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Get the branch name from session outcomes (after session completes).
|
|
345
|
+
*/
|
|
346
|
+
getSessionBranch(session) {
|
|
347
|
+
const outcomes = session.session_context;
|
|
348
|
+
return outcomes?.outcomes?.find((o) => o.type === "git_repository")?.git_info
|
|
349
|
+
?.branches[0];
|
|
350
|
+
}
|
|
351
|
+
// ─── Files API (for seed bundles) ───
|
|
352
|
+
async uploadFile(fileContent, filename, purpose = "user_data") {
|
|
353
|
+
await this.ensureOrgUUID();
|
|
354
|
+
const boundary = `----FormBoundary${crypto.randomUUID().replace(/-/g, "")}`;
|
|
355
|
+
const parts = [];
|
|
356
|
+
parts.push(Buffer.from(`--${boundary}\r\nContent-Disposition: form-data; name="file"; filename="${filename}"\r\nContent-Type: application/octet-stream\r\n\r\n`));
|
|
357
|
+
parts.push(Buffer.from(fileContent));
|
|
358
|
+
parts.push(Buffer.from(`\r\n--${boundary}\r\nContent-Disposition: form-data; name="purpose"\r\n\r\n${purpose}\r\n`));
|
|
359
|
+
parts.push(Buffer.from(`--${boundary}--\r\n`));
|
|
360
|
+
const body = Buffer.concat(parts);
|
|
361
|
+
const resp = await fetch(`${this.baseUrl}/v1/files`, {
|
|
362
|
+
method: "POST",
|
|
363
|
+
headers: {
|
|
364
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
365
|
+
"anthropic-version": ANTHROPIC_VERSION,
|
|
366
|
+
"anthropic-beta": FILES_BETA,
|
|
367
|
+
"Content-Type": `multipart/form-data; boundary=${boundary}`,
|
|
368
|
+
...(this.orgUUID ? { "x-organization-uuid": this.orgUUID } : {}),
|
|
369
|
+
},
|
|
370
|
+
body,
|
|
371
|
+
signal: AbortSignal.timeout(60_000),
|
|
372
|
+
});
|
|
373
|
+
if (!resp.ok) {
|
|
374
|
+
throw new TriggerApiError(`File upload failed: ${resp.status}`, resp.status, await resp.json().catch(() => null));
|
|
375
|
+
}
|
|
376
|
+
const data = (await resp.json());
|
|
377
|
+
return { id: data.id, filename: data.filename, size: data.size_bytes };
|
|
378
|
+
}
|
|
379
|
+
// ─── GitHub integration ───
|
|
380
|
+
/**
|
|
381
|
+
* Check if GitHub token is synced for remote sessions.
|
|
382
|
+
* Requires tengu_cobalt_lantern feature flag.
|
|
383
|
+
*/
|
|
384
|
+
async checkGitHubTokenSync() {
|
|
385
|
+
await this.ensureOrgUUID();
|
|
386
|
+
try {
|
|
387
|
+
const resp = await fetch(`${this.baseUrl}/api/oauth/organizations/${this.orgUUID}/sync/github/auth`, {
|
|
388
|
+
headers: {
|
|
389
|
+
...this.headers(CCR_BETA),
|
|
390
|
+
},
|
|
391
|
+
signal: AbortSignal.timeout(15_000),
|
|
392
|
+
});
|
|
393
|
+
if (resp.status !== 200)
|
|
394
|
+
return false;
|
|
395
|
+
const data = (await resp.json());
|
|
396
|
+
return data.is_authenticated === true;
|
|
397
|
+
}
|
|
398
|
+
catch {
|
|
399
|
+
return false;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Check if the Claude GitHub App is installed on a repo.
|
|
404
|
+
*/
|
|
405
|
+
async checkGitHubAppInstalled(owner, repo) {
|
|
406
|
+
await this.ensureOrgUUID();
|
|
407
|
+
try {
|
|
408
|
+
const resp = await fetch(`${this.baseUrl}/api/oauth/organizations/${this.orgUUID}/code/repos/${owner}/${repo}`, {
|
|
409
|
+
headers: {
|
|
410
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
411
|
+
"x-organization-uuid": this.orgUUID,
|
|
412
|
+
},
|
|
413
|
+
signal: AbortSignal.timeout(15_000),
|
|
414
|
+
});
|
|
415
|
+
if (resp.status !== 200)
|
|
416
|
+
return { installed: false };
|
|
417
|
+
const data = (await resp.json());
|
|
418
|
+
return {
|
|
419
|
+
installed: data.status?.app_installed === true,
|
|
420
|
+
status: JSON.stringify(data.status),
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
catch {
|
|
424
|
+
return { installed: false };
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
// ─── Helper: Build trigger body ───
|
|
429
|
+
export function buildTriggerBody(opts) {
|
|
430
|
+
return {
|
|
431
|
+
name: opts.name,
|
|
432
|
+
cron_expression: opts.cron,
|
|
433
|
+
enabled: opts.enabled ?? true,
|
|
434
|
+
job_config: {
|
|
435
|
+
ccr: {
|
|
436
|
+
environment_id: opts.environmentId,
|
|
437
|
+
session_context: {
|
|
438
|
+
model: opts.model ?? DEFAULT_MODEL,
|
|
439
|
+
sources: opts.repoUrl
|
|
440
|
+
? [{ git_repository: { url: opts.repoUrl } }]
|
|
441
|
+
: [],
|
|
442
|
+
allowed_tools: opts.tools ?? DEFAULT_TOOLS,
|
|
443
|
+
},
|
|
444
|
+
events: [
|
|
445
|
+
{
|
|
446
|
+
data: {
|
|
447
|
+
uuid: crypto.randomUUID(),
|
|
448
|
+
session_id: "",
|
|
449
|
+
type: "user",
|
|
450
|
+
parent_tool_use_id: null,
|
|
451
|
+
message: {
|
|
452
|
+
content: opts.prompt,
|
|
453
|
+
role: "user",
|
|
454
|
+
},
|
|
455
|
+
},
|
|
456
|
+
},
|
|
457
|
+
],
|
|
458
|
+
},
|
|
459
|
+
},
|
|
460
|
+
...(opts.mcpConnections?.length ? { mcp_connections: opts.mcpConnections } : {}),
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC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E,IAAI,CAAC,KAAK,IAAI,aAAa;oBAClC,OAAO,EAAE,IAAI,CAAC,OAAO;wBACnB,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;wBAC7C,CAAC,CAAC,EAAE;oBACN,aAAa,EAAE,IAAI,CAAC,KAAK,IAAI,aAAa;iBAC3C;gBACD,MAAM,EAAE;oBACN;wBACE,IAAI,EAAE;4BACJ,IAAI,EAAE,MAAM,CAAC,UAAU,EAAE;4BACzB,UAAU,EAAE,EAAE;4BACd,IAAI,EAAE,MAAM;4BACZ,kBAAkB,EAAE,IAAI;4BACxB,OAAO,EAAE;gCACP,OAAO,EAAE,IAAI,CAAC,MAAM;gCACpB,IAAI,EAAE,MAAM;6BACb;yBACF;qBACF;iBACF;aACF;SACF;QACD,GAAG,CAAC,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACjF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Code credential management.
|
|
3
|
+
*
|
|
4
|
+
* Reads OAuth tokens from:
|
|
5
|
+
* 1. macOS Keychain ("Claude Code-credentials")
|
|
6
|
+
* 2. ~/.claude/.credentials.json
|
|
7
|
+
*
|
|
8
|
+
* Refreshes tokens via:
|
|
9
|
+
* 1. Direct OAuth refresh_token grant (same as Claude Code)
|
|
10
|
+
* 2. Fallback: shell out to `claude` CLI
|
|
11
|
+
*
|
|
12
|
+
* Token storage after refresh writes back to the same credential store
|
|
13
|
+
* so other tools (Claude Code, opencode, etc.) pick up the new token.
|
|
14
|
+
*/
|
|
15
|
+
import type { ClaudeCredentials } from "./types.js";
|
|
16
|
+
/**
|
|
17
|
+
* Clear the in-memory credential cache. Call after external token refresh.
|
|
18
|
+
*/
|
|
19
|
+
export declare function clearCredentialCache(): void;
|
|
20
|
+
/**
|
|
21
|
+
* Read credentials from the Claude Code credential store (keychain or file).
|
|
22
|
+
* Does NOT refresh — returns whatever is stored.
|
|
23
|
+
*/
|
|
24
|
+
export declare function readCredentials(): ClaudeCredentials | null;
|
|
25
|
+
/**
|
|
26
|
+
* Get valid credentials, refreshing if needed.
|
|
27
|
+
*
|
|
28
|
+
* 1. Check in-memory cache
|
|
29
|
+
* 2. Read from store
|
|
30
|
+
* 3. If expired/near-expiry: refresh via direct OAuth grant
|
|
31
|
+
* 4. Fallback: refresh via Claude CLI
|
|
32
|
+
* 5. Store refreshed tokens back
|
|
33
|
+
*/
|
|
34
|
+
export declare function getCredentials(forceRefresh?: boolean): Promise<ClaudeCredentials | null>;
|
|
35
|
+
/**
|
|
36
|
+
* Get credentials synchronously (no refresh). For quick checks.
|
|
37
|
+
*/
|
|
38
|
+
export declare function getCredentialsSync(): ClaudeCredentials | null;
|
|
39
|
+
//# sourceMappingURL=credentials.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAMH,OAAO,KAAK,EAAE,iBAAiB,EAAsB,MAAM,YAAY,CAAC;AAyBxE;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAG3C;AAuLD;;;GAGG;AACH,wBAAgB,eAAe,IAAI,iBAAiB,GAAG,IAAI,CAE1D;AAED;;;;;;;;GAQG;AACH,wBAAsB,cAAc,CAAC,YAAY,UAAQ,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAiD5F;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,iBAAiB,GAAG,IAAI,CAW7D"}
|