@rahularya01/pi-cursor 1.0.0 → 1.2.0
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/CHANGELOG.md +29 -0
- package/README.md +28 -4
- package/dist/index.js +27 -0
- package/package.json +15 -9
- package/src/auth/cli-credentials.ts +0 -168
- package/src/auth/index.ts +0 -10
- package/src/auth/oauth.ts +0 -214
- package/src/client/bridge.ts +0 -206
- package/src/client/cursor-wire.ts +0 -212
- package/src/client/index.ts +0 -19
- package/src/diagnostics/diagnostics.ts +0 -62
- package/src/diagnostics/index.ts +0 -1
- package/src/index.ts +0 -1393
- package/src/models/catalog.json +0 -1163
- package/src/models/index.ts +0 -2
- package/src/proto/agent_pb.ts +0 -15294
- package/src/stream/index.ts +0 -11
- package/src/stream/native-core.ts +0 -5760
- package/src/usage.ts +0 -262
- package/src/utils/index.ts +0 -2
- package/src/utils/security.ts +0 -65
- package/src/utils/util.ts +0 -19
- package/tsconfig.json +0 -21
- /package/{src/client → dist}/h2-bridge.mjs +0 -0
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
export interface CursorModelParameter {
|
|
2
|
-
id: string;
|
|
3
|
-
value: string;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export interface CursorParameterizedVariant {
|
|
7
|
-
parameters: CursorModelParameter[];
|
|
8
|
-
isMaxMode: boolean;
|
|
9
|
-
isDefaultMaxConfig?: boolean;
|
|
10
|
-
isDefaultNonMaxConfig?: boolean;
|
|
11
|
-
displayName?: string;
|
|
12
|
-
displayNameOutsidePicker?: string;
|
|
13
|
-
variantStringRepresentation?: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface CursorParameterizedModel {
|
|
17
|
-
name: string;
|
|
18
|
-
clientDisplayName?: string;
|
|
19
|
-
serverModelName?: string;
|
|
20
|
-
supportsMaxMode?: boolean;
|
|
21
|
-
supportsNonMaxMode?: boolean;
|
|
22
|
-
supportsImages?: boolean;
|
|
23
|
-
contextTokenLimit?: number;
|
|
24
|
-
contextTokenLimitForMaxMode?: number;
|
|
25
|
-
variants: CursorParameterizedVariant[];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function encodeVarint(value: number): number[] {
|
|
29
|
-
const out: number[] = [];
|
|
30
|
-
let v = value >>> 0;
|
|
31
|
-
while (v >= 0x80) {
|
|
32
|
-
out.push((v & 0x7f) | 0x80);
|
|
33
|
-
v >>>= 7;
|
|
34
|
-
}
|
|
35
|
-
out.push(v);
|
|
36
|
-
return out;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function encodeBoolField(fieldNo: number, value: boolean): number[] {
|
|
40
|
-
return [...encodeVarint(fieldNo << 3), value ? 1 : 0];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function encodeAvailableModelsRequest(): Uint8Array {
|
|
44
|
-
// aiserver.v1.AvailableModelsRequest {
|
|
45
|
-
// optional bool use_model_parameters = 5;
|
|
46
|
-
// optional bool do_not_use_markdown = 7;
|
|
47
|
-
// }
|
|
48
|
-
return new Uint8Array([...encodeBoolField(5, true), ...encodeBoolField(7, true)]);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
interface WireReader {
|
|
52
|
-
bytes: Uint8Array;
|
|
53
|
-
offset: number;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function readVarint(reader: WireReader): number {
|
|
57
|
-
let result = 0;
|
|
58
|
-
let shift = 0;
|
|
59
|
-
while (reader.offset < reader.bytes.length) {
|
|
60
|
-
const byte = reader.bytes[reader.offset++]!;
|
|
61
|
-
// Avoid JS bitwise operators here: they truncate to 32 bits, but protobuf
|
|
62
|
-
// varints can legally carry 64-bit values on fields we merely skip.
|
|
63
|
-
if (shift < 53) result += (byte & 0x7f) * 2 ** shift;
|
|
64
|
-
if ((byte & 0x80) === 0) return result;
|
|
65
|
-
shift += 7;
|
|
66
|
-
if (shift >= 70) throw new Error("varint too long");
|
|
67
|
-
}
|
|
68
|
-
throw new Error("unexpected EOF while reading varint");
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function readLengthDelimited(reader: WireReader): Uint8Array {
|
|
72
|
-
const length = readVarint(reader);
|
|
73
|
-
if (!Number.isSafeInteger(length)) throw new Error("length-delimited size is too large");
|
|
74
|
-
const end = reader.offset + length;
|
|
75
|
-
if (end > reader.bytes.length) throw new Error("length-delimited field exceeds buffer");
|
|
76
|
-
const value = reader.bytes.subarray(reader.offset, end);
|
|
77
|
-
reader.offset = end;
|
|
78
|
-
return value;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function skipBytes(reader: WireReader, length: number): void {
|
|
82
|
-
const end = reader.offset + length;
|
|
83
|
-
if (end > reader.bytes.length) throw new Error("fixed-width field exceeds buffer");
|
|
84
|
-
reader.offset = end;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function skipWireField(reader: WireReader, wireType: number): void {
|
|
88
|
-
switch (wireType) {
|
|
89
|
-
case 0:
|
|
90
|
-
readVarint(reader);
|
|
91
|
-
return;
|
|
92
|
-
case 1:
|
|
93
|
-
skipBytes(reader, 8);
|
|
94
|
-
return;
|
|
95
|
-
case 2:
|
|
96
|
-
readLengthDelimited(reader);
|
|
97
|
-
return;
|
|
98
|
-
case 5:
|
|
99
|
-
skipBytes(reader, 4);
|
|
100
|
-
return;
|
|
101
|
-
default:
|
|
102
|
-
throw new Error(`unsupported wire type ${wireType}`);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function decodeString(bytes: Uint8Array): string {
|
|
107
|
-
return new TextDecoder().decode(bytes);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function decodeModelParameter(bytes: Uint8Array): CursorModelParameter {
|
|
111
|
-
const reader: WireReader = { bytes, offset: 0 };
|
|
112
|
-
const parameter: CursorModelParameter = { id: "", value: "" };
|
|
113
|
-
while (reader.offset < bytes.length) {
|
|
114
|
-
const tag = readVarint(reader);
|
|
115
|
-
const fieldNo = tag >>> 3;
|
|
116
|
-
const wireType = tag & 0x7;
|
|
117
|
-
if (fieldNo === 1 && wireType === 2) parameter.id = decodeString(readLengthDelimited(reader));
|
|
118
|
-
else if (fieldNo === 2 && wireType === 2)
|
|
119
|
-
parameter.value = decodeString(readLengthDelimited(reader));
|
|
120
|
-
else skipWireField(reader, wireType);
|
|
121
|
-
}
|
|
122
|
-
return parameter;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function decodeParameterizedVariant(bytes: Uint8Array): CursorParameterizedVariant {
|
|
126
|
-
const reader: WireReader = { bytes, offset: 0 };
|
|
127
|
-
const variant: CursorParameterizedVariant = { parameters: [], isMaxMode: false };
|
|
128
|
-
while (reader.offset < bytes.length) {
|
|
129
|
-
const tag = readVarint(reader);
|
|
130
|
-
const fieldNo = tag >>> 3;
|
|
131
|
-
const wireType = tag & 0x7;
|
|
132
|
-
if (fieldNo === 1 && wireType === 2)
|
|
133
|
-
variant.parameters.push(decodeModelParameter(readLengthDelimited(reader)));
|
|
134
|
-
else if (fieldNo === 2 && wireType === 2)
|
|
135
|
-
variant.displayName = decodeString(readLengthDelimited(reader));
|
|
136
|
-
else if (fieldNo === 8 && wireType === 2)
|
|
137
|
-
variant.displayNameOutsidePicker = decodeString(readLengthDelimited(reader));
|
|
138
|
-
else if (fieldNo === 3 && wireType === 0) variant.isMaxMode = readVarint(reader) !== 0;
|
|
139
|
-
else if (fieldNo === 4 && wireType === 0) variant.isDefaultMaxConfig = readVarint(reader) !== 0;
|
|
140
|
-
else if (fieldNo === 5 && wireType === 0)
|
|
141
|
-
variant.isDefaultNonMaxConfig = readVarint(reader) !== 0;
|
|
142
|
-
else if (fieldNo === 9 && wireType === 2)
|
|
143
|
-
variant.variantStringRepresentation = decodeString(readLengthDelimited(reader));
|
|
144
|
-
else skipWireField(reader, wireType);
|
|
145
|
-
}
|
|
146
|
-
return variant;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function decodeParameterizedModel(bytes: Uint8Array): CursorParameterizedModel {
|
|
150
|
-
const reader: WireReader = { bytes, offset: 0 };
|
|
151
|
-
const model: CursorParameterizedModel = { name: "", variants: [] };
|
|
152
|
-
while (reader.offset < bytes.length) {
|
|
153
|
-
const tag = readVarint(reader);
|
|
154
|
-
const fieldNo = tag >>> 3;
|
|
155
|
-
const wireType = tag & 0x7;
|
|
156
|
-
if (fieldNo === 1 && wireType === 2) model.name = decodeString(readLengthDelimited(reader));
|
|
157
|
-
else if (fieldNo === 10 && wireType === 0) model.supportsImages = readVarint(reader) !== 0;
|
|
158
|
-
else if (fieldNo === 14 && wireType === 0) model.supportsMaxMode = readVarint(reader) !== 0;
|
|
159
|
-
else if (fieldNo === 19 && wireType === 0) model.supportsNonMaxMode = readVarint(reader) !== 0;
|
|
160
|
-
else if (fieldNo === 15 && wireType === 0) model.contextTokenLimit = readVarint(reader);
|
|
161
|
-
else if (fieldNo === 16 && wireType === 0)
|
|
162
|
-
model.contextTokenLimitForMaxMode = readVarint(reader);
|
|
163
|
-
else if (fieldNo === 17 && wireType === 2)
|
|
164
|
-
model.clientDisplayName = decodeString(readLengthDelimited(reader));
|
|
165
|
-
else if (fieldNo === 18 && wireType === 2)
|
|
166
|
-
model.serverModelName = decodeString(readLengthDelimited(reader));
|
|
167
|
-
else if (fieldNo === 30 && wireType === 2)
|
|
168
|
-
model.variants.push(decodeParameterizedVariant(readLengthDelimited(reader)));
|
|
169
|
-
else skipWireField(reader, wireType);
|
|
170
|
-
}
|
|
171
|
-
return model;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
export function decodeAvailableModelsResponse(bytes: Uint8Array): CursorParameterizedModel[] {
|
|
175
|
-
const reader: WireReader = { bytes, offset: 0 };
|
|
176
|
-
const models: CursorParameterizedModel[] = [];
|
|
177
|
-
while (reader.offset < bytes.length) {
|
|
178
|
-
const tag = readVarint(reader);
|
|
179
|
-
const fieldNo = tag >>> 3;
|
|
180
|
-
const wireType = tag & 0x7;
|
|
181
|
-
if (fieldNo === 2 && wireType === 2) {
|
|
182
|
-
const model = decodeParameterizedModel(readLengthDelimited(reader));
|
|
183
|
-
if (model.name) models.push(model);
|
|
184
|
-
} else {
|
|
185
|
-
skipWireField(reader, wireType);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
return models;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// No generated schema for selectedContextBlob; emit raw wire format for the two
|
|
192
|
-
// fields Cursor actually reads: field 1 (repeated bytes) rootPromptMessagesJson
|
|
193
|
-
// refs, field 22 (string) clientName. blobId.length < 128 (SHA256 = 32 bytes).
|
|
194
|
-
export function buildSelectedContextBlob(
|
|
195
|
-
rootPromptBlobIds: Uint8Array[],
|
|
196
|
-
clientName: string,
|
|
197
|
-
): Uint8Array {
|
|
198
|
-
const parts: Uint8Array[] = [];
|
|
199
|
-
for (const blobId of rootPromptBlobIds) {
|
|
200
|
-
parts.push(new Uint8Array([0x0a, blobId.length, ...blobId]));
|
|
201
|
-
}
|
|
202
|
-
const clientBytes = new TextEncoder().encode(clientName);
|
|
203
|
-
parts.push(new Uint8Array([0xb2, 0x01, clientBytes.length, ...clientBytes]));
|
|
204
|
-
const total = parts.reduce((n, p) => n + p.length, 0);
|
|
205
|
-
const result = new Uint8Array(total);
|
|
206
|
-
let offset = 0;
|
|
207
|
-
for (const p of parts) {
|
|
208
|
-
result.set(p, offset);
|
|
209
|
-
offset += p.length;
|
|
210
|
-
}
|
|
211
|
-
return result;
|
|
212
|
-
}
|
package/src/client/index.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export {
|
|
2
|
-
spawnBridge,
|
|
3
|
-
createConnectFrameParser,
|
|
4
|
-
frameConnectMessage,
|
|
5
|
-
parseConnectEndStream,
|
|
6
|
-
lpEncode,
|
|
7
|
-
type BridgeHandle,
|
|
8
|
-
type BridgeFactory,
|
|
9
|
-
type SpawnBridgeOptions,
|
|
10
|
-
} from "./bridge.js";
|
|
11
|
-
export {
|
|
12
|
-
encodeAvailableModelsRequest,
|
|
13
|
-
decodeAvailableModelsResponse,
|
|
14
|
-
buildSelectedContextBlob,
|
|
15
|
-
type CursorModelParameter,
|
|
16
|
-
type CursorParameterizedModel,
|
|
17
|
-
type CursorParameterizedVariant,
|
|
18
|
-
} from "./cursor-wire.js";
|
|
19
|
-
export { getCursorAgentUrl } from "../stream/native-core.js";
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
-
import { redactSecrets } from "../utils/security.js";
|
|
3
|
-
|
|
4
|
-
export type DiagnosticsSnapshot = {
|
|
5
|
-
status?: number;
|
|
6
|
-
endpoint?: string;
|
|
7
|
-
error?: string;
|
|
8
|
-
projectId?: string;
|
|
9
|
-
resolvedRuntimeModel?: string;
|
|
10
|
-
availableModels?: string;
|
|
11
|
-
matchedModelDebug?: string;
|
|
12
|
-
lastRpc?: string;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const storage = new AsyncLocalStorage<DiagnosticsSnapshot>();
|
|
16
|
-
let lastSnapshot: DiagnosticsSnapshot = {};
|
|
17
|
-
|
|
18
|
-
function currentBag(): DiagnosticsSnapshot {
|
|
19
|
-
return storage.getStore() ?? lastSnapshot;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export async function runWithDiagnostics<T>(fn: () => Promise<T>): Promise<T> {
|
|
23
|
-
const bag: DiagnosticsSnapshot = {};
|
|
24
|
-
return storage.run(bag, async () => {
|
|
25
|
-
try {
|
|
26
|
-
return await fn();
|
|
27
|
-
} finally {
|
|
28
|
-
lastSnapshot = { ...bag };
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function getLastDiagnostics(): Readonly<DiagnosticsSnapshot> {
|
|
34
|
-
return lastSnapshot;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function setLastStatus(status: number | undefined): void {
|
|
38
|
-
currentBag().status = status;
|
|
39
|
-
}
|
|
40
|
-
export function setLastEndpoint(endpoint: string | undefined): void {
|
|
41
|
-
currentBag().endpoint = endpoint;
|
|
42
|
-
}
|
|
43
|
-
export function setLastError(error: string | undefined): void {
|
|
44
|
-
currentBag().error = error === undefined ? undefined : redactSecrets(error).slice(0, 800);
|
|
45
|
-
}
|
|
46
|
-
export function setLastResolvedRuntimeModel(model: string | undefined): void {
|
|
47
|
-
currentBag().resolvedRuntimeModel = model;
|
|
48
|
-
}
|
|
49
|
-
export function setLastAvailableModels(models: string | undefined): void {
|
|
50
|
-
currentBag().availableModels = models;
|
|
51
|
-
}
|
|
52
|
-
export function setLastRpc(rpc: string | undefined): void {
|
|
53
|
-
currentBag().lastRpc = rpc;
|
|
54
|
-
}
|
|
55
|
-
export function setLastMatchedModelDebug(debug: string | undefined): void {
|
|
56
|
-
currentBag().matchedModelDebug =
|
|
57
|
-
debug === undefined ? undefined : redactSecrets(debug).slice(0, 1200);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function resetDiagnosticsForTests(): void {
|
|
61
|
-
lastSnapshot = {};
|
|
62
|
-
}
|
package/src/diagnostics/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./diagnostics.js";
|