@sema-agent/client-core 0.90.0 → 0.92.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/CHANGELOG.md +365 -0
  2. package/README.md +48 -32
  3. package/dist/adapt/arms.js +13 -12
  4. package/dist/adapt/panelTasks.d.ts +0 -2
  5. package/dist/adapt/panelTasks.js +6 -26
  6. package/dist/adapt.js +2 -2
  7. package/dist/adapter/activeRunSelfHeal.d.ts +0 -2
  8. package/dist/adapter/activeRunSelfHeal.js +5 -27
  9. package/dist/adapter/downstream/eventToSdkMessage.js +4 -2
  10. package/dist/adapter/downstream/terminalToSdkResult.js +16 -7
  11. package/dist/adapter/downstream/wiringManifestView.d.ts +6 -0
  12. package/dist/adapter/downstream/wiringManifestView.js +16 -0
  13. package/dist/adapter/runStream.js +39 -20
  14. package/dist/askSurvivesStandingAnswer.d.ts +13 -0
  15. package/dist/askSurvivesStandingAnswer.js +53 -0
  16. package/dist/attachmentSeatCapability.d.ts +11 -0
  17. package/dist/attachmentSeatCapability.js +27 -0
  18. package/dist/attachmentsWireCaps.d.ts +9 -0
  19. package/dist/attachmentsWireCaps.js +74 -21
  20. package/dist/autoModeUnavailable.js +3 -2
  21. package/dist/cloudConfigWireCaps.js +5 -4
  22. package/dist/compensations.js +13 -17
  23. package/dist/controlRouter.d.ts +32 -25
  24. package/dist/controlRouter.js +166 -63
  25. package/dist/coreValuePorts.d.ts +4 -2
  26. package/dist/coreValuePorts.js +5 -0
  27. package/dist/decideFailureNote.js +7 -3
  28. package/dist/decideReceipt.d.ts +9 -0
  29. package/dist/decideReceipt.js +62 -1
  30. package/dist/disableSkillsWire.d.ts +1 -0
  31. package/dist/disableSkillsWire.js +8 -1
  32. package/dist/displayUntrusted.js +155 -5
  33. package/dist/effectiveFacts.d.ts +14 -4
  34. package/dist/effectiveFacts.js +45 -5
  35. package/dist/engineAgentAbsence.js +2 -1
  36. package/dist/engineCapReader.js +16 -10
  37. package/dist/engineCapsCache.d.ts +5 -1
  38. package/dist/engineCapsCache.js +69 -8
  39. package/dist/engineClosedSets.d.ts +2 -0
  40. package/dist/engineClosedSets.js +3 -0
  41. package/dist/engineErrorCodes.d.ts +17 -0
  42. package/dist/engineErrorCodes.js +47 -0
  43. package/dist/engineNoticeCodes.d.ts +14 -0
  44. package/dist/engineNoticeCodes.js +71 -0
  45. package/dist/executionLaneCapability.js +2 -0
  46. package/dist/gateOutcome.js +2 -17
  47. package/dist/gateVocabulary.d.ts +2 -4
  48. package/dist/gateVocabulary.js +3 -11
  49. package/dist/generated/engineFactTables.d.ts +27 -0
  50. package/dist/generated/engineFactTables.js +128 -0
  51. package/dist/generated/engineNoticeTables.js +3 -0
  52. package/dist/generated/settingsSchemaTables.d.ts +8 -0
  53. package/dist/generated/settingsSchemaTables.js +40 -0
  54. package/dist/hitl/allowRuleShadow.d.ts +21 -0
  55. package/dist/hitl/allowRuleShadow.js +167 -0
  56. package/dist/hitl/askClassPair.d.ts +14 -0
  57. package/dist/hitl/askClassPair.js +42 -0
  58. package/dist/hitl/askGateWire.d.ts +1 -1
  59. package/dist/hitl/askGateWire.js +2 -1
  60. package/dist/hitl/askSurvivesPosture.d.ts +5 -0
  61. package/dist/hitl/askSurvivesPosture.js +17 -0
  62. package/dist/hitl/automaticAnswerVerdict.d.ts +21 -0
  63. package/dist/hitl/automaticAnswerVerdict.js +143 -0
  64. package/dist/hitl/crashConverged.d.ts +8 -0
  65. package/dist/hitl/crashConverged.js +58 -1
  66. package/dist/hitl/crashConvergedNotice.d.ts +4 -0
  67. package/dist/hitl/crashConvergedNotice.js +57 -0
  68. package/dist/hitl/frameRouter.d.ts +2 -0
  69. package/dist/hitl/frameRouter.js +66 -14
  70. package/dist/hitl/gateLedger.d.ts +6 -0
  71. package/dist/hitl/gateLedger.js +34 -5
  72. package/dist/hitl/hitlBridge.d.ts +7 -4
  73. package/dist/hitl/hitlHostSurface.d.ts +2 -0
  74. package/dist/hitl/hitlHostSurface.js +7 -0
  75. package/dist/hitl/livePendingAsk.js +24 -5
  76. package/dist/hitl/parkResolver.d.ts +7 -2
  77. package/dist/hitl/parkResolver.js +21 -7
  78. package/dist/hitl/persistedRulesWire.d.ts +4 -1
  79. package/dist/hitl/persistedRulesWire.js +9 -2
  80. package/dist/hitl/planReviewWire.d.ts +1 -1
  81. package/dist/hitl/planReviewWire.js +19 -5
  82. package/dist/hitl/replayedApproval.d.ts +21 -0
  83. package/dist/hitl/replayedApproval.js +89 -0
  84. package/dist/hitl/sessionPolicyDeliverable.js +20 -2
  85. package/dist/hitl/sessionPolicyWire.d.ts +13 -0
  86. package/dist/hitl/sessionPolicyWire.js +75 -2
  87. package/dist/hitl/suspendedReopen.js +2 -2
  88. package/dist/hitl/toolApprovalWire.d.ts +9 -1
  89. package/dist/hitl/toolApprovalWire.js +40 -40
  90. package/dist/hookMatcherVerdict.d.ts +29 -0
  91. package/dist/hookMatcherVerdict.js +266 -0
  92. package/dist/humanTurn.d.ts +91 -0
  93. package/dist/humanTurn.js +252 -0
  94. package/dist/humanTurnRead.d.ts +105 -0
  95. package/dist/humanTurnRead.js +331 -0
  96. package/dist/index.d.ts +38 -11
  97. package/dist/index.js +27 -8
  98. package/dist/inheritEnvWire.js +4 -5
  99. package/dist/liveModelCatalog.d.ts +2 -0
  100. package/dist/liveModelCatalog.js +51 -3
  101. package/dist/mcpLiveness.js +2 -1
  102. package/dist/memoryVerbsWire.d.ts +1 -1
  103. package/dist/memoryVerbsWire.js +3 -0
  104. package/dist/model/catalog.js +2 -1
  105. package/dist/model/providerPresets.d.ts +3 -1
  106. package/dist/model/tierVocabulary.d.ts +2 -1
  107. package/dist/model/tierVocabulary.js +3 -8
  108. package/dist/peerFrames.js +2 -2
  109. package/dist/permissionRuleIssue.d.ts +1 -1
  110. package/dist/permissionRuleIssue.js +31 -9
  111. package/dist/permissionsAllowGrantCapability.d.ts +2 -1
  112. package/dist/permissionsAllowGrantCapability.js +11 -2
  113. package/dist/permissionsDeclaration.d.ts +29 -0
  114. package/dist/permissionsDeclaration.js +155 -66
  115. package/dist/pluginHooksWire.js +2 -11
  116. package/dist/promptDelivery.d.ts +11 -3
  117. package/dist/promptDelivery.js +164 -29
  118. package/dist/promptProfileWireCaps.d.ts +2 -1
  119. package/dist/protocolSegment.d.ts +9 -0
  120. package/dist/protocolSegment.js +28 -0
  121. package/dist/providerRejection.d.ts +1 -0
  122. package/dist/providerRejection.js +20 -0
  123. package/dist/readDenyTiers.d.ts +10 -0
  124. package/dist/readDenyTiers.js +29 -0
  125. package/dist/request/taskRequest.js +3 -17
  126. package/dist/resumeRefusalCopy.d.ts +11 -0
  127. package/dist/resumeRefusalCopy.js +61 -4
  128. package/dist/rewindArchiveCapability.js +4 -4
  129. package/dist/rewindWireCaps.d.ts +2 -1
  130. package/dist/rewindWireCaps.js +19 -2
  131. package/dist/ruleCompileVerdict.d.ts +2 -0
  132. package/dist/ruleCompileVerdict.js +13 -0
  133. package/dist/ruleRemovalConsequence.d.ts +2 -1
  134. package/dist/runCancelContext.d.ts +12 -0
  135. package/dist/runCancelContext.js +83 -1
  136. package/dist/seam.d.ts +2 -0
  137. package/dist/seam.js +1 -1
  138. package/dist/seatContract.d.ts +2 -1
  139. package/dist/sessionMemoryStatus.d.ts +2 -4
  140. package/dist/sessionSyncFileHistoryCapability.d.ts +18 -0
  141. package/dist/sessionSyncFileHistoryCapability.js +50 -0
  142. package/dist/skillToolListsCapability.d.ts +18 -0
  143. package/dist/skillToolListsCapability.js +50 -0
  144. package/dist/sqlEngineCapability.js +1 -8
  145. package/dist/steerPriorityCapability.d.ts +18 -0
  146. package/dist/steerPriorityCapability.js +80 -0
  147. package/dist/steerReceipt.d.ts +9 -0
  148. package/dist/steerReceipt.js +25 -0
  149. package/dist/subagent/engineSubagentSteer.js +2 -9
  150. package/dist/supportFloor.js +2 -2
  151. package/dist/taskRequestWords.d.ts +7 -1
  152. package/dist/taskRequestWords.js +18 -8
  153. package/dist/toolHistoryBadTurn.d.ts +1 -0
  154. package/dist/toolHistoryBadTurn.js +89 -0
  155. package/dist/toolHistoryMismatch.d.ts +2 -1
  156. package/dist/toolHistoryMismatch.js +19 -6
  157. package/dist/toolResult.d.ts +8 -0
  158. package/dist/toolResult.js +47 -3
  159. package/dist/types/engineState.d.ts +2 -12
  160. package/dist/userAttachmentEnvelope.d.ts +61 -0
  161. package/dist/userAttachmentEnvelope.js +204 -0
  162. package/dist/userInvokedSkillsCapability.d.ts +18 -0
  163. package/dist/userInvokedSkillsCapability.js +50 -0
  164. package/dist/wireFailureShape.d.ts +3 -0
  165. package/dist/wireFailureShape.js +8 -0
  166. package/dist/wireRefusalCopy.d.ts +6 -0
  167. package/dist/wireRefusalCopy.js +26 -3
  168. package/dist/workflowsJournalCapability.d.ts +18 -0
  169. package/dist/workflowsJournalCapability.js +50 -0
  170. package/dist/writeProtectionCapability.d.ts +2 -4
  171. package/docs/INTEGRATION-CLIENTS.md +1489 -16
  172. package/package.json +3 -3
@@ -0,0 +1,91 @@
1
+ import type { ImageInput } from './imagesWireCaps.js';
2
+ import type { ImageVision } from './liveModelCatalog.js';
3
+ import { type UserAttachmentDescriptor } from './userAttachmentEnvelope.js';
4
+ export interface HumanTurnRider {
5
+ readonly uuid: string;
6
+ readonly role: 'image_meta' | 'attachment' | 'skill_body' | (string & {});
7
+ readonly textIncluded: boolean;
8
+ }
9
+ export interface HumanTurnMissing {
10
+ readonly kind: 'rider_text' | 'image' | 'attachment_ref' | 'non_text';
11
+ readonly ref?: string;
12
+ readonly reason: 'not_persisted' | 'not_found' | 'non_text_filtered' | 'projection_failed';
13
+ }
14
+ export interface HumanTurnAttachment {
15
+ readonly uuid: string;
16
+ readonly descriptor: Exclude<UserAttachmentDescriptor, {
17
+ kind: 'image';
18
+ }> | Omit<Extract<UserAttachmentDescriptor, {
19
+ kind: 'image';
20
+ }>, 'delivery'>;
21
+ readonly pixels?: {
22
+ readonly data: string;
23
+ readonly mimeType: string;
24
+ };
25
+ }
26
+ export interface HumanTurnItem {
27
+ readonly uuid: string;
28
+ readonly text: string;
29
+ readonly images?: readonly ImageInput[];
30
+ readonly attachments?: readonly HumanTurnAttachment[];
31
+ readonly attachmentIds?: readonly string[];
32
+ readonly riders?: readonly HumanTurnRider[];
33
+ readonly missing?: readonly HumanTurnMissing[];
34
+ }
35
+ export interface HumanTurnCaps {
36
+ readonly vision?: ImageVision;
37
+ }
38
+ export interface HumanTurnInput {
39
+ readonly items: readonly HumanTurnItem[];
40
+ readonly lane: 'objective' | 'steer';
41
+ readonly caps: HumanTurnCaps;
42
+ readonly otherBodyBytes?: number;
43
+ }
44
+ type EncoderShortfall = 'body_budget' | 'steer_admission' | 'vision_no' | 'vision_unknown' | 'image_too_large' | 'seat_count' | 'seat_total' | 'lane_has_no_image_seat' | 'lane_has_no_attachment_id_seat';
45
+ export interface HumanTurnSharePart {
46
+ readonly kind: 'text' | 'image' | 'attachment_ref' | 'attachment_id' | 'rider_text' | 'non_text';
47
+ readonly ref?: string | number;
48
+ readonly status: 'full' | 'none';
49
+ readonly why?: EncoderShortfall | 'text_not_included' | HumanTurnMissing['reason'];
50
+ }
51
+ export interface HumanTurnShare {
52
+ readonly uuid: string;
53
+ readonly riderUuids: readonly string[];
54
+ readonly level: 'full' | 'partial' | 'none';
55
+ readonly parts: readonly HumanTurnSharePart[];
56
+ }
57
+ export interface HumanTurnDegraded {
58
+ readonly uuid: string;
59
+ readonly kind: HumanTurnSharePart['kind'];
60
+ readonly ref?: string | number;
61
+ readonly why: EncoderShortfall;
62
+ }
63
+ export type HumanTurnEncoding = {
64
+ readonly ok: true;
65
+ readonly lane: 'objective';
66
+ readonly text: string;
67
+ readonly images: readonly ImageInput[];
68
+ readonly attachmentIds: readonly string[];
69
+ readonly shares: readonly HumanTurnShare[];
70
+ readonly degraded: readonly HumanTurnDegraded[];
71
+ } | {
72
+ readonly ok: true;
73
+ readonly lane: 'steer';
74
+ readonly text: string;
75
+ readonly shares: readonly HumanTurnShare[];
76
+ readonly degraded: readonly HumanTurnDegraded[];
77
+ } | {
78
+ readonly ok: false;
79
+ readonly reason: 'steer_hold';
80
+ readonly why: 'no_text' | 'reminder_tag' | 'control_char' | 'too_long';
81
+ } | {
82
+ readonly ok: false;
83
+ readonly reason: 'empty' | 'malformed_input' | 'malformed_item' | 'duplicate_uuid' | 'rider_collides_primary' | 'oversize';
84
+ };
85
+ export interface HumanTurnDelivered {
86
+ readonly full: readonly string[];
87
+ readonly partial: readonly string[];
88
+ }
89
+ export declare function encodeHumanTurn(input: HumanTurnInput): HumanTurnEncoding;
90
+ export declare function deliveredUuidsOf(encoding: HumanTurnEncoding): HumanTurnDelivered;
91
+ export {};
@@ -0,0 +1,252 @@
1
+ import { CORE_MAX_PENDING_STEER_CHARS, CORE_MCP_IMAGE_MAX_BASE64 } from './generated/engineFactTables.js';
2
+ import { mintEnvelopeOf, mintReferenceOf } from './userAttachmentEnvelope.js';
3
+ import { readEncodingShares, readHumanTurnInput } from './humanTurnRead.js';
4
+ const REQUEST_BODY_MAX_BYTES = 8 * 1024 * 1024;
5
+ const IMAGE_SEAT_MAX_COUNT = 20;
6
+ const IMAGE_SEAT_MAX_BASE64_CHARS_TOTAL = 6 * 1024 * 1024;
7
+ const STEER_REMINDER_TAG = /<\s*\/?\s*system-reminder(?:\s[^>]*)?>/i;
8
+ const STEER_CONTROL_CHARS = /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/;
9
+ function utf8Length(s) {
10
+ let n = 0;
11
+ for (let i = 0; i < s.length; i += 1) {
12
+ const c = s.charCodeAt(i);
13
+ if (c < 0x80)
14
+ n += 1;
15
+ else if (c < 0x800)
16
+ n += 2;
17
+ else if (c >= 0xd800 && c <= 0xdbff && i + 1 < s.length) {
18
+ const d = s.charCodeAt(i + 1);
19
+ if (d >= 0xdc00 && d <= 0xdfff) {
20
+ n += 4;
21
+ i += 1;
22
+ }
23
+ else
24
+ n += 3;
25
+ }
26
+ else
27
+ n += 3;
28
+ }
29
+ return n;
30
+ }
31
+ const jsonBytes = (v) => utf8Length(JSON.stringify(v));
32
+ function bodyBytes(other, objective, images, ids) {
33
+ const keys = [jsonBytes('objective') + 1 + jsonBytes(objective)];
34
+ if (images.length > 0)
35
+ keys.push(jsonBytes('images') + 1 + jsonBytes(images));
36
+ if (ids.length > 0)
37
+ keys.push(jsonBytes('attachmentIds') + 1 + jsonBytes(ids));
38
+ const commas = other === 2 ? keys.length - 1 : keys.length;
39
+ return other + keys.reduce((a, b) => a + b, 0) + commas;
40
+ }
41
+ function steerRefusal(text) {
42
+ if (text.length === 0)
43
+ return 'no_text';
44
+ if (STEER_REMINDER_TAG.test(text))
45
+ return 'reminder_tag';
46
+ if (STEER_CONTROL_CHARS.test(text))
47
+ return 'control_char';
48
+ if (text.length > CORE_MAX_PENDING_STEER_CHARS)
49
+ return 'too_long';
50
+ return undefined;
51
+ }
52
+ function textOf(p) {
53
+ if (p.form === 'reference')
54
+ return mintReferenceOf(p.a.d);
55
+ return mintEnvelopeOf(p.a.d, p.seated ? 'attached' : 'not-attached');
56
+ }
57
+ function compose(items, placements) {
58
+ const perItem = items.map((it, i) => [...placements.filter((p) => p.item === i).map(textOf), it.text].filter((s) => s.length > 0).join('\n\n'));
59
+ return perItem.filter((s) => s.length > 0).join('\n');
60
+ }
61
+ function seatedImages(items, pastedWhy, placements) {
62
+ const out = [];
63
+ items.forEach((it, i) => {
64
+ it.images.forEach((img, k) => {
65
+ if (pastedWhy[i]?.[k] === undefined)
66
+ out.push('url' in img ? { url: img.url } : { data: img.data, mimeType: img.mimeType });
67
+ });
68
+ for (const p of placements) {
69
+ if (p.item === i && p.form === 'content' && p.seated && p.a.pixels !== undefined)
70
+ out.push({ data: p.a.pixels.data, mimeType: p.a.pixels.mimeType });
71
+ }
72
+ });
73
+ return out;
74
+ }
75
+ const ENCODER_WHY_LIST = [
76
+ 'body_budget',
77
+ 'steer_admission',
78
+ 'vision_no',
79
+ 'vision_unknown',
80
+ 'image_too_large',
81
+ 'seat_count',
82
+ 'seat_total',
83
+ 'lane_has_no_image_seat',
84
+ 'lane_has_no_attachment_id_seat',
85
+ ];
86
+ const encoderWhysExhaustive = true;
87
+ void encoderWhysExhaustive;
88
+ const ENCODER_WHYS = new Set(ENCODER_WHY_LIST);
89
+ function records(lane, items, pastedWhy, placements) {
90
+ const recs = [];
91
+ const push = (item, part) => {
92
+ recs.push({ item, part });
93
+ };
94
+ items.forEach((it, i) => {
95
+ if (it.text.length > 0)
96
+ push(i, { kind: 'text', status: 'full' });
97
+ it.images.forEach((_, k) => {
98
+ const why = pastedWhy[i]?.[k];
99
+ push(i, lane !== 'objective' ? { kind: 'image', ref: k, status: 'none', why: 'lane_has_no_image_seat' } : why === undefined ? { kind: 'image', ref: k, status: 'full' } : { kind: 'image', ref: k, status: 'none', why });
100
+ });
101
+ for (const p of placements) {
102
+ if (p.item !== i)
103
+ continue;
104
+ push(i, p.form === 'content' ? { kind: 'attachment_ref', ref: p.a.uuid, status: 'full' } : { kind: 'attachment_ref', ref: p.a.uuid, status: 'none', why: lane === 'objective' ? 'body_budget' : 'steer_admission' });
105
+ if (p.a.pixels !== undefined) {
106
+ if (lane === 'steer')
107
+ push(i, { kind: 'image', ref: p.a.uuid, status: 'none', why: 'lane_has_no_image_seat' });
108
+ else if (p.seated && p.form === 'content')
109
+ push(i, { kind: 'image', ref: p.a.uuid, status: 'full' });
110
+ else
111
+ push(i, { kind: 'image', ref: p.a.uuid, status: 'none', why: p.seated ? 'body_budget' : p.seatWhy });
112
+ }
113
+ }
114
+ for (const id of it.attachmentIds) {
115
+ push(i, lane === 'objective' ? { kind: 'attachment_id', ref: id, status: 'full' } : { kind: 'attachment_id', ref: id, status: 'none', why: 'lane_has_no_attachment_id_seat' });
116
+ }
117
+ for (const r of it.riders) {
118
+ if (r.role === 'image_meta')
119
+ continue;
120
+ push(i, r.textIncluded ? { kind: 'rider_text', ref: r.uuid, status: 'full' } : { kind: 'rider_text', ref: r.uuid, status: 'none', why: 'text_not_included' });
121
+ }
122
+ for (const m of it.missing) {
123
+ push(i, m.ref === undefined ? { kind: m.kind, status: 'none', why: m.reason } : { kind: m.kind, ref: m.ref, status: 'none', why: m.reason });
124
+ }
125
+ });
126
+ return recs;
127
+ }
128
+ function sharesAndDegraded(items, recs) {
129
+ const shares = items.map((it, i) => {
130
+ const parts = recs.filter((r) => r.item === i).map((r) => r.part);
131
+ const full = parts.filter((p) => p.status === 'full').length;
132
+ const level = parts.length > 0 && full === parts.length ? 'full' : full === 0 ? 'none' : 'partial';
133
+ return { uuid: it.uuid, riderUuids: [...it.riders.map((r) => r.uuid), ...it.attachments.map((a) => a.uuid)], level, parts };
134
+ });
135
+ const degraded = [];
136
+ for (const r of recs) {
137
+ const w = r.part.why;
138
+ if (r.part.status === 'none' && w !== undefined && ENCODER_WHYS.has(w)) {
139
+ const uuid = items[r.item].uuid;
140
+ degraded.push(r.part.ref === undefined ? { uuid, kind: r.part.kind, why: w } : { uuid, kind: r.part.kind, ref: r.part.ref, why: w });
141
+ }
142
+ }
143
+ return { shares, degraded };
144
+ }
145
+ function encodeObjective(v) {
146
+ const { items } = v;
147
+ let count = 0;
148
+ let total = 0;
149
+ const seat = (len) => {
150
+ if (len > CORE_MCP_IMAGE_MAX_BASE64)
151
+ return 'image_too_large';
152
+ if (count + 1 > IMAGE_SEAT_MAX_COUNT)
153
+ return 'seat_count';
154
+ if (total + len > IMAGE_SEAT_MAX_BASE64_CHARS_TOTAL)
155
+ return 'seat_total';
156
+ count += 1;
157
+ total += len;
158
+ return undefined;
159
+ };
160
+ const pastedWhy = items.map((it) => it.images.map((img) => seat('data' in img ? img.data.length : 0)));
161
+ const placements = [];
162
+ items.forEach((it, i) => {
163
+ for (const a of it.attachments) {
164
+ const p = { item: i, a, form: 'content', seated: false, seatWhy: undefined };
165
+ if (a.pixels !== undefined) {
166
+ if (v.vision !== 'yes')
167
+ p.seatWhy = v.vision === 'no' ? 'vision_no' : 'vision_unknown';
168
+ else {
169
+ p.seatWhy = seat(a.pixels.data.length);
170
+ p.seated = p.seatWhy === undefined;
171
+ }
172
+ }
173
+ placements.push(p);
174
+ }
175
+ });
176
+ const ids = items.flatMap((it) => it.attachmentIds);
177
+ for (;;) {
178
+ const text = compose(items, placements);
179
+ const images = seatedImages(items, pastedWhy, placements);
180
+ if (bodyBytes(v.otherBodyBytes, text, images, ids) <= REQUEST_BODY_MAX_BYTES) {
181
+ if (text.trim() === '')
182
+ return { ok: false, reason: 'empty' };
183
+ const { shares, degraded } = sharesAndDegraded(items, records('objective', items, pastedWhy, placements));
184
+ return { ok: true, lane: 'objective', text, images, attachmentIds: [...ids], shares, degraded };
185
+ }
186
+ let pick = -1;
187
+ let pickCost = -1;
188
+ placements.forEach((p, k) => {
189
+ if (p.form !== 'content')
190
+ return;
191
+ const cost = jsonBytes(textOf(p)) + (p.seated && p.a.pixels !== undefined ? jsonBytes({ data: p.a.pixels.data, mimeType: p.a.pixels.mimeType }) : 0);
192
+ if (cost >= pickCost) {
193
+ pick = k;
194
+ pickCost = cost;
195
+ }
196
+ });
197
+ if (pick < 0)
198
+ return { ok: false, reason: 'oversize' };
199
+ placements[pick].form = 'reference';
200
+ }
201
+ }
202
+ function encodeSteer(v) {
203
+ const { items } = v;
204
+ const placements = [];
205
+ items.forEach((it, i) => {
206
+ for (const a of it.attachments)
207
+ placements.push({ item: i, a, form: 'content', seated: false, seatWhy: undefined });
208
+ });
209
+ let text = compose(items, placements);
210
+ let refusal = steerRefusal(text);
211
+ if (refusal !== undefined && refusal !== 'no_text' && placements.length > 0) {
212
+ for (const p of placements)
213
+ p.form = 'reference';
214
+ text = compose(items, placements);
215
+ refusal = steerRefusal(text);
216
+ }
217
+ if (refusal !== undefined)
218
+ return { ok: false, reason: 'steer_hold', why: refusal };
219
+ const { shares, degraded } = sharesAndDegraded(items, records('steer', items, [], placements));
220
+ return { ok: true, lane: 'steer', text, shares, degraded };
221
+ }
222
+ export function encodeHumanTurn(input) {
223
+ let v;
224
+ try {
225
+ v = readHumanTurnInput(input);
226
+ }
227
+ catch {
228
+ return { ok: false, reason: 'malformed_input' };
229
+ }
230
+ if ('reject' in v)
231
+ return { ok: false, reason: v.reject };
232
+ try {
233
+ return v.lane === 'objective' ? encodeObjective(v) : encodeSteer(v);
234
+ }
235
+ catch {
236
+ return { ok: false, reason: 'malformed_input' };
237
+ }
238
+ }
239
+ export function deliveredUuidsOf(encoding) {
240
+ const shares = readEncodingShares(encoding);
241
+ const full = [];
242
+ const partial = [];
243
+ for (const s of shares ?? []) {
244
+ const into = s.level === 'full' ? full : s.level === 'partial' ? partial : undefined;
245
+ if (into === undefined)
246
+ continue;
247
+ into.push(s.uuid);
248
+ for (const r of s.riderUuids)
249
+ into.push(r);
250
+ }
251
+ return { full, partial };
252
+ }
@@ -0,0 +1,105 @@
1
+ import type { ImageInput } from './imagesWireCaps.js';
2
+ import type { UserAttachmentDescriptor, UserAttachmentNotIncludedReason, UserAttachmentSource } from './userAttachmentEnvelope.js';
3
+ import type { HumanTurnAttachment, HumanTurnEncoding, HumanTurnInput, HumanTurnMissing } from './humanTurn.js';
4
+ import type { ImageVision } from './liveModelCatalog.js';
5
+ export interface CellView {
6
+ cellType: string | undefined;
7
+ source: string | undefined;
8
+ cellId: string | undefined;
9
+ language: string | undefined;
10
+ outputs: {
11
+ text: string | undefined;
12
+ hasImage: boolean;
13
+ }[];
14
+ outputsTooLarge: boolean;
15
+ }
16
+ export type DescriptorView = {
17
+ kind: 'text';
18
+ source: UserAttachmentSource;
19
+ name: string;
20
+ path: string;
21
+ lines: string[];
22
+ startLine: number;
23
+ totalLines: number;
24
+ complete: boolean;
25
+ } | {
26
+ kind: 'notebook';
27
+ source: UserAttachmentSource;
28
+ name: string;
29
+ path: string;
30
+ cells: CellView[];
31
+ } | {
32
+ kind: 'image';
33
+ source: UserAttachmentSource;
34
+ name: string;
35
+ path: string;
36
+ sizeBytes: number | null;
37
+ delivery: 'attached' | 'not-attached' | undefined;
38
+ } | {
39
+ kind: 'pdf';
40
+ source: UserAttachmentSource;
41
+ name: string;
42
+ path: string;
43
+ sizeBytes: number | null;
44
+ pageCount: number | null;
45
+ } | {
46
+ kind: 'directory';
47
+ name: string;
48
+ path: string;
49
+ entries: string[];
50
+ totalEntries: number;
51
+ } | {
52
+ kind: 'not-included';
53
+ target: 'file' | 'directory' | 'path';
54
+ name: string;
55
+ path: string;
56
+ sizeBytes: number | null;
57
+ reason: UserAttachmentNotIncludedReason;
58
+ };
59
+ export declare function readDescriptor(x: UserAttachmentDescriptor | HumanTurnAttachment['descriptor'], imageDelivery: 'required' | 'ignored'): DescriptorView | undefined;
60
+ type Reason = Exclude<Extract<HumanTurnEncoding, {
61
+ ok: false;
62
+ }>['reason'], 'steer_hold' | 'oversize'>;
63
+ export interface AttachmentView {
64
+ uuid: string;
65
+ d: DescriptorView;
66
+ pixels: {
67
+ data: string;
68
+ mimeType: string;
69
+ } | undefined;
70
+ }
71
+ export interface RiderView {
72
+ uuid: string;
73
+ role: string;
74
+ textIncluded: boolean;
75
+ }
76
+ export interface MissingView {
77
+ kind: HumanTurnMissing['kind'];
78
+ ref: string | undefined;
79
+ reason: HumanTurnMissing['reason'];
80
+ }
81
+ export interface ItemView {
82
+ uuid: string;
83
+ text: string;
84
+ images: ImageInput[];
85
+ attachments: AttachmentView[];
86
+ attachmentIds: string[];
87
+ riders: RiderView[];
88
+ missing: MissingView[];
89
+ }
90
+ export interface InputView {
91
+ lane: 'objective' | 'steer';
92
+ vision: ImageVision;
93
+ otherBodyBytes: number;
94
+ items: ItemView[];
95
+ }
96
+ export declare function readHumanTurnInput(input: HumanTurnInput): InputView | {
97
+ readonly reject: Reason;
98
+ };
99
+ export interface ShareView {
100
+ uuid: string;
101
+ level: 'full' | 'partial' | 'none';
102
+ riderUuids: string[];
103
+ }
104
+ export declare function readEncodingShares(encoding: HumanTurnEncoding): ShareView[] | undefined;
105
+ export {};