@firstlovecenter/ai-chat 0.1.1 → 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 +26 -8
- 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 +26 -8
- package/dist/server/index.js.map +1 -1
- package/package.json +12 -10
package/dist/server/index.cjs
CHANGED
|
@@ -146,11 +146,19 @@ var ClaudeToolProvider = class {
|
|
|
146
146
|
patchVertexBuildRequestSync(this.client);
|
|
147
147
|
}
|
|
148
148
|
async runTurn(input) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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
|
+
});
|
|
154
162
|
const messages = toAnthropicMessages(input.messages);
|
|
155
163
|
const response = await this.client.messages.create({
|
|
156
164
|
model: this.modelId,
|
|
@@ -1393,6 +1401,16 @@ function configureAiChat(opts) {
|
|
|
1393
1401
|
];
|
|
1394
1402
|
const getProvider = (id) => toolProviders2.find((p) => p.id === id) ?? getToolProvider(id);
|
|
1395
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;
|
|
1396
1414
|
const runAgentBound = async ({
|
|
1397
1415
|
question,
|
|
1398
1416
|
ctx,
|
|
@@ -1415,11 +1433,11 @@ function configureAiChat(opts) {
|
|
|
1415
1433
|
modelIds: opts.vertex.modelIds,
|
|
1416
1434
|
location: location ?? settings.gcpLocation
|
|
1417
1435
|
});
|
|
1418
|
-
const systemBlocks = await
|
|
1436
|
+
const systemBlocks = await tools.buildSystemBlocks(ctx);
|
|
1419
1437
|
const input = {
|
|
1420
1438
|
question,
|
|
1421
1439
|
ctx,
|
|
1422
|
-
tools:
|
|
1440
|
+
tools: tools.tools,
|
|
1423
1441
|
systemBlocks,
|
|
1424
1442
|
provider,
|
|
1425
1443
|
maxToolTurns,
|
|
@@ -1435,7 +1453,7 @@ function configureAiChat(opts) {
|
|
|
1435
1453
|
persistence: opts.persistence,
|
|
1436
1454
|
auth: opts.auth,
|
|
1437
1455
|
scope: opts.scope,
|
|
1438
|
-
tools
|
|
1456
|
+
tools,
|
|
1439
1457
|
vertex: opts.vertex,
|
|
1440
1458
|
logger: opts.logger,
|
|
1441
1459
|
resolveNarratorId: opts.resolveNarratorId,
|