Skip to content

Commit efeed97

Browse files
committed
add untracked files from previous commit
1 parent 4ba0db8 commit efeed97

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import type { AgentTemplate } from '@codebuff/common/types/agent-template'
2+
import type { AssistantMessage } from '@codebuff/common/types/messages/codebuff-message'
3+
import type { AgentState, AgentOutput } from '@codebuff/common/types/session-state'
4+
5+
export function getAgentOutput(
6+
agentState: AgentState,
7+
agentTemplate: AgentTemplate,
8+
): AgentOutput {
9+
if (agentTemplate.outputMode === 'structured_output') {
10+
return {
11+
type: 'structuredOutput',
12+
value: agentState.output ?? null,
13+
}
14+
}
15+
if (agentTemplate.outputMode === 'last_message') {
16+
const assistantMessages = agentState.messageHistory.filter(
17+
(message): message is AssistantMessage => message.role === 'assistant',
18+
)
19+
const lastAssistantMessage = assistantMessages[assistantMessages.length - 1]
20+
if (!lastAssistantMessage) {
21+
return {
22+
type: 'error',
23+
message: 'No response from agent',
24+
}
25+
}
26+
return {
27+
type: 'lastMessage',
28+
value: lastAssistantMessage.content,
29+
}
30+
}
31+
if (agentTemplate.outputMode === 'all_messages') {
32+
// Remove the first message, which includes the previous conversation history.
33+
const agentMessages = agentState.messageHistory.slice(1)
34+
return {
35+
type: 'allMessages',
36+
value: agentMessages,
37+
}
38+
}
39+
agentTemplate.outputMode satisfies never
40+
throw new Error(
41+
`Unknown output mode: ${'outputMode' in agentTemplate ? agentTemplate.outputMode : 'undefined'}`,
42+
)
43+
}

plans/agent-runtime-migration.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Move the file (provided by the user) from `backend/src/some/path.ts` to `packages/agent-runtime/src/some/path.ts`
2+
If there is a test file, it will most likely be at `backend/src/some/__tests__/path.test.ts` If that file exists, move it to `packages/agent-runtime/src/some/__tests__/path.test.ts` If it does not exist, the test may or may not exist, do not worry for now.
3+
4+
Most likely, there will be import errors:
5+
6+
- Repeatedly run `bun run typecheck` in the project root and fix the typecheck errors.
7+
- Any reference from `backend/` to `packages/agent-runtime/` should be imported as `@codebuff/agent-runtime/some/path`
8+
- Any reference from `packages/agent-runtime/` to another file in `agent-runtime` should be imported relatively (e.g. `../some/path`)
9+
- The file moved to `packages/agent-runtime` should never reference a file in `backend/`. If it does, this was an error and you should ask the user what to do and disregard the rest of this file.
10+
- Also, search for the regex in `packages/agent-runtime/`: `@codebuff/agent-runtime`. You should find nothing in any _code_ files. If you find something, replace it with the relative path.
11+
- It does appear in `package.json`, but ignore that file.
12+
13+
Run `bun test $(find . -name '*.test.ts')` twice: in `backend/` and `packages/agent-runtime/`
14+
If they do not pass, do NOT fix the tests (unless it is an import error, which should have been fixed in the step before. You can fix the imports, but do not change the test logic). Ask the user what to do and disregard the rest of this file.
15+
16+
If the tests pass, git add the changed files, then commit the changes. No need to use any subagent to commit, you have all the context you need.
17+
18+
Always listen to the user's feedback and make changes accordingly.

0 commit comments

Comments
 (0)