@contextableai/clawg-ui 0.2.9 → 0.3.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/index.d.ts +27 -0
- package/dist/index.js +124 -0
- package/dist/src/channel.d.ts +8 -0
- package/dist/src/channel.js +29 -0
- package/dist/src/client-tools.d.ts +27 -0
- package/dist/src/client-tools.js +50 -0
- package/dist/src/gateway-secret.d.ts +9 -0
- package/dist/src/gateway-secret.js +17 -0
- package/dist/src/http-handler.d.ts +3 -0
- package/dist/src/http-handler.js +545 -0
- package/dist/src/tool-store.d.ts +21 -0
- package/dist/src/tool-store.js +109 -0
- package/package.json +13 -2
- package/CHANGELOG.md +0 -105
- package/clawgui.png +0 -0
- package/index.ts +0 -182
- package/src/channel.ts +0 -37
- package/src/client-tools.ts +0 -51
- package/src/gateway-secret.ts +0 -20
- package/src/http-handler.ts +0 -627
- package/src/tool-store.ts +0 -152
- package/tsconfig.json +0 -12
package/src/tool-store.ts
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import type { Tool } from "@ag-ui/core";
|
|
2
|
-
|
|
3
|
-
export type EventWriter = (event: { type: string } & Record<string, unknown>) => void;
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Per-session store for:
|
|
7
|
-
* 1. AG-UI client-provided tools (read by the plugin tool factory)
|
|
8
|
-
* 2. SSE event writer (read by before/after_tool_call hooks)
|
|
9
|
-
*
|
|
10
|
-
* Fully reentrant — concurrent requests use different session keys.
|
|
11
|
-
*/
|
|
12
|
-
const toolStore = new Map<string, Tool[]>();
|
|
13
|
-
const writerStore = new Map<string, EventWriter>();
|
|
14
|
-
|
|
15
|
-
// --- Client tools (for the plugin tool factory) ---
|
|
16
|
-
|
|
17
|
-
export function stashTools(sessionKey: string, tools: Tool[]): void {
|
|
18
|
-
console.log(`[clawg-ui] stashTools: sessionKey=${sessionKey}, toolCount=${tools.length}`);
|
|
19
|
-
for (const t of tools) {
|
|
20
|
-
console.log(`[clawg-ui] tool: name=${t.name}, description=${t.description ?? "(none)"}, hasParams=${!!t.parameters}, params=${JSON.stringify(t.parameters ?? {})}`);
|
|
21
|
-
}
|
|
22
|
-
toolStore.set(sessionKey, tools);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function popTools(sessionKey: string): Tool[] {
|
|
26
|
-
const tools = toolStore.get(sessionKey) ?? [];
|
|
27
|
-
console.log(`[clawg-ui] popTools: sessionKey=${sessionKey}, tools=${tools.length}`);
|
|
28
|
-
toolStore.delete(sessionKey);
|
|
29
|
-
return tools;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// --- SSE event writer (for before/after_tool_call hooks) ---
|
|
33
|
-
|
|
34
|
-
const messageIdStore = new Map<string, string>();
|
|
35
|
-
|
|
36
|
-
export function setWriter(
|
|
37
|
-
sessionKey: string,
|
|
38
|
-
writer: EventWriter,
|
|
39
|
-
messageId: string,
|
|
40
|
-
): void {
|
|
41
|
-
writerStore.set(sessionKey, writer);
|
|
42
|
-
messageIdStore.set(sessionKey, messageId);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function getWriter(sessionKey: string): EventWriter | undefined {
|
|
46
|
-
return writerStore.get(sessionKey);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export function getMessageId(sessionKey: string): string | undefined {
|
|
50
|
-
return messageIdStore.get(sessionKey);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function clearWriter(sessionKey: string): void {
|
|
54
|
-
writerStore.delete(sessionKey);
|
|
55
|
-
messageIdStore.delete(sessionKey);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// --- Pending toolCallId stack (before_tool_call pushes, tool_result_persist pops) ---
|
|
59
|
-
// Only used for SERVER-side tools. Client tools emit TOOL_CALL_END in
|
|
60
|
-
// before_tool_call and never push to this stack.
|
|
61
|
-
|
|
62
|
-
const pendingStacks = new Map<string, string[]>();
|
|
63
|
-
|
|
64
|
-
export function pushToolCallId(sessionKey: string, toolCallId: string): void {
|
|
65
|
-
let stack = pendingStacks.get(sessionKey);
|
|
66
|
-
if (!stack) {
|
|
67
|
-
stack = [];
|
|
68
|
-
pendingStacks.set(sessionKey, stack);
|
|
69
|
-
}
|
|
70
|
-
stack.push(toolCallId);
|
|
71
|
-
console.log(`[clawg-ui] pushToolCallId: sessionKey=${sessionKey}, toolCallId=${toolCallId}, stackSize=${stack.length}`);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export function popToolCallId(sessionKey: string): string | undefined {
|
|
75
|
-
const stack = pendingStacks.get(sessionKey);
|
|
76
|
-
const id = stack?.pop();
|
|
77
|
-
console.log(`[clawg-ui] popToolCallId: sessionKey=${sessionKey}, toolCallId=${id ?? "none"}, stackSize=${stack?.length ?? 0}`);
|
|
78
|
-
if (stack && stack.length === 0) {
|
|
79
|
-
pendingStacks.delete(sessionKey);
|
|
80
|
-
}
|
|
81
|
-
return id;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// --- Client tool name tracking ---
|
|
85
|
-
// Tracks which tool names are client-provided so hooks can distinguish them.
|
|
86
|
-
|
|
87
|
-
const clientToolNames = new Map<string, Set<string>>();
|
|
88
|
-
|
|
89
|
-
export function markClientToolNames(
|
|
90
|
-
sessionKey: string,
|
|
91
|
-
names: string[],
|
|
92
|
-
): void {
|
|
93
|
-
console.log(`[clawg-ui] markClientToolNames: sessionKey=${sessionKey}, names=${names.join(", ")}`);
|
|
94
|
-
clientToolNames.set(sessionKey, new Set(names));
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export function isClientTool(
|
|
98
|
-
sessionKey: string,
|
|
99
|
-
toolName: string,
|
|
100
|
-
): boolean {
|
|
101
|
-
const result = clientToolNames.get(sessionKey)?.has(toolName) ?? false;
|
|
102
|
-
console.log(`[clawg-ui] isClientTool: sessionKey=${sessionKey}, toolName=${toolName}, result=${result}`);
|
|
103
|
-
return result;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export function clearClientToolNames(sessionKey: string): void {
|
|
107
|
-
console.log(`[clawg-ui] clearClientToolNames: sessionKey=${sessionKey}`);
|
|
108
|
-
clientToolNames.delete(sessionKey);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// --- Tool-fired-in-run flag ---
|
|
112
|
-
// Tracks whether any tool call (server or client) was emitted in the current
|
|
113
|
-
// run. When a text message is about to be emitted and this flag is set, the
|
|
114
|
-
// http-handler splits into a new run so tool events and text events live in
|
|
115
|
-
// separate runs (per AG-UI protocol best practice).
|
|
116
|
-
|
|
117
|
-
const toolFiredInRunFlags = new Map<string, boolean>();
|
|
118
|
-
|
|
119
|
-
export function setToolFiredInRun(sessionKey: string): void {
|
|
120
|
-
toolFiredInRunFlags.set(sessionKey, true);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export function wasToolFiredInRun(sessionKey: string): boolean {
|
|
124
|
-
return toolFiredInRunFlags.get(sessionKey) ?? false;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export function clearToolFiredInRun(sessionKey: string): void {
|
|
128
|
-
toolFiredInRunFlags.delete(sessionKey);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// --- Client-tool-called flag ---
|
|
132
|
-
// Set when a client tool is invoked during a run so the dispatcher can
|
|
133
|
-
// suppress text output and end the run after the tool call events.
|
|
134
|
-
|
|
135
|
-
const clientToolCalledFlags = new Map<string, boolean>();
|
|
136
|
-
|
|
137
|
-
export function setClientToolCalled(sessionKey: string): void {
|
|
138
|
-
console.log(`[clawg-ui] setClientToolCalled: sessionKey=${sessionKey}`);
|
|
139
|
-
clientToolCalledFlags.set(sessionKey, true);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export function wasClientToolCalled(sessionKey: string): boolean {
|
|
143
|
-
const result = clientToolCalledFlags.get(sessionKey) ?? false;
|
|
144
|
-
console.log(`[clawg-ui] wasClientToolCalled: sessionKey=${sessionKey}, result=${result}`);
|
|
145
|
-
return result;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export function clearClientToolCalled(sessionKey: string): void {
|
|
149
|
-
console.log(`[clawg-ui] clearClientToolCalled: sessionKey=${sessionKey}`);
|
|
150
|
-
clientToolCalledFlags.delete(sessionKey);
|
|
151
|
-
}
|
|
152
|
-
|
package/tsconfig.json
DELETED