@comma-agents/core 2.0.0-rc.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 (216) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +18 -0
  3. package/dist/abortable/abortable.d.ts +5 -0
  4. package/dist/abortable/abortable.types.d.ts +10 -0
  5. package/dist/abortable/index.d.ts +2 -0
  6. package/dist/agents/agent/agent.constants.d.ts +5 -0
  7. package/dist/agents/agent/agent.d.ts +24 -0
  8. package/dist/agents/agent/agent.types.d.ts +408 -0
  9. package/dist/agents/agent/agent.utils.d.ts +107 -0
  10. package/dist/agents/built-in/user/user-agent.d.ts +32 -0
  11. package/dist/agents/built-in/user/user-agent.types.d.ts +53 -0
  12. package/dist/agents/built-in/user/user-agent.utils.d.ts +2 -0
  13. package/dist/agents/hook-into-agent/hook-into-agent.d.ts +29 -0
  14. package/dist/agents/hooks/hooks.types.d.ts +64 -0
  15. package/dist/agents/hooks/hooks.utils.d.ts +9 -0
  16. package/dist/agents/hooks/index.d.ts +2 -0
  17. package/dist/agents/loader/index.d.ts +4 -0
  18. package/dist/agents/loader/loader.d.ts +49 -0
  19. package/dist/agents/loader/loader.schema.d.ts +270 -0
  20. package/dist/agents/loader/loader.types.d.ts +15 -0
  21. package/dist/conversation-context/conversation-context.d.ts +78 -0
  22. package/dist/conversation-context/conversation-context.types.d.ts +111 -0
  23. package/dist/conversation-context/conversation-context.utils.d.ts +6 -0
  24. package/dist/conversation-context/index.d.ts +3 -0
  25. package/dist/conversation-context/retention/compaction/compaction.constants.d.ts +3 -0
  26. package/dist/conversation-context/retention/compaction/compaction.d.ts +21 -0
  27. package/dist/conversation-context/retention/compaction/compaction.types.d.ts +26 -0
  28. package/dist/conversation-context/retention/compaction/index.d.ts +2 -0
  29. package/dist/conversation-context/retention/index.d.ts +4 -0
  30. package/dist/conversation-context/retention/retention.d.ts +9 -0
  31. package/dist/conversation-context/retention/retention.types.d.ts +90 -0
  32. package/dist/conversation-context/retention/retention.utils.d.ts +3 -0
  33. package/dist/conversation-context/retention/rolling-window/index.d.ts +2 -0
  34. package/dist/conversation-context/retention/rolling-window/rolling-window.d.ts +13 -0
  35. package/dist/conversation-context/retention/rolling-window/rolling-window.types.d.ts +5 -0
  36. package/dist/credentials/backends/json-file.d.ts +21 -0
  37. package/dist/credentials/credentials.constants.d.ts +9 -0
  38. package/dist/credentials/credentials.d.ts +18 -0
  39. package/dist/credentials/credentials.schema.d.ts +102 -0
  40. package/dist/credentials/credentials.types.d.ts +118 -0
  41. package/dist/credentials/credentials.utils.d.ts +30 -0
  42. package/dist/credentials/index.d.ts +6 -0
  43. package/dist/defaults/defaults.d.ts +108 -0
  44. package/dist/defaults/defaults.types.d.ts +51 -0
  45. package/dist/defaults/index.d.ts +2 -0
  46. package/dist/errors/index.d.ts +70 -0
  47. package/dist/flows/built-in/broadcast/broadcast-flow.constants.d.ts +2 -0
  48. package/dist/flows/built-in/broadcast/broadcast-flow.d.ts +30 -0
  49. package/dist/flows/built-in/cycle/cycle-flow.d.ts +53 -0
  50. package/dist/flows/built-in/sequential/sequential-flow.d.ts +25 -0
  51. package/dist/flows/flow/flow.d.ts +79 -0
  52. package/dist/flows/flow/flow.types.d.ts +179 -0
  53. package/dist/flows/flow/flow.utils.d.ts +18 -0
  54. package/dist/flows/hook-into-flow/hook-into-flow.d.ts +30 -0
  55. package/dist/flows/index.d.ts +6 -0
  56. package/dist/flows/loader/index.d.ts +4 -0
  57. package/dist/flows/loader/loader.d.ts +55 -0
  58. package/dist/flows/loader/loader.schema.d.ts +195 -0
  59. package/dist/flows/loader/loader.types.d.ts +27 -0
  60. package/dist/guard/guard.d.ts +17 -0
  61. package/dist/guard/guard.types.d.ts +112 -0
  62. package/dist/guard/index.d.ts +3 -0
  63. package/dist/guard/policies.d.ts +28 -0
  64. package/dist/hooks/built-in/token-tracking/index.d.ts +2 -0
  65. package/dist/hooks/built-in/token-tracking/token-tracking.constants.d.ts +14 -0
  66. package/dist/hooks/built-in/token-tracking/token-tracking.d.ts +87 -0
  67. package/dist/hooks/built-in/token-tracking/token-tracking.types.d.ts +136 -0
  68. package/dist/hooks/hooks.d.ts +10 -0
  69. package/dist/hooks/hooks.types.d.ts +11 -0
  70. package/dist/hooks/index.d.ts +2 -0
  71. package/dist/index.d.ts +50 -0
  72. package/dist/index.js +8961 -0
  73. package/dist/language/index.d.ts +1 -0
  74. package/dist/language/language.types.d.ts +60 -0
  75. package/dist/model/index.d.ts +5 -0
  76. package/dist/model/model.d.ts +63 -0
  77. package/dist/model/model.types.d.ts +85 -0
  78. package/dist/model/model.utils.d.ts +151 -0
  79. package/dist/model/providers/catalog/catalog.d.ts +57 -0
  80. package/dist/model/providers/catalog/catalog.types.d.ts +50 -0
  81. package/dist/model/providers/catalog/catalog.utils.d.ts +15 -0
  82. package/dist/model/providers/catalog/index.d.ts +3 -0
  83. package/dist/model/providers/index.d.ts +7 -0
  84. package/dist/model/providers/listers/copilot.d.ts +10 -0
  85. package/dist/model/providers/listers/index.d.ts +2 -0
  86. package/dist/model/providers/listers/ollama.d.ts +9 -0
  87. package/dist/model/providers/providers.d.ts +69 -0
  88. package/dist/model/providers/providers.types.d.ts +157 -0
  89. package/dist/model/providers/providers.utils.d.ts +16 -0
  90. package/dist/prompts/index.d.ts +4 -0
  91. package/dist/prompts/message-builder.d.ts +89 -0
  92. package/dist/prompts/prompts.types.d.ts +86 -0
  93. package/dist/prompts/template/prompt-template.d.ts +22 -0
  94. package/dist/sandbox/in-sandbox.d.ts +31 -0
  95. package/dist/sandbox/index.d.ts +4 -0
  96. package/dist/sandbox/sandbox.constants.d.ts +31 -0
  97. package/dist/sandbox/sandbox.d.ts +11 -0
  98. package/dist/sandbox/sandbox.types.d.ts +105 -0
  99. package/dist/skills/index.d.ts +4 -0
  100. package/dist/skills/skills.constants.d.ts +10 -0
  101. package/dist/skills/skills.loader.d.ts +46 -0
  102. package/dist/skills/skills.registry.d.ts +18 -0
  103. package/dist/skills/skills.types.d.ts +66 -0
  104. package/dist/skills/skills.utils.d.ts +37 -0
  105. package/dist/strategy/discover/discover.d.ts +16 -0
  106. package/dist/strategy/discover/discover.types.d.ts +70 -0
  107. package/dist/strategy/discover/discover.utils.d.ts +95 -0
  108. package/dist/strategy/discover/index.d.ts +3 -0
  109. package/dist/strategy/exporter/exporter.d.ts +27 -0
  110. package/dist/strategy/exporter/exporter.types.d.ts +6 -0
  111. package/dist/strategy/index.d.ts +10 -0
  112. package/dist/strategy/loader/loader.d.ts +39 -0
  113. package/dist/strategy/loader/loader.types.d.ts +106 -0
  114. package/dist/strategy/loader/loader.utils.d.ts +20 -0
  115. package/dist/strategy/loader/project-loader.d.ts +9 -0
  116. package/dist/strategy/schema.d.ts +1032 -0
  117. package/dist/timeline/index.d.ts +4 -0
  118. package/dist/timeline/projections/conversation-context.d.ts +19 -0
  119. package/dist/timeline/projections/file-state.d.ts +8 -0
  120. package/dist/timeline/projections/index.d.ts +3 -0
  121. package/dist/timeline/timeline.d.ts +11 -0
  122. package/dist/timeline/timeline.types.d.ts +97 -0
  123. package/dist/tools/build-tool-system-prompt.d.ts +41 -0
  124. package/dist/tools/built-in/ask-question/ask-question.d.ts +21 -0
  125. package/dist/tools/built-in/ask-question/index.d.ts +2 -0
  126. package/dist/tools/built-in/create-file/create-file.d.ts +18 -0
  127. package/dist/tools/built-in/create-file/create-file.types.d.ts +11 -0
  128. package/dist/tools/built-in/create-file/index.d.ts +2 -0
  129. package/dist/tools/built-in/delete-file/delete-file.constants.d.ts +14 -0
  130. package/dist/tools/built-in/delete-file/delete-file.d.ts +5 -0
  131. package/dist/tools/built-in/delete-file/delete-file.types.d.ts +26 -0
  132. package/dist/tools/built-in/delete-file/index.d.ts +2 -0
  133. package/dist/tools/built-in/describe-tool.d.ts +61 -0
  134. package/dist/tools/built-in/edit-file/edit-file.d.ts +46 -0
  135. package/dist/tools/built-in/edit-file/edit-file.replacers.d.ts +81 -0
  136. package/dist/tools/built-in/edit-file/edit-file.types.d.ts +59 -0
  137. package/dist/tools/built-in/edit-file/edit-file.utils.d.ts +70 -0
  138. package/dist/tools/built-in/edit-file/index.d.ts +2 -0
  139. package/dist/tools/built-in/glob/glob.constants.d.ts +3 -0
  140. package/dist/tools/built-in/glob/glob.d.ts +25 -0
  141. package/dist/tools/built-in/glob/glob.types.d.ts +31 -0
  142. package/dist/tools/built-in/glob/glob.utils.d.ts +4 -0
  143. package/dist/tools/built-in/glob/index.d.ts +2 -0
  144. package/dist/tools/built-in/launch-strategy/index.d.ts +2 -0
  145. package/dist/tools/built-in/launch-strategy/launch-strategy.d.ts +26 -0
  146. package/dist/tools/built-in/launch-strategy/launch-strategy.types.d.ts +14 -0
  147. package/dist/tools/built-in/list-directory/index.d.ts +2 -0
  148. package/dist/tools/built-in/list-directory/list-directory.constants.d.ts +3 -0
  149. package/dist/tools/built-in/list-directory/list-directory.d.ts +20 -0
  150. package/dist/tools/built-in/list-directory/list-directory.types.d.ts +41 -0
  151. package/dist/tools/built-in/list-directory/list-directory.utils.d.ts +4 -0
  152. package/dist/tools/built-in/list-skills/index.d.ts +2 -0
  153. package/dist/tools/built-in/list-skills/list-skills.d.ts +5 -0
  154. package/dist/tools/built-in/list-skills/list-skills.types.d.ts +10 -0
  155. package/dist/tools/built-in/list-strategy/index.d.ts +2 -0
  156. package/dist/tools/built-in/list-strategy/list-strategy.d.ts +14 -0
  157. package/dist/tools/built-in/list-strategy/list-strategy.types.d.ts +33 -0
  158. package/dist/tools/built-in/load-skill/index.d.ts +2 -0
  159. package/dist/tools/built-in/load-skill/load-skill.d.ts +24 -0
  160. package/dist/tools/built-in/load-skill/load-skill.types.d.ts +15 -0
  161. package/dist/tools/built-in/lsp-request/index.d.ts +2 -0
  162. package/dist/tools/built-in/lsp-request/lsp-request.d.ts +4 -0
  163. package/dist/tools/built-in/lsp-request/lsp-request.schema.d.ts +23 -0
  164. package/dist/tools/built-in/lsp-request/lsp-request.types.d.ts +4 -0
  165. package/dist/tools/built-in/move-file/index.d.ts +2 -0
  166. package/dist/tools/built-in/move-file/move-file.d.ts +21 -0
  167. package/dist/tools/built-in/move-file/move-file.types.d.ts +12 -0
  168. package/dist/tools/built-in/read-file/index.d.ts +2 -0
  169. package/dist/tools/built-in/read-file/read-file.constants.d.ts +1 -0
  170. package/dist/tools/built-in/read-file/read-file.d.ts +32 -0
  171. package/dist/tools/built-in/read-file/read-file.types.d.ts +34 -0
  172. package/dist/tools/built-in/read-file/read-file.utils.d.ts +14 -0
  173. package/dist/tools/built-in/restore-file/index.d.ts +2 -0
  174. package/dist/tools/built-in/restore-file/restore-file.d.ts +16 -0
  175. package/dist/tools/built-in/restore-file/restore-file.types.d.ts +11 -0
  176. package/dist/tools/built-in/run-command/index.d.ts +2 -0
  177. package/dist/tools/built-in/run-command/run-command.constants.d.ts +23 -0
  178. package/dist/tools/built-in/run-command/run-command.d.ts +21 -0
  179. package/dist/tools/built-in/run-command/run-command.types.d.ts +81 -0
  180. package/dist/tools/built-in/run-command/run-command.utils.d.ts +37 -0
  181. package/dist/tools/built-in/search-files/index.d.ts +2 -0
  182. package/dist/tools/built-in/search-files/search-files.constants.d.ts +5 -0
  183. package/dist/tools/built-in/search-files/search-files.d.ts +30 -0
  184. package/dist/tools/built-in/search-files/search-files.types.d.ts +19 -0
  185. package/dist/tools/built-in/search-files/search-files.utils.d.ts +11 -0
  186. package/dist/tools/built-in/todo/todo.d.ts +62 -0
  187. package/dist/tools/built-in/todo/todo.types.d.ts +7 -0
  188. package/dist/tools/built-in/webfetch/webfetch.constants.d.ts +3 -0
  189. package/dist/tools/built-in/webfetch/webfetch.d.ts +33 -0
  190. package/dist/tools/built-in/webfetch/webfetch.types.d.ts +8 -0
  191. package/dist/tools/built-in/webfetch/webfetch.utils.d.ts +19 -0
  192. package/dist/tools/built-in/write-file/index.d.ts +2 -0
  193. package/dist/tools/built-in/write-file/write-file.d.ts +18 -0
  194. package/dist/tools/built-in/write-file/write-file.types.d.ts +11 -0
  195. package/dist/tools/define/define-tool.d.ts +15 -0
  196. package/dist/tools/io/atomic-write.d.ts +37 -0
  197. package/dist/tools/io/audit-sink.d.ts +29 -0
  198. package/dist/tools/io/audit.types.d.ts +115 -0
  199. package/dist/tools/io/audit.utils.d.ts +48 -0
  200. package/dist/tools/io/binary.d.ts +16 -0
  201. package/dist/tools/io/bom.d.ts +15 -0
  202. package/dist/tools/io/diff.d.ts +27 -0
  203. package/dist/tools/io/hash.d.ts +25 -0
  204. package/dist/tools/io/index.d.ts +19 -0
  205. package/dist/tools/io/newline.d.ts +34 -0
  206. package/dist/tools/io/sandbox-error.d.ts +13 -0
  207. package/dist/tools/io/session-file-state.d.ts +68 -0
  208. package/dist/tools/io/stale-file.d.ts +9 -0
  209. package/dist/tools/io/trash.d.ts +57 -0
  210. package/dist/tools/launch-strategy.types.d.ts +38 -0
  211. package/dist/tools/result/index.d.ts +1 -0
  212. package/dist/tools/result/result.d.ts +47 -0
  213. package/dist/tools/tool.constants.d.ts +7 -0
  214. package/dist/tools/tool.registry.d.ts +54 -0
  215. package/dist/tools/tool.types.d.ts +191 -0
  216. package/package.json +48 -0
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Context passed to the InputCollector when requesting user input.
3
+ * Richer than a bare string — provides agent identity and cancellation.
4
+ */
5
+ export interface InputRequest {
6
+ /** Name of the agent requesting input. */
7
+ readonly agentName: string;
8
+ /** The prompt message to display to the user. */
9
+ readonly prompt: string;
10
+ /** Signal for cancellation (e.g., flow was stopped). */
11
+ readonly signal?: AbortSignal;
12
+ }
13
+ /**
14
+ * Function that collects input from the user.
15
+ * The daemon/TUI provides an implementation that bridges to the UI.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * // Simple CLI collector
20
+ * const collector: InputCollector = async ({ prompt }) => {
21
+ * return prompt(prompt) ?? "";
22
+ * };
23
+ *
24
+ * // Daemon collector (bridges to WebSocket)
25
+ * const collector: InputCollector = async ({ agentName, prompt, signal }) => {
26
+ * return wsRequestInput(agentName, prompt, signal);
27
+ * };
28
+ * ```
29
+ */
30
+ export type InputCollector = (request: InputRequest) => Promise<string>;
31
+ /** Configuration for creating a user agent. */
32
+ export interface UserAgentConfig {
33
+ /** Unique name for this agent. */
34
+ readonly name: string;
35
+ /**
36
+ * When true, the agent calls the inputCollector when no incoming message is
37
+ * available. A non-empty incoming message satisfies the user step directly.
38
+ * When false, returns `presetMessage` or passes the incoming message through.
39
+ * @default true
40
+ */
41
+ readonly requireInput?: boolean;
42
+ /**
43
+ * A preset message to return when `requireInput` is false.
44
+ * If not set and `requireInput` is false, the incoming message is passed through.
45
+ */
46
+ readonly presetMessage?: string;
47
+ /**
48
+ * Function that collects input from the user.
49
+ * Required when `requireInput` is true.
50
+ * Defaults to reading from stdin via `prompt()`.
51
+ */
52
+ readonly inputCollector?: InputCollector;
53
+ }
@@ -0,0 +1,2 @@
1
+ import type { InputCollector } from "./user-agent.types";
2
+ export declare const defaultInputCollector: InputCollector;
@@ -0,0 +1,29 @@
1
+ import type { Agent } from "../agent/agent.types";
2
+ import type { AgentHooks, ToolHooks } from "../hooks";
3
+ /**
4
+ * Append hooks to an existing agent. Mutates the agent in-place.
5
+ *
6
+ * Accepts both agent lifecycle hooks (`AgentHooks`) and tool execution
7
+ * hooks (`ToolHooks`). All hooks are appended to the agent's mutable
8
+ * internal store, so they take effect on subsequent calls.
9
+ *
10
+ * The agent must have been created by `createAgent()` (which provides
11
+ * the internal `appendHook` method). Throws if the agent doesn't support it.
12
+ *
13
+ * @param agent - An agent created by `createAgent()`.
14
+ * @param hooks - Agent lifecycle and/or tool hooks to append.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * const agent = createAgent({ name: "llm", model: "openai/gpt-4o" });
19
+ *
20
+ * hookIntoAgent(agent, {
21
+ * beforeCall: [async (message) => console.log("calling with:", message)],
22
+ * alterResponse: [async (text) => text.toUpperCase()],
23
+ * beforeToolCall: [async ({ name, args }) => console.log(`tool: ${name}`)],
24
+ * });
25
+ *
26
+ * const result = await agent.call("hello");
27
+ * ```
28
+ */
29
+ export declare function hookIntoAgent(agent: Agent, hooks: AgentHooks & ToolHooks): void;
@@ -0,0 +1,64 @@
1
+ import type { SideEffectHook, TransformHook } from "../../hooks";
2
+ import type { ToolContext } from "../../tools/tool.types";
3
+ import type { AgentCallResult, AgentStreamEvent } from "../agent/agent.types";
4
+ /**
5
+ * Agent lifecycle hooks.
6
+ *
7
+ * Execution order for a call:
8
+ * alterCallMessage → beforeCall → [LLM call] → afterCallResult → alterResponse
9
+ *
10
+ * On the first call, `*First*` variants are used if defined.
11
+ * If a `*First*` hook is not set, the corresponding base hook is used as fallback.
12
+ */
13
+ export interface AgentHooks {
14
+ /** Transform the message before the first call. Falls back to `alterCallMessage`. */
15
+ readonly alterFirstCallMessage?: ReadonlyArray<TransformHook<string>>;
16
+ /** Transform the message before subsequent calls. */
17
+ readonly alterCallMessage?: ReadonlyArray<TransformHook<string>>;
18
+ /** Side-effect before the first call. Falls back to `beforeCall`. */
19
+ readonly beforeFirstCall?: ReadonlyArray<SideEffectHook<string>>;
20
+ /** Side-effect before subsequent calls. */
21
+ readonly beforeCall?: ReadonlyArray<SideEffectHook<string>>;
22
+ /**
23
+ * Side-effect after the first call, receiving the full result including
24
+ * token usage, finish reason, and response text. Falls back to `afterCallResult`.
25
+ */
26
+ readonly afterFirstCallResult?: ReadonlyArray<SideEffectHook<AgentCallResult>>;
27
+ /**
28
+ * Side-effect fired after the call completes, receiving the full result
29
+ * including token usage, finish reason, and response text.
30
+ *
31
+ * Fires before `alterResponse`. Use this for token tracking, cost
32
+ * estimation, analytics, logging, etc.
33
+ */
34
+ readonly afterCallResult?: ReadonlyArray<SideEffectHook<AgentCallResult>>;
35
+ /** Transform the response after the first call. Falls back to `alterResponse`. */
36
+ readonly alterFirstResponse?: ReadonlyArray<TransformHook<string>>;
37
+ /** Transform the response after subsequent calls. */
38
+ readonly alterResponse?: ReadonlyArray<TransformHook<string>>;
39
+ /**
40
+ * Called for each streaming event during an agent's LLM call.
41
+ * Fires when `agent.stream()` is called directly.
42
+ */
43
+ readonly onStreamEvent?: ReadonlyArray<SideEffectHook<AgentStreamEvent>>;
44
+ }
45
+ /**
46
+ * Tool lifecycle hooks.
47
+ *
48
+ * Executed around each individual tool invocation within an agent call.
49
+ */
50
+ export interface ToolHooks {
51
+ /** Called before a tool is executed. */
52
+ readonly beforeToolCall?: ReadonlyArray<SideEffectHook<{
53
+ readonly name: string;
54
+ readonly args: string;
55
+ readonly toolContext: ToolContext;
56
+ }>>;
57
+ /** Called after a tool is executed. */
58
+ readonly afterToolCall?: ReadonlyArray<SideEffectHook<{
59
+ readonly name: string;
60
+ readonly args: string;
61
+ readonly result: string;
62
+ readonly toolContext: ToolContext;
63
+ }>>;
64
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Resolve hooks for a given lifecycle point, handling initial vs regular
3
+ * selection with fallback.
4
+ *
5
+ * On the first call (`isFirst = true`), the initial variant is preferred.
6
+ * If not defined, falls back to the regular variant.
7
+ * On subsequent calls, the regular variant is always used.
8
+ */
9
+ export declare function resolveHook<HookType>(initialHooks: ReadonlyArray<HookType> | undefined, regularHooks: ReadonlyArray<HookType> | undefined, isFirst: boolean): ReadonlyArray<HookType> | undefined;
@@ -0,0 +1,2 @@
1
+ export type { AgentHooks, ToolHooks } from "./hooks.types";
2
+ export { resolveHook } from "./hooks.utils";
@@ -0,0 +1,4 @@
1
+ export { loadAgent, loadAgentFromString } from "./loader";
2
+ export type { AgentDescription } from "./loader.schema";
3
+ export { AgentDescriptionSchema } from "./loader.schema";
4
+ export type { LoadAgentOptions } from "./loader.types";
@@ -0,0 +1,49 @@
1
+ import type { Agent } from "../agent/agent.types";
2
+ import type { LoadAgentOptions } from "./loader.types";
3
+ /**
4
+ * Load a single agent from a JSON or YAML description file.
5
+ *
6
+ * Auto-detects format by file extension (`.json`, `.yaml`, `.yml`).
7
+ * Validates the structure, resolves model and tools, and returns a
8
+ * live `Agent` ready to call.
9
+ *
10
+ * @param filePath - Absolute or relative path to the agent description file.
11
+ * @param options - Hooks, abort signal.
12
+ * Optional — when omitted, global defaults are used for model resolution.
13
+ * @returns A live Agent instance.
14
+ * @throws {StrategyValidationError} If the file is invalid or missing required fields.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import { loadAgent } from "@comma-agents/core";
19
+ *
20
+ * // Zero-config — uses global credential store and provider resolver
21
+ * const agent = await loadAgent("./agents/researcher.yaml");
22
+ * const result = await agent.call("What is TypeScript?");
23
+ * ```
24
+ */
25
+ export declare function loadAgent(filePath: string, options?: LoadAgentOptions): Promise<Agent>;
26
+ /**
27
+ * Load a single agent from a raw JSON or YAML string.
28
+ *
29
+ * Useful when the content is already in memory (e.g., received over
30
+ * a WebSocket, from a database, or from a test fixture).
31
+ *
32
+ * @param content - The raw agent description string.
33
+ * @param format - "json" or "yaml".
34
+ * @param options - Hooks, abort signal.
35
+ * Optional — when omitted, global defaults are used for model resolution.
36
+ * @returns A live Agent instance.
37
+ * @throws {StrategyValidationError} If parsing or validation fails.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * const yaml = `
42
+ * name: writer
43
+ * model: openai/gpt-4o
44
+ * systemPrompt: You are a creative writer.
45
+ * `;
46
+ * const agent = await loadAgentFromString(yaml, "yaml");
47
+ * ```
48
+ */
49
+ export declare function loadAgentFromString(content: string, format: "json" | "yaml", _options?: LoadAgentOptions): Promise<Agent>;
@@ -0,0 +1,270 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * System prompt template — a Liquid template with optional default variables.
4
+ *
5
+ * Mirrors the `systemPromptTemplate` field from the strategy schema but
6
+ * scoped to a single agent description file.
7
+ */
8
+ export declare const SystemPromptTemplateSchema: z.ZodObject<{
9
+ template: z.ZodString;
10
+ variables: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString, "many">, z.ZodRecord<z.ZodString, z.ZodString>]>>>;
11
+ }, "strict", z.ZodTypeAny, {
12
+ template: string;
13
+ variables?: Record<string, string | number | boolean | string[] | Record<string, string>> | undefined;
14
+ }, {
15
+ template: string;
16
+ variables?: Record<string, string | number | boolean | string[] | Record<string, string>> | undefined;
17
+ }>;
18
+ /**
19
+ * Model-level generation parameters forwarded to `streamText`.
20
+ *
21
+ * These are provider-agnostic options supported by virtually every LLM
22
+ * provider. Provider-specific features (extended thinking, reasoning
23
+ * effort) should use `providerOptions` instead.
24
+ */
25
+ export declare const ModelOptionsSchema: z.ZodObject<{
26
+ temperature: z.ZodOptional<z.ZodNumber>;
27
+ topP: z.ZodOptional<z.ZodNumber>;
28
+ topK: z.ZodOptional<z.ZodNumber>;
29
+ maxOutputTokens: z.ZodOptional<z.ZodNumber>;
30
+ maxRetries: z.ZodOptional<z.ZodNumber>;
31
+ frequencyPenalty: z.ZodOptional<z.ZodNumber>;
32
+ presencePenalty: z.ZodOptional<z.ZodNumber>;
33
+ seed: z.ZodOptional<z.ZodNumber>;
34
+ }, "strict", z.ZodTypeAny, {
35
+ temperature?: number | undefined;
36
+ topP?: number | undefined;
37
+ topK?: number | undefined;
38
+ maxOutputTokens?: number | undefined;
39
+ maxRetries?: number | undefined;
40
+ frequencyPenalty?: number | undefined;
41
+ presencePenalty?: number | undefined;
42
+ seed?: number | undefined;
43
+ }, {
44
+ temperature?: number | undefined;
45
+ topP?: number | undefined;
46
+ topK?: number | undefined;
47
+ maxOutputTokens?: number | undefined;
48
+ maxRetries?: number | undefined;
49
+ frequencyPenalty?: number | undefined;
50
+ presencePenalty?: number | undefined;
51
+ seed?: number | undefined;
52
+ }>;
53
+ /** JSON Schema object used for structured agent output in YAML/JSON files. */
54
+ export declare const OutputSchemaSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
55
+ /** Serializable conversation context controls for JSON/YAML definitions. */
56
+ export declare const ConversationContextSchema: z.ZodObject<{
57
+ rollingWindow: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodObject<{
58
+ maxRecords: z.ZodNumber;
59
+ }, "strict", z.ZodTypeAny, {
60
+ maxRecords: number;
61
+ }, {
62
+ maxRecords: number;
63
+ }>]>>;
64
+ compaction: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodObject<{
65
+ keepRecent: z.ZodOptional<z.ZodNumber>;
66
+ threshold: z.ZodOptional<z.ZodNumber>;
67
+ }, "strict", z.ZodTypeAny, {
68
+ keepRecent?: number | undefined;
69
+ threshold?: number | undefined;
70
+ }, {
71
+ keepRecent?: number | undefined;
72
+ threshold?: number | undefined;
73
+ }>]>>;
74
+ }, "strict", z.ZodTypeAny, {
75
+ rollingWindow?: number | {
76
+ maxRecords: number;
77
+ } | undefined;
78
+ compaction?: boolean | {
79
+ keepRecent?: number | undefined;
80
+ threshold?: number | undefined;
81
+ } | undefined;
82
+ }, {
83
+ rollingWindow?: number | {
84
+ maxRecords: number;
85
+ } | undefined;
86
+ compaction?: boolean | {
87
+ keepRecent?: number | undefined;
88
+ threshold?: number | undefined;
89
+ } | undefined;
90
+ }>;
91
+ /**
92
+ * Agent description schema — validates a standalone agent description file.
93
+ *
94
+ * @example
95
+ * ```yaml
96
+ * name: researcher
97
+ * model: openai/gpt-4o
98
+ * systemPrompt: You are a research assistant.
99
+ * tools:
100
+ * - read
101
+ * - grep
102
+ * ```
103
+ */
104
+ export declare const AgentDescriptionSchema: z.ZodObject<{
105
+ /** Unique name for this agent. */
106
+ name: z.ZodString;
107
+ /** Optional human-readable description. */
108
+ description: z.ZodOptional<z.ZodString>;
109
+ /** Model string in "providerID/modelID" format (e.g., "openai/gpt-4o"). */
110
+ model: z.ZodString;
111
+ /** Static system prompt sent to the model. Mutually exclusive with systemPromptTemplate. */
112
+ systemPrompt: z.ZodOptional<z.ZodString>;
113
+ /** Dynamic system prompt using Liquid template syntax. */
114
+ systemPromptTemplate: z.ZodOptional<z.ZodObject<{
115
+ template: z.ZodString;
116
+ variables: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString, "many">, z.ZodRecord<z.ZodString, z.ZodString>]>>>;
117
+ }, "strict", z.ZodTypeAny, {
118
+ template: string;
119
+ variables?: Record<string, string | number | boolean | string[] | Record<string, string>> | undefined;
120
+ }, {
121
+ template: string;
122
+ variables?: Record<string, string | number | boolean | string[] | Record<string, string>> | undefined;
123
+ }>>;
124
+ /** Tool names to make available to the agent. */
125
+ tools: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
126
+ /**
127
+ * Per-call provider options forwarded verbatim to the AI SDK. Used to
128
+ * enable provider-specific features such as Anthropic extended thinking
129
+ * or OpenAI reasoning effort. Shape:
130
+ * `{ <providerId>: { <option>: <value>, ... }, ... }`.
131
+ */
132
+ providerOptions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
133
+ /** Model-level generation parameters (temperature, maxTokens, etc.). */
134
+ modelOptions: z.ZodOptional<z.ZodObject<{
135
+ temperature: z.ZodOptional<z.ZodNumber>;
136
+ topP: z.ZodOptional<z.ZodNumber>;
137
+ topK: z.ZodOptional<z.ZodNumber>;
138
+ maxOutputTokens: z.ZodOptional<z.ZodNumber>;
139
+ maxRetries: z.ZodOptional<z.ZodNumber>;
140
+ frequencyPenalty: z.ZodOptional<z.ZodNumber>;
141
+ presencePenalty: z.ZodOptional<z.ZodNumber>;
142
+ seed: z.ZodOptional<z.ZodNumber>;
143
+ }, "strict", z.ZodTypeAny, {
144
+ temperature?: number | undefined;
145
+ topP?: number | undefined;
146
+ topK?: number | undefined;
147
+ maxOutputTokens?: number | undefined;
148
+ maxRetries?: number | undefined;
149
+ frequencyPenalty?: number | undefined;
150
+ presencePenalty?: number | undefined;
151
+ seed?: number | undefined;
152
+ }, {
153
+ temperature?: number | undefined;
154
+ topP?: number | undefined;
155
+ topK?: number | undefined;
156
+ maxOutputTokens?: number | undefined;
157
+ maxRetries?: number | undefined;
158
+ frequencyPenalty?: number | undefined;
159
+ presencePenalty?: number | undefined;
160
+ seed?: number | undefined;
161
+ }>>;
162
+ /** JSON Schema describing the agent's structured output. */
163
+ outputSchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
164
+ /** Conversation context retention and compaction controls. */
165
+ context: z.ZodOptional<z.ZodObject<{
166
+ rollingWindow: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodObject<{
167
+ maxRecords: z.ZodNumber;
168
+ }, "strict", z.ZodTypeAny, {
169
+ maxRecords: number;
170
+ }, {
171
+ maxRecords: number;
172
+ }>]>>;
173
+ compaction: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodObject<{
174
+ keepRecent: z.ZodOptional<z.ZodNumber>;
175
+ threshold: z.ZodOptional<z.ZodNumber>;
176
+ }, "strict", z.ZodTypeAny, {
177
+ keepRecent?: number | undefined;
178
+ threshold?: number | undefined;
179
+ }, {
180
+ keepRecent?: number | undefined;
181
+ threshold?: number | undefined;
182
+ }>]>>;
183
+ }, "strict", z.ZodTypeAny, {
184
+ rollingWindow?: number | {
185
+ maxRecords: number;
186
+ } | undefined;
187
+ compaction?: boolean | {
188
+ keepRecent?: number | undefined;
189
+ threshold?: number | undefined;
190
+ } | undefined;
191
+ }, {
192
+ rollingWindow?: number | {
193
+ maxRecords: number;
194
+ } | undefined;
195
+ compaction?: boolean | {
196
+ keepRecent?: number | undefined;
197
+ threshold?: number | undefined;
198
+ } | undefined;
199
+ }>>;
200
+ /**
201
+ * Maximum number of LLM round-trips (steps) per call.
202
+ * Each tool-call + response counts as one step.
203
+ */
204
+ maxSteps: z.ZodOptional<z.ZodNumber>;
205
+ }, "strict", z.ZodTypeAny, {
206
+ name: string;
207
+ model: string;
208
+ description?: string | undefined;
209
+ systemPrompt?: string | undefined;
210
+ systemPromptTemplate?: {
211
+ template: string;
212
+ variables?: Record<string, string | number | boolean | string[] | Record<string, string>> | undefined;
213
+ } | undefined;
214
+ tools?: string[] | undefined;
215
+ providerOptions?: Record<string, Record<string, unknown>> | undefined;
216
+ modelOptions?: {
217
+ temperature?: number | undefined;
218
+ topP?: number | undefined;
219
+ topK?: number | undefined;
220
+ maxOutputTokens?: number | undefined;
221
+ maxRetries?: number | undefined;
222
+ frequencyPenalty?: number | undefined;
223
+ presencePenalty?: number | undefined;
224
+ seed?: number | undefined;
225
+ } | undefined;
226
+ outputSchema?: Record<string, unknown> | undefined;
227
+ context?: {
228
+ rollingWindow?: number | {
229
+ maxRecords: number;
230
+ } | undefined;
231
+ compaction?: boolean | {
232
+ keepRecent?: number | undefined;
233
+ threshold?: number | undefined;
234
+ } | undefined;
235
+ } | undefined;
236
+ maxSteps?: number | undefined;
237
+ }, {
238
+ name: string;
239
+ model: string;
240
+ description?: string | undefined;
241
+ systemPrompt?: string | undefined;
242
+ systemPromptTemplate?: {
243
+ template: string;
244
+ variables?: Record<string, string | number | boolean | string[] | Record<string, string>> | undefined;
245
+ } | undefined;
246
+ tools?: string[] | undefined;
247
+ providerOptions?: Record<string, Record<string, unknown>> | undefined;
248
+ modelOptions?: {
249
+ temperature?: number | undefined;
250
+ topP?: number | undefined;
251
+ topK?: number | undefined;
252
+ maxOutputTokens?: number | undefined;
253
+ maxRetries?: number | undefined;
254
+ frequencyPenalty?: number | undefined;
255
+ presencePenalty?: number | undefined;
256
+ seed?: number | undefined;
257
+ } | undefined;
258
+ outputSchema?: Record<string, unknown> | undefined;
259
+ context?: {
260
+ rollingWindow?: number | {
261
+ maxRecords: number;
262
+ } | undefined;
263
+ compaction?: boolean | {
264
+ keepRecent?: number | undefined;
265
+ threshold?: number | undefined;
266
+ } | undefined;
267
+ } | undefined;
268
+ maxSteps?: number | undefined;
269
+ }>;
270
+ export type AgentDescription = z.infer<typeof AgentDescriptionSchema>;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Options for loading an agent from a description file.
3
+ *
4
+ * All fields are optional. Model and tool resolution are handled
5
+ * internally by `createAgent()` using the global provider registry
6
+ * (`registerProvider()`), model registry (`registerModel()`), and
7
+ * tool registry (`registerTool()`).
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * // Zero-config — uses global credential store and provider resolver
12
+ * const agent = await loadAgent("./agents/researcher.yaml");
13
+ * ```
14
+ */
15
+ export type LoadAgentOptions = Record<never, never>;
@@ -0,0 +1,78 @@
1
+ import type { ModelMessage } from "ai";
2
+ import type { ContextUsage, ConversationContext, ConversationContextOptions, ConversationRecord, CreateConversationRecordInput } from "./conversation-context.types";
3
+ /**
4
+ * Create a per-agent conversation context with import/export helpers for
5
+ * the canonical conversation record contract.
6
+ *
7
+ * Optional retention settings run via `prepareForCall` before each call,
8
+ * transforming the effective history non-destructively. The full record list
9
+ * is always retained for export.
10
+ *
11
+ * @param options - Optional retention configuration.
12
+ * @example
13
+ * ```ts
14
+ * const context = createConversationContext();
15
+ * context.appendRecord(record);
16
+ * const messages = context.messages();
17
+ * ```
18
+ */
19
+ export declare function createConversationContext(options?: ConversationContextOptions): ConversationContext;
20
+ /**
21
+ * Build a canonical conversation record from an agent call result.
22
+ *
23
+ * @param input - Agent call data used to construct the record.
24
+ * @example
25
+ * ```ts
26
+ * const record = createConversationRecord({
27
+ * agentName: "assistant",
28
+ * userMessage: "Hello",
29
+ * responseMessages: result.responseMessages,
30
+ * text: result.text,
31
+ * usage: result.usage,
32
+ * finishReason: result.finishReason,
33
+ * });
34
+ * ```
35
+ */
36
+ export declare function createConversationRecord(input: CreateConversationRecordInput): ConversationRecord;
37
+ /**
38
+ * Parse newline-delimited conversation records.
39
+ *
40
+ * @param jsonl - JSONL string containing one conversation record per line.
41
+ * @example
42
+ * ```ts
43
+ * const records = parseConversationJsonl(savedContext);
44
+ * ```
45
+ */
46
+ export declare function parseConversationJsonl(jsonl: string): readonly ConversationRecord[];
47
+ /** Parse a JSON array of canonical conversation records. */
48
+ export declare function parseConversationJson(json: string): readonly ConversationRecord[];
49
+ /** Serialize conversation records as pretty JSON. */
50
+ export declare function serializeConversationRecordsJson(records: readonly ConversationRecord[]): string;
51
+ /** Parse YAML containing an array of canonical conversation records. */
52
+ export declare function parseConversationYaml(yaml: string): readonly ConversationRecord[];
53
+ /** Serialize conversation records as YAML. */
54
+ export declare function serializeConversationRecordsYaml(records: readonly ConversationRecord[]): string;
55
+ /**
56
+ * Serialize conversation records to newline-delimited JSON.
57
+ *
58
+ * @param records - Conversation records to serialize.
59
+ * @example
60
+ * ```ts
61
+ * const jsonl = serializeConversationRecords(context.records());
62
+ * ```
63
+ */
64
+ export declare function serializeConversationRecords(records: readonly ConversationRecord[]): string;
65
+ /**
66
+ * Serialize a single conversation record to one JSONL line.
67
+ *
68
+ * @param record - Conversation record to serialize.
69
+ * @example
70
+ * ```ts
71
+ * const line = recordToJsonlLine(record);
72
+ * ```
73
+ */
74
+ export declare function recordToJsonlLine(record: ConversationRecord): string;
75
+ /** Flatten conversation records into the AI SDK message array shape. */
76
+ export declare function recordsToMessages(records: readonly ConversationRecord[]): readonly ModelMessage[];
77
+ /** Return normalized context usage from the final model step. */
78
+ export declare function contextUsageFromSteps(steps: readonly unknown[] | undefined): ContextUsage | undefined;