@smooai/smooth-operator-core 0.1.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.
Files changed (62) hide show
  1. package/LICENSE +21 -0
  2. package/dist/agent.d.ts +276 -0
  3. package/dist/agent.d.ts.map +1 -0
  4. package/dist/agent.js +450 -0
  5. package/dist/agent.js.map +1 -0
  6. package/dist/cast.d.ts +81 -0
  7. package/dist/cast.d.ts.map +1 -0
  8. package/dist/cast.js +103 -0
  9. package/dist/cast.js.map +1 -0
  10. package/dist/checkpoint.d.ts +25 -0
  11. package/dist/checkpoint.d.ts.map +1 -0
  12. package/dist/checkpoint.js +23 -0
  13. package/dist/checkpoint.js.map +1 -0
  14. package/dist/compaction.d.ts +21 -0
  15. package/dist/compaction.d.ts.map +1 -0
  16. package/dist/compaction.js +50 -0
  17. package/dist/compaction.js.map +1 -0
  18. package/dist/cost.d.ts +34 -0
  19. package/dist/cost.d.ts.map +1 -0
  20. package/dist/cost.js +42 -0
  21. package/dist/cost.js.map +1 -0
  22. package/dist/humanGate.d.ts +44 -0
  23. package/dist/humanGate.d.ts.map +1 -0
  24. package/dist/humanGate.js +30 -0
  25. package/dist/humanGate.js.map +1 -0
  26. package/dist/index.d.ts +32 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +21 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/knowledge.d.ts +30 -0
  31. package/dist/knowledge.d.ts.map +1 -0
  32. package/dist/knowledge.js +43 -0
  33. package/dist/knowledge.js.map +1 -0
  34. package/dist/llmProvider.d.ts +106 -0
  35. package/dist/llmProvider.d.ts.map +1 -0
  36. package/dist/llmProvider.js +160 -0
  37. package/dist/llmProvider.js.map +1 -0
  38. package/dist/memory.d.ts +23 -0
  39. package/dist/memory.d.ts.map +1 -0
  40. package/dist/memory.js +40 -0
  41. package/dist/memory.js.map +1 -0
  42. package/dist/rerank.d.ts +27 -0
  43. package/dist/rerank.d.ts.map +1 -0
  44. package/dist/rerank.js +45 -0
  45. package/dist/rerank.js.map +1 -0
  46. package/dist/thread.d.ts +43 -0
  47. package/dist/thread.d.ts.map +1 -0
  48. package/dist/thread.js +60 -0
  49. package/dist/thread.js.map +1 -0
  50. package/dist/toolSearch.d.ts +55 -0
  51. package/dist/toolSearch.d.ts.map +1 -0
  52. package/dist/toolSearch.js +110 -0
  53. package/dist/toolSearch.js.map +1 -0
  54. package/dist/vector.d.ts +36 -0
  55. package/dist/vector.d.ts.map +1 -0
  56. package/dist/vector.js +75 -0
  57. package/dist/vector.js.map +1 -0
  58. package/dist/workflow.d.ts +62 -0
  59. package/dist/workflow.d.ts.map +1 -0
  60. package/dist/workflow.js +109 -0
  61. package/dist/workflow.js.map +1 -0
  62. package/package.json +38 -0
package/dist/agent.js ADDED
@@ -0,0 +1,450 @@
1
+ /**
2
+ * The TypeScript smooth-operator core: a native agentic loop.
3
+ *
4
+ * Phase-0 sibling of the C# `SmoothAgent` (`dotnet/core`), the Python core
5
+ * (`python/core`), and the Rust reference engine. Drives an agentic tool-calling
6
+ * loop over any OpenAI-compatible chat client (the `openai` SDK pointed at a
7
+ * gateway): inject retrieved knowledge, call the model, run any requested tools,
8
+ * feed results back, and loop until the model answers without a tool call or the
9
+ * iteration budget is hit.
10
+ *
11
+ * Deliberately minimal (no compaction / budget / checkpointing yet) — those layer
12
+ * on exactly as they did when the C# core grew past Phase 0.
13
+ */
14
+ import { compact } from './compaction.js';
15
+ import { CostTracker } from './cost.js';
16
+ import { isApproved } from './humanGate.js';
17
+ import { ToolSearch } from './toolSearch.js';
18
+ const DEFAULTS = {
19
+ model: 'claude-haiku-4-5',
20
+ maxIterations: 8,
21
+ maxTokens: 512,
22
+ temperature: 0,
23
+ knowledgeTopK: 4,
24
+ maxContextTokens: 8000,
25
+ maxRetries: 0,
26
+ retryBackoffMs: 200,
27
+ };
28
+ /** Sleep for `ms` milliseconds; a no-op when `ms <= 0` (so tests don't actually wait). */
29
+ function sleep(ms) {
30
+ return ms > 0 ? new Promise((resolve) => setTimeout(resolve, ms)) : Promise.resolve();
31
+ }
32
+ /** Pull token usage from an OpenAI-shaped response, defaulting to zero when absent. */
33
+ function extractUsage(usage) {
34
+ return { promptTokens: usage?.prompt_tokens ?? 0, completionTokens: usage?.completion_tokens ?? 0 };
35
+ }
36
+ export class SmoothAgent {
37
+ client;
38
+ options;
39
+ toolsByName;
40
+ constructor(client, options = {}) {
41
+ this.client = client;
42
+ this.options = options;
43
+ if (!client)
44
+ throw new Error('client is required');
45
+ this.toolsByName = new Map((options.tools ?? []).map((t) => [t.name, t]));
46
+ }
47
+ buildSystem(message) {
48
+ let system = this.options.instructions ?? '';
49
+ const mem = this.options.memory;
50
+ if (mem) {
51
+ const recalled = mem.recall(message, this.options.memoryTopK ?? 4);
52
+ if (recalled.length > 0) {
53
+ const block = recalled.map((e) => `- ${e.text}`).join('\n');
54
+ system = `${system}\n\nRelevant memory (things you remember about this user/context):\n${block}`.trim();
55
+ }
56
+ }
57
+ const kb = this.options.knowledge;
58
+ if (kb) {
59
+ const topK = this.options.knowledgeTopK ?? DEFAULTS.knowledgeTopK;
60
+ const candidateK = Math.max(this.options.knowledgeCandidateK ?? 0, topK);
61
+ let hits = kb.query(message, candidateK);
62
+ if (this.options.reranker)
63
+ hits = this.options.reranker.rerank(message, hits);
64
+ hits = hits.slice(0, topK);
65
+ if (hits.length > 0) {
66
+ const block = hits.map((h) => `[${h.source}] ${h.content}`).join('\n\n');
67
+ system = `${system}\n\nKnowledge base (ground all facts ONLY in this; if it is not here, say you don't know):\n${block}`.trim();
68
+ }
69
+ }
70
+ return system;
71
+ }
72
+ toolSpecs(search) {
73
+ // Eager (always-visible) tools, plus — when deferred tools exist — the
74
+ // built-in `tool_search` meta-tool and any deferred tools promoted so far
75
+ // this run. Deferred-but-unpromoted tools are deliberately omitted so the
76
+ // model never sees their schemas until it searches for them.
77
+ const visible = [...(this.options.tools ?? [])];
78
+ if (search?.hasDeferred()) {
79
+ visible.push(search);
80
+ visible.push(...search.promotedTools());
81
+ }
82
+ if (visible.length === 0)
83
+ return undefined;
84
+ return visible.map((t) => ({
85
+ type: 'function',
86
+ function: { name: t.name, description: t.description, parameters: t.parameters },
87
+ }));
88
+ }
89
+ /**
90
+ * Run a single turn.
91
+ *
92
+ * `history` is prior OpenAI-format messages (multi-turn). `thread`, when given,
93
+ * is a {@link SmoothAgentThread} carrying the conversation across runs: the turn
94
+ * is seeded from the thread's messages, and this turn's new user + assistant
95
+ * (+ tool) messages are appended back to it before returning. The thread takes
96
+ * precedence over `history` as the prior context.
97
+ */
98
+ async run(message, history, thread) {
99
+ const messages = [];
100
+ const system = this.buildSystem(message);
101
+ if (system)
102
+ messages.push({ role: 'system', content: system });
103
+ // Source prior conversation: the thread (if passed) wins, then the checkpoint
104
+ // store (if configured), then the explicit `history` argument.
105
+ const cpStore = this.options.checkpointStore;
106
+ const cpId = this.options.conversationId;
107
+ let prior = history;
108
+ if (cpStore && cpId) {
109
+ const loaded = cpStore.load(cpId);
110
+ if (loaded)
111
+ prior = loaded.messages;
112
+ }
113
+ if (thread)
114
+ prior = [...thread.messages];
115
+ if (prior)
116
+ messages.push(...prior);
117
+ const userMsg = { role: 'user', content: message };
118
+ messages.push(userMsg);
119
+ // Track this turn's new messages by identity so they can be appended back to
120
+ // the thread on exit. Index slicing would be unsafe — compaction may drop or
121
+ // reorder `messages` mid-turn.
122
+ const turnMessages = [userMsg];
123
+ // Per-run promotion state for deferred tools (undefined when none registered).
124
+ const search = this.options.deferredTools && this.options.deferredTools.length > 0 ? new ToolSearch(this.options.deferredTools) : undefined;
125
+ const maxIterations = this.options.maxIterations ?? DEFAULTS.maxIterations;
126
+ let toolCalls = 0;
127
+ let lastText = '';
128
+ const maxContextTokens = this.options.maxContextTokens ?? DEFAULTS.maxContextTokens;
129
+ const model = this.options.model ?? DEFAULTS.model;
130
+ const tracker = new CostTracker();
131
+ try {
132
+ for (let iteration = 1; iteration <= maxIterations; iteration++) {
133
+ // Keep the context window within budget before each model call.
134
+ messages.splice(0, messages.length, ...compact(messages, maxContextTokens));
135
+ // Recompute tool specs each iteration: a `tool_search` call in the
136
+ // previous iteration may have promoted deferred tools into view.
137
+ const tools = this.toolSpecs(search);
138
+ const response = await this.callModel({
139
+ model,
140
+ messages,
141
+ ...(tools ? { tools } : {}),
142
+ temperature: this.options.temperature ?? DEFAULTS.temperature,
143
+ max_tokens: this.options.maxTokens ?? DEFAULTS.maxTokens,
144
+ });
145
+ tracker.record(model, extractUsage(response.usage), this.options.pricing);
146
+ const choice = response.choices[0].message;
147
+ lastText = choice.content ?? '';
148
+ const assistantMsg = { role: 'assistant', content: choice.content ?? '' };
149
+ if (choice.tool_calls && choice.tool_calls.length > 0) {
150
+ assistantMsg.tool_calls = choice.tool_calls.map((tc) => ({
151
+ id: tc.id,
152
+ type: 'function',
153
+ function: { name: tc.function.name, arguments: tc.function.arguments },
154
+ }));
155
+ }
156
+ messages.push(assistantMsg);
157
+ turnMessages.push(assistantMsg);
158
+ // Stop early if this turn has hit its token/cost budget.
159
+ if (tracker.exceeds(this.options.budget)) {
160
+ return { text: lastText, iterations: iteration, toolCalls, usage: tracker.usage, costUsd: tracker.costUsd, budgetExceeded: true };
161
+ }
162
+ if (!choice.tool_calls || choice.tool_calls.length === 0) {
163
+ return { text: lastText, iterations: iteration, toolCalls, usage: tracker.usage, costUsd: tracker.costUsd, budgetExceeded: false };
164
+ }
165
+ toolCalls += choice.tool_calls.length;
166
+ // Dispatch the tool calls — concurrently when enabled and there's more than
167
+ // one — but always append the results in the original tool_calls order so the
168
+ // transcript stays deterministic. dispatchTool turns failures/denials into a
169
+ // result string, so Promise.all never rejects and cancels its siblings.
170
+ const calls = choice.tool_calls;
171
+ let results;
172
+ if (this.options.parallelToolCalls && calls.length > 1) {
173
+ results = await Promise.all(calls.map((tc) => this.dispatchTool(tc.function.name, tc.function.arguments, search)));
174
+ }
175
+ else {
176
+ results = [];
177
+ for (const tc of calls) {
178
+ results.push(await this.dispatchTool(tc.function.name, tc.function.arguments, search));
179
+ }
180
+ }
181
+ for (let i = 0; i < calls.length; i++) {
182
+ const toolMsg = { role: 'tool', tool_call_id: calls[i].id, content: results[i] };
183
+ messages.push(toolMsg);
184
+ turnMessages.push(toolMsg);
185
+ }
186
+ }
187
+ return { text: lastText, iterations: maxIterations, toolCalls, usage: tracker.usage, costUsd: tracker.costUsd, budgetExceeded: false };
188
+ }
189
+ finally {
190
+ // Persist the conversation (sans system prompt, which is rebuilt each turn).
191
+ if (cpStore && cpId) {
192
+ cpStore.save({ conversationId: cpId, messages: messages.filter((m) => m.role !== 'system') });
193
+ }
194
+ // Append this turn's new messages (user + assistant + tool, never system)
195
+ // back to the thread so the next run sees the full conversation.
196
+ if (thread)
197
+ thread.extend(turnMessages);
198
+ }
199
+ }
200
+ /**
201
+ * Stream a single turn, yielding incremental {@link StreamEvent}s as the model
202
+ * produces them. This drives the SAME agentic loop as {@link run} (system /
203
+ * knowledge / memory build, seed messages, per-iteration compaction, cost
204
+ * tracking, budget early-stop, deferred-tool specs, clearance + human-gate on
205
+ * dispatch, checkpoint/thread persistence on exit) — but calls the model in
206
+ * STREAMING mode and emits events as work happens:
207
+ *
208
+ * - a `text` event per non-empty content delta as it streams in;
209
+ * - a `tool_call` event per requested tool call, after that iteration's model
210
+ * stream ends, BEFORE the call is dispatched;
211
+ * - a `tool_result` event per tool, after it finishes (in original call order
212
+ * even when `parallelToolCalls` runs them concurrently);
213
+ * - exactly one terminal `done` event carrying the same {@link AgentRunResponse}
214
+ * {@link run} would return for the same script.
215
+ *
216
+ * NOTE: retry-with-backoff (`maxRetries`/`retryBackoffMs`) is intentionally NOT
217
+ * applied here — re-running the call after a mid-stream failure would re-emit
218
+ * already-yielded chunks. Retry stays scoped to non-streaming {@link run}; this
219
+ * mirrors the C# `RunStreamingAsync` decision.
220
+ */
221
+ async *runStream(message, history, thread) {
222
+ const createStream = this.client.chat.completions.createStream?.bind(this.client.chat.completions);
223
+ if (!createStream)
224
+ throw new Error('runStream requires a streaming-capable client (chat.completions.createStream)');
225
+ const messages = [];
226
+ const system = this.buildSystem(message);
227
+ if (system)
228
+ messages.push({ role: 'system', content: system });
229
+ // Source prior conversation: the thread (if passed) wins, then the checkpoint
230
+ // store (if configured), then the explicit `history` argument. (Same as `run`.)
231
+ const cpStore = this.options.checkpointStore;
232
+ const cpId = this.options.conversationId;
233
+ let prior = history;
234
+ if (cpStore && cpId) {
235
+ const loaded = cpStore.load(cpId);
236
+ if (loaded)
237
+ prior = loaded.messages;
238
+ }
239
+ if (thread)
240
+ prior = [...thread.messages];
241
+ if (prior)
242
+ messages.push(...prior);
243
+ const userMsg = { role: 'user', content: message };
244
+ messages.push(userMsg);
245
+ const turnMessages = [userMsg];
246
+ const search = this.options.deferredTools && this.options.deferredTools.length > 0 ? new ToolSearch(this.options.deferredTools) : undefined;
247
+ const maxIterations = this.options.maxIterations ?? DEFAULTS.maxIterations;
248
+ let toolCalls = 0;
249
+ let lastText = '';
250
+ const maxContextTokens = this.options.maxContextTokens ?? DEFAULTS.maxContextTokens;
251
+ const model = this.options.model ?? DEFAULTS.model;
252
+ const tracker = new CostTracker();
253
+ try {
254
+ for (let iteration = 1; iteration <= maxIterations; iteration++) {
255
+ messages.splice(0, messages.length, ...compact(messages, maxContextTokens));
256
+ const tools = this.toolSpecs(search);
257
+ // Stream the model call, yielding text deltas as they arrive while
258
+ // accumulating the full assistant message (content + tool calls + usage).
259
+ const assembled = { content: '', toolCalls: [], usage: null };
260
+ const partials = new Map();
261
+ const stream = createStream({
262
+ model,
263
+ messages,
264
+ ...(tools ? { tools } : {}),
265
+ temperature: this.options.temperature ?? DEFAULTS.temperature,
266
+ max_tokens: this.options.maxTokens ?? DEFAULTS.maxTokens,
267
+ stream: true,
268
+ });
269
+ for await (const chunk of stream) {
270
+ if (chunk.usage)
271
+ assembled.usage = chunk.usage;
272
+ const delta = chunk.choices[0]?.delta;
273
+ if (!delta)
274
+ continue;
275
+ if (delta.content) {
276
+ assembled.content += delta.content;
277
+ yield { type: 'text', text: delta.content };
278
+ }
279
+ for (const tc of delta.tool_calls ?? []) {
280
+ const cur = partials.get(tc.index) ?? { id: '', name: '', arguments: '' };
281
+ if (tc.id)
282
+ cur.id = tc.id;
283
+ if (tc.function?.name)
284
+ cur.name = tc.function.name;
285
+ if (tc.function?.arguments)
286
+ cur.arguments += tc.function.arguments;
287
+ partials.set(tc.index, cur);
288
+ }
289
+ }
290
+ // Materialize accumulated tool calls in ascending index order.
291
+ assembled.toolCalls = [...partials.entries()]
292
+ .sort((a, b) => a[0] - b[0])
293
+ .map(([, p]) => ({ id: p.id, function: { name: p.name, arguments: p.arguments } }));
294
+ tracker.record(model, extractUsage(assembled.usage), this.options.pricing);
295
+ lastText = assembled.content;
296
+ const assistantMsg = { role: 'assistant', content: assembled.content };
297
+ if (assembled.toolCalls.length > 0) {
298
+ assistantMsg.tool_calls = assembled.toolCalls.map((tc) => ({
299
+ id: tc.id,
300
+ type: 'function',
301
+ function: { name: tc.function.name, arguments: tc.function.arguments },
302
+ }));
303
+ }
304
+ messages.push(assistantMsg);
305
+ turnMessages.push(assistantMsg);
306
+ if (tracker.exceeds(this.options.budget)) {
307
+ yield {
308
+ type: 'done',
309
+ response: { text: lastText, iterations: iteration, toolCalls, usage: tracker.usage, costUsd: tracker.costUsd, budgetExceeded: true },
310
+ };
311
+ return;
312
+ }
313
+ if (assembled.toolCalls.length === 0) {
314
+ yield {
315
+ type: 'done',
316
+ response: { text: lastText, iterations: iteration, toolCalls, usage: tracker.usage, costUsd: tracker.costUsd, budgetExceeded: false },
317
+ };
318
+ return;
319
+ }
320
+ toolCalls += assembled.toolCalls.length;
321
+ const calls = assembled.toolCalls;
322
+ // Emit a tool_call event per requested call (original order) BEFORE dispatch.
323
+ for (const tc of calls) {
324
+ yield { type: 'tool_call', name: tc.function.name, arguments: tc.function.arguments };
325
+ }
326
+ // Reuse the SAME dispatch path as `run` (clearance, human-gate, tool_search,
327
+ // JSON parsing, error-to-string, parallelToolCalls). Results are surfaced in
328
+ // original call order so the event stream stays deterministic.
329
+ let results;
330
+ if (this.options.parallelToolCalls && calls.length > 1) {
331
+ results = await Promise.all(calls.map((tc) => this.dispatchTool(tc.function.name, tc.function.arguments, search)));
332
+ }
333
+ else {
334
+ results = [];
335
+ for (const tc of calls) {
336
+ results.push(await this.dispatchTool(tc.function.name, tc.function.arguments, search));
337
+ }
338
+ }
339
+ for (let i = 0; i < calls.length; i++) {
340
+ const toolMsg = { role: 'tool', tool_call_id: calls[i].id, content: results[i] };
341
+ messages.push(toolMsg);
342
+ turnMessages.push(toolMsg);
343
+ yield { type: 'tool_result', name: calls[i].function.name, result: results[i] };
344
+ }
345
+ }
346
+ yield {
347
+ type: 'done',
348
+ response: { text: lastText, iterations: maxIterations, toolCalls, usage: tracker.usage, costUsd: tracker.costUsd, budgetExceeded: false },
349
+ };
350
+ }
351
+ finally {
352
+ if (cpStore && cpId) {
353
+ cpStore.save({ conversationId: cpId, messages: messages.filter((m) => m.role !== 'system') });
354
+ }
355
+ if (thread)
356
+ thread.extend(turnMessages);
357
+ }
358
+ }
359
+ /**
360
+ * Invoke the model with bounded retry-with-exponential-backoff.
361
+ *
362
+ * On a transient error (anything the client throws — rate-limit, 5xx, dropped
363
+ * connection) the call is retried up to `maxRetries` additional times, waiting
364
+ * `retryBackoffMs * 2 ** (n - 1)` ms before the n-th (1-indexed) retry. If all
365
+ * attempts fail the LAST error propagates, so the turn fails exactly as it did
366
+ * before retries existed. Only this model call is retried — tool execution is not.
367
+ */
368
+ async callModel(body) {
369
+ const maxRetries = this.options.maxRetries ?? DEFAULTS.maxRetries;
370
+ const backoffMs = this.options.retryBackoffMs ?? DEFAULTS.retryBackoffMs;
371
+ let attempt = 0;
372
+ for (;;) {
373
+ try {
374
+ return await this.client.chat.completions.create(body);
375
+ }
376
+ catch (err) {
377
+ if (attempt >= maxRetries)
378
+ throw err; // retries exhausted (or disabled): propagate last error
379
+ attempt++;
380
+ await sleep(backoffMs * 2 ** (attempt - 1));
381
+ }
382
+ }
383
+ }
384
+ async dispatchTool(name, rawArgs, search) {
385
+ // Enforce the role's tool clearance before dispatch: a forbidden tool is
386
+ // never executed — the model is told it isn't permitted, mirroring how the
387
+ // loop surfaces other tool errors.
388
+ const clearance = this.options.clearance;
389
+ if (clearance && !clearance.isAllowed(name)) {
390
+ return `error: tool '${name}' is not permitted for this role`;
391
+ }
392
+ // Resolve the tool: eager tools first, then the built-in `tool_search`
393
+ // meta-tool, then deferred tools that have been promoted. An unpromoted
394
+ // deferred tool resolves to nothing — it's invisible until searched for.
395
+ let tool = this.toolsByName.get(name);
396
+ if (!tool && search) {
397
+ tool = name === search.name ? search : search.toolByName(name);
398
+ }
399
+ if (!tool)
400
+ return `error: unknown tool '${name}'`;
401
+ let args;
402
+ try {
403
+ args = rawArgs ? JSON.parse(rawArgs) : {};
404
+ }
405
+ catch {
406
+ return `error: tool '${name}' received invalid JSON arguments`;
407
+ }
408
+ // Human-in-the-loop: pause for approval before running a flagged (write/sensitive)
409
+ // tool. A denial is fed back to the model as a result — the tool never runs.
410
+ const gate = this.options.humanGate;
411
+ if (gate && this.options.requiresApproval?.(name, args)) {
412
+ const decision = await gate({ toolName: name, arguments: args, prompt: `Approve calling tool '${name}'?` });
413
+ if (!isApproved(decision)) {
414
+ return `Denied by human: ${decision.reason ?? 'no reason given'}`;
415
+ }
416
+ }
417
+ try {
418
+ return await tool.execute(args);
419
+ }
420
+ catch (err) {
421
+ // Surface tool failures to the model, don't crash the turn.
422
+ return `error: tool '${name}' failed: ${err instanceof Error ? err.message : String(err)}`;
423
+ }
424
+ }
425
+ }
426
+ /**
427
+ * Build a {@link Tool} that delegates a subtask to a child {@link SmoothAgent}.
428
+ *
429
+ * A sub-agent is just a tool backed by another agent: the model calls this tool
430
+ * with a `task` argument, the child agent runs that task, and the child's final
431
+ * reply becomes the tool result — composing with the existing tool loop, no special
432
+ * wiring. The child can have its own instructions, tools, knowledge, etc.
433
+ */
434
+ export function delegateTool(name, description, child, taskProperty = 'task') {
435
+ return {
436
+ name,
437
+ description,
438
+ parameters: {
439
+ type: 'object',
440
+ properties: { [taskProperty]: { type: 'string', description: 'The subtask for the sub-agent to perform.' } },
441
+ required: [taskProperty],
442
+ },
443
+ async execute(args) {
444
+ const task = String(args[taskProperty] ?? '');
445
+ const result = await child.run(task);
446
+ return result.text;
447
+ },
448
+ };
449
+ }
450
+ //# sourceMappingURL=agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAOH,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAGxC,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAwL7C,MAAM,QAAQ,GAAG;IACb,KAAK,EAAE,kBAAkB;IACzB,aAAa,EAAE,CAAC;IAChB,SAAS,EAAE,GAAG;IACd,WAAW,EAAE,CAAC;IACd,aAAa,EAAE,CAAC;IAChB,gBAAgB,EAAE,IAAI;IACtB,UAAU,EAAE,CAAC;IACb,cAAc,EAAE,GAAG;CACtB,CAAC;AAEF,0FAA0F;AAC1F,SAAS,KAAK,CAAC,EAAU;IACrB,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;AAC1F,CAAC;AAED,uFAAuF;AACvF,SAAS,YAAY,CAAC,KAA8F;IAChH,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,IAAI,CAAC,EAAE,gBAAgB,EAAE,KAAK,EAAE,iBAAiB,IAAI,CAAC,EAAE,CAAC;AACxG,CAAC;AAED,MAAM,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OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/F,CAAC;IACL,CAAC;CACJ;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,WAAmB,EAAE,KAAkB,EAAE,YAAY,GAAG,MAAM;IACrG,OAAO;QACH,IAAI;QACJ,WAAW;QACX,UAAU,EAAE;YACR,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE,EAAE,CAAC,YAAY,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,2CAA2C,EAAE,EAAE;YAC5G,QAAQ,EAAE,CAAC,YAAY,CAAC;SAC3B;QACD,KAAK,CAAC,OAAO,CAAC,IAA6B;YACvC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC;YAC9C,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACrC,OAAO,MAAM,CAAC,IAAI,CAAC;QACvB,CAAC;KACJ,CAAC;AACN,CAAC"}
package/dist/cast.d.ts ADDED
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Multi-agent cast: roles and per-role tool-access policy.
3
+ *
4
+ * Phase-2 sibling of the C# reference (`dotnet/core/src/Cast.cs`) and the Rust
5
+ * engine. A *cast* is the set of named roles a lead can dispatch to; each role has
6
+ * a {@link RoleKind} (Lead / Sidekick / Shadow) and a {@link Clearance} that gates
7
+ * which tools it may call.
8
+ *
9
+ * {@link Clearance} semantics (mirrors the reference engines):
10
+ * - a **deny always wins** — a denied tool is never permitted;
11
+ * - a **non-empty allow-list is a whitelist** — only listed tools are permitted;
12
+ * - **empty allow + empty deny means "all tools"**.
13
+ *
14
+ * Clearance is wired into the agent loop: if `AgentOptions.clearance` forbids a
15
+ * tool the model asked for, that tool is *not* executed — a clear "not permitted"
16
+ * result is returned to the model instead, mirroring how the engine surfaces other
17
+ * tool errors.
18
+ */
19
+ /** A role's place in a multi-agent cast. Mirrors the reference engines' `RoleKind`. */
20
+ export declare enum RoleKind {
21
+ /** The orchestrator that delegates to sidekicks. */
22
+ Lead = "lead",
23
+ /** A focused specialist a lead can dispatch a sub-task to. */
24
+ Sidekick = "sidekick",
25
+ /** A passive observer (e.g. for logging/critique); not directly dispatchable. */
26
+ Shadow = "shadow"
27
+ }
28
+ /**
29
+ * Tool-access policy for a role. A deny always wins; a non-empty `allowTools` is a
30
+ * whitelist; empty allow + empty deny means "all tools". `denyEverything` blocks
31
+ * every tool regardless of the lists.
32
+ */
33
+ export declare class Clearance {
34
+ readonly allowTools: ReadonlySet<string>;
35
+ readonly denyTools: ReadonlySet<string>;
36
+ readonly denyEverything: boolean;
37
+ constructor(options?: {
38
+ allowTools?: Iterable<string>;
39
+ denyTools?: Iterable<string>;
40
+ denyEverything?: boolean;
41
+ });
42
+ static allowAll(): Clearance;
43
+ static denyAll(): Clearance;
44
+ static allow(...tools: string[]): Clearance;
45
+ static deny(...tools: string[]): Clearance;
46
+ /** Whether `tool` is permitted under this clearance. */
47
+ isAllowed(tool: string): boolean;
48
+ }
49
+ /**
50
+ * A named role in the cast — its kind, instructions, tool clearance, and budget.
51
+ * Mirrors the reference engines' `OperatorRole`.
52
+ */
53
+ export interface OperatorRole {
54
+ name: string;
55
+ kind: RoleKind;
56
+ instructions?: string;
57
+ /** Tool-access policy (defaults to allow-all when constructed via {@link makeRole}). */
58
+ permissions?: Clearance;
59
+ maxIterations?: number;
60
+ /** Hidden from listings (still dispatchable by name). */
61
+ hidden?: boolean;
62
+ }
63
+ /** Build an {@link OperatorRole} with the reference-engine defaults applied. */
64
+ export declare function makeRole(name: string, kind: RoleKind, overrides?: {
65
+ instructions?: string;
66
+ permissions?: Clearance;
67
+ maxIterations?: number;
68
+ hidden?: boolean;
69
+ }): Required<OperatorRole>;
70
+ /** The registered set of roles a lead can dispatch to. Mirrors the reference engines' `Cast`. */
71
+ export declare class Cast {
72
+ private readonly roles;
73
+ register(role: OperatorRole): this;
74
+ get(name: string): OperatorRole | undefined;
75
+ list(): OperatorRole[];
76
+ listVisible(): OperatorRole[];
77
+ sidekicks(): OperatorRole[];
78
+ get count(): number;
79
+ get isEmpty(): boolean;
80
+ }
81
+ //# sourceMappingURL=cast.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cast.d.ts","sourceRoot":"","sources":["../src/cast.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,uFAAuF;AACvF,oBAAY,QAAQ;IAChB,oDAAoD;IACpD,IAAI,SAAS;IACb,8DAA8D;IAC9D,QAAQ,aAAa;IACrB,iFAAiF;IACjF,MAAM,WAAW;CACpB;AAED;;;;GAIG;AACH,qBAAa,SAAS;IAClB,QAAQ,CAAC,UAAU,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACzC,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACxC,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC;gBAErB,OAAO,GAAE;QAAE,UAAU,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;QAAC,SAAS,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;QAAC,cAAc,CAAC,EAAE,OAAO,CAAA;KAAO;IAMnH,MAAM,CAAC,QAAQ,IAAI,SAAS;IAI5B,MAAM,CAAC,OAAO,IAAI,SAAS;IAI3B,MAAM,CAAC,KAAK,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,SAAS;IAI3C,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,SAAS;IAI1C,wDAAwD;IACxD,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;CAMnC;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,CAAC;IACf,YAAY,CAAC,EAAE,MAA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