@m6d/cortex-server 2.0.0 → 2.1.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/README.md +10 -0
- package/contracts/interactive.ts +53 -0
- package/contracts/rich-text.ts +207 -0
- package/contracts/runtime.ts +58 -1
- package/contracts/wire.ts +32 -0
- package/dist/contracts/interactive.d.ts +39 -0
- package/dist/contracts/rich-text.d.ts +32 -0
- package/dist/contracts/runtime.d.ts +119 -7
- package/dist/contracts/wire.d.ts +30 -0
- package/dist/src/lib/adapters/database/index.d.ts +7 -0
- package/dist/src/lib/adapters/database/message-content.d.ts +2 -0
- package/dist/src/lib/adapters/database/mssql/index.d.ts +1 -0
- package/dist/src/lib/adapters/database/mssql/messages.d.ts +1 -0
- package/dist/src/lib/adapters/database/postgres/index.d.ts +1 -0
- package/dist/src/lib/adapters/database/postgres/messages.d.ts +1 -0
- package/dist/src/lib/ai/cc-runtime.d.ts +5 -4
- package/dist/src/lib/ai/interactive.d.ts +62 -0
- package/dist/src/lib/ai/tools/search-common.d.ts +1 -1
- package/dist/src/lib/ai/turn-tools.d.ts +14 -0
- package/dist/src/lib/cc/client.d.ts +27 -3
- package/dist/src/lib/cc/config-cache.d.ts +2 -2
- package/dist/src/lib/cc/registry.d.ts +14 -1
- package/dist/src/lib/cc/types.d.ts +1 -1
- package/package.json +5 -2
- package/src/lib/adapters/database/index.ts +12 -0
- package/src/lib/adapters/database/mssql/messages.ts +28 -1
- package/src/lib/adapters/database/postgres/messages.ts +22 -1
- package/src/lib/ai/cc-runtime.ts +16 -1
- package/src/lib/ai/index.ts +41 -5
- package/src/lib/ai/interactive.ts +364 -0
- package/src/lib/ai/tools/search-tools.tool.ts +6 -2
- package/src/lib/ai/turn-tools.ts +23 -0
- package/src/lib/cc/client.ts +5 -1
- package/src/lib/cc/format.ts +8 -9
- package/src/lib/cc/registry.ts +16 -2
- package/src/lib/cc/types.ts +1 -0
- package/src/lib/routes/chat.ts +23 -0
package/src/lib/cc/registry.ts
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
import type { ControlCenterClient } from "./client";
|
|
2
|
-
import type { RuntimeAgentConfig } from "./types";
|
|
2
|
+
import type { RuntimeAgentConfig, ToolInteraction } from "./types";
|
|
3
3
|
|
|
4
4
|
export type CcToolBinding = {
|
|
5
5
|
toolId: string;
|
|
6
6
|
readOnly: boolean;
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* An interactive tool resolved for this turn. Declared to the model as a real
|
|
11
|
+
* client-executed tool — never a sandbox binding — so its call streams to the
|
|
12
|
+
* widget as a tool-call part and parks the run until the flow settles.
|
|
13
|
+
*/
|
|
14
|
+
export type CcInteractiveTool = {
|
|
15
|
+
toolId: string;
|
|
16
|
+
signature: string;
|
|
17
|
+
interaction: ToolInteraction;
|
|
18
|
+
inputSchema?: Record<string, unknown>;
|
|
19
|
+
};
|
|
20
|
+
|
|
9
21
|
/**
|
|
10
22
|
* Turn-scoped and mutable: seeded from /resolve, extended by searchTools
|
|
11
23
|
* mid-turn so a tool discovered at step 3 is callable at step 4.
|
|
@@ -14,9 +26,10 @@ export type CcToolRegistry = Map<string, CcToolBinding>;
|
|
|
14
26
|
|
|
15
27
|
export function registerCcTools(
|
|
16
28
|
registry: CcToolRegistry,
|
|
17
|
-
tools: { name: string; toolId: string; readOnly: boolean }[],
|
|
29
|
+
tools: { name: string; toolId: string; readOnly: boolean; interaction?: ToolInteraction }[],
|
|
18
30
|
) {
|
|
19
31
|
for (const tool of tools) {
|
|
32
|
+
if (tool.interaction) continue;
|
|
20
33
|
registry.set(tool.name, { toolId: tool.toolId, readOnly: tool.readOnly });
|
|
21
34
|
}
|
|
22
35
|
}
|
|
@@ -50,6 +63,7 @@ export type CcRuntime = {
|
|
|
50
63
|
agentId: string;
|
|
51
64
|
config: RuntimeAgentConfig;
|
|
52
65
|
registry: CcToolRegistry;
|
|
66
|
+
interactiveTools: Map<string, CcInteractiveTool>;
|
|
53
67
|
threadId: string;
|
|
54
68
|
turnKey: string;
|
|
55
69
|
userId: string;
|
package/src/lib/cc/types.ts
CHANGED
package/src/lib/routes/chat.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { HTTPException } from "hono/http-exception";
|
|
|
6
6
|
import type { CortexAppEnv } from "@/types";
|
|
7
7
|
import { requireAuth } from "@/auth/middleware";
|
|
8
8
|
import { startTurn } from "@/ai/index";
|
|
9
|
+
import { initiateInteractiveTool } from "@/ai/interactive";
|
|
9
10
|
import { abortRun, getRunId, joinLog, offsetBelongsToRun } from "@/ai/active-runs";
|
|
10
11
|
import { notify } from "@/ws/connections";
|
|
11
12
|
import { requireOwnedThread } from "./owned-thread";
|
|
@@ -91,6 +92,28 @@ export function createChatRoutes() {
|
|
|
91
92
|
return resumeServerSentEventsResponse({ adapter: joinLog(chatId, runId) });
|
|
92
93
|
});
|
|
93
94
|
|
|
95
|
+
/**
|
|
96
|
+
* Runs an interactive tool's initiate call for a pending tool call and
|
|
97
|
+
* returns the widget's embed payload. `interactive: false` tells the
|
|
98
|
+
* widget the call is not an interactive CC tool — fall back to its
|
|
99
|
+
* default rendering. The payload never reaches the model.
|
|
100
|
+
*/
|
|
101
|
+
app.post("/chat/:chatId/tools/:toolCallId/initiate", requireAuth, async function (c) {
|
|
102
|
+
const config = c.get("agentConfig");
|
|
103
|
+
const { id: userId, token } = c.get("user");
|
|
104
|
+
const thread = await requireOwnedThread(c, c.req.param("chatId"));
|
|
105
|
+
|
|
106
|
+
return c.json(
|
|
107
|
+
await initiateInteractiveTool({
|
|
108
|
+
config,
|
|
109
|
+
thread,
|
|
110
|
+
userId,
|
|
111
|
+
token,
|
|
112
|
+
toolCallId: c.req.param("toolCallId"),
|
|
113
|
+
}),
|
|
114
|
+
);
|
|
115
|
+
});
|
|
116
|
+
|
|
94
117
|
app.post("/chat/:chatId/abort", requireAuth, async function (c) {
|
|
95
118
|
const agentId = c.get("agentId");
|
|
96
119
|
const userId = c.get("user").id;
|