@puckeditor/cloud-client 0.1.0-canary.eeb9c902 → 0.1.0-canary.f56e596d
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 +21 -13
- package/dist/index.d.ts +21 -13
- package/dist/index.js +125 -89
- package/dist/index.mjs +123 -87
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -2,6 +2,10 @@ 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>;
|
|
5
9
|
type UserTool<INPUT extends z.ZodTypeAny = z.ZodTypeAny, OUTPUT extends z.ZodTypeAny = z.ZodTypeAny> = {
|
|
6
10
|
name?: string;
|
|
7
11
|
description: string;
|
|
@@ -14,20 +18,24 @@ type UserToolRegistry = Record<string, UserTool>;
|
|
|
14
18
|
declare const endpoints: readonly ["chat"];
|
|
15
19
|
type Endpoint = (typeof endpoints)[number];
|
|
16
20
|
type PuckCatchAll = [Endpoint | string, ...string[]];
|
|
17
|
-
type
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
type ApiParams = {
|
|
22
|
+
chat: {
|
|
23
|
+
context?: string;
|
|
24
|
+
chatId?: string;
|
|
25
|
+
messages: UIMessage[];
|
|
26
|
+
config: Config;
|
|
27
|
+
pageData: Data;
|
|
28
|
+
tools?: UserToolRegistry;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
declare const createPuckApi: ({ apiKey, host, }?: {
|
|
24
32
|
host?: string;
|
|
25
33
|
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
|
+
};
|
|
26
39
|
};
|
|
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>;
|
|
32
40
|
|
|
33
|
-
export { type ApiParams, type
|
|
41
|
+
export { type ApiParams, type Endpoint, type PuckCatchAll, createPuckApi, createPuckApi as default, streamingFetch, tool };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,10 @@ 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>;
|
|
5
9
|
type UserTool<INPUT extends z.ZodTypeAny = z.ZodTypeAny, OUTPUT extends z.ZodTypeAny = z.ZodTypeAny> = {
|
|
6
10
|
name?: string;
|
|
7
11
|
description: string;
|
|
@@ -14,20 +18,24 @@ type UserToolRegistry = Record<string, UserTool>;
|
|
|
14
18
|
declare const endpoints: readonly ["chat"];
|
|
15
19
|
type Endpoint = (typeof endpoints)[number];
|
|
16
20
|
type PuckCatchAll = [Endpoint | string, ...string[]];
|
|
17
|
-
type
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
type ApiParams = {
|
|
22
|
+
chat: {
|
|
23
|
+
context?: string;
|
|
24
|
+
chatId?: string;
|
|
25
|
+
messages: UIMessage[];
|
|
26
|
+
config: Config;
|
|
27
|
+
pageData: Data;
|
|
28
|
+
tools?: UserToolRegistry;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
declare const createPuckApi: ({ apiKey, host, }?: {
|
|
24
32
|
host?: string;
|
|
25
33
|
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
|
+
};
|
|
26
39
|
};
|
|
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>;
|
|
32
40
|
|
|
33
|
-
export { type ApiParams, type
|
|
41
|
+
export { type ApiParams, type Endpoint, type PuckCatchAll, createPuckApi, createPuckApi as default, streamingFetch, 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, all) => {
|
|
40
|
+
for (var name17 in all)
|
|
41
|
+
__defProp(target, name17, { get: all[name17], enumerable: true });
|
|
42
42
|
};
|
|
43
43
|
var __copyProps = (to, from, except, desc) => {
|
|
44
44
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
@@ -97,8 +97,9 @@ 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
|
-
|
|
100
|
+
createPuckApi: () => createPuckApi,
|
|
101
|
+
default: () => createPuckApi,
|
|
102
|
+
streamingFetch: () => streamingFetch,
|
|
102
103
|
tool: () => tool
|
|
103
104
|
});
|
|
104
105
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -17877,9 +17878,9 @@ var { btoa: btoa2, atob: atob2 } = globalThis;
|
|
|
17877
17878
|
|
|
17878
17879
|
// ../../node_modules/.pnpm/ai@5.0.44_zod@4.1.9/node_modules/ai/dist/index.mjs
|
|
17879
17880
|
var __defProp2 = Object.defineProperty;
|
|
17880
|
-
var __export2 = (target,
|
|
17881
|
-
for (var name17 in
|
|
17882
|
-
__defProp2(target, name17, { get:
|
|
17881
|
+
var __export2 = (target, all) => {
|
|
17882
|
+
for (var name17 in all)
|
|
17883
|
+
__defProp2(target, name17, { get: all[name17], enumerable: true });
|
|
17883
17884
|
};
|
|
17884
17885
|
var name14 = "AI_NoOutputSpecifiedError";
|
|
17885
17886
|
var marker15 = `vercel.ai.error.${name14}`;
|
|
@@ -19659,6 +19660,32 @@ function createUIMessageStream({
|
|
|
19659
19660
|
}
|
|
19660
19661
|
|
|
19661
19662
|
// 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
|
+
}
|
|
19662
19689
|
function iterSSE(body) {
|
|
19663
19690
|
return __asyncGenerator(this, null, function* () {
|
|
19664
19691
|
const reader = body.getReader();
|
|
@@ -19698,107 +19725,116 @@ var prepareUserTools = (toolRegistry) => Object.keys(toolRegistry).reduce(
|
|
|
19698
19725
|
},
|
|
19699
19726
|
{}
|
|
19700
19727
|
);
|
|
19701
|
-
|
|
19702
|
-
chatId,
|
|
19703
|
-
context,
|
|
19704
|
-
messages: initialMessages,
|
|
19705
|
-
config: config2,
|
|
19706
|
-
pageData,
|
|
19707
|
-
tools = {},
|
|
19728
|
+
var createPuckApi = ({
|
|
19708
19729
|
apiKey = getApiKey(),
|
|
19709
19730
|
host = "https://app.puckbuild.com/api"
|
|
19710
|
-
}) {
|
|
19731
|
+
} = {}) => {
|
|
19711
19732
|
if (!apiKey) {
|
|
19712
19733
|
throw new Error(
|
|
19713
19734
|
"No Puck API key specified. Set the PUCK_API_KEY environment variable, or provide one to createPuckApi()"
|
|
19714
19735
|
);
|
|
19715
19736
|
}
|
|
19716
|
-
|
|
19717
|
-
|
|
19718
|
-
|
|
19719
|
-
|
|
19720
|
-
|
|
19721
|
-
|
|
19722
|
-
|
|
19723
|
-
|
|
19724
|
-
|
|
19725
|
-
|
|
19726
|
-
|
|
19727
|
-
|
|
19728
|
-
|
|
19729
|
-
|
|
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`, {
|
|
19737
|
+
const ai = {
|
|
19738
|
+
chat: function(_0) {
|
|
19739
|
+
return __async(this, arguments, function* ({
|
|
19740
|
+
chatId,
|
|
19741
|
+
context,
|
|
19742
|
+
messages: initialMessages,
|
|
19743
|
+
config: config2,
|
|
19744
|
+
pageData,
|
|
19745
|
+
tools = {}
|
|
19746
|
+
}) {
|
|
19747
|
+
let messages = initialMessages;
|
|
19748
|
+
const stream = createUIMessageStream({
|
|
19749
|
+
execute: (_02) => __async(null, [_02], function* ({ writer }) {
|
|
19750
|
+
var _a17;
|
|
19751
|
+
const res = yield fetch(`${host}/chat`, {
|
|
19761
19752
|
headers: { "x-api-key": apiKey },
|
|
19762
19753
|
method: "post",
|
|
19763
19754
|
body: JSON.stringify({
|
|
19764
|
-
|
|
19765
|
-
|
|
19755
|
+
chatId,
|
|
19756
|
+
context,
|
|
19757
|
+
messages,
|
|
19758
|
+
config: config2,
|
|
19759
|
+
pageData,
|
|
19760
|
+
tools: prepareUserTools(tools)
|
|
19766
19761
|
})
|
|
19767
19762
|
});
|
|
19768
|
-
if (
|
|
19769
|
-
throw new Error(
|
|
19763
|
+
if (!res.body) {
|
|
19764
|
+
throw new Error(`Puck ${res.status} (${res.statusText})`);
|
|
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
19770
|
}
|
|
19771
|
-
|
|
19772
|
-
|
|
19773
|
-
|
|
19774
|
-
|
|
19775
|
-
|
|
19776
|
-
|
|
19777
|
-
|
|
19778
|
-
|
|
19779
|
-
|
|
19780
|
-
|
|
19781
|
-
|
|
19782
|
-
|
|
19783
|
-
|
|
19784
|
-
|
|
19785
|
-
|
|
19786
|
-
|
|
19787
|
-
|
|
19788
|
-
|
|
19789
|
-
|
|
19790
|
-
|
|
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
|
+
}
|
|
19815
|
+
}
|
|
19816
|
+
})
|
|
19817
|
+
});
|
|
19818
|
+
return createUIMessageStreamResponse({ stream });
|
|
19819
|
+
});
|
|
19820
|
+
}
|
|
19821
|
+
};
|
|
19822
|
+
const all = (path, body) => __async(null, null, function* () {
|
|
19791
19823
|
const parts = typeof path === "string" ? path.split("/") : path;
|
|
19792
19824
|
const endpoint = parts[0];
|
|
19793
19825
|
if (endpoint === "chat") {
|
|
19794
|
-
return chat(body);
|
|
19826
|
+
return ai.chat(body);
|
|
19795
19827
|
}
|
|
19796
19828
|
throw new Error(`Invalid endpoint "${endpoint}" provided to all()`);
|
|
19797
19829
|
});
|
|
19798
|
-
|
|
19830
|
+
return {
|
|
19831
|
+
all,
|
|
19832
|
+
ai
|
|
19833
|
+
};
|
|
19834
|
+
};
|
|
19799
19835
|
// Annotate the CommonJS export names for ESM import in node:
|
|
19800
19836
|
0 && (module.exports = {
|
|
19801
|
-
|
|
19802
|
-
|
|
19837
|
+
createPuckApi,
|
|
19838
|
+
streamingFetch,
|
|
19803
19839
|
tool
|
|
19804
19840
|
});
|
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, all) => {
|
|
35
|
+
for (var name17 in all)
|
|
36
|
+
__defProp(target, name17, { get: all[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, all) => {
|
|
17850
|
+
for (var name17 in all)
|
|
17851
|
+
__defProp2(target, name17, { get: all[name17], enumerable: true });
|
|
17852
17852
|
};
|
|
17853
17853
|
var name14 = "AI_NoOutputSpecifiedError";
|
|
17854
17854
|
var marker15 = `vercel.ai.error.${name14}`;
|
|
@@ -19628,6 +19628,32 @@ 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
|
+
}
|
|
19631
19657
|
function iterSSE(body) {
|
|
19632
19658
|
return __asyncGenerator(this, null, function* () {
|
|
19633
19659
|
const reader = body.getReader();
|
|
@@ -19667,106 +19693,116 @@ var prepareUserTools = (toolRegistry) => Object.keys(toolRegistry).reduce(
|
|
|
19667
19693
|
},
|
|
19668
19694
|
{}
|
|
19669
19695
|
);
|
|
19670
|
-
|
|
19671
|
-
chatId,
|
|
19672
|
-
context,
|
|
19673
|
-
messages: initialMessages,
|
|
19674
|
-
config: config2,
|
|
19675
|
-
pageData,
|
|
19676
|
-
tools = {},
|
|
19696
|
+
var createPuckApi = ({
|
|
19677
19697
|
apiKey = getApiKey(),
|
|
19678
19698
|
host = "https://app.puckbuild.com/api"
|
|
19679
|
-
}) {
|
|
19699
|
+
} = {}) => {
|
|
19680
19700
|
if (!apiKey) {
|
|
19681
19701
|
throw new Error(
|
|
19682
19702
|
"No Puck API key specified. Set the PUCK_API_KEY environment variable, or provide one to createPuckApi()"
|
|
19683
19703
|
);
|
|
19684
19704
|
}
|
|
19685
|
-
|
|
19686
|
-
|
|
19687
|
-
|
|
19688
|
-
|
|
19689
|
-
|
|
19690
|
-
|
|
19691
|
-
|
|
19692
|
-
|
|
19693
|
-
|
|
19694
|
-
|
|
19695
|
-
|
|
19696
|
-
|
|
19697
|
-
|
|
19698
|
-
|
|
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`, {
|
|
19705
|
+
const ai = {
|
|
19706
|
+
chat: function(_0) {
|
|
19707
|
+
return __async(this, arguments, function* ({
|
|
19708
|
+
chatId,
|
|
19709
|
+
context,
|
|
19710
|
+
messages: initialMessages,
|
|
19711
|
+
config: config2,
|
|
19712
|
+
pageData,
|
|
19713
|
+
tools = {}
|
|
19714
|
+
}) {
|
|
19715
|
+
let messages = initialMessages;
|
|
19716
|
+
const stream = createUIMessageStream({
|
|
19717
|
+
execute: (_02) => __async(null, [_02], function* ({ writer }) {
|
|
19718
|
+
var _a17;
|
|
19719
|
+
const res = yield fetch(`${host}/chat`, {
|
|
19730
19720
|
headers: { "x-api-key": apiKey },
|
|
19731
19721
|
method: "post",
|
|
19732
19722
|
body: JSON.stringify({
|
|
19733
|
-
|
|
19734
|
-
|
|
19723
|
+
chatId,
|
|
19724
|
+
context,
|
|
19725
|
+
messages,
|
|
19726
|
+
config: config2,
|
|
19727
|
+
pageData,
|
|
19728
|
+
tools: prepareUserTools(tools)
|
|
19735
19729
|
})
|
|
19736
19730
|
});
|
|
19737
|
-
if (
|
|
19738
|
-
throw new Error(
|
|
19731
|
+
if (!res.body) {
|
|
19732
|
+
throw new Error(`Puck ${res.status} (${res.statusText})`);
|
|
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
|
+
);
|
|
19739
19738
|
}
|
|
19740
|
-
|
|
19741
|
-
|
|
19742
|
-
|
|
19743
|
-
|
|
19744
|
-
|
|
19745
|
-
|
|
19746
|
-
|
|
19747
|
-
|
|
19748
|
-
|
|
19749
|
-
|
|
19750
|
-
|
|
19751
|
-
|
|
19752
|
-
|
|
19753
|
-
|
|
19754
|
-
|
|
19755
|
-
|
|
19756
|
-
|
|
19757
|
-
|
|
19758
|
-
|
|
19759
|
-
|
|
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
|
+
}
|
|
19783
|
+
}
|
|
19784
|
+
})
|
|
19785
|
+
});
|
|
19786
|
+
return createUIMessageStreamResponse({ stream });
|
|
19787
|
+
});
|
|
19788
|
+
}
|
|
19789
|
+
};
|
|
19790
|
+
const all = (path, body) => __async(null, null, function* () {
|
|
19760
19791
|
const parts = typeof path === "string" ? path.split("/") : path;
|
|
19761
19792
|
const endpoint = parts[0];
|
|
19762
19793
|
if (endpoint === "chat") {
|
|
19763
|
-
return chat(body);
|
|
19794
|
+
return ai.chat(body);
|
|
19764
19795
|
}
|
|
19765
19796
|
throw new Error(`Invalid endpoint "${endpoint}" provided to all()`);
|
|
19766
19797
|
});
|
|
19767
|
-
|
|
19798
|
+
return {
|
|
19799
|
+
all,
|
|
19800
|
+
ai
|
|
19801
|
+
};
|
|
19802
|
+
};
|
|
19768
19803
|
export {
|
|
19769
|
-
|
|
19770
|
-
|
|
19804
|
+
createPuckApi,
|
|
19805
|
+
createPuckApi as default,
|
|
19806
|
+
streamingFetch,
|
|
19771
19807
|
tool
|
|
19772
19808
|
};
|
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.f56e596d",
|
|
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.2e1b5267",
|
|
25
25
|
"@types/node": "^24.3.0",
|
|
26
26
|
"ai": "^5.0.29",
|
|
27
27
|
"eslint": "^7.32.0",
|