opencode-deepseek-auth 1.0.2 → 1.0.3
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/plugin.d.ts.map +1 -1
- package/dist/plugin.js +53 -22
- package/dist/plugin.js.map +1 -1
- package/package.json +1 -1
- package/src/plugin.ts +89 -61
package/dist/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAGV,aAAa,EACb,YAAY,EAGb,MAAM,SAAS,CAAC;AAqGjB;;;GAGG;AACH,eAAO,MAAM,kBAAkB,GAC7B,YAAY,aAAa,KACxB,OAAO,CAAC,YAAY,
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAGV,aAAa,EACb,YAAY,EAGb,MAAM,SAAS,CAAC;AAqGjB;;;GAGG;AACH,eAAO,MAAM,kBAAkB,GAC7B,YAAY,aAAa,KACxB,OAAO,CAAC,YAAY,CAuJrB,CAAC"}
|
package/dist/plugin.js
CHANGED
|
@@ -90,7 +90,8 @@ const DeepSeekAuthPlugin = async ({ client }) => ({
|
|
|
90
90
|
provider: constants_1.DEEPSEEK_PROVIDER_ID,
|
|
91
91
|
loader: async (getAuth, provider) => {
|
|
92
92
|
const auth = await getAuth();
|
|
93
|
-
|
|
93
|
+
// Handle both OAuth-based auth and API key formatted credentials
|
|
94
|
+
if (!isOAuthAuth(auth) && !auth.apiKey) {
|
|
94
95
|
return null;
|
|
95
96
|
}
|
|
96
97
|
// If models are defined in the provider, set cost to 0 to indicate free usage
|
|
@@ -101,34 +102,59 @@ const DeepSeekAuthPlugin = async ({ client }) => ({
|
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
104
|
}
|
|
105
|
+
// Handle the case where API key contains email:password
|
|
106
|
+
let resolvedAccessToken = "";
|
|
107
|
+
if (auth.apiKey) {
|
|
108
|
+
// Check if API key contains email:password or phone:password format
|
|
109
|
+
const credentialParts = auth.apiKey.split(':');
|
|
110
|
+
if (credentialParts.length === 2) {
|
|
111
|
+
const [identifier, password] = credentialParts;
|
|
112
|
+
// Try to login with these credentials
|
|
113
|
+
const result = await (0, auth_1.loginDeepSeek)(identifier, password);
|
|
114
|
+
if (result.type === "success") {
|
|
115
|
+
resolvedAccessToken = result.access;
|
|
116
|
+
// Cache this for potential future use
|
|
117
|
+
tokenCache.set(identifier, {
|
|
118
|
+
token: result.access,
|
|
119
|
+
expires: result.expires,
|
|
120
|
+
email: result.email || identifier
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
throw new Error(`Failed to authenticate with provided credentials: ${result.error}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
// If it's not in email:password format, assume it's already a valid access token
|
|
129
|
+
resolvedAccessToken = auth.apiKey;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
else if (isOAuthAuth(auth)) {
|
|
133
|
+
// Handle normal OAuth flow
|
|
134
|
+
let authRecord = auth;
|
|
135
|
+
// Check if token has expired and refresh if possible
|
|
136
|
+
if (accessTokenExpired(authRecord)) {
|
|
137
|
+
const refreshed = await refreshAccessToken(authRecord, client);
|
|
138
|
+
if (!refreshed) {
|
|
139
|
+
console.warn("Could not refresh DeepSeek access token");
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
authRecord = refreshed;
|
|
143
|
+
}
|
|
144
|
+
resolvedAccessToken = authRecord.access;
|
|
145
|
+
if (!resolvedAccessToken) {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
104
149
|
return {
|
|
105
|
-
apiKey: "",
|
|
150
|
+
apiKey: resolvedAccessToken || "",
|
|
106
151
|
async fetch(input, init) {
|
|
107
152
|
// If this isn't a DeepSeek request, pass through normally
|
|
108
153
|
if (!isDeepSeekRequest(input)) {
|
|
109
154
|
return fetch(input, init);
|
|
110
155
|
}
|
|
111
|
-
// Get current auth state
|
|
112
|
-
const latestAuth = await getAuth();
|
|
113
|
-
if (!isOAuthAuth(latestAuth)) {
|
|
114
|
-
return fetch(input, init);
|
|
115
|
-
}
|
|
116
|
-
let authRecord = latestAuth;
|
|
117
|
-
// Check if token has expired and refresh if possible
|
|
118
|
-
if (accessTokenExpired(authRecord)) {
|
|
119
|
-
const refreshed = await refreshAccessToken(authRecord, client);
|
|
120
|
-
if (!refreshed) {
|
|
121
|
-
console.warn("Could not refresh DeepSeek access token");
|
|
122
|
-
return fetch(input, init);
|
|
123
|
-
}
|
|
124
|
-
authRecord = refreshed;
|
|
125
|
-
}
|
|
126
|
-
const accessToken = authRecord.access;
|
|
127
|
-
if (!accessToken) {
|
|
128
|
-
return fetch(input, init);
|
|
129
|
-
}
|
|
130
156
|
// Prepare the request with proper headers
|
|
131
|
-
const { request, init: transformedInit } = prepareDeepSeekRequest(input, init,
|
|
157
|
+
const { request, init: transformedInit } = prepareDeepSeekRequest(input, init, resolvedAccessToken);
|
|
132
158
|
// Make the API call
|
|
133
159
|
const response = await fetch(request, transformedInit);
|
|
134
160
|
// Transform response if needed
|
|
@@ -188,6 +214,11 @@ const DeepSeekAuthPlugin = async ({ client }) => ({
|
|
|
188
214
|
};
|
|
189
215
|
},
|
|
190
216
|
},
|
|
217
|
+
{
|
|
218
|
+
provider: constants_1.DEEPSEEK_PROVIDER_ID,
|
|
219
|
+
label: "Enter credentials (email:password or phone:password)",
|
|
220
|
+
type: "api",
|
|
221
|
+
},
|
|
191
222
|
],
|
|
192
223
|
},
|
|
193
224
|
});
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":";;;AAEA,2CAAiG;AACjG,0CAIyB;AAYzB,8BAA8B;AAC9B,MAAM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AAI,KAAK;iCAC7B,CAAC,CAAC;4BACL,CAAC;4BAED,OAAO,MAAM,CAAC;wBAChB,CAAC;qBACF,CAAC;gBACJ,CAAC;aACF;YACD;gBACE,QAAQ,EAAE,gCAAoB;gBAC9B,KAAK,EAAE,sDAAsD;gBAC7D,IAAI,EAAE,KAAK;aACZ;SACF;KACH;CACF,CAAC,CAAC;AAzJU,QAAA,kBAAkB,sBAyJ5B"}
|
package/package.json
CHANGED
package/src/plugin.ts
CHANGED
|
@@ -125,67 +125,90 @@ export const DeepSeekAuthPlugin = async (
|
|
|
125
125
|
): Promise<PluginResult> => ({
|
|
126
126
|
auth: {
|
|
127
127
|
provider: DEEPSEEK_PROVIDER_ID,
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
128
|
+
loader: async (getAuth: GetAuth, provider: Provider): Promise<LoaderResult | null> => {
|
|
129
|
+
const auth = await getAuth();
|
|
130
|
+
|
|
131
|
+
// Handle both OAuth-based auth and API key formatted credentials
|
|
132
|
+
if (!isOAuthAuth(auth) && !auth.apiKey) {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// If models are defined in the provider, set cost to 0 to indicate free usage
|
|
137
|
+
if (provider.models) {
|
|
138
|
+
for (const model of Object.values(provider.models)) {
|
|
139
|
+
if (model) {
|
|
140
|
+
model.cost = { input: 0, output: 0 };
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Handle the case where API key contains email:password
|
|
146
|
+
let resolvedAccessToken = "";
|
|
147
|
+
if (auth.apiKey) {
|
|
148
|
+
// Check if API key contains email:password or phone:password format
|
|
149
|
+
const credentialParts = auth.apiKey.split(':');
|
|
150
|
+
if (credentialParts.length === 2) {
|
|
151
|
+
const [identifier, password] = credentialParts;
|
|
152
|
+
// Try to login with these credentials
|
|
153
|
+
const result = await loginDeepSeek(identifier, password);
|
|
154
|
+
if (result.type === "success") {
|
|
155
|
+
resolvedAccessToken = result.access;
|
|
156
|
+
// Cache this for potential future use
|
|
157
|
+
tokenCache.set(identifier, {
|
|
158
|
+
token: result.access,
|
|
159
|
+
expires: result.expires,
|
|
160
|
+
email: result.email || identifier
|
|
161
|
+
});
|
|
162
|
+
} else {
|
|
163
|
+
throw new Error(`Failed to authenticate with provided credentials: ${result.error}`);
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
// If it's not in email:password format, assume it's already a valid access token
|
|
167
|
+
resolvedAccessToken = auth.apiKey;
|
|
168
|
+
}
|
|
169
|
+
} else if (isOAuthAuth(auth)) {
|
|
170
|
+
// Handle normal OAuth flow
|
|
171
|
+
let authRecord = auth;
|
|
172
|
+
|
|
173
|
+
// Check if token has expired and refresh if possible
|
|
174
|
+
if (accessTokenExpired(authRecord)) {
|
|
175
|
+
const refreshed = await refreshAccessToken(authRecord, client);
|
|
176
|
+
if (!refreshed) {
|
|
177
|
+
console.warn("Could not refresh DeepSeek access token");
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
authRecord = refreshed;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
resolvedAccessToken = authRecord.access;
|
|
184
|
+
if (!resolvedAccessToken) {
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return {
|
|
190
|
+
apiKey: resolvedAccessToken || "",
|
|
191
|
+
async fetch(input: Parameters<typeof fetch>[0], init?: RequestInit) {
|
|
192
|
+
// If this isn't a DeepSeek request, pass through normally
|
|
193
|
+
if (!isDeepSeekRequest(input)) {
|
|
194
|
+
return fetch(input as RequestInfo, init);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Prepare the request with proper headers
|
|
198
|
+
const { request, init: transformedInit } = prepareDeepSeekRequest(
|
|
199
|
+
input,
|
|
200
|
+
init,
|
|
201
|
+
resolvedAccessToken
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
// Make the API call
|
|
205
|
+
const response = await fetch(request, transformedInit);
|
|
206
|
+
|
|
207
|
+
// Transform response if needed
|
|
208
|
+
return transformDeepSeekResponse(response);
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
},
|
|
189
212
|
methods: [
|
|
190
213
|
{
|
|
191
214
|
label: "Login with DeepSeek Account",
|
|
@@ -243,6 +266,11 @@ export const DeepSeekAuthPlugin = async (
|
|
|
243
266
|
};
|
|
244
267
|
},
|
|
245
268
|
},
|
|
269
|
+
{
|
|
270
|
+
provider: DEEPSEEK_PROVIDER_ID,
|
|
271
|
+
label: "Enter credentials (email:password or phone:password)",
|
|
272
|
+
type: "api",
|
|
273
|
+
},
|
|
246
274
|
],
|
|
247
275
|
},
|
|
248
276
|
});
|