-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonit_agent.go
More file actions
109 lines (95 loc) · 4.15 KB
/
Copy pathmonit_agent.go
File metadata and controls
109 lines (95 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package flashduty
import (
"context"
"encoding/json"
"fmt"
)
// MonitAgentCatalogInput is the request payload for /monit/tools/catalog.
// TargetKind is optional — the agent infers it from TargetLocator when
// unambiguous (e.g. host:web-01 → host, mysql:prod-master → mysql).
type MonitAgentCatalogInput struct {
TargetLocator string
TargetKind string
}
// MonitAgentTool describes a single tool the runner exposes for a target.
// InputSchema is a JSON Schema fragment, intentionally kept as RawMessage so
// callers can pipe it straight to a tool-using LLM without re-marshalling.
type MonitAgentTool struct {
Name string `json:"name"`
Description string `json:"description"`
InputSchema json.RawMessage `json:"input_schema"`
}
// MonitAgentCatalogOutput is the decoded response from /monit/tools/catalog.
type MonitAgentCatalogOutput struct {
Tools []MonitAgentTool `json:"tools"`
}
// MonitAgentCatalog lists the tools the runner exposes for the given target.
func (c *Client) MonitAgentCatalog(ctx context.Context, input *MonitAgentCatalogInput) (*MonitAgentCatalogOutput, error) {
if input == nil {
return nil, fmt.Errorf("monit agent catalog: input is required")
}
requestBody := map[string]any{
"target_locator": input.TargetLocator,
}
if input.TargetKind != "" {
requestBody["target_kind"] = input.TargetKind
}
return postData[MonitAgentCatalogOutput](c, ctx, "/monit/tools/catalog", requestBody, "failed to list monit agent tool catalog")
}
// MonitAgentInvokeTool is a single entry in the /monit/tools/invoke `tools`
// array. Params is the tool-specific argument payload — left as RawMessage
// so callers can pass the JSON they already have without round-tripping
// through map[string]any.
type MonitAgentInvokeTool struct {
Tool string `json:"tool"`
Params json.RawMessage `json:"params,omitempty"`
}
// MonitAgentInvokeResult is one entry in the returned `results` array. The
// runner returns results in the request order, with the same length as the
// input `tools` array, even when some tools error — callers must inspect
// Error per result and not assume "no outer error" means all tools succeeded.
//
// Data carries the per-tool payload (typically {summary, data}) and is left
// as RawMessage so the agent doesn't have to model every tool's shape.
type MonitAgentInvokeResult struct {
Tool string `json:"tool"`
Data json.RawMessage `json:"data,omitempty"`
Error string `json:"error,omitempty"`
}
// MonitAgentInvokeInput is the request payload for /monit/tools/invoke.
// At most 8 tools may be invoked per call; the runner executes them
// concurrently and returns them in the same order.
type MonitAgentInvokeInput struct {
TargetLocator string
TargetKind string
Tools []MonitAgentInvokeTool
}
// MonitAgentInvokeOutput is the decoded response from /monit/tools/invoke.
//
// Three error layers exist and callers must distinguish them:
// 1. The error returned by this method — an HTTP-level failure
// (network error, 5xx, malformed JSON).
// 2. A request-level error wrapped in dataEnvelope.Error — surfaced as the
// method's returned error (target_unavailable, ambiguous_target_kind,
// unknown_toolset_hash, forward_failed). When this fires, Results is
// not populated.
// 3. Results[i].Error — a per-tool failure; other entries in Results may
// have succeeded and callers should consume them.
type MonitAgentInvokeOutput struct {
Results []MonitAgentInvokeResult `json:"results"`
}
// MonitAgentInvoke runs one or more tools against the given target. Tools
// execute concurrently on the runner; the response preserves request order.
func (c *Client) MonitAgentInvoke(ctx context.Context, input *MonitAgentInvokeInput) (*MonitAgentInvokeOutput, error) {
if input == nil {
return nil, fmt.Errorf("monit agent invoke: input is required")
}
requestBody := map[string]any{
"target_locator": input.TargetLocator,
"tools": input.Tools,
}
if input.TargetKind != "" {
requestBody["target_kind"] = input.TargetKind
}
return postData[MonitAgentInvokeOutput](c, ctx, "/monit/tools/invoke", requestBody, "failed to invoke monit agent tools")
}