@doubao-dev/framework 0.0.40 → 0.0.42

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/config.d.ts CHANGED
@@ -27,6 +27,14 @@ declare interface AIAppMetadata {
27
27
  * 应用版本
28
28
  */
29
29
  version?: string;
30
+ /**
31
+ * 是否声明小程序已适配深色模式
32
+ */
33
+ darkMode?: boolean;
34
+ /**
35
+ * 应用级对话框能力配置
36
+ */
37
+ chat?: AppletChatConfig;
30
38
  }
31
39
 
32
40
  declare type AIPageMetadata = Omit<PageDefinition, 'entry' | 'renderType' | 'digest' | 'web'>;
@@ -73,6 +81,38 @@ declare type AIWidgetMetadata = {
73
81
  titleType?: 'none' | 'normal' | 'float';
74
82
  };
75
83
 
84
+ declare interface AppletChatConfig {
85
+ /**
86
+ * App-level chat feature overrides.
87
+ */
88
+ features?: AppletChatFeaturesConfig;
89
+ }
90
+
91
+ declare interface AppletChatFeatureConfig {
92
+ /**
93
+ * Whether the chat feature is enabled.
94
+ */
95
+ enabled: boolean;
96
+ }
97
+
98
+ declare interface AppletChatFeaturesConfig {
99
+ /**
100
+ * Camera entry configuration.
101
+ */
102
+ camera?: AppletChatFeatureConfig;
103
+ /**
104
+ * Extra actions entry configuration.
105
+ */
106
+ extraActions?: AppletChatFeatureConfig;
107
+ }
108
+
109
+ declare interface AppletPageChatConfig {
110
+ /**
111
+ * Whether the chat panel is enabled on this page.
112
+ */
113
+ enabled: boolean;
114
+ }
115
+
76
116
  declare interface BaseDefinition {
77
117
  /**
78
118
  * Unique identifier
@@ -169,6 +209,10 @@ export declare interface DoubaoAppsMetaConfig extends AIAppMetadata {
169
209
  * Widget entries and widget metadata.
170
210
  */
171
211
  widgets?: DoubaoAppsWidgetConfig;
212
+ /**
213
+ * Client Tool entries relative to `src/`.
214
+ */
215
+ tools?: DoubaoAppsToolConfig;
172
216
  }
173
217
 
174
218
  export declare type DoubaoAppsObject = Record<string, unknown>;
@@ -209,6 +253,8 @@ export declare interface DoubaoAppsPlugin {
209
253
  setup: (api: any) => void | Promise<void>;
210
254
  }
211
255
 
256
+ export declare type DoubaoAppsToolConfig = string[];
257
+
212
258
  export declare type DoubaoAppsWidgetConfig = DoubaoAppsWidgetEntryConfig[] | DoubaoAppsLegacyEntryConfig<DoubaoAppsWidgetMetaConfig>;
213
259
 
214
260
  export declare type DoubaoAppsWidgetEntryConfig = string | ({
@@ -217,7 +263,7 @@ export declare type DoubaoAppsWidgetEntryConfig = string | ({
217
263
 
218
264
  export declare type DoubaoAppsWidgetMetaConfig = Omit<AIWidgetMetadata, 'id'> & {
219
265
  /**
220
- * Widget ID. Defaults to the entry directory name.
266
+ * Globally unique Widget ID. Defaults to the entry directory name.
221
267
  */
222
268
  id?: string;
223
269
  name?: string;
@@ -237,6 +283,12 @@ export declare type DoubaoAppsWidgetMetaConfig = Omit<AIWidgetMetadata, 'id'> &
237
283
  export declare type Icons = string | Record<'1x' | '2x' | '3x', string>;
238
284
 
239
285
  declare interface PageDefinition extends UIModuleDefinition {
286
+ /**
287
+ * The legacy page identifier.
288
+ *
289
+ * @deprecated Use `path` as the Page identity.
290
+ */
291
+ id: string;
240
292
  /**
241
293
  * The page navbar title
242
294
  */
@@ -245,6 +297,10 @@ declare interface PageDefinition extends UIModuleDefinition {
245
297
  * The page path
246
298
  */
247
299
  path: string;
300
+ /**
301
+ * Page-level chat panel configuration.
302
+ */
303
+ chat?: AppletPageChatConfig;
248
304
  }
249
305
 
250
306
  export declare interface TaroPluginOptions {
package/dist/index.d.ts CHANGED
@@ -101,52 +101,9 @@ import { useSyncExternalStore } from 'react';
101
101
  import { VFC } from 'react';
102
102
  import { VoidFunctionComponent } from 'react';
103
103
 
104
- declare interface AgreePrivacyResult {
105
- /** Whether the save was successful */
106
- result: boolean;
107
- }
104
+ export declare type AgentEventCallback = (payload: AgentEventPayload) => void;
108
105
 
109
- declare interface AIAppMetadata {
110
- /**
111
- *
112
- * 豆包应用 ID
113
- *
114
- */
115
- appId: string;
116
- /**
117
- * 应用名称
118
- */
119
- name?: string;
120
- /**
121
- * 应用描述
122
- */
123
- description?: string;
124
- /**
125
- * 应用图标
126
- *
127
- * 1x, 2x, 3x 分别对应 1x, 2x, 3x 倍的图标
128
- */
129
- icons?: Icons;
130
- /**
131
- * 应用关键词
132
- */
133
- keywords?: string[];
134
- /**
135
- * 应用版本
136
- */
137
- version?: string;
138
- }
139
-
140
- export declare type AIToolContext = MessageMeta & {
141
- /**
142
- * callback Id
143
- */
144
- callbackId: string;
145
- /**
146
- * feature map
147
- */
148
- featureMap: Record<string, string> | undefined;
149
- };
106
+ declare type AgentEventPayload = Record<string, unknown>;
150
107
 
151
108
  export declare type AIViewContext = MessageMeta & {
152
109
  /**
@@ -184,18 +141,6 @@ export declare type AIViewContext = MessageMeta & {
184
141
  };
185
142
  };
186
143
 
187
- export declare type AnyObject = Record<string, any>;
188
-
189
- export declare type App<T extends DefineAppOptions = DefineAppOptions> = T & {
190
- __APP__: boolean;
191
- __UI__: boolean;
192
- };
193
-
194
- declare type AppAIMeta = Omit<AIAppMetadata, 'appId'> & {
195
- appId?: string;
196
- package?: string;
197
- };
198
-
199
144
  export { Attributes }
200
145
 
201
146
  export { CElement }
@@ -262,195 +207,6 @@ export declare interface CurrentPage {
262
207
 
263
208
  export { CustomComponentPropsWithRef }
264
209
 
265
- export declare function defineApp<T extends DefineAppOptions>(options: T & ThisType<T & {
266
- readonly aiMeta: AppAIMeta;
267
- }>): App<T>;
268
-
269
- export declare interface DefineAppOptions {
270
- [key: string]: any;
271
- /**
272
- * @deprecated Configure app metadata in src/app.config.ts instead.
273
- *
274
- * @example
275
- * ```ts
276
- * // src/app.config.ts
277
- * import { defineAppConfig } from '@doubao-dev/framework/config';
278
- *
279
- * export default defineAppConfig({
280
- * appId: 'your-app-id',
281
- * name: 'Demo App',
282
- * description: 'Describe what this app can do',
283
- * icons: 'https://example.com/icon.png',
284
- * keywords: ['demo', 'doubao']
285
- * });
286
- * ```
287
- */
288
- aiMeta?: AppAIMeta;
289
- /**
290
- * App launched
291
- */
292
- onLaunch?: () => void;
293
- /**
294
- * On page opened
295
- */
296
- onPageOpened?: (params: {
297
- viewId: string;
298
- }) => void;
299
- /**
300
- * On foreground
301
- */
302
- onForeground?: () => void;
303
- /**
304
- * On background
305
- */
306
- onBackground?: () => void;
307
- /**
308
- * On destroy
309
- */
310
- onDestroy?: () => void;
311
- /**
312
- * Handle errors from other lifecycle hooks in this class or from tools in same Applet
313
- */
314
- onError?: (e: Error) => void;
315
- }
316
-
317
- export declare interface DefineFunctionalToolOptions extends Tool {
318
- onApply: (input: string, context: AIToolContext) => string | object | Promise<string | object>;
319
- }
320
-
321
- export declare function defineLoginApi(api: LoginApi): LoginApi;
322
-
323
- /**
324
- * 定义 MCP 登录页面
325
- * @param options 定义 MCP 登录页面的选项
326
- * @returns 智能服务 MCP 登录页面
327
- */
328
- export declare function defineLoginPage<Data extends AnyObject>(options: Omit<DefinePageToolOptions<Data>, 'aiMeta'> & ThisType<Readonly<PageInstanceMethods<Data>>>): Page<Data>;
329
-
330
- export declare function definePage<Data extends AnyObject>(options: DefinePageToolOptions<Data> & ThisType<Readonly<PageInstanceMethods<Data>>>): Page<Data>;
331
-
332
- export declare interface DefinePageToolOptions<Data extends AnyObject> extends DefineUIToolOptions<Data, PageToolExtraMetadata> {
333
- /**
334
- * @deprecated Configure page metadata in src/app.config.ts instead.
335
- *
336
- * Use `pages` entries in `src/app.config.ts`. For example,
337
- * `pages/home/index` maps to `src/pages/home/index.tsx`, and
338
- * `pages/account/demo/index` maps to `src/pages/account/demo/index.tsx`.
339
- *
340
- * @example
341
- * ```ts
342
- * // src/app.config.ts
343
- * import { defineAppConfig } from '@doubao-dev/framework/config';
344
- *
345
- * export default defineAppConfig({
346
- * appId: 'your-app-id',
347
- * pages: ['pages/home/index']
348
- * });
349
- * ```
350
- */
351
- aiMeta?: PageToolMetadata;
352
- }
353
-
354
- export declare function definePrivacyApi(api: PrivacyApi): PrivacyApi;
355
-
356
- /**
357
- * 定义 MCP 同意登录和隐私协议卡片组件
358
- * @param options 定义 MCP 同意登录和隐私协议卡片组件的选项
359
- * @returns MCP 同意登录和隐私协议卡片组件
360
- */
361
- export declare function definePrivacyLoginWidget<Data extends AnyObject>(options: Omit<DefineWidgetToolOptions<Data>, 'aiMeta'> & ThisType<Readonly<WidgetInstanceMethods<Data>>>): Widget<Data>;
362
-
363
- export declare function defineTool(options: DefineFunctionalToolOptions & ThisType<Readonly<FunctionalToolInstanceMethods>>): FunctionalTool;
364
-
365
- export declare interface DefineUIToolOptions<Data extends AnyObject, Extra extends AnyObject = AnyObject> extends Tool<Extra> {
366
- /**
367
- * Initial data
368
- */
369
- data?: Data;
370
- /**
371
- * Trigger on view created
372
- * @returns
373
- */
374
- onCreated?: () => void;
375
- /**
376
- * It is triggered after the view is rendered and will only be called once in the view's life cycle.
377
- * @returns
378
- */
379
- onMounted?: () => void;
380
- /**
381
- * 1. It is triggered when the view is first displayed.
382
- * 2. It is triggered when the view is displayed again after being hidden.
383
- * @returns
384
- */
385
- onShow?: () => void;
386
- /**
387
- * It is triggered when the view is hidden.
388
- * @returns
389
- */
390
- onHide?: () => void;
391
- /**
392
- * It is triggered when the view is destroyed.
393
- * @returns
394
- */
395
- onDestroy?: () => void;
396
- /**
397
- * It is triggered when an error occurs.
398
- * @param e
399
- * @returns
400
- */
401
- onError?: (e: Error) => void;
402
- /**
403
- * Render function
404
- * Use getViewData() and getViewContext() to access data and context
405
- * @returns
406
- */
407
- render: () => ReactNode;
408
- }
409
-
410
- export declare function defineWidget<Data extends AnyObject>(options: DefineWidgetToolOptions<Data> & ThisType<Readonly<WidgetInstanceMethods<Data>>>): Widget<Data>;
411
-
412
- export declare interface DefineWidgetToolOptions<Data extends AnyObject> extends DefineUIToolOptions<Data, WidgetToolExtraMetadata> {
413
- /**
414
- * @deprecated Configure widget metadata in src/app.config.ts instead.
415
- *
416
- * Use `widgets` entries in `src/app.config.ts`. For example,
417
- * `widgets/card/index` maps to `src/widgets/card/index.tsx`, and
418
- * `widgets/api/demo/index` maps to `src/widgets/api/demo/index.tsx`.
419
- *
420
- * @example
421
- * ```ts
422
- * // src/app.config.ts
423
- * import { defineAppConfig } from '@doubao-dev/framework/config';
424
- *
425
- * export default defineAppConfig({
426
- * appId: 'your-app-id',
427
- * widgets: [
428
- * {
429
- * entry: 'widgets/card/index',
430
- * id: 'card-widget',
431
- * name: 'Card Widget',
432
- * description: 'Show card content',
433
- * border: true
434
- * }
435
- * ]
436
- * });
437
- * ```
438
- */
439
- aiMeta?: WidgetToolMetadata;
440
- /**
441
- * 1. It is triggered when the app returns to the foreground from the background.
442
- * 2. It is triggered when phone is unlocked.
443
- * @returns
444
- */
445
- onForeground?: () => void;
446
- /**
447
- * 1. It is triggered when the app is moved to the background.
448
- * 2. It is triggered when phone is locked.
449
- * @returns
450
- */
451
- onBackground?: () => void;
452
- }
453
-
454
210
  export { DependencyList }
455
211
 
456
212
  export { DeprecatedLifecycle }
@@ -485,46 +241,24 @@ export { ForwardRefRenderFunction }
485
241
 
486
242
  export { Fragment }
487
243
 
488
- export declare interface FunctionalTool extends DefineFunctionalToolOptions {
489
- __FUNCTIONAL__: boolean;
490
- }
491
-
492
- declare type FunctionalToolInstanceMethods = Tool<ToolMetadata>;
493
-
494
244
  export { FunctionComponent }
495
245
 
496
246
  export { FunctionComponentElement }
497
247
 
498
248
  export { FunctionComponentFactory }
499
249
 
500
- declare function getApp_2<T extends App = App>(): T;
501
- export { getApp_2 as getApp }
502
-
503
250
  export declare function getCurrentPages(): CurrentPage[];
504
251
 
505
252
  export { GetDerivedStateFromError }
506
253
 
507
254
  export { GetDerivedStateFromProps }
508
255
 
509
- declare interface GetPhoneNumberResult {
510
- /**
511
- * 获取手机号结果码。
512
- */
513
- code?: string;
514
- /**
515
- * 获取手机号结果信息。
516
- */
517
- message?: string;
518
- }
519
-
520
256
  export declare function getViewContext(): any;
521
257
 
522
258
  export declare function getViewData<T extends Record<string, any>>(): T;
523
259
 
524
260
  export declare function getWidgetInstanceId(): string | undefined;
525
261
 
526
- declare type Icons = string | Record<'1x' | '2x' | '3x', string>;
527
-
528
262
  export { isValidElement }
529
263
 
530
264
  export { JSXElementConstructor }
@@ -541,13 +275,6 @@ declare type LifecycleCallback = () => void;
541
275
 
542
276
  declare type LifecycleErrorCallback = (error: Error) => void;
543
277
 
544
- export declare interface LoginApi {
545
- onLogin: (res: LoginResult) => Promise<void> | void;
546
- onRefuseLogin: () => Promise<void> | void;
547
- }
548
-
549
- export declare type LoginResult = GetPhoneNumberResult;
550
-
551
278
  export { memo }
552
279
 
553
280
  export { MemoExoticComponent }
@@ -577,41 +304,23 @@ export declare interface MessageMeta {
577
304
 
578
305
  export { Mixin }
579
306
 
580
- export { MutableRefObject }
581
-
582
- export { NamedExoticComponent }
583
-
584
- export { NewLifecycle }
585
-
586
307
  /**
587
- * Register the runtime error handler.
588
- *
589
- * Calling this again replaces the previously registered handler.
308
+ * 页面模型上下文控制器。
590
309
  */
591
- export declare function onError(callback: (error: Error) => void): void;
592
-
593
- export declare interface Page<Data extends AnyObject = AnyObject> extends DefineUIToolOptions<Data> {
594
- __UI__: boolean;
595
- __PAGE__: boolean;
596
- }
597
-
598
- declare type PageInstanceMethods<Data extends AnyObject> = UIInstanceMethods<Data, PageToolExtraMetadata>;
599
-
600
- declare type PageToolExtraMetadata = {
310
+ export declare interface ModelContext {
601
311
  /**
602
- * The page navbar title
312
+ * 设置当前页面的完整上下文。
313
+ *
314
+ * 同一页面内重复调用会更新已有上下文,请传入当前页面的完整信息。
603
315
  */
604
- title?: string;
605
- };
316
+ setPageContext: (params: SetPageContextParams) => ReturnType<typeof setPageModelContext>;
317
+ }
606
318
 
607
- export declare type PageToolMetadata = ToolMeta & PageToolExtraMetadata;
319
+ export { MutableRefObject }
608
320
 
609
- export declare type PrivacyAgreeResult = AgreePrivacyResult;
321
+ export { NamedExoticComponent }
610
322
 
611
- export declare interface PrivacyApi {
612
- onAgreePrivacy: (res: PrivacyAgreeResult) => Promise<void> | void;
613
- onRefusePrivacy: () => Promise<void> | void;
614
- }
323
+ export { NewLifecycle }
615
324
 
616
325
  export { PropsWithChildren }
617
326
 
@@ -653,6 +362,16 @@ export { RefCallback }
653
362
 
654
363
  export { RefObject }
655
364
 
365
+ /**
366
+ * 设置页面模型上下文的参数。
367
+ */
368
+ export declare interface SetPageContextParams {
369
+ taskId: string;
370
+ pageInfo: Record<string, unknown>;
371
+ }
372
+
373
+ declare const setPageModelContext: (params: SetPageContextParams) => Promise<object>;
374
+
656
375
  export { SetStateAction }
657
376
 
658
377
  export { SFCFactory }
@@ -663,56 +382,11 @@ export { Suspense }
663
382
 
664
383
  export { SVGFactory }
665
384
 
666
- export declare interface Tool<Extra extends AnyObject = AnyObject> {
667
- aiMeta?: ToolMeta & Extra;
668
- }
669
-
670
- export declare interface ToolMeta {
671
- /**
672
- * unique identifier
673
- */
674
- id: string;
675
- /**
676
- * name of the tool
677
- */
678
- name?: string;
679
- /**
680
- * description of the tool
681
- */
682
- description?: string;
683
- /**
684
- * Widget title type
685
- * - none: 默认,无标题
686
- * - normal: 常规标题
687
- * - float: 浮动标题
688
- */
689
- titleType?: 'none' | 'normal' | 'float';
690
- }
691
-
692
- export declare type ToolMetadata = {
693
- /**
694
- * specifies when a call to a tool will time out, in ms.
695
- */
696
- timeout?: number;
697
- };
698
-
699
385
  export { TransitionFunction }
700
386
 
701
387
  export { TransitionStartFunction }
702
388
 
703
- export declare interface UIInstanceMethods<Data extends AnyObject, Extra extends AnyObject = AnyObject> extends Tool<Extra> {
704
- /**
705
- * Instance data
706
- */
707
- data: Data;
708
- /**
709
- * Set data asynchronously and trigger view re-rendering
710
- * @param data
711
- * @param callback
712
- * @returns
713
- */
714
- setData: (data: Partial<Data> & AnyObject, callback?: () => void) => Promise<void>;
715
- }
389
+ export declare function useAgentEvent(eventName: string, callback: AgentEventCallback): void;
716
390
 
717
391
  export declare function useBackground(callback: LifecycleCallback): void;
718
392
 
@@ -738,6 +412,29 @@ export { useImperativeHandle }
738
412
 
739
413
  export { useMemo }
740
414
 
415
+ /**
416
+ * 获取页面模型上下文控制器。
417
+ *
418
+ * @example
419
+ * ```typescript
420
+ * import { useEffect, useModelContext } from '@doubao-dev/framework';
421
+ *
422
+ * function Page() {
423
+ * const modelContext = useModelContext();
424
+ *
425
+ * useEffect(() => {
426
+ * modelContext.setPageContext({
427
+ * taskId: 'page-session-001',
428
+ * pageInfo: { route: ['route-1'] }
429
+ * });
430
+ * }, [modelContext]);
431
+ *
432
+ * return <view />;
433
+ * }
434
+ * ```
435
+ */
436
+ export declare function useModelContext(): ModelContext;
437
+
741
438
  export declare function useMounted(callback: LifecycleCallback): void;
742
439
 
743
440
  export { useReducer }
@@ -756,37 +453,4 @@ export { VFC }
756
453
 
757
454
  export { VoidFunctionComponent }
758
455
 
759
- export declare interface Widget<Data extends AnyObject = AnyObject> extends DefineWidgetToolOptions<Data> {
760
- __UI__: boolean;
761
- __WIDGET__: boolean;
762
- setData: (data: Partial<Data>, callback?: () => void) => void;
763
- }
764
-
765
- declare type WidgetInstanceMethods<Data extends AnyObject> = UIInstanceMethods<Data, WidgetToolExtraMetadata>;
766
-
767
- declare type WidgetToolExtraMetadata = {
768
- /**
769
- * Widget box type in Chat UI
770
- */
771
- boxType?: 'inbox' | 'full_box';
772
- /**
773
- * Whether add widget border
774
- */
775
- border?: boolean;
776
- /**
777
- * Keywords of things
778
- */
779
- keywords?: string[];
780
- /**
781
- * Icons
782
- */
783
- icons?: Icons;
784
- /**
785
- * Set extra widget properties
786
- */
787
- prop?: string;
788
- };
789
-
790
- export declare type WidgetToolMetadata = ToolMeta & WidgetToolExtraMetadata;
791
-
792
456
  export { }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doubao-dev/framework",
3
- "version": "0.0.40",
3
+ "version": "0.0.42",
4
4
  "type": "module",
5
5
  "types": "./dist/index.d.ts",
6
6
  "exports": {