Skip to content

Commit

Permalink
Support onprogress callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
jspahrsummers committed Nov 4, 2024
1 parent a9b6ae6 commit 12c9234
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
49 changes: 40 additions & 9 deletions src/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Protocol } from "../shared/protocol.js";
import { ProgressCallback, Protocol } from "../shared/protocol.js";
import { Transport } from "../shared/transport.js";
import {
ClientNotification,
Expand Down Expand Up @@ -126,10 +126,14 @@ export class Client<
return this.request({ method: "ping" }, EmptyResultSchema);
}

async complete(params: CompleteRequest["params"]) {
async complete(
params: CompleteRequest["params"],
onprogress?: ProgressCallback,
) {
return this.request(
{ method: "completion/complete", params },
CompleteResultSchema,
onprogress,
);
}

Expand All @@ -140,31 +144,47 @@ export class Client<
);
}

async getPrompt(params: GetPromptRequest["params"]) {
async getPrompt(
params: GetPromptRequest["params"],
onprogress?: ProgressCallback,
) {
return this.request(
{ method: "prompts/get", params },
GetPromptResultSchema,
onprogress,
);
}

async listPrompts(params?: ListPromptsRequest["params"]) {
async listPrompts(
params?: ListPromptsRequest["params"],
onprogress?: ProgressCallback,
) {
return this.request(
{ method: "prompts/list", params },
ListPromptsResultSchema,
onprogress,
);
}

async listResources(params?: ListResourcesRequest["params"]) {
async listResources(
params?: ListResourcesRequest["params"],
onprogress?: ProgressCallback,
) {
return this.request(
{ method: "resources/list", params },
ListResourcesResultSchema,
onprogress,
);
}

async readResource(params: ReadResourceRequest["params"]) {
async readResource(
params: ReadResourceRequest["params"],
onprogress?: ProgressCallback,
) {
return this.request(
{ method: "resources/read", params },
ReadResourceResultSchema,
onprogress,
);
}

Expand All @@ -182,14 +202,25 @@ export class Client<
);
}

async callTool(params: CallToolRequest["params"]) {
return this.request({ method: "tools/call", params }, CallToolResultSchema);
async callTool(
params: CallToolRequest["params"],
onprogress?: ProgressCallback,
) {
return this.request(
{ method: "tools/call", params },
CallToolResultSchema,
onprogress,
);
}

async listTools(params?: ListToolsRequest["params"]) {
async listTools(
params?: ListToolsRequest["params"],
onprogress?: ProgressCallback,
) {
return this.request(
{ method: "tools/list", params },
ListToolsResultSchema,
onprogress,
);
}
}
8 changes: 6 additions & 2 deletions src/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Protocol } from "../shared/protocol.js";
import { ProgressCallback, Protocol } from "../shared/protocol.js";
import {
ClientCapabilities,
Implementation,
Expand Down Expand Up @@ -143,10 +143,14 @@ export class Server<
return this.request({ method: "ping" }, EmptyResultSchema);
}

async createMessage(params: CreateMessageRequest["params"]) {
async createMessage(
params: CreateMessageRequest["params"],
onprogress?: ProgressCallback,
) {
return this.request(
{ method: "sampling/createMessage", params },
CreateMessageResultSchema,
onprogress,
);
}

Expand Down

0 comments on commit 12c9234

Please sign in to comment.