Open History to see the last commit
1/**
2 * CursorAdapter - Cursor ACP implementation of the generic provider adapter contract.
3 *
4 * Defines ACP JSON-RPC schemas used by the Cursor adapter layer.
5 *
6 * @module CursorAdapter
7 */
8import { Schema, ServiceMap } from "effect";
9
10import type { ProviderAdapterError } from "../Errors.ts";
11import type { ProviderAdapterShape } from "./ProviderAdapter.ts";
12
13export const CursorAcpJsonRpcId = Schema.Union([Schema.String, Schema.Int]);
14export type CursorAcpJsonRpcId = typeof CursorAcpJsonRpcId.Type;
15
16export const CursorAcpTextContent = Schema.Struct({
17 type: Schema.Literal("text"),
18 text: Schema.String,
19});
20export type CursorAcpTextContent = typeof CursorAcpTextContent.Type;
21
22export const CursorAcpSessionUpdate = Schema.Union([
23 Schema.Struct({
24 sessionUpdate: Schema.Literal("available_commands_update"),
25 availableCommands: Schema.Array(
26 Schema.Struct({
27 name: Schema.String,
28 description: Schema.optional(Schema.String),
29 }),
30 ),
31 }),
32 Schema.Struct({
33 sessionUpdate: Schema.Literal("agent_thought_chunk"),
34 content: CursorAcpTextContent,
35 }),
36 Schema.Struct({
37 sessionUpdate: Schema.Literal("agent_message_chunk"),
38 content: CursorAcpTextContent,
39 }),
40 Schema.Struct({
41 sessionUpdate: Schema.Literal("tool_call"),
42 toolCallId: Schema.String,
43 title: Schema.optional(Schema.String),
44 kind: Schema.optional(Schema.String),
45 status: Schema.optional(Schema.String),
46 rawInput: Schema.optional(Schema.Unknown),
47 }),
48 Schema.Struct({
49 sessionUpdate: Schema.Literal("tool_call_update"),
50 toolCallId: Schema.String,
51 status: Schema.String,
52 rawOutput: Schema.optional(Schema.Unknown),
53 }),
54]);
55export type CursorAcpSessionUpdate = typeof CursorAcpSessionUpdate.Type;
56
57export const CursorAcpSessionUpdateNotification = Schema.Struct({
58 jsonrpc: Schema.optional(Schema.Literal("2.0")),
59 method: Schema.Literal("session/update"),
60 params: Schema.Struct({
61 sessionId: Schema.String,
62 update: CursorAcpSessionUpdate,
63 }),
64});
65export type CursorAcpSessionUpdateNotification = typeof CursorAcpSessionUpdateNotification.Type;
66
67export const CursorAcpPermissionOption = Schema.Struct({
68 optionId: Schema.String,
69 name: Schema.optional(Schema.String),
70 kind: Schema.optional(Schema.String),
71});
72export type CursorAcpPermissionOption = typeof CursorAcpPermissionOption.Type;
73
74export const CursorAcpPermissionRequest = Schema.Struct({
75 jsonrpc: Schema.optional(Schema.Literal("2.0")),
76 id: CursorAcpJsonRpcId,
77 method: Schema.Literal("session/request_permission"),
78 params: Schema.Struct({
79 sessionId: Schema.String,
80 toolCall: Schema.optional(Schema.Unknown),
81 options: Schema.Array(CursorAcpPermissionOption),
82 }),
83});
84export type CursorAcpPermissionRequest = typeof CursorAcpPermissionRequest.Type;
85
86export const CursorAcpInitializeResult = Schema.Struct({
87 protocolVersion: Schema.optional(Schema.Int),
88 agentCapabilities: Schema.optional(Schema.Unknown),
89 authMethods: Schema.optional(Schema.Array(Schema.Unknown)),
90});
91export type CursorAcpInitializeResult = typeof CursorAcpInitializeResult.Type;
92
93export const CursorAcpSessionNewResult = Schema.Struct({
94 sessionId: Schema.String,
95 modes: Schema.optional(Schema.Unknown),
96});
97export type CursorAcpSessionNewResult = typeof CursorAcpSessionNewResult.Type;
98
99export const CursorAcpSessionPromptResult = Schema.Struct({
100 stopReason: Schema.optional(Schema.String),
101});
102export type CursorAcpSessionPromptResult = typeof CursorAcpSessionPromptResult.Type;
103
104export interface CursorAdapterShape extends ProviderAdapterShape<ProviderAdapterError> {
105 readonly provider: "cursor";
106}
107
108export class CursorAdapter extends ServiceMap.Service<CursorAdapter, CursorAdapterShape>()(
109 "t3/provider/Services/CursorAdapter",
110) {}