@open-dy/interest-card-cli 0.1.0-beta.29 → 0.1.0-beta.31
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/browser-runtime/scripts/cli.mjs +10 -3
- package/browser-runtime/scripts/inspect-preview-state.mjs +6 -4
- package/card-skills/douyin-interest-card-browser/references/commands.md +1 -1
- package/card-skills/douyin-interest-card-capability/SKILL.md +12 -4
- package/card-skills/douyin-interest-card-capability/references/common/openapi/external/guide.md +5 -5
- package/card-skills/douyin-interest-card-capability/references/microapp/api/capability-index.json +27 -27
- package/card-skills/douyin-interest-card-capability/references/microapp/api/connect-socket.md +24 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/api/create-bytenn-engine-context.md +11 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/api/create-camera-context.md +12 -0
- package/card-skills/douyin-interest-card-capability/references/microapp/api/create-canvas-context.md +45 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/api/create-effect-camera-stream.md +21 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/api/create-inner-audio-context.md +80 -3
- package/card-skills/douyin-interest-card-capability/references/microapp/api/create-intersection-observer.md +12 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/api/create-interstitial-ad.md +12 -0
- package/card-skills/douyin-interest-card-capability/references/microapp/api/create-live-player-context.md +16 -0
- package/card-skills/douyin-interest-card-capability/references/microapp/api/create-map-context.md +24 -0
- package/card-skills/douyin-interest-card-capability/references/microapp/api/create-media-recorder.md +17 -0
- package/card-skills/douyin-interest-card-capability/references/microapp/api/create-offscreen-canvas.md +9 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/api/create-rewarded-video-ad.md +16 -0
- package/card-skills/douyin-interest-card-capability/references/microapp/api/create-rtc-room-context.md +33 -0
- package/card-skills/douyin-interest-card-capability/references/microapp/api/create-scene-activity-context.md +13 -0
- package/card-skills/douyin-interest-card-capability/references/microapp/api/create-selector-query.md +13 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/api/create-sticker-manager.md +11 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/api/create-video-context.md +17 -0
- package/card-skills/douyin-interest-card-capability/references/microapp/api/download-file.md +10 -0
- package/card-skills/douyin-interest-card-capability/references/microapp/api/get-algorithm-manager.md +9 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/api/get-background-audio-manager.md +60 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/api/get-file-system-manager.md +37 -0
- package/card-skills/douyin-interest-card-capability/references/microapp/api/get-recorder-manager.md +23 -0
- package/card-skills/douyin-interest-card-capability/references/microapp/api/get-update-manager.md +11 -0
- package/card-skills/douyin-interest-card-capability/references/microapp/api/preload-video.md +8 -0
- package/card-skills/douyin-interest-card-capability/references/microapp/api/request.md +8 -0
- package/card-skills/douyin-interest-card-capability/references/microapp/api/upload-file.md +10 -0
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/capability-index.json +9 -4
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/censor-image.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/censor-text.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/check-fans.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/create-activity.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-affiliate-id.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-aiuser-data-info.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-aiuser-item-list.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-aiuser-profile.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-fans-favourite.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-fans-profile.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-fans-source.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-feed.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-follow-feed.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-follow-hot-word.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-friend-list.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-hot-list.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-music-collection-list.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-recommend.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-related-id.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-room-real-time-data.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-basic-data.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-cert-labels-info.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-comment-data.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-constellation.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-fans-data.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-fans-profile.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-following.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-hash-mobile.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-interest.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-item-data.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-like-data.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-profile-data.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-share-data.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-video-pack.md +48 -3
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/modify-activity.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/query-activity-info.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/query-activity-user-completion-status.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/query-room-data.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/search-experience.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/search-general.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/search-live.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/search-music.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/search-user.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/search-video.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/search-vision.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/api/call-container.md +1 -0
- package/card-skills/douyin-interest-card-capability/references/opencard/api/capability-index.json +6 -6
- package/card-skills/douyin-interest-card-capability/references/opencard/api/create-inner-audio-context.md +60 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/api/create-map-context.md +24 -0
- package/card-skills/douyin-interest-card-capability/references/opencard/api/create-selector-query.md +13 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/api/create-video-context.md +17 -0
- package/card-skills/douyin-interest-card-capability/references/opencard/api/download-file.md +1 -3
- package/card-skills/douyin-interest-card-capability/references/opencard/api/get-background-audio-manager.md +60 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/api/request.md +1 -3
- package/card-skills/douyin-interest-card-capability/references/opencard/api/upload-file.md +1 -3
- package/card-skills/douyin-interest-card-capability/references/opencard/closed-domain-openapi.md +2 -2
- package/card-skills/douyin-interest-card-capability/references/opencard/component/button.md +4 -2
- package/card-skills/douyin-interest-card-capability/references/opencard/component/canvas.md +4 -3
- package/card-skills/douyin-interest-card-capability/references/opencard/component/capability-index.json +8 -9
- package/card-skills/douyin-interest-card-capability/references/opencard/component/checkbox-group.md +2 -0
- package/card-skills/douyin-interest-card-capability/references/opencard/component/image.md +3 -2
- package/card-skills/douyin-interest-card-capability/references/opencard/component/input.md +3 -2
- package/card-skills/douyin-interest-card-capability/references/opencard/component/text.md +3 -3
- package/card-skills/douyin-interest-card-capability/references/opencard/component/textarea.md +5 -5
- package/card-skills/douyin-interest-card-capability/references/opencard/component/video.md +10 -2
- package/card-skills/douyin-interest-card-capability/references/opencard/component-guide.md +5 -3
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/capability-index.json +16 -11
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/censor-image.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/censor-text.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/check-fans.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/create-activity.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-affiliate-id.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-aiuser-data-info.md +10 -9
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-aiuser-item-list.md +10 -9
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-aiuser-profile.md +10 -9
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-fans-favourite.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-fans-profile.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-fans-source.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-feed.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-follow-feed.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-follow-hot-word.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-friend-list.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-hot-list.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-music-collection-list.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-recommend.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-related-id.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-room-real-time-data.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-basic-data.md +10 -9
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-cert-labels-info.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-comment-data.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-constellation.md +10 -9
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-fans-data.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-fans-profile.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-following.md +10 -9
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-hash-mobile.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-interest.md +10 -9
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-item-data.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-like-data.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-profile-data.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-share-data.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-video-pack.md +48 -3
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/modify-activity.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/query-activity-info.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/query-activity-user-completion-status.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/query-room-data.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/search-experience.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/search-general.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/search-live.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/search-music.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/search-user.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/search-video.md +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/search-vision.md +1 -1
- package/card-skills/douyin-interest-card-cli/SKILL.md +1 -1
- package/card-skills/douyin-interest-card-generate/SKILL.md +5 -3
- package/card-skills/douyin-interest-card-generate/init.sh +13 -23
- package/card-skills/douyin-interest-card-generate/references/common/fullstack.md +6 -10
- package/card-skills/douyin-interest-card-generate/references/common/private-data-intent-routing.md +1 -1
- package/card-skills/douyin-interest-card-generate/references/common/upgrade-to-post.md +1 -1
- package/card-skills/douyin-interest-card-generate/references/microapp/microapp.md +1 -1
- package/card-skills/douyin-interest-card-generate/references/opencard/api.md +8 -0
- package/card-skills/douyin-interest-card-generate/references/opencard/closed-domain-card.md +1 -1
- package/card-skills/douyin-interest-card-generate/references/opencard/components.md +11 -28
- package/card-skills/douyin-interest-card-generate/references/opencard/opencard.md +9 -7
- package/card-skills/douyin-interest-card-generate/references/opencard/rendering.md +5 -5
- package/card-skills/douyin-interest-card-generate/references/opencard/taro-dsl.md +6 -6
- package/card-skills/douyin-interest-card-generate/templates/fragments/opencard/package.json +2 -2
- package/card-skills/douyin-interest-card-generate/templates/fragments/opencard/pnpm-lock.yaml +17 -17
- package/card-skills/douyin-interest-card-generate/templates/taro/closed-domain-server/package.json +1 -1
- package/card-skills/douyin-interest-card-generate/templates/taro/package.json +5 -4
- package/card-skills/douyin-interest-card-generate/templates/taro/pnpm-lock.yaml +27 -26
- package/card-skills/douyin-interest-card-generate/templates/taro/server/package.json +1 -1
- package/dist/src/args.js +23 -8
- package/dist/src/browser.js +3 -1
- package/dist/src/card/agent-chat.js +4 -0
- package/dist/src/card/binding.js +2 -1
- package/dist/src/card/candidate.js +90 -0
- package/dist/src/card/card-api.js +2 -2
- package/dist/src/card/card-token.js +25 -2
- package/dist/src/card/chat-commands.js +26 -11
- package/dist/src/card/constants.js +5 -0
- package/dist/src/card/create-project-client.js +2 -2
- package/dist/src/card/create.js +29 -3
- package/dist/src/card/editor-client.js +41 -6
- package/dist/src/card/editor-fs.js +4 -4
- package/dist/src/card/global-skills.js +6 -1
- package/dist/src/card/handlers-misc.js +3 -6
- package/dist/src/card/handlers.js +32 -24
- package/dist/src/card/help.js +6 -4
- package/dist/src/card/ignore.js +22 -0
- package/dist/src/card/project.js +13 -4
- package/dist/src/card-install.js +8 -9
- package/dist/src/cli.js +5 -2
- package/dist/src/config.js +26 -3
- package/dist/src/creator-device-login.js +2 -1
- package/dist/src/creator-login-session.js +6 -6
- package/dist/src/creator-passport-login.js +8 -2
- package/dist/src/creator-session.js +30 -7
- package/dist/src/current-user.js +29 -0
- package/dist/src/help-access.js +22 -0
- package/dist/src/help.js +6 -2
- package/dist/src/http.js +4 -4
- package/dist/src/login-handlers.js +2 -1
- package/dist/src/platform-process.js +98 -0
- package/dist/src/platform.js +1 -1
- package/dist/src/request-source.js +4 -0
- package/dist/src/telemetry-session.js +17 -0
- package/dist/src/telemetry.js +166 -3
- package/dist/src/update-check.js +5 -3
- package/dist/src/upgrade.js +20 -8
- package/package.json +1 -1
- package/card-skills/douyin-interest-card-capability/references/opencard/component/svg.md +0 -58
package/dist/src/args.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
const globalLeadingOptions = new Set(['config', 'base-url', 'auth-base-url', 'platform']);
|
|
1
|
+
const globalLeadingOptions = new Set(['config', 'base-url', 'auth-base-url', 'platform', 'ppe']);
|
|
2
2
|
const valueOptions = new Set([
|
|
3
|
+
'ppe',
|
|
4
|
+
'prompt-file',
|
|
5
|
+
'skill',
|
|
3
6
|
'agent',
|
|
4
7
|
'answers',
|
|
5
8
|
'auth-base-url',
|
|
@@ -98,12 +101,24 @@ export function parseCliArgs(argv) {
|
|
|
98
101
|
const args = [...globalArgv, ...normalized.slice(1)];
|
|
99
102
|
const options = {};
|
|
100
103
|
const positionals = [];
|
|
101
|
-
if (wantsHelp) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
104
|
+
if (wantsHelp || normalized.length === 0) {
|
|
105
|
+
const positionals = [];
|
|
106
|
+
const options = { help: true };
|
|
107
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
108
|
+
const arg = args[index];
|
|
109
|
+
const [key, inline] = arg.startsWith('--') ? arg.slice(2).split(/=(.*)/s, 2) : [];
|
|
110
|
+
if (key && globalLeadingOptions.has(key)) {
|
|
111
|
+
const value = inline ?? args[index + 1];
|
|
112
|
+
if (value && !value.startsWith('-')) {
|
|
113
|
+
options[key] = value;
|
|
114
|
+
if (inline === undefined)
|
|
115
|
+
index += 1;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else if (!arg.startsWith('-'))
|
|
119
|
+
positionals.push(arg);
|
|
120
|
+
}
|
|
121
|
+
return { command, options, positionals };
|
|
107
122
|
}
|
|
108
123
|
for (let index = 0; index < args.length; index += 1) {
|
|
109
124
|
const arg = args[index];
|
|
@@ -146,7 +161,7 @@ function normalizeCommand(argv) {
|
|
|
146
161
|
return argv;
|
|
147
162
|
}
|
|
148
163
|
function appendOption(options, key, value) {
|
|
149
|
-
if (key !== 'agent') {
|
|
164
|
+
if (key !== 'agent' && key !== 'skill') {
|
|
150
165
|
options[key] = value;
|
|
151
166
|
return;
|
|
152
167
|
}
|
package/dist/src/browser.js
CHANGED
|
@@ -24,6 +24,8 @@ export async function launchLoginPersistentContext(userDataDir, options, chromiu
|
|
|
24
24
|
const type = chromium ?? (await loadChromium());
|
|
25
25
|
return tryChannels(channel => type.launchPersistentContext(userDataDir, { ...options, channel }));
|
|
26
26
|
}
|
|
27
|
+
/** Link authorization needs no browser on this machine, so it is the way out when one will not start. */
|
|
28
|
+
export const LINK_LOGIN_FALLBACK = 'Log in by link instead, without `--qr`: `interest-card-cli login --platform creator --json`.';
|
|
27
29
|
async function tryChannels(launch) {
|
|
28
30
|
const failures = [];
|
|
29
31
|
for (const channel of LOGIN_BROWSER_CHANNELS) {
|
|
@@ -36,7 +38,7 @@ async function tryChannels(launch) {
|
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
40
|
throw new CliError('No browser available for login.', 'BROWSER_LAUNCH_FAILED', {
|
|
39
|
-
hint:
|
|
41
|
+
hint: `${LINK_LOGIN_FALLBACK} To log in with a browser instead, install Google Chrome or Microsoft Edge, or run \`${chromiumInstallCommand()}\`.`,
|
|
40
42
|
attempts: failures,
|
|
41
43
|
});
|
|
42
44
|
}
|
|
@@ -20,6 +20,7 @@ export async function sendCardMessage(target, input) {
|
|
|
20
20
|
conversationId: target.conversationId,
|
|
21
21
|
...(container ? { containerConversationId: container } : {}),
|
|
22
22
|
text: input.text || '',
|
|
23
|
+
...(target.candidate ? { candidate: target.candidate } : {}),
|
|
23
24
|
...(input.systemReminder ? { systemReminder: input.systemReminder } : {}),
|
|
24
25
|
...(input.solutionIds?.length ? { solutionIds: input.solutionIds } : {}),
|
|
25
26
|
...(input.multiModal === false ? { multiModal: false } : {}),
|
|
@@ -39,6 +40,9 @@ export async function sendCardMessage(target, input) {
|
|
|
39
40
|
error: response.error,
|
|
40
41
|
});
|
|
41
42
|
}
|
|
43
|
+
if (target.candidate && response.error) {
|
|
44
|
+
throw new CliError('Candidate execution was not acknowledged. Check the run before retrying.', 'CARD_CANDIDATE_NOT_ACKNOWLEDGED', { messageId });
|
|
45
|
+
}
|
|
42
46
|
if (answer) {
|
|
43
47
|
await rememberAnsweredQuestion(target.conversationId, answer.toolCallId);
|
|
44
48
|
}
|
package/dist/src/card/binding.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import { renameReplacing } from '../platform-process.js';
|
|
3
4
|
import { CliError } from '../types.js';
|
|
4
5
|
import { CARD_STATE_DIR } from './constants.js';
|
|
5
6
|
import { isNotFound } from './snapshot.js';
|
|
@@ -115,5 +116,5 @@ async function writeJsonAtomic(filePath, value) {
|
|
|
115
116
|
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
116
117
|
const tmpPath = `${filePath}.${process.pid}.tmp`;
|
|
117
118
|
await fs.writeFile(tmpPath, `${JSON.stringify(value, null, 2)}\n`);
|
|
118
|
-
await
|
|
119
|
+
await renameReplacing(tmpPath, filePath);
|
|
119
120
|
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { constants } from 'node:fs';
|
|
2
|
+
import { open } from 'node:fs/promises';
|
|
3
|
+
import { getString } from '../cli-helpers.js';
|
|
4
|
+
import { CliError } from '../types.js';
|
|
5
|
+
const OUTER_TOS_HOST = 'lf-aihub.douyinvod.com';
|
|
6
|
+
const LEGACY_SIGNED_HOST = 'lf1-developer-sign.bytemastatic.com';
|
|
7
|
+
const LEGACY_PUBLIC_HOST = 'lf3-static.bytednsdoc.com';
|
|
8
|
+
export function hasCandidateOptions(parsed) {
|
|
9
|
+
return ['skill', 'skill-dir', 'prompt-file', 'skill-archive', 'skill-cdn-url'].some(key => key in parsed.options);
|
|
10
|
+
}
|
|
11
|
+
async function readRegularFile(file, maxBytes) {
|
|
12
|
+
const handle = await open(file, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
13
|
+
try {
|
|
14
|
+
const stat = await handle.stat();
|
|
15
|
+
if (!stat.isFile())
|
|
16
|
+
throw invalidCandidate('--prompt-file must point to a regular file.');
|
|
17
|
+
if (stat.size > maxBytes)
|
|
18
|
+
throw invalidCandidate('--prompt-file exceeds 2 MiB.');
|
|
19
|
+
const bytes = Buffer.alloc(stat.size + 1);
|
|
20
|
+
let offset = 0;
|
|
21
|
+
while (offset < bytes.length) {
|
|
22
|
+
const { bytesRead } = await handle.read(bytes, offset, bytes.length - offset, offset);
|
|
23
|
+
if (!bytesRead)
|
|
24
|
+
break;
|
|
25
|
+
offset += bytesRead;
|
|
26
|
+
}
|
|
27
|
+
if (offset !== stat.size)
|
|
28
|
+
throw invalidCandidate('--prompt-file changed while reading.');
|
|
29
|
+
return bytes.subarray(0, offset);
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
await handle.close();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const invalidCandidate = (message) => new CliError(message, 'CARD_CANDIDATE_INVALID');
|
|
36
|
+
export async function readCardCandidate(parsed) {
|
|
37
|
+
if (!hasCandidateOptions(parsed))
|
|
38
|
+
return;
|
|
39
|
+
const promptPath = getString(parsed, 'prompt-file');
|
|
40
|
+
const values = parsed.options.skill;
|
|
41
|
+
const refs = Array.isArray(values) ? values : typeof values === 'string' ? [values] : [];
|
|
42
|
+
if ((!promptPath && refs.length === 0) || ('prompt-file' in parsed.options && !promptPath) || refs.length > 16 ||
|
|
43
|
+
['skill-dir', 'skill-archive', 'skill-cdn-url'].some(key => key in parsed.options)) {
|
|
44
|
+
throw new CliError('Supply --prompt-file, --skill <name>=<CDN URL> (up to 16), or both.', 'CARD_CANDIDATE_INVALID');
|
|
45
|
+
}
|
|
46
|
+
let prompt;
|
|
47
|
+
if (promptPath) {
|
|
48
|
+
const bytes = await readRegularFile(promptPath, 2 << 20).catch((error) => {
|
|
49
|
+
if (error instanceof CliError)
|
|
50
|
+
throw error;
|
|
51
|
+
throw invalidCandidate('Could not read --prompt-file. Check the path and file permissions.');
|
|
52
|
+
});
|
|
53
|
+
try {
|
|
54
|
+
prompt = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
throw invalidCandidate('--prompt-file must contain valid UTF-8.');
|
|
58
|
+
}
|
|
59
|
+
if (!prompt.trim())
|
|
60
|
+
throw invalidCandidate('--prompt-file must contain a nonempty prompt.');
|
|
61
|
+
}
|
|
62
|
+
const names = new Set();
|
|
63
|
+
const skills = refs.map(ref => {
|
|
64
|
+
const separator = ref.indexOf('=');
|
|
65
|
+
const name = ref.slice(0, separator);
|
|
66
|
+
if (separator < 1 || !/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/.test(name)) {
|
|
67
|
+
throw invalidCandidate('Use --skill <name>=<CDN URL> with a valid Skill name.');
|
|
68
|
+
}
|
|
69
|
+
if (names.has(name))
|
|
70
|
+
throw invalidCandidate(`Duplicate Skill name: ${name}.`);
|
|
71
|
+
names.add(name);
|
|
72
|
+
const cdnUrl = ref.slice(separator + 1);
|
|
73
|
+
let url;
|
|
74
|
+
try {
|
|
75
|
+
url = new URL(cdnUrl);
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
throw invalidCandidate(`Invalid CDN URL for Skill ${name}.`);
|
|
79
|
+
}
|
|
80
|
+
const exactOrigin = cdnUrl.startsWith(`https://${url.hostname}/`);
|
|
81
|
+
const allowed = (url.hostname === OUTER_TOS_HOST && url.pathname.startsWith('/obj/developer/') && !url.search) ||
|
|
82
|
+
url.hostname === LEGACY_SIGNED_HOST || (url.hostname === LEGACY_PUBLIC_HOST && !url.search);
|
|
83
|
+
if (!exactOrigin || !allowed || cdnUrl.length > 2048 || url.pathname === '/' || /[#\\]/.test(cdnUrl) ||
|
|
84
|
+
(url.hostname !== LEGACY_SIGNED_HOST && cdnUrl.includes('?'))) {
|
|
85
|
+
throw invalidCandidate(`Unsupported CDN URL for Skill ${name}.`);
|
|
86
|
+
}
|
|
87
|
+
return { name, url: cdnUrl };
|
|
88
|
+
});
|
|
89
|
+
return { ...(prompt && { prompt }), ...(skills.length && { skills }) };
|
|
90
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { cardAuthFor, fetchWithCredential, isCardGateError } from './card-token.js';
|
|
2
|
-
import {
|
|
2
|
+
import { cliSourceHeaders } from '../request-source.js';
|
|
3
3
|
import { CliError } from '../types.js';
|
|
4
4
|
import { CARD_API_ROUTES, CARD_LOGIN_HINT, getCardApiBaseUrl } from './constants.js';
|
|
5
5
|
import { NETWORK_RETRY_DELAY_MS, isNetworkError, networkErrorCode, neverConnected } from './aio-client.js';
|
|
@@ -34,7 +34,7 @@ export async function cardApi(config, route, body, options = {}) {
|
|
|
34
34
|
referer: `${CARD_WEB_ORIGIN}/`,
|
|
35
35
|
'content-type': 'application/json',
|
|
36
36
|
...(tenant ? { 'x-aicore-tenant': tenant } : {}),
|
|
37
|
-
...
|
|
37
|
+
...cliSourceHeaders(options.headers?.['x-tt-env']),
|
|
38
38
|
},
|
|
39
39
|
body: JSON.stringify(tenant && body.tenant === undefined ? { ...body, tenant } : body),
|
|
40
40
|
});
|
|
@@ -96,6 +96,18 @@ export function notAllowedError(xTtLogid) {
|
|
|
96
96
|
hint: '请联系抖音兴趣卡技术支持团队为该账号开通 CLI 权限。重新登录无法解决,开通前可继续使用网页端编辑。',
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
|
+
function testingAccessError(code, xTtLogid) {
|
|
100
|
+
if (code === 'CLI_TESTING_NOT_ALLOWED') {
|
|
101
|
+
return new CliError('当前账号未开通 CLI 测试权限。', code, {
|
|
102
|
+
hint: '请联系兴趣卡技术支持开通测试权限。重新登录无法解决。', xTtLogid,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
if (code === 'CLI_TESTING_UNAVAILABLE') {
|
|
106
|
+
return new CliError('CLI 测试权限服务暂不可用。', code, {
|
|
107
|
+
hint: '请稍后重试;无需重新登录或重复申请白名单。', xTtLogid,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
99
111
|
async function isNotAllowedResponse(response) {
|
|
100
112
|
if (response.status !== 403) {
|
|
101
113
|
return false;
|
|
@@ -128,6 +140,11 @@ export async function exchangeCookieForToken(config) {
|
|
|
128
140
|
});
|
|
129
141
|
}
|
|
130
142
|
const { response, envelope, xTtLogid } = outcome;
|
|
143
|
+
if (response.status === 403 || response.status === 503) {
|
|
144
|
+
const accessError = testingAccessError(envelope?.error_code, xTtLogid);
|
|
145
|
+
if (accessError)
|
|
146
|
+
throw accessError;
|
|
147
|
+
}
|
|
131
148
|
if (response.status === 403 && envelope?.error_code === NOT_ALLOWED_CODE) {
|
|
132
149
|
throw notAllowedError(xTtLogid);
|
|
133
150
|
}
|
|
@@ -321,7 +338,7 @@ async function rateLimitedError(response, url) {
|
|
|
321
338
|
* or not on the CLI allowlist. Callers pass them through instead of reporting a network failure.
|
|
322
339
|
*/
|
|
323
340
|
export function isCardGateError(error) {
|
|
324
|
-
return error instanceof CliError && (error.code === 'CARD_RATE_LIMITED' || error.code === NOT_ALLOWED_CODE);
|
|
341
|
+
return error instanceof CliError && (error.code === 'CARD_RATE_LIMITED' || error.code === NOT_ALLOWED_CODE || ['CLI_TESTING_NOT_ALLOWED', 'CLI_TESTING_UNAVAILABLE'].includes(error.code));
|
|
325
342
|
}
|
|
326
343
|
/**
|
|
327
344
|
* fetch with card credentials. A 401 is returned as is: the token cannot be renewed, so callers
|
|
@@ -335,6 +352,12 @@ export async function fetchWithCredential(credential, url, init) {
|
|
|
335
352
|
if (response.status === 429) {
|
|
336
353
|
throw await rateLimitedError(response, url);
|
|
337
354
|
}
|
|
355
|
+
if (response.status === 403 || response.status === 503) {
|
|
356
|
+
const body = await response.clone().json().catch(() => undefined);
|
|
357
|
+
const accessError = testingAccessError(body?.error_code, response.headers.get('x-tt-logid') || undefined);
|
|
358
|
+
if (accessError)
|
|
359
|
+
throw accessError;
|
|
360
|
+
}
|
|
338
361
|
if (await isNotAllowedResponse(response)) {
|
|
339
362
|
await response.body?.cancel().catch(() => undefined);
|
|
340
363
|
throw notAllowedError(response.headers.get('x-tt-logid') || undefined);
|
|
@@ -360,7 +383,7 @@ export async function replaceStoredCookieLogin(config) {
|
|
|
360
383
|
}
|
|
361
384
|
catch (error) {
|
|
362
385
|
await removeConfig(configPath).catch(() => false);
|
|
363
|
-
if (error instanceof CliError && error.code === NOT_ALLOWED_CODE) {
|
|
386
|
+
if (error instanceof CliError && (error.code === NOT_ALLOWED_CODE || ['CLI_TESTING_NOT_ALLOWED', 'CLI_TESTING_UNAVAILABLE'].includes(error.code))) {
|
|
364
387
|
throw error;
|
|
365
388
|
}
|
|
366
389
|
throw new CliError('The saved login was a browser Cookie, which is no longer kept on disk. It has been removed.', 'AUTH_REQUIRED', {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getString } from '../cli-helpers.js';
|
|
2
|
+
import { readCardCandidate } from './candidate.js';
|
|
2
3
|
import { printText } from '../output.js';
|
|
3
4
|
import { buildWorkspaceHeaders } from '../platform.js';
|
|
4
5
|
import { CliError } from '../types.js';
|
|
@@ -6,7 +7,7 @@ import { createChildConversation, followRun, formatQuestion, runConversation, se
|
|
|
6
7
|
import { parseAnswersJson } from './agent-questions.js';
|
|
7
8
|
import { findAnsweredQuestion } from './answered-questions.js';
|
|
8
9
|
import { findProjectRoot, readBinding, writeBinding } from './binding.js';
|
|
9
|
-
import { buildProjectPageUrl, getContainerConversationId, getTenantOption, loadCardConfig, parseProjectRef, resolveCardProject, } from './project.js';
|
|
10
|
+
import { buildProjectPageUrl, getContainerConversationId, getCardPpeHeaders, getTenantOption, loadCardConfig, parseProjectRef, resolveCardProject, } from './project.js';
|
|
10
11
|
const MAX_REPLY_CHARS = 4000;
|
|
11
12
|
/**
|
|
12
13
|
* The platform installs the latest project skills into the sandbox when its Agent starts a turn.
|
|
@@ -105,7 +106,7 @@ export async function followAndReport(parsed, target, messageId, command, extraD
|
|
|
105
106
|
...pendingData(outcome.action),
|
|
106
107
|
};
|
|
107
108
|
if (!json && !options.suppressText) {
|
|
108
|
-
printText(`\n\n${describeOutcome(data, target, options.followFlags)}`);
|
|
109
|
+
printText(`\n\n${describeOutcome(data, target, parsed, options.followFlags)}`);
|
|
109
110
|
}
|
|
110
111
|
return { ok: true, command, data };
|
|
111
112
|
}
|
|
@@ -117,16 +118,25 @@ function pendingData(action) {
|
|
|
117
118
|
? { toolCallId: action.toolCallId, questions: action.questions }
|
|
118
119
|
: { toolCallId: action.toolCallId, toolCallName: action.toolCallName, reason: action.reason };
|
|
119
120
|
}
|
|
120
|
-
function describeOutcome(data, target, flags) {
|
|
121
|
+
function describeOutcome(data, target, parsed, flags) {
|
|
121
122
|
const projectFlag = flags ?? (target.projectId ? ` --project ${target.projectId}` : '');
|
|
123
|
+
const lane = target.headers?.['x-tt-env'];
|
|
124
|
+
const followUpFlags = lane ? `${projectFlag} --ppe ${lane}` : projectFlag;
|
|
122
125
|
switch (data.status) {
|
|
123
|
-
case 'needs_input':
|
|
126
|
+
case 'needs_input': {
|
|
127
|
+
const quoteArg = (value) => "'" + value.replaceAll("'", "'\\''") + "'";
|
|
128
|
+
const promptPath = getString(parsed, 'prompt-file');
|
|
129
|
+
const candidateFlags = [
|
|
130
|
+
...(promptPath ? [' --prompt-file ' + quoteArg(promptPath)] : []),
|
|
131
|
+
...(target.candidate?.skills ?? []).map(skill => ' --skill ' + quoteArg(skill.name + '=' + skill.url)),
|
|
132
|
+
].join('');
|
|
124
133
|
return [
|
|
125
134
|
'The platform agent is waiting for your answer:',
|
|
126
135
|
...(data.questions || []).map(formatQuestion),
|
|
127
|
-
`Answer with: interest-card-cli answer${
|
|
136
|
+
`Answer with: interest-card-cli answer${followUpFlags}${candidateFlags} --tool-call-id ${data.toolCallId} ` +
|
|
128
137
|
`--answers '{"<question>":"<option value>"}'`,
|
|
129
138
|
].join('\n');
|
|
139
|
+
}
|
|
130
140
|
case 'needs_web':
|
|
131
141
|
return `${data.reason}. Continue on the web page: ${data.projectUrl || target.conversationId}`;
|
|
132
142
|
case 'stopped':
|
|
@@ -134,8 +144,8 @@ function describeOutcome(data, target, flags) {
|
|
|
134
144
|
default:
|
|
135
145
|
return [
|
|
136
146
|
'The platform agent finished this round.',
|
|
137
|
-
target.projectId ? `Pull the code: interest-card-cli pull ${target.projectId}` : '',
|
|
138
|
-
`Follow up: interest-card-cli reply "<message>"${
|
|
147
|
+
target.projectId && !lane ? `Pull the code: interest-card-cli pull ${target.projectId}` : '',
|
|
148
|
+
`Follow up: interest-card-cli reply "<message>"${followUpFlags}`,
|
|
139
149
|
]
|
|
140
150
|
.filter(Boolean)
|
|
141
151
|
.join('\n');
|
|
@@ -156,7 +166,12 @@ const CONVERSATION_ID_PATTERN = /^conv_[\w-]+$/;
|
|
|
156
166
|
async function resolveChatTarget(parsed) {
|
|
157
167
|
const { config } = await loadCardConfig(parsed);
|
|
158
168
|
const tenant = getTenantOption(parsed);
|
|
159
|
-
const
|
|
169
|
+
const routingHeaders = getCardPpeHeaders(parsed);
|
|
170
|
+
const headers = { ...(tenant ? buildWorkspaceHeaders(config.base_url, tenant) : {}), ...routingHeaders };
|
|
171
|
+
const candidate = await readCardCandidate(parsed);
|
|
172
|
+
if (parsed.options.ppe && parsed.options['new-conversation']) {
|
|
173
|
+
throw new CliError('PPE validation requires an existing owner conversation.', 'CARD_INVALID_ARGS');
|
|
174
|
+
}
|
|
160
175
|
const ref = getString(parsed, 'project');
|
|
161
176
|
const requested = getString(parsed, 'conversation-id');
|
|
162
177
|
if (requested && parsed.options['new-conversation']) {
|
|
@@ -171,7 +186,7 @@ async function resolveChatTarget(parsed) {
|
|
|
171
186
|
let chat;
|
|
172
187
|
let conversations;
|
|
173
188
|
if (ref) {
|
|
174
|
-
const project = await resolveCardProject(config, parseProjectRef(ref), tenant);
|
|
189
|
+
const project = await resolveCardProject(config, parseProjectRef(ref), tenant, routingHeaders);
|
|
175
190
|
projectId = project.projectId;
|
|
176
191
|
container = project.conversationId;
|
|
177
192
|
chat = container;
|
|
@@ -188,7 +203,7 @@ async function resolveChatTarget(parsed) {
|
|
|
188
203
|
}
|
|
189
204
|
if (requested) {
|
|
190
205
|
if (!conversations && projectId) {
|
|
191
|
-
conversations = (await resolveCardProject(config, projectId, tenant)).conversations;
|
|
206
|
+
conversations = (await resolveCardProject(config, projectId, tenant, routingHeaders)).conversations;
|
|
192
207
|
}
|
|
193
208
|
if (conversations) {
|
|
194
209
|
const item = conversations.find(entry => entry.conversationId === requested);
|
|
@@ -201,7 +216,7 @@ async function resolveChatTarget(parsed) {
|
|
|
201
216
|
}
|
|
202
217
|
return {
|
|
203
218
|
root,
|
|
204
|
-
target: { config, headers, conversationId: chat, projectId, containerConversationId: container },
|
|
219
|
+
target: { config, headers, conversationId: chat, projectId, containerConversationId: container, candidate },
|
|
205
220
|
};
|
|
206
221
|
}
|
|
207
222
|
/** Opens a "新建对话" child on the sandbox owner and makes it the directory's chat conversation. */
|
|
@@ -62,6 +62,7 @@ export const CARD_API_ROUTES = {
|
|
|
62
62
|
tenantList: 'tenant/list',
|
|
63
63
|
conversationCreate: 'conversation/create',
|
|
64
64
|
msgSend: 'msg/send',
|
|
65
|
+
authMe: 'auth/me',
|
|
65
66
|
msgPoll: 'msg/poll',
|
|
66
67
|
};
|
|
67
68
|
/**
|
|
@@ -96,6 +97,10 @@ export const LOCAL_DEBOUNCE_MS = 300;
|
|
|
96
97
|
export const ECHO_WINDOW_MS = 10_000;
|
|
97
98
|
export const PING_INTERVAL_MS = 30_000;
|
|
98
99
|
export const REQUEST_TIMEOUT_MS = 60_000;
|
|
100
|
+
/** A batch of up to 50 files / 4 MB regularly takes the sandbox longer than a minute to write. */
|
|
101
|
+
export const WRITE_TIMEOUT_MS = 180_000;
|
|
102
|
+
/** Connection attempts before giving up; a sleeping sandbox often refuses the first one. */
|
|
103
|
+
export const CONNECT_RETRY_DELAYS_MS = [1_000, 3_000];
|
|
99
104
|
export const CONNECT_TIMEOUT_MS = 15_000;
|
|
100
105
|
export const MAX_RECONNECT_DELAY_MS = 30_000;
|
|
101
106
|
export const MAX_PUSH_RETRIES = 3;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { cliSourceHeaders } from '../request-source.js';
|
|
2
2
|
import { fetchWithCredential, isCardGateError } from './card-token.js';
|
|
3
3
|
import { CliError } from '../types.js';
|
|
4
4
|
import { CARD_LOGIN_HINT, getProjectCreateUrl } from './constants.js';
|
|
@@ -83,7 +83,7 @@ export async function createCardProject(options) {
|
|
|
83
83
|
referer: `${CARD_WEB_ORIGIN}/`,
|
|
84
84
|
'content-type': 'application/json',
|
|
85
85
|
'x-aicore-tenant': options.tenant,
|
|
86
|
-
...
|
|
86
|
+
...cliSourceHeaders(options.headers?.['x-tt-env']),
|
|
87
87
|
},
|
|
88
88
|
body: JSON.stringify({
|
|
89
89
|
tenant: options.tenant,
|
package/dist/src/card/create.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readCardCandidate } from './candidate.js';
|
|
1
2
|
import { noteTelemetryProject } from '../telemetry-project.js';
|
|
2
3
|
import { getString } from '../cli-helpers.js';
|
|
3
4
|
import { printText } from '../output.js';
|
|
@@ -9,7 +10,7 @@ import { followAndReport } from './chat-commands.js';
|
|
|
9
10
|
import { BLANK_COPY_SOLUTION_ID, BLANK_INSPIRATION_KEY } from './constants.js';
|
|
10
11
|
import { createCardProject } from './create-project-client.js';
|
|
11
12
|
import { restartDevServices } from './dev-commands.js';
|
|
12
|
-
import { buildProjectPageUrl, getTenantOption, loadCardConfig } from './project.js';
|
|
13
|
+
import { buildProjectPageUrl, getCardPpeHeaders, getTenantOption, loadCardConfig } from './project.js';
|
|
13
14
|
import { applyBlankProjectName, normalizeProjectName } from './rename.js';
|
|
14
15
|
const SEEDED_HINT = 'The sandbox has the blank interest-card template. Pull the project, then immediately set a name that matches the card with interest-card-cli rename --name "<name>" before writing any card code. Do not wait until the card is finished. Implement the card locally. Do not send the card description to the platform agent. data.projectName is only the placeholder list title.';
|
|
15
16
|
/** Visible user bubble for blank create; keeps the conversation panel from looking empty. */
|
|
@@ -28,6 +29,11 @@ export function buildBlankCopyReminder(conversationId) {
|
|
|
28
29
|
*/
|
|
29
30
|
export async function handleCardCreate(parsed) {
|
|
30
31
|
const blank = Boolean(parsed.options.blank);
|
|
32
|
+
const routingHeaders = getCardPpeHeaders(parsed);
|
|
33
|
+
const lane = routingHeaders['x-tt-env'];
|
|
34
|
+
if (blank && lane) {
|
|
35
|
+
throw new CliError('PPE create requires a project description. Omit --blank.', 'CARD_INVALID_ARGS');
|
|
36
|
+
}
|
|
31
37
|
const prompt = parsed.positionals.join(' ').trim();
|
|
32
38
|
if (blank && prompt) {
|
|
33
39
|
throw new CliError('create --blank does not take a card description. Implement the card locally after the command returns seeded.', 'CARD_INVALID_ARGS');
|
|
@@ -41,16 +47,20 @@ export async function handleCardCreate(parsed) {
|
|
|
41
47
|
}
|
|
42
48
|
const { config, auth } = await loadCardConfig(parsed);
|
|
43
49
|
const tenant = getTenantOption(parsed);
|
|
44
|
-
const headers = tenant ? buildWorkspaceHeaders(config.base_url, tenant) :
|
|
50
|
+
const headers = { ...(tenant ? buildWorkspaceHeaders(config.base_url, tenant) : {}), ...routingHeaders };
|
|
51
|
+
const candidate = await readCardCandidate(parsed);
|
|
52
|
+
if (candidate && blank)
|
|
53
|
+
throw new CliError('Candidate create requires a query; do not combine with --blank.', 'CARD_INVALID_ARGS');
|
|
45
54
|
const { projectId, conversationId } = await createCardProject({
|
|
46
55
|
cookie: auth,
|
|
56
|
+
headers: routingHeaders,
|
|
47
57
|
tenant,
|
|
48
58
|
name: requestedName,
|
|
49
59
|
});
|
|
50
60
|
// Noted at once: the project exists from here on, whatever happens to the first message.
|
|
51
61
|
noteTelemetryProject({ projectId, conversationId });
|
|
52
62
|
const projectUrl = buildProjectPageUrl(projectId);
|
|
53
|
-
const target = { config, headers, conversationId, projectId };
|
|
63
|
+
const target = { config, headers, conversationId, projectId, candidate };
|
|
54
64
|
const messageId = await sendCardMessage(target, blank
|
|
55
65
|
? {
|
|
56
66
|
text: BLANK_SEED_USER_TEXT,
|
|
@@ -59,6 +69,22 @@ export async function handleCardCreate(parsed) {
|
|
|
59
69
|
multiModal: false,
|
|
60
70
|
}
|
|
61
71
|
: { text: prompt }).catch((error) => {
|
|
72
|
+
if (lane || candidate) {
|
|
73
|
+
const cause = error instanceof CliError ? error : undefined;
|
|
74
|
+
const details = cause?.details;
|
|
75
|
+
const environment = lane ? `PPE lane ${lane}` : 'production';
|
|
76
|
+
const receipt = details?.messageId ? `message ${details.messageId}` : `project ${projectId}`;
|
|
77
|
+
const lookup = `Check ${receipt} in ${environment} before retrying.`;
|
|
78
|
+
const retry = 'If the message was not sent, use reply on the existing project with the same routing and candidate options.';
|
|
79
|
+
throw new CliError(`Project created, but sending the prompt failed: ${error instanceof Error ? error.message : String(error)}`, cause?.code ?? 'CARD_CREATE_PROMPT_FAILED', {
|
|
80
|
+
...details,
|
|
81
|
+
projectId,
|
|
82
|
+
conversationId,
|
|
83
|
+
projectUrl,
|
|
84
|
+
...(lane ? { ppeLane: lane } : {}),
|
|
85
|
+
hint: [details?.hint, lookup, retry].filter(Boolean).join(' '),
|
|
86
|
+
});
|
|
87
|
+
}
|
|
62
88
|
throw new CliError(`Project created, but sending the prompt failed: ${error instanceof Error ? error.message : String(error)}`, 'CARD_CREATE_PROMPT_FAILED', {
|
|
63
89
|
projectId,
|
|
64
90
|
conversationId,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CliError } from '../types.js';
|
|
2
2
|
import { CLI_SOURCE_HEADERS } from '../request-source.js';
|
|
3
3
|
import { credentialHeaders } from './card-token.js';
|
|
4
|
-
import { CONNECT_TIMEOUT_MS, PING_INTERVAL_MS, REQUEST_TIMEOUT_MS, getEditorWsUrl, } from './constants.js';
|
|
4
|
+
import { CONNECT_RETRY_DELAYS_MS, CONNECT_TIMEOUT_MS, PING_INTERVAL_MS, REQUEST_TIMEOUT_MS, getEditorWsUrl, } from './constants.js';
|
|
5
5
|
/** JSON-RPC client for the editor websocket that the web IDE also uses. */
|
|
6
6
|
export class EditorClient {
|
|
7
7
|
socket;
|
|
@@ -138,10 +138,45 @@ export class EditorClient {
|
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
141
|
+
/** Connects to the sandbox editor, trying again while the sandbox is still waking up. */
|
|
142
|
+
export async function connectEditor(conversationId, cookie, deps = {}) {
|
|
143
|
+
const create = deps.create ?? (() => new EditorClient({ url: getEditorWsUrl(), conversationId, cookie }));
|
|
144
|
+
const delays = deps.retryDelaysMs ?? CONNECT_RETRY_DELAYS_MS;
|
|
145
|
+
for (let attempt = 0;; attempt += 1) {
|
|
146
|
+
const client = create();
|
|
147
|
+
try {
|
|
148
|
+
await client.connect();
|
|
149
|
+
return client;
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
client.close();
|
|
153
|
+
const retryable = error instanceof CliError && error.code === 'CARD_SANDBOX_UNAVAILABLE';
|
|
154
|
+
if (!retryable || attempt >= delays.length) {
|
|
155
|
+
throw error;
|
|
156
|
+
}
|
|
157
|
+
await new Promise(resolve => setTimeout(resolve, delays[attempt]));
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Runs `work` on a sandbox connection and, when the connection drops midway (close code 1006),
|
|
163
|
+
* once more on a new one. Only for work that is safe to repeat from the start.
|
|
164
|
+
*/
|
|
165
|
+
export async function withEditor(connect, work) {
|
|
166
|
+
for (let attempt = 0;; attempt += 1) {
|
|
167
|
+
const client = await connect();
|
|
168
|
+
try {
|
|
169
|
+
return await work(client);
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
if (attempt > 0 || !(error instanceof CliError) || error.code !== 'CARD_WS_CLOSED') {
|
|
173
|
+
throw error;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
finally {
|
|
177
|
+
client.close();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
145
180
|
}
|
|
146
181
|
function parseMessage(data) {
|
|
147
182
|
try {
|
|
@@ -153,6 +188,6 @@ function parseMessage(data) {
|
|
|
153
188
|
}
|
|
154
189
|
function connectError(message) {
|
|
155
190
|
return new CliError(message, 'CARD_SANDBOX_UNAVAILABLE', {
|
|
156
|
-
hint: '
|
|
191
|
+
hint: 'Run the command again. If it keeps failing, open the project in the browser (`interest-card-cli open`) to wake the sandbox, and check login with `interest-card-cli status --json`.',
|
|
157
192
|
});
|
|
158
193
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CliError } from '../types.js';
|
|
2
2
|
import { CLI_SOURCE_HEADERS } from '../request-source.js';
|
|
3
|
-
import { CARD_REMOTE_ROOT, CARD_SANDBOX_PROJECT_DIR, isTrustedSessionUrl, MAX_BATCH_BYTES, MAX_BATCH_FILES, } from './constants.js';
|
|
3
|
+
import { CARD_REMOTE_ROOT, CARD_SANDBOX_PROJECT_DIR, isTrustedSessionUrl, MAX_BATCH_BYTES, MAX_BATCH_FILES, WRITE_TIMEOUT_MS, } from './constants.js';
|
|
4
4
|
import { REMOTE_ZIP_EXCLUDES } from './ignore.js';
|
|
5
5
|
import { assertSafeEntryPath, extractZipEntries } from './zip-extract.js';
|
|
6
6
|
import { fetchWithCredential } from './card-token.js';
|
|
@@ -82,7 +82,7 @@ export async function writeRemoteFiles(client, items) {
|
|
|
82
82
|
content: item.content.toString('base64'),
|
|
83
83
|
})),
|
|
84
84
|
};
|
|
85
|
-
results.push(...(await runBatch(client, 'fs.write', params, batch.map(item => item.path))));
|
|
85
|
+
results.push(...(await runBatch(client, 'fs.write', params, batch.map(item => item.path), WRITE_TIMEOUT_MS)));
|
|
86
86
|
}
|
|
87
87
|
return results;
|
|
88
88
|
}
|
|
@@ -126,12 +126,12 @@ function chunkWrites(items) {
|
|
|
126
126
|
return batches;
|
|
127
127
|
}
|
|
128
128
|
/** The server returns a bare `{success}` for single items and per-item `results` for batches. */
|
|
129
|
-
async function runBatch(client, method, params, paths) {
|
|
129
|
+
async function runBatch(client, method, params, paths, timeoutMs) {
|
|
130
130
|
if (!paths.length) {
|
|
131
131
|
return [];
|
|
132
132
|
}
|
|
133
133
|
try {
|
|
134
|
-
const result = await client.call('fs', method, params);
|
|
134
|
+
const result = await client.call('fs', method, params, timeoutMs);
|
|
135
135
|
if (paths.length === 1) {
|
|
136
136
|
return [{ path: paths[0], success: result?.success !== false }];
|
|
137
137
|
}
|
|
@@ -4,6 +4,7 @@ import fs from 'node:fs/promises';
|
|
|
4
4
|
import os from 'node:os';
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import { resolveConfigPath } from '../config.js';
|
|
7
|
+
import { commandInvocation } from '../platform-process.js';
|
|
7
8
|
import { CliError, DEFAULT_CONFIG_DIR } from '../types.js';
|
|
8
9
|
import { getCliVersion } from '../version.js';
|
|
9
10
|
import { ENTRY_SKILL, LEGACY_SKILL_NAMES, PROJECT_SKILLS } from './skill-names.js';
|
|
@@ -237,7 +238,11 @@ function stampPath(home) {
|
|
|
237
238
|
/** With --json, `npx skills` output goes to stderr so stdout stays one JSON document. */
|
|
238
239
|
function runSkillsCli(args, json) {
|
|
239
240
|
return new Promise((resolve, reject) => {
|
|
240
|
-
const
|
|
241
|
+
const run = commandInvocation('npx', args);
|
|
242
|
+
const child = spawn(run.command, run.args, {
|
|
243
|
+
...run.options,
|
|
244
|
+
stdio: json ? ['ignore', 2, 2] : 'inherit',
|
|
245
|
+
});
|
|
241
246
|
child.on('error', reject);
|
|
242
247
|
child.on('close', code => {
|
|
243
248
|
if (code === 0) {
|
|
@@ -2,6 +2,7 @@ import { spawn } from 'node:child_process';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { getString } from '../cli-helpers.js';
|
|
4
4
|
import { printText } from '../output.js';
|
|
5
|
+
import { browserOpenCommand } from '../platform-process.js';
|
|
5
6
|
import { CliError } from '../types.js';
|
|
6
7
|
import { acquireLock, findProjectRoot, readBinding, readManifest, writeManifest, } from './binding.js';
|
|
7
8
|
import { CARD_CONFLICT_SUFFIX } from './constants.js';
|
|
@@ -200,12 +201,8 @@ async function checkSandbox(parsed, conversationId) {
|
|
|
200
201
|
}
|
|
201
202
|
}
|
|
202
203
|
function openInBrowser(url) {
|
|
203
|
-
const [command, args] =
|
|
204
|
-
|
|
205
|
-
: process.platform === 'win32'
|
|
206
|
-
? ['cmd', ['/c', 'start', '', url]]
|
|
207
|
-
: ['xdg-open', [url]];
|
|
208
|
-
spawn(command, args, { stdio: 'ignore', detached: true })
|
|
204
|
+
const [command, args] = browserOpenCommand(url);
|
|
205
|
+
spawn(command, args, { stdio: 'ignore', detached: true, windowsHide: true })
|
|
209
206
|
.on('error', () => undefined)
|
|
210
207
|
.unref();
|
|
211
208
|
}
|