@rahularya01/pi-cursor 1.0.0 → 1.1.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 +18 -0
- package/README.md +28 -4
- package/package.json +8 -5
- package/src/auth/cli-credentials.ts +30 -5
- package/src/auth/consent.ts +27 -0
- package/src/auth/index.ts +12 -0
- package/src/client/index.ts +1 -1
- package/src/diagnostics/diagnostics.ts +17 -0
- package/src/index.ts +54 -11
- package/src/stream/config.ts +69 -0
- package/src/stream/context-normalize.ts +104 -0
- package/src/stream/index.ts +34 -3
- package/src/stream/model-routing.ts +100 -0
- package/src/stream/native-core.ts +97 -456
- package/src/stream/protocol.ts +41 -0
- package/src/stream/recovery.ts +454 -0
- package/tsconfig.json +1 -1
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model ID effort suffix routing for Cursor runtime variants.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface CursorNativeModelRouting {
|
|
6
|
+
modelId: string;
|
|
7
|
+
parameters?: Array<{ id: string; value: string }>;
|
|
8
|
+
requiresMaxMode?: boolean;
|
|
9
|
+
requestedMaxMode?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ResolvedCursorModelRouting extends CursorNativeModelRouting {
|
|
13
|
+
maxMode: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type CursorModelRoutingByEffort = Record<string, CursorNativeModelRouting>;
|
|
17
|
+
|
|
18
|
+
export interface CursorResolvableModel {
|
|
19
|
+
id: string;
|
|
20
|
+
[key: string]: unknown;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Insert reasoning effort into model ID, before -fast/-thinking suffix.
|
|
25
|
+
* e.g. model="gpt-5.4" + effort="medium" → "gpt-5.4-medium"
|
|
26
|
+
* model="gpt-5.4-fast" + effort="high" → "gpt-5.4-high-fast"
|
|
27
|
+
* If no effort provided, returns model as-is.
|
|
28
|
+
*/
|
|
29
|
+
export function resolveModelId(model: string, reasoningEffort?: string): string {
|
|
30
|
+
if (!reasoningEffort) return model;
|
|
31
|
+
|
|
32
|
+
let suffix = "";
|
|
33
|
+
let base = model;
|
|
34
|
+
if (base.endsWith("-fast")) {
|
|
35
|
+
suffix = "-fast";
|
|
36
|
+
base = base.slice(0, -5);
|
|
37
|
+
} else if (base.endsWith("-thinking")) {
|
|
38
|
+
suffix = "-thinking";
|
|
39
|
+
base = base.slice(0, -9);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return `${base}-${reasoningEffort}${suffix}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function isCursorModelRouting(value: unknown): value is CursorNativeModelRouting {
|
|
46
|
+
return (
|
|
47
|
+
!!value &&
|
|
48
|
+
typeof value === "object" &&
|
|
49
|
+
typeof (value as { modelId?: unknown }).modelId === "string"
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function resolveRequestedModelId(
|
|
54
|
+
model: string,
|
|
55
|
+
reasoningEffort?: string,
|
|
56
|
+
cursorModelId?: string,
|
|
57
|
+
): string;
|
|
58
|
+
export function resolveRequestedModelId(
|
|
59
|
+
model: CursorResolvableModel,
|
|
60
|
+
reasoningEffort?: string,
|
|
61
|
+
routingByModelId?: Map<string, CursorModelRoutingByEffort | CursorNativeModelRouting>,
|
|
62
|
+
): ResolvedCursorModelRouting;
|
|
63
|
+
export function resolveRequestedModelId(
|
|
64
|
+
model: string | CursorResolvableModel,
|
|
65
|
+
reasoningEffort?: string,
|
|
66
|
+
cursorModelIdOrRoutingByModelId?:
|
|
67
|
+
string | Map<string, CursorModelRoutingByEffort | CursorNativeModelRouting>,
|
|
68
|
+
): string | ResolvedCursorModelRouting {
|
|
69
|
+
if (typeof model === "string") {
|
|
70
|
+
const trimmedCursorModelId =
|
|
71
|
+
typeof cursorModelIdOrRoutingByModelId === "string"
|
|
72
|
+
? cursorModelIdOrRoutingByModelId.trim()
|
|
73
|
+
: "";
|
|
74
|
+
if (trimmedCursorModelId) return trimmedCursorModelId;
|
|
75
|
+
return resolveModelId(model, reasoningEffort);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const routingByModelId =
|
|
79
|
+
cursorModelIdOrRoutingByModelId instanceof Map ? cursorModelIdOrRoutingByModelId : undefined;
|
|
80
|
+
const configured = routingByModelId?.get(model.id);
|
|
81
|
+
let routing: CursorNativeModelRouting | undefined;
|
|
82
|
+
if (isCursorModelRouting(configured)) {
|
|
83
|
+
routing = configured;
|
|
84
|
+
} else if (configured) {
|
|
85
|
+
routing =
|
|
86
|
+
configured[reasoningEffort ?? ""] ??
|
|
87
|
+
configured.none ??
|
|
88
|
+
configured.medium ??
|
|
89
|
+
configured.high ??
|
|
90
|
+
Object.values(configured).find(isCursorModelRouting);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
modelId: routing?.modelId ?? resolveModelId(model.id, reasoningEffort),
|
|
95
|
+
maxMode: Boolean(routing?.requestedMaxMode ?? routing?.requiresMaxMode),
|
|
96
|
+
parameters: routing?.parameters,
|
|
97
|
+
requestedMaxMode: routing?.requestedMaxMode,
|
|
98
|
+
requiresMaxMode: routing?.requiresMaxMode,
|
|
99
|
+
};
|
|
100
|
+
}
|