opencode-puter-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/README.md +26 -0
- package/dist/ai-provider/index.d.ts +28 -0
- package/dist/ai-provider/index.d.ts.map +1 -0
- package/dist/ai-provider/index.js +28 -0
- package/dist/ai-provider/index.js.map +1 -0
- package/dist/ai-provider/puter-chat-language-model.d.ts +53 -0
- package/dist/ai-provider/puter-chat-language-model.d.ts.map +1 -0
- package/dist/ai-provider/puter-chat-language-model.js +405 -0
- package/dist/ai-provider/puter-chat-language-model.js.map +1 -0
- package/dist/ai-provider/puter-chat-settings.d.ts +106 -0
- package/dist/ai-provider/puter-chat-settings.d.ts.map +1 -0
- package/dist/ai-provider/puter-chat-settings.js +7 -0
- package/dist/ai-provider/puter-chat-settings.js.map +1 -0
- package/dist/ai-provider/puter-provider.d.ts +58 -0
- package/dist/ai-provider/puter-provider.d.ts.map +1 -0
- package/dist/ai-provider/puter-provider.js +149 -0
- package/dist/ai-provider/puter-provider.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +18 -4
- package/dist/plugin.js.map +1 -1
- package/dist/provider.d.ts +228 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +611 -0
- package/dist/provider.js.map +1 -0
- package/package.json +3 -1
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Puter Provider Integration
|
|
3
|
+
*
|
|
4
|
+
* This module provides two transformation paths:
|
|
5
|
+
*
|
|
6
|
+
* 1. Google Generative Language API format (for google provider integration)
|
|
7
|
+
* - Used when Puter models are configured under provider.google
|
|
8
|
+
* - Transforms Google's format to Puter's format
|
|
9
|
+
*
|
|
10
|
+
* 2. OpenAI-compatible format (for standalone puter provider)
|
|
11
|
+
* - Used when Puter is configured as a separate provider with @ai-sdk/openai-compatible
|
|
12
|
+
* - Transforms OpenAI's format to Puter's format
|
|
13
|
+
*
|
|
14
|
+
* The custom fetch function intercepts requests and routes them to Puter's API.
|
|
15
|
+
*/
|
|
16
|
+
import type { PuterChatMessage, PuterChatStreamChunk, PuterConfig } from './types.js';
|
|
17
|
+
/**
|
|
18
|
+
* Check if a request is targeting the Puter provider
|
|
19
|
+
*/
|
|
20
|
+
export declare function isPuterRequest(input: RequestInfo | URL): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Check if the request is using OpenAI format (vs Google format)
|
|
23
|
+
*/
|
|
24
|
+
export declare function isOpenAIFormat(url: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Extract model ID from the request URL
|
|
27
|
+
*/
|
|
28
|
+
export declare function extractModelFromUrl(url: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* Check if the request is for streaming
|
|
31
|
+
*/
|
|
32
|
+
export declare function isStreamingRequest(url: string): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Transform OpenAI chat completion request to Puter format
|
|
35
|
+
*/
|
|
36
|
+
export declare function transformOpenAIToPuter(body: OpenAIChatCompletionRequest, authToken: string): PuterRequestBody;
|
|
37
|
+
/**
|
|
38
|
+
* Transform Puter response to OpenAI chat completion format
|
|
39
|
+
*/
|
|
40
|
+
export declare function transformPuterToOpenAI(puterResponse: PuterChatResponse): OpenAIChatCompletionResponse;
|
|
41
|
+
/**
|
|
42
|
+
* Transform Puter stream chunk to OpenAI SSE format
|
|
43
|
+
*/
|
|
44
|
+
export declare function transformPuterStreamToOpenAI(chunk: PuterChatStreamChunk): string;
|
|
45
|
+
/**
|
|
46
|
+
* Transform Google Generative Language API request body to Puter format
|
|
47
|
+
*/
|
|
48
|
+
export declare function transformRequestToPuter(body: GoogleGenerateContentRequest, model: string, streaming: boolean, authToken: string): PuterRequestBody;
|
|
49
|
+
/**
|
|
50
|
+
* Transform Puter response to Google Generative Language API format
|
|
51
|
+
*/
|
|
52
|
+
export declare function transformPuterResponseToGoogle(puterResponse: PuterChatResponse): GoogleGenerateContentResponse;
|
|
53
|
+
/**
|
|
54
|
+
* Transform a Puter streaming chunk to Google SSE format
|
|
55
|
+
*/
|
|
56
|
+
export declare function transformPuterStreamChunkToGoogle(chunk: PuterChatStreamChunk): string;
|
|
57
|
+
/**
|
|
58
|
+
* Make a request to Puter API and return transformed response
|
|
59
|
+
*/
|
|
60
|
+
export declare function makePuterRequest(input: RequestInfo | URL, init: RequestInit | undefined, authToken: string, config?: Partial<PuterConfig>): Promise<Response>;
|
|
61
|
+
/**
|
|
62
|
+
* Create a custom fetch function for Puter provider integration.
|
|
63
|
+
*
|
|
64
|
+
* This function intercepts requests to Puter endpoints and routes them
|
|
65
|
+
* through Puter's API with proper request/response transformation.
|
|
66
|
+
*
|
|
67
|
+
* Supports both OpenAI-compatible format (for standalone puter provider)
|
|
68
|
+
* and Google Generative Language API format (for google provider integration).
|
|
69
|
+
*
|
|
70
|
+
* @param authToken - The Puter authentication token
|
|
71
|
+
* @param config - Optional Puter configuration
|
|
72
|
+
* @returns A fetch function that can be used by OpenCode's AI SDK
|
|
73
|
+
*/
|
|
74
|
+
export declare function createPuterFetch(authToken: string, config?: Partial<PuterConfig>): typeof fetch;
|
|
75
|
+
interface OpenAIChatCompletionRequest {
|
|
76
|
+
model?: string;
|
|
77
|
+
messages?: Array<{
|
|
78
|
+
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
79
|
+
content: string | null;
|
|
80
|
+
tool_call_id?: string;
|
|
81
|
+
tool_calls?: Array<{
|
|
82
|
+
id: string;
|
|
83
|
+
type: 'function';
|
|
84
|
+
function: {
|
|
85
|
+
name: string;
|
|
86
|
+
arguments: string;
|
|
87
|
+
};
|
|
88
|
+
}>;
|
|
89
|
+
}>;
|
|
90
|
+
tools?: Array<{
|
|
91
|
+
type: 'function';
|
|
92
|
+
function: {
|
|
93
|
+
name: string;
|
|
94
|
+
description?: string;
|
|
95
|
+
parameters?: Record<string, unknown>;
|
|
96
|
+
};
|
|
97
|
+
}>;
|
|
98
|
+
max_tokens?: number;
|
|
99
|
+
temperature?: number;
|
|
100
|
+
stream?: boolean;
|
|
101
|
+
}
|
|
102
|
+
interface OpenAIChatCompletionResponse {
|
|
103
|
+
id: string;
|
|
104
|
+
object: 'chat.completion';
|
|
105
|
+
created: number;
|
|
106
|
+
model: string;
|
|
107
|
+
choices: Array<{
|
|
108
|
+
index: number;
|
|
109
|
+
message: {
|
|
110
|
+
role: 'assistant';
|
|
111
|
+
content: string | null;
|
|
112
|
+
tool_calls?: Array<{
|
|
113
|
+
id: string;
|
|
114
|
+
type: 'function';
|
|
115
|
+
function: {
|
|
116
|
+
name: string;
|
|
117
|
+
arguments: string;
|
|
118
|
+
};
|
|
119
|
+
}>;
|
|
120
|
+
};
|
|
121
|
+
finish_reason: 'stop' | 'tool_calls' | 'length' | null;
|
|
122
|
+
}>;
|
|
123
|
+
usage?: {
|
|
124
|
+
prompt_tokens: number;
|
|
125
|
+
completion_tokens: number;
|
|
126
|
+
total_tokens: number;
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
interface GooglePart {
|
|
130
|
+
text?: string;
|
|
131
|
+
thought?: boolean;
|
|
132
|
+
functionCall?: {
|
|
133
|
+
name: string;
|
|
134
|
+
args: unknown;
|
|
135
|
+
};
|
|
136
|
+
functionResponse?: {
|
|
137
|
+
name: string;
|
|
138
|
+
response: unknown;
|
|
139
|
+
id?: string;
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
interface GoogleContent {
|
|
143
|
+
role: string;
|
|
144
|
+
parts: GooglePart[];
|
|
145
|
+
}
|
|
146
|
+
interface GoogleGenerateContentRequest {
|
|
147
|
+
contents?: GoogleContent[];
|
|
148
|
+
systemInstruction?: string | {
|
|
149
|
+
parts: {
|
|
150
|
+
text: string;
|
|
151
|
+
}[];
|
|
152
|
+
};
|
|
153
|
+
generationConfig?: {
|
|
154
|
+
maxOutputTokens?: number;
|
|
155
|
+
temperature?: number;
|
|
156
|
+
topP?: number;
|
|
157
|
+
topK?: number;
|
|
158
|
+
thinkingConfig?: {
|
|
159
|
+
thinkingBudget?: number;
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
tools?: Array<{
|
|
163
|
+
functionDeclarations?: Array<{
|
|
164
|
+
name: string;
|
|
165
|
+
description?: string;
|
|
166
|
+
parameters?: Record<string, unknown>;
|
|
167
|
+
}>;
|
|
168
|
+
}>;
|
|
169
|
+
}
|
|
170
|
+
interface GoogleGenerateContentResponse {
|
|
171
|
+
candidates: Array<{
|
|
172
|
+
content: {
|
|
173
|
+
role: string;
|
|
174
|
+
parts: GooglePart[];
|
|
175
|
+
};
|
|
176
|
+
finishReason?: string;
|
|
177
|
+
index: number;
|
|
178
|
+
}>;
|
|
179
|
+
usageMetadata?: {
|
|
180
|
+
promptTokenCount?: number;
|
|
181
|
+
candidatesTokenCount?: number;
|
|
182
|
+
totalTokenCount?: number;
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
interface PuterTool {
|
|
186
|
+
type: 'function';
|
|
187
|
+
function: {
|
|
188
|
+
name: string;
|
|
189
|
+
description: string;
|
|
190
|
+
parameters: Record<string, unknown>;
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
interface PuterRequestBody {
|
|
194
|
+
interface: string;
|
|
195
|
+
service: string;
|
|
196
|
+
method: string;
|
|
197
|
+
args: {
|
|
198
|
+
messages: PuterChatMessage[];
|
|
199
|
+
model: string;
|
|
200
|
+
stream: boolean;
|
|
201
|
+
max_tokens?: number;
|
|
202
|
+
temperature?: number;
|
|
203
|
+
tools?: PuterTool[];
|
|
204
|
+
};
|
|
205
|
+
auth_token: string;
|
|
206
|
+
}
|
|
207
|
+
interface PuterChatResponse {
|
|
208
|
+
message?: {
|
|
209
|
+
role: string;
|
|
210
|
+
content: string | null;
|
|
211
|
+
tool_calls?: Array<{
|
|
212
|
+
id: string;
|
|
213
|
+
type: string;
|
|
214
|
+
function: {
|
|
215
|
+
name: string;
|
|
216
|
+
arguments: string;
|
|
217
|
+
};
|
|
218
|
+
}>;
|
|
219
|
+
};
|
|
220
|
+
finish_reason?: string;
|
|
221
|
+
usage?: {
|
|
222
|
+
prompt_tokens: number;
|
|
223
|
+
completion_tokens: number;
|
|
224
|
+
total_tokens: number;
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
export {};
|
|
228
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAUtF;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,WAAW,GAAG,GAAG,GAAG,OAAO,CAchE;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEnD;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAUvD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEvD;AAMD;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,2BAA2B,EACjC,SAAS,EAAE,MAAM,GAChB,gBAAgB,CAgElB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,aAAa,EAAE,iBAAiB,GAAG,4BAA4B,CA8BrG;AAED;;GAEG;AACH,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,oBAAoB,GAAG,MAAM,CAqChF;AAoED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,4BAA4B,EAClC,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,OAAO,EAClB,SAAS,EAAE,MAAM,GAChB,gBAAgB,CA0DlB;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