@puckeditor/cloud-client 0.8.0-canary.9c5fbcbb → 0.8.0-canary.c7a937d7

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.
@@ -22183,7 +22183,7 @@ async function* iterateSSE(body) {
22183
22183
 
22184
22184
  // src/lib/cloud-api.ts
22185
22185
  var DEFAULT_API_VERSION = "v2";
22186
- var CLOUD_CLIENT_VERSION = true ? "0.8.0-canary.9c5fbcbb" : "unknown";
22186
+ var CLOUD_CLIENT_VERSION = true ? "0.8.0-canary.c7a937d7" : "unknown";
22187
22187
  var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
22188
22188
  const {
22189
22189
  ai = {},
@@ -22196,7 +22196,7 @@ var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
22196
22196
  "No Puck API key specified. Set the PUCK_API_KEY environment variable, or provide one to the function"
22197
22197
  );
22198
22198
  }
22199
- const { context, tools = {} } = ai;
22199
+ const { context, tools = {}, designMode } = ai;
22200
22200
  const res = await fetch(`${host}/${path}`, {
22201
22201
  headers: {
22202
22202
  "x-api-key": apiKey,
@@ -22208,7 +22208,10 @@ var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
22208
22208
  body: JSON.stringify({
22209
22209
  ...body,
22210
22210
  context,
22211
- tools: prepareUserTools(tools)
22211
+ tools: prepareUserTools(tools),
22212
+ ...designMode ? {
22213
+ designMode
22214
+ } : {}
22212
22215
  })
22213
22216
  });
22214
22217
  if (!res.body) {
@@ -22230,12 +22233,34 @@ var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
22230
22233
  };
22231
22234
 
22232
22235
  // src/api/chat.ts
22236
+ function chatPrivate({ chatId, messages, config: config2, pageData, mode }, options = {}, forwardHeaders) {
22237
+ const resolvedMode = mode ?? options?.ai?.mode;
22238
+ const stream = createUIMessageStream({
22239
+ execute: async ({ writer }) => {
22240
+ await cloudApi(
22241
+ "chat",
22242
+ { chatId, config: config2, messages, pageData, mode: resolvedMode },
22243
+ options,
22244
+ (chunk) => {
22245
+ if (chunk.type === "data-finish") {
22246
+ options.ai?.onFinish?.(chunk.data);
22247
+ } else {
22248
+ writer.write(chunk);
22249
+ }
22250
+ },
22251
+ forwardHeaders
22252
+ );
22253
+ }
22254
+ });
22255
+ return createUIMessageStreamResponse({ stream });
22256
+ }
22233
22257
  function chat({ chatId, messages, config: config2, pageData }, options = {}, forwardHeaders) {
22258
+ const resolvedMode = options?.ai?.mode;
22234
22259
  const stream = createUIMessageStream({
22235
22260
  execute: async ({ writer }) => {
22236
22261
  await cloudApi(
22237
22262
  "chat",
22238
- { chatId, config: config2, messages, pageData },
22263
+ { chatId, config: config2, messages, pageData, mode: resolvedMode },
22239
22264
  options,
22240
22265
  (chunk) => {
22241
22266
  if (chunk.type === "data-finish") {
@@ -22274,6 +22299,9 @@ async function generate({
22274
22299
  throw new Error(chunk.errorText);
22275
22300
  }
22276
22301
  });
22302
+ if (result === null) {
22303
+ throw new Error("Puck generate did not return any data");
22304
+ }
22277
22305
  return result;
22278
22306
  }
22279
22307
 
@@ -22442,7 +22470,7 @@ var routeRegistry = [
22442
22470
  {
22443
22471
  pattern: "/api/puck/chat",
22444
22472
  methods: {
22445
- POST: ({ body, headers }, options) => chat(body, options, {
22473
+ POST: ({ body, headers }, options) => chatPrivate(body, options, {
22446
22474
  pluginAiVersion: headers.get("x-puck-plugin-ai-version")
22447
22475
  })
22448
22476
  }
@@ -22511,6 +22539,7 @@ var endpoints = ["chat"];
22511
22539
 
22512
22540
  export {
22513
22541
  getApiKey,
22542
+ chatPrivate,
22514
22543
  chat,
22515
22544
  createAttachments,
22516
22545
  getAttachment,
@@ -1,5 +1,5 @@
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, UserTool, UserToolRegistry, chat, endpoints, generate, tool } from './index.mjs';
3
3
  import { Data } from '@puckeditor/core';
4
4
  import 'zod/v4';
5
5
  import 'ai';
@@ -1,5 +1,5 @@
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, UserTool, UserToolRegistry, chat, endpoints, generate, tool } from './index.js';
3
3
  import { Data } from '@puckeditor/core';
4
4
  import 'zod/v4';
5
5
  import 'ai';
@@ -22226,7 +22226,7 @@ async function* iterateSSE(body) {
22226
22226
 
22227
22227
  // src/lib/cloud-api.ts
22228
22228
  var DEFAULT_API_VERSION = "v2";
22229
- var CLOUD_CLIENT_VERSION = true ? "0.8.0-canary.9c5fbcbb" : "unknown";
22229
+ var CLOUD_CLIENT_VERSION = true ? "0.8.0-canary.c7a937d7" : "unknown";
22230
22230
  var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
22231
22231
  const {
22232
22232
  ai = {},
@@ -22239,7 +22239,7 @@ var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
22239
22239
  "No Puck API key specified. Set the PUCK_API_KEY environment variable, or provide one to the function"
22240
22240
  );
22241
22241
  }
22242
- const { context, tools = {} } = ai;
22242
+ const { context, tools = {}, designMode } = ai;
22243
22243
  const res = await fetch(`${host}/${path}`, {
22244
22244
  headers: {
22245
22245
  "x-api-key": apiKey,
@@ -22251,7 +22251,10 @@ var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
22251
22251
  body: JSON.stringify({
22252
22252
  ...body,
22253
22253
  context,
22254
- tools: prepareUserTools(tools)
22254
+ tools: prepareUserTools(tools),
22255
+ ...designMode ? {
22256
+ designMode
22257
+ } : {}
22255
22258
  })
22256
22259
  });
22257
22260
  if (!res.body) {
@@ -22273,12 +22276,34 @@ var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
22273
22276
  };
22274
22277
 
22275
22278
  // src/api/chat.ts
22279
+ function chatPrivate({ chatId, messages, config: config2, pageData, mode }, options = {}, forwardHeaders) {
22280
+ const resolvedMode = mode ?? options?.ai?.mode;
22281
+ const stream = createUIMessageStream({
22282
+ execute: async ({ writer }) => {
22283
+ await cloudApi(
22284
+ "chat",
22285
+ { chatId, config: config2, messages, pageData, mode: resolvedMode },
22286
+ options,
22287
+ (chunk) => {
22288
+ if (chunk.type === "data-finish") {
22289
+ options.ai?.onFinish?.(chunk.data);
22290
+ } else {
22291
+ writer.write(chunk);
22292
+ }
22293
+ },
22294
+ forwardHeaders
22295
+ );
22296
+ }
22297
+ });
22298
+ return createUIMessageStreamResponse({ stream });
22299
+ }
22276
22300
  function chat({ chatId, messages, config: config2, pageData }, options = {}, forwardHeaders) {
22301
+ const resolvedMode = options?.ai?.mode;
22277
22302
  const stream = createUIMessageStream({
22278
22303
  execute: async ({ writer }) => {
22279
22304
  await cloudApi(
22280
22305
  "chat",
22281
- { chatId, config: config2, messages, pageData },
22306
+ { chatId, config: config2, messages, pageData, mode: resolvedMode },
22282
22307
  options,
22283
22308
  (chunk) => {
22284
22309
  if (chunk.type === "data-finish") {
@@ -22803,6 +22828,9 @@ async function generate({
22803
22828
  throw new Error(chunk.errorText);
22804
22829
  }
22805
22830
  });
22831
+ if (result === null) {
22832
+ throw new Error("Puck generate did not return any data");
22833
+ }
22806
22834
  return result;
22807
22835
  }
22808
22836
 
@@ -22833,7 +22861,7 @@ var routeRegistry = [
22833
22861
  {
22834
22862
  pattern: "/api/puck/chat",
22835
22863
  methods: {
22836
- POST: ({ body }, options) => chat(body, options)
22864
+ POST: ({ body }, options) => chatPrivate(body, options)
22837
22865
  }
22838
22866
  },
22839
22867
  {
@@ -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-XFKCRMW6.mjs";
14
+ } from "./chunk-G2V2GZEF.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) => chat(body, options)
331
+ POST: ({ body }, options) => chatPrivate(body, options)
331
332
  }
332
333
  },
333
334
  {
package/dist/index.d.mts CHANGED
@@ -30,10 +30,25 @@ type DataFinish = {
30
30
  type OnFinishResult = DataFinish;
31
31
  type OnFinishCallback = (result: OnFinishResult) => void;
32
32
  type UserToolRegistry = Record<string, UserTool>;
33
+ type DesignModeOptions = {
34
+ /**
35
+ * Set to true to allow design-mode requests. Defaults to false.
36
+ */
37
+ allowed?: boolean;
38
+ instructions?: string;
39
+ /**
40
+ * Set to true to allow generated components to include scripts. When
41
+ * disabled, the `script` field is removed from the custom component schema,
42
+ * so the model never generates it. Defaults to false.
43
+ */
44
+ scripts?: boolean;
45
+ };
33
46
  type PuckAiOptions = {
34
47
  context?: string;
35
48
  tools?: UserToolRegistry;
36
49
  onFinish?: OnFinishCallback;
50
+ designMode?: DesignModeOptions;
51
+ mode?: "assembly" | "design";
37
52
  };
38
53
  type PuckCloudOptions = {
39
54
  ai?: PuckAiOptions;
@@ -63,11 +78,11 @@ type GenerateParams = {
63
78
  apiKey?: string;
64
79
  onFinish?: OnFinishCallback;
65
80
  };
66
- declare function generate({ prompt, config, pageData, context, tools, apiKey, host, onFinish, }: GenerateParams): Promise<null>;
81
+ declare function generate({ prompt, config, pageData, context, tools, apiKey, host, onFinish, }: GenerateParams): Promise<Data>;
67
82
 
68
83
  declare function puckHandler(request: Request, options?: PuckCloudOptions): Promise<Response>;
69
84
 
70
85
  declare const endpoints: readonly ["chat"];
71
86
  type Endpoint = (typeof endpoints)[number];
72
87
 
73
- export { type ChatParams, type Endpoint, type GenerateParams, type OnFinishCallback, type OnFinishResult, type PuckCloudOptions, type UserTool, type UserToolRegistry, chat, endpoints, generate, puckHandler, tool };
88
+ export { type ChatParams, type DesignModeOptions, type Endpoint, type GenerateParams, type OnFinishCallback, type OnFinishResult, type PuckCloudOptions, type UserTool, type UserToolRegistry, chat, endpoints, generate, puckHandler, tool };
package/dist/index.d.ts CHANGED
@@ -30,10 +30,25 @@ type DataFinish = {
30
30
  type OnFinishResult = DataFinish;
31
31
  type OnFinishCallback = (result: OnFinishResult) => void;
32
32
  type UserToolRegistry = Record<string, UserTool>;
33
+ type DesignModeOptions = {
34
+ /**
35
+ * Set to true to allow design-mode requests. Defaults to false.
36
+ */
37
+ allowed?: boolean;
38
+ instructions?: string;
39
+ /**
40
+ * Set to true to allow generated components to include scripts. When
41
+ * disabled, the `script` field is removed from the custom component schema,
42
+ * so the model never generates it. Defaults to false.
43
+ */
44
+ scripts?: boolean;
45
+ };
33
46
  type PuckAiOptions = {
34
47
  context?: string;
35
48
  tools?: UserToolRegistry;
36
49
  onFinish?: OnFinishCallback;
50
+ designMode?: DesignModeOptions;
51
+ mode?: "assembly" | "design";
37
52
  };
38
53
  type PuckCloudOptions = {
39
54
  ai?: PuckAiOptions;
@@ -63,11 +78,11 @@ type GenerateParams = {
63
78
  apiKey?: string;
64
79
  onFinish?: OnFinishCallback;
65
80
  };
66
- declare function generate({ prompt, config, pageData, context, tools, apiKey, host, onFinish, }: GenerateParams): Promise<null>;
81
+ declare function generate({ prompt, config, pageData, context, tools, apiKey, host, onFinish, }: GenerateParams): Promise<Data>;
67
82
 
68
83
  declare function puckHandler(request: Request, options?: PuckCloudOptions): Promise<Response>;
69
84
 
70
85
  declare const endpoints: readonly ["chat"];
71
86
  type Endpoint = (typeof endpoints)[number];
72
87
 
73
- export { type ChatParams, type Endpoint, type GenerateParams, type OnFinishCallback, type OnFinishResult, type PuckCloudOptions, type UserTool, type UserToolRegistry, chat, endpoints, generate, puckHandler, tool };
88
+ export { type ChatParams, type DesignModeOptions, type Endpoint, type GenerateParams, type OnFinishCallback, type OnFinishResult, type PuckCloudOptions, type UserTool, type UserToolRegistry, chat, endpoints, generate, puckHandler, tool };
package/dist/index.js CHANGED
@@ -22228,7 +22228,7 @@ async function* iterateSSE(body) {
22228
22228
 
22229
22229
  // src/lib/cloud-api.ts
22230
22230
  var DEFAULT_API_VERSION = "v2";
22231
- var CLOUD_CLIENT_VERSION = true ? "0.8.0-canary.9c5fbcbb" : "unknown";
22231
+ var CLOUD_CLIENT_VERSION = true ? "0.8.0-canary.c7a937d7" : "unknown";
22232
22232
  var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
22233
22233
  const {
22234
22234
  ai = {},
@@ -22241,7 +22241,7 @@ var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
22241
22241
  "No Puck API key specified. Set the PUCK_API_KEY environment variable, or provide one to the function"
22242
22242
  );
22243
22243
  }
22244
- const { context, tools = {} } = ai;
22244
+ const { context, tools = {}, designMode } = ai;
22245
22245
  const res = await fetch(`${host}/${path}`, {
22246
22246
  headers: {
22247
22247
  "x-api-key": apiKey,
@@ -22253,7 +22253,10 @@ var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
22253
22253
  body: JSON.stringify({
22254
22254
  ...body,
22255
22255
  context,
22256
- tools: prepareUserTools(tools)
22256
+ tools: prepareUserTools(tools),
22257
+ ...designMode ? {
22258
+ designMode
22259
+ } : {}
22257
22260
  })
22258
22261
  });
22259
22262
  if (!res.body) {
@@ -22275,12 +22278,34 @@ var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
22275
22278
  };
22276
22279
 
22277
22280
  // src/api/chat.ts
22281
+ function chatPrivate({ chatId, messages, config: config2, pageData, mode }, options = {}, forwardHeaders) {
22282
+ const resolvedMode = mode ?? options?.ai?.mode;
22283
+ const stream = createUIMessageStream({
22284
+ execute: async ({ writer }) => {
22285
+ await cloudApi(
22286
+ "chat",
22287
+ { chatId, config: config2, messages, pageData, mode: resolvedMode },
22288
+ options,
22289
+ (chunk) => {
22290
+ if (chunk.type === "data-finish") {
22291
+ options.ai?.onFinish?.(chunk.data);
22292
+ } else {
22293
+ writer.write(chunk);
22294
+ }
22295
+ },
22296
+ forwardHeaders
22297
+ );
22298
+ }
22299
+ });
22300
+ return createUIMessageStreamResponse({ stream });
22301
+ }
22278
22302
  function chat({ chatId, messages, config: config2, pageData }, options = {}, forwardHeaders) {
22303
+ const resolvedMode = options?.ai?.mode;
22279
22304
  const stream = createUIMessageStream({
22280
22305
  execute: async ({ writer }) => {
22281
22306
  await cloudApi(
22282
22307
  "chat",
22283
- { chatId, config: config2, messages, pageData },
22308
+ { chatId, config: config2, messages, pageData, mode: resolvedMode },
22284
22309
  options,
22285
22310
  (chunk) => {
22286
22311
  if (chunk.type === "data-finish") {
@@ -22319,6 +22344,9 @@ async function generate({
22319
22344
  throw new Error(chunk.errorText);
22320
22345
  }
22321
22346
  });
22347
+ if (result === null) {
22348
+ throw new Error("Puck generate did not return any data");
22349
+ }
22322
22350
  return result;
22323
22351
  }
22324
22352
 
@@ -22487,7 +22515,7 @@ var routeRegistry = [
22487
22515
  {
22488
22516
  pattern: "/api/puck/chat",
22489
22517
  methods: {
22490
- POST: ({ body, headers }, options) => chat(body, options, {
22518
+ POST: ({ body, headers }, options) => chatPrivate(body, options, {
22491
22519
  pluginAiVersion: headers.get("x-puck-plugin-ai-version")
22492
22520
  })
22493
22521
  }
package/dist/index.mjs CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  generate,
5
5
  puckHandler,
6
6
  tool
7
- } from "./chunk-XFKCRMW6.mjs";
7
+ } from "./chunk-G2V2GZEF.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.0-canary.9c5fbcbb",
3
+ "version": "0.8.0-canary.c7a937d7",
4
4
  "author": "Chris Villa <chris@puckeditor.com>",
5
5
  "repository": "puckeditor/puck",
6
6
  "bugs": "https://github.com/puckeditor/puck/issues",
@@ -38,7 +38,7 @@
38
38
  "dist"
39
39
  ],
40
40
  "devDependencies": {
41
- "@puckeditor/core": "0.22.0-canary.cbf13a0d",
41
+ "@puckeditor/core": "0.22.0",
42
42
  "@types/node": "^24.3.0",
43
43
  "ai": "^6.0.191",
44
44
  "eslint": "^9.39.4",