@senpi/runtime 3.0.22 → 3.0.24
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 +7 -4
- package/dist/actions/close-position/close-position.action.d.ts.map +1 -1
- package/dist/actions/close-position/close-position.action.js +8 -6
- package/dist/actions/close-position/close-position.action.js.map +1 -1
- package/dist/actions/decision-error-notification.d.ts +14 -0
- package/dist/actions/decision-error-notification.d.ts.map +1 -0
- package/dist/actions/decision-error-notification.js +36 -0
- package/dist/actions/decision-error-notification.js.map +1 -0
- package/dist/actions/open-position/open-position.action.d.ts.map +1 -1
- package/dist/actions/open-position/open-position.action.js +8 -6
- package/dist/actions/open-position/open-position.action.js.map +1 -1
- package/dist/actions/types.d.ts +2 -0
- package/dist/actions/types.d.ts.map +1 -1
- package/dist/cli/guide-commands.d.ts.map +1 -1
- package/dist/cli/guide-commands.js +5 -7
- package/dist/cli/guide-commands.js.map +1 -1
- package/dist/cli/senpi-cli-config.d.ts +0 -17
- package/dist/cli/senpi-cli-config.d.ts.map +1 -1
- package/dist/cli/senpi-cli-config.js +0 -30
- package/dist/cli/senpi-cli-config.js.map +1 -1
- package/dist/cli/senpi-config-commands.d.ts +1 -1
- package/dist/cli/senpi-config-commands.d.ts.map +1 -1
- package/dist/cli/senpi-config-commands.js +1 -16
- package/dist/cli/senpi-config-commands.js.map +1 -1
- package/dist/constants/dsl/index.d.ts +1 -5
- package/dist/constants/dsl/index.d.ts.map +1 -1
- package/dist/constants/dsl/index.js +1 -5
- package/dist/constants/dsl/index.js.map +1 -1
- package/dist/dsl/engine-client/event-mapping.d.ts +1 -1
- package/dist/dsl/engine-client/event-mapping.d.ts.map +1 -1
- package/dist/dsl/events/build-closed-event.d.ts +1 -1
- package/dist/dsl/events/build-closed-event.js +1 -1
- package/dist/dsl/events/handlers.js +1 -1
- package/dist/dsl/monitor/process-one-position.js +3 -3
- package/dist/dsl/monitor/process-one-position.js.map +1 -1
- package/dist/dsl/notifications/format-utils.d.ts +1 -11
- package/dist/dsl/notifications/format-utils.d.ts.map +1 -1
- package/dist/dsl/notifications/format-utils.js +1 -48
- package/dist/dsl/notifications/format-utils.js.map +1 -1
- package/dist/dsl/notifications/formatter.d.ts +9 -25
- package/dist/dsl/notifications/formatter.d.ts.map +1 -1
- package/dist/dsl/notifications/formatter.js +20 -105
- package/dist/dsl/notifications/formatter.js.map +1 -1
- package/dist/dsl/notifications/index.d.ts +2 -8
- package/dist/dsl/notifications/index.d.ts.map +1 -1
- package/dist/dsl/notifications/index.js +60 -57
- package/dist/dsl/notifications/index.js.map +1 -1
- package/dist/dsl/plugin/index.d.ts.map +1 -1
- package/dist/dsl/plugin/index.js +1 -27
- package/dist/dsl/plugin/index.js.map +1 -1
- package/dist/dsl/plugin/options.d.ts +3 -2
- package/dist/dsl/plugin/options.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -123
- package/dist/index.js.map +1 -1
- package/dist/prompt/session-context-seed-hook.d.ts +11 -0
- package/dist/prompt/session-context-seed-hook.d.ts.map +1 -0
- package/dist/prompt/session-context-seed-hook.js +99 -0
- package/dist/prompt/session-context-seed-hook.js.map +1 -0
- package/dist/runtime/auto-update/coordinator.d.ts +19 -7
- package/dist/runtime/auto-update/coordinator.d.ts.map +1 -1
- package/dist/runtime/auto-update/coordinator.js +122 -22
- package/dist/runtime/auto-update/coordinator.js.map +1 -1
- package/dist/runtime/create-action-context.d.ts.map +1 -1
- package/dist/runtime/create-action-context.js +1 -0
- package/dist/runtime/create-action-context.js.map +1 -1
- package/dist/runtime/create-runtime-context.d.ts +1 -0
- package/dist/runtime/create-runtime-context.d.ts.map +1 -1
- package/dist/runtime/create-runtime-context.js +1 -0
- package/dist/runtime/create-runtime-context.js.map +1 -1
- package/dist/runtime/decision-errors.d.ts +41 -53
- package/dist/runtime/decision-errors.d.ts.map +1 -1
- package/dist/runtime/decision-errors.js +48 -111
- package/dist/runtime/decision-errors.js.map +1 -1
- package/dist/runtime/notifications.d.ts +21 -14
- package/dist/runtime/notifications.d.ts.map +1 -1
- package/dist/runtime/notifications.js +192 -59
- package/dist/runtime/notifications.js.map +1 -1
- package/dist/runtime/runtime.d.ts +16 -2
- package/dist/runtime/runtime.d.ts.map +1 -1
- package/dist/runtime/runtime.js +106 -26
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/strategy-lifecycle.d.ts +5 -5
- package/dist/runtime/strategy-lifecycle.d.ts.map +1 -1
- package/dist/runtime/strategy-lifecycle.js +96 -28
- package/dist/runtime/strategy-lifecycle.js.map +1 -1
- package/dist/runtime/supervisor/long-running-supervisor.js +3 -3
- package/dist/runtime/supervisor/long-running-supervisor.js.map +1 -1
- package/dist/runtime-api/lifecycle.d.ts +1 -1
- package/dist/runtime-api/lifecycle.js +1 -1
- package/dist/scripts/run-dsl-standalone-live.d.ts +7 -6
- package/dist/scripts/run-dsl-standalone-live.d.ts.map +1 -1
- package/dist/scripts/run-dsl-standalone-live.js +25 -21
- package/dist/scripts/run-dsl-standalone-live.js.map +1 -1
- package/dist/skills-manager/coordinator.d.ts +2 -2
- package/dist/skills-manager/coordinator.js +2 -2
- package/dist/test-setup.d.ts +2 -0
- package/dist/test-setup.d.ts.map +1 -0
- package/dist/test-setup.js +23 -0
- package/dist/test-setup.js.map +1 -0
- package/dist/types/dsl/index.d.ts +1 -1
- package/dist/types/notification.d.ts +95 -1
- package/dist/types/notification.d.ts.map +1 -1
- package/dist/types/notification.js +76 -1
- package/dist/types/notification.js.map +1 -1
- package/dist/types/runtime.d.ts +6 -0
- package/dist/types/runtime.d.ts.map +1 -1
- package/dist/types/session-context.d.ts +19 -0
- package/dist/types/session-context.d.ts.map +1 -0
- package/dist/types/session-context.js +20 -0
- package/dist/types/session-context.js.map +1 -0
- package/dist/utils/event-catalog.d.ts +73 -0
- package/dist/utils/event-catalog.d.ts.map +1 -1
- package/dist/utils/event-catalog.js +22 -0
- package/dist/utils/event-catalog.js.map +1 -1
- package/dist/utils/logger.d.ts +2 -18
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +2 -40
- package/dist/utils/logger.js.map +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/dist/actions/notifications/formatter.d.ts +0 -39
- package/dist/actions/notifications/formatter.d.ts.map +0 -1
- package/dist/actions/notifications/formatter.js +0 -68
- package/dist/actions/notifications/formatter.js.map +0 -1
- package/dist/actions/notifications/index.d.ts +0 -37
- package/dist/actions/notifications/index.d.ts.map +0 -1
- package/dist/actions/notifications/index.js +0 -89
- package/dist/actions/notifications/index.js.map +0 -1
- package/dist/dsl/notifications/close-resolver.d.ts +0 -92
- package/dist/dsl/notifications/close-resolver.d.ts.map +0 -1
- package/dist/dsl/notifications/close-resolver.js +0 -309
- package/dist/dsl/notifications/close-resolver.js.map +0 -1
- package/dist/dsl/notifications/types.d.ts +0 -27
- package/dist/dsl/notifications/types.d.ts.map +0 -1
- package/dist/dsl/notifications/types.js +0 -5
- package/dist/dsl/notifications/types.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decision-errors.d.ts","sourceRoot":"","sources":["../../src/runtime/decision-errors.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"decision-errors.d.ts","sourceRoot":"","sources":["../../src/runtime/decision-errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAEjE,uEAAuE;AACvE,oBAAY,iBAAiB;IAC3B,8EAA8E;IAC9E,mBAAmB,0BAA0B;IAC7C,2EAA2E;IAC3E,kBAAkB,wBAAwB;IAC1C,mFAAmF;IACnF,qBAAqB,4BAA4B;IACjD,mFAAmF;IACnF,cAAc,oBAAoB;IAClC,uEAAuE;IACvE,uBAAuB,8BAA8B;IACrD,wEAAwE;IACxE,eAAe,s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BAAuB,CAiBjF;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAGhE"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Classification of LLM-decision failures into
|
|
2
|
+
* Classification of LLM-decision failures into a stable code, a retry flag, and
|
|
3
|
+
* a two-bucket user-facing message.
|
|
3
4
|
*
|
|
4
5
|
* ## Why this module exists
|
|
5
6
|
*
|
|
@@ -9,21 +10,25 @@
|
|
|
9
10
|
* need to make decisions from that string:
|
|
10
11
|
*
|
|
11
12
|
* 1. The **notification layer** ({@link formatDecisionErrorNotification} in
|
|
12
|
-
* `notifications.ts`) — what to tell the skill author
|
|
13
|
+
* `notifications.ts`) — what to tell the skill author.
|
|
13
14
|
* 2. The **decision client** (`openclaw-llm-decision.ts`) — whether a retry can
|
|
14
15
|
* plausibly succeed.
|
|
15
16
|
*
|
|
16
|
-
* ##
|
|
17
|
+
* ## Two pieces
|
|
17
18
|
*
|
|
18
|
-
* 1. {@link
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
19
|
+
* 1. {@link DECISION_ERROR_TABLE} — the ordered matchers (raw string → code)
|
|
20
|
+
* and the `retryable` flag. Per-code detail is preserved here for logs and
|
|
21
|
+
* telemetry, even though the two consumers above only see the collapsed
|
|
22
|
+
* bucket.
|
|
23
|
+
* 2. {@link classifyDecisionError} — walks the table, then renders the
|
|
24
|
+
* user-facing message from {@link DECISION_ERROR_BUCKET_COPY}, keyed only
|
|
25
|
+
* by `retryable` (see {@link decisionErrorBucket}). Author-facing copy
|
|
26
|
+
* does not vary by code — dozens of failure-mode-specific messages proved
|
|
27
|
+
* to be more than users act on; the two buckets are "this will likely
|
|
28
|
+
* sort itself out" vs. "this needs you to look at it."
|
|
24
29
|
*
|
|
25
|
-
* To change
|
|
26
|
-
*
|
|
30
|
+
* To change matching or retry behavior: edit {@link DECISION_ERROR_TABLE}.
|
|
31
|
+
* To change user-facing wording: edit {@link DECISION_ERROR_BUCKET_COPY}.
|
|
27
32
|
*
|
|
28
33
|
* ## Where the raw strings come from
|
|
29
34
|
*
|
|
@@ -89,79 +94,11 @@ export var DecisionErrorCode;
|
|
|
89
94
|
DecisionErrorCode["Unknown"] = "UNKNOWN";
|
|
90
95
|
})(DecisionErrorCode || (DecisionErrorCode = {}));
|
|
91
96
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
* with no supplied value is left verbatim so a missing var is visible, not silent.
|
|
98
|
-
*
|
|
99
|
-
* **This is the only place to edit copy.** Nothing else hardcodes a message.
|
|
100
|
-
*/
|
|
101
|
-
export const DECISION_ERROR_MESSAGES = {
|
|
102
|
-
[DecisionErrorCode.GatewayTokenMissing]: "Senpi: OpenClaw gateway token not configured. Set OPENCLAW_GATEWAY_TOKEN.",
|
|
103
|
-
[DecisionErrorCode.GatewayUnreachable]: "Senpi: OpenClaw Gateway is unreachable.",
|
|
104
|
-
[DecisionErrorCode.PluginEndpointMissing]: "Senpi: OpenClaw is missing the plugin endpoint. Please reinstall the plugin.",
|
|
105
|
-
[DecisionErrorCode.PromptRequired]: "Your agent can't trade until its template is fixed. Action `{name}` in your runtime YAML is " +
|
|
106
|
-
"missing a `decision_prompt`. To recover: delete this runtime, ask your OpenClaw agent to add a " +
|
|
107
|
-
"`decision_prompt` to that action, and install it again. If you didn't write this skill, contact " +
|
|
108
|
-
"Senpi support.",
|
|
109
|
-
[DecisionErrorCode.ProviderModelUnresolved]: "Your agent can't trade because the AI model `{model}` isn't recognized by your OpenClaw host. " +
|
|
110
|
-
"To recover: delete this runtime, set a valid `decision_model` in your runtime YAML, and install it " +
|
|
111
|
-
"again. If you didn't write this skill, contact Senpi support.",
|
|
112
|
-
[DecisionErrorCode.ModelNotAllowed]: "Your agent can't trade because `{model}` isn't on your OpenClaw host's allowed-models list. " +
|
|
113
|
-
"Allowed: `{list}`. To recover: pick a model from the allowed list (delete the runtime, edit " +
|
|
114
|
-
"`decision_model` in the runtime YAML, install again) or add it to your host's allowedModels config.",
|
|
115
|
-
[DecisionErrorCode.InputNotSerializable]: "Your agent hit an internal bug while building the AI request (data wasn't serializable). Please " +
|
|
116
|
-
"report this to Senpi support — it isn't something you can fix from your side.",
|
|
117
|
-
[DecisionErrorCode.LlmEmptyOutput]: "Your agent dropped one signal because the AI model returned no answer. This is usually a safety " +
|
|
118
|
-
"filter or a transient model quirk. If it keeps happening, try a different `decision_model` in your " +
|
|
119
|
-
"runtime YAML (delete the runtime, edit, reinstall) or rephrase your `decision_prompt` to be less " +
|
|
120
|
-
"ambiguous.",
|
|
121
|
-
[DecisionErrorCode.LlmInvalidJson]: "Your agent dropped one signal because the AI model's reply wasn't valid JSON — usually a truncation " +
|
|
122
|
-
"or a prompt that didn't force JSON output. To recover: tighten your `decision_prompt` in the runtime " +
|
|
123
|
-
"YAML to require strict JSON, then delete and reinstall the runtime. If you didn't write this skill, " +
|
|
124
|
-
"contact Senpi support.",
|
|
125
|
-
[DecisionErrorCode.LlmSchemaMismatch]: "Your agent dropped one signal because the AI model's reply was valid JSON but didn't match the " +
|
|
126
|
-
"expected shape: `{errors}`. To recover: tweak your `decision_prompt` so the model returns the " +
|
|
127
|
-
"required fields, or have your OpenClaw agent loosen the schema (delete the runtime, edit the YAML, " +
|
|
128
|
-
"reinstall). If you didn't write this skill, contact Senpi support.",
|
|
129
|
-
[DecisionErrorCode.ProviderError]: "Your agent dropped one signal because the AI provider rejected the call (e.g. rate limit or outage). " +
|
|
130
|
-
"Usually transient — the next signal often goes through. If it keeps happening, try switching " +
|
|
131
|
-
"providers or using a different `decision_model` in your runtime YAML.",
|
|
132
|
-
[DecisionErrorCode.Timeout]: "Your agent dropped one signal because the AI model didn't reply in 90 seconds. This is usually " +
|
|
133
|
-
"transient — the next signal often goes through. If it keeps happening, switch to a faster " +
|
|
134
|
-
"`decision_model` in your runtime YAML (delete the runtime, edit, reinstall).",
|
|
135
|
-
[DecisionErrorCode.EmbeddedAgentUnavailable]: "Your agent dropped one signal because OpenClaw's internal LLM helper failed to load on your host. " +
|
|
136
|
-
"This usually means the OpenClaw install is corrupted or partially upgraded. To recover: reinstall " +
|
|
137
|
-
"OpenClaw on your host (or upgrade to the latest version — this error no longer exists in v2026.5.7+). " +
|
|
138
|
-
"If it keeps happening after reinstall, contact Senpi support.",
|
|
139
|
-
[DecisionErrorCode.InvalidThinkingLevel]: "Your agent's runtime YAML uses an unknown thinking level (`{level}`). Valid options: `{hint}`. " +
|
|
140
|
-
"To recover: delete this runtime, set `thinking` to a valid value in the runtime YAML, and install it " +
|
|
141
|
-
"again. If you didn't write this skill, contact Senpi support.",
|
|
142
|
-
[DecisionErrorCode.ThinkingLevelUnsupported]: "Your agent's model (`{providerModel}`) doesn't support the thinking level `{level}`. Supported for " +
|
|
143
|
-
"this model: `{hint}`. To recover: delete this runtime, change either the model or the thinking level " +
|
|
144
|
-
"in the runtime YAML, and install it again.",
|
|
145
|
-
[DecisionErrorCode.PluginResponseShape]: "Your agent hit an internal bug parsing the AI model's response. Please report this to Senpi support " +
|
|
146
|
-
"— it isn't something you can fix from your side.",
|
|
147
|
-
[DecisionErrorCode.OpenClawUnexpected]: "Senpi: Signal Dropped - OpenClaw hit an unexpected error.",
|
|
148
|
-
[DecisionErrorCode.Unknown]: "Senpi: Trading decision failed — {raw}",
|
|
149
|
-
};
|
|
150
|
-
/** Trim a captured token; falls back to `fallback` when empty/absent. */
|
|
151
|
-
function clean(value, fallback) {
|
|
152
|
-
const t = value?.trim();
|
|
153
|
-
return t && t.length > 0 ? t : fallback;
|
|
154
|
-
}
|
|
155
|
-
/** Fill `{token}` placeholders from `vars`; unknown tokens are left verbatim. */
|
|
156
|
-
function renderTemplate(template, vars) {
|
|
157
|
-
return template.replace(/\{(\w+)\}/g, (whole, key) => Object.prototype.hasOwnProperty.call(vars, key) ? vars[key] : whole);
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Ordered classification table — matchers + retry flag + template-variable logic.
|
|
161
|
-
* First match wins, so keep specific matchers above generic ones (e.g.
|
|
162
|
-
* `LlmEmptyOutput` before the catch-all `ProviderError`, since both can appear
|
|
163
|
-
* inside a `"rejected request: ..."` wrapper). Copy lives in
|
|
164
|
-
* {@link DECISION_ERROR_MESSAGES}, not here.
|
|
97
|
+
* Ordered classification table — matchers + retry flag. First match wins, so
|
|
98
|
+
* keep specific matchers above generic ones (e.g. `LlmEmptyOutput` before the
|
|
99
|
+
* catch-all `ProviderError`, since both can appear inside a `"rejected
|
|
100
|
+
* request: ..."` wrapper). `code` and `retryable` are the source of truth for
|
|
101
|
+
* logs/telemetry; user-facing copy lives in {@link DECISION_ERROR_BUCKET_COPY}.
|
|
165
102
|
*/
|
|
166
103
|
export const DECISION_ERROR_TABLE = [
|
|
167
104
|
// ── Pre-HTTP / infra (not retryable) ──────────────────────────────────────
|
|
@@ -185,22 +122,16 @@ export const DECISION_ERROR_TABLE = [
|
|
|
185
122
|
code: DecisionErrorCode.PromptRequired,
|
|
186
123
|
match: (s) => /prompt required/i.test(s),
|
|
187
124
|
retryable: false,
|
|
188
|
-
vars: (_caps, ctx) => ({ name: clean(ctx.actionName, "<name>") }),
|
|
189
125
|
},
|
|
190
126
|
{
|
|
191
127
|
code: DecisionErrorCode.ProviderModelUnresolved,
|
|
192
128
|
match: (s) => s.match(/provider\/model could not be resolved \(provider=(.*?), model=(.*?)\)/),
|
|
193
129
|
retryable: false,
|
|
194
|
-
vars: (caps, ctx) => ({ model: clean(caps?.[2], clean(ctx.model, "your configured model")) }),
|
|
195
130
|
},
|
|
196
131
|
{
|
|
197
132
|
code: DecisionErrorCode.ModelNotAllowed,
|
|
198
133
|
match: (s) => s.match(/Model not allowed by llm-task plugin config:\s*([^.]+)\.\s*Allowed models:\s*([^"}]+)/),
|
|
199
134
|
retryable: false,
|
|
200
|
-
vars: (caps, ctx) => ({
|
|
201
|
-
model: clean(caps?.[1], clean(ctx.model, "that model")),
|
|
202
|
-
list: clean(caps?.[2], "(see your host's allowedModels config)"),
|
|
203
|
-
}),
|
|
204
135
|
},
|
|
205
136
|
{
|
|
206
137
|
code: DecisionErrorCode.InputNotSerializable,
|
|
@@ -225,27 +156,17 @@ export const DECISION_ERROR_TABLE = [
|
|
|
225
156
|
code: DecisionErrorCode.LlmSchemaMismatch,
|
|
226
157
|
match: (s) => s.match(/LLM JSON did not match schema:\s*([^"}]+)/),
|
|
227
158
|
retryable: false,
|
|
228
|
-
vars: (caps) => ({ errors: clean(caps?.[1], "(schema validation failed)") }),
|
|
229
159
|
},
|
|
230
160
|
// ── Thinking-level misconfig (v2026.5.7+, not retryable) ──────────────────
|
|
231
161
|
{
|
|
232
162
|
code: DecisionErrorCode.InvalidThinkingLevel,
|
|
233
163
|
match: (s) => s.match(/Invalid thinking level "(.*?)"\.\s*Use one of:\s*([^"}]+?)\./),
|
|
234
164
|
retryable: false,
|
|
235
|
-
vars: (caps) => ({
|
|
236
|
-
level: clean(caps?.[1], "that value"),
|
|
237
|
-
hint: clean(caps?.[2], "the supported levels"),
|
|
238
|
-
}),
|
|
239
165
|
},
|
|
240
166
|
{
|
|
241
167
|
code: DecisionErrorCode.ThinkingLevelUnsupported,
|
|
242
168
|
match: (s) => s.match(/Thinking level "(.*?)" is not supported for (.+?)\.\s*Use one of:\s*([^"}]+?)\./),
|
|
243
169
|
retryable: false,
|
|
244
|
-
vars: (caps, ctx) => ({
|
|
245
|
-
level: clean(caps?.[1], "that level"),
|
|
246
|
-
providerModel: clean(caps?.[2], clean(ctx.model, "this model")),
|
|
247
|
-
hint: clean(caps?.[3], "the supported levels"),
|
|
248
|
-
}),
|
|
249
170
|
},
|
|
250
171
|
// ── Host/load failure (not retryable) ─────────────────────────────────────
|
|
251
172
|
{
|
|
@@ -284,35 +205,51 @@ export const DECISION_ERROR_TABLE = [
|
|
|
284
205
|
retryable: false,
|
|
285
206
|
},
|
|
286
207
|
];
|
|
208
|
+
/** Map a classified error's retry flag to its user-facing bucket. */
|
|
209
|
+
export function decisionErrorBucket(retryable) {
|
|
210
|
+
return retryable ? "transient" : "attention";
|
|
211
|
+
}
|
|
212
|
+
/** Label-free copy for each bucket — the emit site applies the `[strategy]` prefix. */
|
|
213
|
+
export const DECISION_ERROR_BUCKET_COPY = {
|
|
214
|
+
transient: {
|
|
215
|
+
pushTitle: "⚠️ Signal skipped",
|
|
216
|
+
pushBody: "Skipped a signal (transient) — still running, next one will go",
|
|
217
|
+
inApp: "⚠️ Skipped one trade signal — a brief issue deciding the trade. Still running; it'll take the next one. " +
|
|
218
|
+
"We've logged it — contact support and we'll help fix it.",
|
|
219
|
+
},
|
|
220
|
+
attention: {
|
|
221
|
+
pushTitle: "⚠️ Needs attention",
|
|
222
|
+
pushBody: "Your strategy needs attention before it can trade",
|
|
223
|
+
inApp: "⚠️ Your strategy needs attention before it can trade. We've logged it — contact support and we'll help fix it.",
|
|
224
|
+
},
|
|
225
|
+
};
|
|
287
226
|
/**
|
|
288
227
|
* Classify a raw LLM-decision error string into a {@link ClassifiedDecisionError}.
|
|
289
228
|
*
|
|
290
|
-
* Walks {@link DECISION_ERROR_TABLE} in order; the first matching entry wins
|
|
291
|
-
*
|
|
292
|
-
*
|
|
229
|
+
* Walks {@link DECISION_ERROR_TABLE} in order; the first matching entry wins,
|
|
230
|
+
* giving `code` + `retryable` (preserved for logs/telemetry). If nothing
|
|
231
|
+
* matches, returns {@link DecisionErrorCode.Unknown} (not retryable). The
|
|
232
|
+
* user-facing `userMessage` is always the collapsed bucket's in-app copy from
|
|
233
|
+
* {@link DECISION_ERROR_BUCKET_COPY} — it does not vary by code.
|
|
293
234
|
*
|
|
294
235
|
* @param rawMessage - The error string thrown by the decision client (may embed an
|
|
295
236
|
* OpenClaw gateway message). Non-string / empty inputs are coerced safely.
|
|
296
|
-
* @param ctx - Optional plugin-side context for placeholders the gateway can't supply.
|
|
297
237
|
*/
|
|
298
|
-
export function classifyDecisionError(rawMessage
|
|
238
|
+
export function classifyDecisionError(rawMessage) {
|
|
299
239
|
const raw = typeof rawMessage === "string" ? rawMessage : String(rawMessage ?? "");
|
|
300
240
|
for (const entry of DECISION_ERROR_TABLE) {
|
|
301
|
-
|
|
302
|
-
if (!result)
|
|
241
|
+
if (!entry.match(raw))
|
|
303
242
|
continue;
|
|
304
|
-
const caps = Array.isArray(result) ? result : null;
|
|
305
|
-
const vars = entry.vars ? entry.vars(caps, ctx, raw) : {};
|
|
306
243
|
return {
|
|
307
244
|
code: entry.code,
|
|
308
245
|
retryable: entry.retryable,
|
|
309
|
-
userMessage:
|
|
246
|
+
userMessage: DECISION_ERROR_BUCKET_COPY[decisionErrorBucket(entry.retryable)].inApp,
|
|
310
247
|
};
|
|
311
248
|
}
|
|
312
249
|
return {
|
|
313
250
|
code: DecisionErrorCode.Unknown,
|
|
314
251
|
retryable: false,
|
|
315
|
-
userMessage:
|
|
252
|
+
userMessage: DECISION_ERROR_BUCKET_COPY.attention.inApp,
|
|
316
253
|
};
|
|
317
254
|
}
|
|
318
255
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decision-errors.js","sourceRoot":"","sources":["../../src/runtime/decision-errors.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"decision-errors.js","sourceRoot":"","sources":["../../src/runtime/decision-errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AAIH,uEAAuE;AACvE,MAAM,CAAN,IAAY,iBAqCX;AArCD,WAAY,iBAAiB;IAC3B,8EAA8E;IAC9E,kEAA6C,CAAA;IAC7C,2EAA2E;IAC3E,+DAA0C,CAAA;IAC1C,mFAAmF;IACnF,sEAAiD,CAAA;IACjD,mFAAmF;IACnF,uDAAkC,CAAA;IAClC,uEAAuE;IACvE,0EAAqD,CAAA;IACrD,wEAAwE;IACxE,0DAAqC,CAAA;IAC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,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvE,OAAO,qBAAqB,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC;AAClD,CAAC"}
|
|
@@ -1,33 +1,40 @@
|
|
|
1
1
|
import type { McpTransport } from "../senpi/types.js";
|
|
2
2
|
import type { NotificationService } from "../types/notification.js";
|
|
3
|
-
import { type DecisionErrorContext } from "./decision-errors.js";
|
|
4
3
|
export interface NotificationServiceOptions {
|
|
5
|
-
telegram_chat_id?: string;
|
|
6
4
|
mcpTransport?: McpTransport;
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
/** Override for the `NOTIFICATIONS_INGEST_URL` env (tests / non-standard hosting). */
|
|
6
|
+
ingest_url?: string;
|
|
7
|
+
/** The runtime's own Senpi auth token (MCP bearer). Doubles as the ingest-endpoint
|
|
8
|
+
* bearer credential and, via its `senpi_user_id` claim, the recipient every
|
|
9
|
+
* outgoing notification is stamped with. */
|
|
10
|
+
senpi_auth_token?: string;
|
|
11
|
+
/** Override the per-request timeout in ms (tests). */
|
|
12
|
+
ingest_timeout_ms?: number;
|
|
9
13
|
[key: string]: unknown;
|
|
10
14
|
}
|
|
11
15
|
/**
|
|
12
|
-
* Map a raw LLM-decision error string to
|
|
16
|
+
* Map a raw LLM-decision error string to a user-facing notification message.
|
|
13
17
|
*
|
|
14
|
-
* Thin wrapper over {@link classifyDecisionError} —
|
|
18
|
+
* Thin wrapper over {@link classifyDecisionError} — the two-bucket copy and the
|
|
15
19
|
* failure-mode lookup live in `decision-errors.ts` (the single source of truth
|
|
16
20
|
* shared with the retry logic in `openclaw-llm-decision.ts`). The runtime catches
|
|
17
21
|
* errors from the LLM-decision call and passes `err.message` here.
|
|
18
22
|
*
|
|
19
23
|
* @param rawMessage - Error message thrown by the decision client (may embed an
|
|
20
24
|
* OpenClaw gateway message).
|
|
21
|
-
* @param ctx - Optional plugin-side context (action name, configured model) for
|
|
22
|
-
* placeholders the gateway error string cannot supply.
|
|
23
25
|
*/
|
|
24
|
-
export declare function formatDecisionErrorNotification(rawMessage: string
|
|
26
|
+
export declare function formatDecisionErrorNotification(rawMessage: string): string;
|
|
25
27
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
28
|
+
* Create the runtime's notification service. Every notification is delivered by
|
|
29
|
+
* POSTing the full structured envelope to the authenticated notification-ingest
|
|
30
|
+
* endpoint (`NOTIFICATIONS_INGEST_URL`) — there is no other delivery path. Missing
|
|
31
|
+
* configuration is a startup error (thrown here, not discovered later as silent
|
|
32
|
+
* notification loss), so callers must construct this before a runtime starts
|
|
33
|
+
* trading, not lazily on first notify.
|
|
34
|
+
*
|
|
35
|
+
* Failure paths inside this service log at warn, not error: a delivery failure is a
|
|
36
|
+
* handled, degraded condition — the caller's notify() contract is fire-and-forget and
|
|
37
|
+
* the next notification retries the transport fresh.
|
|
31
38
|
*/
|
|
32
39
|
export declare function createNotificationService(options?: NotificationServiceOptions): NotificationService;
|
|
33
40
|
//# sourceMappingURL=notifications.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notifications.d.ts","sourceRoot":"","sources":["../../src/runtime/notifications.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"notifications.d.ts","sourceRoot":"","sources":["../../src/runtime/notifications.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAyC,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AA+B3G,MAAM,WAAW,0BAA0B;IACzC,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,sFAAsF;IACtF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;gDAE4C;IAC5C,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,sDAAsD;IACtD,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,+BAA+B,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAE1E;AA8FD;;;;;;;;;;;GAWG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,CAAC,EAAE,0BAA0B,GAAG,mBAAmB,CAsHnG"}
|