Repository navigation
[SILO-1834] feat: agent runs and run activities in the v2 client #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,9 @@ TEST_WORKSPACE_SLUG=your-workspace-slug | |
|
|
||
| # Agent configuration | ||
| TEST_AGENT_SLUG=your-installed-agent-slug | ||
| # OAuth access token of that agent's bot user (client-credentials grant); enables the | ||
| # agent-side half of tests/e2e/v2/agent-runs.e2e.test.ts. Short-lived — never commit one. | ||
| TEST_AGENT_ACCESS_TOKEN=your-agent-bot-access-token | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leave the optional bot token empty by default. If a user copies this template and configures only the person-side tests, the placeholder is still a nonempty
|
||
|
|
||
| # Project and user IDs | ||
| TEST_PROJECT_ID=your-project-id | ||
|
|
||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| import { | ||
| AgentRunActivity, | ||
| AgentRunActivitySignal, | ||
| AgentRunActivityType, | ||
| CreateAgentRunActivity, | ||
| } from "../../../models/v2/AgentRunActivity"; | ||
| import { Page } from "../../../models/v2/common"; | ||
| import { EXPAND, FIELDS, ORDER_BY } from "../generated/constants"; | ||
| import { AnyOperationId, V2Resource } from "../kernel/resource"; | ||
|
|
||
| export type AgentRunActivityField = (typeof FIELDS)["run_activities_list"][number]; | ||
| export type AgentRunActivityOrderBy = (typeof ORDER_BY)["run_activities_list"][number]; | ||
| /** Only `"actor"`. */ | ||
| export type AgentRunActivityExpand = (typeof EXPAND)["run_activities_list"][number]; | ||
|
|
||
| /** | ||
| * The filters both activity lists accept — one run's log here, and the cross-run feed | ||
| * (`WorkspaceAgentRunActivities`), which declares the identical set. | ||
| */ | ||
| export interface AgentRunActivityFilters { | ||
| actor_id?: string; | ||
| /** Narrows the cross-run feed to one run; redundant on a single run's log. */ | ||
| agent_run_id?: string; | ||
| comment_id?: string; | ||
| /** Activities created at or after this ISO 8601 timestamp — the polling watermark. */ | ||
| created_at__gte?: string; | ||
| ephemeral?: boolean; | ||
| signal?: AgentRunActivitySignal; | ||
| type?: AgentRunActivityType; | ||
| type__in?: readonly AgentRunActivityType[]; | ||
| } | ||
|
|
||
| export interface ListAgentRunActivitiesParams extends AgentRunActivityFilters { | ||
| fields?: readonly AgentRunActivityField[]; | ||
| expand?: readonly AgentRunActivityExpand[]; | ||
| order_by?: AgentRunActivityOrderBy; | ||
| offset?: number; | ||
| per_page?: number; | ||
| /** Set to `"cursor"` to opt into the cursor envelope — see `ListStatesParams.paginate`. */ | ||
| paginate?: "cursor"; | ||
| /** Resume a cursor-paginated walk from a `next_cursor` an earlier page answered with. */ | ||
| cursor?: string; | ||
| count?: boolean; | ||
| } | ||
|
|
||
| /** `?fields=`/`?expand=` on a single-row read or write. */ | ||
| export interface AgentRunActivityShapeParams { | ||
| fields?: readonly AgentRunActivityField[]; | ||
| expand?: readonly AgentRunActivityExpand[]; | ||
| } | ||
|
|
||
| /** | ||
| * One agent run's activity log (api_v2): list, read, and post. No PATCH and no DELETE — | ||
| * an activity is a record of what happened. | ||
| * | ||
| * Reached flat — `v2.workspaces.agentRuns.activities.list(slug, run)` — or from a fetched run, | ||
| * which supplies both ids: `run.activities.list()`. | ||
| * | ||
| * Oldest first, by `(created_at, id)`, which is cursor-safe: an agent that polls with | ||
| * `paginate: "cursor"` or `created_at__gte` should dedupe by `id`, because a sync read | ||
| * holds back rows stamped in the last 3 seconds until a later poll. | ||
| */ | ||
| export class AgentRunActivities extends V2Resource<AgentRunActivity, CreateAgentRunActivity, never> { | ||
| protected path = "/workspaces/{slug}/runs/{run_id}/activities/"; | ||
| protected operations: Record<string, AnyOperationId> = { | ||
| list: "run_activities_list", | ||
| retrieve: "run_activities_retrieve", | ||
| create: "run_activities_create", | ||
| }; | ||
|
|
||
| /** | ||
| * One page of `AgentRunActivity` rows. Use `iterate` to follow pages automatically. | ||
| * | ||
| * @remarks The row shape returned when `fields` is a literal tuple. `id` is always present. | ||
| */ | ||
| list<F extends Exclude<AgentRunActivityField, "all"> & keyof AgentRunActivity>( | ||
| slug: string, | ||
| run: string, | ||
| params: ListAgentRunActivitiesParams & { fields: readonly F[] } | ||
| ): Promise<Page<Pick<AgentRunActivity, F | "id">>>; | ||
| /** One page of `AgentRunActivity` rows. Use `iterate` to follow pages automatically. */ | ||
| list(slug: string, run: string, params?: ListAgentRunActivitiesParams): Promise<Page<AgentRunActivity>>; | ||
| list(slug: string, run: string, params?: ListAgentRunActivitiesParams): Promise<Page<AgentRunActivity>> { | ||
| return this.doList({ slug, run_id: run }, params as Record<string, unknown>); | ||
| } | ||
|
|
||
| /** Every activity on the run, oldest first, following pages automatically. */ | ||
| iterate<F extends Exclude<AgentRunActivityField, "all"> & keyof AgentRunActivity>( | ||
| slug: string, | ||
| run: string, | ||
| params: Omit<ListAgentRunActivitiesParams, "offset" | "count"> & { fields: readonly F[] } | ||
| ): AsyncGenerator<Pick<AgentRunActivity, F | "id">>; | ||
| /** Every activity on the run, oldest first, following pages automatically. */ | ||
| iterate( | ||
| slug: string, | ||
| run: string, | ||
| params?: Omit<ListAgentRunActivitiesParams, "offset" | "count"> | ||
| ): AsyncGenerator<AgentRunActivity>; | ||
| iterate( | ||
| slug: string, | ||
| run: string, | ||
| params?: Omit<ListAgentRunActivitiesParams, "offset" | "count"> | ||
| ): AsyncGenerator<AgentRunActivity> { | ||
| return this.doIterate({ slug, run_id: run }, params as Record<string, unknown>); | ||
| } | ||
|
|
||
| retrieve<F extends Exclude<AgentRunActivityField, "all"> & keyof AgentRunActivity>( | ||
| slug: string, | ||
| run: string, | ||
| activity: string, | ||
| params: { fields: readonly F[]; expand?: readonly AgentRunActivityExpand[] } | ||
| ): Promise<Pick<AgentRunActivity, F | "id">>; | ||
| retrieve( | ||
| slug: string, | ||
| run: string, | ||
| activity: string, | ||
| params?: AgentRunActivityShapeParams | ||
| ): Promise<AgentRunActivity>; | ||
| retrieve( | ||
| slug: string, | ||
| run: string, | ||
| activity: string, | ||
| params?: AgentRunActivityShapeParams | ||
| ): Promise<AgentRunActivity> { | ||
| return this.doRetrieve({ slug, run_id: run, pk: activity }, params as Record<string, unknown>); | ||
| } | ||
|
|
||
| /** | ||
| * Post an activity to the run. | ||
| * | ||
| * The run's agent (a bot token) posts its output — `thought`, `action`, `response`, | ||
| * `elicitation` or `error`. A person posts only a `prompt` | ||
| * (`{ type: "prompt", content: { type: "prompt", body } }`), which is mirrored into the | ||
| * work item's thread as a reply; anything else from a person is a 400. | ||
| * | ||
| * @remarks The row shape returned when `fields` is a literal tuple. `id` is always present. | ||
| */ | ||
| create<F extends Exclude<AgentRunActivityField, "all"> & keyof AgentRunActivity>( | ||
| slug: string, | ||
| run: string, | ||
| data: CreateAgentRunActivity, | ||
| params: AgentRunActivityShapeParams & { fields: readonly F[] } | ||
| ): Promise<Pick<AgentRunActivity, F | "id">>; | ||
| /** | ||
| * Post an activity to the run. | ||
| * | ||
| * The run's agent (a bot token) posts its output — `thought`, `action`, `response`, | ||
| * `elicitation` or `error`. A person posts only a `prompt` | ||
| * (`{ type: "prompt", content: { type: "prompt", body } }`), which is mirrored into the | ||
| * work item's thread as a reply; anything else from a person is a 400. | ||
| */ | ||
| create( | ||
| slug: string, | ||
| run: string, | ||
| data: CreateAgentRunActivity, | ||
| params?: AgentRunActivityShapeParams | ||
| ): Promise<AgentRunActivity>; | ||
| create( | ||
| slug: string, | ||
| run: string, | ||
| data: CreateAgentRunActivity, | ||
| params?: AgentRunActivityShapeParams | ||
| ): Promise<AgentRunActivity> { | ||
| return this.doCreate(data, { slug, run_id: run }, params as Record<string, unknown>); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import { AgentRunActivity } from "../../../models/v2/AgentRunActivity"; | ||
| import { Page } from "../../../models/v2/common"; | ||
| import { EXPAND, FIELDS, ORDER_BY } from "../generated/constants"; | ||
| import { AnyOperationId, V2Resource } from "../kernel/resource"; | ||
| import { AgentRunActivityFilters } from "./Activities"; | ||
|
|
||
| export type WorkspaceAgentRunActivityField = (typeof FIELDS)["workspace_run_activities_list"][number]; | ||
| export type WorkspaceAgentRunActivityOrderBy = (typeof ORDER_BY)["workspace_run_activities_list"][number]; | ||
| /** Only `"actor"`. */ | ||
| export type WorkspaceAgentRunActivityExpand = (typeof EXPAND)["workspace_run_activities_list"][number]; | ||
|
|
||
| export interface ListWorkspaceAgentRunActivitiesParams extends AgentRunActivityFilters { | ||
| fields?: readonly WorkspaceAgentRunActivityField[]; | ||
| expand?: readonly WorkspaceAgentRunActivityExpand[]; | ||
| order_by?: WorkspaceAgentRunActivityOrderBy; | ||
| offset?: number; | ||
| per_page?: number; | ||
| /** Set to `"cursor"` to opt into the cursor envelope — see `ListStatesParams.paginate`. */ | ||
| paginate?: "cursor"; | ||
| /** Resume a cursor-paginated walk from a `next_cursor` an earlier page answered with. */ | ||
| cursor?: string; | ||
| count?: boolean; | ||
| } | ||
|
|
||
| /** | ||
| * The cross-run activity feed (api_v2): every activity on every run the caller can list, | ||
| * in one stream. Read-only. | ||
| * | ||
| * An agent keeps one `(created_at, id)` cursor here instead of polling run by run — for a | ||
| * bot token the feed is every activity on its own runs. Narrow it with `agent_run_id`, | ||
| * `type`/`type__in`, `signal` (a person's Stop arrives as a `prompt` with | ||
| * `signal: "stop"`) or `created_at__gte`. | ||
| * | ||
| * Reached as `v2.workspaces.agentRunActivities.list(slug)`, or from a fetched workspace as | ||
| * `workspace.agentRunActivities.list()`. It is a separate class from `AgentRunActivities` | ||
| * because the route takes the slug alone: a fetched run binds that class, and this one | ||
| * has no run id to bind. | ||
| * | ||
| * A sync read holds back rows stamped in the last 3 seconds until a later poll, so dedupe | ||
| * by `id` when polling with `paginate: "cursor"` or `created_at__gte`. | ||
| */ | ||
| export class WorkspaceAgentRunActivities extends V2Resource<AgentRunActivity, never, never> { | ||
| protected path = "/workspaces/{slug}/runs/activities/"; | ||
| protected operations: Record<string, AnyOperationId> = { | ||
| list: "workspace_run_activities_list", | ||
| }; | ||
|
|
||
| /** | ||
| * One page of the feed, oldest first. Use `iterate` to follow pages automatically. | ||
| * | ||
| * @remarks The row shape returned when `fields` is a literal tuple. `id` is always present. | ||
| */ | ||
| list<F extends Exclude<WorkspaceAgentRunActivityField, "all"> & keyof AgentRunActivity>( | ||
| slug: string, | ||
| params: ListWorkspaceAgentRunActivitiesParams & { fields: readonly F[] } | ||
| ): Promise<Page<Pick<AgentRunActivity, F | "id">>>; | ||
| /** One page of the feed, oldest first. Use `iterate` to follow pages automatically. */ | ||
| list(slug: string, params?: ListWorkspaceAgentRunActivitiesParams): Promise<Page<AgentRunActivity>>; | ||
| list(slug: string, params?: ListWorkspaceAgentRunActivitiesParams): Promise<Page<AgentRunActivity>> { | ||
| return this.doList({ slug }, params as Record<string, unknown>); | ||
| } | ||
|
|
||
| /** The whole feed, oldest first, following pages automatically. */ | ||
| iterate<F extends Exclude<WorkspaceAgentRunActivityField, "all"> & keyof AgentRunActivity>( | ||
| slug: string, | ||
| params: Omit<ListWorkspaceAgentRunActivitiesParams, "offset" | "count"> & { fields: readonly F[] } | ||
| ): AsyncGenerator<Pick<AgentRunActivity, F | "id">>; | ||
| /** The whole feed, oldest first, following pages automatically. */ | ||
| iterate( | ||
| slug: string, | ||
| params?: Omit<ListWorkspaceAgentRunActivitiesParams, "offset" | "count"> | ||
| ): AsyncGenerator<AgentRunActivity>; | ||
| iterate( | ||
| slug: string, | ||
| params?: Omit<ListWorkspaceAgentRunActivitiesParams, "offset" | "count"> | ||
| ): AsyncGenerator<AgentRunActivity> { | ||
| return this.doIterate({ slug }, params as Record<string, unknown>); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
sed -n '280,330p' README.mdRepository: makeplane/plane-node-sdk
Length of output: 2804
Script executed:
Repository: makeplane/plane-node-sdk
Length of output: 22742
Use a bot client for the agent steps.
If
clienthas the person credential needed forstop, the update can return 403. Use the agent’s bot token for the feed and update.Suggested fix