@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.
- package/LICENSE +21 -0
- package/README.md +18 -0
- package/dist/abortable/abortable.d.ts +5 -0
- package/dist/abortable/abortable.types.d.ts +10 -0
- package/dist/abortable/index.d.ts +2 -0
- package/dist/agents/agent/agent.constants.d.ts +5 -0
- package/dist/agents/agent/agent.d.ts +24 -0
- package/dist/agents/agent/agent.types.d.ts +408 -0
- package/dist/agents/agent/agent.utils.d.ts +107 -0
- package/dist/agents/built-in/user/user-agent.d.ts +32 -0
- package/dist/agents/built-in/user/user-agent.types.d.ts +53 -0
- package/dist/agents/built-in/user/user-agent.utils.d.ts +2 -0
- package/dist/agents/hook-into-agent/hook-into-agent.d.ts +29 -0
- package/dist/agents/hooks/hooks.types.d.ts +64 -0
- package/dist/agents/hooks/hooks.utils.d.ts +9 -0
- package/dist/agents/hooks/index.d.ts +2 -0
- package/dist/agents/loader/index.d.ts +4 -0
- package/dist/agents/loader/loader.d.ts +49 -0
- package/dist/agents/loader/loader.schema.d.ts +270 -0
- package/dist/agents/loader/loader.types.d.ts +15 -0
- package/dist/conversation-context/conversation-context.d.ts +78 -0
- package/dist/conversation-context/conversation-context.types.d.ts +111 -0
- package/dist/conversation-context/conversation-context.utils.d.ts +6 -0
- package/dist/conversation-context/index.d.ts +3 -0
- package/dist/conversation-context/retention/compaction/compaction.constants.d.ts +3 -0
- package/dist/conversation-context/retention/compaction/compaction.d.ts +21 -0
- package/dist/conversation-context/retention/compaction/compaction.types.d.ts +26 -0
- package/dist/conversation-context/retention/compaction/index.d.ts +2 -0
- package/dist/conversation-context/retention/index.d.ts +4 -0
- package/dist/conversation-context/retention/retention.d.ts +9 -0
- package/dist/conversation-context/retention/retention.types.d.ts +90 -0
- package/dist/conversation-context/retention/retention.utils.d.ts +3 -0
- package/dist/conversation-context/retention/rolling-window/index.d.ts +2 -0
- package/dist/conversation-context/retention/rolling-window/rolling-window.d.ts +13 -0
- package/dist/conversation-context/retention/rolling-window/rolling-window.types.d.ts +5 -0
- package/dist/credentials/backends/json-file.d.ts +21 -0
- package/dist/credentials/credentials.constants.d.ts +9 -0
- package/dist/credentials/credentials.d.ts +18 -0
- package/dist/credentials/credentials.schema.d.ts +102 -0
- package/dist/credentials/credentials.types.d.ts +118 -0
- package/dist/credentials/credentials.utils.d.ts +30 -0
- package/dist/credentials/index.d.ts +6 -0
- package/dist/defaults/defaults.d.ts +108 -0
- package/dist/defaults/defaults.types.d.ts +51 -0
- package/dist/defaults/index.d.ts +2 -0
- package/dist/errors/index.d.ts +70 -0
- package/dist/flows/built-in/broadcast/broadcast-flow.constants.d.ts +2 -0
- package/dist/flows/built-in/broadcast/broadcast-flow.d.ts +30 -0
- package/dist/flows/built-in/cycle/cycle-flow.d.ts +53 -0
- package/dist/flows/built-in/sequential/sequential-flow.d.ts +25 -0
- package/dist/flows/flow/flow.d.ts +79 -0
- package/dist/flows/flow/flow.types.d.ts +179 -0
- package/dist/flows/flow/flow.utils.d.ts +18 -0
- package/dist/flows/hook-into-flow/hook-into-flow.d.ts +30 -0
- package/dist/flows/index.d.ts +6 -0
- package/dist/flows/loader/index.d.ts +4 -0
- package/dist/flows/loader/loader.d.ts +55 -0
- package/dist/flows/loader/loader.schema.d.ts +195 -0
- package/dist/flows/loader/loader.types.d.ts +27 -0
- package/dist/guard/guard.d.ts +17 -0
- package/dist/guard/guard.types.d.ts +112 -0
- package/dist/guard/index.d.ts +3 -0
- package/dist/guard/policies.d.ts +28 -0
- package/dist/hooks/built-in/token-tracking/index.d.ts +2 -0
- package/dist/hooks/built-in/token-tracking/token-tracking.constants.d.ts +14 -0
- package/dist/hooks/built-in/token-tracking/token-tracking.d.ts +87 -0
- package/dist/hooks/built-in/token-tracking/token-tracking.types.d.ts +136 -0
- package/dist/hooks/hooks.d.ts +10 -0
- package/dist/hooks/hooks.types.d.ts +11 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +8961 -0
- package/dist/language/index.d.ts +1 -0
- package/dist/language/language.types.d.ts +60 -0
- package/dist/model/index.d.ts +5 -0
- package/dist/model/model.d.ts +63 -0
- package/dist/model/model.types.d.ts +85 -0
- package/dist/model/model.utils.d.ts +151 -0
- package/dist/model/providers/catalog/catalog.d.ts +57 -0
- package/dist/model/providers/catalog/catalog.types.d.ts +50 -0
- package/dist/model/providers/catalog/catalog.utils.d.ts +15 -0
- package/dist/model/providers/catalog/index.d.ts +3 -0
- package/dist/model/providers/index.d.ts +7 -0
- package/dist/model/providers/listers/copilot.d.ts +10 -0
- package/dist/model/providers/listers/index.d.ts +2 -0
- package/dist/model/providers/listers/ollama.d.ts +9 -0
- package/dist/model/providers/providers.d.ts +69 -0
- package/dist/model/providers/providers.types.d.ts +157 -0
- package/dist/model/providers/providers.utils.d.ts +16 -0
- package/dist/prompts/index.d.ts +4 -0
- package/dist/prompts/message-builder.d.ts +89 -0
- package/dist/prompts/prompts.types.d.ts +86 -0
- package/dist/prompts/template/prompt-template.d.ts +22 -0
- package/dist/sandbox/in-sandbox.d.ts +31 -0
- package/dist/sandbox/index.d.ts +4 -0
- package/dist/sandbox/sandbox.constants.d.ts +31 -0
- package/dist/sandbox/sandbox.d.ts +11 -0
- package/dist/sandbox/sandbox.types.d.ts +105 -0
- package/dist/skills/index.d.ts +4 -0
- package/dist/skills/skills.constants.d.ts +10 -0
- package/dist/skills/skills.loader.d.ts +46 -0
- package/dist/skills/skills.registry.d.ts +18 -0
- package/dist/skills/skills.types.d.ts +66 -0
- package/dist/skills/skills.utils.d.ts +37 -0
- package/dist/strategy/discover/discover.d.ts +16 -0
- package/dist/strategy/discover/discover.types.d.ts +70 -0
- package/dist/strategy/discover/discover.utils.d.ts +95 -0
- package/dist/strategy/discover/index.d.ts +3 -0
- package/dist/strategy/exporter/exporter.d.ts +27 -0
- package/dist/strategy/exporter/exporter.types.d.ts +6 -0
- package/dist/strategy/index.d.ts +10 -0
- package/dist/strategy/loader/loader.d.ts +39 -0
- package/dist/strategy/loader/loader.types.d.ts +106 -0
- package/dist/strategy/loader/loader.utils.d.ts +20 -0
- package/dist/strategy/loader/project-loader.d.ts +9 -0
- package/dist/strategy/schema.d.ts +1032 -0
- package/dist/timeline/index.d.ts +4 -0
- package/dist/timeline/projections/conversation-context.d.ts +19 -0
- package/dist/timeline/projections/file-state.d.ts +8 -0
- package/dist/timeline/projections/index.d.ts +3 -0
- package/dist/timeline/timeline.d.ts +11 -0
- package/dist/timeline/timeline.types.d.ts +97 -0
- package/dist/tools/build-tool-system-prompt.d.ts +41 -0
- package/dist/tools/built-in/ask-question/ask-question.d.ts +21 -0
- package/dist/tools/built-in/ask-question/index.d.ts +2 -0
- package/dist/tools/built-in/create-file/create-file.d.ts +18 -0
- package/dist/tools/built-in/create-file/create-file.types.d.ts +11 -0
- package/dist/tools/built-in/create-file/index.d.ts +2 -0
- package/dist/tools/built-in/delete-file/delete-file.constants.d.ts +14 -0
- package/dist/tools/built-in/delete-file/delete-file.d.ts +5 -0
- package/dist/tools/built-in/delete-file/delete-file.types.d.ts +26 -0
- package/dist/tools/built-in/delete-file/index.d.ts +2 -0
- package/dist/tools/built-in/describe-tool.d.ts +61 -0
- package/dist/tools/built-in/edit-file/edit-file.d.ts +46 -0
- package/dist/tools/built-in/edit-file/edit-file.replacers.d.ts +81 -0
- package/dist/tools/built-in/edit-file/edit-file.types.d.ts +59 -0
- package/dist/tools/built-in/edit-file/edit-file.utils.d.ts +70 -0
- package/dist/tools/built-in/edit-file/index.d.ts +2 -0
- package/dist/tools/built-in/glob/glob.constants.d.ts +3 -0
- package/dist/tools/built-in/glob/glob.d.ts +25 -0
- package/dist/tools/built-in/glob/glob.types.d.ts +31 -0
- package/dist/tools/built-in/glob/glob.utils.d.ts +4 -0
- package/dist/tools/built-in/glob/index.d.ts +2 -0
- package/dist/tools/built-in/launch-strategy/index.d.ts +2 -0
- package/dist/tools/built-in/launch-strategy/launch-strategy.d.ts +26 -0
- package/dist/tools/built-in/launch-strategy/launch-strategy.types.d.ts +14 -0
- package/dist/tools/built-in/list-directory/index.d.ts +2 -0
- package/dist/tools/built-in/list-directory/list-directory.constants.d.ts +3 -0
- package/dist/tools/built-in/list-directory/list-directory.d.ts +20 -0
- package/dist/tools/built-in/list-directory/list-directory.types.d.ts +41 -0
- package/dist/tools/built-in/list-directory/list-directory.utils.d.ts +4 -0
- package/dist/tools/built-in/list-skills/index.d.ts +2 -0
- package/dist/tools/built-in/list-skills/list-skills.d.ts +5 -0
- package/dist/tools/built-in/list-skills/list-skills.types.d.ts +10 -0
- package/dist/tools/built-in/list-strategy/index.d.ts +2 -0
- package/dist/tools/built-in/list-strategy/list-strategy.d.ts +14 -0
- package/dist/tools/built-in/list-strategy/list-strategy.types.d.ts +33 -0
- package/dist/tools/built-in/load-skill/index.d.ts +2 -0
- package/dist/tools/built-in/load-skill/load-skill.d.ts +24 -0
- package/dist/tools/built-in/load-skill/load-skill.types.d.ts +15 -0
- package/dist/tools/built-in/lsp-request/index.d.ts +2 -0
- package/dist/tools/built-in/lsp-request/lsp-request.d.ts +4 -0
- package/dist/tools/built-in/lsp-request/lsp-request.schema.d.ts +23 -0
- package/dist/tools/built-in/lsp-request/lsp-request.types.d.ts +4 -0
- package/dist/tools/built-in/move-file/index.d.ts +2 -0
- package/dist/tools/built-in/move-file/move-file.d.ts +21 -0
- package/dist/tools/built-in/move-file/move-file.types.d.ts +12 -0
- package/dist/tools/built-in/read-file/index.d.ts +2 -0
- package/dist/tools/built-in/read-file/read-file.constants.d.ts +1 -0
- package/dist/tools/built-in/read-file/read-file.d.ts +32 -0
- package/dist/tools/built-in/read-file/read-file.types.d.ts +34 -0
- package/dist/tools/built-in/read-file/read-file.utils.d.ts +14 -0
- package/dist/tools/built-in/restore-file/index.d.ts +2 -0
- package/dist/tools/built-in/restore-file/restore-file.d.ts +16 -0
- package/dist/tools/built-in/restore-file/restore-file.types.d.ts +11 -0
- package/dist/tools/built-in/run-command/index.d.ts +2 -0
- package/dist/tools/built-in/run-command/run-command.constants.d.ts +23 -0
- package/dist/tools/built-in/run-command/run-command.d.ts +21 -0
- package/dist/tools/built-in/run-command/run-command.types.d.ts +81 -0
- package/dist/tools/built-in/run-command/run-command.utils.d.ts +37 -0
- package/dist/tools/built-in/search-files/index.d.ts +2 -0
- package/dist/tools/built-in/search-files/search-files.constants.d.ts +5 -0
- package/dist/tools/built-in/search-files/search-files.d.ts +30 -0
- package/dist/tools/built-in/search-files/search-files.types.d.ts +19 -0
- package/dist/tools/built-in/search-files/search-files.utils.d.ts +11 -0
- package/dist/tools/built-in/todo/todo.d.ts +62 -0
- package/dist/tools/built-in/todo/todo.types.d.ts +7 -0
- package/dist/tools/built-in/webfetch/webfetch.constants.d.ts +3 -0
- package/dist/tools/built-in/webfetch/webfetch.d.ts +33 -0
- package/dist/tools/built-in/webfetch/webfetch.types.d.ts +8 -0
- package/dist/tools/built-in/webfetch/webfetch.utils.d.ts +19 -0
- package/dist/tools/built-in/write-file/index.d.ts +2 -0
- package/dist/tools/built-in/write-file/write-file.d.ts +18 -0
- package/dist/tools/built-in/write-file/write-file.types.d.ts +11 -0
- package/dist/tools/define/define-tool.d.ts +15 -0
- package/dist/tools/io/atomic-write.d.ts +37 -0
- package/dist/tools/io/audit-sink.d.ts +29 -0
- package/dist/tools/io/audit.types.d.ts +115 -0
- package/dist/tools/io/audit.utils.d.ts +48 -0
- package/dist/tools/io/binary.d.ts +16 -0
- package/dist/tools/io/bom.d.ts +15 -0
- package/dist/tools/io/diff.d.ts +27 -0
- package/dist/tools/io/hash.d.ts +25 -0
- package/dist/tools/io/index.d.ts +19 -0
- package/dist/tools/io/newline.d.ts +34 -0
- package/dist/tools/io/sandbox-error.d.ts +13 -0
- package/dist/tools/io/session-file-state.d.ts +68 -0
- package/dist/tools/io/stale-file.d.ts +9 -0
- package/dist/tools/io/trash.d.ts +57 -0
- package/dist/tools/launch-strategy.types.d.ts +38 -0
- package/dist/tools/result/index.d.ts +1 -0
- package/dist/tools/result/result.d.ts +47 -0
- package/dist/tools/tool.constants.d.ts +7 -0
- package/dist/tools/tool.registry.d.ts +54 -0
- package/dist/tools/tool.types.d.ts +191 -0
- package/package.json +48 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { CredentialStore } from "../credentials/credentials.types";
|
|
2
|
+
import type { ProviderResolver } from "../model/model.types";
|
|
3
|
+
import type { GlobalDefaults, ProviderRegistration } from "./defaults.types";
|
|
4
|
+
/**
|
|
5
|
+
* Get the global credential store.
|
|
6
|
+
*
|
|
7
|
+
* If no custom store has been set via `setGlobalCredentialStore()`, a default
|
|
8
|
+
* store is lazily created using the platform-aware credentials file path.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const store = getGlobalCredentialStore();
|
|
13
|
+
* const credential = await store.resolve("openai");
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare function getGlobalCredentialStore(): CredentialStore;
|
|
17
|
+
/**
|
|
18
|
+
* Override the global credential store.
|
|
19
|
+
*
|
|
20
|
+
* All subsequent calls to `getGlobalCredentialStore()` (and any
|
|
21
|
+
* `loadStrategy()` / `loadAgent()` calls that rely on global defaults)
|
|
22
|
+
* will use this store instead of the platform-default file store.
|
|
23
|
+
*
|
|
24
|
+
* Pass `undefined` to revert to the default store.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* setGlobalCredentialStore(myCustomStore);
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function setGlobalCredentialStore(store: CredentialStore | undefined): void;
|
|
32
|
+
/**
|
|
33
|
+
* Set the directory where provider npm packages are auto-installed.
|
|
34
|
+
*
|
|
35
|
+
* When set, `resolveViaPackage()` will attempt to install missing provider
|
|
36
|
+
* packages into this directory (using `bun add`) before falling back to
|
|
37
|
+
* the standard module resolution. Pass `undefined` to disable auto-install.
|
|
38
|
+
*
|
|
39
|
+
* The daemon calls this on startup with its configured `providerCacheDir`.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* setProviderCacheDir("/Users/bot/.local/share/comma-agents/providers");
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function setProviderCacheDir(dir: string | undefined): void;
|
|
47
|
+
/**
|
|
48
|
+
* Register a custom provider with the global resolver.
|
|
49
|
+
*
|
|
50
|
+
* Registered providers take precedence over the models.dev catalog
|
|
51
|
+
* map and the default `@ai-sdk/<providerId>` dynamic import convention.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* import { registerProvider } from "@comma-agents/core";
|
|
56
|
+
*
|
|
57
|
+
* // Direct factory — full control over provider creation
|
|
58
|
+
* registerProvider("my-custom-llm", {
|
|
59
|
+
* factory: (credential) => {
|
|
60
|
+
* const apiKey = credential.type === "api" ? credential.key : undefined;
|
|
61
|
+
* return (modelId) => myProvider({ apiKey, model: modelId });
|
|
62
|
+
* },
|
|
63
|
+
* });
|
|
64
|
+
*
|
|
65
|
+
* // Package-based — dynamic import with custom export name
|
|
66
|
+
* registerProvider("deepinfra", {
|
|
67
|
+
* packageName: "@deepinfra/ai-sdk",
|
|
68
|
+
* factoryName: "createDeepInfra",
|
|
69
|
+
* });
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare function registerProvider(providerId: string, registration: ProviderRegistration): void;
|
|
73
|
+
/**
|
|
74
|
+
* Remove a previously registered custom provider.
|
|
75
|
+
* Returns `true` if the provider was registered and removed.
|
|
76
|
+
*/
|
|
77
|
+
export declare function unregisterProvider(providerId: string): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Get the global provider resolver.
|
|
80
|
+
*
|
|
81
|
+
* The resolver uses this resolution order for each provider ID:
|
|
82
|
+
* 1. Custom registration with direct `factory` (via `registerProvider()`)
|
|
83
|
+
* 2. Custom registration with `packageName`/`factoryName`
|
|
84
|
+
* 3. Special handling for `github-copilot` (uses `@ai-sdk/openai-compatible`)
|
|
85
|
+
* 4. models.dev catalog + built-in overrides (ollama, deepseek) — sync lookup
|
|
86
|
+
* 5. Last resort: attempt `@ai-sdk/<providerId>` as a guess
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* const resolver = getGlobalProviderResolver();
|
|
91
|
+
* const factory = await resolver("openai", credential);
|
|
92
|
+
* const model = factory("gpt-4o");
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export declare function getGlobalProviderResolver(): ProviderResolver;
|
|
96
|
+
/**
|
|
97
|
+
* Get a snapshot of the current global defaults state.
|
|
98
|
+
*
|
|
99
|
+
* Useful for inspection and testing.
|
|
100
|
+
*/
|
|
101
|
+
export declare function getGlobalDefaults(): GlobalDefaults;
|
|
102
|
+
/**
|
|
103
|
+
* Reset all global defaults to initial state.
|
|
104
|
+
*
|
|
105
|
+
* Clears the provider registry, removes the custom credential store,
|
|
106
|
+
* and discards the lazily-created default store. Primarily for tests.
|
|
107
|
+
*/
|
|
108
|
+
export declare function resetGlobalDefaults(): void;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Credential, CredentialStore } from "../credentials/credentials.types";
|
|
2
|
+
import type { ProviderFactory, ProviderResolver } from "../model/model.types";
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for registering a custom provider with the global resolver.
|
|
5
|
+
*
|
|
6
|
+
* Provide either a direct `factory` function or a `packageName` + optional
|
|
7
|
+
* `factoryName` for dynamic import resolution.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* // Direct factory — full control
|
|
12
|
+
* registerProvider("my-llm", {
|
|
13
|
+
* factory: (credential) => (modelId) => myProvider({ apiKey: credential.key, model: modelId }),
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* // Package-based — dynamic import with custom names
|
|
17
|
+
* registerProvider("my-llm", {
|
|
18
|
+
* packageName: "my-ai-sdk",
|
|
19
|
+
* factoryName: "createMyLLM",
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export interface ProviderRegistration {
|
|
24
|
+
/**
|
|
25
|
+
* Direct factory function — given a credential, returns a ProviderFactory.
|
|
26
|
+
* When set, `packageName` and `factoryName` are ignored.
|
|
27
|
+
*/
|
|
28
|
+
readonly factory?: (credential: Credential) => ProviderFactory | Promise<ProviderFactory>;
|
|
29
|
+
/**
|
|
30
|
+
* npm package name to dynamically import.
|
|
31
|
+
* Defaults to `@ai-sdk/<providerId>` if omitted and `factory` is not set.
|
|
32
|
+
*/
|
|
33
|
+
readonly packageName?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Export name to look up on the imported module.
|
|
36
|
+
* Defaults to `create<ProviderId>` (AI SDK convention) if omitted.
|
|
37
|
+
*/
|
|
38
|
+
readonly factoryName?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Read-only view of the current global defaults state.
|
|
42
|
+
* Returned by `getGlobalDefaults()` for inspection/testing.
|
|
43
|
+
*/
|
|
44
|
+
export interface GlobalDefaults {
|
|
45
|
+
/** The current global credential store (lazily created if not overridden). */
|
|
46
|
+
readonly credentialStore: CredentialStore;
|
|
47
|
+
/** The current global provider resolver (uses registry + dynamic import fallback). */
|
|
48
|
+
readonly providerResolver: ProviderResolver;
|
|
49
|
+
/** Snapshot of registered provider IDs (does not include catalog-derived providers). */
|
|
50
|
+
readonly registeredProviderIds: readonly string[];
|
|
51
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { getGlobalCredentialStore, getGlobalDefaults, getGlobalProviderResolver, registerProvider, resetGlobalDefaults, setGlobalCredentialStore, setProviderCacheDir, unregisterProvider, } from "./defaults";
|
|
2
|
+
export type { GlobalDefaults, ProviderRegistration } from "./defaults.types";
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error for all CommaAgents errors.
|
|
3
|
+
* Provides a consistent `code` field for programmatic handling.
|
|
4
|
+
*/
|
|
5
|
+
export declare class CommaAgentsError extends Error {
|
|
6
|
+
readonly code: string;
|
|
7
|
+
constructor(code: string, message: string, options?: ErrorOptions);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Thrown when a model string cannot be resolved to an AI SDK LanguageModel.
|
|
11
|
+
* Examples: unknown provider, missing API key, package not installed.
|
|
12
|
+
*/
|
|
13
|
+
export declare class ModelResolutionError extends CommaAgentsError {
|
|
14
|
+
readonly modelString: string;
|
|
15
|
+
constructor(modelString: string, message: string, options?: ErrorOptions);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Thrown when an agent encounters an error during its call lifecycle.
|
|
19
|
+
*/
|
|
20
|
+
export declare class AgentCallError extends CommaAgentsError {
|
|
21
|
+
readonly agentName: string;
|
|
22
|
+
constructor(agentName: string, message: string, options?: ErrorOptions);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Thrown when a flow encounters an error during execution.
|
|
26
|
+
*/
|
|
27
|
+
export declare class FlowExecutionError extends CommaAgentsError {
|
|
28
|
+
readonly flowName: string;
|
|
29
|
+
constructor(flowName: string, message: string, options?: ErrorOptions);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Thrown when a tool execution fails.
|
|
33
|
+
*/
|
|
34
|
+
export declare class ToolExecutionError extends CommaAgentsError {
|
|
35
|
+
readonly toolName: string;
|
|
36
|
+
constructor(toolName: string, message: string, options?: ErrorOptions);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Thrown when a strategy file fails validation.
|
|
40
|
+
*/
|
|
41
|
+
export declare class StrategyValidationError extends CommaAgentsError {
|
|
42
|
+
constructor(message: string, options?: ErrorOptions);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Thrown when a sandbox policy rejects a file-system operation.
|
|
46
|
+
*
|
|
47
|
+
* The `reason` field indicates why the operation was blocked:
|
|
48
|
+
* - `"jail"` — the resolved path escapes the sandbox cwd boundary.
|
|
49
|
+
* - `"read-denied"` — the read policy explicitly denies this path.
|
|
50
|
+
* - `"write-denied"` — the write policy explicitly denies this path.
|
|
51
|
+
* - `"ask-no-handler"` — policy is `"ask"` but no PermissionRequester is configured.
|
|
52
|
+
* - `"ask-aborted"` — the PermissionRequester threw or the AbortSignal fired.
|
|
53
|
+
* - `"forbidden-glob"` — the path matches a sandbox-level forbidden glob (e.g. `.git/**`, `.env*`).
|
|
54
|
+
* These are always-deny patterns evaluated before the read/write policies and
|
|
55
|
+
* cannot be overridden by `allow` patterns or session decisions.
|
|
56
|
+
* - `"absolute-path"` — the input was an absolute path while the sandbox has
|
|
57
|
+
* `allowAbsolutePaths: false` (the default). Tools must use relative paths.
|
|
58
|
+
*/
|
|
59
|
+
export declare class SandboxViolationError extends CommaAgentsError {
|
|
60
|
+
readonly path: string;
|
|
61
|
+
readonly reason: "jail" | "read-denied" | "write-denied" | "ask-no-handler" | "ask-aborted" | "forbidden-glob" | "absolute-path";
|
|
62
|
+
constructor(path: string, reason: "jail" | "read-denied" | "write-denied" | "ask-no-handler" | "ask-aborted" | "forbidden-glob" | "absolute-path", message: string, options?: ErrorOptions);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Thrown when a hook function throws during execution.
|
|
66
|
+
*/
|
|
67
|
+
export declare class HookExecutionError extends CommaAgentsError {
|
|
68
|
+
readonly hookName: string;
|
|
69
|
+
constructor(hookName: string, message: string, options?: ErrorOptions);
|
|
70
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Agent } from "../../../agents/agent/agent.types";
|
|
2
|
+
import type { BroadcastFlowConfig } from "../../flow/flow.types";
|
|
3
|
+
/**
|
|
4
|
+
* Create a broadcast (fan-out) flow.
|
|
5
|
+
*
|
|
6
|
+
* The same input message is sent to every step. All responses are
|
|
7
|
+
* collected and joined with a separator into the final output.
|
|
8
|
+
*
|
|
9
|
+
* Steps are currently called sequentially (in order). Future versions
|
|
10
|
+
* may support parallel execution.
|
|
11
|
+
*
|
|
12
|
+
* @param config - Broadcast flow configuration.
|
|
13
|
+
* @returns An `Agent` implementing the broadcast flow.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { createBroadcastFlow } from "@comma-agents/core";
|
|
18
|
+
*
|
|
19
|
+
* const flow = createBroadcastFlow({
|
|
20
|
+
* name: "multi-review",
|
|
21
|
+
* steps: [reviewer1, reviewer2, reviewer3],
|
|
22
|
+
* separator: "\n---\n",
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* // All three reviewers receive the same code
|
|
26
|
+
* const result = await flow.call("Review this function: ...");
|
|
27
|
+
* // result.text = reviewer1's output + "\n---\n" + reviewer2's output + "\n---\n" + reviewer3's output
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function createBroadcastFlow(config: BroadcastFlowConfig): Agent;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Agent } from "../../../agents/agent/agent.types";
|
|
2
|
+
import type { CycleFlowConfig } from "../../flow/flow.types";
|
|
3
|
+
/**
|
|
4
|
+
* Check whether `observerOutput` contains any of the break signals
|
|
5
|
+
* under the chosen matching mode.
|
|
6
|
+
*
|
|
7
|
+
* Exposed for tests; not part of the public API.
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export declare function matchesBreakSignal(observerOutput: string, signals: ReadonlyArray<string>, mode: "substring" | "first-line" | "any-line" | "exact"): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Create a cycle flow that repeats a sequential pipeline N times.
|
|
14
|
+
*
|
|
15
|
+
* Each cycle runs all steps in sequence. The output of one cycle
|
|
16
|
+
* becomes the input of the next. Supports:
|
|
17
|
+
*
|
|
18
|
+
* - **Finite cycles**: `cycles: 3` runs the pipeline 3 times.
|
|
19
|
+
* - **Infinite cycles**: `cycles: Infinity` runs until externally cancelled.
|
|
20
|
+
* - **Observer**: An agent that processes each cycle's step output.
|
|
21
|
+
* If the observer's response matches a break signal under the
|
|
22
|
+
* configured match strategy (`breakCycleSignalMatch`), the cycle
|
|
23
|
+
* breaks and returns the step output (before the observer ran).
|
|
24
|
+
* - **Cycle hooks**: `alterMessageBeforeCycle` / `alterMessageAfterCycle`
|
|
25
|
+
* transform the message at cycle boundaries.
|
|
26
|
+
*
|
|
27
|
+
* @param config - Cycle flow configuration.
|
|
28
|
+
* @returns An `Agent` implementing the cycle flow.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* // Finite: run reviewer 3 times
|
|
33
|
+
* const flow = createCycleFlow({
|
|
34
|
+
* name: "review-loop",
|
|
35
|
+
* steps: [writer, reviewer],
|
|
36
|
+
* cycles: 3,
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* // Infinite refine-until-good with a unique unambiguous break token.
|
|
40
|
+
* // First-line match means the reviewer's verdict is on line 1, with
|
|
41
|
+
* // optional reasoning below — and casual prose like "not done yet"
|
|
42
|
+
* // in the CONTINUE branch cannot accidentally trigger the break.
|
|
43
|
+
* const flow = createCycleFlow({
|
|
44
|
+
* name: "refine-loop",
|
|
45
|
+
* steps: [writer],
|
|
46
|
+
* cycles: Infinity,
|
|
47
|
+
* observer: critic,
|
|
48
|
+
* breakCycleSignals: ["==CYCLE_DONE=="],
|
|
49
|
+
* breakCycleSignalMatch: "first-line",
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function createCycleFlow(config: CycleFlowConfig): Agent;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Agent } from "../../../agents/agent/agent.types";
|
|
2
|
+
import type { FlowConfig } from "../../flow/flow.types";
|
|
3
|
+
/**
|
|
4
|
+
* Create a sequential (pipeline) flow.
|
|
5
|
+
*
|
|
6
|
+
* Agents are called one after another. The output of each agent becomes
|
|
7
|
+
* the input of the next. The final agent's output is the flow's result.
|
|
8
|
+
*
|
|
9
|
+
* @param config - Flow configuration with steps to run in sequence.
|
|
10
|
+
* @returns An `Agent` implementing the sequential pipeline.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { createSequentialFlow, createAgent } from "@comma-agents/core";
|
|
15
|
+
*
|
|
16
|
+
* const flow = createSequentialFlow({
|
|
17
|
+
* name: "code-review",
|
|
18
|
+
* steps: [writer, reviewer, editor],
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // writer("Write a function") → reviewer(writer's output) → editor(reviewer's output)
|
|
22
|
+
* const result = await flow.call("Write a function that adds two numbers");
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function createSequentialFlow(config: FlowConfig): Agent;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { Agent } from "../../agents/agent/agent.types";
|
|
2
|
+
import type { CustomFlowConfig, FlowConfig, FlowExecutor, FlowHooks } from "./flow.types";
|
|
3
|
+
/**
|
|
4
|
+
* Mutable hook store backed by a hooks interface `H`.
|
|
5
|
+
*
|
|
6
|
+
* Removes the `readonly` modifier from property keys so values can be
|
|
7
|
+
* reassigned (replace-on-append), while preserving the original array
|
|
8
|
+
* types so no casts are needed when reading hooks.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const store: HookStore<FlowHooks> = {};
|
|
13
|
+
* // store.beforeFlow is ReadonlyArray<SideEffectHook<string>> | undefined — typed correctly
|
|
14
|
+
* // store.beforeFlow = [...(store.beforeFlow ?? []), newHook]; — assignable
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export type HookStore<HookType extends FlowHooks = FlowHooks> = {
|
|
18
|
+
-readonly [HookKey in keyof HookType]: HookType[HookKey];
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Build an `Agent` from a flow config, a hooks store, and an executor.
|
|
22
|
+
*
|
|
23
|
+
* This is the shared foundation for all flow types. It:
|
|
24
|
+
* 1. Validates that steps are non-empty.
|
|
25
|
+
* 2. Creates a `FlowContext` per call (tracks step results, fires step hooks).
|
|
26
|
+
* 3. Runs the flow-level hook lifecycle around the executor.
|
|
27
|
+
* 4. Returns an `Agent` with `name`, `call`, `reset`, and internal `appendHook`.
|
|
28
|
+
*
|
|
29
|
+
* The `store` is read on each call, so hooks appended via `appendHook` take
|
|
30
|
+
* effect on subsequent calls.
|
|
31
|
+
*
|
|
32
|
+
* @param config - Flow configuration (name, steps).
|
|
33
|
+
* @param typeName - Identifier for this flow type (for error messages).
|
|
34
|
+
* @param store - Mutable hooks store (starts empty; hooks are added via `hookIntoFlow`).
|
|
35
|
+
* @param executor - The orchestration function that defines step execution order.
|
|
36
|
+
* @param onReset - Optional callback fired after steps are reset (e.g. for observer cleanup).
|
|
37
|
+
* @returns An `Agent` implementing the flow.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* const agent = buildFlowAgent(
|
|
42
|
+
* config,
|
|
43
|
+
* "pipeline",
|
|
44
|
+
* {},
|
|
45
|
+
* async (steps, message, context) => {
|
|
46
|
+
* let current = message;
|
|
47
|
+
* for (const step of steps) {
|
|
48
|
+
* const result = await context.runStep(step, current);
|
|
49
|
+
* current = result.text;
|
|
50
|
+
* }
|
|
51
|
+
* return current;
|
|
52
|
+
* },
|
|
53
|
+
* );
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare function buildFlowAgent<HookType extends FlowHooks = FlowHooks>(config: FlowConfig, typeName: string, store: HookStore<HookType>, executor: FlowExecutor, onReset?: () => void): Agent;
|
|
57
|
+
/**
|
|
58
|
+
* Create a one-off custom flow with inline orchestration logic.
|
|
59
|
+
*
|
|
60
|
+
* For reusable flow types, use `buildFlowAgent()` directly.
|
|
61
|
+
*
|
|
62
|
+
* @param config - Flow configuration including the `execute` function.
|
|
63
|
+
* @returns An `Agent` implementing the custom flow.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* const flow = createFlow({
|
|
68
|
+
* name: "my-custom",
|
|
69
|
+
* steps: [agentA, agentB],
|
|
70
|
+
* execute: async (steps, message, context) => {
|
|
71
|
+
* const firstResult = await context.runStep(steps[0], message);
|
|
72
|
+
* if (firstResult.text.includes("DONE")) return firstResult.text;
|
|
73
|
+
* const secondResult = await context.runStep(steps[1], firstResult.text);
|
|
74
|
+
* return secondResult.text;
|
|
75
|
+
* },
|
|
76
|
+
* });
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare function createFlow(config: CustomFlowConfig): Agent;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import type { Agent, AgentCallResult } from "../../agents/agent/agent.types";
|
|
2
|
+
import type { SideEffectHook, TransformHook } from "../../hooks";
|
|
3
|
+
/**
|
|
4
|
+
* Flow lifecycle hooks.
|
|
5
|
+
*
|
|
6
|
+
* Execution order:
|
|
7
|
+
* alterMessageBeforeFlow → beforeFlow → [execute steps] → afterFlow → alterMessageAfterFlow
|
|
8
|
+
*
|
|
9
|
+
* Per-step hooks fire inside each step execution:
|
|
10
|
+
* beforeStep → [step.call()] → afterStep
|
|
11
|
+
*/
|
|
12
|
+
export interface FlowHooks {
|
|
13
|
+
/** Transform the message before the flow starts. */
|
|
14
|
+
readonly alterMessageBeforeFlow?: ReadonlyArray<TransformHook<string>>;
|
|
15
|
+
/** Side-effect before the flow starts. */
|
|
16
|
+
readonly beforeFlow?: ReadonlyArray<SideEffectHook<string>>;
|
|
17
|
+
/** Side-effect after the flow completes. */
|
|
18
|
+
readonly afterFlow?: ReadonlyArray<SideEffectHook<string>>;
|
|
19
|
+
/** Transform the final message after the flow completes. */
|
|
20
|
+
readonly alterMessageAfterFlow?: ReadonlyArray<TransformHook<string>>;
|
|
21
|
+
/** Side-effect before each step runs within the flow. */
|
|
22
|
+
readonly beforeStep?: ReadonlyArray<SideEffectHook<{
|
|
23
|
+
readonly stepName: string;
|
|
24
|
+
readonly message: string;
|
|
25
|
+
}>>;
|
|
26
|
+
/** Side-effect after each step completes within the flow. */
|
|
27
|
+
readonly afterStep?: ReadonlyArray<SideEffectHook<{
|
|
28
|
+
readonly stepName: string;
|
|
29
|
+
readonly message: string;
|
|
30
|
+
readonly result: AgentCallResult;
|
|
31
|
+
}>>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Additional hooks for cycle-based flows.
|
|
35
|
+
*/
|
|
36
|
+
export interface CycleHooks extends FlowHooks {
|
|
37
|
+
/** Transform the message before each cycle iteration. */
|
|
38
|
+
readonly alterMessageBeforeCycle?: ReadonlyArray<TransformHook<string>>;
|
|
39
|
+
/** Transform the message after each cycle iteration. */
|
|
40
|
+
readonly alterMessageAfterCycle?: ReadonlyArray<TransformHook<string>>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Result from a flow execution. Extends `AgentCallResult` with
|
|
44
|
+
* per-step details and aggregated token usage.
|
|
45
|
+
*
|
|
46
|
+
* Individual step results are available via `stepResults`.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* const result = await flow.call("hello") as FlowResult;
|
|
51
|
+
* console.log(result.text); // final flow output
|
|
52
|
+
* console.log(result.stepResults[0]); // first step's result
|
|
53
|
+
* console.log(result.usage); // aggregated token usage
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export interface FlowResult extends AgentCallResult {
|
|
57
|
+
/** Results from each step execution, in the order they ran. */
|
|
58
|
+
readonly stepResults: ReadonlyArray<AgentCallResult>;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Context provided to the flow executor function.
|
|
62
|
+
*
|
|
63
|
+
* Provides utilities for running steps (which tracks results automatically)
|
|
64
|
+
* and access to flow metadata.
|
|
65
|
+
*/
|
|
66
|
+
export interface FlowContext {
|
|
67
|
+
/** Name of this flow. */
|
|
68
|
+
readonly name: string;
|
|
69
|
+
/**
|
|
70
|
+
* Run a step (agent or nested flow) with a message.
|
|
71
|
+
* Tracks the result internally for aggregation into `FlowResult`.
|
|
72
|
+
*
|
|
73
|
+
* @param step - The agent or nested flow to call.
|
|
74
|
+
* @param message - The message to pass to the step.
|
|
75
|
+
* @returns The step's result.
|
|
76
|
+
*/
|
|
77
|
+
runStep(step: Agent, message: string): Promise<AgentCallResult>;
|
|
78
|
+
/** All results collected so far (for inspection mid-flow). */
|
|
79
|
+
readonly results: ReadonlyArray<AgentCallResult>;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The function that defines how a flow orchestrates its steps.
|
|
83
|
+
*
|
|
84
|
+
* Receives the list of steps, the input message, and a context object.
|
|
85
|
+
* Must return the final output text. Step results are tracked automatically
|
|
86
|
+
* via `flowContext.runStep()`.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* // A simple pipeline executor
|
|
91
|
+
* const pipelineExecutor: FlowExecutor = async (steps, message, flowContext) => {
|
|
92
|
+
* let current = message;
|
|
93
|
+
* for (const step of steps) {
|
|
94
|
+
* const result = await flowContext.runStep(step, current);
|
|
95
|
+
* current = result.text;
|
|
96
|
+
* }
|
|
97
|
+
* return current;
|
|
98
|
+
* };
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export type FlowExecutor = (steps: ReadonlyArray<Agent>, message: string, flowContext: FlowContext) => Promise<string>;
|
|
102
|
+
/** Base configuration shared by all flow types. */
|
|
103
|
+
export interface FlowConfig {
|
|
104
|
+
/** Unique name for this flow. */
|
|
105
|
+
readonly name: string;
|
|
106
|
+
/** The steps (agents or nested flows) this flow orchestrates. */
|
|
107
|
+
readonly steps: ReadonlyArray<Agent>;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Configuration for cycle-based flows.
|
|
111
|
+
*
|
|
112
|
+
* Supports finite cycles (`cycles: 3`), infinite cycles (`cycles: Infinity`),
|
|
113
|
+
* and an optional observer agent that runs after each cycle.
|
|
114
|
+
*/
|
|
115
|
+
export interface CycleFlowConfig extends FlowConfig {
|
|
116
|
+
/**
|
|
117
|
+
* Number of cycle iterations.
|
|
118
|
+
* Use `Infinity` for an infinite loop (requires `abort` signal).
|
|
119
|
+
* @default 1
|
|
120
|
+
*/
|
|
121
|
+
readonly cycles?: number;
|
|
122
|
+
/**
|
|
123
|
+
* Observer agent that runs after each cycle's steps.
|
|
124
|
+
* The observer's output becomes the input for the next cycle,
|
|
125
|
+
* unless a break signal is detected.
|
|
126
|
+
*/
|
|
127
|
+
readonly observer?: Agent;
|
|
128
|
+
/**
|
|
129
|
+
* Keywords that cause the observer to break the cycle loop. Matched
|
|
130
|
+
* against the observer's textual output using {@link breakCycleSignalMatch}.
|
|
131
|
+
*
|
|
132
|
+
* Pick tokens unlikely to appear by accident — `"==CYCLE_DONE=="` is
|
|
133
|
+
* far safer than `"done"`, which appears in casual prose like
|
|
134
|
+
* `"not done yet"` and false-fires the cycle.
|
|
135
|
+
*
|
|
136
|
+
* @default ["end cycle", "stop", "done"]
|
|
137
|
+
*/
|
|
138
|
+
readonly breakCycleSignals?: ReadonlyArray<string>;
|
|
139
|
+
/**
|
|
140
|
+
* Strategy used to compare the observer's output against the break
|
|
141
|
+
* signals.
|
|
142
|
+
*
|
|
143
|
+
* - `"substring"` (default, legacy): the observer output (lowercased)
|
|
144
|
+
* contains the signal (lowercased) anywhere. Permissive — `"done"`
|
|
145
|
+
* matches `"not done yet"`. Backward compatible with existing
|
|
146
|
+
* strategies; brittle for verbose observers.
|
|
147
|
+
* - `"first-line"`: the first non-blank line of the observer output
|
|
148
|
+
* (after trim) equals the signal or starts with the signal followed
|
|
149
|
+
* by whitespace. Recommended for LLM observers that emit a verdict
|
|
150
|
+
* on line 1 and optional reasoning below. Case-insensitive.
|
|
151
|
+
* - `"any-line"`: any line of the observer output (after trim) equals
|
|
152
|
+
* the signal or starts with the signal followed by whitespace.
|
|
153
|
+
* Case-insensitive. Looser than `"first-line"`; useful when the
|
|
154
|
+
* verdict isn't pinned to line 1.
|
|
155
|
+
* - `"exact"`: the entire observer output (after trim) equals the
|
|
156
|
+
* signal. The strictest mode — the observer must output **only** the
|
|
157
|
+
* signal token, nothing else. Use with tokens like `"DONE"` when
|
|
158
|
+
* you want zero false positives.
|
|
159
|
+
*
|
|
160
|
+
* Matching is case-insensitive in every mode except `"exact"` (which
|
|
161
|
+
* is also case-insensitive — use a distinctive token if case matters).
|
|
162
|
+
*
|
|
163
|
+
* @default "substring"
|
|
164
|
+
*/
|
|
165
|
+
readonly breakCycleSignalMatch?: "substring" | "first-line" | "any-line" | "exact";
|
|
166
|
+
}
|
|
167
|
+
/** Configuration for broadcast flows. */
|
|
168
|
+
export interface BroadcastFlowConfig extends FlowConfig {
|
|
169
|
+
/**
|
|
170
|
+
* Separator used to join step responses.
|
|
171
|
+
* @default "\n\n"
|
|
172
|
+
*/
|
|
173
|
+
readonly separator?: string;
|
|
174
|
+
}
|
|
175
|
+
/** Configuration for a one-off custom flow. */
|
|
176
|
+
export interface CustomFlowConfig extends FlowConfig {
|
|
177
|
+
/** The orchestration function. */
|
|
178
|
+
readonly execute: FlowExecutor;
|
|
179
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AgentCallResult } from "../../agents/agent/agent.types";
|
|
2
|
+
import type { FlowContext, FlowHooks, FlowResult } from "./flow.types";
|
|
3
|
+
/**
|
|
4
|
+
* Build a `FlowResult` by aggregating individual step results.
|
|
5
|
+
*
|
|
6
|
+
* - `text` is provided by the caller (the executor's return value).
|
|
7
|
+
* - `usage` is summed across all step results.
|
|
8
|
+
* - `finishReason` is always `"stop"` for flows.
|
|
9
|
+
*/
|
|
10
|
+
export declare function buildFlowResult(text: string, stepResults: ReadonlyArray<AgentCallResult>): FlowResult;
|
|
11
|
+
/**
|
|
12
|
+
* Create a `FlowContext` for a single flow execution.
|
|
13
|
+
*
|
|
14
|
+
* The context tracks step results via `runStep()` and exposes them
|
|
15
|
+
* as a readonly array. If step hooks are provided, `beforeStep` fires
|
|
16
|
+
* before each step and `afterStep` fires after.
|
|
17
|
+
*/
|
|
18
|
+
export declare function createFlowContext(name: string, hooks?: FlowHooks, abortSignal?: AbortSignal): FlowContext;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Agent } from "../../agents/agent/agent.types";
|
|
2
|
+
import type { FlowHooks } from "../flow/flow.types";
|
|
3
|
+
/**
|
|
4
|
+
* Append hooks to an existing flow agent. Mutates the flow in-place.
|
|
5
|
+
*
|
|
6
|
+
* The flow must have been created by one of the flow factories
|
|
7
|
+
* (`createSequentialFlow`, `createCycleFlow`, `createBroadcastFlow`,
|
|
8
|
+
* `createFlow`, or `buildFlowAgent`), which provide the internal
|
|
9
|
+
* `appendHook` method. Throws if the flow doesn't support it.
|
|
10
|
+
*
|
|
11
|
+
* The generic parameter `HookType` allows passing extended hook types
|
|
12
|
+
* (e.g. `CycleHooks`) for cycle-specific hooks:
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* // Basic flow hooks
|
|
17
|
+
* const flow = createSequentialFlow({ name: "pipe", steps: [a, b] });
|
|
18
|
+
* hookIntoFlow(flow, {
|
|
19
|
+
* beforeFlow: [async (message) => console.log("starting:", message)],
|
|
20
|
+
* afterFlow: [async (message) => console.log("done:", message)],
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* // Cycle-specific hooks
|
|
24
|
+
* const cycle = createCycleFlow({ name: "loop", steps: [a], cycles: 3 });
|
|
25
|
+
* hookIntoFlow<CycleHooks>(cycle, {
|
|
26
|
+
* alterMessageBeforeCycle: [async (message) => `[cycle]${message}`],
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function hookIntoFlow<HookType extends FlowHooks = FlowHooks>(flow: Agent, hooks: HookType): void;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createBroadcastFlow } from "./built-in/broadcast/broadcast-flow";
|
|
2
|
+
export { createCycleFlow } from "./built-in/cycle/cycle-flow";
|
|
3
|
+
export { createSequentialFlow } from "./built-in/sequential/sequential-flow";
|
|
4
|
+
export { buildFlowAgent, createFlow } from "./flow/flow";
|
|
5
|
+
export type { BroadcastFlowConfig, CustomFlowConfig, CycleFlowConfig, CycleHooks, FlowConfig, FlowContext, FlowExecutor, FlowHooks, FlowResult, } from "./flow/flow.types";
|
|
6
|
+
export { hookIntoFlow } from "./hook-into-flow/hook-into-flow";
|