@primusclaw/personal-agent-runtime 0.9.0 → 0.10.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/dist/index.js +83 -53
- package/dist/types/claw/client.d.ts +2 -2
- package/dist/types/claw/sessions.d.ts +1 -1
- package/dist/types/config/aliases.d.ts +18 -9
- package/dist/types/config/index.d.ts +1 -1
- package/dist/types/github/feedback-config.d.ts +2 -0
- package/dist/types/github/feedback-issues.d.ts +7 -1
- package/dist/types/github/intent-reader.d.ts +2 -0
- package/dist/types/metrics/index.d.ts +1 -1
- package/dist/types/metrics/prometheus-metrics.d.ts +15 -4
- package/dist/worker.js +24 -12
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1319,7 +1319,7 @@ var HttpSkills = class {
|
|
|
1319
1319
|
};
|
|
1320
1320
|
|
|
1321
1321
|
// packages/runtime/src/claw/client.ts
|
|
1322
|
-
var DEFAULT_CLIENT_LABEL = "
|
|
1322
|
+
var DEFAULT_CLIENT_LABEL = "personal-agent";
|
|
1323
1323
|
function createClawClient(options) {
|
|
1324
1324
|
const http = new ClawHttp(options.baseUrl, options.fetch ?? ((url, init) => fetch(url, init)));
|
|
1325
1325
|
const toolId = options.ruleToolId ?? null;
|
|
@@ -1545,6 +1545,8 @@ import {
|
|
|
1545
1545
|
own as own2
|
|
1546
1546
|
} from "@primusclaw/personal-agent";
|
|
1547
1547
|
var CONTENT_TYPE = "text/plain; version=0.0.4; charset=utf-8";
|
|
1548
|
+
var METRIC_PREFIX = "personal_agent_";
|
|
1549
|
+
var LEGACY_METRIC_PREFIX = "clawy_";
|
|
1548
1550
|
var LAG_WINDOW_MS = 6e4;
|
|
1549
1551
|
var EVENT_BUCKETS = [0.5, 1, 2, 3, 5, 10, 30, 60];
|
|
1550
1552
|
var ALERTED = [
|
|
@@ -1568,27 +1570,30 @@ var ALERTED = [
|
|
|
1568
1570
|
["key_unlinked", [["reason", "rejected"]]]
|
|
1569
1571
|
];
|
|
1570
1572
|
var HELP = {
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1573
|
+
personal_agent_security_events_total: ["counter", "Security events logged by the worker, by event and category."],
|
|
1574
|
+
personal_agent_inbound_handled_total: ["counter", "Inbound messages handled (completed or abandoned)."],
|
|
1575
|
+
personal_agent_inbound_failed_total: [
|
|
1574
1576
|
"counter",
|
|
1575
1577
|
"Inbound messages whose handler failed and that were abandoned for redelivery."
|
|
1576
1578
|
],
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
+
personal_agent_inbound_handle_ms_total: ["counter", "Milliseconds spent handling inbound messages, summed."],
|
|
1580
|
+
personal_agent_inbound_lag_max_ms: [
|
|
1579
1581
|
"gauge",
|
|
1580
1582
|
"Longest time a message handled in the last 60 seconds waited in the inbound queue."
|
|
1581
1583
|
],
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
+
personal_agent_inbound_limited_total: ["counter", "Messages and tasks refused by a per-user limit, by reason."],
|
|
1585
|
+
personal_agent_event_handle_seconds: [
|
|
1584
1586
|
"histogram",
|
|
1585
1587
|
"Seconds from receiving a Claw event to having sent it to the chat, by event type."
|
|
1586
1588
|
],
|
|
1587
|
-
|
|
1589
|
+
personal_agent_event_to_chat_seconds: [
|
|
1588
1590
|
"histogram",
|
|
1589
1591
|
"Seconds from when Claw says an event happened to having sent it to the chat, by event type."
|
|
1590
1592
|
],
|
|
1591
|
-
|
|
1593
|
+
personal_agent_files_dropped_total: [
|
|
1594
|
+
"counter",
|
|
1595
|
+
"Files a user sent that did not reach Claw, by where they were dropped."
|
|
1596
|
+
]
|
|
1592
1597
|
};
|
|
1593
1598
|
function compareTuples(a, b) {
|
|
1594
1599
|
for (let i = 0; i < Math.min(a.length, b.length); i++) {
|
|
@@ -1671,49 +1676,54 @@ var PrometheusMetrics = class {
|
|
|
1671
1676
|
expire(now) {
|
|
1672
1677
|
while ((this.lags[0]?.[0] ?? Infinity) <= now - this.lagWindowMs) this.lags.shift();
|
|
1673
1678
|
}
|
|
1674
|
-
/**
|
|
1679
|
+
/**
|
|
1680
|
+
* All series in the Prometheus text exposition format (version 0.0.4): under their names, then, with the same values and
|
|
1681
|
+
* help, under the deprecated names of an earlier release (that half is the text it wrote, byte for byte).
|
|
1682
|
+
*/
|
|
1675
1683
|
render() {
|
|
1684
|
+
const lagMaxMs = this.lagMaxMs();
|
|
1685
|
+
return this.renderAs(METRIC_PREFIX, lagMaxMs) + this.renderAs(LEGACY_METRIC_PREFIX, lagMaxMs);
|
|
1686
|
+
}
|
|
1687
|
+
renderAs(prefix, lagMaxMs) {
|
|
1676
1688
|
const lines = [];
|
|
1677
|
-
const
|
|
1678
|
-
|
|
1679
|
-
|
|
1689
|
+
const named = (stem) => prefix + stem;
|
|
1690
|
+
const head2 = (stem) => {
|
|
1691
|
+
const [kind, text3] = own2(HELP, METRIC_PREFIX + stem) ?? ["untyped", ""];
|
|
1692
|
+
lines.push(`# HELP ${named(stem)} ${text3}`, `# TYPE ${named(stem)} ${kind}`);
|
|
1680
1693
|
};
|
|
1681
|
-
head2("
|
|
1694
|
+
head2("security_events_total");
|
|
1682
1695
|
const events = [...this.events.values()].sort(
|
|
1683
1696
|
(a, b) => compareTuples([a.event, ...a.labels.flat()], [b.event, ...b.labels.flat()])
|
|
1684
1697
|
);
|
|
1685
1698
|
for (const { event, labels, value } of events) {
|
|
1686
1699
|
const pairs = [["event", event], ...labels].map(([k, v]) => `${k}="${v}"`).join(",");
|
|
1687
|
-
lines.push(
|
|
1700
|
+
lines.push(`${named("security_events_total")}{${pairs}} ${String(value)}`);
|
|
1688
1701
|
}
|
|
1689
1702
|
const plain = [
|
|
1690
|
-
["
|
|
1691
|
-
["
|
|
1692
|
-
["
|
|
1693
|
-
["
|
|
1703
|
+
["inbound_handled_total", this.handledCount],
|
|
1704
|
+
["inbound_failed_total", this.failedCount],
|
|
1705
|
+
["inbound_handle_ms_total", this.handleMsTotal],
|
|
1706
|
+
["inbound_lag_max_ms", lagMaxMs]
|
|
1694
1707
|
];
|
|
1695
|
-
for (const [
|
|
1696
|
-
head2(
|
|
1697
|
-
lines.push(`${
|
|
1708
|
+
for (const [stem, value] of plain) {
|
|
1709
|
+
head2(stem);
|
|
1710
|
+
lines.push(`${named(stem)} ${String(value)}`);
|
|
1698
1711
|
}
|
|
1699
|
-
head2("
|
|
1712
|
+
head2("inbound_limited_total");
|
|
1700
1713
|
for (const [reason, value] of [...this.limits].sort(([a], [b]) => compareTuples([a], [b]))) {
|
|
1701
|
-
lines.push(
|
|
1702
|
-
}
|
|
1703
|
-
this.renderHistograms(lines, head2);
|
|
1704
|
-
head2("clawy_files_dropped_total");
|
|
1705
|
-
for (const [path, value] of [...this.dropped].sort(([a], [b]) => compareTuples([a], [b]))) {
|
|
1706
|
-
lines.push(`clawy_files_dropped_total{path="${path}"} ${String(value)}`);
|
|
1714
|
+
lines.push(`${named("inbound_limited_total")}{reason="${reason}"} ${String(value)}`);
|
|
1707
1715
|
}
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
renderHistograms(lines, head2) {
|
|
1711
|
-
["clawy_event_handle_seconds", "clawy_event_to_chat_seconds"].forEach((name, position) => {
|
|
1712
|
-
head2(name);
|
|
1716
|
+
["event_handle_seconds", "event_to_chat_seconds"].forEach((stem, position) => {
|
|
1717
|
+
head2(stem);
|
|
1713
1718
|
for (const type of DELIVERED_EVENT_TYPES) {
|
|
1714
|
-
lines.push(...this.eventTimes.get(type)?.[position]?.lines(
|
|
1719
|
+
lines.push(...this.eventTimes.get(type)?.[position]?.lines(named(stem), `type="${type}"`) ?? []);
|
|
1715
1720
|
}
|
|
1716
1721
|
});
|
|
1722
|
+
head2("files_dropped_total");
|
|
1723
|
+
for (const [path, value] of [...this.dropped].sort(([a], [b]) => compareTuples([a], [b]))) {
|
|
1724
|
+
lines.push(`${named("files_dropped_total")}{path="${path}"} ${String(value)}`);
|
|
1725
|
+
}
|
|
1726
|
+
return lines.join("\n") + "\n";
|
|
1717
1727
|
}
|
|
1718
1728
|
};
|
|
1719
1729
|
|
|
@@ -1957,9 +1967,13 @@ var ALIASED_SETTINGS = [
|
|
|
1957
1967
|
"LIMIT_APPROVAL",
|
|
1958
1968
|
"LIMIT_REMOTE_AGENT"
|
|
1959
1969
|
];
|
|
1960
|
-
var
|
|
1961
|
-
|
|
1962
|
-
|
|
1970
|
+
var MODEL_SETTING_PREFIX = "PERSONAL_AGENT_";
|
|
1971
|
+
var LEGACY_MODEL_SETTING_PREFIX = "CLAWY_";
|
|
1972
|
+
var MODEL_SETTINGS = ["MODEL", "FALLBACK_MODEL", "REVIEW_MODEL"];
|
|
1973
|
+
var SETTING_ALIASES = new Map([
|
|
1974
|
+
...ALIASED_SETTINGS.map((stem) => [SETTING_PREFIX + stem, LEGACY_SETTING_PREFIX + stem]),
|
|
1975
|
+
...MODEL_SETTINGS.map((stem) => [MODEL_SETTING_PREFIX + stem, LEGACY_MODEL_SETTING_PREFIX + stem])
|
|
1976
|
+
]);
|
|
1963
1977
|
var NEUTRAL_OF = new Map([...SETTING_ALIASES].map(([neutral, old]) => [old, neutral]));
|
|
1964
1978
|
var isSet = (env, name) => pyStrip4(own3(env, name) ?? "") !== "";
|
|
1965
1979
|
function settingSource(env, name) {
|
|
@@ -1984,7 +1998,7 @@ function warnLegacySettings(env, logger) {
|
|
|
1984
1998
|
const read2 = used.filter((s) => !s.ignored);
|
|
1985
1999
|
if (read2.length > 0) {
|
|
1986
2000
|
logger.warn(
|
|
1987
|
-
`deprecated setting names: ${read2.map((s) => `${s.legacy} (now ${s.neutral})`).join(", ")}; they still work, the
|
|
2001
|
+
`deprecated setting names: ${read2.map((s) => `${s.legacy} (now ${s.neutral})`).join(", ")}; they still work, the new names take precedence`,
|
|
1988
2002
|
{ settings: read2.map((s) => s.legacy).join(",") }
|
|
1989
2003
|
);
|
|
1990
2004
|
}
|
|
@@ -2144,6 +2158,7 @@ var EnvSecretSource = class {
|
|
|
2144
2158
|
|
|
2145
2159
|
// packages/runtime/src/config/settings.ts
|
|
2146
2160
|
import {
|
|
2161
|
+
BOT_NAME,
|
|
2147
2162
|
ConfigError as ConfigError2,
|
|
2148
2163
|
DEFAULT_MAX_CONCURRENT_TASKS,
|
|
2149
2164
|
DEFAULT_MESSAGE_LIMIT,
|
|
@@ -2174,6 +2189,7 @@ function readSettings(env, secrets = /* @__PURE__ */ new Map()) {
|
|
|
2174
2189
|
publicBaseUrl,
|
|
2175
2190
|
listenPort,
|
|
2176
2191
|
metricsPort,
|
|
2192
|
+
botName: read2.text("PERSONAL_AGENT_BOT_NAME") || BOT_NAME,
|
|
2177
2193
|
claw: {
|
|
2178
2194
|
pluginId: read2.optionalInt("CLAW_PLUGIN_ID"),
|
|
2179
2195
|
ruleToolId: read2.optionalInt("CLAW_RULE_TOOL_ID"),
|
|
@@ -2181,9 +2197,9 @@ function readSettings(env, secrets = /* @__PURE__ */ new Map()) {
|
|
|
2181
2197
|
},
|
|
2182
2198
|
exchange,
|
|
2183
2199
|
models: {
|
|
2184
|
-
chat: read2.text("
|
|
2185
|
-
fallback: read2.text("
|
|
2186
|
-
review: read2.text("
|
|
2200
|
+
chat: read2.text("PERSONAL_AGENT_MODEL"),
|
|
2201
|
+
fallback: read2.text("PERSONAL_AGENT_FALLBACK_MODEL"),
|
|
2202
|
+
review: read2.text("PERSONAL_AGENT_REVIEW_MODEL")
|
|
2187
2203
|
},
|
|
2188
2204
|
githubReview: githubReviewSettings(read2, publicBaseUrl),
|
|
2189
2205
|
assistant: assistantSettings(read2),
|
|
@@ -2260,7 +2276,7 @@ function githubReviewSettings(read2, publicBaseUrl) {
|
|
|
2260
2276
|
return {
|
|
2261
2277
|
enabled,
|
|
2262
2278
|
owners,
|
|
2263
|
-
intentModel: enabled ? read2.text("PA_REVIEW_INTENT_MODEL") || read2.text("
|
|
2279
|
+
intentModel: enabled ? read2.text("PA_REVIEW_INTENT_MODEL") || read2.text("PERSONAL_AGENT_MODEL") : "",
|
|
2264
2280
|
credentialUrl: enabled ? withoutTrailingSlash(read2.raw("PA_GITHUB_CREDENTIAL_URL", `${publicBaseUrl}/oauth/external-credentials`)) : "",
|
|
2265
2281
|
clientId: read2.text("PA_GITHUB_CLIENT_ID", GITHUB_CLI_CLIENT_ID) || GITHUB_CLI_CLIENT_ID
|
|
2266
2282
|
};
|
|
@@ -5723,13 +5739,16 @@ var GatewayIntentReader = class {
|
|
|
5723
5739
|
url;
|
|
5724
5740
|
fetchImpl;
|
|
5725
5741
|
read(key2, text3, mentions, channel) {
|
|
5726
|
-
return this.complete(key2, intentPrompt(channel), { message: text3, mentions });
|
|
5742
|
+
return this.complete(key2, intentPrompt(channel, this.options.botName), { message: text3, mentions });
|
|
5727
5743
|
}
|
|
5728
5744
|
readMode(key2, text3, channel) {
|
|
5729
|
-
return this.complete(key2, modePrompt(channel), { message: text3 });
|
|
5745
|
+
return this.complete(key2, modePrompt(channel, this.options.botName), { message: text3 });
|
|
5730
5746
|
}
|
|
5731
5747
|
readAnswer(key2, text3, pending, channel) {
|
|
5732
|
-
return this.complete(key2, answerPrompt(channel), {
|
|
5748
|
+
return this.complete(key2, answerPrompt(channel, this.options.botName), {
|
|
5749
|
+
message: text3,
|
|
5750
|
+
waiting_for_this_person: pending
|
|
5751
|
+
});
|
|
5733
5752
|
}
|
|
5734
5753
|
async complete(key2, system, payload) {
|
|
5735
5754
|
const body = {
|
|
@@ -5838,11 +5857,14 @@ import { ConfigError as ConfigError3 } from "@primusclaw/personal-agent";
|
|
|
5838
5857
|
// packages/runtime/src/github/feedback-issues.ts
|
|
5839
5858
|
import {
|
|
5840
5859
|
err as err4,
|
|
5841
|
-
ok as ok4
|
|
5860
|
+
ok as ok4,
|
|
5861
|
+
PERSISTED_FEEDBACK_LABEL
|
|
5842
5862
|
} from "@primusclaw/personal-agent";
|
|
5843
|
-
var FEEDBACK_LABEL =
|
|
5863
|
+
var FEEDBACK_LABEL = PERSISTED_FEEDBACK_LABEL;
|
|
5844
5864
|
var LABEL_COLOR = "d93f0b";
|
|
5845
|
-
|
|
5865
|
+
function labelDescription(botName) {
|
|
5866
|
+
return `Reported by a user from Teams through ${botName}`;
|
|
5867
|
+
}
|
|
5846
5868
|
function isoSeconds(epochMs) {
|
|
5847
5869
|
return `${new Date(Math.floor(epochMs / 1e3) * 1e3).toISOString().slice(0, 19)}Z`;
|
|
5848
5870
|
}
|
|
@@ -5871,14 +5893,16 @@ function bodyOf(value) {
|
|
|
5871
5893
|
return typeof body === "string" ? body : "";
|
|
5872
5894
|
}
|
|
5873
5895
|
var GithubIssueSink = class {
|
|
5874
|
-
constructor(api, repo, log) {
|
|
5896
|
+
constructor(api, repo, log, botName) {
|
|
5875
5897
|
this.api = api;
|
|
5876
5898
|
this.log = log;
|
|
5899
|
+
this.botName = botName;
|
|
5877
5900
|
const [owner = "", name = ""] = repo.split("/");
|
|
5878
5901
|
this.repoPath = `/repos/${segment2(owner)}/${segment2(name)}`;
|
|
5879
5902
|
}
|
|
5880
5903
|
api;
|
|
5881
5904
|
log;
|
|
5905
|
+
botName;
|
|
5882
5906
|
labelReady = false;
|
|
5883
5907
|
repoPath;
|
|
5884
5908
|
async createIssue(title, body, labels) {
|
|
@@ -5951,7 +5975,7 @@ var GithubIssueSink = class {
|
|
|
5951
5975
|
const made = await this.api.request({
|
|
5952
5976
|
method: "POST",
|
|
5953
5977
|
path: `${this.repoPath}/labels`,
|
|
5954
|
-
body: { name: FEEDBACK_LABEL, color: LABEL_COLOR, description:
|
|
5978
|
+
body: { name: FEEDBACK_LABEL, color: LABEL_COLOR, description: labelDescription(this.botName) }
|
|
5955
5979
|
});
|
|
5956
5980
|
if (made.status === 201 || made.status === 422)
|
|
5957
5981
|
this.labelReady = true;
|
|
@@ -6006,7 +6030,7 @@ function feedbackSink(config, options) {
|
|
|
6006
6030
|
options.log.warn("feedback: GitHub App token failed; falling back to the token file", { code });
|
|
6007
6031
|
});
|
|
6008
6032
|
const api = new GithubApi({ apiUrl: config.apiUrl, tokens, ...options.fetch ? { fetch: options.fetch } : {} });
|
|
6009
|
-
return new GithubIssueSink(api, config.repo, options.log);
|
|
6033
|
+
return new GithubIssueSink(api, config.repo, options.log, options.botName);
|
|
6010
6034
|
}
|
|
6011
6035
|
|
|
6012
6036
|
// packages/runtime/src/github/feedback-worker.ts
|
|
@@ -6133,11 +6157,16 @@ export {
|
|
|
6133
6157
|
IdentityCredentialClient,
|
|
6134
6158
|
InvalidToken,
|
|
6135
6159
|
LAG_WINDOW_MS,
|
|
6160
|
+
LEGACY_METRIC_PREFIX,
|
|
6161
|
+
LEGACY_MODEL_SETTING_PREFIX,
|
|
6136
6162
|
LEGACY_SETTING_PREFIX,
|
|
6137
6163
|
LINK_HASH_LABEL,
|
|
6138
6164
|
MAX_BODY_BYTES,
|
|
6139
6165
|
MAX_DEVICE_WAIT_SECONDS,
|
|
6140
6166
|
MAX_SKEW_SECONDS,
|
|
6167
|
+
METRIC_PREFIX,
|
|
6168
|
+
MODEL_SETTINGS,
|
|
6169
|
+
MODEL_SETTING_PREFIX,
|
|
6141
6170
|
MultiFernet,
|
|
6142
6171
|
NOT_BOUND_TTL_SECONDS,
|
|
6143
6172
|
PREFIX,
|
|
@@ -6170,6 +6199,7 @@ export {
|
|
|
6170
6199
|
hashLinkCode,
|
|
6171
6200
|
healthzRoute,
|
|
6172
6201
|
json,
|
|
6202
|
+
labelDescription,
|
|
6173
6203
|
legacySettings,
|
|
6174
6204
|
lineLogger,
|
|
6175
6205
|
linkHashKey,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ClawPort, type Clock, type Logger } from "@primusclaw/personal-agent";
|
|
2
2
|
import { type Fetch } from "./http.js";
|
|
3
3
|
/** What Claw's audit trail calls this client by default (`X-Claw-Client`). */
|
|
4
|
-
export declare const DEFAULT_CLIENT_LABEL = "
|
|
4
|
+
export declare const DEFAULT_CLIENT_LABEL = "personal-agent";
|
|
5
5
|
/** How the Claw client is made (from the worker's settings). */
|
|
6
6
|
export interface ClawClientOptions {
|
|
7
7
|
/** CLAW_API_URL, without a trailing slash. */
|
|
@@ -10,7 +10,7 @@ export interface ClawClientOptions {
|
|
|
10
10
|
readonly logger?: Logger;
|
|
11
11
|
/** CLAW_PLUGIN_ID (null: plain sessions). */
|
|
12
12
|
readonly pluginId?: number | null;
|
|
13
|
-
/**
|
|
13
|
+
/** PERSONAL_AGENT_MODEL ("" sends none). */
|
|
14
14
|
readonly model?: string;
|
|
15
15
|
/** CLAW_RULE_TOOL_ID (null: no rule rides on a message). */
|
|
16
16
|
readonly ruleToolId?: number | null;
|
|
@@ -11,7 +11,7 @@ export declare const CHANGES_MAX_BYTES = 1048576;
|
|
|
11
11
|
export interface MessageDefaults {
|
|
12
12
|
/** CLAW_PLUGIN_ID, named as the web client names it (`pluginId`); null none. */
|
|
13
13
|
readonly pluginId: number | null;
|
|
14
|
-
/**
|
|
14
|
+
/** PERSONAL_AGENT_MODEL: what a new session asks for when its caller names none ("" none). */
|
|
15
15
|
readonly model: string;
|
|
16
16
|
/** The reply-style rule, when a rule tool is configured. */
|
|
17
17
|
readonly rule: StyleRule | null;
|
|
@@ -6,8 +6,11 @@
|
|
|
6
6
|
* uses `WORKER_IDENTITY_*` for its own Azure identity, and a surface's own settings keep the surface's prefix
|
|
7
7
|
* (`TEAMS_STREAMING`, `TEAMS_AI_LABEL`), so the prefix says whose a setting is.
|
|
8
8
|
*
|
|
9
|
-
* The
|
|
10
|
-
*
|
|
9
|
+
* The model settings were first named after the bot's earlier default name; they now carry `PERSONAL_AGENT_`, and the
|
|
10
|
+
* earlier names are read as aliases the same way.
|
|
11
|
+
*
|
|
12
|
+
* The rule, for every pair: the new name when it is set and not blank; else the old name when it is set; else the new
|
|
13
|
+
* name (unset or blank). A message about a value names the variable it was read from. An old name is only ever read.
|
|
11
14
|
*/
|
|
12
15
|
import { type Logger } from "@primusclaw/personal-agent";
|
|
13
16
|
/** The prefix of the worker's own settings. */
|
|
@@ -16,28 +19,34 @@ export declare const SETTING_PREFIX = "PA_";
|
|
|
16
19
|
export declare const LEGACY_SETTING_PREFIX = "TEAMS_";
|
|
17
20
|
/** The settings read under both prefixes, by their name after the prefix. */
|
|
18
21
|
export declare const ALIASED_SETTINGS: readonly ["DB_PATH", "ENCRYPTION_KEYS", "CLAW_EVENTS_GONE", "ON_BEHALF_USERS", "OBSERVE_USERS", "DIRECT_CHAT", "DIRECT_CHAT_USERS", "ASSISTANT_UNDERSTANDING", "ASSISTANT_UNDERSTANDING_USERS", "GROUP_CONTEXT_MESSAGES", "GROUP_CONTEXT_HOURS", "GROUP_CONTEXT_CHARS", "GROUP_CONTEXT_GRANTED", "EXCHANGE_ENABLED", "EXCHANGE_CLIENT_ID", "EXCHANGE_CLIENT_SECRET", "EXCHANGE_TOKEN_URL", "EXCHANGE_BINDING_REQUEST_URL", "EXCHANGE_ISSUER", "EXCHANGE_AUDIENCE", "EXCHANGE_SCOPE", "EXCHANGE_FOR_CHAT", "GITHUB_REVIEW_ENABLED", "GITHUB_REVIEW_OWNERS", "REVIEW_INTENT_MODEL", "GITHUB_CREDENTIAL_URL", "GITHUB_CLIENT_ID", "USER_MESSAGE_LIMIT", "USER_MESSAGE_WINDOW_SECONDS", "USER_MAX_CONCURRENT_TASKS", "LINK_MAX_FAILURES_PER_USER", "LINK_MAX_FAILURES_GLOBAL", "LINK_ATTEMPT_WINDOW_SECONDS", "LIMIT_PR_REVIEW", "LIMIT_PR_MERGE", "LIMIT_APPROVAL", "LIMIT_REMOTE_AGENT"];
|
|
19
|
-
/** The
|
|
22
|
+
/** The prefix of the model settings. */
|
|
23
|
+
export declare const MODEL_SETTING_PREFIX = "PERSONAL_AGENT_";
|
|
24
|
+
/** The prefix the model settings were first written with, still read as an alias. */
|
|
25
|
+
export declare const LEGACY_MODEL_SETTING_PREFIX = "CLAWY_";
|
|
26
|
+
/** The model settings, by their name after the prefix. */
|
|
27
|
+
export declare const MODEL_SETTINGS: readonly ["MODEL", "FALLBACK_MODEL", "REVIEW_MODEL"];
|
|
28
|
+
/** The pairs: new name -> the old name still read when it is not set. */
|
|
20
29
|
export declare const SETTING_ALIASES: ReadonlyMap<string, string>;
|
|
21
30
|
type Env = Readonly<Record<string, string | undefined>>;
|
|
22
31
|
/**
|
|
23
32
|
* The variable a setting is read from: `name` may be either name of a pair (or any other setting, read as it is). The
|
|
24
|
-
*
|
|
33
|
+
* new name when it is set and not blank, else the old name when it is present, else the new name.
|
|
25
34
|
*/
|
|
26
35
|
export declare function settingSource(env: Env, name: string): string;
|
|
27
36
|
/** The value of a setting under the alias rule (undefined: neither name is present). */
|
|
28
37
|
export declare function settingValue(env: Env, name: string): string | undefined;
|
|
29
|
-
/** A legacy name in use: the one read, or one set beside its
|
|
38
|
+
/** A legacy name in use: the one read, or one set beside its new name and ignored. */
|
|
30
39
|
export interface LegacySetting {
|
|
31
40
|
readonly legacy: string;
|
|
32
41
|
readonly neutral: string;
|
|
33
|
-
/** The
|
|
42
|
+
/** The new name is set too, so the old value is not read. */
|
|
34
43
|
readonly ignored: boolean;
|
|
35
44
|
}
|
|
36
|
-
/** The
|
|
45
|
+
/** The old names this environment sets (not blank) of the settings that now carry a new name. */
|
|
37
46
|
export declare function legacySettings(env: Env): LegacySetting[];
|
|
38
47
|
/**
|
|
39
|
-
* One warning at start for the
|
|
40
|
-
*
|
|
48
|
+
* One warning at start for the old names in use, naming the new name of each (never a value: some are secrets); and one
|
|
49
|
+
* for each old name that is set beside its new name and so not read. Nothing when none is in use.
|
|
41
50
|
*/
|
|
42
51
|
export declare function warnLegacySettings(env: Env, logger: Logger): void;
|
|
43
52
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { ALIASED_SETTINGS, LEGACY_SETTING_PREFIX, SETTING_ALIASES, SETTING_PREFIX, legacySettings, settingSource, settingValue, warnLegacySettings, type LegacySetting, } from "./aliases.js";
|
|
1
|
+
export { ALIASED_SETTINGS, LEGACY_MODEL_SETTING_PREFIX, LEGACY_SETTING_PREFIX, MODEL_SETTING_PREFIX, MODEL_SETTINGS, SETTING_ALIASES, SETTING_PREFIX, legacySettings, settingSource, settingValue, warnLegacySettings, type LegacySetting, } from "./aliases.js";
|
|
2
2
|
export { EnvReader, pyRepr, withoutTrailingSlash, type Env } from "./env.js";
|
|
3
3
|
export { ENV_NAMES, EnvSecretSource, SECRET_SETTING_NAMES, secretsSourceOf, wantedSecrets } from "./secrets.js";
|
|
4
4
|
export { ASSISTANT_REPLY_WINDOW_SECONDS, GITHUB_CLI_CLIENT_ID, readSettings } from "./settings.js";
|
|
@@ -21,6 +21,8 @@ export interface FeedbackSinkOptions {
|
|
|
21
21
|
/** Seconds since the epoch. */
|
|
22
22
|
readonly clock?: () => number;
|
|
23
23
|
readonly log: Logger;
|
|
24
|
+
/** The bot's name in this deployment (`Settings.botName`). */
|
|
25
|
+
readonly botName: string;
|
|
24
26
|
}
|
|
25
27
|
/** The sink feedback delivers to, or undefined when nothing is configured (reports are then only recorded). */
|
|
26
28
|
export declare function feedbackSink(config: FeedbackConfig, options: FeedbackSinkOptions): FeedbackSink | undefined;
|
|
@@ -6,14 +6,20 @@
|
|
|
6
6
|
import { type FeedbackSink, type IssueRef, type Logger, type Result, type SinkError } from "@primusclaw/personal-agent";
|
|
7
7
|
import { GithubApi } from "./api.js";
|
|
8
8
|
export declare const FEEDBACK_LABEL = "clawy-feedback";
|
|
9
|
+
/** The feedback label's description, naming the bot by the deployment's name. */
|
|
10
|
+
export declare function labelDescription(botName: string): string;
|
|
9
11
|
export declare class GithubIssueSink implements FeedbackSink {
|
|
10
12
|
private readonly api;
|
|
11
13
|
private readonly log;
|
|
14
|
+
/** The bot's name in this deployment (`Settings.botName`), for the label's description. */
|
|
15
|
+
private readonly botName;
|
|
12
16
|
private labelReady;
|
|
13
17
|
private readonly repoPath;
|
|
14
18
|
constructor(api: GithubApi,
|
|
15
19
|
/** `owner/name`. */
|
|
16
|
-
repo: string, log: Logger
|
|
20
|
+
repo: string, log: Logger,
|
|
21
|
+
/** The bot's name in this deployment (`Settings.botName`), for the label's description. */
|
|
22
|
+
botName: string);
|
|
17
23
|
createIssue(title: string, body: string, labels: readonly string[]): Promise<Result<IssueRef, SinkError>>;
|
|
18
24
|
findIssue(marker: string, sinceEpochMs: number): Promise<Result<IssueRef | undefined, SinkError>>;
|
|
19
25
|
hasComment(issue: number, marker: string, sinceEpochMs: number): Promise<Result<boolean, SinkError>>;
|
|
@@ -10,6 +10,8 @@ export declare const INTENT_MS = 10000;
|
|
|
10
10
|
export interface IntentReaderOptions {
|
|
11
11
|
readonly baseUrl: string;
|
|
12
12
|
readonly model: string;
|
|
13
|
+
/** The bot's name in this deployment (`Settings.botName`): the prompts say who the message was sent to. */
|
|
14
|
+
readonly botName: string;
|
|
13
15
|
readonly logger: Logger;
|
|
14
16
|
readonly fetch?: FetchLike;
|
|
15
17
|
readonly timeoutMs?: number;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { formatNumber, pyFloatRepr, round3 } from "./exposition.js";
|
|
2
|
-
export { ALERTED, CONTENT_TYPE, EVENT_BUCKETS, HELP, LAG_WINDOW_MS, PrometheusMetrics } from "./prometheus-metrics.js";
|
|
2
|
+
export { ALERTED, CONTENT_TYPE, EVENT_BUCKETS, HELP, LAG_WINDOW_MS, LEGACY_METRIC_PREFIX, METRIC_PREFIX, PrometheusMetrics, } from "./prometheus-metrics.js";
|
|
@@ -2,17 +2,25 @@
|
|
|
2
2
|
* The worker's counters for the operator's alerts, in memory (they start from zero when the worker restarts), written in
|
|
3
3
|
* the Prometheus text format for `GET /metrics` on its own port (the listener is the channel's assembly). The text is
|
|
4
4
|
* the Python worker's, line for line: the alert queries and dashboards read these names and labels.
|
|
5
|
+
*
|
|
6
|
+
* Every series is written twice for one release: under its `personal_agent_` name, then under the name an earlier release used
|
|
7
|
+
* (`LEGACY_METRIC_PREFIX`), so that alert rules and dashboards can move to the new names after the new build is live. The old
|
|
8
|
+
* names are deprecated and go away in the next minor release.
|
|
5
9
|
*/
|
|
6
10
|
import { type Clock, type MetricsPort, type SecurityEventRecord } from "@primusclaw/personal-agent";
|
|
7
11
|
export declare const CONTENT_TYPE = "text/plain; version=0.0.4; charset=utf-8";
|
|
8
|
-
/**
|
|
12
|
+
/** The prefix of every metric's name. */
|
|
13
|
+
export declare const METRIC_PREFIX = "personal_agent_";
|
|
14
|
+
/** The prefix an earlier release wrote the same metrics under, still written beside the new names for one release. */
|
|
15
|
+
export declare const LEGACY_METRIC_PREFIX = "clawy_";
|
|
16
|
+
/** `personal_agent_inbound_lag_max_ms`: the longest wait of the messages handled in this many milliseconds. */
|
|
9
17
|
export declare const LAG_WINDOW_MS = 60000;
|
|
10
18
|
/** Seconds; the 5 s bucket is the "card within 5 s" line. */
|
|
11
19
|
export declare const EVENT_BUCKETS: readonly [0.5, 1, 2, 3, 5, 10, 30, 60];
|
|
12
20
|
type Labels = ReadonlyArray<readonly [string, string]>;
|
|
13
21
|
/** Series written as 0 from the start, so that each one an alert reads exists before its first event. */
|
|
14
22
|
export declare const ALERTED: ReadonlyArray<readonly [string, Labels]>;
|
|
15
|
-
/** Every metric: its type and help text. */
|
|
23
|
+
/** Every metric (by its `personal_agent_` name): its type and help text. */
|
|
16
24
|
export declare const HELP: Readonly<Record<string, readonly [string, string]>>;
|
|
17
25
|
/** The MetricsPort of a worker, kept in memory and written in the Prometheus text format. */
|
|
18
26
|
export declare class PrometheusMetrics implements MetricsPort {
|
|
@@ -39,8 +47,11 @@ export declare class PrometheusMetrics implements MetricsPort {
|
|
|
39
47
|
/** The longest wait of the messages handled in the window, in milliseconds (0: none). */
|
|
40
48
|
lagMaxMs(): number;
|
|
41
49
|
private expire;
|
|
42
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* All series in the Prometheus text exposition format (version 0.0.4): under their names, then, with the same values and
|
|
52
|
+
* help, under the deprecated names of an earlier release (that half is the text it wrote, byte for byte).
|
|
53
|
+
*/
|
|
43
54
|
render(): string;
|
|
44
|
-
private
|
|
55
|
+
private renderAs;
|
|
45
56
|
}
|
|
46
57
|
export {};
|
package/dist/worker.js
CHANGED
|
@@ -48,7 +48,6 @@ function withBuildInfo(render, info) {
|
|
|
48
48
|
|
|
49
49
|
// packages/runtime/src/worker/features.ts
|
|
50
50
|
import {
|
|
51
|
-
BOT_NAME,
|
|
52
51
|
chatTurnKey,
|
|
53
52
|
contextInterceptor,
|
|
54
53
|
Guardrails as Guardrails2,
|
|
@@ -289,6 +288,7 @@ function assistantChat(base, integrations, style, parts, hooks) {
|
|
|
289
288
|
users: settings2.assistant.users,
|
|
290
289
|
understanding: settings2.assistant.understandingUsers,
|
|
291
290
|
pluginId: settings2.claw.pluginId ?? void 0,
|
|
291
|
+
assistantName: settings2.botName,
|
|
292
292
|
legacyTurn: (aadId) => hooks.legacyTurn(aadId),
|
|
293
293
|
files: messageFiles(base.surface),
|
|
294
294
|
onFilesDropped: (path, count) => {
|
|
@@ -316,7 +316,11 @@ function assistantParts(base, inputs) {
|
|
|
316
316
|
const { store, claw, logger, exchange } = base;
|
|
317
317
|
const subs = keeper(base, notifyUrl);
|
|
318
318
|
const receipts = new Receipts(base.clock, logger, () => style.assistantReceipt);
|
|
319
|
-
const directChat = new DirectChat(
|
|
319
|
+
const directChat = new DirectChat(
|
|
320
|
+
base.settings.directChat.enabled,
|
|
321
|
+
base.settings.directChat.users,
|
|
322
|
+
base.settings.botName
|
|
323
|
+
);
|
|
320
324
|
const late = {};
|
|
321
325
|
const board = new Board({
|
|
322
326
|
store,
|
|
@@ -431,7 +435,7 @@ function proactiveParts(base, style, assistant, errors, router) {
|
|
|
431
435
|
clock: base.clock,
|
|
432
436
|
logger: base.logger,
|
|
433
437
|
publicEvent: (event) => publicRunEvent(event, errors, (text) => looksLikeServiceError(text) || looksInternal(text)),
|
|
434
|
-
botName:
|
|
438
|
+
botName: settings2.botName,
|
|
435
439
|
...router === void 0 ? {} : { identityAfterRefusal: identityAfterRefusal(base, router) }
|
|
436
440
|
};
|
|
437
441
|
const proactive = new Proactive(deps);
|
|
@@ -513,7 +517,7 @@ function remoteAgents(base, inputs) {
|
|
|
513
517
|
windowDefault: switches.remoteWindow,
|
|
514
518
|
timings: REMOTE_FOLLOW_TIMINGS,
|
|
515
519
|
watchTimings: REMOTE_WATCH_TIMINGS,
|
|
516
|
-
botName:
|
|
520
|
+
botName: settings2.botName,
|
|
517
521
|
streaming: base.surface.caps.streaming
|
|
518
522
|
},
|
|
519
523
|
claw: claw.remoteAgents,
|
|
@@ -635,6 +639,7 @@ function reviewDeps(base, inputs, host) {
|
|
|
635
639
|
intent: review.intentModel ? new GatewayIntentReader({
|
|
636
640
|
baseUrl: `${settings2.safeApiUrl}/llm-proxy/v1`,
|
|
637
641
|
model: review.intentModel,
|
|
642
|
+
botName: settings2.botName,
|
|
638
643
|
logger,
|
|
639
644
|
fetch
|
|
640
645
|
}) : void 0,
|
|
@@ -653,7 +658,8 @@ function reviewDeps(base, inputs, host) {
|
|
|
653
658
|
restoreRef: (stored) => shape.restoreRef(stored),
|
|
654
659
|
owners: review.owners,
|
|
655
660
|
installUrl: shape.installHintUrl,
|
|
656
|
-
defaultModel: settings2.models.review
|
|
661
|
+
defaultModel: settings2.models.review,
|
|
662
|
+
botName: settings2.botName
|
|
657
663
|
};
|
|
658
664
|
}
|
|
659
665
|
function reviewParts(base, inputs, assistant) {
|
|
@@ -871,7 +877,7 @@ function feedbackService(base, mask2) {
|
|
|
871
877
|
return pyStrip3(state.answer);
|
|
872
878
|
}
|
|
873
879
|
},
|
|
874
|
-
wording: { botName:
|
|
880
|
+
wording: { botName: settings2.botName, channelName: base.shape.channelName },
|
|
875
881
|
publicBaseUrl: settings2.publicBaseUrl,
|
|
876
882
|
worker: workerInfoFromEnv(env, {
|
|
877
883
|
pluginId: settings2.claw.pluginId === null ? "" : String(settings2.claw.pluginId),
|
|
@@ -914,7 +920,8 @@ function w8Parts(base, options) {
|
|
|
914
920
|
users: [...settings2.observeUsers],
|
|
915
921
|
conversationOf: conversationFor(base),
|
|
916
922
|
pluginId: settings2.claw.pluginId ?? void 0,
|
|
917
|
-
log: logger
|
|
923
|
+
log: logger,
|
|
924
|
+
botName: settings2.botName
|
|
918
925
|
});
|
|
919
926
|
const groupContext = new GroupContext({
|
|
920
927
|
settings: settings2.groupContext,
|
|
@@ -935,7 +942,7 @@ function w8Parts(base, options) {
|
|
|
935
942
|
});
|
|
936
943
|
return {
|
|
937
944
|
service,
|
|
938
|
-
flow: new FeedbackFlow({ reports: store.feedback, reporting, service, log: logger }),
|
|
945
|
+
flow: new FeedbackFlow({ reports: store.feedback, reporting, service, log: logger, botName: settings2.botName }),
|
|
939
946
|
thumbs,
|
|
940
947
|
observer,
|
|
941
948
|
groupContext,
|
|
@@ -975,7 +982,7 @@ function refuseMissing(base) {
|
|
|
975
982
|
const { settings: settings2, plugins } = base;
|
|
976
983
|
if (settings2.models.fallback !== "" && plugins.modelRefusalPolicy === noModelRefusalPolicy)
|
|
977
984
|
throw new StartupError(
|
|
978
|
-
"
|
|
985
|
+
"PERSONAL_AGENT_FALLBACK_MODEL is set, but no plugin says when a model refused (modelRefusalPolicy): the fallback would never be used"
|
|
979
986
|
);
|
|
980
987
|
if (settings2.onBehalfUsers.size > 0 && !plugins.routeExtensions.some((route) => route.method === "POST" && route.path === ON_BEHALF_PATH))
|
|
981
988
|
throw new StartupError(
|
|
@@ -1015,7 +1022,7 @@ function routerDeps(base, built, errors) {
|
|
|
1015
1022
|
return {
|
|
1016
1023
|
config: {
|
|
1017
1024
|
publicBaseUrl: settings2.publicBaseUrl,
|
|
1018
|
-
botName:
|
|
1025
|
+
botName: settings2.botName,
|
|
1019
1026
|
pluginId: settings2.claw.pluginId === null ? "" : String(settings2.claw.pluginId),
|
|
1020
1027
|
model: settings2.models.chat,
|
|
1021
1028
|
reviewModel: settings2.models.review,
|
|
@@ -1196,7 +1203,7 @@ function buildFeatures(given) {
|
|
|
1196
1203
|
lateReview.handoff = review?.handoff;
|
|
1197
1204
|
const reviewHandlers = review?.service.routeHandlers();
|
|
1198
1205
|
const groupInterceptors = [
|
|
1199
|
-
contextInterceptor(w8.groupContext),
|
|
1206
|
+
contextInterceptor(w8.groupContext, base.settings.botName),
|
|
1200
1207
|
w8.observer.interceptor,
|
|
1201
1208
|
w8.flow.interceptor
|
|
1202
1209
|
];
|
|
@@ -1329,7 +1336,12 @@ function platformPlugins(plugins, deps) {
|
|
|
1329
1336
|
}) : plugins.identityLookup;
|
|
1330
1337
|
const keyRevoker = plugins.keyRevoker === noKeyRevoker ? new HttpKeyRevoker(settings2.safeApiUrl, (url, init) => deps.fetch(url, init)) : plugins.keyRevoker;
|
|
1331
1338
|
const config = feedbackConfigFromEnv(env, secrets.get("FEEDBACK_GITHUB_APP_KEY") ?? "");
|
|
1332
|
-
const sink = plugins.feedbackSink === noFeedbackSink2 ? feedbackSink(config, {
|
|
1339
|
+
const sink = plugins.feedbackSink === noFeedbackSink2 ? feedbackSink(config, {
|
|
1340
|
+
fetch: (url, init) => deps.fetch(url, init),
|
|
1341
|
+
clock: deps.now,
|
|
1342
|
+
log: logger,
|
|
1343
|
+
botName: settings2.botName
|
|
1344
|
+
}) ?? noFeedbackSink2 : plugins.feedbackSink;
|
|
1333
1345
|
if (sink === noFeedbackSink2) logger.info("feedback: not configured; reports are stored only");
|
|
1334
1346
|
else if (plugins.feedbackSink === noFeedbackSink2)
|
|
1335
1347
|
logger.info("feedback: issues go to the configured repository", { repo: config.repo });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primusclaw/personal-agent-runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Node adapters for the personal agent's ports (clock, randomness, logging, storage, Claw, metrics, HTTP), and, at @primusclaw/personal-agent-runtime/worker, the worker process on any chat surface.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@primusclaw/personal-agent": "0.
|
|
36
|
+
"@primusclaw/personal-agent": "0.10.0",
|
|
37
37
|
"fastify": "^5.12.8",
|
|
38
38
|
"zod": "^4.6.7"
|
|
39
39
|
}
|