runcycles 0.1.1 → 0.1.2
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 +10 -1
- package/dist/index.cjs +10 -0
- package/dist/index.d.cts +11 -5
- package/dist/index.d.ts +11 -5
- package/dist/index.js +9 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -58,6 +58,15 @@ const callLlm = withCycles(
|
|
|
58
58
|
const result = await callLlm("Hello", 100);
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
+
> **Need an API key?** API keys are created via the Cycles Admin Server (port 7979). See the [deployment guide](https://runcycles.io/quickstart/deploying-the-full-cycles-stack#step-3-create-an-api-key) to create one, or run:
|
|
62
|
+
> ```bash
|
|
63
|
+
> curl -s -X POST http://localhost:7979/v1/admin/api-keys \
|
|
64
|
+
> -H "Content-Type: application/json" \
|
|
65
|
+
> -H "X-Admin-API-Key: admin-bootstrap-key" \
|
|
66
|
+
> -d '{"tenant_id":"acme-corp","name":"dev-key","permissions":["reservations:create","reservations:commit","reservations:release","reservations:extend","reservations:list","balances:read","decide","events:create"]}' | jq -r '.key_secret'
|
|
67
|
+
> ```
|
|
68
|
+
> The key (e.g. `cyc_live_abc123...`) is shown only once — save it immediately. For key rotation and lifecycle details, see [API Key Management](https://runcycles.io/how-to/api-key-management-in-cycles).
|
|
69
|
+
|
|
61
70
|
**What happens:** `withCycles` reserves budget before calling your function, runs it inside an async context (so `getCyclesContext()` works), commits the actual cost on success, or releases the reservation on failure. A background heartbeat keeps the reservation alive.
|
|
62
71
|
|
|
63
72
|
### 2. Streaming adapter
|
|
@@ -234,7 +243,7 @@ const config = CyclesConfig.fromEnv();
|
|
|
234
243
|
| Variable | Required | Description |
|
|
235
244
|
|----------|----------|-------------|
|
|
236
245
|
| `CYCLES_BASE_URL` | Yes | Cycles server URL |
|
|
237
|
-
| `CYCLES_API_KEY` | Yes | API key for authentication |
|
|
246
|
+
| `CYCLES_API_KEY` | Yes | API key for authentication (see [how to create one](https://runcycles.io/quickstart/deploying-the-full-cycles-stack#step-3-create-an-api-key)) |
|
|
238
247
|
| `CYCLES_TENANT` | No | Default tenant |
|
|
239
248
|
| `CYCLES_WORKSPACE` | No | Default workspace |
|
|
240
249
|
| `CYCLES_APP` | No | Default app |
|
package/dist/index.cjs
CHANGED
|
@@ -28,6 +28,7 @@ __export(index_exports, {
|
|
|
28
28
|
CyclesError: () => CyclesError,
|
|
29
29
|
CyclesProtocolError: () => CyclesProtocolError,
|
|
30
30
|
CyclesResponse: () => CyclesResponse,
|
|
31
|
+
CyclesTransportError: () => CyclesTransportError,
|
|
31
32
|
DebtOutstandingError: () => DebtOutstandingError,
|
|
32
33
|
Decision: () => Decision,
|
|
33
34
|
ErrorCode: () => ErrorCode,
|
|
@@ -722,6 +723,14 @@ var ReservationFinalizedError = class extends CyclesProtocolError {
|
|
|
722
723
|
this.name = "ReservationFinalizedError";
|
|
723
724
|
}
|
|
724
725
|
};
|
|
726
|
+
var CyclesTransportError = class extends CyclesError {
|
|
727
|
+
cause;
|
|
728
|
+
constructor(message, options) {
|
|
729
|
+
super(message);
|
|
730
|
+
this.name = "CyclesTransportError";
|
|
731
|
+
this.cause = options?.cause;
|
|
732
|
+
}
|
|
733
|
+
};
|
|
725
734
|
|
|
726
735
|
// src/errors.ts
|
|
727
736
|
function buildProtocolException(prefix, response) {
|
|
@@ -1414,6 +1423,7 @@ async function reserveForStream(options) {
|
|
|
1414
1423
|
CyclesError,
|
|
1415
1424
|
CyclesProtocolError,
|
|
1416
1425
|
CyclesResponse,
|
|
1426
|
+
CyclesTransportError,
|
|
1417
1427
|
DebtOutstandingError,
|
|
1418
1428
|
Decision,
|
|
1419
1429
|
ErrorCode,
|
package/dist/index.d.cts
CHANGED
|
@@ -335,9 +335,9 @@ declare class CyclesClient {
|
|
|
335
335
|
|
|
336
336
|
/** Lifecycle orchestration: reserve -> execute -> commit/release. */
|
|
337
337
|
|
|
338
|
-
interface WithCyclesConfig {
|
|
339
|
-
estimate: number | ((...args:
|
|
340
|
-
actual?: number | ((result:
|
|
338
|
+
interface WithCyclesConfig<TArgs extends unknown[] = unknown[], TResult = unknown> {
|
|
339
|
+
estimate: number | ((...args: TArgs) => number);
|
|
340
|
+
actual?: number | ((result: TResult) => number);
|
|
341
341
|
actionKind?: string;
|
|
342
342
|
actionName?: string;
|
|
343
343
|
actionTags?: string[];
|
|
@@ -360,7 +360,7 @@ interface WithCyclesConfig {
|
|
|
360
360
|
|
|
361
361
|
declare function setDefaultClient(client: CyclesClient): void;
|
|
362
362
|
declare function setDefaultConfig(config: CyclesConfig): void;
|
|
363
|
-
declare function withCycles<TArgs extends unknown[], TResult>(options: WithCyclesConfig & {
|
|
363
|
+
declare function withCycles<TArgs extends unknown[], TResult>(options: WithCyclesConfig<TArgs, TResult> & {
|
|
364
364
|
client?: CyclesClient;
|
|
365
365
|
}, fn: (...args: TArgs) => Promise<TResult>): (...args: TArgs) => Promise<TResult>;
|
|
366
366
|
|
|
@@ -508,6 +508,12 @@ declare class ReservationExpiredError extends CyclesProtocolError {
|
|
|
508
508
|
declare class ReservationFinalizedError extends CyclesProtocolError {
|
|
509
509
|
constructor(message: string, options?: ConstructorParameters<typeof CyclesProtocolError>[1]);
|
|
510
510
|
}
|
|
511
|
+
declare class CyclesTransportError extends CyclesError {
|
|
512
|
+
readonly cause: Error | undefined;
|
|
513
|
+
constructor(message: string, options?: {
|
|
514
|
+
cause?: Error;
|
|
515
|
+
});
|
|
516
|
+
}
|
|
511
517
|
|
|
512
518
|
/**
|
|
513
519
|
* Explicit request/response mappers between camelCase TypeScript interfaces
|
|
@@ -543,4 +549,4 @@ declare function reservationExtendRequestToWire(req: ReservationExtendRequest):
|
|
|
543
549
|
declare function decisionRequestToWire(req: DecisionRequest): Record<string, unknown>;
|
|
544
550
|
declare function eventCreateRequestToWire(req: EventCreateRequest): Record<string, unknown>;
|
|
545
551
|
|
|
546
|
-
export { type Action, type Amount, type Balance, type BalanceResponse, BudgetExceededError, type Caps, CommitOveragePolicy, type CommitRequest, type CommitResponse, CommitStatus, CyclesClient, CyclesConfig, type CyclesContext, CyclesError, type CyclesMetrics, CyclesProtocolError, CyclesResponse, DebtOutstandingError, Decision, type DecisionRequest, type DecisionResponse, type DryRunResult, ErrorCode, type ErrorResponse, type EventCreateRequest, type EventCreateResponse, EventStatus, ExtendStatus, OverdraftLimitExceededError, type ReleaseRequest, type ReleaseResponse, ReleaseStatus, type ReservationCreateRequest, type ReservationCreateResponse, type ReservationDetail, ReservationExpiredError, type ReservationExtendRequest, type ReservationExtendResponse, ReservationFinalizedError, type ReservationListResponse, ReservationStatus, type ReservationSummary, type SignedAmount, type StreamReservation, type StreamReservationOptions, type Subject, Unit, type WithCyclesConfig, balanceResponseFromWire, capsFromWire, commitRequestToWire, commitResponseFromWire, decisionRequestToWire, decisionResponseFromWire, errorCodeFromString, errorResponseFromWire, eventCreateRequestToWire, eventCreateResponseFromWire, getCyclesContext, isAllowed, isDenied, isMetricsEmpty, isRetryableErrorCode, isToolAllowed, metricsToWire, releaseRequestToWire, releaseResponseFromWire, reservationCreateRequestToWire, reservationCreateResponseFromWire, reservationDetailFromWire, reservationExtendRequestToWire, reservationExtendResponseFromWire, reservationListResponseFromWire, reservationSummaryFromWire, reserveForStream, setDefaultClient, setDefaultConfig, withCycles };
|
|
552
|
+
export { type Action, type Amount, type Balance, type BalanceResponse, BudgetExceededError, type Caps, CommitOveragePolicy, type CommitRequest, type CommitResponse, CommitStatus, CyclesClient, CyclesConfig, type CyclesContext, CyclesError, type CyclesMetrics, CyclesProtocolError, CyclesResponse, CyclesTransportError, DebtOutstandingError, Decision, type DecisionRequest, type DecisionResponse, type DryRunResult, ErrorCode, type ErrorResponse, type EventCreateRequest, type EventCreateResponse, EventStatus, ExtendStatus, OverdraftLimitExceededError, type ReleaseRequest, type ReleaseResponse, ReleaseStatus, type ReservationCreateRequest, type ReservationCreateResponse, type ReservationDetail, ReservationExpiredError, type ReservationExtendRequest, type ReservationExtendResponse, ReservationFinalizedError, type ReservationListResponse, ReservationStatus, type ReservationSummary, type SignedAmount, type StreamReservation, type StreamReservationOptions, type Subject, Unit, type WithCyclesConfig, balanceResponseFromWire, capsFromWire, commitRequestToWire, commitResponseFromWire, decisionRequestToWire, decisionResponseFromWire, errorCodeFromString, errorResponseFromWire, eventCreateRequestToWire, eventCreateResponseFromWire, getCyclesContext, isAllowed, isDenied, isMetricsEmpty, isRetryableErrorCode, isToolAllowed, metricsToWire, releaseRequestToWire, releaseResponseFromWire, reservationCreateRequestToWire, reservationCreateResponseFromWire, reservationDetailFromWire, reservationExtendRequestToWire, reservationExtendResponseFromWire, reservationListResponseFromWire, reservationSummaryFromWire, reserveForStream, setDefaultClient, setDefaultConfig, withCycles };
|
package/dist/index.d.ts
CHANGED
|
@@ -335,9 +335,9 @@ declare class CyclesClient {
|
|
|
335
335
|
|
|
336
336
|
/** Lifecycle orchestration: reserve -> execute -> commit/release. */
|
|
337
337
|
|
|
338
|
-
interface WithCyclesConfig {
|
|
339
|
-
estimate: number | ((...args:
|
|
340
|
-
actual?: number | ((result:
|
|
338
|
+
interface WithCyclesConfig<TArgs extends unknown[] = unknown[], TResult = unknown> {
|
|
339
|
+
estimate: number | ((...args: TArgs) => number);
|
|
340
|
+
actual?: number | ((result: TResult) => number);
|
|
341
341
|
actionKind?: string;
|
|
342
342
|
actionName?: string;
|
|
343
343
|
actionTags?: string[];
|
|
@@ -360,7 +360,7 @@ interface WithCyclesConfig {
|
|
|
360
360
|
|
|
361
361
|
declare function setDefaultClient(client: CyclesClient): void;
|
|
362
362
|
declare function setDefaultConfig(config: CyclesConfig): void;
|
|
363
|
-
declare function withCycles<TArgs extends unknown[], TResult>(options: WithCyclesConfig & {
|
|
363
|
+
declare function withCycles<TArgs extends unknown[], TResult>(options: WithCyclesConfig<TArgs, TResult> & {
|
|
364
364
|
client?: CyclesClient;
|
|
365
365
|
}, fn: (...args: TArgs) => Promise<TResult>): (...args: TArgs) => Promise<TResult>;
|
|
366
366
|
|
|
@@ -508,6 +508,12 @@ declare class ReservationExpiredError extends CyclesProtocolError {
|
|
|
508
508
|
declare class ReservationFinalizedError extends CyclesProtocolError {
|
|
509
509
|
constructor(message: string, options?: ConstructorParameters<typeof CyclesProtocolError>[1]);
|
|
510
510
|
}
|
|
511
|
+
declare class CyclesTransportError extends CyclesError {
|
|
512
|
+
readonly cause: Error | undefined;
|
|
513
|
+
constructor(message: string, options?: {
|
|
514
|
+
cause?: Error;
|
|
515
|
+
});
|
|
516
|
+
}
|
|
511
517
|
|
|
512
518
|
/**
|
|
513
519
|
* Explicit request/response mappers between camelCase TypeScript interfaces
|
|
@@ -543,4 +549,4 @@ declare function reservationExtendRequestToWire(req: ReservationExtendRequest):
|
|
|
543
549
|
declare function decisionRequestToWire(req: DecisionRequest): Record<string, unknown>;
|
|
544
550
|
declare function eventCreateRequestToWire(req: EventCreateRequest): Record<string, unknown>;
|
|
545
551
|
|
|
546
|
-
export { type Action, type Amount, type Balance, type BalanceResponse, BudgetExceededError, type Caps, CommitOveragePolicy, type CommitRequest, type CommitResponse, CommitStatus, CyclesClient, CyclesConfig, type CyclesContext, CyclesError, type CyclesMetrics, CyclesProtocolError, CyclesResponse, DebtOutstandingError, Decision, type DecisionRequest, type DecisionResponse, type DryRunResult, ErrorCode, type ErrorResponse, type EventCreateRequest, type EventCreateResponse, EventStatus, ExtendStatus, OverdraftLimitExceededError, type ReleaseRequest, type ReleaseResponse, ReleaseStatus, type ReservationCreateRequest, type ReservationCreateResponse, type ReservationDetail, ReservationExpiredError, type ReservationExtendRequest, type ReservationExtendResponse, ReservationFinalizedError, type ReservationListResponse, ReservationStatus, type ReservationSummary, type SignedAmount, type StreamReservation, type StreamReservationOptions, type Subject, Unit, type WithCyclesConfig, balanceResponseFromWire, capsFromWire, commitRequestToWire, commitResponseFromWire, decisionRequestToWire, decisionResponseFromWire, errorCodeFromString, errorResponseFromWire, eventCreateRequestToWire, eventCreateResponseFromWire, getCyclesContext, isAllowed, isDenied, isMetricsEmpty, isRetryableErrorCode, isToolAllowed, metricsToWire, releaseRequestToWire, releaseResponseFromWire, reservationCreateRequestToWire, reservationCreateResponseFromWire, reservationDetailFromWire, reservationExtendRequestToWire, reservationExtendResponseFromWire, reservationListResponseFromWire, reservationSummaryFromWire, reserveForStream, setDefaultClient, setDefaultConfig, withCycles };
|
|
552
|
+
export { type Action, type Amount, type Balance, type BalanceResponse, BudgetExceededError, type Caps, CommitOveragePolicy, type CommitRequest, type CommitResponse, CommitStatus, CyclesClient, CyclesConfig, type CyclesContext, CyclesError, type CyclesMetrics, CyclesProtocolError, CyclesResponse, CyclesTransportError, DebtOutstandingError, Decision, type DecisionRequest, type DecisionResponse, type DryRunResult, ErrorCode, type ErrorResponse, type EventCreateRequest, type EventCreateResponse, EventStatus, ExtendStatus, OverdraftLimitExceededError, type ReleaseRequest, type ReleaseResponse, ReleaseStatus, type ReservationCreateRequest, type ReservationCreateResponse, type ReservationDetail, ReservationExpiredError, type ReservationExtendRequest, type ReservationExtendResponse, ReservationFinalizedError, type ReservationListResponse, ReservationStatus, type ReservationSummary, type SignedAmount, type StreamReservation, type StreamReservationOptions, type Subject, Unit, type WithCyclesConfig, balanceResponseFromWire, capsFromWire, commitRequestToWire, commitResponseFromWire, decisionRequestToWire, decisionResponseFromWire, errorCodeFromString, errorResponseFromWire, eventCreateRequestToWire, eventCreateResponseFromWire, getCyclesContext, isAllowed, isDenied, isMetricsEmpty, isRetryableErrorCode, isToolAllowed, metricsToWire, releaseRequestToWire, releaseResponseFromWire, reservationCreateRequestToWire, reservationCreateResponseFromWire, reservationDetailFromWire, reservationExtendRequestToWire, reservationExtendResponseFromWire, reservationListResponseFromWire, reservationSummaryFromWire, reserveForStream, setDefaultClient, setDefaultConfig, withCycles };
|
package/dist/index.js
CHANGED
|
@@ -648,6 +648,14 @@ var ReservationFinalizedError = class extends CyclesProtocolError {
|
|
|
648
648
|
this.name = "ReservationFinalizedError";
|
|
649
649
|
}
|
|
650
650
|
};
|
|
651
|
+
var CyclesTransportError = class extends CyclesError {
|
|
652
|
+
cause;
|
|
653
|
+
constructor(message, options) {
|
|
654
|
+
super(message);
|
|
655
|
+
this.name = "CyclesTransportError";
|
|
656
|
+
this.cause = options?.cause;
|
|
657
|
+
}
|
|
658
|
+
};
|
|
651
659
|
|
|
652
660
|
// src/errors.ts
|
|
653
661
|
function buildProtocolException(prefix, response) {
|
|
@@ -1339,6 +1347,7 @@ export {
|
|
|
1339
1347
|
CyclesError,
|
|
1340
1348
|
CyclesProtocolError,
|
|
1341
1349
|
CyclesResponse,
|
|
1350
|
+
CyclesTransportError,
|
|
1342
1351
|
DebtOutstandingError,
|
|
1343
1352
|
Decision,
|
|
1344
1353
|
ErrorCode,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "runcycles",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "TypeScript client for the Cycles budget-management protocol",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "runcycles",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"test": "vitest run",
|
|
53
53
|
"test:watch": "vitest",
|
|
54
54
|
"test:coverage": "vitest run --coverage",
|
|
55
|
-
"typecheck": "tsc --noEmit",
|
|
55
|
+
"typecheck": "tsc --noEmit -p tsconfig.typecheck.json",
|
|
56
56
|
"prepublishOnly": "npm run lint && npm run build"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|