mesedi 0.1.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +81 -31
- package/dist/_errorClassesGenerated.d.ts +18 -0
- package/dist/_errorClassesGenerated.d.ts.map +1 -0
- package/dist/_errorClassesGenerated.js +24 -0
- package/dist/_errorClassesGenerated.js.map +1 -0
- package/dist/anthropic_integration.d.ts +9 -9
- package/dist/anthropic_integration.d.ts.map +1 -1
- package/dist/anthropic_integration.js +67 -26
- package/dist/anthropic_integration.js.map +1 -1
- package/dist/client.d.ts +32 -12
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +46 -18
- package/dist/client.js.map +1 -1
- package/dist/cohere_integration.d.ts +42 -0
- package/dist/cohere_integration.d.ts.map +1 -0
- package/dist/cohere_integration.js +456 -0
- package/dist/cohere_integration.js.map +1 -0
- package/dist/compress.d.ts +69 -0
- package/dist/compress.d.ts.map +1 -0
- package/dist/compress.js +75 -0
- package/dist/compress.js.map +1 -0
- package/dist/context.d.ts +13 -4
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +15 -5
- package/dist/context.js.map +1 -1
- package/dist/errors.d.ts +137 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +462 -0
- package/dist/errors.js.map +1 -0
- package/dist/events.d.ts +19 -6
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +31 -6
- package/dist/events.js.map +1 -1
- package/dist/gemini_integration.d.ts +33 -0
- package/dist/gemini_integration.d.ts.map +1 -0
- package/dist/gemini_integration.js +334 -0
- package/dist/gemini_integration.js.map +1 -0
- package/dist/halt.d.ts +12 -12
- package/dist/halt.js +16 -16
- package/dist/halt.js.map +1 -1
- package/dist/halt_stream.d.ts +6 -6
- package/dist/halt_stream.d.ts.map +1 -1
- package/dist/halt_stream.js +22 -12
- package/dist/halt_stream.js.map +1 -1
- package/dist/index.d.ts +26 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -12
- package/dist/index.js.map +1 -1
- package/dist/integrations/langgraph.d.ts +99 -0
- package/dist/integrations/langgraph.d.ts.map +1 -0
- package/dist/integrations/langgraph.js +572 -0
- package/dist/integrations/langgraph.js.map +1 -0
- package/dist/integrations/mastra.d.ts +114 -0
- package/dist/integrations/mastra.d.ts.map +1 -0
- package/dist/integrations/mastra.js +354 -0
- package/dist/integrations/mastra.js.map +1 -0
- package/dist/integrations/openai_agents.d.ts +66 -0
- package/dist/integrations/openai_agents.d.ts.map +1 -0
- package/dist/integrations/openai_agents.js +243 -0
- package/dist/integrations/openai_agents.js.map +1 -0
- package/dist/integrations/promptfoo.d.ts +62 -0
- package/dist/integrations/promptfoo.d.ts.map +1 -0
- package/dist/integrations/promptfoo.js +76 -0
- package/dist/integrations/promptfoo.js.map +1 -0
- package/dist/integrations/ragas.d.ts +65 -0
- package/dist/integrations/ragas.d.ts.map +1 -0
- package/dist/integrations/ragas.js +78 -0
- package/dist/integrations/ragas.js.map +1 -0
- package/dist/integrations/vectara.d.ts +60 -0
- package/dist/integrations/vectara.d.ts.map +1 -0
- package/dist/integrations/vectara.js +59 -0
- package/dist/integrations/vectara.js.map +1 -0
- package/dist/integrations/vercel_ai.d.ts +6 -6
- package/dist/integrations/vercel_ai.js +10 -10
- package/dist/integrations/vercel_ai.js.map +1 -1
- package/dist/observe.d.ts +358 -3
- package/dist/observe.d.ts.map +1 -1
- package/dist/observe.js +536 -4
- package/dist/observe.js.map +1 -1
- package/dist/ollama_integration.d.ts +126 -0
- package/dist/ollama_integration.d.ts.map +1 -0
- package/dist/ollama_integration.js +404 -0
- package/dist/ollama_integration.js.map +1 -0
- package/dist/openai_integration.d.ts +67 -0
- package/dist/openai_integration.d.ts.map +1 -0
- package/dist/openai_integration.js +574 -0
- package/dist/openai_integration.js.map +1 -0
- package/dist/tool.d.ts +1 -1
- package/dist/tool.d.ts.map +1 -1
- package/dist/tool.js +193 -10
- package/dist/tool.js.map +1 -1
- package/dist/truncate.d.ts +84 -0
- package/dist/truncate.d.ts.map +1 -0
- package/dist/truncate.js +134 -0
- package/dist/truncate.js.map +1 -0
- package/dist/vertex_gemini_integration.d.ts +27 -0
- package/dist/vertex_gemini_integration.d.ts.map +1 -0
- package/dist/vertex_gemini_integration.js +229 -0
- package/dist/vertex_gemini_integration.js.map +1 -0
- package/dist/wrap.d.ts +39 -3
- package/dist/wrap.d.ts.map +1 -1
- package/dist/wrap.js +15 -12
- package/dist/wrap.js.map +1 -1
- package/package.json +28 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EACL,iBAAiB,EACjB,gCAAgC,GACjC,MAAM,6BAA6B,CAAC;AAErC;;;;;;;uEAOuE;AACvE,MAAM,CAAC,MAAM,UAAU,GAAG,iBAAiB,CAAC;AAI5C;;;;GAIG;AACH,MAAM,CAAC,MAAM,2BAA2B,GACtC,gCAAgE,CAAC;AAEnE;;;;;;;GAOG;AACH,MAAM,uBAAuB,GAAoC;IAC/D,cAAc,EAAE,UAAU,CAAC,YAAY;IACvC,eAAe,EAAE,UAAU,CAAC,OAAO;IACnC,qBAAqB,EAAE,UAAU,CAAC,OAAO;IACzC,kBAAkB,EAAE,UAAU,CAAC,mBAAmB;IAClD,uBAAuB,EAAE,UAAU,CAAC,mBAAmB;IACvD,eAAe,EAAE,UAAU,CAAC,mBAAmB;IAC/C,mBAAmB,EAAE,UAAU,CAAC,cAAc;IAC9C,0BAA0B,EAAE,UAAU,CAAC,cAAc;IACrD,yBAAyB,EAAE,UAAU,CAAC,cAAc;IACpD,mBAAmB,EAAE,UAAU,CAAC,eAAe;IAC/C,qBAAqB,EAAE,UAAU,CAAC,eAAe;IACjD,eAAe,EAAE,UAAU,CAAC,YAAY;IACxC,aAAa,EAAE,UAAU,CAAC,YAAY;IACtC,aAAa,EAAE,UAAU,CAAC,YAA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AC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1D,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,qDAAqD;QACrD,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACzB,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YAAE,OAAO,SAAS,CAAC;QACvC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;IAC3D,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
package/dist/events.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Event types and execution records
|
|
2
|
+
* Event types and execution records, the TypeScript mirror of the Go
|
|
3
3
|
* backend's wire format and the Python SDK's data model.
|
|
4
4
|
*
|
|
5
5
|
* Source-of-truth lives in the Go backend at
|
|
6
6
|
* `backend/internal/events/types.go`. Any new EventType or Status
|
|
7
|
-
* added there MUST be added here too
|
|
7
|
+
* added there MUST be added here too, strict-JSON decoding on the
|
|
8
8
|
* backend will reject events whose fields it doesn't recognize.
|
|
9
9
|
*
|
|
10
10
|
* The wire format uses RFC 3339 UTC timestamps for every time field.
|
|
11
11
|
*/
|
|
12
12
|
/**
|
|
13
|
-
* RFC 3339 UTC timestamp with microsecond precision
|
|
13
|
+
* RFC 3339 UTC timestamp with microsecond precision, the format the
|
|
14
14
|
* Go backend's time.Time RFC3339 marshaller accepts. Example:
|
|
15
15
|
* "2026-05-14T22:17:33.123456Z".
|
|
16
16
|
*
|
|
@@ -32,6 +32,12 @@ export declare const EventType: {
|
|
|
32
32
|
readonly VALIDATOR_RESULT: "validator_result";
|
|
33
33
|
readonly DRIFT_SIGNAL: "drift_signal";
|
|
34
34
|
readonly INJECTION_ALERT: "injection_alert";
|
|
35
|
+
readonly INFRASTRUCTURE_EVENT: "infrastructure_event";
|
|
36
|
+
readonly MCP_CALL: "mcp_call";
|
|
37
|
+
readonly EVAL_SCORE: "eval_score";
|
|
38
|
+
readonly MEMORY_OPERATION: "memory_operation";
|
|
39
|
+
readonly AGENT_HANDOFF: "agent_handoff";
|
|
40
|
+
readonly HUMAN_INTERVENTION: "human_intervention";
|
|
35
41
|
};
|
|
36
42
|
export type EventType = (typeof EventType)[keyof typeof EventType];
|
|
37
43
|
/**
|
|
@@ -63,9 +69,16 @@ export interface Execution {
|
|
|
63
69
|
sdk_language: "typescript";
|
|
64
70
|
sdk_version: string;
|
|
65
71
|
crash_signature?: string;
|
|
72
|
+
/**
|
|
73
|
+
* Mesedi #5: optional per-execution tenant identifier from the
|
|
74
|
+
* host SaaS application. When set, surfaces in the cost-by-tenant
|
|
75
|
+
* report; absent means "not supplied" and the run rolls up under
|
|
76
|
+
* the "(unattributed)" bucket on the dashboard.
|
|
77
|
+
*/
|
|
78
|
+
tenant_id?: string;
|
|
66
79
|
}
|
|
67
80
|
/**
|
|
68
|
-
* A single observation within an execution. Payload is opaque JSON
|
|
81
|
+
* A single observation within an execution. Payload is opaque JSON ,
|
|
69
82
|
* the backend stores it as a raw blob; per-event-type payload shapes
|
|
70
83
|
* are defined in the typed payload helpers below.
|
|
71
84
|
*/
|
|
@@ -79,12 +92,12 @@ export interface Event {
|
|
|
79
92
|
payload: Record<string, unknown>;
|
|
80
93
|
}
|
|
81
94
|
/**
|
|
82
|
-
* Build the body for POST /executions
|
|
95
|
+
* Build the body for POST /executions, only the fields valid at
|
|
83
96
|
* execution start.
|
|
84
97
|
*/
|
|
85
98
|
export declare function executionStartPayload(e: Execution): Record<string, unknown>;
|
|
86
99
|
/**
|
|
87
|
-
* Build the body for PATCH /executions/{id}
|
|
100
|
+
* Build the body for PATCH /executions/{id}, omit any undefined
|
|
88
101
|
* fields so the backend's strict-decode doesn't reject them.
|
|
89
102
|
*/
|
|
90
103
|
export declare function executionEndPayload(e: Execution): Record<string, unknown>;
|
package/dist/events.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH;;;;;;;;;GASG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAMtC;AAED;;;GAGG;AACH,eAAO,MAAM,SAAS
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH;;;;;;;;;GASG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAMtC;AAED;;;GAGG;AACH,eAAO,MAAM,SAAS;;;;;;;;;;;;;;CA8BZ,CAAC;AACX,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,OAAO,SAAS,CAAC,CAAC;AAEnE;;;GAGG;AACH,eAAO,MAAM,MAAM;;;;;;;CAOT,CAAC;AACX,MAAM,MAAM,MAAM,GAAG,CAAC,OAAO,MAAM,CAAC,CAAC,MAAM,OAAO,MAAM,CAAC,CAAC;AAE1D;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,YAAY,EAAE,YAAY,CAAC;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;GAIG;AACH,MAAM,WAAW,KAAK;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,SAAS,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAU3E;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CASzE;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAW7D"}
|
package/dist/events.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Event types and execution records
|
|
2
|
+
* Event types and execution records, the TypeScript mirror of the Go
|
|
3
3
|
* backend's wire format and the Python SDK's data model.
|
|
4
4
|
*
|
|
5
5
|
* Source-of-truth lives in the Go backend at
|
|
6
6
|
* `backend/internal/events/types.go`. Any new EventType or Status
|
|
7
|
-
* added there MUST be added here too
|
|
7
|
+
* added there MUST be added here too, strict-JSON decoding on the
|
|
8
8
|
* backend will reject events whose fields it doesn't recognize.
|
|
9
9
|
*
|
|
10
10
|
* The wire format uses RFC 3339 UTC timestamps for every time field.
|
|
11
11
|
*/
|
|
12
12
|
/**
|
|
13
|
-
* RFC 3339 UTC timestamp with microsecond precision
|
|
13
|
+
* RFC 3339 UTC timestamp with microsecond precision, the format the
|
|
14
14
|
* Go backend's time.Time RFC3339 marshaller accepts. Example:
|
|
15
15
|
* "2026-05-14T22:17:33.123456Z".
|
|
16
16
|
*
|
|
@@ -38,6 +38,28 @@ export const EventType = {
|
|
|
38
38
|
VALIDATOR_RESULT: "validator_result",
|
|
39
39
|
DRIFT_SIGNAL: "drift_signal",
|
|
40
40
|
INJECTION_ALERT: "injection_alert",
|
|
41
|
+
// Mesedi #2: transport-plane backpressure (HTTP 429, circuit breaker
|
|
42
|
+
// trip, hard quota exhaustion). Consumed by the
|
|
43
|
+
// infrastructure_throttled detector on the backend.
|
|
44
|
+
INFRASTRUCTURE_EVENT: "infrastructure_event",
|
|
45
|
+
// Mesedi #7: Model Context Protocol server invocation. Peer to
|
|
46
|
+
// TOOL_CALL but with explicit server identity so cost / failure
|
|
47
|
+
// attribution can break down per MCP server.
|
|
48
|
+
MCP_CALL: "mcp_call",
|
|
49
|
+
// Mesedi #9: external evaluator score (Ragas / Promptfoo / HHEM
|
|
50
|
+
// / custom). Ingestion-only; Mesedi #14 aggregates these into
|
|
51
|
+
// grounding_failure clusters.
|
|
52
|
+
EVAL_SCORE: "eval_score",
|
|
53
|
+
// Mesedi #15: external memory store read/write/search.
|
|
54
|
+
MEMORY_OPERATION: "memory_operation",
|
|
55
|
+
// Mesedi #11: cross-agent task delegation. The downstream
|
|
56
|
+
// cascading_failure detector (#12) correlates the handoff with
|
|
57
|
+
// the resolved child execution via the topology graph (#10).
|
|
58
|
+
AGENT_HANDOFF: "agent_handoff",
|
|
59
|
+
// Mesedi #19: one full HITL ask/answer cycle. Emitted at the
|
|
60
|
+
// moment the human's decision lands. Aggregated by the
|
|
61
|
+
// hitl_timeout (#20) and hitl_rejection_spike (#21) detectors.
|
|
62
|
+
HUMAN_INTERVENTION: "human_intervention",
|
|
41
63
|
};
|
|
42
64
|
/**
|
|
43
65
|
* Execution lifecycle states. Must match `ExecutionStatus` constants
|
|
@@ -52,20 +74,23 @@ export const Status = {
|
|
|
52
74
|
VALIDATION_FAILED: "validation_failed",
|
|
53
75
|
};
|
|
54
76
|
/**
|
|
55
|
-
* Build the body for POST /executions
|
|
77
|
+
* Build the body for POST /executions, only the fields valid at
|
|
56
78
|
* execution start.
|
|
57
79
|
*/
|
|
58
80
|
export function executionStartPayload(e) {
|
|
59
|
-
|
|
81
|
+
const out = {
|
|
60
82
|
execution_id: e.execution_id,
|
|
61
83
|
status: e.status,
|
|
62
84
|
started_at: e.started_at,
|
|
63
85
|
sdk_language: e.sdk_language,
|
|
64
86
|
sdk_version: e.sdk_version,
|
|
65
87
|
};
|
|
88
|
+
if (e.tenant_id !== undefined)
|
|
89
|
+
out["tenant_id"] = e.tenant_id;
|
|
90
|
+
return out;
|
|
66
91
|
}
|
|
67
92
|
/**
|
|
68
|
-
* Build the body for PATCH /executions/{id}
|
|
93
|
+
* Build the body for PATCH /executions/{id}, omit any undefined
|
|
69
94
|
* fields so the backend's strict-decode doesn't reject them.
|
|
70
95
|
*/
|
|
71
96
|
export function executionEndPayload(e) {
|
package/dist/events.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH;;;;;;;;;GASG;AACH,MAAM,UAAU,aAAa;IAC3B,MAAM,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC;IACrB,oEAAoE;IACpE,iEAAiE;IACjE,yDAAyD;IACzD,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AAC/C,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,QAAQ,EAAE,UAAU;IACpB,SAAS,EAAE,WAAW;IACtB,UAAU,EAAE,YAAY;IACxB,SAAS,EAAE,WAAW;IACtB,gBAAgB,EAAE,kBAAkB;IACpC,YAAY,EAAE,cAAc;IAC5B,eAAe,EAAE,iBAAiB;
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH;;;;;;;;;GASG;AACH,MAAM,UAAU,aAAa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C,CAAC,QAAQ;QACpB,SAAS,EAAE,CAAC,CAAC,SAAS;QACtB,OAAO,EAAE,CAAC,CAAC,OAAO;KACnB,CAAC;IACF,IAAI,CAAC,CAAC,WAAW,KAAK,SAAS;QAAE,GAAG,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,WAAW,CAAC;IACpE,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Google Gemini TypeScript SDK monkey-patch — auto-emit llm_call
|
|
3
|
+
* events for every GenerativeModel.generateContent() call inside a
|
|
4
|
+
* wrap()'d execution.
|
|
5
|
+
*
|
|
6
|
+
* Targets the @google/generative-ai package (the dominant non-
|
|
7
|
+
* Vertex Gemini TS surface). Mirrors instrumentAnthropic /
|
|
8
|
+
* instrumentOpenAI / instrumentCohere in fail-open semantics,
|
|
9
|
+
* canonical error vocabulary, idempotency.
|
|
10
|
+
*
|
|
11
|
+
* Out of scope (filed as #271 follow-ups):
|
|
12
|
+
* - generateContentStream / chat sessions
|
|
13
|
+
* - Vertex AI surface (@google-cloud/vertexai)
|
|
14
|
+
*
|
|
15
|
+
* Dependency injection: instrumentGemini accepts an optional class
|
|
16
|
+
* argument so this is testable without installing the package.
|
|
17
|
+
*/
|
|
18
|
+
export interface GenerativeModelClassLike {
|
|
19
|
+
prototype: {
|
|
20
|
+
generateContent: (...args: any[]) => Promise<any>;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/** Patch GenerativeModel.generateContent to emit llm_call events. */
|
|
24
|
+
export declare function instrumentGemini(modelClass?: GenerativeModelClassLike): Promise<boolean>;
|
|
25
|
+
export interface GenerativeModelEmbedClassLike {
|
|
26
|
+
prototype: {
|
|
27
|
+
embedContent: (...args: any[]) => Promise<any>;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** Patch GenerativeModel.embedContent to emit
|
|
31
|
+
* surface='embeddings' llm_call events. Idempotent per class. */
|
|
32
|
+
export declare function patchGeminiEmbedContent(cls: GenerativeModelEmbedClassLike): void;
|
|
33
|
+
//# sourceMappingURL=gemini_integration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gemini_integration.d.ts","sourceRoot":"","sources":["../src/gemini_integration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAqBH,MAAM,WAAW,wBAAwB;IAEvC,SAAS,EAAE;QAAE,eAAe,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;KAAE,CAAC;CAClE;AAqBD,qEAAqE;AACrE,wBAAsB,gBAAgB,CACpC,UAAU,CAAC,EAAE,wBAAwB,GACpC,OAAO,CAAC,OAAO,CAAC,CA8HlB;AAmFD,MAAM,WAAW,6BAA6B;IAE5C,SAAS,EAAE;QAAE,YAAY,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;KAAE,CAAC;CAC/D;AAkBD;iEACiE;AACjE,wBAAgB,uBAAuB,CACrC,GAAG,EAAE,6BAA6B,GACjC,IAAI,CA+FN"}
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Google Gemini TypeScript SDK monkey-patch — auto-emit llm_call
|
|
3
|
+
* events for every GenerativeModel.generateContent() call inside a
|
|
4
|
+
* wrap()'d execution.
|
|
5
|
+
*
|
|
6
|
+
* Targets the @google/generative-ai package (the dominant non-
|
|
7
|
+
* Vertex Gemini TS surface). Mirrors instrumentAnthropic /
|
|
8
|
+
* instrumentOpenAI / instrumentCohere in fail-open semantics,
|
|
9
|
+
* canonical error vocabulary, idempotency.
|
|
10
|
+
*
|
|
11
|
+
* Out of scope (filed as #271 follow-ups):
|
|
12
|
+
* - generateContentStream / chat sessions
|
|
13
|
+
* - Vertex AI surface (@google-cloud/vertexai)
|
|
14
|
+
*
|
|
15
|
+
* Dependency injection: instrumentGemini accepts an optional class
|
|
16
|
+
* argument so this is testable without installing the package.
|
|
17
|
+
*/
|
|
18
|
+
import { getClient } from "./client.js";
|
|
19
|
+
import { currentExecutionContext, newEventId } from "./context.js";
|
|
20
|
+
import { classifyGeminiException, extractHttpStatus, extractRetryAfter, } from "./errors.js";
|
|
21
|
+
import { EventType, utcNowRfc3339 } from "./events.js";
|
|
22
|
+
import { _maybeEmitThrottlingEvent } from "./observe.js";
|
|
23
|
+
const MAX_SYSTEM = 1000;
|
|
24
|
+
const MAX_USER_MSG = 1000;
|
|
25
|
+
const MAX_RESPONSE = 1000;
|
|
26
|
+
const MAX_EXC_MSG = 500;
|
|
27
|
+
const PROVIDER = "gemini";
|
|
28
|
+
const _patched = new WeakSet();
|
|
29
|
+
/** Patch GenerativeModel.generateContent to emit llm_call events. */
|
|
30
|
+
export async function instrumentGemini(modelClass) {
|
|
31
|
+
let cls = modelClass;
|
|
32
|
+
if (!cls) {
|
|
33
|
+
try {
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
35
|
+
// @ts-ignore — package may not be installed; by design.
|
|
36
|
+
const mod = (await import("@google/generative-ai"));
|
|
37
|
+
cls = mod?.GenerativeModel;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
console.warn("mesedi: @google/generative-ai not installed; instrumentGemini() is a no-op. " +
|
|
41
|
+
"Install with `npm install @google/generative-ai` to enable.");
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
if (!cls)
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
if (_patched.has(cls))
|
|
48
|
+
return true;
|
|
49
|
+
const originalGenerate = cls.prototype.generateContent;
|
|
50
|
+
cls.prototype.generateContent = async function patchedGenerate(...args) {
|
|
51
|
+
const ctx = currentExecutionContext();
|
|
52
|
+
if (!ctx)
|
|
53
|
+
return originalGenerate.apply(this, args);
|
|
54
|
+
ctx.checkBudget();
|
|
55
|
+
if (ctx.budgetTracker)
|
|
56
|
+
ctx.budgetTracker.incrementSteps();
|
|
57
|
+
const client = getClient();
|
|
58
|
+
const sequence = ctx.nextSequence();
|
|
59
|
+
const eventId = newEventId();
|
|
60
|
+
const selfRecord = this;
|
|
61
|
+
const model = typeof selfRecord.model === "string"
|
|
62
|
+
? selfRecord.model
|
|
63
|
+
: typeof selfRecord.modelName === "string"
|
|
64
|
+
? selfRecord.modelName
|
|
65
|
+
: "unknown";
|
|
66
|
+
// System instruction is set when the GenerativeModel is
|
|
67
|
+
// constructed (`systemInstruction` option). It surfaces on the
|
|
68
|
+
// instance as `systemInstruction` (string OR Content object).
|
|
69
|
+
const systemRaw = selfRecord.systemInstruction;
|
|
70
|
+
const systemText = stringifyContent(systemRaw);
|
|
71
|
+
const userMessage = extractUserMessage(args[0]);
|
|
72
|
+
const start = performance.now();
|
|
73
|
+
try {
|
|
74
|
+
const response = (await originalGenerate.apply(this, args));
|
|
75
|
+
const durationMs = Math.round(performance.now() - start);
|
|
76
|
+
const { responseText, inputTokens, outputTokens } = extractResponseFields(response);
|
|
77
|
+
if (ctx.budgetTracker)
|
|
78
|
+
ctx.budgetTracker.addTokens(inputTokens, outputTokens);
|
|
79
|
+
client.submitEvent({
|
|
80
|
+
event_id: eventId,
|
|
81
|
+
execution_id: ctx.executionId,
|
|
82
|
+
event_type: EventType.LLM_CALL,
|
|
83
|
+
sequence,
|
|
84
|
+
timestamp: utcNowRfc3339(),
|
|
85
|
+
duration_ms: durationMs,
|
|
86
|
+
payload: {
|
|
87
|
+
provider: PROVIDER,
|
|
88
|
+
surface: "chat",
|
|
89
|
+
model,
|
|
90
|
+
system_prompt: truncate(systemText, MAX_SYSTEM),
|
|
91
|
+
user_message: truncate(userMessage, MAX_USER_MSG),
|
|
92
|
+
response_text: truncate(responseText, MAX_RESPONSE),
|
|
93
|
+
status: "ok",
|
|
94
|
+
input_tokens: inputTokens,
|
|
95
|
+
output_tokens: outputTokens,
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
return response;
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
const durationMs = Math.round(performance.now() - start);
|
|
102
|
+
const failurePayload = {
|
|
103
|
+
provider: PROVIDER,
|
|
104
|
+
surface: "chat",
|
|
105
|
+
model,
|
|
106
|
+
system_prompt: truncate(systemText, MAX_SYSTEM),
|
|
107
|
+
user_message: truncate(userMessage, MAX_USER_MSG),
|
|
108
|
+
status: "failed",
|
|
109
|
+
error_class: classifyGeminiException(err),
|
|
110
|
+
exception_type: err instanceof Error && err.constructor.name
|
|
111
|
+
? err.constructor.name
|
|
112
|
+
: typeof err,
|
|
113
|
+
exception_message: truncate(err instanceof Error ? err.message : String(err), MAX_EXC_MSG),
|
|
114
|
+
};
|
|
115
|
+
const httpStatus = extractHttpStatus(err);
|
|
116
|
+
if (httpStatus !== undefined)
|
|
117
|
+
failurePayload.http_status = httpStatus;
|
|
118
|
+
const retryAfter = extractRetryAfter(err);
|
|
119
|
+
if (retryAfter !== undefined)
|
|
120
|
+
failurePayload.retry_after_seconds = retryAfter;
|
|
121
|
+
client.submitEvent({
|
|
122
|
+
event_id: eventId,
|
|
123
|
+
execution_id: ctx.executionId,
|
|
124
|
+
event_type: EventType.LLM_CALL,
|
|
125
|
+
sequence,
|
|
126
|
+
timestamp: utcNowRfc3339(),
|
|
127
|
+
duration_ms: durationMs,
|
|
128
|
+
payload: failurePayload,
|
|
129
|
+
});
|
|
130
|
+
// Wave 1.4: auto-emit infrastructure_event on throttling-class
|
|
131
|
+
// exceptions so infrastructure_throttled isn't silently inactive.
|
|
132
|
+
_maybeEmitThrottlingEvent({
|
|
133
|
+
provider: PROVIDER,
|
|
134
|
+
errorClass: failurePayload.error_class,
|
|
135
|
+
httpStatus,
|
|
136
|
+
retryAfterSeconds: retryAfter,
|
|
137
|
+
endpoint: "/v1/models/generateContent",
|
|
138
|
+
});
|
|
139
|
+
throw err;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
_patched.add(cls);
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
function extractUserMessage(arg) {
|
|
146
|
+
if (typeof arg === "string")
|
|
147
|
+
return arg;
|
|
148
|
+
if (Array.isArray(arg)) {
|
|
149
|
+
// Array of strings OR Content objects. Walk for the last
|
|
150
|
+
// role:user (or any role-less string) entry.
|
|
151
|
+
for (let i = arg.length - 1; i >= 0; i--) {
|
|
152
|
+
const item = arg[i];
|
|
153
|
+
if (typeof item === "string")
|
|
154
|
+
return item;
|
|
155
|
+
if (item && typeof item === "object") {
|
|
156
|
+
const obj = item;
|
|
157
|
+
if (obj.role && obj.role !== "user")
|
|
158
|
+
continue;
|
|
159
|
+
if (typeof obj.text === "string")
|
|
160
|
+
return obj.text;
|
|
161
|
+
if (Array.isArray(obj.parts)) {
|
|
162
|
+
const parts = [];
|
|
163
|
+
for (const p of obj.parts) {
|
|
164
|
+
if (typeof p?.text === "string")
|
|
165
|
+
parts.push(p.text);
|
|
166
|
+
}
|
|
167
|
+
return parts.join("\n");
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return "";
|
|
172
|
+
}
|
|
173
|
+
if (arg && typeof arg === "object") {
|
|
174
|
+
// GenerateContentRequest-like: { contents: [...] }
|
|
175
|
+
const obj = arg;
|
|
176
|
+
if (obj.contents !== undefined)
|
|
177
|
+
return extractUserMessage(obj.contents);
|
|
178
|
+
}
|
|
179
|
+
return "";
|
|
180
|
+
}
|
|
181
|
+
function stringifyContent(content) {
|
|
182
|
+
if (typeof content === "string")
|
|
183
|
+
return content;
|
|
184
|
+
if (!content || typeof content !== "object")
|
|
185
|
+
return "";
|
|
186
|
+
const obj = content;
|
|
187
|
+
if (typeof obj.text === "string")
|
|
188
|
+
return obj.text;
|
|
189
|
+
if (Array.isArray(obj.parts)) {
|
|
190
|
+
const bits = [];
|
|
191
|
+
for (const p of obj.parts) {
|
|
192
|
+
if (typeof p?.text === "string")
|
|
193
|
+
bits.push(p.text);
|
|
194
|
+
}
|
|
195
|
+
return bits.join("\n");
|
|
196
|
+
}
|
|
197
|
+
return "";
|
|
198
|
+
}
|
|
199
|
+
function extractResponseFields(response) {
|
|
200
|
+
let responseText = "";
|
|
201
|
+
let inputTokens = 0;
|
|
202
|
+
let outputTokens = 0;
|
|
203
|
+
try {
|
|
204
|
+
if (typeof response?.response?.text === "function") {
|
|
205
|
+
const text = response.response.text();
|
|
206
|
+
if (typeof text === "string")
|
|
207
|
+
responseText = text;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
catch {
|
|
211
|
+
/* best-effort */
|
|
212
|
+
}
|
|
213
|
+
try {
|
|
214
|
+
const usage = response?.response?.usageMetadata;
|
|
215
|
+
if (usage) {
|
|
216
|
+
inputTokens = Number(usage.promptTokenCount ?? 0) || 0;
|
|
217
|
+
outputTokens = Number(usage.candidatesTokenCount ?? 0) || 0;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
catch {
|
|
221
|
+
/* best-effort */
|
|
222
|
+
}
|
|
223
|
+
return { responseText, inputTokens, outputTokens };
|
|
224
|
+
}
|
|
225
|
+
function truncate(s, max) {
|
|
226
|
+
if (s.length <= max)
|
|
227
|
+
return s;
|
|
228
|
+
return s.slice(0, max - 3) + "...";
|
|
229
|
+
}
|
|
230
|
+
const _embedPatched = new WeakSet();
|
|
231
|
+
function extractEmbedContentInput(arg) {
|
|
232
|
+
if (typeof arg === "string")
|
|
233
|
+
return arg;
|
|
234
|
+
if (arg && typeof arg === "object") {
|
|
235
|
+
const obj = arg;
|
|
236
|
+
if (obj.content !== undefined) {
|
|
237
|
+
const c = obj.content;
|
|
238
|
+
if (typeof c === "string")
|
|
239
|
+
return c;
|
|
240
|
+
return stringifyContent(c);
|
|
241
|
+
}
|
|
242
|
+
return stringifyContent(arg);
|
|
243
|
+
}
|
|
244
|
+
return "";
|
|
245
|
+
}
|
|
246
|
+
/** Patch GenerativeModel.embedContent to emit
|
|
247
|
+
* surface='embeddings' llm_call events. Idempotent per class. */
|
|
248
|
+
export function patchGeminiEmbedContent(cls) {
|
|
249
|
+
if (_embedPatched.has(cls))
|
|
250
|
+
return;
|
|
251
|
+
const originalEmbed = cls.prototype.embedContent;
|
|
252
|
+
cls.prototype.embedContent = async function patchedEmbed(...args) {
|
|
253
|
+
const ctx = currentExecutionContext();
|
|
254
|
+
if (!ctx)
|
|
255
|
+
return originalEmbed.apply(this, args);
|
|
256
|
+
ctx.checkBudget();
|
|
257
|
+
if (ctx.budgetTracker)
|
|
258
|
+
ctx.budgetTracker.incrementSteps();
|
|
259
|
+
const client = getClient();
|
|
260
|
+
const sequence = ctx.nextSequence();
|
|
261
|
+
const eventId = newEventId();
|
|
262
|
+
const selfRecord = this;
|
|
263
|
+
const model = typeof selfRecord.model === "string"
|
|
264
|
+
? selfRecord.model
|
|
265
|
+
: typeof selfRecord.modelName === "string"
|
|
266
|
+
? selfRecord.modelName
|
|
267
|
+
: "unknown";
|
|
268
|
+
const userMessage = extractEmbedContentInput(args[0]);
|
|
269
|
+
const start = performance.now();
|
|
270
|
+
try {
|
|
271
|
+
const response = await originalEmbed.apply(this, args);
|
|
272
|
+
const durationMs = Math.round(performance.now() - start);
|
|
273
|
+
client.submitEvent({
|
|
274
|
+
event_id: eventId,
|
|
275
|
+
execution_id: ctx.executionId,
|
|
276
|
+
event_type: EventType.LLM_CALL,
|
|
277
|
+
sequence,
|
|
278
|
+
timestamp: utcNowRfc3339(),
|
|
279
|
+
duration_ms: durationMs,
|
|
280
|
+
payload: {
|
|
281
|
+
provider: PROVIDER,
|
|
282
|
+
surface: "embeddings",
|
|
283
|
+
model,
|
|
284
|
+
user_message: truncate(userMessage, MAX_USER_MSG),
|
|
285
|
+
response_text: "<embedding vectors>",
|
|
286
|
+
status: "ok",
|
|
287
|
+
input_tokens: 0,
|
|
288
|
+
output_tokens: 0,
|
|
289
|
+
},
|
|
290
|
+
});
|
|
291
|
+
return response;
|
|
292
|
+
}
|
|
293
|
+
catch (err) {
|
|
294
|
+
const durationMs = Math.round(performance.now() - start);
|
|
295
|
+
const failurePayload = {
|
|
296
|
+
provider: PROVIDER,
|
|
297
|
+
surface: "embeddings",
|
|
298
|
+
model,
|
|
299
|
+
user_message: truncate(userMessage, MAX_USER_MSG),
|
|
300
|
+
status: "failed",
|
|
301
|
+
error_class: classifyGeminiException(err),
|
|
302
|
+
exception_type: err instanceof Error && err.constructor.name
|
|
303
|
+
? err.constructor.name
|
|
304
|
+
: typeof err,
|
|
305
|
+
exception_message: truncate(err instanceof Error ? err.message : String(err), MAX_EXC_MSG),
|
|
306
|
+
};
|
|
307
|
+
const httpStatus = extractHttpStatus(err);
|
|
308
|
+
if (httpStatus !== undefined)
|
|
309
|
+
failurePayload.http_status = httpStatus;
|
|
310
|
+
const retryAfter = extractRetryAfter(err);
|
|
311
|
+
if (retryAfter !== undefined)
|
|
312
|
+
failurePayload.retry_after_seconds = retryAfter;
|
|
313
|
+
client.submitEvent({
|
|
314
|
+
event_id: eventId,
|
|
315
|
+
execution_id: ctx.executionId,
|
|
316
|
+
event_type: EventType.LLM_CALL,
|
|
317
|
+
sequence,
|
|
318
|
+
timestamp: utcNowRfc3339(),
|
|
319
|
+
duration_ms: durationMs,
|
|
320
|
+
payload: failurePayload,
|
|
321
|
+
});
|
|
322
|
+
_maybeEmitThrottlingEvent({
|
|
323
|
+
provider: PROVIDER,
|
|
324
|
+
errorClass: failurePayload.error_class,
|
|
325
|
+
httpStatus,
|
|
326
|
+
retryAfterSeconds: retryAfter,
|
|
327
|
+
endpoint: "/v1/models/embedContent",
|
|
328
|
+
});
|
|
329
|
+
throw err;
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
_embedPatched.add(cls);
|
|
333
|
+
}
|
|
334
|
+
//# sourceMappingURL=gemini_integration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gemini_integration.js","sourceRoot":"","sources":["../src/gemini_integration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EA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UAAU,CAAC;YAC9E,MAAM,CAAC,WAAW,CAAC;gBACjB,QAAQ,EAAE,OAAO;gBACjB,YAAY,EAAE,GAAG,CAAC,WAAW;gBAC7B,UAAU,EAAE,SAAS,CAAC,QAAQ;gBAC9B,QAAQ;gBACR,SAAS,EAAE,aAAa,EAAE;gBAC1B,WAAW,EAAE,UAAU;gBACvB,OAAO,EAAE,cAAc;aACxB,CAAC,CAAC;YACH,yBAAyB,CAAC;gBACxB,QAAQ,EAAE,QAAQ;gBAClB,UAAU,EAAE,cAAc,CAAC,WAAqB;gBAChD,UAAU;gBACV,iBAAiB,EAAE,UAAU;gBAC7B,QAAQ,EAAE,yBAAyB;aACpC,CAAC,CAAC;YACH,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAA4D,CAAC;IAE7D,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC"}
|
package/dist/halt.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Hard-halt primitives
|
|
2
|
+
* Hard-halt primitives, TypeScript port of the Python `mesedi/halt.py`.
|
|
3
3
|
*
|
|
4
4
|
* Three exports:
|
|
5
5
|
*
|
|
6
|
-
* - `Budget
|
|
6
|
+
* - `Budget`: interface describing the per-execution limits
|
|
7
7
|
* (wall-clock seconds, step count, input/output
|
|
8
8
|
* tokens). Any subset of fields can be set; unset
|
|
9
9
|
* fields are "no limit on that axis."
|
|
10
10
|
*
|
|
11
|
-
* - `MesediHalt
|
|
11
|
+
* - `MesediHalt`, Error subclass that the runtime throws when a
|
|
12
12
|
* `Budget` is exceeded. Carries a `reason` and a
|
|
13
13
|
* `trigger` so callers / dashboards can tell which
|
|
14
14
|
* axis blew the budget. Marked with an internal
|
|
@@ -17,15 +17,15 @@
|
|
|
17
17
|
* `try { ... } catch (err) { ... }` and re-threw
|
|
18
18
|
* something else.
|
|
19
19
|
*
|
|
20
|
-
* - `BudgetTracker
|
|
20
|
+
* - `BudgetTracker`, runtime counter struct. One per execution.
|
|
21
21
|
* Tracks wall-clock start (via `performance.now()`
|
|
22
|
-
|
|
22
|
+
*: JS's monotonic clock equivalent of Python's
|
|
23
23
|
* `time.monotonic()`), step count, token totals.
|
|
24
24
|
* `check()` throws MesediHalt if any limit is
|
|
25
25
|
* exceeded; the wrap()'d entry points call it as
|
|
26
26
|
* a halt-safe boundary BEFORE doing work, so the
|
|
27
27
|
* halt always fires between tool/llm/checkpoint
|
|
28
|
-
* calls
|
|
28
|
+
* calls, never mid-call.
|
|
29
29
|
*
|
|
30
30
|
* Cross-language wire-format parity:
|
|
31
31
|
*
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
* Why a marker Symbol on MesediHalt:
|
|
45
45
|
*
|
|
46
46
|
* In Python, `MesediHalt(BaseException)` evades `except Exception:`
|
|
47
|
-
* handlers
|
|
47
|
+
* handlers, broad except blocks miss it. JavaScript has no
|
|
48
48
|
* equivalent of BaseException; `catch (err)` always catches
|
|
49
49
|
* everything. So we mark MesediHalt with a hidden Symbol-keyed
|
|
50
50
|
* property and `wrap()` looks for that symbol, not just an
|
|
@@ -84,7 +84,7 @@ export interface Budget {
|
|
|
84
84
|
*/
|
|
85
85
|
declare const MESEDI_HALT_MARKER: unique symbol;
|
|
86
86
|
/**
|
|
87
|
-
* Trigger that caused a halt
|
|
87
|
+
* Trigger that caused a halt, embedded in the crash_signature
|
|
88
88
|
* (`halt:wall_clock`) so the dashboard groups halts by cause.
|
|
89
89
|
*/
|
|
90
90
|
export type HaltTrigger = "wall_clock" | "step_count" | "token_total" | "remote_signal";
|
|
@@ -110,15 +110,15 @@ export declare class MesediHalt extends Error {
|
|
|
110
110
|
export declare function isMesediHalt(err: unknown): err is MesediHalt;
|
|
111
111
|
/**
|
|
112
112
|
* Runtime counter struct. One instance per execution, lives on the
|
|
113
|
-
* ExecutionContext. Thread-safety isn't a concern in Node
|
|
114
|
-
* single-threaded event loop guarantees serial access
|
|
113
|
+
* ExecutionContext. Thread-safety isn't a concern in Node, the
|
|
114
|
+
* single-threaded event loop guarantees serial access, but the
|
|
115
115
|
* counter writes still need to be coherent across async boundaries,
|
|
116
116
|
* which AsyncLocalStorage gives us for free.
|
|
117
117
|
*
|
|
118
118
|
* `check()` is the halt-safe boundary. Callers (tool, anthropic
|
|
119
119
|
* patch, checkpoint) call it FIRST, then increment counters. If any
|
|
120
120
|
* limit is already exceeded at the time of check, a MesediHalt is
|
|
121
|
-
* thrown
|
|
121
|
+
* thrown, the caller's work is never started.
|
|
122
122
|
*/
|
|
123
123
|
export declare class BudgetTracker {
|
|
124
124
|
private readonly budget;
|
|
@@ -136,7 +136,7 @@ export declare class BudgetTracker {
|
|
|
136
136
|
* `check()` call will throw `MesediHalt(trigger='remote_signal')`
|
|
137
137
|
* with the supplied reason.
|
|
138
138
|
*
|
|
139
|
-
* Idempotent
|
|
139
|
+
* Idempotent, multiple signals overwrite the reason (last one
|
|
140
140
|
* wins). Concurrency is fine: Node's single-threaded event loop
|
|
141
141
|
* means the reader thread's write and the agent thread's read
|
|
142
142
|
* can't interleave at the JS level.
|