@puckeditor/cloud-client 0.1.0-canary.f56e596d → 0.1.0-canary.ff322ae0
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 +13 -21
- package/dist/index.d.ts +13 -21
- package/dist/index.js +89 -125
- package/dist/index.mjs +87 -123
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -2,10 +2,6 @@ import { UIMessage } from 'ai';
|
|
|
2
2
|
import z from 'zod/v4';
|
|
3
3
|
import { Config, Data } from '@measured/puck';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* Generator function that streams the response body from a fetch request.
|
|
7
|
-
*/
|
|
8
|
-
declare function streamingFetch(input: RequestInfo | URL, init?: RequestInit): AsyncGenerator<string, void, unknown>;
|
|
9
5
|
type UserTool<INPUT extends z.ZodTypeAny = z.ZodTypeAny, OUTPUT extends z.ZodTypeAny = z.ZodTypeAny> = {
|
|
10
6
|
name?: string;
|
|
11
7
|
description: string;
|
|
@@ -18,24 +14,20 @@ type UserToolRegistry = Record<string, UserTool>;
|
|
|
18
14
|
declare const endpoints: readonly ["chat"];
|
|
19
15
|
type Endpoint = (typeof endpoints)[number];
|
|
20
16
|
type PuckCatchAll = [Endpoint | string, ...string[]];
|
|
21
|
-
type
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
tools?: UserToolRegistry;
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
declare const createPuckApi: ({ apiKey, host, }?: {
|
|
17
|
+
type ChatParams = {
|
|
18
|
+
context?: string;
|
|
19
|
+
chatId?: string;
|
|
20
|
+
messages: UIMessage[];
|
|
21
|
+
config: Config;
|
|
22
|
+
pageData: Data;
|
|
23
|
+
tools?: UserToolRegistry;
|
|
32
24
|
host?: string;
|
|
33
25
|
apiKey?: string;
|
|
34
|
-
}) => {
|
|
35
|
-
all: <ThisEndpoint extends Endpoint | string>(path: [ThisEndpoint | string, ...string[]] | string[] | string, body: ThisEndpoint extends Endpoint ? ApiParams[ThisEndpoint] : any) => Promise<Response>;
|
|
36
|
-
ai: {
|
|
37
|
-
chat: ({ chatId, context, messages: initialMessages, config, pageData, tools, }: ApiParams["chat"]) => Promise<Response>;
|
|
38
|
-
};
|
|
39
26
|
};
|
|
27
|
+
type ApiParams = {
|
|
28
|
+
chat: ChatParams;
|
|
29
|
+
};
|
|
30
|
+
declare function chat({ chatId, context, messages: initialMessages, config, pageData, tools, apiKey, host, }: ApiParams["chat"]): Response;
|
|
31
|
+
declare function all<ThisEndpoint extends Endpoint | string>(path: [ThisEndpoint | string, ...string[]] | string[] | string, body: ThisEndpoint extends Endpoint ? ApiParams[ThisEndpoint] : any): Promise<Response>;
|
|
40
32
|
|
|
41
|
-
export { type ApiParams, type Endpoint, type PuckCatchAll,
|
|
33
|
+
export { type ApiParams, type ChatParams, type Endpoint, type PuckCatchAll, all, chat, tool };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,10 +2,6 @@ import { UIMessage } from 'ai';
|
|
|
2
2
|
import z from 'zod/v4';
|
|
3
3
|
import { Config, Data } from '@measured/puck';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* Generator function that streams the response body from a fetch request.
|
|
7
|
-
*/
|
|
8
|
-
declare function streamingFetch(input: RequestInfo | URL, init?: RequestInit): AsyncGenerator<string, void, unknown>;
|
|
9
5
|
type UserTool<INPUT extends z.ZodTypeAny = z.ZodTypeAny, OUTPUT extends z.ZodTypeAny = z.ZodTypeAny> = {
|
|
10
6
|
name?: string;
|
|
11
7
|
description: string;
|
|
@@ -18,24 +14,20 @@ type UserToolRegistry = Record<string, UserTool>;
|
|
|
18
14
|
declare const endpoints: readonly ["chat"];
|
|
19
15
|
type Endpoint = (typeof endpoints)[number];
|
|
20
16
|
type PuckCatchAll = [Endpoint | string, ...string[]];
|
|
21
|
-
type
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
tools?: UserToolRegistry;
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
declare const createPuckApi: ({ apiKey, host, }?: {
|
|
17
|
+
type ChatParams = {
|
|
18
|
+
context?: string;
|
|
19
|
+
chatId?: string;
|
|
20
|
+
messages: UIMessage[];
|
|
21
|
+
config: Config;
|
|
22
|
+
pageData: Data;
|
|
23
|
+
tools?: UserToolRegistry;
|
|
32
24
|
host?: string;
|
|
33
25
|
apiKey?: string;
|
|
34
|
-
}) => {
|
|
35
|
-
all: <ThisEndpoint extends Endpoint | string>(path: [ThisEndpoint | string, ...string[]] | string[] | string, body: ThisEndpoint extends Endpoint ? ApiParams[ThisEndpoint] : any) => Promise<Response>;
|
|
36
|
-
ai: {
|
|
37
|
-
chat: ({ chatId, context, messages: initialMessages, config, pageData, tools, }: ApiParams["chat"]) => Promise<Response>;
|
|
38
|
-
};
|
|
39
26
|
};
|
|
27
|
+
type ApiParams = {
|
|
28
|
+
chat: ChatParams;
|
|
29
|
+
};
|
|
30
|
+
declare function chat({ chatId, context, messages: initialMessages, config, pageData, tools, apiKey, host, }: ApiParams["chat"]): Response;
|
|
31
|
+
declare function all<ThisEndpoint extends Endpoint | string>(path: [ThisEndpoint | string, ...string[]] | string[] | string, body: ThisEndpoint extends Endpoint ? ApiParams[ThisEndpoint] : any): Promise<Response>;
|
|
40
32
|
|
|
41
|
-
export { type ApiParams, type Endpoint, type PuckCatchAll,
|
|
33
|
+
export { type ApiParams, type ChatParams, type Endpoint, type PuckCatchAll, all, chat, tool };
|
package/dist/index.js
CHANGED
|
@@ -36,9 +36,9 @@ var __objRest = (source, exclude) => {
|
|
|
36
36
|
}
|
|
37
37
|
return target;
|
|
38
38
|
};
|
|
39
|
-
var __export = (target,
|
|
40
|
-
for (var name17 in
|
|
41
|
-
__defProp(target, name17, { get:
|
|
39
|
+
var __export = (target, all2) => {
|
|
40
|
+
for (var name17 in all2)
|
|
41
|
+
__defProp(target, name17, { get: all2[name17], enumerable: true });
|
|
42
42
|
};
|
|
43
43
|
var __copyProps = (to, from, except, desc) => {
|
|
44
44
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
@@ -97,9 +97,8 @@ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")])
|
|
|
97
97
|
// index.ts
|
|
98
98
|
var index_exports = {};
|
|
99
99
|
__export(index_exports, {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
streamingFetch: () => streamingFetch,
|
|
100
|
+
all: () => all,
|
|
101
|
+
chat: () => chat,
|
|
103
102
|
tool: () => tool
|
|
104
103
|
});
|
|
105
104
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -17878,9 +17877,9 @@ var { btoa: btoa2, atob: atob2 } = globalThis;
|
|
|
17878
17877
|
|
|
17879
17878
|
// ../../node_modules/.pnpm/ai@5.0.44_zod@4.1.9/node_modules/ai/dist/index.mjs
|
|
17880
17879
|
var __defProp2 = Object.defineProperty;
|
|
17881
|
-
var __export2 = (target,
|
|
17882
|
-
for (var name17 in
|
|
17883
|
-
__defProp2(target, name17, { get:
|
|
17880
|
+
var __export2 = (target, all2) => {
|
|
17881
|
+
for (var name17 in all2)
|
|
17882
|
+
__defProp2(target, name17, { get: all2[name17], enumerable: true });
|
|
17884
17883
|
};
|
|
17885
17884
|
var name14 = "AI_NoOutputSpecifiedError";
|
|
17886
17885
|
var marker15 = `vercel.ai.error.${name14}`;
|
|
@@ -19660,32 +19659,6 @@ function createUIMessageStream({
|
|
|
19660
19659
|
}
|
|
19661
19660
|
|
|
19662
19661
|
// src/index.ts
|
|
19663
|
-
function streamingFetch(input, init) {
|
|
19664
|
-
return __asyncGenerator(this, null, function* () {
|
|
19665
|
-
var _a17;
|
|
19666
|
-
const response = yield new __await(fetch(input, init));
|
|
19667
|
-
const reader = (_a17 = response == null ? void 0 : response.body) == null ? void 0 : _a17.getReader();
|
|
19668
|
-
const decoder = new TextDecoder("utf-8");
|
|
19669
|
-
if (reader) {
|
|
19670
|
-
while (true) {
|
|
19671
|
-
const { done, value } = yield new __await(reader.read());
|
|
19672
|
-
if (done) break;
|
|
19673
|
-
try {
|
|
19674
|
-
const lines = decoder.decode(value).split("\n");
|
|
19675
|
-
for (const line of lines) {
|
|
19676
|
-
if (line.trim()) {
|
|
19677
|
-
if (line) {
|
|
19678
|
-
yield line;
|
|
19679
|
-
}
|
|
19680
|
-
}
|
|
19681
|
-
}
|
|
19682
|
-
} catch (e) {
|
|
19683
|
-
console.warn(e.message);
|
|
19684
|
-
}
|
|
19685
|
-
}
|
|
19686
|
-
}
|
|
19687
|
-
});
|
|
19688
|
-
}
|
|
19689
19662
|
function iterSSE(body) {
|
|
19690
19663
|
return __asyncGenerator(this, null, function* () {
|
|
19691
19664
|
const reader = body.getReader();
|
|
@@ -19725,116 +19698,107 @@ var prepareUserTools = (toolRegistry) => Object.keys(toolRegistry).reduce(
|
|
|
19725
19698
|
},
|
|
19726
19699
|
{}
|
|
19727
19700
|
);
|
|
19728
|
-
|
|
19701
|
+
function chat({
|
|
19702
|
+
chatId,
|
|
19703
|
+
context,
|
|
19704
|
+
messages: initialMessages,
|
|
19705
|
+
config: config2,
|
|
19706
|
+
pageData,
|
|
19707
|
+
tools = {},
|
|
19729
19708
|
apiKey = getApiKey(),
|
|
19730
19709
|
host = "https://app.puckbuild.com/api"
|
|
19731
|
-
}
|
|
19710
|
+
}) {
|
|
19732
19711
|
if (!apiKey) {
|
|
19733
19712
|
throw new Error(
|
|
19734
19713
|
"No Puck API key specified. Set the PUCK_API_KEY environment variable, or provide one to createPuckApi()"
|
|
19735
19714
|
);
|
|
19736
19715
|
}
|
|
19737
|
-
|
|
19738
|
-
|
|
19739
|
-
|
|
19740
|
-
|
|
19741
|
-
|
|
19742
|
-
|
|
19743
|
-
|
|
19744
|
-
|
|
19745
|
-
|
|
19746
|
-
|
|
19747
|
-
|
|
19748
|
-
|
|
19749
|
-
|
|
19750
|
-
|
|
19751
|
-
|
|
19716
|
+
let messages = initialMessages;
|
|
19717
|
+
const stream = createUIMessageStream({
|
|
19718
|
+
execute: (_0) => __async(null, [_0], function* ({ writer }) {
|
|
19719
|
+
var _a17;
|
|
19720
|
+
const res = yield fetch(`${host}/chat`, {
|
|
19721
|
+
headers: { "x-api-key": apiKey },
|
|
19722
|
+
method: "post",
|
|
19723
|
+
body: JSON.stringify({
|
|
19724
|
+
chatId,
|
|
19725
|
+
context,
|
|
19726
|
+
messages,
|
|
19727
|
+
config: config2,
|
|
19728
|
+
pageData,
|
|
19729
|
+
tools: prepareUserTools(tools)
|
|
19730
|
+
})
|
|
19731
|
+
});
|
|
19732
|
+
if (!res.body) {
|
|
19733
|
+
throw new Error(`Puck ${res.status} (${res.statusText})`);
|
|
19734
|
+
} else if (!res.ok) {
|
|
19735
|
+
const body = yield res.json();
|
|
19736
|
+
throw new Error(
|
|
19737
|
+
`Puck ${res.status} (${res.statusText}): ${(_a17 = body.error) != null ? _a17 : "Unknown reason"}`
|
|
19738
|
+
);
|
|
19739
|
+
}
|
|
19740
|
+
try {
|
|
19741
|
+
for (var iter = __forAwait(iterSSE(res.body)), more, temp, error45; more = !(temp = yield iter.next()).done; more = false) {
|
|
19742
|
+
const chunk = temp.value;
|
|
19743
|
+
if (chunk.type === "data-user-tool") {
|
|
19744
|
+
const { toolCallId, tools: requestTools } = chunk.data;
|
|
19745
|
+
const responses = [];
|
|
19746
|
+
for (let i = 0; i < requestTools.length; i++) {
|
|
19747
|
+
const { name: name17, input } = requestTools[i];
|
|
19748
|
+
const tool2 = tools == null ? void 0 : tools[name17];
|
|
19749
|
+
if (!tool2) {
|
|
19750
|
+
throw new Error(`An unknown tool was called: ${name17}`);
|
|
19751
|
+
}
|
|
19752
|
+
if (!input) {
|
|
19753
|
+
throw new Error(
|
|
19754
|
+
`Input was not present in tool call: ${toolCallId}`
|
|
19755
|
+
);
|
|
19756
|
+
}
|
|
19757
|
+
const output = yield tool2.execute(input);
|
|
19758
|
+
responses.push({ name: name17, input, output });
|
|
19759
|
+
}
|
|
19760
|
+
const res2 = yield fetch(`${host}/chat/tool`, {
|
|
19752
19761
|
headers: { "x-api-key": apiKey },
|
|
19753
19762
|
method: "post",
|
|
19754
19763
|
body: JSON.stringify({
|
|
19755
|
-
|
|
19756
|
-
|
|
19757
|
-
messages,
|
|
19758
|
-
config: config2,
|
|
19759
|
-
pageData,
|
|
19760
|
-
tools: prepareUserTools(tools)
|
|
19764
|
+
id: toolCallId,
|
|
19765
|
+
responses
|
|
19761
19766
|
})
|
|
19762
19767
|
});
|
|
19763
|
-
if (
|
|
19764
|
-
throw new Error(
|
|
19765
|
-
} else if (!res.ok) {
|
|
19766
|
-
const body = yield res.json();
|
|
19767
|
-
throw new Error(
|
|
19768
|
-
`Puck ${res.status} (${res.statusText}): ${(_a17 = body.error) != null ? _a17 : "Unknown reason"}`
|
|
19769
|
-
);
|
|
19770
|
-
}
|
|
19771
|
-
try {
|
|
19772
|
-
for (var iter = __forAwait(iterSSE(res.body)), more, temp, error45; more = !(temp = yield iter.next()).done; more = false) {
|
|
19773
|
-
const chunk = temp.value;
|
|
19774
|
-
if (chunk.type === "data-user-tool") {
|
|
19775
|
-
const { toolCallId, tools: requestTools } = chunk.data;
|
|
19776
|
-
const responses = [];
|
|
19777
|
-
for (let i = 0; i < requestTools.length; i++) {
|
|
19778
|
-
const { name: name17, input } = requestTools[i];
|
|
19779
|
-
const tool2 = tools == null ? void 0 : tools[name17];
|
|
19780
|
-
if (!tool2) {
|
|
19781
|
-
throw new Error(`An unknown tool was called: ${name17}`);
|
|
19782
|
-
}
|
|
19783
|
-
if (!input) {
|
|
19784
|
-
throw new Error(
|
|
19785
|
-
`Input was not present in tool call: ${toolCallId}`
|
|
19786
|
-
);
|
|
19787
|
-
}
|
|
19788
|
-
const output = yield tool2.execute(input);
|
|
19789
|
-
responses.push({ name: name17, input, output });
|
|
19790
|
-
}
|
|
19791
|
-
const res2 = yield fetch(`${host}/chat/tool`, {
|
|
19792
|
-
headers: { "x-api-key": apiKey },
|
|
19793
|
-
method: "post",
|
|
19794
|
-
body: JSON.stringify({
|
|
19795
|
-
id: toolCallId,
|
|
19796
|
-
responses
|
|
19797
|
-
})
|
|
19798
|
-
});
|
|
19799
|
-
if (res2.status !== 200) {
|
|
19800
|
-
throw new Error("Tool result could not be sent to server");
|
|
19801
|
-
}
|
|
19802
|
-
} else {
|
|
19803
|
-
writer.write(chunk);
|
|
19804
|
-
}
|
|
19805
|
-
}
|
|
19806
|
-
} catch (temp) {
|
|
19807
|
-
error45 = [temp];
|
|
19808
|
-
} finally {
|
|
19809
|
-
try {
|
|
19810
|
-
more && (temp = iter.return) && (yield temp.call(iter));
|
|
19811
|
-
} finally {
|
|
19812
|
-
if (error45)
|
|
19813
|
-
throw error45[0];
|
|
19814
|
-
}
|
|
19768
|
+
if (res2.status !== 200) {
|
|
19769
|
+
throw new Error("Tool result could not be sent to server");
|
|
19815
19770
|
}
|
|
19816
|
-
}
|
|
19817
|
-
|
|
19818
|
-
|
|
19819
|
-
|
|
19820
|
-
|
|
19821
|
-
|
|
19822
|
-
|
|
19771
|
+
} else {
|
|
19772
|
+
writer.write(chunk);
|
|
19773
|
+
}
|
|
19774
|
+
}
|
|
19775
|
+
} catch (temp) {
|
|
19776
|
+
error45 = [temp];
|
|
19777
|
+
} finally {
|
|
19778
|
+
try {
|
|
19779
|
+
more && (temp = iter.return) && (yield temp.call(iter));
|
|
19780
|
+
} finally {
|
|
19781
|
+
if (error45)
|
|
19782
|
+
throw error45[0];
|
|
19783
|
+
}
|
|
19784
|
+
}
|
|
19785
|
+
})
|
|
19786
|
+
});
|
|
19787
|
+
return createUIMessageStreamResponse({ stream });
|
|
19788
|
+
}
|
|
19789
|
+
function all(path, body) {
|
|
19790
|
+
return __async(this, null, function* () {
|
|
19823
19791
|
const parts = typeof path === "string" ? path.split("/") : path;
|
|
19824
19792
|
const endpoint = parts[0];
|
|
19825
19793
|
if (endpoint === "chat") {
|
|
19826
|
-
return
|
|
19794
|
+
return chat(body);
|
|
19827
19795
|
}
|
|
19828
19796
|
throw new Error(`Invalid endpoint "${endpoint}" provided to all()`);
|
|
19829
19797
|
});
|
|
19830
|
-
|
|
19831
|
-
all,
|
|
19832
|
-
ai
|
|
19833
|
-
};
|
|
19834
|
-
};
|
|
19798
|
+
}
|
|
19835
19799
|
// Annotate the CommonJS export names for ESM import in node:
|
|
19836
19800
|
0 && (module.exports = {
|
|
19837
|
-
|
|
19838
|
-
|
|
19801
|
+
all,
|
|
19802
|
+
chat,
|
|
19839
19803
|
tool
|
|
19840
19804
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -31,9 +31,9 @@ var __objRest = (source, exclude) => {
|
|
|
31
31
|
}
|
|
32
32
|
return target;
|
|
33
33
|
};
|
|
34
|
-
var __export = (target,
|
|
35
|
-
for (var name17 in
|
|
36
|
-
__defProp(target, name17, { get:
|
|
34
|
+
var __export = (target, all2) => {
|
|
35
|
+
for (var name17 in all2)
|
|
36
|
+
__defProp(target, name17, { get: all2[name17], enumerable: true });
|
|
37
37
|
};
|
|
38
38
|
var __async = (__this, __arguments, generator) => {
|
|
39
39
|
return new Promise((resolve, reject) => {
|
|
@@ -17846,9 +17846,9 @@ var { btoa: btoa2, atob: atob2 } = globalThis;
|
|
|
17846
17846
|
|
|
17847
17847
|
// ../../node_modules/.pnpm/ai@5.0.44_zod@4.1.9/node_modules/ai/dist/index.mjs
|
|
17848
17848
|
var __defProp2 = Object.defineProperty;
|
|
17849
|
-
var __export2 = (target,
|
|
17850
|
-
for (var name17 in
|
|
17851
|
-
__defProp2(target, name17, { get:
|
|
17849
|
+
var __export2 = (target, all2) => {
|
|
17850
|
+
for (var name17 in all2)
|
|
17851
|
+
__defProp2(target, name17, { get: all2[name17], enumerable: true });
|
|
17852
17852
|
};
|
|
17853
17853
|
var name14 = "AI_NoOutputSpecifiedError";
|
|
17854
17854
|
var marker15 = `vercel.ai.error.${name14}`;
|
|
@@ -19628,32 +19628,6 @@ function createUIMessageStream({
|
|
|
19628
19628
|
}
|
|
19629
19629
|
|
|
19630
19630
|
// src/index.ts
|
|
19631
|
-
function streamingFetch(input, init) {
|
|
19632
|
-
return __asyncGenerator(this, null, function* () {
|
|
19633
|
-
var _a17;
|
|
19634
|
-
const response = yield new __await(fetch(input, init));
|
|
19635
|
-
const reader = (_a17 = response == null ? void 0 : response.body) == null ? void 0 : _a17.getReader();
|
|
19636
|
-
const decoder = new TextDecoder("utf-8");
|
|
19637
|
-
if (reader) {
|
|
19638
|
-
while (true) {
|
|
19639
|
-
const { done, value } = yield new __await(reader.read());
|
|
19640
|
-
if (done) break;
|
|
19641
|
-
try {
|
|
19642
|
-
const lines = decoder.decode(value).split("\n");
|
|
19643
|
-
for (const line of lines) {
|
|
19644
|
-
if (line.trim()) {
|
|
19645
|
-
if (line) {
|
|
19646
|
-
yield line;
|
|
19647
|
-
}
|
|
19648
|
-
}
|
|
19649
|
-
}
|
|
19650
|
-
} catch (e) {
|
|
19651
|
-
console.warn(e.message);
|
|
19652
|
-
}
|
|
19653
|
-
}
|
|
19654
|
-
}
|
|
19655
|
-
});
|
|
19656
|
-
}
|
|
19657
19631
|
function iterSSE(body) {
|
|
19658
19632
|
return __asyncGenerator(this, null, function* () {
|
|
19659
19633
|
const reader = body.getReader();
|
|
@@ -19693,116 +19667,106 @@ var prepareUserTools = (toolRegistry) => Object.keys(toolRegistry).reduce(
|
|
|
19693
19667
|
},
|
|
19694
19668
|
{}
|
|
19695
19669
|
);
|
|
19696
|
-
|
|
19670
|
+
function chat({
|
|
19671
|
+
chatId,
|
|
19672
|
+
context,
|
|
19673
|
+
messages: initialMessages,
|
|
19674
|
+
config: config2,
|
|
19675
|
+
pageData,
|
|
19676
|
+
tools = {},
|
|
19697
19677
|
apiKey = getApiKey(),
|
|
19698
19678
|
host = "https://app.puckbuild.com/api"
|
|
19699
|
-
}
|
|
19679
|
+
}) {
|
|
19700
19680
|
if (!apiKey) {
|
|
19701
19681
|
throw new Error(
|
|
19702
19682
|
"No Puck API key specified. Set the PUCK_API_KEY environment variable, or provide one to createPuckApi()"
|
|
19703
19683
|
);
|
|
19704
19684
|
}
|
|
19705
|
-
|
|
19706
|
-
|
|
19707
|
-
|
|
19708
|
-
|
|
19709
|
-
|
|
19710
|
-
|
|
19711
|
-
|
|
19712
|
-
|
|
19713
|
-
|
|
19714
|
-
|
|
19715
|
-
|
|
19716
|
-
|
|
19717
|
-
|
|
19718
|
-
|
|
19719
|
-
|
|
19685
|
+
let messages = initialMessages;
|
|
19686
|
+
const stream = createUIMessageStream({
|
|
19687
|
+
execute: (_0) => __async(null, [_0], function* ({ writer }) {
|
|
19688
|
+
var _a17;
|
|
19689
|
+
const res = yield fetch(`${host}/chat`, {
|
|
19690
|
+
headers: { "x-api-key": apiKey },
|
|
19691
|
+
method: "post",
|
|
19692
|
+
body: JSON.stringify({
|
|
19693
|
+
chatId,
|
|
19694
|
+
context,
|
|
19695
|
+
messages,
|
|
19696
|
+
config: config2,
|
|
19697
|
+
pageData,
|
|
19698
|
+
tools: prepareUserTools(tools)
|
|
19699
|
+
})
|
|
19700
|
+
});
|
|
19701
|
+
if (!res.body) {
|
|
19702
|
+
throw new Error(`Puck ${res.status} (${res.statusText})`);
|
|
19703
|
+
} else if (!res.ok) {
|
|
19704
|
+
const body = yield res.json();
|
|
19705
|
+
throw new Error(
|
|
19706
|
+
`Puck ${res.status} (${res.statusText}): ${(_a17 = body.error) != null ? _a17 : "Unknown reason"}`
|
|
19707
|
+
);
|
|
19708
|
+
}
|
|
19709
|
+
try {
|
|
19710
|
+
for (var iter = __forAwait(iterSSE(res.body)), more, temp, error45; more = !(temp = yield iter.next()).done; more = false) {
|
|
19711
|
+
const chunk = temp.value;
|
|
19712
|
+
if (chunk.type === "data-user-tool") {
|
|
19713
|
+
const { toolCallId, tools: requestTools } = chunk.data;
|
|
19714
|
+
const responses = [];
|
|
19715
|
+
for (let i = 0; i < requestTools.length; i++) {
|
|
19716
|
+
const { name: name17, input } = requestTools[i];
|
|
19717
|
+
const tool2 = tools == null ? void 0 : tools[name17];
|
|
19718
|
+
if (!tool2) {
|
|
19719
|
+
throw new Error(`An unknown tool was called: ${name17}`);
|
|
19720
|
+
}
|
|
19721
|
+
if (!input) {
|
|
19722
|
+
throw new Error(
|
|
19723
|
+
`Input was not present in tool call: ${toolCallId}`
|
|
19724
|
+
);
|
|
19725
|
+
}
|
|
19726
|
+
const output = yield tool2.execute(input);
|
|
19727
|
+
responses.push({ name: name17, input, output });
|
|
19728
|
+
}
|
|
19729
|
+
const res2 = yield fetch(`${host}/chat/tool`, {
|
|
19720
19730
|
headers: { "x-api-key": apiKey },
|
|
19721
19731
|
method: "post",
|
|
19722
19732
|
body: JSON.stringify({
|
|
19723
|
-
|
|
19724
|
-
|
|
19725
|
-
messages,
|
|
19726
|
-
config: config2,
|
|
19727
|
-
pageData,
|
|
19728
|
-
tools: prepareUserTools(tools)
|
|
19733
|
+
id: toolCallId,
|
|
19734
|
+
responses
|
|
19729
19735
|
})
|
|
19730
19736
|
});
|
|
19731
|
-
if (
|
|
19732
|
-
throw new Error(
|
|
19733
|
-
} else if (!res.ok) {
|
|
19734
|
-
const body = yield res.json();
|
|
19735
|
-
throw new Error(
|
|
19736
|
-
`Puck ${res.status} (${res.statusText}): ${(_a17 = body.error) != null ? _a17 : "Unknown reason"}`
|
|
19737
|
-
);
|
|
19738
|
-
}
|
|
19739
|
-
try {
|
|
19740
|
-
for (var iter = __forAwait(iterSSE(res.body)), more, temp, error45; more = !(temp = yield iter.next()).done; more = false) {
|
|
19741
|
-
const chunk = temp.value;
|
|
19742
|
-
if (chunk.type === "data-user-tool") {
|
|
19743
|
-
const { toolCallId, tools: requestTools } = chunk.data;
|
|
19744
|
-
const responses = [];
|
|
19745
|
-
for (let i = 0; i < requestTools.length; i++) {
|
|
19746
|
-
const { name: name17, input } = requestTools[i];
|
|
19747
|
-
const tool2 = tools == null ? void 0 : tools[name17];
|
|
19748
|
-
if (!tool2) {
|
|
19749
|
-
throw new Error(`An unknown tool was called: ${name17}`);
|
|
19750
|
-
}
|
|
19751
|
-
if (!input) {
|
|
19752
|
-
throw new Error(
|
|
19753
|
-
`Input was not present in tool call: ${toolCallId}`
|
|
19754
|
-
);
|
|
19755
|
-
}
|
|
19756
|
-
const output = yield tool2.execute(input);
|
|
19757
|
-
responses.push({ name: name17, input, output });
|
|
19758
|
-
}
|
|
19759
|
-
const res2 = yield fetch(`${host}/chat/tool`, {
|
|
19760
|
-
headers: { "x-api-key": apiKey },
|
|
19761
|
-
method: "post",
|
|
19762
|
-
body: JSON.stringify({
|
|
19763
|
-
id: toolCallId,
|
|
19764
|
-
responses
|
|
19765
|
-
})
|
|
19766
|
-
});
|
|
19767
|
-
if (res2.status !== 200) {
|
|
19768
|
-
throw new Error("Tool result could not be sent to server");
|
|
19769
|
-
}
|
|
19770
|
-
} else {
|
|
19771
|
-
writer.write(chunk);
|
|
19772
|
-
}
|
|
19773
|
-
}
|
|
19774
|
-
} catch (temp) {
|
|
19775
|
-
error45 = [temp];
|
|
19776
|
-
} finally {
|
|
19777
|
-
try {
|
|
19778
|
-
more && (temp = iter.return) && (yield temp.call(iter));
|
|
19779
|
-
} finally {
|
|
19780
|
-
if (error45)
|
|
19781
|
-
throw error45[0];
|
|
19782
|
-
}
|
|
19737
|
+
if (res2.status !== 200) {
|
|
19738
|
+
throw new Error("Tool result could not be sent to server");
|
|
19783
19739
|
}
|
|
19784
|
-
}
|
|
19785
|
-
|
|
19786
|
-
|
|
19787
|
-
|
|
19788
|
-
|
|
19789
|
-
|
|
19790
|
-
|
|
19740
|
+
} else {
|
|
19741
|
+
writer.write(chunk);
|
|
19742
|
+
}
|
|
19743
|
+
}
|
|
19744
|
+
} catch (temp) {
|
|
19745
|
+
error45 = [temp];
|
|
19746
|
+
} finally {
|
|
19747
|
+
try {
|
|
19748
|
+
more && (temp = iter.return) && (yield temp.call(iter));
|
|
19749
|
+
} finally {
|
|
19750
|
+
if (error45)
|
|
19751
|
+
throw error45[0];
|
|
19752
|
+
}
|
|
19753
|
+
}
|
|
19754
|
+
})
|
|
19755
|
+
});
|
|
19756
|
+
return createUIMessageStreamResponse({ stream });
|
|
19757
|
+
}
|
|
19758
|
+
function all(path, body) {
|
|
19759
|
+
return __async(this, null, function* () {
|
|
19791
19760
|
const parts = typeof path === "string" ? path.split("/") : path;
|
|
19792
19761
|
const endpoint = parts[0];
|
|
19793
19762
|
if (endpoint === "chat") {
|
|
19794
|
-
return
|
|
19763
|
+
return chat(body);
|
|
19795
19764
|
}
|
|
19796
19765
|
throw new Error(`Invalid endpoint "${endpoint}" provided to all()`);
|
|
19797
19766
|
});
|
|
19798
|
-
|
|
19799
|
-
all,
|
|
19800
|
-
ai
|
|
19801
|
-
};
|
|
19802
|
-
};
|
|
19767
|
+
}
|
|
19803
19768
|
export {
|
|
19804
|
-
|
|
19805
|
-
|
|
19806
|
-
streamingFetch,
|
|
19769
|
+
all,
|
|
19770
|
+
chat,
|
|
19807
19771
|
tool
|
|
19808
19772
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@puckeditor/cloud-client",
|
|
3
|
-
"version": "0.1.0-canary.
|
|
3
|
+
"version": "0.1.0-canary.ff322ae0",
|
|
4
4
|
"author": "Chris Villa <chris@puckeditor.com>",
|
|
5
5
|
"repository": "puckeditor/puck",
|
|
6
6
|
"bugs": "https://github.com/puckeditor/puck/issues",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"dist"
|
|
22
22
|
],
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@measured/puck": "0.21.0-canary.
|
|
24
|
+
"@measured/puck": "0.21.0-canary.e9d5c0ea",
|
|
25
25
|
"@types/node": "^24.3.0",
|
|
26
26
|
"ai": "^5.0.29",
|
|
27
27
|
"eslint": "^7.32.0",
|