@puckeditor/cloud-client 0.8.0-canary.63de6e49 → 0.8.0-canary.672c7a1c
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-XI3V7SYA.mjs → chunk-GPNAAQUM.mjs} +46 -8
- package/dist/experimental.d.mts +1 -1
- package/dist/experimental.d.ts +1 -1
- package/dist/experimental.js +43 -8
- package/dist/experimental.mjs +3 -2
- package/dist/index.d.mts +20 -3
- package/dist/index.d.ts +20 -3
- package/dist/index.js +45 -8
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
|
@@ -22183,7 +22183,8 @@ async function* iterateSSE(body) {
|
|
|
22183
22183
|
|
|
22184
22184
|
// src/lib/cloud-api.ts
|
|
22185
22185
|
var DEFAULT_API_VERSION = "v2";
|
|
22186
|
-
var
|
|
22186
|
+
var CLOUD_CLIENT_VERSION = true ? "0.8.0-canary.672c7a1c" : "unknown";
|
|
22187
|
+
var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
|
|
22187
22188
|
const {
|
|
22188
22189
|
ai = {},
|
|
22189
22190
|
apiKey = getApiKey(),
|
|
@@ -22195,14 +22196,22 @@ var cloudApi = async (path, body, options = {}, onChunk) => {
|
|
|
22195
22196
|
"No Puck API key specified. Set the PUCK_API_KEY environment variable, or provide one to the function"
|
|
22196
22197
|
);
|
|
22197
22198
|
}
|
|
22198
|
-
const { context, tools = {} } = ai;
|
|
22199
|
+
const { context, tools = {}, designMode } = ai;
|
|
22199
22200
|
const res = await fetch(`${host}/${path}`, {
|
|
22200
|
-
headers: {
|
|
22201
|
+
headers: {
|
|
22202
|
+
"x-api-key": apiKey,
|
|
22203
|
+
"puck-api-version": apiVersion,
|
|
22204
|
+
"x-puck-cloud-client-version": CLOUD_CLIENT_VERSION,
|
|
22205
|
+
...forwardHeaders?.pluginAiVersion ? { "x-puck-plugin-ai-version": forwardHeaders.pluginAiVersion } : {}
|
|
22206
|
+
},
|
|
22201
22207
|
method: "post",
|
|
22202
22208
|
body: JSON.stringify({
|
|
22203
22209
|
...body,
|
|
22204
22210
|
context,
|
|
22205
|
-
tools: prepareUserTools(tools)
|
|
22211
|
+
tools: prepareUserTools(tools),
|
|
22212
|
+
...designMode ? {
|
|
22213
|
+
designMode
|
|
22214
|
+
} : {}
|
|
22206
22215
|
})
|
|
22207
22216
|
});
|
|
22208
22217
|
if (!res.body) {
|
|
@@ -22224,12 +22233,13 @@ var cloudApi = async (path, body, options = {}, onChunk) => {
|
|
|
22224
22233
|
};
|
|
22225
22234
|
|
|
22226
22235
|
// src/api/chat.ts
|
|
22227
|
-
function
|
|
22236
|
+
function chatPrivate({ chatId, messages, config: config2, pageData, mode }, options = {}, forwardHeaders) {
|
|
22237
|
+
const resolvedMode = mode ?? options?.ai?.mode;
|
|
22228
22238
|
const stream = createUIMessageStream({
|
|
22229
22239
|
execute: async ({ writer }) => {
|
|
22230
22240
|
await cloudApi(
|
|
22231
22241
|
"chat",
|
|
22232
|
-
{ chatId, config: config2, messages, pageData },
|
|
22242
|
+
{ chatId, config: config2, messages, pageData, mode: resolvedMode },
|
|
22233
22243
|
options,
|
|
22234
22244
|
(chunk) => {
|
|
22235
22245
|
if (chunk.type === "data-finish") {
|
|
@@ -22237,7 +22247,29 @@ function chat({ chatId, messages, config: config2, pageData }, options = {}) {
|
|
|
22237
22247
|
} else {
|
|
22238
22248
|
writer.write(chunk);
|
|
22239
22249
|
}
|
|
22240
|
-
}
|
|
22250
|
+
},
|
|
22251
|
+
forwardHeaders
|
|
22252
|
+
);
|
|
22253
|
+
}
|
|
22254
|
+
});
|
|
22255
|
+
return createUIMessageStreamResponse({ stream });
|
|
22256
|
+
}
|
|
22257
|
+
function chat({ chatId, messages, config: config2, pageData }, options = {}, forwardHeaders) {
|
|
22258
|
+
const resolvedMode = options?.ai?.mode;
|
|
22259
|
+
const stream = createUIMessageStream({
|
|
22260
|
+
execute: async ({ writer }) => {
|
|
22261
|
+
await cloudApi(
|
|
22262
|
+
"chat",
|
|
22263
|
+
{ chatId, config: config2, messages, pageData, mode: resolvedMode },
|
|
22264
|
+
options,
|
|
22265
|
+
(chunk) => {
|
|
22266
|
+
if (chunk.type === "data-finish") {
|
|
22267
|
+
options.ai?.onFinish?.(chunk.data);
|
|
22268
|
+
} else {
|
|
22269
|
+
writer.write(chunk);
|
|
22270
|
+
}
|
|
22271
|
+
},
|
|
22272
|
+
forwardHeaders
|
|
22241
22273
|
);
|
|
22242
22274
|
}
|
|
22243
22275
|
});
|
|
@@ -22267,6 +22299,9 @@ async function generate({
|
|
|
22267
22299
|
throw new Error(chunk.errorText);
|
|
22268
22300
|
}
|
|
22269
22301
|
});
|
|
22302
|
+
if (result === null) {
|
|
22303
|
+
throw new Error("Puck generate did not return any data");
|
|
22304
|
+
}
|
|
22270
22305
|
return result;
|
|
22271
22306
|
}
|
|
22272
22307
|
|
|
@@ -22435,7 +22470,9 @@ var routeRegistry = [
|
|
|
22435
22470
|
{
|
|
22436
22471
|
pattern: "/api/puck/chat",
|
|
22437
22472
|
methods: {
|
|
22438
|
-
POST: ({ body }, options) =>
|
|
22473
|
+
POST: ({ body, headers }, options) => chatPrivate(body, options, {
|
|
22474
|
+
pluginAiVersion: headers.get("x-puck-plugin-ai-version")
|
|
22475
|
+
})
|
|
22439
22476
|
}
|
|
22440
22477
|
}
|
|
22441
22478
|
];
|
|
@@ -22502,6 +22539,7 @@ var endpoints = ["chat"];
|
|
|
22502
22539
|
|
|
22503
22540
|
export {
|
|
22504
22541
|
getApiKey,
|
|
22542
|
+
chatPrivate,
|
|
22505
22543
|
chat,
|
|
22506
22544
|
createAttachments,
|
|
22507
22545
|
getAttachment,
|
package/dist/experimental.d.mts
CHANGED
|
@@ -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';
|
package/dist/experimental.d.ts
CHANGED
|
@@ -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';
|
package/dist/experimental.js
CHANGED
|
@@ -22226,7 +22226,8 @@ async function* iterateSSE(body) {
|
|
|
22226
22226
|
|
|
22227
22227
|
// src/lib/cloud-api.ts
|
|
22228
22228
|
var DEFAULT_API_VERSION = "v2";
|
|
22229
|
-
var
|
|
22229
|
+
var CLOUD_CLIENT_VERSION = true ? "0.8.0-canary.672c7a1c" : "unknown";
|
|
22230
|
+
var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
|
|
22230
22231
|
const {
|
|
22231
22232
|
ai = {},
|
|
22232
22233
|
apiKey = getApiKey(),
|
|
@@ -22238,14 +22239,22 @@ var cloudApi = async (path, body, options = {}, onChunk) => {
|
|
|
22238
22239
|
"No Puck API key specified. Set the PUCK_API_KEY environment variable, or provide one to the function"
|
|
22239
22240
|
);
|
|
22240
22241
|
}
|
|
22241
|
-
const { context, tools = {} } = ai;
|
|
22242
|
+
const { context, tools = {}, designMode } = ai;
|
|
22242
22243
|
const res = await fetch(`${host}/${path}`, {
|
|
22243
|
-
headers: {
|
|
22244
|
+
headers: {
|
|
22245
|
+
"x-api-key": apiKey,
|
|
22246
|
+
"puck-api-version": apiVersion,
|
|
22247
|
+
"x-puck-cloud-client-version": CLOUD_CLIENT_VERSION,
|
|
22248
|
+
...forwardHeaders?.pluginAiVersion ? { "x-puck-plugin-ai-version": forwardHeaders.pluginAiVersion } : {}
|
|
22249
|
+
},
|
|
22244
22250
|
method: "post",
|
|
22245
22251
|
body: JSON.stringify({
|
|
22246
22252
|
...body,
|
|
22247
22253
|
context,
|
|
22248
|
-
tools: prepareUserTools(tools)
|
|
22254
|
+
tools: prepareUserTools(tools),
|
|
22255
|
+
...designMode ? {
|
|
22256
|
+
designMode
|
|
22257
|
+
} : {}
|
|
22249
22258
|
})
|
|
22250
22259
|
});
|
|
22251
22260
|
if (!res.body) {
|
|
@@ -22267,12 +22276,13 @@ var cloudApi = async (path, body, options = {}, onChunk) => {
|
|
|
22267
22276
|
};
|
|
22268
22277
|
|
|
22269
22278
|
// src/api/chat.ts
|
|
22270
|
-
function
|
|
22279
|
+
function chatPrivate({ chatId, messages, config: config2, pageData, mode }, options = {}, forwardHeaders) {
|
|
22280
|
+
const resolvedMode = mode ?? options?.ai?.mode;
|
|
22271
22281
|
const stream = createUIMessageStream({
|
|
22272
22282
|
execute: async ({ writer }) => {
|
|
22273
22283
|
await cloudApi(
|
|
22274
22284
|
"chat",
|
|
22275
|
-
{ chatId, config: config2, messages, pageData },
|
|
22285
|
+
{ chatId, config: config2, messages, pageData, mode: resolvedMode },
|
|
22276
22286
|
options,
|
|
22277
22287
|
(chunk) => {
|
|
22278
22288
|
if (chunk.type === "data-finish") {
|
|
@@ -22280,7 +22290,29 @@ function chat({ chatId, messages, config: config2, pageData }, options = {}) {
|
|
|
22280
22290
|
} else {
|
|
22281
22291
|
writer.write(chunk);
|
|
22282
22292
|
}
|
|
22283
|
-
}
|
|
22293
|
+
},
|
|
22294
|
+
forwardHeaders
|
|
22295
|
+
);
|
|
22296
|
+
}
|
|
22297
|
+
});
|
|
22298
|
+
return createUIMessageStreamResponse({ stream });
|
|
22299
|
+
}
|
|
22300
|
+
function chat({ chatId, messages, config: config2, pageData }, options = {}, forwardHeaders) {
|
|
22301
|
+
const resolvedMode = options?.ai?.mode;
|
|
22302
|
+
const stream = createUIMessageStream({
|
|
22303
|
+
execute: async ({ writer }) => {
|
|
22304
|
+
await cloudApi(
|
|
22305
|
+
"chat",
|
|
22306
|
+
{ chatId, config: config2, messages, pageData, mode: resolvedMode },
|
|
22307
|
+
options,
|
|
22308
|
+
(chunk) => {
|
|
22309
|
+
if (chunk.type === "data-finish") {
|
|
22310
|
+
options.ai?.onFinish?.(chunk.data);
|
|
22311
|
+
} else {
|
|
22312
|
+
writer.write(chunk);
|
|
22313
|
+
}
|
|
22314
|
+
},
|
|
22315
|
+
forwardHeaders
|
|
22284
22316
|
);
|
|
22285
22317
|
}
|
|
22286
22318
|
});
|
|
@@ -22796,6 +22828,9 @@ async function generate({
|
|
|
22796
22828
|
throw new Error(chunk.errorText);
|
|
22797
22829
|
}
|
|
22798
22830
|
});
|
|
22831
|
+
if (result === null) {
|
|
22832
|
+
throw new Error("Puck generate did not return any data");
|
|
22833
|
+
}
|
|
22799
22834
|
return result;
|
|
22800
22835
|
}
|
|
22801
22836
|
|
|
@@ -22826,7 +22861,7 @@ var routeRegistry = [
|
|
|
22826
22861
|
{
|
|
22827
22862
|
pattern: "/api/puck/chat",
|
|
22828
22863
|
methods: {
|
|
22829
|
-
POST: ({ body }, options) =>
|
|
22864
|
+
POST: ({ body }, options) => chatPrivate(body, options)
|
|
22830
22865
|
}
|
|
22831
22866
|
},
|
|
22832
22867
|
{
|
package/dist/experimental.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
chat,
|
|
3
|
+
chatPrivate,
|
|
3
4
|
clientTool,
|
|
4
5
|
createAttachments,
|
|
5
6
|
deleteAttachment,
|
|
@@ -10,7 +11,7 @@ import {
|
|
|
10
11
|
getAttachment,
|
|
11
12
|
handlePuckRequest,
|
|
12
13
|
tool
|
|
13
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-GPNAAQUM.mjs";
|
|
14
15
|
import {
|
|
15
16
|
init_react_import
|
|
16
17
|
} from "./chunk-O6DC5HI2.mjs";
|
|
@@ -327,7 +328,7 @@ var routeRegistry = [
|
|
|
327
328
|
{
|
|
328
329
|
pattern: "/api/puck/chat",
|
|
329
330
|
methods: {
|
|
330
|
-
POST: ({ body }, options) =>
|
|
331
|
+
POST: ({ body }, options) => chatPrivate(body, options)
|
|
331
332
|
}
|
|
332
333
|
},
|
|
333
334
|
{
|
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;
|
|
@@ -49,7 +64,9 @@ type ChatParams = {
|
|
|
49
64
|
config: Config;
|
|
50
65
|
pageData: Data;
|
|
51
66
|
};
|
|
52
|
-
declare function chat({ chatId, messages, config, pageData }: ChatParams, options?: PuckCloudOptions | undefined
|
|
67
|
+
declare function chat({ chatId, messages, config, pageData }: ChatParams, options?: PuckCloudOptions | undefined, forwardHeaders?: {
|
|
68
|
+
pluginAiVersion?: string | null;
|
|
69
|
+
}): Response;
|
|
53
70
|
|
|
54
71
|
type GenerateParams = {
|
|
55
72
|
prompt: string;
|
|
@@ -61,11 +78,11 @@ type GenerateParams = {
|
|
|
61
78
|
apiKey?: string;
|
|
62
79
|
onFinish?: OnFinishCallback;
|
|
63
80
|
};
|
|
64
|
-
declare function generate({ prompt, config, pageData, context, tools, apiKey, host, onFinish, }: GenerateParams): Promise<
|
|
81
|
+
declare function generate({ prompt, config, pageData, context, tools, apiKey, host, onFinish, }: GenerateParams): Promise<Data>;
|
|
65
82
|
|
|
66
83
|
declare function puckHandler(request: Request, options?: PuckCloudOptions): Promise<Response>;
|
|
67
84
|
|
|
68
85
|
declare const endpoints: readonly ["chat"];
|
|
69
86
|
type Endpoint = (typeof endpoints)[number];
|
|
70
87
|
|
|
71
|
-
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;
|
|
@@ -49,7 +64,9 @@ type ChatParams = {
|
|
|
49
64
|
config: Config;
|
|
50
65
|
pageData: Data;
|
|
51
66
|
};
|
|
52
|
-
declare function chat({ chatId, messages, config, pageData }: ChatParams, options?: PuckCloudOptions | undefined
|
|
67
|
+
declare function chat({ chatId, messages, config, pageData }: ChatParams, options?: PuckCloudOptions | undefined, forwardHeaders?: {
|
|
68
|
+
pluginAiVersion?: string | null;
|
|
69
|
+
}): Response;
|
|
53
70
|
|
|
54
71
|
type GenerateParams = {
|
|
55
72
|
prompt: string;
|
|
@@ -61,11 +78,11 @@ type GenerateParams = {
|
|
|
61
78
|
apiKey?: string;
|
|
62
79
|
onFinish?: OnFinishCallback;
|
|
63
80
|
};
|
|
64
|
-
declare function generate({ prompt, config, pageData, context, tools, apiKey, host, onFinish, }: GenerateParams): Promise<
|
|
81
|
+
declare function generate({ prompt, config, pageData, context, tools, apiKey, host, onFinish, }: GenerateParams): Promise<Data>;
|
|
65
82
|
|
|
66
83
|
declare function puckHandler(request: Request, options?: PuckCloudOptions): Promise<Response>;
|
|
67
84
|
|
|
68
85
|
declare const endpoints: readonly ["chat"];
|
|
69
86
|
type Endpoint = (typeof endpoints)[number];
|
|
70
87
|
|
|
71
|
-
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,8 @@ async function* iterateSSE(body) {
|
|
|
22228
22228
|
|
|
22229
22229
|
// src/lib/cloud-api.ts
|
|
22230
22230
|
var DEFAULT_API_VERSION = "v2";
|
|
22231
|
-
var
|
|
22231
|
+
var CLOUD_CLIENT_VERSION = true ? "0.8.0-canary.672c7a1c" : "unknown";
|
|
22232
|
+
var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
|
|
22232
22233
|
const {
|
|
22233
22234
|
ai = {},
|
|
22234
22235
|
apiKey = getApiKey(),
|
|
@@ -22240,14 +22241,22 @@ var cloudApi = async (path, body, options = {}, onChunk) => {
|
|
|
22240
22241
|
"No Puck API key specified. Set the PUCK_API_KEY environment variable, or provide one to the function"
|
|
22241
22242
|
);
|
|
22242
22243
|
}
|
|
22243
|
-
const { context, tools = {} } = ai;
|
|
22244
|
+
const { context, tools = {}, designMode } = ai;
|
|
22244
22245
|
const res = await fetch(`${host}/${path}`, {
|
|
22245
|
-
headers: {
|
|
22246
|
+
headers: {
|
|
22247
|
+
"x-api-key": apiKey,
|
|
22248
|
+
"puck-api-version": apiVersion,
|
|
22249
|
+
"x-puck-cloud-client-version": CLOUD_CLIENT_VERSION,
|
|
22250
|
+
...forwardHeaders?.pluginAiVersion ? { "x-puck-plugin-ai-version": forwardHeaders.pluginAiVersion } : {}
|
|
22251
|
+
},
|
|
22246
22252
|
method: "post",
|
|
22247
22253
|
body: JSON.stringify({
|
|
22248
22254
|
...body,
|
|
22249
22255
|
context,
|
|
22250
|
-
tools: prepareUserTools(tools)
|
|
22256
|
+
tools: prepareUserTools(tools),
|
|
22257
|
+
...designMode ? {
|
|
22258
|
+
designMode
|
|
22259
|
+
} : {}
|
|
22251
22260
|
})
|
|
22252
22261
|
});
|
|
22253
22262
|
if (!res.body) {
|
|
@@ -22269,12 +22278,13 @@ var cloudApi = async (path, body, options = {}, onChunk) => {
|
|
|
22269
22278
|
};
|
|
22270
22279
|
|
|
22271
22280
|
// src/api/chat.ts
|
|
22272
|
-
function
|
|
22281
|
+
function chatPrivate({ chatId, messages, config: config2, pageData, mode }, options = {}, forwardHeaders) {
|
|
22282
|
+
const resolvedMode = mode ?? options?.ai?.mode;
|
|
22273
22283
|
const stream = createUIMessageStream({
|
|
22274
22284
|
execute: async ({ writer }) => {
|
|
22275
22285
|
await cloudApi(
|
|
22276
22286
|
"chat",
|
|
22277
|
-
{ chatId, config: config2, messages, pageData },
|
|
22287
|
+
{ chatId, config: config2, messages, pageData, mode: resolvedMode },
|
|
22278
22288
|
options,
|
|
22279
22289
|
(chunk) => {
|
|
22280
22290
|
if (chunk.type === "data-finish") {
|
|
@@ -22282,7 +22292,29 @@ function chat({ chatId, messages, config: config2, pageData }, options = {}) {
|
|
|
22282
22292
|
} else {
|
|
22283
22293
|
writer.write(chunk);
|
|
22284
22294
|
}
|
|
22285
|
-
}
|
|
22295
|
+
},
|
|
22296
|
+
forwardHeaders
|
|
22297
|
+
);
|
|
22298
|
+
}
|
|
22299
|
+
});
|
|
22300
|
+
return createUIMessageStreamResponse({ stream });
|
|
22301
|
+
}
|
|
22302
|
+
function chat({ chatId, messages, config: config2, pageData }, options = {}, forwardHeaders) {
|
|
22303
|
+
const resolvedMode = options?.ai?.mode;
|
|
22304
|
+
const stream = createUIMessageStream({
|
|
22305
|
+
execute: async ({ writer }) => {
|
|
22306
|
+
await cloudApi(
|
|
22307
|
+
"chat",
|
|
22308
|
+
{ chatId, config: config2, messages, pageData, mode: resolvedMode },
|
|
22309
|
+
options,
|
|
22310
|
+
(chunk) => {
|
|
22311
|
+
if (chunk.type === "data-finish") {
|
|
22312
|
+
options.ai?.onFinish?.(chunk.data);
|
|
22313
|
+
} else {
|
|
22314
|
+
writer.write(chunk);
|
|
22315
|
+
}
|
|
22316
|
+
},
|
|
22317
|
+
forwardHeaders
|
|
22286
22318
|
);
|
|
22287
22319
|
}
|
|
22288
22320
|
});
|
|
@@ -22312,6 +22344,9 @@ async function generate({
|
|
|
22312
22344
|
throw new Error(chunk.errorText);
|
|
22313
22345
|
}
|
|
22314
22346
|
});
|
|
22347
|
+
if (result === null) {
|
|
22348
|
+
throw new Error("Puck generate did not return any data");
|
|
22349
|
+
}
|
|
22315
22350
|
return result;
|
|
22316
22351
|
}
|
|
22317
22352
|
|
|
@@ -22480,7 +22515,9 @@ var routeRegistry = [
|
|
|
22480
22515
|
{
|
|
22481
22516
|
pattern: "/api/puck/chat",
|
|
22482
22517
|
methods: {
|
|
22483
|
-
POST: ({ body }, options) =>
|
|
22518
|
+
POST: ({ body, headers }, options) => chatPrivate(body, options, {
|
|
22519
|
+
pluginAiVersion: headers.get("x-puck-plugin-ai-version")
|
|
22520
|
+
})
|
|
22484
22521
|
}
|
|
22485
22522
|
}
|
|
22486
22523
|
];
|
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@puckeditor/cloud-client",
|
|
3
|
-
"version": "0.8.0-canary.
|
|
3
|
+
"version": "0.8.0-canary.672c7a1c",
|
|
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
|
|
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",
|