Skip to content

Commit d067a1b

Browse files
committed
move util/messages to agent-runtime
1 parent ef6ef05 commit d067a1b

File tree

14 files changed

+30
-30
lines changed

14 files changed

+30
-30
lines changed

backend/src/__tests__/run-agent-step-tools.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { asUserMessage } from '@codebuff/agent-runtime/util/messages'
12
import * as bigquery from '@codebuff/bigquery'
23
import * as analytics from '@codebuff/common/analytics'
34
import db from '@codebuff/common/db'
@@ -19,11 +20,9 @@ import {
1920
spyOn,
2021
} from 'bun:test'
2122

22-
// Mock imports
2323
import * as liveUserInputs from '../live-user-inputs'
2424
import { runAgentStep } from '../run-agent-step'
2525
import { clearAgentGeneratorCache } from '../run-programmatic-step'
26-
import { asUserMessage } from '../util/messages'
2726

2827
import type { AgentTemplate } from '@codebuff/agent-runtime/templates/types'
2928
import type {

backend/src/admin/relabelRuns.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { messagesWithSystem } from '@codebuff/agent-runtime/util/messages'
12
import {
23
getTracesAndAllDataForUser,
34
getTracesWithoutRelabels,
@@ -14,9 +15,8 @@ import { closeXml } from '@codebuff/common/util/xml'
1415

1516
import { rerank } from '../llm-apis/relace-api'
1617
import { promptAiSdk } from '../llm-apis/vercel-ai-sdk/ai-sdk'
17-
import { messagesWithSystem } from '../util/messages'
1818

19-
import type { System } from '../llm-apis/claude'
19+
import type { System } from '@codebuff/agent-runtime/llm-api/claude'
2020
import type {
2121
GetExpandedFileContextForTrainingBlobTrace,
2222
GetExpandedFileContextForTrainingTrace,

backend/src/find-files/request-files-prompt.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { dirname, isAbsolute, normalize } from 'path'
22

3+
import {
4+
castAssistantMessage,
5+
messagesWithSystem,
6+
getMessagesSubset,
7+
} from '@codebuff/agent-runtime/util/messages'
38
import { insertTrace } from '@codebuff/bigquery'
49
import db from '@codebuff/common/db'
510
import * as schema from '@codebuff/common/db/schema'
@@ -14,15 +19,10 @@ import { range, shuffle, uniq } from 'lodash'
1419

1520
import { CustomFilePickerConfigSchema } from './custom-file-picker-config'
1621
import { promptFlashWithFallbacks } from '../llm-apis/gemini-with-fallbacks'
17-
import {
18-
castAssistantMessage,
19-
messagesWithSystem,
20-
getMessagesSubset,
21-
} from '../util/messages'
2222
import { getRequestContext } from '../websockets/request-context'
2323

2424
import type { CustomFilePickerConfig } from './custom-file-picker-config'
25-
import type { TextBlock } from '../llm-apis/claude'
25+
import type { TextBlock } from '@codebuff/agent-runtime/llm-api/claude'
2626
import type {
2727
GetExpandedFileContextForTrainingTrace,
2828
GetRelevantFilesTrace,

backend/src/main-prompt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import { expireMessages } from '@codebuff/agent-runtime/util/messages'
12
import { AgentTemplateTypes } from '@codebuff/common/types/session-state'
23
import { generateCompactId } from '@codebuff/common/util/string'
34
import { uniq } from 'lodash'
45

56
import { checkTerminalCommand } from './check-terminal-command'
67
import { loopAgentSteps } from './run-agent-step'
78
import { getAgentTemplate } from './templates/agent-registry'
8-
import { expireMessages } from './util/messages'
99

1010
import type { AgentTemplate } from '@codebuff/agent-runtime/templates/types'
1111
import type { ClientAction } from '@codebuff/common/actions'

backend/src/run-agent-step.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
import {
2+
asSystemInstruction,
3+
asSystemMessage,
4+
buildUserMessageContent,
5+
messagesWithSystem,
6+
expireMessages,
7+
} from '@codebuff/agent-runtime/util/messages'
18
import { countTokensJson } from '@codebuff/agent-runtime/util/token-counter'
29
import { insertTrace } from '@codebuff/bigquery'
310
import { trackEvent } from '@codebuff/common/analytics'
@@ -17,13 +24,6 @@ import { getAgentTemplate } from './templates/agent-registry'
1724
import { getAgentPrompt } from './templates/strings'
1825
import { processStreamWithTools } from './tools/stream-parser'
1926
import { getAgentOutput } from './util/agent-output'
20-
import {
21-
asSystemInstruction,
22-
asSystemMessage,
23-
buildUserMessageContent,
24-
messagesWithSystem,
25-
expireMessages,
26-
} from './util/messages'
2727
import { getRequestContext } from './websockets/request-context'
2828

2929
import type { AgentResponseTrace } from '@codebuff/bigquery'

backend/src/templates/strings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
PLACEHOLDER,
33
placeholderValues,
44
} from '@codebuff/agent-runtime/templates/types'
5+
import { parseUserMessage } from '@codebuff/agent-runtime/util/messages'
56
import { CodebuffConfigSchema } from '@codebuff/common/json-config/constants'
67
import { escapeString } from '@codebuff/common/util/string'
78
import { schemaToJsonStr } from '@codebuff/common/util/zod-schema'
@@ -19,7 +20,6 @@ import {
1920
getShortToolInstructions,
2021
getToolsInstructions,
2122
} from '../tools/prompts'
22-
import { parseUserMessage } from '../util/messages'
2323

2424
import type {
2525
AgentTemplate,

backend/src/tools/stream-parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { expireMessages } from '@codebuff/agent-runtime/util/messages'
12
import {
23
endToolTag,
34
startToolTag,
@@ -9,7 +10,6 @@ import { generateCompactId } from '@codebuff/common/util/string'
910
import { cloneDeep } from 'lodash'
1011

1112
import { executeBatchStrReplaces } from './batch-str-replace'
12-
import { expireMessages } from '../util/messages'
1313
import { processStreamWithTags } from '../xml-stream-parser'
1414
import { executeCustomToolCall, executeToolCall } from './tool-executor'
1515

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Simple text block type that doesn't depend on Anthropic SDK
22
export type TextBlock = {
33
text: string
4-
type?: 'text'
4+
type: 'text'
55
}
66

77
export type System = string | Array<TextBlock>

backend/src/util/__tests__/messages.test.ts renamed to packages/agent-runtime/src/util/__tests__/messages.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as tokenCounter from '@codebuff/agent-runtime/util/token-counter'
21
import {
32
afterEach,
43
beforeEach,
@@ -13,7 +12,9 @@ import {
1312
trimMessagesToFitTokenLimit,
1413
messagesWithSystem,
1514
getPreviouslyReadFiles,
16-
} from '../messages'
15+
} from '@codebuff/agent-runtime/util/messages'
16+
17+
import * as tokenCounter from '../token-counter'
1718

1819
import type { CodebuffToolMessage } from '@codebuff/common/tools/list'
1920
import type {

0 commit comments

Comments
 (0)