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
@@ -0,0 +1,456 @@
1
+ /**
2
+ * Cohere TypeScript SDK monkey-patch — auto-emit llm_call events
3
+ * for every chat call inside a wrap()'d execution.
4
+ *
5
+ * Mirrors instrumentAnthropic / instrumentOpenAI in fail-open
6
+ * semantics, canonical error vocabulary, idempotency. Patches:
7
+ *
8
+ * - cohere-ai CohereClient.chat (v1 surface, `message=` shape)
9
+ * - cohere-ai CohereClientV2.chat (v7+ OpenAI-style `messages=`)
10
+ *
11
+ * Both write the same canonical llm_call payload
12
+ * (provider="cohere") so the backend doesn't need to know which
13
+ * API surface fired.
14
+ *
15
+ * Dependency injection: instrumentCohere accepts optional
16
+ * v1Class + v2Class arguments so this code path is testable
17
+ * without installing cohere-ai.
18
+ */
19
+ import { getClient } from "./client.js";
20
+ import { currentExecutionContext, newEventId } from "./context.js";
21
+ import { classifyCohereException, extractHttpStatus, extractRetryAfter, } from "./errors.js";
22
+ import { EventType, utcNowRfc3339 } from "./events.js";
23
+ import { _maybeEmitThrottlingEvent } from "./observe.js";
24
+ const MAX_SYSTEM = 1000;
25
+ const MAX_USER_MSG = 1000;
26
+ const MAX_RESPONSE = 1000;
27
+ const MAX_EXC_MSG = 500;
28
+ const PROVIDER = "cohere";
29
+ const _patched = new WeakSet();
30
+ /** Patch the Cohere SDK chat surfaces (v1 + v2). Returns true if at
31
+ * least one was patched. False if neither could be located AND the
32
+ * cohere-ai package isn't installed. */
33
+ export async function instrumentCohere(v1Class, v2Class) {
34
+ let patchedAny = false;
35
+ let c1 = v1Class;
36
+ let c2 = v2Class;
37
+ if (!c1 || !c2) {
38
+ try {
39
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
40
+ // @ts-ignore — package may not be installed; by design.
41
+ const mod = (await import("cohere-ai"));
42
+ if (!c1)
43
+ c1 = mod?.CohereClient;
44
+ if (!c2)
45
+ c2 = mod?.CohereClientV2;
46
+ }
47
+ catch {
48
+ console.warn("mesedi: cohere-ai not installed; instrumentCohere() is a no-op. " +
49
+ "Install with `npm install cohere-ai` to enable.");
50
+ return false;
51
+ }
52
+ }
53
+ if (c1) {
54
+ patchV1(c1);
55
+ patchedAny = true;
56
+ }
57
+ if (c2) {
58
+ patchV2(c2);
59
+ patchedAny = true;
60
+ }
61
+ return patchedAny;
62
+ }
63
+ function patchV1(cls) {
64
+ if (_patched.has(cls))
65
+ return;
66
+ const originalChat = cls.prototype.chat;
67
+ cls.prototype.chat = async function patchedChat(...args) {
68
+ const ctx = currentExecutionContext();
69
+ if (!ctx)
70
+ return originalChat.apply(this, args);
71
+ ctx.checkBudget();
72
+ if (ctx.budgetTracker)
73
+ ctx.budgetTracker.incrementSteps();
74
+ const client = getClient();
75
+ const sequence = ctx.nextSequence();
76
+ const eventId = newEventId();
77
+ const firstArg = (args[0] ?? {});
78
+ const model = firstArg.model ?? "unknown";
79
+ const userMessage = typeof firstArg.message === "string" ? firstArg.message : "";
80
+ const systemText = typeof firstArg.preamble === "string" ? firstArg.preamble : "";
81
+ const start = performance.now();
82
+ try {
83
+ const response = (await originalChat.apply(this, args));
84
+ const durationMs = Math.round(performance.now() - start);
85
+ const responseText = typeof response?.text === "string" ? response.text : "";
86
+ const inputTokens = Number(response?.meta?.tokens?.input_tokens ?? 0) || 0;
87
+ const outputTokens = Number(response?.meta?.tokens?.output_tokens ?? 0) || 0;
88
+ if (ctx.budgetTracker)
89
+ ctx.budgetTracker.addTokens(inputTokens, outputTokens);
90
+ client.submitEvent(successEvent({
91
+ eventId,
92
+ executionId: ctx.executionId,
93
+ sequence,
94
+ durationMs,
95
+ model,
96
+ systemText,
97
+ userMessage,
98
+ responseText,
99
+ inputTokens,
100
+ outputTokens,
101
+ }));
102
+ return response;
103
+ }
104
+ catch (err) {
105
+ const durationMs = Math.round(performance.now() - start);
106
+ client.submitEvent(failureEvent({
107
+ eventId,
108
+ executionId: ctx.executionId,
109
+ sequence,
110
+ durationMs,
111
+ model,
112
+ systemText,
113
+ userMessage,
114
+ err,
115
+ }));
116
+ // Wave 1.4: auto-emit infrastructure_event on throttling.
117
+ _maybeEmitThrottlingEvent({
118
+ provider: PROVIDER,
119
+ errorClass: classifyCohereException(err),
120
+ httpStatus: extractHttpStatus(err),
121
+ retryAfterSeconds: extractRetryAfter(err),
122
+ endpoint: "/v1/chat",
123
+ });
124
+ throw err;
125
+ }
126
+ };
127
+ _patched.add(cls);
128
+ }
129
+ function patchV2(cls) {
130
+ if (_patched.has(cls))
131
+ return;
132
+ const originalChat = cls.prototype.chat;
133
+ cls.prototype.chat = async function patchedChat(...args) {
134
+ const ctx = currentExecutionContext();
135
+ if (!ctx)
136
+ return originalChat.apply(this, args);
137
+ ctx.checkBudget();
138
+ if (ctx.budgetTracker)
139
+ ctx.budgetTracker.incrementSteps();
140
+ const client = getClient();
141
+ const sequence = ctx.nextSequence();
142
+ const eventId = newEventId();
143
+ const firstArg = (args[0] ?? {});
144
+ const model = firstArg.model ?? "unknown";
145
+ const messages = Array.isArray(firstArg.messages) ? firstArg.messages : [];
146
+ const systemText = extractFirstSystemMessage(messages);
147
+ const userMessage = extractLastUserMessage(messages);
148
+ const start = performance.now();
149
+ try {
150
+ const response = (await originalChat.apply(this, args));
151
+ const durationMs = Math.round(performance.now() - start);
152
+ const parts = [];
153
+ for (const block of response?.message?.content ?? []) {
154
+ if (typeof block?.text === "string")
155
+ parts.push(block.text);
156
+ }
157
+ const responseText = parts.join("\n");
158
+ const inputTokens = Number(response?.usage?.tokens?.input_tokens ?? 0) || 0;
159
+ const outputTokens = Number(response?.usage?.tokens?.output_tokens ?? 0) || 0;
160
+ if (ctx.budgetTracker)
161
+ ctx.budgetTracker.addTokens(inputTokens, outputTokens);
162
+ client.submitEvent(successEvent({
163
+ eventId,
164
+ executionId: ctx.executionId,
165
+ sequence,
166
+ durationMs,
167
+ model,
168
+ systemText,
169
+ userMessage,
170
+ responseText,
171
+ inputTokens,
172
+ outputTokens,
173
+ }));
174
+ return response;
175
+ }
176
+ catch (err) {
177
+ const durationMs = Math.round(performance.now() - start);
178
+ client.submitEvent(failureEvent({
179
+ eventId,
180
+ executionId: ctx.executionId,
181
+ sequence,
182
+ durationMs,
183
+ model,
184
+ systemText,
185
+ userMessage,
186
+ err,
187
+ }));
188
+ // Wave 1.4: auto-emit infrastructure_event on throttling.
189
+ _maybeEmitThrottlingEvent({
190
+ provider: PROVIDER,
191
+ errorClass: classifyCohereException(err),
192
+ httpStatus: extractHttpStatus(err),
193
+ retryAfterSeconds: extractRetryAfter(err),
194
+ endpoint: "/v2/chat",
195
+ });
196
+ throw err;
197
+ }
198
+ };
199
+ _patched.add(cls);
200
+ }
201
+ function successEvent(args) {
202
+ return {
203
+ event_id: args.eventId,
204
+ execution_id: args.executionId,
205
+ event_type: EventType.LLM_CALL,
206
+ sequence: args.sequence,
207
+ timestamp: utcNowRfc3339(),
208
+ duration_ms: args.durationMs,
209
+ payload: {
210
+ provider: PROVIDER,
211
+ surface: args.surface ?? "chat",
212
+ model: args.model,
213
+ system_prompt: truncate(args.systemText, MAX_SYSTEM),
214
+ user_message: truncate(args.userMessage, MAX_USER_MSG),
215
+ response_text: truncate(args.responseText, MAX_RESPONSE),
216
+ status: "ok",
217
+ input_tokens: args.inputTokens,
218
+ output_tokens: args.outputTokens,
219
+ },
220
+ };
221
+ }
222
+ function failureEvent(args) {
223
+ const payload = {
224
+ provider: PROVIDER,
225
+ surface: args.surface ?? "chat",
226
+ model: args.model,
227
+ system_prompt: truncate(args.systemText, MAX_SYSTEM),
228
+ user_message: truncate(args.userMessage, MAX_USER_MSG),
229
+ status: "failed",
230
+ error_class: classifyCohereException(args.err),
231
+ exception_type: args.err instanceof Error && args.err.constructor.name
232
+ ? args.err.constructor.name
233
+ : typeof args.err,
234
+ exception_message: truncate(args.err instanceof Error ? args.err.message : String(args.err), MAX_EXC_MSG),
235
+ };
236
+ const httpStatus = extractHttpStatus(args.err);
237
+ if (httpStatus !== undefined)
238
+ payload.http_status = httpStatus;
239
+ const retryAfter = extractRetryAfter(args.err);
240
+ if (retryAfter !== undefined)
241
+ payload.retry_after_seconds = retryAfter;
242
+ return {
243
+ event_id: args.eventId,
244
+ execution_id: args.executionId,
245
+ event_type: EventType.LLM_CALL,
246
+ sequence: args.sequence,
247
+ timestamp: utcNowRfc3339(),
248
+ duration_ms: args.durationMs,
249
+ payload,
250
+ };
251
+ }
252
+ function extractFirstSystemMessage(messages) {
253
+ for (const m of messages) {
254
+ if (m?.role !== "system")
255
+ continue;
256
+ return contentToString(m.content);
257
+ }
258
+ return "";
259
+ }
260
+ function extractLastUserMessage(messages) {
261
+ for (let i = messages.length - 1; i >= 0; i--) {
262
+ const m = messages[i];
263
+ if (!m || m.role !== "user")
264
+ continue;
265
+ return contentToString(m.content);
266
+ }
267
+ return "";
268
+ }
269
+ function contentToString(content) {
270
+ if (typeof content === "string")
271
+ return content;
272
+ if (Array.isArray(content)) {
273
+ const parts = [];
274
+ for (const b of content) {
275
+ if (b?.type === "text" && typeof b.text === "string")
276
+ parts.push(b.text);
277
+ }
278
+ return parts.join("\n");
279
+ }
280
+ return "";
281
+ }
282
+ function truncate(s, max) {
283
+ if (s.length <= max)
284
+ return s;
285
+ return s.slice(0, max - 3) + "...";
286
+ }
287
+ const _embedPatched = new WeakSet();
288
+ const _rerankPatched = new WeakSet();
289
+ function extractEmbedInput(args) {
290
+ const texts = (args.texts ?? args.inputs);
291
+ if (typeof texts === "string")
292
+ return texts;
293
+ if (Array.isArray(texts)) {
294
+ if (texts.length > 0 && typeof texts[0] === "string") {
295
+ return texts.map((t) => String(t)).join("\n");
296
+ }
297
+ return `<${texts.length} embed input(s)>`;
298
+ }
299
+ return String(texts ?? "");
300
+ }
301
+ function extractEmbedTokens(response) {
302
+ try {
303
+ const r = response;
304
+ return Number(r?.meta?.billed_units?.input_tokens ?? 0) || 0;
305
+ }
306
+ catch {
307
+ return 0;
308
+ }
309
+ }
310
+ function extractRerankInput(args) {
311
+ const query = args.query ?? "";
312
+ const docs = args.documents;
313
+ if (Array.isArray(docs) && docs.length > 0 && typeof docs[0] === "string") {
314
+ return `query: ${query}\n---\ndocs:\n${docs.map((d) => String(d)).join("\n")}`;
315
+ }
316
+ const n = Array.isArray(docs) ? docs.length : 0;
317
+ return `query: ${query} (docs: ${n})`;
318
+ }
319
+ function rerankResultCount(response) {
320
+ try {
321
+ const r = response;
322
+ return Array.isArray(r?.results) ? r.results.length : 0;
323
+ }
324
+ catch {
325
+ return 0;
326
+ }
327
+ }
328
+ function patchEmbedSync(cls) {
329
+ if (_embedPatched.has(cls))
330
+ return;
331
+ const originalEmbed = cls.prototype.embed;
332
+ cls.prototype.embed = async function patchedEmbed(...args) {
333
+ const ctx = currentExecutionContext();
334
+ if (!ctx)
335
+ return originalEmbed.apply(this, args);
336
+ ctx.checkBudget();
337
+ if (ctx.budgetTracker)
338
+ ctx.budgetTracker.incrementSteps();
339
+ const client = getClient();
340
+ const sequence = ctx.nextSequence();
341
+ const eventId = newEventId();
342
+ const firstArg = (args[0] ?? {});
343
+ const model = firstArg.model ?? "unknown";
344
+ const userMessage = extractEmbedInput(firstArg);
345
+ const start = performance.now();
346
+ try {
347
+ const response = await originalEmbed.apply(this, args);
348
+ const durationMs = Math.round(performance.now() - start);
349
+ const inputTokens = extractEmbedTokens(response);
350
+ if (ctx.budgetTracker)
351
+ ctx.budgetTracker.addTokens(inputTokens, 0);
352
+ client.submitEvent(successEvent({
353
+ eventId,
354
+ executionId: ctx.executionId,
355
+ sequence,
356
+ durationMs,
357
+ model,
358
+ systemText: "",
359
+ userMessage,
360
+ responseText: "<embedding vectors>",
361
+ inputTokens,
362
+ outputTokens: 0,
363
+ surface: "embeddings",
364
+ }));
365
+ return response;
366
+ }
367
+ catch (err) {
368
+ const durationMs = Math.round(performance.now() - start);
369
+ client.submitEvent(failureEvent({
370
+ eventId,
371
+ executionId: ctx.executionId,
372
+ sequence,
373
+ durationMs,
374
+ model,
375
+ systemText: "",
376
+ userMessage,
377
+ err,
378
+ surface: "embeddings",
379
+ }));
380
+ _maybeEmitThrottlingEvent({
381
+ provider: PROVIDER,
382
+ errorClass: classifyCohereException(err),
383
+ httpStatus: extractHttpStatus(err),
384
+ retryAfterSeconds: extractRetryAfter(err),
385
+ endpoint: "/v1/embed",
386
+ });
387
+ throw err;
388
+ }
389
+ };
390
+ _embedPatched.add(cls);
391
+ }
392
+ function patchRerankSync(cls) {
393
+ if (_rerankPatched.has(cls))
394
+ return;
395
+ const originalRerank = cls.prototype.rerank;
396
+ cls.prototype.rerank = async function patchedRerank(...args) {
397
+ const ctx = currentExecutionContext();
398
+ if (!ctx)
399
+ return originalRerank.apply(this, args);
400
+ ctx.checkBudget();
401
+ if (ctx.budgetTracker)
402
+ ctx.budgetTracker.incrementSteps();
403
+ const client = getClient();
404
+ const sequence = ctx.nextSequence();
405
+ const eventId = newEventId();
406
+ const firstArg = (args[0] ?? {});
407
+ const model = firstArg.model ?? "unknown";
408
+ const userMessage = extractRerankInput(firstArg);
409
+ const start = performance.now();
410
+ try {
411
+ const response = await originalRerank.apply(this, args);
412
+ const durationMs = Math.round(performance.now() - start);
413
+ const n = rerankResultCount(response);
414
+ client.submitEvent(successEvent({
415
+ eventId,
416
+ executionId: ctx.executionId,
417
+ sequence,
418
+ durationMs,
419
+ model,
420
+ systemText: "",
421
+ userMessage,
422
+ responseText: `<rerank results: ${n}>`,
423
+ inputTokens: 0,
424
+ outputTokens: 0,
425
+ surface: "rerank",
426
+ }));
427
+ return response;
428
+ }
429
+ catch (err) {
430
+ const durationMs = Math.round(performance.now() - start);
431
+ client.submitEvent(failureEvent({
432
+ eventId,
433
+ executionId: ctx.executionId,
434
+ sequence,
435
+ durationMs,
436
+ model,
437
+ systemText: "",
438
+ userMessage,
439
+ err,
440
+ surface: "rerank",
441
+ }));
442
+ _maybeEmitThrottlingEvent({
443
+ provider: PROVIDER,
444
+ errorClass: classifyCohereException(err),
445
+ httpStatus: extractHttpStatus(err),
446
+ retryAfterSeconds: extractRetryAfter(err),
447
+ endpoint: "/v1/rerank",
448
+ });
449
+ throw err;
450
+ }
451
+ };
452
+ _rerankPatched.add(cls);
453
+ }
454
+ export { patchEmbedSync as patchEmbedV1, patchEmbedSync as patchEmbedV2 };
455
+ export { patchRerankSync as patchRerankV1, patchRerankSync as patchRerankV2 };
456
+ //# sourceMappingURL=cohere_integration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cohere_integration.js","sourceRoot":"","sources":["../src/cohere_integration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,uBAAuB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EACL,uBAAuB,EACvB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAS,SAAS,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AAEzD,MAAM,UAAU,GAAG,IAAI,CAAC;AACxB,MAAM,YAAY,GAAG,IAAI,CAAC;AAC1B,MAAM,YA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AE,QAAQ;gBAClB,UAAU,EAAE,uBAAuB,CAAC,GAAG,CAAC;gBACxC,UAAU,EAAE,iBAAiB,CAAC,GAAG,CAAC;gBAClC,iBAAiB,EAAE,iBAAiB,CAAC,GAAG,CAAC;gBACzC,QAAQ,EAAE,YAAY;aACvB,CAAC,CAAC;YACH,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAA4D,CAAC;IAC7D,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAC1B,CAAC;AAED,OAAO,EAAE,cAAc,IAAI,YAAY,EAAE,cAAc,IAAI,YAAY,EAAE,CAAC;AAC1E,OAAO,EAAE,eAAe,IAAI,aAAa,EAAE,eAAe,IAAI,aAAa,EAAE,CAAC"}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * gzip compression helper for outbound request bodies.
3
+ *
4
+ * The client calls {@link maybeCompress} on every JSON-serialized
5
+ * payload before handing it to `fetch`. Bodies below the threshold
6
+ * (default 1 KB) return unchanged because gzip framing overhead
7
+ * outweighs gains on tiny payloads. Bodies at or above the threshold
8
+ * are encoded and returned with the HTTP headers the backend
9
+ * middleware recognizes.
10
+ *
11
+ * **Why gzip, not zstd.** The Python SDK uses zstd because the
12
+ * `zstandard` package is widely available and adds modest install
13
+ * weight. JavaScript zstd encoders are heavy (~750 KB WASM, async
14
+ * init) and would break this SDK's lightweight install posture. Node
15
+ * ships gzip synchronously in its standard library, so gzip lets us
16
+ * compress with zero runtime dependencies. Backend accepts both
17
+ * Content-Encoding values through the same middleware path.
18
+ *
19
+ * **Fail-open.** Any exception during encoding falls back to the
20
+ * original uncompressed body. Compression is an optimization, not a
21
+ * contract; the request still has to land even if the encoder
22
+ * throws.
23
+ *
24
+ * **Backend negotiation.** The backend looks for
25
+ * `Content-Encoding: gzip` (or `zstd` from the Python SDK) and
26
+ * transparently decompresses before the handler reads the body.
27
+ * Backends without that middleware would see the compressed body as
28
+ * opaque bytes and reject it as malformed JSON, which is why this
29
+ * SDK version (v0.3.0) requires the matching backend release.
30
+ */
31
+ /**
32
+ * Bodies strictly smaller than this byte count skip compression so
33
+ * the gzip frame overhead does not dominate small payloads. 1 KB is
34
+ * the smallest size at which gzip reliably compresses to under 100%
35
+ * of the original on typical JSON inputs.
36
+ */
37
+ export declare const DEFAULT_THRESHOLD_BYTES = 1024;
38
+ /**
39
+ * Content-Encoding value the backend middleware accepts. Must match
40
+ * `EncodingGzip` on the backend side.
41
+ */
42
+ export declare const SUPPORTED_ENCODING = "gzip";
43
+ /** Return shape of {@link maybeCompress}. */
44
+ export interface MaybeCompressedBody {
45
+ /**
46
+ * The body bytes to send. Equal to the input when no compression
47
+ * was applied, otherwise the gzip-encoded form.
48
+ */
49
+ body: Uint8Array;
50
+ /**
51
+ * Extra headers the caller should merge into the outgoing request.
52
+ * Empty when no compression was applied; otherwise contains exactly
53
+ * `Content-Encoding: gzip`.
54
+ */
55
+ extraHeaders: Record<string, string>;
56
+ }
57
+ /**
58
+ * Compress `body` with gzip if its size meets the threshold.
59
+ *
60
+ * Never throws. On any encoding exception, the original body is
61
+ * returned with empty headers so the request still ships
62
+ * uncompressed.
63
+ *
64
+ * @param body raw serialized request body
65
+ * @param thresholdBytes minimum size before compression engages
66
+ * @returns the body to send plus any extra headers to merge
67
+ */
68
+ export declare function maybeCompress(body: Uint8Array, thresholdBytes?: number): MaybeCompressedBody;
69
+ //# sourceMappingURL=compress.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compress.d.ts","sourceRoot":"","sources":["../src/compress.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAIH;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,OAAO,CAAC;AAE5C;;;GAGG;AACH,eAAO,MAAM,kBAAkB,SAAS,CAAC;AAEzC,6CAA6C;AAC7C,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,IAAI,EAAE,UAAU,CAAC;IACjB;;;;OAIG;IACH,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,UAAU,EAChB,cAAc,GAAE,MAAgC,GAC/C,mBAAmB,CAwBrB"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * gzip compression helper for outbound request bodies.
3
+ *
4
+ * The client calls {@link maybeCompress} on every JSON-serialized
5
+ * payload before handing it to `fetch`. Bodies below the threshold
6
+ * (default 1 KB) return unchanged because gzip framing overhead
7
+ * outweighs gains on tiny payloads. Bodies at or above the threshold
8
+ * are encoded and returned with the HTTP headers the backend
9
+ * middleware recognizes.
10
+ *
11
+ * **Why gzip, not zstd.** The Python SDK uses zstd because the
12
+ * `zstandard` package is widely available and adds modest install
13
+ * weight. JavaScript zstd encoders are heavy (~750 KB WASM, async
14
+ * init) and would break this SDK's lightweight install posture. Node
15
+ * ships gzip synchronously in its standard library, so gzip lets us
16
+ * compress with zero runtime dependencies. Backend accepts both
17
+ * Content-Encoding values through the same middleware path.
18
+ *
19
+ * **Fail-open.** Any exception during encoding falls back to the
20
+ * original uncompressed body. Compression is an optimization, not a
21
+ * contract; the request still has to land even if the encoder
22
+ * throws.
23
+ *
24
+ * **Backend negotiation.** The backend looks for
25
+ * `Content-Encoding: gzip` (or `zstd` from the Python SDK) and
26
+ * transparently decompresses before the handler reads the body.
27
+ * Backends without that middleware would see the compressed body as
28
+ * opaque bytes and reject it as malformed JSON, which is why this
29
+ * SDK version (v0.3.0) requires the matching backend release.
30
+ */
31
+ import { gzipSync } from "node:zlib";
32
+ /**
33
+ * Bodies strictly smaller than this byte count skip compression so
34
+ * the gzip frame overhead does not dominate small payloads. 1 KB is
35
+ * the smallest size at which gzip reliably compresses to under 100%
36
+ * of the original on typical JSON inputs.
37
+ */
38
+ export const DEFAULT_THRESHOLD_BYTES = 1024;
39
+ /**
40
+ * Content-Encoding value the backend middleware accepts. Must match
41
+ * `EncodingGzip` on the backend side.
42
+ */
43
+ export const SUPPORTED_ENCODING = "gzip";
44
+ /**
45
+ * Compress `body` with gzip if its size meets the threshold.
46
+ *
47
+ * Never throws. On any encoding exception, the original body is
48
+ * returned with empty headers so the request still ships
49
+ * uncompressed.
50
+ *
51
+ * @param body raw serialized request body
52
+ * @param thresholdBytes minimum size before compression engages
53
+ * @returns the body to send plus any extra headers to merge
54
+ */
55
+ export function maybeCompress(body, thresholdBytes = DEFAULT_THRESHOLD_BYTES) {
56
+ if (body.byteLength < thresholdBytes) {
57
+ return { body, extraHeaders: {} };
58
+ }
59
+ try {
60
+ const compressed = gzipSync(body);
61
+ // Node's gzipSync returns a Buffer, which extends Uint8Array but
62
+ // some downstream type-checkers prefer a plain Uint8Array view.
63
+ // The view shares the underlying ArrayBuffer with the Buffer; no
64
+ // memory copy is performed.
65
+ return {
66
+ body: new Uint8Array(compressed.buffer, compressed.byteOffset, compressed.byteLength),
67
+ extraHeaders: { "Content-Encoding": SUPPORTED_ENCODING },
68
+ };
69
+ }
70
+ catch (err) {
71
+ console.warn(`mesedi: gzip encode failed, sending uncompressed: ${String(err)}`);
72
+ return { body, extraHeaders: {} };
73
+ }
74
+ }
75
+ //# sourceMappingURL=compress.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compress.js","sourceRoot":"","sources":["../src/compress.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,CAAC;AAE5C;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAiBzC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,aAAa,CAC3B,IAAgB,EAChB,iBAAyB,uBAAuB;IAEhD,IAAI,IAAI,CAAC,UAAU,GAAG,cAAc,EAAE,CAAC;QACrC,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC;IACpC,CAAC;IACD,IAAI,CAAC;QACH,MAAM,UAAU,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;QAClC,iEAAiE;QACjE,gEAAgE;QAChE,iEAAiE;QACjE,4BAA4B;QAC5B,OAAO;YACL,IAAI,EAAE,IAAI,UAAU,CAClB,UAAU,CAAC,MAAM,EACjB,UAAU,CAAC,UAAU,EACrB,UAAU,CAAC,UAAU,CACtB;YACD,YAAY,EAAE,EAAE,kBAAkB,EAAE,kBAAkB,EAAE;SACzD,CAAC;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,IAAI,CACV,qDAAqD,MAAM,CAAC,GAAG,CAAC,EAAE,CACnE,CAAC;QACF,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC;IACpC,CAAC;AACH,CAAC"}
package/dist/context.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Execution-context tracking using `AsyncLocalStorage` — Node's
2
+ * Execution-context tracking using `AsyncLocalStorage`, Node's
3
3
  * equivalent of Python's `contextvars`.
4
4
  *
5
5
  * When `wrap()` is entered, it pushes a fresh `ExecutionContext`
@@ -9,7 +9,7 @@
9
9
  * helpers read the context to learn which execution to attach to.
10
10
  *
11
11
  * Why AsyncLocalStorage: it tracks "logical call context" across
12
- * promise boundaries automatically — passing context through every
12
+ * promise boundaries automatically, passing context through every
13
13
  * await would be invasive and error-prone. AsyncLocalStorage is the
14
14
  * Node-native way to do what Python contextvars does.
15
15
  */
@@ -23,8 +23,17 @@ export declare class ExecutionContext {
23
23
  * `checkBudget()` at entry, which is a no-op when this is undefined.
24
24
  */
25
25
  readonly budgetTracker?: BudgetTracker;
26
+ /**
27
+ * Optional human-readable agent name set by
28
+ * `wrap({ agentName: "planner" }, fn)`. Used by `emitAgentHandoff`
29
+ * as a fallback when the caller does NOT supply `fromAgent`,
30
+ * so multi-agent code can avoid repeating the same string at every
31
+ * handoff site. Always undefined when wrap() was invoked without
32
+ * the agentName option.
33
+ */
34
+ readonly agentName?: string;
26
35
  private sequence;
27
- constructor(executionId: string, budgetTracker?: BudgetTracker);
36
+ constructor(executionId: string, budgetTracker?: BudgetTracker, agentName?: string);
28
37
  nextSequence(): number;
29
38
  /**
30
39
  * Halt-safe boundary check. Throws MesediHalt if a budget is
@@ -47,7 +56,7 @@ export declare function currentExecutionContext(): ExecutionContext | null;
47
56
  *
48
57
  * This is the workhorse `wrap()` calls internally.
49
58
  */
50
- export declare function runInExecutionContext<T>(executionId: string, fn: () => Promise<T>, budgetTracker?: BudgetTracker): Promise<T>;
59
+ export declare function runInExecutionContext<T>(executionId: string, fn: () => Promise<T>, budgetTracker?: BudgetTracker, agentName?: string): Promise<T>;
51
60
  /**
52
61
  * Generate a fresh execution_id matching the Python SDK's format:
53
62
  * `exec-<12 hex chars>`. UUID4-derived; the short-prefix variant is