@doubao-dev/framework 0.0.42 → 0.1.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/dist/index.d.ts CHANGED
@@ -103,7 +103,66 @@ import { VoidFunctionComponent } from 'react';
103
103
 
104
104
  export declare type AgentEventCallback = (payload: AgentEventPayload) => void;
105
105
 
106
- declare type AgentEventPayload = Record<string, unknown>;
106
+ export declare type AgentEventHandler = (name: string, payload: AgentEventPayload) => void;
107
+
108
+ export declare type AgentEventPayload = Record<string, unknown>;
109
+
110
+ declare interface AgreePrivacyResult {
111
+ /**
112
+ * 用户是否同意隐私协议授权。
113
+ */
114
+ result: boolean;
115
+ }
116
+
117
+ declare interface AIAppMetadata {
118
+ /**
119
+ *
120
+ * 豆包应用 ID
121
+ *
122
+ */
123
+ appId: string;
124
+ /**
125
+ * 应用名称
126
+ */
127
+ name?: string;
128
+ /**
129
+ * 应用描述
130
+ */
131
+ description?: string;
132
+ /**
133
+ * 应用图标
134
+ *
135
+ * 1x, 2x, 3x 分别对应 1x, 2x, 3x 倍的图标
136
+ */
137
+ icons?: Icons;
138
+ /**
139
+ * 应用关键词
140
+ */
141
+ keywords?: string[];
142
+ /**
143
+ * 应用版本
144
+ */
145
+ version?: string;
146
+ /**
147
+ * 是否声明小程序已适配深色模式
148
+ */
149
+ darkMode?: boolean;
150
+ /**
151
+ * 应用级对话框能力配置
152
+ */
153
+ chat?: AppletChatConfig;
154
+ }
155
+
156
+ export declare type AIToolContext = MessageMeta & {
157
+ /**
158
+ * callback Id
159
+ */
160
+ callbackId: string;
161
+ /**
162
+ * feature map
163
+ */
164
+ featureMap: Record<string, string> | undefined;
165
+ };
107
166
 
108
167
  export declare type AIViewContext = MessageMeta & {
109
168
  /**
@@ -141,6 +200,44 @@ export declare type AIViewContext = MessageMeta & {
141
200
  };
142
201
  };
143
202
 
203
+ export declare type AnyObject = Record<string, any>;
204
+
205
+ export declare type App<T extends DefineAppOptions = DefineAppOptions> = T & {
206
+ readonly eventChannel: EventChannel;
207
+ __APP__: boolean;
208
+ __UI__: boolean;
209
+ };
210
+
211
+ declare type AppAIMeta = Omit<AIAppMetadata, 'appId'> & {
212
+ appId?: string;
213
+ package?: string;
214
+ };
215
+
216
+ declare interface AppletChatConfig {
217
+ /**
218
+ * App-level chat feature overrides.
219
+ */
220
+ features?: AppletChatFeaturesConfig;
221
+ }
222
+
223
+ declare interface AppletChatFeatureConfig {
224
+ /**
225
+ * Whether the chat feature is enabled.
226
+ */
227
+ enabled: boolean;
228
+ }
229
+
230
+ declare interface AppletChatFeaturesConfig {
231
+ /**
232
+ * Camera entry configuration.
233
+ */
234
+ camera?: AppletChatFeatureConfig;
235
+ /**
236
+ * Extra actions entry configuration.
237
+ */
238
+ extraActions?: AppletChatFeatureConfig;
239
+ }
240
+
144
241
  export { Attributes }
145
242
 
146
243
  export { CElement }
@@ -201,12 +298,216 @@ export { createElement }
201
298
 
202
299
  export { createRef }
203
300
 
301
+ /** 当前页面栈中的页面信息。 */
204
302
  export declare interface CurrentPage {
303
+ /** 页面路由。 */
205
304
  route: string;
305
+ /**
306
+ * @since 0.1.0
307
+ * 页面查询参数。
308
+ */
309
+ query: Record<string, string>;
206
310
  }
207
311
 
208
312
  export { CustomComponentPropsWithRef }
209
313
 
314
+ export declare function defineApp<T extends DefineAppOptions>(options: T & ThisType<T & {
315
+ readonly aiMeta: AppAIMeta;
316
+ readonly eventChannel: EventChannel;
317
+ }>): App<T>;
318
+
319
+ export declare interface DefineAppOptions {
320
+ [key: string]: any;
321
+ /**
322
+ * @deprecated Configure app metadata in src/app.config.ts instead.
323
+ *
324
+ * @example
325
+ * ```ts
326
+ * // src/app.config.ts
327
+ * import { defineAppConfig } from '@doubao-dev/framework/config';
328
+ *
329
+ * export default defineAppConfig({
330
+ * appId: 'your-app-id',
331
+ * name: 'Demo App',
332
+ * description: 'Describe what this app can do',
333
+ * icons: 'https://example.com/icon.png',
334
+ * keywords: ['demo', 'doubao']
335
+ * });
336
+ * ```
337
+ */
338
+ aiMeta?: AppAIMeta;
339
+ /**
340
+ * App launched
341
+ */
342
+ onLaunch?: () => void;
343
+ /**
344
+ * On page opened
345
+ */
346
+ onPageOpened?: (params: {
347
+ viewId: string;
348
+ }) => void;
349
+ /**
350
+ * Handle an event sent by the Agent to the app.
351
+ */
352
+ onAgentEvent?: AgentEventHandler;
353
+ /**
354
+ * On foreground
355
+ */
356
+ onForeground?: () => void;
357
+ /**
358
+ * On background
359
+ */
360
+ onBackground?: () => void;
361
+ /**
362
+ * On destroy
363
+ */
364
+ onDestroy?: () => void;
365
+ /**
366
+ * Handle errors from other App callbacks or tools in the same Applet.
367
+ */
368
+ onError?: (e: Error) => void;
369
+ }
370
+
371
+ export declare interface DefineFunctionalToolOptions extends Tool {
372
+ onApply: (input: string, context: AIToolContext) => string | object | Promise<string | object>;
373
+ }
374
+
375
+ export declare function defineLoginApi(api: LoginApi): LoginApi;
376
+
377
+ /**
378
+ * 定义 MCP 登录页面
379
+ * @param options 定义 MCP 登录页面的选项
380
+ * @returns 智能服务 MCP 登录页面
381
+ */
382
+ export declare function defineLoginPage<Data extends AnyObject>(options: Omit<DefinePageToolOptions<Data>, 'aiMeta'> & ThisType<Readonly<PageInstanceMethods<Data>>>): Page<Data>;
383
+
384
+ export declare function definePage<Data extends AnyObject>(options: DefinePageToolOptions<Data> & ThisType<Readonly<PageInstanceMethods<Data>>>): Page<Data>;
385
+
386
+ export declare interface DefinePageToolOptions<Data extends AnyObject> extends DefineUIToolOptions<Data, PageToolExtraMetadata> {
387
+ /**
388
+ * @deprecated Configure page metadata in src/app.config.ts instead.
389
+ *
390
+ * Use `pages` entries in `src/app.config.ts`. For example,
391
+ * `pages/home/index` maps to `src/pages/home/index.tsx`, and
392
+ * `pages/account/demo/index` maps to `src/pages/account/demo/index.tsx`.
393
+ *
394
+ * @example
395
+ * ```ts
396
+ * // src/app.config.ts
397
+ * import { defineAppConfig } from '@doubao-dev/framework/config';
398
+ *
399
+ * export default defineAppConfig({
400
+ * appId: 'your-app-id',
401
+ * pages: ['pages/home/index']
402
+ * });
403
+ * ```
404
+ */
405
+ aiMeta?: PageToolMetadata;
406
+ }
407
+
408
+ export declare function definePrivacyApi(api: PrivacyApi): PrivacyApi;
409
+
410
+ /**
411
+ * 定义 MCP 同意登录和隐私协议卡片组件
412
+ * @param options 定义 MCP 同意登录和隐私协议卡片组件的选项
413
+ * @returns MCP 同意登录和隐私协议卡片组件
414
+ */
415
+ export declare function definePrivacyLoginWidget<Data extends AnyObject>(options: Omit<DefineWidgetToolOptions<Data>, 'aiMeta'> & ThisType<Readonly<WidgetInstanceMethods<Data>>>): Widget<Data>;
416
+
417
+ /**
418
+ * @deprecated Export a default Client Tool handler and configure it in `app.config.ts` instead.
419
+ */
420
+ export declare function defineTool(options: DefineFunctionalToolOptions & ThisType<Readonly<FunctionalToolInstanceMethods>>): FunctionalTool;
421
+
422
+ export declare interface DefineUIToolOptions<Data extends AnyObject, Extra extends AnyObject = AnyObject> extends Tool<Extra> {
423
+ /**
424
+ * Initial data
425
+ */
426
+ data?: Data;
427
+ /**
428
+ * Trigger on view created
429
+ * @returns
430
+ */
431
+ onCreated?: () => void;
432
+ /**
433
+ * It is triggered after the view is rendered and will only be called once in the view's life cycle.
434
+ * @returns
435
+ */
436
+ onMounted?: () => void;
437
+ /**
438
+ * 1. It is triggered when the view is first displayed.
439
+ * 2. It is triggered when the view is displayed again after being hidden.
440
+ * @returns
441
+ */
442
+ onShow?: () => void;
443
+ /**
444
+ * It is triggered when the view is hidden.
445
+ * @returns
446
+ */
447
+ onHide?: () => void;
448
+ /**
449
+ * It is triggered when the view is destroyed.
450
+ * @returns
451
+ */
452
+ onDestroy?: () => void;
453
+ /**
454
+ * It is triggered when an error occurs.
455
+ * @param e
456
+ * @returns
457
+ */
458
+ onError?: (e: Error) => void;
459
+ /**
460
+ * Render function
461
+ * Use getViewData() and getViewContext() to access data and context
462
+ * @returns
463
+ */
464
+ render: () => ReactNode;
465
+ }
466
+
467
+ export declare function defineWidget<Data extends AnyObject>(options: DefineWidgetToolOptions<Data> & ThisType<Readonly<WidgetInstanceMethods<Data>>>): Widget<Data>;
468
+
469
+ export declare interface DefineWidgetToolOptions<Data extends AnyObject> extends DefineUIToolOptions<Data, WidgetToolExtraMetadata> {
470
+ /**
471
+ * @deprecated Configure widget metadata in src/app.config.ts instead.
472
+ *
473
+ * Use `widgets` entries in `src/app.config.ts`. For example,
474
+ * `widgets/card/index` maps to `src/widgets/card/index.tsx`, and
475
+ * `widgets/api/demo/index` maps to `src/widgets/api/demo/index.tsx`.
476
+ *
477
+ * @example
478
+ * ```ts
479
+ * // src/app.config.ts
480
+ * import { defineAppConfig } from '@doubao-dev/framework/config';
481
+ *
482
+ * export default defineAppConfig({
483
+ * appId: 'your-app-id',
484
+ * widgets: [
485
+ * {
486
+ * entry: 'widgets/card/index',
487
+ * id: 'card-widget',
488
+ * name: 'Card Widget',
489
+ * description: 'Show card content',
490
+ * border: true
491
+ * }
492
+ * ]
493
+ * });
494
+ * ```
495
+ */
496
+ aiMeta?: WidgetToolMetadata;
497
+ /**
498
+ * 1. It is triggered when the app returns to the foreground from the background.
499
+ * 2. It is triggered when phone is unlocked.
500
+ * @returns
501
+ */
502
+ onForeground?: () => void;
503
+ /**
504
+ * 1. It is triggered when the app is moved to the background.
505
+ * 2. It is triggered when phone is locked.
506
+ * @returns
507
+ */
508
+ onBackground?: () => void;
509
+ }
510
+
210
511
  export { DependencyList }
211
512
 
212
513
  export { DeprecatedLifecycle }
@@ -225,6 +526,19 @@ export { ElementRef }
225
526
 
226
527
  export { ElementType }
227
528
 
529
+ export declare type EventCallback = (...args: any[]) => void;
530
+
531
+ export declare class EventChannel {
532
+ private readonly handleError;
533
+ private listeners;
534
+ constructor(handleError?: (error: unknown) => void);
535
+ emit(eventName: string, ...args: any[]): void;
536
+ on(eventName: string, callback: EventCallback): void;
537
+ once(eventName: string, callback: EventCallback): void;
538
+ off(eventName: string, callback?: EventCallback): void;
539
+ private addListener;
540
+ }
541
+
228
542
  export { ExoticComponent }
229
543
 
230
544
  export { Factory }
@@ -241,24 +555,49 @@ export { ForwardRefRenderFunction }
241
555
 
242
556
  export { Fragment }
243
557
 
558
+ export declare interface FunctionalTool extends DefineFunctionalToolOptions {
559
+ __FUNCTIONAL__: boolean;
560
+ }
561
+
562
+ declare type FunctionalToolInstanceMethods = Tool<ToolMetadata>;
563
+
244
564
  export { FunctionComponent }
245
565
 
246
566
  export { FunctionComponentElement }
247
567
 
248
568
  export { FunctionComponentFactory }
249
569
 
250
- export declare function getCurrentPages(): CurrentPage[];
570
+ declare function getApp_2<T extends App = App>(): T;
571
+ export { getApp_2 as getApp }
572
+
573
+ export declare function getCurrentPages(): {
574
+ route: string;
575
+ query: Record<string, string>;
576
+ }[];
251
577
 
252
578
  export { GetDerivedStateFromError }
253
579
 
254
580
  export { GetDerivedStateFromProps }
255
581
 
582
+ declare interface GetPhoneNumberResult {
583
+ /**
584
+ * 获取手机号结果码。
585
+ */
586
+ code?: string;
587
+ /**
588
+ * 获取手机号结果信息。
589
+ */
590
+ message?: string;
591
+ }
592
+
256
593
  export declare function getViewContext(): any;
257
594
 
258
595
  export declare function getViewData<T extends Record<string, any>>(): T;
259
596
 
260
597
  export declare function getWidgetInstanceId(): string | undefined;
261
598
 
599
+ declare type Icons = string | Record<'1x' | '2x' | '3x', string>;
600
+
262
601
  export { isValidElement }
263
602
 
264
603
  export { JSXElementConstructor }
@@ -275,6 +614,13 @@ declare type LifecycleCallback = () => void;
275
614
 
276
615
  declare type LifecycleErrorCallback = (error: Error) => void;
277
616
 
617
+ export declare interface LoginApi {
618
+ onLogin: (res: LoginResult) => Promise<void> | void;
619
+ onRefuseLogin: () => Promise<void> | void;
620
+ }
621
+
622
+ export declare type LoginResult = GetPhoneNumberResult;
623
+
278
624
  export { memo }
279
625
 
280
626
  export { MemoExoticComponent }
@@ -322,6 +668,36 @@ export { NamedExoticComponent }
322
668
 
323
669
  export { NewLifecycle }
324
670
 
671
+ /**
672
+ * Register the runtime error handler.
673
+ *
674
+ * Calling this again replaces the previously registered handler.
675
+ */
676
+ export declare function onError(callback: (error: Error) => void): void;
677
+
678
+ export declare interface Page<Data extends AnyObject = AnyObject> extends DefineUIToolOptions<Data> {
679
+ __UI__: boolean;
680
+ __PAGE__: boolean;
681
+ }
682
+
683
+ declare type PageInstanceMethods<Data extends AnyObject> = UIInstanceMethods<Data, PageToolExtraMetadata>;
684
+
685
+ declare type PageToolExtraMetadata = {
686
+ /**
687
+ * The page navbar title
688
+ */
689
+ title?: string;
690
+ };
691
+
692
+ export declare type PageToolMetadata = ToolMeta & PageToolExtraMetadata;
693
+
694
+ export declare type PrivacyAgreeResult = AgreePrivacyResult;
695
+
696
+ export declare interface PrivacyApi {
697
+ onAgreePrivacy: (res: PrivacyAgreeResult) => Promise<void> | void;
698
+ onRefusePrivacy: () => Promise<void> | void;
699
+ }
700
+
325
701
  export { PropsWithChildren }
326
702
 
327
703
  export { PropsWithoutRef }
@@ -382,10 +758,57 @@ export { Suspense }
382
758
 
383
759
  export { SVGFactory }
384
760
 
761
+ export declare interface Tool<Extra extends AnyObject = AnyObject> {
762
+ aiMeta?: ToolMeta & Extra;
763
+ }
764
+
765
+ export declare interface ToolMeta {
766
+ /**
767
+ * unique identifier
768
+ */
769
+ id: string;
770
+ /**
771
+ * name of the tool
772
+ */
773
+ name?: string;
774
+ /**
775
+ * description of the tool
776
+ */
777
+ description?: string;
778
+ /**
779
+ * Widget title type
780
+ * - none: 默认,无标题
781
+ * - normal: 常规标题
782
+ * - float: 浮动标题
783
+ */
784
+ titleType?: 'none' | 'normal' | 'float';
785
+ }
786
+
787
+ export declare type ToolMetadata = {
788
+ /**
789
+ * specifies when a call to a tool will time out, in ms.
790
+ */
791
+ timeout?: number;
792
+ };
793
+
385
794
  export { TransitionFunction }
386
795
 
387
796
  export { TransitionStartFunction }
388
797
 
798
+ export declare interface UIInstanceMethods<Data extends AnyObject, Extra extends AnyObject = AnyObject> extends Tool<Extra> {
799
+ /**
800
+ * Instance data
801
+ */
802
+ data: Data;
803
+ /**
804
+ * Set data asynchronously and trigger view re-rendering
805
+ * @param data
806
+ * @param callback
807
+ * @returns
808
+ */
809
+ setData: (data: Partial<Data> & AnyObject, callback?: () => void) => Promise<void>;
810
+ }
811
+
389
812
  export declare function useAgentEvent(eventName: string, callback: AgentEventCallback): void;
390
813
 
391
814
  export declare function useBackground(callback: LifecycleCallback): void;
@@ -453,4 +876,37 @@ export { VFC }
453
876
 
454
877
  export { VoidFunctionComponent }
455
878
 
879
+ export declare interface Widget<Data extends AnyObject = AnyObject> extends DefineWidgetToolOptions<Data> {
880
+ __UI__: boolean;
881
+ __WIDGET__: boolean;
882
+ setData: (data: Partial<Data>, callback?: () => void) => void;
883
+ }
884
+
885
+ declare type WidgetInstanceMethods<Data extends AnyObject> = UIInstanceMethods<Data, WidgetToolExtraMetadata>;
886
+
887
+ declare type WidgetToolExtraMetadata = {
888
+ /**
889
+ * Widget box type in Chat UI
890
+ */
891
+ boxType?: 'inbox' | 'full_box';
892
+ /**
893
+ * Whether add widget border
894
+ */
895
+ border?: boolean;
896
+ /**
897
+ * Keywords of things
898
+ */
899
+ keywords?: string[];
900
+ /**
901
+ * Icons
902
+ */
903
+ icons?: Icons;
904
+ /**
905
+ * Set extra widget properties
906
+ */
907
+ prop?: string;
908
+ };
909
+
910
+ export declare type WidgetToolMetadata = ToolMeta & WidgetToolExtraMetadata;
911
+
456
912
  export { }
package/jsx-runtime.d.ts CHANGED
@@ -14,6 +14,7 @@ export namespace JSX {
14
14
  interface IntrinsicClassAttributes<T> extends React.JSX.IntrinsicClassAttributes<T> {}
15
15
  interface IntrinsicElements {
16
16
  // Extended components
17
+ audio: import('./components.d.ts').AudioProps;
17
18
  button: import('./components.d.ts').ButtonProps;
18
19
  canvas: import('./components.d.ts').CanvasProps;
19
20
  map: import('./components.d.ts').MapProps;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doubao-dev/framework",
3
- "version": "0.0.42",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "types": "./dist/index.d.ts",
6
6
  "exports": {
@@ -78,6 +78,7 @@
78
78
  "scripts": {
79
79
  "sync:declarations": "node scripts/sync-declarations.cjs",
80
80
  "dev": "tsc -p tsconfig.json -w",
81
- "build": "npm run sync:declarations && rimraf dist && rslib build && tsc"
81
+ "build": "npm run sync:declarations && rimraf dist && rslib build && tsc && npm run sanitize:api-docs",
82
+ "sanitize:api-docs": "node scripts/sanitize-api-declarations.cjs"
82
83
  }
83
84
  }
package/types.d.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  // Generated file. Do not edit this file directly.
2
2
  // CSS modules
3
+ /** App version tag resolved by the build and used for deployment. */
4
+ declare const __VERSION_TAG__: string | undefined;
5
+
3
6
  type CSSModuleClasses = { readonly [key: string]: string };
4
7
 
5
8
  declare module '*.module.css' {