@remixhq/core 0.1.10 → 0.1.11
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/dist/api.d.ts +29 -0
- package/dist/api.js +1 -1
- package/dist/binding.d.ts +9 -4
- package/dist/binding.js +3 -1
- package/dist/chunk-4L3ZBZUQ.js +281 -0
- package/dist/chunk-BNKPTE2U.js +401 -0
- package/dist/chunk-C5NBNU32.js +240 -0
- package/dist/chunk-DXCL6I4Q.js +399 -0
- package/dist/chunk-HZNEDSRS.js +0 -0
- package/dist/chunk-K54U353Z.js +691 -0
- package/dist/chunk-RM2BGDBB.js +400 -0
- package/dist/chunk-ZXP6ENQY.js +244 -0
- package/dist/collab.d.ts +44 -6
- package/dist/collab.js +740 -129
- package/dist/index.js +1 -1
- package/dist/repo.js +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RemixError
|
|
3
|
+
} from "./chunk-YZ34ICNN.js";
|
|
4
|
+
|
|
5
|
+
// src/api/client.ts
|
|
6
|
+
async function readJsonSafe(res) {
|
|
7
|
+
const ct = res.headers.get("content-type") ?? "";
|
|
8
|
+
if (!ct.toLowerCase().includes("application/json")) return null;
|
|
9
|
+
try {
|
|
10
|
+
return await res.json();
|
|
11
|
+
} catch {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function createApiClient(config, opts) {
|
|
16
|
+
const apiKey = (opts?.apiKey ?? "").trim();
|
|
17
|
+
const tokenProvider = opts?.tokenProvider;
|
|
18
|
+
const CLIENT_KEY_HEADER = "x-comerge-api-key";
|
|
19
|
+
async function request(path, init) {
|
|
20
|
+
if (!tokenProvider) {
|
|
21
|
+
throw new RemixError("API client is missing a token provider.", {
|
|
22
|
+
exitCode: 1,
|
|
23
|
+
hint: "Configure auth before creating the Remix API client."
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
const auth = await tokenProvider();
|
|
27
|
+
const url = new URL(path, config.apiUrl).toString();
|
|
28
|
+
const doFetch = async (bearer) => fetch(url, {
|
|
29
|
+
...init,
|
|
30
|
+
headers: {
|
|
31
|
+
Accept: "application/json",
|
|
32
|
+
"Content-Type": "application/json",
|
|
33
|
+
...init?.headers ?? {},
|
|
34
|
+
Authorization: `Bearer ${bearer}`,
|
|
35
|
+
...apiKey ? { [CLIENT_KEY_HEADER]: apiKey } : {}
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
let res = await doFetch(auth.token);
|
|
39
|
+
if (res.status === 401 && !auth.fromEnv && auth.session?.refresh_token) {
|
|
40
|
+
const refreshed = await tokenProvider({ forceRefresh: true });
|
|
41
|
+
res = await doFetch(refreshed.token);
|
|
42
|
+
}
|
|
43
|
+
if (!res.ok) {
|
|
44
|
+
const body = await readJsonSafe(res);
|
|
45
|
+
const msg = (body && typeof body === "object" && body && "message" in body && typeof body.message === "string" ? body.message : null) ?? `Request failed (status ${res.status})`;
|
|
46
|
+
throw new RemixError(msg, { exitCode: 1, hint: body ? JSON.stringify(body, null, 2) : null });
|
|
47
|
+
}
|
|
48
|
+
const json = await readJsonSafe(res);
|
|
49
|
+
return json ?? null;
|
|
50
|
+
}
|
|
51
|
+
async function requestBinary(path, init) {
|
|
52
|
+
if (!tokenProvider) {
|
|
53
|
+
throw new RemixError("API client is missing a token provider.", {
|
|
54
|
+
exitCode: 1,
|
|
55
|
+
hint: "Configure auth before creating the Remix API client."
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
const auth = await tokenProvider();
|
|
59
|
+
const url = new URL(path, config.apiUrl).toString();
|
|
60
|
+
const doFetch = async (bearer) => fetch(url, {
|
|
61
|
+
...init,
|
|
62
|
+
headers: {
|
|
63
|
+
Accept: "*/*",
|
|
64
|
+
...init?.headers ?? {},
|
|
65
|
+
Authorization: `Bearer ${bearer}`,
|
|
66
|
+
...apiKey ? { [CLIENT_KEY_HEADER]: apiKey } : {}
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
let res = await doFetch(auth.token);
|
|
70
|
+
if (res.status === 401 && !auth.fromEnv && auth.session?.refresh_token) {
|
|
71
|
+
const refreshed = await tokenProvider({ forceRefresh: true });
|
|
72
|
+
res = await doFetch(refreshed.token);
|
|
73
|
+
}
|
|
74
|
+
if (!res.ok) {
|
|
75
|
+
const body = await readJsonSafe(res);
|
|
76
|
+
const msg = (body && typeof body === "object" && body && "message" in body && typeof body.message === "string" ? body.message : null) ?? `Request failed (status ${res.status})`;
|
|
77
|
+
throw new RemixError(msg, { exitCode: 1, hint: body ? JSON.stringify(body, null, 2) : null });
|
|
78
|
+
}
|
|
79
|
+
const contentDisposition = res.headers.get("content-disposition") ?? "";
|
|
80
|
+
const fileNameMatch = contentDisposition.match(/filename=\"([^\"]+)\"/i);
|
|
81
|
+
return {
|
|
82
|
+
data: Buffer.from(await res.arrayBuffer()),
|
|
83
|
+
fileName: fileNameMatch?.[1] ?? null,
|
|
84
|
+
contentType: res.headers.get("content-type")
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
getMe: () => request("/v1/me", { method: "GET" }),
|
|
89
|
+
listOrganizations: () => request("/v1/organizations", { method: "GET" }),
|
|
90
|
+
getOrganization: (orgId) => request(`/v1/organizations/${encodeURIComponent(orgId)}`, { method: "GET" }),
|
|
91
|
+
listProjects: (params) => {
|
|
92
|
+
const qs = new URLSearchParams();
|
|
93
|
+
if (params?.organizationId) qs.set("organizationId", params.organizationId);
|
|
94
|
+
if (params?.clientAppId) qs.set("clientAppId", params.clientAppId);
|
|
95
|
+
const suffix = qs.toString() ? `?${qs.toString()}` : "";
|
|
96
|
+
return request(`/v1/projects${suffix}`, { method: "GET" });
|
|
97
|
+
},
|
|
98
|
+
getProject: (projectId) => request(`/v1/projects/${encodeURIComponent(projectId)}`, { method: "GET" }),
|
|
99
|
+
resolveProjectBinding: (params) => {
|
|
100
|
+
const qs = new URLSearchParams();
|
|
101
|
+
if (params.repoFingerprint) qs.set("repoFingerprint", params.repoFingerprint);
|
|
102
|
+
if (params.remoteUrl) qs.set("remoteUrl", params.remoteUrl);
|
|
103
|
+
if (params.branchName) qs.set("branchName", params.branchName);
|
|
104
|
+
return request(`/v1/projects/bindings/resolve?${qs.toString()}`, { method: "GET" });
|
|
105
|
+
},
|
|
106
|
+
resolveProjectLaneBinding: (params) => {
|
|
107
|
+
const qs = new URLSearchParams();
|
|
108
|
+
if (params.projectId) qs.set("projectId", params.projectId);
|
|
109
|
+
if (params.repoFingerprint) qs.set("repoFingerprint", params.repoFingerprint);
|
|
110
|
+
if (params.remoteUrl) qs.set("remoteUrl", params.remoteUrl);
|
|
111
|
+
if (params.defaultBranch) qs.set("defaultBranch", params.defaultBranch);
|
|
112
|
+
qs.set("branchName", params.branchName);
|
|
113
|
+
return request(`/v1/projects/bindings/resolve-lane?${qs.toString()}`, { method: "GET" });
|
|
114
|
+
},
|
|
115
|
+
ensureProjectLaneBinding: (payload) => request("/v1/projects/bindings/ensure-lane", { method: "POST", body: JSON.stringify(payload) }),
|
|
116
|
+
bootstrapFreshProjectLane: (payload) => request("/v1/projects/bindings/bootstrap-fresh-lane", { method: "POST", body: JSON.stringify(payload) }),
|
|
117
|
+
autoEnableDeveloper: () => request("/v1/developer/auto-enable", { method: "POST" }),
|
|
118
|
+
listClientApps: (params) => {
|
|
119
|
+
const qs = params?.orgId ? `?orgId=${encodeURIComponent(params.orgId)}` : "";
|
|
120
|
+
return request(`/v1/developer/client-apps${qs}`, { method: "GET" });
|
|
121
|
+
},
|
|
122
|
+
createClientApp: (payload) => request("/v1/developer/client-apps", { method: "POST", body: JSON.stringify(payload) }),
|
|
123
|
+
createClientAppKey: (clientAppId, payload) => request(`/v1/developer/client-apps/${encodeURIComponent(clientAppId)}/keys`, {
|
|
124
|
+
method: "POST",
|
|
125
|
+
body: JSON.stringify(payload ?? {})
|
|
126
|
+
}),
|
|
127
|
+
listApps: (params) => {
|
|
128
|
+
const qs = new URLSearchParams();
|
|
129
|
+
if (params?.projectId) qs.set("projectId", params.projectId);
|
|
130
|
+
if (params?.organizationId) qs.set("organizationId", params.organizationId);
|
|
131
|
+
if (params?.ownership) qs.set("ownership", params.ownership);
|
|
132
|
+
if (params?.accessScope) qs.set("accessScope", params.accessScope);
|
|
133
|
+
if (params?.createdBy) qs.set("createdBy", params.createdBy);
|
|
134
|
+
if (params?.forked) qs.set("forked", params.forked);
|
|
135
|
+
if (typeof params?.limit === "number") qs.set("limit", String(params.limit));
|
|
136
|
+
if (typeof params?.offset === "number") qs.set("offset", String(params.offset));
|
|
137
|
+
const suffix = qs.toString() ? `?${qs.toString()}` : "";
|
|
138
|
+
return request(`/v1/apps${suffix}`, { method: "GET" });
|
|
139
|
+
},
|
|
140
|
+
getApp: (appId) => request(`/v1/apps/${encodeURIComponent(appId)}`, { method: "GET" }),
|
|
141
|
+
getAppContext: (appId) => request(`/v1/apps/${encodeURIComponent(appId)}/context`, { method: "GET" }),
|
|
142
|
+
getAppOverview: (appId) => request(`/v1/apps/${encodeURIComponent(appId)}/overview`, { method: "GET" }),
|
|
143
|
+
listAppTimeline: (appId, params) => {
|
|
144
|
+
const qs = new URLSearchParams();
|
|
145
|
+
if (typeof params?.limit === "number") qs.set("limit", String(params.limit));
|
|
146
|
+
if (params?.cursor) qs.set("cursor", params.cursor);
|
|
147
|
+
const suffix = qs.toString() ? `?${qs.toString()}` : "";
|
|
148
|
+
return request(`/v1/apps/${encodeURIComponent(appId)}/timeline${suffix}`, { method: "GET" });
|
|
149
|
+
},
|
|
150
|
+
getAppTimelineEvent: (appId, eventId) => request(`/v1/apps/${encodeURIComponent(appId)}/timeline/${encodeURIComponent(eventId)}`, { method: "GET" }),
|
|
151
|
+
listAppEditQueue: (appId, params) => {
|
|
152
|
+
const qs = new URLSearchParams();
|
|
153
|
+
if (typeof params?.limit === "number") qs.set("limit", String(params.limit));
|
|
154
|
+
if (typeof params?.offset === "number") qs.set("offset", String(params.offset));
|
|
155
|
+
const suffix = qs.toString() ? `?${qs.toString()}` : "";
|
|
156
|
+
return request(`/v1/apps/${encodeURIComponent(appId)}/edit-queue${suffix}`, { method: "GET" });
|
|
157
|
+
},
|
|
158
|
+
getMergeRequest: (mrId) => request(`/v1/merge-requests/${encodeURIComponent(mrId)}`, { method: "GET" }),
|
|
159
|
+
presignImportUpload: (payload) => request("/v1/apps/import/upload/presign", { method: "POST", body: JSON.stringify(payload) }),
|
|
160
|
+
importFromUpload: (payload) => request("/v1/apps/import/upload", { method: "POST", body: JSON.stringify(payload) }),
|
|
161
|
+
presignImportUploadFirstParty: (payload) => request("/v1/apps/import/upload/presign/first-party", { method: "POST", body: JSON.stringify(payload) }),
|
|
162
|
+
importFromUploadFirstParty: (payload) => request("/v1/apps/import/upload/first-party", { method: "POST", body: JSON.stringify(payload) }),
|
|
163
|
+
importFromGithubFirstParty: (payload) => request("/v1/apps/import/github/first-party", { method: "POST", body: JSON.stringify(payload) }),
|
|
164
|
+
forkApp: (appId, payload) => request(`/v1/apps/${encodeURIComponent(appId)}/fork`, { method: "POST", body: JSON.stringify(payload ?? {}) }),
|
|
165
|
+
downloadAppBundle: (appId) => requestBinary(`/v1/apps/${encodeURIComponent(appId)}/download.bundle`, { method: "GET" }),
|
|
166
|
+
createChangeStep: (appId, payload) => request(`/v1/apps/${encodeURIComponent(appId)}/change-steps`, {
|
|
167
|
+
method: "POST",
|
|
168
|
+
body: JSON.stringify(payload)
|
|
169
|
+
}),
|
|
170
|
+
createCollabTurn: (appId, payload) => request(`/v1/apps/${encodeURIComponent(appId)}/collab-turns`, {
|
|
171
|
+
method: "POST",
|
|
172
|
+
body: JSON.stringify(payload)
|
|
173
|
+
}),
|
|
174
|
+
listCollabTurns: (appId, params) => {
|
|
175
|
+
const qs = new URLSearchParams();
|
|
176
|
+
if (params?.limit !== void 0) qs.set("limit", String(params.limit));
|
|
177
|
+
if (params?.offset !== void 0) qs.set("offset", String(params.offset));
|
|
178
|
+
if (params?.changeStepId) qs.set("changeStepId", params.changeStepId);
|
|
179
|
+
if (params?.threadId) qs.set("threadId", params.threadId);
|
|
180
|
+
if (params?.collabLaneId) qs.set("collabLaneId", params.collabLaneId);
|
|
181
|
+
if (params?.createdAfter) qs.set("createdAfter", params.createdAfter);
|
|
182
|
+
if (params?.createdBefore) qs.set("createdBefore", params.createdBefore);
|
|
183
|
+
const suffix = qs.toString() ? `?${qs.toString()}` : "";
|
|
184
|
+
return request(`/v1/apps/${encodeURIComponent(appId)}/collab-turns${suffix}`, { method: "GET" });
|
|
185
|
+
},
|
|
186
|
+
getCollabTurn: (appId, collabTurnId) => request(`/v1/apps/${encodeURIComponent(appId)}/collab-turns/${encodeURIComponent(collabTurnId)}`, {
|
|
187
|
+
method: "GET"
|
|
188
|
+
}),
|
|
189
|
+
getAgentMemorySummary: (appId) => request(`/v1/apps/${encodeURIComponent(appId)}/agent-memory/summary`, { method: "GET" }),
|
|
190
|
+
listAgentMemoryTimeline: (appId, params) => {
|
|
191
|
+
const qs = new URLSearchParams();
|
|
192
|
+
if (params?.limit !== void 0) qs.set("limit", String(params.limit));
|
|
193
|
+
if (params?.offset !== void 0) qs.set("offset", String(params.offset));
|
|
194
|
+
if (params?.createdAfter) qs.set("createdAfter", params.createdAfter);
|
|
195
|
+
if (params?.createdBefore) qs.set("createdBefore", params.createdBefore);
|
|
196
|
+
if (params?.kinds?.length) {
|
|
197
|
+
for (const kind of params.kinds) qs.append("kinds", kind);
|
|
198
|
+
}
|
|
199
|
+
const suffix = qs.toString() ? `?${qs.toString()}` : "";
|
|
200
|
+
return request(`/v1/apps/${encodeURIComponent(appId)}/agent-memory/timeline${suffix}`, { method: "GET" });
|
|
201
|
+
},
|
|
202
|
+
searchAgentMemory: (appId, params) => {
|
|
203
|
+
const qs = new URLSearchParams();
|
|
204
|
+
qs.set("q", params.q);
|
|
205
|
+
if (params.limit !== void 0) qs.set("limit", String(params.limit));
|
|
206
|
+
if (params.offset !== void 0) qs.set("offset", String(params.offset));
|
|
207
|
+
if (params.createdAfter) qs.set("createdAfter", params.createdAfter);
|
|
208
|
+
if (params.createdBefore) qs.set("createdBefore", params.createdBefore);
|
|
209
|
+
if (params.kinds?.length) {
|
|
210
|
+
for (const kind of params.kinds) qs.append("kinds", kind);
|
|
211
|
+
}
|
|
212
|
+
return request(`/v1/apps/${encodeURIComponent(appId)}/agent-memory/search?${qs.toString()}`, { method: "GET" });
|
|
213
|
+
},
|
|
214
|
+
getChangeStep: (appId, changeStepId) => request(`/v1/apps/${encodeURIComponent(appId)}/change-steps/${encodeURIComponent(changeStepId)}`, { method: "GET" }),
|
|
215
|
+
getChangeStepDiff: (appId, changeStepId) => request(`/v1/apps/${encodeURIComponent(appId)}/change-steps/${encodeURIComponent(changeStepId)}/diff`, {
|
|
216
|
+
method: "GET"
|
|
217
|
+
}),
|
|
218
|
+
startChangeStepReplay: (appId, payload) => request(`/v1/apps/${encodeURIComponent(appId)}/change-steps/replays`, {
|
|
219
|
+
method: "POST",
|
|
220
|
+
body: JSON.stringify(payload)
|
|
221
|
+
}),
|
|
222
|
+
getChangeStepReplay: (appId, replayId) => request(`/v1/apps/${encodeURIComponent(appId)}/change-steps/replays/${encodeURIComponent(replayId)}`, {
|
|
223
|
+
method: "GET"
|
|
224
|
+
}),
|
|
225
|
+
getChangeStepReplayDiff: (appId, replayId) => request(`/v1/apps/${encodeURIComponent(appId)}/change-steps/replays/${encodeURIComponent(replayId)}/diff`, {
|
|
226
|
+
method: "GET"
|
|
227
|
+
}),
|
|
228
|
+
listMergeRequests: (params) => {
|
|
229
|
+
const qs = new URLSearchParams();
|
|
230
|
+
if (params?.queue) qs.set("queue", params.queue);
|
|
231
|
+
if (params?.appId) qs.set("appId", params.appId);
|
|
232
|
+
if (params?.sourceAppId) qs.set("sourceAppId", params.sourceAppId);
|
|
233
|
+
if (params?.targetAppId) qs.set("targetAppId", params.targetAppId);
|
|
234
|
+
if (Array.isArray(params?.status)) {
|
|
235
|
+
for (const status of params.status) qs.append("status", status);
|
|
236
|
+
} else if (typeof params?.status === "string") {
|
|
237
|
+
qs.set("status", params.status);
|
|
238
|
+
}
|
|
239
|
+
if (params?.kind) qs.set("kind", params.kind);
|
|
240
|
+
if (typeof params?.limit === "number") qs.set("limit", String(params.limit));
|
|
241
|
+
if (typeof params?.offset === "number") qs.set("offset", String(params.offset));
|
|
242
|
+
const suffix = qs.toString() ? `?${qs.toString()}` : "";
|
|
243
|
+
return request(`/v1/merge-requests${suffix}`, { method: "GET" });
|
|
244
|
+
},
|
|
245
|
+
openMergeRequest: (sourceAppId) => request("/v1/merge-requests", { method: "POST", body: JSON.stringify({ sourceAppId }) }),
|
|
246
|
+
getMergeRequestReview: (mrId) => request(`/v1/merge-requests/${encodeURIComponent(mrId)}/review`, { method: "GET" }),
|
|
247
|
+
updateMergeRequest: (mrId, payload) => request(`/v1/merge-requests/${encodeURIComponent(mrId)}`, { method: "PATCH", body: JSON.stringify(payload) }),
|
|
248
|
+
createOrganizationInvite: (orgId, payload) => request(`/v1/organizations/${encodeURIComponent(orgId)}/invitations`, {
|
|
249
|
+
method: "POST",
|
|
250
|
+
body: JSON.stringify(payload)
|
|
251
|
+
}),
|
|
252
|
+
createProjectInvite: (projectId, payload) => request(`/v1/projects/${encodeURIComponent(projectId)}/invitations`, {
|
|
253
|
+
method: "POST",
|
|
254
|
+
body: JSON.stringify(payload)
|
|
255
|
+
}),
|
|
256
|
+
createAppInvite: (appId, payload) => request(`/v1/apps/${encodeURIComponent(appId)}/invitations`, {
|
|
257
|
+
method: "POST",
|
|
258
|
+
body: JSON.stringify(payload)
|
|
259
|
+
}),
|
|
260
|
+
listOrganizationMembers: (orgId, params) => {
|
|
261
|
+
const qs = new URLSearchParams();
|
|
262
|
+
if (typeof params?.limit === "number") qs.set("limit", String(params.limit));
|
|
263
|
+
if (typeof params?.offset === "number") qs.set("offset", String(params.offset));
|
|
264
|
+
const suffix = qs.toString() ? `?${qs.toString()}` : "";
|
|
265
|
+
return request(`/v1/organizations/${encodeURIComponent(orgId)}/members${suffix}`, { method: "GET" });
|
|
266
|
+
},
|
|
267
|
+
updateOrganizationMember: (orgId, userId, payload) => request(`/v1/organizations/${encodeURIComponent(orgId)}/members/${encodeURIComponent(userId)}`, {
|
|
268
|
+
method: "PATCH",
|
|
269
|
+
body: JSON.stringify(payload)
|
|
270
|
+
}),
|
|
271
|
+
listProjectMembers: (projectId, params) => {
|
|
272
|
+
const qs = new URLSearchParams();
|
|
273
|
+
if (typeof params?.limit === "number") qs.set("limit", String(params.limit));
|
|
274
|
+
if (typeof params?.offset === "number") qs.set("offset", String(params.offset));
|
|
275
|
+
const suffix = qs.toString() ? `?${qs.toString()}` : "";
|
|
276
|
+
return request(`/v1/projects/${encodeURIComponent(projectId)}/members${suffix}`, { method: "GET" });
|
|
277
|
+
},
|
|
278
|
+
updateProjectMember: (projectId, userId, payload) => request(`/v1/projects/${encodeURIComponent(projectId)}/members/${encodeURIComponent(userId)}`, {
|
|
279
|
+
method: "PATCH",
|
|
280
|
+
body: JSON.stringify(payload)
|
|
281
|
+
}),
|
|
282
|
+
listAppMembers: (appId, params) => {
|
|
283
|
+
const qs = new URLSearchParams();
|
|
284
|
+
if (typeof params?.limit === "number") qs.set("limit", String(params.limit));
|
|
285
|
+
if (typeof params?.offset === "number") qs.set("offset", String(params.offset));
|
|
286
|
+
const suffix = qs.toString() ? `?${qs.toString()}` : "";
|
|
287
|
+
return request(`/v1/apps/${encodeURIComponent(appId)}/members${suffix}`, { method: "GET" });
|
|
288
|
+
},
|
|
289
|
+
updateAppMember: (appId, userId, payload) => request(`/v1/apps/${encodeURIComponent(appId)}/members/${encodeURIComponent(userId)}`, {
|
|
290
|
+
method: "PATCH",
|
|
291
|
+
body: JSON.stringify(payload)
|
|
292
|
+
}),
|
|
293
|
+
listOrganizationInvites: (orgId, params) => {
|
|
294
|
+
const qs = new URLSearchParams();
|
|
295
|
+
if (typeof params?.limit === "number") qs.set("limit", String(params.limit));
|
|
296
|
+
if (typeof params?.offset === "number") qs.set("offset", String(params.offset));
|
|
297
|
+
const suffix = qs.toString() ? `?${qs.toString()}` : "";
|
|
298
|
+
return request(`/v1/organizations/${encodeURIComponent(orgId)}/invitations${suffix}`, { method: "GET" });
|
|
299
|
+
},
|
|
300
|
+
listProjectInvites: (projectId, params) => {
|
|
301
|
+
const qs = new URLSearchParams();
|
|
302
|
+
if (typeof params?.limit === "number") qs.set("limit", String(params.limit));
|
|
303
|
+
if (typeof params?.offset === "number") qs.set("offset", String(params.offset));
|
|
304
|
+
const suffix = qs.toString() ? `?${qs.toString()}` : "";
|
|
305
|
+
return request(`/v1/projects/${encodeURIComponent(projectId)}/invitations${suffix}`, { method: "GET" });
|
|
306
|
+
},
|
|
307
|
+
listAppInvites: (appId, params) => {
|
|
308
|
+
const qs = new URLSearchParams();
|
|
309
|
+
if (typeof params?.limit === "number") qs.set("limit", String(params.limit));
|
|
310
|
+
if (typeof params?.offset === "number") qs.set("offset", String(params.offset));
|
|
311
|
+
const suffix = qs.toString() ? `?${qs.toString()}` : "";
|
|
312
|
+
return request(`/v1/apps/${encodeURIComponent(appId)}/invitations${suffix}`, { method: "GET" });
|
|
313
|
+
},
|
|
314
|
+
resendOrganizationInvite: (orgId, inviteId, payload) => request(`/v1/organizations/${encodeURIComponent(orgId)}/invitations/${encodeURIComponent(inviteId)}/resend`, {
|
|
315
|
+
method: "POST",
|
|
316
|
+
body: JSON.stringify(payload ?? {})
|
|
317
|
+
}),
|
|
318
|
+
resendProjectInvite: (projectId, inviteId, payload) => request(`/v1/projects/${encodeURIComponent(projectId)}/invitations/${encodeURIComponent(inviteId)}/resend`, {
|
|
319
|
+
method: "POST",
|
|
320
|
+
body: JSON.stringify(payload ?? {})
|
|
321
|
+
}),
|
|
322
|
+
resendAppInvite: (appId, inviteId, payload) => request(`/v1/apps/${encodeURIComponent(appId)}/invitations/${encodeURIComponent(inviteId)}/resend`, {
|
|
323
|
+
method: "POST",
|
|
324
|
+
body: JSON.stringify(payload ?? {})
|
|
325
|
+
}),
|
|
326
|
+
revokeOrganizationInvite: (orgId, inviteId) => request(`/v1/organizations/${encodeURIComponent(orgId)}/invitations/${encodeURIComponent(inviteId)}`, {
|
|
327
|
+
method: "DELETE"
|
|
328
|
+
}),
|
|
329
|
+
revokeProjectInvite: (projectId, inviteId) => request(`/v1/projects/${encodeURIComponent(projectId)}/invitations/${encodeURIComponent(inviteId)}`, {
|
|
330
|
+
method: "DELETE"
|
|
331
|
+
}),
|
|
332
|
+
revokeAppInvite: (appId, inviteId) => request(`/v1/apps/${encodeURIComponent(appId)}/invitations/${encodeURIComponent(inviteId)}`, {
|
|
333
|
+
method: "DELETE"
|
|
334
|
+
}),
|
|
335
|
+
acceptInvitation: (payload) => request("/v1/invitations/accept", { method: "POST", body: JSON.stringify(payload) }),
|
|
336
|
+
syncUpstreamApp: (appId) => request(`/v1/apps/${encodeURIComponent(appId)}/sync-upstream`, {
|
|
337
|
+
method: "POST",
|
|
338
|
+
body: JSON.stringify({})
|
|
339
|
+
}),
|
|
340
|
+
preflightAppReconcile: (appId, payload) => request(`/v1/apps/${encodeURIComponent(appId)}/reconcile/preflight`, {
|
|
341
|
+
method: "POST",
|
|
342
|
+
body: JSON.stringify(payload)
|
|
343
|
+
}),
|
|
344
|
+
startAppReconcile: (appId, payload) => request(`/v1/apps/${encodeURIComponent(appId)}/reconcile/start`, {
|
|
345
|
+
method: "POST",
|
|
346
|
+
body: JSON.stringify(payload)
|
|
347
|
+
}),
|
|
348
|
+
getAppReconcile: (appId, reconcileId) => request(`/v1/apps/${encodeURIComponent(appId)}/reconcile/${encodeURIComponent(reconcileId)}`, { method: "GET" }),
|
|
349
|
+
downloadAppReconcileBundle: (appId, reconcileId) => requestBinary(`/v1/apps/${encodeURIComponent(appId)}/reconcile/${encodeURIComponent(reconcileId)}/download.bundle`, {
|
|
350
|
+
method: "GET"
|
|
351
|
+
}),
|
|
352
|
+
syncLocalApp: (appId, payload) => request(`/v1/apps/${encodeURIComponent(appId)}/sync-local`, {
|
|
353
|
+
method: "POST",
|
|
354
|
+
body: JSON.stringify(payload)
|
|
355
|
+
}),
|
|
356
|
+
initiateBundle: (appId, payload) => request(`/v1/apps/${encodeURIComponent(appId)}/bundles`, { method: "POST", body: JSON.stringify(payload) }),
|
|
357
|
+
getBundle: (appId, bundleId) => request(`/v1/apps/${encodeURIComponent(appId)}/bundles/${encodeURIComponent(bundleId)}`, { method: "GET" }),
|
|
358
|
+
getBundleDownloadUrl: (appId, bundleId, options) => request(
|
|
359
|
+
`/v1/apps/${encodeURIComponent(appId)}/bundles/${encodeURIComponent(bundleId)}/download?redirect=${options?.redirect ?? false}`,
|
|
360
|
+
{ method: "GET" }
|
|
361
|
+
),
|
|
362
|
+
getBundleAssetsDownloadUrl: (appId, bundleId, options) => {
|
|
363
|
+
const qs = new URLSearchParams({
|
|
364
|
+
redirect: String(options?.redirect ?? false),
|
|
365
|
+
kind: options?.kind ?? "metro-assets"
|
|
366
|
+
});
|
|
367
|
+
return request(
|
|
368
|
+
`/v1/apps/${encodeURIComponent(appId)}/bundles/${encodeURIComponent(bundleId)}/assets/download?${qs.toString()}`,
|
|
369
|
+
{ method: "GET" }
|
|
370
|
+
);
|
|
371
|
+
},
|
|
372
|
+
listAgentRuns: (appId, params) => {
|
|
373
|
+
const qs = new URLSearchParams();
|
|
374
|
+
if (typeof params?.limit === "number") qs.set("limit", String(params.limit));
|
|
375
|
+
if (typeof params?.offset === "number") qs.set("offset", String(params.offset));
|
|
376
|
+
if (params?.status) qs.set("status", params.status);
|
|
377
|
+
if (params?.currentPhase) qs.set("currentPhase", params.currentPhase);
|
|
378
|
+
if (params?.createdAfter) qs.set("createdAfter", params.createdAfter);
|
|
379
|
+
if (params?.createdBefore) qs.set("createdBefore", params.createdBefore);
|
|
380
|
+
const suffix = qs.toString() ? `?${qs.toString()}` : "";
|
|
381
|
+
return request(`/v1/apps/${encodeURIComponent(appId)}/agent-runs${suffix}`, { method: "GET" });
|
|
382
|
+
},
|
|
383
|
+
getAgentRun: (appId, runId) => request(`/v1/apps/${encodeURIComponent(appId)}/agent-runs/${encodeURIComponent(runId)}`, { method: "GET" }),
|
|
384
|
+
listAgentRunEvents: (appId, runId, params) => {
|
|
385
|
+
const qs = new URLSearchParams();
|
|
386
|
+
if (typeof params?.limit === "number") qs.set("limit", String(params.limit));
|
|
387
|
+
if (typeof params?.offset === "number") qs.set("offset", String(params.offset));
|
|
388
|
+
if (params?.createdAfter) qs.set("createdAfter", params.createdAfter);
|
|
389
|
+
if (params?.createdBefore) qs.set("createdBefore", params.createdBefore);
|
|
390
|
+
const suffix = qs.toString() ? `?${qs.toString()}` : "";
|
|
391
|
+
return request(`/v1/apps/${encodeURIComponent(appId)}/agent-runs/${encodeURIComponent(runId)}/events${suffix}`, {
|
|
392
|
+
method: "GET"
|
|
393
|
+
});
|
|
394
|
+
},
|
|
395
|
+
getSandboxStatus: (appId) => request(`/v1/apps/${encodeURIComponent(appId)}/sandbox/status`, { method: "GET" })
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
export {
|
|
400
|
+
createApiClient
|
|
401
|
+
};
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getCurrentBranch
|
|
3
|
+
} from "./chunk-K54U353Z.js";
|
|
4
|
+
import {
|
|
5
|
+
RemixError
|
|
6
|
+
} from "./chunk-YZ34ICNN.js";
|
|
7
|
+
|
|
8
|
+
// src/infrastructure/binding/collabBindingStore.ts
|
|
9
|
+
import fs2 from "fs/promises";
|
|
10
|
+
import path2 from "path";
|
|
11
|
+
|
|
12
|
+
// src/shared/fs.ts
|
|
13
|
+
import fs from "fs/promises";
|
|
14
|
+
import path from "path";
|
|
15
|
+
async function reserveDirectory(targetDir) {
|
|
16
|
+
try {
|
|
17
|
+
await fs.mkdir(targetDir);
|
|
18
|
+
return targetDir;
|
|
19
|
+
} catch (error) {
|
|
20
|
+
if (error?.code === "EEXIST") {
|
|
21
|
+
throw new RemixError("Output directory already exists.", {
|
|
22
|
+
exitCode: 2,
|
|
23
|
+
hint: `Choose an empty destination path: ${targetDir}`
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async function reserveAvailableDirPath(preferredDir) {
|
|
30
|
+
const parent = path.dirname(preferredDir);
|
|
31
|
+
const base = path.basename(preferredDir);
|
|
32
|
+
for (let i = 1; i <= 1e3; i += 1) {
|
|
33
|
+
const candidate = i === 1 ? preferredDir : path.join(parent, `${base}-${i}`);
|
|
34
|
+
try {
|
|
35
|
+
await fs.mkdir(candidate);
|
|
36
|
+
return candidate;
|
|
37
|
+
} catch (error) {
|
|
38
|
+
if (error?.code === "EEXIST") continue;
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
throw new RemixError("No available output directory name.", {
|
|
43
|
+
exitCode: 2,
|
|
44
|
+
hint: `Tried ${base} through ${base}-1000 under ${parent}.`
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
async function writeJsonAtomic(filePath, value) {
|
|
48
|
+
const dir = path.dirname(filePath);
|
|
49
|
+
await fs.mkdir(dir, { recursive: true });
|
|
50
|
+
const tmp = `${filePath}.tmp-${Date.now()}`;
|
|
51
|
+
await fs.writeFile(tmp, `${JSON.stringify(value, null, 2)}
|
|
52
|
+
`, "utf8");
|
|
53
|
+
await fs.rename(tmp, filePath);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// src/infrastructure/binding/collabBindingStore.ts
|
|
57
|
+
function getCollabBindingPath(repoRoot) {
|
|
58
|
+
return path2.join(repoRoot, ".remix", "config.json");
|
|
59
|
+
}
|
|
60
|
+
function buildBindingFileV2(params) {
|
|
61
|
+
return {
|
|
62
|
+
schemaVersion: 2,
|
|
63
|
+
projectId: params.projectId,
|
|
64
|
+
repoFingerprint: params.repoFingerprint,
|
|
65
|
+
remoteUrl: params.remoteUrl,
|
|
66
|
+
defaultBranch: params.defaultBranch,
|
|
67
|
+
branchBindings: params.branchBindings
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function normalizeBranchName(value) {
|
|
71
|
+
const normalized = String(value ?? "").trim();
|
|
72
|
+
return normalized || null;
|
|
73
|
+
}
|
|
74
|
+
function normalizeBranchBinding(value) {
|
|
75
|
+
if (!value?.currentAppId || !value?.upstreamAppId) return null;
|
|
76
|
+
return {
|
|
77
|
+
currentAppId: value.currentAppId,
|
|
78
|
+
upstreamAppId: value.upstreamAppId,
|
|
79
|
+
threadId: value.threadId ?? null,
|
|
80
|
+
laneId: value.laneId ?? null,
|
|
81
|
+
bindingMode: value.bindingMode === "legacy" ? "legacy" : "lane"
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function buildResolvedBinding(params) {
|
|
85
|
+
if (!params.binding) return null;
|
|
86
|
+
return {
|
|
87
|
+
schemaVersion: 2,
|
|
88
|
+
projectId: params.projectId,
|
|
89
|
+
currentAppId: params.binding.currentAppId,
|
|
90
|
+
upstreamAppId: params.binding.upstreamAppId,
|
|
91
|
+
threadId: params.binding.threadId,
|
|
92
|
+
repoFingerprint: params.repoFingerprint,
|
|
93
|
+
remoteUrl: params.remoteUrl,
|
|
94
|
+
defaultBranch: params.defaultBranch,
|
|
95
|
+
laneId: params.binding.laneId,
|
|
96
|
+
branchName: params.branchName,
|
|
97
|
+
bindingMode: params.binding.bindingMode
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
async function readCollabBindingState(repoRoot) {
|
|
101
|
+
try {
|
|
102
|
+
const filePath = getCollabBindingPath(repoRoot);
|
|
103
|
+
const raw = await fs2.readFile(filePath, "utf8");
|
|
104
|
+
const parsed = JSON.parse(raw);
|
|
105
|
+
if (!parsed || typeof parsed !== "object" || !("projectId" in parsed) || !parsed.projectId) return null;
|
|
106
|
+
const currentBranch = normalizeBranchName(await getCurrentBranch(repoRoot).catch(() => null));
|
|
107
|
+
if (parsed.schemaVersion === 1) {
|
|
108
|
+
if (!parsed.currentAppId || !parsed.upstreamAppId) return null;
|
|
109
|
+
const preferredBranch = normalizeBranchName(parsed.preferredBranch ?? parsed.defaultBranch ?? null);
|
|
110
|
+
const branchKey = preferredBranch ?? currentBranch ?? null;
|
|
111
|
+
const branchBindings2 = branchKey ? {
|
|
112
|
+
[branchKey]: {
|
|
113
|
+
currentAppId: parsed.currentAppId,
|
|
114
|
+
upstreamAppId: parsed.upstreamAppId,
|
|
115
|
+
threadId: parsed.threadId ?? null,
|
|
116
|
+
laneId: null,
|
|
117
|
+
bindingMode: "legacy"
|
|
118
|
+
}
|
|
119
|
+
} : {};
|
|
120
|
+
const migratedFile = buildBindingFileV2({
|
|
121
|
+
projectId: parsed.projectId,
|
|
122
|
+
repoFingerprint: parsed.repoFingerprint ?? null,
|
|
123
|
+
remoteUrl: parsed.remoteUrl ?? null,
|
|
124
|
+
defaultBranch: parsed.defaultBranch ?? null,
|
|
125
|
+
branchBindings: branchBindings2
|
|
126
|
+
});
|
|
127
|
+
try {
|
|
128
|
+
await writeJsonAtomic(filePath, migratedFile);
|
|
129
|
+
} catch {
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
schemaVersion: 2,
|
|
133
|
+
projectId: migratedFile.projectId,
|
|
134
|
+
repoFingerprint: migratedFile.repoFingerprint,
|
|
135
|
+
remoteUrl: migratedFile.remoteUrl,
|
|
136
|
+
defaultBranch: migratedFile.defaultBranch,
|
|
137
|
+
currentBranch,
|
|
138
|
+
branchBindings: migratedFile.branchBindings,
|
|
139
|
+
binding: buildResolvedBinding({
|
|
140
|
+
projectId: migratedFile.projectId,
|
|
141
|
+
repoFingerprint: migratedFile.repoFingerprint,
|
|
142
|
+
remoteUrl: migratedFile.remoteUrl,
|
|
143
|
+
defaultBranch: migratedFile.defaultBranch,
|
|
144
|
+
branchName: branchKey,
|
|
145
|
+
binding: branchKey ? migratedFile.branchBindings[branchKey] : null
|
|
146
|
+
})
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
if (parsed.schemaVersion !== 2) return null;
|
|
150
|
+
const file = parsed;
|
|
151
|
+
if (!file.projectId) return null;
|
|
152
|
+
let shouldPersistNormalizedBranchBindings = false;
|
|
153
|
+
const branchBindings = Object.fromEntries(
|
|
154
|
+
Object.entries(file.branchBindings ?? {}).map(([branchName, branchBinding]) => {
|
|
155
|
+
const normalized = normalizeBranchBinding(branchBinding);
|
|
156
|
+
const rawBindingMode = branchBinding && typeof branchBinding === "object" && "bindingMode" in branchBinding ? branchBinding.bindingMode : null;
|
|
157
|
+
const hasLegacyPreferredBranch = Boolean(branchBinding) && typeof branchBinding === "object" && "preferredBranch" in branchBinding;
|
|
158
|
+
if (normalized && (rawBindingMode !== normalized.bindingMode || hasLegacyPreferredBranch)) {
|
|
159
|
+
shouldPersistNormalizedBranchBindings = true;
|
|
160
|
+
}
|
|
161
|
+
return [branchName, normalized];
|
|
162
|
+
}).filter((entry) => Boolean(entry[1]))
|
|
163
|
+
);
|
|
164
|
+
const legacyExplicitBinding = normalizeBranchBinding(file.explicitBinding ?? null);
|
|
165
|
+
const legacyExplicitBranch = currentBranch ?? normalizeBranchName(file.defaultBranch);
|
|
166
|
+
if (legacyExplicitBinding && legacyExplicitBranch) {
|
|
167
|
+
branchBindings[legacyExplicitBranch] = {
|
|
168
|
+
...legacyExplicitBinding,
|
|
169
|
+
bindingMode: "lane"
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
if ("explicitBinding" in file || shouldPersistNormalizedBranchBindings) {
|
|
173
|
+
try {
|
|
174
|
+
await writeJsonAtomic(filePath, buildBindingFileV2({
|
|
175
|
+
projectId: file.projectId,
|
|
176
|
+
repoFingerprint: file.repoFingerprint ?? null,
|
|
177
|
+
remoteUrl: file.remoteUrl ?? null,
|
|
178
|
+
defaultBranch: file.defaultBranch ?? null,
|
|
179
|
+
branchBindings
|
|
180
|
+
}));
|
|
181
|
+
} catch {
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
const resolvedBranch = currentBranch ?? normalizeBranchName(file.defaultBranch);
|
|
185
|
+
return {
|
|
186
|
+
schemaVersion: 2,
|
|
187
|
+
projectId: file.projectId,
|
|
188
|
+
repoFingerprint: file.repoFingerprint ?? null,
|
|
189
|
+
remoteUrl: file.remoteUrl ?? null,
|
|
190
|
+
defaultBranch: file.defaultBranch ?? null,
|
|
191
|
+
currentBranch,
|
|
192
|
+
branchBindings,
|
|
193
|
+
binding: buildResolvedBinding({
|
|
194
|
+
projectId: file.projectId,
|
|
195
|
+
repoFingerprint: file.repoFingerprint ?? null,
|
|
196
|
+
remoteUrl: file.remoteUrl ?? null,
|
|
197
|
+
defaultBranch: file.defaultBranch ?? null,
|
|
198
|
+
branchName: resolvedBranch,
|
|
199
|
+
binding: resolvedBranch ? branchBindings[resolvedBranch] ?? null : null
|
|
200
|
+
})
|
|
201
|
+
};
|
|
202
|
+
} catch {
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
async function readCollabBinding(repoRoot) {
|
|
207
|
+
const state = await readCollabBindingState(repoRoot);
|
|
208
|
+
return state?.binding ?? null;
|
|
209
|
+
}
|
|
210
|
+
async function writeCollabBinding(repoRoot, binding) {
|
|
211
|
+
const filePath = getCollabBindingPath(repoRoot);
|
|
212
|
+
const currentBranch = normalizeBranchName(await getCurrentBranch(repoRoot).catch(() => null));
|
|
213
|
+
const branchName = normalizeBranchName(binding.branchName) ?? currentBranch ?? binding.defaultBranch ?? "main";
|
|
214
|
+
const existing = await readCollabBindingState(repoRoot);
|
|
215
|
+
const branchBindings = { ...existing?.branchBindings ?? {} };
|
|
216
|
+
branchBindings[branchName] = {
|
|
217
|
+
currentAppId: binding.currentAppId,
|
|
218
|
+
upstreamAppId: binding.upstreamAppId,
|
|
219
|
+
threadId: binding.threadId ?? null,
|
|
220
|
+
laneId: binding.laneId ?? null,
|
|
221
|
+
bindingMode: binding.bindingMode ?? "lane"
|
|
222
|
+
};
|
|
223
|
+
await writeJsonAtomic(filePath, buildBindingFileV2({
|
|
224
|
+
projectId: binding.projectId,
|
|
225
|
+
repoFingerprint: binding.repoFingerprint ?? null,
|
|
226
|
+
remoteUrl: binding.remoteUrl ?? null,
|
|
227
|
+
defaultBranch: binding.defaultBranch ?? null,
|
|
228
|
+
branchBindings
|
|
229
|
+
}));
|
|
230
|
+
return filePath;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export {
|
|
234
|
+
reserveDirectory,
|
|
235
|
+
reserveAvailableDirPath,
|
|
236
|
+
getCollabBindingPath,
|
|
237
|
+
readCollabBindingState,
|
|
238
|
+
readCollabBinding,
|
|
239
|
+
writeCollabBinding
|
|
240
|
+
};
|