2026-03-17 17:45:04 +00:00
|
|
|
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
|
|
feat(v0.8.0): full AX migration — ServiceRuntime, Actions, quality gates, transport
go-process:
- Register factory, Result lifecycle, 5 named Action handlers
- Start/Run/StartWithOptions/RunWithOptions all return core.Result
- core.ID() replaces fmt.Sprintf, core.As replaces errors.As
core/agent:
- PrepSubsystem + monitor.Subsystem + setup.Service embed ServiceRuntime[T]
- 22 named Actions + agent.completion Task pipeline in OnStartup
- ChannelNotifier removed — all IPC via c.ACTION(messages.X{})
- proc.go: all methods via s.Core().Process(), returns core.Result
- status.go: WriteAtomic + JSONMarshalString
- paths.go: Fs.NewUnrestricted() replaces unsafe.Pointer
- transport.go: ONE net/http file — HTTPGet/HTTPPost/HTTPDo/MCP transport
- All disallowed imports eliminated from source files (13 quality gates)
- String concat eliminated — core.Concat() throughout
- 1:1 _test.go + _example_test.go for every source file
- Reference docs synced from core/go v0.8.0
- RFC-025 updated with net/http, net/url, io/fs quality gates
- lib.go: io/fs eliminated via Data.ListNames, Array[T].Deduplicate
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-26 01:27:46 +00:00
|
|
|
package agentic
|
2026-04-02 06:23:07 +00:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
|
|
|
|
core "dappco.re/go/core"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// client := agentic.NewRemoteClient("charon")
|
|
|
|
|
// core.Println(client.URL) // "http://10.69.69.165:9101/mcp"
|
|
|
|
|
type RemoteClient struct {
|
|
|
|
|
Host string
|
|
|
|
|
Address string
|
|
|
|
|
Token string
|
|
|
|
|
URL string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// client := agentic.NewRemoteClient("charon")
|
|
|
|
|
func NewRemoteClient(host string) RemoteClient {
|
2026-04-02 09:12:49 +00:00
|
|
|
host = core.Trim(host)
|
2026-04-02 06:23:07 +00:00
|
|
|
address := resolveHost(host)
|
|
|
|
|
return RemoteClient{
|
|
|
|
|
Host: host,
|
|
|
|
|
Address: address,
|
|
|
|
|
Token: remoteToken(host),
|
|
|
|
|
URL: core.Sprintf("http://%s/mcp", address),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// sessionID, err := client.Initialize(context.Background())
|
|
|
|
|
func (c RemoteClient) Initialize(ctx context.Context) (string, error) {
|
|
|
|
|
result := mcpInitializeResult(ctx, c.URL, c.Token)
|
|
|
|
|
if !result.OK {
|
|
|
|
|
err, _ := result.Value.(error)
|
|
|
|
|
if err == nil {
|
|
|
|
|
err = core.E("remoteClient.Initialize", "MCP initialise failed", nil)
|
|
|
|
|
}
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
sessionID, ok := result.Value.(string)
|
|
|
|
|
if !ok || sessionID == "" {
|
|
|
|
|
return "", core.E("remoteClient.Initialize", "invalid session id", nil)
|
|
|
|
|
}
|
|
|
|
|
return sessionID, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// response, err := client.Call(context.Background(), "session-1", core.JSONMarshalString(map[string]any{"method":"tools/call"}))
|
|
|
|
|
func (c RemoteClient) Call(ctx context.Context, sessionID string, body []byte) ([]byte, error) {
|
|
|
|
|
result := mcpCallResult(ctx, c.URL, c.Token, sessionID, body)
|
|
|
|
|
if !result.OK {
|
|
|
|
|
err, _ := result.Value.(error)
|
|
|
|
|
if err == nil {
|
|
|
|
|
err = core.E("remoteClient.Call", "tool call failed", nil)
|
|
|
|
|
}
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
response, ok := result.Value.([]byte)
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil, core.E("remoteClient.Call", "invalid response payload", nil)
|
|
|
|
|
}
|
|
|
|
|
return response, nil
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-02 08:53:28 +00:00
|
|
|
// body := client.ToolCallBody(1, "agentic_dispatch", map[string]any{"repo": "go-io", "task": "Fix tests"})
|
2026-04-02 06:23:07 +00:00
|
|
|
func (c RemoteClient) ToolCallBody(id int, name string, arguments map[string]any) []byte {
|
|
|
|
|
request := map[string]any{
|
|
|
|
|
"jsonrpc": "2.0",
|
|
|
|
|
"id": id,
|
|
|
|
|
"method": "tools/call",
|
|
|
|
|
"params": map[string]any{
|
|
|
|
|
"name": name,
|
|
|
|
|
"arguments": arguments,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
return []byte(core.JSONMarshalString(request))
|
|
|
|
|
}
|