Skip to content

Commit 9c19a53

Browse files
committed
refactor(event): remove ModelLoaded and ToolAdded
1 parent 194e8b8 commit 9c19a53

File tree

11 files changed

+22
-308
lines changed

11 files changed

+22
-308
lines changed

agent/agent.mbt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,6 @@ pub async fn new(
366366
event_target.add_listener(event => logger.info("Received event", data={
367367
"event": event.to_json(),
368368
}))
369-
event_target.emit(ModelLoaded(name=model.name, model~))
370369
let history = session_manager.new_conversation(name="history")
371370
let external_events = match external_events {
372371
Some(queue) => queue
@@ -429,7 +428,6 @@ pub async fn load(
429428
json.remove("msg")
430429
logger.info(msg, data=json)
431430
})
432-
event_target.emit(ModelLoaded(name=model.name, model~))
433431
let external_events = match external_events {
434432
Some(queue) => queue
435433
None => @event.ExternalEventQueue::new()

agent/agent_tool.mbt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ fn Agent::add_agent_tool(
146146
) -> Unit {
147147
let desc = tool.desc()
148148
agent.tools[desc.name] = Tool::new(tool, enabled~)
149-
agent.emit(ToolAdded(desc))
150149
}
151150

152151
///|

cmd/jsonl2md/formatter.mbt

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -436,18 +436,6 @@ fn Formatter::format_post_tool_call(
436436
self.lines.push("")
437437
}
438438

439-
///|
440-
fn Formatter::format_model_loaded(
441-
self : Formatter,
442-
name : String,
443-
timestamp? : Int64,
444-
) -> Unit raise {
445-
self.push_title("System information", timestamp?)
446-
self.lines.push("")
447-
self.lines.push("Model: \{name}")
448-
self.lines.push("")
449-
}
450-
451439
///|
452440
/// Formats a log entry from JSON.
453441
async fn Formatter::format_log_entry(self : Formatter, json : Json) -> Unit {
@@ -553,7 +541,6 @@ async fn Formatter::format_log_entry(self : Formatter, json : Json) -> Unit {
553541
PostToolCall(tool_call, result~, rendered=text) =>
554542
self.format_post_tool_call(tool_call.name, result~, text, timestamp?)
555543
UserMessage(content) => self.format_user_message(content, timestamp?)
556-
ModelLoaded(name~, ..) => self.format_model_loaded(name, timestamp?)
557544
_ => ()
558545
}
559546
}

cmd/jsonl2md/formatter_wbtest.mbt

Lines changed: 21 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,39 +1328,6 @@ test "recover_diagnostics" {
13281328
)
13291329
}
13301330

1331-
///|
1332-
async test "ModelLoaded" (t : @test.Test) {
1333-
@mock.run(t, _ => {
1334-
let event_target = @event.EventTarget::new()
1335-
event_target.emit(
1336-
ModelLoaded(
1337-
name="qwen/qwen3-coder-plus",
1338-
model=@model.Model::new(
1339-
name="qwen/qwen3-coder-plus",
1340-
description="Qwen coder",
1341-
model_name="qwen/qwen3-coder-plus",
1342-
model_type=SaaS(OpenAI),
1343-
api_key="sk-test",
1344-
base_url="https://openrouter.ai/api/v1",
1345-
safe_zone_tokens=256000,
1346-
supports_anthropic_prompt_caching=false,
1347-
),
1348-
),
1349-
)
1350-
inspect(
1351-
format_event_target(event_target),
1352-
content=(
1353-
#|# System information
1354-
#|
1355-
#|00:00:00
1356-
#|
1357-
#|Model: qwen/qwen3-coder-plus
1358-
#|
1359-
),
1360-
)
1361-
})
1362-
}
1363-
13641331
///|
13651332
async test "subagent" (t : @test.Test) {
13661333
@mock.run(t, mock => {
@@ -1558,18 +1525,8 @@ async test "timestamp" (t : @test.Test) {
15581525
@mock.run(t, _ => {
15591526
let event_target = @event.EventTarget::new()
15601527
event_target.emit(
1561-
ModelLoaded(
1562-
name="qwen/qwen3-coder-plus",
1563-
model=@model.Model::new(
1564-
name="qwen/qwen3-coder-plus",
1565-
description="Qwen coder",
1566-
model_name="qwen/qwen3-coder-plus",
1567-
model_type=SaaS(OpenAI),
1568-
api_key="sk-test",
1569-
base_url="https://openrouter.ai/api/v1",
1570-
safe_zone_tokens=256000,
1571-
supports_anthropic_prompt_caching=false,
1572-
),
1528+
UserMessage(
1529+
"Write the file `toml_parser/src/moon.pkg.json` with the content:\n\n```json\n{\n \"name\": \"toml_parser\",\n \"version\": \"1.0.0\",\n \"description\": \"A MoonBit package for parsing TOML files.\",\n \"main\": \"src/main.mbt\",\n \"scripts\": {\n \"build\": \"moon build\",\n \"test\": \"moon test\"\n },\n \"dependencies\": {\n \"moonbit/core\": \"^1.0.0\"\n }\n}\n```",
15731530
),
15741531
)
15751532
event_target.emit(
@@ -1589,13 +1546,29 @@ async test "timestamp" (t : @test.Test) {
15891546
inspect(
15901547
format_event_target(event_target),
15911548
content=(
1592-
#|# System information
1549+
#|# 1 User: Write the file `toml_parser/src/moon.pkg.json` with the content:
15931550
#|
15941551
#|00:00:00
15951552
#|
1596-
#|Model: qwen/qwen3-coder-plus
1553+
#|Write the file `toml_parser/src/moon.pkg.json` with the content:
1554+
#|
1555+
#|```json
1556+
#|{
1557+
#| "name": "toml_parser",
1558+
#| "version": "1.0.0",
1559+
#| "description": "A MoonBit package for parsing TOML files.",
1560+
#| "main": "src/main.mbt",
1561+
#| "scripts": {
1562+
#| "build": "moon build",
1563+
#| "test": "moon test"
1564+
#| },
1565+
#| "dependencies": {
1566+
#| "moonbit/core": "^1.0.0"
1567+
#| }
1568+
#|}
1569+
#|```
15971570
#|
1598-
#|# 1 Tool call result: <meta_write_to_file path="toml_parser/src/moon.pkg.json">
1571+
#|# 2 Tool call result: <meta_write_to_file path="toml_parser/src/moon.pkg.json">
15991572
#|
16001573
#|00:00:00
16011574
#|

cmd/jsonl2md/moon.pkg.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"overrides": ["moonbitlang/maria/internal/abort"],
1616
"wbtest-import": [
1717
"moonbitlang/maria/internal/mock",
18-
"moonbitlang/maria/internal/pino",
19-
"moonbitlang/maria/model"
18+
"moonbitlang/maria/internal/pino"
2019
]
2120
}

event/event.mbt

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ pub(all) struct Event {
3434
3535
///|
3636
pub(all) enum EventDesc {
37-
/// Event triggered when a model is loaded.
38-
ModelLoaded(name~ : String, model~ : @model.Model)
3937
/// Event triggered before a conversation starts.
4038
PreConversation
4139
/// Event triggered after a conversation ends.
@@ -48,9 +46,6 @@ pub(all) enum EventDesc {
4846
/// The message ID can be obtained via the return value of `queue_message`
4947
/// function.
5048
MessageQueued(id~ : @uuid.Uuid)
51-
/// Event triggered when a tool is added to the agent. This message will only
52-
/// be triggered once per agent instance.
53-
ToolAdded(@tool.ToolDesc)
5449
/// Event triggered before a tool is called.
5550
PreToolCall(@ai.ToolCall)
5651
/// Event triggered after a tool call is completed.
@@ -95,20 +90,6 @@ pub(all) enum EventDesc {
9590
///|
9691
pub impl ToJson for EventDesc with to_json(self : EventDesc) -> Json {
9792
match self {
98-
ModelLoaded(name~, model~) =>
99-
{
100-
"msg": "ModelLoaded",
101-
"name": name.to_json(),
102-
"model": {
103-
let json = model.to_json()
104-
if json is Object(obj) {
105-
obj["api_key"] = "****"
106-
Json::object(obj)
107-
} else {
108-
json
109-
}
110-
},
111-
}
11293
TokenCounted(token_count) =>
11394
{ "msg": "TokenCounted", "token_count": token_count }
11495
ContextPruned(origin_token_count~, pruned_token_count~) =>
@@ -174,15 +155,6 @@ pub impl ToJson for EventDesc with to_json(self : EventDesc) -> Json {
174155
MessageQueued(id~) => { "msg": "MessageQueued", "message": { "id": id } }
175156
MessageUnqueued(id~) =>
176157
{ "msg": "MessageUnqueued", "message": { "id": id } }
177-
ToolAdded(tool_desc) =>
178-
{
179-
"msg": "ToolAdded",
180-
"tool": {
181-
"name": tool_desc.name,
182-
"description": tool_desc.description,
183-
"schema": tool_desc.schema,
184-
},
185-
}
186158
AssistantMessage(usage~, tool_calls~, content) => {
187159
let json : Map[String, Json] = {
188160
"msg": "AssistantMessage",
@@ -213,27 +185,6 @@ pub impl @json.FromJson for EventDesc with from_json(
213185
)
214186
}
215187
match msg {
216-
"ModelLoaded" => {
217-
guard json_object.get("name") is Some(name_json) else {
218-
raise @json.JsonDecodeError(
219-
(json_path, "ModelLoaded event missing 'name' field"),
220-
)
221-
}
222-
let name : String = @json.from_json(
223-
name_json,
224-
path=json_path.add_key("name"),
225-
)
226-
guard json_object.get("model") is Some(model_json) else {
227-
raise @json.JsonDecodeError(
228-
(json_path, "ModelLoaded event missing 'model' field"),
229-
)
230-
}
231-
let model : @model.Model = @json.from_json(
232-
model_json,
233-
path=json_path.add_key("model"),
234-
)
235-
ModelLoaded(name~, model~)
236-
}
237188
"TokenCounted" => {
238189
guard json_object.get("token_count") is Some(token_count_json) else {
239190
raise @json.JsonDecodeError(
@@ -365,36 +316,6 @@ pub impl @json.FromJson for EventDesc with from_json(
365316
)
366317
MessageUnqueued(id~)
367318
}
368-
"ToolAdded" => {
369-
guard json_object.get("tool") is Some(tool_json) else {
370-
raise @json.JsonDecodeError(
371-
(json_path, "ToolAdded event missing 'tool' field"),
372-
)
373-
}
374-
guard tool_json
375-
is Object(
376-
{
377-
"name": name_json,
378-
"description": description_json,
379-
"schema": schema_json,
380-
..
381-
}
382-
) else {
383-
raise @json.JsonDecodeError(
384-
(json_path, "Invalid 'tool' field in ToolAdded event"),
385-
)
386-
}
387-
let name : String = @json.from_json(
388-
name_json,
389-
path=json_path.add_key("tool").add_key("name"),
390-
)
391-
let description : String = @json.from_json(
392-
description_json,
393-
path=json_path.add_key("tool").add_key("description"),
394-
)
395-
let schema : Json = schema_json
396-
ToolAdded(@tool.tool_desc(description~, name~, schema~))
397-
}
398319
"AssistantMessage" => {
399320
let usage : @ai.Usage? = match json_object.get("usage") {
400321
None | Some(Null) => None

0 commit comments

Comments
 (0)