@refkit/core 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 +201 -0
- package/README.md +12 -0
- package/dist/index.d.ts +199 -0
- package/dist/index.js +351 -0
- package/dist/index.js.map +1 -0
- package/package.json +28 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
95
|
+
Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work, excluding
|
|
103
|
+
those notices that do not pertain to any part of the Derivative
|
|
104
|
+
Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 refkit authors
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# @refkit/core
|
|
2
|
+
|
|
3
|
+
Neutral reference-retrieval core. **Zero network, zero providers, only depends on `zod`.**
|
|
4
|
+
|
|
5
|
+
Invariants (enforced by `src/__tests__/no-network.test.ts`):
|
|
6
|
+
- No `fetch` call and no hard-coded endpoint in this package. Hosts inject `ProviderContext.fetch`.
|
|
7
|
+
- No import of any host/orchestration framework. This package is substrate-agnostic.
|
|
8
|
+
- Only `zod` as a non-relative dependency.
|
|
9
|
+
|
|
10
|
+
This is a heuristic tool, **not legal advice**. `evaluateUse` returns a conservative
|
|
11
|
+
verdict based on source-declared license/ToS facts; it does not determine legal rights.
|
|
12
|
+
Never re-host originals: keep `canonicalUrl` + thumbnails only.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
type Modality = 'image' | 'video' | 'audio' | 'text';
|
|
4
|
+
|
|
5
|
+
type LicenseId = 'CC0-1.0' | 'CC-BY' | 'CC-BY-SA' | 'PD' | 'unsplash' | 'pexels' | 'pixabay' | 'proprietary' | 'unknown';
|
|
6
|
+
/** Three-state: known-true / known-false / not-determinable. Drives strict-deny. */
|
|
7
|
+
type Tri = true | false | 'unknown';
|
|
8
|
+
interface LicenseFacts {
|
|
9
|
+
commercialUse: Tri;
|
|
10
|
+
derivatives: Tri;
|
|
11
|
+
redistribution: Tri;
|
|
12
|
+
attributionRequired: boolean;
|
|
13
|
+
shareAlike: boolean;
|
|
14
|
+
}
|
|
15
|
+
declare const LICENSE_FACTS: Record<LicenseId, LicenseFacts>;
|
|
16
|
+
/** Resolve facts for a license id; unrecognized → `unknown` (strict-deny fallback). */
|
|
17
|
+
declare function factsFor(license: LicenseId): LicenseFacts;
|
|
18
|
+
|
|
19
|
+
type RehostPolicy = 'hotlink-required' | 'cache-allowed' | 'thumbnail-only' | 'no-store';
|
|
20
|
+
interface RightsRecord {
|
|
21
|
+
license: LicenseId;
|
|
22
|
+
/** Precise CC version ("4.0", "3.0", …) for family ids (CC-BY/CC-BY-SA).
|
|
23
|
+
* Attribution/audit only — never read by evaluateUse. Omitted for non-CC. */
|
|
24
|
+
licenseVersion?: string;
|
|
25
|
+
/** Per-item attribution datum; attribution text is generated, not stored. */
|
|
26
|
+
author?: string;
|
|
27
|
+
rehostPolicy: RehostPolicy;
|
|
28
|
+
/** Source-declared jurisdiction of the PD/copyright status (e.g. 'US'). P0: metadata only. */
|
|
29
|
+
jurisdiction?: string;
|
|
30
|
+
editorialOnly?: boolean;
|
|
31
|
+
/** Auditable anchor back to the source's stated terms. */
|
|
32
|
+
raw: {
|
|
33
|
+
sourceTerms: string;
|
|
34
|
+
sourceUrl: string;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
declare const rightsRecordSchema: z.ZodType<RightsRecord>;
|
|
38
|
+
|
|
39
|
+
interface Attribution {
|
|
40
|
+
required: boolean;
|
|
41
|
+
text?: string;
|
|
42
|
+
html?: string;
|
|
43
|
+
}
|
|
44
|
+
interface AttributionInput {
|
|
45
|
+
license: LicenseId;
|
|
46
|
+
/** Precise CC version for family ids; appended to the license name in the credit line. */
|
|
47
|
+
licenseVersion?: string;
|
|
48
|
+
canonicalUrl: string;
|
|
49
|
+
author?: string;
|
|
50
|
+
title?: string;
|
|
51
|
+
}
|
|
52
|
+
declare function buildAttribution(input: AttributionInput): Attribution;
|
|
53
|
+
|
|
54
|
+
interface ReferenceMedia {
|
|
55
|
+
url: string;
|
|
56
|
+
width?: number;
|
|
57
|
+
height?: number;
|
|
58
|
+
}
|
|
59
|
+
interface MediaPreview {
|
|
60
|
+
url: string;
|
|
61
|
+
mediaType: string;
|
|
62
|
+
width?: number;
|
|
63
|
+
height?: number;
|
|
64
|
+
}
|
|
65
|
+
interface VisualMeta {
|
|
66
|
+
width: number;
|
|
67
|
+
height: number;
|
|
68
|
+
dominantColors?: string[];
|
|
69
|
+
}
|
|
70
|
+
interface TextMeta {
|
|
71
|
+
excerpt: string;
|
|
72
|
+
excerptKind: 'passage' | 'structure' | 'quote';
|
|
73
|
+
locator?: string;
|
|
74
|
+
}
|
|
75
|
+
interface Reference {
|
|
76
|
+
id: string;
|
|
77
|
+
modality: Modality;
|
|
78
|
+
title?: string;
|
|
79
|
+
source: {
|
|
80
|
+
providerId: string;
|
|
81
|
+
sourceUrl: string;
|
|
82
|
+
};
|
|
83
|
+
canonicalUrl: string;
|
|
84
|
+
rights: RightsRecord;
|
|
85
|
+
verifiedAt: string;
|
|
86
|
+
thumbnail?: ReferenceMedia;
|
|
87
|
+
preview?: MediaPreview;
|
|
88
|
+
perceptualHash?: string;
|
|
89
|
+
visual?: VisualMeta;
|
|
90
|
+
text?: TextMeta;
|
|
91
|
+
relevance: number;
|
|
92
|
+
raw?: unknown;
|
|
93
|
+
}
|
|
94
|
+
declare const referenceSchema: z.ZodType<Reference>;
|
|
95
|
+
/** Validate a provider-emitted reference at the core boundary. Throws on malformed input. */
|
|
96
|
+
declare function parseReference(input: unknown): Reference;
|
|
97
|
+
|
|
98
|
+
declare function fnv1a(str: string): string;
|
|
99
|
+
|
|
100
|
+
declare function canonicalizeUrl(url: string): string;
|
|
101
|
+
/** Content-addressed id: stable within a result set, not promised across calls. */
|
|
102
|
+
declare function referenceId(providerId: string, sourceUrl: string): string;
|
|
103
|
+
|
|
104
|
+
/** Bitwise hamming distance between two equal-length lowercase hex strings. */
|
|
105
|
+
declare function hammingDistance(a: string, b: string): number;
|
|
106
|
+
interface DedupeOptions {
|
|
107
|
+
/** Max hamming distance between perceptual hashes to treat as duplicates. Default 0 (off). */
|
|
108
|
+
hashThreshold?: number;
|
|
109
|
+
}
|
|
110
|
+
declare function dedupeReferences(refs: Reference[], opts?: DedupeOptions): Reference[];
|
|
111
|
+
|
|
112
|
+
interface MergeOptions extends DedupeOptions {
|
|
113
|
+
/** RRF dampening constant. Standard default 60. */
|
|
114
|
+
k?: number;
|
|
115
|
+
}
|
|
116
|
+
declare function mergeReferences(perSource: Reference[][], opts?: MergeOptions): Reference[];
|
|
117
|
+
|
|
118
|
+
type Intent = 'internal-moodboard' | 'commercial-product' | 'ai-generation-input' | 'redistribution';
|
|
119
|
+
type Decision = 'allowed' | 'allowed-with-attribution' | 'denied' | 'needs-review';
|
|
120
|
+
interface Verdict {
|
|
121
|
+
decision: Decision;
|
|
122
|
+
reasons: string[];
|
|
123
|
+
confidence: 'high' | 'low';
|
|
124
|
+
disclaimer: string;
|
|
125
|
+
}
|
|
126
|
+
declare const NOT_LEGAL_ADVICE = "Heuristic based on source-declared license/ToS facts; not legal advice.";
|
|
127
|
+
declare function evaluateUse(r: RightsRecord, intent: Intent, ctx?: {
|
|
128
|
+
userJurisdiction?: string;
|
|
129
|
+
}): Verdict;
|
|
130
|
+
|
|
131
|
+
type QueryFeature = 'keyword' | 'color' | 'orientation' | 'license-filter' | 'author' | 'language';
|
|
132
|
+
interface SearchFilters {
|
|
133
|
+
color?: string;
|
|
134
|
+
orientation?: 'landscape' | 'portrait' | 'square';
|
|
135
|
+
language?: string;
|
|
136
|
+
}
|
|
137
|
+
interface NormalizedQuery {
|
|
138
|
+
text: string;
|
|
139
|
+
modalities: Modality[];
|
|
140
|
+
filters?: SearchFilters;
|
|
141
|
+
limit?: number;
|
|
142
|
+
}
|
|
143
|
+
interface KeyValueCache {
|
|
144
|
+
get(key: string): Promise<string | undefined>;
|
|
145
|
+
set(key: string, value: string, ttlMs?: number): Promise<void>;
|
|
146
|
+
}
|
|
147
|
+
interface ProviderContext {
|
|
148
|
+
fetch: typeof fetch;
|
|
149
|
+
cache?: KeyValueCache;
|
|
150
|
+
signal?: AbortSignal;
|
|
151
|
+
}
|
|
152
|
+
interface ReferenceProvider {
|
|
153
|
+
id: string;
|
|
154
|
+
modalities: Modality[];
|
|
155
|
+
queryFeatures: QueryFeature[];
|
|
156
|
+
search(query: NormalizedQuery, ctx: ProviderContext): Promise<Reference[]>;
|
|
157
|
+
}
|
|
158
|
+
/** Identity helper for type inference when authoring a provider factory. */
|
|
159
|
+
declare function defineProvider(p: ReferenceProvider): ReferenceProvider;
|
|
160
|
+
|
|
161
|
+
declare function normalizeQuery(input: {
|
|
162
|
+
query: string;
|
|
163
|
+
modalities: Modality[];
|
|
164
|
+
filters?: SearchFilters;
|
|
165
|
+
limit?: number;
|
|
166
|
+
}, provider: ReferenceProvider): NormalizedQuery;
|
|
167
|
+
|
|
168
|
+
interface RefkitOptions {
|
|
169
|
+
providers: ReferenceProvider[];
|
|
170
|
+
fetch?: typeof fetch;
|
|
171
|
+
cache?: KeyValueCache;
|
|
172
|
+
signal?: AbortSignal;
|
|
173
|
+
merge?: MergeOptions;
|
|
174
|
+
}
|
|
175
|
+
interface ProviderError {
|
|
176
|
+
providerId: string;
|
|
177
|
+
error: unknown;
|
|
178
|
+
}
|
|
179
|
+
interface SearchInput {
|
|
180
|
+
query: string;
|
|
181
|
+
modalities: Modality[];
|
|
182
|
+
filters?: SearchFilters;
|
|
183
|
+
limit?: number;
|
|
184
|
+
signal?: AbortSignal;
|
|
185
|
+
gateFor?: Intent;
|
|
186
|
+
onProviderError?: (e: ProviderError) => void;
|
|
187
|
+
rerank?: (refs: Reference[]) => Reference[] | Promise<Reference[]>;
|
|
188
|
+
}
|
|
189
|
+
interface RefkitClient {
|
|
190
|
+
search(input: SearchInput): Promise<Reference[]>;
|
|
191
|
+
evaluateUse(ref: Reference, intent: Intent, ctx?: {
|
|
192
|
+
userJurisdiction?: string;
|
|
193
|
+
}): Verdict;
|
|
194
|
+
buildAttribution(ref: Reference): Attribution;
|
|
195
|
+
readonly providers: readonly ReferenceProvider[];
|
|
196
|
+
}
|
|
197
|
+
declare function createRefkit(options: RefkitOptions): RefkitClient;
|
|
198
|
+
|
|
199
|
+
export { type Attribution, type AttributionInput, type Decision, type DedupeOptions, type Intent, type KeyValueCache, LICENSE_FACTS, type LicenseFacts, type LicenseId, type MediaPreview, type MergeOptions, type Modality, NOT_LEGAL_ADVICE, type NormalizedQuery, type ProviderContext, type ProviderError, type QueryFeature, type Reference, type ReferenceMedia, type ReferenceProvider, type RefkitClient, type RefkitOptions, type RehostPolicy, type RightsRecord, type SearchFilters, type SearchInput, type TextMeta, type Tri, type Verdict, type VisualMeta, buildAttribution, canonicalizeUrl, createRefkit, dedupeReferences, defineProvider, evaluateUse, factsFor, fnv1a, hammingDistance, mergeReferences, normalizeQuery, parseReference, referenceId, referenceSchema, rightsRecordSchema };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
// src/license.ts
|
|
2
|
+
var LICENSE_FACTS = {
|
|
3
|
+
"CC0-1.0": { commercialUse: true, derivatives: true, redistribution: true, attributionRequired: false, shareAlike: false },
|
|
4
|
+
"PD": { commercialUse: true, derivatives: true, redistribution: true, attributionRequired: false, shareAlike: false },
|
|
5
|
+
"CC-BY": { commercialUse: true, derivatives: true, redistribution: true, attributionRequired: true, shareAlike: false },
|
|
6
|
+
"CC-BY-SA": { commercialUse: true, derivatives: true, redistribution: true, attributionRequired: true, shareAlike: true },
|
|
7
|
+
// Stock-platform licenses: free to use incl. commercial, no attribution legally
|
|
8
|
+
// required, but NOT redistributable as-is (can't resell/redistribute the asset itself).
|
|
9
|
+
"unsplash": { commercialUse: true, derivatives: true, redistribution: false, attributionRequired: false, shareAlike: false },
|
|
10
|
+
"pexels": { commercialUse: true, derivatives: true, redistribution: false, attributionRequired: false, shareAlike: false },
|
|
11
|
+
"pixabay": { commercialUse: true, derivatives: true, redistribution: false, attributionRequired: false, shareAlike: false },
|
|
12
|
+
"proprietary": { commercialUse: false, derivatives: false, redistribution: false, attributionRequired: false, shareAlike: false },
|
|
13
|
+
"unknown": { commercialUse: "unknown", derivatives: "unknown", redistribution: "unknown", attributionRequired: false, shareAlike: false }
|
|
14
|
+
};
|
|
15
|
+
function factsFor(license) {
|
|
16
|
+
return LICENSE_FACTS[license] ?? LICENSE_FACTS.unknown;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// src/rights.ts
|
|
20
|
+
import { z } from "zod";
|
|
21
|
+
var licenseIdSchema = z.enum([
|
|
22
|
+
"CC0-1.0",
|
|
23
|
+
"CC-BY",
|
|
24
|
+
"CC-BY-SA",
|
|
25
|
+
"PD",
|
|
26
|
+
"unsplash",
|
|
27
|
+
"pexels",
|
|
28
|
+
"pixabay",
|
|
29
|
+
"proprietary",
|
|
30
|
+
"unknown"
|
|
31
|
+
]);
|
|
32
|
+
var rightsRecordSchema = z.object({
|
|
33
|
+
license: licenseIdSchema,
|
|
34
|
+
licenseVersion: z.string().optional(),
|
|
35
|
+
author: z.string().optional(),
|
|
36
|
+
rehostPolicy: z.enum(["hotlink-required", "cache-allowed", "thumbnail-only", "no-store"]),
|
|
37
|
+
jurisdiction: z.string().optional(),
|
|
38
|
+
editorialOnly: z.boolean().optional(),
|
|
39
|
+
raw: z.object({ sourceTerms: z.string(), sourceUrl: z.string() })
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// src/attribution.ts
|
|
43
|
+
function escapeHtml(s) {
|
|
44
|
+
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
45
|
+
}
|
|
46
|
+
function buildAttribution(input) {
|
|
47
|
+
const facts = factsFor(input.license);
|
|
48
|
+
if (!facts.attributionRequired) return { required: false };
|
|
49
|
+
const author = input.author ?? "Unknown author";
|
|
50
|
+
const licenseLabel = input.licenseVersion ? `${input.license} ${input.licenseVersion}` : input.license;
|
|
51
|
+
const titlePart = input.title ? `"${input.title}" ` : "";
|
|
52
|
+
const text = `${titlePart}by ${author} is licensed under ${licenseLabel}. Source: ${input.canonicalUrl}`;
|
|
53
|
+
const url = escapeHtml(input.canonicalUrl);
|
|
54
|
+
const titleHtml = input.title ? `"${escapeHtml(input.title)}" ` : "";
|
|
55
|
+
const html = `${titleHtml}by ${escapeHtml(author)} is licensed under ${escapeHtml(licenseLabel)}. <a href="${url}">Source</a>`;
|
|
56
|
+
return { required: true, text, html };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// src/reference.ts
|
|
60
|
+
import { z as z2 } from "zod";
|
|
61
|
+
var modalitySchema = z2.enum(["image", "video", "audio", "text"]);
|
|
62
|
+
var referenceSchema = z2.object({
|
|
63
|
+
id: z2.string().min(1),
|
|
64
|
+
modality: modalitySchema,
|
|
65
|
+
title: z2.string().optional(),
|
|
66
|
+
source: z2.object({ providerId: z2.string().min(1), sourceUrl: z2.string().min(1) }),
|
|
67
|
+
canonicalUrl: z2.string().min(1),
|
|
68
|
+
rights: rightsRecordSchema,
|
|
69
|
+
verifiedAt: z2.string().datetime(),
|
|
70
|
+
thumbnail: z2.object({ url: z2.string(), width: z2.number().optional(), height: z2.number().optional() }).optional(),
|
|
71
|
+
preview: z2.object({ url: z2.string(), mediaType: z2.string(), width: z2.number().optional(), height: z2.number().optional() }).optional(),
|
|
72
|
+
perceptualHash: z2.string().optional(),
|
|
73
|
+
visual: z2.object({ width: z2.number(), height: z2.number(), dominantColors: z2.array(z2.string()).optional() }).optional(),
|
|
74
|
+
text: z2.object({
|
|
75
|
+
excerpt: z2.string(),
|
|
76
|
+
excerptKind: z2.enum(["passage", "structure", "quote"]),
|
|
77
|
+
locator: z2.string().optional()
|
|
78
|
+
}).optional(),
|
|
79
|
+
relevance: z2.number().min(0).max(1),
|
|
80
|
+
raw: z2.unknown().optional()
|
|
81
|
+
});
|
|
82
|
+
function parseReference(input) {
|
|
83
|
+
return referenceSchema.parse(input);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// src/hash.ts
|
|
87
|
+
function fnv1a(str) {
|
|
88
|
+
let h = 2166136261;
|
|
89
|
+
for (let i = 0; i < str.length; i++) {
|
|
90
|
+
h ^= str.charCodeAt(i);
|
|
91
|
+
h = Math.imul(h, 16777619);
|
|
92
|
+
}
|
|
93
|
+
return (h >>> 0).toString(36);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// src/dedup-key.ts
|
|
97
|
+
function canonicalizeUrl(url) {
|
|
98
|
+
try {
|
|
99
|
+
const u = new URL(url);
|
|
100
|
+
u.hash = "";
|
|
101
|
+
u.protocol = u.protocol.toLowerCase();
|
|
102
|
+
u.hostname = u.hostname.toLowerCase();
|
|
103
|
+
let out = u.toString();
|
|
104
|
+
if (out.endsWith("/") && !out.endsWith("://")) out = out.slice(0, -1);
|
|
105
|
+
return out;
|
|
106
|
+
} catch {
|
|
107
|
+
return url;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function referenceId(providerId, sourceUrl) {
|
|
111
|
+
return `${providerId}:${fnv1a(canonicalizeUrl(sourceUrl))}`;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// src/dedup.ts
|
|
115
|
+
var HEX_BITS = {
|
|
116
|
+
"0": 0,
|
|
117
|
+
"1": 1,
|
|
118
|
+
"2": 1,
|
|
119
|
+
"3": 2,
|
|
120
|
+
"4": 1,
|
|
121
|
+
"5": 2,
|
|
122
|
+
"6": 2,
|
|
123
|
+
"7": 3,
|
|
124
|
+
"8": 1,
|
|
125
|
+
"9": 2,
|
|
126
|
+
a: 2,
|
|
127
|
+
b: 3,
|
|
128
|
+
c: 2,
|
|
129
|
+
d: 3,
|
|
130
|
+
e: 3,
|
|
131
|
+
f: 4
|
|
132
|
+
};
|
|
133
|
+
function hammingDistance(a, b) {
|
|
134
|
+
if (a.length !== b.length) return Infinity;
|
|
135
|
+
let d = 0;
|
|
136
|
+
for (let i = 0; i < a.length; i++) {
|
|
137
|
+
if (a[i] === b[i]) continue;
|
|
138
|
+
const xor = (parseInt(a[i], 16) ^ parseInt(b[i], 16)).toString(16);
|
|
139
|
+
d += HEX_BITS[xor] ?? 4;
|
|
140
|
+
}
|
|
141
|
+
return d;
|
|
142
|
+
}
|
|
143
|
+
function dedupeReferences(refs, opts = {}) {
|
|
144
|
+
const threshold = opts.hashThreshold ?? 0;
|
|
145
|
+
const kept = [];
|
|
146
|
+
const byUrl = /* @__PURE__ */ new Map();
|
|
147
|
+
for (const ref of refs) {
|
|
148
|
+
const url = canonicalizeUrl(ref.canonicalUrl);
|
|
149
|
+
const urlHit = byUrl.get(url);
|
|
150
|
+
if (urlHit !== void 0) {
|
|
151
|
+
if (ref.relevance > kept[urlHit].relevance) kept[urlHit] = ref;
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
let merged = false;
|
|
155
|
+
if (threshold > 0 && ref.perceptualHash) {
|
|
156
|
+
for (let i = 0; i < kept.length; i++) {
|
|
157
|
+
const k = kept[i];
|
|
158
|
+
if (k.perceptualHash && hammingDistance(ref.perceptualHash, k.perceptualHash) <= threshold) {
|
|
159
|
+
if (ref.relevance > k.relevance) {
|
|
160
|
+
byUrl.delete(canonicalizeUrl(k.canonicalUrl));
|
|
161
|
+
byUrl.set(canonicalizeUrl(ref.canonicalUrl), i);
|
|
162
|
+
kept[i] = ref;
|
|
163
|
+
}
|
|
164
|
+
merged = true;
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (merged) continue;
|
|
170
|
+
byUrl.set(url, kept.length);
|
|
171
|
+
kept.push(ref);
|
|
172
|
+
}
|
|
173
|
+
return kept;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// src/merge.ts
|
|
177
|
+
function mergeReferences(perSource, opts = {}) {
|
|
178
|
+
const k = opts.k ?? 60;
|
|
179
|
+
const score = /* @__PURE__ */ new Map();
|
|
180
|
+
const rep = /* @__PURE__ */ new Map();
|
|
181
|
+
for (const list of perSource) {
|
|
182
|
+
list.forEach((ref, rank) => {
|
|
183
|
+
const key = canonicalizeUrl(ref.canonicalUrl);
|
|
184
|
+
score.set(key, (score.get(key) ?? 0) + 1 / (k + rank));
|
|
185
|
+
const cur = rep.get(key);
|
|
186
|
+
if (!cur || ref.relevance > cur.relevance) rep.set(key, ref);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
const maxScore = Math.max(...score.values());
|
|
190
|
+
const fused = [...score.entries()].map(([key, s]) => ({ ...rep.get(key), relevance: s / maxScore })).sort((a, b) => b.relevance - a.relevance);
|
|
191
|
+
return dedupeReferences(fused, opts);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// src/evaluate-use.ts
|
|
195
|
+
var NOT_LEGAL_ADVICE = "Heuristic based on source-declared license/ToS facts; not legal advice.";
|
|
196
|
+
function requiredPermissions(intent) {
|
|
197
|
+
switch (intent) {
|
|
198
|
+
case "commercial-product":
|
|
199
|
+
return ["commercialUse"];
|
|
200
|
+
case "ai-generation-input":
|
|
201
|
+
return ["commercialUse", "derivatives"];
|
|
202
|
+
case "redistribution":
|
|
203
|
+
return ["redistribution"];
|
|
204
|
+
case "internal-moodboard":
|
|
205
|
+
return [];
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
function evaluateUse(r, intent, ctx) {
|
|
209
|
+
const facts = factsFor(r.license);
|
|
210
|
+
const reasons = [];
|
|
211
|
+
const confidence = r.license === "unknown" ? "low" : "high";
|
|
212
|
+
const base = { reasons, confidence, disclaimer: NOT_LEGAL_ADVICE };
|
|
213
|
+
const commercialIntent = intent === "commercial-product" || intent === "ai-generation-input";
|
|
214
|
+
if (r.license === "unknown") {
|
|
215
|
+
reasons.push("license could not be determined (strict-deny)");
|
|
216
|
+
return { decision: "needs-review", ...base };
|
|
217
|
+
}
|
|
218
|
+
if (r.editorialOnly && commercialIntent) {
|
|
219
|
+
reasons.push("source marked editorial-only");
|
|
220
|
+
return { decision: "denied", ...base };
|
|
221
|
+
}
|
|
222
|
+
if (ctx?.userJurisdiction && r.jurisdiction && ctx.userJurisdiction !== r.jurisdiction) {
|
|
223
|
+
reasons.push(`source jurisdiction ${r.jurisdiction} != user jurisdiction ${ctx.userJurisdiction}`);
|
|
224
|
+
return { decision: "needs-review", ...base };
|
|
225
|
+
}
|
|
226
|
+
for (const perm of requiredPermissions(intent)) {
|
|
227
|
+
const value = facts[perm];
|
|
228
|
+
if (value === false) {
|
|
229
|
+
reasons.push(`${perm} not granted by ${r.license}`);
|
|
230
|
+
return { decision: "denied", ...base };
|
|
231
|
+
}
|
|
232
|
+
if (value === "unknown") {
|
|
233
|
+
reasons.push(`${perm} undetermined for ${r.license}`);
|
|
234
|
+
return { decision: "needs-review", ...base };
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
reasons.push(`permitted for ${intent} under ${r.license}`);
|
|
238
|
+
if (facts.attributionRequired && intent === "internal-moodboard") {
|
|
239
|
+
reasons.push("attribution required by license but not enforced for internal-moodboard use");
|
|
240
|
+
}
|
|
241
|
+
const decision = facts.attributionRequired && intent !== "internal-moodboard" ? "allowed-with-attribution" : "allowed";
|
|
242
|
+
return { decision, ...base };
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// src/provider.ts
|
|
246
|
+
function defineProvider(p) {
|
|
247
|
+
return p;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// src/query.ts
|
|
251
|
+
function normalizeQuery(input, provider) {
|
|
252
|
+
const feats = new Set(provider.queryFeatures);
|
|
253
|
+
const filters = {};
|
|
254
|
+
if (input.filters?.color && feats.has("color")) filters.color = input.filters.color;
|
|
255
|
+
if (input.filters?.orientation && feats.has("orientation")) filters.orientation = input.filters.orientation;
|
|
256
|
+
if (input.filters?.language && feats.has("language")) filters.language = input.filters.language;
|
|
257
|
+
const hasFilters = Object.keys(filters).length > 0;
|
|
258
|
+
return {
|
|
259
|
+
text: input.query,
|
|
260
|
+
modalities: input.modalities.filter((m) => provider.modalities.includes(m)),
|
|
261
|
+
...hasFilters ? { filters } : {},
|
|
262
|
+
...input.limit !== void 0 ? { limit: input.limit } : {}
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// src/client.ts
|
|
267
|
+
var DEFAULT_LIMIT = 30;
|
|
268
|
+
function createRefkit(options) {
|
|
269
|
+
if (!options.providers || options.providers.length === 0) {
|
|
270
|
+
throw new Error("createRefkit: at least one provider is required");
|
|
271
|
+
}
|
|
272
|
+
async function search(input) {
|
|
273
|
+
const doFetch = options.fetch ?? globalThis.fetch;
|
|
274
|
+
if (typeof doFetch !== "function") {
|
|
275
|
+
throw new Error("createRefkit: no fetch available \u2014 pass options.fetch");
|
|
276
|
+
}
|
|
277
|
+
const ctx = {
|
|
278
|
+
fetch: doFetch,
|
|
279
|
+
cache: options.cache,
|
|
280
|
+
signal: input.signal ?? options.signal
|
|
281
|
+
};
|
|
282
|
+
const chosen = options.providers.filter((p) => p.modalities.some((m) => input.modalities.includes(m)));
|
|
283
|
+
if (chosen.length === 0) {
|
|
284
|
+
throw new Error(`refkit.search: no registered provider supports modalities [${input.modalities.join(", ")}]`);
|
|
285
|
+
}
|
|
286
|
+
const settled = await Promise.allSettled(chosen.map((p) => p.search(normalizeQuery(input, p), ctx)));
|
|
287
|
+
const perSource = [];
|
|
288
|
+
let anyOk = false;
|
|
289
|
+
settled.forEach((res, i) => {
|
|
290
|
+
const provider = chosen[i];
|
|
291
|
+
if (res.status === "fulfilled") {
|
|
292
|
+
anyOk = true;
|
|
293
|
+
const valid = [];
|
|
294
|
+
for (const raw of res.value) {
|
|
295
|
+
try {
|
|
296
|
+
valid.push(parseReference(raw));
|
|
297
|
+
} catch (error) {
|
|
298
|
+
input.onProviderError?.({ providerId: provider.id, error });
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
perSource.push(valid);
|
|
302
|
+
} else {
|
|
303
|
+
input.onProviderError?.({ providerId: provider.id, error: res.reason });
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
if (!anyOk) {
|
|
307
|
+
const reasons = settled.filter((s) => s.status === "rejected").map((s) => s.reason);
|
|
308
|
+
throw new AggregateError(reasons, "refkit.search: all providers failed");
|
|
309
|
+
}
|
|
310
|
+
let refs = mergeReferences(perSource, options.merge);
|
|
311
|
+
if (input.rerank) refs = await input.rerank(refs);
|
|
312
|
+
if (input.gateFor) {
|
|
313
|
+
const intent = input.gateFor;
|
|
314
|
+
refs = refs.filter((r) => evaluateUse(r.rights, intent).decision.startsWith("allowed"));
|
|
315
|
+
}
|
|
316
|
+
return refs.slice(0, input.limit ?? DEFAULT_LIMIT);
|
|
317
|
+
}
|
|
318
|
+
return {
|
|
319
|
+
search,
|
|
320
|
+
evaluateUse: (ref, intent, ctx) => evaluateUse(ref.rights, intent, ctx),
|
|
321
|
+
buildAttribution: (ref) => buildAttribution({
|
|
322
|
+
license: ref.rights.license,
|
|
323
|
+
author: ref.rights.author,
|
|
324
|
+
title: ref.title,
|
|
325
|
+
canonicalUrl: ref.canonicalUrl
|
|
326
|
+
}),
|
|
327
|
+
get providers() {
|
|
328
|
+
return options.providers;
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
export {
|
|
333
|
+
LICENSE_FACTS,
|
|
334
|
+
NOT_LEGAL_ADVICE,
|
|
335
|
+
buildAttribution,
|
|
336
|
+
canonicalizeUrl,
|
|
337
|
+
createRefkit,
|
|
338
|
+
dedupeReferences,
|
|
339
|
+
defineProvider,
|
|
340
|
+
evaluateUse,
|
|
341
|
+
factsFor,
|
|
342
|
+
fnv1a,
|
|
343
|
+
hammingDistance,
|
|
344
|
+
mergeReferences,
|
|
345
|
+
normalizeQuery,
|
|
346
|
+
parseReference,
|
|
347
|
+
referenceId,
|
|
348
|
+
referenceSchema,
|
|
349
|
+
rightsRecordSchema
|
|
350
|
+
};
|
|
351
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/license.ts","../src/rights.ts","../src/attribution.ts","../src/reference.ts","../src/hash.ts","../src/dedup-key.ts","../src/dedup.ts","../src/merge.ts","../src/evaluate-use.ts","../src/provider.ts","../src/query.ts","../src/client.ts"],"sourcesContent":["export type LicenseId =\n | 'CC0-1.0'\n | 'CC-BY'\n | 'CC-BY-SA'\n | 'PD'\n | 'unsplash'\n | 'pexels'\n | 'pixabay'\n | 'proprietary'\n | 'unknown'\n\n/** Three-state: known-true / known-false / not-determinable. Drives strict-deny. */\nexport type Tri = true | false | 'unknown'\n\nexport interface LicenseFacts {\n commercialUse: Tri\n derivatives: Tri\n redistribution: Tri\n attributionRequired: boolean\n shareAlike: boolean\n}\n\n// Canonical, auditable license facts. The single source of truth for permissions —\n// RightsRecord stores the license id; permissions are derived via factsFor(), never\n// duplicated. Conservative by design: anything not clearly granted is false/unknown.\nexport const LICENSE_FACTS: Record<LicenseId, LicenseFacts> = {\n 'CC0-1.0': { commercialUse: true, derivatives: true, redistribution: true, attributionRequired: false, shareAlike: false },\n 'PD': { commercialUse: true, derivatives: true, redistribution: true, attributionRequired: false, shareAlike: false },\n 'CC-BY': { commercialUse: true, derivatives: true, redistribution: true, attributionRequired: true, shareAlike: false },\n 'CC-BY-SA': { commercialUse: true, derivatives: true, redistribution: true, attributionRequired: true, shareAlike: true },\n // Stock-platform licenses: free to use incl. commercial, no attribution legally\n // required, but NOT redistributable as-is (can't resell/redistribute the asset itself).\n 'unsplash': { commercialUse: true, derivatives: true, redistribution: false, attributionRequired: false, shareAlike: false },\n 'pexels': { commercialUse: true, derivatives: true, redistribution: false, attributionRequired: false, shareAlike: false },\n 'pixabay': { commercialUse: true, derivatives: true, redistribution: false, attributionRequired: false, shareAlike: false },\n 'proprietary': { commercialUse: false, derivatives: false, redistribution: false, attributionRequired: false, shareAlike: false },\n 'unknown': { commercialUse: 'unknown', derivatives: 'unknown', redistribution: 'unknown', attributionRequired: false, shareAlike: false },\n}\n\n/** Resolve facts for a license id; unrecognized → `unknown` (strict-deny fallback). */\nexport function factsFor(license: LicenseId): LicenseFacts {\n return LICENSE_FACTS[license] ?? LICENSE_FACTS.unknown\n}\n","import { z } from 'zod'\nimport type { LicenseId } from './license'\n\nexport type RehostPolicy = 'hotlink-required' | 'cache-allowed' | 'thumbnail-only' | 'no-store'\n\n// What a satellite emits per result. Permissions are NOT stored here — they are\n// derived from `license` via factsFor() (one source of truth). Only per-item data\n// (author, rehost quirk, jurisdiction) and an auditable raw anchor live here.\nexport interface RightsRecord {\n license: LicenseId\n /** Precise CC version (\"4.0\", \"3.0\", …) for family ids (CC-BY/CC-BY-SA).\n * Attribution/audit only — never read by evaluateUse. Omitted for non-CC. */\n licenseVersion?: string\n /** Per-item attribution datum; attribution text is generated, not stored. */\n author?: string\n rehostPolicy: RehostPolicy\n /** Source-declared jurisdiction of the PD/copyright status (e.g. 'US'). P0: metadata only. */\n jurisdiction?: string\n editorialOnly?: boolean\n /** Auditable anchor back to the source's stated terms. */\n raw: { sourceTerms: string; sourceUrl: string }\n}\n\nconst licenseIdSchema: z.ZodType<LicenseId> = z.enum([\n 'CC0-1.0', 'CC-BY', 'CC-BY-SA', 'PD',\n 'unsplash', 'pexels', 'pixabay', 'proprietary', 'unknown',\n])\n\nexport const rightsRecordSchema: z.ZodType<RightsRecord> = z.object({\n license: licenseIdSchema,\n licenseVersion: z.string().optional(),\n author: z.string().optional(),\n rehostPolicy: z.enum(['hotlink-required', 'cache-allowed', 'thumbnail-only', 'no-store']),\n jurisdiction: z.string().optional(),\n editorialOnly: z.boolean().optional(),\n raw: z.object({ sourceTerms: z.string(), sourceUrl: z.string() }),\n})\n","import { factsFor, type LicenseId } from './license'\n\nexport interface Attribution {\n required: boolean\n text?: string\n html?: string\n}\n\nexport interface AttributionInput {\n license: LicenseId\n /** Precise CC version for family ids; appended to the license name in the credit line. */\n licenseVersion?: string\n canonicalUrl: string\n author?: string\n title?: string\n}\n\nfunction escapeHtml(s: string): string {\n return s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/\"/g, '"')\n}\n\n// Mechanically derive attribution from license + author + title + canonicalUrl, so\n// satellites pass fields (not hand-written strings) and credit lines stay consistent.\nexport function buildAttribution(input: AttributionInput): Attribution {\n const facts = factsFor(input.license)\n if (!facts.attributionRequired) return { required: false }\n\n const author = input.author ?? 'Unknown author'\n const licenseLabel = input.licenseVersion ? `${input.license} ${input.licenseVersion}` : input.license\n const titlePart = input.title ? `\"${input.title}\" ` : ''\n const text = `${titlePart}by ${author} is licensed under ${licenseLabel}. Source: ${input.canonicalUrl}`\n\n const url = escapeHtml(input.canonicalUrl)\n const titleHtml = input.title ? `"${escapeHtml(input.title)}" ` : ''\n const html = `${titleHtml}by ${escapeHtml(author)} is licensed under ${escapeHtml(licenseLabel)}. <a href=\"${url}\">Source</a>`\n\n return { required: true, text, html }\n}\n","import { z } from 'zod'\nimport type { Modality } from './modality'\nimport { rightsRecordSchema, type RightsRecord } from './rights'\n\nexport interface ReferenceMedia { url: string; width?: number; height?: number }\nexport interface MediaPreview { url: string; mediaType: string; width?: number; height?: number }\nexport interface VisualMeta { width: number; height: number; dominantColors?: string[] }\nexport interface TextMeta {\n excerpt: string\n excerptKind: 'passage' | 'structure' | 'quote'\n locator?: string\n}\n\nexport interface Reference {\n // content-addressed, stable within a single result set only (core is zero-storage).\n id: string\n modality: Modality\n title?: string\n // — provenance (required; a result missing any of these never enters the set) —\n source: { providerId: string; sourceUrl: string }\n canonicalUrl: string\n rights: RightsRecord\n verifiedAt: string // ISO; = the moment the satellite parsed rights (not a ToS-drift signal)\n // — carriers —\n thumbnail?: ReferenceMedia\n preview?: MediaPreview\n // computed by the satellite (pHash/blockhash); core only compares it, never decodes bytes.\n perceptualHash?: string\n // — modality-specific —\n visual?: VisualMeta\n text?: TextMeta\n // — retrieval —\n relevance: number // RRF fused score in 0..1; cross-source orderable, not absolute relevance\n raw?: unknown\n}\n\nconst modalitySchema: z.ZodType<Modality> = z.enum(['image', 'video', 'audio', 'text'])\n\nexport const referenceSchema: z.ZodType<Reference> = z.object({\n id: z.string().min(1),\n modality: modalitySchema,\n title: z.string().optional(),\n source: z.object({ providerId: z.string().min(1), sourceUrl: z.string().min(1) }),\n canonicalUrl: z.string().min(1),\n rights: rightsRecordSchema,\n verifiedAt: z.string().datetime(),\n thumbnail: z.object({ url: z.string(), width: z.number().optional(), height: z.number().optional() }).optional(),\n preview: z.object({ url: z.string(), mediaType: z.string(), width: z.number().optional(), height: z.number().optional() }).optional(),\n perceptualHash: z.string().optional(),\n visual: z.object({ width: z.number(), height: z.number(), dominantColors: z.array(z.string()).optional() }).optional(),\n text: z.object({\n excerpt: z.string(),\n excerptKind: z.enum(['passage', 'structure', 'quote']),\n locator: z.string().optional(),\n }).optional(),\n relevance: z.number().min(0).max(1),\n raw: z.unknown().optional(),\n})\n\n/** Validate a provider-emitted reference at the core boundary. Throws on malformed input. */\nexport function parseReference(input: unknown): Reference {\n return referenceSchema.parse(input)\n}\n","// FNV-1a 32-bit, base36. Deterministic, dependency-free, runtime-agnostic.\n// Used only for content-addressed ids / dedup keys — not for security.\nexport function fnv1a(str: string): string {\n let h = 0x811c9dc5\n for (let i = 0; i < str.length; i++) {\n h ^= str.charCodeAt(i)\n h = Math.imul(h, 0x01000193)\n }\n return (h >>> 0).toString(36)\n}\n","import { fnv1a } from './hash'\n\n// Conservative URL canonicalization: lowercase scheme+host, drop fragment + a single\n// trailing slash. Path case and query are preserved (some sources are case-sensitive).\nexport function canonicalizeUrl(url: string): string {\n try {\n const u = new URL(url)\n u.hash = ''\n u.protocol = u.protocol.toLowerCase()\n u.hostname = u.hostname.toLowerCase()\n let out = u.toString()\n if (out.endsWith('/') && !out.endsWith('://')) out = out.slice(0, -1)\n return out\n } catch {\n return url\n }\n}\n\n/** Content-addressed id: stable within a result set, not promised across calls. */\nexport function referenceId(providerId: string, sourceUrl: string): string {\n return `${providerId}:${fnv1a(canonicalizeUrl(sourceUrl))}`\n}\n","import type { Reference } from './reference'\nimport { canonicalizeUrl } from './dedup-key'\n\nconst HEX_BITS: Record<string, number> = {\n '0': 0, '1': 1, '2': 1, '3': 2, '4': 1, '5': 2, '6': 2, '7': 3,\n '8': 1, '9': 2, a: 2, b: 3, c: 2, d: 3, e: 3, f: 4,\n}\n\n/** Bitwise hamming distance between two equal-length lowercase hex strings. */\nexport function hammingDistance(a: string, b: string): number {\n if (a.length !== b.length) return Infinity\n let d = 0\n for (let i = 0; i < a.length; i++) {\n if (a[i] === b[i]) continue\n const xor = (parseInt(a[i], 16) ^ parseInt(b[i], 16)).toString(16)\n d += HEX_BITS[xor] ?? 4\n }\n return d\n}\n\nexport interface DedupeOptions {\n /** Max hamming distance between perceptual hashes to treat as duplicates. Default 0 (off). */\n hashThreshold?: number\n}\n\n// Collapse duplicates, keeping the highest-relevance representative. Two passes:\n// 1) exact canonical-URL match; 2) perceptual-hash within threshold (if both present).\n// Pure: never decodes bytes — operates only on caller-supplied perceptualHash strings.\nexport function dedupeReferences(refs: Reference[], opts: DedupeOptions = {}): Reference[] {\n const threshold = opts.hashThreshold ?? 0\n const kept: Reference[] = []\n const byUrl = new Map<string, number>() // canonicalUrl -> index in kept\n\n for (const ref of refs) {\n const url = canonicalizeUrl(ref.canonicalUrl)\n const urlHit = byUrl.get(url)\n if (urlHit !== undefined) {\n if (ref.relevance > kept[urlHit].relevance) kept[urlHit] = ref\n continue\n }\n\n let merged = false\n if (threshold > 0 && ref.perceptualHash) {\n // NOTE (P1): perceptual hashes must be equal-length across providers or they silently\n // won't hash-dedupe — hammingDistance returns Infinity for unequal lengths.\n for (let i = 0; i < kept.length; i++) {\n const k = kept[i]\n if (k.perceptualHash && hammingDistance(ref.perceptualHash, k.perceptualHash) <= threshold) {\n if (ref.relevance > k.relevance) {\n byUrl.delete(canonicalizeUrl(k.canonicalUrl))\n byUrl.set(canonicalizeUrl(ref.canonicalUrl), i)\n kept[i] = ref\n }\n merged = true\n break\n }\n }\n }\n if (merged) continue\n\n byUrl.set(url, kept.length)\n kept.push(ref)\n }\n return kept\n}\n","import type { Reference } from './reference'\nimport { canonicalizeUrl } from './dedup-key'\nimport { dedupeReferences, type DedupeOptions } from './dedup'\n\nexport interface MergeOptions extends DedupeOptions {\n /** RRF dampening constant. Standard default 60. */\n k?: number\n}\n\n// Reciprocal Rank Fusion across per-source ranked lists. Each list is assumed already\n// ordered best-first by its source. The same item (by canonical URL) appearing across\n// lists accumulates score, so cross-source agreement floats to the top — without\n// needing comparable absolute scores. Output relevance is max-normalized to 0..1.\nexport function mergeReferences(perSource: Reference[][], opts: MergeOptions = {}): Reference[] {\n const k = opts.k ?? 60\n const score = new Map<string, number>() // dedup key -> accumulated RRF score\n const rep = new Map<string, Reference>() // dedup key -> best representative\n\n for (const list of perSource) {\n list.forEach((ref, rank) => {\n const key = canonicalizeUrl(ref.canonicalUrl)\n score.set(key, (score.get(key) ?? 0) + 1 / (k + rank))\n const cur = rep.get(key)\n if (!cur || ref.relevance > cur.relevance) rep.set(key, ref)\n })\n }\n\n // `score` always has ≥1 entry here (we only reach this after building it from\n // non-empty per-source lists; empty input returns [] earlier). Normalize by the\n // actual max so the top result's relevance is exactly 1.0.\n const maxScore = Math.max(...score.values())\n const fused: Reference[] = [...score.entries()]\n .map(([key, s]) => ({ ...rep.get(key)!, relevance: s / maxScore }))\n .sort((a, b) => b.relevance - a.relevance)\n\n // Perceptual-hash dedup as a second pass (URL dedup already happened via the key map).\n return dedupeReferences(fused, opts)\n}\n","import { factsFor, type Tri } from './license'\nimport type { RightsRecord } from './rights'\n\nexport type Intent = 'internal-moodboard' | 'commercial-product' | 'ai-generation-input' | 'redistribution'\nexport type Decision = 'allowed' | 'allowed-with-attribution' | 'denied' | 'needs-review'\n\nexport interface Verdict {\n decision: Decision\n reasons: string[]\n confidence: 'high' | 'low'\n disclaimer: string\n}\n\nexport const NOT_LEGAL_ADVICE =\n 'Heuristic based on source-declared license/ToS facts; not legal advice.'\n\n// Which permission(s) an intent requires to be granted (true).\n// strict-deny: a required permission that is false → denied; 'unknown' → needs-review.\nfunction requiredPermissions(intent: Intent): Array<keyof ReturnType<typeof factsFor>> {\n switch (intent) {\n case 'commercial-product': return ['commercialUse']\n case 'ai-generation-input': return ['commercialUse', 'derivatives']\n case 'redistribution': return ['redistribution']\n case 'internal-moodboard': return [] // lenient; gated only by the unknown/proprietary checks below\n }\n}\n\nexport function evaluateUse(\n r: RightsRecord,\n intent: Intent,\n ctx?: { userJurisdiction?: string },\n): Verdict {\n const facts = factsFor(r.license)\n const reasons: string[] = []\n const confidence: 'high' | 'low' = r.license === 'unknown' ? 'low' : 'high'\n const base = { reasons, confidence, disclaimer: NOT_LEGAL_ADVICE }\n\n const commercialIntent = intent === 'commercial-product' || intent === 'ai-generation-input'\n\n // Unknown license: never allowed — needs-review regardless of intent.\n if (r.license === 'unknown') {\n reasons.push('license could not be determined (strict-deny)')\n return { decision: 'needs-review', ...base }\n }\n\n // editorial-only blocks commercial/AI use outright.\n if (r.editorialOnly && commercialIntent) {\n reasons.push('source marked editorial-only')\n return { decision: 'denied', ...base }\n }\n\n // Jurisdiction (P0 minimal): if both the source jurisdiction and a user jurisdiction\n // are known and differ, defer to human review. Full logic is P2.\n if (ctx?.userJurisdiction && r.jurisdiction && ctx.userJurisdiction !== r.jurisdiction) {\n reasons.push(`source jurisdiction ${r.jurisdiction} != user jurisdiction ${ctx.userJurisdiction}`)\n return { decision: 'needs-review', ...base }\n }\n\n // Evaluate the required permissions with strict-deny semantics.\n for (const perm of requiredPermissions(intent)) {\n const value = facts[perm] as Tri\n if (value === false) {\n reasons.push(`${perm} not granted by ${r.license}`)\n return { decision: 'denied', ...base }\n }\n if (value === 'unknown') {\n reasons.push(`${perm} undetermined for ${r.license}`)\n return { decision: 'needs-review', ...base }\n }\n }\n\n reasons.push(`permitted for ${intent} under ${r.license}`)\n // internal-moodboard is lenient: attribution not enforced for internal-only use.\n if (facts.attributionRequired && intent === 'internal-moodboard') {\n reasons.push('attribution required by license but not enforced for internal-moodboard use')\n }\n const decision: Decision =\n facts.attributionRequired && intent !== 'internal-moodboard'\n ? 'allowed-with-attribution'\n : 'allowed'\n return { decision, ...base }\n}\n","import type { Modality } from './modality'\nimport type { Reference } from './reference'\n\nexport type QueryFeature =\n | 'keyword'\n | 'color'\n | 'orientation'\n | 'license-filter'\n | 'author'\n | 'language'\n\nexport interface SearchFilters {\n color?: string\n orientation?: 'landscape' | 'portrait' | 'square'\n language?: string\n}\n\nexport interface NormalizedQuery {\n text: string\n modalities: Modality[]\n filters?: SearchFilters\n limit?: number\n}\n\nexport interface KeyValueCache {\n get(key: string): Promise<string | undefined>\n set(key: string, value: string, ttlMs?: number): Promise<void>\n}\n\n// Injected by the host/client. core defines the port; providers call `ctx.fetch`.\n// core itself never references a global fetch nor hard-codes an endpoint (zero-network).\nexport interface ProviderContext {\n fetch: typeof fetch\n cache?: KeyValueCache\n signal?: AbortSignal\n}\n\n// 4 load-bearing fields. Keys are held by the provider's factory closure\n// (e.g. `unsplash({ accessKey })`), not declared here; rate-limit metadata is added\n// in P1 when the orchestrator implements throttling.\nexport interface ReferenceProvider {\n id: string\n modalities: Modality[]\n queryFeatures: QueryFeature[]\n search(query: NormalizedQuery, ctx: ProviderContext): Promise<Reference[]>\n}\n\n/** Identity helper for type inference when authoring a provider factory. */\nexport function defineProvider(p: ReferenceProvider): ReferenceProvider {\n return p\n}\n","import type { Modality } from './modality'\nimport type { NormalizedQuery, ReferenceProvider, SearchFilters } from './provider'\n\n// Build a per-provider NormalizedQuery: keep only the filters this provider's\n// queryFeatures support (silently drop the rest — never error), and intersect modalities.\nexport function normalizeQuery(\n input: { query: string; modalities: Modality[]; filters?: SearchFilters; limit?: number },\n provider: ReferenceProvider,\n): NormalizedQuery {\n const feats = new Set(provider.queryFeatures)\n const filters: SearchFilters = {}\n if (input.filters?.color && feats.has('color')) filters.color = input.filters.color\n if (input.filters?.orientation && feats.has('orientation')) filters.orientation = input.filters.orientation\n if (input.filters?.language && feats.has('language')) filters.language = input.filters.language\n const hasFilters = Object.keys(filters).length > 0\n return {\n text: input.query,\n modalities: input.modalities.filter(m => provider.modalities.includes(m)),\n ...(hasFilters ? { filters } : {}),\n ...(input.limit !== undefined ? { limit: input.limit } : {}),\n }\n}\n","import type { Reference } from './reference'\nimport { parseReference } from './reference'\nimport type { Modality } from './modality'\nimport type { Intent, Verdict } from './evaluate-use'\nimport { evaluateUse } from './evaluate-use'\nimport type { Attribution } from './attribution'\nimport { buildAttribution } from './attribution'\nimport type { ReferenceProvider, ProviderContext, KeyValueCache, SearchFilters } from './provider'\nimport { mergeReferences, type MergeOptions } from './merge'\nimport { normalizeQuery } from './query'\n\nexport interface RefkitOptions {\n providers: ReferenceProvider[]\n fetch?: typeof fetch // optional; defaults to globalThis.fetch\n cache?: KeyValueCache\n signal?: AbortSignal\n merge?: MergeOptions\n}\n\nexport interface ProviderError {\n providerId: string\n error: unknown\n}\n\nexport interface SearchInput {\n query: string\n modalities: Modality[]\n filters?: SearchFilters\n limit?: number\n signal?: AbortSignal\n gateFor?: Intent\n onProviderError?: (e: ProviderError) => void\n rerank?: (refs: Reference[]) => Reference[] | Promise<Reference[]>\n}\n\nexport interface RefkitClient {\n search(input: SearchInput): Promise<Reference[]>\n evaluateUse(ref: Reference, intent: Intent, ctx?: { userJurisdiction?: string }): Verdict\n buildAttribution(ref: Reference): Attribution\n readonly providers: readonly ReferenceProvider[]\n}\n\nconst DEFAULT_LIMIT = 30\n\nexport function createRefkit(options: RefkitOptions): RefkitClient {\n if (!options.providers || options.providers.length === 0) {\n throw new Error('createRefkit: at least one provider is required')\n }\n\n async function search(input: SearchInput): Promise<Reference[]> {\n const doFetch = options.fetch ?? globalThis.fetch\n if (typeof doFetch !== 'function') {\n throw new Error('createRefkit: no fetch available — pass options.fetch')\n }\n const ctx: ProviderContext = {\n fetch: doFetch,\n cache: options.cache,\n signal: input.signal ?? options.signal,\n }\n\n const chosen = options.providers.filter(p => p.modalities.some(m => input.modalities.includes(m)))\n if (chosen.length === 0) {\n throw new Error(`refkit.search: no registered provider supports modalities [${input.modalities.join(', ')}]`)\n }\n const settled = await Promise.allSettled(chosen.map(p => p.search(normalizeQuery(input, p), ctx)))\n\n const perSource: Reference[][] = []\n let anyOk = false\n settled.forEach((res, i) => {\n const provider = chosen[i]\n if (res.status === 'fulfilled') {\n anyOk = true\n const valid: Reference[] = []\n for (const raw of res.value) {\n try {\n valid.push(parseReference(raw))\n } catch (error) {\n input.onProviderError?.({ providerId: provider.id, error })\n }\n }\n perSource.push(valid)\n } else {\n input.onProviderError?.({ providerId: provider.id, error: res.reason })\n }\n })\n\n if (!anyOk) {\n const reasons = settled\n .filter((s): s is PromiseRejectedResult => s.status === 'rejected')\n .map(s => s.reason)\n throw new AggregateError(reasons, 'refkit.search: all providers failed')\n }\n\n let refs = mergeReferences(perSource, options.merge)\n if (input.rerank) refs = await input.rerank(refs)\n if (input.gateFor) {\n const intent = input.gateFor\n refs = refs.filter(r => evaluateUse(r.rights, intent).decision.startsWith('allowed'))\n }\n return refs.slice(0, input.limit ?? DEFAULT_LIMIT)\n }\n\n return {\n search,\n evaluateUse: (ref, intent, ctx) => evaluateUse(ref.rights, intent, ctx),\n buildAttribution: ref =>\n buildAttribution({\n license: ref.rights.license,\n author: ref.rights.author,\n title: ref.title,\n canonicalUrl: ref.canonicalUrl,\n }),\n get providers() {\n return options.providers\n },\n }\n}\n"],"mappings":";AAyBO,IAAM,gBAAiD;AAAA,EAC5D,WAAW,EAAE,eAAe,MAAM,aAAa,MAAM,gBAAgB,MAAM,qBAAqB,OAAO,YAAY,MAAM;AAAA,EACzH,MAAM,EAAE,eAAe,MAAM,aAAa,MAAM,gBAAgB,MAAM,qBAAqB,OAAO,YAAY,MAAM;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,OAAO,IAAI,OAAO,CAAC;AAAA,MACxE;AAAA,IACF,CAAC;AAED,QAAI,CAAC,OAAO;AACV,YAAM,UAAU,QACb,OAAO,CAAC,MAAkC,EAAE,WAAW,UAAU,EACjE,IAAI,OAAK,EAAE,MAAM;AACpB,YAAM,IAAI,eAAe,SAAS,qCAAqC;AAAA,IACzE;AAEA,QAAI,OAAO,gBAAgB,WAAW,QAAQ,KAAK;AACnD,QAAI,MAAM,OAAQ,QAAO,MAAM,MAAM,OAAO,IAAI;AAChD,QAAI,MAAM,SAAS;AACjB,YAAM,SAAS,MAAM;AACrB,aAAO,KAAK,OAAO,OAAK,YAAY,EAAE,QAAQ,MAAM,EAAE,SAAS,WAAW,SAAS,CAAC;AAAA,IACtF;AACA,WAAO,KAAK,MAAM,GAAG,MAAM,SAAS,aAAa;AAAA,EACnD;AAEA,SAAO;AAAA,IACL;AAAA,IACA,aAAa,CAAC,KAAK,QAAQ,QAAQ,YAAY,IAAI,QAAQ,QAAQ,GAAG;AAAA,IACtE,kBAAkB,SAChB,iBAAiB;AAAA,MACf,SAAS,IAAI,OAAO;AAAA,MACpB,QAAQ,IAAI,OAAO;AAAA,MACnB,OAAO,IAAI;AAAA,MACX,cAAc,IAAI;AAAA,IACpB,CAAC;AAAA,IACH,IAAI,YAAY;AACd,aAAO,QAAQ;AAAA,IACjB;AAAA,EACF;AACF;","names":["z","z"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@refkit/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "refkit core — neutral reference-retrieval brain: Reference/RightsRecord contract, license normalization, strict-deny use-gate, RRF merge/dedup, ReferenceProvider interfaces. Zero-network, zero-provider, only zod.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"LICENSE"
|
|
18
|
+
],
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"zod": "^4.3.6"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"typecheck": "tsc --noEmit",
|
|
24
|
+
"test": "vitest run",
|
|
25
|
+
"test:watch": "vitest watch",
|
|
26
|
+
"build": "tsup"
|
|
27
|
+
}
|
|
28
|
+
}
|