@teactjs/telegram 0.1.0-alpha.1
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/README.md +111 -0
- package/dist/index.js +8263 -0
- package/dist/react/src/callback-registry.d.ts +11 -0
- package/dist/react/src/callback-registry.d.ts.map +1 -0
- package/dist/react/src/components.d.ts +396 -0
- package/dist/react/src/components.d.ts.map +1 -0
- package/dist/react/src/error-boundary.d.ts +19 -0
- package/dist/react/src/error-boundary.d.ts.map +1 -0
- package/dist/react/src/hooks.d.ts +37 -0
- package/dist/react/src/hooks.d.ts.map +1 -0
- package/dist/react/src/index.d.ts +11 -0
- package/dist/react/src/index.d.ts.map +1 -0
- package/dist/renderer/src/index.d.ts +5 -0
- package/dist/renderer/src/index.d.ts.map +1 -0
- package/dist/renderer/src/nodes.d.ts +23 -0
- package/dist/renderer/src/nodes.d.ts.map +1 -0
- package/dist/renderer/src/renderer.d.ts +9 -0
- package/dist/renderer/src/renderer.d.ts.map +1 -0
- package/dist/renderer/src/types.d.ts +36 -0
- package/dist/renderer/src/types.d.ts.map +1 -0
- package/dist/runtime/src/auth-session.d.ts +51 -0
- package/dist/runtime/src/auth-session.d.ts.map +1 -0
- package/dist/runtime/src/auth.d.ts +37 -0
- package/dist/runtime/src/auth.d.ts.map +1 -0
- package/dist/runtime/src/bot.d.ts +143 -0
- package/dist/runtime/src/bot.d.ts.map +1 -0
- package/dist/runtime/src/config.d.ts +38 -0
- package/dist/runtime/src/config.d.ts.map +1 -0
- package/dist/runtime/src/context.d.ts +74 -0
- package/dist/runtime/src/context.d.ts.map +1 -0
- package/dist/runtime/src/conversation.d.ts +310 -0
- package/dist/runtime/src/conversation.d.ts.map +1 -0
- package/dist/runtime/src/event-hooks.d.ts +49 -0
- package/dist/runtime/src/event-hooks.d.ts.map +1 -0
- package/dist/runtime/src/i18n.d.ts +55 -0
- package/dist/runtime/src/i18n.d.ts.map +1 -0
- package/dist/runtime/src/index.d.ts +28 -0
- package/dist/runtime/src/index.d.ts.map +1 -0
- package/dist/runtime/src/invoice.d.ts +120 -0
- package/dist/runtime/src/invoice.d.ts.map +1 -0
- package/dist/runtime/src/media-hooks.d.ts +178 -0
- package/dist/runtime/src/media-hooks.d.ts.map +1 -0
- package/dist/runtime/src/middleware.d.ts +26 -0
- package/dist/runtime/src/middleware.d.ts.map +1 -0
- package/dist/runtime/src/plugin.d.ts +32 -0
- package/dist/runtime/src/plugin.d.ts.map +1 -0
- package/dist/runtime/src/router.d.ts +168 -0
- package/dist/runtime/src/router.d.ts.map +1 -0
- package/dist/runtime/src/session.d.ts +20 -0
- package/dist/runtime/src/session.d.ts.map +1 -0
- package/dist/runtime/src/stream.d.ts +34 -0
- package/dist/runtime/src/stream.d.ts.map +1 -0
- package/dist/telegram/src/adapter.d.ts +83 -0
- package/dist/telegram/src/adapter.d.ts.map +1 -0
- package/dist/telegram/src/conversations.d.ts +175 -0
- package/dist/telegram/src/conversations.d.ts.map +1 -0
- package/dist/telegram/src/index.d.ts +8 -0
- package/dist/telegram/src/index.d.ts.map +1 -0
- package/dist/telegram/src/serialize.d.ts +80 -0
- package/dist/telegram/src/serialize.d.ts.map +1 -0
- package/dist/telegram/src/stream.d.ts +12 -0
- package/dist/telegram/src/stream.d.ts.map +1 -0
- package/package.json +38 -0
- package/src/index.ts +7 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** Shape of auth data stored in the session. */
|
|
2
|
+
export interface AuthTokens {
|
|
3
|
+
accessToken: string;
|
|
4
|
+
refreshToken?: string;
|
|
5
|
+
expiresAt?: number;
|
|
6
|
+
}
|
|
7
|
+
/** Return value of `useAuthSession`. */
|
|
8
|
+
export interface AuthSessionState {
|
|
9
|
+
/** Whether the user is currently authenticated (has a non-expired access token). */
|
|
10
|
+
isAuthenticated: boolean;
|
|
11
|
+
/** The current access token, or `null` if not logged in. */
|
|
12
|
+
accessToken: string | null;
|
|
13
|
+
/** The current refresh token, or `null`. */
|
|
14
|
+
refreshToken: string | null;
|
|
15
|
+
/** Expiry timestamp (ms since epoch), or `null`. */
|
|
16
|
+
expiresAt: number | null;
|
|
17
|
+
/** Store auth tokens. Marks the session as authenticated. */
|
|
18
|
+
login(tokens: AuthTokens): void;
|
|
19
|
+
/** Clear all auth data. */
|
|
20
|
+
logout(): void;
|
|
21
|
+
/** Update the access token (e.g. after a refresh). */
|
|
22
|
+
setAccessToken(token: string, expiresAt?: number): void;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Token-based auth session hook.
|
|
26
|
+
*
|
|
27
|
+
* Stores `accessToken`, `refreshToken`, and `expiresAt` inside the
|
|
28
|
+
* per-chat session (backed by whatever `SessionStore` you configured —
|
|
29
|
+
* memory, file, or custom).
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```tsx
|
|
33
|
+
* const auth = useAuthSession();
|
|
34
|
+
*
|
|
35
|
+
* if (!auth.isAuthenticated) {
|
|
36
|
+
* return (
|
|
37
|
+
* <Message text="Please log in">
|
|
38
|
+
* <InlineKeyboard>
|
|
39
|
+
* <ButtonRow>
|
|
40
|
+
* <Button text="Login" onClick={() => auth.login({ accessToken: 'tok_abc' })} />
|
|
41
|
+
* </ButtonRow>
|
|
42
|
+
* </InlineKeyboard>
|
|
43
|
+
* </Message>
|
|
44
|
+
* );
|
|
45
|
+
* }
|
|
46
|
+
*
|
|
47
|
+
* return <Message text={`Logged in! Token: ${auth.accessToken}`} />;
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare function useAuthSession(): AuthSessionState;
|
|
51
|
+
//# sourceMappingURL=auth-session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-session.d.ts","sourceRoot":"","sources":["../../../../runtime/src/auth-session.ts"],"names":[],"mappings":"AAGA,gDAAgD;AAChD,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wCAAwC;AACxC,MAAM,WAAW,gBAAgB;IAC/B,oFAAoF;IACpF,eAAe,EAAE,OAAO,CAAC;IACzB,4DAA4D;IAC5D,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,4CAA4C;IAC5C,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,oDAAoD;IACpD,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,6DAA6D;IAC7D,KAAK,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;IAChC,2BAA2B;IAC3B,MAAM,IAAI,IAAI,CAAC;IACf,sDAAsD;IACtD,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACzD;AAID;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,cAAc,IAAI,gBAAgB,CA+BjD"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { TeactPlugin } from './plugin';
|
|
2
|
+
export interface AuthConfig {
|
|
3
|
+
/** Telegram user IDs with admin access. Admins implicitly have all roles. */
|
|
4
|
+
admins?: (string | number)[];
|
|
5
|
+
/** Named roles mapped to arrays of user IDs. */
|
|
6
|
+
roles?: Record<string, (string | number)[]>;
|
|
7
|
+
}
|
|
8
|
+
export interface AuthState {
|
|
9
|
+
userId: string;
|
|
10
|
+
isAdmin: boolean;
|
|
11
|
+
/** The user's highest role, or null if none. */
|
|
12
|
+
role: string | null;
|
|
13
|
+
/** Check if the current user has a specific role. Admins pass all checks. */
|
|
14
|
+
is(role: string): boolean;
|
|
15
|
+
/** Check if the current user has at least one of the given roles. */
|
|
16
|
+
hasAny(...roles: string[]): boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Access the current user's auth state.
|
|
20
|
+
* Requires `authPlugin()` to be registered.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* const { isAdmin, is } = useAuth();
|
|
24
|
+
* if (!is('moderator')) return <Message text="Access denied" />;
|
|
25
|
+
*/
|
|
26
|
+
export declare function useAuth(): AuthState;
|
|
27
|
+
/**
|
|
28
|
+
* Role-based auth plugin.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* authPlugin({
|
|
32
|
+
* admins: [123456789],
|
|
33
|
+
* roles: { moderator: [987654321, 111222333] },
|
|
34
|
+
* })
|
|
35
|
+
*/
|
|
36
|
+
export declare function authPlugin(config?: AuthConfig): TeactPlugin;
|
|
37
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../../runtime/src/auth.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAG5C,MAAM,WAAW,UAAU;IACzB,6EAA6E;IAC7E,MAAM,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAC7B,gDAAgD;IAChD,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;CAC7C;AAED,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,gDAAgD;IAChD,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,6EAA6E;IAC7E,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAC1B,qEAAqE;IACrE,MAAM,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;CACrC;AAID;;;;;;;GAOG;AACH,wBAAgB,OAAO,IAAI,SAAS,CAInC;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,MAAM,GAAE,UAAe,GAAG,WAAW,CA6C/D"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import type { FunctionComponent, ReactNode } from 'react';
|
|
2
|
+
import { type TeactRoot, type SessionStore, type Middleware } from '@teactjs/renderer';
|
|
3
|
+
import { TelegramAdapter } from '@teactjs/telegram';
|
|
4
|
+
import { type CallbackMap } from '@teactjs/react';
|
|
5
|
+
import { type RouterConfig, type CommitModeRef } from './router';
|
|
6
|
+
import type { TeactPlugin } from './plugin';
|
|
7
|
+
/** A button in an inline keyboard sent via {@link CommandContext.reply}. */
|
|
8
|
+
export interface ReplyButton {
|
|
9
|
+
text: string;
|
|
10
|
+
url?: string;
|
|
11
|
+
route?: string;
|
|
12
|
+
}
|
|
13
|
+
/** A button in a custom reply keyboard sent via {@link CommandContext.reply}. */
|
|
14
|
+
export interface ReplyKeyboardButton {
|
|
15
|
+
text: string;
|
|
16
|
+
requestContact?: boolean;
|
|
17
|
+
requestLocation?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/** Options for {@link CommandContext.reply}. */
|
|
20
|
+
export interface ReplyOptions {
|
|
21
|
+
/** Inline keyboard rows. */
|
|
22
|
+
buttons?: ReplyButton[][];
|
|
23
|
+
/** Custom reply keyboard rows. */
|
|
24
|
+
replyKeyboard?: ReplyKeyboardButton[][];
|
|
25
|
+
}
|
|
26
|
+
/** Context object passed to command handlers defined in `commands`. */
|
|
27
|
+
export interface CommandContext {
|
|
28
|
+
args: string[];
|
|
29
|
+
reply: (text: string, options?: ReplyOptions) => Promise<void>;
|
|
30
|
+
chatId: string;
|
|
31
|
+
user: {
|
|
32
|
+
id: string;
|
|
33
|
+
username?: string;
|
|
34
|
+
firstName?: string;
|
|
35
|
+
};
|
|
36
|
+
platform: string;
|
|
37
|
+
raw: any;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Definition of a bot command registered via `createBot({ commands })`.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* const commands = {
|
|
44
|
+
* start: { description: 'Start the bot', route: '/' },
|
|
45
|
+
* help: { description: 'Show help', handler: 'Use /start to begin.' },
|
|
46
|
+
* echo: { description: 'Echo args', handler: async (ctx) => ctx.reply(ctx.args.join(' ')) },
|
|
47
|
+
* };
|
|
48
|
+
*/
|
|
49
|
+
export interface CommandDef {
|
|
50
|
+
description: string;
|
|
51
|
+
/** A static string reply, or an async handler function. */
|
|
52
|
+
handler?: string | ((ctx: CommandContext) => Promise<void> | void);
|
|
53
|
+
/** Route to navigate to when the command is triggered. */
|
|
54
|
+
route?: string;
|
|
55
|
+
/** Resolve deep-link parameters (e.g. `/start payload`) into a route path. */
|
|
56
|
+
deepLink?: (args: string[]) => string;
|
|
57
|
+
}
|
|
58
|
+
/** Webhook server configuration for production deployments. */
|
|
59
|
+
export interface WebhookConfig {
|
|
60
|
+
domain: string;
|
|
61
|
+
port?: number;
|
|
62
|
+
path?: string;
|
|
63
|
+
secretToken?: string;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Options for {@link createBot}.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* createBot({
|
|
70
|
+
* adapter: new TelegramAdapter(),
|
|
71
|
+
* router: createRouter({ '/': Home }),
|
|
72
|
+
* commands: { start: { description: 'Start', route: '/' } },
|
|
73
|
+
* });
|
|
74
|
+
*/
|
|
75
|
+
export interface CreateBotOptions {
|
|
76
|
+
component?: FunctionComponent<any>;
|
|
77
|
+
router?: RouterConfig;
|
|
78
|
+
providers?: FunctionComponent<{
|
|
79
|
+
children: ReactNode;
|
|
80
|
+
}>;
|
|
81
|
+
adapter: TelegramAdapter;
|
|
82
|
+
token?: string;
|
|
83
|
+
/** @default 'polling' — overrides teact.config */
|
|
84
|
+
mode?: 'polling' | 'webhook';
|
|
85
|
+
/** Webhook configuration — overrides teact.config */
|
|
86
|
+
webhook?: WebhookConfig;
|
|
87
|
+
session?: {
|
|
88
|
+
store?: SessionStore;
|
|
89
|
+
ttl?: number;
|
|
90
|
+
};
|
|
91
|
+
/** Additional middleware — merged with teact.config middleware */
|
|
92
|
+
middleware?: Middleware[];
|
|
93
|
+
/** Additional plugins — merged with teact.config plugins */
|
|
94
|
+
plugins?: TeactPlugin[];
|
|
95
|
+
/** Bot commands (stays in the React/app layer, not in config) */
|
|
96
|
+
commands?: Record<string, CommandDef>;
|
|
97
|
+
/** Experimental feature flags for opt-in features. */
|
|
98
|
+
experimental?: Record<string, unknown>;
|
|
99
|
+
/**
|
|
100
|
+
* Enable verbose debug logging.
|
|
101
|
+
* Logs every incoming update, render cycle, middleware execution, and errors
|
|
102
|
+
* with timestamps so you can diagnose stuck bots or unexpected behavior.
|
|
103
|
+
* @default false
|
|
104
|
+
*/
|
|
105
|
+
debug?: boolean;
|
|
106
|
+
}
|
|
107
|
+
interface ChatRoot {
|
|
108
|
+
root: TeactRoot;
|
|
109
|
+
handlers: CallbackMap;
|
|
110
|
+
chatId: string;
|
|
111
|
+
lastMessageId?: number;
|
|
112
|
+
commitQueue: Promise<void>;
|
|
113
|
+
commitMode: CommitModeRef;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Create and configure a Teact bot instance.
|
|
117
|
+
*
|
|
118
|
+
* Provide either a `component` (single-page) or a `router` (multi-page) for the UI.
|
|
119
|
+
* Call `.start()` on the returned object to connect and begin processing updates.
|
|
120
|
+
*
|
|
121
|
+
* @param options - Bot configuration including adapter, component/router, commands, and plugins.
|
|
122
|
+
* @returns A bot instance with `start()` and `stop()` methods.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* const bot = createBot({
|
|
126
|
+
* adapter: new TelegramAdapter(),
|
|
127
|
+
* router: createRouter({ '/': Home, '/settings': Settings }),
|
|
128
|
+
* commands: {
|
|
129
|
+
* start: { description: 'Start the bot', route: '/' },
|
|
130
|
+
* settings: { description: 'Open settings', route: '/settings' },
|
|
131
|
+
* },
|
|
132
|
+
* });
|
|
133
|
+
*
|
|
134
|
+
* bot.start();
|
|
135
|
+
*/
|
|
136
|
+
export declare function createBot(options: CreateBotOptions): {
|
|
137
|
+
start(): Promise<void>;
|
|
138
|
+
stop(): Promise<void>;
|
|
139
|
+
_chatRoots: Map<string, ChatRoot>;
|
|
140
|
+
_sessionStore: SessionStore;
|
|
141
|
+
};
|
|
142
|
+
export {};
|
|
143
|
+
//# sourceMappingURL=bot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bot.d.ts","sourceRoot":"","sources":["../../../../runtime/src/bot.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC1D,OAAO,EAAc,KAAK,SAAS,EAAoC,KAAK,YAAY,EAAE,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACrI,OAAO,EAAE,eAAe,EAAmB,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAwD,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAIxG,OAAO,EAAiC,KAAK,YAAY,EAAqB,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AACnH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AA8D5C,4EAA4E;AAC5E,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,iFAAiF;AACjF,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,gDAAgD;AAChD,MAAM,WAAW,YAAY;IAC3B,4BAA4B;IAC5B,OAAO,CAAC,EAAE,WAAW,EAAE,EAAE,CAAC;IAC1B,kCAAkC;IAClC,aAAa,CAAC,EAAE,mBAAmB,EAAE,EAAE,CAAC;CACzC;AAED,uEAAuE;AACvE,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/D,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC5D,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,GAAG,CAAC;CACV;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,2DAA2D;IAC3D,OAAO,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;IACnE,0DAA0D;IAC1D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,MAAM,CAAC;CACvC;AAED,+DAA+D;AAC/D,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,gBAAgB;IAC/B,SAAS,CAAC,EAAE,iBAAiB,CAAC,GAAG,CAAC,CAAC;IACnC,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,SAAS,CAAC,EAAE,iBAAiB,CAAC;QAAE,QAAQ,EAAE,SAAS,CAAA;KAAE,CAAC,CAAC;IACvD,OAAO,EAAE,eAAe,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kDAAkD;IAClD,IAAI,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;IAC7B,qDAAqD;IACrD,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,YAAY,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACjD,kEAAkE;IAClE,UAAU,CAAC,EAAE,UAAU,EAAE,CAAC;IAC1B,4DAA4D;IAC5D,OAAO,CAAC,EAAE,WAAW,EAAE,CAAC;IACxB,iEAAiE;IACjE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACtC,sDAAsD;IACtD,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC;;;;;OAKG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAID,UAAU,QAAQ;IAChB,IAAI,EAAE,SAAS,CAAC;IAChB,QAAQ,EAAE,WAAW,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,UAAU,EAAE,aAAa,CAAC;CAC3B;AA6CD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,gBAAgB;;;;;EAmXlD"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { TeactPlugin } from './plugin';
|
|
2
|
+
import type { WebhookConfig } from './bot';
|
|
3
|
+
import type { Middleware, SessionStore } from '@teactjs/renderer';
|
|
4
|
+
/**
|
|
5
|
+
* Infrastructure configuration for `teact.config.ts`.
|
|
6
|
+
* Commands and app logic belong in `createBot()` — this is for deployment settings only.
|
|
7
|
+
*/
|
|
8
|
+
export interface TeactConfig {
|
|
9
|
+
/** Transport mode. @default 'polling' */
|
|
10
|
+
mode?: 'polling' | 'webhook';
|
|
11
|
+
/** Webhook server settings (required when `mode` is `'webhook'`). */
|
|
12
|
+
webhook?: WebhookConfig;
|
|
13
|
+
/** Plugins loaded at startup (e.g. `storagePlugin()`, `authPlugin()`). */
|
|
14
|
+
plugins?: TeactPlugin[];
|
|
15
|
+
/** Global middleware that runs on every update. */
|
|
16
|
+
middleware?: Middleware[];
|
|
17
|
+
/** Session store override and TTL. */
|
|
18
|
+
session?: {
|
|
19
|
+
store?: SessionStore;
|
|
20
|
+
ttl?: number;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Type-safe config helper for `teact.config.ts`.
|
|
25
|
+
* Infrastructure-only — commands live in createBot() on the React side.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* // teact.config.ts
|
|
29
|
+
* import { defineConfig } from '@teactjs/core';
|
|
30
|
+
* import { storagePlugin } from '@teactjs/storage';
|
|
31
|
+
*
|
|
32
|
+
* export default defineConfig({
|
|
33
|
+
* mode: 'polling',
|
|
34
|
+
* plugins: [storagePlugin()],
|
|
35
|
+
* });
|
|
36
|
+
*/
|
|
37
|
+
export declare function defineConfig(config: TeactConfig): TeactConfig;
|
|
38
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../../runtime/src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAElE;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,yCAAyC;IACzC,IAAI,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;IAC7B,qEAAqE;IACrE,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,0EAA0E;IAC1E,OAAO,CAAC,EAAE,WAAW,EAAE,CAAC;IACxB,mDAAmD;IACnD,UAAU,CAAC,EAAE,UAAU,EAAE,CAAC;IAC1B,sCAAsC;IACtC,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,YAAY,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAClD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW,CAE7D"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { BotContext, SessionData } from '@teactjs/renderer';
|
|
3
|
+
/** Internal context value provided to all components during a render cycle. */
|
|
4
|
+
export interface RuntimeContextValue {
|
|
5
|
+
botCtx: BotContext;
|
|
6
|
+
session: SessionData;
|
|
7
|
+
updateSession: (patch: Partial<SessionData>) => void;
|
|
8
|
+
command: {
|
|
9
|
+
name: string;
|
|
10
|
+
args: string[];
|
|
11
|
+
} | null;
|
|
12
|
+
}
|
|
13
|
+
export declare const RuntimeContext: React.Context<RuntimeContextValue | null>;
|
|
14
|
+
/**
|
|
15
|
+
* Access the current bot context (chatId, userId, text, callbackData, raw update, etc.).
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* const { chatId, text, user } = useBot();
|
|
19
|
+
*/
|
|
20
|
+
export declare function useBot(): BotContext;
|
|
21
|
+
/**
|
|
22
|
+
* Read and write session data that persists across messages for the current chat.
|
|
23
|
+
*
|
|
24
|
+
* @returns A `[session, updateSession]` tuple (like `useState`).
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* const [session, setSession] = useSession<{ counter: number }>();
|
|
28
|
+
* setSession({ counter: (session.counter ?? 0) + 1 });
|
|
29
|
+
*/
|
|
30
|
+
export declare function useSession<T extends SessionData = SessionData>(): [T, (patch: Partial<T>) => void];
|
|
31
|
+
/**
|
|
32
|
+
* Returns the current platform name (e.g. `"telegram"`).
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* const platform = usePlatform(); // "telegram"
|
|
36
|
+
*/
|
|
37
|
+
export declare function usePlatform(): string;
|
|
38
|
+
/**
|
|
39
|
+
* Returns the current chat ID.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* const chatId = useChatId();
|
|
43
|
+
*/
|
|
44
|
+
export declare function useChatId(): string;
|
|
45
|
+
/**
|
|
46
|
+
* Returns the current message text, or `undefined` for callback queries.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* const text = useText();
|
|
50
|
+
* if (text === 'hello') return <Message text="Hi there!" />;
|
|
51
|
+
*/
|
|
52
|
+
export declare function useText(): string | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Returns the current callback data, or `undefined` for normal messages.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* const data = useCallbackData();
|
|
58
|
+
*/
|
|
59
|
+
export declare function useCallbackData(): string | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* Returns the command that triggered this render, or `null`.
|
|
62
|
+
*
|
|
63
|
+
* Only populated when a handler-less command falls through to the component tree.
|
|
64
|
+
* Useful in `useState` initializers to pick the starting screen based on the command.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* const cmd = useCommand();
|
|
68
|
+
* if (cmd?.name === 'settings') return <SettingsPage />;
|
|
69
|
+
*/
|
|
70
|
+
export declare function useCommand(): {
|
|
71
|
+
name: string;
|
|
72
|
+
args: string[];
|
|
73
|
+
} | null;
|
|
74
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../runtime/src/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAqB,MAAM,OAAO,CAAC;AAC1C,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEjE,+EAA+E;AAC/E,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,UAAU,CAAC;IACnB,OAAO,EAAE,WAAW,CAAC;IACrB,aAAa,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;IACrD,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,IAAI,CAAC;CAClD;AAED,eAAO,MAAM,cAAc,2CAAwD,CAAC;AAQpF;;;;;GAKG;AACH,wBAAgB,MAAM,IAAI,UAAU,CAEnC;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAGlG;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,IAAI,MAAM,CAEpC;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,IAAI,MAAM,CAElC;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,IAAI,MAAM,GAAG,SAAS,CAE5C;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,IAAI,MAAM,GAAG,SAAS,CAEpD;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,IAAI;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,GAAG,IAAI,CAEpE"}
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Validation function: return `true` to accept, or an error-message string.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* const notEmpty: ValidateFn = (v) => v.trim() ? true : 'Cannot be empty';
|
|
7
|
+
*/
|
|
8
|
+
export type ValidateFn = (value: string) => true | string;
|
|
9
|
+
/** Duck-typed Zod / Standard Schema — anything with a `.safeParse()` method. */
|
|
10
|
+
export interface SchemaLike {
|
|
11
|
+
safeParse(value: unknown): {
|
|
12
|
+
success: boolean;
|
|
13
|
+
error?: {
|
|
14
|
+
issues: Array<{
|
|
15
|
+
message: string;
|
|
16
|
+
}>;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Input validator — either a plain function or a Zod-compatible schema.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* // Function validator
|
|
25
|
+
* const v: Validator = (val) => val.length >= 2 || 'Too short';
|
|
26
|
+
*
|
|
27
|
+
* // Zod schema
|
|
28
|
+
* const v: Validator = z.string().min(2);
|
|
29
|
+
*/
|
|
30
|
+
export type Validator = ValidateFn | SchemaLike;
|
|
31
|
+
type AskOption = string | {
|
|
32
|
+
text: string;
|
|
33
|
+
value: string;
|
|
34
|
+
};
|
|
35
|
+
/** Navigation actions available inside custom render steps. */
|
|
36
|
+
export interface StepActions {
|
|
37
|
+
back(): void;
|
|
38
|
+
goTo(key: string): void;
|
|
39
|
+
canGoBack(): boolean;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A single conversation step definition:
|
|
43
|
+
* - `prompt` — wait for free-text input with optional validation
|
|
44
|
+
* - `ask` — present inline-keyboard buttons for selection
|
|
45
|
+
* - `render` — custom React element with manual `done()` callback
|
|
46
|
+
*/
|
|
47
|
+
export type StepDef = {
|
|
48
|
+
prompt: string;
|
|
49
|
+
validate?: Validator;
|
|
50
|
+
} | {
|
|
51
|
+
ask: string;
|
|
52
|
+
options: AskOption[][];
|
|
53
|
+
} | {
|
|
54
|
+
render: (done: (value?: string) => void, actions: StepActions) => React.ReactElement;
|
|
55
|
+
};
|
|
56
|
+
/** Map of step names to their definitions. */
|
|
57
|
+
export type StepsConfig = Record<string, StepDef>;
|
|
58
|
+
/** Navigation actions returned by `useConversation` for controlling flow. */
|
|
59
|
+
export interface ConversationActions {
|
|
60
|
+
goTo(key: string): void;
|
|
61
|
+
back(): void;
|
|
62
|
+
reset(): void;
|
|
63
|
+
clear(key: string): void;
|
|
64
|
+
canGoBack(): boolean;
|
|
65
|
+
}
|
|
66
|
+
/** Navigation actions returned by `useForm` for controlling form flow. */
|
|
67
|
+
export interface FormActions<K extends string = string> {
|
|
68
|
+
goTo(key: K): void;
|
|
69
|
+
back(): void;
|
|
70
|
+
reset(): void;
|
|
71
|
+
}
|
|
72
|
+
interface UseConversationOptions {
|
|
73
|
+
validate?: (key: string, value: string) => true | string;
|
|
74
|
+
}
|
|
75
|
+
export interface ConversationState<K extends string = string> {
|
|
76
|
+
has(key: K): boolean;
|
|
77
|
+
get(key: K): string | undefined;
|
|
78
|
+
set(key: K, value: string): void;
|
|
79
|
+
/** Remove a collected answer, causing that step to be re-asked. */
|
|
80
|
+
clear(key: K): void;
|
|
81
|
+
prompt(key: K, questionText: string): React.ReactElement;
|
|
82
|
+
ask(key: K, questionText: string, options: AskOption[][]): React.ReactElement;
|
|
83
|
+
waitFor(key: K): void;
|
|
84
|
+
/** Current step index (0-based). */
|
|
85
|
+
step: number;
|
|
86
|
+
/** Key of the current step, or null when complete. */
|
|
87
|
+
current: K | null;
|
|
88
|
+
/** True when all declared steps are done (always false in imperative mode). */
|
|
89
|
+
complete: boolean;
|
|
90
|
+
isWaiting: boolean;
|
|
91
|
+
data: Readonly<Record<K, string>>;
|
|
92
|
+
lastError: string | null;
|
|
93
|
+
/**
|
|
94
|
+
* Render the conversation flow.
|
|
95
|
+
*
|
|
96
|
+
* With a completion callback (recommended) — no `if` check needed:
|
|
97
|
+
* ```tsx
|
|
98
|
+
* return conv.render(() => <Message text="Done!" />);
|
|
99
|
+
* ```
|
|
100
|
+
*
|
|
101
|
+
* Without a callback — returns null when complete:
|
|
102
|
+
* ```tsx
|
|
103
|
+
* const el = conv.render();
|
|
104
|
+
* if (!el) return <Message text="Done!" />;
|
|
105
|
+
* return el;
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
render(onComplete: () => React.ReactElement): React.ReactElement;
|
|
109
|
+
render(): React.ReactElement | null;
|
|
110
|
+
/** Go back to the previous step. Clears that step's answer so it gets re-asked. */
|
|
111
|
+
back(): void;
|
|
112
|
+
/** Jump to a specific step. Clears that step's answer so it gets re-asked. After answering, resumes from there. */
|
|
113
|
+
goTo(key: K): void;
|
|
114
|
+
/** True when there is a previous step to go back to. */
|
|
115
|
+
canGoBack(): boolean;
|
|
116
|
+
reset(): void;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Multi-step conversation hook.
|
|
120
|
+
*
|
|
121
|
+
* @example Step-based (declarative)
|
|
122
|
+
* ```tsx
|
|
123
|
+
* const conv = useConversation({
|
|
124
|
+
* name: { prompt: "What's your name?" },
|
|
125
|
+
* rating: { ask: 'Rate us:', options: [['⭐ 1', '⭐⭐ 2']] },
|
|
126
|
+
* });
|
|
127
|
+
*
|
|
128
|
+
* return conv.render(() => (
|
|
129
|
+
* <Message text={`Thanks ${conv.data.name}! Rating: ${conv.data.rating}`} />
|
|
130
|
+
* ));
|
|
131
|
+
* ```
|
|
132
|
+
*
|
|
133
|
+
* @example Imperative (manual control)
|
|
134
|
+
* ```tsx
|
|
135
|
+
* const conv = useConversation();
|
|
136
|
+
* if (!conv.has('name')) return conv.prompt('name', "What's your name?");
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
export declare function useConversation<T extends StepsConfig>(config: T): ConversationState<Extract<keyof T, string>>;
|
|
140
|
+
export declare function useConversation(config?: UseConversationOptions): ConversationState;
|
|
141
|
+
export interface FormFieldDef {
|
|
142
|
+
/** Question text, or a function that receives collected data so far. */
|
|
143
|
+
prompt: string | ((data: Readonly<Record<string, string>>) => string);
|
|
144
|
+
/** If provided, show inline-keyboard buttons instead of waiting for text input. Each inner array is a row. */
|
|
145
|
+
options?: string[][];
|
|
146
|
+
/**
|
|
147
|
+
* Validate text input before accepting.
|
|
148
|
+
* - Function: `(v) => true | "error message"`
|
|
149
|
+
* - Zod schema: `z.string().min(2)`
|
|
150
|
+
* - Any object with `.safeParse()` (Standard Schema protocol)
|
|
151
|
+
*/
|
|
152
|
+
validate?: Validator;
|
|
153
|
+
}
|
|
154
|
+
export interface FormResult<K extends string = string> {
|
|
155
|
+
/** True when all fields have been collected. */
|
|
156
|
+
complete: boolean;
|
|
157
|
+
/** All collected answers, keyed by field name. */
|
|
158
|
+
data: Readonly<Record<K, string>>;
|
|
159
|
+
/**
|
|
160
|
+
* Render the form flow.
|
|
161
|
+
* ```tsx
|
|
162
|
+
* return form.render(() => <Message text={`Hello ${form.data.name}!`} />);
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
render(onComplete: () => React.ReactElement): React.ReactElement;
|
|
166
|
+
render(): React.ReactElement | null;
|
|
167
|
+
/** Go back to the previous field. */
|
|
168
|
+
back(): void;
|
|
169
|
+
/** Jump to a specific field. */
|
|
170
|
+
goTo(key: K): void;
|
|
171
|
+
/** True when there is a previous field to go back to. */
|
|
172
|
+
canGoBack(): boolean;
|
|
173
|
+
/** Clear all answers and restart the form. */
|
|
174
|
+
reset(): void;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Multi-step form hook with validation, back/goTo navigation, and completion state.
|
|
178
|
+
*
|
|
179
|
+
* @param schema - Map of field names to their prompt text, options, and validators.
|
|
180
|
+
* @returns A {@link FormResult} object for rendering and reading collected data.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```tsx
|
|
184
|
+
* const form = useForm({
|
|
185
|
+
* name: { prompt: "What's your name?", validate: z.string().min(2) },
|
|
186
|
+
* region: { prompt: 'Pick a region:', options: [['Kanto', 'Johto']] },
|
|
187
|
+
* });
|
|
188
|
+
*
|
|
189
|
+
* return form.render(() => (
|
|
190
|
+
* <Message text={`${form.data.name} from ${form.data.region}`} />
|
|
191
|
+
* ));
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
export declare function useForm<T extends Record<string, FormFieldDef>>(schema: T): FormResult<Extract<keyof T, string>>;
|
|
195
|
+
/** Access the nearest `<Conversation>` state from any child component. */
|
|
196
|
+
export declare function useConversationContext(): ConversationState;
|
|
197
|
+
/** Access the nearest `<Form>` state from any child component. */
|
|
198
|
+
export declare function useFormContext<K extends string = string>(): FormResult<K>;
|
|
199
|
+
interface ConvPromptProps {
|
|
200
|
+
name: string;
|
|
201
|
+
text: string;
|
|
202
|
+
validate?: Validator;
|
|
203
|
+
}
|
|
204
|
+
declare function ConversationPrompt(_: ConvPromptProps): null;
|
|
205
|
+
interface ConvAskProps {
|
|
206
|
+
name: string;
|
|
207
|
+
text: string;
|
|
208
|
+
options: AskOption[][];
|
|
209
|
+
}
|
|
210
|
+
declare function ConversationAsk(_: ConvAskProps): null;
|
|
211
|
+
interface ConvStepProps {
|
|
212
|
+
name: string;
|
|
213
|
+
children: (done: (value?: string) => void, actions: StepActions) => React.ReactElement;
|
|
214
|
+
}
|
|
215
|
+
declare function ConversationStepChild(_: ConvStepProps): null;
|
|
216
|
+
interface ConvCompleteProps {
|
|
217
|
+
children: React.ReactNode | ((conv: ConversationState) => React.ReactElement);
|
|
218
|
+
}
|
|
219
|
+
declare function ConversationComplete(_: ConvCompleteProps): null;
|
|
220
|
+
interface FormFieldProps {
|
|
221
|
+
name: string;
|
|
222
|
+
prompt: string | ((data: Readonly<Record<string, string>>) => string);
|
|
223
|
+
options?: string[][];
|
|
224
|
+
validate?: Validator;
|
|
225
|
+
}
|
|
226
|
+
declare function FormFieldChild(_: FormFieldProps): null;
|
|
227
|
+
interface FormCompleteProps {
|
|
228
|
+
children: React.ReactNode | ((form: FormResult) => React.ReactElement);
|
|
229
|
+
}
|
|
230
|
+
declare function FormCompleteChild(_: FormCompleteProps): null;
|
|
231
|
+
/**
|
|
232
|
+
* Shadcn-like composable conversation component.
|
|
233
|
+
*
|
|
234
|
+
* @example With `useConversation` hook (recommended)
|
|
235
|
+
* ```tsx
|
|
236
|
+
* const conv = useConversation({
|
|
237
|
+
* name: { prompt: "What's your name?" },
|
|
238
|
+
* rating: { ask: 'Rate us:', options: [['⭐ 1', '⭐⭐ 2']] },
|
|
239
|
+
* });
|
|
240
|
+
*
|
|
241
|
+
* return (
|
|
242
|
+
* <Conversation value={conv}>
|
|
243
|
+
* <Conversation.Complete>
|
|
244
|
+
* <Message text={`Hello ${conv.data.name}! Rating: ${conv.data.rating}`} />
|
|
245
|
+
* </Conversation.Complete>
|
|
246
|
+
* </Conversation>
|
|
247
|
+
* );
|
|
248
|
+
* ```
|
|
249
|
+
*
|
|
250
|
+
* @example Self-contained (steps as children, like shadcn Tabs)
|
|
251
|
+
* ```tsx
|
|
252
|
+
* <Conversation>
|
|
253
|
+
* <Conversation.Prompt name="name" text="What's your name?" />
|
|
254
|
+
* <Conversation.Ask name="color" text="Pick:" options={[['Red', 'Blue']]} />
|
|
255
|
+
* <Conversation.Complete>
|
|
256
|
+
* {(conv) => <Message text={`${conv.data.name} chose ${conv.data.color}`} />}
|
|
257
|
+
* </Conversation.Complete>
|
|
258
|
+
* </Conversation>
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
declare function ConversationRoot({ children, value }: {
|
|
262
|
+
children: React.ReactNode;
|
|
263
|
+
value?: ConversationState;
|
|
264
|
+
}): React.ReactElement;
|
|
265
|
+
export declare const Conversation: typeof ConversationRoot & {
|
|
266
|
+
Prompt: typeof ConversationPrompt;
|
|
267
|
+
Ask: typeof ConversationAsk;
|
|
268
|
+
Step: typeof ConversationStepChild;
|
|
269
|
+
Complete: typeof ConversationComplete;
|
|
270
|
+
};
|
|
271
|
+
/**
|
|
272
|
+
* Shadcn-like composable form component.
|
|
273
|
+
*
|
|
274
|
+
* @example With `useForm` hook (recommended)
|
|
275
|
+
* ```tsx
|
|
276
|
+
* const form = useForm({
|
|
277
|
+
* name: { prompt: "Name?", validate: z.string().min(2) },
|
|
278
|
+
* region: { prompt: "Region?", options: [['Kanto', 'Johto']] },
|
|
279
|
+
* });
|
|
280
|
+
*
|
|
281
|
+
* return (
|
|
282
|
+
* <Form value={form}>
|
|
283
|
+
* <Form.Complete>
|
|
284
|
+
* <Message text={`${form.data.name} from ${form.data.region}`} />
|
|
285
|
+
* </Form.Complete>
|
|
286
|
+
* </Form>
|
|
287
|
+
* );
|
|
288
|
+
* ```
|
|
289
|
+
*
|
|
290
|
+
* @example Self-contained (fields as children)
|
|
291
|
+
* ```tsx
|
|
292
|
+
* <Form>
|
|
293
|
+
* <Form.Field name="name" prompt="Name?" validate={z.string().min(2)} />
|
|
294
|
+
* <Form.Field name="region" prompt="Region?" options={[['Kanto', 'Johto']]} />
|
|
295
|
+
* <Form.Complete>
|
|
296
|
+
* {(form) => <Message text={`${form.data.name} from ${form.data.region}`} />}
|
|
297
|
+
* </Form.Complete>
|
|
298
|
+
* </Form>
|
|
299
|
+
* ```
|
|
300
|
+
*/
|
|
301
|
+
declare function FormRoot({ children, value }: {
|
|
302
|
+
children: React.ReactNode;
|
|
303
|
+
value?: FormResult;
|
|
304
|
+
}): React.ReactElement;
|
|
305
|
+
export declare const Form: typeof FormRoot & {
|
|
306
|
+
Field: typeof FormFieldChild;
|
|
307
|
+
Complete: typeof FormCompleteChild;
|
|
308
|
+
};
|
|
309
|
+
export {};
|
|
310
|
+
//# sourceMappingURL=conversation.d.ts.map
|