mesedi 0.1.0 → 0.2.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 +26 -28
- package/dist/anthropic_integration.d.ts +9 -9
- package/dist/anthropic_integration.js +16 -16
- package/dist/anthropic_integration.js.map +1 -1
- package/dist/client.d.ts +6 -6
- package/dist/client.js +11 -11
- package/dist/client.js.map +1 -1
- package/dist/context.d.ts +2 -2
- package/dist/context.js +2 -2
- package/dist/events.d.ts +6 -6
- package/dist/events.js +5 -5
- 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.js +11 -11
- package/dist/halt_stream.js.map +1 -1
- package/dist/index.d.ts +11 -11
- package/dist/index.js +11 -11
- 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 +3 -3
- package/dist/observe.js +4 -4
- package/dist/observe.js.map +1 -1
- package/dist/tool.d.ts +1 -1
- package/dist/tool.js +4 -4
- package/dist/tool.js.map +1 -1
- package/dist/wrap.d.ts +3 -3
- package/dist/wrap.js +10 -10
- package/dist/wrap.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,28 +1,16 @@
|
|
|
1
1
|
# Mesedi TypeScript SDK
|
|
2
2
|
|
|
3
|
-
**Status:**
|
|
3
|
+
**Status:** v0.1.0 alpha. Live on npm.
|
|
4
4
|
|
|
5
5
|
The TypeScript companion to `sdk-python/`. Feature parity for the v1
|
|
6
|
-
surface
|
|
7
|
-
fail-open posture
|
|
6
|
+
surface (`configure()`, `wrap()`, `tool()`, async event shipper,
|
|
7
|
+
fail-open posture), built on Node 18+ native `fetch` and
|
|
8
8
|
`AsyncLocalStorage`. **Zero runtime dependencies.**
|
|
9
9
|
|
|
10
|
-
##
|
|
11
|
-
|
|
12
|
-
Prerequisites: Mesedi backend running on `localhost:8080`. See
|
|
13
|
-
`../backend/README.md` if not yet running.
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
cd ~/mesedi/sdk-typescript
|
|
17
|
-
npm install # installs only devDeps (TypeScript)
|
|
18
|
-
npm run build # compile src/ → dist/
|
|
19
|
-
node sandbox/real_agent.js
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
Or run the sandbox in one shot:
|
|
10
|
+
## Install
|
|
23
11
|
|
|
24
12
|
```bash
|
|
25
|
-
npm
|
|
13
|
+
npm install mesedi
|
|
26
14
|
```
|
|
27
15
|
|
|
28
16
|
## API
|
|
@@ -35,12 +23,12 @@ configure({
|
|
|
35
23
|
baseUrl: "http://localhost:8080",
|
|
36
24
|
});
|
|
37
25
|
|
|
38
|
-
// Define a tool
|
|
26
|
+
// Define a tool. Observed when called from inside a wrap()'d function.
|
|
39
27
|
const searchWeb = tool({ name: "search_web" }, async (q: string) => {
|
|
40
28
|
return ["result1", "result2"];
|
|
41
29
|
});
|
|
42
30
|
|
|
43
|
-
// Wrap an agent function
|
|
31
|
+
// Wrap an agent function. Records start/complete/crash automatically.
|
|
44
32
|
const runAgent = wrap(async (query: string) => {
|
|
45
33
|
const results = await searchWeb(query);
|
|
46
34
|
return `found ${results.length} results`;
|
|
@@ -72,7 +60,7 @@ For each `tool()`-decorated call (from inside a `wrap()`):
|
|
|
72
60
|
|
|
73
61
|
All HTTP is async via a single in-process queue + a `setInterval`
|
|
74
62
|
drainer. Network failures during observation NEVER throw back into the
|
|
75
|
-
wrapped agent
|
|
63
|
+
wrapped agent. The SDK is fail-open: a Mesedi outage degrades to
|
|
76
64
|
invisibility, not to broken production code.
|
|
77
65
|
|
|
78
66
|
## Framework integrations
|
|
@@ -113,25 +101,35 @@ Per invocation, the wrapper emits:
|
|
|
113
101
|
|
|
114
102
|
- One `llm_call` event per step (Vercel's multi-step ReAct surfaces
|
|
115
103
|
intermediate reasoning + final answer on `result.steps`). Model id,
|
|
116
|
-
user message, system prompt, token usage, response text
|
|
104
|
+
user message, system prompt, token usage, response text, all
|
|
117
105
|
captured in the standard Mesedi wire format.
|
|
118
106
|
- One `tool_call` event per tool invocation in each step. Pairs
|
|
119
107
|
`result.toolCalls[i]` to `result.toolResults` by `toolCallId`,
|
|
120
108
|
detects failure mode (missing result OR `result.error` field) and
|
|
121
109
|
records `status=failed` with `exception_type` / `exception_message`.
|
|
122
110
|
|
|
123
|
-
Detectors
|
|
124
|
-
cost-velocity, prompt-injection
|
|
111
|
+
Detectors (drift, identical/similar-call loops, tool-failures,
|
|
112
|
+
cost-velocity, prompt-injection) see the same wire format as a
|
|
125
113
|
hand-written `mesedi` instrumentation produces.
|
|
126
114
|
|
|
127
|
-
`ai` is declared as an **optional peer dependency
|
|
115
|
+
`ai` is declared as an **optional peer dependency**. Installing
|
|
128
116
|
`mesedi` doesn't require it. If your project already has `ai`
|
|
129
117
|
installed for `generateText`, the integration just works.
|
|
130
118
|
|
|
131
119
|
`streamText` and `generateObject` ship in a later slice.
|
|
132
120
|
|
|
133
|
-
##
|
|
121
|
+
## Releases
|
|
122
|
+
|
|
123
|
+
This SDK is published to npm via OIDC Trusted Publishing from the
|
|
124
|
+
`release-sdk-typescript.yml` GitHub Actions workflow, with no long-lived
|
|
125
|
+
NPM_TOKEN secret. Every release carries an npm provenance attestation
|
|
126
|
+
linking it to a specific commit in `mesedi-ai/mesedi`.
|
|
127
|
+
|
|
128
|
+
To cut a new release, bump `version` in `package.json`, commit, then:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
git tag -a sdk-typescript-v0.X.Y -m "Release sdk-typescript v0.X.Y"
|
|
132
|
+
git push origin sdk-typescript-v0.X.Y
|
|
133
|
+
```
|
|
134
134
|
|
|
135
|
-
|
|
136
|
-
trusted-publishing flow ships post-LOI alongside the SDK ecosystem
|
|
137
|
-
work in Phase 16.
|
|
135
|
+
The workflow installs, builds, and publishes with `--provenance`.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Anthropic SDK monkey-patch
|
|
2
|
+
* Anthropic SDK monkey-patch, auto-emit llm_call events for every
|
|
3
3
|
* messages.create() call inside a wrap()'d execution.
|
|
4
4
|
*
|
|
5
5
|
* Activation is opt-in (call instrumentAnthropic() once at startup),
|
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
*
|
|
9
9
|
* What gets captured per call:
|
|
10
10
|
* - model (e.g. "claude-opus-4-6")
|
|
11
|
-
* - system_prompt
|
|
12
|
-
* - user_message
|
|
13
|
-
* - response_text
|
|
14
|
-
* - input_tokens / output_tokens
|
|
15
|
-
* - duration_ms
|
|
16
|
-
* - status
|
|
11
|
+
* - system_prompt, truncated to 1000 chars
|
|
12
|
+
* - user_message, the LAST user-role message, truncated to 1000
|
|
13
|
+
* - response_text, concatenated text-block content, truncated
|
|
14
|
+
* - input_tokens / output_tokens, from response.usage
|
|
15
|
+
* - duration_ms, wall-clock of the API call
|
|
16
|
+
* - status, "ok" / "failed"
|
|
17
17
|
* - exception_type + exception_message on failure
|
|
18
18
|
*
|
|
19
19
|
* Dependency injection: instrumentAnthropic accepts an optional
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
/**
|
|
26
26
|
* Minimal duck-typed interfaces for the parts of the Anthropic SDK
|
|
27
27
|
* shape we depend on. Defined here so the SDK has zero direct
|
|
28
|
-
* dependency on @anthropic-ai/sdk
|
|
28
|
+
* dependency on @anthropic-ai/sdk, at runtime we just call .create()
|
|
29
29
|
* on whatever class was passed.
|
|
30
30
|
*
|
|
31
31
|
* `create` typed as `(...args: any[]) => Promise<any>` rather than a
|
|
@@ -45,7 +45,7 @@ export interface MessagesClassLike {
|
|
|
45
45
|
* llm_call events. Returns true on success or no-op (already
|
|
46
46
|
* patched). Returns false if no class was supplied and the
|
|
47
47
|
* @anthropic-ai/sdk package isn't installed (best-effort dynamic
|
|
48
|
-
* import
|
|
48
|
+
* import, kept optional so the SDK stays dependency-free at install
|
|
49
49
|
* time).
|
|
50
50
|
*/
|
|
51
51
|
export declare function instrumentAnthropic(messagesClass?: MessagesClassLike): Promise<boolean>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Anthropic SDK monkey-patch
|
|
2
|
+
* Anthropic SDK monkey-patch, auto-emit llm_call events for every
|
|
3
3
|
* messages.create() call inside a wrap()'d execution.
|
|
4
4
|
*
|
|
5
5
|
* Activation is opt-in (call instrumentAnthropic() once at startup),
|
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
*
|
|
9
9
|
* What gets captured per call:
|
|
10
10
|
* - model (e.g. "claude-opus-4-6")
|
|
11
|
-
* - system_prompt
|
|
12
|
-
* - user_message
|
|
13
|
-
* - response_text
|
|
14
|
-
* - input_tokens / output_tokens
|
|
15
|
-
* - duration_ms
|
|
16
|
-
* - status
|
|
11
|
+
* - system_prompt, truncated to 1000 chars
|
|
12
|
+
* - user_message, the LAST user-role message, truncated to 1000
|
|
13
|
+
* - response_text, concatenated text-block content, truncated
|
|
14
|
+
* - input_tokens / output_tokens, from response.usage
|
|
15
|
+
* - duration_ms, wall-clock of the API call
|
|
16
|
+
* - status, "ok" / "failed"
|
|
17
17
|
* - exception_type + exception_message on failure
|
|
18
18
|
*
|
|
19
19
|
* Dependency injection: instrumentAnthropic accepts an optional
|
|
@@ -29,7 +29,7 @@ const MAX_SYSTEM = 1000;
|
|
|
29
29
|
const MAX_USER_MSG = 1000;
|
|
30
30
|
const MAX_RESPONSE = 1000;
|
|
31
31
|
const MAX_EXC_MSG = 500;
|
|
32
|
-
/** Already-patched classes
|
|
32
|
+
/** Already-patched classes, keyed by class identity to make
|
|
33
33
|
* instrumentAnthropic() idempotent and to allow distinct fake classes
|
|
34
34
|
* to be patched in tests without falsely tripping the check. */
|
|
35
35
|
const _patched = new WeakSet();
|
|
@@ -38,7 +38,7 @@ const _patched = new WeakSet();
|
|
|
38
38
|
* llm_call events. Returns true on success or no-op (already
|
|
39
39
|
* patched). Returns false if no class was supplied and the
|
|
40
40
|
* @anthropic-ai/sdk package isn't installed (best-effort dynamic
|
|
41
|
-
* import
|
|
41
|
+
* import, kept optional so the SDK stays dependency-free at install
|
|
42
42
|
* time).
|
|
43
43
|
*/
|
|
44
44
|
export async function instrumentAnthropic(messagesClass) {
|
|
@@ -50,7 +50,7 @@ export async function instrumentAnthropic(messagesClass) {
|
|
|
50
50
|
// installed, we auto-locate Messages; otherwise instrumentation
|
|
51
51
|
// is a no-op.
|
|
52
52
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
53
|
-
// @ts-ignore
|
|
53
|
+
// @ts-ignore, the package may not be installed; this is by design
|
|
54
54
|
const mod = (await import("@anthropic-ai/sdk"));
|
|
55
55
|
cls = mod?.Anthropic?.Messages;
|
|
56
56
|
}
|
|
@@ -60,7 +60,7 @@ export async function instrumentAnthropic(messagesClass) {
|
|
|
60
60
|
return false;
|
|
61
61
|
}
|
|
62
62
|
if (!cls) {
|
|
63
|
-
console.warn("mesedi: located @anthropic-ai/sdk but couldn't find Anthropic.Messages
|
|
63
|
+
console.warn("mesedi: located @anthropic-ai/sdk but couldn't find Anthropic.Messages, SDK version mismatch?");
|
|
64
64
|
return false;
|
|
65
65
|
}
|
|
66
66
|
}
|
|
@@ -70,14 +70,14 @@ export async function instrumentAnthropic(messagesClass) {
|
|
|
70
70
|
cls.prototype.create = async function patchedCreate(...args) {
|
|
71
71
|
const ctx = currentExecutionContext();
|
|
72
72
|
if (!ctx) {
|
|
73
|
-
// Outside wrap()
|
|
73
|
+
// Outside wrap(), pass through unobserved.
|
|
74
74
|
return originalCreate.apply(this, args);
|
|
75
75
|
}
|
|
76
76
|
// Halt-safe boundary: check the budget BEFORE the actual LLM
|
|
77
77
|
// call. If a budget exists and is exceeded, this throws
|
|
78
78
|
// MesediHalt which propagates up to wrap()'s catch block. We
|
|
79
79
|
// count this as a step now (after the check passes) so the
|
|
80
|
-
// counter advances even though the LLM call hasn't run yet
|
|
80
|
+
// counter advances even though the LLM call hasn't run yet ,
|
|
81
81
|
// matches the Python SDK's pattern (check, then count, then act).
|
|
82
82
|
ctx.checkBudget();
|
|
83
83
|
if (ctx.budgetTracker) {
|
|
@@ -101,7 +101,7 @@ export async function instrumentAnthropic(messagesClass) {
|
|
|
101
101
|
// halt-safe boundary checks know how many tokens this execution
|
|
102
102
|
// has consumed. Tokens from FAILED LLM calls don't get
|
|
103
103
|
// accounted (we don't reach this code path on the error
|
|
104
|
-
// branch)
|
|
104
|
+
// branch), that matches the Python SDK behavior.
|
|
105
105
|
if (ctx.budgetTracker) {
|
|
106
106
|
ctx.budgetTracker.addTokens(inputTokens, outputTokens);
|
|
107
107
|
}
|
|
@@ -191,7 +191,7 @@ function extractResponseFields(response) {
|
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
193
|
catch {
|
|
194
|
-
// best effort
|
|
194
|
+
// best effort, leave responseText empty
|
|
195
195
|
}
|
|
196
196
|
try {
|
|
197
197
|
if (response.usage) {
|
|
@@ -200,7 +200,7 @@ function extractResponseFields(response) {
|
|
|
200
200
|
}
|
|
201
201
|
}
|
|
202
202
|
catch {
|
|
203
|
-
// best effort
|
|
203
|
+
// best effort, leave token counts at 0
|
|
204
204
|
}
|
|
205
205
|
return { responseText, inputTokens, outputTokens };
|
|
206
206
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic_integration.js","sourceRoot":"","sources":["../src/anthropic_integration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,uBAAuB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAS,SAAS,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE9D,MAAM,UAAU,GAAG,IAAI,CAAC;AACxB,MAAM,YAAY,GAAG,IAAI,CAAC;AAC1B,MAAM,YAAY,GAAG,IAAI,CA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E,GAAG,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC;AACrC,CAAC"}
|
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* MesediClient
|
|
2
|
+
* MesediClient, HTTP client + async event shipper for Node.
|
|
3
3
|
*
|
|
4
4
|
* Zero runtime dependencies: uses Node 18+ native `fetch` for HTTP
|
|
5
5
|
* and the event loop for async dispatch. No background threads (Node
|
|
@@ -12,12 +12,12 @@
|
|
|
12
12
|
* backend tightens enforcement.
|
|
13
13
|
*
|
|
14
14
|
* Fail-open: every observation HTTP call wraps its promise in a
|
|
15
|
-
* try/catch
|
|
15
|
+
* try/catch, backend errors are logged via console.warn (configurable
|
|
16
16
|
* via a logger injection in a future polish slice) but NEVER bubble
|
|
17
17
|
* back to the wrapped agent code.
|
|
18
18
|
*/
|
|
19
19
|
import { Event, Execution } from "./events.js";
|
|
20
|
-
export declare const DEFAULT_BASE_URL = "
|
|
20
|
+
export declare const DEFAULT_BASE_URL = "https://api.mesedi.ai";
|
|
21
21
|
export declare const DEFAULT_TIMEOUT_MS = 10000;
|
|
22
22
|
export declare const SCHEMA_VERSION = "1";
|
|
23
23
|
/** Configuration accepted by `configure()`. */
|
|
@@ -29,7 +29,7 @@ export interface ConfigureOptions {
|
|
|
29
29
|
apiKey?: string;
|
|
30
30
|
/**
|
|
31
31
|
* Backend URL. Defaults to `MESEDI_BASE_URL` env var, then to
|
|
32
|
-
* "
|
|
32
|
+
* "https://api.mesedi.ai" (production). Override to localhost for local dev.
|
|
33
33
|
*/
|
|
34
34
|
baseUrl?: string;
|
|
35
35
|
/** Per-request timeout in milliseconds. Default 10s. */
|
|
@@ -72,7 +72,7 @@ export declare class MesediClient {
|
|
|
72
72
|
shutdown(timeoutMs?: number): Promise<void>;
|
|
73
73
|
private enqueue;
|
|
74
74
|
/**
|
|
75
|
-
* Single tick of the shipper loop
|
|
75
|
+
* Single tick of the shipper loop, called by setInterval. Drains
|
|
76
76
|
* the queue, dispatches non-event items, and flushes the pending-
|
|
77
77
|
* events batch if it's full OR the flush interval has elapsed.
|
|
78
78
|
*/
|
|
@@ -83,7 +83,7 @@ export declare class MesediClient {
|
|
|
83
83
|
private sendUpdateExecution;
|
|
84
84
|
/**
|
|
85
85
|
* One HTTP call with up to 3 retries on transient failure
|
|
86
|
-
* (network errors, 5xx). 4xx responses drop with a warning
|
|
86
|
+
* (network errors, 5xx). 4xx responses drop with a warning, the
|
|
87
87
|
* request is malformed and retrying won't help.
|
|
88
88
|
*/
|
|
89
89
|
private sendWithRetry;
|
package/dist/client.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* MesediClient
|
|
2
|
+
* MesediClient, HTTP client + async event shipper for Node.
|
|
3
3
|
*
|
|
4
4
|
* Zero runtime dependencies: uses Node 18+ native `fetch` for HTTP
|
|
5
5
|
* and the event loop for async dispatch. No background threads (Node
|
|
@@ -12,12 +12,12 @@
|
|
|
12
12
|
* backend tightens enforcement.
|
|
13
13
|
*
|
|
14
14
|
* Fail-open: every observation HTTP call wraps its promise in a
|
|
15
|
-
* try/catch
|
|
15
|
+
* try/catch, backend errors are logged via console.warn (configurable
|
|
16
16
|
* via a logger injection in a future polish slice) but NEVER bubble
|
|
17
17
|
* back to the wrapped agent code.
|
|
18
18
|
*/
|
|
19
19
|
import { eventToWire, executionEndPayload, executionStartPayload, } from "./events.js";
|
|
20
|
-
export const DEFAULT_BASE_URL = "
|
|
20
|
+
export const DEFAULT_BASE_URL = "https://api.mesedi.ai";
|
|
21
21
|
export const DEFAULT_TIMEOUT_MS = 10_000;
|
|
22
22
|
export const SCHEMA_VERSION = "1";
|
|
23
23
|
export class MesediClient {
|
|
@@ -40,7 +40,7 @@ export class MesediClient {
|
|
|
40
40
|
throw new Error("Mesedi API key not provided. Pass { apiKey: '...' } or set MESEDI_API_KEY in the environment.");
|
|
41
41
|
}
|
|
42
42
|
if (!apiKey.startsWith("mesedi_sk_")) {
|
|
43
|
-
// Mirror the backend's auth-middleware check
|
|
43
|
+
// Mirror the backend's auth-middleware check, fail loudly on
|
|
44
44
|
// the SDK side rather than letting the backend return 401 on
|
|
45
45
|
// every call.
|
|
46
46
|
throw new Error("api_key must start with 'mesedi_sk_' (received an obviously-malformed key)");
|
|
@@ -52,7 +52,7 @@ export class MesediClient {
|
|
|
52
52
|
this.batchSize = opts.batchSize ?? 100;
|
|
53
53
|
this.maxQueue = opts.maxQueue ?? 10_000;
|
|
54
54
|
// Start the periodic flush timer. unref() so it doesn't keep the
|
|
55
|
-
// event loop alive on its own
|
|
55
|
+
// event loop alive on its own, the process can exit when the
|
|
56
56
|
// user's code is done, and our atexit handler drains anything left.
|
|
57
57
|
this.timer = setInterval(() => this.tick(), this.flushIntervalMs);
|
|
58
58
|
this.timer.unref();
|
|
@@ -105,7 +105,7 @@ export class MesediClient {
|
|
|
105
105
|
if (this.stopped) {
|
|
106
106
|
// Even after shutdown is invoked, the user's main code might
|
|
107
107
|
// continue running for a short tick. Best-effort: drop silently
|
|
108
|
-
// rather than throw
|
|
108
|
+
// rather than throw, we're already past the contractual
|
|
109
109
|
// observation window.
|
|
110
110
|
return;
|
|
111
111
|
}
|
|
@@ -119,7 +119,7 @@ export class MesediClient {
|
|
|
119
119
|
this.queue.push(item);
|
|
120
120
|
}
|
|
121
121
|
/**
|
|
122
|
-
* Single tick of the shipper loop
|
|
122
|
+
* Single tick of the shipper loop, called by setInterval. Drains
|
|
123
123
|
* the queue, dispatches non-event items, and flushes the pending-
|
|
124
124
|
* events batch if it's full OR the flush interval has elapsed.
|
|
125
125
|
*/
|
|
@@ -127,7 +127,7 @@ export class MesediClient {
|
|
|
127
127
|
if (this.queue.length === 0 && this.pendingEvents.length === 0)
|
|
128
128
|
return;
|
|
129
129
|
// Chain onto the previous tick's promise so we serialize HTTP
|
|
130
|
-
// calls
|
|
130
|
+
// calls, preserves ordering (POST /executions before PATCH for
|
|
131
131
|
// the same execution).
|
|
132
132
|
this.inflight = this.inflight.then(() => this.processOnce());
|
|
133
133
|
await this.inflight;
|
|
@@ -142,7 +142,7 @@ export class MesediClient {
|
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
else {
|
|
145
|
-
// Non-event item
|
|
145
|
+
// Non-event item, flush pending events first so the PATCH
|
|
146
146
|
// doesn't arrive before its preceding /events POST.
|
|
147
147
|
if (this.pendingEvents.length > 0) {
|
|
148
148
|
await this.flushPendingEvents();
|
|
@@ -181,7 +181,7 @@ export class MesediClient {
|
|
|
181
181
|
}
|
|
182
182
|
/**
|
|
183
183
|
* One HTTP call with up to 3 retries on transient failure
|
|
184
|
-
* (network errors, 5xx). 4xx responses drop with a warning
|
|
184
|
+
* (network errors, 5xx). 4xx responses drop with a warning, the
|
|
185
185
|
* request is malformed and retrying won't help.
|
|
186
186
|
*/
|
|
187
187
|
async sendWithRetry(method, path, body, description) {
|
|
@@ -205,7 +205,7 @@ export class MesediClient {
|
|
|
205
205
|
if (resp.status < 400)
|
|
206
206
|
return; // success
|
|
207
207
|
if (resp.status >= 400 && resp.status < 500) {
|
|
208
|
-
// Permanent failure
|
|
208
|
+
// Permanent failure, retrying won't help.
|
|
209
209
|
const text = await resp.text().catch(() => "");
|
|
210
210
|
console.warn(`mesedi: ${description} rejected with ${resp.status}: ${text.slice(0, 200)}`);
|
|
211
211
|
return;
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAGL,WAAW,EACX,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AAErB,MAAM,CAAC,MAAM,gBAAgB,GAAG,uBAAuB,CAAC;AACxD,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AACzC,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,CAAC;AAkClC,MAAM,OAAO,YAA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Q,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;QACxC,OACE,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC;YACxD,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,EACrB,CAAC;YACD,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;QAC3B,CAAC;IACH,CAAC;CACF;AAED,uEAAuE;AAEvE,IAAI,cAAc,GAAwB,IAAI,CAAC;AAE/C,MAAM,UAAU,SAAS,CAAC,OAAyB,EAAE;IACnD,IAAI,cAAc,EAAE,CAAC;QACnB,oDAAoD;QACpD,cAAc,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IACnD,CAAC;IACD,cAAc,GAAG,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC;IACxC,OAAO,cAAc,CAAC;AACxB,CAAC;AAED,MAAM,UAAU,SAAS;IACvB,IAAI,cAAc;QAAE,OAAO,cAAc,CAAC;IAC1C,oDAAoD;IACpD,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,EAAE,CAAC;QAClC,OAAO,SAAS,EAAE,CAAC;IACrB,CAAC;IACD,MAAM,IAAI,KAAK,CACb,+GAA+G,CAChH,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,SAAS,GAAG,KAAK;IAC3C,OAAO,SAAS,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AACtC,CAAC"}
|
package/dist/context.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Execution-context tracking using `AsyncLocalStorage
|
|
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
|
|
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
|
*/
|
package/dist/context.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Execution-context tracking using `AsyncLocalStorage
|
|
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
|
|
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
|
*/
|
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
|
*
|
|
@@ -65,7 +65,7 @@ export interface Execution {
|
|
|
65
65
|
crash_signature?: string;
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
68
|
-
* A single observation within an execution. Payload is opaque JSON
|
|
68
|
+
* A single observation within an execution. Payload is opaque JSON ,
|
|
69
69
|
* the backend stores it as a raw blob; per-event-type payload shapes
|
|
70
70
|
* are defined in the typed payload helpers below.
|
|
71
71
|
*/
|
|
@@ -79,12 +79,12 @@ export interface Event {
|
|
|
79
79
|
payload: Record<string, unknown>;
|
|
80
80
|
}
|
|
81
81
|
/**
|
|
82
|
-
* Build the body for POST /executions
|
|
82
|
+
* Build the body for POST /executions, only the fields valid at
|
|
83
83
|
* execution start.
|
|
84
84
|
*/
|
|
85
85
|
export declare function executionStartPayload(e: Execution): Record<string, unknown>;
|
|
86
86
|
/**
|
|
87
|
-
* Build the body for PATCH /executions/{id}
|
|
87
|
+
* Build the body for PATCH /executions/{id}, omit any undefined
|
|
88
88
|
* fields so the backend's strict-decode doesn't reject them.
|
|
89
89
|
*/
|
|
90
90
|
export declare function executionEndPayload(e: Execution): Record<string, unknown>;
|
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
|
*
|
|
@@ -52,7 +52,7 @@ export const Status = {
|
|
|
52
52
|
VALIDATION_FAILED: "validation_failed",
|
|
53
53
|
};
|
|
54
54
|
/**
|
|
55
|
-
* Build the body for POST /executions
|
|
55
|
+
* Build the body for POST /executions, only the fields valid at
|
|
56
56
|
* execution start.
|
|
57
57
|
*/
|
|
58
58
|
export function executionStartPayload(e) {
|
|
@@ -65,7 +65,7 @@ export function executionStartPayload(e) {
|
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
68
|
-
* Build the body for PATCH /executions/{id}
|
|
68
|
+
* Build the body for PATCH /executions/{id}, omit any undefined
|
|
69
69
|
* fields so the backend's strict-decode doesn't reject them.
|
|
70
70
|
*/
|
|
71
71
|
export function executionEndPayload(e) {
|