@teactjs/core 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 +41 -0
- package/dist/core/src/index.d.ts +31 -0
- package/dist/core/src/index.d.ts.map +1 -0
- package/dist/index.js +23152 -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 +33 -0
- package/src/index.ts +89 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { FunctionComponent, ReactElement } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* Determines how the router transitions between messages.
|
|
5
|
+
* - `replace` — edit the current message in-place
|
|
6
|
+
* - `push` — keep old message, send a new one below
|
|
7
|
+
* - `stack` — strip buttons from old message, send new one below
|
|
8
|
+
* - `dismiss` — strip buttons from old message, do NOT send a new one
|
|
9
|
+
*/
|
|
10
|
+
export type NavigateMode = 'replace' | 'push' | 'stack' | 'dismiss';
|
|
11
|
+
export interface NavigateOptions {
|
|
12
|
+
/** How to handle the previous message (default: 'replace').
|
|
13
|
+
* - replace: edit the current message in-place
|
|
14
|
+
* - push: keep old message, send a new one below
|
|
15
|
+
* - stack: strip buttons from old message, send new one below
|
|
16
|
+
* - dismiss: strip buttons from old message, do NOT send a new one */
|
|
17
|
+
mode?: NavigateMode;
|
|
18
|
+
}
|
|
19
|
+
/** Button definition used in guard replies and redirects. */
|
|
20
|
+
export interface GuardButton {
|
|
21
|
+
text: string;
|
|
22
|
+
route?: string;
|
|
23
|
+
url?: string;
|
|
24
|
+
}
|
|
25
|
+
/** Options for the `reply` helper inside `beforeLoad`. */
|
|
26
|
+
export interface GuardReplyOptions {
|
|
27
|
+
buttons?: GuardButton[][];
|
|
28
|
+
}
|
|
29
|
+
declare const GUARD_REPLY_SYMBOL: unique symbol;
|
|
30
|
+
/** Sentinel object returned by the `reply()` helper inside `beforeLoad`. */
|
|
31
|
+
export interface GuardReply {
|
|
32
|
+
readonly __type: typeof GUARD_REPLY_SYMBOL;
|
|
33
|
+
text: string;
|
|
34
|
+
buttons?: GuardButton[][];
|
|
35
|
+
}
|
|
36
|
+
/** Context passed to route guards in `beforeLoad`. */
|
|
37
|
+
export interface BeforeLoadContext {
|
|
38
|
+
path: string;
|
|
39
|
+
params: Record<string, string>;
|
|
40
|
+
session: Record<string, any>;
|
|
41
|
+
/** Send a message (with optional buttons) instead of loading the route. */
|
|
42
|
+
reply: (text: string, options?: GuardReplyOptions) => GuardReply;
|
|
43
|
+
}
|
|
44
|
+
/** Object returned from a route guard to trigger a redirect with an optional message. */
|
|
45
|
+
export interface GuardRedirect {
|
|
46
|
+
redirect: string;
|
|
47
|
+
message?: string;
|
|
48
|
+
buttons?: GuardButton[][];
|
|
49
|
+
}
|
|
50
|
+
/** Object returned from a guard to render a component instead of the target route. */
|
|
51
|
+
export interface GuardComponent {
|
|
52
|
+
component: FunctionComponent<any>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* A route guard function that runs before the route loads.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* // Redirect to home
|
|
59
|
+
* beforeLoad: ({ session }) => {
|
|
60
|
+
* if (!session.auth) return redirect('/');
|
|
61
|
+
* }
|
|
62
|
+
*
|
|
63
|
+
* // Return JSX directly
|
|
64
|
+
* beforeLoad: ({ session }) => {
|
|
65
|
+
* if (!session.auth) return <LoginPage />;
|
|
66
|
+
* }
|
|
67
|
+
*
|
|
68
|
+
* // Reply with a message and buttons (same API as command handlers)
|
|
69
|
+
* beforeLoad: ({ session, reply }) => {
|
|
70
|
+
* if (!session.auth) return reply('Please log in.', {
|
|
71
|
+
* buttons: [[{ text: 'Login', route: '/login' }, { text: 'Menu', route: '/' }]],
|
|
72
|
+
* });
|
|
73
|
+
* }
|
|
74
|
+
*/
|
|
75
|
+
export type RouteGuard = (ctx: BeforeLoadContext) => void | string | GuardRedirect | GuardComponent | GuardReply | ReactElement;
|
|
76
|
+
/**
|
|
77
|
+
* A route value: either a plain component or an object with `component` and optional `beforeLoad` guard.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* const routes = {
|
|
81
|
+
* '/': Home,
|
|
82
|
+
* '/admin': { component: Admin, beforeLoad: ({ session }) => session.admin ? undefined : '/' },
|
|
83
|
+
* };
|
|
84
|
+
*/
|
|
85
|
+
export type RouteValue = FunctionComponent<any> | {
|
|
86
|
+
component: FunctionComponent<any>;
|
|
87
|
+
beforeLoad?: RouteGuard;
|
|
88
|
+
};
|
|
89
|
+
export interface RouteDefinition {
|
|
90
|
+
path: string;
|
|
91
|
+
component: FunctionComponent<any>;
|
|
92
|
+
pattern: RegExp;
|
|
93
|
+
paramNames: string[];
|
|
94
|
+
beforeLoad?: RouteGuard;
|
|
95
|
+
}
|
|
96
|
+
export interface RouterConfig {
|
|
97
|
+
routes: RouteDefinition[];
|
|
98
|
+
defaultRoute: string;
|
|
99
|
+
notFound: FunctionComponent<any>;
|
|
100
|
+
}
|
|
101
|
+
interface RouterContextValue {
|
|
102
|
+
path: string;
|
|
103
|
+
params: Record<string, string>;
|
|
104
|
+
navigate: (path: string, opts?: NavigateOptions) => void;
|
|
105
|
+
}
|
|
106
|
+
/** Mutable ref shared between the router and the commit callback. */
|
|
107
|
+
export interface CommitModeRef {
|
|
108
|
+
current: NavigateMode;
|
|
109
|
+
}
|
|
110
|
+
export declare const RouterCtx: React.Context<RouterContextValue | null>;
|
|
111
|
+
export declare const CommitModeCtx: React.Context<CommitModeRef>;
|
|
112
|
+
/** Redirect helper for use inside `beforeLoad` guards. */
|
|
113
|
+
export declare function redirect(path: string): string;
|
|
114
|
+
/** Options for `createRouter`. */
|
|
115
|
+
export interface CreateRouterOptions {
|
|
116
|
+
/** Component to render when no route matches (custom 404 page). */
|
|
117
|
+
notFound?: FunctionComponent<any>;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Create a router from a route map.
|
|
121
|
+
*
|
|
122
|
+
* Routes can be plain components or objects with `beforeLoad` guards.
|
|
123
|
+
* Pass a `notFound` component as the second argument for custom 404 pages:
|
|
124
|
+
*
|
|
125
|
+
* ```tsx
|
|
126
|
+
* createRouter(
|
|
127
|
+
* {
|
|
128
|
+
* '/': Home,
|
|
129
|
+
* '/admin': { component: AdminPanel, beforeLoad: ({ session }) => {
|
|
130
|
+
* if (!session.loggedIn) return redirect('/');
|
|
131
|
+
* }},
|
|
132
|
+
* },
|
|
133
|
+
* { notFound: NotFoundPage },
|
|
134
|
+
* );
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
export declare function createRouter(routes: Record<string, RouteValue>, options?: CreateRouterOptions): RouterConfig;
|
|
138
|
+
export declare function RouterProvider({ config, initialPath, }: {
|
|
139
|
+
config: RouterConfig;
|
|
140
|
+
initialPath: string;
|
|
141
|
+
}): React.ReactElement | null;
|
|
142
|
+
/** Navigate to a different route.
|
|
143
|
+
* @example
|
|
144
|
+
* navigate('/pokemon/25') // replace current message
|
|
145
|
+
* navigate('/pokemon/25', { mode: 'push' }) // keep old message, send new below
|
|
146
|
+
* navigate('/pokemon/25', { mode: 'stack' }) // strip buttons from old, send new below
|
|
147
|
+
* navigate('/pokemon/25', { mode: 'dismiss' }) // strip buttons only, no new message
|
|
148
|
+
*/
|
|
149
|
+
export declare function useNavigate(): (path: string, opts?: NavigateOptions) => void;
|
|
150
|
+
/**
|
|
151
|
+
* Read the current route's dynamic parameters.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* // Route: '/pokemon/:id'
|
|
155
|
+
* const { id } = useParams<{ id: string }>();
|
|
156
|
+
*/
|
|
157
|
+
export declare function useParams<T extends Record<string, string> = Record<string, string>>(): T;
|
|
158
|
+
/**
|
|
159
|
+
* Returns the current matched path and params.
|
|
160
|
+
*
|
|
161
|
+
* @returns An object with `path` and `params`.
|
|
162
|
+
*/
|
|
163
|
+
export declare function useRoute(): {
|
|
164
|
+
path: string;
|
|
165
|
+
params: Record<string, string>;
|
|
166
|
+
};
|
|
167
|
+
export {};
|
|
168
|
+
//# sourceMappingURL=router.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../../../runtime/src/router.ts"],"names":[],"mappings":"AAAA,OAAO,KAA2D,MAAM,OAAO,CAAC;AAChF,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAK7D;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;AAEpE,MAAM,WAAW,eAAe;IAC9B;;;;2EAIuE;IACvE,IAAI,CAAC,EAAE,YAAY,CAAC;CACrB;AAED,6DAA6D;AAC7D,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,0DAA0D;AAC1D,M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;;;GAMG;AACH,wBAAgB,WAAW,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,eAAe,KAAK,IAAI,CAI5E;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,CAIxF;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,IAAI;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,CAI3E"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { SessionData, SessionStore } from '@teactjs/renderer';
|
|
2
|
+
/**
|
|
3
|
+
* In-memory session store with TTL-based expiration.
|
|
4
|
+
* Used as the default when no custom `SessionStore` is provided.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* const store = new MemorySessionStore(30 * 60 * 1000); // 30-minute TTL
|
|
8
|
+
*/
|
|
9
|
+
export declare class MemorySessionStore implements SessionStore {
|
|
10
|
+
private store;
|
|
11
|
+
private ttl;
|
|
12
|
+
/** @param ttl - Time-to-live in milliseconds (default: 24 hours). */
|
|
13
|
+
constructor(ttl?: number);
|
|
14
|
+
get(key: string): Promise<SessionData | null>;
|
|
15
|
+
set(key: string, data: SessionData): Promise<void>;
|
|
16
|
+
delete(key: string): Promise<void>;
|
|
17
|
+
get size(): number;
|
|
18
|
+
cleanup(): void;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../../runtime/src/session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEnE;;;;;;GAMG;AACH,qBAAa,kBAAmB,YAAW,YAAY;IACrD,OAAO,CAAC,KAAK,CAA+D;IAC5E,OAAO,CAAC,GAAG,CAAS;IAEpB,qEAAqE;gBACzD,GAAG,SAAsB;IAI/B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAU7C,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxC,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,OAAO,IAAI,IAAI;CAMhB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export interface UseStreamResult {
|
|
2
|
+
/** Accumulated text so far. */
|
|
3
|
+
text: string;
|
|
4
|
+
/** Whether a stream is currently active. */
|
|
5
|
+
isStreaming: boolean;
|
|
6
|
+
/** Start streaming from an async generator. Cancels any previous stream. */
|
|
7
|
+
stream(source: AsyncIterable<string>): void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* React hook for streaming text into a message with throttled updates.
|
|
11
|
+
*
|
|
12
|
+
* @param opts.throttleMs - Minimum ms between re-renders (default 500). Prevents Telegram rate-limit errors.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* function StreamDemo() {
|
|
16
|
+
* const { text, isStreaming, stream } = useStream();
|
|
17
|
+
*
|
|
18
|
+
* async function* generate() {
|
|
19
|
+
* yield "Loading";
|
|
20
|
+
* await delay(500);
|
|
21
|
+
* yield " your data...";
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* return (
|
|
25
|
+
* <Message text={text || "Click to start"}>
|
|
26
|
+
* <Button text={isStreaming ? "⏳ Streaming…" : "▶️ Start"} onClick={() => stream(generate())} />
|
|
27
|
+
* </Message>
|
|
28
|
+
* );
|
|
29
|
+
* }
|
|
30
|
+
*/
|
|
31
|
+
export declare function useStream(opts?: {
|
|
32
|
+
throttleMs?: number;
|
|
33
|
+
}): UseStreamResult;
|
|
34
|
+
//# sourceMappingURL=stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../../../runtime/src/stream.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,eAAe;IAC9B,+BAA+B;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,4CAA4C;IAC5C,WAAW,EAAE,OAAO,CAAC;IACrB,4EAA4E;IAC5E,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;CAC7C;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,SAAS,CAAC,IAAI,CAAC,EAAE;IAAE,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,eAAe,CAiCzE"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Bot } from 'grammy';
|
|
2
|
+
import type { BotContext, OutputNode } from '@teactjs/renderer';
|
|
3
|
+
export interface TelegramAdapterConfig {
|
|
4
|
+
token: string;
|
|
5
|
+
}
|
|
6
|
+
export interface WebhookConfig {
|
|
7
|
+
/** Public URL (e.g. https://mybot.example.com) */
|
|
8
|
+
domain: string;
|
|
9
|
+
/** Port to listen on (default: 3000) */
|
|
10
|
+
port?: number;
|
|
11
|
+
/** URL path for the webhook endpoint (default: /webhook) */
|
|
12
|
+
path?: string;
|
|
13
|
+
/** Secret token for verifying Telegram requests */
|
|
14
|
+
secretToken?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface ListenOptions {
|
|
17
|
+
/** Set to false to skip auto-start (manual control). */
|
|
18
|
+
polling?: boolean;
|
|
19
|
+
/** If provided, uses webhook mode instead of polling. */
|
|
20
|
+
webhook?: WebhookConfig;
|
|
21
|
+
}
|
|
22
|
+
type EventHandler = (ctx: BotContext) => void | Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Telegram platform adapter powered by grammY.
|
|
25
|
+
*
|
|
26
|
+
* Lifecycle: connect() → use() → listen()
|
|
27
|
+
* 1. connect() — creates the Grammy Bot instance.
|
|
28
|
+
* 2. use() — registers Grammy middleware (conversations, session, etc.).
|
|
29
|
+
* 3. listen() — registers Teact bridge handlers, then starts polling or webhook.
|
|
30
|
+
*/
|
|
31
|
+
export declare class TelegramAdapter {
|
|
32
|
+
readonly name = "telegram";
|
|
33
|
+
private bot;
|
|
34
|
+
private httpServer;
|
|
35
|
+
private listeners;
|
|
36
|
+
private _pendingNotification;
|
|
37
|
+
/** Register a handler for a given event (e.g. `'message'`, `'callback_query'`). */
|
|
38
|
+
on(event: string, handler: EventHandler): void;
|
|
39
|
+
/** Remove a previously registered event handler. */
|
|
40
|
+
off(event: string, handler: EventHandler): void;
|
|
41
|
+
private emit;
|
|
42
|
+
/** Step 1 — create the Grammy Bot with auto-retry. Does NOT start polling. */
|
|
43
|
+
connect(config: TelegramAdapterConfig): Promise<void>;
|
|
44
|
+
/** Register Grammy middleware (call between connect() and listen()). */
|
|
45
|
+
use(...middlewares: any[]): void;
|
|
46
|
+
/** Step 2 — register Teact bridge handlers, then start polling or webhook. */
|
|
47
|
+
listen(opts?: ListenOptions): Promise<void>;
|
|
48
|
+
/** Stop polling/webhook and disconnect the bot. */
|
|
49
|
+
disconnect(): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Send a rendered output tree to a Telegram chat.
|
|
52
|
+
*
|
|
53
|
+
* @param chatId - Target chat ID.
|
|
54
|
+
* @param output - Serialized component tree produced by the Teact renderer.
|
|
55
|
+
* @returns The `message_id` of the sent message, or `undefined`.
|
|
56
|
+
*/
|
|
57
|
+
send(chatId: string | number, output: OutputNode): Promise<number | undefined>;
|
|
58
|
+
getPendingNotification(): {
|
|
59
|
+
text: string;
|
|
60
|
+
showAlert?: boolean;
|
|
61
|
+
} | null;
|
|
62
|
+
/**
|
|
63
|
+
* Edit an existing message's text and inline keyboard.
|
|
64
|
+
*
|
|
65
|
+
* @param chatId - Target chat ID.
|
|
66
|
+
* @param messageId - ID of the message to edit.
|
|
67
|
+
* @param output - New rendered output tree.
|
|
68
|
+
*/
|
|
69
|
+
edit(chatId: string | number, messageId: number, output: OutputNode): Promise<void>;
|
|
70
|
+
/** Remove all inline keyboard buttons from a message. */
|
|
71
|
+
clearButtons(chatId: string | number, messageId: number): Promise<void>;
|
|
72
|
+
/** Register bot commands with Telegram's command menu. */
|
|
73
|
+
setCommands(commands: {
|
|
74
|
+
command: string;
|
|
75
|
+
description: string;
|
|
76
|
+
}[]): Promise<void>;
|
|
77
|
+
/** Access the raw grammY Bot instance for advanced usage (plugins, middleware). */
|
|
78
|
+
getBot(): Bot;
|
|
79
|
+
private startWebhook;
|
|
80
|
+
private mapContext;
|
|
81
|
+
}
|
|
82
|
+
export {};
|
|
83
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../../telegram/src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAyD,MAAM,QAAQ,CAAC;AAEpF,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAIhE,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,aAAa;IAC5B,kDAAkD;IAClD,MAAM,EAAE,MAAM,CAAC;IACf,wCAAwC;IACxC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,4DAA4D;IAC5D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,mDAAmD;IACnD,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,aAAa;IAC5B,wDAAwD;IACxD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,yDAAyD;IACzD,OAAO,CAAC,EAAE,aAAa,CAAC;CACzB;AAED,KAAK,YAAY,GAAG,CAAC,GAAG,EAA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O,CAAC,IAAI,CAAC;IAW7E,0DAA0D;IACpD,WAAW,CAAC,QAAQ,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAKtF,mFAAmF;IACnF,MAAM,IAAI,GAAG;YAOC,YAAY;IA+C1B,OAAO,CAAC,UAAU;CAsBnB"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import type { TeactPlugin } from '@teactjs/runtime';
|
|
2
|
+
type ValidateFn = (value: string) => true | string;
|
|
3
|
+
interface SchemaLike {
|
|
4
|
+
safeParse(value: unknown): {
|
|
5
|
+
success: boolean;
|
|
6
|
+
error?: {
|
|
7
|
+
issues: Array<{
|
|
8
|
+
message: string;
|
|
9
|
+
}>;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export type Validator = ValidateFn | SchemaLike;
|
|
14
|
+
type AskOption = string | {
|
|
15
|
+
text: string;
|
|
16
|
+
value: string;
|
|
17
|
+
};
|
|
18
|
+
export interface PromptOptions {
|
|
19
|
+
/** Zod schema, function validator, or any object with `.safeParse()`. */
|
|
20
|
+
validate?: Validator;
|
|
21
|
+
}
|
|
22
|
+
export interface MediaGroupItem {
|
|
23
|
+
type: 'photo' | 'video';
|
|
24
|
+
media: string;
|
|
25
|
+
caption?: string;
|
|
26
|
+
parse_mode?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface Conversation {
|
|
29
|
+
/** Send a text message and wait for the user's text reply. Auto-retries on validation failure. */
|
|
30
|
+
prompt(text: string, opts?: PromptOptions): Promise<string>;
|
|
31
|
+
/** Send a text message without waiting. */
|
|
32
|
+
send(text: string): Promise<void>;
|
|
33
|
+
/** Wait for the user's next text message. */
|
|
34
|
+
wait(opts?: PromptOptions): Promise<string>;
|
|
35
|
+
/** Send a message with button options and wait for selection. */
|
|
36
|
+
ask(text: string, options: AskOption[][]): Promise<string>;
|
|
37
|
+
/** Stream an async generator's output as a live-updating message. */
|
|
38
|
+
stream(source: AsyncIterable<string>): Promise<void>;
|
|
39
|
+
/** Send a photo. */
|
|
40
|
+
replyWithPhoto(src: string, opts?: {
|
|
41
|
+
caption?: string;
|
|
42
|
+
parse_mode?: string;
|
|
43
|
+
has_spoiler?: boolean;
|
|
44
|
+
}): Promise<void>;
|
|
45
|
+
/** Send a video. */
|
|
46
|
+
replyWithVideo(src: string, opts?: {
|
|
47
|
+
caption?: string;
|
|
48
|
+
parse_mode?: string;
|
|
49
|
+
duration?: number;
|
|
50
|
+
width?: number;
|
|
51
|
+
height?: number;
|
|
52
|
+
supports_streaming?: boolean;
|
|
53
|
+
}): Promise<void>;
|
|
54
|
+
/** Send an animation (GIF). */
|
|
55
|
+
replyWithAnimation(src: string, opts?: {
|
|
56
|
+
caption?: string;
|
|
57
|
+
parse_mode?: string;
|
|
58
|
+
duration?: number;
|
|
59
|
+
width?: number;
|
|
60
|
+
height?: number;
|
|
61
|
+
}): Promise<void>;
|
|
62
|
+
/** Send a voice message. */
|
|
63
|
+
replyWithVoice(src: string, opts?: {
|
|
64
|
+
caption?: string;
|
|
65
|
+
parse_mode?: string;
|
|
66
|
+
duration?: number;
|
|
67
|
+
}): Promise<void>;
|
|
68
|
+
/** Send an audio file. */
|
|
69
|
+
replyWithAudio(src: string, opts?: {
|
|
70
|
+
caption?: string;
|
|
71
|
+
parse_mode?: string;
|
|
72
|
+
performer?: string;
|
|
73
|
+
title?: string;
|
|
74
|
+
duration?: number;
|
|
75
|
+
}): Promise<void>;
|
|
76
|
+
/** Send a round video note. */
|
|
77
|
+
replyWithVideoNote(src: string, opts?: {
|
|
78
|
+
duration?: number;
|
|
79
|
+
length?: number;
|
|
80
|
+
}): Promise<void>;
|
|
81
|
+
/** Send a sticker. */
|
|
82
|
+
replyWithSticker(src: string, opts?: {
|
|
83
|
+
emoji?: string;
|
|
84
|
+
}): Promise<void>;
|
|
85
|
+
/** Send a document/file. */
|
|
86
|
+
replyWithDocument(src: string, opts?: {
|
|
87
|
+
caption?: string;
|
|
88
|
+
filename?: string;
|
|
89
|
+
}): Promise<void>;
|
|
90
|
+
/** Send a contact card. */
|
|
91
|
+
replyWithContact(phoneNumber: string, firstName: string, opts?: {
|
|
92
|
+
last_name?: string;
|
|
93
|
+
vcard?: string;
|
|
94
|
+
}): Promise<void>;
|
|
95
|
+
/** Send a location pin. */
|
|
96
|
+
replyWithLocation(latitude: number, longitude: number, opts?: {
|
|
97
|
+
live_period?: number;
|
|
98
|
+
horizontal_accuracy?: number;
|
|
99
|
+
heading?: number;
|
|
100
|
+
proximity_alert_radius?: number;
|
|
101
|
+
}): Promise<void>;
|
|
102
|
+
/** Send a venue. */
|
|
103
|
+
replyWithVenue(latitude: number, longitude: number, title: string, address: string, opts?: {
|
|
104
|
+
foursquare_id?: string;
|
|
105
|
+
google_place_id?: string;
|
|
106
|
+
}): Promise<void>;
|
|
107
|
+
/** Send a media group (album). */
|
|
108
|
+
replyWithMediaGroup(media: MediaGroupItem[]): Promise<void>;
|
|
109
|
+
/** Send a poll. */
|
|
110
|
+
replyWithPoll(question: string, options: string[], opts?: {
|
|
111
|
+
is_anonymous?: boolean;
|
|
112
|
+
type?: 'regular' | 'quiz';
|
|
113
|
+
allows_multiple_answers?: boolean;
|
|
114
|
+
correct_option_id?: number;
|
|
115
|
+
explanation?: string;
|
|
116
|
+
open_period?: number;
|
|
117
|
+
}): Promise<void>;
|
|
118
|
+
/** Show a "Share Contact" reply-keyboard and wait for the user's contact. Returns { phone_number, first_name, last_name?, user_id? }. */
|
|
119
|
+
requestContact(promptText: string, buttonText?: string): Promise<{
|
|
120
|
+
phone_number: string;
|
|
121
|
+
first_name: string;
|
|
122
|
+
last_name?: string;
|
|
123
|
+
user_id?: number;
|
|
124
|
+
}>;
|
|
125
|
+
/** Show a "Share Location" reply-keyboard and wait for the user's location. Returns { latitude, longitude }. */
|
|
126
|
+
requestLocation(promptText: string, buttonText?: string): Promise<{
|
|
127
|
+
latitude: number;
|
|
128
|
+
longitude: number;
|
|
129
|
+
}>;
|
|
130
|
+
/** The current chat ID. */
|
|
131
|
+
chatId: number;
|
|
132
|
+
/** The Grammy API object for advanced calls. */
|
|
133
|
+
api: any;
|
|
134
|
+
/** The Grammy chat object. */
|
|
135
|
+
chat: any;
|
|
136
|
+
/** Raw Grammy objects — escape hatch. */
|
|
137
|
+
raw: {
|
|
138
|
+
conversation: any;
|
|
139
|
+
ctx: any;
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
export type ConversationHandler = (conversation: Conversation) => Promise<void>;
|
|
143
|
+
export type RawConversationHandler = (conversation: any, ctx: any) => Promise<void>;
|
|
144
|
+
export interface ConversationDef {
|
|
145
|
+
handler: ConversationHandler;
|
|
146
|
+
command?: string;
|
|
147
|
+
}
|
|
148
|
+
export interface ConversationsPluginOptions {
|
|
149
|
+
/** Named conversation definitions. */
|
|
150
|
+
[name: string]: ConversationDef | ConversationHandler;
|
|
151
|
+
}
|
|
152
|
+
export interface ConversationsConfig {
|
|
153
|
+
/** Conversation definitions (same as passing to conversationsPlugin). */
|
|
154
|
+
conversations?: ConversationsPluginOptions;
|
|
155
|
+
/**
|
|
156
|
+
* When true (default), automatically exit all active conversations
|
|
157
|
+
* before entering a new one. Prevents the "already in a conversation" error.
|
|
158
|
+
*/
|
|
159
|
+
exitActive?: boolean;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Define a conversation — co-locate the handler with the component that triggers it.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* const feedback = defineConversation('feedback', async (conversation) => {
|
|
166
|
+
* const name = await conversation.prompt("What's your name?");
|
|
167
|
+
* await conversation.replyWithPhoto('https://example.com/thanks.png', { caption: `Thanks ${name}!` });
|
|
168
|
+
* await conversation.replyWithLocation(37.77, -122.42);
|
|
169
|
+
* await conversation.send('Done!');
|
|
170
|
+
* });
|
|
171
|
+
*/
|
|
172
|
+
export declare function defineConversation(name: string, handlerOrDef: ConversationHandler | ConversationDef): string;
|
|
173
|
+
export declare function conversationsPlugin(configOrDefs?: ConversationsConfig | ConversationsPluginOptions): TeactPlugin;
|
|
174
|
+
export {};
|
|
175
|
+
//# sourceMappingURL=conversations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversations.d.ts","sourceRoot":"","sources":["../../../../telegram/src/conversations.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAMpD,KAAK,UAAU,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,MAAM,CAAC;AACnD,UAAU,UAAU;IAClB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE;YAAE,MAAM,EAAE,KAAK,CAAC;gBAAE,OAAO,EAAE,MAAM,CAAA;aAAE,CAAC,CAAA;SAAE,CAAA;KAAE,CAAC;CACjG;AACD,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,UAAU,CAAC;AAahD,KAAK,SAAS,GAAG,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1D,MAAM,WAAW,aAAa;IAC5B,yEAAyE;IACzE,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IAC3B,kGAAkG;IAClG,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC5D,2CAA2C;IAC3C,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG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jC,YAAY,CAAC,EAAE,mBAAmB,GAAG,0BAA0B,GAC9D,WAAW,CAgEb"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { TelegramAdapter } from './adapter';
|
|
2
|
+
export type { TelegramAdapterConfig } from './adapter';
|
|
3
|
+
export { serializeOutput } from './serialize';
|
|
4
|
+
export type { TelegramSendPayload } from './serialize';
|
|
5
|
+
export { conversationsPlugin, defineConversation } from './conversations';
|
|
6
|
+
export type { Conversation, ConversationHandler, ConversationDef, ConversationsPluginOptions, ConversationsConfig, MediaGroupItem } from './conversations';
|
|
7
|
+
export { streamPlugin } from './stream';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../telegram/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,YAAY,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,YAAY,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAC1E,YAAY,EAAE,YAAY,EAAE,mBAAmB,EAAE,eAAe,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAC3J,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { OutputNode } from '@teactjs/renderer';
|
|
2
|
+
import type { InlineKeyboardButton as GrammyButton, KeyboardButton } from 'grammy/types';
|
|
3
|
+
export type SendMethod = 'sendMessage' | 'sendPhoto' | 'sendDocument' | 'sendVideo' | 'sendVoice' | 'sendAudio' | 'sendAnimation' | 'sendVideoNote' | 'sendSticker' | 'sendContact' | 'sendLocation' | 'sendVenue' | 'sendMediaGroup' | 'sendPoll';
|
|
4
|
+
export interface MediaGroupItem {
|
|
5
|
+
type: 'photo' | 'video';
|
|
6
|
+
media: string;
|
|
7
|
+
caption?: string;
|
|
8
|
+
parse_mode?: string;
|
|
9
|
+
has_spoiler?: boolean;
|
|
10
|
+
width?: number;
|
|
11
|
+
height?: number;
|
|
12
|
+
duration?: number;
|
|
13
|
+
supports_streaming?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface TelegramSendPayload {
|
|
16
|
+
method: SendMethod;
|
|
17
|
+
text?: string;
|
|
18
|
+
photo?: string;
|
|
19
|
+
document?: string;
|
|
20
|
+
filename?: string;
|
|
21
|
+
parseMode?: string;
|
|
22
|
+
disablePreview?: boolean;
|
|
23
|
+
keyboard?: GrammyButton[][];
|
|
24
|
+
video?: string;
|
|
25
|
+
voice?: string;
|
|
26
|
+
audio?: string;
|
|
27
|
+
animation?: string;
|
|
28
|
+
videoNote?: string;
|
|
29
|
+
sticker?: string;
|
|
30
|
+
width?: number;
|
|
31
|
+
height?: number;
|
|
32
|
+
duration?: number;
|
|
33
|
+
supportsStreaming?: boolean;
|
|
34
|
+
hasSpoiler?: boolean;
|
|
35
|
+
performer?: string;
|
|
36
|
+
title?: string;
|
|
37
|
+
length?: number;
|
|
38
|
+
emoji?: string;
|
|
39
|
+
phoneNumber?: string;
|
|
40
|
+
firstName?: string;
|
|
41
|
+
lastName?: string;
|
|
42
|
+
vcard?: string;
|
|
43
|
+
latitude?: number;
|
|
44
|
+
longitude?: number;
|
|
45
|
+
livePeriod?: number;
|
|
46
|
+
horizontalAccuracy?: number;
|
|
47
|
+
heading?: number;
|
|
48
|
+
proximityAlertRadius?: number;
|
|
49
|
+
venueTitle?: string;
|
|
50
|
+
venueAddress?: string;
|
|
51
|
+
foursquareId?: string;
|
|
52
|
+
foursquareType?: string;
|
|
53
|
+
googlePlaceId?: string;
|
|
54
|
+
googlePlaceType?: string;
|
|
55
|
+
mediaGroup?: MediaGroupItem[];
|
|
56
|
+
replyKeyboard?: {
|
|
57
|
+
rows: KeyboardButton[][];
|
|
58
|
+
resizeKeyboard?: boolean;
|
|
59
|
+
oneTimeKeyboard?: boolean;
|
|
60
|
+
placeholder?: string;
|
|
61
|
+
isPersistent?: boolean;
|
|
62
|
+
};
|
|
63
|
+
removeKeyboard?: boolean;
|
|
64
|
+
notification?: {
|
|
65
|
+
text: string;
|
|
66
|
+
showAlert?: boolean;
|
|
67
|
+
};
|
|
68
|
+
pollQuestion?: string;
|
|
69
|
+
pollOptions?: string[];
|
|
70
|
+
pollIsAnonymous?: boolean;
|
|
71
|
+
pollType?: 'regular' | 'quiz';
|
|
72
|
+
pollAllowsMultipleAnswers?: boolean;
|
|
73
|
+
pollCorrectOptionId?: number;
|
|
74
|
+
pollExplanation?: string;
|
|
75
|
+
pollExplanationParseMode?: string;
|
|
76
|
+
pollOpenPeriod?: number;
|
|
77
|
+
pollIsClosed?: boolean;
|
|
78
|
+
}
|
|
79
|
+
export declare function serializeOutput(node: OutputNode): TelegramSendPayload;
|
|
80
|
+
//# sourceMappingURL=serialize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../../../telegram/src/serialize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,oBAAoB,IAAI,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEzF,MAAM,MAAM,UAAU,GAClB,aAAa,GAAG,WAAW,GAAG,cAAc,GAC5C,WAAW,GAAG,WAAW,GAAG,WAAW,GACvC,eAAe,GAAG,eAAe,GAAG,aAAa,GACjD,aAAa,GAAG,cAAc,GAAG,WAAW,GAC5C,gBAAgB,GAAG,UAAU,CAAC;AAElC,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC;IACxB,KAAK,EAAE,MAA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EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,GAAG,mBAAmB,CAIrE"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { TeactPlugin } from '@teactjs/runtime';
|
|
2
|
+
/**
|
|
3
|
+
* Grammy stream plugin for Teact.
|
|
4
|
+
*
|
|
5
|
+
* Registers `@grammyjs/stream` and `@grammyjs/auto-retry` on the Grammy bot.
|
|
6
|
+
* Enables `conversation.stream()` for live-updating messages from async generators.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* plugins: [ streamPlugin() ]
|
|
10
|
+
*/
|
|
11
|
+
export declare function streamPlugin(): TeactPlugin;
|
|
12
|
+
//# sourceMappingURL=stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../../../telegram/src/stream.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD;;;;;;;;GAQG;AACH,wBAAgB,YAAY,IAAI,WAAW,CAS1C"}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@teactjs/core",
|
|
3
|
+
"version": "0.1.0-alpha.1",
|
|
4
|
+
"description": "Teact framework core — createBot, hooks, router, and more",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.ts",
|
|
7
|
+
"types": "src/index.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./src/index.ts"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"main": "dist/index.js",
|
|
13
|
+
"types": "dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"import": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": ["dist", "README.md"],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "bun build ./src/index.ts --outdir ./dist --format esm --target bun && tsc --emitDeclarationOnly --outDir dist --declaration --project tsconfig.build.json"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@teactjs/renderer": "workspace:*",
|
|
27
|
+
"@teactjs/runtime": "workspace:*"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
31
|
+
},
|
|
32
|
+
"license": "MIT"
|
|
33
|
+
}
|