opencloud-platform-sdk 1.1.0 → 1.2.0
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.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +45 -0
- package/dist/index.mjs +45 -0
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* opencloud-platform-sdk v1.2.0
|
|
3
3
|
* Official SDK for OpenCloud - AI App Marketplace
|
|
4
4
|
*
|
|
5
5
|
* Features:
|
|
6
6
|
* - Automatic preview/production mode detection
|
|
7
7
|
* - Works in bolt.diy/WebContainers preview
|
|
8
|
+
* - Auto-detects API keys from bolt.diy builder
|
|
8
9
|
* - Seamless transition to production with credits
|
|
9
10
|
*/
|
|
10
11
|
interface OpenCloudConfig {
|
|
@@ -55,6 +56,7 @@ declare class OpenCloudSDK {
|
|
|
55
56
|
setPreviewApiKey(key: string, provider?: 'openrouter' | 'anthropic' | 'openai'): void;
|
|
56
57
|
/**
|
|
57
58
|
* Get API key for preview mode
|
|
59
|
+
* Checks in order: config, localStorage, bolt.diy cookies
|
|
58
60
|
*/
|
|
59
61
|
private getPreviewApiKey;
|
|
60
62
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* opencloud-platform-sdk v1.2.0
|
|
3
3
|
* Official SDK for OpenCloud - AI App Marketplace
|
|
4
4
|
*
|
|
5
5
|
* Features:
|
|
6
6
|
* - Automatic preview/production mode detection
|
|
7
7
|
* - Works in bolt.diy/WebContainers preview
|
|
8
|
+
* - Auto-detects API keys from bolt.diy builder
|
|
8
9
|
* - Seamless transition to production with credits
|
|
9
10
|
*/
|
|
10
11
|
interface OpenCloudConfig {
|
|
@@ -55,6 +56,7 @@ declare class OpenCloudSDK {
|
|
|
55
56
|
setPreviewApiKey(key: string, provider?: 'openrouter' | 'anthropic' | 'openai'): void;
|
|
56
57
|
/**
|
|
57
58
|
* Get API key for preview mode
|
|
59
|
+
* Checks in order: config, localStorage, bolt.diy cookies
|
|
58
60
|
*/
|
|
59
61
|
private getPreviewApiKey;
|
|
60
62
|
/**
|
package/dist/index.js
CHANGED
|
@@ -30,6 +30,31 @@ var STORAGE_KEYS = {
|
|
|
30
30
|
OPENAI_KEY: "openai_api_key",
|
|
31
31
|
PREVIEW_PROVIDER: "opencloud_preview_provider"
|
|
32
32
|
};
|
|
33
|
+
function getCookie(name) {
|
|
34
|
+
if (typeof document === "undefined") return null;
|
|
35
|
+
const value = `; ${document.cookie}`;
|
|
36
|
+
const parts = value.split(`; ${name}=`);
|
|
37
|
+
if (parts.length === 2) {
|
|
38
|
+
const cookieValue = parts.pop()?.split(";").shift();
|
|
39
|
+
if (cookieValue) {
|
|
40
|
+
try {
|
|
41
|
+
return decodeURIComponent(cookieValue);
|
|
42
|
+
} catch {
|
|
43
|
+
return cookieValue;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
function getBoltApiKeys() {
|
|
50
|
+
const apiKeysCookie = getCookie("apiKeys");
|
|
51
|
+
if (!apiKeysCookie) return null;
|
|
52
|
+
try {
|
|
53
|
+
return JSON.parse(apiKeysCookie);
|
|
54
|
+
} catch {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
33
58
|
var OpenCloudSDK = class {
|
|
34
59
|
constructor() {
|
|
35
60
|
this._isPreviewMode = false;
|
|
@@ -86,6 +111,7 @@ var OpenCloudSDK = class {
|
|
|
86
111
|
}
|
|
87
112
|
/**
|
|
88
113
|
* Get API key for preview mode
|
|
114
|
+
* Checks in order: config, localStorage, bolt.diy cookies
|
|
89
115
|
*/
|
|
90
116
|
getPreviewApiKey() {
|
|
91
117
|
if (typeof window === "undefined") return null;
|
|
@@ -105,6 +131,25 @@ var OpenCloudSDK = class {
|
|
|
105
131
|
return { key: key2, provider: name.replace("_KEY", "").toLowerCase() };
|
|
106
132
|
}
|
|
107
133
|
}
|
|
134
|
+
const boltApiKeys = getBoltApiKeys();
|
|
135
|
+
if (boltApiKeys) {
|
|
136
|
+
const providerMappings = [
|
|
137
|
+
{ boltName: "OpenRouter", provider: "openrouter" },
|
|
138
|
+
{ boltName: "Anthropic", provider: "anthropic" },
|
|
139
|
+
{ boltName: "OpenAI", provider: "openai" },
|
|
140
|
+
// Also check with _API_KEY suffix (older format)
|
|
141
|
+
{ boltName: "OpenRouter_API_KEY", provider: "openrouter" },
|
|
142
|
+
{ boltName: "Anthropic_API_KEY", provider: "anthropic" },
|
|
143
|
+
{ boltName: "OpenAI_API_KEY", provider: "openai" }
|
|
144
|
+
];
|
|
145
|
+
for (const { boltName, provider: provider2 } of providerMappings) {
|
|
146
|
+
const apiKey = boltApiKeys[boltName];
|
|
147
|
+
if (apiKey && apiKey.length > 10 && !apiKey.includes("your_")) {
|
|
148
|
+
console.log(`[OpenCloudSDK] Using API key from bolt.diy (${provider2})`);
|
|
149
|
+
return { key: apiKey, provider: provider2 };
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
108
153
|
return null;
|
|
109
154
|
}
|
|
110
155
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -5,6 +5,31 @@ var STORAGE_KEYS = {
|
|
|
5
5
|
OPENAI_KEY: "openai_api_key",
|
|
6
6
|
PREVIEW_PROVIDER: "opencloud_preview_provider"
|
|
7
7
|
};
|
|
8
|
+
function getCookie(name) {
|
|
9
|
+
if (typeof document === "undefined") return null;
|
|
10
|
+
const value = `; ${document.cookie}`;
|
|
11
|
+
const parts = value.split(`; ${name}=`);
|
|
12
|
+
if (parts.length === 2) {
|
|
13
|
+
const cookieValue = parts.pop()?.split(";").shift();
|
|
14
|
+
if (cookieValue) {
|
|
15
|
+
try {
|
|
16
|
+
return decodeURIComponent(cookieValue);
|
|
17
|
+
} catch {
|
|
18
|
+
return cookieValue;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
function getBoltApiKeys() {
|
|
25
|
+
const apiKeysCookie = getCookie("apiKeys");
|
|
26
|
+
if (!apiKeysCookie) return null;
|
|
27
|
+
try {
|
|
28
|
+
return JSON.parse(apiKeysCookie);
|
|
29
|
+
} catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
8
33
|
var OpenCloudSDK = class {
|
|
9
34
|
constructor() {
|
|
10
35
|
this._isPreviewMode = false;
|
|
@@ -61,6 +86,7 @@ var OpenCloudSDK = class {
|
|
|
61
86
|
}
|
|
62
87
|
/**
|
|
63
88
|
* Get API key for preview mode
|
|
89
|
+
* Checks in order: config, localStorage, bolt.diy cookies
|
|
64
90
|
*/
|
|
65
91
|
getPreviewApiKey() {
|
|
66
92
|
if (typeof window === "undefined") return null;
|
|
@@ -80,6 +106,25 @@ var OpenCloudSDK = class {
|
|
|
80
106
|
return { key: key2, provider: name.replace("_KEY", "").toLowerCase() };
|
|
81
107
|
}
|
|
82
108
|
}
|
|
109
|
+
const boltApiKeys = getBoltApiKeys();
|
|
110
|
+
if (boltApiKeys) {
|
|
111
|
+
const providerMappings = [
|
|
112
|
+
{ boltName: "OpenRouter", provider: "openrouter" },
|
|
113
|
+
{ boltName: "Anthropic", provider: "anthropic" },
|
|
114
|
+
{ boltName: "OpenAI", provider: "openai" },
|
|
115
|
+
// Also check with _API_KEY suffix (older format)
|
|
116
|
+
{ boltName: "OpenRouter_API_KEY", provider: "openrouter" },
|
|
117
|
+
{ boltName: "Anthropic_API_KEY", provider: "anthropic" },
|
|
118
|
+
{ boltName: "OpenAI_API_KEY", provider: "openai" }
|
|
119
|
+
];
|
|
120
|
+
for (const { boltName, provider: provider2 } of providerMappings) {
|
|
121
|
+
const apiKey = boltApiKeys[boltName];
|
|
122
|
+
if (apiKey && apiKey.length > 10 && !apiKey.includes("your_")) {
|
|
123
|
+
console.log(`[OpenCloudSDK] Using API key from bolt.diy (${provider2})`);
|
|
124
|
+
return { key: apiKey, provider: provider2 };
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
83
128
|
return null;
|
|
84
129
|
}
|
|
85
130
|
/**
|