@lotics/app-sdk 0.131.6 → 0.131.8
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/agent_stream.d.ts +3 -11
- package/dist/hooks.d.ts +3 -1
- package/dist/index.js +51 -31
- package/dist/shared_types.d.ts +1 -0
- package/docs/ai.md +1 -1
- package/docs/workflows.md +2 -0
- package/package.json +1 -1
package/dist/agent_stream.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* before `finish`); until it arrives, `submit_result`'s input — never a part.
|
|
7
7
|
*/
|
|
8
8
|
import type { UIMessagePart, UIDataTypes, UITools } from "ai";
|
|
9
|
+
import type { AgentRunRecord } from "./hooks.js";
|
|
9
10
|
/** An ai-sdk message part — the render model, tool-set-agnostic. */
|
|
10
11
|
export type AgentUIPart = UIMessagePart<UIDataTypes, UITools>;
|
|
11
12
|
/** Mirrors the server's `INTERACTIVE_APP_TOOLS`; a call parks the run as `awaiting_input`. */
|
|
@@ -17,17 +18,8 @@ export interface AgentRunState {
|
|
|
17
18
|
output?: unknown;
|
|
18
19
|
error?: string;
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
output?: unknown;
|
|
23
|
-
error_message?: string | null;
|
|
24
|
-
/** On an `awaiting_input` row: rebuilds the ask for a client that lost the stream. */
|
|
25
|
-
pending_interactive?: {
|
|
26
|
-
tool_call_id: string;
|
|
27
|
-
tool_name: string;
|
|
28
|
-
input: unknown;
|
|
29
|
-
} | null;
|
|
30
|
-
}
|
|
21
|
+
/** The part of a polled row the stream's state adopts. */
|
|
22
|
+
export type SettledAgentRun = Pick<AgentRunRecord, "status"> & Partial<Pick<AgentRunRecord, "output" | "error_message" | "pending_interactive">>;
|
|
31
23
|
/**
|
|
32
24
|
* Fold a polled row into the stream's state, for a dropped or truncated stream.
|
|
33
25
|
* The row owns status and structured output; a free-text row's string output
|
package/dist/hooks.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { type AiContextValue } from "./rpc.js";
|
|
|
4
4
|
import { type AgentUIPart, type PendingChoice, type AgentRunLanding } from "./agent_stream.js";
|
|
5
5
|
import type { AppWorkflows, AppWorkflowResults, AppAgents, AppAgentResults } from "./types.js";
|
|
6
6
|
import type { PhotoPlace, ResolvedMember } from "./shared_types.js";
|
|
7
|
+
import type { AppAgentRunStatus } from "./shared_types.js";
|
|
7
8
|
export type { AgentRunState, AgentUIPart, PendingChoice, ChoiceQuestion, ChoiceOption, AskUserChoiceOutput, AgentRunLanding } from "./agent_stream.js";
|
|
8
9
|
export { buildChoiceOutput } from "./agent_stream.js";
|
|
9
10
|
/**
|
|
@@ -214,7 +215,8 @@ export interface AgentRunRecord {
|
|
|
214
215
|
id: string;
|
|
215
216
|
agent_alias: string;
|
|
216
217
|
session_id: string;
|
|
217
|
-
|
|
218
|
+
/** `running` until the run ends; `awaiting_input` while it waits on an answer; `error` carries `error_message`; `aborted` (cancelled) leaves it null. */
|
|
219
|
+
status: AppAgentRunStatus;
|
|
218
220
|
input: Record<string, unknown> | null;
|
|
219
221
|
output: unknown;
|
|
220
222
|
error_message: string | null;
|
package/dist/index.js
CHANGED
|
@@ -295,27 +295,38 @@ function useAttachmentQueue(upload, options) {
|
|
|
295
295
|
var INTERACTIVE_TOOLS = /* @__PURE__ */ new Set(["ask_user_choice"]);
|
|
296
296
|
var SUBMIT_TOOL = "submit_result";
|
|
297
297
|
function adoptSettledRun(state, settled) {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
return
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
298
|
+
switch (settled.status) {
|
|
299
|
+
case "running":
|
|
300
|
+
return state;
|
|
301
|
+
case "completed": {
|
|
302
|
+
const structured = settled.output !== null && typeof settled.output === "object" ? settled.output : void 0;
|
|
303
|
+
return { ...state, status: "completed", output: structured ?? state.output };
|
|
304
|
+
}
|
|
305
|
+
// A parked row is resumable; rebuild the ask part if the stream never delivered it.
|
|
306
|
+
case "awaiting_input": {
|
|
307
|
+
const next = { ...state, status: "awaiting_input" };
|
|
308
|
+
if (pendingInteractiveCall(next)) return next;
|
|
309
|
+
const p = settled.pending_interactive;
|
|
310
|
+
const alreadyPresent = p && state.parts.some((part) => part.type === "dynamic-tool" && part.toolCallId === p.tool_call_id);
|
|
311
|
+
if (p && INTERACTIVE_TOOLS.has(p.tool_name) && !alreadyPresent) {
|
|
312
|
+
return {
|
|
313
|
+
...next,
|
|
314
|
+
parts: [
|
|
315
|
+
...state.parts,
|
|
316
|
+
{ type: "dynamic-tool", toolName: p.tool_name, toolCallId: p.tool_call_id, state: "input-available", input: p.input }
|
|
317
|
+
]
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
return next;
|
|
321
|
+
}
|
|
322
|
+
case "error":
|
|
323
|
+
case "aborted":
|
|
324
|
+
return { ...state, status: "error", error: settled.error_message ?? "The run was stopped." };
|
|
325
|
+
default: {
|
|
326
|
+
const unknown = settled.status;
|
|
327
|
+
return { ...state, status: "error", error: `The run ended in a state this version of the app does not know: ${String(unknown)}.` };
|
|
315
328
|
}
|
|
316
|
-
return next;
|
|
317
329
|
}
|
|
318
|
-
return { ...state, status: "error", error: settled.error_message ?? "The run was stopped." };
|
|
319
330
|
}
|
|
320
331
|
function decodeJson(raw) {
|
|
321
332
|
try {
|
|
@@ -9904,16 +9915,22 @@ function assertLinkId(item, via) {
|
|
|
9904
9915
|
}
|
|
9905
9916
|
return item;
|
|
9906
9917
|
}
|
|
9907
|
-
async function
|
|
9908
|
-
|
|
9909
|
-
|
|
9918
|
+
async function fetchRecordsData(recordIds, ctx) {
|
|
9919
|
+
const missing = [...new Set(recordIds.filter((id) => !ctx.record_cache.has(id)))];
|
|
9920
|
+
if (missing.length > 0) {
|
|
9921
|
+
const fetched = await ctx.fetch_record(missing);
|
|
9922
|
+
for (const id of missing) {
|
|
9923
|
+
const row2 = fetched.get(id) ?? null;
|
|
9924
|
+
ctx.record_cache.set(id, row2 === null ? null : { id: row2.id, ...row2.data, table_id: row2.table_id });
|
|
9925
|
+
}
|
|
9910
9926
|
}
|
|
9911
|
-
|
|
9912
|
-
|
|
9913
|
-
|
|
9914
|
-
return
|
|
9927
|
+
return new Map(recordIds.map((id) => [id, ctx.record_cache.get(id) ?? null]));
|
|
9928
|
+
}
|
|
9929
|
+
async function fetchRecordData(recordId, ctx) {
|
|
9930
|
+
return (await fetchRecordsData([recordId], ctx)).get(recordId) ?? null;
|
|
9915
9931
|
}
|
|
9916
9932
|
var LINK_FETCH_CONCURRENCY = 20;
|
|
9933
|
+
var LINK_FETCH_BATCH = 200;
|
|
9917
9934
|
var MAX_LINK_FAN_OUT = 1e4;
|
|
9918
9935
|
async function fetchRecordsBounded(ids, reading, ctx) {
|
|
9919
9936
|
if (ids.length > MAX_LINK_FAN_OUT) {
|
|
@@ -9923,10 +9940,11 @@ async function fetchRecordsBounded(ids, reading, ctx) {
|
|
|
9923
9940
|
);
|
|
9924
9941
|
}
|
|
9925
9942
|
const results = [];
|
|
9926
|
-
for (let i = 0; i < ids.length; i +=
|
|
9943
|
+
for (let i = 0; i < ids.length; i += LINK_FETCH_BATCH) {
|
|
9927
9944
|
for (let pause = checkClock(ctx); pause !== null; pause = checkClock(ctx)) await pause;
|
|
9928
|
-
const chunk = ids.slice(i, i +
|
|
9929
|
-
|
|
9945
|
+
const chunk = ids.slice(i, i + LINK_FETCH_BATCH);
|
|
9946
|
+
const rows = await fetchRecordsData(chunk.flatMap((id) => id === null ? [] : [id]), ctx);
|
|
9947
|
+
results.push(...chunk.map((id) => id === null ? null : rows.get(id) ?? null));
|
|
9930
9948
|
}
|
|
9931
9949
|
return results;
|
|
9932
9950
|
}
|
|
@@ -10633,9 +10651,11 @@ async function predictWorkflowEffects(given) {
|
|
|
10633
10651
|
const record = look(recordId);
|
|
10634
10652
|
return record === void 0 ? void 0 : knownCells(input.tables, record.table_id, { id: recordId, ...record.cells, table_id: record.table_id });
|
|
10635
10653
|
},
|
|
10636
|
-
set: () => void 0
|
|
10654
|
+
set: () => void 0,
|
|
10655
|
+
// What the prediction holds is its own model of the writes, never dropped.
|
|
10656
|
+
clear: () => void 0
|
|
10637
10657
|
};
|
|
10638
|
-
const fetchRecord = async (
|
|
10658
|
+
const fetchRecord = async (recordIds) => unread(recordIds[0] ?? "");
|
|
10639
10659
|
const ctx = {
|
|
10640
10660
|
trigger: { app_workflow: clientTrigger(input) },
|
|
10641
10661
|
step_outputs: {},
|
package/dist/shared_types.d.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* tarball. Written at every build, never edited.
|
|
5
5
|
*/
|
|
6
6
|
export type AppAbsence = { member: { id: string; name: string; }; stand_in: { id: string; name: string; }; starts_on: string; ends_on: string; group_ids: string[]; };
|
|
7
|
+
export type AppAgentRunStatus = "aborted" | "awaiting_input" | "completed" | "error" | "running";
|
|
7
8
|
/** A files cell entry; `url`/`thumbnail_url` are presigned (24h) and load from the sandboxed frame. */
|
|
8
9
|
export interface AppFile {
|
|
9
10
|
id: string;
|
package/docs/ai.md
CHANGED
|
@@ -199,7 +199,7 @@ that reads its own input never gains the ability to read *other* files in the wo
|
|
|
199
199
|
|
|
200
200
|
## `useAgentRuns(sessionId, opts?)` — session history
|
|
201
201
|
|
|
202
|
-
Reads a session's persisted run history, oldest-first: `{ runs, loading, error, refetch }`, where each `AgentRunRecord` carries `id`, `agent_alias`, `session_id`, `status`, `input`, `output`, `error_message`, `started_at`, `completed_at`. `opts` takes `{ enabled?, revalidateOnFocus? }`. A persisted record's `output` is the validated structured object for a structured agent and the **final answer string** for a free-text agent.
|
|
202
|
+
Reads a session's persisted run history, oldest-first: `{ runs, loading, error, refetch }`, where each `AgentRunRecord` carries `id`, `agent_alias`, `session_id`, `status`, `input`, `output`, `error_message`, `started_at`, `completed_at`. `status` is `running`, `awaiting_input` (parked on an answer), `completed`, `error` (with `error_message`) or `aborted` (cancelled; `error_message` stays null). `opts` takes `{ enabled?, revalidateOnFocus? }`. A persisted record's `output` is the validated structured object for a structured agent and the **final answer string** for a free-text agent.
|
|
203
203
|
|
|
204
204
|
**Limitation:** the embedded product host implements no history op — `useAgentRuns` errors with "Unknown RPC op: agentRuns" in an embedded app, and a standalone caller is anonymous, so it is refused. The history *exists* server-side (it is what feeds session context), but this hook reads it from no transport. Do not build a session-log UI on it; keep the visible log in app state from the live `useAgentRun` results instead.
|
|
205
205
|
|
package/docs/workflows.md
CHANGED
|
@@ -256,6 +256,8 @@ be written before its declaration. A key outside its row is refused when the bod
|
|
|
256
256
|
`wait` and `wait_for_event` carry no payload and are statement-only. `wait.duration_in_minutes`
|
|
257
257
|
and every `timeout_in_minutes` must be a **positive number literal**, not an expression, and
|
|
258
258
|
`wait_for_event.event_type` is a string literal from a closed set — `"payment"` or `"webhook"`.
|
|
259
|
+
A `"payment"` wait resumes with `event_data.payment_status` set to `"paid"`, `"failed"` or `"expired"`; `"expired"`
|
|
260
|
+
arrives once the payment link has expired, within about half an hour of its expiry.
|
|
259
261
|
|
|
260
262
|
### `agent` — LLM reasoning as one step
|
|
261
263
|
|
package/package.json
CHANGED