@inferior-ai/sdk 2.0.0-beta.3
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/CHANGELOG.md +70 -0
- package/LICENSE.md +37 -0
- package/NOTICE.md +56 -0
- package/README.md +454 -0
- package/SECURITY.md +62 -0
- package/STABILITY.md +95 -0
- package/SUPPORT.md +66 -0
- package/dist/__tests__/with_mock_client.test.d.ts +9 -0
- package/dist/__tests__/with_mock_client.test.d.ts.map +1 -0
- package/dist/__tests__/with_mock_client.test.js +154 -0
- package/dist/__tests__/with_mock_client.test.js.map +1 -0
- package/dist/_worthiness.d.ts +34 -0
- package/dist/_worthiness.d.ts.map +1 -0
- package/dist/_worthiness.js +201 -0
- package/dist/_worthiness.js.map +1 -0
- package/dist/client.d.ts +155 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +900 -0
- package/dist/client.js.map +1 -0
- package/dist/constants.d.ts +31 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +35 -0
- package/dist/constants.js.map +1 -0
- package/dist/errors.d.ts +71 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +114 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/models.d.ts +603 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +10 -0
- package/dist/models.js.map +1 -0
- package/dist/retry.d.ts +35 -0
- package/dist/retry.d.ts.map +1 -0
- package/dist/retry.js +83 -0
- package/dist/retry.js.map +1 -0
- package/dist/testing/index.d.ts +16 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +15 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/mock-client.d.ts +102 -0
- package/dist/testing/mock-client.d.ts.map +1 -0
- package/dist/testing/mock-client.js +217 -0
- package/dist/testing/mock-client.js.map +1 -0
- package/dist/webhooks.d.ts +52 -0
- package/dist/webhooks.d.ts.map +1 -0
- package/dist/webhooks.js +90 -0
- package/dist/webhooks.js.map +1 -0
- package/package.json +61 -0
package/STABILITY.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Stability policy — inferior-sdk-ts
|
|
2
|
+
|
|
3
|
+
This document explains what guarantees the `@inferior-ai/sdk` package
|
|
4
|
+
makes during the beta phase and what triggers a graduation to stable.
|
|
5
|
+
|
|
6
|
+
## Current stage
|
|
7
|
+
|
|
8
|
+
**Beta** (`2.0.0-beta.0`). API surfaces are likely-stable but not
|
|
9
|
+
contract-locked. We may make breaking changes between beta releases
|
|
10
|
+
when we judge them to materially improve the SDK before customers pin
|
|
11
|
+
to a stable version.
|
|
12
|
+
|
|
13
|
+
## What's stable now
|
|
14
|
+
|
|
15
|
+
These are unlikely to break across betas; if they do, we'll call it
|
|
16
|
+
out at the top of the changelog and ship a deprecation in a prior
|
|
17
|
+
beta:
|
|
18
|
+
|
|
19
|
+
- The shape of the core client constructor.
|
|
20
|
+
- Method names on the client (`deposit`, `search`, `feedback`, etc.).
|
|
21
|
+
- The `request_id` propagation contract on responses + errors.
|
|
22
|
+
- The four authentication scope prefixes (`cw_full_`, `cw_dep_`,
|
|
23
|
+
`cw_read_`, `cw_search_`).
|
|
24
|
+
|
|
25
|
+
## What's still in motion
|
|
26
|
+
|
|
27
|
+
These may change between betas without ceremony:
|
|
28
|
+
|
|
29
|
+
- Optional kwargs on existing methods (especially filter args).
|
|
30
|
+
- The shape of advanced response fields (`dim_*`, `validity_state`,
|
|
31
|
+
`insight_id`).
|
|
32
|
+
- Internal client classes (anything prefixed `_`).
|
|
33
|
+
- Test-fixture helpers under `inferior.testing` / `@inferior-ai/sdk/testing`.
|
|
34
|
+
|
|
35
|
+
## Graduation criteria
|
|
36
|
+
|
|
37
|
+
This package graduates to `2.0.0` (drops the `b1` / `-beta.0` suffix)
|
|
38
|
+
when **all** of the following are true for at least 30 consecutive
|
|
39
|
+
days:
|
|
40
|
+
|
|
41
|
+
1. **No breaking change** has been merged. (Additive changes are fine.)
|
|
42
|
+
2. **At least 2 external integrations** have shipped against the current beta and reported success.
|
|
43
|
+
3. **`eval-l1`** (deterministic regression suite, see backend
|
|
44
|
+
`evaluation-plan.md` §2.1) is green on every backend release for 7
|
|
45
|
+
consecutive days.
|
|
46
|
+
4. **`eval-l2-nightly`** (paraphrase-set + product-scorecard) has run
|
|
47
|
+
for 7 consecutive nights without a failure cascade or threshold
|
|
48
|
+
breach.
|
|
49
|
+
5. **A security review** by a designated reviewer has signed off on
|
|
50
|
+
the SDK code surface and the API-version pinning behavior.
|
|
51
|
+
|
|
52
|
+
Once graduated, the next breaking change requires a major version bump
|
|
53
|
+
to `3.0.0`. Pre-graduation, we don't owe customers backward-compatible
|
|
54
|
+
betas; we owe them a clear changelog and a pinning convention that
|
|
55
|
+
prevents surprise upgrades.
|
|
56
|
+
|
|
57
|
+
## Pinning recommendation
|
|
58
|
+
|
|
59
|
+
For the duration of the beta:
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
# Python
|
|
63
|
+
npm install @inferior-ai/sdk@beta == 2.0.0-beta.0
|
|
64
|
+
|
|
65
|
+
# TypeScript
|
|
66
|
+
"@inferior-ai/sdk": "2.0.0-beta.0"
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Do *not* use `>=` or `^` ranges during beta. Once stable ships, the
|
|
70
|
+
recommendation flips to `^2.x` (compatible-update range).
|
|
71
|
+
|
|
72
|
+
## Deprecation policy (post-graduation)
|
|
73
|
+
|
|
74
|
+
Once `2.0.0` ships stable:
|
|
75
|
+
|
|
76
|
+
- Deprecations are announced one minor version before removal.
|
|
77
|
+
- Removed methods/fields are kept as warning-only shims for at least
|
|
78
|
+
6 months.
|
|
79
|
+
- Major-version bumps follow the same 6-month window.
|
|
80
|
+
|
|
81
|
+
## What "stable" doesn't mean
|
|
82
|
+
|
|
83
|
+
- We do not promise wire-format compatibility *across* SDK versions —
|
|
84
|
+
if you upgrade your SDK and pass a request through the same backend,
|
|
85
|
+
you may see different default header values, pagination cursors,
|
|
86
|
+
etc.
|
|
87
|
+
- We do not promise behavioral compatibility under errors. Retry
|
|
88
|
+
strategies, jittering, and backoff curves are tunable knobs, not
|
|
89
|
+
contracts.
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
For the full launch and post-launch operating discipline, see the
|
|
94
|
+
internal `evaluation-plan.md` and `launch-plan.md`. Customers see
|
|
95
|
+
this `STABILITY.md` as the authoritative public statement.
|
package/SUPPORT.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Support — inferior-sdk-ts
|
|
2
|
+
|
|
3
|
+
This package is closed source; the source repository is not public.
|
|
4
|
+
Customer support flows through email and the Inferior status page,
|
|
5
|
+
not GitHub issues.
|
|
6
|
+
|
|
7
|
+
## Where to go
|
|
8
|
+
|
|
9
|
+
| You want to … | Send to |
|
|
10
|
+
|---|---|
|
|
11
|
+
| Report a bug | `support@inferior.ai` |
|
|
12
|
+
| Ask a usage question | `support@inferior.ai` |
|
|
13
|
+
| Report a security vulnerability | `security@inferior.ai` (see [`SECURITY.md`](./SECURITY.md)) |
|
|
14
|
+
| Ask a licensing / terms question | `legal@inferior.ai` |
|
|
15
|
+
| Request a new feature | `support@inferior.ai` with subject `[FR]` |
|
|
16
|
+
| Check whether something is a known incident | [https://status.inferior.ai](https://status.inferior.ai) |
|
|
17
|
+
|
|
18
|
+
## What to include in a support ticket
|
|
19
|
+
|
|
20
|
+
For the fastest triage, include:
|
|
21
|
+
|
|
22
|
+
1. **Package + version**: e.g., `@inferior-ai/sdk 2.0.0-beta.0`.
|
|
23
|
+
2. **Runtime**: Python 3.x.x or Node x.x.x; OS.
|
|
24
|
+
3. **Reproduction**: smallest snippet that triggers the issue.
|
|
25
|
+
4. **Expected vs actual** behaviour.
|
|
26
|
+
5. **`request_id`** if available — every error from this SDK includes
|
|
27
|
+
one. Quoting it lets us find the exact request in our logs.
|
|
28
|
+
6. **Environment context**: API endpoint (`api.inferior.ai` vs.
|
|
29
|
+
self-hosted), API key prefix (the `cw_*_` prefix only — never the
|
|
30
|
+
full key), any reverse proxies.
|
|
31
|
+
|
|
32
|
+
## Response SLAs
|
|
33
|
+
|
|
34
|
+
| Plan | Acknowledgement | Resolution target |
|
|
35
|
+
|---|---|---|
|
|
36
|
+
| Free / community | best-effort | best-effort |
|
|
37
|
+
| Paid | 24 business hours | per [https://inferior.ai/legal/sla](https://inferior.ai/legal/sla) |
|
|
38
|
+
| Enterprise | 4 business hours | per signed agreement |
|
|
39
|
+
|
|
40
|
+
Pre-launch (during beta), all support tickets are best-effort while we
|
|
41
|
+
calibrate process. Tag tickets with `[beta]` in the subject line so we
|
|
42
|
+
prioritise correctly.
|
|
43
|
+
|
|
44
|
+
## Status page + incidents
|
|
45
|
+
|
|
46
|
+
[https://status.inferior.ai](https://status.inferior.ai) shows the
|
|
47
|
+
state of the production API. SDK issues that are actually backend
|
|
48
|
+
incidents will show up there before our support team responds; check
|
|
49
|
+
it first.
|
|
50
|
+
|
|
51
|
+
## What we cannot help with
|
|
52
|
+
|
|
53
|
+
- Modifications to this package, including private patches, are out of
|
|
54
|
+
scope (this is a closed-source license).
|
|
55
|
+
- Help wiring this package into proprietary internal systems beyond
|
|
56
|
+
the documented integration points.
|
|
57
|
+
- Bugs in the underlying networking stack (`httpx` / `node:http`) that
|
|
58
|
+
reproduce outside the Inferior SDK.
|
|
59
|
+
|
|
60
|
+
## Contributing
|
|
61
|
+
|
|
62
|
+
This repository is private and does not accept external contributions.
|
|
63
|
+
If you have an idea for a feature, send it to `support@inferior.ai`
|
|
64
|
+
with subject `[FR]` and we'll evaluate. Internal contributors should
|
|
65
|
+
see the team wiki for the contribution flow (DCO sign-off, branch
|
|
66
|
+
naming, review requirements).
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example tests using `MockInferiorClient` from `@inferior-ai/sdk/testing`.
|
|
3
|
+
*
|
|
4
|
+
* Doubles as a smoke test for the testing helper itself — if the SDK
|
|
5
|
+
* ever changes shape, these tests fail and signal that the helper
|
|
6
|
+
* needs to be updated.
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=with_mock_client.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with_mock_client.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/with_mock_client.test.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example tests using `MockInferiorClient` from `@inferior-ai/sdk/testing`.
|
|
3
|
+
*
|
|
4
|
+
* Doubles as a smoke test for the testing helper itself — if the SDK
|
|
5
|
+
* ever changes shape, these tests fail and signal that the helper
|
|
6
|
+
* needs to be updated.
|
|
7
|
+
*/
|
|
8
|
+
import { describe, expect, it } from "vitest";
|
|
9
|
+
import { InferiorError, NotFoundError, PoisoningDetectedError, RateLimitError, } from "../index.js";
|
|
10
|
+
import { MockInferiorClient } from "../testing/mock-client.js";
|
|
11
|
+
describe("MockInferiorClient", () => {
|
|
12
|
+
it("returns stubbed search results", async () => {
|
|
13
|
+
const client = new MockInferiorClient();
|
|
14
|
+
client.mockSearch({
|
|
15
|
+
results: [
|
|
16
|
+
{
|
|
17
|
+
id: "exp_abc",
|
|
18
|
+
title: "Stripe webhook on Vercel Edge",
|
|
19
|
+
problem: "Signature verification fails silently",
|
|
20
|
+
root_cause: "Edge runtime canonicalises the body",
|
|
21
|
+
insight: "Switch to nodejs runtime",
|
|
22
|
+
successful_approach: { method: "export const runtime = 'nodejs'" },
|
|
23
|
+
failed_approaches: [],
|
|
24
|
+
applies_when: [],
|
|
25
|
+
does_not_apply_when: [],
|
|
26
|
+
tags: ["stripe", "vercel"],
|
|
27
|
+
context: {},
|
|
28
|
+
outcome: { status: "resolved" },
|
|
29
|
+
contributor: {
|
|
30
|
+
display_handle: "anon_1",
|
|
31
|
+
type: "ai_agent",
|
|
32
|
+
total_experiences: 3,
|
|
33
|
+
total_helpful: 2,
|
|
34
|
+
total_not_helpful: 0,
|
|
35
|
+
reputation_score: 0.7,
|
|
36
|
+
trust_level: "established",
|
|
37
|
+
},
|
|
38
|
+
relevance: { combined_score: 0.91 },
|
|
39
|
+
schema_version: "2.0.0",
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
total: 1,
|
|
43
|
+
});
|
|
44
|
+
const response = await client.search("stripe webhook");
|
|
45
|
+
expect(response.total_results).toBe(1);
|
|
46
|
+
expect(response.results[0].title).toMatch(/^Stripe webhook/);
|
|
47
|
+
expect(client.calls).toHaveLength(1);
|
|
48
|
+
const call = client.calls[0];
|
|
49
|
+
expect(call.method).toBe("GET");
|
|
50
|
+
expect(call.url).toContain("/v1/experiences/search");
|
|
51
|
+
expect(call.headers.get("authorization")).toMatch(/^Bearer /);
|
|
52
|
+
expect(call.headers.get("user-agent")).toMatch(/^inferior-sdk-ts\//);
|
|
53
|
+
expect(call.headers.get("inferior-version")).toBe("2026-04-28");
|
|
54
|
+
});
|
|
55
|
+
it("carries idempotency-key on deposit", async () => {
|
|
56
|
+
const client = new MockInferiorClient();
|
|
57
|
+
client.mockDeposit({ id: "exp_test_42", qualityScore: 0.81 });
|
|
58
|
+
const response = await client.deposit({
|
|
59
|
+
title: "Test deposit",
|
|
60
|
+
problem: "A test problem",
|
|
61
|
+
solution: "A test solution",
|
|
62
|
+
root_cause: "A test cause",
|
|
63
|
+
insight: "A test insight",
|
|
64
|
+
tags: ["test"],
|
|
65
|
+
idempotencyKey: "user-test-evt-1",
|
|
66
|
+
});
|
|
67
|
+
expect(response.id).toBe("exp_test_42");
|
|
68
|
+
expect(response.quality_score).toBe(0.81);
|
|
69
|
+
expect(client.calls[0].headers.get("idempotency-key")).toBe("user-test-evt-1");
|
|
70
|
+
});
|
|
71
|
+
it("raises typed exception with requestId on error", async () => {
|
|
72
|
+
const client = new MockInferiorClient();
|
|
73
|
+
client.mockError("GET", "/v1/experiences/search", {
|
|
74
|
+
status: 404,
|
|
75
|
+
error: "NotFoundError",
|
|
76
|
+
message: "Index not initialised",
|
|
77
|
+
});
|
|
78
|
+
try {
|
|
79
|
+
await client.search("anything");
|
|
80
|
+
throw new Error("expected NotFoundError");
|
|
81
|
+
}
|
|
82
|
+
catch (e) {
|
|
83
|
+
expect(e).toBeInstanceOf(NotFoundError);
|
|
84
|
+
const err = e;
|
|
85
|
+
expect(err.statusCode).toBe(404);
|
|
86
|
+
expect(err.requestId).toBe("req_mock_test");
|
|
87
|
+
expect(String(e)).toContain("request_id=req_mock_test");
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
it("preserves rate-limit metadata on 429", async () => {
|
|
91
|
+
const client = new MockInferiorClient();
|
|
92
|
+
client.mockError("POST", "/v1/experiences", {
|
|
93
|
+
status: 429,
|
|
94
|
+
error: "RateLimitExceededError",
|
|
95
|
+
details: { retry_after_seconds: 30, scope: "deposit" },
|
|
96
|
+
});
|
|
97
|
+
try {
|
|
98
|
+
await client.deposit({
|
|
99
|
+
title: "x", problem: "y", solution: "z",
|
|
100
|
+
root_cause: "r", insight: "i", tags: ["t"],
|
|
101
|
+
});
|
|
102
|
+
throw new Error("expected RateLimitError");
|
|
103
|
+
}
|
|
104
|
+
catch (e) {
|
|
105
|
+
expect(e).toBeInstanceOf(RateLimitError);
|
|
106
|
+
const err = e;
|
|
107
|
+
expect(err.retryAfterSeconds).toBe(30);
|
|
108
|
+
expect(err.scope).toBe("deposit");
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
it("raises PoisoningDetectedError specifically on 422 poisoning", async () => {
|
|
112
|
+
const client = new MockInferiorClient();
|
|
113
|
+
client.mockError("POST", "/v1/experiences", {
|
|
114
|
+
status: 422,
|
|
115
|
+
error: "PoisoningDetectedError",
|
|
116
|
+
details: { rejection_reason: "poisoning_detected", gate: "poisoning" },
|
|
117
|
+
});
|
|
118
|
+
await expect(client.deposit({
|
|
119
|
+
title: "x", problem: "y", solution: "z",
|
|
120
|
+
root_cause: "r", insight: "i", tags: ["t"],
|
|
121
|
+
})).rejects.toBeInstanceOf(PoisoningDetectedError);
|
|
122
|
+
});
|
|
123
|
+
it("returns helpful 404 on unmatched request", async () => {
|
|
124
|
+
const client = new MockInferiorClient();
|
|
125
|
+
try {
|
|
126
|
+
await client.search("anything");
|
|
127
|
+
throw new Error("expected error");
|
|
128
|
+
}
|
|
129
|
+
catch (e) {
|
|
130
|
+
expect(e).toBeInstanceOf(InferiorError);
|
|
131
|
+
const err = e;
|
|
132
|
+
expect(err.statusCode).toBe(404);
|
|
133
|
+
expect(err.message).toContain("No stub matched");
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
it("assertNoUnmatched catches over-stubbing", async () => {
|
|
137
|
+
const client = new MockInferiorClient();
|
|
138
|
+
client.mockSearch({ results: [] });
|
|
139
|
+
client.mockSearch({ results: [] }); // registered twice; only one call below
|
|
140
|
+
await client.search("once");
|
|
141
|
+
expect(() => client.assertNoUnmatched()).toThrow(/1 unfired stubs/);
|
|
142
|
+
});
|
|
143
|
+
it("reset() clears state", async () => {
|
|
144
|
+
const client = new MockInferiorClient();
|
|
145
|
+
client.mockSearch({ results: [] });
|
|
146
|
+
await client.search("foo");
|
|
147
|
+
expect(client.calls.length).toBe(1);
|
|
148
|
+
client.reset();
|
|
149
|
+
expect(client.calls.length).toBe(0);
|
|
150
|
+
// No stubs left — next call should 404.
|
|
151
|
+
await expect(client.search("foo")).rejects.toThrow();
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
//# sourceMappingURL=with_mock_client.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with_mock_client.test.js","sourceRoot":"","sources":["../../src/__tests__/with_mock_client.test.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE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EAAE;QACpC,MAAM,MAAM,GAAG,IAAI,kBAAkB,EAAE,CAAC;QACxC,MAAM,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC;QACnC,MAAM,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC3B,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACpC,MAAM,CAAC,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACpC,wCAAwC;QACxC,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;IACvD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared worthiness scoring math (v1.2+).
|
|
3
|
+
*
|
|
4
|
+
* Pure functions implementing the 5-dimension scoring model from the
|
|
5
|
+
* worthiness framework. Used by ``InferiorClient.depositWorthiness`` to
|
|
6
|
+
* produce a local preview of what the server's worthiness gate will score.
|
|
7
|
+
*
|
|
8
|
+
* Weights are exposed as ``DEFAULT_WEIGHTS`` so a future backend TS
|
|
9
|
+
* implementation can override for env-var-driven tuning. The client uses
|
|
10
|
+
* the defaults as a preview estimate; the authoritative score lives on
|
|
11
|
+
* the server.
|
|
12
|
+
*/
|
|
13
|
+
import type { DepositDraft, Signal } from "./models.js";
|
|
14
|
+
export declare const DEFAULT_WEIGHTS: Record<string, number>;
|
|
15
|
+
type Triple = [number, "definitive" | "estimated" | "unknown", string];
|
|
16
|
+
export declare function scoreNovelty(draft: DepositDraft): Triple;
|
|
17
|
+
export declare function scoreTransferability(draft: DepositDraft): Triple;
|
|
18
|
+
export declare function scoreConsequence(signalsFired: Signal[] | undefined): Triple;
|
|
19
|
+
export declare function scoreEvidence(draft: DepositDraft): Triple;
|
|
20
|
+
export declare function scoreRecurrence(draft: DepositDraft): Triple;
|
|
21
|
+
export declare function applySignalBoosts(baseScore: number, signalsFired: Signal[] | undefined, draft: DepositDraft): [number, string[]];
|
|
22
|
+
export declare function composeWorthiness(dimensionScores: Record<string, number>, weights?: Record<string, number>): number;
|
|
23
|
+
export interface WorthinessPreview {
|
|
24
|
+
dimensionScores: Record<string, number>;
|
|
25
|
+
dimensionConfidence: Record<string, "definitive" | "estimated" | "unknown">;
|
|
26
|
+
dimensionReasons: Record<string, string>;
|
|
27
|
+
baseScore: number;
|
|
28
|
+
estimatedServerScore: number;
|
|
29
|
+
boostReasons: string[];
|
|
30
|
+
wouldLikelyAccept: boolean;
|
|
31
|
+
}
|
|
32
|
+
export declare function previewWorthiness(draft: DepositDraft, signalsFired?: Signal[], weights?: Record<string, number>): WorthinessPreview;
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=_worthiness.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_worthiness.d.ts","sourceRoot":"","sources":["../src/_worthiness.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAExD,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAMlD,CAAC;AAmBF,KAAK,MAAM,GAAG,CAAC,MAAM,EAAE,YAAY,GAAG,WAAW,GAAG,SAAS,EAAE,MAAM,CAAC,CAAC;AAEvE,wBAAgB,YAAY,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAoBxD;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CA0BhE;AAED,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,SAAS,GAAG,MAAM,CAmB3E;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAiBzD;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAe3D;AAED,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,EAAE,GAAG,SAAS,EAClC,KAAK,EAAE,YAAY,GAClB,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAwBpB;AAED,wBAAgB,iBAAiB,CAC/B,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACvC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,MAAM,CAOR;AAED,MAAM,WAAW,iBAAiB;IAChC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,WAAW,GAAG,SAAS,CAAC,CAAC;IAC5E,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,iBAAiB,EAAE,OAAO,CAAC;CAC5B;AAED,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,YAAY,EACnB,YAAY,CAAC,EAAE,MAAM,EAAE,EACvB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,iBAAiB,CA+CnB"}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared worthiness scoring math (v1.2+).
|
|
3
|
+
*
|
|
4
|
+
* Pure functions implementing the 5-dimension scoring model from the
|
|
5
|
+
* worthiness framework. Used by ``InferiorClient.depositWorthiness`` to
|
|
6
|
+
* produce a local preview of what the server's worthiness gate will score.
|
|
7
|
+
*
|
|
8
|
+
* Weights are exposed as ``DEFAULT_WEIGHTS`` so a future backend TS
|
|
9
|
+
* implementation can override for env-var-driven tuning. The client uses
|
|
10
|
+
* the defaults as a preview estimate; the authoritative score lives on
|
|
11
|
+
* the server.
|
|
12
|
+
*/
|
|
13
|
+
export const DEFAULT_WEIGHTS = {
|
|
14
|
+
novelty: 0.30,
|
|
15
|
+
transferability: 0.25,
|
|
16
|
+
consequence: 0.20,
|
|
17
|
+
evidence: 0.15,
|
|
18
|
+
recurrence: 0.10,
|
|
19
|
+
};
|
|
20
|
+
const EVIDENCE_RANK = {
|
|
21
|
+
production_validated: 1.0,
|
|
22
|
+
integration_tested: 0.8,
|
|
23
|
+
local_tested: 0.6,
|
|
24
|
+
self_reported: 0.4,
|
|
25
|
+
speculative: 0.2,
|
|
26
|
+
};
|
|
27
|
+
const SIGNAL_SEVERITY = {
|
|
28
|
+
error_recovery: 0.9,
|
|
29
|
+
output_rejection_recovery: 0.9,
|
|
30
|
+
high_retry: 0.8,
|
|
31
|
+
plan_deviation: 0.7,
|
|
32
|
+
human_correction: 0.6,
|
|
33
|
+
search_miss: 0.5,
|
|
34
|
+
};
|
|
35
|
+
export function scoreNovelty(draft) {
|
|
36
|
+
const report = draft.noveltySelfReport ?? "unknown";
|
|
37
|
+
if (report === "searched_and_none_found") {
|
|
38
|
+
return [0.8, "estimated", "Client novelty estimate: searched and found nothing."];
|
|
39
|
+
}
|
|
40
|
+
if (report === "searched_and_similar_found") {
|
|
41
|
+
return [
|
|
42
|
+
0.2,
|
|
43
|
+
"estimated",
|
|
44
|
+
"Client novelty estimate: searched and found similar — reconsider whether a new deposit is worthwhile.",
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
if (report === "did_not_search") {
|
|
48
|
+
return [
|
|
49
|
+
0.5,
|
|
50
|
+
"estimated",
|
|
51
|
+
"You have not searched Inferior — do that before depositing so the server can verify novelty.",
|
|
52
|
+
];
|
|
53
|
+
}
|
|
54
|
+
return [0.5, "unknown", "Novelty unknown without a search — server will verify."];
|
|
55
|
+
}
|
|
56
|
+
export function scoreTransferability(draft) {
|
|
57
|
+
const aw = draft.applies_when ?? [];
|
|
58
|
+
const dw = draft.does_not_apply_when ?? [];
|
|
59
|
+
const total = aw.length + dw.length;
|
|
60
|
+
if (total === 0) {
|
|
61
|
+
return [
|
|
62
|
+
0.1,
|
|
63
|
+
"definitive",
|
|
64
|
+
"No applies_when or does_not_apply_when — this deposit looks context-free, which the server will heavily penalise.",
|
|
65
|
+
];
|
|
66
|
+
}
|
|
67
|
+
if (dw.length === 0) {
|
|
68
|
+
return [
|
|
69
|
+
0.3,
|
|
70
|
+
"definitive",
|
|
71
|
+
"does_not_apply_when is empty — without a stated boundary the experience doesn't transfer well.",
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
const allLens = [...aw, ...dw].map((s) => s.length);
|
|
75
|
+
const avgLen = allLens.reduce((a, b) => a + b, 0) / Math.max(1, total);
|
|
76
|
+
const score = Math.min(1.0, total * 0.2 + (avgLen / 100.0) * 0.4);
|
|
77
|
+
return [
|
|
78
|
+
score,
|
|
79
|
+
"definitive",
|
|
80
|
+
`Transferability looks reasonable (applies_when=${aw.length}, does_not_apply_when=${dw.length}, avg length=${avgLen.toFixed(0)}).`,
|
|
81
|
+
];
|
|
82
|
+
}
|
|
83
|
+
export function scoreConsequence(signalsFired) {
|
|
84
|
+
if (!signalsFired || signalsFired.length === 0) {
|
|
85
|
+
return [
|
|
86
|
+
0.5,
|
|
87
|
+
"unknown",
|
|
88
|
+
"No signals provided — server may infer consequence from session metadata.",
|
|
89
|
+
];
|
|
90
|
+
}
|
|
91
|
+
const maxSeverity = Math.max(...signalsFired.map((s) => SIGNAL_SEVERITY[s.type] ?? 0.4));
|
|
92
|
+
const countBonus = Math.min(0.15, 0.05 * signalsFired.length);
|
|
93
|
+
const score = Math.min(1.0, maxSeverity + countBonus - 0.1);
|
|
94
|
+
const types = signalsFired.map((s) => s.type).join(", ");
|
|
95
|
+
return [
|
|
96
|
+
score,
|
|
97
|
+
"estimated",
|
|
98
|
+
`Consequence derived from ${signalsFired.length} signal(s): ${types}.`,
|
|
99
|
+
];
|
|
100
|
+
}
|
|
101
|
+
export function scoreEvidence(draft) {
|
|
102
|
+
const ec = draft.evidence_class;
|
|
103
|
+
if (ec == null) {
|
|
104
|
+
return [0.2, "definitive", "evidence_class is unset — tag honestly."];
|
|
105
|
+
}
|
|
106
|
+
const base = EVIDENCE_RANK[ec] ?? 0.3;
|
|
107
|
+
if (draft.hasBeenVerified === false &&
|
|
108
|
+
["production_validated", "integration_tested", "local_tested"].includes(ec)) {
|
|
109
|
+
return [
|
|
110
|
+
0.3,
|
|
111
|
+
"definitive",
|
|
112
|
+
`evidence_class='${ec}' claims verification but hasBeenVerified=false — server will penalise inflation. Downgrade to 'self_reported' or 'speculative'.`,
|
|
113
|
+
];
|
|
114
|
+
}
|
|
115
|
+
return [base, "definitive", `evidence_class='${ec}' → ${base.toFixed(2)}.`];
|
|
116
|
+
}
|
|
117
|
+
export function scoreRecurrence(draft) {
|
|
118
|
+
const estimate = draft.recurrenceSelfReport;
|
|
119
|
+
if (estimate == null) {
|
|
120
|
+
return [
|
|
121
|
+
0.5,
|
|
122
|
+
"unknown",
|
|
123
|
+
"Recurrence unknown without a corpus lookup — server will compute from agent_search_log.",
|
|
124
|
+
];
|
|
125
|
+
}
|
|
126
|
+
const score = Math.min(1.0, 0.2 + estimate * 0.06);
|
|
127
|
+
return [
|
|
128
|
+
score,
|
|
129
|
+
"estimated",
|
|
130
|
+
`Recurrence estimate: ~${estimate} peers would hit this → ${score.toFixed(2)}.`,
|
|
131
|
+
];
|
|
132
|
+
}
|
|
133
|
+
export function applySignalBoosts(baseScore, signalsFired, draft) {
|
|
134
|
+
const reasons = [];
|
|
135
|
+
let score = baseScore;
|
|
136
|
+
const signals = signalsFired ?? [];
|
|
137
|
+
const signalTypes = new Set(signals.map((s) => s.type));
|
|
138
|
+
if (signalTypes.has("search_miss")) {
|
|
139
|
+
score += 0.15;
|
|
140
|
+
reasons.push("+0.15 (search miss — filling a known gap)");
|
|
141
|
+
}
|
|
142
|
+
if (signalTypes.has("human_correction")) {
|
|
143
|
+
score += 0.10;
|
|
144
|
+
reasons.push("+0.10 (human correction — captured user knowledge)");
|
|
145
|
+
}
|
|
146
|
+
if (signals.length >= 3) {
|
|
147
|
+
score += 0.10;
|
|
148
|
+
reasons.push(`+0.10 (≥3 signals fired: ${signals.length})`);
|
|
149
|
+
}
|
|
150
|
+
if ((draft.failed_approaches ?? []).length >= 2) {
|
|
151
|
+
score += 0.05;
|
|
152
|
+
reasons.push("+0.05 (≥2 failed approaches documented)");
|
|
153
|
+
}
|
|
154
|
+
return [Math.min(1.0, score), reasons];
|
|
155
|
+
}
|
|
156
|
+
export function composeWorthiness(dimensionScores, weights) {
|
|
157
|
+
const w = weights ?? DEFAULT_WEIGHTS;
|
|
158
|
+
const sum = Object.keys(w).reduce((acc, d) => acc + (dimensionScores[d] ?? 0.5) * (w[d] ?? 0), 0);
|
|
159
|
+
return Math.round(sum * 10000) / 10000;
|
|
160
|
+
}
|
|
161
|
+
export function previewWorthiness(draft, signalsFired, weights) {
|
|
162
|
+
const novelty = scoreNovelty(draft);
|
|
163
|
+
const transferability = scoreTransferability(draft);
|
|
164
|
+
const consequence = scoreConsequence(signalsFired);
|
|
165
|
+
const evidence = scoreEvidence(draft);
|
|
166
|
+
const recurrence = scoreRecurrence(draft);
|
|
167
|
+
const dimensionScores = {
|
|
168
|
+
novelty: novelty[0],
|
|
169
|
+
transferability: transferability[0],
|
|
170
|
+
consequence: consequence[0],
|
|
171
|
+
evidence: evidence[0],
|
|
172
|
+
recurrence: recurrence[0],
|
|
173
|
+
};
|
|
174
|
+
const dimensionConfidence = {
|
|
175
|
+
novelty: novelty[1],
|
|
176
|
+
transferability: transferability[1],
|
|
177
|
+
consequence: consequence[1],
|
|
178
|
+
evidence: evidence[1],
|
|
179
|
+
recurrence: recurrence[1],
|
|
180
|
+
};
|
|
181
|
+
const dimensionReasons = {
|
|
182
|
+
novelty: novelty[2],
|
|
183
|
+
transferability: transferability[2],
|
|
184
|
+
consequence: consequence[2],
|
|
185
|
+
evidence: evidence[2],
|
|
186
|
+
recurrence: recurrence[2],
|
|
187
|
+
};
|
|
188
|
+
const base = composeWorthiness(dimensionScores, weights);
|
|
189
|
+
const [boosted, boostReasons] = applySignalBoosts(base, signalsFired, draft);
|
|
190
|
+
const wouldLikelyAccept = boosted >= 0.35 && draft.noveltySelfReport !== "searched_and_similar_found";
|
|
191
|
+
return {
|
|
192
|
+
dimensionScores,
|
|
193
|
+
dimensionConfidence,
|
|
194
|
+
dimensionReasons,
|
|
195
|
+
baseScore: base,
|
|
196
|
+
estimatedServerScore: boosted,
|
|
197
|
+
boostReasons,
|
|
198
|
+
wouldLikelyAccept,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
//# sourceMappingURL=_worthiness.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_worthiness.js","sourceRoot":"","sources":["../src/_worthiness.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,MAAM,CAAC,MAAM,eAAe,GAA2B;IACrD,OAAO,EAAE,IAAI;IACb,eAAe,EAAE,IAAI;IACrB,WAAW,EAAE,IAAI;IACjB,QAAQ,EAAE,IAAI;IACd,UAAU,EAAE,IAAI;CACjB,CAAC;AAEF,MAAM,aAAa,GAA2B;IAC5C,oBAAoB,EAAE,GAAG;IACzB,kBAAkB,EAAE,GAAG;IACvB,YAAY,EAAE,GAAG;IACjB,aAAa,EAAE,GAAG;IAClB,WAAW,EAAE,GAAG;CACjB,CAAC;AAEF,MAAM,eAAe,GAA2B;IAC9C,cAAc,EAAE,GAAG;IACnB,yBAAyB,EAAE,GAAG;IAC9B,UAAU,EAAE,GAAG;IACf,cAAc,EAAE,GAAG;IACnB,gBAAgB,EAAE,GAAG;IACrB,WAAW,EAAE,GAAG;CACjB,CAAC;AAIF,MAAM,UAAU,YAAY,CAAC,KAAm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