@puckeditor/plugin-ai 0.9.0-canary.5c55a953 → 0.9.0-canary.bc43b29b
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/index.d.mts +2 -108
- package/dist/index.d.ts +2 -108
- package/dist/index.js +2741 -2634
- package/dist/index.mjs +2756 -2648
- package/package.json +13 -11
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
-
import * as ai from 'ai';
|
|
5
|
-
import { LanguageModelUsage, UIMessage, ChatOnFinishCallback, DataUIPart, CreateUIMessage, ChatStatus } from 'ai';
|
|
6
4
|
import { PuckAction, Data, Config } from '@puckeditor/core';
|
|
5
|
+
import { LanguageModelUsage, UIMessage, CreateUIMessage, DataUIPart, ChatStatus, ChatOnFinishCallback } from 'ai';
|
|
7
6
|
|
|
8
7
|
type _JSONSchema = boolean | JSONSchema;
|
|
9
8
|
type JSONSchema = {
|
|
@@ -248,32 +247,6 @@ type PuckProviderMetadata = {
|
|
|
248
247
|
|
|
249
248
|
type PuckMessage = UIMessage<PuckProviderMetadata, PuckDataParts>;
|
|
250
249
|
|
|
251
|
-
type SubagentChildPart = {
|
|
252
|
-
kind: "text";
|
|
253
|
-
blockId: string;
|
|
254
|
-
text: string;
|
|
255
|
-
} | {
|
|
256
|
-
kind: "reasoning";
|
|
257
|
-
blockId: string;
|
|
258
|
-
text: string;
|
|
259
|
-
state: "streaming" | "done";
|
|
260
|
-
} | {
|
|
261
|
-
kind: "tool";
|
|
262
|
-
childToolCallId: string;
|
|
263
|
-
toolName: string;
|
|
264
|
-
input?: unknown;
|
|
265
|
-
output?: unknown;
|
|
266
|
-
};
|
|
267
|
-
type SubagentState = {
|
|
268
|
-
toolCallId: string;
|
|
269
|
-
parentToolCallId?: string;
|
|
270
|
-
agentType: string;
|
|
271
|
-
depth: number;
|
|
272
|
-
label: string;
|
|
273
|
-
state: "running" | "done";
|
|
274
|
-
parts: SubagentChildPart[];
|
|
275
|
-
};
|
|
276
|
-
|
|
277
250
|
type Mode = "assembly" | "design";
|
|
278
251
|
type RequestOptions = {
|
|
279
252
|
body?: {
|
|
@@ -288,84 +261,6 @@ type RequestOptions = {
|
|
|
288
261
|
headers?: HeadersInit;
|
|
289
262
|
credentials?: RequestCredentials;
|
|
290
263
|
};
|
|
291
|
-
type UsePuckAiOptions = {
|
|
292
|
-
/** Endpoint serving the chat stream. Defaults to `/api/puck/chat`. */
|
|
293
|
-
host?: string;
|
|
294
|
-
/**
|
|
295
|
-
* Endpoint serving one-shot generations for `stream()`. Defaults to
|
|
296
|
-
* `/api/puck/stream`.
|
|
297
|
-
*/
|
|
298
|
-
streamHost?: string;
|
|
299
|
-
/**
|
|
300
|
-
* Whether the agent assembles your components or designs new ones. Read at
|
|
301
|
-
* request time, so a plugin can flip it between calls.
|
|
302
|
-
*/
|
|
303
|
-
mode?: Mode;
|
|
304
|
-
apiVersion?: string;
|
|
305
|
-
/** Adjust the outgoing request — add auth headers, extra body fields. */
|
|
306
|
-
prepareRequest?: (opts: RequestOptions) => RequestOptions | Promise<RequestOptions>;
|
|
307
|
-
onFinish?: ChatOnFinishCallback<PuckMessage>;
|
|
308
|
-
onError?: (error: Error) => void;
|
|
309
|
-
};
|
|
310
|
-
type SendMessageOptions = {
|
|
311
|
-
/** Override the hook's mode for this call. */
|
|
312
|
-
mode?: Mode;
|
|
313
|
-
/** Attachments to send alongside the prompt. */
|
|
314
|
-
files?: Extract<PuckMessage["parts"][number], {
|
|
315
|
-
type: "file";
|
|
316
|
-
}>[];
|
|
317
|
-
};
|
|
318
|
-
type StreamOptions = {
|
|
319
|
-
/** Override the hook's mode for this call. */
|
|
320
|
-
mode?: Mode;
|
|
321
|
-
/** Extra context for this generation. */
|
|
322
|
-
context?: string;
|
|
323
|
-
};
|
|
324
|
-
/**
|
|
325
|
-
* Puck AI, wired into the editor you're already inside.
|
|
326
|
-
*
|
|
327
|
-
* Call it from any plugin render or override — it reads the editor through
|
|
328
|
-
* `useGetPuck`, so there's no provider to add. `stream()` sends a prompt and
|
|
329
|
-
* applies everything that comes back to the live canvas: component writes,
|
|
330
|
-
* design-mode definitions, and the screenshot/page-data round trips the agent
|
|
331
|
-
* uses to see what it built.
|
|
332
|
-
*
|
|
333
|
-
* The UI is yours. This owns the transport and the editor mutations only.
|
|
334
|
-
*/
|
|
335
|
-
declare function usePuckAi({ host, streamHost, mode, apiVersion, prepareRequest, onFinish, onError, }?: UsePuckAiOptions): {
|
|
336
|
-
/**
|
|
337
|
-
* Send a prompt as the next turn of a conversation. The agent sees the
|
|
338
|
-
* history, and can write, check its work and correct itself.
|
|
339
|
-
*/
|
|
340
|
-
sendMessage: (prompt: string, opts?: SendMessageOptions) => Promise<void>;
|
|
341
|
-
/**
|
|
342
|
-
* Run a one-shot generation from a prompt, with no conversation. Cheaper
|
|
343
|
-
* and more predictable than `sendMessage`, but it stops after its first
|
|
344
|
-
* write rather than reviewing the result.
|
|
345
|
-
*/
|
|
346
|
-
stream: (prompt: string, opts?: StreamOptions) => Promise<void>;
|
|
347
|
-
/** Abort whichever request is in flight */
|
|
348
|
-
stop: () => void;
|
|
349
|
-
status: ai.ChatStatus;
|
|
350
|
-
/** The conversation so far, for building a transcript */
|
|
351
|
-
messages: PuckMessage[];
|
|
352
|
-
setMessages: (messages: PuckMessage[] | ((messages: PuckMessage[]) => PuckMessage[])) => void;
|
|
353
|
-
regenerate: ({ messageId, ...options }?: {
|
|
354
|
-
messageId?: string;
|
|
355
|
-
} & ai.ChatRequestOptions) => Promise<void>;
|
|
356
|
-
error: string | undefined;
|
|
357
|
-
/** Live per-tool progress, keyed by tool call id */
|
|
358
|
-
toolStatus: Record<string, ToolStatus>;
|
|
359
|
-
/** Live subagent progress, keyed by tool call id */
|
|
360
|
-
subagentState: Record<string, SubagentState>;
|
|
361
|
-
/**
|
|
362
|
-
* @internal Apply a single stream part to the editor. Exposed for
|
|
363
|
-
* replaying a recorded stream (the marketing demo) — a real agent should
|
|
364
|
-
* go through `stream`.
|
|
365
|
-
*/
|
|
366
|
-
processData: (dataPart: DataUIPart<PuckDataParts>) => void;
|
|
367
|
-
};
|
|
368
|
-
|
|
369
264
|
type AiPluginProps = {
|
|
370
265
|
host?: string;
|
|
371
266
|
chat?: {
|
|
@@ -411,7 +306,6 @@ declare global {
|
|
|
411
306
|
}
|
|
412
307
|
|
|
413
308
|
declare function withDynamicConfig<UserConfig extends Config>(config: UserConfig, data: Data): UserConfig;
|
|
414
|
-
|
|
415
309
|
declare function createAiPlugin(opts?: AiPluginProps): {
|
|
416
310
|
label: string;
|
|
417
311
|
name: string;
|
|
@@ -428,4 +322,4 @@ declare function createAiPlugin(opts?: AiPluginProps): {
|
|
|
428
322
|
};
|
|
429
323
|
};
|
|
430
324
|
|
|
431
|
-
export { type ComponentAiParams, type FieldAiParams,
|
|
325
|
+
export { type ComponentAiParams, type FieldAiParams, createAiPlugin, withDynamicConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
-
import * as ai from 'ai';
|
|
5
|
-
import { LanguageModelUsage, UIMessage, ChatOnFinishCallback, DataUIPart, CreateUIMessage, ChatStatus } from 'ai';
|
|
6
4
|
import { PuckAction, Data, Config } from '@puckeditor/core';
|
|
5
|
+
import { LanguageModelUsage, UIMessage, CreateUIMessage, DataUIPart, ChatStatus, ChatOnFinishCallback } from 'ai';
|
|
7
6
|
|
|
8
7
|
type _JSONSchema = boolean | JSONSchema;
|
|
9
8
|
type JSONSchema = {
|
|
@@ -248,32 +247,6 @@ type PuckProviderMetadata = {
|
|
|
248
247
|
|
|
249
248
|
type PuckMessage = UIMessage<PuckProviderMetadata, PuckDataParts>;
|
|
250
249
|
|
|
251
|
-
type SubagentChildPart = {
|
|
252
|
-
kind: "text";
|
|
253
|
-
blockId: string;
|
|
254
|
-
text: string;
|
|
255
|
-
} | {
|
|
256
|
-
kind: "reasoning";
|
|
257
|
-
blockId: string;
|
|
258
|
-
text: string;
|
|
259
|
-
state: "streaming" | "done";
|
|
260
|
-
} | {
|
|
261
|
-
kind: "tool";
|
|
262
|
-
childToolCallId: string;
|
|
263
|
-
toolName: string;
|
|
264
|
-
input?: unknown;
|
|
265
|
-
output?: unknown;
|
|
266
|
-
};
|
|
267
|
-
type SubagentState = {
|
|
268
|
-
toolCallId: string;
|
|
269
|
-
parentToolCallId?: string;
|
|
270
|
-
agentType: string;
|
|
271
|
-
depth: number;
|
|
272
|
-
label: string;
|
|
273
|
-
state: "running" | "done";
|
|
274
|
-
parts: SubagentChildPart[];
|
|
275
|
-
};
|
|
276
|
-
|
|
277
250
|
type Mode = "assembly" | "design";
|
|
278
251
|
type RequestOptions = {
|
|
279
252
|
body?: {
|
|
@@ -288,84 +261,6 @@ type RequestOptions = {
|
|
|
288
261
|
headers?: HeadersInit;
|
|
289
262
|
credentials?: RequestCredentials;
|
|
290
263
|
};
|
|
291
|
-
type UsePuckAiOptions = {
|
|
292
|
-
/** Endpoint serving the chat stream. Defaults to `/api/puck/chat`. */
|
|
293
|
-
host?: string;
|
|
294
|
-
/**
|
|
295
|
-
* Endpoint serving one-shot generations for `stream()`. Defaults to
|
|
296
|
-
* `/api/puck/stream`.
|
|
297
|
-
*/
|
|
298
|
-
streamHost?: string;
|
|
299
|
-
/**
|
|
300
|
-
* Whether the agent assembles your components or designs new ones. Read at
|
|
301
|
-
* request time, so a plugin can flip it between calls.
|
|
302
|
-
*/
|
|
303
|
-
mode?: Mode;
|
|
304
|
-
apiVersion?: string;
|
|
305
|
-
/** Adjust the outgoing request — add auth headers, extra body fields. */
|
|
306
|
-
prepareRequest?: (opts: RequestOptions) => RequestOptions | Promise<RequestOptions>;
|
|
307
|
-
onFinish?: ChatOnFinishCallback<PuckMessage>;
|
|
308
|
-
onError?: (error: Error) => void;
|
|
309
|
-
};
|
|
310
|
-
type SendMessageOptions = {
|
|
311
|
-
/** Override the hook's mode for this call. */
|
|
312
|
-
mode?: Mode;
|
|
313
|
-
/** Attachments to send alongside the prompt. */
|
|
314
|
-
files?: Extract<PuckMessage["parts"][number], {
|
|
315
|
-
type: "file";
|
|
316
|
-
}>[];
|
|
317
|
-
};
|
|
318
|
-
type StreamOptions = {
|
|
319
|
-
/** Override the hook's mode for this call. */
|
|
320
|
-
mode?: Mode;
|
|
321
|
-
/** Extra context for this generation. */
|
|
322
|
-
context?: string;
|
|
323
|
-
};
|
|
324
|
-
/**
|
|
325
|
-
* Puck AI, wired into the editor you're already inside.
|
|
326
|
-
*
|
|
327
|
-
* Call it from any plugin render or override — it reads the editor through
|
|
328
|
-
* `useGetPuck`, so there's no provider to add. `stream()` sends a prompt and
|
|
329
|
-
* applies everything that comes back to the live canvas: component writes,
|
|
330
|
-
* design-mode definitions, and the screenshot/page-data round trips the agent
|
|
331
|
-
* uses to see what it built.
|
|
332
|
-
*
|
|
333
|
-
* The UI is yours. This owns the transport and the editor mutations only.
|
|
334
|
-
*/
|
|
335
|
-
declare function usePuckAi({ host, streamHost, mode, apiVersion, prepareRequest, onFinish, onError, }?: UsePuckAiOptions): {
|
|
336
|
-
/**
|
|
337
|
-
* Send a prompt as the next turn of a conversation. The agent sees the
|
|
338
|
-
* history, and can write, check its work and correct itself.
|
|
339
|
-
*/
|
|
340
|
-
sendMessage: (prompt: string, opts?: SendMessageOptions) => Promise<void>;
|
|
341
|
-
/**
|
|
342
|
-
* Run a one-shot generation from a prompt, with no conversation. Cheaper
|
|
343
|
-
* and more predictable than `sendMessage`, but it stops after its first
|
|
344
|
-
* write rather than reviewing the result.
|
|
345
|
-
*/
|
|
346
|
-
stream: (prompt: string, opts?: StreamOptions) => Promise<void>;
|
|
347
|
-
/** Abort whichever request is in flight */
|
|
348
|
-
stop: () => void;
|
|
349
|
-
status: ai.ChatStatus;
|
|
350
|
-
/** The conversation so far, for building a transcript */
|
|
351
|
-
messages: PuckMessage[];
|
|
352
|
-
setMessages: (messages: PuckMessage[] | ((messages: PuckMessage[]) => PuckMessage[])) => void;
|
|
353
|
-
regenerate: ({ messageId, ...options }?: {
|
|
354
|
-
messageId?: string;
|
|
355
|
-
} & ai.ChatRequestOptions) => Promise<void>;
|
|
356
|
-
error: string | undefined;
|
|
357
|
-
/** Live per-tool progress, keyed by tool call id */
|
|
358
|
-
toolStatus: Record<string, ToolStatus>;
|
|
359
|
-
/** Live subagent progress, keyed by tool call id */
|
|
360
|
-
subagentState: Record<string, SubagentState>;
|
|
361
|
-
/**
|
|
362
|
-
* @internal Apply a single stream part to the editor. Exposed for
|
|
363
|
-
* replaying a recorded stream (the marketing demo) — a real agent should
|
|
364
|
-
* go through `stream`.
|
|
365
|
-
*/
|
|
366
|
-
processData: (dataPart: DataUIPart<PuckDataParts>) => void;
|
|
367
|
-
};
|
|
368
|
-
|
|
369
264
|
type AiPluginProps = {
|
|
370
265
|
host?: string;
|
|
371
266
|
chat?: {
|
|
@@ -411,7 +306,6 @@ declare global {
|
|
|
411
306
|
}
|
|
412
307
|
|
|
413
308
|
declare function withDynamicConfig<UserConfig extends Config>(config: UserConfig, data: Data): UserConfig;
|
|
414
|
-
|
|
415
309
|
declare function createAiPlugin(opts?: AiPluginProps): {
|
|
416
310
|
label: string;
|
|
417
311
|
name: string;
|
|
@@ -428,4 +322,4 @@ declare function createAiPlugin(opts?: AiPluginProps): {
|
|
|
428
322
|
};
|
|
429
323
|
};
|
|
430
324
|
|
|
431
|
-
export { type ComponentAiParams, type FieldAiParams,
|
|
325
|
+
export { type ComponentAiParams, type FieldAiParams, createAiPlugin, withDynamicConfig };
|