The Coline App SDK: apps, tools, file types and surfaces that run inside Coline workspaces, and public websites with Coline Sites. TypeScript, with an in-memory test workspace. MIT.
| 6 | emitAmbientEventsInputSchema, |
| 7 | appPermissionSchema, |
| 8 | type AppPermission, |
| 9 | type BatchDeleteAppIndexDocumentsInput, |
| 10 | type BatchUpsertAppIndexDocumentsInput, |
| 11 | type ColineAppRegistrationPayload, |
| 12 | type ColineAppRegistrationPayloadInput, |
| 13 | type CreateNotificationInputInput, |
| 14 | type EmitAmbientEventsInputInput, |
| 15 | } from "./manifest"; |
| 16 | import { ColineApiError } from "./errors"; |
| 17 | import type { components as AppPlatformComponents } from "./generated/app-platform-v1"; |
| 18 | import { |
| 19 | createAppPlatformClient, |
| 20 | type AppPlatformClient, |
| 21 | } from "./app-platform-client"; |
| 22 |
| 23 | interface ApiErrorPayload { |
| 24 | error?: { |
| 25 | code?: string; |
| 26 | message?: string; |
| 27 | }; |
| 28 | } |
| 29 |
| 30 | async function parseJsonResponse<T>(response: Response): Promise<T> { |
| 31 | const payload = (await response.json().catch(() => null)) as T | null; |
| 32 |
| 33 | if (!response.ok) { |
| 34 | const errorMessage = |
| 35 | payload && |
| 36 | typeof payload === "object" && |
| 37 | "error_description" in payload && |
| 38 | typeof (payload as Record<string, unknown>)["error_description"] === "string" |
| 39 | ? ((payload as Record<string, unknown>)["error_description"] as string) |
| 40 | : `Request failed (${response.status}).`; |
| 41 |
| 42 | throw new ColineApiError({ |
| 43 | message: errorMessage, |
| 44 | type: "oauth", |
| 45 | status: response.status, |
| 46 | code: |
| 47 | payload && |
| 48 | typeof payload === "object" && |
| 49 | "error" in payload && |
| 50 | typeof (payload as Record<string, unknown>)["error"] === "string" |
| 51 | ? ((payload as Record<string, unknown>)["error"] as string) |
| 52 | : null, |
| 53 | }); |
| 54 | } |
| 55 |
| 56 | if (!payload) { |
| 57 | throw new ColineApiError({ |
| 58 | message: "Invalid JSON response.", |
| 59 | type: "oauth", |
| 60 | status: response.status, |
| 61 | }); |
| 62 | } |
| 63 |
| 64 | return payload; |
| 65 | } |
| 66 |
| 67 | export interface ColineApiClientOptions { |
| 68 | baseUrl: string; |
| 69 | apiKey?: string; |
| 70 | fetch?: typeof fetch; |
| 71 | headers?: HeadersInit; |
| 72 | /** Maximum number of automatic retries on 429 / 5xx responses (default: 0). */ |
| 73 | maxRetries?: number; |
| 74 | /** Log requests and responses to console for debugging. */ |
| 75 | debug?: boolean; |
| 76 | } |
| 77 |
| 78 | type Schemas = AppPlatformComponents["schemas"]; |
| 79 | type UnwrapData<TKey extends keyof Schemas> = |
| 80 | Schemas[TKey] extends { data: infer T } ? T : never; |
| 81 |
| 82 | export type RegisteredAppDetail = Schemas["RegisteredAppDetail"]; |
| 83 | export type RegisteredAppRecord = Omit< |
| 84 | RegisteredAppDetail, |
| 85 | "latestPublishedVersionId" |
| 86 | >; |
| 87 | export type RegisteredAppVersionSummary = Schemas["RegisteredAppVersionSummary"]; |
| 88 | export type WorkspaceInstalledApp = Schemas["InstalledAppSummary"]; |
| 89 | export type WorkspaceAppCatalogItem = Schemas["AppCatalogItem"]; |
| 90 | export type WorkspaceAppsResponse = UnwrapData<"WorkspaceAppsResponse">; |
| 91 |
| 92 | export interface InstallWorkspaceAppInput { |
| 93 | appId: string; |
| 94 | pinnedVersionId?: string; |
| 95 | grantedPermissions?: AppPermission[]; |
| 96 | } |
| 97 |
| 98 | export type InstallWorkspaceAppResponse = UnwrapData<"InstallWorkspaceAppResponse">; |
| 99 |
| 100 | export interface SubmitAppVersionForReviewInput { |
| 101 | storeListed?: boolean; |
| 102 | } |
| 103 |
| 104 | export type SubmitAppVersionForReviewResponse = UnwrapData< |
| 105 | "SubmitAppVersionForReviewResponse" |
| 106 | >; |
| 107 | export type WorkspaceAppPermissionsResponse = UnwrapData< |
| 108 | "WorkspaceAppPermissionsResponse" |
| 109 | >; |
| 110 | export type WorkspaceInstalledAppResponse = UnwrapData< |
| 111 | "WorkspaceInstalledAppResponse" |
| 112 | >; |
| 113 | export type WorkspaceAppSecretsResponse = UnwrapData< |
| 114 | "WorkspaceAppSecretsResponse" |
| 115 | >; |
| 116 | export type WorkspaceAppSecretSummary = WorkspaceAppSecretsResponse["secrets"][number]; |
| 117 | export type CreateWorkspaceAppSecretResponse = UnwrapData< |
| 118 | "CreateWorkspaceAppSecretResponse" |
| 119 | >; |
| 120 | export type WorkspaceAppOauthConnectionsResponse = UnwrapData< |
| 121 | "WorkspaceAppOauthConnectionsResponse" |
| 122 | >; |
| 123 | export type WorkspaceAppOauthConnectionSummary = |
| 124 | WorkspaceAppOauthConnectionsResponse["connections"][number]; |
| 125 | export type CreateWorkspaceAppOauthConnectionResponse = UnwrapData< |
| 126 | "CreateWorkspaceAppOauthConnectionResponse" |
| 127 | >; |
| 128 | export type WorkspaceAppDeliveriesResponse = UnwrapData< |
| 129 | "WorkspaceAppDeliveriesResponse" |
| 130 | >; |
| 131 | export type WorkspaceAppDeliverySummary = |
| 132 | WorkspaceAppDeliveriesResponse["deliveries"][number]; |
| 133 | export type SendWorkspaceAppTestDeliveryResponse = UnwrapData< |
| 134 | "SendWorkspaceAppTestDeliveryResponse" |
| 135 | >; |
| 136 | export type AppFilesListResponse = UnwrapData<"AppFilesListResponse">; |
| 137 | export type AppFileDocumentResponse = UnwrapData<"AppFileDocumentResponse">; |
| 138 | export type AppFileDocumentUpdateResponse = UnwrapData< |
| 139 | "AppFileDocumentUpdateResponse" |
| 140 | >; |
| 141 | export type CreateAppFileResponse = UnwrapData<"CreateAppFileResponse">; |
| 142 | export type ExecuteAppActionResponse = UnwrapData<"ExecuteAppActionResponse">; |
| 143 | export type OkResponse = UnwrapData<"OkResponse">; |
| 144 | export type TabModelRecord = Schemas["TabModelRecord"]; |
| 145 | export type TabModelsResponse = UnwrapData<"TabModelsResponse">; |
| 146 | export type TabChatCompletionResponse = UnwrapData< |
| 147 | "TabChatCompletionResponseEnvelope" |
| 148 | >; |
| 149 | export type UpsertAppIndexDocumentsResponse = UnwrapData< |
| 150 | "UpsertAppIndexDocumentsResponse" |
| 151 | >; |
| 152 | export type DeleteAppIndexDocumentsResponse = UnwrapData< |
| 153 | "DeleteAppIndexDocumentsResponse" |
| 154 | >; |
| 155 | export type EmitAppAmbientEventsResponse = UnwrapData< |
| 156 | "EmitAppAmbientEventsResponse" |
| 157 | >; |
| 158 |
| 159 | export interface OAuthTokenResponse { |
| 160 | access_token: string; |
| 161 | token_type: "Bearer"; |
| 162 | expires_in: number; |
| 163 | refresh_token: string; |
| 164 | scope: string; |
| 165 | } |
| 166 |
| 167 | export interface OAuthUserInfoResponse { |
| 168 | sub: string; |
| 169 | email: string; |
| 170 | email_verified: boolean; |
| 171 | name: string; |
| 172 | given_name: string | null; |
| 173 | family_name: string | null; |
| 174 | picture: string | null; |
| 175 | preferred_username: string | null; |
| 176 | scope: string; |
| 177 | } |
| 178 |
| 179 | export interface UpdateWorkspaceAppPermissionsInput { |
| 180 | grantedPermissions: AppPermission[]; |
| 181 | } |
| 182 |
| 183 | export interface CreateWorkspaceAppSecretInput { |
| 184 | key: string; |
| 185 | value: string; |
| 186 | } |
| 187 |
| 188 | export interface CreateWorkspaceAppOauthConnectionInput { |
| 189 | providerKey: string; |
| 190 | externalAccountId?: string | null; |
| 191 | accessToken: string; |
| 192 | refreshToken?: string | null; |
| 193 | scopes: string[]; |
| 194 | tokenExpiresAt?: string | null; |
| 195 | metadata?: Record<string, unknown>; |
| 196 | } |
| 197 |
| 198 | export interface SendWorkspaceAppTestDeliveryInput { |
| 199 | eventType: string; |
| 200 | targetUrl?: string; |
| 201 | payload: Record<string, unknown>; |
| 202 | } |
| 203 |
| 204 | export interface ListAppFilesQuery { |
| 205 | driveId?: string; |
| 206 | typeKey?: string; |
| 207 | limit?: number; |
| 208 | } |
| 209 |
| 210 | export interface CreateAppFileInput { |
| 211 | name: string; |
| 212 | typeKey?: string; |
| 213 | driveId?: string; |
| 214 | parentId?: string | null; |
| 215 | document?: Record<string, unknown>; |
| 216 | } |
| 217 |
| 218 | export interface ExecuteAppActionInput { |
| 219 | action: { |
| 220 | type: string; |
| 221 | payload?: Record<string, unknown>; |
| 222 | }; |
| 223 | fileId?: string | null; |
| 224 | } |
| 225 |
| 226 | // --------------------------------------------------------------------------- |
| 227 | // Core Platform API — Types |
| 228 | // --------------------------------------------------------------------------- |
| 229 |
| 230 | export interface WorkspaceMember { |
| 231 | id: string; |
| 232 | workspaceMemberId: string; |
| 233 | email: string; |
| 234 | firstName: string | null; |
| 235 | lastName: string | null; |
| 236 | avatarUrl: string | null; |
| 237 | joinedAt: string; |
| 238 | roles: string[]; |
| 239 | } |
| 240 |
| 241 | export interface WorkspaceMembersResponse { |
| 242 | members: WorkspaceMember[]; |
| 243 | } |
| 244 |
| 245 | export interface WorkspaceNoteSummary { |
| 246 | id: string; |
| 247 | driveId: string; |
| 248 | parentId: string | null; |
| 249 | title: string; |
| 250 | body: string; |
| 251 | color: string | null; |
| 252 | createdByUserId: string | null; |
| 253 | createdAt: string; |
| 254 | updatedAt: string; |
| 255 | } |
| 256 |
| 257 | export interface WorkspaceNoteDetail extends WorkspaceNoteSummary { |
| 258 | blocks: unknown[]; |
| 259 | } |
| 260 |
| 261 | export interface WorkspaceNotesListResponse { |
| 262 | notes: WorkspaceNoteSummary[]; |
| 263 | page: { limit: number; hasMore: boolean; nextCursor: string | null }; |
| 264 | } |
| 265 |
| 266 | export interface WorkspaceNoteResponse { |
| 267 | note: WorkspaceNoteSummary; |
| 268 | } |
| 269 |
| 270 | export interface WorkspaceNoteDetailResponse { |
| 271 | note: WorkspaceNoteDetail; |
| 272 | } |
| 273 |
| 274 | export interface ListWorkspaceNotesQuery { |
| 275 | q?: string; |
| 276 | limit?: number; |
| 277 | cursor?: string; |
| 278 | } |
| 279 |
| 280 | export interface CreateWorkspaceNoteInput { |
| 281 | title?: string; |
| 282 | body?: string; |
| 283 | blocks?: unknown[]; |
| 284 | driveId?: string; |
| 285 | parentId?: string | null; |
| 286 | } |
| 287 |
| 288 | export interface UpdateWorkspaceNoteInput { |
| 289 | title?: string; |
| 290 | body?: string; |
| 291 | blocks?: unknown[]; |
| 292 | } |
| 293 |
| 294 | export interface CalendarEventLinkInput { |
| 295 | linkType: "file" | "channel" | "url"; |
| 296 | fileId?: string; |
| 297 | channelId?: string; |
| 298 | url?: string; |
| 299 | label?: string | null; |
| 300 | } |
| 301 |
| 302 | // --------------------------------------------------------------------------- |
| 303 | // Core Platform API — Calendar Types |
| 304 | // --------------------------------------------------------------------------- |
| 305 |
| 306 | export interface CalendarEventAttendeeUser { |
| 307 | id: string; |
| 308 | firstName: string | null; |
| 309 | lastName: string | null; |
| 310 | avatarUrl: string | null; |
| 311 | email: string; |
| 312 | timezone: string | null; |
| 313 | } |
| 314 |
| 315 | export interface CalendarEventAttendee { |
| 316 | id: string; |
| 317 | userId: string; |
| 318 | role: "organizer" | "attendee"; |
| 319 | responseStatus: "needs_action" | "accepted" | "tentative" | "declined"; |
| 320 | availabilityStatus: "available" | "busy" | "unavailable" | "unknown"; |
| 321 | respondedAt: string | null; |
| 322 | user: CalendarEventAttendeeUser; |
| 323 | } |
| 324 |
| 325 | export interface CalendarEventLink { |
| 326 | id: string; |
| 327 | linkType: "file" | "channel" | "url"; |
| 328 | label: string | null; |
| 329 | url: string | null; |
| 330 | file: { |
| 331 | id: string; |
| 332 | name: string; |
| 333 | fileType: string; |
| 334 | driveId: string; |
| 335 | parentId: string | null; |
| 336 | } | null; |
| 337 | channel: { |
| 338 | id: string; |
| 339 | name: string; |
| 340 | slug: string; |
| 341 | } | null; |
| 342 | } |
| 343 |
| 344 | export interface CalendarSchedulingBooking { |
| 345 | id: string; |
| 346 | schedulingLinkId: string; |
| 347 | calendarEventId: string; |
| 348 | guestName: string; |
| 349 | guestEmail: string; |
| 350 | guestMessage: string | null; |
| 351 | guestTimeZone: string | null; |
| 352 | startsAt: string; |
| 353 | endsAt: string; |
| 354 | status: "active" | "canceled"; |
| 355 | schedulingLink: { |
| 356 | id: string; |
| 357 | slug: string; |
| 358 | title: string; |
| 359 | }; |
| 360 | } |
| 361 |
| 362 | export interface CalendarViewItem { |
| 363 | id: string; |
| 364 | title: string; |
| 365 | startsAt: string; |
| 366 | endsAt: string; |
| 367 | timeZone: string; |
| 368 | isAllDay: boolean; |
| 369 | visibility: "private" | "invitees" | "workspace"; |
| 370 | status: "active" | "canceled"; |
| 371 | recurrenceRule: CalendarRecurrenceRule | Record<string, never>; |
| 372 | attendeeCount: number; |
| 373 | acceptedCount: number; |
| 374 | tentativeCount: number; |
| 375 | declinedCount: number; |
| 376 | myResponse: "needs_action" | "accepted" | "tentative" | "declined" | null; |
| 377 | kind?: "event" | "task"; |
| 378 | taskPriority?: "none" | "low" | "medium" | "high" | "urgent"; |
| 379 | taskCompleted?: boolean; |
| 380 | taskboardId?: string; |
| 381 | } |
| 382 |
| 383 | export interface CalendarEventDetail { |
| 384 | id: string; |
| 385 | workspaceId: string; |
| 386 | title: string; |
| 387 | description: string | null; |
| 388 | location: string | null; |
| 389 | startsAt: string; |
| 390 | endsAt: string; |
| 391 | timeZone: string; |
| 392 | isAllDay: boolean; |
| 393 | visibility: "private" | "invitees" | "workspace"; |
| 394 | status: "active" | "canceled"; |
| 395 | organizerUserId: string; |
| 396 | createdByUserId: string | null; |
| 397 | callProvider: string | null; |
| 398 | callJoinUrl: string | null; |
| 399 | callState: string | null; |
| 400 | recurrenceRule: CalendarRecurrenceRule | Record<string, never>; |
| 401 | attendees: CalendarEventAttendee[]; |
| 402 | links: CalendarEventLink[]; |
| 403 | myAttendance: CalendarEventAttendee | null; |
| 404 | schedulingBooking: CalendarSchedulingBooking | null; |
| 405 | } |
| 406 |
| 407 | // --------------------------------------------------------------------------- |
| 408 | // Core Platform API — Docs Types |
| 409 | // --------------------------------------------------------------------------- |
| 410 |
| 411 | export interface DocLayout { |
| 412 | mode: "pages"; |
| 413 | pageSize: "letter"; |
| 414 | orientation: "portrait" | "landscape"; |
| 415 | margins: "normal" | "narrow" | "wide"; |
| 416 | backgroundColor: string | null; |
| 417 | showPageNumbers: boolean; |
| 418 | } |
| 419 |
| 420 | export interface WorkspaceDocSummary { |
| 421 | id: string; |
| 422 | driveId: string; |
| 423 | parentId: string | null; |
| 424 | title: string; |
| 425 | excerpt: string; |
| 426 | color: string | null; |
| 427 | layout: DocLayout; |
| 428 | createdByUserId: string | null; |
| 429 | createdAt: string; |
| 430 | updatedAt: string; |
| 431 | } |
| 432 |
| 433 | export interface WorkspaceDocDetail extends Omit<WorkspaceDocSummary, "excerpt"> { |
| 434 | content: Record<string, unknown>; |
| 435 | plainText: string; |
| 436 | } |
| 437 |
| 438 | export interface WorkspaceDocsListResponse { |
| 439 | docs: WorkspaceDocSummary[]; |
| 440 | page: { limit: number; hasMore: boolean; nextCursor: string | null }; |
| 441 | } |
| 442 |
| 443 | export interface WorkspaceDocResponse { |
| 444 | doc: WorkspaceDocSummary; |
| 445 | } |
| 446 |
| 447 | export interface WorkspaceDocDetailResponse { |
| 448 | doc: WorkspaceDocDetail; |
| 449 | } |
| 450 |
| 451 | export interface ListWorkspaceDocsQuery { |
| 452 | q?: string; |
| 453 | limit?: number; |
| 454 | cursor?: string; |
| 455 | } |
| 456 |
| 457 | export interface CreateWorkspaceDocInput { |
| 458 | title?: string; |
| 459 | content?: Record<string, unknown>; |
| 460 | layout?: { |
| 461 | orientation?: "portrait" | "landscape"; |
| 462 | margins?: "normal" | "narrow" | "wide"; |
| 463 | backgroundColor?: string | null; |
| 464 | showPageNumbers?: boolean; |
| 465 | }; |
| 466 | driveId?: string; |
| 467 | parentId?: string | null; |
| 468 | } |
| 469 |
| 470 | export interface UpdateWorkspaceDocInput { |
| 471 | title?: string; |
| 472 | content?: Record<string, unknown>; |
| 473 | layout?: { |
| 474 | orientation?: "portrait" | "landscape"; |
| 475 | margins?: "normal" | "narrow" | "wide"; |
| 476 | backgroundColor?: string | null; |
| 477 | showPageNumbers?: boolean; |
| 478 | }; |
| 479 | } |
| 480 |
| 481 | // --------------------------------------------------------------------------- |
| 482 | // Core Platform API — Drives & Files Types |
| 483 | // --------------------------------------------------------------------------- |
| 484 |
| 485 | export interface DriveMountSummary { |
| 486 | type: "native" | "integration"; |
| 487 | providerKey: string | null; |
| 488 | syncStatus: "idle" | "syncing" | "errored" | "disabled"; |
| 489 | } |
| 490 |
| 491 | export interface WorkspaceDriveSummary { |
| 492 | id: string; |
| 493 | name: string; |
| 494 | slug: string; |
| 495 | kind: "personal" | "shared"; |
| 496 | accessMode: "workspace_default" | "restricted"; |
| 497 | isDefault: boolean; |
| 498 | ownerUserId: string | null; |
| 499 | mount: DriveMountSummary; |
| 500 | createdAt: string; |
| 501 | updatedAt: string; |
| 502 | } |
| 503 |
| 504 | export interface WorkspaceDrivesListResponse { |
| 505 | drives: WorkspaceDriveSummary[]; |
| 506 | } |
| 507 |
| 508 | export interface DriveFileSummary { |
| 509 | id: string; |
| 510 | driveId: string; |
| 511 | parentId: string | null; |
| 512 | name: string; |
| 513 | fileType: string; |
| 514 | mimeType: string | null; |
| 515 | sizeBytes: number | null; |
| 516 | color: string | null; |
| 517 | createdByUserId: string | null; |
| 518 | createdAt: string; |
| 519 | updatedAt: string; |
| 520 | } |
| 521 |
| 522 | export interface DriveFilesListResponse { |
| 523 | files: DriveFileSummary[]; |
| 524 | page: { limit: number; hasMore: boolean; nextCursor: string | null }; |
| 525 | } |
| 526 |
| 527 | export interface ListDriveFilesQuery { |
| 528 | parentId?: string; |
| 529 | fileType?: string; |
| 530 | trashed?: boolean; |
| 531 | limit?: number; |
| 532 | cursor?: string; |
| 533 | } |
| 534 |
| 535 | export interface FileDetail { |
| 536 | id: string; |
| 537 | driveId: string; |
| 538 | parentId: string | null; |
| 539 | name: string; |
| 540 | fileType: string; |
| 541 | mimeType: string | null; |
| 542 | sizeBytes: number | null; |
| 543 | color: string | null; |
| 544 | accessMode: string; |
| 545 | isTrashed: boolean; |
| 546 | createdByUserId: string | null; |
| 547 | createdAt: string; |
| 548 | updatedAt: string; |
| 549 | } |
| 550 |
| 551 | export interface FileDetailResponse { |
| 552 | file: FileDetail; |
| 553 | } |
| 554 |
| 555 | export interface UpdateFileInput { |
| 556 | name?: string; |
| 557 | parentId?: string | null; |
| 558 | color?: "red" | "orange" | "yellow" | "green" | "blue" | "purple" | "pink" | "gray" | null; |
| 559 | } |
| 560 |
| 561 | // --------------------------------------------------------------------------- |
| 562 | // Channels |
| 563 | // --------------------------------------------------------------------------- |
| 564 |
| 565 | export interface ChannelSummary { |
| 566 | id: string; |
| 567 | name: string; |
| 568 | slug: string; |
| 569 | description: string | null; |
| 570 | topic: string | null; |
| 571 | type: "public" | "private"; |
| 572 | isDefault: boolean; |
| 573 | createdAt: string; |
| 574 | updatedAt: string; |
| 575 | } |
| 576 |
| 577 | export interface ChannelListResponse { |
| 578 | channels: ChannelSummary[]; |
| 579 | } |
| 580 |
| 581 | // --------------------------------------------------------------------------- |
| 582 | // Direct Messages |
| 583 | // --------------------------------------------------------------------------- |
| 584 |
| 585 | export interface DmMemberSummary { |
| 586 | userId: string; |
| 587 | firstName: string | null; |
| 588 | lastName: string | null; |
| 589 | email: string; |
| 590 | } |
| 591 |
| 592 | export interface DmSummary { |
| 593 | id: string; |
| 594 | isGroup: boolean; |
| 595 | name: string | null; |
| 596 | members: DmMemberSummary[]; |
| 597 | createdAt: string; |
| 598 | updatedAt: string; |
| 599 | } |
| 600 |
| 601 | export interface DmListResponse { |
| 602 | dms: DmSummary[]; |
| 603 | } |
| 604 |
| 605 | // --------------------------------------------------------------------------- |
| 606 | // Messages |
| 607 | // --------------------------------------------------------------------------- |
| 608 |
| 609 | export interface MessageTextPart { |
| 610 | type: "text"; |
| 611 | text: string; |
| 612 | } |
| 613 |
| 614 | export interface MessageMentionPart { |
| 615 | type: "mention"; |
| 616 | userId: string; |
| 617 | displayName: string; |
| 618 | } |
| 619 |
| 620 | export type MessageContentPart = MessageTextPart | MessageMentionPart; |
| 621 |
| 622 | export interface ContainerMessageSummary { |
| 623 | id: string; |
| 624 | authorUserId: string | null; |
| 625 | messageKind: string; |
| 626 | plaintext: string; |
| 627 | content: MessageContentPart[]; |
| 628 | replyToMessageId: string | null; |
| 629 | editedAt: string | null; |
| 630 | createdAt: string; |
| 631 | updatedAt: string; |
| 632 | } |
| 633 |
| 634 | export interface MessagesListResponse { |
| 635 | messages: ContainerMessageSummary[]; |
| 636 | page: { |
| 637 | limit: number; |
| 638 | hasMore: boolean; |
| 639 | nextCursor: string | null; |
| 640 | }; |
| 641 | } |
| 642 |
| 643 | export interface SendMessageInput { |
| 644 | content: MessageContentPart[]; |
| 645 | replyToMessageId?: string | null; |
| 646 | threadRootMessageId?: string | null; |
| 647 | } |
| 648 |
| 649 | export interface SendMessageResponse { |
| 650 | message: ContainerMessageSummary; |
| 651 | } |
| 652 |
| 653 | export interface MessageDetailResponse { |
| 654 | message: ContainerMessageSummary & { |
| 655 | containerType: string; |
| 656 | containerId: string; |
| 657 | }; |
| 658 | } |
| 659 |
| 660 | export interface EditMessageInput { |
| 661 | content: MessageContentPart[]; |
| 662 | } |
| 663 |
| 664 | export interface ThreadResponse { |
| 665 | rootMessage: MessageDetailResponse["message"]; |
| 666 | replies: ContainerMessageSummary[]; |
| 667 | } |
| 668 |
| 669 | export interface ThreadReplyInput { |
| 670 | content: MessageContentPart[]; |
| 671 | } |
| 672 |
| 673 | export interface ReactionResponse { |
| 674 | messageId: string; |
| 675 | emoji: string; |
| 676 | count: number; |
| 677 | } |
| 678 |
| 679 | export interface PinResponse { |
| 680 | messageId: string; |
| 681 | pinned: boolean; |
| 682 | } |
| 683 |
| 684 | export interface CalendarRecurrenceRule { |
| 685 | frequency: "daily" | "weekly" | "monthly" | "yearly"; |
| 686 | interval: number; |
| 687 | byDay?: Array<"MO" | "TU" | "WE" | "TH" | "FR" | "SA" | "SU">; |
| 688 | count?: number; |
| 689 | until?: string; |
| 690 | } |
| 691 |
| 692 | export interface CreateCalendarEventInput { |
| 693 | title: string; |
| 694 | description?: string | null; |
| 695 | location?: string | null; |
| 696 | startsAt: string; |
| 697 | endsAt: string; |
| 698 | timeZone: string; |
| 699 | isAllDay?: boolean; |
| 700 | visibility?: "private" | "invitees" | "workspace"; |
| 701 | attendeeUserIds?: string[]; |
| 702 | linkInputs?: CalendarEventLinkInput[]; |
| 703 | recurrenceRule?: CalendarRecurrenceRule | null; |
| 704 | } |
| 705 |
| 706 | export interface UpdateCalendarEventInput { |
| 707 | title?: string; |
| 708 | description?: string | null; |
| 709 | location?: string | null; |
| 710 | startsAt?: string; |
| 711 | endsAt?: string; |
| 712 | timeZone?: string; |
| 713 | isAllDay?: boolean; |
| 714 | visibility?: "private" | "invitees" | "workspace"; |
| 715 | status?: "active" | "canceled"; |
| 716 | attendeeUserIds?: string[]; |
| 717 | linkInputs?: CalendarEventLinkInput[]; |
| 718 | recurrenceRule?: CalendarRecurrenceRule | null; |
| 719 | } |
| 720 |
| 721 | export interface CalendarEventsListResponse { |
| 722 | items: CalendarViewItem[]; |
| 723 | range: { start: string; end: string }; |
| 724 | } |
| 725 |
| 726 | export interface CalendarEventDetailResponse { |
| 727 | event: CalendarEventDetail; |
| 728 | } |
| 729 |
| 730 | export interface WorkspaceSearchInput { |
| 731 | query: string; |
| 732 | sourceKinds?: Array< |
| 733 | "file" | "task" | "container_message" | "kairo_message" | "app_document" |
| 734 | >; |
| 735 | limit?: number; |
| 736 | cursor?: string; |
| 737 | } |
| 738 |
| 739 | export interface WorkspaceSearchResult { |
| 740 | id: string; |
| 741 | title: string | null; |
| 742 | snippet: string | null; |
| 743 | sourceKind: string; |
| 744 | sourceId: string; |
| 745 | url: string | null; |
| 746 | score: number; |
| 747 | } |
| 748 |
| 749 | export interface WorkspaceSearchResponse { |
| 750 | results: WorkspaceSearchResult[]; |
| 751 | nextCursor: string | null; |
| 752 | } |
| 753 |
| 754 | export interface TaskboardStatusSummary { |
| 755 | id: string; |
| 756 | key: string; |
| 757 | name: string; |
| 758 | color: string; |
| 759 | isDefault: boolean; |
| 760 | isCompleted: boolean; |
| 761 | sortOrder: number; |
| 762 | } |
| 763 |
| 764 | export interface TaskboardSummary { |
| 765 | id: string; |
| 766 | name: string; |
| 767 | driveId: string; |
| 768 | color: string | null; |
| 769 | identifierPrefix: string | null; |
| 770 | description: string | null; |
| 771 | defaultView: string | null; |
| 772 | statuses: TaskboardStatusSummary[]; |
| 773 | createdAt: string; |
| 774 | updatedAt: string; |
| 775 | } |
| 776 |
| 777 | export interface WorkspaceTaskboardsResponse { |
| 778 | taskboards: TaskboardSummary[]; |
| 779 | } |
| 780 |
| 781 | export interface TaskAssignee { |
| 782 | id: string; |
| 783 | firstName: string | null; |
| 784 | lastName: string | null; |
| 785 | avatarUrl: string | null; |
| 786 | email: string; |
| 787 | } |
| 788 |
| 789 | export interface TaskSummary { |
| 790 | id: string; |
| 791 | taskboardId: string; |
| 792 | taskNumber: number; |
| 793 | identifier: string | null; |
| 794 | title: string; |
| 795 | description: string | null; |
| 796 | status: { |
| 797 | id: string; |
| 798 | key: string; |
| 799 | name: string; |
| 800 | color: string; |
| 801 | isCompleted: boolean; |
| 802 | } | null; |
| 803 | priority: string; |
| 804 | labels: string[]; |
| 805 | dueDate: string | null; |
| 806 | assignees: TaskAssignee[]; |
| 807 | isCompleted: boolean; |
| 808 | completedAt: string | null; |
| 809 | createdByUserId: string | null; |
| 810 | createdAt: string; |
| 811 | updatedAt: string; |
| 812 | } |
| 813 |
| 814 | export interface TaskboardTasksResponse { |
| 815 | tasks: TaskSummary[]; |
| 816 | } |
| 817 |
| 818 | export interface ListTaskboardTasksQuery { |
| 819 | q?: string; |
| 820 | statusId?: string; |
| 821 | assigneeUserId?: string; |
| 822 | limit?: number; |
| 823 | } |
| 824 |
| 825 | export interface CreateTaskInput { |
| 826 | title: string; |
| 827 | description?: string; |
| 828 | statusId?: string; |
| 829 | priority?: "none" | "low" | "medium" | "high" | "urgent"; |
| 830 | dueDate?: string | null; |
| 831 | labels?: string[]; |
| 832 | assigneeUserIds?: string[]; |
| 833 | } |
| 834 |
| 835 | export interface CreateTaskResponse { |
| 836 | task: { |
| 837 | id: string; |
| 838 | taskboardId: string; |
| 839 | title: string; |
| 840 | description: string; |
| 841 | statusId: string; |
| 842 | priority: string; |
| 843 | labels: string[]; |
| 844 | dueDate: string | null; |
| 845 | assigneeUserIds: string[]; |
| 846 | createdByUserId: string; |
| 847 | createdAt: string; |
| 848 | updatedAt: string; |
| 849 | }; |
| 850 | } |
| 851 |
| 852 | export interface UpdateTaskInput { |
| 853 | title?: string; |
| 854 | description?: string; |
| 855 | statusId?: string; |
| 856 | priority?: "none" | "low" | "medium" | "high" | "urgent"; |
| 857 | dueDate?: string | null; |
| 858 | labels?: string[]; |
| 859 | assigneeUserIds?: string[]; |
| 860 | } |
| 861 |
| 862 | // --------------------------------------------------------------------------- |
| 863 | // Tab streaming types |
| 864 | // --------------------------------------------------------------------------- |
| 865 |
| 866 | export interface TabChatCompletionInput { |
| 867 | model?: string; |
| 868 | tab_context: { |
| 869 | surface: "notes" | "docs" | "messages" | "tasks" | "calendar"; |
| 870 | workspace_slug: string; |
| 871 | entity_id: string; |
| 872 | active_text_before_cursor: string; |
| 873 | active_text_after_cursor?: string; |
| 874 | surrounding_context?: string; |
| 875 | block_kind?: string; |
| 876 | note_title?: string; |
| 877 | document_title?: string; |
| 878 | document_type?: "plaintext" | "markdown"; |
| 879 | taskboard_file_id?: string; |
| 880 | }; |
| 881 | messages?: Array<{ role?: string; content?: string }>; |
| 882 | max_tokens?: number; |
| 883 | temperature?: number; |
| 884 | top_p?: number; |
| 885 | } |
| 886 |
| 887 | export interface TabChatCompletionChunk { |
| 888 | id: string; |
| 889 | object: "chat.completion.chunk"; |
| 890 | created: number; |
| 891 | model: string; |
| 892 | choices: Array<{ |
| 893 | index: number; |
| 894 | delta: { |
| 895 | role?: string; |
| 896 | content?: string; |
| 897 | }; |
| 898 | finish_reason: string | null; |
| 899 | }>; |
| 900 | } |
| 901 |
| 902 | // --------------------------------------------------------------------------- |
| 903 | // File upload types |
| 904 | // --------------------------------------------------------------------------- |
| 905 |
| 906 | export interface InitiateUploadInput { |
| 907 | fileName: string; |
| 908 | mimeType: string; |
| 909 | sizeBytes: number; |
| 910 | driveId: string; |
| 911 | parentId?: string | null; |
| 912 | } |
| 913 |
| 914 | export interface InitiateUploadResponse { |
| 915 | uploadId: string; |
| 916 | partCount: number; |
| 917 | } |
| 918 |
| 919 | export interface UploadPartResponse { |
| 920 | partNumber: number; |
| 921 | etag: string; |
| 922 | } |
| 923 |
| 924 | export interface CompletedUploadPart { |
| 925 | partNumber: number; |
| 926 | etag: string; |
| 927 | } |
| 928 |
| 929 | export interface UploadedFile { |
| 930 | id: string; |
| 931 | driveId: string; |
| 932 | parentId: string | null; |
| 933 | name: string; |
| 934 | fileType: string; |
| 935 | mimeType: string | null; |
| 936 | sizeBytes: number | null; |
| 937 | color: string | null; |
| 938 | createdAt: string; |
| 939 | updatedAt: string; |
| 940 | } |
| 941 |
| 942 | export interface CompleteUploadResponse { |
| 943 | file: UploadedFile; |
| 944 | } |
| 945 |
| 946 | export interface UploadFileInput { |
| 947 | data: Blob | ArrayBuffer | Uint8Array; |
| 948 | fileName: string; |
| 949 | mimeType: string; |
| 950 | driveId: string; |
| 951 | parentId?: string | null; |
| 952 | } |
| 953 |
| 954 | // --------------------------------------------------------------------------- |
| 955 | // Batch task types |
| 956 | // --------------------------------------------------------------------------- |
| 957 |
| 958 | export interface BatchUpdateTaskEntry extends UpdateTaskInput { |
| 959 | taskId: string; |
| 960 | } |
| 961 |
| 962 | export interface BatchResultEntry<T> { |
| 963 | status: "fulfilled" | "rejected"; |
| 964 | value?: T; |
| 965 | reason?: string; |
| 966 | } |
| 967 |
| 968 | // --------------------------------------------------------------------------- |
| 969 | // Pagination helper |
| 970 | // --------------------------------------------------------------------------- |
| 971 |
| 972 | /** |
| 973 | * A page from a paginated endpoint. |
| 974 | */ |
| 975 | export interface Page<T> { |
| 976 | items: T[]; |
| 977 | nextCursor: string | null; |
| 978 | hasMore: boolean; |
| 979 | } |
| 980 |
| 981 | /** |
| 982 | * Async generator that auto-fetches subsequent pages from a paginated Coline |
| 983 | * endpoint. Yields one item at a time. |
| 984 | * |
| 985 | * @example |
| 986 | * ```ts |
| 987 | * const ws = coline.workspace("ws_123"); |
| 988 | * for await (const note of ws.paginateNotes({ limit: 50 })) { |
| 989 | * console.log(note.title); |
| 990 | * } |
| 991 | * ``` |
| 992 | */ |
| 993 | export async function* paginate<T>( |
| 994 | fetchPage: (cursor: string | undefined) => Promise<Page<T>>, |
| 995 | ): AsyncGenerator<T, void, undefined> { |
| 996 | let cursor: string | undefined = undefined; |
| 997 | // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition |
| 998 | while (true) { |
| 999 | const page = await fetchPage(cursor); |
| 1000 | for (const item of page.items) { |
| 1001 | yield item; |
| 1002 | } |
| 1003 | if (!page.hasMore || page.nextCursor === null) break; |
| 1004 | cursor = page.nextCursor; |
| 1005 | } |
| 1006 | } |
| 1007 |
| 1008 | // --------------------------------------------------------------------------- |
| 1009 | // Retry + backoff helper |
| 1010 | // --------------------------------------------------------------------------- |
| 1011 |
| 1012 | function isRetryableStatus(status: number): boolean { |
| 1013 | return status === 429 || status >= 500; |
| 1014 | } |
| 1015 |
| 1016 | async function sleep(ms: number): Promise<void> { |
| 1017 | return new Promise((resolve) => setTimeout(resolve, ms)); |
| 1018 | } |
| 1019 |
| 1020 | function joinUrl(baseUrl: string, path: string): string { |
| 1021 | return `${baseUrl.replace(/\/+$/, "")}${path}`; |
| 1022 | } |
| 1023 |
| 1024 | function toRegisterAppInput(payload: ColineAppRegistrationPayload) { |
| 1025 | const notificationChannels = payload.manifest.notificationChannels.map((channel) => ({ |
| 1026 | key: channel.key, |
| 1027 | name: channel.name, |
| 1028 | defaultDeliveries: [...channel.defaultDeliveries], |
| 1029 | defaultPriority: channel.defaultPriority, |
| 1030 | ...(channel.description ? { description: channel.description } : {}), |
| 1031 | })); |
| 1032 |
| 1033 | const ui = |
| 1034 | payload.manifest.ui.mode || payload.manifest.ui.homePath || payload.manifest.ui.filePath |
| 1035 | ? { |
| 1036 | ...(payload.manifest.ui.mode |
| 1037 | ? { mode: payload.manifest.ui.mode } |
| 1038 | : {}), |
| 1039 | ...(payload.manifest.ui.homePath |
| 1040 | ? { homePath: payload.manifest.ui.homePath } |
| 1041 | : {}), |
| 1042 | ...(payload.manifest.ui.filePath |
| 1043 | ? { filePath: payload.manifest.ui.filePath } |
| 1044 | : {}), |
| 1045 | } |
| 1046 | : undefined; |
| 1047 |
| 1048 | const manifest = { |
| 1049 | key: payload.manifest.key, |
| 1050 | name: payload.manifest.name, |
| 1051 | permissions: payload.manifest.permissions, |
| 1052 | notificationChannels, |
| 1053 | hosting: { |
| 1054 | mode: payload.manifest.hosting.mode, |
| 1055 | baseUrl: payload.manifest.hosting.baseUrl, |
| 1056 | }, |
| 1057 | ...(ui ? { ui } : {}), |
| 1058 | ...(payload.manifest.description |
| 1059 | ? { description: payload.manifest.description } |
| 1060 | : {}), |
| 1061 | ...(payload.manifest.iconUrl ? { iconUrl: payload.manifest.iconUrl } : {}), |
| 1062 | ...(payload.manifest.kairo |
| 1063 | ? { |
| 1064 | kairo: JSON.parse(JSON.stringify(payload.manifest.kairo)) as Record< |
| 1065 | string, |
| 1066 | unknown |
| 1067 | >, |
| 1068 | } |
| 1069 | : {}), |
| 1070 | }; |
| 1071 |
| 1072 | const fileTypes = payload.fileTypes.map((fileType) => ({ |
| 1073 | typeKey: fileType.typeKey, |
| 1074 | name: fileType.name, |
| 1075 | storage: fileType.storage, |
| 1076 | indexable: fileType.indexable, |
| 1077 | homeRenderMode: fileType.homeRenderMode, |
| 1078 | ...(fileType.description ? { description: fileType.description } : {}), |
| 1079 | })); |
| 1080 |
| 1081 | return { |
| 1082 | version: payload.version, |
| 1083 | manifest, |
| 1084 | fileTypes, |
| 1085 | }; |
| 1086 | } |
| 1087 |
| 1088 | export class ColineApiClient { |
| 1089 | private readonly baseUrl: string; |
| 1090 | private readonly apiKey: string | undefined; |
| 1091 | private readonly fetchImpl: typeof fetch; |
| 1092 | private readonly defaultHeaders: HeadersInit | undefined; |
| 1093 | private readonly appPlatformClient: AppPlatformClient; |
| 1094 | private readonly maxRetries: number; |
| 1095 | private readonly debug: boolean; |
| 1096 |
| 1097 | constructor(options: ColineApiClientOptions) { |
| 1098 | this.baseUrl = options.baseUrl; |
| 1099 | this.apiKey = options.apiKey; |
| 1100 | this.fetchImpl = options.fetch ?? fetch; |
| 1101 | this.defaultHeaders = options.headers; |
| 1102 | this.maxRetries = options.maxRetries ?? 0; |
| 1103 | this.debug = options.debug ?? false; |
| 1104 | this.appPlatformClient = createAppPlatformClient(options); |
| 1105 | } |
| 1106 |
| 1107 | private async unwrapGeneratedResponse<T>( |
| 1108 | promise: Promise<{ |
| 1109 | data?: { data: T }; |
| 1110 | error?: ApiErrorPayload; |
| 1111 | response: Response; |
| 1112 | }>, |
| 1113 | ): Promise<T> { |
| 1114 | const { data, error, response } = await promise; |
| 1115 |
| 1116 | if (error) { |
| 1117 | throw new ColineApiError({ |
| 1118 | message: error.error?.message ?? `Request failed (${response.status}).`, |
| 1119 | type: "api", |
| 1120 | status: response.status, |
| 1121 | code: error.error?.code ?? null, |
| 1122 | }); |
| 1123 | } |
| 1124 |
| 1125 | if (data === undefined) { |
| 1126 | throw new ColineApiError({ |
| 1127 | message: "Invalid API response.", |
| 1128 | type: "api", |
| 1129 | status: response.status, |
| 1130 | }); |
| 1131 | } |
| 1132 |
| 1133 | return data.data; |
| 1134 | } |
| 1135 |
| 1136 | withApiKey(apiKey: string): ColineApiClient { |
| 1137 | const options: ColineApiClientOptions = { |
| 1138 | baseUrl: this.baseUrl, |
| 1139 | apiKey, |
| 1140 | fetch: this.fetchImpl, |
| 1141 | maxRetries: this.maxRetries, |
| 1142 | debug: this.debug, |
| 1143 | }; |
| 1144 |
| 1145 | if (this.defaultHeaders !== undefined) { |
| 1146 | options.headers = this.defaultHeaders; |
| 1147 | } |
| 1148 |
| 1149 | return new ColineApiClient(options); |
| 1150 | } |
| 1151 |
| 1152 | withHeaders(headers: HeadersInit): ColineApiClient { |
| 1153 | const mergedHeaders = new Headers(this.defaultHeaders); |
| 1154 | new Headers(headers).forEach((value, key) => mergedHeaders.set(key, value)); |
| 1155 |
| 1156 | const options: ColineApiClientOptions = { |
| 1157 | baseUrl: this.baseUrl, |
| 1158 | fetch: this.fetchImpl, |
| 1159 | headers: mergedHeaders, |
| 1160 | maxRetries: this.maxRetries, |
| 1161 | debug: this.debug, |
| 1162 | }; |
| 1163 |
| 1164 | if (this.apiKey !== undefined) { |
| 1165 | options.apiKey = this.apiKey; |
| 1166 | } |
| 1167 |
| 1168 | return new ColineApiClient(options); |
| 1169 | } |
| 1170 |
| 1171 | buildLoginWithColineAuthorizeUrl(input: { |
| 1172 | clientId: string; |
| 1173 | redirectUri: string; |
| 1174 | scope?: string; |
| 1175 | state?: string; |
| 1176 | codeChallenge?: string; |
| 1177 | codeChallengeMethod?: "S256" | "plain"; |
| 1178 | }): string { |
| 1179 | const url = new URL("/api/v1/oauth/authorize", this.baseUrl); |
| 1180 | url.searchParams.set("response_type", "code"); |
| 1181 | url.searchParams.set("client_id", input.clientId); |
| 1182 | url.searchParams.set("redirect_uri", input.redirectUri); |
| 1183 | if (input.scope) { |
| 1184 | url.searchParams.set("scope", input.scope); |
| 1185 | } |
| 1186 | if (input.state) { |
| 1187 | url.searchParams.set("state", input.state); |
| 1188 | } |
| 1189 | if (input.codeChallenge) { |
| 1190 | url.searchParams.set("code_challenge", input.codeChallenge); |
| 1191 | } |
| 1192 | if (input.codeChallengeMethod) { |
| 1193 | url.searchParams.set("code_challenge_method", input.codeChallengeMethod); |
| 1194 | } |
| 1195 | return url.toString(); |
| 1196 | } |
| 1197 |
| 1198 | async listApps(): Promise<{ apps: RegisteredAppRecord[] }> { |
| 1199 | return this.unwrapGeneratedResponse( |
| 1200 | this.appPlatformClient.GET("/api/v1/apps"), |
| 1201 | ); |
| 1202 | } |
| 1203 |
| 1204 | async getApp(appKey: string): Promise<{ app: RegisteredAppDetail }> { |
| 1205 | return this.unwrapGeneratedResponse( |
| 1206 | this.appPlatformClient.GET("/api/v1/apps/{appKey}", { |
| 1207 | params: { path: { appKey } }, |
| 1208 | }), |
| 1209 | ); |
| 1210 | } |
| 1211 |
| 1212 | async listAppVersions( |
| 1213 | appKey: string, |
| 1214 | ): Promise<{ versions: RegisteredAppVersionSummary[] }> { |
| 1215 | return this.unwrapGeneratedResponse( |
| 1216 | this.appPlatformClient.GET("/api/v1/apps/{appKey}/versions", { |
| 1217 | params: { path: { appKey } }, |
| 1218 | }), |
| 1219 | ); |
| 1220 | } |
| 1221 |
| 1222 | async registerApp( |
| 1223 | payload: ColineAppRegistrationPayloadInput, |
| 1224 | ): Promise<{ appId: string; appKey: string; versionId: string; version: string }> { |
| 1225 | const body = toRegisterAppInput(colineAppRegistrationPayloadSchema.parse(payload)); |
| 1226 |
| 1227 | return this.unwrapGeneratedResponse( |
| 1228 | this.appPlatformClient.POST("/api/v1/apps", { |
| 1229 | body, |
| 1230 | }), |
| 1231 | ); |
| 1232 | } |
| 1233 |
| 1234 | async createAppVersion( |
| 1235 | appKey: string, |
| 1236 | payload: ColineAppRegistrationPayloadInput, |
| 1237 | ): Promise<{ appId: string; appKey: string; versionId: string; version: string }> { |
| 1238 | const body = toRegisterAppInput(colineAppRegistrationPayloadSchema.parse(payload)); |
| 1239 |
| 1240 | return this.unwrapGeneratedResponse( |
| 1241 | this.appPlatformClient.POST("/api/v1/apps/{appKey}/versions", { |
| 1242 | params: { path: { appKey } }, |
| 1243 | body, |
| 1244 | }), |
| 1245 | ); |
| 1246 | } |
| 1247 |
| 1248 | async submitAppVersionForReview( |
| 1249 | appKey: string, |
| 1250 | versionId: string, |
| 1251 | input: SubmitAppVersionForReviewInput = {}, |
| 1252 | ): Promise<SubmitAppVersionForReviewResponse> { |
| 1253 | return this.unwrapGeneratedResponse( |
| 1254 | this.appPlatformClient.POST( |
| 1255 | "/api/v1/apps/{appKey}/versions/{versionId}/submit", |
| 1256 | { |
| 1257 | params: { path: { appKey, versionId } }, |
| 1258 | body: { |
| 1259 | ...(input.storeListed !== undefined |
| 1260 | ? { storeListed: input.storeListed } |
| 1261 | : {}), |
| 1262 | }, |
| 1263 | }, |
| 1264 | ), |
| 1265 | ); |
| 1266 | } |
| 1267 |
| 1268 | async listWorkspaceApps(workspaceSlug: string): Promise<WorkspaceAppsResponse> { |
| 1269 | return this.unwrapGeneratedResponse( |
| 1270 | this.appPlatformClient.GET("/api/v1/workspaces/{workspaceSlug}/apps", { |
| 1271 | params: { path: { workspaceSlug } }, |
| 1272 | }), |
| 1273 | ); |
| 1274 | } |
| 1275 |
| 1276 | async installWorkspaceApp( |
| 1277 | workspaceSlug: string, |
| 1278 | input: InstallWorkspaceAppInput, |
| 1279 | ): Promise<InstallWorkspaceAppResponse> { |
| 1280 | const grantedPermissions = input.grantedPermissions |
| 1281 | ? input.grantedPermissions.map((permission) => |
| 1282 | appPermissionSchema.parse(permission), |
| 1283 | ) |
| 1284 | : undefined; |
| 1285 |
| 1286 | return this.unwrapGeneratedResponse( |
| 1287 | this.appPlatformClient.POST("/api/v1/workspaces/{workspaceSlug}/apps", { |
| 1288 | params: { path: { workspaceSlug } }, |
| 1289 | body: { |
| 1290 | appId: input.appId, |
| 1291 | ...(input.pinnedVersionId |
| 1292 | ? { pinnedVersionId: input.pinnedVersionId } |
| 1293 | : {}), |
| 1294 | ...(grantedPermissions ? { grantedPermissions } : {}), |
| 1295 | }, |
| 1296 | }), |
| 1297 | ); |
| 1298 | } |
| 1299 |
| 1300 | async getWorkspaceAppPermissions( |
| 1301 | workspaceSlug: string, |
| 1302 | appKey: string, |
| 1303 | ): Promise<WorkspaceAppPermissionsResponse> { |
| 1304 | return this.unwrapGeneratedResponse( |
| 1305 | this.appPlatformClient.GET( |
| 1306 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/permissions", |
| 1307 | { |
| 1308 | params: { path: { workspaceSlug, appKey } }, |
| 1309 | }, |
| 1310 | ), |
| 1311 | ); |
| 1312 | } |
| 1313 |
| 1314 | async getWorkspaceInstalledApp( |
| 1315 | workspaceSlug: string, |
| 1316 | appKey: string, |
| 1317 | ): Promise<WorkspaceInstalledAppResponse> { |
| 1318 | return this.unwrapGeneratedResponse( |
| 1319 | this.appPlatformClient.GET("/api/v1/workspaces/{workspaceSlug}/apps/{appKey}", { |
| 1320 | params: { path: { workspaceSlug, appKey } }, |
| 1321 | }), |
| 1322 | ); |
| 1323 | } |
| 1324 |
| 1325 | async updateWorkspaceAppPermissions( |
| 1326 | workspaceSlug: string, |
| 1327 | appKey: string, |
| 1328 | input: UpdateWorkspaceAppPermissionsInput, |
| 1329 | ): Promise<WorkspaceAppPermissionsResponse> { |
| 1330 | return this.unwrapGeneratedResponse( |
| 1331 | this.appPlatformClient.PUT( |
| 1332 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/permissions", |
| 1333 | { |
| 1334 | params: { path: { workspaceSlug, appKey } }, |
| 1335 | body: { |
| 1336 | grantedPermissions: input.grantedPermissions.map((permission) => |
| 1337 | appPermissionSchema.parse(permission), |
| 1338 | ), |
| 1339 | }, |
| 1340 | }, |
| 1341 | ), |
| 1342 | ); |
| 1343 | } |
| 1344 |
| 1345 | async uninstallWorkspaceApp( |
| 1346 | workspaceSlug: string, |
| 1347 | appKey: string, |
| 1348 | ): Promise<{ ok: true }> { |
| 1349 | return this.unwrapGeneratedResponse( |
| 1350 | this.appPlatformClient.DELETE( |
| 1351 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}", |
| 1352 | { |
| 1353 | params: { path: { workspaceSlug, appKey } }, |
| 1354 | }, |
| 1355 | ), |
| 1356 | ); |
| 1357 | } |
| 1358 |
| 1359 | async listWorkspaceAppSecrets( |
| 1360 | workspaceSlug: string, |
| 1361 | appKey: string, |
| 1362 | ): Promise<WorkspaceAppSecretsResponse> { |
| 1363 | return this.unwrapGeneratedResponse( |
| 1364 | this.appPlatformClient.GET( |
| 1365 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/secrets", |
| 1366 | { |
| 1367 | params: { path: { workspaceSlug, appKey } }, |
| 1368 | }, |
| 1369 | ), |
| 1370 | ); |
| 1371 | } |
| 1372 |
| 1373 | async createWorkspaceAppSecret( |
| 1374 | workspaceSlug: string, |
| 1375 | appKey: string, |
| 1376 | input: CreateWorkspaceAppSecretInput, |
| 1377 | ): Promise<CreateWorkspaceAppSecretResponse> { |
| 1378 | return this.unwrapGeneratedResponse( |
| 1379 | this.appPlatformClient.POST( |
| 1380 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/secrets", |
| 1381 | { |
| 1382 | params: { path: { workspaceSlug, appKey } }, |
| 1383 | body: input, |
| 1384 | }, |
| 1385 | ), |
| 1386 | ); |
| 1387 | } |
| 1388 |
| 1389 | async deleteWorkspaceAppSecret( |
| 1390 | workspaceSlug: string, |
| 1391 | appKey: string, |
| 1392 | secretId: string, |
| 1393 | ): Promise<{ ok: true }> { |
| 1394 | return this.unwrapGeneratedResponse( |
| 1395 | this.appPlatformClient.DELETE( |
| 1396 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/secrets/{secretId}", |
| 1397 | { |
| 1398 | params: { path: { workspaceSlug, appKey, secretId } }, |
| 1399 | }, |
| 1400 | ), |
| 1401 | ); |
| 1402 | } |
| 1403 |
| 1404 | async listWorkspaceAppOauthConnections( |
| 1405 | workspaceSlug: string, |
| 1406 | appKey: string, |
| 1407 | ): Promise<WorkspaceAppOauthConnectionsResponse> { |
| 1408 | return this.unwrapGeneratedResponse( |
| 1409 | this.appPlatformClient.GET( |
| 1410 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/oauth-connections", |
| 1411 | { |
| 1412 | params: { path: { workspaceSlug, appKey } }, |
| 1413 | }, |
| 1414 | ), |
| 1415 | ); |
| 1416 | } |
| 1417 |
| 1418 | async createWorkspaceAppOauthConnection( |
| 1419 | workspaceSlug: string, |
| 1420 | appKey: string, |
| 1421 | input: CreateWorkspaceAppOauthConnectionInput, |
| 1422 | ): Promise<CreateWorkspaceAppOauthConnectionResponse> { |
| 1423 | const body: { |
| 1424 | providerKey: string; |
| 1425 | accessToken: string; |
| 1426 | scopes: string[]; |
| 1427 | externalAccountId?: string; |
| 1428 | refreshToken?: string; |
| 1429 | tokenExpiresAt?: string; |
| 1430 | metadata?: Record<string, unknown>; |
| 1431 | } = { |
| 1432 | providerKey: input.providerKey, |
| 1433 | accessToken: input.accessToken, |
| 1434 | scopes: input.scopes, |
| 1435 | }; |
| 1436 |
| 1437 | if (input.externalAccountId) { |
| 1438 | body.externalAccountId = input.externalAccountId; |
| 1439 | } |
| 1440 | if (input.refreshToken) { |
| 1441 | body.refreshToken = input.refreshToken; |
| 1442 | } |
| 1443 | if (input.tokenExpiresAt) { |
| 1444 | body.tokenExpiresAt = input.tokenExpiresAt; |
| 1445 | } |
| 1446 | if (input.metadata) { |
| 1447 | body.metadata = input.metadata; |
| 1448 | } |
| 1449 |
| 1450 | return this.unwrapGeneratedResponse( |
| 1451 | this.appPlatformClient.POST( |
| 1452 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/oauth-connections", |
| 1453 | { |
| 1454 | params: { path: { workspaceSlug, appKey } }, |
| 1455 | body, |
| 1456 | }, |
| 1457 | ), |
| 1458 | ); |
| 1459 | } |
| 1460 |
| 1461 | async deleteWorkspaceAppOauthConnection( |
| 1462 | workspaceSlug: string, |
| 1463 | appKey: string, |
| 1464 | connectionId: string, |
| 1465 | ): Promise<{ ok: true }> { |
| 1466 | return this.unwrapGeneratedResponse( |
| 1467 | this.appPlatformClient.DELETE( |
| 1468 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/oauth-connections/{connectionId}", |
| 1469 | { |
| 1470 | params: { path: { workspaceSlug, appKey, connectionId } }, |
| 1471 | }, |
| 1472 | ), |
| 1473 | ); |
| 1474 | } |
| 1475 |
| 1476 | async listWorkspaceAppDeliveries( |
| 1477 | workspaceSlug: string, |
| 1478 | appKey: string, |
| 1479 | ): Promise<WorkspaceAppDeliveriesResponse> { |
| 1480 | return this.unwrapGeneratedResponse( |
| 1481 | this.appPlatformClient.GET( |
| 1482 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/deliveries", |
| 1483 | { |
| 1484 | params: { path: { workspaceSlug, appKey } }, |
| 1485 | }, |
| 1486 | ), |
| 1487 | ); |
| 1488 | } |
| 1489 |
| 1490 | async sendWorkspaceAppTestDelivery( |
| 1491 | workspaceSlug: string, |
| 1492 | appKey: string, |
| 1493 | input: SendWorkspaceAppTestDeliveryInput, |
| 1494 | ): Promise<SendWorkspaceAppTestDeliveryResponse> { |
| 1495 | return this.unwrapGeneratedResponse( |
| 1496 | this.appPlatformClient.POST( |
| 1497 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/deliveries", |
| 1498 | { |
| 1499 | params: { path: { workspaceSlug, appKey } }, |
| 1500 | body: input, |
| 1501 | }, |
| 1502 | ), |
| 1503 | ); |
| 1504 | } |
| 1505 |
| 1506 | async replayWorkspaceAppDelivery( |
| 1507 | workspaceSlug: string, |
| 1508 | appKey: string, |
| 1509 | deliveryId: string, |
| 1510 | ): Promise<SendWorkspaceAppTestDeliveryResponse> { |
| 1511 | return this.unwrapGeneratedResponse( |
| 1512 | this.appPlatformClient.POST( |
| 1513 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/deliveries/{deliveryId}/replay", |
| 1514 | { |
| 1515 | params: { path: { workspaceSlug, appKey, deliveryId } }, |
| 1516 | }, |
| 1517 | ), |
| 1518 | ); |
| 1519 | } |
| 1520 |
| 1521 | async emitAppAmbientEvents( |
| 1522 | workspaceSlug: string, |
| 1523 | appKey: string, |
| 1524 | input: EmitAmbientEventsInputInput, |
| 1525 | ): Promise<EmitAppAmbientEventsResponse> { |
| 1526 | const parsed = emitAmbientEventsInputSchema.parse(input); |
| 1527 | const body = { |
| 1528 | events: parsed.events.map((event) => ({ |
| 1529 | sourceKind: event.sourceKind, |
| 1530 | action: event.action, |
| 1531 | entityType: event.entityType, |
| 1532 | entityId: event.entityId, |
| 1533 | dedupeKey: event.dedupeKey, |
| 1534 | payload: event.payload, |
| 1535 | metadata: event.metadata, |
| 1536 | schemaVersion: event.schemaVersion, |
| 1537 | ...(event.actorUserId ? { actorUserId: event.actorUserId } : {}), |
| 1538 | ...(event.containerType ? { containerType: event.containerType } : {}), |
| 1539 | ...(event.containerId ? { containerId: event.containerId } : {}), |
| 1540 | ...(event.occurredAt |
| 1541 | ? { occurredAt: event.occurredAt.toISOString() } |
| 1542 | : {}), |
| 1543 | })), |
| 1544 | }; |
| 1545 |
| 1546 | return this.unwrapGeneratedResponse( |
| 1547 | this.appPlatformClient.POST( |
| 1548 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/ambient/events", |
| 1549 | { |
| 1550 | params: { path: { workspaceSlug, appKey } }, |
| 1551 | body, |
| 1552 | }, |
| 1553 | ), |
| 1554 | ); |
| 1555 | } |
| 1556 |
| 1557 | async createAppNotification( |
| 1558 | workspaceSlug: string, |
| 1559 | appKey: string, |
| 1560 | input: CreateNotificationInputInput, |
| 1561 | ): Promise<OkResponse> { |
| 1562 | const parsed = createNotificationInputSchema.parse(input); |
| 1563 | const body = { |
| 1564 | channelKey: parsed.channelKey, |
| 1565 | typeKey: parsed.typeKey, |
| 1566 | recipients: parsed.recipients.map((recipient) => ({ |
| 1567 | userId: recipient.userId, |
| 1568 | })), |
| 1569 | title: parsed.title, |
| 1570 | priority: parsed.priority, |
| 1571 | metadata: parsed.metadata, |
| 1572 | ...(parsed.body ? { body: parsed.body } : {}), |
| 1573 | ...(parsed.targetUrl ? { targetUrl: parsed.targetUrl } : {}), |
| 1574 | ...(parsed.icon ? { icon: parsed.icon } : {}), |
| 1575 | ...(parsed.dedupeKey ? { dedupeKey: parsed.dedupeKey } : {}), |
| 1576 | }; |
| 1577 |
| 1578 | return this.unwrapGeneratedResponse( |
| 1579 | this.appPlatformClient.POST( |
| 1580 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/notifications", |
| 1581 | { |
| 1582 | params: { path: { workspaceSlug, appKey } }, |
| 1583 | body, |
| 1584 | }, |
| 1585 | ), |
| 1586 | ); |
| 1587 | } |
| 1588 |
| 1589 | async upsertAppIndexDocuments( |
| 1590 | workspaceSlug: string, |
| 1591 | appKey: string, |
| 1592 | input: BatchUpsertAppIndexDocumentsInput, |
| 1593 | ): Promise<UpsertAppIndexDocumentsResponse> { |
| 1594 | const parsed = batchUpsertAppIndexDocumentsSchema.parse(input); |
| 1595 | const body = { |
| 1596 | documents: parsed.documents.map((document) => ({ |
| 1597 | documentKey: document.documentKey, |
| 1598 | documentType: document.documentType, |
| 1599 | title: document.title, |
| 1600 | body: document.body, |
| 1601 | metadata: document.metadata, |
| 1602 | visibilityMode: document.visibilityMode, |
| 1603 | visibility: document.visibility.map((grant) => ({ |
| 1604 | subjectType: grant.subjectType, |
| 1605 | subjectId: grant.subjectId, |
| 1606 | })), |
| 1607 | ...(document.fileId ? { fileId: document.fileId } : {}), |
| 1608 | ...(document.url ? { url: document.url } : {}), |
| 1609 | })), |
| 1610 | }; |
| 1611 |
| 1612 | return this.unwrapGeneratedResponse( |
| 1613 | this.appPlatformClient.POST( |
| 1614 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/index-documents", |
| 1615 | { |
| 1616 | params: { path: { workspaceSlug, appKey } }, |
| 1617 | body, |
| 1618 | }, |
| 1619 | ), |
| 1620 | ); |
| 1621 | } |
| 1622 |
| 1623 | async deleteAppIndexDocuments( |
| 1624 | workspaceSlug: string, |
| 1625 | appKey: string, |
| 1626 | input: BatchDeleteAppIndexDocumentsInput, |
| 1627 | ): Promise<DeleteAppIndexDocumentsResponse> { |
| 1628 | const body = batchDeleteAppIndexDocumentsSchema.parse(input); |
| 1629 |
| 1630 | return this.unwrapGeneratedResponse( |
| 1631 | this.appPlatformClient.DELETE( |
| 1632 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/index-documents", |
| 1633 | { |
| 1634 | params: { path: { workspaceSlug, appKey } }, |
| 1635 | body, |
| 1636 | }, |
| 1637 | ), |
| 1638 | ); |
| 1639 | } |
| 1640 |
| 1641 | async listAppFiles( |
| 1642 | workspaceSlug: string, |
| 1643 | appKey: string, |
| 1644 | query?: ListAppFilesQuery, |
| 1645 | ): Promise<AppFilesListResponse> { |
| 1646 | return this.unwrapGeneratedResponse( |
| 1647 | this.appPlatformClient.GET( |
| 1648 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/files", |
| 1649 | { |
| 1650 | params: { |
| 1651 | path: { workspaceSlug, appKey }, |
| 1652 | ...(query |
| 1653 | ? { |
| 1654 | query: { |
| 1655 | ...(query.driveId ? { driveId: query.driveId } : {}), |
| 1656 | ...(query.typeKey ? { typeKey: query.typeKey } : {}), |
| 1657 | ...(query.limit !== undefined ? { limit: query.limit } : {}), |
| 1658 | }, |
| 1659 | } |
| 1660 | : {}), |
| 1661 | }, |
| 1662 | }, |
| 1663 | ), |
| 1664 | ); |
| 1665 | } |
| 1666 |
| 1667 | async createAppFile( |
| 1668 | workspaceSlug: string, |
| 1669 | appKey: string, |
| 1670 | input: CreateAppFileInput, |
| 1671 | ): Promise<CreateAppFileResponse> { |
| 1672 | return this.unwrapGeneratedResponse( |
| 1673 | this.appPlatformClient.POST( |
| 1674 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/files", |
| 1675 | { |
| 1676 | params: { path: { workspaceSlug, appKey } }, |
| 1677 | body: { |
| 1678 | name: input.name, |
| 1679 | ...(input.typeKey ? { typeKey: input.typeKey } : {}), |
| 1680 | ...(input.driveId ? { driveId: input.driveId } : {}), |
| 1681 | ...(input.parentId !== undefined ? { parentId: input.parentId } : {}), |
| 1682 | ...(input.document ? { document: input.document } : {}), |
| 1683 | }, |
| 1684 | }, |
| 1685 | ), |
| 1686 | ); |
| 1687 | } |
| 1688 |
| 1689 | async executeAppAction( |
| 1690 | workspaceSlug: string, |
| 1691 | appKey: string, |
| 1692 | input: ExecuteAppActionInput, |
| 1693 | ): Promise<ExecuteAppActionResponse> { |
| 1694 | return this.unwrapGeneratedResponse( |
| 1695 | this.appPlatformClient.POST( |
| 1696 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/actions", |
| 1697 | { |
| 1698 | params: { path: { workspaceSlug, appKey } }, |
| 1699 | body: { |
| 1700 | action: { |
| 1701 | type: input.action.type, |
| 1702 | ...(input.action.payload ? { payload: input.action.payload } : {}), |
| 1703 | }, |
| 1704 | ...(input.fileId !== undefined ? { fileId: input.fileId } : {}), |
| 1705 | }, |
| 1706 | }, |
| 1707 | ), |
| 1708 | ); |
| 1709 | } |
| 1710 |
| 1711 | async getAppFileDocument( |
| 1712 | workspaceSlug: string, |
| 1713 | appKey: string, |
| 1714 | fileId: string, |
| 1715 | ): Promise<AppFileDocumentResponse> { |
| 1716 | return this.unwrapGeneratedResponse( |
| 1717 | this.appPlatformClient.GET( |
| 1718 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/files/{fileId}", |
| 1719 | { |
| 1720 | params: { path: { workspaceSlug, appKey, fileId } }, |
| 1721 | }, |
| 1722 | ), |
| 1723 | ); |
| 1724 | } |
| 1725 |
| 1726 | async updateAppFileDocument( |
| 1727 | workspaceSlug: string, |
| 1728 | appKey: string, |
| 1729 | fileId: string, |
| 1730 | document: Record<string, unknown>, |
| 1731 | ): Promise<AppFileDocumentUpdateResponse> { |
| 1732 | return this.unwrapGeneratedResponse( |
| 1733 | this.appPlatformClient.PATCH( |
| 1734 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/files/{fileId}", |
| 1735 | { |
| 1736 | params: { path: { workspaceSlug, appKey, fileId } }, |
| 1737 | body: { document }, |
| 1738 | }, |
| 1739 | ), |
| 1740 | ); |
| 1741 | } |
| 1742 |
| 1743 | async deleteAppFile( |
| 1744 | workspaceSlug: string, |
| 1745 | appKey: string, |
| 1746 | fileId: string, |
| 1747 | ): Promise<OkResponse> { |
| 1748 | return this.unwrapGeneratedResponse( |
| 1749 | this.appPlatformClient.DELETE( |
| 1750 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/files/{fileId}", |
| 1751 | { |
| 1752 | params: { path: { workspaceSlug, appKey, fileId } }, |
| 1753 | }, |
| 1754 | ), |
| 1755 | ); |
| 1756 | } |
| 1757 |
| 1758 | async listTabModels(): Promise<TabModelsResponse> { |
| 1759 | return this.unwrapGeneratedResponse( |
| 1760 | this.appPlatformClient.GET("/api/v1/tab/models"), |
| 1761 | ); |
| 1762 | } |
| 1763 |
| 1764 | async createTabChatCompletion( |
| 1765 | input: TabChatCompletionInput, |
| 1766 | ): Promise<TabChatCompletionResponse> { |
| 1767 | const body = { |
| 1768 | model: input.model ?? "tab-v1", |
| 1769 | stream: false as const, |
| 1770 | tab_context: input.tab_context as Record<string, unknown>, |
| 1771 | ...(input.messages !== undefined ? { messages: input.messages } : {}), |
| 1772 | ...(input.max_tokens !== undefined ? { max_tokens: input.max_tokens } : {}), |
| 1773 | ...(input.temperature !== undefined ? { temperature: input.temperature } : {}), |
| 1774 | ...(input.top_p !== undefined ? { top_p: input.top_p } : {}), |
| 1775 | }; |
| 1776 | return this.unwrapGeneratedResponse( |
| 1777 | this.appPlatformClient.POST("/api/v1/tab/chat/completions", { body }), |
| 1778 | ); |
| 1779 | } |
| 1780 |
| 1781 | /** |
| 1782 | * Stream a Tab chat completion as an async generator of SSE chunks. |
| 1783 | * |
| 1784 | * @example |
| 1785 | * ```ts |
| 1786 | * const stream = client.streamTabChatCompletion({ |
| 1787 | * tab_context: { |
| 1788 | * surface: "docs", |
| 1789 | * workspace_slug: "acme", |
| 1790 | * entity_id: "doc_123", |
| 1791 | * active_text_before_cursor: "The quick brown ", |
| 1792 | * }, |
| 1793 | * }); |
| 1794 | * |
| 1795 | * for await (const chunk of stream) { |
| 1796 | * process.stdout.write(chunk.choices[0]?.delta.content ?? ""); |
| 1797 | * } |
| 1798 | * ``` |
| 1799 | */ |
| 1800 | async *streamTabChatCompletion( |
| 1801 | input: TabChatCompletionInput, |
| 1802 | ): AsyncGenerator<TabChatCompletionChunk, void, undefined> { |
| 1803 | const url = joinUrl(this.baseUrl, "/api/v1/tab/chat/completions"); |
| 1804 | const headers: Record<string, string> = { |
| 1805 | "Content-Type": "application/json", |
| 1806 | Accept: "text/event-stream", |
| 1807 | }; |
| 1808 | if (this.apiKey) { |
| 1809 | headers["Authorization"] = `Bearer ${this.apiKey}`; |
| 1810 | } |
| 1811 | if (this.defaultHeaders) { |
| 1812 | new Headers(this.defaultHeaders).forEach((v, k) => { |
| 1813 | headers[k] = v; |
| 1814 | }); |
| 1815 | } |
| 1816 |
| 1817 | const response = await this.fetchImpl(url, { |
| 1818 | method: "POST", |
| 1819 | headers, |
| 1820 | body: JSON.stringify({ ...input, stream: true }), |
| 1821 | }); |
| 1822 |
| 1823 | if (!response.ok) { |
| 1824 | const payload = (await response.json().catch(() => null)) as ApiErrorPayload | null; |
| 1825 | throw new ColineApiError({ |
| 1826 | message: payload?.error?.message ?? `Request failed (${response.status}).`, |
| 1827 | type: "api", |
| 1828 | status: response.status, |
| 1829 | code: payload?.error?.code ?? null, |
| 1830 | }); |
| 1831 | } |
| 1832 |
| 1833 | if (!response.body) { |
| 1834 | return; |
| 1835 | } |
| 1836 |
| 1837 | const reader = response.body.getReader(); |
| 1838 | const decoder = new TextDecoder(); |
| 1839 | let buffer = ""; |
| 1840 |
| 1841 | try { |
| 1842 | while (true) { |
| 1843 | const { done, value } = await reader.read(); |
| 1844 | if (done) break; |
| 1845 |
| 1846 | buffer += decoder.decode(value, { stream: true }); |
| 1847 | const lines = buffer.split("\n"); |
| 1848 | buffer = lines.pop() ?? ""; |
| 1849 |
| 1850 | for (const line of lines) { |
| 1851 | const trimmed = line.trim(); |
| 1852 | if (!trimmed || !trimmed.startsWith("data: ")) continue; |
| 1853 | const data = trimmed.slice(6); |
| 1854 | if (data === "[DONE]") return; |
| 1855 |
| 1856 | try { |
| 1857 | const chunk = JSON.parse(data) as TabChatCompletionChunk; |
| 1858 | yield chunk; |
| 1859 | } catch { |
| 1860 | // Skip malformed chunks |
| 1861 | } |
| 1862 | } |
| 1863 | } |
| 1864 | } finally { |
| 1865 | reader.releaseLock(); |
| 1866 | } |
| 1867 | } |
| 1868 |
| 1869 | /** |
| 1870 | * Stream a Tab chat completion and yield only the text content. |
| 1871 | * |
| 1872 | * @example |
| 1873 | * ```ts |
| 1874 | * for await (const text of client.streamTabText({ |
| 1875 | * tab_context: { |
| 1876 | * surface: "notes", |
| 1877 | * workspace_slug: "acme", |
| 1878 | * entity_id: "note_123", |
| 1879 | * active_text_before_cursor: "Today I need to ", |
| 1880 | * }, |
| 1881 | * })) { |
| 1882 | * process.stdout.write(text); |
| 1883 | * } |
| 1884 | * ``` |
| 1885 | */ |
| 1886 | async *streamTabText( |
| 1887 | input: TabChatCompletionInput, |
| 1888 | ): AsyncGenerator<string, void, undefined> { |
| 1889 | for await (const chunk of this.streamTabChatCompletion(input)) { |
| 1890 | const content = chunk.choices[0]?.delta.content; |
| 1891 | if (content) yield content; |
| 1892 | } |
| 1893 | } |
| 1894 |
| 1895 | async exchangeOAuthCode(input: { |
| 1896 | clientId: string; |
| 1897 | clientSecret: string; |
| 1898 | code: string; |
| 1899 | redirectUri: string; |
| 1900 | codeVerifier?: string; |
| 1901 | }): Promise<OAuthTokenResponse> { |
| 1902 | const response = await this.fetchImpl(joinUrl(this.baseUrl, "/api/v1/oauth/token"), { |
| 1903 | method: "POST", |
| 1904 | headers: { |
| 1905 | "Content-Type": "application/json", |
| 1906 | }, |
| 1907 | body: JSON.stringify({ |
| 1908 | grant_type: "authorization_code", |
| 1909 | client_id: input.clientId, |
| 1910 | client_secret: input.clientSecret, |
| 1911 | code: input.code, |
| 1912 | redirect_uri: input.redirectUri, |
| 1913 | ...(input.codeVerifier ? { code_verifier: input.codeVerifier } : {}), |
| 1914 | }), |
| 1915 | }); |
| 1916 |
| 1917 | return parseJsonResponse<OAuthTokenResponse>(response); |
| 1918 | } |
| 1919 |
| 1920 | async getOAuthUserInfo(accessToken: string): Promise<OAuthUserInfoResponse> { |
| 1921 | const response = await this.fetchImpl(joinUrl(this.baseUrl, "/api/v1/oauth/userinfo"), { |
| 1922 | method: "GET", |
| 1923 | headers: { |
| 1924 | Authorization: `Bearer ${accessToken}`, |
| 1925 | }, |
| 1926 | }); |
| 1927 |
| 1928 | return parseJsonResponse<OAuthUserInfoResponse>(response); |
| 1929 | } |
| 1930 |
| 1931 | // --------------------------------------------------------------------------- |
| 1932 | // Core Platform API — internal fetch helper |
| 1933 | // --------------------------------------------------------------------------- |
| 1934 |
| 1935 | private async coreRequest<T>( |
| 1936 | method: string, |
| 1937 | path: string, |
| 1938 | body?: unknown, |
| 1939 | ): Promise<T> { |
| 1940 | const url = joinUrl(this.baseUrl, path); |
| 1941 | const headers: Record<string, string> = {}; |
| 1942 | if (this.apiKey) { |
| 1943 | headers["Authorization"] = `Bearer ${this.apiKey}`; |
| 1944 | } |
| 1945 | if (body !== undefined) { |
| 1946 | headers["Content-Type"] = "application/json"; |
| 1947 | } |
| 1948 | if (this.defaultHeaders) { |
| 1949 | new Headers(this.defaultHeaders).forEach((v, k) => { |
| 1950 | headers[k] = v; |
| 1951 | }); |
| 1952 | } |
| 1953 |
| 1954 | const requestInit: RequestInit = { |
| 1955 | method, |
| 1956 | headers, |
| 1957 | ...(body !== undefined ? { body: JSON.stringify(body) } : {}), |
| 1958 | }; |
| 1959 |
| 1960 | if (this.debug) { |
| 1961 | console.debug(`[coline-sdk] ${method} ${path}`, body !== undefined ? { body } : ""); |
| 1962 | } |
| 1963 |
| 1964 | let lastError: ColineApiError | undefined; |
| 1965 |
| 1966 | for (let attempt = 0; attempt <= this.maxRetries; attempt++) { |
| 1967 | if (attempt > 0) { |
| 1968 | // Exponential backoff: 500ms, 1s, 2s, 4s ... |
| 1969 | const delayMs = Math.min(500 * Math.pow(2, attempt - 1), 30_000); |
| 1970 | if (this.debug) { |
| 1971 | console.debug(`[coline-sdk] retry ${attempt}/${this.maxRetries} after ${delayMs}ms`); |
| 1972 | } |
| 1973 | await sleep(delayMs); |
| 1974 | } |
| 1975 |
| 1976 | const response = await this.fetchImpl(url, requestInit); |
| 1977 |
| 1978 | if (!response.ok) { |
| 1979 | const payload = (await response.json().catch(() => null)) as ApiErrorPayload | null; |
| 1980 | const error = new ColineApiError({ |
| 1981 | message: |
| 1982 | payload?.error?.message ?? `Request failed (${response.status}).`, |
| 1983 | type: "api", |
| 1984 | status: response.status, |
| 1985 | code: payload?.error?.code ?? null, |
| 1986 | }); |
| 1987 |
| 1988 | // Retry on 429 (rate limit) and 5xx (server errors) |
| 1989 | if (isRetryableStatus(response.status) && attempt < this.maxRetries) { |
| 1990 | lastError = error; |
| 1991 | continue; |
| 1992 | } |
| 1993 |
| 1994 | if (this.debug) { |
| 1995 | console.debug(`[coline-sdk] ${method} ${path} → ${response.status}`, payload); |
| 1996 | } |
| 1997 |
| 1998 | throw error; |
| 1999 | } |
| 2000 |
| 2001 | const json = (await response.json().catch(() => null)) as { |
| 2002 | data: T; |
| 2003 | } | null; |
| 2004 |
| 2005 | if (!json || !("data" in json)) { |
| 2006 | throw new ColineApiError({ |
| 2007 | message: "Invalid API response.", |
| 2008 | type: "api", |
| 2009 | status: response.status, |
| 2010 | }); |
| 2011 | } |
| 2012 |
| 2013 | if (this.debug) { |
| 2014 | console.debug(`[coline-sdk] ${method} ${path} → ${response.status} OK`); |
| 2015 | } |
| 2016 |
| 2017 | return json.data; |
| 2018 | } |
| 2019 |
| 2020 | // Should not reach here, but safety net |
| 2021 | throw lastError ?? new ColineApiError({ |
| 2022 | message: "Max retries exceeded.", |
| 2023 | type: "api", |
| 2024 | status: 0, |
| 2025 | }); |
| 2026 | } |
| 2027 |
| 2028 | /** |
| 2029 | * Like `coreRequest` but accepts a raw `BodyInit` and custom Content-Type. |
| 2030 | * Used for binary uploads. |
| 2031 | */ |
| 2032 | private async coreRawRequest<T>( |
| 2033 | method: string, |
| 2034 | path: string, |
| 2035 | body: BodyInit | undefined, |
| 2036 | contentType?: string, |
| 2037 | ): Promise<T> { |
| 2038 | const url = joinUrl(this.baseUrl, path); |
| 2039 | const headers: Record<string, string> = {}; |
| 2040 | if (this.apiKey) { |
| 2041 | headers["Authorization"] = `Bearer ${this.apiKey}`; |
| 2042 | } |
| 2043 | if (contentType) { |
| 2044 | headers["Content-Type"] = contentType; |
| 2045 | } |
| 2046 | if (this.defaultHeaders) { |
| 2047 | new Headers(this.defaultHeaders).forEach((v, k) => { |
| 2048 | headers[k] = v; |
| 2049 | }); |
| 2050 | } |
| 2051 |
| 2052 | const response = await this.fetchImpl(url, { |
| 2053 | method, |
| 2054 | headers, |
| 2055 | ...(body !== undefined ? { body } : {}), |
| 2056 | }); |
| 2057 |
| 2058 | if (!response.ok) { |
| 2059 | const payload = (await response.json().catch(() => null)) as ApiErrorPayload | null; |
| 2060 | throw new ColineApiError({ |
| 2061 | message: payload?.error?.message ?? `Request failed (${response.status}).`, |
| 2062 | type: "api", |
| 2063 | status: response.status, |
| 2064 | code: payload?.error?.code ?? null, |
| 2065 | }); |
| 2066 | } |
| 2067 |
| 2068 | const json = (await response.json().catch(() => null)) as { data: T } | null; |
| 2069 | if (!json || !("data" in json)) { |
| 2070 | throw new ColineApiError({ |
| 2071 | message: "Invalid API response.", |
| 2072 | type: "api", |
| 2073 | status: response.status, |
| 2074 | }); |
| 2075 | } |
| 2076 |
| 2077 | return json.data; |
| 2078 | } |
| 2079 |
| 2080 | // --------------------------------------------------------------------------- |
| 2081 | // Core Platform API — Workspace Members |
| 2082 | // --------------------------------------------------------------------------- |
| 2083 |
| 2084 | async listWorkspaceMembers( |
| 2085 | workspaceId: string, |
| 2086 | ): Promise<WorkspaceMembersResponse> { |
| 2087 | return this.coreRequest<WorkspaceMembersResponse>( |
| 2088 | "GET", |
| 2089 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/members`, |
| 2090 | ); |
| 2091 | } |
| 2092 |
| 2093 | // --------------------------------------------------------------------------- |
| 2094 | // Core Platform API — Notes |
| 2095 | // --------------------------------------------------------------------------- |
| 2096 |
| 2097 | async listWorkspaceNotes( |
| 2098 | workspaceId: string, |
| 2099 | query?: ListWorkspaceNotesQuery, |
| 2100 | ): Promise<WorkspaceNotesListResponse> { |
| 2101 | const params = new URLSearchParams(); |
| 2102 | if (query?.q) params.set("q", query.q); |
| 2103 | if (query?.limit !== undefined) params.set("limit", String(query.limit)); |
| 2104 | if (query?.cursor) params.set("cursor", query.cursor); |
| 2105 | const qs = params.toString(); |
| 2106 | return this.coreRequest<WorkspaceNotesListResponse>( |
| 2107 | "GET", |
| 2108 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/notes${qs ? `?${qs}` : ""}`, |
| 2109 | ); |
| 2110 | } |
| 2111 |
| 2112 | async createWorkspaceNote( |
| 2113 | workspaceId: string, |
| 2114 | input: CreateWorkspaceNoteInput, |
| 2115 | ): Promise<WorkspaceNoteResponse> { |
| 2116 | return this.coreRequest<WorkspaceNoteResponse>( |
| 2117 | "POST", |
| 2118 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/notes`, |
| 2119 | { |
| 2120 | ...(input.title !== undefined ? { title: input.title } : {}), |
| 2121 | ...(input.body !== undefined ? { body: input.body } : {}), |
| 2122 | ...(input.blocks !== undefined ? { blocks: input.blocks } : {}), |
| 2123 | ...(input.driveId !== undefined ? { driveId: input.driveId } : {}), |
| 2124 | ...(input.parentId !== undefined ? { parentId: input.parentId } : {}), |
| 2125 | }, |
| 2126 | ); |
| 2127 | } |
| 2128 |
| 2129 | async getWorkspaceNote( |
| 2130 | workspaceId: string, |
| 2131 | noteId: string, |
| 2132 | ): Promise<WorkspaceNoteDetailResponse> { |
| 2133 | return this.coreRequest<WorkspaceNoteDetailResponse>( |
| 2134 | "GET", |
| 2135 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/notes/${encodeURIComponent(noteId)}`, |
| 2136 | ); |
| 2137 | } |
| 2138 |
| 2139 | async updateWorkspaceNote( |
| 2140 | workspaceId: string, |
| 2141 | noteId: string, |
| 2142 | input: UpdateWorkspaceNoteInput, |
| 2143 | ): Promise<WorkspaceNoteResponse> { |
| 2144 | return this.coreRequest<WorkspaceNoteResponse>( |
| 2145 | "PUT", |
| 2146 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/notes/${encodeURIComponent(noteId)}`, |
| 2147 | input, |
| 2148 | ); |
| 2149 | } |
| 2150 |
| 2151 | async deleteWorkspaceNote( |
| 2152 | workspaceId: string, |
| 2153 | noteId: string, |
| 2154 | ): Promise<{ ok: true }> { |
| 2155 | return this.coreRequest<{ ok: true }>( |
| 2156 | "DELETE", |
| 2157 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/notes/${encodeURIComponent(noteId)}`, |
| 2158 | ); |
| 2159 | } |
| 2160 |
| 2161 | // --------------------------------------------------------------------------- |
| 2162 | // Core Platform API — Docs |
| 2163 | // --------------------------------------------------------------------------- |
| 2164 |
| 2165 | async listWorkspaceDocs( |
| 2166 | workspaceId: string, |
| 2167 | query?: ListWorkspaceDocsQuery, |
| 2168 | ): Promise<WorkspaceDocsListResponse> { |
| 2169 | const params = new URLSearchParams(); |
| 2170 | if (query?.q) params.set("q", query.q); |
| 2171 | if (query?.limit !== undefined) params.set("limit", String(query.limit)); |
| 2172 | if (query?.cursor) params.set("cursor", query.cursor); |
| 2173 | const qs = params.toString(); |
| 2174 | return this.coreRequest<WorkspaceDocsListResponse>( |
| 2175 | "GET", |
| 2176 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/docs${qs ? `?${qs}` : ""}`, |
| 2177 | ); |
| 2178 | } |
| 2179 |
| 2180 | async createWorkspaceDoc( |
| 2181 | workspaceId: string, |
| 2182 | input: CreateWorkspaceDocInput, |
| 2183 | ): Promise<WorkspaceDocResponse> { |
| 2184 | return this.coreRequest<WorkspaceDocResponse>( |
| 2185 | "POST", |
| 2186 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/docs`, |
| 2187 | { |
| 2188 | ...(input.title !== undefined ? { title: input.title } : {}), |
| 2189 | ...(input.content !== undefined ? { content: input.content } : {}), |
| 2190 | ...(input.layout !== undefined ? { layout: input.layout } : {}), |
| 2191 | ...(input.driveId !== undefined ? { driveId: input.driveId } : {}), |
| 2192 | ...(input.parentId !== undefined ? { parentId: input.parentId } : {}), |
| 2193 | }, |
| 2194 | ); |
| 2195 | } |
| 2196 |
| 2197 | async getWorkspaceDoc( |
| 2198 | workspaceId: string, |
| 2199 | docId: string, |
| 2200 | ): Promise<WorkspaceDocDetailResponse> { |
| 2201 | return this.coreRequest<WorkspaceDocDetailResponse>( |
| 2202 | "GET", |
| 2203 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/docs/${encodeURIComponent(docId)}`, |
| 2204 | ); |
| 2205 | } |
| 2206 |
| 2207 | async updateWorkspaceDoc( |
| 2208 | workspaceId: string, |
| 2209 | docId: string, |
| 2210 | input: UpdateWorkspaceDocInput, |
| 2211 | ): Promise<WorkspaceDocDetailResponse> { |
| 2212 | return this.coreRequest<WorkspaceDocDetailResponse>( |
| 2213 | "PATCH", |
| 2214 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/docs/${encodeURIComponent(docId)}`, |
| 2215 | input, |
| 2216 | ); |
| 2217 | } |
| 2218 |
| 2219 | async deleteWorkspaceDoc( |
| 2220 | workspaceId: string, |
| 2221 | docId: string, |
| 2222 | ): Promise<{ ok: true }> { |
| 2223 | return this.coreRequest<{ ok: true }>( |
| 2224 | "DELETE", |
| 2225 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/docs/${encodeURIComponent(docId)}`, |
| 2226 | ); |
| 2227 | } |
| 2228 |
| 2229 | // --------------------------------------------------------------------------- |
| 2230 | // Core Platform API — Drives |
| 2231 | // --------------------------------------------------------------------------- |
| 2232 |
| 2233 | async listWorkspaceDrives( |
| 2234 | workspaceId: string, |
| 2235 | ): Promise<WorkspaceDrivesListResponse> { |
| 2236 | return this.coreRequest<WorkspaceDrivesListResponse>( |
| 2237 | "GET", |
| 2238 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/drives`, |
| 2239 | ); |
| 2240 | } |
| 2241 |
| 2242 | // --------------------------------------------------------------------------- |
| 2243 | // Core Platform API — Files |
| 2244 | // --------------------------------------------------------------------------- |
| 2245 |
| 2246 | async listDriveFiles( |
| 2247 | workspaceId: string, |
| 2248 | driveId: string, |
| 2249 | query?: ListDriveFilesQuery, |
| 2250 | ): Promise<DriveFilesListResponse> { |
| 2251 | const params = new URLSearchParams(); |
| 2252 | if (query?.parentId) params.set("parentId", query.parentId); |
| 2253 | if (query?.fileType) params.set("fileType", query.fileType); |
| 2254 | if (query?.trashed !== undefined) params.set("trashed", String(query.trashed)); |
| 2255 | if (query?.limit !== undefined) params.set("limit", String(query.limit)); |
| 2256 | if (query?.cursor) params.set("cursor", query.cursor); |
| 2257 | const qs = params.toString(); |
| 2258 | return this.coreRequest<DriveFilesListResponse>( |
| 2259 | "GET", |
| 2260 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/drives/${encodeURIComponent(driveId)}/files${qs ? `?${qs}` : ""}`, |
| 2261 | ); |
| 2262 | } |
| 2263 |
| 2264 | async getFile( |
| 2265 | workspaceId: string, |
| 2266 | fileId: string, |
| 2267 | ): Promise<FileDetailResponse> { |
| 2268 | return this.coreRequest<FileDetailResponse>( |
| 2269 | "GET", |
| 2270 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/files/${encodeURIComponent(fileId)}`, |
| 2271 | ); |
| 2272 | } |
| 2273 |
| 2274 | async updateFile( |
| 2275 | workspaceId: string, |
| 2276 | fileId: string, |
| 2277 | input: UpdateFileInput, |
| 2278 | ): Promise<FileDetailResponse> { |
| 2279 | return this.coreRequest<FileDetailResponse>( |
| 2280 | "PATCH", |
| 2281 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/files/${encodeURIComponent(fileId)}`, |
| 2282 | input, |
| 2283 | ); |
| 2284 | } |
| 2285 |
| 2286 | async deleteFile( |
| 2287 | workspaceId: string, |
| 2288 | fileId: string, |
| 2289 | ): Promise<{ ok: true }> { |
| 2290 | return this.coreRequest<{ ok: true }>( |
| 2291 | "DELETE", |
| 2292 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/files/${encodeURIComponent(fileId)}`, |
| 2293 | ); |
| 2294 | } |
| 2295 |
| 2296 | // --------------------------------------------------------------------------- |
| 2297 | // Core Platform API — Channels |
| 2298 | // --------------------------------------------------------------------------- |
| 2299 |
| 2300 | async listWorkspaceChannels( |
| 2301 | workspaceId: string, |
| 2302 | ): Promise<ChannelListResponse> { |
| 2303 | return this.coreRequest<ChannelListResponse>( |
| 2304 | "GET", |
| 2305 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/channels`, |
| 2306 | ); |
| 2307 | } |
| 2308 |
| 2309 | async listChannelMessages( |
| 2310 | workspaceId: string, |
| 2311 | channelId: string, |
| 2312 | options?: { limit?: number; cursor?: string }, |
| 2313 | ): Promise<MessagesListResponse> { |
| 2314 | const params = new URLSearchParams(); |
| 2315 | if (options?.limit !== undefined) params.set("limit", String(options.limit)); |
| 2316 | if (options?.cursor) params.set("cursor", options.cursor); |
| 2317 | const qs = params.toString(); |
| 2318 | return this.coreRequest<MessagesListResponse>( |
| 2319 | "GET", |
| 2320 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/channels/${encodeURIComponent(channelId)}/messages${qs ? `?${qs}` : ""}`, |
| 2321 | ); |
| 2322 | } |
| 2323 |
| 2324 | // --------------------------------------------------------------------------- |
| 2325 | // Core Platform API — Direct Messages |
| 2326 | // --------------------------------------------------------------------------- |
| 2327 |
| 2328 | async listWorkspaceDms( |
| 2329 | workspaceId: string, |
| 2330 | ): Promise<DmListResponse> { |
| 2331 | return this.coreRequest<DmListResponse>( |
| 2332 | "GET", |
| 2333 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/dms`, |
| 2334 | ); |
| 2335 | } |
| 2336 |
| 2337 | async listDmMessages( |
| 2338 | workspaceId: string, |
| 2339 | dmId: string, |
| 2340 | options?: { limit?: number; cursor?: string }, |
| 2341 | ): Promise<MessagesListResponse> { |
| 2342 | const params = new URLSearchParams(); |
| 2343 | if (options?.limit !== undefined) params.set("limit", String(options.limit)); |
| 2344 | if (options?.cursor) params.set("cursor", options.cursor); |
| 2345 | const qs = params.toString(); |
| 2346 | return this.coreRequest<MessagesListResponse>( |
| 2347 | "GET", |
| 2348 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/dms/${encodeURIComponent(dmId)}/messages${qs ? `?${qs}` : ""}`, |
| 2349 | ); |
| 2350 | } |
| 2351 |
| 2352 | async sendDmMessage( |
| 2353 | workspaceId: string, |
| 2354 | dmId: string, |
| 2355 | input: SendMessageInput, |
| 2356 | ): Promise<SendMessageResponse> { |
| 2357 | return this.coreRequest<SendMessageResponse>( |
| 2358 | "POST", |
| 2359 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/dms/${encodeURIComponent(dmId)}/messages`, |
| 2360 | input, |
| 2361 | ); |
| 2362 | } |
| 2363 |
| 2364 | async sendChannelMessage( |
| 2365 | workspaceId: string, |
| 2366 | channelId: string, |
| 2367 | input: SendMessageInput, |
| 2368 | ): Promise<SendMessageResponse> { |
| 2369 | return this.coreRequest<SendMessageResponse>( |
| 2370 | "POST", |
| 2371 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/channels/${encodeURIComponent(channelId)}/messages`, |
| 2372 | input, |
| 2373 | ); |
| 2374 | } |
| 2375 |
| 2376 | // --------------------------------------------------------------------------- |
| 2377 | // Core Platform API — Messages (cross-container) |
| 2378 | // --------------------------------------------------------------------------- |
| 2379 |
| 2380 | async getMessage( |
| 2381 | workspaceId: string, |
| 2382 | messageId: string, |
| 2383 | ): Promise<MessageDetailResponse> { |
| 2384 | return this.coreRequest<MessageDetailResponse>( |
| 2385 | "GET", |
| 2386 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/messages/${encodeURIComponent(messageId)}`, |
| 2387 | ); |
| 2388 | } |
| 2389 |
| 2390 | async editMessage( |
| 2391 | workspaceId: string, |
| 2392 | messageId: string, |
| 2393 | input: EditMessageInput, |
| 2394 | ): Promise<MessageDetailResponse> { |
| 2395 | return this.coreRequest<MessageDetailResponse>( |
| 2396 | "PATCH", |
| 2397 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/messages/${encodeURIComponent(messageId)}`, |
| 2398 | input, |
| 2399 | ); |
| 2400 | } |
| 2401 |
| 2402 | async deleteMessage( |
| 2403 | workspaceId: string, |
| 2404 | messageId: string, |
| 2405 | ): Promise<{ ok: true }> { |
| 2406 | return this.coreRequest<{ ok: true }>( |
| 2407 | "DELETE", |
| 2408 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/messages/${encodeURIComponent(messageId)}`, |
| 2409 | ); |
| 2410 | } |
| 2411 |
| 2412 | async getThread( |
| 2413 | workspaceId: string, |
| 2414 | messageId: string, |
| 2415 | ): Promise<ThreadResponse> { |
| 2416 | return this.coreRequest<ThreadResponse>( |
| 2417 | "GET", |
| 2418 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/messages/${encodeURIComponent(messageId)}/thread`, |
| 2419 | ); |
| 2420 | } |
| 2421 |
| 2422 | async replyToThread( |
| 2423 | workspaceId: string, |
| 2424 | messageId: string, |
| 2425 | input: ThreadReplyInput, |
| 2426 | ): Promise<SendMessageResponse> { |
| 2427 | return this.coreRequest<SendMessageResponse>( |
| 2428 | "POST", |
| 2429 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/messages/${encodeURIComponent(messageId)}/thread`, |
| 2430 | input, |
| 2431 | ); |
| 2432 | } |
| 2433 |
| 2434 | async addReaction( |
| 2435 | workspaceId: string, |
| 2436 | messageId: string, |
| 2437 | emoji: string, |
| 2438 | ): Promise<ReactionResponse> { |
| 2439 | return this.coreRequest<ReactionResponse>( |
| 2440 | "PUT", |
| 2441 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/messages/${encodeURIComponent(messageId)}/reactions/${encodeURIComponent(emoji)}`, |
| 2442 | ); |
| 2443 | } |
| 2444 |
| 2445 | async removeReaction( |
| 2446 | workspaceId: string, |
| 2447 | messageId: string, |
| 2448 | emoji: string, |
| 2449 | ): Promise<{ ok: true }> { |
| 2450 | return this.coreRequest<{ ok: true }>( |
| 2451 | "DELETE", |
| 2452 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/messages/${encodeURIComponent(messageId)}/reactions/${encodeURIComponent(emoji)}`, |
| 2453 | ); |
| 2454 | } |
| 2455 |
| 2456 | async pinMessage( |
| 2457 | workspaceId: string, |
| 2458 | messageId: string, |
| 2459 | ): Promise<PinResponse> { |
| 2460 | return this.coreRequest<PinResponse>( |
| 2461 | "PUT", |
| 2462 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/messages/${encodeURIComponent(messageId)}/pin`, |
| 2463 | ); |
| 2464 | } |
| 2465 |
| 2466 | async unpinMessage( |
| 2467 | workspaceId: string, |
| 2468 | messageId: string, |
| 2469 | ): Promise<PinResponse> { |
| 2470 | return this.coreRequest<PinResponse>( |
| 2471 | "DELETE", |
| 2472 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/messages/${encodeURIComponent(messageId)}/pin`, |
| 2473 | ); |
| 2474 | } |
| 2475 |
| 2476 | // --------------------------------------------------------------------------- |
| 2477 | // Core Platform API — Calendar Events |
| 2478 | // --------------------------------------------------------------------------- |
| 2479 |
| 2480 | async listCalendarEvents( |
| 2481 | workspaceId: string, |
| 2482 | range: { start: string; end: string }, |
| 2483 | ): Promise<CalendarEventsListResponse> { |
| 2484 | const params = new URLSearchParams({ |
| 2485 | start: range.start, |
| 2486 | end: range.end, |
| 2487 | }); |
| 2488 | return this.coreRequest<CalendarEventsListResponse>( |
| 2489 | "GET", |
| 2490 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/calendar/events?${params}`, |
| 2491 | ); |
| 2492 | } |
| 2493 |
| 2494 | async createCalendarEvent( |
| 2495 | workspaceId: string, |
| 2496 | input: CreateCalendarEventInput, |
| 2497 | ): Promise<CalendarEventDetailResponse> { |
| 2498 | return this.coreRequest<CalendarEventDetailResponse>( |
| 2499 | "POST", |
| 2500 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/calendar/events`, |
| 2501 | input, |
| 2502 | ); |
| 2503 | } |
| 2504 |
| 2505 | async getCalendarEvent( |
| 2506 | workspaceId: string, |
| 2507 | eventId: string, |
| 2508 | ): Promise<CalendarEventDetailResponse> { |
| 2509 | return this.coreRequest<CalendarEventDetailResponse>( |
| 2510 | "GET", |
| 2511 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/calendar/events/${encodeURIComponent(eventId)}`, |
| 2512 | ); |
| 2513 | } |
| 2514 |
| 2515 | async updateCalendarEvent( |
| 2516 | workspaceId: string, |
| 2517 | eventId: string, |
| 2518 | input: UpdateCalendarEventInput, |
| 2519 | ): Promise<CalendarEventDetailResponse> { |
| 2520 | return this.coreRequest<CalendarEventDetailResponse>( |
| 2521 | "PATCH", |
| 2522 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/calendar/events/${encodeURIComponent(eventId)}`, |
| 2523 | input, |
| 2524 | ); |
| 2525 | } |
| 2526 |
| 2527 | async deleteCalendarEvent( |
| 2528 | workspaceId: string, |
| 2529 | eventId: string, |
| 2530 | ): Promise<{ ok: true }> { |
| 2531 | return this.coreRequest<{ ok: true }>( |
| 2532 | "DELETE", |
| 2533 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/calendar/events/${encodeURIComponent(eventId)}`, |
| 2534 | ); |
| 2535 | } |
| 2536 |
| 2537 | // --------------------------------------------------------------------------- |
| 2538 | // Core Platform API — Search |
| 2539 | // --------------------------------------------------------------------------- |
| 2540 |
| 2541 | async searchWorkspace( |
| 2542 | workspaceId: string, |
| 2543 | input: WorkspaceSearchInput, |
| 2544 | ): Promise<WorkspaceSearchResponse> { |
| 2545 | return this.coreRequest<WorkspaceSearchResponse>( |
| 2546 | "POST", |
| 2547 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/search`, |
| 2548 | input, |
| 2549 | ); |
| 2550 | } |
| 2551 |
| 2552 | // --------------------------------------------------------------------------- |
| 2553 | // Core Platform API — Taskboards |
| 2554 | // --------------------------------------------------------------------------- |
| 2555 |
| 2556 | async listWorkspaceTaskboards( |
| 2557 | workspaceId: string, |
| 2558 | ): Promise<WorkspaceTaskboardsResponse> { |
| 2559 | return this.coreRequest<WorkspaceTaskboardsResponse>( |
| 2560 | "GET", |
| 2561 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/taskboards`, |
| 2562 | ); |
| 2563 | } |
| 2564 |
| 2565 | // --------------------------------------------------------------------------- |
| 2566 | // Core Platform API — Tasks |
| 2567 | // --------------------------------------------------------------------------- |
| 2568 |
| 2569 | async listTaskboardTasks( |
| 2570 | workspaceId: string, |
| 2571 | taskboardId: string, |
| 2572 | query?: ListTaskboardTasksQuery, |
| 2573 | ): Promise<TaskboardTasksResponse> { |
| 2574 | const params = new URLSearchParams(); |
| 2575 | if (query?.q) params.set("q", query.q); |
| 2576 | if (query?.statusId) params.set("statusId", query.statusId); |
| 2577 | if (query?.assigneeUserId) params.set("assigneeUserId", query.assigneeUserId); |
| 2578 | if (query?.limit !== undefined) params.set("limit", String(query.limit)); |
| 2579 | const qs = params.toString(); |
| 2580 | return this.coreRequest<TaskboardTasksResponse>( |
| 2581 | "GET", |
| 2582 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/taskboards/${encodeURIComponent(taskboardId)}/tasks${qs ? `?${qs}` : ""}`, |
| 2583 | ); |
| 2584 | } |
| 2585 |
| 2586 | async createTaskboardTask( |
| 2587 | workspaceId: string, |
| 2588 | taskboardId: string, |
| 2589 | input: CreateTaskInput, |
| 2590 | ): Promise<CreateTaskResponse> { |
| 2591 | return this.coreRequest<CreateTaskResponse>( |
| 2592 | "POST", |
| 2593 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/taskboards/${encodeURIComponent(taskboardId)}/tasks`, |
| 2594 | input, |
| 2595 | ); |
| 2596 | } |
| 2597 |
| 2598 | async updateTaskboardTask( |
| 2599 | workspaceId: string, |
| 2600 | taskboardId: string, |
| 2601 | taskId: string, |
| 2602 | input: UpdateTaskInput, |
| 2603 | ): Promise<{ ok: true }> { |
| 2604 | return this.coreRequest<{ ok: true }>( |
| 2605 | "PATCH", |
| 2606 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/taskboards/${encodeURIComponent(taskboardId)}/tasks/${encodeURIComponent(taskId)}`, |
| 2607 | input, |
| 2608 | ); |
| 2609 | } |
| 2610 |
| 2611 | async deleteTaskboardTask( |
| 2612 | workspaceId: string, |
| 2613 | taskboardId: string, |
| 2614 | taskId: string, |
| 2615 | ): Promise<{ ok: true }> { |
| 2616 | return this.coreRequest<{ ok: true }>( |
| 2617 | "DELETE", |
| 2618 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/taskboards/${encodeURIComponent(taskboardId)}/tasks/${encodeURIComponent(taskId)}`, |
| 2619 | ); |
| 2620 | } |
| 2621 |
| 2622 | // --------------------------------------------------------------------------- |
| 2623 | // File Uploads |
| 2624 | // --------------------------------------------------------------------------- |
| 2625 |
| 2626 | /** |
| 2627 | * Start a multipart upload. Returns an `uploadId` and the expected `partCount`. |
| 2628 | */ |
| 2629 | async initiateUpload( |
| 2630 | workspaceId: string, |
| 2631 | input: InitiateUploadInput, |
| 2632 | ): Promise<InitiateUploadResponse> { |
| 2633 | return this.coreRequest<InitiateUploadResponse>( |
| 2634 | "POST", |
| 2635 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/uploads/initiate`, |
| 2636 | { |
| 2637 | fileName: input.fileName, |
| 2638 | mimeType: input.mimeType, |
| 2639 | sizeBytes: input.sizeBytes, |
| 2640 | driveId: input.driveId, |
| 2641 | ...(input.parentId !== undefined ? { parentId: input.parentId } : {}), |
| 2642 | }, |
| 2643 | ); |
| 2644 | } |
| 2645 |
| 2646 | /** |
| 2647 | * Upload a single part of a multipart upload. |
| 2648 | */ |
| 2649 | async uploadPart( |
| 2650 | workspaceId: string, |
| 2651 | uploadId: string, |
| 2652 | partNumber: number, |
| 2653 | data: Uint8Array | ArrayBuffer | Blob, |
| 2654 | ): Promise<UploadPartResponse> { |
| 2655 | const qs = new URLSearchParams({ |
| 2656 | uploadId, |
| 2657 | partNumber: String(partNumber), |
| 2658 | }); |
| 2659 | let body: Blob; |
| 2660 | if (data instanceof Blob) { |
| 2661 | body = data; |
| 2662 | } else if (data instanceof ArrayBuffer) { |
| 2663 | body = new Blob([data]); |
| 2664 | } else { |
| 2665 | // Uint8Array — extract the underlying ArrayBuffer slice |
| 2666 | body = new Blob([(data.buffer as ArrayBuffer).slice(data.byteOffset, data.byteOffset + data.byteLength)]); |
| 2667 | } |
| 2668 | return this.coreRawRequest<UploadPartResponse>( |
| 2669 | "POST", |
| 2670 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/uploads/part?${qs}`, |
| 2671 | body, |
| 2672 | "application/octet-stream", |
| 2673 | ); |
| 2674 | } |
| 2675 |
| 2676 | /** |
| 2677 | * Finalize a multipart upload and create the file in the workspace drive. |
| 2678 | */ |
| 2679 | async completeUpload( |
| 2680 | workspaceId: string, |
| 2681 | uploadId: string, |
| 2682 | parts: CompletedUploadPart[], |
| 2683 | ): Promise<CompleteUploadResponse> { |
| 2684 | return this.coreRequest<CompleteUploadResponse>( |
| 2685 | "POST", |
| 2686 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/uploads/complete`, |
| 2687 | { uploadId, parts }, |
| 2688 | ); |
| 2689 | } |
| 2690 |
| 2691 | /** |
| 2692 | * Upload a file in one call. Handles chunking, multipart upload, and |
| 2693 | * finalization automatically. |
| 2694 | * |
| 2695 | * @example |
| 2696 | * ```ts |
| 2697 | * const file = await client.uploadFile("ws_123", { |
| 2698 | * data: myBlob, |
| 2699 | * fileName: "report.pdf", |
| 2700 | * mimeType: "application/pdf", |
| 2701 | * driveId: "drive_abc", |
| 2702 | * }); |
| 2703 | * console.log(file.file.id); |
| 2704 | * ``` |
| 2705 | */ |
| 2706 | async uploadFile( |
| 2707 | workspaceId: string, |
| 2708 | input: UploadFileInput, |
| 2709 | ): Promise<CompleteUploadResponse> { |
| 2710 | const bytes = |
| 2711 | input.data instanceof Blob |
| 2712 | ? new Uint8Array(await input.data.arrayBuffer()) |
| 2713 | : input.data instanceof ArrayBuffer |
| 2714 | ? new Uint8Array(input.data) |
| 2715 | : input.data; |
| 2716 |
| 2717 | const initInput: InitiateUploadInput = { |
| 2718 | fileName: input.fileName, |
| 2719 | mimeType: input.mimeType, |
| 2720 | sizeBytes: bytes.byteLength, |
| 2721 | driveId: input.driveId, |
| 2722 | }; |
| 2723 | if (input.parentId !== undefined) { |
| 2724 | initInput.parentId = input.parentId; |
| 2725 | } |
| 2726 | const { uploadId, partCount } = await this.initiateUpload(workspaceId, initInput); |
| 2727 |
| 2728 | const partSize = Math.ceil(bytes.byteLength / partCount); |
| 2729 | const completedParts: CompletedUploadPart[] = []; |
| 2730 |
| 2731 | for (let i = 0; i < partCount; i++) { |
| 2732 | const start = i * partSize; |
| 2733 | const end = Math.min(start + partSize, bytes.byteLength); |
| 2734 | const chunk = bytes.slice(start, end); |
| 2735 | const part = await this.uploadPart(workspaceId, uploadId, i + 1, chunk); |
| 2736 | completedParts.push({ partNumber: part.partNumber, etag: part.etag }); |
| 2737 | } |
| 2738 |
| 2739 | return this.completeUpload(workspaceId, uploadId, completedParts); |
| 2740 | } |
| 2741 |
| 2742 | // --------------------------------------------------------------------------- |
| 2743 | // Batch Task Operations |
| 2744 | // --------------------------------------------------------------------------- |
| 2745 |
| 2746 | /** |
| 2747 | * Create multiple tasks concurrently. Returns results in the same order as |
| 2748 | * the input array, with each entry indicating success or failure. |
| 2749 | * |
| 2750 | * @example |
| 2751 | * ```ts |
| 2752 | * const results = await client.batchCreateTasks("ws_123", "board_456", [ |
| 2753 | * { title: "Task A" }, |
| 2754 | * { title: "Task B", priority: "high" }, |
| 2755 | * ]); |
| 2756 | * ``` |
| 2757 | */ |
| 2758 | async batchCreateTasks( |
| 2759 | workspaceId: string, |
| 2760 | taskboardId: string, |
| 2761 | tasks: CreateTaskInput[], |
| 2762 | ): Promise<BatchResultEntry<CreateTaskResponse>[]> { |
| 2763 | const settled = await Promise.allSettled( |
| 2764 | tasks.map((task) => |
| 2765 | this.createTaskboardTask(workspaceId, taskboardId, task), |
| 2766 | ), |
| 2767 | ); |
| 2768 | return settled.map((r) => |
| 2769 | r.status === "fulfilled" |
| 2770 | ? { status: "fulfilled" as const, value: r.value } |
| 2771 | : { status: "rejected" as const, reason: String(r.reason) }, |
| 2772 | ); |
| 2773 | } |
| 2774 |
| 2775 | /** |
| 2776 | * Update multiple tasks concurrently. |
| 2777 | */ |
| 2778 | async batchUpdateTasks( |
| 2779 | workspaceId: string, |
| 2780 | taskboardId: string, |
| 2781 | updates: BatchUpdateTaskEntry[], |
| 2782 | ): Promise<BatchResultEntry<{ ok: true }>[]> { |
| 2783 | const settled = await Promise.allSettled( |
| 2784 | updates.map(({ taskId, ...input }) => |
| 2785 | this.updateTaskboardTask(workspaceId, taskboardId, taskId, input), |
| 2786 | ), |
| 2787 | ); |
| 2788 | return settled.map((r) => |
| 2789 | r.status === "fulfilled" |
| 2790 | ? { status: "fulfilled" as const, value: r.value } |
| 2791 | : { status: "rejected" as const, reason: String(r.reason) }, |
| 2792 | ); |
| 2793 | } |
| 2794 |
| 2795 | /** |
| 2796 | * Delete multiple tasks concurrently. |
| 2797 | */ |
| 2798 | async batchDeleteTasks( |
| 2799 | workspaceId: string, |
| 2800 | taskboardId: string, |
| 2801 | taskIds: string[], |
| 2802 | ): Promise<BatchResultEntry<{ ok: true }>[]> { |
| 2803 | const settled = await Promise.allSettled( |
| 2804 | taskIds.map((taskId) => |
| 2805 | this.deleteTaskboardTask(workspaceId, taskboardId, taskId), |
| 2806 | ), |
| 2807 | ); |
| 2808 | return settled.map((r) => |
| 2809 | r.status === "fulfilled" |
| 2810 | ? { status: "fulfilled" as const, value: r.value } |
| 2811 | : { status: "rejected" as const, reason: String(r.reason) }, |
| 2812 | ); |
| 2813 | } |
| 2814 |
| 2815 | // --------------------------------------------------------------------------- |
| 2816 | // Workspace-scoped client |
| 2817 | // --------------------------------------------------------------------------- |
| 2818 |
| 2819 | /** |
| 2820 | * Returns a publisher-scoped handle for a specific app key. |
| 2821 | * |
| 2822 | * @example |
| 2823 | * ```ts |
| 2824 | * const app = coline.app("com.example.notes"); |
| 2825 | * const versions = await app.listVersions(); |
| 2826 | * await app.submitVersionForReview("ver_123", { storeListed: true }); |
| 2827 | * ``` |
| 2828 | */ |
| 2829 | app(appKey: string): PublishedAppHandle { |
| 2830 | return new PublishedAppHandle(this, appKey); |
| 2831 | } |
| 2832 |
| 2833 | /** |
| 2834 | * Returns a workspace-scoped client that drops the `workspaceId` first |
| 2835 | * argument from every workspace method. |
| 2836 | * |
| 2837 | * @example |
| 2838 | * ```ts |
| 2839 | * const ws = coline.workspace("ws_abc123"); |
| 2840 | * const notes = await ws.listNotes({ limit: 10 }); |
| 2841 | * const thread = await ws.getThread(messageId); |
| 2842 | * for await (const note of ws.paginateNotes()) { |
| 2843 | * console.log(note.title); |
| 2844 | * } |
| 2845 | * ``` |
| 2846 | */ |
| 2847 | workspace(workspaceId: string): ColineWorkspace { |
| 2848 | return new ColineWorkspace(this, workspaceId); |
| 2849 | } |
| 2850 | } |
| 2851 |
| 2852 | // --------------------------------------------------------------------------- |
| 2853 | // Workspace-scoped client — removes workspaceId boilerplate |
| 2854 | // --------------------------------------------------------------------------- |
| 2855 |
| 2856 | /** |
| 2857 | * A convenience wrapper around `ColineApiClient` that binds a workspace ID |
| 2858 | * so you don't have to pass it to every call. |
| 2859 | * |
| 2860 | * Get one via `client.workspace("ws_abc123")`. |
| 2861 | */ |
| 2862 | export class ColineWorkspace { |
| 2863 | constructor( |
| 2864 | private readonly client: ColineApiClient, |
| 2865 | readonly workspaceId: string, |
| 2866 | ) {} |
| 2867 |
| 2868 | // -- Installed Apps & App Runtime ----------------------------------------- |
| 2869 |
| 2870 | listApps() { |
| 2871 | return this.client.listWorkspaceApps(this.workspaceId); |
| 2872 | } |
| 2873 |
| 2874 | installApp(input: InstallWorkspaceAppInput) { |
| 2875 | return this.client.installWorkspaceApp(this.workspaceId, input); |
| 2876 | } |
| 2877 |
| 2878 | // -- Members --------------------------------------------------------------- |
| 2879 |
| 2880 | listMembers() { |
| 2881 | return this.client.listWorkspaceMembers(this.workspaceId); |
| 2882 | } |
| 2883 |
| 2884 | // -- Notes ----------------------------------------------------------------- |
| 2885 |
| 2886 | listNotes(query?: ListWorkspaceNotesQuery) { |
| 2887 | return this.client.listWorkspaceNotes(this.workspaceId, query); |
| 2888 | } |
| 2889 |
| 2890 | createNote(input: CreateWorkspaceNoteInput) { |
| 2891 | return this.client.createWorkspaceNote(this.workspaceId, input); |
| 2892 | } |
| 2893 |
| 2894 | getNote(noteId: string) { |
| 2895 | return this.client.getWorkspaceNote(this.workspaceId, noteId); |
| 2896 | } |
| 2897 |
| 2898 | updateNote(noteId: string, input: UpdateWorkspaceNoteInput) { |
| 2899 | return this.client.updateWorkspaceNote(this.workspaceId, noteId, input); |
| 2900 | } |
| 2901 |
| 2902 | deleteNote(noteId: string) { |
| 2903 | return this.client.deleteWorkspaceNote(this.workspaceId, noteId); |
| 2904 | } |
| 2905 |
| 2906 | /** Async generator that auto-paginates through all notes. */ |
| 2907 | paginateNotes(query?: Omit<ListWorkspaceNotesQuery, "cursor">) { |
| 2908 | return paginate<WorkspaceNoteSummary>(async (cursor) => { |
| 2909 | const res = await this.listNotes({ ...query, ...(cursor !== undefined ? { cursor } : {}) }); |
| 2910 | return { |
| 2911 | items: res.notes, |
| 2912 | nextCursor: res.page.nextCursor, |
| 2913 | hasMore: res.page.hasMore, |
| 2914 | }; |
| 2915 | }); |
| 2916 | } |
| 2917 |
| 2918 | // -- Docs ------------------------------------------------------------------ |
| 2919 |
| 2920 | listDocs(query?: ListWorkspaceDocsQuery) { |
| 2921 | return this.client.listWorkspaceDocs(this.workspaceId, query); |
| 2922 | } |
| 2923 |
| 2924 | createDoc(input: CreateWorkspaceDocInput) { |
| 2925 | return this.client.createWorkspaceDoc(this.workspaceId, input); |
| 2926 | } |
| 2927 |
| 2928 | getDoc(docId: string) { |
| 2929 | return this.client.getWorkspaceDoc(this.workspaceId, docId); |
| 2930 | } |
| 2931 |
| 2932 | updateDoc(docId: string, input: UpdateWorkspaceDocInput) { |
| 2933 | return this.client.updateWorkspaceDoc(this.workspaceId, docId, input); |
| 2934 | } |
| 2935 |
| 2936 | deleteDoc(docId: string) { |
| 2937 | return this.client.deleteWorkspaceDoc(this.workspaceId, docId); |
| 2938 | } |
| 2939 |
| 2940 | /** Async generator that auto-paginates through all docs. */ |
| 2941 | paginateDocs(query?: Omit<ListWorkspaceDocsQuery, "cursor">) { |
| 2942 | return paginate<WorkspaceDocSummary>(async (cursor) => { |
| 2943 | const res = await this.listDocs({ ...query, ...(cursor !== undefined ? { cursor } : {}) }); |
| 2944 | return { |
| 2945 | items: res.docs, |
| 2946 | nextCursor: res.page.nextCursor, |
| 2947 | hasMore: res.page.hasMore, |
| 2948 | }; |
| 2949 | }); |
| 2950 | } |
| 2951 |
| 2952 | // -- Drives & Files -------------------------------------------------------- |
| 2953 |
| 2954 | listDrives() { |
| 2955 | return this.client.listWorkspaceDrives(this.workspaceId); |
| 2956 | } |
| 2957 |
| 2958 | listDriveFiles(driveId: string, query?: ListDriveFilesQuery) { |
| 2959 | return this.client.listDriveFiles(this.workspaceId, driveId, query); |
| 2960 | } |
| 2961 |
| 2962 | getFile(fileId: string) { |
| 2963 | return this.client.getFile(this.workspaceId, fileId); |
| 2964 | } |
| 2965 |
| 2966 | updateFile(fileId: string, input: UpdateFileInput) { |
| 2967 | return this.client.updateFile(this.workspaceId, fileId, input); |
| 2968 | } |
| 2969 |
| 2970 | deleteFile(fileId: string) { |
| 2971 | return this.client.deleteFile(this.workspaceId, fileId); |
| 2972 | } |
| 2973 |
| 2974 | // -- Channels -------------------------------------------------------------- |
| 2975 |
| 2976 | listChannels() { |
| 2977 | return this.client.listWorkspaceChannels(this.workspaceId); |
| 2978 | } |
| 2979 |
| 2980 | listChannelMessages(channelId: string, query?: { cursor?: string; limit?: number }) { |
| 2981 | return this.client.listChannelMessages(this.workspaceId, channelId, query); |
| 2982 | } |
| 2983 |
| 2984 | sendChannelMessage(channelId: string, input: SendMessageInput) { |
| 2985 | return this.client.sendChannelMessage(this.workspaceId, channelId, input); |
| 2986 | } |
| 2987 |
| 2988 | // -- Direct Messages ------------------------------------------------------- |
| 2989 |
| 2990 | listDms() { |
| 2991 | return this.client.listWorkspaceDms(this.workspaceId); |
| 2992 | } |
| 2993 |
| 2994 | listDmMessages(dmId: string, query?: { cursor?: string; limit?: number }) { |
| 2995 | return this.client.listDmMessages(this.workspaceId, dmId, query); |
| 2996 | } |
| 2997 |
| 2998 | sendDmMessage(dmId: string, input: SendMessageInput) { |
| 2999 | return this.client.sendDmMessage(this.workspaceId, dmId, input); |
| 3000 | } |
| 3001 |
| 3002 | // -- Messages -------------------------------------------------------------- |
| 3003 |
| 3004 | getMessage(messageId: string) { |
| 3005 | return this.client.getMessage(this.workspaceId, messageId); |
| 3006 | } |
| 3007 |
| 3008 | editMessage(messageId: string, input: EditMessageInput) { |
| 3009 | return this.client.editMessage(this.workspaceId, messageId, input); |
| 3010 | } |
| 3011 |
| 3012 | deleteMessage(messageId: string) { |
| 3013 | return this.client.deleteMessage(this.workspaceId, messageId); |
| 3014 | } |
| 3015 |
| 3016 | getThread(messageId: string) { |
| 3017 | return this.client.getThread(this.workspaceId, messageId); |
| 3018 | } |
| 3019 |
| 3020 | replyToThread(messageId: string, input: ThreadReplyInput) { |
| 3021 | return this.client.replyToThread(this.workspaceId, messageId, input); |
| 3022 | } |
| 3023 |
| 3024 | addReaction(messageId: string, emoji: string) { |
| 3025 | return this.client.addReaction(this.workspaceId, messageId, emoji); |
| 3026 | } |
| 3027 |
| 3028 | removeReaction(messageId: string, emoji: string) { |
| 3029 | return this.client.removeReaction(this.workspaceId, messageId, emoji); |
| 3030 | } |
| 3031 |
| 3032 | pinMessage(messageId: string) { |
| 3033 | return this.client.pinMessage(this.workspaceId, messageId); |
| 3034 | } |
| 3035 |
| 3036 | unpinMessage(messageId: string) { |
| 3037 | return this.client.unpinMessage(this.workspaceId, messageId); |
| 3038 | } |
| 3039 |
| 3040 | // -- Calendar Events ------------------------------------------------------- |
| 3041 |
| 3042 | listCalendarEvents(range: { start: string; end: string }) { |
| 3043 | return this.client.listCalendarEvents(this.workspaceId, range); |
| 3044 | } |
| 3045 |
| 3046 | createCalendarEvent(input: CreateCalendarEventInput) { |
| 3047 | return this.client.createCalendarEvent(this.workspaceId, input); |
| 3048 | } |
| 3049 |
| 3050 | getCalendarEvent(eventId: string) { |
| 3051 | return this.client.getCalendarEvent(this.workspaceId, eventId); |
| 3052 | } |
| 3053 |
| 3054 | updateCalendarEvent(eventId: string, input: UpdateCalendarEventInput) { |
| 3055 | return this.client.updateCalendarEvent(this.workspaceId, eventId, input); |
| 3056 | } |
| 3057 |
| 3058 | deleteCalendarEvent(eventId: string) { |
| 3059 | return this.client.deleteCalendarEvent(this.workspaceId, eventId); |
| 3060 | } |
| 3061 |
| 3062 | // -- Search ---------------------------------------------------------------- |
| 3063 |
| 3064 | search(input: WorkspaceSearchInput) { |
| 3065 | return this.client.searchWorkspace(this.workspaceId, input); |
| 3066 | } |
| 3067 |
| 3068 | // -- Taskboards & Tasks ---------------------------------------------------- |
| 3069 |
| 3070 | listTaskboards() { |
| 3071 | return this.client.listWorkspaceTaskboards(this.workspaceId); |
| 3072 | } |
| 3073 |
| 3074 | listTasks(taskboardId: string, query?: ListTaskboardTasksQuery) { |
| 3075 | return this.client.listTaskboardTasks(this.workspaceId, taskboardId, query); |
| 3076 | } |
| 3077 |
| 3078 | createTask(taskboardId: string, input: CreateTaskInput) { |
| 3079 | return this.client.createTaskboardTask(this.workspaceId, taskboardId, input); |
| 3080 | } |
| 3081 |
| 3082 | updateTask(taskboardId: string, taskId: string, input: UpdateTaskInput) { |
| 3083 | return this.client.updateTaskboardTask(this.workspaceId, taskboardId, taskId, input); |
| 3084 | } |
| 3085 |
| 3086 | deleteTask(taskboardId: string, taskId: string) { |
| 3087 | return this.client.deleteTaskboardTask(this.workspaceId, taskboardId, taskId); |
| 3088 | } |
| 3089 |
| 3090 | batchCreateTasks(taskboardId: string, tasks: CreateTaskInput[]) { |
| 3091 | return this.client.batchCreateTasks(this.workspaceId, taskboardId, tasks); |
| 3092 | } |
| 3093 |
| 3094 | batchUpdateTasks(taskboardId: string, updates: BatchUpdateTaskEntry[]) { |
| 3095 | return this.client.batchUpdateTasks(this.workspaceId, taskboardId, updates); |
| 3096 | } |
| 3097 |
| 3098 | batchDeleteTasks(taskboardId: string, taskIds: string[]) { |
| 3099 | return this.client.batchDeleteTasks(this.workspaceId, taskboardId, taskIds); |
| 3100 | } |
| 3101 |
| 3102 | // -- File Uploads ---------------------------------------------------------- |
| 3103 |
| 3104 | initiateUpload(input: InitiateUploadInput) { |
| 3105 | return this.client.initiateUpload(this.workspaceId, input); |
| 3106 | } |
| 3107 |
| 3108 | uploadPart(uploadId: string, partNumber: number, data: Uint8Array | ArrayBuffer | Blob) { |
| 3109 | return this.client.uploadPart(this.workspaceId, uploadId, partNumber, data); |
| 3110 | } |
| 3111 |
| 3112 | completeUpload(uploadId: string, parts: CompletedUploadPart[]) { |
| 3113 | return this.client.completeUpload(this.workspaceId, uploadId, parts); |
| 3114 | } |
| 3115 |
| 3116 | /** |
| 3117 | * Upload a file in one call. Handles chunking automatically. |
| 3118 | * |
| 3119 | * @example |
| 3120 | * ```ts |
| 3121 | * const ws = client.workspace("ws_123"); |
| 3122 | * const result = await ws.uploadFile({ |
| 3123 | * data: myBlob, |
| 3124 | * fileName: "photo.jpg", |
| 3125 | * mimeType: "image/jpeg", |
| 3126 | * driveId: "drive_abc", |
| 3127 | * }); |
| 3128 | * console.log(result.file.id); |
| 3129 | * ``` |
| 3130 | */ |
| 3131 | uploadFile(input: UploadFileInput) { |
| 3132 | return this.client.uploadFile(this.workspaceId, input); |
| 3133 | } |
| 3134 |
| 3135 | // -- Tab AI ---------------------------------------------------------------- |
| 3136 |
| 3137 | /** Stream Tab completions and yield SSE chunks. */ |
| 3138 | streamTabChatCompletion(input: TabChatCompletionInput) { |
| 3139 | return this.client.streamTabChatCompletion(input); |
| 3140 | } |
| 3141 |
| 3142 | /** Stream Tab completions and yield only the text strings. */ |
| 3143 | streamTabText(input: TabChatCompletionInput) { |
| 3144 | return this.client.streamTabText(input); |
| 3145 | } |
| 3146 |
| 3147 | // --------------------------------------------------------------------------- |
| 3148 | // Resource handles — chainable accessors for individual resources |
| 3149 | // --------------------------------------------------------------------------- |
| 3150 |
| 3151 | /** |
| 3152 | * Get a handle to a specific note. |
| 3153 | * @example |
| 3154 | * ```ts |
| 3155 | * const body = await ws.note("note_123").get(); |
| 3156 | * await ws.note("note_123").update({ title: "New title" }); |
| 3157 | * await ws.note("note_123").delete(); |
| 3158 | * ``` |
| 3159 | */ |
| 3160 | note(noteId: string): NoteHandle { |
| 3161 | return new NoteHandle(this, noteId); |
| 3162 | } |
| 3163 |
| 3164 | /** |
| 3165 | * Get a handle to a specific doc. |
| 3166 | * @example |
| 3167 | * ```ts |
| 3168 | * const doc = await ws.doc("doc_456").get(); |
| 3169 | * await ws.doc("doc_456").update({ title: "Updated" }); |
| 3170 | * ``` |
| 3171 | */ |
| 3172 | doc(docId: string): DocHandle { |
| 3173 | return new DocHandle(this, docId); |
| 3174 | } |
| 3175 |
| 3176 | /** |
| 3177 | * Get a handle to a specific file. |
| 3178 | * @example |
| 3179 | * ```ts |
| 3180 | * const file = await ws.file("file_789").get(); |
| 3181 | * await ws.file("file_789").update({ name: "renamed.pdf" }); |
| 3182 | * await ws.file("file_789").delete(); |
| 3183 | * ``` |
| 3184 | */ |
| 3185 | file(fileId: string): FileHandle { |
| 3186 | return new FileHandle(this, fileId); |
| 3187 | } |
| 3188 |
| 3189 | /** |
| 3190 | * Get a handle to a specific message. |
| 3191 | * @example |
| 3192 | * ```ts |
| 3193 | * const msg = await ws.message("msg_123").get(); |
| 3194 | * await ws.message("msg_123").edit({ content: Message.text("updated").build() }); |
| 3195 | * await ws.message("msg_123").react("👍"); |
| 3196 | * await ws.message("msg_123").pin(); |
| 3197 | * const thread = await ws.message("msg_123").thread(); |
| 3198 | * await ws.message("msg_123").reply(Message.text("reply!").toInput()); |
| 3199 | * ``` |
| 3200 | */ |
| 3201 | message(messageId: string): MessageHandle { |
| 3202 | return new MessageHandle(this, messageId); |
| 3203 | } |
| 3204 |
| 3205 | /** |
| 3206 | * Get a handle to a specific channel. |
| 3207 | * @example |
| 3208 | * ```ts |
| 3209 | * const messages = await ws.channel("ch_123").messages(); |
| 3210 | * await ws.channel("ch_123").send(Message.text("hello!").toInput()); |
| 3211 | * ``` |
| 3212 | */ |
| 3213 | channel(channelId: string): ChannelHandle { |
| 3214 | return new ChannelHandle(this, channelId); |
| 3215 | } |
| 3216 |
| 3217 | /** |
| 3218 | * Get a handle to a specific DM. |
| 3219 | * @example |
| 3220 | * ```ts |
| 3221 | * await ws.dm("dm_456").send(Message.text("hey!").toInput()); |
| 3222 | * ``` |
| 3223 | */ |
| 3224 | dm(dmId: string): DmHandle { |
| 3225 | return new DmHandle(this, dmId); |
| 3226 | } |
| 3227 |
| 3228 | /** |
| 3229 | * Get a handle to a specific calendar event. |
| 3230 | * @example |
| 3231 | * ```ts |
| 3232 | * const event = await ws.event("evt_789").get(); |
| 3233 | * await ws.event("evt_789").update({ title: "Moved" }); |
| 3234 | * await ws.event("evt_789").delete(); |
| 3235 | * ``` |
| 3236 | */ |
| 3237 | event(eventId: string): CalendarEventHandle { |
| 3238 | return new CalendarEventHandle(this, eventId); |
| 3239 | } |
| 3240 |
| 3241 | /** |
| 3242 | * Get a handle to a specific taskboard. |
| 3243 | * @example |
| 3244 | * ```ts |
| 3245 | * const tasks = await ws.taskboard("tb_123").listTasks(); |
| 3246 | * await ws.taskboard("tb_123").createTask({ title: "New task" }); |
| 3247 | * await ws.taskboard("tb_123").task("task_456").update({ priority: "high" }); |
| 3248 | * ``` |
| 3249 | */ |
| 3250 | taskboard(taskboardId: string): TaskboardHandle { |
| 3251 | return new TaskboardHandle(this, taskboardId); |
| 3252 | } |
| 3253 |
| 3254 | /** |
| 3255 | * Get a handle to a workspace-installed app and its runtime surfaces. |
| 3256 | * |
| 3257 | * @example |
| 3258 | * ```ts |
| 3259 | * await ws.installApp({ appId: "app_123" }); |
| 3260 | * const crm = ws.app("acme-crm"); |
| 3261 | * const files = await crm.listFiles({ limit: 20 }); |
| 3262 | * await crm.file("file_123").updateDocument({ status: "active" }); |
| 3263 | * ``` |
| 3264 | */ |
| 3265 | app(appKey: string): WorkspaceAppHandle { |
| 3266 | return new WorkspaceAppHandle(this.client, this.workspaceId, appKey); |
| 3267 | } |
| 3268 | } |
| 3269 |
| 3270 | // --------------------------------------------------------------------------- |
| 3271 | // Resource handles |
| 3272 | // --------------------------------------------------------------------------- |
| 3273 |
| 3274 | export class PublishedAppHandle { |
| 3275 | constructor( |
| 3276 | private readonly client: ColineApiClient, |
| 3277 | readonly key: string, |
| 3278 | ) {} |
| 3279 |
| 3280 | get() { return this.client.getApp(this.key); } |
| 3281 | listVersions() { return this.client.listAppVersions(this.key); } |
| 3282 | createVersion(payload: ColineAppRegistrationPayloadInput) { |
| 3283 | return this.client.createAppVersion(this.key, payload); |
| 3284 | } |
| 3285 | submitVersionForReview( |
| 3286 | versionId: string, |
| 3287 | input: SubmitAppVersionForReviewInput = {}, |
| 3288 | ) { |
| 3289 | return this.client.submitAppVersionForReview(this.key, versionId, input); |
| 3290 | } |
| 3291 | } |
| 3292 |
| 3293 | export class WorkspaceAppHandle { |
| 3294 | constructor( |
| 3295 | private readonly client: ColineApiClient, |
| 3296 | readonly workspaceId: string, |
| 3297 | readonly key: string, |
| 3298 | ) {} |
| 3299 |
| 3300 | get() { |
| 3301 | return this.client.getWorkspaceInstalledApp(this.workspaceId, this.key); |
| 3302 | } |
| 3303 |
| 3304 | getPermissions() { |
| 3305 | return this.client.getWorkspaceAppPermissions(this.workspaceId, this.key); |
| 3306 | } |
| 3307 |
| 3308 | updatePermissions(input: UpdateWorkspaceAppPermissionsInput) { |
| 3309 | return this.client.updateWorkspaceAppPermissions(this.workspaceId, this.key, input); |
| 3310 | } |
| 3311 |
| 3312 | uninstall() { |
| 3313 | return this.client.uninstallWorkspaceApp(this.workspaceId, this.key); |
| 3314 | } |
| 3315 |
| 3316 | listSecrets() { |
| 3317 | return this.client.listWorkspaceAppSecrets(this.workspaceId, this.key); |
| 3318 | } |
| 3319 |
| 3320 | createSecret(input: CreateWorkspaceAppSecretInput) { |
| 3321 | return this.client.createWorkspaceAppSecret(this.workspaceId, this.key, input); |
| 3322 | } |
| 3323 |
| 3324 | deleteSecret(secretId: string) { |
| 3325 | return this.client.deleteWorkspaceAppSecret(this.workspaceId, this.key, secretId); |
| 3326 | } |
| 3327 |
| 3328 | listOauthConnections() { |
| 3329 | return this.client.listWorkspaceAppOauthConnections(this.workspaceId, this.key); |
| 3330 | } |
| 3331 |
| 3332 | createOauthConnection(input: CreateWorkspaceAppOauthConnectionInput) { |
| 3333 | return this.client.createWorkspaceAppOauthConnection(this.workspaceId, this.key, input); |
| 3334 | } |
| 3335 |
| 3336 | deleteOauthConnection(connectionId: string) { |
| 3337 | return this.client.deleteWorkspaceAppOauthConnection( |
| 3338 | this.workspaceId, |
| 3339 | this.key, |
| 3340 | connectionId, |
| 3341 | ); |
| 3342 | } |
| 3343 |
| 3344 | listDeliveries() { |
| 3345 | return this.client.listWorkspaceAppDeliveries(this.workspaceId, this.key); |
| 3346 | } |
| 3347 |
| 3348 | sendTestDelivery(input: SendWorkspaceAppTestDeliveryInput) { |
| 3349 | return this.client.sendWorkspaceAppTestDelivery(this.workspaceId, this.key, input); |
| 3350 | } |
| 3351 |
| 3352 | replayDelivery(deliveryId: string) { |
| 3353 | return this.client.replayWorkspaceAppDelivery(this.workspaceId, this.key, deliveryId); |
| 3354 | } |
| 3355 |
| 3356 | emitAmbientEvents(input: EmitAmbientEventsInputInput) { |
| 3357 | return this.client.emitAppAmbientEvents(this.workspaceId, this.key, input); |
| 3358 | } |
| 3359 |
| 3360 | createNotification(input: CreateNotificationInputInput) { |
| 3361 | return this.client.createAppNotification(this.workspaceId, this.key, input); |
| 3362 | } |
| 3363 |
| 3364 | upsertIndexDocuments(input: BatchUpsertAppIndexDocumentsInput) { |
| 3365 | return this.client.upsertAppIndexDocuments(this.workspaceId, this.key, input); |
| 3366 | } |
| 3367 |
| 3368 | deleteIndexDocuments(input: BatchDeleteAppIndexDocumentsInput) { |
| 3369 | return this.client.deleteAppIndexDocuments(this.workspaceId, this.key, input); |
| 3370 | } |
| 3371 |
| 3372 | listFiles(query?: ListAppFilesQuery) { |
| 3373 | return this.client.listAppFiles(this.workspaceId, this.key, query); |
| 3374 | } |
| 3375 |
| 3376 | createFile(input: CreateAppFileInput) { |
| 3377 | return this.client.createAppFile(this.workspaceId, this.key, input); |
| 3378 | } |
| 3379 |
| 3380 | executeAction(input: ExecuteAppActionInput) { |
| 3381 | return this.client.executeAppAction(this.workspaceId, this.key, input); |
| 3382 | } |
| 3383 |
| 3384 | file(fileId: string): WorkspaceAppFileHandle { |
| 3385 | return new WorkspaceAppFileHandle(this.client, this.workspaceId, this.key, fileId); |
| 3386 | } |
| 3387 | } |
| 3388 |
| 3389 | export class WorkspaceAppFileHandle { |
| 3390 | constructor( |
| 3391 | private readonly client: ColineApiClient, |
| 3392 | readonly workspaceId: string, |
| 3393 | readonly appKey: string, |
| 3394 | readonly id: string, |
| 3395 | ) {} |
| 3396 |
| 3397 | get() { |
| 3398 | return this.client.getAppFileDocument(this.workspaceId, this.appKey, this.id); |
| 3399 | } |
| 3400 |
| 3401 | updateDocument(document: Record<string, unknown>) { |
| 3402 | return this.client.updateAppFileDocument( |
| 3403 | this.workspaceId, |
| 3404 | this.appKey, |
| 3405 | this.id, |
| 3406 | document, |
| 3407 | ); |
| 3408 | } |
| 3409 |
| 3410 | delete() { |
| 3411 | return this.client.deleteAppFile(this.workspaceId, this.appKey, this.id); |
| 3412 | } |
| 3413 | } |
| 3414 |
| 3415 | export class NoteHandle { |
| 3416 | constructor(private readonly ws: ColineWorkspace, readonly id: string) {} |
| 3417 | get() { return this.ws.getNote(this.id); } |
| 3418 | update(input: UpdateWorkspaceNoteInput) { return this.ws.updateNote(this.id, input); } |
| 3419 | delete() { return this.ws.deleteNote(this.id); } |
| 3420 | } |
| 3421 |
| 3422 | export class DocHandle { |
| 3423 | constructor(private readonly ws: ColineWorkspace, readonly id: string) {} |
| 3424 | get() { return this.ws.getDoc(this.id); } |
| 3425 | update(input: UpdateWorkspaceDocInput) { return this.ws.updateDoc(this.id, input); } |
| 3426 | delete() { return this.ws.deleteDoc(this.id); } |
| 3427 | } |
| 3428 |
| 3429 | export class FileHandle { |
| 3430 | constructor(private readonly ws: ColineWorkspace, readonly id: string) {} |
| 3431 | get() { return this.ws.getFile(this.id); } |
| 3432 | update(input: UpdateFileInput) { return this.ws.updateFile(this.id, input); } |
| 3433 | delete() { return this.ws.deleteFile(this.id); } |
| 3434 | } |
| 3435 |
| 3436 | export class MessageHandle { |
| 3437 | constructor(private readonly ws: ColineWorkspace, readonly id: string) {} |
| 3438 | get() { return this.ws.getMessage(this.id); } |
| 3439 | edit(input: EditMessageInput) { return this.ws.editMessage(this.id, input); } |
| 3440 | delete() { return this.ws.deleteMessage(this.id); } |
| 3441 | thread() { return this.ws.getThread(this.id); } |
| 3442 | reply(input: ThreadReplyInput) { return this.ws.replyToThread(this.id, input); } |
| 3443 | react(emoji: string) { return this.ws.addReaction(this.id, emoji); } |
| 3444 | unreact(emoji: string) { return this.ws.removeReaction(this.id, emoji); } |
| 3445 | pin() { return this.ws.pinMessage(this.id); } |
| 3446 | unpin() { return this.ws.unpinMessage(this.id); } |
| 3447 | } |
| 3448 |
| 3449 | export class ChannelHandle { |
| 3450 | constructor(private readonly ws: ColineWorkspace, readonly id: string) {} |
| 3451 | messages(query?: { cursor?: string; limit?: number }) { |
| 3452 | return this.ws.listChannelMessages(this.id, query); |
| 3453 | } |
| 3454 | send(input: SendMessageInput) { return this.ws.sendChannelMessage(this.id, input); } |
| 3455 | } |
| 3456 |
| 3457 | export class DmHandle { |
| 3458 | constructor(private readonly ws: ColineWorkspace, readonly id: string) {} |
| 3459 | messages(query?: { cursor?: string; limit?: number }) { |
| 3460 | return this.ws.listDmMessages(this.id, query); |
| 3461 | } |
| 3462 | send(input: SendMessageInput) { return this.ws.sendDmMessage(this.id, input); } |
| 3463 | } |
| 3464 |
| 3465 | export class CalendarEventHandle { |
| 3466 | constructor(private readonly ws: ColineWorkspace, readonly id: string) {} |
| 3467 | get() { return this.ws.getCalendarEvent(this.id); } |
| 3468 | update(input: UpdateCalendarEventInput) { return this.ws.updateCalendarEvent(this.id, input); } |
| 3469 | delete() { return this.ws.deleteCalendarEvent(this.id); } |
| 3470 | } |
| 3471 |
| 3472 | export class TaskboardHandle { |
| 3473 | constructor(private readonly ws: ColineWorkspace, readonly id: string) {} |
| 3474 | listTasks(query?: ListTaskboardTasksQuery) { return this.ws.listTasks(this.id, query); } |
| 3475 | createTask(input: CreateTaskInput) { return this.ws.createTask(this.id, input); } |
| 3476 | task(taskId: string): TaskHandle { return new TaskHandle(this.ws, this.id, taskId); } |
| 3477 | batchCreateTasks(tasks: CreateTaskInput[]) { return this.ws.batchCreateTasks(this.id, tasks); } |
| 3478 | batchUpdateTasks(updates: BatchUpdateTaskEntry[]) { return this.ws.batchUpdateTasks(this.id, updates); } |
| 3479 | batchDeleteTasks(taskIds: string[]) { return this.ws.batchDeleteTasks(this.id, taskIds); } |
| 3480 | } |
| 3481 |
| 3482 | export class TaskHandle { |
| 3483 | constructor( |
| 3484 | private readonly ws: ColineWorkspace, |
| 3485 | private readonly taskboardId: string, |
| 3486 | readonly id: string, |
| 3487 | ) {} |
| 3488 | update(input: UpdateTaskInput) { return this.ws.updateTask(this.taskboardId, this.id, input); } |
| 3489 | delete() { return this.ws.deleteTask(this.taskboardId, this.id); } |
| 3490 | } |
| 3491 |