Skip to content

An open-source, faster Devin alternative

TypeScript

fix: isolate attachment retries and metadata

Mohamed Habibe326f00fe16a
diff --git a/cli/src/api.test.ts b/cli/src/api.test.ts
index 795e2ef7..fe5773d6 100644
--- a/cli/src/api.test.ts
+++ b/cli/src/api.test.ts
@@ -15,6 +15,7 @@ test("project service connections use project-scoped attachment routes", async (
if (request.method === "DELETE") return new Response(null, { status: 204 });
return Response.json({
projectId: "prj_1",
+ service: "linear",
provider: "linear",
label: "default",
connectionId: "conn_1",
@@ -27,28 +28,48 @@ test("project service connections use project-scoped attachment routes", async (
const client = new OpenComputerClient({
apiUrl: "https://app.opencomputer.dev",
apiKey: "test",
- });
+ }, "setup");
await client.projectServiceConnections("prj_1");
await client.attachProjectServiceConnection({
projectId: "prj_1",
connectionId: "conn_1",
});
+ await client.attachProjectServiceConnection({
+ projectId: "prj_1",
+ connectionId: "conn_2",
+ });
await client.detachProjectServiceConnection({
projectId: "prj_1",
connectionId: "conn_1",
});
+ await client.detachProjectServiceConnection({
+ projectId: "prj_1",
+ connectionId: "conn_2",
+ });
assert.deepEqual(
requests.map((request) => [request.method, new URL(request.url).pathname]),
[
["GET", "/api/managed-agents/projects/prj_1/service-connections"],
["POST", "/api/managed-agents/projects/prj_1/service-connections"],
+ ["POST", "/api/managed-agents/projects/prj_1/service-connections"],
+ ["DELETE", "/api/managed-agents/projects/prj_1/service-connections"],
["DELETE", "/api/managed-agents/projects/prj_1/service-connections"],
],
);
assert.deepEqual(await requests[1]!.json(), { connectionId: "conn_1" });
- assert.deepEqual(await requests[2]!.json(), { connectionId: "conn_1" });
+ assert.deepEqual(await requests[2]!.json(), { connectionId: "conn_2" });
+ assert.deepEqual(await requests[3]!.json(), { connectionId: "conn_1" });
+ assert.deepEqual(await requests[4]!.json(), { connectionId: "conn_2" });
+ assert.notEqual(
+ requests[1]!.headers.get("idempotency-key"),
+ requests[2]!.headers.get("idempotency-key"),
+ );
+ assert.notEqual(
+ requests[3]!.headers.get("idempotency-key"),
+ requests[4]!.headers.get("idempotency-key"),
+ );
});
test("reconnect asks the backend to preserve and reauthorize the logical connection", async (context) => {
diff --git a/cli/src/api.ts b/cli/src/api.ts
index 20caaf9f..c76c9626 100644
--- a/cli/src/api.ts
+++ b/cli/src/api.ts
@@ -123,6 +123,7 @@ export interface ServiceConnection {
export interface ProjectServiceAttachment {
projectId: string;
+ service: string;
provider: string;
label: string;
connectionId: string;
@@ -879,6 +880,17 @@ export class OpenComputerClient {
{
method: "POST",
body: JSON.stringify({ connectionId: input.connectionId }),
+ ...(this.idempotencyKey
+ ? {
+ headers: {
+ "idempotency-key": this.derivedIdempotencyKey(
+ "POST",
+ `/api/managed-agents/projects/${encodeURIComponent(input.projectId)}/service-connections`,
+ input.connectionId,
+ ),
+ },
+ }
+ : {}),
},
);
}
@@ -892,6 +904,17 @@ export class OpenComputerClient {
{
method: "DELETE",
body: JSON.stringify({ connectionId: input.connectionId }),
+ ...(this.idempotencyKey
+ ? {
+ headers: {
+ "idempotency-key": this.derivedIdempotencyKey(
+ "DELETE",
+ `/api/managed-agents/projects/${encodeURIComponent(input.projectId)}/service-connections`,
+ input.connectionId,
+ ),
+ },
+ }
+ : {}),
},
);
}
diff --git a/cloudflare-workers/api-edge/src/managed_agents.test.ts b/cloudflare-workers/api-edge/src/managed_agents.test.ts
index fd79143d..d385a427 100644
--- a/cloudflare-workers/api-edge/src/managed_agents.test.ts
+++ b/cloudflare-workers/api-edge/src/managed_agents.test.ts
@@ -998,6 +998,7 @@ describe("managed agents proxy", () => {
Response.json({
organizationId: "org_test",
projectId: "prj_test",
+ service: "linear",
provider: "openai",
environment: "development",
enabled: false,
diff --git a/cloudflare-workers/api-edge/src/managed_agents.ts b/cloudflare-workers/api-edge/src/managed_agents.ts
index f915204a..4cc4096b 100644
--- a/cloudflare-workers/api-edge/src/managed_agents.ts
+++ b/cloudflare-workers/api-edge/src/managed_agents.ts
@@ -666,6 +666,7 @@ function publicProjectServiceAttachment(
const attachment = record(value) ?? {};
return {
projectId: attachment.projectId,
+ service: attachment.service,
provider: attachment.provider,
label: attachment.label,
connectionId: attachment.connectionId,