@lotics/app-sdk 0.133.0 → 0.133.2
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/{chunk-J3UN4AJW.js → chunk-FAT4EYLS.js} +159 -56
- package/dist/index.js +4 -4
- package/dist/router.js +1 -1
- package/package.json +1 -1
|
@@ -348,6 +348,104 @@ function telemetryErrorMessage(status, parsed) {
|
|
|
348
348
|
return code ?? gatewayErrorMessage(status);
|
|
349
349
|
}
|
|
350
350
|
|
|
351
|
+
// ../shared/src/schemas/loaded_shape.ts
|
|
352
|
+
var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
353
|
+
|
|
354
|
+
// ../shared/src/answer_lines.ts
|
|
355
|
+
var ANSWER_LINES_MEDIA_TYPE = "application/x-ndjson";
|
|
356
|
+
var AnswerLinesError = class extends Error {
|
|
357
|
+
name = "AnswerLinesError";
|
|
358
|
+
};
|
|
359
|
+
var mediaTypeOf = (stated) => stated.split(";")[0]?.trim().toLowerCase();
|
|
360
|
+
function isAnswerLines(headers) {
|
|
361
|
+
const type = headers.get("content-type");
|
|
362
|
+
return type !== null && mediaTypeOf(type) === ANSWER_LINES_MEDIA_TYPE;
|
|
363
|
+
}
|
|
364
|
+
async function readAnswerLines(body, count, onLine, signal) {
|
|
365
|
+
signal?.throwIfAborted();
|
|
366
|
+
const reader = body.getReader();
|
|
367
|
+
let onAbort;
|
|
368
|
+
const aborted = new Promise((_, reject) => {
|
|
369
|
+
if (signal === void 0) return;
|
|
370
|
+
onAbort = () => reject(signal.reason);
|
|
371
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
372
|
+
});
|
|
373
|
+
const decoder = new TextDecoder();
|
|
374
|
+
const answered = /* @__PURE__ */ new Set();
|
|
375
|
+
let pending2 = "";
|
|
376
|
+
const take = (text) => {
|
|
377
|
+
if (text.trim() === "") return;
|
|
378
|
+
let line;
|
|
379
|
+
try {
|
|
380
|
+
line = JSON.parse(text);
|
|
381
|
+
} catch (cause) {
|
|
382
|
+
throw new AnswerLinesError(`An answer line is not JSON (${text.length} characters).`, { cause });
|
|
383
|
+
}
|
|
384
|
+
if (!isObject(line)) throw new AnswerLinesError("An answer line is not an object.");
|
|
385
|
+
const { at } = line;
|
|
386
|
+
if (typeof at !== "number" || !Number.isInteger(at) || at < 0 || at >= count || answered.has(at)) {
|
|
387
|
+
throw new AnswerLinesError(`An answer line names read ${String(at)}, which is not one of the ${count} left to answer.`);
|
|
388
|
+
}
|
|
389
|
+
answered.add(at);
|
|
390
|
+
onLine(at, line);
|
|
391
|
+
};
|
|
392
|
+
try {
|
|
393
|
+
for (; ; ) {
|
|
394
|
+
const { done, value } = await (signal === void 0 ? reader.read() : Promise.race([reader.read(), aborted]));
|
|
395
|
+
if (done) break;
|
|
396
|
+
pending2 += decoder.decode(value, { stream: true });
|
|
397
|
+
const lines = pending2.split("\n");
|
|
398
|
+
pending2 = lines.pop() ?? "";
|
|
399
|
+
for (const text of lines) take(text);
|
|
400
|
+
}
|
|
401
|
+
pending2 += decoder.decode();
|
|
402
|
+
if (pending2.trim() !== "") throw new AnswerLinesError(`The answer lines ended inside a line (${pending2.length} characters).`);
|
|
403
|
+
} catch (error) {
|
|
404
|
+
await reader.cancel(error);
|
|
405
|
+
throw error;
|
|
406
|
+
} finally {
|
|
407
|
+
if (onAbort !== void 0) signal?.removeEventListener("abort", onAbort);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// ../shared/src/query_batch_answer.ts
|
|
412
|
+
var QueryBatchAnswerError = class extends Error {
|
|
413
|
+
name = "QueryBatchAnswerError";
|
|
414
|
+
};
|
|
415
|
+
function queryBatchAnswerOf(value) {
|
|
416
|
+
if (!isObject(value)) return void 0;
|
|
417
|
+
if ("result" in value) return isObject(value.result) ? { result: value.result } : void 0;
|
|
418
|
+
const { error } = value;
|
|
419
|
+
if (!isObject(error) || typeof error.status !== "number" || typeof error.message !== "string") return void 0;
|
|
420
|
+
const { code, hint, message_source: source } = error;
|
|
421
|
+
return {
|
|
422
|
+
error: {
|
|
423
|
+
status: error.status,
|
|
424
|
+
message: error.message,
|
|
425
|
+
...typeof code === "string" ? { code } : {},
|
|
426
|
+
...typeof hint === "string" ? { hint } : {},
|
|
427
|
+
...source === "system" || source === "customer" ? { message_source: source } : {}
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
async function readQueryBatch(response, count, onAnswer, signal) {
|
|
432
|
+
const answered = /* @__PURE__ */ new Set();
|
|
433
|
+
const take = (at, value) => {
|
|
434
|
+
const answer = queryBatchAnswerOf(value);
|
|
435
|
+
if (answer === void 0) throw new QueryBatchAnswerError(`The answer to read ${at} is neither a result nor a refusal.`);
|
|
436
|
+
answered.add(at);
|
|
437
|
+
onAnswer(at, answer);
|
|
438
|
+
};
|
|
439
|
+
if (response.body !== null && isAnswerLines(response.headers)) {
|
|
440
|
+
await readAnswerLines(response.body, count, take, signal);
|
|
441
|
+
return answered;
|
|
442
|
+
}
|
|
443
|
+
const body = await response.json();
|
|
444
|
+
if (!isObject(body) || !Array.isArray(body.results)) throw new QueryBatchAnswerError("The batch's answer carries no results.");
|
|
445
|
+
body.results.slice(0, count).forEach((value, at) => take(at, value));
|
|
446
|
+
return answered;
|
|
447
|
+
}
|
|
448
|
+
|
|
351
449
|
// ../shared/src/diacritics.ts
|
|
352
450
|
var COMBINING_MARKS = /[̀-ͯ]/g;
|
|
353
451
|
function foldDiacritics(value) {
|
|
@@ -1866,7 +1964,7 @@ async function streamStartError(res) {
|
|
|
1866
1964
|
return new ApiRefusal(res.status, parsed);
|
|
1867
1965
|
}
|
|
1868
1966
|
var API_TIMEOUT_MS = 3e4;
|
|
1869
|
-
|
|
1967
|
+
function apiHeaders(body, opts) {
|
|
1870
1968
|
const headers = {};
|
|
1871
1969
|
if (body) headers["content-type"] = "application/json";
|
|
1872
1970
|
if (sessionToken && !opts?.skipAuth) {
|
|
@@ -1875,47 +1973,70 @@ async function apiCall(method, path, body, opts) {
|
|
|
1875
1973
|
if (opts?.runToken) {
|
|
1876
1974
|
headers[APP_AGENT_RUN_TOKEN_HEADER] = opts.runToken;
|
|
1877
1975
|
}
|
|
1976
|
+
return headers;
|
|
1977
|
+
}
|
|
1978
|
+
function parsedJson(text) {
|
|
1979
|
+
if (!text) return null;
|
|
1980
|
+
try {
|
|
1981
|
+
return JSON.parse(text);
|
|
1982
|
+
} catch {
|
|
1983
|
+
return null;
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
async function refused(res, opts) {
|
|
1987
|
+
const parsed = parsedJson(await res.text());
|
|
1988
|
+
const errorBody = parsed;
|
|
1989
|
+
if (res.status === 401 && errorBody?.error_code === PASSWORD_REQUIRED_CODE && !opts?.skipAuth) {
|
|
1990
|
+
sessionToken = null;
|
|
1991
|
+
window.location.assign("/__gate");
|
|
1992
|
+
return new Promise(() => {
|
|
1993
|
+
});
|
|
1994
|
+
}
|
|
1995
|
+
throw new ApiRefusal(res.status, parsed, readFieldErrors(parsed));
|
|
1996
|
+
}
|
|
1997
|
+
async function readResponse(res, opts) {
|
|
1998
|
+
if (!res.ok) return refused(res, opts);
|
|
1999
|
+
const text = await res.text();
|
|
2000
|
+
return parsedJson(text) ?? (text ? text : {});
|
|
2001
|
+
}
|
|
2002
|
+
async function withinTimeout(request) {
|
|
1878
2003
|
const controller = new AbortController();
|
|
1879
2004
|
let didTimeout = false;
|
|
1880
2005
|
const timeoutId = setTimeout(() => {
|
|
1881
2006
|
didTimeout = true;
|
|
1882
2007
|
controller.abort();
|
|
1883
2008
|
}, API_TIMEOUT_MS);
|
|
1884
|
-
let res;
|
|
1885
2009
|
try {
|
|
1886
|
-
|
|
1887
|
-
method,
|
|
1888
|
-
headers,
|
|
1889
|
-
...method === "POST" && body ? { body: JSON.stringify(body) } : {},
|
|
1890
|
-
signal: controller.signal
|
|
1891
|
-
});
|
|
2010
|
+
return await request(controller.signal);
|
|
1892
2011
|
} catch (err) {
|
|
1893
|
-
if (didTimeout
|
|
1894
|
-
throw new Error(gatewayErrorMessage(524));
|
|
1895
|
-
}
|
|
2012
|
+
if (didTimeout) throw new Error(gatewayErrorMessage(524), { cause: err });
|
|
1896
2013
|
throw err;
|
|
1897
2014
|
} finally {
|
|
1898
2015
|
clearTimeout(timeoutId);
|
|
1899
2016
|
}
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
2017
|
+
}
|
|
2018
|
+
async function apiCall(method, path, body, opts) {
|
|
2019
|
+
const res = await withinTimeout(
|
|
2020
|
+
(signal) => fetch(`${apiBase()}${path}`, {
|
|
2021
|
+
method,
|
|
2022
|
+
headers: apiHeaders(body, opts),
|
|
2023
|
+
...method === "POST" && body ? { body: JSON.stringify(body) } : {},
|
|
2024
|
+
signal
|
|
2025
|
+
})
|
|
2026
|
+
);
|
|
2027
|
+
return readResponse(res, opts);
|
|
2028
|
+
}
|
|
2029
|
+
async function apiQueryBatch(path, body, count, onAnswer) {
|
|
2030
|
+
return withinTimeout(async (signal) => {
|
|
2031
|
+
const res = await fetch(`${apiBase()}${path}`, {
|
|
2032
|
+
method: "POST",
|
|
2033
|
+
headers: { ...apiHeaders(body), accept: ANSWER_LINES_MEDIA_TYPE },
|
|
2034
|
+
body: JSON.stringify(body),
|
|
2035
|
+
signal
|
|
2036
|
+
});
|
|
2037
|
+
if (!res.ok) return refused(res);
|
|
2038
|
+
return readQueryBatch(res, count, onAnswer, signal);
|
|
2039
|
+
});
|
|
1919
2040
|
}
|
|
1920
2041
|
function rpcStandalone(op, payload) {
|
|
1921
2042
|
switch (op) {
|
|
@@ -2071,37 +2192,19 @@ async function sendAskedReads() {
|
|
|
2071
2192
|
if (booted === void 0) return;
|
|
2072
2193
|
for (let at = 0; at < asked.length; at += APP_QUERY_BATCH_MAX) {
|
|
2073
2194
|
const chunk = asked.slice(at, at + APP_QUERY_BATCH_MAX);
|
|
2074
|
-
|
|
2075
|
-
const
|
|
2195
|
+
const answerRead = (k, answer) => {
|
|
2196
|
+
const read = chunk[k];
|
|
2197
|
+
if (read === void 0) return;
|
|
2198
|
+
if ("result" in answer) read.resolve(answer.result);
|
|
2199
|
+
else read.reject(new ApiRefusal(answer.error.status, answer.error));
|
|
2200
|
+
};
|
|
2201
|
+
apiQueryBatch(`/v1/apps/${booted.app_id}/query_batch`, { reads: chunk.map((read) => read.payload) }, chunk.length, answerRead).then((answered) => {
|
|
2076
2202
|
chunk.forEach((read, k) => {
|
|
2077
|
-
|
|
2078
|
-
if (answer === void 0) read.reject(new Error(`The server answered ${results.length} of ${chunk.length} reads.`));
|
|
2079
|
-
else if ("result" in answer) read.resolve(answer.result);
|
|
2080
|
-
else read.reject(new ApiRefusal(answer.error.status, answer.error));
|
|
2203
|
+
if (!answered.has(k)) read.reject(new Error(`The server answered ${answered.size} of ${chunk.length} reads.`));
|
|
2081
2204
|
});
|
|
2082
2205
|
}).catch((error) => chunk.forEach((read) => read.reject(error)));
|
|
2083
2206
|
}
|
|
2084
2207
|
}
|
|
2085
|
-
function batchResults(answered) {
|
|
2086
|
-
if (answered === null || typeof answered !== "object" || !("results" in answered) || !Array.isArray(answered.results)) {
|
|
2087
|
-
throw new Error("The server's batch answer carried no results.");
|
|
2088
|
-
}
|
|
2089
|
-
return answered.results.map((answer, at) => {
|
|
2090
|
-
if (answer !== null && typeof answer === "object" && "result" in answer) return { result: answer.result };
|
|
2091
|
-
const error = answer !== null && typeof answer === "object" && "error" in answer ? answer.error : void 0;
|
|
2092
|
-
if (error !== null && typeof error === "object" && "status" in error && typeof error.status === "number" && "message" in error && typeof error.message === "string") {
|
|
2093
|
-
return {
|
|
2094
|
-
error: {
|
|
2095
|
-
status: error.status,
|
|
2096
|
-
message: error.message,
|
|
2097
|
-
code: "code" in error ? error.code : void 0,
|
|
2098
|
-
message_source: "message_source" in error ? error.message_source : void 0
|
|
2099
|
-
}
|
|
2100
|
-
};
|
|
2101
|
-
}
|
|
2102
|
-
throw new Error(`The server's batch answer ${at} is neither a result nor a refusal.`);
|
|
2103
|
-
});
|
|
2104
|
-
}
|
|
2105
2208
|
async function standaloneExport(payload) {
|
|
2106
2209
|
const { app_id } = await boot();
|
|
2107
2210
|
return apiCall("POST", `/v1/apps/${app_id}/export`, payload, { appId: app_id });
|
package/dist/index.js
CHANGED
|
@@ -61,7 +61,7 @@ import {
|
|
|
61
61
|
subtractDecimal,
|
|
62
62
|
sumDecimal,
|
|
63
63
|
urlParam
|
|
64
|
-
} from "./chunk-
|
|
64
|
+
} from "./chunk-FAT4EYLS.js";
|
|
65
65
|
|
|
66
66
|
// src/mount.tsx
|
|
67
67
|
import { createRoot } from "react-dom/client";
|
|
@@ -8655,7 +8655,7 @@ function walkStepTree(steps, visit) {
|
|
|
8655
8655
|
}
|
|
8656
8656
|
}
|
|
8657
8657
|
}
|
|
8658
|
-
function
|
|
8658
|
+
function literalString(value) {
|
|
8659
8659
|
return value !== void 0 && isToolInputExpression(value) && value.$expr.kind === "lit" && typeof value.$expr.value === "string" ? value.$expr.value : null;
|
|
8660
8660
|
}
|
|
8661
8661
|
function toolRows(toolName) {
|
|
@@ -8670,7 +8670,7 @@ function rowWriteOf(step) {
|
|
|
8670
8670
|
if (step.type !== "tool_call") return void 0;
|
|
8671
8671
|
const rows = toolRows(step.tool_name);
|
|
8672
8672
|
if (rows === null) return void 0;
|
|
8673
|
-
return { table_id: rows === "unnamed" ? null :
|
|
8673
|
+
return { table_id: rows === "unnamed" ? null : literalString(step.input[rows.kwarg]) };
|
|
8674
8674
|
}
|
|
8675
8675
|
|
|
8676
8676
|
// ../shared/src/walk_workflow_expression.ts
|
|
@@ -8981,7 +8981,7 @@ function stepOutputRecordAnchor(stepId, path, ctx, seen) {
|
|
|
8981
8981
|
const step = steps.get(stepId);
|
|
8982
8982
|
if (!step) return null;
|
|
8983
8983
|
if (step.type === "tool_call") {
|
|
8984
|
-
const tableId =
|
|
8984
|
+
const tableId = literalString(step.input.table_id);
|
|
8985
8985
|
if (tableId === null) return null;
|
|
8986
8986
|
const table = ctx.tables.get(tableId);
|
|
8987
8987
|
if (!table) return null;
|
package/dist/router.js
CHANGED
package/package.json
CHANGED