palbase 0.62.0 → 0.64.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/ai/index.js +2 -2
- package/dist/backend/engine.js +2 -2
- package/dist/backend/env.js +1 -1
- package/dist/backend/index.js +3 -3
- package/dist/backend/stack.js +1 -1
- package/dist/backend/test.js +2 -2
- package/dist/chunks/{WJXZYXL6.js → 2FPPZ3A3.js} +2 -2
- package/dist/chunks/{S3YODXG5.js → 47YRZOKH.js} +2 -2
- package/dist/chunks/{PYL5JMWN.js → 73CKSYD7.js} +2 -2
- package/dist/chunks/{7J3HTVFX.js → 7WLAMFND.js} +2 -2
- package/dist/chunks/{LXAR6WWQ.js → AUCNHNPD.js} +2 -2
- package/dist/chunks/{SCUAN3L3.js → B6FEEB5R.js} +1 -1
- package/dist/chunks/{HXKBPLL2.js → D2Z5R7ZP.js} +1 -1
- package/dist/chunks/{IPAVEV75.js → HWDOVTN4.js} +2 -2
- package/dist/chunks/K4E27V7K.js +2 -0
- package/dist/chunks/{ECVNYWWT.js → KRYGPGVB.js} +2 -2
- package/dist/chunks/{P3QFV5EA.js → MUHCCKSS.js} +1 -1
- package/dist/chunks/{PQ627JVJ.js → MVHF5I2L.js} +2 -2
- package/dist/chunks/QDAQJXBR.js +18 -0
- package/dist/chunks/{WBKZLJ66.js → RCV4YOM6.js} +1 -1
- package/dist/chunks/{ZVDYTR3S.js → SKPSBDXT.js} +2 -2
- package/dist/chunks/{EEGVWOER.js → TNY6UGJZ.js} +2 -2
- package/dist/chunks/{LDLYOQAV.js → TTDCC4FL.js} +1 -1
- package/dist/chunks/{LUVYYNMK.js → U6S2T2FE.js} +2 -2
- package/dist/chunks/{M6KUVE4B.js → UAD4XPIB.js} +2 -2
- package/dist/chunks/{3KEWWFIC.js → XDGXREXS.js} +1 -1
- package/dist/chunks/{KUSZFTJK.js → XIHO4HVO.js} +1 -1
- package/dist/chunks/{USL5YRDX.js → ZO7BWXF3.js} +2 -2
- package/dist/chunks/{WEMTQPSH.js → ZZLCBUNM.js} +2 -2
- package/dist/cli.js +10802 -349
- package/dist/cloud/index.js +2 -2
- package/dist/refuse/ai.js +1 -1
- package/dist/refuse/backend.js +1 -1
- package/dist/refuse/cloud.js +1 -1
- package/dist/refuse/server.js +1 -1
- package/dist/server/index.js +2 -2
- package/dist/server/testing.js +2 -2
- package/dist/web/index.js +2 -2
- package/dist/web/message.js +2 -2
- package/dist/web/palbe.js +2 -2
- package/dist/web/paywall.js +2 -2
- package/dist/web/push-sw.js +1 -1
- package/dist/web/ssr.js +2 -2
- package/dist/web/vite.js +2 -2
- package/package.json +2 -2
- package/types/ai/src/chats.d.ts +20 -2
- package/types/ai/src/index.d.ts +2 -2
- package/types/ai/src/pools.d.ts +158 -9
- package/types/ai/src/tools.d.ts +83 -2
- package/types/cloud/src/generated/project.d.ts +1 -1
- package/types/cloud/src/generated/studio.d.ts +67 -8
- package/types/internal/src/modules/ai.d.ts +306 -11
- package/types/internal/src/modules/analytics.d.ts +7 -7
- package/types/internal/src/modules/auth.d.ts +41 -30
- package/types/internal/src/modules/events.d.ts +2 -2
- package/types/internal/src/modules/notify.d.ts +1 -1
- package/types/internal/src/modules/purchases.d.ts +19 -7
- package/types/internal/src/modules/stores.d.ts +3 -3
- package/types/web/src/screen/resolve.d.ts +2 -1
- package/dist/chunks/DCWPUWZE.js +0 -18
- package/dist/chunks/ZWSYEBRO.js +0 -2
|
@@ -5162,8 +5162,7 @@ export declare function client(t: Transport): {
|
|
|
5162
5162
|
* Enroll email OTP
|
|
5163
5163
|
*
|
|
5164
5164
|
* Enroll email OTP as a second factor for the authenticated user.
|
|
5165
|
-
* The user's email must already be verified.
|
|
5166
|
-
*
|
|
5165
|
+
* The user's email must already be verified. An account whose email address is not confirmed is refused (403 email_unconfirmed): no sign-in method is added to it until its address is confirmed, as its owner, proving the address, takes the account as it was opened.
|
|
5167
5166
|
*/
|
|
5168
5167
|
mfaEmailEnroll(input?: {
|
|
5169
5168
|
signal?: AbortSignal;
|
|
@@ -5186,8 +5185,7 @@ export declare function client(t: Transport): {
|
|
|
5186
5185
|
* returns the secret, otpauth URL, QR code (base64 PNG), and a
|
|
5187
5186
|
* one-time set of recovery codes (only on the user's first MFA
|
|
5188
5187
|
* enrollment). `type=email` marks email OTP as enrolled and
|
|
5189
|
-
* returns `{status: enrolled}` — email must already be verified.
|
|
5190
|
-
*
|
|
5188
|
+
* returns `{status: enrolled}` — email must already be verified. An account whose email address is not confirmed is refused (403 email_unconfirmed): no sign-in method is added to it until its address is confirmed, as its owner, proving the address, takes the account as it was opened.
|
|
5191
5189
|
*/
|
|
5192
5190
|
mfaEnroll(input: {
|
|
5193
5191
|
body: MFAEnrollRequest; /** Stops the call: the request in flight, a wait before a retry, a proof-of-work being solved. */
|
|
@@ -5239,8 +5237,7 @@ export declare function client(t: Transport): {
|
|
|
5239
5237
|
*
|
|
5240
5238
|
* Regenerate recovery codes — invalidates all previously issued
|
|
5241
5239
|
* codes and returns a fresh batch. The new codes are returned only
|
|
5242
|
-
* in this response and cannot be retrieved later.
|
|
5243
|
-
*
|
|
5240
|
+
* in this response and cannot be retrieved later. An account whose email address is not confirmed is refused (403 email_unconfirmed): no sign-in method is added to it until its address is confirmed, as its owner, proving the address, takes the account as it was opened.
|
|
5244
5241
|
*/
|
|
5245
5242
|
mfaRegenerateRecoveryCodes(input?: {
|
|
5246
5243
|
signal?: AbortSignal;
|
|
@@ -5265,8 +5262,7 @@ export declare function client(t: Transport): {
|
|
|
5265
5262
|
* format and may be subject to country allow/deny lists. NIST
|
|
5266
5263
|
* SP 800-63B treats SMS OTP as a "restricted authenticator" — a
|
|
5267
5264
|
* warning string is included in the response for surfacing to the
|
|
5268
|
-
* user.
|
|
5269
|
-
*
|
|
5265
|
+
* user. An account whose email address is not confirmed is refused (403 email_unconfirmed): no sign-in method is added to it until its address is confirmed, as its owner, proving the address, takes the account as it was opened.
|
|
5270
5266
|
*/
|
|
5271
5267
|
mfaSmsEnroll(input: {
|
|
5272
5268
|
body: MFASMSEnrollRequest; /** Stops the call: the request in flight, a wait before a retry, a proof-of-work being solved. */
|
|
@@ -5276,8 +5272,7 @@ export declare function client(t: Transport): {
|
|
|
5276
5272
|
* Verify SMS enrollment
|
|
5277
5273
|
*
|
|
5278
5274
|
* Verify a pending SMS enrollment by submitting the OTP code
|
|
5279
|
-
* received via SMS.
|
|
5280
|
-
*
|
|
5275
|
+
* received via SMS. An account whose email address is not confirmed is refused (403 email_unconfirmed): no sign-in method is added to it until its address is confirmed, as its owner, proving the address, takes the account as it was opened.
|
|
5281
5276
|
*/
|
|
5282
5277
|
mfaSmsVerifyEnrollment(input: {
|
|
5283
5278
|
body: MFASMSVerifyRequest; /** Stops the call: the request in flight, a wait before a retry, a proof-of-work being solved. */
|
|
@@ -5288,8 +5283,7 @@ export declare function client(t: Transport): {
|
|
|
5288
5283
|
*
|
|
5289
5284
|
* Verify a pending TOTP enrollment by submitting the first code
|
|
5290
5285
|
* from the authenticator app. On success the enrollment is marked
|
|
5291
|
-
* verified and may be used as a second factor on future logins.
|
|
5292
|
-
*
|
|
5286
|
+
* verified and may be used as a second factor on future logins. An account whose email address is not confirmed is refused (403 email_unconfirmed): no sign-in method is added to it until its address is confirmed, as its owner, proving the address, takes the account as it was opened.
|
|
5293
5287
|
*/
|
|
5294
5288
|
mfaVerifyEnrollment(input: {
|
|
5295
5289
|
body: MFAVerifyEnrollmentRequest; /** Stops the call: the request in flight, a wait before a retry, a proof-of-work being solved. */
|
|
@@ -5395,7 +5389,7 @@ export declare function client(t: Transport): {
|
|
|
5395
5389
|
/**
|
|
5396
5390
|
* Begin a social sign-in
|
|
5397
5391
|
*
|
|
5398
|
-
* Starts a sign-in with a provider: answers the provider URL to open (browser) or the parameters for the native SDK. With a session, the identity is linked to the signed-in user instead. A guest's session links at any age, and the guest becomes an account with the provider under the same id. It takes the provider's address only when the provider hosts it (then confirmed); when another account holds that address, completing answers 409 `email_exists` and nothing changes. A session opened as a guest that has since become an account is asked for a sign-in, as any credential change asks.
|
|
5392
|
+
* Starts a sign-in with a provider: answers the provider URL to open (browser) or the parameters for the native SDK. With a session, the identity is linked to the signed-in user instead. A guest's session links at any age, and the guest becomes an account with the provider under the same id. It takes the provider's address only when the provider hosts it (then confirmed); when another account holds that address, completing answers 409 `email_exists` and nothing changes. A session opened as a guest that has since become an account is asked for a sign-in, as any credential change asks. Linking a provider to the signed-in account is refused the same way while its email address is not confirmed (403 email_unconfirmed).
|
|
5399
5393
|
*/
|
|
5400
5394
|
socialBegin(input: {
|
|
5401
5395
|
body: SocialBeginRequest; /** Stops the call: the request in flight, a wait before a retry, a proof-of-work being solved. */
|
|
@@ -5568,7 +5562,7 @@ export declare function client(t: Transport): {
|
|
|
5568
5562
|
/**
|
|
5569
5563
|
* Add a first password to the signed-in account
|
|
5570
5564
|
*
|
|
5571
|
-
* Gives an account that has no password (social, passkey or phone sign-in) its first one. The user must have signed in within the last 5 minutes (403 `reauthentication_required` otherwise). An account that already has a password gets 409 `password_already_set` and should use `POST /auth/password/change`. The password is checked against the project's policy and known breaches; 503 means a check or the server's hashing capacity is momentarily unavailable and the same request can be retried (see `Retry-After`). A guest gets 409 `anonymous_user`: it takes a password with an address, by `POST /auth/anonymous/convert`.
|
|
5565
|
+
* Gives an account that has no password (social, passkey or phone sign-in) its first one. The user must have signed in within the last 5 minutes (403 `reauthentication_required` otherwise). An account that already has a password gets 409 `password_already_set` and should use `POST /auth/password/change`. The password is checked against the project's policy and known breaches; 503 means a check or the server's hashing capacity is momentarily unavailable and the same request can be retried (see `Retry-After`). A guest gets 409 `anonymous_user`: it takes a password with an address, by `POST /auth/anonymous/convert`. An account whose email address is not confirmed is refused (403 email_unconfirmed): no sign-in method is added to it until its address is confirmed, as its owner, proving the address, takes the account as it was opened.
|
|
5572
5566
|
*/
|
|
5573
5567
|
setPassword(input: {
|
|
5574
5568
|
body: PasswordSetRequest; /** Stops the call: the request in flight, a wait before a retry, a proof-of-work being solved. */
|
|
@@ -5612,8 +5606,7 @@ export declare function client(t: Transport): {
|
|
|
5612
5606
|
*
|
|
5613
5607
|
* Add a trusted recovery contact. A verification email is sent to
|
|
5614
5608
|
* the contact; they must confirm before being used for recovery
|
|
5615
|
-
* approvals. Maximum 5 contacts per user.
|
|
5616
|
-
*
|
|
5609
|
+
* approvals. Maximum 5 contacts per user. An account whose email address is not confirmed is refused (403 email_unconfirmed): no sign-in method is added to it until its address is confirmed, as its owner, proving the address, takes the account as it was opened.
|
|
5617
5610
|
*/
|
|
5618
5611
|
addRecoveryContact(input: {
|
|
5619
5612
|
body: AddContactRequest; /** Stops the call: the request in flight, a wait before a retry, a proof-of-work being solved. */
|
|
@@ -5804,10 +5797,13 @@ export declare function client(t: Transport): {
|
|
|
5804
5797
|
/**
|
|
5805
5798
|
* Exchange custom token for session
|
|
5806
5799
|
*
|
|
5807
|
-
* Trades a server-minted custom
|
|
5808
|
-
* token) for a regular session — access + refresh tokens.
|
|
5809
|
-
*
|
|
5810
|
-
*
|
|
5800
|
+
* Trades a server-minted custom token (Firebase-style backend-issued
|
|
5801
|
+
* token) for a regular session — access + refresh tokens. Only a token
|
|
5802
|
+
* minted by `/admin/token/custom`, within its TTL, is taken, and once:
|
|
5803
|
+
* it alone carries the custom token's audience and no session. Any other
|
|
5804
|
+
* token the project signs — a session's access token, signed out or not,
|
|
5805
|
+
* an impersonation's — is refused with 401 `invalid_token`, as is a custom
|
|
5806
|
+
* token presented again (401 `token_used`).
|
|
5811
5807
|
*
|
|
5812
5808
|
*/
|
|
5813
5809
|
exchangeCustomToken(input: {
|
|
@@ -5910,8 +5906,7 @@ export declare function client(t: Transport): {
|
|
|
5910
5906
|
*
|
|
5911
5907
|
* Register the current device as trusted. Returns a long-lived
|
|
5912
5908
|
* token the SDK stores to skip MFA on future logins. The plain
|
|
5913
|
-
* token is shown once.
|
|
5914
|
-
*
|
|
5909
|
+
* token is shown once. An account whose email address is not confirmed is refused (403 email_unconfirmed): no sign-in method is added to it until its address is confirmed, as its owner, proving the address, takes the account as it was opened.
|
|
5915
5910
|
*/
|
|
5916
5911
|
registerTrustedDevice(input: {
|
|
5917
5912
|
body: RegisterTrustedDeviceRequest; /** Stops the call: the request in flight, a wait before a retry, a proof-of-work being solved. */
|
|
@@ -6055,8 +6050,7 @@ export declare function client(t: Transport): {
|
|
|
6055
6050
|
*
|
|
6056
6051
|
* Start registering a recovery passkey for the authenticated user.
|
|
6057
6052
|
* Recovery credentials can only be used via
|
|
6058
|
-
* `/auth/webauthn/recovery/*`, never for normal login.
|
|
6059
|
-
*
|
|
6053
|
+
* `/auth/webauthn/recovery/*`, never for normal login. An account whose email address is not confirmed is refused (403 email_unconfirmed): no sign-in method is added to it until its address is confirmed, as its owner, proving the address, takes the account as it was opened.
|
|
6060
6054
|
*/
|
|
6061
6055
|
webauthnRecoveryRegisterBegin(input?: {
|
|
6062
6056
|
body?: WebAuthnRegisterRecoveryRequest; /** Stops the call: the request in flight, a wait before a retry, a proof-of-work being solved. */
|
|
@@ -6066,8 +6060,7 @@ export declare function client(t: Transport): {
|
|
|
6066
6060
|
* Complete recovery passkey registration
|
|
6067
6061
|
*
|
|
6068
6062
|
* Complete registration of a recovery passkey for the
|
|
6069
|
-
* authenticated user.
|
|
6070
|
-
*
|
|
6063
|
+
* authenticated user. An account whose email address is not confirmed is refused (403 email_unconfirmed): no sign-in method is added to it until its address is confirmed, as its owner, proving the address, takes the account as it was opened.
|
|
6071
6064
|
*/
|
|
6072
6065
|
webauthnRecoveryRegisterFinish(input: {
|
|
6073
6066
|
body: WebAuthnAttestationResponse; /** Stops the call: the request in flight, a wait before a retry, a proof-of-work being solved. */
|
|
@@ -6081,8 +6074,7 @@ export declare function client(t: Transport): {
|
|
|
6081
6074
|
* and/or `is_recovery` to mark the credential as a recovery
|
|
6082
6075
|
* passkey.
|
|
6083
6076
|
*
|
|
6084
|
-
* A guest becomes an account with the passkey it adds (`is_anonymous` false from the next refresh); it must send `user_name`, having no address to label the passkey with, and is not asked for a recent sign-in.
|
|
6085
|
-
*
|
|
6077
|
+
* A guest becomes an account with the passkey it adds (`is_anonymous` false from the next refresh); it must send `user_name`, having no address to label the passkey with, and is not asked for a recent sign-in. An account whose email address is not confirmed is refused (403 email_unconfirmed): no sign-in method is added to it until its address is confirmed, as its owner, proving the address, takes the account as it was opened.
|
|
6086
6078
|
*/
|
|
6087
6079
|
webauthnRegisterBegin(input?: {
|
|
6088
6080
|
body?: WebAuthnRegisterBeginRequest; /** Stops the call: the request in flight, a wait before a retry, a proof-of-work being solved. */
|
|
@@ -6094,8 +6086,7 @@ export declare function client(t: Transport): {
|
|
|
6094
6086
|
* Complete registration of an additional WebAuthn credential for
|
|
6095
6087
|
* the authenticated user.
|
|
6096
6088
|
*
|
|
6097
|
-
* A guest's account is converted with it (`user.converted`), under the same id.
|
|
6098
|
-
*
|
|
6089
|
+
* A guest's account is converted with it (`user.converted`), under the same id. An account whose email address is not confirmed is refused (403 email_unconfirmed): no sign-in method is added to it until its address is confirmed, as its owner, proving the address, takes the account as it was opened.
|
|
6099
6090
|
*/
|
|
6100
6091
|
webauthnRegisterFinish(input: {
|
|
6101
6092
|
body: WebAuthnAttestationResponse; /** Stops the call: the request in flight, a wait before a retry, a proof-of-work being solved. */
|
|
@@ -6406,5 +6397,25 @@ export declare function client(t: Transport): {
|
|
|
6406
6397
|
body: HostedAcceptInvitationForm; /** Stops the call: the request in flight, a wait before a retry, a proof-of-work being solved. */
|
|
6407
6398
|
signal?: AbortSignal;
|
|
6408
6399
|
}): Promise<Reply<200, Response>>;
|
|
6400
|
+
/**
|
|
6401
|
+
* Show the not-me page
|
|
6402
|
+
*
|
|
6403
|
+
* A sign-up confirmation's "this was not me" link: a page that offers to delete the account opened with the reader's address while that address is unconfirmed. Opening it changes nothing.
|
|
6404
|
+
*/
|
|
6405
|
+
hostedNotMePage(input?: {
|
|
6406
|
+
query?: {
|
|
6407
|
+
token?: string;
|
|
6408
|
+
}; /** Stops the call: the request in flight, a wait before a retry, a proof-of-work being solved. */
|
|
6409
|
+
signal?: AbortSignal;
|
|
6410
|
+
}): Promise<Reply<200, Response>>;
|
|
6411
|
+
/**
|
|
6412
|
+
* Delete an unconfirmed account from the not-me page
|
|
6413
|
+
*
|
|
6414
|
+
* The page's form: deletes the account the token names, with everything that belongs to it, while its address is unconfirmed (an account deletion, user.deleted). Once the address is confirmed it deletes nothing (409). Accepted only from the page itself (Origin).
|
|
6415
|
+
*/
|
|
6416
|
+
hostedNotMeSubmit(input: {
|
|
6417
|
+
body: HostedVerifyEmailForm; /** Stops the call: the request in flight, a wait before a retry, a proof-of-work being solved. */
|
|
6418
|
+
signal?: AbortSignal;
|
|
6419
|
+
}): Promise<Reply<200, Response>>;
|
|
6409
6420
|
};
|
|
6410
6421
|
export type Client = ReturnType<typeof client>;
|
|
@@ -16,11 +16,11 @@ export interface PlatformEvents extends AiEvents, AnalyticsEvents, AuthEvents, C
|
|
|
16
16
|
/** A platform event's type: one a module's contract declares. */
|
|
17
17
|
export type EventType = keyof PlatformEvents;
|
|
18
18
|
/** Every platform event's type, as the contracts declare them. */
|
|
19
|
-
export declare const EVENT_TYPES: readonly ["ai.goal.updated", "ai.response.completed", "ai.response.failed", "ai.response.started", "ai.voice.closed", "ai.voice.delegated", "ai.voice.started", "ai.workspace.conflict", "ai.workspace.published", "ai.workspace.pushed", "audience.entered", "audience.exited", "calls.call.ended", "calls.call.started", "calls.participant.joined", "calls.participant.left", "consent.changed", "device.revoked", "file.deleted", "file.moved", "file.uploaded", "flag.changed", "flag.override_changed", "journey.converted", "journey.ended", "journey.entered", "journey.event", "journey.step", "messaging.conversation.created", "messaging.conversation.deleted", "messaging.conversation.read", "messaging.message.created", "messaging.report.created", "notification.action", "notification.bounced", "notification.complained", "notification.delivered", "notification.dismissed", "notification.expired", "notification.failed", "notification.not_shown", "notification.opened", "notification.push_failing", "notification.read", "notification.received", "notification.rejected", "notification.sent", "notification.shared_paused", "notification.unconfirmed", "notification.undelivered", "notification.uninstalled", "purchases.catalog.applied", "purchases.catalog.changed", "purchases.coupon.redeemed", "purchases.credits.depleted", "purchases.credits.low", "purchases.customer.changed", "purchases.customer.erased", "purchases.customer.merged", "purchases.entitlement.changed", "purchases.offer.redeemed", "purchases.ownership.transferred", "purchases.paywall.published", "purchases.purchase.completed", "purchases.quota.exhausted", "purchases.quota.threshold", "purchases.refund.changed", "purchases.store.changed", "purchases.subscription.changed", "session.ended", "stores.action.changed", "stores.app.changed", "stores.apple.changed", "stores.apple.key.made", "stores.apple.key.revoked", "stores.apple.session.changed", "stores.apple.session.ended", "stores.apple.session.expired", "stores.beta_review.changed", "stores.build.changed", "stores.delivery.changed", "stores.delivery.requested", "stores.device.changed", "stores.feedback.received", "stores.google.changed", "stores.group.changed", "stores.invitation.changed", "stores.package.changed", "stores.play_release.changed", "stores.product.changed", "stores.review.message", "stores.version.changed", "stores.version.reviewed", "stores.vitals.changed", "stores.webhook.changed", "user.converted", "user.deleted", "user.locale_changed", "user.password_changed", "user.permissions_changed"];
|
|
19
|
+
export declare const EVENT_TYPES: readonly ["ai.goal.updated", "ai.response.completed", "ai.response.failed", "ai.response.started", "ai.secret_host_requested", "ai.voice.closed", "ai.voice.delegated", "ai.voice.started", "ai.workspace.conflict", "ai.workspace.published", "ai.workspace.pushed", "audience.entered", "audience.exited", "calls.call.ended", "calls.call.started", "calls.participant.joined", "calls.participant.left", "consent.changed", "device.revoked", "file.deleted", "file.moved", "file.uploaded", "flag.changed", "flag.override_changed", "journey.converted", "journey.ended", "journey.entered", "journey.event", "journey.step", "messaging.conversation.created", "messaging.conversation.deleted", "messaging.conversation.read", "messaging.message.created", "messaging.report.created", "notification.action", "notification.bounced", "notification.complained", "notification.delivered", "notification.dismissed", "notification.expired", "notification.failed", "notification.not_shown", "notification.opened", "notification.push_failing", "notification.read", "notification.received", "notification.rejected", "notification.sent", "notification.shared_paused", "notification.unconfirmed", "notification.undelivered", "notification.uninstalled", "purchases.catalog.applied", "purchases.catalog.changed", "purchases.coupon.redeemed", "purchases.credits.depleted", "purchases.credits.low", "purchases.customer.changed", "purchases.customer.erased", "purchases.customer.merged", "purchases.entitlement.changed", "purchases.offer.redeemed", "purchases.ownership.transferred", "purchases.paywall.published", "purchases.purchase.completed", "purchases.quota.exhausted", "purchases.quota.threshold", "purchases.refund.changed", "purchases.store.changed", "purchases.subscription.changed", "session.ended", "stores.action.changed", "stores.app.changed", "stores.apple.changed", "stores.apple.key.made", "stores.apple.key.revoked", "stores.apple.session.changed", "stores.apple.session.ended", "stores.apple.session.expired", "stores.beta_review.changed", "stores.build.changed", "stores.delivery.changed", "stores.delivery.requested", "stores.device.changed", "stores.feedback.received", "stores.google.changed", "stores.group.changed", "stores.invitation.changed", "stores.package.changed", "stores.play_release.changed", "stores.product.changed", "stores.review.message", "stores.version.changed", "stores.version.reviewed", "stores.vitals.changed", "stores.webhook.changed", "user.converted", "user.deleted", "user.locale_changed", "user.password_changed", "user.permissions_changed"];
|
|
20
20
|
/**
|
|
21
21
|
* A platform event as delivered: one member per type the contracts declare,
|
|
22
22
|
* its data that type's payload, so a switch on its type narrows it. An
|
|
23
23
|
* event of a type none of them declares (one a newer platform sends) is no
|
|
24
24
|
* member: at run time it reaches the switch's default, which takes it.
|
|
25
25
|
*/
|
|
26
|
-
export type PalbaseEvent = WebhookEvent<PlatformEvents["ai.goal.updated"], "ai.goal.updated"> | WebhookEvent<PlatformEvents["ai.response.completed"], "ai.response.completed"> | WebhookEvent<PlatformEvents["ai.response.failed"], "ai.response.failed"> | WebhookEvent<PlatformEvents["ai.response.started"], "ai.response.started"> | WebhookEvent<PlatformEvents["ai.voice.closed"], "ai.voice.closed"> | WebhookEvent<PlatformEvents["ai.voice.delegated"], "ai.voice.delegated"> | WebhookEvent<PlatformEvents["ai.voice.started"], "ai.voice.started"> | WebhookEvent<PlatformEvents["ai.workspace.conflict"], "ai.workspace.conflict"> | WebhookEvent<PlatformEvents["ai.workspace.published"], "ai.workspace.published"> | WebhookEvent<PlatformEvents["ai.workspace.pushed"], "ai.workspace.pushed"> | WebhookEvent<PlatformEvents["audience.entered"], "audience.entered"> | WebhookEvent<PlatformEvents["audience.exited"], "audience.exited"> | WebhookEvent<PlatformEvents["calls.call.ended"], "calls.call.ended"> | WebhookEvent<PlatformEvents["calls.call.started"], "calls.call.started"> | WebhookEvent<PlatformEvents["calls.participant.joined"], "calls.participant.joined"> | WebhookEvent<PlatformEvents["calls.participant.left"], "calls.participant.left"> | WebhookEvent<PlatformEvents["consent.changed"], "consent.changed"> | WebhookEvent<PlatformEvents["device.revoked"], "device.revoked"> | WebhookEvent<PlatformEvents["file.deleted"], "file.deleted"> | WebhookEvent<PlatformEvents["file.moved"], "file.moved"> | WebhookEvent<PlatformEvents["file.uploaded"], "file.uploaded"> | WebhookEvent<PlatformEvents["flag.changed"], "flag.changed"> | WebhookEvent<PlatformEvents["flag.override_changed"], "flag.override_changed"> | WebhookEvent<PlatformEvents["journey.converted"], "journey.converted"> | WebhookEvent<PlatformEvents["journey.ended"], "journey.ended"> | WebhookEvent<PlatformEvents["journey.entered"], "journey.entered"> | WebhookEvent<PlatformEvents["journey.event"], "journey.event"> | WebhookEvent<PlatformEvents["journey.step"], "journey.step"> | WebhookEvent<PlatformEvents["messaging.conversation.created"], "messaging.conversation.created"> | WebhookEvent<PlatformEvents["messaging.conversation.deleted"], "messaging.conversation.deleted"> | WebhookEvent<PlatformEvents["messaging.conversation.read"], "messaging.conversation.read"> | WebhookEvent<PlatformEvents["messaging.message.created"], "messaging.message.created"> | WebhookEvent<PlatformEvents["messaging.report.created"], "messaging.report.created"> | WebhookEvent<PlatformEvents["notification.action"], "notification.action"> | WebhookEvent<PlatformEvents["notification.bounced"], "notification.bounced"> | WebhookEvent<PlatformEvents["notification.complained"], "notification.complained"> | WebhookEvent<PlatformEvents["notification.delivered"], "notification.delivered"> | WebhookEvent<PlatformEvents["notification.dismissed"], "notification.dismissed"> | WebhookEvent<PlatformEvents["notification.expired"], "notification.expired"> | WebhookEvent<PlatformEvents["notification.failed"], "notification.failed"> | WebhookEvent<PlatformEvents["notification.not_shown"], "notification.not_shown"> | WebhookEvent<PlatformEvents["notification.opened"], "notification.opened"> | WebhookEvent<PlatformEvents["notification.push_failing"], "notification.push_failing"> | WebhookEvent<PlatformEvents["notification.read"], "notification.read"> | WebhookEvent<PlatformEvents["notification.received"], "notification.received"> | WebhookEvent<PlatformEvents["notification.rejected"], "notification.rejected"> | WebhookEvent<PlatformEvents["notification.sent"], "notification.sent"> | WebhookEvent<PlatformEvents["notification.shared_paused"], "notification.shared_paused"> | WebhookEvent<PlatformEvents["notification.unconfirmed"], "notification.unconfirmed"> | WebhookEvent<PlatformEvents["notification.undelivered"], "notification.undelivered"> | WebhookEvent<PlatformEvents["notification.uninstalled"], "notification.uninstalled"> | WebhookEvent<PlatformEvents["purchases.catalog.applied"], "purchases.catalog.applied"> | WebhookEvent<PlatformEvents["purchases.catalog.changed"], "purchases.catalog.changed"> | WebhookEvent<PlatformEvents["purchases.coupon.redeemed"], "purchases.coupon.redeemed"> | WebhookEvent<PlatformEvents["purchases.credits.depleted"], "purchases.credits.depleted"> | WebhookEvent<PlatformEvents["purchases.credits.low"], "purchases.credits.low"> | WebhookEvent<PlatformEvents["purchases.customer.changed"], "purchases.customer.changed"> | WebhookEvent<PlatformEvents["purchases.customer.erased"], "purchases.customer.erased"> | WebhookEvent<PlatformEvents["purchases.customer.merged"], "purchases.customer.merged"> | WebhookEvent<PlatformEvents["purchases.entitlement.changed"], "purchases.entitlement.changed"> | WebhookEvent<PlatformEvents["purchases.offer.redeemed"], "purchases.offer.redeemed"> | WebhookEvent<PlatformEvents["purchases.ownership.transferred"], "purchases.ownership.transferred"> | WebhookEvent<PlatformEvents["purchases.paywall.published"], "purchases.paywall.published"> | WebhookEvent<PlatformEvents["purchases.purchase.completed"], "purchases.purchase.completed"> | WebhookEvent<PlatformEvents["purchases.quota.exhausted"], "purchases.quota.exhausted"> | WebhookEvent<PlatformEvents["purchases.quota.threshold"], "purchases.quota.threshold"> | WebhookEvent<PlatformEvents["purchases.refund.changed"], "purchases.refund.changed"> | WebhookEvent<PlatformEvents["purchases.store.changed"], "purchases.store.changed"> | WebhookEvent<PlatformEvents["purchases.subscription.changed"], "purchases.subscription.changed"> | WebhookEvent<PlatformEvents["session.ended"], "session.ended"> | WebhookEvent<PlatformEvents["stores.action.changed"], "stores.action.changed"> | WebhookEvent<PlatformEvents["stores.app.changed"], "stores.app.changed"> | WebhookEvent<PlatformEvents["stores.apple.changed"], "stores.apple.changed"> | WebhookEvent<PlatformEvents["stores.apple.key.made"], "stores.apple.key.made"> | WebhookEvent<PlatformEvents["stores.apple.key.revoked"], "stores.apple.key.revoked"> | WebhookEvent<PlatformEvents["stores.apple.session.changed"], "stores.apple.session.changed"> | WebhookEvent<PlatformEvents["stores.apple.session.ended"], "stores.apple.session.ended"> | WebhookEvent<PlatformEvents["stores.apple.session.expired"], "stores.apple.session.expired"> | WebhookEvent<PlatformEvents["stores.beta_review.changed"], "stores.beta_review.changed"> | WebhookEvent<PlatformEvents["stores.build.changed"], "stores.build.changed"> | WebhookEvent<PlatformEvents["stores.delivery.changed"], "stores.delivery.changed"> | WebhookEvent<PlatformEvents["stores.delivery.requested"], "stores.delivery.requested"> | WebhookEvent<PlatformEvents["stores.device.changed"], "stores.device.changed"> | WebhookEvent<PlatformEvents["stores.feedback.received"], "stores.feedback.received"> | WebhookEvent<PlatformEvents["stores.google.changed"], "stores.google.changed"> | WebhookEvent<PlatformEvents["stores.group.changed"], "stores.group.changed"> | WebhookEvent<PlatformEvents["stores.invitation.changed"], "stores.invitation.changed"> | WebhookEvent<PlatformEvents["stores.package.changed"], "stores.package.changed"> | WebhookEvent<PlatformEvents["stores.play_release.changed"], "stores.play_release.changed"> | WebhookEvent<PlatformEvents["stores.product.changed"], "stores.product.changed"> | WebhookEvent<PlatformEvents["stores.review.message"], "stores.review.message"> | WebhookEvent<PlatformEvents["stores.version.changed"], "stores.version.changed"> | WebhookEvent<PlatformEvents["stores.version.reviewed"], "stores.version.reviewed"> | WebhookEvent<PlatformEvents["stores.vitals.changed"], "stores.vitals.changed"> | WebhookEvent<PlatformEvents["stores.webhook.changed"], "stores.webhook.changed"> | WebhookEvent<PlatformEvents["user.converted"], "user.converted"> | WebhookEvent<PlatformEvents["user.deleted"], "user.deleted"> | WebhookEvent<PlatformEvents["user.locale_changed"], "user.locale_changed"> | WebhookEvent<PlatformEvents["user.password_changed"], "user.password_changed"> | WebhookEvent<PlatformEvents["user.permissions_changed"], "user.permissions_changed">;
|
|
26
|
+
export type PalbaseEvent = WebhookEvent<PlatformEvents["ai.goal.updated"], "ai.goal.updated"> | WebhookEvent<PlatformEvents["ai.response.completed"], "ai.response.completed"> | WebhookEvent<PlatformEvents["ai.response.failed"], "ai.response.failed"> | WebhookEvent<PlatformEvents["ai.response.started"], "ai.response.started"> | WebhookEvent<PlatformEvents["ai.secret_host_requested"], "ai.secret_host_requested"> | WebhookEvent<PlatformEvents["ai.voice.closed"], "ai.voice.closed"> | WebhookEvent<PlatformEvents["ai.voice.delegated"], "ai.voice.delegated"> | WebhookEvent<PlatformEvents["ai.voice.started"], "ai.voice.started"> | WebhookEvent<PlatformEvents["ai.workspace.conflict"], "ai.workspace.conflict"> | WebhookEvent<PlatformEvents["ai.workspace.published"], "ai.workspace.published"> | WebhookEvent<PlatformEvents["ai.workspace.pushed"], "ai.workspace.pushed"> | WebhookEvent<PlatformEvents["audience.entered"], "audience.entered"> | WebhookEvent<PlatformEvents["audience.exited"], "audience.exited"> | WebhookEvent<PlatformEvents["calls.call.ended"], "calls.call.ended"> | WebhookEvent<PlatformEvents["calls.call.started"], "calls.call.started"> | WebhookEvent<PlatformEvents["calls.participant.joined"], "calls.participant.joined"> | WebhookEvent<PlatformEvents["calls.participant.left"], "calls.participant.left"> | WebhookEvent<PlatformEvents["consent.changed"], "consent.changed"> | WebhookEvent<PlatformEvents["device.revoked"], "device.revoked"> | WebhookEvent<PlatformEvents["file.deleted"], "file.deleted"> | WebhookEvent<PlatformEvents["file.moved"], "file.moved"> | WebhookEvent<PlatformEvents["file.uploaded"], "file.uploaded"> | WebhookEvent<PlatformEvents["flag.changed"], "flag.changed"> | WebhookEvent<PlatformEvents["flag.override_changed"], "flag.override_changed"> | WebhookEvent<PlatformEvents["journey.converted"], "journey.converted"> | WebhookEvent<PlatformEvents["journey.ended"], "journey.ended"> | WebhookEvent<PlatformEvents["journey.entered"], "journey.entered"> | WebhookEvent<PlatformEvents["journey.event"], "journey.event"> | WebhookEvent<PlatformEvents["journey.step"], "journey.step"> | WebhookEvent<PlatformEvents["messaging.conversation.created"], "messaging.conversation.created"> | WebhookEvent<PlatformEvents["messaging.conversation.deleted"], "messaging.conversation.deleted"> | WebhookEvent<PlatformEvents["messaging.conversation.read"], "messaging.conversation.read"> | WebhookEvent<PlatformEvents["messaging.message.created"], "messaging.message.created"> | WebhookEvent<PlatformEvents["messaging.report.created"], "messaging.report.created"> | WebhookEvent<PlatformEvents["notification.action"], "notification.action"> | WebhookEvent<PlatformEvents["notification.bounced"], "notification.bounced"> | WebhookEvent<PlatformEvents["notification.complained"], "notification.complained"> | WebhookEvent<PlatformEvents["notification.delivered"], "notification.delivered"> | WebhookEvent<PlatformEvents["notification.dismissed"], "notification.dismissed"> | WebhookEvent<PlatformEvents["notification.expired"], "notification.expired"> | WebhookEvent<PlatformEvents["notification.failed"], "notification.failed"> | WebhookEvent<PlatformEvents["notification.not_shown"], "notification.not_shown"> | WebhookEvent<PlatformEvents["notification.opened"], "notification.opened"> | WebhookEvent<PlatformEvents["notification.push_failing"], "notification.push_failing"> | WebhookEvent<PlatformEvents["notification.read"], "notification.read"> | WebhookEvent<PlatformEvents["notification.received"], "notification.received"> | WebhookEvent<PlatformEvents["notification.rejected"], "notification.rejected"> | WebhookEvent<PlatformEvents["notification.sent"], "notification.sent"> | WebhookEvent<PlatformEvents["notification.shared_paused"], "notification.shared_paused"> | WebhookEvent<PlatformEvents["notification.unconfirmed"], "notification.unconfirmed"> | WebhookEvent<PlatformEvents["notification.undelivered"], "notification.undelivered"> | WebhookEvent<PlatformEvents["notification.uninstalled"], "notification.uninstalled"> | WebhookEvent<PlatformEvents["purchases.catalog.applied"], "purchases.catalog.applied"> | WebhookEvent<PlatformEvents["purchases.catalog.changed"], "purchases.catalog.changed"> | WebhookEvent<PlatformEvents["purchases.coupon.redeemed"], "purchases.coupon.redeemed"> | WebhookEvent<PlatformEvents["purchases.credits.depleted"], "purchases.credits.depleted"> | WebhookEvent<PlatformEvents["purchases.credits.low"], "purchases.credits.low"> | WebhookEvent<PlatformEvents["purchases.customer.changed"], "purchases.customer.changed"> | WebhookEvent<PlatformEvents["purchases.customer.erased"], "purchases.customer.erased"> | WebhookEvent<PlatformEvents["purchases.customer.merged"], "purchases.customer.merged"> | WebhookEvent<PlatformEvents["purchases.entitlement.changed"], "purchases.entitlement.changed"> | WebhookEvent<PlatformEvents["purchases.offer.redeemed"], "purchases.offer.redeemed"> | WebhookEvent<PlatformEvents["purchases.ownership.transferred"], "purchases.ownership.transferred"> | WebhookEvent<PlatformEvents["purchases.paywall.published"], "purchases.paywall.published"> | WebhookEvent<PlatformEvents["purchases.purchase.completed"], "purchases.purchase.completed"> | WebhookEvent<PlatformEvents["purchases.quota.exhausted"], "purchases.quota.exhausted"> | WebhookEvent<PlatformEvents["purchases.quota.threshold"], "purchases.quota.threshold"> | WebhookEvent<PlatformEvents["purchases.refund.changed"], "purchases.refund.changed"> | WebhookEvent<PlatformEvents["purchases.store.changed"], "purchases.store.changed"> | WebhookEvent<PlatformEvents["purchases.subscription.changed"], "purchases.subscription.changed"> | WebhookEvent<PlatformEvents["session.ended"], "session.ended"> | WebhookEvent<PlatformEvents["stores.action.changed"], "stores.action.changed"> | WebhookEvent<PlatformEvents["stores.app.changed"], "stores.app.changed"> | WebhookEvent<PlatformEvents["stores.apple.changed"], "stores.apple.changed"> | WebhookEvent<PlatformEvents["stores.apple.key.made"], "stores.apple.key.made"> | WebhookEvent<PlatformEvents["stores.apple.key.revoked"], "stores.apple.key.revoked"> | WebhookEvent<PlatformEvents["stores.apple.session.changed"], "stores.apple.session.changed"> | WebhookEvent<PlatformEvents["stores.apple.session.ended"], "stores.apple.session.ended"> | WebhookEvent<PlatformEvents["stores.apple.session.expired"], "stores.apple.session.expired"> | WebhookEvent<PlatformEvents["stores.beta_review.changed"], "stores.beta_review.changed"> | WebhookEvent<PlatformEvents["stores.build.changed"], "stores.build.changed"> | WebhookEvent<PlatformEvents["stores.delivery.changed"], "stores.delivery.changed"> | WebhookEvent<PlatformEvents["stores.delivery.requested"], "stores.delivery.requested"> | WebhookEvent<PlatformEvents["stores.device.changed"], "stores.device.changed"> | WebhookEvent<PlatformEvents["stores.feedback.received"], "stores.feedback.received"> | WebhookEvent<PlatformEvents["stores.google.changed"], "stores.google.changed"> | WebhookEvent<PlatformEvents["stores.group.changed"], "stores.group.changed"> | WebhookEvent<PlatformEvents["stores.invitation.changed"], "stores.invitation.changed"> | WebhookEvent<PlatformEvents["stores.package.changed"], "stores.package.changed"> | WebhookEvent<PlatformEvents["stores.play_release.changed"], "stores.play_release.changed"> | WebhookEvent<PlatformEvents["stores.product.changed"], "stores.product.changed"> | WebhookEvent<PlatformEvents["stores.review.message"], "stores.review.message"> | WebhookEvent<PlatformEvents["stores.version.changed"], "stores.version.changed"> | WebhookEvent<PlatformEvents["stores.version.reviewed"], "stores.version.reviewed"> | WebhookEvent<PlatformEvents["stores.vitals.changed"], "stores.vitals.changed"> | WebhookEvent<PlatformEvents["stores.webhook.changed"], "stores.webhook.changed"> | WebhookEvent<PlatformEvents["user.converted"], "user.converted"> | WebhookEvent<PlatformEvents["user.deleted"], "user.deleted"> | WebhookEvent<PlatformEvents["user.locale_changed"], "user.locale_changed"> | WebhookEvent<PlatformEvents["user.password_changed"], "user.password_changed"> | WebhookEvent<PlatformEvents["user.permissions_changed"], "user.permissions_changed">;
|
|
@@ -647,7 +647,7 @@ export type Channel = {
|
|
|
647
647
|
};
|
|
648
648
|
review?: AppReview;
|
|
649
649
|
/**
|
|
650
|
-
* Stripe's tax code for the product (the web's alone).
|
|
650
|
+
* Stripe's tax code for the product (the web's alone): what Stripe taxes it as, txcd_ and eight digits (txcd_10103000: SaaS for personal use; another is a problem, invalid_tax_code, and is not sent). Written on the product at Stripe; Managed Payments (settings' web_tax) needs one on every web product. Leaving it out later leaves Stripe's as it is.
|
|
651
651
|
*/
|
|
652
652
|
tax_code?: string;
|
|
653
653
|
/**
|
|
@@ -2563,7 +2563,7 @@ export type PaywallCondition = {
|
|
|
2563
2563
|
/**
|
|
2564
2564
|
* Platform.
|
|
2565
2565
|
*/
|
|
2566
|
-
platform?: ("ios" | "android" | "web")[];
|
|
2566
|
+
platform?: ("ios" | "android" | "web" | "macos")[];
|
|
2567
2567
|
/**
|
|
2568
2568
|
* Selected package.
|
|
2569
2569
|
*/
|
|
@@ -4164,7 +4164,7 @@ export type PreviewContext = {
|
|
|
4164
4164
|
*/
|
|
4165
4165
|
locale?: string;
|
|
4166
4166
|
/**
|
|
4167
|
-
* ios, android or
|
|
4167
|
+
* ios, android, web or macos (X-Platform).
|
|
4168
4168
|
*/
|
|
4169
4169
|
platform?: string;
|
|
4170
4170
|
/**
|
|
@@ -4535,7 +4535,7 @@ export type Revenue = {
|
|
|
4535
4535
|
/**
|
|
4536
4536
|
* One thing a rule asks of a viewer. `field` is what it reads, `op` how:
|
|
4537
4537
|
* - `country` (`in`, `not_in`; `values` ISO 3166-1 alpha-2, alpha-3 read as alpha-2): the store's country the app sends (X-Palbase-Storefront), else the country of the request's address.
|
|
4538
|
-
* - `platform` (`in`, `not_in`; `values` ios, android, web): X-Platform, else `?channel=`.
|
|
4538
|
+
* - `platform` (`in`, `not_in`; `values` ios, android, web, macos): X-Platform, else `?channel=`.
|
|
4539
4539
|
* - `app` (`in`, `not_in`; `values` registered apps' ids): X-Palbase-App.
|
|
4540
4540
|
* - `app_version` (`eq`, `neq`, `gt`, `gte`, `lt`, `lte`; `value` a version string): X-Palbase-Client-Version, compared as Semantic Versioning orders versions (2.1 is 2.1.0; a pre-release before its release).
|
|
4541
4541
|
* - `sdk_version` (the same operators; `sdk` the SDK's name, `value` a version): X-Palbase-SDK — a viewer on another SDK does not meet it.
|
|
@@ -4766,6 +4766,10 @@ export type Settings = {
|
|
|
4766
4766
|
* For how many days after the link a purchase owes the App Store its fee (7 unless set), 1 to 90: a subscription's renewals past them owe none.
|
|
4767
4767
|
*/
|
|
4768
4768
|
app_store_link_attribution_days: number;
|
|
4769
|
+
/**
|
|
4770
|
+
* How the web's (Stripe Checkout's) sales are taxed: none (none unless set) — Checkout works out no tax — or managed — Stripe Managed Payments: Stripe is the merchant of record, works out, collects and files the tax, invoices the buyer and takes their refunds and disputes. The Stripe account turns Managed Payments on first (Dashboard › Settings › Managed Payments), and every web product needs an eligible tax code (the catalog's web channel's tax_code).
|
|
4771
|
+
*/
|
|
4772
|
+
web_tax: "none" | "managed";
|
|
4769
4773
|
};
|
|
4770
4774
|
/**
|
|
4771
4775
|
* A change of the settings: the fields given change, the others stay.
|
|
@@ -4815,6 +4819,10 @@ export type SettingsUpdate = {
|
|
|
4815
4819
|
* For how many days after the link a purchase owes the App Store its fee (7 unless set), 1 to 90: a subscription's renewals past them owe none.
|
|
4816
4820
|
*/
|
|
4817
4821
|
app_store_link_attribution_days?: number;
|
|
4822
|
+
/**
|
|
4823
|
+
* How the web's (Stripe Checkout's) sales are taxed: none (none unless set) — Checkout works out no tax — or managed — Stripe Managed Payments: Stripe is the merchant of record, works out, collects and files the tax, invoices the buyer and takes their refunds and disputes. The Stripe account turns Managed Payments on first (Dashboard › Settings › Managed Payments), and every web product needs an eligible tax code (the catalog's web channel's tax_code).
|
|
4824
|
+
*/
|
|
4825
|
+
web_tax?: "none" | "managed";
|
|
4818
4826
|
};
|
|
4819
4827
|
/**
|
|
4820
4828
|
* What a commit, an extension or a reversal takes; a release takes nothing.
|
|
@@ -5091,6 +5099,10 @@ export type StripeProduct = {
|
|
|
5091
5099
|
* Its name.
|
|
5092
5100
|
*/
|
|
5093
5101
|
name: string;
|
|
5102
|
+
/**
|
|
5103
|
+
* What Stripe taxes it as (txcd_…); absent when none.
|
|
5104
|
+
*/
|
|
5105
|
+
tax_code?: string;
|
|
5094
5106
|
};
|
|
5095
5107
|
/**
|
|
5096
5108
|
* purchases.subscription.changed: a customer's subscription started, renewed, stopped renewing (canceled) or renews again (uncanceled), could not be charged (billing_issue) or was again (recovered), ended (expired), or moved to another product (product_changed).
|
|
@@ -5289,9 +5301,9 @@ export type ChartValue = {
|
|
|
5289
5301
|
*/
|
|
5290
5302
|
export type CheckoutSource = {
|
|
5291
5303
|
/**
|
|
5292
|
-
* The app's platform.
|
|
5304
|
+
* The app's platform: a Mac app's is macos. A web purchase counts in the charts as made on it.
|
|
5293
5305
|
*/
|
|
5294
|
-
platform: "ios" | "android" | "web";
|
|
5306
|
+
platform: "ios" | "android" | "web" | "macos";
|
|
5295
5307
|
/**
|
|
5296
5308
|
* The store's storefront the app runs in, ISO 3166-1 alpha-3 (StoreKit's Storefront.countryCode: USA).
|
|
5297
5309
|
*/
|
|
@@ -7382,7 +7394,7 @@ export declare function client(t: Transport): {
|
|
|
7382
7394
|
headers?: {
|
|
7383
7395
|
"X-Palbase-Paywall-Schema"?: number; /** The installation's id, as the SDK keeps it: who the paywall is shown to before anyone signs in. A signed-in user (a guest included) is who it is shown to, the installation aside. */
|
|
7384
7396
|
"X-Palbase-Installation"?: string; /** The ETag of the answer the app holds (a header over 1 KiB is not read). */
|
|
7385
|
-
"If-None-Match"?: string; /** The app's platform: ios, android or
|
|
7397
|
+
"If-None-Match"?: string; /** The app's platform: ios, android, web or macos (a placement's platform rules read it; `?channel=` when absent). */
|
|
7386
7398
|
"X-Platform"?: string; /** The app's version, as its users see it (CFBundleShortVersionString, versionName): app_version rules read it. */
|
|
7387
7399
|
"X-Palbase-Client-Version"?: string; /** The registered app's id: app rules read it. */
|
|
7388
7400
|
"X-Palbase-App"?: string; /** The SDK's name and version, name/version (palbase-swift/1.4.0): sdk_version rules read it. */
|
|
@@ -2581,7 +2581,7 @@ export type AppleSessionChangedEvent = {
|
|
|
2581
2581
|
team: AppleTeam;
|
|
2582
2582
|
};
|
|
2583
2583
|
/**
|
|
2584
|
-
* stores.apple.session.expired: Apple ended the project's Apple ID session (
|
|
2584
|
+
* stores.apple.session.expired: Apple ended the project's Apple ID session (Apple ends one some time after its sign-in, and at once when its password changes). What needs it answers 409 `apple_id_expired` until someone signs in again.
|
|
2585
2585
|
*/
|
|
2586
2586
|
export type AppleSessionExpiredEvent = {
|
|
2587
2587
|
/**
|
|
@@ -3599,7 +3599,7 @@ export interface Events {
|
|
|
3599
3599
|
*/
|
|
3600
3600
|
"stores.apple.session.changed": AppleSessionChangedEvent;
|
|
3601
3601
|
/**
|
|
3602
|
-
* stores.apple.session.expired: Apple ended the project's Apple ID session (
|
|
3602
|
+
* stores.apple.session.expired: Apple ended the project's Apple ID session (Apple ends one some time after its sign-in, and at once when its password changes). What needs it answers 409 `apple_id_expired` until someone signs in again.
|
|
3603
3603
|
*/
|
|
3604
3604
|
"stores.apple.session.expired": AppleSessionExpiredEvent;
|
|
3605
3605
|
/**
|
|
@@ -4405,7 +4405,7 @@ export declare function client(t: Transport): {
|
|
|
4405
4405
|
/**
|
|
4406
4406
|
* Check the Apple ID session
|
|
4407
4407
|
*
|
|
4408
|
-
* Asks Apple whose the session is now (its team, its roles) — the module does every
|
|
4408
|
+
* Asks Apple whose the session is now (its team, its roles) — the module does every 30 minutes a session is not used. A session Apple ended is marked `expired` and told (`stores.apple.session.expired`); sign in again to go on.
|
|
4409
4409
|
*/
|
|
4410
4410
|
checkAppleSession(input?: {
|
|
4411
4411
|
headers?: {
|
|
@@ -3,7 +3,8 @@ export type PaywallDefinition = purchases.PaywallDefinition;
|
|
|
3
3
|
export type MessageDefinition = notify.MessageDefinition;
|
|
4
4
|
/** What a screen is for: a paywall sells the catalog's packages; a message is shown in the app, or as a card of its inbox. */
|
|
5
5
|
export type ScreenKind = 'paywall' | 'message';
|
|
6
|
-
|
|
6
|
+
/** Where a screen is drawn: a Mac app's is macos. */
|
|
7
|
+
export type Platform = 'ios' | 'android' | 'web' | 'macos';
|
|
7
8
|
export type Appearance = 'light' | 'dark';
|
|
8
9
|
/** What the store gave a package, as the variables of its texts: `{{price}}` … */
|
|
9
10
|
export interface PackageValues {
|
package/dist/chunks/DCWPUWZE.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/*! palbase 0.62.0 — Palbase SDK License (see LICENSE) */
|
|
2
|
-
import{a as j,c as Ee,d as Pe,e as Re}from"./ZVDYTR3S.js";import{a as Ce}from"./3KEWWFIC.js";import{a as Ae}from"./ZWSYEBRO.js";import{a as xe,b as ve,c as _e}from"./USL5YRDX.js";import{b as P,d as Se}from"./ECVNYWWT.js";async function*Ie(e,t={}){let o=e.getReader(),s=new TextDecoder,i="",d="",l=[],p,r=()=>{o.cancel().catch(()=>{})};t.signal?.addEventListener("abort",r,{once:!0});try{if(t.signal?.aborted)return;for(;;){let{done:n,value:a}=await o.read();if(n||t.signal?.aborted)return;t.onBytes?.(),i+=s.decode(a,{stream:!0});for(let c=i.indexOf(`
|
|
3
|
-
`);c>=0;c=i.indexOf(`
|
|
4
|
-
`)){let g=i.slice(0,i[c-1]==="\r"?c-1:c);i=i.slice(c+1),g===""?(d!==""&&(yield p===void 0?{event:d,data:l.join(`
|
|
5
|
-
`)}:{event:d,data:l.join(`
|
|
6
|
-
`),id:p}),d="",l=[],p=void 0):g.startsWith("event:")?d=ie(g,6):g.startsWith("data:")?l.push(ie(g,5)):g.startsWith("id:")&&(p=ie(g,3))}}}finally{t.signal?.removeEventListener("abort",r);try{await o.cancel()}catch{}}}function ie(e,t){let o=e.slice(t);return o.startsWith(" ")?o.slice(1):o}var Dt=/\s/;function Y(e,t){for(;t<e.length&&Dt.test(e[t]);)t++;return t}function $e(e,t){let o="";for(let s=t+1;s<e.length;s++){let i=e[s];if(i==='"')return{value:o,complete:!0,empty:!1,at:s+1};if(i!=="\\"){o+=i;continue}let d=e[s+1];if(d===void 0)break;if(d==="u"){let l=e.slice(s+2,s+6);if(l.length<4)break;o+=String.fromCharCode(Number.parseInt(l,16)),s+=5;continue}o+={n:`
|
|
7
|
-
`,t:" ",r:"\r",b:"\b",f:"\f"}[d]??d,s++}return{value:o,complete:!1,empty:!1,at:e.length}}function de(e,t){t=Y(e,t);let o=e[t];if(o===void 0)return{value:void 0,complete:!1,empty:!0,at:t};if(o==='"')return $e(e,t);if(o==="{")return Ut(e,t);if(o==="[")return Lt(e,t);let s=t;for(;s<e.length&&/[-+0-9.A-Za-z]/.test(e[s]);)s++;if(s===e.length)return{value:void 0,complete:!1,empty:!0,at:s};try{return{value:JSON.parse(e.slice(t,s)),complete:!0,empty:!1,at:s}}catch{return{value:void 0,complete:!1,empty:!0,at:e.length}}}function Ut(e,t){let o={},s=t+1;for(;;){if(s=Y(e,s),e[s]==="}")return{value:o,complete:!0,empty:!1,at:s+1};if(e[s]===","){s++;continue}if(e[s]!=='"')return{value:o,complete:!1,empty:!1,at:e.length};let i=$e(e,s);if(!i.complete)return{value:o,complete:!1,empty:!1,at:e.length};if(s=Y(e,i.at),e[s]!==":")return{value:o,complete:!1,empty:!1,at:e.length};let d=de(e,s+1);if(d.empty||Object.defineProperty(o,i.value,{value:d.value,enumerable:!0,writable:!0,configurable:!0}),!d.complete)return{value:o,complete:!1,empty:!1,at:e.length};s=d.at}}function Lt(e,t){let o=[],s=t+1;for(;;){if(s=Y(e,s),e[s]==="]")return{value:o,complete:!0,empty:!1,at:s+1};if(e[s]===","){s++;continue}if(s>=e.length)return{value:o,complete:!1,empty:!1,at:s};let i=de(e,s);if(i.empty||o.push(i.value),!i.complete)return{value:o,complete:!1,empty:!1,at:e.length};s=i.at}}function ce(e){let t=de(e,0);return t.empty?void 0:t.value}var w=class extends Error{path;constructor(t,o){super(`${t}: ${o}`),this.name="AISchemaError",this.path=t}},qt=new Set(["type","properties","required","additionalProperties","items","enum","description","title","minimum","maximum","minLength","maxLength","minItems","maxItems"]),Vt=new Set(["format","pattern","exclusiveMinimum","exclusiveMaximum","multipleOf","uniqueItems","contentEncoding","contentMediaType","default","examples","readOnly","writeOnly","deprecated","$comment"]),Gt=new Set(["object","array","string","integer","number","boolean"]),Oe=12,Me=512,zt=/^[A-Za-z][A-Za-z0-9_-]{0,63}$/;function B(e,t="answer"){if(!zt.test(t))throw new w(t||"(name)","a schema name starts with a letter and holds letters, digits, _ and -, 64 at most");let o=e?.["~standard"];if(!o||o.version!==1||typeof o.validate!="function")throw new w(t,"not a Standard Schema: pass a zod (4.2+), valibot or arktype schema");if(!o.jsonSchema||typeof o.jsonSchema.output!="function")throw new w(t,`${o.vendor}'s schema cannot say itself as JSON Schema; use a version that implements Standard JSON Schema`);let s;try{s=o.jsonSchema.output({target:"draft-2020-12",libraryOptions:{unrepresentable:"throw"}})}catch(l){throw new w(t,`the schema has a part JSON Schema cannot say (${l.message}): a function, a transform, a date \u2014 give the model a string and convert it after`)}if(s.type!=="object")throw new w(t,"the answer is an object: wrap the value in z.object({ \u2026 })");let d=le(s,t,0,{properties:0});return{name:t,json:d,async check(l){let p=await o.validate(l);if(p.issues){let r=p.issues[0],n=(r?.path??[]).map(a=>String(typeof a=="object"?a.key:a)).join(".");throw new w(n?`${t}.${n}`:t,`the model's answer does not match the schema: ${r?.message??"invalid"}`)}return p.value}}}function le(e,t,o,s){if(o>Oe)throw new w(t,`nests deeper than ${Oe} levels, the most the provider takes`);for(let l of["anyOf","oneOf","allOf"])if(l in e)throw new w(t,Kt(e[l])??"is a union of several shapes: the provider holds a model to one shape per field \u2014 use an enum, or one object with every field");for(let l of["$ref","$defs","definitions","$dynamicRef"])if(l in e)throw new w(t,"refers to another schema (a recursive or shared type): the provider takes no references \u2014 write the shape out, a bounded number of levels deep");if(e.type==="object"&&("propertyNames"in e||"patternProperties"in e||e.additionalProperties!==void 0&&e.additionalProperties!==!1))throw new w(t,"accepts fields it does not name (a record, passthrough or catchall): the provider holds a model only to the fields named \u2014 name them");for(let l of["prefixItems","patternProperties","propertyNames","not","if","then","else","dependentRequired","dependentSchemas","const","minProperties","maxProperties","contains","unevaluatedProperties","unevaluatedItems"])if(l in e)throw new w(t,`uses ${l}, which the provider cannot hold a model to`);if(Array.isArray(e.type))throw new w(t,`may be ${e.type.join(" or ")}: one type per field \u2014 a nullable field is not expressible; give it a value that means "none" (an empty string, an enum member)`);let i=e.type;if(typeof i!="string"&&!("enum"in e))throw new w(t,"has no type: the provider holds a model only to a typed value");if(typeof i=="string"&&!Gt.has(i))throw new w(t,`is of type ${i}, which the provider does not take`);let d={};for(let[l,p]of Object.entries(e))if(!(l==="$schema"||l==="id"||l==="$id")&&!Vt.has(l)){if(!qt.has(l))throw new w(t,`uses ${l}, which the provider cannot hold a model to`);d[l]=p}if("enum"in e&&typeof i!="string"){let l=e.enum,p=new Set(l.map(r=>r===null?"null":typeof r));if(p.size!==1||p.has("null"))throw new w(t,"an enum of values of several types (or with null): one type per field");d.type=p.has("string")?"string":p.has("boolean")?"boolean":"number"}if(i==="object"){let l=e.properties??{},p=Object.keys(l);if(p.length===0)throw new w(t,"is an object with no fields (a record, or any object): the provider holds a model only to named fields \u2014 name them");if(e.additionalProperties!==void 0&&e.additionalProperties!==!1)throw new w(t,"accepts fields it does not name (passthrough, catchall, record): the provider holds a model only to the fields named");if(s.properties+=p.length,s.properties>Me)throw new w(t,`the schema has more than ${Me} fields in all, the most the provider takes`);let r=new Set(e.required??[]),n={};for(let a of p){if(!r.has(a))throw new w(`${t}.${a}`,'is optional: the provider makes the model write every field \u2014 make it required (give it a value that means "none"), or leave it out of the schema');n[a]=le(l[a],`${t}.${a}`,o+1,s)}d.properties=n,d.required=p,d.additionalProperties=!1}if(i==="array"){let l=e.items;if(!l||typeof l!="object"||Array.isArray(l))throw new w(t,"is a list with no one shape for its items: the provider takes a list of one shape");d.items=le(l,`${t}[]`,o+1,s)}return d}function Kt(e){if(Array.isArray(e)&&e.length===2&&e.some(t=>t?.type==="null"))return'is nullable: the provider makes the model write a value of one type \u2014 drop .nullable() and give it a value that means "none"'}var Jt=new Set(["image/png","image/jpeg","image/webp","image/gif"]);function z(e){return Array.isArray(e)&&e.length>0&&e.every(je)?e.map(Be):je(e)?[Be(e)]:e==null?[{type:"text",text:""}]:typeof e=="string"?[{type:"text",text:e}]:[{type:"text",text:JSON.stringify(e)??String(e)}]}function je(e){if(typeof e!="object"||e===null)return!1;let t=e;return t.type==="text"?typeof t.text=="string":t.type==="image"?(typeof t.mediaType=="string"||typeof t.media_type=="string")&&(typeof t.data=="string"||t.data instanceof Uint8Array):t.type===void 0&&typeof t.mediaType=="string"&&t.bytes instanceof Uint8Array}function Be(e){if("type"in e&&e.type==="text")return{type:"text",text:e.text};let t="bytes"in e||"mediaType"in e?e.mediaType:e.media_type;if(!Jt.has(t))throw new TypeError(`a tool's picture is image/png, image/jpeg, image/webp or image/gif (got ${JSON.stringify(t)})`);let o="bytes"in e?e.bytes:e.data;return{type:"image",media_type:t,data:typeof o=="string"?o:Ft(o)}}function Ft(e){let t="";for(let o=0;o<e.length;o+=32768)t+=String.fromCharCode(...e.subarray(o,o+32768));return btoa(t)}var Ke=Symbol.for("palbase.ai.deferred"),Ne=60,We=86400;function Je(e={}){let t=e?.expiresInSeconds;if(t!==void 0&&(!Number.isInteger(t)||t<Ne||t>We))throw new TypeError(`ai.deferred: expiresInSeconds is how long the call waits for its answer, ${Ne} to ${We} seconds (got ${String(t)})`);return Object.freeze({[Ke]:!0,...t!==void 0?{expiresInSeconds:t}:{}})}function Xt(e){return typeof e=="object"&&e!==null&&e[Ke]===!0}var Fe=Symbol.for("palbase.ai.reply"),Zt=/^[A-Za-z0-9_.:-]{1,160}$/;function F(e,t){if(typeof e!="object"||e===null)throw new TypeError(`${t}: workspaceTree is the tree the tool's writes left the workspace at \u2014 what chats.workspace.write answered ({ manifestId, seq }), either or both`);let{manifestId:o,seq:s}=e,i={};if(o!==void 0){if(typeof o!="string"||!Zt.test(o))throw new TypeError(`${t}: workspaceTree.manifestId is a tree's id as chats.workspace.write answered it (got ${JSON.stringify(o)})`);i.manifest_id=o}if(s!==void 0){if(!Number.isSafeInteger(s)||s<1)throw new TypeError(`${t}: workspaceTree.seq is a place in the workspace's history, a whole number from 1 (got ${String(s)})`);i.seq=s}if(i.manifest_id===void 0&&i.seq===void 0)throw new TypeError(`${t}: workspaceTree names the tree \u2014 its manifestId, its seq, or both`);return i}function Xe(e,t){let o=F(t?.workspaceTree,"ai.answer");return Object.freeze({[Fe]:!0,output:e,workspaceTree:Object.freeze({...o.manifest_id!==void 0?{manifestId:o.manifest_id}:{},...o.seq!==void 0?{seq:o.seq}:{}})})}function Yt(e){return typeof e=="object"&&e!==null&&e[Fe]===!0}var Ht=Symbol.for("palbase.ai.declared"),Qt=Symbol.for("palbase.ai.tool_error"),ue=class extends Error{workspaceTree;constructor(t,o){if(super(t),this.name="ToolError",Object.defineProperty(this,Qt,{value:!0}),o?.workspaceTree!==void 0){let s=F(o.workspaceTree,"ToolError");this.workspaceTree=Object.freeze({...s.manifest_id!==void 0?{manifestId:s.manifest_id}:{},...s.seq!==void 0?{seq:s.seq}:{}})}}};function N(){let e=globalThis,t=e[Ht]??={tools:new Map,clientTools:new Map,agents:new Map,repos:new Map,twice:new Set};return t.repos??=new Map,t.clientTools??=new Map,t}function H(e,t,o,s,i=(d,l)=>d===l){let d=e.get(o);d===void 0?e.set(o,s):i(d,s)||N().twice.add(`${t}:${o}`)}var Ze=/^[A-Za-z][A-Za-z0-9_-]{0,63}$/,v=/^[a-z][a-z0-9_-]{0,63}$/,Q=/^[A-Za-z0-9_.:-]{1,160}$/,Ye=128,en=/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}\p{Cs}]/u,ee=`${Ye} bytes at most, no control, format (bidi, zero-width) or line-separator character`;function te(e){return typeof e=="string"&&new TextEncoder().encode(e).byteLength<=Ye&&!en.test(e)}function He(e,t){if(e===void 0)return{type:"object",properties:{}};let o=e?.["~standard"];if(!o||o.version!==1||typeof o.validate!="function")throw new TypeError(`${t}: input is a Standard Schema \u2014 a zod (4.2+), valibot or arktype object schema`);if(!o.jsonSchema||typeof o.jsonSchema.output!="function")throw new TypeError(`${t}: ${o.vendor}'s schema cannot say itself as JSON Schema; use a version that implements Standard JSON Schema`);let s;try{s=o.jsonSchema.output({target:"draft-2020-12",libraryOptions:{unrepresentable:"throw"}})}catch(p){throw new TypeError(`${t}: the input has a part JSON Schema cannot say (${p.message}) \u2014 a function, a transform, a date: take a string and convert it in run`)}if(s.type!=="object")throw new TypeError(`${t}: a tool takes an object \u2014 wrap the input in z.object({ \u2026 })`);let i=JSON.stringify(s);if(/"\$(ref|defs|dynamicRef)"/.test(i))throw new TypeError(`${t}: the input refers to another schema (a recursive or shared type) \u2014 write the shape out`);let{$schema:d,...l}=s;return l}function Qe(e){let t=`ai.tool(${JSON.stringify(e?.name??null)})`;if(typeof e?.name!="string"||!Ze.test(e.name))throw new TypeError(`${t}: name is letters, digits, _ and -, starting with a letter, at most 64`);if(typeof e.description!="string"||e.description.trim()==="")throw new TypeError(`${t}: description says what it does \u2014 the agent reads it to choose`);if(typeof e.run!="function")throw new TypeError(`${t}: run(input, ctx) is what a call does`);if(e.machine!==void 0&&!v.test(e.machine))throw new TypeError(`${t}: machine is the name of one of the project's machines`);if(e.input===void 0)throw new TypeError(`${t}: input is what it takes \u2014 z.object({}) for nothing`);let o=He(e.input,t),s=e.input["~standard"],i=e.run,d={source:"backend",name:e.name,description:e.description,input:e.input,parameters:o,approval:e.approval===!0,...e.machine!==void 0?{machine:e.machine}:{},async call(p,r){let n=await s.validate(p);if(n.issues){let c=n.issues[0],g=(c?.path??[]).map(_=>String(typeof _=="object"?_.key:_)).join(".");return{output:[{type:"text",text:`the input does not match ${e.name}'s schema${g?` at ${g}`:""}: ${c?.message??"invalid"}`}],is_error:!0}}let a=await i(n.value,r);if(Xt(a))return r.chatId===""?{output:[{type:"text",text:`${e.name} answers later, and a one-shot answer waits for no call: it answers at once, or in a chat`}],is_error:!0}:{deferred:!0,...a.expiresInSeconds!==void 0?{expires_in_seconds:a.expiresInSeconds}:{}};if(Yt(a)){let c={output:z(a.output),is_error:!1};return a.workspaceTree!==void 0&&(c.workspace_tree=F(a.workspaceTree,t)),c}return{output:z(a),is_error:!1}}};Object.freeze(d);let l=N();return l.clientTools.has(d.name)&&l.twice.add(`tool:${d.name}`),H(l.tools,"tool",d.name,d),d}function et(e){let t=`ai.clientTool(${JSON.stringify(e?.name??null)})`;if(typeof e?.name!="string"||!Ze.test(e.name))throw new TypeError(`${t}: name is letters, digits, _ and -, starting with a letter, at most 64`);if(typeof e.description!="string"||e.description.trim()==="")throw new TypeError(`${t}: description says what it does \u2014 the agent reads it to choose`);let o=Object.freeze({source:"client",name:e.name,description:e.description,parameters:He(e.input,t),approval:e.approval===!0}),s=N();return s.tools.has(o.name)&&s.twice.add(`tool:${o.name}`),H(s.clientTools,"tool",o.name,o,(i,d)=>JSON.stringify(i)===JSON.stringify(d)),o}var tn=/^[A-Za-z0-9_.-]{1,100}\/[A-Za-z0-9_.-]{1,100}$/;function tt(e){let t=e??{};if(typeof t.name!="string"||!v.test(t.name))throw new TypeError("ai.repo: name is lowercase letters, digits, _ and -, starting with a letter, at most 64");if(typeof t.repository!="string"||!tn.test(t.repository))throw new TypeError(`ai.repo(${JSON.stringify(t.name)}): repository is a GitHub repository, owner/name`);if(typeof t.token!="function")throw new TypeError(`ai.repo(${JSON.stringify(t.name)}): token is the function that gives a token for one clone or push`);if(t.machine!==void 0&&!v.test(t.machine))throw new TypeError(`ai.repo(${JSON.stringify(t.name)}): machine is the project's machine that gives its tokens`);let o=t.token,s={kind:"repo",name:t.name,repository:t.repository,defaultBranch:t.defaultBranch??"main",...t.machine!==void 0?{machine:t.machine}:{},async token(i){return await o(i)}};return H(N().repos,"repo",t.name,s),s}function nt(e){if(typeof e!="function")throw new TypeError("ai.repoTokens(give): give is the function that gives a token for one clone or push of a repository put by name");let t=N();t.repoTokens===void 0?t.repoTokens=e:t.repoTokens!==e&&t.twice.add("repoTokens")}function rt(e,t,o={}){let s=`ai.agent(${JSON.stringify(e??null)})`;if(typeof e!="string"||!v.test(e))throw new TypeError(`${s}: name is lowercase letters, digits, _ and -, starting with a letter, at most 64`);if(typeof t!="function")throw new TypeError(`${s}: the agent is a function of the turn's context that returns its definition`);let i=o??{};if(i.machine!==void 0&&!v.test(i.machine))throw new TypeError(`${s}: machine is the name of one of the project's machines`);let d=i.description===void 0?void 0:st(i.description,s),l={kind:"agent",name:e,...d!==void 0?{description:d}:{},...i.machine!==void 0?{machine:i.machine}:{},async resolve(p){let r=await t(p),n=ne(r,`${s} for chat ${p.chatId}`);if(n.backend!==void 0)throw new TypeError(`${s}: a backend's agent is its definition \u2014 it names no other backend`);return n.description===void 0&&d!==void 0&&(n.description=d),{definition:n,tools:nn(r)}}};return Object.freeze(l),H(N().agents,"agent",e,l),l}function X(e){return typeof e=="object"&&e!==null&&e.kind==="agent"?e:void 0}function nn(e){return[...e.tools??[],...(e.subagents??[]).flatMap(o=>o.tools??[])].filter(o=>o.source==="backend")}var De=["web.search","web.fetch","workspace.fetch_archive"];function K(e,t){if(typeof e!="object"||e===null)throw new TypeError(`${t}: a tool is ai.tool(\u2026), ai.clientTool(\u2026), { source: 'https', name }, { source: 'mcp', name } or { source: 'platform', name }`);let o=e.approval===!0?{approval:!0}:{};switch(e.source){case"backend":if(typeof e.call!="function")throw new TypeError(`${t}: a backend tool is made with ai.tool({ name, description, input, run })`);return{source:"backend",name:e.name,description:e.description,parameters:e.parameters,...o,...e.machine!==void 0?{machine:e.machine}:{}};case"client":return{source:"client",name:e.name,description:e.description,parameters:e.parameters,...o};case"https":if(typeof e.name!="string"||!v.test(e.name))throw new TypeError(`${t}: { source: 'https', name } names an endpoint the project put`);return{source:"https",name:e.name,...o};case"mcp":if(typeof e.name!="string"||!v.test(e.name))throw new TypeError(`${t}: { source: 'mcp', name } names an MCP server the project put`);return{source:"mcp",name:e.name,...o,...e.only!==void 0?{only:[...e.only]}:{}};case"platform":{let s=Object.keys(e).filter(i=>i!=="source"&&i!=="name");if(typeof e.name!="string"||!De.includes(e.name))throw new TypeError(`${t}: { source: 'platform', name } names one of the platform's tools: ${De.join(", ")}`);if(s.length>0)throw new TypeError(`${t}: the platform's ${e.name} is given by its name alone (not ${s.join(", ")})`);return{source:"platform",name:e.name}}default:throw new TypeError(`${t}: a tool's source is backend, client, https, mcp or platform (got ${JSON.stringify(e.source)})`)}}var Ue=1e4,Le=["none","minimal","low","medium","high","xhigh","max"],rn=1e8,sn=/^[A-Za-z]{2,8}(-[A-Za-z0-9]{1,8})*$/,qe=1024,on=/^[A-Z][A-Z0-9_]{0,127}$/,Ve=64,J=32768,Ge=65536;function ge(e){return typeof e=="string"&&on.test(e)&&!e.startsWith("PALAI_")}var ze=e=>new TextEncoder().encode(e).byteLength;function an(e,t){let o={};if(e.env!==void 0){if(typeof e.env!="object"||e.env===null||Array.isArray(e.env))throw new TypeError(`${t}: env is the agent's own variables, { NAME: value }`);let s=Object.entries(e.env);if(s.length>Ve)throw new TypeError(`${t}: env names ${Ve} variables at most`);let i={};for(let[d,l]of s){if(!ge(d))throw new TypeError(`${t}: env: ${JSON.stringify(d.slice(0,140))} is no variable's name \u2014 upper-case letters, digits and _, a letter first, at most 128, and not PALAI_\u2026, the engine's own`);if(typeof l!="string"||ze(l)>J||l.includes("\0"))throw new TypeError(`${t}: env.${d} is text of ${J} bytes at most, no NUL ('' keeps the value it has)`);i[d]=l}o.env=i}if(e.setup!==void 0){if(typeof e.setup!="string"||ze(e.setup)>Ge||e.setup.includes("\0"))throw new TypeError(`${t}: setup is a shell script of ${Ge} bytes at most, no NUL`);o.setup=e.setup}return o}function st(e,t){if(typeof e!="string"||e.trim()===""||e.length>qe)throw new TypeError(`${t}: description says what the agent is for, in a sentence or two (${qe} characters at most)`);return e}function dn(e,t){let o=e?.prepared;if(o!==void 0&&typeof o=="object"&&o!==null&&typeof o.json=="object")return o.json;if(typeof e!="object"||e===null||!("~standard"in e))throw new TypeError(`${t}: output is the shape of its one-shot answers \u2014 a zod (valibot, arktype) object schema, or ai.schema(name, schema)`);return B(e,"output").json}function fe(e,t){if(!Number.isInteger(e)||e<1||e>Ue)throw new TypeError(`${t}: maxToolCalls is a whole number, 1 to ${Ue} (got ${String(e)})`);return e}function pe(e,t){let o={};if(e.effort!==void 0){if(typeof e.effort!="string"||!Le.includes(e.effort))throw new TypeError(`${t}: effort is one of ${Le.join(", ")} \u2014 which a model takes is its catalogue entry's (ai.models())`);o.effort=e.effort}if(e.contextWindow!==void 0){if(!Number.isInteger(e.contextWindow)||e.contextWindow<1||e.contextWindow>rn)throw new TypeError(`${t}: contextWindow is a number of tokens (got ${String(e.contextWindow)})`);o.context_window=e.contextWindow}if(e.thinking!==void 0){if(e.thinking!=="visible"&&e.thinking!=="hidden")throw new TypeError(`${t}: thinking is visible (the model's reasoning in the chat's stream) or hidden`);o.thinking=e.thinking}return o}function ne(e,t){if(typeof e!="object"||e===null)throw new TypeError(`${t}: a definition is { description, instructions, model, tools, subagents, advisor, maxToolCalls, effort, contextWindow, thinking, language, env, setup, output }`);let o={};if(e.description!==void 0&&(o.description=st(e.description,t)),e.instructions!==void 0&&(o.instructions=e.instructions),e.model!==void 0&&(o.model=e.model),e.maxToolCalls!==void 0&&(o.max_tool_calls=fe(e.maxToolCalls,t)),Object.assign(o,pe(e,t)),e.language!==void 0){if(typeof e.language!="string"||e.language.length>35||!sn.test(e.language))throw new TypeError(`${t}: language is the language of the person the turn works for, as a BCP 47 tag (tr, en-GB)`);o.language=e.language}if(Object.assign(o,an(e,t)),e.output!==void 0&&(o.output=dn(e.output,t)),e.tools!==void 0&&(o.tools=e.tools.map(s=>K(s,t))),e.subagents!==void 0){for(let s of e.subagents){let i=(s?.tools??[]).find(d=>d?.source==="platform");if(i)throw new TypeError(`${t} subagent ${s.name}: the platform's ${i.name} is the agent's tool \u2014 its subagents work with the agent's`)}o.subagents=e.subagents.map(s=>({name:s.name,description:s.description,...s.instructions!==void 0?{instructions:s.instructions}:{},...s.model!==void 0?{model:s.model}:{},...s.required!==void 0?{required:s.required}:{},...pe(s,`${t} subagent ${s.name}`),...s.tools!==void 0?{tools:s.tools.map(i=>K(i,`${t} subagent ${s.name}`))}:{}}))}return e.advisor!==void 0&&(o.advisor=cn(e.advisor,`${t} advisor`)),o}function cn(e,t){if(typeof e!="object"||e===null)throw new TypeError(`${t}: an advisor is { model, instructions, effort, tools }`);let o={};if(e.model!==void 0&&(o.model=e.model),e.instructions!==void 0){if(typeof e.instructions!="string"||new TextEncoder().encode(e.instructions).length>64*1024)throw new TypeError(`${t}: instructions is text, 64 KiB at most`);o.instructions=e.instructions}let{effort:s}=pe({effort:e.effort},t);if(s!==void 0&&(o.effort=s),e.tools!==void 0){if(!Array.isArray(e.tools)||e.tools.length>32)throw new TypeError(`${t}: tools is 32 MCP servers at most`);o.tools=e.tools.map(i=>{if(i?.source!=="mcp")throw new TypeError(`${t}: the advisor reads; its tools are MCP servers' ({ source: 'mcp', name }), whose tools it is given when they say they only read`);if(i.approval===!0)throw new TypeError(`${t}: nothing the advisor reads waits for a person (approval)`);return K(i,t)})}return o}function W(e,t){if(typeof e!="string"||!v.test(e))throw new TypeError(`${t}: an agent's name is lowercase letters, digits, _ and -, starting with a letter, at most 64 (got ${JSON.stringify(e)})`);return e}function ot(e,t){if(!Number.isSafeInteger(e)||e<1)throw new TypeError(`${t}: revision is the draft's revision as it was read (Agent's revision), a whole number from 1 (got ${String(e)})`);return e}function at(e,t){let o={approve:e};return t.reason!==void 0&&(o.reason=t.reason),t.as!==void 0&&(o.as=t.as),o}var ln=/^[a-z][a-z0-9-]{1,62}$/,it=4,dt=8;function un(e){let t={},o=(s,i)=>{if(typeof s?.bucket!="string"||!ln.test(s.bucket))throw new TypeError(`chats.send: ${i}'s bucket is one of the project's buckets, by its name`);if(typeof s.path!="string"||s.path===""||s.path.length>1024)throw new TypeError(`chats.send: ${i}'s path is its path in the bucket (1024 characters at most)`);return{bucket:s.bucket,path:s.path}};if(e.images!==void 0){if(!Array.isArray(e.images)||e.images.length>it)throw new TypeError(`chats.send: images are ${it} at most \u2014 as many as the model is shown at once`);t.images=e.images.map((s,i)=>o(s,`images[${i}]`))}if(e.files!==void 0){if(!Array.isArray(e.files)||e.files.length>dt)throw new TypeError(`chats.send: files are ${dt} at most`);t.files=e.files.map((s,i)=>{let d=o(s,`files[${i}]`);if(s.filename!==void 0){if(typeof s.filename!="string"||s.filename===""||s.filename.length>255)throw new TypeError(`chats.send: files[${i}].filename is its name in the workspace (255 characters at most)`);d.filename=s.filename}if(s.contentType!==void 0){if(typeof s.contentType!="string"||s.contentType===""||s.contentType.length>128)throw new TypeError(`chats.send: files[${i}].contentType is a media type (application/pdf)`);d.content_type=s.contentType}return d})}return t}function re(e){return{id:e.id,chatId:e.chat_id,userId:e.user_id,delegation:e.delegation,status:e.status,seconds:e.seconds,startedAt:e.started_at,closedAt:e.closed_at,closeReason:e.close_reason??""}}var pn=["speak","tell","know","instruct"];function ct(){return"cm_"+crypto.randomUUID()}async function se(e,t,o=4){for(let s=1;;s++)try{return await e()}catch(i){if(s>=o||!(i instanceof P)||i.status===429||t?.aborted)throw i;let d=_e(i,s,30);if(d===void 0)throw i;await new Promise((l,p)=>{let r=setTimeout(l,d*1e3);t?.addEventListener("abort",()=>(clearTimeout(r),p(t.reason)),{once:!0})})}}function me(e){return{id:e.id,chatId:e.chat_id,objective:e.objective,rubric:e.rubric,status:e.status,stopCode:e.stop_code,stopReason:e.stop_reason,phase:e.phase,setBy:e.set_by,maxTurns:e.max_turns,budget:e.budget===null?null:{maxCostUsd:e.budget.max_cost_usd},usage:{turns:e.usage.turns,verifications:e.usage.verifications,costUsd:e.usage.cost_usd,costIsLowerBound:e.usage.cost_is_lower_bound,activeSeconds:e.usage.active_seconds},achievedAt:e.achieved_at,createdAt:e.created_at,updatedAt:e.updated_at}}var lt=e=>({user_id:e.userId,...e.name!==void 0?{name:e.name}:{},...e.email!==void 0?{email:e.email}:{},...e.owner!==void 0?{owner:e.owner}:{}}),gn=/^[A-Za-z0-9-]{1,64}$/,ut=16;function fn(e){if(!Array.isArray(e)||e.length>ut)throw new TypeError(`chats.create: workspace.trailers are ${ut} at most, each { key, value }`);return e.map((t,o)=>{if(typeof t?.key!="string"||!gn.test(t.key))throw new TypeError(`chats.create: workspace.trailers[${o}].key is a git trailer's token: letters, digits and -, at most 64 (PalCore-Task, Co-authored-by)`);if(typeof t.value!="string"||t.value===""||/[\r\n]/.test(t.value)||new TextEncoder().encode(t.value).byteLength>512)throw new TypeError(`chats.create: workspace.trailers[${o}].value is one line of 512 bytes at most`);return{key:t.key,value:t.value}})}var pt=2048,gt=255;function ft(e,t){let o=s=>new TextEncoder().encode(s).byteLength;if(typeof e!="string"||e===""||o(e)>pt||e.startsWith("/")||e.split("/").some(s=>s===""||s==="."||s===".."||o(s)>gt))throw new TypeError(`${t}: path is a file of the chat's workspace, relative to its root (repo/src/config.json): 1 to ${pt} bytes, each segment 1 to ${gt}, no . or .. segment, no leading or trailing slash`);return e}var he=64*1024*1024;async function mn(e,t){let o=r=>new RangeError(`${t}: a workspace's file is written up to 64 MiB (${he} bytes); this one is ${r}`);if(typeof e=="string"&&(e=new TextEncoder().encode(e)),e instanceof Uint8Array||e instanceof Blob){let r=e instanceof Blob?e.size:e.byteLength;if(r>he)throw o(`${r} bytes`);return e}if(!(e instanceof ReadableStream))throw new TypeError(`${t}: the file's bytes are text, a Uint8Array, a Blob or a ReadableStream`);let s=e.getReader(),i=[],d=0;try{for(;;){let{done:r,value:n}=await s.read();if(r)break;if(!(n instanceof Uint8Array))throw new TypeError(`${t}: a stream's chunks are Uint8Arrays (got ${typeof n})`);if(d+=n.byteLength,d>he)throw o("more");i.push(n)}}catch(r){throw await s.cancel(r).catch(()=>{}),r}finally{s.releaseLock()}let l=new Uint8Array(d),p=0;for(let r of i)l.set(r,p),p+=r.byteLength;return l}var mt=e=>({path:e.path,manifestId:e.manifest_id,seq:e.seq});function ht(e){return{id:e.id,access:e.access,...e.label?{label:e.label}:{},expiresAt:e.expires_at,workspaceId:e.workspace_id}}var yt=604800;function hn(e){return{runId:e.run_id,responseId:e.response_id,parentRunId:e.parent_run_id??null,subagent:e.subagent,model:e.model,state:e.state,inputTokens:e.input_tokens,outputTokens:e.output_tokens,cacheReadTokens:e.cache_read_tokens,cacheWriteTokens:e.cache_write_tokens,costNanoUsd:e.cost_nano_usd,usd:e.usd,unpriced:e.unpriced}}function wt(e){return{clients:e.clients,userMessagesPerMinute:e.user_messages_per_minute,historyLimitBytes:e.history_limit_bytes,historyBytes:e.history_bytes,monthlyBudgetUsd:e.monthly_budget_usd??null}}function yn(e){return new Proxy(e,{get(t,o){let s=t[o];return typeof s=="function"?(...i)=>j(s.apply(t,i)):s}})}function bt(e){let t=yn(e),o={async create(r){let n=typeof r.agent=="string"||r.agent===void 0?r.agent:X(r.agent)?.name;if(r.agent!==void 0&&n===void 0)throw new TypeError("chats.create: agent is one of the project's agents by name (name@N for a version), or a backend's ai.agent");if(n===void 0&&r.definition===void 0)throw new TypeError("chats.create: an agent (one of the project's, by name) or a definition of the chat's own");let a={agent:n??"assistant"};if(r.definition!==void 0&&(a.definition=ne(r.definition,"chats.create")),r.title!==void 0&&(a.title=r.title),r.metadata!==void 0&&(a.metadata=r.metadata),r.members!==void 0&&(a.members=r.members.map(lt)),r.pool!==void 0){if(typeof r.pool!="string"||!Q.test(r.pool))throw new TypeError("chats.create: pool is one of the project's runner pools (ai.pools), by its id or its name");a.pool=r.pool}return r.workspace!==void 0&&(a.workspace={repos:r.workspace.repos.map(c=>({repo:typeof c.repo=="string"?c.repo:c.repo.name,...c.branch!==void 0?{branch:c.branch}:{}})),...r.workspace.autoPush!==void 0?{auto_push:r.workspace.autoPush}:{},...r.workspace.trailers!==void 0?{trailers:fn(r.workspace.trailers)}:{}}),(await t.createChat({body:a,signal:r.signal})).data},async get(r,n={}){return(await t.getChat({path:{chat_id:r},signal:n.signal})).data},async list(r={}){let n=r.metadata===void 0?void 0:Object.entries(r.metadata).map(([c,g])=>`${c}:${g}`),a=(await t.listChats({query:{member:r.member,limit:r.limit,cursor:r.cursor,metadata:n},signal:r.signal})).data;return a.next_cursor===void 0?{chats:a.chats}:{chats:a.chats,nextCursor:a.next_cursor}},async delete(r){await t.deleteChat({path:{chat_id:r}})},members:{async put(r,n,a){let c={};return a.name!==void 0&&(c.name=a.name),a.email!==void 0&&(c.email=a.email),a.owner!==void 0&&(c.owner=a.owner),(await t.putChatMember({path:{chat_id:r,user_id:n},body:c})).data},async delete(r,n){await t.deleteChatMember({path:{chat_id:r,user_id:n}})}},async send(r,n){let a={client_id:n.clientId??ct(),text:n.text};return n.delivery!==void 0&&(a.delivery=n.delivery),n.as!==void 0&&(a.as=n.as),n.budget!==void 0&&(a.budget={max_cost_usd:n.budget.maxCostUsd}),n.metadata!==void 0&&(a.metadata=n.metadata),n.context!==void 0&&(a.context=n.context),Object.assign(a,un(n)),se(async()=>(await t.sendChatMessage({path:{chat_id:r},body:a,signal:n.signal})).data,n.signal)},async turnCost(r,n,a={}){let c=(await t.getChatTurnCost({path:{chat_id:r,response_id:n},signal:a.signal})).data,g={chatId:c.chat_id,responseId:c.response_id,inputTokens:c.input_tokens,outputTokens:c.output_tokens,costNanoUsd:c.cost_nano_usd,usd:c.usd,unpriced:c.unpriced,final:c.final,runs:c.runs.map(hn)};return c.advisor&&(g.advisor={inputTokens:c.advisor.input_tokens,outputTokens:c.advisor.output_tokens,cacheReadTokens:c.advisor.cache_read_tokens,cacheWriteTokens:c.advisor.cache_write_tokens,costNanoUsd:c.advisor.cost_nano_usd,usd:c.advisor.usd,unpriced:c.advisor.unpriced}),g},async artifacts(r,n,a={}){return(await t.listChatTurnArtifacts({path:{chat_id:r,response_id:n},signal:a.signal})).data.artifacts.map(g=>({id:g.id,mediaType:g.media_type,...g.logical_type?{logicalType:g.logical_type}:{},sizeBytes:g.size_bytes,checksum:g.checksum,createdAt:g.created_at}))},async artifact(r,n,a,c={}){return(await t.getChatTurnArtifact({path:{chat_id:r,response_id:n,artifact_id:a},signal:c.signal})).data},async messages(r,n={}){let a=(await t.listChatMessages({path:{chat_id:r},query:{limit:n.limit,cursor:n.cursor},signal:n.signal})).data;return a.next_cursor===void 0?{messages:a.messages}:{messages:a.messages,nextCursor:a.next_cursor}},async parts(r,n={}){if(n.cursor!==void 0&&n.before!==void 0)throw new TypeError("chats.parts: cursor (where a page left off) or before (the oldest part the app's channel holds, by its id), not both");if(n.before!==void 0&&(!Number.isSafeInteger(n.before)||n.before<1))throw new TypeError(`chats.parts: before is a part's id \u2014 its journal sequence, a whole number from 1 (got ${String(n.before)})`);if(n.limit!==void 0&&n.turns!==void 0)throw new TypeError("chats.parts: limit (events) or turns (turns), not both");if(n.turns!==void 0&&(!Number.isSafeInteger(n.turns)||n.turns<1||n.turns>20))throw new TypeError(`chats.parts: turns is how many of the chat's turns a page reads back to, 1 to 20 (got ${String(n.turns)})`);let a=(await t.listChatParts({path:{chat_id:r},query:{limit:n.limit,turns:n.turns,cursor:n.cursor,before:n.before},signal:n.signal})).data;return{parts:a.parts.map(g=>({type:g.type,...g.id!==void 0?{id:g.id}:{},partId:g.part_id,data:g.data})),...a.next_cursor!==void 0?{nextCursor:a.next_cursor}:{},...a.turns!==void 0?{turns:a.turns}:{}}},async toolCall(r,n,a={}){let c=(await t.getChatToolCall({path:{chat_id:r,call_id:n},signal:a.signal})).data;return{callId:c.call_id,name:c.name,status:c.status,runId:c.run_id,responseId:c.response_id,input:c.input,output:c.output,outputBytes:c.output_bytes,imageCount:c.image_count,isError:c.is_error}},async toolCalls(r,n){if(typeof n?.turn!="string"||n.turn==="")throw new TypeError("chats.toolCalls: turn is the turn's responseId \u2014 a message's, or a turn's or an agent part's");let a=(await t.listTurnToolCalls({path:{chat_id:r},query:{turn:n.turn,limit:n.limit,cursor:n.cursor},signal:n.signal})).data,c=a.tool_calls.map(g=>({callId:g.call_id,name:g.name,state:g.state,createdAt:g.created_at,updatedAt:g.updated_at,arguments:g.arguments,...g.result!==void 0?{result:g.result}:{}}));return a.next_cursor===void 0?{toolCalls:c}:{toolCalls:c,nextCursor:a.next_cursor}},workspace:{async file(r,n,a={}){if(typeof n!="string"||n==="")throw new TypeError("chats.workspace.file: path is the file as the workspace's tree names it (repo/output/app/App.zip)");return(await t.getChatWorkspaceFile({path:{chat_id:r},query:{path:n,...a.manifest!==void 0?{manifest:a.manifest}:{}},signal:a.signal})).data},async addRepo(r,n){let a=typeof n?.repo=="string"?n.repo:n?.repo?.name;if(typeof a!="string"||!v.test(a))throw new TypeError("chats.workspace.addRepo: repo is the project's name for the repository (ai.repos.put), or its ai.repo");let c={repo:a};return n.branch!==void 0&&(c.branch=n.branch),(await t.addChatWorkspaceRepo({path:{chat_id:r},body:c,signal:n.signal})).data},async write(r,n,a,c={}){ft(n,"chats.workspace.write");let g=await mn(a,"chats.workspace.write"),_=await t.putChatWorkspaceFile({path:{chat_id:r},query:{path:n},body:g,...c.contentType!==void 0?{contentType:c.contentType}:{},signal:c.signal});return mt(_.data)},async remove(r,n,a={}){return ft(n,"chats.workspace.remove"),mt((await t.deleteChatWorkspaceFile({path:{chat_id:r},query:{path:n},signal:a.signal})).data)},tokens:{async create(r,n){if(n?.access!=="read"&&n?.access!=="write")throw new TypeError("chats.workspace.tokens.create: access is read (the workspace followed) or write (followed and written, both ways)");let a={access:n.access};if(n.ttlSeconds!==void 0){if(!Number.isSafeInteger(n.ttlSeconds)||n.ttlSeconds<1||n.ttlSeconds>yt)throw new TypeError(`chats.workspace.tokens.create: ttlSeconds is how long it lives, 1 to ${yt} seconds (got ${String(n.ttlSeconds)})`);a.ttl_seconds=n.ttlSeconds}if(n.label!==void 0){if(!te(n.label))throw new TypeError(`chats.workspace.tokens.create: label is what it is for \u2014 the machine's name \u2014 ${ee}`);a.label=n.label}let c=(await t.createChatWorkspaceToken({path:{chat_id:r},body:a,signal:n.signal})).data;return{...ht(c),token:c.token,syncUrl:c.sync_url}},async list(r,n={}){return(await t.listChatWorkspaceTokens({path:{chat_id:r},signal:n.signal})).data.tokens.map(ht)},async revoke(r,n,a={}){if(typeof n!="string"||n==="")throw new TypeError("chats.workspace.tokens.revoke: tokenId is the token's id (tokens.list)");await t.revokeChatWorkspaceToken({path:{chat_id:r,token:n},signal:a.signal})}}},events(r){if(typeof r!="string"||!/^chat_[0-9a-f]{32}$/.test(r))throw new TypeError(`chats.events(id): a chat's id, chat_ and 32 hex digits (got ${JSON.stringify(r)})`);return Object.freeze({kind:"ai.chat",chatId:r,async pipe(n,a={}){await t.putChatPipe({path:{chat_id:r},body:{topic:n},signal:a.signal})},async unpipe(n={}){await t.deleteChatPipe({path:{chat_id:r},signal:n.signal})}})},async stop(r,n={}){return(await t.stopChat({path:{chat_id:r},...n.as!==void 0?{body:{as:n.as}}:{},signal:n.signal})).data.stopped},async approve(r,n,a={}){return(await t.decideChatApproval({path:{chat_id:r,approval_id:n},body:at(!0,a)})).data},async deny(r,n,a={}){return(await t.decideChatApproval({path:{chat_id:r,approval_id:n},body:at(!1,a)})).data},async answer(r,n,a,c={}){let g={output:z(a)};c.isError&&(g.is_error=!0),c.as!==void 0&&(g.as=c.as),c.workspaceTree!==void 0&&(g.workspace_tree=F(c.workspaceTree,"chats.answer"));try{return await se(()=>t.answerChatToolCall({path:{chat_id:r,call_id:n},body:g})),!0}catch(_){if(_ instanceof P&&_.status===409)return!1;throw _}},async sendToSubagent(r,n,a,c={}){let g={client_id:c.clientId??ct(),text:a};c.as!==void 0&&(g.as=c.as);let _=await se(async()=>(await t.sendSubagentMessage({path:{chat_id:r,run_id:n},body:g})).data);return{runId:_.run_id,clientId:_.client_id}},async stopSubagent(r,n,a={}){return{runId:(await se(async()=>(await t.stopSubagent({path:{chat_id:r,run_id:n},body:a.as!==void 0?{as:a.as}:{},signal:a.signal})).data,a.signal)).run_id}},async fork(r,n){if(typeof n?.beforeMessage!="string"||n.beforeMessage==="")throw new TypeError("chats.fork: beforeMessage is the id of the message the fork is cut before (a message's id, msg_\u2026)");let a={before_message:n.beforeMessage};return n.title!==void 0&&(a.title=n.title),n.members!==void 0&&(a.members=n.members.map(lt)),(await t.forkChat({path:{chat_id:r},body:a,signal:n.signal})).data},goal:{async set(r,n){let a={objective:n.objective};return n.rubric!==void 0&&(a.rubric=n.rubric),n.maxTurns!==void 0&&(a.max_turns=n.maxTurns),n.budget!==void 0&&(a.budget={max_cost_usd:n.budget.maxCostUsd}),n.as!==void 0&&(a.as=n.as),me((await t.setChatGoal({path:{chat_id:r},body:a,signal:n.signal})).data)},async get(r,n={}){return me((await t.getChatGoal({path:{chat_id:r},query:n.as!==void 0?{as:n.as}:void 0,signal:n.signal})).data)},async update(r,n){let a={};return n.status!==void 0&&(a.status=n.status),n.reason!==void 0&&(a.reason=n.reason),n.objective!==void 0&&(a.objective=n.objective),n.rubric!==void 0&&(a.rubric=n.rubric),n.maxTurns!==void 0&&(a.max_turns=n.maxTurns),n.budget!==void 0&&(a.budget=n.budget===null?null:{max_cost_usd:n.budget.maxCostUsd}),n.as!==void 0&&(a.as=n.as),me((await t.updateChatGoal({path:{chat_id:r},body:a,signal:n.signal})).data)},async clear(r,n={}){await t.clearChatGoal({path:{chat_id:r},query:n.as!==void 0?{as:n.as}:void 0,signal:n.signal})}},voice:{async start(r,n){if(typeof n?.sdp!="string"||!n.sdp.startsWith("v="))throw new TypeError("chats.voice.start: sdp is the app's WebRTC offer (an SDP, v=0 \u2026): its peer connection's localDescription.sdp");if(n.delegation!==void 0&&n.delegation!=="chat"&&n.delegation!=="events")throw new TypeError("chats.voice.start: delegation is chat (a turn of the chat) or events (ai.voice.delegated)");let a={sdp:n.sdp};n.voice!==void 0&&(a.voice=n.voice),n.delegation!==void 0&&(a.delegation=n.delegation),n.as!==void 0&&(a.as=n.as),n.instructions!==void 0&&(a.instructions=n.instructions),n.context!==void 0&&(a.context=n.context);let c=(await t.startChatVoice({path:{chat_id:r},body:a,signal:n.signal})).data;if(typeof c.sdp!="string"||c.sdp==="")throw new P({op:"startChatVoice",status:502,code:"no_answer",message:"the voice was started but its WebRTC answer was not given"});return{...re(c),sdp:c.sdp}},async get(r,n,a={}){return re((await t.getChatVoice({path:{chat_id:r,voice_id:n},query:a.as!==void 0?{as:a.as}:void 0,signal:a.signal})).data)},async command(r,n,a){if(!pn.includes(a?.type))throw new TypeError("chats.voice.command: type is speak (say this exactly), tell (say it in your own words), know (keep it in mind) or instruct (behave so)");if(typeof a.text!="string"||a.text==="")throw new TypeError("chats.voice.command: text is what the voice is given");if(a.delegationId!==void 0&&a.type!=="speak"&&a.type!=="tell")throw new TypeError("chats.voice.command: delegationId names the request a speak or a tell answers");if(a.interrupt!==void 0&&(typeof a.interrupt!="boolean"||a.type!=="speak"))throw new TypeError("chats.voice.command: interrupt is a speak's: it cuts what the voice is saying");let c={type:a.type,text:a.text};return a.delegationId!==void 0&&(c.delegation_id=a.delegationId),a.interrupt===!0&&(c.interrupt=!0),a.as!==void 0&&(c.as=a.as),re((await t.commandChatVoice({path:{chat_id:r,voice_id:n},body:c,signal:a.signal})).data)},async close(r,n,a={}){return re((await t.closeChatVoice({path:{chat_id:r,voice_id:n},query:a.as!==void 0?{as:a.as}:void 0,signal:a.signal})).data)}}},s={async list(r={}){return(await t.listAgents({signal:r.signal})).data.agents},async get(r,n={}){return(await t.getAgent({path:{name:W(r,"agents.get")},signal:n.signal})).data},async saveDraft(r,n,a={}){let c=`agents.saveDraft(${JSON.stringify(r)})`;if(W(r,"agents.saveDraft"),X(n))throw new TypeError(`${c}: a backend's ai.agent is its code's \u2014 its build's contract names it, and its chats ask its machine; it has no draft to save`);if(n===void 0)throw new TypeError(`${c}: its definition \u2014 { instructions, model, tools, \u2026 }`);let g=ne(n,c);return(await t.putAgent({path:{name:r},...a.revision!==void 0?{query:{revision:ot(a.revision,c)}}:{},body:g,signal:a.signal})).data},async publish(r,n={}){let a=`agents.publish(${JSON.stringify(r)})`;W(r,"agents.publish");let c=n.revision!==void 0?{revision:ot(n.revision,a)}:{};return(await t.publishAgent({path:{name:r},body:c,signal:n.signal})).data},async rollback(r,n,a={}){if(W(r,"agents.rollback"),!Number.isSafeInteger(n)||n<1)throw new TypeError(`agents.rollback(${JSON.stringify(r)}): version is one it had \u2014 a whole number from 1 (got ${String(n)})`);return(await t.rollbackAgent({path:{name:r},body:{version:n},signal:a.signal})).data},async versions(r,n={}){W(r,"agents.versions");let a=(await t.listAgentVersions({path:{name:r},query:{limit:n.limit,cursor:n.cursor},signal:n.signal})).data;return a.next_cursor===void 0?{versions:a.versions,publishedVersion:a.published_version}:{versions:a.versions,publishedVersion:a.published_version,nextCursor:a.next_cursor}},async delete(r,n={}){await t.deleteAgent({path:{name:W(r,"agents.delete")},signal:n.signal})},async tools(r={}){return(await t.listTools({signal:r.signal})).data.tools}},i={async put(r,n){let a={kind:n.kind,url:n.url};if(n.description!==void 0&&(a.description=n.description),n.parameters!==void 0&&(a.parameters=n.parameters),n.approval!==void 0&&(a.approval=n.approval),n.workspace!==void 0){if(typeof n.workspace!="boolean")throw new TypeError("endpoints.put: workspace is true for an endpoint of the project's own that reads or writes a chat's workspace, false (the default) for any other");a.workspace=n.workspace}return(await t.putEndpoint({path:{name:r},body:a})).data},async list(){return(await t.listEndpoints({})).data.endpoints},async delete(r){await t.deleteEndpoint({path:{name:r}})}},d={async get(){return wt((await t.getSettings({})).data)},async put(r){let n={};return r.clients!==void 0&&(n.clients=r.clients),r.userMessagesPerMinute!==void 0&&(n.user_messages_per_minute=r.userMessagesPerMinute),r.historyLimitBytes!==void 0&&(n.history_limit_bytes=r.historyLimitBytes),wt((await t.putSettings({body:n})).data)}},l=r=>({name:r.name,repository:r.repository,defaultBranch:r.default_branch,backend:r.backend,createdAt:r.created_at});return{chats:o,agents:s,endpoints:i,settings:d,repos:{async put(r,n){let a=typeof r=="string"?r:r.name;if(typeof a!="string"||!v.test(a))throw new TypeError("repos.put: name is lowercase letters, digits, _ and -, starting with a letter, at most 64");let c=typeof r=="string"?{repository:n?.repository??"",...n?.defaultBranch?{default_branch:n.defaultBranch}:{},...n?.backend?{backend:n.backend}:{}}:{repository:r.repository,default_branch:r.defaultBranch,...r.machine?{backend:r.machine}:{}};return l((await t.putRepo({path:{name:a},body:c})).data)},async list(r={}){let n=(await t.listRepos({query:{limit:r.limit,cursor:r.cursor}})).data,a=n.repos.map(l);return n.next_cursor===void 0?{repos:a}:{repos:a,nextCursor:n.next_cursor}},async delete(r){await t.deleteRepo({path:{name:r}})}}}}function O(e,t,o){if(typeof e!="string"||!Q.test(e))throw new TypeError(`${t}: ${o} (got ${JSON.stringify(e)})`);return e}var oe="the pool is one of the project's runner pools, by its id or its name",ye="the machine is a pool's machine by its id (pools.state(pool).machines)";function kt(e){return{id:e.id,name:e.name,os:e.os,arch:e.arch,...e.created_at!==void 0?{createdAt:e.created_at}:{},...e.machines!==void 0?{machines:e.machines}:{},...e.capacity_total!==void 0?{capacityTotal:e.capacity_total}:{},...e.capacity_used!==void 0?{capacityUsed:e.capacity_used}:{},...e.waiting!==void 0?{waiting:e.waiting}:{}}}function Tt(e){return{id:e.id,...e.label?{label:e.label}:{},...e.created_at!==void 0?{createdAt:e.created_at}:{},...e.expires_at!==void 0?{expiresAt:e.expires_at}:{},...e.last_used_at?{lastUsedAt:e.last_used_at}:{},...e.revoked_at?{revokedAt:e.revoked_at}:{}}}function wn(e){return{id:e.id,state:e.state,capacity:e.capacity,used:e.used,...e.label?{label:e.label}:{},...e.os?{os:e.os}:{},...e.arch?{arch:e.arch}:{},idleSince:e.idle_since??null,lastSeenAt:e.last_seen_at??null,registeredAt:e.registered_at??null}}var St=e=>({key:e.key,secret:e.secret,updatedAt:e.updated_at});function At(e,t){if(!ge(e))throw new TypeError(`${t}: ${JSON.stringify(typeof e=="string"?e.slice(0,140):e)} is no variable's name \u2014 upper-case letters, digits and _, a letter first, at most 128, and not PALAI_\u2026, the engine's own`);return e}function xt(e){return{pools:{async create(i){if(typeof i?.name!="string"||!v.test(i.name))throw new TypeError("pools.create: name is lowercase letters, digits, _ and -, a letter first, at most 64 \u2014 the project's once");if(i.os!=="linux"&&i.os!=="macos")throw new TypeError("pools.create: os is its machines' operating system, linux or macos (a pool is of one type)");if(i.arch!=="amd64"&&i.arch!=="arm64")throw new TypeError("pools.create: arch is its machines' architecture, amd64 or arm64 (a pool is of one type)");return kt((await e.createPool({body:{name:i.name,os:i.os,arch:i.arch},signal:i.signal})).data)},async list(i={}){return(await e.listPools({signal:i.signal})).data.pools.map(kt)},async delete(i,d={}){await e.deletePool({path:{pool:O(i,"pools.delete",oe)},signal:d.signal})},async state(i,d={}){let l=(await e.getPoolState({path:{pool:O(i,"pools.state",oe)},signal:d.signal})).data;return{pool:{id:l.pool.id,name:l.pool.name,os:l.pool.os,arch:l.pool.arch},capacityTotal:l.capacity_total,capacityUsed:l.capacity_used,waiting:l.waiting,oldestWaitingSince:l.oldest_waiting_since??null,machines:l.machines.map(wn)}},keys:{async create(i,d={}){let l={};if(d.label!==void 0){if(!te(d.label))throw new TypeError(`pools.keys.create: label is what the key is for, ${ee}`);l.label=d.label}let p=(await e.createPoolKey({path:{pool:O(i,"pools.keys.create",oe)},body:l,signal:d.signal})).data;if(typeof p.key!="string"||p.key==="")throw new P({op:"createPoolKey",status:502,code:"no_key",message:`the key ${p.id} was minted but not said: revoke it (pools.keys.revoke) and mint another`});return{...Tt(p),key:p.key,...p.enroll_url?{enrollUrl:p.enroll_url}:{},...p.enroll?{enroll:{url:p.enroll.url,...p.enroll.server_name?{serverName:p.enroll.server_name}:{},...p.enroll.ca_certificate?{caCertificate:p.enroll.ca_certificate}:{}}}:{}}},async list(i,d={}){return(await e.listPoolKeys({path:{pool:O(i,"pools.keys.list",oe)},signal:d.signal})).data.keys.map(Tt)},async revoke(i,d={}){await e.revokePoolKey({path:{key:O(i,"pools.keys.revoke","the key is a pool's key by its id (pools.keys.list)")},signal:d.signal})}}},machines:{async cordon(i,d={}){await e.cordonMachine({path:{machine:O(i,"machines.cordon",ye)},signal:d.signal})},async resume(i,d={}){await e.resumeMachine({path:{machine:O(i,"machines.resume",ye)},signal:d.signal})},async delete(i,d={}){await e.deleteMachine({path:{machine:O(i,"machines.delete",ye)},signal:d.signal})}},env:{async set(i,d,l={}){if(At(i,"env.set"),typeof d!="string"||d===""||new TextEncoder().encode(d).byteLength>J||d.includes("\0"))throw new TypeError(`env.set(${JSON.stringify(i)}): the value is text of 1 to ${J} bytes, no NUL`);if(l.secret!==void 0&&typeof l.secret!="boolean")throw new TypeError(`env.set(${JSON.stringify(i)}): secret is true (the default) or false`);let p={value:d};return l.secret!==void 0&&(p.secret=l.secret),St((await e.putEnv({path:{key:i},body:p,signal:l.signal})).data)},async unset(i,d={}){await e.deleteEnv({path:{key:At(i,"env.unset")},signal:d.signal})},async list(i={}){return(await e.listEnv({signal:i.signal})).data.variables.map(St)}}}}var bn=/^pb_[a-z0-9]+_s/;function vt(e){let t=globalThis;return t.process?.env?.[e]??t.Deno?.env?.get(e)}function we(){return"ai_"+crypto.randomUUID()}function be(e){if(e.prepared)return e;let t=e;return{name:"answer",schema:t,prepared:B(t,"answer")}}var _t=4,kn=/^[a-z][a-z0-9-]{1,62}$/,Et=["image/png","image/jpeg","image/webp","image/gif"],Pt=5<<20,Rt=6<<20;function Ot(e){let t="";for(let o=0;o<e.length;o+=32768)t+=String.fromCharCode(...e.subarray(o,o+32768));return btoa(t)}function Tn(e){return e.length%4!==0||!/^[A-Za-z0-9+/]*={0,2}$/.test(e)?-1:e.length/4*3-(e.endsWith("==")?2:e.endsWith("=")?1:0)}function Sn(e){if(!Array.isArray(e))throw new TypeError("images is a list of { bucket, path } (a file of the project's storage), { url } (an https address) or { mediaType, data } (its bytes)");if(e.length>_t)throw new TypeError(`a question takes ${_t} pictures at most (got ${e.length})`);let t=0;return e.map((o,s)=>{let i=o??{};if("bytes"in i||o instanceof Uint8Array)throw new TypeError(`images[${s}]: a picture's bytes are { mediaType, data } \u2014 or, in the project's storage, { bucket, path }`);if("data"in i||"mediaType"in i){if(i.bucket!==void 0||i.path!==void 0||i.url!==void 0)throw new TypeError(`images[${s}] is { bucket, path }, { url } or { mediaType, data }: one of them`);if(typeof i.mediaType!="string"||!Et.includes(i.mediaType))throw new TypeError(`images[${s}].mediaType is the picture's type: ${Et.join(", ")}`);let d=i.data instanceof Uint8Array?Ot(i.data):i.data,l=typeof d=="string"?Tn(d):-1;if(l<0)throw new TypeError(`images[${s}].data is the picture's bytes: base64, or a Uint8Array`);if(l===0||l>Pt)throw new TypeError(`images[${s}] is ${l} bytes: a picture given by its bytes is 1 byte to ${Pt>>20} MiB`);if(t+=l,t>Rt)throw new TypeError(`the pictures given by their bytes are ${Rt>>20} MiB at most together: put a larger one in the project's storage and give { bucket, path }`);return{media_type:i.mediaType,data:d}}if(typeof i.url=="string"){if(i.bucket!==void 0||i.path!==void 0)throw new TypeError(`images[${s}] is { bucket, path } or { url }, not both`);let d;try{d=new URL(i.url)}catch{throw new TypeError(`images[${s}].url is not an address: ${JSON.stringify(i.url.slice(0,80))}`)}if(d.protocol!=="https:"||i.url.length>2048)throw new TypeError(`images[${s}].url is an https address of 2048 characters at most`);return{url:i.url}}if(typeof i.bucket!="string"||!kn.test(i.bucket)||typeof i.path!="string"||i.path==="")throw new TypeError(`images[${s}] is { bucket, path } \u2014 a file of the project's storage \u2014 { url } or { mediaType, data }`);return{bucket:i.bucket,path:i.path}})}var An=/^[a-z][a-z0-9_-]{0,63}(@[1-9][0-9]{0,8})?$/;function Mt(e){let t=typeof e=="string"?e:X(e)?.name;if(typeof t!="string"||!An.test(t))throw new TypeError(`agent is one of the project's agents by name (support), name@N for its version N (support@3), or a backend's ai.agent (got ${JSON.stringify(typeof e=="string"?e:typeof e)})`);return t}function Z(e,t={},o){if(e.prompt===void 0&&e.messages===void 0)throw new TypeError("ask a model something: prompt, or messages");let s={...t};if(e.agent!==void 0&&(s.agent=Mt(e.agent)),e.prompt!==void 0&&(s.input=e.prompt),e.messages!==void 0&&(s.messages=e.messages),e.instructions!==void 0&&(s.instructions=e.instructions),e.model!==void 0&&(s.model=e.model),e.metadata!==void 0&&(s.metadata=e.metadata),e.images!==void 0&&(s.images=Sn(e.images)),e.tools!==void 0&&(s.tools=e.tools.map((i,d)=>{if(i?.source==="client")throw new TypeError(`tools[${d}]: ${i.name} is a client tool \u2014 an app answers it, in a chat; a one-shot answer has no app to wait for`);if(i?.source==="platform")throw new TypeError(`tools[${d}]: the platform's ${i.name} is a chat's agent's tool \u2014 a one-shot answer is given none`);let l=K(i,`tools[${d}]`);return l.source==="backend"&&l.machine===void 0&&o!==void 0&&(l.machine=o),l})),e.maxToolCalls!==void 0){if(!e.tools?.length)throw new TypeError("maxToolCalls bounds the calls of the tools given: give tools");s.max_tool_calls=fe(e.maxToolCalls,"ask")}return s}function Ct(e,t){if(e.output===null||e.output===void 0)throw new w(t,"the answer is text, not a document: the agent has no output (the shape of its one-shot answers) \u2014 give it one, give generate a schema, or ask() it");return e.output}var C=class extends Error{code;response;constructor(t){super(t.error?.message??`the response ended ${t.status}`),this.name="AIResponseError",this.code=t.error?.code??t.status,this.response=t}};function xn(e){let t=Uint8Array.from(atob(e),i=>i.charCodeAt(0)),o=new DataView(t.buffer,t.byteOffset,t.byteLength),s=new Array(t.byteLength/4);for(let i=0;i<s.length;i++)s[i]=o.getFloat32(i*4,!0);return s}async function It(e){let t,o;return e instanceof Uint8Array?(t=e,o=$t(t)):typeof Blob<"u"&&e instanceof Blob?(t=new Uint8Array(await e.arrayBuffer()),o=e.type||$t(t)):(t=e.bytes,o=e.mediaType),{media_type:o,data:Ot(t)}}function $t(e){return e[0]===137&&e[1]===80?"image/png":e[0]===255&&e[1]===216?"image/jpeg":e[8]===87&&e[9]===69&&e[10]===66&&e[11]===80?"image/webp":"application/octet-stream"}function vn(e){let t=e.url??vt("PALBASE_URL"),o=e.secretKey??vt("PALBASE_SECRET_KEY");if(typeof t!="string"||t==="")throw new TypeError("url is the project address (https://<ref>.<domain>) \u2014 or set PALBASE_URL");if(typeof o!="string"||!bn.test(o))throw new TypeError("secretKey is the project secret key (pb_<ref>_s\u2026) \u2014 or set PALBASE_SECRET_KEY; a model call is billed to the project, so it is never made with a publishable key");let s=ve(Se({baseUrl:t,credentials:{secretKey:o},fetch:e.fetch}),e.retry??xe);return Ae.client(s)}function _n(e){return new Proxy({},{get:(t,o)=>e.ai[o]})}function En(e={}){if(Ce())throw new TypeError("palbase/ai runs on a server: it speaks with the project secret key, which never goes into a browser or a mobile app \u2014 call your backend, and let it ask the model");if(e.machine!==void 0&&!v.test(e.machine))throw new TypeError("machine is the name of one of the project's machines");let t=e.server?_n(e.server):vn(e),o=e.resumeFor??12e4;async function s(u,f,h=we()){return j(t.createResponse({headers:{"Idempotency-Key":h},body:u,signal:f}))}async function i(u,f={}){return(await t.getResponse({path:{response_id:u},signal:f.signal})).data}async function d(u,f,h,S,y){let b=0,A=u,E=we(),D=()=>Date.now()+o,U=D();for(let L=0;;L++)try{if(A||(f===null?A=(await s({...y,stream:!0},S,E)).data:A=(await t.followResponse({path:{response_id:f},query:{offset:b},signal:S})).data),!A.body)throw new Error("the stream has no body");for await(let k of Ie(A.body)){let x=JSON.parse(k.data);switch(k.event){case"response":f===null&&(f=x.id,h.admitted(x));break;case"delta":{let M=x.offset+Ee(x.text);if(M>b){let ae=x.offset>=b?x.text:Re(x.text,b-x.offset);h.delta(b,ae),b=M}U=D();break}case"reset":x.offset<b&&(b=x.offset,h.reset(b));break;case"terminal":return x}}throw new Error("the stream ended before its answer did")}catch(k){if(A=null,S?.aborted||k instanceof P&&k.status>0&&k.status<500&&k.status!==429||f===null&&!(k instanceof P)||Date.now()>U)throw k;await new Promise(x=>setTimeout(x,Math.min(250*2**Math.min(L,4),4e3)))}}function l(u){if(u.status!=="completed")throw new C(u);return u.text??""}function p(u,f){let h=Z(u,f?{schema:f.prepared.json,schema_name:f.name}:{},e.machine),S=[],y=!1,b,A=null,E=()=>{let m=A;A=null,m?.()},D,U,L=new Promise((m,T)=>{D=m,U=T});L.catch(()=>{});let k="",x=d(null,null,{admitted:m=>D(m.id),delta:(m,T)=>{k+=T,S.push(T),E()},reset:m=>{let T=Pe(k,m);k=k.slice(0,T),S.push("\0reset:"+T),E()}},u.signal,h).then(m=>{let T=m.status==="completed"?m.text??"":"";return T.length>k.length&&T.startsWith(k)&&(S.push(T.slice(k.length)),k=T),y=!0,E(),m},m=>{throw y=!0,b=m,U(m),E(),m});x.catch(()=>{});async function*M(){for(let m=0;;m++){for(;m>=S.length;){if(y){if(b)throw b;return}await new Promise(T=>A=T)}yield S[m]}}async function*ae(){for await(let m of M())m.startsWith("\0reset:")||(yield m)}async function*Wt(){let m="",T="";for await(let V of M()){V.startsWith("\0reset:")?m=m.slice(0,Number(V.slice(7))):m+=V;let I=ce(m);if(I===void 0)continue;let $=JSON.stringify(I);$!==T&&(T=$,yield I)}}let q=x.then(m=>{if(m.status!=="completed")throw new C(m);return m});q.catch(()=>{});let ke=f?q.then(m=>f.prepared.check(m.output)):Promise.reject(new TypeError("object is a schema stream's"));ke.catch(()=>{});let Te=q.then(m=>m.text??k);return Te.catch(()=>{}),{id:L,response:q,text:Te,get textStream(){return ae()},get partialObjectStream(){return Wt()},object:ke,toResponse(m={}){let T=new TextEncoder,V=new ReadableStream({async start($){try{for await(let G of M())G.startsWith("\0reset:")?$.enqueue(T.encode(`event: reset
|
|
8
|
-
data: ${JSON.stringify({offset:Number(G.slice(7))})}
|
|
9
|
-
|
|
10
|
-
`)):$.enqueue(T.encode(`data: ${JSON.stringify({text:G})}
|
|
11
|
-
|
|
12
|
-
`));let R=await q;$.enqueue(T.encode(`event: done
|
|
13
|
-
data: ${JSON.stringify({id:R.id,text:R.text,output:R.output,usage:R.usage})}
|
|
14
|
-
|
|
15
|
-
`))}catch(R){let G=R instanceof C||R instanceof P?R.code:"stream_failed";$.enqueue(T.encode(`event: error
|
|
16
|
-
data: ${JSON.stringify({code:G})}
|
|
17
|
-
|
|
18
|
-
`))}finally{$.close()}}}),I=new Headers(m.headers);return I.set("content-type","text/event-stream"),I.set("cache-control","no-store"),I.set("x-accel-buffering","no"),new globalThis.Response(V,{...m,headers:I})}}}async function r(u,f){return d(null,null,{admitted:()=>{},delta:()=>{},reset:()=>{}},u.signal,Z(u,f,e.machine))}let{chats:n,agents:a,endpoints:c,settings:g,repos:_}=bt(t),{pools:jt,machines:Bt,env:Nt}=xt(t);return{module:t,chats:n,agents:a,endpoints:c,settings:g,repos:_,pools:jt,machines:Bt,env:Nt,tool:Qe,clientTool:et,deferred:Je,answer:Xe,agent:rt,repo:tt,repoTokens:nt,async ask(u,f={}){let h=typeof u=="string"?{...f,prompt:u}:u;return l(await r(h,{}))},async generate(u){if(u.schema===void 0){if(u.agent===void 0)throw new TypeError("generate: a schema \u2014 the answer's shape \u2014 or an agent whose output is");if(u.background){let A=(await s(Z(u,{background:!0},e.machine),u.signal)).data;return{id:A.id,status:A.status}}let y=await r(u,{});if(y.status!=="completed")throw new C(y);return Ct(y,Mt(u.agent))}let f=be(u.schema),h={schema:f.prepared.json,schema_name:f.name};if(u.background){let b=(await s(Z(u,{...h,background:!0},e.machine),u.signal)).data;return{id:b.id,status:b.status}}let S=await r(u,h);if(S.status!=="completed")throw new C(S);return f.prepared.check(S.output)},stream(u){return p(u,u.schema?be(u.schema):void 0)},async start(u){let f=(await s(Z(u,{background:!0},e.machine),u.signal)).data;return{id:f.id,status:f.status}},schema(u,f){return{name:u,schema:f,prepared:B(f,u)}},response:i,async result(u,f){let h=await i(u);if(h.status!=="completed")throw new C(h);return f===void 0?Ct(h,"the response"):be(f).prepared.check(h.output)},async cancel(u){return(await t.cancelResponse({path:{response_id:u}})).data},async embed(u,f={}){let h=Array.isArray(u)?u:[u],S=[];for(let y=0;y<h.length;y+=1024){let b=await j(t.createEmbeddings({body:{input:h.slice(y,y+1024),model:f.model,dimensions:f.dimensions},signal:f.signal}));for(let A of b.data.vectors)S.push(xn(A))}return Array.isArray(u)?S:S[0]},async image(u){let f={prompt:u.prompt};for(let y of["model","size","quality","background","format","count"])u[y]!==void 0&&(f[y]=u[y]);u.references?.length&&(f.references=await Promise.all(u.references.map(It))),u.mask&&(f.mask=await It(u.mask));let h=(await j(t.createImage({headers:{"Idempotency-Key":we()},body:f,signal:u.signal}))).data;for(let y=0;h.status==="running";y++){if(await new Promise(b=>setTimeout(b,Math.min(500+y*250,3e3))),u.signal?.aborted)throw u.signal.reason;h=(await t.getImage({path:{image_id:h.id},signal:u.signal})).data}if(h.status!=="completed")throw new Error(`the image failed: ${h.error?.code??"image_failed"}: ${h.error?.message??""}`);let S=await Promise.all(h.files.map(async y=>{let A=(await t.getImageFile({path:{image_id:h.id,position:y.position},signal:u.signal})).data;return{mediaType:y.media_type,bytes:new Uint8Array(await A.arrayBuffer())}}));return{id:h.id,model:h.model,pictures:S,costNanoUSD:h.usage?.cost_nano_usd??0,save(y,b,A=0){let E=S[A];if(!E)throw new RangeError(`the job made ${S.length} picture(s)`);return y.upload(b,E.bytes,{contentType:E.mediaType})}}},async models(){return(await t.listModels({})).data},async usage(u={}){let f=u.metadata===void 0?void 0:JSON.stringify(u.metadata),h=(await t.listUsage({query:{kind:u.kind,limit:u.limit,cursor:u.cursor,metadata:f}})).data;return{usage:h.usage,nextCursor:h.next_cursor}},async spend(u={}){return(await t.getSpend({signal:u.signal})).data},async connectProvider(u,f){return(await t.connectProvider({path:{provider:u},body:{key:f}})).data},async disconnectProvider(u){await t.disconnectProvider({path:{provider:u}})}}}export{ce as a,w as b,B as c,ue as d,C as e,En as f};
|