@juspay/neurolink 11.16.2 → 11.17.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.
@@ -27,6 +27,19 @@ export type AgenticLoopUsage = {
27
27
  cacheReadTokens?: number;
28
28
  cacheWriteTokens?: number;
29
29
  reasoningTokens?: number;
30
+ /**
31
+ * Cache writes split by time-to-live, which Anthropic reports separately
32
+ * from the total under `cache_creation.ephemeral_5m_input_tokens` and
33
+ * `ephemeral_1h_input_tokens`.
34
+ *
35
+ * Carried because the Claude-on-Vertex turn span reports both as
36
+ * `input_cache_creation_5m` / `_1h`, and `cacheWriteTokens` alone cannot
37
+ * reconstruct them — the two tiers are priced differently, so collapsing
38
+ * them loses the only signal that says which one a turn actually bought.
39
+ * Undefined for providers that never report the split.
40
+ */
41
+ cacheWrite5mTokens?: number;
42
+ cacheWrite1hTokens?: number;
30
43
  };
31
44
  export type AgenticLoopStepResult<TRaw = unknown> = {
32
45
  text: string;
@@ -191,15 +204,46 @@ export type AgenticLoopAdapter<TConversation = unknown, TRaw = unknown> = {
191
204
  * Anthropic has never had one, and setting it for both would change native
192
205
  * Anthropic's behaviour under the guise of a shared refactor.
193
206
  */
194
- export type AnthropicLoopAdapterConfig = {
195
- client: Pick<Anthropic, "messages">;
207
+ /**
208
+ * Construction input for `createAnthropicLoopAdapter`, shared by direct
209
+ * Anthropic and Claude-on-Vertex.
210
+ *
211
+ * Parameterized on the message shape because the two do NOT agree on it.
212
+ * Direct Anthropic uses the SDK's `MessageParam`; Claude-on-Vertex carries its
213
+ * own `VertexAnthropicMessage`, whose role union is narrower
214
+ * ("user" | "assistant", no "system") and whose image `media_type` is a plain
215
+ * string rather than the SDK's four-way union. Neither is assignable to the
216
+ * other, so pinning the adapter to one of them locked the other out entirely.
217
+ * The engine has been generic over its conversation type all along; this makes
218
+ * the adapter config match.
219
+ */
220
+ export type AnthropicLoopAdapterConfig<TMessage = Anthropic.Messages.MessageParam> = {
221
+ /**
222
+ * Only `messages.create` is ever called, so only that is required.
223
+ *
224
+ * `Pick<Anthropic, "messages">` looked equivalent and is not: it demands the
225
+ * FULL `Messages` resource, including `batches` and the private `_client`.
226
+ * That excludes `AnthropicVertex`, whose `MessagesResource` is structurally
227
+ * smaller but has the one method this adapter uses — a client the adapter
228
+ * can drive perfectly, rejected for members it never touches.
229
+ */
230
+ client: {
231
+ messages: Pick<Anthropic["messages"], "create">;
232
+ };
196
233
  maxSteps: number;
197
234
  /**
198
235
  * Build one step's request. A closure so the per-turn work the caller
199
236
  * already does — system prompt, tool declarations, sampling, thinking
200
237
  * config, cache breakpoints — stays where it is rather than moving here.
201
238
  */
202
- buildParams: (conversation: Anthropic.Messages.MessageParam[], step: number) => Anthropic.Messages.MessageCreateParams;
239
+ /**
240
+ * Returns the NON-streaming params. The adapter adds `stream: true` itself,
241
+ * so requiring the streaming variant here would force every caller to
242
+ * declare a literal `true` it does not control — and a caller whose params
243
+ * type carries `stream?: boolean` fails to match `stream: true` for a field
244
+ * the adapter is about to overwrite.
245
+ */
246
+ buildParams: (conversation: TMessage[], step: number) => Anthropic.Messages.MessageCreateParamsNonStreaming;
203
247
  /** The turn's live tool record, used for deferred-catalog resolution. */
204
248
  toolsRecord: Record<string, Tool>;
205
249
  /**
@@ -234,7 +278,7 @@ export type AnthropicLoopAdapterConfig = {
234
278
  * both every step with nothing else bounding growth, so a migration that
235
279
  * drops this overflows the window mid-turn.
236
280
  */
237
- planReclaim?: (conversation: Anthropic.Messages.MessageParam[], step: number) => Anthropic.Messages.MessageParam[] | undefined;
281
+ planReclaim?: (conversation: TMessage[], step: number) => AgenticLoopReclaimResult<TMessage[]> | undefined;
238
282
  /**
239
283
  * Calibration feedback for the provider's reclaim guard: the FULL prompt
240
284
  * size for the step just made — uncached input plus both cache tiers.
@@ -268,6 +312,21 @@ export type GeminiToolExecutionGuards = {
268
312
  * legitimately slow tool reads as a stalled turn without this.
269
313
  */
270
314
  onProgress?: () => void;
315
+ /**
316
+ * Wrap one tool call in the provider's own observability.
317
+ *
318
+ * A function rather than a pair of start/end callbacks, because the caller
319
+ * needs the execution to happen INSIDE its span's context — spans opened by
320
+ * the tool itself must nest under the tool call, not dangle as siblings of
321
+ * the turn. Handing over the whole invocation is the only shape that lets a
322
+ * caller do `context.with(span, run)`.
323
+ *
324
+ * The caller awaits `run()` itself, so it sees the settled result and can
325
+ * mark a FAILURE THAT WAS RETURNED rather than thrown: MCP tools report
326
+ * errors in their payload, and an observation that only watches for
327
+ * exceptions records those calls as successful.
328
+ */
329
+ withToolSpan?: <T>(name: string, run: () => Promise<T>) => Promise<T>;
271
330
  };
272
331
  /** What one Gemini step produced, carried to `buildToolResultMessages`. */
273
332
  export type GeminiStepRaw = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juspay/neurolink",
3
- "version": "11.16.2",
3
+ "version": "11.17.0",
4
4
  "packageManager": "pnpm@10.15.1",
5
5
  "description": "TypeScript AI SDK with 24+ LLM providers behind one consistent API. MCP-native (connect any MCP server), voice TTS/STT/realtime, RAG, agents, memory, context compaction. OpenAI · Anthropic · Gemini · Bedrock · Azure · Ollama · DeepSeek · NVIDIA NIM and more.",
6
6
  "author": {
@@ -40,6 +40,8 @@
40
40
  "prepack": "svelte-kit sync && svelte-package && pnpm run build:react-hooks && pnpm run build:cli && pnpm run build:browser && publint",
41
41
  "build:react-hooks": "npx tsc --jsx react-jsx --module nodenext --moduleResolution nodenext --target esnext --esModuleInterop --skipLibCheck --outDir dist --declaration false src/lib/client/reactHooks.tsx",
42
42
  "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json && tsc --noEmit --strict",
43
+ "check:ci-scripts": "svelte-kit sync && tsc -p tsconfig.ci-scripts.json",
44
+ "check:test-parse": "node scripts/parse-check-tests.mjs",
43
45
  "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
44
46
  "typecheck": "tsc --noEmit",
45
47
  "modelServer": "tsx scripts/modelServer.ts",