zilmate 1.7.2 → 1.7.6
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/.env.example +36 -36
- package/README.md +503 -503
- package/SDK.md +320 -320
- package/agent-docs.md +276 -276
- package/dist/agents/automation-planner.agent.d.ts.map +1 -1
- package/dist/agents/coding.agent.d.ts +18 -0
- package/dist/agents/coding.agent.d.ts.map +1 -1
- package/dist/agents/finance.agent.d.ts +60 -0
- package/dist/agents/finance.agent.d.ts.map +1 -0
- package/dist/agents/finance.agent.js +30 -0
- package/dist/agents/finance.agent.js.map +1 -0
- package/dist/agents/manager.d.ts +94 -1
- package/dist/agents/manager.d.ts.map +1 -1
- package/dist/agents/manager.js +102 -36
- package/dist/agents/manager.js.map +1 -1
- package/dist/agents/swarm/engineering/qa.d.ts +3 -0
- package/dist/agents/swarm/engineering/qa.d.ts.map +1 -0
- package/dist/agents/swarm/engineering/qa.js +19 -0
- package/dist/agents/swarm/engineering/qa.js.map +1 -0
- package/dist/agents/swarm/growth/seo.d.ts +3 -0
- package/dist/agents/swarm/growth/seo.d.ts.map +1 -0
- package/dist/agents/swarm/growth/seo.js +19 -0
- package/dist/agents/swarm/growth/seo.js.map +1 -0
- package/dist/agents/swarm/main.d.ts +22 -0
- package/dist/agents/swarm/main.d.ts.map +1 -0
- package/dist/agents/swarm/main.js +65 -0
- package/dist/agents/swarm/main.js.map +1 -0
- package/dist/agents/swarm/operations/finance.d.ts +3 -0
- package/dist/agents/swarm/operations/finance.d.ts.map +1 -0
- package/dist/agents/swarm/operations/finance.js +19 -0
- package/dist/agents/swarm/operations/finance.js.map +1 -0
- package/dist/agents/swarm/registry.d.ts +4 -0
- package/dist/agents/swarm/registry.d.ts.map +1 -0
- package/dist/agents/swarm/registry.js +361 -0
- package/dist/agents/swarm/registry.js.map +1 -0
- package/dist/cli/chat.d.ts +2 -0
- package/dist/cli/chat.d.ts.map +1 -0
- package/dist/cli/chat.js +61 -0
- package/dist/cli/chat.js.map +1 -0
- package/dist/cli/composer.d.ts.map +1 -1
- package/dist/cli/composer.js +54 -4
- package/dist/cli/composer.js.map +1 -1
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +13 -0
- package/dist/cli/doctor.js.map +1 -1
- package/dist/cli/format.d.ts.map +1 -1
- package/dist/cli/format.js +46 -53
- package/dist/cli/format.js.map +1 -1
- package/dist/cli/interactive.d.ts.map +1 -1
- package/dist/cli/interactive.js +51 -6
- package/dist/cli/interactive.js.map +1 -1
- package/dist/cli/models.d.ts +1 -1
- package/dist/cli/models.d.ts.map +1 -1
- package/dist/cli/models.js +21 -21
- package/dist/cli/models.js.map +1 -1
- package/dist/cli/prompt.d.ts +2 -2
- package/dist/cli/prompt.d.ts.map +1 -1
- package/dist/cli/prompt.js +58 -14
- package/dist/cli/prompt.js.map +1 -1
- package/dist/cli/render.d.ts.map +1 -1
- package/dist/cli/render.js +25 -17
- package/dist/cli/render.js.map +1 -1
- package/dist/cli/setup.d.ts +1 -0
- package/dist/cli/setup.d.ts.map +1 -1
- package/dist/cli/setup.js +74 -2
- package/dist/cli/setup.js.map +1 -1
- package/dist/cli/swarm.d.ts +4 -0
- package/dist/cli/swarm.d.ts.map +1 -0
- package/dist/cli/swarm.js +21 -0
- package/dist/cli/swarm.js.map +1 -0
- package/dist/cli/theme.d.ts +67 -1
- package/dist/cli/theme.d.ts.map +1 -1
- package/dist/cli/theme.js +66 -4
- package/dist/cli/theme.js.map +1 -1
- package/dist/cli/tunnel.d.ts.map +1 -1
- package/dist/cli/tunnel.js +2 -1
- package/dist/cli/tunnel.js.map +1 -1
- package/dist/cli/voice.js +11 -11
- package/dist/cli/welcome.d.ts.map +1 -1
- package/dist/cli/welcome.js +2 -0
- package/dist/cli/welcome.js.map +1 -1
- package/dist/config/model-store.d.ts +1 -1
- package/dist/config/model-store.d.ts.map +1 -1
- package/dist/config/model-store.js +14 -1
- package/dist/config/model-store.js.map +1 -1
- package/dist/config/models.d.ts +7 -0
- package/dist/config/models.d.ts.map +1 -1
- package/dist/config/models.js +30 -6
- package/dist/config/models.js.map +1 -1
- package/dist/documents/pdf.d.ts.map +1 -1
- package/dist/documents/pdf.js +143 -41
- package/dist/documents/pdf.js.map +1 -1
- package/dist/index.js +19 -1
- package/dist/index.js.map +1 -1
- package/dist/jobs/anomaly.js +5 -5
- package/dist/memory/heal.js +43 -43
- package/dist/observability/doctor.d.ts +3 -0
- package/dist/observability/doctor.d.ts.map +1 -0
- package/dist/observability/doctor.js +33 -0
- package/dist/observability/doctor.js.map +1 -0
- package/dist/observability/usage.d.ts +13 -0
- package/dist/observability/usage.d.ts.map +1 -0
- package/dist/observability/usage.js +34 -0
- package/dist/observability/usage.js.map +1 -0
- package/dist/runtime/chat-bridge.d.ts +32 -0
- package/dist/runtime/chat-bridge.d.ts.map +1 -0
- package/dist/runtime/chat-bridge.js +92 -0
- package/dist/runtime/chat-bridge.js.map +1 -0
- package/dist/runtime/confirm.d.ts.map +1 -1
- package/dist/runtime/confirm.js +12 -2
- package/dist/runtime/confirm.js.map +1 -1
- package/dist/runtime/progress.d.ts.map +1 -1
- package/dist/runtime/progress.js +3 -1
- package/dist/runtime/progress.js.map +1 -1
- package/dist/runtime/prompts/builder.d.ts +11 -0
- package/dist/runtime/prompts/builder.d.ts.map +1 -0
- package/dist/runtime/prompts/builder.js +29 -0
- package/dist/runtime/prompts/builder.js.map +1 -0
- package/dist/runtime/registry.d.ts +14 -0
- package/dist/runtime/registry.d.ts.map +1 -0
- package/dist/runtime/registry.js +39 -0
- package/dist/runtime/registry.js.map +1 -0
- package/dist/runtime/storage/interface.d.ts +16 -0
- package/dist/runtime/storage/interface.d.ts.map +1 -0
- package/dist/runtime/storage/interface.js +19 -0
- package/dist/runtime/storage/interface.js.map +1 -0
- package/dist/runtime/storage/local.d.ts +12 -0
- package/dist/runtime/storage/local.d.ts.map +1 -0
- package/dist/runtime/storage/local.js +48 -0
- package/dist/runtime/storage/local.js.map +1 -0
- package/dist/runtime/storage/redis.d.ts +11 -0
- package/dist/runtime/storage/redis.d.ts.map +1 -0
- package/dist/runtime/storage/redis.js +21 -0
- package/dist/runtime/storage/redis.js.map +1 -0
- package/dist/runtime/swarm/reports.d.ts +9 -0
- package/dist/runtime/swarm/reports.d.ts.map +1 -0
- package/dist/runtime/swarm/reports.js +43 -0
- package/dist/runtime/swarm/reports.js.map +1 -0
- package/dist/runtime/swarm.d.ts +38 -0
- package/dist/runtime/swarm.d.ts.map +1 -0
- package/dist/runtime/swarm.js +110 -0
- package/dist/runtime/swarm.js.map +1 -0
- package/dist/runtime/telemetry.d.ts +15 -0
- package/dist/runtime/telemetry.d.ts.map +1 -0
- package/dist/runtime/telemetry.js +25 -0
- package/dist/runtime/telemetry.js.map +1 -0
- package/dist/runtime/tool-utils.d.ts +12 -0
- package/dist/runtime/tool-utils.d.ts.map +1 -0
- package/dist/runtime/tool-utils.js +31 -0
- package/dist/runtime/tool-utils.js.map +1 -0
- package/dist/tools/browser.tool.d.ts +54 -0
- package/dist/tools/browser.tool.d.ts.map +1 -0
- package/dist/tools/browser.tool.js +193 -0
- package/dist/tools/browser.tool.js.map +1 -0
- package/dist/tools/business-apps.tool.d.ts +18 -0
- package/dist/tools/business-apps.tool.d.ts.map +1 -0
- package/dist/tools/business-apps.tool.js +43 -0
- package/dist/tools/business-apps.tool.js.map +1 -0
- package/dist/tools/computer-use.tool.js +66 -66
- package/dist/tools/cross-app-ledger.tool.d.ts +7 -0
- package/dist/tools/cross-app-ledger.tool.d.ts.map +1 -0
- package/dist/tools/cross-app-ledger.tool.js +70 -0
- package/dist/tools/cross-app-ledger.tool.js.map +1 -0
- package/dist/tools/daytona-browser.tool.d.ts +113 -0
- package/dist/tools/daytona-browser.tool.d.ts.map +1 -0
- package/dist/tools/daytona-browser.tool.js +348 -0
- package/dist/tools/daytona-browser.tool.js.map +1 -0
- package/dist/tools/desktop.tool.js +10 -10
- package/dist/tools/documents.tool.js +5 -5
- package/dist/tools/finance.tool.d.ts +18 -0
- package/dist/tools/finance.tool.d.ts.map +1 -0
- package/dist/tools/finance.tool.js +88 -0
- package/dist/tools/finance.tool.js.map +1 -0
- package/dist/tools/image-intelligence.tool.d.ts +12 -0
- package/dist/tools/image-intelligence.tool.d.ts.map +1 -0
- package/dist/tools/image-intelligence.tool.js +62 -0
- package/dist/tools/image-intelligence.tool.js.map +1 -0
- package/dist/tools/notify.tool.js +8 -8
- package/dist/tools/osint-install.tool.js +8 -8
- package/dist/tools/pentest-install.tool.js +6 -6
- package/dist/tools/setup-assistant.tool.d.ts +1 -1
- package/dist/tools/shell.tool.d.ts +18 -0
- package/dist/tools/shell.tool.d.ts.map +1 -1
- package/dist/tools/shell.tool.js +34 -0
- package/dist/tools/shell.tool.js.map +1 -1
- package/dist/tools/swarm-collaboration.tool.d.ts +29 -0
- package/dist/tools/swarm-collaboration.tool.d.ts.map +1 -0
- package/dist/tools/swarm-collaboration.tool.js +88 -0
- package/dist/tools/swarm-collaboration.tool.js.map +1 -0
- package/dist/tools/swarm-memory.tool.d.ts +16 -0
- package/dist/tools/swarm-memory.tool.d.ts.map +1 -0
- package/dist/tools/swarm-memory.tool.js +31 -0
- package/dist/tools/swarm-memory.tool.js.map +1 -0
- package/dist/tools/swarm-ops.tool.d.ts +20 -0
- package/dist/tools/swarm-ops.tool.d.ts.map +1 -0
- package/dist/tools/swarm-ops.tool.js +55 -0
- package/dist/tools/swarm-ops.tool.js.map +1 -0
- package/dist/tools/triggers.tool.d.ts.map +1 -1
- package/dist/tools/visual-audit.tool.d.ts +24 -0
- package/dist/tools/visual-audit.tool.d.ts.map +1 -0
- package/dist/tools/visual-audit.tool.js +48 -0
- package/dist/tools/visual-audit.tool.js.map +1 -0
- package/dist/tools/web-intelligence.tool.d.ts +12 -0
- package/dist/tools/web-intelligence.tool.d.ts.map +1 -0
- package/dist/tools/web-intelligence.tool.js +27 -0
- package/dist/tools/web-intelligence.tool.js.map +1 -0
- package/dist/workspace/init.js +18 -18
- package/dist/workspace/output-paths.d.ts +1 -1
- package/dist/workspace/output-paths.d.ts.map +1 -1
- package/dist/workspace/output-paths.js +1 -0
- package/dist/workspace/output-paths.js.map +1 -1
- package/dist/workspace/paths.d.ts +1 -0
- package/dist/workspace/paths.d.ts.map +1 -1
- package/dist/workspace/paths.js +1 -0
- package/dist/workspace/paths.js.map +1 -1
- package/install.ps1 +62 -62
- package/package.json +107 -103
- package/scripts/postinstall.mjs +42 -42
- package/scripts/release-github.mjs +91 -91
- package/src/doc/README.md +49 -49
- package/src/doc/admin-tools-and-sms-campaigns.md +99 -99
- package/src/doc/escalation-checklist.md +97 -97
- package/src/doc/payments-and-payouts.md +82 -82
- package/src/doc/shift-lifecycle-and-disputes.md +95 -95
- package/src/doc/support-macros.md +40 -40
- package/src/doc/venue-support-playbook.md +145 -145
- package/src/doc/verification-and-trust.md +88 -88
- package/src/doc/worker-support-playbook.md +159 -159
package/SDK.md
CHANGED
|
@@ -1,320 +1,320 @@
|
|
|
1
|
-
# ZilMate SDK
|
|
2
|
-
|
|
3
|
-
Use ZilMate as a programmable agent layer in Next.js, server routes, background workers, and automation scripts. The SDK wraps the same manager, subagents, memory, jobs, and voice stack as the CLI.
|
|
4
|
-
|
|
5
|
-
## Install
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install zilmate
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
Set environment variables (see `.env.example`):
|
|
12
|
-
|
|
13
|
-
```env
|
|
14
|
-
AI_GATEWAY_API_KEY=...
|
|
15
|
-
ZILMATE_USER_ID=zilmate-your-id
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
Optional: `COMPOSIO_API_KEY`, `TAVILY_API_KEY`, Upstash Redis/QStash, `DEEPGRAM_API_KEY`.
|
|
19
|
-
|
|
20
|
-
## Quick start (Node / Next.js server)
|
|
21
|
-
|
|
22
|
-
```ts
|
|
23
|
-
import { createZilMate } from 'zilmate/server';
|
|
24
|
-
|
|
25
|
-
const zilmate = createZilMate({
|
|
26
|
-
sessionId: 'dashboard-user-123',
|
|
27
|
-
onProgress: (event) => console.log(event.type, event.label),
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const { text } = await zilmate.manager({ message: 'Summarize my open jobs and suggest next steps.' });
|
|
31
|
-
console.log(text);
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
## Next.js App Router — streaming chat route
|
|
35
|
-
|
|
36
|
-
Create `app/api/zilmate/route.ts`:
|
|
37
|
-
|
|
38
|
-
```ts
|
|
39
|
-
import { createZilMate } from 'zilmate/server';
|
|
40
|
-
|
|
41
|
-
export const runtime = 'nodejs';
|
|
42
|
-
export const maxDuration = 120;
|
|
43
|
-
|
|
44
|
-
export async function POST(request: Request) {
|
|
45
|
-
const { message, sessionId = 'web-default' } = await request.json();
|
|
46
|
-
|
|
47
|
-
const encoder = new TextEncoder();
|
|
48
|
-
const stream = new ReadableStream({
|
|
49
|
-
async start(controller) {
|
|
50
|
-
const send = (payload: unknown) => {
|
|
51
|
-
controller.enqueue(encoder.encode(`${JSON.stringify(payload)}\n`));
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const zilmate = createZilMate({
|
|
55
|
-
sessionId,
|
|
56
|
-
onProgress: (event) => send({ type: 'progress', event }),
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
const { text } = await zilmate.manager({ message });
|
|
61
|
-
send({ type: 'done', text });
|
|
62
|
-
} catch (error) {
|
|
63
|
-
send({
|
|
64
|
-
type: 'error',
|
|
65
|
-
message: error instanceof Error ? error.message : String(error),
|
|
66
|
-
});
|
|
67
|
-
} finally {
|
|
68
|
-
controller.close();
|
|
69
|
-
}
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
return new Response(stream, {
|
|
74
|
-
headers: {
|
|
75
|
-
'Content-Type': 'application/x-ndjson',
|
|
76
|
-
'Cache-Control': 'no-cache',
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
Client hook (React):
|
|
83
|
-
|
|
84
|
-
```tsx
|
|
85
|
-
'use client';
|
|
86
|
-
|
|
87
|
-
import { useState } from 'react';
|
|
88
|
-
|
|
89
|
-
export function ZilMateChat() {
|
|
90
|
-
const [input, setInput] = useState('');
|
|
91
|
-
const [reply, setReply] = useState('');
|
|
92
|
-
const [progress, setProgress] = useState<string[]>([]);
|
|
93
|
-
|
|
94
|
-
async function send() {
|
|
95
|
-
setProgress([]);
|
|
96
|
-
const res = await fetch('/api/zilmate', {
|
|
97
|
-
method: 'POST',
|
|
98
|
-
headers: { 'Content-Type': 'application/json' },
|
|
99
|
-
body: JSON.stringify({ message: input, sessionId: 'web-1' }),
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
const reader = res.body!.getReader();
|
|
103
|
-
const decoder = new TextDecoder();
|
|
104
|
-
let buffer = '';
|
|
105
|
-
|
|
106
|
-
while (true) {
|
|
107
|
-
const { done, value } = await reader.read();
|
|
108
|
-
if (done) break;
|
|
109
|
-
buffer += decoder.decode(value, { stream: true });
|
|
110
|
-
const lines = buffer.split('\n');
|
|
111
|
-
buffer = lines.pop() ?? '';
|
|
112
|
-
for (const line of lines) {
|
|
113
|
-
if (!line.trim()) continue;
|
|
114
|
-
const chunk = JSON.parse(line);
|
|
115
|
-
if (chunk.type === 'progress') setProgress((p) => [...p, chunk.event.label]);
|
|
116
|
-
if (chunk.type === 'done') setReply(chunk.text);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return (
|
|
122
|
-
<div>
|
|
123
|
-
<textarea value={input} onChange={(e) => setInput(e.target.value)} />
|
|
124
|
-
<button onClick={send}>Ask ZilMate</button>
|
|
125
|
-
<ul>{progress.map((p) => <li key={p}>{p}</li>)}</ul>
|
|
126
|
-
<pre>{reply}</pre>
|
|
127
|
-
</div>
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
## Subagents
|
|
133
|
-
|
|
134
|
-
The manager orchestrates specialized subagents. Call them directly when you do not need full orchestration.
|
|
135
|
-
|
|
136
|
-
| Method | Agent | Best for |
|
|
137
|
-
|--------|-------|----------|
|
|
138
|
-
| `manager()` | Main orchestrator | General tasks, routing, tools, memory |
|
|
139
|
-
| `coding()` | Coding agent + appBuilder + qaIntegration | Repo edits, builds, tests, patches |
|
|
140
|
-
| `imageAgent()` | Image director | Prompt refinement + generation/editing |
|
|
141
|
-
| `goalManager()` | Goal planner | Break goals into steps and schedules |
|
|
142
|
-
| `research()` | Docs/web research | Sourced answers |
|
|
143
|
-
| `help()` | Quick help | Usage and troubleshooting |
|
|
144
|
-
| `post()` | Copywriter | Short social/status posts |
|
|
145
|
-
|
|
146
|
-
### Coding agent with sub-coders
|
|
147
|
-
|
|
148
|
-
```ts
|
|
149
|
-
const zilmate = createZilMate({ sessionId: 'repo-session' });
|
|
150
|
-
|
|
151
|
-
const { text } = await zilmate.coding({
|
|
152
|
-
prompt: [
|
|
153
|
-
'In this Next.js repo:',
|
|
154
|
-
'1) Add a /api/health route',
|
|
155
|
-
'2) Run typecheck',
|
|
156
|
-
'3) Return files changed and test output',
|
|
157
|
-
].join('\n'),
|
|
158
|
-
});
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
Internally, the coding agent can delegate to:
|
|
162
|
-
|
|
163
|
-
- **appBuilder** — full app/game/UI implementation
|
|
164
|
-
- **qaIntegration** — tests, build fixes, release checks
|
|
165
|
-
|
|
166
|
-
It also uses **code intelligence tools**: `grepCodebase`, `reviewWorkingTree`, `explainSymbol`, `scaffoldFiles`, `runProjectChecks`.
|
|
167
|
-
|
|
168
|
-
### Image director
|
|
169
|
-
|
|
170
|
-
```ts
|
|
171
|
-
const { text } = await zilmate.imageAgent({
|
|
172
|
-
prompt: 'Product hero image: dark SaaS dashboard on laptop, cyan accent, no text gibberish, 16:9',
|
|
173
|
-
});
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
The image agent runs `enhanceImagePrompt` then `generateImage` for precise visuals.
|
|
177
|
-
|
|
178
|
-
## Agentic features (10x differentiators)
|
|
179
|
-
|
|
180
|
-
### 1. Situational awareness
|
|
181
|
-
|
|
182
|
-
Before major work, the manager can call `getSituationBrief` (cwd, git, workspace, models, jobs, memory, projects). Use directly:
|
|
183
|
-
|
|
184
|
-
```ts
|
|
185
|
-
const brief = await zilmate.situation({ sessionId: 'default' });
|
|
186
|
-
console.log(brief.git, brief.recentJobs, brief.models);
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
### 2. Session continuity (handoffs)
|
|
190
|
-
|
|
191
|
-
Resume work across sessions:
|
|
192
|
-
|
|
193
|
-
```ts
|
|
194
|
-
const handoff = await zilmate.handoff({ sessionId: 'default' });
|
|
195
|
-
if (handoff) {
|
|
196
|
-
await zilmate.manager({
|
|
197
|
-
message: `Continue from handoff:\n${handoff.summary}\nNext: ${handoff.nextActions.join(', ')}`,
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
The manager can also call `generateSessionHandoff` / `saveSessionHandoff` before ending a long task.
|
|
203
|
-
|
|
204
|
-
## Model selection
|
|
205
|
-
|
|
206
|
-
CLI users run `/model pick`. In code, persist selections to the workspace:
|
|
207
|
-
|
|
208
|
-
```ts
|
|
209
|
-
import { applyStoredModelSelections, saveModelSelection } from 'zilmate/server';
|
|
210
|
-
|
|
211
|
-
await applyStoredModelSelections();
|
|
212
|
-
await saveModelSelection('manager', 'anthropic/claude-sonnet-4');
|
|
213
|
-
await saveModelSelection('coding', 'openai/gpt-5.4-mini');
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
Models are stored in `~/Downloads/ZilMate/config/models.json` (or `ZILMATE_WORKSPACE`).
|
|
217
|
-
|
|
218
|
-
## Memory
|
|
219
|
-
|
|
220
|
-
```ts
|
|
221
|
-
await zilmate.remember({ text: 'User prefers pnpm and App Router', tags: ['prefs'] });
|
|
222
|
-
const hits = await zilmate.recall({ query: 'package manager', limit: 5 });
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
## Background jobs
|
|
226
|
-
|
|
227
|
-
```ts
|
|
228
|
-
const job = await zilmate.createJob({
|
|
229
|
-
task: 'Weekly summary of GitHub PRs',
|
|
230
|
-
schedule: '0 9 * * 1',
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
await zilmate.runDueJobs();
|
|
234
|
-
const logs = await zilmate.getJobLogs(job.id);
|
|
235
|
-
```
|
|
236
|
-
|
|
237
|
-
Expose webhooks for QStash:
|
|
238
|
-
|
|
239
|
-
```ts
|
|
240
|
-
// app/api/jobs/webhook/route.ts
|
|
241
|
-
import { createZilMate } from 'zilmate/server';
|
|
242
|
-
|
|
243
|
-
export async function POST(req: Request) {
|
|
244
|
-
const body = await req.json();
|
|
245
|
-
const zilmate = createZilMate();
|
|
246
|
-
const job = await zilmate.handleJobWebhook(body, process.env.ZILMATE_JOB_WEBHOOK_SECRET);
|
|
247
|
-
return Response.json({ ok: true, jobId: job.id });
|
|
248
|
-
}
|
|
249
|
-
```
|
|
250
|
-
|
|
251
|
-
Use `zilmate jobs listen --tunnel` (Cloudflare quick tunnel) during local development.
|
|
252
|
-
|
|
253
|
-
## Voice (Deepgram)
|
|
254
|
-
|
|
255
|
-
```ts
|
|
256
|
-
const session = await zilmate.startVoiceSession({
|
|
257
|
-
onProgress: (e) => console.log(e.label),
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
// session exposes Deepgram agent wiring — see src/voice/deepgram.ts
|
|
261
|
-
console.log(session.config.listenModel);
|
|
262
|
-
await session.close?.();
|
|
263
|
-
```
|
|
264
|
-
|
|
265
|
-
## Confirmation in server contexts
|
|
266
|
-
|
|
267
|
-
Destructive tools require explicit approval. Provide a handler:
|
|
268
|
-
|
|
269
|
-
```ts
|
|
270
|
-
import type { ConfirmationHandler } from 'zilmate/server';
|
|
271
|
-
|
|
272
|
-
const confirm: ConfirmationHandler = async (request) => {
|
|
273
|
-
// In a web app, push to UI and await user click
|
|
274
|
-
console.log('Approve?', request.message);
|
|
275
|
-
return true;
|
|
276
|
-
};
|
|
277
|
-
|
|
278
|
-
const zilmate = createZilMate({ confirm });
|
|
279
|
-
```
|
|
280
|
-
|
|
281
|
-
## Exports reference
|
|
282
|
-
|
|
283
|
-
```ts
|
|
284
|
-
import {
|
|
285
|
-
createZilMate,
|
|
286
|
-
chat,
|
|
287
|
-
help,
|
|
288
|
-
post,
|
|
289
|
-
research,
|
|
290
|
-
image,
|
|
291
|
-
applyStoredModelSelections,
|
|
292
|
-
buildSituationBrief,
|
|
293
|
-
loadSessionHandoff,
|
|
294
|
-
clearSessionApprovals,
|
|
295
|
-
} from 'zilmate/server';
|
|
296
|
-
```
|
|
297
|
-
|
|
298
|
-
## CLI parity
|
|
299
|
-
|
|
300
|
-
| CLI | SDK |
|
|
301
|
-
|-----|-----|
|
|
302
|
-
| `zilmate talk` | `createZilMate().manager()` |
|
|
303
|
-
| `zilmate coding "..."` | `createZilMate().coding()` |
|
|
304
|
-
| `zilmate heal` | manager + heal tools (via manager) |
|
|
305
|
-
| `zilmate jobs worker` | `runDueJobs()` + worker process |
|
|
306
|
-
| `/model pick` | `saveModelSelection()` |
|
|
307
|
-
|
|
308
|
-
## Production checklist
|
|
309
|
-
|
|
310
|
-
1. Run `zilmate setup` once per environment (merge-safe).
|
|
311
|
-
2. Set `ZILMATE_WORKSPACE` for durable notebook/knowledge/skills.
|
|
312
|
-
3. Enable Redis for multi-instance memory and jobs.
|
|
313
|
-
4. Use QStash + Cloudflare tunnel for hosted schedules.
|
|
314
|
-
5. Never expose `AI_GATEWAY_API_KEY` to the browser — keep SDK calls on the server.
|
|
315
|
-
|
|
316
|
-
## Learn more
|
|
317
|
-
|
|
318
|
-
- Repository: https://github.com/zester4/zilo-manager
|
|
319
|
-
- Agent skill: `plugins/zilmate/skills/zilmate/SKILL.md`
|
|
320
|
-
- AI SDK patterns: https://sdk.vercel.ai/docs
|
|
1
|
+
# ZilMate SDK
|
|
2
|
+
|
|
3
|
+
Use ZilMate as a programmable agent layer in Next.js, server routes, background workers, and automation scripts. The SDK wraps the same manager, subagents, memory, jobs, and voice stack as the CLI.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install zilmate
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Set environment variables (see `.env.example`):
|
|
12
|
+
|
|
13
|
+
```env
|
|
14
|
+
AI_GATEWAY_API_KEY=...
|
|
15
|
+
ZILMATE_USER_ID=zilmate-your-id
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Optional: `COMPOSIO_API_KEY`, `TAVILY_API_KEY`, Upstash Redis/QStash, `DEEPGRAM_API_KEY`.
|
|
19
|
+
|
|
20
|
+
## Quick start (Node / Next.js server)
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { createZilMate } from 'zilmate/server';
|
|
24
|
+
|
|
25
|
+
const zilmate = createZilMate({
|
|
26
|
+
sessionId: 'dashboard-user-123',
|
|
27
|
+
onProgress: (event) => console.log(event.type, event.label),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const { text } = await zilmate.manager({ message: 'Summarize my open jobs and suggest next steps.' });
|
|
31
|
+
console.log(text);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Next.js App Router — streaming chat route
|
|
35
|
+
|
|
36
|
+
Create `app/api/zilmate/route.ts`:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { createZilMate } from 'zilmate/server';
|
|
40
|
+
|
|
41
|
+
export const runtime = 'nodejs';
|
|
42
|
+
export const maxDuration = 120;
|
|
43
|
+
|
|
44
|
+
export async function POST(request: Request) {
|
|
45
|
+
const { message, sessionId = 'web-default' } = await request.json();
|
|
46
|
+
|
|
47
|
+
const encoder = new TextEncoder();
|
|
48
|
+
const stream = new ReadableStream({
|
|
49
|
+
async start(controller) {
|
|
50
|
+
const send = (payload: unknown) => {
|
|
51
|
+
controller.enqueue(encoder.encode(`${JSON.stringify(payload)}\n`));
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const zilmate = createZilMate({
|
|
55
|
+
sessionId,
|
|
56
|
+
onProgress: (event) => send({ type: 'progress', event }),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
const { text } = await zilmate.manager({ message });
|
|
61
|
+
send({ type: 'done', text });
|
|
62
|
+
} catch (error) {
|
|
63
|
+
send({
|
|
64
|
+
type: 'error',
|
|
65
|
+
message: error instanceof Error ? error.message : String(error),
|
|
66
|
+
});
|
|
67
|
+
} finally {
|
|
68
|
+
controller.close();
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
return new Response(stream, {
|
|
74
|
+
headers: {
|
|
75
|
+
'Content-Type': 'application/x-ndjson',
|
|
76
|
+
'Cache-Control': 'no-cache',
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Client hook (React):
|
|
83
|
+
|
|
84
|
+
```tsx
|
|
85
|
+
'use client';
|
|
86
|
+
|
|
87
|
+
import { useState } from 'react';
|
|
88
|
+
|
|
89
|
+
export function ZilMateChat() {
|
|
90
|
+
const [input, setInput] = useState('');
|
|
91
|
+
const [reply, setReply] = useState('');
|
|
92
|
+
const [progress, setProgress] = useState<string[]>([]);
|
|
93
|
+
|
|
94
|
+
async function send() {
|
|
95
|
+
setProgress([]);
|
|
96
|
+
const res = await fetch('/api/zilmate', {
|
|
97
|
+
method: 'POST',
|
|
98
|
+
headers: { 'Content-Type': 'application/json' },
|
|
99
|
+
body: JSON.stringify({ message: input, sessionId: 'web-1' }),
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const reader = res.body!.getReader();
|
|
103
|
+
const decoder = new TextDecoder();
|
|
104
|
+
let buffer = '';
|
|
105
|
+
|
|
106
|
+
while (true) {
|
|
107
|
+
const { done, value } = await reader.read();
|
|
108
|
+
if (done) break;
|
|
109
|
+
buffer += decoder.decode(value, { stream: true });
|
|
110
|
+
const lines = buffer.split('\n');
|
|
111
|
+
buffer = lines.pop() ?? '';
|
|
112
|
+
for (const line of lines) {
|
|
113
|
+
if (!line.trim()) continue;
|
|
114
|
+
const chunk = JSON.parse(line);
|
|
115
|
+
if (chunk.type === 'progress') setProgress((p) => [...p, chunk.event.label]);
|
|
116
|
+
if (chunk.type === 'done') setReply(chunk.text);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return (
|
|
122
|
+
<div>
|
|
123
|
+
<textarea value={input} onChange={(e) => setInput(e.target.value)} />
|
|
124
|
+
<button onClick={send}>Ask ZilMate</button>
|
|
125
|
+
<ul>{progress.map((p) => <li key={p}>{p}</li>)}</ul>
|
|
126
|
+
<pre>{reply}</pre>
|
|
127
|
+
</div>
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Subagents
|
|
133
|
+
|
|
134
|
+
The manager orchestrates specialized subagents. Call them directly when you do not need full orchestration.
|
|
135
|
+
|
|
136
|
+
| Method | Agent | Best for |
|
|
137
|
+
|--------|-------|----------|
|
|
138
|
+
| `manager()` | Main orchestrator | General tasks, routing, tools, memory |
|
|
139
|
+
| `coding()` | Coding agent + appBuilder + qaIntegration | Repo edits, builds, tests, patches |
|
|
140
|
+
| `imageAgent()` | Image director | Prompt refinement + generation/editing |
|
|
141
|
+
| `goalManager()` | Goal planner | Break goals into steps and schedules |
|
|
142
|
+
| `research()` | Docs/web research | Sourced answers |
|
|
143
|
+
| `help()` | Quick help | Usage and troubleshooting |
|
|
144
|
+
| `post()` | Copywriter | Short social/status posts |
|
|
145
|
+
|
|
146
|
+
### Coding agent with sub-coders
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
const zilmate = createZilMate({ sessionId: 'repo-session' });
|
|
150
|
+
|
|
151
|
+
const { text } = await zilmate.coding({
|
|
152
|
+
prompt: [
|
|
153
|
+
'In this Next.js repo:',
|
|
154
|
+
'1) Add a /api/health route',
|
|
155
|
+
'2) Run typecheck',
|
|
156
|
+
'3) Return files changed and test output',
|
|
157
|
+
].join('\n'),
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Internally, the coding agent can delegate to:
|
|
162
|
+
|
|
163
|
+
- **appBuilder** — full app/game/UI implementation
|
|
164
|
+
- **qaIntegration** — tests, build fixes, release checks
|
|
165
|
+
|
|
166
|
+
It also uses **code intelligence tools**: `grepCodebase`, `reviewWorkingTree`, `explainSymbol`, `scaffoldFiles`, `runProjectChecks`.
|
|
167
|
+
|
|
168
|
+
### Image director
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
const { text } = await zilmate.imageAgent({
|
|
172
|
+
prompt: 'Product hero image: dark SaaS dashboard on laptop, cyan accent, no text gibberish, 16:9',
|
|
173
|
+
});
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
The image agent runs `enhanceImagePrompt` then `generateImage` for precise visuals.
|
|
177
|
+
|
|
178
|
+
## Agentic features (10x differentiators)
|
|
179
|
+
|
|
180
|
+
### 1. Situational awareness
|
|
181
|
+
|
|
182
|
+
Before major work, the manager can call `getSituationBrief` (cwd, git, workspace, models, jobs, memory, projects). Use directly:
|
|
183
|
+
|
|
184
|
+
```ts
|
|
185
|
+
const brief = await zilmate.situation({ sessionId: 'default' });
|
|
186
|
+
console.log(brief.git, brief.recentJobs, brief.models);
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### 2. Session continuity (handoffs)
|
|
190
|
+
|
|
191
|
+
Resume work across sessions:
|
|
192
|
+
|
|
193
|
+
```ts
|
|
194
|
+
const handoff = await zilmate.handoff({ sessionId: 'default' });
|
|
195
|
+
if (handoff) {
|
|
196
|
+
await zilmate.manager({
|
|
197
|
+
message: `Continue from handoff:\n${handoff.summary}\nNext: ${handoff.nextActions.join(', ')}`,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
The manager can also call `generateSessionHandoff` / `saveSessionHandoff` before ending a long task.
|
|
203
|
+
|
|
204
|
+
## Model selection
|
|
205
|
+
|
|
206
|
+
CLI users run `/model pick`. In code, persist selections to the workspace:
|
|
207
|
+
|
|
208
|
+
```ts
|
|
209
|
+
import { applyStoredModelSelections, saveModelSelection } from 'zilmate/server';
|
|
210
|
+
|
|
211
|
+
await applyStoredModelSelections();
|
|
212
|
+
await saveModelSelection('manager', 'anthropic/claude-sonnet-4');
|
|
213
|
+
await saveModelSelection('coding', 'openai/gpt-5.4-mini');
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Models are stored in `~/Downloads/ZilMate/config/models.json` (or `ZILMATE_WORKSPACE`).
|
|
217
|
+
|
|
218
|
+
## Memory
|
|
219
|
+
|
|
220
|
+
```ts
|
|
221
|
+
await zilmate.remember({ text: 'User prefers pnpm and App Router', tags: ['prefs'] });
|
|
222
|
+
const hits = await zilmate.recall({ query: 'package manager', limit: 5 });
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## Background jobs
|
|
226
|
+
|
|
227
|
+
```ts
|
|
228
|
+
const job = await zilmate.createJob({
|
|
229
|
+
task: 'Weekly summary of GitHub PRs',
|
|
230
|
+
schedule: '0 9 * * 1',
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
await zilmate.runDueJobs();
|
|
234
|
+
const logs = await zilmate.getJobLogs(job.id);
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
Expose webhooks for QStash:
|
|
238
|
+
|
|
239
|
+
```ts
|
|
240
|
+
// app/api/jobs/webhook/route.ts
|
|
241
|
+
import { createZilMate } from 'zilmate/server';
|
|
242
|
+
|
|
243
|
+
export async function POST(req: Request) {
|
|
244
|
+
const body = await req.json();
|
|
245
|
+
const zilmate = createZilMate();
|
|
246
|
+
const job = await zilmate.handleJobWebhook(body, process.env.ZILMATE_JOB_WEBHOOK_SECRET);
|
|
247
|
+
return Response.json({ ok: true, jobId: job.id });
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
Use `zilmate jobs listen --tunnel` (Cloudflare quick tunnel) during local development.
|
|
252
|
+
|
|
253
|
+
## Voice (Deepgram)
|
|
254
|
+
|
|
255
|
+
```ts
|
|
256
|
+
const session = await zilmate.startVoiceSession({
|
|
257
|
+
onProgress: (e) => console.log(e.label),
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
// session exposes Deepgram agent wiring — see src/voice/deepgram.ts
|
|
261
|
+
console.log(session.config.listenModel);
|
|
262
|
+
await session.close?.();
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
## Confirmation in server contexts
|
|
266
|
+
|
|
267
|
+
Destructive tools require explicit approval. Provide a handler:
|
|
268
|
+
|
|
269
|
+
```ts
|
|
270
|
+
import type { ConfirmationHandler } from 'zilmate/server';
|
|
271
|
+
|
|
272
|
+
const confirm: ConfirmationHandler = async (request) => {
|
|
273
|
+
// In a web app, push to UI and await user click
|
|
274
|
+
console.log('Approve?', request.message);
|
|
275
|
+
return true;
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
const zilmate = createZilMate({ confirm });
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
## Exports reference
|
|
282
|
+
|
|
283
|
+
```ts
|
|
284
|
+
import {
|
|
285
|
+
createZilMate,
|
|
286
|
+
chat,
|
|
287
|
+
help,
|
|
288
|
+
post,
|
|
289
|
+
research,
|
|
290
|
+
image,
|
|
291
|
+
applyStoredModelSelections,
|
|
292
|
+
buildSituationBrief,
|
|
293
|
+
loadSessionHandoff,
|
|
294
|
+
clearSessionApprovals,
|
|
295
|
+
} from 'zilmate/server';
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
## CLI parity
|
|
299
|
+
|
|
300
|
+
| CLI | SDK |
|
|
301
|
+
|-----|-----|
|
|
302
|
+
| `zilmate talk` | `createZilMate().manager()` |
|
|
303
|
+
| `zilmate coding "..."` | `createZilMate().coding()` |
|
|
304
|
+
| `zilmate heal` | manager + heal tools (via manager) |
|
|
305
|
+
| `zilmate jobs worker` | `runDueJobs()` + worker process |
|
|
306
|
+
| `/model pick` | `saveModelSelection()` |
|
|
307
|
+
|
|
308
|
+
## Production checklist
|
|
309
|
+
|
|
310
|
+
1. Run `zilmate setup` once per environment (merge-safe).
|
|
311
|
+
2. Set `ZILMATE_WORKSPACE` for durable notebook/knowledge/skills.
|
|
312
|
+
3. Enable Redis for multi-instance memory and jobs.
|
|
313
|
+
4. Use QStash + Cloudflare tunnel for hosted schedules.
|
|
314
|
+
5. Never expose `AI_GATEWAY_API_KEY` to the browser — keep SDK calls on the server.
|
|
315
|
+
|
|
316
|
+
## Learn more
|
|
317
|
+
|
|
318
|
+
- Repository: https://github.com/zester4/zilo-manager
|
|
319
|
+
- Agent skill: `plugins/zilmate/skills/zilmate/SKILL.md`
|
|
320
|
+
- AI SDK patterns: https://sdk.vercel.ai/docs
|