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/dist/observe.d.ts
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* }
|
|
17
17
|
*
|
|
18
18
|
* Both helpers no-op silently when called outside an active wrap()
|
|
19
|
-
* execution context
|
|
19
|
+
* execution context, same fail-open pattern as `tool()`.
|
|
20
20
|
*/
|
|
21
21
|
/**
|
|
22
22
|
* Emit a `checkpoint` event marking a notable point in execution.
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* A checkpoint is a free-form marker: a name + arbitrary metadata.
|
|
25
25
|
* Typical uses: "after_retrieval", "before_synthesis", "cache_hit".
|
|
26
26
|
* Useful both for Phase 3+ detector hooks (drift, cost-velocity)
|
|
27
|
-
* and for ad-hoc debugging
|
|
27
|
+
* and for ad-hoc debugging, replay UI in a future phase will
|
|
28
28
|
* render checkpoints as anchored markers on the execution timeline.
|
|
29
29
|
*
|
|
30
30
|
* Outside `wrap()`: silent no-op.
|
|
@@ -40,7 +40,7 @@ export interface ValidatorResultOptions {
|
|
|
40
40
|
*
|
|
41
41
|
* Validators are checks the agent (or its framework) runs against
|
|
42
42
|
* intermediate or final outputs: schema conformance, factuality,
|
|
43
|
-
* relevance, safety. The result
|
|
43
|
+
* relevance, safety. The result, pass or fail, becomes a discrete
|
|
44
44
|
* event so Phase-3 detection can spot patterns like "validator X
|
|
45
45
|
* has been failing 90% of the time on this model."
|
|
46
46
|
*
|
package/dist/observe.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* }
|
|
17
17
|
*
|
|
18
18
|
* Both helpers no-op silently when called outside an active wrap()
|
|
19
|
-
* execution context
|
|
19
|
+
* execution context, same fail-open pattern as `tool()`.
|
|
20
20
|
*/
|
|
21
21
|
import { getClient } from "./client.js";
|
|
22
22
|
import { currentExecutionContext, newEventId } from "./context.js";
|
|
@@ -28,7 +28,7 @@ const MAX_VALIDATOR_MSG = 500;
|
|
|
28
28
|
* A checkpoint is a free-form marker: a name + arbitrary metadata.
|
|
29
29
|
* Typical uses: "after_retrieval", "before_synthesis", "cache_hit".
|
|
30
30
|
* Useful both for Phase 3+ detector hooks (drift, cost-velocity)
|
|
31
|
-
* and for ad-hoc debugging
|
|
31
|
+
* and for ad-hoc debugging, replay UI in a future phase will
|
|
32
32
|
* render checkpoints as anchored markers on the execution timeline.
|
|
33
33
|
*
|
|
34
34
|
* Outside `wrap()`: silent no-op.
|
|
@@ -61,7 +61,7 @@ export function checkpoint(name, metadata = {}) {
|
|
|
61
61
|
*
|
|
62
62
|
* Validators are checks the agent (or its framework) runs against
|
|
63
63
|
* intermediate or final outputs: schema conformance, factuality,
|
|
64
|
-
* relevance, safety. The result
|
|
64
|
+
* relevance, safety. The result, pass or fail, becomes a discrete
|
|
65
65
|
* event so Phase-3 detection can spot patterns like "validator X
|
|
66
66
|
* has been failing 90% of the time on this model."
|
|
67
67
|
*
|
|
@@ -75,7 +75,7 @@ export function validatorResult(name, passed, opts = {}) {
|
|
|
75
75
|
if (severity !== "warning" &&
|
|
76
76
|
severity !== "error" &&
|
|
77
77
|
severity !== "critical") {
|
|
78
|
-
// Don't throw
|
|
78
|
+
// Don't throw, the caller's agent shouldn't fail because of an
|
|
79
79
|
// SDK-side validation. Coerce to the safest default.
|
|
80
80
|
severity = "error";
|
|
81
81
|
}
|
package/dist/observe.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observe.js","sourceRoot":"","sources":["../src/observe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;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,iBAAiB,GAAG,GAAG,CAAC;AAE9B;;;;;;;;;;GAUG;AACH,MAAM,UAAU,UAAU,CACxB,IAAY,EACZ,WAAoC,EAAE;IAEtC,MAAM,GAAG,GAAG,uBAAuB,EAAE,CAAC;IACtC,IAAI,CAAC,GAAG;QAAE,OAAO;IAEjB,kEAAkE;IAClE,mEAAmE;IACnE,gEAAgE;IAChE,8DAA8D;IAC9D,GAAG,CAAC,WAAW,EAAE,CAAC;IAClB,IAAI,GAAG,CAAC,aAAa,EAAE,CAAC;QACtB,GAAG,CAAC,aAAa,CAAC,cAAc,EAAE,CAAC;IACrC,CAAC;IAED,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAC3B,MAAM,KAAK,GAAU;QACnB,QAAQ,EAAE,UAAU,EAAE;QACtB,YAAY,EAAE,GAAG,CAAC,WAAW;QAC7B,UAAU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EAAE,aAAa,EAAE;QAC1B,OAAO;KACR,CAAC;IACF,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;AAC5B,CAAC"}
|
package/dist/tool.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* tool()
|
|
2
|
+
* tool(), wraps an async function as an instrumented agent tool.
|
|
3
3
|
*
|
|
4
4
|
* Mirrors the Python `@mesedi.tool` decorator, but as a higher-order
|
|
5
5
|
* function (TS doesn't have stable decorators yet). When the
|
package/dist/tool.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* tool()
|
|
2
|
+
* tool(), wraps an async function as an instrumented agent tool.
|
|
3
3
|
*
|
|
4
4
|
* Mirrors the Python `@mesedi.tool` decorator, but as a higher-order
|
|
5
5
|
* function (TS doesn't have stable decorators yet). When the
|
|
@@ -37,7 +37,7 @@ export function tool(fnOrOpts, maybeFn) {
|
|
|
37
37
|
else {
|
|
38
38
|
opts = fnOrOpts;
|
|
39
39
|
if (!maybeFn) {
|
|
40
|
-
throw new TypeError("tool() requires a function
|
|
40
|
+
throw new TypeError("tool() requires a function, pass either tool(fn) or tool(options, fn).");
|
|
41
41
|
}
|
|
42
42
|
fn = maybeFn;
|
|
43
43
|
}
|
|
@@ -45,13 +45,13 @@ export function tool(fnOrOpts, maybeFn) {
|
|
|
45
45
|
return async function inner(...args) {
|
|
46
46
|
const ctx = currentExecutionContext();
|
|
47
47
|
if (!ctx) {
|
|
48
|
-
// No active execution
|
|
48
|
+
// No active execution, run unobserved.
|
|
49
49
|
return fn(...args);
|
|
50
50
|
}
|
|
51
51
|
// Halt-safe boundary: check the budget BEFORE doing any work.
|
|
52
52
|
// If a budget exists and is exceeded, this throws MesediHalt
|
|
53
53
|
// which propagates up to wrap()'s catch block. The user's tool
|
|
54
|
-
// code never runs
|
|
54
|
+
// code never runs, guarantees halt fires at the boundary, not
|
|
55
55
|
// mid-tool. wrap() also incrementing steps post-check matches
|
|
56
56
|
// the Python pattern (check, then count).
|
|
57
57
|
ctx.checkBudget();
|
package/dist/tool.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.js","sourceRoot":"","sources":["../src/tool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EACL,uBAAuB,EACvB,UAAU,GACX,MAAM,cAAc,CAAC;AACtB,OAAO,EAAS,SAAS,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE9D,MAAM,YAAY,GAAG,GAAG,CAAC;AACzB,MAAM,eAAe,GAAG,GAAG,CAAC;AAC5B,MAAM,WAAW,GAAG,GAAG,CAAC;AAOxB;;GAEG;AACH,MAAM,UAAU,IAAI,CAClB,QAA8D,EAC9D,OAA8C;IAE9C,IAAI,IAAiB,CAAC;IACtB,IAAI,EAAwC,CAAC;IAC7C,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;QACnC,IAAI,GAAG,EAAE,CAAC;QACV,8DAA8D;QAC9D,yDAAyD;QACzD,EAAE,GAAG,QAAgD,CAAC;IACxD,CAAC;SAAM,CAAC;QACN,IAAI,GAAG,QAAQ,CAAC;QAChB,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,SAAS,CACjB,
|
|
1
|
+
{"version":3,"file":"tool.js","sourceRoot":"","sources":["../src/tool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EACL,uBAAuB,EACvB,UAAU,GACX,MAAM,cAAc,CAAC;AACtB,OAAO,EAAS,SAAS,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE9D,MAAM,YAAY,GAAG,GAAG,CAAC;AACzB,MAAM,eAAe,GAAG,GAAG,CAAC;AAC5B,MAAM,WAAW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.
|
|
3
3
|
*
|
|
4
4
|
* TypeScript doesn't have stable decorators in regular JS, so wrap()
|
|
5
5
|
* is a HIGHER-ORDER FUNCTION rather than a decorator. The shape:
|
|
@@ -51,12 +51,12 @@ export interface WrapOptions {
|
|
|
51
51
|
* Optional per-execution budget. When set, the wrapped function
|
|
52
52
|
* runs with halt-safe boundary checks at every `tool()` /
|
|
53
53
|
* `checkpoint()` / Anthropic LLM-call entry point. If any limit is
|
|
54
|
-
* exceeded between calls, a MesediHalt is thrown internally
|
|
54
|
+
* exceeded between calls, a MesediHalt is thrown internally ,
|
|
55
55
|
* wrap() catches it, marks the execution status=halted (with
|
|
56
56
|
* crash_signature=`halt:<trigger>`), and returns undefined.
|
|
57
57
|
*
|
|
58
58
|
* The wrapped function's normal try/finally cleanup runs as
|
|
59
|
-
* expected
|
|
59
|
+
* expected, halt is raised AT a safe boundary, never mid-tool /
|
|
60
60
|
* mid-LLM-call, so user resources release cleanly.
|
|
61
61
|
*/
|
|
62
62
|
budget?: Budget;
|
package/dist/wrap.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* wrap()
|
|
2
|
+
* wrap(), Mesedi's primary observation primitive for TypeScript.
|
|
3
3
|
*
|
|
4
4
|
* TypeScript doesn't have stable decorators in regular JS, so wrap()
|
|
5
5
|
* is a HIGHER-ORDER FUNCTION rather than a decorator. The shape:
|
|
@@ -49,22 +49,22 @@ import { HaltStreamReader } from "./halt_stream.js";
|
|
|
49
49
|
*/
|
|
50
50
|
export function wrap(fnOrOpts, maybeFn) {
|
|
51
51
|
// Support both call shapes:
|
|
52
|
-
// wrap(fn)
|
|
53
|
-
// wrap({...opts}, fn)
|
|
52
|
+
// wrap(fn), no options
|
|
53
|
+
// wrap({...opts}, fn), with options
|
|
54
54
|
let opts;
|
|
55
55
|
let fn;
|
|
56
56
|
if (typeof fnOrOpts === "function") {
|
|
57
57
|
opts = {};
|
|
58
58
|
// Cast: `typeof === "function"` narrows to the broad built-in
|
|
59
59
|
// `Function` type rather than to our specific signature, but at
|
|
60
|
-
// runtime it IS our signature
|
|
60
|
+
// runtime it IS our signature, the call site guarantees that
|
|
61
61
|
// shape since the function position is statically typed.
|
|
62
62
|
fn = fnOrOpts;
|
|
63
63
|
}
|
|
64
64
|
else {
|
|
65
65
|
opts = fnOrOpts;
|
|
66
66
|
if (!maybeFn) {
|
|
67
|
-
throw new TypeError("wrap() requires a function
|
|
67
|
+
throw new TypeError("wrap() requires a function, pass either wrap(fn) or wrap(options, fn).");
|
|
68
68
|
}
|
|
69
69
|
fn = maybeFn;
|
|
70
70
|
}
|
|
@@ -82,7 +82,7 @@ export function wrap(fnOrOpts, maybeFn) {
|
|
|
82
82
|
sdk_version: "0.0.4",
|
|
83
83
|
};
|
|
84
84
|
// Construct a budget tracker iff a budget was supplied. Stays
|
|
85
|
-
// undefined for un-budgeted wraps
|
|
85
|
+
// undefined for un-budgeted wraps, checkBudget() then no-ops.
|
|
86
86
|
const tracker = opts.budget ? new BudgetTracker(opts.budget) : undefined;
|
|
87
87
|
// Sub-slice 21e: if a budget is configured, spawn an SSE reader
|
|
88
88
|
// subscribed to /executions/{id}/halt-stream. When the backend
|
|
@@ -116,16 +116,16 @@ export function wrap(fnOrOpts, maybeFn) {
|
|
|
116
116
|
execution.duration_ms = Math.round(performance.now() - startWall);
|
|
117
117
|
execution.ended_at = utcNowRfc3339();
|
|
118
118
|
if (isMesediHalt(err)) {
|
|
119
|
-
// Controlled halt
|
|
119
|
+
// Controlled halt, record as halted, NOT crashed. The
|
|
120
120
|
// crash_signature carries the trigger so the dashboard can
|
|
121
|
-
// group halts by cause (`halt:wall_clock` etc.)
|
|
121
|
+
// group halts by cause (`halt:wall_clock` etc.), same wire
|
|
122
122
|
// format the Python SDK emits.
|
|
123
123
|
execution.status = Status.HALTED;
|
|
124
124
|
// err is narrowed to MesediHalt here by isMesediHalt's type
|
|
125
125
|
// guard, so the trigger access is type-safe.
|
|
126
126
|
execution.crash_signature = `halt:${err.trigger}`;
|
|
127
127
|
client.submitExecutionEnd(execution);
|
|
128
|
-
// Return undefined
|
|
128
|
+
// Return undefined, DON'T re-throw. The halt is a
|
|
129
129
|
// controlled stop; the caller's downstream code should NOT
|
|
130
130
|
// see an exception. This matches Python's `return None`
|
|
131
131
|
// behavior in wrap.py.
|
|
@@ -149,7 +149,7 @@ export function wrap(fnOrOpts, maybeFn) {
|
|
|
149
149
|
*
|
|
150
150
|
* Matches the Python SDK formula: SHA-256 of (error class name +
|
|
151
151
|
* the first 5 lines of the formatted error). Truncates to 16 hex
|
|
152
|
-
* chars
|
|
152
|
+
* chars, collision-resistant at scale, easy to display in
|
|
153
153
|
* dashboards.
|
|
154
154
|
*
|
|
155
155
|
* The backend's Phase-3a crash grouper uses the same input shape, so
|
package/dist/wrap.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrap.js","sourceRoot":"","sources":["../src/wrap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EACL,cAAc,EACd,qBAAqB,GACtB,MAAM,cAAc,CAAC;AACtB,OAAO,EAEL,MAAM,EACN,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAU,aAAa,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AA0BpD;;;GAGG;AACH,MAAM,UAAU,IAAI,CAClB,QAA8D,EAC9D,OAA8C;IAE9C,4BAA4B;IAC5B,
|
|
1
|
+
{"version":3,"file":"wrap.js","sourceRoot":"","sources":["../src/wrap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,OAAO,EAAE,UA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CAAC;IAC1E,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACtD,MAAM,KAAK,GAAG,GAAG,IAAI,KAAK,IAAI,EAAE,CAAC;IACjC,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC/E,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mesedi",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Mesedi SDK — guardians for autonomous AI agents. Detect failures, halt runaways, escalate first occurrence.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://mesedi.ai",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"bugs": {
|
|
13
13
|
"url": "https://github.com/mesedi-ai/mesedi/issues"
|
|
14
14
|
},
|
|
15
|
-
"author": "Robert J. Canario <
|
|
15
|
+
"author": "Robert J. Canario <hello@mesedi.ai>",
|
|
16
16
|
"type": "module",
|
|
17
17
|
"main": "./dist/index.js",
|
|
18
18
|
"types": "./dist/index.d.ts",
|