fn(arguments$0, request$1) =>
let project$2 = match @definy.json-get-string(value: $0, key: "project") {
#some(text$3) =>
$3,
#none(_) =>
""
};
let message$4 = match @definy.json-get-string(value: $0, key: "message") {
#some(text$5) =>
$5,
#none(_) =>
@core.string-concat(left: "Create project ", right: $2)
};
match @core.equal(left: $2, right: "") {
true =>
@definy.mcp-text-error(text: "project is required"),
false =>
@definy.mcp-with-account(
then: fn(account$6) =>
@definy.read-branch-snapshot(
project: $2,
branch: "main",
then: fn(commit$7, commits$8) =>
match $7 {
#some(_) =>
@definy.mcp-text-error(text: @std.string-join(items: ["Project ", $2, " already exists"], separator: "")),
#none(_) =>
@definy.mcp-submit-content(
account: $6,
after_time_ms: 0,
content: #project_commit<@core.event-content>({
project_name: $2,
branch: "main",
project_description: match @definy.json-get-string(value: $0, key: "description") {
#some(text$9) =>
[{language: "en", text: $9}],
#none(_) =>
[]
},
message: $4,
parent_commit_hash: #none,
merged_commit_hash: #none,
modules: []
}),
then: fn(accepted$10, text$11) =>
match $10 {
true =>
@definy.mcp-text(
text: @std.string-join(
items: [
"Created project ",
$2,
" with an empty main branch (owned by account ",
$6.account_id,
"). Add modules and parts with definy_create_snapshot (branch: main)\n",
$11
],
separator: ""
)
),
false =>
@definy.mcp-text-error(text: $11)
}
)
}
)
)
}