Skip to content

Commit 2ffc369

Browse files
committed
revert import message from sdk
1 parent 6f34fbd commit 2ffc369

File tree

15 files changed

+436
-4
lines changed

15 files changed

+436
-4
lines changed

.agents/types/agent-definition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* export default definition
1515
*/
1616

17+
import type { Message } from './codebuff-message'
1718
import type * as Tools from './tools'
18-
import type { Message } from '@codebuff/sdk'
1919
type ToolName = Tools.ToolName
2020

2121
// ============================================================================

.agents/types/codebuff-message.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import z from 'zod/v4'
2+
3+
import {
4+
filePartSchema,
5+
imagePartSchema,
6+
reasoningPartSchema,
7+
textPartSchema,
8+
toolCallPartSchema,
9+
toolResultPartSchema,
10+
} from './content-part'
11+
import { providerMetadataSchema } from './provider-metadata'
12+
13+
const auxiliaryDataSchema = z.object({
14+
providerOptions: providerMetadataSchema.optional(),
15+
timeToLive: z
16+
.union([z.literal('agentStep'), z.literal('userPrompt')])
17+
.optional(),
18+
keepDuringTruncation: z.boolean().optional(),
19+
})
20+
21+
export const systemMessageSchema = z
22+
.object({
23+
role: z.literal('system'),
24+
content: z.string(),
25+
})
26+
.and(auxiliaryDataSchema)
27+
export type SystemMessage = z.infer<typeof systemMessageSchema>
28+
29+
export const userMessageSchema = z
30+
.object({
31+
role: z.literal('user'),
32+
content: z.union([
33+
z.string(),
34+
z.union([textPartSchema, imagePartSchema, filePartSchema]).array(),
35+
]),
36+
})
37+
.and(auxiliaryDataSchema)
38+
export type UserMessage = z.infer<typeof userMessageSchema>
39+
40+
export const assistantMessageSchema = z
41+
.object({
42+
role: z.literal('assistant'),
43+
content: z.union([
44+
z.string(),
45+
z
46+
.union([textPartSchema, reasoningPartSchema, toolCallPartSchema])
47+
.array(),
48+
]),
49+
})
50+
.and(auxiliaryDataSchema)
51+
export type AssistantMessage = z.infer<typeof assistantMessageSchema>
52+
53+
export const toolMessageSchema = z
54+
.object({
55+
role: z.literal('tool'),
56+
content: toolResultPartSchema,
57+
})
58+
.and(auxiliaryDataSchema)
59+
export type ToolMessage = z.infer<typeof toolMessageSchema>
60+
61+
export const messageSchema = z
62+
.union([
63+
systemMessageSchema,
64+
userMessageSchema,
65+
assistantMessageSchema,
66+
toolMessageSchema,
67+
])
68+
.and(
69+
z.object({
70+
providerOptions: providerMetadataSchema.optional(),
71+
timeToLive: z
72+
.union([z.literal('agentStep'), z.literal('userPrompt')])
73+
.optional(),
74+
keepDuringTruncation: z.boolean().optional(),
75+
}),
76+
)
77+
export type Message = z.infer<typeof messageSchema>

.agents/types/content-part.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import z from 'zod/v4'
2+
3+
import { dataContentSchema } from './data-content'
4+
import { jsonValueSchema } from './json'
5+
import { providerMetadataSchema } from './provider-metadata'
6+
7+
export const textPartSchema = z.object({
8+
type: z.literal('text'),
9+
text: z.string(),
10+
providerOptions: providerMetadataSchema.optional(),
11+
})
12+
export type TextPart = z.infer<typeof textPartSchema>
13+
14+
export const imagePartSchema = z.object({
15+
type: z.literal('image'),
16+
image: z.union([dataContentSchema, z.instanceof(URL)]),
17+
mediaType: z.string().optional(),
18+
providerOptions: providerMetadataSchema.optional(),
19+
})
20+
export type ImagePart = z.infer<typeof imagePartSchema>
21+
22+
export const filePartSchema = z.object({
23+
type: z.literal('file'),
24+
data: z.union([dataContentSchema, z.instanceof(URL)]),
25+
filename: z.string().optional(),
26+
mediaType: z.string(),
27+
providerOptions: providerMetadataSchema.optional(),
28+
})
29+
export type FilePart = z.infer<typeof filePartSchema>
30+
31+
export const reasoningPartSchema = z.object({
32+
type: z.literal('reasoning'),
33+
text: z.string(),
34+
providerOptions: providerMetadataSchema.optional(),
35+
})
36+
export type ReasoningPart = z.infer<typeof reasoningPartSchema>
37+
38+
export const toolCallPartSchema = z.object({
39+
type: z.literal('tool-call'),
40+
toolCallId: z.string(),
41+
toolName: z.string(),
42+
input: z.record(z.string(), z.unknown()),
43+
providerOptions: providerMetadataSchema.optional(),
44+
providerExecuted: z.boolean().optional(),
45+
})
46+
export type ToolCallPart = z.infer<typeof toolCallPartSchema>
47+
48+
export const toolResultOutputSchema = z.discriminatedUnion('type', [
49+
z.object({
50+
type: z.literal('json'),
51+
value: jsonValueSchema,
52+
}),
53+
z.object({
54+
type: z.literal('media'),
55+
data: z.string(),
56+
mediaType: z.string(),
57+
}),
58+
])
59+
export type ToolResultOutput = z.infer<typeof toolResultOutputSchema>
60+
61+
export const toolResultPartSchema = z.object({
62+
type: z.literal('tool-result'),
63+
toolCallId: z.string(),
64+
toolName: z.string(),
65+
output: toolResultOutputSchema.array(),
66+
providerOptions: providerMetadataSchema.optional(),
67+
})
68+
export type ToolResultPart = z.infer<typeof toolResultPartSchema>

.agents/types/data-content.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import z from 'zod/v4'
2+
3+
export const dataContentSchema = z.union([
4+
z.string(),
5+
z.instanceof(Uint8Array),
6+
z.instanceof(ArrayBuffer),
7+
z.custom<Buffer>(
8+
// Buffer might not be available in some environments such as CloudFlare:
9+
(value: unknown): value is Buffer =>
10+
globalThis.Buffer?.isBuffer(value) ?? false,
11+
{ message: 'Must be a Buffer' },
12+
),
13+
])
14+
export type DataContent = z.infer<typeof dataContentSchema>

.agents/types/json.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import z from 'zod/v4'
2+
3+
export type JSONValue =
4+
| null
5+
| string
6+
| number
7+
| boolean
8+
| JSONObject
9+
| JSONArray
10+
export const jsonValueSchema: z.ZodType<JSONValue> = z.lazy(() =>
11+
z.union([
12+
z.null(),
13+
z.string(),
14+
z.number(),
15+
z.boolean(),
16+
jsonObjectSchema,
17+
jsonArraySchema,
18+
]),
19+
)
20+
21+
export const jsonObjectSchema: z.ZodType<JSONObject> = z.lazy(() =>
22+
z.record(z.string(), jsonValueSchema),
23+
)
24+
export type JSONObject = { [key: string]: JSONValue }
25+
26+
export const jsonArraySchema: z.ZodType<JSONArray> = z.lazy(() =>
27+
z.array(jsonValueSchema),
28+
)
29+
export type JSONArray = JSONValue[]

.agents/types/provider-metadata.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import z from 'zod/v4'
2+
3+
import { jsonValueSchema } from './json'
4+
5+
export const providerMetadataSchema = z.record(
6+
z.string(),
7+
z.record(z.string(), jsonValueSchema),
8+
)
9+
10+
export type ProviderMetadata = z.infer<typeof providerMetadataSchema>

.agents/types/tools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Message } from '@codebuff/sdk'
1+
import type { Message } from './codebuff-message'
22

33
/**
44
* Union type of all available tool names

common/src/templates/initial-agents-dir/types/agent-definition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* export default definition
1515
*/
1616

17+
import type { Message } from './codebuff-message'
1718
import type * as Tools from './tools'
18-
import type { Message } from '@codebuff/sdk'
1919
type ToolName = Tools.ToolName
2020

2121
// ============================================================================
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import z from 'zod/v4'
2+
3+
import {
4+
filePartSchema,
5+
imagePartSchema,
6+
reasoningPartSchema,
7+
textPartSchema,
8+
toolCallPartSchema,
9+
toolResultPartSchema,
10+
} from './content-part'
11+
import { providerMetadataSchema } from './provider-metadata'
12+
13+
const auxiliaryDataSchema = z.object({
14+
providerOptions: providerMetadataSchema.optional(),
15+
timeToLive: z
16+
.union([z.literal('agentStep'), z.literal('userPrompt')])
17+
.optional(),
18+
keepDuringTruncation: z.boolean().optional(),
19+
})
20+
21+
export const systemMessageSchema = z
22+
.object({
23+
role: z.literal('system'),
24+
content: z.string(),
25+
})
26+
.and(auxiliaryDataSchema)
27+
export type SystemMessage = z.infer<typeof systemMessageSchema>
28+
29+
export const userMessageSchema = z
30+
.object({
31+
role: z.literal('user'),
32+
content: z.union([
33+
z.string(),
34+
z.union([textPartSchema, imagePartSchema, filePartSchema]).array(),
35+
]),
36+
})
37+
.and(auxiliaryDataSchema)
38+
export type UserMessage = z.infer<typeof userMessageSchema>
39+
40+
export const assistantMessageSchema = z
41+
.object({
42+
role: z.literal('assistant'),
43+
content: z.union([
44+
z.string(),
45+
z
46+
.union([textPartSchema, reasoningPartSchema, toolCallPartSchema])
47+
.array(),
48+
]),
49+
})
50+
.and(auxiliaryDataSchema)
51+
export type AssistantMessage = z.infer<typeof assistantMessageSchema>
52+
53+
export const toolMessageSchema = z
54+
.object({
55+
role: z.literal('tool'),
56+
content: toolResultPartSchema,
57+
})
58+
.and(auxiliaryDataSchema)
59+
export type ToolMessage = z.infer<typeof toolMessageSchema>
60+
61+
export const messageSchema = z
62+
.union([
63+
systemMessageSchema,
64+
userMessageSchema,
65+
assistantMessageSchema,
66+
toolMessageSchema,
67+
])
68+
.and(
69+
z.object({
70+
providerOptions: providerMetadataSchema.optional(),
71+
timeToLive: z
72+
.union([z.literal('agentStep'), z.literal('userPrompt')])
73+
.optional(),
74+
keepDuringTruncation: z.boolean().optional(),
75+
}),
76+
)
77+
export type Message = z.infer<typeof messageSchema>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import z from 'zod/v4'
2+
3+
import { dataContentSchema } from './data-content'
4+
import { jsonValueSchema } from './json'
5+
import { providerMetadataSchema } from './provider-metadata'
6+
7+
export const textPartSchema = z.object({
8+
type: z.literal('text'),
9+
text: z.string(),
10+
providerOptions: providerMetadataSchema.optional(),
11+
})
12+
export type TextPart = z.infer<typeof textPartSchema>
13+
14+
export const imagePartSchema = z.object({
15+
type: z.literal('image'),
16+
image: z.union([dataContentSchema, z.instanceof(URL)]),
17+
mediaType: z.string().optional(),
18+
providerOptions: providerMetadataSchema.optional(),
19+
})
20+
export type ImagePart = z.infer<typeof imagePartSchema>
21+
22+
export const filePartSchema = z.object({
23+
type: z.literal('file'),
24+
data: z.union([dataContentSchema, z.instanceof(URL)]),
25+
filename: z.string().optional(),
26+
mediaType: z.string(),
27+
providerOptions: providerMetadataSchema.optional(),
28+
})
29+
export type FilePart = z.infer<typeof filePartSchema>
30+
31+
export const reasoningPartSchema = z.object({
32+
type: z.literal('reasoning'),
33+
text: z.string(),
34+
providerOptions: providerMetadataSchema.optional(),
35+
})
36+
export type ReasoningPart = z.infer<typeof reasoningPartSchema>
37+
38+
export const toolCallPartSchema = z.object({
39+
type: z.literal('tool-call'),
40+
toolCallId: z.string(),
41+
toolName: z.string(),
42+
input: z.record(z.string(), z.unknown()),
43+
providerOptions: providerMetadataSchema.optional(),
44+
providerExecuted: z.boolean().optional(),
45+
})
46+
export type ToolCallPart = z.infer<typeof toolCallPartSchema>
47+
48+
export const toolResultOutputSchema = z.discriminatedUnion('type', [
49+
z.object({
50+
type: z.literal('json'),
51+
value: jsonValueSchema,
52+
}),
53+
z.object({
54+
type: z.literal('media'),
55+
data: z.string(),
56+
mediaType: z.string(),
57+
}),
58+
])
59+
export type ToolResultOutput = z.infer<typeof toolResultOutputSchema>
60+
61+
export const toolResultPartSchema = z.object({
62+
type: z.literal('tool-result'),
63+
toolCallId: z.string(),
64+
toolName: z.string(),
65+
output: toolResultOutputSchema.array(),
66+
providerOptions: providerMetadataSchema.optional(),
67+
})
68+
export type ToolResultPart = z.infer<typeof toolResultPartSchema>

0 commit comments

Comments
 (0)