sarvam-agents-client 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +136 -23
- package/dist/apis/AgentConversationsApi.d.ts +8 -2
- package/dist/apis/AgentConversationsApi.js +8 -2
- package/dist/apis/AgentsApi.d.ts +6 -6
- package/dist/apis/AgentsApi.js +6 -6
- package/dist/apis/ConversationsApi.d.ts +6 -2
- package/dist/apis/ConversationsApi.js +10 -2
- package/dist/apis/MessagesApi.d.ts +1 -0
- package/dist/apis/MessagesApi.js +3 -0
- package/dist/apis/TriggersApi.d.ts +154 -0
- package/dist/apis/TriggersApi.js +376 -0
- package/dist/apis/index.d.ts +1 -0
- package/dist/apis/index.js +1 -0
- package/dist/client.d.ts +21 -0
- package/dist/client.js +24 -0
- package/dist/compose/agent.d.ts +4 -0
- package/dist/compose/agent.js +9 -0
- package/dist/compose/deploy.d.ts +8 -0
- package/dist/compose/deploy.js +32 -6
- package/dist/compose/index.d.ts +5 -1
- package/dist/compose/index.js +12 -1
- package/dist/compose/settingsTransport.d.ts +22 -3
- package/dist/compose/settingsTransport.js +180 -15
- package/dist/compose/transport.d.ts +19 -3
- package/dist/compose/trigger.d.ts +166 -0
- package/dist/compose/trigger.js +525 -0
- package/dist/compose/triggers.d.ts +96 -0
- package/dist/compose/triggers.js +319 -0
- package/dist/compose/webhook.d.ts +18 -3
- package/dist/compose/webhook.js +59 -10
- package/dist/compose/webhookSecrets.d.ts +64 -0
- package/dist/compose/webhookSecrets.js +255 -0
- package/dist/esm/apis/AgentConversationsApi.d.ts +8 -2
- package/dist/esm/apis/AgentConversationsApi.js +8 -2
- package/dist/esm/apis/AgentsApi.d.ts +6 -6
- package/dist/esm/apis/AgentsApi.js +6 -6
- package/dist/esm/apis/ConversationsApi.d.ts +6 -2
- package/dist/esm/apis/ConversationsApi.js +10 -2
- package/dist/esm/apis/MessagesApi.d.ts +1 -0
- package/dist/esm/apis/MessagesApi.js +3 -0
- package/dist/esm/apis/TriggersApi.d.ts +154 -0
- package/dist/esm/apis/TriggersApi.js +372 -0
- package/dist/esm/apis/index.d.ts +1 -0
- package/dist/esm/apis/index.js +1 -0
- package/dist/esm/client.d.ts +21 -0
- package/dist/esm/client.js +20 -0
- package/dist/esm/compose/agent.d.ts +4 -0
- package/dist/esm/compose/agent.js +9 -0
- package/dist/esm/compose/deploy.d.ts +8 -0
- package/dist/esm/compose/deploy.js +32 -6
- package/dist/esm/compose/index.d.ts +5 -1
- package/dist/esm/compose/index.js +2 -0
- package/dist/esm/compose/settingsTransport.d.ts +22 -3
- package/dist/esm/compose/settingsTransport.js +179 -15
- package/dist/esm/compose/transport.d.ts +19 -3
- package/dist/esm/compose/trigger.d.ts +166 -0
- package/dist/esm/compose/trigger.js +514 -0
- package/dist/esm/compose/triggers.d.ts +96 -0
- package/dist/esm/compose/triggers.js +315 -0
- package/dist/esm/compose/webhook.d.ts +18 -3
- package/dist/esm/compose/webhook.js +55 -9
- package/dist/esm/compose/webhookSecrets.d.ts +64 -0
- package/dist/esm/compose/webhookSecrets.js +250 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/models/AgentResource.d.ts +7 -0
- package/dist/esm/models/AgentResource.js +3 -0
- package/dist/esm/models/FireResponse.d.ts +63 -0
- package/dist/esm/models/FireResponse.js +63 -0
- package/dist/esm/models/MessagePart.d.ts +8 -0
- package/dist/esm/models/MessagePart.js +2 -0
- package/dist/esm/models/ResponseRotateTriggerSecret.d.ts +50 -0
- package/dist/esm/models/ResponseRotateTriggerSecret.js +54 -0
- package/dist/esm/models/RotatedSecret.d.ts +44 -0
- package/dist/esm/models/RotatedSecret.js +50 -0
- package/dist/esm/models/RotatedSigningSecret.d.ts +40 -0
- package/dist/esm/models/RotatedSigningSecret.js +46 -0
- package/dist/esm/models/TriggerDryRun.d.ts +44 -0
- package/dist/esm/models/TriggerDryRun.js +47 -0
- package/dist/esm/models/TriggerEventList.d.ts +39 -0
- package/dist/esm/models/TriggerEventList.js +46 -0
- package/dist/esm/models/TriggerEventView.d.ts +117 -0
- package/dist/esm/models/TriggerEventView.js +89 -0
- package/dist/esm/models/TriggerList.d.ts +33 -0
- package/dist/esm/models/TriggerList.js +44 -0
- package/dist/esm/models/TriggerSecretPut.d.ts +38 -0
- package/dist/esm/models/TriggerSecretPut.js +45 -0
- package/dist/esm/models/TriggerSecretState.d.ts +52 -0
- package/dist/esm/models/TriggerSecretState.js +56 -0
- package/dist/esm/models/TriggerTestFireRequest.d.ts +38 -0
- package/dist/esm/models/TriggerTestFireRequest.js +43 -0
- package/dist/esm/models/TriggerToken.d.ts +50 -0
- package/dist/esm/models/TriggerToken.js +56 -0
- package/dist/esm/models/TriggerView.d.ts +105 -0
- package/dist/esm/models/TriggerView.js +92 -0
- package/dist/esm/models/index.d.ts +13 -0
- package/dist/esm/models/index.js +13 -0
- package/dist/esm/runtime.d.ts +5 -0
- package/dist/esm/runtime.js +11 -0
- package/dist/esm/webhooks.d.ts +5 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +14 -0
- package/dist/models/AgentResource.d.ts +7 -0
- package/dist/models/AgentResource.js +3 -0
- package/dist/models/FireResponse.d.ts +63 -0
- package/dist/models/FireResponse.js +71 -0
- package/dist/models/MessagePart.d.ts +8 -0
- package/dist/models/MessagePart.js +2 -0
- package/dist/models/ResponseRotateTriggerSecret.d.ts +50 -0
- package/dist/models/ResponseRotateTriggerSecret.js +61 -0
- package/dist/models/RotatedSecret.d.ts +44 -0
- package/dist/models/RotatedSecret.js +57 -0
- package/dist/models/RotatedSigningSecret.d.ts +40 -0
- package/dist/models/RotatedSigningSecret.js +53 -0
- package/dist/models/TriggerDryRun.d.ts +44 -0
- package/dist/models/TriggerDryRun.js +54 -0
- package/dist/models/TriggerEventList.d.ts +39 -0
- package/dist/models/TriggerEventList.js +53 -0
- package/dist/models/TriggerEventView.d.ts +117 -0
- package/dist/models/TriggerEventView.js +97 -0
- package/dist/models/TriggerList.d.ts +33 -0
- package/dist/models/TriggerList.js +51 -0
- package/dist/models/TriggerSecretPut.d.ts +38 -0
- package/dist/models/TriggerSecretPut.js +52 -0
- package/dist/models/TriggerSecretState.d.ts +52 -0
- package/dist/models/TriggerSecretState.js +64 -0
- package/dist/models/TriggerTestFireRequest.d.ts +38 -0
- package/dist/models/TriggerTestFireRequest.js +50 -0
- package/dist/models/TriggerToken.d.ts +50 -0
- package/dist/models/TriggerToken.js +63 -0
- package/dist/models/TriggerView.d.ts +105 -0
- package/dist/models/TriggerView.js +100 -0
- package/dist/models/index.d.ts +13 -0
- package/dist/models/index.js +13 -0
- package/dist/runtime.d.ts +5 -0
- package/dist/runtime.js +12 -0
- package/dist/webhooks.d.ts +5 -1
- package/package.json +1 -1
- package/src/apis/AgentConversationsApi.ts +8 -2
- package/src/apis/AgentsApi.ts +6 -6
- package/src/apis/ConversationsApi.ts +14 -2
- package/src/apis/MessagesApi.ts +5 -0
- package/src/apis/TriggersApi.ts +584 -0
- package/src/apis/index.ts +1 -0
- package/src/client.ts +27 -0
- package/src/compose/agent.ts +11 -0
- package/src/compose/deploy.ts +42 -7
- package/src/compose/index.ts +8 -1
- package/src/compose/settingsTransport.ts +183 -18
- package/src/compose/transport.ts +20 -3
- package/src/compose/trigger.ts +635 -0
- package/src/compose/triggers.ts +337 -0
- package/src/compose/webhook.ts +64 -11
- package/src/compose/webhookSecrets.ts +257 -0
- package/src/index.ts +9 -0
- package/src/models/AgentResource.ts +15 -0
- package/src/models/FireResponse.ts +107 -0
- package/src/models/MessagePart.ts +8 -0
- package/src/models/ResponseRotateTriggerSecret.ts +107 -0
- package/src/models/RotatedSecret.ts +83 -0
- package/src/models/RotatedSigningSecret.ts +76 -0
- package/src/models/TriggerDryRun.ts +82 -0
- package/src/models/TriggerEventList.ts +82 -0
- package/src/models/TriggerEventView.ts +183 -0
- package/src/models/TriggerList.ts +74 -0
- package/src/models/TriggerSecretPut.ts +74 -0
- package/src/models/TriggerSecretState.ts +94 -0
- package/src/models/TriggerTestFireRequest.ts +73 -0
- package/src/models/TriggerToken.ts +93 -0
- package/src/models/TriggerView.ts +168 -0
- package/src/models/index.ts +13 -0
- package/src/runtime.ts +12 -0
- package/src/webhooks.ts +5 -1
|
@@ -0,0 +1,525 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Trigger = exports.ToolPolicy = exports.EXACT_NAME_TOOLS = exports.ALLOW_ALL = void 0;
|
|
4
|
+
exports.parsePath = parsePath;
|
|
5
|
+
exports.checkTrigger = checkTrigger;
|
|
6
|
+
exports.checkTriggers = checkTriggers;
|
|
7
|
+
exports.triggerJson = triggerJson;
|
|
8
|
+
exports.triggersJson = triggersJson;
|
|
9
|
+
exports.keyed = keyed;
|
|
10
|
+
exports.newSession = newSession;
|
|
11
|
+
exports.triggerToken = triggerToken;
|
|
12
|
+
/**
|
|
13
|
+
* `triggers` entries of `agent.json`: inbound events that start a turn (as the Python SDK's `Trigger`).
|
|
14
|
+
*
|
|
15
|
+
* The rules mirror the server's (panja `claw_common/agent_settings/triggers.py`, its parse messages in `schema.py`
|
|
16
|
+
* and `triggers_check.check_triggers_list` with the default `TriggerSettings`); `shared/triggers/vectors.json` pins
|
|
17
|
+
* them for both SDKs. `checkTriggers` checks the `agent.json` form and throws `UserError` with the server's path and
|
|
18
|
+
* sentence and the issue (`code`, `path`, `message`) it would report.
|
|
19
|
+
*
|
|
20
|
+
* `agent.json` never holds a signing secret: a provider trigger's secret is set per trigger after deploy
|
|
21
|
+
* (`client.triggers.setSecret`). What needs the server stays there: a `regex` filter's syntax, a `promptTemplate`'s
|
|
22
|
+
* Jinja syntax and the server's caps. Its 422 throws `UserError` from `deploy`.
|
|
23
|
+
*/
|
|
24
|
+
const errors_js_1 = require("./errors.js");
|
|
25
|
+
/** The `"*"` pattern: every tool, `bash`, `run_program`, `delegate_task` and `agent_test_run` included. */
|
|
26
|
+
exports.ALLOW_ALL = "*";
|
|
27
|
+
/** Tools a partial glob never reaches: a trigger gets one only by naming it exactly or with `"*"`. */
|
|
28
|
+
exports.EXACT_NAME_TOOLS = ["bash", "run_program", "delegate_task", "agent_test_run"];
|
|
29
|
+
/** Builders for `ToolPolicy`. */
|
|
30
|
+
exports.ToolPolicy = {
|
|
31
|
+
/** Every tool the agent has, `bash`, `run_program`, `delegate_task` and `agent_test_run` included. */
|
|
32
|
+
all: () => ({ allow: [exports.ALLOW_ALL] }),
|
|
33
|
+
};
|
|
34
|
+
const NAME_PATTERN = /^[a-z][a-z0-9_]{0,62}$/;
|
|
35
|
+
const PATH_SEGMENTS_MAX = 16;
|
|
36
|
+
const KEY_PATHS_MIN = 2;
|
|
37
|
+
const KEY_PATHS_MAX = 4;
|
|
38
|
+
const TOOL_ALLOW_MAX = 64;
|
|
39
|
+
const TOOL_PATTERN_MAX = 128;
|
|
40
|
+
const HEADER_PATTERN = /^[A-Za-z0-9-]{1,64}$/;
|
|
41
|
+
const ALWAYS_HIDDEN_HEADERS = ["authorization", "cookie", "proxy-authorization"];
|
|
42
|
+
const HMAC_PREFIX_MAX = 16;
|
|
43
|
+
// The server's default caps (TriggerSettings). An operator can raise them, so they are not checked here: the server's
|
|
44
|
+
// 422 reports a value over them. Only a limit below 1, which no setting allows, is refused locally; its sentence names
|
|
45
|
+
// the default cap, as the server's does unless an operator changed it.
|
|
46
|
+
const LIMIT_CAPS = [["max_payload_bytes", 1048576], ["per_hour", 600], ["per_day", 10000]];
|
|
47
|
+
const VERIFY_MODES = ["bearer", "standard_webhooks", "github", "slack", "hmac"];
|
|
48
|
+
const FILTER_OPS = ["eq", "in", "contains", "starts_with", "regex"];
|
|
49
|
+
const HMAC_CHOICES = [
|
|
50
|
+
["algorithm", ["sha256", "sha1"]], ["encoding", ["hex", "base64"]], ["signed", ["body", "timestamp.body", "timestamp+body"]],
|
|
51
|
+
];
|
|
52
|
+
const SESSION_MODES = ["new", "keyed"];
|
|
53
|
+
// The server's fixed sentences for a value of the wrong shape (schema.py _MESSAGES, triggers rows).
|
|
54
|
+
const TRIGGERS_SENTENCE = 'triggers must be a list of objects with a name, a verify object ({"mode": "bearer"}, ' +
|
|
55
|
+
'"github", "slack", "standard_webhooks" or "hmac") and optional filter, prompt_template, session, limits and ' +
|
|
56
|
+
"tool_policy.";
|
|
57
|
+
const SENTENCES = {
|
|
58
|
+
"triggers.name": "name must be 1 to 63 characters: a lowercase letter, then lowercase letters, digits or _.",
|
|
59
|
+
"triggers.verify": 'verify must be an object with a mode: "bearer", "standard_webhooks", "github", "slack" or ' +
|
|
60
|
+
'"hmac" (hmac also needs a header).',
|
|
61
|
+
"triggers.verify.mode": 'verify.mode must be "bearer", "standard_webhooks", "github", "slack" or "hmac".',
|
|
62
|
+
"triggers.filter": "filter must be a list of rules, each with a path, an op (eq, in, contains, starts_with or " +
|
|
63
|
+
"regex) and a value.",
|
|
64
|
+
"triggers.prompt_template": "prompt_template must be a string.",
|
|
65
|
+
"triggers.session": 'session must be an object: mode "new" or "keyed", and for keyed a key_path (a path, or a ' +
|
|
66
|
+
"list of 2 to 4 paths).",
|
|
67
|
+
"triggers.limits": "limits must be an object of whole numbers: max_payload_bytes, per_hour, per_day.",
|
|
68
|
+
"triggers.limits.max_payload_bytes": "limits.max_payload_bytes must be a whole number.",
|
|
69
|
+
"triggers.limits.per_hour": "limits.per_hour must be a whole number.",
|
|
70
|
+
"triggers.limits.per_day": "limits.per_day must be a whole number.",
|
|
71
|
+
"triggers.tool_policy": "tool_policy must be an object with allow: a list of strings.",
|
|
72
|
+
};
|
|
73
|
+
// The server's field names (schema.py _FIELD_NAMES): its error path keeps a key that is one of these and stops at the
|
|
74
|
+
// first that is not. `secret_credential` is one (a webhook's field), so a trigger that still names one is refused at
|
|
75
|
+
// `verify.secret_credential`.
|
|
76
|
+
const FIELD_NAMES = new Set([
|
|
77
|
+
"algorithm", "allow", "allow_bot_events", "allowed_domains", "blocked_domains", "builtin_tools", "clarify",
|
|
78
|
+
"code_mode", "description", "encoding", "endpoint", "events", "fallback", "filter",
|
|
79
|
+
"function_timeout_seconds", "functions", "header", "id_header", "id_path", "key_path", "limits",
|
|
80
|
+
"max_output_tokens", "max_payload_bytes", "max_tokens_per_turn", "max_tool_calls_per_turn", "max_turns", "mode",
|
|
81
|
+
"model", "name", "op", "output_schema", "parameters", "path", "per_day", "per_hour", "prefix", "prompt_template",
|
|
82
|
+
"reasoning", "sandbox", "schedules", "secret_credential", "session", "signed", "subagents", "temperature",
|
|
83
|
+
"timestamp_header", "todo", "tool_choice", "tool_policy", "top_p", "triggers", "url", "value", "verify",
|
|
84
|
+
"version", "web_search", "webhooks",
|
|
85
|
+
]);
|
|
86
|
+
const VERIFY_FIELDS = {
|
|
87
|
+
bearer: ["mode"],
|
|
88
|
+
standard_webhooks: ["mode"],
|
|
89
|
+
github: ["mode"],
|
|
90
|
+
slack: ["mode", "allow_bot_events"],
|
|
91
|
+
hmac: ["mode", "header", "algorithm", "encoding", "signed", "timestamp_header", "prefix", "id_header", "id_path"],
|
|
92
|
+
};
|
|
93
|
+
const TRIGGER_FIELDS = ["name", "verify", "filter", "prompt_template", "session", "limits", "tool_policy"];
|
|
94
|
+
class Issue extends Error {
|
|
95
|
+
constructor(issue) {
|
|
96
|
+
super(issue.message);
|
|
97
|
+
this.issue = issue;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const issue = (code, path, message) => new Issue({ code, path, message });
|
|
101
|
+
function sentence(path) {
|
|
102
|
+
var _a;
|
|
103
|
+
const key = path.split(".").filter((p) => !/^[0-9]+$/.test(p)).join(".");
|
|
104
|
+
return (_a = SENTENCES[key]) !== null && _a !== void 0 ? _a : TRIGGERS_SENTENCE;
|
|
105
|
+
}
|
|
106
|
+
/** A value of the wrong type or shape, as the server's parse reports it. */
|
|
107
|
+
const shape = (path) => issue("invalid_value", path, sentence(path));
|
|
108
|
+
const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
109
|
+
const isStr = (v) => typeof v === "string";
|
|
110
|
+
const isInt = (v) => typeof v === "number" && Number.isInteger(v);
|
|
111
|
+
/** A JSON scalar; NaN and infinities are not JSON (they would be written as null). */
|
|
112
|
+
const isScalar = (v) => typeof v === "string" || (typeof v === "number" && Number.isFinite(v)) || typeof v === "boolean";
|
|
113
|
+
/** Length in code points, as Python's `len`. */
|
|
114
|
+
const chars = (s) => Array.from(s).length;
|
|
115
|
+
function extra(obj, allowed, path, stop = false) {
|
|
116
|
+
for (const key of Object.keys(obj)) {
|
|
117
|
+
if (allowed.indexOf(key) === -1)
|
|
118
|
+
throw shape(stop || !FIELD_NAMES.has(key) ? path : `${path}.${key}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/** A dot path as segments (digits index an array), or null when the server refuses it. */
|
|
122
|
+
function parsePath(path) {
|
|
123
|
+
const segments = path.split(".");
|
|
124
|
+
if (segments.length > PATH_SEGMENTS_MAX || segments.some((s) => s === ""))
|
|
125
|
+
return null;
|
|
126
|
+
return segments.map((s) => (/^[0-9]+$/.test(s) ? Number(s) : s));
|
|
127
|
+
}
|
|
128
|
+
/** A path's identity as the server compares key paths: digit segments without leading zeros ("a.01" is "a.1"). Kept
|
|
129
|
+
* as strings, so digit runs longer than a safe integer stay distinct. */
|
|
130
|
+
function pathKey(path) {
|
|
131
|
+
const segments = path.split(".");
|
|
132
|
+
if (segments.length > PATH_SEGMENTS_MAX || segments.some((s) => s === ""))
|
|
133
|
+
return null;
|
|
134
|
+
return JSON.stringify(segments.map((s) => (/^[0-9]+$/.test(s) ? ["#", s.replace(/^0+(?=.)/, "")] : s)));
|
|
135
|
+
}
|
|
136
|
+
// -- the agent.json form ------------------------------------------------------------------------------------------
|
|
137
|
+
function findNull(value, path) {
|
|
138
|
+
if (Array.isArray(value)) {
|
|
139
|
+
value.forEach((item, i) => {
|
|
140
|
+
const child = `${path}.${i}`;
|
|
141
|
+
if (item === null)
|
|
142
|
+
throw issue("null_not_allowed", child, `${child} is null; null is not allowed in agent.json.`);
|
|
143
|
+
findNull(item, child);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
else if (isObject(value)) {
|
|
147
|
+
for (const [key, item] of Object.entries(value)) {
|
|
148
|
+
const child = `${path}.${key}`;
|
|
149
|
+
if (item === null) {
|
|
150
|
+
throw issue("null_not_allowed", child, `${child} is null; null is not allowed in agent.json. Remove the key to use the default.`);
|
|
151
|
+
}
|
|
152
|
+
findNull(item, child);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const verifyRule = (path, field, text) => issue("trigger_verify_invalid", `${path}.${field}`, `verify.${field}: ${text}`);
|
|
157
|
+
function headerOk(path, field, value) {
|
|
158
|
+
if (value === undefined)
|
|
159
|
+
return;
|
|
160
|
+
if (!isStr(value))
|
|
161
|
+
throw shape(`${path}.${field}`);
|
|
162
|
+
if (!HEADER_PATTERN.test(value))
|
|
163
|
+
throw verifyRule(path, field, "must be a header name of 1 to 64 letters, digits or -.");
|
|
164
|
+
if (ALWAYS_HIDDEN_HEADERS.indexOf(value.toLowerCase()) !== -1) {
|
|
165
|
+
throw verifyRule(path, field, `${value} carries credentials and is never forwarded; name the header the ` +
|
|
166
|
+
"provider signs with.");
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function parseVerify(verify, path) {
|
|
170
|
+
var _a;
|
|
171
|
+
if (!isObject(verify))
|
|
172
|
+
throw shape(path);
|
|
173
|
+
const mode = verify["mode"];
|
|
174
|
+
if (!isStr(mode) || VERIFY_MODES.indexOf(mode) === -1)
|
|
175
|
+
throw shape(`${path}.mode`);
|
|
176
|
+
if (mode === "bearer") {
|
|
177
|
+
extra(verify, VERIFY_FIELDS["bearer"], path, true);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (mode === "slack" && "allow_bot_events" in verify && typeof verify["allow_bot_events"] !== "boolean") {
|
|
181
|
+
throw shape(`${path}.allow_bot_events`);
|
|
182
|
+
}
|
|
183
|
+
if (mode === "hmac") {
|
|
184
|
+
headerOk(path, "header", verify["header"]);
|
|
185
|
+
if (!("header" in verify))
|
|
186
|
+
throw shape(`${path}.header`);
|
|
187
|
+
for (const [field, allowed] of HMAC_CHOICES) {
|
|
188
|
+
if (field in verify && allowed.indexOf(verify[field]) === -1)
|
|
189
|
+
throw shape(`${path}.${field}`);
|
|
190
|
+
}
|
|
191
|
+
headerOk(path, "timestamp_header", verify["timestamp_header"]);
|
|
192
|
+
const prefix = "prefix" in verify ? verify["prefix"] : "";
|
|
193
|
+
if (!isStr(prefix))
|
|
194
|
+
throw shape(`${path}.prefix`);
|
|
195
|
+
if (chars(prefix) > HMAC_PREFIX_MAX) {
|
|
196
|
+
throw verifyRule(path, "prefix", `prefix may be at most ${HMAC_PREFIX_MAX} characters.`);
|
|
197
|
+
}
|
|
198
|
+
headerOk(path, "id_header", verify["id_header"]);
|
|
199
|
+
const idPath = verify["id_path"];
|
|
200
|
+
if (idPath !== undefined) {
|
|
201
|
+
if (!isStr(idPath))
|
|
202
|
+
throw shape(`${path}.id_path`);
|
|
203
|
+
if (parsePath(idPath) === null) {
|
|
204
|
+
throw verifyRule(path, "id_path", `id_path must be a dot path of at most ${PATH_SEGMENTS_MAX} segments.`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
extra(verify, VERIFY_FIELDS[mode], path);
|
|
209
|
+
if (mode === "hmac") {
|
|
210
|
+
const signed = (_a = verify["signed"]) !== null && _a !== void 0 ? _a : "body";
|
|
211
|
+
if (signed !== "body" && verify["timestamp_header"] === undefined) {
|
|
212
|
+
throw verifyRule(path, "timestamp_header", `signed ${signed} needs timestamp_header: the header that carries the timestamp.`);
|
|
213
|
+
}
|
|
214
|
+
if (verify["id_header"] !== undefined && verify["id_path"] !== undefined) {
|
|
215
|
+
throw verifyRule(path, "id_path", "set id_header or id_path for the event id, not both.");
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
function parseFilter(rules, path) {
|
|
220
|
+
if (!Array.isArray(rules))
|
|
221
|
+
throw shape(path);
|
|
222
|
+
rules.forEach((rule, j) => {
|
|
223
|
+
const rpath = `${path}.${j}`;
|
|
224
|
+
if (!isObject(rule))
|
|
225
|
+
throw shape(rpath);
|
|
226
|
+
if (!isStr(rule["path"]))
|
|
227
|
+
throw shape(`${rpath}.path`);
|
|
228
|
+
if (FILTER_OPS.indexOf(rule["op"]) === -1)
|
|
229
|
+
throw shape(`${rpath}.op`);
|
|
230
|
+
const value = rule["value"];
|
|
231
|
+
if (!("value" in rule) || !(isScalar(value) || (Array.isArray(value) && value.every(isScalar)))) {
|
|
232
|
+
throw shape(`${rpath}.value`);
|
|
233
|
+
}
|
|
234
|
+
extra(rule, ["path", "op", "value"], rpath);
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
function parseSession(session, path) {
|
|
238
|
+
if (!isObject(session))
|
|
239
|
+
throw shape(path);
|
|
240
|
+
if ("mode" in session && SESSION_MODES.indexOf(session["mode"]) === -1)
|
|
241
|
+
throw shape(`${path}.mode`);
|
|
242
|
+
const keyPath = session["key_path"];
|
|
243
|
+
if (keyPath !== undefined && !isStr(keyPath) && !(Array.isArray(keyPath) && keyPath.every(isStr))) {
|
|
244
|
+
throw shape(`${path}.key_path`);
|
|
245
|
+
}
|
|
246
|
+
extra(session, ["mode", "key_path"], path);
|
|
247
|
+
}
|
|
248
|
+
function parseLimits(limits, path) {
|
|
249
|
+
if (!isObject(limits))
|
|
250
|
+
throw shape(path);
|
|
251
|
+
for (const [name] of LIMIT_CAPS)
|
|
252
|
+
if (name in limits && !isInt(limits[name]))
|
|
253
|
+
throw shape(`${path}.${name}`);
|
|
254
|
+
extra(limits, LIMIT_CAPS.map(([n]) => n), path);
|
|
255
|
+
}
|
|
256
|
+
function parseToolPolicy(policy, path) {
|
|
257
|
+
if (!isObject(policy))
|
|
258
|
+
throw shape(path);
|
|
259
|
+
const allow = policy["allow"];
|
|
260
|
+
if (!Array.isArray(allow))
|
|
261
|
+
throw shape(`${path}.allow`);
|
|
262
|
+
allow.forEach((pattern, i) => {
|
|
263
|
+
if (!isStr(pattern))
|
|
264
|
+
throw shape(`${path}.allow.${i}`);
|
|
265
|
+
});
|
|
266
|
+
// ToolPolicy's own validator (pattern length, then the reserved ":" prefix) runs before the unknown-key check.
|
|
267
|
+
if (allow.some((p) => chars(p) > TOOL_PATTERN_MAX)) {
|
|
268
|
+
throw issue("invalid_value", `${path}.allow`, `each tool_policy.allow pattern may be at most ${TOOL_PATTERN_MAX} characters.`);
|
|
269
|
+
}
|
|
270
|
+
if (allow.some((p) => p.startsWith(":"))) {
|
|
271
|
+
throw issue("invalid_value", `${path}.allow`, "a tool_policy.allow pattern may not start with ':'.");
|
|
272
|
+
}
|
|
273
|
+
extra(policy, ["allow"], path);
|
|
274
|
+
}
|
|
275
|
+
/** The rules the server's parse applies to one entry (shape, name, verify, tool_policy patterns). */
|
|
276
|
+
function parse(item, base) {
|
|
277
|
+
if (!isObject(item))
|
|
278
|
+
throw shape(base);
|
|
279
|
+
const name = item["name"];
|
|
280
|
+
if (!isStr(name) || !NAME_PATTERN.test(name))
|
|
281
|
+
throw shape(`${base}.name`);
|
|
282
|
+
if (!("verify" in item))
|
|
283
|
+
throw shape(`${base}.verify`);
|
|
284
|
+
parseVerify(item["verify"], `${base}.verify`);
|
|
285
|
+
if ("filter" in item)
|
|
286
|
+
parseFilter(item["filter"], `${base}.filter`);
|
|
287
|
+
if ("prompt_template" in item && !isStr(item["prompt_template"]))
|
|
288
|
+
throw shape(`${base}.prompt_template`);
|
|
289
|
+
if ("session" in item)
|
|
290
|
+
parseSession(item["session"], `${base}.session`);
|
|
291
|
+
if ("limits" in item)
|
|
292
|
+
parseLimits(item["limits"], `${base}.limits`);
|
|
293
|
+
if ("tool_policy" in item)
|
|
294
|
+
parseToolPolicy(item["tool_policy"], `${base}.tool_policy`);
|
|
295
|
+
extra(item, TRIGGER_FIELDS, base);
|
|
296
|
+
}
|
|
297
|
+
function valueProblem(op, value) {
|
|
298
|
+
if (op === "in") {
|
|
299
|
+
if (!Array.isArray(value))
|
|
300
|
+
return "value must be a list for op in.";
|
|
301
|
+
}
|
|
302
|
+
else if (Array.isArray(value)) {
|
|
303
|
+
return "value must be a single value unless op is in.";
|
|
304
|
+
}
|
|
305
|
+
else if ((op === "starts_with" || op === "regex") && !isStr(value)) {
|
|
306
|
+
return `value must be a string for op ${op}.`;
|
|
307
|
+
}
|
|
308
|
+
return null;
|
|
309
|
+
}
|
|
310
|
+
/** The server's save rules for one parsed entry (check_triggers_list). */
|
|
311
|
+
function save(item, base) {
|
|
312
|
+
var _a, _b, _c, _d;
|
|
313
|
+
const session = ((_a = item["session"]) !== null && _a !== void 0 ? _a : {});
|
|
314
|
+
const keyPath = session["key_path"];
|
|
315
|
+
const kpath = `${base}.session.key_path`;
|
|
316
|
+
if (session["mode"] === "keyed" && keyPath === undefined) {
|
|
317
|
+
throw issue("trigger_key_path_required", kpath, "a keyed session needs key_path: the path of the value that names the conversation.");
|
|
318
|
+
}
|
|
319
|
+
if (keyPath !== undefined && ((_b = session["mode"]) !== null && _b !== void 0 ? _b : "new") === "new") {
|
|
320
|
+
throw issue("trigger_key_path_unused", kpath, "key_path is only read by a keyed session: set session.mode to keyed, or remove key_path.");
|
|
321
|
+
}
|
|
322
|
+
if (keyPath !== undefined) {
|
|
323
|
+
const paths = isStr(keyPath) ? [keyPath] : keyPath;
|
|
324
|
+
if (Array.isArray(keyPath)) {
|
|
325
|
+
if (keyPath.length < KEY_PATHS_MIN || keyPath.length > KEY_PATHS_MAX) {
|
|
326
|
+
throw issue("trigger_key_path_invalid", kpath, `key_path as a list needs ${KEY_PATHS_MIN} to ${KEY_PATHS_MAX} paths; use a single string for one path.`);
|
|
327
|
+
}
|
|
328
|
+
// Compared as parsed segments, so "a.1" and "a.01" are one path.
|
|
329
|
+
const keys = new Set(keyPath.map((p) => { var _a; return (_a = pathKey(p)) !== null && _a !== void 0 ? _a : `raw:${p}`; }));
|
|
330
|
+
if (keys.size < keyPath.length) {
|
|
331
|
+
throw issue("trigger_key_path_invalid", kpath, "key_path must not list the same path twice.");
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
if (!paths.every((p) => parsePath(p) !== null)) {
|
|
335
|
+
throw issue("trigger_path_invalid", kpath, `key_path must be dot paths of at most ${PATH_SEGMENTS_MAX} segments, like repository.full_name.`);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
const rules = ((_c = item["filter"]) !== null && _c !== void 0 ? _c : []);
|
|
339
|
+
rules.forEach((rule, j) => {
|
|
340
|
+
const rbase = `${base}.filter.${j}`;
|
|
341
|
+
if (parsePath(rule["path"]) === null) {
|
|
342
|
+
throw issue("trigger_path_invalid", `${rbase}.path`, `path must be a dot path of at most ${PATH_SEGMENTS_MAX} segments, like pull_request.labels.0.name.`);
|
|
343
|
+
}
|
|
344
|
+
const problem = valueProblem(rule["op"], rule["value"]);
|
|
345
|
+
if (problem !== null)
|
|
346
|
+
throw issue("trigger_filter_value_invalid", `${rbase}.value`, problem);
|
|
347
|
+
});
|
|
348
|
+
const limits = ((_d = item["limits"]) !== null && _d !== void 0 ? _d : {});
|
|
349
|
+
for (const [name, cap] of LIMIT_CAPS) {
|
|
350
|
+
const value = limits[name];
|
|
351
|
+
if (value !== undefined && value < 1) {
|
|
352
|
+
throw issue("trigger_limit_out_of_range", `${base}.limits.${name}`, `limits.${name} must be from 1 to ${cap}.`);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
const policy = item["tool_policy"];
|
|
356
|
+
if (policy !== undefined) {
|
|
357
|
+
const n = policy["allow"].length;
|
|
358
|
+
if (n < 1 || n > TOOL_ALLOW_MAX) {
|
|
359
|
+
throw issue("trigger_tool_policy_empty", `${base}.tool_policy.allow`, `tool_policy.allow must list 1 to ${TOOL_ALLOW_MAX} tool patterns; remove tool_policy to inherit the ` +
|
|
360
|
+
"agent's tools.");
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
function rethrow(err) {
|
|
365
|
+
if (err instanceof Issue)
|
|
366
|
+
throw new errors_js_1.UserError(`${err.issue.path}: ${err.issue.message}`, [err.issue]);
|
|
367
|
+
throw err;
|
|
368
|
+
}
|
|
369
|
+
/** One entry's rules (not the list's), reported under `base`. */
|
|
370
|
+
function checkTrigger(item, base = "triggers") {
|
|
371
|
+
try {
|
|
372
|
+
findNull(item, base);
|
|
373
|
+
parse(item, base);
|
|
374
|
+
save(item, base);
|
|
375
|
+
}
|
|
376
|
+
catch (err) {
|
|
377
|
+
rethrow(err);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
/** The server's `triggers` rules over the `agent.json` form; throws `UserError` for the first issue. */
|
|
381
|
+
function checkTriggers(items) {
|
|
382
|
+
try {
|
|
383
|
+
findNull(items, "triggers");
|
|
384
|
+
items.forEach((item, i) => parse(item, `triggers.${i}`));
|
|
385
|
+
const seen = new Set();
|
|
386
|
+
items.forEach((item, i) => {
|
|
387
|
+
const name = item["name"];
|
|
388
|
+
if (seen.has(name)) {
|
|
389
|
+
throw issue("trigger_name_duplicate", `triggers.${i}.name`, "triggers must not share a name; give each its own.");
|
|
390
|
+
}
|
|
391
|
+
seen.add(name);
|
|
392
|
+
});
|
|
393
|
+
items.forEach((item, i) => save(item, `triggers.${i}`));
|
|
394
|
+
}
|
|
395
|
+
catch (err) {
|
|
396
|
+
rethrow(err);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
// -- the camelCase form -------------------------------------------------------------------------------------------
|
|
400
|
+
/** Copies `obj`'s keys under their agent.json names; a key not in `names` throws, as Python's keyword arguments do.
|
|
401
|
+
* null and undefined mean unset (like Python's None) and write no key. */
|
|
402
|
+
function rename(obj, names, path) {
|
|
403
|
+
if (!isObject(obj))
|
|
404
|
+
return obj;
|
|
405
|
+
const out = {};
|
|
406
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
407
|
+
if (!(key in names))
|
|
408
|
+
throw new errors_js_1.UserError(`${path}.${key}: Extra inputs are not permitted`);
|
|
409
|
+
if (value !== undefined && value !== null)
|
|
410
|
+
out[names[key]] = Array.isArray(value) ? [...value] : value;
|
|
411
|
+
}
|
|
412
|
+
return out;
|
|
413
|
+
}
|
|
414
|
+
const VERIFY_NAMES = {
|
|
415
|
+
mode: "mode", allowBotEvents: "allow_bot_events", header: "header",
|
|
416
|
+
algorithm: "algorithm", encoding: "encoding", signed: "signed", timestampHeader: "timestamp_header",
|
|
417
|
+
prefix: "prefix", idHeader: "id_header", idPath: "id_path",
|
|
418
|
+
};
|
|
419
|
+
function triggerJsonAt(t, path) {
|
|
420
|
+
if (!isObject(t))
|
|
421
|
+
return t;
|
|
422
|
+
const known = ["name", "verify", "filter", "promptTemplate", "session", "limits", "toolPolicy"];
|
|
423
|
+
for (const key of Object.keys(t)) {
|
|
424
|
+
if (known.indexOf(key) === -1)
|
|
425
|
+
throw new errors_js_1.UserError(`${path}.${key}: Extra inputs are not permitted`);
|
|
426
|
+
}
|
|
427
|
+
const out = { name: t["name"], verify: rename(t["verify"], VERIFY_NAMES, `${path}.verify`) };
|
|
428
|
+
const verify = out["verify"];
|
|
429
|
+
// Python writes allow_bot_events only when it is not False.
|
|
430
|
+
if (isObject(verify) && verify["allow_bot_events"] === false)
|
|
431
|
+
delete verify["allow_bot_events"];
|
|
432
|
+
const filter = t["filter"];
|
|
433
|
+
if (Array.isArray(filter) ? filter.length > 0 : filter !== undefined && filter !== null) {
|
|
434
|
+
out["filter"] = Array.isArray(filter)
|
|
435
|
+
? filter.map((rule, j) => rename(rule, { path: "path", op: "op", value: "value" }, `${path}.filter.${j}`))
|
|
436
|
+
: filter;
|
|
437
|
+
// A rule's value of null is a value (the server refuses it), not an unset key.
|
|
438
|
+
if (Array.isArray(filter)) {
|
|
439
|
+
filter.forEach((rule, j) => {
|
|
440
|
+
if (isObject(rule) && rule["value"] === null)
|
|
441
|
+
(out["filter"][j])["value"] = null;
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
if (t["promptTemplate"] !== undefined && t["promptTemplate"] !== null)
|
|
446
|
+
out["prompt_template"] = t["promptTemplate"];
|
|
447
|
+
if (t["session"] !== undefined && t["session"] !== null) {
|
|
448
|
+
out["session"] = rename(t["session"], { mode: "mode", keyPath: "key_path" }, `${path}.session`);
|
|
449
|
+
}
|
|
450
|
+
if (t["limits"] !== undefined && t["limits"] !== null) {
|
|
451
|
+
out["limits"] = rename(t["limits"], { maxPayloadBytes: "max_payload_bytes", perHour: "per_hour", perDay: "per_day" }, `${path}.limits`);
|
|
452
|
+
}
|
|
453
|
+
const policy = t["toolPolicy"];
|
|
454
|
+
if (Array.isArray(policy)) {
|
|
455
|
+
out["tool_policy"] = { allow: [...policy] };
|
|
456
|
+
}
|
|
457
|
+
else if (policy !== undefined && policy !== null) {
|
|
458
|
+
out["tool_policy"] = rename(policy, { allow: "allow" }, `${path}.toolPolicy`);
|
|
459
|
+
}
|
|
460
|
+
return out;
|
|
461
|
+
}
|
|
462
|
+
/** One trigger in agent.json's names (a copy). */
|
|
463
|
+
function triggerJson(t) {
|
|
464
|
+
return triggerJsonAt(t, "triggers");
|
|
465
|
+
}
|
|
466
|
+
function triggersJson(triggers) {
|
|
467
|
+
return triggers.map((t, i) => triggerJsonAt(t, `triggers.${i}`));
|
|
468
|
+
}
|
|
469
|
+
function built(t) {
|
|
470
|
+
checkTrigger(triggerJsonAt(t, "triggers"));
|
|
471
|
+
return t;
|
|
472
|
+
}
|
|
473
|
+
/** Builders for the common triggers; each checks the trigger as the server would and throws `UserError`. */
|
|
474
|
+
exports.Trigger = {
|
|
475
|
+
/** Your own system sends `Authorization: Bearer <token>`; `deploy` returns the token once. */
|
|
476
|
+
bearer(opts) {
|
|
477
|
+
const { name, ...rest } = opts;
|
|
478
|
+
return built({ name, verify: { mode: "bearer" }, ...rest });
|
|
479
|
+
},
|
|
480
|
+
/** A GitHub webhook. After deploy, set its secret: `client.triggers.setSecret(agentId, name)` returns a generated
|
|
481
|
+
* one to paste into GitHub. */
|
|
482
|
+
github(opts) {
|
|
483
|
+
const { name, ...rest } = opts;
|
|
484
|
+
return built({ name, verify: { mode: "github" }, ...rest });
|
|
485
|
+
},
|
|
486
|
+
/** Your Slack app's Events API. After deploy, pass the app's signing secret to
|
|
487
|
+
* `client.triggers.setSecret(agentId, name, secret)`. */
|
|
488
|
+
slack(opts) {
|
|
489
|
+
const { name, allowBotEvents, ...rest } = opts;
|
|
490
|
+
const verify = { mode: "slack" };
|
|
491
|
+
if (allowBotEvents !== undefined)
|
|
492
|
+
verify.allowBotEvents = allowBotEvents;
|
|
493
|
+
return built({ name, verify, ...rest });
|
|
494
|
+
},
|
|
495
|
+
/** A sender that signs with Standard Webhooks (Svix and many SaaS tools). */
|
|
496
|
+
standardWebhooks(opts) {
|
|
497
|
+
const { name, ...rest } = opts;
|
|
498
|
+
return built({ name, verify: { mode: "standard_webhooks" }, ...rest });
|
|
499
|
+
},
|
|
500
|
+
/** A provider's own HMAC signature in `header` (see `HmacVerify`). */
|
|
501
|
+
hmac(opts) {
|
|
502
|
+
const { name, header, algorithm, encoding, signed, timestampHeader, prefix, idHeader, idPath, ...rest } = opts;
|
|
503
|
+
const verify = { mode: "hmac", header };
|
|
504
|
+
const options = { algorithm, encoding, signed, timestampHeader, prefix, idHeader, idPath };
|
|
505
|
+
for (const [key, value] of Object.entries(options)) {
|
|
506
|
+
if (value !== undefined)
|
|
507
|
+
verify[key] = value;
|
|
508
|
+
}
|
|
509
|
+
return built({ name, verify, ...rest });
|
|
510
|
+
},
|
|
511
|
+
};
|
|
512
|
+
/** Events with the same value at `keyPath` (or the same values at 2 to 4 paths) share one conversation. */
|
|
513
|
+
function keyed(keyPath) {
|
|
514
|
+
return { mode: "keyed", keyPath: Array.isArray(keyPath) ? [...keyPath] : keyPath };
|
|
515
|
+
}
|
|
516
|
+
/** Every event starts its own conversation (the default). */
|
|
517
|
+
function newSession() {
|
|
518
|
+
return { mode: "new" };
|
|
519
|
+
}
|
|
520
|
+
/** A deploy response's `triggerTokens` entry as a `MintedTriggerToken` whose `token` is not enumerable. */
|
|
521
|
+
function triggerToken(name, triggerId, url, token) {
|
|
522
|
+
const out = { name, triggerId, url };
|
|
523
|
+
Object.defineProperty(out, "token", { value: token, enumerable: false, writable: false });
|
|
524
|
+
return Object.freeze(out);
|
|
525
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `client.triggers`: an agent's inbound triggers after deploy: their signing secrets and their events (as Python's
|
|
3
|
+
* `sarvam_agents.compose.triggers`).
|
|
4
|
+
*
|
|
5
|
+
* The public surface is `Triggers`, shaped like `client.webhooks`: every method takes the agent's id and the trigger,
|
|
6
|
+
* named by its agent.json name (or a compose `Trigger`, or a `TriggerView` from `Triggers.list`).
|
|
7
|
+
*
|
|
8
|
+
* A provider trigger (`github`, `standard_webhooks`, `hmac`, `slack`) refuses every request until it has a signing
|
|
9
|
+
* secret, set per trigger (panja #1758: `PUT`/`DELETE /v1/triggers/{id}/secret`, `POST .../rotate-secret`). A
|
|
10
|
+
* `bearer` trigger has a token instead, minted by the deploy (`Deployment.triggerTokens`) or by
|
|
11
|
+
* `Triggers.rotateSecret`.
|
|
12
|
+
*
|
|
13
|
+
* No secret or token is logged, kept on an object or put in an error message.
|
|
14
|
+
*/
|
|
15
|
+
import { TriggersApi } from "../apis/TriggersApi.js";
|
|
16
|
+
import type { TriggerEventList, TriggerEventView, TriggerView } from "../models/index.js";
|
|
17
|
+
import type { Configuration } from "../runtime.js";
|
|
18
|
+
import type { Trigger } from "./trigger.js";
|
|
19
|
+
export type TriggerSecretStatus = "set" | "missing";
|
|
20
|
+
/** A trigger: its agent.json name, a compose `Trigger`, or a `TriggerView` from `client.triggers.list`. */
|
|
21
|
+
export type TriggerRef = string | Trigger | TriggerView;
|
|
22
|
+
/** How long a replaced secret or token keeps working by default, and at most (TOKEN_ROTATION_GRACE_SECONDS). */
|
|
23
|
+
export declare const GRACE_SECONDS_MAX = 86400;
|
|
24
|
+
/** The longest secret the server stores (trigger_secret_repo.SECRET_MAX_CHARS). */
|
|
25
|
+
export declare const SECRET_MAX_CHARS = 512;
|
|
26
|
+
/** Events are kept for this many days; older ones are no longer listed (CLAW_TRIGGERS_EVENT_RETENTION_DAYS). */
|
|
27
|
+
export declare const EVENT_WINDOW_DAYS = 7;
|
|
28
|
+
/** The event list's page size: default and maximum. */
|
|
29
|
+
export declare const EVENTS_PAGE_DEFAULT = 50;
|
|
30
|
+
export declare const EVENTS_PAGE_MAX = 200;
|
|
31
|
+
/** `error` of an event whose turn failed on a model-provider or transport outage (the worker's code). It does not
|
|
32
|
+
* count toward the trigger's auto-pause; replay the event once the provider is back. */
|
|
33
|
+
export declare const PROVIDER_OUTAGE_ERROR = "llm_unavailable";
|
|
34
|
+
/**
|
|
35
|
+
* `client.triggers`: an agent's inbound triggers.
|
|
36
|
+
*
|
|
37
|
+
* `list` / `get` read them (`tokenPrefix`, `secretStatus`, `url`, `enabled`, `pausedReason`...). `setSecret`,
|
|
38
|
+
* `rotateSecret`, `deleteSecret` and `secretStatus` manage a trigger's signing secret (a provider trigger) or token
|
|
39
|
+
* (`rotateSecret` of a `bearer` trigger). `listEvents` / `iterEvents` read its event log, newest first, by cursor.
|
|
40
|
+
*
|
|
41
|
+
* The generated `TriggersApi` (`client.triggers.api`) has the rest: enable, disable, replay and test-fire.
|
|
42
|
+
*/
|
|
43
|
+
export declare class Triggers {
|
|
44
|
+
readonly api: TriggersApi;
|
|
45
|
+
constructor(config: Configuration);
|
|
46
|
+
/** The agent's triggers. Throws `NotSupportedByServerError` when the server has triggers switched off or predates
|
|
47
|
+
* per-trigger secrets (panja #1758). */
|
|
48
|
+
list(agentId: string): Promise<TriggerView[]>;
|
|
49
|
+
/** The trigger named `trigger` (a name, a compose `Trigger`, or a `TriggerView` to re-read). */
|
|
50
|
+
get(agentId: string, trigger: TriggerRef): Promise<TriggerView>;
|
|
51
|
+
private resolve;
|
|
52
|
+
/**
|
|
53
|
+
* Set a provider trigger's signing secret and return it; the server never shows it again.
|
|
54
|
+
*
|
|
55
|
+
* Leave `secret` out to generate a `whsec_` secret (`standard_webhooks`, `github`, `hmac`): give it to the sender
|
|
56
|
+
* (GitHub's webhook secret, say). Pass `secret` to bring your own: Slack's signing secret (32 hex characters; Slack
|
|
57
|
+
* issues it, so a `slack` trigger always needs it), the secret you set on GitHub, or a Standard Webhooks sender's
|
|
58
|
+
* `whsec_` secret. The replaced secret keeps verifying for `graceSeconds` (default a day, the most; `0` drops it at
|
|
59
|
+
* once, after a leak).
|
|
60
|
+
*
|
|
61
|
+
* A `bearer` trigger has a token, not a secret: use `rotateSecret`.
|
|
62
|
+
*/
|
|
63
|
+
setSecret(agentId: string, trigger: TriggerRef, secret?: string, options?: {
|
|
64
|
+
graceSeconds?: number;
|
|
65
|
+
}): Promise<string>;
|
|
66
|
+
/**
|
|
67
|
+
* Replace the trigger's credential with a new one and return it; the server never shows it again.
|
|
68
|
+
*
|
|
69
|
+
* A `bearer` trigger gets a new token (send it as `Authorization: Bearer <token>`); the old one keeps working for a
|
|
70
|
+
* day. A `standard_webhooks`, `github` or `hmac` trigger gets a new generated `whsec_` secret; the old one keeps
|
|
71
|
+
* verifying for `graceSeconds` (default a day; `0` at once). A `slack` trigger's secret comes from Slack:
|
|
72
|
+
* regenerate it there, then `setSecret` it.
|
|
73
|
+
*/
|
|
74
|
+
rotateSecret(agentId: string, trigger: TriggerRef, options?: {
|
|
75
|
+
graceSeconds?: number;
|
|
76
|
+
}): Promise<string>;
|
|
77
|
+
/** Remove a provider trigger's signing secret (the current one and any previous one still in its grace period).
|
|
78
|
+
* The trigger refuses every request until a secret is set again. Nothing to remove is not an error. */
|
|
79
|
+
deleteSecret(agentId: string, trigger: TriggerRef): Promise<void>;
|
|
80
|
+
/** `"set"` when the trigger has its credential (a provider mode's signing secret, a bearer trigger's token);
|
|
81
|
+
* `"missing"` when it refuses every request until one is set. Read fresh from the server. */
|
|
82
|
+
secretStatus(agentId: string, trigger: TriggerRef): Promise<TriggerSecretStatus>;
|
|
83
|
+
private put;
|
|
84
|
+
/** The server's refusal as a `UserError` naming the trigger, never the secret. */
|
|
85
|
+
private refused;
|
|
86
|
+
/** One page of the trigger's events, newest first (by event id), from the last 7 days. Pass the page's `nextCursor`
|
|
87
|
+
* back as `cursor` for the next page; it is left out on the last one. */
|
|
88
|
+
listEvents(agentId: string, trigger: TriggerRef, options?: {
|
|
89
|
+
limit?: number;
|
|
90
|
+
cursor?: string | null;
|
|
91
|
+
}): Promise<TriggerEventList>;
|
|
92
|
+
/** Every event of the last 7 days, newest first, fetched a page at a time. */
|
|
93
|
+
iterEvents(agentId: string, trigger: TriggerRef, options?: {
|
|
94
|
+
pageSize?: number;
|
|
95
|
+
}): AsyncGenerator<TriggerEventView, void, undefined>;
|
|
96
|
+
}
|