@heybox/hb-sdk 0.3.3 → 0.4.0

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.
Files changed (35) hide show
  1. package/README.md +63 -28
  2. package/dist/cli-chunks/browser-RAy8e8cV.cjs +635 -0
  3. package/dist/cli-chunks/create-D1j9UnM7.cjs +1376 -0
  4. package/dist/cli-chunks/deploy-CknDDoS_.cjs +3730 -0
  5. package/dist/cli-chunks/dev-BS9h09yG.cjs +955 -0
  6. package/dist/cli-chunks/doctor-WTl1HCW0.cjs +186 -0
  7. package/dist/cli-chunks/index-io4h3kr-.cjs +13348 -0
  8. package/dist/cli-chunks/index-yjJgBEBF.cjs +64023 -0
  9. package/dist/cli-chunks/login-B-A53Sta.cjs +193 -0
  10. package/dist/cli-chunks/session-CMBN3o9z.cjs +3040 -0
  11. package/dist/cli.cjs +19 -77707
  12. package/dist/devtools/mock-host/index.html +62 -2
  13. package/dist/devtools/mock-host/main.js +3246 -20
  14. package/dist/index.cjs.js +20 -0
  15. package/dist/index.esm.js +20 -0
  16. package/dist/miniapp-publish.cjs.js +2810 -4
  17. package/dist/miniapp-publish.esm.js +2809 -4
  18. package/dist/protocol.cjs.js +15 -0
  19. package/dist/protocol.esm.js +15 -1
  20. package/dist/templates/vue3-vite-ts/README.md.ejs +2 -2
  21. package/dist/vite.cjs.js +2814 -14
  22. package/dist/vite.esm.js +2814 -14
  23. package/package.json +6 -1
  24. package/skill/SKILL.md +19 -13
  25. package/skill/references/api-protocol.md +7 -2
  26. package/skill/references/api-root.md +24 -13
  27. package/skill/references/cli.md +335 -104
  28. package/skill/scripts/sync-references.mjs +17 -1
  29. package/skill/skill.json +4 -4
  30. package/types/index.d.ts +1 -1
  31. package/types/miniapp-manifest/schema.d.ts +2 -1
  32. package/types/miniapp-publish/index.d.ts +2 -1
  33. package/types/modules/viewport/index.d.ts +33 -0
  34. package/types/protocol/capabilities.d.ts +17 -2
  35. package/types/protocol.d.ts +2 -2
@@ -0,0 +1,186 @@
1
+ 'use strict';
2
+
3
+ var fs$1 = require('node:fs');
4
+ var fs = require('node:fs/promises');
5
+ var os = require('node:os');
6
+ var path = require('node:path');
7
+ var index = require('./index-io4h3kr-.cjs');
8
+ require('node:module');
9
+ require('path');
10
+ require('os');
11
+ require('readline');
12
+ require('tty');
13
+ require('assert');
14
+ require('events');
15
+ require('stream');
16
+ require('buffer');
17
+ require('util');
18
+
19
+ const DEFAULT_TIMEOUT_MS = 3000;
20
+ const PACKAGE_JSON_CANDIDATES = [
21
+ path.resolve(__dirname, '..', 'package.json'),
22
+ path.resolve(__dirname, '..', '..', 'package.json'),
23
+ path.resolve(__dirname, '..', '..', '..', 'package.json'),
24
+ ];
25
+ async function runDoctorCommand(runtime = {}) {
26
+ const logger = runtime.logger ?? index.createCliLogger();
27
+ const result = await logger.task('正在检查 Agent Skill 元数据', () => getDoctorResult(runtime), {
28
+ successText: 'Agent Skill 检查完成',
29
+ });
30
+ printDoctorResult(result, logger);
31
+ printDoctorNextStep(result, logger);
32
+ return result;
33
+ }
34
+ async function getDoctorResult(runtime = {}) {
35
+ const currentSdkVersion = await readCurrentSdkVersion(runtime.packageJsonFiles);
36
+ const localSkillJsonPath = resolveLocalSkillJsonPath(runtime);
37
+ let remoteSkill;
38
+ try {
39
+ remoteSkill = await fetchRemoteSkill(runtime);
40
+ }
41
+ catch {
42
+ return {
43
+ currentSdkVersion,
44
+ localSkillJsonPath,
45
+ status: 'REMOTE_UNAVAILABLE',
46
+ };
47
+ }
48
+ if (remoteSkill?.sdk?.version !== currentSdkVersion) {
49
+ return {
50
+ currentSdkVersion,
51
+ localSkillJsonPath,
52
+ remoteSkill,
53
+ status: 'SDK_MISMATCH',
54
+ };
55
+ }
56
+ const localSkill = await readLocalSkillManifest(localSkillJsonPath);
57
+ if (!localSkill.exists) {
58
+ return {
59
+ currentSdkVersion,
60
+ localSkillJsonPath,
61
+ remoteSkill,
62
+ status: 'SKILL_MISSING',
63
+ };
64
+ }
65
+ if (!localSkill.manifest ||
66
+ localSkill.manifest.name !== index.HB_SDK_SKILL_NAME ||
67
+ localSkill.manifest.skillVersion !== remoteSkill.version ||
68
+ localSkill.manifest.sdk?.version !== remoteSkill.sdk?.version) {
69
+ return {
70
+ currentSdkVersion,
71
+ localSkillJsonPath,
72
+ localSkillVersion: localSkill.manifest?.skillVersion,
73
+ remoteSkill,
74
+ status: 'SKILL_OUTDATED',
75
+ };
76
+ }
77
+ return {
78
+ currentSdkVersion,
79
+ localSkillJsonPath,
80
+ localSkillVersion: localSkill.manifest.skillVersion,
81
+ remoteSkill,
82
+ status: 'OK',
83
+ };
84
+ }
85
+ function printDoctorResult(result, logger) {
86
+ logger.section('Doctor');
87
+ logger.info(`SDK version: ${result.currentSdkVersion}`);
88
+ logger.info(`Remote skill: ${result.remoteSkill?.version ? `${result.remoteSkill.version} (sdk ${result.remoteSkill.sdk?.version ?? 'unknown'})` : 'unavailable'}`);
89
+ logger.info(`Local skill: ${result.localSkillVersion ?? 'missing'}`);
90
+ logger.debug(`Local skill path: ${result.localSkillJsonPath}`);
91
+ logger.info(`Status: ${result.status}`);
92
+ }
93
+ function printDoctorNextStep(result, logger) {
94
+ if (result.status === 'OK') {
95
+ logger.success('Skill is up to date.');
96
+ return;
97
+ }
98
+ if (result.status === 'SDK_MISMATCH') {
99
+ logger.warn(`Current SDK does not match the latest skill metadata. Upgrade with: npm i -D ${index.HB_SDK_PACKAGE_NAME}@latest`);
100
+ logger.info(`Then install or refresh the skill manually: ${formatSkillInstallCommand(result)}`);
101
+ return;
102
+ }
103
+ if (result.status === 'REMOTE_UNAVAILABLE') {
104
+ logger.warn('Remote skill metadata is unavailable. Try again later.');
105
+ logger.info(`Manual install command: ${index.HB_SDK_SKILL_INSTALL_COMMAND}`);
106
+ return;
107
+ }
108
+ logger.info(`Install or refresh the skill manually: ${formatSkillInstallCommand(result)}`);
109
+ }
110
+ function formatSkillInstallCommand(result) {
111
+ return `npx skills add ${result.remoteSkill?.source || index.HB_SDK_SKILL_SOURCE}`;
112
+ }
113
+ async function fetchRemoteSkill(runtime) {
114
+ const fetchImpl = runtime.fetchImpl ?? fetch;
115
+ const controller = new AbortController();
116
+ const timeout = setTimeout(() => controller.abort(), runtime.timeoutMs ?? DEFAULT_TIMEOUT_MS);
117
+ try {
118
+ const response = await fetchImpl(runtime.remoteIndexUrl ?? index.HB_SDK_SKILL_INDEX_URL, {
119
+ headers: {
120
+ accept: 'application/json',
121
+ },
122
+ signal: controller.signal,
123
+ });
124
+ if (!response.ok) {
125
+ throw new Error(`remote skill index returned ${response.status}`);
126
+ }
127
+ const index$1 = (await response.json());
128
+ const skill = index$1.skills?.find(item => item.name === index.HB_SDK_SKILL_NAME);
129
+ if (!skill?.version || skill.sdk?.package !== index.HB_SDK_PACKAGE_NAME || !skill.sdk.version) {
130
+ throw new Error('remote hb-sdk skill metadata is incomplete');
131
+ }
132
+ return skill;
133
+ }
134
+ finally {
135
+ clearTimeout(timeout);
136
+ }
137
+ }
138
+ async function readLocalSkillManifest(skillJsonPath) {
139
+ if (!(await pathExists(skillJsonPath))) {
140
+ return {
141
+ exists: false,
142
+ };
143
+ }
144
+ try {
145
+ return {
146
+ exists: true,
147
+ manifest: JSON.parse(await fs.readFile(skillJsonPath, 'utf8')),
148
+ };
149
+ }
150
+ catch {
151
+ return {
152
+ exists: true,
153
+ };
154
+ }
155
+ }
156
+ async function readCurrentSdkVersion(packageJsonCandidates = PACKAGE_JSON_CANDIDATES) {
157
+ for (const candidate of packageJsonCandidates) {
158
+ if (!(await pathExists(candidate))) {
159
+ continue;
160
+ }
161
+ const packageJson = JSON.parse(await fs.readFile(candidate, 'utf8'));
162
+ if (typeof packageJson.version === 'string' && packageJson.version) {
163
+ return packageJson.version;
164
+ }
165
+ }
166
+ throw new Error('未能读取 @heybox/hb-sdk 当前版本号');
167
+ }
168
+ function resolveLocalSkillJsonPath(runtime) {
169
+ if (runtime.localSkillJsonPath) {
170
+ return runtime.localSkillJsonPath;
171
+ }
172
+ const codexHome = runtime.codexHome ?? runtime.env?.CODEX_HOME ?? process.env.CODEX_HOME ?? path.join(os.homedir(), '.codex');
173
+ return path.join(codexHome, 'skills', index.HB_SDK_SKILL_NAME, 'skill.json');
174
+ }
175
+ async function pathExists(filePath) {
176
+ try {
177
+ await fs.access(filePath, fs$1.constants.F_OK);
178
+ return true;
179
+ }
180
+ catch {
181
+ return false;
182
+ }
183
+ }
184
+
185
+ exports.getDoctorResult = getDoctorResult;
186
+ exports.runDoctorCommand = runDoctorCommand;