xiaodcs-copilot-api 2.1.0-recovery.1

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.
@@ -0,0 +1,88 @@
1
+ import { B as state } from "./token--3EQGrXj.js";
2
+ //#region src/lib/models.ts
3
+ /**
4
+ * Converts a Copilot upstream model ID to a client-friendly ID that Claude Code
5
+ * and Claude Desktop recognize (dots in version replaced with hyphens).
6
+ * e.g. "claude-sonnet-4.6" -> "claude-sonnet-4-6"
7
+ * Non-Claude models are returned unchanged.
8
+ */
9
+ const toClientModelId = (modelId) => {
10
+ const normalized = normalizeSdkModelId(modelId);
11
+ if (!normalized) return modelId;
12
+ const versionHyphenated = normalized.version.replaceAll(".", "-");
13
+ return `claude-${normalized.family}-${versionHyphenated}`;
14
+ };
15
+ const findEndpointModel = (sdkModelId) => {
16
+ const models = state.models?.data ?? [];
17
+ const exactMatch = models.find((m) => m.id === sdkModelId);
18
+ if (exactMatch) return exactMatch;
19
+ const normalized = normalizeSdkModelId(sdkModelId);
20
+ if (!normalized) return;
21
+ const modelName = `claude-${normalized.family}-${normalized.version}`;
22
+ const model = models.find((m) => m.id === modelName);
23
+ if (model) return model;
24
+ };
25
+ /**
26
+ * Finds the latest available model for a given Claude family (e.g. "opus",
27
+ * "sonnet", "haiku") among the models currently cached in `state.models`.
28
+ * "Latest" is determined by the highest semantic version parsed from the model
29
+ * ID. Returns `undefined` when no model of that family is available.
30
+ */
31
+ const getLatestModelForFamily = (family) => {
32
+ const models = state.models?.data ?? [];
33
+ let best;
34
+ for (const model of models) {
35
+ const normalized = normalizeSdkModelId(model.id);
36
+ if (!normalized || normalized.family !== family) continue;
37
+ const [majorPart, minorPart = "0"] = normalized.version.split(".");
38
+ const major = Number.parseInt(majorPart, 10);
39
+ const minor = Number.parseInt(minorPart, 10);
40
+ if (Number.isNaN(major) || Number.isNaN(minor)) continue;
41
+ if (!best || major > best.major || major === best.major && minor > best.minor) best = {
42
+ model,
43
+ major,
44
+ minor
45
+ };
46
+ }
47
+ return best?.model;
48
+ };
49
+ /**
50
+ * Normalizes an SDK model ID to extract the model family and version.
51
+ * this method from github copilot extension
52
+ * Examples:
53
+ * - "claude-opus-4-5-20251101" -> { family: "opus", version: "4.5" }
54
+ * - "claude-3-5-sonnet-20241022" -> { family: "sonnet", version: "3.5" }
55
+ * - "claude-sonnet-4-20250514" -> { family: "sonnet", version: "4" }
56
+ * - "claude-haiku-3-5-20250514" -> { family: "haiku", version: "3.5" }
57
+ * - "claude-haiku-4.5" -> { family: "haiku", version: "4.5" }
58
+ */
59
+ const normalizeSdkModelId = (sdkModelId) => {
60
+ const withoutDate = sdkModelId.toLowerCase().replace(/-\d{8}$/, "");
61
+ const pattern1 = withoutDate.match(/^claude-(\w+)-(\d+)\.(\d+)$/);
62
+ if (pattern1) return {
63
+ family: pattern1[1],
64
+ version: `${pattern1[2]}.${pattern1[3]}`
65
+ };
66
+ const pattern2 = withoutDate.match(/^claude-(\w+)-(\d+)-(\d+)$/);
67
+ if (pattern2) return {
68
+ family: pattern2[1],
69
+ version: `${pattern2[2]}.${pattern2[3]}`
70
+ };
71
+ const pattern3 = withoutDate.match(/^claude-(\d+)-(\d+)-(\w+)$/);
72
+ if (pattern3) return {
73
+ family: pattern3[3],
74
+ version: `${pattern3[1]}.${pattern3[2]}`
75
+ };
76
+ const pattern4 = withoutDate.match(/^claude-(\w+)-(\d+)$/);
77
+ if (pattern4) return {
78
+ family: pattern4[1],
79
+ version: pattern4[2]
80
+ };
81
+ const pattern5 = withoutDate.match(/^claude-(\d+)-(\w+)$/);
82
+ if (pattern5) return {
83
+ family: pattern5[2],
84
+ version: pattern5[1]
85
+ };
86
+ };
87
+ //#endregion
88
+ export { toClientModelId as i, getLatestModelForFamily as n, normalizeSdkModelId as r, findEndpointModel as t };