@gemies/sdk 8.0.0 → 9.0.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 +15 -0
- package/package.json +1 -1
- package/src/accounts.ts +0 -11
- 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,20 @@
|
|
|
1
1
|
# @gemies/sdk
|
|
2
2
|
|
|
3
|
+
## 9.0.0
|
|
4
|
+
|
|
5
|
+
Gemies acts for the person with Oxy's first-party authority (oxy ADR 0066): what the Oxy registry
|
|
6
|
+
declares for it, checked live by Oxy on every call. A channel, a linked Telegram or a gemie's
|
|
7
|
+
background work holds no Oxy task any more, so there is nothing to renew or reauthorise.
|
|
8
|
+
|
|
9
|
+
- **Breaking — channel task renewal is gone.** `useChannelTaskRenewal`, `useReauthorizeChannels`,
|
|
10
|
+
`renewChannelTasks`, `CHANNEL_TASK_KINDS` and the `ChannelTaskKind`, `ChannelTaskRef` and
|
|
11
|
+
`ChannelTaskRenewal` types are removed from `@gemies/sdk/accounts`, with the
|
|
12
|
+
`ACCOUNT_ROUTES.renewChannelTasks` route and the `accounts.channelTaskRenewal` query key. The API
|
|
13
|
+
no longer serves `POST /me/channel-tasks/renew` or `POST /me/accounts/:accountId/reauthorize`.
|
|
14
|
+
- **Breaking — `ConnectedAccount.oxyTaskState` is removed.** `useConnectedAccounts` only reads the
|
|
15
|
+
list. The person's off switches stay where they were: which gemie answers an account, whom it
|
|
16
|
+
answers, and removing the account.
|
|
17
|
+
|
|
3
18
|
## 8.0.0
|
|
4
19
|
|
|
5
20
|
Gemies talk to each other in real conversations (Gemies ADR 0042). A gemie that wants something from
|
package/package.json
CHANGED
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,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
|
-
}
|