@clocknext/sdk 0.19.0 → 0.19.1
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 +28 -0
- package/dist/index.cjs +22 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +113 -1
- package/dist/index.d.ts +113 -1
- package/dist/index.js +22 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +3 -0
- package/src/resources/signals.ts +23 -0
- package/src/types.ts +77 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
package/src/resources/signals.ts
CHANGED
|
@@ -18,6 +18,7 @@ import type {
|
|
|
18
18
|
UnitTrackResult,
|
|
19
19
|
UsageLogListParams,
|
|
20
20
|
UsageLogPage,
|
|
21
|
+
UsageLogLookupResult,
|
|
21
22
|
WalletInput,
|
|
22
23
|
} from "../types.js";
|
|
23
24
|
|
|
@@ -46,6 +47,7 @@ const UNIT_PATH = "/api/v1/signal/unit";
|
|
|
46
47
|
const COMPOSITE_COMPLETE_PATH = "/api/v1/signal/composite/complete";
|
|
47
48
|
const OUTCOME_COMPLETE_PATH = "/api/v1/signal/outcome/complete";
|
|
48
49
|
const USAGE_LOG_PATH = "/api/v1/signal/usage-log";
|
|
50
|
+
const USAGE_LOG_LOOKUP_PATH = "/api/v1/signal/usage-log/lookup";
|
|
49
51
|
|
|
50
52
|
/**
|
|
51
53
|
* Builds the request body for a typed Signal.
|
|
@@ -444,4 +446,25 @@ export class Signals {
|
|
|
444
446
|
},
|
|
445
447
|
});
|
|
446
448
|
}
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* Fetches up to 100 usage-log rows by id, in one call.
|
|
452
|
+
* `GET /api/v1/signal/usage-log/lookup`.
|
|
453
|
+
*
|
|
454
|
+
* Built for linking a wallet debit to its usage: pass the `usageLogId`s
|
|
455
|
+
* from `customers.wallet()` instead of paging through
|
|
456
|
+
* {@link usageLog}. Scoped to your org, not to one customer — every row
|
|
457
|
+
* carries its own `customerId`.
|
|
458
|
+
*
|
|
459
|
+
* Rows come back in the order of `ids`; duplicates are removed. Ids that
|
|
460
|
+
* match nothing in your org are listed in `notFound`. More than 100
|
|
461
|
+
* distinct ids is a 400.
|
|
462
|
+
*/
|
|
463
|
+
lookupUsageLogs(ids: string[]): Promise<UsageLogLookupResult> {
|
|
464
|
+
return this.transport.request<UsageLogLookupResult>({
|
|
465
|
+
method: "GET",
|
|
466
|
+
path: USAGE_LOG_LOOKUP_PATH,
|
|
467
|
+
query: { ids: ids.join(",") },
|
|
468
|
+
});
|
|
469
|
+
}
|
|
447
470
|
}
|
package/src/types.ts
CHANGED
|
@@ -484,6 +484,83 @@ export interface UsageLogPage {
|
|
|
484
484
|
nextCursor: string | null;
|
|
485
485
|
}
|
|
486
486
|
|
|
487
|
+
// ---------------------------------------------------------------------------
|
|
488
|
+
// Usage log lookup (mirrors GET /api/v1/signal/usage-log/lookup)
|
|
489
|
+
// ---------------------------------------------------------------------------
|
|
490
|
+
|
|
491
|
+
/** What a {@link UsageLogLookupEntry} row is. `"outcome"` is one step of a
|
|
492
|
+
* run; `"outcome_completion"` and `"composite_completion"` are the finished
|
|
493
|
+
* runs themselves. */
|
|
494
|
+
export type UsageLogLookupEntitlementType =
|
|
495
|
+
| "credit"
|
|
496
|
+
| "outcome"
|
|
497
|
+
| "outcome_completion"
|
|
498
|
+
| "unit"
|
|
499
|
+
| "composite_completion"
|
|
500
|
+
| "wallet";
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* One row of `signals.lookupUsageLogs()`. Only the group that matches
|
|
504
|
+
* `entitlement.type` holds data; the others are `null`.
|
|
505
|
+
*/
|
|
506
|
+
export interface UsageLogLookupEntry {
|
|
507
|
+
id: string;
|
|
508
|
+
/** The customer this row belongs to — a lookup can span customers. */
|
|
509
|
+
customerId: string;
|
|
510
|
+
/** For a finished run (`outcome_completion`, `composite_completion`), when
|
|
511
|
+
* it completed. */
|
|
512
|
+
createdAt: string;
|
|
513
|
+
status: SignalStatus;
|
|
514
|
+
/** The credit / outcome / unit / composite this row is for. A wallet row has
|
|
515
|
+
* `id: null` and `name: "Wallet"`. */
|
|
516
|
+
entitlement: { type: UsageLogLookupEntitlementType; id: string | null; name: string | null };
|
|
517
|
+
member: string | null;
|
|
518
|
+
model: { name: string | null; provider: string | null } | null;
|
|
519
|
+
usage: {
|
|
520
|
+
inputTokens: number;
|
|
521
|
+
outputTokens: number;
|
|
522
|
+
/** Cache-read tokens. */
|
|
523
|
+
cacheTokens: number;
|
|
524
|
+
/** Cache-write tokens, priced separately from cache reads. */
|
|
525
|
+
cacheWriteTokens: number;
|
|
526
|
+
};
|
|
527
|
+
/** Formatted USD strings. `customerCost` is what this row charged:
|
|
528
|
+
* `"$0.00"` on an outcome step (the run is billed at completion) and on any
|
|
529
|
+
* row a composite pays for. On a unit row it is what the wallet paid for
|
|
530
|
+
* that report (debits minus refunds), `"$0.00"` when the wallet paid
|
|
531
|
+
* nothing. */
|
|
532
|
+
cost: { providedCost: string; customerCost: string };
|
|
533
|
+
/** `entitlement.type === "credit"`. */
|
|
534
|
+
credit: { amount: string; appliedRules: UsageLogAppliedRule[] } | null;
|
|
535
|
+
/** `entitlement.type === "outcome"`. `runCompleted` is true once the run is
|
|
536
|
+
* finished — on every step row of that run. */
|
|
537
|
+
outcome: { step: string | null; stepName: string | null; runId: string | null; runCompleted: boolean } | null;
|
|
538
|
+
/** `entitlement.type === "outcome_completion"`. `amount` is the price frozen
|
|
539
|
+
* when the run completed. */
|
|
540
|
+
outcomeCompletion: { runId: string | null; amount: string } | null;
|
|
541
|
+
/** `entitlement.type === "unit"`. `quantity` is formatted. */
|
|
542
|
+
unit: { quantity: string } | null;
|
|
543
|
+
/** `entitlement.type === "composite_completion"`. `refId` is the
|
|
544
|
+
* composite's tag key, `runId` the tag value you sent. */
|
|
545
|
+
compositeCompletion: { refId: string | null; runId: string | null; amount: string; startedAt: string } | null;
|
|
546
|
+
/** `entitlement.type === "wallet"`. What the wallet paid, formatted USD —
|
|
547
|
+
* the same value as `cost.customerCost`. */
|
|
548
|
+
wallet: { amount: string } | null;
|
|
549
|
+
/** The composite that pays for this row — its id, its tag key (`refId`) and
|
|
550
|
+
* the tag value you sent (`runId`). `null` when the row is billed by
|
|
551
|
+
* itself. */
|
|
552
|
+
composite: { id: string | null; refId: string | null; runId: string | null } | null;
|
|
553
|
+
/** The `custom` object sent, as sent. `null` when none was sent. */
|
|
554
|
+
custom: Record<string, unknown> | null;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
export interface UsageLogLookupResult {
|
|
558
|
+
/** The rows found, in the order of the ids you asked for. */
|
|
559
|
+
usageLogs: UsageLogLookupEntry[];
|
|
560
|
+
/** The ids that matched nothing in your org, in the order you asked. */
|
|
561
|
+
notFound: string[];
|
|
562
|
+
}
|
|
563
|
+
|
|
487
564
|
// ---------------------------------------------------------------------------
|
|
488
565
|
// Customers (mirrors src/lib/customers/api.ts)
|
|
489
566
|
// ---------------------------------------------------------------------------
|