@otium-team/negotium 0.24.0 → 0.24.2
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/agent-helpers.js +61 -25
- package/dist/agent-helpers.js.map +9 -9
- package/dist/background-bash.js +3 -2
- package/dist/background-bash.js.map +3 -3
- package/dist/browser-runtime.js +21 -5
- package/dist/browser-runtime.js.map +5 -5
- package/dist/{chunk-fzfzskjq.js → chunk-7jdavm0e.js} +20 -4
- package/dist/{chunk-fzfzskjq.js.map → chunk-7jdavm0e.js.map} +4 -4
- package/dist/{chunk-3r4xfhkx.js → chunk-8nr3h475.js} +3 -3
- package/dist/{chunk-3r4xfhkx.js.map → chunk-8nr3h475.js.map} +2 -2
- package/dist/{chunk-hn2cqdd0.js → chunk-q701c7k3.js} +1 -1
- package/dist/{chunk-pesnv5zv.js → chunk-r3q0kjed.js} +4 -3
- package/dist/{chunk-pesnv5zv.js.map → chunk-r3q0kjed.js.map} +3 -3
- package/dist/{chunk-d1c2wt8q.js → chunk-wcs8ztpt.js} +4 -2
- package/dist/{chunk-d1c2wt8q.js.map → chunk-wcs8ztpt.js.map} +1 -1
- package/dist/hosted-agent.js +22 -6
- package/dist/hosted-agent.js.map +4 -4
- package/dist/main.js +161 -46
- package/dist/main.js.map +13 -13
- package/dist/mcp-factories.js +61 -25
- package/dist/mcp-factories.js.map +9 -9
- package/dist/media.js +3 -2
- package/dist/media.js.map +3 -3
- package/dist/prompts.js +3 -2
- package/dist/prompts.js.map +3 -3
- package/dist/query-runtime.js +3 -2
- package/dist/query-runtime.js.map +3 -3
- package/dist/registry.js +3 -3
- package/dist/rollout.js +2 -2
- package/dist/runtime/src/agents/mcp-tools/ask-user.ts +56 -1
- package/dist/runtime/src/application/submit-runtime-gateway-turn.ts +86 -0
- package/dist/runtime/src/application/topic-service.ts +11 -1
- package/dist/runtime/src/application/turn-follow-ups.ts +7 -0
- package/dist/runtime/src/platform/config.ts +9 -1
- package/dist/runtime/src/platform/playwright/vault-broker.ts +6 -2
- package/dist/runtime/src/runtime/turn-runner.ts +58 -23
- package/dist/runtime/src/storage/vault-public.ts +1 -0
- package/dist/runtime/src/storage/vault.ts +36 -4
- package/dist/runtime/src/version.ts +1 -1
- package/dist/runtime-helpers.js +3 -2
- package/dist/runtime-helpers.js.map +3 -3
- package/dist/types/packages/core/src/agents/mcp-tools/ask-user.d.ts +14 -0
- package/dist/types/packages/core/src/platform/config.d.ts +9 -1
- package/dist/types/packages/core/src/runtime/turn-runner.d.ts +12 -0
- package/dist/types/packages/core/src/storage/vault-public.d.ts +1 -1
- package/dist/types/packages/core/src/storage/vault.d.ts +10 -0
- package/dist/types/packages/core/src/version.d.ts +1 -1
- package/dist/vault.js +27 -5
- package/dist/vault.js.map +4 -4
- package/install-browser-rs.mjs +4 -4
- package/package.json +1 -1
- /package/dist/{chunk-hn2cqdd0.js.map → chunk-q701c7k3.js.map} +0 -0
package/dist/main.js
CHANGED
|
@@ -3889,8 +3889,8 @@ function answerToolResult(answer) {
|
|
|
3889
3889
|
return textResult("The user skipped this question. Continue using your best judgment and finish the current turn.");
|
|
3890
3890
|
}
|
|
3891
3891
|
if (answer.kind === "custom") {
|
|
3892
|
-
return textResult(`
|
|
3893
|
-
Continue from this answer and finish the current turn.`);
|
|
3892
|
+
return textResult(`The user did not pick a listed option. They typed this reply in the chat instead: "${answer.label}"
|
|
3893
|
+
Treat it as their free-text answer to your question and read it for what it says. If it hands the decision back to you (for example "decide yourself" or "you handle it"), choose the best option yourself and go on. Continue from this answer and finish the current turn.`);
|
|
3894
3894
|
}
|
|
3895
3895
|
const description = answer.description ? `
|
|
3896
3896
|
Description: ${answer.description}` : "";
|
|
@@ -3982,6 +3982,7 @@ function createAskUserRuntime(host) {
|
|
|
3982
3982
|
id: createId(),
|
|
3983
3983
|
topicId,
|
|
3984
3984
|
authorId: userId,
|
|
3985
|
+
...options.answerMessage,
|
|
3985
3986
|
text: label,
|
|
3986
3987
|
parentId: messageId,
|
|
3987
3988
|
...existing.threadRootId ? { threadRootId: existing.threadRootId } : {},
|
|
@@ -4000,6 +4001,20 @@ function createAskUserRuntime(host) {
|
|
|
4000
4001
|
pending.resolve({ ...choice, userId, ...kind ? { kind } : {} });
|
|
4001
4002
|
return { ok: true, queryId: pending.queryId, answerMessage };
|
|
4002
4003
|
}
|
|
4004
|
+
function answerOpenQuestionWithText(topicId, text, userId, options = {}) {
|
|
4005
|
+
for (const [messageId, pending] of pendingAsks) {
|
|
4006
|
+
if (pending.topicId !== topicId)
|
|
4007
|
+
continue;
|
|
4008
|
+
const card = host.messaging.persistence.getMessage(topicId, messageId);
|
|
4009
|
+
if ((card?.threadRootId ?? undefined) !== (options.threadRootId ?? undefined))
|
|
4010
|
+
continue;
|
|
4011
|
+
return answerPendingQuestion(topicId, messageId, text, userId, {
|
|
4012
|
+
kind: "custom",
|
|
4013
|
+
...options.answerMessage ? { answerMessage: options.answerMessage } : {}
|
|
4014
|
+
});
|
|
4015
|
+
}
|
|
4016
|
+
return null;
|
|
4017
|
+
}
|
|
4003
4018
|
function cancelPendingQuestions(topicId, queryId) {
|
|
4004
4019
|
for (const [messageId, pending] of pendingAsks) {
|
|
4005
4020
|
if (pending.topicId === topicId && pending.queryId === queryId) {
|
|
@@ -4155,6 +4170,7 @@ function createAskUserRuntime(host) {
|
|
|
4155
4170
|
reconcilePendingGates,
|
|
4156
4171
|
hasPendingQuestion,
|
|
4157
4172
|
answerPendingQuestion,
|
|
4173
|
+
answerOpenQuestionWithText,
|
|
4158
4174
|
cancelPendingQuestions,
|
|
4159
4175
|
createToolDefinition
|
|
4160
4176
|
};
|
|
@@ -4171,6 +4187,9 @@ function reconcilePendingAskUserQuestionGates() {
|
|
|
4171
4187
|
function answerPendingAskUserQuestion(topicId, messageId, label, userId, options) {
|
|
4172
4188
|
return defaultAskUserRuntime.answerPendingQuestion(topicId, messageId, label, userId, options);
|
|
4173
4189
|
}
|
|
4190
|
+
function answerOpenAskUserQuestionWithText(topicId, text, userId, options) {
|
|
4191
|
+
return defaultAskUserRuntime.answerOpenQuestionWithText(topicId, text, userId, options);
|
|
4192
|
+
}
|
|
4174
4193
|
function cancelPendingAskUserQuestions(topicId, queryId) {
|
|
4175
4194
|
defaultAskUserRuntime.cancelPendingQuestions(topicId, queryId);
|
|
4176
4195
|
}
|
|
@@ -4483,7 +4502,7 @@ function resolveWhisperBackend() {
|
|
|
4483
4502
|
function codexAuthFilePath() {
|
|
4484
4503
|
return process.env.NEGOTIUM_CODEX_AUTH_FILE || join5(process.env.CODEX_HOME || join5(homedir3(), ".codex"), "auth.json");
|
|
4485
4504
|
}
|
|
4486
|
-
var HOME, PROJECT_ROOT, STATE_DIR, WORKSPACE_DIR, TOPIC_WORKSPACE_DIR, SHARED_WIKI_DIR, CRON_WORKSPACE_DIR, BROWSER_DIR, BROWSER_BACKEND, BROWSER_PROFILES_DIR, BINARIES_DIR, SECRETS_DIR, DM_WORKSPACE_DIR, SESSION_WORKSPACE_DIR, CLAUDE_EXECUTABLE_ENV, CLAUDE_EXECUTABLE, DEFAULT_OUTPUT_LANGUAGE = "English", BINARY_EXTENSION, BROWSER_RS_VERSION = "v0.
|
|
4505
|
+
var HOME, PROJECT_ROOT, STATE_DIR, WORKSPACE_DIR, TOPIC_WORKSPACE_DIR, SHARED_WIKI_DIR, CRON_WORKSPACE_DIR, BROWSER_DIR, BROWSER_BACKEND, BROWSER_PROFILES_DIR, BINARIES_DIR, SECRETS_DIR, DM_WORKSPACE_DIR, SESSION_WORKSPACE_DIR, CLAUDE_EXECUTABLE_ENV, CLAUDE_EXECUTABLE, DEFAULT_OUTPUT_LANGUAGE = "English", BINARY_EXTENSION, BROWSER_RS_VERSION = "v0.8.1", BROWSER_RS_MIN_SECURE_VERSION = "0.2.1", BROWSER_RS_VERSION_PROBE_TIMEOUT_MS = 15000, SNIPPETS_API_URL, BROWSER_RS_BIN, BASH_RS_VERSION = "v0.1.10", BASH_RS_BIN, PLAYWRIGHT_MCP_BIN, TSX_BIN, TSX_LOADER_PATH, TSX_LOADER, TSCONFIG_PATH, SESSION_COMM_SERVER, TASK_SERVER, DECISION_SERVER, CANONICAL_MCP_PROXY_SERVER, WIKI_SERVER, TOKEN_STATS_SERVER, COMPACTION_LOG_SERVER, SESSION_HISTORY_SERVER, SYSTEM_HEALTH_SERVER, AGENT_HEALTH_SERVER, VAULT_SERVER, BG_BASH_BASE_PORT, BG_BASH_MAX_PORT, RUNTIME_MCP_SECRET, NODE_CONTROL_TOKEN, NODE_ID, VAULT_MASTER_KEY, VAULT_SHARED_USER_ID, NEGOTIUM_PORT, hostname, DATA_DIR, LOG_DIR, UPLOADS_DIR, VAULT_DIR, SESSIONS_DB, DEBUG_FILE, USERS_LOG_DIR, RUN_DIR, PROGRESS_DIR, DM_CMD_DIR, DM_RESP_DIR, SESSION_INBOX_DIR, SESSION_ASKS_DIR, BASHRS_SPILL_ROOT, PLAYWRIGHT_BASE_PORT, PLAYWRIGHT_MAX_PORT, PLAYWRIGHT_PORTS_DIR, ACTIVE_QUERY_STALE_MS, AGENTS_PROMPTS_DIR, RESOURCES_DIR, ABSOLUTE_PATH_PREFIX, FILE_EXTENSIONS_REGEX, FILE_TAG_REGEX, MODEL_SONNET = "claude-sonnet-5", MODEL_OPUS = "claude-opus-5-5", MODEL_FABLE = "claude-fable-5-1", MODEL_FABLE_5_2 = "claude-fable-5-2", FALLBACK_AGENT, FALLBACK_MODEL, DEFAULT_TOPIC_EFFORT, FFMPEG_BIN, FFPROBE_BIN, PYTHON_BIN, FASTER_WHISPER_WRAPPER, WHISPER_MODEL, TESSERACT_BIN, PDFTOTEXT_BIN, WHISPER_BACKEND, MLX_WHISPER_BIN, WHISPER_MODEL_MLX, _envMaxTellDepth, MAX_TELL_DEPTH;
|
|
4487
4506
|
var init_config = __esm(() => {
|
|
4488
4507
|
init_browser_backend();
|
|
4489
4508
|
init_config_helpers();
|
|
@@ -4532,6 +4551,7 @@ var init_config = __esm(() => {
|
|
|
4532
4551
|
NODE_ID = loadOrCreateLocalSecret("NEGOTIUM_NODE_ID", "node-id");
|
|
4533
4552
|
VAULT_MASTER_KEY = loadOrCreateLocalSecret("NEGOTIUM_VAULT_MASTER_KEY", "vault-master-key", { persistEnvValue: true });
|
|
4534
4553
|
delete process.env.NEGOTIUM_VAULT_MASTER_KEY;
|
|
4554
|
+
VAULT_SHARED_USER_ID = process.env.NEGOTIUM_VAULT_SHARED_USER?.trim() || undefined;
|
|
4535
4555
|
NEGOTIUM_PORT = parseInt(process.env.NEGOTIUM_PORT || "7777", 10);
|
|
4536
4556
|
hostname = process.env.HOSTNAME || "127.0.0.1";
|
|
4537
4557
|
DATA_DIR = resolveLocalStateDir("NEGOTIUM_DATA_DIR", "data");
|
|
@@ -4656,6 +4676,9 @@ var init_vault_crypto = __esm(() => {
|
|
|
4656
4676
|
// ../../packages/core/src/storage/vault.ts
|
|
4657
4677
|
import { chmodSync as chmodSync2, mkdirSync as mkdirSync6 } from "fs";
|
|
4658
4678
|
import { join as join6 } from "path";
|
|
4679
|
+
function sharedOwnerFor(userId) {
|
|
4680
|
+
return vaultSharedUserId && vaultSharedUserId !== userId ? vaultSharedUserId : undefined;
|
|
4681
|
+
}
|
|
4659
4682
|
function initializeVaultDatabase(database) {
|
|
4660
4683
|
database.exec("PRAGMA journal_mode = WAL");
|
|
4661
4684
|
database.exec("PRAGMA busy_timeout = 5000");
|
|
@@ -4762,13 +4785,20 @@ function vaultGetValue(userId, key) {
|
|
|
4762
4785
|
const row = activeVaultDatabase().prepare("SELECT key, value FROM vault WHERE user_id = ? AND key = ?").get(userId, normalizedKey);
|
|
4763
4786
|
return row ? decryptRow(userId, row.key, row.value) : undefined;
|
|
4764
4787
|
}
|
|
4788
|
+
function vaultResolveValue(userId, key) {
|
|
4789
|
+
const own = vaultGetValue(userId, key);
|
|
4790
|
+
if (own !== undefined)
|
|
4791
|
+
return own;
|
|
4792
|
+
const shared = sharedOwnerFor(userId);
|
|
4793
|
+
return shared ? vaultGetValue(shared, key) : undefined;
|
|
4794
|
+
}
|
|
4765
4795
|
function vaultSubstituteDetailed(userId, text) {
|
|
4766
4796
|
const entries = new Map;
|
|
4767
4797
|
const usedKeys = new Set;
|
|
4768
4798
|
const substituted = text.replace(/\{\{([^}]+)\}\}/g, (match, rawKey) => {
|
|
4769
4799
|
const key = normalizeVaultKey(rawKey);
|
|
4770
4800
|
if (!entries.has(key))
|
|
4771
|
-
entries.set(key,
|
|
4801
|
+
entries.set(key, vaultResolveValue(userId, key));
|
|
4772
4802
|
const value = entries.get(key);
|
|
4773
4803
|
if (value === undefined)
|
|
4774
4804
|
return match;
|
|
@@ -4789,7 +4819,11 @@ function encodedSecretForms(value) {
|
|
|
4789
4819
|
return [...forms].sort((a, b) => b.length - a.length);
|
|
4790
4820
|
}
|
|
4791
4821
|
function redactVaultSecrets(userId, text) {
|
|
4792
|
-
const
|
|
4822
|
+
const shared = sharedOwnerFor(userId);
|
|
4823
|
+
const candidates = [
|
|
4824
|
+
...vaultListDecryptableValues(userId),
|
|
4825
|
+
...shared ? vaultListDecryptableValues(shared) : []
|
|
4826
|
+
].flatMap((entry) => encodedSecretForms(entry.value).map((form) => ({ form, key: entry.key }))).sort((a, b) => b.form.length - a.form.length || a.key.localeCompare(b.key));
|
|
4793
4827
|
if (candidates.length === 0)
|
|
4794
4828
|
return text;
|
|
4795
4829
|
const candidatesByFirstCharacter = new Map;
|
|
@@ -4815,7 +4849,7 @@ function redactVaultSecrets(userId, text) {
|
|
|
4815
4849
|
}
|
|
4816
4850
|
return redacted;
|
|
4817
4851
|
}
|
|
4818
|
-
var vaultDb, vaultMasterKey, VAULT_KEY_PATTERN, VAULT_VALUE_MIN_BYTES = 4, VAULT_VALUE_MAX_BYTES, VAULT_DESCRIPTION_MAX_LENGTH = 500;
|
|
4852
|
+
var vaultDb, vaultMasterKey, vaultSharedUserId, VAULT_KEY_PATTERN, VAULT_VALUE_MIN_BYTES = 4, VAULT_VALUE_MAX_BYTES, VAULT_DESCRIPTION_MAX_LENGTH = 500;
|
|
4819
4853
|
var init_vault = __esm(async () => {
|
|
4820
4854
|
init_config();
|
|
4821
4855
|
init_vault_crypto();
|
|
@@ -4824,6 +4858,7 @@ var init_vault = __esm(async () => {
|
|
|
4824
4858
|
init_storage_host()
|
|
4825
4859
|
]);
|
|
4826
4860
|
vaultMasterKey = VAULT_MASTER_KEY;
|
|
4861
|
+
vaultSharedUserId = VAULT_SHARED_USER_ID;
|
|
4827
4862
|
VAULT_KEY_PATTERN = /^[A-Z][A-Z0-9_]{0,127}$/;
|
|
4828
4863
|
VAULT_VALUE_MAX_BYTES = 64 * 1024;
|
|
4829
4864
|
});
|
|
@@ -8899,7 +8934,7 @@ var init_codex = __esm(async () => {
|
|
|
8899
8934
|
});
|
|
8900
8935
|
|
|
8901
8936
|
// ../../packages/core/src/version.ts
|
|
8902
|
-
var NEGOTIUM_VERSION = "0.24.
|
|
8937
|
+
var NEGOTIUM_VERSION = "0.24.2";
|
|
8903
8938
|
|
|
8904
8939
|
// ../../packages/core/src/agents/codex-native-multi-agent.ts
|
|
8905
8940
|
import { spawn as spawn2 } from "child_process";
|
|
@@ -10317,7 +10352,7 @@ async function createBrowserVaultBroker(userId) {
|
|
|
10317
10352
|
const substituted = deepMapStrings(request.value, (text) => {
|
|
10318
10353
|
const result = vaultSubstituteDetailed(userId, text);
|
|
10319
10354
|
for (const key of result.usedKeys) {
|
|
10320
|
-
const secret =
|
|
10355
|
+
const secret = vaultResolveValue(userId, key);
|
|
10321
10356
|
if (secret === undefined)
|
|
10322
10357
|
continue;
|
|
10323
10358
|
for (const form of encodedSecretForms2(secret))
|
|
@@ -22600,6 +22635,7 @@ var init_plugin_turn = __esm(async () => {
|
|
|
22600
22635
|
var exports_turn_runner = {};
|
|
22601
22636
|
__export(exports_turn_runner, {
|
|
22602
22637
|
deliverAskCallbackToCaller: () => deliverAskCallbackToCaller,
|
|
22638
|
+
preemptSessionInjectForUserTurn: () => preemptSessionInjectForUserTurn,
|
|
22603
22639
|
resolveInitialTurnSessionId: () => resolveInitialTurnSessionId,
|
|
22604
22640
|
resolveTopicTurnExecution: () => resolveTopicTurnExecution,
|
|
22605
22641
|
resolveTopicTurnSession: () => resolveTopicTurnSession,
|
|
@@ -23352,22 +23388,7 @@ function startAiTurn(params) {
|
|
|
23352
23388
|
];
|
|
23353
23389
|
}
|
|
23354
23390
|
}
|
|
23355
|
-
|
|
23356
|
-
const runningInject = running.injectParams;
|
|
23357
|
-
const requeuedInject = prepareInjectReplayAfterUserPreemption(runningInject);
|
|
23358
|
-
const queued = deferInject(requeuedInject);
|
|
23359
|
-
running.injectRequeued = queued;
|
|
23360
|
-
if (queued && runningInject.prepareSession) {
|
|
23361
|
-
running.injectParams = { ...runningInject, requestId: undefined };
|
|
23362
|
-
} else if (!queued && runningInject.forkHandle) {
|
|
23363
|
-
cleanupAgentFork(runningInject.forkHandle);
|
|
23364
|
-
running.injectParams = {
|
|
23365
|
-
...runningInject,
|
|
23366
|
-
forkHandle: undefined,
|
|
23367
|
-
sessionId: undefined
|
|
23368
|
-
};
|
|
23369
|
-
}
|
|
23370
|
-
}
|
|
23391
|
+
requeueSessionInjectForUserPreemption(running);
|
|
23371
23392
|
running.abortReason = "internal" /* Internal */;
|
|
23372
23393
|
running.abortController.abort();
|
|
23373
23394
|
logger.info({ topicId, supersededQueryId: running.queryId, supersededOrigin: running.origin }, "ai: new user message superseded running turn");
|
|
@@ -23996,6 +24017,38 @@ To use another registered model, switch with /model <model> and send again.`, th
|
|
|
23996
24017
|
});
|
|
23997
24018
|
return queryId;
|
|
23998
24019
|
}
|
|
24020
|
+
function requeueSessionInjectForUserPreemption(running) {
|
|
24021
|
+
const runningInject = running.injectParams;
|
|
24022
|
+
if (!runningInject)
|
|
24023
|
+
return false;
|
|
24024
|
+
const requeuedInject = prepareInjectReplayAfterUserPreemption(runningInject);
|
|
24025
|
+
const queued = deferInject(requeuedInject);
|
|
24026
|
+
running.injectRequeued = queued;
|
|
24027
|
+
if (queued && runningInject.prepareSession) {
|
|
24028
|
+
running.injectParams = { ...runningInject, requestId: undefined };
|
|
24029
|
+
} else if (!queued && runningInject.forkHandle) {
|
|
24030
|
+
cleanupAgentFork(runningInject.forkHandle);
|
|
24031
|
+
running.injectParams = {
|
|
24032
|
+
...runningInject,
|
|
24033
|
+
forkHandle: undefined,
|
|
24034
|
+
sessionId: undefined
|
|
24035
|
+
};
|
|
24036
|
+
}
|
|
24037
|
+
return queued;
|
|
24038
|
+
}
|
|
24039
|
+
function preemptSessionInjectForUserTurn(topicId) {
|
|
24040
|
+
const running = getRoomQuery(topicId);
|
|
24041
|
+
if (!running || isUserOrigin(running.origin) || !running.injectParams)
|
|
24042
|
+
return false;
|
|
24043
|
+
if (running.abortController.signal.aborted)
|
|
24044
|
+
return false;
|
|
24045
|
+
if (!requeueSessionInjectForUserPreemption(running))
|
|
24046
|
+
return false;
|
|
24047
|
+
running.abortReason = "internal" /* Internal */;
|
|
24048
|
+
running.abortController.abort();
|
|
24049
|
+
logger.info({ topicId, supersededQueryId: running.queryId, supersededOrigin: running.origin }, "ai: user steer preempted running session-inject");
|
|
24050
|
+
return true;
|
|
24051
|
+
}
|
|
23999
24052
|
function wasLocallyRequeuedAfterUserPreemption(outcomeKind, control) {
|
|
24000
24053
|
return outcomeKind === "aborted" && control.abortReason === "internal" /* Internal */ && Boolean(control.injectParams) && control.injectRequeued === true;
|
|
24001
24054
|
}
|
|
@@ -26504,6 +26557,54 @@ function gatewayPayloadHash(params, requestId, actorUserId) {
|
|
|
26504
26557
|
params.attachments ?? []
|
|
26505
26558
|
])).digest("hex");
|
|
26506
26559
|
}
|
|
26560
|
+
function answerOpenAskWithMessage(params) {
|
|
26561
|
+
const text = params.text.trim();
|
|
26562
|
+
if (!text || params.respond === false || params.silent === true || params.parentId || params.attachments?.length || isTopicClaimAbortFenced(params.topic.id)) {
|
|
26563
|
+
return null;
|
|
26564
|
+
}
|
|
26565
|
+
const requestId = params.requestId ?? params.clientMessageId;
|
|
26566
|
+
const actorUserId = params.actorUserId ?? params.userId;
|
|
26567
|
+
const sourceAdapter = params.sourceAdapter?.trim() || "runtime-gateway";
|
|
26568
|
+
const answered = answerOpenAskUserQuestionWithText(params.topic.id, text, params.userId, {
|
|
26569
|
+
...params.threadRootId ? { threadRootId: params.threadRootId } : {},
|
|
26570
|
+
answerMessage: {
|
|
26571
|
+
authorId: actorUserId,
|
|
26572
|
+
...params.actorLabel ? { authorName: params.actorLabel } : {},
|
|
26573
|
+
sourceAdapter,
|
|
26574
|
+
sourceMessageId: params.clientMessageId
|
|
26575
|
+
}
|
|
26576
|
+
});
|
|
26577
|
+
if (!answered?.ok)
|
|
26578
|
+
return null;
|
|
26579
|
+
const message = answered.answerMessage;
|
|
26580
|
+
const submission = {
|
|
26581
|
+
clientMessageId: params.clientMessageId,
|
|
26582
|
+
requestId,
|
|
26583
|
+
topicId: params.topic.id,
|
|
26584
|
+
messageId: message.id,
|
|
26585
|
+
userId: params.userId,
|
|
26586
|
+
createdAt: message.createdAt,
|
|
26587
|
+
ackCursor: 0,
|
|
26588
|
+
messageCursor: 0,
|
|
26589
|
+
payloadHash: gatewayPayloadHash(params, requestId, actorUserId)
|
|
26590
|
+
};
|
|
26591
|
+
db.transaction(() => {
|
|
26592
|
+
const acceptedEvent = appendRuntimeEvent("runtime-gateway-ingress", {
|
|
26593
|
+
type: "ai-status",
|
|
26594
|
+
topicId: params.topic.id,
|
|
26595
|
+
payload: {
|
|
26596
|
+
kind: "turn_accepted",
|
|
26597
|
+
requestId,
|
|
26598
|
+
clientMessageId: params.clientMessageId,
|
|
26599
|
+
messageId: message.id,
|
|
26600
|
+
delivery: "answered"
|
|
26601
|
+
}
|
|
26602
|
+
});
|
|
26603
|
+
submission.ackCursor = acceptedEvent.seq;
|
|
26604
|
+
recordRuntimeGatewaySubmission(submission);
|
|
26605
|
+
})();
|
|
26606
|
+
return { ...submission, message, deduplicated: false };
|
|
26607
|
+
}
|
|
26507
26608
|
function submitRuntimeGatewayTurn(params) {
|
|
26508
26609
|
const hostMcpServers = parseHostMcpServers(params.hostMcpServers);
|
|
26509
26610
|
const grantRefusal = hostMcpServers === undefined ? null : hostMcpGrantRefusal(params.topic, Object.keys(hostMcpServers));
|
|
@@ -26524,6 +26625,9 @@ function submitRuntimeGatewayTurn(params) {
|
|
|
26524
26625
|
}
|
|
26525
26626
|
if (isTopicClaimAbortFenced(params.topic.id))
|
|
26526
26627
|
throw new RuntimeGatewayTopicUnavailableError;
|
|
26628
|
+
const answeredAsk = answerOpenAskWithMessage(params);
|
|
26629
|
+
if (answeredAsk)
|
|
26630
|
+
return answeredAsk;
|
|
26527
26631
|
recordTopicToolCapabilities(params.topic.id, {
|
|
26528
26632
|
visualTools: params.visualTools === true,
|
|
26529
26633
|
fileDeliveryTools: params.fileDeliveryTools === true
|
|
@@ -26562,6 +26666,7 @@ function submitRuntimeGatewayTurn(params) {
|
|
|
26562
26666
|
payloadHash
|
|
26563
26667
|
};
|
|
26564
26668
|
let steersActiveTurn = false;
|
|
26669
|
+
let preemptsSessionInject = false;
|
|
26565
26670
|
let delivery;
|
|
26566
26671
|
try {
|
|
26567
26672
|
db.transaction(() => {
|
|
@@ -26623,6 +26728,7 @@ function submitRuntimeGatewayTurn(params) {
|
|
|
26623
26728
|
...(params.steer === false || params.inject === true) && active ? { keepRequestIds: [active.requestId] } : {}
|
|
26624
26729
|
});
|
|
26625
26730
|
steersActiveTurn = active !== null && merged.supersededRequestIds.includes(active.requestId);
|
|
26731
|
+
preemptsSessionInject = active === null && params.steer !== false && params.inject !== true && params.silent !== true;
|
|
26626
26732
|
delivery = steersActiveTurn ? "steered" : active ? "queued" : "started";
|
|
26627
26733
|
}
|
|
26628
26734
|
}
|
|
@@ -26659,6 +26765,8 @@ function submitRuntimeGatewayTurn(params) {
|
|
|
26659
26765
|
}
|
|
26660
26766
|
if (steersActiveTurn)
|
|
26661
26767
|
abortRoom(params.topic.id, "internal" /* Internal */);
|
|
26768
|
+
else if (preemptsSessionInject)
|
|
26769
|
+
preemptSessionInjectForUserTurn(params.topic.id);
|
|
26662
26770
|
return { ...submission, message, deduplicated: false };
|
|
26663
26771
|
}
|
|
26664
26772
|
var RuntimeGatewayIdempotencyConflictError, RuntimeGatewayTopicUnavailableError;
|
|
@@ -26669,8 +26777,10 @@ var init_submit_runtime_gateway_turn = __esm(async () => {
|
|
|
26669
26777
|
init_user_turn_envelope();
|
|
26670
26778
|
init_runtime_gateway();
|
|
26671
26779
|
await __promiseAll([
|
|
26780
|
+
init_ask_user(),
|
|
26672
26781
|
init_mcp_config(),
|
|
26673
26782
|
init_active_rooms(),
|
|
26783
|
+
init_turn_runner(),
|
|
26674
26784
|
init_api_messages(),
|
|
26675
26785
|
init_api_topics(),
|
|
26676
26786
|
init_forum_db(),
|
|
@@ -27080,6 +27190,7 @@ var init_topic_service = __esm(async () => {
|
|
|
27080
27190
|
init_request_vault(),
|
|
27081
27191
|
init_bus(),
|
|
27082
27192
|
init_active_rooms(),
|
|
27193
|
+
init_turn_runner(),
|
|
27083
27194
|
init_api_topics(),
|
|
27084
27195
|
init_runtime_leases(),
|
|
27085
27196
|
init_runtime_topic_state(),
|
|
@@ -27141,8 +27252,12 @@ var init_topic_service = __esm(async () => {
|
|
|
27141
27252
|
steerQueuedTurn(topicId, userId) {
|
|
27142
27253
|
participantTopic(topicId, userId);
|
|
27143
27254
|
const folded = foldQueuedIntoActiveRuntimeUserTurnRequest(topicId, randomUUID26());
|
|
27144
|
-
if (!folded)
|
|
27145
|
-
|
|
27255
|
+
if (!folded) {
|
|
27256
|
+
const queued = getRuntimeUserTurnRequest(topicId);
|
|
27257
|
+
if (queued?.status !== "pending")
|
|
27258
|
+
return false;
|
|
27259
|
+
return preemptSessionInjectForUserTurn(topicId);
|
|
27260
|
+
}
|
|
27146
27261
|
abortRoom(topicId, "internal" /* Internal */);
|
|
27147
27262
|
return true;
|
|
27148
27263
|
},
|
|
@@ -27324,6 +27439,11 @@ function holdOrSubmitRuntimeGatewayTurn(params) {
|
|
|
27324
27439
|
const alreadySent = findRuntimeGatewaySubmission(params.clientMessageId, requestId) !== null;
|
|
27325
27440
|
const waiting = listRuntimeFollowUps(topicId).length > 0;
|
|
27326
27441
|
const paused = areRuntimeFollowUpsPaused(topicId);
|
|
27442
|
+
if (!alreadySent) {
|
|
27443
|
+
const answered = answerOpenAskWithMessage(params);
|
|
27444
|
+
if (answered)
|
|
27445
|
+
return { held: false, submission: answered };
|
|
27446
|
+
}
|
|
27327
27447
|
const holdable = !alreadySent && params.respond !== false && params.silent !== true;
|
|
27328
27448
|
if (holdable && (isRoomWorking(topicId) || waiting && !paused)) {
|
|
27329
27449
|
const { topic: _topic, text, ...rest } = params;
|
|
@@ -49959,11 +50079,22 @@ class TerminalApp {
|
|
|
49959
50079
|
}
|
|
49960
50080
|
this.#queueRender();
|
|
49961
50081
|
}
|
|
50082
|
+
#restoreActivity(topicId, optimisticQueryId, previous) {
|
|
50083
|
+
if (this.#state.activity[topicId]?.queryId !== optimisticQueryId)
|
|
50084
|
+
return;
|
|
50085
|
+
const activity = { ...this.#state.activity };
|
|
50086
|
+
if (previous)
|
|
50087
|
+
activity[topicId] = previous;
|
|
50088
|
+
else
|
|
50089
|
+
delete activity[topicId];
|
|
50090
|
+
this.#state = { ...this.#state, activity };
|
|
50091
|
+
}
|
|
49962
50092
|
async#steerQueued() {
|
|
49963
50093
|
const topic = activeTopic(this.#state);
|
|
49964
50094
|
if (!topic || (this.#state.queued[topic.id] ?? []).length === 0)
|
|
49965
50095
|
return;
|
|
49966
50096
|
const optimisticQueryId = `terminal-pending-${Date.now()}`;
|
|
50097
|
+
const previousActivity = this.#state.activity[topic.id];
|
|
49967
50098
|
this.#state = applyRuntimeEvent({ ...this.#state, scrollOffset: 0 }, {
|
|
49968
50099
|
type: "ai-status",
|
|
49969
50100
|
topicId: topic.id,
|
|
@@ -49981,31 +50112,15 @@ class TerminalApp {
|
|
|
49981
50112
|
this.#state = drainQueuedMessages(this.#state, topic.id, new Date().toISOString());
|
|
49982
50113
|
}
|
|
49983
50114
|
if (steered === false) {
|
|
49984
|
-
|
|
49985
|
-
this.#state = applyRuntimeEvent(this.#state, {
|
|
49986
|
-
type: "ai-status",
|
|
49987
|
-
topicId: topic.id,
|
|
49988
|
-
payload: { kind: "ai_aborted", queryId: optimisticQueryId }
|
|
49989
|
-
});
|
|
49990
|
-
}
|
|
50115
|
+
this.#restoreActivity(topic.id, optimisticQueryId, previousActivity);
|
|
49991
50116
|
this.#state = {
|
|
49992
50117
|
...this.#state,
|
|
49993
|
-
notice: "Nothing to steer
|
|
50118
|
+
notice: "Nothing to steer.",
|
|
49994
50119
|
noticeLevel: "info"
|
|
49995
50120
|
};
|
|
49996
50121
|
}
|
|
49997
50122
|
} catch (error) {
|
|
49998
|
-
|
|
49999
|
-
this.#state = applyRuntimeEvent(this.#state, {
|
|
50000
|
-
type: "ai-status",
|
|
50001
|
-
topicId: topic.id,
|
|
50002
|
-
payload: {
|
|
50003
|
-
kind: "ai_error",
|
|
50004
|
-
queryId: optimisticQueryId,
|
|
50005
|
-
error: "Steer failed"
|
|
50006
|
-
}
|
|
50007
|
-
});
|
|
50008
|
-
}
|
|
50123
|
+
this.#restoreActivity(topic.id, optimisticQueryId, previousActivity);
|
|
50009
50124
|
this.#state = {
|
|
50010
50125
|
...this.#state,
|
|
50011
50126
|
notice: error instanceof Error ? error.message : String(error),
|
|
@@ -61222,4 +61337,4 @@ switch (command) {
|
|
|
61222
61337
|
}
|
|
61223
61338
|
}
|
|
61224
61339
|
|
|
61225
|
-
//# debugId=
|
|
61340
|
+
//# debugId=36D8D1C0A0825AED64756E2164756E21
|