MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / create

Method create

crates/opencode-session/src/compaction.rs:671–711  ·  view source on GitHub ↗

Create a compaction user message and compaction part. Mirrors TS `SessionCompaction.create`. Creates a user message with the given agent/model, then attaches a compaction part with the `auto` flag.

(
        input: CreateCompactionInput,
        session_ops: &S,
    )

Source from the content-addressed store, hash-verified

669 /// Mirrors TS `SessionCompaction.create`. Creates a user message with the
670 /// given agent/model, then attaches a compaction part with the `auto` flag.
671 pub async fn create<S: SessionOps>(
672 input: CreateCompactionInput,
673 session_ops: &S,
674 ) -> anyhow::Result<(MessageInfo, Part)> {
675 let msg_id = opencode_core::id::create(opencode_core::id::Prefix::Message, false, None);
676 let now_ms = Utc::now().timestamp_millis();
677
678 // TS: const msg = await Session.updateMessage({ role: "user", ... })
679 let user_msg = MessageInfo::User {
680 id: msg_id.clone(),
681 session_id: input.session_id.clone(),
682 time: UserTime { created: now_ms },
683 agent: input.agent.clone(),
684 model: input.model.clone(),
685 format: None,
686 summary: None,
687 system: None,
688 tools: None,
689 variant: None,
690 };
691 let persisted_msg = session_ops.update_message(user_msg.clone()).await?;
692
693 let persisted_id = match &persisted_msg {
694 MessageInfo::User { id, .. } => id.clone(),
695 MessageInfo::Assistant { id, .. } => id.clone(),
696 };
697
698 // TS: await Session.updatePart({ type: "compaction", auto: input.auto, ... })
699 let part_id = opencode_core::id::create(opencode_core::id::Prefix::Part, false, None);
700 let compaction_part = Part::Compaction(crate::message_v2::CompactionPart {
701 id: part_id,
702 session_id: input.session_id.clone(),
703 message_id: persisted_id.clone(),
704 auto: input.auto,
705 });
706 session_ops
707 .update_part(&input.session_id, &persisted_id, compaction_part.clone())
708 .await?;
709
710 Ok((persisted_msg, compaction_part))
711 }
712
713 /// Prune tool results for a session using `SessionOps` for persistence.
714 ///

Callers

nothing calls this directly

Calls 4

createFunction · 0.85
cloneMethod · 0.45
update_messageMethod · 0.45
update_partMethod · 0.45

Tested by

no test coverage detected