@sonordev/contracts 2.22.0 → 2.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/README.md +147 -4
- package/dist/resonance.d.ts +1449 -348
- package/dist/resonance.js +421 -9
- package/dist/resonance.mjs +376 -10
- package/dist/sales-call-prep.d.ts +666 -0
- package/dist/sales-call-prep.js +334 -0
- package/dist/sales-call-prep.mjs +288 -0
- package/dist/signal-experiments.d.ts +0 -1
- package/dist/signal-experiments.js +4 -1
- package/dist/signal-experiments.mjs +4 -1
- package/dist/wire-uuid.d.ts +5 -0
- package/package.json +6 -1
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/contracts/wire-uuid.ts
|
|
4
|
+
var UUID_V1_TO_V8_PATTERN = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89aAbB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/;
|
|
5
|
+
|
|
6
|
+
// src/contracts/wire-schema.ts
|
|
7
|
+
function createWireSchema(fail2, isValidationError) {
|
|
8
|
+
const own = (v, k) => Object.prototype.hasOwnProperty.call(v, k);
|
|
9
|
+
const field2 = (schema, read) => ({ schema, read });
|
|
10
|
+
const text2 = (max = 200, pattern, min = 1) => field2({ type: "string", minLength: min, maxLength: max, ...pattern ? { pattern: pattern.source } : {} }, (v, p) => typeof v === "string" && v.length >= min && v.length <= max && (!pattern || pattern.test(v)) ? v : fail2(p, "invalid string"));
|
|
11
|
+
const choice2 = (...values) => field2({ type: "string", enum: values }, (v, p) => typeof v === "string" && values.includes(v) ? v : fail2(p, "unsupported value"));
|
|
12
|
+
const literal2 = (value) => field2({ const: value }, (v, p) => v === value ? value : fail2(p, "unexpected value"));
|
|
13
|
+
const integer2 = (min = 0, max = Number.MAX_SAFE_INTEGER) => field2({ type: "integer", minimum: min, maximum: max }, (v, p) => typeof v === "number" && Number.isSafeInteger(v) && v >= min && v <= max ? v : fail2(p, "invalid integer"));
|
|
14
|
+
const bool2 = field2({ type: "boolean" }, (v, p) => typeof v === "boolean" ? v : fail2(p, "must be boolean"));
|
|
15
|
+
const optional2 = (f) => ({ ...f, optional: true });
|
|
16
|
+
const nullable2 = (f) => field2({ anyOf: [f.schema, { type: "null" }] }, (v, p) => v === null ? null : f.read(v, p));
|
|
17
|
+
const list2 = (f, max = 100, min = 0) => field2({ type: "array", items: f.schema, minItems: min, maxItems: max }, (v, p) => {
|
|
18
|
+
if (!Array.isArray(v) || v.length < min || v.length > max) fail2(p, "invalid array");
|
|
19
|
+
return v.map((x, i) => f.read(x, `${p}[${i}]`));
|
|
20
|
+
});
|
|
21
|
+
const object2 = (fields) => field2({ type: "object", additionalProperties: false, properties: Object.fromEntries(Object.entries(fields).map(([k, f]) => [k, f.schema])), required: Object.keys(fields).filter((k) => !("optional" in fields[k])) }, (v, p) => {
|
|
22
|
+
if (!v || typeof v !== "object" || Array.isArray(v) || ![Object.prototype, null].includes(Object.getPrototypeOf(v))) fail2(p, "must be a plain object");
|
|
23
|
+
const source = v, result = {};
|
|
24
|
+
for (const key of Reflect.ownKeys(source)) if (typeof key !== "string" || !own(fields, key)) fail2(p, "unknown field");
|
|
25
|
+
for (const [key, f] of Object.entries(fields)) {
|
|
26
|
+
if (!own(source, key)) {
|
|
27
|
+
if ("optional" in f) continue;
|
|
28
|
+
fail2(`${p}.${key}`, "required");
|
|
29
|
+
}
|
|
30
|
+
const descriptor = Object.getOwnPropertyDescriptor(source, key);
|
|
31
|
+
if (!own(descriptor, "value")) fail2(`${p}.${key}`, "accessors are not wire data");
|
|
32
|
+
result[key] = f.read(descriptor.value, `${p}.${key}`);
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
});
|
|
36
|
+
const union2 = (...fields) => field2({ oneOf: fields.map((f) => f.schema) }, (v, p) => {
|
|
37
|
+
const found = [];
|
|
38
|
+
for (const f of fields) {
|
|
39
|
+
try {
|
|
40
|
+
found.push(f.read(v, p));
|
|
41
|
+
} catch (e) {
|
|
42
|
+
if (!isValidationError(e)) throw e;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return found.length === 1 ? found[0] : fail2(p, "must match exactly one supported shape");
|
|
46
|
+
});
|
|
47
|
+
const refine2 = (f, check) => field2(f.schema, (v, p) => {
|
|
48
|
+
const result = f.read(v, p);
|
|
49
|
+
check(result, p);
|
|
50
|
+
return result;
|
|
51
|
+
});
|
|
52
|
+
return { field: field2, text: text2, choice: choice2, literal: literal2, integer: integer2, bool: bool2, optional: optional2, nullable: nullable2, list: list2, object: object2, union: union2, refine: refine2 };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/contracts/sales-call-prep.ts
|
|
56
|
+
var SALES_CALL_PREP_SCHEMA_VERSION = 1;
|
|
57
|
+
var SALES_CALL_PREP_STYLE_POLICY_VERSION = "sales_call_style_v1";
|
|
58
|
+
var SALES_CALL_PREP_OBJECTIVES = ["qualify", "book", "follow_up", "advance"];
|
|
59
|
+
var SALES_CALL_PREP_STYLE_ANCHORS = [
|
|
60
|
+
{ value: 0, label: "Professional" },
|
|
61
|
+
{ value: 33, label: "Conversational" },
|
|
62
|
+
{ value: 67, label: "Bold" },
|
|
63
|
+
{ value: 100, label: "Wild" }
|
|
64
|
+
];
|
|
65
|
+
var SalesCallPrepValidationError = class extends Error {
|
|
66
|
+
constructor(path, reason) {
|
|
67
|
+
super(`${path}: ${reason}`);
|
|
68
|
+
this.path = path;
|
|
69
|
+
this.name = "SalesCallPrepValidationError";
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var fail = (path, reason) => {
|
|
73
|
+
throw new SalesCallPrepValidationError(path, reason);
|
|
74
|
+
};
|
|
75
|
+
var { field, text, choice, literal, integer, bool, optional, nullable, list, object, union, refine } = createWireSchema(fail, (e) => e instanceof SalesCallPrepValidationError);
|
|
76
|
+
var uuid = text(36, UUID_V1_TO_V8_PATTERN);
|
|
77
|
+
var digest = text(64, /^[a-f0-9]{64}$/);
|
|
78
|
+
var revision = text(200);
|
|
79
|
+
var instant = refine(text(30, /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/), (v, p) => {
|
|
80
|
+
if (!Number.isFinite(Date.parse(v)) || new Date(v).toISOString().replace(".000Z", "Z") !== v.replace(".000Z", "Z")) fail(p, "invalid UTC instant");
|
|
81
|
+
});
|
|
82
|
+
function array(item, max, min = 0) {
|
|
83
|
+
const base = list(item, max, min);
|
|
84
|
+
return field(base.schema, (v, p) => {
|
|
85
|
+
if (!Array.isArray(v) || Object.getPrototypeOf(v) !== Array.prototype || v.length > max || v.length < min || Reflect.ownKeys(v).length !== v.length + 1) fail(p, "must be a dense wire array");
|
|
86
|
+
const values = v;
|
|
87
|
+
for (let i = 0; i < values.length; i++) if (!Object.prototype.hasOwnProperty.call(Object.getOwnPropertyDescriptor(v, String(i)) ?? {}, "value")) fail(p, "array accessors or holes are not wire data");
|
|
88
|
+
return base.read(v, p);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
function unique(item, max, key, min = 0) {
|
|
92
|
+
return refine(array(item, max, min), (v, p) => {
|
|
93
|
+
if (new Set(v.map(key)).size !== v.length) fail(p, "duplicate identity");
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
var objective = choice(...SALES_CALL_PREP_OBJECTIVES);
|
|
97
|
+
var styleFields = { objective, style: integer(0, 100), stylePolicyVersion: literal(SALES_CALL_PREP_STYLE_POLICY_VERSION) };
|
|
98
|
+
var request = object({ schemaVersion: literal(1), requestId: uuid, projectId: uuid, selectedContactId: nullable(uuid), ...styleFields, callNotes: text(4e3, void 0, 0), regenerate: bool });
|
|
99
|
+
var parseSalesCallPrepRequest = (v) => request.read(v, "callPrepRequest");
|
|
100
|
+
var SALES_CALL_PREP_REQUEST_JSON_SCHEMA = request.schema;
|
|
101
|
+
var sourceRef = object({ id: text(200), kind: choice("company_research", "website_audit", "crm_history", "seller_brain", "seller_voice", "approved_guidance", "research_principle"), revision: nullable(revision), digest: nullable(digest), observedAt: nullable(instant) });
|
|
102
|
+
var sourceRefs = unique(sourceRef, 30, (v) => v.id);
|
|
103
|
+
var witnessSourceRefs = unique(sourceRef, 100, (v) => v.id);
|
|
104
|
+
var guide = refine(object({
|
|
105
|
+
schemaVersion: literal(1),
|
|
106
|
+
status: choice("ready", "qualify_first", "no_clear_fit", "needs_context"),
|
|
107
|
+
evidenceState: choice("grounded", "limited", "no_clear_fit"),
|
|
108
|
+
opener: nullable(text(1500)),
|
|
109
|
+
alternateOpening: nullable(object({ style: choice("direct", "warm"), text: text(1500) })),
|
|
110
|
+
sourceRefs,
|
|
111
|
+
reason: object({ observation: nullable(text(1500)), evidenceIds: unique(text(200), 30, (v) => v), hypothesis: nullable(text(1500)), unknowns: array(text(500), 10) }),
|
|
112
|
+
diagnosticQuestion: nullable(text(1e3)),
|
|
113
|
+
nextStepInvitation: nullable(text(1500)),
|
|
114
|
+
responses: object({ interested: text(1500), busy: text(1500), has_provider: text(1500), send_info: text(1500), not_a_fit: text(1500) }),
|
|
115
|
+
gracefulClose: text(1e3),
|
|
116
|
+
cautions: array(text(500), 10),
|
|
117
|
+
missingContext: unique(choice("seller_identity", "seller_offer", "call_objective", "research", "follow_up_history"), 5, (v) => v),
|
|
118
|
+
voiceBasis: choice("verified_saved", "neutral_fallback")
|
|
119
|
+
}), (v, p) => {
|
|
120
|
+
if (v.reason.evidenceIds.some((id) => !v.sourceRefs.some((ref) => ref.id === id))) fail(p + ".reason.evidenceIds", "unknown source reference");
|
|
121
|
+
if (v.evidenceState === "grounded" && (!v.reason.observation || !v.reason.evidenceIds.length)) fail(p, "grounded observation needs actual cited evidence");
|
|
122
|
+
if (v.alternateOpening?.text === v.opener) fail(p + ".alternateOpening", "alternate must be distinct");
|
|
123
|
+
if (v.status === "needs_context" && (v.opener !== null || v.alternateOpening !== null || v.diagnosticQuestion !== null || v.nextStepInvitation !== null || v.missingContext.length === 0)) fail(p, "needs_context must identify missing context without a ready script");
|
|
124
|
+
if (v.status === "ready" && (!v.opener || !v.diagnosticQuestion || !v.nextStepInvitation || v.missingContext.length)) fail(p, "ready guide needs opener, diagnostic question and invitation without missing context");
|
|
125
|
+
if (v.status === "qualify_first" && (!v.opener || !v.diagnosticQuestion)) fail(p, "qualify_first needs an opener and diagnostic question");
|
|
126
|
+
});
|
|
127
|
+
var content = refine(object({
|
|
128
|
+
schemaVersion: literal(1),
|
|
129
|
+
businessSummary: text(4e3, void 0, 0),
|
|
130
|
+
topIssues: array(object({ issue: text(1e3), impact: text(1e3), solution: text(1e3) }), 10),
|
|
131
|
+
recommendedOpening: text(1500, void 0, 0),
|
|
132
|
+
likelyObjections: array(object({ objection: text(1500), response: text(1500) }), 10),
|
|
133
|
+
keyQuestions: array(text(1e3), 10),
|
|
134
|
+
competitorContext: optional(text(2e3, void 0, 0)),
|
|
135
|
+
nextJsRationale: optional(text(2e3, void 0, 0)),
|
|
136
|
+
callGuide: guide
|
|
137
|
+
}), (v, p) => {
|
|
138
|
+
if (v.recommendedOpening !== (v.callGuide.opener ?? "")) fail(p + ".recommendedOpening", "compatible opener must match the one guide");
|
|
139
|
+
});
|
|
140
|
+
function parseSalesCallPrepContent(v, actualSources) {
|
|
141
|
+
const parsed = content.read(v, "callPrepContent");
|
|
142
|
+
if (actualSources !== void 0) {
|
|
143
|
+
const actual = witnessSourceRefs.read(actualSources, "actualCallPrepSources");
|
|
144
|
+
for (const ref of parsed.callGuide.sourceRefs) if (!actual.some((source) => stable(source) === stable(ref))) fail("callPrepContent.callGuide.sourceRefs", "source does not match actual context evidence");
|
|
145
|
+
}
|
|
146
|
+
return parsed;
|
|
147
|
+
}
|
|
148
|
+
var SALES_CALL_PREP_CONTENT_JSON_SCHEMA = content.schema;
|
|
149
|
+
var binding = object({ orgId: uuid, projectId: uuid, companyId: uuid, selectedContactId: nullable(uuid), principalContactId: uuid });
|
|
150
|
+
var availability = union(object({ state: literal("available"), revision, digest }), object({ state: literal("unavailable"), reasonCode: choice("not_configured", "not_accessible", "unavailable") }));
|
|
151
|
+
var learningRef = object({ id: uuid, revision, digest });
|
|
152
|
+
var witness = object({ schemaVersion: literal(1), companyDigest: digest, contactDigest: nullable(digest), brain: availability, voice: availability, sourceRefs: witnessSourceRefs, historyDigest: digest, learningRefs: unique(learningRef, 30, (v) => v.id.toLowerCase()), promptVersion: revision, resultSchemaVersion: literal(1) });
|
|
153
|
+
var context = refine(object({ schemaVersion: literal(1), binding, ...styleFields, notesDigest: digest, witness }), (v, p) => {
|
|
154
|
+
if (v.binding.selectedContactId === null !== (v.witness.contactDigest === null)) fail(p + ".witness.contactDigest", "selected contact and actual contact witness must agree");
|
|
155
|
+
});
|
|
156
|
+
var parseSalesCallPrepWitness = (v) => witness.read(v, "callPrepWitness");
|
|
157
|
+
var parseSalesCallPrepContext = (v) => context.read(v, "callPrepContext");
|
|
158
|
+
var SALES_CALL_PREP_CONTEXT_JSON_SCHEMA = context.schema;
|
|
159
|
+
var SALES_CALL_PREP_WITNESS_JSON_SCHEMA = witness.schema;
|
|
160
|
+
function stable(v) {
|
|
161
|
+
if (v === null || typeof v !== "object") return JSON.stringify(v);
|
|
162
|
+
if (Array.isArray(v)) return "[" + v.map(stable).join(",") + "]";
|
|
163
|
+
return "{" + Object.keys(v).sort().map((k) => JSON.stringify(k) + ":" + stable(v[k])).join(",") + "}";
|
|
164
|
+
}
|
|
165
|
+
function witnessProjection(v) {
|
|
166
|
+
const order = (a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
|
|
167
|
+
return { ...v, sourceRefs: [...v.sourceRefs].sort(order), learningRefs: [...v.learningRefs].sort(order) };
|
|
168
|
+
}
|
|
169
|
+
var salesCallPrepRequestDigestInput = (v) => stable(parseSalesCallPrepRequest(v));
|
|
170
|
+
var salesCallPrepContentDigestInput = (v) => stable(parseSalesCallPrepContent(v));
|
|
171
|
+
var salesCallPrepWitnessDigestInput = (v) => stable(witnessProjection(parseSalesCallPrepWitness(v)));
|
|
172
|
+
var salesCallPrepContextDigestInput = (v) => {
|
|
173
|
+
const parsed = parseSalesCallPrepContext(v);
|
|
174
|
+
return stable({ ...parsed, witness: witnessProjection(parsed.witness) });
|
|
175
|
+
};
|
|
176
|
+
function parseSalesCallPrepContentForContext(v, actualContext) {
|
|
177
|
+
const resolved = parseSalesCallPrepContext(actualContext);
|
|
178
|
+
const parsed = parseSalesCallPrepContent(v, resolved.witness.sourceRefs);
|
|
179
|
+
if (parsed.callGuide.voiceBasis === "verified_saved" && resolved.witness.voice.state !== "available") fail("callPrepContent.callGuide.voiceBasis", "verified voice needs actual saved voice context");
|
|
180
|
+
return parsed;
|
|
181
|
+
}
|
|
182
|
+
var versionFields = { schemaVersion: literal(1), requestId: uuid, requestOwnerId: uuid, versionId: uuid, parentVersionId: nullable(uuid), source: choice("generated", "human_edit"), binding, ...styleFields, contextDigest: digest, contentDigest: digest, witnessDigest: digest, createdAt: instant, content };
|
|
183
|
+
var versionReceipt = refine(object(versionFields), (v, p) => {
|
|
184
|
+
if (v.source === "human_edit" && v.parentVersionId === null) fail(p + ".parentVersionId", "human edit requires an actual parent version");
|
|
185
|
+
if (v.parentVersionId?.toLowerCase() === v.versionId.toLowerCase()) fail(p + ".parentVersionId", "version cannot parent itself");
|
|
186
|
+
});
|
|
187
|
+
var parseSalesCallPrepVersion = (v) => versionReceipt.read(v, "callPrepVersion");
|
|
188
|
+
var SALES_CALL_PREP_VERSION_JSON_SCHEMA = versionReceipt.schema;
|
|
189
|
+
var editRequest = object({ schemaVersion: literal(1), requestId: uuid, baseVersionId: uuid, expectedHeadVersionId: uuid, expectedContextDigest: digest, finalContent: content });
|
|
190
|
+
var parseSalesCallPrepEditRequest = (v) => editRequest.read(v, "callPrepEdit");
|
|
191
|
+
var SALES_CALL_PREP_EDIT_REQUEST_JSON_SCHEMA = editRequest.schema;
|
|
192
|
+
var nativeUseRefs = { versionId: uuid, attemptId: uuid, callId: nullable(uuid), manualEventId: nullable(uuid) };
|
|
193
|
+
function checkUseRefs(v, p) {
|
|
194
|
+
if (v.callId === null && v.manualEventId === null) fail(p, "requires an actual native call or manual event");
|
|
195
|
+
}
|
|
196
|
+
var confirmUse = refine(object({ schemaVersion: literal(1), requestId: uuid, ...nativeUseRefs, confirmedUsed: literal(true) }), checkUseRefs);
|
|
197
|
+
var parseSalesCallPrepConfirmUseRequest = (v) => confirmUse.read(v, "callPrepConfirmUse");
|
|
198
|
+
var SALES_CALL_PREP_CONFIRM_USE_REQUEST_JSON_SCHEMA = confirmUse.schema;
|
|
199
|
+
var correction = union(
|
|
200
|
+
refine(object({ schemaVersion: literal(1), requestId: uuid, supersedesUseId: uuid, kind: literal("correct"), reason: text(1e3), ...nativeUseRefs, confirmedUsed: literal(true) }), checkUseRefs),
|
|
201
|
+
object({ schemaVersion: literal(1), requestId: uuid, supersedesUseId: uuid, kind: literal("retract"), reason: text(1e3) })
|
|
202
|
+
);
|
|
203
|
+
var parseSalesCallPrepUseCorrection = (v) => correction.read(v, "callPrepUseCorrection");
|
|
204
|
+
var SALES_CALL_PREP_USE_CORRECTION_JSON_SCHEMA = correction.schema;
|
|
205
|
+
var salesCallPrepEditDigestInput = (v) => stable(parseSalesCallPrepEditRequest(v));
|
|
206
|
+
var salesCallPrepConfirmUseDigestInput = (v) => stable(parseSalesCallPrepConfirmUseRequest(v));
|
|
207
|
+
var salesCallPrepUseCorrectionDigestInput = (v) => stable(parseSalesCallPrepUseCorrection(v));
|
|
208
|
+
var salesCallPrepNotesDigestInput = (v) => stable(text(4e3, void 0, 0).read(v, "callPrepNotes"));
|
|
209
|
+
var eligibleUseRef = object({ useId: uuid, versionId: uuid, sourceDigest: digest });
|
|
210
|
+
var eligibleUseRefs = unique(eligibleUseRef, 100, (v) => v.useId.toLowerCase());
|
|
211
|
+
var outcomeSourceRef = object({ sourceType: choice("call_log", "crm_event", "script_use"), sourceId: uuid, revision, digest, observedAt: instant });
|
|
212
|
+
var summaryFields = {
|
|
213
|
+
schemaVersion: literal(1),
|
|
214
|
+
binding,
|
|
215
|
+
basis: literal("observational_association"),
|
|
216
|
+
privacy: literal("principal_private"),
|
|
217
|
+
generatedAt: instant,
|
|
218
|
+
window: object({ from: instant, to: instant }),
|
|
219
|
+
counts: object({ generatedVersions: integer(0), confirmedUses: integer(0), inferredUses: integer(0), connected: integer(0), qualifiedNextSteps: integer(0), meetingsBooked: integer(0), meetingsHeld: integer(0), dealsWon: integer(0), dealsLost: integer(0), optedOut: integer(0), negativeOrNotFit: integer(0), unknownOutcomes: integer(0), ambiguousManualEvents: integer(0), unresolvedSourceLinks: integer(0) }),
|
|
220
|
+
eligibleUseRefs,
|
|
221
|
+
sourceRefs: unique(outcomeSourceRef, 100, (v) => `${v.sourceType}:${v.sourceId.toLowerCase()}`),
|
|
222
|
+
limitations: array(text(1e3), 10)
|
|
223
|
+
};
|
|
224
|
+
function checkSummary(v, p) {
|
|
225
|
+
if (Date.parse(v.window.from) >= Date.parse(v.window.to) || Date.parse(v.window.to) > Date.parse(v.generatedAt)) fail(p + ".window", "requires a positive observed window ending no later than summary creation");
|
|
226
|
+
}
|
|
227
|
+
var learningSummary = refine(object({ ...summaryFields, snapshotDigest: digest }), checkSummary);
|
|
228
|
+
var parseSalesCallPrepLearningSummary = (v) => learningSummary.read(v, "callPrepLearningSummary");
|
|
229
|
+
var SALES_CALL_PREP_LEARNING_SUMMARY_JSON_SCHEMA = learningSummary.schema;
|
|
230
|
+
var summaryDigestValue = refine(object({ ...summaryFields, snapshotDigest: optional(digest) }), checkSummary);
|
|
231
|
+
function salesCallPrepLearningSummaryDigestInput(v) {
|
|
232
|
+
const { snapshotDigest: _self, ...parsed } = summaryDigestValue.read(v, "callPrepLearningSummaryDigestInput");
|
|
233
|
+
const order = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
234
|
+
return stable({ ...parsed, eligibleUseRefs: [...parsed.eligibleUseRefs].sort((a, b) => order(a.useId, b.useId)), sourceRefs: [...parsed.sourceRefs].sort((a, b) => order(`${a.sourceType}:${a.sourceId}`, `${b.sourceType}:${b.sourceId}`)) });
|
|
235
|
+
}
|
|
236
|
+
var reviewedPrinciple = object({ schemaVersion: literal(1), domain: literal("phone_sales"), ledgerEntryId: uuid, revision, digest, principle: text(1e3), sourceUseRefs: eligibleUseRefs });
|
|
237
|
+
var parseSalesCallPrepReviewedPrinciple = (v) => reviewedPrinciple.read(v, "callPrepReviewedPrinciple");
|
|
238
|
+
var SALES_CALL_PREP_REVIEWED_PRINCIPLE_JSON_SCHEMA = reviewedPrinciple.schema;
|
|
239
|
+
var useReceipt = refine(object({
|
|
240
|
+
schemaVersion: literal(1),
|
|
241
|
+
requestId: uuid,
|
|
242
|
+
useId: uuid,
|
|
243
|
+
rootUseId: uuid,
|
|
244
|
+
supersedesUseId: nullable(uuid),
|
|
245
|
+
kind: choice("use", "correct", "retract"),
|
|
246
|
+
...nativeUseRefs,
|
|
247
|
+
binding,
|
|
248
|
+
confirmedUsed: bool,
|
|
249
|
+
method: nullable(literal("user_confirmed")),
|
|
250
|
+
actorContactId: uuid,
|
|
251
|
+
createdAt: instant,
|
|
252
|
+
reason: nullable(text(1e3)),
|
|
253
|
+
sourceDigest: digest,
|
|
254
|
+
sourceOccurredAt: instant
|
|
255
|
+
}), (v, p) => {
|
|
256
|
+
checkUseRefs(v, p);
|
|
257
|
+
const sameId = (a, b) => a.toLowerCase() === b.toLowerCase();
|
|
258
|
+
if (v.binding.selectedContactId === null || !sameId(v.actorContactId, v.binding.principalContactId)) fail(p, "actual person and human private principal are required for use");
|
|
259
|
+
if (v.kind === "use") {
|
|
260
|
+
if (v.supersedesUseId !== null || !sameId(v.rootUseId, v.useId) || v.reason !== null) fail(p, "initial use must root its own chain without a correction reason");
|
|
261
|
+
} else if (v.supersedesUseId === null || sameId(v.supersedesUseId, v.useId) || sameId(v.rootUseId, v.useId) || v.reason === null) fail(p, "correction requires prior chain identity and reason");
|
|
262
|
+
if (v.kind === "retract" ? v.confirmedUsed || v.method !== null : !v.confirmedUsed || v.method !== "user_confirmed") fail(p, "retraction is not confirmed use; v1 confirmed use requires actual human attestation");
|
|
263
|
+
});
|
|
264
|
+
var parseSalesCallPrepUseReceipt = (v) => useReceipt.read(v, "callPrepUseReceipt");
|
|
265
|
+
var SALES_CALL_PREP_USE_RECEIPT_JSON_SCHEMA = useReceipt.schema;
|
|
266
|
+
var useEligibility = object({ receipt: useReceipt, active: bool, sourceCurrent: bool, sourceAmbiguous: bool });
|
|
267
|
+
var usesPage = object({ items: unique(useEligibility, 100, (v) => v.receipt.useId.toLowerCase()), truncated: bool });
|
|
268
|
+
var parseSalesCallPrepUsesPage = (v) => usesPage.read(v, "callPrepUsesPage");
|
|
269
|
+
var SALES_CALL_PREP_USES_PAGE_JSON_SCHEMA = usesPage.schema;
|
|
270
|
+
var useRetry = object({ companyId: uuid, projectId: uuid, selectedContactId: uuid, callId: nullable(uuid), manualEventId: nullable(uuid) });
|
|
271
|
+
var scriptUseResult = refine(object({ status: choice("saved", "not_saved"), receipt: nullable(useReceipt), retry: nullable(useRetry), code: optional(text(100)) }), (v, p) => {
|
|
272
|
+
if (v.status === "saved" !== (v.receipt !== null)) fail(p, "saved requires the actual persisted use receipt");
|
|
273
|
+
if (v.status === "saved" && v.retry !== null) fail(p, "saved use has no pending retry");
|
|
274
|
+
if (v.retry !== null) checkUseRefs(v.retry, p + ".retry");
|
|
275
|
+
});
|
|
276
|
+
var parseSalesCallPrepScriptUseResult = (v) => scriptUseResult.read(v, "callPrepScriptUseResult");
|
|
277
|
+
var SALES_CALL_PREP_SCRIPT_USE_RESULT_JSON_SCHEMA = scriptUseResult.schema;
|
|
278
|
+
var learningProposalResult = union(
|
|
279
|
+
object({ proposal: literal(null), reason: literal("insufficient_confirmed_use"), basis: literal("observational_association") }),
|
|
280
|
+
object({ proposal: object({ id: uuid, kind: literal("echo_learning"), status: text(80) }), basis: literal("observational_association") })
|
|
281
|
+
);
|
|
282
|
+
var parseSalesCallPrepLearningProposalResult = (v) => learningProposalResult.read(v, "callPrepLearningProposal");
|
|
283
|
+
var SALES_CALL_PREP_LEARNING_PROPOSAL_RESULT_JSON_SCHEMA = learningProposalResult.schema;
|
|
284
|
+
var generateResult = refine(object({ schemaVersion: literal(1), requestId: uuid, reused: bool, version: versionReceipt }), (v, p) => {
|
|
285
|
+
if (!v.reused && (v.requestId.toLowerCase() !== v.version.requestId.toLowerCase() || v.version.source !== "generated")) fail(p, "new generation requires its actual generated request/version receipt");
|
|
286
|
+
});
|
|
287
|
+
var parseSalesCallPrepGenerateResult = (v) => generateResult.read(v, "callPrepGenerateResult");
|
|
288
|
+
var SALES_CALL_PREP_GENERATE_RESULT_JSON_SCHEMA = generateResult.schema;
|
|
289
|
+
|
|
290
|
+
exports.SALES_CALL_PREP_CONFIRM_USE_REQUEST_JSON_SCHEMA = SALES_CALL_PREP_CONFIRM_USE_REQUEST_JSON_SCHEMA;
|
|
291
|
+
exports.SALES_CALL_PREP_CONTENT_JSON_SCHEMA = SALES_CALL_PREP_CONTENT_JSON_SCHEMA;
|
|
292
|
+
exports.SALES_CALL_PREP_CONTEXT_JSON_SCHEMA = SALES_CALL_PREP_CONTEXT_JSON_SCHEMA;
|
|
293
|
+
exports.SALES_CALL_PREP_EDIT_REQUEST_JSON_SCHEMA = SALES_CALL_PREP_EDIT_REQUEST_JSON_SCHEMA;
|
|
294
|
+
exports.SALES_CALL_PREP_GENERATE_RESULT_JSON_SCHEMA = SALES_CALL_PREP_GENERATE_RESULT_JSON_SCHEMA;
|
|
295
|
+
exports.SALES_CALL_PREP_LEARNING_PROPOSAL_RESULT_JSON_SCHEMA = SALES_CALL_PREP_LEARNING_PROPOSAL_RESULT_JSON_SCHEMA;
|
|
296
|
+
exports.SALES_CALL_PREP_LEARNING_SUMMARY_JSON_SCHEMA = SALES_CALL_PREP_LEARNING_SUMMARY_JSON_SCHEMA;
|
|
297
|
+
exports.SALES_CALL_PREP_OBJECTIVES = SALES_CALL_PREP_OBJECTIVES;
|
|
298
|
+
exports.SALES_CALL_PREP_REQUEST_JSON_SCHEMA = SALES_CALL_PREP_REQUEST_JSON_SCHEMA;
|
|
299
|
+
exports.SALES_CALL_PREP_REVIEWED_PRINCIPLE_JSON_SCHEMA = SALES_CALL_PREP_REVIEWED_PRINCIPLE_JSON_SCHEMA;
|
|
300
|
+
exports.SALES_CALL_PREP_SCHEMA_VERSION = SALES_CALL_PREP_SCHEMA_VERSION;
|
|
301
|
+
exports.SALES_CALL_PREP_SCRIPT_USE_RESULT_JSON_SCHEMA = SALES_CALL_PREP_SCRIPT_USE_RESULT_JSON_SCHEMA;
|
|
302
|
+
exports.SALES_CALL_PREP_STYLE_ANCHORS = SALES_CALL_PREP_STYLE_ANCHORS;
|
|
303
|
+
exports.SALES_CALL_PREP_STYLE_POLICY_VERSION = SALES_CALL_PREP_STYLE_POLICY_VERSION;
|
|
304
|
+
exports.SALES_CALL_PREP_USES_PAGE_JSON_SCHEMA = SALES_CALL_PREP_USES_PAGE_JSON_SCHEMA;
|
|
305
|
+
exports.SALES_CALL_PREP_USE_CORRECTION_JSON_SCHEMA = SALES_CALL_PREP_USE_CORRECTION_JSON_SCHEMA;
|
|
306
|
+
exports.SALES_CALL_PREP_USE_RECEIPT_JSON_SCHEMA = SALES_CALL_PREP_USE_RECEIPT_JSON_SCHEMA;
|
|
307
|
+
exports.SALES_CALL_PREP_VERSION_JSON_SCHEMA = SALES_CALL_PREP_VERSION_JSON_SCHEMA;
|
|
308
|
+
exports.SALES_CALL_PREP_WITNESS_JSON_SCHEMA = SALES_CALL_PREP_WITNESS_JSON_SCHEMA;
|
|
309
|
+
exports.SalesCallPrepValidationError = SalesCallPrepValidationError;
|
|
310
|
+
exports.parseSalesCallPrepConfirmUseRequest = parseSalesCallPrepConfirmUseRequest;
|
|
311
|
+
exports.parseSalesCallPrepContent = parseSalesCallPrepContent;
|
|
312
|
+
exports.parseSalesCallPrepContentForContext = parseSalesCallPrepContentForContext;
|
|
313
|
+
exports.parseSalesCallPrepContext = parseSalesCallPrepContext;
|
|
314
|
+
exports.parseSalesCallPrepEditRequest = parseSalesCallPrepEditRequest;
|
|
315
|
+
exports.parseSalesCallPrepGenerateResult = parseSalesCallPrepGenerateResult;
|
|
316
|
+
exports.parseSalesCallPrepLearningProposalResult = parseSalesCallPrepLearningProposalResult;
|
|
317
|
+
exports.parseSalesCallPrepLearningSummary = parseSalesCallPrepLearningSummary;
|
|
318
|
+
exports.parseSalesCallPrepRequest = parseSalesCallPrepRequest;
|
|
319
|
+
exports.parseSalesCallPrepReviewedPrinciple = parseSalesCallPrepReviewedPrinciple;
|
|
320
|
+
exports.parseSalesCallPrepScriptUseResult = parseSalesCallPrepScriptUseResult;
|
|
321
|
+
exports.parseSalesCallPrepUseCorrection = parseSalesCallPrepUseCorrection;
|
|
322
|
+
exports.parseSalesCallPrepUseReceipt = parseSalesCallPrepUseReceipt;
|
|
323
|
+
exports.parseSalesCallPrepUsesPage = parseSalesCallPrepUsesPage;
|
|
324
|
+
exports.parseSalesCallPrepVersion = parseSalesCallPrepVersion;
|
|
325
|
+
exports.parseSalesCallPrepWitness = parseSalesCallPrepWitness;
|
|
326
|
+
exports.salesCallPrepConfirmUseDigestInput = salesCallPrepConfirmUseDigestInput;
|
|
327
|
+
exports.salesCallPrepContentDigestInput = salesCallPrepContentDigestInput;
|
|
328
|
+
exports.salesCallPrepContextDigestInput = salesCallPrepContextDigestInput;
|
|
329
|
+
exports.salesCallPrepEditDigestInput = salesCallPrepEditDigestInput;
|
|
330
|
+
exports.salesCallPrepLearningSummaryDigestInput = salesCallPrepLearningSummaryDigestInput;
|
|
331
|
+
exports.salesCallPrepNotesDigestInput = salesCallPrepNotesDigestInput;
|
|
332
|
+
exports.salesCallPrepRequestDigestInput = salesCallPrepRequestDigestInput;
|
|
333
|
+
exports.salesCallPrepUseCorrectionDigestInput = salesCallPrepUseCorrectionDigestInput;
|
|
334
|
+
exports.salesCallPrepWitnessDigestInput = salesCallPrepWitnessDigestInput;
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
// src/contracts/wire-uuid.ts
|
|
2
|
+
var UUID_V1_TO_V8_PATTERN = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89aAbB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/;
|
|
3
|
+
|
|
4
|
+
// src/contracts/wire-schema.ts
|
|
5
|
+
function createWireSchema(fail2, isValidationError) {
|
|
6
|
+
const own = (v, k) => Object.prototype.hasOwnProperty.call(v, k);
|
|
7
|
+
const field2 = (schema, read) => ({ schema, read });
|
|
8
|
+
const text2 = (max = 200, pattern, min = 1) => field2({ type: "string", minLength: min, maxLength: max, ...pattern ? { pattern: pattern.source } : {} }, (v, p) => typeof v === "string" && v.length >= min && v.length <= max && (!pattern || pattern.test(v)) ? v : fail2(p, "invalid string"));
|
|
9
|
+
const choice2 = (...values) => field2({ type: "string", enum: values }, (v, p) => typeof v === "string" && values.includes(v) ? v : fail2(p, "unsupported value"));
|
|
10
|
+
const literal2 = (value) => field2({ const: value }, (v, p) => v === value ? value : fail2(p, "unexpected value"));
|
|
11
|
+
const integer2 = (min = 0, max = Number.MAX_SAFE_INTEGER) => field2({ type: "integer", minimum: min, maximum: max }, (v, p) => typeof v === "number" && Number.isSafeInteger(v) && v >= min && v <= max ? v : fail2(p, "invalid integer"));
|
|
12
|
+
const bool2 = field2({ type: "boolean" }, (v, p) => typeof v === "boolean" ? v : fail2(p, "must be boolean"));
|
|
13
|
+
const optional2 = (f) => ({ ...f, optional: true });
|
|
14
|
+
const nullable2 = (f) => field2({ anyOf: [f.schema, { type: "null" }] }, (v, p) => v === null ? null : f.read(v, p));
|
|
15
|
+
const list2 = (f, max = 100, min = 0) => field2({ type: "array", items: f.schema, minItems: min, maxItems: max }, (v, p) => {
|
|
16
|
+
if (!Array.isArray(v) || v.length < min || v.length > max) fail2(p, "invalid array");
|
|
17
|
+
return v.map((x, i) => f.read(x, `${p}[${i}]`));
|
|
18
|
+
});
|
|
19
|
+
const object2 = (fields) => field2({ type: "object", additionalProperties: false, properties: Object.fromEntries(Object.entries(fields).map(([k, f]) => [k, f.schema])), required: Object.keys(fields).filter((k) => !("optional" in fields[k])) }, (v, p) => {
|
|
20
|
+
if (!v || typeof v !== "object" || Array.isArray(v) || ![Object.prototype, null].includes(Object.getPrototypeOf(v))) fail2(p, "must be a plain object");
|
|
21
|
+
const source = v, result = {};
|
|
22
|
+
for (const key of Reflect.ownKeys(source)) if (typeof key !== "string" || !own(fields, key)) fail2(p, "unknown field");
|
|
23
|
+
for (const [key, f] of Object.entries(fields)) {
|
|
24
|
+
if (!own(source, key)) {
|
|
25
|
+
if ("optional" in f) continue;
|
|
26
|
+
fail2(`${p}.${key}`, "required");
|
|
27
|
+
}
|
|
28
|
+
const descriptor = Object.getOwnPropertyDescriptor(source, key);
|
|
29
|
+
if (!own(descriptor, "value")) fail2(`${p}.${key}`, "accessors are not wire data");
|
|
30
|
+
result[key] = f.read(descriptor.value, `${p}.${key}`);
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
});
|
|
34
|
+
const union2 = (...fields) => field2({ oneOf: fields.map((f) => f.schema) }, (v, p) => {
|
|
35
|
+
const found = [];
|
|
36
|
+
for (const f of fields) {
|
|
37
|
+
try {
|
|
38
|
+
found.push(f.read(v, p));
|
|
39
|
+
} catch (e) {
|
|
40
|
+
if (!isValidationError(e)) throw e;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return found.length === 1 ? found[0] : fail2(p, "must match exactly one supported shape");
|
|
44
|
+
});
|
|
45
|
+
const refine2 = (f, check) => field2(f.schema, (v, p) => {
|
|
46
|
+
const result = f.read(v, p);
|
|
47
|
+
check(result, p);
|
|
48
|
+
return result;
|
|
49
|
+
});
|
|
50
|
+
return { field: field2, text: text2, choice: choice2, literal: literal2, integer: integer2, bool: bool2, optional: optional2, nullable: nullable2, list: list2, object: object2, union: union2, refine: refine2 };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/contracts/sales-call-prep.ts
|
|
54
|
+
var SALES_CALL_PREP_SCHEMA_VERSION = 1;
|
|
55
|
+
var SALES_CALL_PREP_STYLE_POLICY_VERSION = "sales_call_style_v1";
|
|
56
|
+
var SALES_CALL_PREP_OBJECTIVES = ["qualify", "book", "follow_up", "advance"];
|
|
57
|
+
var SALES_CALL_PREP_STYLE_ANCHORS = [
|
|
58
|
+
{ value: 0, label: "Professional" },
|
|
59
|
+
{ value: 33, label: "Conversational" },
|
|
60
|
+
{ value: 67, label: "Bold" },
|
|
61
|
+
{ value: 100, label: "Wild" }
|
|
62
|
+
];
|
|
63
|
+
var SalesCallPrepValidationError = class extends Error {
|
|
64
|
+
constructor(path, reason) {
|
|
65
|
+
super(`${path}: ${reason}`);
|
|
66
|
+
this.path = path;
|
|
67
|
+
this.name = "SalesCallPrepValidationError";
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
var fail = (path, reason) => {
|
|
71
|
+
throw new SalesCallPrepValidationError(path, reason);
|
|
72
|
+
};
|
|
73
|
+
var { field, text, choice, literal, integer, bool, optional, nullable, list, object, union, refine } = createWireSchema(fail, (e) => e instanceof SalesCallPrepValidationError);
|
|
74
|
+
var uuid = text(36, UUID_V1_TO_V8_PATTERN);
|
|
75
|
+
var digest = text(64, /^[a-f0-9]{64}$/);
|
|
76
|
+
var revision = text(200);
|
|
77
|
+
var instant = refine(text(30, /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/), (v, p) => {
|
|
78
|
+
if (!Number.isFinite(Date.parse(v)) || new Date(v).toISOString().replace(".000Z", "Z") !== v.replace(".000Z", "Z")) fail(p, "invalid UTC instant");
|
|
79
|
+
});
|
|
80
|
+
function array(item, max, min = 0) {
|
|
81
|
+
const base = list(item, max, min);
|
|
82
|
+
return field(base.schema, (v, p) => {
|
|
83
|
+
if (!Array.isArray(v) || Object.getPrototypeOf(v) !== Array.prototype || v.length > max || v.length < min || Reflect.ownKeys(v).length !== v.length + 1) fail(p, "must be a dense wire array");
|
|
84
|
+
const values = v;
|
|
85
|
+
for (let i = 0; i < values.length; i++) if (!Object.prototype.hasOwnProperty.call(Object.getOwnPropertyDescriptor(v, String(i)) ?? {}, "value")) fail(p, "array accessors or holes are not wire data");
|
|
86
|
+
return base.read(v, p);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function unique(item, max, key, min = 0) {
|
|
90
|
+
return refine(array(item, max, min), (v, p) => {
|
|
91
|
+
if (new Set(v.map(key)).size !== v.length) fail(p, "duplicate identity");
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
var objective = choice(...SALES_CALL_PREP_OBJECTIVES);
|
|
95
|
+
var styleFields = { objective, style: integer(0, 100), stylePolicyVersion: literal(SALES_CALL_PREP_STYLE_POLICY_VERSION) };
|
|
96
|
+
var request = object({ schemaVersion: literal(1), requestId: uuid, projectId: uuid, selectedContactId: nullable(uuid), ...styleFields, callNotes: text(4e3, void 0, 0), regenerate: bool });
|
|
97
|
+
var parseSalesCallPrepRequest = (v) => request.read(v, "callPrepRequest");
|
|
98
|
+
var SALES_CALL_PREP_REQUEST_JSON_SCHEMA = request.schema;
|
|
99
|
+
var sourceRef = object({ id: text(200), kind: choice("company_research", "website_audit", "crm_history", "seller_brain", "seller_voice", "approved_guidance", "research_principle"), revision: nullable(revision), digest: nullable(digest), observedAt: nullable(instant) });
|
|
100
|
+
var sourceRefs = unique(sourceRef, 30, (v) => v.id);
|
|
101
|
+
var witnessSourceRefs = unique(sourceRef, 100, (v) => v.id);
|
|
102
|
+
var guide = refine(object({
|
|
103
|
+
schemaVersion: literal(1),
|
|
104
|
+
status: choice("ready", "qualify_first", "no_clear_fit", "needs_context"),
|
|
105
|
+
evidenceState: choice("grounded", "limited", "no_clear_fit"),
|
|
106
|
+
opener: nullable(text(1500)),
|
|
107
|
+
alternateOpening: nullable(object({ style: choice("direct", "warm"), text: text(1500) })),
|
|
108
|
+
sourceRefs,
|
|
109
|
+
reason: object({ observation: nullable(text(1500)), evidenceIds: unique(text(200), 30, (v) => v), hypothesis: nullable(text(1500)), unknowns: array(text(500), 10) }),
|
|
110
|
+
diagnosticQuestion: nullable(text(1e3)),
|
|
111
|
+
nextStepInvitation: nullable(text(1500)),
|
|
112
|
+
responses: object({ interested: text(1500), busy: text(1500), has_provider: text(1500), send_info: text(1500), not_a_fit: text(1500) }),
|
|
113
|
+
gracefulClose: text(1e3),
|
|
114
|
+
cautions: array(text(500), 10),
|
|
115
|
+
missingContext: unique(choice("seller_identity", "seller_offer", "call_objective", "research", "follow_up_history"), 5, (v) => v),
|
|
116
|
+
voiceBasis: choice("verified_saved", "neutral_fallback")
|
|
117
|
+
}), (v, p) => {
|
|
118
|
+
if (v.reason.evidenceIds.some((id) => !v.sourceRefs.some((ref) => ref.id === id))) fail(p + ".reason.evidenceIds", "unknown source reference");
|
|
119
|
+
if (v.evidenceState === "grounded" && (!v.reason.observation || !v.reason.evidenceIds.length)) fail(p, "grounded observation needs actual cited evidence");
|
|
120
|
+
if (v.alternateOpening?.text === v.opener) fail(p + ".alternateOpening", "alternate must be distinct");
|
|
121
|
+
if (v.status === "needs_context" && (v.opener !== null || v.alternateOpening !== null || v.diagnosticQuestion !== null || v.nextStepInvitation !== null || v.missingContext.length === 0)) fail(p, "needs_context must identify missing context without a ready script");
|
|
122
|
+
if (v.status === "ready" && (!v.opener || !v.diagnosticQuestion || !v.nextStepInvitation || v.missingContext.length)) fail(p, "ready guide needs opener, diagnostic question and invitation without missing context");
|
|
123
|
+
if (v.status === "qualify_first" && (!v.opener || !v.diagnosticQuestion)) fail(p, "qualify_first needs an opener and diagnostic question");
|
|
124
|
+
});
|
|
125
|
+
var content = refine(object({
|
|
126
|
+
schemaVersion: literal(1),
|
|
127
|
+
businessSummary: text(4e3, void 0, 0),
|
|
128
|
+
topIssues: array(object({ issue: text(1e3), impact: text(1e3), solution: text(1e3) }), 10),
|
|
129
|
+
recommendedOpening: text(1500, void 0, 0),
|
|
130
|
+
likelyObjections: array(object({ objection: text(1500), response: text(1500) }), 10),
|
|
131
|
+
keyQuestions: array(text(1e3), 10),
|
|
132
|
+
competitorContext: optional(text(2e3, void 0, 0)),
|
|
133
|
+
nextJsRationale: optional(text(2e3, void 0, 0)),
|
|
134
|
+
callGuide: guide
|
|
135
|
+
}), (v, p) => {
|
|
136
|
+
if (v.recommendedOpening !== (v.callGuide.opener ?? "")) fail(p + ".recommendedOpening", "compatible opener must match the one guide");
|
|
137
|
+
});
|
|
138
|
+
function parseSalesCallPrepContent(v, actualSources) {
|
|
139
|
+
const parsed = content.read(v, "callPrepContent");
|
|
140
|
+
if (actualSources !== void 0) {
|
|
141
|
+
const actual = witnessSourceRefs.read(actualSources, "actualCallPrepSources");
|
|
142
|
+
for (const ref of parsed.callGuide.sourceRefs) if (!actual.some((source) => stable(source) === stable(ref))) fail("callPrepContent.callGuide.sourceRefs", "source does not match actual context evidence");
|
|
143
|
+
}
|
|
144
|
+
return parsed;
|
|
145
|
+
}
|
|
146
|
+
var SALES_CALL_PREP_CONTENT_JSON_SCHEMA = content.schema;
|
|
147
|
+
var binding = object({ orgId: uuid, projectId: uuid, companyId: uuid, selectedContactId: nullable(uuid), principalContactId: uuid });
|
|
148
|
+
var availability = union(object({ state: literal("available"), revision, digest }), object({ state: literal("unavailable"), reasonCode: choice("not_configured", "not_accessible", "unavailable") }));
|
|
149
|
+
var learningRef = object({ id: uuid, revision, digest });
|
|
150
|
+
var witness = object({ schemaVersion: literal(1), companyDigest: digest, contactDigest: nullable(digest), brain: availability, voice: availability, sourceRefs: witnessSourceRefs, historyDigest: digest, learningRefs: unique(learningRef, 30, (v) => v.id.toLowerCase()), promptVersion: revision, resultSchemaVersion: literal(1) });
|
|
151
|
+
var context = refine(object({ schemaVersion: literal(1), binding, ...styleFields, notesDigest: digest, witness }), (v, p) => {
|
|
152
|
+
if (v.binding.selectedContactId === null !== (v.witness.contactDigest === null)) fail(p + ".witness.contactDigest", "selected contact and actual contact witness must agree");
|
|
153
|
+
});
|
|
154
|
+
var parseSalesCallPrepWitness = (v) => witness.read(v, "callPrepWitness");
|
|
155
|
+
var parseSalesCallPrepContext = (v) => context.read(v, "callPrepContext");
|
|
156
|
+
var SALES_CALL_PREP_CONTEXT_JSON_SCHEMA = context.schema;
|
|
157
|
+
var SALES_CALL_PREP_WITNESS_JSON_SCHEMA = witness.schema;
|
|
158
|
+
function stable(v) {
|
|
159
|
+
if (v === null || typeof v !== "object") return JSON.stringify(v);
|
|
160
|
+
if (Array.isArray(v)) return "[" + v.map(stable).join(",") + "]";
|
|
161
|
+
return "{" + Object.keys(v).sort().map((k) => JSON.stringify(k) + ":" + stable(v[k])).join(",") + "}";
|
|
162
|
+
}
|
|
163
|
+
function witnessProjection(v) {
|
|
164
|
+
const order = (a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
|
|
165
|
+
return { ...v, sourceRefs: [...v.sourceRefs].sort(order), learningRefs: [...v.learningRefs].sort(order) };
|
|
166
|
+
}
|
|
167
|
+
var salesCallPrepRequestDigestInput = (v) => stable(parseSalesCallPrepRequest(v));
|
|
168
|
+
var salesCallPrepContentDigestInput = (v) => stable(parseSalesCallPrepContent(v));
|
|
169
|
+
var salesCallPrepWitnessDigestInput = (v) => stable(witnessProjection(parseSalesCallPrepWitness(v)));
|
|
170
|
+
var salesCallPrepContextDigestInput = (v) => {
|
|
171
|
+
const parsed = parseSalesCallPrepContext(v);
|
|
172
|
+
return stable({ ...parsed, witness: witnessProjection(parsed.witness) });
|
|
173
|
+
};
|
|
174
|
+
function parseSalesCallPrepContentForContext(v, actualContext) {
|
|
175
|
+
const resolved = parseSalesCallPrepContext(actualContext);
|
|
176
|
+
const parsed = parseSalesCallPrepContent(v, resolved.witness.sourceRefs);
|
|
177
|
+
if (parsed.callGuide.voiceBasis === "verified_saved" && resolved.witness.voice.state !== "available") fail("callPrepContent.callGuide.voiceBasis", "verified voice needs actual saved voice context");
|
|
178
|
+
return parsed;
|
|
179
|
+
}
|
|
180
|
+
var versionFields = { schemaVersion: literal(1), requestId: uuid, requestOwnerId: uuid, versionId: uuid, parentVersionId: nullable(uuid), source: choice("generated", "human_edit"), binding, ...styleFields, contextDigest: digest, contentDigest: digest, witnessDigest: digest, createdAt: instant, content };
|
|
181
|
+
var versionReceipt = refine(object(versionFields), (v, p) => {
|
|
182
|
+
if (v.source === "human_edit" && v.parentVersionId === null) fail(p + ".parentVersionId", "human edit requires an actual parent version");
|
|
183
|
+
if (v.parentVersionId?.toLowerCase() === v.versionId.toLowerCase()) fail(p + ".parentVersionId", "version cannot parent itself");
|
|
184
|
+
});
|
|
185
|
+
var parseSalesCallPrepVersion = (v) => versionReceipt.read(v, "callPrepVersion");
|
|
186
|
+
var SALES_CALL_PREP_VERSION_JSON_SCHEMA = versionReceipt.schema;
|
|
187
|
+
var editRequest = object({ schemaVersion: literal(1), requestId: uuid, baseVersionId: uuid, expectedHeadVersionId: uuid, expectedContextDigest: digest, finalContent: content });
|
|
188
|
+
var parseSalesCallPrepEditRequest = (v) => editRequest.read(v, "callPrepEdit");
|
|
189
|
+
var SALES_CALL_PREP_EDIT_REQUEST_JSON_SCHEMA = editRequest.schema;
|
|
190
|
+
var nativeUseRefs = { versionId: uuid, attemptId: uuid, callId: nullable(uuid), manualEventId: nullable(uuid) };
|
|
191
|
+
function checkUseRefs(v, p) {
|
|
192
|
+
if (v.callId === null && v.manualEventId === null) fail(p, "requires an actual native call or manual event");
|
|
193
|
+
}
|
|
194
|
+
var confirmUse = refine(object({ schemaVersion: literal(1), requestId: uuid, ...nativeUseRefs, confirmedUsed: literal(true) }), checkUseRefs);
|
|
195
|
+
var parseSalesCallPrepConfirmUseRequest = (v) => confirmUse.read(v, "callPrepConfirmUse");
|
|
196
|
+
var SALES_CALL_PREP_CONFIRM_USE_REQUEST_JSON_SCHEMA = confirmUse.schema;
|
|
197
|
+
var correction = union(
|
|
198
|
+
refine(object({ schemaVersion: literal(1), requestId: uuid, supersedesUseId: uuid, kind: literal("correct"), reason: text(1e3), ...nativeUseRefs, confirmedUsed: literal(true) }), checkUseRefs),
|
|
199
|
+
object({ schemaVersion: literal(1), requestId: uuid, supersedesUseId: uuid, kind: literal("retract"), reason: text(1e3) })
|
|
200
|
+
);
|
|
201
|
+
var parseSalesCallPrepUseCorrection = (v) => correction.read(v, "callPrepUseCorrection");
|
|
202
|
+
var SALES_CALL_PREP_USE_CORRECTION_JSON_SCHEMA = correction.schema;
|
|
203
|
+
var salesCallPrepEditDigestInput = (v) => stable(parseSalesCallPrepEditRequest(v));
|
|
204
|
+
var salesCallPrepConfirmUseDigestInput = (v) => stable(parseSalesCallPrepConfirmUseRequest(v));
|
|
205
|
+
var salesCallPrepUseCorrectionDigestInput = (v) => stable(parseSalesCallPrepUseCorrection(v));
|
|
206
|
+
var salesCallPrepNotesDigestInput = (v) => stable(text(4e3, void 0, 0).read(v, "callPrepNotes"));
|
|
207
|
+
var eligibleUseRef = object({ useId: uuid, versionId: uuid, sourceDigest: digest });
|
|
208
|
+
var eligibleUseRefs = unique(eligibleUseRef, 100, (v) => v.useId.toLowerCase());
|
|
209
|
+
var outcomeSourceRef = object({ sourceType: choice("call_log", "crm_event", "script_use"), sourceId: uuid, revision, digest, observedAt: instant });
|
|
210
|
+
var summaryFields = {
|
|
211
|
+
schemaVersion: literal(1),
|
|
212
|
+
binding,
|
|
213
|
+
basis: literal("observational_association"),
|
|
214
|
+
privacy: literal("principal_private"),
|
|
215
|
+
generatedAt: instant,
|
|
216
|
+
window: object({ from: instant, to: instant }),
|
|
217
|
+
counts: object({ generatedVersions: integer(0), confirmedUses: integer(0), inferredUses: integer(0), connected: integer(0), qualifiedNextSteps: integer(0), meetingsBooked: integer(0), meetingsHeld: integer(0), dealsWon: integer(0), dealsLost: integer(0), optedOut: integer(0), negativeOrNotFit: integer(0), unknownOutcomes: integer(0), ambiguousManualEvents: integer(0), unresolvedSourceLinks: integer(0) }),
|
|
218
|
+
eligibleUseRefs,
|
|
219
|
+
sourceRefs: unique(outcomeSourceRef, 100, (v) => `${v.sourceType}:${v.sourceId.toLowerCase()}`),
|
|
220
|
+
limitations: array(text(1e3), 10)
|
|
221
|
+
};
|
|
222
|
+
function checkSummary(v, p) {
|
|
223
|
+
if (Date.parse(v.window.from) >= Date.parse(v.window.to) || Date.parse(v.window.to) > Date.parse(v.generatedAt)) fail(p + ".window", "requires a positive observed window ending no later than summary creation");
|
|
224
|
+
}
|
|
225
|
+
var learningSummary = refine(object({ ...summaryFields, snapshotDigest: digest }), checkSummary);
|
|
226
|
+
var parseSalesCallPrepLearningSummary = (v) => learningSummary.read(v, "callPrepLearningSummary");
|
|
227
|
+
var SALES_CALL_PREP_LEARNING_SUMMARY_JSON_SCHEMA = learningSummary.schema;
|
|
228
|
+
var summaryDigestValue = refine(object({ ...summaryFields, snapshotDigest: optional(digest) }), checkSummary);
|
|
229
|
+
function salesCallPrepLearningSummaryDigestInput(v) {
|
|
230
|
+
const { snapshotDigest: _self, ...parsed } = summaryDigestValue.read(v, "callPrepLearningSummaryDigestInput");
|
|
231
|
+
const order = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
232
|
+
return stable({ ...parsed, eligibleUseRefs: [...parsed.eligibleUseRefs].sort((a, b) => order(a.useId, b.useId)), sourceRefs: [...parsed.sourceRefs].sort((a, b) => order(`${a.sourceType}:${a.sourceId}`, `${b.sourceType}:${b.sourceId}`)) });
|
|
233
|
+
}
|
|
234
|
+
var reviewedPrinciple = object({ schemaVersion: literal(1), domain: literal("phone_sales"), ledgerEntryId: uuid, revision, digest, principle: text(1e3), sourceUseRefs: eligibleUseRefs });
|
|
235
|
+
var parseSalesCallPrepReviewedPrinciple = (v) => reviewedPrinciple.read(v, "callPrepReviewedPrinciple");
|
|
236
|
+
var SALES_CALL_PREP_REVIEWED_PRINCIPLE_JSON_SCHEMA = reviewedPrinciple.schema;
|
|
237
|
+
var useReceipt = refine(object({
|
|
238
|
+
schemaVersion: literal(1),
|
|
239
|
+
requestId: uuid,
|
|
240
|
+
useId: uuid,
|
|
241
|
+
rootUseId: uuid,
|
|
242
|
+
supersedesUseId: nullable(uuid),
|
|
243
|
+
kind: choice("use", "correct", "retract"),
|
|
244
|
+
...nativeUseRefs,
|
|
245
|
+
binding,
|
|
246
|
+
confirmedUsed: bool,
|
|
247
|
+
method: nullable(literal("user_confirmed")),
|
|
248
|
+
actorContactId: uuid,
|
|
249
|
+
createdAt: instant,
|
|
250
|
+
reason: nullable(text(1e3)),
|
|
251
|
+
sourceDigest: digest,
|
|
252
|
+
sourceOccurredAt: instant
|
|
253
|
+
}), (v, p) => {
|
|
254
|
+
checkUseRefs(v, p);
|
|
255
|
+
const sameId = (a, b) => a.toLowerCase() === b.toLowerCase();
|
|
256
|
+
if (v.binding.selectedContactId === null || !sameId(v.actorContactId, v.binding.principalContactId)) fail(p, "actual person and human private principal are required for use");
|
|
257
|
+
if (v.kind === "use") {
|
|
258
|
+
if (v.supersedesUseId !== null || !sameId(v.rootUseId, v.useId) || v.reason !== null) fail(p, "initial use must root its own chain without a correction reason");
|
|
259
|
+
} else if (v.supersedesUseId === null || sameId(v.supersedesUseId, v.useId) || sameId(v.rootUseId, v.useId) || v.reason === null) fail(p, "correction requires prior chain identity and reason");
|
|
260
|
+
if (v.kind === "retract" ? v.confirmedUsed || v.method !== null : !v.confirmedUsed || v.method !== "user_confirmed") fail(p, "retraction is not confirmed use; v1 confirmed use requires actual human attestation");
|
|
261
|
+
});
|
|
262
|
+
var parseSalesCallPrepUseReceipt = (v) => useReceipt.read(v, "callPrepUseReceipt");
|
|
263
|
+
var SALES_CALL_PREP_USE_RECEIPT_JSON_SCHEMA = useReceipt.schema;
|
|
264
|
+
var useEligibility = object({ receipt: useReceipt, active: bool, sourceCurrent: bool, sourceAmbiguous: bool });
|
|
265
|
+
var usesPage = object({ items: unique(useEligibility, 100, (v) => v.receipt.useId.toLowerCase()), truncated: bool });
|
|
266
|
+
var parseSalesCallPrepUsesPage = (v) => usesPage.read(v, "callPrepUsesPage");
|
|
267
|
+
var SALES_CALL_PREP_USES_PAGE_JSON_SCHEMA = usesPage.schema;
|
|
268
|
+
var useRetry = object({ companyId: uuid, projectId: uuid, selectedContactId: uuid, callId: nullable(uuid), manualEventId: nullable(uuid) });
|
|
269
|
+
var scriptUseResult = refine(object({ status: choice("saved", "not_saved"), receipt: nullable(useReceipt), retry: nullable(useRetry), code: optional(text(100)) }), (v, p) => {
|
|
270
|
+
if (v.status === "saved" !== (v.receipt !== null)) fail(p, "saved requires the actual persisted use receipt");
|
|
271
|
+
if (v.status === "saved" && v.retry !== null) fail(p, "saved use has no pending retry");
|
|
272
|
+
if (v.retry !== null) checkUseRefs(v.retry, p + ".retry");
|
|
273
|
+
});
|
|
274
|
+
var parseSalesCallPrepScriptUseResult = (v) => scriptUseResult.read(v, "callPrepScriptUseResult");
|
|
275
|
+
var SALES_CALL_PREP_SCRIPT_USE_RESULT_JSON_SCHEMA = scriptUseResult.schema;
|
|
276
|
+
var learningProposalResult = union(
|
|
277
|
+
object({ proposal: literal(null), reason: literal("insufficient_confirmed_use"), basis: literal("observational_association") }),
|
|
278
|
+
object({ proposal: object({ id: uuid, kind: literal("echo_learning"), status: text(80) }), basis: literal("observational_association") })
|
|
279
|
+
);
|
|
280
|
+
var parseSalesCallPrepLearningProposalResult = (v) => learningProposalResult.read(v, "callPrepLearningProposal");
|
|
281
|
+
var SALES_CALL_PREP_LEARNING_PROPOSAL_RESULT_JSON_SCHEMA = learningProposalResult.schema;
|
|
282
|
+
var generateResult = refine(object({ schemaVersion: literal(1), requestId: uuid, reused: bool, version: versionReceipt }), (v, p) => {
|
|
283
|
+
if (!v.reused && (v.requestId.toLowerCase() !== v.version.requestId.toLowerCase() || v.version.source !== "generated")) fail(p, "new generation requires its actual generated request/version receipt");
|
|
284
|
+
});
|
|
285
|
+
var parseSalesCallPrepGenerateResult = (v) => generateResult.read(v, "callPrepGenerateResult");
|
|
286
|
+
var SALES_CALL_PREP_GENERATE_RESULT_JSON_SCHEMA = generateResult.schema;
|
|
287
|
+
|
|
288
|
+
export { SALES_CALL_PREP_CONFIRM_USE_REQUEST_JSON_SCHEMA, SALES_CALL_PREP_CONTENT_JSON_SCHEMA, SALES_CALL_PREP_CONTEXT_JSON_SCHEMA, SALES_CALL_PREP_EDIT_REQUEST_JSON_SCHEMA, SALES_CALL_PREP_GENERATE_RESULT_JSON_SCHEMA, SALES_CALL_PREP_LEARNING_PROPOSAL_RESULT_JSON_SCHEMA, SALES_CALL_PREP_LEARNING_SUMMARY_JSON_SCHEMA, SALES_CALL_PREP_OBJECTIVES, SALES_CALL_PREP_REQUEST_JSON_SCHEMA, SALES_CALL_PREP_REVIEWED_PRINCIPLE_JSON_SCHEMA, SALES_CALL_PREP_SCHEMA_VERSION, SALES_CALL_PREP_SCRIPT_USE_RESULT_JSON_SCHEMA, SALES_CALL_PREP_STYLE_ANCHORS, SALES_CALL_PREP_STYLE_POLICY_VERSION, SALES_CALL_PREP_USES_PAGE_JSON_SCHEMA, SALES_CALL_PREP_USE_CORRECTION_JSON_SCHEMA, SALES_CALL_PREP_USE_RECEIPT_JSON_SCHEMA, SALES_CALL_PREP_VERSION_JSON_SCHEMA, SALES_CALL_PREP_WITNESS_JSON_SCHEMA, SalesCallPrepValidationError, parseSalesCallPrepConfirmUseRequest, parseSalesCallPrepContent, parseSalesCallPrepContentForContext, parseSalesCallPrepContext, parseSalesCallPrepEditRequest, parseSalesCallPrepGenerateResult, parseSalesCallPrepLearningProposalResult, parseSalesCallPrepLearningSummary, parseSalesCallPrepRequest, parseSalesCallPrepReviewedPrinciple, parseSalesCallPrepScriptUseResult, parseSalesCallPrepUseCorrection, parseSalesCallPrepUseReceipt, parseSalesCallPrepUsesPage, parseSalesCallPrepVersion, parseSalesCallPrepWitness, salesCallPrepConfirmUseDigestInput, salesCallPrepContentDigestInput, salesCallPrepContextDigestInput, salesCallPrepEditDigestInput, salesCallPrepLearningSummaryDigestInput, salesCallPrepNotesDigestInput, salesCallPrepRequestDigestInput, salesCallPrepUseCorrectionDigestInput, salesCallPrepWitnessDigestInput };
|