openbot 0.2.12 → 0.2.14

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 (141) hide show
  1. package/.prettierrc +8 -0
  2. package/AGENTS.md +68 -0
  3. package/CONTRIBUTING.md +74 -0
  4. package/LICENSE +21 -0
  5. package/README.md +117 -14
  6. package/dist/agents/system.js +106 -0
  7. package/dist/app/cli.js +27 -0
  8. package/dist/app/config.js +64 -0
  9. package/dist/app/server.js +237 -0
  10. package/dist/app/utils.js +35 -0
  11. package/dist/harness/agent-harness.js +45 -0
  12. package/dist/harness/mcp.js +61 -0
  13. package/dist/harness/orchestrator.js +273 -0
  14. package/dist/harness/process.js +7 -0
  15. package/dist/plugins/ai-sdk.js +141 -0
  16. package/dist/plugins/delegation.js +52 -0
  17. package/dist/plugins/mcp.js +140 -0
  18. package/dist/plugins/storage.js +502 -0
  19. package/dist/plugins/ui.js +47 -0
  20. package/dist/registry/plugins.js +73 -0
  21. package/dist/services/storage.js +724 -0
  22. package/docs/README.md +7 -0
  23. package/docs/agents.md +83 -0
  24. package/docs/architecture.md +34 -0
  25. package/docs/plugins.md +77 -0
  26. package/logo-black.png +0 -0
  27. package/{dist/assets/logo.js → logo-black.svg} +24 -24
  28. package/{dist/ui/sidebar.js → logo-white.svg} +23 -88
  29. package/package.json +6 -5
  30. package/src/agents/system.ts +112 -0
  31. package/src/app/cli.ts +38 -0
  32. package/src/app/config.ts +104 -0
  33. package/src/app/server.ts +284 -0
  34. package/src/app/types.ts +476 -0
  35. package/src/app/utils.ts +43 -0
  36. package/src/assets/icon.svg +1 -0
  37. package/src/harness/agent-harness.ts +58 -0
  38. package/src/harness/mcp.ts +78 -0
  39. package/src/harness/orchestrator.ts +342 -0
  40. package/src/harness/process.ts +9 -0
  41. package/src/harness/types.ts +34 -0
  42. package/src/plugins/ai-sdk.ts +197 -0
  43. package/src/plugins/delegation.ts +60 -0
  44. package/src/plugins/mcp.ts +154 -0
  45. package/src/plugins/storage.ts +725 -0
  46. package/src/plugins/ui.ts +57 -0
  47. package/src/registry/plugins.ts +85 -0
  48. package/src/services/storage.ts +957 -0
  49. package/tsconfig.json +18 -0
  50. package/dist/agents/agent-creator.js +0 -74
  51. package/dist/agents/browser-agent.js +0 -31
  52. package/dist/agents/os-agent.js +0 -32
  53. package/dist/agents/planner-agent.js +0 -32
  54. package/dist/agents/topic-agent.js +0 -46
  55. package/dist/architecture/execution-engine.js +0 -151
  56. package/dist/architecture/intent-classifier.js +0 -26
  57. package/dist/architecture/planner.js +0 -106
  58. package/dist/automation-worker.js +0 -121
  59. package/dist/automations.js +0 -52
  60. package/dist/cli.js +0 -279
  61. package/dist/config.js +0 -53
  62. package/dist/core/agents.js +0 -41
  63. package/dist/core/delegation.js +0 -230
  64. package/dist/core/manager.js +0 -96
  65. package/dist/core/plugins.js +0 -74
  66. package/dist/core/router.js +0 -191
  67. package/dist/handlers/init.js +0 -29
  68. package/dist/handlers/session-change.js +0 -21
  69. package/dist/handlers/settings.js +0 -47
  70. package/dist/handlers/tab-change.js +0 -14
  71. package/dist/installers.js +0 -156
  72. package/dist/marketplace.js +0 -80
  73. package/dist/model-catalog.js +0 -132
  74. package/dist/model-defaults.js +0 -25
  75. package/dist/models.js +0 -47
  76. package/dist/open-bot.js +0 -51
  77. package/dist/orchestrator/direct-invocation.js +0 -13
  78. package/dist/orchestrator/events.js +0 -36
  79. package/dist/orchestrator/state.js +0 -54
  80. package/dist/orchestrator.js +0 -422
  81. package/dist/plugins/agent/index.js +0 -81
  82. package/dist/plugins/approval/index.js +0 -100
  83. package/dist/plugins/brain/identity.js +0 -77
  84. package/dist/plugins/brain/index.js +0 -204
  85. package/dist/plugins/brain/memory.js +0 -120
  86. package/dist/plugins/brain/prompt.js +0 -46
  87. package/dist/plugins/brain/types.js +0 -45
  88. package/dist/plugins/brain/ui.js +0 -7
  89. package/dist/plugins/browser/index.js +0 -629
  90. package/dist/plugins/browser/ui.js +0 -13
  91. package/dist/plugins/file-system/index.js +0 -171
  92. package/dist/plugins/file-system/ui.js +0 -6
  93. package/dist/plugins/llm/context-budget.js +0 -139
  94. package/dist/plugins/llm/context-shaping.js +0 -177
  95. package/dist/plugins/llm/index.js +0 -380
  96. package/dist/plugins/memory/index.js +0 -220
  97. package/dist/plugins/memory/memory.js +0 -122
  98. package/dist/plugins/memory/prompt.js +0 -55
  99. package/dist/plugins/memory/types.js +0 -45
  100. package/dist/plugins/meta-agent/index.js +0 -570
  101. package/dist/plugins/meta-agent/ui.js +0 -11
  102. package/dist/plugins/shell/index.js +0 -100
  103. package/dist/plugins/shell/ui.js +0 -6
  104. package/dist/plugins/skills/index.js +0 -286
  105. package/dist/plugins/skills/types.js +0 -50
  106. package/dist/plugins/skills/ui.js +0 -12
  107. package/dist/registry/agent-registry.js +0 -35
  108. package/dist/registry/index.js +0 -2
  109. package/dist/registry/plugin-loader.js +0 -499
  110. package/dist/registry/plugin-registry.js +0 -44
  111. package/dist/registry/ts-agent-loader.js +0 -82
  112. package/dist/registry/yaml-agent-loader.js +0 -246
  113. package/dist/runtime/execution-trace.js +0 -41
  114. package/dist/runtime/intent-routing.js +0 -26
  115. package/dist/runtime/openbot-runtime.js +0 -354
  116. package/dist/server.js +0 -890
  117. package/dist/session.js +0 -179
  118. package/dist/ui/block.js +0 -12
  119. package/dist/ui/header.js +0 -52
  120. package/dist/ui/layout.js +0 -26
  121. package/dist/ui/navigation.js +0 -15
  122. package/dist/ui/settings.js +0 -106
  123. package/dist/ui/skills.js +0 -7
  124. package/dist/ui/thread.js +0 -16
  125. package/dist/ui/widgets/action-list.js +0 -2
  126. package/dist/ui/widgets/approval-card.js +0 -9
  127. package/dist/ui/widgets/code-snippet.js +0 -2
  128. package/dist/ui/widgets/data-block.js +0 -2
  129. package/dist/ui/widgets/data-table.js +0 -2
  130. package/dist/ui/widgets/delegation.js +0 -29
  131. package/dist/ui/widgets/empty-state.js +0 -2
  132. package/dist/ui/widgets/index.js +0 -23
  133. package/dist/ui/widgets/inquiry.js +0 -7
  134. package/dist/ui/widgets/key-value.js +0 -2
  135. package/dist/ui/widgets/progress-step.js +0 -2
  136. package/dist/ui/widgets/resource-card.js +0 -2
  137. package/dist/ui/widgets/status.js +0 -2
  138. package/dist/ui/widgets/todo-list.js +0 -2
  139. package/dist/version.js +0 -62
  140. /package/dist/{types.js → app/types.js} +0 -0
  141. /package/dist/{architecture/contracts.js → harness/types.js} +0 -0
@@ -1,80 +0,0 @@
1
- import { installAgentFromSource, installPluginFromSource } from "./installers.js";
2
- const DEFAULT_MARKETPLACE_REGISTRY_URL = "https://raw.githubusercontent.com/meetopenbot/openbot-registry/main/registry.json";
3
- const CACHE_TTL_MS = 5 * 60 * 1000;
4
- let cachedRegistry = null;
5
- let cacheExpiresAt = 0;
6
- function normalizeSource(source) {
7
- if (!source || typeof source !== "object") {
8
- throw new Error("invalid source");
9
- }
10
- const value = source;
11
- if ((value.type !== "github" && value.type !== "npm") || typeof value.value !== "string" || !value.value.trim()) {
12
- throw new Error("invalid source");
13
- }
14
- return { type: value.type, value: value.value.trim() };
15
- }
16
- function normalizeItem(item) {
17
- if (!item || typeof item !== "object")
18
- throw new Error("invalid item");
19
- const value = item;
20
- if (typeof value.id !== "string" || !value.id.trim())
21
- throw new Error("invalid item id");
22
- if (typeof value.name !== "string" || !value.name.trim())
23
- throw new Error("invalid item name");
24
- if (typeof value.description !== "string")
25
- throw new Error("invalid item description");
26
- const tags = Array.isArray(value.tags) ? value.tags.filter((tag) => typeof tag === "string") : undefined;
27
- return {
28
- id: value.id.trim(),
29
- name: value.name.trim(),
30
- description: value.description,
31
- source: normalizeSource(value.source),
32
- tags,
33
- image: typeof value.image === "string" ? value.image.trim() : undefined,
34
- };
35
- }
36
- function normalizeRegistry(value) {
37
- if (!value || typeof value !== "object")
38
- throw new Error("invalid registry");
39
- const raw = value;
40
- if (typeof raw.version !== "number")
41
- throw new Error("invalid version");
42
- const agents = Array.isArray(raw.agents) ? raw.agents.map(normalizeItem) : [];
43
- const plugins = Array.isArray(raw.plugins) ? raw.plugins.map(normalizeItem) : [];
44
- return { version: raw.version, agents, plugins };
45
- }
46
- export async function getMarketplaceRegistry(forceRefresh = false) {
47
- const now = Date.now();
48
- if (!forceRefresh && cachedRegistry && now < cacheExpiresAt) {
49
- return cachedRegistry;
50
- }
51
- const registryUrl = process.env.OPENBOT_MARKETPLACE_REGISTRY_URL || DEFAULT_MARKETPLACE_REGISTRY_URL;
52
- const response = await fetch(registryUrl);
53
- if (!response.ok) {
54
- throw new Error(`Failed to fetch marketplace registry (${response.status})`);
55
- }
56
- const json = await response.json();
57
- const normalized = normalizeRegistry(json);
58
- cachedRegistry = normalized;
59
- cacheExpiresAt = now + CACHE_TTL_MS;
60
- return normalized;
61
- }
62
- export async function installMarketplaceAgent(agentId) {
63
- const registry = await getMarketplaceRegistry(true);
64
- const agent = registry.agents.find((entry) => entry.id === agentId);
65
- if (!agent)
66
- throw new Error(`Agent "${agentId}" was not found in marketplace`);
67
- if (agent.source.type !== "github") {
68
- throw new Error(`Marketplace agent "${agentId}" has unsupported source type "${agent.source.type}"`);
69
- }
70
- const installedName = await installAgentFromSource({ type: "github", value: agent.source.value }, { id: agent.id });
71
- return { installedName, agent };
72
- }
73
- export async function installMarketplacePlugin(pluginId) {
74
- const registry = await getMarketplaceRegistry(true);
75
- const plugin = registry.plugins.find((entry) => entry.id === pluginId);
76
- if (!plugin)
77
- throw new Error(`Plugin "${pluginId}" was not found in marketplace`);
78
- const installedName = await installPluginFromSource(plugin.source, { id: plugin.id });
79
- return { installedName, plugin };
80
- }
@@ -1,132 +0,0 @@
1
- import { loadConfig } from "./config.js";
2
- import { FALLBACK_MODELS } from "./model-defaults.js";
3
- const CACHE_TTL_MS = 5 * 60 * 1000;
4
- let cachedCatalog = null;
5
- let cachedAt = 0;
6
- let cachedFingerprint = "";
7
- function keyFingerprint(value) {
8
- if (!value)
9
- return "none";
10
- const trimmed = value.trim();
11
- if (!trimmed)
12
- return "none";
13
- return `${trimmed.slice(0, 4)}:${trimmed.length}`;
14
- }
15
- function buildFingerprint(input) {
16
- return [
17
- `openai=${keyFingerprint(input.openaiApiKey)}`,
18
- `anthropic=${keyFingerprint(input.anthropicApiKey)}`,
19
- `model=${input.model ?? ""}`,
20
- ].join("|");
21
- }
22
- function titleCaseModel(raw) {
23
- return raw
24
- .split("-")
25
- .map((part) => (part ? part[0].toUpperCase() + part.slice(1) : part))
26
- .join(" ");
27
- }
28
- function toProviderModel(provider, modelId) {
29
- const id = `${provider}/${modelId}`;
30
- const providerLabel = provider === "openai" ? "OpenAI" : "Anthropic";
31
- return { id, label: `${providerLabel} ${titleCaseModel(modelId)}` };
32
- }
33
- function dedupeModels(models) {
34
- const seen = new Set();
35
- const deduped = [];
36
- for (const model of models) {
37
- if (seen.has(model.id))
38
- continue;
39
- seen.add(model.id);
40
- deduped.push(model);
41
- }
42
- return deduped;
43
- }
44
- function sortModels(models) {
45
- return [...models].sort((a, b) => a.id.localeCompare(b.id));
46
- }
47
- function keepLikelyOpenAIChatModel(modelId) {
48
- return /^(gpt|o[1-9]|chatgpt)/.test(modelId);
49
- }
50
- async function fetchOpenAIModels(apiKey) {
51
- const res = await fetch("https://api.openai.com/v1/models", {
52
- headers: {
53
- Authorization: `Bearer ${apiKey}`,
54
- },
55
- });
56
- if (!res.ok) {
57
- throw new Error(`OpenAI models request failed (${res.status})`);
58
- }
59
- const data = await res.json();
60
- const models = (data.data ?? [])
61
- .map((m) => (typeof m.id === "string" ? m.id : ""))
62
- .filter((id) => !!id && keepLikelyOpenAIChatModel(id))
63
- .map((id) => toProviderModel("openai", id));
64
- return sortModels(dedupeModels(models));
65
- }
66
- async function fetchAnthropicModels(apiKey) {
67
- const res = await fetch("https://api.anthropic.com/v1/models", {
68
- headers: {
69
- "x-api-key": apiKey,
70
- "anthropic-version": "2023-06-01",
71
- },
72
- });
73
- if (!res.ok) {
74
- throw new Error(`Anthropic models request failed (${res.status})`);
75
- }
76
- const data = await res.json();
77
- const models = (data.data ?? [])
78
- .map((m) => {
79
- const modelId = typeof m.id === "string" ? m.id : "";
80
- if (!modelId)
81
- return null;
82
- const label = typeof m.display_name === "string" && m.display_name.trim()
83
- ? m.display_name.trim()
84
- : toProviderModel("anthropic", modelId).label;
85
- return { id: `anthropic/${modelId}`, label };
86
- })
87
- .filter((m) => !!m);
88
- return sortModels(dedupeModels(models));
89
- }
90
- export async function fetchProviderModels(provider, apiKey) {
91
- if (provider === "openai") {
92
- return fetchOpenAIModels(apiKey);
93
- }
94
- return fetchAnthropicModels(apiKey);
95
- }
96
- export async function getModelCatalog(forceRefresh = false) {
97
- const cfg = loadConfig();
98
- const openaiApiKey = cfg.openaiApiKey || process.env.OPENAI_API_KEY;
99
- const anthropicApiKey = cfg.anthropicApiKey || process.env.ANTHROPIC_API_KEY;
100
- const now = Date.now();
101
- const fingerprint = buildFingerprint({
102
- openaiApiKey,
103
- anthropicApiKey,
104
- model: cfg.model,
105
- });
106
- if (!forceRefresh &&
107
- cachedCatalog &&
108
- now - cachedAt < CACHE_TTL_MS &&
109
- cachedFingerprint === fingerprint) {
110
- return cachedCatalog;
111
- }
112
- const providerFetches = [];
113
- if (openaiApiKey) {
114
- providerFetches.push(fetchOpenAIModels(openaiApiKey));
115
- }
116
- if (anthropicApiKey) {
117
- providerFetches.push(fetchAnthropicModels(anthropicApiKey));
118
- }
119
- const results = await Promise.allSettled(providerFetches);
120
- const fetched = results
121
- .filter((r) => r.status === "fulfilled")
122
- .flatMap((r) => r.value);
123
- const merged = dedupeModels([...fetched, ...FALLBACK_MODELS]);
124
- if (cfg.model && !merged.some((m) => m.id === cfg.model)) {
125
- merged.push({ id: cfg.model, label: cfg.model });
126
- }
127
- const catalog = sortModels(merged);
128
- cachedCatalog = catalog;
129
- cachedAt = now;
130
- cachedFingerprint = fingerprint;
131
- return catalog;
132
- }
@@ -1,25 +0,0 @@
1
- export const DEFAULT_MODEL_ID = "openai/gpt-5-nano";
2
- export const DEFAULT_MODEL_BY_PROVIDER = {
3
- openai: DEFAULT_MODEL_ID,
4
- anthropic: "anthropic/claude-sonnet-4-5-20250929",
5
- };
6
- export const FALLBACK_MODELS = [
7
- { id: "openai/gpt-5.2", label: "OpenAI GPT-5.2" },
8
- { id: "openai/gpt-5.2-chat-latest", label: "OpenAI GPT-5.2 Chat Latest" },
9
- { id: "openai/gpt-5.2-pro", label: "OpenAI GPT-5.2 Pro" },
10
- { id: "openai/gpt-5", label: "OpenAI GPT-5" },
11
- { id: "openai/gpt-5-mini", label: "OpenAI GPT-5 Mini" },
12
- { id: "openai/gpt-5-nano", label: "OpenAI GPT-5 Nano" },
13
- { id: "openai/gpt-4.1", label: "OpenAI GPT-4.1" },
14
- { id: "openai/gpt-4.1-mini", label: "OpenAI GPT-4.1 Mini" },
15
- { id: "openai/gpt-4o", label: "OpenAI GPT-4o" },
16
- { id: "openai/gpt-4o-mini", label: "OpenAI GPT-4o Mini" },
17
- { id: "openai/o4-mini", label: "OpenAI o4-mini" },
18
- { id: "anthropic/claude-opus-4-6", label: "Claude Opus 4.6" },
19
- { id: "anthropic/claude-sonnet-4-6", label: "Claude Sonnet 4.6" },
20
- { id: "anthropic/claude-opus-4-5-20251101", label: "Claude Opus 4.5" },
21
- { id: "anthropic/claude-sonnet-4-5-20250929", label: "Claude Sonnet 4.5" },
22
- { id: "anthropic/claude-3-7-sonnet-latest", label: "Claude 3.7 Sonnet" },
23
- { id: "anthropic/claude-3-5-sonnet-latest", label: "Claude 3.5 Sonnet" },
24
- { id: "anthropic/claude-3-5-haiku-latest", label: "Claude 3.5 Haiku" },
25
- ];
package/dist/models.js DELETED
@@ -1,47 +0,0 @@
1
- import { openai } from "@ai-sdk/openai";
2
- import { anthropic } from "@ai-sdk/anthropic";
3
- import { loadConfig } from "./config.js";
4
- import { DEFAULT_MODEL_ID } from "./model-defaults.js";
5
- /**
6
- * Parse model string to extract provider and model ID
7
- * Supports formats: "provider/model" or just "model" (defaults to openai)
8
- */
9
- export function parseModelString(modelString) {
10
- // Check for provider/model format
11
- if (modelString.includes("/")) {
12
- const [provider, modelId] = modelString.split("/");
13
- if (provider === "openai" || provider === "anthropic") {
14
- return { provider: provider, modelId };
15
- }
16
- }
17
- // Auto-detect provider based on model name
18
- if (modelString.startsWith("claude") || modelString.startsWith("claude-")) {
19
- return { provider: "anthropic", modelId: modelString };
20
- }
21
- // Default to OpenAI
22
- return { provider: "openai", modelId: modelString };
23
- }
24
- export function createModel(options) {
25
- const config = loadConfig();
26
- const openaiKey = options?.openaiApiKey || config.openaiApiKey || process.env.OPENAI_API_KEY;
27
- const anthropicKey = options?.anthropicApiKey || config.anthropicApiKey || process.env.ANTHROPIC_API_KEY;
28
- if (openaiKey) {
29
- process.env.OPENAI_API_KEY = openaiKey;
30
- }
31
- if (anthropicKey) {
32
- process.env.ANTHROPIC_API_KEY = anthropicKey;
33
- }
34
- const { provider, modelId } = parseModelString(options?.model || config.model || DEFAULT_MODEL_ID);
35
- if (provider === "anthropic") {
36
- if (!anthropicKey) {
37
- console.warn("Warning: Anthropic model selected but ANTHROPIC_API_KEY is not set");
38
- }
39
- return anthropic(modelId);
40
- }
41
- else {
42
- if (!openaiKey) {
43
- console.warn("Warning: OpenAI model selected but OPENAI_API_KEY is not set");
44
- }
45
- return openai(modelId);
46
- }
47
- }
package/dist/open-bot.js DELETED
@@ -1,51 +0,0 @@
1
- import { melony } from "melony";
2
- import { loadConfig, resolvePath, DEFAULT_BASE_DIR } from "./config.js";
3
- import { createModel, parseModelString } from "./models.js";
4
- import { DEFAULT_MODEL_ID } from "./model-defaults.js";
5
- import { setupPluginRegistry } from "./core/plugins.js";
6
- import { createManagerPlugin } from "./core/manager.js";
7
- import { setupDelegation } from "./core/delegation.js";
8
- import { runOpenBot } from "./core/router.js";
9
- /**
10
- * Create the OpenBot runtime.
11
- */
12
- export async function createOpenBot(options) {
13
- const config = loadConfig();
14
- const baseDir = config.baseDir || DEFAULT_BASE_DIR;
15
- const resolvedBaseDir = resolvePath(baseDir);
16
- const configuredModel = config.model || DEFAULT_MODEL_ID;
17
- const { provider, modelId } = parseModelString(configuredModel);
18
- const resolvedModelId = `${provider}/${modelId}`;
19
- const model = createModel(options);
20
- // 1. Setup unified registry (built-in tools + agents + community plugins)
21
- const registry = await setupPluginRegistry(resolvedBaseDir, model, options);
22
- // 2. Initialize agent runtimes
23
- const agentRuntimes = new Map();
24
- for (const agent of registry.getAgents()) {
25
- const builder = melony();
26
- builder.use(agent.plugin);
27
- agentRuntimes.set(agent.id, builder.build());
28
- }
29
- // 3. Initialize manager runtime
30
- const managerBuilder = melony();
31
- managerBuilder.use(createManagerPlugin(model, resolvedModelId, resolvedBaseDir, registry));
32
- // 4. Setup delegation
33
- setupDelegation(managerBuilder, agentRuntimes);
34
- const managerRuntime = managerBuilder.build();
35
- // 5. Trigger initialization for all runtimes
36
- const initPromises = [];
37
- const exhaust = async (runtime) => {
38
- const iterator = runtime.run({ type: "init" }, { runId: "init", state: {} });
39
- for await (const _ of iterator) { /* side-effects only */ }
40
- };
41
- for (const agentRuntime of agentRuntimes.values()) {
42
- initPromises.push(exhaust(agentRuntime));
43
- }
44
- initPromises.push(exhaust(managerRuntime));
45
- await Promise.all(initPromises);
46
- // 6. Return the runtime
47
- return {
48
- registry,
49
- run: (event, context) => runOpenBot(event, context, managerRuntime, agentRuntimes, registry),
50
- };
51
- }
@@ -1,13 +0,0 @@
1
- export function parseDirectAgentInvocation(content, hasAgent) {
2
- const trimmed = content.trim();
3
- if (!trimmed || (!trimmed.startsWith("/") && !trimmed.startsWith("@"))) {
4
- return undefined;
5
- }
6
- const firstSpace = trimmed.indexOf(" ");
7
- const agentName = firstSpace === -1 ? trimmed.slice(1) : trimmed.slice(1, firstSpace);
8
- if (!hasAgent(agentName)) {
9
- return undefined;
10
- }
11
- const task = firstSpace === -1 ? "" : trimmed.slice(firstSpace + 1).trim();
12
- return { agentName, task };
13
- }
@@ -1,36 +0,0 @@
1
- const AGENT_TEXT_TYPES = new Set(["assistant:text-delta", "assistant:text"]);
2
- export function isAgentTextEvent(event) {
3
- return AGENT_TEXT_TYPES.has(event.type);
4
- }
5
- export function isApprovalEvent(event) {
6
- return event.type === "action:approve" || event.type === "action:deny";
7
- }
8
- export function makeManagerInputEvent(data) {
9
- return { type: "manager:input", data };
10
- }
11
- export function makeManagerResultEvent(options) {
12
- const { action = "delegateTask", toolCallId, result } = options;
13
- return {
14
- type: "manager:result",
15
- data: { action, toolCallId, result },
16
- };
17
- }
18
- export function makeAgentInputEvent(agentName, task) {
19
- return {
20
- type: `agent:${agentName}:input`,
21
- data: { content: task },
22
- };
23
- }
24
- export function makeAgentResultType(agentName) {
25
- return `agent:${agentName}:result`;
26
- }
27
- export function makeAgentOutputType(agentName) {
28
- return `agent:${agentName}:output`;
29
- }
30
- export function makeAssistantTextEvent(content, agentName) {
31
- return {
32
- type: "assistant:text",
33
- data: { content },
34
- meta: { agent: agentName },
35
- };
36
- }
@@ -1,54 +0,0 @@
1
- let pendingTaskCounter = 0;
2
- export function getAgentState(sessionState, agentName) {
3
- if (!sessionState.agentStates) {
4
- sessionState.agentStates = {};
5
- }
6
- if (!sessionState.agentStates[agentName]) {
7
- sessionState.agentStates[agentName] = {};
8
- }
9
- const agentState = sessionState.agentStates[agentName];
10
- if (!agentState.cwd) {
11
- agentState.cwd = sessionState.cwd;
12
- }
13
- return agentState;
14
- }
15
- export function addPendingAgentTask(state, agentName, toolCallId) {
16
- if (!state.pendingAgentTasks) {
17
- state.pendingAgentTasks = {};
18
- }
19
- const taskKey = toolCallId ?? `pending_${Date.now()}_${pendingTaskCounter++}`;
20
- state.pendingAgentTasks[taskKey] = { agentName, toolCallId };
21
- return taskKey;
22
- }
23
- export function removePendingAgentTask(state, taskKey) {
24
- if (!state.pendingAgentTasks) {
25
- return;
26
- }
27
- delete state.pendingAgentTasks[taskKey];
28
- }
29
- export function findPendingTaskByToolCallId(state, toolCallId) {
30
- if (!toolCallId || !state.pendingAgentTasks) {
31
- return undefined;
32
- }
33
- const task = state.pendingAgentTasks[toolCallId];
34
- if (task) {
35
- return { key: toolCallId, toolCallId: task.toolCallId };
36
- }
37
- for (const [key, pendingTask] of Object.entries(state.pendingAgentTasks)) {
38
- if (pendingTask.toolCallId === toolCallId) {
39
- return { key, toolCallId: pendingTask.toolCallId };
40
- }
41
- }
42
- return undefined;
43
- }
44
- export function findPendingTaskByAgent(state, agentName) {
45
- if (!state.pendingAgentTasks) {
46
- return undefined;
47
- }
48
- for (const [key, pendingTask] of Object.entries(state.pendingAgentTasks)) {
49
- if (pendingTask.agentName === agentName) {
50
- return { key, toolCallId: pendingTask.toolCallId };
51
- }
52
- }
53
- return undefined;
54
- }