@puckeditor/cloud-client 0.8.2 → 0.9.0-canary.50fad349
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-CVAUWBJD.mjs → chunk-TWV5OYHJ.mjs} +95 -53
- package/dist/experimental.js +94 -53
- package/dist/experimental.mjs +10 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +94 -53
- package/dist/index.mjs +1 -1
- package/package.json +4 -4
|
@@ -13,6 +13,9 @@ var tool = (t) => t;
|
|
|
13
13
|
// src/api/chat.ts
|
|
14
14
|
init_react_import();
|
|
15
15
|
|
|
16
|
+
// src/lib/stream-cloud-api.ts
|
|
17
|
+
init_react_import();
|
|
18
|
+
|
|
16
19
|
// ../../node_modules/.pnpm/ai@6.0.230_zod@4.3.6/node_modules/ai/dist/index.mjs
|
|
17
20
|
init_react_import();
|
|
18
21
|
|
|
@@ -20961,14 +20964,14 @@ function createUIMessageStreamResponse({
|
|
|
20961
20964
|
status,
|
|
20962
20965
|
statusText,
|
|
20963
20966
|
headers,
|
|
20964
|
-
stream,
|
|
20967
|
+
stream: stream2,
|
|
20965
20968
|
consumeSseStream
|
|
20966
20969
|
}) {
|
|
20967
|
-
let sseStream =
|
|
20970
|
+
let sseStream = stream2.pipeThrough(new JsonToSseTransformStream());
|
|
20968
20971
|
if (consumeSseStream) {
|
|
20969
|
-
const [stream1,
|
|
20972
|
+
const [stream1, stream22] = sseStream.tee();
|
|
20970
20973
|
sseStream = stream1;
|
|
20971
|
-
consumeSseStream({ stream:
|
|
20974
|
+
consumeSseStream({ stream: stream22 });
|
|
20972
20975
|
}
|
|
20973
20976
|
return new Response(sseStream.pipeThrough(new TextEncoderStream()), {
|
|
20974
20977
|
status,
|
|
@@ -21185,7 +21188,7 @@ function createStreamingUIMessageState({
|
|
|
21185
21188
|
};
|
|
21186
21189
|
}
|
|
21187
21190
|
function processUIMessageStream({
|
|
21188
|
-
stream,
|
|
21191
|
+
stream: stream2,
|
|
21189
21192
|
messageMetadataSchema,
|
|
21190
21193
|
dataPartSchemas,
|
|
21191
21194
|
runUpdateMessageJob,
|
|
@@ -21193,7 +21196,7 @@ function processUIMessageStream({
|
|
|
21193
21196
|
onToolCall,
|
|
21194
21197
|
onData
|
|
21195
21198
|
}) {
|
|
21196
|
-
return
|
|
21199
|
+
return stream2.pipeThrough(
|
|
21197
21200
|
new TransformStream({
|
|
21198
21201
|
async transform(chunk, controller) {
|
|
21199
21202
|
await runUpdateMessageJob(async ({ state, write }) => {
|
|
@@ -21740,7 +21743,7 @@ function handleUIMessageStreamFinish({
|
|
|
21740
21743
|
onStepFinish,
|
|
21741
21744
|
onFinish,
|
|
21742
21745
|
onError,
|
|
21743
|
-
stream
|
|
21746
|
+
stream: stream2
|
|
21744
21747
|
}) {
|
|
21745
21748
|
let lastMessage = originalMessages == null ? void 0 : originalMessages[originalMessages.length - 1];
|
|
21746
21749
|
if ((lastMessage == null ? void 0 : lastMessage.role) !== "assistant") {
|
|
@@ -21749,7 +21752,7 @@ function handleUIMessageStreamFinish({
|
|
|
21749
21752
|
messageId = lastMessage.id;
|
|
21750
21753
|
}
|
|
21751
21754
|
let isAborted2 = false;
|
|
21752
|
-
const idInjectedStream =
|
|
21755
|
+
const idInjectedStream = stream2.pipeThrough(
|
|
21753
21756
|
new TransformStream({
|
|
21754
21757
|
transform(chunk, controller) {
|
|
21755
21758
|
if (chunk.type === "start") {
|
|
@@ -21850,7 +21853,7 @@ function createUIMessageStream({
|
|
|
21850
21853
|
}) {
|
|
21851
21854
|
let controller;
|
|
21852
21855
|
const ongoingStreamPromises = [];
|
|
21853
|
-
const
|
|
21856
|
+
const stream2 = new ReadableStream({
|
|
21854
21857
|
start(controllerArg) {
|
|
21855
21858
|
controller = controllerArg;
|
|
21856
21859
|
}
|
|
@@ -21917,7 +21920,7 @@ function createUIMessageStream({
|
|
|
21917
21920
|
}
|
|
21918
21921
|
});
|
|
21919
21922
|
return handleUIMessageStreamFinish({
|
|
21920
|
-
stream,
|
|
21923
|
+
stream: stream2,
|
|
21921
21924
|
messageId: generateId2(),
|
|
21922
21925
|
originalMessages,
|
|
21923
21926
|
onStepFinish,
|
|
@@ -22363,27 +22366,33 @@ var processUserTool = async ({
|
|
|
22363
22366
|
}
|
|
22364
22367
|
};
|
|
22365
22368
|
|
|
22366
|
-
//
|
|
22369
|
+
// ../utils/lib/iterate-sse.ts
|
|
22367
22370
|
init_react_import();
|
|
22368
22371
|
async function* iterateSSE(body) {
|
|
22369
22372
|
const reader = body.getReader();
|
|
22370
22373
|
const dec = new TextDecoder();
|
|
22371
22374
|
let buf = "";
|
|
22372
|
-
|
|
22373
|
-
|
|
22374
|
-
|
|
22375
|
-
|
|
22376
|
-
|
|
22377
|
-
|
|
22378
|
-
|
|
22379
|
-
|
|
22380
|
-
|
|
22381
|
-
|
|
22382
|
-
|
|
22383
|
-
|
|
22384
|
-
|
|
22375
|
+
try {
|
|
22376
|
+
while (true) {
|
|
22377
|
+
const { done, value } = await reader.read();
|
|
22378
|
+
if (done) break;
|
|
22379
|
+
buf += dec.decode(value, { stream: true });
|
|
22380
|
+
let idx;
|
|
22381
|
+
while ((idx = buf.indexOf("\n\n")) >= 0) {
|
|
22382
|
+
const chunk = buf.slice(0, idx).trim();
|
|
22383
|
+
buf = buf.slice(idx + 2);
|
|
22384
|
+
if (!chunk) continue;
|
|
22385
|
+
const line = chunk.startsWith("data: ") ? chunk.slice(6) : chunk;
|
|
22386
|
+
try {
|
|
22387
|
+
yield JSON.parse(line);
|
|
22388
|
+
} catch {
|
|
22389
|
+
}
|
|
22385
22390
|
}
|
|
22386
22391
|
}
|
|
22392
|
+
} finally {
|
|
22393
|
+
reader.cancel().catch(() => {
|
|
22394
|
+
});
|
|
22395
|
+
reader.releaseLock();
|
|
22387
22396
|
}
|
|
22388
22397
|
}
|
|
22389
22398
|
|
|
@@ -22414,7 +22423,7 @@ var DEFAULT_V2_MODELS = {
|
|
|
22414
22423
|
assembly: "openai/gpt-5.4-mini",
|
|
22415
22424
|
design: "openai/gpt-5.6-luna"
|
|
22416
22425
|
};
|
|
22417
|
-
var CLOUD_CLIENT_VERSION = true ? "0.
|
|
22426
|
+
var CLOUD_CLIENT_VERSION = true ? "0.9.0-canary.50fad349" : "unknown";
|
|
22418
22427
|
var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
|
|
22419
22428
|
const {
|
|
22420
22429
|
ai = {},
|
|
@@ -22475,19 +22484,18 @@ var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
|
|
|
22475
22484
|
return res;
|
|
22476
22485
|
};
|
|
22477
22486
|
|
|
22478
|
-
// src/api
|
|
22487
|
+
// src/lib/stream-cloud-api.ts
|
|
22479
22488
|
var handleStreamError = (error48) => {
|
|
22480
22489
|
console.error(error48);
|
|
22481
22490
|
return error48 instanceof Error ? error48.message : "An error occurred.";
|
|
22482
22491
|
};
|
|
22483
|
-
|
|
22484
|
-
const
|
|
22485
|
-
const stream = createUIMessageStream({
|
|
22492
|
+
var streamCloudApi = (path, body, options = {}, forwardHeaders) => {
|
|
22493
|
+
const stream2 = createUIMessageStream({
|
|
22486
22494
|
onError: handleStreamError,
|
|
22487
22495
|
execute: async ({ writer }) => {
|
|
22488
22496
|
await cloudApi(
|
|
22489
|
-
|
|
22490
|
-
|
|
22497
|
+
path,
|
|
22498
|
+
body,
|
|
22491
22499
|
options,
|
|
22492
22500
|
(chunk) => {
|
|
22493
22501
|
if (chunk.type === "data-finish") {
|
|
@@ -22500,29 +22508,24 @@ function chatPrivate({ chatId, messages, config: config2, pageData, mode }, opti
|
|
|
22500
22508
|
);
|
|
22501
22509
|
}
|
|
22502
22510
|
});
|
|
22503
|
-
return createUIMessageStreamResponse({ stream });
|
|
22511
|
+
return createUIMessageStreamResponse({ stream: stream2 });
|
|
22512
|
+
};
|
|
22513
|
+
|
|
22514
|
+
// src/api/chat.ts
|
|
22515
|
+
function chatPrivate({ chatId, messages, config: config2, pageData, mode }, options = {}, forwardHeaders) {
|
|
22516
|
+
return streamCloudApi(
|
|
22517
|
+
"chat",
|
|
22518
|
+
{ chatId, config: config2, messages, pageData, mode: mode ?? options?.ai?.mode },
|
|
22519
|
+
options,
|
|
22520
|
+
forwardHeaders
|
|
22521
|
+
);
|
|
22504
22522
|
}
|
|
22505
22523
|
function chat({ chatId, messages, config: config2, pageData }, options = {}, forwardHeaders) {
|
|
22506
|
-
|
|
22507
|
-
|
|
22508
|
-
|
|
22509
|
-
|
|
22510
|
-
|
|
22511
|
-
"chat",
|
|
22512
|
-
{ chatId, config: config2, messages, pageData, mode: resolvedMode },
|
|
22513
|
-
options,
|
|
22514
|
-
(chunk) => {
|
|
22515
|
-
if (chunk.type === "data-finish") {
|
|
22516
|
-
options.ai?.onFinish?.(chunk.data);
|
|
22517
|
-
} else {
|
|
22518
|
-
writer.write(chunk);
|
|
22519
|
-
}
|
|
22520
|
-
},
|
|
22521
|
-
forwardHeaders
|
|
22522
|
-
);
|
|
22523
|
-
}
|
|
22524
|
-
});
|
|
22525
|
-
return createUIMessageStreamResponse({ stream });
|
|
22524
|
+
return chatPrivate(
|
|
22525
|
+
{ chatId, messages, config: config2, pageData },
|
|
22526
|
+
options,
|
|
22527
|
+
forwardHeaders
|
|
22528
|
+
);
|
|
22526
22529
|
}
|
|
22527
22530
|
|
|
22528
22531
|
// src/api/generate.ts
|
|
@@ -22576,6 +22579,36 @@ init_react_import();
|
|
|
22576
22579
|
// src/routes.ts
|
|
22577
22580
|
init_react_import();
|
|
22578
22581
|
|
|
22582
|
+
// src/api/stream.ts
|
|
22583
|
+
init_react_import();
|
|
22584
|
+
function stream(params, options = {}, forwardHeaders) {
|
|
22585
|
+
const { prompt, config: config2, pageData, context, mode } = params ?? {};
|
|
22586
|
+
const { ai } = options;
|
|
22587
|
+
if (!prompt) {
|
|
22588
|
+
return Response.json({ error: "A prompt is required" }, { status: 400 });
|
|
22589
|
+
}
|
|
22590
|
+
const designAllowed = ai?.designMode?.allowed === true;
|
|
22591
|
+
const requestedMode = ai?.mode ?? mode;
|
|
22592
|
+
return streamCloudApi(
|
|
22593
|
+
"generate",
|
|
22594
|
+
{
|
|
22595
|
+
prompt,
|
|
22596
|
+
config: config2 ?? { components: {} },
|
|
22597
|
+
pageData,
|
|
22598
|
+
mode: requestedMode === "design" && designAllowed ? "design" : "assembly",
|
|
22599
|
+
stream: true
|
|
22600
|
+
},
|
|
22601
|
+
{
|
|
22602
|
+
...options,
|
|
22603
|
+
ai: {
|
|
22604
|
+
...ai,
|
|
22605
|
+
context: ai?.context ?? context
|
|
22606
|
+
}
|
|
22607
|
+
},
|
|
22608
|
+
forwardHeaders
|
|
22609
|
+
);
|
|
22610
|
+
}
|
|
22611
|
+
|
|
22579
22612
|
// src/api/attachments.ts
|
|
22580
22613
|
init_react_import();
|
|
22581
22614
|
var DEFAULT_HOST = "https://cloud.puckeditor.com/api";
|
|
@@ -22713,6 +22746,14 @@ var matchRoute = (pattern, pathname) => {
|
|
|
22713
22746
|
return params;
|
|
22714
22747
|
};
|
|
22715
22748
|
var routeRegistry = [
|
|
22749
|
+
{
|
|
22750
|
+
pattern: "/api/puck/stream",
|
|
22751
|
+
methods: {
|
|
22752
|
+
POST: ({ body, headers }, options) => stream(body, options, {
|
|
22753
|
+
pluginAiVersion: headers.get("x-puck-plugin-ai-version")
|
|
22754
|
+
})
|
|
22755
|
+
}
|
|
22756
|
+
},
|
|
22716
22757
|
{
|
|
22717
22758
|
pattern: "/api/puck/chat/tool",
|
|
22718
22759
|
methods: {
|
|
@@ -22800,12 +22841,13 @@ async function puckHandler(request, options = {}) {
|
|
|
22800
22841
|
}
|
|
22801
22842
|
|
|
22802
22843
|
// src/index.ts
|
|
22803
|
-
var endpoints = ["chat"];
|
|
22844
|
+
var endpoints = ["chat", "stream"];
|
|
22804
22845
|
|
|
22805
22846
|
export {
|
|
22806
22847
|
getApiKey,
|
|
22807
22848
|
chatPrivate,
|
|
22808
22849
|
chat,
|
|
22850
|
+
stream,
|
|
22809
22851
|
createAttachments,
|
|
22810
22852
|
getAttachment,
|
|
22811
22853
|
deleteAttachment,
|
package/dist/experimental.js
CHANGED
|
@@ -56,6 +56,9 @@ init_react_import();
|
|
|
56
56
|
// src/api/chat.ts
|
|
57
57
|
init_react_import();
|
|
58
58
|
|
|
59
|
+
// src/lib/stream-cloud-api.ts
|
|
60
|
+
init_react_import();
|
|
61
|
+
|
|
59
62
|
// ../../node_modules/.pnpm/ai@6.0.230_zod@4.3.6/node_modules/ai/dist/index.mjs
|
|
60
63
|
init_react_import();
|
|
61
64
|
|
|
@@ -21004,14 +21007,14 @@ function createUIMessageStreamResponse({
|
|
|
21004
21007
|
status,
|
|
21005
21008
|
statusText,
|
|
21006
21009
|
headers,
|
|
21007
|
-
stream,
|
|
21010
|
+
stream: stream2,
|
|
21008
21011
|
consumeSseStream
|
|
21009
21012
|
}) {
|
|
21010
|
-
let sseStream =
|
|
21013
|
+
let sseStream = stream2.pipeThrough(new JsonToSseTransformStream());
|
|
21011
21014
|
if (consumeSseStream) {
|
|
21012
|
-
const [stream1,
|
|
21015
|
+
const [stream1, stream22] = sseStream.tee();
|
|
21013
21016
|
sseStream = stream1;
|
|
21014
|
-
consumeSseStream({ stream:
|
|
21017
|
+
consumeSseStream({ stream: stream22 });
|
|
21015
21018
|
}
|
|
21016
21019
|
return new Response(sseStream.pipeThrough(new TextEncoderStream()), {
|
|
21017
21020
|
status,
|
|
@@ -21228,7 +21231,7 @@ function createStreamingUIMessageState({
|
|
|
21228
21231
|
};
|
|
21229
21232
|
}
|
|
21230
21233
|
function processUIMessageStream({
|
|
21231
|
-
stream,
|
|
21234
|
+
stream: stream2,
|
|
21232
21235
|
messageMetadataSchema,
|
|
21233
21236
|
dataPartSchemas,
|
|
21234
21237
|
runUpdateMessageJob,
|
|
@@ -21236,7 +21239,7 @@ function processUIMessageStream({
|
|
|
21236
21239
|
onToolCall,
|
|
21237
21240
|
onData
|
|
21238
21241
|
}) {
|
|
21239
|
-
return
|
|
21242
|
+
return stream2.pipeThrough(
|
|
21240
21243
|
new TransformStream({
|
|
21241
21244
|
async transform(chunk, controller) {
|
|
21242
21245
|
await runUpdateMessageJob(async ({ state, write }) => {
|
|
@@ -21783,7 +21786,7 @@ function handleUIMessageStreamFinish({
|
|
|
21783
21786
|
onStepFinish,
|
|
21784
21787
|
onFinish,
|
|
21785
21788
|
onError,
|
|
21786
|
-
stream
|
|
21789
|
+
stream: stream2
|
|
21787
21790
|
}) {
|
|
21788
21791
|
let lastMessage = originalMessages == null ? void 0 : originalMessages[originalMessages.length - 1];
|
|
21789
21792
|
if ((lastMessage == null ? void 0 : lastMessage.role) !== "assistant") {
|
|
@@ -21792,7 +21795,7 @@ function handleUIMessageStreamFinish({
|
|
|
21792
21795
|
messageId = lastMessage.id;
|
|
21793
21796
|
}
|
|
21794
21797
|
let isAborted2 = false;
|
|
21795
|
-
const idInjectedStream =
|
|
21798
|
+
const idInjectedStream = stream2.pipeThrough(
|
|
21796
21799
|
new TransformStream({
|
|
21797
21800
|
transform(chunk, controller) {
|
|
21798
21801
|
if (chunk.type === "start") {
|
|
@@ -21893,7 +21896,7 @@ function createUIMessageStream({
|
|
|
21893
21896
|
}) {
|
|
21894
21897
|
let controller;
|
|
21895
21898
|
const ongoingStreamPromises = [];
|
|
21896
|
-
const
|
|
21899
|
+
const stream2 = new ReadableStream({
|
|
21897
21900
|
start(controllerArg) {
|
|
21898
21901
|
controller = controllerArg;
|
|
21899
21902
|
}
|
|
@@ -21960,7 +21963,7 @@ function createUIMessageStream({
|
|
|
21960
21963
|
}
|
|
21961
21964
|
});
|
|
21962
21965
|
return handleUIMessageStreamFinish({
|
|
21963
|
-
stream,
|
|
21966
|
+
stream: stream2,
|
|
21964
21967
|
messageId: generateId2(),
|
|
21965
21968
|
originalMessages,
|
|
21966
21969
|
onStepFinish,
|
|
@@ -22406,27 +22409,33 @@ var processUserTool = async ({
|
|
|
22406
22409
|
}
|
|
22407
22410
|
};
|
|
22408
22411
|
|
|
22409
|
-
//
|
|
22412
|
+
// ../utils/lib/iterate-sse.ts
|
|
22410
22413
|
init_react_import();
|
|
22411
22414
|
async function* iterateSSE(body) {
|
|
22412
22415
|
const reader = body.getReader();
|
|
22413
22416
|
const dec = new TextDecoder();
|
|
22414
22417
|
let buf = "";
|
|
22415
|
-
|
|
22416
|
-
|
|
22417
|
-
|
|
22418
|
-
|
|
22419
|
-
|
|
22420
|
-
|
|
22421
|
-
|
|
22422
|
-
|
|
22423
|
-
|
|
22424
|
-
|
|
22425
|
-
|
|
22426
|
-
|
|
22427
|
-
|
|
22418
|
+
try {
|
|
22419
|
+
while (true) {
|
|
22420
|
+
const { done, value } = await reader.read();
|
|
22421
|
+
if (done) break;
|
|
22422
|
+
buf += dec.decode(value, { stream: true });
|
|
22423
|
+
let idx;
|
|
22424
|
+
while ((idx = buf.indexOf("\n\n")) >= 0) {
|
|
22425
|
+
const chunk = buf.slice(0, idx).trim();
|
|
22426
|
+
buf = buf.slice(idx + 2);
|
|
22427
|
+
if (!chunk) continue;
|
|
22428
|
+
const line = chunk.startsWith("data: ") ? chunk.slice(6) : chunk;
|
|
22429
|
+
try {
|
|
22430
|
+
yield JSON.parse(line);
|
|
22431
|
+
} catch {
|
|
22432
|
+
}
|
|
22428
22433
|
}
|
|
22429
22434
|
}
|
|
22435
|
+
} finally {
|
|
22436
|
+
reader.cancel().catch(() => {
|
|
22437
|
+
});
|
|
22438
|
+
reader.releaseLock();
|
|
22430
22439
|
}
|
|
22431
22440
|
}
|
|
22432
22441
|
|
|
@@ -22457,7 +22466,7 @@ var DEFAULT_V2_MODELS = {
|
|
|
22457
22466
|
assembly: "openai/gpt-5.4-mini",
|
|
22458
22467
|
design: "openai/gpt-5.6-luna"
|
|
22459
22468
|
};
|
|
22460
|
-
var CLOUD_CLIENT_VERSION = true ? "0.
|
|
22469
|
+
var CLOUD_CLIENT_VERSION = true ? "0.9.0-canary.50fad349" : "unknown";
|
|
22461
22470
|
var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
|
|
22462
22471
|
const {
|
|
22463
22472
|
ai = {},
|
|
@@ -22518,19 +22527,18 @@ var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
|
|
|
22518
22527
|
return res;
|
|
22519
22528
|
};
|
|
22520
22529
|
|
|
22521
|
-
// src/api
|
|
22530
|
+
// src/lib/stream-cloud-api.ts
|
|
22522
22531
|
var handleStreamError = (error48) => {
|
|
22523
22532
|
console.error(error48);
|
|
22524
22533
|
return error48 instanceof Error ? error48.message : "An error occurred.";
|
|
22525
22534
|
};
|
|
22526
|
-
|
|
22527
|
-
const
|
|
22528
|
-
const stream = createUIMessageStream({
|
|
22535
|
+
var streamCloudApi = (path, body, options = {}, forwardHeaders) => {
|
|
22536
|
+
const stream2 = createUIMessageStream({
|
|
22529
22537
|
onError: handleStreamError,
|
|
22530
22538
|
execute: async ({ writer }) => {
|
|
22531
22539
|
await cloudApi(
|
|
22532
|
-
|
|
22533
|
-
|
|
22540
|
+
path,
|
|
22541
|
+
body,
|
|
22534
22542
|
options,
|
|
22535
22543
|
(chunk) => {
|
|
22536
22544
|
if (chunk.type === "data-finish") {
|
|
@@ -22543,29 +22551,54 @@ function chatPrivate({ chatId, messages, config: config2, pageData, mode }, opti
|
|
|
22543
22551
|
);
|
|
22544
22552
|
}
|
|
22545
22553
|
});
|
|
22546
|
-
return createUIMessageStreamResponse({ stream });
|
|
22554
|
+
return createUIMessageStreamResponse({ stream: stream2 });
|
|
22555
|
+
};
|
|
22556
|
+
|
|
22557
|
+
// src/api/chat.ts
|
|
22558
|
+
function chatPrivate({ chatId, messages, config: config2, pageData, mode }, options = {}, forwardHeaders) {
|
|
22559
|
+
return streamCloudApi(
|
|
22560
|
+
"chat",
|
|
22561
|
+
{ chatId, config: config2, messages, pageData, mode: mode ?? options?.ai?.mode },
|
|
22562
|
+
options,
|
|
22563
|
+
forwardHeaders
|
|
22564
|
+
);
|
|
22547
22565
|
}
|
|
22548
22566
|
function chat({ chatId, messages, config: config2, pageData }, options = {}, forwardHeaders) {
|
|
22549
|
-
|
|
22550
|
-
|
|
22551
|
-
|
|
22552
|
-
|
|
22553
|
-
|
|
22554
|
-
|
|
22555
|
-
|
|
22556
|
-
|
|
22557
|
-
|
|
22558
|
-
|
|
22559
|
-
|
|
22560
|
-
|
|
22561
|
-
|
|
22562
|
-
|
|
22563
|
-
|
|
22564
|
-
|
|
22565
|
-
|
|
22566
|
-
|
|
22567
|
-
|
|
22568
|
-
|
|
22567
|
+
return chatPrivate(
|
|
22568
|
+
{ chatId, messages, config: config2, pageData },
|
|
22569
|
+
options,
|
|
22570
|
+
forwardHeaders
|
|
22571
|
+
);
|
|
22572
|
+
}
|
|
22573
|
+
|
|
22574
|
+
// src/api/stream.ts
|
|
22575
|
+
init_react_import();
|
|
22576
|
+
function stream(params, options = {}, forwardHeaders) {
|
|
22577
|
+
const { prompt, config: config2, pageData, context, mode } = params ?? {};
|
|
22578
|
+
const { ai } = options;
|
|
22579
|
+
if (!prompt) {
|
|
22580
|
+
return Response.json({ error: "A prompt is required" }, { status: 400 });
|
|
22581
|
+
}
|
|
22582
|
+
const designAllowed = ai?.designMode?.allowed === true;
|
|
22583
|
+
const requestedMode = ai?.mode ?? mode;
|
|
22584
|
+
return streamCloudApi(
|
|
22585
|
+
"generate",
|
|
22586
|
+
{
|
|
22587
|
+
prompt,
|
|
22588
|
+
config: config2 ?? { components: {} },
|
|
22589
|
+
pageData,
|
|
22590
|
+
mode: requestedMode === "design" && designAllowed ? "design" : "assembly",
|
|
22591
|
+
stream: true
|
|
22592
|
+
},
|
|
22593
|
+
{
|
|
22594
|
+
...options,
|
|
22595
|
+
ai: {
|
|
22596
|
+
...ai,
|
|
22597
|
+
context: ai?.context ?? context
|
|
22598
|
+
}
|
|
22599
|
+
},
|
|
22600
|
+
forwardHeaders
|
|
22601
|
+
);
|
|
22569
22602
|
}
|
|
22570
22603
|
|
|
22571
22604
|
// src/api/attachments.ts
|
|
@@ -23100,10 +23133,18 @@ async function generate({
|
|
|
23100
23133
|
}
|
|
23101
23134
|
|
|
23102
23135
|
// src/index.ts
|
|
23103
|
-
var endpoints = ["chat"];
|
|
23136
|
+
var endpoints = ["chat", "stream"];
|
|
23104
23137
|
|
|
23105
23138
|
// src/experimental.ts
|
|
23106
23139
|
var routeRegistry = [
|
|
23140
|
+
{
|
|
23141
|
+
pattern: "/api/puck/stream",
|
|
23142
|
+
methods: {
|
|
23143
|
+
POST: ({ body, headers }, options) => stream(body, options, {
|
|
23144
|
+
pluginAiVersion: headers.get("x-puck-plugin-ai-version")
|
|
23145
|
+
})
|
|
23146
|
+
}
|
|
23147
|
+
},
|
|
23107
23148
|
{
|
|
23108
23149
|
pattern: "/api/puck/chat/tool",
|
|
23109
23150
|
methods: {
|
package/dist/experimental.mjs
CHANGED
|
@@ -10,8 +10,9 @@ import {
|
|
|
10
10
|
getApiKey,
|
|
11
11
|
getAttachment,
|
|
12
12
|
handlePuckRequest,
|
|
13
|
+
stream,
|
|
13
14
|
tool
|
|
14
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-TWV5OYHJ.mjs";
|
|
15
16
|
import {
|
|
16
17
|
init_react_import
|
|
17
18
|
} from "./chunk-O6DC5HI2.mjs";
|
|
@@ -306,6 +307,14 @@ var getPublishedPageData = async ({
|
|
|
306
307
|
|
|
307
308
|
// src/experimental.ts
|
|
308
309
|
var routeRegistry = [
|
|
310
|
+
{
|
|
311
|
+
pattern: "/api/puck/stream",
|
|
312
|
+
methods: {
|
|
313
|
+
POST: ({ body, headers }, options) => stream(body, options, {
|
|
314
|
+
pluginAiVersion: headers.get("x-puck-plugin-ai-version")
|
|
315
|
+
})
|
|
316
|
+
}
|
|
317
|
+
},
|
|
309
318
|
{
|
|
310
319
|
pattern: "/api/puck/chat/tool",
|
|
311
320
|
methods: {
|
package/dist/index.d.mts
CHANGED
|
@@ -722,7 +722,7 @@ declare function generate({ prompt, config, pageData, context, tools, mode, desi
|
|
|
722
722
|
|
|
723
723
|
declare function puckHandler(request: Request, options?: PuckCloudOptions): Promise<Response>;
|
|
724
724
|
|
|
725
|
-
declare const endpoints: readonly ["chat"];
|
|
725
|
+
declare const endpoints: readonly ["chat", "stream"];
|
|
726
726
|
type Endpoint = (typeof endpoints)[number];
|
|
727
727
|
|
|
728
728
|
export { type ChatParams, type DesignModeOptions, type Endpoint, type GenerateParams, type OnFinishCallback, type OnFinishResult, type PuckAiModel, type PuckAiProviderOptions, type PuckCloudOptions, type UserTool, type UserToolRegistry, chat, endpoints, generate, puckHandler, tool };
|
package/dist/index.d.ts
CHANGED
|
@@ -722,7 +722,7 @@ declare function generate({ prompt, config, pageData, context, tools, mode, desi
|
|
|
722
722
|
|
|
723
723
|
declare function puckHandler(request: Request, options?: PuckCloudOptions): Promise<Response>;
|
|
724
724
|
|
|
725
|
-
declare const endpoints: readonly ["chat"];
|
|
725
|
+
declare const endpoints: readonly ["chat", "stream"];
|
|
726
726
|
type Endpoint = (typeof endpoints)[number];
|
|
727
727
|
|
|
728
728
|
export { type ChatParams, type DesignModeOptions, type Endpoint, type GenerateParams, type OnFinishCallback, type OnFinishResult, type PuckAiModel, type PuckAiProviderOptions, type PuckCloudOptions, type UserTool, type UserToolRegistry, chat, endpoints, generate, puckHandler, tool };
|
package/dist/index.js
CHANGED
|
@@ -58,6 +58,9 @@ var tool = (t) => t;
|
|
|
58
58
|
// src/api/chat.ts
|
|
59
59
|
init_react_import();
|
|
60
60
|
|
|
61
|
+
// src/lib/stream-cloud-api.ts
|
|
62
|
+
init_react_import();
|
|
63
|
+
|
|
61
64
|
// ../../node_modules/.pnpm/ai@6.0.230_zod@4.3.6/node_modules/ai/dist/index.mjs
|
|
62
65
|
init_react_import();
|
|
63
66
|
|
|
@@ -21006,14 +21009,14 @@ function createUIMessageStreamResponse({
|
|
|
21006
21009
|
status,
|
|
21007
21010
|
statusText,
|
|
21008
21011
|
headers,
|
|
21009
|
-
stream,
|
|
21012
|
+
stream: stream2,
|
|
21010
21013
|
consumeSseStream
|
|
21011
21014
|
}) {
|
|
21012
|
-
let sseStream =
|
|
21015
|
+
let sseStream = stream2.pipeThrough(new JsonToSseTransformStream());
|
|
21013
21016
|
if (consumeSseStream) {
|
|
21014
|
-
const [stream1,
|
|
21017
|
+
const [stream1, stream22] = sseStream.tee();
|
|
21015
21018
|
sseStream = stream1;
|
|
21016
|
-
consumeSseStream({ stream:
|
|
21019
|
+
consumeSseStream({ stream: stream22 });
|
|
21017
21020
|
}
|
|
21018
21021
|
return new Response(sseStream.pipeThrough(new TextEncoderStream()), {
|
|
21019
21022
|
status,
|
|
@@ -21230,7 +21233,7 @@ function createStreamingUIMessageState({
|
|
|
21230
21233
|
};
|
|
21231
21234
|
}
|
|
21232
21235
|
function processUIMessageStream({
|
|
21233
|
-
stream,
|
|
21236
|
+
stream: stream2,
|
|
21234
21237
|
messageMetadataSchema,
|
|
21235
21238
|
dataPartSchemas,
|
|
21236
21239
|
runUpdateMessageJob,
|
|
@@ -21238,7 +21241,7 @@ function processUIMessageStream({
|
|
|
21238
21241
|
onToolCall,
|
|
21239
21242
|
onData
|
|
21240
21243
|
}) {
|
|
21241
|
-
return
|
|
21244
|
+
return stream2.pipeThrough(
|
|
21242
21245
|
new TransformStream({
|
|
21243
21246
|
async transform(chunk, controller) {
|
|
21244
21247
|
await runUpdateMessageJob(async ({ state, write }) => {
|
|
@@ -21785,7 +21788,7 @@ function handleUIMessageStreamFinish({
|
|
|
21785
21788
|
onStepFinish,
|
|
21786
21789
|
onFinish,
|
|
21787
21790
|
onError,
|
|
21788
|
-
stream
|
|
21791
|
+
stream: stream2
|
|
21789
21792
|
}) {
|
|
21790
21793
|
let lastMessage = originalMessages == null ? void 0 : originalMessages[originalMessages.length - 1];
|
|
21791
21794
|
if ((lastMessage == null ? void 0 : lastMessage.role) !== "assistant") {
|
|
@@ -21794,7 +21797,7 @@ function handleUIMessageStreamFinish({
|
|
|
21794
21797
|
messageId = lastMessage.id;
|
|
21795
21798
|
}
|
|
21796
21799
|
let isAborted2 = false;
|
|
21797
|
-
const idInjectedStream =
|
|
21800
|
+
const idInjectedStream = stream2.pipeThrough(
|
|
21798
21801
|
new TransformStream({
|
|
21799
21802
|
transform(chunk, controller) {
|
|
21800
21803
|
if (chunk.type === "start") {
|
|
@@ -21895,7 +21898,7 @@ function createUIMessageStream({
|
|
|
21895
21898
|
}) {
|
|
21896
21899
|
let controller;
|
|
21897
21900
|
const ongoingStreamPromises = [];
|
|
21898
|
-
const
|
|
21901
|
+
const stream2 = new ReadableStream({
|
|
21899
21902
|
start(controllerArg) {
|
|
21900
21903
|
controller = controllerArg;
|
|
21901
21904
|
}
|
|
@@ -21962,7 +21965,7 @@ function createUIMessageStream({
|
|
|
21962
21965
|
}
|
|
21963
21966
|
});
|
|
21964
21967
|
return handleUIMessageStreamFinish({
|
|
21965
|
-
stream,
|
|
21968
|
+
stream: stream2,
|
|
21966
21969
|
messageId: generateId2(),
|
|
21967
21970
|
originalMessages,
|
|
21968
21971
|
onStepFinish,
|
|
@@ -22408,27 +22411,33 @@ var processUserTool = async ({
|
|
|
22408
22411
|
}
|
|
22409
22412
|
};
|
|
22410
22413
|
|
|
22411
|
-
//
|
|
22414
|
+
// ../utils/lib/iterate-sse.ts
|
|
22412
22415
|
init_react_import();
|
|
22413
22416
|
async function* iterateSSE(body) {
|
|
22414
22417
|
const reader = body.getReader();
|
|
22415
22418
|
const dec = new TextDecoder();
|
|
22416
22419
|
let buf = "";
|
|
22417
|
-
|
|
22418
|
-
|
|
22419
|
-
|
|
22420
|
-
|
|
22421
|
-
|
|
22422
|
-
|
|
22423
|
-
|
|
22424
|
-
|
|
22425
|
-
|
|
22426
|
-
|
|
22427
|
-
|
|
22428
|
-
|
|
22429
|
-
|
|
22420
|
+
try {
|
|
22421
|
+
while (true) {
|
|
22422
|
+
const { done, value } = await reader.read();
|
|
22423
|
+
if (done) break;
|
|
22424
|
+
buf += dec.decode(value, { stream: true });
|
|
22425
|
+
let idx;
|
|
22426
|
+
while ((idx = buf.indexOf("\n\n")) >= 0) {
|
|
22427
|
+
const chunk = buf.slice(0, idx).trim();
|
|
22428
|
+
buf = buf.slice(idx + 2);
|
|
22429
|
+
if (!chunk) continue;
|
|
22430
|
+
const line = chunk.startsWith("data: ") ? chunk.slice(6) : chunk;
|
|
22431
|
+
try {
|
|
22432
|
+
yield JSON.parse(line);
|
|
22433
|
+
} catch {
|
|
22434
|
+
}
|
|
22430
22435
|
}
|
|
22431
22436
|
}
|
|
22437
|
+
} finally {
|
|
22438
|
+
reader.cancel().catch(() => {
|
|
22439
|
+
});
|
|
22440
|
+
reader.releaseLock();
|
|
22432
22441
|
}
|
|
22433
22442
|
}
|
|
22434
22443
|
|
|
@@ -22459,7 +22468,7 @@ var DEFAULT_V2_MODELS = {
|
|
|
22459
22468
|
assembly: "openai/gpt-5.4-mini",
|
|
22460
22469
|
design: "openai/gpt-5.6-luna"
|
|
22461
22470
|
};
|
|
22462
|
-
var CLOUD_CLIENT_VERSION = true ? "0.
|
|
22471
|
+
var CLOUD_CLIENT_VERSION = true ? "0.9.0-canary.50fad349" : "unknown";
|
|
22463
22472
|
var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
|
|
22464
22473
|
const {
|
|
22465
22474
|
ai = {},
|
|
@@ -22520,19 +22529,18 @@ var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
|
|
|
22520
22529
|
return res;
|
|
22521
22530
|
};
|
|
22522
22531
|
|
|
22523
|
-
// src/api
|
|
22532
|
+
// src/lib/stream-cloud-api.ts
|
|
22524
22533
|
var handleStreamError = (error48) => {
|
|
22525
22534
|
console.error(error48);
|
|
22526
22535
|
return error48 instanceof Error ? error48.message : "An error occurred.";
|
|
22527
22536
|
};
|
|
22528
|
-
|
|
22529
|
-
const
|
|
22530
|
-
const stream = createUIMessageStream({
|
|
22537
|
+
var streamCloudApi = (path, body, options = {}, forwardHeaders) => {
|
|
22538
|
+
const stream2 = createUIMessageStream({
|
|
22531
22539
|
onError: handleStreamError,
|
|
22532
22540
|
execute: async ({ writer }) => {
|
|
22533
22541
|
await cloudApi(
|
|
22534
|
-
|
|
22535
|
-
|
|
22542
|
+
path,
|
|
22543
|
+
body,
|
|
22536
22544
|
options,
|
|
22537
22545
|
(chunk) => {
|
|
22538
22546
|
if (chunk.type === "data-finish") {
|
|
@@ -22545,29 +22553,24 @@ function chatPrivate({ chatId, messages, config: config2, pageData, mode }, opti
|
|
|
22545
22553
|
);
|
|
22546
22554
|
}
|
|
22547
22555
|
});
|
|
22548
|
-
return createUIMessageStreamResponse({ stream });
|
|
22556
|
+
return createUIMessageStreamResponse({ stream: stream2 });
|
|
22557
|
+
};
|
|
22558
|
+
|
|
22559
|
+
// src/api/chat.ts
|
|
22560
|
+
function chatPrivate({ chatId, messages, config: config2, pageData, mode }, options = {}, forwardHeaders) {
|
|
22561
|
+
return streamCloudApi(
|
|
22562
|
+
"chat",
|
|
22563
|
+
{ chatId, config: config2, messages, pageData, mode: mode ?? options?.ai?.mode },
|
|
22564
|
+
options,
|
|
22565
|
+
forwardHeaders
|
|
22566
|
+
);
|
|
22549
22567
|
}
|
|
22550
22568
|
function chat({ chatId, messages, config: config2, pageData }, options = {}, forwardHeaders) {
|
|
22551
|
-
|
|
22552
|
-
|
|
22553
|
-
|
|
22554
|
-
|
|
22555
|
-
|
|
22556
|
-
"chat",
|
|
22557
|
-
{ chatId, config: config2, messages, pageData, mode: resolvedMode },
|
|
22558
|
-
options,
|
|
22559
|
-
(chunk) => {
|
|
22560
|
-
if (chunk.type === "data-finish") {
|
|
22561
|
-
options.ai?.onFinish?.(chunk.data);
|
|
22562
|
-
} else {
|
|
22563
|
-
writer.write(chunk);
|
|
22564
|
-
}
|
|
22565
|
-
},
|
|
22566
|
-
forwardHeaders
|
|
22567
|
-
);
|
|
22568
|
-
}
|
|
22569
|
-
});
|
|
22570
|
-
return createUIMessageStreamResponse({ stream });
|
|
22569
|
+
return chatPrivate(
|
|
22570
|
+
{ chatId, messages, config: config2, pageData },
|
|
22571
|
+
options,
|
|
22572
|
+
forwardHeaders
|
|
22573
|
+
);
|
|
22571
22574
|
}
|
|
22572
22575
|
|
|
22573
22576
|
// src/api/generate.ts
|
|
@@ -22621,6 +22624,36 @@ init_react_import();
|
|
|
22621
22624
|
// src/routes.ts
|
|
22622
22625
|
init_react_import();
|
|
22623
22626
|
|
|
22627
|
+
// src/api/stream.ts
|
|
22628
|
+
init_react_import();
|
|
22629
|
+
function stream(params, options = {}, forwardHeaders) {
|
|
22630
|
+
const { prompt, config: config2, pageData, context, mode } = params ?? {};
|
|
22631
|
+
const { ai } = options;
|
|
22632
|
+
if (!prompt) {
|
|
22633
|
+
return Response.json({ error: "A prompt is required" }, { status: 400 });
|
|
22634
|
+
}
|
|
22635
|
+
const designAllowed = ai?.designMode?.allowed === true;
|
|
22636
|
+
const requestedMode = ai?.mode ?? mode;
|
|
22637
|
+
return streamCloudApi(
|
|
22638
|
+
"generate",
|
|
22639
|
+
{
|
|
22640
|
+
prompt,
|
|
22641
|
+
config: config2 ?? { components: {} },
|
|
22642
|
+
pageData,
|
|
22643
|
+
mode: requestedMode === "design" && designAllowed ? "design" : "assembly",
|
|
22644
|
+
stream: true
|
|
22645
|
+
},
|
|
22646
|
+
{
|
|
22647
|
+
...options,
|
|
22648
|
+
ai: {
|
|
22649
|
+
...ai,
|
|
22650
|
+
context: ai?.context ?? context
|
|
22651
|
+
}
|
|
22652
|
+
},
|
|
22653
|
+
forwardHeaders
|
|
22654
|
+
);
|
|
22655
|
+
}
|
|
22656
|
+
|
|
22624
22657
|
// src/api/attachments.ts
|
|
22625
22658
|
init_react_import();
|
|
22626
22659
|
var DEFAULT_HOST = "https://cloud.puckeditor.com/api";
|
|
@@ -22758,6 +22791,14 @@ var matchRoute = (pattern, pathname) => {
|
|
|
22758
22791
|
return params;
|
|
22759
22792
|
};
|
|
22760
22793
|
var routeRegistry = [
|
|
22794
|
+
{
|
|
22795
|
+
pattern: "/api/puck/stream",
|
|
22796
|
+
methods: {
|
|
22797
|
+
POST: ({ body, headers }, options) => stream(body, options, {
|
|
22798
|
+
pluginAiVersion: headers.get("x-puck-plugin-ai-version")
|
|
22799
|
+
})
|
|
22800
|
+
}
|
|
22801
|
+
},
|
|
22761
22802
|
{
|
|
22762
22803
|
pattern: "/api/puck/chat/tool",
|
|
22763
22804
|
methods: {
|
|
@@ -22845,7 +22886,7 @@ async function puckHandler(request, options = {}) {
|
|
|
22845
22886
|
}
|
|
22846
22887
|
|
|
22847
22888
|
// src/index.ts
|
|
22848
|
-
var endpoints = ["chat"];
|
|
22889
|
+
var endpoints = ["chat", "stream"];
|
|
22849
22890
|
// Annotate the CommonJS export names for ESM import in node:
|
|
22850
22891
|
0 && (module.exports = {
|
|
22851
22892
|
chat,
|
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@puckeditor/cloud-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0-canary.50fad349",
|
|
4
4
|
"author": "Chris Villa <chris@puckeditor.com>",
|
|
5
5
|
"repository": "puckeditor/puck",
|
|
6
6
|
"bugs": "https://github.com/puckeditor/puck/issues",
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
"vite-tsconfig-paths": "^5.1.4",
|
|
45
45
|
"vitest": "^4.1.0",
|
|
46
46
|
"zod": "^4.1.12",
|
|
47
|
-
"eslint-config-custom": "0.
|
|
48
|
-
"tsconfig": "0.
|
|
49
|
-
"tsup-config": "0.
|
|
47
|
+
"eslint-config-custom": "0.9.0-canary.50fad349",
|
|
48
|
+
"tsconfig": "0.9.0-canary.50fad349",
|
|
49
|
+
"tsup-config": "0.9.0-canary.50fad349"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
52
|
"lint": "eslint \"**/*.ts*\"",
|