decision-xray 0.1.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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Mehul
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # decision-xray
2
+
3
+ Lightweight SDK for capturing decision-making in multi-step pipelines.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install decision-xray
9
+ ```
10
+
11
+ ## Quick Example
12
+
13
+ ```typescript
14
+ import { createExecution, recordStep, createEvaluation, createFilterResult } from 'decision-xray';
15
+
16
+ // Create execution
17
+ const execution = createExecution({ name: 'Product Recommendation' });
18
+
19
+ // Record a step with evaluations
20
+ const step = recordStep({
21
+ executionId: execution.id,
22
+ name: 'Price Filter',
23
+ stepType: 'filter',
24
+ input: { candidates: 100 },
25
+ output: { passed: 25 },
26
+ reasoning: 'Filtered products over $50',
27
+ evaluations: [
28
+ createEvaluation('prod-1', 'Product A', false, {
29
+ filters: [
30
+ createFilterResult('price', false, '$75 exceeds maximum $50', 75, 50)
31
+ ]
32
+ })
33
+ ]
34
+ });
35
+
36
+ // You handle persistence
37
+ await saveExecution(execution);
38
+ await saveStep(step);
39
+ ```
40
+
41
+ ## API
42
+
43
+ ### createExecution
44
+ Creates a new execution with unique ID and timestamp.
45
+
46
+ ### recordStep
47
+ Records a decision step with inputs, outputs, reasoning, and optional evaluations.
48
+
49
+ ### createEvaluation
50
+ Creates an evaluation for a single candidate (passed/failed, why).
51
+
52
+ ### createFilterResult
53
+ Creates a filter result with actual vs expected values.
54
+
55
+ ### completeExecution
56
+ Marks an execution as completed or failed.
57
+
58
+ ## Design
59
+
60
+ - **No I/O**: SDK only creates objects. You handle persistence.
61
+ - **Zero dependencies**: Works anywhere.
62
+ - **Functional API**: Simple functions, no classes.
63
+ - **Domain-agnostic**: Works with any decision pipeline.
64
+
65
+ See full docs in code comments.
@@ -0,0 +1,11 @@
1
+ import { Execution, CreateExecutionInput, CompleteExecutionInput } from './types';
2
+ /**
3
+ * Create a new execution. Returns an execution object with status 'running'.
4
+ * You're responsible for persisting it.
5
+ */
6
+ export declare const createExecution: (input: CreateExecutionInput) => Execution;
7
+ /**
8
+ * Mark an execution as completed or failed.
9
+ * Returns a new execution object with updated status and completedAt timestamp.
10
+ */
11
+ export declare const completeExecution: (execution: Execution, input: CompleteExecutionInput) => Execution;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.completeExecution = exports.createExecution = void 0;
4
+ const generateExecutionId = () => {
5
+ const timestamp = Date.now();
6
+ const random = Math.random().toString(36).substring(2, 9);
7
+ return `exec_${timestamp}_${random}`;
8
+ };
9
+ /**
10
+ * Create a new execution. Returns an execution object with status 'running'.
11
+ * You're responsible for persisting it.
12
+ */
13
+ const createExecution = (input) => {
14
+ return {
15
+ id: generateExecutionId(),
16
+ name: input.name,
17
+ description: input.description,
18
+ status: 'running',
19
+ startedAt: new Date(),
20
+ metadata: input.metadata
21
+ };
22
+ };
23
+ exports.createExecution = createExecution;
24
+ /**
25
+ * Mark an execution as completed or failed.
26
+ * Returns a new execution object with updated status and completedAt timestamp.
27
+ */
28
+ const completeExecution = (execution, input) => {
29
+ return {
30
+ ...execution,
31
+ status: input.status,
32
+ completedAt: new Date(),
33
+ metadata: {
34
+ ...execution.metadata,
35
+ ...input.metadata
36
+ }
37
+ };
38
+ };
39
+ exports.completeExecution = completeExecution;
40
+ //# sourceMappingURL=execution.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution.js","sourceRoot":"","sources":["../src/execution.ts"],"names":[],"mappings":";;;AAOA,MAAM,mBAAmB,GAAG,GAAgB,EAAE;IAC5C,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC7B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC1D,OAAO,QAAQ,SAAS,IAAI,MAAM,EAAE,CAAC;AACvC,CAAC,CAAC;AAEF;;;GAGG;AACI,MAAM,eAAe,GAAG,CAAC,KAA2B,EAAa,EAAE;IACxE,OAAO;QACL,EAAE,EAAE,mBAAmB,EAAE;QACzB,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,MAAM,EAAE,SAAS;QACjB,SAAS,EAAE,IAAI,IAAI,EAAE;QACrB,QAAQ,EAAE,KAAK,CAAC,QAAQ;KACzB,CAAC;AACJ,CAAC,CAAC;AATW,QAAA,eAAe,mBAS1B;AAEF;;;GAGG;AACI,MAAM,iBAAiB,GAAG,CAC/B,SAAoB,EACpB,KAA6B,EAClB,EAAE;IACb,OAAO;QACL,GAAG,SAAS;QACZ,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,WAAW,EAAE,IAAI,IAAI,EAAE;QACvB,QAAQ,EAAE;YACR,GAAG,SAAS,CAAC,QAAQ;YACrB,GAAG,KAAK,CAAC,QAAQ;SAClB;KACF,CAAC;AACJ,CAAC,CAAC;AAbW,QAAA,iBAAiB,qBAa5B"}
@@ -0,0 +1,3 @@
1
+ export type { ExecutionId, StepId, Execution, ExecutionStatus, Step, Evaluation, FilterResult, CreateExecutionInput, RecordStepInput, CompleteExecutionInput } from './types';
2
+ export { createExecution, completeExecution } from './execution';
3
+ export { recordStep, createEvaluation, createFilterResult } from './step';
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createFilterResult = exports.createEvaluation = exports.recordStep = exports.completeExecution = exports.createExecution = void 0;
4
+ var execution_1 = require("./execution");
5
+ Object.defineProperty(exports, "createExecution", { enumerable: true, get: function () { return execution_1.createExecution; } });
6
+ Object.defineProperty(exports, "completeExecution", { enumerable: true, get: function () { return execution_1.completeExecution; } });
7
+ var step_1 = require("./step");
8
+ Object.defineProperty(exports, "recordStep", { enumerable: true, get: function () { return step_1.recordStep; } });
9
+ Object.defineProperty(exports, "createEvaluation", { enumerable: true, get: function () { return step_1.createEvaluation; } });
10
+ Object.defineProperty(exports, "createFilterResult", { enumerable: true, get: function () { return step_1.createFilterResult; } });
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAaA,yCAGqB;AAFnB,4GAAA,eAAe,OAAA;AACf,8GAAA,iBAAiB,OAAA;AAGnB,+BAIgB;AAHd,kGAAA,UAAU,OAAA;AACV,wGAAA,gBAAgB,OAAA;AAChB,0GAAA,kBAAkB,OAAA"}
package/dist/step.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ import { Step, RecordStepInput, Evaluation, FilterResult } from './types';
2
+ /**
3
+ * Record a decision step with inputs, outpts, reasoning, and optional evaluations.
4
+ * Returns a step object that you should persist.
5
+ */
6
+ export declare const recordStep: (input: RecordStepInput) => Step;
7
+ /**
8
+ * Create an evaluation for a candidate item.
9
+ * Use this to track pass/fail decisions with optional filters and scoring.
10
+ */
11
+ export declare const createEvaluation: (itemId: string, itemLabel: string, passed: boolean, options?: {
12
+ score?: number;
13
+ filters?: FilterResult[];
14
+ reason?: string;
15
+ metadata?: Record<string, unknown>;
16
+ }) => Evaluation;
17
+ /**
18
+ * Create a filter result showing why a candidate passed or failed a specific filter.
19
+ * Include actual and expected values for better debugging.
20
+ */
21
+ export declare const createFilterResult: (filterName: string, passed: boolean, detail: string, actualValue?: unknown, expectedValue?: unknown) => FilterResult;
package/dist/step.js ADDED
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createFilterResult = exports.createEvaluation = exports.recordStep = void 0;
4
+ const generateStepId = () => {
5
+ const timestamp = Date.now();
6
+ const random = Math.random().toString(36).substring(2, 9);
7
+ return `step_${timestamp}_${random}`;
8
+ };
9
+ /**
10
+ * Record a decision step with inputs, outpts, reasoning, and optional evaluations.
11
+ * Returns a step object that you should persist.
12
+ */
13
+ const recordStep = (input) => {
14
+ return {
15
+ id: generateStepId(),
16
+ executionId: input.executionId,
17
+ name: input.name,
18
+ stepType: input.stepType,
19
+ timestamp: new Date(),
20
+ durationMs: input.durationMs,
21
+ input: input.input,
22
+ output: input.output,
23
+ reasoning: input.reasoning,
24
+ evaluations: input.evaluations,
25
+ metadata: input.metadata
26
+ };
27
+ };
28
+ exports.recordStep = recordStep;
29
+ /**
30
+ * Create an evaluation for a candidate item.
31
+ * Use this to track pass/fail decisions with optional filters and scoring.
32
+ */
33
+ const createEvaluation = (itemId, itemLabel, passed, options) => {
34
+ return {
35
+ itemId,
36
+ itemLabel,
37
+ passed,
38
+ score: options?.score,
39
+ filters: options?.filters,
40
+ reason: options?.reason,
41
+ metadata: options?.metadata
42
+ };
43
+ };
44
+ exports.createEvaluation = createEvaluation;
45
+ /**
46
+ * Create a filter result showing why a candidate passed or failed a specific filter.
47
+ * Include actual and expected values for better debugging.
48
+ */
49
+ const createFilterResult = (filterName, passed, detail, actualValue, expectedValue) => {
50
+ return {
51
+ filterName,
52
+ passed,
53
+ detail,
54
+ actualValue,
55
+ expectedValue
56
+ };
57
+ };
58
+ exports.createFilterResult = createFilterResult;
59
+ //# sourceMappingURL=step.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"step.js","sourceRoot":"","sources":["../src/step.ts"],"names":[],"mappings":";;;AAEA,MAAM,cAAc,GAAG,GAAW,EAAE;IAClC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC7B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC1D,OAAO,QAAQ,SAAS,IAAI,MAAM,EAAE,CAAC;AACvC,CAAC,CAAC;AAEF;;;GAGG;AACI,MAAM,UAAU,GAAG,CAAC,KAAsB,EAAQ,EAAE;IACzD,OAAO;QACL,EAAE,EAAE,cAAc,EAAE;QACpB,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,SAAS,EAAE,IAAI,IAAI,EAAE;QACrB,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,QAAQ,EAAE,KAAK,CAAC,QAAQ;KACzB,CAAC;AACJ,CAAC,CAAC;AAdW,QAAA,UAAU,cAcrB;AAEF;;;GAGG;AACI,MAAM,gBAAgB,GAAG,CAC9B,MAAc,EACd,SAAiB,EACjB,MAAe,EACf,OAKC,EACW,EAAE;IACd,OAAO;QACL,MAAM;QACN,SAAS;QACT,MAAM;QACN,KAAK,EAAE,OAAO,EAAE,KAAK;QACrB,OAAO,EAAE,OAAO,EAAE,OAAO;QACzB,MAAM,EAAE,OAAO,EAAE,MAAM;QACvB,QAAQ,EAAE,OAAO,EAAE,QAAQ;KAC5B,CAAC;AACJ,CAAC,CAAC;AApBW,QAAA,gBAAgB,oBAoB3B;AAEF;;;GAGG;AACI,MAAM,kBAAkB,GAAG,CAChC,UAAkB,EAClB,MAAe,EACf,MAAc,EACd,WAAqB,EACrB,aAAuB,EACT,EAAE;IAChB,OAAO;QACL,UAAU;QACV,MAAM;QACN,MAAM;QACN,WAAW;QACX,aAAa;KACd,CAAC;AACJ,CAAC,CAAC;AAdW,QAAA,kBAAkB,sBAc7B"}
@@ -0,0 +1,61 @@
1
+ export type ExecutionId = string;
2
+ export type StepId = string;
3
+ export interface Execution {
4
+ id: ExecutionId;
5
+ name: string;
6
+ description?: string;
7
+ status: ExecutionStatus;
8
+ startedAt: Date;
9
+ completedAt?: Date;
10
+ metadata?: Record<string, unknown>;
11
+ }
12
+ export type ExecutionStatus = 'running' | 'completed' | 'failed';
13
+ export interface Step {
14
+ id: StepId;
15
+ executionId: ExecutionId;
16
+ name: string;
17
+ stepType: string;
18
+ timestamp: Date;
19
+ durationMs?: number;
20
+ input: Record<string, unknown>;
21
+ output: Record<string, unknown>;
22
+ reasoning: string;
23
+ metadata?: Record<string, unknown>;
24
+ evaluations?: Evaluation[];
25
+ }
26
+ export interface Evaluation {
27
+ itemId: string;
28
+ itemLabel: string;
29
+ passed: boolean;
30
+ score?: number;
31
+ filters?: FilterResult[];
32
+ reason?: string;
33
+ metadata?: Record<string, unknown>;
34
+ }
35
+ export interface FilterResult {
36
+ filterName: string;
37
+ passed: boolean;
38
+ detail: string;
39
+ actualValue?: unknown;
40
+ expectedValue?: unknown;
41
+ }
42
+ export interface CreateExecutionInput {
43
+ name: string;
44
+ description?: string;
45
+ metadata?: Record<string, unknown>;
46
+ }
47
+ export interface RecordStepInput {
48
+ executionId: ExecutionId;
49
+ name: string;
50
+ stepType: string;
51
+ input: Record<string, unknown>;
52
+ output: Record<string, unknown>;
53
+ reasoning: string;
54
+ durationMs?: number;
55
+ evaluations?: Evaluation[];
56
+ metadata?: Record<string, unknown>;
57
+ }
58
+ export interface CompleteExecutionInput {
59
+ status: 'completed' | 'failed';
60
+ metadata?: Record<string, unknown>;
61
+ }
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "decision-xray",
3
+ "version": "0.1.0",
4
+ "description": "Lightweight SDK for capturing decision-making in multi-step algorithmic systems",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "watch": "tsc --watch",
10
+ "type-check": "tsc --noEmit",
11
+ "prepublishOnly": "npm run build"
12
+ },
13
+ "keywords": [
14
+ "debugging",
15
+ "decision-tracking",
16
+ "pipeline",
17
+ "observability",
18
+ "tracing",
19
+ "xray"
20
+ ],
21
+ "author": "Mehul",
22
+ "license": "MIT",
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/mehulkchaudhari/decision-xray.git",
26
+ "directory": "decision-xray"
27
+ },
28
+ "homepage": "https://github.com/mehulkchaudhari/decision-xray#readme",
29
+ "bugs": {
30
+ "url": "https://github.com/mehulkchaudhari/decision-xray/issues"
31
+ },
32
+ "devDependencies": {
33
+ "typescript": "^5.2.2"
34
+ },
35
+ "files": [
36
+ "dist",
37
+ "README.md",
38
+ "LICENSE"
39
+ ]
40
+ }
41
+