@juspay/neurolink 13.11.0 → 13.12.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/CHANGELOG.md +2 -7
- package/dist/browser/neurolink.min.js +435 -435
- package/dist/cli/loop/optionsSchema.d.ts +1 -1
- package/dist/neurolink.d.ts +7 -0
- package/dist/neurolink.js +21 -0
- package/dist/providers/anthropic/client.d.ts +9 -0
- package/dist/providers/anthropic/client.js +139 -10
- package/dist/providers/anthropic/threads.d.ts +39 -2
- package/dist/providers/anthropic/threads.js +246 -4
- package/dist/types/generate.d.ts +16 -0
- package/dist/types/loopEngine.d.ts +29 -2
- package/dist/types/stream.d.ts +12 -3
- package/docs-site/static/search-index.json +1 -0
- package/package.json +1 -1
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* by itself.
|
|
17
17
|
*/
|
|
18
18
|
import { createHash } from "node:crypto";
|
|
19
|
+
import { CONVERSATION_INSTRUCTIONS } from "../../config/conversationMemory.js";
|
|
19
20
|
export const MESSAGE_THREADS_BETA = "message-threads-2026-08-12";
|
|
20
21
|
/** Stop reasons after which the API has stored the response as a continuable turn. */
|
|
21
22
|
const STORABLE_STOP_REASONS = new Set([
|
|
@@ -36,7 +37,7 @@ export function settleThread(session, response) {
|
|
|
36
37
|
response.messageId !== undefined &&
|
|
37
38
|
response.stopReason !== undefined &&
|
|
38
39
|
STORABLE_STOP_REASONS.has(response.stopReason)) {
|
|
39
|
-
session.accept(response.messageId);
|
|
40
|
+
session.accept(response.messageId, response.stopReason);
|
|
40
41
|
}
|
|
41
42
|
else {
|
|
42
43
|
session.reset();
|
|
@@ -63,6 +64,73 @@ const withoutCacheControl = (value) => {
|
|
|
63
64
|
}
|
|
64
65
|
return value;
|
|
65
66
|
};
|
|
67
|
+
// What conversation memory keeps of a message: its role and its text. Memory
|
|
68
|
+
// drops tool_use / tool_result blocks and anything that is not text, so that is
|
|
69
|
+
// all a later call can be compared on.
|
|
70
|
+
const textOfMessage = (message) => {
|
|
71
|
+
const content = message?.content;
|
|
72
|
+
if (typeof content === "string") {
|
|
73
|
+
return content;
|
|
74
|
+
}
|
|
75
|
+
if (!Array.isArray(content)) {
|
|
76
|
+
return "";
|
|
77
|
+
}
|
|
78
|
+
return content
|
|
79
|
+
.map((block) => {
|
|
80
|
+
const b = block;
|
|
81
|
+
if (b?.type === "text" && typeof b.text === "string") {
|
|
82
|
+
return b.text;
|
|
83
|
+
}
|
|
84
|
+
// An attachment (image, document) is part of what the model was given.
|
|
85
|
+
// It is compared by content, so a replaced one is a different message;
|
|
86
|
+
// an attachment memory does not hand back simply never matches, which
|
|
87
|
+
// costs a new thread and nothing else.
|
|
88
|
+
return b === null || b === undefined
|
|
89
|
+
? ""
|
|
90
|
+
: `\u0000${String(b.type)}:${sha(withoutCacheControl(b))}\u0000`;
|
|
91
|
+
})
|
|
92
|
+
.join("");
|
|
93
|
+
};
|
|
94
|
+
// By default conversation memory replays a turn's tool calls as one
|
|
95
|
+
// `[called <tool> → ok]` line each, in front of the assistant's own text. Those
|
|
96
|
+
// lines describe tool blocks the thread already holds in full, so they are
|
|
97
|
+
// left out of the comparison: what is compared is what the model said.
|
|
98
|
+
const TOOL_MARKER_LINE = /^\[called [^\n]*? → (?:ok|error|unknown)\](?:\n|$)/;
|
|
99
|
+
const withoutToolMarkers = (text) => {
|
|
100
|
+
let rest = text;
|
|
101
|
+
while (TOOL_MARKER_LINE.test(rest)) {
|
|
102
|
+
rest = rest.replace(TOOL_MARKER_LINE, "");
|
|
103
|
+
}
|
|
104
|
+
return rest;
|
|
105
|
+
};
|
|
106
|
+
const memoryHash = (role, text) => sha([role, role === "assistant" ? withoutToolMarkers(text) : text]);
|
|
107
|
+
const memoryHashOf = (message) => memoryHash(message?.role, textOfMessage(message));
|
|
108
|
+
// NeuroLink appends CONVERSATION_INSTRUCTIONS to the system prompt once a
|
|
109
|
+
// conversation has history, so a session's first call and its second carry
|
|
110
|
+
// different system prompts for the same conversation. The note is about
|
|
111
|
+
// history a continued thread already holds, so it is left out of the
|
|
112
|
+
// comparison; a continued call therefore runs without it.
|
|
113
|
+
const withoutConversationNote = (system) => {
|
|
114
|
+
if (typeof system === "string") {
|
|
115
|
+
return system.endsWith(CONVERSATION_INSTRUCTIONS)
|
|
116
|
+
? system.slice(0, -CONVERSATION_INSTRUCTIONS.length)
|
|
117
|
+
: system;
|
|
118
|
+
}
|
|
119
|
+
if (Array.isArray(system)) {
|
|
120
|
+
return system.map((block) => {
|
|
121
|
+
const text = block?.text;
|
|
122
|
+
return typeof text === "string" &&
|
|
123
|
+
text.endsWith(CONVERSATION_INSTRUCTIONS)
|
|
124
|
+
? {
|
|
125
|
+
...block,
|
|
126
|
+
text: text.slice(0, -CONVERSATION_INSTRUCTIONS.length),
|
|
127
|
+
}
|
|
128
|
+
: block;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
return system;
|
|
132
|
+
};
|
|
133
|
+
const TURN_ENDING_STOPS = new Set(["end_turn", "stop_sequence"]);
|
|
66
134
|
const FIXED_FIELDS = [
|
|
67
135
|
"model",
|
|
68
136
|
"system",
|
|
@@ -86,7 +154,7 @@ const mergeBetas = (existing) => [
|
|
|
86
154
|
* @param betaHeader the `anthropic-beta` value the client already sends; the
|
|
87
155
|
* thread beta is added to it, identically on every request of the thread.
|
|
88
156
|
*/
|
|
89
|
-
export function createAnthropicThreadSession(betaHeader) {
|
|
157
|
+
export function createAnthropicThreadSession(betaHeader, carried) {
|
|
90
158
|
const headers = { "anthropic-beta": mergeBetas(betaHeader) };
|
|
91
159
|
let enabled = true;
|
|
92
160
|
let previousMessageId;
|
|
@@ -95,6 +163,18 @@ export function createAnthropicThreadSession(betaHeader) {
|
|
|
95
163
|
// the API stored after them is not hashed; it is the API's own copy.
|
|
96
164
|
let stored;
|
|
97
165
|
let pending;
|
|
166
|
+
// The call's starting conversation as memory sees it, and how the last
|
|
167
|
+
// stored response ended: together they are what the next call is matched on.
|
|
168
|
+
let startAnchor;
|
|
169
|
+
// The call's starting messages, hashed exactly. A thread can be handed to the
|
|
170
|
+
// next call only while it still holds them unchanged: a reclaim that rewrites
|
|
171
|
+
// earlier history leaves a thread the caller's history no longer matches.
|
|
172
|
+
let startHashes;
|
|
173
|
+
let extendsStart = true;
|
|
174
|
+
let lastStop;
|
|
175
|
+
// A thread left by the previous call of the session, adopted by the first
|
|
176
|
+
// plan only if everything it was created with is still the same.
|
|
177
|
+
let handedOver = carried;
|
|
98
178
|
return {
|
|
99
179
|
get enabled() {
|
|
100
180
|
return enabled;
|
|
@@ -105,10 +185,35 @@ export function createAnthropicThreadSession(betaHeader) {
|
|
|
105
185
|
betas: headers["anthropic-beta"],
|
|
106
186
|
};
|
|
107
187
|
for (const field of FIXED_FIELDS) {
|
|
108
|
-
fixed[field] =
|
|
188
|
+
fixed[field] =
|
|
189
|
+
field === "system" ? withoutConversationNote(bag[field]) : bag[field];
|
|
109
190
|
}
|
|
110
191
|
const fingerprint = sha(fixed);
|
|
111
192
|
const hashes = params.messages.map((message) => sha(withoutCacheControl(message)));
|
|
193
|
+
const memory = params.messages.map(memoryHashOf);
|
|
194
|
+
startAnchor ??= memory;
|
|
195
|
+
startHashes ??= hashes;
|
|
196
|
+
if (hashes.length < startHashes.length ||
|
|
197
|
+
!startHashes.every((hash, index) => hashes[index] === hash)) {
|
|
198
|
+
extendsStart = false;
|
|
199
|
+
}
|
|
200
|
+
if (handedOver !== undefined) {
|
|
201
|
+
// The previous call ended on an assistant reply that memory now hands
|
|
202
|
+
// back, and this call adds one user message. The thread also holds the
|
|
203
|
+
// tool blocks memory dropped; that difference is the point of the
|
|
204
|
+
// session scope and is accepted, not detected.
|
|
205
|
+
const prior = handedOver;
|
|
206
|
+
handedOver = undefined;
|
|
207
|
+
const last = params.messages[params.messages.length - 1];
|
|
208
|
+
if (params.messages.length >= 3 &&
|
|
209
|
+
last.role === "user" &&
|
|
210
|
+
prior.fingerprint === fingerprint &&
|
|
211
|
+
prior.anchor.length === memory.length - 1 &&
|
|
212
|
+
prior.anchor.every((hash, index) => hash === memory[index])) {
|
|
213
|
+
previousMessageId = prior.previousMessageId;
|
|
214
|
+
stored = { fingerprint, hashes: hashes.slice(0, -2) };
|
|
215
|
+
}
|
|
216
|
+
}
|
|
112
217
|
pending = { fingerprint, hashes };
|
|
113
218
|
// The stored reply sits between the messages already sent and the new ones.
|
|
114
219
|
const held = stored ? stored.hashes.length + 1 : 0;
|
|
@@ -140,26 +245,46 @@ export function createAnthropicThreadSession(betaHeader) {
|
|
|
140
245
|
headers,
|
|
141
246
|
};
|
|
142
247
|
},
|
|
143
|
-
accept(messageId) {
|
|
248
|
+
accept(messageId, stopReason) {
|
|
144
249
|
if (pending === undefined) {
|
|
145
250
|
previousMessageId = undefined;
|
|
146
251
|
stored = undefined;
|
|
252
|
+
lastStop = undefined;
|
|
147
253
|
return;
|
|
148
254
|
}
|
|
149
255
|
previousMessageId = messageId;
|
|
150
256
|
stored = pending;
|
|
151
257
|
pending = undefined;
|
|
258
|
+
lastStop = stopReason;
|
|
152
259
|
},
|
|
153
260
|
reset() {
|
|
154
261
|
previousMessageId = undefined;
|
|
155
262
|
stored = undefined;
|
|
156
263
|
pending = undefined;
|
|
264
|
+
lastStop = undefined;
|
|
157
265
|
},
|
|
158
266
|
disable() {
|
|
159
267
|
enabled = false;
|
|
160
268
|
previousMessageId = undefined;
|
|
161
269
|
stored = undefined;
|
|
162
270
|
pending = undefined;
|
|
271
|
+
lastStop = undefined;
|
|
272
|
+
},
|
|
273
|
+
carry(assistantText) {
|
|
274
|
+
if (!enabled ||
|
|
275
|
+
previousMessageId === undefined ||
|
|
276
|
+
stored === undefined ||
|
|
277
|
+
startAnchor === undefined ||
|
|
278
|
+
!extendsStart ||
|
|
279
|
+
lastStop === undefined ||
|
|
280
|
+
!TURN_ENDING_STOPS.has(lastStop)) {
|
|
281
|
+
return undefined;
|
|
282
|
+
}
|
|
283
|
+
return {
|
|
284
|
+
previousMessageId,
|
|
285
|
+
fingerprint: stored.fingerprint,
|
|
286
|
+
anchor: [...startAnchor, memoryHash("assistant", assistantText)],
|
|
287
|
+
};
|
|
163
288
|
},
|
|
164
289
|
};
|
|
165
290
|
}
|
|
@@ -198,3 +323,120 @@ export function threadRecovery(error) {
|
|
|
198
323
|
return undefined;
|
|
199
324
|
}
|
|
200
325
|
}
|
|
326
|
+
/** How long a thread is kept for the next call of its session. */
|
|
327
|
+
const SESSION_THREAD_TTL_MS = 4 * 60 * 1000; // the API drops one after 5 minutes idle
|
|
328
|
+
const SESSION_THREAD_MAX = 500;
|
|
329
|
+
/**
|
|
330
|
+
* The threads a NeuroLink instance has left behind for its sessions' next
|
|
331
|
+
* calls. In memory and per process only: another process simply creates a new
|
|
332
|
+
* thread, which is always correct. An entry is taken out by the call that
|
|
333
|
+
* continues it, because a response id can be continued once, so two concurrent
|
|
334
|
+
* calls of one session cannot both continue the same thread.
|
|
335
|
+
*/
|
|
336
|
+
export class AnthropicThreadStore {
|
|
337
|
+
entries = new Map();
|
|
338
|
+
// Bumped when a session (or everything) is cleared. A call records the epoch
|
|
339
|
+
// when it starts and may leave a thread only if it is unchanged, so a stream
|
|
340
|
+
// that finishes after its conversation was cleared cannot bring the thread
|
|
341
|
+
// back. Coarse by design: a missed reuse costs one new thread.
|
|
342
|
+
globalEpoch = 0;
|
|
343
|
+
sessionEpochs = new Map();
|
|
344
|
+
sweepTimer;
|
|
345
|
+
/**
|
|
346
|
+
* The identity of a thread's owner: who asked, in which session, with which
|
|
347
|
+
* credential and endpoint. A thread belongs to the key that created it, so
|
|
348
|
+
* the credential is part of the key (hashed; the key itself is never kept).
|
|
349
|
+
*/
|
|
350
|
+
static keyOf(parts) {
|
|
351
|
+
return sha([
|
|
352
|
+
parts.userId ?? "",
|
|
353
|
+
parts.sessionId,
|
|
354
|
+
parts.credential,
|
|
355
|
+
parts.baseURL ?? "",
|
|
356
|
+
]);
|
|
357
|
+
}
|
|
358
|
+
take(key, now = Date.now()) {
|
|
359
|
+
const entry = this.entries.get(key);
|
|
360
|
+
if (entry === undefined) {
|
|
361
|
+
return undefined;
|
|
362
|
+
}
|
|
363
|
+
this.entries.delete(key);
|
|
364
|
+
return entry.expiresAt > now ? entry.carry : undefined;
|
|
365
|
+
}
|
|
366
|
+
/** The epoch a call must hand back to `put` for its thread to be kept. */
|
|
367
|
+
epochOf(sessionId) {
|
|
368
|
+
return `${this.globalEpoch}:${this.sessionEpochs.get(sessionId) ?? 0}`;
|
|
369
|
+
}
|
|
370
|
+
put(key, sessionId, carry, epoch, now = Date.now()) {
|
|
371
|
+
if (epoch !== this.epochOf(sessionId)) {
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
this.sweep(now);
|
|
375
|
+
while (this.entries.size >= SESSION_THREAD_MAX) {
|
|
376
|
+
const oldest = this.entries.keys().next().value;
|
|
377
|
+
if (oldest === undefined) {
|
|
378
|
+
break;
|
|
379
|
+
}
|
|
380
|
+
this.entries.delete(oldest);
|
|
381
|
+
}
|
|
382
|
+
this.entries.set(key, {
|
|
383
|
+
sessionId,
|
|
384
|
+
carry,
|
|
385
|
+
expiresAt: now + SESSION_THREAD_TTL_MS,
|
|
386
|
+
});
|
|
387
|
+
this.armSweep();
|
|
388
|
+
}
|
|
389
|
+
/** Drop every entry that has expired. */
|
|
390
|
+
sweep(now = Date.now()) {
|
|
391
|
+
for (const [key, entry] of this.entries) {
|
|
392
|
+
if (entry.expiresAt <= now) {
|
|
393
|
+
this.entries.delete(key);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
// An idle store still lets go of its entries when they expire. The timer is
|
|
398
|
+
// unref'd, so it never keeps a process alive, and it stops once empty.
|
|
399
|
+
armSweep() {
|
|
400
|
+
if (this.sweepTimer !== undefined) {
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
const timer = setTimeout(() => {
|
|
404
|
+
this.sweepTimer = undefined;
|
|
405
|
+
this.sweep();
|
|
406
|
+
if (this.entries.size > 0) {
|
|
407
|
+
this.armSweep();
|
|
408
|
+
}
|
|
409
|
+
}, SESSION_THREAD_TTL_MS + 1000);
|
|
410
|
+
timer.unref?.();
|
|
411
|
+
this.sweepTimer = timer;
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Forget a session's thread, or every thread when no session is named, and
|
|
415
|
+
* fence any call still running from leaving one afterwards.
|
|
416
|
+
*/
|
|
417
|
+
forget(sessionId) {
|
|
418
|
+
if (sessionId === undefined) {
|
|
419
|
+
this.globalEpoch++;
|
|
420
|
+
this.sessionEpochs.clear();
|
|
421
|
+
this.entries.clear();
|
|
422
|
+
if (this.sweepTimer !== undefined) {
|
|
423
|
+
clearTimeout(this.sweepTimer);
|
|
424
|
+
this.sweepTimer = undefined;
|
|
425
|
+
}
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
if (this.sessionEpochs.size >= SESSION_THREAD_MAX) {
|
|
429
|
+
this.globalEpoch++;
|
|
430
|
+
this.sessionEpochs.clear();
|
|
431
|
+
}
|
|
432
|
+
this.sessionEpochs.set(sessionId, (this.sessionEpochs.get(sessionId) ?? 0) + 1);
|
|
433
|
+
for (const [key, entry] of this.entries) {
|
|
434
|
+
if (entry.sessionId === sessionId) {
|
|
435
|
+
this.entries.delete(key);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
get size() {
|
|
440
|
+
return this.entries.size;
|
|
441
|
+
}
|
|
442
|
+
}
|
package/dist/types/generate.d.ts
CHANGED
|
@@ -30,6 +30,14 @@ import type { ProcessorPipelineConfig } from "./ioProcessor.js";
|
|
|
30
30
|
* Supports multimodal content while maintaining backward compatibility
|
|
31
31
|
*/
|
|
32
32
|
export type GenerateOptions = {
|
|
33
|
+
/**
|
|
34
|
+
* Send this call's steps as an Anthropic message thread (beta); `"session"`
|
|
35
|
+
* also keeps the thread for the session's next call. The same option and the
|
|
36
|
+
* same limits as `StreamOptions.messageThreads`: native Anthropic with
|
|
37
|
+
* API-key auth only, off by default, not zero-data-retention eligible, and no
|
|
38
|
+
* way to delete a thread. See that option for the trade-offs.
|
|
39
|
+
*/
|
|
40
|
+
messageThreads?: boolean | "session";
|
|
33
41
|
/**
|
|
34
42
|
* Input content for generation. Optional for media-only modes (avatar, music,
|
|
35
43
|
* video) where all configuration lives in `output`; the SDK synthesises an
|
|
@@ -1222,6 +1230,14 @@ export type FactoryEnhancedProvider = EnhancedProvider & {
|
|
|
1222
1230
|
* Extended to support video generation mode
|
|
1223
1231
|
*/
|
|
1224
1232
|
export type TextGenerationOptions = {
|
|
1233
|
+
/**
|
|
1234
|
+
* Send this call's steps as an Anthropic message thread (beta); `"session"`
|
|
1235
|
+
* also keeps the thread for the session's next call. The same option and the
|
|
1236
|
+
* same limits as `StreamOptions.messageThreads`: native Anthropic with
|
|
1237
|
+
* API-key auth only, off by default, not zero-data-retention eligible, and no
|
|
1238
|
+
* way to delete a thread. See that option for the trade-offs.
|
|
1239
|
+
*/
|
|
1240
|
+
messageThreads?: boolean | "session";
|
|
1225
1241
|
prompt?: string;
|
|
1226
1242
|
/**
|
|
1227
1243
|
* Fraction of the model's context window at which compaction runs for this
|
|
@@ -255,6 +255,23 @@ export type AnthropicThreadPlan = {
|
|
|
255
255
|
/** The `anthropic-beta` value for this request: the client's own plus the thread beta. */
|
|
256
256
|
headers: Record<string, string>;
|
|
257
257
|
};
|
|
258
|
+
/**
|
|
259
|
+
* What one call hands the next call of the same session so it can continue the
|
|
260
|
+
* thread instead of creating another: the last stored response, the fixed
|
|
261
|
+
* fields the thread was created with, and a hash of each message the call
|
|
262
|
+
* started from (the history conversation memory rebuilt for it).
|
|
263
|
+
*/
|
|
264
|
+
export type AnthropicThreadCarry = {
|
|
265
|
+
previousMessageId: string;
|
|
266
|
+
fingerprint: string;
|
|
267
|
+
anchor: string[];
|
|
268
|
+
};
|
|
269
|
+
/** A thread a NeuroLink instance keeps for its session's next call. */
|
|
270
|
+
export type AnthropicStoredThread = {
|
|
271
|
+
sessionId: string;
|
|
272
|
+
carry: AnthropicThreadCarry;
|
|
273
|
+
expiresAt: number;
|
|
274
|
+
};
|
|
258
275
|
/**
|
|
259
276
|
* The state of one Anthropic message thread across the steps of a turn.
|
|
260
277
|
*
|
|
@@ -265,9 +282,19 @@ export type AnthropicThreadPlan = {
|
|
|
265
282
|
export type AnthropicThreadSession = {
|
|
266
283
|
/** False once the API has said it cannot thread this request. */
|
|
267
284
|
readonly enabled: boolean;
|
|
285
|
+
/**
|
|
286
|
+
* What the next call of the same session needs to continue this thread, or
|
|
287
|
+
* undefined when it cannot: the turn did not end on a normal stop, or no
|
|
288
|
+
* response was stored. `assistantText` is the text the turn streamed, which
|
|
289
|
+
* is what conversation memory will hand back as the assistant's reply.
|
|
290
|
+
*/
|
|
291
|
+
carry(assistantText: string): AnthropicThreadCarry | undefined;
|
|
268
292
|
plan(params: Anthropic.Messages.MessageCreateParams & AnthropicSamplingParams): AnthropicThreadPlan;
|
|
269
|
-
/**
|
|
270
|
-
|
|
293
|
+
/**
|
|
294
|
+
* The response was complete and stored: the next step may continue from it.
|
|
295
|
+
* `stopReason` says whether it also ended the turn.
|
|
296
|
+
*/
|
|
297
|
+
accept(messageId: string, stopReason?: string): void;
|
|
271
298
|
/** The next plan is a `create`. */
|
|
272
299
|
reset(): void;
|
|
273
300
|
/** Stop threading for the rest of the turn. */
|
package/dist/types/stream.d.ts
CHANGED
|
@@ -569,15 +569,24 @@ export type StreamOptions = {
|
|
|
569
569
|
* the thread fixes has changed (otherwise it starts a new thread), so the
|
|
570
570
|
* request stops growing with the turn. Off by default.
|
|
571
571
|
*
|
|
572
|
-
* Native Anthropic
|
|
573
|
-
* OAuth ignore it. The server keeps a thread for minutes and may drop it, in
|
|
572
|
+
* Native Anthropic (`stream()` and `generate()`) with API-key auth only;
|
|
573
|
+
* other providers and OAuth ignore it. The server keeps a thread for minutes and may drop it, in
|
|
574
574
|
* which case the step is resent in full; a change to the tools, system
|
|
575
575
|
* prompt, tool choice or earlier messages starts a new thread. Threads are
|
|
576
576
|
* not zero-data-retention eligible, and the API has no way to delete one
|
|
577
577
|
* (it expires within an hour). It was measured to shrink the request, not to
|
|
578
578
|
* lower time to first token when prompt caching is already on.
|
|
579
|
+
*
|
|
580
|
+
* `"session"` also keeps the thread for the session's next call (same user,
|
|
581
|
+
* session id, credential and endpoint; in memory on the NeuroLink instance,
|
|
582
|
+
* for up to four minutes), so that call sends only its new message. Two
|
|
583
|
+
* things to know. Conversation memory keeps only each turn's final text, so
|
|
584
|
+
* the thread still holds the tool calls and results that memory dropped: the
|
|
585
|
+
* model sees more than it would without a thread. And the thread outlives
|
|
586
|
+
* `clearConversationSession()`: NeuroLink forgets it, the server keeps it
|
|
587
|
+
* until it expires, up to an hour, and cannot be asked to delete it.
|
|
579
588
|
*/
|
|
580
|
-
messageThreads?: boolean;
|
|
589
|
+
messageThreads?: boolean | "session";
|
|
581
590
|
/** Max time with no progress before the turn ends as "stalled" (ms). Native Vertex loops only — see GenerateOptions.stallTimeoutMs. */
|
|
582
591
|
stallTimeoutMs?: number;
|
|
583
592
|
/** Remaining-time threshold that triggers the wrap-up nudge (ms). See GenerateOptions.wrapupTimeLeadMs. */
|
|
@@ -4823,6 +4823,7 @@
|
|
|
4823
4823
|
{"objectID":"57cf0f7394ea15937bfa56393a1810810e6ac4f8b0ad606cd7884760e89b051d","title":"CLI Usage","url":"/docs/getting-started/providers/anthropic#cli-usage","content":"CLI Usage","hierarchy":{"lvl0":"Getting Started","lvl1":"Anthropic Provider Guide","lvl2":"CLI Usage","lvl3":""}},
|
|
4824
4824
|
{"objectID":"363647b336363b9f2e8dae713031aec7e297f0f0fa3799cec3280131890f6226","title":"Beta Features","url":"/docs/getting-started/providers/anthropic#beta-features","content":"The Anthropic provider supports beta features via the anthropic-beta header. The following beta headers are included by default when enableBetaFeatures is true:\nclaude-code-20250219 -- Claude Code specific features\ninterleaved-thinking-2025-05-14 -- Interleaved thinking mode\nfine-grained-tool-streaming-2025-05-14 -- Fine-grained tool streaming\n\nThese correspond to the AnthropicBetaFeature enum values in src/lib/constants/enums.ts:\n\nFor OAuth mode, the beta headers are different: oauth-2025-04-20 and interleaved-thinking-2025-05-14 are sent (the claude-code-20250219 header is only included if it was present in the original request headers, as it can trigger authorization errors with OAuth tokens).","hierarchy":{"lvl0":"Getting Started","lvl1":"Anthropic Provider Guide","lvl2":"Beta Features","lvl3":""}},
|
|
4825
4825
|
{"objectID":"e8a6ea83967bb6e1e6fe7208c5e1d1aa868e114173dca65e43938b6fddca5ae6","title":"Message threads (beta)","url":"/docs/getting-started/providers/anthropic#message-threads-beta","content":"A turn with tools makes several requests, and each one carries the whole conversation so far. With messageThreads: true the first request creates an Anthropic message thread. A later request sends only the messages since the last response, plus the previous response id, while nothing the thread fixes has changed; otherwise it sends the whole conversation as a new thread. It adds the message-threads-2026-08-12 beta header to those requests.\n\nWhat to know before turning it on:\nIt shrinks the request, it did not lower latency in a measurement. Against the Messages API, with prompt caching on in both modes, a tool turn's later requests went from about 79 KB to about 0.3 KB at 25k tokens of context, and from about 337 KB to about 0.3 KB at 110k tokens. Median time to first token was the same either way (672 vs 700 ms, and 739 vs 724 ms; one model, one network, no tools in the loop). The saving is bandwidth, not time.\nStreaming stream() turns on API-key auth only. generate(), other providers and OAuth (subscription) auth ignore the option.\nIt is best-effort and the conversation stays yours. The API keeps a thread in memory for a few minutes. If it cannot continue one (thread_not_found and similar), the same step is resent once in full as a new thread. If it cannot thread the request at all (thread_unsupported_request: HIPAA or inference-hook organisations, for example), that step and the rest of the turn go out unthreaded.\nAnything a thread fixes starts a new one. A change to the tools, the system prompt, the tool choice or the earlier messages (a context reclaim, for example) is sent as a new thread rather than a continue. A forced first-step tool choice therefore makes step 2 a new thread.\nA cut-off, refused or otherwise abnormal response is never continued from.\nRetention. Threads are not zero-data-retention eligible, there is no API to delete one, and each is deleted within an hour of its last use.","hierarchy":{"lvl0":"Getting Started","lvl1":"Anthropic Provider Guide","lvl2":"Message threads (beta)","lvl3":""}},
|
|
4826
|
+
{"objectID":"34441eee0c40860138d19ffcfce73b82e33f0f9125ddee3f426680e1a095c687","title":"Across the calls of a session (messageThreads: \"session\")","url":"/docs/getting-started/providers/anthropic#across-the-calls-of-a-session-messagethreads-session","content":"\"session\" also keeps the thread for the session's next call, so that call sends only its new message instead of the whole history. The thread is found again by user (context.userId), session (context.sessionId), API key (hashed) and endpoint; it lives in memory on the NeuroLink instance for up to four minutes (the API drops an idle thread after five), and another process simply starts a new one. A call continues only if its model, tools, system prompt (without the \"you are continuing a conversation\" note NeuroLink appends once there is history) and tool choice are the same, and the history conversation memory rebuilt matches what the thread holds. Otherwise it is a new thread.\n\nThree things differ from the per-turn option, and the first two are the price of the feature:\nThe model sees more than the unthreaded path would. Conversation memory keeps only each turn's final text plus a one-line [called <tool> → ok] marker per call. The thread still holds the full tool calls and results from earlier turns, so after a tool turn a continued call has context a rebuilt-from-memory call does not. That is deliberate, and it is why this is a separate value rather than the default.\nThe thread outlives clearConversationSession(). NeuroLink forgets it, so the next call starts a new thread, but the server keeps the old one until it expires (up to an hour) and has no delete. It is not zero-data-retention eligible. There is no carve-out for the conversation-erasure write protocol: choose \"session\" only where that is acceptable.\nA continued call runs without the conversation note in its system prompt, since the thread already holds the history the note points at.","hierarchy":{"lvl0":"Getting Started","lvl1":"Anthropic Provider Guide","lvl2":"Across the calls of a session (messageThreads: \"session\")","lvl3":""}},
|
|
4826
4827
|
{"objectID":"b11311c624dc33cf3ddb6888c5ff085a18e0ce089b0db5cdb15bd2ebe2b70bf7","title":"Multimodal Capabilities","url":"/docs/getting-started/providers/anthropic#multimodal-capabilities","content":"Claude models with vision support can analyze images.","hierarchy":{"lvl0":"Getting Started","lvl1":"Anthropic Provider Guide","lvl2":"Multimodal Capabilities","lvl3":""}},
|
|
4827
4828
|
{"objectID":"b9d325e6a6e5e5934dc6e4662fa16de4b606dfc6e2184e7a41dc7e60d4d59fe8","title":"Image Analysis","url":"/docs/getting-started/providers/anthropic#image-analysis","content":"Image Analysis","hierarchy":{"lvl0":"Getting Started","lvl1":"Anthropic Provider Guide","lvl2":"Image Analysis","lvl3":""}},
|
|
4828
4829
|
{"objectID":"173aa07da1c648c3a005ea3cd6bcee2016d7a2fa4401ea8cdfe440615545abe3","title":"PDF Processing","url":"/docs/getting-started/providers/anthropic#pdf-processing","content":"PDF Processing","hierarchy":{"lvl0":"Getting Started","lvl1":"Anthropic Provider Guide","lvl2":"PDF Processing","lvl3":""}},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juspay/neurolink",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.12.0",
|
|
4
4
|
"packageManager": "pnpm@10.34.9+sha512.f49b5a8ea0fdedb44bb3c0c1d6575092a53c2950d95b7ad15df11f17974877a2de3a01c07e934e9b28ce716e51c09a94962c7306d09be2e1e4b18a8c8762fd32",
|
|
5
5
|
"description": "The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002/call) for routing, tool selection and context budgeting. MCP-native (4 transports), voice TTS/STT/realtime, RAG, agents, memory, compaction, 9 observability exporters. OpenAI · Anthropic · Gemini · Bedrock · Azure · Ollama · TypeSafe Jev and more.",
|
|
6
6
|
"author": {
|