@base44-preview/platform 0.5.0-pr.354.eeb83f0 → 0.6.0-pr.356.0052aed

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.
@@ -34,12 +34,14 @@ export interface ToolCallAnswer {
34
34
  * `X-Request-ID` built from the tool call ID, so a retry resumes the turn only once.
35
35
  *
36
36
  * Base44 keeps the Send chat message and Submit tool-call input requests open until the AI
37
- * finishes the turn, which can take minutes. Forward the request and return its result: the hook
38
- * learns from the live updates as soon as Base44 has the prompt or the answer, and a failure after
39
- * that, such as a timeout on your server, doesn't set an error. A rejected promise from any call
40
- * before then sets [`error`](#error). Next.js server actions run one at a time, so one that waits
41
- * out the turn holds up every later call: resolve it once Base44 hasn't refused the request
42
- * within a few seconds. Base44 refuses at once.
37
+ * finishes the turn, which can take minutes. Forward each request and return its result. The hook
38
+ * learns from the live updates as soon as Base44 has the prompt or the answer, so a failure after
39
+ * that, such as a timeout on your server, doesn't set an error. A rejected promise before then sets
40
+ * [`error`](#error).
41
+ *
42
+ * Next.js server actions run one at a time, so one that waits out the turn holds up every later
43
+ * call. In a server action, wait a few seconds for a refusal instead, and resolve if none comes.
44
+ * Base44 refuses a request right away.
43
45
  *
44
46
  * @example
45
47
  * ```typescript
@@ -116,6 +118,54 @@ export interface ChatBackend {
116
118
  * @param appId - ID of the app.
117
119
  * @param content - The prompt.
118
120
  * @returns Promise resolving when Base44 answers the request, which can be when the turn ends.
121
+ *
122
+ * @example
123
+ * ```typescript
124
+ * // Your route handler for sendMessage(), forwarding the request
125
+ * export async function POST(request: Request) {
126
+ * const { appId, content } = await request.json();
127
+ * // Check that the signed-in user may use this app before you forward anything
128
+ * const response = await fetch(`https://app.base44.com/api/apps/${appId}/chat/message`, {
129
+ * method: "POST",
130
+ * headers: {
131
+ * Authorization: `Bearer ${process.env.BASE44_ACCESS_TOKEN}`,
132
+ * "Content-Type": "application/json",
133
+ * "X-Request-ID": crypto.randomUUID(),
134
+ * },
135
+ * body: JSON.stringify({ content }),
136
+ * });
137
+ * return new Response(response.body, { status: response.status });
138
+ * }
139
+ * ```
140
+ * ```typescript
141
+ * // Your server action for sendMessage(), waiting a few seconds for a refusal
142
+ * "use server";
143
+ *
144
+ * export async function sendMessage(appId: string, content: string) {
145
+ * const sent = fetch(`https://app.base44.com/api/apps/${appId}/chat/message`, {
146
+ * method: "POST",
147
+ * headers: {
148
+ * Authorization: `Bearer ${process.env.BASE44_ACCESS_TOKEN}`,
149
+ * "Content-Type": "application/json",
150
+ * "X-Request-ID": crypto.randomUUID(),
151
+ * },
152
+ * body: JSON.stringify({ content }),
153
+ * });
154
+ * const timeout = new Promise<null>((resolve) => setTimeout(resolve, 3000, null));
155
+ * const response = await Promise.race([sent, timeout]);
156
+ * if (response === null) {
157
+ * // The caller has moved on, so a later failure can only be logged
158
+ * sent.then(
159
+ * (late) => {
160
+ * if (!late.ok) console.error(`Send chat message failed: ${late.status}`);
161
+ * },
162
+ * (error) => console.error("Send chat message failed", error),
163
+ * );
164
+ * return;
165
+ * }
166
+ * if (!response.ok) throw new Error(`Send chat message failed: ${response.status}`);
167
+ * }
168
+ * ```
119
169
  */
120
170
  sendMessage(appId: string, content: string): Promise<void>;
121
171
  /**
@@ -125,6 +175,30 @@ export interface ChatBackend {
125
175
  * @param appId - ID of the app.
126
176
  * @param answer - The tool call and the answer to it.
127
177
  * @returns Promise resolving when Base44 answers the request, which can be when the turn ends.
178
+ *
179
+ * @example
180
+ * ```typescript
181
+ * // Your route handler for submitToolCallInput(), forwarding the answer
182
+ * export async function POST(request: Request) {
183
+ * const { appId, answer } = await request.json();
184
+ * // Check that the signed-in user may use this app before you forward anything
185
+ * const response = await fetch(`https://app.base44.com/api/apps/${appId}/chat/submit-tool-call-input`, {
186
+ * method: "POST",
187
+ * headers: {
188
+ * Authorization: `Bearer ${process.env.BASE44_ACCESS_TOKEN}`,
189
+ * "Content-Type": "application/json",
190
+ * "X-Request-ID": `submit-${answer.toolCallId}`,
191
+ * },
192
+ * body: JSON.stringify({
193
+ * tool_call_id: answer.toolCallId,
194
+ * action: answer.approve ? "approved" : "rejected",
195
+ * // A choice's answers or a secrets request's values, and nothing for an approval or a decline
196
+ * extra_user_input: answer.extraUserInput,
197
+ * }),
198
+ * });
199
+ * return new Response(response.body, { status: response.status });
200
+ * }
201
+ * ```
128
202
  */
129
203
  submitToolCallInput(appId: string, answer: ToolCallAnswer): Promise<void>;
130
204
  }
@@ -194,8 +268,9 @@ export interface ChatAnswer {
194
268
  *
195
269
  * Each kind has only the actions that fit it, and every kind can be declined. Calling an action
196
270
  * closes the question right away and sends the answer through your
197
- * [`submitToolCallInput()`](#submittoolcallinput). The actions never throw. A failure sets
198
- * [`error`](#error), and the question opens again.
271
+ * [`submitToolCallInput()`](#submittoolcallinput). The actions never throw. If Base44 refuses an
272
+ * answer, or your backend fails before Base44 has it, [`error`](#error) is set and the question
273
+ * opens again.
199
274
  *
200
275
  * The hook declines a question kind this release doesn't know, once per tool call, when Base44
201
276
  * names that kind on the last assistant message. If the decline fails, [`error`](#error) says
@@ -450,7 +525,8 @@ export interface ChatOptions {
450
525
  *
451
526
  * @groupDescription Methods
452
527
  * Functions on the same object, which you call to act on the chat, as in `chat.send(prompt)`. They
453
- * never throw. A failure sets [`error`](#error).
528
+ * never throw. If Base44 refuses the request, or your backend fails before Base44 has the prompt or
529
+ * answer, [`error`](#error) is set.
454
530
  */
455
531
  export interface UseChatResult {
456
532
  /** The conversation, oldest first. Each open question appears with the step that asked it. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/platform",
3
- "version": "0.5.0-pr.354.eeb83f0",
3
+ "version": "0.6.0-pr.356.0052aed",
4
4
  "description": "Base44 Platform SDK for white-label platforms: a browser client for following the AI chat and a server entrypoint for webhooks",
5
5
  "main": "dist/client/index.js",
6
6
  "types": "dist/client/index.d.ts",