@puckeditor/cloud-client 0.1.0-canary.4e547168 → 0.1.0-canary.4f53eebc

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.
@@ -0,0 +1,41 @@
1
+ import { UIMessage } from 'ai';
2
+ import z from 'zod/v4';
3
+ import { Config, Data } from '@measured/puck';
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
+ type UserTool<INPUT extends z.ZodTypeAny = z.ZodTypeAny, OUTPUT extends z.ZodTypeAny = z.ZodTypeAny> = {
10
+ name?: string;
11
+ description: string;
12
+ inputSchema: INPUT;
13
+ outputSchema?: OUTPUT;
14
+ execute: (input: z.infer<INPUT>) => Promise<z.infer<OUTPUT>> | z.infer<OUTPUT>;
15
+ };
16
+ declare const tool: <INPUT extends z.ZodTypeAny, OUTPUT extends z.ZodTypeAny>(t: UserTool<INPUT, OUTPUT>) => UserTool<INPUT, OUTPUT>;
17
+ type UserToolRegistry = Record<string, UserTool>;
18
+ declare const endpoints: readonly ["chat"];
19
+ type Endpoint = (typeof endpoints)[number];
20
+ type PuckCatchAll = [Endpoint | string, ...string[]];
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, }?: {
32
+ host?: string;
33
+ apiKey?: string;
34
+ }) => {
35
+ all: <ThisEndpoint extends Endpoint | string>(path: [ThisEndpoint | 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
+ };
40
+
41
+ export { type ApiParams, type Endpoint, type PuckCatchAll, createPuckApi, createPuckApi as default, streamingFetch, tool };
@@ -0,0 +1,41 @@
1
+ import { UIMessage } from 'ai';
2
+ import z from 'zod/v4';
3
+ import { Config, Data } from '@measured/puck';
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
+ type UserTool<INPUT extends z.ZodTypeAny = z.ZodTypeAny, OUTPUT extends z.ZodTypeAny = z.ZodTypeAny> = {
10
+ name?: string;
11
+ description: string;
12
+ inputSchema: INPUT;
13
+ outputSchema?: OUTPUT;
14
+ execute: (input: z.infer<INPUT>) => Promise<z.infer<OUTPUT>> | z.infer<OUTPUT>;
15
+ };
16
+ declare const tool: <INPUT extends z.ZodTypeAny, OUTPUT extends z.ZodTypeAny>(t: UserTool<INPUT, OUTPUT>) => UserTool<INPUT, OUTPUT>;
17
+ type UserToolRegistry = Record<string, UserTool>;
18
+ declare const endpoints: readonly ["chat"];
19
+ type Endpoint = (typeof endpoints)[number];
20
+ type PuckCatchAll = [Endpoint | string, ...string[]];
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, }?: {
32
+ host?: string;
33
+ apiKey?: string;
34
+ }) => {
35
+ all: <ThisEndpoint extends Endpoint | string>(path: [ThisEndpoint | 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
+ };
40
+
41
+ export { type ApiParams, type Endpoint, type PuckCatchAll, createPuckApi, createPuckApi as default, streamingFetch, tool };
package/dist/index.js ADDED
@@ -0,0 +1,270 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __getProtoOf = Object.getPrototypeOf;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
+ var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
13
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
14
+ var __spreadValues = (a, b) => {
15
+ for (var prop in b || (b = {}))
16
+ if (__hasOwnProp.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ if (__getOwnPropSymbols)
19
+ for (var prop of __getOwnPropSymbols(b)) {
20
+ if (__propIsEnum.call(b, prop))
21
+ __defNormalProp(a, prop, b[prop]);
22
+ }
23
+ return a;
24
+ };
25
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
26
+ var __export = (target, all) => {
27
+ for (var name in all)
28
+ __defProp(target, name, { get: all[name], enumerable: true });
29
+ };
30
+ var __copyProps = (to, from, except, desc) => {
31
+ if (from && typeof from === "object" || typeof from === "function") {
32
+ for (let key of __getOwnPropNames(from))
33
+ if (!__hasOwnProp.call(to, key) && key !== except)
34
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
35
+ }
36
+ return to;
37
+ };
38
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
39
+ // If the importer is in node compatibility mode or this is not an ESM
40
+ // file that has been converted to a CommonJS file using a Babel-
41
+ // compatible transform (i.e. "__esModule" has not been set), then set
42
+ // "default" to the CommonJS "module.exports" for node compatibility.
43
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
44
+ mod
45
+ ));
46
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
47
+ var __async = (__this, __arguments, generator) => {
48
+ return new Promise((resolve, reject) => {
49
+ var fulfilled = (value) => {
50
+ try {
51
+ step(generator.next(value));
52
+ } catch (e) {
53
+ reject(e);
54
+ }
55
+ };
56
+ var rejected = (value) => {
57
+ try {
58
+ step(generator.throw(value));
59
+ } catch (e) {
60
+ reject(e);
61
+ }
62
+ };
63
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
64
+ step((generator = generator.apply(__this, __arguments)).next());
65
+ });
66
+ };
67
+ var __await = function(promise, isYieldStar) {
68
+ this[0] = promise;
69
+ this[1] = isYieldStar;
70
+ };
71
+ var __asyncGenerator = (__this, __arguments, generator) => {
72
+ var resume = (k, v, yes, no) => {
73
+ try {
74
+ var x = generator[k](v), isAwait = (v = x.value) instanceof __await, done = x.done;
75
+ Promise.resolve(isAwait ? v[0] : v).then((y) => isAwait ? resume(k === "return" ? k : "next", v[1] ? { done: y.done, value: y.value } : y, yes, no) : yes({ value: y, done })).catch((e) => resume("throw", e, yes, no));
76
+ } catch (e) {
77
+ no(e);
78
+ }
79
+ }, method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no)), it = {};
80
+ return generator = generator.apply(__this, __arguments), it[__knownSymbol("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
81
+ };
82
+ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")]) ? it.call(obj) : (obj = obj[__knownSymbol("iterator")](), it = {}, method = (key, fn) => (fn = obj[key]) && (it[key] = (arg) => new Promise((yes, no, done) => (arg = fn.call(obj, arg), done = arg.done, Promise.resolve(arg.value).then((value) => yes({ value, done }), no)))), method("next"), method("return"), it);
83
+
84
+ // index.ts
85
+ var index_exports = {};
86
+ __export(index_exports, {
87
+ createPuckApi: () => createPuckApi,
88
+ default: () => createPuckApi,
89
+ streamingFetch: () => streamingFetch,
90
+ tool: () => tool
91
+ });
92
+ module.exports = __toCommonJS(index_exports);
93
+
94
+ // ../tsup-config/react-import.js
95
+ var import_react = __toESM(require("react"));
96
+
97
+ // src/index.ts
98
+ var import_ai = require("ai");
99
+ var import_v4 = __toESM(require("zod/v4"));
100
+ function streamingFetch(input, init) {
101
+ return __asyncGenerator(this, null, function* () {
102
+ var _a;
103
+ const response = yield new __await(fetch(input, init));
104
+ const reader = (_a = response == null ? void 0 : response.body) == null ? void 0 : _a.getReader();
105
+ const decoder = new TextDecoder("utf-8");
106
+ if (reader) {
107
+ while (true) {
108
+ const { done, value } = yield new __await(reader.read());
109
+ if (done) break;
110
+ try {
111
+ const lines = decoder.decode(value).split("\n");
112
+ for (const line of lines) {
113
+ if (line.trim()) {
114
+ if (line) {
115
+ yield line;
116
+ }
117
+ }
118
+ }
119
+ } catch (e) {
120
+ console.warn(e.message);
121
+ }
122
+ }
123
+ }
124
+ });
125
+ }
126
+ function iterSSE(body) {
127
+ return __asyncGenerator(this, null, function* () {
128
+ const reader = body.getReader();
129
+ const dec = new TextDecoder();
130
+ let buf = "";
131
+ while (true) {
132
+ const { done, value } = yield new __await(reader.read());
133
+ if (done) break;
134
+ buf += dec.decode(value, { stream: true });
135
+ let idx;
136
+ while ((idx = buf.indexOf("\n\n")) >= 0) {
137
+ const chunk = buf.slice(0, idx).trim();
138
+ buf = buf.slice(idx + 2);
139
+ if (!chunk) continue;
140
+ const line = chunk.startsWith("data: ") ? chunk.slice(6) : chunk;
141
+ try {
142
+ yield JSON.parse(line);
143
+ } catch (e) {
144
+ }
145
+ }
146
+ }
147
+ });
148
+ }
149
+ var getApiKey = () => process.env.PUCK_API_KEY;
150
+ var tool = (t) => t;
151
+ var prepareUserTools = (toolRegistry) => Object.keys(toolRegistry).reduce(
152
+ (acc, key) => {
153
+ var _a;
154
+ return __spreadProps(__spreadValues({}, acc), {
155
+ [key]: {
156
+ name: (_a = toolRegistry[key].name) != null ? _a : key,
157
+ description: toolRegistry[key].description,
158
+ inputSchema: import_v4.default.toJSONSchema(toolRegistry[key].inputSchema),
159
+ outputSchema: toolRegistry[key].outputSchema ? import_v4.default.toJSONSchema(toolRegistry[key].outputSchema) : null
160
+ }
161
+ });
162
+ },
163
+ {}
164
+ );
165
+ var createPuckApi = ({
166
+ apiKey = getApiKey(),
167
+ host = "https://app.puckbuild.com/api"
168
+ } = {}) => {
169
+ if (!apiKey) {
170
+ throw new Error(
171
+ "No Puck API key specified. Set the PUCK_API_KEY environment variable, or provide one to createPuckApi()"
172
+ );
173
+ }
174
+ const ai = {
175
+ chat: function(_0) {
176
+ return __async(this, arguments, function* ({
177
+ chatId,
178
+ context,
179
+ messages: initialMessages,
180
+ config,
181
+ pageData,
182
+ tools = {}
183
+ }) {
184
+ let messages = initialMessages;
185
+ const stream = (0, import_ai.createUIMessageStream)({
186
+ execute: (_02) => __async(null, [_02], function* ({ writer }) {
187
+ const res = yield fetch(`${host}/chat`, {
188
+ headers: { "x-api-key": apiKey },
189
+ method: "post",
190
+ body: JSON.stringify({
191
+ chatId,
192
+ context,
193
+ messages,
194
+ config,
195
+ pageData,
196
+ tools: prepareUserTools(tools)
197
+ })
198
+ });
199
+ if (!res.ok || !res.body) {
200
+ throw new Error(`Puck ${res.status}`);
201
+ }
202
+ try {
203
+ for (var iter = __forAwait(iterSSE(res.body)), more, temp, error; more = !(temp = yield iter.next()).done; more = false) {
204
+ const chunk = temp.value;
205
+ if (chunk.type === "data-user-tool") {
206
+ const { toolCallId, tools: requestTools } = chunk.data;
207
+ const responses = [];
208
+ for (let i = 0; i < requestTools.length; i++) {
209
+ const { name, input } = requestTools[i];
210
+ const tool2 = tools == null ? void 0 : tools[name];
211
+ if (!tool2) {
212
+ throw new Error(`An unknown tool was called: ${name}`);
213
+ }
214
+ if (!input) {
215
+ throw new Error(
216
+ `Input was not present in tool call: ${toolCallId}`
217
+ );
218
+ }
219
+ const output = yield tool2.execute(input);
220
+ responses.push({ name, input, output });
221
+ }
222
+ const res2 = yield fetch(`${host}/chat/tool`, {
223
+ headers: { "x-api-key": apiKey },
224
+ method: "post",
225
+ body: JSON.stringify({
226
+ id: toolCallId,
227
+ responses
228
+ })
229
+ });
230
+ if (res2.status !== 200) {
231
+ throw new Error("Tool result could not be sent to server");
232
+ }
233
+ } else {
234
+ writer.write(chunk);
235
+ }
236
+ }
237
+ } catch (temp) {
238
+ error = [temp];
239
+ } finally {
240
+ try {
241
+ more && (temp = iter.return) && (yield temp.call(iter));
242
+ } finally {
243
+ if (error)
244
+ throw error[0];
245
+ }
246
+ }
247
+ })
248
+ });
249
+ return (0, import_ai.createUIMessageStreamResponse)({ stream });
250
+ });
251
+ }
252
+ };
253
+ const all = (path, body) => __async(null, null, function* () {
254
+ const endpoint = path[0];
255
+ if (endpoint === "chat") {
256
+ return ai.chat(body);
257
+ }
258
+ throw new Error(`Invalid endpoint "${endpoint}" provided to all()`);
259
+ });
260
+ return {
261
+ all,
262
+ ai
263
+ };
264
+ };
265
+ // Annotate the CommonJS export names for ESM import in node:
266
+ 0 && (module.exports = {
267
+ createPuckApi,
268
+ streamingFetch,
269
+ tool
270
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,237 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __spreadValues = (a, b) => {
10
+ for (var prop in b || (b = {}))
11
+ if (__hasOwnProp.call(b, prop))
12
+ __defNormalProp(a, prop, b[prop]);
13
+ if (__getOwnPropSymbols)
14
+ for (var prop of __getOwnPropSymbols(b)) {
15
+ if (__propIsEnum.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ }
18
+ return a;
19
+ };
20
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
+ var __async = (__this, __arguments, generator) => {
22
+ return new Promise((resolve, reject) => {
23
+ var fulfilled = (value) => {
24
+ try {
25
+ step(generator.next(value));
26
+ } catch (e) {
27
+ reject(e);
28
+ }
29
+ };
30
+ var rejected = (value) => {
31
+ try {
32
+ step(generator.throw(value));
33
+ } catch (e) {
34
+ reject(e);
35
+ }
36
+ };
37
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
38
+ step((generator = generator.apply(__this, __arguments)).next());
39
+ });
40
+ };
41
+ var __await = function(promise, isYieldStar) {
42
+ this[0] = promise;
43
+ this[1] = isYieldStar;
44
+ };
45
+ var __asyncGenerator = (__this, __arguments, generator) => {
46
+ var resume = (k, v, yes, no) => {
47
+ try {
48
+ var x = generator[k](v), isAwait = (v = x.value) instanceof __await, done = x.done;
49
+ Promise.resolve(isAwait ? v[0] : v).then((y) => isAwait ? resume(k === "return" ? k : "next", v[1] ? { done: y.done, value: y.value } : y, yes, no) : yes({ value: y, done })).catch((e) => resume("throw", e, yes, no));
50
+ } catch (e) {
51
+ no(e);
52
+ }
53
+ }, method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no)), it = {};
54
+ return generator = generator.apply(__this, __arguments), it[__knownSymbol("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
55
+ };
56
+ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")]) ? it.call(obj) : (obj = obj[__knownSymbol("iterator")](), it = {}, method = (key, fn) => (fn = obj[key]) && (it[key] = (arg) => new Promise((yes, no, done) => (arg = fn.call(obj, arg), done = arg.done, Promise.resolve(arg.value).then((value) => yes({ value, done }), no)))), method("next"), method("return"), it);
57
+
58
+ // ../tsup-config/react-import.js
59
+ import React from "react";
60
+
61
+ // src/index.ts
62
+ import {
63
+ createUIMessageStream,
64
+ createUIMessageStreamResponse
65
+ } from "ai";
66
+ import z from "zod/v4";
67
+ function streamingFetch(input, init) {
68
+ return __asyncGenerator(this, null, function* () {
69
+ var _a;
70
+ const response = yield new __await(fetch(input, init));
71
+ const reader = (_a = response == null ? void 0 : response.body) == null ? void 0 : _a.getReader();
72
+ const decoder = new TextDecoder("utf-8");
73
+ if (reader) {
74
+ while (true) {
75
+ const { done, value } = yield new __await(reader.read());
76
+ if (done) break;
77
+ try {
78
+ const lines = decoder.decode(value).split("\n");
79
+ for (const line of lines) {
80
+ if (line.trim()) {
81
+ if (line) {
82
+ yield line;
83
+ }
84
+ }
85
+ }
86
+ } catch (e) {
87
+ console.warn(e.message);
88
+ }
89
+ }
90
+ }
91
+ });
92
+ }
93
+ function iterSSE(body) {
94
+ return __asyncGenerator(this, null, function* () {
95
+ const reader = body.getReader();
96
+ const dec = new TextDecoder();
97
+ let buf = "";
98
+ while (true) {
99
+ const { done, value } = yield new __await(reader.read());
100
+ if (done) break;
101
+ buf += dec.decode(value, { stream: true });
102
+ let idx;
103
+ while ((idx = buf.indexOf("\n\n")) >= 0) {
104
+ const chunk = buf.slice(0, idx).trim();
105
+ buf = buf.slice(idx + 2);
106
+ if (!chunk) continue;
107
+ const line = chunk.startsWith("data: ") ? chunk.slice(6) : chunk;
108
+ try {
109
+ yield JSON.parse(line);
110
+ } catch (e) {
111
+ }
112
+ }
113
+ }
114
+ });
115
+ }
116
+ var getApiKey = () => process.env.PUCK_API_KEY;
117
+ var tool = (t) => t;
118
+ var prepareUserTools = (toolRegistry) => Object.keys(toolRegistry).reduce(
119
+ (acc, key) => {
120
+ var _a;
121
+ return __spreadProps(__spreadValues({}, acc), {
122
+ [key]: {
123
+ name: (_a = toolRegistry[key].name) != null ? _a : key,
124
+ description: toolRegistry[key].description,
125
+ inputSchema: z.toJSONSchema(toolRegistry[key].inputSchema),
126
+ outputSchema: toolRegistry[key].outputSchema ? z.toJSONSchema(toolRegistry[key].outputSchema) : null
127
+ }
128
+ });
129
+ },
130
+ {}
131
+ );
132
+ var createPuckApi = ({
133
+ apiKey = getApiKey(),
134
+ host = "https://app.puckbuild.com/api"
135
+ } = {}) => {
136
+ if (!apiKey) {
137
+ throw new Error(
138
+ "No Puck API key specified. Set the PUCK_API_KEY environment variable, or provide one to createPuckApi()"
139
+ );
140
+ }
141
+ const ai = {
142
+ chat: function(_0) {
143
+ return __async(this, arguments, function* ({
144
+ chatId,
145
+ context,
146
+ messages: initialMessages,
147
+ config,
148
+ pageData,
149
+ tools = {}
150
+ }) {
151
+ let messages = initialMessages;
152
+ const stream = createUIMessageStream({
153
+ execute: (_02) => __async(null, [_02], function* ({ writer }) {
154
+ const res = yield fetch(`${host}/chat`, {
155
+ headers: { "x-api-key": apiKey },
156
+ method: "post",
157
+ body: JSON.stringify({
158
+ chatId,
159
+ context,
160
+ messages,
161
+ config,
162
+ pageData,
163
+ tools: prepareUserTools(tools)
164
+ })
165
+ });
166
+ if (!res.ok || !res.body) {
167
+ throw new Error(`Puck ${res.status}`);
168
+ }
169
+ try {
170
+ for (var iter = __forAwait(iterSSE(res.body)), more, temp, error; more = !(temp = yield iter.next()).done; more = false) {
171
+ const chunk = temp.value;
172
+ if (chunk.type === "data-user-tool") {
173
+ const { toolCallId, tools: requestTools } = chunk.data;
174
+ const responses = [];
175
+ for (let i = 0; i < requestTools.length; i++) {
176
+ const { name, input } = requestTools[i];
177
+ const tool2 = tools == null ? void 0 : tools[name];
178
+ if (!tool2) {
179
+ throw new Error(`An unknown tool was called: ${name}`);
180
+ }
181
+ if (!input) {
182
+ throw new Error(
183
+ `Input was not present in tool call: ${toolCallId}`
184
+ );
185
+ }
186
+ const output = yield tool2.execute(input);
187
+ responses.push({ name, input, output });
188
+ }
189
+ const res2 = yield fetch(`${host}/chat/tool`, {
190
+ headers: { "x-api-key": apiKey },
191
+ method: "post",
192
+ body: JSON.stringify({
193
+ id: toolCallId,
194
+ responses
195
+ })
196
+ });
197
+ if (res2.status !== 200) {
198
+ throw new Error("Tool result could not be sent to server");
199
+ }
200
+ } else {
201
+ writer.write(chunk);
202
+ }
203
+ }
204
+ } catch (temp) {
205
+ error = [temp];
206
+ } finally {
207
+ try {
208
+ more && (temp = iter.return) && (yield temp.call(iter));
209
+ } finally {
210
+ if (error)
211
+ throw error[0];
212
+ }
213
+ }
214
+ })
215
+ });
216
+ return createUIMessageStreamResponse({ stream });
217
+ });
218
+ }
219
+ };
220
+ const all = (path, body) => __async(null, null, function* () {
221
+ const endpoint = path[0];
222
+ if (endpoint === "chat") {
223
+ return ai.chat(body);
224
+ }
225
+ throw new Error(`Invalid endpoint "${endpoint}" provided to all()`);
226
+ });
227
+ return {
228
+ all,
229
+ ai
230
+ };
231
+ };
232
+ export {
233
+ createPuckApi,
234
+ createPuckApi as default,
235
+ streamingFetch,
236
+ tool
237
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@puckeditor/cloud-client",
3
- "version": "0.1.0-canary.4e547168",
3
+ "version": "0.1.0-canary.4f53eebc",
4
4
  "author": "Chris Villa <chris@puckeditor.com>",
5
5
  "repository": "puckeditor/puck",
6
6
  "bugs": "https://github.com/puckeditor/puck/issues",