@questionbase/deskfree 0.4.2 → 0.4.4
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/bin.js +47 -12
- package/dist/bin.js.map +1 -1
- package/dist/index.d.ts +10 -0
- package/dist/index.js +47 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire } from 'node:module';
|
|
3
|
-
import { execSync, execFile } from 'child_process';
|
|
3
|
+
import { execSync, execFileSync, execFile } from 'child_process';
|
|
4
4
|
import { writeFileSync, chmodSync, existsSync, unlinkSync, mkdirSync, readdirSync, readFileSync, createWriteStream } from 'fs';
|
|
5
5
|
import { createRequire as createRequire$1 } from 'module';
|
|
6
6
|
import { join, dirname, extname } from 'path';
|
|
@@ -7793,7 +7793,7 @@ Send a brief main-thread message via \`deskfree_send_message\`:
|
|
|
7793
7793
|
}
|
|
7794
7794
|
});
|
|
7795
7795
|
function runOrchestrator(opts) {
|
|
7796
|
-
const { prompt, orchestratorServer, model, sessionId } = opts;
|
|
7796
|
+
const { prompt, orchestratorServer, model, sessionId, claudeCodePath } = opts;
|
|
7797
7797
|
return query({
|
|
7798
7798
|
prompt,
|
|
7799
7799
|
options: {
|
|
@@ -7805,6 +7805,7 @@ function runOrchestrator(opts) {
|
|
|
7805
7805
|
},
|
|
7806
7806
|
systemPrompt: DESKFREE_AGENT_DIRECTIVE,
|
|
7807
7807
|
model,
|
|
7808
|
+
...claudeCodePath ? { pathToClaudeCodeExecutable: claudeCodePath } : {},
|
|
7808
7809
|
maxTurns: MAX_ORCHESTRATOR_TURNS,
|
|
7809
7810
|
permissionMode: "bypassPermissions",
|
|
7810
7811
|
allowDangerouslySkipPermissions: true,
|
|
@@ -7832,12 +7833,13 @@ function runOrchestrator(opts) {
|
|
|
7832
7833
|
});
|
|
7833
7834
|
}
|
|
7834
7835
|
function runHeartbeat(opts) {
|
|
7835
|
-
const { prompt, orchestratorServer, model } = opts;
|
|
7836
|
+
const { prompt, orchestratorServer, model, claudeCodePath } = opts;
|
|
7836
7837
|
return query({
|
|
7837
7838
|
prompt,
|
|
7838
7839
|
options: {
|
|
7839
7840
|
systemPrompt: DESKFREE_AGENT_DIRECTIVE,
|
|
7840
7841
|
model,
|
|
7842
|
+
...claudeCodePath ? { pathToClaudeCodeExecutable: claudeCodePath } : {},
|
|
7841
7843
|
maxTurns: MAX_ORCHESTRATOR_TURNS,
|
|
7842
7844
|
permissionMode: "bypassPermissions",
|
|
7843
7845
|
allowDangerouslySkipPermissions: true,
|
|
@@ -7959,8 +7961,27 @@ function loadConfig() {
|
|
|
7959
7961
|
};
|
|
7960
7962
|
}
|
|
7961
7963
|
function mergeWithRemoteConfig(local, remote) {
|
|
7964
|
+
const stateDirOverridden = !!process.env["DESKFREE_STATE_DIR"];
|
|
7965
|
+
const toolsDirOverridden = !!process.env["DESKFREE_TOOLS_DIR"];
|
|
7966
|
+
const stateDir = stateDirOverridden ? local.stateDir : isDocker ? local.stateDir : `.deskfree/${remote.botId}/state`;
|
|
7967
|
+
const toolsDir = toolsDirOverridden ? local.toolsDir : isDocker ? local.toolsDir : `.deskfree/${remote.botId}/tools`;
|
|
7968
|
+
let claudeCodePath;
|
|
7969
|
+
if (remote.provider === "claude-code") {
|
|
7970
|
+
try {
|
|
7971
|
+
claudeCodePath = execFileSync("which", ["claude"], {
|
|
7972
|
+
encoding: "utf8"
|
|
7973
|
+
}).trim();
|
|
7974
|
+
} catch {
|
|
7975
|
+
throw new Error(
|
|
7976
|
+
'Provider is "claude-code" but the `claude` CLI was not found on PATH. Install Claude Code first: https://docs.anthropic.com/en/docs/claude-code'
|
|
7977
|
+
);
|
|
7978
|
+
}
|
|
7979
|
+
}
|
|
7962
7980
|
return {
|
|
7963
7981
|
...local,
|
|
7982
|
+
stateDir,
|
|
7983
|
+
toolsDir,
|
|
7984
|
+
claudeCodePath,
|
|
7964
7985
|
wsUrl: process.env["DESKFREE_WS_URL"] ?? remote.wsUrl,
|
|
7965
7986
|
model: process.env["DESKFREE_MODEL"] ?? remote.model,
|
|
7966
7987
|
awsRegion: process.env["AWS_REGION"] ?? remote.awsRegion,
|
|
@@ -13037,7 +13058,8 @@ async function routeMessage(message, client, deps, sessionStore, config) {
|
|
|
13037
13058
|
prompt,
|
|
13038
13059
|
orchestratorServer: deps.createOrchestratorServer(),
|
|
13039
13060
|
model: deps.model,
|
|
13040
|
-
sessionId: existingSessionId
|
|
13061
|
+
sessionId: existingSessionId,
|
|
13062
|
+
claudeCodePath: deps.claudeCodePath
|
|
13041
13063
|
});
|
|
13042
13064
|
let fullText = "";
|
|
13043
13065
|
let capturedSessionId = null;
|
|
@@ -13771,7 +13793,16 @@ function startHealthServer(port, log) {
|
|
|
13771
13793
|
log.info(`Health server listening on port ${port}`);
|
|
13772
13794
|
});
|
|
13773
13795
|
server.on("error", (err) => {
|
|
13774
|
-
|
|
13796
|
+
if (err.code === "EADDRINUSE") {
|
|
13797
|
+
log.info(`Port ${port} in use, requesting OS-assigned port...`);
|
|
13798
|
+
server.listen(0, () => {
|
|
13799
|
+
const addr = server.address();
|
|
13800
|
+
const assignedPort = typeof addr === "object" && addr ? addr.port : "unknown";
|
|
13801
|
+
log.info(`Health server listening on port ${assignedPort}`);
|
|
13802
|
+
});
|
|
13803
|
+
} else {
|
|
13804
|
+
log.warn(`Health server error: ${err.message}`);
|
|
13805
|
+
}
|
|
13775
13806
|
});
|
|
13776
13807
|
return {
|
|
13777
13808
|
close() {
|
|
@@ -13779,7 +13810,7 @@ function startHealthServer(port, log) {
|
|
|
13779
13810
|
}
|
|
13780
13811
|
};
|
|
13781
13812
|
}
|
|
13782
|
-
function scheduleHeartbeat(createOrchServer, model, intervalMs, signal, log) {
|
|
13813
|
+
function scheduleHeartbeat(createOrchServer, model, intervalMs, signal, log, claudeCodePath) {
|
|
13783
13814
|
if (intervalMs <= 0) return;
|
|
13784
13815
|
let running = false;
|
|
13785
13816
|
async function tick() {
|
|
@@ -13790,7 +13821,8 @@ function scheduleHeartbeat(createOrchServer, model, intervalMs, signal, log) {
|
|
|
13790
13821
|
const result = runHeartbeat({
|
|
13791
13822
|
prompt: DESKFREE_HEARTBEAT_DIRECTIVE,
|
|
13792
13823
|
orchestratorServer: createOrchServer(),
|
|
13793
|
-
model
|
|
13824
|
+
model,
|
|
13825
|
+
claudeCodePath
|
|
13794
13826
|
});
|
|
13795
13827
|
for await (const _ of result) {
|
|
13796
13828
|
}
|
|
@@ -13812,8 +13844,6 @@ async function startAgent(opts) {
|
|
|
13812
13844
|
const log = opts?.log ?? createLogger("agent", localConfig.logLevel);
|
|
13813
13845
|
const abortController = new AbortController();
|
|
13814
13846
|
log.info("DeskFree Agent Runtime starting...");
|
|
13815
|
-
mkdirSync(localConfig.stateDir, { recursive: true });
|
|
13816
|
-
mkdirSync(localConfig.toolsDir, { recursive: true });
|
|
13817
13847
|
const client = new DeskFreeClient(localConfig.botToken, localConfig.apiUrl);
|
|
13818
13848
|
const errorReporter = initErrorReporter(client, log);
|
|
13819
13849
|
initializeHealth("unknown");
|
|
@@ -13826,12 +13856,15 @@ async function startAgent(opts) {
|
|
|
13826
13856
|
wsUrl: config.wsUrl,
|
|
13827
13857
|
model: config.model,
|
|
13828
13858
|
region: config.awsRegion,
|
|
13829
|
-
tools: config.tools.length
|
|
13859
|
+
tools: config.tools.length,
|
|
13860
|
+
botId: config.botId
|
|
13830
13861
|
});
|
|
13831
13862
|
} catch (err) {
|
|
13832
13863
|
const msg = err instanceof Error ? err.message : String(err);
|
|
13833
13864
|
throw new Error(`Failed to bootstrap config from API: ${msg}`);
|
|
13834
13865
|
}
|
|
13866
|
+
mkdirSync(config.stateDir, { recursive: true });
|
|
13867
|
+
mkdirSync(config.toolsDir, { recursive: true });
|
|
13835
13868
|
if (config.tools.length > 0) {
|
|
13836
13869
|
log.info(`Installing ${config.tools.length} tool package(s)...`);
|
|
13837
13870
|
await installTools(config.tools, config.toolsDir, log);
|
|
@@ -13912,7 +13945,8 @@ async function startAgent(opts) {
|
|
|
13912
13945
|
{
|
|
13913
13946
|
createOrchestratorServer: createOrchServer,
|
|
13914
13947
|
workerManager,
|
|
13915
|
-
model: config.model
|
|
13948
|
+
model: config.model,
|
|
13949
|
+
claudeCodePath: config.claudeCodePath
|
|
13916
13950
|
},
|
|
13917
13951
|
sessionStore,
|
|
13918
13952
|
{
|
|
@@ -13927,7 +13961,8 @@ async function startAgent(opts) {
|
|
|
13927
13961
|
config.model,
|
|
13928
13962
|
config.heartbeatIntervalMs,
|
|
13929
13963
|
abortController.signal,
|
|
13930
|
-
log
|
|
13964
|
+
log,
|
|
13965
|
+
config.claudeCodePath
|
|
13931
13966
|
);
|
|
13932
13967
|
if (config.memoryFileId && config.sleepHour !== null && config.timezone) {
|
|
13933
13968
|
const memoryFileId = config.memoryFileId;
|