@puckeditor/cloud-client 0.8.0-canary.844eb87d → 0.8.0-canary.847b2ca9
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-NYUJ34K5.mjs → chunk-6YFG2NZY.mjs} +93 -11
- package/dist/experimental.d.mts +3 -1
- package/dist/experimental.d.ts +3 -1
- package/dist/experimental.js +90 -10
- package/dist/experimental.mjs +1 -1
- package/dist/index.d.mts +629 -3
- package/dist/index.d.ts +629 -3
- package/dist/index.js +93 -11
- package/dist/index.mjs +1 -1
- package/package.json +3 -2
|
@@ -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,8 @@ async function* iterateSSE(body) {
|
|
|
22183
22239
|
|
|
22184
22240
|
// src/lib/cloud-api.ts
|
|
22185
22241
|
var DEFAULT_API_VERSION = "v2";
|
|
22186
|
-
var
|
|
22242
|
+
var CLOUD_CLIENT_VERSION = true ? "0.8.0-canary.847b2ca9" : "unknown";
|
|
22243
|
+
var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
|
|
22187
22244
|
const {
|
|
22188
22245
|
ai = {},
|
|
22189
22246
|
apiKey = getApiKey(),
|
|
@@ -22195,9 +22252,22 @@ var cloudApi = async (path, body, options = {}, onChunk) => {
|
|
|
22195
22252
|
"No Puck API key specified. Set the PUCK_API_KEY environment variable, or provide one to the function"
|
|
22196
22253
|
);
|
|
22197
22254
|
}
|
|
22198
|
-
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;
|
|
22199
22263
|
const res = await fetch(`${host}/${path}`, {
|
|
22200
|
-
headers: {
|
|
22264
|
+
headers: {
|
|
22265
|
+
"x-api-key": apiKey,
|
|
22266
|
+
"puck-api-version": apiVersion,
|
|
22267
|
+
"x-puck-cloud-client-version": CLOUD_CLIENT_VERSION,
|
|
22268
|
+
...forwardHeaders?.pluginAiVersion ? { "x-puck-plugin-ai-version": forwardHeaders.pluginAiVersion } : {},
|
|
22269
|
+
...sealedProviderKey ? { "x-puck-provider-key": sealedProviderKey } : {}
|
|
22270
|
+
},
|
|
22201
22271
|
method: "post",
|
|
22202
22272
|
body: JSON.stringify({
|
|
22203
22273
|
...body,
|
|
@@ -22205,7 +22275,8 @@ var cloudApi = async (path, body, options = {}, onChunk) => {
|
|
|
22205
22275
|
tools: prepareUserTools(tools),
|
|
22206
22276
|
...designMode ? {
|
|
22207
22277
|
designMode
|
|
22208
|
-
} : {}
|
|
22278
|
+
} : {},
|
|
22279
|
+
...model ? { byok: { model, providerOptions } } : {}
|
|
22209
22280
|
})
|
|
22210
22281
|
});
|
|
22211
22282
|
if (!res.body) {
|
|
@@ -22227,7 +22298,7 @@ var cloudApi = async (path, body, options = {}, onChunk) => {
|
|
|
22227
22298
|
};
|
|
22228
22299
|
|
|
22229
22300
|
// src/api/chat.ts
|
|
22230
|
-
function chatPrivate({ chatId, messages, config: config2, pageData, mode }, options = {}) {
|
|
22301
|
+
function chatPrivate({ chatId, messages, config: config2, pageData, mode }, options = {}, forwardHeaders) {
|
|
22231
22302
|
const resolvedMode = mode ?? options?.ai?.mode;
|
|
22232
22303
|
const stream = createUIMessageStream({
|
|
22233
22304
|
execute: async ({ writer }) => {
|
|
@@ -22241,13 +22312,14 @@ function chatPrivate({ chatId, messages, config: config2, pageData, mode }, opti
|
|
|
22241
22312
|
} else {
|
|
22242
22313
|
writer.write(chunk);
|
|
22243
22314
|
}
|
|
22244
|
-
}
|
|
22315
|
+
},
|
|
22316
|
+
forwardHeaders
|
|
22245
22317
|
);
|
|
22246
22318
|
}
|
|
22247
22319
|
});
|
|
22248
22320
|
return createUIMessageStreamResponse({ stream });
|
|
22249
22321
|
}
|
|
22250
|
-
function chat({ chatId, messages, config: config2, pageData }, options = {}) {
|
|
22322
|
+
function chat({ chatId, messages, config: config2, pageData }, options = {}, forwardHeaders) {
|
|
22251
22323
|
const resolvedMode = options?.ai?.mode;
|
|
22252
22324
|
const stream = createUIMessageStream({
|
|
22253
22325
|
execute: async ({ writer }) => {
|
|
@@ -22261,7 +22333,8 @@ function chat({ chatId, messages, config: config2, pageData }, options = {}) {
|
|
|
22261
22333
|
} else {
|
|
22262
22334
|
writer.write(chunk);
|
|
22263
22335
|
}
|
|
22264
|
-
}
|
|
22336
|
+
},
|
|
22337
|
+
forwardHeaders
|
|
22265
22338
|
);
|
|
22266
22339
|
}
|
|
22267
22340
|
});
|
|
@@ -22278,10 +22351,17 @@ async function generate({
|
|
|
22278
22351
|
tools,
|
|
22279
22352
|
apiKey,
|
|
22280
22353
|
host,
|
|
22281
|
-
onFinish
|
|
22354
|
+
onFinish,
|
|
22355
|
+
model,
|
|
22356
|
+
providerApiKey,
|
|
22357
|
+
providerOptions
|
|
22282
22358
|
}) {
|
|
22283
22359
|
let result = null;
|
|
22284
|
-
const options = {
|
|
22360
|
+
const options = {
|
|
22361
|
+
ai: { context, tools, model, providerApiKey, providerOptions },
|
|
22362
|
+
apiKey,
|
|
22363
|
+
host
|
|
22364
|
+
};
|
|
22285
22365
|
await cloudApi("generate", { prompt, config: config2, pageData }, options, (chunk) => {
|
|
22286
22366
|
if (chunk.type === "data-page") {
|
|
22287
22367
|
result = chunk.data;
|
|
@@ -22459,7 +22539,9 @@ var routeRegistry = [
|
|
|
22459
22539
|
{
|
|
22460
22540
|
pattern: "/api/puck/chat",
|
|
22461
22541
|
methods: {
|
|
22462
|
-
POST: ({ body }, options) => chatPrivate(body, options
|
|
22542
|
+
POST: ({ body, headers }, options) => chatPrivate(body, options, {
|
|
22543
|
+
pluginAiVersion: headers.get("x-puck-plugin-ai-version")
|
|
22544
|
+
})
|
|
22463
22545
|
}
|
|
22464
22546
|
}
|
|
22465
22547
|
];
|
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,8 @@ async function* iterateSSE(body) {
|
|
|
22226
22282
|
|
|
22227
22283
|
// src/lib/cloud-api.ts
|
|
22228
22284
|
var DEFAULT_API_VERSION = "v2";
|
|
22229
|
-
var
|
|
22285
|
+
var CLOUD_CLIENT_VERSION = true ? "0.8.0-canary.847b2ca9" : "unknown";
|
|
22286
|
+
var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
|
|
22230
22287
|
const {
|
|
22231
22288
|
ai = {},
|
|
22232
22289
|
apiKey = getApiKey(),
|
|
@@ -22238,9 +22295,22 @@ var cloudApi = async (path, body, options = {}, onChunk) => {
|
|
|
22238
22295
|
"No Puck API key specified. Set the PUCK_API_KEY environment variable, or provide one to the function"
|
|
22239
22296
|
);
|
|
22240
22297
|
}
|
|
22241
|
-
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;
|
|
22242
22306
|
const res = await fetch(`${host}/${path}`, {
|
|
22243
|
-
headers: {
|
|
22307
|
+
headers: {
|
|
22308
|
+
"x-api-key": apiKey,
|
|
22309
|
+
"puck-api-version": apiVersion,
|
|
22310
|
+
"x-puck-cloud-client-version": CLOUD_CLIENT_VERSION,
|
|
22311
|
+
...forwardHeaders?.pluginAiVersion ? { "x-puck-plugin-ai-version": forwardHeaders.pluginAiVersion } : {},
|
|
22312
|
+
...sealedProviderKey ? { "x-puck-provider-key": sealedProviderKey } : {}
|
|
22313
|
+
},
|
|
22244
22314
|
method: "post",
|
|
22245
22315
|
body: JSON.stringify({
|
|
22246
22316
|
...body,
|
|
@@ -22248,7 +22318,8 @@ var cloudApi = async (path, body, options = {}, onChunk) => {
|
|
|
22248
22318
|
tools: prepareUserTools(tools),
|
|
22249
22319
|
...designMode ? {
|
|
22250
22320
|
designMode
|
|
22251
|
-
} : {}
|
|
22321
|
+
} : {},
|
|
22322
|
+
...model ? { byok: { model, providerOptions } } : {}
|
|
22252
22323
|
})
|
|
22253
22324
|
});
|
|
22254
22325
|
if (!res.body) {
|
|
@@ -22270,7 +22341,7 @@ var cloudApi = async (path, body, options = {}, onChunk) => {
|
|
|
22270
22341
|
};
|
|
22271
22342
|
|
|
22272
22343
|
// src/api/chat.ts
|
|
22273
|
-
function chatPrivate({ chatId, messages, config: config2, pageData, mode }, options = {}) {
|
|
22344
|
+
function chatPrivate({ chatId, messages, config: config2, pageData, mode }, options = {}, forwardHeaders) {
|
|
22274
22345
|
const resolvedMode = mode ?? options?.ai?.mode;
|
|
22275
22346
|
const stream = createUIMessageStream({
|
|
22276
22347
|
execute: async ({ writer }) => {
|
|
@@ -22284,13 +22355,14 @@ function chatPrivate({ chatId, messages, config: config2, pageData, mode }, opti
|
|
|
22284
22355
|
} else {
|
|
22285
22356
|
writer.write(chunk);
|
|
22286
22357
|
}
|
|
22287
|
-
}
|
|
22358
|
+
},
|
|
22359
|
+
forwardHeaders
|
|
22288
22360
|
);
|
|
22289
22361
|
}
|
|
22290
22362
|
});
|
|
22291
22363
|
return createUIMessageStreamResponse({ stream });
|
|
22292
22364
|
}
|
|
22293
|
-
function chat({ chatId, messages, config: config2, pageData }, options = {}) {
|
|
22365
|
+
function chat({ chatId, messages, config: config2, pageData }, options = {}, forwardHeaders) {
|
|
22294
22366
|
const resolvedMode = options?.ai?.mode;
|
|
22295
22367
|
const stream = createUIMessageStream({
|
|
22296
22368
|
execute: async ({ writer }) => {
|
|
@@ -22304,7 +22376,8 @@ function chat({ chatId, messages, config: config2, pageData }, options = {}) {
|
|
|
22304
22376
|
} else {
|
|
22305
22377
|
writer.write(chunk);
|
|
22306
22378
|
}
|
|
22307
|
-
}
|
|
22379
|
+
},
|
|
22380
|
+
forwardHeaders
|
|
22308
22381
|
);
|
|
22309
22382
|
}
|
|
22310
22383
|
});
|
|
@@ -22807,10 +22880,17 @@ async function generate({
|
|
|
22807
22880
|
tools,
|
|
22808
22881
|
apiKey,
|
|
22809
22882
|
host,
|
|
22810
|
-
onFinish
|
|
22883
|
+
onFinish,
|
|
22884
|
+
model,
|
|
22885
|
+
providerApiKey,
|
|
22886
|
+
providerOptions
|
|
22811
22887
|
}) {
|
|
22812
22888
|
let result = null;
|
|
22813
|
-
const options = {
|
|
22889
|
+
const options = {
|
|
22890
|
+
ai: { context, tools, model, providerApiKey, providerOptions },
|
|
22891
|
+
apiKey,
|
|
22892
|
+
host
|
|
22893
|
+
};
|
|
22814
22894
|
await cloudApi("generate", { prompt, config: config2, pageData }, options, (chunk) => {
|
|
22815
22895
|
if (chunk.type === "data-page") {
|
|
22816
22896
|
result = chunk.data;
|