@agent-native/core 0.16.1 → 0.16.3
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/README.md +21 -5
- package/dist/cli/code-agent-executor.js +1 -1
- package/dist/cli/code-agent-executor.js.map +1 -1
- package/dist/cli/code.d.ts.map +1 -1
- package/dist/cli/code.js +29 -4
- package/dist/cli/code.js.map +1 -1
- package/dist/client/AgentPanel.d.ts.map +1 -1
- package/dist/client/AgentPanel.js +9 -1
- package/dist/client/AgentPanel.js.map +1 -1
- package/dist/client/AssistantChat.js +2 -2
- package/dist/client/AssistantChat.js.map +1 -1
- package/dist/client/ConnectBuilderCard.js +1 -1
- package/dist/client/ConnectBuilderCard.js.map +1 -1
- package/dist/client/components/CodeRequiredDialog.d.ts.map +1 -1
- package/dist/client/components/CodeRequiredDialog.js +3 -1
- package/dist/client/components/CodeRequiredDialog.js.map +1 -1
- package/dist/client/composer/AgentComposerFrame.d.ts +3 -1
- package/dist/client/composer/AgentComposerFrame.d.ts.map +1 -1
- package/dist/client/composer/AgentComposerFrame.js +3 -3
- package/dist/client/composer/AgentComposerFrame.js.map +1 -1
- package/dist/client/composer/ComposerPlusMenu.d.ts.map +1 -1
- package/dist/client/composer/ComposerPlusMenu.js +2 -7
- package/dist/client/composer/ComposerPlusMenu.js.map +1 -1
- package/dist/client/composer/PromptComposer.d.ts +4 -1
- package/dist/client/composer/PromptComposer.d.ts.map +1 -1
- package/dist/client/composer/PromptComposer.js +3 -3
- package/dist/client/composer/PromptComposer.js.map +1 -1
- package/dist/client/composer/TiptapComposer.d.ts.map +1 -1
- package/dist/client/composer/TiptapComposer.js +13 -3
- package/dist/client/composer/TiptapComposer.js.map +1 -1
- package/dist/client/composer/useVoiceDictation.d.ts.map +1 -1
- package/dist/client/composer/useVoiceDictation.js +16 -10
- package/dist/client/composer/useVoiceDictation.js.map +1 -1
- package/dist/client/onboarding/OnboardingPanel.js +1 -1
- package/dist/client/onboarding/OnboardingPanel.js.map +1 -1
- package/dist/client/settings/BackgroundAgentSection.d.ts.map +1 -1
- package/dist/client/settings/BackgroundAgentSection.js +9 -2
- package/dist/client/settings/BackgroundAgentSection.js.map +1 -1
- package/dist/client/settings/BrowserSection.d.ts.map +1 -1
- package/dist/client/settings/BrowserSection.js +17 -3
- package/dist/client/settings/BrowserSection.js.map +1 -1
- package/dist/client/settings/SettingsPanel.d.ts.map +1 -1
- package/dist/client/settings/SettingsPanel.js +5 -5
- package/dist/client/settings/SettingsPanel.js.map +1 -1
- package/dist/client/settings/useBuilderStatus.d.ts +15 -2
- package/dist/client/settings/useBuilderStatus.d.ts.map +1 -1
- package/dist/client/settings/useBuilderStatus.js +99 -11
- package/dist/client/settings/useBuilderStatus.js.map +1 -1
- package/dist/client/settings/useBuilderStatus.spec.js +12 -6
- package/dist/client/settings/useBuilderStatus.spec.js.map +1 -1
- package/dist/code-agents/background-controller.d.ts +39 -0
- package/dist/code-agents/background-controller.d.ts.map +1 -0
- package/dist/code-agents/background-controller.js +249 -0
- package/dist/code-agents/background-controller.js.map +1 -0
- package/dist/code-agents/background-run.d.ts +58 -0
- package/dist/code-agents/background-run.d.ts.map +1 -0
- package/dist/code-agents/background-run.js +58 -0
- package/dist/code-agents/background-run.js.map +1 -0
- package/dist/code-agents/index.d.ts +2 -0
- package/dist/code-agents/index.d.ts.map +1 -1
- package/dist/code-agents/index.js +2 -0
- package/dist/code-agents/index.js.map +1 -1
- package/dist/connections/index.d.ts +1 -0
- package/dist/connections/index.d.ts.map +1 -1
- package/dist/connections/index.js +1 -0
- package/dist/connections/index.js.map +1 -1
- package/dist/connections/reader.d.ts +248 -0
- package/dist/connections/reader.d.ts.map +1 -0
- package/dist/connections/reader.js +461 -0
- package/dist/connections/reader.js.map +1 -0
- package/dist/credentials/index.d.ts +11 -0
- package/dist/credentials/index.d.ts.map +1 -1
- package/dist/credentials/index.js +40 -15
- package/dist/credentials/index.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/server/agent-chat-plugin.d.ts +18 -0
- package/dist/server/agent-chat-plugin.d.ts.map +1 -1
- package/dist/server/agent-chat-plugin.js +57 -9
- package/dist/server/agent-chat-plugin.js.map +1 -1
- package/dist/server/agent-teams.d.ts +66 -1
- package/dist/server/agent-teams.d.ts.map +1 -1
- package/dist/server/agent-teams.js +433 -16
- package/dist/server/agent-teams.js.map +1 -1
- package/dist/server/builder-browser.d.ts +11 -0
- package/dist/server/builder-browser.d.ts.map +1 -1
- package/dist/server/builder-browser.js +45 -0
- package/dist/server/builder-browser.js.map +1 -1
- package/dist/server/core-routes-plugin.d.ts.map +1 -1
- package/dist/server/core-routes-plugin.js +25 -2
- package/dist/server/core-routes-plugin.js.map +1 -1
- package/dist/templates/workspace-root/AGENTS.md +5 -5
- package/dist/templates/workspace-root/README.md +1 -1
- package/dist/workspace-connections/credentials.d.ts +64 -0
- package/dist/workspace-connections/credentials.d.ts.map +1 -0
- package/dist/workspace-connections/credentials.js +378 -0
- package/dist/workspace-connections/credentials.js.map +1 -0
- package/dist/workspace-connections/index.d.ts +2 -1
- package/dist/workspace-connections/index.d.ts.map +1 -1
- package/dist/workspace-connections/index.js +2 -1
- package/dist/workspace-connections/index.js.map +1 -1
- package/dist/workspace-connections/store.d.ts +16 -0
- package/dist/workspace-connections/store.d.ts.map +1 -1
- package/dist/workspace-connections/store.js +57 -1
- package/dist/workspace-connections/store.js.map +1 -1
- package/docs/content/agent-teams.md +22 -5
- package/docs/content/cloneable-saas.md +2 -2
- package/docs/content/code-agents-ui.md +103 -3
- package/docs/content/creating-templates.md +16 -0
- package/docs/content/getting-started.md +40 -14
- package/docs/content/migration-workbench.md +25 -2
- package/docs/content/multi-app-workspace.md +1 -1
- package/docs/content/template-analytics.md +17 -1
- package/docs/content/template-brain.md +57 -28
- package/docs/content/template-dispatch.md +9 -2
- package/docs/content/workspace-connections.md +63 -14
- package/docs/content/workspace-management.md +9 -2
- package/docs/content/workspace.md +12 -5
- package/package.json +1 -1
- package/src/templates/workspace-root/AGENTS.md +5 -5
- package/src/templates/workspace-root/README.md +1 -1
|
@@ -15,8 +15,11 @@
|
|
|
15
15
|
* serverless cold starts and works across multiple processes.
|
|
16
16
|
*/
|
|
17
17
|
import type { AgentChatEvent } from "../agent/types.js";
|
|
18
|
-
import type { ActionEntry } from "../agent/production-agent.js";
|
|
18
|
+
import type { ActionEntry, AgentLoopFinalResponseGuard } from "../agent/production-agent.js";
|
|
19
19
|
import type { AgentEngine } from "../agent/engine/types.js";
|
|
20
|
+
import type { RunEvent } from "../agent/types.js";
|
|
21
|
+
import type { BackgroundAgentRun, BackgroundAgentRunStatus, BackgroundAgentTranscriptEvent } from "../code-agents/background-run.js";
|
|
22
|
+
import type { BackgroundAgentController } from "../code-agents/index.js";
|
|
20
23
|
export interface AgentTask {
|
|
21
24
|
taskId: string;
|
|
22
25
|
threadId: string;
|
|
@@ -27,6 +30,53 @@ export interface AgentTask {
|
|
|
27
30
|
currentStep: string;
|
|
28
31
|
createdAt: number;
|
|
29
32
|
}
|
|
33
|
+
export type AgentTeamBackgroundRun = Omit<BackgroundAgentRun, "kind" | "source" | "sourceRecord" | "status" | "cwd" | "goalId" | "transcriptPath" | "artifactRoot"> & {
|
|
34
|
+
kind: "agent-team";
|
|
35
|
+
source: "hosted-agent-team";
|
|
36
|
+
sourceRecord: {
|
|
37
|
+
type: "agent-team-task";
|
|
38
|
+
id: string;
|
|
39
|
+
threadId: string;
|
|
40
|
+
};
|
|
41
|
+
status: BackgroundAgentRunStatus;
|
|
42
|
+
cwd?: string;
|
|
43
|
+
goalId: "agent-team";
|
|
44
|
+
transcriptPath?: string;
|
|
45
|
+
artifactRoot?: string;
|
|
46
|
+
};
|
|
47
|
+
export type AgentTeamBackgroundTranscriptEvent = Omit<BackgroundAgentTranscriptEvent, "kind" | "source" | "sourceRecord"> & {
|
|
48
|
+
kind: "user" | "system" | "note" | "artifact" | "status";
|
|
49
|
+
source: "hosted-agent-team";
|
|
50
|
+
sourceRecord: {
|
|
51
|
+
type: "agent-team-run-event";
|
|
52
|
+
id: string;
|
|
53
|
+
seq: number;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
export interface SendToAgentTeamBackgroundRunResult {
|
|
57
|
+
ok: boolean;
|
|
58
|
+
error?: string;
|
|
59
|
+
messageId?: string;
|
|
60
|
+
queuedCount?: number;
|
|
61
|
+
}
|
|
62
|
+
export interface ControlAgentTeamBackgroundRunResult {
|
|
63
|
+
ok: boolean;
|
|
64
|
+
error?: string;
|
|
65
|
+
}
|
|
66
|
+
export declare function createAgentTeamBackgroundAgentController(): BackgroundAgentController;
|
|
67
|
+
export declare const agentTeamBackgroundAgentController: BackgroundAgentController;
|
|
68
|
+
export interface QueuedTaskMessage {
|
|
69
|
+
id: string;
|
|
70
|
+
from: "orchestrator";
|
|
71
|
+
message: string;
|
|
72
|
+
timestamp: number;
|
|
73
|
+
}
|
|
74
|
+
declare function formatQueuedTaskMessages(messages: QueuedTaskMessage[]): string;
|
|
75
|
+
declare function drainQueuedTaskMessages(taskId: string): Promise<QueuedTaskMessage[]>;
|
|
76
|
+
declare function createMessageAwareActions(taskId: string, actions: Record<string, ActionEntry>): Record<string, ActionEntry>;
|
|
77
|
+
declare function createTaskMessageFinalGuard(taskId: string): AgentLoopFinalResponseGuard;
|
|
78
|
+
export declare function toAgentTaskBackgroundRun(task: AgentTask): AgentTeamBackgroundRun;
|
|
79
|
+
export declare function toAgentTaskBackgroundTranscriptEvent(runId: string, event: RunEvent): AgentTeamBackgroundTranscriptEvent | null;
|
|
30
80
|
export interface SpawnTaskOptions {
|
|
31
81
|
/** Description of what the sub-agent should do */
|
|
32
82
|
description: string;
|
|
@@ -60,11 +110,26 @@ export declare function getTask(taskId: string): Promise<AgentTask | undefined>;
|
|
|
60
110
|
export declare function getTaskByThread(threadId: string): Promise<AgentTask | undefined>;
|
|
61
111
|
/** List all tasks (most recent first) */
|
|
62
112
|
export declare function listTasks(): Promise<AgentTask[]>;
|
|
113
|
+
export declare function listAgentTeamBackgroundRuns(): Promise<AgentTeamBackgroundRun[]>;
|
|
114
|
+
export declare function getAgentTeamBackgroundRun(runId: string): Promise<AgentTeamBackgroundRun | null>;
|
|
115
|
+
export declare function listAgentTeamBackgroundTranscriptEvents(runId: string): Promise<AgentTeamBackgroundTranscriptEvent[]>;
|
|
116
|
+
export declare function subscribeToAgentTeamBackgroundRun(runId: string, fromSeq?: number): ReadableStream<Uint8Array> | null;
|
|
63
117
|
/** Send a message/update to a running sub-agent via application state */
|
|
64
118
|
export declare function sendToTask(taskId: string, message: string): Promise<{
|
|
65
119
|
ok: boolean;
|
|
66
120
|
error?: string;
|
|
121
|
+
messageId?: string;
|
|
122
|
+
queuedCount?: number;
|
|
67
123
|
}>;
|
|
124
|
+
export declare function sendToAgentTeamBackgroundRun(runId: string, message: string): Promise<SendToAgentTeamBackgroundRunResult>;
|
|
125
|
+
export declare function stopAgentTeamBackgroundRun(runId: string, reason?: string): Promise<ControlAgentTeamBackgroundRunResult>;
|
|
68
126
|
/** Mark a task as errored */
|
|
69
127
|
export declare function markTaskErrored(taskId: string, error: string): Promise<void>;
|
|
128
|
+
export declare const _agentTeamsQueueForTests: {
|
|
129
|
+
createMessageAwareActions: typeof createMessageAwareActions;
|
|
130
|
+
createTaskMessageFinalGuard: typeof createTaskMessageFinalGuard;
|
|
131
|
+
drainQueuedTaskMessages: typeof drainQueuedTaskMessages;
|
|
132
|
+
formatQueuedTaskMessages: typeof formatQueuedTaskMessages;
|
|
133
|
+
};
|
|
134
|
+
export {};
|
|
70
135
|
//# sourceMappingURL=agent-teams.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-teams.d.ts","sourceRoot":"","sources":["../../src/server/agent-teams.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC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S,EAAE,CAAC,CAItD;AAED,wBAAsB,2BAA2B,IAAI,OAAO,CAC1D,sBAAsB,EAAE,CACzB,CAEA;AAED,wBAAsB,yBAAyB,CAC7C,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,sBAAsB,GAAG,IAAI,CAAC,CAGxC;AAED,wBAAsB,uCAAuC,CAC3D,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,kCAAkC,EAAE,CAAC,CAc/C;AAED,wBAAgB,iCAAiC,CAC/C,KAAK,EAAE,MAAM,EACb,OAAO,SAAI,GACV,cAAc,CAAC,UAAU,CAAC,GAAG,IAAI,CAEnC;AAkBD,yEAAyE;AACzE,wBAAsB,UAAU,CAC9B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GACd,OAAO,CAAC;IACT,EAAE,EAAE,OAAO,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC,CAoBD;AAED,wBAAsB,4BAA4B,CAChD,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,kCAAkC,CAAC,CAE7C;AAmDD,wBAAsB,0BAA0B,CAC9C,KAAK,EAAE,MAAM,EACb,MAAM,SAAS,GACd,OAAO,CAAC,mCAAmC,CAAC,CAc9C;AAED,6BAA6B;AAC7B,wBAAsB,eAAe,CACnC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC,CAOf;AAED,eAAO,MAAM,wBAAwB;;;;;CAKpC,CAAC"}
|
|
@@ -17,15 +17,164 @@
|
|
|
17
17
|
import { actionsToEngineTools } from "../agent/production-agent.js";
|
|
18
18
|
import { createAnthropicEngine } from "../agent/engine/anthropic-engine.js";
|
|
19
19
|
import { createThread } from "../chat-threads/store.js";
|
|
20
|
-
import { startRun } from "../agent/run-manager.js";
|
|
20
|
+
import { abortRun, getRun, startRun, subscribeToRun, } from "../agent/run-manager.js";
|
|
21
|
+
import { getRunEventsSince } from "../agent/run-store.js";
|
|
21
22
|
import { runAgentLoop } from "../agent/production-agent.js";
|
|
22
23
|
import { buildAssistantMessage } from "../agent/thread-data-builder.js";
|
|
23
|
-
import { readAppState, writeAppState, listAppState, } from "../application-state/script-helpers.js";
|
|
24
|
+
import { readAppState, writeAppState, listAppState, deleteAppState, } from "../application-state/script-helpers.js";
|
|
24
25
|
import { getRequestUserEmail } from "./request-context.js";
|
|
26
|
+
export function createAgentTeamBackgroundAgentController() {
|
|
27
|
+
return {
|
|
28
|
+
async list(options) {
|
|
29
|
+
if (options?.goalId && options.goalId !== "agent-team")
|
|
30
|
+
return [];
|
|
31
|
+
return listAgentTeamBackgroundRuns();
|
|
32
|
+
},
|
|
33
|
+
get: getAgentTeamBackgroundRun,
|
|
34
|
+
transcript: listAgentTeamBackgroundTranscriptEvents,
|
|
35
|
+
sendFollowUp: sendAgentTeamBackgroundAgentFollowUp,
|
|
36
|
+
control: controlAgentTeamBackgroundAgentRun,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export const agentTeamBackgroundAgentController = createAgentTeamBackgroundAgentController();
|
|
25
40
|
/** Key prefix for task records: agent-task:{taskId} */
|
|
26
41
|
const TASK_PREFIX = "agent-task:";
|
|
27
42
|
/** Key prefix for thread→task reverse lookup: agent-task-thread:{threadId} */
|
|
28
43
|
const THREAD_PREFIX = "agent-task-thread:";
|
|
44
|
+
/** Key prefix for queued orchestrator→sub-agent messages. */
|
|
45
|
+
const TASK_MESSAGE_PREFIX = "task-message:";
|
|
46
|
+
function taskMessageQueuePrefix(taskId) {
|
|
47
|
+
return `${TASK_MESSAGE_PREFIX}${taskId}:`;
|
|
48
|
+
}
|
|
49
|
+
function generateTaskMessageId() {
|
|
50
|
+
return `msg-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
51
|
+
}
|
|
52
|
+
function normalizeQueuedTaskMessage(value, fallbackId) {
|
|
53
|
+
if (typeof value.message !== "string" || value.message.trim().length === 0) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
const timestamp = typeof value.timestamp === "number" && Number.isFinite(value.timestamp)
|
|
57
|
+
? value.timestamp
|
|
58
|
+
: Date.now();
|
|
59
|
+
return {
|
|
60
|
+
id: typeof value.id === "string" ? value.id : fallbackId,
|
|
61
|
+
from: "orchestrator",
|
|
62
|
+
message: value.message,
|
|
63
|
+
timestamp,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function formatQueuedTaskMessages(messages) {
|
|
67
|
+
const label = messages.length === 1
|
|
68
|
+
? "Orchestrator message received while you were working"
|
|
69
|
+
: "Orchestrator messages received while you were working";
|
|
70
|
+
const body = messages
|
|
71
|
+
.map((message) => {
|
|
72
|
+
const sentAt = new Date(message.timestamp).toISOString();
|
|
73
|
+
return `[${sentAt}] ${message.message}`;
|
|
74
|
+
})
|
|
75
|
+
.join("\n\n");
|
|
76
|
+
return `${label}:\n\n${body}\n\nAdjust your next steps to account for this update.`;
|
|
77
|
+
}
|
|
78
|
+
const taskMessageDrainLocks = new Map();
|
|
79
|
+
async function withTaskMessageDrainLock(taskId, fn) {
|
|
80
|
+
const previous = taskMessageDrainLocks.get(taskId) ?? Promise.resolve();
|
|
81
|
+
let release;
|
|
82
|
+
const current = new Promise((resolve) => (release = resolve));
|
|
83
|
+
taskMessageDrainLocks.set(taskId, current);
|
|
84
|
+
await previous.catch(() => { });
|
|
85
|
+
try {
|
|
86
|
+
return await fn();
|
|
87
|
+
}
|
|
88
|
+
finally {
|
|
89
|
+
release();
|
|
90
|
+
if (taskMessageDrainLocks.get(taskId) === current) {
|
|
91
|
+
taskMessageDrainLocks.delete(taskId);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async function listQueuedTaskMessages(taskId) {
|
|
96
|
+
const queuePrefix = taskMessageQueuePrefix(taskId);
|
|
97
|
+
const entries = await listAppState(queuePrefix);
|
|
98
|
+
const messages = entries
|
|
99
|
+
.map((entry) => {
|
|
100
|
+
const id = entry.key.slice(queuePrefix.length);
|
|
101
|
+
const message = normalizeQueuedTaskMessage(entry.value, id);
|
|
102
|
+
return message ? { key: entry.key, message } : null;
|
|
103
|
+
})
|
|
104
|
+
.filter((entry) => Boolean(entry));
|
|
105
|
+
// Backward compatibility for messages queued by the old implementation.
|
|
106
|
+
const legacyKey = `${TASK_MESSAGE_PREFIX}${taskId}`;
|
|
107
|
+
const legacy = await readAppState(legacyKey);
|
|
108
|
+
const legacyMessage = legacy
|
|
109
|
+
? normalizeQueuedTaskMessage(legacy, "legacy")
|
|
110
|
+
: null;
|
|
111
|
+
if (legacyMessage) {
|
|
112
|
+
messages.push({ key: legacyKey, message: legacyMessage });
|
|
113
|
+
}
|
|
114
|
+
return messages.sort((a, b) => {
|
|
115
|
+
const byTimestamp = a.message.timestamp - b.message.timestamp;
|
|
116
|
+
return byTimestamp || a.message.id.localeCompare(b.message.id);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
async function drainQueuedTaskMessages(taskId) {
|
|
120
|
+
return withTaskMessageDrainLock(taskId, async () => {
|
|
121
|
+
const entries = await listQueuedTaskMessages(taskId);
|
|
122
|
+
if (entries.length === 0)
|
|
123
|
+
return [];
|
|
124
|
+
for (const entry of entries) {
|
|
125
|
+
await deleteAppState(entry.key);
|
|
126
|
+
}
|
|
127
|
+
return entries.map((entry) => entry.message);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
async function appendQueuedTaskMessage(taskId, message) {
|
|
131
|
+
const messageId = generateTaskMessageId();
|
|
132
|
+
await writeAppState(`${taskMessageQueuePrefix(taskId)}${messageId}`, {
|
|
133
|
+
id: messageId,
|
|
134
|
+
from: "orchestrator",
|
|
135
|
+
message,
|
|
136
|
+
timestamp: Date.now(),
|
|
137
|
+
});
|
|
138
|
+
const queuedCount = (await listQueuedTaskMessages(taskId)).length;
|
|
139
|
+
return { messageId, queuedCount };
|
|
140
|
+
}
|
|
141
|
+
function createMessageAwareActions(taskId, actions) {
|
|
142
|
+
return Object.fromEntries(Object.entries(actions).map(([name, entry]) => [
|
|
143
|
+
name,
|
|
144
|
+
{
|
|
145
|
+
...entry,
|
|
146
|
+
run: async (args, context) => {
|
|
147
|
+
const result = await entry.run(args, context);
|
|
148
|
+
const queuedMessages = await drainQueuedTaskMessages(taskId);
|
|
149
|
+
if (queuedMessages.length === 0)
|
|
150
|
+
return result;
|
|
151
|
+
// Tool results are already the next safe model-visible boundary:
|
|
152
|
+
// the loop records all tool output, then asks the model to continue.
|
|
153
|
+
// Attaching queued updates here avoids mutating message history while
|
|
154
|
+
// an assistant tool-call turn is still being resolved.
|
|
155
|
+
const formatted = formatQueuedTaskMessages(queuedMessages);
|
|
156
|
+
const resultText = typeof result === "string"
|
|
157
|
+
? result
|
|
158
|
+
: JSON.stringify(result, null, 2);
|
|
159
|
+
return `${resultText}\n\n${formatted}`;
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
]));
|
|
163
|
+
}
|
|
164
|
+
function createTaskMessageFinalGuard(taskId) {
|
|
165
|
+
return async () => {
|
|
166
|
+
const queuedMessages = await drainQueuedTaskMessages(taskId);
|
|
167
|
+
if (queuedMessages.length === 0)
|
|
168
|
+
return null;
|
|
169
|
+
// This is queued delivery, not a live interrupt: if the sub-agent is
|
|
170
|
+
// already producing a final answer, the guard asks the loop for one more
|
|
171
|
+
// continuation that includes the orchestrator update as a fresh user turn.
|
|
172
|
+
return {
|
|
173
|
+
retryMessage: formatQueuedTaskMessages(queuedMessages),
|
|
174
|
+
fallbackMessage: "I received an orchestrator update while finishing, but could not continue from it. Please check the task status and send the update again if needed.",
|
|
175
|
+
};
|
|
176
|
+
};
|
|
177
|
+
}
|
|
29
178
|
async function saveTask(task) {
|
|
30
179
|
await writeAppState(`${TASK_PREFIX}${task.taskId}`, task);
|
|
31
180
|
await writeAppState(`${THREAD_PREFIX}${task.threadId}`, {
|
|
@@ -45,6 +194,174 @@ async function loadTaskByThread(threadId) {
|
|
|
45
194
|
function generateTaskId() {
|
|
46
195
|
return `task-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
47
196
|
}
|
|
197
|
+
function taskRunId(taskId) {
|
|
198
|
+
return `run-task-${taskId}`;
|
|
199
|
+
}
|
|
200
|
+
function taskIdFromBackgroundRunId(runId) {
|
|
201
|
+
return runId.startsWith("run-task-")
|
|
202
|
+
? runId.slice("run-task-".length)
|
|
203
|
+
: runId;
|
|
204
|
+
}
|
|
205
|
+
function mapTaskStatusToBackgroundStatus(status) {
|
|
206
|
+
return status;
|
|
207
|
+
}
|
|
208
|
+
function taskTimestampToIso(timestamp) {
|
|
209
|
+
const date = new Date(timestamp);
|
|
210
|
+
return Number.isFinite(date.getTime())
|
|
211
|
+
? date.toISOString()
|
|
212
|
+
: new Date(0).toISOString();
|
|
213
|
+
}
|
|
214
|
+
function latestTaskText(task) {
|
|
215
|
+
return task.summary || task.preview || task.currentStep || undefined;
|
|
216
|
+
}
|
|
217
|
+
export function toAgentTaskBackgroundRun(task) {
|
|
218
|
+
const createdAt = taskTimestampToIso(task.createdAt);
|
|
219
|
+
return {
|
|
220
|
+
schemaVersion: 1,
|
|
221
|
+
id: taskRunId(task.taskId),
|
|
222
|
+
kind: "agent-team",
|
|
223
|
+
source: "hosted-agent-team",
|
|
224
|
+
sourceLabel: "Agent Teams",
|
|
225
|
+
sourceRecord: {
|
|
226
|
+
type: "agent-team-task",
|
|
227
|
+
id: task.taskId,
|
|
228
|
+
threadId: task.threadId,
|
|
229
|
+
},
|
|
230
|
+
title: task.description,
|
|
231
|
+
subtitle: task.currentStep || undefined,
|
|
232
|
+
status: mapTaskStatusToBackgroundStatus(task.status),
|
|
233
|
+
phase: task.currentStep || task.status,
|
|
234
|
+
createdAt,
|
|
235
|
+
updatedAt: createdAt,
|
|
236
|
+
goalId: "agent-team",
|
|
237
|
+
needsInput: false,
|
|
238
|
+
needsApproval: false,
|
|
239
|
+
details: [
|
|
240
|
+
{ label: "Task", value: task.taskId },
|
|
241
|
+
{ label: "Thread", value: task.threadId },
|
|
242
|
+
],
|
|
243
|
+
surfaceUrl: `agent-native://threads/${task.threadId}`,
|
|
244
|
+
metadata: {
|
|
245
|
+
taskId: task.taskId,
|
|
246
|
+
threadId: task.threadId,
|
|
247
|
+
description: task.description,
|
|
248
|
+
preview: task.preview,
|
|
249
|
+
summary: task.summary,
|
|
250
|
+
currentStep: task.currentStep,
|
|
251
|
+
latestText: latestTaskText(task),
|
|
252
|
+
},
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
function summarizeAgentChatEvent(event) {
|
|
256
|
+
const payload = event.event;
|
|
257
|
+
switch (payload.type) {
|
|
258
|
+
case "text":
|
|
259
|
+
return { kind: "note", message: payload.text };
|
|
260
|
+
case "activity":
|
|
261
|
+
return {
|
|
262
|
+
kind: "status",
|
|
263
|
+
message: payload.label,
|
|
264
|
+
metadata: payload.tool ? { tool: payload.tool } : undefined,
|
|
265
|
+
};
|
|
266
|
+
case "tool_start":
|
|
267
|
+
return {
|
|
268
|
+
kind: "status",
|
|
269
|
+
message: `Running ${payload.tool}`,
|
|
270
|
+
metadata: { tool: payload.tool, input: payload.input },
|
|
271
|
+
};
|
|
272
|
+
case "tool_done":
|
|
273
|
+
return {
|
|
274
|
+
kind: "artifact",
|
|
275
|
+
message: payload.result,
|
|
276
|
+
metadata: { tool: payload.tool },
|
|
277
|
+
};
|
|
278
|
+
case "agent_task":
|
|
279
|
+
return {
|
|
280
|
+
kind: "status",
|
|
281
|
+
message: `${payload.description} (${payload.status})`,
|
|
282
|
+
metadata: {
|
|
283
|
+
taskId: payload.taskId,
|
|
284
|
+
threadId: payload.threadId,
|
|
285
|
+
status: payload.status,
|
|
286
|
+
},
|
|
287
|
+
};
|
|
288
|
+
case "agent_task_update":
|
|
289
|
+
return {
|
|
290
|
+
kind: "status",
|
|
291
|
+
message: payload.preview || payload.currentStep || "Task updated",
|
|
292
|
+
metadata: {
|
|
293
|
+
taskId: payload.taskId,
|
|
294
|
+
currentStep: payload.currentStep,
|
|
295
|
+
},
|
|
296
|
+
};
|
|
297
|
+
case "agent_task_complete":
|
|
298
|
+
return {
|
|
299
|
+
kind: "status",
|
|
300
|
+
message: payload.summary,
|
|
301
|
+
metadata: { taskId: payload.taskId },
|
|
302
|
+
};
|
|
303
|
+
case "error":
|
|
304
|
+
return {
|
|
305
|
+
kind: "status",
|
|
306
|
+
message: payload.error,
|
|
307
|
+
metadata: {
|
|
308
|
+
errorCode: payload.errorCode,
|
|
309
|
+
upgradeUrl: payload.upgradeUrl,
|
|
310
|
+
},
|
|
311
|
+
};
|
|
312
|
+
case "missing_api_key":
|
|
313
|
+
return {
|
|
314
|
+
kind: "status",
|
|
315
|
+
message: "Missing API key",
|
|
316
|
+
};
|
|
317
|
+
case "done":
|
|
318
|
+
return { kind: "status", message: "Run completed" };
|
|
319
|
+
case "loop_limit":
|
|
320
|
+
return { kind: "status", message: "Run stopped at the loop limit" };
|
|
321
|
+
case "auto_continue":
|
|
322
|
+
return {
|
|
323
|
+
kind: "status",
|
|
324
|
+
message: "Run reached its continuation boundary",
|
|
325
|
+
metadata: { reason: payload.reason },
|
|
326
|
+
};
|
|
327
|
+
case "clear":
|
|
328
|
+
return null;
|
|
329
|
+
case "agent_call":
|
|
330
|
+
return {
|
|
331
|
+
kind: "status",
|
|
332
|
+
message: `${payload.agent} ${payload.status}`,
|
|
333
|
+
metadata: { agent: payload.agent, status: payload.status },
|
|
334
|
+
};
|
|
335
|
+
case "agent_call_text":
|
|
336
|
+
return {
|
|
337
|
+
kind: "note",
|
|
338
|
+
message: payload.text,
|
|
339
|
+
metadata: { agent: payload.agent },
|
|
340
|
+
};
|
|
341
|
+
default:
|
|
342
|
+
return null;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
export function toAgentTaskBackgroundTranscriptEvent(runId, event) {
|
|
346
|
+
const summary = summarizeAgentChatEvent(event);
|
|
347
|
+
if (!summary)
|
|
348
|
+
return null;
|
|
349
|
+
return {
|
|
350
|
+
schemaVersion: 1,
|
|
351
|
+
id: `${runId}:${event.seq}`,
|
|
352
|
+
runId,
|
|
353
|
+
kind: summary.kind,
|
|
354
|
+
source: "hosted-agent-team",
|
|
355
|
+
sourceRecord: {
|
|
356
|
+
type: "agent-team-run-event",
|
|
357
|
+
id: `${runId}:${event.seq}`,
|
|
358
|
+
seq: event.seq,
|
|
359
|
+
},
|
|
360
|
+
message: summary.message,
|
|
361
|
+
createdAt: new Date().toISOString(),
|
|
362
|
+
metadata: summary.metadata,
|
|
363
|
+
};
|
|
364
|
+
}
|
|
48
365
|
/**
|
|
49
366
|
* Spawn a sub-agent task. Creates a thread, starts a background agent run,
|
|
50
367
|
* and emits agent_task events to the parent chat stream.
|
|
@@ -126,7 +443,8 @@ You are a focused sub-agent with a specific task. You have been given a curated
|
|
|
126
443
|
const engine = opts.engine ?? createAnthropicEngine({ apiKey: opts.apiKey });
|
|
127
444
|
const model = opts.model ?? engine.defaultModel;
|
|
128
445
|
// Build tools from actions using the normalized EngineTool format
|
|
129
|
-
const
|
|
446
|
+
const messageAwareActions = createMessageAwareActions(taskId, opts.actions);
|
|
447
|
+
const tools = actionsToEngineTools(messageAwareActions);
|
|
130
448
|
const messages = [
|
|
131
449
|
{ role: "user", content: [{ type: "text", text: opts.description }] },
|
|
132
450
|
];
|
|
@@ -177,9 +495,10 @@ You are a focused sub-agent with a specific task. You have been given a curated
|
|
|
177
495
|
systemPrompt,
|
|
178
496
|
tools,
|
|
179
497
|
messages,
|
|
180
|
-
actions:
|
|
498
|
+
actions: messageAwareActions,
|
|
181
499
|
send: wrappedSend,
|
|
182
500
|
signal,
|
|
501
|
+
finalResponseGuard: createTaskMessageFinalGuard(taskId),
|
|
183
502
|
});
|
|
184
503
|
},
|
|
185
504
|
// onComplete callback — called when the run finishes (success or error)
|
|
@@ -307,6 +626,42 @@ export async function listTasks() {
|
|
|
307
626
|
const tasks = entries.map((e) => e.value);
|
|
308
627
|
return tasks.sort((a, b) => b.createdAt - a.createdAt);
|
|
309
628
|
}
|
|
629
|
+
export async function listAgentTeamBackgroundRuns() {
|
|
630
|
+
return (await listTasks()).map(toAgentTaskBackgroundRun);
|
|
631
|
+
}
|
|
632
|
+
export async function getAgentTeamBackgroundRun(runId) {
|
|
633
|
+
const task = await loadTask(taskIdFromBackgroundRunId(runId));
|
|
634
|
+
return task ? toAgentTaskBackgroundRun(task) : null;
|
|
635
|
+
}
|
|
636
|
+
export async function listAgentTeamBackgroundTranscriptEvents(runId) {
|
|
637
|
+
const normalizedRunId = taskRunId(taskIdFromBackgroundRunId(runId));
|
|
638
|
+
const activeRun = getRun(normalizedRunId);
|
|
639
|
+
const events = activeRun
|
|
640
|
+
? activeRun.events
|
|
641
|
+
: await getPersistedRunEvents(normalizedRunId);
|
|
642
|
+
return events
|
|
643
|
+
.map((event) => toAgentTaskBackgroundTranscriptEvent(normalizedRunId, event))
|
|
644
|
+
.filter((event) => Boolean(event));
|
|
645
|
+
}
|
|
646
|
+
export function subscribeToAgentTeamBackgroundRun(runId, fromSeq = 0) {
|
|
647
|
+
return subscribeToRun(taskRunId(taskIdFromBackgroundRunId(runId)), fromSeq);
|
|
648
|
+
}
|
|
649
|
+
async function getPersistedRunEvents(runId) {
|
|
650
|
+
const rows = await getRunEventsSince(runId, 0);
|
|
651
|
+
return rows
|
|
652
|
+
.map((row) => {
|
|
653
|
+
try {
|
|
654
|
+
return {
|
|
655
|
+
seq: row.seq,
|
|
656
|
+
event: JSON.parse(row.eventData),
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
catch {
|
|
660
|
+
return null;
|
|
661
|
+
}
|
|
662
|
+
})
|
|
663
|
+
.filter((event) => Boolean(event));
|
|
664
|
+
}
|
|
310
665
|
/** Send a message/update to a running sub-agent via application state */
|
|
311
666
|
export async function sendToTask(taskId, message) {
|
|
312
667
|
const task = await loadTask(taskId);
|
|
@@ -314,23 +669,79 @@ export async function sendToTask(taskId, message) {
|
|
|
314
669
|
return { ok: false, error: "Task not found" };
|
|
315
670
|
if (task.status !== "running")
|
|
316
671
|
return { ok: false, error: "Task is not running" };
|
|
317
|
-
|
|
318
|
-
|
|
672
|
+
if (message.trim().length === 0)
|
|
673
|
+
return { ok: false, error: "Message is required" };
|
|
674
|
+
// Append to a durable per-task queue. Running sub-agents drain this queue
|
|
675
|
+
// after tool batches and immediately before a final response. This does not
|
|
676
|
+
// interrupt an in-flight model stream or tool call; it guarantees the next
|
|
677
|
+
// safe continuation sees the update.
|
|
319
678
|
try {
|
|
320
|
-
const
|
|
679
|
+
const queued = await appendQueuedTaskMessage(taskId, message);
|
|
680
|
+
return { ok: true, ...queued };
|
|
681
|
+
}
|
|
682
|
+
catch {
|
|
321
683
|
const sessionId = getRequestUserEmail();
|
|
322
|
-
if (!sessionId)
|
|
684
|
+
if (!sessionId)
|
|
323
685
|
return { ok: false, error: "no authenticated user" };
|
|
324
|
-
}
|
|
325
|
-
await appStatePut(sessionId, `task-message:${taskId}`, {
|
|
326
|
-
from: "orchestrator",
|
|
327
|
-
message,
|
|
328
|
-
timestamp: Date.now(),
|
|
329
|
-
});
|
|
686
|
+
return { ok: false, error: "Unable to queue message" };
|
|
330
687
|
}
|
|
331
|
-
|
|
332
|
-
|
|
688
|
+
}
|
|
689
|
+
export async function sendToAgentTeamBackgroundRun(runId, message) {
|
|
690
|
+
return sendToTask(taskIdFromBackgroundRunId(runId), message);
|
|
691
|
+
}
|
|
692
|
+
async function sendAgentTeamBackgroundAgentFollowUp(input) {
|
|
693
|
+
const prompt = input.prompt.trim();
|
|
694
|
+
if (!prompt) {
|
|
695
|
+
return {
|
|
696
|
+
ok: false,
|
|
697
|
+
runId: input.runId,
|
|
698
|
+
run: await getAgentTeamBackgroundRun(input.runId),
|
|
699
|
+
error: "Follow-up prompt is required.",
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
const result = await sendToAgentTeamBackgroundRun(input.runId, prompt);
|
|
703
|
+
return {
|
|
704
|
+
ok: result.ok,
|
|
705
|
+
runId: input.runId,
|
|
706
|
+
run: await getAgentTeamBackgroundRun(input.runId),
|
|
707
|
+
queued: result.ok,
|
|
708
|
+
message: result.ok
|
|
709
|
+
? "Follow-up queued for the Agent Teams background run."
|
|
710
|
+
: undefined,
|
|
711
|
+
error: result.error,
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
async function controlAgentTeamBackgroundAgentRun(input) {
|
|
715
|
+
if (input.command !== "stop") {
|
|
716
|
+
return {
|
|
717
|
+
ok: false,
|
|
718
|
+
runId: input.runId,
|
|
719
|
+
run: await getAgentTeamBackgroundRun(input.runId),
|
|
720
|
+
error: "Agent Teams background runs currently support stop through the shared controller.",
|
|
721
|
+
};
|
|
722
|
+
}
|
|
723
|
+
const result = await stopAgentTeamBackgroundRun(input.runId);
|
|
724
|
+
return {
|
|
725
|
+
ok: result.ok,
|
|
726
|
+
runId: input.runId,
|
|
727
|
+
run: await getAgentTeamBackgroundRun(input.runId),
|
|
728
|
+
message: result.ok ? "Agent Teams background run stopped." : undefined,
|
|
729
|
+
error: result.error,
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
export async function stopAgentTeamBackgroundRun(runId, reason = "user") {
|
|
733
|
+
const taskId = taskIdFromBackgroundRunId(runId);
|
|
734
|
+
const task = await loadTask(taskId);
|
|
735
|
+
if (!task)
|
|
736
|
+
return { ok: false, error: "Task not found" };
|
|
737
|
+
if (task.status !== "running") {
|
|
738
|
+
return { ok: false, error: "Task is not running" };
|
|
333
739
|
}
|
|
740
|
+
abortRun(taskRunId(taskId), reason);
|
|
741
|
+
task.status = "errored";
|
|
742
|
+
task.summary =
|
|
743
|
+
reason === "user" ? "Task stopped." : `Task stopped: ${reason}`;
|
|
744
|
+
await saveTask(task);
|
|
334
745
|
return { ok: true };
|
|
335
746
|
}
|
|
336
747
|
/** Mark a task as errored */
|
|
@@ -342,4 +753,10 @@ export async function markTaskErrored(taskId, error) {
|
|
|
342
753
|
await saveTask(task);
|
|
343
754
|
}
|
|
344
755
|
}
|
|
756
|
+
export const _agentTeamsQueueForTests = {
|
|
757
|
+
createMessageAwareActions,
|
|
758
|
+
createTaskMessageFinalGuard,
|
|
759
|
+
drainQueuedTaskMessages,
|
|
760
|
+
formatQueuedTaskMessages,
|
|
761
|
+
};
|
|
345
762
|
//# sourceMappingURL=agent-teams.js.map
|