@puckeditor/cloud-client 0.4.1-canary.fd833f7d → 0.5.0-canary.c689dcb2
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 +18 -2
- package/dist/index.d.ts +18 -2
- package/dist/index.js +9 -2
- package/dist/index.mjs +9 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -2,6 +2,18 @@ import z from 'zod/v4';
|
|
|
2
2
|
import { UIMessage } from 'ai';
|
|
3
3
|
import { Config, Data } from '@measured/puck';
|
|
4
4
|
|
|
5
|
+
type TokenUsage = {
|
|
6
|
+
inputTokens: number | undefined;
|
|
7
|
+
outputTokens: number | undefined;
|
|
8
|
+
totalTokens: number | undefined;
|
|
9
|
+
reasoningTokens?: number | undefined;
|
|
10
|
+
cachedInputTokens?: number | undefined;
|
|
11
|
+
};
|
|
12
|
+
type DataFinish = {
|
|
13
|
+
totalCost: number;
|
|
14
|
+
tokenUsage: TokenUsage;
|
|
15
|
+
};
|
|
16
|
+
|
|
5
17
|
type UserTool<INPUT extends z.ZodTypeAny = z.ZodTypeAny, OUTPUT extends z.ZodTypeAny = z.ZodTypeAny> = {
|
|
6
18
|
name?: string;
|
|
7
19
|
description: string;
|
|
@@ -27,21 +39,25 @@ type GenerateParams = {
|
|
|
27
39
|
tools?: UserToolRegistry;
|
|
28
40
|
host?: string;
|
|
29
41
|
apiKey?: string;
|
|
42
|
+
onFinish?: OnFinishCallback;
|
|
30
43
|
};
|
|
31
|
-
declare function generate({ prompt, config, pageData, context, tools, apiKey, host, }: GenerateParams): Promise<null>;
|
|
44
|
+
declare function generate({ prompt, config, pageData, context, tools, apiKey, host, onFinish, }: GenerateParams): Promise<null>;
|
|
32
45
|
|
|
33
46
|
declare function puckHandler(request: Request, options: PuckCloudOptions): Promise<Response>;
|
|
34
47
|
|
|
35
48
|
declare const endpoints: readonly ["chat"];
|
|
36
49
|
type Endpoint = (typeof endpoints)[number];
|
|
50
|
+
type OnFinishResult = DataFinish;
|
|
51
|
+
type OnFinishCallback = (result: OnFinishResult) => void;
|
|
37
52
|
type PuckCloudOptions = {
|
|
38
53
|
ai?: {
|
|
39
54
|
context?: string;
|
|
40
55
|
tools?: UserToolRegistry;
|
|
56
|
+
onFinish?: OnFinishCallback;
|
|
41
57
|
};
|
|
42
58
|
host?: string;
|
|
43
59
|
apiKey?: string;
|
|
44
60
|
};
|
|
45
61
|
type UserToolRegistry = Record<string, UserTool>;
|
|
46
62
|
|
|
47
|
-
export { type ChatParams, type Endpoint, type GenerateParams, type PuckCloudOptions, type UserTool, type UserToolRegistry, chat, endpoints, generate, puckHandler, tool };
|
|
63
|
+
export { type ChatParams, 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
|
@@ -2,6 +2,18 @@ import z from 'zod/v4';
|
|
|
2
2
|
import { UIMessage } from 'ai';
|
|
3
3
|
import { Config, Data } from '@measured/puck';
|
|
4
4
|
|
|
5
|
+
type TokenUsage = {
|
|
6
|
+
inputTokens: number | undefined;
|
|
7
|
+
outputTokens: number | undefined;
|
|
8
|
+
totalTokens: number | undefined;
|
|
9
|
+
reasoningTokens?: number | undefined;
|
|
10
|
+
cachedInputTokens?: number | undefined;
|
|
11
|
+
};
|
|
12
|
+
type DataFinish = {
|
|
13
|
+
totalCost: number;
|
|
14
|
+
tokenUsage: TokenUsage;
|
|
15
|
+
};
|
|
16
|
+
|
|
5
17
|
type UserTool<INPUT extends z.ZodTypeAny = z.ZodTypeAny, OUTPUT extends z.ZodTypeAny = z.ZodTypeAny> = {
|
|
6
18
|
name?: string;
|
|
7
19
|
description: string;
|
|
@@ -27,21 +39,25 @@ type GenerateParams = {
|
|
|
27
39
|
tools?: UserToolRegistry;
|
|
28
40
|
host?: string;
|
|
29
41
|
apiKey?: string;
|
|
42
|
+
onFinish?: OnFinishCallback;
|
|
30
43
|
};
|
|
31
|
-
declare function generate({ prompt, config, pageData, context, tools, apiKey, host, }: GenerateParams): Promise<null>;
|
|
44
|
+
declare function generate({ prompt, config, pageData, context, tools, apiKey, host, onFinish, }: GenerateParams): Promise<null>;
|
|
32
45
|
|
|
33
46
|
declare function puckHandler(request: Request, options: PuckCloudOptions): Promise<Response>;
|
|
34
47
|
|
|
35
48
|
declare const endpoints: readonly ["chat"];
|
|
36
49
|
type Endpoint = (typeof endpoints)[number];
|
|
50
|
+
type OnFinishResult = DataFinish;
|
|
51
|
+
type OnFinishCallback = (result: OnFinishResult) => void;
|
|
37
52
|
type PuckCloudOptions = {
|
|
38
53
|
ai?: {
|
|
39
54
|
context?: string;
|
|
40
55
|
tools?: UserToolRegistry;
|
|
56
|
+
onFinish?: OnFinishCallback;
|
|
41
57
|
};
|
|
42
58
|
host?: string;
|
|
43
59
|
apiKey?: string;
|
|
44
60
|
};
|
|
45
61
|
type UserToolRegistry = Record<string, UserTool>;
|
|
46
62
|
|
|
47
|
-
export { type ChatParams, type Endpoint, type GenerateParams, type PuckCloudOptions, type UserTool, type UserToolRegistry, chat, endpoints, generate, puckHandler, tool };
|
|
63
|
+
export { type ChatParams, type Endpoint, type GenerateParams, type OnFinishCallback, type OnFinishResult, type PuckCloudOptions, type UserTool, type UserToolRegistry, chat, endpoints, generate, puckHandler, tool };
|
package/dist/index.js
CHANGED
|
@@ -19742,7 +19742,11 @@ function chat({ chatId, messages, config: config2, pageData }, options = {}) {
|
|
|
19742
19742
|
{ chatId, config: config2, messages, pageData },
|
|
19743
19743
|
options,
|
|
19744
19744
|
(chunk) => {
|
|
19745
|
-
|
|
19745
|
+
if (chunk.type === "data-finish") {
|
|
19746
|
+
options.ai?.onFinish?.(chunk.data);
|
|
19747
|
+
} else {
|
|
19748
|
+
writer.write(chunk);
|
|
19749
|
+
}
|
|
19746
19750
|
}
|
|
19747
19751
|
);
|
|
19748
19752
|
}
|
|
@@ -19758,13 +19762,16 @@ async function generate({
|
|
|
19758
19762
|
context,
|
|
19759
19763
|
tools,
|
|
19760
19764
|
apiKey,
|
|
19761
|
-
host
|
|
19765
|
+
host,
|
|
19766
|
+
onFinish
|
|
19762
19767
|
}) {
|
|
19763
19768
|
let result = null;
|
|
19764
19769
|
const options = { ai: { context, tools }, apiKey, host };
|
|
19765
19770
|
await cloudApi("generate", { prompt, config: config2, pageData }, options, (chunk) => {
|
|
19766
19771
|
if (chunk.type === "data-page") {
|
|
19767
19772
|
result = chunk.data;
|
|
19773
|
+
} else if (chunk.type === "data-finish") {
|
|
19774
|
+
onFinish?.(chunk.data);
|
|
19768
19775
|
} else if (chunk.type === "error") {
|
|
19769
19776
|
throw new Error(chunk.errorText);
|
|
19770
19777
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -19708,7 +19708,11 @@ function chat({ chatId, messages, config: config2, pageData }, options = {}) {
|
|
|
19708
19708
|
{ chatId, config: config2, messages, pageData },
|
|
19709
19709
|
options,
|
|
19710
19710
|
(chunk) => {
|
|
19711
|
-
|
|
19711
|
+
if (chunk.type === "data-finish") {
|
|
19712
|
+
options.ai?.onFinish?.(chunk.data);
|
|
19713
|
+
} else {
|
|
19714
|
+
writer.write(chunk);
|
|
19715
|
+
}
|
|
19712
19716
|
}
|
|
19713
19717
|
);
|
|
19714
19718
|
}
|
|
@@ -19724,13 +19728,16 @@ async function generate({
|
|
|
19724
19728
|
context,
|
|
19725
19729
|
tools,
|
|
19726
19730
|
apiKey,
|
|
19727
|
-
host
|
|
19731
|
+
host,
|
|
19732
|
+
onFinish
|
|
19728
19733
|
}) {
|
|
19729
19734
|
let result = null;
|
|
19730
19735
|
const options = { ai: { context, tools }, apiKey, host };
|
|
19731
19736
|
await cloudApi("generate", { prompt, config: config2, pageData }, options, (chunk) => {
|
|
19732
19737
|
if (chunk.type === "data-page") {
|
|
19733
19738
|
result = chunk.data;
|
|
19739
|
+
} else if (chunk.type === "data-finish") {
|
|
19740
|
+
onFinish?.(chunk.data);
|
|
19734
19741
|
} else if (chunk.type === "error") {
|
|
19735
19742
|
throw new Error(chunk.errorText);
|
|
19736
19743
|
}
|
package/package.json
CHANGED