@gemies/sdk 8.0.0 → 9.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/package.json +3 -3
- package/src/accounts.ts +0 -11
- package/src/components/ComposerSuggestions.tsx +5 -6
- package/src/components/GemieBetweenGemies.tsx +4 -4
- package/src/components/GemieChatHeader.tsx +8 -12
- package/src/components/GemieRecentConversations.tsx +4 -5
- package/src/components/RichBlocks.tsx +7 -6
- package/src/components/thought/FilesAndSources.tsx +18 -13
- package/src/components/thread/GemieConversationCard.tsx +21 -15
- package/src/components/thread/ThreadSearch.tsx +4 -4
- package/src/runtime/connected-accounts.ts +2 -24
- package/src/runtime/query-keys.ts +0 -2
- package/src/runtime/routes.ts +0 -5
- package/src/runtime/channel-tasks.ts +0 -78
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @gemies/sdk
|
|
2
2
|
|
|
3
|
+
## 9.1.0
|
|
4
|
+
|
|
5
|
+
Conversation lists, search results and file/source rows now use Bloom's shared ListItem. Group
|
|
6
|
+
conversation avatars use AvatarGroup's conversation layout, and header actions use Button.Group
|
|
7
|
+
with the same Button component as standalone actions. Existing SDK exports, callbacks and
|
|
8
|
+
conversation behavior remain unchanged.
|
|
9
|
+
|
|
10
|
+
Requires Bloom 22 or later and Services 14.22 or later; earlier Services versions import Bloom
|
|
11
|
+
components removed in version 22.
|
|
12
|
+
|
|
13
|
+
## 9.0.0
|
|
14
|
+
|
|
15
|
+
Gemies acts for the person with Oxy's first-party authority (oxy ADR 0066): what the Oxy registry
|
|
16
|
+
declares for it, checked live by Oxy on every call. A channel, a linked Telegram or a gemie's
|
|
17
|
+
background work holds no Oxy task any more, so there is nothing to renew or reauthorise.
|
|
18
|
+
|
|
19
|
+
- **Breaking — channel task renewal is gone.** `useChannelTaskRenewal`, `useReauthorizeChannels`,
|
|
20
|
+
`renewChannelTasks`, `CHANNEL_TASK_KINDS` and the `ChannelTaskKind`, `ChannelTaskRef` and
|
|
21
|
+
`ChannelTaskRenewal` types are removed from `@gemies/sdk/accounts`, with the
|
|
22
|
+
`ACCOUNT_ROUTES.renewChannelTasks` route and the `accounts.channelTaskRenewal` query key. The API
|
|
23
|
+
no longer serves `POST /me/channel-tasks/renew` or `POST /me/accounts/:accountId/reauthorize`.
|
|
24
|
+
- **Breaking — `ConnectedAccount.oxyTaskState` is removed.** `useConnectedAccounts` only reads the
|
|
25
|
+
list. The person's off switches stay where they were: which gemie answers an account, whom it
|
|
26
|
+
answers, and removing the account.
|
|
27
|
+
|
|
3
28
|
## 8.0.0
|
|
4
29
|
|
|
5
30
|
Gemies talk to each other in real conversations (Gemies ADR 0042). A gemie that wants something from
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gemies/sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.1.0",
|
|
4
4
|
"description": "The Gemies SDK: the conversation runtime, chat UI, voice calls and dictation for Oxy apps that talk to a gemie",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"react-native": "src/index.ts",
|
|
@@ -60,9 +60,9 @@
|
|
|
60
60
|
"react": "^19.2.3",
|
|
61
61
|
"react-native": "^0.86.0 || ^0.88.0",
|
|
62
62
|
"@expo/vector-icons": "^15.1.1",
|
|
63
|
-
"@oxy.so/bloom": ">=
|
|
63
|
+
"@oxy.so/bloom": ">=22.0.0",
|
|
64
64
|
"@oxy.so/core": ">=7.1.0 <8",
|
|
65
|
-
"@oxy.so/services": ">=14.
|
|
65
|
+
"@oxy.so/services": ">=14.22.0 <15",
|
|
66
66
|
"@tanstack/react-query": "^5.101",
|
|
67
67
|
"@react-native-async-storage/async-storage": "^2.2.0",
|
|
68
68
|
"expo-blur": "^57.0.0 || ^58.0.0",
|
package/src/accounts.ts
CHANGED
|
@@ -4,10 +4,6 @@
|
|
|
4
4
|
* person connects once and grants to their gemies. `GemieConnectedAccounts` is Settings ›
|
|
5
5
|
* Connected accounts; `GemieAccountGrants` is the list of them a gemie's editor shows, one switch
|
|
6
6
|
* each. Its own entry so an app that does not draw them never reaches the QR encoder.
|
|
7
|
-
*
|
|
8
|
-
* Every channel's Oxy task is renewed from here too (`runtime/channel-tasks.ts`): mount
|
|
9
|
-
* `useChannelTaskRenewal` once where the app is signed in, and `useReauthorizeChannels` on the page
|
|
10
|
-
* a channel's notice opens.
|
|
11
7
|
*/
|
|
12
8
|
export { GemieAccountGrants } from './components/accounts/GemieAccountGrants';
|
|
13
9
|
export type { GemieAccountGrantsProps } from './components/accounts/GemieAccountGrants';
|
|
@@ -35,10 +31,3 @@ export type {
|
|
|
35
31
|
GemieAccountStatus,
|
|
36
32
|
GrantableGemie,
|
|
37
33
|
} from './runtime/connected-accounts';
|
|
38
|
-
export {
|
|
39
|
-
CHANNEL_TASK_KINDS,
|
|
40
|
-
renewChannelTasks,
|
|
41
|
-
useChannelTaskRenewal,
|
|
42
|
-
useReauthorizeChannels,
|
|
43
|
-
} from './runtime/channel-tasks';
|
|
44
|
-
export type { ChannelTaskKind, ChannelTaskRef, ChannelTaskRenewal } from './runtime/channel-tasks';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ListItem } from '@oxy.so/bloom/list';
|
|
2
2
|
import { Text } from '@oxy.so/bloom/typography';
|
|
3
3
|
import { View } from 'react-native';
|
|
4
4
|
import type { Completion } from '../lib/suggestions';
|
|
@@ -23,12 +23,11 @@ export function ComposerSuggestions<T extends GemieSuggestion>({
|
|
|
23
23
|
{completions.map(({ suggestion, matchStart, matchEnd }, index) => {
|
|
24
24
|
const { text } = suggestion;
|
|
25
25
|
return (
|
|
26
|
-
<
|
|
26
|
+
<ListItem
|
|
27
27
|
key={suggestion.id}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
accessibilityLabel={text}
|
|
28
|
+
active={index === selected}
|
|
29
|
+
role="button"
|
|
30
|
+
label={text}
|
|
32
31
|
onPress={() => onPick(suggestion)}
|
|
33
32
|
title={
|
|
34
33
|
<Text numberOfLines={1}>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AgentAvatarProvider } from '@oxy.so/bloom/agent-avatar';
|
|
2
2
|
import type { AiChatThreadHandle } from '@oxy.so/bloom/ai-chat';
|
|
3
|
-
import {
|
|
3
|
+
import { Button } from '@oxy.so/bloom/button';
|
|
4
4
|
import { RiArrowLeftLine } from '@oxy.so/bloom/icons/RiArrowLeftLine';
|
|
5
5
|
import { PageHeader } from '@oxy.so/bloom/page-header';
|
|
6
6
|
import { Text } from '@oxy.so/bloom/typography';
|
|
@@ -80,14 +80,14 @@ function ConversationBetweenGemies({ conversationId, onBack }: GemieBetweenGemie
|
|
|
80
80
|
<View className="flex-1 bg-background" testID="gemie-conversation">
|
|
81
81
|
<PageHeader
|
|
82
82
|
leading={
|
|
83
|
-
<
|
|
84
|
-
<
|
|
83
|
+
<Button.Group accessibilityLabel={back}>
|
|
84
|
+
<Button
|
|
85
85
|
iconOnly
|
|
86
86
|
leadingIcon={RiArrowLeftLine}
|
|
87
87
|
accessibilityLabel={back}
|
|
88
88
|
onPress={onBack}
|
|
89
89
|
/>
|
|
90
|
-
</
|
|
90
|
+
</Button.Group>
|
|
91
91
|
}
|
|
92
92
|
title={participants ? <GemieParticipants participants={participants} /> : undefined}
|
|
93
93
|
titleAlign="center"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Button } from '@oxy.so/bloom/button';
|
|
2
2
|
import {
|
|
3
3
|
DropdownMenu,
|
|
4
4
|
DropdownMenuContent,
|
|
@@ -63,14 +63,14 @@ export const GemieChatHeader = memo(function GemieChatHeader({
|
|
|
63
63
|
leading={
|
|
64
64
|
leading ??
|
|
65
65
|
(onBack ? (
|
|
66
|
-
<
|
|
67
|
-
<
|
|
66
|
+
<Button.Group accessibilityLabel={labels.chatActions}>
|
|
67
|
+
<Button
|
|
68
68
|
iconOnly
|
|
69
69
|
leadingIcon={RiArrowLeftLine}
|
|
70
70
|
accessibilityLabel={labels.back}
|
|
71
71
|
onPress={onBack}
|
|
72
72
|
/>
|
|
73
|
-
</
|
|
73
|
+
</Button.Group>
|
|
74
74
|
) : undefined)
|
|
75
75
|
}
|
|
76
76
|
title={
|
|
@@ -83,9 +83,9 @@ export const GemieChatHeader = memo(function GemieChatHeader({
|
|
|
83
83
|
<>
|
|
84
84
|
{trailing}
|
|
85
85
|
{hasMessages ? (
|
|
86
|
-
<
|
|
86
|
+
<Button.Group accessibilityLabel={labels.chatActions}>
|
|
87
87
|
{onShare ? (
|
|
88
|
-
<
|
|
88
|
+
<Button
|
|
89
89
|
iconOnly
|
|
90
90
|
leadingIcon={RiShare2Line}
|
|
91
91
|
accessibilityLabel={labels.share}
|
|
@@ -94,11 +94,7 @@ export const GemieChatHeader = memo(function GemieChatHeader({
|
|
|
94
94
|
) : null}
|
|
95
95
|
<DropdownMenu>
|
|
96
96
|
<DropdownMenuTrigger asChild label={labels.more}>
|
|
97
|
-
<
|
|
98
|
-
iconOnly
|
|
99
|
-
leadingIcon={RiMoreFill}
|
|
100
|
-
accessibilityLabel={labels.more}
|
|
101
|
-
/>
|
|
97
|
+
<Button iconOnly leadingIcon={RiMoreFill} accessibilityLabel={labels.more} />
|
|
102
98
|
</DropdownMenuTrigger>
|
|
103
99
|
<DropdownMenuContent align="end">
|
|
104
100
|
{menu}
|
|
@@ -111,7 +107,7 @@ export const GemieChatHeader = memo(function GemieChatHeader({
|
|
|
111
107
|
</DropdownMenuItem>
|
|
112
108
|
</DropdownMenuContent>
|
|
113
109
|
</DropdownMenu>
|
|
114
|
-
</
|
|
110
|
+
</Button.Group>
|
|
115
111
|
) : null}
|
|
116
112
|
</>
|
|
117
113
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ListItem } from '@oxy.so/bloom/list';
|
|
2
2
|
import { Text } from '@oxy.so/bloom/typography';
|
|
3
3
|
import { useMemo } from 'react';
|
|
4
4
|
import { View } from 'react-native';
|
|
@@ -45,11 +45,10 @@ export function GemieRecentConversations({
|
|
|
45
45
|
{recent.map((conversation) => {
|
|
46
46
|
const title = conversation.title || labels.newChat;
|
|
47
47
|
return (
|
|
48
|
-
<
|
|
48
|
+
<ListItem
|
|
49
49
|
key={conversation.id}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
accessibilityLabel={title}
|
|
50
|
+
role="button"
|
|
51
|
+
label={title}
|
|
53
52
|
onPress={() => onOpen(conversation.id)}
|
|
54
53
|
title={<Text numberOfLines={1}>{title}</Text>}
|
|
55
54
|
trailing={
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
} from '@oxy.so/bloom/admonition';
|
|
10
10
|
import { Card, CardBody, CardHeader, CardTitle } from '@oxy.so/bloom/card';
|
|
11
11
|
import { RiExternalLinkLine } from '@oxy.so/bloom/icons/RiExternalLinkLine';
|
|
12
|
-
import {
|
|
12
|
+
import { ListItem } from '@oxy.so/bloom/list';
|
|
13
13
|
import { Rating } from '@oxy.so/bloom/rating';
|
|
14
14
|
import { Muted, Text } from '@oxy.so/bloom/typography';
|
|
15
15
|
import { Image } from './Image';
|
|
@@ -17,7 +17,7 @@ import { Linking, View } from 'react-native';
|
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* The rich blocks a reply can carry (```compactlist, ```banner, …), drawn with
|
|
20
|
-
* Bloom: a card per block, `
|
|
20
|
+
* Bloom: a card per block, `ListItem` rows, `Admonition` for a banner and `Rating`
|
|
21
21
|
* for a source's credibility. `ReplyMarkdown.tsx` parses the fences.
|
|
22
22
|
*/
|
|
23
23
|
|
|
@@ -37,11 +37,11 @@ export function CompactList({ title, items }: { title: string; items: CompactLis
|
|
|
37
37
|
<CardBody>
|
|
38
38
|
<View role="list">
|
|
39
39
|
{items.map((item, index) => (
|
|
40
|
-
<
|
|
40
|
+
<ListItem
|
|
41
41
|
key={index}
|
|
42
42
|
role="listitem"
|
|
43
43
|
title={item.title}
|
|
44
|
-
|
|
44
|
+
supporting={item.meta}
|
|
45
45
|
leading={
|
|
46
46
|
item.image ? (
|
|
47
47
|
<Image
|
|
@@ -151,12 +151,13 @@ export function Timeline({ title, items }: { title: string; items: TimelineItem[
|
|
|
151
151
|
<CardBody>
|
|
152
152
|
<View role="list">
|
|
153
153
|
{items.map((item, index) => (
|
|
154
|
-
<
|
|
154
|
+
<ListItem
|
|
155
155
|
key={index}
|
|
156
156
|
role="listitem"
|
|
157
157
|
leading={<Muted>{item.date}</Muted>}
|
|
158
158
|
title={item.title}
|
|
159
|
-
|
|
159
|
+
supporting={item.description}
|
|
160
|
+
supportingLines="adaptive"
|
|
160
161
|
/>
|
|
161
162
|
))}
|
|
162
163
|
</View>
|
|
@@ -9,13 +9,14 @@ import {
|
|
|
9
9
|
import { EmptyState } from '@oxy.so/bloom/empty-state';
|
|
10
10
|
import { RiFileTextLine } from '@oxy.so/bloom/icons/RiFileTextLine';
|
|
11
11
|
import { RiGlobalLine } from '@oxy.so/bloom/icons/RiGlobalLine';
|
|
12
|
-
import {
|
|
12
|
+
import { ListItem } from '@oxy.so/bloom/list';
|
|
13
13
|
import { useTheme } from '@oxy.so/bloom/theme';
|
|
14
14
|
import { useState } from 'react';
|
|
15
|
+
import { View } from 'react-native';
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* "Files and sources": what a turn produced and what it read, as two Bloom
|
|
18
|
-
* `Accordion` sections of `
|
|
19
|
+
* `Accordion` sections of `ListItem` rows.
|
|
19
20
|
*
|
|
20
21
|
* An output row is pressable only when the canvas holds its artifact to open;
|
|
21
22
|
* otherwise it is a labelled row and says so to assistive tech. A name is
|
|
@@ -77,15 +78,16 @@ export function FilesAndSources({
|
|
|
77
78
|
// button under it.
|
|
78
79
|
const openable = outputActions?.canOpen(output) === true;
|
|
79
80
|
return (
|
|
80
|
-
<
|
|
81
|
+
<ListItem
|
|
81
82
|
key={output.id}
|
|
82
83
|
role="listitem"
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
openable ? t('thought.openOutput', { name: output.name }) : output.name
|
|
84
|
+
leading={
|
|
85
|
+
<View pointerEvents="none">
|
|
86
|
+
<RiFileTextLine size="md" fill={colors.textSecondary} />
|
|
87
|
+
</View>
|
|
88
88
|
}
|
|
89
|
+
title={output.name}
|
|
90
|
+
label={openable ? t('thought.openOutput', { name: output.name }) : output.name}
|
|
89
91
|
onPress={openable ? () => outputActions?.open(output) : undefined}
|
|
90
92
|
/>
|
|
91
93
|
);
|
|
@@ -101,14 +103,17 @@ export function FilesAndSources({
|
|
|
101
103
|
<EmptyState variant="compact" description={t('thought.noSources')} />
|
|
102
104
|
) : (
|
|
103
105
|
sources.map((source, index) => (
|
|
104
|
-
<
|
|
106
|
+
<ListItem
|
|
105
107
|
key={source.url}
|
|
106
108
|
role="listitem"
|
|
107
|
-
|
|
108
|
-
|
|
109
|
+
leading={
|
|
110
|
+
<View pointerEvents="none">
|
|
111
|
+
<RiGlobalLine size="sm" fill={colors.textSecondary} />
|
|
112
|
+
</View>
|
|
113
|
+
}
|
|
109
114
|
title={source.title}
|
|
110
|
-
|
|
111
|
-
|
|
115
|
+
supporting={source.domain}
|
|
116
|
+
label={t('thought.sourceLabel', { n: index + 1, title: source.title })}
|
|
112
117
|
onPress={() => onOpenSource(source)}
|
|
113
118
|
/>
|
|
114
119
|
))
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AvatarGroup } from '@oxy.so/bloom/avatar-group';
|
|
2
2
|
import { AiChatMessageLine } from '@oxy.so/bloom/ai-chat';
|
|
3
3
|
import { Card } from '@oxy.so/bloom/card';
|
|
4
4
|
import { TypingDots } from '@oxy.so/bloom/chat-indicators';
|
|
5
5
|
import { RiArrowRightSLine } from '@oxy.so/bloom/icons/RiArrowRightSLine';
|
|
6
|
-
import {
|
|
6
|
+
import { ListItem } from '@oxy.so/bloom/list';
|
|
7
7
|
import { useRef, useState } from 'react';
|
|
8
|
+
import { View } from 'react-native';
|
|
8
9
|
import { useOpenGemieConversation } from '../../lib/gemie-conversation-opener';
|
|
9
10
|
import { useLabels } from '../../lib/labels';
|
|
10
11
|
import { agentCharacterOf } from '../../lib/participants';
|
|
@@ -90,26 +91,31 @@ export function GemieConversationCard({
|
|
|
90
91
|
return (
|
|
91
92
|
<AiChatMessageLine block>
|
|
92
93
|
<Card>
|
|
93
|
-
<
|
|
94
|
+
<ListItem
|
|
94
95
|
leading={
|
|
95
|
-
<
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
96
|
+
<View pointerEvents="none">
|
|
97
|
+
<AvatarGroup
|
|
98
|
+
layout="conversation"
|
|
99
|
+
motion="always"
|
|
100
|
+
size={STACK_SIZE}
|
|
101
|
+
items={[from, to].map((agent) => ({
|
|
102
|
+
id: agent.id,
|
|
103
|
+
name: agent.name,
|
|
104
|
+
kind: 'bot' as const,
|
|
105
|
+
character: agentCharacterOf(agent),
|
|
106
|
+
}))}
|
|
107
|
+
/>
|
|
108
|
+
</View>
|
|
103
109
|
}
|
|
104
110
|
title={title}
|
|
105
|
-
|
|
111
|
+
supporting={subtitle}
|
|
106
112
|
// The last thing said is a glimpse; the whole of it is one press away.
|
|
107
|
-
|
|
113
|
+
supportingLines={1}
|
|
108
114
|
trailing={talking ? <TypingDots /> : pressable ? <RiArrowRightSLine size="sm" /> : null}
|
|
109
115
|
{...(pressable
|
|
110
116
|
? {
|
|
111
|
-
|
|
112
|
-
|
|
117
|
+
role: 'button' as const,
|
|
118
|
+
label: `${title}. ${t('chat.gemiesOpen')}`,
|
|
113
119
|
onPress: () => open(conversationId),
|
|
114
120
|
}
|
|
115
121
|
: {})}
|
|
@@ -5,7 +5,7 @@ import { useLabels } from '../../lib/labels';
|
|
|
5
5
|
import { Button } from '@oxy.so/bloom/button';
|
|
6
6
|
import { Card, CardBody } from '@oxy.so/bloom/card';
|
|
7
7
|
import { RiCloseLine } from '@oxy.so/bloom/icons/RiCloseLine';
|
|
8
|
-
import {
|
|
8
|
+
import { ListItem } from '@oxy.so/bloom/list';
|
|
9
9
|
import { Search } from '@oxy.so/bloom/search';
|
|
10
10
|
import { Muted } from '@oxy.so/bloom/typography';
|
|
11
11
|
import { useState } from 'react';
|
|
@@ -24,7 +24,7 @@ import { ScrollView, View } from 'react-native';
|
|
|
24
24
|
* can read and not reach is a wall, so `onJump` is not an extra: it is what the
|
|
25
25
|
* hit is for.
|
|
26
26
|
*
|
|
27
|
-
* Bloom's `Search` for the field and
|
|
27
|
+
* Bloom's `Search` for the field and a `ListItem` per hit, on a `Card` floating
|
|
28
28
|
* over the top of the thread in its 768 column: the card is the surface, so
|
|
29
29
|
* nothing here paints one of its own.
|
|
30
30
|
*/
|
|
@@ -109,12 +109,12 @@ export const ThreadSearch = ({ thread, onJump, onClose }: ThreadSearchProps) =>
|
|
|
109
109
|
keyboardShouldPersistTaps="handled"
|
|
110
110
|
>
|
|
111
111
|
{found.map((hit) => (
|
|
112
|
-
<
|
|
112
|
+
<ListItem
|
|
113
113
|
// The cursor, never `messageId`: a message the server wrote
|
|
114
114
|
// has no client id, and `null` is not a key.
|
|
115
115
|
key={hit.cursor}
|
|
116
116
|
title={hit.snippet}
|
|
117
|
-
|
|
117
|
+
supporting={`${t(
|
|
118
118
|
hit.role === 'user' ? 'chat.searchThreadYou' : 'chat.searchThreadAgent',
|
|
119
119
|
)} · ${hitDay(hit.createdAt, locale)}`}
|
|
120
120
|
onPress={() => onJump(hit)}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { useOxy } from '@oxy.so/services/ui/client';
|
|
2
2
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
3
3
|
import { useGemieApi } from './api';
|
|
4
|
-
import { renewChannelTasks } from './channel-tasks';
|
|
5
4
|
import { errorStatus } from './error-utils';
|
|
6
5
|
import { gemieQueryKeys } from './query-keys';
|
|
7
6
|
import { ACCOUNT_ROUTES } from './routes';
|
|
@@ -46,7 +45,6 @@ export interface ConnectedAccount {
|
|
|
46
45
|
status: GemieAccountStatus;
|
|
47
46
|
/** Whether the platform lets a gemie write from it (Telegram Business); `null` elsewhere. */
|
|
48
47
|
canReply: boolean | null;
|
|
49
|
-
oxyTaskState: 'active' | 'reauth_required';
|
|
50
48
|
/** The gemies that may use it. */
|
|
51
49
|
gemieIds: string[];
|
|
52
50
|
/** The one that answers what arrives on it, or `null` when none does. */
|
|
@@ -87,13 +85,7 @@ export interface ConnectedAccountsAnswer {
|
|
|
87
85
|
platforms: GemieAccountPlatform[];
|
|
88
86
|
}
|
|
89
87
|
|
|
90
|
-
/**
|
|
91
|
-
* The caller's accounts, each as its session is now with its grants, and what can be connected.
|
|
92
|
-
* When an account's answering gemie's Oxy task lapsed, the person's channels are renewed on the way
|
|
93
|
-
* (`renewChannelTasks`: the provider link is kept; the person looking is the verified requester);
|
|
94
|
-
* one that could not be renewed stays typed inactive for the next visit to retry. An account nobody
|
|
95
|
-
* answers holds no task to renew.
|
|
96
|
-
*/
|
|
88
|
+
/** The caller's accounts, each as its session is now with its grants, and what can be connected. */
|
|
97
89
|
export function useConnectedAccounts() {
|
|
98
90
|
const api = useGemieApi();
|
|
99
91
|
const { isAuthenticated } = useOxy();
|
|
@@ -101,20 +93,6 @@ export function useConnectedAccounts() {
|
|
|
101
93
|
queryKey: gemieQueryKeys.accounts.all,
|
|
102
94
|
queryFn: async (): Promise<ConnectedAccountsAnswer> => {
|
|
103
95
|
const { data } = await api.get<ConnectedAccountsAnswer>(ACCOUNT_ROUTES.all);
|
|
104
|
-
const lapsed = data.accounts.filter(
|
|
105
|
-
(account) => account.answeringGemieId && account.oxyTaskState === 'reauth_required',
|
|
106
|
-
);
|
|
107
|
-
if (lapsed.length === 0) return data;
|
|
108
|
-
try {
|
|
109
|
-
const { renewed } = await renewChannelTasks(api);
|
|
110
|
-
for (const account of lapsed) {
|
|
111
|
-
if (renewed.some((ref) => ref.kind === 'account' && ref.id === account._id)) {
|
|
112
|
-
account.oxyTaskState = 'active';
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
} catch {
|
|
116
|
-
/* Remains typed inactive; the next verified visit may retry. */
|
|
117
|
-
}
|
|
118
96
|
return data;
|
|
119
97
|
},
|
|
120
98
|
enabled: isAuthenticated,
|
|
@@ -178,7 +156,7 @@ export interface ConnectedAccountPatch {
|
|
|
178
156
|
}
|
|
179
157
|
|
|
180
158
|
/**
|
|
181
|
-
* Connecting, granting, who answers, and removing (its session ends and its
|
|
159
|
+
* Connecting, granting, who answers, and removing (its session ends and its grants go).
|
|
182
160
|
* Every write re-reads the list, so each screen that shows an account shows it as it now is.
|
|
183
161
|
*/
|
|
184
162
|
export function useConnectedAccountMutations() {
|
|
@@ -37,8 +37,6 @@ export const gemieQueryKeys = {
|
|
|
37
37
|
all: ['connected-accounts'] as const,
|
|
38
38
|
qr: (accountId: string) => ['connected-account-qr', accountId] as const,
|
|
39
39
|
chats: (accountId: string) => ['connected-account-chats', accountId] as const,
|
|
40
|
-
/** The signed-in account's silent channel-task renewal, once a session (`channel-tasks.ts`). */
|
|
41
|
-
channelTaskRenewal: (userId: string) => ['channel-task-renewal', userId] as const,
|
|
42
40
|
},
|
|
43
41
|
/** An agent the chat is opened on: its profile and the state of its feature gates. */
|
|
44
42
|
agents: {
|
package/src/runtime/routes.ts
CHANGED
|
@@ -105,9 +105,4 @@ export const ACCOUNT_ROUTES = {
|
|
|
105
105
|
/** A gemie's grant of one account: `PUT` grants it, `DELETE` revokes it. */
|
|
106
106
|
grant: (accountId: string, gemieId: string) =>
|
|
107
107
|
`/me/accounts/${encodeURIComponent(accountId)}/gemies/${encodeURIComponent(gemieId)}`,
|
|
108
|
-
/**
|
|
109
|
-
* `POST` renews every channel of the caller whose Oxy task needs it — a connected account, a
|
|
110
|
-
* system bot link, a gemie bot they linked their Telegram to — with their present session.
|
|
111
|
-
*/
|
|
112
|
-
renewChannelTasks: '/me/channel-tasks/renew',
|
|
113
108
|
} as const;
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { useOxy } from '@oxy.so/services/ui/client';
|
|
2
|
-
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
3
|
-
import type { GemieApi } from './api';
|
|
4
|
-
import { useGemieApi } from './api';
|
|
5
|
-
import { errorStatus } from './error-utils';
|
|
6
|
-
import { gemieQueryKeys } from './query-keys';
|
|
7
|
-
import { ACCOUNT_ROUTES } from './routes';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* A person's channels' Oxy tasks: the authority each channel of theirs acts with — a connected
|
|
11
|
-
* account a gemie answers, a link to a system bot, a gemie's own Telegram bot they linked their
|
|
12
|
-
* Telegram to. Oxy lets only the person's present session mint one, so the apps renew them the
|
|
13
|
-
* way they renew every standing authority: silently while the person is in the app
|
|
14
|
-
* ({@link useChannelTaskRenewal}), and with one tap from the notice they get when a channel needs
|
|
15
|
-
* them ({@link useReauthorizeChannels}). The API renews only what is due: lapsed, undated, or
|
|
16
|
-
* lapsing within its renewal window.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
export const CHANNEL_TASK_KINDS = ['account', 'bot_link', 'gemie_bot'] as const;
|
|
20
|
-
export type ChannelTaskKind = (typeof CHANNEL_TASK_KINDS)[number];
|
|
21
|
-
|
|
22
|
-
/** One channel: its kind, and its own id (a connected account's `_id`, for an `account`). */
|
|
23
|
-
export interface ChannelTaskRef {
|
|
24
|
-
kind: ChannelTaskKind;
|
|
25
|
-
id: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** What one renewal did. */
|
|
29
|
-
export interface ChannelTaskRenewal {
|
|
30
|
-
renewed: ChannelTaskRef[];
|
|
31
|
-
/** The channels that still need the person: a gemie they may no longer grant, Oxy refusing. */
|
|
32
|
-
failed: ChannelTaskRef[];
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** Renew every channel of the signed-in person that needs it, with their present session. */
|
|
36
|
-
export async function renewChannelTasks(api: GemieApi): Promise<ChannelTaskRenewal> {
|
|
37
|
-
const { data } = await api.post<ChannelTaskRenewal>(ACCOUNT_ROUTES.renewChannelTasks);
|
|
38
|
-
return data;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* The silent handshake: once a session for the signed-in account, as the apps' agents' work
|
|
43
|
-
* handshake (`POST /agents/:id/work`). Mount it once, where the app is signed in; it draws
|
|
44
|
-
* nothing. A renewed connected account re-reads the accounts list.
|
|
45
|
-
*/
|
|
46
|
-
export function useChannelTaskRenewal(): void {
|
|
47
|
-
const api = useGemieApi();
|
|
48
|
-
const queryClient = useQueryClient();
|
|
49
|
-
const { user, isAuthenticated } = useOxy();
|
|
50
|
-
const userId = user?.id ?? '';
|
|
51
|
-
useQuery({
|
|
52
|
-
queryKey: gemieQueryKeys.accounts.channelTaskRenewal(userId),
|
|
53
|
-
queryFn: async () => {
|
|
54
|
-
const renewal = await renewChannelTasks(api);
|
|
55
|
-
if (renewal.renewed.some((ref) => ref.kind === 'account')) {
|
|
56
|
-
await queryClient.invalidateQueries({ queryKey: gemieQueryKeys.accounts.all });
|
|
57
|
-
}
|
|
58
|
-
return renewal;
|
|
59
|
-
},
|
|
60
|
-
enabled: isAuthenticated && userId !== '',
|
|
61
|
-
staleTime: Number.POSITIVE_INFINITY,
|
|
62
|
-
// A session that is not the person's (401/403) will not become theirs by asking again.
|
|
63
|
-
retry: (attempt, error) => attempt < 2 && ![401, 403].includes(errorStatus(error) ?? 0),
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* The one-tap reauthorisation the notice links to: the tap is the person's say-so, and their
|
|
69
|
-
* present session renews every channel that needs it. Re-reads the accounts list after.
|
|
70
|
-
*/
|
|
71
|
-
export function useReauthorizeChannels() {
|
|
72
|
-
const api = useGemieApi();
|
|
73
|
-
const queryClient = useQueryClient();
|
|
74
|
-
return useMutation({
|
|
75
|
-
mutationFn: () => renewChannelTasks(api),
|
|
76
|
-
onSuccess: () => queryClient.invalidateQueries({ queryKey: gemieQueryKeys.accounts.all }),
|
|
77
|
-
});
|
|
78
|
-
}
|