|
| 1 | +import { PlaneClient } from "../../../src/client/plane-client"; |
| 2 | +import { AgentRun, AgentRunActivity } from "../../../src/models"; |
| 3 | +import { config } from "../constants"; |
| 4 | +import { createTestClient } from "../../helpers/test-utils"; |
| 5 | +import { describeIf as describe } from "../../helpers/conditional-tests"; |
| 6 | + |
| 7 | +describe(!!(config.workspaceSlug && config.agentSlug), "Agent Run Activities API Tests", () => { |
| 8 | + let client: PlaneClient; |
| 9 | + let workspaceSlug: string; |
| 10 | + let agentSlug: string; |
| 11 | + let projectId: string; |
| 12 | + let agentRun: AgentRun; |
| 13 | + let activity: AgentRunActivity; |
| 14 | + |
| 15 | + beforeAll(async () => { |
| 16 | + client = createTestClient(); |
| 17 | + workspaceSlug = config.workspaceSlug; |
| 18 | + agentSlug = config.agentSlug; |
| 19 | + projectId = config.projectId; |
| 20 | + |
| 21 | + // Create an agent run for testing activities |
| 22 | + agentRun = await client.agentRuns.create(workspaceSlug, { |
| 23 | + agent_slug: agentSlug, |
| 24 | + project: projectId, |
| 25 | + }); |
| 26 | + }); |
| 27 | + |
| 28 | + it("should create an agent run activity", async () => { |
| 29 | + activity = await client.agentRuns.activities.create(workspaceSlug, agentRun.id, { |
| 30 | + content: { |
| 31 | + type: "thought", |
| 32 | + body: "Test thought activity", |
| 33 | + }, |
| 34 | + type: "thought", |
| 35 | + project: projectId, |
| 36 | + }); |
| 37 | + |
| 38 | + expect(activity).toBeDefined(); |
| 39 | + expect(activity.id).toBeDefined(); |
| 40 | + expect(activity.type).toBe("thought"); |
| 41 | + expect(activity.agent_run).toBe(agentRun.id); |
| 42 | + }); |
| 43 | + |
| 44 | + it("should list agent run activities", async () => { |
| 45 | + const activitiesResponse = await client.agentRuns.activities.list(workspaceSlug, agentRun.id); |
| 46 | + |
| 47 | + expect(activitiesResponse).toBeDefined(); |
| 48 | + expect(Array.isArray(activitiesResponse.results)).toBe(true); |
| 49 | + expect(activitiesResponse.results.length).toBeGreaterThan(0); |
| 50 | + |
| 51 | + const foundActivity = activitiesResponse.results.find((a) => a.id === activity.id); |
| 52 | + expect(foundActivity).toBeDefined(); |
| 53 | + }); |
| 54 | + |
| 55 | + it("should retrieve an agent run activity", async () => { |
| 56 | + const retrievedActivity = await client.agentRuns.activities.retrieve( |
| 57 | + workspaceSlug, |
| 58 | + agentRun.id, |
| 59 | + activity.id |
| 60 | + ); |
| 61 | + |
| 62 | + expect(retrievedActivity).toBeDefined(); |
| 63 | + expect(retrievedActivity.id).toBe(activity.id); |
| 64 | + expect(retrievedActivity.type).toBe("thought"); |
| 65 | + }); |
| 66 | + |
| 67 | + it("should create an action type activity", async () => { |
| 68 | + const actionActivity = await client.agentRuns.activities.create(workspaceSlug, agentRun.id, { |
| 69 | + content: { |
| 70 | + type: "action", |
| 71 | + action: "create_comment", |
| 72 | + parameters: { |
| 73 | + comment: "Test comment from agent", |
| 74 | + }, |
| 75 | + }, |
| 76 | + type: "action", |
| 77 | + project: projectId, |
| 78 | + }); |
| 79 | + |
| 80 | + expect(actionActivity).toBeDefined(); |
| 81 | + expect(actionActivity.id).toBeDefined(); |
| 82 | + expect(actionActivity.type).toBe("action"); |
| 83 | + }); |
| 84 | + |
| 85 | + it("should create a response type activity", async () => { |
| 86 | + const responseActivity = await client.agentRuns.activities.create(workspaceSlug, agentRun.id, { |
| 87 | + content: { |
| 88 | + type: "response", |
| 89 | + body: "This is a response from the agent", |
| 90 | + }, |
| 91 | + type: "response", |
| 92 | + project: projectId, |
| 93 | + }); |
| 94 | + |
| 95 | + expect(responseActivity).toBeDefined(); |
| 96 | + expect(responseActivity.id).toBeDefined(); |
| 97 | + expect(responseActivity.type).toBe("response"); |
| 98 | + }); |
| 99 | + |
| 100 | + it("should create an elicitation type activity", async () => { |
| 101 | + const elicitationActivity = await client.agentRuns.activities.create(workspaceSlug, agentRun.id, { |
| 102 | + content: { |
| 103 | + type: "elicitation", |
| 104 | + body: "What would you like me to do next?", |
| 105 | + }, |
| 106 | + type: "elicitation", |
| 107 | + signal: "select", |
| 108 | + signal_metadata: { |
| 109 | + options: ["option1", "option2"], |
| 110 | + }, |
| 111 | + project: projectId, |
| 112 | + }); |
| 113 | + |
| 114 | + expect(elicitationActivity).toBeDefined(); |
| 115 | + expect(elicitationActivity.id).toBeDefined(); |
| 116 | + expect(elicitationActivity.type).toBe("elicitation"); |
| 117 | + expect(elicitationActivity.signal).toBe("select"); |
| 118 | + }); |
| 119 | +}); |
| 120 | + |
0 commit comments