codai-sdk 0.5.0 → 0.6.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 +28 -0
- package/dist/index.d.ts +119 -1
- package/dist/index.js +41 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -198,6 +198,34 @@ with `balance`, `required`, `currency: 'micro_eur'` and `topupUrl`. `submit` and
|
|
|
198
198
|
`accept` are never retried. `waitFor` stops at `resolved | failed | declined | error`
|
|
199
199
|
(or `until`), and throws `ResolveError` with `status: 0` on timeout.
|
|
200
200
|
|
|
201
|
+
### Webhooks instead of polling
|
|
202
|
+
|
|
203
|
+
Pass `callback_url` (https, public host) on `submit`; the response carries
|
|
204
|
+
`callback_secret` **once** — store it. Resolve then POSTs `job.quoted`,
|
|
205
|
+
`job.declined`, `job.resolved`, `job.failed` and `job.error` events signed with
|
|
206
|
+
`x-codai-signature: t=<unix>,v1=<hex HMAC-SHA256>`. Verify against the raw body
|
|
207
|
+
with `verifyResolveWebhook` (server-side, uses `node:crypto`; 300 s tolerance by
|
|
208
|
+
default). Up to 3 attempts on `5xx`/`429`/network errors; deduplicate on
|
|
209
|
+
`x-codai-delivery`; delivery never changes job state — `get(id)` stays the truth.
|
|
210
|
+
|
|
211
|
+
```ts
|
|
212
|
+
import { verifyResolveWebhook, type ResolveWebhookEvent } from 'codai-sdk';
|
|
213
|
+
|
|
214
|
+
const q = await codai.resolve.submit({
|
|
215
|
+
repo_url: 'https://github.com/psf/requests',
|
|
216
|
+
issue_url: 'https://github.com/psf/requests/issues/6000',
|
|
217
|
+
callback_url: 'https://ci.example.com/hooks/codai-resolve',
|
|
218
|
+
});
|
|
219
|
+
await saveSecret(q.id, q.callback_secret!); // shown once
|
|
220
|
+
|
|
221
|
+
// in your webhook handler (Hono / Next route / express.raw):
|
|
222
|
+
const raw = await req.text();
|
|
223
|
+
if (!verifyResolveWebhook(secret, raw, req.headers.get('x-codai-signature'))) {
|
|
224
|
+
return new Response('bad signature', { status: 401 });
|
|
225
|
+
}
|
|
226
|
+
const evt = JSON.parse(raw) as ResolveWebhookEvent; // evt.event, evt.job.attestation_url
|
|
227
|
+
```
|
|
228
|
+
|
|
201
229
|
## Shared sessions, devices and hosts
|
|
202
230
|
|
|
203
231
|
Shared-sessions and hosts calls need a device UUID (`x-codai-device`). Set it once
|
package/dist/index.d.ts
CHANGED
|
@@ -11075,6 +11075,12 @@ type components = {
|
|
|
11075
11075
|
* @description `200` body — triage declined the issue. The job is persisted with `status: declined` and is never billed.
|
|
11076
11076
|
*/
|
|
11077
11077
|
readonly ResolveDeclined: {
|
|
11078
|
+
/**
|
|
11079
|
+
* @description Present only when the intake carried `callback_url` (a `job.declined` event is sent
|
|
11080
|
+
* too). HMAC-SHA256 key for webhook signatures. **Returned once** — store it now.
|
|
11081
|
+
* @example whsec_3q2-7wQ1d0X9mZk4Vb8yTnR5sLpA6cEe
|
|
11082
|
+
*/
|
|
11083
|
+
readonly callback_secret?: string;
|
|
11078
11084
|
/**
|
|
11079
11085
|
* @example feature request, no testable behavior
|
|
11080
11086
|
* @example triage unavailable, please retry
|
|
@@ -11132,6 +11138,15 @@ type components = {
|
|
|
11132
11138
|
* @description Body of `POST /v1/resolve/jobs`. Provide `issue_url` or `issue_text` (at least one).
|
|
11133
11139
|
*/
|
|
11134
11140
|
readonly ResolveIntake: {
|
|
11141
|
+
/**
|
|
11142
|
+
* Format: uri
|
|
11143
|
+
* @description Optional webhook target. Must be `https`, carry no credentials and point at a public
|
|
11144
|
+
* host (no localhost, private, link-local or metadata addresses; every DNS answer is
|
|
11145
|
+
* re-checked at delivery). Events are signed with the per-job `callback_secret`
|
|
11146
|
+
* returned in the intake response. Redirects are not followed.
|
|
11147
|
+
* @example https://ci.example.com/hooks/codai-resolve
|
|
11148
|
+
*/
|
|
11149
|
+
readonly callback_url?: string;
|
|
11135
11150
|
/** @description Inline issue description. Takes precedence over `issue_url`. Only the first 20 000 characters reach triage. */
|
|
11136
11151
|
readonly issue_text?: string;
|
|
11137
11152
|
/**
|
|
@@ -11203,6 +11218,12 @@ type components = {
|
|
|
11203
11218
|
* @description `201` body — the job was quoted (`quoted`) or auto-accepted on the free tier (`accepted`).
|
|
11204
11219
|
*/
|
|
11205
11220
|
readonly ResolveQuote: {
|
|
11221
|
+
/**
|
|
11222
|
+
* @description Present only when the intake carried `callback_url`. HMAC-SHA256 key for verifying
|
|
11223
|
+
* webhook signatures. **Returned once** — it is never shown again, store it now.
|
|
11224
|
+
* @example whsec_3q2-7wQ1d0X9mZk4Vb8yTnR5sLpA6cEe
|
|
11225
|
+
*/
|
|
11226
|
+
readonly callback_secret?: string;
|
|
11206
11227
|
/** @description Free resolves left for this user after this submission. */
|
|
11207
11228
|
readonly free_tier_remaining: number;
|
|
11208
11229
|
/** Format: uuid */
|
|
@@ -11252,6 +11273,53 @@ type components = {
|
|
|
11252
11273
|
/** @description Errors on the whole object, e.g. `one of issue_url or issue_text is required`. */
|
|
11253
11274
|
readonly formErrors: readonly string[];
|
|
11254
11275
|
};
|
|
11276
|
+
/**
|
|
11277
|
+
* Webhook event payload
|
|
11278
|
+
* @description JSON body POSTed to `callback_url`. Verify `x-codai-signature` over the raw bytes before trusting it.
|
|
11279
|
+
*/
|
|
11280
|
+
readonly ResolveWebhookEvent: {
|
|
11281
|
+
readonly event: components['schemas']['ResolveWebhookEventName'];
|
|
11282
|
+
readonly job: components['schemas']['ResolveWebhookJob'];
|
|
11283
|
+
/**
|
|
11284
|
+
* Format: date-time
|
|
11285
|
+
* @description When this delivery attempt was built (UTC).
|
|
11286
|
+
*/
|
|
11287
|
+
readonly sent_at: string;
|
|
11288
|
+
};
|
|
11289
|
+
/**
|
|
11290
|
+
* Webhook event
|
|
11291
|
+
* @description `job.quoted` (paid quote ready), `job.declined` (triage refused), `job.resolved` (verified fix + attestation), `job.failed` (no verified fix, hold refunded), `job.error` (infrastructure failure, hold refunded).
|
|
11292
|
+
* @enum {string}
|
|
11293
|
+
*/
|
|
11294
|
+
readonly ResolveWebhookEventName: 'job.quoted' | 'job.declined' | 'job.resolved' | 'job.failed' | 'job.error';
|
|
11295
|
+
/**
|
|
11296
|
+
* Webhook job snapshot
|
|
11297
|
+
* @description Snapshot of the job at send time. Nullable fields are `null` until the corresponding stage has run.
|
|
11298
|
+
*/
|
|
11299
|
+
readonly ResolveWebhookJob: {
|
|
11300
|
+
/** Format: uuid */
|
|
11301
|
+
readonly attestation_id: string | null;
|
|
11302
|
+
/**
|
|
11303
|
+
* Format: uri
|
|
11304
|
+
* @description Absolute URL of the public attestation (unlike the relative path on `GET /v1/resolve/jobs/{id}`).
|
|
11305
|
+
* @example https://resolve.codai.ro/v1/resolve/attestations/1f2c1a3e-8d4b-4f8e-9a1b-0c2d3e4f5a6b
|
|
11306
|
+
*/
|
|
11307
|
+
readonly attestation_url: string | null;
|
|
11308
|
+
/** Format: date-time */
|
|
11309
|
+
readonly completed_at: string | null;
|
|
11310
|
+
/** @description Upstream inference spend attributed to this job, USD micros (informational). */
|
|
11311
|
+
readonly cost_micro_usd: number;
|
|
11312
|
+
readonly decline_reason: string | null;
|
|
11313
|
+
readonly fail_reason: string | null;
|
|
11314
|
+
/** Format: uuid */
|
|
11315
|
+
readonly id: string;
|
|
11316
|
+
/** @description Quoted price in USD micros; `0` on the free tier. */
|
|
11317
|
+
readonly quote_micro_usd: number | null;
|
|
11318
|
+
/** Format: uri */
|
|
11319
|
+
readonly repo_url: string;
|
|
11320
|
+
readonly status: components['schemas']['ResolveJobStatus'];
|
|
11321
|
+
readonly tier: components['schemas']['ResolveTier'] | null;
|
|
11322
|
+
};
|
|
11255
11323
|
};
|
|
11256
11324
|
responses: {
|
|
11257
11325
|
/**
|
|
@@ -11473,6 +11541,35 @@ interface operations {
|
|
|
11473
11541
|
readonly 409: components['responses']['ResolveConflict'];
|
|
11474
11542
|
};
|
|
11475
11543
|
};
|
|
11544
|
+
readonly resolveJobWebhook: {
|
|
11545
|
+
readonly parameters: {
|
|
11546
|
+
readonly query?: never;
|
|
11547
|
+
readonly header: {
|
|
11548
|
+
/** @description Idempotency key `<jobId>:<event>`, identical on every retry. */
|
|
11549
|
+
readonly 'x-codai-delivery': string;
|
|
11550
|
+
/** @description Event name, same as `event` in the body. */
|
|
11551
|
+
readonly 'x-codai-event': components['schemas']['ResolveWebhookEventName'];
|
|
11552
|
+
/** @description `t=<unix seconds>,v1=<hex HMAC-SHA256 of "<t>.<raw body>">`. */
|
|
11553
|
+
readonly 'x-codai-signature': string;
|
|
11554
|
+
};
|
|
11555
|
+
readonly path?: never;
|
|
11556
|
+
readonly cookie?: never;
|
|
11557
|
+
};
|
|
11558
|
+
readonly requestBody: {
|
|
11559
|
+
readonly content: {
|
|
11560
|
+
readonly 'application/json': components['schemas']['ResolveWebhookEvent'];
|
|
11561
|
+
};
|
|
11562
|
+
};
|
|
11563
|
+
readonly responses: {
|
|
11564
|
+
/** @description Any 2xx acknowledges the delivery; the body is ignored. */
|
|
11565
|
+
readonly 200: {
|
|
11566
|
+
headers: {
|
|
11567
|
+
readonly [name: string]: unknown;
|
|
11568
|
+
};
|
|
11569
|
+
content?: never;
|
|
11570
|
+
};
|
|
11571
|
+
};
|
|
11572
|
+
};
|
|
11476
11573
|
}
|
|
11477
11574
|
|
|
11478
11575
|
/**
|
|
@@ -11499,6 +11596,27 @@ type ResolveReproTest = ResolveSchemas['ResolveReproTest'];
|
|
|
11499
11596
|
type ResolveHealth = ResolveSchemas['ResolveHealth'];
|
|
11500
11597
|
type ResolveValidationDetails = ResolveSchemas['ResolveValidationDetails'];
|
|
11501
11598
|
type ResolveInsufficientFunds = ResolveSchemas['ResolveInsufficientFunds'];
|
|
11599
|
+
/** Body POSTed to `callback_url` (verify with `verifyResolveWebhook` first). */
|
|
11600
|
+
type ResolveWebhookEvent = ResolveSchemas['ResolveWebhookEvent'];
|
|
11601
|
+
type ResolveWebhookEventName = ResolveSchemas['ResolveWebhookEventName'];
|
|
11602
|
+
type ResolveWebhookJob = ResolveSchemas['ResolveWebhookJob'];
|
|
11603
|
+
interface VerifyResolveWebhookOptions {
|
|
11604
|
+
/** Maximum age (and future skew) of `t`, in seconds. Default 300. */
|
|
11605
|
+
toleranceSeconds?: number;
|
|
11606
|
+
/** Current unix time in seconds (tests). Default `Date.now() / 1000`. */
|
|
11607
|
+
nowSeconds?: number;
|
|
11608
|
+
}
|
|
11609
|
+
/**
|
|
11610
|
+
* Verify a Resolve webhook delivery: `x-codai-signature: t=<unix>,v1=<hex>`
|
|
11611
|
+
* with `v1 = HMAC-SHA256(callback_secret, "<t>.<rawBody>")`. Pass the RAW
|
|
11612
|
+
* request body (before JSON parsing). Constant-time compare; rejects a
|
|
11613
|
+
* timestamp outside `toleranceSeconds`. Returns `false` for any bad input.
|
|
11614
|
+
*
|
|
11615
|
+
* Server-side only: uses `node:crypto` (Node 20.16+/22.3+, Bun, Deno), loaded
|
|
11616
|
+
* lazily so the rest of the SDK still bundles for browsers and edge runtimes.
|
|
11617
|
+
* Throws only when `node:crypto` is unavailable in the current runtime.
|
|
11618
|
+
*/
|
|
11619
|
+
declare function verifyResolveWebhook(secret: string, rawBody: string | Uint8Array, signatureHeader: string | null | undefined, opts?: VerifyResolveWebhookOptions): boolean;
|
|
11502
11620
|
/** Statuses after which a job never changes again. */
|
|
11503
11621
|
declare const RESOLVE_TERMINAL_STATUSES: ReadonlySet<ResolveJobStatus>;
|
|
11504
11622
|
/** Any non-2xx answer from the Resolve service (flat `{ error }` body). */
|
|
@@ -12068,4 +12186,4 @@ declare class Codai {
|
|
|
12068
12186
|
private legacyExt;
|
|
12069
12187
|
}
|
|
12070
12188
|
|
|
12071
|
-
export { Account, type AccountPatchRequest, type AccountPatchResponse, type AccountView, type AgentRun, type AgentRunAccepted, type AgentRunCreateRequest, type AgentRunRequest, type AgentRunResult, type AgentRunStats, type AgentRunStatus, type AgentRunStep, type AgentRunStreamEvent, AgentRuns, type AgentSyncResult, Agents, Audio, Chat, type ChatCallOptions, type ChatCompletionChunk, type ChatCompletionInput, type ChatCompletionRequest, type ChatCompletionResponse, ChatCompletions, type ChatMessage, type ChatOptions, type ChatResult, type ChatStream, type ChatStreamResult, type ChatTool, type ChatToolCall, type ChatUsage, Codai, type CodaiClientOptions, CodaiError, type CodaiRequestExtensions, type Device, type DevicePatch, type DevicePatched, Devices, type DispatchInbox, Embeddings, type EmbeddingsOptions, type EmbeddingsRequest, type EmbeddingsResponse, type EmbeddingsResult, type Environment, type EnvironmentAddMemberBody, type EnvironmentCreateBody, type EnvironmentDetail, type EnvironmentEnrollBody, type EnvironmentEnrollToken, type EnvironmentEnrolled, type EnvironmentMember, type EnvironmentMemberCreated, EnvironmentMembers, type EnvironmentPatchBody, type EnvironmentPort, type EnvironmentPortBody, EnvironmentPorts, type EnvironmentProvider, type EnvironmentRole, type EnvironmentSecret, type EnvironmentSecretSet, EnvironmentSecrets, type EnvironmentSshCa, type EnvironmentSshCert, type EnvironmentSshCertBody, type EnvironmentState, type EnvironmentTaskCreateBody, type EnvironmentTaskCreated, type EnvironmentTaskDetail, type EnvironmentTaskList, EnvironmentTasks, type EnvironmentTransition, Environments, type EphemeralScope, type EphemeralToken, type EphemeralTokenResponse, type ErrorCode, Feedback, type FeedbackRequest, type FeedbackResponse, Health, type HealthReadyResponse, type HealthResponse, type HostExecBody, type HostExecRequest, type HostExecResponse, type HostExecResultBody, type HostOp, type HostPresence, type HostStreamEvent, Hosts, HttpClient, type ListEnvironmentsQuery, type MessageCallOptions, type MessageInput, type MessageRequest, type MessageResponse, type MessageResult, type MessageStream, type MessageStreamEvent, type MessageStreamResult, Messages, type Model, type ModelList, Models, type NotificationList, Notifications, type NotificationsDeleted, type NotificationsRead, OPERATION_METHODS, type Org, type OrgAddMemberBody, type OrgMember, OrgMembers, type OrgRole, Orgs, type PhoneModel, PhoneModels, type Project, type ProjectCreateBody, type ProjectDetail, type ProjectIsolation, type ProjectPatchBody, Projects, RESOLVE_OPERATION_METHODS, RESOLVE_TERMINAL_STATUSES, type Receipt, Receipts, type RequestOptions, Resolve, type ResolveAccepted, type ResolveAttestation, type components as ResolveComponents, type ResolveDeclined, ResolveError, type ResolveHealth, type ResolveInsufficientFunds, ResolveInsufficientFundsError, type ResolveIntake, type ResolveJob, type ResolveJobStatus, type operations as ResolveOperations, type paths as ResolvePaths, type ResolveQuote, type ResolveReproTest, type ResolveSubmitResult, type ResolveTier, type ResolveValidationDetails, type ResolveWaitOptions, Responses, type ResponsesCallOptions, type ResponsesInput, type ResponsesRequest, type ResponsesResponse, type ResponsesResult, type ResponsesStream, type ResponsesStreamEvent, type ResponsesStreamResult, STREAMING_OPERATIONS, type Session, type SessionControl, type SessionControlAccepted, type SessionControlRequest, SessionControls, type SessionCreateRequest, type SessionDetail, type SessionDispatchRequest, type SessionDispatchResponse, type SessionEvent, SessionEvents, type SessionEventsAppendRequest, type SessionEventsAppendResponse, type SessionEventsPage, type SessionIncomingEvent, SessionLease, type SessionLeaseClaimRequest, type SessionLeaseResponse, type SessionListItem, type SessionPatchRequest, type SessionShare, type SessionShareCreateRequest, type SessionShareCreated, SessionShares, type SessionStreamEvent, Sessions, type SharedSession, type SpeechRequest, type SpeechResult, type SseFrame, type StatusResponse, type Task, type TaskConfirmRequest, type TaskConfirmResponse, type TaskListPage, type TaskListQuery, type TaskOutcome, type TaskStats, Tasks, type TokenUsage, Tokens, type ToolFetchRequest, type ToolFetchResponse, type ToolSearchRequest, type ToolSearchResponse, Tools, type TranscriptionOptions, type TranscriptionResponse, type TranscriptionResult, type TriggerCreateRequest, type TriggerCreated, type TriggerEvents, type TriggerList, type TriggerPatch, type TriggerTestRequest, type TriggerTestResult, type TriggerUpdated, Triggers, type components$1 as components, Codai as default, extensionHeaders, frameJson, mergeToolCall, type operations$1 as operations, type paths$1 as paths, readSse };
|
|
12189
|
+
export { Account, type AccountPatchRequest, type AccountPatchResponse, type AccountView, type AgentRun, type AgentRunAccepted, type AgentRunCreateRequest, type AgentRunRequest, type AgentRunResult, type AgentRunStats, type AgentRunStatus, type AgentRunStep, type AgentRunStreamEvent, AgentRuns, type AgentSyncResult, Agents, Audio, Chat, type ChatCallOptions, type ChatCompletionChunk, type ChatCompletionInput, type ChatCompletionRequest, type ChatCompletionResponse, ChatCompletions, type ChatMessage, type ChatOptions, type ChatResult, type ChatStream, type ChatStreamResult, type ChatTool, type ChatToolCall, type ChatUsage, Codai, type CodaiClientOptions, CodaiError, type CodaiRequestExtensions, type Device, type DevicePatch, type DevicePatched, Devices, type DispatchInbox, Embeddings, type EmbeddingsOptions, type EmbeddingsRequest, type EmbeddingsResponse, type EmbeddingsResult, type Environment, type EnvironmentAddMemberBody, type EnvironmentCreateBody, type EnvironmentDetail, type EnvironmentEnrollBody, type EnvironmentEnrollToken, type EnvironmentEnrolled, type EnvironmentMember, type EnvironmentMemberCreated, EnvironmentMembers, type EnvironmentPatchBody, type EnvironmentPort, type EnvironmentPortBody, EnvironmentPorts, type EnvironmentProvider, type EnvironmentRole, type EnvironmentSecret, type EnvironmentSecretSet, EnvironmentSecrets, type EnvironmentSshCa, type EnvironmentSshCert, type EnvironmentSshCertBody, type EnvironmentState, type EnvironmentTaskCreateBody, type EnvironmentTaskCreated, type EnvironmentTaskDetail, type EnvironmentTaskList, EnvironmentTasks, type EnvironmentTransition, Environments, type EphemeralScope, type EphemeralToken, type EphemeralTokenResponse, type ErrorCode, Feedback, type FeedbackRequest, type FeedbackResponse, Health, type HealthReadyResponse, type HealthResponse, type HostExecBody, type HostExecRequest, type HostExecResponse, type HostExecResultBody, type HostOp, type HostPresence, type HostStreamEvent, Hosts, HttpClient, type ListEnvironmentsQuery, type MessageCallOptions, type MessageInput, type MessageRequest, type MessageResponse, type MessageResult, type MessageStream, type MessageStreamEvent, type MessageStreamResult, Messages, type Model, type ModelList, Models, type NotificationList, Notifications, type NotificationsDeleted, type NotificationsRead, OPERATION_METHODS, type Org, type OrgAddMemberBody, type OrgMember, OrgMembers, type OrgRole, Orgs, type PhoneModel, PhoneModels, type Project, type ProjectCreateBody, type ProjectDetail, type ProjectIsolation, type ProjectPatchBody, Projects, RESOLVE_OPERATION_METHODS, RESOLVE_TERMINAL_STATUSES, type Receipt, Receipts, type RequestOptions, Resolve, type ResolveAccepted, type ResolveAttestation, type components as ResolveComponents, type ResolveDeclined, ResolveError, type ResolveHealth, type ResolveInsufficientFunds, ResolveInsufficientFundsError, type ResolveIntake, type ResolveJob, type ResolveJobStatus, type operations as ResolveOperations, type paths as ResolvePaths, type ResolveQuote, type ResolveReproTest, type ResolveSubmitResult, type ResolveTier, type ResolveValidationDetails, type ResolveWaitOptions, type ResolveWebhookEvent, type ResolveWebhookEventName, type ResolveWebhookJob, Responses, type ResponsesCallOptions, type ResponsesInput, type ResponsesRequest, type ResponsesResponse, type ResponsesResult, type ResponsesStream, type ResponsesStreamEvent, type ResponsesStreamResult, STREAMING_OPERATIONS, type Session, type SessionControl, type SessionControlAccepted, type SessionControlRequest, SessionControls, type SessionCreateRequest, type SessionDetail, type SessionDispatchRequest, type SessionDispatchResponse, type SessionEvent, SessionEvents, type SessionEventsAppendRequest, type SessionEventsAppendResponse, type SessionEventsPage, type SessionIncomingEvent, SessionLease, type SessionLeaseClaimRequest, type SessionLeaseResponse, type SessionListItem, type SessionPatchRequest, type SessionShare, type SessionShareCreateRequest, type SessionShareCreated, SessionShares, type SessionStreamEvent, Sessions, type SharedSession, type SpeechRequest, type SpeechResult, type SseFrame, type StatusResponse, type Task, type TaskConfirmRequest, type TaskConfirmResponse, type TaskListPage, type TaskListQuery, type TaskOutcome, type TaskStats, Tasks, type TokenUsage, Tokens, type ToolFetchRequest, type ToolFetchResponse, type ToolSearchRequest, type ToolSearchResponse, Tools, type TranscriptionOptions, type TranscriptionResponse, type TranscriptionResult, type TriggerCreateRequest, type TriggerCreated, type TriggerEvents, type TriggerList, type TriggerPatch, type TriggerTestRequest, type TriggerTestResult, type TriggerUpdated, Triggers, type VerifyResolveWebhookOptions, type components$1 as components, Codai as default, extensionHeaders, frameJson, mergeToolCall, type operations$1 as operations, type paths$1 as paths, readSse, verifyResolveWebhook };
|
package/dist/index.js
CHANGED
|
@@ -1220,6 +1220,46 @@ var Projects = class {
|
|
|
1220
1220
|
};
|
|
1221
1221
|
|
|
1222
1222
|
// src/resources/resolve.ts
|
|
1223
|
+
function verifyResolveWebhook(secret, rawBody, signatureHeader, opts = {}) {
|
|
1224
|
+
if (!secret || !signatureHeader) return false;
|
|
1225
|
+
let t;
|
|
1226
|
+
const v1s = [];
|
|
1227
|
+
for (const part of signatureHeader.split(",")) {
|
|
1228
|
+
const eq = part.indexOf("=");
|
|
1229
|
+
if (eq === -1) continue;
|
|
1230
|
+
const k = part.slice(0, eq).trim();
|
|
1231
|
+
const v = part.slice(eq + 1).trim();
|
|
1232
|
+
if (k === "t") t = v;
|
|
1233
|
+
else if (k === "v1") v1s.push(v.toLowerCase());
|
|
1234
|
+
}
|
|
1235
|
+
if (!t || !/^\d+$/.test(t) || v1s.length === 0) return false;
|
|
1236
|
+
const tolerance = opts.toleranceSeconds ?? 300;
|
|
1237
|
+
const now = opts.nowSeconds ?? Math.floor(Date.now() / 1e3);
|
|
1238
|
+
if (Math.abs(now - Number(t)) > tolerance) return false;
|
|
1239
|
+
const { createHmac, timingSafeEqual } = nodeCrypto();
|
|
1240
|
+
const enc2 = new TextEncoder();
|
|
1241
|
+
const body = typeof rawBody === "string" ? enc2.encode(rawBody) : rawBody;
|
|
1242
|
+
const expected = createHmac("sha256", secret).update(enc2.encode(`${t}.`)).update(body).digest();
|
|
1243
|
+
return v1s.some((v1) => {
|
|
1244
|
+
if (!/^[0-9a-f]{64}$/.test(v1)) return false;
|
|
1245
|
+
return timingSafeEqual(hexToBytes(v1), expected);
|
|
1246
|
+
});
|
|
1247
|
+
}
|
|
1248
|
+
function nodeCrypto() {
|
|
1249
|
+
const proc = globalThis.process;
|
|
1250
|
+
const mod = proc?.getBuiltinModule?.("node:crypto");
|
|
1251
|
+
if (!mod) {
|
|
1252
|
+
throw new Error(
|
|
1253
|
+
"verifyResolveWebhook needs node:crypto (Node 20.16+/22.3+, Bun or Deno); run it server-side"
|
|
1254
|
+
);
|
|
1255
|
+
}
|
|
1256
|
+
return mod;
|
|
1257
|
+
}
|
|
1258
|
+
function hexToBytes(hex) {
|
|
1259
|
+
const out = new Uint8Array(hex.length / 2);
|
|
1260
|
+
for (let i = 0; i < out.length; i++) out[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
1261
|
+
return out;
|
|
1262
|
+
}
|
|
1223
1263
|
var RESOLVE_TERMINAL_STATUSES = /* @__PURE__ */ new Set([
|
|
1224
1264
|
"resolved",
|
|
1225
1265
|
"failed",
|
|
@@ -2187,6 +2227,6 @@ function allKeys(obj) {
|
|
|
2187
2227
|
}
|
|
2188
2228
|
var index_default = Codai;
|
|
2189
2229
|
|
|
2190
|
-
export { Account, AgentRuns, Agents, Audio, Chat, ChatCompletions, Codai, CodaiError, Devices, Embeddings, EnvironmentMembers, EnvironmentPorts, EnvironmentSecrets, EnvironmentTasks, Environments, Feedback, Health, Hosts, HttpClient, Messages, Models, Notifications, OPERATION_METHODS, OrgMembers, Orgs, PhoneModels, Projects, RESOLVE_OPERATION_METHODS, RESOLVE_TERMINAL_STATUSES, Receipts, Resolve, ResolveError, ResolveInsufficientFundsError, Responses, STREAMING_OPERATIONS, SessionControls, SessionEvents, SessionLease, SessionShares, Sessions, Tasks, Tokens, Tools, Triggers, index_default as default, extensionHeaders, frameJson, mergeToolCall, readSse };
|
|
2230
|
+
export { Account, AgentRuns, Agents, Audio, Chat, ChatCompletions, Codai, CodaiError, Devices, Embeddings, EnvironmentMembers, EnvironmentPorts, EnvironmentSecrets, EnvironmentTasks, Environments, Feedback, Health, Hosts, HttpClient, Messages, Models, Notifications, OPERATION_METHODS, OrgMembers, Orgs, PhoneModels, Projects, RESOLVE_OPERATION_METHODS, RESOLVE_TERMINAL_STATUSES, Receipts, Resolve, ResolveError, ResolveInsufficientFundsError, Responses, STREAMING_OPERATIONS, SessionControls, SessionEvents, SessionLease, SessionShares, Sessions, Tasks, Tokens, Tools, Triggers, index_default as default, extensionHeaders, frameJson, mergeToolCall, readSse, verifyResolveWebhook };
|
|
2191
2231
|
//# sourceMappingURL=index.js.map
|
|
2192
2232
|
//# sourceMappingURL=index.js.map
|