@theokit/sdk-tools 0.13.0 → 0.14.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.cjs +57 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -1
- package/dist/index.d.ts +29 -1
- package/dist/index.js +56 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -8,6 +8,7 @@ var fs = require('fs');
|
|
|
8
8
|
var pathSafety = require('@theokit/sdk/path-safety');
|
|
9
9
|
var persistence = require('@theokit/sdk/persistence');
|
|
10
10
|
var child_process = require('child_process');
|
|
11
|
+
var interactive = require('@theokit/sdk/interactive');
|
|
11
12
|
var promises$1 = require('dns/promises');
|
|
12
13
|
var net = require('net');
|
|
13
14
|
var filesystem = require('@theokit/sdk/filesystem');
|
|
@@ -691,6 +692,60 @@ function globToRegex(pattern) {
|
|
|
691
692
|
}
|
|
692
693
|
return new RegExp(`^${regexStr}$`);
|
|
693
694
|
}
|
|
695
|
+
function toErrorJson(err) {
|
|
696
|
+
if (err instanceof interactive.InteractiveUnavailableError) {
|
|
697
|
+
return JSON.stringify({ ok: false, error: "interactive_unavailable" });
|
|
698
|
+
}
|
|
699
|
+
if (err instanceof interactive.NoSuchSessionError) {
|
|
700
|
+
return JSON.stringify({ ok: false, error: "no_such_session" });
|
|
701
|
+
}
|
|
702
|
+
throw err;
|
|
703
|
+
}
|
|
704
|
+
function createInteractiveShellTool(opts) {
|
|
705
|
+
const { interactive: interactive$1 } = opts;
|
|
706
|
+
return sdk.Tool.create({
|
|
707
|
+
name: "interactive_shell",
|
|
708
|
+
description: "Start an interactive shell session for a command that PROMPTS for input or is a REPL (python, node, `git rebase -i`, a `read` prompt) \u2014 NOT for one-shot commands (use shell_exec). Returns a session_id; drive it with write_stdin, reading the incremental output each step. Returns { ok, session_id, output } or { ok: false, error }.",
|
|
709
|
+
inputSchema: zod.z.object({
|
|
710
|
+
command: zod.z.string().min(1).describe("Command to run interactively, e.g. 'python3' or 'bash -i'."),
|
|
711
|
+
yield_time_ms: zod.z.number().int().positive().optional().describe("How long to wait for startup output before returning (clamped by the backend).")
|
|
712
|
+
}),
|
|
713
|
+
handler: async ({ command, yield_time_ms }, ctx) => {
|
|
714
|
+
try {
|
|
715
|
+
const backend = await interactive.resolveInteractive(interactive$1, ctx ?? {});
|
|
716
|
+
const { sessionId, output } = await backend.startInteractive(command, {
|
|
717
|
+
yieldMs: yield_time_ms
|
|
718
|
+
});
|
|
719
|
+
return JSON.stringify({ ok: true, session_id: sessionId, output });
|
|
720
|
+
} catch (err) {
|
|
721
|
+
return toErrorJson(err);
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
function createWriteStdinTool(opts) {
|
|
727
|
+
const { interactive: interactive$1 } = opts;
|
|
728
|
+
return sdk.Tool.create({
|
|
729
|
+
name: "write_stdin",
|
|
730
|
+
description: "Write input to a live interactive session (from interactive_shell) and read the output it produces during the wait window. Include a trailing newline to submit a line. Returns { ok, output, alive } (alive:false means the session exited) or { ok: false, error }.",
|
|
731
|
+
inputSchema: zod.z.object({
|
|
732
|
+
session_id: zod.z.string().min(1).describe("The session_id returned by interactive_shell."),
|
|
733
|
+
input: zod.z.string().describe("Text to write to stdin (add a trailing '\\n' to submit a line)."),
|
|
734
|
+
yield_time_ms: zod.z.number().int().positive().optional().describe("How long to wait for output before returning (clamped by the backend).")
|
|
735
|
+
}),
|
|
736
|
+
handler: async ({ session_id, input, yield_time_ms }, ctx) => {
|
|
737
|
+
try {
|
|
738
|
+
const backend = await interactive.resolveInteractive(interactive$1, ctx ?? {});
|
|
739
|
+
const { output, alive } = await backend.writeStdin(session_id, input, {
|
|
740
|
+
yieldMs: yield_time_ms
|
|
741
|
+
});
|
|
742
|
+
return JSON.stringify({ ok: true, output, alive });
|
|
743
|
+
} catch (err) {
|
|
744
|
+
return toErrorJson(err);
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
});
|
|
748
|
+
}
|
|
694
749
|
var CatastrophicCommandError = class extends sdk.ConfigurationError {
|
|
695
750
|
name = "CatastrophicCommandError";
|
|
696
751
|
constructor(reason) {
|
|
@@ -2360,6 +2415,7 @@ exports.createEditFileTool = createEditFileTool;
|
|
|
2360
2415
|
exports.createGenericHttpSearchAdapter = createGenericHttpSearchAdapter;
|
|
2361
2416
|
exports.createGitDiffTool = createGitDiffTool;
|
|
2362
2417
|
exports.createGlobTool = createGlobTool;
|
|
2418
|
+
exports.createInteractiveShellTool = createInteractiveShellTool;
|
|
2363
2419
|
exports.createListDirTool = createListDirTool;
|
|
2364
2420
|
exports.createPlanModeTool = createPlanModeTool;
|
|
2365
2421
|
exports.createQuestionTool = createQuestionTool;
|
|
@@ -2372,6 +2428,7 @@ exports.createTodolistTool = createTodolistTool;
|
|
|
2372
2428
|
exports.createWebFetchTool = createWebFetchTool;
|
|
2373
2429
|
exports.createWebSearchTool = createWebSearchTool;
|
|
2374
2430
|
exports.createWriteFileTool = createWriteFileTool;
|
|
2431
|
+
exports.createWriteStdinTool = createWriteStdinTool;
|
|
2375
2432
|
exports.denyCatastrophicCommands = denyCatastrophicCommands;
|
|
2376
2433
|
exports.formatCode = formatCode;
|
|
2377
2434
|
exports.formatDiff = formatDiff;
|