@rubric-protocol/schema 1.0.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/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/package.json +33 -0
- package/src/index.ts +73 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ZodTypeAny } from "zod";
|
|
2
|
+
import type { DarBuildInput, DarMeta } from "@rubric-protocol/attest-decision";
|
|
3
|
+
/** A JSON Schema descriptor (plain JSON; JCS-canonicalizable). */
|
|
4
|
+
export type JsonSchema = Record<string, unknown>;
|
|
5
|
+
export declare const SCHEMA_ADAPTER_VERSION: "1.0.0";
|
|
6
|
+
export interface SchemaDecisionInput {
|
|
7
|
+
agentId: string;
|
|
8
|
+
/** Adapter input, hashed to inputHash. */
|
|
9
|
+
input: unknown;
|
|
10
|
+
/** Adapter output, hashed to outputHash. */
|
|
11
|
+
output: unknown;
|
|
12
|
+
/** The raw JSON Schema descriptor the decision was produced under. */
|
|
13
|
+
schema: JsonSchema;
|
|
14
|
+
meta?: DarMeta;
|
|
15
|
+
}
|
|
16
|
+
/** Package DAR builder inputs from input/output + a raw JSON Schema descriptor. */
|
|
17
|
+
export declare function toDecision(input: SchemaDecisionInput): DarBuildInput;
|
|
18
|
+
/**
|
|
19
|
+
* Convert a Zod schema to a JSON Schema descriptor. Deterministic: identical Zod
|
|
20
|
+
* schemas convert to byte-identical JSON Schema, hence a stable schemaHash.
|
|
21
|
+
*/
|
|
22
|
+
export declare function zodToSchema(zod: ZodTypeAny, name?: string): JsonSchema;
|
|
23
|
+
export interface ZodDecisionInput {
|
|
24
|
+
agentId: string;
|
|
25
|
+
input: unknown;
|
|
26
|
+
output: unknown;
|
|
27
|
+
zod: ZodTypeAny;
|
|
28
|
+
/** Optional definition name for the converted schema. */
|
|
29
|
+
name?: string;
|
|
30
|
+
meta?: DarMeta;
|
|
31
|
+
}
|
|
32
|
+
/** Package DAR builder inputs from input/output + a Zod schema. */
|
|
33
|
+
export declare function toDecisionFromZod(input: ZodDecisionInput): DarBuildInput;
|
|
34
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACtC,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAE/E,kEAAkE;AAClE,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEjD,eAAO,MAAM,sBAAsB,EAAG,OAAgB,CAAC;AAQvD,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,0CAA0C;IAC1C,KAAK,EAAE,OAAO,CAAC;IACf,4CAA4C;IAC5C,MAAM,EAAE,OAAO,CAAC;IAChB,sEAAsE;IACtE,MAAM,EAAE,UAAU,CAAC;IACnB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,mFAAmF;AACnF,wBAAgB,UAAU,CAAC,KAAK,EAAE,mBAAmB,GAAG,aAAa,CAQpE;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAEtE;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;IAChB,GAAG,EAAE,UAAU,CAAC;IAChB,yDAAyD;IACzD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,mEAAmE;AACnE,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,gBAAgB,GAAG,aAAa,CAQxE"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @rubric-protocol/schema — JSON Schema / Zod adapter (tasks/P3.md).
|
|
3
|
+
*
|
|
4
|
+
* Produces hashes-only DAR builder inputs from a decision's `input`/`output`
|
|
5
|
+
* plus either a raw JSON Schema descriptor or a Zod schema (converted via
|
|
6
|
+
* zod-to-json-schema). The conversion is deterministic, so the same Zod schema
|
|
7
|
+
* yields a byte-identical JSON Schema and a stable schemaHash.
|
|
8
|
+
*/
|
|
9
|
+
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
10
|
+
export const SCHEMA_ADAPTER_VERSION = "1.0.0";
|
|
11
|
+
const ADAPTER = { name: "schema", version: SCHEMA_ADAPTER_VERSION };
|
|
12
|
+
/** Merge the adapter identity into caller-supplied meta (caller wins on overlap). */
|
|
13
|
+
function withAdapter(meta) {
|
|
14
|
+
return { adapter: { ...ADAPTER }, ...meta };
|
|
15
|
+
}
|
|
16
|
+
/** Package DAR builder inputs from input/output + a raw JSON Schema descriptor. */
|
|
17
|
+
export function toDecision(input) {
|
|
18
|
+
return {
|
|
19
|
+
agentId: input.agentId,
|
|
20
|
+
input: input.input,
|
|
21
|
+
output: input.output,
|
|
22
|
+
schema: input.schema,
|
|
23
|
+
meta: withAdapter(input.meta),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Convert a Zod schema to a JSON Schema descriptor. Deterministic: identical Zod
|
|
28
|
+
* schemas convert to byte-identical JSON Schema, hence a stable schemaHash.
|
|
29
|
+
*/
|
|
30
|
+
export function zodToSchema(zod, name) {
|
|
31
|
+
return zodToJsonSchema(zod, name);
|
|
32
|
+
}
|
|
33
|
+
/** Package DAR builder inputs from input/output + a Zod schema. */
|
|
34
|
+
export function toDecisionFromZod(input) {
|
|
35
|
+
return toDecision({
|
|
36
|
+
agentId: input.agentId,
|
|
37
|
+
input: input.input,
|
|
38
|
+
output: input.output,
|
|
39
|
+
schema: zodToSchema(input.zod, input.name),
|
|
40
|
+
meta: input.meta,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAOrD,MAAM,CAAC,MAAM,sBAAsB,GAAG,OAAgB,CAAC;AACvD,MAAM,OAAO,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,sBAAsB,EAAW,CAAC;AAE7E,qFAAqF;AACrF,SAAS,WAAW,CAAC,IAAc;IACjC,OAAO,EAAE,OAAO,EAAE,EAAE,GAAG,OAAO,EAAE,EAAE,GAAG,IAAI,EAAE,CAAC;AAC9C,CAAC;AAaD,mFAAmF;AACnF,MAAM,UAAU,UAAU,CAAC,KAA0B;IACnD,OAAO;QACL,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,IAAI,EAAE,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC;KAC9B,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,GAAe,EAAE,IAAa;IACxD,OAAO,eAAe,CAAC,GAAG,EAAE,IAAI,CAAe,CAAC;AAClD,CAAC;AAYD,mEAAmE;AACnE,MAAM,UAAU,iBAAiB,CAAC,KAAuB;IACvD,OAAO,UAAU,CAAC;QAChB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,MAAM,EAAE,WAAW,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC;QAC1C,IAAI,EAAE,KAAK,CAAC,IAAI;KACjB,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rubric-protocol/schema",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Rubric adapter: JSON Schema / Zod (zod-to-json-schema) -> DAR inputs",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/0xsims/rubric-attest.git",
|
|
10
|
+
"directory": "packages/schema"
|
|
11
|
+
},
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"development": "./src/index.ts",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": ["dist", "src"],
|
|
22
|
+
"publishConfig": { "access": "public" },
|
|
23
|
+
"scripts": {
|
|
24
|
+
"prepublishOnly": "npm run build",
|
|
25
|
+
"build": "tsc -p tsconfig.build.json",
|
|
26
|
+
"test": "vitest run"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@rubric-protocol/attest-decision": "^1.0.0",
|
|
30
|
+
"zod": "^3.23.8",
|
|
31
|
+
"zod-to-json-schema": "^3.24.1"
|
|
32
|
+
}
|
|
33
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @rubric-protocol/schema — JSON Schema / Zod adapter (tasks/P3.md).
|
|
3
|
+
*
|
|
4
|
+
* Produces hashes-only DAR builder inputs from a decision's `input`/`output`
|
|
5
|
+
* plus either a raw JSON Schema descriptor or a Zod schema (converted via
|
|
6
|
+
* zod-to-json-schema). The conversion is deterministic, so the same Zod schema
|
|
7
|
+
* yields a byte-identical JSON Schema and a stable schemaHash.
|
|
8
|
+
*/
|
|
9
|
+
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
10
|
+
import type { ZodTypeAny } from "zod";
|
|
11
|
+
import type { DarBuildInput, DarMeta } from "@rubric-protocol/attest-decision";
|
|
12
|
+
|
|
13
|
+
/** A JSON Schema descriptor (plain JSON; JCS-canonicalizable). */
|
|
14
|
+
export type JsonSchema = Record<string, unknown>;
|
|
15
|
+
|
|
16
|
+
export const SCHEMA_ADAPTER_VERSION = "1.0.0" as const;
|
|
17
|
+
const ADAPTER = { name: "schema", version: SCHEMA_ADAPTER_VERSION } as const;
|
|
18
|
+
|
|
19
|
+
/** Merge the adapter identity into caller-supplied meta (caller wins on overlap). */
|
|
20
|
+
function withAdapter(meta?: DarMeta): DarMeta {
|
|
21
|
+
return { adapter: { ...ADAPTER }, ...meta };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface SchemaDecisionInput {
|
|
25
|
+
agentId: string;
|
|
26
|
+
/** Adapter input, hashed to inputHash. */
|
|
27
|
+
input: unknown;
|
|
28
|
+
/** Adapter output, hashed to outputHash. */
|
|
29
|
+
output: unknown;
|
|
30
|
+
/** The raw JSON Schema descriptor the decision was produced under. */
|
|
31
|
+
schema: JsonSchema;
|
|
32
|
+
meta?: DarMeta;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Package DAR builder inputs from input/output + a raw JSON Schema descriptor. */
|
|
36
|
+
export function toDecision(input: SchemaDecisionInput): DarBuildInput {
|
|
37
|
+
return {
|
|
38
|
+
agentId: input.agentId,
|
|
39
|
+
input: input.input,
|
|
40
|
+
output: input.output,
|
|
41
|
+
schema: input.schema,
|
|
42
|
+
meta: withAdapter(input.meta),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Convert a Zod schema to a JSON Schema descriptor. Deterministic: identical Zod
|
|
48
|
+
* schemas convert to byte-identical JSON Schema, hence a stable schemaHash.
|
|
49
|
+
*/
|
|
50
|
+
export function zodToSchema(zod: ZodTypeAny, name?: string): JsonSchema {
|
|
51
|
+
return zodToJsonSchema(zod, name) as JsonSchema;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface ZodDecisionInput {
|
|
55
|
+
agentId: string;
|
|
56
|
+
input: unknown;
|
|
57
|
+
output: unknown;
|
|
58
|
+
zod: ZodTypeAny;
|
|
59
|
+
/** Optional definition name for the converted schema. */
|
|
60
|
+
name?: string;
|
|
61
|
+
meta?: DarMeta;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Package DAR builder inputs from input/output + a Zod schema. */
|
|
65
|
+
export function toDecisionFromZod(input: ZodDecisionInput): DarBuildInput {
|
|
66
|
+
return toDecision({
|
|
67
|
+
agentId: input.agentId,
|
|
68
|
+
input: input.input,
|
|
69
|
+
output: input.output,
|
|
70
|
+
schema: zodToSchema(input.zod, input.name),
|
|
71
|
+
meta: input.meta,
|
|
72
|
+
});
|
|
73
|
+
}
|