diff --git a/api/README.md b/api/README.md index 9f62f37a4a..3756b11612 100644 --- a/api/README.md +++ b/api/README.md @@ -34,6 +34,7 @@ not touch the same lines: | `memory.yaml` | A person's memories and memory sources | | `agents.yaml` | The agents Bots hand work to (`bot-agents`), their callback tokens, and each Bot's delegation | | `management.yaml` | Connecting a self-hosted OpenBot to CopilotKit's management service: where it stands, starting and stopping it | +| `moves.yaml` | Moving to OpenBot Cloud: exporting what a person has in an OpenBot on their own computer, importing it into a Cloud organization, and checking it all arrived | An area file holds its operations under `paths`, and under `components` the schemas, parameters, responses and examples only it uses. Inside the file, refer to them as usual diff --git a/api/openapi.yaml b/api/openapi.yaml index d8a3746189..6b364f6e7a 100644 --- a/api/openapi.yaml +++ b/api/openapi.yaml @@ -123,6 +123,8 @@ tags: description: 'The agents an organization''s Bots hand work to: OpenBot''s own, a framework OpenBot runs, or an agent somebody runs at its own address. An administrator adds the organization''s, and anybody may add a private one for their own Bots. A Bot''s delegation says whether it works on one agent or hands work to several, and which.' - name: CopilotKit management description: Connecting a self-hosted OpenBot to CopilotKit's management service, which keeps it up to date in the company's own cluster through an agent installed there. Only the administrators of the organization `default` manage it, and only on the team edition a company runs itself. + - name: Moving to OpenBot Cloud + description: 'Moving what a person has in an OpenBot on their own computer to an organization on OpenBot Cloud: exporting it there as a bundle, importing the bundle on Cloud, and checking that everything arrived before anything is removed. Connections to apps never carry their sign-in, and a model key moves only when the person chooses, sealed to the import.' paths: /api/v2/organizations/{organizationId}/reactions: parameters: @@ -20968,6 +20970,496 @@ paths: $ref: '#/components/responses/ManagementServiceFailed' default: $ref: '#/components/responses/UnexpectedError' + /api/v2/organizations/{organizationId}/export-estimate: + parameters: + - $ref: '#/components/parameters/OrganizationId' + get: + tags: + - Moving to OpenBot Cloud + operationId: getExportEstimate + summary: Read what moving to OpenBot Cloud would take + description: 'Count what an export would hold, without making one: the caller''s Bots, their skills, conversations and messages, memories, routines, goals and check-ins, files and settings, and, when the caller is an administrator, the organization''s own skills. Also says roughly how big the bundle will be, how much space this OpenBot holds for it on disk (what the move frees once the local OpenBot is removed), which apps the person will need to connect again on OpenBot Cloud, and whether a model key could come along. Served only by an OpenBot that runs on the person''s own computer; elsewhere it answers 404 with the code MOVE_UNAVAILABLE.' + x-openbot-singleton: true + security: + - webSession: [] + - appOAuth: + - exports:read + - apiKey: [] + responses: + '200': + description: What an export would hold. + headers: + Cache-Control: + $ref: '#/components/headers/PrivateNoStore' + content: + application/json: + schema: + $ref: '#/components/schemas/ExportEstimate' + examples: + example: + $ref: '#/components/examples/ExportEstimateExample' + '401': + $ref: '#/components/responses/Unauthenticated' + '404': + $ref: '#/components/responses/MoveUnavailable' + '500': + $ref: '#/components/responses/ServerError' + default: + $ref: '#/components/responses/UnexpectedError' + /api/v2/organizations/{organizationId}/exports: + parameters: + - $ref: '#/components/parameters/OrganizationId' + post: + tags: + - Moving to OpenBot Cloud + operationId: createExport + summary: Start exporting what the caller has here + description: |- + Start writing a bundle of everything the caller has in this organization, to move it to OpenBot Cloud: their Bots (settings, instructions and skills), conversations with every message, memories, routines, goals and check-ins, files, standing instructions and preferences, and, when the caller is an administrator, the organization's own skills. Connections to apps travel as their app and account name only: no token or password ever leaves, and each one is listed in reconnect so the person connects it again on Cloud. A model key travels only when includeModelKeys is true, and then only sealed to recipientKey, the key the import on Cloud gave (createImport), so the bundle never holds it readable. + + The bundle is written in the background; read getExport until status is ready. It is cut into parts of at most 32 MiB, each with its size and SHA-256, so a dropped download resumes where it stopped. One export is kept for each person: starting another removes the one before. An export is removed 7 days after it was made, or with deleteExport. Served only by an OpenBot that runs on the person's own computer; elsewhere it answers 404 with the code MOVE_UNAVAILABLE. + security: + - webSession: [] + - appOAuth: + - exports:write + - apiKey: [] + parameters: + - $ref: '#/components/parameters/IdempotencyKey' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/ExportInput' + examples: + withModelKeys: + $ref: '#/components/examples/ExportInputExample' + responses: + '202': + description: The export has started. + headers: + Cache-Control: + $ref: '#/components/headers/PrivateNoStore' + content: + application/json: + schema: + $ref: '#/components/schemas/Export' + examples: + preparing: + $ref: '#/components/examples/ExportPreparingExample' + '400': + $ref: '#/components/responses/InvalidRequest' + '401': + $ref: '#/components/responses/Unauthenticated' + '404': + $ref: '#/components/responses/MoveUnavailable' + '409': + $ref: '#/components/responses/IdempotencyConflict' + '429': + $ref: '#/components/responses/TooManyMoves' + '500': + $ref: '#/components/responses/ServerError' + default: + $ref: '#/components/responses/UnexpectedError' + /api/v2/organizations/{organizationId}/exports/{exportId}: + parameters: + - $ref: '#/components/parameters/OrganizationId' + - $ref: '#/components/parameters/ExportId' + get: + tags: + - Moving to OpenBot Cloud + operationId: getExport + summary: Read an export + description: Return where the caller's export stands. Once ready it lists the bundle's parts with their sizes and SHA-256, its total size, and the count of everything in it by kind, which are the counts getImportVerification is compared with. Only the person who made it reads it; anybody else is answered 404. + security: + - webSession: [] + - appOAuth: + - exports:read + - apiKey: [] + responses: + '200': + description: The export. + headers: + Cache-Control: + $ref: '#/components/headers/PrivateNoStore' + content: + application/json: + schema: + $ref: '#/components/schemas/Export' + examples: + preparing: + $ref: '#/components/examples/ExportPreparingExample' + ready: + $ref: '#/components/examples/ExportReadyExample' + '401': + $ref: '#/components/responses/Unauthenticated' + '404': + $ref: '#/components/responses/ExportNotFound' + '500': + $ref: '#/components/responses/ServerError' + default: + $ref: '#/components/responses/UnexpectedError' + delete: + tags: + - Moving to OpenBot Cloud + operationId: deleteExport + summary: Remove an export + description: Remove the caller's export and its bundle from disk. Nothing it was made from changes. One already gone answers 204 too. + security: + - webSession: [] + - appOAuth: + - exports:write + - apiKey: [] + parameters: + - $ref: '#/components/parameters/IdempotencyKey' + responses: + '204': + description: The export is gone. + '401': + $ref: '#/components/responses/Unauthenticated' + '404': + $ref: '#/components/responses/MoveUnavailable' + '409': + $ref: '#/components/responses/IdempotencyConflict' + '500': + $ref: '#/components/responses/ServerError' + default: + $ref: '#/components/responses/UnexpectedError' + /api/v2/organizations/{organizationId}/exports/{exportId}/parts/{partNumber}: + parameters: + - $ref: '#/components/parameters/OrganizationId' + - $ref: '#/components/parameters/ExportId' + - $ref: '#/components/parameters/PartNumber' + get: + tags: + - Moving to OpenBot Cloud + operationId: downloadExportPart + summary: Download one part of an export's bundle + description: Return one part of a ready export's bundle, as bytes to hand to uploadImportPart unchanged. A Range header of one byte range (bytes=N- or bytes=N-M) answers 206 with that range, so a dropped download resumes where it stopped. The SHA-256 of the whole part is in the export's parts and in the ETag. Only the person who made the export downloads it. + x-openbot-singleton: true + security: + - webSession: [] + - appOAuth: + - exports:read + - apiKey: [] + parameters: + - name: Range + in: header + required: false + description: One byte range of the part, as RFC 9110 writes it. + schema: + type: string + pattern: ^bytes=[0-9]+-[0-9]*$ + maxLength: 64 + responses: + '200': + description: The whole part. + headers: + Cache-Control: + $ref: '#/components/headers/PrivateNoStore' + ETag: + $ref: '#/components/headers/PartETag' + Accept-Ranges: + $ref: '#/components/headers/AcceptRanges' + content: + application/octet-stream: + schema: + type: string + format: binary + '206': + description: The range asked for. + headers: + Cache-Control: + $ref: '#/components/headers/PrivateNoStore' + ETag: + $ref: '#/components/headers/PartETag' + Content-Range: + description: Which bytes of the part this is, and the part's size. + schema: + type: string + example: bytes 1048576-33554431/33554432 + content: + application/octet-stream: + schema: + type: string + format: binary + '401': + $ref: '#/components/responses/Unauthenticated' + '404': + $ref: '#/components/responses/ExportNotFound' + '409': + $ref: '#/components/responses/ExportNotReady' + '416': + $ref: '#/components/responses/RangeNotSatisfiable' + '500': + $ref: '#/components/responses/ServerError' + default: + $ref: '#/components/responses/UnexpectedError' + /api/v2/organizations/{organizationId}/imports: + parameters: + - $ref: '#/components/parameters/OrganizationId' + post: + tags: + - Moving to OpenBot Cloud + operationId: createImport + summary: Start importing a bundle into this organization + description: |- + Start an import of what the caller is moving from an OpenBot on their own computer into this organization, the caller's own organization by default. Everything imported belongs to the caller, in this organization only. The answer carries recipientKey, a public key made for this import alone: pass it to createExport, and a model key in the bundle is sealed to it, readable only by this import. The answer also says how big a bundle and a part may be. Then upload the export's parts with uploadImportPart and apply them with applyImport. + + Importing is safe to repeat: an import of the same OpenBot into the same organization (an export made again, or a new import after a dropped one) adds only what isn't here yet and duplicates nothing. Served only by OpenBot Cloud; elsewhere it answers 404 with the code MOVE_UNAVAILABLE. A person starts at most 10 imports a day. + security: + - webSession: [] + - appOAuth: + - imports:write + - apiKey: [] + parameters: + - $ref: '#/components/parameters/IdempotencyKey' + requestBody: + required: false + content: + application/json: + schema: + $ref: '#/components/schemas/ImportInput' + responses: + '201': + description: The import, waiting for its bundle. + headers: + Cache-Control: + $ref: '#/components/headers/PrivateNoStore' + content: + application/json: + schema: + $ref: '#/components/schemas/Import' + examples: + waiting: + $ref: '#/components/examples/ImportWaitingExample' + '400': + $ref: '#/components/responses/InvalidRequest' + '401': + $ref: '#/components/responses/Unauthenticated' + '404': + $ref: '#/components/responses/MoveUnavailable' + '409': + $ref: '#/components/responses/IdempotencyConflict' + '429': + $ref: '#/components/responses/TooManyMoves' + '500': + $ref: '#/components/responses/ServerError' + default: + $ref: '#/components/responses/UnexpectedError' + get: + tags: + - Moving to OpenBot Cloud + operationId: listImports + summary: List the caller's imports into this organization + description: List the imports the caller started in this organization, newest first, so an app that lost track of one after a drop finds it again. Only the caller's own. Served only by OpenBot Cloud. + security: + - webSession: [] + - appOAuth: + - imports:read + - apiKey: [] + parameters: + - $ref: '#/components/parameters/Limit' + - $ref: '#/components/parameters/Cursor' + responses: + '200': + description: A page of imports. + headers: + Cache-Control: + $ref: '#/components/headers/PrivateNoStore' + content: + application/json: + schema: + $ref: '#/components/schemas/ImportPage' + examples: + page: + $ref: '#/components/examples/ImportPageExample' + '400': + $ref: '#/components/responses/InvalidRequest' + '401': + $ref: '#/components/responses/Unauthenticated' + '404': + $ref: '#/components/responses/MoveUnavailable' + '500': + $ref: '#/components/responses/ServerError' + default: + $ref: '#/components/responses/UnexpectedError' + /api/v2/organizations/{organizationId}/imports/{importId}: + parameters: + - $ref: '#/components/parameters/OrganizationId' + - $ref: '#/components/parameters/ImportId' + get: + tags: + - Moving to OpenBot Cloud + operationId: getImport + summary: Read an import + description: 'Return where the caller''s import stands: which parts have arrived, how far applying them has got by kind, and once imported, the summary: what was imported, what was imported differently or left out on OpenBot Cloud and why (notes), and which apps to connect again (reconnect). Only the person who started it reads it.' + security: + - webSession: [] + - appOAuth: + - imports:read + - apiKey: [] + responses: + '200': + description: The import. + headers: + Cache-Control: + $ref: '#/components/headers/PrivateNoStore' + content: + application/json: + schema: + $ref: '#/components/schemas/Import' + examples: + waiting: + $ref: '#/components/examples/ImportWaitingExample' + imported: + $ref: '#/components/examples/ImportImportedExample' + '401': + $ref: '#/components/responses/Unauthenticated' + '404': + $ref: '#/components/responses/ImportNotFound' + '500': + $ref: '#/components/responses/ServerError' + default: + $ref: '#/components/responses/UnexpectedError' + /api/v2/organizations/{organizationId}/imports/{importId}/parts/{partNumber}: + parameters: + - $ref: '#/components/parameters/OrganizationId' + - $ref: '#/components/parameters/ImportId' + - $ref: '#/components/parameters/PartNumber' + put: + tags: + - Moving to OpenBot Cloud + operationId: uploadImportPart + summary: Upload one part of the bundle + description: Upload one part of the export's bundle, exactly as downloadExportPart gave it. Part 1 carries the bundle's manifest, so it is uploaded first; after it the parts go in any order, and the import's expectedParts says how many there are and the SHA-256 of each. A part whose bytes don't match the manifest is refused (IMPORT_PART_MISMATCH) and can be uploaded again. Uploading a part that already arrived changes nothing and answers 200 again, so after a drop an app sends whatever receivedParts doesn't list. A part is at most 32 MiB, and a bundle at most maxBundleBytes. At most 120 parts a minute for each person. + security: + - webSession: [] + - appOAuth: + - imports:write + - apiKey: [] + parameters: + - $ref: '#/components/parameters/IdempotencyKey' + requestBody: + required: true + content: + application/octet-stream: + schema: + type: string + format: binary + responses: + '200': + description: The part arrived (or had already arrived). + headers: + Cache-Control: + $ref: '#/components/headers/PrivateNoStore' + content: + application/json: + schema: + $ref: '#/components/schemas/Import' + examples: + receiving: + $ref: '#/components/examples/ImportReceivingExample' + '400': + $ref: '#/components/responses/InvalidRequest' + '401': + $ref: '#/components/responses/Unauthenticated' + '404': + $ref: '#/components/responses/ImportNotFound' + '409': + $ref: '#/components/responses/ImportConflict' + '413': + $ref: '#/components/responses/PayloadTooLarge' + '422': + $ref: '#/components/responses/ImportBundleRefused' + '429': + $ref: '#/components/responses/TooManyMoves' + '500': + $ref: '#/components/responses/ServerError' + default: + $ref: '#/components/responses/UnexpectedError' + /api/v2/organizations/{organizationId}/imports/{importId}/apply: + parameters: + - $ref: '#/components/parameters/OrganizationId' + - $ref: '#/components/parameters/ImportId' + post: + tags: + - Moving to OpenBot Cloud + operationId: applyImport + summary: Import the uploaded bundle + description: |- + Once every part has arrived, import the bundle into this organization in the background: every id is given a new one here, everything is owned by the caller, and nothing reaches another organization. Every file is stored where a file uploaded here is, in this organization's own place in OpenBot's file store, and the uploaded parts are removed once the import is done. Read getImport until status is imported or failed. Applying again while it runs, or after it finished, changes nothing and answers where it stands; applying a failed import tries again from where it stopped, and nothing already imported is imported twice. A missing part answers 409 with IMPORT_INCOMPLETE. + + What OpenBot Cloud doesn't have comes in differently, and the summary says so in notes: a Bot that ran on its own isolated computer comes in as an ordinary Bot; a feature that needs the Business plan, in an organization that isn't on it, is left out. A model key in the bundle becomes the caller's own AI connection, unless they have one here already, which is kept. + security: + - webSession: [] + - appOAuth: + - imports:write + - apiKey: [] + parameters: + - $ref: '#/components/parameters/IdempotencyKey' + responses: + '202': + description: Importing, or where the import stands. + headers: + Cache-Control: + $ref: '#/components/headers/PrivateNoStore' + content: + application/json: + schema: + $ref: '#/components/schemas/Import' + examples: + importing: + $ref: '#/components/examples/ImportImportingExample' + '401': + $ref: '#/components/responses/Unauthenticated' + '404': + $ref: '#/components/responses/ImportNotFound' + '409': + $ref: '#/components/responses/ImportConflict' + '500': + $ref: '#/components/responses/ServerError' + default: + $ref: '#/components/responses/UnexpectedError' + /api/v2/organizations/{organizationId}/imports/{importId}/verification: + parameters: + - $ref: '#/components/parameters/OrganizationId' + - $ref: '#/components/parameters/ImportId' + get: + tags: + - Moving to OpenBot Cloud + operationId: getImportVerification + summary: Check that everything arrived + description: Count, by kind, what from this import's OpenBot is in this organization now, read from what is stored here rather than from the import's own tally, beside what the bundle held. matches is true only when every kind is all here, apart from what the notes say OpenBot Cloud left out on purpose. OpenBot Desktop removes nothing on the person's computer until it does. Also lists the apps to connect again. + x-openbot-singleton: true + security: + - webSession: [] + - appOAuth: + - imports:read + - apiKey: [] + responses: + '200': + description: The counts. + headers: + Cache-Control: + $ref: '#/components/headers/PrivateNoStore' + content: + application/json: + schema: + $ref: '#/components/schemas/ImportVerification' + examples: + matches: + $ref: '#/components/examples/ImportVerificationExample' + '401': + $ref: '#/components/responses/Unauthenticated' + '404': + $ref: '#/components/responses/ImportNotFound' + '409': + $ref: '#/components/responses/ImportConflict' + '500': + $ref: '#/components/responses/ServerError' + default: + $ref: '#/components/responses/UnexpectedError' components: securitySchemes: webSession: @@ -21084,6 +21576,10 @@ components: memories:write: Write, change and forget the signed-in person's memories, and add, change, sync and remove their memory sources. bot-agents:read: Read the agents the signed-in person's Bots may hand work to, and for an administrator every agent in the organization. bot-agents:write: Add, change and delete the signed-in person's own agents and their callback tokens, and for an administrator the organization's. + exports:read: Read and download the signed-in person's exports for moving to OpenBot Cloud, and what one would hold. + exports:write: Start and remove the signed-in person's exports for moving to OpenBot Cloud. + imports:read: Read the signed-in person's imports into OpenBot Cloud and check what arrived. + imports:write: Start an import into OpenBot Cloud as the signed-in person, upload its bundle and import it. apiKey: type: http scheme: bearer @@ -21828,12 +22324,54 @@ components: maxLength: 200 pattern: \S example: bag_4f7c1e2a9d0b4c63 + ExportId: + name: exportId + in: path + required: true + description: The export's id. + schema: + type: string + minLength: 1 + maxLength: 64 + pattern: ^[A-Za-z0-9_-]+$ + example: exp_7d1f2c3b8a4e4b5f + PartNumber: + name: partNumber + in: path + required: true + description: Which part of the bundle, counted from 1. + schema: + type: integer + minimum: 1 + maximum: 10000 + example: 1 + ImportId: + name: importId + in: path + required: true + description: The import's id. + schema: + type: string + minLength: 1 + maxLength: 64 + pattern: ^[A-Za-z0-9_-]+$ + example: imp_0e1f2a3b4c5d6f1d headers: PrivateNoStore: description: A Bot is private to the caller. schema: type: string const: private, no-store + PartETag: + description: The part's SHA-256 in hex, quoted. + schema: + type: string + example: '"9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"' + AcceptRanges: + description: A part can be downloaded a byte range at a time. + schema: + type: string + const: bytes schemas: BotVisibility: type: string @@ -38008,6 +38546,391 @@ components: - invalid-licence - unreachable description: 'Which refusal lastError is, where a client acts on it. not-entitled: this OpenBot''s licence doesn''t include managed updates (it isn''t a team licence, or managed updates were turned off for its organization), so connecting again fails the same way until they are added to it. invalid-licence: the licence wasn''t accepted (invalid or expired). unreachable: the managed updates service couldn''t be reached when OpenBot last tried to connect by itself; it tries again within the hour. A later OpenBot may add a code; read one you don''t know as no code.' + MoveKind: + type: string + x-extensible-enum: + - bots + - skills + - conversations + - messages + - memories + - routines + - goals + - check-ins + - files + - settings + - model-keys + description: 'A kind of thing that moves. bots: Bots with their settings and instructions. skills: skills, a Bot''s and the person''s (and the organization''s, for an administrator). conversations and messages: every conversation and every message in it. memories: what the person''s Bots remember about them. routines, goals and check-ins: with their schedules. files: files sent in conversations and kept on a Bot''s computer. settings: the person''s standing instructions and preferences. model-keys: a model key, only when the person chose to bring it. A later OpenBot may add a kind; count one you don''t know like any other.' + MoveCount: + type: object + required: + - kind + - count + properties: + kind: + $ref: '#/components/schemas/MoveKind' + count: + type: integer + minimum: 0 + bytes: + type: integer + minimum: 0 + description: For files, how many bytes they hold together. + ReconnectApp: + type: object + description: 'A connection to an app that doesn''t move, because its sign-in stays on the person''s computer: the person connects it again on OpenBot Cloud. Never carries a token, a password or a key.' + required: + - appId + - appName + properties: + appId: + type: string + minLength: 1 + description: The app's id in the app directory, such as gmail or slack. + appName: + type: string + minLength: 1 + description: The app's name as a person reads it. + accountLabel: + type: string + minLength: 1 + description: Which account it was connected as, such as an email address or a workspace name, when known. + iconUrl: + type: string + format: uri + description: The app's icon, when the directory has one. + botNames: + type: array + description: The Bots that used it, so the person knows which to check. + items: + type: string + ExportEstimate: + type: object + required: + - counts + - estimatedBytes + - storedBytes + - reconnect + - modelKeysAvailable + properties: + counts: + type: array + items: + $ref: '#/components/schemas/MoveCount' + estimatedBytes: + type: integer + minimum: 0 + description: Roughly how big the bundle will be, in bytes. + storedBytes: + type: integer + minimum: 0 + description: How much this OpenBot keeps on disk for the person (its database and files), which removing it frees. OpenBot Desktop adds what the engine itself takes. + reconnect: + type: array + items: + $ref: '#/components/schemas/ReconnectApp' + modelKeysAvailable: + type: boolean + description: True when there is a model key the person could choose to bring. + MoveRecipientKey: + type: object + description: 'A public key as a JSON Web Key (RFC 7517): RSA, 4096 bits, for RSA-OAEP-256. A model key is sealed to it as a JWE (RFC 7516, RSA-OAEP-256 with A256GCM), so only the import that made it reads it.' + additionalProperties: false + required: + - kty + - 'n' + - e + - alg + - kid + properties: + kty: + type: string + const: RSA + 'n': + type: string + minLength: 1 + maxLength: 1024 + e: + type: string + minLength: 1 + maxLength: 16 + alg: + type: string + const: RSA-OAEP-256 + kid: + type: string + minLength: 1 + maxLength: 128 + ExportInput: + type: object + additionalProperties: false + properties: + includeModelKeys: + type: boolean + default: false + description: Bring the person's model key, sealed to recipientKey. Without recipientKey this is refused. + recipientKey: + $ref: '#/components/schemas/MoveRecipientKey' + BundlePart: + type: object + required: + - number + - bytes + - sha256 + properties: + number: + type: integer + minimum: 1 + bytes: + type: integer + minimum: 1 + sha256: + type: string + pattern: ^[0-9a-f]{64}$ + Export: + type: object + required: + - id + - status + - createdAt + - expiresAt + - includesModelKeys + properties: + id: + type: string + minLength: 1 + status: + type: string + x-extensible-enum: + - preparing + - ready + - failed + description: 'preparing: the bundle is being written. ready: every part can be downloaded. failed: it stopped; error says why, and starting another export tries again. A later OpenBot may add a status; read one you don''t know as preparing.' + formatVersion: + type: integer + minimum: 1 + description: The bundle's format, once ready. This OpenBot writes 1. + createdAt: + type: string + format: date-time + expiresAt: + type: string + format: date-time + description: When the bundle is removed. + totalBytes: + type: integer + minimum: 0 + description: The bundle's size, once ready. + parts: + type: array + description: The bundle's parts in order, once ready. + items: + $ref: '#/components/schemas/BundlePart' + counts: + type: array + description: Everything in the bundle by kind, once ready. + items: + $ref: '#/components/schemas/MoveCount' + reconnect: + type: array + description: The apps to connect again on OpenBot Cloud. + items: + $ref: '#/components/schemas/ReconnectApp' + includesModelKeys: + type: boolean + progress: + type: number + minimum: 0 + maximum: 1 + description: How far writing the bundle has got, while preparing. + error: + type: string + minLength: 1 + description: What went wrong, when failed, in a sentence a person reads. + MoveNote: + type: object + description: Something that moved differently, or not at all, and why, in a sentence a person reads. + required: + - code + - message + properties: + code: + type: string + x-extensible-enum: + - isolated-bot-made-ordinary + - business-plan-feature-left-out + - model-key-kept-existing + - model-key-not-brought + - item-skipped + description: 'isolated-bot-made-ordinary: OpenBot Cloud has no isolated computers, so a Bot that had one runs on an ordinary one. business-plan-feature-left-out: the feature needs the Business plan and this organization isn''t on it. model-key-kept-existing: the person already had an AI connection here, which was kept. model-key-not-brought: the person chose not to bring a model key. item-skipped: one item couldn''t be imported; message says which and why. A later OpenBot may add a code; show the message.' + kind: + $ref: '#/components/schemas/MoveKind' + count: + type: integer + minimum: 1 + description: How many items the note is about. + message: + type: string + minLength: 1 + items: + type: array + description: The names of the items, such as the Bots, when there are a few. + items: + type: string + Import: + type: object + required: + - id + - status + - createdAt + - recipientKey + - maxBundleBytes + - maxPartBytes + - receivedParts + properties: + id: + type: string + minLength: 1 + status: + type: string + x-extensible-enum: + - waiting-for-bundle + - receiving + - ready + - importing + - imported + - failed + description: 'waiting-for-bundle: no part has arrived. receiving: part 1 has arrived and others are still to come. ready: every part arrived; apply it. importing: being imported. imported: done; read the summary, then verify. failed: it stopped; error says why, and applying again goes on from there. A later OpenBot may add a status; read one you don''t know as importing.' + sourceName: + type: string + createdAt: + type: string + format: date-time + finishedAt: + type: string + format: date-time + recipientKey: + $ref: '#/components/schemas/MoveRecipientKey' + maxBundleBytes: + type: integer + minimum: 1 + maxPartBytes: + type: integer + minimum: 1 + expectedParts: + type: array + description: The bundle's parts, from its manifest, once part 1 arrived. + items: + $ref: '#/components/schemas/BundlePart' + receivedParts: + type: array + description: The numbers of the parts that arrived. + items: + type: integer + minimum: 1 + expected: + type: array + description: Everything the bundle holds by kind, from its manifest, once part 1 arrived. + items: + $ref: '#/components/schemas/MoveCount' + imported: + type: array + description: What has been imported so far by kind, while importing and once imported. Items a repeated import found already here count as imported. + items: + $ref: '#/components/schemas/MoveCount' + notes: + type: array + items: + $ref: '#/components/schemas/MoveNote' + reconnect: + type: array + description: The apps to connect again here, once part 1 arrived. + items: + $ref: '#/components/schemas/ReconnectApp' + error: + type: string + minLength: 1 + description: What went wrong, when failed, in a sentence a person reads. + ImportPage: + type: object + required: + - items + - nextCursor + properties: + items: + type: array + items: + $ref: '#/components/schemas/Import' + nextCursor: + type: + - string + - 'null' + ImportInput: + type: object + additionalProperties: false + properties: + sourceName: + type: string + minLength: 1 + maxLength: 200 + description: A name for where the bundle comes from, such as the computer's name, shown in the list of imports. + ImportVerificationKind: + type: object + required: + - kind + - expected + - found + - leftOut + properties: + kind: + $ref: '#/components/schemas/MoveKind' + expected: + type: integer + minimum: 0 + description: How many the bundle held. + found: + type: integer + minimum: 0 + description: How many from this OpenBot are in this organization now. + leftOut: + type: integer + minimum: 0 + description: How many OpenBot Cloud left out on purpose, as the notes say. + expectedBytes: + type: integer + minimum: 0 + description: For files, how many bytes the bundle held. + foundBytes: + type: integer + minimum: 0 + description: For files, how many bytes are in this organization's file store now, read from the store itself. + ImportVerification: + type: object + required: + - importId + - matches + - kinds + - notes + - reconnect + properties: + importId: + type: string + minLength: 1 + matches: + type: boolean + description: True when, for every kind, found plus leftOut is expected, and for files foundBytes is expectedBytes. + kinds: + type: array + items: + $ref: '#/components/schemas/ImportVerificationKind' + notes: + type: array + items: + $ref: '#/components/schemas/MoveNote' + reconnect: + type: array + items: + $ref: '#/components/schemas/ReconnectApp' responses: InvalidRequest: description: A parameter is malformed. @@ -43782,6 +44705,167 @@ components: retryable: true requestId: req_example traceId: trace_example + MoveUnavailable: + description: 'Moving isn''t served here: exports only by an OpenBot on the person''s own computer, imports only by OpenBot Cloud.' + content: + application/problem+json: + schema: + $ref: '#/components/schemas/Problem' + examples: + unavailable: + value: + type: https://open.bot/errors/move-unavailable + title: Moving isn't available here. + status: 404 + detail: Importing is available only on OpenBot Cloud. + code: MOVE_UNAVAILABLE + category: not_found + retryable: false + requestId: req_example + traceId: trace_example + TooManyMoves: + description: Too many exports, imports or parts at once for one person. + headers: + Retry-After: + description: Seconds to wait. + schema: + type: integer + minimum: 1 + content: + application/problem+json: + schema: + $ref: '#/components/schemas/Problem' + examples: + tooMany: + value: + type: https://open.bot/errors/rate-limited + title: Too many requests. + status: 429 + detail: That's a lot of uploads at once. Wait a minute, then go on. + code: RATE_LIMITED + category: rate_limit + retryable: true + requestId: req_example + traceId: trace_example + ExportNotFound: + description: The export doesn't exist, has been removed, or isn't the caller's. + content: + application/problem+json: + schema: + $ref: '#/components/schemas/Problem' + examples: + notFound: + value: + type: https://open.bot/errors/export-not-found + title: Export not found. + status: 404 + detail: That export isn't here any more. Start the move again. + code: EXPORT_NOT_FOUND + category: not_found + retryable: false + requestId: req_example + traceId: trace_example + ExportNotReady: + description: The export is still being written, or failed. + content: + application/problem+json: + schema: + $ref: '#/components/schemas/Problem' + examples: + preparing: + value: + type: https://open.bot/errors/export-not-ready + title: The export isn't ready. + status: 409 + detail: The export is still being prepared. Try again when it's ready. + code: EXPORT_NOT_READY + category: conflict + retryable: true + requestId: req_example + traceId: trace_example + RangeNotSatisfiable: + description: The Range asked for lies outside the part. + content: + application/problem+json: + schema: + $ref: '#/components/schemas/Problem' + examples: + outside: + value: + type: https://open.bot/errors/range-not-satisfiable + title: That range isn't in the part. + status: 416 + detail: The part is 33554432 bytes long. + code: RANGE_NOT_SATISFIABLE + category: validation + retryable: false + requestId: req_example + traceId: trace_example + ImportNotFound: + description: The import doesn't exist, or isn't the caller's. + content: + application/problem+json: + schema: + $ref: '#/components/schemas/Problem' + examples: + notFound: + value: + type: https://open.bot/errors/import-not-found + title: Import not found. + status: 404 + detail: That import isn't here. Start the move again. + code: IMPORT_NOT_FOUND + category: not_found + retryable: false + requestId: req_example + traceId: trace_example + ImportConflict: + description: 'The import can''t do that in its state: a part doesn''t match the manifest (IMPORT_PART_MISMATCH), part 1 hasn''t arrived (IMPORT_MANIFEST_MISSING), a part is missing (IMPORT_INCOMPLETE), the import hasn''t finished (IMPORT_NOT_FINISHED), or the Idempotency-Key was used for a different request.' + content: + application/problem+json: + schema: + $ref: '#/components/schemas/Problem' + examples: + incomplete: + value: + type: https://open.bot/errors/import-incomplete + title: Some parts haven't arrived. + status: 409 + detail: Parts 3 and 4 haven't arrived yet. Upload them, then import. + code: IMPORT_INCOMPLETE + category: conflict + retryable: false + requestId: req_example + traceId: trace_example + mismatch: + value: + type: https://open.bot/errors/import-part-mismatch + title: That part doesn't match the bundle. + status: 409 + detail: Part 2 arrived damaged. Download it again and upload it. + code: IMPORT_PART_MISMATCH + category: conflict + retryable: true + requestId: req_example + traceId: trace_example + ImportBundleRefused: + description: 'Part 1 isn''t a bundle this OpenBot reads: not a bundle at all, a format newer than it reads (IMPORT_FORMAT_UNSUPPORTED), larger than maxBundleBytes, or a model key sealed to another import''s key.' + content: + application/problem+json: + schema: + $ref: '#/components/schemas/Problem' + examples: + newer: + value: + type: https://open.bot/errors/import-format-unsupported + title: This bundle is newer than OpenBot Cloud reads. + status: 422 + detail: This bundle was made by a newer OpenBot. Try again once OpenBot Cloud is updated. + code: IMPORT_FORMAT_UNSUPPORTED + category: validation + retryable: false + requestId: req_example + traceId: trace_example examples: ReactionPageLast: summary: Every reaction in a conversation, on one page. @@ -48133,3 +49217,255 @@ components: value: state: opted-out agentInstalledByChart: true + ExportEstimateExample: + value: + counts: + - kind: bots + count: 4 + - kind: skills + count: 9 + - kind: conversations + count: 37 + - kind: messages + count: 2814 + - kind: memories + count: 52 + - kind: routines + count: 3 + - kind: goals + count: 1 + - kind: check-ins + count: 2 + - kind: files + count: 64 + - kind: settings + count: 1 + estimatedBytes: 187432960 + storedBytes: 1288490188 + reconnect: + - appId: gmail + appName: Gmail + accountLabel: sam@example.com + botNames: + - Inbox helper + - appId: slack + appName: Slack + accountLabel: Example workspace + botNames: + - Inbox helper + - Standup + modelKeysAvailable: true + ExportInputExample: + value: + includeModelKeys: true + recipientKey: + kty: RSA + alg: RSA-OAEP-256 + kid: imp_0e1f2a3b4c5d6f1d + e: AQAB + 'n': 0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw + ExportPreparingExample: + value: + id: exp_7d1f2c3b8a4e4b5f + status: preparing + createdAt: '2026-11-21T10:00:00Z' + expiresAt: '2026-11-28T10:00:00Z' + includesModelKeys: true + progress: 0.4 + ExportReadyExample: + value: + id: exp_7d1f2c3b8a4e4b5f + status: ready + formatVersion: 1 + createdAt: '2026-11-21T10:00:00Z' + expiresAt: '2026-11-28T10:00:00Z' + totalBytes: 41943040 + parts: + - number: 1 + bytes: 33554432 + sha256: 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08 + - number: 2 + bytes: 8388608 + sha256: 60303ae22b998861bce3b28f33eec1be758a213c86c93c076dbe9f558c11c752 + counts: + - kind: bots + count: 4 + - kind: conversations + count: 37 + - kind: messages + count: 2814 + - kind: model-keys + count: 1 + reconnect: + - appId: gmail + appName: Gmail + accountLabel: sam@example.com + includesModelKeys: true + ImportPageExample: + value: + items: + - id: imp_0e1f2a3b4c5d6f1d + status: waiting-for-bundle + sourceName: Sam's MacBook + createdAt: '2026-11-21T10:00:00Z' + recipientKey: + kty: RSA + alg: RSA-OAEP-256 + kid: imp_0e1f2a3b4c5d6f1d + e: AQAB + 'n': 0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw + maxBundleBytes: 10737418240 + maxPartBytes: 33554432 + receivedParts: [] + nextCursor: null + ImportWaitingExample: + value: + id: imp_0e1f2a3b4c5d6f1d + status: waiting-for-bundle + sourceName: Sam's MacBook + createdAt: '2026-11-21T10:00:00Z' + recipientKey: + kty: RSA + alg: RSA-OAEP-256 + kid: imp_0e1f2a3b4c5d6f1d + e: AQAB + 'n': 0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw + maxBundleBytes: 10737418240 + maxPartBytes: 33554432 + receivedParts: [] + ImportImportedExample: + value: + id: imp_0e1f2a3b4c5d6f1d + status: imported + createdAt: '2026-11-21T10:00:00Z' + finishedAt: '2026-11-21T10:03:12Z' + recipientKey: + kty: RSA + alg: RSA-OAEP-256 + kid: imp_0e1f2a3b4c5d6f1d + e: AQAB + 'n': 0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw + maxBundleBytes: 10737418240 + maxPartBytes: 33554432 + expectedParts: + - number: 1 + bytes: 33554432 + sha256: 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08 + - number: 2 + bytes: 8388608 + sha256: 60303ae22b998861bce3b28f33eec1be758a213c86c93c076dbe9f558c11c752 + receivedParts: + - 1 + - 2 + expected: + - kind: bots + count: 4 + - kind: conversations + count: 37 + - kind: messages + count: 2814 + imported: + - kind: bots + count: 4 + - kind: conversations + count: 37 + - kind: messages + count: 2814 + notes: + - code: isolated-bot-made-ordinary + kind: bots + count: 1 + message: Research runs on an ordinary computer here, because OpenBot Cloud has no isolated computers. + items: + - Research + reconnect: + - appId: gmail + appName: Gmail + accountLabel: sam@example.com + ImportReceivingExample: + value: + id: imp_0e1f2a3b4c5d6f1d + status: receiving + createdAt: '2026-11-21T10:00:00Z' + recipientKey: + kty: RSA + alg: RSA-OAEP-256 + kid: imp_0e1f2a3b4c5d6f1d + e: AQAB + 'n': 0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw + maxBundleBytes: 10737418240 + maxPartBytes: 33554432 + expectedParts: + - number: 1 + bytes: 2048 + sha256: 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08 + - number: 2 + bytes: 8388608 + sha256: 60303ae22b998861bce3b28f33eec1be758a213c86c93c076dbe9f558c11c752 + receivedParts: + - 1 + expected: + - kind: bots + count: 4 + - kind: conversations + count: 37 + - kind: messages + count: 2814 + reconnect: + - appId: gmail + appName: Gmail + accountLabel: sam@example.com + ImportImportingExample: + value: + id: imp_0e1f2a3b4c5d6f1d + status: importing + createdAt: '2026-11-21T10:00:00Z' + recipientKey: + kty: RSA + alg: RSA-OAEP-256 + kid: imp_0e1f2a3b4c5d6f1d + e: AQAB + 'n': 0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw + maxBundleBytes: 10737418240 + maxPartBytes: 33554432 + receivedParts: + - 1 + - 2 + expected: + - kind: bots + count: 4 + - kind: conversations + count: 37 + imported: + - kind: bots + count: 4 + - kind: conversations + count: 12 + ImportVerificationExample: + value: + importId: imp_0e1f2a3b4c5d6f1d + matches: true + kinds: + - kind: bots + expected: 4 + found: 4 + leftOut: 0 + - kind: conversations + expected: 37 + found: 37 + leftOut: 0 + - kind: messages + expected: 2814 + found: 2814 + leftOut: 0 + - kind: files + expected: 64 + found: 64 + leftOut: 0 + expectedBytes: 152043520 + foundBytes: 152043520 + notes: [] + reconnect: + - appId: gmail + appName: Gmail + accountLabel: sam@example.com diff --git a/api/openapi/common.yaml b/api/openapi/common.yaml index 012d9a1cb6..5feb2538c5 100644 --- a/api/openapi/common.yaml +++ b/api/openapi/common.yaml @@ -138,6 +138,7 @@ tags: - { name: Memory, description: "The facts a person's Bots remember about them, and the app actions those facts are read in from. Each person's are theirs alone: an administrator can't read them either." } - { name: Agents, description: "The agents an organization's Bots hand work to: OpenBot's own, a framework OpenBot runs, or an agent somebody runs at its own address. An administrator adds the organization's, and anybody may add a private one for their own Bots. A Bot's delegation says whether it works on one agent or hands work to several, and which." } - { name: CopilotKit management, description: "Connecting a self-hosted OpenBot to CopilotKit's management service, which keeps it up to date in the company's own cluster through an agent installed there. Only the administrators of the organization `default` manage it, and only on the team edition a company runs itself." } + - { name: Moving to OpenBot Cloud, description: "Moving what a person has in an OpenBot on their own computer to an organization on OpenBot Cloud: exporting it there as a bundle, importing the bundle on Cloud, and checking that everything arrived before anything is removed. Connections to apps never carry their sign-in, and a model key moves only when the person chooses, sealed to the import." } paths: /api/v2/organizations/{organizationId}/reactions: { $ref: './conversations.yaml#/paths/~1api~1v2~1organizations~1{organizationId}~1reactions' } /api/v2/organizations/{organizationId}/bots: { $ref: './bots.yaml#/paths/~1api~1v2~1organizations~1{organizationId}~1bots' } @@ -495,6 +496,15 @@ paths: /api/v2/organizations/{organizationId}/bots/{botId}/delegation: { $ref: './agents.yaml#/paths/~1api~1v2~1organizations~1{organizationId}~1bots~1{botId}~1delegation' } /api/v2/organizations/{organizationId}/management: { $ref: './management.yaml#/paths/~1api~1v2~1organizations~1{organizationId}~1management' } /api/v2/organizations/{organizationId}/management/enrollment: { $ref: './management.yaml#/paths/~1api~1v2~1organizations~1{organizationId}~1management~1enrollment' } + /api/v2/organizations/{organizationId}/export-estimate: { $ref: './moves.yaml#/paths/~1api~1v2~1organizations~1{organizationId}~1export-estimate' } + /api/v2/organizations/{organizationId}/exports: { $ref: './moves.yaml#/paths/~1api~1v2~1organizations~1{organizationId}~1exports' } + /api/v2/organizations/{organizationId}/exports/{exportId}: { $ref: './moves.yaml#/paths/~1api~1v2~1organizations~1{organizationId}~1exports~1{exportId}' } + /api/v2/organizations/{organizationId}/exports/{exportId}/parts/{partNumber}: { $ref: './moves.yaml#/paths/~1api~1v2~1organizations~1{organizationId}~1exports~1{exportId}~1parts~1{partNumber}' } + /api/v2/organizations/{organizationId}/imports: { $ref: './moves.yaml#/paths/~1api~1v2~1organizations~1{organizationId}~1imports' } + /api/v2/organizations/{organizationId}/imports/{importId}: { $ref: './moves.yaml#/paths/~1api~1v2~1organizations~1{organizationId}~1imports~1{importId}' } + /api/v2/organizations/{organizationId}/imports/{importId}/parts/{partNumber}: { $ref: './moves.yaml#/paths/~1api~1v2~1organizations~1{organizationId}~1imports~1{importId}~1parts~1{partNumber}' } + /api/v2/organizations/{organizationId}/imports/{importId}/apply: { $ref: './moves.yaml#/paths/~1api~1v2~1organizations~1{organizationId}~1imports~1{importId}~1apply' } + /api/v2/organizations/{organizationId}/imports/{importId}/verification: { $ref: './moves.yaml#/paths/~1api~1v2~1organizations~1{organizationId}~1imports~1{importId}~1verification' } components: securitySchemes: webSession: @@ -661,6 +671,10 @@ components: memories:write: Write, change and forget the signed-in person's memories, and add, change, sync and remove their memory sources. bot-agents:read: Read the agents the signed-in person's Bots may hand work to, and for an administrator every agent in the organization. bot-agents:write: Add, change and delete the signed-in person's own agents and their callback tokens, and for an administrator the organization's. + exports:read: Read and download the signed-in person's exports for moving to OpenBot Cloud, and what one would hold. + exports:write: Start and remove the signed-in person's exports for moving to OpenBot Cloud. + imports:read: Read the signed-in person's imports into OpenBot Cloud and check what arrived. + imports:write: Start an import into OpenBot Cloud as the signed-in person, upload its bundle and import it. apiKey: type: http scheme: bearer diff --git a/api/openapi/moves.yaml b/api/openapi/moves.yaml new file mode 100644 index 0000000000..ff0d9c6ebe --- /dev/null +++ b/api/openapi/moves.yaml @@ -0,0 +1,1353 @@ +# Moving to OpenBot Cloud: exporting what a person has in an OpenBot on their own computer, and +# importing it into an organization on OpenBot Cloud. +# +# One area of OpenBot's REST API. `bun run api:bundle` joins every area with common.yaml into +# api/openapi.yaml, the file every client and check reads. See api/README.md. +# +# The move, as OpenBot Desktop runs it: +# 1. Cloud: createImport. The answer carries recipientKey, the public key model keys are sealed to. +# 2. Here: getExportEstimate, to show what moves and how much space the move frees. +# 3. Here: createExport (with recipientKey when the person chose to bring their model keys), then +# getExport until it is ready. The answer lists the bundle's parts, their sizes and digests, +# and the counts of everything in it. +# 4. Desktop: downloadExportPart for each part (resumable with Range), and on Cloud +# uploadImportPart for each (a part already received is skipped). +# 5. Cloud: applyImport, then getImport until it is imported. +# 6. Cloud: getImportVerification. Desktop removes nothing here until it says matches. +paths: + /api/v2/organizations/{organizationId}/export-estimate: + parameters: + - $ref: './common.yaml#/components/parameters/OrganizationId' + get: + tags: [Moving to OpenBot Cloud] + operationId: getExportEstimate + summary: Read what moving to OpenBot Cloud would take + description: >- + Count what an export would hold, without making one: the caller's + Bots, their skills, conversations and messages, memories, routines, + goals and check-ins, files and settings, and, when the caller is an + administrator, the organization's own skills. Also says roughly how + big the bundle will be, how much space this OpenBot holds for it on + disk (what the move frees once the local OpenBot is removed), which + apps the person will need to connect again on OpenBot Cloud, and + whether a model key could come along. Served only by an OpenBot that + runs on the person's own computer; elsewhere it answers 404 with the + code MOVE_UNAVAILABLE. + x-openbot-singleton: true + security: + - webSession: [] + - appOAuth: [exports:read] + - apiKey: [] + responses: + '200': + description: What an export would hold. + headers: + Cache-Control: + $ref: './common.yaml#/components/headers/PrivateNoStore' + content: + application/json: + schema: + $ref: '#/components/schemas/ExportEstimate' + examples: + example: + $ref: '#/components/examples/ExportEstimateExample' + '401': + $ref: './common.yaml#/components/responses/Unauthenticated' + '404': + $ref: '#/components/responses/MoveUnavailable' + '500': + $ref: './common.yaml#/components/responses/ServerError' + default: + $ref: './common.yaml#/components/responses/UnexpectedError' + /api/v2/organizations/{organizationId}/exports: + parameters: + - $ref: './common.yaml#/components/parameters/OrganizationId' + post: + tags: [Moving to OpenBot Cloud] + operationId: createExport + summary: Start exporting what the caller has here + description: >- + Start writing a bundle of everything the caller has in this + organization, to move it to OpenBot Cloud: their Bots (settings, + instructions and skills), conversations with every message, + memories, routines, goals and check-ins, files, standing + instructions and preferences, and, when the caller is an + administrator, the organization's own skills. Connections to apps + travel as their app and account name only: no token or password ever + leaves, and each one is listed in reconnect so the person connects + it again on Cloud. A model key travels only when includeModelKeys is + true, and then only sealed to recipientKey, the key the import on + Cloud gave (createImport), so the bundle never holds it readable. + + + The bundle is written in the background; read getExport until status + is ready. It is cut into parts of at most 32 MiB, each with its size + and SHA-256, so a dropped download resumes where it stopped. One + export is kept for each person: starting another removes the one + before. An export is removed 7 days after it was made, or with + deleteExport. Served only by an OpenBot that runs on the person's own + computer; elsewhere it answers 404 with the code MOVE_UNAVAILABLE. + security: + - webSession: [] + - appOAuth: [exports:write] + - apiKey: [] + parameters: + - $ref: './common.yaml#/components/parameters/IdempotencyKey' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/ExportInput' + examples: + withModelKeys: + $ref: '#/components/examples/ExportInputExample' + responses: + '202': + description: The export has started. + headers: + Cache-Control: + $ref: './common.yaml#/components/headers/PrivateNoStore' + content: + application/json: + schema: + $ref: '#/components/schemas/Export' + examples: + preparing: + $ref: '#/components/examples/ExportPreparingExample' + '400': + $ref: './common.yaml#/components/responses/InvalidRequest' + '401': + $ref: './common.yaml#/components/responses/Unauthenticated' + '404': + $ref: '#/components/responses/MoveUnavailable' + '409': + $ref: './common.yaml#/components/responses/IdempotencyConflict' + '429': + $ref: '#/components/responses/TooManyMoves' + '500': + $ref: './common.yaml#/components/responses/ServerError' + default: + $ref: './common.yaml#/components/responses/UnexpectedError' + /api/v2/organizations/{organizationId}/exports/{exportId}: + parameters: + - $ref: './common.yaml#/components/parameters/OrganizationId' + - $ref: '#/components/parameters/ExportId' + get: + tags: [Moving to OpenBot Cloud] + operationId: getExport + summary: Read an export + description: >- + Return where the caller's export stands. Once ready it lists the + bundle's parts with their sizes and SHA-256, its total size, and the + count of everything in it by kind, which are the counts + getImportVerification is compared with. Only the person who made it + reads it; anybody else is answered 404. + security: + - webSession: [] + - appOAuth: [exports:read] + - apiKey: [] + responses: + '200': + description: The export. + headers: + Cache-Control: + $ref: './common.yaml#/components/headers/PrivateNoStore' + content: + application/json: + schema: + $ref: '#/components/schemas/Export' + examples: + preparing: + $ref: '#/components/examples/ExportPreparingExample' + ready: + $ref: '#/components/examples/ExportReadyExample' + '401': + $ref: './common.yaml#/components/responses/Unauthenticated' + '404': + $ref: '#/components/responses/ExportNotFound' + '500': + $ref: './common.yaml#/components/responses/ServerError' + default: + $ref: './common.yaml#/components/responses/UnexpectedError' + delete: + tags: [Moving to OpenBot Cloud] + operationId: deleteExport + summary: Remove an export + description: >- + Remove the caller's export and its bundle from disk. Nothing it was + made from changes. One already gone answers 204 too. + security: + - webSession: [] + - appOAuth: [exports:write] + - apiKey: [] + parameters: + - $ref: './common.yaml#/components/parameters/IdempotencyKey' + responses: + '204': + description: The export is gone. + '401': + $ref: './common.yaml#/components/responses/Unauthenticated' + '404': + $ref: '#/components/responses/MoveUnavailable' + '409': + $ref: './common.yaml#/components/responses/IdempotencyConflict' + '500': + $ref: './common.yaml#/components/responses/ServerError' + default: + $ref: './common.yaml#/components/responses/UnexpectedError' + /api/v2/organizations/{organizationId}/exports/{exportId}/parts/{partNumber}: + parameters: + - $ref: './common.yaml#/components/parameters/OrganizationId' + - $ref: '#/components/parameters/ExportId' + - $ref: '#/components/parameters/PartNumber' + get: + tags: [Moving to OpenBot Cloud] + operationId: downloadExportPart + summary: Download one part of an export's bundle + description: >- + Return one part of a ready export's bundle, as bytes to hand to + uploadImportPart unchanged. A Range header of one byte range (bytes=N- + or bytes=N-M) answers 206 with that range, so a dropped download + resumes where it stopped. The SHA-256 of the whole part is in the + export's parts and in the ETag. Only the person who made the export + downloads it. + x-openbot-singleton: true + security: + - webSession: [] + - appOAuth: [exports:read] + - apiKey: [] + parameters: + - name: Range + in: header + required: false + description: One byte range of the part, as RFC 9110 writes it. + schema: + type: string + pattern: ^bytes=[0-9]+-[0-9]*$ + maxLength: 64 + responses: + '200': + description: The whole part. + headers: + Cache-Control: + $ref: './common.yaml#/components/headers/PrivateNoStore' + ETag: + $ref: '#/components/headers/PartETag' + Accept-Ranges: + $ref: '#/components/headers/AcceptRanges' + content: + application/octet-stream: + schema: + type: string + format: binary + '206': + description: The range asked for. + headers: + Cache-Control: + $ref: './common.yaml#/components/headers/PrivateNoStore' + ETag: + $ref: '#/components/headers/PartETag' + Content-Range: + description: Which bytes of the part this is, and the part's size. + schema: + type: string + example: bytes 1048576-33554431/33554432 + content: + application/octet-stream: + schema: + type: string + format: binary + '401': + $ref: './common.yaml#/components/responses/Unauthenticated' + '404': + $ref: '#/components/responses/ExportNotFound' + '409': + $ref: '#/components/responses/ExportNotReady' + '416': + $ref: '#/components/responses/RangeNotSatisfiable' + '500': + $ref: './common.yaml#/components/responses/ServerError' + default: + $ref: './common.yaml#/components/responses/UnexpectedError' + /api/v2/organizations/{organizationId}/imports: + parameters: + - $ref: './common.yaml#/components/parameters/OrganizationId' + post: + tags: [Moving to OpenBot Cloud] + operationId: createImport + summary: Start importing a bundle into this organization + description: >- + Start an import of what the caller is moving from an OpenBot on their + own computer into this organization, the caller's own organization by + default. Everything imported belongs to the caller, in this + organization only. The answer carries recipientKey, a public key made + for this import alone: pass it to createExport, and a model key in the + bundle is sealed to it, readable only by this import. The answer also + says how big a bundle and a part may be. Then upload the export's + parts with uploadImportPart and apply them with applyImport. + + + Importing is safe to repeat: an import of the same OpenBot into the + same organization (an export made again, or a new import after a + dropped one) adds only what isn't here yet and duplicates nothing. + Served only by OpenBot Cloud; elsewhere it answers 404 with the code + MOVE_UNAVAILABLE. A person starts at most 10 imports a day. + security: + - webSession: [] + - appOAuth: [imports:write] + - apiKey: [] + parameters: + - $ref: './common.yaml#/components/parameters/IdempotencyKey' + requestBody: + required: false + content: + application/json: + schema: + $ref: '#/components/schemas/ImportInput' + responses: + '201': + description: The import, waiting for its bundle. + headers: + Cache-Control: + $ref: './common.yaml#/components/headers/PrivateNoStore' + content: + application/json: + schema: + $ref: '#/components/schemas/Import' + examples: + waiting: + $ref: '#/components/examples/ImportWaitingExample' + '400': + $ref: './common.yaml#/components/responses/InvalidRequest' + '401': + $ref: './common.yaml#/components/responses/Unauthenticated' + '404': + $ref: '#/components/responses/MoveUnavailable' + '409': + $ref: './common.yaml#/components/responses/IdempotencyConflict' + '429': + $ref: '#/components/responses/TooManyMoves' + '500': + $ref: './common.yaml#/components/responses/ServerError' + default: + $ref: './common.yaml#/components/responses/UnexpectedError' + get: + tags: [Moving to OpenBot Cloud] + operationId: listImports + summary: List the caller's imports into this organization + description: >- + List the imports the caller started in this organization, newest + first, so an app that lost track of one after a drop finds it again. + Only the caller's own. Served only by OpenBot Cloud. + security: + - webSession: [] + - appOAuth: [imports:read] + - apiKey: [] + parameters: + - $ref: './common.yaml#/components/parameters/Limit' + - $ref: './common.yaml#/components/parameters/Cursor' + responses: + '200': + description: A page of imports. + headers: + Cache-Control: + $ref: './common.yaml#/components/headers/PrivateNoStore' + content: + application/json: + schema: + $ref: '#/components/schemas/ImportPage' + examples: + page: + $ref: '#/components/examples/ImportPageExample' + '400': + $ref: './common.yaml#/components/responses/InvalidRequest' + '401': + $ref: './common.yaml#/components/responses/Unauthenticated' + '404': + $ref: '#/components/responses/MoveUnavailable' + '500': + $ref: './common.yaml#/components/responses/ServerError' + default: + $ref: './common.yaml#/components/responses/UnexpectedError' + /api/v2/organizations/{organizationId}/imports/{importId}: + parameters: + - $ref: './common.yaml#/components/parameters/OrganizationId' + - $ref: '#/components/parameters/ImportId' + get: + tags: [Moving to OpenBot Cloud] + operationId: getImport + summary: Read an import + description: >- + Return where the caller's import stands: which parts have arrived, + how far applying them has got by kind, and once imported, the + summary: what was imported, what was imported differently or left + out on OpenBot Cloud and why (notes), and which apps to connect + again (reconnect). Only the person who started it reads it. + security: + - webSession: [] + - appOAuth: [imports:read] + - apiKey: [] + responses: + '200': + description: The import. + headers: + Cache-Control: + $ref: './common.yaml#/components/headers/PrivateNoStore' + content: + application/json: + schema: + $ref: '#/components/schemas/Import' + examples: + waiting: + $ref: '#/components/examples/ImportWaitingExample' + imported: + $ref: '#/components/examples/ImportImportedExample' + '401': + $ref: './common.yaml#/components/responses/Unauthenticated' + '404': + $ref: '#/components/responses/ImportNotFound' + '500': + $ref: './common.yaml#/components/responses/ServerError' + default: + $ref: './common.yaml#/components/responses/UnexpectedError' + /api/v2/organizations/{organizationId}/imports/{importId}/parts/{partNumber}: + parameters: + - $ref: './common.yaml#/components/parameters/OrganizationId' + - $ref: '#/components/parameters/ImportId' + - $ref: '#/components/parameters/PartNumber' + put: + tags: [Moving to OpenBot Cloud] + operationId: uploadImportPart + summary: Upload one part of the bundle + description: >- + Upload one part of the export's bundle, exactly as downloadExportPart + gave it. Part 1 carries the bundle's manifest, so it is uploaded + first; after it the parts go in any order, and the import's + expectedParts says how many there are and the SHA-256 of each. A part + whose bytes don't match the manifest is refused (IMPORT_PART_MISMATCH) + and can be uploaded again. Uploading a part that already arrived + changes nothing and answers 200 again, so after a drop an app sends + whatever receivedParts doesn't list. A part is at most 32 MiB, and a + bundle at most maxBundleBytes. At most 120 parts a minute for each + person. + security: + - webSession: [] + - appOAuth: [imports:write] + - apiKey: [] + parameters: + - $ref: './common.yaml#/components/parameters/IdempotencyKey' + requestBody: + required: true + content: + application/octet-stream: + schema: + type: string + format: binary + responses: + '200': + description: The part arrived (or had already arrived). + headers: + Cache-Control: + $ref: './common.yaml#/components/headers/PrivateNoStore' + content: + application/json: + schema: + $ref: '#/components/schemas/Import' + examples: + receiving: + $ref: '#/components/examples/ImportReceivingExample' + '400': + $ref: './common.yaml#/components/responses/InvalidRequest' + '401': + $ref: './common.yaml#/components/responses/Unauthenticated' + '404': + $ref: '#/components/responses/ImportNotFound' + '409': + $ref: '#/components/responses/ImportConflict' + '413': + $ref: './common.yaml#/components/responses/PayloadTooLarge' + '422': + $ref: '#/components/responses/ImportBundleRefused' + '429': + $ref: '#/components/responses/TooManyMoves' + '500': + $ref: './common.yaml#/components/responses/ServerError' + default: + $ref: './common.yaml#/components/responses/UnexpectedError' + /api/v2/organizations/{organizationId}/imports/{importId}/apply: + parameters: + - $ref: './common.yaml#/components/parameters/OrganizationId' + - $ref: '#/components/parameters/ImportId' + post: + tags: [Moving to OpenBot Cloud] + operationId: applyImport + summary: Import the uploaded bundle + description: >- + Once every part has arrived, import the bundle into this organization + in the background: every id is given a new one here, everything is + owned by the caller, and nothing reaches another organization. Every + file is stored where a file uploaded here is, in this organization's + own place in OpenBot's file store, and the uploaded parts are removed + once the import is done. Read + getImport until status is imported or failed. Applying again while it + runs, or after it finished, changes nothing and answers where it + stands; applying a failed import tries again from where it stopped, + and nothing already imported is imported twice. A missing part + answers 409 with IMPORT_INCOMPLETE. + + + What OpenBot Cloud doesn't have comes in differently, and the summary + says so in notes: a Bot that ran on its own isolated computer comes + in as an ordinary Bot; a feature that needs the Business plan, in an + organization that isn't on it, is left out. A model key in the bundle + becomes the caller's own AI connection, unless they have one here + already, which is kept. + security: + - webSession: [] + - appOAuth: [imports:write] + - apiKey: [] + parameters: + - $ref: './common.yaml#/components/parameters/IdempotencyKey' + responses: + '202': + description: Importing, or where the import stands. + headers: + Cache-Control: + $ref: './common.yaml#/components/headers/PrivateNoStore' + content: + application/json: + schema: + $ref: '#/components/schemas/Import' + examples: + importing: + $ref: '#/components/examples/ImportImportingExample' + '401': + $ref: './common.yaml#/components/responses/Unauthenticated' + '404': + $ref: '#/components/responses/ImportNotFound' + '409': + $ref: '#/components/responses/ImportConflict' + '500': + $ref: './common.yaml#/components/responses/ServerError' + default: + $ref: './common.yaml#/components/responses/UnexpectedError' + /api/v2/organizations/{organizationId}/imports/{importId}/verification: + parameters: + - $ref: './common.yaml#/components/parameters/OrganizationId' + - $ref: '#/components/parameters/ImportId' + get: + tags: [Moving to OpenBot Cloud] + operationId: getImportVerification + summary: Check that everything arrived + description: >- + Count, by kind, what from this import's OpenBot is in this + organization now, read from what is stored here rather than from the + import's own tally, beside what the bundle held. matches is true only + when every kind is all here, apart from what the notes say OpenBot + Cloud left out on purpose. OpenBot Desktop removes nothing on the + person's computer until it does. Also lists the apps to connect again. + x-openbot-singleton: true + security: + - webSession: [] + - appOAuth: [imports:read] + - apiKey: [] + responses: + '200': + description: The counts. + headers: + Cache-Control: + $ref: './common.yaml#/components/headers/PrivateNoStore' + content: + application/json: + schema: + $ref: '#/components/schemas/ImportVerification' + examples: + matches: + $ref: '#/components/examples/ImportVerificationExample' + '401': + $ref: './common.yaml#/components/responses/Unauthenticated' + '404': + $ref: '#/components/responses/ImportNotFound' + '409': + $ref: '#/components/responses/ImportConflict' + '500': + $ref: './common.yaml#/components/responses/ServerError' + default: + $ref: './common.yaml#/components/responses/UnexpectedError' +components: + parameters: + ExportId: + name: exportId + in: path + required: true + description: The export's id. + schema: + type: string + minLength: 1 + maxLength: 64 + pattern: ^[A-Za-z0-9_-]+$ + example: exp_7d1f2c3b8a4e4b5f + ImportId: + name: importId + in: path + required: true + description: The import's id. + schema: + type: string + minLength: 1 + maxLength: 64 + pattern: ^[A-Za-z0-9_-]+$ + example: imp_0e1f2a3b4c5d6f1d + PartNumber: + name: partNumber + in: path + required: true + description: Which part of the bundle, counted from 1. + schema: + type: integer + minimum: 1 + maximum: 10000 + example: 1 + headers: + PartETag: + description: The part's SHA-256 in hex, quoted. + schema: + type: string + example: '"9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"' + AcceptRanges: + description: A part can be downloaded a byte range at a time. + schema: + type: string + const: bytes + schemas: + MoveKind: + type: string + x-extensible-enum: + - bots + - skills + - conversations + - messages + - memories + - routines + - goals + - check-ins + - files + - settings + - model-keys + description: >- + A kind of thing that moves. bots: Bots with their settings and + instructions. skills: skills, a Bot's and the person's (and the + organization's, for an administrator). conversations and messages: + every conversation and every message in it. memories: what the + person's Bots remember about them. routines, goals and check-ins: + with their schedules. files: files sent in conversations and kept on + a Bot's computer. settings: the person's standing instructions and + preferences. model-keys: a model key, only when the person chose to + bring it. A later OpenBot may add a kind; count one you don't know + like any other. + MoveCount: + type: object + required: [kind, count] + properties: + kind: + $ref: '#/components/schemas/MoveKind' + count: + type: integer + minimum: 0 + bytes: + type: integer + minimum: 0 + description: For files, how many bytes they hold together. + ReconnectApp: + type: object + description: >- + A connection to an app that doesn't move, because its sign-in stays + on the person's computer: the person connects it again on OpenBot + Cloud. Never carries a token, a password or a key. + required: [appId, appName] + properties: + appId: + type: string + minLength: 1 + description: The app's id in the app directory, such as gmail or slack. + appName: + type: string + minLength: 1 + description: The app's name as a person reads it. + accountLabel: + type: string + minLength: 1 + description: Which account it was connected as, such as an email address or a workspace name, when known. + iconUrl: + type: string + format: uri + description: The app's icon, when the directory has one. + botNames: + type: array + description: The Bots that used it, so the person knows which to check. + items: + type: string + MoveNote: + type: object + description: >- + Something that moved differently, or not at all, and why, in a + sentence a person reads. + required: [code, message] + properties: + code: + type: string + x-extensible-enum: + - isolated-bot-made-ordinary + - business-plan-feature-left-out + - model-key-kept-existing + - model-key-not-brought + - item-skipped + description: >- + isolated-bot-made-ordinary: OpenBot Cloud has no isolated + computers, so a Bot that had one runs on an ordinary one. + business-plan-feature-left-out: the feature needs the Business + plan and this organization isn't on it. model-key-kept-existing: + the person already had an AI connection here, which was kept. + model-key-not-brought: the person chose not to bring a model key. + item-skipped: one item couldn't be imported; message says which + and why. A later OpenBot may add a code; show the message. + kind: + $ref: '#/components/schemas/MoveKind' + count: + type: integer + minimum: 1 + description: How many items the note is about. + message: + type: string + minLength: 1 + items: + type: array + description: The names of the items, such as the Bots, when there are a few. + items: + type: string + ExportEstimate: + type: object + required: [counts, estimatedBytes, storedBytes, reconnect, modelKeysAvailable] + properties: + counts: + type: array + items: + $ref: '#/components/schemas/MoveCount' + estimatedBytes: + type: integer + minimum: 0 + description: Roughly how big the bundle will be, in bytes. + storedBytes: + type: integer + minimum: 0 + description: >- + How much this OpenBot keeps on disk for the person (its database + and files), which removing it frees. OpenBot Desktop adds what the + engine itself takes. + reconnect: + type: array + items: + $ref: '#/components/schemas/ReconnectApp' + modelKeysAvailable: + type: boolean + description: True when there is a model key the person could choose to bring. + ExportInput: + type: object + additionalProperties: false + properties: + includeModelKeys: + type: boolean + default: false + description: >- + Bring the person's model key, sealed to recipientKey. Without + recipientKey this is refused. + recipientKey: + $ref: '#/components/schemas/MoveRecipientKey' + MoveRecipientKey: + type: object + description: >- + A public key as a JSON Web Key (RFC 7517): RSA, 4096 bits, for + RSA-OAEP-256. A model key is sealed to it as a JWE (RFC 7516, + RSA-OAEP-256 with A256GCM), so only the import that made it reads + it. + additionalProperties: false + required: [kty, n, e, alg, kid] + properties: + kty: + type: string + const: RSA + n: + type: string + minLength: 1 + maxLength: 1024 + e: + type: string + minLength: 1 + maxLength: 16 + alg: + type: string + const: RSA-OAEP-256 + kid: + type: string + minLength: 1 + maxLength: 128 + BundlePart: + type: object + required: [number, bytes, sha256] + properties: + number: + type: integer + minimum: 1 + bytes: + type: integer + minimum: 1 + sha256: + type: string + pattern: ^[0-9a-f]{64}$ + Export: + type: object + required: [id, status, createdAt, expiresAt, includesModelKeys] + properties: + id: + type: string + minLength: 1 + status: + type: string + x-extensible-enum: [preparing, ready, failed] + description: >- + preparing: the bundle is being written. ready: every part can be + downloaded. failed: it stopped; error says why, and starting + another export tries again. A later OpenBot may add a status; + read one you don't know as preparing. + formatVersion: + type: integer + minimum: 1 + description: The bundle's format, once ready. This OpenBot writes 1. + createdAt: + type: string + format: date-time + expiresAt: + type: string + format: date-time + description: When the bundle is removed. + totalBytes: + type: integer + minimum: 0 + description: The bundle's size, once ready. + parts: + type: array + description: The bundle's parts in order, once ready. + items: + $ref: '#/components/schemas/BundlePart' + counts: + type: array + description: Everything in the bundle by kind, once ready. + items: + $ref: '#/components/schemas/MoveCount' + reconnect: + type: array + description: The apps to connect again on OpenBot Cloud. + items: + $ref: '#/components/schemas/ReconnectApp' + includesModelKeys: + type: boolean + progress: + type: number + minimum: 0 + maximum: 1 + description: How far writing the bundle has got, while preparing. + error: + type: string + minLength: 1 + description: What went wrong, when failed, in a sentence a person reads. + ImportInput: + type: object + additionalProperties: false + properties: + sourceName: + type: string + minLength: 1 + maxLength: 200 + description: A name for where the bundle comes from, such as the computer's name, shown in the list of imports. + Import: + type: object + required: [id, status, createdAt, recipientKey, maxBundleBytes, maxPartBytes, receivedParts] + properties: + id: + type: string + minLength: 1 + status: + type: string + x-extensible-enum: [waiting-for-bundle, receiving, ready, importing, imported, failed] + description: >- + waiting-for-bundle: no part has arrived. receiving: part 1 has + arrived and others are still to come. ready: every part arrived; + apply it. importing: being imported. imported: done; read the + summary, then verify. failed: it stopped; error says why, and + applying again goes on from there. A later OpenBot may add a + status; read one you don't know as importing. + sourceName: + type: string + createdAt: + type: string + format: date-time + finishedAt: + type: string + format: date-time + recipientKey: + $ref: '#/components/schemas/MoveRecipientKey' + maxBundleBytes: + type: integer + minimum: 1 + maxPartBytes: + type: integer + minimum: 1 + expectedParts: + type: array + description: The bundle's parts, from its manifest, once part 1 arrived. + items: + $ref: '#/components/schemas/BundlePart' + receivedParts: + type: array + description: The numbers of the parts that arrived. + items: + type: integer + minimum: 1 + expected: + type: array + description: Everything the bundle holds by kind, from its manifest, once part 1 arrived. + items: + $ref: '#/components/schemas/MoveCount' + imported: + type: array + description: >- + What has been imported so far by kind, while importing and once + imported. Items a repeated import found already here count as + imported. + items: + $ref: '#/components/schemas/MoveCount' + notes: + type: array + items: + $ref: '#/components/schemas/MoveNote' + reconnect: + type: array + description: The apps to connect again here, once part 1 arrived. + items: + $ref: '#/components/schemas/ReconnectApp' + error: + type: string + minLength: 1 + description: What went wrong, when failed, in a sentence a person reads. + ImportPage: + type: object + required: [items, nextCursor] + properties: + items: + type: array + items: + $ref: '#/components/schemas/Import' + nextCursor: + type: [string, 'null'] + ImportVerificationKind: + type: object + required: [kind, expected, found, leftOut] + properties: + kind: + $ref: '#/components/schemas/MoveKind' + expected: + type: integer + minimum: 0 + description: How many the bundle held. + found: + type: integer + minimum: 0 + description: How many from this OpenBot are in this organization now. + leftOut: + type: integer + minimum: 0 + description: How many OpenBot Cloud left out on purpose, as the notes say. + expectedBytes: + type: integer + minimum: 0 + description: For files, how many bytes the bundle held. + foundBytes: + type: integer + minimum: 0 + description: >- + For files, how many bytes are in this organization's file store + now, read from the store itself. + ImportVerification: + type: object + required: [importId, matches, kinds, notes, reconnect] + properties: + importId: + type: string + minLength: 1 + matches: + type: boolean + description: >- + True when, for every kind, found plus leftOut is expected, and for + files foundBytes is expectedBytes. + kinds: + type: array + items: + $ref: '#/components/schemas/ImportVerificationKind' + notes: + type: array + items: + $ref: '#/components/schemas/MoveNote' + reconnect: + type: array + items: + $ref: '#/components/schemas/ReconnectApp' + responses: + MoveUnavailable: + description: >- + Moving isn't served here: exports only by an OpenBot on the person's + own computer, imports only by OpenBot Cloud. + content: + application/problem+json: + schema: + $ref: './common.yaml#/components/schemas/Problem' + examples: + unavailable: + value: + type: https://open.bot/errors/move-unavailable + title: Moving isn't available here. + status: 404 + detail: Importing is available only on OpenBot Cloud. + code: MOVE_UNAVAILABLE + category: not_found + retryable: false + requestId: req_example + traceId: trace_example + ExportNotFound: + description: The export doesn't exist, has been removed, or isn't the caller's. + content: + application/problem+json: + schema: + $ref: './common.yaml#/components/schemas/Problem' + examples: + notFound: + value: + type: https://open.bot/errors/export-not-found + title: Export not found. + status: 404 + detail: That export isn't here any more. Start the move again. + code: EXPORT_NOT_FOUND + category: not_found + retryable: false + requestId: req_example + traceId: trace_example + ExportNotReady: + description: The export is still being written, or failed. + content: + application/problem+json: + schema: + $ref: './common.yaml#/components/schemas/Problem' + examples: + preparing: + value: + type: https://open.bot/errors/export-not-ready + title: The export isn't ready. + status: 409 + detail: The export is still being prepared. Try again when it's ready. + code: EXPORT_NOT_READY + category: conflict + retryable: true + requestId: req_example + traceId: trace_example + RangeNotSatisfiable: + description: The Range asked for lies outside the part. + content: + application/problem+json: + schema: + $ref: './common.yaml#/components/schemas/Problem' + examples: + outside: + value: + type: https://open.bot/errors/range-not-satisfiable + title: That range isn't in the part. + status: 416 + detail: The part is 33554432 bytes long. + code: RANGE_NOT_SATISFIABLE + category: validation + retryable: false + requestId: req_example + traceId: trace_example + ImportNotFound: + description: The import doesn't exist, or isn't the caller's. + content: + application/problem+json: + schema: + $ref: './common.yaml#/components/schemas/Problem' + examples: + notFound: + value: + type: https://open.bot/errors/import-not-found + title: Import not found. + status: 404 + detail: That import isn't here. Start the move again. + code: IMPORT_NOT_FOUND + category: not_found + retryable: false + requestId: req_example + traceId: trace_example + ImportConflict: + description: >- + The import can't do that in its state: a part doesn't match the + manifest (IMPORT_PART_MISMATCH), part 1 hasn't arrived + (IMPORT_MANIFEST_MISSING), a part is missing (IMPORT_INCOMPLETE), the + import hasn't finished (IMPORT_NOT_FINISHED), or the Idempotency-Key + was used for a different request. + content: + application/problem+json: + schema: + $ref: './common.yaml#/components/schemas/Problem' + examples: + incomplete: + value: + type: https://open.bot/errors/import-incomplete + title: Some parts haven't arrived. + status: 409 + detail: Parts 3 and 4 haven't arrived yet. Upload them, then import. + code: IMPORT_INCOMPLETE + category: conflict + retryable: false + requestId: req_example + traceId: trace_example + mismatch: + value: + type: https://open.bot/errors/import-part-mismatch + title: That part doesn't match the bundle. + status: 409 + detail: Part 2 arrived damaged. Download it again and upload it. + code: IMPORT_PART_MISMATCH + category: conflict + retryable: true + requestId: req_example + traceId: trace_example + ImportBundleRefused: + description: >- + Part 1 isn't a bundle this OpenBot reads: not a bundle at all, a + format newer than it reads (IMPORT_FORMAT_UNSUPPORTED), larger than + maxBundleBytes, or a model key sealed to another import's key. + content: + application/problem+json: + schema: + $ref: './common.yaml#/components/schemas/Problem' + examples: + newer: + value: + type: https://open.bot/errors/import-format-unsupported + title: This bundle is newer than OpenBot Cloud reads. + status: 422 + detail: This bundle was made by a newer OpenBot. Try again once OpenBot Cloud is updated. + code: IMPORT_FORMAT_UNSUPPORTED + category: validation + retryable: false + requestId: req_example + traceId: trace_example + TooManyMoves: + description: Too many exports, imports or parts at once for one person. + headers: + Retry-After: + description: Seconds to wait. + schema: + type: integer + minimum: 1 + content: + application/problem+json: + schema: + $ref: './common.yaml#/components/schemas/Problem' + examples: + tooMany: + value: + type: https://open.bot/errors/rate-limited + title: Too many requests. + status: 429 + detail: That's a lot of uploads at once. Wait a minute, then go on. + code: RATE_LIMITED + category: rate_limit + retryable: true + requestId: req_example + traceId: trace_example + examples: + ExportEstimateExample: + value: + counts: + - { kind: bots, count: 4 } + - { kind: skills, count: 9 } + - { kind: conversations, count: 37 } + - { kind: messages, count: 2814 } + - { kind: memories, count: 52 } + - { kind: routines, count: 3 } + - { kind: goals, count: 1 } + - { kind: check-ins, count: 2 } + - { kind: files, count: 64 } + - { kind: settings, count: 1 } + estimatedBytes: 187432960 + storedBytes: 1288490188 + reconnect: + - { appId: gmail, appName: Gmail, accountLabel: sam@example.com, botNames: [Inbox helper] } + - { appId: slack, appName: Slack, accountLabel: Example workspace, botNames: [Inbox helper, Standup] } + modelKeysAvailable: true + ExportInputExample: + value: + includeModelKeys: true + recipientKey: + kty: RSA + alg: RSA-OAEP-256 + kid: imp_0e1f2a3b4c5d6f1d + e: AQAB + n: 0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw + ExportPreparingExample: + value: + id: exp_7d1f2c3b8a4e4b5f + status: preparing + createdAt: '2026-11-21T10:00:00Z' + expiresAt: '2026-11-28T10:00:00Z' + includesModelKeys: true + progress: 0.4 + ExportReadyExample: + value: + id: exp_7d1f2c3b8a4e4b5f + status: ready + formatVersion: 1 + createdAt: '2026-11-21T10:00:00Z' + expiresAt: '2026-11-28T10:00:00Z' + totalBytes: 41943040 + parts: + - { number: 1, bytes: 33554432, sha256: 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08 } + - { number: 2, bytes: 8388608, sha256: 60303ae22b998861bce3b28f33eec1be758a213c86c93c076dbe9f558c11c752 } + counts: + - { kind: bots, count: 4 } + - { kind: conversations, count: 37 } + - { kind: messages, count: 2814 } + - { kind: model-keys, count: 1 } + reconnect: + - { appId: gmail, appName: Gmail, accountLabel: sam@example.com } + includesModelKeys: true + ImportWaitingExample: + value: + id: imp_0e1f2a3b4c5d6f1d + status: waiting-for-bundle + sourceName: Sam's MacBook + createdAt: '2026-11-21T10:00:00Z' + recipientKey: + kty: RSA + alg: RSA-OAEP-256 + kid: imp_0e1f2a3b4c5d6f1d + e: AQAB + n: 0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw + maxBundleBytes: 10737418240 + maxPartBytes: 33554432 + receivedParts: [] + ImportReceivingExample: + value: + id: imp_0e1f2a3b4c5d6f1d + status: receiving + createdAt: '2026-11-21T10:00:00Z' + recipientKey: + kty: RSA + alg: RSA-OAEP-256 + kid: imp_0e1f2a3b4c5d6f1d + e: AQAB + n: 0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw + maxBundleBytes: 10737418240 + maxPartBytes: 33554432 + expectedParts: + - { number: 1, bytes: 2048, sha256: 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08 } + - { number: 2, bytes: 8388608, sha256: 60303ae22b998861bce3b28f33eec1be758a213c86c93c076dbe9f558c11c752 } + receivedParts: [1] + expected: + - { kind: bots, count: 4 } + - { kind: conversations, count: 37 } + - { kind: messages, count: 2814 } + reconnect: + - { appId: gmail, appName: Gmail, accountLabel: sam@example.com } + ImportImportingExample: + value: + id: imp_0e1f2a3b4c5d6f1d + status: importing + createdAt: '2026-11-21T10:00:00Z' + recipientKey: + kty: RSA + alg: RSA-OAEP-256 + kid: imp_0e1f2a3b4c5d6f1d + e: AQAB + n: 0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw + maxBundleBytes: 10737418240 + maxPartBytes: 33554432 + receivedParts: [1, 2] + expected: + - { kind: bots, count: 4 } + - { kind: conversations, count: 37 } + imported: + - { kind: bots, count: 4 } + - { kind: conversations, count: 12 } + ImportPageExample: + value: + items: + - id: imp_0e1f2a3b4c5d6f1d + status: waiting-for-bundle + sourceName: Sam's MacBook + createdAt: '2026-11-21T10:00:00Z' + recipientKey: + kty: RSA + alg: RSA-OAEP-256 + kid: imp_0e1f2a3b4c5d6f1d + e: AQAB + n: 0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw + maxBundleBytes: 10737418240 + maxPartBytes: 33554432 + receivedParts: [] + nextCursor: null + ImportImportedExample: + value: + id: imp_0e1f2a3b4c5d6f1d + status: imported + createdAt: '2026-11-21T10:00:00Z' + finishedAt: '2026-11-21T10:03:12Z' + recipientKey: + kty: RSA + alg: RSA-OAEP-256 + kid: imp_0e1f2a3b4c5d6f1d + e: AQAB + n: 0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw + maxBundleBytes: 10737418240 + maxPartBytes: 33554432 + expectedParts: + - { number: 1, bytes: 33554432, sha256: 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08 } + - { number: 2, bytes: 8388608, sha256: 60303ae22b998861bce3b28f33eec1be758a213c86c93c076dbe9f558c11c752 } + receivedParts: [1, 2] + expected: + - { kind: bots, count: 4 } + - { kind: conversations, count: 37 } + - { kind: messages, count: 2814 } + imported: + - { kind: bots, count: 4 } + - { kind: conversations, count: 37 } + - { kind: messages, count: 2814 } + notes: + - code: isolated-bot-made-ordinary + kind: bots + count: 1 + message: Research runs on an ordinary computer here, because OpenBot Cloud has no isolated computers. + items: [Research] + reconnect: + - { appId: gmail, appName: Gmail, accountLabel: sam@example.com } + ImportVerificationExample: + value: + importId: imp_0e1f2a3b4c5d6f1d + matches: true + kinds: + - { kind: bots, expected: 4, found: 4, leftOut: 0 } + - { kind: conversations, expected: 37, found: 37, leftOut: 0 } + - { kind: messages, expected: 2814, found: 2814, leftOut: 0 } + - { kind: files, expected: 64, found: 64, leftOut: 0, expectedBytes: 152043520, foundBytes: 152043520 } + notes: [] + reconnect: + - { appId: gmail, appName: Gmail, accountLabel: sam@example.com } diff --git a/app/orval.config.ts b/app/orval.config.ts index df4df16aee..b2f5f6b47f 100644 --- a/app/orval.config.ts +++ b/app/orval.config.ts @@ -41,6 +41,10 @@ export default defineConfig({ mutator: { path: "src/lib/api/request.ts", name: "apiRequest" }, fetch: { includeHttpResponseReturnType: false }, query: { signal: true }, + operations: { + // A part of a move's bundle is bytes, which no example in the spec can be: an empty one. + downloadExportPart: { mock: { data: new Blob([]) } }, + }, }, }, hooks: { afterAllFilesWrite: "bunx biome format --write" }, diff --git a/app/src/lib/api/generated/index.ts b/app/src/lib/api/generated/index.ts index 66ef6527f1..c2e5130413 100644 --- a/app/src/lib/api/generated/index.ts +++ b/app/src/lib/api/generated/index.ts @@ -28,6 +28,7 @@ export * from "./learning/learning"; export * from "./linked-accounts/linked-accounts"; export * from "./memory/memory"; export * from "./models/models"; +export * from "./moving-to-openbot-cloud/moving-to-openbot-cloud"; export * from "./network-policies/network-policies"; export * from "./notification-settings/notification-settings"; export * from "./organization-settings/organization-settings"; diff --git a/app/src/lib/api/generated/index.zod.ts b/app/src/lib/api/generated/index.zod.ts index 64afd6778c..4d4e81220f 100644 --- a/app/src/lib/api/generated/index.zod.ts +++ b/app/src/lib/api/generated/index.zod.ts @@ -28,6 +28,7 @@ export * from "./learning/learning.zod"; export * from "./linked-accounts/linked-accounts.zod"; export * from "./memory/memory.zod"; export * from "./models/models.zod"; +export * from "./moving-to-openbot-cloud/moving-to-openbot-cloud.zod"; export * from "./network-policies/network-policies.zod"; export * from "./notification-settings/notification-settings.zod"; export * from "./organization-settings/organization-settings.zod"; diff --git a/app/src/lib/api/generated/model/applyImportHeaders.ts b/app/src/lib/api/generated/model/applyImportHeaders.ts new file mode 100644 index 0000000000..665b8ca081 --- /dev/null +++ b/app/src/lib/api/generated/model/applyImportHeaders.ts @@ -0,0 +1,13 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ +import type { IdempotencyKeyParameter } from "./idempotencyKeyParameter"; + +export type ApplyImportHeaders = { + /** + * Generated by the caller for each write it means to make once. Reuse the same key and the same request for 24 hours after an uncertain response; the same key with a different request is a conflict. + * @minLength 1 + * @maxLength 128 + */ + "Idempotency-Key": IdempotencyKeyParameter; +}; diff --git a/app/src/lib/api/generated/model/bundlePart.ts b/app/src/lib/api/generated/model/bundlePart.ts new file mode 100644 index 0000000000..f35f029f79 --- /dev/null +++ b/app/src/lib/api/generated/model/bundlePart.ts @@ -0,0 +1,12 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ + +export interface BundlePart { + /** @minimum 1 */ + number: number; + /** @minimum 1 */ + bytes: number; + /** @pattern ^[0-9a-f]{64}$ */ + sha256: string; +} diff --git a/app/src/lib/api/generated/model/createExportHeaders.ts b/app/src/lib/api/generated/model/createExportHeaders.ts new file mode 100644 index 0000000000..6ad4a50cbd --- /dev/null +++ b/app/src/lib/api/generated/model/createExportHeaders.ts @@ -0,0 +1,13 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ +import type { IdempotencyKeyParameter } from "./idempotencyKeyParameter"; + +export type CreateExportHeaders = { + /** + * Generated by the caller for each write it means to make once. Reuse the same key and the same request for 24 hours after an uncertain response; the same key with a different request is a conflict. + * @minLength 1 + * @maxLength 128 + */ + "Idempotency-Key": IdempotencyKeyParameter; +}; diff --git a/app/src/lib/api/generated/model/createImportHeaders.ts b/app/src/lib/api/generated/model/createImportHeaders.ts new file mode 100644 index 0000000000..0bf3ce48e6 --- /dev/null +++ b/app/src/lib/api/generated/model/createImportHeaders.ts @@ -0,0 +1,13 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ +import type { IdempotencyKeyParameter } from "./idempotencyKeyParameter"; + +export type CreateImportHeaders = { + /** + * Generated by the caller for each write it means to make once. Reuse the same key and the same request for 24 hours after an uncertain response; the same key with a different request is a conflict. + * @minLength 1 + * @maxLength 128 + */ + "Idempotency-Key": IdempotencyKeyParameter; +}; diff --git a/app/src/lib/api/generated/model/deleteExportHeaders.ts b/app/src/lib/api/generated/model/deleteExportHeaders.ts new file mode 100644 index 0000000000..dc904d991d --- /dev/null +++ b/app/src/lib/api/generated/model/deleteExportHeaders.ts @@ -0,0 +1,13 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ +import type { IdempotencyKeyParameter } from "./idempotencyKeyParameter"; + +export type DeleteExportHeaders = { + /** + * Generated by the caller for each write it means to make once. Reuse the same key and the same request for 24 hours after an uncertain response; the same key with a different request is a conflict. + * @minLength 1 + * @maxLength 128 + */ + "Idempotency-Key": IdempotencyKeyParameter; +}; diff --git a/app/src/lib/api/generated/model/downloadExportPartHeaders.ts b/app/src/lib/api/generated/model/downloadExportPartHeaders.ts new file mode 100644 index 0000000000..963c0e5afb --- /dev/null +++ b/app/src/lib/api/generated/model/downloadExportPartHeaders.ts @@ -0,0 +1,12 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ + +export type DownloadExportPartHeaders = { + /** + * One byte range of the part, as RFC 9110 writes it. + * @maxLength 64 + * @pattern ^bytes=[0-9]+-[0-9]*$ + */ + Range?: string; +}; diff --git a/app/src/lib/api/generated/model/export.ts b/app/src/lib/api/generated/model/export.ts new file mode 100644 index 0000000000..38202ef988 --- /dev/null +++ b/app/src/lib/api/generated/model/export.ts @@ -0,0 +1,44 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ +import type { BundlePart } from "./bundlePart"; +import type { MoveCount } from "./moveCount"; +import type { ReconnectApp } from "./reconnectApp"; + +export interface Export { + /** @minLength 1 */ + id: string; + /** preparing: the bundle is being written. ready: every part can be downloaded. failed: it stopped; error says why, and starting another export tries again. A later OpenBot may add a status; read one you don't know as preparing. */ + status: string; + /** + * The bundle's format, once ready. This OpenBot writes 1. + * @minimum 1 + */ + formatVersion?: number; + createdAt: string; + /** When the bundle is removed. */ + expiresAt: string; + /** + * The bundle's size, once ready. + * @minimum 0 + */ + totalBytes?: number; + /** The bundle's parts in order, once ready. */ + parts?: BundlePart[]; + /** Everything in the bundle by kind, once ready. */ + counts?: MoveCount[]; + /** The apps to connect again on OpenBot Cloud. */ + reconnect?: ReconnectApp[]; + includesModelKeys: boolean; + /** + * How far writing the bundle has got, while preparing. + * @minimum 0 + * @maximum 1 + */ + progress?: number; + /** + * What went wrong, when failed, in a sentence a person reads. + * @minLength 1 + */ + error?: string; +} diff --git a/app/src/lib/api/generated/model/exportEstimate.ts b/app/src/lib/api/generated/model/exportEstimate.ts new file mode 100644 index 0000000000..f18ed4a706 --- /dev/null +++ b/app/src/lib/api/generated/model/exportEstimate.ts @@ -0,0 +1,22 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ +import type { MoveCount } from "./moveCount"; +import type { ReconnectApp } from "./reconnectApp"; + +export interface ExportEstimate { + counts: MoveCount[]; + /** + * Roughly how big the bundle will be, in bytes. + * @minimum 0 + */ + estimatedBytes: number; + /** + * How much this OpenBot keeps on disk for the person (its database and files), which removing it frees. OpenBot Desktop adds what the engine itself takes. + * @minimum 0 + */ + storedBytes: number; + reconnect: ReconnectApp[]; + /** True when there is a model key the person could choose to bring. */ + modelKeysAvailable: boolean; +} diff --git a/app/src/lib/api/generated/model/exportInput.ts b/app/src/lib/api/generated/model/exportInput.ts new file mode 100644 index 0000000000..249708d15f --- /dev/null +++ b/app/src/lib/api/generated/model/exportInput.ts @@ -0,0 +1,10 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ +import type { MoveRecipientKey } from "./moveRecipientKey"; + +export interface ExportInput { + /** Bring the person's model key, sealed to recipientKey. Without recipientKey this is refused. */ + includeModelKeys?: boolean; + recipientKey?: MoveRecipientKey; +} diff --git a/app/src/lib/api/generated/model/exportNotFoundResponse.ts b/app/src/lib/api/generated/model/exportNotFoundResponse.ts new file mode 100644 index 0000000000..01722277ab --- /dev/null +++ b/app/src/lib/api/generated/model/exportNotFoundResponse.ts @@ -0,0 +1,9 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ +import type { Problem } from "./problem"; + +/** + * The export doesn't exist, has been removed, or isn't the caller's. + */ +export type ExportNotFoundResponse = Problem; diff --git a/app/src/lib/api/generated/model/exportNotReadyResponse.ts b/app/src/lib/api/generated/model/exportNotReadyResponse.ts new file mode 100644 index 0000000000..7975f001f4 --- /dev/null +++ b/app/src/lib/api/generated/model/exportNotReadyResponse.ts @@ -0,0 +1,9 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ +import type { Problem } from "./problem"; + +/** + * The export is still being written, or failed. + */ +export type ExportNotReadyResponse = Problem; diff --git a/app/src/lib/api/generated/model/import.ts b/app/src/lib/api/generated/model/import.ts new file mode 100644 index 0000000000..1b5ad35e08 --- /dev/null +++ b/app/src/lib/api/generated/model/import.ts @@ -0,0 +1,42 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ +import type { BundlePart } from "./bundlePart"; +import type { MoveCount } from "./moveCount"; +import type { MoveNote } from "./moveNote"; +import type { MoveRecipientKey } from "./moveRecipientKey"; +import type { ReconnectApp } from "./reconnectApp"; + +export interface Import { + /** @minLength 1 */ + id: string; + /** waiting-for-bundle: no part has arrived. receiving: part 1 has arrived and others are still to come. ready: every part arrived; apply it. importing: being imported. imported: done; read the summary, then verify. failed: it stopped; error says why, and applying again goes on from there. A later OpenBot may add a status; read one you don't know as importing. */ + status: string; + sourceName?: string; + createdAt: string; + finishedAt?: string; + recipientKey: MoveRecipientKey; + /** @minimum 1 */ + maxBundleBytes: number; + /** @minimum 1 */ + maxPartBytes: number; + /** The bundle's parts, from its manifest, once part 1 arrived. */ + expectedParts?: BundlePart[]; + /** + * The numbers of the parts that arrived. + * @items.minimum 1 + */ + receivedParts: number[]; + /** Everything the bundle holds by kind, from its manifest, once part 1 arrived. */ + expected?: MoveCount[]; + /** What has been imported so far by kind, while importing and once imported. Items a repeated import found already here count as imported. */ + imported?: MoveCount[]; + notes?: MoveNote[]; + /** The apps to connect again here, once part 1 arrived. */ + reconnect?: ReconnectApp[]; + /** + * What went wrong, when failed, in a sentence a person reads. + * @minLength 1 + */ + error?: string; +} diff --git a/app/src/lib/api/generated/model/importBundleRefusedResponse.ts b/app/src/lib/api/generated/model/importBundleRefusedResponse.ts new file mode 100644 index 0000000000..cc13a01a89 --- /dev/null +++ b/app/src/lib/api/generated/model/importBundleRefusedResponse.ts @@ -0,0 +1,9 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ +import type { Problem } from "./problem"; + +/** + * Part 1 isn't a bundle this OpenBot reads: not a bundle at all, a format newer than it reads (IMPORT_FORMAT_UNSUPPORTED), larger than maxBundleBytes, or a model key sealed to another import's key. + */ +export type ImportBundleRefusedResponse = Problem; diff --git a/app/src/lib/api/generated/model/importConflictResponse.ts b/app/src/lib/api/generated/model/importConflictResponse.ts new file mode 100644 index 0000000000..a8a863b910 --- /dev/null +++ b/app/src/lib/api/generated/model/importConflictResponse.ts @@ -0,0 +1,9 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ +import type { Problem } from "./problem"; + +/** + * The import can't do that in its state: a part doesn't match the manifest (IMPORT_PART_MISMATCH), part 1 hasn't arrived (IMPORT_MANIFEST_MISSING), a part is missing (IMPORT_INCOMPLETE), the import hasn't finished (IMPORT_NOT_FINISHED), or the Idempotency-Key was used for a different request. + */ +export type ImportConflictResponse = Problem; diff --git a/app/src/lib/api/generated/model/importInput.ts b/app/src/lib/api/generated/model/importInput.ts new file mode 100644 index 0000000000..db905e0e3e --- /dev/null +++ b/app/src/lib/api/generated/model/importInput.ts @@ -0,0 +1,12 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ + +export interface ImportInput { + /** + * A name for where the bundle comes from, such as the computer's name, shown in the list of imports. + * @minLength 1 + * @maxLength 200 + */ + sourceName?: string; +} diff --git a/app/src/lib/api/generated/model/importNotFoundResponse.ts b/app/src/lib/api/generated/model/importNotFoundResponse.ts new file mode 100644 index 0000000000..b9a4afbf41 --- /dev/null +++ b/app/src/lib/api/generated/model/importNotFoundResponse.ts @@ -0,0 +1,9 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ +import type { Problem } from "./problem"; + +/** + * The import doesn't exist, or isn't the caller's. + */ +export type ImportNotFoundResponse = Problem; diff --git a/app/src/lib/api/generated/model/importPage.ts b/app/src/lib/api/generated/model/importPage.ts new file mode 100644 index 0000000000..592b9cdc07 --- /dev/null +++ b/app/src/lib/api/generated/model/importPage.ts @@ -0,0 +1,10 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ +import type { Import } from "./import"; + +export interface ImportPage { + items: Import[]; + /** @nullable */ + nextCursor: string | null; +} diff --git a/app/src/lib/api/generated/model/importVerification.ts b/app/src/lib/api/generated/model/importVerification.ts new file mode 100644 index 0000000000..d5f3e0bada --- /dev/null +++ b/app/src/lib/api/generated/model/importVerification.ts @@ -0,0 +1,16 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ +import type { ImportVerificationKind } from "./importVerificationKind"; +import type { MoveNote } from "./moveNote"; +import type { ReconnectApp } from "./reconnectApp"; + +export interface ImportVerification { + /** @minLength 1 */ + importId: string; + /** True when, for every kind, found plus leftOut is expected, and for files foundBytes is expectedBytes. */ + matches: boolean; + kinds: ImportVerificationKind[]; + notes: MoveNote[]; + reconnect: ReconnectApp[]; +} diff --git a/app/src/lib/api/generated/model/importVerificationKind.ts b/app/src/lib/api/generated/model/importVerificationKind.ts new file mode 100644 index 0000000000..9bb8dce352 --- /dev/null +++ b/app/src/lib/api/generated/model/importVerificationKind.ts @@ -0,0 +1,33 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ +import type { MoveKind } from "./moveKind"; + +export interface ImportVerificationKind { + kind: MoveKind; + /** + * How many the bundle held. + * @minimum 0 + */ + expected: number; + /** + * How many from this OpenBot are in this organization now. + * @minimum 0 + */ + found: number; + /** + * How many OpenBot Cloud left out on purpose, as the notes say. + * @minimum 0 + */ + leftOut: number; + /** + * For files, how many bytes the bundle held. + * @minimum 0 + */ + expectedBytes?: number; + /** + * For files, how many bytes are in this organization's file store now, read from the store itself. + * @minimum 0 + */ + foundBytes?: number; +} diff --git a/app/src/lib/api/generated/model/index.ts b/app/src/lib/api/generated/model/index.ts index f9f96ade07..152a3d215b 100644 --- a/app/src/lib/api/generated/model/index.ts +++ b/app/src/lib/api/generated/model/index.ts @@ -77,6 +77,7 @@ export * from "./appDirectoryUnavailableResponse"; export * from "./appError"; export * from "./appErrorSource"; export * from "./appErrorSurface"; +export * from "./applyImportHeaders"; export * from "./appNotFoundResponse"; export * from "./appOAuthClientRequest"; export * from "./appOrTeamNotFoundResponse"; @@ -377,6 +378,7 @@ export * from "./browserUnavailableResponse"; export * from "./browserUnfinishedResponse"; export * from "./browserUnreachableResponse"; export * from "./browserWindow"; +export * from "./bundlePart"; export * from "./callComponentFunctionHeaders"; export * from "./cancelComputerControlHeaders"; export * from "./cancelFollowUpHeaders"; @@ -620,6 +622,7 @@ export * from "./createConversationRequest"; export * from "./createConversationThreadHeaders"; export * from "./createCredentialHeaders"; export * from "./createdApiKey"; +export * from "./createExportHeaders"; export * from "./createGithubEventSourceHeaders"; export * from "./createGithubEventSourceRequest"; export * from "./createGoalHeaders"; @@ -630,6 +633,7 @@ export * from "./createHostAccessGrantHeaders"; export * from "./createHostAccessGrantRequest"; export * from "./createIdentityProviderHeaders"; export * from "./createIdentityProviderRequest"; +export * from "./createImportHeaders"; export * from "./createMemoryHeaders"; export * from "./createMemoryRequest"; export * from "./createMemorySourceHeaders"; @@ -687,6 +691,7 @@ export * from "./deleteConversationParams"; export * from "./deleteCurrentRecorderConnectionHeaders"; export * from "./deleteDestinationHeaders"; export * from "./deleteDeviceHeaders"; +export * from "./deleteExportHeaders"; export * from "./deleteGithubEventSourceHeaders"; export * from "./deleteGoalHeaders"; export * from "./deleteGoalTriggerHeaders"; @@ -739,6 +744,7 @@ export * from "./disconnectSharedAppHeaders"; export * from "./dismissAppAccessRequestHeaders"; export * from "./dismissCheckInItemHeaders"; export * from "./dismissQuestionHeaders"; +export * from "./downloadExportPartHeaders"; export * from "./duplicateBotHeaders"; export * from "./egressRule"; export * from "./egressRuleType"; @@ -747,7 +753,12 @@ export * from "./emailTriggerConfigKind"; export * from "./enableGoalTriggerHeaders"; export * from "./exchangeRecorderConnectCodeHeaders"; export * from "./exchangeRecorderConnectCodeRequest"; +export * from "./export"; export * from "./exportAuditEventsParams"; +export * from "./exportEstimate"; +export * from "./exportInput"; +export * from "./exportNotFoundResponse"; +export * from "./exportNotReadyResponse"; export * from "./finishSignInHeaders"; export * from "./followUpCancelled"; export * from "./followUpNotFoundResponse"; @@ -824,6 +835,14 @@ export * from "./identityProviderProtocol"; export * from "./identityProviderRemovalConflictResponse"; export * from "./identityProviderResponse"; export * from "./identityProviderText"; +export * from "./import"; +export * from "./importBundleRefusedResponse"; +export * from "./importConflictResponse"; +export * from "./importInput"; +export * from "./importNotFoundResponse"; +export * from "./importPage"; +export * from "./importVerification"; +export * from "./importVerificationKind"; export * from "./inactiveComputersStopped"; export * from "./invalidAiConnectionResponse"; export * from "./invalidAppChangeResponse"; @@ -979,6 +998,7 @@ export * from "./listGoalRunsParams"; export * from "./listGoalsParams"; export * from "./listGoalTriggersParams"; export * from "./listIdentityProvidersParams"; +export * from "./listImportsParams"; export * from "./listInvitationsParams"; export * from "./listLearningProposalsParams"; export * from "./listLinkedAccountProvidersParams"; @@ -1059,6 +1079,11 @@ export * from "./modelOption"; export * from "./modelUsage"; export * from "./modelUsageRecentItem"; export * from "./modelUsageSummaryItem"; +export * from "./moveCount"; +export * from "./moveKind"; +export * from "./moveNote"; +export * from "./moveRecipientKey"; +export * from "./moveUnavailableResponse"; export * from "./narrateInBotBrowserHeaders"; export * from "./narrateInPersonBrowserHeaders"; export * from "./navigateBotBrowserHeaders"; @@ -1193,12 +1218,14 @@ export * from "./questionAnswer"; export * from "./questionNotFoundResponse"; export * from "./questionPage"; export * from "./questionPart"; +export * from "./rangeNotSatisfiableResponse"; export * from "./reaction"; export * from "./reactionPage"; export * from "./readComputerFileHeaders"; export * from "./realBrowser"; export * from "./recheckConnectionHeaders"; export * from "./recheckSharedConnectionHeaders"; +export * from "./reconnectApp"; export * from "./recordAppErrorHeaders"; export * from "./recordConversationActivityHeaders"; export * from "./recorderActivity"; @@ -1483,6 +1510,7 @@ export * from "./teamRole"; export * from "./teamSource"; export * from "./testBotConnectionHeaders"; export * from "./textMessagesUnavailableResponse"; +export * from "./tooManyMovesResponse"; export * from "./tooManyPendingRequestsResponse"; export * from "./tooManyRecorderConnectCodesResponse"; export * from "./tooManyRequestsResponse"; @@ -1568,6 +1596,7 @@ export * from "./updateStandingInstructionsHeaders"; export * from "./updateTeamHeaders"; export * from "./updateTeamRequest"; export * from "./uploadConversationAttachmentHeaders"; +export * from "./uploadImportPartHeaders"; export * from "./useSavedLoginHeaders"; export * from "./useSavedLoginRequest"; export * from "./verifyPhoneDestinationHeaders"; diff --git a/app/src/lib/api/generated/model/listImportsParams.ts b/app/src/lib/api/generated/model/listImportsParams.ts new file mode 100644 index 0000000000..b401fc1812 --- /dev/null +++ b/app/src/lib/api/generated/model/listImportsParams.ts @@ -0,0 +1,21 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ +import type { CursorParameter } from "./cursorParameter"; +import type { LimitParameter } from "./limitParameter"; + +export type ListImportsParams = { + /** + * Most items in one page. + * @minimum 1 + * @maximum 100 + */ + limit?: LimitParameter; + /** + * Opaque continuation from the previous page's nextCursor, bound to the organization and the filters that made it. The server only ever issues cursors written in URL-safe base64 (letters, digits, - and _, no padding) and refuses anything else, so the pattern says so. A cursor that fits the pattern can still be refused: one this list never gave out, or one made for another organization or other filters. + * @minLength 1 + * @maxLength 4096 + * @pattern ^[A-Za-z0-9_-]+$ + */ + cursor?: CursorParameter; +}; diff --git a/app/src/lib/api/generated/model/moveCount.ts b/app/src/lib/api/generated/model/moveCount.ts new file mode 100644 index 0000000000..9e2ad5065d --- /dev/null +++ b/app/src/lib/api/generated/model/moveCount.ts @@ -0,0 +1,15 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ +import type { MoveKind } from "./moveKind"; + +export interface MoveCount { + kind: MoveKind; + /** @minimum 0 */ + count: number; + /** + * For files, how many bytes they hold together. + * @minimum 0 + */ + bytes?: number; +} diff --git a/app/src/lib/api/generated/model/moveKind.ts b/app/src/lib/api/generated/model/moveKind.ts new file mode 100644 index 0000000000..f6975660d2 --- /dev/null +++ b/app/src/lib/api/generated/model/moveKind.ts @@ -0,0 +1,8 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ + +/** + * A kind of thing that moves. bots: Bots with their settings and instructions. skills: skills, a Bot's and the person's (and the organization's, for an administrator). conversations and messages: every conversation and every message in it. memories: what the person's Bots remember about them. routines, goals and check-ins: with their schedules. files: files sent in conversations and kept on a Bot's computer. settings: the person's standing instructions and preferences. model-keys: a model key, only when the person chose to bring it. A later OpenBot may add a kind; count one you don't know like any other. + */ +export type MoveKind = string; diff --git a/app/src/lib/api/generated/model/moveNote.ts b/app/src/lib/api/generated/model/moveNote.ts new file mode 100644 index 0000000000..84c73bad89 --- /dev/null +++ b/app/src/lib/api/generated/model/moveNote.ts @@ -0,0 +1,22 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ +import type { MoveKind } from "./moveKind"; + +/** + * Something that moved differently, or not at all, and why, in a sentence a person reads. + */ +export interface MoveNote { + /** isolated-bot-made-ordinary: OpenBot Cloud has no isolated computers, so a Bot that had one runs on an ordinary one. business-plan-feature-left-out: the feature needs the Business plan and this organization isn't on it. model-key-kept-existing: the person already had an AI connection here, which was kept. model-key-not-brought: the person chose not to bring a model key. item-skipped: one item couldn't be imported; message says which and why. A later OpenBot may add a code; show the message. */ + code: string; + kind?: MoveKind; + /** + * How many items the note is about. + * @minimum 1 + */ + count?: number; + /** @minLength 1 */ + message: string; + /** The names of the items, such as the Bots, when there are a few. */ + items?: string[]; +} diff --git a/app/src/lib/api/generated/model/moveRecipientKey.ts b/app/src/lib/api/generated/model/moveRecipientKey.ts new file mode 100644 index 0000000000..b58fb1c2fc --- /dev/null +++ b/app/src/lib/api/generated/model/moveRecipientKey.ts @@ -0,0 +1,26 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ + +/** + * A public key as a JSON Web Key (RFC 7517): RSA, 4096 bits, for RSA-OAEP-256. A model key is sealed to it as a JWE (RFC 7516, RSA-OAEP-256 with A256GCM), so only the import that made it reads it. + */ +export interface MoveRecipientKey { + kty: "RSA"; + /** + * @minLength 1 + * @maxLength 1024 + */ + n: string; + /** + * @minLength 1 + * @maxLength 16 + */ + e: string; + alg: "RSA-OAEP-256"; + /** + * @minLength 1 + * @maxLength 128 + */ + kid: string; +} diff --git a/app/src/lib/api/generated/model/moveUnavailableResponse.ts b/app/src/lib/api/generated/model/moveUnavailableResponse.ts new file mode 100644 index 0000000000..847a116918 --- /dev/null +++ b/app/src/lib/api/generated/model/moveUnavailableResponse.ts @@ -0,0 +1,9 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ +import type { Problem } from "./problem"; + +/** + * Moving isn't served here: exports only by an OpenBot on the person's own computer, imports only by OpenBot Cloud. + */ +export type MoveUnavailableResponse = Problem; diff --git a/app/src/lib/api/generated/model/rangeNotSatisfiableResponse.ts b/app/src/lib/api/generated/model/rangeNotSatisfiableResponse.ts new file mode 100644 index 0000000000..eec0d867a3 --- /dev/null +++ b/app/src/lib/api/generated/model/rangeNotSatisfiableResponse.ts @@ -0,0 +1,9 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ +import type { Problem } from "./problem"; + +/** + * The Range asked for lies outside the part. + */ +export type RangeNotSatisfiableResponse = Problem; diff --git a/app/src/lib/api/generated/model/reconnectApp.ts b/app/src/lib/api/generated/model/reconnectApp.ts new file mode 100644 index 0000000000..2e5e867a57 --- /dev/null +++ b/app/src/lib/api/generated/model/reconnectApp.ts @@ -0,0 +1,28 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ + +/** + * A connection to an app that doesn't move, because its sign-in stays on the person's computer: the person connects it again on OpenBot Cloud. Never carries a token, a password or a key. + */ +export interface ReconnectApp { + /** + * The app's id in the app directory, such as gmail or slack. + * @minLength 1 + */ + appId: string; + /** + * The app's name as a person reads it. + * @minLength 1 + */ + appName: string; + /** + * Which account it was connected as, such as an email address or a workspace name, when known. + * @minLength 1 + */ + accountLabel?: string; + /** The app's icon, when the directory has one. */ + iconUrl?: string; + /** The Bots that used it, so the person knows which to check. */ + botNames?: string[]; +} diff --git a/app/src/lib/api/generated/model/tooManyMovesResponse.ts b/app/src/lib/api/generated/model/tooManyMovesResponse.ts new file mode 100644 index 0000000000..e8b52143ab --- /dev/null +++ b/app/src/lib/api/generated/model/tooManyMovesResponse.ts @@ -0,0 +1,9 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ +import type { Problem } from "./problem"; + +/** + * Too many exports, imports or parts at once for one person. + */ +export type TooManyMovesResponse = Problem; diff --git a/app/src/lib/api/generated/model/uploadImportPartHeaders.ts b/app/src/lib/api/generated/model/uploadImportPartHeaders.ts new file mode 100644 index 0000000000..c8826eb16f --- /dev/null +++ b/app/src/lib/api/generated/model/uploadImportPartHeaders.ts @@ -0,0 +1,13 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ +import type { IdempotencyKeyParameter } from "./idempotencyKeyParameter"; + +export type UploadImportPartHeaders = { + /** + * Generated by the caller for each write it means to make once. Reuse the same key and the same request for 24 hours after an uncertain response; the same key with a different request is a conflict. + * @minLength 1 + * @maxLength 128 + */ + "Idempotency-Key": IdempotencyKeyParameter; +}; diff --git a/app/src/lib/api/generated/moving-to-openbot-cloud/moving-to-openbot-cloud.msw.ts b/app/src/lib/api/generated/moving-to-openbot-cloud/moving-to-openbot-cloud.msw.ts new file mode 100644 index 0000000000..79ad5d8832 --- /dev/null +++ b/app/src/lib/api/generated/moving-to-openbot-cloud/moving-to-openbot-cloud.msw.ts @@ -0,0 +1,562 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ +import { HttpResponse, http } from "msw"; +import type { HttpResponseResolver, RequestHandlerOptions } from "msw"; + +import type { + Export, + ExportEstimate, + ExportInput, + Import, + ImportInput, + ImportPage, + ImportVerification, +} from "../model"; + +export const getGetExportEstimateResponseMock = (): ExportEstimate => ({ + counts: [ + { kind: "bots", count: 4 }, + { kind: "skills", count: 9 }, + { kind: "conversations", count: 37 }, + { kind: "messages", count: 2814 }, + { kind: "memories", count: 52 }, + { kind: "routines", count: 3 }, + { kind: "goals", count: 1 }, + { kind: "check-ins", count: 2 }, + { kind: "files", count: 64 }, + { kind: "settings", count: 1 }, + ], + estimatedBytes: 187432960, + storedBytes: 1288490188, + reconnect: [ + { + appId: "gmail", + appName: "Gmail", + accountLabel: "sam@example.com", + botNames: ["Inbox helper"], + }, + { + appId: "slack", + appName: "Slack", + accountLabel: "Example workspace", + botNames: ["Inbox helper", "Standup"], + }, + ], + modelKeysAvailable: true, +}); + +export const getCreateExportResponseMock = (): Export => ({ + id: "exp_7d1f2c3b8a4e4b5f", + status: "preparing", + createdAt: "2026-11-21T10:00:00Z", + expiresAt: "2026-11-28T10:00:00Z", + includesModelKeys: true, + progress: 0.4, +}); + +export const getGetExportResponseMock = (): Export => ({ + id: "exp_7d1f2c3b8a4e4b5f", + status: "preparing", + createdAt: "2026-11-21T10:00:00Z", + expiresAt: "2026-11-28T10:00:00Z", + includesModelKeys: true, + progress: 0.4, +}); + +export const getDownloadExportPartResponseMock = () => ({}); + +export const getCreateImportResponseMock = (): Import => ({ + id: "imp_0e1f2a3b4c5d6f1d", + status: "waiting-for-bundle", + sourceName: "Sam's MacBook", + createdAt: "2026-11-21T10:00:00Z", + recipientKey: { + kty: "RSA", + alg: "RSA-OAEP-256", + kid: "imp_0e1f2a3b4c5d6f1d", + e: "AQAB", + n: "0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw", + }, + maxBundleBytes: 10737418240, + maxPartBytes: 33554432, + receivedParts: [], +}); + +export const getListImportsResponseMock = (): ImportPage => ({ + items: [ + { + id: "imp_0e1f2a3b4c5d6f1d", + status: "waiting-for-bundle", + sourceName: "Sam's MacBook", + createdAt: "2026-11-21T10:00:00Z", + recipientKey: { + kty: "RSA", + alg: "RSA-OAEP-256", + kid: "imp_0e1f2a3b4c5d6f1d", + e: "AQAB", + n: "0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw", + }, + maxBundleBytes: 10737418240, + maxPartBytes: 33554432, + receivedParts: [], + }, + ], + nextCursor: null, +}); + +export const getGetImportResponseMock = (): Import => ({ + id: "imp_0e1f2a3b4c5d6f1d", + status: "waiting-for-bundle", + sourceName: "Sam's MacBook", + createdAt: "2026-11-21T10:00:00Z", + recipientKey: { + kty: "RSA", + alg: "RSA-OAEP-256", + kid: "imp_0e1f2a3b4c5d6f1d", + e: "AQAB", + n: "0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw", + }, + maxBundleBytes: 10737418240, + maxPartBytes: 33554432, + receivedParts: [], +}); + +export const getUploadImportPartResponseMock = (): Import => ({ + id: "imp_0e1f2a3b4c5d6f1d", + status: "receiving", + createdAt: "2026-11-21T10:00:00Z", + recipientKey: { + kty: "RSA", + alg: "RSA-OAEP-256", + kid: "imp_0e1f2a3b4c5d6f1d", + e: "AQAB", + n: "0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw", + }, + maxBundleBytes: 10737418240, + maxPartBytes: 33554432, + expectedParts: [ + { + number: 1, + bytes: 2048, + sha256: + "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08", + }, + { + number: 2, + bytes: 8388608, + sha256: + "60303ae22b998861bce3b28f33eec1be758a213c86c93c076dbe9f558c11c752", + }, + ], + receivedParts: [1], + expected: [ + { kind: "bots", count: 4 }, + { kind: "conversations", count: 37 }, + { kind: "messages", count: 2814 }, + ], + reconnect: [ + { appId: "gmail", appName: "Gmail", accountLabel: "sam@example.com" }, + ], +}); + +export const getApplyImportResponseMock = (): Import => ({ + id: "imp_0e1f2a3b4c5d6f1d", + status: "importing", + createdAt: "2026-11-21T10:00:00Z", + recipientKey: { + kty: "RSA", + alg: "RSA-OAEP-256", + kid: "imp_0e1f2a3b4c5d6f1d", + e: "AQAB", + n: "0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw", + }, + maxBundleBytes: 10737418240, + maxPartBytes: 33554432, + receivedParts: [1, 2], + expected: [ + { kind: "bots", count: 4 }, + { kind: "conversations", count: 37 }, + ], + imported: [ + { kind: "bots", count: 4 }, + { kind: "conversations", count: 12 }, + ], +}); + +export const getGetImportVerificationResponseMock = (): ImportVerification => ({ + importId: "imp_0e1f2a3b4c5d6f1d", + matches: true, + kinds: [ + { kind: "bots", expected: 4, found: 4, leftOut: 0 }, + { kind: "conversations", expected: 37, found: 37, leftOut: 0 }, + { kind: "messages", expected: 2814, found: 2814, leftOut: 0 }, + { + kind: "files", + expected: 64, + found: 64, + leftOut: 0, + expectedBytes: 152043520, + foundBytes: 152043520, + }, + ], + notes: [], + reconnect: [ + { appId: "gmail", appName: "Gmail", accountLabel: "sam@example.com" }, + ], +}); + +export const getGetExportEstimateMockHandler = ( + overrideResponse?: + | ExportEstimate + | (( + info: Parameters>[0], + ) => Promise | ExportEstimate), + options?: RequestHandlerOptions, +) => { + return http.get<{ organizationId: string }>( + "*/api/v2/organizations/:organizationId/export-estimate", + async ( + info: Parameters>[0], + ) => { + return HttpResponse.json( + overrideResponse !== undefined + ? typeof overrideResponse === "function" + ? await overrideResponse(info) + : overrideResponse + : getGetExportEstimateResponseMock(), + { status: 200 }, + ); + }, + options, + ); +}; + +export const getCreateExportMockHandler = ( + overrideResponse?: + | Export + | (( + info: Parameters< + HttpResponseResolver<{ organizationId: string }, ExportInput> + >[0], + ) => Promise | Export), + options?: RequestHandlerOptions, +) => { + return http.post<{ organizationId: string }, ExportInput>( + "*/api/v2/organizations/:organizationId/exports", + async ( + info: Parameters< + HttpResponseResolver<{ organizationId: string }, ExportInput> + >[0], + ) => { + return HttpResponse.json( + overrideResponse !== undefined + ? typeof overrideResponse === "function" + ? await overrideResponse(info) + : overrideResponse + : getCreateExportResponseMock(), + { status: 202 }, + ); + }, + options, + ); +}; + +export const getGetExportMockHandler = ( + overrideResponse?: + | Export + | (( + info: Parameters< + HttpResponseResolver<{ organizationId: string; exportId: string }> + >[0], + ) => Promise | Export), + options?: RequestHandlerOptions, +) => { + return http.get<{ organizationId: string; exportId: string }>( + "*/api/v2/organizations/:organizationId/exports/:exportId", + async ( + info: Parameters< + HttpResponseResolver<{ organizationId: string; exportId: string }> + >[0], + ) => { + return HttpResponse.json( + overrideResponse !== undefined + ? typeof overrideResponse === "function" + ? await overrideResponse(info) + : overrideResponse + : getGetExportResponseMock(), + { status: 200 }, + ); + }, + options, + ); +}; + +export const getDeleteExportMockHandler = ( + overrideResponse?: + | void + | (( + info: Parameters< + HttpResponseResolver<{ organizationId: string; exportId: string }> + >[0], + ) => Promise | void), + options?: RequestHandlerOptions, +) => { + return http.delete<{ organizationId: string; exportId: string }>( + "*/api/v2/organizations/:organizationId/exports/:exportId", + async ( + info: Parameters< + HttpResponseResolver<{ organizationId: string; exportId: string }> + >[0], + ) => { + if (typeof overrideResponse === "function") { + await overrideResponse(info); + } + + return new HttpResponse(null, { status: 204 }); + }, + options, + ); +}; + +export const getDownloadExportPartMockHandler = ( + overrideResponse?: + | Blob + | (( + info: Parameters< + HttpResponseResolver<{ + organizationId: string; + exportId: string; + partNumber: string; + }> + >[0], + ) => Promise | Blob), + options?: RequestHandlerOptions, +) => { + return http.get<{ + organizationId: string; + exportId: string; + partNumber: string; + }>( + "*/api/v2/organizations/:organizationId/exports/:exportId/parts/:partNumber", + async ( + info: Parameters< + HttpResponseResolver<{ + organizationId: string; + exportId: string; + partNumber: string; + }> + >[0], + ) => { + const binaryBody = + overrideResponse !== undefined + ? typeof overrideResponse === "function" + ? await overrideResponse(info) + : overrideResponse + : getDownloadExportPartResponseMock(); + return new HttpResponse(binaryBody, { + status: 200, + headers: { "Content-Type": "application/octet-stream" }, + }); + }, + options, + ); +}; + +export const getCreateImportMockHandler = ( + overrideResponse?: + | Import + | (( + info: Parameters< + HttpResponseResolver<{ organizationId: string }, ImportInput> + >[0], + ) => Promise | Import), + options?: RequestHandlerOptions, +) => { + return http.post<{ organizationId: string }, ImportInput>( + "*/api/v2/organizations/:organizationId/imports", + async ( + info: Parameters< + HttpResponseResolver<{ organizationId: string }, ImportInput> + >[0], + ) => { + return HttpResponse.json( + overrideResponse !== undefined + ? typeof overrideResponse === "function" + ? await overrideResponse(info) + : overrideResponse + : getCreateImportResponseMock(), + { status: 201 }, + ); + }, + options, + ); +}; + +export const getListImportsMockHandler = ( + overrideResponse?: + | ImportPage + | (( + info: Parameters>[0], + ) => Promise | ImportPage), + options?: RequestHandlerOptions, +) => { + return http.get<{ organizationId: string }>( + "*/api/v2/organizations/:organizationId/imports", + async ( + info: Parameters>[0], + ) => { + return HttpResponse.json( + overrideResponse !== undefined + ? typeof overrideResponse === "function" + ? await overrideResponse(info) + : overrideResponse + : getListImportsResponseMock(), + { status: 200 }, + ); + }, + options, + ); +}; + +export const getGetImportMockHandler = ( + overrideResponse?: + | Import + | (( + info: Parameters< + HttpResponseResolver<{ organizationId: string; importId: string }> + >[0], + ) => Promise | Import), + options?: RequestHandlerOptions, +) => { + return http.get<{ organizationId: string; importId: string }>( + "*/api/v2/organizations/:organizationId/imports/:importId", + async ( + info: Parameters< + HttpResponseResolver<{ organizationId: string; importId: string }> + >[0], + ) => { + return HttpResponse.json( + overrideResponse !== undefined + ? typeof overrideResponse === "function" + ? await overrideResponse(info) + : overrideResponse + : getGetImportResponseMock(), + { status: 200 }, + ); + }, + options, + ); +}; + +export const getUploadImportPartMockHandler = ( + overrideResponse?: + | Import + | (( + info: Parameters< + HttpResponseResolver< + { organizationId: string; importId: string; partNumber: string }, + Blob + > + >[0], + ) => Promise | Import), + options?: RequestHandlerOptions, +) => { + return http.put< + { organizationId: string; importId: string; partNumber: string }, + Blob + >( + "*/api/v2/organizations/:organizationId/imports/:importId/parts/:partNumber", + async ( + info: Parameters< + HttpResponseResolver< + { organizationId: string; importId: string; partNumber: string }, + Blob + > + >[0], + ) => { + return HttpResponse.json( + overrideResponse !== undefined + ? typeof overrideResponse === "function" + ? await overrideResponse(info) + : overrideResponse + : getUploadImportPartResponseMock(), + { status: 200 }, + ); + }, + options, + ); +}; + +export const getApplyImportMockHandler = ( + overrideResponse?: + | Import + | (( + info: Parameters< + HttpResponseResolver<{ organizationId: string; importId: string }> + >[0], + ) => Promise | Import), + options?: RequestHandlerOptions, +) => { + return http.post<{ organizationId: string; importId: string }>( + "*/api/v2/organizations/:organizationId/imports/:importId/apply", + async ( + info: Parameters< + HttpResponseResolver<{ organizationId: string; importId: string }> + >[0], + ) => { + return HttpResponse.json( + overrideResponse !== undefined + ? typeof overrideResponse === "function" + ? await overrideResponse(info) + : overrideResponse + : getApplyImportResponseMock(), + { status: 202 }, + ); + }, + options, + ); +}; + +export const getGetImportVerificationMockHandler = ( + overrideResponse?: + | ImportVerification + | (( + info: Parameters< + HttpResponseResolver<{ organizationId: string; importId: string }> + >[0], + ) => Promise | ImportVerification), + options?: RequestHandlerOptions, +) => { + return http.get<{ organizationId: string; importId: string }>( + "*/api/v2/organizations/:organizationId/imports/:importId/verification", + async ( + info: Parameters< + HttpResponseResolver<{ organizationId: string; importId: string }> + >[0], + ) => { + return HttpResponse.json( + overrideResponse !== undefined + ? typeof overrideResponse === "function" + ? await overrideResponse(info) + : overrideResponse + : getGetImportVerificationResponseMock(), + { status: 200 }, + ); + }, + options, + ); +}; +export const getMovingToOpenbotCloudMock = () => [ + getGetExportEstimateMockHandler(), + getCreateExportMockHandler(), + getGetExportMockHandler(), + getDeleteExportMockHandler(), + getDownloadExportPartMockHandler(), + getCreateImportMockHandler(), + getListImportsMockHandler(), + getGetImportMockHandler(), + getUploadImportPartMockHandler(), + getApplyImportMockHandler(), + getGetImportVerificationMockHandler(), +]; diff --git a/app/src/lib/api/generated/moving-to-openbot-cloud/moving-to-openbot-cloud.ts b/app/src/lib/api/generated/moving-to-openbot-cloud/moving-to-openbot-cloud.ts new file mode 100644 index 0000000000..4e594a6b89 --- /dev/null +++ b/app/src/lib/api/generated/moving-to-openbot-cloud/moving-to-openbot-cloud.ts @@ -0,0 +1,2104 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ +import { useMutation, useQuery } from "@tanstack/react-query"; +import type { + DataTag, + DefinedInitialDataOptions, + DefinedUseQueryResult, + MutationFunction, + QueryClient, + QueryFunction, + QueryKey, + UndefinedInitialDataOptions, + UseMutationOptions, + UseMutationResult, + UseQueryOptions, + UseQueryResult, +} from "@tanstack/react-query"; + +import type { + ApplyImportHeaders, + CreateExportHeaders, + CreateImportHeaders, + DeleteExportHeaders, + DownloadExportPartHeaders, + Export, + ExportEstimate, + ExportInput, + ExportNotFoundResponse, + ExportNotReadyResponse, + IdempotencyConflictResponse, + Import, + ImportBundleRefusedResponse, + ImportConflictResponse, + ImportInput, + ImportNotFoundResponse, + ImportPage, + ImportVerification, + InvalidRequestResponse, + ListImportsParams, + MoveUnavailableResponse, + PayloadTooLargeResponse, + RangeNotSatisfiableResponse, + ServerErrorResponse, + TooManyMovesResponse, + UnauthenticatedResponse, + UnexpectedErrorResponse, + UploadImportPartHeaders, +} from "../model"; + +import { apiRequest } from "../../request"; + +type AwaitedInput = PromiseLike | T; + +type Awaited = O extends AwaitedInput ? T : never; + +type SecondParameter unknown> = Parameters[1]; + +const withQueryKey = ( + query: T, + queryKey: K, +): T & { queryKey: K } => { + const result = { queryKey } as T & { queryKey: K }; + for (const key of Object.keys(query)) { + // The explicit queryKey always wins, matching the previous + // `{ ...query, queryKey }` spread where it was set last. + if (key === "queryKey") continue; + Object.defineProperty(result, key, { + enumerable: true, + configurable: true, + get: () => (query as Record)[key], + }); + } + return result; +}; + +export const getGetExportEstimateUrl = (organizationId: string) => { + return `/api/v2/organizations/${encodeURIComponent(String(organizationId))}/export-estimate`; +}; + +/** + * Count what an export would hold, without making one: the caller's Bots, their skills, conversations and messages, memories, routines, goals and check-ins, files and settings, and, when the caller is an administrator, the organization's own skills. Also says roughly how big the bundle will be, how much space this OpenBot holds for it on disk (what the move frees once the local OpenBot is removed), which apps the person will need to connect again on OpenBot Cloud, and whether a model key could come along. Served only by an OpenBot that runs on the person's own computer; elsewhere it answers 404 with the code MOVE_UNAVAILABLE. + * @summary Read what moving to OpenBot Cloud would take + */ +export const getExportEstimate = async ( + organizationId: string, + options?: Parameters[1], +): Promise => { + return apiRequest(getGetExportEstimateUrl(organizationId), { + ...options, + method: "GET", + }); +}; + +export const getGetExportEstimateQueryKey = (organizationId: string) => { + return [`/api/v2/organizations/${organizationId}/export-estimate`] as const; +}; + +export const getGetExportEstimateQueryOptions = < + TData = Awaited>, + TError = + | UnauthenticatedResponse + | MoveUnavailableResponse + | ServerErrorResponse + | UnexpectedErrorResponse, +>( + organizationId: string, + options?: { + query?: Partial< + UseQueryOptions< + Awaited>, + TError, + TData + > + >; + request?: SecondParameter; + }, +) => { + const { query: queryOptions, request: requestOptions } = options ?? {}; + + const queryKey = + queryOptions?.queryKey ?? getGetExportEstimateQueryKey(organizationId); + + const queryFn: QueryFunction< + Awaited> + > = ({ signal }) => + getExportEstimate(organizationId, { signal, ...requestOptions }); + + return { + queryKey, + queryFn, + enabled: organizationId !== null && organizationId !== undefined, + ...queryOptions, + } as UseQueryOptions< + Awaited>, + TError, + TData + > & { queryKey: DataTag }; +}; + +export type GetExportEstimateQueryResult = NonNullable< + Awaited> +>; +export type GetExportEstimateQueryError = + | UnauthenticatedResponse + | MoveUnavailableResponse + | ServerErrorResponse + | UnexpectedErrorResponse; + +export function useGetExportEstimate< + TData = Awaited>, + TError = + | UnauthenticatedResponse + | MoveUnavailableResponse + | ServerErrorResponse + | UnexpectedErrorResponse, +>( + organizationId: string, + options: { + query: Partial< + UseQueryOptions< + Awaited>, + TError, + TData + > + > & + Pick< + DefinedInitialDataOptions< + Awaited>, + TError, + Awaited> + >, + "initialData" + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): DefinedUseQueryResult & { + queryKey: DataTag; +}; +export function useGetExportEstimate< + TData = Awaited>, + TError = + | UnauthenticatedResponse + | MoveUnavailableResponse + | ServerErrorResponse + | UnexpectedErrorResponse, +>( + organizationId: string, + options?: { + query?: Partial< + UseQueryOptions< + Awaited>, + TError, + TData + > + > & + Pick< + UndefinedInitialDataOptions< + Awaited>, + TError, + Awaited> + >, + "initialData" + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): UseQueryResult & { + queryKey: DataTag; +}; +export function useGetExportEstimate< + TData = Awaited>, + TError = + | UnauthenticatedResponse + | MoveUnavailableResponse + | ServerErrorResponse + | UnexpectedErrorResponse, +>( + organizationId: string, + options?: { + query?: Partial< + UseQueryOptions< + Awaited>, + TError, + TData + > + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): UseQueryResult & { + queryKey: DataTag; +}; +/** + * @summary Read what moving to OpenBot Cloud would take + */ + +export function useGetExportEstimate< + TData = Awaited>, + TError = + | UnauthenticatedResponse + | MoveUnavailableResponse + | ServerErrorResponse + | UnexpectedErrorResponse, +>( + organizationId: string, + options?: { + query?: Partial< + UseQueryOptions< + Awaited>, + TError, + TData + > + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): UseQueryResult & { + queryKey: DataTag; +} { + const queryOptions = getGetExportEstimateQueryOptions( + organizationId, + options, + ); + + const query = useQuery(queryOptions, queryClient) as UseQueryResult< + TData, + TError + > & { queryKey: DataTag }; + + return withQueryKey(query, queryOptions.queryKey); +} + +export const getCreateExportUrl = (organizationId: string) => { + return `/api/v2/organizations/${encodeURIComponent(String(organizationId))}/exports`; +}; + +/** + * Start writing a bundle of everything the caller has in this organization, to move it to OpenBot Cloud: their Bots (settings, instructions and skills), conversations with every message, memories, routines, goals and check-ins, files, standing instructions and preferences, and, when the caller is an administrator, the organization's own skills. Connections to apps travel as their app and account name only: no token or password ever leaves, and each one is listed in reconnect so the person connects it again on Cloud. A model key travels only when includeModelKeys is true, and then only sealed to recipientKey, the key the import on Cloud gave (createImport), so the bundle never holds it readable. + * + * The bundle is written in the background; read getExport until status is ready. It is cut into parts of at most 32 MiB, each with its size and SHA-256, so a dropped download resumes where it stopped. One export is kept for each person: starting another removes the one before. An export is removed 7 days after it was made, or with deleteExport. Served only by an OpenBot that runs on the person's own computer; elsewhere it answers 404 with the code MOVE_UNAVAILABLE. + * @summary Start exporting what the caller has here + */ +export const createExport = async ( + organizationId: string, + exportInput: ExportInput, + headers: CreateExportHeaders, + options?: Parameters[1], +): Promise => { + const getHeaders = ( + h?: NonNullable, + ): Record => { + if (!h) return {}; + if (h instanceof Headers) return Object.fromEntries(h.entries()); + if (Symbol.iterator in h) { + return Object.fromEntries( + Array.from( + h as Iterable>, + (entry) => Array.from(entry) as [string, string], + ), + ); + } + const headers: Record = {}; + for (const [name, value] of Object.entries< + string | readonly string[] | undefined + >(h)) { + if (value !== undefined) headers[name] = value; + } + return headers; + }; + return apiRequest(getCreateExportUrl(organizationId), { + ...options, + method: "POST", + headers: { + "Content-Type": "application/json", + ...headers, + ...getHeaders(options?.headers), + }, + body: JSON.stringify(exportInput), + }); +}; + +export const getCreateExportMutationKey = () => ["createExport"] as const; + +export const getCreateExportMutationOptions = < + TError = + | InvalidRequestResponse + | UnauthenticatedResponse + | MoveUnavailableResponse + | IdempotencyConflictResponse + | TooManyMovesResponse + | ServerErrorResponse + | UnexpectedErrorResponse, + TContext = unknown, +>(options?: { + mutation?: UseMutationOptions< + Awaited>, + TError, + CreateExportMutationVariables, + TContext + >; + request?: SecondParameter; +}): UseMutationOptions< + Awaited>, + TError, + CreateExportMutationVariables, + TContext +> => { + const mutationKey = getCreateExportMutationKey(); + const { mutation: mutationOptions, request: requestOptions } = options + ? options.mutation && + "mutationKey" in options.mutation && + options.mutation.mutationKey + ? options + : { ...options, mutation: { ...options.mutation, mutationKey } } + : { mutation: { mutationKey }, request: undefined }; + + const mutationFn: MutationFunction< + Awaited>, + CreateExportMutationVariables + > = (props) => { + const { organizationId, data, headers } = props ?? {}; + + return createExport(organizationId, data, headers, requestOptions); + }; + + return { mutationFn, ...mutationOptions }; +}; + +export type CreateExportMutationResult = NonNullable< + Awaited> +>; +export type CreateExportMutationBody = ExportInput; +export type CreateExportMutationError = + | InvalidRequestResponse + | UnauthenticatedResponse + | MoveUnavailableResponse + | IdempotencyConflictResponse + | TooManyMovesResponse + | ServerErrorResponse + | UnexpectedErrorResponse; +export type CreateExportMutationVariables = { + organizationId: string; + data: ExportInput; + headers: CreateExportHeaders; +}; + +/** + * @summary Start exporting what the caller has here + */ +export const useCreateExport = < + TError = + | InvalidRequestResponse + | UnauthenticatedResponse + | MoveUnavailableResponse + | IdempotencyConflictResponse + | TooManyMovesResponse + | ServerErrorResponse + | UnexpectedErrorResponse, + TContext = unknown, +>( + options?: { + mutation?: UseMutationOptions< + Awaited>, + TError, + CreateExportMutationVariables, + TContext + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): UseMutationResult< + Awaited>, + TError, + CreateExportMutationVariables, + TContext +> => { + return useMutation(getCreateExportMutationOptions(options), queryClient); +}; +export const getGetExportUrl = (organizationId: string, exportId: string) => { + return `/api/v2/organizations/${encodeURIComponent(String(organizationId))}/exports/${encodeURIComponent(String(exportId))}`; +}; + +/** + * Return where the caller's export stands. Once ready it lists the bundle's parts with their sizes and SHA-256, its total size, and the count of everything in it by kind, which are the counts getImportVerification is compared with. Only the person who made it reads it; anybody else is answered 404. + * @summary Read an export + */ +export const getExport = async ( + organizationId: string, + exportId: string, + options?: Parameters[1], +): Promise => { + return apiRequest(getGetExportUrl(organizationId, exportId), { + ...options, + method: "GET", + }); +}; + +export const getGetExportQueryKey = ( + organizationId: string, + exportId: string, +) => { + return [ + `/api/v2/organizations/${organizationId}/exports/${exportId}`, + ] as const; +}; + +export const getGetExportQueryOptions = < + TData = Awaited>, + TError = + | UnauthenticatedResponse + | ExportNotFoundResponse + | ServerErrorResponse + | UnexpectedErrorResponse, +>( + organizationId: string, + exportId: string, + options?: { + query?: Partial< + UseQueryOptions>, TError, TData> + >; + request?: SecondParameter; + }, +) => { + const { query: queryOptions, request: requestOptions } = options ?? {}; + + const queryKey = + queryOptions?.queryKey ?? getGetExportQueryKey(organizationId, exportId); + + const queryFn: QueryFunction>> = ({ + signal, + }) => getExport(organizationId, exportId, { signal, ...requestOptions }); + + return { + queryKey, + queryFn, + enabled: + organizationId !== null && + organizationId !== undefined && + exportId !== null && + exportId !== undefined, + ...queryOptions, + } as UseQueryOptions>, TError, TData> & { + queryKey: DataTag; + }; +}; + +export type GetExportQueryResult = NonNullable< + Awaited> +>; +export type GetExportQueryError = + | UnauthenticatedResponse + | ExportNotFoundResponse + | ServerErrorResponse + | UnexpectedErrorResponse; + +export function useGetExport< + TData = Awaited>, + TError = + | UnauthenticatedResponse + | ExportNotFoundResponse + | ServerErrorResponse + | UnexpectedErrorResponse, +>( + organizationId: string, + exportId: string, + options: { + query: Partial< + UseQueryOptions>, TError, TData> + > & + Pick< + DefinedInitialDataOptions< + Awaited>, + TError, + Awaited> + >, + "initialData" + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): DefinedUseQueryResult & { + queryKey: DataTag; +}; +export function useGetExport< + TData = Awaited>, + TError = + | UnauthenticatedResponse + | ExportNotFoundResponse + | ServerErrorResponse + | UnexpectedErrorResponse, +>( + organizationId: string, + exportId: string, + options?: { + query?: Partial< + UseQueryOptions>, TError, TData> + > & + Pick< + UndefinedInitialDataOptions< + Awaited>, + TError, + Awaited> + >, + "initialData" + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): UseQueryResult & { + queryKey: DataTag; +}; +export function useGetExport< + TData = Awaited>, + TError = + | UnauthenticatedResponse + | ExportNotFoundResponse + | ServerErrorResponse + | UnexpectedErrorResponse, +>( + organizationId: string, + exportId: string, + options?: { + query?: Partial< + UseQueryOptions>, TError, TData> + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): UseQueryResult & { + queryKey: DataTag; +}; +/** + * @summary Read an export + */ + +export function useGetExport< + TData = Awaited>, + TError = + | UnauthenticatedResponse + | ExportNotFoundResponse + | ServerErrorResponse + | UnexpectedErrorResponse, +>( + organizationId: string, + exportId: string, + options?: { + query?: Partial< + UseQueryOptions>, TError, TData> + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): UseQueryResult & { + queryKey: DataTag; +} { + const queryOptions = getGetExportQueryOptions( + organizationId, + exportId, + options, + ); + + const query = useQuery(queryOptions, queryClient) as UseQueryResult< + TData, + TError + > & { queryKey: DataTag }; + + return withQueryKey(query, queryOptions.queryKey); +} + +export const getDeleteExportUrl = ( + organizationId: string, + exportId: string, +) => { + return `/api/v2/organizations/${encodeURIComponent(String(organizationId))}/exports/${encodeURIComponent(String(exportId))}`; +}; + +/** + * Remove the caller's export and its bundle from disk. Nothing it was made from changes. One already gone answers 204 too. + * @summary Remove an export + */ +export const deleteExport = async ( + organizationId: string, + exportId: string, + headers: DeleteExportHeaders, + options?: Parameters[1], +): Promise => { + const getHeaders = ( + h?: NonNullable, + ): Record => { + if (!h) return {}; + if (h instanceof Headers) return Object.fromEntries(h.entries()); + if (Symbol.iterator in h) { + return Object.fromEntries( + Array.from( + h as Iterable>, + (entry) => Array.from(entry) as [string, string], + ), + ); + } + const headers: Record = {}; + for (const [name, value] of Object.entries< + string | readonly string[] | undefined + >(h)) { + if (value !== undefined) headers[name] = value; + } + return headers; + }; + return apiRequest(getDeleteExportUrl(organizationId, exportId), { + ...options, + method: "DELETE", + headers: { ...headers, ...getHeaders(options?.headers) }, + }); +}; + +export const getDeleteExportMutationKey = () => ["deleteExport"] as const; + +export const getDeleteExportMutationOptions = < + TError = + | UnauthenticatedResponse + | MoveUnavailableResponse + | IdempotencyConflictResponse + | ServerErrorResponse + | UnexpectedErrorResponse, + TContext = unknown, +>(options?: { + mutation?: UseMutationOptions< + Awaited>, + TError, + DeleteExportMutationVariables, + TContext + >; + request?: SecondParameter; +}): UseMutationOptions< + Awaited>, + TError, + DeleteExportMutationVariables, + TContext +> => { + const mutationKey = getDeleteExportMutationKey(); + const { mutation: mutationOptions, request: requestOptions } = options + ? options.mutation && + "mutationKey" in options.mutation && + options.mutation.mutationKey + ? options + : { ...options, mutation: { ...options.mutation, mutationKey } } + : { mutation: { mutationKey }, request: undefined }; + + const mutationFn: MutationFunction< + Awaited>, + DeleteExportMutationVariables + > = (props) => { + const { organizationId, exportId, headers } = props ?? {}; + + return deleteExport(organizationId, exportId, headers, requestOptions); + }; + + return { mutationFn, ...mutationOptions }; +}; + +export type DeleteExportMutationResult = NonNullable< + Awaited> +>; + +export type DeleteExportMutationError = + | UnauthenticatedResponse + | MoveUnavailableResponse + | IdempotencyConflictResponse + | ServerErrorResponse + | UnexpectedErrorResponse; +export type DeleteExportMutationVariables = { + organizationId: string; + exportId: string; + headers: DeleteExportHeaders; +}; + +/** + * @summary Remove an export + */ +export const useDeleteExport = < + TError = + | UnauthenticatedResponse + | MoveUnavailableResponse + | IdempotencyConflictResponse + | ServerErrorResponse + | UnexpectedErrorResponse, + TContext = unknown, +>( + options?: { + mutation?: UseMutationOptions< + Awaited>, + TError, + DeleteExportMutationVariables, + TContext + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): UseMutationResult< + Awaited>, + TError, + DeleteExportMutationVariables, + TContext +> => { + return useMutation(getDeleteExportMutationOptions(options), queryClient); +}; +export const getDownloadExportPartUrl = ( + organizationId: string, + exportId: string, + partNumber: number, +) => { + return `/api/v2/organizations/${encodeURIComponent(String(organizationId))}/exports/${encodeURIComponent(String(exportId))}/parts/${encodeURIComponent(String(partNumber))}`; +}; + +/** + * Return one part of a ready export's bundle, as bytes to hand to uploadImportPart unchanged. A Range header of one byte range (bytes=N- or bytes=N-M) answers 206 with that range, so a dropped download resumes where it stopped. The SHA-256 of the whole part is in the export's parts and in the ETag. Only the person who made the export downloads it. + * @summary Download one part of an export's bundle + */ +export const downloadExportPart = async ( + organizationId: string, + exportId: string, + partNumber: number, + headers?: DownloadExportPartHeaders, + options?: Parameters[1], +): Promise => { + const getHeaders = ( + h?: NonNullable, + ): Record => { + if (!h) return {}; + if (h instanceof Headers) return Object.fromEntries(h.entries()); + if (Symbol.iterator in h) { + return Object.fromEntries( + Array.from( + h as Iterable>, + (entry) => Array.from(entry) as [string, string], + ), + ); + } + const headers: Record = {}; + for (const [name, value] of Object.entries< + string | readonly string[] | undefined + >(h)) { + if (value !== undefined) headers[name] = value; + } + return headers; + }; + return apiRequest( + getDownloadExportPartUrl(organizationId, exportId, partNumber), + { + ...options, + method: "GET", + headers: { ...headers, ...getHeaders(options?.headers) }, + }, + ); +}; + +export const getDownloadExportPartQueryKey = ( + organizationId: string, + exportId: string, + partNumber: number, +) => { + return [ + `/api/v2/organizations/${organizationId}/exports/${exportId}/parts/${partNumber}`, + ] as const; +}; + +export const getDownloadExportPartQueryOptions = < + TData = Awaited>, + TError = + | UnauthenticatedResponse + | ExportNotFoundResponse + | ExportNotReadyResponse + | RangeNotSatisfiableResponse + | ServerErrorResponse + | UnexpectedErrorResponse, +>( + organizationId: string, + exportId: string, + partNumber: number, + headers?: DownloadExportPartHeaders, + options?: { + query?: Partial< + UseQueryOptions< + Awaited>, + TError, + TData + > + >; + request?: SecondParameter; + }, +) => { + const { query: queryOptions, request: requestOptions } = options ?? {}; + + const queryKey = + queryOptions?.queryKey ?? + getDownloadExportPartQueryKey(organizationId, exportId, partNumber); + + const queryFn: QueryFunction< + Awaited> + > = ({ signal }) => + downloadExportPart(organizationId, exportId, partNumber, headers, { + signal, + ...requestOptions, + }); + + return { + queryKey, + queryFn, + enabled: + organizationId !== null && + organizationId !== undefined && + exportId !== null && + exportId !== undefined && + partNumber !== null && + partNumber !== undefined, + ...queryOptions, + } as UseQueryOptions< + Awaited>, + TError, + TData + > & { queryKey: DataTag }; +}; + +export type DownloadExportPartQueryResult = NonNullable< + Awaited> +>; +export type DownloadExportPartQueryError = + | UnauthenticatedResponse + | ExportNotFoundResponse + | ExportNotReadyResponse + | RangeNotSatisfiableResponse + | ServerErrorResponse + | UnexpectedErrorResponse; + +export function useDownloadExportPart< + TData = Awaited>, + TError = + | UnauthenticatedResponse + | ExportNotFoundResponse + | ExportNotReadyResponse + | RangeNotSatisfiableResponse + | ServerErrorResponse + | UnexpectedErrorResponse, +>( + organizationId: string, + exportId: string, + partNumber: number, + headers: undefined | DownloadExportPartHeaders, + options: { + query: Partial< + UseQueryOptions< + Awaited>, + TError, + TData + > + > & + Pick< + DefinedInitialDataOptions< + Awaited>, + TError, + Awaited> + >, + "initialData" + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): DefinedUseQueryResult & { + queryKey: DataTag; +}; +export function useDownloadExportPart< + TData = Awaited>, + TError = + | UnauthenticatedResponse + | ExportNotFoundResponse + | ExportNotReadyResponse + | RangeNotSatisfiableResponse + | ServerErrorResponse + | UnexpectedErrorResponse, +>( + organizationId: string, + exportId: string, + partNumber: number, + headers?: DownloadExportPartHeaders, + options?: { + query?: Partial< + UseQueryOptions< + Awaited>, + TError, + TData + > + > & + Pick< + UndefinedInitialDataOptions< + Awaited>, + TError, + Awaited> + >, + "initialData" + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): UseQueryResult & { + queryKey: DataTag; +}; +export function useDownloadExportPart< + TData = Awaited>, + TError = + | UnauthenticatedResponse + | ExportNotFoundResponse + | ExportNotReadyResponse + | RangeNotSatisfiableResponse + | ServerErrorResponse + | UnexpectedErrorResponse, +>( + organizationId: string, + exportId: string, + partNumber: number, + headers?: DownloadExportPartHeaders, + options?: { + query?: Partial< + UseQueryOptions< + Awaited>, + TError, + TData + > + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): UseQueryResult & { + queryKey: DataTag; +}; +/** + * @summary Download one part of an export's bundle + */ + +export function useDownloadExportPart< + TData = Awaited>, + TError = + | UnauthenticatedResponse + | ExportNotFoundResponse + | ExportNotReadyResponse + | RangeNotSatisfiableResponse + | ServerErrorResponse + | UnexpectedErrorResponse, +>( + organizationId: string, + exportId: string, + partNumber: number, + headers?: DownloadExportPartHeaders, + options?: { + query?: Partial< + UseQueryOptions< + Awaited>, + TError, + TData + > + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): UseQueryResult & { + queryKey: DataTag; +} { + const queryOptions = getDownloadExportPartQueryOptions( + organizationId, + exportId, + partNumber, + headers, + options, + ); + + const query = useQuery(queryOptions, queryClient) as UseQueryResult< + TData, + TError + > & { queryKey: DataTag }; + + return withQueryKey(query, queryOptions.queryKey); +} + +export const getCreateImportUrl = (organizationId: string) => { + return `/api/v2/organizations/${encodeURIComponent(String(organizationId))}/imports`; +}; + +/** + * Start an import of what the caller is moving from an OpenBot on their own computer into this organization, the caller's own organization by default. Everything imported belongs to the caller, in this organization only. The answer carries recipientKey, a public key made for this import alone: pass it to createExport, and a model key in the bundle is sealed to it, readable only by this import. The answer also says how big a bundle and a part may be. Then upload the export's parts with uploadImportPart and apply them with applyImport. + * + * Importing is safe to repeat: an import of the same OpenBot into the same organization (an export made again, or a new import after a dropped one) adds only what isn't here yet and duplicates nothing. Served only by OpenBot Cloud; elsewhere it answers 404 with the code MOVE_UNAVAILABLE. A person starts at most 10 imports a day. + * @summary Start importing a bundle into this organization + */ +export const createImport = async ( + organizationId: string, + headers: CreateImportHeaders, + importInput?: ImportInput, + options?: Parameters[1], +): Promise => { + const getHeaders = ( + h?: NonNullable, + ): Record => { + if (!h) return {}; + if (h instanceof Headers) return Object.fromEntries(h.entries()); + if (Symbol.iterator in h) { + return Object.fromEntries( + Array.from( + h as Iterable>, + (entry) => Array.from(entry) as [string, string], + ), + ); + } + const headers: Record = {}; + for (const [name, value] of Object.entries< + string | readonly string[] | undefined + >(h)) { + if (value !== undefined) headers[name] = value; + } + return headers; + }; + return apiRequest(getCreateImportUrl(organizationId), { + ...options, + method: "POST", + headers: { + "Content-Type": "application/json", + ...headers, + ...getHeaders(options?.headers), + }, + body: JSON.stringify(importInput), + }); +}; + +export const getCreateImportMutationKey = () => ["createImport"] as const; + +export const getCreateImportMutationOptions = < + TError = + | InvalidRequestResponse + | UnauthenticatedResponse + | MoveUnavailableResponse + | IdempotencyConflictResponse + | TooManyMovesResponse + | ServerErrorResponse + | UnexpectedErrorResponse, + TContext = unknown, +>(options?: { + mutation?: UseMutationOptions< + Awaited>, + TError, + CreateImportMutationVariables, + TContext + >; + request?: SecondParameter; +}): UseMutationOptions< + Awaited>, + TError, + CreateImportMutationVariables, + TContext +> => { + const mutationKey = getCreateImportMutationKey(); + const { mutation: mutationOptions, request: requestOptions } = options + ? options.mutation && + "mutationKey" in options.mutation && + options.mutation.mutationKey + ? options + : { ...options, mutation: { ...options.mutation, mutationKey } } + : { mutation: { mutationKey }, request: undefined }; + + const mutationFn: MutationFunction< + Awaited>, + CreateImportMutationVariables + > = (props) => { + const { organizationId, headers, data } = props ?? {}; + + return createImport(organizationId, headers, data, requestOptions); + }; + + return { mutationFn, ...mutationOptions }; +}; + +export type CreateImportMutationResult = NonNullable< + Awaited> +>; +export type CreateImportMutationBody = ImportInput | undefined; +export type CreateImportMutationError = + | InvalidRequestResponse + | UnauthenticatedResponse + | MoveUnavailableResponse + | IdempotencyConflictResponse + | TooManyMovesResponse + | ServerErrorResponse + | UnexpectedErrorResponse; +export type CreateImportMutationVariables = { + organizationId: string; + headers: CreateImportHeaders; + data?: ImportInput; +}; + +/** + * @summary Start importing a bundle into this organization + */ +export const useCreateImport = < + TError = + | InvalidRequestResponse + | UnauthenticatedResponse + | MoveUnavailableResponse + | IdempotencyConflictResponse + | TooManyMovesResponse + | ServerErrorResponse + | UnexpectedErrorResponse, + TContext = unknown, +>( + options?: { + mutation?: UseMutationOptions< + Awaited>, + TError, + CreateImportMutationVariables, + TContext + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): UseMutationResult< + Awaited>, + TError, + CreateImportMutationVariables, + TContext +> => { + return useMutation(getCreateImportMutationOptions(options), queryClient); +}; +export const getListImportsUrl = ( + organizationId: string, + params?: ListImportsParams, +) => { + const normalizedParams = new URLSearchParams(); + + Object.entries(params || {}).forEach(([key, value]) => { + if (value !== undefined) { + normalizedParams.append(key, value === null ? "null" : String(value)); + } + }); + + const stringifiedParams = normalizedParams.toString(); + + return stringifiedParams.length > 0 + ? `/api/v2/organizations/${encodeURIComponent(String(organizationId))}/imports?${stringifiedParams}` + : `/api/v2/organizations/${encodeURIComponent(String(organizationId))}/imports`; +}; + +/** + * List the imports the caller started in this organization, newest first, so an app that lost track of one after a drop finds it again. Only the caller's own. Served only by OpenBot Cloud. + * @summary List the caller's imports into this organization + */ +export const listImports = async ( + organizationId: string, + params?: ListImportsParams, + options?: Parameters[1], +): Promise => { + return apiRequest(getListImportsUrl(organizationId, params), { + ...options, + method: "GET", + }); +}; + +export const getListImportsQueryKey = ( + organizationId: string, + params?: ListImportsParams, +) => { + return [ + `/api/v2/organizations/${organizationId}/imports`, + ...(params ? [params] : []), + ] as const; +}; + +export const getListImportsQueryOptions = < + TData = Awaited>, + TError = + | InvalidRequestResponse + | UnauthenticatedResponse + | MoveUnavailableResponse + | ServerErrorResponse + | UnexpectedErrorResponse, +>( + organizationId: string, + params?: ListImportsParams, + options?: { + query?: Partial< + UseQueryOptions>, TError, TData> + >; + request?: SecondParameter; + }, +) => { + const { query: queryOptions, request: requestOptions } = options ?? {}; + + const queryKey = + queryOptions?.queryKey ?? getListImportsQueryKey(organizationId, params); + + const queryFn: QueryFunction>> = ({ + signal, + }) => listImports(organizationId, params, { signal, ...requestOptions }); + + return { + queryKey, + queryFn, + enabled: organizationId !== null && organizationId !== undefined, + ...queryOptions, + } as UseQueryOptions< + Awaited>, + TError, + TData + > & { queryKey: DataTag }; +}; + +export type ListImportsQueryResult = NonNullable< + Awaited> +>; +export type ListImportsQueryError = + | InvalidRequestResponse + | UnauthenticatedResponse + | MoveUnavailableResponse + | ServerErrorResponse + | UnexpectedErrorResponse; + +export function useListImports< + TData = Awaited>, + TError = + | InvalidRequestResponse + | UnauthenticatedResponse + | MoveUnavailableResponse + | ServerErrorResponse + | UnexpectedErrorResponse, +>( + organizationId: string, + params: undefined | ListImportsParams, + options: { + query: Partial< + UseQueryOptions>, TError, TData> + > & + Pick< + DefinedInitialDataOptions< + Awaited>, + TError, + Awaited> + >, + "initialData" + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): DefinedUseQueryResult & { + queryKey: DataTag; +}; +export function useListImports< + TData = Awaited>, + TError = + | InvalidRequestResponse + | UnauthenticatedResponse + | MoveUnavailableResponse + | ServerErrorResponse + | UnexpectedErrorResponse, +>( + organizationId: string, + params?: ListImportsParams, + options?: { + query?: Partial< + UseQueryOptions>, TError, TData> + > & + Pick< + UndefinedInitialDataOptions< + Awaited>, + TError, + Awaited> + >, + "initialData" + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): UseQueryResult & { + queryKey: DataTag; +}; +export function useListImports< + TData = Awaited>, + TError = + | InvalidRequestResponse + | UnauthenticatedResponse + | MoveUnavailableResponse + | ServerErrorResponse + | UnexpectedErrorResponse, +>( + organizationId: string, + params?: ListImportsParams, + options?: { + query?: Partial< + UseQueryOptions>, TError, TData> + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): UseQueryResult & { + queryKey: DataTag; +}; +/** + * @summary List the caller's imports into this organization + */ + +export function useListImports< + TData = Awaited>, + TError = + | InvalidRequestResponse + | UnauthenticatedResponse + | MoveUnavailableResponse + | ServerErrorResponse + | UnexpectedErrorResponse, +>( + organizationId: string, + params?: ListImportsParams, + options?: { + query?: Partial< + UseQueryOptions>, TError, TData> + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): UseQueryResult & { + queryKey: DataTag; +} { + const queryOptions = getListImportsQueryOptions( + organizationId, + params, + options, + ); + + const query = useQuery(queryOptions, queryClient) as UseQueryResult< + TData, + TError + > & { queryKey: DataTag }; + + return withQueryKey(query, queryOptions.queryKey); +} + +export const getGetImportUrl = (organizationId: string, importId: string) => { + return `/api/v2/organizations/${encodeURIComponent(String(organizationId))}/imports/${encodeURIComponent(String(importId))}`; +}; + +/** + * Return where the caller's import stands: which parts have arrived, how far applying them has got by kind, and once imported, the summary: what was imported, what was imported differently or left out on OpenBot Cloud and why (notes), and which apps to connect again (reconnect). Only the person who started it reads it. + * @summary Read an import + */ +export const getImport = async ( + organizationId: string, + importId: string, + options?: Parameters[1], +): Promise => { + return apiRequest(getGetImportUrl(organizationId, importId), { + ...options, + method: "GET", + }); +}; + +export const getGetImportQueryKey = ( + organizationId: string, + importId: string, +) => { + return [ + `/api/v2/organizations/${organizationId}/imports/${importId}`, + ] as const; +}; + +export const getGetImportQueryOptions = < + TData = Awaited>, + TError = + | UnauthenticatedResponse + | ImportNotFoundResponse + | ServerErrorResponse + | UnexpectedErrorResponse, +>( + organizationId: string, + importId: string, + options?: { + query?: Partial< + UseQueryOptions>, TError, TData> + >; + request?: SecondParameter; + }, +) => { + const { query: queryOptions, request: requestOptions } = options ?? {}; + + const queryKey = + queryOptions?.queryKey ?? getGetImportQueryKey(organizationId, importId); + + const queryFn: QueryFunction>> = ({ + signal, + }) => getImport(organizationId, importId, { signal, ...requestOptions }); + + return { + queryKey, + queryFn, + enabled: + organizationId !== null && + organizationId !== undefined && + importId !== null && + importId !== undefined, + ...queryOptions, + } as UseQueryOptions>, TError, TData> & { + queryKey: DataTag; + }; +}; + +export type GetImportQueryResult = NonNullable< + Awaited> +>; +export type GetImportQueryError = + | UnauthenticatedResponse + | ImportNotFoundResponse + | ServerErrorResponse + | UnexpectedErrorResponse; + +export function useGetImport< + TData = Awaited>, + TError = + | UnauthenticatedResponse + | ImportNotFoundResponse + | ServerErrorResponse + | UnexpectedErrorResponse, +>( + organizationId: string, + importId: string, + options: { + query: Partial< + UseQueryOptions>, TError, TData> + > & + Pick< + DefinedInitialDataOptions< + Awaited>, + TError, + Awaited> + >, + "initialData" + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): DefinedUseQueryResult & { + queryKey: DataTag; +}; +export function useGetImport< + TData = Awaited>, + TError = + | UnauthenticatedResponse + | ImportNotFoundResponse + | ServerErrorResponse + | UnexpectedErrorResponse, +>( + organizationId: string, + importId: string, + options?: { + query?: Partial< + UseQueryOptions>, TError, TData> + > & + Pick< + UndefinedInitialDataOptions< + Awaited>, + TError, + Awaited> + >, + "initialData" + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): UseQueryResult & { + queryKey: DataTag; +}; +export function useGetImport< + TData = Awaited>, + TError = + | UnauthenticatedResponse + | ImportNotFoundResponse + | ServerErrorResponse + | UnexpectedErrorResponse, +>( + organizationId: string, + importId: string, + options?: { + query?: Partial< + UseQueryOptions>, TError, TData> + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): UseQueryResult & { + queryKey: DataTag; +}; +/** + * @summary Read an import + */ + +export function useGetImport< + TData = Awaited>, + TError = + | UnauthenticatedResponse + | ImportNotFoundResponse + | ServerErrorResponse + | UnexpectedErrorResponse, +>( + organizationId: string, + importId: string, + options?: { + query?: Partial< + UseQueryOptions>, TError, TData> + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): UseQueryResult & { + queryKey: DataTag; +} { + const queryOptions = getGetImportQueryOptions( + organizationId, + importId, + options, + ); + + const query = useQuery(queryOptions, queryClient) as UseQueryResult< + TData, + TError + > & { queryKey: DataTag }; + + return withQueryKey(query, queryOptions.queryKey); +} + +export const getUploadImportPartUrl = ( + organizationId: string, + importId: string, + partNumber: number, +) => { + return `/api/v2/organizations/${encodeURIComponent(String(organizationId))}/imports/${encodeURIComponent(String(importId))}/parts/${encodeURIComponent(String(partNumber))}`; +}; + +/** + * Upload one part of the export's bundle, exactly as downloadExportPart gave it. Part 1 carries the bundle's manifest, so it is uploaded first; after it the parts go in any order, and the import's expectedParts says how many there are and the SHA-256 of each. A part whose bytes don't match the manifest is refused (IMPORT_PART_MISMATCH) and can be uploaded again. Uploading a part that already arrived changes nothing and answers 200 again, so after a drop an app sends whatever receivedParts doesn't list. A part is at most 32 MiB, and a bundle at most maxBundleBytes. At most 120 parts a minute for each person. + * @summary Upload one part of the bundle + */ +export const uploadImportPart = async ( + organizationId: string, + importId: string, + partNumber: number, + uploadImportPartBody: Blob, + headers: UploadImportPartHeaders, + options?: Parameters[1], +): Promise => { + const getHeaders = ( + h?: NonNullable, + ): Record => { + if (!h) return {}; + if (h instanceof Headers) return Object.fromEntries(h.entries()); + if (Symbol.iterator in h) { + return Object.fromEntries( + Array.from( + h as Iterable>, + (entry) => Array.from(entry) as [string, string], + ), + ); + } + const headers: Record = {}; + for (const [name, value] of Object.entries< + string | readonly string[] | undefined + >(h)) { + if (value !== undefined) headers[name] = value; + } + return headers; + }; + return apiRequest( + getUploadImportPartUrl(organizationId, importId, partNumber), + { + ...options, + method: "PUT", + headers: { + "Content-Type": "application/octet-stream", + ...headers, + ...getHeaders(options?.headers), + }, + body: uploadImportPartBody, + }, + ); +}; + +export const getUploadImportPartMutationKey = () => + ["uploadImportPart"] as const; + +export const getUploadImportPartMutationOptions = < + TError = + | InvalidRequestResponse + | UnauthenticatedResponse + | ImportNotFoundResponse + | ImportConflictResponse + | PayloadTooLargeResponse + | ImportBundleRefusedResponse + | TooManyMovesResponse + | ServerErrorResponse + | UnexpectedErrorResponse, + TContext = unknown, +>(options?: { + mutation?: UseMutationOptions< + Awaited>, + TError, + UploadImportPartMutationVariables, + TContext + >; + request?: SecondParameter; +}): UseMutationOptions< + Awaited>, + TError, + UploadImportPartMutationVariables, + TContext +> => { + const mutationKey = getUploadImportPartMutationKey(); + const { mutation: mutationOptions, request: requestOptions } = options + ? options.mutation && + "mutationKey" in options.mutation && + options.mutation.mutationKey + ? options + : { ...options, mutation: { ...options.mutation, mutationKey } } + : { mutation: { mutationKey }, request: undefined }; + + const mutationFn: MutationFunction< + Awaited>, + UploadImportPartMutationVariables + > = (props) => { + const { organizationId, importId, partNumber, data, headers } = props ?? {}; + + return uploadImportPart( + organizationId, + importId, + partNumber, + data, + headers, + requestOptions, + ); + }; + + return { mutationFn, ...mutationOptions }; +}; + +export type UploadImportPartMutationResult = NonNullable< + Awaited> +>; +export type UploadImportPartMutationBody = Blob; +export type UploadImportPartMutationError = + | InvalidRequestResponse + | UnauthenticatedResponse + | ImportNotFoundResponse + | ImportConflictResponse + | PayloadTooLargeResponse + | ImportBundleRefusedResponse + | TooManyMovesResponse + | ServerErrorResponse + | UnexpectedErrorResponse; +export type UploadImportPartMutationVariables = { + organizationId: string; + importId: string; + partNumber: number; + data: Blob; + headers: UploadImportPartHeaders; +}; + +/** + * @summary Upload one part of the bundle + */ +export const useUploadImportPart = < + TError = + | InvalidRequestResponse + | UnauthenticatedResponse + | ImportNotFoundResponse + | ImportConflictResponse + | PayloadTooLargeResponse + | ImportBundleRefusedResponse + | TooManyMovesResponse + | ServerErrorResponse + | UnexpectedErrorResponse, + TContext = unknown, +>( + options?: { + mutation?: UseMutationOptions< + Awaited>, + TError, + UploadImportPartMutationVariables, + TContext + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): UseMutationResult< + Awaited>, + TError, + UploadImportPartMutationVariables, + TContext +> => { + return useMutation(getUploadImportPartMutationOptions(options), queryClient); +}; +export const getApplyImportUrl = (organizationId: string, importId: string) => { + return `/api/v2/organizations/${encodeURIComponent(String(organizationId))}/imports/${encodeURIComponent(String(importId))}/apply`; +}; + +/** + * Once every part has arrived, import the bundle into this organization in the background: every id is given a new one here, everything is owned by the caller, and nothing reaches another organization. Every file is stored where a file uploaded here is, in this organization's own place in OpenBot's file store, and the uploaded parts are removed once the import is done. Read getImport until status is imported or failed. Applying again while it runs, or after it finished, changes nothing and answers where it stands; applying a failed import tries again from where it stopped, and nothing already imported is imported twice. A missing part answers 409 with IMPORT_INCOMPLETE. + * + * What OpenBot Cloud doesn't have comes in differently, and the summary says so in notes: a Bot that ran on its own isolated computer comes in as an ordinary Bot; a feature that needs the Business plan, in an organization that isn't on it, is left out. A model key in the bundle becomes the caller's own AI connection, unless they have one here already, which is kept. + * @summary Import the uploaded bundle + */ +export const applyImport = async ( + organizationId: string, + importId: string, + headers: ApplyImportHeaders, + options?: Parameters[1], +): Promise => { + const getHeaders = ( + h?: NonNullable, + ): Record => { + if (!h) return {}; + if (h instanceof Headers) return Object.fromEntries(h.entries()); + if (Symbol.iterator in h) { + return Object.fromEntries( + Array.from( + h as Iterable>, + (entry) => Array.from(entry) as [string, string], + ), + ); + } + const headers: Record = {}; + for (const [name, value] of Object.entries< + string | readonly string[] | undefined + >(h)) { + if (value !== undefined) headers[name] = value; + } + return headers; + }; + return apiRequest(getApplyImportUrl(organizationId, importId), { + ...options, + method: "POST", + headers: { ...headers, ...getHeaders(options?.headers) }, + }); +}; + +export const getApplyImportMutationKey = () => ["applyImport"] as const; + +export const getApplyImportMutationOptions = < + TError = + | UnauthenticatedResponse + | ImportNotFoundResponse + | ImportConflictResponse + | ServerErrorResponse + | UnexpectedErrorResponse, + TContext = unknown, +>(options?: { + mutation?: UseMutationOptions< + Awaited>, + TError, + ApplyImportMutationVariables, + TContext + >; + request?: SecondParameter; +}): UseMutationOptions< + Awaited>, + TError, + ApplyImportMutationVariables, + TContext +> => { + const mutationKey = getApplyImportMutationKey(); + const { mutation: mutationOptions, request: requestOptions } = options + ? options.mutation && + "mutationKey" in options.mutation && + options.mutation.mutationKey + ? options + : { ...options, mutation: { ...options.mutation, mutationKey } } + : { mutation: { mutationKey }, request: undefined }; + + const mutationFn: MutationFunction< + Awaited>, + ApplyImportMutationVariables + > = (props) => { + const { organizationId, importId, headers } = props ?? {}; + + return applyImport(organizationId, importId, headers, requestOptions); + }; + + return { mutationFn, ...mutationOptions }; +}; + +export type ApplyImportMutationResult = NonNullable< + Awaited> +>; + +export type ApplyImportMutationError = + | UnauthenticatedResponse + | ImportNotFoundResponse + | ImportConflictResponse + | ServerErrorResponse + | UnexpectedErrorResponse; +export type ApplyImportMutationVariables = { + organizationId: string; + importId: string; + headers: ApplyImportHeaders; +}; + +/** + * @summary Import the uploaded bundle + */ +export const useApplyImport = < + TError = + | UnauthenticatedResponse + | ImportNotFoundResponse + | ImportConflictResponse + | ServerErrorResponse + | UnexpectedErrorResponse, + TContext = unknown, +>( + options?: { + mutation?: UseMutationOptions< + Awaited>, + TError, + ApplyImportMutationVariables, + TContext + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): UseMutationResult< + Awaited>, + TError, + ApplyImportMutationVariables, + TContext +> => { + return useMutation(getApplyImportMutationOptions(options), queryClient); +}; +export const getGetImportVerificationUrl = ( + organizationId: string, + importId: string, +) => { + return `/api/v2/organizations/${encodeURIComponent(String(organizationId))}/imports/${encodeURIComponent(String(importId))}/verification`; +}; + +/** + * Count, by kind, what from this import's OpenBot is in this organization now, read from what is stored here rather than from the import's own tally, beside what the bundle held. matches is true only when every kind is all here, apart from what the notes say OpenBot Cloud left out on purpose. OpenBot Desktop removes nothing on the person's computer until it does. Also lists the apps to connect again. + * @summary Check that everything arrived + */ +export const getImportVerification = async ( + organizationId: string, + importId: string, + options?: Parameters[1], +): Promise => { + return apiRequest( + getGetImportVerificationUrl(organizationId, importId), + { + ...options, + method: "GET", + }, + ); +}; + +export const getGetImportVerificationQueryKey = ( + organizationId: string, + importId: string, +) => { + return [ + `/api/v2/organizations/${organizationId}/imports/${importId}/verification`, + ] as const; +}; + +export const getGetImportVerificationQueryOptions = < + TData = Awaited>, + TError = + | UnauthenticatedResponse + | ImportNotFoundResponse + | ImportConflictResponse + | ServerErrorResponse + | UnexpectedErrorResponse, +>( + organizationId: string, + importId: string, + options?: { + query?: Partial< + UseQueryOptions< + Awaited>, + TError, + TData + > + >; + request?: SecondParameter; + }, +) => { + const { query: queryOptions, request: requestOptions } = options ?? {}; + + const queryKey = + queryOptions?.queryKey ?? + getGetImportVerificationQueryKey(organizationId, importId); + + const queryFn: QueryFunction< + Awaited> + > = ({ signal }) => + getImportVerification(organizationId, importId, { + signal, + ...requestOptions, + }); + + return { + queryKey, + queryFn, + enabled: + organizationId !== null && + organizationId !== undefined && + importId !== null && + importId !== undefined, + ...queryOptions, + } as UseQueryOptions< + Awaited>, + TError, + TData + > & { queryKey: DataTag }; +}; + +export type GetImportVerificationQueryResult = NonNullable< + Awaited> +>; +export type GetImportVerificationQueryError = + | UnauthenticatedResponse + | ImportNotFoundResponse + | ImportConflictResponse + | ServerErrorResponse + | UnexpectedErrorResponse; + +export function useGetImportVerification< + TData = Awaited>, + TError = + | UnauthenticatedResponse + | ImportNotFoundResponse + | ImportConflictResponse + | ServerErrorResponse + | UnexpectedErrorResponse, +>( + organizationId: string, + importId: string, + options: { + query: Partial< + UseQueryOptions< + Awaited>, + TError, + TData + > + > & + Pick< + DefinedInitialDataOptions< + Awaited>, + TError, + Awaited> + >, + "initialData" + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): DefinedUseQueryResult & { + queryKey: DataTag; +}; +export function useGetImportVerification< + TData = Awaited>, + TError = + | UnauthenticatedResponse + | ImportNotFoundResponse + | ImportConflictResponse + | ServerErrorResponse + | UnexpectedErrorResponse, +>( + organizationId: string, + importId: string, + options?: { + query?: Partial< + UseQueryOptions< + Awaited>, + TError, + TData + > + > & + Pick< + UndefinedInitialDataOptions< + Awaited>, + TError, + Awaited> + >, + "initialData" + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): UseQueryResult & { + queryKey: DataTag; +}; +export function useGetImportVerification< + TData = Awaited>, + TError = + | UnauthenticatedResponse + | ImportNotFoundResponse + | ImportConflictResponse + | ServerErrorResponse + | UnexpectedErrorResponse, +>( + organizationId: string, + importId: string, + options?: { + query?: Partial< + UseQueryOptions< + Awaited>, + TError, + TData + > + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): UseQueryResult & { + queryKey: DataTag; +}; +/** + * @summary Check that everything arrived + */ + +export function useGetImportVerification< + TData = Awaited>, + TError = + | UnauthenticatedResponse + | ImportNotFoundResponse + | ImportConflictResponse + | ServerErrorResponse + | UnexpectedErrorResponse, +>( + organizationId: string, + importId: string, + options?: { + query?: Partial< + UseQueryOptions< + Awaited>, + TError, + TData + > + >; + request?: SecondParameter; + }, + queryClient?: QueryClient, +): UseQueryResult & { + queryKey: DataTag; +} { + const queryOptions = getGetImportVerificationQueryOptions( + organizationId, + importId, + options, + ); + + const query = useQuery(queryOptions, queryClient) as UseQueryResult< + TData, + TError + > & { queryKey: DataTag }; + + return withQueryKey(query, queryOptions.queryKey); +} diff --git a/app/src/lib/api/generated/moving-to-openbot-cloud/moving-to-openbot-cloud.zod.ts b/app/src/lib/api/generated/moving-to-openbot-cloud/moving-to-openbot-cloud.zod.ts new file mode 100644 index 0000000000..a818d1a68d --- /dev/null +++ b/app/src/lib/api/generated/moving-to-openbot-cloud/moving-to-openbot-cloud.zod.ts @@ -0,0 +1,1710 @@ +/** + * Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`. + */ +import * as zod from "zod"; + +/** + * Count what an export would hold, without making one: the caller's Bots, their skills, conversations and messages, memories, routines, goals and check-ins, files and settings, and, when the caller is an administrator, the organization's own skills. Also says roughly how big the bundle will be, how much space this OpenBot holds for it on disk (what the move frees once the local OpenBot is removed), which apps the person will need to connect again on OpenBot Cloud, and whether a model key could come along. Served only by an OpenBot that runs on the person's own computer; elsewhere it answers 404 with the code MOVE_UNAVAILABLE. + * @summary Read what moving to OpenBot Cloud would take + */ + +export const GetExportEstimateParams = zod.object({ + organizationId: zod + .string() + .min(1) + .describe( + "The organization, by its id or its slug. One the caller is not a member of answers as one that does not exist, `default` included.", + ), +}); + +export const getExportEstimateResponseCountsItemCountMin = 0; + +export const getExportEstimateResponseCountsItemBytesMin = 0; + +export const getExportEstimateResponseEstimatedBytesMin = 0; + +export const getExportEstimateResponseStoredBytesMin = 0; + +export const GetExportEstimateResponse = zod.object({ + counts: zod.array( + zod.object({ + kind: zod + .string() + .describe( + "A kind of thing that moves. bots: Bots with their settings and instructions. skills: skills, a Bot's and the person's (and the organization's, for an administrator). conversations and messages: every conversation and every message in it. memories: what the person's Bots remember about them. routines, goals and check-ins: with their schedules. files: files sent in conversations and kept on a Bot's computer. settings: the person's standing instructions and preferences. model-keys: a model key, only when the person chose to bring it. A later OpenBot may add a kind; count one you don't know like any other.", + ), + count: zod.int().min(getExportEstimateResponseCountsItemCountMin), + bytes: zod + .int() + .min(getExportEstimateResponseCountsItemBytesMin) + .optional() + .describe("For files, how many bytes they hold together."), + }), + ), + estimatedBytes: zod + .int() + .min(getExportEstimateResponseEstimatedBytesMin) + .describe("Roughly how big the bundle will be, in bytes."), + storedBytes: zod + .int() + .min(getExportEstimateResponseStoredBytesMin) + .describe( + "How much this OpenBot keeps on disk for the person (its database and files), which removing it frees. OpenBot Desktop adds what the engine itself takes.", + ), + reconnect: zod.array( + zod + .object({ + appId: zod + .string() + .min(1) + .describe( + "The app's id in the app directory, such as gmail or slack.", + ), + appName: zod + .string() + .min(1) + .describe("The app's name as a person reads it."), + accountLabel: zod + .string() + .min(1) + .optional() + .describe( + "Which account it was connected as, such as an email address or a workspace name, when known.", + ), + iconUrl: zod + .url() + .optional() + .describe("The app's icon, when the directory has one."), + botNames: zod + .array(zod.string()) + .optional() + .describe( + "The Bots that used it, so the person knows which to check.", + ), + }) + .describe( + "A connection to an app that doesn't move, because its sign-in stays on the person's computer: the person connects it again on OpenBot Cloud. Never carries a token, a password or a key.", + ), + ), + modelKeysAvailable: zod + .boolean() + .describe( + "True when there is a model key the person could choose to bring.", + ), +}); + +/** + * Start writing a bundle of everything the caller has in this organization, to move it to OpenBot Cloud: their Bots (settings, instructions and skills), conversations with every message, memories, routines, goals and check-ins, files, standing instructions and preferences, and, when the caller is an administrator, the organization's own skills. Connections to apps travel as their app and account name only: no token or password ever leaves, and each one is listed in reconnect so the person connects it again on Cloud. A model key travels only when includeModelKeys is true, and then only sealed to recipientKey, the key the import on Cloud gave (createImport), so the bundle never holds it readable. + * + * The bundle is written in the background; read getExport until status is ready. It is cut into parts of at most 32 MiB, each with its size and SHA-256, so a dropped download resumes where it stopped. One export is kept for each person: starting another removes the one before. An export is removed 7 days after it was made, or with deleteExport. Served only by an OpenBot that runs on the person's own computer; elsewhere it answers 404 with the code MOVE_UNAVAILABLE. + * @summary Start exporting what the caller has here + */ + +export const CreateExportParams = zod.object({ + organizationId: zod + .string() + .min(1) + .describe( + "The organization, by its id or its slug. One the caller is not a member of answers as one that does not exist, `default` included.", + ), +}); + +export const createExportHeaderIdempotencyKeyMax = 128; + +export const CreateExportHeader = zod.object({ + "Idempotency-Key": zod + .string() + .min(1) + .max(createExportHeaderIdempotencyKeyMax) + .describe( + "Generated by the caller for each write it means to make once. Reuse the same key and the same request for 24 hours after an uncertain response; the same key with a different request is a conflict.", + ), +}); + +export const createExportBodyIncludeModelKeysDefault = false; +export const createExportBodyRecipientKeyNMax = 1024; + +export const createExportBodyRecipientKeyEMax = 16; + +export const createExportBodyRecipientKeyKidMax = 128; + +export const CreateExportBody = zod.object({ + includeModelKeys: zod + .boolean() + .default(createExportBodyIncludeModelKeysDefault) + .describe( + "Bring the person's model key, sealed to recipientKey. Without recipientKey this is refused.", + ), + recipientKey: zod + .object({ + kty: zod.literal("RSA"), + n: zod.string().min(1).max(createExportBodyRecipientKeyNMax), + e: zod.string().min(1).max(createExportBodyRecipientKeyEMax), + alg: zod.literal("RSA-OAEP-256"), + kid: zod.string().min(1).max(createExportBodyRecipientKeyKidMax), + }) + .optional() + .describe( + "A public key as a JSON Web Key (RFC 7517): RSA, 4096 bits, for RSA-OAEP-256. A model key is sealed to it as a JWE (RFC 7516, RSA-OAEP-256 with A256GCM), so only the import that made it reads it.", + ), +}); + +export const createExportResponseTotalBytesMin = 0; + +export const createExportResponsePartsItemSha256RegExp = new RegExp( + "^[0-9a-f]{64}$", +); +export const createExportResponseCountsItemCountMin = 0; + +export const createExportResponseCountsItemBytesMin = 0; + +export const createExportResponseProgressMin = 0; +export const createExportResponseProgressMax = 1; + +export const CreateExportResponse = zod.object({ + id: zod.string().min(1), + status: zod + .string() + .describe( + "preparing: the bundle is being written. ready: every part can be downloaded. failed: it stopped; error says why, and starting another export tries again. A later OpenBot may add a status; read one you don't know as preparing.", + ), + formatVersion: zod + .int() + .min(1) + .optional() + .describe("The bundle's format, once ready. This OpenBot writes 1."), + createdAt: zod.iso.datetime({ offset: true }), + expiresAt: zod.iso + .datetime({ offset: true }) + .describe("When the bundle is removed."), + totalBytes: zod + .int() + .min(createExportResponseTotalBytesMin) + .optional() + .describe("The bundle's size, once ready."), + parts: zod + .array( + zod.object({ + number: zod.int().min(1), + bytes: zod.int().min(1), + sha256: zod.string().regex(createExportResponsePartsItemSha256RegExp), + }), + ) + .optional() + .describe("The bundle's parts in order, once ready."), + counts: zod + .array( + zod.object({ + kind: zod + .string() + .describe( + "A kind of thing that moves. bots: Bots with their settings and instructions. skills: skills, a Bot's and the person's (and the organization's, for an administrator). conversations and messages: every conversation and every message in it. memories: what the person's Bots remember about them. routines, goals and check-ins: with their schedules. files: files sent in conversations and kept on a Bot's computer. settings: the person's standing instructions and preferences. model-keys: a model key, only when the person chose to bring it. A later OpenBot may add a kind; count one you don't know like any other.", + ), + count: zod.int().min(createExportResponseCountsItemCountMin), + bytes: zod + .int() + .min(createExportResponseCountsItemBytesMin) + .optional() + .describe("For files, how many bytes they hold together."), + }), + ) + .optional() + .describe("Everything in the bundle by kind, once ready."), + reconnect: zod + .array( + zod + .object({ + appId: zod + .string() + .min(1) + .describe( + "The app's id in the app directory, such as gmail or slack.", + ), + appName: zod + .string() + .min(1) + .describe("The app's name as a person reads it."), + accountLabel: zod + .string() + .min(1) + .optional() + .describe( + "Which account it was connected as, such as an email address or a workspace name, when known.", + ), + iconUrl: zod + .url() + .optional() + .describe("The app's icon, when the directory has one."), + botNames: zod + .array(zod.string()) + .optional() + .describe( + "The Bots that used it, so the person knows which to check.", + ), + }) + .describe( + "A connection to an app that doesn't move, because its sign-in stays on the person's computer: the person connects it again on OpenBot Cloud. Never carries a token, a password or a key.", + ), + ) + .optional() + .describe("The apps to connect again on OpenBot Cloud."), + includesModelKeys: zod.boolean(), + progress: zod + .number() + .min(createExportResponseProgressMin) + .max(createExportResponseProgressMax) + .optional() + .describe("How far writing the bundle has got, while preparing."), + error: zod + .string() + .min(1) + .optional() + .describe("What went wrong, when failed, in a sentence a person reads."), +}); + +/** + * Return where the caller's export stands. Once ready it lists the bundle's parts with their sizes and SHA-256, its total size, and the count of everything in it by kind, which are the counts getImportVerification is compared with. Only the person who made it reads it; anybody else is answered 404. + * @summary Read an export + */ + +export const getExportPathExportIdMax = 64; + +export const getExportPathExportIdRegExp = new RegExp("^[A-Za-z0-9_-]+$"); + +export const GetExportParams = zod.object({ + organizationId: zod + .string() + .min(1) + .describe( + "The organization, by its id or its slug. One the caller is not a member of answers as one that does not exist, `default` included.", + ), + exportId: zod + .string() + .min(1) + .max(getExportPathExportIdMax) + .regex(getExportPathExportIdRegExp) + .describe("The export's id."), +}); + +export const getExportResponseTotalBytesMin = 0; + +export const getExportResponsePartsItemSha256RegExp = new RegExp( + "^[0-9a-f]{64}$", +); +export const getExportResponseCountsItemCountMin = 0; + +export const getExportResponseCountsItemBytesMin = 0; + +export const getExportResponseProgressMin = 0; +export const getExportResponseProgressMax = 1; + +export const GetExportResponse = zod.object({ + id: zod.string().min(1), + status: zod + .string() + .describe( + "preparing: the bundle is being written. ready: every part can be downloaded. failed: it stopped; error says why, and starting another export tries again. A later OpenBot may add a status; read one you don't know as preparing.", + ), + formatVersion: zod + .int() + .min(1) + .optional() + .describe("The bundle's format, once ready. This OpenBot writes 1."), + createdAt: zod.iso.datetime({ offset: true }), + expiresAt: zod.iso + .datetime({ offset: true }) + .describe("When the bundle is removed."), + totalBytes: zod + .int() + .min(getExportResponseTotalBytesMin) + .optional() + .describe("The bundle's size, once ready."), + parts: zod + .array( + zod.object({ + number: zod.int().min(1), + bytes: zod.int().min(1), + sha256: zod.string().regex(getExportResponsePartsItemSha256RegExp), + }), + ) + .optional() + .describe("The bundle's parts in order, once ready."), + counts: zod + .array( + zod.object({ + kind: zod + .string() + .describe( + "A kind of thing that moves. bots: Bots with their settings and instructions. skills: skills, a Bot's and the person's (and the organization's, for an administrator). conversations and messages: every conversation and every message in it. memories: what the person's Bots remember about them. routines, goals and check-ins: with their schedules. files: files sent in conversations and kept on a Bot's computer. settings: the person's standing instructions and preferences. model-keys: a model key, only when the person chose to bring it. A later OpenBot may add a kind; count one you don't know like any other.", + ), + count: zod.int().min(getExportResponseCountsItemCountMin), + bytes: zod + .int() + .min(getExportResponseCountsItemBytesMin) + .optional() + .describe("For files, how many bytes they hold together."), + }), + ) + .optional() + .describe("Everything in the bundle by kind, once ready."), + reconnect: zod + .array( + zod + .object({ + appId: zod + .string() + .min(1) + .describe( + "The app's id in the app directory, such as gmail or slack.", + ), + appName: zod + .string() + .min(1) + .describe("The app's name as a person reads it."), + accountLabel: zod + .string() + .min(1) + .optional() + .describe( + "Which account it was connected as, such as an email address or a workspace name, when known.", + ), + iconUrl: zod + .url() + .optional() + .describe("The app's icon, when the directory has one."), + botNames: zod + .array(zod.string()) + .optional() + .describe( + "The Bots that used it, so the person knows which to check.", + ), + }) + .describe( + "A connection to an app that doesn't move, because its sign-in stays on the person's computer: the person connects it again on OpenBot Cloud. Never carries a token, a password or a key.", + ), + ) + .optional() + .describe("The apps to connect again on OpenBot Cloud."), + includesModelKeys: zod.boolean(), + progress: zod + .number() + .min(getExportResponseProgressMin) + .max(getExportResponseProgressMax) + .optional() + .describe("How far writing the bundle has got, while preparing."), + error: zod + .string() + .min(1) + .optional() + .describe("What went wrong, when failed, in a sentence a person reads."), +}); + +/** + * Remove the caller's export and its bundle from disk. Nothing it was made from changes. One already gone answers 204 too. + * @summary Remove an export + */ + +export const deleteExportPathExportIdMax = 64; + +export const deleteExportPathExportIdRegExp = new RegExp("^[A-Za-z0-9_-]+$"); + +export const DeleteExportParams = zod.object({ + organizationId: zod + .string() + .min(1) + .describe( + "The organization, by its id or its slug. One the caller is not a member of answers as one that does not exist, `default` included.", + ), + exportId: zod + .string() + .min(1) + .max(deleteExportPathExportIdMax) + .regex(deleteExportPathExportIdRegExp) + .describe("The export's id."), +}); + +export const deleteExportHeaderIdempotencyKeyMax = 128; + +export const DeleteExportHeader = zod.object({ + "Idempotency-Key": zod + .string() + .min(1) + .max(deleteExportHeaderIdempotencyKeyMax) + .describe( + "Generated by the caller for each write it means to make once. Reuse the same key and the same request for 24 hours after an uncertain response; the same key with a different request is a conflict.", + ), +}); + +export const DeleteExportResponse = zod.void(); + +/** + * Return one part of a ready export's bundle, as bytes to hand to uploadImportPart unchanged. A Range header of one byte range (bytes=N- or bytes=N-M) answers 206 with that range, so a dropped download resumes where it stopped. The SHA-256 of the whole part is in the export's parts and in the ETag. Only the person who made the export downloads it. + * @summary Download one part of an export's bundle + */ + +export const downloadExportPartPathExportIdMax = 64; + +export const downloadExportPartPathExportIdRegExp = new RegExp( + "^[A-Za-z0-9_-]+$", +); +export const downloadExportPartPathPartNumberMax = 10000; + +export const DownloadExportPartParams = zod.object({ + organizationId: zod + .string() + .min(1) + .describe( + "The organization, by its id or its slug. One the caller is not a member of answers as one that does not exist, `default` included.", + ), + exportId: zod + .string() + .min(1) + .max(downloadExportPartPathExportIdMax) + .regex(downloadExportPartPathExportIdRegExp) + .describe("The export's id."), + partNumber: zod + .int() + .min(1) + .max(downloadExportPartPathPartNumberMax) + .describe("Which part of the bundle, counted from 1."), +}); + +export const downloadExportPartHeaderRangeMax = 64; + +export const downloadExportPartHeaderRangeRegExp = new RegExp( + "^bytes=[0-9]+-[0-9]*$", +); + +export const DownloadExportPartHeader = zod.object({ + Range: zod + .string() + .max(downloadExportPartHeaderRangeMax) + .regex(downloadExportPartHeaderRangeRegExp) + .optional() + .describe("One byte range of the part, as RFC 9110 writes it."), +}); + +export const DownloadExportPartResponse = zod.unknown(); + +/** + * Start an import of what the caller is moving from an OpenBot on their own computer into this organization, the caller's own organization by default. Everything imported belongs to the caller, in this organization only. The answer carries recipientKey, a public key made for this import alone: pass it to createExport, and a model key in the bundle is sealed to it, readable only by this import. The answer also says how big a bundle and a part may be. Then upload the export's parts with uploadImportPart and apply them with applyImport. + * + * Importing is safe to repeat: an import of the same OpenBot into the same organization (an export made again, or a new import after a dropped one) adds only what isn't here yet and duplicates nothing. Served only by OpenBot Cloud; elsewhere it answers 404 with the code MOVE_UNAVAILABLE. A person starts at most 10 imports a day. + * @summary Start importing a bundle into this organization + */ + +export const CreateImportParams = zod.object({ + organizationId: zod + .string() + .min(1) + .describe( + "The organization, by its id or its slug. One the caller is not a member of answers as one that does not exist, `default` included.", + ), +}); + +export const createImportHeaderIdempotencyKeyMax = 128; + +export const CreateImportHeader = zod.object({ + "Idempotency-Key": zod + .string() + .min(1) + .max(createImportHeaderIdempotencyKeyMax) + .describe( + "Generated by the caller for each write it means to make once. Reuse the same key and the same request for 24 hours after an uncertain response; the same key with a different request is a conflict.", + ), +}); + +export const createImportBodySourceNameMax = 200; + +export const CreateImportBody = zod.object({ + sourceName: zod + .string() + .min(1) + .max(createImportBodySourceNameMax) + .optional() + .describe( + "A name for where the bundle comes from, such as the computer's name, shown in the list of imports.", + ), +}); + +export const createImportResponseRecipientKeyNMax = 1024; + +export const createImportResponseRecipientKeyEMax = 16; + +export const createImportResponseRecipientKeyKidMax = 128; + +export const createImportResponseExpectedPartsItemSha256RegExp = new RegExp( + "^[0-9a-f]{64}$", +); + +export const createImportResponseExpectedItemCountMin = 0; + +export const createImportResponseExpectedItemBytesMin = 0; + +export const createImportResponseImportedItemCountMin = 0; + +export const createImportResponseImportedItemBytesMin = 0; + +export const CreateImportResponse = zod.object({ + id: zod.string().min(1), + status: zod + .string() + .describe( + "waiting-for-bundle: no part has arrived. receiving: part 1 has arrived and others are still to come. ready: every part arrived; apply it. importing: being imported. imported: done; read the summary, then verify. failed: it stopped; error says why, and applying again goes on from there. A later OpenBot may add a status; read one you don't know as importing.", + ), + sourceName: zod.string().optional(), + createdAt: zod.iso.datetime({ offset: true }), + finishedAt: zod.iso.datetime({ offset: true }).optional(), + recipientKey: zod + .object({ + kty: zod.literal("RSA"), + n: zod.string().min(1).max(createImportResponseRecipientKeyNMax), + e: zod.string().min(1).max(createImportResponseRecipientKeyEMax), + alg: zod.literal("RSA-OAEP-256"), + kid: zod.string().min(1).max(createImportResponseRecipientKeyKidMax), + }) + .describe( + "A public key as a JSON Web Key (RFC 7517): RSA, 4096 bits, for RSA-OAEP-256. A model key is sealed to it as a JWE (RFC 7516, RSA-OAEP-256 with A256GCM), so only the import that made it reads it.", + ), + maxBundleBytes: zod.int().min(1), + maxPartBytes: zod.int().min(1), + expectedParts: zod + .array( + zod.object({ + number: zod.int().min(1), + bytes: zod.int().min(1), + sha256: zod + .string() + .regex(createImportResponseExpectedPartsItemSha256RegExp), + }), + ) + .optional() + .describe("The bundle's parts, from its manifest, once part 1 arrived."), + receivedParts: zod + .array(zod.int().min(1)) + .describe("The numbers of the parts that arrived."), + expected: zod + .array( + zod.object({ + kind: zod + .string() + .describe( + "A kind of thing that moves. bots: Bots with their settings and instructions. skills: skills, a Bot's and the person's (and the organization's, for an administrator). conversations and messages: every conversation and every message in it. memories: what the person's Bots remember about them. routines, goals and check-ins: with their schedules. files: files sent in conversations and kept on a Bot's computer. settings: the person's standing instructions and preferences. model-keys: a model key, only when the person chose to bring it. A later OpenBot may add a kind; count one you don't know like any other.", + ), + count: zod.int().min(createImportResponseExpectedItemCountMin), + bytes: zod + .int() + .min(createImportResponseExpectedItemBytesMin) + .optional() + .describe("For files, how many bytes they hold together."), + }), + ) + .optional() + .describe( + "Everything the bundle holds by kind, from its manifest, once part 1 arrived.", + ), + imported: zod + .array( + zod.object({ + kind: zod + .string() + .describe( + "A kind of thing that moves. bots: Bots with their settings and instructions. skills: skills, a Bot's and the person's (and the organization's, for an administrator). conversations and messages: every conversation and every message in it. memories: what the person's Bots remember about them. routines, goals and check-ins: with their schedules. files: files sent in conversations and kept on a Bot's computer. settings: the person's standing instructions and preferences. model-keys: a model key, only when the person chose to bring it. A later OpenBot may add a kind; count one you don't know like any other.", + ), + count: zod.int().min(createImportResponseImportedItemCountMin), + bytes: zod + .int() + .min(createImportResponseImportedItemBytesMin) + .optional() + .describe("For files, how many bytes they hold together."), + }), + ) + .optional() + .describe( + "What has been imported so far by kind, while importing and once imported. Items a repeated import found already here count as imported.", + ), + notes: zod + .array( + zod + .object({ + code: zod + .string() + .describe( + "isolated-bot-made-ordinary: OpenBot Cloud has no isolated computers, so a Bot that had one runs on an ordinary one. business-plan-feature-left-out: the feature needs the Business plan and this organization isn't on it. model-key-kept-existing: the person already had an AI connection here, which was kept. model-key-not-brought: the person chose not to bring a model key. item-skipped: one item couldn't be imported; message says which and why. A later OpenBot may add a code; show the message.", + ), + kind: zod + .string() + .optional() + .describe( + "A kind of thing that moves. bots: Bots with their settings and instructions. skills: skills, a Bot's and the person's (and the organization's, for an administrator). conversations and messages: every conversation and every message in it. memories: what the person's Bots remember about them. routines, goals and check-ins: with their schedules. files: files sent in conversations and kept on a Bot's computer. settings: the person's standing instructions and preferences. model-keys: a model key, only when the person chose to bring it. A later OpenBot may add a kind; count one you don't know like any other.", + ), + count: zod + .int() + .min(1) + .optional() + .describe("How many items the note is about."), + message: zod.string().min(1), + items: zod + .array(zod.string()) + .optional() + .describe( + "The names of the items, such as the Bots, when there are a few.", + ), + }) + .describe( + "Something that moved differently, or not at all, and why, in a sentence a person reads.", + ), + ) + .optional(), + reconnect: zod + .array( + zod + .object({ + appId: zod + .string() + .min(1) + .describe( + "The app's id in the app directory, such as gmail or slack.", + ), + appName: zod + .string() + .min(1) + .describe("The app's name as a person reads it."), + accountLabel: zod + .string() + .min(1) + .optional() + .describe( + "Which account it was connected as, such as an email address or a workspace name, when known.", + ), + iconUrl: zod + .url() + .optional() + .describe("The app's icon, when the directory has one."), + botNames: zod + .array(zod.string()) + .optional() + .describe( + "The Bots that used it, so the person knows which to check.", + ), + }) + .describe( + "A connection to an app that doesn't move, because its sign-in stays on the person's computer: the person connects it again on OpenBot Cloud. Never carries a token, a password or a key.", + ), + ) + .optional() + .describe("The apps to connect again here, once part 1 arrived."), + error: zod + .string() + .min(1) + .optional() + .describe("What went wrong, when failed, in a sentence a person reads."), +}); + +/** + * List the imports the caller started in this organization, newest first, so an app that lost track of one after a drop finds it again. Only the caller's own. Served only by OpenBot Cloud. + * @summary List the caller's imports into this organization + */ + +export const ListImportsParams = zod.object({ + organizationId: zod + .string() + .min(1) + .describe( + "The organization, by its id or its slug. One the caller is not a member of answers as one that does not exist, `default` included.", + ), +}); + +export const listImportsQueryLimitDefault = 50; +export const listImportsQueryLimitMax = 100; + +export const listImportsQueryCursorMax = 4096; + +export const listImportsQueryCursorRegExp = new RegExp("^[A-Za-z0-9_-]+$"); + +export const ListImportsQueryParams = zod.object({ + limit: zod + .int() + .min(1) + .max(listImportsQueryLimitMax) + .default(listImportsQueryLimitDefault) + .describe("Most items in one page."), + cursor: zod + .string() + .min(1) + .max(listImportsQueryCursorMax) + .regex(listImportsQueryCursorRegExp) + .optional() + .describe( + "Opaque continuation from the previous page's nextCursor, bound to the organization and the filters that made it. The server only ever issues cursors written in URL-safe base64 (letters, digits, - and _, no padding) and refuses anything else, so the pattern says so. A cursor that fits the pattern can still be refused: one this list never gave out, or one made for another organization or other filters.", + ), +}); + +export const listImportsResponseItemsItemRecipientKeyNMax = 1024; + +export const listImportsResponseItemsItemRecipientKeyEMax = 16; + +export const listImportsResponseItemsItemRecipientKeyKidMax = 128; + +export const listImportsResponseItemsItemExpectedPartsItemSha256RegExp = + new RegExp("^[0-9a-f]{64}$"); + +export const listImportsResponseItemsItemExpectedItemCountMin = 0; + +export const listImportsResponseItemsItemExpectedItemBytesMin = 0; + +export const listImportsResponseItemsItemImportedItemCountMin = 0; + +export const listImportsResponseItemsItemImportedItemBytesMin = 0; + +export const ListImportsResponse = zod.object({ + items: zod.array( + zod.object({ + id: zod.string().min(1), + status: zod + .string() + .describe( + "waiting-for-bundle: no part has arrived. receiving: part 1 has arrived and others are still to come. ready: every part arrived; apply it. importing: being imported. imported: done; read the summary, then verify. failed: it stopped; error says why, and applying again goes on from there. A later OpenBot may add a status; read one you don't know as importing.", + ), + sourceName: zod.string().optional(), + createdAt: zod.iso.datetime({ offset: true }), + finishedAt: zod.iso.datetime({ offset: true }).optional(), + recipientKey: zod + .object({ + kty: zod.literal("RSA"), + n: zod + .string() + .min(1) + .max(listImportsResponseItemsItemRecipientKeyNMax), + e: zod + .string() + .min(1) + .max(listImportsResponseItemsItemRecipientKeyEMax), + alg: zod.literal("RSA-OAEP-256"), + kid: zod + .string() + .min(1) + .max(listImportsResponseItemsItemRecipientKeyKidMax), + }) + .describe( + "A public key as a JSON Web Key (RFC 7517): RSA, 4096 bits, for RSA-OAEP-256. A model key is sealed to it as a JWE (RFC 7516, RSA-OAEP-256 with A256GCM), so only the import that made it reads it.", + ), + maxBundleBytes: zod.int().min(1), + maxPartBytes: zod.int().min(1), + expectedParts: zod + .array( + zod.object({ + number: zod.int().min(1), + bytes: zod.int().min(1), + sha256: zod + .string() + .regex(listImportsResponseItemsItemExpectedPartsItemSha256RegExp), + }), + ) + .optional() + .describe( + "The bundle's parts, from its manifest, once part 1 arrived.", + ), + receivedParts: zod + .array(zod.int().min(1)) + .describe("The numbers of the parts that arrived."), + expected: zod + .array( + zod.object({ + kind: zod + .string() + .describe( + "A kind of thing that moves. bots: Bots with their settings and instructions. skills: skills, a Bot's and the person's (and the organization's, for an administrator). conversations and messages: every conversation and every message in it. memories: what the person's Bots remember about them. routines, goals and check-ins: with their schedules. files: files sent in conversations and kept on a Bot's computer. settings: the person's standing instructions and preferences. model-keys: a model key, only when the person chose to bring it. A later OpenBot may add a kind; count one you don't know like any other.", + ), + count: zod + .int() + .min(listImportsResponseItemsItemExpectedItemCountMin), + bytes: zod + .int() + .min(listImportsResponseItemsItemExpectedItemBytesMin) + .optional() + .describe("For files, how many bytes they hold together."), + }), + ) + .optional() + .describe( + "Everything the bundle holds by kind, from its manifest, once part 1 arrived.", + ), + imported: zod + .array( + zod.object({ + kind: zod + .string() + .describe( + "A kind of thing that moves. bots: Bots with their settings and instructions. skills: skills, a Bot's and the person's (and the organization's, for an administrator). conversations and messages: every conversation and every message in it. memories: what the person's Bots remember about them. routines, goals and check-ins: with their schedules. files: files sent in conversations and kept on a Bot's computer. settings: the person's standing instructions and preferences. model-keys: a model key, only when the person chose to bring it. A later OpenBot may add a kind; count one you don't know like any other.", + ), + count: zod + .int() + .min(listImportsResponseItemsItemImportedItemCountMin), + bytes: zod + .int() + .min(listImportsResponseItemsItemImportedItemBytesMin) + .optional() + .describe("For files, how many bytes they hold together."), + }), + ) + .optional() + .describe( + "What has been imported so far by kind, while importing and once imported. Items a repeated import found already here count as imported.", + ), + notes: zod + .array( + zod + .object({ + code: zod + .string() + .describe( + "isolated-bot-made-ordinary: OpenBot Cloud has no isolated computers, so a Bot that had one runs on an ordinary one. business-plan-feature-left-out: the feature needs the Business plan and this organization isn't on it. model-key-kept-existing: the person already had an AI connection here, which was kept. model-key-not-brought: the person chose not to bring a model key. item-skipped: one item couldn't be imported; message says which and why. A later OpenBot may add a code; show the message.", + ), + kind: zod + .string() + .optional() + .describe( + "A kind of thing that moves. bots: Bots with their settings and instructions. skills: skills, a Bot's and the person's (and the organization's, for an administrator). conversations and messages: every conversation and every message in it. memories: what the person's Bots remember about them. routines, goals and check-ins: with their schedules. files: files sent in conversations and kept on a Bot's computer. settings: the person's standing instructions and preferences. model-keys: a model key, only when the person chose to bring it. A later OpenBot may add a kind; count one you don't know like any other.", + ), + count: zod + .int() + .min(1) + .optional() + .describe("How many items the note is about."), + message: zod.string().min(1), + items: zod + .array(zod.string()) + .optional() + .describe( + "The names of the items, such as the Bots, when there are a few.", + ), + }) + .describe( + "Something that moved differently, or not at all, and why, in a sentence a person reads.", + ), + ) + .optional(), + reconnect: zod + .array( + zod + .object({ + appId: zod + .string() + .min(1) + .describe( + "The app's id in the app directory, such as gmail or slack.", + ), + appName: zod + .string() + .min(1) + .describe("The app's name as a person reads it."), + accountLabel: zod + .string() + .min(1) + .optional() + .describe( + "Which account it was connected as, such as an email address or a workspace name, when known.", + ), + iconUrl: zod + .url() + .optional() + .describe("The app's icon, when the directory has one."), + botNames: zod + .array(zod.string()) + .optional() + .describe( + "The Bots that used it, so the person knows which to check.", + ), + }) + .describe( + "A connection to an app that doesn't move, because its sign-in stays on the person's computer: the person connects it again on OpenBot Cloud. Never carries a token, a password or a key.", + ), + ) + .optional() + .describe("The apps to connect again here, once part 1 arrived."), + error: zod + .string() + .min(1) + .optional() + .describe( + "What went wrong, when failed, in a sentence a person reads.", + ), + }), + ), + nextCursor: zod.string().nullable(), +}); + +/** + * Return where the caller's import stands: which parts have arrived, how far applying them has got by kind, and once imported, the summary: what was imported, what was imported differently or left out on OpenBot Cloud and why (notes), and which apps to connect again (reconnect). Only the person who started it reads it. + * @summary Read an import + */ + +export const getImportPathImportIdMax = 64; + +export const getImportPathImportIdRegExp = new RegExp("^[A-Za-z0-9_-]+$"); + +export const GetImportParams = zod.object({ + organizationId: zod + .string() + .min(1) + .describe( + "The organization, by its id or its slug. One the caller is not a member of answers as one that does not exist, `default` included.", + ), + importId: zod + .string() + .min(1) + .max(getImportPathImportIdMax) + .regex(getImportPathImportIdRegExp) + .describe("The import's id."), +}); + +export const getImportResponseRecipientKeyNMax = 1024; + +export const getImportResponseRecipientKeyEMax = 16; + +export const getImportResponseRecipientKeyKidMax = 128; + +export const getImportResponseExpectedPartsItemSha256RegExp = new RegExp( + "^[0-9a-f]{64}$", +); + +export const getImportResponseExpectedItemCountMin = 0; + +export const getImportResponseExpectedItemBytesMin = 0; + +export const getImportResponseImportedItemCountMin = 0; + +export const getImportResponseImportedItemBytesMin = 0; + +export const GetImportResponse = zod.object({ + id: zod.string().min(1), + status: zod + .string() + .describe( + "waiting-for-bundle: no part has arrived. receiving: part 1 has arrived and others are still to come. ready: every part arrived; apply it. importing: being imported. imported: done; read the summary, then verify. failed: it stopped; error says why, and applying again goes on from there. A later OpenBot may add a status; read one you don't know as importing.", + ), + sourceName: zod.string().optional(), + createdAt: zod.iso.datetime({ offset: true }), + finishedAt: zod.iso.datetime({ offset: true }).optional(), + recipientKey: zod + .object({ + kty: zod.literal("RSA"), + n: zod.string().min(1).max(getImportResponseRecipientKeyNMax), + e: zod.string().min(1).max(getImportResponseRecipientKeyEMax), + alg: zod.literal("RSA-OAEP-256"), + kid: zod.string().min(1).max(getImportResponseRecipientKeyKidMax), + }) + .describe( + "A public key as a JSON Web Key (RFC 7517): RSA, 4096 bits, for RSA-OAEP-256. A model key is sealed to it as a JWE (RFC 7516, RSA-OAEP-256 with A256GCM), so only the import that made it reads it.", + ), + maxBundleBytes: zod.int().min(1), + maxPartBytes: zod.int().min(1), + expectedParts: zod + .array( + zod.object({ + number: zod.int().min(1), + bytes: zod.int().min(1), + sha256: zod + .string() + .regex(getImportResponseExpectedPartsItemSha256RegExp), + }), + ) + .optional() + .describe("The bundle's parts, from its manifest, once part 1 arrived."), + receivedParts: zod + .array(zod.int().min(1)) + .describe("The numbers of the parts that arrived."), + expected: zod + .array( + zod.object({ + kind: zod + .string() + .describe( + "A kind of thing that moves. bots: Bots with their settings and instructions. skills: skills, a Bot's and the person's (and the organization's, for an administrator). conversations and messages: every conversation and every message in it. memories: what the person's Bots remember about them. routines, goals and check-ins: with their schedules. files: files sent in conversations and kept on a Bot's computer. settings: the person's standing instructions and preferences. model-keys: a model key, only when the person chose to bring it. A later OpenBot may add a kind; count one you don't know like any other.", + ), + count: zod.int().min(getImportResponseExpectedItemCountMin), + bytes: zod + .int() + .min(getImportResponseExpectedItemBytesMin) + .optional() + .describe("For files, how many bytes they hold together."), + }), + ) + .optional() + .describe( + "Everything the bundle holds by kind, from its manifest, once part 1 arrived.", + ), + imported: zod + .array( + zod.object({ + kind: zod + .string() + .describe( + "A kind of thing that moves. bots: Bots with their settings and instructions. skills: skills, a Bot's and the person's (and the organization's, for an administrator). conversations and messages: every conversation and every message in it. memories: what the person's Bots remember about them. routines, goals and check-ins: with their schedules. files: files sent in conversations and kept on a Bot's computer. settings: the person's standing instructions and preferences. model-keys: a model key, only when the person chose to bring it. A later OpenBot may add a kind; count one you don't know like any other.", + ), + count: zod.int().min(getImportResponseImportedItemCountMin), + bytes: zod + .int() + .min(getImportResponseImportedItemBytesMin) + .optional() + .describe("For files, how many bytes they hold together."), + }), + ) + .optional() + .describe( + "What has been imported so far by kind, while importing and once imported. Items a repeated import found already here count as imported.", + ), + notes: zod + .array( + zod + .object({ + code: zod + .string() + .describe( + "isolated-bot-made-ordinary: OpenBot Cloud has no isolated computers, so a Bot that had one runs on an ordinary one. business-plan-feature-left-out: the feature needs the Business plan and this organization isn't on it. model-key-kept-existing: the person already had an AI connection here, which was kept. model-key-not-brought: the person chose not to bring a model key. item-skipped: one item couldn't be imported; message says which and why. A later OpenBot may add a code; show the message.", + ), + kind: zod + .string() + .optional() + .describe( + "A kind of thing that moves. bots: Bots with their settings and instructions. skills: skills, a Bot's and the person's (and the organization's, for an administrator). conversations and messages: every conversation and every message in it. memories: what the person's Bots remember about them. routines, goals and check-ins: with their schedules. files: files sent in conversations and kept on a Bot's computer. settings: the person's standing instructions and preferences. model-keys: a model key, only when the person chose to bring it. A later OpenBot may add a kind; count one you don't know like any other.", + ), + count: zod + .int() + .min(1) + .optional() + .describe("How many items the note is about."), + message: zod.string().min(1), + items: zod + .array(zod.string()) + .optional() + .describe( + "The names of the items, such as the Bots, when there are a few.", + ), + }) + .describe( + "Something that moved differently, or not at all, and why, in a sentence a person reads.", + ), + ) + .optional(), + reconnect: zod + .array( + zod + .object({ + appId: zod + .string() + .min(1) + .describe( + "The app's id in the app directory, such as gmail or slack.", + ), + appName: zod + .string() + .min(1) + .describe("The app's name as a person reads it."), + accountLabel: zod + .string() + .min(1) + .optional() + .describe( + "Which account it was connected as, such as an email address or a workspace name, when known.", + ), + iconUrl: zod + .url() + .optional() + .describe("The app's icon, when the directory has one."), + botNames: zod + .array(zod.string()) + .optional() + .describe( + "The Bots that used it, so the person knows which to check.", + ), + }) + .describe( + "A connection to an app that doesn't move, because its sign-in stays on the person's computer: the person connects it again on OpenBot Cloud. Never carries a token, a password or a key.", + ), + ) + .optional() + .describe("The apps to connect again here, once part 1 arrived."), + error: zod + .string() + .min(1) + .optional() + .describe("What went wrong, when failed, in a sentence a person reads."), +}); + +/** + * Upload one part of the export's bundle, exactly as downloadExportPart gave it. Part 1 carries the bundle's manifest, so it is uploaded first; after it the parts go in any order, and the import's expectedParts says how many there are and the SHA-256 of each. A part whose bytes don't match the manifest is refused (IMPORT_PART_MISMATCH) and can be uploaded again. Uploading a part that already arrived changes nothing and answers 200 again, so after a drop an app sends whatever receivedParts doesn't list. A part is at most 32 MiB, and a bundle at most maxBundleBytes. At most 120 parts a minute for each person. + * @summary Upload one part of the bundle + */ + +export const uploadImportPartPathImportIdMax = 64; + +export const uploadImportPartPathImportIdRegExp = new RegExp( + "^[A-Za-z0-9_-]+$", +); +export const uploadImportPartPathPartNumberMax = 10000; + +export const UploadImportPartParams = zod.object({ + organizationId: zod + .string() + .min(1) + .describe( + "The organization, by its id or its slug. One the caller is not a member of answers as one that does not exist, `default` included.", + ), + importId: zod + .string() + .min(1) + .max(uploadImportPartPathImportIdMax) + .regex(uploadImportPartPathImportIdRegExp) + .describe("The import's id."), + partNumber: zod + .int() + .min(1) + .max(uploadImportPartPathPartNumberMax) + .describe("Which part of the bundle, counted from 1."), +}); + +export const uploadImportPartHeaderIdempotencyKeyMax = 128; + +export const UploadImportPartHeader = zod.object({ + "Idempotency-Key": zod + .string() + .min(1) + .max(uploadImportPartHeaderIdempotencyKeyMax) + .describe( + "Generated by the caller for each write it means to make once. Reuse the same key and the same request for 24 hours after an uncertain response; the same key with a different request is a conflict.", + ), +}); + +export const uploadImportPartResponseRecipientKeyNMax = 1024; + +export const uploadImportPartResponseRecipientKeyEMax = 16; + +export const uploadImportPartResponseRecipientKeyKidMax = 128; + +export const uploadImportPartResponseExpectedPartsItemSha256RegExp = new RegExp( + "^[0-9a-f]{64}$", +); + +export const uploadImportPartResponseExpectedItemCountMin = 0; + +export const uploadImportPartResponseExpectedItemBytesMin = 0; + +export const uploadImportPartResponseImportedItemCountMin = 0; + +export const uploadImportPartResponseImportedItemBytesMin = 0; + +export const UploadImportPartResponse = zod.object({ + id: zod.string().min(1), + status: zod + .string() + .describe( + "waiting-for-bundle: no part has arrived. receiving: part 1 has arrived and others are still to come. ready: every part arrived; apply it. importing: being imported. imported: done; read the summary, then verify. failed: it stopped; error says why, and applying again goes on from there. A later OpenBot may add a status; read one you don't know as importing.", + ), + sourceName: zod.string().optional(), + createdAt: zod.iso.datetime({ offset: true }), + finishedAt: zod.iso.datetime({ offset: true }).optional(), + recipientKey: zod + .object({ + kty: zod.literal("RSA"), + n: zod.string().min(1).max(uploadImportPartResponseRecipientKeyNMax), + e: zod.string().min(1).max(uploadImportPartResponseRecipientKeyEMax), + alg: zod.literal("RSA-OAEP-256"), + kid: zod.string().min(1).max(uploadImportPartResponseRecipientKeyKidMax), + }) + .describe( + "A public key as a JSON Web Key (RFC 7517): RSA, 4096 bits, for RSA-OAEP-256. A model key is sealed to it as a JWE (RFC 7516, RSA-OAEP-256 with A256GCM), so only the import that made it reads it.", + ), + maxBundleBytes: zod.int().min(1), + maxPartBytes: zod.int().min(1), + expectedParts: zod + .array( + zod.object({ + number: zod.int().min(1), + bytes: zod.int().min(1), + sha256: zod + .string() + .regex(uploadImportPartResponseExpectedPartsItemSha256RegExp), + }), + ) + .optional() + .describe("The bundle's parts, from its manifest, once part 1 arrived."), + receivedParts: zod + .array(zod.int().min(1)) + .describe("The numbers of the parts that arrived."), + expected: zod + .array( + zod.object({ + kind: zod + .string() + .describe( + "A kind of thing that moves. bots: Bots with their settings and instructions. skills: skills, a Bot's and the person's (and the organization's, for an administrator). conversations and messages: every conversation and every message in it. memories: what the person's Bots remember about them. routines, goals and check-ins: with their schedules. files: files sent in conversations and kept on a Bot's computer. settings: the person's standing instructions and preferences. model-keys: a model key, only when the person chose to bring it. A later OpenBot may add a kind; count one you don't know like any other.", + ), + count: zod.int().min(uploadImportPartResponseExpectedItemCountMin), + bytes: zod + .int() + .min(uploadImportPartResponseExpectedItemBytesMin) + .optional() + .describe("For files, how many bytes they hold together."), + }), + ) + .optional() + .describe( + "Everything the bundle holds by kind, from its manifest, once part 1 arrived.", + ), + imported: zod + .array( + zod.object({ + kind: zod + .string() + .describe( + "A kind of thing that moves. bots: Bots with their settings and instructions. skills: skills, a Bot's and the person's (and the organization's, for an administrator). conversations and messages: every conversation and every message in it. memories: what the person's Bots remember about them. routines, goals and check-ins: with their schedules. files: files sent in conversations and kept on a Bot's computer. settings: the person's standing instructions and preferences. model-keys: a model key, only when the person chose to bring it. A later OpenBot may add a kind; count one you don't know like any other.", + ), + count: zod.int().min(uploadImportPartResponseImportedItemCountMin), + bytes: zod + .int() + .min(uploadImportPartResponseImportedItemBytesMin) + .optional() + .describe("For files, how many bytes they hold together."), + }), + ) + .optional() + .describe( + "What has been imported so far by kind, while importing and once imported. Items a repeated import found already here count as imported.", + ), + notes: zod + .array( + zod + .object({ + code: zod + .string() + .describe( + "isolated-bot-made-ordinary: OpenBot Cloud has no isolated computers, so a Bot that had one runs on an ordinary one. business-plan-feature-left-out: the feature needs the Business plan and this organization isn't on it. model-key-kept-existing: the person already had an AI connection here, which was kept. model-key-not-brought: the person chose not to bring a model key. item-skipped: one item couldn't be imported; message says which and why. A later OpenBot may add a code; show the message.", + ), + kind: zod + .string() + .optional() + .describe( + "A kind of thing that moves. bots: Bots with their settings and instructions. skills: skills, a Bot's and the person's (and the organization's, for an administrator). conversations and messages: every conversation and every message in it. memories: what the person's Bots remember about them. routines, goals and check-ins: with their schedules. files: files sent in conversations and kept on a Bot's computer. settings: the person's standing instructions and preferences. model-keys: a model key, only when the person chose to bring it. A later OpenBot may add a kind; count one you don't know like any other.", + ), + count: zod + .int() + .min(1) + .optional() + .describe("How many items the note is about."), + message: zod.string().min(1), + items: zod + .array(zod.string()) + .optional() + .describe( + "The names of the items, such as the Bots, when there are a few.", + ), + }) + .describe( + "Something that moved differently, or not at all, and why, in a sentence a person reads.", + ), + ) + .optional(), + reconnect: zod + .array( + zod + .object({ + appId: zod + .string() + .min(1) + .describe( + "The app's id in the app directory, such as gmail or slack.", + ), + appName: zod + .string() + .min(1) + .describe("The app's name as a person reads it."), + accountLabel: zod + .string() + .min(1) + .optional() + .describe( + "Which account it was connected as, such as an email address or a workspace name, when known.", + ), + iconUrl: zod + .url() + .optional() + .describe("The app's icon, when the directory has one."), + botNames: zod + .array(zod.string()) + .optional() + .describe( + "The Bots that used it, so the person knows which to check.", + ), + }) + .describe( + "A connection to an app that doesn't move, because its sign-in stays on the person's computer: the person connects it again on OpenBot Cloud. Never carries a token, a password or a key.", + ), + ) + .optional() + .describe("The apps to connect again here, once part 1 arrived."), + error: zod + .string() + .min(1) + .optional() + .describe("What went wrong, when failed, in a sentence a person reads."), +}); + +/** + * Once every part has arrived, import the bundle into this organization in the background: every id is given a new one here, everything is owned by the caller, and nothing reaches another organization. Every file is stored where a file uploaded here is, in this organization's own place in OpenBot's file store, and the uploaded parts are removed once the import is done. Read getImport until status is imported or failed. Applying again while it runs, or after it finished, changes nothing and answers where it stands; applying a failed import tries again from where it stopped, and nothing already imported is imported twice. A missing part answers 409 with IMPORT_INCOMPLETE. + * + * What OpenBot Cloud doesn't have comes in differently, and the summary says so in notes: a Bot that ran on its own isolated computer comes in as an ordinary Bot; a feature that needs the Business plan, in an organization that isn't on it, is left out. A model key in the bundle becomes the caller's own AI connection, unless they have one here already, which is kept. + * @summary Import the uploaded bundle + */ + +export const applyImportPathImportIdMax = 64; + +export const applyImportPathImportIdRegExp = new RegExp("^[A-Za-z0-9_-]+$"); + +export const ApplyImportParams = zod.object({ + organizationId: zod + .string() + .min(1) + .describe( + "The organization, by its id or its slug. One the caller is not a member of answers as one that does not exist, `default` included.", + ), + importId: zod + .string() + .min(1) + .max(applyImportPathImportIdMax) + .regex(applyImportPathImportIdRegExp) + .describe("The import's id."), +}); + +export const applyImportHeaderIdempotencyKeyMax = 128; + +export const ApplyImportHeader = zod.object({ + "Idempotency-Key": zod + .string() + .min(1) + .max(applyImportHeaderIdempotencyKeyMax) + .describe( + "Generated by the caller for each write it means to make once. Reuse the same key and the same request for 24 hours after an uncertain response; the same key with a different request is a conflict.", + ), +}); + +export const applyImportResponseRecipientKeyNMax = 1024; + +export const applyImportResponseRecipientKeyEMax = 16; + +export const applyImportResponseRecipientKeyKidMax = 128; + +export const applyImportResponseExpectedPartsItemSha256RegExp = new RegExp( + "^[0-9a-f]{64}$", +); + +export const applyImportResponseExpectedItemCountMin = 0; + +export const applyImportResponseExpectedItemBytesMin = 0; + +export const applyImportResponseImportedItemCountMin = 0; + +export const applyImportResponseImportedItemBytesMin = 0; + +export const ApplyImportResponse = zod.object({ + id: zod.string().min(1), + status: zod + .string() + .describe( + "waiting-for-bundle: no part has arrived. receiving: part 1 has arrived and others are still to come. ready: every part arrived; apply it. importing: being imported. imported: done; read the summary, then verify. failed: it stopped; error says why, and applying again goes on from there. A later OpenBot may add a status; read one you don't know as importing.", + ), + sourceName: zod.string().optional(), + createdAt: zod.iso.datetime({ offset: true }), + finishedAt: zod.iso.datetime({ offset: true }).optional(), + recipientKey: zod + .object({ + kty: zod.literal("RSA"), + n: zod.string().min(1).max(applyImportResponseRecipientKeyNMax), + e: zod.string().min(1).max(applyImportResponseRecipientKeyEMax), + alg: zod.literal("RSA-OAEP-256"), + kid: zod.string().min(1).max(applyImportResponseRecipientKeyKidMax), + }) + .describe( + "A public key as a JSON Web Key (RFC 7517): RSA, 4096 bits, for RSA-OAEP-256. A model key is sealed to it as a JWE (RFC 7516, RSA-OAEP-256 with A256GCM), so only the import that made it reads it.", + ), + maxBundleBytes: zod.int().min(1), + maxPartBytes: zod.int().min(1), + expectedParts: zod + .array( + zod.object({ + number: zod.int().min(1), + bytes: zod.int().min(1), + sha256: zod + .string() + .regex(applyImportResponseExpectedPartsItemSha256RegExp), + }), + ) + .optional() + .describe("The bundle's parts, from its manifest, once part 1 arrived."), + receivedParts: zod + .array(zod.int().min(1)) + .describe("The numbers of the parts that arrived."), + expected: zod + .array( + zod.object({ + kind: zod + .string() + .describe( + "A kind of thing that moves. bots: Bots with their settings and instructions. skills: skills, a Bot's and the person's (and the organization's, for an administrator). conversations and messages: every conversation and every message in it. memories: what the person's Bots remember about them. routines, goals and check-ins: with their schedules. files: files sent in conversations and kept on a Bot's computer. settings: the person's standing instructions and preferences. model-keys: a model key, only when the person chose to bring it. A later OpenBot may add a kind; count one you don't know like any other.", + ), + count: zod.int().min(applyImportResponseExpectedItemCountMin), + bytes: zod + .int() + .min(applyImportResponseExpectedItemBytesMin) + .optional() + .describe("For files, how many bytes they hold together."), + }), + ) + .optional() + .describe( + "Everything the bundle holds by kind, from its manifest, once part 1 arrived.", + ), + imported: zod + .array( + zod.object({ + kind: zod + .string() + .describe( + "A kind of thing that moves. bots: Bots with their settings and instructions. skills: skills, a Bot's and the person's (and the organization's, for an administrator). conversations and messages: every conversation and every message in it. memories: what the person's Bots remember about them. routines, goals and check-ins: with their schedules. files: files sent in conversations and kept on a Bot's computer. settings: the person's standing instructions and preferences. model-keys: a model key, only when the person chose to bring it. A later OpenBot may add a kind; count one you don't know like any other.", + ), + count: zod.int().min(applyImportResponseImportedItemCountMin), + bytes: zod + .int() + .min(applyImportResponseImportedItemBytesMin) + .optional() + .describe("For files, how many bytes they hold together."), + }), + ) + .optional() + .describe( + "What has been imported so far by kind, while importing and once imported. Items a repeated import found already here count as imported.", + ), + notes: zod + .array( + zod + .object({ + code: zod + .string() + .describe( + "isolated-bot-made-ordinary: OpenBot Cloud has no isolated computers, so a Bot that had one runs on an ordinary one. business-plan-feature-left-out: the feature needs the Business plan and this organization isn't on it. model-key-kept-existing: the person already had an AI connection here, which was kept. model-key-not-brought: the person chose not to bring a model key. item-skipped: one item couldn't be imported; message says which and why. A later OpenBot may add a code; show the message.", + ), + kind: zod + .string() + .optional() + .describe( + "A kind of thing that moves. bots: Bots with their settings and instructions. skills: skills, a Bot's and the person's (and the organization's, for an administrator). conversations and messages: every conversation and every message in it. memories: what the person's Bots remember about them. routines, goals and check-ins: with their schedules. files: files sent in conversations and kept on a Bot's computer. settings: the person's standing instructions and preferences. model-keys: a model key, only when the person chose to bring it. A later OpenBot may add a kind; count one you don't know like any other.", + ), + count: zod + .int() + .min(1) + .optional() + .describe("How many items the note is about."), + message: zod.string().min(1), + items: zod + .array(zod.string()) + .optional() + .describe( + "The names of the items, such as the Bots, when there are a few.", + ), + }) + .describe( + "Something that moved differently, or not at all, and why, in a sentence a person reads.", + ), + ) + .optional(), + reconnect: zod + .array( + zod + .object({ + appId: zod + .string() + .min(1) + .describe( + "The app's id in the app directory, such as gmail or slack.", + ), + appName: zod + .string() + .min(1) + .describe("The app's name as a person reads it."), + accountLabel: zod + .string() + .min(1) + .optional() + .describe( + "Which account it was connected as, such as an email address or a workspace name, when known.", + ), + iconUrl: zod + .url() + .optional() + .describe("The app's icon, when the directory has one."), + botNames: zod + .array(zod.string()) + .optional() + .describe( + "The Bots that used it, so the person knows which to check.", + ), + }) + .describe( + "A connection to an app that doesn't move, because its sign-in stays on the person's computer: the person connects it again on OpenBot Cloud. Never carries a token, a password or a key.", + ), + ) + .optional() + .describe("The apps to connect again here, once part 1 arrived."), + error: zod + .string() + .min(1) + .optional() + .describe("What went wrong, when failed, in a sentence a person reads."), +}); + +/** + * Count, by kind, what from this import's OpenBot is in this organization now, read from what is stored here rather than from the import's own tally, beside what the bundle held. matches is true only when every kind is all here, apart from what the notes say OpenBot Cloud left out on purpose. OpenBot Desktop removes nothing on the person's computer until it does. Also lists the apps to connect again. + * @summary Check that everything arrived + */ + +export const getImportVerificationPathImportIdMax = 64; + +export const getImportVerificationPathImportIdRegExp = new RegExp( + "^[A-Za-z0-9_-]+$", +); + +export const GetImportVerificationParams = zod.object({ + organizationId: zod + .string() + .min(1) + .describe( + "The organization, by its id or its slug. One the caller is not a member of answers as one that does not exist, `default` included.", + ), + importId: zod + .string() + .min(1) + .max(getImportVerificationPathImportIdMax) + .regex(getImportVerificationPathImportIdRegExp) + .describe("The import's id."), +}); + +export const getImportVerificationResponseKindsItemExpectedMin = 0; + +export const getImportVerificationResponseKindsItemFoundMin = 0; + +export const getImportVerificationResponseKindsItemLeftOutMin = 0; + +export const getImportVerificationResponseKindsItemExpectedBytesMin = 0; + +export const getImportVerificationResponseKindsItemFoundBytesMin = 0; + +export const GetImportVerificationResponse = zod.object({ + importId: zod.string().min(1), + matches: zod + .boolean() + .describe( + "True when, for every kind, found plus leftOut is expected, and for files foundBytes is expectedBytes.", + ), + kinds: zod.array( + zod.object({ + kind: zod + .string() + .describe( + "A kind of thing that moves. bots: Bots with their settings and instructions. skills: skills, a Bot's and the person's (and the organization's, for an administrator). conversations and messages: every conversation and every message in it. memories: what the person's Bots remember about them. routines, goals and check-ins: with their schedules. files: files sent in conversations and kept on a Bot's computer. settings: the person's standing instructions and preferences. model-keys: a model key, only when the person chose to bring it. A later OpenBot may add a kind; count one you don't know like any other.", + ), + expected: zod + .int() + .min(getImportVerificationResponseKindsItemExpectedMin) + .describe("How many the bundle held."), + found: zod + .int() + .min(getImportVerificationResponseKindsItemFoundMin) + .describe("How many from this OpenBot are in this organization now."), + leftOut: zod + .int() + .min(getImportVerificationResponseKindsItemLeftOutMin) + .describe( + "How many OpenBot Cloud left out on purpose, as the notes say.", + ), + expectedBytes: zod + .int() + .min(getImportVerificationResponseKindsItemExpectedBytesMin) + .optional() + .describe("For files, how many bytes the bundle held."), + foundBytes: zod + .int() + .min(getImportVerificationResponseKindsItemFoundBytesMin) + .optional() + .describe( + "For files, how many bytes are in this organization's file store now, read from the store itself.", + ), + }), + ), + notes: zod.array( + zod + .object({ + code: zod + .string() + .describe( + "isolated-bot-made-ordinary: OpenBot Cloud has no isolated computers, so a Bot that had one runs on an ordinary one. business-plan-feature-left-out: the feature needs the Business plan and this organization isn't on it. model-key-kept-existing: the person already had an AI connection here, which was kept. model-key-not-brought: the person chose not to bring a model key. item-skipped: one item couldn't be imported; message says which and why. A later OpenBot may add a code; show the message.", + ), + kind: zod + .string() + .optional() + .describe( + "A kind of thing that moves. bots: Bots with their settings and instructions. skills: skills, a Bot's and the person's (and the organization's, for an administrator). conversations and messages: every conversation and every message in it. memories: what the person's Bots remember about them. routines, goals and check-ins: with their schedules. files: files sent in conversations and kept on a Bot's computer. settings: the person's standing instructions and preferences. model-keys: a model key, only when the person chose to bring it. A later OpenBot may add a kind; count one you don't know like any other.", + ), + count: zod + .int() + .min(1) + .optional() + .describe("How many items the note is about."), + message: zod.string().min(1), + items: zod + .array(zod.string()) + .optional() + .describe( + "The names of the items, such as the Bots, when there are a few.", + ), + }) + .describe( + "Something that moved differently, or not at all, and why, in a sentence a person reads.", + ), + ), + reconnect: zod.array( + zod + .object({ + appId: zod + .string() + .min(1) + .describe( + "The app's id in the app directory, such as gmail or slack.", + ), + appName: zod + .string() + .min(1) + .describe("The app's name as a person reads it."), + accountLabel: zod + .string() + .min(1) + .optional() + .describe( + "Which account it was connected as, such as an email address or a workspace name, when known.", + ), + iconUrl: zod + .url() + .optional() + .describe("The app's icon, when the directory has one."), + botNames: zod + .array(zod.string()) + .optional() + .describe( + "The Bots that used it, so the person knows which to check.", + ), + }) + .describe( + "A connection to an app that doesn't move, because its sign-in stays on the person's computer: the person connects it again on OpenBot Cloud. Never carries a token, a password or a key.", + ), + ), +});