Skip to content

Address issues in core package #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions typescript-sdk/.husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

pnpm format
pnpm lint
1 change: 1 addition & 0 deletions typescript-sdk/commit_message.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Refactor: Update dependencies, improve scripts, and add pre-commit hooks
18 changes: 10 additions & 8 deletions typescript-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"author": "Markus Ecker <[email protected]>",
"private": true,
"scripts": {
"build": "turbo run build",
"prepare": "husky",
"build": "turbo run build",,
"build:clean": "pnpm -r clean && pnpm install && turbo run build",
"dev": "turbo run dev",
"lint": "turbo run lint",
Expand All @@ -12,17 +13,18 @@
"test": "turbo run test",
"bump": "pnpm --filter './packages/*' exec -- pnpm version",
"bump:alpha": "pnpm --filter './packages/*' exec -- pnpm version --preid alpha",
"publish": "pnpm -r clean && pnpm install && turbo run build && pnpm publish -r --filter='./packages/*'",
"publish:alpha": "pnpm -r clean && pnpm install && turbo run build && pnpm publish -r --no-git-checks --filter='./packages/*' --tag alpha"
"publish": "turbo run build && pnpm publish -r --filter='./packages/*'",
"publish:alpha": "turbo run build && pnpm publish -r --filter='./packages/*' --tag alpha"
},
"devDependencies": {
"prettier": "^3.5.3",
"turbo": "^2.4.4",
"typescript": "5.8.2"
"prettier": "^3.6.2",
"turbo": "^2.5.4",
"typescript": "^5.8.3",
"husky": "^9.1.7"
},
"packageManager": "[email protected]",
"engines": {
"node": ">=18"
"node": ">=20"
},
"version": "0.0.1"
}
} // Consider using a versioning strategy like semantic-release or changesets for monorepos.
38 changes: 5 additions & 33 deletions typescript-sdk/packages/core/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,18 @@ export const TextMessageEndEventSchema = BaseEventSchema.extend({

export const TextMessageChunkEventSchema = BaseEventSchema.extend({
type: z.literal(EventType.TEXT_MESSAGE_CHUNK),
messageId: z.string().optional(),
role: z.literal("assistant").optional(),
messageId: z.string(),
role: z.literal("assistant"),
delta: z.string().optional(),
});

export const ThinkingTextMessageStartEventSchema = BaseEventSchema.extend({
type: z.literal(EventType.THINKING_TEXT_MESSAGE_START),
});

export const ThinkingTextMessageContentEventSchema = TextMessageContentEventSchema.omit({
messageId: true,
type: true,
}).extend({
export const ThinkingTextMessageContentEventSchema = BaseEventSchema.extend({
type: z.literal(EventType.THINKING_TEXT_MESSAGE_CONTENT),
delta: z.string().refine((s) => s.length > 0, "Delta must not be an empty string"),
});

export const ThinkingTextMessageEndEventSchema = BaseEventSchema.extend({
Expand Down Expand Up @@ -151,7 +149,7 @@ export const StateSnapshotEventSchema = BaseEventSchema.extend({

export const StateDeltaEventSchema = BaseEventSchema.extend({
type: z.literal(EventType.STATE_DELTA),
delta: z.array(z.any()), // JSON Patch (RFC 6902)
delta: z.array(z.any()), // JSON Patch (RFC 6902) operations
});

export const MessagesSnapshotEventSchema = BaseEventSchema.extend({
Expand All @@ -171,33 +169,7 @@ export const CustomEventSchema = BaseEventSchema.extend({
value: z.any(),
});

export const RunStartedEventSchema = BaseEventSchema.extend({
type: z.literal(EventType.RUN_STARTED),
threadId: z.string(),
runId: z.string(),
});

export const RunFinishedEventSchema = BaseEventSchema.extend({
type: z.literal(EventType.RUN_FINISHED),
threadId: z.string(),
runId: z.string(),
});

export const RunErrorEventSchema = BaseEventSchema.extend({
type: z.literal(EventType.RUN_ERROR),
message: z.string(),
code: z.string().optional(),
});

export const StepStartedEventSchema = BaseEventSchema.extend({
type: z.literal(EventType.STEP_STARTED),
stepName: z.string(),
});

export const StepFinishedEventSchema = BaseEventSchema.extend({
type: z.literal(EventType.STEP_FINISHED),
stepName: z.string(),
});

export const EventSchemas = z.discriminatedUnion("type", [
TextMessageStartEventSchema,
Expand Down
18 changes: 10 additions & 8 deletions typescript-sdk/packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ export const UserMessageSchema = BaseMessageSchema.extend({
content: z.string(),
});

export const ToolMessageSchema = z.object({
id: z.string(),
content: z.string(),
export const ToolMessageSchema = BaseMessageSchema.extend({
role: z.literal("tool"),
toolCallId: z.string(),
});
Expand Down Expand Up @@ -70,20 +68,20 @@ export const ContextSchema = z.object({
export const ToolSchema = z.object({
name: z.string(),
description: z.string(),
parameters: z.any(), // JSON Schema for the tool parameters
parameters: z.any(), // Should be a JSON Schema object
});

export const RunAgentInputSchema = z.object({
threadId: z.string(),
runId: z.string(),
state: z.any(),
state: z.any(), // Arbitrary state object
messages: z.array(MessageSchema),
tools: z.array(ToolSchema),
context: z.array(ContextSchema),
forwardedProps: z.any(),
forwardedProps: z.any(), // Arbitrary object for forwarding additional properties
});

export const StateSchema = z.any();
export const StateSchema = z.any(); // Arbitrary state object

export type ToolCall = z.infer<typeof ToolCallSchema>;
export type FunctionCall = z.infer<typeof FunctionCallSchema>;
Expand All @@ -100,7 +98,11 @@ export type State = z.infer<typeof StateSchema>;
export type Role = z.infer<typeof RoleSchema>;

export class AGUIError extends Error {
constructor(message: string) {
code?: string;

constructor(message: string, code?: string) {
super(message);
this.name = "AGUIError";
this.code = code;
}
}