Explorer

definy.mcp-get-part

description
(en) The definy_get_part MCP tool
type
Fn(arguments: @definy.json, request: @http.request) -> @definy.service-io
expression
fn(arguments$0, request$1) =>
  let part$2 = match @definy.json-get-string(value: $0, key: "part") {
      #some(text$3) =>
        $3,
      #none(_) =>
        ""
    };
  let dot$4 = @std.string-index-of(text: $2, target: ".", startIndex: 0);
  match @core.less-than(left: $4, right: 1) {
    true =>
      @definy.mcp-text-error(text: "part must be in the form 'module.name', e.g. 'core.plus'"),
    false =>
      let branch$7 = match @definy.json-get-string(value: $0, key: "branch") {
          #some(text$8) =>
            $8,
          #none(_) =>
            "main"
        };
      @definy.read-snapshots-with(
        event_hashes: match @definy.json-get-string(value: $0, key: "snapshot") {
          #some(hash$30) =>
            [$30],
          #none(_) =>
            []
        },
        then: fn(commits$9) =>
          let candidates$10 = match @definy.json-get-string(value: $0, key: "snapshot") {
              #some(hash$17) =>
                match @definy.event-snapshot-find(commits: $9, event_hash: $17, index: 0) {
                  #some(found$18) =>
                    [$18],
                  #none(_) =>
                    []
                },
              #none(_) =>
                match @definy.json-get-string(value: $0, key: "project") {
                  #some(project$11) =>
                    match @definy.branch-snapshot-find(
                        commits: $9,
                        branches: @core.project-branches(
                          commits: @core.list-map(
                            T: @definy.event-snapshot,
                            U: @core.snapshot-summary,
                            f: fn(item$12) =>
                              @definy.snapshot-summary-of(commit: $12),
                            xs: $9
                          )
                        ),
                        project: $11,
                        branch: $7,
                        index: 0
                      ) {
                      #some(commit$13) =>
                        [$13],
                      #none(_) =>
                        []
                    },
                  #none(_) =>
                    @definy.latest-main-snapshots(commits: $9)
                }
            };
          match @definy.snapshot-part-find(commits: $10, name: $2, index: 0) {
            #none(_) =>
              @definy.mcp-text-error(text: @std.string-join(items: ["Part ", $2, " was not found"], separator: "")),
            #some(found$14) =>
              @definy.read-part-contents(
                parts: [$14.part],
                then: fn(parts$15) =>
                  match @core.list-get(list: $15, index: 0) {
                    #none(_) =>
                      @definy.mcp-text-error(text: "The part could not be read"),
                    #some(resolved$16) =>
                      @definy.mcp-text(
                        text: @definy.mcp-part-text(
                          part: $16,
                          commit: $14.commit,
                          names: @definy.snapshot-part-names(commits: @core.list-concat(left: [$14.commit], right: @definy.latest-main-snapshots(commits: $9)))
                        )
                      )
                  }
              )
          }
      )
  }
visibility
public
definy.mcp-get-part (project definy, branch main, snapshot l0VFjJZP174d8CbZWFoujAGTYjgsQu4uTq5uWCZaXgo)
id: 0DBDvlwhFU_rzdEUYbyRSHvnKqSA-IY7dOKHlEShDr8
content hash: AKvIOHb6b1tKnjY0J-05TcSR5AznKuJ5KW-UVo1NdUY