opencode-deepseek-auth 1.0.1 → 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 +50 -24
- package/dist/plugin.js.map +1 -1
- package/package.json +1 -1
- package/src/plugin.ts +146 -123
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
|
|
@@ -139,7 +165,7 @@ const DeepSeekAuthPlugin = async ({ client }) => ({
|
|
|
139
165
|
methods: [
|
|
140
166
|
{
|
|
141
167
|
label: "Login with DeepSeek Account",
|
|
142
|
-
type: "
|
|
168
|
+
type: "oauth",
|
|
143
169
|
authorize: async () => {
|
|
144
170
|
// Direct credential form for DeepSeek as they don't use standard OAuth
|
|
145
171
|
const form = {
|
|
@@ -190,7 +216,7 @@ const DeepSeekAuthPlugin = async ({ client }) => ({
|
|
|
190
216
|
},
|
|
191
217
|
{
|
|
192
218
|
provider: constants_1.DEEPSEEK_PROVIDER_ID,
|
|
193
|
-
label: "
|
|
219
|
+
label: "Enter credentials (email:password or phone:password)",
|
|
194
220
|
type: "api",
|
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IAAI,KAAK,SAAS,EAAE,CAAC;gCAC9B,kBAAkB;gCAClB,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE;oCACpB,KAAK,EAAE,MAAM,CAAC,MAAM;oCACpB,OAAO,EAAE,MAAM,CAAC,OAAO;oCACvB,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,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,129 +125,152 @@ export const DeepSeekAuthPlugin = async (
|
|
|
125
125
|
): Promise<PluginResult> => ({
|
|
126
126
|
auth: {
|
|
127
127
|
provider: DEEPSEEK_PROVIDER_ID,
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
+
},
|
|
212
|
+
methods: [
|
|
213
|
+
{
|
|
214
|
+
label: "Login with DeepSeek Account",
|
|
215
|
+
type: "oauth",
|
|
216
|
+
authorize: async () => {
|
|
217
|
+
// Direct credential form for DeepSeek as they don't use standard OAuth
|
|
218
|
+
const form: FormConfig = {
|
|
219
|
+
fields: [
|
|
220
|
+
{
|
|
221
|
+
name: "email",
|
|
222
|
+
label: "Email",
|
|
223
|
+
type: "email",
|
|
224
|
+
required: true,
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
name: "password",
|
|
228
|
+
label: "Password",
|
|
229
|
+
type: "password",
|
|
230
|
+
required: true,
|
|
231
|
+
}
|
|
232
|
+
]
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
return {
|
|
236
|
+
url: "https://chat.deepseek.com",
|
|
237
|
+
instructions: "Enter your DeepSeek account credentials below. Your credentials will be stored securely and used for authentication.",
|
|
238
|
+
method: "form",
|
|
239
|
+
form: form,
|
|
240
|
+
callback: async (formData: Record<string, string>): Promise<DeepSeekTokenExchangeResult> => {
|
|
241
|
+
const email = formData.email;
|
|
242
|
+
const password = formData.password;
|
|
243
|
+
|
|
244
|
+
// Validate inputs
|
|
245
|
+
if (!email || !password) {
|
|
246
|
+
return {
|
|
247
|
+
type: "failed",
|
|
248
|
+
error: "Email and password are required for DeepSeek authentication"
|
|
249
|
+
};
|
|
250
|
+
}
|
|
133
251
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
let authRecord = latestAuth;
|
|
158
|
-
|
|
159
|
-
// Check if token has expired and refresh if possible
|
|
160
|
-
if (accessTokenExpired(authRecord)) {
|
|
161
|
-
const refreshed = await refreshAccessToken(authRecord, client);
|
|
162
|
-
if (!refreshed) {
|
|
163
|
-
console.warn("Could not refresh DeepSeek access token");
|
|
164
|
-
return fetch(input as RequestInfo, init);
|
|
165
|
-
}
|
|
166
|
-
authRecord = refreshed;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
const accessToken = authRecord.access;
|
|
170
|
-
if (!accessToken) {
|
|
171
|
-
return fetch(input as RequestInfo, init);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// Prepare the request with proper headers
|
|
175
|
-
const { request, init: transformedInit } = prepareDeepSeekRequest(
|
|
176
|
-
input,
|
|
177
|
-
init,
|
|
178
|
-
accessToken
|
|
179
|
-
);
|
|
180
|
-
|
|
181
|
-
// Make the API call
|
|
182
|
-
const response = await fetch(request, transformedInit);
|
|
183
|
-
|
|
184
|
-
// Transform response if needed
|
|
185
|
-
return transformDeepSeekResponse(response);
|
|
186
|
-
},
|
|
187
|
-
};
|
|
188
|
-
},
|
|
189
|
-
methods: [
|
|
190
|
-
{
|
|
191
|
-
label: "Login with DeepSeek Account",
|
|
192
|
-
type: "form",
|
|
193
|
-
authorize: async () => {
|
|
194
|
-
// Direct credential form for DeepSeek as they don't use standard OAuth
|
|
195
|
-
const form: FormConfig = {
|
|
196
|
-
fields: [
|
|
197
|
-
{
|
|
198
|
-
name: "email",
|
|
199
|
-
label: "Email",
|
|
200
|
-
type: "email",
|
|
201
|
-
required: true,
|
|
202
|
-
},
|
|
203
|
-
{
|
|
204
|
-
name: "password",
|
|
205
|
-
label: "Password",
|
|
206
|
-
type: "password",
|
|
207
|
-
required: true,
|
|
208
|
-
}
|
|
209
|
-
]
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
return {
|
|
213
|
-
url: "https://chat.deepseek.com",
|
|
214
|
-
instructions: "Enter your DeepSeek account credentials below. Your credentials will be stored securely and used for authentication.",
|
|
215
|
-
method: "form",
|
|
216
|
-
form: form,
|
|
217
|
-
callback: async (formData: Record<string, string>): Promise<DeepSeekTokenExchangeResult> => {
|
|
218
|
-
const email = formData.email;
|
|
219
|
-
const password = formData.password;
|
|
220
|
-
|
|
221
|
-
// Validate inputs
|
|
222
|
-
if (!email || !password) {
|
|
223
|
-
return {
|
|
224
|
-
type: "failed",
|
|
225
|
-
error: "Email and password are required for DeepSeek authentication"
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// Attempt to log in using the provided credentials
|
|
230
|
-
const result = await loginDeepSeek(email, password);
|
|
231
|
-
|
|
232
|
-
if (result.type === "success") {
|
|
233
|
-
// Cache the token
|
|
234
|
-
tokenCache.set(email, {
|
|
235
|
-
token: result.access,
|
|
236
|
-
expires: result.expires,
|
|
237
|
-
email: result.email || email
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
return result;
|
|
242
|
-
},
|
|
243
|
-
};
|
|
244
|
-
},
|
|
245
|
-
},
|
|
246
|
-
{
|
|
247
|
-
provider: DEEPSEEK_PROVIDER_ID,
|
|
248
|
-
label: "Manually enter API Key",
|
|
249
|
-
type: "api",
|
|
250
|
-
},
|
|
251
|
-
],
|
|
252
|
+
// Attempt to log in using the provided credentials
|
|
253
|
+
const result = await loginDeepSeek(email, password);
|
|
254
|
+
|
|
255
|
+
if (result.type === "success") {
|
|
256
|
+
// Cache the token
|
|
257
|
+
tokenCache.set(email, {
|
|
258
|
+
token: result.access,
|
|
259
|
+
expires: result.expires,
|
|
260
|
+
email: result.email || email
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return result;
|
|
265
|
+
},
|
|
266
|
+
};
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
provider: DEEPSEEK_PROVIDER_ID,
|
|
271
|
+
label: "Enter credentials (email:password or phone:password)",
|
|
272
|
+
type: "api",
|
|
273
|
+
},
|
|
274
|
+
],
|
|
252
275
|
},
|
|
253
276
|
});
|