@pstdio/sdk 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/dist/api/actions.d.ts +12 -0
- package/dist/api/agents.d.ts +1 -0
- package/dist/api/index.d.ts +9 -0
- package/dist/api/index.js +0 -0
- package/dist/api/projects.d.ts +1 -0
- package/dist/api/sessions.d.ts +1 -0
- package/dist/api/statuses.d.ts +1 -0
- package/dist/api/tags.d.ts +1 -0
- package/dist/api/templates.d.ts +1 -0
- package/dist/api/tickets.d.ts +23 -0
- package/dist/api/workspaces.d.ts +1 -0
- package/dist/client/actions.d.ts +8 -0
- package/dist/client/agents.d.ts +13 -0
- package/dist/client/client.d.ts +24 -0
- package/dist/client/index.d.ts +12 -0
- package/dist/client/index.js +215 -0
- package/dist/client/projects.d.ts +13 -0
- package/dist/client/request.d.ts +16 -0
- package/dist/client/sessions.d.ts +15 -0
- package/dist/client/skills.d.ts +8 -0
- package/dist/client/statuses.d.ts +22 -0
- package/dist/client/tags.d.ts +13 -0
- package/dist/client/templates.d.ts +11 -0
- package/dist/client/tickets.d.ts +17 -0
- package/dist/client/workspaces.d.ts +12 -0
- package/dist/hooks/attempt.d.ts +14 -0
- package/dist/hooks/base.d.ts +17 -0
- package/dist/hooks/entities.d.ts +8 -0
- package/dist/hooks/index.d.ts +5 -0
- package/dist/hooks/index.js +0 -0
- package/dist/hooks/session.d.ts +13 -0
- package/dist/hooks/ticket.d.ts +23 -0
- package/dist/hooks/worktree.d.ts +52 -0
- package/dist/plugins/define-plugin.d.ts +2 -0
- package/dist/plugins/helpers/context.d.ts +24 -0
- package/dist/plugins/helpers/create-attempt.d.ts +5 -0
- package/dist/plugins/helpers/create-session.d.ts +20 -0
- package/dist/plugins/helpers/create-workspace.d.ts +5 -0
- package/dist/plugins/helpers/find-ticket-by-ref.d.ts +6 -0
- package/dist/plugins/helpers/find-workspace-by-ref.d.ts +5 -0
- package/dist/plugins/helpers/followup-session.d.ts +22 -0
- package/dist/plugins/helpers/get-attempts-for-ticket.d.ts +17 -0
- package/dist/plugins/helpers/index.d.ts +15 -0
- package/dist/plugins/helpers/remove-all-worktrees-for-ticket.d.ts +2 -0
- package/dist/plugins/helpers/run-command.d.ts +9 -0
- package/dist/plugins/helpers/set-ticket-status.d.ts +7 -0
- package/dist/plugins/helpers/set-workspace-attempt-status.d.ts +7 -0
- package/dist/plugins/helpers/ticket-pull.d.ts +18 -0
- package/dist/plugins/helpers/update-ticket-when-all-attempts-match.d.ts +7 -0
- package/dist/plugins/helpers/workspaces-for-ticket.d.ts +17 -0
- package/dist/plugins/helpers/worktree-bootstrap.d.ts +8 -0
- package/dist/plugins/hooks.d.ts +42 -0
- package/dist/plugins/index.d.ts +5 -0
- package/dist/plugins/index.js +464 -0
- package/dist/plugins/types.d.ts +89 -0
- package/dist/prompts/index.d.ts +1 -0
- package/dist/prompts/index.js +6 -0
- package/dist/prompts/render-prompt.d.ts +1 -0
- package/dist/resources/agent.d.ts +1 -0
- package/dist/resources/file.d.ts +1 -0
- package/dist/resources/index.d.ts +11 -0
- package/dist/resources/index.js +0 -0
- package/dist/resources/project.d.ts +1 -0
- package/dist/resources/session.d.ts +1 -0
- package/dist/resources/skill.d.ts +1 -0
- package/dist/resources/status.d.ts +1 -0
- package/dist/resources/tag.d.ts +1 -0
- package/dist/resources/template.d.ts +1 -0
- package/dist/resources/ticket.d.ts +1 -0
- package/dist/resources/workspace.d.ts +1 -0
- package/package.json +61 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { TargetType } from "../plugins/types";
|
|
2
|
+
export type ExecuteActionInput = {
|
|
3
|
+
target_type: TargetType;
|
|
4
|
+
target_id: string;
|
|
5
|
+
};
|
|
6
|
+
export type ActionResult = {
|
|
7
|
+
status: "success";
|
|
8
|
+
session_id?: string;
|
|
9
|
+
} | {
|
|
10
|
+
status: "error";
|
|
11
|
+
message: string;
|
|
12
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { SetupAgentInput, SetupAvailableAgentsInput, UpdateAgentInput } from "pstdio-api-contracts";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type { ActionResult, ExecuteActionInput } from "./actions";
|
|
2
|
+
export type { SetupAgentInput, SetupAvailableAgentsInput, UpdateAgentInput } from "./agents";
|
|
3
|
+
export type { CreateProjectInput, RegisterRepoInput } from "./projects";
|
|
4
|
+
export type { ApprovalInput, CreateSessionInput, FollowUpInput, ResolveSessionIdInput, ResolveSessionIdResponse, SessionConversationResponse, } from "./sessions";
|
|
5
|
+
export type { CreateAttemptStatusInput, CreateStatusInput } from "./statuses";
|
|
6
|
+
export type { CreateTagInput, CreateTagOptionInput, UpdateTagInput, UpdateTagOptionInput } from "./tags";
|
|
7
|
+
export type { CreateTemplateInput, UpdateTemplateInput } from "./templates";
|
|
8
|
+
export type { CreateTicketAttemptInput, CreateTicketInput, ListTicketsInput, TicketAttemptMode, TicketAttemptResponse, UpdateTicketInput, UpdateWhenAttemptStatusInput, UpdateWhenAttemptStatusResponse, UploadTicketFileInput, } from "./tickets";
|
|
9
|
+
export type { CreateWorkspaceInput, RemoveWorktreeResponse, UpdateAttemptStatusInput, UpdateAttemptStatusResponse, } from "./workspaces";
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { CreateProjectInput, RegisterRepoInput } from "pstdio-api-contracts";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { ApprovalInput, CreateSessionInput, FollowUpInput, ResolveSessionIdInput, ResolveSessionIdResponse, SessionConversationResponse, } from "pstdio-api-contracts";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { CreateAttemptStatusInput, CreateStatusInput } from "pstdio-api-contracts";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { CreateTagInput, CreateTagOptionInput, UpdateTagInput, UpdateTagOptionInput, } from "pstdio-api-contracts";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { CreateTemplateInput, UpdateTemplateInput } from "pstdio-api-contracts";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type { CreateTicketAttemptInput, CreateTicketInput, TicketAttemptMode, UpdateTicketInput, UpdateWhenAttemptStatusInput, UpdateWhenAttemptStatusResponse, UploadTicketFileInput, } from "pstdio-api-contracts";
|
|
2
|
+
import type { Ticket, Workspace } from "../resources";
|
|
3
|
+
export type ListTicketsInput = {
|
|
4
|
+
status?: string;
|
|
5
|
+
tag?: string | string[];
|
|
6
|
+
archived?: boolean;
|
|
7
|
+
draft?: boolean;
|
|
8
|
+
parent_id?: string;
|
|
9
|
+
shorthand?: string;
|
|
10
|
+
search?: string;
|
|
11
|
+
};
|
|
12
|
+
export type TicketAttemptResponse = {
|
|
13
|
+
mode: "worktree" | "current_branch";
|
|
14
|
+
ticket: Ticket;
|
|
15
|
+
workspace: Workspace;
|
|
16
|
+
session: {
|
|
17
|
+
id: string;
|
|
18
|
+
workspace_id: string;
|
|
19
|
+
title: string;
|
|
20
|
+
created_at: string;
|
|
21
|
+
updated_at: string;
|
|
22
|
+
} | null;
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { CreateWorkspaceInput, RemoveWorktreeResponse, UpdateAttemptStatusInput, UpdateAttemptStatusResponse, } from "pstdio-api-contracts";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ActionResult, ExecuteActionInput } from "../api/actions";
|
|
2
|
+
import type { ActionDescriptor, TargetType } from "../plugins/types";
|
|
3
|
+
import type { RequestFn } from "./request";
|
|
4
|
+
export type ActionClient = {
|
|
5
|
+
list(projectId: string, targetType?: TargetType): Promise<ActionDescriptor[]>;
|
|
6
|
+
execute(projectId: string, actionKey: string, input: ExecuteActionInput): Promise<ActionResult>;
|
|
7
|
+
};
|
|
8
|
+
export declare const createActionClient: (request: RequestFn) => ActionClient;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AgentModel, SetupAgentInput, SetupAvailableAgentsInput, UpdateAgentInput } from "pstdio-api-contracts";
|
|
2
|
+
import type { AgentConfig, AgentInfo } from "../resources";
|
|
3
|
+
import type { RequestFn } from "./request";
|
|
4
|
+
export type AgentClient = {
|
|
5
|
+
list(): Promise<AgentConfig[]>;
|
|
6
|
+
info(): Promise<AgentInfo[]>;
|
|
7
|
+
models(agentId: string): Promise<AgentModel[]>;
|
|
8
|
+
setup(input: SetupAgentInput): Promise<AgentConfig>;
|
|
9
|
+
setupAvailable(input: SetupAvailableAgentsInput): Promise<AgentConfig[]>;
|
|
10
|
+
update(agentId: string, input: UpdateAgentInput): Promise<AgentConfig>;
|
|
11
|
+
delete(agentId: string): Promise<void>;
|
|
12
|
+
};
|
|
13
|
+
export declare const createAgentClient: (request: RequestFn) => AgentClient;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type ActionClient } from "./actions";
|
|
2
|
+
import { type AgentClient } from "./agents";
|
|
3
|
+
import { type ProjectClient } from "./projects";
|
|
4
|
+
import type { ClientOptions } from "./request";
|
|
5
|
+
import { type SessionClient } from "./sessions";
|
|
6
|
+
import { type SkillClient } from "./skills";
|
|
7
|
+
import { type StatusClient } from "./statuses";
|
|
8
|
+
import { type TagClient } from "./tags";
|
|
9
|
+
import { type TemplateClient } from "./templates";
|
|
10
|
+
import { type TicketClient } from "./tickets";
|
|
11
|
+
import { type WorkspaceClient } from "./workspaces";
|
|
12
|
+
export type PstdioClient = {
|
|
13
|
+
projects: ProjectClient;
|
|
14
|
+
tickets: TicketClient;
|
|
15
|
+
workspaces: WorkspaceClient;
|
|
16
|
+
sessions: SessionClient;
|
|
17
|
+
statuses: StatusClient;
|
|
18
|
+
tags: TagClient;
|
|
19
|
+
templates: TemplateClient;
|
|
20
|
+
skills: SkillClient;
|
|
21
|
+
agents: AgentClient;
|
|
22
|
+
actions: ActionClient;
|
|
23
|
+
};
|
|
24
|
+
export declare const createClient: (options?: ClientOptions) => PstdioClient;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type { ActionClient } from "./actions";
|
|
2
|
+
export type { AgentClient } from "./agents";
|
|
3
|
+
export { createClient, type PstdioClient } from "./client";
|
|
4
|
+
export type { ProjectClient } from "./projects";
|
|
5
|
+
export { type ClientOptions, createRequest, PstdioApiError, type RequestFn } from "./request";
|
|
6
|
+
export type { SessionClient } from "./sessions";
|
|
7
|
+
export type { SkillClient } from "./skills";
|
|
8
|
+
export type { StatusClient } from "./statuses";
|
|
9
|
+
export type { TagClient } from "./tags";
|
|
10
|
+
export type { TemplateClient } from "./templates";
|
|
11
|
+
export type { TicketClient } from "./tickets";
|
|
12
|
+
export type { WorkspaceClient } from "./workspaces";
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
// src/client/actions.ts
|
|
2
|
+
var createActionClient = (request) => ({
|
|
3
|
+
list: (projectId, targetType) => request(targetType ? `/v1/projects/${projectId}/actions?targetType=${targetType}` : `/v1/projects/${projectId}/actions`),
|
|
4
|
+
execute: (projectId, actionKey, input) => request(`/v1/projects/${projectId}/actions/${encodeURIComponent(actionKey)}/execute`, {
|
|
5
|
+
method: "POST",
|
|
6
|
+
body: input
|
|
7
|
+
})
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
// src/client/agents.ts
|
|
11
|
+
var createAgentClient = (request) => ({
|
|
12
|
+
list: () => request("/v1/agents"),
|
|
13
|
+
info: () => request("/v1/agents/info"),
|
|
14
|
+
models: (agentId) => request(`/v1/agents/${agentId}/models`),
|
|
15
|
+
setup: (input) => request("/v1/agents", { method: "POST", body: input }),
|
|
16
|
+
setupAvailable: (input) => request("/v1/agents/setup-available", { method: "POST", body: input }),
|
|
17
|
+
update: (agentId, input) => request(`/v1/agents/${agentId}`, { method: "PATCH", body: input }),
|
|
18
|
+
delete: (agentId) => request(`/v1/agents/${agentId}`, { method: "DELETE" })
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// src/client/projects.ts
|
|
22
|
+
var createProjectClient = (request) => ({
|
|
23
|
+
list: () => request("/v1/projects"),
|
|
24
|
+
get: (projectId) => request(`/v1/projects/${projectId}`),
|
|
25
|
+
create: (input) => request("/v1/projects", { method: "POST", body: input }),
|
|
26
|
+
delete: (projectId) => request(`/v1/projects/${projectId}`, { method: "DELETE" }),
|
|
27
|
+
listRepos: (projectId) => request(`/v1/projects/${projectId}/repos`),
|
|
28
|
+
registerRepo: (projectId, input) => request(`/v1/projects/${projectId}/repos`, { method: "POST", body: input }),
|
|
29
|
+
removeRepo: (projectId, repoId) => request(`/v1/projects/${projectId}/repos/${repoId}`, { method: "DELETE" })
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// src/client/request.ts
|
|
33
|
+
class PstdioApiError extends Error {
|
|
34
|
+
status;
|
|
35
|
+
constructor(message, status) {
|
|
36
|
+
super(message);
|
|
37
|
+
this.name = "PstdioApiError";
|
|
38
|
+
this.status = status;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
var readErrorMessage = (errorBody, status) => {
|
|
42
|
+
if (errorBody && typeof errorBody === "object" && errorBody !== null && "error" in errorBody) {
|
|
43
|
+
const message = String(errorBody.error);
|
|
44
|
+
const hookOutput = "hook_output" in errorBody && typeof errorBody.hook_output === "string" ? errorBody.hook_output.trim() : "";
|
|
45
|
+
return hookOutput ? `${message}
|
|
46
|
+
${hookOutput}` : message;
|
|
47
|
+
}
|
|
48
|
+
return `Request failed: ${status}`;
|
|
49
|
+
};
|
|
50
|
+
var createRequest = (options) => {
|
|
51
|
+
const baseUrl = options.baseUrl ?? (typeof process !== "undefined" ? process.env.PSTDIO_API_URL : undefined) ?? "http://localhost:19840";
|
|
52
|
+
const fetchFn = options.fetch ?? globalThis.fetch;
|
|
53
|
+
return async (path, reqOpts = {}) => {
|
|
54
|
+
const headers = {};
|
|
55
|
+
if (reqOpts.body !== undefined)
|
|
56
|
+
headers["content-type"] = "application/json";
|
|
57
|
+
if (options.token)
|
|
58
|
+
headers.authorization = `Bearer ${options.token}`;
|
|
59
|
+
const response = await fetchFn(`${baseUrl}${path}`, {
|
|
60
|
+
method: reqOpts.method ?? "GET",
|
|
61
|
+
headers,
|
|
62
|
+
body: reqOpts.body !== undefined ? JSON.stringify(reqOpts.body) : undefined,
|
|
63
|
+
signal: reqOpts.signal
|
|
64
|
+
});
|
|
65
|
+
if (!response.ok) {
|
|
66
|
+
const errorBody = await response.json().catch(() => null);
|
|
67
|
+
const message = readErrorMessage(errorBody, response.status);
|
|
68
|
+
throw new PstdioApiError(message, response.status);
|
|
69
|
+
}
|
|
70
|
+
if (response.status === 204)
|
|
71
|
+
return;
|
|
72
|
+
return response.json();
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// src/client/sessions.ts
|
|
77
|
+
var createSessionClient = (request) => ({
|
|
78
|
+
list: (projectId) => request(`/v1/sessions?project_id=${projectId}`),
|
|
79
|
+
get: (sessionId) => request(`/v1/sessions/${sessionId}`),
|
|
80
|
+
create: (input) => request("/v1/sessions", { method: "POST", body: input }),
|
|
81
|
+
archive: (sessionId) => request(`/v1/sessions/${sessionId}/archive`, { method: "POST" }),
|
|
82
|
+
followUp: (sessionId, input) => request(`/v1/sessions/${sessionId}/follow-up`, { method: "POST", body: input }),
|
|
83
|
+
approve: (sessionId, input) => request(`/v1/sessions/${sessionId}/approve`, { method: "POST", body: input }),
|
|
84
|
+
getConversation: (sessionId) => request(`/v1/sessions/${sessionId}/conversation`),
|
|
85
|
+
resolveSessionId: (input) => request("/v1/sessions/resolve-session-id", { method: "POST", body: input }),
|
|
86
|
+
updateStatus: (sessionId, status) => request(`/v1/sessions/${sessionId}/status`, { method: "PATCH", body: { status } })
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// src/client/skills.ts
|
|
90
|
+
var createSkillClient = (request) => ({
|
|
91
|
+
list: (projectId) => request(`/v1/projects/${projectId}/skills`),
|
|
92
|
+
get: (projectId, skillId) => request(`/v1/projects/${projectId}/skills/${skillId}`),
|
|
93
|
+
update: (projectId, skillName) => request(`/v1/projects/${projectId}/skills/${skillName}/update`, { method: "POST" })
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// src/client/statuses.ts
|
|
97
|
+
var createStatusClient = (request) => ({
|
|
98
|
+
list: (projectId) => request(`/v1/projects/${projectId}/statuses`),
|
|
99
|
+
create: (projectId, input) => request(`/v1/projects/${projectId}/statuses`, { method: "POST", body: input }),
|
|
100
|
+
update: (projectId, statusId, input) => request(`/v1/projects/${projectId}/statuses/${statusId}`, { method: "PATCH", body: input }),
|
|
101
|
+
setDefault: (projectId, statusId) => request(`/v1/projects/${projectId}/statuses/${statusId}/set-default`, { method: "PATCH" }),
|
|
102
|
+
delete: (projectId, statusId) => request(`/v1/projects/${projectId}/statuses/${statusId}`, { method: "DELETE" }),
|
|
103
|
+
listAttemptStatuses: (projectId) => request(`/v1/projects/${projectId}/attempt-statuses`),
|
|
104
|
+
createAttemptStatus: (projectId, input) => request(`/v1/projects/${projectId}/attempt-statuses`, { method: "POST", body: input }),
|
|
105
|
+
updateAttemptStatus: (projectId, statusId, input) => request(`/v1/projects/${projectId}/attempt-statuses/${statusId}`, { method: "PATCH", body: input }),
|
|
106
|
+
deleteAttemptStatus: (projectId, statusId) => request(`/v1/projects/${projectId}/attempt-statuses/${statusId}`, { method: "DELETE" })
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// src/client/tags.ts
|
|
110
|
+
var createTagClient = (request) => ({
|
|
111
|
+
list: (projectId) => request(`/v1/projects/${projectId}/ticket-tags`),
|
|
112
|
+
create: (projectId, input) => request(`/v1/projects/${projectId}/ticket-tags`, { method: "POST", body: input }),
|
|
113
|
+
update: (projectId, tagId, input) => request(`/v1/projects/${projectId}/ticket-tags/${tagId}`, { method: "PATCH", body: input }),
|
|
114
|
+
delete: (projectId, tagId) => request(`/v1/projects/${projectId}/ticket-tags/${tagId}`, { method: "DELETE" }),
|
|
115
|
+
createOption: (projectId, tagId, input) => request(`/v1/projects/${projectId}/ticket-tags/${tagId}/options`, { method: "POST", body: input }),
|
|
116
|
+
updateOption: (projectId, tagId, optionId, input) => request(`/v1/projects/${projectId}/ticket-tags/${tagId}/options/${optionId}`, { method: "PATCH", body: input }),
|
|
117
|
+
deleteOption: (projectId, tagId, optionId) => request(`/v1/projects/${projectId}/ticket-tags/${tagId}/options/${optionId}`, { method: "DELETE" })
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// src/client/templates.ts
|
|
121
|
+
var createTemplateClient = (request) => ({
|
|
122
|
+
list: (projectId) => request(`/v1/projects/${projectId}/templates`),
|
|
123
|
+
get: (projectId, templateId) => request(`/v1/projects/${projectId}/templates/${templateId}`),
|
|
124
|
+
create: (projectId, input) => request(`/v1/projects/${projectId}/templates`, { method: "POST", body: input }),
|
|
125
|
+
update: (projectId, templateId, input) => request(`/v1/projects/${projectId}/templates/${templateId}`, { method: "PUT", body: input }),
|
|
126
|
+
delete: (projectId, templateId) => request(`/v1/projects/${projectId}/templates/${templateId}`, { method: "DELETE" })
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// src/client/tickets.ts
|
|
130
|
+
var resolveBaseUrl = (options) => options.baseUrl ?? (typeof process !== "undefined" ? process.env.PSTDIO_API_URL : undefined) ?? "http://localhost:19840";
|
|
131
|
+
var readErrorMessage2 = async (response) => {
|
|
132
|
+
const errorBody = await response.json().catch(() => null);
|
|
133
|
+
if (errorBody && typeof errorBody === "object" && errorBody !== null && "error" in errorBody) {
|
|
134
|
+
return String(errorBody.error);
|
|
135
|
+
}
|
|
136
|
+
return `Request failed: ${response.status}`;
|
|
137
|
+
};
|
|
138
|
+
var buildTicketsQuery = (projectId, input = {}) => {
|
|
139
|
+
const params = new URLSearchParams({ project_id: projectId });
|
|
140
|
+
if (input.status)
|
|
141
|
+
params.append("status", input.status);
|
|
142
|
+
if (Array.isArray(input.tag)) {
|
|
143
|
+
for (const tag of input.tag)
|
|
144
|
+
params.append("tag", tag);
|
|
145
|
+
} else if (input.tag) {
|
|
146
|
+
params.append("tag", input.tag);
|
|
147
|
+
}
|
|
148
|
+
if (input.archived !== undefined)
|
|
149
|
+
params.append("archived", String(input.archived));
|
|
150
|
+
if (input.draft !== undefined)
|
|
151
|
+
params.append("draft", String(input.draft));
|
|
152
|
+
if (input.parent_id)
|
|
153
|
+
params.append("parent_id", input.parent_id);
|
|
154
|
+
if (input.shorthand)
|
|
155
|
+
params.append("shorthand", input.shorthand);
|
|
156
|
+
if (input.search)
|
|
157
|
+
params.append("search", input.search);
|
|
158
|
+
return params.toString();
|
|
159
|
+
};
|
|
160
|
+
var createTicketClient = (request, options = {}) => ({
|
|
161
|
+
list: (projectId, input) => request(`/v1/tickets?${buildTicketsQuery(projectId, input)}`),
|
|
162
|
+
get: (ticketId) => request(`/v1/tickets/${ticketId}`),
|
|
163
|
+
create: (input) => request("/v1/tickets", { method: "POST", body: input }),
|
|
164
|
+
update: (ticketId, input) => request(`/v1/tickets/${ticketId}`, { method: "PATCH", body: input }),
|
|
165
|
+
delete: (ticketId) => request(`/v1/tickets/${ticketId}`, { method: "DELETE" }),
|
|
166
|
+
createAttempt: (ticketId, input) => request(`/v1/tickets/${ticketId}/attempts`, { method: "POST", body: input }),
|
|
167
|
+
updateWhenAttemptStatus: (ticketId, input) => request(`/v1/tickets/${ticketId}/update-when-attempt-status`, { method: "POST", body: input }),
|
|
168
|
+
listFiles: (ticketId) => request(`/v1/tickets/${ticketId}/files`),
|
|
169
|
+
getFileContent: async (ticketId, fileId) => {
|
|
170
|
+
const baseUrl = resolveBaseUrl(options);
|
|
171
|
+
const fetchFn = options.fetch ?? globalThis.fetch;
|
|
172
|
+
const headers = {};
|
|
173
|
+
if (options.token)
|
|
174
|
+
headers.authorization = `Bearer ${options.token}`;
|
|
175
|
+
const response = await fetchFn(`${baseUrl}/v1/tickets/${encodeURIComponent(ticketId)}/files/${encodeURIComponent(fileId)}/content`, { headers });
|
|
176
|
+
if (!response.ok) {
|
|
177
|
+
throw new PstdioApiError(await readErrorMessage2(response), response.status);
|
|
178
|
+
}
|
|
179
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
180
|
+
},
|
|
181
|
+
uploadFile: (ticketId, input) => request(`/v1/tickets/${ticketId}/files`, { method: "POST", body: input }),
|
|
182
|
+
deleteFile: (ticketId, fileId) => request(`/v1/tickets/${ticketId}/files/${fileId}`, { method: "DELETE" })
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// src/client/workspaces.ts
|
|
186
|
+
var createWorkspaceClient = (request) => ({
|
|
187
|
+
list: (projectId) => request(`/v1/workspaces?project_id=${projectId}`),
|
|
188
|
+
getByShorthand: (projectId, shorthand) => request(`/v1/workspaces/by-shorthand?project_id=${encodeURIComponent(projectId)}&shorthand=${encodeURIComponent(shorthand)}`),
|
|
189
|
+
create: (input) => request("/v1/workspaces", { method: "POST", body: input }),
|
|
190
|
+
updateAttemptStatus: (workspaceId, input) => request(`/v1/workspaces/${workspaceId}/attempt-status`, { method: "PATCH", body: input }),
|
|
191
|
+
removeWorktree: (workspaceId) => request(`/v1/workspaces/${workspaceId}/remove-worktree`, { method: "POST" }),
|
|
192
|
+
delete: (workspaceId) => request(`/v1/workspaces/${workspaceId}`, { method: "DELETE" })
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
// src/client/client.ts
|
|
196
|
+
var createClient = (options = {}) => {
|
|
197
|
+
const request = createRequest(options);
|
|
198
|
+
return {
|
|
199
|
+
projects: createProjectClient(request),
|
|
200
|
+
tickets: createTicketClient(request, options),
|
|
201
|
+
workspaces: createWorkspaceClient(request),
|
|
202
|
+
sessions: createSessionClient(request),
|
|
203
|
+
statuses: createStatusClient(request),
|
|
204
|
+
tags: createTagClient(request),
|
|
205
|
+
templates: createTemplateClient(request),
|
|
206
|
+
skills: createSkillClient(request),
|
|
207
|
+
agents: createAgentClient(request),
|
|
208
|
+
actions: createActionClient(request)
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
export {
|
|
212
|
+
createRequest,
|
|
213
|
+
createClient,
|
|
214
|
+
PstdioApiError
|
|
215
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CreateProjectInput, RegisterRepoInput, Repo } from "pstdio-api-contracts";
|
|
2
|
+
import type { Project } from "../resources";
|
|
3
|
+
import type { RequestFn } from "./request";
|
|
4
|
+
export type ProjectClient = {
|
|
5
|
+
list(): Promise<Project[]>;
|
|
6
|
+
get(projectId: string): Promise<Project>;
|
|
7
|
+
create(input: CreateProjectInput): Promise<Project>;
|
|
8
|
+
delete(projectId: string): Promise<void>;
|
|
9
|
+
listRepos(projectId: string): Promise<Repo[]>;
|
|
10
|
+
registerRepo(projectId: string, input: RegisterRepoInput): Promise<Repo>;
|
|
11
|
+
removeRepo(projectId: string, repoId: string): Promise<void>;
|
|
12
|
+
};
|
|
13
|
+
export declare const createProjectClient: (request: RequestFn) => ProjectClient;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type ClientOptions = {
|
|
2
|
+
baseUrl?: string;
|
|
3
|
+
token?: string;
|
|
4
|
+
fetch?: typeof fetch;
|
|
5
|
+
};
|
|
6
|
+
export declare class PstdioApiError extends Error {
|
|
7
|
+
status: number;
|
|
8
|
+
constructor(message: string, status: number);
|
|
9
|
+
}
|
|
10
|
+
export type RequestOptions = {
|
|
11
|
+
method?: string;
|
|
12
|
+
body?: unknown;
|
|
13
|
+
signal?: AbortSignal;
|
|
14
|
+
};
|
|
15
|
+
export type RequestFn = <T>(path: string, options?: RequestOptions) => Promise<T>;
|
|
16
|
+
export declare const createRequest: (options: ClientOptions) => RequestFn;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ApprovalInput, CreateSessionInput, FollowUpInput, ResolveSessionIdInput, ResolveSessionIdResponse, SessionConversationResponse } from "pstdio-api-contracts";
|
|
2
|
+
import type { Session } from "../resources";
|
|
3
|
+
import type { RequestFn } from "./request";
|
|
4
|
+
export type SessionClient = {
|
|
5
|
+
list(projectId: string): Promise<Session[]>;
|
|
6
|
+
get(sessionId: string): Promise<Session>;
|
|
7
|
+
create(input: CreateSessionInput): Promise<Session>;
|
|
8
|
+
archive(sessionId: string): Promise<void>;
|
|
9
|
+
followUp(sessionId: string, input: FollowUpInput): Promise<Session>;
|
|
10
|
+
approve(sessionId: string, input: ApprovalInput): Promise<void>;
|
|
11
|
+
getConversation(sessionId: string): Promise<SessionConversationResponse>;
|
|
12
|
+
resolveSessionId(input: ResolveSessionIdInput): Promise<ResolveSessionIdResponse>;
|
|
13
|
+
updateStatus(sessionId: string, status: string): Promise<Session>;
|
|
14
|
+
};
|
|
15
|
+
export declare const createSessionClient: (request: RequestFn) => SessionClient;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Skill, SkillWithContent } from "../resources";
|
|
2
|
+
import type { RequestFn } from "./request";
|
|
3
|
+
export type SkillClient = {
|
|
4
|
+
list(projectId: string): Promise<Skill[]>;
|
|
5
|
+
get(projectId: string, skillId: string): Promise<SkillWithContent>;
|
|
6
|
+
update(projectId: string, skillName: string): Promise<SkillWithContent>;
|
|
7
|
+
};
|
|
8
|
+
export declare const createSkillClient: (request: RequestFn) => SkillClient;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AttemptStatus, CreateAttemptStatusInput, CreateStatusInput } from "pstdio-api-contracts";
|
|
2
|
+
import type { Status } from "../resources";
|
|
3
|
+
import type { RequestFn } from "./request";
|
|
4
|
+
export type StatusClient = {
|
|
5
|
+
list(projectId: string): Promise<Status[]>;
|
|
6
|
+
create(projectId: string, input: CreateStatusInput): Promise<Status>;
|
|
7
|
+
update(projectId: string, statusId: string, input: {
|
|
8
|
+
color?: string;
|
|
9
|
+
}): Promise<Status>;
|
|
10
|
+
setDefault(projectId: string, statusId: string): Promise<void>;
|
|
11
|
+
delete(projectId: string, statusId: string): Promise<void>;
|
|
12
|
+
listAttemptStatuses(projectId: string): Promise<AttemptStatus[]>;
|
|
13
|
+
createAttemptStatus(projectId: string, input: CreateAttemptStatusInput): Promise<AttemptStatus>;
|
|
14
|
+
updateAttemptStatus(projectId: string, statusId: string, input: {
|
|
15
|
+
name?: string;
|
|
16
|
+
color?: string;
|
|
17
|
+
sort_order?: number;
|
|
18
|
+
is_default?: boolean;
|
|
19
|
+
}): Promise<AttemptStatus>;
|
|
20
|
+
deleteAttemptStatus(projectId: string, statusId: string): Promise<void>;
|
|
21
|
+
};
|
|
22
|
+
export declare const createStatusClient: (request: RequestFn) => StatusClient;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CreateTagInput, CreateTagOptionInput, UpdateTagInput, UpdateTagOptionInput } from "../api/tags";
|
|
2
|
+
import type { Tag, TagOption } from "../resources";
|
|
3
|
+
import type { RequestFn } from "./request";
|
|
4
|
+
export type TagClient = {
|
|
5
|
+
list(projectId: string): Promise<Tag[]>;
|
|
6
|
+
create(projectId: string, input: CreateTagInput): Promise<Tag>;
|
|
7
|
+
update(projectId: string, tagId: string, input: UpdateTagInput): Promise<Tag>;
|
|
8
|
+
delete(projectId: string, tagId: string): Promise<void>;
|
|
9
|
+
createOption(projectId: string, tagId: string, input: CreateTagOptionInput): Promise<TagOption>;
|
|
10
|
+
updateOption(projectId: string, tagId: string, optionId: string, input: UpdateTagOptionInput): Promise<TagOption>;
|
|
11
|
+
deleteOption(projectId: string, tagId: string, optionId: string): Promise<void>;
|
|
12
|
+
};
|
|
13
|
+
export declare const createTagClient: (request: RequestFn) => TagClient;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CreateTemplateInput, UpdateTemplateInput } from "../api/templates";
|
|
2
|
+
import type { Template, TemplateWithContent } from "../resources";
|
|
3
|
+
import type { RequestFn } from "./request";
|
|
4
|
+
export type TemplateClient = {
|
|
5
|
+
list(projectId: string): Promise<Template[]>;
|
|
6
|
+
get(projectId: string, templateId: string): Promise<TemplateWithContent>;
|
|
7
|
+
create(projectId: string, input: CreateTemplateInput): Promise<Template>;
|
|
8
|
+
update(projectId: string, templateId: string, input: UpdateTemplateInput): Promise<Template>;
|
|
9
|
+
delete(projectId: string, templateId: string): Promise<void>;
|
|
10
|
+
};
|
|
11
|
+
export declare const createTemplateClient: (request: RequestFn) => TemplateClient;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { CreateTicketAttemptInput, CreateTicketInput, ListTicketsInput, TicketAttemptResponse, UpdateTicketInput, UpdateWhenAttemptStatusInput, UpdateWhenAttemptStatusResponse, UploadTicketFileInput } from "../api/tickets";
|
|
2
|
+
import type { Ticket, TicketDetail, TicketFile, TicketListItem } from "../resources";
|
|
3
|
+
import { type ClientOptions, type RequestFn } from "./request";
|
|
4
|
+
export type TicketClient = {
|
|
5
|
+
list(projectId: string, input?: ListTicketsInput): Promise<TicketListItem[]>;
|
|
6
|
+
get(ticketId: string): Promise<TicketDetail>;
|
|
7
|
+
create(input: CreateTicketInput): Promise<Ticket>;
|
|
8
|
+
update(ticketId: string, input: UpdateTicketInput): Promise<Ticket>;
|
|
9
|
+
delete(ticketId: string): Promise<void>;
|
|
10
|
+
createAttempt(ticketId: string, input: CreateTicketAttemptInput): Promise<TicketAttemptResponse>;
|
|
11
|
+
updateWhenAttemptStatus(ticketId: string, input: UpdateWhenAttemptStatusInput): Promise<UpdateWhenAttemptStatusResponse>;
|
|
12
|
+
listFiles(ticketId: string): Promise<TicketFile[]>;
|
|
13
|
+
getFileContent(ticketId: string, fileId: string): Promise<Uint8Array>;
|
|
14
|
+
uploadFile(ticketId: string, input: UploadTicketFileInput): Promise<TicketFile>;
|
|
15
|
+
deleteFile(ticketId: string, fileId: string): Promise<void>;
|
|
16
|
+
};
|
|
17
|
+
export declare const createTicketClient: (request: RequestFn, options?: ClientOptions) => TicketClient;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CreateWorkspaceInput, RemoveWorktreeResponse, UpdateAttemptStatusInput, UpdateAttemptStatusResponse } from "pstdio-api-contracts";
|
|
2
|
+
import type { Workspace, WorkspaceListItem } from "../resources";
|
|
3
|
+
import type { RequestFn } from "./request";
|
|
4
|
+
export type WorkspaceClient = {
|
|
5
|
+
list(projectId: string): Promise<WorkspaceListItem[]>;
|
|
6
|
+
getByShorthand(projectId: string, shorthand: string): Promise<Workspace>;
|
|
7
|
+
create(input: CreateWorkspaceInput): Promise<Workspace>;
|
|
8
|
+
updateAttemptStatus(workspaceId: string, input: UpdateAttemptStatusInput): Promise<UpdateAttemptStatusResponse>;
|
|
9
|
+
removeWorktree(workspaceId: string): Promise<RemoveWorktreeResponse>;
|
|
10
|
+
delete(workspaceId: string): Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
export declare const createWorkspaceClient: (request: RequestFn) => WorkspaceClient;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { BaseHookContext } from "./base";
|
|
2
|
+
import type { HookTicket, HookWorkspace } from "./entities";
|
|
3
|
+
export type AttemptStatusChangeContext = BaseHookContext & {
|
|
4
|
+
workspace: HookWorkspace;
|
|
5
|
+
workspaceId: string;
|
|
6
|
+
prompts: Record<string, string>;
|
|
7
|
+
ticket?: HookTicket;
|
|
8
|
+
worktreePath?: string;
|
|
9
|
+
branch?: string;
|
|
10
|
+
fromStatus: string;
|
|
11
|
+
toStatus: string;
|
|
12
|
+
sessionId?: string;
|
|
13
|
+
originalSessionId?: string;
|
|
14
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { FollowUpInput } from "../api/sessions";
|
|
2
|
+
import type { PstdioClient } from "../client";
|
|
3
|
+
import type { Session } from "../resources";
|
|
4
|
+
export type SessionFollowupInput = Omit<FollowUpInput, "template" | "vars">;
|
|
5
|
+
type HookSessionClient = {
|
|
6
|
+
followup(input: SessionFollowupInput): Promise<Session>;
|
|
7
|
+
};
|
|
8
|
+
export type HookClient = PstdioClient & {
|
|
9
|
+
session: HookSessionClient;
|
|
10
|
+
};
|
|
11
|
+
export type HookPayload = Record<string, unknown>;
|
|
12
|
+
export type BaseHookContext = {
|
|
13
|
+
client: HookClient;
|
|
14
|
+
projectId: string;
|
|
15
|
+
payload?: HookPayload;
|
|
16
|
+
};
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { AttemptStatusChangeContext } from "./attempt";
|
|
2
|
+
export type { BaseHookContext, HookClient, HookPayload, SessionFollowupInput } from "./base";
|
|
3
|
+
export type { SessionHookContext } from "./session";
|
|
4
|
+
export type { TicketContext, TicketCreationContext, TicketStatusChangeContext } from "./ticket";
|
|
5
|
+
export type { WorktreeContext, WorktreeCreateContext } from "./worktree";
|
|
File without changes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { BaseHookContext } from "./base";
|
|
2
|
+
import type { HookTicket, HookWorkspace } from "./entities";
|
|
3
|
+
export type SessionHookContext = BaseHookContext & {
|
|
4
|
+
sessionId: string;
|
|
5
|
+
sessionStatus: "in_progress" | "awaiting_input" | "completed" | "failed" | "cancelled";
|
|
6
|
+
originalSessionId?: string;
|
|
7
|
+
workspace?: HookWorkspace;
|
|
8
|
+
workspaceId?: string;
|
|
9
|
+
worktreePath?: string;
|
|
10
|
+
branch?: string;
|
|
11
|
+
ticket?: HookTicket;
|
|
12
|
+
attemptStatus?: string;
|
|
13
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { BaseHookContext } from "./base";
|
|
2
|
+
export type TicketContext = BaseHookContext & {
|
|
3
|
+
id: string;
|
|
4
|
+
shorthand: string;
|
|
5
|
+
displayTitle: string | null;
|
|
6
|
+
userPrompt: string | null;
|
|
7
|
+
parentId: string | null;
|
|
8
|
+
draft: boolean;
|
|
9
|
+
archived: boolean;
|
|
10
|
+
status: string | null;
|
|
11
|
+
tagIds: string[];
|
|
12
|
+
tagNames: string[];
|
|
13
|
+
fileIds: string[];
|
|
14
|
+
};
|
|
15
|
+
export type TicketCreationContext = Omit<TicketContext, "id" | "shorthand"> & {
|
|
16
|
+
id: null;
|
|
17
|
+
shorthand: null;
|
|
18
|
+
content: string | null;
|
|
19
|
+
};
|
|
20
|
+
export type TicketStatusChangeContext = TicketContext & {
|
|
21
|
+
fromStatus: string | null;
|
|
22
|
+
toStatus: string | null;
|
|
23
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { BaseHookContext } from "./base";
|
|
2
|
+
export type WorktreeCreateContext = BaseHookContext & {
|
|
3
|
+
repoPath: string;
|
|
4
|
+
worktreePath: string;
|
|
5
|
+
branch: string;
|
|
6
|
+
workspace: string;
|
|
7
|
+
ticket: string;
|
|
8
|
+
base: string;
|
|
9
|
+
};
|
|
10
|
+
export type WorktreeContext = BaseHookContext & {
|
|
11
|
+
repoPath: string;
|
|
12
|
+
worktreePath: string;
|
|
13
|
+
branch: string;
|
|
14
|
+
workspace: string;
|
|
15
|
+
workspaceId: string;
|
|
16
|
+
ticket: string;
|
|
17
|
+
};
|
|
18
|
+
export type CommitContext = {
|
|
19
|
+
repoPath: string;
|
|
20
|
+
worktreePath: string;
|
|
21
|
+
commitMessage: string;
|
|
22
|
+
stagePolicy: string;
|
|
23
|
+
commitSha?: string;
|
|
24
|
+
};
|
|
25
|
+
export type RebaseContext = {
|
|
26
|
+
repoPath: string;
|
|
27
|
+
branch: string;
|
|
28
|
+
target: string;
|
|
29
|
+
};
|
|
30
|
+
export type MergeContext = {
|
|
31
|
+
repoPath: string;
|
|
32
|
+
branch: string;
|
|
33
|
+
target: string;
|
|
34
|
+
squash: boolean;
|
|
35
|
+
commitMessage: string | null;
|
|
36
|
+
commitSha?: string;
|
|
37
|
+
};
|
|
38
|
+
export type ConflictContext = {
|
|
39
|
+
repoPath: string;
|
|
40
|
+
branch: string;
|
|
41
|
+
target: string;
|
|
42
|
+
operation: "rebase" | "merge";
|
|
43
|
+
};
|
|
44
|
+
export type WorktreeRemoveContext = {
|
|
45
|
+
repoPath: string;
|
|
46
|
+
worktreePath: string | null;
|
|
47
|
+
branch: string;
|
|
48
|
+
workspace: string;
|
|
49
|
+
workspaceId: string;
|
|
50
|
+
ticket: string | null;
|
|
51
|
+
projectId: string;
|
|
52
|
+
};
|