Files
Agent-Native/runtime/session/intent.go
T
weichen 6ddd3da8df Enable canonical versioned Go module consumption
Why: Allow consumers to download an immutable module revision without nested source checkouts or local path replacements.

Evidence: SELF package tests and the prior canonical-path rejection are recorded in the Dev dependency-workspace task card; remote consumption is replayed against the committed candidate.

Impact: Change the module identity and its Go imports while preserving API behavior. Existing historical submodule revisions remain buildable.

Refs: Versioned dependencies U1/U3; feature/dependency-workspace
2026-10-13 15:36:10 +00:00

58 lines
1.5 KiB
Go

package session
import (
"encoding/json"
"git-ssh.u1680832.nyat.app/weichen/Agent-Native.git/runtime/llm"
)
// ToolIntent 是一次尚未配对结果的工具调用声明。
type ToolIntent struct {
CallID string `json:"callId"`
Name string `json:"name"`
Arguments string `json:"arguments,omitempty"`
Replay string `json:"replay"`
}
// AppendToolIntent 先落下「即将执行」。结果另写一条 tool 消息。
func (s *Store) AppendToolIntent(in ToolIntent) error {
raw, err := json.Marshal(in)
if err != nil {
return err
}
_, err = s.AppendEntry(Entry{Type: TypeToolIntent, Data: raw})
return err
}
// PendingIntents 返回活动分支上还没有对应 tool 结果的意图。
func (s *Store) PendingIntents() ([]ToolIntent, error) {
s.mu.Lock()
defer s.mu.Unlock()
entries, err := s.readEntriesLocked()
if err != nil {
return nil, err
}
answered := map[string]bool{}
var intents []ToolIntent
for _, e := range pathTo(entries, s.leafLocked(entries)) {
if e.Type == TypeMessage && e.Message != nil && e.Message.Role == llm.RoleTool && e.Message.ToolCallID != "" {
answered[e.Message.ToolCallID] = true
}
if e.Type != TypeToolIntent {
continue
}
var in ToolIntent
if err := json.Unmarshal(e.Data, &in); err != nil {
return nil, err
}
intents = append(intents, in)
}
var pending []ToolIntent
for _, in := range intents {
if !answered[in.CallID] {
pending = append(pending, in)
}
}
return pending, nil
}