@playwo/opencode-cursor-oauth 0.0.0-dev.2c48be2f48c9 → 0.0.0-dev.36e1216df6cf
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/README.md +33 -12
- package/dist/AGENTS.md +8 -0
- package/dist/agent-rules.d.ts +1 -0
- package/dist/agent-rules.js +28 -0
- package/dist/cursor/bidi-session.d.ts +1 -2
- package/dist/cursor/bidi-session.js +153 -138
- package/dist/cursor/index.d.ts +1 -1
- package/dist/cursor/index.js +1 -1
- package/dist/cursor/unary-rpc.d.ts +0 -1
- package/dist/cursor/unary-rpc.js +2 -59
- package/dist/logger.d.ts +1 -0
- package/dist/logger.js +3 -0
- package/dist/openai/messages.js +5 -0
- package/dist/plugin/cursor-auth-plugin.js +0 -1
- package/dist/proxy/bridge-close-controller.d.ts +6 -0
- package/dist/proxy/bridge-close-controller.js +37 -0
- package/dist/proxy/bridge-non-streaming.js +33 -3
- package/dist/proxy/bridge-session.js +1 -3
- package/dist/proxy/bridge-streaming.d.ts +1 -1
- package/dist/proxy/bridge-streaming.js +430 -64
- package/dist/proxy/chat-completion.js +44 -3
- package/dist/proxy/cursor-request.d.ts +1 -0
- package/dist/proxy/cursor-request.js +24 -8
- package/dist/proxy/server.js +23 -5
- package/dist/proxy/stream-dispatch.d.ts +17 -1
- package/dist/proxy/stream-dispatch.js +280 -12
- package/dist/proxy/types.d.ts +14 -1
- package/package.json +2 -3
|
@@ -5,6 +5,7 @@ import { updateStoredConversationAfterCompletion } from "./conversation-state";
|
|
|
5
5
|
import { startBridge } from "./bridge-session";
|
|
6
6
|
import { updateConversationCheckpoint, syncStoredBlobStore, } from "./state-sync";
|
|
7
7
|
import { computeUsage, createConnectFrameParser, createThinkingTagFilter, parseConnectEndStream, processServerMessage, scheduleBridgeEnd, } from "./stream-dispatch";
|
|
8
|
+
import { createBridgeCloseController } from "./bridge-close-controller";
|
|
8
9
|
export async function handleNonStreamingResponse(payload, accessToken, modelId, convKey, metadata) {
|
|
9
10
|
const completionId = `chatcmpl-${crypto.randomUUID().replace(/-/g, "").slice(0, 28)}`;
|
|
10
11
|
const created = Math.floor(Date.now() / 1000);
|
|
@@ -33,6 +34,7 @@ async function collectFullResponse(payload, accessToken, modelId, convKey, metad
|
|
|
33
34
|
let endStreamError = null;
|
|
34
35
|
const pendingToolCalls = [];
|
|
35
36
|
const { bridge, heartbeatTimer } = await startBridge(accessToken, payload.requestBytes);
|
|
37
|
+
const bridgeCloseController = createBridgeCloseController(bridge);
|
|
36
38
|
const state = {
|
|
37
39
|
toolCallIndex: 0,
|
|
38
40
|
pendingExecs: [],
|
|
@@ -43,22 +45,49 @@ async function collectFullResponse(payload, accessToken, modelId, convKey, metad
|
|
|
43
45
|
bridge.onData(createConnectFrameParser((messageBytes) => {
|
|
44
46
|
try {
|
|
45
47
|
const serverMessage = fromBinary(AgentServerMessageSchema, messageBytes);
|
|
46
|
-
processServerMessage(serverMessage, payload.blobStore, payload.mcpTools, (data) => bridge.write(data), state, (text, isThinking) => {
|
|
48
|
+
processServerMessage(serverMessage, payload.blobStore, payload.cloudRule, payload.mcpTools, (data) => bridge.write(data), state, (text, isThinking) => {
|
|
47
49
|
if (isThinking)
|
|
48
50
|
return;
|
|
49
51
|
const { content } = tagFilter.process(text);
|
|
50
52
|
fullText += content;
|
|
51
53
|
}, (exec) => {
|
|
52
|
-
|
|
54
|
+
const toolCall = {
|
|
53
55
|
id: exec.toolCallId,
|
|
54
56
|
type: "function",
|
|
55
57
|
function: {
|
|
56
58
|
name: exec.toolName,
|
|
57
59
|
arguments: exec.decodedArgs,
|
|
58
60
|
},
|
|
61
|
+
};
|
|
62
|
+
const existingIndex = pendingToolCalls.findIndex((call) => call.id === exec.toolCallId);
|
|
63
|
+
if (existingIndex >= 0) {
|
|
64
|
+
pendingToolCalls[existingIndex] = toolCall;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
pendingToolCalls.push(toolCall);
|
|
68
|
+
}
|
|
69
|
+
}, (_info) => { }, undefined, (checkpointBytes) => {
|
|
70
|
+
updateConversationCheckpoint(convKey, checkpointBytes);
|
|
71
|
+
bridgeCloseController.noteCheckpoint();
|
|
72
|
+
if (pendingToolCalls.length > 0) {
|
|
73
|
+
scheduleBridgeEnd(bridge);
|
|
74
|
+
}
|
|
75
|
+
}, () => {
|
|
76
|
+
bridgeCloseController.noteTurnEnded();
|
|
77
|
+
if (pendingToolCalls.length > 0) {
|
|
78
|
+
scheduleBridgeEnd(bridge);
|
|
79
|
+
}
|
|
80
|
+
}, (info) => {
|
|
81
|
+
endStreamError = new Error(`Cursor returned unsupported ${info.category}: ${info.caseName}${info.detail ? ` (${info.detail})` : ""}`);
|
|
82
|
+
logPluginError("Closing non-streaming Cursor bridge after unsupported message", {
|
|
83
|
+
modelId,
|
|
84
|
+
convKey,
|
|
85
|
+
category: info.category,
|
|
86
|
+
caseName: info.caseName,
|
|
87
|
+
detail: info.detail,
|
|
59
88
|
});
|
|
60
89
|
scheduleBridgeEnd(bridge);
|
|
61
|
-
}, (
|
|
90
|
+
}, (info) => {
|
|
62
91
|
endStreamError = new Error(`Cursor requested unsupported exec type: ${info.execCase}`);
|
|
63
92
|
logPluginError("Closing non-streaming Cursor bridge after unsupported exec", {
|
|
64
93
|
modelId,
|
|
@@ -85,6 +114,7 @@ async function collectFullResponse(payload, accessToken, modelId, convKey, metad
|
|
|
85
114
|
scheduleBridgeEnd(bridge);
|
|
86
115
|
}));
|
|
87
116
|
bridge.onClose(() => {
|
|
117
|
+
bridgeCloseController.dispose();
|
|
88
118
|
clearInterval(heartbeatTimer);
|
|
89
119
|
syncStoredBlobStore(convKey, payload.blobStore);
|
|
90
120
|
const flushed = tagFilter.flush();
|
|
@@ -2,12 +2,10 @@ import { createCursorSession } from "../cursor/bidi-session";
|
|
|
2
2
|
import { makeHeartbeatBytes } from "./stream-dispatch";
|
|
3
3
|
const HEARTBEAT_INTERVAL_MS = 5_000;
|
|
4
4
|
export async function startBridge(accessToken, requestBytes) {
|
|
5
|
-
const requestId = crypto.randomUUID();
|
|
6
5
|
const bridge = await createCursorSession({
|
|
7
6
|
accessToken,
|
|
8
|
-
|
|
7
|
+
initialRequestBytes: requestBytes,
|
|
9
8
|
});
|
|
10
|
-
bridge.write(requestBytes);
|
|
11
9
|
const heartbeatTimer = setInterval(() => bridge.write(makeHeartbeatBytes()), HEARTBEAT_INTERVAL_MS);
|
|
12
10
|
return { bridge, heartbeatTimer };
|
|
13
11
|
}
|
|
@@ -2,4 +2,4 @@ import { type ToolResultInfo } from "../openai/messages";
|
|
|
2
2
|
import type { ConversationRequestMetadata } from "./conversation-meta";
|
|
3
3
|
import type { ActiveBridge, CursorRequestPayload } from "./types";
|
|
4
4
|
export declare function handleStreamingResponse(payload: CursorRequestPayload, accessToken: string, modelId: string, bridgeKey: string, convKey: string, metadata: ConversationRequestMetadata): Promise<Response>;
|
|
5
|
-
export declare function handleToolResultResume(active: ActiveBridge, toolResults: ToolResultInfo[], bridgeKey: string, convKey: string): Response
|
|
5
|
+
export declare function handleToolResultResume(active: ActiveBridge, toolResults: ToolResultInfo[], bridgeKey: string, convKey: string): Promise<Response>;
|