@kontourai/survey 0.1.1 → 0.1.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/README.md CHANGED
@@ -64,6 +64,75 @@ const trustInput = validateTrustInput(buildSurveyTrustInput(surveyInput));
64
64
  const report = buildTrustReport(trustInput);
65
65
  ```
66
66
 
67
+ ## Repeated observations
68
+
69
+ Use `repeatedObservation` when a producer wants to describe a repeated field or
70
+ entity list as one aggregate observation. The helper returns a normal
71
+ `SurveyObservationInput`, so it works with `SurveyInputBuilder.addObservation`
72
+ and the same Surface projection path.
73
+
74
+ ```ts
75
+ import {
76
+ buildSurveyTrustInput,
77
+ repeatedObservation,
78
+ SurveyInputBuilder,
79
+ } from "@kontourai/survey";
80
+
81
+ const aliases = [
82
+ { name: "North Annex", sourceLabel: "record row 1" },
83
+ { name: "East Annex", sourceLabel: "record row 2" },
84
+ ];
85
+
86
+ const surveyInput = new SurveyInputBuilder({
87
+ source: "example-producer:run-1",
88
+ })
89
+ .addObservation(repeatedObservation({
90
+ id: "entity-123.aliases.current",
91
+ field: "knownAliases",
92
+ value: aliases,
93
+ rawSource: {
94
+ kind: "api-record",
95
+ sourceRef: "example-records://entity/entity-123",
96
+ observedAt: new Date().toISOString(),
97
+ locatorScheme: "structured-field",
98
+ },
99
+ extraction: {
100
+ confidence: 0.88,
101
+ locator: "json:$.aliases",
102
+ extractor: "example-extractor",
103
+ extractedAt: new Date().toISOString(),
104
+ },
105
+ reviewOutcome: {
106
+ status: "verified",
107
+ actor: "records-operator",
108
+ reviewedAt: new Date().toISOString(),
109
+ },
110
+ claim: {
111
+ subjectType: "public-record.entity",
112
+ subjectId: "entity-123",
113
+ surface: "example.profile",
114
+ claimType: "public-data.repeated-field",
115
+ status: "verified",
116
+ impactLevel: "medium",
117
+ collectedBy: "example-extractor",
118
+ },
119
+ metadata: {
120
+ producerField: "aliases",
121
+ },
122
+ }))
123
+ .build();
124
+
125
+ const trustInput = buildSurveyTrustInput(surveyInput);
126
+ ```
127
+
128
+ `repeatedObservation` sets `extraction.target` and
129
+ `claim.fieldOrBehavior` from `field` when omitted, uses the array as both the
130
+ extraction and claim value, and adds neutral helper metadata at
131
+ `metadata.survey.repeated = { representation: "aggregate-array", itemCount }`.
132
+ Producer metadata is preserved. Producers still own item semantics,
133
+ validation, candidate ranking, review policy, and whether a value should be
134
+ verified, proposed, rejected, or assumed.
135
+
67
136
  ## Product Boundary
68
137
 
69
138
  Survey does not crawl pages, parse PDFs, rank candidates, decide review policy,
@@ -2,3 +2,5 @@ export type { CandidateSetStatus, Candidate, CandidateSet, ClaimTarget, DerivedC
2
2
  export { SurveyInputBuilder } from "./builder.js";
3
3
  export type { SurveyClaimRecord, SurveyInputBuilderArgs, SurveyObservationInput } from "./builder.js";
4
4
  export { buildSurveyTrustInput } from "./to-surface.js";
5
+ export { repeatedObservation } from "./repeated-observation.js";
6
+ export type { RepeatedObservationInput } from "./repeated-observation.js";
package/dist/src/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export { SurveyInputBuilder } from "./builder.js";
2
2
  export { buildSurveyTrustInput } from "./to-surface.js";
3
+ export { repeatedObservation } from "./repeated-observation.js";
@@ -0,0 +1,20 @@
1
+ import type { SurveyObservationInput } from "./builder.js";
2
+ export interface RepeatedObservationInput<TItem> {
3
+ id: string;
4
+ field: string;
5
+ value: readonly TItem[];
6
+ rawSource: SurveyObservationInput["rawSource"];
7
+ extraction: Omit<SurveyObservationInput["extraction"], "target" | "value" | "excerpt"> & {
8
+ target?: string;
9
+ excerpt?: string | null;
10
+ };
11
+ reviewOutcome?: SurveyObservationInput["reviewOutcome"];
12
+ claim: Omit<SurveyObservationInput["claim"], "fieldOrBehavior" | "value"> & {
13
+ fieldOrBehavior?: string;
14
+ };
15
+ candidate?: SurveyObservationInput["candidate"];
16
+ candidateSet?: SurveyObservationInput["candidateSet"];
17
+ representation?: "aggregate-array";
18
+ metadata?: Record<string, unknown>;
19
+ }
20
+ export declare function repeatedObservation<TItem>(input: RepeatedObservationInput<TItem>): SurveyObservationInput;
@@ -0,0 +1,42 @@
1
+ export function repeatedObservation(input) {
2
+ const representation = input.representation ?? "aggregate-array";
3
+ const value = [...input.value];
4
+ return {
5
+ id: input.id,
6
+ rawSource: input.rawSource,
7
+ extraction: {
8
+ ...input.extraction,
9
+ target: input.extraction.target ?? input.field,
10
+ value,
11
+ excerpt: input.extraction.excerpt ?? `${input.field}: ${value.length} item(s)`,
12
+ },
13
+ candidate: input.candidate,
14
+ candidateSet: input.candidateSet,
15
+ reviewOutcome: input.reviewOutcome,
16
+ claim: {
17
+ ...input.claim,
18
+ fieldOrBehavior: input.claim.fieldOrBehavior ?? input.field,
19
+ value,
20
+ metadata: repeatedMetadata(input.claim.metadata, input.metadata, representation, value.length),
21
+ },
22
+ };
23
+ }
24
+ function repeatedMetadata(claimMetadata, metadata, representation, itemCount) {
25
+ const claimSurvey = claimMetadata?.survey && isRecord(claimMetadata.survey) ? claimMetadata.survey : {};
26
+ const survey = metadata?.survey && isRecord(metadata.survey) ? metadata.survey : {};
27
+ return {
28
+ ...claimMetadata,
29
+ ...metadata,
30
+ survey: {
31
+ ...claimSurvey,
32
+ ...survey,
33
+ repeated: {
34
+ representation,
35
+ itemCount,
36
+ },
37
+ },
38
+ };
39
+ }
40
+ function isRecord(value) {
41
+ return typeof value === "object" && value !== null && !Array.isArray(value);
42
+ }
@@ -41,6 +41,7 @@ export function buildSurveyTrustInput(input) {
41
41
  metadata: {
42
42
  ...projection.metadata,
43
43
  survey: {
44
+ ...(isRecord(projection.metadata?.survey) ? projection.metadata.survey : {}),
44
45
  rawSourceId: rawSource.id,
45
46
  extractionId: extraction.id,
46
47
  candidateSetId: candidateSet.id,
@@ -213,3 +214,6 @@ function groupBy(items, getKey) {
213
214
  }
214
215
  return map;
215
216
  }
217
+ function isRecord(value) {
218
+ return typeof value === "object" && value !== null && !Array.isArray(value);
219
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kontourai/survey",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Producer-side source, extraction, candidate, and review contracts for projecting verified claims into Surface.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",