Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@polyscope/sdk",
"version": "0.1.0",
"version": "0.2.0",
"description": "Official Polyscope SDK for JavaScript and TypeScript",
"type": "module",
"main": "./dist/index.cjs",
Expand Down
39 changes: 30 additions & 9 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import { HttpClient } from "./http.js";
import { MissingApiTokenError } from "./errors.js";
import { previewUrlMatches, toPreviewLookupUrl } from "./url-matching.js";
import { ServerModels } from "./resources/models.js";
import { Repository } from "./resources/repository.js";
import { Server } from "./resources/server.js";
import { TeamInvite } from "./resources/team-invite.js";
import {
GenericResource,
Workspace,
toCreateWorkspaceBody,
} from "./resources/workspace.js";
import { resolveApiToken } from "./utils/settings.js";
import type {
CreateWorkspaceParams,
GenericResourceData,
ListModelsParams,
ListRepositoriesParams,
ListWorkspacesParams,
PolyscopeConfig,
RepositoryData,
ServerData,
ServerModelsData,
TeamInviteData,
WorkspaceData,
} from "./types.js";

Expand Down Expand Up @@ -88,6 +94,29 @@ export class Polyscope {
return response.data.map((s) => new Server(s));
}

async models(params?: ListModelsParams): Promise<ServerModels[]> {
const http = await this.getHttp();
const query: Record<string, string> = {};
if (params?.serverId) {
query.server_id = params.serverId;
}

const response = await http.get<{ data: ServerModelsData[] }>(
"models",
query,
);
return response.data.map((m) => new ServerModels(m));
}

async inviteTeamMember(email: string): Promise<TeamInvite> {
const http = await this.getHttp();
const response = await http.post<{ data: TeamInviteData }>(
"team/invites",
{ email },
);
return new TeamInvite(response.data);
}

// --- Repositories ---

async repositories(params?: ListRepositoriesParams): Promise<Repository[]> {
Expand All @@ -108,17 +137,9 @@ export class Polyscope {

async createWorkspace(params: CreateWorkspaceParams): Promise<Workspace> {
const http = await this.getHttp();
const body = {
repository_id: params.repositoryId,
prompt: params.prompt ?? undefined,
server_id: params.serverId ?? undefined,
issue_url: params.issueUrl ?? undefined,
pull_request_url: params.pullRequestUrl ?? undefined,
};

const response = await http.post<{ data: WorkspaceData }>(
"workspaces",
body,
toCreateWorkspaceBody(params),
);
return new Workspace(response.data, http);
}
Expand Down
2 changes: 1 addition & 1 deletion src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { ApiErrorResponse } from "./types.js";

const DEFAULT_BASE_URL = "https://getpolyscope.com";
const DEFAULT_TIMEOUT = 30_000;
const USER_AGENT = "Polyscope JS SDK/0.1";
const USER_AGENT = "Polyscope JS SDK/0.2";

export class HttpClient {
private apiToken: string;
Expand Down
11 changes: 11 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export {

export { Server } from "./resources/server.js";
export { Repository } from "./resources/repository.js";
export { ServerModels, AvailableAgent } from "./resources/models.js";
export { TeamInvite } from "./resources/team-invite.js";
export {
Workspace,
WorkspaceDiff,
Expand All @@ -31,16 +33,25 @@ export type {
ServerData,
RepositoryData,
WorkspaceData,
WorkspaceStatus,
InterfaceMode,
MessageData,
MessageRole,
DiffFileData,
DiffStatsData,
DiffSnapshotData,
WorkspaceDiffData,
GenericResourceData,
ServerModelsData,
AvailableAgentData,
ModelCapabilitiesData,
TeamInviteData,
CreateWorkspaceParams,
SendMessageParams,
CommitParams,
CreatePullRequestParams,
ListWorkspacesParams,
ListRepositoriesParams,
ListModelsParams,
PolyscopeConfig,
} from "./types.js";
44 changes: 44 additions & 0 deletions src/resources/models.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type {
AvailableAgentData,
ModelCapabilitiesData,
ServerModelsData,
} from "../types.js";

export class AvailableAgent {
readonly id: string;
readonly name: string;
readonly models: string[];

constructor(data: AvailableAgentData) {
this.id = data.id;
this.name = data.name;
this.models = data.models;
}
}

export class ServerModels {
readonly serverId: string;
readonly agents: AvailableAgent[];
readonly models: string[];
readonly modelCapabilities: ModelCapabilitiesData[];

constructor(data: ServerModelsData) {
this.serverId = data.server_id;
this.agents = data.agents.map((a) => new AvailableAgent(a));
this.models = data.models;
this.modelCapabilities = data.model_capabilities;
}

toJSON(): ServerModelsData {
return {
server_id: this.serverId,
agents: this.agents.map((a) => ({
id: a.id,
name: a.name,
models: a.models,
})),
models: this.models,
model_capabilities: this.modelCapabilities,
};
}
}
35 changes: 21 additions & 14 deletions src/resources/repository.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import type { HttpClient } from "../http.js";
import type { CreateWorkspaceParams, RepositoryData, WorkspaceData } from "../types.js";
import { Workspace } from "./workspace.js";
import { Workspace, toCreateWorkspaceBody } from "./workspace.js";

export class Repository {
readonly id: string;
readonly name: string;
readonly path: string;
readonly baseBranch: string;
readonly defaultModel: string | null;
readonly reviewModel: string | null;
readonly reviewPrompt: string | null;
readonly githubAssignSelfEnabled: boolean;
/** @deprecated No longer sent by the API, always `false`. Replaced by `githubAssignSelfEnabled`. */
readonly githubReactionEnabled: boolean;
/** @deprecated No longer sent by the API, always `null`. */
readonly githubReactionEmoji: string | null;
readonly mergePrompt: string | null;
readonly mergeAndPushPrompt: string | null;
readonly prPrompt: string | null;
readonly draftPrPrompt: string | null;
readonly worktreeBaseFromOrigin: boolean | null;
readonly hasRemote: boolean;
readonly nonGit: boolean;
readonly linkedRepoIds: string[];
readonly createdAt: string;
readonly serverId: string | null;
Expand All @@ -29,14 +35,18 @@ export class Repository {
this.path = data.path;
this.baseBranch = data.base_branch;
this.defaultModel = data.default_model;
this.githubReactionEnabled = data.github_reaction_enabled;
this.githubReactionEmoji = data.github_reaction_emoji;
this.reviewModel = data.review_model ?? null;
this.reviewPrompt = data.review_prompt ?? null;
this.githubAssignSelfEnabled = data.github_assign_self_enabled ?? false;
this.githubReactionEnabled = data.github_reaction_enabled ?? false;
this.githubReactionEmoji = data.github_reaction_emoji ?? null;
this.mergePrompt = data.merge_prompt;
this.mergeAndPushPrompt = data.merge_and_push_prompt;
this.prPrompt = data.pr_prompt;
this.draftPrPrompt = data.draft_pr_prompt;
this.worktreeBaseFromOrigin = data.worktree_base_from_origin;
this.hasRemote = data.has_remote;
this.nonGit = data.non_git ?? false;
this.linkedRepoIds = data.linked_repo_ids;
this.createdAt = data.created_at;
this.serverId = data.server_id;
Expand All @@ -46,16 +56,11 @@ export class Repository {
async createWorkspace(
params: Omit<CreateWorkspaceParams, "repositoryId"> | string,
): Promise<Workspace> {
const body =
const body = toCreateWorkspaceBody(
typeof params === "string"
? { repository_id: this.id, prompt: params }
: {
repository_id: this.id,
prompt: params.prompt ?? undefined,
server_id: params.serverId ?? undefined,
issue_url: params.issueUrl ?? undefined,
pull_request_url: params.pullRequestUrl ?? undefined,
};
? { repositoryId: this.id, prompt: params }
: { ...params, repositoryId: this.id },
);

const response = await this.http.post<{ data: WorkspaceData }>(
"workspaces",
Expand All @@ -71,14 +76,16 @@ export class Repository {
path: this.path,
base_branch: this.baseBranch,
default_model: this.defaultModel,
github_reaction_enabled: this.githubReactionEnabled,
github_reaction_emoji: this.githubReactionEmoji,
review_model: this.reviewModel,
review_prompt: this.reviewPrompt,
github_assign_self_enabled: this.githubAssignSelfEnabled,
merge_prompt: this.mergePrompt,
merge_and_push_prompt: this.mergeAndPushPrompt,
pr_prompt: this.prPrompt,
draft_pr_prompt: this.draftPrPrompt,
worktree_base_from_origin: this.worktreeBaseFromOrigin,
has_remote: this.hasRemote,
non_git: this.nonGit,
linked_repo_ids: this.linkedRepoIds,
created_at: this.createdAt,
server_id: this.serverId,
Expand Down
11 changes: 11 additions & 0 deletions src/resources/team-invite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { TeamInviteData } from "../types.js";

export class TeamInvite {
readonly email: string;
readonly invited: boolean;

constructor(data: TeamInviteData) {
this.email = data.email;
this.invited = data.invited;
}
}
Loading
Loading