@runtypelabs/cli 2.20.0 → 2.21.0
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.js +181 -145
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -44228,6 +44228,135 @@ import React3 from "react";
|
|
|
44228
44228
|
import { render as render3 } from "ink";
|
|
44229
44229
|
import { useState as useState4, useEffect as useEffect5 } from "react";
|
|
44230
44230
|
import { writeFileSync } from "fs";
|
|
44231
|
+
|
|
44232
|
+
// src/lib/terminal-image.ts
|
|
44233
|
+
var ESC = "\x1B";
|
|
44234
|
+
var BEL = "\x07";
|
|
44235
|
+
var ST = `${ESC}\\`;
|
|
44236
|
+
function detectImageProtocol(env = process.env, isTTY2 = process.stdout.isTTY === true) {
|
|
44237
|
+
if (!isTTY2) return null;
|
|
44238
|
+
if (env.TERM === "xterm-kitty" || env.KITTY_WINDOW_ID || env.TERM_PROGRAM === "ghostty") {
|
|
44239
|
+
return "kitty";
|
|
44240
|
+
}
|
|
44241
|
+
if (env.TERM_PROGRAM === "iTerm.app" || env.TERM_PROGRAM === "WezTerm" || env.LC_TERMINAL === "iTerm2") {
|
|
44242
|
+
return "iterm2";
|
|
44243
|
+
}
|
|
44244
|
+
return null;
|
|
44245
|
+
}
|
|
44246
|
+
function parseImageDataUri(value) {
|
|
44247
|
+
if (typeof value !== "string" || !value.startsWith("data:")) return null;
|
|
44248
|
+
const match = value.match(/^data:([^;,]+)(?:;[^,]*)?;base64,(.+)$/s);
|
|
44249
|
+
if (!match || !match[1] || !match[2]) return null;
|
|
44250
|
+
return { mimeType: match[1], base64: match[2] };
|
|
44251
|
+
}
|
|
44252
|
+
function base64DecodedByteLength(base643) {
|
|
44253
|
+
const len = base643.length;
|
|
44254
|
+
if (len === 0) return 0;
|
|
44255
|
+
let padding = 0;
|
|
44256
|
+
if (base643.endsWith("==")) padding = 2;
|
|
44257
|
+
else if (base643.endsWith("=")) padding = 1;
|
|
44258
|
+
return Math.floor(len * 3 / 4) - padding;
|
|
44259
|
+
}
|
|
44260
|
+
function kittyImageSequence(base643) {
|
|
44261
|
+
const CHUNK = 4096;
|
|
44262
|
+
if (base643.length <= CHUNK) {
|
|
44263
|
+
return `${ESC}_Ga=T,f=100,m=0;${base643}${ST}`;
|
|
44264
|
+
}
|
|
44265
|
+
let out = "";
|
|
44266
|
+
for (let i = 0; i < base643.length; i += CHUNK) {
|
|
44267
|
+
const piece = base643.slice(i, i + CHUNK);
|
|
44268
|
+
const more = i + CHUNK < base643.length ? 1 : 0;
|
|
44269
|
+
out += i === 0 ? `${ESC}_Ga=T,f=100,m=${more};${piece}${ST}` : `${ESC}_Gm=${more};${piece}${ST}`;
|
|
44270
|
+
}
|
|
44271
|
+
return out;
|
|
44272
|
+
}
|
|
44273
|
+
function encodeInlineImage(opts) {
|
|
44274
|
+
const { base64: base643, mimeType, protocol } = opts;
|
|
44275
|
+
if (!base643) return null;
|
|
44276
|
+
if (protocol === "iterm2") {
|
|
44277
|
+
const sizeBytes = base64DecodedByteLength(base643);
|
|
44278
|
+
return `${ESC}]1337;File=inline=1;size=${sizeBytes};width=auto;height=auto;preserveAspectRatio=1:${base643}${BEL}`;
|
|
44279
|
+
}
|
|
44280
|
+
if (mimeType !== "image/png") return null;
|
|
44281
|
+
return kittyImageSequence(base643);
|
|
44282
|
+
}
|
|
44283
|
+
function renderInlineImage(value, protocol) {
|
|
44284
|
+
const parsed = parseImageDataUri(value);
|
|
44285
|
+
if (!parsed) return null;
|
|
44286
|
+
return encodeInlineImage({ base64: parsed.base64, mimeType: parsed.mimeType, protocol });
|
|
44287
|
+
}
|
|
44288
|
+
|
|
44289
|
+
// src/lib/message-content.ts
|
|
44290
|
+
function renderMessageContent(content) {
|
|
44291
|
+
if (typeof content === "string") return content;
|
|
44292
|
+
if (!Array.isArray(content)) return content == null ? "" : String(content);
|
|
44293
|
+
return content.map((part) => {
|
|
44294
|
+
if (part == null || typeof part !== "object") return part == null ? "" : String(part);
|
|
44295
|
+
const p = part;
|
|
44296
|
+
switch (p.type) {
|
|
44297
|
+
case "text":
|
|
44298
|
+
case "reasoning":
|
|
44299
|
+
return typeof p.text === "string" ? p.text : "";
|
|
44300
|
+
case "image":
|
|
44301
|
+
return `[image${"mimeType" in p && p.mimeType ? ` ${p.mimeType}` : ""}]`;
|
|
44302
|
+
case "file":
|
|
44303
|
+
return `[file${"filename" in p && p.filename ? ` ${p.filename}` : ""}${"mimeType" in p && p.mimeType ? ` (${p.mimeType})` : ""}]`;
|
|
44304
|
+
case "asset_ref":
|
|
44305
|
+
return `[attachment${"filename" in p && p.filename ? ` ${p.filename}` : ""}${"mimeType" in p && p.mimeType ? ` ${p.mimeType}` : ""}]`;
|
|
44306
|
+
default:
|
|
44307
|
+
return typeof p.type === "string" ? `[${p.type}]` : "";
|
|
44308
|
+
}
|
|
44309
|
+
}).filter((s) => s.length > 0).join(" ");
|
|
44310
|
+
}
|
|
44311
|
+
function renderMessageContentWithImages(content, protocol) {
|
|
44312
|
+
if (!Array.isArray(content)) {
|
|
44313
|
+
return { text: renderMessageContent(content), images: [] };
|
|
44314
|
+
}
|
|
44315
|
+
const inline = [];
|
|
44316
|
+
const images = [];
|
|
44317
|
+
for (const part of content) {
|
|
44318
|
+
if (part && typeof part === "object" && part.type === "image") {
|
|
44319
|
+
const image = part.image;
|
|
44320
|
+
const seq = typeof image === "string" ? renderInlineImage(image, protocol) : null;
|
|
44321
|
+
if (seq) {
|
|
44322
|
+
images.push(seq);
|
|
44323
|
+
continue;
|
|
44324
|
+
}
|
|
44325
|
+
}
|
|
44326
|
+
inline.push(renderMessageContent([part]));
|
|
44327
|
+
}
|
|
44328
|
+
return { text: inline.filter((s) => s.length > 0).join(" "), images };
|
|
44329
|
+
}
|
|
44330
|
+
|
|
44331
|
+
// src/commands/records.ts
|
|
44332
|
+
function printRecordDetail(data, imageProtocol) {
|
|
44333
|
+
console.log(` ID: ${data.id}`);
|
|
44334
|
+
console.log(` Name: ${data.name}`);
|
|
44335
|
+
console.log(` Type: ${data.type}`);
|
|
44336
|
+
if (data.metadata) {
|
|
44337
|
+
console.log(` Metadata: ${JSON.stringify(data.metadata, null, 2)}`);
|
|
44338
|
+
}
|
|
44339
|
+
const messages = data.messages ?? [];
|
|
44340
|
+
if (messages.length === 0) return;
|
|
44341
|
+
console.log(chalk6.cyan(`
|
|
44342
|
+
Messages (${messages.length}):`));
|
|
44343
|
+
for (const msg of messages) {
|
|
44344
|
+
const role = typeof msg.role === "string" ? msg.role : "message";
|
|
44345
|
+
const roleColor = role === "user" ? chalk6.blue : role === "assistant" ? chalk6.green : chalk6.gray;
|
|
44346
|
+
const rolePrefix = ` ${roleColor(role)}: `;
|
|
44347
|
+
if (imageProtocol) {
|
|
44348
|
+
const { text, images } = renderMessageContentWithImages(msg.content, imageProtocol);
|
|
44349
|
+
process.stdout.write(`${rolePrefix}${text}
|
|
44350
|
+
`);
|
|
44351
|
+
for (const seq of images) {
|
|
44352
|
+
process.stdout.write(`${seq}
|
|
44353
|
+
`);
|
|
44354
|
+
}
|
|
44355
|
+
} else {
|
|
44356
|
+
console.log(`${rolePrefix}${renderMessageContent(msg.content)}`);
|
|
44357
|
+
}
|
|
44358
|
+
}
|
|
44359
|
+
}
|
|
44231
44360
|
var recordsCommand = new Command3("records").description("Manage records");
|
|
44232
44361
|
recordsCommand.command("list").description("List all records").option("--type <type>", "Filter by record type").option("--limit <n>", "Limit number of results", "20").option("--cursor <cursor>", "Pagination cursor for the next page").option("--json", "Output as JSON").option("--tty", "Force TTY mode").option("--no-tty", "Force non-TTY mode").action(
|
|
44233
44362
|
async (options) => {
|
|
@@ -44307,45 +44436,43 @@ recordsCommand.command("list").description("List all records").option("--type <t
|
|
|
44307
44436
|
await waitUntilExit();
|
|
44308
44437
|
}
|
|
44309
44438
|
);
|
|
44310
|
-
recordsCommand.command("get <id>").description("Get record details").option("--json", "Output as JSON").option("--tty", "Force TTY mode").option("--no-tty", "Force non-TTY mode").
|
|
44311
|
-
|
|
44312
|
-
|
|
44313
|
-
|
|
44314
|
-
|
|
44315
|
-
|
|
44316
|
-
|
|
44317
|
-
|
|
44318
|
-
|
|
44319
|
-
|
|
44320
|
-
|
|
44321
|
-
|
|
44322
|
-
|
|
44323
|
-
|
|
44324
|
-
|
|
44325
|
-
|
|
44439
|
+
recordsCommand.command("get <id>").description("Get record details").option("--json", "Output as JSON").option("--tty", "Force TTY mode").option("--no-tty", "Force non-TTY mode").option("--no-images", "Disable inline image rendering even in supported terminals").action(
|
|
44440
|
+
async (id, options) => {
|
|
44441
|
+
const apiKey = await ensureAuth();
|
|
44442
|
+
if (!apiKey) return;
|
|
44443
|
+
const client = createCliClient(apiKey);
|
|
44444
|
+
const interactive = isTTY(options) && !options.json;
|
|
44445
|
+
const imageProtocol = interactive && options.images !== false ? detectImageProtocol() : null;
|
|
44446
|
+
if (!interactive || imageProtocol) {
|
|
44447
|
+
try {
|
|
44448
|
+
const data = await client.get(`/records/${id}`);
|
|
44449
|
+
if (options.json) {
|
|
44450
|
+
printJson(data);
|
|
44451
|
+
return;
|
|
44452
|
+
}
|
|
44453
|
+
printRecordDetail(data, imageProtocol);
|
|
44454
|
+
} catch (error51) {
|
|
44455
|
+
const message = error51 instanceof Error ? error51.message : "Unknown error";
|
|
44456
|
+
console.error(chalk6.red(`Failed to fetch record: ${message}`));
|
|
44457
|
+
process.exit(1);
|
|
44326
44458
|
}
|
|
44327
|
-
|
|
44328
|
-
const message = error51 instanceof Error ? error51.message : "Unknown error";
|
|
44329
|
-
console.error(chalk6.red(`Failed to fetch record: ${message}`));
|
|
44330
|
-
process.exit(1);
|
|
44459
|
+
return;
|
|
44331
44460
|
}
|
|
44332
|
-
|
|
44333
|
-
|
|
44334
|
-
|
|
44335
|
-
|
|
44336
|
-
|
|
44337
|
-
|
|
44338
|
-
|
|
44339
|
-
|
|
44340
|
-
|
|
44341
|
-
|
|
44342
|
-
|
|
44343
|
-
|
|
44344
|
-
|
|
44345
|
-
|
|
44346
|
-
|
|
44347
|
-
return React3.createElement(EntityCard, {
|
|
44348
|
-
fields: [
|
|
44461
|
+
const App = () => {
|
|
44462
|
+
const [items, setItems] = useState4(null);
|
|
44463
|
+
const [error51, setError] = useState4(null);
|
|
44464
|
+
useEffect5(() => {
|
|
44465
|
+
client.get(`/records/${id}`).then((res) => setItems([res])).catch((err) => setError(err instanceof Error ? err : new Error(String(err))));
|
|
44466
|
+
}, []);
|
|
44467
|
+
return React3.createElement(DataList, {
|
|
44468
|
+
title: "Record",
|
|
44469
|
+
items,
|
|
44470
|
+
error: error51,
|
|
44471
|
+
loading: items === null && error51 === null,
|
|
44472
|
+
renderCard: (item) => {
|
|
44473
|
+
const record2 = item;
|
|
44474
|
+
const messages = record2.messages ?? [];
|
|
44475
|
+
const fields = [
|
|
44349
44476
|
{ label: "ID", value: record2.id, color: "green" },
|
|
44350
44477
|
{ label: "Name", value: record2.name },
|
|
44351
44478
|
{ label: "Type", value: record2.type },
|
|
@@ -44353,14 +44480,21 @@ recordsCommand.command("get <id>").description("Get record details").option("--j
|
|
|
44353
44480
|
label: "Metadata",
|
|
44354
44481
|
value: record2.metadata ? JSON.stringify(record2.metadata) : null
|
|
44355
44482
|
}
|
|
44356
|
-
]
|
|
44357
|
-
|
|
44358
|
-
|
|
44359
|
-
|
|
44360
|
-
|
|
44361
|
-
|
|
44362
|
-
|
|
44363
|
-
});
|
|
44483
|
+
];
|
|
44484
|
+
if (messages.length > 0) {
|
|
44485
|
+
fields.push({
|
|
44486
|
+
label: `Messages (${messages.length})`,
|
|
44487
|
+
value: messages.map((m2) => `${m2.role ?? "message"}: ${renderMessageContent(m2.content)}`).join("\n")
|
|
44488
|
+
});
|
|
44489
|
+
}
|
|
44490
|
+
return React3.createElement(EntityCard, { fields });
|
|
44491
|
+
}
|
|
44492
|
+
});
|
|
44493
|
+
};
|
|
44494
|
+
const { waitUntilExit } = render3(React3.createElement(App));
|
|
44495
|
+
await waitUntilExit();
|
|
44496
|
+
}
|
|
44497
|
+
);
|
|
44364
44498
|
recordsCommand.command("results <id>").description("Get step-level execution results for a record").option("--flow-id <flowId>", "Filter by flow ID").option("--batch-id <batchId>", "Filter by batch ID").option("--status <status>", "Filter by status").option("--limit <n>", "Limit number of results").option("--offset <n>", "Offset for pagination").option("--json", "Output as JSON").option("--tty", "Force TTY mode").option("--no-tty", "Force non-TTY mode").action(
|
|
44365
44499
|
async (id, options) => {
|
|
44366
44500
|
const apiKey = await ensureAuth();
|
|
@@ -48784,108 +48918,10 @@ import chalk17 from "chalk";
|
|
|
48784
48918
|
import React14 from "react";
|
|
48785
48919
|
import { render as render14 } from "ink";
|
|
48786
48920
|
import { useState as useState15, useEffect as useEffect16 } from "react";
|
|
48787
|
-
|
|
48788
|
-
// src/lib/terminal-image.ts
|
|
48789
|
-
var ESC = "\x1B";
|
|
48790
|
-
var BEL = "\x07";
|
|
48791
|
-
var ST = `${ESC}\\`;
|
|
48792
|
-
function detectImageProtocol(env = process.env, isTTY2 = process.stdout.isTTY === true) {
|
|
48793
|
-
if (!isTTY2) return null;
|
|
48794
|
-
if (env.TERM === "xterm-kitty" || env.KITTY_WINDOW_ID || env.TERM_PROGRAM === "ghostty") {
|
|
48795
|
-
return "kitty";
|
|
48796
|
-
}
|
|
48797
|
-
if (env.TERM_PROGRAM === "iTerm.app" || env.TERM_PROGRAM === "WezTerm" || env.LC_TERMINAL === "iTerm2") {
|
|
48798
|
-
return "iterm2";
|
|
48799
|
-
}
|
|
48800
|
-
return null;
|
|
48801
|
-
}
|
|
48802
|
-
function parseImageDataUri(value) {
|
|
48803
|
-
if (typeof value !== "string" || !value.startsWith("data:")) return null;
|
|
48804
|
-
const match = value.match(/^data:([^;,]+)(?:;[^,]*)?;base64,(.+)$/s);
|
|
48805
|
-
if (!match || !match[1] || !match[2]) return null;
|
|
48806
|
-
return { mimeType: match[1], base64: match[2] };
|
|
48807
|
-
}
|
|
48808
|
-
function base64DecodedByteLength(base643) {
|
|
48809
|
-
const len = base643.length;
|
|
48810
|
-
if (len === 0) return 0;
|
|
48811
|
-
let padding = 0;
|
|
48812
|
-
if (base643.endsWith("==")) padding = 2;
|
|
48813
|
-
else if (base643.endsWith("=")) padding = 1;
|
|
48814
|
-
return Math.floor(len * 3 / 4) - padding;
|
|
48815
|
-
}
|
|
48816
|
-
function kittyImageSequence(base643) {
|
|
48817
|
-
const CHUNK = 4096;
|
|
48818
|
-
if (base643.length <= CHUNK) {
|
|
48819
|
-
return `${ESC}_Ga=T,f=100,m=0;${base643}${ST}`;
|
|
48820
|
-
}
|
|
48821
|
-
let out = "";
|
|
48822
|
-
for (let i = 0; i < base643.length; i += CHUNK) {
|
|
48823
|
-
const piece = base643.slice(i, i + CHUNK);
|
|
48824
|
-
const more = i + CHUNK < base643.length ? 1 : 0;
|
|
48825
|
-
out += i === 0 ? `${ESC}_Ga=T,f=100,m=${more};${piece}${ST}` : `${ESC}_Gm=${more};${piece}${ST}`;
|
|
48826
|
-
}
|
|
48827
|
-
return out;
|
|
48828
|
-
}
|
|
48829
|
-
function encodeInlineImage(opts) {
|
|
48830
|
-
const { base64: base643, mimeType, protocol } = opts;
|
|
48831
|
-
if (!base643) return null;
|
|
48832
|
-
if (protocol === "iterm2") {
|
|
48833
|
-
const sizeBytes = base64DecodedByteLength(base643);
|
|
48834
|
-
return `${ESC}]1337;File=inline=1;size=${sizeBytes};width=auto;height=auto;preserveAspectRatio=1:${base643}${BEL}`;
|
|
48835
|
-
}
|
|
48836
|
-
if (mimeType !== "image/png") return null;
|
|
48837
|
-
return kittyImageSequence(base643);
|
|
48838
|
-
}
|
|
48839
|
-
function renderInlineImage(value, protocol) {
|
|
48840
|
-
const parsed = parseImageDataUri(value);
|
|
48841
|
-
if (!parsed) return null;
|
|
48842
|
-
return encodeInlineImage({ base64: parsed.base64, mimeType: parsed.mimeType, protocol });
|
|
48843
|
-
}
|
|
48844
|
-
|
|
48845
|
-
// src/commands/conversations.ts
|
|
48846
|
-
function renderMessageContent(content) {
|
|
48847
|
-
if (typeof content === "string") return content;
|
|
48848
|
-
if (!Array.isArray(content)) return content == null ? "" : String(content);
|
|
48849
|
-
return content.map((part) => {
|
|
48850
|
-
if (part == null || typeof part !== "object") return part == null ? "" : String(part);
|
|
48851
|
-
const p = part;
|
|
48852
|
-
switch (p.type) {
|
|
48853
|
-
case "text":
|
|
48854
|
-
case "reasoning":
|
|
48855
|
-
return typeof p.text === "string" ? p.text : "";
|
|
48856
|
-
case "image":
|
|
48857
|
-
return `[image${"mimeType" in p && p.mimeType ? ` ${p.mimeType}` : ""}]`;
|
|
48858
|
-
case "file":
|
|
48859
|
-
return `[file${"filename" in p && p.filename ? ` ${p.filename}` : ""}${"mimeType" in p && p.mimeType ? ` (${p.mimeType})` : ""}]`;
|
|
48860
|
-
case "asset_ref":
|
|
48861
|
-
return `[attachment${"filename" in p && p.filename ? ` ${p.filename}` : ""}${"mimeType" in p && p.mimeType ? ` ${p.mimeType}` : ""}]`;
|
|
48862
|
-
default:
|
|
48863
|
-
return typeof p.type === "string" ? `[${p.type}]` : "";
|
|
48864
|
-
}
|
|
48865
|
-
}).filter((s) => s.length > 0).join(" ");
|
|
48866
|
-
}
|
|
48867
48921
|
function writeMessageWithImages(msg, rolePrefix, protocol) {
|
|
48868
48922
|
const out = process.stdout;
|
|
48869
|
-
const
|
|
48870
|
-
|
|
48871
|
-
out.write(`${rolePrefix}${renderMessageContent(content)}
|
|
48872
|
-
`);
|
|
48873
|
-
return;
|
|
48874
|
-
}
|
|
48875
|
-
const inline = [];
|
|
48876
|
-
const images = [];
|
|
48877
|
-
for (const part of content) {
|
|
48878
|
-
if (part && typeof part === "object" && part.type === "image") {
|
|
48879
|
-
const image = part.image;
|
|
48880
|
-
const seq = typeof image === "string" ? renderInlineImage(image, protocol) : null;
|
|
48881
|
-
if (seq) {
|
|
48882
|
-
images.push(seq);
|
|
48883
|
-
continue;
|
|
48884
|
-
}
|
|
48885
|
-
}
|
|
48886
|
-
inline.push(renderMessageContent([part]));
|
|
48887
|
-
}
|
|
48888
|
-
out.write(`${rolePrefix}${inline.filter((s) => s.length > 0).join(" ")}
|
|
48923
|
+
const { text, images } = renderMessageContentWithImages(msg.content, protocol);
|
|
48924
|
+
out.write(`${rolePrefix}${text}
|
|
48889
48925
|
`);
|
|
48890
48926
|
for (const seq of images) {
|
|
48891
48927
|
out.write(`${seq}
|