@clocknext/sdk 0.12.0 → 0.13.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/dist/index.d.cts CHANGED
@@ -123,7 +123,14 @@ interface WalletSignal extends SignalBase {
123
123
  /**
124
124
  * Records one step of a multi-call outcome run. The `agentKey` identifies the
125
125
  * step (and the outcome); `runId` groups every signal of a single run, so a step
126
- * may repeat freely. The run bills once, when the caller marks it `complete`.
126
+ * may repeat freely. The run bills once, when the caller closes it with
127
+ * `signals.completeOutcome()` — a SEPARATE, dedicated call, never a flag on a
128
+ * step signal.
129
+ *
130
+ * There is no `complete` field here. `POST /api/v1/signal/outcome` (what this
131
+ * type posts to) now accepts ONLY the step shape and rejects a body that also
132
+ * carries `complete` — see {@link OutcomeCompletionInput} /
133
+ * `signals.completeOutcome()`, its own dedicated route.
127
134
  */
128
135
  interface OutcomeSignal extends SignalBase {
129
136
  type: "outcome";
@@ -135,17 +142,6 @@ interface OutcomeSignal extends SignalBase {
135
142
  * outcome). Opaque to ClockNext — any string you can correlate; unique per org.
136
143
  */
137
144
  runId: string;
138
- /**
139
- * Set `true` on the LAST step signal to declare the run finished — completion
140
- * is never inferred from step coverage. Sending it twice is a safe no-op and
141
- * can't bill again.
142
- *
143
- * This closes the RUN only. If the signal also carries a `composite`, that
144
- * occurrence stays open and unbilled until you call
145
- * `signals.completeComposite()` — the two completions are separate, and
146
- * neither implies the other.
147
- */
148
- complete?: boolean;
149
145
  /** Optional composite this signal belongs to. See {@link CompositeTag}. */
150
146
  composite?: CompositeTag;
151
147
  }
@@ -154,6 +150,56 @@ type Signal = CreditSignal | WalletSignal | OutcomeSignal;
154
150
  type CreditInput = Omit<CreditSignal, "type">;
155
151
  type WalletInput = Omit<WalletSignal, "type">;
156
152
  type OutcomeInput = Omit<OutcomeSignal, "type">;
153
+ /**
154
+ * Input for `signals.completeOutcome()` — closes ONE outcome run, the outcome
155
+ * mirror of {@link CompositeCompletionInput}. No `agentKey`, no `usage`: this
156
+ * closes an EXISTING run that an earlier `signals.outcome()` step already
157
+ * opened, so there is no step behind this call and nothing here to price.
158
+ *
159
+ * This closes the RUN only. If a step of this run also carried a `composite`,
160
+ * that occurrence stays open and unbilled until you separately call
161
+ * `signals.completeComposite()` — the two completions are independent, and
162
+ * neither implies the other.
163
+ */
164
+ interface OutcomeCompletionInput {
165
+ customerId: string;
166
+ /** The same `runId` the run's step signals were sent with. */
167
+ runId: string;
168
+ /** Optional member (email) this completion is attributed to. */
169
+ member?: string;
170
+ /** Idempotency key, auto-generated if omitted. Sending `complete` twice for
171
+ * the same run is already a safe no-op server-side, so this only collapses
172
+ * a retry into one attempt rather than protecting against a double bill. */
173
+ idempotencyKey?: string;
174
+ }
175
+ /**
176
+ * The result of `signals.completeOutcome()`.
177
+ *
178
+ * Unlike {@link CompositeCompletionResult}, `ALREADY_COMPLETED` is NOT what a
179
+ * normal second ping for the same run gets back — that is rejected outright
180
+ * (a permanent error: the run has already been billed, and completing it again
181
+ * would bill it twice). `ALREADY_COMPLETED` is reserved for the much rarer case
182
+ * of two concurrent deliveries of the exact same request (e.g. a client-side
183
+ * retry racing the original), which really is a harmless echo.
184
+ */
185
+ interface OutcomeCompletionResult {
186
+ /** How far the ping got. Never `"buffered"` — completions are always sent
187
+ * immediately. See {@link TrackResult.status}. */
188
+ delivery: Extract<SignalDelivery, "accepted" | "recorded">;
189
+ /** True when the ping was accepted but not yet applied (`202`). Prefer
190
+ * {@link OutcomeCompletionResult.delivery}. */
191
+ queued: boolean;
192
+ /** `COMPLETED` on the first close, `ALREADY_COMPLETED` only on the rare
193
+ * concurrent-replay case described above. Absent when the ping was queued. */
194
+ status?: "COMPLETED" | "ALREADY_COMPLETED";
195
+ /** The priced usage log, when the server closed the run inline. `null` on a
196
+ * `202` hand-off. */
197
+ usageLog?: SerializedUsageLog | null;
198
+ /** The durable inbox id — see {@link TrackResult.rawId}. */
199
+ rawId?: string;
200
+ /** The queue message id, present only on a `202` hand-off. */
201
+ messageId?: string;
202
+ }
157
203
  interface SerializedRuleApplication {
158
204
  ruleId: string | null;
159
205
  ruleName: string;
@@ -249,8 +295,10 @@ interface TrackResult {
249
295
  * `"accepted"` — the server has written it to its durable inbox (`202`)
250
296
  * and will price it shortly. It can no longer be lost, but
251
297
  * it is not billed yet and `usageLog` is null. A rejection
252
- * discovered during pricing will NOT come back to you here —
253
- * read it back with `signals.list()`.
298
+ * discovered during pricing will NOT come back to you here,
299
+ * nor on `onError`. `signals.list()` shows what got priced;
300
+ * the dashboard's signal log — owner-only, by design — is
301
+ * where an individual rejection says why.
254
302
  * `"recorded"` — the server priced it inline and `usageLog` is populated.
255
303
  * `"dropped"` — the SDK threw it away without sending: the client is
256
304
  * closed, or the local queue is full. `onDrop` fired with
@@ -900,17 +948,21 @@ interface WalletEntryInput {
900
948
  notes?: string;
901
949
  }
902
950
  /** Grant (positive) or claw back (negative) a credit balance. `delta` must be a
903
- * non-zero whole number. The credit is addressed by its stable `agentKey`. */
951
+ * non-zero whole number. The credit is addressed by its stable `agentKey`. A
952
+ * reduce is never rejected or floored for going below 0 — the resulting
953
+ * balance may read negative, same as a real-usage overdraft already can. */
904
954
  interface CreditAdjustInput {
905
955
  /** The credit's stable agent key (the same key used to record usage). */
906
956
  agentKey: string;
907
957
  delta: number;
908
958
  notes?: string;
909
959
  }
910
- /** Grant/claw an outcome balance. `delta` is a non-zero whole number; floored at
911
- * 0. The outcome is addressed here by a STEP's `agentKey`, which resolves to its
960
+ /** Grant/claw an outcome balance. `delta` is a non-zero whole number. The
961
+ * outcome is addressed here by a STEP's `agentKey`, which resolves to its
912
962
  * parent outcome — NOT by the outcome's own `agentKey` ({@link Outcome.agentKey}),
913
- * which this endpoint does not accept. */
963
+ * which this endpoint does not accept. A reduce is never rejected or floored
964
+ * for going below 0 — the resulting balance may read negative, same as a
965
+ * real-usage overdraft already can. */
914
966
  interface OutcomeAdjustInput {
915
967
  /** An outcome STEP's stable agent key — identifies the parent outcome. Passing
916
968
  * the outcome's own `agentKey` here fails with `422`. */
@@ -918,14 +970,35 @@ interface OutcomeAdjustInput {
918
970
  delta: number;
919
971
  notes?: string;
920
972
  }
921
- /** Grant/claw a unit balance. `delta` is non-zero (fractional allowed); floored
922
- * at 0. The unit is addressed by its stable `agentKey`. */
973
+ /** Grant/claw a unit balance. `delta` is non-zero (fractional allowed). The
974
+ * unit is addressed by its stable `agentKey`. A reduce is never rejected or
975
+ * floored for going below 0 — the resulting balance may read negative, same
976
+ * as a real-usage overdraft already can. */
923
977
  interface UnitAdjustInput {
924
978
  /** The unit's stable agent key (the same key used to record usage). */
925
979
  agentKey: string;
926
980
  delta: number;
927
981
  notes?: string;
928
982
  }
983
+ /**
984
+ * Grant (positive) or claw back (negative) slots on a customer's ADVANCE
985
+ * composite (pricing metric) pool for the CURRENT billing cycle. `delta` is a
986
+ * non-zero whole number. A reduce is never rejected or floored for going below
987
+ * 0 — same as credit/outcome/unit adjustments; the resulting pool may read
988
+ * negative. Fails if the customer has no active ADVANCE purchase component
989
+ * selling this composite.
990
+ */
991
+ interface CompositeAdjustInput {
992
+ /**
993
+ * The composite's stable identifier — its `refId` (see {@link Composite.refId}),
994
+ * the same value signals tag it with, NOT `agentKey` (a composite has no
995
+ * `agentKey` column of its own). Named `agentKey` on the wire only so the
996
+ * four adjust endpoints share one request shape.
997
+ */
998
+ agentKey: string;
999
+ delta: number;
1000
+ notes?: string;
1001
+ }
929
1002
  /** A per-model token bundle attached to a credit or outcome step. */
930
1003
  interface ModelBundleEntry {
931
1004
  orgModelId: string;
@@ -1658,8 +1731,11 @@ declare class Customers {
1658
1731
  transaction: WalletTransaction;
1659
1732
  balanceUsd: number;
1660
1733
  }>;
1661
- /** Grant or claw back a credit balance. `POST …/:id/credits/adjust`. */
1662
- adjustCredit(id: string, input: CreditAdjustInput): Promise<void>;
1734
+ /** Grant or claw back a credit balance. Returns the remaining balance.
1735
+ * `POST …/:id/credits/adjust`. */
1736
+ adjustCredit(id: string, input: CreditAdjustInput): Promise<{
1737
+ remaining: number;
1738
+ }>;
1663
1739
  /** Grant or claw back an outcome balance. Returns the remaining balance. */
1664
1740
  adjustOutcome(id: string, input: OutcomeAdjustInput): Promise<{
1665
1741
  remaining: number;
@@ -1668,6 +1744,14 @@ declare class Customers {
1668
1744
  adjustUnit(id: string, input: UnitAdjustInput): Promise<{
1669
1745
  remaining: number;
1670
1746
  }>;
1747
+ /**
1748
+ * Grant or claw back slots on a customer's ADVANCE composite pool for the
1749
+ * current billing cycle. Returns the resulting `remaining` slot count.
1750
+ * `POST …/:id/composites/adjust`.
1751
+ */
1752
+ adjustComposite(id: string, input: CompositeAdjustInput): Promise<{
1753
+ remaining: number;
1754
+ }>;
1671
1755
  }
1672
1756
 
1673
1757
  /**
@@ -1916,8 +2000,15 @@ declare function signalToWire(signal: Signal): Record<string, unknown>;
1916
2000
  *
1917
2001
  * Because of that, a signal the server later REJECTS (unknown `agentKey`, a
1918
2002
  * model the org has not enabled, no active plan) cannot come back through this
1919
- * promise. It surfaces on the `onError` hook, and `list()` is how you confirm
1920
- * one actually landed — ingestion being asynchronous, the only way to.
2003
+ * promise — and does not reach `onError` either, since from here that request
2004
+ * succeeded. Such a rejection has no programmatic channel at all: it is
2005
+ * recorded on the workspace's signal log in the ClockNext dashboard, which is
2006
+ * owner-only by design.
2007
+ *
2008
+ * `list()` is the partial check available from code. It returns priced usage
2009
+ * logs with a `status`, so it confirms a signal landed and whether pricing
2010
+ * succeeded — but a signal refused BEFORE pricing never becomes a usage log
2011
+ * and does not appear there.
1921
2012
  */
1922
2013
  declare class Signals {
1923
2014
  private readonly transport;
@@ -1947,6 +2038,25 @@ declare class Signals {
1947
2038
  outcome(input: OutcomeInput, opts?: {
1948
2039
  wait?: boolean;
1949
2040
  }): Promise<TrackResult>;
2041
+ /**
2042
+ * Close ONE outcome run — declares the workflow finished and bills it. The
2043
+ * outcome mirror of {@link Signals.completeComposite}, on its own dedicated
2044
+ * route: `POST /api/v1/signal/outcome/complete`.
2045
+ *
2046
+ * An outcome bills per COMPLETION, never per step, and `signals.outcome()`
2047
+ * never closes one — it accepts only the step shape. Declaring the workflow
2048
+ * finished is always this separate, explicit, contentless call.
2049
+ *
2050
+ * This closes the RUN only. If a step of this run also carried a
2051
+ * `composite`, that occurrence stays open and unbilled until you separately
2052
+ * call {@link Signals.completeComposite} — the two completions are
2053
+ * independent, and neither implies the other.
2054
+ *
2055
+ * Sent immediately, never buffered. A genuinely second, independent call for
2056
+ * an already-closed run is a PERMANENT error (it would bill the run twice),
2057
+ * not a safe no-op — see {@link OutcomeCompletionResult}.
2058
+ */
2059
+ completeOutcome(input: OutcomeCompletionInput): Promise<OutcomeCompletionResult>;
1950
2060
  /**
1951
2061
  * Recent usage logs + totals for a customer. `GET /api/v1/usage`.
1952
2062
  *
@@ -1984,13 +2094,13 @@ declare class Signals {
1984
2094
  * arrive in any order and the occurrence stays open and unbilled until you
1985
2095
  * say otherwise. Put it on the line before your own `return`.
1986
2096
  *
1987
- * EVERY composite needs this, outcome-backed ones included. An outcome's own
1988
- * `complete: true` closes its RUN and nothing else — it does not close the
1989
- * composite occurrence the run was tagged into, whatever mix of credits,
1990
- * outcomes and units that composite wraps. (Earlier versions of this SDK
1991
- * documented the opposite. Believing it means the occurrence stays ONGOING
1992
- * forever and is never billed, so if you tag outcome signals with a
1993
- * `composite`, you must still call this.)
2097
+ * EVERY composite needs this, outcome-backed ones included. `completeOutcome()`
2098
+ * closes its RUN and nothing else — it does not close the composite
2099
+ * occurrence the run was tagged into, whatever mix of credits, outcomes and
2100
+ * units that composite wraps. (Earlier versions of this SDK documented the
2101
+ * opposite. Believing it means the occurrence stays ONGOING forever and is
2102
+ * never billed, so if you tag outcome signals with a `composite`, you must
2103
+ * still call this.)
1994
2104
  *
1995
2105
  * Closing twice is safe: the second call answers `ALREADY_COMPLETED` and
1996
2106
  * cannot bill again. Calling it EARLY is also safe — before every entitlement
@@ -2202,4 +2312,4 @@ declare class NetworkError extends ClockNextError {
2202
2312
  });
2203
2313
  }
2204
2314
 
2205
- export { type AddMemberInput, AllowanceError, type ApiCustomer, AuthError, type BillingCycle, type BillingMode, ClockNext, type ClockNextConfig, ClockNextError, type ClockNextErrorCode, type ComponentType, type Composite, type CompositeCatalogueRef, type CompositeCompletionInput, type CompositeCompletionResult, type CompositeComponentInput, type CompositeTag, ConflictError, type CostPoint, type CostStats, type CreateCompositeInput, type CreateCreditInput, type CreateCustomerInput, type CreateOutcomeInput, type CreatePlanInput, type CreatePurchaseInput, type CreateUnitInput, type Credit, type CreditAdjustInput, type CreditAnalytics, type CreditBalance, type CreditComponentInput, type CreditDetail, type CreditInput, type CreditSignal, type CustomerBalances, type CustomerList, type CustomerPlan, type CustomerPlanDetails, type CustomerProfileInput, type DropReason, type FetchLike, type FlatComponentInput, type FlatUnitInput, ForbiddenError, type Invoice, type InvoiceDetail, type InvoiceLineItem, type InvoiceListRow, type InvoiceParty, type InvoicePlanSnapshot, type InvoiceStatus, type Logger, type Member, type MemberProfile, type Model, type ModelBundleEntry, NetworkError, NotFoundError, type Outcome, type OutcomeAdjustInput, type OutcomeAnalytics, type OutcomeBalance, type OutcomeComponentInput, type OutcomeDetail, type OutcomeInput, type OutcomeSignal, type OutcomeStepInput, type PayLink, type PaymentDetail, type PaymentRow, type Plan, type PlanComponent, type PlanComponentInput, type PlanDetail, PlanError, type PlanKind, type PlanRef, type PlanType, type PortalToken, type PortalTokenInput, type Purchase, type PurchaseDetail, type PurchaseStatus, RateLimitError, type RemovedMember, type SerializedOutcomeAttribution, type SerializedRuleApplication, type SerializedUnitUsage, type SerializedUsageLog, ServerError, type Signal, type SignalDelivery, type SignalStatus, type SignalType, type ThresholdKind, type TieredUnitInput, type Tokens, type TrackResult, type Unit, type UnitAdjustInput, type UnitBalance, type UnitComponentInput, type UnitCustomerRow, type UnitDetail, type UnitInput, type UnitPricingType, type UnitTier, type UnitTierInput, type UnitTrackResult, type UnitUsageList, type UnitUsageRow, type UpdateCreditInput, type UpdateMemberInput, type UpdateOutcomeInput, type UpdatePlanInput, type UpdateUnitInput, type UpsertWebhookInput, type UsageBalance, type UsageList, ValidationError, type WalletComponentInput, type WalletEntitlementKind, type WalletEntryInput, type WalletInput, type WalletList, type WalletSignal, type WalletTransaction, type WalletTransactionSource, type WalletTransactionType, type Webhook, type WorkspaceIdentity, signalToWire };
2315
+ export { type AddMemberInput, AllowanceError, type ApiCustomer, AuthError, type BillingCycle, type BillingMode, ClockNext, type ClockNextConfig, ClockNextError, type ClockNextErrorCode, type ComponentType, type Composite, type CompositeAdjustInput, type CompositeCatalogueRef, type CompositeCompletionInput, type CompositeCompletionResult, type CompositeComponentInput, type CompositeTag, ConflictError, type CostPoint, type CostStats, type CreateCompositeInput, type CreateCreditInput, type CreateCustomerInput, type CreateOutcomeInput, type CreatePlanInput, type CreatePurchaseInput, type CreateUnitInput, type Credit, type CreditAdjustInput, type CreditAnalytics, type CreditBalance, type CreditComponentInput, type CreditDetail, type CreditInput, type CreditSignal, type CustomerBalances, type CustomerList, type CustomerPlan, type CustomerPlanDetails, type CustomerProfileInput, type DropReason, type FetchLike, type FlatComponentInput, type FlatUnitInput, ForbiddenError, type Invoice, type InvoiceDetail, type InvoiceLineItem, type InvoiceListRow, type InvoiceParty, type InvoicePlanSnapshot, type InvoiceStatus, type Logger, type Member, type MemberProfile, type Model, type ModelBundleEntry, NetworkError, NotFoundError, type Outcome, type OutcomeAdjustInput, type OutcomeAnalytics, type OutcomeBalance, type OutcomeCompletionInput, type OutcomeCompletionResult, type OutcomeComponentInput, type OutcomeDetail, type OutcomeInput, type OutcomeSignal, type OutcomeStepInput, type PayLink, type PaymentDetail, type PaymentRow, type Plan, type PlanComponent, type PlanComponentInput, type PlanDetail, PlanError, type PlanKind, type PlanRef, type PlanType, type PortalToken, type PortalTokenInput, type Purchase, type PurchaseDetail, type PurchaseStatus, RateLimitError, type RemovedMember, type SerializedOutcomeAttribution, type SerializedRuleApplication, type SerializedUnitUsage, type SerializedUsageLog, ServerError, type Signal, type SignalDelivery, type SignalStatus, type SignalType, type ThresholdKind, type TieredUnitInput, type Tokens, type TrackResult, type Unit, type UnitAdjustInput, type UnitBalance, type UnitComponentInput, type UnitCustomerRow, type UnitDetail, type UnitInput, type UnitPricingType, type UnitTier, type UnitTierInput, type UnitTrackResult, type UnitUsageList, type UnitUsageRow, type UpdateCreditInput, type UpdateMemberInput, type UpdateOutcomeInput, type UpdatePlanInput, type UpdateUnitInput, type UpsertWebhookInput, type UsageBalance, type UsageList, ValidationError, type WalletComponentInput, type WalletEntitlementKind, type WalletEntryInput, type WalletInput, type WalletList, type WalletSignal, type WalletTransaction, type WalletTransactionSource, type WalletTransactionType, type Webhook, type WorkspaceIdentity, signalToWire };
package/dist/index.d.ts CHANGED
@@ -123,7 +123,14 @@ interface WalletSignal extends SignalBase {
123
123
  /**
124
124
  * Records one step of a multi-call outcome run. The `agentKey` identifies the
125
125
  * step (and the outcome); `runId` groups every signal of a single run, so a step
126
- * may repeat freely. The run bills once, when the caller marks it `complete`.
126
+ * may repeat freely. The run bills once, when the caller closes it with
127
+ * `signals.completeOutcome()` — a SEPARATE, dedicated call, never a flag on a
128
+ * step signal.
129
+ *
130
+ * There is no `complete` field here. `POST /api/v1/signal/outcome` (what this
131
+ * type posts to) now accepts ONLY the step shape and rejects a body that also
132
+ * carries `complete` — see {@link OutcomeCompletionInput} /
133
+ * `signals.completeOutcome()`, its own dedicated route.
127
134
  */
128
135
  interface OutcomeSignal extends SignalBase {
129
136
  type: "outcome";
@@ -135,17 +142,6 @@ interface OutcomeSignal extends SignalBase {
135
142
  * outcome). Opaque to ClockNext — any string you can correlate; unique per org.
136
143
  */
137
144
  runId: string;
138
- /**
139
- * Set `true` on the LAST step signal to declare the run finished — completion
140
- * is never inferred from step coverage. Sending it twice is a safe no-op and
141
- * can't bill again.
142
- *
143
- * This closes the RUN only. If the signal also carries a `composite`, that
144
- * occurrence stays open and unbilled until you call
145
- * `signals.completeComposite()` — the two completions are separate, and
146
- * neither implies the other.
147
- */
148
- complete?: boolean;
149
145
  /** Optional composite this signal belongs to. See {@link CompositeTag}. */
150
146
  composite?: CompositeTag;
151
147
  }
@@ -154,6 +150,56 @@ type Signal = CreditSignal | WalletSignal | OutcomeSignal;
154
150
  type CreditInput = Omit<CreditSignal, "type">;
155
151
  type WalletInput = Omit<WalletSignal, "type">;
156
152
  type OutcomeInput = Omit<OutcomeSignal, "type">;
153
+ /**
154
+ * Input for `signals.completeOutcome()` — closes ONE outcome run, the outcome
155
+ * mirror of {@link CompositeCompletionInput}. No `agentKey`, no `usage`: this
156
+ * closes an EXISTING run that an earlier `signals.outcome()` step already
157
+ * opened, so there is no step behind this call and nothing here to price.
158
+ *
159
+ * This closes the RUN only. If a step of this run also carried a `composite`,
160
+ * that occurrence stays open and unbilled until you separately call
161
+ * `signals.completeComposite()` — the two completions are independent, and
162
+ * neither implies the other.
163
+ */
164
+ interface OutcomeCompletionInput {
165
+ customerId: string;
166
+ /** The same `runId` the run's step signals were sent with. */
167
+ runId: string;
168
+ /** Optional member (email) this completion is attributed to. */
169
+ member?: string;
170
+ /** Idempotency key, auto-generated if omitted. Sending `complete` twice for
171
+ * the same run is already a safe no-op server-side, so this only collapses
172
+ * a retry into one attempt rather than protecting against a double bill. */
173
+ idempotencyKey?: string;
174
+ }
175
+ /**
176
+ * The result of `signals.completeOutcome()`.
177
+ *
178
+ * Unlike {@link CompositeCompletionResult}, `ALREADY_COMPLETED` is NOT what a
179
+ * normal second ping for the same run gets back — that is rejected outright
180
+ * (a permanent error: the run has already been billed, and completing it again
181
+ * would bill it twice). `ALREADY_COMPLETED` is reserved for the much rarer case
182
+ * of two concurrent deliveries of the exact same request (e.g. a client-side
183
+ * retry racing the original), which really is a harmless echo.
184
+ */
185
+ interface OutcomeCompletionResult {
186
+ /** How far the ping got. Never `"buffered"` — completions are always sent
187
+ * immediately. See {@link TrackResult.status}. */
188
+ delivery: Extract<SignalDelivery, "accepted" | "recorded">;
189
+ /** True when the ping was accepted but not yet applied (`202`). Prefer
190
+ * {@link OutcomeCompletionResult.delivery}. */
191
+ queued: boolean;
192
+ /** `COMPLETED` on the first close, `ALREADY_COMPLETED` only on the rare
193
+ * concurrent-replay case described above. Absent when the ping was queued. */
194
+ status?: "COMPLETED" | "ALREADY_COMPLETED";
195
+ /** The priced usage log, when the server closed the run inline. `null` on a
196
+ * `202` hand-off. */
197
+ usageLog?: SerializedUsageLog | null;
198
+ /** The durable inbox id — see {@link TrackResult.rawId}. */
199
+ rawId?: string;
200
+ /** The queue message id, present only on a `202` hand-off. */
201
+ messageId?: string;
202
+ }
157
203
  interface SerializedRuleApplication {
158
204
  ruleId: string | null;
159
205
  ruleName: string;
@@ -249,8 +295,10 @@ interface TrackResult {
249
295
  * `"accepted"` — the server has written it to its durable inbox (`202`)
250
296
  * and will price it shortly. It can no longer be lost, but
251
297
  * it is not billed yet and `usageLog` is null. A rejection
252
- * discovered during pricing will NOT come back to you here —
253
- * read it back with `signals.list()`.
298
+ * discovered during pricing will NOT come back to you here,
299
+ * nor on `onError`. `signals.list()` shows what got priced;
300
+ * the dashboard's signal log — owner-only, by design — is
301
+ * where an individual rejection says why.
254
302
  * `"recorded"` — the server priced it inline and `usageLog` is populated.
255
303
  * `"dropped"` — the SDK threw it away without sending: the client is
256
304
  * closed, or the local queue is full. `onDrop` fired with
@@ -900,17 +948,21 @@ interface WalletEntryInput {
900
948
  notes?: string;
901
949
  }
902
950
  /** Grant (positive) or claw back (negative) a credit balance. `delta` must be a
903
- * non-zero whole number. The credit is addressed by its stable `agentKey`. */
951
+ * non-zero whole number. The credit is addressed by its stable `agentKey`. A
952
+ * reduce is never rejected or floored for going below 0 — the resulting
953
+ * balance may read negative, same as a real-usage overdraft already can. */
904
954
  interface CreditAdjustInput {
905
955
  /** The credit's stable agent key (the same key used to record usage). */
906
956
  agentKey: string;
907
957
  delta: number;
908
958
  notes?: string;
909
959
  }
910
- /** Grant/claw an outcome balance. `delta` is a non-zero whole number; floored at
911
- * 0. The outcome is addressed here by a STEP's `agentKey`, which resolves to its
960
+ /** Grant/claw an outcome balance. `delta` is a non-zero whole number. The
961
+ * outcome is addressed here by a STEP's `agentKey`, which resolves to its
912
962
  * parent outcome — NOT by the outcome's own `agentKey` ({@link Outcome.agentKey}),
913
- * which this endpoint does not accept. */
963
+ * which this endpoint does not accept. A reduce is never rejected or floored
964
+ * for going below 0 — the resulting balance may read negative, same as a
965
+ * real-usage overdraft already can. */
914
966
  interface OutcomeAdjustInput {
915
967
  /** An outcome STEP's stable agent key — identifies the parent outcome. Passing
916
968
  * the outcome's own `agentKey` here fails with `422`. */
@@ -918,14 +970,35 @@ interface OutcomeAdjustInput {
918
970
  delta: number;
919
971
  notes?: string;
920
972
  }
921
- /** Grant/claw a unit balance. `delta` is non-zero (fractional allowed); floored
922
- * at 0. The unit is addressed by its stable `agentKey`. */
973
+ /** Grant/claw a unit balance. `delta` is non-zero (fractional allowed). The
974
+ * unit is addressed by its stable `agentKey`. A reduce is never rejected or
975
+ * floored for going below 0 — the resulting balance may read negative, same
976
+ * as a real-usage overdraft already can. */
923
977
  interface UnitAdjustInput {
924
978
  /** The unit's stable agent key (the same key used to record usage). */
925
979
  agentKey: string;
926
980
  delta: number;
927
981
  notes?: string;
928
982
  }
983
+ /**
984
+ * Grant (positive) or claw back (negative) slots on a customer's ADVANCE
985
+ * composite (pricing metric) pool for the CURRENT billing cycle. `delta` is a
986
+ * non-zero whole number. A reduce is never rejected or floored for going below
987
+ * 0 — same as credit/outcome/unit adjustments; the resulting pool may read
988
+ * negative. Fails if the customer has no active ADVANCE purchase component
989
+ * selling this composite.
990
+ */
991
+ interface CompositeAdjustInput {
992
+ /**
993
+ * The composite's stable identifier — its `refId` (see {@link Composite.refId}),
994
+ * the same value signals tag it with, NOT `agentKey` (a composite has no
995
+ * `agentKey` column of its own). Named `agentKey` on the wire only so the
996
+ * four adjust endpoints share one request shape.
997
+ */
998
+ agentKey: string;
999
+ delta: number;
1000
+ notes?: string;
1001
+ }
929
1002
  /** A per-model token bundle attached to a credit or outcome step. */
930
1003
  interface ModelBundleEntry {
931
1004
  orgModelId: string;
@@ -1658,8 +1731,11 @@ declare class Customers {
1658
1731
  transaction: WalletTransaction;
1659
1732
  balanceUsd: number;
1660
1733
  }>;
1661
- /** Grant or claw back a credit balance. `POST …/:id/credits/adjust`. */
1662
- adjustCredit(id: string, input: CreditAdjustInput): Promise<void>;
1734
+ /** Grant or claw back a credit balance. Returns the remaining balance.
1735
+ * `POST …/:id/credits/adjust`. */
1736
+ adjustCredit(id: string, input: CreditAdjustInput): Promise<{
1737
+ remaining: number;
1738
+ }>;
1663
1739
  /** Grant or claw back an outcome balance. Returns the remaining balance. */
1664
1740
  adjustOutcome(id: string, input: OutcomeAdjustInput): Promise<{
1665
1741
  remaining: number;
@@ -1668,6 +1744,14 @@ declare class Customers {
1668
1744
  adjustUnit(id: string, input: UnitAdjustInput): Promise<{
1669
1745
  remaining: number;
1670
1746
  }>;
1747
+ /**
1748
+ * Grant or claw back slots on a customer's ADVANCE composite pool for the
1749
+ * current billing cycle. Returns the resulting `remaining` slot count.
1750
+ * `POST …/:id/composites/adjust`.
1751
+ */
1752
+ adjustComposite(id: string, input: CompositeAdjustInput): Promise<{
1753
+ remaining: number;
1754
+ }>;
1671
1755
  }
1672
1756
 
1673
1757
  /**
@@ -1916,8 +2000,15 @@ declare function signalToWire(signal: Signal): Record<string, unknown>;
1916
2000
  *
1917
2001
  * Because of that, a signal the server later REJECTS (unknown `agentKey`, a
1918
2002
  * model the org has not enabled, no active plan) cannot come back through this
1919
- * promise. It surfaces on the `onError` hook, and `list()` is how you confirm
1920
- * one actually landed — ingestion being asynchronous, the only way to.
2003
+ * promise — and does not reach `onError` either, since from here that request
2004
+ * succeeded. Such a rejection has no programmatic channel at all: it is
2005
+ * recorded on the workspace's signal log in the ClockNext dashboard, which is
2006
+ * owner-only by design.
2007
+ *
2008
+ * `list()` is the partial check available from code. It returns priced usage
2009
+ * logs with a `status`, so it confirms a signal landed and whether pricing
2010
+ * succeeded — but a signal refused BEFORE pricing never becomes a usage log
2011
+ * and does not appear there.
1921
2012
  */
1922
2013
  declare class Signals {
1923
2014
  private readonly transport;
@@ -1947,6 +2038,25 @@ declare class Signals {
1947
2038
  outcome(input: OutcomeInput, opts?: {
1948
2039
  wait?: boolean;
1949
2040
  }): Promise<TrackResult>;
2041
+ /**
2042
+ * Close ONE outcome run — declares the workflow finished and bills it. The
2043
+ * outcome mirror of {@link Signals.completeComposite}, on its own dedicated
2044
+ * route: `POST /api/v1/signal/outcome/complete`.
2045
+ *
2046
+ * An outcome bills per COMPLETION, never per step, and `signals.outcome()`
2047
+ * never closes one — it accepts only the step shape. Declaring the workflow
2048
+ * finished is always this separate, explicit, contentless call.
2049
+ *
2050
+ * This closes the RUN only. If a step of this run also carried a
2051
+ * `composite`, that occurrence stays open and unbilled until you separately
2052
+ * call {@link Signals.completeComposite} — the two completions are
2053
+ * independent, and neither implies the other.
2054
+ *
2055
+ * Sent immediately, never buffered. A genuinely second, independent call for
2056
+ * an already-closed run is a PERMANENT error (it would bill the run twice),
2057
+ * not a safe no-op — see {@link OutcomeCompletionResult}.
2058
+ */
2059
+ completeOutcome(input: OutcomeCompletionInput): Promise<OutcomeCompletionResult>;
1950
2060
  /**
1951
2061
  * Recent usage logs + totals for a customer. `GET /api/v1/usage`.
1952
2062
  *
@@ -1984,13 +2094,13 @@ declare class Signals {
1984
2094
  * arrive in any order and the occurrence stays open and unbilled until you
1985
2095
  * say otherwise. Put it on the line before your own `return`.
1986
2096
  *
1987
- * EVERY composite needs this, outcome-backed ones included. An outcome's own
1988
- * `complete: true` closes its RUN and nothing else — it does not close the
1989
- * composite occurrence the run was tagged into, whatever mix of credits,
1990
- * outcomes and units that composite wraps. (Earlier versions of this SDK
1991
- * documented the opposite. Believing it means the occurrence stays ONGOING
1992
- * forever and is never billed, so if you tag outcome signals with a
1993
- * `composite`, you must still call this.)
2097
+ * EVERY composite needs this, outcome-backed ones included. `completeOutcome()`
2098
+ * closes its RUN and nothing else — it does not close the composite
2099
+ * occurrence the run was tagged into, whatever mix of credits, outcomes and
2100
+ * units that composite wraps. (Earlier versions of this SDK documented the
2101
+ * opposite. Believing it means the occurrence stays ONGOING forever and is
2102
+ * never billed, so if you tag outcome signals with a `composite`, you must
2103
+ * still call this.)
1994
2104
  *
1995
2105
  * Closing twice is safe: the second call answers `ALREADY_COMPLETED` and
1996
2106
  * cannot bill again. Calling it EARLY is also safe — before every entitlement
@@ -2202,4 +2312,4 @@ declare class NetworkError extends ClockNextError {
2202
2312
  });
2203
2313
  }
2204
2314
 
2205
- export { type AddMemberInput, AllowanceError, type ApiCustomer, AuthError, type BillingCycle, type BillingMode, ClockNext, type ClockNextConfig, ClockNextError, type ClockNextErrorCode, type ComponentType, type Composite, type CompositeCatalogueRef, type CompositeCompletionInput, type CompositeCompletionResult, type CompositeComponentInput, type CompositeTag, ConflictError, type CostPoint, type CostStats, type CreateCompositeInput, type CreateCreditInput, type CreateCustomerInput, type CreateOutcomeInput, type CreatePlanInput, type CreatePurchaseInput, type CreateUnitInput, type Credit, type CreditAdjustInput, type CreditAnalytics, type CreditBalance, type CreditComponentInput, type CreditDetail, type CreditInput, type CreditSignal, type CustomerBalances, type CustomerList, type CustomerPlan, type CustomerPlanDetails, type CustomerProfileInput, type DropReason, type FetchLike, type FlatComponentInput, type FlatUnitInput, ForbiddenError, type Invoice, type InvoiceDetail, type InvoiceLineItem, type InvoiceListRow, type InvoiceParty, type InvoicePlanSnapshot, type InvoiceStatus, type Logger, type Member, type MemberProfile, type Model, type ModelBundleEntry, NetworkError, NotFoundError, type Outcome, type OutcomeAdjustInput, type OutcomeAnalytics, type OutcomeBalance, type OutcomeComponentInput, type OutcomeDetail, type OutcomeInput, type OutcomeSignal, type OutcomeStepInput, type PayLink, type PaymentDetail, type PaymentRow, type Plan, type PlanComponent, type PlanComponentInput, type PlanDetail, PlanError, type PlanKind, type PlanRef, type PlanType, type PortalToken, type PortalTokenInput, type Purchase, type PurchaseDetail, type PurchaseStatus, RateLimitError, type RemovedMember, type SerializedOutcomeAttribution, type SerializedRuleApplication, type SerializedUnitUsage, type SerializedUsageLog, ServerError, type Signal, type SignalDelivery, type SignalStatus, type SignalType, type ThresholdKind, type TieredUnitInput, type Tokens, type TrackResult, type Unit, type UnitAdjustInput, type UnitBalance, type UnitComponentInput, type UnitCustomerRow, type UnitDetail, type UnitInput, type UnitPricingType, type UnitTier, type UnitTierInput, type UnitTrackResult, type UnitUsageList, type UnitUsageRow, type UpdateCreditInput, type UpdateMemberInput, type UpdateOutcomeInput, type UpdatePlanInput, type UpdateUnitInput, type UpsertWebhookInput, type UsageBalance, type UsageList, ValidationError, type WalletComponentInput, type WalletEntitlementKind, type WalletEntryInput, type WalletInput, type WalletList, type WalletSignal, type WalletTransaction, type WalletTransactionSource, type WalletTransactionType, type Webhook, type WorkspaceIdentity, signalToWire };
2315
+ export { type AddMemberInput, AllowanceError, type ApiCustomer, AuthError, type BillingCycle, type BillingMode, ClockNext, type ClockNextConfig, ClockNextError, type ClockNextErrorCode, type ComponentType, type Composite, type CompositeAdjustInput, type CompositeCatalogueRef, type CompositeCompletionInput, type CompositeCompletionResult, type CompositeComponentInput, type CompositeTag, ConflictError, type CostPoint, type CostStats, type CreateCompositeInput, type CreateCreditInput, type CreateCustomerInput, type CreateOutcomeInput, type CreatePlanInput, type CreatePurchaseInput, type CreateUnitInput, type Credit, type CreditAdjustInput, type CreditAnalytics, type CreditBalance, type CreditComponentInput, type CreditDetail, type CreditInput, type CreditSignal, type CustomerBalances, type CustomerList, type CustomerPlan, type CustomerPlanDetails, type CustomerProfileInput, type DropReason, type FetchLike, type FlatComponentInput, type FlatUnitInput, ForbiddenError, type Invoice, type InvoiceDetail, type InvoiceLineItem, type InvoiceListRow, type InvoiceParty, type InvoicePlanSnapshot, type InvoiceStatus, type Logger, type Member, type MemberProfile, type Model, type ModelBundleEntry, NetworkError, NotFoundError, type Outcome, type OutcomeAdjustInput, type OutcomeAnalytics, type OutcomeBalance, type OutcomeCompletionInput, type OutcomeCompletionResult, type OutcomeComponentInput, type OutcomeDetail, type OutcomeInput, type OutcomeSignal, type OutcomeStepInput, type PayLink, type PaymentDetail, type PaymentRow, type Plan, type PlanComponent, type PlanComponentInput, type PlanDetail, PlanError, type PlanKind, type PlanRef, type PlanType, type PortalToken, type PortalTokenInput, type Purchase, type PurchaseDetail, type PurchaseStatus, RateLimitError, type RemovedMember, type SerializedOutcomeAttribution, type SerializedRuleApplication, type SerializedUnitUsage, type SerializedUsageLog, ServerError, type Signal, type SignalDelivery, type SignalStatus, type SignalType, type ThresholdKind, type TieredUnitInput, type Tokens, type TrackResult, type Unit, type UnitAdjustInput, type UnitBalance, type UnitComponentInput, type UnitCustomerRow, type UnitDetail, type UnitInput, type UnitPricingType, type UnitTier, type UnitTierInput, type UnitTrackResult, type UnitUsageList, type UnitUsageRow, type UpdateCreditInput, type UpdateMemberInput, type UpdateOutcomeInput, type UpdatePlanInput, type UpdateUnitInput, type UpsertWebhookInput, type UsageBalance, type UsageList, ValidationError, type WalletComponentInput, type WalletEntitlementKind, type WalletEntryInput, type WalletInput, type WalletList, type WalletSignal, type WalletTransaction, type WalletTransactionSource, type WalletTransactionType, type Webhook, type WorkspaceIdentity, signalToWire };