@levelcode/sdk 0.1.0 → 0.2.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 (70) hide show
  1. package/README.md +104 -0
  2. package/dist/agents/constants.d.ts +1 -0
  3. package/dist/agents/team/apprentice.d.ts +3 -0
  4. package/dist/agents/team/coordinator.d.ts +3 -0
  5. package/dist/agents/team/cto.d.ts +3 -0
  6. package/dist/agents/team/designer.d.ts +3 -0
  7. package/dist/agents/team/director.d.ts +3 -0
  8. package/dist/agents/team/distinguished-engineer.d.ts +3 -0
  9. package/dist/agents/team/fellow.d.ts +3 -0
  10. package/dist/agents/team/index.d.ts +27 -0
  11. package/dist/agents/team/intern.d.ts +3 -0
  12. package/dist/agents/team/junior-engineer.d.ts +3 -0
  13. package/dist/agents/team/manager.d.ts +3 -0
  14. package/dist/agents/team/mid-level-engineer.d.ts +3 -0
  15. package/dist/agents/team/principal-engineer.d.ts +3 -0
  16. package/dist/agents/team/product-lead.d.ts +3 -0
  17. package/dist/agents/team/researcher.d.ts +3 -0
  18. package/dist/agents/team/role-hierarchy.d.ts +24 -0
  19. package/dist/agents/team/scientist.d.ts +3 -0
  20. package/dist/agents/team/senior-engineer.d.ts +3 -0
  21. package/dist/agents/team/senior-staff-engineer.d.ts +3 -0
  22. package/dist/agents/team/staff-engineer.d.ts +3 -0
  23. package/dist/agents/team/sub-manager.d.ts +3 -0
  24. package/dist/agents/team/tester.d.ts +3 -0
  25. package/dist/agents/team/vp-engineering.d.ts +3 -0
  26. package/dist/agents/types/agent-definition.d.ts +296 -0
  27. package/dist/agents/types/secret-agent-definition.d.ts +19 -0
  28. package/dist/agents/types/tools.d.ts +308 -0
  29. package/dist/agents/types/util-types.d.ts +134 -0
  30. package/dist/common/src/constants/analytics-events.d.ts +5 -1
  31. package/dist/common/src/constants/model-config.d.ts +1 -1
  32. package/dist/common/src/tools/list.d.ts +18 -6
  33. package/dist/common/src/tools/params/tool/run-file-change-hooks.d.ts +2 -2
  34. package/dist/common/src/tools/params/tool/run-terminal-command.d.ts +3 -3
  35. package/dist/common/src/tools/params/tool/send-message.d.ts +2 -2
  36. package/dist/common/src/tools/params/tool/task-create.d.ts +6 -0
  37. package/dist/common/src/tools/params/tool/task-update.d.ts +6 -0
  38. package/dist/common/src/types/print-mode.d.ts +2 -2
  39. package/dist/common/src/types/team-config-schemas.d.ts +213 -0
  40. package/dist/common/src/types/team-config.d.ts +4 -1
  41. package/dist/common/src/types/team-hook-events.d.ts +36 -0
  42. package/dist/common/src/utils/dev-phases.d.ts +23 -0
  43. package/dist/common/src/utils/file-lock.d.ts +13 -0
  44. package/dist/common/src/utils/team-analytics.d.ts +16 -0
  45. package/dist/common/src/utils/team-discovery.d.ts +47 -0
  46. package/dist/common/src/utils/team-fs.d.ts +9 -6
  47. package/dist/common/src/utils/team-hook-emitter.d.ts +40 -0
  48. package/dist/common/src/utils/team-presets.d.ts +35 -0
  49. package/dist/index.cjs +5339 -1554
  50. package/dist/index.cjs.map +62 -24
  51. package/dist/index.mjs +6027 -2242
  52. package/dist/index.mjs.map +62 -24
  53. package/dist/packages/agent-runtime/src/inbox-poller.d.ts +81 -0
  54. package/dist/packages/agent-runtime/src/message-formatter.d.ts +12 -0
  55. package/dist/packages/agent-runtime/src/system-prompt/team-context-prompt.d.ts +9 -0
  56. package/dist/packages/agent-runtime/src/system-prompt/team-prompt.d.ts +9 -0
  57. package/dist/packages/agent-runtime/src/team-context.d.ts +14 -0
  58. package/dist/packages/agent-runtime/src/templates/agent-registry.d.ts +1 -1
  59. package/dist/packages/agent-runtime/src/tools/handlers/list.d.ts +20 -1
  60. package/dist/packages/agent-runtime/src/tools/handlers/tool/send-message.d.ts +5 -0
  61. package/dist/packages/agent-runtime/src/tools/handlers/tool/spawn-agent-utils.d.ts +31 -1
  62. package/dist/packages/agent-runtime/src/tools/handlers/tool/spawn-agents.d.ts +2 -0
  63. package/dist/packages/agent-runtime/src/tools/handlers/tool/task-completed.d.ts +9 -1
  64. package/dist/packages/agent-runtime/src/tools/handlers/tool/task-update.d.ts +5 -0
  65. package/dist/packages/agent-runtime/src/tools/handlers/tool/team-create.d.ts +5 -0
  66. package/dist/packages/agent-runtime/src/tools/handlers/tool/team-delete.d.ts +5 -0
  67. package/dist/sdk/src/__tests__/team-api.test.d.ts +1 -0
  68. package/dist/sdk/src/client.d.ts +38 -0
  69. package/dist/sdk/src/team.d.ts +49 -0
  70. package/package.json +1 -1
package/README.md CHANGED
@@ -261,6 +261,110 @@ The `RunState` object contains:
261
261
  - `sessionState`: Internal state to be passed to the next run
262
262
  - `output`: The agent's output (text, error, or other types)
263
263
 
264
+ ### Team Management
265
+
266
+ The SDK provides programmatic team management for coordinating multiple agents.
267
+
268
+ #### `client.createTeam(config)`
269
+
270
+ Creates a new team from a `TeamConfig` object. If a team with the same name already exists it will be overwritten.
271
+
272
+ ```typescript
273
+ import { LevelCodeClient } from '@levelcode/sdk'
274
+ import type { TeamConfig } from '@levelcode/sdk'
275
+
276
+ const client = new LevelCodeClient({ apiKey: process.env.LEVELCODE_API_KEY })
277
+
278
+ const config: TeamConfig = {
279
+ name: 'my-team',
280
+ description: 'Backend refactor squad',
281
+ createdAt: Date.now(),
282
+ leadAgentId: 'lead-001',
283
+ phase: 'planning',
284
+ members: [
285
+ {
286
+ agentId: 'lead-001',
287
+ name: 'team-lead',
288
+ role: 'coordinator',
289
+ agentType: 'coordinator',
290
+ model: 'claude-opus-4-6',
291
+ joinedAt: Date.now(),
292
+ status: 'active',
293
+ cwd: process.cwd(),
294
+ },
295
+ ],
296
+ settings: { maxMembers: 10, autoAssign: true },
297
+ }
298
+
299
+ client.createTeam(config)
300
+ ```
301
+
302
+ #### `client.deleteTeam(name)`
303
+
304
+ Deletes a team by name, removing all associated data (config, tasks, inboxes). Safe to call on a team that does not exist.
305
+
306
+ ```typescript
307
+ client.deleteTeam('my-team')
308
+ ```
309
+
310
+ #### `client.getTeamStatus(name)`
311
+
312
+ Returns summary information for a team, or `null` if the team does not exist or has a corrupted config.
313
+
314
+ ```typescript
315
+ const status = client.getTeamStatus('my-team')
316
+ if (status) {
317
+ console.log(status.name) // 'my-team'
318
+ console.log(status.phase) // 'planning'
319
+ console.log(status.memberCount) // 1
320
+ }
321
+ ```
322
+
323
+ Returns a `TeamSummary`:
324
+
325
+ | Field | Type | Description |
326
+ | ------------- | ---------- | ---------------------------------- |
327
+ | `name` | `string` | Team name |
328
+ | `phase` | `DevPhase` | Current development phase |
329
+ | `memberCount` | `number` | Number of members in the team |
330
+
331
+ #### `client.listTeams()`
332
+
333
+ Returns an array of `TeamSummary` objects for every team. Teams with corrupted config files are silently skipped.
334
+
335
+ ```typescript
336
+ const teams = client.listTeams()
337
+ for (const team of teams) {
338
+ console.log(`${team.name} — ${team.phase} (${team.memberCount} members)`)
339
+ }
340
+ ```
341
+
342
+ #### Team Types
343
+
344
+ The following types are exported from `@levelcode/sdk` for use with the team API:
345
+
346
+ ```typescript
347
+ import type {
348
+ TeamConfig,
349
+ TeamMember,
350
+ TeamTask,
351
+ TeamRole,
352
+ DevPhase,
353
+ TeamSummary,
354
+ TeamProtocolMessage,
355
+ } from '@levelcode/sdk'
356
+ ```
357
+
358
+ | Type | Description |
359
+ | ----------------------- | ------------------------------------------------------------------ |
360
+ | `TeamConfig` | Full team configuration (name, members, settings, phase) |
361
+ | `TeamMember` | A single member entry (agentId, name, role, model, status) |
362
+ | `TeamTask` | A task within a team (id, subject, status, priority, owner) |
363
+ | `TeamRole` | Union of all role strings (`'coordinator'`, `'senior-engineer'`, etc.) |
364
+ | `DevPhase` | Development phase (`'planning'` \| `'pre-alpha'` \| `'alpha'` \| `'beta'` \| `'production'` \| `'mature'`) |
365
+ | `TeamSummary` | Lightweight summary returned by `getTeamStatus` and `listTeams` |
366
+ | `TeamProtocolMessage` | Message type used for inter-agent communication |
367
+
264
368
  ## License
265
369
 
266
370
  MIT
@@ -0,0 +1 @@
1
+ export declare const publisher = "levelcode";
@@ -0,0 +1,3 @@
1
+ import type { AgentDefinition } from '../types/agent-definition';
2
+ declare const apprentice: AgentDefinition;
3
+ export default apprentice;
@@ -0,0 +1,3 @@
1
+ import type { AgentDefinition } from '../types/agent-definition';
2
+ declare const coordinator: AgentDefinition;
3
+ export default coordinator;
@@ -0,0 +1,3 @@
1
+ import type { AgentDefinition } from '../types/agent-definition';
2
+ declare const cto: AgentDefinition;
3
+ export default cto;
@@ -0,0 +1,3 @@
1
+ import type { AgentDefinition } from '../types/agent-definition';
2
+ declare const designer: AgentDefinition;
3
+ export default designer;
@@ -0,0 +1,3 @@
1
+ import type { AgentDefinition } from '../types/agent-definition';
2
+ declare const director: AgentDefinition;
3
+ export default director;
@@ -0,0 +1,3 @@
1
+ import type { AgentDefinition } from '../types/agent-definition';
2
+ declare const distinguishedEngineer: AgentDefinition;
3
+ export default distinguishedEngineer;
@@ -0,0 +1,3 @@
1
+ import type { AgentDefinition } from '../types/agent-definition';
2
+ declare const fellow: AgentDefinition;
3
+ export default fellow;
@@ -0,0 +1,27 @@
1
+ import type { TeamRole } from '@levelcode/common/types/team-config';
2
+ import type { AgentDefinition } from '../types/agent-definition';
3
+ /**
4
+ * Map of TeamRole to its AgentDefinition.
5
+ *
6
+ * Roles that exist in the TeamRole type but have no dedicated template
7
+ * (e.g. 'super-senior', 'reviewer') are intentionally omitted.
8
+ */
9
+ export declare const TEAM_AGENTS: Partial<Record<TeamRole, AgentDefinition>>;
10
+ /**
11
+ * Human-readable descriptions for each team role.
12
+ */
13
+ export declare const TEAM_ROLE_DESCRIPTIONS: Partial<Record<TeamRole, string>>;
14
+ /**
15
+ * Look up the AgentDefinition for a given team role.
16
+ * Returns undefined if the role has no registered template.
17
+ */
18
+ export declare function getTeamAgent(role: TeamRole): AgentDefinition | undefined;
19
+ /**
20
+ * Get all registered team agent definitions.
21
+ */
22
+ export declare function getAllTeamAgents(): AgentDefinition[];
23
+ /**
24
+ * Get a map of agent ID to AgentDefinition for all team agents.
25
+ * Useful for registering team agents into the agent template system.
26
+ */
27
+ export declare function getTeamAgentsByIds(): Record<string, AgentDefinition>;
@@ -0,0 +1,3 @@
1
+ import type { AgentDefinition } from '../types/agent-definition';
2
+ declare const intern: AgentDefinition;
3
+ export default intern;
@@ -0,0 +1,3 @@
1
+ import type { AgentDefinition } from '../types/agent-definition';
2
+ declare const juniorEngineer: AgentDefinition;
3
+ export default juniorEngineer;
@@ -0,0 +1,3 @@
1
+ import type { AgentDefinition } from '../types/agent-definition';
2
+ declare const manager: AgentDefinition;
3
+ export default manager;
@@ -0,0 +1,3 @@
1
+ import type { AgentDefinition } from '../types/agent-definition';
2
+ declare const midLevelEngineer: AgentDefinition;
3
+ export default midLevelEngineer;
@@ -0,0 +1,3 @@
1
+ import type { AgentDefinition } from '../types/agent-definition';
2
+ declare const principalEngineer: AgentDefinition;
3
+ export default principalEngineer;
@@ -0,0 +1,3 @@
1
+ import type { AgentDefinition } from '../types/agent-definition';
2
+ declare const productLead: AgentDefinition;
3
+ export default productLead;
@@ -0,0 +1,3 @@
1
+ import type { AgentDefinition } from '../types/agent-definition';
2
+ declare const researcher: AgentDefinition;
3
+ export default researcher;
@@ -0,0 +1,24 @@
1
+ import type { TeamRole } from '@levelcode/common/types/team-config';
2
+ /**
3
+ * Team roles ordered from lowest to highest authority.
4
+ * Index 0 is the lowest level (intern), last element is the highest (cto).
5
+ *
6
+ * Specialist roles (researcher, scientist, designer, product-lead, tester)
7
+ * are placed alongside their equivalent IC/management level.
8
+ */
9
+ export declare const ROLE_HIERARCHY: TeamRole[];
10
+ /**
11
+ * Get the numeric authority level for a role.
12
+ * 0 = intern (lowest), 13 = CTO (highest).
13
+ */
14
+ export declare function getRoleLevel(role: TeamRole): number;
15
+ /**
16
+ * Returns true if the manager role has authority over the subordinate role.
17
+ * A role can manage any role with a strictly lower level.
18
+ */
19
+ export declare function canManage(managerRole: TeamRole, subordinateRole: TeamRole): boolean;
20
+ /**
21
+ * Get the team roles that a given role is allowed to spawn as sub-agents.
22
+ * Returns an empty array for roles that cannot spawn other team agents.
23
+ */
24
+ export declare function getSpawnableRoles(role: TeamRole): TeamRole[];
@@ -0,0 +1,3 @@
1
+ import type { AgentDefinition } from '../types/agent-definition';
2
+ declare const scientist: AgentDefinition;
3
+ export default scientist;
@@ -0,0 +1,3 @@
1
+ import { type SecretAgentDefinition } from '../types/secret-agent-definition';
2
+ declare const definition: SecretAgentDefinition;
3
+ export default definition;
@@ -0,0 +1,3 @@
1
+ import type { AgentDefinition } from '../types/agent-definition';
2
+ declare const seniorStaffEngineer: AgentDefinition;
3
+ export default seniorStaffEngineer;
@@ -0,0 +1,3 @@
1
+ import type { AgentDefinition } from '../types/agent-definition';
2
+ declare const staffEngineer: AgentDefinition;
3
+ export default staffEngineer;
@@ -0,0 +1,3 @@
1
+ import type { AgentDefinition } from '../types/agent-definition';
2
+ declare const subManager: AgentDefinition;
3
+ export default subManager;
@@ -0,0 +1,3 @@
1
+ import type { AgentDefinition } from '../types/agent-definition';
2
+ declare const tester: AgentDefinition;
3
+ export default tester;
@@ -0,0 +1,3 @@
1
+ import type { AgentDefinition } from '../types/agent-definition';
2
+ declare const vpEngineering: AgentDefinition;
3
+ export default vpEngineering;
@@ -0,0 +1,296 @@
1
+ /**
2
+ * LevelCode Agent Type Definitions
3
+ *
4
+ * This file provides TypeScript type definitions for creating custom LevelCode agents.
5
+ * Import these types in your agent files to get full type safety and IntelliSense.
6
+ *
7
+ * Usage in .agents/your-agent.ts:
8
+ * import { AgentDefinition, ToolName, ModelName } from './types/agent-definition'
9
+ *
10
+ * const definition: AgentDefinition = {
11
+ * // ... your agent configuration with full type safety ...
12
+ * }
13
+ *
14
+ * export default definition
15
+ */
16
+ export interface AgentDefinition {
17
+ /** Unique identifier for this agent. Must contain only lowercase letters, numbers, and hyphens, e.g. 'code-reviewer' */
18
+ id: string;
19
+ /** Version string (if not provided, will default to '0.0.1' and be bumped on each publish) */
20
+ version?: string;
21
+ /** Publisher ID for the agent. Must be provided if you want to publish the agent. */
22
+ publisher?: string;
23
+ /** Human-readable name for the agent */
24
+ displayName: string;
25
+ /** AI model to use for this agent. Can be any model in OpenRouter: https://openrouter.ai/models */
26
+ model: ModelName;
27
+ /**
28
+ * https://openrouter.ai/docs/use-cases/reasoning-tokens
29
+ * One of `max_tokens` or `effort` is required.
30
+ * If `exclude` is true, reasoning will be removed from the response. Default is false.
31
+ */
32
+ reasoningOptions?: {
33
+ enabled?: boolean;
34
+ exclude?: boolean;
35
+ } & ({
36
+ max_tokens: number;
37
+ } | {
38
+ effort: 'high' | 'medium' | 'low' | 'minimal' | 'none';
39
+ });
40
+ /**
41
+ * Provider routing options for OpenRouter.
42
+ * Controls which providers to use and fallback behavior.
43
+ * See https://openrouter.ai/docs/features/provider-routing
44
+ */
45
+ providerOptions?: {
46
+ /**
47
+ * List of provider slugs to try in order (e.g. ["anthropic", "openai"])
48
+ */
49
+ order?: string[];
50
+ /**
51
+ * Whether to allow backup providers when primary is unavailable (default: true)
52
+ */
53
+ allow_fallbacks?: boolean;
54
+ /**
55
+ * Only use providers that support all parameters in your request (default: false)
56
+ */
57
+ require_parameters?: boolean;
58
+ /**
59
+ * Control whether to use providers that may store data
60
+ */
61
+ data_collection?: 'allow' | 'deny';
62
+ /**
63
+ * List of provider slugs to allow for this request
64
+ */
65
+ only?: string[];
66
+ /**
67
+ * List of provider slugs to skip for this request
68
+ */
69
+ ignore?: string[];
70
+ /**
71
+ * List of quantization levels to filter by (e.g. ["int4", "int8"])
72
+ */
73
+ quantizations?: Array<'int4' | 'int8' | 'fp4' | 'fp6' | 'fp8' | 'fp16' | 'bf16' | 'fp32' | 'unknown'>;
74
+ /**
75
+ * Sort providers by price, throughput, or latency
76
+ */
77
+ sort?: 'price' | 'throughput' | 'latency';
78
+ /**
79
+ * Maximum pricing you want to pay for this request
80
+ */
81
+ max_price?: {
82
+ prompt?: number | string;
83
+ completion?: number | string;
84
+ image?: number | string;
85
+ audio?: number | string;
86
+ request?: number | string;
87
+ };
88
+ };
89
+ /** MCP servers by name. Names cannot contain `/`. */
90
+ mcpServers?: Record<string, MCPConfig>;
91
+ /**
92
+ * Tools this agent can use.
93
+ *
94
+ * By default, all tools are available from any specified MCP server. In
95
+ * order to limit the tools from a specific MCP server, add the tool name(s)
96
+ * in the format `'mcpServerName/toolName1'`, `'mcpServerName/toolName2'`,
97
+ * etc.
98
+ */
99
+ toolNames?: (ToolName | (string & {}))[];
100
+ /** Other agents this agent can spawn, like 'levelcode/file-picker@0.0.1'.
101
+ *
102
+ * Use the fully qualified agent id from the agent store, including publisher and version: 'levelcode/file-picker@0.0.1'
103
+ * (publisher and version are required!)
104
+ *
105
+ * Or, use the agent id from a local agent file in your .agents directory: 'file-picker'.
106
+ */
107
+ spawnableAgents?: string[];
108
+ /** The input schema required to spawn the agent. Provide a prompt string and/or a params object or none.
109
+ * 80% of the time you want just a prompt string with a description:
110
+ * inputSchema: {
111
+ * prompt: { type: 'string', description: 'A description of what info would be helpful to the agent' }
112
+ * }
113
+ */
114
+ inputSchema?: {
115
+ prompt?: {
116
+ type: 'string';
117
+ description?: string;
118
+ };
119
+ params?: JsonObjectSchema;
120
+ };
121
+ /** How the agent should output a response to its parent (defaults to 'last_message')
122
+ *
123
+ * last_message: The last message from the agent, typically after using tools.
124
+ *
125
+ * all_messages: All messages from the agent, including tool calls and results.
126
+ *
127
+ * structured_output: Make the agent output a JSON object. Can be used with outputSchema or without if you want freeform json output.
128
+ */
129
+ outputMode?: 'last_message' | 'all_messages' | 'structured_output';
130
+ /** JSON schema for structured output (when outputMode is 'structured_output') */
131
+ outputSchema?: JsonObjectSchema;
132
+ /** Prompt for when and why to spawn this agent. Include the main purpose and use cases.
133
+ *
134
+ * This field is key if the agent is intended to be spawned by other agents. */
135
+ spawnerPrompt?: string;
136
+ /** Whether to include conversation history from the parent agent in context.
137
+ *
138
+ * Defaults to false.
139
+ * Use this when the agent needs to know all the previous messages in the conversation.
140
+ */
141
+ includeMessageHistory?: boolean;
142
+ /** Whether to inherit the parent agent's system prompt instead of using this agent's own systemPrompt.
143
+ *
144
+ * Defaults to false.
145
+ * Use this when you want to enable prompt caching by preserving the same system prompt prefix.
146
+ * Cannot be used together with the systemPrompt field.
147
+ */
148
+ inheritParentSystemPrompt?: boolean;
149
+ /** Background information for the agent. Fairly optional. Prefer using instructionsPrompt for agent instructions. */
150
+ systemPrompt?: string;
151
+ /** Instructions for the agent.
152
+ *
153
+ * IMPORTANT: Updating this prompt is the best way to shape the agent's behavior.
154
+ * This prompt is inserted after each user input. */
155
+ instructionsPrompt?: string;
156
+ /** Prompt inserted at each agent step.
157
+ *
158
+ * Powerful for changing the agent's behavior, but usually not necessary for smart models.
159
+ * Prefer instructionsPrompt for most instructions. */
160
+ stepPrompt?: string;
161
+ /** Programmatically step the agent forward and run tools.
162
+ *
163
+ * You can either yield:
164
+ * - A tool call object with toolName and input properties.
165
+ * - 'STEP' to run agent's model and generate one assistant message.
166
+ * - 'STEP_ALL' to run the agent's model until it uses the end_turn tool or stops includes no tool calls in a message.
167
+ *
168
+ * Or use 'return' to end the turn.
169
+ *
170
+ * Example 1:
171
+ * function* handleSteps({ agentState, prompt, params, logger }) {
172
+ * logger.info('Starting file read process')
173
+ * const { toolResult } = yield {
174
+ * toolName: 'read_files',
175
+ * input: { paths: ['file1.txt', 'file2.txt'] }
176
+ * }
177
+ * yield 'STEP_ALL'
178
+ *
179
+ * // Optionally do a post-processing step here...
180
+ * logger.info('Files read successfully, setting output')
181
+ * yield {
182
+ * toolName: 'set_output',
183
+ * input: {
184
+ * output: 'The files were read successfully.',
185
+ * },
186
+ * }
187
+ * }
188
+ *
189
+ * Example 2:
190
+ * handleSteps: function* ({ agentState, prompt, params, logger }) {
191
+ * while (true) {
192
+ * logger.debug('Spawning thinker agent')
193
+ * yield {
194
+ * toolName: 'spawn_agents',
195
+ * input: {
196
+ * agents: [
197
+ * {
198
+ * agent_type: 'thinker',
199
+ * prompt: 'Think deeply about the user request',
200
+ * },
201
+ * ],
202
+ * },
203
+ * }
204
+ * const { stepsComplete } = yield 'STEP'
205
+ * if (stepsComplete) break
206
+ * }
207
+ * }
208
+ */
209
+ handleSteps?: (context: AgentStepContext) => Generator<ToolCall | 'STEP' | 'STEP_ALL' | StepText | GenerateN, void, {
210
+ agentState: AgentState;
211
+ toolResult: ToolResultOutput[] | undefined;
212
+ stepsComplete: boolean;
213
+ nResponses?: string[];
214
+ }>;
215
+ }
216
+ export interface AgentState {
217
+ agentId: string;
218
+ runId: string;
219
+ parentId: string | undefined;
220
+ /** The agent's conversation history: messages from the user and the assistant. */
221
+ messageHistory: Message[];
222
+ /** The last value set by the set_output tool. This is a plain object or undefined if not set. */
223
+ output: Record<string, any> | undefined;
224
+ /** The system prompt for this agent. */
225
+ systemPrompt: string;
226
+ /** The tool definitions for this agent. */
227
+ toolDefinitions: Record<string, {
228
+ description: string | undefined;
229
+ inputSchema: {};
230
+ }>;
231
+ /**
232
+ * The token count from the Anthropic API.
233
+ * This is updated on every agent step via the /api/v1/token-count endpoint.
234
+ */
235
+ contextTokenCount: number;
236
+ }
237
+ /**
238
+ * Context provided to handleSteps generator function
239
+ */
240
+ export interface AgentStepContext {
241
+ agentState: AgentState;
242
+ prompt?: string;
243
+ params?: Record<string, any>;
244
+ logger: Logger;
245
+ }
246
+ export type StepText = {
247
+ type: 'STEP_TEXT';
248
+ text: string;
249
+ };
250
+ export type GenerateN = {
251
+ type: 'GENERATE_N';
252
+ n: number;
253
+ };
254
+ /**
255
+ * Tool call object for handleSteps generator
256
+ */
257
+ export type ToolCall<T extends ToolName = ToolName> = {
258
+ [K in T]: {
259
+ toolName: K;
260
+ input: GetToolParams<K>;
261
+ includeToolCall?: boolean;
262
+ };
263
+ }[T];
264
+ /**
265
+ * File operation tools
266
+ */
267
+ export type FileEditingTools = 'read_files' | 'write_file' | 'str_replace';
268
+ /**
269
+ * Code analysis tools
270
+ */
271
+ export type CodeAnalysisTools = 'code_search' | 'find_files' | 'read_files';
272
+ /**
273
+ * Terminal and system tools
274
+ */
275
+ export type TerminalTools = 'run_terminal_command' | 'code_search';
276
+ /**
277
+ * Web and browser tools
278
+ */
279
+ export type WebTools = 'web_search' | 'read_docs';
280
+ /**
281
+ * Agent management tools
282
+ */
283
+ export type AgentTools = 'spawn_agents';
284
+ /**
285
+ * Output and control tools
286
+ */
287
+ export type OutputTools = 'set_output';
288
+ /**
289
+ * AI models available for agents. Pick from our selection of recommended models or choose any model in OpenRouter.
290
+ *
291
+ * See available models at https://openrouter.ai/models
292
+ */
293
+ export type ModelName = 'openai/gpt-5.1' | 'openai/gpt-5.1-chat' | 'openai/gpt-5-mini' | 'openai/gpt-5-nano' | 'anthropic/claude-sonnet-4.5' | 'anthropic/claude-opus-4.1' | 'google/gemini-2.5-pro' | 'google/gemini-2.5-flash' | 'google/gemini-2.5-flash-lite' | 'google/gemini-2.5-flash-preview-09-2025' | 'google/gemini-2.5-flash-lite-preview-09-2025' | 'x-ai/grok-4-07-09' | 'x-ai/grok-4-fast' | 'x-ai/grok-code-fast-1' | 'qwen/qwen3-max' | 'qwen/qwen3-coder-plus' | 'qwen/qwen3-coder' | 'qwen/qwen3-coder:nitro' | 'qwen/qwen3-coder-flash' | 'qwen/qwen3-235b-a22b-2507' | 'qwen/qwen3-235b-a22b-2507:nitro' | 'qwen/qwen3-235b-a22b-thinking-2507' | 'qwen/qwen3-235b-a22b-thinking-2507:nitro' | 'qwen/qwen3-30b-a3b' | 'qwen/qwen3-30b-a3b:nitro' | 'deepseek/deepseek-chat-v3-0324' | 'deepseek/deepseek-chat-v3-0324:nitro' | 'deepseek/deepseek-r1-0528' | 'deepseek/deepseek-r1-0528:nitro' | 'moonshotai/kimi-k2' | 'moonshotai/kimi-k2:nitro' | 'z-ai/glm-4.6' | 'z-ai/glm-4.6:nitro' | (string & {});
294
+ import type { ToolName, GetToolParams } from './tools';
295
+ import type { Message, ToolResultOutput, JsonObjectSchema, MCPConfig, Logger } from './util-types';
296
+ export type { ToolName, GetToolParams };
@@ -0,0 +1,19 @@
1
+ import type { AgentDefinition } from './agent-definition';
2
+ import type * as Tools from './tools';
3
+ export type { Tools };
4
+ export type AllToolNames = Tools.ToolName | 'add_subgoal' | 'browser_logs' | 'create_plan' | 'spawn_agent_inline' | 'update_subgoal';
5
+ export interface SecretAgentDefinition extends Omit<AgentDefinition, 'toolNames'> {
6
+ /** Tools this agent can use. */
7
+ toolNames?: AllToolNames[];
8
+ }
9
+ declare const placeholderNames: readonly ["AGENT_NAME", "AGENTS_PROMPT", "FILE_TREE_PROMPT_SMALL", "FILE_TREE_PROMPT", "FILE_TREE_PROMPT_LARGE", "GIT_CHANGES_PROMPT", "INITIAL_AGENT_PROMPT", "KNOWLEDGE_FILES_CONTENTS", "PROJECT_ROOT", "REMAINING_STEPS", "SYSTEM_INFO_PROMPT", "TOOLS_PROMPT", "USER_CWD", "USER_INPUT_PROMPT"];
10
+ type PlaceholderType<T extends readonly string[]> = {
11
+ [K in T[number]]: `{LEVELCODE_${K}}`;
12
+ };
13
+ export declare const PLACEHOLDER: PlaceholderType<typeof placeholderNames>;
14
+ export type PlaceholderValue = (typeof PLACEHOLDER)[keyof typeof PLACEHOLDER];
15
+ export declare const placeholderValues: ("{LEVELCODE_AGENT_NAME}" | "{LEVELCODE_FILE_TREE_PROMPT_SMALL}" | "{LEVELCODE_FILE_TREE_PROMPT}" | "{LEVELCODE_FILE_TREE_PROMPT_LARGE}" | "{LEVELCODE_GIT_CHANGES_PROMPT}" | "{LEVELCODE_INITIAL_AGENT_PROMPT}" | "{LEVELCODE_KNOWLEDGE_FILES_CONTENTS}" | "{LEVELCODE_PROJECT_ROOT}" | "{LEVELCODE_REMAINING_STEPS}" | "{LEVELCODE_SYSTEM_INFO_PROMPT}" | "{LEVELCODE_USER_CWD}" | "{LEVELCODE_USER_INPUT_PROMPT}" | "{LEVELCODE_AGENTS_PROMPT}" | "{LEVELCODE_TOOLS_PROMPT}")[];
16
+ export declare const AgentTemplateTypeList: readonly ["base", "base_lite", "base_max", "base_experimental", "claude4_gemini_thinking", "superagent", "base_agent_builder", "ask", "dry_run", "thinker", "file_picker", "file_explorer", "researcher", "reviewer", "agent_builder", "example_programmatic"];
17
+ type UnderscoreToDash<S extends string> = S extends `${infer L}_${infer R}` ? `${L}-${UnderscoreToDash<R>}` : S;
18
+ export declare const AgentTemplateTypes: { [K in (typeof AgentTemplateTypeList)[number]]: UnderscoreToDash<K>; };
19
+ export type AgentTemplateType = (typeof AgentTemplateTypeList)[number] | (string & {});