open-agent-docs 0.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4300 @@
1
+ # 由 codegen 生成,不要手改:python sdks/python/codegen/generate.py(来源 docs/openapi.json、sdks/operations.json)
2
+ # pyright: reportPrivateUsage=false
3
+ """资源类:client.pages.versions.list(...) 这样的方法(名字见 sdks/operations.json)。"""
4
+ from __future__ import annotations
5
+
6
+ from functools import cached_property
7
+ from typing import Any, Dict, List, Mapping, Optional, Sequence, Union
8
+
9
+ from .._base_client import AsyncAPIClient, Body, Headers, Query, SyncAPIClient, TimeoutTypes
10
+ from .._files import FileTypes, csv_body as _csv_body, file_part as _file_part
11
+ from .._pagination import AsyncPaginator, CursorPage
12
+ from .._sse import AsyncEventStream, EventStream
13
+ from .._types import NOT_GIVEN, NotGiven
14
+ from .._utils import quote_path as _p
15
+ from .models import (
16
+ Acked,
17
+ AddRow,
18
+ AddedRows,
19
+ Agent,
20
+ AgentNotes,
21
+ AgentNotification,
22
+ AgentView,
23
+ Anchor,
24
+ AuthConfigBody,
25
+ AuthorRef,
26
+ BlockContent,
27
+ BlockIds,
28
+ CellOp,
29
+ CommentView,
30
+ Content,
31
+ CreatedAgent,
32
+ DbHistory,
33
+ DbHistoryItem,
34
+ DbInfo,
35
+ DbUndone,
36
+ DbView,
37
+ Deleted,
38
+ DocNode,
39
+ Inbox,
40
+ InboxNotification,
41
+ InviteInfo,
42
+ InviteView,
43
+ Me,
44
+ MemberList,
45
+ MemberRole,
46
+ NewSecret,
47
+ NewToken,
48
+ Notify,
49
+ Page,
50
+ Patched,
51
+ Pressed,
52
+ PutViews,
53
+ QueryResult,
54
+ ReadCount,
55
+ Restored,
56
+ RestoredPage,
57
+ RowsDelta,
58
+ SchemaChanged,
59
+ SchemaUndone,
60
+ SearchResult,
61
+ Seq,
62
+ ShareView,
63
+ SignedFileUrls,
64
+ ThreadView,
65
+ TrashItem,
66
+ TrashList,
67
+ UnfurlCard,
68
+ Uploaded,
69
+ VersionContent,
70
+ VersionDiff,
71
+ VersionList,
72
+ VersionMeta,
73
+ Workspace,
74
+ )
75
+
76
+ __all__ = ["SyncResources", "AsyncResources"]
77
+
78
+
79
+ class AgentNotificationsResource:
80
+ """`client.agent.notifications`"""
81
+
82
+ def __init__(self, client: SyncAPIClient) -> None:
83
+ self._client = client
84
+
85
+ def list(
86
+ self,
87
+ *,
88
+ after: Union[int, NotGiven] = NOT_GIVEN,
89
+ cursor: Union[str, NotGiven] = NOT_GIVEN,
90
+ limit: Union[int, NotGiven] = NOT_GIVEN,
91
+ wait: Union[int, NotGiven] = NOT_GIVEN,
92
+ extra_headers: Optional[Headers] = None,
93
+ extra_query: Optional[Query] = None,
94
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
95
+ ) -> CursorPage[AgentNotification]:
96
+ """Agent 取通知(长轮询):没有新的就等 wait 秒。不给 after / cursor 就是还没处理(ack)的。只有 Agent 能调。
97
+
98
+ `GET /api/v1/agent/notifications`
99
+ """
100
+ return self._client._call_page(
101
+ "GET",
102
+ "/agent/notifications",
103
+ query={"after": after, "cursor": cursor, "limit": limit, "wait": wait},
104
+ model=AgentNotes,
105
+ items="notifications",
106
+ item=AgentNotification,
107
+ extra_headers=extra_headers,
108
+ extra_query=extra_query,
109
+ timeout=timeout,
110
+ )
111
+
112
+ def ack(
113
+ self,
114
+ *,
115
+ ids: Union[Sequence[int], NotGiven] = NOT_GIVEN,
116
+ upto: Union[int, None, NotGiven] = NOT_GIVEN,
117
+ extra_headers: Optional[Headers] = None,
118
+ extra_query: Optional[Query] = None,
119
+ extra_body: Optional[Body] = None,
120
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
121
+ ) -> Acked:
122
+ """`POST /api/v1/agent/notifications/ack`"""
123
+ return self._client._call(
124
+ "POST",
125
+ "/agent/notifications/ack",
126
+ body={"ids": ids, "upto": upto},
127
+ extra_body=extra_body,
128
+ cast=Acked,
129
+ extra_headers=extra_headers,
130
+ extra_query=extra_query,
131
+ timeout=timeout,
132
+ )
133
+
134
+ def stream(
135
+ self,
136
+ *,
137
+ after: Union[int, NotGiven] = NOT_GIVEN,
138
+ cursor: Union[str, NotGiven] = NOT_GIVEN,
139
+ extra_headers: Optional[Headers] = None,
140
+ extra_query: Optional[Query] = None,
141
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
142
+ ) -> EventStream:
143
+ """SSE:先补发游标之后的(`?after=` / `?cursor=` 或 `Last-Event-ID` 头;都没有就是没处理的),再实时推。每条是 `event: notification`,`id` 是通知编号,`data` 是 AgentNotification。每 25 秒一个注释行保活。只有 Agent 能调。
144
+
145
+ `GET /api/v1/agent/notifications/stream`
146
+ """
147
+ return self._client._stream(
148
+ "/agent/notifications/stream",
149
+ query={"after": after, "cursor": cursor},
150
+ kind="agent",
151
+ extra_headers=extra_headers,
152
+ extra_query=extra_query,
153
+ timeout=timeout,
154
+ )
155
+
156
+
157
+ class AgentResource:
158
+ """`client.agent`"""
159
+
160
+ def __init__(self, client: SyncAPIClient) -> None:
161
+ self._client = client
162
+
163
+ @cached_property
164
+ def notifications(self) -> AgentNotificationsResource:
165
+ return AgentNotificationsResource(self._client)
166
+
167
+
168
+ class AgentsResource:
169
+ """`client.agents`"""
170
+
171
+ def __init__(self, client: SyncAPIClient) -> None:
172
+ self._client = client
173
+
174
+ def list(
175
+ self,
176
+ ws: str,
177
+ *,
178
+ extra_headers: Optional[Headers] = None,
179
+ extra_query: Optional[Query] = None,
180
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
181
+ ) -> List[AgentView]:
182
+ """`GET /api/v1/workspaces/{ws}/agents`"""
183
+ return self._client._call(
184
+ "GET",
185
+ f"/workspaces/{_p(ws)}/agents",
186
+ unwrap="agents",
187
+ cast=List[AgentView],
188
+ extra_headers=extra_headers,
189
+ extra_query=extra_query,
190
+ timeout=timeout,
191
+ )
192
+
193
+ def create(
194
+ self,
195
+ ws: str,
196
+ *,
197
+ name: str,
198
+ scope: str,
199
+ about: Union[str, None, NotGiven] = NOT_GIVEN,
200
+ webhook: Union[str, None, NotGiven] = NOT_GIVEN,
201
+ extra_headers: Optional[Headers] = None,
202
+ extra_query: Optional[Query] = None,
203
+ extra_body: Optional[Body] = None,
204
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
205
+ ) -> CreatedAgent:
206
+ """`POST /api/v1/workspaces/{ws}/agents`"""
207
+ return self._client._call(
208
+ "POST",
209
+ f"/workspaces/{_p(ws)}/agents",
210
+ body={"about": about, "name": name, "scope": scope, "webhook": webhook},
211
+ extra_body=extra_body,
212
+ cast=CreatedAgent,
213
+ extra_headers=extra_headers,
214
+ extra_query=extra_query,
215
+ timeout=timeout,
216
+ )
217
+
218
+ def update(
219
+ self,
220
+ id: str,
221
+ *,
222
+ about: Union[str, None, NotGiven] = NOT_GIVEN,
223
+ locale: Union[str, None, NotGiven] = NOT_GIVEN,
224
+ name: Union[str, None, NotGiven] = NOT_GIVEN,
225
+ scope: Union[str, None, NotGiven] = NOT_GIVEN,
226
+ webhook: Union[str, None, NotGiven] = NOT_GIVEN,
227
+ extra_headers: Optional[Headers] = None,
228
+ extra_query: Optional[Query] = None,
229
+ extra_body: Optional[Body] = None,
230
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
231
+ ) -> Agent:
232
+ """`PATCH /api/v1/agents/{id}`"""
233
+ return self._client._call(
234
+ "PATCH",
235
+ f"/agents/{_p(id)}",
236
+ body={"about": about, "locale": locale, "name": name, "scope": scope, "webhook": webhook},
237
+ extra_body=extra_body,
238
+ cast=Agent,
239
+ extra_headers=extra_headers,
240
+ extra_query=extra_query,
241
+ timeout=timeout,
242
+ )
243
+
244
+ def revoke(
245
+ self,
246
+ id: str,
247
+ *,
248
+ extra_headers: Optional[Headers] = None,
249
+ extra_query: Optional[Query] = None,
250
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
251
+ ) -> Agent:
252
+ """撤销:token 马上失效,返回撤销后的 Agent(带 revoked_at)。
253
+
254
+ `DELETE /api/v1/agents/{id}`
255
+ """
256
+ return self._client._call(
257
+ "DELETE",
258
+ f"/agents/{_p(id)}",
259
+ cast=Agent,
260
+ extra_headers=extra_headers,
261
+ extra_query=extra_query,
262
+ timeout=timeout,
263
+ )
264
+
265
+ def rotate_token(
266
+ self,
267
+ id: str,
268
+ *,
269
+ extra_headers: Optional[Headers] = None,
270
+ extra_query: Optional[Query] = None,
271
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
272
+ ) -> NewToken:
273
+ """`POST /api/v1/agents/{id}/token`"""
274
+ return self._client._call(
275
+ "POST",
276
+ f"/agents/{_p(id)}/token",
277
+ cast=NewToken,
278
+ extra_headers=extra_headers,
279
+ extra_query=extra_query,
280
+ timeout=timeout,
281
+ )
282
+
283
+ def rotate_webhook_secret(
284
+ self,
285
+ id: str,
286
+ *,
287
+ extra_headers: Optional[Headers] = None,
288
+ extra_query: Optional[Query] = None,
289
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
290
+ ) -> NewSecret:
291
+ """`POST /api/v1/agents/{id}/webhook-secret`"""
292
+ return self._client._call(
293
+ "POST",
294
+ f"/agents/{_p(id)}/webhook-secret",
295
+ cast=NewSecret,
296
+ extra_headers=extra_headers,
297
+ extra_query=extra_query,
298
+ timeout=timeout,
299
+ )
300
+
301
+
302
+ class AuthResource:
303
+ """`client.auth`"""
304
+
305
+ def __init__(self, client: SyncAPIClient) -> None:
306
+ self._client = client
307
+
308
+ def config(
309
+ self,
310
+ *,
311
+ extra_headers: Optional[Headers] = None,
312
+ extra_query: Optional[Query] = None,
313
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
314
+ ) -> AuthConfigBody:
315
+ """`GET /api/v1/auth/config`"""
316
+ return self._client._call(
317
+ "GET",
318
+ "/auth/config",
319
+ cast=AuthConfigBody,
320
+ extra_headers=extra_headers,
321
+ extra_query=extra_query,
322
+ timeout=timeout,
323
+ )
324
+
325
+ def login(
326
+ self,
327
+ *,
328
+ email: str,
329
+ password: str,
330
+ extra_headers: Optional[Headers] = None,
331
+ extra_query: Optional[Query] = None,
332
+ extra_body: Optional[Body] = None,
333
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
334
+ ) -> Me:
335
+ """`POST /api/v1/auth/login`"""
336
+ return self._client._call(
337
+ "POST",
338
+ "/auth/login",
339
+ body={"email": email, "password": password},
340
+ extra_body=extra_body,
341
+ cast=Me,
342
+ extra_headers=extra_headers,
343
+ extra_query=extra_query,
344
+ timeout=timeout,
345
+ )
346
+
347
+ def logout(
348
+ self,
349
+ *,
350
+ extra_headers: Optional[Headers] = None,
351
+ extra_query: Optional[Query] = None,
352
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
353
+ ) -> None:
354
+ """`POST /api/v1/auth/logout`"""
355
+ return self._client._call(
356
+ "POST",
357
+ "/auth/logout",
358
+ cast=type(None),
359
+ extra_headers=extra_headers,
360
+ extra_query=extra_query,
361
+ timeout=timeout,
362
+ )
363
+
364
+ def signup(
365
+ self,
366
+ *,
367
+ email: str,
368
+ password: str,
369
+ invite: Union[str, None, NotGiven] = NOT_GIVEN,
370
+ name: Union[str, NotGiven] = NOT_GIVEN,
371
+ extra_headers: Optional[Headers] = None,
372
+ extra_query: Optional[Query] = None,
373
+ extra_body: Optional[Body] = None,
374
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
375
+ ) -> Me:
376
+ """注册(本地登录模式)。OAD_SIGNUP:invite(默认,要凭邀请)、open、off。
377
+
378
+ `POST /api/v1/auth/signup`
379
+ """
380
+ return self._client._call(
381
+ "POST",
382
+ "/auth/signup",
383
+ body={"email": email, "invite": invite, "name": name, "password": password},
384
+ extra_body=extra_body,
385
+ cast=Me,
386
+ extra_headers=extra_headers,
387
+ extra_query=extra_query,
388
+ timeout=timeout,
389
+ )
390
+
391
+
392
+ class CommentsResource:
393
+ """`client.comments`"""
394
+
395
+ def __init__(self, client: SyncAPIClient) -> None:
396
+ self._client = client
397
+
398
+ def update(
399
+ self,
400
+ id: str,
401
+ *,
402
+ body: str,
403
+ extra_headers: Optional[Headers] = None,
404
+ extra_query: Optional[Query] = None,
405
+ extra_body: Optional[Body] = None,
406
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
407
+ ) -> CommentView:
408
+ """只有作者能改。
409
+
410
+ `PATCH /api/v1/comments/{id}`
411
+ """
412
+ return self._client._call(
413
+ "PATCH",
414
+ f"/comments/{_p(id)}",
415
+ body={"body": body},
416
+ extra_body=extra_body,
417
+ cast=CommentView,
418
+ extra_headers=extra_headers,
419
+ extra_query=extra_query,
420
+ timeout=timeout,
421
+ )
422
+
423
+ def delete(
424
+ self,
425
+ id: str,
426
+ *,
427
+ extra_headers: Optional[Headers] = None,
428
+ extra_query: Optional[Query] = None,
429
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
430
+ ) -> None:
431
+ """`DELETE /api/v1/comments/{id}`"""
432
+ return self._client._call(
433
+ "DELETE",
434
+ f"/comments/{_p(id)}",
435
+ cast=type(None),
436
+ extra_headers=extra_headers,
437
+ extra_query=extra_query,
438
+ timeout=timeout,
439
+ )
440
+
441
+
442
+ class DatabasesHistoryResource:
443
+ """`client.databases.history`"""
444
+
445
+ def __init__(self, client: SyncAPIClient) -> None:
446
+ self._client = client
447
+
448
+ def list(
449
+ self,
450
+ id: str,
451
+ *,
452
+ row: Union[str, NotGiven] = NOT_GIVEN,
453
+ prop: Union[str, NotGiven] = NOT_GIVEN,
454
+ limit: Union[int, NotGiven] = NOT_GIVEN,
455
+ cursor: Union[str, NotGiven] = NOT_GIVEN,
456
+ extra_headers: Optional[Headers] = None,
457
+ extra_query: Optional[Query] = None,
458
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
459
+ ) -> CursorPage[DbHistoryItem]:
460
+ """`GET /api/v1/databases/{id}/history`"""
461
+ return self._client._call_page(
462
+ "GET",
463
+ f"/databases/{_p(id)}/history",
464
+ query={"row": row, "prop": prop, "limit": limit, "cursor": cursor},
465
+ model=DbHistory,
466
+ items="items",
467
+ item=DbHistoryItem,
468
+ extra_headers=extra_headers,
469
+ extra_query=extra_query,
470
+ timeout=timeout,
471
+ )
472
+
473
+ def undo(
474
+ self,
475
+ id: str,
476
+ *,
477
+ seq: int,
478
+ extra_headers: Optional[Headers] = None,
479
+ extra_query: Optional[Query] = None,
480
+ extra_body: Optional[Body] = None,
481
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
482
+ ) -> DbUndone:
483
+ """`POST /api/v1/databases/{id}/history/undo`"""
484
+ return self._client._call(
485
+ "POST",
486
+ f"/databases/{_p(id)}/history/undo",
487
+ body={"seq": seq},
488
+ extra_body=extra_body,
489
+ cast=DbUndone,
490
+ extra_headers=extra_headers,
491
+ extra_query=extra_query,
492
+ timeout=timeout,
493
+ )
494
+
495
+
496
+ class DatabasesRowsResource:
497
+ """`client.databases.rows`"""
498
+
499
+ def __init__(self, client: SyncAPIClient) -> None:
500
+ self._client = client
501
+
502
+ def list(
503
+ self,
504
+ id: str,
505
+ *,
506
+ since: Union[int, NotGiven] = NOT_GIVEN,
507
+ extra_headers: Optional[Headers] = None,
508
+ extra_query: Optional[Query] = None,
509
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
510
+ ) -> RowsDelta:
511
+ """行(全量或增量)。按 Accept-Encoding 压缩:br 优先,其次 gzip(1 万行的全量压缩后 < 1MB)。
512
+
513
+ `GET /api/v1/databases/{id}/rows`
514
+ """
515
+ return self._client._call(
516
+ "GET",
517
+ f"/databases/{_p(id)}/rows",
518
+ query={"since": since},
519
+ cast=RowsDelta,
520
+ extra_headers=extra_headers,
521
+ extra_query=extra_query,
522
+ timeout=timeout,
523
+ )
524
+
525
+ def add(
526
+ self,
527
+ id: str,
528
+ *,
529
+ rows: Sequence[Union[AddRow, Dict[str, Any]]],
530
+ extra_headers: Optional[Headers] = None,
531
+ extra_query: Optional[Query] = None,
532
+ extra_body: Optional[Body] = None,
533
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
534
+ ) -> AddedRows:
535
+ """`POST /api/v1/databases/{id}/rows`"""
536
+ return self._client._call(
537
+ "POST",
538
+ f"/databases/{_p(id)}/rows",
539
+ body={"rows": rows},
540
+ extra_body=extra_body,
541
+ cast=AddedRows,
542
+ extra_headers=extra_headers,
543
+ extra_query=extra_query,
544
+ timeout=timeout,
545
+ )
546
+
547
+ def update(
548
+ self,
549
+ id: str,
550
+ *,
551
+ ops: Sequence[Union[CellOp, Dict[str, Any]]],
552
+ extra_headers: Optional[Headers] = None,
553
+ extra_query: Optional[Query] = None,
554
+ extra_body: Optional[Body] = None,
555
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
556
+ ) -> Patched:
557
+ """`PATCH /api/v1/databases/{id}/rows`"""
558
+ return self._client._call(
559
+ "PATCH",
560
+ f"/databases/{_p(id)}/rows",
561
+ body={"ops": ops},
562
+ extra_body=extra_body,
563
+ cast=Patched,
564
+ extra_headers=extra_headers,
565
+ extra_query=extra_query,
566
+ timeout=timeout,
567
+ )
568
+
569
+ def delete(
570
+ self,
571
+ id: str,
572
+ *,
573
+ ids: Sequence[str],
574
+ extra_headers: Optional[Headers] = None,
575
+ extra_query: Optional[Query] = None,
576
+ extra_body: Optional[Body] = None,
577
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
578
+ ) -> Seq:
579
+ """`DELETE /api/v1/databases/{id}/rows`"""
580
+ return self._client._call(
581
+ "DELETE",
582
+ f"/databases/{_p(id)}/rows",
583
+ body={"ids": ids},
584
+ extra_body=extra_body,
585
+ cast=Seq,
586
+ extra_headers=extra_headers,
587
+ extra_query=extra_query,
588
+ timeout=timeout,
589
+ )
590
+
591
+ def delete_one(
592
+ self,
593
+ id: str,
594
+ row: str,
595
+ *,
596
+ extra_headers: Optional[Headers] = None,
597
+ extra_query: Optional[Query] = None,
598
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
599
+ ) -> Seq:
600
+ """`DELETE /api/v1/databases/{id}/rows/{row}`"""
601
+ return self._client._call(
602
+ "DELETE",
603
+ f"/databases/{_p(id)}/rows/{_p(row)}",
604
+ cast=Seq,
605
+ extra_headers=extra_headers,
606
+ extra_query=extra_query,
607
+ timeout=timeout,
608
+ )
609
+
610
+
611
+ class DatabasesSchemaResource:
612
+ """`client.databases.schema`"""
613
+
614
+ def __init__(self, client: SyncAPIClient) -> None:
615
+ self._client = client
616
+
617
+ def update(
618
+ self,
619
+ id: str,
620
+ *,
621
+ ops: Sequence[Mapping[str, Any]],
622
+ extra_headers: Optional[Headers] = None,
623
+ extra_query: Optional[Query] = None,
624
+ extra_body: Optional[Body] = None,
625
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
626
+ ) -> SchemaChanged:
627
+ """`PATCH /api/v1/databases/{id}/schema`"""
628
+ return self._client._call(
629
+ "PATCH",
630
+ f"/databases/{_p(id)}/schema",
631
+ body={"ops": ops},
632
+ extra_body=extra_body,
633
+ cast=SchemaChanged,
634
+ extra_headers=extra_headers,
635
+ extra_query=extra_query,
636
+ timeout=timeout,
637
+ )
638
+
639
+ def undo(
640
+ self,
641
+ id: str,
642
+ *,
643
+ seq: int,
644
+ extra_headers: Optional[Headers] = None,
645
+ extra_query: Optional[Query] = None,
646
+ extra_body: Optional[Body] = None,
647
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
648
+ ) -> SchemaUndone:
649
+ """`POST /api/v1/databases/{id}/schema/undo`"""
650
+ return self._client._call(
651
+ "POST",
652
+ f"/databases/{_p(id)}/schema/undo",
653
+ body={"seq": seq},
654
+ extra_body=extra_body,
655
+ cast=SchemaUndone,
656
+ extra_headers=extra_headers,
657
+ extra_query=extra_query,
658
+ timeout=timeout,
659
+ )
660
+
661
+
662
+ class DatabasesViewsResource:
663
+ """`client.databases.views`"""
664
+
665
+ def __init__(self, client: SyncAPIClient) -> None:
666
+ self._client = client
667
+
668
+ def create(
669
+ self,
670
+ id: str,
671
+ *,
672
+ body: Mapping[str, Any],
673
+ extra_headers: Optional[Headers] = None,
674
+ extra_query: Optional[Query] = None,
675
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
676
+ ) -> DbView:
677
+ """加一个视图(不给 type 是表格),返回它(带上新的 id)。
678
+
679
+ `POST /api/v1/databases/{id}/views`
680
+ """
681
+ return self._client._call(
682
+ "POST",
683
+ f"/databases/{_p(id)}/views",
684
+ body=body,
685
+ cast=DbView,
686
+ extra_headers=extra_headers,
687
+ extra_query=extra_query,
688
+ timeout=timeout,
689
+ )
690
+
691
+ def replace(
692
+ self,
693
+ id: str,
694
+ *,
695
+ body: PutViews,
696
+ extra_headers: Optional[Headers] = None,
697
+ extra_query: Optional[Query] = None,
698
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
699
+ ) -> List[DbView]:
700
+ """整个换掉:`[...]` 或 `{ views: [...] }`。
701
+
702
+ `PUT /api/v1/databases/{id}/views`
703
+ """
704
+ return self._client._call(
705
+ "PUT",
706
+ f"/databases/{_p(id)}/views",
707
+ body=body,
708
+ unwrap="views",
709
+ cast=List[DbView],
710
+ extra_headers=extra_headers,
711
+ extra_query=extra_query,
712
+ timeout=timeout,
713
+ )
714
+
715
+ def update(
716
+ self,
717
+ id: str,
718
+ view: str,
719
+ *,
720
+ body: Mapping[str, Any],
721
+ extra_headers: Optional[Headers] = None,
722
+ extra_query: Optional[Query] = None,
723
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
724
+ ) -> DbView:
725
+ """改一个视图的几项:给了的字段覆盖,null 去掉。返回改好的视图。
726
+
727
+ `PATCH /api/v1/databases/{id}/views/{view}`
728
+ """
729
+ return self._client._call(
730
+ "PATCH",
731
+ f"/databases/{_p(id)}/views/{_p(view)}",
732
+ body=body,
733
+ cast=DbView,
734
+ extra_headers=extra_headers,
735
+ extra_query=extra_query,
736
+ timeout=timeout,
737
+ )
738
+
739
+ def delete(
740
+ self,
741
+ id: str,
742
+ view: str,
743
+ *,
744
+ extra_headers: Optional[Headers] = None,
745
+ extra_query: Optional[Query] = None,
746
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
747
+ ) -> None:
748
+ """删一个视图(最后一个不能删)。
749
+
750
+ `DELETE /api/v1/databases/{id}/views/{view}`
751
+ """
752
+ return self._client._call(
753
+ "DELETE",
754
+ f"/databases/{_p(id)}/views/{_p(view)}",
755
+ cast=type(None),
756
+ extra_headers=extra_headers,
757
+ extra_query=extra_query,
758
+ timeout=timeout,
759
+ )
760
+
761
+
762
+ class DatabasesResource:
763
+ """`client.databases`"""
764
+
765
+ def __init__(self, client: SyncAPIClient) -> None:
766
+ self._client = client
767
+
768
+ @cached_property
769
+ def history(self) -> DatabasesHistoryResource:
770
+ return DatabasesHistoryResource(self._client)
771
+
772
+ @cached_property
773
+ def rows(self) -> DatabasesRowsResource:
774
+ return DatabasesRowsResource(self._client)
775
+
776
+ @cached_property
777
+ def schema(self) -> DatabasesSchemaResource:
778
+ return DatabasesSchemaResource(self._client)
779
+
780
+ @cached_property
781
+ def views(self) -> DatabasesViewsResource:
782
+ return DatabasesViewsResource(self._client)
783
+
784
+ def create(
785
+ self,
786
+ ws: str,
787
+ *,
788
+ after: Union[str, None, NotGiven] = NOT_GIVEN,
789
+ parent_id: Union[str, None, NotGiven] = NOT_GIVEN,
790
+ schema: Union[Mapping[str, Any], None, NotGiven] = NOT_GIVEN,
791
+ title: Union[str, None, NotGiven] = NOT_GIVEN,
792
+ views: Union[Sequence[Mapping[str, Any]], None, NotGiven] = NOT_GIVEN,
793
+ extra_headers: Optional[Headers] = None,
794
+ extra_query: Optional[Query] = None,
795
+ extra_body: Optional[Body] = None,
796
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
797
+ ) -> DbInfo:
798
+ """`POST /api/v1/workspaces/{ws}/databases`"""
799
+ return self._client._call(
800
+ "POST",
801
+ f"/workspaces/{_p(ws)}/databases",
802
+ body={"after": after, "parent_id": parent_id, "schema": schema, "title": title, "views": views},
803
+ extra_body=extra_body,
804
+ cast=DbInfo,
805
+ extra_headers=extra_headers,
806
+ extra_query=extra_query,
807
+ timeout=timeout,
808
+ )
809
+
810
+ def import_csv(
811
+ self,
812
+ ws: str,
813
+ csv: Union[str, bytes],
814
+ *,
815
+ title: Union[str, NotGiven] = NOT_GIVEN,
816
+ parent_id: Union[str, NotGiven] = NOT_GIVEN,
817
+ extra_headers: Optional[Headers] = None,
818
+ extra_query: Optional[Query] = None,
819
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
820
+ ) -> DbInfo:
821
+ """导入 CSV:multipart 的 `file`(和可选的 `title`、`parent_id`),或者原始正文(`?title=`)。
822
+
823
+ `POST /api/v1/workspaces/{ws}/databases/import`
824
+ """
825
+ return self._client._call(
826
+ "POST",
827
+ f"/workspaces/{_p(ws)}/databases/import",
828
+ query={"title": title, "parent_id": parent_id},
829
+ content=_csv_body(csv),
830
+ headers={"content-type": "text/csv; charset=utf-8"},
831
+ cast=DbInfo,
832
+ extra_headers=extra_headers,
833
+ extra_query=extra_query,
834
+ timeout=timeout,
835
+ )
836
+
837
+ def get(
838
+ self,
839
+ id: str,
840
+ *,
841
+ extra_headers: Optional[Headers] = None,
842
+ extra_query: Optional[Query] = None,
843
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
844
+ ) -> DbInfo:
845
+ """库的页面、表结构、视图、现在的 seq。
846
+
847
+ `GET /api/v1/databases/{id}`
848
+ """
849
+ return self._client._call(
850
+ "GET",
851
+ f"/databases/{_p(id)}",
852
+ cast=DbInfo,
853
+ extra_headers=extra_headers,
854
+ extra_query=extra_query,
855
+ timeout=timeout,
856
+ )
857
+
858
+ def query(
859
+ self,
860
+ id: str,
861
+ *,
862
+ filter: Union[Mapping[str, Any], None, NotGiven] = NOT_GIVEN,
863
+ group_by: Union[str, None, NotGiven] = NOT_GIVEN,
864
+ limit: Union[int, None, NotGiven] = NOT_GIVEN,
865
+ offset: Union[int, None, NotGiven] = NOT_GIVEN,
866
+ search: Union[str, None, NotGiven] = NOT_GIVEN,
867
+ sorts: Union[Sequence[Mapping[str, Any]], None, NotGiven] = NOT_GIVEN,
868
+ totals: Union[Mapping[str, Any], None, NotGiven] = NOT_GIVEN,
869
+ view_id: Union[str, None, NotGiven] = NOT_GIVEN,
870
+ extra_headers: Optional[Headers] = None,
871
+ extra_query: Optional[Query] = None,
872
+ extra_body: Optional[Body] = None,
873
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
874
+ ) -> QueryResult:
875
+ """服务器算的查询:给了 view_id 就从那个视图出发,别的字段覆盖它。
876
+
877
+ `POST /api/v1/databases/{id}/query`
878
+ """
879
+ return self._client._call(
880
+ "POST",
881
+ f"/databases/{_p(id)}/query",
882
+ body={"filter": filter, "group_by": group_by, "limit": limit, "offset": offset, "search": search, "sorts": sorts, "totals": totals, "view_id": view_id},
883
+ extra_body=extra_body,
884
+ cast=QueryResult,
885
+ extra_headers=extra_headers,
886
+ extra_query=extra_query,
887
+ timeout=timeout,
888
+ )
889
+
890
+ def export_csv(
891
+ self,
892
+ id: str,
893
+ *,
894
+ extra_headers: Optional[Headers] = None,
895
+ extra_query: Optional[Query] = None,
896
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
897
+ ) -> bytes:
898
+ """导出 CSV(UTF-8,按第一个视图的列)。
899
+
900
+ `GET /api/v1/databases/{id}/export.csv`
901
+ """
902
+ return self._client._call(
903
+ "GET",
904
+ f"/databases/{_p(id)}/export.csv",
905
+ cast=bytes,
906
+ extra_headers=extra_headers,
907
+ extra_query=extra_query,
908
+ timeout=timeout,
909
+ )
910
+
911
+ def press_button(
912
+ self,
913
+ id: str,
914
+ row: str,
915
+ key: str,
916
+ *,
917
+ extra_headers: Optional[Headers] = None,
918
+ extra_query: Optional[Query] = None,
919
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
920
+ ) -> Pressed:
921
+ """按一行上的按钮:按设置改属性,有 `comment` 的在这一行上发一条评论(可以叫 Agent)。
922
+
923
+ `POST /api/v1/databases/{id}/button/{row}/{key}`
924
+ """
925
+ return self._client._call(
926
+ "POST",
927
+ f"/databases/{_p(id)}/button/{_p(row)}/{_p(key)}",
928
+ cast=Pressed,
929
+ extra_headers=extra_headers,
930
+ extra_query=extra_query,
931
+ timeout=timeout,
932
+ )
933
+
934
+
935
+ class FilesResource:
936
+ """`client.files`"""
937
+
938
+ def __init__(self, client: SyncAPIClient) -> None:
939
+ self._client = client
940
+
941
+ def upload(
942
+ self,
943
+ ws: str,
944
+ file: FileTypes,
945
+ filename: Optional[str] = None,
946
+ content_type: Optional[str] = None,
947
+ *,
948
+ extra_headers: Optional[Headers] = None,
949
+ extra_query: Optional[Query] = None,
950
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
951
+ ) -> Uploaded:
952
+ """上传文件:`multipart/form-data` 的 `file` 字段,或者原始正文 + `X-Filename` 头(文件名按网址规则编码)。大小上限见 OAD_MAX_UPLOAD。图片会算宽高和 blurhash,音视频算时长。
953
+
954
+ `POST /api/v1/workspaces/{ws}/files`
955
+ """
956
+ return self._client._call(
957
+ "POST",
958
+ f"/workspaces/{_p(ws)}/files",
959
+ files=_file_part(file, filename, content_type),
960
+ cast=Uploaded,
961
+ extra_headers=extra_headers,
962
+ extra_query=extra_query,
963
+ timeout=timeout,
964
+ )
965
+
966
+ def download(
967
+ self,
968
+ id: str,
969
+ *,
970
+ w: Union[int, NotGiven] = NOT_GIVEN,
971
+ exp: Union[int, NotGiven] = NOT_GIVEN,
972
+ sig: Union[str, NotGiven] = NOT_GIVEN,
973
+ extra_headers: Optional[Headers] = None,
974
+ extra_query: Optional[Query] = None,
975
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
976
+ ) -> bytes:
977
+ """同 `/files/{id}/{name}`,不带文件名。
978
+
979
+ `GET /api/v1/files/{id}`
980
+ """
981
+ return self._client._call(
982
+ "GET",
983
+ f"/files/{_p(id)}",
984
+ query={"w": w, "exp": exp, "sig": sig},
985
+ cast=bytes,
986
+ extra_headers=extra_headers,
987
+ extra_query=extra_query,
988
+ timeout=timeout,
989
+ )
990
+
991
+ def download_named(
992
+ self,
993
+ id: str,
994
+ name: str,
995
+ *,
996
+ w: Union[int, NotGiven] = NOT_GIVEN,
997
+ exp: Union[int, NotGiven] = NOT_GIVEN,
998
+ sig: Union[str, NotGiven] = NOT_GIVEN,
999
+ extra_headers: Optional[Headers] = None,
1000
+ extra_query: Optional[Query] = None,
1001
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1002
+ ) -> bytes:
1003
+ """下载上传的文件:原来的类型;带 ETag、长缓存、Range。`?w=` 给图片的缩略图(WebP)。SVG、HTML 之类带 `Content-Security-Policy: sandbox`,SVG 当附件下载。不是这个工作区的成员当不存在(404)。带了有效的签名(`?exp=&sig=`,见 `POST /files/sign`)就不用登录;签名过期了或者不对回 403(登录了、看得到的照样给)。
1004
+
1005
+ `GET /api/v1/files/{id}/{name}`
1006
+ """
1007
+ return self._client._call(
1008
+ "GET",
1009
+ f"/files/{_p(id)}/{_p(name)}",
1010
+ query={"w": w, "exp": exp, "sig": sig},
1011
+ cast=bytes,
1012
+ extra_headers=extra_headers,
1013
+ extra_query=extra_query,
1014
+ timeout=timeout,
1015
+ )
1016
+
1017
+ def media(
1018
+ self,
1019
+ hash: str,
1020
+ *,
1021
+ w: Union[int, NotGiven] = NOT_GIVEN,
1022
+ exp: Union[int, NotGiven] = NOT_GIVEN,
1023
+ sig: Union[str, NotGiven] = NOT_GIVEN,
1024
+ extra_headers: Optional[Headers] = None,
1025
+ extra_query: Optional[Query] = None,
1026
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1027
+ ) -> bytes:
1028
+ """转存的外部图片(链接卡片的封面、头像之类),按内容的 hash。登录了就能看,带了有效的签名(`?exp=&sig=`)也行。`?w=` 给缩略图(WebP),支持 Range。
1029
+
1030
+ `GET /api/v1/media/{hash}`
1031
+ """
1032
+ return self._client._call(
1033
+ "GET",
1034
+ f"/media/{_p(hash)}",
1035
+ query={"w": w, "exp": exp, "sig": sig},
1036
+ cast=bytes,
1037
+ extra_headers=extra_headers,
1038
+ extra_query=extra_query,
1039
+ timeout=timeout,
1040
+ )
1041
+
1042
+ def sign(
1043
+ self,
1044
+ *,
1045
+ urls: Sequence[str],
1046
+ extra_headers: Optional[Headers] = None,
1047
+ extra_query: Optional[Query] = None,
1048
+ extra_body: Optional[Body] = None,
1049
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1050
+ ) -> SignedFileUrls:
1051
+ """给文件、转存的图片签名,拿到不用登录就能打开的地址(`<img>`、链接带不了 `Authorization`:跨域 iframe、Web Component、宿主自己渲染的 HTML 用)。签名不包含 `w` 和文件名,拿到以后可以自己加 `w=`。只签调用者看得到的;拿到地址的人在有效期内不登录也能打开,别外传。
1052
+
1053
+ `POST /api/v1/files/sign`
1054
+ """
1055
+ return self._client._call(
1056
+ "POST",
1057
+ "/files/sign",
1058
+ body={"urls": urls},
1059
+ extra_body=extra_body,
1060
+ cast=SignedFileUrls,
1061
+ extra_headers=extra_headers,
1062
+ extra_query=extra_query,
1063
+ timeout=timeout,
1064
+ )
1065
+
1066
+
1067
+ class InvitesResource:
1068
+ """`client.invites`"""
1069
+
1070
+ def __init__(self, client: SyncAPIClient) -> None:
1071
+ self._client = client
1072
+
1073
+ def get(
1074
+ self,
1075
+ token: str,
1076
+ *,
1077
+ extra_headers: Optional[Headers] = None,
1078
+ extra_query: Optional[Query] = None,
1079
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1080
+ ) -> InviteInfo:
1081
+ """打开邀请链接时看的:哪个工作区、什么角色、谁邀请的。不用登录。
1082
+
1083
+ `GET /api/v1/invites/{token}`
1084
+ """
1085
+ return self._client._call(
1086
+ "GET",
1087
+ f"/invites/{_p(token)}",
1088
+ cast=InviteInfo,
1089
+ extra_headers=extra_headers,
1090
+ extra_query=extra_query,
1091
+ timeout=timeout,
1092
+ )
1093
+
1094
+ def accept(
1095
+ self,
1096
+ token: str,
1097
+ *,
1098
+ extra_headers: Optional[Headers] = None,
1099
+ extra_query: Optional[Query] = None,
1100
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1101
+ ) -> Me:
1102
+ """接受邀请,加入工作区(已经在里面的不降角色)。返回加入后的 /me。
1103
+
1104
+ `POST /api/v1/invites/{token}/accept`
1105
+ """
1106
+ return self._client._call(
1107
+ "POST",
1108
+ f"/invites/{_p(token)}/accept",
1109
+ cast=Me,
1110
+ extra_headers=extra_headers,
1111
+ extra_query=extra_query,
1112
+ timeout=timeout,
1113
+ )
1114
+
1115
+ def list(
1116
+ self,
1117
+ ws: str,
1118
+ *,
1119
+ extra_headers: Optional[Headers] = None,
1120
+ extra_query: Optional[Query] = None,
1121
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1122
+ ) -> List[InviteView]:
1123
+ """`GET /api/v1/workspaces/{ws}/invites`"""
1124
+ return self._client._call(
1125
+ "GET",
1126
+ f"/workspaces/{_p(ws)}/invites",
1127
+ unwrap="invites",
1128
+ cast=List[InviteView],
1129
+ extra_headers=extra_headers,
1130
+ extra_query=extra_query,
1131
+ timeout=timeout,
1132
+ )
1133
+
1134
+ def create(
1135
+ self,
1136
+ ws: str,
1137
+ *,
1138
+ role: str,
1139
+ expires_in: Union[int, None, NotGiven] = NOT_GIVEN,
1140
+ extra_headers: Optional[Headers] = None,
1141
+ extra_query: Optional[Query] = None,
1142
+ extra_body: Optional[Body] = None,
1143
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1144
+ ) -> InviteView:
1145
+ """`POST /api/v1/workspaces/{ws}/invites`"""
1146
+ return self._client._call(
1147
+ "POST",
1148
+ f"/workspaces/{_p(ws)}/invites",
1149
+ body={"expires_in": expires_in, "role": role},
1150
+ extra_body=extra_body,
1151
+ cast=InviteView,
1152
+ extra_headers=extra_headers,
1153
+ extra_query=extra_query,
1154
+ timeout=timeout,
1155
+ )
1156
+
1157
+ def revoke(
1158
+ self,
1159
+ ws: str,
1160
+ token: str,
1161
+ *,
1162
+ extra_headers: Optional[Headers] = None,
1163
+ extra_query: Optional[Query] = None,
1164
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1165
+ ) -> None:
1166
+ """`DELETE /api/v1/workspaces/{ws}/invites/{token}`"""
1167
+ return self._client._call(
1168
+ "DELETE",
1169
+ f"/workspaces/{_p(ws)}/invites/{_p(token)}",
1170
+ cast=type(None),
1171
+ extra_headers=extra_headers,
1172
+ extra_query=extra_query,
1173
+ timeout=timeout,
1174
+ )
1175
+
1176
+
1177
+ class LinksResource:
1178
+ """`client.links`"""
1179
+
1180
+ def __init__(self, client: SyncAPIClient) -> None:
1181
+ self._client = client
1182
+
1183
+ def unfurl(
1184
+ self,
1185
+ *,
1186
+ url: str,
1187
+ extra_headers: Optional[Headers] = None,
1188
+ extra_query: Optional[Query] = None,
1189
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1190
+ ) -> UnfurlCard:
1191
+ """解析一个网址成卡片:上传的文件直接从库里给,本站的库给视图列表,别的网址去抓(有缓存,图片转存到 /media)。
1192
+
1193
+ `GET /api/v1/unfurl`
1194
+ """
1195
+ return self._client._call(
1196
+ "GET",
1197
+ "/unfurl",
1198
+ query={"url": url},
1199
+ cast=UnfurlCard,
1200
+ extra_headers=extra_headers,
1201
+ extra_query=extra_query,
1202
+ timeout=timeout,
1203
+ )
1204
+
1205
+
1206
+ class MeNotificationsResource:
1207
+ """`client.me.notifications`"""
1208
+
1209
+ def __init__(self, client: SyncAPIClient) -> None:
1210
+ self._client = client
1211
+
1212
+ def list(
1213
+ self,
1214
+ *,
1215
+ after: Union[int, NotGiven] = NOT_GIVEN,
1216
+ cursor: Union[str, NotGiven] = NOT_GIVEN,
1217
+ limit: Union[int, NotGiven] = NOT_GIVEN,
1218
+ extra_headers: Optional[Headers] = None,
1219
+ extra_query: Optional[Query] = None,
1220
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1221
+ ) -> CursorPage[InboxNotification]:
1222
+ """`GET /api/v1/me/notifications`"""
1223
+ return self._client._call_page(
1224
+ "GET",
1225
+ "/me/notifications",
1226
+ query={"after": after, "cursor": cursor, "limit": limit},
1227
+ model=Inbox,
1228
+ items="notifications",
1229
+ item=InboxNotification,
1230
+ extra_headers=extra_headers,
1231
+ extra_query=extra_query,
1232
+ timeout=timeout,
1233
+ )
1234
+
1235
+ def mark_read(
1236
+ self,
1237
+ *,
1238
+ all: Union[bool, NotGiven] = NOT_GIVEN,
1239
+ ids: Union[Sequence[int], None, NotGiven] = NOT_GIVEN,
1240
+ extra_headers: Optional[Headers] = None,
1241
+ extra_query: Optional[Query] = None,
1242
+ extra_body: Optional[Body] = None,
1243
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1244
+ ) -> ReadCount:
1245
+ """`POST /api/v1/me/notifications/read`"""
1246
+ return self._client._call(
1247
+ "POST",
1248
+ "/me/notifications/read",
1249
+ body={"all": all, "ids": ids},
1250
+ extra_body=extra_body,
1251
+ cast=ReadCount,
1252
+ extra_headers=extra_headers,
1253
+ extra_query=extra_query,
1254
+ timeout=timeout,
1255
+ )
1256
+
1257
+
1258
+ class MeResource:
1259
+ """`client.me`"""
1260
+
1261
+ def __init__(self, client: SyncAPIClient) -> None:
1262
+ self._client = client
1263
+
1264
+ @cached_property
1265
+ def notifications(self) -> MeNotificationsResource:
1266
+ return MeNotificationsResource(self._client)
1267
+
1268
+ def get(
1269
+ self,
1270
+ *,
1271
+ extra_headers: Optional[Headers] = None,
1272
+ extra_query: Optional[Query] = None,
1273
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1274
+ ) -> Me:
1275
+ """`GET /api/v1/me`"""
1276
+ return self._client._call(
1277
+ "GET",
1278
+ "/me",
1279
+ cast=Me,
1280
+ extra_headers=extra_headers,
1281
+ extra_query=extra_query,
1282
+ timeout=timeout,
1283
+ )
1284
+
1285
+ def update(
1286
+ self,
1287
+ *,
1288
+ avatar: Union[str, None, NotGiven] = NOT_GIVEN,
1289
+ locale: Union[str, None, NotGiven] = NOT_GIVEN,
1290
+ name: Union[str, None, NotGiven] = NOT_GIVEN,
1291
+ timezone: Union[str, None, NotGiven] = NOT_GIVEN,
1292
+ extra_headers: Optional[Headers] = None,
1293
+ extra_query: Optional[Query] = None,
1294
+ extra_body: Optional[Body] = None,
1295
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1296
+ ) -> Me:
1297
+ """`PATCH /api/v1/me`"""
1298
+ return self._client._call(
1299
+ "PATCH",
1300
+ "/me",
1301
+ body={"avatar": avatar, "locale": locale, "name": name, "timezone": timezone},
1302
+ extra_body=extra_body,
1303
+ cast=Me,
1304
+ extra_headers=extra_headers,
1305
+ extra_query=extra_query,
1306
+ timeout=timeout,
1307
+ )
1308
+
1309
+ def change_password(
1310
+ self,
1311
+ *,
1312
+ current: str,
1313
+ new: str,
1314
+ extra_headers: Optional[Headers] = None,
1315
+ extra_query: Optional[Query] = None,
1316
+ extra_body: Optional[Body] = None,
1317
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1318
+ ) -> None:
1319
+ """改密码(本地登录)。别的会话都退出,这次请求用的会话保留。
1320
+
1321
+ `POST /api/v1/me/password`
1322
+ """
1323
+ return self._client._call(
1324
+ "POST",
1325
+ "/me/password",
1326
+ body={"current": current, "new": new},
1327
+ extra_body=extra_body,
1328
+ cast=type(None),
1329
+ extra_headers=extra_headers,
1330
+ extra_query=extra_query,
1331
+ timeout=timeout,
1332
+ )
1333
+
1334
+
1335
+ class PagesBlocksResource:
1336
+ """`client.pages.blocks`"""
1337
+
1338
+ def __init__(self, client: SyncAPIClient) -> None:
1339
+ self._client = client
1340
+
1341
+ def insert(
1342
+ self,
1343
+ id: str,
1344
+ *,
1345
+ markdown: str,
1346
+ after: Union[str, None, NotGiven] = NOT_GIVEN,
1347
+ base: Union[str, None, NotGiven] = NOT_GIVEN,
1348
+ extra_headers: Optional[Headers] = None,
1349
+ extra_query: Optional[Query] = None,
1350
+ extra_body: Optional[Body] = None,
1351
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1352
+ ) -> BlockIds:
1353
+ """`POST /api/v1/pages/{id}/blocks`"""
1354
+ return self._client._call(
1355
+ "POST",
1356
+ f"/pages/{_p(id)}/blocks",
1357
+ body={"after": after, "base": base, "markdown": markdown},
1358
+ extra_body=extra_body,
1359
+ cast=BlockIds,
1360
+ extra_headers=extra_headers,
1361
+ extra_query=extra_query,
1362
+ timeout=timeout,
1363
+ )
1364
+
1365
+ def get(
1366
+ self,
1367
+ id: str,
1368
+ block_id: str,
1369
+ *,
1370
+ extra_headers: Optional[Headers] = None,
1371
+ extra_query: Optional[Query] = None,
1372
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1373
+ ) -> BlockContent:
1374
+ """`GET /api/v1/pages/{id}/blocks/{block_id}`"""
1375
+ return self._client._call(
1376
+ "GET",
1377
+ f"/pages/{_p(id)}/blocks/{_p(block_id)}",
1378
+ cast=BlockContent,
1379
+ extra_headers=extra_headers,
1380
+ extra_query=extra_query,
1381
+ timeout=timeout,
1382
+ )
1383
+
1384
+ def replace(
1385
+ self,
1386
+ id: str,
1387
+ block_id: str,
1388
+ *,
1389
+ markdown: str,
1390
+ after: Union[str, None, NotGiven] = NOT_GIVEN,
1391
+ base: Union[str, None, NotGiven] = NOT_GIVEN,
1392
+ extra_headers: Optional[Headers] = None,
1393
+ extra_query: Optional[Query] = None,
1394
+ extra_body: Optional[Body] = None,
1395
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1396
+ ) -> BlockIds:
1397
+ """`PUT /api/v1/pages/{id}/blocks/{block_id}`"""
1398
+ return self._client._call(
1399
+ "PUT",
1400
+ f"/pages/{_p(id)}/blocks/{_p(block_id)}",
1401
+ body={"after": after, "base": base, "markdown": markdown},
1402
+ extra_body=extra_body,
1403
+ cast=BlockIds,
1404
+ extra_headers=extra_headers,
1405
+ extra_query=extra_query,
1406
+ timeout=timeout,
1407
+ )
1408
+
1409
+ def delete(
1410
+ self,
1411
+ id: str,
1412
+ block_id: str,
1413
+ *,
1414
+ extra_headers: Optional[Headers] = None,
1415
+ extra_query: Optional[Query] = None,
1416
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1417
+ ) -> None:
1418
+ """`DELETE /api/v1/pages/{id}/blocks/{block_id}`"""
1419
+ return self._client._call(
1420
+ "DELETE",
1421
+ f"/pages/{_p(id)}/blocks/{_p(block_id)}",
1422
+ cast=type(None),
1423
+ extra_headers=extra_headers,
1424
+ extra_query=extra_query,
1425
+ timeout=timeout,
1426
+ )
1427
+
1428
+
1429
+ class PagesContentResource:
1430
+ """`client.pages.content`"""
1431
+
1432
+ def __init__(self, client: SyncAPIClient) -> None:
1433
+ self._client = client
1434
+
1435
+ def get(
1436
+ self,
1437
+ id: str,
1438
+ *,
1439
+ format: Union[str, NotGiven] = NOT_GIVEN,
1440
+ limit: Union[int, NotGiven] = NOT_GIVEN,
1441
+ extra_headers: Optional[Headers] = None,
1442
+ extra_query: Optional[Query] = None,
1443
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1444
+ ) -> Content:
1445
+ """`GET /api/v1/pages/{id}/content`"""
1446
+ return self._client._call(
1447
+ "GET",
1448
+ f"/pages/{_p(id)}/content",
1449
+ query={"format": format, "limit": limit},
1450
+ cast=Content,
1451
+ extra_headers=extra_headers,
1452
+ extra_query=extra_query,
1453
+ timeout=timeout,
1454
+ )
1455
+
1456
+ def replace(
1457
+ self,
1458
+ id: str,
1459
+ *,
1460
+ base: Union[str, None, NotGiven] = NOT_GIVEN,
1461
+ doc: Union[Union[DocNode, Dict[str, Any]], None, NotGiven] = NOT_GIVEN,
1462
+ markdown: Union[str, None, NotGiven] = NOT_GIVEN,
1463
+ extra_headers: Optional[Headers] = None,
1464
+ extra_query: Optional[Query] = None,
1465
+ extra_body: Optional[Body] = None,
1466
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1467
+ ) -> None:
1468
+ """`PUT /api/v1/pages/{id}/content`"""
1469
+ return self._client._call(
1470
+ "PUT",
1471
+ f"/pages/{_p(id)}/content",
1472
+ body={"base": base, "doc": doc, "markdown": markdown},
1473
+ extra_body=extra_body,
1474
+ cast=type(None),
1475
+ extra_headers=extra_headers,
1476
+ extra_query=extra_query,
1477
+ timeout=timeout,
1478
+ )
1479
+
1480
+
1481
+ class PagesShareResource:
1482
+ """`client.pages.share`"""
1483
+
1484
+ def __init__(self, client: SyncAPIClient) -> None:
1485
+ self._client = client
1486
+
1487
+ def get(
1488
+ self,
1489
+ id: str,
1490
+ *,
1491
+ extra_headers: Optional[Headers] = None,
1492
+ extra_query: Optional[Query] = None,
1493
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1494
+ ) -> Optional[ShareView]:
1495
+ """`GET /api/v1/pages/{id}/share`"""
1496
+ return self._client._call_or_none(
1497
+ "GET",
1498
+ f"/pages/{_p(id)}/share",
1499
+ cast=ShareView,
1500
+ extra_headers=extra_headers,
1501
+ extra_query=extra_query,
1502
+ timeout=timeout,
1503
+ )
1504
+
1505
+ def enable(
1506
+ self,
1507
+ id: str,
1508
+ *,
1509
+ include_children: Union[bool, NotGiven] = NOT_GIVEN,
1510
+ indexable: Union[bool, NotGiven] = NOT_GIVEN,
1511
+ extra_headers: Optional[Headers] = None,
1512
+ extra_query: Optional[Query] = None,
1513
+ extra_body: Optional[Body] = None,
1514
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1515
+ ) -> ShareView:
1516
+ """打开分享或改设置(已经分享了的,链接不变)。
1517
+
1518
+ `POST /api/v1/pages/{id}/share`
1519
+ """
1520
+ return self._client._call(
1521
+ "POST",
1522
+ f"/pages/{_p(id)}/share",
1523
+ body={"include_children": include_children, "indexable": indexable},
1524
+ extra_body=extra_body,
1525
+ cast=ShareView,
1526
+ extra_headers=extra_headers,
1527
+ extra_query=extra_query,
1528
+ timeout=timeout,
1529
+ )
1530
+
1531
+ def disable(
1532
+ self,
1533
+ id: str,
1534
+ *,
1535
+ extra_headers: Optional[Headers] = None,
1536
+ extra_query: Optional[Query] = None,
1537
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1538
+ ) -> None:
1539
+ """关掉分享,链接马上失效。
1540
+
1541
+ `DELETE /api/v1/pages/{id}/share`
1542
+ """
1543
+ return self._client._call(
1544
+ "DELETE",
1545
+ f"/pages/{_p(id)}/share",
1546
+ cast=type(None),
1547
+ extra_headers=extra_headers,
1548
+ extra_query=extra_query,
1549
+ timeout=timeout,
1550
+ )
1551
+
1552
+
1553
+ class PagesVersionsResource:
1554
+ """`client.pages.versions`"""
1555
+
1556
+ def __init__(self, client: SyncAPIClient) -> None:
1557
+ self._client = client
1558
+
1559
+ def list(
1560
+ self,
1561
+ id: str,
1562
+ *,
1563
+ limit: Union[int, NotGiven] = NOT_GIVEN,
1564
+ cursor: Union[str, NotGiven] = NOT_GIVEN,
1565
+ extra_headers: Optional[Headers] = None,
1566
+ extra_query: Optional[Query] = None,
1567
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1568
+ ) -> CursorPage[VersionMeta]:
1569
+ """`GET /api/v1/pages/{id}/versions`"""
1570
+ return self._client._call_page(
1571
+ "GET",
1572
+ f"/pages/{_p(id)}/versions",
1573
+ query={"limit": limit, "cursor": cursor},
1574
+ model=VersionList,
1575
+ items="versions",
1576
+ item=VersionMeta,
1577
+ extra_headers=extra_headers,
1578
+ extra_query=extra_query,
1579
+ timeout=timeout,
1580
+ )
1581
+
1582
+ def create(
1583
+ self,
1584
+ id: str,
1585
+ *,
1586
+ label: Union[str, None, NotGiven] = NOT_GIVEN,
1587
+ extra_headers: Optional[Headers] = None,
1588
+ extra_query: Optional[Query] = None,
1589
+ extra_body: Optional[Body] = None,
1590
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1591
+ ) -> VersionMeta:
1592
+ """`POST /api/v1/pages/{id}/versions`"""
1593
+ return self._client._call(
1594
+ "POST",
1595
+ f"/pages/{_p(id)}/versions",
1596
+ body={"label": label},
1597
+ extra_body=extra_body,
1598
+ cast=VersionMeta,
1599
+ extra_headers=extra_headers,
1600
+ extra_query=extra_query,
1601
+ timeout=timeout,
1602
+ )
1603
+
1604
+ def get(
1605
+ self,
1606
+ id: str,
1607
+ v: int,
1608
+ *,
1609
+ extra_headers: Optional[Headers] = None,
1610
+ extra_query: Optional[Query] = None,
1611
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1612
+ ) -> VersionContent:
1613
+ """`GET /api/v1/pages/{id}/versions/{v}`"""
1614
+ return self._client._call(
1615
+ "GET",
1616
+ f"/pages/{_p(id)}/versions/{_p(v)}",
1617
+ cast=VersionContent,
1618
+ extra_headers=extra_headers,
1619
+ extra_query=extra_query,
1620
+ timeout=timeout,
1621
+ )
1622
+
1623
+ def diff(
1624
+ self,
1625
+ id: str,
1626
+ v: int,
1627
+ *,
1628
+ to: Union[str, NotGiven] = NOT_GIVEN,
1629
+ extra_headers: Optional[Headers] = None,
1630
+ extra_query: Optional[Query] = None,
1631
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1632
+ ) -> VersionDiff:
1633
+ """`GET /api/v1/pages/{id}/versions/{v}/diff`"""
1634
+ return self._client._call(
1635
+ "GET",
1636
+ f"/pages/{_p(id)}/versions/{_p(v)}/diff",
1637
+ query={"to": to},
1638
+ cast=VersionDiff,
1639
+ extra_headers=extra_headers,
1640
+ extra_query=extra_query,
1641
+ timeout=timeout,
1642
+ )
1643
+
1644
+ def restore(
1645
+ self,
1646
+ id: str,
1647
+ v: int,
1648
+ *,
1649
+ extra_headers: Optional[Headers] = None,
1650
+ extra_query: Optional[Query] = None,
1651
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1652
+ ) -> Restored:
1653
+ """`POST /api/v1/pages/{id}/versions/{v}/restore`"""
1654
+ return self._client._call(
1655
+ "POST",
1656
+ f"/pages/{_p(id)}/versions/{_p(v)}/restore",
1657
+ cast=Restored,
1658
+ extra_headers=extra_headers,
1659
+ extra_query=extra_query,
1660
+ timeout=timeout,
1661
+ )
1662
+
1663
+
1664
+ class PagesResource:
1665
+ """`client.pages`"""
1666
+
1667
+ def __init__(self, client: SyncAPIClient) -> None:
1668
+ self._client = client
1669
+
1670
+ @cached_property
1671
+ def blocks(self) -> PagesBlocksResource:
1672
+ return PagesBlocksResource(self._client)
1673
+
1674
+ @cached_property
1675
+ def content(self) -> PagesContentResource:
1676
+ return PagesContentResource(self._client)
1677
+
1678
+ @cached_property
1679
+ def share(self) -> PagesShareResource:
1680
+ return PagesShareResource(self._client)
1681
+
1682
+ @cached_property
1683
+ def versions(self) -> PagesVersionsResource:
1684
+ return PagesVersionsResource(self._client)
1685
+
1686
+ def list(
1687
+ self,
1688
+ ws: str,
1689
+ *,
1690
+ extra_headers: Optional[Headers] = None,
1691
+ extra_query: Optional[Query] = None,
1692
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1693
+ ) -> List[Page]:
1694
+ """`GET /api/v1/workspaces/{ws}/pages`"""
1695
+ return self._client._call(
1696
+ "GET",
1697
+ f"/workspaces/{_p(ws)}/pages",
1698
+ unwrap="pages",
1699
+ cast=List[Page],
1700
+ extra_headers=extra_headers,
1701
+ extra_query=extra_query,
1702
+ timeout=timeout,
1703
+ )
1704
+
1705
+ def create(
1706
+ self,
1707
+ ws: str,
1708
+ *,
1709
+ after: Union[str, None, NotGiven] = NOT_GIVEN,
1710
+ icon: Union[str, None, NotGiven] = NOT_GIVEN,
1711
+ parent_id: Union[str, None, NotGiven] = NOT_GIVEN,
1712
+ title: Union[str, None, NotGiven] = NOT_GIVEN,
1713
+ markdown: Union[str, NotGiven] = NOT_GIVEN,
1714
+ extra_headers: Optional[Headers] = None,
1715
+ extra_query: Optional[Query] = None,
1716
+ extra_body: Optional[Body] = None,
1717
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1718
+ ) -> Page:
1719
+ """`POST /api/v1/workspaces/{ws}/pages`"""
1720
+ page = self._client._call(
1721
+ "POST",
1722
+ f"/workspaces/{_p(ws)}/pages",
1723
+ body={"after": after, "icon": icon, "parent_id": parent_id, "title": title},
1724
+ extra_body=extra_body,
1725
+ cast=Page,
1726
+ extra_headers=extra_headers,
1727
+ extra_query=extra_query,
1728
+ timeout=timeout,
1729
+ )
1730
+ if not isinstance(markdown, NotGiven):
1731
+ # 两步:先建页面,再写正文
1732
+ self._client._call(
1733
+ "PUT",
1734
+ f"/pages/{_p(page.id)}/content",
1735
+ body={"markdown": markdown},
1736
+ cast=type(None),
1737
+ extra_headers=extra_headers,
1738
+ extra_query=extra_query,
1739
+ timeout=timeout,
1740
+ )
1741
+ return page
1742
+
1743
+ def get(
1744
+ self,
1745
+ id: str,
1746
+ *,
1747
+ extra_headers: Optional[Headers] = None,
1748
+ extra_query: Optional[Query] = None,
1749
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1750
+ ) -> Page:
1751
+ """`GET /api/v1/pages/{id}`"""
1752
+ return self._client._call(
1753
+ "GET",
1754
+ f"/pages/{_p(id)}",
1755
+ cast=Page,
1756
+ extra_headers=extra_headers,
1757
+ extra_query=extra_query,
1758
+ timeout=timeout,
1759
+ )
1760
+
1761
+ def update(
1762
+ self,
1763
+ id: str,
1764
+ *,
1765
+ after: Union[str, None, NotGiven] = NOT_GIVEN,
1766
+ icon: Union[str, None, NotGiven] = NOT_GIVEN,
1767
+ parent_id: Union[str, None, NotGiven] = NOT_GIVEN,
1768
+ title: Union[str, None, NotGiven] = NOT_GIVEN,
1769
+ extra_headers: Optional[Headers] = None,
1770
+ extra_query: Optional[Query] = None,
1771
+ extra_body: Optional[Body] = None,
1772
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1773
+ ) -> Page:
1774
+ """`PATCH /api/v1/pages/{id}`"""
1775
+ return self._client._call(
1776
+ "PATCH",
1777
+ f"/pages/{_p(id)}",
1778
+ body={"after": after, "icon": icon, "parent_id": parent_id, "title": title},
1779
+ extra_body=extra_body,
1780
+ cast=Page,
1781
+ extra_headers=extra_headers,
1782
+ extra_query=extra_query,
1783
+ timeout=timeout,
1784
+ )
1785
+
1786
+ def delete(
1787
+ self,
1788
+ id: str,
1789
+ *,
1790
+ extra_headers: Optional[Headers] = None,
1791
+ extra_query: Optional[Query] = None,
1792
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1793
+ ) -> Deleted:
1794
+ """`DELETE /api/v1/pages/{id}`"""
1795
+ return self._client._call(
1796
+ "DELETE",
1797
+ f"/pages/{_p(id)}",
1798
+ cast=Deleted,
1799
+ extra_headers=extra_headers,
1800
+ extra_query=extra_query,
1801
+ timeout=timeout,
1802
+ )
1803
+
1804
+ def authors(
1805
+ self,
1806
+ id: str,
1807
+ *,
1808
+ extra_headers: Optional[Headers] = None,
1809
+ extra_query: Optional[Query] = None,
1810
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1811
+ ) -> Dict[str, AuthorRef]:
1812
+ """`GET /api/v1/pages/{id}/authors`"""
1813
+ return self._client._call(
1814
+ "GET",
1815
+ f"/pages/{_p(id)}/authors",
1816
+ unwrap="clients",
1817
+ cast=Dict[str, AuthorRef],
1818
+ extra_headers=extra_headers,
1819
+ extra_query=extra_query,
1820
+ timeout=timeout,
1821
+ )
1822
+
1823
+
1824
+ class ThreadsResource:
1825
+ """`client.threads`"""
1826
+
1827
+ def __init__(self, client: SyncAPIClient) -> None:
1828
+ self._client = client
1829
+
1830
+ def list(
1831
+ self,
1832
+ id: str,
1833
+ *,
1834
+ resolved: Union[str, NotGiven] = NOT_GIVEN,
1835
+ extra_headers: Optional[Headers] = None,
1836
+ extra_query: Optional[Query] = None,
1837
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1838
+ ) -> List[ThreadView]:
1839
+ """`GET /api/v1/pages/{id}/comments`"""
1840
+ return self._client._call(
1841
+ "GET",
1842
+ f"/pages/{_p(id)}/comments",
1843
+ query={"resolved": resolved},
1844
+ unwrap="threads",
1845
+ cast=List[ThreadView],
1846
+ extra_headers=extra_headers,
1847
+ extra_query=extra_query,
1848
+ timeout=timeout,
1849
+ )
1850
+
1851
+ def create(
1852
+ self,
1853
+ id: str,
1854
+ *,
1855
+ body: str,
1856
+ anchor: Union[Union[Anchor, Dict[str, Any]], None, NotGiven] = NOT_GIVEN,
1857
+ notify: Union[Notify, None, NotGiven] = NOT_GIVEN,
1858
+ extra_headers: Optional[Headers] = None,
1859
+ extra_query: Optional[Query] = None,
1860
+ extra_body: Optional[Body] = None,
1861
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1862
+ ) -> ThreadView:
1863
+ """`POST /api/v1/pages/{id}/comments`"""
1864
+ return self._client._call(
1865
+ "POST",
1866
+ f"/pages/{_p(id)}/comments",
1867
+ body={"anchor": anchor, "body": body, "notify": notify},
1868
+ extra_body=extra_body,
1869
+ cast=ThreadView,
1870
+ extra_headers=extra_headers,
1871
+ extra_query=extra_query,
1872
+ timeout=timeout,
1873
+ )
1874
+
1875
+ def update(
1876
+ self,
1877
+ id: str,
1878
+ *,
1879
+ resolved: bool,
1880
+ extra_headers: Optional[Headers] = None,
1881
+ extra_query: Optional[Query] = None,
1882
+ extra_body: Optional[Body] = None,
1883
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1884
+ ) -> ThreadView:
1885
+ """`PATCH /api/v1/threads/{id}`"""
1886
+ return self._client._call(
1887
+ "PATCH",
1888
+ f"/threads/{_p(id)}",
1889
+ body={"resolved": resolved},
1890
+ extra_body=extra_body,
1891
+ cast=ThreadView,
1892
+ extra_headers=extra_headers,
1893
+ extra_query=extra_query,
1894
+ timeout=timeout,
1895
+ )
1896
+
1897
+ def reply(
1898
+ self,
1899
+ id: str,
1900
+ *,
1901
+ body: str,
1902
+ notify: Union[Notify, None, NotGiven] = NOT_GIVEN,
1903
+ extra_headers: Optional[Headers] = None,
1904
+ extra_query: Optional[Query] = None,
1905
+ extra_body: Optional[Body] = None,
1906
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1907
+ ) -> CommentView:
1908
+ """`POST /api/v1/threads/{id}/comments`"""
1909
+ return self._client._call(
1910
+ "POST",
1911
+ f"/threads/{_p(id)}/comments",
1912
+ body={"body": body, "notify": notify},
1913
+ extra_body=extra_body,
1914
+ cast=CommentView,
1915
+ extra_headers=extra_headers,
1916
+ extra_query=extra_query,
1917
+ timeout=timeout,
1918
+ )
1919
+
1920
+
1921
+ class TrashResource:
1922
+ """`client.trash`"""
1923
+
1924
+ def __init__(self, client: SyncAPIClient) -> None:
1925
+ self._client = client
1926
+
1927
+ def list(
1928
+ self,
1929
+ ws: str,
1930
+ *,
1931
+ limit: Union[int, NotGiven] = NOT_GIVEN,
1932
+ cursor: Union[str, NotGiven] = NOT_GIVEN,
1933
+ extra_headers: Optional[Headers] = None,
1934
+ extra_query: Optional[Query] = None,
1935
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1936
+ ) -> CursorPage[TrashItem]:
1937
+ """`GET /api/v1/workspaces/{ws}/trash`"""
1938
+ return self._client._call_page(
1939
+ "GET",
1940
+ f"/workspaces/{_p(ws)}/trash",
1941
+ query={"limit": limit, "cursor": cursor},
1942
+ model=TrashList,
1943
+ items="items",
1944
+ item=TrashItem,
1945
+ extra_headers=extra_headers,
1946
+ extra_query=extra_query,
1947
+ timeout=timeout,
1948
+ )
1949
+
1950
+ def restore(
1951
+ self,
1952
+ id: str,
1953
+ *,
1954
+ extra_headers: Optional[Headers] = None,
1955
+ extra_query: Optional[Query] = None,
1956
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1957
+ ) -> RestoredPage:
1958
+ """`POST /api/v1/trash/{id}/restore`"""
1959
+ return self._client._call(
1960
+ "POST",
1961
+ f"/trash/{_p(id)}/restore",
1962
+ cast=RestoredPage,
1963
+ extra_headers=extra_headers,
1964
+ extra_query=extra_query,
1965
+ timeout=timeout,
1966
+ )
1967
+
1968
+ def purge(
1969
+ self,
1970
+ id: str,
1971
+ *,
1972
+ extra_headers: Optional[Headers] = None,
1973
+ extra_query: Optional[Query] = None,
1974
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
1975
+ ) -> None:
1976
+ """`DELETE /api/v1/trash/{id}`"""
1977
+ return self._client._call(
1978
+ "DELETE",
1979
+ f"/trash/{_p(id)}",
1980
+ cast=type(None),
1981
+ extra_headers=extra_headers,
1982
+ extra_query=extra_query,
1983
+ timeout=timeout,
1984
+ )
1985
+
1986
+
1987
+ class WorkspacesMembersResource:
1988
+ """`client.workspaces.members`"""
1989
+
1990
+ def __init__(self, client: SyncAPIClient) -> None:
1991
+ self._client = client
1992
+
1993
+ def list(
1994
+ self,
1995
+ ws: str,
1996
+ *,
1997
+ extra_headers: Optional[Headers] = None,
1998
+ extra_query: Optional[Query] = None,
1999
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2000
+ ) -> MemberList:
2001
+ """`GET /api/v1/workspaces/{ws}/members`"""
2002
+ return self._client._call(
2003
+ "GET",
2004
+ f"/workspaces/{_p(ws)}/members",
2005
+ cast=MemberList,
2006
+ extra_headers=extra_headers,
2007
+ extra_query=extra_query,
2008
+ timeout=timeout,
2009
+ )
2010
+
2011
+ def set_role(
2012
+ self,
2013
+ ws: str,
2014
+ user: str,
2015
+ *,
2016
+ role: str,
2017
+ extra_headers: Optional[Headers] = None,
2018
+ extra_query: Optional[Query] = None,
2019
+ extra_body: Optional[Body] = None,
2020
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2021
+ ) -> MemberRole:
2022
+ """`PATCH /api/v1/workspaces/{ws}/members/{user}`"""
2023
+ return self._client._call(
2024
+ "PATCH",
2025
+ f"/workspaces/{_p(ws)}/members/{_p(user)}",
2026
+ body={"role": role},
2027
+ extra_body=extra_body,
2028
+ cast=MemberRole,
2029
+ extra_headers=extra_headers,
2030
+ extra_query=extra_query,
2031
+ timeout=timeout,
2032
+ )
2033
+
2034
+ def remove(
2035
+ self,
2036
+ ws: str,
2037
+ user: str,
2038
+ *,
2039
+ extra_headers: Optional[Headers] = None,
2040
+ extra_query: Optional[Query] = None,
2041
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2042
+ ) -> None:
2043
+ """`DELETE /api/v1/workspaces/{ws}/members/{user}`"""
2044
+ return self._client._call(
2045
+ "DELETE",
2046
+ f"/workspaces/{_p(ws)}/members/{_p(user)}",
2047
+ cast=type(None),
2048
+ extra_headers=extra_headers,
2049
+ extra_query=extra_query,
2050
+ timeout=timeout,
2051
+ )
2052
+
2053
+
2054
+ class WorkspacesResource:
2055
+ """`client.workspaces`"""
2056
+
2057
+ def __init__(self, client: SyncAPIClient) -> None:
2058
+ self._client = client
2059
+
2060
+ @cached_property
2061
+ def members(self) -> WorkspacesMembersResource:
2062
+ return WorkspacesMembersResource(self._client)
2063
+
2064
+ def update(
2065
+ self,
2066
+ ws: str,
2067
+ *,
2068
+ icon: Union[str, None, NotGiven] = NOT_GIVEN,
2069
+ name: Union[str, None, NotGiven] = NOT_GIVEN,
2070
+ extra_headers: Optional[Headers] = None,
2071
+ extra_query: Optional[Query] = None,
2072
+ extra_body: Optional[Body] = None,
2073
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2074
+ ) -> Workspace:
2075
+ """改工作区的名字、图标(admin 以上)。
2076
+
2077
+ `PATCH /api/v1/workspaces/{ws}`
2078
+ """
2079
+ return self._client._call(
2080
+ "PATCH",
2081
+ f"/workspaces/{_p(ws)}",
2082
+ body={"icon": icon, "name": name},
2083
+ extra_body=extra_body,
2084
+ cast=Workspace,
2085
+ extra_headers=extra_headers,
2086
+ extra_query=extra_query,
2087
+ timeout=timeout,
2088
+ )
2089
+
2090
+ def events(
2091
+ self,
2092
+ ws: str,
2093
+ *,
2094
+ extra_headers: Optional[Headers] = None,
2095
+ extra_query: Optional[Query] = None,
2096
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2097
+ ) -> EventStream:
2098
+ """SSE:工作区的实时事件,事件名和数据见 webhooks(page.created、db.changed……)。慢了会收到 resync。
2099
+
2100
+ `GET /api/v1/workspaces/{ws}/events`
2101
+ """
2102
+ return self._client._stream(
2103
+ f"/workspaces/{_p(ws)}/events",
2104
+ kind="workspace",
2105
+ extra_headers=extra_headers,
2106
+ extra_query=extra_query,
2107
+ timeout=timeout,
2108
+ )
2109
+
2110
+
2111
+ class SyncResources(SyncAPIClient):
2112
+ """客户端上的资源和方法(生成的);Client / AsyncClient 继承它。"""
2113
+
2114
+ @cached_property
2115
+ def agent(self) -> AgentResource:
2116
+ return AgentResource(self)
2117
+
2118
+ @cached_property
2119
+ def agents(self) -> AgentsResource:
2120
+ return AgentsResource(self)
2121
+
2122
+ @cached_property
2123
+ def auth(self) -> AuthResource:
2124
+ return AuthResource(self)
2125
+
2126
+ @cached_property
2127
+ def comments(self) -> CommentsResource:
2128
+ return CommentsResource(self)
2129
+
2130
+ @cached_property
2131
+ def databases(self) -> DatabasesResource:
2132
+ return DatabasesResource(self)
2133
+
2134
+ @cached_property
2135
+ def files(self) -> FilesResource:
2136
+ return FilesResource(self)
2137
+
2138
+ @cached_property
2139
+ def invites(self) -> InvitesResource:
2140
+ return InvitesResource(self)
2141
+
2142
+ @cached_property
2143
+ def links(self) -> LinksResource:
2144
+ return LinksResource(self)
2145
+
2146
+ @cached_property
2147
+ def me(self) -> MeResource:
2148
+ return MeResource(self)
2149
+
2150
+ @cached_property
2151
+ def pages(self) -> PagesResource:
2152
+ return PagesResource(self)
2153
+
2154
+ @cached_property
2155
+ def threads(self) -> ThreadsResource:
2156
+ return ThreadsResource(self)
2157
+
2158
+ @cached_property
2159
+ def trash(self) -> TrashResource:
2160
+ return TrashResource(self)
2161
+
2162
+ @cached_property
2163
+ def workspaces(self) -> WorkspacesResource:
2164
+ return WorkspacesResource(self)
2165
+
2166
+ def search(
2167
+ self,
2168
+ ws: str,
2169
+ *,
2170
+ q: str,
2171
+ limit: Union[int, NotGiven] = NOT_GIVEN,
2172
+ kind: Union[str, NotGiven] = NOT_GIVEN,
2173
+ per: Union[str, NotGiven] = NOT_GIVEN,
2174
+ extra_headers: Optional[Headers] = None,
2175
+ extra_query: Optional[Query] = None,
2176
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2177
+ ) -> List[SearchResult]:
2178
+ """`GET /api/v1/workspaces/{ws}/search`"""
2179
+ return self._call(
2180
+ "GET",
2181
+ f"/workspaces/{_p(ws)}/search",
2182
+ query={"q": q, "limit": limit, "kind": kind, "per": per},
2183
+ unwrap="results",
2184
+ cast=List[SearchResult],
2185
+ extra_headers=extra_headers,
2186
+ extra_query=extra_query,
2187
+ timeout=timeout,
2188
+ )
2189
+
2190
+
2191
+ class AsyncAgentNotificationsResource:
2192
+ """`client.agent.notifications`"""
2193
+
2194
+ def __init__(self, client: AsyncAPIClient) -> None:
2195
+ self._client = client
2196
+
2197
+ def list(
2198
+ self,
2199
+ *,
2200
+ after: Union[int, NotGiven] = NOT_GIVEN,
2201
+ cursor: Union[str, NotGiven] = NOT_GIVEN,
2202
+ limit: Union[int, NotGiven] = NOT_GIVEN,
2203
+ wait: Union[int, NotGiven] = NOT_GIVEN,
2204
+ extra_headers: Optional[Headers] = None,
2205
+ extra_query: Optional[Query] = None,
2206
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2207
+ ) -> AsyncPaginator[AgentNotification]:
2208
+ """Agent 取通知(长轮询):没有新的就等 wait 秒。不给 after / cursor 就是还没处理(ack)的。只有 Agent 能调。
2209
+
2210
+ `GET /api/v1/agent/notifications`
2211
+ """
2212
+ return self._client._call_page(
2213
+ "GET",
2214
+ "/agent/notifications",
2215
+ query={"after": after, "cursor": cursor, "limit": limit, "wait": wait},
2216
+ model=AgentNotes,
2217
+ items="notifications",
2218
+ item=AgentNotification,
2219
+ extra_headers=extra_headers,
2220
+ extra_query=extra_query,
2221
+ timeout=timeout,
2222
+ )
2223
+
2224
+ async def ack(
2225
+ self,
2226
+ *,
2227
+ ids: Union[Sequence[int], NotGiven] = NOT_GIVEN,
2228
+ upto: Union[int, None, NotGiven] = NOT_GIVEN,
2229
+ extra_headers: Optional[Headers] = None,
2230
+ extra_query: Optional[Query] = None,
2231
+ extra_body: Optional[Body] = None,
2232
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2233
+ ) -> Acked:
2234
+ """`POST /api/v1/agent/notifications/ack`"""
2235
+ return await self._client._call(
2236
+ "POST",
2237
+ "/agent/notifications/ack",
2238
+ body={"ids": ids, "upto": upto},
2239
+ extra_body=extra_body,
2240
+ cast=Acked,
2241
+ extra_headers=extra_headers,
2242
+ extra_query=extra_query,
2243
+ timeout=timeout,
2244
+ )
2245
+
2246
+ def stream(
2247
+ self,
2248
+ *,
2249
+ after: Union[int, NotGiven] = NOT_GIVEN,
2250
+ cursor: Union[str, NotGiven] = NOT_GIVEN,
2251
+ extra_headers: Optional[Headers] = None,
2252
+ extra_query: Optional[Query] = None,
2253
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2254
+ ) -> AsyncEventStream:
2255
+ """SSE:先补发游标之后的(`?after=` / `?cursor=` 或 `Last-Event-ID` 头;都没有就是没处理的),再实时推。每条是 `event: notification`,`id` 是通知编号,`data` 是 AgentNotification。每 25 秒一个注释行保活。只有 Agent 能调。
2256
+
2257
+ `GET /api/v1/agent/notifications/stream`
2258
+ """
2259
+ return self._client._stream(
2260
+ "/agent/notifications/stream",
2261
+ query={"after": after, "cursor": cursor},
2262
+ kind="agent",
2263
+ extra_headers=extra_headers,
2264
+ extra_query=extra_query,
2265
+ timeout=timeout,
2266
+ )
2267
+
2268
+
2269
+ class AsyncAgentResource:
2270
+ """`client.agent`"""
2271
+
2272
+ def __init__(self, client: AsyncAPIClient) -> None:
2273
+ self._client = client
2274
+
2275
+ @cached_property
2276
+ def notifications(self) -> AsyncAgentNotificationsResource:
2277
+ return AsyncAgentNotificationsResource(self._client)
2278
+
2279
+
2280
+ class AsyncAgentsResource:
2281
+ """`client.agents`"""
2282
+
2283
+ def __init__(self, client: AsyncAPIClient) -> None:
2284
+ self._client = client
2285
+
2286
+ async def list(
2287
+ self,
2288
+ ws: str,
2289
+ *,
2290
+ extra_headers: Optional[Headers] = None,
2291
+ extra_query: Optional[Query] = None,
2292
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2293
+ ) -> List[AgentView]:
2294
+ """`GET /api/v1/workspaces/{ws}/agents`"""
2295
+ return await self._client._call(
2296
+ "GET",
2297
+ f"/workspaces/{_p(ws)}/agents",
2298
+ unwrap="agents",
2299
+ cast=List[AgentView],
2300
+ extra_headers=extra_headers,
2301
+ extra_query=extra_query,
2302
+ timeout=timeout,
2303
+ )
2304
+
2305
+ async def create(
2306
+ self,
2307
+ ws: str,
2308
+ *,
2309
+ name: str,
2310
+ scope: str,
2311
+ about: Union[str, None, NotGiven] = NOT_GIVEN,
2312
+ webhook: Union[str, None, NotGiven] = NOT_GIVEN,
2313
+ extra_headers: Optional[Headers] = None,
2314
+ extra_query: Optional[Query] = None,
2315
+ extra_body: Optional[Body] = None,
2316
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2317
+ ) -> CreatedAgent:
2318
+ """`POST /api/v1/workspaces/{ws}/agents`"""
2319
+ return await self._client._call(
2320
+ "POST",
2321
+ f"/workspaces/{_p(ws)}/agents",
2322
+ body={"about": about, "name": name, "scope": scope, "webhook": webhook},
2323
+ extra_body=extra_body,
2324
+ cast=CreatedAgent,
2325
+ extra_headers=extra_headers,
2326
+ extra_query=extra_query,
2327
+ timeout=timeout,
2328
+ )
2329
+
2330
+ async def update(
2331
+ self,
2332
+ id: str,
2333
+ *,
2334
+ about: Union[str, None, NotGiven] = NOT_GIVEN,
2335
+ locale: Union[str, None, NotGiven] = NOT_GIVEN,
2336
+ name: Union[str, None, NotGiven] = NOT_GIVEN,
2337
+ scope: Union[str, None, NotGiven] = NOT_GIVEN,
2338
+ webhook: Union[str, None, NotGiven] = NOT_GIVEN,
2339
+ extra_headers: Optional[Headers] = None,
2340
+ extra_query: Optional[Query] = None,
2341
+ extra_body: Optional[Body] = None,
2342
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2343
+ ) -> Agent:
2344
+ """`PATCH /api/v1/agents/{id}`"""
2345
+ return await self._client._call(
2346
+ "PATCH",
2347
+ f"/agents/{_p(id)}",
2348
+ body={"about": about, "locale": locale, "name": name, "scope": scope, "webhook": webhook},
2349
+ extra_body=extra_body,
2350
+ cast=Agent,
2351
+ extra_headers=extra_headers,
2352
+ extra_query=extra_query,
2353
+ timeout=timeout,
2354
+ )
2355
+
2356
+ async def revoke(
2357
+ self,
2358
+ id: str,
2359
+ *,
2360
+ extra_headers: Optional[Headers] = None,
2361
+ extra_query: Optional[Query] = None,
2362
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2363
+ ) -> Agent:
2364
+ """撤销:token 马上失效,返回撤销后的 Agent(带 revoked_at)。
2365
+
2366
+ `DELETE /api/v1/agents/{id}`
2367
+ """
2368
+ return await self._client._call(
2369
+ "DELETE",
2370
+ f"/agents/{_p(id)}",
2371
+ cast=Agent,
2372
+ extra_headers=extra_headers,
2373
+ extra_query=extra_query,
2374
+ timeout=timeout,
2375
+ )
2376
+
2377
+ async def rotate_token(
2378
+ self,
2379
+ id: str,
2380
+ *,
2381
+ extra_headers: Optional[Headers] = None,
2382
+ extra_query: Optional[Query] = None,
2383
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2384
+ ) -> NewToken:
2385
+ """`POST /api/v1/agents/{id}/token`"""
2386
+ return await self._client._call(
2387
+ "POST",
2388
+ f"/agents/{_p(id)}/token",
2389
+ cast=NewToken,
2390
+ extra_headers=extra_headers,
2391
+ extra_query=extra_query,
2392
+ timeout=timeout,
2393
+ )
2394
+
2395
+ async def rotate_webhook_secret(
2396
+ self,
2397
+ id: str,
2398
+ *,
2399
+ extra_headers: Optional[Headers] = None,
2400
+ extra_query: Optional[Query] = None,
2401
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2402
+ ) -> NewSecret:
2403
+ """`POST /api/v1/agents/{id}/webhook-secret`"""
2404
+ return await self._client._call(
2405
+ "POST",
2406
+ f"/agents/{_p(id)}/webhook-secret",
2407
+ cast=NewSecret,
2408
+ extra_headers=extra_headers,
2409
+ extra_query=extra_query,
2410
+ timeout=timeout,
2411
+ )
2412
+
2413
+
2414
+ class AsyncAuthResource:
2415
+ """`client.auth`"""
2416
+
2417
+ def __init__(self, client: AsyncAPIClient) -> None:
2418
+ self._client = client
2419
+
2420
+ async def config(
2421
+ self,
2422
+ *,
2423
+ extra_headers: Optional[Headers] = None,
2424
+ extra_query: Optional[Query] = None,
2425
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2426
+ ) -> AuthConfigBody:
2427
+ """`GET /api/v1/auth/config`"""
2428
+ return await self._client._call(
2429
+ "GET",
2430
+ "/auth/config",
2431
+ cast=AuthConfigBody,
2432
+ extra_headers=extra_headers,
2433
+ extra_query=extra_query,
2434
+ timeout=timeout,
2435
+ )
2436
+
2437
+ async def login(
2438
+ self,
2439
+ *,
2440
+ email: str,
2441
+ password: str,
2442
+ extra_headers: Optional[Headers] = None,
2443
+ extra_query: Optional[Query] = None,
2444
+ extra_body: Optional[Body] = None,
2445
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2446
+ ) -> Me:
2447
+ """`POST /api/v1/auth/login`"""
2448
+ return await self._client._call(
2449
+ "POST",
2450
+ "/auth/login",
2451
+ body={"email": email, "password": password},
2452
+ extra_body=extra_body,
2453
+ cast=Me,
2454
+ extra_headers=extra_headers,
2455
+ extra_query=extra_query,
2456
+ timeout=timeout,
2457
+ )
2458
+
2459
+ async def logout(
2460
+ self,
2461
+ *,
2462
+ extra_headers: Optional[Headers] = None,
2463
+ extra_query: Optional[Query] = None,
2464
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2465
+ ) -> None:
2466
+ """`POST /api/v1/auth/logout`"""
2467
+ return await self._client._call(
2468
+ "POST",
2469
+ "/auth/logout",
2470
+ cast=type(None),
2471
+ extra_headers=extra_headers,
2472
+ extra_query=extra_query,
2473
+ timeout=timeout,
2474
+ )
2475
+
2476
+ async def signup(
2477
+ self,
2478
+ *,
2479
+ email: str,
2480
+ password: str,
2481
+ invite: Union[str, None, NotGiven] = NOT_GIVEN,
2482
+ name: Union[str, NotGiven] = NOT_GIVEN,
2483
+ extra_headers: Optional[Headers] = None,
2484
+ extra_query: Optional[Query] = None,
2485
+ extra_body: Optional[Body] = None,
2486
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2487
+ ) -> Me:
2488
+ """注册(本地登录模式)。OAD_SIGNUP:invite(默认,要凭邀请)、open、off。
2489
+
2490
+ `POST /api/v1/auth/signup`
2491
+ """
2492
+ return await self._client._call(
2493
+ "POST",
2494
+ "/auth/signup",
2495
+ body={"email": email, "invite": invite, "name": name, "password": password},
2496
+ extra_body=extra_body,
2497
+ cast=Me,
2498
+ extra_headers=extra_headers,
2499
+ extra_query=extra_query,
2500
+ timeout=timeout,
2501
+ )
2502
+
2503
+
2504
+ class AsyncCommentsResource:
2505
+ """`client.comments`"""
2506
+
2507
+ def __init__(self, client: AsyncAPIClient) -> None:
2508
+ self._client = client
2509
+
2510
+ async def update(
2511
+ self,
2512
+ id: str,
2513
+ *,
2514
+ body: str,
2515
+ extra_headers: Optional[Headers] = None,
2516
+ extra_query: Optional[Query] = None,
2517
+ extra_body: Optional[Body] = None,
2518
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2519
+ ) -> CommentView:
2520
+ """只有作者能改。
2521
+
2522
+ `PATCH /api/v1/comments/{id}`
2523
+ """
2524
+ return await self._client._call(
2525
+ "PATCH",
2526
+ f"/comments/{_p(id)}",
2527
+ body={"body": body},
2528
+ extra_body=extra_body,
2529
+ cast=CommentView,
2530
+ extra_headers=extra_headers,
2531
+ extra_query=extra_query,
2532
+ timeout=timeout,
2533
+ )
2534
+
2535
+ async def delete(
2536
+ self,
2537
+ id: str,
2538
+ *,
2539
+ extra_headers: Optional[Headers] = None,
2540
+ extra_query: Optional[Query] = None,
2541
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2542
+ ) -> None:
2543
+ """`DELETE /api/v1/comments/{id}`"""
2544
+ return await self._client._call(
2545
+ "DELETE",
2546
+ f"/comments/{_p(id)}",
2547
+ cast=type(None),
2548
+ extra_headers=extra_headers,
2549
+ extra_query=extra_query,
2550
+ timeout=timeout,
2551
+ )
2552
+
2553
+
2554
+ class AsyncDatabasesHistoryResource:
2555
+ """`client.databases.history`"""
2556
+
2557
+ def __init__(self, client: AsyncAPIClient) -> None:
2558
+ self._client = client
2559
+
2560
+ def list(
2561
+ self,
2562
+ id: str,
2563
+ *,
2564
+ row: Union[str, NotGiven] = NOT_GIVEN,
2565
+ prop: Union[str, NotGiven] = NOT_GIVEN,
2566
+ limit: Union[int, NotGiven] = NOT_GIVEN,
2567
+ cursor: Union[str, NotGiven] = NOT_GIVEN,
2568
+ extra_headers: Optional[Headers] = None,
2569
+ extra_query: Optional[Query] = None,
2570
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2571
+ ) -> AsyncPaginator[DbHistoryItem]:
2572
+ """`GET /api/v1/databases/{id}/history`"""
2573
+ return self._client._call_page(
2574
+ "GET",
2575
+ f"/databases/{_p(id)}/history",
2576
+ query={"row": row, "prop": prop, "limit": limit, "cursor": cursor},
2577
+ model=DbHistory,
2578
+ items="items",
2579
+ item=DbHistoryItem,
2580
+ extra_headers=extra_headers,
2581
+ extra_query=extra_query,
2582
+ timeout=timeout,
2583
+ )
2584
+
2585
+ async def undo(
2586
+ self,
2587
+ id: str,
2588
+ *,
2589
+ seq: int,
2590
+ extra_headers: Optional[Headers] = None,
2591
+ extra_query: Optional[Query] = None,
2592
+ extra_body: Optional[Body] = None,
2593
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2594
+ ) -> DbUndone:
2595
+ """`POST /api/v1/databases/{id}/history/undo`"""
2596
+ return await self._client._call(
2597
+ "POST",
2598
+ f"/databases/{_p(id)}/history/undo",
2599
+ body={"seq": seq},
2600
+ extra_body=extra_body,
2601
+ cast=DbUndone,
2602
+ extra_headers=extra_headers,
2603
+ extra_query=extra_query,
2604
+ timeout=timeout,
2605
+ )
2606
+
2607
+
2608
+ class AsyncDatabasesRowsResource:
2609
+ """`client.databases.rows`"""
2610
+
2611
+ def __init__(self, client: AsyncAPIClient) -> None:
2612
+ self._client = client
2613
+
2614
+ async def list(
2615
+ self,
2616
+ id: str,
2617
+ *,
2618
+ since: Union[int, NotGiven] = NOT_GIVEN,
2619
+ extra_headers: Optional[Headers] = None,
2620
+ extra_query: Optional[Query] = None,
2621
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2622
+ ) -> RowsDelta:
2623
+ """行(全量或增量)。按 Accept-Encoding 压缩:br 优先,其次 gzip(1 万行的全量压缩后 < 1MB)。
2624
+
2625
+ `GET /api/v1/databases/{id}/rows`
2626
+ """
2627
+ return await self._client._call(
2628
+ "GET",
2629
+ f"/databases/{_p(id)}/rows",
2630
+ query={"since": since},
2631
+ cast=RowsDelta,
2632
+ extra_headers=extra_headers,
2633
+ extra_query=extra_query,
2634
+ timeout=timeout,
2635
+ )
2636
+
2637
+ async def add(
2638
+ self,
2639
+ id: str,
2640
+ *,
2641
+ rows: Sequence[Union[AddRow, Dict[str, Any]]],
2642
+ extra_headers: Optional[Headers] = None,
2643
+ extra_query: Optional[Query] = None,
2644
+ extra_body: Optional[Body] = None,
2645
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2646
+ ) -> AddedRows:
2647
+ """`POST /api/v1/databases/{id}/rows`"""
2648
+ return await self._client._call(
2649
+ "POST",
2650
+ f"/databases/{_p(id)}/rows",
2651
+ body={"rows": rows},
2652
+ extra_body=extra_body,
2653
+ cast=AddedRows,
2654
+ extra_headers=extra_headers,
2655
+ extra_query=extra_query,
2656
+ timeout=timeout,
2657
+ )
2658
+
2659
+ async def update(
2660
+ self,
2661
+ id: str,
2662
+ *,
2663
+ ops: Sequence[Union[CellOp, Dict[str, Any]]],
2664
+ extra_headers: Optional[Headers] = None,
2665
+ extra_query: Optional[Query] = None,
2666
+ extra_body: Optional[Body] = None,
2667
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2668
+ ) -> Patched:
2669
+ """`PATCH /api/v1/databases/{id}/rows`"""
2670
+ return await self._client._call(
2671
+ "PATCH",
2672
+ f"/databases/{_p(id)}/rows",
2673
+ body={"ops": ops},
2674
+ extra_body=extra_body,
2675
+ cast=Patched,
2676
+ extra_headers=extra_headers,
2677
+ extra_query=extra_query,
2678
+ timeout=timeout,
2679
+ )
2680
+
2681
+ async def delete(
2682
+ self,
2683
+ id: str,
2684
+ *,
2685
+ ids: Sequence[str],
2686
+ extra_headers: Optional[Headers] = None,
2687
+ extra_query: Optional[Query] = None,
2688
+ extra_body: Optional[Body] = None,
2689
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2690
+ ) -> Seq:
2691
+ """`DELETE /api/v1/databases/{id}/rows`"""
2692
+ return await self._client._call(
2693
+ "DELETE",
2694
+ f"/databases/{_p(id)}/rows",
2695
+ body={"ids": ids},
2696
+ extra_body=extra_body,
2697
+ cast=Seq,
2698
+ extra_headers=extra_headers,
2699
+ extra_query=extra_query,
2700
+ timeout=timeout,
2701
+ )
2702
+
2703
+ async def delete_one(
2704
+ self,
2705
+ id: str,
2706
+ row: str,
2707
+ *,
2708
+ extra_headers: Optional[Headers] = None,
2709
+ extra_query: Optional[Query] = None,
2710
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2711
+ ) -> Seq:
2712
+ """`DELETE /api/v1/databases/{id}/rows/{row}`"""
2713
+ return await self._client._call(
2714
+ "DELETE",
2715
+ f"/databases/{_p(id)}/rows/{_p(row)}",
2716
+ cast=Seq,
2717
+ extra_headers=extra_headers,
2718
+ extra_query=extra_query,
2719
+ timeout=timeout,
2720
+ )
2721
+
2722
+
2723
+ class AsyncDatabasesSchemaResource:
2724
+ """`client.databases.schema`"""
2725
+
2726
+ def __init__(self, client: AsyncAPIClient) -> None:
2727
+ self._client = client
2728
+
2729
+ async def update(
2730
+ self,
2731
+ id: str,
2732
+ *,
2733
+ ops: Sequence[Mapping[str, Any]],
2734
+ extra_headers: Optional[Headers] = None,
2735
+ extra_query: Optional[Query] = None,
2736
+ extra_body: Optional[Body] = None,
2737
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2738
+ ) -> SchemaChanged:
2739
+ """`PATCH /api/v1/databases/{id}/schema`"""
2740
+ return await self._client._call(
2741
+ "PATCH",
2742
+ f"/databases/{_p(id)}/schema",
2743
+ body={"ops": ops},
2744
+ extra_body=extra_body,
2745
+ cast=SchemaChanged,
2746
+ extra_headers=extra_headers,
2747
+ extra_query=extra_query,
2748
+ timeout=timeout,
2749
+ )
2750
+
2751
+ async def undo(
2752
+ self,
2753
+ id: str,
2754
+ *,
2755
+ seq: int,
2756
+ extra_headers: Optional[Headers] = None,
2757
+ extra_query: Optional[Query] = None,
2758
+ extra_body: Optional[Body] = None,
2759
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2760
+ ) -> SchemaUndone:
2761
+ """`POST /api/v1/databases/{id}/schema/undo`"""
2762
+ return await self._client._call(
2763
+ "POST",
2764
+ f"/databases/{_p(id)}/schema/undo",
2765
+ body={"seq": seq},
2766
+ extra_body=extra_body,
2767
+ cast=SchemaUndone,
2768
+ extra_headers=extra_headers,
2769
+ extra_query=extra_query,
2770
+ timeout=timeout,
2771
+ )
2772
+
2773
+
2774
+ class AsyncDatabasesViewsResource:
2775
+ """`client.databases.views`"""
2776
+
2777
+ def __init__(self, client: AsyncAPIClient) -> None:
2778
+ self._client = client
2779
+
2780
+ async def create(
2781
+ self,
2782
+ id: str,
2783
+ *,
2784
+ body: Mapping[str, Any],
2785
+ extra_headers: Optional[Headers] = None,
2786
+ extra_query: Optional[Query] = None,
2787
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2788
+ ) -> DbView:
2789
+ """加一个视图(不给 type 是表格),返回它(带上新的 id)。
2790
+
2791
+ `POST /api/v1/databases/{id}/views`
2792
+ """
2793
+ return await self._client._call(
2794
+ "POST",
2795
+ f"/databases/{_p(id)}/views",
2796
+ body=body,
2797
+ cast=DbView,
2798
+ extra_headers=extra_headers,
2799
+ extra_query=extra_query,
2800
+ timeout=timeout,
2801
+ )
2802
+
2803
+ async def replace(
2804
+ self,
2805
+ id: str,
2806
+ *,
2807
+ body: PutViews,
2808
+ extra_headers: Optional[Headers] = None,
2809
+ extra_query: Optional[Query] = None,
2810
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2811
+ ) -> List[DbView]:
2812
+ """整个换掉:`[...]` 或 `{ views: [...] }`。
2813
+
2814
+ `PUT /api/v1/databases/{id}/views`
2815
+ """
2816
+ return await self._client._call(
2817
+ "PUT",
2818
+ f"/databases/{_p(id)}/views",
2819
+ body=body,
2820
+ unwrap="views",
2821
+ cast=List[DbView],
2822
+ extra_headers=extra_headers,
2823
+ extra_query=extra_query,
2824
+ timeout=timeout,
2825
+ )
2826
+
2827
+ async def update(
2828
+ self,
2829
+ id: str,
2830
+ view: str,
2831
+ *,
2832
+ body: Mapping[str, Any],
2833
+ extra_headers: Optional[Headers] = None,
2834
+ extra_query: Optional[Query] = None,
2835
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2836
+ ) -> DbView:
2837
+ """改一个视图的几项:给了的字段覆盖,null 去掉。返回改好的视图。
2838
+
2839
+ `PATCH /api/v1/databases/{id}/views/{view}`
2840
+ """
2841
+ return await self._client._call(
2842
+ "PATCH",
2843
+ f"/databases/{_p(id)}/views/{_p(view)}",
2844
+ body=body,
2845
+ cast=DbView,
2846
+ extra_headers=extra_headers,
2847
+ extra_query=extra_query,
2848
+ timeout=timeout,
2849
+ )
2850
+
2851
+ async def delete(
2852
+ self,
2853
+ id: str,
2854
+ view: str,
2855
+ *,
2856
+ extra_headers: Optional[Headers] = None,
2857
+ extra_query: Optional[Query] = None,
2858
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2859
+ ) -> None:
2860
+ """删一个视图(最后一个不能删)。
2861
+
2862
+ `DELETE /api/v1/databases/{id}/views/{view}`
2863
+ """
2864
+ return await self._client._call(
2865
+ "DELETE",
2866
+ f"/databases/{_p(id)}/views/{_p(view)}",
2867
+ cast=type(None),
2868
+ extra_headers=extra_headers,
2869
+ extra_query=extra_query,
2870
+ timeout=timeout,
2871
+ )
2872
+
2873
+
2874
+ class AsyncDatabasesResource:
2875
+ """`client.databases`"""
2876
+
2877
+ def __init__(self, client: AsyncAPIClient) -> None:
2878
+ self._client = client
2879
+
2880
+ @cached_property
2881
+ def history(self) -> AsyncDatabasesHistoryResource:
2882
+ return AsyncDatabasesHistoryResource(self._client)
2883
+
2884
+ @cached_property
2885
+ def rows(self) -> AsyncDatabasesRowsResource:
2886
+ return AsyncDatabasesRowsResource(self._client)
2887
+
2888
+ @cached_property
2889
+ def schema(self) -> AsyncDatabasesSchemaResource:
2890
+ return AsyncDatabasesSchemaResource(self._client)
2891
+
2892
+ @cached_property
2893
+ def views(self) -> AsyncDatabasesViewsResource:
2894
+ return AsyncDatabasesViewsResource(self._client)
2895
+
2896
+ async def create(
2897
+ self,
2898
+ ws: str,
2899
+ *,
2900
+ after: Union[str, None, NotGiven] = NOT_GIVEN,
2901
+ parent_id: Union[str, None, NotGiven] = NOT_GIVEN,
2902
+ schema: Union[Mapping[str, Any], None, NotGiven] = NOT_GIVEN,
2903
+ title: Union[str, None, NotGiven] = NOT_GIVEN,
2904
+ views: Union[Sequence[Mapping[str, Any]], None, NotGiven] = NOT_GIVEN,
2905
+ extra_headers: Optional[Headers] = None,
2906
+ extra_query: Optional[Query] = None,
2907
+ extra_body: Optional[Body] = None,
2908
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2909
+ ) -> DbInfo:
2910
+ """`POST /api/v1/workspaces/{ws}/databases`"""
2911
+ return await self._client._call(
2912
+ "POST",
2913
+ f"/workspaces/{_p(ws)}/databases",
2914
+ body={"after": after, "parent_id": parent_id, "schema": schema, "title": title, "views": views},
2915
+ extra_body=extra_body,
2916
+ cast=DbInfo,
2917
+ extra_headers=extra_headers,
2918
+ extra_query=extra_query,
2919
+ timeout=timeout,
2920
+ )
2921
+
2922
+ async def import_csv(
2923
+ self,
2924
+ ws: str,
2925
+ csv: Union[str, bytes],
2926
+ *,
2927
+ title: Union[str, NotGiven] = NOT_GIVEN,
2928
+ parent_id: Union[str, NotGiven] = NOT_GIVEN,
2929
+ extra_headers: Optional[Headers] = None,
2930
+ extra_query: Optional[Query] = None,
2931
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2932
+ ) -> DbInfo:
2933
+ """导入 CSV:multipart 的 `file`(和可选的 `title`、`parent_id`),或者原始正文(`?title=`)。
2934
+
2935
+ `POST /api/v1/workspaces/{ws}/databases/import`
2936
+ """
2937
+ return await self._client._call(
2938
+ "POST",
2939
+ f"/workspaces/{_p(ws)}/databases/import",
2940
+ query={"title": title, "parent_id": parent_id},
2941
+ content=_csv_body(csv),
2942
+ headers={"content-type": "text/csv; charset=utf-8"},
2943
+ cast=DbInfo,
2944
+ extra_headers=extra_headers,
2945
+ extra_query=extra_query,
2946
+ timeout=timeout,
2947
+ )
2948
+
2949
+ async def get(
2950
+ self,
2951
+ id: str,
2952
+ *,
2953
+ extra_headers: Optional[Headers] = None,
2954
+ extra_query: Optional[Query] = None,
2955
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2956
+ ) -> DbInfo:
2957
+ """库的页面、表结构、视图、现在的 seq。
2958
+
2959
+ `GET /api/v1/databases/{id}`
2960
+ """
2961
+ return await self._client._call(
2962
+ "GET",
2963
+ f"/databases/{_p(id)}",
2964
+ cast=DbInfo,
2965
+ extra_headers=extra_headers,
2966
+ extra_query=extra_query,
2967
+ timeout=timeout,
2968
+ )
2969
+
2970
+ async def query(
2971
+ self,
2972
+ id: str,
2973
+ *,
2974
+ filter: Union[Mapping[str, Any], None, NotGiven] = NOT_GIVEN,
2975
+ group_by: Union[str, None, NotGiven] = NOT_GIVEN,
2976
+ limit: Union[int, None, NotGiven] = NOT_GIVEN,
2977
+ offset: Union[int, None, NotGiven] = NOT_GIVEN,
2978
+ search: Union[str, None, NotGiven] = NOT_GIVEN,
2979
+ sorts: Union[Sequence[Mapping[str, Any]], None, NotGiven] = NOT_GIVEN,
2980
+ totals: Union[Mapping[str, Any], None, NotGiven] = NOT_GIVEN,
2981
+ view_id: Union[str, None, NotGiven] = NOT_GIVEN,
2982
+ extra_headers: Optional[Headers] = None,
2983
+ extra_query: Optional[Query] = None,
2984
+ extra_body: Optional[Body] = None,
2985
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
2986
+ ) -> QueryResult:
2987
+ """服务器算的查询:给了 view_id 就从那个视图出发,别的字段覆盖它。
2988
+
2989
+ `POST /api/v1/databases/{id}/query`
2990
+ """
2991
+ return await self._client._call(
2992
+ "POST",
2993
+ f"/databases/{_p(id)}/query",
2994
+ body={"filter": filter, "group_by": group_by, "limit": limit, "offset": offset, "search": search, "sorts": sorts, "totals": totals, "view_id": view_id},
2995
+ extra_body=extra_body,
2996
+ cast=QueryResult,
2997
+ extra_headers=extra_headers,
2998
+ extra_query=extra_query,
2999
+ timeout=timeout,
3000
+ )
3001
+
3002
+ async def export_csv(
3003
+ self,
3004
+ id: str,
3005
+ *,
3006
+ extra_headers: Optional[Headers] = None,
3007
+ extra_query: Optional[Query] = None,
3008
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3009
+ ) -> bytes:
3010
+ """导出 CSV(UTF-8,按第一个视图的列)。
3011
+
3012
+ `GET /api/v1/databases/{id}/export.csv`
3013
+ """
3014
+ return await self._client._call(
3015
+ "GET",
3016
+ f"/databases/{_p(id)}/export.csv",
3017
+ cast=bytes,
3018
+ extra_headers=extra_headers,
3019
+ extra_query=extra_query,
3020
+ timeout=timeout,
3021
+ )
3022
+
3023
+ async def press_button(
3024
+ self,
3025
+ id: str,
3026
+ row: str,
3027
+ key: str,
3028
+ *,
3029
+ extra_headers: Optional[Headers] = None,
3030
+ extra_query: Optional[Query] = None,
3031
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3032
+ ) -> Pressed:
3033
+ """按一行上的按钮:按设置改属性,有 `comment` 的在这一行上发一条评论(可以叫 Agent)。
3034
+
3035
+ `POST /api/v1/databases/{id}/button/{row}/{key}`
3036
+ """
3037
+ return await self._client._call(
3038
+ "POST",
3039
+ f"/databases/{_p(id)}/button/{_p(row)}/{_p(key)}",
3040
+ cast=Pressed,
3041
+ extra_headers=extra_headers,
3042
+ extra_query=extra_query,
3043
+ timeout=timeout,
3044
+ )
3045
+
3046
+
3047
+ class AsyncFilesResource:
3048
+ """`client.files`"""
3049
+
3050
+ def __init__(self, client: AsyncAPIClient) -> None:
3051
+ self._client = client
3052
+
3053
+ async def upload(
3054
+ self,
3055
+ ws: str,
3056
+ file: FileTypes,
3057
+ filename: Optional[str] = None,
3058
+ content_type: Optional[str] = None,
3059
+ *,
3060
+ extra_headers: Optional[Headers] = None,
3061
+ extra_query: Optional[Query] = None,
3062
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3063
+ ) -> Uploaded:
3064
+ """上传文件:`multipart/form-data` 的 `file` 字段,或者原始正文 + `X-Filename` 头(文件名按网址规则编码)。大小上限见 OAD_MAX_UPLOAD。图片会算宽高和 blurhash,音视频算时长。
3065
+
3066
+ `POST /api/v1/workspaces/{ws}/files`
3067
+ """
3068
+ return await self._client._call(
3069
+ "POST",
3070
+ f"/workspaces/{_p(ws)}/files",
3071
+ files=_file_part(file, filename, content_type),
3072
+ cast=Uploaded,
3073
+ extra_headers=extra_headers,
3074
+ extra_query=extra_query,
3075
+ timeout=timeout,
3076
+ )
3077
+
3078
+ async def download(
3079
+ self,
3080
+ id: str,
3081
+ *,
3082
+ w: Union[int, NotGiven] = NOT_GIVEN,
3083
+ exp: Union[int, NotGiven] = NOT_GIVEN,
3084
+ sig: Union[str, NotGiven] = NOT_GIVEN,
3085
+ extra_headers: Optional[Headers] = None,
3086
+ extra_query: Optional[Query] = None,
3087
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3088
+ ) -> bytes:
3089
+ """同 `/files/{id}/{name}`,不带文件名。
3090
+
3091
+ `GET /api/v1/files/{id}`
3092
+ """
3093
+ return await self._client._call(
3094
+ "GET",
3095
+ f"/files/{_p(id)}",
3096
+ query={"w": w, "exp": exp, "sig": sig},
3097
+ cast=bytes,
3098
+ extra_headers=extra_headers,
3099
+ extra_query=extra_query,
3100
+ timeout=timeout,
3101
+ )
3102
+
3103
+ async def download_named(
3104
+ self,
3105
+ id: str,
3106
+ name: str,
3107
+ *,
3108
+ w: Union[int, NotGiven] = NOT_GIVEN,
3109
+ exp: Union[int, NotGiven] = NOT_GIVEN,
3110
+ sig: Union[str, NotGiven] = NOT_GIVEN,
3111
+ extra_headers: Optional[Headers] = None,
3112
+ extra_query: Optional[Query] = None,
3113
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3114
+ ) -> bytes:
3115
+ """下载上传的文件:原来的类型;带 ETag、长缓存、Range。`?w=` 给图片的缩略图(WebP)。SVG、HTML 之类带 `Content-Security-Policy: sandbox`,SVG 当附件下载。不是这个工作区的成员当不存在(404)。带了有效的签名(`?exp=&sig=`,见 `POST /files/sign`)就不用登录;签名过期了或者不对回 403(登录了、看得到的照样给)。
3116
+
3117
+ `GET /api/v1/files/{id}/{name}`
3118
+ """
3119
+ return await self._client._call(
3120
+ "GET",
3121
+ f"/files/{_p(id)}/{_p(name)}",
3122
+ query={"w": w, "exp": exp, "sig": sig},
3123
+ cast=bytes,
3124
+ extra_headers=extra_headers,
3125
+ extra_query=extra_query,
3126
+ timeout=timeout,
3127
+ )
3128
+
3129
+ async def media(
3130
+ self,
3131
+ hash: str,
3132
+ *,
3133
+ w: Union[int, NotGiven] = NOT_GIVEN,
3134
+ exp: Union[int, NotGiven] = NOT_GIVEN,
3135
+ sig: Union[str, NotGiven] = NOT_GIVEN,
3136
+ extra_headers: Optional[Headers] = None,
3137
+ extra_query: Optional[Query] = None,
3138
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3139
+ ) -> bytes:
3140
+ """转存的外部图片(链接卡片的封面、头像之类),按内容的 hash。登录了就能看,带了有效的签名(`?exp=&sig=`)也行。`?w=` 给缩略图(WebP),支持 Range。
3141
+
3142
+ `GET /api/v1/media/{hash}`
3143
+ """
3144
+ return await self._client._call(
3145
+ "GET",
3146
+ f"/media/{_p(hash)}",
3147
+ query={"w": w, "exp": exp, "sig": sig},
3148
+ cast=bytes,
3149
+ extra_headers=extra_headers,
3150
+ extra_query=extra_query,
3151
+ timeout=timeout,
3152
+ )
3153
+
3154
+ async def sign(
3155
+ self,
3156
+ *,
3157
+ urls: Sequence[str],
3158
+ extra_headers: Optional[Headers] = None,
3159
+ extra_query: Optional[Query] = None,
3160
+ extra_body: Optional[Body] = None,
3161
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3162
+ ) -> SignedFileUrls:
3163
+ """给文件、转存的图片签名,拿到不用登录就能打开的地址(`<img>`、链接带不了 `Authorization`:跨域 iframe、Web Component、宿主自己渲染的 HTML 用)。签名不包含 `w` 和文件名,拿到以后可以自己加 `w=`。只签调用者看得到的;拿到地址的人在有效期内不登录也能打开,别外传。
3164
+
3165
+ `POST /api/v1/files/sign`
3166
+ """
3167
+ return await self._client._call(
3168
+ "POST",
3169
+ "/files/sign",
3170
+ body={"urls": urls},
3171
+ extra_body=extra_body,
3172
+ cast=SignedFileUrls,
3173
+ extra_headers=extra_headers,
3174
+ extra_query=extra_query,
3175
+ timeout=timeout,
3176
+ )
3177
+
3178
+
3179
+ class AsyncInvitesResource:
3180
+ """`client.invites`"""
3181
+
3182
+ def __init__(self, client: AsyncAPIClient) -> None:
3183
+ self._client = client
3184
+
3185
+ async def get(
3186
+ self,
3187
+ token: str,
3188
+ *,
3189
+ extra_headers: Optional[Headers] = None,
3190
+ extra_query: Optional[Query] = None,
3191
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3192
+ ) -> InviteInfo:
3193
+ """打开邀请链接时看的:哪个工作区、什么角色、谁邀请的。不用登录。
3194
+
3195
+ `GET /api/v1/invites/{token}`
3196
+ """
3197
+ return await self._client._call(
3198
+ "GET",
3199
+ f"/invites/{_p(token)}",
3200
+ cast=InviteInfo,
3201
+ extra_headers=extra_headers,
3202
+ extra_query=extra_query,
3203
+ timeout=timeout,
3204
+ )
3205
+
3206
+ async def accept(
3207
+ self,
3208
+ token: str,
3209
+ *,
3210
+ extra_headers: Optional[Headers] = None,
3211
+ extra_query: Optional[Query] = None,
3212
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3213
+ ) -> Me:
3214
+ """接受邀请,加入工作区(已经在里面的不降角色)。返回加入后的 /me。
3215
+
3216
+ `POST /api/v1/invites/{token}/accept`
3217
+ """
3218
+ return await self._client._call(
3219
+ "POST",
3220
+ f"/invites/{_p(token)}/accept",
3221
+ cast=Me,
3222
+ extra_headers=extra_headers,
3223
+ extra_query=extra_query,
3224
+ timeout=timeout,
3225
+ )
3226
+
3227
+ async def list(
3228
+ self,
3229
+ ws: str,
3230
+ *,
3231
+ extra_headers: Optional[Headers] = None,
3232
+ extra_query: Optional[Query] = None,
3233
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3234
+ ) -> List[InviteView]:
3235
+ """`GET /api/v1/workspaces/{ws}/invites`"""
3236
+ return await self._client._call(
3237
+ "GET",
3238
+ f"/workspaces/{_p(ws)}/invites",
3239
+ unwrap="invites",
3240
+ cast=List[InviteView],
3241
+ extra_headers=extra_headers,
3242
+ extra_query=extra_query,
3243
+ timeout=timeout,
3244
+ )
3245
+
3246
+ async def create(
3247
+ self,
3248
+ ws: str,
3249
+ *,
3250
+ role: str,
3251
+ expires_in: Union[int, None, NotGiven] = NOT_GIVEN,
3252
+ extra_headers: Optional[Headers] = None,
3253
+ extra_query: Optional[Query] = None,
3254
+ extra_body: Optional[Body] = None,
3255
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3256
+ ) -> InviteView:
3257
+ """`POST /api/v1/workspaces/{ws}/invites`"""
3258
+ return await self._client._call(
3259
+ "POST",
3260
+ f"/workspaces/{_p(ws)}/invites",
3261
+ body={"expires_in": expires_in, "role": role},
3262
+ extra_body=extra_body,
3263
+ cast=InviteView,
3264
+ extra_headers=extra_headers,
3265
+ extra_query=extra_query,
3266
+ timeout=timeout,
3267
+ )
3268
+
3269
+ async def revoke(
3270
+ self,
3271
+ ws: str,
3272
+ token: str,
3273
+ *,
3274
+ extra_headers: Optional[Headers] = None,
3275
+ extra_query: Optional[Query] = None,
3276
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3277
+ ) -> None:
3278
+ """`DELETE /api/v1/workspaces/{ws}/invites/{token}`"""
3279
+ return await self._client._call(
3280
+ "DELETE",
3281
+ f"/workspaces/{_p(ws)}/invites/{_p(token)}",
3282
+ cast=type(None),
3283
+ extra_headers=extra_headers,
3284
+ extra_query=extra_query,
3285
+ timeout=timeout,
3286
+ )
3287
+
3288
+
3289
+ class AsyncLinksResource:
3290
+ """`client.links`"""
3291
+
3292
+ def __init__(self, client: AsyncAPIClient) -> None:
3293
+ self._client = client
3294
+
3295
+ async def unfurl(
3296
+ self,
3297
+ *,
3298
+ url: str,
3299
+ extra_headers: Optional[Headers] = None,
3300
+ extra_query: Optional[Query] = None,
3301
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3302
+ ) -> UnfurlCard:
3303
+ """解析一个网址成卡片:上传的文件直接从库里给,本站的库给视图列表,别的网址去抓(有缓存,图片转存到 /media)。
3304
+
3305
+ `GET /api/v1/unfurl`
3306
+ """
3307
+ return await self._client._call(
3308
+ "GET",
3309
+ "/unfurl",
3310
+ query={"url": url},
3311
+ cast=UnfurlCard,
3312
+ extra_headers=extra_headers,
3313
+ extra_query=extra_query,
3314
+ timeout=timeout,
3315
+ )
3316
+
3317
+
3318
+ class AsyncMeNotificationsResource:
3319
+ """`client.me.notifications`"""
3320
+
3321
+ def __init__(self, client: AsyncAPIClient) -> None:
3322
+ self._client = client
3323
+
3324
+ def list(
3325
+ self,
3326
+ *,
3327
+ after: Union[int, NotGiven] = NOT_GIVEN,
3328
+ cursor: Union[str, NotGiven] = NOT_GIVEN,
3329
+ limit: Union[int, NotGiven] = NOT_GIVEN,
3330
+ extra_headers: Optional[Headers] = None,
3331
+ extra_query: Optional[Query] = None,
3332
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3333
+ ) -> AsyncPaginator[InboxNotification]:
3334
+ """`GET /api/v1/me/notifications`"""
3335
+ return self._client._call_page(
3336
+ "GET",
3337
+ "/me/notifications",
3338
+ query={"after": after, "cursor": cursor, "limit": limit},
3339
+ model=Inbox,
3340
+ items="notifications",
3341
+ item=InboxNotification,
3342
+ extra_headers=extra_headers,
3343
+ extra_query=extra_query,
3344
+ timeout=timeout,
3345
+ )
3346
+
3347
+ async def mark_read(
3348
+ self,
3349
+ *,
3350
+ all: Union[bool, NotGiven] = NOT_GIVEN,
3351
+ ids: Union[Sequence[int], None, NotGiven] = NOT_GIVEN,
3352
+ extra_headers: Optional[Headers] = None,
3353
+ extra_query: Optional[Query] = None,
3354
+ extra_body: Optional[Body] = None,
3355
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3356
+ ) -> ReadCount:
3357
+ """`POST /api/v1/me/notifications/read`"""
3358
+ return await self._client._call(
3359
+ "POST",
3360
+ "/me/notifications/read",
3361
+ body={"all": all, "ids": ids},
3362
+ extra_body=extra_body,
3363
+ cast=ReadCount,
3364
+ extra_headers=extra_headers,
3365
+ extra_query=extra_query,
3366
+ timeout=timeout,
3367
+ )
3368
+
3369
+
3370
+ class AsyncMeResource:
3371
+ """`client.me`"""
3372
+
3373
+ def __init__(self, client: AsyncAPIClient) -> None:
3374
+ self._client = client
3375
+
3376
+ @cached_property
3377
+ def notifications(self) -> AsyncMeNotificationsResource:
3378
+ return AsyncMeNotificationsResource(self._client)
3379
+
3380
+ async def get(
3381
+ self,
3382
+ *,
3383
+ extra_headers: Optional[Headers] = None,
3384
+ extra_query: Optional[Query] = None,
3385
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3386
+ ) -> Me:
3387
+ """`GET /api/v1/me`"""
3388
+ return await self._client._call(
3389
+ "GET",
3390
+ "/me",
3391
+ cast=Me,
3392
+ extra_headers=extra_headers,
3393
+ extra_query=extra_query,
3394
+ timeout=timeout,
3395
+ )
3396
+
3397
+ async def update(
3398
+ self,
3399
+ *,
3400
+ avatar: Union[str, None, NotGiven] = NOT_GIVEN,
3401
+ locale: Union[str, None, NotGiven] = NOT_GIVEN,
3402
+ name: Union[str, None, NotGiven] = NOT_GIVEN,
3403
+ timezone: Union[str, None, NotGiven] = NOT_GIVEN,
3404
+ extra_headers: Optional[Headers] = None,
3405
+ extra_query: Optional[Query] = None,
3406
+ extra_body: Optional[Body] = None,
3407
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3408
+ ) -> Me:
3409
+ """`PATCH /api/v1/me`"""
3410
+ return await self._client._call(
3411
+ "PATCH",
3412
+ "/me",
3413
+ body={"avatar": avatar, "locale": locale, "name": name, "timezone": timezone},
3414
+ extra_body=extra_body,
3415
+ cast=Me,
3416
+ extra_headers=extra_headers,
3417
+ extra_query=extra_query,
3418
+ timeout=timeout,
3419
+ )
3420
+
3421
+ async def change_password(
3422
+ self,
3423
+ *,
3424
+ current: str,
3425
+ new: str,
3426
+ extra_headers: Optional[Headers] = None,
3427
+ extra_query: Optional[Query] = None,
3428
+ extra_body: Optional[Body] = None,
3429
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3430
+ ) -> None:
3431
+ """改密码(本地登录)。别的会话都退出,这次请求用的会话保留。
3432
+
3433
+ `POST /api/v1/me/password`
3434
+ """
3435
+ return await self._client._call(
3436
+ "POST",
3437
+ "/me/password",
3438
+ body={"current": current, "new": new},
3439
+ extra_body=extra_body,
3440
+ cast=type(None),
3441
+ extra_headers=extra_headers,
3442
+ extra_query=extra_query,
3443
+ timeout=timeout,
3444
+ )
3445
+
3446
+
3447
+ class AsyncPagesBlocksResource:
3448
+ """`client.pages.blocks`"""
3449
+
3450
+ def __init__(self, client: AsyncAPIClient) -> None:
3451
+ self._client = client
3452
+
3453
+ async def insert(
3454
+ self,
3455
+ id: str,
3456
+ *,
3457
+ markdown: str,
3458
+ after: Union[str, None, NotGiven] = NOT_GIVEN,
3459
+ base: Union[str, None, NotGiven] = NOT_GIVEN,
3460
+ extra_headers: Optional[Headers] = None,
3461
+ extra_query: Optional[Query] = None,
3462
+ extra_body: Optional[Body] = None,
3463
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3464
+ ) -> BlockIds:
3465
+ """`POST /api/v1/pages/{id}/blocks`"""
3466
+ return await self._client._call(
3467
+ "POST",
3468
+ f"/pages/{_p(id)}/blocks",
3469
+ body={"after": after, "base": base, "markdown": markdown},
3470
+ extra_body=extra_body,
3471
+ cast=BlockIds,
3472
+ extra_headers=extra_headers,
3473
+ extra_query=extra_query,
3474
+ timeout=timeout,
3475
+ )
3476
+
3477
+ async def get(
3478
+ self,
3479
+ id: str,
3480
+ block_id: str,
3481
+ *,
3482
+ extra_headers: Optional[Headers] = None,
3483
+ extra_query: Optional[Query] = None,
3484
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3485
+ ) -> BlockContent:
3486
+ """`GET /api/v1/pages/{id}/blocks/{block_id}`"""
3487
+ return await self._client._call(
3488
+ "GET",
3489
+ f"/pages/{_p(id)}/blocks/{_p(block_id)}",
3490
+ cast=BlockContent,
3491
+ extra_headers=extra_headers,
3492
+ extra_query=extra_query,
3493
+ timeout=timeout,
3494
+ )
3495
+
3496
+ async def replace(
3497
+ self,
3498
+ id: str,
3499
+ block_id: str,
3500
+ *,
3501
+ markdown: str,
3502
+ after: Union[str, None, NotGiven] = NOT_GIVEN,
3503
+ base: Union[str, None, NotGiven] = NOT_GIVEN,
3504
+ extra_headers: Optional[Headers] = None,
3505
+ extra_query: Optional[Query] = None,
3506
+ extra_body: Optional[Body] = None,
3507
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3508
+ ) -> BlockIds:
3509
+ """`PUT /api/v1/pages/{id}/blocks/{block_id}`"""
3510
+ return await self._client._call(
3511
+ "PUT",
3512
+ f"/pages/{_p(id)}/blocks/{_p(block_id)}",
3513
+ body={"after": after, "base": base, "markdown": markdown},
3514
+ extra_body=extra_body,
3515
+ cast=BlockIds,
3516
+ extra_headers=extra_headers,
3517
+ extra_query=extra_query,
3518
+ timeout=timeout,
3519
+ )
3520
+
3521
+ async def delete(
3522
+ self,
3523
+ id: str,
3524
+ block_id: str,
3525
+ *,
3526
+ extra_headers: Optional[Headers] = None,
3527
+ extra_query: Optional[Query] = None,
3528
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3529
+ ) -> None:
3530
+ """`DELETE /api/v1/pages/{id}/blocks/{block_id}`"""
3531
+ return await self._client._call(
3532
+ "DELETE",
3533
+ f"/pages/{_p(id)}/blocks/{_p(block_id)}",
3534
+ cast=type(None),
3535
+ extra_headers=extra_headers,
3536
+ extra_query=extra_query,
3537
+ timeout=timeout,
3538
+ )
3539
+
3540
+
3541
+ class AsyncPagesContentResource:
3542
+ """`client.pages.content`"""
3543
+
3544
+ def __init__(self, client: AsyncAPIClient) -> None:
3545
+ self._client = client
3546
+
3547
+ async def get(
3548
+ self,
3549
+ id: str,
3550
+ *,
3551
+ format: Union[str, NotGiven] = NOT_GIVEN,
3552
+ limit: Union[int, NotGiven] = NOT_GIVEN,
3553
+ extra_headers: Optional[Headers] = None,
3554
+ extra_query: Optional[Query] = None,
3555
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3556
+ ) -> Content:
3557
+ """`GET /api/v1/pages/{id}/content`"""
3558
+ return await self._client._call(
3559
+ "GET",
3560
+ f"/pages/{_p(id)}/content",
3561
+ query={"format": format, "limit": limit},
3562
+ cast=Content,
3563
+ extra_headers=extra_headers,
3564
+ extra_query=extra_query,
3565
+ timeout=timeout,
3566
+ )
3567
+
3568
+ async def replace(
3569
+ self,
3570
+ id: str,
3571
+ *,
3572
+ base: Union[str, None, NotGiven] = NOT_GIVEN,
3573
+ doc: Union[Union[DocNode, Dict[str, Any]], None, NotGiven] = NOT_GIVEN,
3574
+ markdown: Union[str, None, NotGiven] = NOT_GIVEN,
3575
+ extra_headers: Optional[Headers] = None,
3576
+ extra_query: Optional[Query] = None,
3577
+ extra_body: Optional[Body] = None,
3578
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3579
+ ) -> None:
3580
+ """`PUT /api/v1/pages/{id}/content`"""
3581
+ return await self._client._call(
3582
+ "PUT",
3583
+ f"/pages/{_p(id)}/content",
3584
+ body={"base": base, "doc": doc, "markdown": markdown},
3585
+ extra_body=extra_body,
3586
+ cast=type(None),
3587
+ extra_headers=extra_headers,
3588
+ extra_query=extra_query,
3589
+ timeout=timeout,
3590
+ )
3591
+
3592
+
3593
+ class AsyncPagesShareResource:
3594
+ """`client.pages.share`"""
3595
+
3596
+ def __init__(self, client: AsyncAPIClient) -> None:
3597
+ self._client = client
3598
+
3599
+ async def get(
3600
+ self,
3601
+ id: str,
3602
+ *,
3603
+ extra_headers: Optional[Headers] = None,
3604
+ extra_query: Optional[Query] = None,
3605
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3606
+ ) -> Optional[ShareView]:
3607
+ """`GET /api/v1/pages/{id}/share`"""
3608
+ return await self._client._call_or_none(
3609
+ "GET",
3610
+ f"/pages/{_p(id)}/share",
3611
+ cast=ShareView,
3612
+ extra_headers=extra_headers,
3613
+ extra_query=extra_query,
3614
+ timeout=timeout,
3615
+ )
3616
+
3617
+ async def enable(
3618
+ self,
3619
+ id: str,
3620
+ *,
3621
+ include_children: Union[bool, NotGiven] = NOT_GIVEN,
3622
+ indexable: Union[bool, NotGiven] = NOT_GIVEN,
3623
+ extra_headers: Optional[Headers] = None,
3624
+ extra_query: Optional[Query] = None,
3625
+ extra_body: Optional[Body] = None,
3626
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3627
+ ) -> ShareView:
3628
+ """打开分享或改设置(已经分享了的,链接不变)。
3629
+
3630
+ `POST /api/v1/pages/{id}/share`
3631
+ """
3632
+ return await self._client._call(
3633
+ "POST",
3634
+ f"/pages/{_p(id)}/share",
3635
+ body={"include_children": include_children, "indexable": indexable},
3636
+ extra_body=extra_body,
3637
+ cast=ShareView,
3638
+ extra_headers=extra_headers,
3639
+ extra_query=extra_query,
3640
+ timeout=timeout,
3641
+ )
3642
+
3643
+ async def disable(
3644
+ self,
3645
+ id: str,
3646
+ *,
3647
+ extra_headers: Optional[Headers] = None,
3648
+ extra_query: Optional[Query] = None,
3649
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3650
+ ) -> None:
3651
+ """关掉分享,链接马上失效。
3652
+
3653
+ `DELETE /api/v1/pages/{id}/share`
3654
+ """
3655
+ return await self._client._call(
3656
+ "DELETE",
3657
+ f"/pages/{_p(id)}/share",
3658
+ cast=type(None),
3659
+ extra_headers=extra_headers,
3660
+ extra_query=extra_query,
3661
+ timeout=timeout,
3662
+ )
3663
+
3664
+
3665
+ class AsyncPagesVersionsResource:
3666
+ """`client.pages.versions`"""
3667
+
3668
+ def __init__(self, client: AsyncAPIClient) -> None:
3669
+ self._client = client
3670
+
3671
+ def list(
3672
+ self,
3673
+ id: str,
3674
+ *,
3675
+ limit: Union[int, NotGiven] = NOT_GIVEN,
3676
+ cursor: Union[str, NotGiven] = NOT_GIVEN,
3677
+ extra_headers: Optional[Headers] = None,
3678
+ extra_query: Optional[Query] = None,
3679
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3680
+ ) -> AsyncPaginator[VersionMeta]:
3681
+ """`GET /api/v1/pages/{id}/versions`"""
3682
+ return self._client._call_page(
3683
+ "GET",
3684
+ f"/pages/{_p(id)}/versions",
3685
+ query={"limit": limit, "cursor": cursor},
3686
+ model=VersionList,
3687
+ items="versions",
3688
+ item=VersionMeta,
3689
+ extra_headers=extra_headers,
3690
+ extra_query=extra_query,
3691
+ timeout=timeout,
3692
+ )
3693
+
3694
+ async def create(
3695
+ self,
3696
+ id: str,
3697
+ *,
3698
+ label: Union[str, None, NotGiven] = NOT_GIVEN,
3699
+ extra_headers: Optional[Headers] = None,
3700
+ extra_query: Optional[Query] = None,
3701
+ extra_body: Optional[Body] = None,
3702
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3703
+ ) -> VersionMeta:
3704
+ """`POST /api/v1/pages/{id}/versions`"""
3705
+ return await self._client._call(
3706
+ "POST",
3707
+ f"/pages/{_p(id)}/versions",
3708
+ body={"label": label},
3709
+ extra_body=extra_body,
3710
+ cast=VersionMeta,
3711
+ extra_headers=extra_headers,
3712
+ extra_query=extra_query,
3713
+ timeout=timeout,
3714
+ )
3715
+
3716
+ async def get(
3717
+ self,
3718
+ id: str,
3719
+ v: int,
3720
+ *,
3721
+ extra_headers: Optional[Headers] = None,
3722
+ extra_query: Optional[Query] = None,
3723
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3724
+ ) -> VersionContent:
3725
+ """`GET /api/v1/pages/{id}/versions/{v}`"""
3726
+ return await self._client._call(
3727
+ "GET",
3728
+ f"/pages/{_p(id)}/versions/{_p(v)}",
3729
+ cast=VersionContent,
3730
+ extra_headers=extra_headers,
3731
+ extra_query=extra_query,
3732
+ timeout=timeout,
3733
+ )
3734
+
3735
+ async def diff(
3736
+ self,
3737
+ id: str,
3738
+ v: int,
3739
+ *,
3740
+ to: Union[str, NotGiven] = NOT_GIVEN,
3741
+ extra_headers: Optional[Headers] = None,
3742
+ extra_query: Optional[Query] = None,
3743
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3744
+ ) -> VersionDiff:
3745
+ """`GET /api/v1/pages/{id}/versions/{v}/diff`"""
3746
+ return await self._client._call(
3747
+ "GET",
3748
+ f"/pages/{_p(id)}/versions/{_p(v)}/diff",
3749
+ query={"to": to},
3750
+ cast=VersionDiff,
3751
+ extra_headers=extra_headers,
3752
+ extra_query=extra_query,
3753
+ timeout=timeout,
3754
+ )
3755
+
3756
+ async def restore(
3757
+ self,
3758
+ id: str,
3759
+ v: int,
3760
+ *,
3761
+ extra_headers: Optional[Headers] = None,
3762
+ extra_query: Optional[Query] = None,
3763
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3764
+ ) -> Restored:
3765
+ """`POST /api/v1/pages/{id}/versions/{v}/restore`"""
3766
+ return await self._client._call(
3767
+ "POST",
3768
+ f"/pages/{_p(id)}/versions/{_p(v)}/restore",
3769
+ cast=Restored,
3770
+ extra_headers=extra_headers,
3771
+ extra_query=extra_query,
3772
+ timeout=timeout,
3773
+ )
3774
+
3775
+
3776
+ class AsyncPagesResource:
3777
+ """`client.pages`"""
3778
+
3779
+ def __init__(self, client: AsyncAPIClient) -> None:
3780
+ self._client = client
3781
+
3782
+ @cached_property
3783
+ def blocks(self) -> AsyncPagesBlocksResource:
3784
+ return AsyncPagesBlocksResource(self._client)
3785
+
3786
+ @cached_property
3787
+ def content(self) -> AsyncPagesContentResource:
3788
+ return AsyncPagesContentResource(self._client)
3789
+
3790
+ @cached_property
3791
+ def share(self) -> AsyncPagesShareResource:
3792
+ return AsyncPagesShareResource(self._client)
3793
+
3794
+ @cached_property
3795
+ def versions(self) -> AsyncPagesVersionsResource:
3796
+ return AsyncPagesVersionsResource(self._client)
3797
+
3798
+ async def list(
3799
+ self,
3800
+ ws: str,
3801
+ *,
3802
+ extra_headers: Optional[Headers] = None,
3803
+ extra_query: Optional[Query] = None,
3804
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3805
+ ) -> List[Page]:
3806
+ """`GET /api/v1/workspaces/{ws}/pages`"""
3807
+ return await self._client._call(
3808
+ "GET",
3809
+ f"/workspaces/{_p(ws)}/pages",
3810
+ unwrap="pages",
3811
+ cast=List[Page],
3812
+ extra_headers=extra_headers,
3813
+ extra_query=extra_query,
3814
+ timeout=timeout,
3815
+ )
3816
+
3817
+ async def create(
3818
+ self,
3819
+ ws: str,
3820
+ *,
3821
+ after: Union[str, None, NotGiven] = NOT_GIVEN,
3822
+ icon: Union[str, None, NotGiven] = NOT_GIVEN,
3823
+ parent_id: Union[str, None, NotGiven] = NOT_GIVEN,
3824
+ title: Union[str, None, NotGiven] = NOT_GIVEN,
3825
+ markdown: Union[str, NotGiven] = NOT_GIVEN,
3826
+ extra_headers: Optional[Headers] = None,
3827
+ extra_query: Optional[Query] = None,
3828
+ extra_body: Optional[Body] = None,
3829
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3830
+ ) -> Page:
3831
+ """`POST /api/v1/workspaces/{ws}/pages`"""
3832
+ page = await self._client._call(
3833
+ "POST",
3834
+ f"/workspaces/{_p(ws)}/pages",
3835
+ body={"after": after, "icon": icon, "parent_id": parent_id, "title": title},
3836
+ extra_body=extra_body,
3837
+ cast=Page,
3838
+ extra_headers=extra_headers,
3839
+ extra_query=extra_query,
3840
+ timeout=timeout,
3841
+ )
3842
+ if not isinstance(markdown, NotGiven):
3843
+ # 两步:先建页面,再写正文
3844
+ await self._client._call(
3845
+ "PUT",
3846
+ f"/pages/{_p(page.id)}/content",
3847
+ body={"markdown": markdown},
3848
+ cast=type(None),
3849
+ extra_headers=extra_headers,
3850
+ extra_query=extra_query,
3851
+ timeout=timeout,
3852
+ )
3853
+ return page
3854
+
3855
+ async def get(
3856
+ self,
3857
+ id: str,
3858
+ *,
3859
+ extra_headers: Optional[Headers] = None,
3860
+ extra_query: Optional[Query] = None,
3861
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3862
+ ) -> Page:
3863
+ """`GET /api/v1/pages/{id}`"""
3864
+ return await self._client._call(
3865
+ "GET",
3866
+ f"/pages/{_p(id)}",
3867
+ cast=Page,
3868
+ extra_headers=extra_headers,
3869
+ extra_query=extra_query,
3870
+ timeout=timeout,
3871
+ )
3872
+
3873
+ async def update(
3874
+ self,
3875
+ id: str,
3876
+ *,
3877
+ after: Union[str, None, NotGiven] = NOT_GIVEN,
3878
+ icon: Union[str, None, NotGiven] = NOT_GIVEN,
3879
+ parent_id: Union[str, None, NotGiven] = NOT_GIVEN,
3880
+ title: Union[str, None, NotGiven] = NOT_GIVEN,
3881
+ extra_headers: Optional[Headers] = None,
3882
+ extra_query: Optional[Query] = None,
3883
+ extra_body: Optional[Body] = None,
3884
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3885
+ ) -> Page:
3886
+ """`PATCH /api/v1/pages/{id}`"""
3887
+ return await self._client._call(
3888
+ "PATCH",
3889
+ f"/pages/{_p(id)}",
3890
+ body={"after": after, "icon": icon, "parent_id": parent_id, "title": title},
3891
+ extra_body=extra_body,
3892
+ cast=Page,
3893
+ extra_headers=extra_headers,
3894
+ extra_query=extra_query,
3895
+ timeout=timeout,
3896
+ )
3897
+
3898
+ async def delete(
3899
+ self,
3900
+ id: str,
3901
+ *,
3902
+ extra_headers: Optional[Headers] = None,
3903
+ extra_query: Optional[Query] = None,
3904
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3905
+ ) -> Deleted:
3906
+ """`DELETE /api/v1/pages/{id}`"""
3907
+ return await self._client._call(
3908
+ "DELETE",
3909
+ f"/pages/{_p(id)}",
3910
+ cast=Deleted,
3911
+ extra_headers=extra_headers,
3912
+ extra_query=extra_query,
3913
+ timeout=timeout,
3914
+ )
3915
+
3916
+ async def authors(
3917
+ self,
3918
+ id: str,
3919
+ *,
3920
+ extra_headers: Optional[Headers] = None,
3921
+ extra_query: Optional[Query] = None,
3922
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3923
+ ) -> Dict[str, AuthorRef]:
3924
+ """`GET /api/v1/pages/{id}/authors`"""
3925
+ return await self._client._call(
3926
+ "GET",
3927
+ f"/pages/{_p(id)}/authors",
3928
+ unwrap="clients",
3929
+ cast=Dict[str, AuthorRef],
3930
+ extra_headers=extra_headers,
3931
+ extra_query=extra_query,
3932
+ timeout=timeout,
3933
+ )
3934
+
3935
+
3936
+ class AsyncThreadsResource:
3937
+ """`client.threads`"""
3938
+
3939
+ def __init__(self, client: AsyncAPIClient) -> None:
3940
+ self._client = client
3941
+
3942
+ async def list(
3943
+ self,
3944
+ id: str,
3945
+ *,
3946
+ resolved: Union[str, NotGiven] = NOT_GIVEN,
3947
+ extra_headers: Optional[Headers] = None,
3948
+ extra_query: Optional[Query] = None,
3949
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3950
+ ) -> List[ThreadView]:
3951
+ """`GET /api/v1/pages/{id}/comments`"""
3952
+ return await self._client._call(
3953
+ "GET",
3954
+ f"/pages/{_p(id)}/comments",
3955
+ query={"resolved": resolved},
3956
+ unwrap="threads",
3957
+ cast=List[ThreadView],
3958
+ extra_headers=extra_headers,
3959
+ extra_query=extra_query,
3960
+ timeout=timeout,
3961
+ )
3962
+
3963
+ async def create(
3964
+ self,
3965
+ id: str,
3966
+ *,
3967
+ body: str,
3968
+ anchor: Union[Union[Anchor, Dict[str, Any]], None, NotGiven] = NOT_GIVEN,
3969
+ notify: Union[Notify, None, NotGiven] = NOT_GIVEN,
3970
+ extra_headers: Optional[Headers] = None,
3971
+ extra_query: Optional[Query] = None,
3972
+ extra_body: Optional[Body] = None,
3973
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3974
+ ) -> ThreadView:
3975
+ """`POST /api/v1/pages/{id}/comments`"""
3976
+ return await self._client._call(
3977
+ "POST",
3978
+ f"/pages/{_p(id)}/comments",
3979
+ body={"anchor": anchor, "body": body, "notify": notify},
3980
+ extra_body=extra_body,
3981
+ cast=ThreadView,
3982
+ extra_headers=extra_headers,
3983
+ extra_query=extra_query,
3984
+ timeout=timeout,
3985
+ )
3986
+
3987
+ async def update(
3988
+ self,
3989
+ id: str,
3990
+ *,
3991
+ resolved: bool,
3992
+ extra_headers: Optional[Headers] = None,
3993
+ extra_query: Optional[Query] = None,
3994
+ extra_body: Optional[Body] = None,
3995
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
3996
+ ) -> ThreadView:
3997
+ """`PATCH /api/v1/threads/{id}`"""
3998
+ return await self._client._call(
3999
+ "PATCH",
4000
+ f"/threads/{_p(id)}",
4001
+ body={"resolved": resolved},
4002
+ extra_body=extra_body,
4003
+ cast=ThreadView,
4004
+ extra_headers=extra_headers,
4005
+ extra_query=extra_query,
4006
+ timeout=timeout,
4007
+ )
4008
+
4009
+ async def reply(
4010
+ self,
4011
+ id: str,
4012
+ *,
4013
+ body: str,
4014
+ notify: Union[Notify, None, NotGiven] = NOT_GIVEN,
4015
+ extra_headers: Optional[Headers] = None,
4016
+ extra_query: Optional[Query] = None,
4017
+ extra_body: Optional[Body] = None,
4018
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
4019
+ ) -> CommentView:
4020
+ """`POST /api/v1/threads/{id}/comments`"""
4021
+ return await self._client._call(
4022
+ "POST",
4023
+ f"/threads/{_p(id)}/comments",
4024
+ body={"body": body, "notify": notify},
4025
+ extra_body=extra_body,
4026
+ cast=CommentView,
4027
+ extra_headers=extra_headers,
4028
+ extra_query=extra_query,
4029
+ timeout=timeout,
4030
+ )
4031
+
4032
+
4033
+ class AsyncTrashResource:
4034
+ """`client.trash`"""
4035
+
4036
+ def __init__(self, client: AsyncAPIClient) -> None:
4037
+ self._client = client
4038
+
4039
+ def list(
4040
+ self,
4041
+ ws: str,
4042
+ *,
4043
+ limit: Union[int, NotGiven] = NOT_GIVEN,
4044
+ cursor: Union[str, NotGiven] = NOT_GIVEN,
4045
+ extra_headers: Optional[Headers] = None,
4046
+ extra_query: Optional[Query] = None,
4047
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
4048
+ ) -> AsyncPaginator[TrashItem]:
4049
+ """`GET /api/v1/workspaces/{ws}/trash`"""
4050
+ return self._client._call_page(
4051
+ "GET",
4052
+ f"/workspaces/{_p(ws)}/trash",
4053
+ query={"limit": limit, "cursor": cursor},
4054
+ model=TrashList,
4055
+ items="items",
4056
+ item=TrashItem,
4057
+ extra_headers=extra_headers,
4058
+ extra_query=extra_query,
4059
+ timeout=timeout,
4060
+ )
4061
+
4062
+ async def restore(
4063
+ self,
4064
+ id: str,
4065
+ *,
4066
+ extra_headers: Optional[Headers] = None,
4067
+ extra_query: Optional[Query] = None,
4068
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
4069
+ ) -> RestoredPage:
4070
+ """`POST /api/v1/trash/{id}/restore`"""
4071
+ return await self._client._call(
4072
+ "POST",
4073
+ f"/trash/{_p(id)}/restore",
4074
+ cast=RestoredPage,
4075
+ extra_headers=extra_headers,
4076
+ extra_query=extra_query,
4077
+ timeout=timeout,
4078
+ )
4079
+
4080
+ async def purge(
4081
+ self,
4082
+ id: str,
4083
+ *,
4084
+ extra_headers: Optional[Headers] = None,
4085
+ extra_query: Optional[Query] = None,
4086
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
4087
+ ) -> None:
4088
+ """`DELETE /api/v1/trash/{id}`"""
4089
+ return await self._client._call(
4090
+ "DELETE",
4091
+ f"/trash/{_p(id)}",
4092
+ cast=type(None),
4093
+ extra_headers=extra_headers,
4094
+ extra_query=extra_query,
4095
+ timeout=timeout,
4096
+ )
4097
+
4098
+
4099
+ class AsyncWorkspacesMembersResource:
4100
+ """`client.workspaces.members`"""
4101
+
4102
+ def __init__(self, client: AsyncAPIClient) -> None:
4103
+ self._client = client
4104
+
4105
+ async def list(
4106
+ self,
4107
+ ws: str,
4108
+ *,
4109
+ extra_headers: Optional[Headers] = None,
4110
+ extra_query: Optional[Query] = None,
4111
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
4112
+ ) -> MemberList:
4113
+ """`GET /api/v1/workspaces/{ws}/members`"""
4114
+ return await self._client._call(
4115
+ "GET",
4116
+ f"/workspaces/{_p(ws)}/members",
4117
+ cast=MemberList,
4118
+ extra_headers=extra_headers,
4119
+ extra_query=extra_query,
4120
+ timeout=timeout,
4121
+ )
4122
+
4123
+ async def set_role(
4124
+ self,
4125
+ ws: str,
4126
+ user: str,
4127
+ *,
4128
+ role: str,
4129
+ extra_headers: Optional[Headers] = None,
4130
+ extra_query: Optional[Query] = None,
4131
+ extra_body: Optional[Body] = None,
4132
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
4133
+ ) -> MemberRole:
4134
+ """`PATCH /api/v1/workspaces/{ws}/members/{user}`"""
4135
+ return await self._client._call(
4136
+ "PATCH",
4137
+ f"/workspaces/{_p(ws)}/members/{_p(user)}",
4138
+ body={"role": role},
4139
+ extra_body=extra_body,
4140
+ cast=MemberRole,
4141
+ extra_headers=extra_headers,
4142
+ extra_query=extra_query,
4143
+ timeout=timeout,
4144
+ )
4145
+
4146
+ async def remove(
4147
+ self,
4148
+ ws: str,
4149
+ user: str,
4150
+ *,
4151
+ extra_headers: Optional[Headers] = None,
4152
+ extra_query: Optional[Query] = None,
4153
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
4154
+ ) -> None:
4155
+ """`DELETE /api/v1/workspaces/{ws}/members/{user}`"""
4156
+ return await self._client._call(
4157
+ "DELETE",
4158
+ f"/workspaces/{_p(ws)}/members/{_p(user)}",
4159
+ cast=type(None),
4160
+ extra_headers=extra_headers,
4161
+ extra_query=extra_query,
4162
+ timeout=timeout,
4163
+ )
4164
+
4165
+
4166
+ class AsyncWorkspacesResource:
4167
+ """`client.workspaces`"""
4168
+
4169
+ def __init__(self, client: AsyncAPIClient) -> None:
4170
+ self._client = client
4171
+
4172
+ @cached_property
4173
+ def members(self) -> AsyncWorkspacesMembersResource:
4174
+ return AsyncWorkspacesMembersResource(self._client)
4175
+
4176
+ async def update(
4177
+ self,
4178
+ ws: str,
4179
+ *,
4180
+ icon: Union[str, None, NotGiven] = NOT_GIVEN,
4181
+ name: Union[str, None, NotGiven] = NOT_GIVEN,
4182
+ extra_headers: Optional[Headers] = None,
4183
+ extra_query: Optional[Query] = None,
4184
+ extra_body: Optional[Body] = None,
4185
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
4186
+ ) -> Workspace:
4187
+ """改工作区的名字、图标(admin 以上)。
4188
+
4189
+ `PATCH /api/v1/workspaces/{ws}`
4190
+ """
4191
+ return await self._client._call(
4192
+ "PATCH",
4193
+ f"/workspaces/{_p(ws)}",
4194
+ body={"icon": icon, "name": name},
4195
+ extra_body=extra_body,
4196
+ cast=Workspace,
4197
+ extra_headers=extra_headers,
4198
+ extra_query=extra_query,
4199
+ timeout=timeout,
4200
+ )
4201
+
4202
+ def events(
4203
+ self,
4204
+ ws: str,
4205
+ *,
4206
+ extra_headers: Optional[Headers] = None,
4207
+ extra_query: Optional[Query] = None,
4208
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
4209
+ ) -> AsyncEventStream:
4210
+ """SSE:工作区的实时事件,事件名和数据见 webhooks(page.created、db.changed……)。慢了会收到 resync。
4211
+
4212
+ `GET /api/v1/workspaces/{ws}/events`
4213
+ """
4214
+ return self._client._stream(
4215
+ f"/workspaces/{_p(ws)}/events",
4216
+ kind="workspace",
4217
+ extra_headers=extra_headers,
4218
+ extra_query=extra_query,
4219
+ timeout=timeout,
4220
+ )
4221
+
4222
+
4223
+ class AsyncResources(AsyncAPIClient):
4224
+ """客户端上的资源和方法(生成的);Client / AsyncClient 继承它。"""
4225
+
4226
+ @cached_property
4227
+ def agent(self) -> AsyncAgentResource:
4228
+ return AsyncAgentResource(self)
4229
+
4230
+ @cached_property
4231
+ def agents(self) -> AsyncAgentsResource:
4232
+ return AsyncAgentsResource(self)
4233
+
4234
+ @cached_property
4235
+ def auth(self) -> AsyncAuthResource:
4236
+ return AsyncAuthResource(self)
4237
+
4238
+ @cached_property
4239
+ def comments(self) -> AsyncCommentsResource:
4240
+ return AsyncCommentsResource(self)
4241
+
4242
+ @cached_property
4243
+ def databases(self) -> AsyncDatabasesResource:
4244
+ return AsyncDatabasesResource(self)
4245
+
4246
+ @cached_property
4247
+ def files(self) -> AsyncFilesResource:
4248
+ return AsyncFilesResource(self)
4249
+
4250
+ @cached_property
4251
+ def invites(self) -> AsyncInvitesResource:
4252
+ return AsyncInvitesResource(self)
4253
+
4254
+ @cached_property
4255
+ def links(self) -> AsyncLinksResource:
4256
+ return AsyncLinksResource(self)
4257
+
4258
+ @cached_property
4259
+ def me(self) -> AsyncMeResource:
4260
+ return AsyncMeResource(self)
4261
+
4262
+ @cached_property
4263
+ def pages(self) -> AsyncPagesResource:
4264
+ return AsyncPagesResource(self)
4265
+
4266
+ @cached_property
4267
+ def threads(self) -> AsyncThreadsResource:
4268
+ return AsyncThreadsResource(self)
4269
+
4270
+ @cached_property
4271
+ def trash(self) -> AsyncTrashResource:
4272
+ return AsyncTrashResource(self)
4273
+
4274
+ @cached_property
4275
+ def workspaces(self) -> AsyncWorkspacesResource:
4276
+ return AsyncWorkspacesResource(self)
4277
+
4278
+ async def search(
4279
+ self,
4280
+ ws: str,
4281
+ *,
4282
+ q: str,
4283
+ limit: Union[int, NotGiven] = NOT_GIVEN,
4284
+ kind: Union[str, NotGiven] = NOT_GIVEN,
4285
+ per: Union[str, NotGiven] = NOT_GIVEN,
4286
+ extra_headers: Optional[Headers] = None,
4287
+ extra_query: Optional[Query] = None,
4288
+ timeout: Union[TimeoutTypes, NotGiven] = NOT_GIVEN,
4289
+ ) -> List[SearchResult]:
4290
+ """`GET /api/v1/workspaces/{ws}/search`"""
4291
+ return await self._call(
4292
+ "GET",
4293
+ f"/workspaces/{_p(ws)}/search",
4294
+ query={"q": q, "limit": limit, "kind": kind, "per": per},
4295
+ unwrap="results",
4296
+ cast=List[SearchResult],
4297
+ extra_headers=extra_headers,
4298
+ extra_query=extra_query,
4299
+ timeout=timeout,
4300
+ )