@company-semantics/contracts 91.1.0 → 93.0.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 (68) hide show
  1. package/package.json +11 -10
  2. package/src/action-items/README.md +12 -4
  3. package/src/action-items/schemas.ts +10 -0
  4. package/src/affordances/README.md +52 -1
  5. package/src/affordances/__tests__/README.md +10 -1
  6. package/src/affordances/__tests__/affordances.test.ts +13 -1
  7. package/src/affordances/__tests__/catalog-wave.test.ts +237 -0
  8. package/src/affordances/affordance.ts +56 -4
  9. package/src/affordances/args.ts +44 -1
  10. package/src/affordances/available.ts +59 -0
  11. package/src/affordances/coverage.ts +51 -0
  12. package/src/affordances/ids.ts +28 -0
  13. package/src/affordances/index.ts +17 -0
  14. package/src/api/README.md +1 -0
  15. package/src/api/generated-spec-hash.ts +2 -2
  16. package/src/api/generated.ts +401 -11
  17. package/src/api/primitives.ts +13 -0
  18. package/src/billing/README.md +1 -0
  19. package/src/billing/refusals.ts +12 -0
  20. package/src/message-parts/README.md +5 -0
  21. package/src/message-parts/affordance-offer.ts +44 -0
  22. package/src/message-parts/index.ts +7 -0
  23. package/src/message-parts/types.ts +7 -1
  24. package/src/message-parts/wire.ts +18 -0
  25. package/src/notifications/README.md +17 -3
  26. package/src/notifications/__tests__/README.md +4 -0
  27. package/src/notifications/__tests__/__snapshots__/render-snapshot.test.ts.snap +27 -25
  28. package/src/notifications/__tests__/fixtures.ts +7 -1
  29. package/src/notifications/__tests__/grounded-ctas.test.ts +103 -0
  30. package/src/notifications/__tests__/render-snapshot.test.ts +1 -1
  31. package/src/notifications/content.ts +9 -0
  32. package/src/notifications/kinds/billing-auto-recharge-failed.ts +4 -2
  33. package/src/notifications/kinds/billing-payment-past-due.ts +2 -0
  34. package/src/notifications/kinds/billing-suspended.ts +2 -0
  35. package/src/notifications/kinds/chat-shared.ts +10 -3
  36. package/src/notifications/kinds/company-md-access-approved.ts +13 -6
  37. package/src/notifications/kinds/share-granted.ts +1 -1
  38. package/src/notifications/kinds/unit-owner-granted.ts +9 -2
  39. package/src/notifications/payloads.ts +6 -0
  40. package/src/proactive/README.md +18 -2
  41. package/src/proactive/__tests__/README.md +11 -1
  42. package/src/proactive/__tests__/chat-templates.test.ts +7 -6
  43. package/src/proactive/__tests__/proactive-offers.test.ts +124 -0
  44. package/src/proactive/__tests__/vocabulary.test.ts +1 -1
  45. package/src/proactive/composer.ts +11 -0
  46. package/src/proactive/templates/README.md +11 -3
  47. package/src/proactive/templates/billing-auto-recharge-failed.ts +1 -0
  48. package/src/proactive/templates/billing-balance-exhausted.ts +2 -6
  49. package/src/proactive/templates/billing-payment-past-due.ts +1 -0
  50. package/src/proactive/templates/billing-subscription-canceled.ts +1 -5
  51. package/src/proactive/templates/billing-suspended.ts +1 -0
  52. package/src/proactive/templates/morning-brief.ts +1 -0
  53. package/src/proactive/templates/org-became-shared.ts +4 -3
  54. package/src/proactive/templates/source-sync-review-ready.ts +3 -8
  55. package/src/proactive/templates/workflow-needs-attention.ts +1 -0
  56. package/src/rate-limit/README.md +27 -1
  57. package/src/rate-limit/__tests__/README.md +23 -0
  58. package/src/rate-limit/__tests__/rate-limited-error.test.ts +53 -0
  59. package/src/rate-limit/index.ts +33 -0
  60. package/src/root-exports/agent-runtime.ts +14 -2
  61. package/src/root-exports/delivery.ts +15 -0
  62. package/src/source-sync/README.md +2 -1
  63. package/src/source-sync/__tests__/approval-schemas.test.ts +2 -13
  64. package/src/source-sync/__tests__/current-synthesis.test.ts +1 -0
  65. package/src/source-sync/__tests__/schemas.test.ts +5 -32
  66. package/src/source-sync/schemas.ts +6 -15
  67. package/src/workflows/deferred-route.ts +2 -0
  68. package/src/workflows/outcome-reasons.ts +4 -0
@@ -299,13 +299,24 @@ export {
299
299
  AFFORDANCE_UNAVAILABLE_REASONS,
300
300
  AffordanceAvailabilityIdSchema,
301
301
  AffordanceAvailabilitySchema,
302
+ AffordanceCoverageSchema,
302
303
  AffordanceIdSchema,
303
304
  AffordanceSchema,
305
+ AvailableAffordanceSchema,
306
+ AvailableAffordancesSchema,
307
+ ChatOpenArgsSchema,
308
+ CompanyMdDocArgsSchema,
309
+ ExecutionOpenArgsSchema,
304
310
  MAX_OFFERED_AFFORDANCES,
311
+ NO_AFFORDANCE_REASONS,
305
312
  NO_ARG_AFFORDANCE_IDS,
313
+ NoAffordanceReasonSchema,
306
314
  OfferedAffordanceSchema,
315
+ OrgStructureOpenReviewArgsSchema,
307
316
  PROJECTED_AFFORDANCE_IDS,
308
317
  ReviewOpenArgsSchema,
318
+ SourceSyncOpenUpdateArgsSchema,
319
+ TeamOpenArgsSchema,
309
320
  sameAffordances,
310
321
  } from "../affordances/index";
311
322
 
@@ -315,8 +326,12 @@ export type {
315
326
  AffordanceAvailability,
316
327
  AffordanceAvailabilityId,
317
328
  AffordanceBindingKind,
329
+ AffordanceCoverage,
318
330
  AffordanceId,
319
331
  AffordanceUnavailableReason,
332
+ AvailableAffordance,
333
+ AvailableAffordances,
334
+ NoAffordanceReason,
320
335
  OfferedAffordance,
321
336
  ProjectedAffordanceId,
322
337
  } from "../affordances/index";
@@ -305,7 +305,8 @@ in `attention-evidence.ts`.
305
305
  `attentionEvidence` (null before index-first discovery).
306
306
  - `SourceSyncCandidateSetResponseSchema` / `SourceSyncCandidateSetResponse` —
307
307
  the draft set under review: its revision, items, presented questions,
308
- distinct-file `totals` and cost estimate.
308
+ distinct-file `totals`. No cost estimate: approval authorizes the files,
309
+ never a spend.
309
310
  - `SourceSyncCandidateTotalsSchema` / `SourceSyncCandidateTotals` and
310
311
  `candidateTotalsOf(items)` — THE file count: distinct `sourceId`, never lines
311
312
  (ADR-CONTRACTS-195).
@@ -48,7 +48,6 @@ function addCandidate(overrides: Record<string, unknown> = {}) {
48
48
  function approveRequest(overrides: Record<string, unknown> = {}) {
49
49
  return {
50
50
  revision: 7,
51
- spendCapMicroUsd: "2500000",
52
51
  ...overrides,
53
52
  };
54
53
  }
@@ -112,20 +111,10 @@ describe("SourceSyncApproveRequestSchema", () => {
112
111
  expect(refused.error?.issues[0]?.path).toEqual(["revision"]);
113
112
  });
114
113
 
115
- it("refuses an approval with no spend cap", () => {
116
- const { spendCapMicroUsd: _cap, ...withoutCap } = approveRequest();
117
- const refused = SourceSyncApproveRequestSchema.safeParse(withoutCap);
118
- expect(refused.success).toBe(false);
119
- expect(refused.error?.issues[0]?.path).toEqual(["spendCapMicroUsd"]);
120
-
121
- expect(
122
- SourceSyncApproveRequestSchema.safeParse(
123
- approveRequest({ spendCapMicroUsd: "2.50" }),
124
- ).success,
125
- ).toBe(false);
114
+ it("refuses a spend cap: an approval authorizes files, never a spend", () => {
126
115
  expect(
127
116
  SourceSyncApproveRequestSchema.safeParse(
128
- approveRequest({ spendCapMicroUsd: 2500000 }),
117
+ approveRequest({ spendCapMicroUsd: "2500000" }),
129
118
  ).success,
130
119
  ).toBe(false);
131
120
  });
@@ -43,6 +43,7 @@ describe("SOURCE_SYNC_SYNTHESIS_PHASES", () => {
43
43
  "drafting",
44
44
  "waiting_for_review",
45
45
  "paused_billing",
46
+ "paused_ceiling",
46
47
  "applied",
47
48
  "applied_partial",
48
49
  "failed",
@@ -140,11 +140,6 @@ function candidateSet(overrides: Record<string, unknown> = {}) {
140
140
  filesPendingClassification: 0,
141
141
  },
142
142
  scopes: [],
143
- estimate: {
144
- lowMicroUsd: "250000",
145
- highMicroUsd: "1250000",
146
- capMicroUsd: "2000000",
147
- },
148
143
  discovery: {
149
144
  foundThisRun: 12,
150
145
  retainedDecisions: 3,
@@ -264,38 +259,16 @@ describe("SourceSyncCandidateItemSchema", () => {
264
259
  });
265
260
 
266
261
  describe("SourceSyncCandidateSetResponseSchema", () => {
267
- it("accepts an estimate as integer micro-USD strings and refuses a decimal", () => {
262
+ it("accepts the draft set", () => {
268
263
  expect(
269
264
  SourceSyncCandidateSetResponseSchema.safeParse(candidateSet()).success,
270
265
  ).toBe(true);
271
- const decimal = candidateSet({
272
- estimate: {
273
- lowMicroUsd: "0.25",
274
- highMicroUsd: "1250000",
275
- capMicroUsd: "2000000",
276
- },
277
- });
278
- expect(
279
- SourceSyncCandidateSetResponseSchema.safeParse(decimal).success,
280
- ).toBe(false);
281
- const jsonNumber = candidateSet({
282
- estimate: {
283
- lowMicroUsd: "250000",
284
- highMicroUsd: "1250000",
285
- capMicroUsd: 2000000,
286
- },
287
- });
288
- expect(
289
- SourceSyncCandidateSetResponseSchema.safeParse(jsonNumber).success,
290
- ).toBe(false);
291
266
  });
292
267
 
293
- it("accepts a null estimate before the estimator has run", () => {
294
- expect(
295
- SourceSyncCandidateSetResponseSchema.safeParse(
296
- candidateSet({ estimate: null }),
297
- ).success,
298
- ).toBe(true);
268
+ it("carries no cost estimate: the review authorizes files, never a spend", () => {
269
+ expect(SourceSyncCandidateSetResponseSchema.shape).not.toHaveProperty(
270
+ "estimate",
271
+ );
299
272
  });
300
273
 
301
274
  it("refuses an unknown set state", () => {
@@ -30,9 +30,6 @@ import {
30
30
  import { CandidateDiscoverySummarySchema } from "./relevance";
31
31
  import { SourceSyncCandidateItemSchema } from "./candidate-item";
32
32
 
33
- /** Integer micro-USD as a string — the billing domain's money convention on the wire. */
34
- const MicroUsd = z.string().regex(/^[0-9]+$/);
35
-
36
33
  /** A person as the review names them: a display label, never an id or an address. */
37
34
  const PersonLabel = z.string().min(1).max(255);
38
35
 
@@ -109,14 +106,6 @@ export const SourceSyncCandidateSetResponseSchema = z.object({
109
106
  totals: SourceSyncCandidateTotalsSchema,
110
107
  /** Every scope of the set the caller may see, and where its approval stands. */
111
108
  scopes: z.array(SourceSyncScopeApprovalProjectionSchema).max(500),
112
- /** A RANGE, and the cap that is the promise. Null until the estimator has run. */
113
- estimate: z
114
- .object({
115
- lowMicroUsd: MicroUsd,
116
- highMicroUsd: MicroUsd,
117
- capMicroUsd: MicroUsd,
118
- })
119
- .nullable(),
120
109
  /** The last completed discovery run's counts; null before any run completed. */
121
110
  discovery: z.nullable(CandidateDiscoverySummarySchema),
122
111
  });
@@ -134,13 +123,14 @@ export const SourceSyncAddCandidateRequestSchema = z
134
123
 
135
124
  /**
136
125
  * Approve the set AS REVIEWED. `revision` is the revision the person was looking at; the server
137
- * refuses a stale one, freezes the items, and hashes them PER SCOPE with that scope's share of the cap.
126
+ * refuses a stale one, freezes the items, and hashes them PER SCOPE.
127
+ *
128
+ * An approval authorizes the files, never a spend: there is no cap and no estimate here. Spend is
129
+ * bounded by the org's standing spending controls and a server-derived run ceiling.
138
130
  */
139
131
  export const SourceSyncApproveRequestSchema = z
140
132
  .object({
141
133
  revision: z.number().int().min(0),
142
- /** The promise: synthesis stops at this. Integer micro-USD. */
143
- spendCapMicroUsd: MicroUsd,
144
134
  /** Absent: every scope the caller may approve (all of them for the single v1 approver). */
145
135
  scopeKeys: z.array(z.string().min(1).max(64)).min(1).max(500).optional(),
146
136
  })
@@ -151,7 +141,7 @@ export const SourceSyncScopeApprovalSchema = z.object({
151
141
  /** 'company' or 'unit:<uuid>'. */
152
142
  scopeKey: z.string().min(1).max(64),
153
143
  approvalId: z.string().uuid(),
154
- /** Hash over THIS scope's ordered (source, target, use, observation) tuples and its share of the cap. */
144
+ /** Hash over THIS scope's ordered (source, target, use, observation) tuples. */
155
145
  candidateSetHash: z.string().regex(/^[0-9a-f]{64}$/),
156
146
  });
157
147
 
@@ -285,6 +275,7 @@ export const SOURCE_SYNC_SYNTHESIS_PHASES = [
285
275
  "drafting",
286
276
  "waiting_for_review",
287
277
  "paused_billing",
278
+ "paused_ceiling",
288
279
  "applied",
289
280
  "applied_partial",
290
281
  "failed",
@@ -150,6 +150,8 @@ export const SYNTHESIZE_DEFERRED_ROUTE_OF_REASON = {
150
150
  updates_applied: { route: "covered", by: "sourceSync.docs_updated", fallback: "notice", audience: "creator" },
151
151
  stopped_by_user: STOPPED,
152
152
  paused_billing: EXPLAINED,
153
+ run_ceiling_reached: NOTICE_ADMINS,
154
+ pricing_unconfigured: NOTICE_ADMINS,
153
155
  synthesis_incomplete: NOTICE_ADMINS,
154
156
  approval_mismatch: NOTICE_ADMINS,
155
157
  landing_refused: NOTICE_ADMINS,
@@ -123,6 +123,8 @@ export const SYNTHESIZE_OUTCOME_KIND_OF_REASON = {
123
123
  updates_applied: "produced",
124
124
  stopped_by_user: "stopped",
125
125
  paused_billing: "failed",
126
+ run_ceiling_reached: "failed",
127
+ pricing_unconfigured: "failed",
126
128
  synthesis_incomplete: "failed",
127
129
  approval_mismatch: "failed",
128
130
  landing_refused: "failed",
@@ -143,6 +145,8 @@ export const SYNTHESIZE_AFFORDANCES_OF_REASON = {
143
145
  updates_applied: [],
144
146
  stopped_by_user: [],
145
147
  paused_billing: [OPEN_BILLING],
148
+ run_ceiling_reached: [],
149
+ pricing_unconfigured: [],
146
150
  synthesis_incomplete: [],
147
151
  approval_mismatch: [],
148
152
  landing_refused: [],