@puckeditor/cloud-client 0.8.0-canary.dc11b4e2 → 0.8.0-canary.fdb02235
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/{chunk-N6PJ6YM6.mjs → chunk-Q3KHF34V.mjs} +93 -17
- package/dist/experimental.d.mts +3 -1
- package/dist/experimental.d.ts +3 -1
- package/dist/experimental.js +93 -17
- package/dist/experimental.mjs +1 -1
- package/dist/index.d.mts +628 -2
- package/dist/index.d.ts +628 -2
- package/dist/index.js +93 -17
- package/dist/index.mjs +1 -1
- package/package.json +2 -1
|
@@ -22113,6 +22113,62 @@ var prepareUserTools = (toolRegistry) => Object.keys(toolRegistry).reduce(
|
|
|
22113
22113
|
{}
|
|
22114
22114
|
);
|
|
22115
22115
|
|
|
22116
|
+
// src/lib/seal-provider-key.ts
|
|
22117
|
+
init_react_import();
|
|
22118
|
+
var DEFAULT_SEALING_KEY = {
|
|
22119
|
+
kid: "puck-2026-07",
|
|
22120
|
+
publicKey: "MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAwg3kLK+8I4jz7dORQa4QM/QZ4uMBmYanJnSjgDnSCIjs3aUgRstrIe0RWhXcq0V/nzq/P8dIlVD3idyG2UlTXjJb41mPw3hg1zkjW36jtSfRxmkfQMgIEcfeGl9vTnAVdZnHpf720462ZJTxWt/Wg0Uj5202XilIWjjiM/uYzvUSNSHqqhb6hehvIu7qIHZ4nrA2KkkJyGT2IOTyuWAyApS6G9ju9+AjdIM85ycqufCdjMcso6yWnFjN3VYNfF2N9W10dvlgui0NDZjjTrl/6+ckkzAwknZBwoWl0x/cTW0zyiaUcaU4oytluFXBJM4ELIU+M9kal7ivC58WwULC22yvnZICcaGdX4h0/rlRPc6PppSbbN8NRWzNHkkqdPeqYWIJCcl0W1MvmWa2iTyhpI58Jo8VNBQbCTfdKLy/mGytg2FmBXQiwWHg212XBkG0LriBLWdfMW5KNgPu7z1bgC6Mlb7LIkjgR9qgkBNOgKf2NSuIRq+pn9GTxGJL9YhfSDnn77QExHl1QyieD1dIEDCJPX6USdSnhdi1paSRIenpJTAWcsVMtP/1nMCmSYLcCojXCATQkPALTv1ZrMv0xFL61yaW5JF9RMwYCwnh/TdS1AppdAY6ftZG3sQ3XrwTCCVbw1Cn1rxZ8t3tIbepeZ8CaRFiLuUqaSL0EGzi1x8CAwEAAQ=="
|
|
22121
|
+
};
|
|
22122
|
+
var MAX_PLAINTEXT_BYTES = 446;
|
|
22123
|
+
var fromBase64 = (b64) => {
|
|
22124
|
+
const binary = atob(b64);
|
|
22125
|
+
const bytes = new Uint8Array(new ArrayBuffer(binary.length));
|
|
22126
|
+
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
22127
|
+
return bytes;
|
|
22128
|
+
};
|
|
22129
|
+
var toBase64 = (bytes) => {
|
|
22130
|
+
let binary = "";
|
|
22131
|
+
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
22132
|
+
return btoa(binary);
|
|
22133
|
+
};
|
|
22134
|
+
var importCache = /* @__PURE__ */ new Map();
|
|
22135
|
+
var importPublicKey = (publicKey) => {
|
|
22136
|
+
let imported = importCache.get(publicKey);
|
|
22137
|
+
if (!imported) {
|
|
22138
|
+
imported = crypto.subtle.importKey(
|
|
22139
|
+
"spki",
|
|
22140
|
+
fromBase64(publicKey),
|
|
22141
|
+
{ name: "RSA-OAEP", hash: "SHA-256" },
|
|
22142
|
+
false,
|
|
22143
|
+
["encrypt"]
|
|
22144
|
+
);
|
|
22145
|
+
importCache.set(publicKey, imported);
|
|
22146
|
+
}
|
|
22147
|
+
return imported;
|
|
22148
|
+
};
|
|
22149
|
+
var activeSealingKey = DEFAULT_SEALING_KEY;
|
|
22150
|
+
var sealProviderKey = async (providerApiKey, puckApiKey) => {
|
|
22151
|
+
const sealingKey = activeSealingKey;
|
|
22152
|
+
if (typeof crypto === "undefined" || !crypto.subtle) {
|
|
22153
|
+
throw new Error(
|
|
22154
|
+
"BYOK requires the WebCrypto API (Node 18+ or an edge runtime) to encrypt the provider key"
|
|
22155
|
+
);
|
|
22156
|
+
}
|
|
22157
|
+
const encoder = new TextEncoder();
|
|
22158
|
+
const plaintext = encoder.encode(providerApiKey);
|
|
22159
|
+
if (plaintext.length > MAX_PLAINTEXT_BYTES) {
|
|
22160
|
+
throw new Error(
|
|
22161
|
+
`Provider API key is too long to seal (${plaintext.length} bytes, max ${MAX_PLAINTEXT_BYTES})`
|
|
22162
|
+
);
|
|
22163
|
+
}
|
|
22164
|
+
const ciphertext = await crypto.subtle.encrypt(
|
|
22165
|
+
{ name: "RSA-OAEP", label: encoder.encode(puckApiKey) },
|
|
22166
|
+
await importPublicKey(sealingKey.publicKey),
|
|
22167
|
+
plaintext
|
|
22168
|
+
);
|
|
22169
|
+
return `v1.${sealingKey.kid}.${toBase64(new Uint8Array(ciphertext))}`;
|
|
22170
|
+
};
|
|
22171
|
+
|
|
22116
22172
|
// src/lib/get-api-key.ts
|
|
22117
22173
|
init_react_import();
|
|
22118
22174
|
var getApiKey = () => process.env.PUCK_API_KEY;
|
|
@@ -22183,7 +22239,7 @@ async function* iterateSSE(body) {
|
|
|
22183
22239
|
|
|
22184
22240
|
// src/lib/cloud-api.ts
|
|
22185
22241
|
var DEFAULT_API_VERSION = "v2";
|
|
22186
|
-
var CLOUD_CLIENT_VERSION = true ? "0.8.0-canary.
|
|
22242
|
+
var CLOUD_CLIENT_VERSION = true ? "0.8.0-canary.fdb02235" : "unknown";
|
|
22187
22243
|
var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
|
|
22188
22244
|
const {
|
|
22189
22245
|
ai = {},
|
|
@@ -22196,13 +22252,21 @@ var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
|
|
|
22196
22252
|
"No Puck API key specified. Set the PUCK_API_KEY environment variable, or provide one to the function"
|
|
22197
22253
|
);
|
|
22198
22254
|
}
|
|
22199
|
-
const { context, tools = {}, designMode } = ai;
|
|
22255
|
+
const { context, tools = {}, designMode, model, providerOptions } = ai;
|
|
22256
|
+
const providerApiKey = model ? ai.providerApiKey ?? process.env.OPENAI_API_KEY : void 0;
|
|
22257
|
+
if (model && !providerApiKey) {
|
|
22258
|
+
throw new Error(
|
|
22259
|
+
`No provider API key found for "${model}". Please provide one via the providerApiKey parameter.`
|
|
22260
|
+
);
|
|
22261
|
+
}
|
|
22262
|
+
const sealedProviderKey = providerApiKey ? await sealProviderKey(providerApiKey, apiKey) : void 0;
|
|
22200
22263
|
const res = await fetch(`${host}/${path}`, {
|
|
22201
22264
|
headers: {
|
|
22202
22265
|
"x-api-key": apiKey,
|
|
22203
22266
|
"puck-api-version": apiVersion,
|
|
22204
22267
|
"x-puck-cloud-client-version": CLOUD_CLIENT_VERSION,
|
|
22205
|
-
...forwardHeaders?.pluginAiVersion ? { "x-puck-plugin-ai-version": forwardHeaders.pluginAiVersion } : {}
|
|
22268
|
+
...forwardHeaders?.pluginAiVersion ? { "x-puck-plugin-ai-version": forwardHeaders.pluginAiVersion } : {},
|
|
22269
|
+
...sealedProviderKey ? { "x-puck-provider-key": sealedProviderKey } : {}
|
|
22206
22270
|
},
|
|
22207
22271
|
method: "post",
|
|
22208
22272
|
body: JSON.stringify({
|
|
@@ -22211,7 +22275,8 @@ var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
|
|
|
22211
22275
|
tools: prepareUserTools(tools),
|
|
22212
22276
|
...designMode ? {
|
|
22213
22277
|
designMode
|
|
22214
|
-
} : {}
|
|
22278
|
+
} : {},
|
|
22279
|
+
...model ? { byok: { model, providerOptions } } : {}
|
|
22215
22280
|
})
|
|
22216
22281
|
});
|
|
22217
22282
|
if (!res.body) {
|
|
@@ -22284,24 +22349,35 @@ async function generate({
|
|
|
22284
22349
|
pageData,
|
|
22285
22350
|
context,
|
|
22286
22351
|
tools,
|
|
22352
|
+
mode,
|
|
22353
|
+
designMode,
|
|
22287
22354
|
apiKey,
|
|
22288
22355
|
host,
|
|
22289
|
-
onFinish
|
|
22356
|
+
onFinish,
|
|
22357
|
+
model,
|
|
22358
|
+
providerApiKey,
|
|
22359
|
+
providerOptions
|
|
22290
22360
|
}) {
|
|
22291
22361
|
let result = null;
|
|
22292
|
-
const options = {
|
|
22293
|
-
|
|
22294
|
-
|
|
22295
|
-
|
|
22296
|
-
|
|
22297
|
-
|
|
22298
|
-
|
|
22299
|
-
|
|
22362
|
+
const options = {
|
|
22363
|
+
ai: { context, tools, designMode, model, providerApiKey, providerOptions },
|
|
22364
|
+
apiKey,
|
|
22365
|
+
host
|
|
22366
|
+
};
|
|
22367
|
+
await cloudApi(
|
|
22368
|
+
"generate",
|
|
22369
|
+
{ prompt, config: config2, pageData, mode },
|
|
22370
|
+
options,
|
|
22371
|
+
(chunk) => {
|
|
22372
|
+
if (chunk.type === "data-page") {
|
|
22373
|
+
result = chunk.data;
|
|
22374
|
+
} else if (chunk.type === "data-finish") {
|
|
22375
|
+
onFinish?.(chunk.data);
|
|
22376
|
+
} else if (chunk.type === "error") {
|
|
22377
|
+
throw new Error(chunk.errorText);
|
|
22378
|
+
}
|
|
22300
22379
|
}
|
|
22301
|
-
|
|
22302
|
-
if (result === null) {
|
|
22303
|
-
throw new Error("Puck generate did not return any data");
|
|
22304
|
-
}
|
|
22380
|
+
);
|
|
22305
22381
|
return result;
|
|
22306
22382
|
}
|
|
22307
22383
|
|
package/dist/experimental.d.mts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { PuckCloudOptions as PuckCloudOptions$1 } from './index.mjs';
|
|
2
|
-
export { ChatParams, DesignModeOptions, Endpoint, GenerateParams, OnFinishCallback, OnFinishResult, UserTool, UserToolRegistry, chat, endpoints, generate, tool } from './index.mjs';
|
|
2
|
+
export { ChatParams, DesignModeOptions, Endpoint, GenerateParams, OnFinishCallback, OnFinishResult, PuckAiModel, PuckAiProviderOptions, UserTool, UserToolRegistry, chat, endpoints, generate, tool } from './index.mjs';
|
|
3
3
|
import { Data } from '@puckeditor/core';
|
|
4
|
+
import '@ai-sdk/provider';
|
|
5
|
+
import '@ai-sdk/provider-utils';
|
|
4
6
|
import 'zod/v4';
|
|
5
7
|
import 'ai';
|
|
6
8
|
|
package/dist/experimental.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { PuckCloudOptions as PuckCloudOptions$1 } from './index.js';
|
|
2
|
-
export { ChatParams, DesignModeOptions, Endpoint, GenerateParams, OnFinishCallback, OnFinishResult, UserTool, UserToolRegistry, chat, endpoints, generate, tool } from './index.js';
|
|
2
|
+
export { ChatParams, DesignModeOptions, Endpoint, GenerateParams, OnFinishCallback, OnFinishResult, PuckAiModel, PuckAiProviderOptions, UserTool, UserToolRegistry, chat, endpoints, generate, tool } from './index.js';
|
|
3
3
|
import { Data } from '@puckeditor/core';
|
|
4
|
+
import '@ai-sdk/provider';
|
|
5
|
+
import '@ai-sdk/provider-utils';
|
|
4
6
|
import 'zod/v4';
|
|
5
7
|
import 'ai';
|
|
6
8
|
|
package/dist/experimental.js
CHANGED
|
@@ -22156,6 +22156,62 @@ var prepareUserTools = (toolRegistry) => Object.keys(toolRegistry).reduce(
|
|
|
22156
22156
|
{}
|
|
22157
22157
|
);
|
|
22158
22158
|
|
|
22159
|
+
// src/lib/seal-provider-key.ts
|
|
22160
|
+
init_react_import();
|
|
22161
|
+
var DEFAULT_SEALING_KEY = {
|
|
22162
|
+
kid: "puck-2026-07",
|
|
22163
|
+
publicKey: "MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAwg3kLK+8I4jz7dORQa4QM/QZ4uMBmYanJnSjgDnSCIjs3aUgRstrIe0RWhXcq0V/nzq/P8dIlVD3idyG2UlTXjJb41mPw3hg1zkjW36jtSfRxmkfQMgIEcfeGl9vTnAVdZnHpf720462ZJTxWt/Wg0Uj5202XilIWjjiM/uYzvUSNSHqqhb6hehvIu7qIHZ4nrA2KkkJyGT2IOTyuWAyApS6G9ju9+AjdIM85ycqufCdjMcso6yWnFjN3VYNfF2N9W10dvlgui0NDZjjTrl/6+ckkzAwknZBwoWl0x/cTW0zyiaUcaU4oytluFXBJM4ELIU+M9kal7ivC58WwULC22yvnZICcaGdX4h0/rlRPc6PppSbbN8NRWzNHkkqdPeqYWIJCcl0W1MvmWa2iTyhpI58Jo8VNBQbCTfdKLy/mGytg2FmBXQiwWHg212XBkG0LriBLWdfMW5KNgPu7z1bgC6Mlb7LIkjgR9qgkBNOgKf2NSuIRq+pn9GTxGJL9YhfSDnn77QExHl1QyieD1dIEDCJPX6USdSnhdi1paSRIenpJTAWcsVMtP/1nMCmSYLcCojXCATQkPALTv1ZrMv0xFL61yaW5JF9RMwYCwnh/TdS1AppdAY6ftZG3sQ3XrwTCCVbw1Cn1rxZ8t3tIbepeZ8CaRFiLuUqaSL0EGzi1x8CAwEAAQ=="
|
|
22164
|
+
};
|
|
22165
|
+
var MAX_PLAINTEXT_BYTES = 446;
|
|
22166
|
+
var fromBase64 = (b64) => {
|
|
22167
|
+
const binary = atob(b64);
|
|
22168
|
+
const bytes = new Uint8Array(new ArrayBuffer(binary.length));
|
|
22169
|
+
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
22170
|
+
return bytes;
|
|
22171
|
+
};
|
|
22172
|
+
var toBase64 = (bytes) => {
|
|
22173
|
+
let binary = "";
|
|
22174
|
+
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
22175
|
+
return btoa(binary);
|
|
22176
|
+
};
|
|
22177
|
+
var importCache = /* @__PURE__ */ new Map();
|
|
22178
|
+
var importPublicKey = (publicKey) => {
|
|
22179
|
+
let imported = importCache.get(publicKey);
|
|
22180
|
+
if (!imported) {
|
|
22181
|
+
imported = crypto.subtle.importKey(
|
|
22182
|
+
"spki",
|
|
22183
|
+
fromBase64(publicKey),
|
|
22184
|
+
{ name: "RSA-OAEP", hash: "SHA-256" },
|
|
22185
|
+
false,
|
|
22186
|
+
["encrypt"]
|
|
22187
|
+
);
|
|
22188
|
+
importCache.set(publicKey, imported);
|
|
22189
|
+
}
|
|
22190
|
+
return imported;
|
|
22191
|
+
};
|
|
22192
|
+
var activeSealingKey = DEFAULT_SEALING_KEY;
|
|
22193
|
+
var sealProviderKey = async (providerApiKey, puckApiKey) => {
|
|
22194
|
+
const sealingKey = activeSealingKey;
|
|
22195
|
+
if (typeof crypto === "undefined" || !crypto.subtle) {
|
|
22196
|
+
throw new Error(
|
|
22197
|
+
"BYOK requires the WebCrypto API (Node 18+ or an edge runtime) to encrypt the provider key"
|
|
22198
|
+
);
|
|
22199
|
+
}
|
|
22200
|
+
const encoder = new TextEncoder();
|
|
22201
|
+
const plaintext = encoder.encode(providerApiKey);
|
|
22202
|
+
if (plaintext.length > MAX_PLAINTEXT_BYTES) {
|
|
22203
|
+
throw new Error(
|
|
22204
|
+
`Provider API key is too long to seal (${plaintext.length} bytes, max ${MAX_PLAINTEXT_BYTES})`
|
|
22205
|
+
);
|
|
22206
|
+
}
|
|
22207
|
+
const ciphertext = await crypto.subtle.encrypt(
|
|
22208
|
+
{ name: "RSA-OAEP", label: encoder.encode(puckApiKey) },
|
|
22209
|
+
await importPublicKey(sealingKey.publicKey),
|
|
22210
|
+
plaintext
|
|
22211
|
+
);
|
|
22212
|
+
return `v1.${sealingKey.kid}.${toBase64(new Uint8Array(ciphertext))}`;
|
|
22213
|
+
};
|
|
22214
|
+
|
|
22159
22215
|
// src/lib/get-api-key.ts
|
|
22160
22216
|
init_react_import();
|
|
22161
22217
|
var getApiKey = () => process.env.PUCK_API_KEY;
|
|
@@ -22226,7 +22282,7 @@ async function* iterateSSE(body) {
|
|
|
22226
22282
|
|
|
22227
22283
|
// src/lib/cloud-api.ts
|
|
22228
22284
|
var DEFAULT_API_VERSION = "v2";
|
|
22229
|
-
var CLOUD_CLIENT_VERSION = true ? "0.8.0-canary.
|
|
22285
|
+
var CLOUD_CLIENT_VERSION = true ? "0.8.0-canary.fdb02235" : "unknown";
|
|
22230
22286
|
var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
|
|
22231
22287
|
const {
|
|
22232
22288
|
ai = {},
|
|
@@ -22239,13 +22295,21 @@ var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
|
|
|
22239
22295
|
"No Puck API key specified. Set the PUCK_API_KEY environment variable, or provide one to the function"
|
|
22240
22296
|
);
|
|
22241
22297
|
}
|
|
22242
|
-
const { context, tools = {}, designMode } = ai;
|
|
22298
|
+
const { context, tools = {}, designMode, model, providerOptions } = ai;
|
|
22299
|
+
const providerApiKey = model ? ai.providerApiKey ?? process.env.OPENAI_API_KEY : void 0;
|
|
22300
|
+
if (model && !providerApiKey) {
|
|
22301
|
+
throw new Error(
|
|
22302
|
+
`No provider API key found for "${model}". Please provide one via the providerApiKey parameter.`
|
|
22303
|
+
);
|
|
22304
|
+
}
|
|
22305
|
+
const sealedProviderKey = providerApiKey ? await sealProviderKey(providerApiKey, apiKey) : void 0;
|
|
22243
22306
|
const res = await fetch(`${host}/${path}`, {
|
|
22244
22307
|
headers: {
|
|
22245
22308
|
"x-api-key": apiKey,
|
|
22246
22309
|
"puck-api-version": apiVersion,
|
|
22247
22310
|
"x-puck-cloud-client-version": CLOUD_CLIENT_VERSION,
|
|
22248
|
-
...forwardHeaders?.pluginAiVersion ? { "x-puck-plugin-ai-version": forwardHeaders.pluginAiVersion } : {}
|
|
22311
|
+
...forwardHeaders?.pluginAiVersion ? { "x-puck-plugin-ai-version": forwardHeaders.pluginAiVersion } : {},
|
|
22312
|
+
...sealedProviderKey ? { "x-puck-provider-key": sealedProviderKey } : {}
|
|
22249
22313
|
},
|
|
22250
22314
|
method: "post",
|
|
22251
22315
|
body: JSON.stringify({
|
|
@@ -22254,7 +22318,8 @@ var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
|
|
|
22254
22318
|
tools: prepareUserTools(tools),
|
|
22255
22319
|
...designMode ? {
|
|
22256
22320
|
designMode
|
|
22257
|
-
} : {}
|
|
22321
|
+
} : {},
|
|
22322
|
+
...model ? { byok: { model, providerOptions } } : {}
|
|
22258
22323
|
})
|
|
22259
22324
|
});
|
|
22260
22325
|
if (!res.body) {
|
|
@@ -22813,24 +22878,35 @@ async function generate({
|
|
|
22813
22878
|
pageData,
|
|
22814
22879
|
context,
|
|
22815
22880
|
tools,
|
|
22881
|
+
mode,
|
|
22882
|
+
designMode,
|
|
22816
22883
|
apiKey,
|
|
22817
22884
|
host,
|
|
22818
|
-
onFinish
|
|
22885
|
+
onFinish,
|
|
22886
|
+
model,
|
|
22887
|
+
providerApiKey,
|
|
22888
|
+
providerOptions
|
|
22819
22889
|
}) {
|
|
22820
22890
|
let result = null;
|
|
22821
|
-
const options = {
|
|
22822
|
-
|
|
22823
|
-
|
|
22824
|
-
|
|
22825
|
-
|
|
22826
|
-
|
|
22827
|
-
|
|
22828
|
-
|
|
22891
|
+
const options = {
|
|
22892
|
+
ai: { context, tools, designMode, model, providerApiKey, providerOptions },
|
|
22893
|
+
apiKey,
|
|
22894
|
+
host
|
|
22895
|
+
};
|
|
22896
|
+
await cloudApi(
|
|
22897
|
+
"generate",
|
|
22898
|
+
{ prompt, config: config2, pageData, mode },
|
|
22899
|
+
options,
|
|
22900
|
+
(chunk) => {
|
|
22901
|
+
if (chunk.type === "data-page") {
|
|
22902
|
+
result = chunk.data;
|
|
22903
|
+
} else if (chunk.type === "data-finish") {
|
|
22904
|
+
onFinish?.(chunk.data);
|
|
22905
|
+
} else if (chunk.type === "error") {
|
|
22906
|
+
throw new Error(chunk.errorText);
|
|
22907
|
+
}
|
|
22829
22908
|
}
|
|
22830
|
-
|
|
22831
|
-
if (result === null) {
|
|
22832
|
-
throw new Error("Puck generate did not return any data");
|
|
22833
|
-
}
|
|
22909
|
+
);
|
|
22834
22910
|
return result;
|
|
22835
22911
|
}
|
|
22836
22912
|
|