opencode-puter-auth 1.0.6 → 1.0.10
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/index.d.ts +1 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/dist/plugin-minimal.d.ts +13 -0
- package/dist/plugin-minimal.d.ts.map +1 -0
- package/dist/plugin-minimal.js +111 -0
- package/dist/plugin-minimal.js.map +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -7,8 +7,6 @@
|
|
|
7
7
|
* @author chindris-mihai-alexandru
|
|
8
8
|
* @license MIT
|
|
9
9
|
*/
|
|
10
|
-
export { PuterAuthPlugin } from './plugin.js';
|
|
11
|
-
export { createPuter } from './ai-provider/index.js';
|
|
12
|
-
export type { PuterProvider, PuterChatSettings, PuterProviderConfig, PuterChatConfig } from './ai-provider/index.js';
|
|
10
|
+
export { PuterAuthPlugin } from './plugin-minimal.js';
|
|
13
11
|
export type { PuterConfig, PuterAccount, PuterChatOptions, PuterChatResponse, PuterChatMessage, PuterChatStreamChunk, PuterModelInfo } from './types.js';
|
|
14
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,OAAO,EAAE,eAAe,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAOtD,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -11,7 +11,5 @@
|
|
|
11
11
|
// IMPORTANT: Only export the plugin function, not classes!
|
|
12
12
|
// OpenCode's plugin loader calls all exports as functions, so exporting
|
|
13
13
|
// classes (PuterClient, PuterAuthManager) causes "cannot call class without new" errors.
|
|
14
|
-
export { PuterAuthPlugin } from './plugin.js';
|
|
15
|
-
// AI SDK Provider exports - factory functions only (no classes or default instances)
|
|
16
|
-
export { createPuter } from './ai-provider/index.js';
|
|
14
|
+
export { PuterAuthPlugin } from './plugin-minimal.js';
|
|
17
15
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,kDAAkD;AAClD,2DAA2D;AAC3D,wEAAwE;AACxE,yFAAyF;AACzF,OAAO,EAAE,eAAe,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,kDAAkD;AAClD,2DAA2D;AAC3D,wEAAwE;AACxE,yFAAyF;AACzF,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenCode plugin implementation with AI SDK provider
|
|
3
|
+
* Implements auth loader pattern like Antigravity plugin
|
|
4
|
+
*/
|
|
5
|
+
export declare const PuterAuthPlugin: (_ctx: any) => Promise<{
|
|
6
|
+
'auth.loader': {
|
|
7
|
+
puter: () => Promise<{
|
|
8
|
+
apiKey: string;
|
|
9
|
+
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
10
|
+
}>;
|
|
11
|
+
};
|
|
12
|
+
}>;
|
|
13
|
+
//# sourceMappingURL=plugin-minimal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-minimal.d.ts","sourceRoot":"","sources":["../src/plugin-minimal.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAYH,eAAO,MAAM,eAAe,GAAU,MAAM,GAAG;;;;yBAkBlB,WAAW,GAAG,GAAG,SAAS,WAAW;;;EA4FjE,CAAC"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenCode plugin implementation with AI SDK provider
|
|
3
|
+
* Implements auth loader pattern like Antigravity plugin
|
|
4
|
+
*/
|
|
5
|
+
import { PuterAuthManager } from './auth.js';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import os from 'os';
|
|
8
|
+
// Get config directory
|
|
9
|
+
function getConfigDir() {
|
|
10
|
+
return path.join(os.homedir(), '.config', 'opencode');
|
|
11
|
+
}
|
|
12
|
+
// OpenCode plugin function - async with context parameter
|
|
13
|
+
export const PuterAuthPlugin = async (_ctx) => {
|
|
14
|
+
console.log("Puter Auth Plugin initialized!");
|
|
15
|
+
return {
|
|
16
|
+
// Auth loader - returns custom fetch for AI SDK provider
|
|
17
|
+
'auth.loader': {
|
|
18
|
+
puter: async () => {
|
|
19
|
+
const configDir = getConfigDir();
|
|
20
|
+
const authManager = new PuterAuthManager(configDir);
|
|
21
|
+
await authManager.init();
|
|
22
|
+
const activeAccount = authManager.getActiveAccount();
|
|
23
|
+
if (!activeAccount) {
|
|
24
|
+
throw new Error('Not authenticated with Puter. Run: opencode auth login');
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
apiKey: '', // Not used, we use custom fetch
|
|
28
|
+
async fetch(input, init) {
|
|
29
|
+
const url = input.toString();
|
|
30
|
+
// Intercept requests to puter models
|
|
31
|
+
if (url.includes('/chat/completions') && init?.body) {
|
|
32
|
+
const body = JSON.parse(init.body);
|
|
33
|
+
// Check if this is a puter model request
|
|
34
|
+
if (body.model?.startsWith('puter/') || body.model?.includes('claude-opus-4-5') || body.model?.includes('claude-sonnet-4-5')) {
|
|
35
|
+
// Map model names to Puter drivers
|
|
36
|
+
const modelMap = {
|
|
37
|
+
'claude-opus-4-5': 'claude-opus-4-5',
|
|
38
|
+
'claude-sonnet-4-5': 'claude-sonnet-4-5',
|
|
39
|
+
'claude-sonnet-4': 'claude-sonnet-4',
|
|
40
|
+
'gpt-4o': 'gpt-4o',
|
|
41
|
+
'gpt-5-nano': 'gpt-5-nano',
|
|
42
|
+
'o3-mini': 'o3-mini',
|
|
43
|
+
'gemini-2.5-pro': 'gemini-2.5-pro',
|
|
44
|
+
'gemini-2.5-flash': 'gemini-2.5-flash'
|
|
45
|
+
};
|
|
46
|
+
const cleanModel = body.model.replace('puter/', '').replace('google/', '');
|
|
47
|
+
const driver = modelMap[cleanModel] || 'claude-opus-4-5';
|
|
48
|
+
// Translate to Puter API format
|
|
49
|
+
const puterRequest = {
|
|
50
|
+
interface: 'puter-chat-completion',
|
|
51
|
+
driver,
|
|
52
|
+
method: 'complete',
|
|
53
|
+
args: {
|
|
54
|
+
messages: body.messages,
|
|
55
|
+
stream: body.stream || false,
|
|
56
|
+
max_tokens: body.max_tokens,
|
|
57
|
+
temperature: body.temperature
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
// Make request to Puter API
|
|
61
|
+
const response = await fetch('http://localhost:8080/drivers/call', {
|
|
62
|
+
method: 'POST',
|
|
63
|
+
headers: {
|
|
64
|
+
'Content-Type': 'application/json',
|
|
65
|
+
'Authorization': `Bearer ${activeAccount.authToken}`
|
|
66
|
+
},
|
|
67
|
+
body: JSON.stringify(puterRequest)
|
|
68
|
+
});
|
|
69
|
+
if (!response.ok) {
|
|
70
|
+
throw new Error(`Puter API error: ${response.statusText}`);
|
|
71
|
+
}
|
|
72
|
+
// For streaming responses
|
|
73
|
+
if (body.stream) {
|
|
74
|
+
return response; // Return raw response for streaming
|
|
75
|
+
}
|
|
76
|
+
// For non-streaming, translate response back to OpenAI format
|
|
77
|
+
const puterResponse = await response.json();
|
|
78
|
+
const openaiResponse = {
|
|
79
|
+
id: 'puter-' + Date.now(),
|
|
80
|
+
object: 'chat.completion',
|
|
81
|
+
created: Math.floor(Date.now() / 1000),
|
|
82
|
+
model: body.model,
|
|
83
|
+
choices: [{
|
|
84
|
+
index: 0,
|
|
85
|
+
message: {
|
|
86
|
+
role: 'assistant',
|
|
87
|
+
content: puterResponse.result || puterResponse.message || 'No response'
|
|
88
|
+
},
|
|
89
|
+
finish_reason: 'stop'
|
|
90
|
+
}],
|
|
91
|
+
usage: {
|
|
92
|
+
prompt_tokens: 0,
|
|
93
|
+
completion_tokens: 0,
|
|
94
|
+
total_tokens: 0
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
return new Response(JSON.stringify(openaiResponse), {
|
|
98
|
+
status: 200,
|
|
99
|
+
headers: { 'Content-Type': 'application/json' }
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
// For non-puter requests, pass through
|
|
104
|
+
return fetch(input, init);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
//# sourceMappingURL=plugin-minimal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-minimal.js","sourceRoot":"","sources":["../src/plugin-minimal.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,uBAAuB;AACvB,SAAS,YAAY;IACnB,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;AACxD,CAAC;AAED,0DAA0D;AAC1D,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAAE,IAAS,EAAE,EAAE;IACjD,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;IAE9C,OAA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zB,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;oCACtC,KAAK,EAAE,IAAI,CAAC,KAAK;oCACjB,OAAO,EAAE,CAAC;4CACR,KAAK,EAAE,CAAC;4CACR,OAAO,EAAE;gDACP,IAAI,EAAE,WAAW;gDACjB,OAAO,EAAE,aAAa,CAAC,MAAM,IAAI,aAAa,CAAC,OAAO,IAAI,aAAa;6CACxE;4CACD,aAAa,EAAE,MAAM;yCACtB,CAAC;oCACF,KAAK,EAAE;wCACL,aAAa,EAAE,CAAC;wCAChB,iBAAiB,EAAE,CAAC;wCACpB,YAAY,EAAE,CAAC;qCAChB;iCACF,CAAC;gCAEF,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,EAAE;oCAClD,MAAM,EAAE,GAAG;oCACX,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;iCAChD,CAAC,CAAC;4BACL,CAAC;wBACH,CAAC;wBAED,uCAAuC;wBACvC,OAAO,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;oBAC5B,CAAC;iBACF,CAAC;YACJ,CAAC;SACF;KACF,CAAC;AACJ,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-puter-auth",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"description": "Puter.com OAuth auth plugin for OpenCode - FREE UNLIMITED access to Claude Opus 4.5, Sonnet 4.5, GPT-5, Gemini, and 500+ AI models",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|