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.
Files changed (104) hide show
  1. package/README.md +81 -31
  2. package/dist/_errorClassesGenerated.d.ts +18 -0
  3. package/dist/_errorClassesGenerated.d.ts.map +1 -0
  4. package/dist/_errorClassesGenerated.js +24 -0
  5. package/dist/_errorClassesGenerated.js.map +1 -0
  6. package/dist/anthropic_integration.d.ts +9 -9
  7. package/dist/anthropic_integration.d.ts.map +1 -1
  8. package/dist/anthropic_integration.js +67 -26
  9. package/dist/anthropic_integration.js.map +1 -1
  10. package/dist/client.d.ts +32 -12
  11. package/dist/client.d.ts.map +1 -1
  12. package/dist/client.js +46 -18
  13. package/dist/client.js.map +1 -1
  14. package/dist/cohere_integration.d.ts +42 -0
  15. package/dist/cohere_integration.d.ts.map +1 -0
  16. package/dist/cohere_integration.js +456 -0
  17. package/dist/cohere_integration.js.map +1 -0
  18. package/dist/compress.d.ts +69 -0
  19. package/dist/compress.d.ts.map +1 -0
  20. package/dist/compress.js +75 -0
  21. package/dist/compress.js.map +1 -0
  22. package/dist/context.d.ts +13 -4
  23. package/dist/context.d.ts.map +1 -1
  24. package/dist/context.js +15 -5
  25. package/dist/context.js.map +1 -1
  26. package/dist/errors.d.ts +137 -0
  27. package/dist/errors.d.ts.map +1 -0
  28. package/dist/errors.js +462 -0
  29. package/dist/errors.js.map +1 -0
  30. package/dist/events.d.ts +19 -6
  31. package/dist/events.d.ts.map +1 -1
  32. package/dist/events.js +31 -6
  33. package/dist/events.js.map +1 -1
  34. package/dist/gemini_integration.d.ts +33 -0
  35. package/dist/gemini_integration.d.ts.map +1 -0
  36. package/dist/gemini_integration.js +334 -0
  37. package/dist/gemini_integration.js.map +1 -0
  38. package/dist/halt.d.ts +12 -12
  39. package/dist/halt.js +16 -16
  40. package/dist/halt.js.map +1 -1
  41. package/dist/halt_stream.d.ts +6 -6
  42. package/dist/halt_stream.d.ts.map +1 -1
  43. package/dist/halt_stream.js +22 -12
  44. package/dist/halt_stream.js.map +1 -1
  45. package/dist/index.d.ts +26 -13
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +20 -12
  48. package/dist/index.js.map +1 -1
  49. package/dist/integrations/langgraph.d.ts +99 -0
  50. package/dist/integrations/langgraph.d.ts.map +1 -0
  51. package/dist/integrations/langgraph.js +572 -0
  52. package/dist/integrations/langgraph.js.map +1 -0
  53. package/dist/integrations/mastra.d.ts +114 -0
  54. package/dist/integrations/mastra.d.ts.map +1 -0
  55. package/dist/integrations/mastra.js +354 -0
  56. package/dist/integrations/mastra.js.map +1 -0
  57. package/dist/integrations/openai_agents.d.ts +66 -0
  58. package/dist/integrations/openai_agents.d.ts.map +1 -0
  59. package/dist/integrations/openai_agents.js +243 -0
  60. package/dist/integrations/openai_agents.js.map +1 -0
  61. package/dist/integrations/promptfoo.d.ts +62 -0
  62. package/dist/integrations/promptfoo.d.ts.map +1 -0
  63. package/dist/integrations/promptfoo.js +76 -0
  64. package/dist/integrations/promptfoo.js.map +1 -0
  65. package/dist/integrations/ragas.d.ts +65 -0
  66. package/dist/integrations/ragas.d.ts.map +1 -0
  67. package/dist/integrations/ragas.js +78 -0
  68. package/dist/integrations/ragas.js.map +1 -0
  69. package/dist/integrations/vectara.d.ts +60 -0
  70. package/dist/integrations/vectara.d.ts.map +1 -0
  71. package/dist/integrations/vectara.js +59 -0
  72. package/dist/integrations/vectara.js.map +1 -0
  73. package/dist/integrations/vercel_ai.d.ts +6 -6
  74. package/dist/integrations/vercel_ai.js +10 -10
  75. package/dist/integrations/vercel_ai.js.map +1 -1
  76. package/dist/observe.d.ts +358 -3
  77. package/dist/observe.d.ts.map +1 -1
  78. package/dist/observe.js +536 -4
  79. package/dist/observe.js.map +1 -1
  80. package/dist/ollama_integration.d.ts +126 -0
  81. package/dist/ollama_integration.d.ts.map +1 -0
  82. package/dist/ollama_integration.js +404 -0
  83. package/dist/ollama_integration.js.map +1 -0
  84. package/dist/openai_integration.d.ts +67 -0
  85. package/dist/openai_integration.d.ts.map +1 -0
  86. package/dist/openai_integration.js +574 -0
  87. package/dist/openai_integration.js.map +1 -0
  88. package/dist/tool.d.ts +1 -1
  89. package/dist/tool.d.ts.map +1 -1
  90. package/dist/tool.js +193 -10
  91. package/dist/tool.js.map +1 -1
  92. package/dist/truncate.d.ts +84 -0
  93. package/dist/truncate.d.ts.map +1 -0
  94. package/dist/truncate.js +134 -0
  95. package/dist/truncate.js.map +1 -0
  96. package/dist/vertex_gemini_integration.d.ts +27 -0
  97. package/dist/vertex_gemini_integration.d.ts.map +1 -0
  98. package/dist/vertex_gemini_integration.js +229 -0
  99. package/dist/vertex_gemini_integration.js.map +1 -0
  100. package/dist/wrap.d.ts +39 -3
  101. package/dist/wrap.d.ts.map +1 -1
  102. package/dist/wrap.js +15 -12
  103. package/dist/wrap.js.map +1 -1
  104. package/package.json +28 -4
package/dist/halt.js CHANGED
@@ -1,14 +1,14 @@
1
1
  /**
2
- * Hard-halt primitives — TypeScript port of the Python `mesedi/halt.py`.
2
+ * Hard-halt primitives, TypeScript port of the Python `mesedi/halt.py`.
3
3
  *
4
4
  * Three exports:
5
5
  *
6
- * - `Budget` — interface describing the per-execution limits
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` — Error subclass that the runtime throws when a
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` — runtime counter struct. One per execution.
20
+ * - `BudgetTracker`, runtime counter struct. One per execution.
21
21
  * Tracks wall-clock start (via `performance.now()`
22
- * — JS's monotonic clock equivalent of Python's
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 — never mid-call.
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 — broad except blocks miss it. JavaScript has no
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
@@ -68,7 +68,7 @@ const MESEDI_HALT_MARKER = Symbol.for("mesedi.halt.marker");
68
68
  export class MesediHalt extends Error {
69
69
  reason;
70
70
  trigger;
71
- // Symbol-keyed marker — invisible to JSON.stringify, hard for user
71
+ // Symbol-keyed marker, invisible to JSON.stringify, hard for user
72
72
  // code to spoof.
73
73
  [MESEDI_HALT_MARKER] = true;
74
74
  constructor(reason, trigger) {
@@ -95,7 +95,7 @@ export function isMesediHalt(err) {
95
95
  if (err[MESEDI_HALT_MARKER]) {
96
96
  return true;
97
97
  }
98
- // Walk Error.cause chain — ES2022 standard for wrapped errors.
98
+ // Walk Error.cause chain, ES2022 standard for wrapped errors.
99
99
  let cursor = err.cause;
100
100
  let safety = 0;
101
101
  while (cursor && safety < 10) {
@@ -110,15 +110,15 @@ export function isMesediHalt(err) {
110
110
  }
111
111
  /**
112
112
  * Runtime counter struct. One instance per execution, lives on the
113
- * ExecutionContext. Thread-safety isn't a concern in Node — the
114
- * single-threaded event loop guarantees serial access — but the
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 — the caller's work is never started.
121
+ * thrown, the caller's work is never started.
122
122
  */
123
123
  export class BudgetTracker {
124
124
  budget;
@@ -135,7 +135,7 @@ export class BudgetTracker {
135
135
  constructor(budget) {
136
136
  this.budget = budget;
137
137
  // performance.now() returns a monotonic millisecond timer that
138
- // doesn't jump backward on NTP adjustments — the JS equivalent
138
+ // doesn't jump backward on NTP adjustments, the JS equivalent
139
139
  // of Python's time.monotonic().
140
140
  this.startMs = performance.now();
141
141
  }
@@ -147,7 +147,7 @@ export class BudgetTracker {
147
147
  * `check()` call will throw `MesediHalt(trigger='remote_signal')`
148
148
  * with the supplied reason.
149
149
  *
150
- * Idempotent — multiple signals overwrite the reason (last one
150
+ * Idempotent, multiple signals overwrite the reason (last one
151
151
  * wins). Concurrency is fine: Node's single-threaded event loop
152
152
  * means the reader thread's write and the agent thread's read
153
153
  * can't interleave at the JS level.
@@ -165,7 +165,7 @@ export class BudgetTracker {
165
165
  * axis. Local budgets only trip when no remote halt is pending.
166
166
  */
167
167
  check() {
168
- // Remote halt check — runs even when the budget is unbounded,
168
+ // Remote halt check, runs even when the budget is unbounded,
169
169
  // so a wrap()'d agent without explicit local limits can still
170
170
  // be remote-halted (dashboard panic-stop semantics).
171
171
  if (this.remoteHaltReason !== undefined) {
@@ -177,7 +177,7 @@ export class BudgetTracker {
177
177
  this.remoteHaltReason = undefined;
178
178
  throw new MesediHalt(reason, "remote_signal");
179
179
  }
180
- // Wall-clock — checked first among the local axes because it's
180
+ // Wall-clock, checked first among the local axes because it's
181
181
  // the most common trigger in practice. A runaway agent burns
182
182
  // time before it burns steps or tokens.
183
183
  if (this.budget.maxWallClockSeconds !== undefined) {
package/dist/halt.js.map CHANGED
@@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IAAI,IAAI,CAAC,MAAM,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;YAC3C,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;gBAC/C,MAAM,IAAI,UAAU,CAClB,iCAAiC,IAAI,CAAC,SAAS,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,GAAG,EAChF,aAAa,CACd,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;IAED,wDAAwD;IACxD,cAAc;QACZ,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC;IAClB,CAAC;IAED,iDAAiD;IACjD,SAAS,CAAC,QAAgB,EAAE,SAAiB;QAC3C,IAAI,QAAQ,GAAG,CAAC;YAAE,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC;QAC5C,IAAI,SAAS,GAAG,CAAC;YAAE,IAAI,CAAC,SAAS,IAAI,SAAS,CAAC;IACjD,CAAC;IAED,mDAAmD;IACnD,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IACD,IAAI,eAAe;QACjB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IACD,IAAI,gBAAgB;QAClB,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IACD,IAAI,SAAS;QACX,OAAO,WAAW,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;IAC1C,CAAC;CACF"}
@@ -1,5 +1,5 @@
1
1
  /**
2
- * SSE halt-stream reader — sub-slice 21e (TS port of 21b.2).
2
+ * SSE halt-stream reader, sub-slice 21e (TS port of 21b.2).
3
3
  *
4
4
  * When `wrap()` is entered with a `budget` configured, the wrap layer
5
5
  * spawns a HaltStreamReader that opens an HTTP stream against
@@ -14,7 +14,7 @@
14
14
  * - **No thread.** JavaScript is single-threaded; the reader is
15
15
  * just an async function returning a Promise that we kick off
16
16
  * without awaiting. The fetch's underlying I/O runs on Node's
17
- * libuv pool — same effective concurrency as a Python daemon
17
+ * libuv pool, same effective concurrency as a Python daemon
18
18
  * thread.
19
19
  *
20
20
  * - **AbortController for stop().** We can't "interrupt" an async
@@ -28,7 +28,7 @@
28
28
  * stdlib. We pull bytes off `response.body.getReader()`, decode
29
29
  * UTF-8 chunks via TextDecoder, accumulate into a buffer, and
30
30
  * split on newlines to get SSE lines. The SSE spec uses `\n` or
31
- * `\r\n` or `\r` as line separators — we normalize all three.
31
+ * `\r\n` or `\r` as line separators, we normalize all three.
32
32
  *
33
33
  * - **Fail-open posture.** If subscription fails (connect error,
34
34
  * non-200 response, parse error), the reader logs at debug-level
@@ -38,7 +38,7 @@
38
38
  *
39
39
  * - **One-shot semantics.** After dispatching a halt event, the
40
40
  * reader exits. The backend closes the SSE connection at the
41
- * same moment — both sides agree halt is one signal per
41
+ * same moment, both sides agree halt is one signal per
42
42
  * subscription.
43
43
  *
44
44
  * No public API surface: customers don't construct HaltStreamReader.
@@ -62,8 +62,8 @@ export declare class HaltStreamReader {
62
62
  private stopped;
63
63
  constructor(opts: HaltStreamReaderOptions);
64
64
  /**
65
- * Kick off the async read loop. Idempotent — second call is a no-op.
66
- * Does NOT await — the wrap layer fires this and continues.
65
+ * Kick off the async read loop. Idempotent, second call is a no-op.
66
+ * Does NOT await, the wrap layer fires this and continues.
67
67
  */
68
68
  start(): void;
69
69
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"halt_stream.d.ts","sourceRoot":"","sources":["../src/halt_stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAIH,MAAM,WAAW,uBAAuB;IACtC,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,qBAAa,gBAAg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H,KAAK,IAAI,IAAI;IAQb;;;OAGG;IACH,IAAI,IAAI,IAAI;YAUE,IAAI;IA4GlB,OAAO,CAAC,aAAa;CAsBtB"}
@@ -1,5 +1,5 @@
1
1
  /**
2
- * SSE halt-stream reader — sub-slice 21e (TS port of 21b.2).
2
+ * SSE halt-stream reader, sub-slice 21e (TS port of 21b.2).
3
3
  *
4
4
  * When `wrap()` is entered with a `budget` configured, the wrap layer
5
5
  * spawns a HaltStreamReader that opens an HTTP stream against
@@ -14,7 +14,7 @@
14
14
  * - **No thread.** JavaScript is single-threaded; the reader is
15
15
  * just an async function returning a Promise that we kick off
16
16
  * without awaiting. The fetch's underlying I/O runs on Node's
17
- * libuv pool — same effective concurrency as a Python daemon
17
+ * libuv pool, same effective concurrency as a Python daemon
18
18
  * thread.
19
19
  *
20
20
  * - **AbortController for stop().** We can't "interrupt" an async
@@ -28,7 +28,7 @@
28
28
  * stdlib. We pull bytes off `response.body.getReader()`, decode
29
29
  * UTF-8 chunks via TextDecoder, accumulate into a buffer, and
30
30
  * split on newlines to get SSE lines. The SSE spec uses `\n` or
31
- * `\r\n` or `\r` as line separators — we normalize all three.
31
+ * `\r\n` or `\r` as line separators, we normalize all three.
32
32
  *
33
33
  * - **Fail-open posture.** If subscription fails (connect error,
34
34
  * non-200 response, parse error), the reader logs at debug-level
@@ -38,7 +38,7 @@
38
38
  *
39
39
  * - **One-shot semantics.** After dispatching a halt event, the
40
40
  * reader exits. The backend closes the SSE connection at the
41
- * same moment — both sides agree halt is one signal per
41
+ * same moment, both sides agree halt is one signal per
42
42
  * subscription.
43
43
  *
44
44
  * No public API surface: customers don't construct HaltStreamReader.
@@ -56,15 +56,25 @@ export class HaltStreamReader {
56
56
  stopped = false;
57
57
  constructor(opts) {
58
58
  this.executionId = opts.executionId;
59
- this.baseUrl = opts.baseUrl.replace(/\/+$/, "");
59
+ // Strip trailing slashes from the base URL without using a regex
60
+ // with a quantifier (#204 alert #4, js/polynomial-redos). The old
61
+ // .replace(/\/+$/, "") form was flagged because a pathological
62
+ // input like "/".repeat(N) drives O(N) backtracking on some JS
63
+ // engines; the explicit loop is linear AND avoids the regex
64
+ // engine entirely.
65
+ let normalizedBaseUrl = opts.baseUrl;
66
+ while (normalizedBaseUrl.endsWith("/")) {
67
+ normalizedBaseUrl = normalizedBaseUrl.slice(0, -1);
68
+ }
69
+ this.baseUrl = normalizedBaseUrl;
60
70
  this.apiKey = opts.apiKey;
61
71
  this.onHalt = opts.onHalt;
62
72
  this.schemaVersion = opts.schemaVersion ?? "1";
63
73
  this.controller = new AbortController();
64
74
  }
65
75
  /**
66
- * Kick off the async read loop. Idempotent — second call is a no-op.
67
- * Does NOT await — the wrap layer fires this and continues.
76
+ * Kick off the async read loop. Idempotent, second call is a no-op.
77
+ * Does NOT await, the wrap layer fires this and continues.
68
78
  */
69
79
  start() {
70
80
  if (this.started)
@@ -86,7 +96,7 @@ export class HaltStreamReader {
86
96
  this.controller.abort();
87
97
  }
88
98
  catch {
89
- // ignore — abort can throw on some Node versions if already aborted
99
+ // ignore, abort can throw on some Node versions if already aborted
90
100
  }
91
101
  }
92
102
  async _run() {
@@ -101,7 +111,7 @@ export class HaltStreamReader {
101
111
  };
102
112
  // Connect-timeout is a separate signal so it doesn't kill the
103
113
  // long-lived read after connect succeeds. AbortSignal.timeout()
104
- // is Node 17.3+ / native; AbortSignal.any() is Node 20+ — we
114
+ // is Node 17.3+ / native; AbortSignal.any() is Node 20+, we
105
115
  // compose them manually for broader compatibility (Node 18 LTS).
106
116
  const connectTimeout = setTimeout(() => this.controller.abort(), CONNECT_TIMEOUT_MS);
107
117
  let resp;
@@ -158,14 +168,14 @@ export class HaltStreamReader {
158
168
  // Blank line dispatches the accumulated event.
159
169
  if (currentEvent === "halt" && dataLines.length > 0) {
160
170
  this._dispatchHalt(dataLines.join("\n"));
161
- return; // one-shot — done
171
+ return; // one-shot, done
162
172
  }
163
173
  currentEvent = "message";
164
174
  dataLines = [];
165
175
  continue;
166
176
  }
167
177
  if (line.startsWith(":")) {
168
- // Comment frame (`: keepalive`) — ignore.
178
+ // Comment frame (`: keepalive`), ignore.
169
179
  continue;
170
180
  }
171
181
  if (line.startsWith("event:")) {
@@ -207,7 +217,7 @@ export class HaltStreamReader {
207
217
  this.onHalt(reason);
208
218
  }
209
219
  catch (err) {
210
- console.warn("[mesedi.halt_stream] onHalt callback threw — halt may not have fired", { executionId: this.executionId, error: String(err) });
220
+ console.warn("[mesedi.halt_stream] onHalt callback threw, halt may not have fired", { executionId: this.executionId, error: String(err) });
211
221
  }
212
222
  }
213
223
  }
@@ -1 +1 @@
1
- {"version":3,"file":"halt_stream.js","sourceRoot":"","sources":["../src/halt_stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAEH,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAUhC,MAAM,OAAO,gBAAgB;IACV,WAAW,CAAS;IACpB,OAAO,CAAS;IAChB,MAAM,CAAS;IACf,MAAM,CAA2B;IACjC,aAAa,CAAS;IACtB,UAAU,CAAkB;IACrC,OAAO,GAAG,KAAK,CAAC;IAChB,OAAO,GAAG,KAAK,CAAC;IAExB,YAAY,IAA6B;QACvC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;QACpC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAChD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,IAAI,GAAG,CAAC;QAC/C,IAAI,CAAC,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IAC1C,CAAC;IAED;;;OAGG;IACH,KAAK;QACH,IAAI,IAAI,CAAC,OAAO;YAAE,OAAO;QACzB,IAAI,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AAC;CACF"}
package/dist/index.d.ts CHANGED
@@ -1,27 +1,30 @@
1
1
  /**
2
- * Mesedi TypeScript SDK — Guardians for Autonomous AI.
2
+ * Mesedi TypeScript SDK, Guardians for Autonomous AI.
3
3
  *
4
4
  * Public API:
5
5
  *
6
- * configure(opts) — set up the module-level default client.
6
+ * configure(opts): set up the module-level default client.
7
7
  * Reads MESEDI_API_KEY / MESEDI_BASE_URL
8
8
  * from process.env as fallbacks.
9
- * wrap(opts?, fn) — higher-order function that records the
9
+ * wrap(opts?, fn): higher-order function that records the
10
10
  * wrapped function's invocation as an
11
11
  * agent execution.
12
- * tool(opts?, fn) — higher-order function that records each
12
+ * tool(opts?, fn): higher-order function that records each
13
13
  * call as a tool_call event linked to the
14
14
  * surrounding wrap()'d execution.
15
- * checkpoint(name, meta?) — mark a notable point in execution.
16
- * validatorResult(name, passed, opts?) — report a validator outcome.
17
- * instrumentAnthropic(cls?)— patch @anthropic-ai/sdk's
15
+ * checkpoint(name, meta?): mark a notable point in execution.
16
+ * validatorResult(name, passed, opts?), report a validator outcome.
17
+ * instrumentAnthropic(cls?), patch @anthropic-ai/sdk's
18
18
  * Messages.create to emit llm_call events.
19
19
  * Optional `cls` for testing.
20
- * flush(timeoutMs?) — wait for the background shipper to
20
+ * instrumentOpenAI(c?, r?), patch openai SDK's chat.completions
21
+ * and Responses APIs to emit llm_call
22
+ * events. Optional class args for testing.
23
+ * flush(timeoutMs?): wait for the background shipper to
21
24
  * drain all events submitted so far.
22
- * MesediClient — explicit client for advanced use cases.
23
- * Event, Execution — wire-format dataclasses.
24
- * EventType, Status — enum-style constants.
25
+ * MesediClient: explicit client for advanced use cases.
26
+ * Event, Execution: wire-format dataclasses.
27
+ * EventType, Status: enum-style constants.
25
28
  */
26
29
  export { MesediClient, configure, flush, getClient } from "./client.js";
27
30
  export type { ConfigureOptions } from "./client.js";
@@ -31,10 +34,20 @@ export { wrap } from "./wrap.js";
31
34
  export type { WrapOptions } from "./wrap.js";
32
35
  export { tool } from "./tool.js";
33
36
  export type { ToolOptions } from "./tool.js";
34
- export { checkpoint, validatorResult } from "./observe.js";
35
- export type { ValidatorResultOptions, ValidatorSeverity, } from "./observe.js";
37
+ export { checkpoint, completeHumanIntervention, emitAgentHandoff, emitEvalScore, emitInfrastructureEvent, emitMcpCall, emitMemoryOperation, pauseForHuman, requestHumanIntervention, resumeForAgent, validatorResult, } from "./observe.js";
38
+ export type { AgentHandoffOptions, CompleteHumanInterventionOptions, EvalScoreOptions, HumanInterventionHandleData, InfrastructureEventOptions, InfrastructureReason, McpCallOptions, MemoryOperationOptions, ValidatorResultOptions, ValidatorSeverity, } from "./observe.js";
36
39
  export { instrumentAnthropic } from "./anthropic_integration.js";
37
40
  export type { MessagesClassLike } from "./anthropic_integration.js";
41
+ export { instrumentOpenAI } from "./openai_integration.js";
42
+ export type { CompletionsClassLike, ResponsesClassLike, } from "./openai_integration.js";
43
+ export { instrumentCohere } from "./cohere_integration.js";
44
+ export type { CohereClientLike } from "./cohere_integration.js";
45
+ export { instrumentGemini } from "./gemini_integration.js";
46
+ export type { GenerativeModelClassLike } from "./gemini_integration.js";
47
+ export { instrumentVertexGemini } from "./vertex_gemini_integration.js";
48
+ export type { VertexGenerativeModelClassLike } from "./vertex_gemini_integration.js";
49
+ export { instrumentOllama } from "./ollama_integration.js";
50
+ export type { OllamaClassLike } from "./ollama_integration.js";
38
51
  export { MesediHalt, isMesediHalt } from "./halt.js";
39
52
  export type { Budget, HaltTrigger } from "./halt.js";
40
53
  export declare const VERSION = "0.0.4";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxE,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EACL,SAAS,EAC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- * Mesedi TypeScript SDK — Guardians for Autonomous AI.
2
+ * Mesedi TypeScript SDK, Guardians for Autonomous AI.
3
3
  *
4
4
  * Public API:
5
5
  *
6
- * configure(opts) — set up the module-level default client.
6
+ * configure(opts): set up the module-level default client.
7
7
  * Reads MESEDI_API_KEY / MESEDI_BASE_URL
8
8
  * from process.env as fallbacks.
9
- * wrap(opts?, fn) — higher-order function that records the
9
+ * wrap(opts?, fn): higher-order function that records the
10
10
  * wrapped function's invocation as an
11
11
  * agent execution.
12
- * tool(opts?, fn) — higher-order function that records each
12
+ * tool(opts?, fn): higher-order function that records each
13
13
  * call as a tool_call event linked to the
14
14
  * surrounding wrap()'d execution.
15
- * checkpoint(name, meta?) — mark a notable point in execution.
16
- * validatorResult(name, passed, opts?) — report a validator outcome.
17
- * instrumentAnthropic(cls?)— patch @anthropic-ai/sdk's
15
+ * checkpoint(name, meta?): mark a notable point in execution.
16
+ * validatorResult(name, passed, opts?), report a validator outcome.
17
+ * instrumentAnthropic(cls?), patch @anthropic-ai/sdk's
18
18
  * Messages.create to emit llm_call events.
19
19
  * Optional `cls` for testing.
20
- * flush(timeoutMs?) — wait for the background shipper to
20
+ * instrumentOpenAI(c?, r?), patch openai SDK's chat.completions
21
+ * and Responses APIs to emit llm_call
22
+ * events. Optional class args for testing.
23
+ * flush(timeoutMs?): wait for the background shipper to
21
24
  * drain all events submitted so far.
22
- * MesediClient — explicit client for advanced use cases.
23
- * Event, Execution — wire-format dataclasses.
24
- * EventType, Status — enum-style constants.
25
+ * MesediClient: explicit client for advanced use cases.
26
+ * Event, Execution: wire-format dataclasses.
27
+ * EventType, Status: enum-style constants.
25
28
  */
26
29
  export { MesediClient, configure, flush, getClient } from "./client.js";
27
30
  export { EventType, Status, utcNowRfc3339, } from "./events.js";
28
31
  export { wrap } from "./wrap.js";
29
32
  export { tool } from "./tool.js";
30
- export { checkpoint, validatorResult } from "./observe.js";
33
+ export { checkpoint, completeHumanIntervention, emitAgentHandoff, emitEvalScore, emitInfrastructureEvent, emitMcpCall, emitMemoryOperation, pauseForHuman, requestHumanIntervention, resumeForAgent, validatorResult, } from "./observe.js";
31
34
  export { instrumentAnthropic } from "./anthropic_integration.js";
35
+ export { instrumentOpenAI } from "./openai_integration.js";
36
+ export { instrumentCohere } from "./cohere_integration.js";
37
+ export { instrumentGemini } from "./gemini_integration.js";
38
+ export { instrumentVertexGemini } from "./vertex_gemini_integration.js";
39
+ export { instrumentOllama } from "./ollama_integration.js";
32
40
  export { MesediHalt, isMesediHalt } from "./halt.js";
33
41
  export const VERSION = "0.0.4";
34
42
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExE,OAAO,EACL,SAAS,EACT,MAAM,EACN,aAAa,GACd,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAK3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAGrD,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExE,OAAO,EACL,SAAS,EACT,MAAM,EACN,aAAa,GACd,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EACL,UAAU,EACV,yBAAyB,EACzB,gBAAgB,EAChB,aAAa,EACb,uBAAuB,EACvB,WAAW,EACX,mBAAmB,EACnB,aAAa,EACb,wBAAwB,EACxB,cAAc,EACd,eAAe,GAChB,MAAM,cAAc,CAAC;AAatB,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAK3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAExE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAGrD,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC"}
@@ -0,0 +1,99 @@
1
+ /**
2
+ * LangGraph integration for Mesedi (Mesedi #26).
3
+ *
4
+ * Usage (one-liner):
5
+ *
6
+ * import { wrap } from "mesedi";
7
+ * import { instrumentLangGraph } from "mesedi/integrations/langgraph";
8
+ * import { StateGraph } from "@langchain/langgraph";
9
+ *
10
+ * let graph = buildMyGraph().compile();
11
+ * graph = instrumentLangGraph(graph);
12
+ *
13
+ * export const runAgent = wrap(async (question: string) => {
14
+ * const result = await graph.invoke({ question });
15
+ * return result.answer;
16
+ * });
17
+ *
18
+ * What the integration emits:
19
+ *
20
+ * - `llm_call` events for every chat-model invocation inside the
21
+ * graph (via the inherited LangChain dispatcher).
22
+ * - `tool_call` events for every tool invocation.
23
+ * - `checkpoint` events at every node entry and exit, with the
24
+ * node name and a truncated state repr. Feeds the semantic_loop
25
+ * detector (#6) which hashes canonical state.
26
+ * - `agent_handoff` events when the graph invokes a compiled
27
+ * sub-graph. Feeds cascading_failure (#12) and
28
+ * coordination_deadlock (#13).
29
+ *
30
+ * Why this exists at the TS layer:
31
+ *
32
+ * The Python integration ships in `mesedi.integrations.langgraph`.
33
+ * The TypeScript LangChain / LangGraph stack uses the same callback
34
+ * handler surface (`BaseCallbackHandler` from
35
+ * `@langchain/core/callbacks/base`), so this port keeps wire-format
36
+ * parity with the Python emitter while reading idiomatically in
37
+ * TypeScript.
38
+ *
39
+ * Out of scope for v1:
40
+ *
41
+ * - Streaming hooks (`graph.streamEvents`). Covered in a follow-up.
42
+ * - LangGraph's persistence (checkpointer) — Mesedi emits
43
+ * telemetry parallel to it without touching the stored state.
44
+ * - LangGraph `interrupt()` auto-bridging — use the existing HITL
45
+ * helpers (`pauseForHuman`, `requestHumanIntervention`) for now.
46
+ */
47
+ /**
48
+ * Mesedi LangGraph callback handler. Duck-typed against
49
+ * `BaseCallbackHandler` from `@langchain/core/callbacks/base`.
50
+ *
51
+ * We do NOT extend the LangChain class directly because that would
52
+ * make `@langchain/core` a required runtime dependency. The handler
53
+ * implements the methods the LangGraph dispatcher calls and is
54
+ * picked up structurally.
55
+ */
56
+ export declare class MesediLangGraphCallbackHandler {
57
+ readonly name = "mesedi-langgraph";
58
+ readonly raiseError = false;
59
+ private nodeStarts;
60
+ private handoffStarts;
61
+ onChainStart(serialized: Record<string, unknown> | undefined, inputs: Record<string, unknown> | undefined, runId: string, _parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>): void;
62
+ onChainEnd(outputs: Record<string, unknown> | undefined, runId: string, _parentRunId?: string, _tags?: string[], _kwargs?: Record<string, unknown>): void;
63
+ onChainError(error: unknown, runId: string, _parentRunId?: string, _tags?: string[], _kwargs?: Record<string, unknown>): void;
64
+ onChatModelStart(serialized: Record<string, unknown> | undefined, messages: Array<Array<unknown>>, runId: string, _parentRunId?: string, extraParams?: Record<string, unknown>): void;
65
+ onLLMStart(serialized: Record<string, unknown> | undefined, prompts: string[], runId: string, _parentRunId?: string, extraParams?: Record<string, unknown>): void;
66
+ onLLMEnd(output: unknown, runId: string): void;
67
+ onLLMError(_error: unknown, runId: string): void;
68
+ onToolStart(serialized: Record<string, unknown> | undefined, inputStr: string | Record<string, unknown>, runId: string): void;
69
+ onToolEnd(output: unknown, runId: string): void;
70
+ onToolError(error: unknown, runId: string): void;
71
+ private llmStarts;
72
+ private toolStarts;
73
+ private mostRecentNode;
74
+ }
75
+ /**
76
+ * Attach Mesedi telemetry to a compiled LangGraph.
77
+ *
78
+ * Wraps the supplied compiled graph so every call to `invoke`,
79
+ * `stream`, or their async variants automatically attaches a
80
+ * `MesediLangGraphCallbackHandler` to the LangChain callback config.
81
+ * The wrap is non-destructive: it adds the handler to whatever
82
+ * callbacks the caller passed in via `config={ callbacks: [...] }`,
83
+ * so existing instrumentation keeps working.
84
+ *
85
+ * Returns the same `graph` object with patched methods, so callers
86
+ * can re-assign in place.
87
+ *
88
+ * Outside a `wrap()` execution context, the handler's emissions
89
+ * silently no-op, so it is safe to instrument the graph once at
90
+ * module load and let individual invocations decide whether they
91
+ * want to be observed.
92
+ */
93
+ export declare function instrumentLangGraph<G extends LangGraphLike>(graph: G): G;
94
+ interface LangGraphLike {
95
+ invoke?: (input: unknown, config?: Record<string, unknown>, ...rest: unknown[]) => Promise<unknown>;
96
+ stream?: (input: unknown, config?: Record<string, unknown>, ...rest: unknown[]) => Promise<unknown> | AsyncIterable<unknown>;
97
+ }
98
+ export {};
99
+ //# sourceMappingURL=langgraph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"langgraph.d.ts","sourceRoot":"","sources":["../../src/integrations/langgraph.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAWH;;;;;;;;GAQG;AACH,qBAAa,8BAA8B;IAGzC,QAAQ,CAAC,IAAI,sBAAsB;IACnC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