Skip to content

Commit 2b9e8e3

Browse files
committed
add types package
1 parent bc13f76 commit 2b9e8e3

File tree

11 files changed

+98
-75
lines changed

11 files changed

+98
-75
lines changed

backend/src/agent-run.ts

Lines changed: 34 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,15 @@ import type {
77
AddAgentStepFn,
88
FinishAgentRunFn,
99
StartAgentRunFn,
10-
Logger,
11-
} from '@codebuff/agent-runtime'
10+
} from '@codebuff/types/database'
1211

1312
/**
1413
* Starts a new agent run and creates an entry in the agent_run table
1514
*/
16-
export async function startAgentRun({
17-
runId,
18-
userId,
19-
agentId,
20-
ancestorRunIds,
21-
logger,
22-
}: {
23-
runId?: string
24-
userId?: string
25-
agentId: string
26-
ancestorRunIds: string[]
27-
logger: Logger
28-
}): Promise<string> {
15+
export async function startAgentRun(
16+
params: Parameters<StartAgentRunFn>[0],
17+
): ReturnType<StartAgentRunFn> {
18+
const { runId, userId, agentId, ancestorRunIds, logger } = params
2919
if (userId === TEST_USER_ID) {
3020
return 'test-run-id'
3121
}
@@ -51,30 +41,23 @@ export async function startAgentRun({
5141
throw error
5242
}
5343
}
54-
startAgentRun satisfies StartAgentRunFn
5544

5645
/**
5746
* Completes an agent run by updating its status and metrics
5847
*/
59-
export async function finishAgentRun({
60-
userId,
61-
runId,
62-
status,
63-
totalSteps,
64-
directCredits,
65-
totalCredits,
66-
errorMessage,
67-
logger,
68-
}: {
69-
userId: string | undefined
70-
runId: string
71-
status: 'completed' | 'failed' | 'cancelled'
72-
totalSteps: number
73-
directCredits: number
74-
totalCredits: number
75-
errorMessage?: string
76-
logger: Logger
77-
}): Promise<void> {
48+
export async function finishAgentRun(
49+
params: Parameters<FinishAgentRunFn>[0],
50+
): ReturnType<FinishAgentRunFn> {
51+
const {
52+
userId,
53+
runId,
54+
status,
55+
totalSteps,
56+
directCredits,
57+
totalCredits,
58+
errorMessage,
59+
logger,
60+
} = params
7861
if (userId === TEST_USER_ID) {
7962
return
8063
}
@@ -96,34 +79,26 @@ export async function finishAgentRun({
9679
throw error
9780
}
9881
}
99-
finishAgentRun satisfies FinishAgentRunFn
10082

10183
/**
10284
* Adds a completed step to the agent_step table
10385
*/
104-
export async function addAgentStep({
105-
userId,
106-
agentRunId,
107-
stepNumber,
108-
credits,
109-
childRunIds,
110-
messageId,
111-
status = 'completed',
112-
errorMessage,
113-
startTime,
114-
logger,
115-
}: {
116-
userId: string | undefined
117-
agentRunId: string
118-
stepNumber: number
119-
credits?: number
120-
childRunIds?: string[]
121-
messageId: string | null
122-
status?: 'running' | 'completed' | 'skipped'
123-
errorMessage?: string
124-
startTime: Date
125-
logger: Logger
126-
}): Promise<string> {
86+
export async function addAgentStep(
87+
params: Parameters<AddAgentStepFn>[0],
88+
): ReturnType<AddAgentStepFn> {
89+
const {
90+
userId,
91+
agentRunId,
92+
stepNumber,
93+
credits,
94+
childRunIds,
95+
messageId,
96+
status = 'completed',
97+
errorMessage,
98+
startTime,
99+
logger,
100+
} = params
101+
127102
if (userId === TEST_USER_ID) {
128103
return 'test-step-id'
129104
}
@@ -149,4 +124,3 @@ export async function addAgentStep({
149124
throw error
150125
}
151126
}
152-
addAgentStep satisfies AddAgentStepFn

bun.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
},
3333
"dependencies": {
3434
"@auth/drizzle-adapter": "^1.5.0",
35+
"@codebuff/types": "workspace:*",
3536
"@modelcontextprotocol/sdk": "^1.18.2",
3637
"@types/pg": "^8.11.10",
3738
"@types/readable-stream": "^4.0.18",
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
export type * from './types'

packages/agent-runtime/src/types/index.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

packages/agent-runtime/src/types/logger.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/types/package.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "@codebuff/types",
3+
"version": "0.0.0",
4+
"private": true,
5+
"type": "module",
6+
"exports": {
7+
".": {
8+
"bun": "./src/index.ts",
9+
"import": "./src/index.ts",
10+
"types": "./src/index.ts",
11+
"default": "./src/index.ts"
12+
},
13+
"./*": {
14+
"bun": "./src/*.ts",
15+
"import": "./src/*.ts",
16+
"types": "./src/*.ts",
17+
"default": "./src/*.ts"
18+
}
19+
},
20+
"scripts": {
21+
"typecheck": "tsc --noEmit -p .",
22+
"test": "bun test"
23+
},
24+
"sideEffects": false,
25+
"engines": {
26+
"bun": ">=1.2.11"
27+
},
28+
"devDependencies": {
29+
"@types/node": "22",
30+
"@types/bun": "^1.2.11"
31+
}
32+
}
File renamed without changes.

packages/types/src/index.ts

Whitespace-only changes.

packages/types/src/logger.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export type LoggerFn = (
2+
data: unknown,
3+
msg?: string,
4+
...args: unknown[]
5+
) => unknown
6+
7+
export type Logger = {
8+
debug: LoggerFn
9+
info: LoggerFn
10+
warn: LoggerFn
11+
error: LoggerFn
12+
}

0 commit comments

Comments
 (0)