@geminixiang/mikan 1.0.0-beta.73 → 1.0.0-beta.75
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/CHANGELOG.md +21 -0
- package/dist/adapters/slack/bot.d.ts.map +1 -1
- package/dist/adapters/slack/bot.js +1 -3
- package/dist/adapters/slack/bot.js.map +1 -1
- package/dist/adapters/slack/task-intent.d.ts.map +1 -1
- package/dist/adapters/slack/task-intent.js +1 -1
- package/dist/adapters/slack/task-intent.js.map +1 -1
- package/dist/adapters/slack/tools/blockkit.d.ts +1 -0
- package/dist/adapters/slack/tools/blockkit.d.ts.map +1 -1
- package/dist/adapters/slack/tools/blockkit.js +1 -0
- package/dist/adapters/slack/tools/blockkit.js.map +1 -1
- package/dist/adapters/web/admin/portal.js +33 -17
- package/dist/adapters/web/admin/portal.js.map +1 -1
- package/dist/adapters/web/portal-shell.js +5 -2
- package/dist/adapters/web/portal-shell.js.map +1 -1
- package/dist/harness/execution-env.js +34 -1
- package/dist/harness/execution-env.js.map +1 -1
- package/dist/harness/jev.d.ts +10 -1
- package/dist/harness/jev.d.ts.map +1 -1
- package/dist/harness/jev.js +17 -1
- package/dist/harness/jev.js.map +1 -1
- package/dist/harness/presenter.d.ts.map +1 -1
- package/dist/harness/presenter.js +8 -3
- package/dist/harness/presenter.js.map +1 -1
- package/dist/harness/prompt.js +1 -1
- package/dist/harness/prompt.js.map +1 -1
- package/dist/harness/tools/generate-image.d.ts +1 -0
- package/dist/harness/tools/generate-image.d.ts.map +1 -1
- package/dist/harness/tools/generate-image.js +1 -0
- package/dist/harness/tools/generate-image.js.map +1 -1
- package/dist/harness/tools/host-fn-tool.d.ts +10 -1
- package/dist/harness/tools/host-fn-tool.d.ts.map +1 -1
- package/dist/harness/tools/host-fn-tool.js +22 -2
- package/dist/harness/tools/host-fn-tool.js.map +1 -1
- package/dist/harness/tools/index.d.ts.map +1 -1
- package/dist/harness/tools/index.js +12 -1
- package/dist/harness/tools/index.js.map +1 -1
- package/dist/harness/tools/jev-browser.d.ts +130 -0
- package/dist/harness/tools/jev-browser.d.ts.map +1 -0
- package/dist/harness/tools/jev-browser.js +434 -0
- package/dist/harness/tools/jev-browser.js.map +1 -0
- package/dist/harness/tools/jev.d.ts.map +1 -1
- package/dist/harness/tools/jev.js +1 -0
- package/dist/harness/tools/jev.js.map +1 -1
- package/dist/harness/tools/sandbox.d.ts +1 -0
- package/dist/harness/tools/sandbox.d.ts.map +1 -1
- package/dist/harness/tools/sandbox.js +1 -0
- package/dist/harness/tools/sandbox.js.map +1 -1
- package/dist/harness/tools/secret-redaction.d.ts +34 -0
- package/dist/harness/tools/secret-redaction.d.ts.map +1 -0
- package/dist/harness/tools/secret-redaction.js +77 -0
- package/dist/harness/tools/secret-redaction.js.map +1 -0
- package/dist/observability/index.d.ts +11 -2
- package/dist/observability/index.d.ts.map +1 -1
- package/dist/observability/index.js +30 -0
- package/dist/observability/index.js.map +1 -1
- package/dist/observability/sentry.d.ts +9 -2
- package/dist/observability/sentry.d.ts.map +1 -1
- package/dist/observability/sentry.js +28 -0
- package/dist/observability/sentry.js.map +1 -1
- package/dist/observability/types.d.ts +15 -0
- package/dist/observability/types.d.ts.map +1 -1
- package/dist/observability/types.js.map +1 -1
- package/dist/runtime/conversation-runtime.d.ts.map +1 -1
- package/dist/runtime/conversation-runtime.js +19 -10
- package/dist/runtime/conversation-runtime.js.map +1 -1
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +4 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sandbox.js","sourceRoot":"","sources":["../../../src/harness/tools/sandbox.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAGzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC;IAChC,MA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,EAAE,MAAM,IAAI,WAAW,EAAE,CAAC;AACxF,CAAC;AAED,SAAS,UAAU,CAAC,IAAY;IAI9B,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;AACnE,CAAC","sourcesContent":["import type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport { Type } from \"@sinclair/typebox\";\nimport type { SandboxConfig } from \"../../sandbox/index.js\";\nimport type { OfficeAddress, ResourceLimits, SandboxResourceController } from \"../../types.js\";\nimport { runtimeResourceKey } from \"../../sandbox/identity.js\";\n\nconst sandboxSchema = Type.Object({\n label: Type.String({ description: \"Brief description of this action (shown to user)\" }),\n action: Type.Union([Type.Literal(\"status\"), Type.Literal(\"set\")], {\n description: \"Use status to inspect current limits, or set to apply temporary limits.\",\n }),\n cpus: Type.Optional(\n Type.String({\n description: \"CPU limit for action=set, for example '0.5', '1', or '2'.\",\n }),\n ),\n memory: Type.Optional(\n Type.String({\n description: \"Docker memory limit for action=set, for example '512m', '1g', or '4g'.\",\n }),\n ),\n});\n\ntype SandboxToolParams = {\n label: string;\n action: \"status\" | \"set\";\n cpus?: string;\n memory?: string;\n};\n\ninterface SandboxToolContext {\n userId: string;\n address: OfficeAddress;\n}\n\ninterface SandboxToolController {\n sandbox: SandboxConfig;\n resourceController?: Pick<SandboxResourceController, \"getLimitStatus\" | \"setLimits\">;\n}\n\nexport function createSandboxTool(controller: SandboxToolController): {\n tool: AgentTool<typeof sandboxSchema>;\n setSandboxContext: (context: SandboxToolContext) => void;\n} {\n let sandboxContext: SandboxToolContext | null = null;\n\n const tool: AgentTool<typeof sandboxSchema> = {\n name: \"sandbox\",\n label: \"sandbox\",\n executionMode: \"sequential\",\n description:\n \"Inspect or temporarily set CPU/memory limits for the current managed sandbox. Limits apply to this conversation's runtime and are cleared when it stops.\",\n parameters: sandboxSchema,\n execute: async (_toolCallId: string, params: SandboxToolParams, signal?: AbortSignal) => {\n if (signal?.aborted) {\n throw new Error(\"Operation aborted\");\n }\n if (!sandboxContext) {\n throw new Error(\"Sandbox context not configured\");\n }\n if (controller.sandbox.type !== \"image\" || !controller.resourceController) {\n throw new Error(\"The sandbox tool only supports image:* managed sandboxes\");\n }\n\n const containerKey = runtimeResourceKey(controller.sandbox, {\n userId: sandboxContext.userId,\n address: sandboxContext.address,\n });\n\n if (params.action === \"set\") {\n const limits = normalizeLimits(params);\n const status = await controller.resourceController.setLimits(containerKey, limits);\n return textResult(\n `Updated sandbox limits for ${containerKey}: ${formatLimits(status.limits)}. These temporary limits are cleared when the sandbox runtime stops.`,\n );\n }\n\n const status = controller.resourceController.getLimitStatus(containerKey);\n return textResult(\n `Sandbox limits for ${containerKey}: ${formatLimits(status.limits)}${status.boosted ? \" (boosted)\" : \"\"}.`,\n );\n },\n };\n\n return {\n tool,\n setSandboxContext: (context: SandboxToolContext) => {\n sandboxContext = context;\n },\n };\n}\n\nfunction normalizeLimits(params: SandboxToolParams): ResourceLimits {\n const cpus = normalizeLimitValue(\"cpus\", params.cpus);\n const memory = normalizeLimitValue(\"memory\", params.memory);\n if (!cpus && !memory) {\n throw new Error(\"action=set requires cpus and/or memory\");\n }\n return { ...(cpus ? { cpus } : {}), ...(memory ? { memory } : {}) };\n}\n\nfunction normalizeLimitValue(name: string, value: string | undefined): string | undefined {\n if (value === undefined) return undefined;\n const trimmed = value.trim();\n if (!trimmed) return undefined;\n if (!/^[A-Za-z0-9_.-]+$/.test(trimmed)) {\n throw new Error(`${name} must not contain whitespace or shell metacharacters`);\n }\n return trimmed;\n}\n\nfunction formatLimits(limits: ResourceLimits | undefined): string {\n return `CPU ${limits?.cpus ?? \"unlimited\"} / Memory ${limits?.memory ?? \"unlimited\"}`;\n}\n\nfunction textResult(text: string): {\n content: Array<{ type: \"text\"; text: string }>;\n details: undefined;\n} {\n return { content: [{ type: \"text\", text }], details: undefined };\n}\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { MikanHarnessTool } from "../types.js";
|
|
2
|
+
interface SecretEntry {
|
|
3
|
+
/** `[SECRET:<label>]` placeholder shown in place of the value. */
|
|
4
|
+
label: string;
|
|
5
|
+
value: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Replace every occurrence of a known secret env var's value in `text` with
|
|
9
|
+
* `[SECRET:<VAR_NAME>]`. Safe to call on arbitrary tool output; a no-op when
|
|
10
|
+
* no configured secret value appears in it.
|
|
11
|
+
*/
|
|
12
|
+
export declare function redactSecrets(text: string, secrets?: SecretEntry[]): string;
|
|
13
|
+
export type { SecretEntry };
|
|
14
|
+
/**
|
|
15
|
+
* Wrap a harness tool so every text part of its result passes through
|
|
16
|
+
* {@link redactSecrets} before the model or the session ever sees it. Applied
|
|
17
|
+
* uniformly to every tool at assembly time (`tools/index.ts`) rather than
|
|
18
|
+
* only `bash`: `read` can return a secret file's contents just as easily,
|
|
19
|
+
* and a platform or MCP tool could too.
|
|
20
|
+
*
|
|
21
|
+
* Mutates `tool.execute` in place rather than spreading into a new object.
|
|
22
|
+
* `pi-tools.ts`'s `isHarnessTool` marks a tool with a non-enumerable symbol
|
|
23
|
+
* property (`Object.defineProperty`, default `enumerable: false`), and a
|
|
24
|
+
* platform pack's `bindRun` closure can hold the exact tool object it wired
|
|
25
|
+
* up (`host-fn-tool.ts`'s `setFn`). A `{ ...tool }` spread drops that
|
|
26
|
+
* marker and detaches the copy from the pack's binding — which is exactly
|
|
27
|
+
* what happened here first: every platform/task/subagent tool silently
|
|
28
|
+
* stopped running because the session's `isHarnessTool` check saw an
|
|
29
|
+
* unmarked object and re-adapted an already-harness tool, scrambling its
|
|
30
|
+
* call signature. In-place mutation keeps identity, markers, and bound
|
|
31
|
+
* state intact; only `execute`'s behavior changes.
|
|
32
|
+
*/
|
|
33
|
+
export declare function withSecretRedaction(tool: MikanHarnessTool): MikanHarnessTool;
|
|
34
|
+
//# sourceMappingURL=secret-redaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secret-redaction.d.ts","sourceRoot":"","sources":["../../../src/harness/tools/secret-redaction.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAMpD,UAAU,WAAW;IACnB,kEAAkE;IAClE,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAwBD;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,WAAW,EAA2B,GAC9C,MAAM,CAQR;AAED,YAAY,EAAE,WAAW,EAAE,CAAC;AAE5B;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,gBAAgB,GAAG,gBAAgB,CAc5E"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { ENV_MANIFEST, readEnv } from "../../env-manifest.js";
|
|
2
|
+
/** Values shorter than this are not redacted: too likely to false-positive
|
|
3
|
+
* on ordinary short strings (e.g. a placeholder, a short flag value). */
|
|
4
|
+
const MIN_SECRET_LENGTH = 8;
|
|
5
|
+
/**
|
|
6
|
+
* Read every `secret: true` env var's current value from the process
|
|
7
|
+
* environment (via `readEnv`, so a `MIKAN_`-prefixed alias counts too).
|
|
8
|
+
* Recomputed per call — cheap, and correctness matters more than caching a
|
|
9
|
+
* snapshot that could go stale relative to `process.env`.
|
|
10
|
+
*/
|
|
11
|
+
function collectSecretEntries() {
|
|
12
|
+
const entries = [];
|
|
13
|
+
for (const group of ENV_MANIFEST) {
|
|
14
|
+
for (const spec of group.vars) {
|
|
15
|
+
if (!spec.secret)
|
|
16
|
+
continue;
|
|
17
|
+
const value = readEnv(spec.name);
|
|
18
|
+
if (!value || value.length < MIN_SECRET_LENGTH)
|
|
19
|
+
continue;
|
|
20
|
+
entries.push({ label: spec.name, value });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
// Longest value first: if one secret's value is a substring of another's
|
|
24
|
+
// (unlikely but not impossible), replace the longer match first so the
|
|
25
|
+
// shorter one does not leave a partial secret behind.
|
|
26
|
+
return entries.toSorted((a, b) => b.value.length - a.value.length);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Replace every occurrence of a known secret env var's value in `text` with
|
|
30
|
+
* `[SECRET:<VAR_NAME>]`. Safe to call on arbitrary tool output; a no-op when
|
|
31
|
+
* no configured secret value appears in it.
|
|
32
|
+
*/
|
|
33
|
+
export function redactSecrets(text, secrets = collectSecretEntries()) {
|
|
34
|
+
if (!text || secrets.length === 0)
|
|
35
|
+
return text;
|
|
36
|
+
let result = text;
|
|
37
|
+
for (const { label, value } of secrets) {
|
|
38
|
+
if (!result.includes(value))
|
|
39
|
+
continue;
|
|
40
|
+
result = result.split(value).join(`[SECRET:${label}]`);
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Wrap a harness tool so every text part of its result passes through
|
|
46
|
+
* {@link redactSecrets} before the model or the session ever sees it. Applied
|
|
47
|
+
* uniformly to every tool at assembly time (`tools/index.ts`) rather than
|
|
48
|
+
* only `bash`: `read` can return a secret file's contents just as easily,
|
|
49
|
+
* and a platform or MCP tool could too.
|
|
50
|
+
*
|
|
51
|
+
* Mutates `tool.execute` in place rather than spreading into a new object.
|
|
52
|
+
* `pi-tools.ts`'s `isHarnessTool` marks a tool with a non-enumerable symbol
|
|
53
|
+
* property (`Object.defineProperty`, default `enumerable: false`), and a
|
|
54
|
+
* platform pack's `bindRun` closure can hold the exact tool object it wired
|
|
55
|
+
* up (`host-fn-tool.ts`'s `setFn`). A `{ ...tool }` spread drops that
|
|
56
|
+
* marker and detaches the copy from the pack's binding — which is exactly
|
|
57
|
+
* what happened here first: every platform/task/subagent tool silently
|
|
58
|
+
* stopped running because the session's `isHarnessTool` check saw an
|
|
59
|
+
* unmarked object and re-adapted an already-harness tool, scrambling its
|
|
60
|
+
* call signature. In-place mutation keeps identity, markers, and bound
|
|
61
|
+
* state intact; only `execute`'s behavior changes.
|
|
62
|
+
*/
|
|
63
|
+
export function withSecretRedaction(tool) {
|
|
64
|
+
const original = tool.execute.bind(tool);
|
|
65
|
+
tool.execute = async (...args) => {
|
|
66
|
+
const result = await original(...args);
|
|
67
|
+
const secrets = collectSecretEntries();
|
|
68
|
+
if (secrets.length === 0)
|
|
69
|
+
return result;
|
|
70
|
+
return {
|
|
71
|
+
...result,
|
|
72
|
+
content: result.content.map((part) => part.type === "text" ? { ...part, text: redactSecrets(part.text, secrets) } : part),
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
return tool;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=secret-redaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secret-redaction.js","sourceRoot":"","sources":["../../../src/harness/tools/secret-redaction.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAG9D;0EAC0E;AAC1E,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAQ5B;;;;;GAKG;AACH,SAAS,oBAAoB;IAC3B,MAAM,OAAO,GAAkB,EAAE,CAAC;IAClC,KAAK,MAAM,KAAK,IAAI,YAAY,EAAE,CAAC;QACjC,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;YAC9B,IAAI,CAAC,IAAI,CAAC,MAAM;gBAAE,SAAS;YAC3B,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACjC,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,GAAG,iBAAiB;gBAAE,SAAS;YACzD,OAAO,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QAC5C,CAAC;IACH,CAAC;IACD,yEAAyE;IACzE,uEAAuE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,CAAC,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CACnF;SACF,CAAC;IACJ,CAAC,CAAC;IACF,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["/**\n * Redacts secret env var values out of tool output before it reaches the\n * model or gets persisted in the session transcript.\n *\n * mikan does not sandbox-isolate environment variables in host sandbox mode\n * (`docs/testing/slack-e2e.md`, `AGENTS.md`: host sandbox is trusted, not OS\n * isolation), so a tool that runs a shell command or reads a file can expose\n * any secret value the mikan process itself holds — `echo $OPENROUTER_API_KEY`\n * or `cat .env` return it in plain text. Without this pass, that plain text\n * flows straight into the model's context and the durable session JSONL; the\n * only remaining defense was the model choosing not to repeat it, which is\n * not a defense the model can be trusted to hold up. This is defense in\n * depth, not the sole one: authorized tools should still avoid emitting\n * secrets in the first place.\n *\n * `ENV_MANIFEST` is mikan's own inventory of every env var it reads, with\n * `secret: true` already curated (used today by `mikan env`'s report). This\n * module is the second consumer of that same authority, not a parallel list\n * that could drift from it.\n */\nimport type { ImageContent, TextContent } from \"@earendil-works/pi-ai\";\nimport { ENV_MANIFEST, readEnv } from \"../../env-manifest.js\";\nimport type { MikanHarnessTool } from \"../types.js\";\n\n/** Values shorter than this are not redacted: too likely to false-positive\n * on ordinary short strings (e.g. a placeholder, a short flag value). */\nconst MIN_SECRET_LENGTH = 8;\n\ninterface SecretEntry {\n /** `[SECRET:<label>]` placeholder shown in place of the value. */\n label: string;\n value: string;\n}\n\n/**\n * Read every `secret: true` env var's current value from the process\n * environment (via `readEnv`, so a `MIKAN_`-prefixed alias counts too).\n * Recomputed per call — cheap, and correctness matters more than caching a\n * snapshot that could go stale relative to `process.env`.\n */\nfunction collectSecretEntries(): SecretEntry[] {\n const entries: SecretEntry[] = [];\n for (const group of ENV_MANIFEST) {\n for (const spec of group.vars) {\n if (!spec.secret) continue;\n const value = readEnv(spec.name);\n if (!value || value.length < MIN_SECRET_LENGTH) continue;\n entries.push({ label: spec.name, value });\n }\n }\n // Longest value first: if one secret's value is a substring of another's\n // (unlikely but not impossible), replace the longer match first so the\n // shorter one does not leave a partial secret behind.\n return entries.toSorted((a, b) => b.value.length - a.value.length);\n}\n\n/**\n * Replace every occurrence of a known secret env var's value in `text` with\n * `[SECRET:<VAR_NAME>]`. Safe to call on arbitrary tool output; a no-op when\n * no configured secret value appears in it.\n */\nexport function redactSecrets(\n text: string,\n secrets: SecretEntry[] = collectSecretEntries(),\n): string {\n if (!text || secrets.length === 0) return text;\n let result = text;\n for (const { label, value } of secrets) {\n if (!result.includes(value)) continue;\n result = result.split(value).join(`[SECRET:${label}]`);\n }\n return result;\n}\n\nexport type { SecretEntry };\n\n/**\n * Wrap a harness tool so every text part of its result passes through\n * {@link redactSecrets} before the model or the session ever sees it. Applied\n * uniformly to every tool at assembly time (`tools/index.ts`) rather than\n * only `bash`: `read` can return a secret file's contents just as easily,\n * and a platform or MCP tool could too.\n *\n * Mutates `tool.execute` in place rather than spreading into a new object.\n * `pi-tools.ts`'s `isHarnessTool` marks a tool with a non-enumerable symbol\n * property (`Object.defineProperty`, default `enumerable: false`), and a\n * platform pack's `bindRun` closure can hold the exact tool object it wired\n * up (`host-fn-tool.ts`'s `setFn`). A `{ ...tool }` spread drops that\n * marker and detaches the copy from the pack's binding — which is exactly\n * what happened here first: every platform/task/subagent tool silently\n * stopped running because the session's `isHarnessTool` check saw an\n * unmarked object and re-adapted an already-harness tool, scrambling its\n * call signature. In-place mutation keeps identity, markers, and bound\n * state intact; only `execute`'s behavior changes.\n */\nexport function withSecretRedaction(tool: MikanHarnessTool): MikanHarnessTool {\n const original = tool.execute.bind(tool);\n tool.execute = async (...args: Parameters<MikanHarnessTool[\"execute\"]>) => {\n const result = await original(...args);\n const secrets = collectSecretEntries();\n if (secrets.length === 0) return result;\n return {\n ...result,\n content: result.content.map((part): TextContent | ImageContent =>\n part.type === \"text\" ? { ...part, text: redactSecrets(part.text, secrets) } : part,\n ),\n };\n };\n return tool;\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ObservabilityAttributes, ReportUserFacingErrorOptions, RunScopeContext, SubagentOutcomeReport } from "./types.js";
|
|
1
|
+
import type { JevOutcomeReport, ObservabilityAttributes, ReportUserFacingErrorOptions, RunScopeContext, SubagentOutcomeReport } from "./types.js";
|
|
2
2
|
export type { ObservabilityAttributes, RunScopeContext } from "./types.js";
|
|
3
3
|
export interface ObservabilitySpan {
|
|
4
4
|
end(options?: {
|
|
@@ -6,7 +6,7 @@ export interface ObservabilitySpan {
|
|
|
6
6
|
error?: unknown;
|
|
7
7
|
}): void;
|
|
8
8
|
}
|
|
9
|
-
export type { ReportUserFacingErrorOptions, SubagentOutcomeReport } from "./types.js";
|
|
9
|
+
export type { JevCaller, JevOutcomeReport, ReportUserFacingErrorOptions, SubagentOutcomeReport, } from "./types.js";
|
|
10
10
|
export { sanitizeBreadcrumb } from "./sentry.js";
|
|
11
11
|
export declare function metricAttributes(attributes: Record<string, string | number | boolean | undefined>): ObservabilityAttributes;
|
|
12
12
|
export declare function recordCounter(name: string, value: number, attributes?: ObservabilityAttributes): void;
|
|
@@ -30,4 +30,13 @@ export declare function captureError(error: unknown): string | undefined;
|
|
|
30
30
|
export declare function shutdownObservability(timeoutMs: number): Promise<boolean>;
|
|
31
31
|
export declare function recordSubagentOutcome(report: SubagentOutcomeReport): string | undefined;
|
|
32
32
|
export declare function reportSubagentLaunchError(error: unknown, report: Pick<SubagentOutcomeReport, "itemId" | "mode" | "profile">): string | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Record one `evaluateWithJev` call's cost/duration, tagged by which call
|
|
35
|
+
* site made it. Called from `evaluateWithJev` itself so every caller (the
|
|
36
|
+
* `jev` tool, `jev_browser`'s decision loop, Slack auto-reply gating, task
|
|
37
|
+
* intent classification) is covered by one instrumentation point instead of
|
|
38
|
+
* each call site remembering to report it. Never receives the judged state,
|
|
39
|
+
* questions, or answers — only the numbers.
|
|
40
|
+
*/
|
|
41
|
+
export declare function recordJevOutcome(report: JevOutcomeReport): void;
|
|
33
42
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/observability/index.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EACV,uBAAuB,EACvB,4BAA4B,EAC5B,eAAe,EACf,qBAAqB,EACtB,MAAM,YAAY,CAAC;AAEpB,YAAY,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE3E,MAAM,WAAW,iBAAiB;IAChC,GAAG,CAAC,OAAO,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,uBAAuB,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;CAChF;AACD,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/observability/index.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EACV,gBAAgB,EAChB,uBAAuB,EACvB,4BAA4B,EAC5B,eAAe,EACf,qBAAqB,EACtB,MAAM,YAAY,CAAC;AAEpB,YAAY,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE3E,MAAM,WAAW,iBAAiB;IAChC,GAAG,CAAC,OAAO,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,uBAAuB,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;CAChF;AACD,YAAY,EACV,SAAS,EACT,gBAAgB,EAChB,4BAA4B,EAC5B,qBAAqB,GACtB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAQjD,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC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AE,4BAA4B,GACpC,MAAM,GAAG,SAAS,CAQpB;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAO/D;AAED,wBAAsB,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAsB/E;AAQD,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,qBAAqB,GAAG,MAAM,GAAG,SAAS,CAuDvF;AAED,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,IAAI,CAAC,qBAAqB,EAAE,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAC,GACjE,MAAM,GAAG,SAAS,CAUpB;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,GAAG,IAAI,CAqB/D"}
|
|
@@ -254,4 +254,34 @@ export function reportSubagentLaunchError(error, report) {
|
|
|
254
254
|
context: { itemId: report.itemId },
|
|
255
255
|
});
|
|
256
256
|
}
|
|
257
|
+
/**
|
|
258
|
+
* Record one `evaluateWithJev` call's cost/duration, tagged by which call
|
|
259
|
+
* site made it. Called from `evaluateWithJev` itself so every caller (the
|
|
260
|
+
* `jev` tool, `jev_browser`'s decision loop, Slack auto-reply gating, task
|
|
261
|
+
* intent classification) is covered by one instrumentation point instead of
|
|
262
|
+
* each call site remembering to report it. Never receives the judged state,
|
|
263
|
+
* questions, or answers — only the numbers.
|
|
264
|
+
*/
|
|
265
|
+
export function recordJevOutcome(report) {
|
|
266
|
+
const attributes = metricAttributes({ caller: report.caller, status: report.status });
|
|
267
|
+
recordCounter("agent.jev.calls", 1, attributes);
|
|
268
|
+
if (report.costUsd !== undefined) {
|
|
269
|
+
recordDistribution("agent.jev.cost", report.costUsd, { attributes });
|
|
270
|
+
}
|
|
271
|
+
if (report.durationMs !== undefined) {
|
|
272
|
+
recordDistribution("agent.jev.duration", report.durationMs, {
|
|
273
|
+
unit: "millisecond",
|
|
274
|
+
attributes,
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
addLifecycleEvent("agent.jev.completed", {
|
|
278
|
+
caller: report.caller,
|
|
279
|
+
status: report.status,
|
|
280
|
+
error_type: report.errorType,
|
|
281
|
+
input_tokens: report.inputTokens,
|
|
282
|
+
output_tokens: report.outputTokens,
|
|
283
|
+
cost_usd: report.costUsd,
|
|
284
|
+
duration_ms: report.durationMs,
|
|
285
|
+
});
|
|
286
|
+
}
|
|
257
287
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/observability/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,KAAK,EAAmB,MAAM,oBAAoB,CAAC;AACrF,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,WAAW,EACX,mBAAmB,EACnB,wBAAwB,EACxB,iBAAiB,EACjB,uBAAuB,EACvB,aAAa,EACb,kBAAkB,GACnB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,6BAA6B,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAcjF,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC;AACrD,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAC,CAAC;AACrD,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAkD,CAAC;AAC3E,MAAM,UAAU,GAAG,IAAI,GAAG,EAAoD,CAAC;AAC/E,MAAM,MAAM,GAAG,IAAI,GAAG,EAAgD,CAAC;AAEvE,MAAM,UAAU,gBAAgB,CAC9B,UAAiE;IAEjE,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,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AACJ,CAAC;AAED,MAAM,UAAU,yBAAyB,CACvC,KAAc,EACd,MAAkE;IAElE,OAAO,qBAAqB,CAAC,KAAK,EAAE;QAClC,MAAM,EAAE,UAAU;QAClB,OAAO,EAAE,eAAe;QACxB,SAAS,EAAE,QAAQ;QACnB,QAAQ,EAAE,OAAO;QACjB,QAAQ,EAAE,UAAU;QACpB,IAAI,EAAE,EAAE,gBAAgB,EAAE,MAAM,CAAC,OAAO,EAAE,aAAa,EAAE,MAAM,CAAC,IAAI,EAAE;QACtE,OAAO,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE;KACnC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { metrics, SpanStatusCode, trace, type Attributes } from \"@opentelemetry/api\";\nimport {\n addSentryBreadcrumb,\n captureSentryError,\n closeSentry,\n recordSentryCounter,\n recordSentryDistribution,\n recordSentryGauge,\n sanitizeTelemetryString,\n sanitizeValue,\n withSentryRunScope,\n} from \"./sentry.js\";\nimport { isOpenTelemetryMetricsEnabled, shutdownOpenTelemetry } from \"./otel.js\";\nimport type {\n ObservabilityAttributes,\n ReportUserFacingErrorOptions,\n RunScopeContext,\n SubagentOutcomeReport,\n} from \"./types.js\";\n\nexport type { ObservabilityAttributes, RunScopeContext } from \"./types.js\";\n\nexport interface ObservabilitySpan {\n end(options?: { attributes?: ObservabilityAttributes; error?: unknown }): void;\n}\nexport type { ReportUserFacingErrorOptions, SubagentOutcomeReport } from \"./types.js\";\nexport { sanitizeBreadcrumb } from \"./sentry.js\";\n\nconst tracer = trace.getTracer(\"@geminixiang/mikan\");\nconst meter = metrics.getMeter(\"@geminixiang/mikan\");\nconst counters = new Map<string, ReturnType<typeof meter.createCounter>>();\nconst histograms = new Map<string, ReturnType<typeof meter.createHistogram>>();\nconst gauges = new Map<string, ReturnType<typeof meter.createGauge>>();\n\nexport function metricAttributes(\n attributes: Record<string, string | number | boolean | undefined>,\n): ObservabilityAttributes {\n return Object.fromEntries(\n Object.entries(attributes).flatMap(([key, value]) => {\n if (value === undefined) return [];\n const sanitized = sanitizeValue(value, key);\n return typeof sanitized === \"string\" ||\n typeof sanitized === \"number\" ||\n typeof sanitized === \"boolean\"\n ? [[key, sanitized] as const]\n : [];\n }),\n );\n}\n\nexport function recordCounter(\n name: string,\n value: number,\n attributes: ObservabilityAttributes = {},\n): void {\n const safeAttributes = metricAttributes(attributes);\n if (!isOpenTelemetryMetricsEnabled()) {\n recordSentryCounter(name, value, safeAttributes);\n return;\n }\n let counter = counters.get(name);\n if (!counter) {\n counter = meter.createCounter(name);\n counters.set(name, counter);\n }\n counter.add(value, safeAttributes as Attributes);\n}\n\nexport function recordDistribution(\n name: string,\n value: number,\n options: { unit?: string; attributes?: ObservabilityAttributes } = {},\n): void {\n const safeAttributes = metricAttributes(options.attributes ?? {});\n if (!isOpenTelemetryMetricsEnabled()) {\n recordSentryDistribution(name, value, {\n ...(options.unit ? { unit: options.unit } : {}),\n attributes: safeAttributes,\n });\n return;\n }\n const key = `${name}\\0${options.unit ?? \"\"}`;\n let histogram = histograms.get(key);\n if (!histogram) {\n histogram = meter.createHistogram(name, options.unit ? { unit: options.unit } : undefined);\n histograms.set(key, histogram);\n }\n histogram.record(value, safeAttributes as Attributes);\n}\n\nexport function recordGauge(\n name: string,\n value: number,\n options: { unit?: string; attributes?: ObservabilityAttributes } = {},\n): void {\n const safeAttributes = metricAttributes(options.attributes ?? {});\n if (!isOpenTelemetryMetricsEnabled()) {\n recordSentryGauge(name, value, {\n ...(options.unit ? { unit: options.unit } : {}),\n attributes: safeAttributes,\n });\n return;\n }\n const key = `${name}\\0${options.unit ?? \"\"}`;\n let gauge = gauges.get(key);\n if (!gauge) {\n gauge = meter.createGauge(name, options.unit ? { unit: options.unit } : undefined);\n gauges.set(key, gauge);\n }\n gauge.record(value, safeAttributes as Attributes);\n}\n\nexport function createRunAttributionAttributes(context: RunScopeContext): ObservabilityAttributes {\n return metricAttributes({\n conversation_id: context.conversationId,\n channel_id: context.conversationId,\n session_key: context.sessionKey,\n message_id: context.messageId,\n platform: context.platform,\n conversation_kind: context.conversationKind,\n user_id: context.userId,\n thread_id: context.threadTs,\n provider: context.provider,\n model: context.model,\n \"gen_ai.operation.name\": \"invoke_agent\",\n \"gen_ai.agent.name\": \"mikan\",\n \"gen_ai.conversation.id\": context.sessionKey,\n \"openinference.span.kind\": \"AGENT\",\n \"session.id\": context.sessionKey,\n });\n}\n\nexport async function withRunSpan<T>(context: RunScopeContext, body: () => Promise<T>): Promise<T> {\n const attribution = createRunAttributionAttributes(context);\n return tracer.startActiveSpan(\"agent.run\", { attributes: attribution as Attributes }, (span) =>\n withSentryRunScope(context, async () => {\n try {\n return await body();\n } catch (error) {\n span.setStatus({ code: SpanStatusCode.ERROR, message: safeErrorType(error) });\n throw error;\n } finally {\n span.end();\n }\n }),\n );\n}\n\nexport function startOperationSpan(\n name: string,\n attributes: ObservabilityAttributes = {},\n): ObservabilitySpan {\n const span = tracer.startSpan(name, {\n attributes: metricAttributes(attributes) as Attributes,\n });\n return {\n end(options = {}) {\n if (options.attributes) {\n span.setAttributes(metricAttributes(options.attributes) as Attributes);\n }\n if (options.error !== undefined) {\n const errorType = safeErrorType(options.error);\n span.setAttribute(\"error.type\", errorType);\n span.setStatus({ code: SpanStatusCode.ERROR, message: errorType });\n }\n span.end();\n },\n };\n}\n\nexport function updateActiveSpanAttribution(attributes: ObservabilityAttributes): void {\n trace.getActiveSpan()?.setAttributes(metricAttributes(attributes) as Attributes);\n}\n\nexport function addLifecycleEvent(\n name: string,\n attributes?: Record<string, string | number | boolean | undefined>,\n): void {\n const safeAttributes = attributes ? metricAttributes(attributes) : undefined;\n trace.getActiveSpan()?.addEvent(name, safeAttributes as Attributes | undefined);\n addSentryBreadcrumb(name, safeAttributes);\n}\n\n/** Record a deliberately shaped diagnostic payload; the Sentry adapter sanitizes it again. */\nexport function recordDiagnosticEvent(name: string, data: Record<string, unknown>): void {\n const spanAttributes = metricAttributes(\n Object.fromEntries(\n Object.entries(data).filter((entry): entry is [string, string | number | boolean] => {\n const value = entry[1];\n return typeof value === \"string\" || typeof value === \"number\" || typeof value === \"boolean\";\n }),\n ),\n );\n trace.getActiveSpan()?.addEvent(name, spanAttributes as Attributes);\n const recovered = name === \"slack.update.recovered\";\n addSentryBreadcrumb(\n recovered\n ? \"Slack update recovered\"\n : name === \"slack.update.rejected\"\n ? \"Slack update rejected\"\n : name,\n data,\n {\n category: name.startsWith(\"slack.update.\") ? \"slack.update\" : \"diagnostic\",\n level: name.endsWith(\".rejected\") ? \"warning\" : \"info\",\n log: recovered,\n },\n );\n}\n\nexport function reportUserFacingError(\n error: unknown,\n options: ReportUserFacingErrorOptions,\n): string | undefined {\n if (options.expected) return undefined;\n const span = trace.getActiveSpan();\n if (span) {\n span.setAttribute(\"error.type\", safeErrorType(error));\n span.setStatus({ code: SpanStatusCode.ERROR, message: safeErrorType(error) });\n }\n return captureSentryError(error, options);\n}\n\nexport function captureError(error: unknown): string | undefined {\n return reportUserFacingError(error, {\n domain: \"mikan\",\n surface: \"process\",\n operation: \"shutdown\",\n severity: \"error\",\n });\n}\n\nexport async function shutdownObservability(timeoutMs: number): Promise<boolean> {\n let openTelemetryFailure: unknown;\n try {\n await shutdownOpenTelemetry();\n } catch (error) {\n openTelemetryFailure = error;\n }\n\n let sentryClosed: boolean;\n try {\n sentryClosed = await closeSentry(timeoutMs);\n } catch (error) {\n if (openTelemetryFailure !== undefined) {\n const failure = new Error(\"Observability shutdown failed\", { cause: error });\n Object.assign(failure, { errors: [openTelemetryFailure, error] });\n throw failure;\n }\n throw new Error(\"Sentry shutdown failed\", { cause: error });\n }\n\n if (openTelemetryFailure !== undefined) throw openTelemetryFailure;\n return sentryClosed;\n}\n\nfunction safeErrorType(error: unknown): string {\n if (error instanceof Error && /^[A-Za-z][A-Za-z0-9_.-]{0,79}$/.test(error.name))\n return error.name;\n return \"Error\";\n}\n\nexport function recordSubagentOutcome(report: SubagentOutcomeReport): string | undefined {\n const attributes = metricAttributes({\n status: report.status,\n profile: report.profile,\n mode: report.mode,\n });\n recordCounter(\"agent.subagent.runs\", 1, attributes);\n if (report.durationMs !== undefined) {\n recordDistribution(\"agent.subagent.duration\", report.durationMs, {\n unit: \"millisecond\",\n attributes,\n });\n }\n addLifecycleEvent(\"agent.subagent.completed\", {\n item_id: report.itemId,\n status: report.status,\n profile: report.profile,\n mode: report.mode,\n turns: report.turns,\n tool_calls: report.toolCalls,\n tokens: report.tokens,\n cost_usd: report.costUsd,\n duration_ms: report.durationMs,\n cleanup_pending: report.cleanupPending,\n });\n if (report.status !== \"failed\" && report.status !== \"invalid_output\") return undefined;\n const errorClass = sanitizeTelemetryString(\n (report.error ?? report.status).split(\":\")[0]!.trim(),\n ).slice(0, 80);\n return reportUserFacingError(\n new Error(`Subagent ${report.status}: ${report.error ?? \"no error detail\"}`),\n {\n domain: \"subagent\",\n surface: \"subagent_tool\",\n operation: \"run\",\n severity: \"error\",\n toolName: \"subagent\",\n fingerprint: [\"subagent\", report.status, errorClass],\n tags: {\n subagent_status: report.status,\n subagent_profile: report.profile,\n subagent_mode: report.mode,\n cleanup_pending: report.cleanupPending,\n },\n context: {\n itemId: report.itemId,\n error: report.error,\n turns: report.turns,\n toolCalls: report.toolCalls,\n tokens: report.tokens,\n costUsd: report.costUsd,\n durationMs: report.durationMs,\n },\n },\n );\n}\n\nexport function reportSubagentLaunchError(\n error: unknown,\n report: Pick<SubagentOutcomeReport, \"itemId\" | \"mode\" | \"profile\">,\n): string | undefined {\n return reportUserFacingError(error, {\n domain: \"subagent\",\n surface: \"subagent_tool\",\n operation: \"launch\",\n severity: \"error\",\n toolName: \"subagent\",\n tags: { subagent_profile: report.profile, subagent_mode: report.mode },\n context: { itemId: report.itemId },\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/observability/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,KAAK,EAAmB,MAAM,oBAAoB,CAAC;AACrF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CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IACtF,aAAa,CAAC,iBAAiB,EAAE,CAAC,EAAE,UAAU,CAAC,CAAC;IAChD,IAAI,MAAM,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QACjC,kBAAkB,CAAC,gBAAgB,EAAE,MAAM,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;IACvE,CAAC;IACD,IAAI,MAAM,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;QACpC,kBAAkB,CAAC,oBAAoB,EAAE,MAAM,CAAC,UAAU,EAAE;YAC1D,IAAI,EAAE,aAAa;YACnB,UAAU;SACX,CAAC,CAAC;IACL,CAAC;IACD,iBAAiB,CAAC,qBAAqB,EAAE;QACvC,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,UAAU,EAAE,MAAM,CAAC,SAAS;QAC5B,YAAY,EAAE,MAAM,CAAC,WAAW;QAChC,aAAa,EAAE,MAAM,CAAC,YAAY;QAClC,QAAQ,EAAE,MAAM,CAAC,OAAO;QACxB,WAAW,EAAE,MAAM,CAAC,UAAU;KAC/B,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { metrics, SpanStatusCode, trace, type Attributes } from \"@opentelemetry/api\";\nimport {\n addSentryBreadcrumb,\n captureSentryError,\n closeSentry,\n recordSentryCounter,\n recordSentryDistribution,\n recordSentryGauge,\n sanitizeTelemetryString,\n sanitizeValue,\n withSentryRunScope,\n} from \"./sentry.js\";\nimport { isOpenTelemetryMetricsEnabled, shutdownOpenTelemetry } from \"./otel.js\";\nimport type {\n JevOutcomeReport,\n ObservabilityAttributes,\n ReportUserFacingErrorOptions,\n RunScopeContext,\n SubagentOutcomeReport,\n} from \"./types.js\";\n\nexport type { ObservabilityAttributes, RunScopeContext } from \"./types.js\";\n\nexport interface ObservabilitySpan {\n end(options?: { attributes?: ObservabilityAttributes; error?: unknown }): void;\n}\nexport type {\n JevCaller,\n JevOutcomeReport,\n ReportUserFacingErrorOptions,\n SubagentOutcomeReport,\n} from \"./types.js\";\nexport { sanitizeBreadcrumb } from \"./sentry.js\";\n\nconst tracer = trace.getTracer(\"@geminixiang/mikan\");\nconst meter = metrics.getMeter(\"@geminixiang/mikan\");\nconst counters = new Map<string, ReturnType<typeof meter.createCounter>>();\nconst histograms = new Map<string, ReturnType<typeof meter.createHistogram>>();\nconst gauges = new Map<string, ReturnType<typeof meter.createGauge>>();\n\nexport function metricAttributes(\n attributes: Record<string, string | number | boolean | undefined>,\n): ObservabilityAttributes {\n return Object.fromEntries(\n Object.entries(attributes).flatMap(([key, value]) => {\n if (value === undefined) return [];\n const sanitized = sanitizeValue(value, key);\n return typeof sanitized === \"string\" ||\n typeof sanitized === \"number\" ||\n typeof sanitized === \"boolean\"\n ? [[key, sanitized] as const]\n : [];\n }),\n );\n}\n\nexport function recordCounter(\n name: string,\n value: number,\n attributes: ObservabilityAttributes = {},\n): void {\n const safeAttributes = metricAttributes(attributes);\n if (!isOpenTelemetryMetricsEnabled()) {\n recordSentryCounter(name, value, safeAttributes);\n return;\n }\n let counter = counters.get(name);\n if (!counter) {\n counter = meter.createCounter(name);\n counters.set(name, counter);\n }\n counter.add(value, safeAttributes as Attributes);\n}\n\nexport function recordDistribution(\n name: string,\n value: number,\n options: { unit?: string; attributes?: ObservabilityAttributes } = {},\n): void {\n const safeAttributes = metricAttributes(options.attributes ?? {});\n if (!isOpenTelemetryMetricsEnabled()) {\n recordSentryDistribution(name, value, {\n ...(options.unit ? { unit: options.unit } : {}),\n attributes: safeAttributes,\n });\n return;\n }\n const key = `${name}\\0${options.unit ?? \"\"}`;\n let histogram = histograms.get(key);\n if (!histogram) {\n histogram = meter.createHistogram(name, options.unit ? { unit: options.unit } : undefined);\n histograms.set(key, histogram);\n }\n histogram.record(value, safeAttributes as Attributes);\n}\n\nexport function recordGauge(\n name: string,\n value: number,\n options: { unit?: string; attributes?: ObservabilityAttributes } = {},\n): void {\n const safeAttributes = metricAttributes(options.attributes ?? {});\n if (!isOpenTelemetryMetricsEnabled()) {\n recordSentryGauge(name, value, {\n ...(options.unit ? { unit: options.unit } : {}),\n attributes: safeAttributes,\n });\n return;\n }\n const key = `${name}\\0${options.unit ?? \"\"}`;\n let gauge = gauges.get(key);\n if (!gauge) {\n gauge = meter.createGauge(name, options.unit ? { unit: options.unit } : undefined);\n gauges.set(key, gauge);\n }\n gauge.record(value, safeAttributes as Attributes);\n}\n\nexport function createRunAttributionAttributes(context: RunScopeContext): ObservabilityAttributes {\n return metricAttributes({\n conversation_id: context.conversationId,\n channel_id: context.conversationId,\n session_key: context.sessionKey,\n message_id: context.messageId,\n platform: context.platform,\n conversation_kind: context.conversationKind,\n user_id: context.userId,\n thread_id: context.threadTs,\n provider: context.provider,\n model: context.model,\n \"gen_ai.operation.name\": \"invoke_agent\",\n \"gen_ai.agent.name\": \"mikan\",\n \"gen_ai.conversation.id\": context.sessionKey,\n \"openinference.span.kind\": \"AGENT\",\n \"session.id\": context.sessionKey,\n });\n}\n\nexport async function withRunSpan<T>(context: RunScopeContext, body: () => Promise<T>): Promise<T> {\n const attribution = createRunAttributionAttributes(context);\n return tracer.startActiveSpan(\"agent.run\", { attributes: attribution as Attributes }, (span) =>\n withSentryRunScope(context, async () => {\n try {\n return await body();\n } catch (error) {\n span.setStatus({ code: SpanStatusCode.ERROR, message: safeErrorType(error) });\n throw error;\n } finally {\n span.end();\n }\n }),\n );\n}\n\nexport function startOperationSpan(\n name: string,\n attributes: ObservabilityAttributes = {},\n): ObservabilitySpan {\n const span = tracer.startSpan(name, {\n attributes: metricAttributes(attributes) as Attributes,\n });\n return {\n end(options = {}) {\n if (options.attributes) {\n span.setAttributes(metricAttributes(options.attributes) as Attributes);\n }\n if (options.error !== undefined) {\n const errorType = safeErrorType(options.error);\n span.setAttribute(\"error.type\", errorType);\n span.setStatus({ code: SpanStatusCode.ERROR, message: errorType });\n }\n span.end();\n },\n };\n}\n\nexport function updateActiveSpanAttribution(attributes: ObservabilityAttributes): void {\n trace.getActiveSpan()?.setAttributes(metricAttributes(attributes) as Attributes);\n}\n\nexport function addLifecycleEvent(\n name: string,\n attributes?: Record<string, string | number | boolean | undefined>,\n): void {\n const safeAttributes = attributes ? metricAttributes(attributes) : undefined;\n trace.getActiveSpan()?.addEvent(name, safeAttributes as Attributes | undefined);\n addSentryBreadcrumb(name, safeAttributes);\n}\n\n/** Record a deliberately shaped diagnostic payload; the Sentry adapter sanitizes it again. */\nexport function recordDiagnosticEvent(name: string, data: Record<string, unknown>): void {\n const spanAttributes = metricAttributes(\n Object.fromEntries(\n Object.entries(data).filter((entry): entry is [string, string | number | boolean] => {\n const value = entry[1];\n return typeof value === \"string\" || typeof value === \"number\" || typeof value === \"boolean\";\n }),\n ),\n );\n trace.getActiveSpan()?.addEvent(name, spanAttributes as Attributes);\n const recovered = name === \"slack.update.recovered\";\n addSentryBreadcrumb(\n recovered\n ? \"Slack update recovered\"\n : name === \"slack.update.rejected\"\n ? \"Slack update rejected\"\n : name,\n data,\n {\n category: name.startsWith(\"slack.update.\") ? \"slack.update\" : \"diagnostic\",\n level: name.endsWith(\".rejected\") ? \"warning\" : \"info\",\n log: recovered,\n },\n );\n}\n\nexport function reportUserFacingError(\n error: unknown,\n options: ReportUserFacingErrorOptions,\n): string | undefined {\n if (options.expected) return undefined;\n const span = trace.getActiveSpan();\n if (span) {\n span.setAttribute(\"error.type\", safeErrorType(error));\n span.setStatus({ code: SpanStatusCode.ERROR, message: safeErrorType(error) });\n }\n return captureSentryError(error, options);\n}\n\nexport function captureError(error: unknown): string | undefined {\n return reportUserFacingError(error, {\n domain: \"mikan\",\n surface: \"process\",\n operation: \"shutdown\",\n severity: \"error\",\n });\n}\n\nexport async function shutdownObservability(timeoutMs: number): Promise<boolean> {\n let openTelemetryFailure: unknown;\n try {\n await shutdownOpenTelemetry();\n } catch (error) {\n openTelemetryFailure = error;\n }\n\n let sentryClosed: boolean;\n try {\n sentryClosed = await closeSentry(timeoutMs);\n } catch (error) {\n if (openTelemetryFailure !== undefined) {\n const failure = new Error(\"Observability shutdown failed\", { cause: error });\n Object.assign(failure, { errors: [openTelemetryFailure, error] });\n throw failure;\n }\n throw new Error(\"Sentry shutdown failed\", { cause: error });\n }\n\n if (openTelemetryFailure !== undefined) throw openTelemetryFailure;\n return sentryClosed;\n}\n\nfunction safeErrorType(error: unknown): string {\n if (error instanceof Error && /^[A-Za-z][A-Za-z0-9_.-]{0,79}$/.test(error.name))\n return error.name;\n return \"Error\";\n}\n\nexport function recordSubagentOutcome(report: SubagentOutcomeReport): string | undefined {\n const attributes = metricAttributes({\n status: report.status,\n profile: report.profile,\n mode: report.mode,\n });\n recordCounter(\"agent.subagent.runs\", 1, attributes);\n if (report.durationMs !== undefined) {\n recordDistribution(\"agent.subagent.duration\", report.durationMs, {\n unit: \"millisecond\",\n attributes,\n });\n }\n addLifecycleEvent(\"agent.subagent.completed\", {\n item_id: report.itemId,\n status: report.status,\n profile: report.profile,\n mode: report.mode,\n turns: report.turns,\n tool_calls: report.toolCalls,\n tokens: report.tokens,\n cost_usd: report.costUsd,\n duration_ms: report.durationMs,\n cleanup_pending: report.cleanupPending,\n });\n if (report.status !== \"failed\" && report.status !== \"invalid_output\") return undefined;\n const errorClass = sanitizeTelemetryString(\n (report.error ?? report.status).split(\":\")[0]!.trim(),\n ).slice(0, 80);\n return reportUserFacingError(\n new Error(`Subagent ${report.status}: ${report.error ?? \"no error detail\"}`),\n {\n domain: \"subagent\",\n surface: \"subagent_tool\",\n operation: \"run\",\n severity: \"error\",\n toolName: \"subagent\",\n fingerprint: [\"subagent\", report.status, errorClass],\n tags: {\n subagent_status: report.status,\n subagent_profile: report.profile,\n subagent_mode: report.mode,\n cleanup_pending: report.cleanupPending,\n },\n context: {\n itemId: report.itemId,\n error: report.error,\n turns: report.turns,\n toolCalls: report.toolCalls,\n tokens: report.tokens,\n costUsd: report.costUsd,\n durationMs: report.durationMs,\n },\n },\n );\n}\n\nexport function reportSubagentLaunchError(\n error: unknown,\n report: Pick<SubagentOutcomeReport, \"itemId\" | \"mode\" | \"profile\">,\n): string | undefined {\n return reportUserFacingError(error, {\n domain: \"subagent\",\n surface: \"subagent_tool\",\n operation: \"launch\",\n severity: \"error\",\n toolName: \"subagent\",\n tags: { subagent_profile: report.profile, subagent_mode: report.mode },\n context: { itemId: report.itemId },\n });\n}\n\n/**\n * Record one `evaluateWithJev` call's cost/duration, tagged by which call\n * site made it. Called from `evaluateWithJev` itself so every caller (the\n * `jev` tool, `jev_browser`'s decision loop, Slack auto-reply gating, task\n * intent classification) is covered by one instrumentation point instead of\n * each call site remembering to report it. Never receives the judged state,\n * questions, or answers — only the numbers.\n */\nexport function recordJevOutcome(report: JevOutcomeReport): void {\n const attributes = metricAttributes({ caller: report.caller, status: report.status });\n recordCounter(\"agent.jev.calls\", 1, attributes);\n if (report.costUsd !== undefined) {\n recordDistribution(\"agent.jev.cost\", report.costUsd, { attributes });\n }\n if (report.durationMs !== undefined) {\n recordDistribution(\"agent.jev.duration\", report.durationMs, {\n unit: \"millisecond\",\n attributes,\n });\n }\n addLifecycleEvent(\"agent.jev.completed\", {\n caller: report.caller,\n status: report.status,\n error_type: report.errorType,\n input_tokens: report.inputTokens,\n output_tokens: report.outputTokens,\n cost_usd: report.costUsd,\n duration_ms: report.durationMs,\n });\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Breadcrumb, ErrorEvent, Event, EventHint, Scope } from "@sentry/node";
|
|
2
2
|
import * as Sentry from "@sentry/node";
|
|
3
|
-
export type { ReportUserFacingErrorOptions, SentryAttributionAttributes, SubagentOutcomeReport, SentryRunScopeContext, SentrySpanPayload, SentryTransactionPayload, } from "./types.js";
|
|
4
|
-
import type { ReportUserFacingErrorOptions, SentryAttributionAttributes, SubagentOutcomeReport, SentryRunScopeContext, SentrySpanPayload, SentryTransactionPayload } from "./types.js";
|
|
3
|
+
export type { JevOutcomeReport, ReportUserFacingErrorOptions, SentryAttributionAttributes, SubagentOutcomeReport, SentryRunScopeContext, SentrySpanPayload, SentryTransactionPayload, } from "./types.js";
|
|
4
|
+
import type { JevOutcomeReport, ReportUserFacingErrorOptions, SentryAttributionAttributes, SubagentOutcomeReport, SentryRunScopeContext, SentrySpanPayload, SentryTransactionPayload } from "./types.js";
|
|
5
5
|
export declare function createSentryInitOptions(dsn?: string, customOpenTelemetry?: boolean): {
|
|
6
6
|
dsn: string | undefined;
|
|
7
7
|
environment: string;
|
|
@@ -60,4 +60,11 @@ export declare function recordSubagentOutcome(report: SubagentOutcomeReport): st
|
|
|
60
60
|
* error; this only makes sure it also reaches Sentry.
|
|
61
61
|
*/
|
|
62
62
|
export declare function reportSubagentLaunchError(error: unknown, report: Pick<SubagentOutcomeReport, "itemId" | "mode" | "profile">): string | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* Record one `evaluateWithJev` call's cost/duration, tagged by which call
|
|
65
|
+
* site made it (the `jev` tool, `jev_browser`'s decision loop, Slack
|
|
66
|
+
* auto-reply gating, task intent classification). Never receives the
|
|
67
|
+
* judged state, questions, or answers — only the numbers.
|
|
68
|
+
*/
|
|
69
|
+
export declare function recordJevOutcome(report: JevOutcomeReport): void;
|
|
63
70
|
//# sourceMappingURL=sentry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sentry.d.ts","sourceRoot":"","sources":["../../src/observability/sentry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACpF,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AAiEvC,YAAY,EACV,4BAA4B,EAC5B,2BAA2B,EAC3B,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,EACjB,wBAAwB,GACzB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EACV,4B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,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,GAChE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAO3C;AAcD,wBAAgB,aAAa,CAAC,CAAC,SAAS,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,SAAS,GAAG,CAAC,GAAG,IAAI,CA+CpF;AAED,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,iBAAiB,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,CAU5E;AAsBD,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,GAAG,IAAI,CAU5E;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,KAAK,SAAI,GAAG,OAAO,CAwB9E;AA8CD,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAS7D;AAYD;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,qBAAqB,GAAG,MAAM,GAAG,SAAS,CAwDvF;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,IAAI,CAAC,qBAAqB,EAAE,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAC,GACjE,MAAM,GAAG,SAAS,CAUpB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,GAAG,IAAI,CAqB/D"}
|
|
@@ -480,4 +480,32 @@ export function reportSubagentLaunchError(error, report) {
|
|
|
480
480
|
context: { itemId: report.itemId },
|
|
481
481
|
});
|
|
482
482
|
}
|
|
483
|
+
/**
|
|
484
|
+
* Record one `evaluateWithJev` call's cost/duration, tagged by which call
|
|
485
|
+
* site made it (the `jev` tool, `jev_browser`'s decision loop, Slack
|
|
486
|
+
* auto-reply gating, task intent classification). Never receives the
|
|
487
|
+
* judged state, questions, or answers — only the numbers.
|
|
488
|
+
*/
|
|
489
|
+
export function recordJevOutcome(report) {
|
|
490
|
+
const attributes = metricAttributes({ caller: report.caller, status: report.status });
|
|
491
|
+
Sentry.metrics.count("agent.jev.calls", 1, { attributes });
|
|
492
|
+
if (report.costUsd !== undefined) {
|
|
493
|
+
Sentry.metrics.distribution("agent.jev.cost", report.costUsd, { attributes });
|
|
494
|
+
}
|
|
495
|
+
if (report.durationMs !== undefined) {
|
|
496
|
+
Sentry.metrics.distribution("agent.jev.duration", report.durationMs, {
|
|
497
|
+
unit: "millisecond",
|
|
498
|
+
attributes,
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
addLifecycleBreadcrumb("agent.jev.completed", {
|
|
502
|
+
caller: report.caller,
|
|
503
|
+
status: report.status,
|
|
504
|
+
error_type: report.errorType,
|
|
505
|
+
input_tokens: report.inputTokens,
|
|
506
|
+
output_tokens: report.outputTokens,
|
|
507
|
+
cost_usd: report.costUsd,
|
|
508
|
+
duration_ms: report.durationMs,
|
|
509
|
+
});
|
|
510
|
+
}
|
|
483
511
|
//# sourceMappingURL=sentry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sentry.js","sourceRoot":"","sources":["../../src/observability/sentry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,MAAM,QAAQ,GAAG,YAAY,CAAC;AAC9B,MAAM,aAAa,GAAG,iBAAiB,CAAC;AACxC,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAC9B,MAAM,SAAS,GAAG,CAAC,CAAC;AACpB,MAAM,4BAA4B,GAAG,EAAE,CAAC;AACxC,MAAM,wBAAwB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AAE/C,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC;IAC7B,aAAa;IACb,QAAQ;IACR,UA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AE,gBAAgB,EAAE,MAAM,CAAC,OAAO,EAAE,aAAa,EAAE,MAAM,CAAC,IAAI,EAAE;QACtE,OAAO,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE;KACnC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { Breadcrumb, ErrorEvent, Event, EventHint, Scope } from \"@sentry/node\";\nimport * as Sentry from \"@sentry/node\";\nimport { readEnv } from \"../env-manifest.js\";\n\nconst REDACTED = \"[REDACTED]\";\nconst REDACTED_PATH = \"[REDACTED_PATH]\";\nconst MAX_STRING_LENGTH = 256;\nconst MAX_DEPTH = 4;\nconst MAX_FINGERPRINT_CLASS_LENGTH = 80;\nconst TRACE_ATTRIBUTION_TTL_MS = 5 * 60 * 1000;\n\nconst SENSITIVE_KEYS = new Set([\n \"accesstoken\",\n \"apikey\",\n \"apitoken\",\n \"args\",\n \"attachment\",\n \"attachments\",\n \"authorization\",\n \"body\",\n \"clientsecret\",\n \"code\",\n \"completion\",\n \"completions\",\n \"content\",\n \"contents\",\n \"cookie\",\n \"cookies\",\n \"credential\",\n \"filepath\",\n \"headers\",\n \"image\",\n \"imageattachments\",\n \"images\",\n \"localpath\",\n \"messages\",\n \"newusermessage\",\n \"password\",\n \"path\",\n \"paths\",\n \"prompt\",\n \"refreshtoken\",\n \"response\",\n \"result\",\n \"secret\",\n \"systemprompt\",\n \"text\",\n \"thinking\",\n \"toolarguments\",\n \"toolargs\",\n \"toolinput\",\n \"tooloutput\",\n \"token\",\n \"url\",\n \"uri\",\n \"workspacepath\",\n]);\n\nconst ABSOLUTE_PATH_PATTERN = /(?:(?<![A-Za-z0-9:/])\\/(?!\\/)[^\\s\"'`<>]+|[A-Za-z]:\\\\[^\\s\"'`<>]+)/;\nconst TOKEN_PATTERNS = [\n /\\bsk-[A-Za-z0-9_-]{12,}\\b/,\n /\\bxox[a-z]-[A-Za-z0-9-]{10,}\\b/,\n /\\bAIza[0-9A-Za-z_-]{20,}\\b/,\n /\\bgh[pousr]_[A-Za-z0-9]{20,}\\b/,\n];\n\nexport type {\n ReportUserFacingErrorOptions,\n SentryAttributionAttributes,\n SubagentOutcomeReport,\n SentryRunScopeContext,\n SentrySpanPayload,\n SentryTransactionPayload,\n} from \"./types.js\";\nimport type {\n ReportUserFacingErrorOptions,\n SentryAttributionAttributes,\n SubagentOutcomeReport,\n SubagentOutcomeStatus,\n SentryRunScopeContext,\n SentrySpanPayload,\n SentryTransactionPayload,\n} from \"./types.js\";\n\ntype TraceAttributionEntry = {\n attributes: SentryAttributionAttributes;\n expiresAt: number;\n};\n\nconst traceAttribution = new Map<string, TraceAttributionEntry>();\n\nexport function createSentryInitOptions(dsn?: string, customOpenTelemetry = false) {\n return {\n dsn,\n environment: readEnv(\"SENTRY_ENVIRONMENT\") ?? \"production\",\n enabled: Boolean(dsn) && readEnv(\"SENTRY_ENABLED\") !== \"false\",\n // Also keeps gen_ai inputs/outputs off. Do not add a `dataCollection`\n // block here: its mere presence switches the SDK base to all-true, and\n // prompts and completions start shipping unless every key is set false.\n sendDefaultPii: false,\n tracesSampleRate: customOpenTelemetry ? undefined : 1.0,\n skipOpenTelemetrySetup: customOpenTelemetry,\n registerEsmLoaderHooks: customOpenTelemetry ? false : undefined,\n includeLocalVariables: false,\n enableLogs: true,\n // Sentry's OpenAI APIPromise wrapper leaks a second rejection when an\n // in-flight request is aborted (for example by an agent budget limit).\n // Keep all other default integrations until the upstream wrapper handles\n // both withResponse() branches without an unhandled rejection.\n integrations(defaultIntegrations: ReturnType<typeof Sentry.getDefaultIntegrations>) {\n const retained = defaultIntegrations.filter(\n (integration) =>\n integration.name !== \"OpenAI\" &&\n (!customOpenTelemetry ||\n (integration.name !== \"Http\" && integration.name !== \"NodeFetch\")),\n );\n if (!customOpenTelemetry) return retained;\n\n // OTel owns span creation and W3C propagation in custom mode. Keep\n // Sentry's HTTP integration for request isolation, but do not let either\n // Sentry integration create spans or inject a second set of headers.\n return [\n ...retained,\n Sentry.httpIntegration({ spans: false, tracePropagation: false }),\n Sentry.nativeNodeFetchIntegration({ tracePropagation: false }),\n ];\n },\n beforeSend(event: ErrorEvent, hint: EventHint): ErrorEvent | null {\n return sanitizeEvent(event, hint);\n },\n beforeSendSpan(span: SentrySpanPayload): SentrySpanPayload {\n return applySpanAttribution(span);\n },\n beforeSendTransaction(event: SentryTransactionPayload): SentryTransactionPayload | null {\n return sanitizeTransactionEvent(event);\n },\n beforeBreadcrumb(breadcrumb: Breadcrumb): Breadcrumb | null {\n return sanitizeBreadcrumb(breadcrumb);\n },\n };\n}\n\nexport function captureSentryError(\n error: unknown,\n options: ReportUserFacingErrorOptions,\n): string | undefined {\n if (options.expected) return undefined;\n\n const exception = error instanceof Error ? error : new Error(String(error));\n return Sentry.withScope((scope) => {\n scope.setLevel(options.severity ?? \"error\");\n scope.setTag(\"user_facing\", \"true\");\n scope.setTag(\"expected\", \"false\");\n scope.setTag(\"error_domain\", options.domain);\n scope.setTag(\"error_surface\", options.surface);\n scope.setTag(\"operation\", options.operation);\n setOptionalTag(scope, \"platform\", options.platform);\n setOptionalTag(scope, \"provider\", options.provider);\n setOptionalTag(scope, \"model\", options.model);\n setOptionalTag(scope, \"tool\", options.toolName);\n setOptionalTag(scope, \"stop_reason\", options.stopReason);\n for (const [key, value] of Object.entries(options.tags ?? {})) {\n if (value !== undefined) scope.setTag(key, String(value));\n }\n if (options.fingerprint) scope.setFingerprint(options.fingerprint);\n scope.setContext(\"user_facing_error\", {\n domain: options.domain,\n surface: options.surface,\n operation: options.operation,\n severity: options.severity ?? \"error\",\n platform: options.platform,\n provider: options.provider,\n model: options.model,\n toolName: options.toolName,\n stopReason: options.stopReason,\n ...(sanitizeValue(options.context ?? {}) as Record<string, unknown>),\n });\n return Sentry.captureException(exception);\n });\n}\n\nexport function closeSentry(timeoutMs: number): Promise<boolean> {\n return Sentry.close(timeoutMs);\n}\n\nexport function recordSentryCounter(\n name: string,\n value: number,\n attributes: SentryAttributionAttributes,\n): void {\n Sentry.metrics.count(name, value, { attributes });\n}\n\nexport function recordSentryDistribution(\n name: string,\n value: number,\n options: { unit?: string; attributes: SentryAttributionAttributes },\n): void {\n Sentry.metrics.distribution(name, value, options);\n}\n\nexport function recordSentryGauge(\n name: string,\n value: number,\n options: { unit?: string; attributes: SentryAttributionAttributes },\n): void {\n Sentry.metrics.gauge(name, value, options);\n}\n\nexport function addSentryBreadcrumb(\n message: string,\n data?: Record<string, unknown>,\n options: {\n category?: string;\n level?: \"info\" | \"warning\";\n log?: boolean;\n } = {},\n): void {\n if (options.log) Sentry.logger.info(message, data);\n Sentry.addBreadcrumb({\n category: options.category ?? \"agent.lifecycle\",\n message,\n level: options.level ?? \"info\",\n data,\n });\n}\n\nexport function withSentryRunScope<T>(context: SentryRunScopeContext, body: () => T): T {\n return Sentry.withScope((scope) => {\n applyRunScope(scope, context);\n return body();\n });\n}\n\nfunction setOptionalTag(scope: Scope, key: string, value: string | undefined): void {\n if (value !== undefined) scope.setTag(key, value);\n}\n\nexport function createRunAttributionAttributes(\n context: SentryRunScopeContext,\n): SentryAttributionAttributes {\n return metricAttributes({\n conversation_id: context.conversationId,\n channel_id: context.conversationId,\n session_key: context.sessionKey,\n message_id: context.messageId,\n platform: context.platform,\n conversation_kind: context.conversationKind,\n user_id: context.userId,\n thread_id: context.threadTs,\n provider: context.provider,\n model: context.model,\n });\n}\n\nexport function registerTraceAttribution(\n span: { setAttributes(attributes: SentryAttributionAttributes): unknown },\n attributes: SentryAttributionAttributes,\n): void {\n span.setAttributes(attributes);\n const traceId = Sentry.spanToJSON(span as Parameters<typeof Sentry.spanToJSON>[0]).trace_id;\n if (!traceId) return;\n\n const now = Date.now();\n pruneExpiredTraceAttributions(now);\n traceAttribution.set(traceId, {\n attributes: { ...traceAttribution.get(traceId)?.attributes, ...attributes },\n expiresAt: now + TRACE_ATTRIBUTION_TTL_MS,\n });\n}\n\nexport function applyRunScope(scope: Scope, context: SentryRunScopeContext): void {\n const attributes = createRunAttributionAttributes(context);\n\n for (const [key, value] of Object.entries(attributes)) {\n scope.setTag(key, value);\n }\n scope.setAttributes(attributes);\n // Agent Monitoring groups spans by the platform session identifier.\n scope.setUser({ id: String(attributes.user_id) });\n scope.setConversationId(String(attributes.session_key));\n scope.setContext(\"agent_run\", {\n conversationId: attributes.conversation_id,\n channelId: attributes.channel_id,\n sessionKey: attributes.session_key,\n messageId: attributes.message_id,\n threadId: attributes.thread_id,\n platform: context.platform,\n conversationKind: context.conversationKind,\n provider: context.provider,\n model: context.model,\n });\n}\n\nexport function metricAttributes(\n attributes: Record<string, string | number | boolean | undefined>,\n): Record<string, string | number | boolean> {\n return Object.fromEntries(\n Object.entries(attributes).filter((entry): entry is [string, string | number | boolean] => {\n const [, value] = entry;\n return value !== undefined;\n }),\n );\n}\n\nfunction addLifecycleBreadcrumb(\n message: string,\n data?: Record<string, string | number | boolean | undefined>,\n): void {\n Sentry.addBreadcrumb({\n category: \"agent.lifecycle\",\n message,\n level: \"info\",\n data: data ? metricAttributes(data) : undefined,\n });\n}\n\nexport function sanitizeEvent<T extends Event>(event: T, _hint?: EventHint): T | null {\n const sanitized: T = {\n ...event,\n breadcrumbs: event.breadcrumbs\n ?.map((breadcrumb) => sanitizeBreadcrumb(breadcrumb))\n .filter((breadcrumb): breadcrumb is Breadcrumb => breadcrumb !== null),\n extra: sanitizeValue(event.extra) as T[\"extra\"],\n contexts: sanitizeValue(event.contexts) as T[\"contexts\"],\n request: sanitizeRequest(event.request),\n // Keep the identity applyRunScope set so Conversations show who sent each\n // message; drop anything else the SDK may have attached (email, IP).\n user: event.user ? { id: event.user.id, username: event.user.username } : undefined,\n server_name: undefined,\n };\n\n if (sanitized.message) {\n sanitized.message = sanitizeTelemetryString(sanitized.message);\n }\n\n if (sanitized.logentry) {\n sanitized.logentry = {\n ...sanitized.logentry,\n message: sanitized.logentry.message\n ? sanitizeTelemetryString(sanitized.logentry.message)\n : undefined,\n };\n }\n\n if (sanitized.exception?.values) {\n sanitized.exception.values = sanitized.exception.values.map((value) => ({\n ...value,\n value: value.value ? sanitizeTelemetryString(value.value) : value.value,\n stacktrace: value.stacktrace\n ? {\n ...value.stacktrace,\n frames: value.stacktrace.frames?.map((frame) => ({\n ...frame,\n filename: frame.filename ? sanitizeTelemetryString(frame.filename) : frame.filename,\n abs_path: frame.abs_path ? sanitizeTelemetryString(frame.abs_path) : frame.abs_path,\n vars: undefined,\n })),\n }\n : value.stacktrace,\n }));\n }\n\n return sanitized;\n}\n\nexport function applySpanAttribution<T extends SentrySpanPayload>(span: T): T {\n const attributes = getTraceAttribution(span.trace_id);\n if (!attributes) return span;\n return {\n ...span,\n data: {\n ...span.data,\n ...attributes,\n },\n };\n}\n\nfunction sanitizeTransactionEvent<T extends SentryTransactionPayload>(event: T): T | null {\n const sanitized = sanitizeEvent(event);\n if (!sanitized) return null;\n\n const traceContext = sanitized.contexts?.trace;\n const traceId = traceContext?.trace_id;\n if (typeof traceId !== \"string\") return sanitized;\n const attributes = getTraceAttribution(traceId);\n if (!attributes) return sanitized;\n\n const entries = (sanitized as { entries?: Array<{ type?: string; data?: unknown }> }).entries;\n for (const entry of entries ?? []) {\n if (entry.type !== \"spans\" || !Array.isArray(entry.data)) continue;\n entry.data = entry.data.map((span: SentrySpanPayload) => applySpanAttribution(span));\n }\n\n traceAttribution.delete(traceId);\n return sanitized;\n}\n\nexport function sanitizeBreadcrumb(breadcrumb: Breadcrumb): Breadcrumb | null {\n if (breadcrumb.category === \"console\") {\n return null;\n }\n\n return {\n ...breadcrumb,\n message: breadcrumb.message ? sanitizeTelemetryString(breadcrumb.message) : breadcrumb.message,\n data: sanitizeValue(breadcrumb.data) as Breadcrumb[\"data\"],\n };\n}\n\nexport function sanitizeValue(value: unknown, key?: string, depth = 0): unknown {\n if (value == null) return value;\n if (depth > MAX_DEPTH) return \"[Truncated]\";\n\n if (isSensitiveKey(key)) {\n return summarizeValue(value, key);\n }\n\n if (typeof value === \"string\") {\n return sanitizeTelemetryString(value);\n }\n\n if (Array.isArray(value)) {\n return value.slice(0, 20).map((entry) => sanitizeValue(entry, key, depth + 1));\n }\n\n if (typeof value === \"object\") {\n const entries = Object.entries(value as Record<string, unknown>).map(\n ([entryKey, entryValue]) => [entryKey, sanitizeValue(entryValue, entryKey, depth + 1)],\n );\n return Object.fromEntries(entries);\n }\n\n return value;\n}\n\nfunction sanitizeRequest(request: Event[\"request\"]): Event[\"request\"] {\n if (!request) return request;\n\n return {\n ...request,\n data: request.data ? summarizeValue(request.data, \"body\") : undefined,\n headers: undefined,\n cookies: undefined,\n };\n}\n\nfunction getTraceAttribution(traceId: string): SentryAttributionAttributes | undefined {\n const entry = traceAttribution.get(traceId);\n if (!entry) return undefined;\n if (entry.expiresAt > Date.now()) return entry.attributes;\n traceAttribution.delete(traceId);\n return undefined;\n}\n\nfunction pruneExpiredTraceAttributions(now: number): void {\n for (const [traceId, entry] of traceAttribution) {\n if (entry.expiresAt <= now) traceAttribution.delete(traceId);\n }\n}\n\nfunction isSensitiveKey(key?: string): boolean {\n if (!key) return false;\n return SENSITIVE_KEYS.has(key.toLowerCase().replace(/[^a-z0-9]/g, \"\"));\n}\n\nfunction summarizeValue(value: unknown, key?: string): string {\n const label = key ?? \"field\";\n if (typeof value === \"string\") {\n return `[Redacted ${label}; length=${value.length}]`;\n }\n if (Array.isArray(value)) {\n return `[Redacted ${label}; items=${value.length}]`;\n }\n if (value && typeof value === \"object\") {\n return `[Redacted ${label}; keys=${Object.keys(value as Record<string, unknown>).length}]`;\n }\n return `[Redacted ${label}]`;\n}\n\nexport function sanitizeTelemetryString(value: string): string {\n let sanitized = value.replace(new RegExp(ABSOLUTE_PATH_PATTERN, \"g\"), REDACTED_PATH);\n for (const pattern of TOKEN_PATTERNS) {\n sanitized = sanitized.replace(new RegExp(pattern, \"g\"), REDACTED);\n }\n if (sanitized.length > MAX_STRING_LENGTH) {\n return `${sanitized.slice(0, MAX_STRING_LENGTH)}… [truncated ${sanitized.length - MAX_STRING_LENGTH} chars]`;\n }\n return sanitized;\n}\n\n/**\n * Subagent outcomes that page. Everything else is a bounded, expected end\n * state the parent model already sees in the tool result: a budget or clock\n * ran out, the caller aborted, or a dependency failed upstream.\n */\nconst UNEXPECTED_SUBAGENT_STATUSES: ReadonlySet<SubagentOutcomeStatus> = new Set([\n \"failed\",\n \"invalid_output\",\n]);\n\n/**\n * Record one subagent outcome: a run counter and duration for every status,\n * a lifecycle breadcrumb, and a Sentry error only for statuses in\n * `UNEXPECTED_SUBAGENT_STATUSES`. Fingerprinted on the error's prefix before\n * the first colon so one failure class is one issue regardless of which\n * tool, file, or model message follows it.\n */\nexport function recordSubagentOutcome(report: SubagentOutcomeReport): string | undefined {\n const attributes = metricAttributes({\n status: report.status,\n profile: report.profile,\n mode: report.mode,\n });\n Sentry.metrics.count(\"agent.subagent.runs\", 1, { attributes });\n if (report.durationMs !== undefined) {\n Sentry.metrics.distribution(\"agent.subagent.duration\", report.durationMs, {\n unit: \"millisecond\",\n attributes,\n });\n }\n addLifecycleBreadcrumb(\"agent.subagent.completed\", {\n item_id: report.itemId,\n status: report.status,\n profile: report.profile,\n mode: report.mode,\n turns: report.turns,\n tool_calls: report.toolCalls,\n tokens: report.tokens,\n cost_usd: report.costUsd,\n duration_ms: report.durationMs,\n cleanup_pending: report.cleanupPending,\n });\n if (!UNEXPECTED_SUBAGENT_STATUSES.has(report.status)) return undefined;\n\n const errorClass = sanitizeTelemetryString(\n (report.error ?? report.status).split(\":\")[0]!.trim(),\n ).slice(0, MAX_FINGERPRINT_CLASS_LENGTH);\n return captureSentryError(\n new Error(`Subagent ${report.status}: ${report.error ?? \"no error detail\"}`),\n {\n domain: \"subagent\",\n surface: \"subagent_tool\",\n operation: \"run\",\n severity: \"error\",\n toolName: \"subagent\",\n fingerprint: [\"subagent\", report.status, errorClass],\n tags: {\n subagent_status: report.status,\n subagent_profile: report.profile,\n subagent_mode: report.mode,\n cleanup_pending: report.cleanupPending,\n },\n context: {\n itemId: report.itemId,\n error: report.error,\n turns: report.turns,\n toolCalls: report.toolCalls,\n tokens: report.tokens,\n costUsd: report.costUsd,\n durationMs: report.durationMs,\n },\n },\n );\n}\n\n/**\n * A subagent that never started: unknown profile, ungranted tool, or a\n * harness rejection. The throw still reaches the parent model as a tool\n * error; this only makes sure it also reaches Sentry.\n */\nexport function reportSubagentLaunchError(\n error: unknown,\n report: Pick<SubagentOutcomeReport, \"itemId\" | \"mode\" | \"profile\">,\n): string | undefined {\n return captureSentryError(error, {\n domain: \"subagent\",\n surface: \"subagent_tool\",\n operation: \"launch\",\n severity: \"error\",\n toolName: \"subagent\",\n tags: { subagent_profile: report.profile, subagent_mode: report.mode },\n context: { itemId: report.itemId },\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"sentry.js","sourceRoot":"","sources":["../../src/observability/sentry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,MAAM,QAAQ,GAAG,YAAY,CAAC;AAC9B,MAAM,aAAa,GAAG,iBAAiB,CAAC;AACxC,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAC9B,MAAM,SAAS,GAAG,CAAC,CAAC;AACpB,MAAM,4BAA4B,GAAG,EAAE,CAAC;AACxC,MAAM,wBAAwB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AAE/C,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC;IAC7B,aAAa;IACb,QAAQ;IACR,UAAU;IACV,MAAM;IACN,YAAY;IACZ,aAAa;IACb,eAAe;IACf,MAAM;IACN,cAAc;IACd,MAAM;IACN,YAAY;IACZ,aAAa;IACb,SAAS;IACT,UAAU;IACV,QAAQ;IACR,SAAS;IACT,YAAY;IACZ,UAAU;IACV,SAAS;IACT,OAAO;IACP,kBAAkB;IAClB,QAAQ;IACR,WAAW;IACX,UAAU;IACV,gBAAgB;IAChB,UAAU;IACV,MAAM;IACN,OAAO;IACP,QAAQ;IACR,cAAc;IACd,UAAU;IACV,QAA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M,EAAE,CAAC,CAAC;IACtF,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,iBAAiB,EAAE,CAAC,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;IAC3D,IAAI,MAAM,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QACjC,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,gBAAgB,EAAE,MAAM,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;IAChF,CAAC;IACD,IAAI,MAAM,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;QACpC,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,oBAAoB,EAAE,MAAM,CAAC,UAAU,EAAE;YACnE,IAAI,EAAE,aAAa;YACnB,UAAU;SACX,CAAC,CAAC;IACL,CAAC;IACD,sBAAsB,CAAC,qBAAqB,EAAE;QAC5C,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,UAAU,EAAE,MAAM,CAAC,SAAS;QAC5B,YAAY,EAAE,MAAM,CAAC,WAAW;QAChC,aAAa,EAAE,MAAM,CAAC,YAAY;QAClC,QAAQ,EAAE,MAAM,CAAC,OAAO;QACxB,WAAW,EAAE,MAAM,CAAC,UAAU;KAC/B,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { Breadcrumb, ErrorEvent, Event, EventHint, Scope } from \"@sentry/node\";\nimport * as Sentry from \"@sentry/node\";\nimport { readEnv } from \"../env-manifest.js\";\n\nconst REDACTED = \"[REDACTED]\";\nconst REDACTED_PATH = \"[REDACTED_PATH]\";\nconst MAX_STRING_LENGTH = 256;\nconst MAX_DEPTH = 4;\nconst MAX_FINGERPRINT_CLASS_LENGTH = 80;\nconst TRACE_ATTRIBUTION_TTL_MS = 5 * 60 * 1000;\n\nconst SENSITIVE_KEYS = new Set([\n \"accesstoken\",\n \"apikey\",\n \"apitoken\",\n \"args\",\n \"attachment\",\n \"attachments\",\n \"authorization\",\n \"body\",\n \"clientsecret\",\n \"code\",\n \"completion\",\n \"completions\",\n \"content\",\n \"contents\",\n \"cookie\",\n \"cookies\",\n \"credential\",\n \"filepath\",\n \"headers\",\n \"image\",\n \"imageattachments\",\n \"images\",\n \"localpath\",\n \"messages\",\n \"newusermessage\",\n \"password\",\n \"path\",\n \"paths\",\n \"prompt\",\n \"refreshtoken\",\n \"response\",\n \"result\",\n \"secret\",\n \"systemprompt\",\n \"text\",\n \"thinking\",\n \"toolarguments\",\n \"toolargs\",\n \"toolinput\",\n \"tooloutput\",\n \"token\",\n \"url\",\n \"uri\",\n \"workspacepath\",\n]);\n\nconst ABSOLUTE_PATH_PATTERN = /(?:(?<![A-Za-z0-9:/])\\/(?!\\/)[^\\s\"'`<>]+|[A-Za-z]:\\\\[^\\s\"'`<>]+)/;\nconst TOKEN_PATTERNS = [\n /\\bsk-[A-Za-z0-9_-]{12,}\\b/,\n /\\bxox[a-z]-[A-Za-z0-9-]{10,}\\b/,\n /\\bAIza[0-9A-Za-z_-]{20,}\\b/,\n /\\bgh[pousr]_[A-Za-z0-9]{20,}\\b/,\n];\n\nexport type {\n JevOutcomeReport,\n ReportUserFacingErrorOptions,\n SentryAttributionAttributes,\n SubagentOutcomeReport,\n SentryRunScopeContext,\n SentrySpanPayload,\n SentryTransactionPayload,\n} from \"./types.js\";\nimport type {\n JevOutcomeReport,\n ReportUserFacingErrorOptions,\n SentryAttributionAttributes,\n SubagentOutcomeReport,\n SubagentOutcomeStatus,\n SentryRunScopeContext,\n SentrySpanPayload,\n SentryTransactionPayload,\n} from \"./types.js\";\n\ntype TraceAttributionEntry = {\n attributes: SentryAttributionAttributes;\n expiresAt: number;\n};\n\nconst traceAttribution = new Map<string, TraceAttributionEntry>();\n\nexport function createSentryInitOptions(dsn?: string, customOpenTelemetry = false) {\n return {\n dsn,\n environment: readEnv(\"SENTRY_ENVIRONMENT\") ?? \"production\",\n enabled: Boolean(dsn) && readEnv(\"SENTRY_ENABLED\") !== \"false\",\n // Also keeps gen_ai inputs/outputs off. Do not add a `dataCollection`\n // block here: its mere presence switches the SDK base to all-true, and\n // prompts and completions start shipping unless every key is set false.\n sendDefaultPii: false,\n tracesSampleRate: customOpenTelemetry ? undefined : 1.0,\n skipOpenTelemetrySetup: customOpenTelemetry,\n registerEsmLoaderHooks: customOpenTelemetry ? false : undefined,\n includeLocalVariables: false,\n enableLogs: true,\n // Sentry's OpenAI APIPromise wrapper leaks a second rejection when an\n // in-flight request is aborted (for example by an agent budget limit).\n // Keep all other default integrations until the upstream wrapper handles\n // both withResponse() branches without an unhandled rejection.\n integrations(defaultIntegrations: ReturnType<typeof Sentry.getDefaultIntegrations>) {\n const retained = defaultIntegrations.filter(\n (integration) =>\n integration.name !== \"OpenAI\" &&\n (!customOpenTelemetry ||\n (integration.name !== \"Http\" && integration.name !== \"NodeFetch\")),\n );\n if (!customOpenTelemetry) return retained;\n\n // OTel owns span creation and W3C propagation in custom mode. Keep\n // Sentry's HTTP integration for request isolation, but do not let either\n // Sentry integration create spans or inject a second set of headers.\n return [\n ...retained,\n Sentry.httpIntegration({ spans: false, tracePropagation: false }),\n Sentry.nativeNodeFetchIntegration({ tracePropagation: false }),\n ];\n },\n beforeSend(event: ErrorEvent, hint: EventHint): ErrorEvent | null {\n return sanitizeEvent(event, hint);\n },\n beforeSendSpan(span: SentrySpanPayload): SentrySpanPayload {\n return applySpanAttribution(span);\n },\n beforeSendTransaction(event: SentryTransactionPayload): SentryTransactionPayload | null {\n return sanitizeTransactionEvent(event);\n },\n beforeBreadcrumb(breadcrumb: Breadcrumb): Breadcrumb | null {\n return sanitizeBreadcrumb(breadcrumb);\n },\n };\n}\n\nexport function captureSentryError(\n error: unknown,\n options: ReportUserFacingErrorOptions,\n): string | undefined {\n if (options.expected) return undefined;\n\n const exception = error instanceof Error ? error : new Error(String(error));\n return Sentry.withScope((scope) => {\n scope.setLevel(options.severity ?? \"error\");\n scope.setTag(\"user_facing\", \"true\");\n scope.setTag(\"expected\", \"false\");\n scope.setTag(\"error_domain\", options.domain);\n scope.setTag(\"error_surface\", options.surface);\n scope.setTag(\"operation\", options.operation);\n setOptionalTag(scope, \"platform\", options.platform);\n setOptionalTag(scope, \"provider\", options.provider);\n setOptionalTag(scope, \"model\", options.model);\n setOptionalTag(scope, \"tool\", options.toolName);\n setOptionalTag(scope, \"stop_reason\", options.stopReason);\n for (const [key, value] of Object.entries(options.tags ?? {})) {\n if (value !== undefined) scope.setTag(key, String(value));\n }\n if (options.fingerprint) scope.setFingerprint(options.fingerprint);\n scope.setContext(\"user_facing_error\", {\n domain: options.domain,\n surface: options.surface,\n operation: options.operation,\n severity: options.severity ?? \"error\",\n platform: options.platform,\n provider: options.provider,\n model: options.model,\n toolName: options.toolName,\n stopReason: options.stopReason,\n ...(sanitizeValue(options.context ?? {}) as Record<string, unknown>),\n });\n return Sentry.captureException(exception);\n });\n}\n\nexport function closeSentry(timeoutMs: number): Promise<boolean> {\n return Sentry.close(timeoutMs);\n}\n\nexport function recordSentryCounter(\n name: string,\n value: number,\n attributes: SentryAttributionAttributes,\n): void {\n Sentry.metrics.count(name, value, { attributes });\n}\n\nexport function recordSentryDistribution(\n name: string,\n value: number,\n options: { unit?: string; attributes: SentryAttributionAttributes },\n): void {\n Sentry.metrics.distribution(name, value, options);\n}\n\nexport function recordSentryGauge(\n name: string,\n value: number,\n options: { unit?: string; attributes: SentryAttributionAttributes },\n): void {\n Sentry.metrics.gauge(name, value, options);\n}\n\nexport function addSentryBreadcrumb(\n message: string,\n data?: Record<string, unknown>,\n options: {\n category?: string;\n level?: \"info\" | \"warning\";\n log?: boolean;\n } = {},\n): void {\n if (options.log) Sentry.logger.info(message, data);\n Sentry.addBreadcrumb({\n category: options.category ?? \"agent.lifecycle\",\n message,\n level: options.level ?? \"info\",\n data,\n });\n}\n\nexport function withSentryRunScope<T>(context: SentryRunScopeContext, body: () => T): T {\n return Sentry.withScope((scope) => {\n applyRunScope(scope, context);\n return body();\n });\n}\n\nfunction setOptionalTag(scope: Scope, key: string, value: string | undefined): void {\n if (value !== undefined) scope.setTag(key, value);\n}\n\nexport function createRunAttributionAttributes(\n context: SentryRunScopeContext,\n): SentryAttributionAttributes {\n return metricAttributes({\n conversation_id: context.conversationId,\n channel_id: context.conversationId,\n session_key: context.sessionKey,\n message_id: context.messageId,\n platform: context.platform,\n conversation_kind: context.conversationKind,\n user_id: context.userId,\n thread_id: context.threadTs,\n provider: context.provider,\n model: context.model,\n });\n}\n\nexport function registerTraceAttribution(\n span: { setAttributes(attributes: SentryAttributionAttributes): unknown },\n attributes: SentryAttributionAttributes,\n): void {\n span.setAttributes(attributes);\n const traceId = Sentry.spanToJSON(span as Parameters<typeof Sentry.spanToJSON>[0]).trace_id;\n if (!traceId) return;\n\n const now = Date.now();\n pruneExpiredTraceAttributions(now);\n traceAttribution.set(traceId, {\n attributes: { ...traceAttribution.get(traceId)?.attributes, ...attributes },\n expiresAt: now + TRACE_ATTRIBUTION_TTL_MS,\n });\n}\n\nexport function applyRunScope(scope: Scope, context: SentryRunScopeContext): void {\n const attributes = createRunAttributionAttributes(context);\n\n for (const [key, value] of Object.entries(attributes)) {\n scope.setTag(key, value);\n }\n scope.setAttributes(attributes);\n // Agent Monitoring groups spans by the platform session identifier.\n scope.setUser({ id: String(attributes.user_id) });\n scope.setConversationId(String(attributes.session_key));\n scope.setContext(\"agent_run\", {\n conversationId: attributes.conversation_id,\n channelId: attributes.channel_id,\n sessionKey: attributes.session_key,\n messageId: attributes.message_id,\n threadId: attributes.thread_id,\n platform: context.platform,\n conversationKind: context.conversationKind,\n provider: context.provider,\n model: context.model,\n });\n}\n\nexport function metricAttributes(\n attributes: Record<string, string | number | boolean | undefined>,\n): Record<string, string | number | boolean> {\n return Object.fromEntries(\n Object.entries(attributes).filter((entry): entry is [string, string | number | boolean] => {\n const [, value] = entry;\n return value !== undefined;\n }),\n );\n}\n\nfunction addLifecycleBreadcrumb(\n message: string,\n data?: Record<string, string | number | boolean | undefined>,\n): void {\n Sentry.addBreadcrumb({\n category: \"agent.lifecycle\",\n message,\n level: \"info\",\n data: data ? metricAttributes(data) : undefined,\n });\n}\n\nexport function sanitizeEvent<T extends Event>(event: T, _hint?: EventHint): T | null {\n const sanitized: T = {\n ...event,\n breadcrumbs: event.breadcrumbs\n ?.map((breadcrumb) => sanitizeBreadcrumb(breadcrumb))\n .filter((breadcrumb): breadcrumb is Breadcrumb => breadcrumb !== null),\n extra: sanitizeValue(event.extra) as T[\"extra\"],\n contexts: sanitizeValue(event.contexts) as T[\"contexts\"],\n request: sanitizeRequest(event.request),\n // Keep the identity applyRunScope set so Conversations show who sent each\n // message; drop anything else the SDK may have attached (email, IP).\n user: event.user ? { id: event.user.id, username: event.user.username } : undefined,\n server_name: undefined,\n };\n\n if (sanitized.message) {\n sanitized.message = sanitizeTelemetryString(sanitized.message);\n }\n\n if (sanitized.logentry) {\n sanitized.logentry = {\n ...sanitized.logentry,\n message: sanitized.logentry.message\n ? sanitizeTelemetryString(sanitized.logentry.message)\n : undefined,\n };\n }\n\n if (sanitized.exception?.values) {\n sanitized.exception.values = sanitized.exception.values.map((value) => ({\n ...value,\n value: value.value ? sanitizeTelemetryString(value.value) : value.value,\n stacktrace: value.stacktrace\n ? {\n ...value.stacktrace,\n frames: value.stacktrace.frames?.map((frame) => ({\n ...frame,\n filename: frame.filename ? sanitizeTelemetryString(frame.filename) : frame.filename,\n abs_path: frame.abs_path ? sanitizeTelemetryString(frame.abs_path) : frame.abs_path,\n vars: undefined,\n })),\n }\n : value.stacktrace,\n }));\n }\n\n return sanitized;\n}\n\nexport function applySpanAttribution<T extends SentrySpanPayload>(span: T): T {\n const attributes = getTraceAttribution(span.trace_id);\n if (!attributes) return span;\n return {\n ...span,\n data: {\n ...span.data,\n ...attributes,\n },\n };\n}\n\nfunction sanitizeTransactionEvent<T extends SentryTransactionPayload>(event: T): T | null {\n const sanitized = sanitizeEvent(event);\n if (!sanitized) return null;\n\n const traceContext = sanitized.contexts?.trace;\n const traceId = traceContext?.trace_id;\n if (typeof traceId !== \"string\") return sanitized;\n const attributes = getTraceAttribution(traceId);\n if (!attributes) return sanitized;\n\n const entries = (sanitized as { entries?: Array<{ type?: string; data?: unknown }> }).entries;\n for (const entry of entries ?? []) {\n if (entry.type !== \"spans\" || !Array.isArray(entry.data)) continue;\n entry.data = entry.data.map((span: SentrySpanPayload) => applySpanAttribution(span));\n }\n\n traceAttribution.delete(traceId);\n return sanitized;\n}\n\nexport function sanitizeBreadcrumb(breadcrumb: Breadcrumb): Breadcrumb | null {\n if (breadcrumb.category === \"console\") {\n return null;\n }\n\n return {\n ...breadcrumb,\n message: breadcrumb.message ? sanitizeTelemetryString(breadcrumb.message) : breadcrumb.message,\n data: sanitizeValue(breadcrumb.data) as Breadcrumb[\"data\"],\n };\n}\n\nexport function sanitizeValue(value: unknown, key?: string, depth = 0): unknown {\n if (value == null) return value;\n if (depth > MAX_DEPTH) return \"[Truncated]\";\n\n if (isSensitiveKey(key)) {\n return summarizeValue(value, key);\n }\n\n if (typeof value === \"string\") {\n return sanitizeTelemetryString(value);\n }\n\n if (Array.isArray(value)) {\n return value.slice(0, 20).map((entry) => sanitizeValue(entry, key, depth + 1));\n }\n\n if (typeof value === \"object\") {\n const entries = Object.entries(value as Record<string, unknown>).map(\n ([entryKey, entryValue]) => [entryKey, sanitizeValue(entryValue, entryKey, depth + 1)],\n );\n return Object.fromEntries(entries);\n }\n\n return value;\n}\n\nfunction sanitizeRequest(request: Event[\"request\"]): Event[\"request\"] {\n if (!request) return request;\n\n return {\n ...request,\n data: request.data ? summarizeValue(request.data, \"body\") : undefined,\n headers: undefined,\n cookies: undefined,\n };\n}\n\nfunction getTraceAttribution(traceId: string): SentryAttributionAttributes | undefined {\n const entry = traceAttribution.get(traceId);\n if (!entry) return undefined;\n if (entry.expiresAt > Date.now()) return entry.attributes;\n traceAttribution.delete(traceId);\n return undefined;\n}\n\nfunction pruneExpiredTraceAttributions(now: number): void {\n for (const [traceId, entry] of traceAttribution) {\n if (entry.expiresAt <= now) traceAttribution.delete(traceId);\n }\n}\n\nfunction isSensitiveKey(key?: string): boolean {\n if (!key) return false;\n return SENSITIVE_KEYS.has(key.toLowerCase().replace(/[^a-z0-9]/g, \"\"));\n}\n\nfunction summarizeValue(value: unknown, key?: string): string {\n const label = key ?? \"field\";\n if (typeof value === \"string\") {\n return `[Redacted ${label}; length=${value.length}]`;\n }\n if (Array.isArray(value)) {\n return `[Redacted ${label}; items=${value.length}]`;\n }\n if (value && typeof value === \"object\") {\n return `[Redacted ${label}; keys=${Object.keys(value as Record<string, unknown>).length}]`;\n }\n return `[Redacted ${label}]`;\n}\n\nexport function sanitizeTelemetryString(value: string): string {\n let sanitized = value.replace(new RegExp(ABSOLUTE_PATH_PATTERN, \"g\"), REDACTED_PATH);\n for (const pattern of TOKEN_PATTERNS) {\n sanitized = sanitized.replace(new RegExp(pattern, \"g\"), REDACTED);\n }\n if (sanitized.length > MAX_STRING_LENGTH) {\n return `${sanitized.slice(0, MAX_STRING_LENGTH)}… [truncated ${sanitized.length - MAX_STRING_LENGTH} chars]`;\n }\n return sanitized;\n}\n\n/**\n * Subagent outcomes that page. Everything else is a bounded, expected end\n * state the parent model already sees in the tool result: a budget or clock\n * ran out, the caller aborted, or a dependency failed upstream.\n */\nconst UNEXPECTED_SUBAGENT_STATUSES: ReadonlySet<SubagentOutcomeStatus> = new Set([\n \"failed\",\n \"invalid_output\",\n]);\n\n/**\n * Record one subagent outcome: a run counter and duration for every status,\n * a lifecycle breadcrumb, and a Sentry error only for statuses in\n * `UNEXPECTED_SUBAGENT_STATUSES`. Fingerprinted on the error's prefix before\n * the first colon so one failure class is one issue regardless of which\n * tool, file, or model message follows it.\n */\nexport function recordSubagentOutcome(report: SubagentOutcomeReport): string | undefined {\n const attributes = metricAttributes({\n status: report.status,\n profile: report.profile,\n mode: report.mode,\n });\n Sentry.metrics.count(\"agent.subagent.runs\", 1, { attributes });\n if (report.durationMs !== undefined) {\n Sentry.metrics.distribution(\"agent.subagent.duration\", report.durationMs, {\n unit: \"millisecond\",\n attributes,\n });\n }\n addLifecycleBreadcrumb(\"agent.subagent.completed\", {\n item_id: report.itemId,\n status: report.status,\n profile: report.profile,\n mode: report.mode,\n turns: report.turns,\n tool_calls: report.toolCalls,\n tokens: report.tokens,\n cost_usd: report.costUsd,\n duration_ms: report.durationMs,\n cleanup_pending: report.cleanupPending,\n });\n if (!UNEXPECTED_SUBAGENT_STATUSES.has(report.status)) return undefined;\n\n const errorClass = sanitizeTelemetryString(\n (report.error ?? report.status).split(\":\")[0]!.trim(),\n ).slice(0, MAX_FINGERPRINT_CLASS_LENGTH);\n return captureSentryError(\n new Error(`Subagent ${report.status}: ${report.error ?? \"no error detail\"}`),\n {\n domain: \"subagent\",\n surface: \"subagent_tool\",\n operation: \"run\",\n severity: \"error\",\n toolName: \"subagent\",\n fingerprint: [\"subagent\", report.status, errorClass],\n tags: {\n subagent_status: report.status,\n subagent_profile: report.profile,\n subagent_mode: report.mode,\n cleanup_pending: report.cleanupPending,\n },\n context: {\n itemId: report.itemId,\n error: report.error,\n turns: report.turns,\n toolCalls: report.toolCalls,\n tokens: report.tokens,\n costUsd: report.costUsd,\n durationMs: report.durationMs,\n },\n },\n );\n}\n\n/**\n * A subagent that never started: unknown profile, ungranted tool, or a\n * harness rejection. The throw still reaches the parent model as a tool\n * error; this only makes sure it also reaches Sentry.\n */\nexport function reportSubagentLaunchError(\n error: unknown,\n report: Pick<SubagentOutcomeReport, \"itemId\" | \"mode\" | \"profile\">,\n): string | undefined {\n return captureSentryError(error, {\n domain: \"subagent\",\n surface: \"subagent_tool\",\n operation: \"launch\",\n severity: \"error\",\n toolName: \"subagent\",\n tags: { subagent_profile: report.profile, subagent_mode: report.mode },\n context: { itemId: report.itemId },\n });\n}\n\n/**\n * Record one `evaluateWithJev` call's cost/duration, tagged by which call\n * site made it (the `jev` tool, `jev_browser`'s decision loop, Slack\n * auto-reply gating, task intent classification). Never receives the\n * judged state, questions, or answers — only the numbers.\n */\nexport function recordJevOutcome(report: JevOutcomeReport): void {\n const attributes = metricAttributes({ caller: report.caller, status: report.status });\n Sentry.metrics.count(\"agent.jev.calls\", 1, { attributes });\n if (report.costUsd !== undefined) {\n Sentry.metrics.distribution(\"agent.jev.cost\", report.costUsd, { attributes });\n }\n if (report.durationMs !== undefined) {\n Sentry.metrics.distribution(\"agent.jev.duration\", report.durationMs, {\n unit: \"millisecond\",\n attributes,\n });\n }\n addLifecycleBreadcrumb(\"agent.jev.completed\", {\n caller: report.caller,\n status: report.status,\n error_type: report.errorType,\n input_tokens: report.inputTokens,\n output_tokens: report.outputTokens,\n cost_usd: report.costUsd,\n duration_ms: report.durationMs,\n });\n}\n"]}
|