@clocknext/sdk 0.5.0 → 0.7.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/README.md +37 -2
- package/dist/index.cjs +8 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +50 -4
- package/dist/index.d.ts +50 -4
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -18,6 +18,21 @@ interface Tokens {
|
|
|
18
18
|
output: number;
|
|
19
19
|
cache?: number;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Tags a signal with a pricing metric for reporting. `ref` is the metric's
|
|
23
|
+
* `refId` (defined in Settings → Pricing metrics) and `value` is your own
|
|
24
|
+
* correlation id — a session, a call, a tenant — which the metric rolls up one
|
|
25
|
+
* row per distinct value. Reporting only: a metric never affects billing, a bad
|
|
26
|
+
* tag never fails the signal, and a `ref` naming no live metric is simply
|
|
27
|
+
* ignored. Applies to credit and outcome signals (ignored on wallet).
|
|
28
|
+
*/
|
|
29
|
+
interface MetricTag {
|
|
30
|
+
/** The metric's `refId`. Case-insensitive; must not collide with a reserved
|
|
31
|
+
* ingest field (e.g. `model`, `member`, `agentKey`, `runId`, `custom`). */
|
|
32
|
+
ref: string;
|
|
33
|
+
/** Your correlation value for this metric, stored verbatim. */
|
|
34
|
+
value: string | number;
|
|
35
|
+
}
|
|
21
36
|
/** The organisation + key behind a request — `cnk.workspace.me()`. */
|
|
22
37
|
interface WorkspaceIdentity {
|
|
23
38
|
organization: {
|
|
@@ -75,16 +90,36 @@ interface CreditSignal extends SignalBase {
|
|
|
75
90
|
type: "credit";
|
|
76
91
|
/** The Credit's stable agent key (assigned when the credit was created). */
|
|
77
92
|
agentKey: string;
|
|
93
|
+
/** Optional pricing-metric tag for reporting. */
|
|
94
|
+
metric?: MetricTag;
|
|
78
95
|
}
|
|
79
96
|
/** Debits the customer's wallet in USD at the model's cost. */
|
|
80
97
|
interface WalletSignal extends SignalBase {
|
|
81
98
|
type: "wallet";
|
|
82
99
|
}
|
|
83
|
-
/**
|
|
100
|
+
/**
|
|
101
|
+
* Records one step of a multi-call outcome run. The `agentKey` identifies the
|
|
102
|
+
* step (and the outcome); `runId` groups every signal of a single run, so a step
|
|
103
|
+
* may repeat freely. The run bills once, when the caller marks it `complete`.
|
|
104
|
+
*/
|
|
84
105
|
interface OutcomeSignal extends SignalBase {
|
|
85
106
|
type: "outcome";
|
|
86
107
|
/** The OutcomeStep's stable agent key — identifies the outcome AND the step. */
|
|
87
108
|
agentKey: string;
|
|
109
|
+
/**
|
|
110
|
+
* Correlates every signal of one workflow run. Required. A step may fire more
|
|
111
|
+
* than once within a run (a "verify" loop firing 3× is three signals, one
|
|
112
|
+
* outcome). Opaque to ClockNext — any string you can correlate; unique per org.
|
|
113
|
+
*/
|
|
114
|
+
runId: string;
|
|
115
|
+
/**
|
|
116
|
+
* Set `true` on the LAST step signal to declare the run finished — completion
|
|
117
|
+
* is never inferred from step coverage. Sending it twice is a safe no-op and
|
|
118
|
+
* can't bill again.
|
|
119
|
+
*/
|
|
120
|
+
complete?: boolean;
|
|
121
|
+
/** Optional pricing-metric tag for reporting. */
|
|
122
|
+
metric?: MetricTag;
|
|
88
123
|
}
|
|
89
124
|
type Signal = CreditSignal | WalletSignal | OutcomeSignal;
|
|
90
125
|
/** Helper input shapes for the per-type convenience methods. */
|
|
@@ -98,9 +133,21 @@ interface SerializedRuleApplication {
|
|
|
98
133
|
}
|
|
99
134
|
interface SerializedOutcomeAttribution {
|
|
100
135
|
name: string;
|
|
136
|
+
/** The step of the outcome this signal performed. */
|
|
101
137
|
step: string;
|
|
138
|
+
/** The caller's run id — every signal of one run shares it. `null` on logs
|
|
139
|
+
* recorded before the run-based flow. */
|
|
140
|
+
runId: string | null;
|
|
141
|
+
/** True when this signal ended the run (`complete: true`). */
|
|
142
|
+
closedRun: boolean;
|
|
143
|
+
/** True once the run's completion was counted against the allowance. Diverges
|
|
144
|
+
* from `closedRun` only when a run closes with no allowance left — it waits,
|
|
145
|
+
* then flips true once a top-up settles it. */
|
|
102
146
|
completed: boolean;
|
|
103
|
-
|
|
147
|
+
/** How many signals the run holds after this one. */
|
|
148
|
+
signalCount: number;
|
|
149
|
+
/** The outcome's catalogue step count — not a progress target, since steps
|
|
150
|
+
* may repeat within a run. */
|
|
104
151
|
totalSteps: number;
|
|
105
152
|
}
|
|
106
153
|
/** The customer's remaining balance for the dimension a signal metered, AFTER
|
|
@@ -200,7 +247,6 @@ interface CustomerProfileInput {
|
|
|
200
247
|
taxId?: string | null;
|
|
201
248
|
notes?: string | null;
|
|
202
249
|
logoUrl?: string | null;
|
|
203
|
-
creditAllowance?: number;
|
|
204
250
|
/** ISO 4217 (3 letters); must be enabled for the org. */
|
|
205
251
|
currencyCode?: string;
|
|
206
252
|
}
|
|
@@ -1593,4 +1639,4 @@ declare class NetworkError extends ClockNextError {
|
|
|
1593
1639
|
constructor(message: string);
|
|
1594
1640
|
}
|
|
1595
1641
|
|
|
1596
|
-
export { type AddMemberInput, AllowanceError, type ApiCustomer, AuthError, type BillingCycle, type BillingMode, ClockNext, type ClockNextConfig, ClockNextError, type ComponentType, ConflictError, type CostPoint, type CostStats, 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, type Invoice, type InvoiceDetail, type InvoiceLineItem, type InvoiceListRow, type InvoiceParty, type InvoicePlanSnapshot, type InvoiceStatus, type Logger, type Member, type MemberRole, 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 SerializedOutcomeAttribution, type SerializedRuleApplication, type SerializedUnitUsage, type SerializedUsageLog, ServerError, type Signal, 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 UnitUsageList, type UnitUsageRow, type UpdateCreditInput, type UpdateMemberInput, type UpdateOutcomeInput, type UpdatePlanInput, type UpdateUnitInput, type UpsertWebhookInput, type UsageBalance, type UsageList, ValidationError, type WalletComponentInput, type WalletEntryInput, type WalletInput, type WalletList, type WalletSignal, type WalletTransaction, type WalletTransactionType, type Webhook, type WorkspaceIdentity, signalToWire };
|
|
1642
|
+
export { type AddMemberInput, AllowanceError, type ApiCustomer, AuthError, type BillingCycle, type BillingMode, ClockNext, type ClockNextConfig, ClockNextError, type ComponentType, ConflictError, type CostPoint, type CostStats, 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, type Invoice, type InvoiceDetail, type InvoiceLineItem, type InvoiceListRow, type InvoiceParty, type InvoicePlanSnapshot, type InvoiceStatus, type Logger, type Member, type MemberRole, type MetricTag, 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 SerializedOutcomeAttribution, type SerializedRuleApplication, type SerializedUnitUsage, type SerializedUsageLog, ServerError, type Signal, 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 UnitUsageList, type UnitUsageRow, type UpdateCreditInput, type UpdateMemberInput, type UpdateOutcomeInput, type UpdatePlanInput, type UpdateUnitInput, type UpsertWebhookInput, type UsageBalance, type UsageList, ValidationError, type WalletComponentInput, type WalletEntryInput, type WalletInput, type WalletList, type WalletSignal, type WalletTransaction, type WalletTransactionType, type Webhook, type WorkspaceIdentity, signalToWire };
|
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,21 @@ interface Tokens {
|
|
|
18
18
|
output: number;
|
|
19
19
|
cache?: number;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Tags a signal with a pricing metric for reporting. `ref` is the metric's
|
|
23
|
+
* `refId` (defined in Settings → Pricing metrics) and `value` is your own
|
|
24
|
+
* correlation id — a session, a call, a tenant — which the metric rolls up one
|
|
25
|
+
* row per distinct value. Reporting only: a metric never affects billing, a bad
|
|
26
|
+
* tag never fails the signal, and a `ref` naming no live metric is simply
|
|
27
|
+
* ignored. Applies to credit and outcome signals (ignored on wallet).
|
|
28
|
+
*/
|
|
29
|
+
interface MetricTag {
|
|
30
|
+
/** The metric's `refId`. Case-insensitive; must not collide with a reserved
|
|
31
|
+
* ingest field (e.g. `model`, `member`, `agentKey`, `runId`, `custom`). */
|
|
32
|
+
ref: string;
|
|
33
|
+
/** Your correlation value for this metric, stored verbatim. */
|
|
34
|
+
value: string | number;
|
|
35
|
+
}
|
|
21
36
|
/** The organisation + key behind a request — `cnk.workspace.me()`. */
|
|
22
37
|
interface WorkspaceIdentity {
|
|
23
38
|
organization: {
|
|
@@ -75,16 +90,36 @@ interface CreditSignal extends SignalBase {
|
|
|
75
90
|
type: "credit";
|
|
76
91
|
/** The Credit's stable agent key (assigned when the credit was created). */
|
|
77
92
|
agentKey: string;
|
|
93
|
+
/** Optional pricing-metric tag for reporting. */
|
|
94
|
+
metric?: MetricTag;
|
|
78
95
|
}
|
|
79
96
|
/** Debits the customer's wallet in USD at the model's cost. */
|
|
80
97
|
interface WalletSignal extends SignalBase {
|
|
81
98
|
type: "wallet";
|
|
82
99
|
}
|
|
83
|
-
/**
|
|
100
|
+
/**
|
|
101
|
+
* Records one step of a multi-call outcome run. The `agentKey` identifies the
|
|
102
|
+
* step (and the outcome); `runId` groups every signal of a single run, so a step
|
|
103
|
+
* may repeat freely. The run bills once, when the caller marks it `complete`.
|
|
104
|
+
*/
|
|
84
105
|
interface OutcomeSignal extends SignalBase {
|
|
85
106
|
type: "outcome";
|
|
86
107
|
/** The OutcomeStep's stable agent key — identifies the outcome AND the step. */
|
|
87
108
|
agentKey: string;
|
|
109
|
+
/**
|
|
110
|
+
* Correlates every signal of one workflow run. Required. A step may fire more
|
|
111
|
+
* than once within a run (a "verify" loop firing 3× is three signals, one
|
|
112
|
+
* outcome). Opaque to ClockNext — any string you can correlate; unique per org.
|
|
113
|
+
*/
|
|
114
|
+
runId: string;
|
|
115
|
+
/**
|
|
116
|
+
* Set `true` on the LAST step signal to declare the run finished — completion
|
|
117
|
+
* is never inferred from step coverage. Sending it twice is a safe no-op and
|
|
118
|
+
* can't bill again.
|
|
119
|
+
*/
|
|
120
|
+
complete?: boolean;
|
|
121
|
+
/** Optional pricing-metric tag for reporting. */
|
|
122
|
+
metric?: MetricTag;
|
|
88
123
|
}
|
|
89
124
|
type Signal = CreditSignal | WalletSignal | OutcomeSignal;
|
|
90
125
|
/** Helper input shapes for the per-type convenience methods. */
|
|
@@ -98,9 +133,21 @@ interface SerializedRuleApplication {
|
|
|
98
133
|
}
|
|
99
134
|
interface SerializedOutcomeAttribution {
|
|
100
135
|
name: string;
|
|
136
|
+
/** The step of the outcome this signal performed. */
|
|
101
137
|
step: string;
|
|
138
|
+
/** The caller's run id — every signal of one run shares it. `null` on logs
|
|
139
|
+
* recorded before the run-based flow. */
|
|
140
|
+
runId: string | null;
|
|
141
|
+
/** True when this signal ended the run (`complete: true`). */
|
|
142
|
+
closedRun: boolean;
|
|
143
|
+
/** True once the run's completion was counted against the allowance. Diverges
|
|
144
|
+
* from `closedRun` only when a run closes with no allowance left — it waits,
|
|
145
|
+
* then flips true once a top-up settles it. */
|
|
102
146
|
completed: boolean;
|
|
103
|
-
|
|
147
|
+
/** How many signals the run holds after this one. */
|
|
148
|
+
signalCount: number;
|
|
149
|
+
/** The outcome's catalogue step count — not a progress target, since steps
|
|
150
|
+
* may repeat within a run. */
|
|
104
151
|
totalSteps: number;
|
|
105
152
|
}
|
|
106
153
|
/** The customer's remaining balance for the dimension a signal metered, AFTER
|
|
@@ -200,7 +247,6 @@ interface CustomerProfileInput {
|
|
|
200
247
|
taxId?: string | null;
|
|
201
248
|
notes?: string | null;
|
|
202
249
|
logoUrl?: string | null;
|
|
203
|
-
creditAllowance?: number;
|
|
204
250
|
/** ISO 4217 (3 letters); must be enabled for the org. */
|
|
205
251
|
currencyCode?: string;
|
|
206
252
|
}
|
|
@@ -1593,4 +1639,4 @@ declare class NetworkError extends ClockNextError {
|
|
|
1593
1639
|
constructor(message: string);
|
|
1594
1640
|
}
|
|
1595
1641
|
|
|
1596
|
-
export { type AddMemberInput, AllowanceError, type ApiCustomer, AuthError, type BillingCycle, type BillingMode, ClockNext, type ClockNextConfig, ClockNextError, type ComponentType, ConflictError, type CostPoint, type CostStats, 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, type Invoice, type InvoiceDetail, type InvoiceLineItem, type InvoiceListRow, type InvoiceParty, type InvoicePlanSnapshot, type InvoiceStatus, type Logger, type Member, type MemberRole, 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 SerializedOutcomeAttribution, type SerializedRuleApplication, type SerializedUnitUsage, type SerializedUsageLog, ServerError, type Signal, 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 UnitUsageList, type UnitUsageRow, type UpdateCreditInput, type UpdateMemberInput, type UpdateOutcomeInput, type UpdatePlanInput, type UpdateUnitInput, type UpsertWebhookInput, type UsageBalance, type UsageList, ValidationError, type WalletComponentInput, type WalletEntryInput, type WalletInput, type WalletList, type WalletSignal, type WalletTransaction, type WalletTransactionType, type Webhook, type WorkspaceIdentity, signalToWire };
|
|
1642
|
+
export { type AddMemberInput, AllowanceError, type ApiCustomer, AuthError, type BillingCycle, type BillingMode, ClockNext, type ClockNextConfig, ClockNextError, type ComponentType, ConflictError, type CostPoint, type CostStats, 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, type Invoice, type InvoiceDetail, type InvoiceLineItem, type InvoiceListRow, type InvoiceParty, type InvoicePlanSnapshot, type InvoiceStatus, type Logger, type Member, type MemberRole, type MetricTag, 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 SerializedOutcomeAttribution, type SerializedRuleApplication, type SerializedUnitUsage, type SerializedUsageLog, ServerError, type Signal, 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 UnitUsageList, type UnitUsageRow, type UpdateCreditInput, type UpdateMemberInput, type UpdateOutcomeInput, type UpdatePlanInput, type UpdateUnitInput, type UpsertWebhookInput, type UsageBalance, type UsageList, ValidationError, type WalletComponentInput, type WalletEntryInput, type WalletInput, type WalletList, type WalletSignal, type WalletTransaction, type WalletTransactionType, type Webhook, type WorkspaceIdentity, signalToWire };
|
package/dist/index.js
CHANGED
|
@@ -227,7 +227,7 @@ function sleep(ms) {
|
|
|
227
227
|
}
|
|
228
228
|
|
|
229
229
|
// src/http.ts
|
|
230
|
-
var SDK_VERSION = "0.
|
|
230
|
+
var SDK_VERSION = "0.7.0" ;
|
|
231
231
|
var Transport = class {
|
|
232
232
|
constructor(cfg) {
|
|
233
233
|
this.cfg = cfg;
|
|
@@ -868,6 +868,13 @@ function signalToWire(signal) {
|
|
|
868
868
|
if (signal.type === "credit" || signal.type === "outcome") {
|
|
869
869
|
body.agentKey = signal.agentKey;
|
|
870
870
|
}
|
|
871
|
+
if (signal.type === "outcome") {
|
|
872
|
+
body.runId = signal.runId;
|
|
873
|
+
if (signal.complete != null) body.complete = signal.complete;
|
|
874
|
+
}
|
|
875
|
+
if (signal.type !== "wallet" && signal.metric) {
|
|
876
|
+
body[signal.metric.ref] = signal.metric.value;
|
|
877
|
+
}
|
|
871
878
|
if (signal.idempotencyKey) body.idempotencyKey = signal.idempotencyKey;
|
|
872
879
|
return body;
|
|
873
880
|
}
|