@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.
@@ -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 = stream.pipeThrough(new JsonToSseTransformStream());
20970
+ let sseStream = stream2.pipeThrough(new JsonToSseTransformStream());
20968
20971
  if (consumeSseStream) {
20969
- const [stream1, stream2] = sseStream.tee();
20972
+ const [stream1, stream22] = sseStream.tee();
20970
20973
  sseStream = stream1;
20971
- consumeSseStream({ stream: stream2 });
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 stream.pipeThrough(
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 = stream.pipeThrough(
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 stream = new ReadableStream({
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
- // src/lib/iterate-sse.ts
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
- while (true) {
22373
- const { done, value } = await reader.read();
22374
- if (done) break;
22375
- buf += dec.decode(value, { stream: true });
22376
- let idx;
22377
- while ((idx = buf.indexOf("\n\n")) >= 0) {
22378
- const chunk = buf.slice(0, idx).trim();
22379
- buf = buf.slice(idx + 2);
22380
- if (!chunk) continue;
22381
- const line = chunk.startsWith("data: ") ? chunk.slice(6) : chunk;
22382
- try {
22383
- yield JSON.parse(line);
22384
- } catch {
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.8.2" : "unknown";
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/chat.ts
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
- function chatPrivate({ chatId, messages, config: config2, pageData, mode }, options = {}, forwardHeaders) {
22484
- const resolvedMode = mode ?? options?.ai?.mode;
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
- "chat",
22490
- { chatId, config: config2, messages, pageData, mode: resolvedMode },
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
- const resolvedMode = options?.ai?.mode;
22507
- const stream = createUIMessageStream({
22508
- onError: handleStreamError,
22509
- execute: async ({ writer }) => {
22510
- await cloudApi(
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,
@@ -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 = stream.pipeThrough(new JsonToSseTransformStream());
21013
+ let sseStream = stream2.pipeThrough(new JsonToSseTransformStream());
21011
21014
  if (consumeSseStream) {
21012
- const [stream1, stream2] = sseStream.tee();
21015
+ const [stream1, stream22] = sseStream.tee();
21013
21016
  sseStream = stream1;
21014
- consumeSseStream({ stream: stream2 });
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 stream.pipeThrough(
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 = stream.pipeThrough(
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 stream = new ReadableStream({
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
- // src/lib/iterate-sse.ts
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
- while (true) {
22416
- const { done, value } = await reader.read();
22417
- if (done) break;
22418
- buf += dec.decode(value, { stream: true });
22419
- let idx;
22420
- while ((idx = buf.indexOf("\n\n")) >= 0) {
22421
- const chunk = buf.slice(0, idx).trim();
22422
- buf = buf.slice(idx + 2);
22423
- if (!chunk) continue;
22424
- const line = chunk.startsWith("data: ") ? chunk.slice(6) : chunk;
22425
- try {
22426
- yield JSON.parse(line);
22427
- } catch {
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.8.2" : "unknown";
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/chat.ts
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
- function chatPrivate({ chatId, messages, config: config2, pageData, mode }, options = {}, forwardHeaders) {
22527
- const resolvedMode = mode ?? options?.ai?.mode;
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
- "chat",
22533
- { chatId, config: config2, messages, pageData, mode: resolvedMode },
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
- const resolvedMode = options?.ai?.mode;
22550
- const stream = createUIMessageStream({
22551
- onError: handleStreamError,
22552
- execute: async ({ writer }) => {
22553
- await cloudApi(
22554
- "chat",
22555
- { chatId, config: config2, messages, pageData, mode: resolvedMode },
22556
- options,
22557
- (chunk) => {
22558
- if (chunk.type === "data-finish") {
22559
- options.ai?.onFinish?.(chunk.data);
22560
- } else {
22561
- writer.write(chunk);
22562
- }
22563
- },
22564
- forwardHeaders
22565
- );
22566
- }
22567
- });
22568
- return createUIMessageStreamResponse({ stream });
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: {
@@ -10,8 +10,9 @@ import {
10
10
  getApiKey,
11
11
  getAttachment,
12
12
  handlePuckRequest,
13
+ stream,
13
14
  tool
14
- } from "./chunk-CVAUWBJD.mjs";
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 = stream.pipeThrough(new JsonToSseTransformStream());
21015
+ let sseStream = stream2.pipeThrough(new JsonToSseTransformStream());
21013
21016
  if (consumeSseStream) {
21014
- const [stream1, stream2] = sseStream.tee();
21017
+ const [stream1, stream22] = sseStream.tee();
21015
21018
  sseStream = stream1;
21016
- consumeSseStream({ stream: stream2 });
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 stream.pipeThrough(
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 = stream.pipeThrough(
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 stream = new ReadableStream({
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
- // src/lib/iterate-sse.ts
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
- while (true) {
22418
- const { done, value } = await reader.read();
22419
- if (done) break;
22420
- buf += dec.decode(value, { stream: true });
22421
- let idx;
22422
- while ((idx = buf.indexOf("\n\n")) >= 0) {
22423
- const chunk = buf.slice(0, idx).trim();
22424
- buf = buf.slice(idx + 2);
22425
- if (!chunk) continue;
22426
- const line = chunk.startsWith("data: ") ? chunk.slice(6) : chunk;
22427
- try {
22428
- yield JSON.parse(line);
22429
- } catch {
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.8.2" : "unknown";
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/chat.ts
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
- function chatPrivate({ chatId, messages, config: config2, pageData, mode }, options = {}, forwardHeaders) {
22529
- const resolvedMode = mode ?? options?.ai?.mode;
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
- "chat",
22535
- { chatId, config: config2, messages, pageData, mode: resolvedMode },
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
- const resolvedMode = options?.ai?.mode;
22552
- const stream = createUIMessageStream({
22553
- onError: handleStreamError,
22554
- execute: async ({ writer }) => {
22555
- await cloudApi(
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
@@ -4,7 +4,7 @@ import {
4
4
  generate,
5
5
  puckHandler,
6
6
  tool
7
- } from "./chunk-CVAUWBJD.mjs";
7
+ } from "./chunk-TWV5OYHJ.mjs";
8
8
  import "./chunk-O6DC5HI2.mjs";
9
9
  export {
10
10
  chat,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@puckeditor/cloud-client",
3
- "version": "0.8.2",
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.8.2",
48
- "tsconfig": "0.8.2",
49
- "tsup-config": "0.8.2"
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*\"",