@proposit/proposit-core 5.1.0 → 5.2.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.
Files changed (118) hide show
  1. package/dist/cli/builder-repl.js +1 -1
  2. package/dist/cli/builder-repl.js.map +1 -1
  3. package/dist/extensions/chat-completions/structured-output.d.ts.map +1 -1
  4. package/dist/extensions/chat-completions/structured-output.js +5 -8
  5. package/dist/extensions/chat-completions/structured-output.js.map +1 -1
  6. package/dist/extensions/openai/openai-retrieval.d.ts.map +1 -1
  7. package/dist/extensions/openai/openai-retrieval.js +4 -2
  8. package/dist/extensions/openai/openai-retrieval.js.map +1 -1
  9. package/dist/extensions/openai/openai-tools.d.ts +8 -1
  10. package/dist/extensions/openai/openai-tools.d.ts.map +1 -1
  11. package/dist/extensions/openai/openai-tools.js +10 -0
  12. package/dist/extensions/openai/openai-tools.js.map +1 -1
  13. package/dist/extensions/openai/provider.d.ts.map +1 -1
  14. package/dist/extensions/openai/provider.js +5 -3
  15. package/dist/extensions/openai/provider.js.map +1 -1
  16. package/dist/extensions/openai/structured-output.d.ts.map +1 -1
  17. package/dist/extensions/openai/structured-output.js +7 -8
  18. package/dist/extensions/openai/structured-output.js.map +1 -1
  19. package/dist/extensions/openai/types.d.ts +2 -1
  20. package/dist/extensions/openai/types.d.ts.map +1 -1
  21. package/dist/extensions/openai/types.js.map +1 -1
  22. package/dist/extensions/pipelines/base/finalize-response-v2.d.ts +9 -6
  23. package/dist/extensions/pipelines/base/finalize-response-v2.d.ts.map +1 -1
  24. package/dist/extensions/pipelines/base/finalize-response-v2.js +106 -28
  25. package/dist/extensions/pipelines/base/finalize-response-v2.js.map +1 -1
  26. package/dist/extensions/pipelines/base/index.d.ts +1 -1
  27. package/dist/extensions/pipelines/base/index.d.ts.map +1 -1
  28. package/dist/extensions/pipelines/base/index.js.map +1 -1
  29. package/dist/extensions/pipelines/base/source-anchors.d.ts +33 -2
  30. package/dist/extensions/pipelines/base/source-anchors.d.ts.map +1 -1
  31. package/dist/extensions/pipelines/base/source-anchors.js +191 -13
  32. package/dist/extensions/pipelines/base/source-anchors.js.map +1 -1
  33. package/dist/extensions/pipelines/base/stages/axiom-indicator-detection.d.ts +1 -1
  34. package/dist/extensions/pipelines/base/stages/axiom-indicator-detection.d.ts.map +1 -1
  35. package/dist/extensions/pipelines/base/stages/axiom-indicator-detection.js +1 -1
  36. package/dist/extensions/pipelines/base/stages/axiom-indicator-detection.js.map +1 -1
  37. package/dist/extensions/pipelines/base/stages/citation-source-detection.d.ts +1 -1
  38. package/dist/extensions/pipelines/base/stages/citation-source-detection.d.ts.map +1 -1
  39. package/dist/extensions/pipelines/base/stages/citation-source-detection.js +1 -1
  40. package/dist/extensions/pipelines/base/stages/citation-source-detection.js.map +1 -1
  41. package/dist/extensions/pipelines/base/stages/claim-canonicalization.d.ts +3 -2
  42. package/dist/extensions/pipelines/base/stages/claim-canonicalization.d.ts.map +1 -1
  43. package/dist/extensions/pipelines/base/stages/claim-canonicalization.js +2 -2
  44. package/dist/extensions/pipelines/base/stages/claim-canonicalization.js.map +1 -1
  45. package/dist/extensions/pipelines/base/stages/claim-mention-extraction.d.ts +1 -1
  46. package/dist/extensions/pipelines/base/stages/claim-mention-extraction.d.ts.map +1 -1
  47. package/dist/extensions/pipelines/base/stages/claim-mention-extraction.js +1 -1
  48. package/dist/extensions/pipelines/base/stages/claim-mention-extraction.js.map +1 -1
  49. package/dist/extensions/pipelines/base/stages/claim-type-classification.d.ts +1 -1
  50. package/dist/extensions/pipelines/base/stages/claim-type-classification.d.ts.map +1 -1
  51. package/dist/extensions/pipelines/base/stages/claim-type-classification.js +1 -1
  52. package/dist/extensions/pipelines/base/stages/claim-type-classification.js.map +1 -1
  53. package/dist/extensions/pipelines/base/stages/conclusion-selection.d.ts +26 -3
  54. package/dist/extensions/pipelines/base/stages/conclusion-selection.d.ts.map +1 -1
  55. package/dist/extensions/pipelines/base/stages/conclusion-selection.js +40 -2
  56. package/dist/extensions/pipelines/base/stages/conclusion-selection.js.map +1 -1
  57. package/dist/extensions/pipelines/base/stages/index.d.ts +1 -1
  58. package/dist/extensions/pipelines/base/stages/index.d.ts.map +1 -1
  59. package/dist/extensions/pipelines/base/stages/index.js +1 -1
  60. package/dist/extensions/pipelines/base/stages/index.js.map +1 -1
  61. package/dist/extensions/pipelines/base/stages/relation-extraction.d.ts +4 -3
  62. package/dist/extensions/pipelines/base/stages/relation-extraction.d.ts.map +1 -1
  63. package/dist/extensions/pipelines/base/stages/relation-extraction.js +6 -4
  64. package/dist/extensions/pipelines/base/stages/relation-extraction.js.map +1 -1
  65. package/dist/extensions/pipelines/base/stages/schemas.js +2 -2
  66. package/dist/extensions/pipelines/base/stages/schemas.js.map +1 -1
  67. package/dist/extensions/pipelines/base/stages/segmentation.d.ts +1 -1
  68. package/dist/extensions/pipelines/base/stages/segmentation.d.ts.map +1 -1
  69. package/dist/extensions/pipelines/base/stages/segmentation.js +1 -1
  70. package/dist/extensions/pipelines/base/stages/segmentation.js.map +1 -1
  71. package/dist/extensions/pipelines/base/types.d.ts +1 -1
  72. package/dist/extensions/pipelines/ingestion/scribe/extract-stage.d.ts +61 -10
  73. package/dist/extensions/pipelines/ingestion/scribe/extract-stage.d.ts.map +1 -1
  74. package/dist/extensions/pipelines/ingestion/scribe/extract-stage.js +203 -14
  75. package/dist/extensions/pipelines/ingestion/scribe/extract-stage.js.map +1 -1
  76. package/dist/extensions/pipelines/ingestion/scribe/schemas.d.ts +15 -2
  77. package/dist/extensions/pipelines/ingestion/scribe/schemas.d.ts.map +1 -1
  78. package/dist/extensions/pipelines/ingestion/scribe/schemas.js +14 -2
  79. package/dist/extensions/pipelines/ingestion/scribe/schemas.js.map +1 -1
  80. package/dist/extensions/pipelines/ingestion/scribe/scribe.js +2 -2
  81. package/dist/extensions/pipelines/ingestion/scribe/scribe.js.map +1 -1
  82. package/dist/extensions/pipelines/ingestion/scribe/source-attachment.d.ts +29 -0
  83. package/dist/extensions/pipelines/ingestion/scribe/source-attachment.d.ts.map +1 -0
  84. package/dist/extensions/pipelines/ingestion/scribe/source-attachment.js +200 -0
  85. package/dist/extensions/pipelines/ingestion/scribe/source-attachment.js.map +1 -0
  86. package/dist/extensions/pipelines/ingestion/scribe/structure-stage.d.ts +5 -3
  87. package/dist/extensions/pipelines/ingestion/scribe/structure-stage.d.ts.map +1 -1
  88. package/dist/extensions/pipelines/ingestion/scribe/structure-stage.js +42 -14
  89. package/dist/extensions/pipelines/ingestion/scribe/structure-stage.js.map +1 -1
  90. package/dist/extensions/structured-output/length-hint.d.ts +4 -4
  91. package/dist/extensions/structured-output/length-hint.d.ts.map +1 -1
  92. package/dist/extensions/structured-output/length-hint.js +17 -21
  93. package/dist/extensions/structured-output/length-hint.js.map +1 -1
  94. package/dist/lib/core/parser/formula-gen.js +309 -46
  95. package/dist/lib/llm/types.d.ts +8 -2
  96. package/dist/lib/llm/types.d.ts.map +1 -1
  97. package/dist/lib/llm/types.js.map +1 -1
  98. package/dist/lib/parsing/clamp-max-lengths.d.ts +11 -1
  99. package/dist/lib/parsing/clamp-max-lengths.d.ts.map +1 -1
  100. package/dist/lib/parsing/clamp-max-lengths.js +23 -2
  101. package/dist/lib/parsing/clamp-max-lengths.js.map +1 -1
  102. package/dist/lib/pipelines/debug-log.js +1 -1
  103. package/dist/lib/pipelines/debug-log.js.map +1 -1
  104. package/dist/lib/pipelines/index.d.ts +1 -1
  105. package/dist/lib/pipelines/index.d.ts.map +1 -1
  106. package/dist/lib/pipelines/index.js.map +1 -1
  107. package/dist/lib/pipelines/llm-stage-helpers.d.ts +22 -1
  108. package/dist/lib/pipelines/llm-stage-helpers.d.ts.map +1 -1
  109. package/dist/lib/pipelines/llm-stage-helpers.js +26 -13
  110. package/dist/lib/pipelines/llm-stage-helpers.js.map +1 -1
  111. package/dist/lib/pipelines/single-stage.d.ts +9 -1
  112. package/dist/lib/pipelines/single-stage.d.ts.map +1 -1
  113. package/dist/lib/pipelines/single-stage.js +14 -3
  114. package/dist/lib/pipelines/single-stage.js.map +1 -1
  115. package/dist/lib/pipelines/stage-helpers.d.ts +1 -1
  116. package/dist/lib/pipelines/stage-helpers.d.ts.map +1 -1
  117. package/dist/lib/pipelines/stage-helpers.js.map +1 -1
  118. package/package.json +1 -1
@@ -0,0 +1,200 @@
1
+ // Attaching scribe's source claims — citations and axioms — to the claims
2
+ // they support.
3
+ //
4
+ // A source becomes derivation backing only as the antecedent of an
5
+ // inference relation (`sortInferenceRelations`). `structure` is the only
6
+ // stage that emits relations, and it is shown the claim list, never the
7
+ // text, so it cannot tell which claim a link or an appeal to a principle
8
+ // sits beside — and it may leave a source out altogether. A source
9
+ // attached to nothing backs nothing and is lost downstream.
10
+ //
11
+ // So each source gets extra single-antecedent relations `[source] →
12
+ // supported`: first to every normal claim `extract` named for it (the
13
+ // one stage that reads the text); failing that, when `structure` did not
14
+ // use it either, to a claim chosen by where the mentions sit — the
15
+ // normal claim whose mention overlaps the source's most, else the nearest
16
+ // normal claim in the same sentence, else the nearest normal claim whose
17
+ // mention ends before the source's begins. A relation
18
+ // with only a source antecedent compiles to backing and no freeform
19
+ // premise, so nothing else about the argument changes.
20
+ //
21
+ // An axiom is never attached to a claim a citation backs: grammar rule D-3
22
+ // forbids one derivation mixing the two. Citations are attached first and
23
+ // the axiom is dropped with a warning.
24
+ import { locateSourceAnchor } from "../../base/source-anchors.js";
25
+ import { sortInferenceRelations } from "../../base/stages/formula-compilation.js";
26
+ export const SOURCE_ATTACHMENT_FAILURE_CODES = {
27
+ invalidSource: "SOURCE_ATTACHMENT_INVALID_SOURCE",
28
+ invalidTarget: "SOURCE_ATTACHMENT_INVALID_TARGET",
29
+ mixed: "SOURCE_ATTACHMENT_MIXED",
30
+ unattached: "SOURCE_ATTACHMENT_UNATTACHED",
31
+ };
32
+ /**
33
+ * Where a mention sits in the input: its quote located in the text when
34
+ * it can be, else the offsets the model reported.
35
+ */
36
+ function mentionRange(mention, inputText) {
37
+ const match = locateSourceAnchor(inputText, mention.text, mention.span.start);
38
+ return match === undefined
39
+ ? mention.span
40
+ : { start: match.anchor.startUtf16, end: match.anchor.endUtf16 };
41
+ }
42
+ function overlapLength(a, b) {
43
+ return Math.max(0, Math.min(a.end, b.end) - Math.max(a.start, b.start));
44
+ }
45
+ // A sentence ends at a terminator followed by whitespace (closing quotes and
46
+ // brackets allowed in between), or at a line break. The dots inside a URL
47
+ // are followed by more of the URL, so they never count.
48
+ const SENTENCE_BREAK = /[.!?]["')\]]*\s|\n/;
49
+ /**
50
+ * The normal claim a source's mentions belong to, if any: the one whose
51
+ * mention overlaps a source mention most; else the nearest one in the same
52
+ * sentence, on either side ("According to <link>, <claim>."); else the
53
+ * nearest one that ends before the source begins.
54
+ */
55
+ function claimByPosition(sourceRanges, normalRanges, inputText) {
56
+ let overlapping;
57
+ let sameSentence;
58
+ let preceding;
59
+ for (const claim of normalRanges) {
60
+ for (const range of claim.ranges) {
61
+ for (const source of sourceRanges) {
62
+ const overlap = overlapLength(range, source);
63
+ if (overlap > 0) {
64
+ if (overlapping === undefined ||
65
+ overlap > overlapping.overlap)
66
+ overlapping = { miniId: claim.miniId, overlap };
67
+ continue;
68
+ }
69
+ const [gapStart, gapEnd] = range.end <= source.start
70
+ ? [range.end, source.start]
71
+ : [source.end, range.start];
72
+ const gap = gapEnd - gapStart;
73
+ // From the earlier mention's last character, which is where
74
+ // a sentence it closes has its terminator.
75
+ const between = inputText.slice(Math.max(0, gapStart - 1), gapEnd);
76
+ if (!SENTENCE_BREAK.test(between) &&
77
+ (sameSentence === undefined || gap < sameSentence.gap))
78
+ sameSentence = { miniId: claim.miniId, gap };
79
+ if (range.end <= source.start &&
80
+ (preceding === undefined || range.end > preceding.end))
81
+ preceding = { miniId: claim.miniId, end: range.end };
82
+ }
83
+ }
84
+ }
85
+ return (overlapping ?? sameSentence ?? preceding)?.miniId;
86
+ }
87
+ /**
88
+ * The relations that attach each citation and axiomatic claim to what it
89
+ * supports, to be published alongside `structure`'s own. See the file
90
+ * comment for the order in which a target is chosen.
91
+ */
92
+ export function buildSourceRelations(args) {
93
+ const claims = args.extract?.canonicalClaims ?? [];
94
+ const mentionById = new Map((args.extract?.mentions ?? []).map((m) => [m.mentionId, m]));
95
+ const rangesOf = (mentionIds) => mentionIds.flatMap((id) => {
96
+ const mention = mentionById.get(id);
97
+ return mention === undefined
98
+ ? []
99
+ : [mentionRange(mention, args.inputText)];
100
+ });
101
+ const normalRanges = claims
102
+ .filter((c) => args.typeByMiniId.get(c.miniId) === "normal")
103
+ .map((c) => ({ miniId: c.miniId, ranges: rangesOf(c.mentionIds) }));
104
+ // Read off what the compiler will make of structure's relations, so a
105
+ // relation it drops (an unknown claim id, say) attaches nothing here
106
+ // either. Its warnings are the compiler's to report, not this stage's.
107
+ const structureBacking = sortInferenceRelations({
108
+ relations: [...args.structureRelations],
109
+ typeByClaimMiniId: args.typeByMiniId,
110
+ }).derivationBacking;
111
+ const attachedByStructure = new Set([...structureBacking.values()].flat());
112
+ // Claims a citation backs. An axiom may not join them: one derivation
113
+ // mixing axioms and citations breaks grammar rule D-3.
114
+ const backedByCitation = new Set([...structureBacking]
115
+ .filter(([, supporters]) => supporters.some((id) => args.typeByMiniId.get(id) === "citation"))
116
+ .map(([consequent]) => consequent));
117
+ const relations = [];
118
+ const attach = (sourceMiniId, sourceType, supportedMiniId) => {
119
+ if (sourceType === "axiomatic" &&
120
+ backedByCitation.has(supportedMiniId)) {
121
+ args.addFailure({
122
+ code: SOURCE_ATTACHMENT_FAILURE_CODES.mixed,
123
+ message: `Axiom "${sourceMiniId}" supports "${supportedMiniId}", which a citation already backs; one claim cannot be backed by both, so the axiom was not attached.`,
124
+ severity: "warning",
125
+ context: { sourceMiniId, supportedMiniId },
126
+ });
127
+ return;
128
+ }
129
+ if (sourceType === "citation")
130
+ backedByCitation.add(supportedMiniId);
131
+ relations.push({
132
+ relationId: `source-${sourceMiniId}-${supportedMiniId}`,
133
+ type: "inference",
134
+ antecedents: [sourceMiniId],
135
+ consequent: supportedMiniId,
136
+ title: "",
137
+ evidence: { segmentIds: [], quote: "" },
138
+ });
139
+ };
140
+ for (const entry of args.extract?.sourceSupport ?? []) {
141
+ const sourceType = args.typeByMiniId.get(entry.sourceMiniId);
142
+ if (sourceType === "citation" || sourceType === "axiomatic")
143
+ continue;
144
+ args.addFailure({
145
+ code: SOURCE_ATTACHMENT_FAILURE_CODES.invalidSource,
146
+ message: `"${entry.sourceMiniId}" was paired as a source for "${entry.supportedMiniId}", but it is ${sourceType === undefined ? "not a known claim" : `a ${sourceType} claim`}; only a citation or axiomatic claim is a source. Ignoring the pairing.`,
147
+ severity: "warning",
148
+ context: {
149
+ sourceMiniId: entry.sourceMiniId,
150
+ supportedMiniId: entry.supportedMiniId,
151
+ },
152
+ });
153
+ }
154
+ // Citations first, so an axiom sees every claim a citation backs.
155
+ for (const sourceType of ["citation", "axiomatic"]) {
156
+ const label = sourceType === "citation" ? "Source" : "Axiom";
157
+ for (const claim of claims) {
158
+ if (args.typeByMiniId.get(claim.miniId) !== sourceType)
159
+ continue;
160
+ const sourceMiniId = claim.miniId;
161
+ const named = new Set();
162
+ for (const entry of args.extract?.sourceSupport ?? []) {
163
+ if (entry.sourceMiniId !== sourceMiniId)
164
+ continue;
165
+ const targetType = args.typeByMiniId.get(entry.supportedMiniId);
166
+ if (targetType !== "normal") {
167
+ args.addFailure({
168
+ code: SOURCE_ATTACHMENT_FAILURE_CODES.invalidTarget,
169
+ message: `${label} "${sourceMiniId}" was said to support "${entry.supportedMiniId}", which is ${targetType === undefined ? "not a known claim" : `a ${targetType} claim`}; a ${label.toLowerCase()} can only support a normal claim.`,
170
+ severity: "warning",
171
+ context: {
172
+ sourceMiniId,
173
+ supportedMiniId: entry.supportedMiniId,
174
+ },
175
+ });
176
+ continue;
177
+ }
178
+ named.add(entry.supportedMiniId);
179
+ }
180
+ for (const supportedMiniId of named) {
181
+ attach(sourceMiniId, sourceType, supportedMiniId);
182
+ }
183
+ if (named.size > 0 || attachedByStructure.has(sourceMiniId))
184
+ continue;
185
+ const supportedMiniId = claimByPosition(rangesOf(claim.mentionIds), normalRanges, args.inputText);
186
+ if (supportedMiniId === undefined) {
187
+ args.addFailure({
188
+ code: SOURCE_ATTACHMENT_FAILURE_CODES.unattached,
189
+ message: `${label} "${sourceMiniId}" supports no claim: none was named for it, and no normal claim is stated where it appears or before it.`,
190
+ severity: "warning",
191
+ context: { sourceMiniId },
192
+ });
193
+ continue;
194
+ }
195
+ attach(sourceMiniId, sourceType, supportedMiniId);
196
+ }
197
+ }
198
+ return relations;
199
+ }
200
+ //# sourceMappingURL=source-attachment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source-attachment.js","sourceRoot":"","sources":["../../../../../src/extensions/pipelines/ingestion/scribe/source-attachment.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,gBAAgB;AAChB,EAAE;AACF,mEAAmE;AACnE,yEAAyE;AACzE,wEAAwE;AACxE,yEAAyE;AACzE,mEAAmE;AACnE,4DAA4D;AAC5D,EAAE;AACF,oEAAoE;AACpE,sEAAsE;AACtE,yEAAyE;AACzE,mEAAmE;AACnE,0EAA0E;AAC1E,yEAAyE;AACzE,sDAAsD;AACtD,oEAAoE;AACpE,uDAAuD;AACvD,EAAE;AACF,2EAA2E;AAC3E,0EAA0E;AAC1E,uCAAuC;AAOvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAA;AACjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0CAA0C,CAAA;AAGjF,MAAM,CAAC,MAAM,+BAA+B,GAAG;IAC3C,aAAa,EAAE,kCAAkC;IACjD,aAAa,EAAE,kCAAkC;IACjD,KAAK,EAAE,yBAAyB;IAChC,UAAU,EAAE,8BAA8B;CACpC,CAAA;AAaV;;;GAGG;AACH,SAAS,YAAY,CAAC,OAAsB,EAAE,SAAiB;IAC3D,MAAM,KAAK,GAAG,kBAAkB,CAC5B,SAAS,EACT,OAAO,CAAC,IAAI,EACZ,OAAO,CAAC,IAAI,CAAC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AAK,YAAY,0BAA0B,KAAK,CAAC,eAAe,eAAe,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,KAAK,UAAU,QAAQ,OAAO,KAAK,CAAC,WAAW,EAAE,mCAAmC;wBACrO,QAAQ,EAAE,SAAS;wBACnB,OAAO,EAAE;4BACL,YAAY;4BACZ,eAAe,EAAE,KAAK,CAAC,eAAe;yBACzC;qBACJ,CAAC,CAAA;oBACF,SAAQ;gBACZ,CAAC;gBACD,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,eAAe,CAAC,CAAA;YACpC,CAAC;YACD,KAAK,MAAM,eAAe,IAAI,KAAK,EAAE,CAAC;gBAClC,MAAM,CAAC,YAAY,EAAE,UAAU,EAAE,eAAe,CAAC,CAAA;YACrD,CAAC;YACD,IAAI,KAAK,CAAC,IAAI,GAAG,CAAC,IAAI,mBAAmB,CAAC,GAAG,CAAC,YAAY,CAAC;gBACvD,SAAQ;YAEZ,MAAM,eAAe,GAAG,eAAe,CACnC,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,EAC1B,YAAY,EACZ,IAAI,CAAC,SAAS,CACjB,CAAA;YACD,IAAI,eAAe,KAAK,SAAS,EAAE,CAAC;gBAChC,IAAI,CAAC,UAAU,CAAC;oBACZ,IAAI,EAAE,+BAA+B,CAAC,UAAU;oBAChD,OAAO,EAAE,GAAG,KAAK,KAAK,YAAY,0GAA0G;oBAC5I,QAAQ,EAAE,SAAS;oBACnB,OAAO,EAAE,EAAE,YAAY,EAAE;iBAC5B,CAAC,CAAA;gBACF,SAAQ;YACZ,CAAC;YACD,MAAM,CAAC,YAAY,EAAE,UAAU,EAAE,eAAe,CAAC,CAAA;QACrD,CAAC;IACL,CAAC;IACD,OAAO,SAAS,CAAA;AACpB,CAAC"}
@@ -2,10 +2,10 @@ import type { TStage } from "../../../../lib/pipelines/types.js";
2
2
  import { type TConclusionSelectionOutput, type TRelationExtractionOutput } from "../../base/stages/index.js";
3
3
  import type { TLlmStageOptionsOverride } from "../../base/types.js";
4
4
  import { type TScribeStructureOutput } from "./schemas.js";
5
- export declare const STRUCTURE_MODEL = "gpt-5.4-mini";
5
+ export declare const STRUCTURE_MODEL = "gpt-6-sol";
6
6
  /** Internal default knobs for scribe's `structure` stage. */
7
7
  export declare const STRUCTURE_STAGE_DEFAULTS: TLlmStageOptionsOverride;
8
- export declare const STRUCTURE_SYSTEM_PROMPT = "You read a canonical claim set \u2014 each claim's id, type, and content fields (title/body) \u2014 and emit the argument's structure.\n\nEmit:\n- `relations` \u2014 the inference edges between claims. Each relation: a stable `relationId` (r1, r2, ...), a `type` of \"inference\", an `antecedents` array of the claim miniIds whose conjunction implies the consequent (one or more; citation- or axiomatic-typed claims may appear here, but never as the consequent), a single `consequent` claim miniId, a `title`, and an `evidence` object, which is always exactly { segmentIds: [], quote: \"\" } \u2014 you are shown the claims, not the text they came from, so you have nothing to quote.\n- each relation's `title` \u2014 a short noun phrase naming what that step DOES in the argument \u2014 the inferential move, not the proposition. Do not restate the consequent: that claim's own title is already shown directly beneath this one. Aim for under 60 characters. Examples: \"Limits of the crowd's power\", \"Residence as tacit consent\", \"Principle over survival\".\n- `conclusionCandidates` \u2014 the claim miniIds that could be the argument's conclusion, ordered by DECREASING confidence (best first). The conclusion is the claim other claims support but that supports nothing further. Never list a citation- or axiomatic-typed claim. Return an empty array only when there is no argument structure.\n- `conclusionTitle` \u2014 for your FIRST candidate only: a short noun phrase naming what the concluding step DOES in the argument \u2014 the inferential move, not the proposition. Do not restate the consequent: that claim's own title is already shown directly beneath this one. Aim for under 60 characters. Return an empty string when `conclusionCandidates` is empty.\n- `rationale` \u2014 one sentence explaining your best pick (or why none qualifies).\n\nOutput ONLY the schema-shaped object. No prose.";
8
+ export declare const STRUCTURE_SYSTEM_PROMPT = "You read a canonical claim set \u2014 each claim's id, type, and content fields (title/body) \u2014 and emit the argument's structure.\n\nEmit:\n- `relations` \u2014 the inference edges between claims. Each relation: a stable `relationId` (r1, r2, ...), a `type` of \"inference\", an `antecedents` array of the claim miniIds whose conjunction implies the consequent (one or more; citation- or axiomatic-typed claims may appear here, but never as the consequent), a single `consequent` claim miniId, a `title`, and an `evidence` object, which is always exactly { segmentIds: [], quote: \"\" } \u2014 you are shown the claims, not the text they came from, so you have nothing to quote.\n- each relation's `title` \u2014 a short noun phrase naming what that step DOES in the argument \u2014 the inferential move, not the proposition. Do not restate the consequent: that claim's own title is already shown directly beneath this one. Aim for under 60 characters. Examples: \"Limits of the crowd's power\", \"Residence as tacit consent\", \"Principle over survival\". Every relation's title must differ from every other relation's \u2014 two steps never share a name.\n- `conclusionCandidates` \u2014 the claim miniIds that could be the argument's conclusion, ordered by DECREASING confidence (best first). The conclusion is the claim other claims support but that supports nothing further. Never list a citation- or axiomatic-typed claim.\n- `conclusionTitle` \u2014 for your FIRST candidate only: a short noun phrase naming what the concluding step DOES in the argument \u2014 the inferential move, not the proposition. Do not restate the consequent: that claim's own title is already shown directly beneath this one. Aim for under 60 characters. It must differ from every relation's `title` \u2014 the step that reaches the conclusion already has its own. Return an empty string when `conclusionCandidates` is empty.\n- `rationale` \u2014 one sentence explaining your best pick (or why none qualifies).\n\nEmit the relations and conclusion the author actually argues. An argument with at least two normal-typed claims has at least one relation and one conclusion candidate, so look for them before concluding there are none. Never invent support the author does not give: if the claims genuinely do not connect, return `relations` and `conclusionCandidates` empty.\n\nOutput ONLY the schema-shaped object. No prose.";
9
9
  /**
10
10
  * Build scribe's `structure` LLM stage. Depends on the canonicalization
11
11
  * + classification slots (populated by `extract`'s adapters) so the
@@ -15,7 +15,9 @@ export declare const STRUCTURE_SYSTEM_PROMPT = "You read a canonical claim set \
15
15
  export declare function createStructureStage(options?: TLlmStageOptionsOverride): TStage<TScribeStructureOutput>;
16
16
  /**
17
17
  * Adapter — republish `structure`'s relations under the
18
- * relation-extraction slot.
18
+ * relation-extraction slot, together with the relations that attach each
19
+ * source claim to the claim it supports (`buildSourceRelations`), read
20
+ * off the same settled citations the canonicalization slot carries.
19
21
  */
20
22
  export declare const structureRelationAdapterStage: TStage<TRelationExtractionOutput>;
21
23
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"structure-stage.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/pipelines/ingestion/scribe/structure-stage.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,oCAAoC,CAAA;AAC/E,OAAO,EAQH,KAAK,0BAA0B,EAC/B,KAAK,yBAAyB,EACjC,MAAM,4BAA4B,CAAA;AACnC,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AACnE,OAAO,EAEH,KAAK,sBAAsB,EAC9B,MAAM,cAAc,CAAA;AAErB,eAAO,MAAM,eAAe,iBAAiB,CAAA;AAE7C,6DAA6D;AAC7D,eAAO,MAAM,wBAAwB,EAAE,wBAEtC,CAAA;AAED,eAAO,MAAM,uBAAuB,q3DASY,CAAA;AAwChD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAChC,OAAO,CAAC,EAAE,wBAAwB,GACnC,MAAM,CAAC,sBAAsB,CAAC,CAchC;AAED;;;GAGG;AACH,eAAO,MAAM,6BAA6B,EAAE,MAAM,CAAC,yBAAyB,CAUtE,CAAA;AAEN;;;;;;;GAOG;AACH,eAAO,MAAM,+BAA+B,EAAE,MAAM,CAAC,0BAA0B,CA4DzE,CAAA"}
1
+ {"version":3,"file":"structure-stage.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/pipelines/ingestion/scribe/structure-stage.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,oCAAoC,CAAA;AAC/E,OAAO,EASH,KAAK,0BAA0B,EAC/B,KAAK,yBAAyB,EACjC,MAAM,4BAA4B,CAAA;AAEnC,OAAO,KAAK,EAER,wBAAwB,EAC3B,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAGH,KAAK,sBAAsB,EAC9B,MAAM,cAAc,CAAA;AAIrB,eAAO,MAAM,eAAe,cAAc,CAAA;AAE1C,6DAA6D;AAC7D,eAAO,MAAM,wBAAwB,EAAE,wBAEtC,CAAA;AAED,eAAO,MAAM,uBAAuB,i3EAWY,CAAA;AAwChD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAChC,OAAO,CAAC,EAAE,wBAAwB,GACnC,MAAM,CAAC,sBAAsB,CAAC,CAehC;AAED;;;;;GAKG;AACH,eAAO,MAAM,6BAA6B,EAAE,MAAM,CAAC,yBAAyB,CAoCtE,CAAA;AAEN;;;;;;;GAOG;AACH,eAAO,MAAM,+BAA+B,EAAE,MAAM,CAAC,0BAA0B,CA4DzE,CAAA"}
@@ -13,9 +13,12 @@
13
13
  // read, not the raw model candidates.
14
14
  import { llmStage } from "../../../../lib/pipelines/stage-helpers.js";
15
15
  import { deterministicStage } from "../../../../lib/pipelines/stage-helpers.js";
16
- import { STAGE_IDS, RelationExtractionOutputSchema, ConclusionSelectionOutputSchema, selectFallbackConclusion, CONCLUSION_SELECTION_NO_CONCLUSION_FAILURE_CODE, } from "../../base/stages/index.js";
16
+ import { STAGE_IDS, RelationExtractionOutputSchema, ConclusionSelectionOutputSchema, checkArgumentStructure, selectFallbackConclusion, CONCLUSION_SELECTION_NO_CONCLUSION_FAILURE_CODE, } from "../../base/stages/index.js";
17
+ import { resolveClaimTypes } from "../../base/stages/formula-compilation.js";
17
18
  import { ScribeStructureOutputSchema, } from "./schemas.js";
18
- export const STRUCTURE_MODEL = "gpt-5.4-mini";
19
+ import { buildSourceRelations } from "./source-attachment.js";
20
+ import { settleCitations } from "./extract-stage.js";
21
+ export const STRUCTURE_MODEL = "gpt-6-sol";
19
22
  /** Internal default knobs for scribe's `structure` stage. */
20
23
  export const STRUCTURE_STAGE_DEFAULTS = {
21
24
  model: STRUCTURE_MODEL,
@@ -24,11 +27,13 @@ export const STRUCTURE_SYSTEM_PROMPT = `You read a canonical claim set — each
24
27
 
25
28
  Emit:
26
29
  - \`relations\` — the inference edges between claims. Each relation: a stable \`relationId\` (r1, r2, ...), a \`type\` of "inference", an \`antecedents\` array of the claim miniIds whose conjunction implies the consequent (one or more; citation- or axiomatic-typed claims may appear here, but never as the consequent), a single \`consequent\` claim miniId, a \`title\`, and an \`evidence\` object, which is always exactly { segmentIds: [], quote: "" } — you are shown the claims, not the text they came from, so you have nothing to quote.
27
- - each relation's \`title\` — a short noun phrase naming what that step DOES in the argument — the inferential move, not the proposition. Do not restate the consequent: that claim's own title is already shown directly beneath this one. Aim for under 60 characters. Examples: "Limits of the crowd's power", "Residence as tacit consent", "Principle over survival".
28
- - \`conclusionCandidates\` — the claim miniIds that could be the argument's conclusion, ordered by DECREASING confidence (best first). The conclusion is the claim other claims support but that supports nothing further. Never list a citation- or axiomatic-typed claim. Return an empty array only when there is no argument structure.
29
- - \`conclusionTitle\` — for your FIRST candidate only: a short noun phrase naming what the concluding step DOES in the argument — the inferential move, not the proposition. Do not restate the consequent: that claim's own title is already shown directly beneath this one. Aim for under 60 characters. Return an empty string when \`conclusionCandidates\` is empty.
30
+ - each relation's \`title\` — a short noun phrase naming what that step DOES in the argument — the inferential move, not the proposition. Do not restate the consequent: that claim's own title is already shown directly beneath this one. Aim for under 60 characters. Examples: "Limits of the crowd's power", "Residence as tacit consent", "Principle over survival". Every relation's title must differ from every other relation's — two steps never share a name.
31
+ - \`conclusionCandidates\` — the claim miniIds that could be the argument's conclusion, ordered by DECREASING confidence (best first). The conclusion is the claim other claims support but that supports nothing further. Never list a citation- or axiomatic-typed claim.
32
+ - \`conclusionTitle\` — for your FIRST candidate only: a short noun phrase naming what the concluding step DOES in the argument — the inferential move, not the proposition. Do not restate the consequent: that claim's own title is already shown directly beneath this one. Aim for under 60 characters. It must differ from every relation's \`title\` — the step that reaches the conclusion already has its own. Return an empty string when \`conclusionCandidates\` is empty.
30
33
  - \`rationale\` — one sentence explaining your best pick (or why none qualifies).
31
34
 
35
+ Emit the relations and conclusion the author actually argues. An argument with at least two normal-typed claims has at least one relation and one conclusion candidate, so look for them before concluding there are none. Never invent support the author does not give: if the claims genuinely do not connect, return \`relations\` and \`conclusionCandidates\` empty.
36
+
32
37
  Output ONLY the schema-shaped object. No prose.`;
33
38
  function buildStructurePrompt(ctx) {
34
39
  const canon = ctx.get(STAGE_IDS.claimCanonicalization);
@@ -77,20 +82,42 @@ export function createStructureStage(options) {
77
82
  reasoningEffort: options?.reasoningEffort,
78
83
  retry: options?.retry,
79
84
  buildPrompt: buildStructurePrompt,
85
+ checkOutput: (output, ctx) => checkArgumentStructure(ctx, output),
80
86
  });
81
87
  }
82
88
  /**
83
89
  * Adapter — republish `structure`'s relations under the
84
- * relation-extraction slot.
90
+ * relation-extraction slot, together with the relations that attach each
91
+ * source claim to the claim it supports (`buildSourceRelations`), read
92
+ * off the same settled citations the canonicalization slot carries.
85
93
  */
86
94
  export const structureRelationAdapterStage = deterministicStage({
87
95
  id: STAGE_IDS.relationExtraction,
88
- dependsOn: [STAGE_IDS.scribeStructure],
96
+ dependsOn: [
97
+ STAGE_IDS.scribeStructure,
98
+ STAGE_IDS.extract,
99
+ STAGE_IDS.claimTypeClassification,
100
+ ],
89
101
  outputSchema: RelationExtractionOutputSchema,
90
- fn: (ctx) => ({
91
- relations: ctx.get(STAGE_IDS.scribeStructure)
92
- ?.relations ?? [],
93
- }),
102
+ fn: (ctx) => {
103
+ const structureRelations = ctx.get(STAGE_IDS.scribeStructure)
104
+ ?.relations ?? [];
105
+ // Settled again rather than read from the canonicalization slot:
106
+ // attachment needs the mentions and source pairings too, which
107
+ // that slot does not carry. The adapter there has reported.
108
+ const extract = settleCitations(ctx.get(STAGE_IDS.extract), ctx.input.text, () => undefined);
109
+ const sourceRelations = buildSourceRelations({
110
+ extract,
111
+ structureRelations,
112
+ typeByMiniId: resolveClaimTypes({
113
+ classifications: ctx.get(STAGE_IDS.claimTypeClassification)?.classifications ?? [],
114
+ canonicalClaims: extract?.canonicalClaims ?? [],
115
+ }),
116
+ inputText: ctx.input.text,
117
+ addFailure: ctx.addFailure,
118
+ });
119
+ return { relations: [...structureRelations, ...sourceRelations] };
120
+ },
94
121
  });
95
122
  /**
96
123
  * Adapter — republish `structure`'s conclusion candidates under the
@@ -105,7 +132,6 @@ export const structureConclusionAdapterStage = deterministicStage({
105
132
  dependsOn: [
106
133
  STAGE_IDS.scribeStructure,
107
134
  STAGE_IDS.claimTypeClassification,
108
- STAGE_IDS.relationExtraction,
109
135
  ],
110
136
  outputSchema: ConclusionSelectionOutputSchema,
111
137
  fn: (ctx) => {
@@ -113,8 +139,10 @@ export const structureConclusionAdapterStage = deterministicStage({
113
139
  const candidates = structure?.conclusionCandidates ?? [];
114
140
  const rationale = structure?.rationale ?? "";
115
141
  const classifications = ctx.get(STAGE_IDS.claimTypeClassification)?.classifications ?? [];
116
- const relations = ctx.get(STAGE_IDS.relationExtraction)
117
- ?.relations ?? [];
142
+ // `structure`'s own relations, not the published slot: the
143
+ // source relations added there would make each supported claim
144
+ // look like a candidate conclusion to the graph fallback.
145
+ const relations = structure?.relations ?? [];
118
146
  const normalMiniIds = new Set(classifications
119
147
  .filter((entry) => entry.type === "normal")
120
148
  .map((entry) => entry.miniId));
@@ -1 +1 @@
1
- {"version":3,"file":"structure-stage.js","sourceRoot":"","sources":["../../../../../src/extensions/pipelines/ingestion/scribe/structure-stage.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,oEAAoE;AACpE,2DAA2D;AAC3D,iEAAiE;AACjE,sDAAsD;AACtD,gEAAgE;AAChE,EAAE;AACF,mEAAmE;AACnE,kEAAkE;AAClE,qEAAqE;AACrE,sEAAsE;AACtE,sEAAsE;AACtE,sCAAsC;AAEtC,OAAO,EAAE,QAAQ,EAAE,MAAM,4CAA4C,CAAA;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAA;AAE/E,OAAO,EACH,SAAS,EACT,8BAA8B,EAC9B,+BAA+B,EAC/B,wBAAwB,EACxB,+CAA+C,GAKlD,MAAM,4BAA4B,CAAA;AAEnC,OAAO,EACH,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CAAC,CAAA;QACN,CAAC;QAED,OAAO;YACH,gBAAgB;YAChB,oBAAoB,EAAE,UAAU;YAChC,oDAAoD;YACpD,gDAAgD;YAChD,6CAA6C;YAC7C,KAAK,EAAE,SAAS,EAAE,eAAe,IAAI,EAAE;YACvC,SAAS,EAAE,iBAAiB;gBACxB,CAAC,CAAC,iBAAiB,gBAAgB,iEAAiE;gBACpG,CAAC,CAAC,SAAS;SAClB,CAAA;IACL,CAAC;CACJ,CAAC,CAAA"}
1
+ {"version":3,"file":"structure-stage.js","sourceRoot":"","sources":["../../../../../src/extensions/pipelines/ingestion/scribe/structure-stage.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,oEAAoE;AACpE,2DAA2D;AAC3D,iEAAiE;AACjE,sDAAsD;AACtD,gEAAgE;AAChE,EAAE;AACF,mEAAmE;AACnE,kEAAkE;AAClE,qEAAqE;AACrE,sEAAsE;AACtE,sEAAsE;AACtE,sCAAsC;AAEtC,OAAO,EAAE,QAAQ,EAAE,MAAM,4CAA4C,CAAA;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAA;AAE/E,OAAO,EACH,SAAS,EACT,8BAA8B,EAC9B,+BAA+B,EAC/B,sBAAsB,EACtB,wBAAwB,EACxB,+CAA+C,GAKlD,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAA;AAK5E,OAAO,EACH,2BAA2B,GAG9B,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAEpD,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAA;AAE1C,6DAA6D;AAC7D,MAAM,CAAC,MAAM,wBAAwB,GAA6B;IAC9D,KAAK,EAAE,eAAe;CACzB,CAAA;AAED,MAAM,CAAC,MAAM,uBAAuB,GAAG;;;;;;;;;;;gDAWS,CAA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,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,IAAI,CAAA;QAClE,MAAM,gBAAgB,GAClB,SAAS;YACT,wBAAwB,CAAC,eAAe,EAAE,SAAS,CAAC,CAAA;QACxD,MAAM,iBAAiB,GACnB,SAAS,KAAK,IAAI,IAAI,gBAAgB,KAAK,IAAI,CAAA;QAEnD,IAAI,gBAAgB,KAAK,IAAI,EAAE,CAAC;YAC5B,GAAG,CAAC,UAAU,CAAC;gBACX,IAAI,EAAE,+CAA+C;gBACrD,OAAO,EACH,SAAS,CAAC,MAAM,GAAG,CAAC;oBAChB,CAAC,CAAC,SAAS;oBACX,CAAC,CAAC,yCAAyC;gBACnD,QAAQ,EAAE,SAAS;gBACnB,OAAO,EAAE,EAAE,SAAS,EAAE;aACzB,CAAC,CAAA;QACN,CAAC;QAED,OAAO;YACH,gBAAgB;YAChB,oBAAoB,EAAE,UAAU;YAChC,oDAAoD;YACpD,gDAAgD;YAChD,6CAA6C;YAC7C,KAAK,EAAE,SAAS,EAAE,eAAe,IAAI,EAAE;YACvC,SAAS,EAAE,iBAAiB;gBACxB,CAAC,CAAC,iBAAiB,gBAAgB,iEAAiE;gBACpG,CAAC,CAAC,SAAS;SAClB,CAAA;IACL,CAAC;CACJ,CAAC,CAAA"}
@@ -1,7 +1,7 @@
1
1
  import type { TSchema } from "typebox";
2
2
  /**
3
- * Fraction of a free-text field's declared `maxLength` to project into
4
- * the wire schema — leaving headroom below the true cap so the model's
3
+ * Fraction of a free-text field's declared `maxLength` to state as its
4
+ * budget in the wire schema's `description` — leaving headroom below the true cap so the model's
5
5
  * tendency to overshoot lands under the real limit rather than past it.
6
6
  *
7
7
  * ponytail: tunable heuristic knob. Lower it (e.g. 0.85, 0.8) if
@@ -14,8 +14,8 @@ export declare const SHRINK = 0.9;
14
14
  * Project a TypeBox String node into the wire-schema String object,
15
15
  * applying free-text length steering.
16
16
  *
17
- * - A free-text String with a `maxLength` gets a shrunk `maxLength` and
18
- * a `description` ending `…at most <shrunk> characters`.
17
+ * - A free-text String with a `maxLength` gets no `maxLength` and a
18
+ * `description` ending `…at most <shrunk> characters`.
19
19
  * - An exact-value String (declares a `format`, or a very small
20
20
  * `maxLength`) keeps its original `maxLength`/`description` and gets
21
21
  * no hint.
@@ -1 +1 @@
1
- {"version":3,"file":"length-hint.d.ts","sourceRoot":"","sources":["../../../src/extensions/structured-output/length-hint.ts"],"names":[],"mappings":"AAmCA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEtC;;;;;;;;;GASG;AACH,eAAO,MAAM,MAAM,MAAM,CAAA;AAyCzB;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,uBAAuB,CACnC,MAAM,EAAE,OAAO,GAChB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAuCzB"}
1
+ {"version":3,"file":"length-hint.d.ts","sourceRoot":"","sources":["../../../src/extensions/structured-output/length-hint.ts"],"names":[],"mappings":"AAmCA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEtC;;;;;;;;;GASG;AACH,eAAO,MAAM,MAAM,MAAM,CAAA;AAyCzB;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,uBAAuB,CACnC,MAAM,EAAE,OAAO,GAChB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAmCzB"}
@@ -13,18 +13,18 @@
13
13
  // This helper restores a *steering* projection for free-text String
14
14
  // fields, shared so the shrink math, hint wording, and exact-value
15
15
  // exemption rule live in exactly one place. It does NOT enforce the
16
- // true limit — a post-hoc clamp against the original (unshrunk) schema
17
- // remains the only thing that truncates. The projection only nudges
18
- // the model toward the limit:
16
+ // true limit — a post-hoc clamp against the original schema remains the
17
+ // only thing that shortens, and it ends on a whole word. The projection
18
+ // only nudges the model toward the limit: it appends a *shrunk* budget
19
+ // (`floor(original * SHRINK)`) to `description`, so a model reading the
20
+ // schema sees the cap with headroom below the real one.
19
21
  //
20
- // * Project a *shrunk* `maxLength` (`floor(original * SHRINK)`,
21
- // floored at 1). On a respected-`maxLength` consumer (a local
22
- // llama-server compiling to GBNF) this caps output strictly below
23
- // the true limit. On OpenAI strict mode the value is ignored, so
24
- // it is an inert structural placeholder there.
25
- // * Append the budget to `description` so a model reading the prose
26
- // schema sees the cap explicitly — this is what steers OpenAI,
27
- // which ignores `maxLength` but does read `description`.
22
+ // A free-text field carries no `maxLength` on the wire. A model that
23
+ // enforces it — a local llama-server compiling the schema to a grammar,
24
+ // and newer OpenAI models in strict mode — stops generating at the cap,
25
+ // which cuts the value off mid-word ("…major politicians since 177")
26
+ // with nothing downstream able to repair it. Prose steering plus the
27
+ // word-boundary clamp keeps every value whole.
28
28
  //
29
29
  // Exact-value fields are exempt from both. A String that declares a
30
30
  // `format` (e.g. `uri`) or a very small `maxLength` is not free text:
@@ -33,8 +33,8 @@
33
33
  // hint is meaningless for an exact value. Those keep their original
34
34
  // `maxLength` (and original `description`), with no hint.
35
35
  /**
36
- * Fraction of a free-text field's declared `maxLength` to project into
37
- * the wire schema — leaving headroom below the true cap so the model's
36
+ * Fraction of a free-text field's declared `maxLength` to state as its
37
+ * budget in the wire schema's `description` — leaving headroom below the true cap so the model's
38
38
  * tendency to overshoot lands under the real limit rather than past it.
39
39
  *
40
40
  * ponytail: tunable heuristic knob. Lower it (e.g. 0.85, 0.8) if
@@ -70,8 +70,8 @@ function isExactValueField(fields) {
70
70
  * Project a TypeBox String node into the wire-schema String object,
71
71
  * applying free-text length steering.
72
72
  *
73
- * - A free-text String with a `maxLength` gets a shrunk `maxLength` and
74
- * a `description` ending `…at most <shrunk> characters`.
73
+ * - A free-text String with a `maxLength` gets no `maxLength` and a
74
+ * `description` ending `…at most <shrunk> characters`.
75
75
  * - An exact-value String (declares a `format`, or a very small
76
76
  * `maxLength`) keeps its original `maxLength`/`description` and gets
77
77
  * no hint.
@@ -105,16 +105,12 @@ export function projectStringLengthHint(schema) {
105
105
  }
106
106
  return exact;
107
107
  }
108
- // Free-text field: shrink the cap and restate the budget in prose.
108
+ // Free-text field: state the shrunk budget in prose only.
109
109
  const shrunk = Math.max(1, Math.floor(fields.maxLength * SHRINK));
110
110
  const budgetHint = `at most ${String(shrunk)} characters`;
111
111
  const description = fields.description !== undefined
112
112
  ? `${fields.description}; ${budgetHint}`
113
113
  : budgetHint;
114
- return {
115
- type: "string",
116
- maxLength: shrunk,
117
- description,
118
- };
114
+ return { type: "string", description };
119
115
  }
120
116
  //# sourceMappingURL=length-hint.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"length-hint.js","sourceRoot":"","sources":["../../../src/extensions/structured-output/length-hint.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,cAAc;AACd,EAAE;AACF,+DAA+D;AAC/D,sEAAsE;AACtE,gEAAgE;AAChE,8DAA8D;AAC9D,mEAAmE;AACnE,oEAAoE;AACpE,sEAAsE;AACtE,0DAA0D;AAC1D,EAAE;AACF,oEAAoE;AACpE,mEAAmE;AACnE,oEAAoE;AACpE,uEAAuE;AACvE,oEAAoE;AACpE,8BAA8B;AAC9B,EAAE;AACF,kEAAkE;AAClE,kEAAkE;AAClE,sEAAsE;AACtE,qEAAqE;AACrE,mDAAmD;AACnD,sEAAsE;AACtE,mEAAmE;AACnE,6DAA6D;AAC7D,EAAE;AACF,oEAAoE;AACpE,sEAAsE;AACtE,sEAAsE;AACtE,uEAAuE;AACvE,oEAAoE;AACpE,0DAA0D;AAI1D;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,GAAG,CAAA;AAEzB,wEAAwE;AACxE,qEAAqE;AACrE,gEAAgE;AAChE,mEAAmE;AACnE,eAAe;AACf,MAAM,sBAAsB,GAAG,EAAE,CAAA;AAajC,SAAS,sBAAsB,CAAC,MAAe;IAC3C,MAAM,CAAC,GAAG,MAA6B,CAAA;IACvC,OAAO;QACH,SAAS,EAAE,OAAO,CAAC,CAAC,SAAS,KAAK,QAAQ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K,CAAA;IAChB,CAAC;IAED,mEAAmE;IACnE,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC,CAAC,CAAA;IACjE,MAAM,UAAU,GAAG,WAAW,MAAM,CAAC,MAAM,CAAC,aAAa,CAAA;IACzD,MAAM,WAAW,GACb,MAAM,CAAC,WAAW,KAAK,SAAS;QAC5B,CAAC,CAAC,GAAG,MAAM,CAAC,WAAW,KAAK,UAAU,EAAE;QACxC,CAAC,CAAC,UAAU,CAAA;IACpB,OAAO;QACH,IAAI,EAAE,QAAQ;QACd,SAAS,EAAE,MAAM;QACjB,WAAW;KACd,CAAA;AACL,CAAC"}
1
+ {"version":3,"file":"length-hint.js","sourceRoot":"","sources":["../../../src/extensions/structured-output/length-hint.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,cAAc;AACd,EAAE;AACF,+DAA+D;AAC/D,sEAAsE;AACtE,gEAAgE;AAChE,8DAA8D;AAC9D,mEAAmE;AACnE,oEAAoE;AACpE,sEAAsE;AACtE,0DAA0D;AAC1D,EAAE;AACF,oEAAoE;AACpE,mEAAmE;AACnE,oEAAoE;AACpE,wEAAwE;AACxE,wEAAwE;AACxE,uEAAuE;AACvE,wEAAwE;AACxE,wDAAwD;AACxD,EAAE;AACF,qEAAqE;AACrE,wEAAwE;AACxE,wEAAwE;AACxE,qEAAqE;AACrE,qEAAqE;AACrE,+CAA+C;AAC/C,EAAE;AACF,oEAAoE;AACpE,sEAAsE;AACtE,sEAAsE;AACtE,uEAAuE;AACvE,oEAAoE;AACpE,0DAA0D;AAI1D;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,GAAG,CAAA;AAEzB,wEAAwE;AACxE,qEAAqE;AACrE,gEAAgE;AAChE,mEAAmE;AACnE,eAAe;AACf,MAAM,sBAAsB,GAAG,EAAE,CAAA;AAajC,SAAS,sBAAsB,CAA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