toolpack-sdk 1.2.0 → 1.4.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Toolpack SDK
2
2
 
3
- A unified TypeScript/Node.js SDK for building AI-powered applications with multiple providers, 77 built-in tools, a workflow engine, and a flexible mode system — all through a single API.
3
+ A unified TypeScript/Node.js SDK for building AI-powered applications with multiple providers, 90 built-in tools, a workflow engine, and a flexible mode system — all through a single API.
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/toolpack-sdk.svg)](https://www.npmjs.com/package/toolpack-sdk)
6
6
  [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
@@ -16,8 +16,9 @@ A unified TypeScript/Node.js SDK for building AI-powered applications with multi
16
16
  - **Embeddings** — Vector generation for RAG applications (OpenAI, Gemini, Ollama)
17
17
  - **Workflow Engine** — AI-driven planning and step-by-step task execution with progress events
18
18
  - **Mode System** — Built-in Agent and Chat modes, plus `createMode()` for custom modes with tool filtering
19
+ - **HITL Confirmation** — Human-in-the-loop approval for high-risk operations with configurable bypass rules
19
20
  - **Custom Providers** — Bring your own provider by implementing the `ProviderAdapter` interface
20
- - **77 Built-in Tools** across 10 categories:
21
+ - **90 Built-in Tools** across 11 categories:
21
22
  - **MCP Tool Server Integration** — dynamically bridge external Model Context Protocol servers into Toolpack as first-class tools via `createMcpToolProject()` and `disconnectMcpToolProject()`.
22
23
 
23
24
  | Category | Tools | Description |
@@ -32,6 +33,8 @@ A unified TypeScript/Node.js SDK for building AI-powered applications with multi
32
33
  | **`system-tools`** | 5 | System info — env vars, cwd, disk usage, system info, set env |
33
34
  | **`diff-tools`** | 3 | Patch operations — create, apply, and preview diffs |
34
35
  | **`cloud-tools`** | 3 | Deployments — deploy, status, list (via Netlify) |
36
+ | **`k8s-tools`** | 11 | Kubernetes cluster inspection and management via kubectl |
37
+ | **`mcp-tools`** | 2 | MCP integration — createMcpToolProject, disconnectMcpToolProject |
35
38
 
36
39
  ## Quick Start
37
40
 
@@ -57,7 +60,7 @@ const sdk = await Toolpack.init({
57
60
  anthropic: {}, // Reads ANTHROPIC_API_KEY from env
58
61
  },
59
62
  defaultProvider: 'openai',
60
- tools: true, // Load all 77 built-in tools
63
+ tools: true, // Load all 90 built-in tools
61
64
  defaultMode: 'agent', // Agent mode with workflow engine
62
65
  });
63
66
 
@@ -89,6 +92,44 @@ const sdk = await Toolpack.init({
89
92
  });
90
93
  ```
91
94
 
95
+ ## Kubernetes Tools
96
+
97
+ Toolpack SDK now includes a dedicated Kubernetes tool category that exposes `kubectl`-backed operations when `tools: true` is enabled. Use these tools to inspect cluster state, fetch pod logs, apply manifests, and wait for rollout status.
98
+
99
+ ```typescript
100
+ const sdk = await Toolpack.init({
101
+ provider: 'openai',
102
+ tools: true,
103
+ defaultMode: 'agent',
104
+ });
105
+
106
+ const podsResponse = await sdk.generate({
107
+ model: 'gpt-4o',
108
+ messages: [
109
+ {
110
+ role: 'user',
111
+ content: 'List pods in the default namespace using Kubernetes tools.',
112
+ },
113
+ ],
114
+ });
115
+ console.log(podsResponse.content);
116
+
117
+ const applyResponse = await sdk.generate({
118
+ model: 'gpt-4o',
119
+ messages: [
120
+ {
121
+ role: 'user',
122
+ content: 'Apply the manifest at ./deploy/my-app.yaml to the staging namespace using Kubernetes tools.',
123
+ },
124
+ ],
125
+ });
126
+ console.log(applyResponse.content);
127
+ ```
128
+
129
+ > Requires `kubectl` installed and configured with a valid kubeconfig.
130
+
131
+ See `packages/toolpack-sdk/docs/examples/kubernetes-usage.ts` for a complete example.
132
+
92
133
  ## Providers
93
134
 
94
135
  ### Built-in Providers
@@ -229,13 +270,14 @@ const reasoningModels = allModels.filter(m => m.reasoningTier);
229
270
 
230
271
  ## Modes
231
272
 
232
- Modes control AI behavior by setting a system prompt, filtering available tools, and configuring the workflow engine. The SDK ships with two built-in modes and supports unlimited custom modes.
273
+ Modes control AI behavior by setting a system prompt, filtering available tools, and configuring the workflow engine. The SDK ships with three built-in modes and supports unlimited custom modes.
233
274
 
234
275
  ### Built-in Modes
235
276
 
236
277
  | Mode | Tools | Workflow | Description |
237
278
  |------|-------|----------|-------------|
238
279
  | **Agent** | All tools | Planning + step execution + dynamic steps | Full autonomous access — read, write, execute, browse |
280
+ | **Coding** | All tools | Concise planning + step execution | Optimized for coding tasks — minimal text, file operations |
239
281
  | **Chat** | Web/HTTP only | Direct execution (no planning) | Conversational assistant with web access |
240
282
 
241
283
  ### Custom Modes
@@ -402,11 +444,88 @@ interface WorkflowConfig {
402
444
  };
403
445
 
404
446
  onFailure?: {
405
- strategy: 'abort' | 'skip' | 'ask_user' | 'try_alternative';
447
+ strategy: 'abort' | 'skip' | 'ask_user';
406
448
  };
407
449
  }
408
450
  ```
409
451
 
452
+ ### Custom Workflow Presets
453
+
454
+ The SDK provides built-in workflow presets for common use cases:
455
+
456
+ ```typescript
457
+ import { DEFAULT_WORKFLOW, AGENT_WORKFLOW, CODING_WORKFLOW, CHAT_WORKFLOW } from 'toolpack-sdk';
458
+ ```
459
+
460
+ | Preset | Planning | Steps | Description |
461
+ |--------|----------|-------|-------------|
462
+ | `DEFAULT_WORKFLOW` | Disabled | Disabled | Direct execution, no planning |
463
+ | `AGENT_WORKFLOW` | Enabled (detailed) | Enabled | Full autonomous agent with 11 planning rules |
464
+ | `CODING_WORKFLOW` | Enabled (concise) | Enabled | Minimal prompts optimized for coding tasks |
465
+ | `CHAT_WORKFLOW` | Disabled | Disabled | Simple conversational mode |
466
+
467
+ ### Creating Custom Workflows
468
+
469
+ Define custom workflows by extending presets or creating from scratch:
470
+
471
+ ```typescript
472
+ import { WorkflowConfig, AGENT_WORKFLOW } from 'toolpack-sdk';
473
+
474
+ // Extend an existing preset
475
+ const DOC_WORKFLOW: WorkflowConfig = {
476
+ ...AGENT_WORKFLOW,
477
+ name: 'Documentation',
478
+ planning: {
479
+ enabled: true,
480
+ planningPrompt: `Create a documentation plan.
481
+
482
+ Rules:
483
+ 1. Read existing code files first
484
+ 2. Identify public APIs needing documentation
485
+ 3. Generate docs in consistent format
486
+ 4. Output JSON: {"summary": "...", "steps": [...]}`,
487
+ },
488
+ steps: {
489
+ ...AGENT_WORKFLOW.steps,
490
+ stepPrompt: `Execute step {stepNumber}: {stepDescription}
491
+
492
+ Analyze code and write clear documentation.
493
+ Focus on: purpose, parameters, return values, examples.
494
+
495
+ Previous: {previousStepsResults}`,
496
+ },
497
+ };
498
+
499
+ // Use in a custom mode
500
+ import { createMode } from 'toolpack-sdk';
501
+
502
+ const docMode = createMode({
503
+ name: 'docs',
504
+ displayName: 'Documentation',
505
+ systemPrompt: 'Documentation assistant. Generate clear API docs.',
506
+ workflow: DOC_WORKFLOW,
507
+ allowedToolCategories: ['filesystem', 'coding'],
508
+ });
509
+ ```
510
+
511
+ ### Step Prompt Template Variables
512
+
513
+ When using custom `stepPrompt`, these variables are automatically substituted:
514
+
515
+ | Variable | Description |
516
+ |----------|-------------|
517
+ | `{stepNumber}` | Current step number (1-indexed) |
518
+ | `{planSummary}` | Summary of the overall plan |
519
+ | `{stepDescription}` | Description of the current step |
520
+ | `{previousStepsResults}` | Output from completed steps (truncated to 2000 chars) |
521
+
522
+ ### Workflow Prompt Tips
523
+
524
+ - **Keep planning prompts concise** — LLMs perform better with 5-7 clear rules
525
+ - **Use JSON schema examples** — Include the exact expected output format
526
+ - **Avoid meta-commentary in step prompts** — The AI should just execute, not discuss
527
+ - **Leverage previous results** — The `{previousStepsResults}` variable provides context
528
+
410
529
  ## Tool Call Events
411
530
 
412
531
  The SDK emits events for tool execution, useful for building tool activity logs:
@@ -429,7 +548,7 @@ client.on('tool:failed', (event) => { /* ... */ });
429
548
 
430
549
  ## Custom Tools
431
550
 
432
- In addition to the 77 built-in tools, you can create and register your own custom tool projects using `createToolProject()`:
551
+ In addition to the 90 built-in tools, you can create and register your own custom tool projects using `createToolProject()`:
433
552
 
434
553
  ```typescript
435
554
  import { Toolpack, createToolProject } from 'toolpack-sdk';
@@ -485,6 +604,48 @@ const sdk = await Toolpack.init({
485
604
  | `tools` | ToolDefinition[] | ✓ | Array of tool definitions |
486
605
  | `dependencies` | Record<string, string> | | npm dependencies (validated at load) |
487
606
 
607
+ ## Knowledge & RAG (Retrieval-Augmented Generation)
608
+
609
+ For AI applications that need to search and reference documentation, use the companion `@toolpack-sdk/knowledge` package:
610
+
611
+ ```bash
612
+ npm install @toolpack-sdk/knowledge
613
+ ```
614
+
615
+ ### Quick Start
616
+
617
+ ```typescript
618
+ import { Knowledge, MemoryProvider, MarkdownSource, OllamaEmbedder } from '@toolpack-sdk/knowledge';
619
+ import { Toolpack } from 'toolpack-sdk';
620
+
621
+ // Create a knowledge base from markdown files
622
+ const kb = await Knowledge.create({
623
+ provider: new MemoryProvider(),
624
+ sources: [new MarkdownSource('./docs/**/*.md')],
625
+ embedder: new OllamaEmbedder({ model: 'nomic-embed-text' }),
626
+ description: 'Search this for setup and configuration questions.',
627
+ });
628
+
629
+ // Integrate with Toolpack SDK
630
+ const toolpack = await Toolpack.init({
631
+ provider: 'openai',
632
+ knowledge: kb, // Registered as knowledge_search tool
633
+ });
634
+
635
+ // The AI can now search your documentation
636
+ const response = await toolpack.chat('How do I configure authentication?');
637
+ ```
638
+
639
+ ### Features
640
+
641
+ - **Multiple Providers**: In-memory (`MemoryProvider`) or persistent SQLite (`PersistentKnowledgeProvider`)
642
+ - **Multiple Embedders**: OpenAI, Ollama (local), or custom embedders
643
+ - **Multiple Sources**: Markdown, JSON, SQLite ingestion
644
+ - **Progress Events**: Track embedding progress with `onEmbeddingProgress`
645
+ - **Metadata Filtering**: Query with filters like `{ hasCode: true, category: 'api' }`
646
+
647
+ See the [Knowledge package README](../toolpack-knowledge/README.md) for full documentation.
648
+
488
649
  ## Multimodal Support
489
650
 
490
651
  The SDK supports multimodal inputs (text + images) across all vision-capable providers. Images can be provided in three formats:
@@ -645,6 +806,49 @@ Create a `toolpack.config.json` in your project root:
645
806
  | `enabledTools` | string[] | `[]` | Whitelist specific tools (empty = all) |
646
807
  | `enabledToolCategories` | string[] | `[]` | Whitelist categories (empty = all) |
647
808
 
809
+ ### HITL (Human-in-the-Loop) Configuration
810
+
811
+ Configure user confirmation for high-risk tool operations:
812
+
813
+ ```json
814
+ {
815
+ "hitl": {
816
+ "enabled": true,
817
+ "confirmationMode": "all",
818
+ "bypass": {
819
+ "tools": ["fs.write_file"],
820
+ "categories": ["filesystem"],
821
+ "levels": ["medium"]
822
+ }
823
+ }
824
+ }
825
+ ```
826
+
827
+ | Option | Type | Default | Description |
828
+ |--------|------|---------|-------------|
829
+ | `enabled` | boolean | `true` | Master switch for HITL confirmation |
830
+ | `confirmationMode` | string | `"all"` | `"off"`, `"high-only"`, or `"all"` |
831
+ | `bypass.tools` | string[] | `[]` | Tool names to bypass (e.g., `["fs.write_file"]`) |
832
+ | `bypass.categories` | string[] | `[]` | Categories to bypass (e.g., `["filesystem"]`) |
833
+ | `bypass.levels` | string[] | `[]` | Risk levels to bypass (`["high"]` or `["medium"]`) |
834
+
835
+ **Programmatic API:**
836
+
837
+ ```typescript
838
+ import { addBypassRule, removeBypassRule } from 'toolpack-sdk';
839
+
840
+ // Add bypass rule
841
+ await addBypassRule({ type: 'tool', value: 'fs.delete_file' });
842
+
843
+ // Remove bypass rule
844
+ await removeBypassRule({ type: 'tool', value: 'fs.delete_file' });
845
+
846
+ // Reload config to apply changes
847
+ toolpack.reloadConfig();
848
+ ```
849
+
850
+ See the [HITL documentation](https://toolpacksdk.com/guides/hitl-confirmation) for detailed configuration options and best practices.
851
+
648
852
  #### Web Search Providers
649
853
 
650
854
  The `web.search` tool supports multiple search backends with automatic fallback:
@@ -807,7 +1011,7 @@ toolpack-sdk/
807
1011
  │ │ └── ollama/ # Ollama adapter + provider (auto-discovery)
808
1012
  │ ├── modes/ # Mode system (Agent, Chat, createMode)
809
1013
  │ ├── workflows/ # Workflow engine (planner, step executor, progress)
810
- │ ├── tools/ # 72 built-in tools + registry + router + BM25 search
1014
+ │ ├── tools/ # 90 built-in tools + registry + router + BM25 search
811
1015
  │ │ ├── fs-tools/ # File system (18 tools)
812
1016
  │ │ ├── coding-tools/ # Code analysis (12 tools)
813
1017
  │ │ ├── git-tools/ # Git operations (9 tools)
@@ -818,6 +1022,7 @@ toolpack-sdk/
818
1022
  │ │ ├── system-tools/ # System info (5 tools)
819
1023
  │ │ ├── diff-tools/ # Patch operations (3 tools)
820
1024
  │ │ ├── cloud-tools/ # Deployments (3 tools)
1025
+ │ │ ├── k8s-tools/ # Kubernetes management (11 tools)
821
1026
  │ │ ├── registry.ts # Tool registry and loading
822
1027
  │ │ ├── router.ts # Tool routing and filtering
823
1028
  │ │ └── search/ # BM25 tool discovery engine (internal)
@@ -833,9 +1038,9 @@ toolpack-sdk/
833
1038
  **Current Version:** 0.1.0
834
1039
 
835
1040
  - ✓ **4 Built-in Providers** — OpenAI, Anthropic, Gemini, Ollama (+ custom provider API)
836
- - ✓ **77 Built-in Tools** — fs, exec, git, diff, web, coding, db, cloud, http, system
1041
+ - ✓ **90 Built-in Tools** — fs, exec, git, diff, web, coding, db, cloud, http, system, Kubernetes
837
1042
  - ✓ **Workflow Engine** — AI-driven planning, step execution, retries, dynamic steps, progress events
838
- - ✓ **Mode System** — Agent, Chat, and custom modes via `createMode()` with `blockAllTools` support
1043
+ - ✓ **Mode System** — Agent, Coding, Chat, and custom modes via `createMode()` with `blockAllTools` support
839
1044
  - ✓ **Tool Search** — BM25-based on-demand tool discovery for large tool libraries
840
1045
  - ✓ **545 Tests** passing across 81 test files
841
1046