@coffer-org/plugin-orchestrator 2.2.1 → 2.3.0
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/index.js +1 -0
- package/dist/runtime/config.d.ts +1 -0
- package/dist/runtime/config.js +6 -0
- package/dist/runtime/index.d.ts +3 -2
- package/dist/runtime/index.js +2 -1
- package/dist/runtime/pipeline.d.ts +2 -3
- package/dist/runtime/pipeline.js +16 -6
- package/dist/runtime/registry.d.ts +8 -0
- package/dist/runtime/registry.js +44 -0
- package/dist/runtime/types.d.ts +52 -2
- package/dist/schema.js +4 -0
- package/package.json +3 -4
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export default definePlugin({
|
|
|
8
8
|
settings: defineSettings({
|
|
9
9
|
label: 'orchestrator.settings.label',
|
|
10
10
|
fields: [
|
|
11
|
+
field.select({ key: 'agent_id', label: 'orchestrator.settings.agent_id' }),
|
|
11
12
|
field.password({ key: 'access_password', label: 'orchestrator.settings.access_password' }),
|
|
12
13
|
field.string({ key: 'trigger_prefix', label: 'orchestrator.settings.trigger_prefix' }),
|
|
13
14
|
field.int({ key: 'reply_window', label: 'orchestrator.settings.reply_window', default: 1800 }),
|
package/dist/runtime/config.d.ts
CHANGED
package/dist/runtime/config.js
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
export function buildPolicy(dbSettings = {}) {
|
|
2
2
|
const db = dbSettings;
|
|
3
3
|
return {
|
|
4
|
+
...(typeof db.agent_id === 'string' && db.agent_id ? { agentId: db.agent_id } : {}),
|
|
4
5
|
accessPassword: db.access_password ?? '',
|
|
5
6
|
triggerPrefix: db.trigger_prefix ?? '',
|
|
6
7
|
replyWindow: Number(db.reply_window ?? 1800) || 1800,
|
|
7
8
|
};
|
|
8
9
|
}
|
|
10
|
+
export async function loadAgentId() {
|
|
11
|
+
const { getPluginSettings } = await import('@coffer-org/server/plugin-runtime');
|
|
12
|
+
const value = (await getPluginSettings('orchestrator'))['agent_id'];
|
|
13
|
+
return typeof value === 'string' && value ? value : undefined;
|
|
14
|
+
}
|
|
9
15
|
export async function loadGatePolicy() {
|
|
10
16
|
const { getPluginSettings } = await import('@coffer-org/server/plugin-runtime');
|
|
11
17
|
return buildPolicy(await getPluginSettings('orchestrator'));
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { PluginHooks } from '@coffer-org/server/plugin-hooks';
|
|
2
2
|
export { handleIncoming } from './pipeline.ts';
|
|
3
|
+
export { registerAgent, resolveAgent, registerConnector, isConnectorRegistered, clearRuntimeRegistries } from './registry.ts';
|
|
3
4
|
export { attachmentMaterializer } from './attachments.ts';
|
|
4
5
|
export { makeAttachmentCapabilities } from './agent-capabilities.ts';
|
|
5
6
|
export type { PipelineDeps, RunAgentFn } from './pipeline.ts';
|
|
6
|
-
export { buildPolicy, loadGatePolicy } from './config.ts';
|
|
7
|
+
export { buildPolicy, loadGatePolicy, loadAgentId } from './config.ts';
|
|
7
8
|
export { makeLiveChannel, plainRender } from './live-message.ts';
|
|
8
9
|
export type { LiveChannelOps, LiveChannelOpts, RenderFn } from './live-message.ts';
|
|
9
10
|
export { chunk } from './format.ts';
|
|
10
|
-
export type { Connector, IncomingConversation, GatePolicy, ReplyContext, ReplyPayload, ReplyChannel, AttachmentRef, AttachmentMaterializer, AgentToolDefinition, AgentToolProvider, ConvMessage, SystemLayer, AgentRequest, AgentResult, } from './types.ts';
|
|
11
|
+
export type { Connector, IncomingConversation, GatePolicy, ReplyContext, ReplyPayload, ReplyChannel, AttachmentRef, AttachmentMaterializer, AgentToolDefinition, AgentToolProvider, ConvMessage, SystemLayer, AgentRequest, AgentResult, AgentRuntime, ConnectorRegistration, } from './types.ts';
|
|
11
12
|
export declare const serverHooks: PluginHooks;
|
package/dist/runtime/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { openLogDb } from "./db.js";
|
|
2
2
|
import { setLogDb } from "./pipeline.js";
|
|
3
3
|
export { handleIncoming } from "./pipeline.js";
|
|
4
|
+
export { registerAgent, resolveAgent, registerConnector, isConnectorRegistered, clearRuntimeRegistries } from "./registry.js";
|
|
4
5
|
export { attachmentMaterializer } from "./attachments.js";
|
|
5
6
|
export { makeAttachmentCapabilities } from "./agent-capabilities.js";
|
|
6
|
-
export { buildPolicy, loadGatePolicy } from "./config.js";
|
|
7
|
+
export { buildPolicy, loadGatePolicy, loadAgentId } from "./config.js";
|
|
7
8
|
export { makeLiveChannel, plainRender } from "./live-message.js";
|
|
8
9
|
export { chunk } from "./format.js";
|
|
9
10
|
let db;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { Connector, IncomingConversation, GatePolicy } from './types.ts';
|
|
1
|
+
import type { Connector, IncomingConversation, GatePolicy, AgentRuntime } from './types.ts';
|
|
3
2
|
import type { LogDb } from './db.ts';
|
|
4
3
|
export declare function setLogDb(db: LogDb | undefined): void;
|
|
5
|
-
export type RunAgentFn =
|
|
4
|
+
export type RunAgentFn = AgentRuntime['run'];
|
|
6
5
|
export interface PipelineDeps {
|
|
7
6
|
runAgent?: RunAgentFn;
|
|
8
7
|
logDb?: LogDb | null;
|
package/dist/runtime/pipeline.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { runAgent, agentSystemBase } from '@coffer-org/plugin-claude-agent/runtime';
|
|
2
1
|
import { join } from 'node:path';
|
|
3
2
|
import { loadAllowed, saveAllowed, isAllowed, addAllowed, makeThrottle } from "./allow.js";
|
|
4
|
-
import { loadGatePolicy } from "./config.js";
|
|
3
|
+
import { loadAgentId, loadGatePolicy } from "./config.js";
|
|
5
4
|
import { buildSystem } from "./system-assembly.js";
|
|
6
5
|
import { attachmentMaterializer } from "./attachments.js";
|
|
7
6
|
import { makeAttachmentCapabilities } from "./agent-capabilities.js";
|
|
7
|
+
import { resolveAgent } from "./registry.js";
|
|
8
8
|
import { getLogger } from '@coffer-org/sdk/logger';
|
|
9
9
|
const log = getLogger('orchestrator');
|
|
10
10
|
const stateDir = () => process.env['ORCHESTRATOR_STATE_DIR']
|
|
@@ -21,7 +21,15 @@ function passThrottle(connectorId) {
|
|
|
21
21
|
return t;
|
|
22
22
|
}
|
|
23
23
|
let cachedBase;
|
|
24
|
-
|
|
24
|
+
let cachedBaseAgentId;
|
|
25
|
+
function cachedAgentBase() {
|
|
26
|
+
const runtime = resolveAgent();
|
|
27
|
+
if (cachedBaseAgentId !== runtime.id) {
|
|
28
|
+
cachedBaseAgentId = runtime.id;
|
|
29
|
+
cachedBase = runtime.systemBase();
|
|
30
|
+
}
|
|
31
|
+
return cachedBase;
|
|
32
|
+
}
|
|
25
33
|
function openChannel(connector, chatId, ctx) {
|
|
26
34
|
try {
|
|
27
35
|
return connector.reply(chatId, ctx);
|
|
@@ -41,10 +49,12 @@ async function safeCall(fn, fallback, label) {
|
|
|
41
49
|
}
|
|
42
50
|
}
|
|
43
51
|
export async function handleIncoming(connector, conversation, deps) {
|
|
44
|
-
const agent = deps?.runAgent ?? runAgent;
|
|
45
|
-
const db = deps && 'logDb' in deps ? deps.logDb : logDb;
|
|
46
52
|
const policy = deps?.policy ?? await loadGatePolicy();
|
|
47
|
-
const
|
|
53
|
+
const selectedAgentId = conversation.agentId ?? policy.agentId ?? (deps?.runAgent ? undefined : await loadAgentId());
|
|
54
|
+
const runtime = deps?.runAgent ? undefined : resolveAgent(selectedAgentId);
|
|
55
|
+
const agent = deps?.runAgent ?? runtime.run.bind(runtime);
|
|
56
|
+
const db = deps && 'logDb' in deps ? deps.logDb : logDb;
|
|
57
|
+
const agentBase = deps?.agentBase ?? (() => selectedAgentId ? runtime.systemBase() : cachedAgentBase());
|
|
48
58
|
const { connectorId, chatId, sender, messages } = conversation;
|
|
49
59
|
const last = messages[messages.length - 1];
|
|
50
60
|
if (!last || last.role !== 'user')
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AgentRuntime, ConnectorRegistration } from './types.ts';
|
|
2
|
+
export declare function registerAgent(runtime: AgentRuntime, opts?: {
|
|
3
|
+
default?: boolean;
|
|
4
|
+
}): () => void;
|
|
5
|
+
export declare function resolveAgent(id?: string): AgentRuntime;
|
|
6
|
+
export declare function registerConnector(registration: ConnectorRegistration): () => void;
|
|
7
|
+
export declare function isConnectorRegistered(id: string): boolean;
|
|
8
|
+
export declare function clearRuntimeRegistries(): void;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const agents = new Map();
|
|
2
|
+
const connectors = new Map();
|
|
3
|
+
let defaultAgentId;
|
|
4
|
+
export function registerAgent(runtime, opts = {}) {
|
|
5
|
+
const current = agents.get(runtime.id);
|
|
6
|
+
if (current && current !== runtime)
|
|
7
|
+
throw new Error(`agent already registered: ${runtime.id}`);
|
|
8
|
+
agents.set(runtime.id, runtime);
|
|
9
|
+
if (opts.default || !defaultAgentId)
|
|
10
|
+
defaultAgentId = runtime.id;
|
|
11
|
+
return () => unregisterAgent(runtime.id, runtime);
|
|
12
|
+
}
|
|
13
|
+
function unregisterAgent(id, expected) {
|
|
14
|
+
if (agents.get(id) !== expected)
|
|
15
|
+
return;
|
|
16
|
+
agents.delete(id);
|
|
17
|
+
if (defaultAgentId === id)
|
|
18
|
+
defaultAgentId = agents.keys().next().value;
|
|
19
|
+
}
|
|
20
|
+
export function resolveAgent(id) {
|
|
21
|
+
const key = id ?? defaultAgentId;
|
|
22
|
+
const runtime = key ? agents.get(key) : undefined;
|
|
23
|
+
if (!runtime)
|
|
24
|
+
throw new Error(id ? `agent is not registered: ${id}` : 'no agent is registered');
|
|
25
|
+
return runtime;
|
|
26
|
+
}
|
|
27
|
+
export function registerConnector(registration) {
|
|
28
|
+
const current = connectors.get(registration.id);
|
|
29
|
+
if (current && current !== registration)
|
|
30
|
+
throw new Error(`connector already registered: ${registration.id}`);
|
|
31
|
+
connectors.set(registration.id, registration);
|
|
32
|
+
return () => {
|
|
33
|
+
if (connectors.get(registration.id) === registration)
|
|
34
|
+
connectors.delete(registration.id);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export function isConnectorRegistered(id) {
|
|
38
|
+
return connectors.has(id);
|
|
39
|
+
}
|
|
40
|
+
export function clearRuntimeRegistries() {
|
|
41
|
+
agents.clear();
|
|
42
|
+
connectors.clear();
|
|
43
|
+
defaultAgentId = undefined;
|
|
44
|
+
}
|
package/dist/runtime/types.d.ts
CHANGED
|
@@ -1,5 +1,53 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
1
|
+
export interface AttachmentRef {
|
|
2
|
+
name: string;
|
|
3
|
+
mime?: string;
|
|
4
|
+
size?: number;
|
|
5
|
+
label?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface AgentToolDefinition {
|
|
8
|
+
name: string;
|
|
9
|
+
description: string;
|
|
10
|
+
inputSchema: Record<string, unknown>;
|
|
11
|
+
handler: (args: Record<string, unknown>) => Promise<unknown>;
|
|
12
|
+
}
|
|
13
|
+
export interface AgentToolProvider {
|
|
14
|
+
tools: AgentToolDefinition[];
|
|
15
|
+
}
|
|
16
|
+
export interface ConvMessage {
|
|
17
|
+
role: 'user' | 'assistant';
|
|
18
|
+
content: string;
|
|
19
|
+
attachments?: AttachmentRef[];
|
|
20
|
+
sender?: string | null;
|
|
21
|
+
msgId: string;
|
|
22
|
+
ts: number;
|
|
23
|
+
}
|
|
24
|
+
export interface SystemLayer {
|
|
25
|
+
text: string;
|
|
26
|
+
stable: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface AgentRequest {
|
|
29
|
+
system: SystemLayer[];
|
|
30
|
+
messages: ConvMessage[];
|
|
31
|
+
toolProvider?: AgentToolProvider;
|
|
32
|
+
onDelta?: (accumulated: string) => void;
|
|
33
|
+
onReasoning?: (accumulated: string) => void;
|
|
34
|
+
onSegment?: () => void;
|
|
35
|
+
}
|
|
36
|
+
export interface AgentResult {
|
|
37
|
+
text: string | null;
|
|
38
|
+
reasoning: string | null;
|
|
39
|
+
tokensIn: number | null;
|
|
40
|
+
tokensOut: number | null;
|
|
41
|
+
stopReason: string | null;
|
|
42
|
+
}
|
|
43
|
+
export interface AgentRuntime {
|
|
44
|
+
id: string;
|
|
45
|
+
run(request: AgentRequest): Promise<AgentResult>;
|
|
46
|
+
systemBase(): Promise<string>;
|
|
47
|
+
}
|
|
48
|
+
export interface ConnectorRegistration {
|
|
49
|
+
id: string;
|
|
50
|
+
}
|
|
3
51
|
export interface AttachmentMaterializer {
|
|
4
52
|
store(bytes: Uint8Array, opts?: {
|
|
5
53
|
originalName?: string;
|
|
@@ -8,6 +56,7 @@ export interface AttachmentMaterializer {
|
|
|
8
56
|
}
|
|
9
57
|
export interface IncomingConversation {
|
|
10
58
|
connectorId: string;
|
|
59
|
+
agentId?: string;
|
|
11
60
|
chatId: string;
|
|
12
61
|
channelSystem?: string;
|
|
13
62
|
volatileSystem?: string;
|
|
@@ -42,6 +91,7 @@ export interface Connector {
|
|
|
42
91
|
}): Promise<void>;
|
|
43
92
|
}
|
|
44
93
|
export interface GatePolicy {
|
|
94
|
+
agentId?: string;
|
|
45
95
|
accessPassword: string;
|
|
46
96
|
triggerPrefix: string;
|
|
47
97
|
replyWindow: number;
|
package/dist/schema.js
CHANGED
|
@@ -7077,6 +7077,10 @@ var src_default = definePlugin({
|
|
|
7077
7077
|
settings: defineSettings({
|
|
7078
7078
|
label: "orchestrator.settings.label",
|
|
7079
7079
|
fields: [
|
|
7080
|
+
field.select({
|
|
7081
|
+
key: "agent_id",
|
|
7082
|
+
label: "orchestrator.settings.agent_id"
|
|
7083
|
+
}),
|
|
7080
7084
|
field.password({
|
|
7081
7085
|
key: "access_password",
|
|
7082
7086
|
label: "orchestrator.settings.access_password"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coffer-org/plugin-orchestrator",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=24"
|
|
@@ -25,9 +25,8 @@
|
|
|
25
25
|
"postpack": "node ../../scripts/swap-exports.mjs src"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@coffer-org/sdk": "^2.1.
|
|
29
|
-
"@coffer-org/server": "^2.3.0"
|
|
30
|
-
"@coffer-org/plugin-claude-agent": "^2.5.2"
|
|
28
|
+
"@coffer-org/sdk": "^2.1.2",
|
|
29
|
+
"@coffer-org/server": "^2.3.0"
|
|
31
30
|
},
|
|
32
31
|
"coffer": {
|
|
33
32
|
"schema": "dist/schema.js"
|