@puckeditor/cloud-client 0.8.0-canary.9c5fbcbb → 0.8.0-canary.ad0c4c0e
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-XFKCRMW6.mjs → chunk-BEW26CFQ.mjs} +121 -16
- package/dist/experimental.d.mts +3 -1
- package/dist/experimental.d.ts +3 -1
- package/dist/experimental.js +120 -16
- package/dist/experimental.mjs +3 -2
- package/dist/index.d.mts +643 -2
- package/dist/index.d.ts +643 -2
- package/dist/index.js +120 -16
- package/dist/index.mjs +1 -1
- package/package.json +10 -9
|
@@ -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.ad0c4c0e" : "unknown";
|
|
22187
22243
|
var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
|
|
22188
22244
|
const {
|
|
22189
22245
|
ai = {},
|
|
@@ -22196,19 +22252,31 @@ 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 = {} } = 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({
|
|
22209
22273
|
...body,
|
|
22210
22274
|
context,
|
|
22211
|
-
tools: prepareUserTools(tools)
|
|
22275
|
+
tools: prepareUserTools(tools),
|
|
22276
|
+
...designMode ? {
|
|
22277
|
+
designMode
|
|
22278
|
+
} : {},
|
|
22279
|
+
...model ? { byok: { model, providerOptions } } : {}
|
|
22212
22280
|
})
|
|
22213
22281
|
});
|
|
22214
22282
|
if (!res.body) {
|
|
@@ -22230,12 +22298,34 @@ var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
|
|
|
22230
22298
|
};
|
|
22231
22299
|
|
|
22232
22300
|
// src/api/chat.ts
|
|
22301
|
+
function chatPrivate({ chatId, messages, config: config2, pageData, mode }, options = {}, forwardHeaders) {
|
|
22302
|
+
const resolvedMode = mode ?? options?.ai?.mode;
|
|
22303
|
+
const stream = createUIMessageStream({
|
|
22304
|
+
execute: async ({ writer }) => {
|
|
22305
|
+
await cloudApi(
|
|
22306
|
+
"chat",
|
|
22307
|
+
{ chatId, config: config2, messages, pageData, mode: resolvedMode },
|
|
22308
|
+
options,
|
|
22309
|
+
(chunk) => {
|
|
22310
|
+
if (chunk.type === "data-finish") {
|
|
22311
|
+
options.ai?.onFinish?.(chunk.data);
|
|
22312
|
+
} else {
|
|
22313
|
+
writer.write(chunk);
|
|
22314
|
+
}
|
|
22315
|
+
},
|
|
22316
|
+
forwardHeaders
|
|
22317
|
+
);
|
|
22318
|
+
}
|
|
22319
|
+
});
|
|
22320
|
+
return createUIMessageStreamResponse({ stream });
|
|
22321
|
+
}
|
|
22233
22322
|
function chat({ chatId, messages, config: config2, pageData }, options = {}, forwardHeaders) {
|
|
22323
|
+
const resolvedMode = options?.ai?.mode;
|
|
22234
22324
|
const stream = createUIMessageStream({
|
|
22235
22325
|
execute: async ({ writer }) => {
|
|
22236
22326
|
await cloudApi(
|
|
22237
22327
|
"chat",
|
|
22238
|
-
{ chatId, config: config2, messages, pageData },
|
|
22328
|
+
{ chatId, config: config2, messages, pageData, mode: resolvedMode },
|
|
22239
22329
|
options,
|
|
22240
22330
|
(chunk) => {
|
|
22241
22331
|
if (chunk.type === "data-finish") {
|
|
@@ -22259,21 +22349,35 @@ async function generate({
|
|
|
22259
22349
|
pageData,
|
|
22260
22350
|
context,
|
|
22261
22351
|
tools,
|
|
22352
|
+
mode,
|
|
22353
|
+
designMode,
|
|
22262
22354
|
apiKey,
|
|
22263
22355
|
host,
|
|
22264
|
-
onFinish
|
|
22356
|
+
onFinish,
|
|
22357
|
+
model,
|
|
22358
|
+
providerApiKey,
|
|
22359
|
+
providerOptions
|
|
22265
22360
|
}) {
|
|
22266
22361
|
let result = null;
|
|
22267
|
-
const options = {
|
|
22268
|
-
|
|
22269
|
-
|
|
22270
|
-
|
|
22271
|
-
|
|
22272
|
-
|
|
22273
|
-
|
|
22274
|
-
|
|
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
|
+
}
|
|
22275
22379
|
}
|
|
22276
|
-
|
|
22380
|
+
);
|
|
22277
22381
|
return result;
|
|
22278
22382
|
}
|
|
22279
22383
|
|
|
@@ -22442,7 +22546,7 @@ var routeRegistry = [
|
|
|
22442
22546
|
{
|
|
22443
22547
|
pattern: "/api/puck/chat",
|
|
22444
22548
|
methods: {
|
|
22445
|
-
POST: ({ body, headers }, options) =>
|
|
22549
|
+
POST: ({ body, headers }, options) => chatPrivate(body, options, {
|
|
22446
22550
|
pluginAiVersion: headers.get("x-puck-plugin-ai-version")
|
|
22447
22551
|
})
|
|
22448
22552
|
}
|
|
@@ -22511,6 +22615,7 @@ var endpoints = ["chat"];
|
|
|
22511
22615
|
|
|
22512
22616
|
export {
|
|
22513
22617
|
getApiKey,
|
|
22618
|
+
chatPrivate,
|
|
22514
22619
|
chat,
|
|
22515
22620
|
createAttachments,
|
|
22516
22621
|
getAttachment,
|
package/dist/experimental.d.mts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { PuckCloudOptions as PuckCloudOptions$1 } from './index.mjs';
|
|
2
|
-
export { ChatParams, 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, 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.ad0c4c0e" : "unknown";
|
|
22230
22286
|
var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
|
|
22231
22287
|
const {
|
|
22232
22288
|
ai = {},
|
|
@@ -22239,19 +22295,31 @@ 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 = {} } = 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({
|
|
22252
22316
|
...body,
|
|
22253
22317
|
context,
|
|
22254
|
-
tools: prepareUserTools(tools)
|
|
22318
|
+
tools: prepareUserTools(tools),
|
|
22319
|
+
...designMode ? {
|
|
22320
|
+
designMode
|
|
22321
|
+
} : {},
|
|
22322
|
+
...model ? { byok: { model, providerOptions } } : {}
|
|
22255
22323
|
})
|
|
22256
22324
|
});
|
|
22257
22325
|
if (!res.body) {
|
|
@@ -22273,12 +22341,34 @@ var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
|
|
|
22273
22341
|
};
|
|
22274
22342
|
|
|
22275
22343
|
// src/api/chat.ts
|
|
22344
|
+
function chatPrivate({ chatId, messages, config: config2, pageData, mode }, options = {}, forwardHeaders) {
|
|
22345
|
+
const resolvedMode = mode ?? options?.ai?.mode;
|
|
22346
|
+
const stream = createUIMessageStream({
|
|
22347
|
+
execute: async ({ writer }) => {
|
|
22348
|
+
await cloudApi(
|
|
22349
|
+
"chat",
|
|
22350
|
+
{ chatId, config: config2, messages, pageData, mode: resolvedMode },
|
|
22351
|
+
options,
|
|
22352
|
+
(chunk) => {
|
|
22353
|
+
if (chunk.type === "data-finish") {
|
|
22354
|
+
options.ai?.onFinish?.(chunk.data);
|
|
22355
|
+
} else {
|
|
22356
|
+
writer.write(chunk);
|
|
22357
|
+
}
|
|
22358
|
+
},
|
|
22359
|
+
forwardHeaders
|
|
22360
|
+
);
|
|
22361
|
+
}
|
|
22362
|
+
});
|
|
22363
|
+
return createUIMessageStreamResponse({ stream });
|
|
22364
|
+
}
|
|
22276
22365
|
function chat({ chatId, messages, config: config2, pageData }, options = {}, forwardHeaders) {
|
|
22366
|
+
const resolvedMode = options?.ai?.mode;
|
|
22277
22367
|
const stream = createUIMessageStream({
|
|
22278
22368
|
execute: async ({ writer }) => {
|
|
22279
22369
|
await cloudApi(
|
|
22280
22370
|
"chat",
|
|
22281
|
-
{ chatId, config: config2, messages, pageData },
|
|
22371
|
+
{ chatId, config: config2, messages, pageData, mode: resolvedMode },
|
|
22282
22372
|
options,
|
|
22283
22373
|
(chunk) => {
|
|
22284
22374
|
if (chunk.type === "data-finish") {
|
|
@@ -22788,21 +22878,35 @@ async function generate({
|
|
|
22788
22878
|
pageData,
|
|
22789
22879
|
context,
|
|
22790
22880
|
tools,
|
|
22881
|
+
mode,
|
|
22882
|
+
designMode,
|
|
22791
22883
|
apiKey,
|
|
22792
22884
|
host,
|
|
22793
|
-
onFinish
|
|
22885
|
+
onFinish,
|
|
22886
|
+
model,
|
|
22887
|
+
providerApiKey,
|
|
22888
|
+
providerOptions
|
|
22794
22889
|
}) {
|
|
22795
22890
|
let result = null;
|
|
22796
|
-
const options = {
|
|
22797
|
-
|
|
22798
|
-
|
|
22799
|
-
|
|
22800
|
-
|
|
22801
|
-
|
|
22802
|
-
|
|
22803
|
-
|
|
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
|
+
}
|
|
22804
22908
|
}
|
|
22805
|
-
|
|
22909
|
+
);
|
|
22806
22910
|
return result;
|
|
22807
22911
|
}
|
|
22808
22912
|
|
|
@@ -22833,7 +22937,7 @@ var routeRegistry = [
|
|
|
22833
22937
|
{
|
|
22834
22938
|
pattern: "/api/puck/chat",
|
|
22835
22939
|
methods: {
|
|
22836
|
-
POST: ({ body }, options) =>
|
|
22940
|
+
POST: ({ body }, options) => chatPrivate(body, options)
|
|
22837
22941
|
}
|
|
22838
22942
|
},
|
|
22839
22943
|
{
|
package/dist/experimental.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
chat,
|
|
3
|
+
chatPrivate,
|
|
3
4
|
clientTool,
|
|
4
5
|
createAttachments,
|
|
5
6
|
deleteAttachment,
|
|
@@ -10,7 +11,7 @@ import {
|
|
|
10
11
|
getAttachment,
|
|
11
12
|
handlePuckRequest,
|
|
12
13
|
tool
|
|
13
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-BEW26CFQ.mjs";
|
|
14
15
|
import {
|
|
15
16
|
init_react_import
|
|
16
17
|
} from "./chunk-O6DC5HI2.mjs";
|
|
@@ -327,7 +328,7 @@ var routeRegistry = [
|
|
|
327
328
|
{
|
|
328
329
|
pattern: "/api/puck/chat",
|
|
329
330
|
methods: {
|
|
330
|
-
POST: ({ body }, options) =>
|
|
331
|
+
POST: ({ body }, options) => chatPrivate(body, options)
|
|
331
332
|
}
|
|
332
333
|
},
|
|
333
334
|
{
|