@doubao-apps/kit 0.0.28 → 0.0.29

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/29.js CHANGED
@@ -1,2 +1,2 @@
1
- import"node:module";import{Command as n,Launcher as o}from"./288.js";let t=function(n=o){return async function({cliOptions:o={},appDirectory:t=process.cwd(),command:i}){let c=new n(t);await c.run(i,o)}}(o);function i(o,i){return t({cliOptions:o,appDirectory:i,command:n.DEV})}function c(o,i){return t({cliOptions:o,appDirectory:i,command:n.BUILD})}function r(o,i){return t({cliOptions:o,appDirectory:i,command:n.ANALYZE})}export{r as analyze,c as build,i as dev};
1
+ import"node:module";import{resolveLoginCookie as n,Command as o,Launcher as t}from"./288.js";let i=function(n=t){return async function({cliOptions:o={},appDirectory:t=process.cwd(),command:i}){let r=new n(t);await r.run(i,o)}}(t);function r(n,t){return i({cliOptions:n,appDirectory:t,command:o.DEV})}function c(n,t){return i({cliOptions:n,appDirectory:t,command:o.BUILD})}function e(n,t){return i({cliOptions:n,appDirectory:t,command:o.ANALYZE})}function u(o){return n(o??{},{force:!0})}export{e as analyze,c as build,r as dev,u as login};
2
2
  //# sourceMappingURL=29.js.map
package/dist/614.js ADDED
@@ -0,0 +1,2 @@
1
+ import"node:module";function r(r){if(r instanceof Error)return r.message;if("string"==typeof r)return r;try{return JSON.stringify(r)??String(r)}catch{return String(r)}}export{r as getErrorMessage};
2
+ //# sourceMappingURL=614.js.map
@@ -1,3 +1,3 @@
1
- import"node:module";import e from"magic-string";import{parseSync as o,simple as t}from"../../../330.js";let r={button:"DoubaoButton",map:"DoubaoMap","map-marker":"DoubaoMapMarker","long-image":"DoubaoLongImage","movable-area":"DoubaoMovableArea","movable-view":"DoubaoMovableView",popup:"DoubaoPopup",radio:"DoubaoRadio","radio-group":"DoubaoRadioGroup",slider:"DoubaoSlider",switch:"DoubaoSwitch",swiper:"DoubaoSwiper","swiper-item":"DoubaoSwiperItem","picker-column":"DoubaoPickerColumn","picker-divider":"DoubaoPickerDivider","picker-view":"DoubaoPickerView",video:"DoubaoVideo","web-view":"DoubaoWebView",image:"DoubaoImage",input:"DoubaoInput",list:"DoubaoList","scroll-view":"DoubaoScrollView",svg:"DoubaoSvg",text:"DoubaoText",textarea:"DoubaoTextArea",view:"DoubaoView"};function a(e){return"Identifier"===e.type&&e.value in r?e.value:null}function i(e,o,t,r,a){if("Identifier"!==o.type)return;let i=a(o.span.start-r),n=a(o.span.end-r);e.overwrite(i,n,t)}export default function(n){let u=this.async();try{let l=new e(n),p=o(n,{syntax:"typescript",tsx:!0,decorators:!0}),b=function(e){let o=0;for(;o<e.length;){let t=e[o];if(" "===t||" "===t||"\n"===t||"\r"===t||"\f"===t){o+=1;continue}if("/"===t&&"/"===e[o+1]){for(o+=2;o<e.length&&"\n"!==e[o];)o+=1;continue}if("/"===t&&"*"===e[o+1]){for(o+=2;o<e.length&&("*"!==e[o]||"/"!==e[o+1]);)o+=1;o<e.length&&(o+=2);continue}break}return Buffer.byteLength(e.slice(0,o))}(n),s=Math.max(0,p.span.start-b),f=function(e){let o=new Map([[0,0]]),t=0,r=0;for(let a of e)t+=Buffer.byteLength(a),r+=a.length,o.set(t,r);return e=>{let t=o.get(e);if(void 0===t)throw Error(`Unable to map byte offset ${e} to string index`);return t}}(n),m=new Set;if(t(p,{JSXOpeningElement(e){let o=a(e.name);if(!o)return;let t=r[o];i(l,e.name,t,s,f),m.add(t)},JSXClosingElement(e){let o=a(e.name);if(!o)return;let t=r[o];i(l,e.name,t,s,f),m.add(t)}}),m.size>0){let e=Array.from(m).map(e=>{let o=e.replace("Doubao","");return`${o} as ${e}`}).join(", "),o=`import { ${e} } from '@byted-doubao-apps/framework/components';
1
+ import"node:module";import e from"magic-string";import{parseSync as o,simple as t}from"../../../330.js";let r={button:"DoubaoButton",canvas:"DoubaoCanvas",map:"DoubaoMap","map-marker":"DoubaoMapMarker","long-image":"DoubaoLongImage","movable-area":"DoubaoMovableArea","movable-view":"DoubaoMovableView",popup:"DoubaoPopup",radio:"DoubaoRadio","radio-group":"DoubaoRadioGroup",slider:"DoubaoSlider",switch:"DoubaoSwitch",swiper:"DoubaoSwiper","swiper-item":"DoubaoSwiperItem","picker-column":"DoubaoPickerColumn","picker-divider":"DoubaoPickerDivider","picker-view":"DoubaoPickerView","theme-provider":"DoubaoThemeProvider",video:"DoubaoVideo","web-view":"DoubaoWebView",image:"DoubaoImage",input:"DoubaoInput",list:"DoubaoList","scroll-view":"DoubaoScrollView",svg:"DoubaoSvg",text:"DoubaoText",textarea:"DoubaoTextArea",view:"DoubaoView"};function a(e){return"Identifier"===e.type&&e.value in r?e.value:null}function i(e,o,t,r,a){if("Identifier"!==o.type)return;let i=a(o.span.start-r),n=a(o.span.end-r);e.overwrite(i,n,t)}export default function(n){let u=this.async();try{let l=new e(n),p=o(n,{syntax:"typescript",tsx:!0,decorators:!0}),b=function(e){let o=0;for(;o<e.length;){let t=e[o];if(" "===t||" "===t||"\n"===t||"\r"===t||"\f"===t){o+=1;continue}if("/"===t&&"/"===e[o+1]){for(o+=2;o<e.length&&"\n"!==e[o];)o+=1;continue}if("/"===t&&"*"===e[o+1]){for(o+=2;o<e.length&&("*"!==e[o]||"/"!==e[o+1]);)o+=1;o<e.length&&(o+=2);continue}break}return Buffer.byteLength(e.slice(0,o))}(n),s=Math.max(0,p.span.start-b),m=function(e){let o=new Map([[0,0]]),t=0,r=0;for(let a of e)t+=Buffer.byteLength(a),r+=a.length,o.set(t,r);return e=>{let t=o.get(e);if(void 0===t)throw Error(`Unable to map byte offset ${e} to string index`);return t}}(n),f=new Set;if(t(p,{JSXOpeningElement(e){let o=a(e.name);if(!o)return;let t=r[o];i(l,e.name,t,s,m),f.add(t)},JSXClosingElement(e){let o=a(e.name);if(!o)return;let t=r[o];i(l,e.name,t,s,m),f.add(t)}}),f.size>0){let e=Array.from(f).map(e=>{let o=e.replace("Doubao","");return`${o} as ${e}`}).join(", "),o=`import { ${e} } from '@byted-doubao-apps/framework/components';
2
2
  `;l.prepend(o)}if(l.hasChanged()){let e=l.toString(),o=l.generateMap({includeContent:!0,hires:!0,source:this.resourcePath,file:this.resourcePath});u(null,e,o)}else u(null,n)}catch(e){u(null,n)}};
3
3
  //# sourceMappingURL=index.js.map
package/dist/cli/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import"node:module";import{program as e}from"commander";import{logger as o,chalk_0 as r}from"../288.js";import{dev as a,build as t,analyze as n}from"../29.js";function i(){if(!process.env.NODE_ENV){let e=process.argv[2];process.env.NODE_ENV=["build","package","deploy","analyze","perf"].includes(e)?"production":"development"}o.greet("Doubao Apps SDK v0.0.28")}function c(e){return e.option("-c --config <config>","specify the configuration file, can be a relative or absolute path").option("--env-mode <mode>","specify the env mode to load the `.env.[mode]` file"),e}function p(i=process.cwd(),d={},s="0.0.28"){e.name("doubao").usage("<command> [options]").version(s),c(e.command("dev")).description("starting the dev server...").action(async e=>{try{await a(e)}catch(e){o.error("Failed to dev"),o.error(e),process.exit(1)}}),c(e.command("build")).description("starting build the applet").option("-a --archive","Archive all package",!1).option("-ch --channel <string>","Need channel name").action(async e=>{try{await t(e)}catch(e){o.error("Failed to build"),o.error(e),process.exit(1)}}),c(e.command("analyze")).description("analyze the applet package").action(async e=>{try{await n(e)}catch(e){o.error(r.red("Failed to analyze")),o.error(e),process.exit(1)}}),e.parse()}export{i as prepareCli,p as runCli};
1
+ import"node:module";import{program as e}from"commander";import{logger as o,chalk_0 as r}from"../288.js";import{dev as a,login as t,build as i,analyze as n}from"../29.js";function c(){if(!process.env.NODE_ENV){let e=process.argv[2];process.env.NODE_ENV=["build","package","deploy","analyze","perf"].includes(e)?"production":"development"}o.greet("Doubao Apps SDK v0.0.29")}function s(e){return e.option("-c --config <config>","specify the configuration file, can be a relative or absolute path").option("--env-mode <mode>","specify the env mode to load the `.env.[mode]` file"),e}function p(c=process.cwd(),d={},l="0.0.29"){var m;e.name("doubao").usage("<command> [options]").version(l),s(e.command("dev")).description("starting the dev server...").action(async e=>{try{await a(e)}catch(e){o.error("Failed to dev"),o.error(e),process.exit(1)}}),((m=e.command("login")).option("--login-browser <browser>","browser for interactive login: system Chrome/Edge first, optional Playwright Chromium fallback (auto/chrome/msedge/chromium)","auto").option("--login-browser-path <path>","custom Chromium-based browser executable path for login"),m).description("login to Doubao Apps").action(async e=>{try{await t(e),o.info(r.green("Login succeeded."))}catch(e){o.error(r.red("Failed to login")),o.error(e),process.exit(1)}}),s(e.command("build")).description("starting build the applet").option("-a --archive","Archive all package",!1).option("-ch --channel <string>","Need channel name").action(async e=>{try{await i(e)}catch(e){o.error("Failed to build"),o.error(e),process.exit(1)}}),s(e.command("analyze")).description("analyze the applet package").action(async e=>{try{await n(e)}catch(e){o.error(r.red("Failed to analyze")),o.error(e),process.exit(1)}}),e.parse()}export{c as prepareCli,p as runCli};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- export { analyze, build, dev } from '@byted-doubao-apps/kit/commands';
1
+ export { analyze, build, dev, login } from '@byted-doubao-apps/kit/commands';
2
2
  export type { CliOptions } from '@byted-doubao-apps/kit/commands';
@@ -1 +1 @@
1
- import"node:module";export{analyze,build,dev}from"../29.js";
1
+ import"node:module";export{analyze,build,dev,login}from"../29.js";
@@ -1,5 +1,5 @@
1
- import"node:module";import{__webpack_require__ as e}from"../rslib-runtime.js";import{execFileSync as t}from"node:child_process";import{getDoubaoAppsDomain as a,node_path as o,fileURLToPath as r,promises as i,getPPEEnvironmentHeader as n,dev_server_log_plugin_getDebugDriver as s,node_fs as c,getDebugScenes as p,Launcher as l,executeDebugScene as d,loadDebugScene as u,archivePackage as f,isDebugMode as y}from"../288.js";let h=o.join("src","app.config.ts"),m=o.join("src","app.ts");function g(e){return e.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}async function w(e,t,a=""){for(let r of[h,m].map(t=>o.join(e,t))){let e;try{e=await i.readFile(r,"utf8")}catch(e){if(e?.code==="ENOENT")continue;throw e}let o=e.replace("<%= appId %>",g(t)).replace("<%= name %>",g(a));o!==e&&await i.writeFile(r,o,"utf8")}}let b=new Set(["node_modules","dist",".git"]);async function E(e,t,a={}){let{includeAI:r=!0}=a,n=async(e,t)=>{for(let a of(await i.mkdir(t,{recursive:!0}),await i.readdir(e,{withFileTypes:!0}))){let s=o.join(e,a.name),c=o.join(t,a.name);if(a.isDirectory()){if(b.has(a.name)||"references"===a.name&&!r)continue;await n(s,c)}else{if("AGENTS.md"===a.name&&!r)continue;await i.copyFile(s,c)}}};await n(e,t)}let j=new Set([".js",".cjs",".mjs",".ts",".tsx",".jsx",".json",".md",".txt",".scss",".css",".less",".html",".yml",".yaml"]),D=[["@byted-doubao-apps/framework","@doubao-apps/framework"],["@byted-doubao-apps/kit","@doubao-apps/kit"],["@byted-doubao-apps/ai","@doubao-apps/ai"],["@byted-doubao-apps/create","@doubao-apps/create"],["@byted-doubao-apps/taro-runtime","@doubao-apps/taro-runtime"]],v=["doubao.config.ts"],S=["@byted-doubao-apps/deploy","@doubao-apps/deploy"],N=["deploy"],O=["pnpm run deploy","doubao.config.ts","部署到豆包平台"];function _(e){let t=e;for(let[e,a]of D)t=t.replace(RegExp(e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"g"),a);return t}async function T(e,t){for(let r of(await i.readdir(e,{withFileTypes:!0}))){var a;let n=o.join(e,r.name);if(function(e){return v.some(t=>t===e)}(r.name)){await i.rm(n,{recursive:!0,force:!0});continue}if(r.isDirectory()){await T(n,t);continue}if(a=r.name,!j.has(o.extname(a))&&"package.json"!==a&&"tsconfig.json"!==a)continue;let s=await i.readFile(n,"utf-8");await i.writeFile(n,function(e,t,a){if("package.json"===e){let e=JSON.parse(_(t));if(e.scripts&&"object"==typeof e.scripts){for(let t of N)delete e.scripts[t];0===Object.keys(e.scripts).length&&delete e.scripts}for(let t of["dependencies","devDependencies","peerDependencies"])if(e[t]&&"object"==typeof e[t]){for(let o of Object.keys(e[t]))S.some(e=>e===o)?delete e[t][o]:o.startsWith("@doubao-apps/")&&(e[t][o]=`^${a}`);0===Object.keys(e[t]).length&&delete e[t]}return`${JSON.stringify(e,null,2)}
2
- `}return"README.md"===e||"AGENTS.md"===e?_(t).split("\n").filter(e=>!O.some(t=>e.includes(t))).join("\n"):_(t)}(r.name,s,t))}}async function $(e,t){let a=o.join(e,"package.json");if(!c.existsSync(a))throw Error("package.json not found in template");let r=JSON.parse(c.readFileSync(a,"utf-8"));r.name=t,c.writeFileSync(a,`${JSON.stringify(r,null,2)}
3
- `)}let k=["starter","empty"],x=r(import.meta.url),P=o.dirname(x),F={".gitignore":["dist","node_modules",".DS_Store"]};async function C(e){for(let[t,a]of Object.entries(F))await i.writeFile(o.join(e,t),`${a.join("\n")}
4
- `)}async function A(){let e=o.resolve(P,"..","package.json");return JSON.parse(await i.readFile(e,"utf-8")).version??"0.0.1"}async function I(e){let a=o.join(e,".git");if(!await i.stat(a).then(e=>e.isDirectory()).catch(e=>{if(e?.code==="ENOENT")return!1;throw e}))try{t("git",["init"],{cwd:e,stdio:"ignore"})}catch(t){if(t?.code==="ENOENT")return;throw Error(`Failed to initialize git repository: ${e}`,{cause:t})}}async function J({template:e,projectDir:t,public:a=!0,includeAI:r,appId:n,name:s,packageName:c,overwrite:p}){if(!o.isAbsolute(t))throw Error(`Project directory must be an absolute path: ${t}`);if(!k.includes(e))throw Error(`Invalid template: ${e}. Valid options: ${k.join(", ")}`);let l=o.resolve(P,`template-${e}`);try{if(!(await i.stat(l)).isDirectory())throw Error(`Template path is not a directory: ${l}`)}catch(e){if(e?.code==="ENOENT")throw Error(`Template directory not found: ${l}`,{cause:e});throw Error(`Unable to access template directory: ${l}`,{cause:e})}if(await i.stat(t).then(e=>{if(!e.isDirectory())throw Error(`Project path is not a directory: ${t}`);return!0}).catch(e=>{if(e?.code==="ENOENT")return!1;throw Error(`Unable to access project directory: ${t}`,{cause:e})})){if((await i.readdir(t)).length>0&&!p)throw Error(`Project directory is not empty: ${t}`)}else await i.mkdir(t,{recursive:!0});await E(l,t,{includeAI:r}),a&&await T(t,await A()),await C(t),await I(t);let d=c??o.basename(t).trim().toLowerCase().replace(/\s+/g,"-").replace(/^[._]/,"").replace(/[^a-z0-9-~._]+/g,"-");await $(t,d),await w(t,n??`com.doubao.${d}`,s??"")}let R=e("fs");function U(e){return[{name:"DoubaoAppsDevPlugin",setup(t){t.onDevCompileDone(()=>{e?.onDevCompileDone?.()})}}]}class K{appDirectory;launcher;constructor(e,t=l){this.appDirectory=e,this.launcher=new t(e)}async create(e){await J(e)}async dev(e={}){let{compileHooks:t,...a}=e;return await this.launcher.dev({...a,rsbuildPlugins:U(t),signingEncryptionOptions:e.signingEncryptionOptions})}async build(e={}){process.env.NODE_ENV="production";let{compileHooks:t,...a}=e;await this.launcher.build({...a,rsbuildPlugins:U(t),signingEncryptionOptions:e.signingEncryptionOptions,versionTag:e.versionTag})}async discoverWidgets(){return Object.values(this.launcher.context.metadata.getData().widgets)}async discoverPages(){return Object.values(this.launcher.context.metadata.getData().pages)}async discoverTools(){return Object.values(this.launcher.context.metadata.getData().tools)}async pushWidget(e){let{widgetId:t,deviceId:a,botId:o,widgetData:r,hdt:i}=e,n=await s({hdt:i,deviceId:a}),c=this.launcher.context.metadata.getData().app.appId;n.pushWidget({appId:c,widgetId:t,widgetData:r,botId:o})}async openPage(e){let{pageId:t,pageData:a,pageSettings:o,mode:r,hdt:i,deviceId:n}=e,c=await s({hdt:i,deviceId:n}),p=this.launcher.context.metadata.getData().app.appId;c.openPage({appId:p,pageId:t,pageData:a,pageSettings:o,mode:r})}async callTool(e){let{toolId:t,toolData:a,hdt:o,deviceId:r}=e,i=await s({hdt:o,deviceId:r}),n=this.launcher.context.metadata.getData().app.appId;i.callTool({appId:n,toolId:t,toolData:a})}async executeDebugScene(e){let{matchedScene:t,deviceId:a,hdt:o}=e,r=this.launcher.context.metadata.getData().app.appId,i=await s({hdt:o,deviceId:a});await d({matchedScene:t,appId:r,driver:i})}async getDebugScenes(){let e=await p(this.appDirectory||process.cwd());return await Promise.all(e.map(async e=>({...e,content:await u(e.path)})))}async deploy(e){let{versionTag:t,cookie:o,appKey:r,signingEncryptionOptions:i}=e;process.env.NODE_ENV="production",await this.launcher.build({skipCleanupRootPath:!0,signingEncryptionOptions:i,versionTag:e.versionTag});let{manifest:s}=this.launcher.context,{appId:c,versionCode:p}=s,{packageResource:l}=await f({channelName:"doubao_app",manifest:s,rootPath:this.launcher.rootPath});if(!l)throw Error("Failed to archive package");let{resource:d}=l,u=new FormData,h=new Blob([new Uint8Array(R.default.readFileSync(d))],{type:"application/zip"});u.append("applet_file",h,"doubao_app.zip"),u.append("applet_version_code",p.toString());let m=encodeURIComponent(t),g=`https://${a(e.internal||!1)}/developer/resource_api/apps/${encodeURIComponent(r||c)}/versions/${m}/package/upload_applet`,w={...n(),Cookie:o};try{let e=await fetch(g,{method:"POST",body:u,headers:w}),t=e.headers.get("x-tt-logid")||"";if(!e.ok){let a=await e.text(),o=JSON.stringify({code:e.status,message:"HTTP Error",data:a,log_id:t});throw Error(o)}let a=await e.json();if(0!==a.code){let e=JSON.stringify({...a,log_id:t});throw Error(e)}return console.log("Deploy success:",a),a}catch(e){return console.error("Deploy error:",e?.message||e),JSON.parse(e.message)}finally{y()||R.default.rmSync(this.launcher.rootPath,{recursive:!0,force:!0})}}}export{K as DoubaoAppsSDK};
1
+ import"node:module";import{__webpack_require__ as e}from"../rslib-runtime.js";import{execFileSync as t}from"node:child_process";import{node_path as a,fileURLToPath as r,promises as o,dev_server_log_plugin_getDebugDriver as i,node_fs as n,getDebugScenes as s,requestDoubaoAppsPlatform as c,Launcher as p,executeDebugScene as l,loadDebugScene as u,archivePackage as d,isDebugMode as y}from"../288.js";import{getErrorMessage as f}from"../614.js";async function h({appId:e,versionTag:t,versionCode:a,packagePath:r,internal:o,domainId:i,cookie:s,needAuth:p=!0}){let l=new FormData,u=new Blob([new Uint8Array(n.readFileSync(r))],{type:"application/zip"});l.append("applet_file",u,"doubao_app.zip"),l.append("applet_version_code",a.toString());let d=`/developer/${p?"resource_api":"resource_internal_api"}/apps/${encodeURIComponent(e)}/versions/${encodeURIComponent(t)}/package/upload_applet`;return await c({internal:o,domainId:i,path:d,method:"POST",body:l,headers:s?{Cookie:s}:void 0})}let m=a.join("src","app.config.ts"),w=a.join("src","app.ts");function g(e){return e.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}async function b(e,t,r=""){for(let i of[m,w].map(t=>a.join(e,t))){let e;try{e=await o.readFile(i,"utf8")}catch(e){if(e?.code==="ENOENT")continue;throw e}let a=e.replace("<%= appId %>",g(t)).replace("<%= name %>",g(r));a!==e&&await o.writeFile(i,a,"utf8")}}let E=new Set(["node_modules","dist",".git"]);async function j(e,t,r={}){let{includeAI:i=!0}=r,n=async(e,t)=>{for(let r of(await o.mkdir(t,{recursive:!0}),await o.readdir(e,{withFileTypes:!0}))){let s=a.join(e,r.name),c=a.join(t,r.name);if(r.isDirectory()){if(E.has(r.name)||"references"===r.name&&!i)continue;await n(s,c)}else{if("AGENTS.md"===r.name&&!i)continue;await o.copyFile(s,c)}}};await n(e,t)}let D=new Set([".js",".cjs",".mjs",".ts",".tsx",".jsx",".json",".md",".txt",".scss",".css",".less",".html",".yml",".yaml"]),_=[["@byted-doubao-apps/framework","@doubao-apps/framework"],["@byted-doubao-apps/kit","@doubao-apps/kit"],["@byted-doubao-apps/ai","@doubao-apps/ai"],["@byted-doubao-apps/create","@doubao-apps/create"],["@byted-doubao-apps/taro-runtime","@doubao-apps/taro-runtime"]],v=["doubao.config.ts"],S=["@byted-doubao-apps/deploy","@doubao-apps/deploy"],N=["deploy"],O=["pnpm run deploy","doubao.config.ts","部署到豆包平台"];function $(e){let t=e;for(let[e,a]of _)t=t.replace(RegExp(e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"g"),a);return t}async function k(e,t){for(let i of(await o.readdir(e,{withFileTypes:!0}))){var r;let n=a.join(e,i.name);if(function(e){return v.some(t=>t===e)}(i.name)){await o.rm(n,{recursive:!0,force:!0});continue}if(i.isDirectory()){await k(n,t);continue}if(r=i.name,!D.has(a.extname(r))&&"package.json"!==r&&"tsconfig.json"!==r)continue;let s=await o.readFile(n,"utf-8");await o.writeFile(n,function(e,t,a){if("package.json"===e){let e=JSON.parse($(t));if(e.scripts&&"object"==typeof e.scripts){for(let t of N)delete e.scripts[t];0===Object.keys(e.scripts).length&&delete e.scripts}for(let t of["dependencies","devDependencies","peerDependencies"])if(e[t]&&"object"==typeof e[t]){for(let r of Object.keys(e[t]))S.some(e=>e===r)?delete e[t][r]:r.startsWith("@doubao-apps/")&&(e[t][r]=`^${a}`);0===Object.keys(e[t]).length&&delete e[t]}return`${JSON.stringify(e,null,2)}
2
+ `}return"README.md"===e||"AGENTS.md"===e?$(t).split("\n").filter(e=>!O.some(t=>e.includes(t))).join("\n"):$(t)}(i.name,s,t))}}async function P(e,t){let r=a.join(e,"package.json");if(!n.existsSync(r))throw Error("package.json not found in template");let o=JSON.parse(n.readFileSync(r,"utf-8"));o.name=t,n.writeFileSync(r,`${JSON.stringify(o,null,2)}
3
+ `)}let T=["starter","empty"],x=r(import.meta.url),F=a.dirname(x),C={".gitignore":["dist","node_modules",".DS_Store"]};async function A(e){for(let[t,r]of Object.entries(C))await o.writeFile(a.join(e,t),`${r.join("\n")}
4
+ `)}async function I(){let e=a.resolve(F,"..","package.json");return JSON.parse(await o.readFile(e,"utf-8")).version??"0.0.1"}async function R(e){let r=a.join(e,".git");if(!await o.stat(r).then(e=>e.isDirectory()).catch(e=>{if(e?.code==="ENOENT")return!1;throw e}))try{t("git",["init"],{cwd:e,stdio:"ignore"})}catch(t){if(t?.code==="ENOENT")return;throw Error(`Failed to initialize git repository: ${e}`,{cause:t})}}async function U({template:e,projectDir:t,public:r=!0,includeAI:i,appId:n,name:s,packageName:c,overwrite:p}){if(!a.isAbsolute(t))throw Error(`Project directory must be an absolute path: ${t}`);if(!T.includes(e))throw Error(`Invalid template: ${e}. Valid options: ${T.join(", ")}`);let l=a.resolve(F,`template-${e}`);try{if(!(await o.stat(l)).isDirectory())throw Error(`Template path is not a directory: ${l}`)}catch(e){if(e?.code==="ENOENT")throw Error(`Template directory not found: ${l}`,{cause:e});throw Error(`Unable to access template directory: ${l}`,{cause:e})}if(await o.stat(t).then(e=>{if(!e.isDirectory())throw Error(`Project path is not a directory: ${t}`);return!0}).catch(e=>{if(e?.code==="ENOENT")return!1;throw Error(`Unable to access project directory: ${t}`,{cause:e})})){if((await o.readdir(t)).length>0&&!p)throw Error(`Project directory is not empty: ${t}`)}else await o.mkdir(t,{recursive:!0});await j(l,t,{includeAI:i}),r&&await k(t,await I()),await A(t),await R(t);let u=c??a.basename(t).trim().toLowerCase().replace(/\s+/g,"-").replace(/^[._]/,"").replace(/[^a-z0-9-~._]+/g,"-");await P(t,u),await b(t,n??`com.doubao.${u}`,s??"")}let K=e("fs");function J(e){return[{name:"DoubaoAppsDevPlugin",setup(t){t.onDevCompileDone(()=>{e?.onDevCompileDone?.()})}}]}class z{appDirectory;launcher;constructor(e,t=p){this.appDirectory=e,this.launcher=new t(e)}async create(e){await U(e)}async dev(e={}){let{compileHooks:t,...a}=e;return await this.launcher.dev({...a,rsbuildPlugins:J(t),signingEncryptionOptions:e.signingEncryptionOptions})}async build(e={}){process.env.NODE_ENV="production";let{compileHooks:t,...a}=e;await this.launcher.build({...a,rsbuildPlugins:J(t),signingEncryptionOptions:e.signingEncryptionOptions,versionTag:e.versionTag})}async discoverWidgets(){return Object.values(this.launcher.context.metadata.getData().widgets)}async discoverPages(){return Object.values(this.launcher.context.metadata.getData().pages)}async discoverTools(){return Object.values(this.launcher.context.metadata.getData().tools)}async pushWidget(e){let{widgetId:t,deviceId:a,botId:r,widgetData:o,hdt:n}=e,s=await i({hdt:n,deviceId:a}),c=this.launcher.context.metadata.getData().app.appId;s.pushWidget({appId:c,widgetId:t,widgetData:o,botId:r})}async openPage(e){let{pageId:t,pageData:a,pageSettings:r,mode:o,hdt:n,deviceId:s}=e,c=await i({hdt:n,deviceId:s}),p=this.launcher.context.metadata.getData().app.appId;c.openPage({appId:p,pageId:t,pageData:a,pageSettings:r,mode:o})}async callTool(e){let{toolId:t,toolData:a,hdt:r,deviceId:o}=e,n=await i({hdt:r,deviceId:o}),s=this.launcher.context.metadata.getData().app.appId;n.callTool({appId:s,toolId:t,toolData:a})}async executeDebugScene(e){let{matchedScene:t,deviceId:a,hdt:r}=e,o=this.launcher.context.metadata.getData().app.appId,n=await i({hdt:r,deviceId:a});await l({matchedScene:t,appId:o,driver:n})}async getDebugScenes(){let e=await s(this.appDirectory||process.cwd());return await Promise.all(e.map(async e=>({...e,content:await u(e.path)})))}async deploy(e){let{versionTag:t,cookie:a,appKey:r,signingEncryptionOptions:o}=e;process.env.NODE_ENV="production",await this.launcher.build({skipCleanupRootPath:!0,signingEncryptionOptions:o,versionTag:e.versionTag});let{manifest:i}=this.launcher.context,{appId:n,versionCode:s}=i,{packageResource:c}=await d({channelName:"doubao_app",manifest:i,rootPath:this.launcher.rootPath});if(!c)throw Error("Failed to archive package");try{let o=await h({appId:r||n,versionTag:t,versionCode:s,packagePath:c.resource,internal:e.internal??this.launcher.context.internal,cookie:a});return console.log("Deploy success:",o),o}catch(t){console.error("Deploy error:",f(t));let e=f(t);try{return JSON.parse(e)}catch{return{code:-1,message:e,data:null,log_id:""}}}finally{y()||K.default.rmSync(this.launcher.rootPath,{recursive:!0,force:!0})}}}export{z as DoubaoAppsSDK};
5
5
  //# sourceMappingURL=sdk.js.map
package/dist/types.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { PluginTypeCheckerOptions } from '@rsbuild/plugin-type-check';
2
- import type { ResolveConfig } from '@rsbuild/core';
3
- import type { SourceConfig } from '@rsbuild/core';
2
+ import { ResolveConfig } from '@rsbuild/core';
3
+ import { SourceConfig } from '@rsbuild/core';
4
4
 
5
5
  declare interface AIAppMetadata {
6
6
  /**
@@ -121,20 +121,22 @@ declare interface BaseModuleDefinition extends BaseDefinition {
121
121
  * export default defineAppConfig({
122
122
  * appId: 'your-app-id',
123
123
  * name: 'Demo App',
124
- * pages: {
125
- * 'pages/home': {
124
+ * pages: [
125
+ * {
126
+ * entry: 'pages/home/index',
126
127
  * id: 'home-page',
127
128
  * title: 'Home',
128
129
  * description: 'The home page'
129
130
  * }
130
- * },
131
- * widgets: {
132
- * 'widgets/card': {
131
+ * ],
132
+ * widgets: [
133
+ * {
134
+ * entry: 'widgets/card/index',
133
135
  * id: 'card-widget',
134
136
  * name: 'Card Widget',
135
137
  * description: 'Show card content'
136
138
  * }
137
- * }
139
+ * ]
138
140
  * });
139
141
  * ```
140
142
  */
@@ -162,11 +164,13 @@ export declare interface DoubaoAppsBuildConfig {
162
164
  };
163
165
  }
164
166
 
167
+ declare type DoubaoAppsLegacyEntryConfig<Meta extends object> = Record<string, Meta>;
168
+
165
169
  /**
166
170
  * Metadata config loaded from src/app.config.ts.
167
171
  *
168
- * Use src/app.config.ts for app/page/widget metadata instead of source-level
169
- * aiMeta or metadata fields in doubao.config.ts.
172
+ * App metadata is declared at the top level. Pages and widgets use arrays to
173
+ * declare entries and metadata.
170
174
  *
171
175
  * @example
172
176
  * ```ts
@@ -174,52 +178,70 @@ export declare interface DoubaoAppsBuildConfig {
174
178
  * import { defineAppConfig } from '@doubao-apps/kit';
175
179
  *
176
180
  * export default defineAppConfig({
177
- * appId: 'your-app-id',
181
+ * appId: 'db_xxx',
178
182
  * name: 'Demo App',
179
- * description: 'Describe what this app can do',
180
- * pages: {
181
- * 'pages/home': {
182
- * id: 'home-page',
183
- * title: 'Home',
184
- * description: 'The home page'
183
+ * description: 'App description',
184
+ * pages: [
185
+ * 'pages/home/index',
186
+ * {
187
+ * entry: 'pages/account/demo/index',
188
+ * id: 'account-demo',
189
+ * title: 'Account Demo',
190
+ * description: 'A nested page entry'
185
191
  * }
186
- * },
187
- * widgets: {
188
- * 'widgets/card': {
192
+ * ],
193
+ * widgets: [
194
+ * 'widgets/summary/index',
195
+ * {
196
+ * entry: 'widgets/card/index',
189
197
  * id: 'card-widget',
190
198
  * name: 'Card Widget',
191
199
  * description: 'Show card content',
192
200
  * border: true
193
201
  * }
194
- * }
202
+ * ]
195
203
  * });
196
204
  * ```
197
205
  */
198
206
  export declare interface DoubaoAppsMetaConfig extends Omit<AIAppMetadata, 'appId'> {
199
207
  /**
200
- * 豆包应用 ID
208
+ * Doubao app ID.
201
209
  */
202
210
  appId?: string;
203
211
  /**
204
- * Page 配置
212
+ * Page entries and page metadata.
213
+ *
214
+ * The first page is used as the home page.
205
215
  */
206
- pages?: Record<string, DoubaoAppsPageMetaConfig>;
216
+ pages?: DoubaoAppsPageConfig;
207
217
  /**
208
- * Widget 配置
218
+ * Widget entries and widget metadata.
209
219
  */
210
- widgets?: Record<string, DoubaoAppsWidgetMetaConfig>;
220
+ widgets?: DoubaoAppsWidgetConfig;
211
221
  }
212
222
 
223
+ export declare type DoubaoAppsPageConfig = DoubaoAppsPageEntryConfig[] | DoubaoAppsLegacyEntryConfig<DoubaoAppsPageMetaConfig>;
224
+
225
+ export declare type DoubaoAppsPageEntryConfig = string | ({
226
+ entry: string;
227
+ } & DoubaoAppsPageMetaConfig);
228
+
213
229
  export declare type DoubaoAppsPageMetaConfig = Omit<AIPageMetadata, 'id' | 'path'> & {
214
230
  /**
215
- * Page ID。不配置时默认以目录名为 ID,例如 pages/account/demo 默认为 demo。
231
+ * Page ID。不配置时默认以入口目录名为 ID,例如 pages/account/demo/index 默认为 demo。
216
232
  */
217
233
  id?: string;
218
234
  };
219
235
 
236
+ export declare type DoubaoAppsWidgetConfig = DoubaoAppsWidgetEntryConfig[] | DoubaoAppsLegacyEntryConfig<DoubaoAppsWidgetMetaConfig>;
237
+
238
+ export declare type DoubaoAppsWidgetEntryConfig = string | ({
239
+ entry: string;
240
+ } & DoubaoAppsWidgetMetaConfig);
241
+
220
242
  export declare type DoubaoAppsWidgetMetaConfig = Omit<AIWidgetMetadata, 'id'> & {
221
243
  /**
222
- * Widget ID。不配置时默认以目录名为 ID,例如 widgets/api/demo 默认为 demo。
244
+ * Widget ID。不配置时默认以入口目录名为 ID,例如 widgets/api/demo/index 默认为 demo。
223
245
  */
224
246
  id?: string;
225
247
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doubao-apps/kit",
3
- "version": "0.0.28",
3
+ "version": "0.0.29",
4
4
  "type": "module",
5
5
  "types": "./dist/types.d.ts",
6
6
  "bin": {
@@ -73,6 +73,7 @@
73
73
  "lodash-es": "4.17.21",
74
74
  "magic-string": "^0.30.0",
75
75
  "ora": "^5.0.0",
76
+ "playwright-core": "^1.56.1",
76
77
  "picocolors": "1.1.1",
77
78
  "schema-utils": "^4.2.0",
78
79
  "swc-walk": "1.0.1",
@@ -81,6 +82,9 @@
81
82
  "uqr": "0.1.2",
82
83
  "zod": "3.23.8"
83
84
  },
85
+ "optionalDependencies": {
86
+ "@napi-rs/keyring": "^1.2.0"
87
+ },
84
88
  "peerDependencies": {
85
89
  "@lynx-js/react": "^0.117.1"
86
90
  },