repoburg 1.3.199 → 1.3.202
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/agent-pane/backend/data.db +0 -0
- package/agent-pane/backend/data.db-shm +0 -0
- package/agent-pane/backend/data.db-wal +0 -0
- package/agent-pane/backend/dist/index.js +1658 -277
- package/agent-pane/backend/src/claude/claude-provider.test.ts +393 -3
- package/agent-pane/backend/src/claude/claude-provider.ts +53 -50
- package/agent-pane/backend/src/db/index.ts +12 -0
- package/agent-pane/backend/src/index.ts +5 -2
- package/agent-pane/backend/src/integration/threads-claude-fork.test.ts +241 -0
- package/agent-pane/backend/src/providers/index.ts +3 -1
- package/agent-pane/backend/src/providers/runtime-provider.ts +6 -0
- package/agent-pane/backend/src/repoburg/action-mapping.test.ts +122 -0
- package/agent-pane/backend/src/repoburg/action-mapping.ts +294 -0
- package/agent-pane/backend/src/repoburg/agent-runtime-client.test.ts +271 -0
- package/agent-pane/backend/src/repoburg/agent-runtime-client.ts +285 -0
- package/agent-pane/backend/src/repoburg/backend-resolver.test.ts +356 -0
- package/agent-pane/backend/src/repoburg/backend-resolver.ts +261 -0
- package/agent-pane/backend/src/repoburg/repoburg-client.test.ts +180 -0
- package/agent-pane/backend/src/repoburg/repoburg-client.ts +194 -0
- package/agent-pane/backend/src/repoburg/repoburg-provider.test.ts +780 -0
- package/agent-pane/backend/src/repoburg/repoburg-provider.ts +471 -0
- package/agent-pane/backend/src/repoburg/turn-projector.test.ts +621 -0
- package/agent-pane/backend/src/repoburg/turn-projector.ts +637 -0
- package/agent-pane/backend/src/routes/providers.test.ts +18 -1
- package/agent-pane/backend/src/routes/providers.ts +19 -1
- package/agent-pane/backend/src/routes/sessions.test.ts +215 -1
- package/agent-pane/backend/src/routes/sessions.ts +82 -9
- package/agent-pane/backend/src/routes/threads.ts +21 -6
- package/agent-pane/backend/src/routes/turns.test.ts +45 -1
- package/agent-pane/frontend/dist/assets/index-CJxD4YmJ.js +370 -0
- package/agent-pane/frontend/dist/assets/{index-Dwwhx7YN.css → index-r-xwfOKQ.css} +1 -1
- package/agent-pane/frontend/dist/index.html +2 -2
- package/agent-pane/frontend/src/api/sessions.test.ts +1 -0
- package/agent-pane/frontend/src/api/websocket.test.ts +2 -2
- package/agent-pane/frontend/src/api/websocket.ts +3 -1
- package/agent-pane/frontend/src/components/AskUserItem.test.tsx +143 -0
- package/agent-pane/frontend/src/components/AskUserItem.tsx +207 -0
- package/agent-pane/frontend/src/components/CommentableText.test.tsx +196 -0
- package/agent-pane/frontend/src/components/CommentableText.tsx +109 -21
- package/agent-pane/frontend/src/components/IdeWorkspace.test.tsx +39 -0
- package/agent-pane/frontend/src/components/IdeWorkspace.tsx +28 -2
- package/agent-pane/frontend/src/components/ResizeHandle.tsx +29 -0
- package/agent-pane/frontend/src/components/TurnContent.test.tsx +79 -0
- package/agent-pane/frontend/src/components/TurnContent.tsx +49 -3
- package/agent-pane/frontend/src/components/panels/ThreadsPanel.tsx +35 -3
- package/agent-pane/frontend/src/components/panels/TurnsPanel.test.tsx +48 -0
- package/agent-pane/frontend/src/components/panels/TurnsPanel.tsx +7 -2
- package/agent-pane/frontend/src/constants/models.ts +37 -0
- package/agent-pane/frontend/src/hooks/useResizable.test.ts +97 -0
- package/agent-pane/frontend/src/hooks/useResizable.ts +75 -0
- package/agent-pane/frontend/src/store/store.test.ts +54 -0
- package/agent-pane/frontend/src/store/uiSlice.ts +50 -0
- package/agent-pane/frontend/src/store/wsSlice.ts +10 -3
- package/agent-pane/frontend/src/styles/app.css +26 -1
- package/agent-pane/frontend/src/test/component-helpers.ts +2 -0
- package/agent-pane/frontend/src/test/fixtures.ts +1 -0
- package/agent-pane/frontend/src/types/index.ts +2 -0
- package/agent-pane/frontend/src/utils/duration.test.ts +1 -0
- package/agent-pane/shared/types.ts +17 -0
- package/agent-pane-bug-repro-no-agent-reply.png +0 -0
- package/askuser-after-step5-postgres-selected.png +0 -0
- package/askuser-after-step7-answer-sent.png +0 -0
- package/askuser-card-visible.png +0 -0
- package/backend/dist/src/agent-runtime/agent-runtime-event-emitter.d.ts +36 -0
- package/backend/dist/src/agent-runtime/agent-runtime-event-emitter.js +199 -0
- package/backend/dist/src/agent-runtime/agent-runtime-event-emitter.js.map +1 -0
- package/backend/dist/src/agent-runtime/agent-runtime.controller.d.ts +11 -0
- package/backend/dist/src/agent-runtime/agent-runtime.controller.js +91 -0
- package/backend/dist/src/agent-runtime/agent-runtime.controller.js.map +1 -0
- package/backend/dist/src/agent-runtime/agent-runtime.module.d.ts +2 -0
- package/backend/dist/src/agent-runtime/agent-runtime.module.js +26 -0
- package/backend/dist/src/agent-runtime/agent-runtime.module.js.map +1 -0
- package/backend/dist/src/agent-runtime/agent-runtime.types.d.ts +92 -0
- package/backend/dist/src/agent-runtime/agent-runtime.types.js +3 -0
- package/backend/dist/src/agent-runtime/agent-runtime.types.js.map +1 -0
- package/backend/dist/src/app.controller.d.ts +1 -0
- package/backend/dist/src/app.module.js +4 -0
- package/backend/dist/src/app.module.js.map +1 -1
- package/backend/dist/src/app.service.d.ts +1 -0
- package/backend/dist/src/app.service.js +4 -1
- package/backend/dist/src/app.service.js.map +1 -1
- package/backend/dist/src/interactive-chat/chat.module.js +4 -0
- package/backend/dist/src/interactive-chat/chat.module.js.map +1 -1
- package/backend/dist/src/interactive-chat/chat.service.d.ts +7 -1
- package/backend/dist/src/interactive-chat/chat.service.js +54 -7
- package/backend/dist/src/interactive-chat/chat.service.js.map +1 -1
- package/backend/dist/src/llm-orchestration/action-handlers/invoke-subagent.handler.js +12 -1
- package/backend/dist/src/llm-orchestration/action-handlers/invoke-subagent.handler.js.map +1 -1
- package/backend/dist/src/llm-orchestration/hooks/frontend-notification.hook.d.ts +3 -1
- package/backend/dist/src/llm-orchestration/hooks/frontend-notification.hook.js +20 -2
- package/backend/dist/src/llm-orchestration/hooks/frontend-notification.hook.js.map +1 -1
- package/backend/dist/src/llm-orchestration/llm-orchestration.interfaces.d.ts +1 -0
- package/backend/dist/src/llm-orchestration/llm-orchestration.interfaces.js +1 -0
- package/backend/dist/src/llm-orchestration/llm-orchestration.interfaces.js.map +1 -1
- package/backend/dist/src/llm-orchestration/llm-orchestration.module.js +2 -0
- package/backend/dist/src/llm-orchestration/llm-orchestration.module.js.map +1 -1
- package/backend/dist/src/llm-orchestration/llm-turn-processor.service.d.ts +4 -1
- package/backend/dist/src/llm-orchestration/llm-turn-processor.service.js +37 -2
- package/backend/dist/src/llm-orchestration/llm-turn-processor.service.js.map +1 -1
- package/backend/dist/src/llm-provider/ollama-llm.provider.d.ts +1 -0
- package/backend/dist/src/llm-provider/ollama-llm.provider.js +19 -1
- package/backend/dist/src/llm-provider/ollama-llm.provider.js.map +1 -1
- package/backend/dist/src/llm-responses/llm-responses.module.js +4 -0
- package/backend/dist/src/llm-responses/llm-responses.module.js.map +1 -1
- package/backend/dist/src/llm-responses/llm-responses.service.d.ts +4 -1
- package/backend/dist/src/llm-responses/llm-responses.service.js +52 -2
- package/backend/dist/src/llm-responses/llm-responses.service.js.map +1 -1
- package/backend/dist/tsconfig.build.tsbuildinfo +1 -1
- package/daemon/dist/api/services.js +4 -0
- package/daemon/dist/index.js +0 -0
- package/daemon/dist/serviceManager.js +30 -11
- package/daemon/dist/serviceManager.spec.js +26 -0
- package/daemon/dist/workspace-validation.js +63 -0
- package/daemon/dist/workspace-validation.spec.js +63 -0
- package/package.json +1 -1
- package/r2-step4-apple-banana.png +0 -0
- package/r2-step5-after-rewind-apple-last.png +0 -0
- package/r2-step7-apple-cherry.png +0 -0
- package/r2-step8-cherry-menu-no-restore.png +0 -0
- package/r3-step3-live-task-card-running.png +0 -0
- package/r3-step4-after-completion.png +0 -0
- package/r3-step5-persistence-after-reload.png +0 -0
- package/r3-step6-tasks-tab-card.png +0 -0
- package/reverify-answered-state-answer-sent.png +0 -0
- package/reverify-card-visible-after-completion.png +0 -0
- package/rewind-step3-apple-banana-turns.png +0 -0
- package/rewind-step5-ui-unchanged-after-confirmed-rewind.png +0 -0
- package/rewind-step6-apple-menu-no-restore.png +0 -0
- package/rewind-step7-final-turnlist-unchanged.png +0 -0
- package/rewind-step7-negative-error-toast.png +0 -0
- package/rewind-step7-negative-error-toast2.png +0 -0
- package/subagent-r2-step5-turn-after-reload-no-card.png +0 -0
- package/subagent-r2-step6-tasks-panel-card.png +0 -0
- package/subagent-step3-tasks-tab-done-card.png +0 -0
- package/subagent-step4-turn-stuck-no-cards.png +0 -0
- package/agent-pane/frontend/dist/assets/index-BYo-lnxm.js +0 -362
|
@@ -28,7 +28,16 @@ body {
|
|
|
28
28
|
|
|
29
29
|
/* === IDE Root Layout === */
|
|
30
30
|
.ide-root { display: flex; flex-direction: column; height: 100vh; }
|
|
31
|
-
|
|
31
|
+
/* Default track sizes match uiSlice defaults; IdeWorkspace overrides via inline style
|
|
32
|
+
once hydrated (and adds two 6px resize-handle tracks: 240px 6px 1fr 6px 300px). */
|
|
33
|
+
.ide-layout { display: grid; grid-template-columns: 240px 6px 1fr 6px 300px; flex: 1; overflow: hidden; }
|
|
34
|
+
|
|
35
|
+
/* === Resize handles === */
|
|
36
|
+
.resize-handle { width: 6px; cursor: col-resize; background: transparent; flex-shrink: 0; transition: background var(--dur-fast) var(--ease); }
|
|
37
|
+
.resize-handle:hover, .resize-handle.dragging { background: var(--border-hover); }
|
|
38
|
+
/* While dragging, suppress text selection across the whole app. */
|
|
39
|
+
body.is-resizing { user-select: none; }
|
|
40
|
+
body.is-resizing * { cursor: col-resize !important; }
|
|
32
41
|
|
|
33
42
|
/* === Sidebar === */
|
|
34
43
|
.ide-sidebar { background: var(--surface-0); border-right: 1px solid var(--border); overflow-y: auto; display: flex; flex-direction: column; }
|
|
@@ -600,3 +609,19 @@ mark[data-thread-id].thread-mark-resolved { background: transparent; border-bott
|
|
|
600
609
|
.agent-call-status.running { color: var(--accent); background: var(--accent-soft); }
|
|
601
610
|
.agent-call-status.done { color: var(--green); background: rgba(34,197,94,0.08); }
|
|
602
611
|
.agent-call-status.failed { color: var(--red); background: rgba(239,68,68,0.08); }
|
|
612
|
+
|
|
613
|
+
/* === Ask-user selection buttons (platform parity) === */
|
|
614
|
+
.ask-user-card { border-left: 3px solid var(--accent); }
|
|
615
|
+
.ask-user-groups { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
|
|
616
|
+
.ask-user-group { display: flex; flex-direction: column; gap: 6px; }
|
|
617
|
+
.ask-user-question { font-size: 12px; font-weight: 600; color: var(--text-2); }
|
|
618
|
+
.ask-user-options { display: flex; flex-wrap: wrap; gap: 6px; }
|
|
619
|
+
.ask-user-option { padding: 4px 10px; font-size: 12px; font-family: var(--font-sans); color: var(--text-2); background: var(--canvas); border: 1px solid var(--border); border-radius: var(--r-sm); cursor: pointer; transition: all var(--dur-fast) var(--ease); }
|
|
620
|
+
.ask-user-option:not(:disabled):hover { border-color: var(--accent); color: var(--accent); }
|
|
621
|
+
.ask-user-option.selected { background: var(--accent); border-color: var(--accent); color: #fff; }
|
|
622
|
+
.ask-user-option:disabled { opacity: 0.55; cursor: default; }
|
|
623
|
+
.ask-user-option.selected:disabled { opacity: 0.8; }
|
|
624
|
+
.ask-user-send { display: inline-flex; align-items: center; gap: 5px; padding: 4px 12px; font-size: 12px; font-family: var(--font-sans); color: #fff; background: var(--accent); border: none; border-radius: var(--r-sm); cursor: pointer; align-self: flex-start; transition: background var(--dur-fast) var(--ease); }
|
|
625
|
+
.ask-user-send:disabled { opacity: 0.4; cursor: default; }
|
|
626
|
+
.ask-user-send:not(:disabled):hover { background: var(--accent-hover); }
|
|
627
|
+
.ask-user-submitted { font-size: 11px; color: var(--text-muted); font-style: italic; }
|
|
@@ -15,6 +15,8 @@ export type {
|
|
|
15
15
|
DiscussionThread,
|
|
16
16
|
Attachment,
|
|
17
17
|
ContextUsage,
|
|
18
|
+
AskUserItemData,
|
|
19
|
+
AskUserSelectionGroup,
|
|
18
20
|
} from '@agentpane/shared';
|
|
19
21
|
|
|
20
22
|
export type { ProviderDefinition, ProviderCapabilities, ProviderSlashCommand, SessionRuntimeConfig, ModelInfo, Extension } from '@agentpane/shared';
|
|
@@ -22,10 +22,24 @@ export type ItemType =
|
|
|
22
22
|
| 'todo_list'
|
|
23
23
|
| 'context_compaction'
|
|
24
24
|
| 'background_task'
|
|
25
|
+
| 'ask_user'
|
|
25
26
|
| 'error';
|
|
26
27
|
/** Item processing state. */
|
|
27
28
|
export type ItemStatus = 'in_progress' | 'completed' | 'failed';
|
|
28
29
|
|
|
30
|
+
/** One ask_user selection group — a question with clickable options. */
|
|
31
|
+
export interface AskUserSelectionGroup {
|
|
32
|
+
question: string;
|
|
33
|
+
selections: string[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** ask_user item data — the runtime's ask_user action payload. */
|
|
37
|
+
export interface AskUserItemData {
|
|
38
|
+
/** Fallback plain text when the selections payload is malformed. */
|
|
39
|
+
question: string;
|
|
40
|
+
groups: AskUserSelectionGroup[];
|
|
41
|
+
}
|
|
42
|
+
|
|
29
43
|
/** A session row — maps directly to the `sessions` SQLite table. */
|
|
30
44
|
export interface Session {
|
|
31
45
|
id: string;
|
|
@@ -90,6 +104,9 @@ export interface TurnBase {
|
|
|
90
104
|
thread_id: string | null;
|
|
91
105
|
/** Attachments sent with the user prompt (images, PDFs, text files). Null = no attachments. */
|
|
92
106
|
attachments: Attachment[] | null;
|
|
107
|
+
/** Runtime input ids composing this turn (rewind anchor mapping — repoburg;
|
|
108
|
+
* JSON array in the DB). Null = not recorded (turn predates the mapping). */
|
|
109
|
+
runtime_input_ids: string[] | null;
|
|
93
110
|
created_at: string;
|
|
94
111
|
updated_at: string;
|
|
95
112
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { AgentRuntimeContentBlock, AgentRuntimeMessage, AgentRuntimeToolResultBlock, AgentRuntimeUsage, StreamEventMessage, AgentRuntimeResultSubtype } from './agent-runtime.types';
|
|
2
|
+
export declare class AgentRuntimeEventEmitter {
|
|
3
|
+
private readonly logger;
|
|
4
|
+
private readonly clients;
|
|
5
|
+
private readonly turnStates;
|
|
6
|
+
private readonly subagents;
|
|
7
|
+
hasSubscribers(sessionId: string): boolean;
|
|
8
|
+
subscribe(sessionId: string, listener: (message: AgentRuntimeMessage) => void, opts?: {
|
|
9
|
+
deltas?: boolean;
|
|
10
|
+
}): () => void;
|
|
11
|
+
private emit;
|
|
12
|
+
emitStreamEvent(sessionId: string, inputId: string, delta: StreamEventMessage['delta']): void;
|
|
13
|
+
emitAssistant(sessionId: string, inputId: string, content: AgentRuntimeContentBlock[], usage?: AgentRuntimeUsage): void;
|
|
14
|
+
emitToolResult(sessionId: string, inputId: string, toolResult: AgentRuntimeToolResultBlock): void;
|
|
15
|
+
emitResult(sessionId: string, partial: {
|
|
16
|
+
subtype: AgentRuntimeResultSubtype;
|
|
17
|
+
is_error: boolean;
|
|
18
|
+
result: string;
|
|
19
|
+
errors?: string[];
|
|
20
|
+
}): void;
|
|
21
|
+
registerSubagent(childSessionId: string, meta: {
|
|
22
|
+
parentId: string;
|
|
23
|
+
inputId: string;
|
|
24
|
+
actionId: string;
|
|
25
|
+
agentName: string;
|
|
26
|
+
description: string;
|
|
27
|
+
}): void;
|
|
28
|
+
unregisterSubagent(childSessionId: string): void;
|
|
29
|
+
emitSubagentStarted(childSessionId: string): void;
|
|
30
|
+
emitSubagentSettled(childSessionId: string, settlement: {
|
|
31
|
+
success: boolean;
|
|
32
|
+
summary: string;
|
|
33
|
+
}): void;
|
|
34
|
+
private emitSubagentEvent;
|
|
35
|
+
private resolveDeliveryParent;
|
|
36
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var AgentRuntimeEventEmitter_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.AgentRuntimeEventEmitter = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const emptyUsage = () => ({
|
|
13
|
+
input_tokens: 0,
|
|
14
|
+
output_tokens: 0,
|
|
15
|
+
cache_read_input_tokens: 0,
|
|
16
|
+
cache_creation_input_tokens: 0,
|
|
17
|
+
});
|
|
18
|
+
let AgentRuntimeEventEmitter = AgentRuntimeEventEmitter_1 = class AgentRuntimeEventEmitter {
|
|
19
|
+
constructor() {
|
|
20
|
+
this.logger = new common_1.Logger(AgentRuntimeEventEmitter_1.name);
|
|
21
|
+
this.clients = new Map();
|
|
22
|
+
this.turnStates = new Map();
|
|
23
|
+
this.subagents = new Map();
|
|
24
|
+
}
|
|
25
|
+
hasSubscribers(sessionId) {
|
|
26
|
+
return (this.clients.get(sessionId)?.size ?? 0) > 0;
|
|
27
|
+
}
|
|
28
|
+
subscribe(sessionId, listener, opts = {}) {
|
|
29
|
+
const client = { listener, deltas: opts.deltas !== false };
|
|
30
|
+
let set = this.clients.get(sessionId);
|
|
31
|
+
if (!set) {
|
|
32
|
+
set = new Set();
|
|
33
|
+
this.clients.set(sessionId, set);
|
|
34
|
+
}
|
|
35
|
+
set.add(client);
|
|
36
|
+
this.logger.log(`SSE client subscribed to session ${sessionId} (deltas: ${client.deltas})`);
|
|
37
|
+
return () => {
|
|
38
|
+
set.delete(client);
|
|
39
|
+
if (set.size === 0)
|
|
40
|
+
this.clients.delete(sessionId);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
emit(message) {
|
|
44
|
+
const set = this.clients.get(message.sessionId);
|
|
45
|
+
if (!set || set.size === 0)
|
|
46
|
+
return;
|
|
47
|
+
for (const client of set) {
|
|
48
|
+
if (message.type === 'stream_event' && !client.deltas)
|
|
49
|
+
continue;
|
|
50
|
+
try {
|
|
51
|
+
client.listener(message);
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
this.logger.warn(`SSE listener failed: ${err.message}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
emitStreamEvent(sessionId, inputId, delta) {
|
|
59
|
+
this.emit({ type: 'stream_event', sessionId, inputId, delta });
|
|
60
|
+
}
|
|
61
|
+
emitAssistant(sessionId, inputId, content, usage) {
|
|
62
|
+
const sub = this.subagents.get(sessionId);
|
|
63
|
+
if (sub) {
|
|
64
|
+
if (usage) {
|
|
65
|
+
sub.usage.input_tokens += usage.input_tokens ?? 0;
|
|
66
|
+
sub.usage.output_tokens += usage.output_tokens ?? 0;
|
|
67
|
+
sub.usage.cache_read_input_tokens += usage.cache_read_input_tokens ?? 0;
|
|
68
|
+
sub.usage.cache_creation_input_tokens +=
|
|
69
|
+
usage.cache_creation_input_tokens ?? 0;
|
|
70
|
+
sub.tokenCount +=
|
|
71
|
+
(usage.input_tokens ?? 0) + (usage.output_tokens ?? 0);
|
|
72
|
+
}
|
|
73
|
+
this.emitSubagentEvent(sessionId, sub, 'progress');
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const state = this.turnStates.get(sessionId) ?? {
|
|
77
|
+
rounds: 0,
|
|
78
|
+
usage: emptyUsage(),
|
|
79
|
+
};
|
|
80
|
+
state.rounds += 1;
|
|
81
|
+
if (usage) {
|
|
82
|
+
state.usage.input_tokens += usage.input_tokens ?? 0;
|
|
83
|
+
state.usage.output_tokens += usage.output_tokens ?? 0;
|
|
84
|
+
state.usage.cache_read_input_tokens += usage.cache_read_input_tokens ?? 0;
|
|
85
|
+
state.usage.cache_creation_input_tokens +=
|
|
86
|
+
usage.cache_creation_input_tokens ?? 0;
|
|
87
|
+
}
|
|
88
|
+
this.turnStates.set(sessionId, state);
|
|
89
|
+
const message = {
|
|
90
|
+
type: 'assistant',
|
|
91
|
+
sessionId,
|
|
92
|
+
inputId,
|
|
93
|
+
content,
|
|
94
|
+
...(usage ? { usage } : {}),
|
|
95
|
+
};
|
|
96
|
+
this.emit(message);
|
|
97
|
+
}
|
|
98
|
+
emitToolResult(sessionId, inputId, toolResult) {
|
|
99
|
+
const sub = this.subagents.get(sessionId);
|
|
100
|
+
if (sub) {
|
|
101
|
+
const action = toolResult.action;
|
|
102
|
+
if (action.action_type !== 'final' &&
|
|
103
|
+
action.action_type !== 'html_final') {
|
|
104
|
+
const detail = action.file_path ?? action.command_string ?? action.tool_name ?? '';
|
|
105
|
+
sub.description = detail
|
|
106
|
+
? `${action.action_type}: ${detail}`
|
|
107
|
+
: action.action_type;
|
|
108
|
+
sub.lastToolName = action.action_type;
|
|
109
|
+
}
|
|
110
|
+
this.emitSubagentEvent(sessionId, sub, 'progress');
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const message = {
|
|
114
|
+
type: 'user',
|
|
115
|
+
sessionId,
|
|
116
|
+
inputId,
|
|
117
|
+
content: [toolResult],
|
|
118
|
+
};
|
|
119
|
+
this.emit(message);
|
|
120
|
+
}
|
|
121
|
+
emitResult(sessionId, partial) {
|
|
122
|
+
if (this.subagents.has(sessionId))
|
|
123
|
+
return;
|
|
124
|
+
const state = this.turnStates.get(sessionId);
|
|
125
|
+
const message = {
|
|
126
|
+
type: 'result',
|
|
127
|
+
subtype: partial.subtype,
|
|
128
|
+
sessionId,
|
|
129
|
+
is_error: partial.is_error,
|
|
130
|
+
result: partial.result,
|
|
131
|
+
num_rounds: state?.rounds ?? 0,
|
|
132
|
+
...(state && state.rounds > 0 ? { usage: state.usage } : {}),
|
|
133
|
+
...(partial.errors ? { errors: partial.errors } : {}),
|
|
134
|
+
};
|
|
135
|
+
this.turnStates.delete(sessionId);
|
|
136
|
+
this.emit(message);
|
|
137
|
+
}
|
|
138
|
+
registerSubagent(childSessionId, meta) {
|
|
139
|
+
this.subagents.set(childSessionId, {
|
|
140
|
+
parentId: meta.parentId,
|
|
141
|
+
inputId: meta.inputId,
|
|
142
|
+
actionId: meta.actionId,
|
|
143
|
+
agentName: meta.agentName,
|
|
144
|
+
description: meta.description,
|
|
145
|
+
lastToolName: null,
|
|
146
|
+
tokenCount: 0,
|
|
147
|
+
usage: emptyUsage(),
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
unregisterSubagent(childSessionId) {
|
|
151
|
+
this.subagents.delete(childSessionId);
|
|
152
|
+
}
|
|
153
|
+
emitSubagentStarted(childSessionId) {
|
|
154
|
+
const sub = this.subagents.get(childSessionId);
|
|
155
|
+
if (sub)
|
|
156
|
+
this.emitSubagentEvent(childSessionId, sub, 'started');
|
|
157
|
+
}
|
|
158
|
+
emitSubagentSettled(childSessionId, settlement) {
|
|
159
|
+
const sub = this.subagents.get(childSessionId);
|
|
160
|
+
if (!sub)
|
|
161
|
+
return;
|
|
162
|
+
this.emitSubagentEvent(childSessionId, sub, settlement.success ? 'completed' : 'failed', { summary: settlement.summary });
|
|
163
|
+
this.subagents.delete(childSessionId);
|
|
164
|
+
}
|
|
165
|
+
emitSubagentEvent(childSessionId, sub, event, extra = {}) {
|
|
166
|
+
const message = {
|
|
167
|
+
type: 'subagent',
|
|
168
|
+
sessionId: this.resolveDeliveryParent(sub),
|
|
169
|
+
event,
|
|
170
|
+
task_id: childSessionId,
|
|
171
|
+
agent_name: sub.agentName,
|
|
172
|
+
description: sub.description,
|
|
173
|
+
input_id: sub.inputId,
|
|
174
|
+
action_id: sub.actionId,
|
|
175
|
+
...(sub.lastToolName !== null || event !== 'started'
|
|
176
|
+
? { last_tool_name: sub.lastToolName }
|
|
177
|
+
: {}),
|
|
178
|
+
...(sub.tokenCount > 0 ? { token_count: sub.tokenCount } : {}),
|
|
179
|
+
...(event === 'completed' || event === 'failed'
|
|
180
|
+
? { summary: extra.summary ?? '', usage: sub.usage }
|
|
181
|
+
: {}),
|
|
182
|
+
};
|
|
183
|
+
this.emit(message);
|
|
184
|
+
}
|
|
185
|
+
resolveDeliveryParent(sub) {
|
|
186
|
+
let parentId = sub.parentId;
|
|
187
|
+
let guard = 0;
|
|
188
|
+
while (this.subagents.has(parentId) && guard < 100) {
|
|
189
|
+
parentId = this.subagents.get(parentId).parentId;
|
|
190
|
+
guard += 1;
|
|
191
|
+
}
|
|
192
|
+
return parentId;
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
exports.AgentRuntimeEventEmitter = AgentRuntimeEventEmitter;
|
|
196
|
+
exports.AgentRuntimeEventEmitter = AgentRuntimeEventEmitter = AgentRuntimeEventEmitter_1 = __decorate([
|
|
197
|
+
(0, common_1.Injectable)()
|
|
198
|
+
], AgentRuntimeEventEmitter);
|
|
199
|
+
//# sourceMappingURL=agent-runtime-event-emitter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-runtime-event-emitter.js","sourceRoot":"","sources":["../../../src/agent-runtime/agent-runtime-event-emitter.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAoD;AA0BpD,MAAM,UAAU,GAAG,GAAsB,EAAE,CAAC,CAAC;IAC3C,YAAY,EAAE,CAAC;IACf,aAAa,EAAE,CAAC;IAChB,uBAAuB,EAAE,CAAC;IAC1B,2BAA2B,EAAE,CAAC;CAC/B,CAAC,CAAC;AA6BI,IAAM,wBAAwB,gCAA9B,MAAM,wBAAwB;IAA9B;QACY,WAAM,GAAG,IAAI,eAAM,CAAC,0BAAwB,CAAC,IAAI,CAAC,CAAC;QACnD,YAAO,GAAG,IAAI,GAAG,EAA0B,CAAC;QAC5C,eAAU,GAAG,IAAI,GAAG,EAAqB,CAAC;QAC1C,cAAS,GAAG,IAAI,GAAG,EAAgC,CAAC;IAyQvE,CAAC;IAtQC,cAAc,CAAC,SAAiB;QAC9B,OAAO,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,IAAA,mBAAU,GAAE;GACA,wBAAwB,CA6QpC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Repository } from 'typeorm';
|
|
2
|
+
import { Response } from 'express';
|
|
3
|
+
import { Session } from '../core-entities';
|
|
4
|
+
import { AgentRuntimeEventEmitter } from './agent-runtime-event-emitter';
|
|
5
|
+
export declare class AgentRuntimeController {
|
|
6
|
+
private readonly emitter;
|
|
7
|
+
private readonly sessionsRepository;
|
|
8
|
+
private readonly logger;
|
|
9
|
+
constructor(emitter: AgentRuntimeEventEmitter, sessionsRepository: Repository<Session>);
|
|
10
|
+
streamMessages(sessionId: string, stream: string | undefined, res: Response): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var AgentRuntimeController_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.AgentRuntimeController = void 0;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
19
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
20
|
+
const typeorm_2 = require("typeorm");
|
|
21
|
+
const core_entities_1 = require("../core-entities");
|
|
22
|
+
const agent_runtime_event_emitter_1 = require("./agent-runtime-event-emitter");
|
|
23
|
+
const HEARTBEAT_INTERVAL_MS = 15_000;
|
|
24
|
+
let AgentRuntimeController = AgentRuntimeController_1 = class AgentRuntimeController {
|
|
25
|
+
constructor(emitter, sessionsRepository) {
|
|
26
|
+
this.emitter = emitter;
|
|
27
|
+
this.sessionsRepository = sessionsRepository;
|
|
28
|
+
this.logger = new common_1.Logger(AgentRuntimeController_1.name);
|
|
29
|
+
}
|
|
30
|
+
async streamMessages(sessionId, stream, res) {
|
|
31
|
+
const session = await this.sessionsRepository.findOne({
|
|
32
|
+
where: { id: sessionId },
|
|
33
|
+
select: ['id', 'model_id'],
|
|
34
|
+
});
|
|
35
|
+
if (!session) {
|
|
36
|
+
res.status(404).json({ message: `Session "${sessionId}" not found.` });
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
res.status(200);
|
|
40
|
+
res.setHeader('Content-Type', 'text/event-stream');
|
|
41
|
+
res.setHeader('Cache-Control', 'no-cache, no-transform');
|
|
42
|
+
res.setHeader('Connection', 'keep-alive');
|
|
43
|
+
res.setHeader('X-Accel-Buffering', 'no');
|
|
44
|
+
res.flushHeaders();
|
|
45
|
+
const write = (message) => {
|
|
46
|
+
res.write(`data: ${JSON.stringify(message)}\n\n`);
|
|
47
|
+
};
|
|
48
|
+
write({
|
|
49
|
+
type: 'system',
|
|
50
|
+
subtype: 'init',
|
|
51
|
+
sessionId,
|
|
52
|
+
modelId: session.model_id ?? null,
|
|
53
|
+
});
|
|
54
|
+
const unsubscribe = this.emitter.subscribe(sessionId, write, {
|
|
55
|
+
deltas: stream !== '0',
|
|
56
|
+
});
|
|
57
|
+
const heartbeat = setInterval(() => {
|
|
58
|
+
res.write(': ping\n\n');
|
|
59
|
+
}, HEARTBEAT_INTERVAL_MS);
|
|
60
|
+
res.on('close', () => {
|
|
61
|
+
clearInterval(heartbeat);
|
|
62
|
+
unsubscribe();
|
|
63
|
+
this.logger.log(`SSE client disconnected from session ${sessionId}`);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
exports.AgentRuntimeController = AgentRuntimeController;
|
|
68
|
+
__decorate([
|
|
69
|
+
(0, common_1.Get)('sessions/:sessionId/messages'),
|
|
70
|
+
(0, swagger_1.ApiOperation)({
|
|
71
|
+
summary: 'Agent-runtime message stream (SSE)',
|
|
72
|
+
description: 'Ordered agent-runtime messages for a session. Opens with system/init; ' +
|
|
73
|
+
'the terminal result message ends a turn. Heartbeat comments keep the ' +
|
|
74
|
+
'connection alive between messages.',
|
|
75
|
+
}),
|
|
76
|
+
(0, swagger_1.ApiParam)({ name: 'sessionId', description: 'Session UUID', format: 'uuid' }),
|
|
77
|
+
__param(0, (0, common_1.Param)('sessionId', common_1.ParseUUIDPipe)),
|
|
78
|
+
__param(1, (0, common_1.Query)('stream')),
|
|
79
|
+
__param(2, (0, common_1.Res)()),
|
|
80
|
+
__metadata("design:type", Function),
|
|
81
|
+
__metadata("design:paramtypes", [String, String, Object]),
|
|
82
|
+
__metadata("design:returntype", Promise)
|
|
83
|
+
], AgentRuntimeController.prototype, "streamMessages", null);
|
|
84
|
+
exports.AgentRuntimeController = AgentRuntimeController = AgentRuntimeController_1 = __decorate([
|
|
85
|
+
(0, swagger_1.ApiTags)('agent-runtime'),
|
|
86
|
+
(0, common_1.Controller)('agent-runtime'),
|
|
87
|
+
__param(1, (0, typeorm_1.InjectRepository)(core_entities_1.Session)),
|
|
88
|
+
__metadata("design:paramtypes", [agent_runtime_event_emitter_1.AgentRuntimeEventEmitter,
|
|
89
|
+
typeorm_2.Repository])
|
|
90
|
+
], AgentRuntimeController);
|
|
91
|
+
//# sourceMappingURL=agent-runtime.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-runtime.controller.js","sourceRoot":"","sources":["../../../src/agent-runtime/agent-runtime.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAQwB;AACxB,6CAAkE;AAClE,6CAAmD;AACnD,qCAAqC;AAErC,oDAA2C;AAC3C,+EAAyE;AAGzE,MAAM,qBAAqB,GAAG,MAAM,CAAC;AAW9B,IAAM,sBAAsB,8BAA5B,MAAM,sBAAsB;IAGjC,YACmB,OAAiC,EAElD,kBAAwD;QAFvC,YAAO,GAAP,OAAO,CAA0B;QAEjC,uBAAkB,GAAlB,kBAAkB,CAAqB;QALzC,WAAM,GAAG,IAAI,eAAM,CAAC,wBAAsB,CAAC,IAAI,CAAC,CAAC;IAM/D,CAAC;IAWE,AAAN,KAAK,CAAC,cAAc,CACiB,SAAiB,EACnC,MAA0B,EACpC,GAAa;QAEpB,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC;YACpD,KAAK,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE;YACxB,MAAM,EAAE,CAAC,IAAI,EAAE,UAAU,CAAC;SAC3B,CAAC,CAAC;QACH,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,YAAY,SAAS,cAAc,EAAE,CAAC,CAAC;YACvE,OAAO;QACT,CAAC;QAED,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAChB,GAAG,CAAC,SAAS,CAAC,cAAc,EAAE,mBAAmB,CAAC,CAAC;QACnD,GAAG,CAAC,SAAS,CAAC,eAAe,EAAE,wBAAwB,CAAC,CAAC;QACzD,GAAG,CAAC,SAAS,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;QAC1C,GAAG,CAAC,SAAS,CAAC,mBAAmB,EAAE,IAAI,CAAC,CAAC;QACzC,GAAG,CAAC,YAAY,EAAE,CAAC;QAEnB,MAAM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CAAA;;;;4DA2CP;iCAhEU,sBAAsB;IAFlC,IAAA,iBAAO,EAAC,eAAe,CAAC;IACxB,IAAA,mBAAU,EAAC,eAAe,CAAC;IAMvB,WAAA,IAAA,0BAAgB,EAAC,uBAAO,CAAC,CAAA;qCADA,sDAAwB;QAEb,oBAAU;GANtC,sBAAsB,CAiElC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.AgentRuntimeModule = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
12
|
+
const core_entities_1 = require("../core-entities");
|
|
13
|
+
const agent_runtime_controller_1 = require("./agent-runtime.controller");
|
|
14
|
+
const agent_runtime_event_emitter_1 = require("./agent-runtime-event-emitter");
|
|
15
|
+
let AgentRuntimeModule = class AgentRuntimeModule {
|
|
16
|
+
};
|
|
17
|
+
exports.AgentRuntimeModule = AgentRuntimeModule;
|
|
18
|
+
exports.AgentRuntimeModule = AgentRuntimeModule = __decorate([
|
|
19
|
+
(0, common_1.Module)({
|
|
20
|
+
imports: [typeorm_1.TypeOrmModule.forFeature([core_entities_1.Session])],
|
|
21
|
+
controllers: [agent_runtime_controller_1.AgentRuntimeController],
|
|
22
|
+
providers: [agent_runtime_event_emitter_1.AgentRuntimeEventEmitter],
|
|
23
|
+
exports: [agent_runtime_event_emitter_1.AgentRuntimeEventEmitter],
|
|
24
|
+
})
|
|
25
|
+
], AgentRuntimeModule);
|
|
26
|
+
//# sourceMappingURL=agent-runtime.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-runtime.module.js","sourceRoot":"","sources":["../../../src/agent-runtime/agent-runtime.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,6CAAgD;AAChD,oDAA2C;AAC3C,yEAAoE;AACpE,+EAAyE;AAalE,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;CAAG,CAAA;AAArB,gDAAkB;6BAAlB,kBAAkB;IAN9B,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,uBAAa,CAAC,UAAU,CAAC,CAAC,uBAAO,CAAC,CAAC,CAAC;QAC9C,WAAW,EAAE,CAAC,iDAAsB,CAAC;QACrC,SAAS,EAAE,CAAC,sDAAwB,CAAC;QACrC,OAAO,EAAE,CAAC,sDAAwB,CAAC;KACpC,CAAC;GACW,kBAAkB,CAAG"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
export interface AgentRuntimeUsage {
|
|
2
|
+
input_tokens: number;
|
|
3
|
+
output_tokens: number;
|
|
4
|
+
cache_read_input_tokens: number;
|
|
5
|
+
cache_creation_input_tokens: number;
|
|
6
|
+
}
|
|
7
|
+
export type AgentRuntimeContentBlock = {
|
|
8
|
+
type: 'text';
|
|
9
|
+
text: string;
|
|
10
|
+
} | {
|
|
11
|
+
type: 'thinking';
|
|
12
|
+
thinking: string;
|
|
13
|
+
} | {
|
|
14
|
+
type: 'tool_use';
|
|
15
|
+
id: string;
|
|
16
|
+
name: string;
|
|
17
|
+
input: Record<string, unknown> | null;
|
|
18
|
+
};
|
|
19
|
+
export interface AgentRuntimeActionInfo {
|
|
20
|
+
id: string;
|
|
21
|
+
action_type: string;
|
|
22
|
+
file_path: string | null;
|
|
23
|
+
command_string: string | null;
|
|
24
|
+
status: string;
|
|
25
|
+
server_name: string | null;
|
|
26
|
+
tool_name: string | null;
|
|
27
|
+
arguments: string | null;
|
|
28
|
+
plain: string | null;
|
|
29
|
+
selections: string | null;
|
|
30
|
+
order_of_execution: number;
|
|
31
|
+
}
|
|
32
|
+
export interface AgentRuntimeToolResultBlock {
|
|
33
|
+
type: 'tool_result';
|
|
34
|
+
tool_use_id: string;
|
|
35
|
+
content: string;
|
|
36
|
+
is_error: boolean;
|
|
37
|
+
action: AgentRuntimeActionInfo;
|
|
38
|
+
}
|
|
39
|
+
export interface SystemInitMessage {
|
|
40
|
+
type: 'system';
|
|
41
|
+
subtype: 'init';
|
|
42
|
+
sessionId: string;
|
|
43
|
+
modelId: string | null;
|
|
44
|
+
}
|
|
45
|
+
export interface StreamEventMessage {
|
|
46
|
+
type: 'stream_event';
|
|
47
|
+
sessionId: string;
|
|
48
|
+
inputId: string;
|
|
49
|
+
delta: {
|
|
50
|
+
type: 'text' | 'thinking';
|
|
51
|
+
text: string;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export interface AssistantMessage {
|
|
55
|
+
type: 'assistant';
|
|
56
|
+
sessionId: string;
|
|
57
|
+
inputId: string;
|
|
58
|
+
content: AgentRuntimeContentBlock[];
|
|
59
|
+
usage?: AgentRuntimeUsage;
|
|
60
|
+
}
|
|
61
|
+
export interface UserMessage {
|
|
62
|
+
type: 'user';
|
|
63
|
+
sessionId: string;
|
|
64
|
+
inputId: string;
|
|
65
|
+
content: AgentRuntimeToolResultBlock[];
|
|
66
|
+
}
|
|
67
|
+
export interface SubagentMessage {
|
|
68
|
+
type: 'subagent';
|
|
69
|
+
sessionId: string;
|
|
70
|
+
event: 'started' | 'progress' | 'completed' | 'failed';
|
|
71
|
+
task_id: string;
|
|
72
|
+
agent_name: string;
|
|
73
|
+
description: string;
|
|
74
|
+
input_id: string;
|
|
75
|
+
action_id: string;
|
|
76
|
+
last_tool_name?: string | null;
|
|
77
|
+
token_count?: number;
|
|
78
|
+
summary?: string;
|
|
79
|
+
usage?: AgentRuntimeUsage;
|
|
80
|
+
}
|
|
81
|
+
export type AgentRuntimeResultSubtype = 'success' | 'error_during_execution' | 'aborted';
|
|
82
|
+
export interface ResultMessage {
|
|
83
|
+
type: 'result';
|
|
84
|
+
subtype: AgentRuntimeResultSubtype;
|
|
85
|
+
sessionId: string;
|
|
86
|
+
is_error: boolean;
|
|
87
|
+
result: string;
|
|
88
|
+
usage?: AgentRuntimeUsage;
|
|
89
|
+
num_rounds: number;
|
|
90
|
+
errors?: string[];
|
|
91
|
+
}
|
|
92
|
+
export type AgentRuntimeMessage = SystemInitMessage | StreamEventMessage | AssistantMessage | UserMessage | SubagentMessage | ResultMessage;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-runtime.types.js","sourceRoot":"","sources":["../../../src/agent-runtime/agent-runtime.types.ts"],"names":[],"mappings":""}
|
|
@@ -45,6 +45,7 @@ const global_config_module_1 = require("./global-config/global-config.module");
|
|
|
45
45
|
const agents_module_1 = require("./agents/agents.module");
|
|
46
46
|
const mcp_server_module_1 = require("./mcp-server/mcp-server.module");
|
|
47
47
|
const marketplace_module_1 = require("./mcp/marketplace/marketplace.module");
|
|
48
|
+
const agent_runtime_module_1 = require("./agent-runtime/agent-runtime.module");
|
|
48
49
|
let dbPath = ':memory:';
|
|
49
50
|
if (process.env.NODE_ENV === 'production') {
|
|
50
51
|
const projectPath = process.env.REPOBURG_PROJECT_PATH || process.cwd();
|
|
@@ -115,6 +116,9 @@ exports.AppModule = AppModule = __decorate([
|
|
|
115
116
|
agents_module_1.AgentsModule,
|
|
116
117
|
mcp_server_module_1.McpServerModule,
|
|
117
118
|
marketplace_module_1.MarketplaceModule,
|
|
119
|
+
mcp_server_module_1.McpServerModule,
|
|
120
|
+
marketplace_module_1.MarketplaceModule,
|
|
121
|
+
agent_runtime_module_1.AgentRuntimeModule,
|
|
118
122
|
],
|
|
119
123
|
controllers: [app_controller_1.AppController],
|
|
120
124
|
providers: [app_service_1.AppService],
|