@firstlovecenter/ai-chat 0.1.0 → 0.2.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/server/index.cjs +42 -9
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.cts +30 -0
- package/dist/server/index.d.ts +30 -0
- package/dist/server/index.js +42 -9
- package/dist/server/index.js.map +1 -1
- package/package.json +12 -10
package/dist/server/index.cjs
CHANGED
|
@@ -39,11 +39,26 @@ async function runAgent(input) {
|
|
|
39
39
|
}
|
|
40
40
|
if (response.toolCalls.length === 0) {
|
|
41
41
|
if (presentPayload) break;
|
|
42
|
+
const text = (response.text ?? "").trim();
|
|
43
|
+
if (text) {
|
|
44
|
+
const topic = input.question.length > 80 ? input.question.slice(0, 77) + "..." : input.question;
|
|
45
|
+
presentPayload = {
|
|
46
|
+
blocks: [
|
|
47
|
+
{
|
|
48
|
+
kind: "paragraph_brief",
|
|
49
|
+
topic,
|
|
50
|
+
key_facts: [text]
|
|
51
|
+
}
|
|
52
|
+
],
|
|
53
|
+
raw_numbers: {}
|
|
54
|
+
};
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
42
57
|
return {
|
|
43
58
|
ok: false,
|
|
44
59
|
error: {
|
|
45
60
|
code: "AGENT_NO_PRESENT",
|
|
46
|
-
message: "The agent
|
|
61
|
+
message: "The agent produced no response. Try rephrasing."
|
|
47
62
|
},
|
|
48
63
|
transcript
|
|
49
64
|
};
|
|
@@ -131,11 +146,19 @@ var ClaudeToolProvider = class {
|
|
|
131
146
|
patchVertexBuildRequestSync(this.client);
|
|
132
147
|
}
|
|
133
148
|
async runTurn(input) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
149
|
+
let cacheMarkersUsed = 0;
|
|
150
|
+
const MAX_CACHE_MARKERS = 4;
|
|
151
|
+
const system = input.system.map((b) => {
|
|
152
|
+
if (b.cached && cacheMarkersUsed < MAX_CACHE_MARKERS) {
|
|
153
|
+
cacheMarkersUsed++;
|
|
154
|
+
return {
|
|
155
|
+
type: "text",
|
|
156
|
+
text: b.text,
|
|
157
|
+
cache_control: { type: "ephemeral" }
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
return { type: "text", text: b.text };
|
|
161
|
+
});
|
|
139
162
|
const messages = toAnthropicMessages(input.messages);
|
|
140
163
|
const response = await this.client.messages.create({
|
|
141
164
|
model: this.modelId,
|
|
@@ -1378,6 +1401,16 @@ function configureAiChat(opts) {
|
|
|
1378
1401
|
];
|
|
1379
1402
|
const getProvider = (id) => toolProviders2.find((p) => p.id === id) ?? getToolProvider(id);
|
|
1380
1403
|
const chatInterfaces = opts.chatInterfaces ?? BUILTIN_CHAT_INTERFACE_IDS.map((id) => ({ id }));
|
|
1404
|
+
const tools = opts.rolePrompt ? {
|
|
1405
|
+
tools: opts.tools.tools,
|
|
1406
|
+
async buildSystemBlocks(ctx) {
|
|
1407
|
+
const inner = await opts.tools.buildSystemBlocks(ctx);
|
|
1408
|
+
const rolePrompt = opts.rolePrompt;
|
|
1409
|
+
const role = typeof rolePrompt === "function" ? await rolePrompt(ctx) : rolePrompt;
|
|
1410
|
+
if (!role || !role.trim()) return inner;
|
|
1411
|
+
return [{ text: role, cached: true }, ...inner];
|
|
1412
|
+
}
|
|
1413
|
+
} : opts.tools;
|
|
1381
1414
|
const runAgentBound = async ({
|
|
1382
1415
|
question,
|
|
1383
1416
|
ctx,
|
|
@@ -1400,11 +1433,11 @@ function configureAiChat(opts) {
|
|
|
1400
1433
|
modelIds: opts.vertex.modelIds,
|
|
1401
1434
|
location: location ?? settings.gcpLocation
|
|
1402
1435
|
});
|
|
1403
|
-
const systemBlocks = await
|
|
1436
|
+
const systemBlocks = await tools.buildSystemBlocks(ctx);
|
|
1404
1437
|
const input = {
|
|
1405
1438
|
question,
|
|
1406
1439
|
ctx,
|
|
1407
|
-
tools:
|
|
1440
|
+
tools: tools.tools,
|
|
1408
1441
|
systemBlocks,
|
|
1409
1442
|
provider,
|
|
1410
1443
|
maxToolTurns,
|
|
@@ -1420,7 +1453,7 @@ function configureAiChat(opts) {
|
|
|
1420
1453
|
persistence: opts.persistence,
|
|
1421
1454
|
auth: opts.auth,
|
|
1422
1455
|
scope: opts.scope,
|
|
1423
|
-
tools
|
|
1456
|
+
tools,
|
|
1424
1457
|
vertex: opts.vertex,
|
|
1425
1458
|
logger: opts.logger,
|
|
1426
1459
|
resolveNarratorId: opts.resolveNarratorId,
|