@otium-team/negotium 0.23.15 → 0.24.1
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 +969 -245
- package/dist/agent-helpers.js.map +13 -10
- package/dist/{chunk-ng13grfj.js → chunk-fzfzskjq.js} +18 -2
- package/dist/{chunk-ng13grfj.js.map → chunk-fzfzskjq.js.map} +4 -4
- package/dist/{chunk-m1ngkjdd.js → chunk-hn2cqdd0.js} +1 -1
- package/dist/{chunk-3hf8y6bd.js → chunk-kfckfff2.js} +3 -3
- package/dist/{chunk-3hf8y6bd.js.map → chunk-kfckfff2.js.map} +2 -2
- package/dist/hosted-agent.js +19 -3
- package/dist/hosted-agent.js.map +5 -5
- package/dist/main.js +3744 -2928
- package/dist/main.js.map +18 -15
- package/dist/mcp-factories.js +959 -229
- package/dist/mcp-factories.js.map +14 -11
- package/dist/prompts.js +221 -1
- package/dist/prompts.js.map +7 -5
- 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 +71 -0
- package/dist/runtime/src/application/turn-follow-ups.ts +7 -0
- package/dist/runtime/src/mcp/wiki-server.ts +8 -0
- package/dist/runtime/src/platform/mcp-config.ts +26 -0
- package/dist/runtime/src/prompts/builders.ts +5 -0
- package/dist/runtime/src/runtime/turn-runner.ts +65 -1
- package/dist/runtime/src/storage/api-topics.ts +29 -0
- package/dist/runtime/src/topics/agent-plugins/mcp.schema.json +120 -0
- package/dist/runtime/src/topics/agent-plugins/plugin.schema.json +65 -0
- package/dist/runtime/src/topics/plugin-server-instructions.ts +201 -0
- package/dist/runtime/src/topics/plugin-turn.ts +37 -0
- package/dist/runtime/src/topics/plugins.ts +445 -0
- package/dist/runtime/src/topics/update.ts +34 -0
- package/dist/runtime/src/types/api.ts +5 -0
- package/dist/runtime/src/version.ts +1 -1
- package/dist/storage.js +23 -2
- package/dist/storage.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/mcp-config.d.ts +6 -0
- package/dist/types/packages/core/src/prompts/builders.d.ts +3 -0
- package/dist/types/packages/core/src/runtime/turn-runner.d.ts +14 -1
- package/dist/types/packages/core/src/storage/api-topics.d.ts +3 -0
- package/dist/types/packages/core/src/topics/plugin-server-instructions.d.ts +55 -0
- package/dist/types/packages/core/src/topics/plugin-turn.d.ts +17 -0
- package/dist/types/packages/core/src/topics/plugins.d.ts +66 -0
- package/dist/types/packages/core/src/types/api.d.ts +5 -0
- package/dist/types/packages/core/src/version.d.ts +1 -1
- package/package.json +1 -1
- /package/dist/{chunk-m1ngkjdd.js.map → chunk-hn2cqdd0.js.map} +0 -0
package/dist/registry.js
CHANGED
|
@@ -13,11 +13,11 @@ import {
|
|
|
13
13
|
extractChatPairs2,
|
|
14
14
|
hostedCodexHomePath,
|
|
15
15
|
writeCodexRollout2
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-fzfzskjq.js";
|
|
17
17
|
import {
|
|
18
18
|
encodeClaudeCwd2,
|
|
19
19
|
writeClaudeRollout2
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-hn2cqdd0.js";
|
|
21
21
|
|
|
22
22
|
// ../../packages/core/src/agents/claude-registry.ts
|
|
23
23
|
import { existsSync, mkdirSync, readdirSync, renameSync, unlinkSync } from "fs";
|
|
@@ -133,7 +133,7 @@ var codexRegistryOperations = {
|
|
|
133
133
|
return { sessionId: threadId, rolloutPath };
|
|
134
134
|
},
|
|
135
135
|
async forkSession({ parentSessionId }) {
|
|
136
|
-
const { forkCodexSession } = await import("./chunk-
|
|
136
|
+
const { forkCodexSession } = await import("./chunk-kfckfff2.js");
|
|
137
137
|
return await forkCodexSession(parentSessionId);
|
|
138
138
|
},
|
|
139
139
|
async cleanupRollouts({ sessionIds }) {
|
package/dist/rollout.js
CHANGED
|
@@ -11,12 +11,12 @@ import {
|
|
|
11
11
|
migrateCodexRolloutNativeMultiAgentMetadata2,
|
|
12
12
|
writeCodexRollout2,
|
|
13
13
|
decodeUuidV7Timestamp2
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-fzfzskjq.js";
|
|
15
15
|
import {
|
|
16
16
|
encodeClaudeCwd2,
|
|
17
17
|
writeClaudeRollout2,
|
|
18
18
|
repairPoisonedRollout2
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-hn2cqdd0.js";
|
|
20
20
|
|
|
21
21
|
// src/rollout.ts
|
|
22
22
|
import { fileURLToPath } from "url";
|
|
@@ -44,6 +44,20 @@ const MAX_CUSTOM_ANSWER_CHARS = 2000;
|
|
|
44
44
|
export type AskUserAnswerKind = "custom" | "skip";
|
|
45
45
|
export interface AnswerAskUserQuestionOptions {
|
|
46
46
|
kind?: AskUserAnswerKind;
|
|
47
|
+
/**
|
|
48
|
+
* Who and what the recorded answer message stands in for. A chat message
|
|
49
|
+
* that answers the card keeps its own author and source ids, so the host
|
|
50
|
+
* that sent it recognises the answer as its message.
|
|
51
|
+
*/
|
|
52
|
+
answerMessage?: Partial<
|
|
53
|
+
Pick<MessageDto, "authorId" | "authorName" | "sourceAdapter" | "sourceMessageId">
|
|
54
|
+
>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface OpenQuestionAnswerOptions {
|
|
58
|
+
/** The flow the message was typed in; a card is answered from the flow it sits in. */
|
|
59
|
+
threadRootId?: string;
|
|
60
|
+
answerMessage?: AnswerAskUserQuestionOptions["answerMessage"];
|
|
47
61
|
}
|
|
48
62
|
|
|
49
63
|
export interface AskUserToolContext {
|
|
@@ -139,6 +153,12 @@ export interface AskUserRuntime {
|
|
|
139
153
|
userId: string,
|
|
140
154
|
options?: AnswerAskUserQuestionOptions,
|
|
141
155
|
): AnswerAskUserQuestionResult;
|
|
156
|
+
answerOpenQuestionWithText(
|
|
157
|
+
topicId: string,
|
|
158
|
+
text: string,
|
|
159
|
+
userId: string,
|
|
160
|
+
options?: OpenQuestionAnswerOptions,
|
|
161
|
+
): AnswerAskUserQuestionResult | null;
|
|
142
162
|
cancelPendingQuestions(topicId: string, queryId: string): void;
|
|
143
163
|
createToolDefinition(ctx: AskUserToolContext): SharedMcpTool;
|
|
144
164
|
}
|
|
@@ -206,7 +226,7 @@ function answerToolResult(answer: AskUserAnswer) {
|
|
|
206
226
|
}
|
|
207
227
|
if (answer.kind === "custom") {
|
|
208
228
|
return textResult(
|
|
209
|
-
`
|
|
229
|
+
`The user did not pick a listed option. They typed this reply in the chat instead: "${answer.label}"\nTreat 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.`,
|
|
210
230
|
);
|
|
211
231
|
}
|
|
212
232
|
const description = answer.description ? `\nDescription: ${answer.description}` : "";
|
|
@@ -328,6 +348,7 @@ export function createAskUserRuntime(host: AskUserRuntimeHost): AskUserRuntime {
|
|
|
328
348
|
id: createId(),
|
|
329
349
|
topicId,
|
|
330
350
|
authorId: userId,
|
|
351
|
+
...options.answerMessage,
|
|
331
352
|
text: label,
|
|
332
353
|
parentId: messageId,
|
|
333
354
|
// Follow the card rather than the caller: whoever clicks the button is
|
|
@@ -352,6 +373,29 @@ export function createAskUserRuntime(host: AskUserRuntimeHost): AskUserRuntime {
|
|
|
352
373
|
return { ok: true, queryId: pending.queryId, answerMessage };
|
|
353
374
|
}
|
|
354
375
|
|
|
376
|
+
/**
|
|
377
|
+
* A chat message typed while a card of the running turn is still open
|
|
378
|
+
* answers that card in the user's own words. Null when no card is open in
|
|
379
|
+
* this flow, so the message goes the usual way.
|
|
380
|
+
*/
|
|
381
|
+
function answerOpenQuestionWithText(
|
|
382
|
+
topicId: string,
|
|
383
|
+
text: string,
|
|
384
|
+
userId: string,
|
|
385
|
+
options: OpenQuestionAnswerOptions = {},
|
|
386
|
+
): AnswerAskUserQuestionResult | null {
|
|
387
|
+
for (const [messageId, pending] of pendingAsks) {
|
|
388
|
+
if (pending.topicId !== topicId) continue;
|
|
389
|
+
const card = host.messaging.persistence.getMessage(topicId, messageId);
|
|
390
|
+
if ((card?.threadRootId ?? undefined) !== (options.threadRootId ?? undefined)) continue;
|
|
391
|
+
return answerPendingQuestion(topicId, messageId, text, userId, {
|
|
392
|
+
kind: "custom",
|
|
393
|
+
...(options.answerMessage ? { answerMessage: options.answerMessage } : {}),
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
return null;
|
|
397
|
+
}
|
|
398
|
+
|
|
355
399
|
function cancelPendingQuestions(topicId: string, queryId: string): void {
|
|
356
400
|
for (const [messageId, pending] of pendingAsks) {
|
|
357
401
|
if (pending.topicId === topicId && pending.queryId === queryId) {
|
|
@@ -551,6 +595,7 @@ export function createAskUserRuntime(host: AskUserRuntimeHost): AskUserRuntime {
|
|
|
551
595
|
reconcilePendingGates,
|
|
552
596
|
hasPendingQuestion,
|
|
553
597
|
answerPendingQuestion,
|
|
598
|
+
answerOpenQuestionWithText,
|
|
554
599
|
cancelPendingQuestions,
|
|
555
600
|
createToolDefinition,
|
|
556
601
|
};
|
|
@@ -644,6 +689,16 @@ export function answerPendingAskUserQuestion(
|
|
|
644
689
|
return defaultAskUserRuntime.answerPendingQuestion(topicId, messageId, label, userId, options);
|
|
645
690
|
}
|
|
646
691
|
|
|
692
|
+
/** Settle the open ask card of this room's running turn with a typed chat message. */
|
|
693
|
+
export function answerOpenAskUserQuestionWithText(
|
|
694
|
+
topicId: string,
|
|
695
|
+
text: string,
|
|
696
|
+
userId: string,
|
|
697
|
+
options?: OpenQuestionAnswerOptions,
|
|
698
|
+
): AnswerAskUserQuestionResult | null {
|
|
699
|
+
return defaultAskUserRuntime.answerOpenQuestionWithText(topicId, text, userId, options);
|
|
700
|
+
}
|
|
701
|
+
|
|
647
702
|
export function cancelPendingAskUserQuestions(topicId: string, queryId: string): void {
|
|
648
703
|
defaultAskUserRuntime.cancelPendingQuestions(topicId, queryId);
|
|
649
704
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import { answerOpenAskUserQuestionWithText } from "#agents/mcp-tools/ask-user";
|
|
2
3
|
import { hostMcpGrantRefusal, isReservedRuntimeMcpServerName } from "#platform/mcp-config";
|
|
3
4
|
import { abortRoom, getRoomQuery } from "#query/active-rooms";
|
|
4
5
|
import { AbortReason } from "#query/types";
|
|
@@ -246,6 +247,73 @@ export class RuntimeGatewayTopicUnavailableError extends Error {
|
|
|
246
247
|
}
|
|
247
248
|
}
|
|
248
249
|
|
|
250
|
+
/**
|
|
251
|
+
* A message typed while the running turn waits on an `ask_user_question` card
|
|
252
|
+
* in the same flow is that card's answer, in the person's own words. Queuing it
|
|
253
|
+
* as a turn would leave it behind the card until the card times out, with the
|
|
254
|
+
* room looking frozen. Plain text only: a message with attachments, a quote, or
|
|
255
|
+
* no AI response keeps the normal path, as does a sender who may not answer the
|
|
256
|
+
* card (the same participant rule as pressing a button). Null means "not an
|
|
257
|
+
* answer"; the caller carries on as before.
|
|
258
|
+
*/
|
|
259
|
+
export function answerOpenAskWithMessage(
|
|
260
|
+
params: SubmitRuntimeGatewayTurnParams,
|
|
261
|
+
): SubmitRuntimeGatewayTurnResult | null {
|
|
262
|
+
const text = params.text.trim();
|
|
263
|
+
if (
|
|
264
|
+
!text ||
|
|
265
|
+
params.respond === false ||
|
|
266
|
+
params.silent === true ||
|
|
267
|
+
params.parentId ||
|
|
268
|
+
params.attachments?.length ||
|
|
269
|
+
isTopicClaimAbortFenced(params.topic.id)
|
|
270
|
+
) {
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
const requestId = params.requestId ?? params.clientMessageId;
|
|
274
|
+
const actorUserId = params.actorUserId ?? params.userId;
|
|
275
|
+
const sourceAdapter = params.sourceAdapter?.trim() || "runtime-gateway";
|
|
276
|
+
const answered = answerOpenAskUserQuestionWithText(params.topic.id, text, params.userId, {
|
|
277
|
+
...(params.threadRootId ? { threadRootId: params.threadRootId } : {}),
|
|
278
|
+
answerMessage: {
|
|
279
|
+
authorId: actorUserId,
|
|
280
|
+
...(params.actorLabel ? { authorName: params.actorLabel } : {}),
|
|
281
|
+
sourceAdapter,
|
|
282
|
+
sourceMessageId: params.clientMessageId,
|
|
283
|
+
},
|
|
284
|
+
});
|
|
285
|
+
if (!answered?.ok) return null;
|
|
286
|
+
|
|
287
|
+
const message = answered.answerMessage;
|
|
288
|
+
const submission: RuntimeGatewaySubmission = {
|
|
289
|
+
clientMessageId: params.clientMessageId,
|
|
290
|
+
requestId,
|
|
291
|
+
topicId: params.topic.id,
|
|
292
|
+
messageId: message.id,
|
|
293
|
+
userId: params.userId,
|
|
294
|
+
createdAt: message.createdAt,
|
|
295
|
+
ackCursor: 0,
|
|
296
|
+
messageCursor: 0,
|
|
297
|
+
payloadHash: gatewayPayloadHash(params, requestId, actorUserId),
|
|
298
|
+
};
|
|
299
|
+
db.transaction(() => {
|
|
300
|
+
const acceptedEvent = appendRuntimeEvent("runtime-gateway-ingress", {
|
|
301
|
+
type: "ai-status",
|
|
302
|
+
topicId: params.topic.id,
|
|
303
|
+
payload: {
|
|
304
|
+
kind: "turn_accepted",
|
|
305
|
+
requestId,
|
|
306
|
+
clientMessageId: params.clientMessageId,
|
|
307
|
+
messageId: message.id,
|
|
308
|
+
delivery: "answered",
|
|
309
|
+
},
|
|
310
|
+
});
|
|
311
|
+
submission.ackCursor = acceptedEvent.seq;
|
|
312
|
+
recordRuntimeGatewaySubmission(submission);
|
|
313
|
+
})();
|
|
314
|
+
return { ...submission, message, deduplicated: false };
|
|
315
|
+
}
|
|
316
|
+
|
|
249
317
|
export function submitRuntimeGatewayTurn(
|
|
250
318
|
params: SubmitRuntimeGatewayTurnParams,
|
|
251
319
|
): SubmitRuntimeGatewayTurnResult {
|
|
@@ -276,6 +344,9 @@ export function submitRuntimeGatewayTurn(
|
|
|
276
344
|
// atomically, by the `api_messages` trigger inside the transaction below.
|
|
277
345
|
if (isTopicClaimAbortFenced(params.topic.id)) throw new RuntimeGatewayTopicUnavailableError();
|
|
278
346
|
|
|
347
|
+
const answeredAsk = answerOpenAskWithMessage(params);
|
|
348
|
+
if (answeredAsk) return answeredAsk;
|
|
349
|
+
|
|
279
350
|
// Remember what this adapter grants for the room, so the turns that never
|
|
280
351
|
// see an adapter — tell/ask, cron, auto-continue, subagent reports — inherit
|
|
281
352
|
// it instead of silently running without the tools.
|
|
@@ -36,6 +36,7 @@ import { isRuntimeTopicMaintenance } from "#storage/runtime-topic-state";
|
|
|
36
36
|
import { getRuntimeUserTurnRequest } from "#storage/runtime-turn-requests";
|
|
37
37
|
import type { AttachmentDto } from "#types/api";
|
|
38
38
|
import {
|
|
39
|
+
answerOpenAskWithMessage,
|
|
39
40
|
type SubmitRuntimeGatewayTurnParams,
|
|
40
41
|
type SubmitRuntimeGatewayTurnResult,
|
|
41
42
|
submitRuntimeGatewayTurn,
|
|
@@ -116,6 +117,12 @@ export function holdOrSubmitRuntimeGatewayTurn(
|
|
|
116
117
|
const alreadySent = findRuntimeGatewaySubmission(params.clientMessageId, requestId) !== null;
|
|
117
118
|
const waiting = listRuntimeFollowUps(topicId).length > 0;
|
|
118
119
|
const paused = areRuntimeFollowUpsPaused(topicId);
|
|
120
|
+
// An open question is waiting for exactly this: answer it instead of holding
|
|
121
|
+
// the message behind the question until the question times out.
|
|
122
|
+
if (!alreadySent) {
|
|
123
|
+
const answered = answerOpenAskWithMessage(params);
|
|
124
|
+
if (answered) return { held: false, submission: answered };
|
|
125
|
+
}
|
|
119
126
|
const holdable = !alreadySent && params.respond !== false && params.silent !== true;
|
|
120
127
|
if (holdable && (isRoomWorking(topicId) || (waiting && !paused))) {
|
|
121
128
|
const { topic: _topic, text, ...rest } = params;
|
|
@@ -1515,7 +1515,15 @@ function skillSave(args: Record<string, unknown>): CallToolResult {
|
|
|
1515
1515
|
return `${target.trimEnd()}\n\n## Gotchas\n${fresh.join("\n")}\n`;
|
|
1516
1516
|
}
|
|
1517
1517
|
|
|
1518
|
+
// A name that is a path (`../x`, `/abs/dir`) would write outside the skill
|
|
1519
|
+
// library, anywhere the node can write.
|
|
1518
1520
|
const skillDir = resolve(runtime().skillsDir, name);
|
|
1521
|
+
if (dirname(skillDir) !== resolve(runtime().skillsDir) || name !== basename(skillDir)) {
|
|
1522
|
+
return {
|
|
1523
|
+
content: [{ type: "text", text: "Skill name must be a single folder name." }],
|
|
1524
|
+
isError: true,
|
|
1525
|
+
};
|
|
1526
|
+
}
|
|
1519
1527
|
ensureDir(skillDir);
|
|
1520
1528
|
const skillPath = resolve(skillDir, "skill.md");
|
|
1521
1529
|
|
|
@@ -875,6 +875,32 @@ export function hostMcpGrantRefusal(
|
|
|
875
875
|
return managerOnly ? `${managerOnly} is only allowed for manager topics` : null;
|
|
876
876
|
}
|
|
877
877
|
|
|
878
|
+
/**
|
|
879
|
+
* Why servers from a room's plugins (their root `mcp.json`) may not join its
|
|
880
|
+
* turns, or null when they may. They take the checks host grants get, and must not
|
|
881
|
+
* share a name with the host's own servers for the room.
|
|
882
|
+
*/
|
|
883
|
+
export function pluginMcpRefusal(
|
|
884
|
+
topic: Pick<TopicDto, "kind" | "isSubagent">,
|
|
885
|
+
names: readonly string[],
|
|
886
|
+
hostNames: readonly string[] = [],
|
|
887
|
+
): string | null {
|
|
888
|
+
if (names.length > 0 && topic.isSubagent)
|
|
889
|
+
return "plugin servers are not allowed for subagent topics";
|
|
890
|
+
for (const name of names) {
|
|
891
|
+
if (isReservedRuntimeMcpServerName(name)) {
|
|
892
|
+
return `plugin MCP server name conflicts with node catalog: ${name}`;
|
|
893
|
+
}
|
|
894
|
+
if (topic.kind !== "manager" && MANAGER_ONLY_HOST_MCP_NAMES.has(name)) {
|
|
895
|
+
return `${name} is only allowed for manager topics`;
|
|
896
|
+
}
|
|
897
|
+
if (hostNames.includes(name)) {
|
|
898
|
+
return `plugin MCP server name conflicts with a host MCP server: ${name}`;
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
return null;
|
|
902
|
+
}
|
|
903
|
+
|
|
878
904
|
function withoutManagerOnlyHostMcpServers(
|
|
879
905
|
hostMcpServers: Record<string, HostMcpServerSpec> | undefined,
|
|
880
906
|
): Record<string, HostMcpServerSpec> | undefined {
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
resolveOutputLanguage,
|
|
15
15
|
} from "#platform/config";
|
|
16
16
|
import { logger } from "#platform/logger";
|
|
17
|
+
import { renderTopicPluginsPrompt, type TopicPlugin } from "#topics/plugins";
|
|
17
18
|
import type { AgentKind, EffortLevel } from "#types";
|
|
18
19
|
import type { SubagentReportMode, TopicSurface } from "#types/api";
|
|
19
20
|
|
|
@@ -233,6 +234,8 @@ export interface SessionSystemPromptOpts {
|
|
|
233
234
|
visualTools?: boolean;
|
|
234
235
|
/** True only when the current adapter can deliver files to its chat. */
|
|
235
236
|
fileDeliveryTools?: boolean;
|
|
237
|
+
/** The room's plugins (`#topics/plugins`): their rules and skills follow the topic's own instructions. */
|
|
238
|
+
plugins?: readonly TopicPlugin[];
|
|
236
239
|
}
|
|
237
240
|
|
|
238
241
|
export type SessionPromptKind = "topic" | "channel" | "manager";
|
|
@@ -603,6 +606,8 @@ export function createPromptBuilders(host: PromptBuilderHost = {}): PromptBuilde
|
|
|
603
606
|
if (sessionKind !== "channel" && opts.description?.trim()) {
|
|
604
607
|
prompt += `\n\n## Topic-Specific Instructions\n${opts.description.trim()}`;
|
|
605
608
|
}
|
|
609
|
+
const plugins = renderTopicPluginsPrompt(opts.plugins ?? []);
|
|
610
|
+
if (plugins) prompt += `\n\n${plugins}`;
|
|
606
611
|
if (sessionKind === "manager") {
|
|
607
612
|
// Substitute the same vars so a host manager template using placeholders
|
|
608
613
|
// like {{RESPONSE_LANGUAGE}} never reaches the model unresolved.
|
|
@@ -80,6 +80,7 @@ import {
|
|
|
80
80
|
} from "#runtime/user-turn-envelope";
|
|
81
81
|
import { getActiveVisualForPrompt } from "#runtime/visual-store";
|
|
82
82
|
import { activeVisualHtmlForPrompt } from "#runtime/visuals";
|
|
83
|
+
import type { HostMcpServerSpec } from "#runtime-gateway";
|
|
83
84
|
import { appendApiMessage, getApiMessage } from "#storage/api-messages";
|
|
84
85
|
import { resolveTopicBrief } from "#storage/api-topic-brief";
|
|
85
86
|
import {
|
|
@@ -120,6 +121,12 @@ import {
|
|
|
120
121
|
wikiSummaryFilename,
|
|
121
122
|
} from "#storage/wiki-summary-names";
|
|
122
123
|
import { getTopics } from "#topics/derive";
|
|
124
|
+
import {
|
|
125
|
+
fetchMcpServerInstructions,
|
|
126
|
+
renderMcpServerInstructions,
|
|
127
|
+
} from "#topics/plugin-server-instructions";
|
|
128
|
+
import { resolveTopicPluginTurn } from "#topics/plugin-turn";
|
|
129
|
+
import type { TopicPlugin } from "#topics/plugins";
|
|
123
130
|
import type {
|
|
124
131
|
ActorTopicScope,
|
|
125
132
|
AgentKind,
|
|
@@ -789,6 +796,44 @@ export function resolveTurnHostMcpServers(
|
|
|
789
796
|
return getTopicHostMcpGrant(topic.id) ?? undefined;
|
|
790
797
|
}
|
|
791
798
|
|
|
799
|
+
/**
|
|
800
|
+
* The room's plugins for this turn, under the same scope rule as its host
|
|
801
|
+
* grant: the plugins, the servers they add, and the turn's host servers with
|
|
802
|
+
* those added. Broken plugins or unusable servers are logged and left out,
|
|
803
|
+
* never thrown.
|
|
804
|
+
*/
|
|
805
|
+
export function resolveTurnPlugins(
|
|
806
|
+
topic: Pick<TopicDto, "id" | "kind" | "isSubagent">,
|
|
807
|
+
sessionType: "dm" | "forum" | "ephemeral" | "manager" | "cron" | undefined,
|
|
808
|
+
hostMcpServers: Record<string, HostMcpServerSpec> | undefined,
|
|
809
|
+
): {
|
|
810
|
+
plugins: readonly TopicPlugin[];
|
|
811
|
+
pluginMcpServers: Record<string, HostMcpServerSpec>;
|
|
812
|
+
hostMcpServers: Record<string, HostMcpServerSpec> | undefined;
|
|
813
|
+
} {
|
|
814
|
+
const ownScope = topic.kind === "manager" ? "manager" : "forum";
|
|
815
|
+
const stored = getTopic(topic.id);
|
|
816
|
+
if (!stored?.plugins?.length || (sessionType ?? ownScope) !== ownScope) {
|
|
817
|
+
return { plugins: [], pluginMcpServers: {}, hostMcpServers };
|
|
818
|
+
}
|
|
819
|
+
const turn = resolveTopicPluginTurn(stored, Object.keys(hostMcpServers ?? {}));
|
|
820
|
+
const problems = [...turn.loadProblems, ...turn.serverProblems];
|
|
821
|
+
if (problems.length > 0) {
|
|
822
|
+
logger.warn(
|
|
823
|
+
{ topicId: topic.id, problems },
|
|
824
|
+
"ai: topic plugins partly or wholly left out of the turn",
|
|
825
|
+
);
|
|
826
|
+
}
|
|
827
|
+
return {
|
|
828
|
+
plugins: turn.plugins,
|
|
829
|
+
pluginMcpServers: turn.mcpServers,
|
|
830
|
+
hostMcpServers:
|
|
831
|
+
Object.keys(turn.mcpServers).length > 0
|
|
832
|
+
? { ...hostMcpServers, ...turn.mcpServers }
|
|
833
|
+
: hostMcpServers,
|
|
834
|
+
};
|
|
835
|
+
}
|
|
836
|
+
|
|
792
837
|
export interface StartAiTurnParams extends AiTurnExecutionOptions {
|
|
793
838
|
topic: AiTurnTopic;
|
|
794
839
|
userId: string;
|
|
@@ -1159,7 +1204,11 @@ export function startAiTurn(params: StartAiTurnParams): string | null {
|
|
|
1159
1204
|
const sessionName = params.sessionName ?? topic.title;
|
|
1160
1205
|
const sessionType = params.sessionType;
|
|
1161
1206
|
const { visualTools, fileDeliveryTools } = resolveTurnToolCapabilities(topicId, params);
|
|
1162
|
-
const hostMcpServers =
|
|
1207
|
+
const { plugins, pluginMcpServers, hostMcpServers } = resolveTurnPlugins(
|
|
1208
|
+
topic,
|
|
1209
|
+
sessionType,
|
|
1210
|
+
resolveTurnHostMcpServers(topic, sessionType),
|
|
1211
|
+
);
|
|
1163
1212
|
const onSessionId = params.onSessionId;
|
|
1164
1213
|
const onSessionReset = params.onSessionReset;
|
|
1165
1214
|
const bridgeSessionFromHistory = params.bridgeSessionFromHistory === true;
|
|
@@ -1658,6 +1707,7 @@ export function startAiTurn(params: StartAiTurnParams): string | null {
|
|
|
1658
1707
|
subagentReportMode: topicRecord?.isSubagent ? subagentReportMode(topicId) : undefined,
|
|
1659
1708
|
visualTools,
|
|
1660
1709
|
fileDeliveryTools,
|
|
1710
|
+
plugins,
|
|
1661
1711
|
};
|
|
1662
1712
|
const isManager = topicRecord?.kind === "manager";
|
|
1663
1713
|
const isMentionOnlyChannel = topic.aiMode === "mention" && !isManager;
|
|
@@ -1886,6 +1936,20 @@ export function startAiTurn(params: StartAiTurnParams): string | null {
|
|
|
1886
1936
|
"<system-reminder>Playwright browser tools are UNAVAILABLE this turn. The `mcp__playwright__*` tools have been removed from this turn's catalog because the long-lived browser MCP could not be prepared. Do not attempt to call browser tools. If browser interaction is required, ask the user to retry shortly or use a non-browser alternative.</system-reminder>",
|
|
1887
1937
|
);
|
|
1888
1938
|
}
|
|
1939
|
+
if (Object.keys(pluginMcpServers).length > 0) {
|
|
1940
|
+
const fetched = await fetchMcpServerInstructions(pluginMcpServers, {
|
|
1941
|
+
signal: abortController.signal,
|
|
1942
|
+
});
|
|
1943
|
+
if (abortController.signal.aborted) return;
|
|
1944
|
+
const { section, problems } = renderMcpServerInstructions(fetched.instructions);
|
|
1945
|
+
if (fetched.problems.length + problems.length > 0) {
|
|
1946
|
+
logger.warn(
|
|
1947
|
+
{ topicId, problems: [...fetched.problems, ...problems] },
|
|
1948
|
+
"ai: plugin server instructions cut or left out of the turn",
|
|
1949
|
+
);
|
|
1950
|
+
}
|
|
1951
|
+
if (section) systemPrompt += `\n\n${section}`;
|
|
1952
|
+
}
|
|
1889
1953
|
// Build this after conversation recording: transient runtime facts must be
|
|
1890
1954
|
// supplied again by the host on a later external turn, never resumed from
|
|
1891
1955
|
// Negotium's canonical conversation state.
|
|
@@ -320,6 +320,7 @@ function initializeApiTopicsSchema(): void {
|
|
|
320
320
|
browser_profile TEXT NOT NULL DEFAULT 'default',
|
|
321
321
|
browser_profile_owner TEXT,
|
|
322
322
|
browser_connect_port INTEGER,
|
|
323
|
+
plugins_json TEXT,
|
|
323
324
|
session_id TEXT,
|
|
324
325
|
CHECK (
|
|
325
326
|
(kind = 'channel' AND response_policy = 'off' AND agent IS NULL) OR
|
|
@@ -497,6 +498,11 @@ function initializeApiTopicsSchema(): void {
|
|
|
497
498
|
if (!tableColumns("api_topics").has("browser_connect_port")) {
|
|
498
499
|
db.exec("ALTER TABLE api_topics ADD COLUMN browser_connect_port INTEGER");
|
|
499
500
|
}
|
|
501
|
+
if (!tableColumns("api_topics").has("plugins_json")) {
|
|
502
|
+
db.exec("ALTER TABLE api_topics ADD COLUMN plugins_json TEXT");
|
|
503
|
+
}
|
|
504
|
+
// Plugin url placeholders were removed; a node that ran them kept credential-bearing values here.
|
|
505
|
+
db.exec("DROP TABLE IF EXISTS api_topic_plugin_variables");
|
|
500
506
|
if (!tableColumns("api_topics").has("subagent_report_mode")) {
|
|
501
507
|
db.exec("ALTER TABLE api_topics ADD COLUMN subagent_report_mode TEXT NOT NULL DEFAULT 'auto'");
|
|
502
508
|
}
|
|
@@ -912,6 +918,7 @@ export interface TopicRow {
|
|
|
912
918
|
surface_scope: string | null;
|
|
913
919
|
browser_profile_owner: string | null;
|
|
914
920
|
browser_connect_port: number | null;
|
|
921
|
+
plugins_json?: string | null;
|
|
915
922
|
session_id: string | null;
|
|
916
923
|
}
|
|
917
924
|
|
|
@@ -1013,9 +1020,31 @@ function rowToDto(
|
|
|
1013
1020
|
surface: normalizeTopicSurface(r.surface),
|
|
1014
1021
|
surfaceScope: normalizeSurfaceScope(r.surface_scope),
|
|
1015
1022
|
...(r.browser_connect_port != null ? { browserConnectPort: r.browser_connect_port } : {}),
|
|
1023
|
+
...pluginsField(r.plugins_json),
|
|
1016
1024
|
};
|
|
1017
1025
|
}
|
|
1018
1026
|
|
|
1027
|
+
/** A stored plugin list that does not parse reads as none: fail closed. */
|
|
1028
|
+
function pluginsField(json: string | null | undefined): { plugins?: string[] } {
|
|
1029
|
+
if (!json) return {};
|
|
1030
|
+
try {
|
|
1031
|
+
const plugins: unknown = JSON.parse(json);
|
|
1032
|
+
return Array.isArray(plugins) && plugins.every((dir) => typeof dir === "string")
|
|
1033
|
+
? { plugins }
|
|
1034
|
+
: {};
|
|
1035
|
+
} catch {
|
|
1036
|
+
return {};
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
/** The room's plugin folders; an empty list or `null` removes them all. */
|
|
1041
|
+
export function setTopicPlugins(topicId: string, plugins: readonly string[] | null): void {
|
|
1042
|
+
db.query("UPDATE api_topics SET plugins_json = ? WHERE id = ?").run(
|
|
1043
|
+
plugins?.length ? JSON.stringify(plugins) : null,
|
|
1044
|
+
topicId,
|
|
1045
|
+
);
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1019
1048
|
export function normalizeTopicVisibility(value: unknown): TopicVisibility {
|
|
1020
1049
|
return value === "hidden" ? "hidden" : "visible";
|
|
1021
1050
|
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://agent-plugins.org/schemas/1.0.0/mcp.schema.json",
|
|
4
|
+
"title": "Agent Plugins MCP Configuration",
|
|
5
|
+
"description": "Machine-readable schema for mcp.json in Agent Plugins 1.0.0. The Agent Plugins specification defines additional semantic and operational requirements.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"$schema": {
|
|
9
|
+
"const": "https://agent-plugins.org/schemas/1.0.0/mcp.schema.json",
|
|
10
|
+
"description": "Canonical identifier of the MCP configuration schema for the Agent Plugins version targeted by this document."
|
|
11
|
+
},
|
|
12
|
+
"mcpServers": {
|
|
13
|
+
"type": "object",
|
|
14
|
+
"additionalProperties": {
|
|
15
|
+
"$ref": "#/$defs/server"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"required": ["$schema", "mcpServers"],
|
|
20
|
+
"additionalProperties": false,
|
|
21
|
+
"$defs": {
|
|
22
|
+
"server": {
|
|
23
|
+
"title": "MCP server",
|
|
24
|
+
"oneOf": [
|
|
25
|
+
{
|
|
26
|
+
"$ref": "#/$defs/stdioServer"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"$ref": "#/$defs/streamableHttpServer"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"$ref": "#/$defs/sseServer"
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
"stdioServer": {
|
|
37
|
+
"title": "stdio MCP server",
|
|
38
|
+
"type": "object",
|
|
39
|
+
"properties": {
|
|
40
|
+
"type": {
|
|
41
|
+
"const": "stdio"
|
|
42
|
+
},
|
|
43
|
+
"command": {
|
|
44
|
+
"type": "string",
|
|
45
|
+
"minLength": 1,
|
|
46
|
+
"description": "Executable token. Resolution rules are defined by the Agent Plugins specification."
|
|
47
|
+
},
|
|
48
|
+
"args": {
|
|
49
|
+
"type": "array",
|
|
50
|
+
"items": {
|
|
51
|
+
"type": "string"
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"env": {
|
|
55
|
+
"type": "object",
|
|
56
|
+
"propertyNames": {
|
|
57
|
+
"not": {
|
|
58
|
+
"enum": ["PLUGIN_ROOT", "PLUGIN_DATA"]
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"additionalProperties": {
|
|
62
|
+
"type": "string"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"cwd": {
|
|
66
|
+
"type": "string",
|
|
67
|
+
"pattern": "^(?:\\./|\\$\\{PLUGIN_ROOT\\}(?:/|$)|\\$\\{PLUGIN_DATA\\}(?:/|$))",
|
|
68
|
+
"description": "Plugin-relative, PLUGIN_ROOT-rooted, or PLUGIN_DATA-rooted working directory. Filesystem containment is validated separately."
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"required": ["type", "command"],
|
|
72
|
+
"additionalProperties": false
|
|
73
|
+
},
|
|
74
|
+
"streamableHttpServer": {
|
|
75
|
+
"title": "Streamable HTTP MCP server",
|
|
76
|
+
"type": "object",
|
|
77
|
+
"properties": {
|
|
78
|
+
"type": {
|
|
79
|
+
"const": "streamable-http"
|
|
80
|
+
},
|
|
81
|
+
"url": {
|
|
82
|
+
"type": "string",
|
|
83
|
+
"minLength": 1,
|
|
84
|
+
"description": "MCP endpoint URL. URL semantics are defined by the Agent Plugins specification."
|
|
85
|
+
},
|
|
86
|
+
"headers": {
|
|
87
|
+
"$ref": "#/$defs/headers"
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
"required": ["type", "url"],
|
|
91
|
+
"additionalProperties": false
|
|
92
|
+
},
|
|
93
|
+
"sseServer": {
|
|
94
|
+
"title": "Legacy HTTP+SSE MCP server",
|
|
95
|
+
"type": "object",
|
|
96
|
+
"properties": {
|
|
97
|
+
"type": {
|
|
98
|
+
"const": "sse"
|
|
99
|
+
},
|
|
100
|
+
"url": {
|
|
101
|
+
"type": "string",
|
|
102
|
+
"minLength": 1,
|
|
103
|
+
"description": "MCP endpoint URL. URL semantics are defined by the Agent Plugins specification."
|
|
104
|
+
},
|
|
105
|
+
"headers": {
|
|
106
|
+
"$ref": "#/$defs/headers"
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
"required": ["type", "url"],
|
|
110
|
+
"additionalProperties": false
|
|
111
|
+
},
|
|
112
|
+
"headers": {
|
|
113
|
+
"title": "HTTP headers",
|
|
114
|
+
"type": "object",
|
|
115
|
+
"additionalProperties": {
|
|
116
|
+
"type": "string"
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|