@puku-ai/sdk 2.0.2 → 2.0.3

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.
Files changed (44) hide show
  1. package/README.md +45 -0
  2. package/dist/helpers/beta/json-schema.d.mts +13 -3
  3. package/dist/helpers/beta/json-schema.d.ts.map +1 -1
  4. package/dist/helpers/beta/json-schema.js +10 -6
  5. package/dist/helpers/beta/json-schema.js.map +1 -1
  6. package/dist/helpers/beta/json-schema.mjs +10 -6
  7. package/dist/helpers/beta/json-schema.mjs.map +1 -1
  8. package/dist/internal/utils/promise.d.mts +11 -0
  9. package/dist/internal/utils/promise.d.ts.map +1 -0
  10. package/dist/internal/utils/promise.js +18 -0
  11. package/dist/internal/utils/promise.js.map +1 -0
  12. package/dist/internal/utils/promise.mjs +15 -0
  13. package/dist/internal/utils/promise.mjs.map +1 -0
  14. package/dist/lib/tools/BetaRunnableTool.d.mts +46 -1
  15. package/dist/lib/tools/BetaRunnableTool.d.ts.map +1 -1
  16. package/dist/lib/tools/BetaRunnableTool.js +26 -0
  17. package/dist/lib/tools/BetaRunnableTool.js.map +1 -1
  18. package/dist/lib/tools/BetaRunnableTool.mjs +24 -1
  19. package/dist/lib/tools/BetaRunnableTool.mjs.map +1 -1
  20. package/dist/tools/agent-toolset/fs-util.d.mts +50 -0
  21. package/dist/tools/agent-toolset/fs-util.d.ts.map +1 -0
  22. package/dist/tools/agent-toolset/fs-util.js +191 -0
  23. package/dist/tools/agent-toolset/fs-util.js.map +1 -0
  24. package/dist/tools/agent-toolset/fs-util.mjs +151 -0
  25. package/dist/tools/agent-toolset/fs-util.mjs.map +1 -0
  26. package/dist/tools/agent-toolset/node.browser.d.mts +51 -0
  27. package/dist/tools/agent-toolset/node.browser.d.ts.map +1 -0
  28. package/dist/tools/agent-toolset/node.browser.js +94 -0
  29. package/dist/tools/agent-toolset/node.browser.js.map +1 -0
  30. package/dist/tools/agent-toolset/node.browser.mjs +78 -0
  31. package/dist/tools/agent-toolset/node.browser.mjs.map +1 -0
  32. package/dist/tools/agent-toolset/node.d.mts +158 -0
  33. package/dist/tools/agent-toolset/node.d.ts.map +1 -0
  34. package/dist/tools/agent-toolset/node.js +814 -0
  35. package/dist/tools/agent-toolset/node.js.map +1 -0
  36. package/dist/tools/agent-toolset/node.mjs +765 -0
  37. package/dist/tools/agent-toolset/node.mjs.map +1 -0
  38. package/dist/tools/agent-toolset/skills.d.mts +75 -0
  39. package/dist/tools/agent-toolset/skills.d.ts.map +1 -0
  40. package/dist/tools/agent-toolset/skills.js +196 -0
  41. package/dist/tools/agent-toolset/skills.js.map +1 -0
  42. package/dist/tools/agent-toolset/skills.mjs +153 -0
  43. package/dist/tools/agent-toolset/skills.mjs.map +1 -0
  44. package/package.json +1 -1
@@ -0,0 +1,158 @@
1
+ /**
2
+ * Node implementation of the `agent_toolset_20260401` tools — `bash`, `read`,
3
+ * `write`, `edit`, `glob`, `grep` — plus the workdir/skills
4
+ * {@link AgentToolContext}.
5
+ *
6
+ * This mirrors `@anthropic-ai/sdk/tools/memory/node`: it is the explicit,
7
+ * Node-only entry point for these implementations. Importing it pulls in
8
+ * `node:child_process`, `node:fs`, etc., so it is kept separate from the rest of
9
+ * the SDK — depending on it is an opt-in.
10
+ *
11
+ * **Node 22+ is required** for this module: the `glob` tool uses the native
12
+ * `fs.glob`, added in Node 22. The rest of the SDK still supports Node 18+; only
13
+ * the agent toolset has this requirement.
14
+ *
15
+ * The result of {@link betaAgentToolset20260401} is a plain `BetaRunnableTool[]`;
16
+ * hand it to any tool runner — `client.beta.messages.toolRunner({ …, tools })`
17
+ * for the Messages API, or `client.beta.sessions.events.toolRunner({ …, tools })`
18
+ * for a managed-agents session:
19
+ *
20
+ * ```ts
21
+ * import { betaAgentToolset20260401 } from '@anthropic-ai/sdk/tools/agent-toolset/node';
22
+ *
23
+ * const tools = betaAgentToolset20260401({ workdir: '/work' });
24
+ * const tools2 = betaAgentToolset20260401({ workdir: '/work' }).filter((t) => t.name !== 'bash');
25
+ * ```
26
+ *
27
+ * Trust model: the file tools confine to `workdir` (symlink-aware) and are safe
28
+ * without a sandbox; `bash` is unrestricted and should run inside one. See
29
+ * {@link AgentToolContext}.
30
+ */
31
+ import type { PukuAI as Anthropic } from '../../client.js';
32
+ import { AnthropicError } from '../../core/error.js';
33
+ import type { BetaRunnableTool } from '../../lib/tools/BetaRunnableTool.js';
34
+ export { setupSkills, resolveSkillVersion, extractSkillArchive } from './skills.js';
35
+ /**
36
+ * A bash command exceeded its `timeoutMs`. Carries the timeout so a caller can
37
+ * tell it apart from an abort without matching on the message text.
38
+ */
39
+ export declare class BashTimeoutError extends AnthropicError {
40
+ readonly timeoutMs: number;
41
+ constructor(timeoutMs: number);
42
+ }
43
+ /**
44
+ * Workdir + path-policy for the agent toolset.
45
+ *
46
+ * Trust model — two tiers:
47
+ *
48
+ * - The file tools ({@link betaReadTool}, {@link betaWriteTool},
49
+ * {@link betaEditTool}, {@link betaGlobTool}, {@link betaGrepTool}) confine to
50
+ * `workdir` unless `unrestrictedPaths` is set. {@link resolvePath}
51
+ * canonicalizes the target (resolving every symlink, including the leaf)
52
+ * before the check *and* returns that canonical path for the operation, so a
53
+ * symlink inside the workdir that points outside it neither passes the check
54
+ * nor gets followed afterwards — this is a real boundary, not a lexical hint
55
+ * (modulo the residual TOCTOU noted on {@link resolvePath}).
56
+ * - {@link betaBashTool} runs an unrestricted `/bin/bash` and cannot be
57
+ * confined. Run it — and, for defense in depth, the whole toolset — inside a
58
+ * sandbox the host controls (e.g. a self-hosted environment runner).
59
+ */
60
+ export interface AgentToolContext {
61
+ /** Base directory for resolving relative tool paths. */
62
+ workdir: string;
63
+ /**
64
+ * When `false` (default), the file tools reject paths that resolve outside
65
+ * `workdir` (symlinks resolved). Does **not** constrain {@link betaBashTool}.
66
+ */
67
+ unrestrictedPaths?: boolean;
68
+ /**
69
+ * Anthropic client. Optional — the bare toolset needs no client; it is only
70
+ * used by `setupSkills`, which (together with {@link AgentToolContext.sessionId})
71
+ * fetches the session's resolved agent and downloads each of its skills into
72
+ * `{workdir}/skills/<name>/`.
73
+ */
74
+ client?: Anthropic;
75
+ /** Session whose agent's skills `setupSkills` should download. */
76
+ sessionId?: string;
77
+ /**
78
+ * Optional environment for the bash subprocess. When unset, the bash tool
79
+ * inherits the process environment with the runner's `ANTHROPIC_*`
80
+ * credentials scrubbed. When provided, it FULLY REPLACES that default
81
+ * environment — the mapping is used verbatim and is NOT merged with or added
82
+ * to the scrubbed process environment. To keep the defaults plus extra vars,
83
+ * build the combined mapping yourself before passing it.
84
+ */
85
+ env?: NodeJS.ProcessEnv;
86
+ /**
87
+ * Size cap for the `read` and `edit` tools, which both load the whole file into
88
+ * memory. `undefined` (default) uses the built-in 256 KiB cap; a positive number
89
+ * sets a custom cap; `null` disables the cap entirely. Disabling it reintroduces
90
+ * the OOM risk on a model-controlled path, so pass `null` only when the sandbox
91
+ * can absorb arbitrarily large files. The non-regular-file (FIFO/device) guard
92
+ * always applies regardless of this value.
93
+ */
94
+ maxFileBytes?: number | null;
95
+ }
96
+ /**
97
+ * Returns the `agent_toolset_20260401` implementations bound to `ctx`. The
98
+ * result is a plain array of `BetaRunnableTool`; filter or extend it before
99
+ * handing it to a tool runner:
100
+ *
101
+ * ```ts
102
+ * const tools = [...betaAgentToolset20260401(ctx), myCustomTool];
103
+ * const tools = betaAgentToolset20260401(ctx).filter((t) => t.name !== 'grep');
104
+ * ```
105
+ *
106
+ * Concurrency note: `client.beta.sessions.events.toolRunner` dispatches a
107
+ * session's tool calls serially (the sessions API delivers one `agent.tool_use`
108
+ * at a time). `client.beta.messages.toolRunner` runs a turn's `tool.run` calls
109
+ * via `Promise.all`. The toolset below is safe under either model —
110
+ * {@link betaBashTool} serializes its persistent shell internally and the FS
111
+ * tools are independent per call — but {@link betaEditTool}/{@link betaWriteTool}
112
+ * cannot synchronize concurrent writes to the *same* file across processes, so a
113
+ * multi-edit turn touching one path is still subject to inherent FS lost-update
114
+ * races. Custom tools that close over mutable state should do their own queueing.
115
+ */
116
+ export declare function betaAgentToolset20260401(ctx: AgentToolContext): BetaRunnableTool[];
117
+ /**
118
+ * Resolve `p` against `ctx.workdir`. Absolute and relative inputs go through
119
+ * the same canonicalise-then-contain check — an absolute path that lands inside
120
+ * the workdir is permitted, only paths that resolve *outside* are rejected.
121
+ * Every symlink in `p` (including the leaf, even a dangling one) is resolved
122
+ * before the workdir check, and the resolved path is what the tool then operates
123
+ * on, so a symlink inside the workdir that points outside it can neither pass
124
+ * the check nor be followed afterwards. See the trust model on
125
+ * {@link AgentToolContext}.
126
+ *
127
+ * Residual TOCTOU: a component could still be swapped for a symlink between this
128
+ * call and the eventual `fs` operation. Closing that fully needs per-component
129
+ * `O_NOFOLLOW`/`openat`, which Node does not expose ergonomically; the same
130
+ * residual exposure exists in `tools/memory/node` and is why a sandbox is still
131
+ * recommended for the toolset as a whole.
132
+ */
133
+ export declare function resolvePath(ctx: AgentToolContext, p: string): Promise<string>;
134
+ /**
135
+ * A persistent /bin/bash process. State (cwd, env, background jobs) survives
136
+ * across exec() calls. Uses pipes rather than a PTY so input is never echoed.
137
+ */
138
+ export declare class BashSession {
139
+ #private;
140
+ constructor(dir: string, env?: NodeJS.ProcessEnv);
141
+ /** Whether the underlying shell process has exited. */
142
+ get closed(): boolean;
143
+ exec(command: string, opts?: {
144
+ timeoutMs?: number;
145
+ signal?: AbortSignal | null | undefined;
146
+ }): Promise<{
147
+ output: string;
148
+ exitCode: number;
149
+ }>;
150
+ close(): void;
151
+ }
152
+ export declare function betaBashTool(ctx: AgentToolContext): BetaRunnableTool;
153
+ export declare function betaReadTool(ctx: AgentToolContext): BetaRunnableTool;
154
+ export declare function betaWriteTool(ctx: AgentToolContext): BetaRunnableTool;
155
+ export declare function betaEditTool(ctx: AgentToolContext): BetaRunnableTool;
156
+ export declare function betaGlobTool(ctx: AgentToolContext): BetaRunnableTool;
157
+ export declare function betaGrepTool(ctx: AgentToolContext): BetaRunnableTool;
158
+ //# sourceMappingUR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