File size: 3,083 Bytes
d739b1b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/** ๋ฐฐ์น˜ ๋Œ€ํ™”ํ˜• ์‹คํ–‰์„ ๊ณตํ†ต ์„ธ์…˜์— ์—ฐ๊ฒฐํ•œ๋‹ค. docs/specs/interactive-execution.md v1.0.0 */
const path = require('path');
const { prepareLaunch } = require('./utils/interactive-cli-launch');
const { runInteractive } = require('./utils/interactive-cli-session');
const { addUsage } = require('./utils/run-usage');
async function runBatchInteractive(config, prompt, cwd, logStream, owner) {
  // ๊ฐ™์€ ๋Œ€ํ™”ํ˜• ์„ธ์…˜์˜ explicitโ†’auto ์ „ํ™˜์€ helper๊ฐ€ ์ข์€ ์–ธ์–ด ์žฌ์„ค์ • ์ง€์‹œ๋กœ ์ฒ˜๋ฆฌํ•œ๋‹ค.
  // ์„ค๋ช… ๋ฌธ์„œ: /docs/specs/bada-bong-language-settings.md (v0.3.0)
  prompt = require('./utils/agent-reply-language').interactiveAppend(prompt, owner, {id:require('./workflow/node-context').current(owner)?.nodeId});
  const conf = require('./config-manager').getConfig();
  const launch = prepareLaunch({ cliCommand: config.cli_engine || require('./context').getActiveCli() || 'claude',
    cliArguments: config.cliArguments || [], model: config.model, profile: config.executionProfile, permissionBypass: config.permission_mode === 'bypass',
    maxTurns: config.max_turns, cwd, env: { ...process.env,
      LANGFUSE_HOST: conf.host || '', LANGFUSE_PUBLIC_KEY: conf.publicKey || '', LANGFUSE_SECRET_KEY: conf.secretKey || '' } });
  const output = await runInteractive({ ...launch, owner, profile: { ...config, prompt: undefined }, prompt,
    signal: owner.lifecycleController?.signal || owner.abortController?.signal, isCancelled: () => owner.aborted === true,
    timeoutMs: (config.timeout ?? 600) * 1000, readyTimeoutMs: (config.ready_timeout ?? 30) * 1000,
    maxBytes: config.maxOutputBytes ?? 2 * 1024 * 1024,
    // ์„ค๋ช… ๋ฌธ์„œ: /docs/specs/bada-bong-agent-sources.md (v0.1.0) โ€” ์žฌ์‚ฌ์šฉ PTY๋„ ์‹ค์ œ ๋‹ด๋‹น ์—ฐ๊ฒฐ๋งŒ ๊ด€์ธกํ•œ๋‹ค.
    register: child => { owner.currentProcess = child; if (child?.pid) { const conductor = require('./services/agent-telemetry-conductor').current(owner); if (conductor) conductor.assigned({...config.executionProfile,name:config.executionProfile?.name || config.model || 'CLI'}); else require('./services/agent-telemetry-batch').assigned(owner, config.executionProfile); } },
    unregister: child => { if (owner.currentProcess === child) owner.currentProcess = null; },
    onOutput: data => logStream.write(data),
    onResult: ({ submitted, complete, requestId }) => {
      // ๋Œ€ํ™”ํ˜• ํ™”๋ฉด์œผ๋กœ provider ์ฒญ๊ตฌ ํ† ํฐ์„ ํ™•์ •ํ•˜์ง€ ์•Š๋Š”๋‹ค. ์‹คํŒจํ•œ ์ œ์ถœ๋„ ๋ฏธ์ƒ ํ˜ธ์ถœ๋กœ ๊ธฐ๋กํ•œ๋‹ค.
      if (submitted) addUsage(owner, 0, 1, { id: requestId, costSource: 'unknown', tokenSource: 'unknown', totalTokens: null, complete });
      else if (requestId) addUsage(owner, 0, 0, { id: requestId, complete, notSubmitted: true,
        costSource: 'not_submitted', tokenSource: 'not_submitted', totalTokens: 0 });
    }
  });
  const hint = output.match(/(?:Wrote to|Edited|Wrote|Created)\s+([^\s\r\n]+)/i)?.[1].replace(/['"`]/g, '');
  return { result: 'success', output, data: {}, file_path: hint ? path.resolve(cwd, hint) : '', usageRecorded: true };
}
module.exports = { runBatchInteractive };