@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.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CustomTool, ConfigurationError } from '@theokit/sdk';
|
|
2
|
+
import { InteractiveProvider } from '@theokit/sdk/interactive';
|
|
2
3
|
import { FilesystemProvider } from '@theokit/sdk/filesystem';
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -153,6 +154,33 @@ interface CreateGlobToolOptions {
|
|
|
153
154
|
}
|
|
154
155
|
declare function createGlobTool(opts: CreateGlobToolOptions): CustomTool;
|
|
155
156
|
|
|
157
|
+
/**
|
|
158
|
+
* `interactive_shell` + `write_stdin` — built-in tools for driving an interactive
|
|
159
|
+
* session (a REPL, `git rebase -i`, any command that PROMPTS for stdin).
|
|
160
|
+
*
|
|
161
|
+
* Surface-agnostic by construction: both tools depend on an INJECTED
|
|
162
|
+
* `InteractiveProvider` (`@theokit/sdk/interactive`) exactly as `read_file`
|
|
163
|
+
* depends on `FilesystemProvider`. The HOST supplies the backend — a local
|
|
164
|
+
* `@theokit/sdk-pty` (terminal), a container/E2B backend (cluster/web), or a
|
|
165
|
+
* Tauri backend (desktop) — so the SAME tool runs on every theokit surface with
|
|
166
|
+
* NO native dependency here. When no backend is injected (or it cannot allocate
|
|
167
|
+
* a session) the tool returns `{ ok: false, error: 'interactive_unavailable' }`
|
|
168
|
+
* and the agent falls back to non-interactive exec.
|
|
169
|
+
*
|
|
170
|
+
* Return shapes (always a JSON string):
|
|
171
|
+
* interactive_shell → `{ ok: true, session_id, output }` | `{ ok: false, error }`
|
|
172
|
+
* write_stdin → `{ ok: true, output, alive }` | `{ ok: false, error }`
|
|
173
|
+
*/
|
|
174
|
+
|
|
175
|
+
interface CreateInteractiveShellToolOptions {
|
|
176
|
+
/** The interactive backend, or a per-request resolver of one (injected — never a direct native dep). */
|
|
177
|
+
interactive: InteractiveProvider<unknown>;
|
|
178
|
+
}
|
|
179
|
+
/** Start an interactive session; returns a `session_id` to drive with `write_stdin`. */
|
|
180
|
+
declare function createInteractiveShellTool(opts: CreateInteractiveShellToolOptions): CustomTool;
|
|
181
|
+
/** Write to a live interactive session's stdin and read the output it produces. */
|
|
182
|
+
declare function createWriteStdinTool(opts: CreateInteractiveShellToolOptions): CustomTool;
|
|
183
|
+
|
|
156
184
|
/**
|
|
157
185
|
* Composable command-permission policy layer (M3-6).
|
|
158
186
|
*
|
|
@@ -1003,4 +1031,4 @@ interface CreateWriteFileToolOptions {
|
|
|
1003
1031
|
}
|
|
1004
1032
|
declare function createWriteFileTool(opts: CreateWriteFileToolOptions): CustomTool;
|
|
1005
1033
|
|
|
1006
|
-
export { CatastrophicCommandError, type CommandPolicy, ContextMatchError, type ContextMatchReason, type CreateApplyPatchToolOptions, type CreateBraveWebSearchAdapterOptions, type CreateEditFileToolOptions, type CreateGenericHttpSearchAdapterOptions, type CreateGitDiffToolOptions, type CreateGlobToolOptions, type CreateListDirToolOptions, type CreateReadFileToolOptions, type CreateRunVitestToolOptions, type CreateSearchTextToolOptions, type CreateShellToolOptions, type CreateWebFetchToolOptions, type CreateWebSearchToolOptions, type CreateWriteFileToolOptions, DEFAULT_TOOL_GUIDANCE, type EnvContextOptions, type PlanModeTool, type PlanModeToolOptions, type PlanModeToolWithStore, type PlanNode, type QuestionTool, type QuestionToolOptions, ReadTracker, ReasoningTools, RedirectBlockedError, type RepoMapOptions, type ResolveAndScreenOptions, type ScreenedFetchOptions, type SessionArtifactStore, type SessionArtifactStoreOptions, SsrfBlockedError, type TodoItem, type TodolistTool, type ToolGuidanceMap, type TruncationOptions, type TruncationResult, type VitestSummary, type WebSearchCallback, type WebSearchResult, buildEnvContext, buildRepoMap, catastrophicShellReason, commandDenialReason, createApplyPatchTool, createBraveWebSearchAdapter, createEditFileTool, createGenericHttpSearchAdapter, createGitDiffTool, createGlobTool, createListDirTool, createPlanModeTool, createQuestionTool, createReadFileTool, createRunVitestTool, createSearchTextTool, createSessionArtifactStore, createShellTool, createTodolistTool, createWebFetchTool, createWebSearchTool, createWriteFileTool, denyCatastrophicCommands, formatCode, formatDiff, formatError, formatFileList, injectGuidance, isBlockedIp, isCommandAllowed, renderToolList, replaceUnique, resolveAndScreen, screenedFetch, todoItemsToPlanNodes, truncateOutput, withDefaultGuidance, withDescription, withName, withShellExitGuidance, withToolResultGuidance };
|
|
1034
|
+
export { CatastrophicCommandError, type CommandPolicy, ContextMatchError, type ContextMatchReason, type CreateApplyPatchToolOptions, type CreateBraveWebSearchAdapterOptions, type CreateEditFileToolOptions, type CreateGenericHttpSearchAdapterOptions, type CreateGitDiffToolOptions, type CreateGlobToolOptions, type CreateInteractiveShellToolOptions, type CreateListDirToolOptions, type CreateReadFileToolOptions, type CreateRunVitestToolOptions, type CreateSearchTextToolOptions, type CreateShellToolOptions, type CreateWebFetchToolOptions, type CreateWebSearchToolOptions, type CreateWriteFileToolOptions, DEFAULT_TOOL_GUIDANCE, type EnvContextOptions, type PlanModeTool, type PlanModeToolOptions, type PlanModeToolWithStore, type PlanNode, type QuestionTool, type QuestionToolOptions, ReadTracker, ReasoningTools, RedirectBlockedError, type RepoMapOptions, type ResolveAndScreenOptions, type ScreenedFetchOptions, type SessionArtifactStore, type SessionArtifactStoreOptions, SsrfBlockedError, type TodoItem, type TodolistTool, type ToolGuidanceMap, type TruncationOptions, type TruncationResult, type VitestSummary, type WebSearchCallback, type WebSearchResult, buildEnvContext, buildRepoMap, catastrophicShellReason, commandDenialReason, createApplyPatchTool, createBraveWebSearchAdapter, createEditFileTool, createGenericHttpSearchAdapter, createGitDiffTool, createGlobTool, createInteractiveShellTool, createListDirTool, createPlanModeTool, createQuestionTool, createReadFileTool, createRunVitestTool, createSearchTextTool, createSessionArtifactStore, createShellTool, createTodolistTool, createWebFetchTool, createWebSearchTool, createWriteFileTool, createWriteStdinTool, denyCatastrophicCommands, formatCode, formatDiff, formatError, formatFileList, injectGuidance, isBlockedIp, isCommandAllowed, renderToolList, replaceUnique, resolveAndScreen, screenedFetch, todoItemsToPlanNodes, truncateOutput, withDefaultGuidance, withDescription, withName, withShellExitGuidance, withToolResultGuidance };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CustomTool, ConfigurationError } from '@theokit/sdk';
|
|
2
|
+
import { InteractiveProvider } from '@theokit/sdk/interactive';
|
|
2
3
|
import { FilesystemProvider } from '@theokit/sdk/filesystem';
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -153,6 +154,33 @@ interface CreateGlobToolOptions {
|
|
|
153
154
|
}
|
|
154
155
|
declare function createGlobTool(opts: CreateGlobToolOptions): CustomTool;
|
|
155
156
|
|
|
157
|
+
/**
|
|
158
|
+
* `interactive_shell` + `write_stdin` — built-in tools for driving an interactive
|
|
159
|
+
* session (a REPL, `git rebase -i`, any command that PROMPTS for stdin).
|
|
160
|
+
*
|
|
161
|
+
* Surface-agnostic by construction: both tools depend on an INJECTED
|
|
162
|
+
* `InteractiveProvider` (`@theokit/sdk/interactive`) exactly as `read_file`
|
|
163
|
+
* depends on `FilesystemProvider`. The HOST supplies the backend — a local
|
|
164
|
+
* `@theokit/sdk-pty` (terminal), a container/E2B backend (cluster/web), or a
|
|
165
|
+
* Tauri backend (desktop) — so the SAME tool runs on every theokit surface with
|
|
166
|
+
* NO native dependency here. When no backend is injected (or it cannot allocate
|
|
167
|
+
* a session) the tool returns `{ ok: false, error: 'interactive_unavailable' }`
|
|
168
|
+
* and the agent falls back to non-interactive exec.
|
|
169
|
+
*
|
|
170
|
+
* Return shapes (always a JSON string):
|
|
171
|
+
* interactive_shell → `{ ok: true, session_id, output }` | `{ ok: false, error }`
|
|
172
|
+
* write_stdin → `{ ok: true, output, alive }` | `{ ok: false, error }`
|
|
173
|
+
*/
|
|
174
|
+
|
|
175
|
+
interface CreateInteractiveShellToolOptions {
|
|
176
|
+
/** The interactive backend, or a per-request resolver of one (injected — never a direct native dep). */
|
|
177
|
+
interactive: InteractiveProvider<unknown>;
|
|
178
|
+
}
|
|
179
|
+
/** Start an interactive session; returns a `session_id` to drive with `write_stdin`. */
|
|
180
|
+
declare function createInteractiveShellTool(opts: CreateInteractiveShellToolOptions): CustomTool;
|
|
181
|
+
/** Write to a live interactive session's stdin and read the output it produces. */
|
|
182
|
+
declare function createWriteStdinTool(opts: CreateInteractiveShellToolOptions): CustomTool;
|
|
183
|
+
|
|
156
184
|
/**
|
|
157
185
|
* Composable command-permission policy layer (M3-6).
|
|
158
186
|
*
|
|
@@ -1003,4 +1031,4 @@ interface CreateWriteFileToolOptions {
|
|
|
1003
1031
|
}
|
|
1004
1032
|
declare function createWriteFileTool(opts: CreateWriteFileToolOptions): CustomTool;
|
|
1005
1033
|
|
|
1006
|
-
export { CatastrophicCommandError, type CommandPolicy, ContextMatchError, type ContextMatchReason, type CreateApplyPatchToolOptions, type CreateBraveWebSearchAdapterOptions, type CreateEditFileToolOptions, type CreateGenericHttpSearchAdapterOptions, type CreateGitDiffToolOptions, type CreateGlobToolOptions, type CreateListDirToolOptions, type CreateReadFileToolOptions, type CreateRunVitestToolOptions, type CreateSearchTextToolOptions, type CreateShellToolOptions, type CreateWebFetchToolOptions, type CreateWebSearchToolOptions, type CreateWriteFileToolOptions, DEFAULT_TOOL_GUIDANCE, type EnvContextOptions, type PlanModeTool, type PlanModeToolOptions, type PlanModeToolWithStore, type PlanNode, type QuestionTool, type QuestionToolOptions, ReadTracker, ReasoningTools, RedirectBlockedError, type RepoMapOptions, type ResolveAndScreenOptions, type ScreenedFetchOptions, type SessionArtifactStore, type SessionArtifactStoreOptions, SsrfBlockedError, type TodoItem, type TodolistTool, type ToolGuidanceMap, type TruncationOptions, type TruncationResult, type VitestSummary, type WebSearchCallback, type WebSearchResult, buildEnvContext, buildRepoMap, catastrophicShellReason, commandDenialReason, createApplyPatchTool, createBraveWebSearchAdapter, createEditFileTool, createGenericHttpSearchAdapter, createGitDiffTool, createGlobTool, createListDirTool, createPlanModeTool, createQuestionTool, createReadFileTool, createRunVitestTool, createSearchTextTool, createSessionArtifactStore, createShellTool, createTodolistTool, createWebFetchTool, createWebSearchTool, createWriteFileTool, denyCatastrophicCommands, formatCode, formatDiff, formatError, formatFileList, injectGuidance, isBlockedIp, isCommandAllowed, renderToolList, replaceUnique, resolveAndScreen, screenedFetch, todoItemsToPlanNodes, truncateOutput, withDefaultGuidance, withDescription, withName, withShellExitGuidance, withToolResultGuidance };
|
|
1034
|
+
export { CatastrophicCommandError, type CommandPolicy, ContextMatchError, type ContextMatchReason, type CreateApplyPatchToolOptions, type CreateBraveWebSearchAdapterOptions, type CreateEditFileToolOptions, type CreateGenericHttpSearchAdapterOptions, type CreateGitDiffToolOptions, type CreateGlobToolOptions, type CreateInteractiveShellToolOptions, type CreateListDirToolOptions, type CreateReadFileToolOptions, type CreateRunVitestToolOptions, type CreateSearchTextToolOptions, type CreateShellToolOptions, type CreateWebFetchToolOptions, type CreateWebSearchToolOptions, type CreateWriteFileToolOptions, DEFAULT_TOOL_GUIDANCE, type EnvContextOptions, type PlanModeTool, type PlanModeToolOptions, type PlanModeToolWithStore, type PlanNode, type QuestionTool, type QuestionToolOptions, ReadTracker, ReasoningTools, RedirectBlockedError, type RepoMapOptions, type ResolveAndScreenOptions, type ScreenedFetchOptions, type SessionArtifactStore, type SessionArtifactStoreOptions, SsrfBlockedError, type TodoItem, type TodolistTool, type ToolGuidanceMap, type TruncationOptions, type TruncationResult, type VitestSummary, type WebSearchCallback, type WebSearchResult, buildEnvContext, buildRepoMap, catastrophicShellReason, commandDenialReason, createApplyPatchTool, createBraveWebSearchAdapter, createEditFileTool, createGenericHttpSearchAdapter, createGitDiffTool, createGlobTool, createInteractiveShellTool, createListDirTool, createPlanModeTool, createQuestionTool, createReadFileTool, createRunVitestTool, createSearchTextTool, createSessionArtifactStore, createShellTool, createTodolistTool, createWebFetchTool, createWebSearchTool, createWriteFileTool, createWriteStdinTool, denyCatastrophicCommands, formatCode, formatDiff, formatError, formatFileList, injectGuidance, isBlockedIp, isCommandAllowed, renderToolList, replaceUnique, resolveAndScreen, screenedFetch, todoItemsToPlanNodes, truncateOutput, withDefaultGuidance, withDescription, withName, withShellExitGuidance, withToolResultGuidance };
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { existsSync, statSync, mkdirSync, writeFileSync, realpathSync, readFileS
|
|
|
6
6
|
import { safeFilenameForId, safePathJoin as safePathJoin$1 } from '@theokit/sdk/path-safety';
|
|
7
7
|
import { replaceFileAtomic } from '@theokit/sdk/persistence';
|
|
8
8
|
import { spawn } from 'child_process';
|
|
9
|
+
import { resolveInteractive, InteractiveUnavailableError, NoSuchSessionError } from '@theokit/sdk/interactive';
|
|
9
10
|
import { lookup } from 'dns/promises';
|
|
10
11
|
import { isIP } from 'net';
|
|
11
12
|
import { resolveFilesystem, FileNotFoundError, FilesystemSecurityError, FilesystemReadOnlyError, StaleFileError, FilesystemError } from '@theokit/sdk/filesystem';
|
|
@@ -689,6 +690,60 @@ function globToRegex(pattern) {
|
|
|
689
690
|
}
|
|
690
691
|
return new RegExp(`^${regexStr}$`);
|
|
691
692
|
}
|
|
693
|
+
function toErrorJson(err) {
|
|
694
|
+
if (err instanceof InteractiveUnavailableError) {
|
|
695
|
+
return JSON.stringify({ ok: false, error: "interactive_unavailable" });
|
|
696
|
+
}
|
|
697
|
+
if (err instanceof NoSuchSessionError) {
|
|
698
|
+
return JSON.stringify({ ok: false, error: "no_such_session" });
|
|
699
|
+
}
|
|
700
|
+
throw err;
|
|
701
|
+
}
|
|
702
|
+
function createInteractiveShellTool(opts) {
|
|
703
|
+
const { interactive } = opts;
|
|
704
|
+
return Tool.create({
|
|
705
|
+
name: "interactive_shell",
|
|
706
|
+
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 }.",
|
|
707
|
+
inputSchema: z.object({
|
|
708
|
+
command: z.string().min(1).describe("Command to run interactively, e.g. 'python3' or 'bash -i'."),
|
|
709
|
+
yield_time_ms: z.number().int().positive().optional().describe("How long to wait for startup output before returning (clamped by the backend).")
|
|
710
|
+
}),
|
|
711
|
+
handler: async ({ command, yield_time_ms }, ctx) => {
|
|
712
|
+
try {
|
|
713
|
+
const backend = await resolveInteractive(interactive, ctx ?? {});
|
|
714
|
+
const { sessionId, output } = await backend.startInteractive(command, {
|
|
715
|
+
yieldMs: yield_time_ms
|
|
716
|
+
});
|
|
717
|
+
return JSON.stringify({ ok: true, session_id: sessionId, output });
|
|
718
|
+
} catch (err) {
|
|
719
|
+
return toErrorJson(err);
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
function createWriteStdinTool(opts) {
|
|
725
|
+
const { interactive } = opts;
|
|
726
|
+
return Tool.create({
|
|
727
|
+
name: "write_stdin",
|
|
728
|
+
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 }.",
|
|
729
|
+
inputSchema: z.object({
|
|
730
|
+
session_id: z.string().min(1).describe("The session_id returned by interactive_shell."),
|
|
731
|
+
input: z.string().describe("Text to write to stdin (add a trailing '\\n' to submit a line)."),
|
|
732
|
+
yield_time_ms: z.number().int().positive().optional().describe("How long to wait for output before returning (clamped by the backend).")
|
|
733
|
+
}),
|
|
734
|
+
handler: async ({ session_id, input, yield_time_ms }, ctx) => {
|
|
735
|
+
try {
|
|
736
|
+
const backend = await resolveInteractive(interactive, ctx ?? {});
|
|
737
|
+
const { output, alive } = await backend.writeStdin(session_id, input, {
|
|
738
|
+
yieldMs: yield_time_ms
|
|
739
|
+
});
|
|
740
|
+
return JSON.stringify({ ok: true, output, alive });
|
|
741
|
+
} catch (err) {
|
|
742
|
+
return toErrorJson(err);
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
});
|
|
746
|
+
}
|
|
692
747
|
var CatastrophicCommandError = class extends ConfigurationError {
|
|
693
748
|
name = "CatastrophicCommandError";
|
|
694
749
|
constructor(reason) {
|
|
@@ -2341,6 +2396,6 @@ async function isBinaryFile(absolutePath) {
|
|
|
2341
2396
|
}
|
|
2342
2397
|
}
|
|
2343
2398
|
|
|
2344
|
-
export { CatastrophicCommandError, ContextMatchError, DEFAULT_TOOL_GUIDANCE, ReadTracker, ReasoningTools, RedirectBlockedError, SsrfBlockedError, buildEnvContext, buildRepoMap, catastrophicShellReason, commandDenialReason, createApplyPatchTool, createBraveWebSearchAdapter, createEditFileTool, createGenericHttpSearchAdapter, createGitDiffTool, createGlobTool, createListDirTool, createPlanModeTool, createQuestionTool, createReadFileTool, createRunVitestTool, createSearchTextTool, createSessionArtifactStore, createShellTool, createTodolistTool, createWebFetchTool, createWebSearchTool, createWriteFileTool, denyCatastrophicCommands, formatCode, formatDiff, formatError, formatFileList, injectGuidance, isBlockedIp, isCommandAllowed, renderToolList, replaceUnique, resolveAndScreen, screenedFetch, todoItemsToPlanNodes, truncateOutput, withDefaultGuidance, withDescription, withName, withShellExitGuidance, withToolResultGuidance };
|
|
2399
|
+
export { CatastrophicCommandError, ContextMatchError, DEFAULT_TOOL_GUIDANCE, ReadTracker, ReasoningTools, RedirectBlockedError, SsrfBlockedError, buildEnvContext, buildRepoMap, catastrophicShellReason, commandDenialReason, createApplyPatchTool, createBraveWebSearchAdapter, createEditFileTool, createGenericHttpSearchAdapter, createGitDiffTool, createGlobTool, createInteractiveShellTool, createListDirTool, createPlanModeTool, createQuestionTool, createReadFileTool, createRunVitestTool, createSearchTextTool, createSessionArtifactStore, createShellTool, createTodolistTool, createWebFetchTool, createWebSearchTool, createWriteFileTool, createWriteStdinTool, denyCatastrophicCommands, formatCode, formatDiff, formatError, formatFileList, injectGuidance, isBlockedIp, isCommandAllowed, renderToolList, replaceUnique, resolveAndScreen, screenedFetch, todoItemsToPlanNodes, truncateOutput, withDefaultGuidance, withDescription, withName, withShellExitGuidance, withToolResultGuidance };
|
|
2345
2400
|
//# sourceMappingURL=index.js.map
|
|
2346
2401
|
//# sourceMappingURL=index.js.map
|