@onlyworlds/sdk 4.137.0 → 4.138.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/CHANGELOG.md +10 -0
- package/dist/index.d.ts +75 -2
- package/dist/index.js +76 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,16 @@ earlier history lives in git log only.
|
|
|
5
5
|
|
|
6
6
|
## [Unreleased]
|
|
7
7
|
|
|
8
|
+
## [4.138.0] - 2026-11-10
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- An AI door token: an `ow_a_` token that opens only `aiUses()` and the AI uses it names, as the person and on their token rating, until midnight UTC at the latest. Another use answers 403 `use_not_granted`, every other route 401 `wrong_audience`.
|
|
13
|
+
- `completeSignIn({ ..., aiUses, aiLifetimeMinutes })` asks the sign-in's code exchange for one beside the account token; the result's new `aiToken` (`OwAiToken`: `token`, `tokenId`, `tokenType`, `audience`, `aiUses`, `expiresAt`) carries it, and is null when none was asked or the server answered none. The exchange spends its code whatever it answers, so a list the SDK can see is wrong (not 1 to 8 names, a name that is not one path segment, a lifetime outside 1 to 1440 minutes or without `aiUses`) is refused before anything is sent and before the pending sign-in is touched. A name the server does not run is its 422, and the code is then spent. Both options are optional, and every field the result had stays as it was.
|
|
14
|
+
- `mintAiToken(uses, { lifetimeMinutes, name })`: `POST /account/tokens` with `ai_uses`, trading an account token down to an AI door token (`OwMintedAiToken`, the token's row with the token once). It belongs to the token that minted it: revoking that one revokes it too. The uses are required, so a call without them never reaches the route that would mint a full account token.
|
|
15
|
+
- `OwApiError.isUseNotGranted` (403 `use_not_granted`) and `isWrongAudience` (401 `wrong_audience`).
|
|
16
|
+
- `OwAccountToken.ai_uses`, on an `ai` token's row.
|
|
17
|
+
|
|
8
18
|
## [4.137.0] - 2026-11-09
|
|
9
19
|
|
|
10
20
|
### Added
|
package/dist/index.d.ts
CHANGED
|
@@ -3695,13 +3695,27 @@ interface OwAccountToken {
|
|
|
3695
3695
|
expires_at: string | null;
|
|
3696
3696
|
/** How many live world keys this token minted. */
|
|
3697
3697
|
keys_minted: number;
|
|
3698
|
-
/** Who the token is for: empty for a token made by hand or a sign-in tool's; `mcp` for a hosted client's grant on the MCP server. */
|
|
3698
|
+
/** Who the token is for: empty for a token made by hand or a sign-in tool's; `mcp` for a hosted client's grant on the MCP server; `ai` for an AI door token (mintAiToken, or the sign-in's `aiUses`). */
|
|
3699
3699
|
audience: string;
|
|
3700
|
+
/** On an `ai` token only: the AI uses it opens (`ai(use, …)`). */
|
|
3701
|
+
ai_uses?: string[];
|
|
3700
3702
|
/** On an `mcp` token only: the client's name, as it registered itself, or its id when it is no longer registered. */
|
|
3701
3703
|
client?: string;
|
|
3702
3704
|
/** On an `mcp` token only: the host the client returns the person to. */
|
|
3703
3705
|
return_host?: string;
|
|
3704
3706
|
}
|
|
3707
|
+
/**
|
|
3708
|
+
* An AI door token as minted by mintAiToken (POST /account/tokens with `ai_uses`): its row, as the
|
|
3709
|
+
* account's token list shows it, plus the token itself once in `token` (never shown again).
|
|
3710
|
+
*/
|
|
3711
|
+
interface OwMintedAiToken extends OwAccountToken {
|
|
3712
|
+
audience: 'ai';
|
|
3713
|
+
ai_uses: string[];
|
|
3714
|
+
/** When it stops working: midnight UTC at the latest. */
|
|
3715
|
+
expires_at: string;
|
|
3716
|
+
/** The `ow_a_` AI door token, shown only here. */
|
|
3717
|
+
token: string;
|
|
3718
|
+
}
|
|
3705
3719
|
interface OwSeat {
|
|
3706
3720
|
/** The seat's membership id: removeSeat takes it, and GET /members names the seat by it. */
|
|
3707
3721
|
id: string;
|
|
@@ -4221,6 +4235,16 @@ declare class OwApiError extends Error {
|
|
|
4221
4235
|
* with a ceiling runs one call at a time. Wait `retryAfter` seconds (a short wait) and send again.
|
|
4222
4236
|
*/
|
|
4223
4237
|
get isUseInFlight(): boolean;
|
|
4238
|
+
/**
|
|
4239
|
+
* ai: an AI door token called a use it was not minted for (403 `use_not_granted`, param `use`).
|
|
4240
|
+
* Nothing was counted. Mint one that names this use (mintAiToken), or call with an account token.
|
|
4241
|
+
*/
|
|
4242
|
+
get isUseNotGranted(): boolean;
|
|
4243
|
+
/**
|
|
4244
|
+
* The account token works on some routes only (401 `wrong_audience`): an AI door token on any route
|
|
4245
|
+
* but `aiUses()`, its uses and its own revoke, or a hosted MCP client's token anywhere but /mcp.
|
|
4246
|
+
*/
|
|
4247
|
+
get isWrongAudience(): boolean;
|
|
4224
4248
|
/** ask: the model gave no answer (502 `ask_failed`). Not counted; try again in a moment. */
|
|
4225
4249
|
get isAskFailed(): boolean;
|
|
4226
4250
|
/**
|
|
@@ -4433,6 +4457,34 @@ interface OwSignInComplete {
|
|
|
4433
4457
|
* the window's history is left alone.
|
|
4434
4458
|
*/
|
|
4435
4459
|
url?: string;
|
|
4460
|
+
/**
|
|
4461
|
+
* Also ask the exchange for an AI door token for these AI uses (their slugs, as `aiUses()` lists
|
|
4462
|
+
* them): 1 to 8, each one path segment. It comes back as `aiToken`. The exchange spends the code
|
|
4463
|
+
* whatever it answers, so a list the SDK can see is wrong is refused before anything is sent; a
|
|
4464
|
+
* name the server does not run is its 422, and then the code is spent.
|
|
4465
|
+
*/
|
|
4466
|
+
aiUses?: string[];
|
|
4467
|
+
/** With `aiUses` only: the AI door token ends this many minutes after the exchange (1 to 1440), or at midnight UTC if that comes first. */
|
|
4468
|
+
aiLifetimeMinutes?: number;
|
|
4469
|
+
}
|
|
4470
|
+
/**
|
|
4471
|
+
* An AI door token: an `ow_a_` token that opens only `aiUses()` and the AI uses it names (`ai()`),
|
|
4472
|
+
* as the person and on their token rating; another use answers 403 `use_not_granted`
|
|
4473
|
+
* (`err.isUseNotGranted`), every other route 401 `wrong_audience` (`err.isWrongAudience`). It ends at
|
|
4474
|
+
* `expiresAt` (midnight UTC at the latest), then answers 401 `key_revoked`. A client built on it may
|
|
4475
|
+
* revoke it with `revokeAccountToken(tokenId)`; revoking it touches no other token, and revoking the
|
|
4476
|
+
* account token beside it leaves it live.
|
|
4477
|
+
*/
|
|
4478
|
+
interface OwAiToken {
|
|
4479
|
+
/** The `ow_a_` AI door token, shown only here. */
|
|
4480
|
+
token: string;
|
|
4481
|
+
tokenId: string;
|
|
4482
|
+
tokenType: 'bearer';
|
|
4483
|
+
audience: 'ai';
|
|
4484
|
+
/** The uses it opens, as the server took them (each once, in the order sent). */
|
|
4485
|
+
aiUses: string[];
|
|
4486
|
+
/** When it stops working (ISO 8601). */
|
|
4487
|
+
expiresAt: string;
|
|
4436
4488
|
}
|
|
4437
4489
|
/** What `completeSignIn` returns: the account token, shown only here, and what the tool parked. */
|
|
4438
4490
|
interface OwSignInResult {
|
|
@@ -4455,6 +4507,11 @@ interface OwSignInResult {
|
|
|
4455
4507
|
};
|
|
4456
4508
|
/** The `resume` given to `beginSignIn`, or null. */
|
|
4457
4509
|
resume: unknown;
|
|
4510
|
+
/**
|
|
4511
|
+
* The AI door token, when `aiUses` asked for one; null when none was asked, and from a server that
|
|
4512
|
+
* answered none (the account token above is good either way).
|
|
4513
|
+
*/
|
|
4514
|
+
aiToken: OwAiToken | null;
|
|
4458
4515
|
}
|
|
4459
4516
|
/** Base64url without padding (RFC 4648 §5), as PKCE wants it. */
|
|
4460
4517
|
declare function base64url(bytes: Uint8Array): string;
|
|
@@ -5314,6 +5371,22 @@ declare class OwV2Client {
|
|
|
5314
5371
|
signal?: AbortSignal;
|
|
5315
5372
|
keepalive?: boolean;
|
|
5316
5373
|
}): Promise<void>;
|
|
5374
|
+
/**
|
|
5375
|
+
* POST /account/tokens with `ai_uses` -- trade this client's account token down to an AI door
|
|
5376
|
+
* token: an `ow_a_` token that opens only `aiUses()` and the uses named here (1 to 8, by slug, as
|
|
5377
|
+
* `aiUses()` lists them), as this account and on its token rating. Another use answers 403
|
|
5378
|
+
* `use_not_granted` (`err.isUseNotGranted`), every other route 401 `wrong_audience`
|
|
5379
|
+
* (`err.isWrongAudience`). It ends at midnight UTC, or `lifetimeMinutes` (1 to 1440) after the mint
|
|
5380
|
+
* if that comes first, then answers 401 `key_revoked`. It belongs to the token that minted it:
|
|
5381
|
+
* revoking this client's token revokes it too, while revoking it leaves this one live. A client
|
|
5382
|
+
* built on it revokes it with `revokeAccountToken(minted.id)`. The answer is the token's row with
|
|
5383
|
+
* the token itself, shown only here. A name the server does not run is a 422 (`err.code` `invalid_request`, `err.param` `ai_uses`).
|
|
5384
|
+
* Account token only; the AI door token itself mints nothing (401 `wrong_audience`).
|
|
5385
|
+
*/
|
|
5386
|
+
mintAiToken(uses: string[], opts?: {
|
|
5387
|
+
lifetimeMinutes?: number;
|
|
5388
|
+
name?: string;
|
|
5389
|
+
}): Promise<OwMintedAiToken>;
|
|
5317
5390
|
/**
|
|
5318
5391
|
* Start Sign in with OnlyWorlds from a tool's page: mint `state` and a PKCE verifier, keep them
|
|
5319
5392
|
* under `clientId` in `storage` (sessionStorage by default; in Node pass one), and send the
|
|
@@ -7471,4 +7544,4 @@ declare class TokenResource {
|
|
|
7471
7544
|
getEncryptionInfo(): Promise<EncryptionInfo>;
|
|
7472
7545
|
}
|
|
7473
7546
|
|
|
7474
|
-
export { AGENT_DOORS, ASK_LIMITS, type AccessKeyResponse, CALENDAR_FIELD, CALENDAR_SUPERTYPE, CHARTER_PAIRS, type CalendarConfig, type CalendarEra, type CalendarIntercalary, type CalendarMonths, type CalendarWeek, DATE_FIELD, ELEMENT_FAMILIES, ELEMENT_GROUPS, ELEMENT_ICONS, ELEMENT_LABELS, ELEMENT_SECTIONS, ELEMENT_TYPES, type ElementFamily, type ElementGroup, type ElementType, type EncryptionInfo, type EraDomain, FAMILY_COLORS, FAMILY_ORDER, FIELD_ACRONYMS, FIELD_SCHEMA, FILE_EXTENSIONS, type FieldInfo, type FieldType, GROUP_COLORS, GROUP_ORDER, GameTier, type ListParams, MESSAGE_PAIR, NOTE_PAIR, ONLYWORLDS_VERSION, type OwAccountToken, type OwAccountWorld, type OwAddress, OwAddressError, type OwAddressForm, type OwAddressReading, type OwAddressReason, type OwAddressingOptions, type OwAgentJoined, type OwAiAskAnswer, type OwAiAskBody, type OwAiMeter, type OwAiSortAnswer, type OwAiSortBody, type OwAiUse, type OwAllowance, OwApiError, type OwAskAnswer, type OwAskContext, type OwAskContextOptions, type OwAskLeftOut, type OwAuthErrorCode, type OwBulkItem, type OwBulkItemResult, type OwBulkResponse, type OwCalendarElement, type OwChange, type OwChangeDelete, type OwChangeUpsert, type OwChangesPage, type OwCharterWorld, type OwClientConfig, type OwCreateAccountWorldInput, type OwCreatedAccountWorld, type OwCreatedWorldLink, type OwDeleteReason, type OwDoor, type OwDragField, type OwDraught, type OwDraughtCompact, type OwDraughtComponent, type OwDraughtItem, type OwDraughtLens, type OwDraughtPolicy, type OwEdited, type OwElement, type OwElementBase, type OwElementMark, type OwErrorBody, type OwFileAddedBy, type OwFileDownload, type OwFileKind, type OwFileRow, type OwFileTicket, type OwFrontDoor, type OwGraphCutReason, type OwGraphEdge, type OwGraphMark, type OwGraphNode, type OwGraphOptions, type OwHiddenRow, type OwJoinPreview, type OwJoined, type OwJoinedMembership, type OwKeyKind, type OwLanding, type OwLandingCluster, type OwLandingGap, type OwLandingGapKind, type OwLandingMember, type OwLandingMode, type OwLandingOptions, type OwLensCutReason, type OwLensMail, type OwLensOptions, type OwLensReader, type OwLensReading, type OwLensWorld, type OwLinkEdit, type OwLookupElement, type OwLookupHit, type OwLookupLink, type OwLookupOptions, type OwLookupReason, type OwMapSpace, type OwMapSpaceMap, type OwMapSpaceOutReason, type OwMapSpaceOutline, type OwMapSpacePin, type OwMapSpacePoint, type OwMe, type OwMediaTicket, type OwMember, type OwMemberLenses, type OwMemberRole, type OwMessageMember, type OwMintedKey, type OwMySeat, type OwNamesMap, OwNetworkError, type OwOpener, type OwOpenerKind, type OwOpenerState, type OwOpenerSurface, type OwOpenersOptions, type OwPage, type OwPaidBy, type OwPhotoOptions, type OwPhotoPlan, type OwPlayerJoined, OwPreconditionFailedError, type OwPreparedPhoto, type OwProposal, type OwProposalAccepted, type OwProposalConflict, type OwProposalList, type OwProposalQuery, type OwProposalState, type OwProposeInput, type OwProposed, OwProposedError, type OwProposedMark, type OwProposedNewElement, type OwReadWorldFile, type OwReadWorldFileOptions, type OwReadingAids, type OwReadingAidsCharter, type OwReadingAidsDomain, type OwReadingAidsGuide, type OwReadingAidsHub, type OwRecord, type OwRecordMark, type OwRecordStory, type OwRemovalTicket, type OwRemovedImage, type OwRenderOptions, type OwResyncReason, type OwReviewInput, type OwReviewed, type OwSeat, type OwSeatCreated, type OwSender, type OwSenderStatus, type OwServedReadingAids, type OwSignInBegin, type OwSignInBegun, type OwSignInComplete, OwSignInError, type OwSignInReason, type OwSignInResult, type OwSignInStorage, type OwSignedIn, type OwSortAddToRow, type OwSortAnswer, type OwSortAskRow, type OwSortLinkRow, type OwSortMakeRow, type OwSortNote, type OwSortRef, type OwSortRow, OwStaleProposalError, type OwStrand, type OwStrandSlot, type OwStrandWorld, type OwTool, type OwToolNeeds, type OwToolOpen, type OwTrailGround, type OwTrailHanger, type OwTrailInput, type OwTrailLayout, type OwTrailPin, type OwTrailPlace, type OwTrailSettings, type OwTrailSpiral, type OwTrailTier, type OwUploadedFile, type OwUploadedImage, OwV2Client, type OwWordPair, type OwWorldFileEntry, OwWorldFileError, type OwWorldFileReason, type OwWorldFileRow, type OwWorldFiles, type OwWorldGraph, type OwWorldIndex, type OwWorldKeyMember, type OwWorldKeyRow, type OwWorldLens, type OwWorldLensReading, type OwWorldLenses, type OwWorldLink, type OwWorldMeta, type OwWorldOrigin, type OwWorldProducer, type OwWorldProposalList, type OwWorldProposalQuery, type OwWorldProposalRow, type OwWorldPublicPage, type OwWorldSource, type OwWriteDoor, type OwWriteWorldFileOptions, type OwWriteWorldFileReport, PHOTO_MAX_BYTES, PHOTO_TYPES, PROPOSED_MARK, PUBLIC_FIELDS, type ParseError, type ParseOptions, type ParseResult, RECORD_FIELD, REVIEW_PROPOSED_LABEL, ROOM_PAIRS, type RevokeAllSessionsResponse, type RevokeSessionResponse, SPATIAL_TYPES, STRAND_FIELD, type SectionInfo, type StepBreakdown, TOOLS, TRAIL_TIERS, type TokenConsumeParams, type TokenConsumeResponse, TokenResource, type TokenStatus, type TokenTransport, WORLD_FILE_MAX_BYTES, WORLD_FILE_MAX_ENTRIES, WORLD_FILE_MEDIA_TYPE, type WorldCalendar, absYearForEraYear, absoluteYear, approxYearLength, base64url, breakdownStep, buildAskContext, buildWorldIndex, charterOf, dateOf, degreeOf, detectKeyKind, displayYear, domainsOf, doorWhere, doorsOf, dragField, draughtText, editedBy, elementAddress, elementColor, eraForStep, errorFromResponse, familyOf, fieldLabel, fileKindOf, floorDiv, floorMod, formatDuration, formatMidLabel, formatStep, formatYearLabel, getElementIcon, getElementLabel, groupOf, handsOnAsProposed, hasUnseenRecipients, intercalaryInYear, isAddressedTo, isAgentDoor, isCharterElement, isDemoKey, isKnownOf, isLeapYear, isLens, isMessage, isNote, isParseError, isRoomElement, isSentBy, isTemplate, isToEveryone, kindCanWrite, landingOf, lensesInUse, lookupWorld, mapSpace, monthStartSteps, nfc, noteOf, openersFor, outDegreeOf, parseDate, parseErrorEnvelope, parseOwLink, pinExpectation, pkceChallenge, planPhoto, preparePhoto, proposedMarkOf, readCalendarConfig, readCalendarValue, readMarkOf, readWorldFile, readingAidOf, recipientsOf, recordMarkOf, recordsOf, renderElement, resolveCalendar, resolveCalendarLens, resolveEraDomains, resolveLens, roundHalfEven, senderStatus, simpleCaseFold, strandOf, threadOf, trailByPlace, typeWord, unreadFor, validateCalendarConfig, weekdayForStep, worldCalendars, worldGraph, writeWorldFile, yearLength, yearStartStep };
|
|
7547
|
+
export { AGENT_DOORS, ASK_LIMITS, type AccessKeyResponse, CALENDAR_FIELD, CALENDAR_SUPERTYPE, CHARTER_PAIRS, type CalendarConfig, type CalendarEra, type CalendarIntercalary, type CalendarMonths, type CalendarWeek, DATE_FIELD, ELEMENT_FAMILIES, ELEMENT_GROUPS, ELEMENT_ICONS, ELEMENT_LABELS, ELEMENT_SECTIONS, ELEMENT_TYPES, type ElementFamily, type ElementGroup, type ElementType, type EncryptionInfo, type EraDomain, FAMILY_COLORS, FAMILY_ORDER, FIELD_ACRONYMS, FIELD_SCHEMA, FILE_EXTENSIONS, type FieldInfo, type FieldType, GROUP_COLORS, GROUP_ORDER, GameTier, type ListParams, MESSAGE_PAIR, NOTE_PAIR, ONLYWORLDS_VERSION, type OwAccountToken, type OwAccountWorld, type OwAddress, OwAddressError, type OwAddressForm, type OwAddressReading, type OwAddressReason, type OwAddressingOptions, type OwAgentJoined, type OwAiAskAnswer, type OwAiAskBody, type OwAiMeter, type OwAiSortAnswer, type OwAiSortBody, type OwAiToken, type OwAiUse, type OwAllowance, OwApiError, type OwAskAnswer, type OwAskContext, type OwAskContextOptions, type OwAskLeftOut, type OwAuthErrorCode, type OwBulkItem, type OwBulkItemResult, type OwBulkResponse, type OwCalendarElement, type OwChange, type OwChangeDelete, type OwChangeUpsert, type OwChangesPage, type OwCharterWorld, type OwClientConfig, type OwCreateAccountWorldInput, type OwCreatedAccountWorld, type OwCreatedWorldLink, type OwDeleteReason, type OwDoor, type OwDragField, type OwDraught, type OwDraughtCompact, type OwDraughtComponent, type OwDraughtItem, type OwDraughtLens, type OwDraughtPolicy, type OwEdited, type OwElement, type OwElementBase, type OwElementMark, type OwErrorBody, type OwFileAddedBy, type OwFileDownload, type OwFileKind, type OwFileRow, type OwFileTicket, type OwFrontDoor, type OwGraphCutReason, type OwGraphEdge, type OwGraphMark, type OwGraphNode, type OwGraphOptions, type OwHiddenRow, type OwJoinPreview, type OwJoined, type OwJoinedMembership, type OwKeyKind, type OwLanding, type OwLandingCluster, type OwLandingGap, type OwLandingGapKind, type OwLandingMember, type OwLandingMode, type OwLandingOptions, type OwLensCutReason, type OwLensMail, type OwLensOptions, type OwLensReader, type OwLensReading, type OwLensWorld, type OwLinkEdit, type OwLookupElement, type OwLookupHit, type OwLookupLink, type OwLookupOptions, type OwLookupReason, type OwMapSpace, type OwMapSpaceMap, type OwMapSpaceOutReason, type OwMapSpaceOutline, type OwMapSpacePin, type OwMapSpacePoint, type OwMe, type OwMediaTicket, type OwMember, type OwMemberLenses, type OwMemberRole, type OwMessageMember, type OwMintedAiToken, type OwMintedKey, type OwMySeat, type OwNamesMap, OwNetworkError, type OwOpener, type OwOpenerKind, type OwOpenerState, type OwOpenerSurface, type OwOpenersOptions, type OwPage, type OwPaidBy, type OwPhotoOptions, type OwPhotoPlan, type OwPlayerJoined, OwPreconditionFailedError, type OwPreparedPhoto, type OwProposal, type OwProposalAccepted, type OwProposalConflict, type OwProposalList, type OwProposalQuery, type OwProposalState, type OwProposeInput, type OwProposed, OwProposedError, type OwProposedMark, type OwProposedNewElement, type OwReadWorldFile, type OwReadWorldFileOptions, type OwReadingAids, type OwReadingAidsCharter, type OwReadingAidsDomain, type OwReadingAidsGuide, type OwReadingAidsHub, type OwRecord, type OwRecordMark, type OwRecordStory, type OwRemovalTicket, type OwRemovedImage, type OwRenderOptions, type OwResyncReason, type OwReviewInput, type OwReviewed, type OwSeat, type OwSeatCreated, type OwSender, type OwSenderStatus, type OwServedReadingAids, type OwSignInBegin, type OwSignInBegun, type OwSignInComplete, OwSignInError, type OwSignInReason, type OwSignInResult, type OwSignInStorage, type OwSignedIn, type OwSortAddToRow, type OwSortAnswer, type OwSortAskRow, type OwSortLinkRow, type OwSortMakeRow, type OwSortNote, type OwSortRef, type OwSortRow, OwStaleProposalError, type OwStrand, type OwStrandSlot, type OwStrandWorld, type OwTool, type OwToolNeeds, type OwToolOpen, type OwTrailGround, type OwTrailHanger, type OwTrailInput, type OwTrailLayout, type OwTrailPin, type OwTrailPlace, type OwTrailSettings, type OwTrailSpiral, type OwTrailTier, type OwUploadedFile, type OwUploadedImage, OwV2Client, type OwWordPair, type OwWorldFileEntry, OwWorldFileError, type OwWorldFileReason, type OwWorldFileRow, type OwWorldFiles, type OwWorldGraph, type OwWorldIndex, type OwWorldKeyMember, type OwWorldKeyRow, type OwWorldLens, type OwWorldLensReading, type OwWorldLenses, type OwWorldLink, type OwWorldMeta, type OwWorldOrigin, type OwWorldProducer, type OwWorldProposalList, type OwWorldProposalQuery, type OwWorldProposalRow, type OwWorldPublicPage, type OwWorldSource, type OwWriteDoor, type OwWriteWorldFileOptions, type OwWriteWorldFileReport, PHOTO_MAX_BYTES, PHOTO_TYPES, PROPOSED_MARK, PUBLIC_FIELDS, type ParseError, type ParseOptions, type ParseResult, RECORD_FIELD, REVIEW_PROPOSED_LABEL, ROOM_PAIRS, type RevokeAllSessionsResponse, type RevokeSessionResponse, SPATIAL_TYPES, STRAND_FIELD, type SectionInfo, type StepBreakdown, TOOLS, TRAIL_TIERS, type TokenConsumeParams, type TokenConsumeResponse, TokenResource, type TokenStatus, type TokenTransport, WORLD_FILE_MAX_BYTES, WORLD_FILE_MAX_ENTRIES, WORLD_FILE_MEDIA_TYPE, type WorldCalendar, absYearForEraYear, absoluteYear, approxYearLength, base64url, breakdownStep, buildAskContext, buildWorldIndex, charterOf, dateOf, degreeOf, detectKeyKind, displayYear, domainsOf, doorWhere, doorsOf, dragField, draughtText, editedBy, elementAddress, elementColor, eraForStep, errorFromResponse, familyOf, fieldLabel, fileKindOf, floorDiv, floorMod, formatDuration, formatMidLabel, formatStep, formatYearLabel, getElementIcon, getElementLabel, groupOf, handsOnAsProposed, hasUnseenRecipients, intercalaryInYear, isAddressedTo, isAgentDoor, isCharterElement, isDemoKey, isKnownOf, isLeapYear, isLens, isMessage, isNote, isParseError, isRoomElement, isSentBy, isTemplate, isToEveryone, kindCanWrite, landingOf, lensesInUse, lookupWorld, mapSpace, monthStartSteps, nfc, noteOf, openersFor, outDegreeOf, parseDate, parseErrorEnvelope, parseOwLink, pinExpectation, pkceChallenge, planPhoto, preparePhoto, proposedMarkOf, readCalendarConfig, readCalendarValue, readMarkOf, readWorldFile, readingAidOf, recipientsOf, recordMarkOf, recordsOf, renderElement, resolveCalendar, resolveCalendarLens, resolveEraDomains, resolveLens, roundHalfEven, senderStatus, simpleCaseFold, strandOf, threadOf, trailByPlace, typeWord, unreadFor, validateCalendarConfig, weekdayForStep, worldCalendars, worldGraph, writeWorldFile, yearLength, yearStartStep };
|
package/dist/index.js
CHANGED
|
@@ -349,6 +349,20 @@ var OwApiError = class extends Error {
|
|
|
349
349
|
get isUseInFlight() {
|
|
350
350
|
return this.status === 429 && this.code === "use_in_flight";
|
|
351
351
|
}
|
|
352
|
+
/**
|
|
353
|
+
* ai: an AI door token called a use it was not minted for (403 `use_not_granted`, param `use`).
|
|
354
|
+
* Nothing was counted. Mint one that names this use (mintAiToken), or call with an account token.
|
|
355
|
+
*/
|
|
356
|
+
get isUseNotGranted() {
|
|
357
|
+
return this.status === 403 && this.code === "use_not_granted";
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* The account token works on some routes only (401 `wrong_audience`): an AI door token on any route
|
|
361
|
+
* but `aiUses()`, its uses and its own revoke, or a hosted MCP client's token anywhere but /mcp.
|
|
362
|
+
*/
|
|
363
|
+
get isWrongAudience() {
|
|
364
|
+
return this.status === 401 && this.code === "wrong_audience";
|
|
365
|
+
}
|
|
352
366
|
/** ask: the model gave no answer (502 `ask_failed`). Not counted; try again in a moment. */
|
|
353
367
|
get isAskFailed() {
|
|
354
368
|
return this.status === 502 && this.code === "ask_failed";
|
|
@@ -518,6 +532,36 @@ function pinExpectation(kind) {
|
|
|
518
532
|
}
|
|
519
533
|
|
|
520
534
|
// src/v2/oauth.ts
|
|
535
|
+
var AI_USES_MAX = 8;
|
|
536
|
+
var AI_LIFETIME_MAX_MINUTES = 1440;
|
|
537
|
+
var AI_USE_SLUG = /^[A-Za-z0-9][A-Za-z0-9_.-]*$/;
|
|
538
|
+
function aiTokenParams(method, uses, minutes) {
|
|
539
|
+
if (uses === void 0) {
|
|
540
|
+
if (minutes !== void 0) throw new TypeError(`${method}: the AI token's lifetime goes with its uses: send aiUses too. Nothing was sent.`);
|
|
541
|
+
return {};
|
|
542
|
+
}
|
|
543
|
+
if (!Array.isArray(uses) || uses.length < 1 || uses.length > AI_USES_MAX) {
|
|
544
|
+
throw new TypeError(`${method}: the AI uses are a list of 1 to ${AI_USES_MAX} use names, got ${JSON.stringify(uses)}. Nothing was sent.`);
|
|
545
|
+
}
|
|
546
|
+
for (const u of uses) {
|
|
547
|
+
if (typeof u !== "string" || !AI_USE_SLUG.test(u)) {
|
|
548
|
+
throw new TypeError(`${method}: ${JSON.stringify(u)} is not an AI use's name (one path segment, as aiUses() lists them). Nothing was sent.`);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
const body = { ai_uses: [...uses] };
|
|
552
|
+
if (minutes !== void 0) {
|
|
553
|
+
if (typeof minutes !== "number" || !Number.isInteger(minutes) || minutes < 1 || minutes > AI_LIFETIME_MAX_MINUTES) {
|
|
554
|
+
throw new TypeError(`${method}: the AI token's lifetime is a whole number of minutes, 1 to ${AI_LIFETIME_MAX_MINUTES}, got ${JSON.stringify(minutes)}. Nothing was sent.`);
|
|
555
|
+
}
|
|
556
|
+
body.ai_lifetime_minutes = minutes;
|
|
557
|
+
}
|
|
558
|
+
return body;
|
|
559
|
+
}
|
|
560
|
+
function readAiToken(v) {
|
|
561
|
+
const t = v;
|
|
562
|
+
if (!t || typeof t !== "object" || typeof t.token !== "string" || t.token === "" || typeof t.token_id !== "string" || t.token_id === "" || !Array.isArray(t.ai_uses) || !t.ai_uses.every((u) => typeof u === "string") || typeof t.expires_at !== "string" || t.expires_at === "") return null;
|
|
563
|
+
return { token: t.token, tokenId: t.token_id, tokenType: "bearer", audience: "ai", aiUses: [...t.ai_uses], expiresAt: t.expires_at };
|
|
564
|
+
}
|
|
521
565
|
var RECORD_PREFIX = "ow_signin:";
|
|
522
566
|
function defaultStorage(name) {
|
|
523
567
|
const ss = globalThis.sessionStorage;
|
|
@@ -646,6 +690,7 @@ function samePage(a, b) {
|
|
|
646
690
|
async function completeSignIn(baseUrl, fetchImpl, opts) {
|
|
647
691
|
const { clientId } = opts ?? {};
|
|
648
692
|
if (typeof clientId !== "string" || clientId === "") throw new TypeError("completeSignIn needs clientId");
|
|
693
|
+
const ai = aiTokenParams("completeSignIn", opts.aiUses, opts.aiLifetimeMinutes);
|
|
649
694
|
const storage = opts.storage ?? defaultStorage("completeSignIn");
|
|
650
695
|
const here = opts.url ?? globalThis.location?.href;
|
|
651
696
|
if (typeof here !== "string") throw new TypeError("completeSignIn: no location here; pass url (the callback page's address)");
|
|
@@ -694,7 +739,8 @@ async function completeSignIn(baseUrl, fetchImpl, opts) {
|
|
|
694
739
|
code,
|
|
695
740
|
code_verifier: record.verifier,
|
|
696
741
|
client_id: clientId,
|
|
697
|
-
redirect_uri: record.redirectUri
|
|
742
|
+
redirect_uri: record.redirectUri,
|
|
743
|
+
...ai
|
|
698
744
|
})
|
|
699
745
|
});
|
|
700
746
|
} catch {
|
|
@@ -726,7 +772,8 @@ async function completeSignIn(baseUrl, fetchImpl, opts) {
|
|
|
726
772
|
expiresAt: typeof ok.expires_at === "string" && ok.expires_at !== "" ? ok.expires_at : null,
|
|
727
773
|
tokenType: "bearer",
|
|
728
774
|
account: { id: ok.account.id, username: typeof ok.account.username === "string" ? ok.account.username : "" },
|
|
729
|
-
resume: record.resume ?? null
|
|
775
|
+
resume: record.resume ?? null,
|
|
776
|
+
aiToken: "ai_uses" in ai ? readAiToken(ok.ai_token) : null
|
|
730
777
|
};
|
|
731
778
|
}
|
|
732
779
|
|
|
@@ -2075,6 +2122,32 @@ var OwV2Client = class {
|
|
|
2075
2122
|
if (opts.keepalive !== void 0) send.keepalive = opts.keepalive;
|
|
2076
2123
|
await this.request("DELETE", `/account/tokens/${seg("tokenId", tokenId)}`, send);
|
|
2077
2124
|
}
|
|
2125
|
+
/**
|
|
2126
|
+
* POST /account/tokens with `ai_uses` -- trade this client's account token down to an AI door
|
|
2127
|
+
* token: an `ow_a_` token that opens only `aiUses()` and the uses named here (1 to 8, by slug, as
|
|
2128
|
+
* `aiUses()` lists them), as this account and on its token rating. Another use answers 403
|
|
2129
|
+
* `use_not_granted` (`err.isUseNotGranted`), every other route 401 `wrong_audience`
|
|
2130
|
+
* (`err.isWrongAudience`). It ends at midnight UTC, or `lifetimeMinutes` (1 to 1440) after the mint
|
|
2131
|
+
* if that comes first, then answers 401 `key_revoked`. It belongs to the token that minted it:
|
|
2132
|
+
* revoking this client's token revokes it too, while revoking it leaves this one live. A client
|
|
2133
|
+
* built on it revokes it with `revokeAccountToken(minted.id)`. The answer is the token's row with
|
|
2134
|
+
* the token itself, shown only here. A name the server does not run is a 422 (`err.code` `invalid_request`, `err.param` `ai_uses`).
|
|
2135
|
+
* Account token only; the AI door token itself mints nothing (401 `wrong_audience`).
|
|
2136
|
+
*/
|
|
2137
|
+
async mintAiToken(uses, opts = {}) {
|
|
2138
|
+
only("mintAiToken", opts, ["lifetimeMinutes", "name"]);
|
|
2139
|
+
if (this.keyKind !== "account") {
|
|
2140
|
+
throw new TypeError("mintAiToken needs an account token (ow_a_)");
|
|
2141
|
+
}
|
|
2142
|
+
const body = aiTokenParams("mintAiToken", uses ?? null, opts.lifetimeMinutes);
|
|
2143
|
+
if (opts.name !== void 0) {
|
|
2144
|
+
if (typeof opts.name !== "string" || opts.name.length > 255) {
|
|
2145
|
+
throw new TypeError(`mintAiToken: name is a string of at most 255 characters, got ${JSON.stringify(opts.name)}. Nothing was sent.`);
|
|
2146
|
+
}
|
|
2147
|
+
body.name = opts.name;
|
|
2148
|
+
}
|
|
2149
|
+
return this.request("POST", "/account/tokens", { body });
|
|
2150
|
+
}
|
|
2078
2151
|
// -- Sign in with OnlyWorlds (OAuth 2.1 code + PKCE) ----------------------
|
|
2079
2152
|
/**
|
|
2080
2153
|
* Start Sign in with OnlyWorlds from a tool's page: mint `state` and a PKCE verifier, keep them
|
|
@@ -2105,7 +2178,7 @@ var OwV2Client = class {
|
|
|
2105
2178
|
* 400: used, expired, or another client's code), `rate_limited`, `offline`, `failed`.
|
|
2106
2179
|
*/
|
|
2107
2180
|
async completeSignIn(opts) {
|
|
2108
|
-
only("completeSignIn", opts, ["clientId", "storage", "url"]);
|
|
2181
|
+
only("completeSignIn", opts, ["clientId", "storage", "url", "aiUses", "aiLifetimeMinutes"]);
|
|
2109
2182
|
return completeSignIn(this.baseUrl, this.fetchImpl, opts);
|
|
2110
2183
|
}
|
|
2111
2184
|
// -- Ask your world -------------------------------------------
|