@playwo/opencode-cursor-oauth 0.0.0-dev.e3644b4a140d → 0.0.0-dev.e95256212849
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/auth.js +1 -2
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +2 -0
- package/dist/cursor/bidi-session.d.ts +12 -0
- package/dist/cursor/bidi-session.js +164 -0
- package/dist/cursor/config.d.ts +4 -0
- package/dist/cursor/config.js +4 -0
- package/dist/cursor/connect-framing.d.ts +10 -0
- package/dist/cursor/connect-framing.js +80 -0
- package/dist/cursor/headers.d.ts +6 -0
- package/dist/cursor/headers.js +16 -0
- package/dist/cursor/index.d.ts +5 -0
- package/dist/cursor/index.js +5 -0
- package/dist/cursor/unary-rpc.d.ts +12 -0
- package/dist/cursor/unary-rpc.js +124 -0
- package/dist/index.d.ts +2 -14
- package/dist/index.js +2 -306
- package/dist/logger.js +7 -2
- package/dist/models.js +1 -23
- package/dist/openai/index.d.ts +3 -0
- package/dist/openai/index.js +3 -0
- package/dist/openai/messages.d.ts +39 -0
- package/dist/openai/messages.js +228 -0
- package/dist/openai/tools.d.ts +7 -0
- package/dist/openai/tools.js +58 -0
- package/dist/openai/types.d.ts +41 -0
- package/dist/openai/types.js +1 -0
- package/dist/plugin/cursor-auth-plugin.d.ts +3 -0
- package/dist/plugin/cursor-auth-plugin.js +139 -0
- package/dist/proto/agent_pb.js +637 -319
- package/dist/provider/index.d.ts +2 -0
- package/dist/provider/index.js +2 -0
- package/dist/provider/model-cost.d.ts +9 -0
- package/dist/provider/model-cost.js +206 -0
- package/dist/provider/models.d.ts +8 -0
- package/dist/provider/models.js +86 -0
- package/dist/proxy/bridge-non-streaming.d.ts +3 -0
- package/dist/proxy/bridge-non-streaming.js +119 -0
- package/dist/proxy/bridge-session.d.ts +5 -0
- package/dist/proxy/bridge-session.js +11 -0
- package/dist/proxy/bridge-streaming.d.ts +5 -0
- package/dist/proxy/bridge-streaming.js +342 -0
- package/dist/proxy/bridge.d.ts +3 -0
- package/dist/proxy/bridge.js +3 -0
- package/dist/proxy/chat-completion.d.ts +2 -0
- package/dist/proxy/chat-completion.js +114 -0
- package/dist/proxy/conversation-meta.d.ts +12 -0
- package/dist/proxy/conversation-meta.js +1 -0
- package/dist/proxy/conversation-state.d.ts +35 -0
- package/dist/proxy/conversation-state.js +95 -0
- package/dist/proxy/cursor-request.d.ts +6 -0
- package/dist/proxy/cursor-request.js +104 -0
- package/dist/proxy/index.d.ts +12 -0
- package/dist/proxy/index.js +12 -0
- package/dist/proxy/server.d.ts +6 -0
- package/dist/proxy/server.js +107 -0
- package/dist/proxy/sse.d.ts +5 -0
- package/dist/proxy/sse.js +5 -0
- package/dist/proxy/state-sync.d.ts +2 -0
- package/dist/proxy/state-sync.js +17 -0
- package/dist/proxy/stream-dispatch.d.ts +42 -0
- package/dist/proxy/stream-dispatch.js +614 -0
- package/dist/proxy/stream-state.d.ts +9 -0
- package/dist/proxy/stream-state.js +1 -0
- package/dist/proxy/title.d.ts +1 -0
- package/dist/proxy/title.js +103 -0
- package/dist/proxy/types.d.ts +27 -0
- package/dist/proxy/types.js +1 -0
- package/dist/proxy.d.ts +2 -20
- package/dist/proxy.js +2 -1689
- package/package.json +1 -1
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { create, fromBinary, toBinary } from "@bufbuild/protobuf";
|
|
2
|
+
import { NameAgentRequestSchema, NameAgentResponseSchema, } from "../proto/agent_pb";
|
|
3
|
+
import { callCursorUnaryRpc, decodeConnectUnaryBody } from "../cursor";
|
|
4
|
+
import { SSE_HEADERS } from "./sse";
|
|
5
|
+
function deriveFallbackTitle(text) {
|
|
6
|
+
const cleaned = text
|
|
7
|
+
.replace(/<[^>]+>/g, " ")
|
|
8
|
+
.replace(/\[[^\]]+\]/g, " ")
|
|
9
|
+
.replace(/[^\p{L}\p{N}'’\-\s]+/gu, " ")
|
|
10
|
+
.replace(/\s+/g, " ")
|
|
11
|
+
.trim();
|
|
12
|
+
if (!cleaned)
|
|
13
|
+
return "";
|
|
14
|
+
const words = cleaned.split(" ").filter(Boolean).slice(0, 6);
|
|
15
|
+
return finalizeTitle(words.map(titleCaseWord).join(" "));
|
|
16
|
+
}
|
|
17
|
+
function titleCaseWord(word) {
|
|
18
|
+
if (!word)
|
|
19
|
+
return word;
|
|
20
|
+
return word[0].toUpperCase() + word.slice(1);
|
|
21
|
+
}
|
|
22
|
+
function finalizeTitle(value) {
|
|
23
|
+
return value
|
|
24
|
+
.replace(/^#{1,6}\s*/, "")
|
|
25
|
+
.replace(/[.!?,:;]+$/g, "")
|
|
26
|
+
.replace(/\s+/g, " ")
|
|
27
|
+
.trim()
|
|
28
|
+
.slice(0, 80)
|
|
29
|
+
.trim();
|
|
30
|
+
}
|
|
31
|
+
function createBufferedSSETextResponse(modelId, text, usage) {
|
|
32
|
+
const completionId = `chatcmpl-${crypto.randomUUID().replace(/-/g, "").slice(0, 28)}`;
|
|
33
|
+
const created = Math.floor(Date.now() / 1000);
|
|
34
|
+
const payload = [
|
|
35
|
+
{
|
|
36
|
+
id: completionId,
|
|
37
|
+
object: "chat.completion.chunk",
|
|
38
|
+
created,
|
|
39
|
+
model: modelId,
|
|
40
|
+
choices: [{ index: 0, delta: { content: text }, finish_reason: null }],
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
id: completionId,
|
|
44
|
+
object: "chat.completion.chunk",
|
|
45
|
+
created,
|
|
46
|
+
model: modelId,
|
|
47
|
+
choices: [{ index: 0, delta: {}, finish_reason: "stop" }],
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
id: completionId,
|
|
51
|
+
object: "chat.completion.chunk",
|
|
52
|
+
created,
|
|
53
|
+
model: modelId,
|
|
54
|
+
choices: [],
|
|
55
|
+
usage,
|
|
56
|
+
},
|
|
57
|
+
]
|
|
58
|
+
.map((chunk) => `data: ${JSON.stringify(chunk)}\n\n`)
|
|
59
|
+
.join("") + "data: [DONE]\n\n";
|
|
60
|
+
return new Response(payload, { headers: SSE_HEADERS });
|
|
61
|
+
}
|
|
62
|
+
export async function handleTitleGenerationRequest(sourceText, accessToken, modelId, stream) {
|
|
63
|
+
const requestBody = toBinary(NameAgentRequestSchema, create(NameAgentRequestSchema, {
|
|
64
|
+
userMessage: sourceText,
|
|
65
|
+
}));
|
|
66
|
+
const response = await callCursorUnaryRpc({
|
|
67
|
+
accessToken,
|
|
68
|
+
rpcPath: "/agent.v1.AgentService/NameAgent",
|
|
69
|
+
requestBody,
|
|
70
|
+
timeoutMs: 5_000,
|
|
71
|
+
});
|
|
72
|
+
if (response.timedOut) {
|
|
73
|
+
throw new Error("Cursor title generation timed out");
|
|
74
|
+
}
|
|
75
|
+
if (response.exitCode !== 0) {
|
|
76
|
+
throw new Error(`Cursor title generation failed with HTTP ${response.exitCode}`);
|
|
77
|
+
}
|
|
78
|
+
const payload = decodeConnectUnaryBody(response.body) ?? response.body;
|
|
79
|
+
const decoded = fromBinary(NameAgentResponseSchema, payload);
|
|
80
|
+
const title = finalizeTitle(decoded.name) ||
|
|
81
|
+
deriveFallbackTitle(sourceText) ||
|
|
82
|
+
"Untitled Session";
|
|
83
|
+
const usage = { prompt_tokens: 0, completion_tokens: 0, total_tokens: 0 };
|
|
84
|
+
if (stream) {
|
|
85
|
+
return createBufferedSSETextResponse(modelId, title, usage);
|
|
86
|
+
}
|
|
87
|
+
const completionId = `chatcmpl-${crypto.randomUUID().replace(/-/g, "").slice(0, 28)}`;
|
|
88
|
+
const created = Math.floor(Date.now() / 1000);
|
|
89
|
+
return new Response(JSON.stringify({
|
|
90
|
+
id: completionId,
|
|
91
|
+
object: "chat.completion",
|
|
92
|
+
created,
|
|
93
|
+
model: modelId,
|
|
94
|
+
choices: [
|
|
95
|
+
{
|
|
96
|
+
index: 0,
|
|
97
|
+
message: { role: "assistant", content: title },
|
|
98
|
+
finish_reason: "stop",
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
usage,
|
|
102
|
+
}), { headers: { "Content-Type": "application/json" } });
|
|
103
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { CursorSession } from "../cursor/bidi-session";
|
|
2
|
+
import type { ConversationRequestMetadata } from "./conversation-meta";
|
|
3
|
+
import type { McpToolDefinition } from "../proto/agent_pb";
|
|
4
|
+
export interface CursorRequestPayload {
|
|
5
|
+
requestBytes: Uint8Array;
|
|
6
|
+
blobStore: Map<string, Uint8Array>;
|
|
7
|
+
mcpTools: McpToolDefinition[];
|
|
8
|
+
}
|
|
9
|
+
/** A pending tool execution waiting for results from the caller. */
|
|
10
|
+
export interface PendingExec {
|
|
11
|
+
execId: string;
|
|
12
|
+
execMsgId: number;
|
|
13
|
+
toolCallId: string;
|
|
14
|
+
toolName: string;
|
|
15
|
+
/** Decoded arguments JSON string for SSE tool_calls emission. */
|
|
16
|
+
decodedArgs: string;
|
|
17
|
+
}
|
|
18
|
+
/** A live Cursor session kept alive across requests for tool result continuation. */
|
|
19
|
+
export interface ActiveBridge {
|
|
20
|
+
bridge: CursorSession;
|
|
21
|
+
heartbeatTimer: NodeJS.Timeout;
|
|
22
|
+
blobStore: Map<string, Uint8Array>;
|
|
23
|
+
mcpTools: McpToolDefinition[];
|
|
24
|
+
pendingExecs: PendingExec[];
|
|
25
|
+
modelId: string;
|
|
26
|
+
metadata: ConversationRequestMetadata;
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/proxy.d.ts
CHANGED
|
@@ -1,20 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
rpcPath: string;
|
|
4
|
-
requestBody: Uint8Array;
|
|
5
|
-
url?: string;
|
|
6
|
-
timeoutMs?: number;
|
|
7
|
-
transport?: "auto" | "fetch" | "http2";
|
|
8
|
-
}
|
|
9
|
-
export declare function callCursorUnaryRpc(options: CursorUnaryRpcOptions): Promise<{
|
|
10
|
-
body: Uint8Array;
|
|
11
|
-
exitCode: number;
|
|
12
|
-
timedOut: boolean;
|
|
13
|
-
}>;
|
|
14
|
-
export declare function getProxyPort(): number | undefined;
|
|
15
|
-
export declare function startProxy(getAccessToken: () => Promise<string>, models?: ReadonlyArray<{
|
|
16
|
-
id: string;
|
|
17
|
-
name: string;
|
|
18
|
-
}>): Promise<number>;
|
|
19
|
-
export declare function stopProxy(): void;
|
|
20
|
-
export {};
|
|
1
|
+
export { getProxyPort, startProxy, stopProxy } from "./proxy/index";
|
|
2
|
+
export { callCursorUnaryRpc } from "./cursor";
|