@proposit/proposit-core 3.3.0 → 3.4.1
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 +99 -2
- package/dist/cli/commands/expressions.d.ts.map +1 -1
- package/dist/cli/commands/expressions.js +44 -0
- package/dist/cli/commands/expressions.js.map +1 -1
- package/dist/cli/commands/origins.d.ts +3 -0
- package/dist/cli/commands/origins.d.ts.map +1 -0
- package/dist/cli/commands/origins.js +264 -0
- package/dist/cli/commands/origins.js.map +1 -0
- package/dist/cli/commands/premises.d.ts.map +1 -1
- package/dist/cli/commands/premises.js +18 -2
- package/dist/cli/commands/premises.js.map +1 -1
- package/dist/cli/engine.d.ts.map +1 -1
- package/dist/cli/engine.js +5 -2
- package/dist/cli/engine.js.map +1 -1
- package/dist/cli/router.d.ts.map +1 -1
- package/dist/cli/router.js +1 -0
- package/dist/cli/router.js.map +1 -1
- package/dist/cli/schemata.d.ts +2 -0
- package/dist/cli/schemata.d.ts.map +1 -1
- package/dist/cli/schemata.js +14 -1
- package/dist/cli/schemata.js.map +1 -1
- package/dist/cli/storage/libraries.d.ts +4 -0
- package/dist/cli/storage/libraries.d.ts.map +1 -1
- package/dist/cli/storage/libraries.js +19 -0
- package/dist/cli/storage/libraries.js.map +1 -1
- package/dist/cli.js +2 -0
- package/dist/cli.js.map +1 -1
- package/dist/extensions/basics/schemata.d.ts +2 -0
- package/dist/extensions/basics/schemata.d.ts.map +1 -1
- package/dist/extensions/citations/ieee/index.d.ts +1 -0
- package/dist/extensions/citations/ieee/index.d.ts.map +1 -1
- package/dist/extensions/citations/ieee/index.js +1 -0
- package/dist/extensions/citations/ieee/index.js.map +1 -1
- package/dist/extensions/citations/ieee/origin-document.d.ts +452 -0
- package/dist/extensions/citations/ieee/origin-document.d.ts.map +1 -0
- package/dist/extensions/citations/ieee/origin-document.js +25 -0
- package/dist/extensions/citations/ieee/origin-document.js.map +1 -0
- package/dist/extensions/pipelines/base/finalize-response-v2.d.ts +24 -0
- package/dist/extensions/pipelines/base/finalize-response-v2.d.ts.map +1 -1
- package/dist/extensions/pipelines/base/finalize-response-v2.js +249 -8
- package/dist/extensions/pipelines/base/finalize-response-v2.js.map +1 -1
- package/dist/extensions/pipelines/base/index.d.ts +3 -1
- package/dist/extensions/pipelines/base/index.d.ts.map +1 -1
- package/dist/extensions/pipelines/base/index.js +2 -1
- package/dist/extensions/pipelines/base/index.js.map +1 -1
- package/dist/extensions/pipelines/base/source-anchors.d.ts +58 -0
- package/dist/extensions/pipelines/base/source-anchors.d.ts.map +1 -0
- package/dist/extensions/pipelines/base/source-anchors.js +209 -0
- package/dist/extensions/pipelines/base/source-anchors.js.map +1 -0
- package/dist/extensions/pipelines/ingestion/canonical-stages.d.ts.map +1 -1
- package/dist/extensions/pipelines/ingestion/canonical-stages.js +1 -0
- package/dist/extensions/pipelines/ingestion/canonical-stages.js.map +1 -1
- package/dist/extensions/pipelines/ingestion/scholar/scholar.d.ts.map +1 -1
- package/dist/extensions/pipelines/ingestion/scholar/scholar.js +11 -1
- package/dist/extensions/pipelines/ingestion/scholar/scholar.js.map +1 -1
- package/dist/extensions/pipelines/ingestion/scribe/extract-stage.d.ts +27 -11
- package/dist/extensions/pipelines/ingestion/scribe/extract-stage.d.ts.map +1 -1
- package/dist/extensions/pipelines/ingestion/scribe/extract-stage.js +56 -22
- package/dist/extensions/pipelines/ingestion/scribe/extract-stage.js.map +1 -1
- package/dist/extensions/pipelines/ingestion/scribe/schemas.d.ts +25 -1
- package/dist/extensions/pipelines/ingestion/scribe/schemas.d.ts.map +1 -1
- package/dist/extensions/pipelines/ingestion/scribe/schemas.js +25 -3
- package/dist/extensions/pipelines/ingestion/scribe/schemas.js.map +1 -1
- package/dist/extensions/pipelines/ingestion/scribe/scribe.d.ts.map +1 -1
- package/dist/extensions/pipelines/ingestion/scribe/scribe.js +25 -4
- package/dist/extensions/pipelines/ingestion/scribe/scribe.js.map +1 -1
- package/dist/extensions/pipelines/ingestion/scribe/structure-stage.d.ts +1 -1
- package/dist/extensions/pipelines/ingestion/scribe/structure-stage.d.ts.map +1 -1
- package/dist/extensions/pipelines/ingestion/scribe/structure-stage.js +1 -1
- package/dist/lib/consts.d.ts.map +1 -1
- package/dist/lib/consts.js +27 -0
- package/dist/lib/consts.js.map +1 -1
- package/dist/lib/core/argument-engine.d.ts +5 -3
- package/dist/lib/core/argument-engine.d.ts.map +1 -1
- package/dist/lib/core/argument-engine.js +7 -4
- package/dist/lib/core/argument-engine.js.map +1 -1
- package/dist/lib/core/interfaces/argument-engine.interfaces.d.ts +2 -1
- package/dist/lib/core/interfaces/argument-engine.interfaces.d.ts.map +1 -1
- package/dist/lib/core/interfaces/index.d.ts +1 -1
- package/dist/lib/core/interfaces/index.d.ts.map +1 -1
- package/dist/lib/core/interfaces/library.interfaces.d.ts +72 -1
- package/dist/lib/core/interfaces/library.interfaces.d.ts.map +1 -1
- package/dist/lib/core/origin-library.d.ts +127 -0
- package/dist/lib/core/origin-library.d.ts.map +1 -0
- package/dist/lib/core/origin-library.js +520 -0
- package/dist/lib/core/origin-library.js.map +1 -0
- package/dist/lib/core/premise-engine.d.ts.map +1 -1
- package/dist/lib/core/premise-engine.js +20 -3
- package/dist/lib/core/premise-engine.js.map +1 -1
- package/dist/lib/core/proposit-core.d.ts +15 -8
- package/dist/lib/core/proposit-core.d.ts.map +1 -1
- package/dist/lib/core/proposit-core.js +28 -3
- package/dist/lib/core/proposit-core.js.map +1 -1
- package/dist/lib/grammar/types.d.ts +2 -2
- package/dist/lib/grammar/types.d.ts.map +1 -1
- package/dist/lib/grammar/types.js +2 -1
- package/dist/lib/grammar/types.js.map +1 -1
- package/dist/lib/grammar/validators/presentable.d.ts +19 -0
- package/dist/lib/grammar/validators/presentable.d.ts.map +1 -1
- package/dist/lib/grammar/validators/presentable.js +57 -0
- package/dist/lib/grammar/validators/presentable.js.map +1 -1
- package/dist/lib/index.d.ts +4 -0
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +3 -0
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/parsing/argument-parser.d.ts.map +1 -1
- package/dist/lib/parsing/argument-parser.js +4 -3
- package/dist/lib/parsing/argument-parser.js.map +1 -1
- package/dist/lib/schemata/index.d.ts +1 -0
- package/dist/lib/schemata/index.d.ts.map +1 -1
- package/dist/lib/schemata/index.js +1 -0
- package/dist/lib/schemata/index.js.map +1 -1
- package/dist/lib/schemata/origin.d.ts +48 -0
- package/dist/lib/schemata/origin.d.ts.map +1 -0
- package/dist/lib/schemata/origin.js +102 -0
- package/dist/lib/schemata/origin.js.map +1 -0
- package/dist/lib/schemata/propositional.d.ts +6 -0
- package/dist/lib/schemata/propositional.d.ts.map +1 -1
- package/dist/lib/schemata/propositional.js +13 -0
- package/dist/lib/schemata/propositional.js.map +1 -1
- package/dist/lib/types/checksum.d.ts +3 -0
- package/dist/lib/types/checksum.d.ts.map +1 -1
- package/dist/lib/types/validation.d.ts +19 -1
- package/dist/lib/types/validation.d.ts.map +1 -1
- package/dist/lib/types/validation.js +19 -0
- package/dist/lib/types/validation.js.map +1 -1
- package/dist/lib/utils/collections.d.ts +15 -0
- package/dist/lib/utils/collections.d.ts.map +1 -1
- package/dist/lib/utils/collections.js +17 -0
- package/dist/lib/utils/collections.js.map +1 -1
- package/dist/lib/utils/origin-text.d.ts +62 -0
- package/dist/lib/utils/origin-text.d.ts.map +1 -0
- package/dist/lib/utils/origin-text.js +204 -0
- package/dist/lib/utils/origin-text.js.map +1 -0
- package/dist/lib/utils/sha256.d.ts +6 -0
- package/dist/lib/utils/sha256.d.ts.map +1 -0
- package/dist/lib/utils/sha256.js +98 -0
- package/dist/lib/utils/sha256.js.map +1 -0
- package/package.json +1 -1
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
// way for `finalize.run` to consult the executor's accumulated failure
|
|
31
31
|
// list (which would require widening `TStageContext`).
|
|
32
32
|
import { STAGE_IDS, } from "./stages/schemas.js";
|
|
33
|
+
import { locateSourceAnchor, nearestOccurrence, } from "./source-anchors.js";
|
|
33
34
|
import { IEEE_REFERENCE_TYPES } from "../../citations/ieee/references.js";
|
|
34
35
|
// The valid `citationTypeGuess` values — the 33 IEEE reference types
|
|
35
36
|
// plus the explicit "unknown" fallback. Built from the IEEE list so the
|
|
@@ -111,9 +112,10 @@ function buildClaimToRole(args) {
|
|
|
111
112
|
function stripCanonicalizerOnlyFields(claim) {
|
|
112
113
|
// The canonicalizer's per-claim record carries `mentionIds` and
|
|
113
114
|
// `suggestedSymbol` which are not part of the public response
|
|
114
|
-
// schema. Strip them from the finalize output
|
|
115
|
-
// `symbol` carries the assigned identifier
|
|
116
|
-
//
|
|
115
|
+
// schema. Strip them from the finalize output: the variable's
|
|
116
|
+
// `symbol` carries the assigned identifier, and mention ids name an
|
|
117
|
+
// id space the response never carries — the provenance they trace is
|
|
118
|
+
// resolved into `sourceAnchors` instead, which a consumer can act on.
|
|
117
119
|
const stripped = {};
|
|
118
120
|
for (const [key, value] of Object.entries(claim)) {
|
|
119
121
|
if (key === "mentionIds" || key === "suggestedSymbol")
|
|
@@ -122,6 +124,193 @@ function stripCanonicalizerOnlyFields(claim) {
|
|
|
122
124
|
}
|
|
123
125
|
return stripped;
|
|
124
126
|
}
|
|
127
|
+
// -- Source anchors --
|
|
128
|
+
//
|
|
129
|
+
// The pipeline knows where each claim and each inference came from, but
|
|
130
|
+
// only as data spread across three stages: `segmentation` holds
|
|
131
|
+
// input-relative segment spans, `claim-mention-extraction` holds
|
|
132
|
+
// *segment-relative* mention spans plus the mention text, and
|
|
133
|
+
// `relation-extraction` holds a quote per relation. Finalize is the
|
|
134
|
+
// first place all three are in scope at once, so it is where they become
|
|
135
|
+
// a usable reference back into the input.
|
|
136
|
+
//
|
|
137
|
+
// Only quoted text crosses the boundary as fact; the model's offsets are
|
|
138
|
+
// used to choose among repeated occurrences and are never emitted
|
|
139
|
+
// unverified. See `source-anchors.ts`.
|
|
140
|
+
/**
|
|
141
|
+
* Where each segment actually begins in the input.
|
|
142
|
+
*
|
|
143
|
+
* The segmentation prompt requires `segment.text` be copied verbatim, so
|
|
144
|
+
* the true offset is recoverable by searching — and searching is what
|
|
145
|
+
* this does, because the model's own `span.start` drifts — off by one on
|
|
146
|
+
* several segments of the recorded corpus. Small, and invisible until a
|
|
147
|
+
* quote repeats, at which point the drifted hint picks the wrong
|
|
148
|
+
* occurrence.
|
|
149
|
+
*
|
|
150
|
+
* Segments are emitted left to right and cover the input, so the scan
|
|
151
|
+
* carries a cursor rather than searching from zero: that keeps a segment
|
|
152
|
+
* whose text repeats earlier in the document from collapsing onto the
|
|
153
|
+
* earlier copy. Among the candidates at or after the cursor, the one
|
|
154
|
+
* nearest the model's reported start wins — the model's number chooses
|
|
155
|
+
* between verified positions rather than supplying one.
|
|
156
|
+
*/
|
|
157
|
+
function resolveSegmentStarts(inputText, segmentation) {
|
|
158
|
+
const out = new Map();
|
|
159
|
+
let cursor = 0;
|
|
160
|
+
for (const segment of segmentation?.segments ?? []) {
|
|
161
|
+
const found = nearestOccurrence(inputText, segment.text, segment.span.start, cursor);
|
|
162
|
+
if (found === undefined) {
|
|
163
|
+
out.set(segment.segmentId, segment.span.start);
|
|
164
|
+
// Advance past where the model says this segment ended.
|
|
165
|
+
// Leaving the cursor behind would let the next segment's
|
|
166
|
+
// scan reach back into territory this one owns and match a
|
|
167
|
+
// duplicate inside it — the exact collapse the cursor
|
|
168
|
+
// exists to prevent, triggered by the branch that handles a
|
|
169
|
+
// rewritten segment.
|
|
170
|
+
cursor = Math.max(cursor, segment.span.end);
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
out.set(segment.segmentId, found);
|
|
174
|
+
cursor = found + segment.text.length;
|
|
175
|
+
}
|
|
176
|
+
return out;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Non-fatal note codes for anchor resolution. Neither stops assembly:
|
|
180
|
+
* an unresolved quote yields no anchor, and an ambiguous one yields the
|
|
181
|
+
* nearest-hint winner. Both are reported because silence here is
|
|
182
|
+
* indistinguishable from success — a model that starts paraphrasing
|
|
183
|
+
* would otherwise take anchor coverage to zero with no signal.
|
|
184
|
+
*/
|
|
185
|
+
export const SOURCE_ANCHOR_NOTE_CODES = {
|
|
186
|
+
unresolved: "SOURCE_ANCHOR_UNRESOLVED",
|
|
187
|
+
ambiguous: "SOURCE_ANCHOR_AMBIGUOUS",
|
|
188
|
+
inputUnavailable: "SOURCE_ANCHOR_INPUT_UNAVAILABLE",
|
|
189
|
+
};
|
|
190
|
+
/** Emit the note for one attempted resolution, if there is one to emit. */
|
|
191
|
+
function noteResolution(args) {
|
|
192
|
+
const subjectText = Object.entries(args.subject)
|
|
193
|
+
.map(([key, value]) => `${key} ${value}`)
|
|
194
|
+
.join(" ");
|
|
195
|
+
if (args.match === undefined) {
|
|
196
|
+
args.ctx.addFailure({
|
|
197
|
+
code: SOURCE_ANCHOR_NOTE_CODES.unresolved,
|
|
198
|
+
message: `Quote for ${subjectText} was not found in the input; no source anchor was emitted.`,
|
|
199
|
+
severity: "warning",
|
|
200
|
+
context: { ...args.subject, quote: args.quote },
|
|
201
|
+
});
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (args.match.occurrences > 1) {
|
|
205
|
+
args.ctx.addFailure({
|
|
206
|
+
code: SOURCE_ANCHOR_NOTE_CODES.ambiguous,
|
|
207
|
+
message: `Quote for ${subjectText} occurs ${String(args.match.occurrences)} times in the input; the occurrence nearest the reported position was used.`,
|
|
208
|
+
severity: "warning",
|
|
209
|
+
context: {
|
|
210
|
+
...args.subject,
|
|
211
|
+
quote: args.quote,
|
|
212
|
+
occurrences: args.match.occurrences,
|
|
213
|
+
startUtf16: args.match.anchor.startUtf16,
|
|
214
|
+
},
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
/** Resolve every mention to a verified anchor in the input, by id. */
|
|
219
|
+
function buildAnchorByMentionId(args) {
|
|
220
|
+
const out = new Map();
|
|
221
|
+
if (!args.mentions)
|
|
222
|
+
return out;
|
|
223
|
+
const segmentStartById = args.segmentStartById;
|
|
224
|
+
const segmentTextById = new Map((args.segments ?? []).map((s) => [s.segmentId, s.text]));
|
|
225
|
+
for (const mention of args.mentions.mentions) {
|
|
226
|
+
// Mention spans are relative to the segment's text, so the
|
|
227
|
+
// input-relative hint only exists once the segment's own start is
|
|
228
|
+
// added back on.
|
|
229
|
+
//
|
|
230
|
+
// Both halves of that sum are located rather than trusted. The
|
|
231
|
+
// mention's own offset is the larger error of the two on the
|
|
232
|
+
// recorded corpus — a model can miscount its way through a
|
|
233
|
+
// markdown link and report a mention 14 characters early — and
|
|
234
|
+
// the mention text is copied from the segment, so its position
|
|
235
|
+
// inside the segment is recoverable exactly the way the
|
|
236
|
+
// segment's position in the document is.
|
|
237
|
+
const segmentText = segmentTextById.get(mention.segmentId);
|
|
238
|
+
const offsetInSegment = segmentText === undefined
|
|
239
|
+
? undefined
|
|
240
|
+
: nearestOccurrence(segmentText, mention.text, mention.span.start);
|
|
241
|
+
const hint = (segmentStartById.get(mention.segmentId) ?? 0) +
|
|
242
|
+
(offsetInSegment ?? mention.span.start);
|
|
243
|
+
const match = locateSourceAnchor(args.inputText, mention.text, hint);
|
|
244
|
+
noteResolution({
|
|
245
|
+
ctx: args.ctx,
|
|
246
|
+
match,
|
|
247
|
+
quote: mention.text,
|
|
248
|
+
subject: { mentionId: mention.mentionId },
|
|
249
|
+
});
|
|
250
|
+
if (match !== undefined)
|
|
251
|
+
out.set(mention.mentionId, match.anchor);
|
|
252
|
+
}
|
|
253
|
+
return out;
|
|
254
|
+
}
|
|
255
|
+
/** Anchors for the mentions of one claim, in order, deduped by range. */
|
|
256
|
+
function claimAnchors(mentionIds, anchorByMentionId) {
|
|
257
|
+
const seen = new Set();
|
|
258
|
+
const anchors = [];
|
|
259
|
+
for (const mentionId of mentionIds) {
|
|
260
|
+
const anchor = anchorByMentionId.get(mentionId);
|
|
261
|
+
if (anchor === undefined)
|
|
262
|
+
continue;
|
|
263
|
+
const key = `${String(anchor.startUtf16)}:${String(anchor.endUtf16)}`;
|
|
264
|
+
if (seen.has(key))
|
|
265
|
+
continue;
|
|
266
|
+
seen.add(key);
|
|
267
|
+
anchors.push(anchor);
|
|
268
|
+
}
|
|
269
|
+
return anchors;
|
|
270
|
+
}
|
|
271
|
+
/** The anchor for a relation's evidence quote, if it can be located. */
|
|
272
|
+
function relationAnchor(args) {
|
|
273
|
+
const starts = args.relation.evidence.segmentIds
|
|
274
|
+
.map((id) => args.segmentStartById.get(id))
|
|
275
|
+
.filter((start) => start !== undefined);
|
|
276
|
+
const hint = starts.length > 0 ? Math.min(...starts) : 0;
|
|
277
|
+
const quote = args.relation.evidence.quote;
|
|
278
|
+
const match = locateSourceAnchor(args.inputText, quote, hint);
|
|
279
|
+
// An empty evidence quote is a legal "no span to cite" the fast
|
|
280
|
+
// pipeline's prompt explicitly permits, not a failure to find one,
|
|
281
|
+
// so it is not reported.
|
|
282
|
+
if (quote.trim().length > 0) {
|
|
283
|
+
noteResolution({
|
|
284
|
+
ctx: args.ctx,
|
|
285
|
+
match,
|
|
286
|
+
quote,
|
|
287
|
+
subject: { relationId: args.relation.relationId },
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
return match?.anchor;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* The raw text this pipeline was given, or `""` for any input shape that
|
|
294
|
+
* does not carry one.
|
|
295
|
+
*
|
|
296
|
+
* `TStageContext.input` is `unknown` and this assembler is public API
|
|
297
|
+
* for consumers composing their own pipelines, whose `inputSchema` need
|
|
298
|
+
* not be `{ text }`. Anchors are the only thing that reads the input, so
|
|
299
|
+
* an empty string degrades exactly into the documented no-anchor
|
|
300
|
+
* behavior — every match misses — rather than throwing out of finalize
|
|
301
|
+
* on the happy path, after every LLM call has been paid for.
|
|
302
|
+
*/
|
|
303
|
+
function readInputText(input) {
|
|
304
|
+
const text = input?.text;
|
|
305
|
+
return typeof text === "string" ? text : "";
|
|
306
|
+
}
|
|
307
|
+
/** The `mentionIds` on a canonical claim record, defensively read. */
|
|
308
|
+
function readMentionIds(record) {
|
|
309
|
+
const raw = record.mentionIds;
|
|
310
|
+
return Array.isArray(raw)
|
|
311
|
+
? raw.filter((id) => typeof id === "string")
|
|
312
|
+
: [];
|
|
313
|
+
}
|
|
125
314
|
/**
|
|
126
315
|
* Resolve a claim miniId to its quoted display title, falling back to
|
|
127
316
|
* the claim's assigned variable symbol (quoted) when no title is
|
|
@@ -237,6 +426,31 @@ export function finalizeResponseV2(input) {
|
|
|
237
426
|
};
|
|
238
427
|
}
|
|
239
428
|
// Happy path: assemble the argument.
|
|
429
|
+
const inputText = readInputText(ctx.input);
|
|
430
|
+
// Nothing resolves against an empty input, so resolution is skipped
|
|
431
|
+
// wholesale rather than run to produce one "quote not found" note per
|
|
432
|
+
// mention and relation. N notes blaming the model for a fault in the
|
|
433
|
+
// caller's input shape is worse than no notes; one note naming the
|
|
434
|
+
// real cause is better than either. It also keeps every extracted
|
|
435
|
+
// quote out of `failures`.
|
|
436
|
+
const inputAvailable = inputText.length > 0;
|
|
437
|
+
if (!inputAvailable) {
|
|
438
|
+
ctx.addFailure({
|
|
439
|
+
code: SOURCE_ANCHOR_NOTE_CODES.inputUnavailable,
|
|
440
|
+
message: "The pipeline input carries no text, so no source anchors were resolved. This is a property of the input, not of the model's output.",
|
|
441
|
+
severity: "warning",
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
const segmentStartById = resolveSegmentStarts(inputText, input.segmentation);
|
|
445
|
+
const anchorByMentionId = inputAvailable
|
|
446
|
+
? buildAnchorByMentionId({
|
|
447
|
+
ctx,
|
|
448
|
+
inputText,
|
|
449
|
+
segmentStartById,
|
|
450
|
+
segments: input.segmentation?.segments,
|
|
451
|
+
mentions: input.mentions,
|
|
452
|
+
})
|
|
453
|
+
: new Map();
|
|
240
454
|
const conclusionMiniId = conclusion?.conclusionMiniId ?? null;
|
|
241
455
|
const roles = buildClaimToRole({
|
|
242
456
|
canonicalClaims: canon.canonicalClaims,
|
|
@@ -248,6 +462,14 @@ export function finalizeResponseV2(input) {
|
|
|
248
462
|
const classifiedType = typeByMiniId.get(c.miniId)?.type ?? c.type;
|
|
249
463
|
const record = c;
|
|
250
464
|
const stripped = stripCanonicalizerOnlyFields(record);
|
|
465
|
+
// An entity with no resolvable provenance carries no key at all
|
|
466
|
+
// rather than an empty array — "we found nothing" and "we did not
|
|
467
|
+
// look" read the same to a consumer, and neither is a claim about
|
|
468
|
+
// the text.
|
|
469
|
+
const anchors = claimAnchors(readMentionIds(record), anchorByMentionId);
|
|
470
|
+
if (anchors.length > 0) {
|
|
471
|
+
stripped.sourceAnchors = anchors;
|
|
472
|
+
}
|
|
251
473
|
// A claim classified `citation` stays `citation` and carries an
|
|
252
474
|
// explicit `UnparsedCitation` (its `text` is the display text, so
|
|
253
475
|
// a url-less reference no longer renders blank). Premise
|
|
@@ -290,11 +512,30 @@ export function finalizeResponseV2(input) {
|
|
|
290
512
|
symbolByClaimMiniId: new Map(variables.map((v) => [v.claimMiniId, v.symbol])),
|
|
291
513
|
relationById: new Map(relations.map((r) => [r.relationId, r])),
|
|
292
514
|
};
|
|
293
|
-
const finalPremises = compilation.premises.map((p) =>
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
515
|
+
const finalPremises = compilation.premises.map((p) => {
|
|
516
|
+
const premise = {
|
|
517
|
+
miniId: p.premiseMiniId,
|
|
518
|
+
formula: p.formula,
|
|
519
|
+
title: buildPremiseTitle(p, titleComposerMaps),
|
|
520
|
+
};
|
|
521
|
+
// The conclusion premise is synthesized from a bare symbol and
|
|
522
|
+
// has no source relation, so it has no evidence quote to anchor.
|
|
523
|
+
const relation = p.sourceRelationId !== null
|
|
524
|
+
? titleComposerMaps.relationById.get(p.sourceRelationId)
|
|
525
|
+
: undefined;
|
|
526
|
+
const anchor = inputAvailable && relation !== undefined
|
|
527
|
+
? relationAnchor({
|
|
528
|
+
ctx,
|
|
529
|
+
inputText,
|
|
530
|
+
relation,
|
|
531
|
+
segmentStartById,
|
|
532
|
+
})
|
|
533
|
+
: undefined;
|
|
534
|
+
if (anchor !== undefined) {
|
|
535
|
+
premise.sourceAnchors = [anchor];
|
|
536
|
+
}
|
|
537
|
+
return premise;
|
|
538
|
+
});
|
|
298
539
|
const argument = {
|
|
299
540
|
claims,
|
|
300
541
|
variables: finalVariables,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"finalize-response-v2.js","sourceRoot":"","sources":["../../../../src/extensions/pipelines/base/finalize-response-v2.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,iEAAiE;AACjE,qBAAqB;AACrB,EAAE;AACF,iEAAiE;AACjE,wBAAwB;AACxB,EAAE;AACF,8DAA8D;AAC9D,oEAAoE;AACpE,iDAAiD;AACjD,2DAA2D;AAC3D,EAAE;AACF,iEAAiE;AACjE,mEAAmE;AACnE,yDAAyD;AACzD,sEAAsE;AACtE,EAAE;AACF,sEAAsE;AACtE,gEAAgE;AAChE,yEAAyE;AACzE,4EAA4E;AAC5E,kEAAkE;AAClE,yBAAyB;AACzB,EAAE;AACF,qEAAqE;AACrE,sEAAsE;AACtE,yEAAyE;AACzE,uEAAuE;AACvE,sEAAsE;AACtE,uEAAuE;AACvE,uDAAuD;AAIvD,OAAO,EACH,SAAS,GAUZ,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAA;AAMzE,qEAAqE;AACrE,wEAAwE;AACxE,8DAA8D;AAC9D,MAAM,2BAA2B,GAAG,IAAI,GAAG,CAA6B;IACpE,GAAG,oBAAoB;IACvB,SAAS;CACZ,CAAC,CAAA;AAEF;;;;;GAKG;AACH,SAAS,yBAAyB,CAAC,GAAY;IAC3C,IACI,OAAO,GAAG,KAAK,QAAQ;QACvB,2BAA2B,CAAC,GAAG,CAAC,GAAiC,CAAC,EACpE,CAAC;QACC,OAAO,GAAiC,CAAA;IAC5C,CAAC;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AC5D,+DAA+D;QAC/D,iEAAiE;QACjE,iBAAiB,EAAE,WAAW,CAAC,iBAAiB;QAChD,KAAK,EAAE,kBAAkB,CAAC,KAAK,CAAC,eAAe,EAAE,gBAAgB,CAAC;KACrE,CAAA;IAED,OAAO;QACH,QAAQ,EAAE,QAA0D;QACpE,WAAW,EAAE,IAAI;QACjB,GAAG,YAAY;QAEf,kBAAkB;KACM,CAAA;AAChC,CAAC"}
|
|
1
|
+
{"version":3,"file":"finalize-response-v2.js","sourceRoot":"","sources":["../../../../src/extensions/pipelines/base/finalize-response-v2.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,iEAAiE;AACjE,qBAAqB;AACrB,EAAE;AACF,iEAAiE;AACjE,wBAAwB;AACxB,EAAE;AACF,8DAA8D;AAC9D,oEAAoE;AACpE,iDAAiD;AACjD,2DAA2D;AAC3D,EAAE;AACF,iEAAiE;AACjE,mEAAmE;AACnE,yDAAyD;AACzD,sEAAsE;AACtE,EAAE;AACF,sEAAsE;AACtE,gEAAgE;AAChE,yEAAyE;AACzE,4EAA4E;AAC5E,kEAAkE;AAClE,yBAAyB;AACzB,EAAE;AACF,qEAAqE;AACrE,sEAAsE;AACtE,yEAAyE;AACzE,uEAAuE;AACvE,sEAAsE;AACtE,uEAAuE;AACvE,uDAAuD;AAIvD,OAAO,EACH,SAAS,GAYZ,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EACH,kBAAkB,EAClB,iBAAiB,GAGpB,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAA;AAMzE,qEAAqE;AACrE,wEAAwE;AACxE,8DAA8D;AAC9D,MAAM,2BAA2B,GAAG,IAAI,GAAG,CAA6B;IACpE,GAAG,oBAAoB;IACvB,SAAS;CACZ,CAAC,CAAA;AAEF;;;;;GAKG;AACH,SAAS,yBAAyB,CAAC,GAAY;IAC3C,IACI,OAAO,GAAG,KAAK,QAAQ;QACvB,2BAA2B,CAAC,GA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C,CAAC,CAAA;IAEF,MAAM,QAAQ,GAAuB;QACjC,MAAM;QACN,SAAS,EAAE,cAAc;QACzB,QAAQ,EAAE,aAAa;QACvB,uBAAuB,EAAE,WAAW,CAAC,uBAAuB;QAC5D,+DAA+D;QAC/D,iEAAiE;QACjE,iBAAiB,EAAE,WAAW,CAAC,iBAAiB;QAChD,KAAK,EAAE,kBAAkB,CAAC,KAAK,CAAC,eAAe,EAAE,gBAAgB,CAAC;KACrE,CAAA;IAED,OAAO;QACH,QAAQ,EAAE,QAA0D;QACpE,WAAW,EAAE,IAAI;QACjB,GAAG,YAAY;QAEf,kBAAkB;KACM,CAAA;AAChC,CAAC"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
export { finalizeResponseV2, FINALIZE_V2_FAILURE_TEXTS, } from "./finalize-response-v2.js";
|
|
1
|
+
export { finalizeResponseV2, FINALIZE_V2_FAILURE_TEXTS, SOURCE_ANCHOR_NOTE_CODES, } from "./finalize-response-v2.js";
|
|
2
2
|
export type { TFinalizeResponseV2Input } from "./finalize-response-v2.js";
|
|
3
|
+
export { locateSourceAnchor, SOURCE_ANCHOR_CONTEXT_CHARS, } from "./source-anchors.js";
|
|
4
|
+
export type { TIngestionSourceAnchor, TSourceAnchorMatch, } from "./source-anchors.js";
|
|
3
5
|
export { resolveLlmStageOptions } from "./resolve-llm-stage-options.js";
|
|
4
6
|
export { basicsExtension } from "./basics-extension.js";
|
|
5
7
|
export type { TIngestionExtension, TIngestionInput, TIngestionLlmOptions, TLlmStageOptionsOverride, } from "./types.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/extensions/pipelines/base/index.ts"],"names":[],"mappings":"AAUA,OAAO,EACH,kBAAkB,EAClB,yBAAyB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/extensions/pipelines/base/index.ts"],"names":[],"mappings":"AAUA,OAAO,EACH,kBAAkB,EAClB,yBAAyB,EACzB,wBAAwB,GAC3B,MAAM,2BAA2B,CAAA;AAClC,YAAY,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAA;AACzE,OAAO,EACH,kBAAkB,EAClB,2BAA2B,GAC9B,MAAM,qBAAqB,CAAA;AAC5B,YAAY,EACR,sBAAsB,EACtB,kBAAkB,GACrB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAA;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACvD,YAAY,EACR,mBAAmB,EACnB,eAAe,EACf,oBAAoB,EACpB,wBAAwB,GAC3B,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,YAAY,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAGzE,cAAc,mBAAmB,CAAA"}
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
// (factories, STAGE_IDS, schemas, *_DEFAULTS) — including the
|
|
8
8
|
// per-extension canonicalization schema builders and the
|
|
9
9
|
// fallback-conclusion helper alternate pipelines reuse.
|
|
10
|
-
export { finalizeResponseV2, FINALIZE_V2_FAILURE_TEXTS, } from "./finalize-response-v2.js";
|
|
10
|
+
export { finalizeResponseV2, FINALIZE_V2_FAILURE_TEXTS, SOURCE_ANCHOR_NOTE_CODES, } from "./finalize-response-v2.js";
|
|
11
|
+
export { locateSourceAnchor, SOURCE_ANCHOR_CONTEXT_CHARS, } from "./source-anchors.js";
|
|
11
12
|
export { resolveLlmStageOptions } from "./resolve-llm-stage-options.js";
|
|
12
13
|
export { basicsExtension } from "./basics-extension.js";
|
|
13
14
|
export { deriveRoles } from "./role-derivation.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/extensions/pipelines/base/index.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,kDAAkD;AAClD,EAAE;AACF,mEAAmE;AACnE,wEAAwE;AACxE,qEAAqE;AACrE,8DAA8D;AAC9D,yDAAyD;AACzD,wDAAwD;AAExD,OAAO,EACH,kBAAkB,EAClB,yBAAyB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/extensions/pipelines/base/index.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,kDAAkD;AAClD,EAAE;AACF,mEAAmE;AACnE,wEAAwE;AACxE,qEAAqE;AACrE,8DAA8D;AAC9D,yDAAyD;AACzD,wDAAwD;AAExD,OAAO,EACH,kBAAkB,EAClB,yBAAyB,EACzB,wBAAwB,GAC3B,MAAM,2BAA2B,CAAA;AAElC,OAAO,EACH,kBAAkB,EAClB,2BAA2B,GAC9B,MAAM,qBAAqB,CAAA;AAK5B,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAA;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAOvD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAElD,sEAAsE;AACtE,qEAAqE;AACrE,cAAc,mBAAmB,CAAA"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/** Characters of surrounding input carried on either side of a quote. */
|
|
2
|
+
export declare const SOURCE_ANCHOR_CONTEXT_CHARS = 32;
|
|
3
|
+
/**
|
|
4
|
+
* A verified reference from an ingested entity back into the text the
|
|
5
|
+
* pipeline was given.
|
|
6
|
+
*
|
|
7
|
+
* `quote` is authoritative: it is the input's own text for the range,
|
|
8
|
+
* so a consumer that stores a differently-normalized copy of the
|
|
9
|
+
* document can re-locate it there rather than trusting these offsets.
|
|
10
|
+
* `prefix` / `suffix` disambiguate a quote that occurs more than once.
|
|
11
|
+
*
|
|
12
|
+
* Offsets are **JS string indices (UTF-16 code units)** into the
|
|
13
|
+
* pipeline input, which is why they say so in their names — a consumer
|
|
14
|
+
* counting code points must convert.
|
|
15
|
+
*/
|
|
16
|
+
export type TIngestionSourceAnchor = {
|
|
17
|
+
quote: string;
|
|
18
|
+
startUtf16: number;
|
|
19
|
+
endUtf16: number;
|
|
20
|
+
prefix: string;
|
|
21
|
+
suffix: string;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* The occurrence of `needle` at or after `fromUtf16` whose start sits
|
|
25
|
+
* nearest `hintUtf16`, or `undefined` when there is none.
|
|
26
|
+
*
|
|
27
|
+
* The same rule the anchor locator applies, exposed because the offsets
|
|
28
|
+
* the model reports for segments and mentions need it too: take the
|
|
29
|
+
* verifiable positions as the candidates and let the model's number pick
|
|
30
|
+
* between them, never the reverse.
|
|
31
|
+
*/
|
|
32
|
+
export declare function nearestOccurrence(haystack: string, needle: string, hintUtf16: number, fromUtf16?: number): number | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* A located anchor together with how many candidates it was chosen from.
|
|
35
|
+
*
|
|
36
|
+
* `occurrences > 1` means the quote is not unique in the input and the
|
|
37
|
+
* hint broke the tie. Callers surface that as a note rather than
|
|
38
|
+
* swallowing it: a silent tie-break is indistinguishable from a certain
|
|
39
|
+
* match, and the two deserve different trust.
|
|
40
|
+
*/
|
|
41
|
+
export type TSourceAnchorMatch = {
|
|
42
|
+
anchor: TIngestionSourceAnchor;
|
|
43
|
+
occurrences: number;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Locate `quote` in `input`, returning a verified match or `undefined`.
|
|
47
|
+
*
|
|
48
|
+
* `hintUtf16` selects among repeated occurrences — the occurrence whose
|
|
49
|
+
* start sits nearest the hint wins. It never affects *whether* a quote
|
|
50
|
+
* matches, so a wrong hint degrades to "picked another occurrence of the
|
|
51
|
+
* same text", never to a wrong span.
|
|
52
|
+
*
|
|
53
|
+
* The ladder is exact match, then whitespace-insensitive match, then
|
|
54
|
+
* both again with the quote's first character re-cased. Nothing
|
|
55
|
+
* approximate: a quote that still does not match yields `undefined`.
|
|
56
|
+
*/
|
|
57
|
+
export declare function locateSourceAnchor(input: string, quote: string, hintUtf16: number): TSourceAnchorMatch | undefined;
|
|
58
|
+
//# sourceMappingURL=source-anchors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-anchors.d.ts","sourceRoot":"","sources":["../../../../src/extensions/pipelines/base/source-anchors.ts"],"names":[],"mappings":"AAoBA,yEAAyE;AACzE,eAAO,MAAM,2BAA2B,KAAK,CAAA;AAE7C;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACjC,KAAK,EAAE,MAAM,CAAA;IACb,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;CACjB,CAAA;AAuBD;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC7B,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,SAAS,SAAI,GACd,MAAM,GAAG,SAAS,CAYpB;AA8ID;;;;;;;GAOG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC7B,MAAM,EAAE,sBAAsB,CAAA;IAC9B,WAAW,EAAE,MAAM,CAAA;CACtB,CAAA;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAC9B,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,GAClB,kBAAkB,GAAG,SAAS,CAwBhC"}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
// Locating a model-supplied quote in the pipeline input.
|
|
2
|
+
//
|
|
3
|
+
// The ingestion stages emit both quoted text and character offsets, but
|
|
4
|
+
// only the text is trustworthy. Two independent reasons:
|
|
5
|
+
//
|
|
6
|
+
// - Offset units are ambiguous. JS string indices are UTF-16 code
|
|
7
|
+
// units, so an emoji or much CJK counts as two, while a model told
|
|
8
|
+
// "character offsets" generally counts code points.
|
|
9
|
+
// - Claim-mention spans are *segment-relative* (see the
|
|
10
|
+
// `claim-mention-extraction` prompt), so an input-relative offset
|
|
11
|
+
// only exists after composing them with the segment's own span —
|
|
12
|
+
// arithmetic over two numbers the model produced independently.
|
|
13
|
+
//
|
|
14
|
+
// So the model's number is used only as a hint for choosing among
|
|
15
|
+
// occurrences of a quote that has already been found by text match.
|
|
16
|
+
// Every anchor returned here satisfies
|
|
17
|
+
// `input.slice(startUtf16, endUtf16) === quote`; a quote that cannot be
|
|
18
|
+
// located yields no anchor at all, never an anchor at an unverified
|
|
19
|
+
// offset.
|
|
20
|
+
/** Characters of surrounding input carried on either side of a quote. */
|
|
21
|
+
export const SOURCE_ANCHOR_CONTEXT_CHARS = 32;
|
|
22
|
+
/** Escape a literal string for use inside a regular expression. */
|
|
23
|
+
function escapeForRegExp(literal) {
|
|
24
|
+
return literal.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
25
|
+
}
|
|
26
|
+
/** Every start index at which `needle` occurs in `haystack`, from `fromUtf16`. */
|
|
27
|
+
function exactOccurrences(haystack, needle, fromUtf16 = 0) {
|
|
28
|
+
const starts = [];
|
|
29
|
+
let from = fromUtf16;
|
|
30
|
+
for (;;) {
|
|
31
|
+
const at = haystack.indexOf(needle, from);
|
|
32
|
+
if (at === -1)
|
|
33
|
+
return starts;
|
|
34
|
+
starts.push(at);
|
|
35
|
+
from = at + 1;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The occurrence of `needle` at or after `fromUtf16` whose start sits
|
|
40
|
+
* nearest `hintUtf16`, or `undefined` when there is none.
|
|
41
|
+
*
|
|
42
|
+
* The same rule the anchor locator applies, exposed because the offsets
|
|
43
|
+
* the model reports for segments and mentions need it too: take the
|
|
44
|
+
* verifiable positions as the candidates and let the model's number pick
|
|
45
|
+
* between them, never the reverse.
|
|
46
|
+
*/
|
|
47
|
+
export function nearestOccurrence(haystack, needle, hintUtf16, fromUtf16 = 0) {
|
|
48
|
+
if (needle.length === 0)
|
|
49
|
+
return undefined;
|
|
50
|
+
let best;
|
|
51
|
+
for (const at of exactOccurrences(haystack, needle, fromUtf16)) {
|
|
52
|
+
if (best === undefined ||
|
|
53
|
+
Math.abs(at - hintUtf16) < Math.abs(best - hintUtf16)) {
|
|
54
|
+
best = at;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return best;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Ranges matching `quote` when every whitespace run is treated as
|
|
61
|
+
* interchangeable. Covers the common case of a model flattening a line
|
|
62
|
+
* break to a space while copying.
|
|
63
|
+
*/
|
|
64
|
+
function whitespaceInsensitiveRanges(haystack, quote) {
|
|
65
|
+
const pattern = quote.split(/\s+/).map(escapeForRegExp).join("\\s+");
|
|
66
|
+
const ranges = [];
|
|
67
|
+
const matcher = new RegExp(pattern, "g");
|
|
68
|
+
for (const match of haystack.matchAll(matcher)) {
|
|
69
|
+
if (match.index === undefined)
|
|
70
|
+
continue;
|
|
71
|
+
ranges.push({ start: match.index, end: match.index + match[0].length });
|
|
72
|
+
}
|
|
73
|
+
return ranges;
|
|
74
|
+
}
|
|
75
|
+
/** Exact ranges for `quote`, falling back to whitespace-insensitive ones. */
|
|
76
|
+
function rangesFor(input, quote) {
|
|
77
|
+
const exact = exactOccurrences(input, quote).map((start) => ({
|
|
78
|
+
start,
|
|
79
|
+
end: start + quote.length,
|
|
80
|
+
}));
|
|
81
|
+
return exact.length > 0 ? exact : whitespaceInsensitiveRanges(input, quote);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The same text with its first character's case flipped, or `undefined`
|
|
85
|
+
* when that character has no other case.
|
|
86
|
+
*
|
|
87
|
+
* Models re-case the first character of a quoted span reflexively, in
|
|
88
|
+
* both directions: a span lifted from mid-sentence comes back with a
|
|
89
|
+
* capital, and one lifted from a sentence start comes back lower-cased
|
|
90
|
+
* to look like a fragment. Both were observed on the same document, on
|
|
91
|
+
* consecutive runs, under a prompt that forbids exactly this — so it is
|
|
92
|
+
* handled here rather than argued about in the prompt.
|
|
93
|
+
*
|
|
94
|
+
* Only the first character, and only after an exact search has already
|
|
95
|
+
* failed: every other character must still match, so this cannot invent
|
|
96
|
+
* a match the model did not essentially supply. The anchor is built from
|
|
97
|
+
* the range in the input, so what gets stored is the document's own
|
|
98
|
+
* casing, not the model's.
|
|
99
|
+
*/
|
|
100
|
+
function flipFirstCharacterCase(text) {
|
|
101
|
+
const first = text[0];
|
|
102
|
+
const lower = first.toLowerCase();
|
|
103
|
+
const upper = first.toUpperCase();
|
|
104
|
+
if (lower === upper)
|
|
105
|
+
return undefined;
|
|
106
|
+
return (first === lower ? upper : lower) + text.slice(1);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Drop a lone surrogate left at either edge by slicing on a code-unit
|
|
110
|
+
* boundary, shrinking the window by one unit rather than emitting an
|
|
111
|
+
* ill-formed string.
|
|
112
|
+
*
|
|
113
|
+
* Ill-formed here is not cosmetic. Postgres rejects an unpaired
|
|
114
|
+
* surrogate escape on insert into `json`/`jsonb`, so one emoji sitting
|
|
115
|
+
* on the context boundary would fail a consumer's whole persist
|
|
116
|
+
* transaction; and a `TextEncoder` round-trip silently substitutes
|
|
117
|
+
* U+FFFD, which breaks the re-locate path the context exists to serve.
|
|
118
|
+
* A slice of well-formed text can strand at most one surrogate per edge.
|
|
119
|
+
*/
|
|
120
|
+
function dropEdgeLoneSurrogates(context) {
|
|
121
|
+
let start = 0;
|
|
122
|
+
let end = context.length;
|
|
123
|
+
const first = context.charCodeAt(start);
|
|
124
|
+
if (first >= 0xdc00 && first <= 0xdfff)
|
|
125
|
+
start += 1;
|
|
126
|
+
const last = context.charCodeAt(end - 1);
|
|
127
|
+
if (last >= 0xd800 && last <= 0xdbff)
|
|
128
|
+
end -= 1;
|
|
129
|
+
return start === 0 && end === context.length
|
|
130
|
+
? context
|
|
131
|
+
: context.slice(start, end);
|
|
132
|
+
}
|
|
133
|
+
/** Build the anchor for an already-verified range. */
|
|
134
|
+
function buildAnchor(input, start, end) {
|
|
135
|
+
return {
|
|
136
|
+
quote: input.slice(start, end),
|
|
137
|
+
startUtf16: start,
|
|
138
|
+
endUtf16: end,
|
|
139
|
+
prefix: dropEdgeLoneSurrogates(input.slice(Math.max(0, start - SOURCE_ANCHOR_CONTEXT_CHARS), start)),
|
|
140
|
+
suffix: dropEdgeLoneSurrogates(input.slice(end, Math.min(input.length, end + SOURCE_ANCHOR_CONTEXT_CHARS))),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Whether index `at` falls between the halves of a surrogate pair.
|
|
145
|
+
*
|
|
146
|
+
* A range boundary there would put a lone surrogate in `quote`. That is
|
|
147
|
+
* reachable from an ill-formed model quote — a bare `\uD83D` escape is
|
|
148
|
+
* valid JSON and survives `JSON.parse`, and half a pair matches inside a
|
|
149
|
+
* whole one — and the resulting string fails a Postgres `json`/`jsonb`
|
|
150
|
+
* insert just as an ill-formed context string would.
|
|
151
|
+
*/
|
|
152
|
+
function splitsSurrogatePair(text, at) {
|
|
153
|
+
if (at <= 0 || at >= text.length)
|
|
154
|
+
return false;
|
|
155
|
+
const before = text.charCodeAt(at - 1);
|
|
156
|
+
const after = text.charCodeAt(at);
|
|
157
|
+
return (before >= 0xd800 &&
|
|
158
|
+
before <= 0xdbff &&
|
|
159
|
+
after >= 0xdc00 &&
|
|
160
|
+
after <= 0xdfff);
|
|
161
|
+
}
|
|
162
|
+
/** The range whose start sits nearest `hintUtf16`, or undefined if none. */
|
|
163
|
+
function nearestRange(ranges, hintUtf16) {
|
|
164
|
+
let best;
|
|
165
|
+
let bestDistance = Number.POSITIVE_INFINITY;
|
|
166
|
+
for (const range of ranges) {
|
|
167
|
+
const distance = Math.abs(range.start - hintUtf16);
|
|
168
|
+
if (distance < bestDistance) {
|
|
169
|
+
best = range;
|
|
170
|
+
bestDistance = distance;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return best;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Locate `quote` in `input`, returning a verified match or `undefined`.
|
|
177
|
+
*
|
|
178
|
+
* `hintUtf16` selects among repeated occurrences — the occurrence whose
|
|
179
|
+
* start sits nearest the hint wins. It never affects *whether* a quote
|
|
180
|
+
* matches, so a wrong hint degrades to "picked another occurrence of the
|
|
181
|
+
* same text", never to a wrong span.
|
|
182
|
+
*
|
|
183
|
+
* The ladder is exact match, then whitespace-insensitive match, then
|
|
184
|
+
* both again with the quote's first character re-cased. Nothing
|
|
185
|
+
* approximate: a quote that still does not match yields `undefined`.
|
|
186
|
+
*/
|
|
187
|
+
export function locateSourceAnchor(input, quote, hintUtf16) {
|
|
188
|
+
const trimmed = quote.trim();
|
|
189
|
+
if (trimmed.length === 0)
|
|
190
|
+
return undefined;
|
|
191
|
+
let candidates = rangesFor(input, trimmed);
|
|
192
|
+
if (candidates.length === 0) {
|
|
193
|
+
const recased = flipFirstCharacterCase(trimmed);
|
|
194
|
+
if (recased !== undefined)
|
|
195
|
+
candidates = rangesFor(input, recased);
|
|
196
|
+
}
|
|
197
|
+
// Discarding the range, rather than trimming the quote, is what
|
|
198
|
+
// keeps `input.slice(start, end) === quote` true.
|
|
199
|
+
const ranges = candidates.filter((range) => !splitsSurrogatePair(input, range.start) &&
|
|
200
|
+
!splitsSurrogatePair(input, range.end));
|
|
201
|
+
const range = nearestRange(ranges, hintUtf16);
|
|
202
|
+
return range === undefined
|
|
203
|
+
? undefined
|
|
204
|
+
: {
|
|
205
|
+
anchor: buildAnchor(input, range.start, range.end),
|
|
206
|
+
occurrences: ranges.length,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
//# sourceMappingURL=source-anchors.js.map
|