@gemies/sdk 6.5.0 → 7.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 +23 -0
- package/package.json +1 -1
- package/src/accounts.ts +11 -0
- package/src/realtime/contract.ts +0 -2
- package/src/runtime/channel-tasks.ts +78 -0
- package/src/runtime/connected-accounts.ts +18 -16
- package/src/runtime/query-keys.ts +2 -0
- package/src/runtime/routes.ts +5 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @gemies/sdk
|
|
2
2
|
|
|
3
|
+
## 7.1.0
|
|
4
|
+
|
|
5
|
+
- **A person's channels keep their authority** (Gemies ADR 0037, amendment of 2026-11-14). Each
|
|
6
|
+
channel's Oxy task — a connected account a gemie answers, a system bot link, a gemie bot they
|
|
7
|
+
linked their Telegram to — lapses after the time Oxy gave it, and only their present session can
|
|
8
|
+
renew it. New in `@gemies/sdk/accounts`:
|
|
9
|
+
- `useChannelTaskRenewal()`: the silent renewal, once a session for the signed-in account. Mount
|
|
10
|
+
it once where the app is signed in (it draws nothing); it renews whatever is lapsed, undated or
|
|
11
|
+
within 30 days of its expiry (`POST /me/channel-tasks/renew`).
|
|
12
|
+
- `useReauthorizeChannels()`: the one tap, a mutation for the page a channel's notice opens
|
|
13
|
+
(`/channels/reauthorize`). It answers `{ renewed, failed }`, each a `ChannelTaskRef`.
|
|
14
|
+
- `renewChannelTasks(api)`, `CHANNEL_TASK_KINDS`, and the types `ChannelTaskKind`,
|
|
15
|
+
`ChannelTaskRef` and `ChannelTaskRenewal`.
|
|
16
|
+
- `useConnectedAccounts` renews through the same call when an answered account's task lapsed, once
|
|
17
|
+
for all of them, instead of one `POST /me/accounts/:id/reauthorize` per account.
|
|
18
|
+
|
|
19
|
+
## 7.0.0
|
|
20
|
+
|
|
21
|
+
- **Breaking: the `show.progress` realtime event is gone** (`REALTIME_SIGNAL_TYPES`, `RealtimeData`).
|
|
22
|
+
Gemies no longer generates podcasts: that is Syra's, which a gemie reaches through the Syra
|
|
23
|
+
connector. A host that listened for it (`useRealtimeEvent('show.progress', …)`) removes its shows
|
|
24
|
+
screens with it; the server stopped emitting the event in the same release.
|
|
25
|
+
|
|
3
26
|
## 6.5.0
|
|
4
27
|
|
|
5
28
|
- **A scheduled reply or task that ended without an answer reads as one.** The server stores it as
|
package/package.json
CHANGED
package/src/accounts.ts
CHANGED
|
@@ -4,6 +4,10 @@
|
|
|
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.
|
|
7
11
|
*/
|
|
8
12
|
export { GemieAccountGrants } from './components/accounts/GemieAccountGrants';
|
|
9
13
|
export type { GemieAccountGrantsProps } from './components/accounts/GemieAccountGrants';
|
|
@@ -31,3 +35,10 @@ export type {
|
|
|
31
35
|
GemieAccountStatus,
|
|
32
36
|
GrantableGemie,
|
|
33
37
|
} 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';
|
package/src/realtime/contract.ts
CHANGED
|
@@ -35,7 +35,6 @@ export const REALTIME_SIGNAL_TYPES = [
|
|
|
35
35
|
'room',
|
|
36
36
|
'presence',
|
|
37
37
|
'runtimes',
|
|
38
|
-
'show.progress',
|
|
39
38
|
'agent.activity',
|
|
40
39
|
] as const;
|
|
41
40
|
|
|
@@ -143,7 +142,6 @@ export interface RealtimeData {
|
|
|
143
142
|
};
|
|
144
143
|
presence: { readonly agentId: string; readonly online: boolean };
|
|
145
144
|
runtimes: Record<string, never>;
|
|
146
|
-
'show.progress': Record<string, unknown> & { readonly episodeId: string };
|
|
147
145
|
'agent.activity': Record<string, unknown> & {
|
|
148
146
|
readonly sessionId: string;
|
|
149
147
|
readonly agentId: string;
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
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';
|
|
4
5
|
import { errorStatus } from './error-utils';
|
|
5
6
|
import { gemieQueryKeys } from './query-keys';
|
|
6
7
|
import { ACCOUNT_ROUTES } from './routes';
|
|
@@ -88,9 +89,10 @@ export interface ConnectedAccountsAnswer {
|
|
|
88
89
|
|
|
89
90
|
/**
|
|
90
91
|
* The caller's accounts, each as its session is now with its grants, and what can be connected.
|
|
91
|
-
*
|
|
92
|
-
* kept; the person looking is the verified requester);
|
|
93
|
-
* inactive for the next visit to retry. An account nobody
|
|
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.
|
|
94
96
|
*/
|
|
95
97
|
export function useConnectedAccounts() {
|
|
96
98
|
const api = useGemieApi();
|
|
@@ -99,20 +101,20 @@ export function useConnectedAccounts() {
|
|
|
99
101
|
queryKey: gemieQueryKeys.accounts.all,
|
|
100
102
|
queryFn: async (): Promise<ConnectedAccountsAnswer> => {
|
|
101
103
|
const { data } = await api.get<ConnectedAccountsAnswer>(ACCOUNT_ROUTES.all);
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
.filter(
|
|
105
|
-
(account) => account.answeringGemieId && account.oxyTaskState === 'reauth_required',
|
|
106
|
-
)
|
|
107
|
-
.map(async (account) => {
|
|
108
|
-
try {
|
|
109
|
-
await api.post(`${ACCOUNT_ROUTES.one(account._id)}/reauthorize`);
|
|
110
|
-
account.oxyTaskState = 'active';
|
|
111
|
-
} catch {
|
|
112
|
-
/* Remains typed inactive; the next verified visit may retry. */
|
|
113
|
-
}
|
|
114
|
-
}),
|
|
104
|
+
const lapsed = data.accounts.filter(
|
|
105
|
+
(account) => account.answeringGemieId && account.oxyTaskState === 'reauth_required',
|
|
115
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
|
+
}
|
|
116
118
|
return data;
|
|
117
119
|
},
|
|
118
120
|
enabled: isAuthenticated,
|
|
@@ -32,6 +32,8 @@ export const gemieQueryKeys = {
|
|
|
32
32
|
all: ['connected-accounts'] as const,
|
|
33
33
|
qr: (accountId: string) => ['connected-account-qr', accountId] as const,
|
|
34
34
|
chats: (accountId: string) => ['connected-account-chats', accountId] as const,
|
|
35
|
+
/** The signed-in account's silent channel-task renewal, once a session (`channel-tasks.ts`). */
|
|
36
|
+
channelTaskRenewal: (userId: string) => ['channel-task-renewal', userId] as const,
|
|
35
37
|
},
|
|
36
38
|
/** An agent the chat is opened on: its profile and the state of its feature gates. */
|
|
37
39
|
agents: {
|
package/src/runtime/routes.ts
CHANGED
|
@@ -105,4 +105,9 @@ 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',
|
|
108
113
|
} as const;
|