@niadra/sdk 0.1.0 → 0.7.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.
Files changed (133) hide show
  1. package/CHANGELOG.md +161 -20
  2. package/README.md +484 -38
  3. package/dist/ai-sdk.cjs +1037 -0
  4. package/dist/ai-sdk.cjs.map +1 -0
  5. package/dist/ai-sdk.d.cts +118 -0
  6. package/dist/ai-sdk.d.ts +118 -0
  7. package/dist/ai-sdk.js +1030 -0
  8. package/dist/ai-sdk.js.map +1 -0
  9. package/dist/anthropic.cjs +528 -0
  10. package/dist/anthropic.cjs.map +1 -0
  11. package/dist/anthropic.d.cts +35 -0
  12. package/dist/anthropic.d.ts +35 -0
  13. package/dist/anthropic.js +523 -0
  14. package/dist/anthropic.js.map +1 -0
  15. package/dist/bedrock.cjs +392 -0
  16. package/dist/bedrock.cjs.map +1 -0
  17. package/dist/bedrock.d.cts +25 -0
  18. package/dist/bedrock.d.ts +25 -0
  19. package/dist/bedrock.js +388 -0
  20. package/dist/bedrock.js.map +1 -0
  21. package/dist/cli.js +11045 -0
  22. package/dist/cli.js.map +1 -0
  23. package/dist/client-DsIxZxZk.d.cts +6905 -0
  24. package/dist/client-DsIxZxZk.d.ts +6905 -0
  25. package/dist/cloudflare-agents.cjs +626 -0
  26. package/dist/cloudflare-agents.cjs.map +1 -0
  27. package/dist/cloudflare-agents.d.cts +113 -0
  28. package/dist/cloudflare-agents.d.ts +113 -0
  29. package/dist/cloudflare-agents.js +622 -0
  30. package/dist/cloudflare-agents.js.map +1 -0
  31. package/dist/elevenlabs.cjs +738 -0
  32. package/dist/elevenlabs.cjs.map +1 -0
  33. package/dist/elevenlabs.d.cts +86 -0
  34. package/dist/elevenlabs.d.ts +86 -0
  35. package/dist/elevenlabs.js +733 -0
  36. package/dist/elevenlabs.js.map +1 -0
  37. package/dist/genkit.cjs +323 -0
  38. package/dist/genkit.cjs.map +1 -0
  39. package/dist/genkit.d.cts +67 -0
  40. package/dist/genkit.d.ts +67 -0
  41. package/dist/genkit.js +318 -0
  42. package/dist/genkit.js.map +1 -0
  43. package/dist/google-adk.cjs +705 -0
  44. package/dist/google-adk.cjs.map +1 -0
  45. package/dist/google-adk.d.cts +91 -0
  46. package/dist/google-adk.d.ts +91 -0
  47. package/dist/google-adk.js +701 -0
  48. package/dist/google-adk.js.map +1 -0
  49. package/dist/google-genai.cjs +422 -0
  50. package/dist/google-genai.cjs.map +1 -0
  51. package/dist/google-genai.d.cts +26 -0
  52. package/dist/google-genai.d.ts +26 -0
  53. package/dist/google-genai.js +418 -0
  54. package/dist/google-genai.js.map +1 -0
  55. package/dist/index.cjs +11449 -1796
  56. package/dist/index.cjs.map +1 -1
  57. package/dist/index.d.cts +1006 -1247
  58. package/dist/index.d.ts +1006 -1247
  59. package/dist/index.js +11393 -1797
  60. package/dist/index.js.map +1 -1
  61. package/dist/intercept-0_lJE6k1.d.cts +20 -0
  62. package/dist/intercept-D7qFCaRb.d.ts +20 -0
  63. package/dist/langchain.cjs +1077 -0
  64. package/dist/langchain.cjs.map +1 -0
  65. package/dist/langchain.d.cts +102 -0
  66. package/dist/langchain.d.ts +102 -0
  67. package/dist/langchain.js +1068 -0
  68. package/dist/langchain.js.map +1 -0
  69. package/dist/livekit.cjs +404 -0
  70. package/dist/livekit.cjs.map +1 -0
  71. package/dist/livekit.d.cts +113 -0
  72. package/dist/livekit.d.ts +113 -0
  73. package/dist/livekit.js +398 -0
  74. package/dist/livekit.js.map +1 -0
  75. package/dist/llamaindex.cjs +349 -0
  76. package/dist/llamaindex.cjs.map +1 -0
  77. package/dist/llamaindex.d.cts +92 -0
  78. package/dist/llamaindex.d.ts +92 -0
  79. package/dist/llamaindex.js +344 -0
  80. package/dist/llamaindex.js.map +1 -0
  81. package/dist/mastra.cjs +1082 -0
  82. package/dist/mastra.cjs.map +1 -0
  83. package/dist/mastra.d.cts +86 -0
  84. package/dist/mastra.d.ts +86 -0
  85. package/dist/mastra.js +1075 -0
  86. package/dist/mastra.js.map +1 -0
  87. package/dist/openai-agents.cjs +465 -0
  88. package/dist/openai-agents.cjs.map +1 -0
  89. package/dist/openai-agents.d.cts +75 -0
  90. package/dist/openai-agents.d.ts +75 -0
  91. package/dist/openai-agents.js +459 -0
  92. package/dist/openai-agents.js.map +1 -0
  93. package/dist/retell.cjs +846 -0
  94. package/dist/retell.cjs.map +1 -0
  95. package/dist/retell.d.cts +161 -0
  96. package/dist/retell.d.ts +161 -0
  97. package/dist/retell.js +841 -0
  98. package/dist/retell.js.map +1 -0
  99. package/dist/shared-Bb5B59Bu.d.ts +39 -0
  100. package/dist/shared-DTPWVlWm.d.cts +39 -0
  101. package/dist/strands.cjs +352 -0
  102. package/dist/strands.cjs.map +1 -0
  103. package/dist/strands.d.cts +72 -0
  104. package/dist/strands.d.ts +72 -0
  105. package/dist/strands.js +347 -0
  106. package/dist/strands.js.map +1 -0
  107. package/dist/twilio.cjs +174 -0
  108. package/dist/twilio.cjs.map +1 -0
  109. package/dist/twilio.d.cts +64 -0
  110. package/dist/twilio.d.ts +64 -0
  111. package/dist/twilio.js +167 -0
  112. package/dist/twilio.js.map +1 -0
  113. package/dist/vapi.cjs +661 -0
  114. package/dist/vapi.cjs.map +1 -0
  115. package/dist/vapi.d.cts +78 -0
  116. package/dist/vapi.d.ts +78 -0
  117. package/dist/vapi.js +656 -0
  118. package/dist/vapi.js.map +1 -0
  119. package/dist/voltagent.cjs +509 -0
  120. package/dist/voltagent.cjs.map +1 -0
  121. package/dist/voltagent.d.cts +70 -0
  122. package/dist/voltagent.d.ts +70 -0
  123. package/dist/voltagent.js +503 -0
  124. package/dist/voltagent.js.map +1 -0
  125. package/dist/webhook-1ozGyksG.d.ts +37 -0
  126. package/dist/webhook-CG4om_DK.d.cts +37 -0
  127. package/dist/whatsapp.cjs +214 -0
  128. package/dist/whatsapp.cjs.map +1 -0
  129. package/dist/whatsapp.d.cts +81 -0
  130. package/dist/whatsapp.d.ts +81 -0
  131. package/dist/whatsapp.js +207 -0
  132. package/dist/whatsapp.js.map +1 -0
  133. package/package.json +355 -7
@@ -0,0 +1,102 @@
1
+ import { BaseCallbackHandler } from '@langchain/core/callbacks/base';
2
+ import { BaseMessage } from '@langchain/core/messages';
3
+ import { LLMResult } from '@langchain/core/outputs';
4
+ import { Runnable } from '@langchain/core/runnables';
5
+ import { DynamicStructuredTool } from '@langchain/core/tools';
6
+ import { g as ModelUsage } from './client-DsIxZxZk.js';
7
+ import { S as SessionResolver, a as ProofSource, A as AgentMemoryOption, b as Session } from './shared-Bb5B59Bu.js';
8
+ export { P as Proof, c as attestationProof } from './shared-Bb5B59Bu.js';
9
+ import { Serialized } from '@langchain/core/load/serializable';
10
+
11
+ /**
12
+ * Niadra for LangChain.js and LangGraph.js (`@langchain/core` 1.x).
13
+ *
14
+ * - `niadraContext(session)` is a runnable for LCEL chains (`niadraContext(convo).pipe(model)`):
15
+ * it takes the messages (or `{ messages }`), records the customer's newest message, and returns
16
+ * them with the pack as a system message after the leading system messages and the suffix
17
+ * appended to the last human message. `withNiadraContext(session, messages)` does the same
18
+ * inside a LangGraph node, right before the model call, so nothing lands in the graph's state.
19
+ * - `NiadraCallbackHandler` records the model's answers with the usage LangChain standardizes
20
+ * (`usage_metadata`, prompt cache reads and writes included). Answers that only call tools
21
+ * record nothing. With `{ turns: true }` each top-level run (a chain, a graph, an agent, or a
22
+ * chat model called alone) is a turn record, with its tool calls (the provider's call ids) and
23
+ * its model calls with their tokens; a run inside a turn in progress (`conversation.turn()`)
24
+ * records into it. A function wrapped with `tool()` inside a tool takes over its call, which is
25
+ * how a replay answers it from the record.
26
+ * - `niadraTools(session)` is the navigation kit as structured tools bound to the customer.
27
+ *
28
+ * Fail-open: when Niadra is slow or down, the messages go to the model as they came.
29
+ */
30
+
31
+ interface NiadraContextOptions {
32
+ /** What your app proved about the user, recorded once before the first context read. */
33
+ verify?: ProofSource;
34
+ /** Records the newest human message as the customer's turn. Defaults to `true`. */
35
+ recordCustomer?: boolean;
36
+ /** Puts the agent's own notes before the customer's context. Pass the same to `niadraTools`. */
37
+ agentMemory?: AgentMemoryOption;
38
+ }
39
+ /**
40
+ * The messages with the context in place: the prefix (the agent's notes and the customer's pack)
41
+ * after the leading system messages, the suffix at the end of the last human message. Records
42
+ * the newest human message once. Returns a new array; never throws.
43
+ */
44
+ declare function withNiadraContext(session: Session, messages: readonly BaseMessage[], options?: NiadraContextOptions): Promise<BaseMessage[]>;
45
+ /**
46
+ * A runnable that puts the context into the messages, for LCEL: `niadraContext(convo).pipe(model)`.
47
+ * Takes a list of messages or `{ messages }`. With a function in place of the session, it finds
48
+ * the session per call; `null` passes the messages through.
49
+ */
50
+ declare function niadraContext(session: SessionResolver, options?: NiadraContextOptions): Runnable<BaseMessage[] | {
51
+ messages: BaseMessage[];
52
+ }, BaseMessage[]>;
53
+ interface NiadraCallbackOptions {
54
+ /** Records each top-level run as a turn, with its tool and model calls. Defaults to `false`. */
55
+ turns?: boolean;
56
+ }
57
+ /**
58
+ * Records the model's answers as the agent's turns, with their usage, and with `turns: true` the
59
+ * turn record of each top-level run. Pass it in `callbacks` of the model or of the whole run; with
60
+ * a function in place of the session, it finds the session per callback.
61
+ */
62
+ declare class NiadraCallbackHandler extends BaseCallbackHandler {
63
+ private readonly session;
64
+ name: string;
65
+ private readonly hooks;
66
+ /** Each nested run's top-level run, whose turn it records into. */
67
+ private readonly roots;
68
+ constructor(session: SessionResolver, options?: NiadraCallbackOptions);
69
+ /** The same handler: the turns it holds open are shared by every run it is passed to. */
70
+ copy(): this;
71
+ handleChainStart(_chain: Serialized, _inputs: unknown, runId: string, runType?: string, _tags?: string[], _metadata?: Record<string, unknown>, _runName?: string, parentRunId?: string): void;
72
+ handleChainEnd(_outputs: unknown, runId: string): void;
73
+ handleChainError(error: Error, runId: string): void;
74
+ handleChatModelStart(_llm: Serialized, _messages: BaseMessage[][], runId: string, parentRunId?: string): void;
75
+ handleToolStart(tool: Serialized, input: string, runId: string, parentRunId?: string, _tags?: string[], _metadata?: Record<string, unknown>, runName?: string, toolCallId?: string): void;
76
+ handleToolEnd(output: unknown, runId: string): void;
77
+ handleToolError(error: Error, runId: string): void;
78
+ handleLLMEnd(output: LLMResult, runId?: string): void;
79
+ handleLLMError(error: Error, runId: string): void;
80
+ private started;
81
+ private ended;
82
+ private rootOf;
83
+ private model;
84
+ }
85
+ /** The navigation kit as LangChain structured tools, bound to the session's customer. */
86
+ /** The tool metadata key `recordTools()` sets: a replay answers the tool from the record. */
87
+ declare const RECORDED = "niadra_recorded";
88
+ /**
89
+ * Your LangChain tools with each call recorded in the turn it runs in, and answered from the record in a replay.
90
+ * `dryRun` names the tools a replay may run for real when the record has no answer. A tool without a function
91
+ * of its own (`func`) is refused: wrap what it calls with `tool()`.
92
+ */
93
+ declare function recordTools(tools: readonly DynamicStructuredTool[], options?: {
94
+ dryRun?: readonly string[];
95
+ }): DynamicStructuredTool[];
96
+ declare function niadraTools(session: Session, options?: {
97
+ agentMemory?: AgentMemoryOption;
98
+ }): DynamicStructuredTool[];
99
+ /** An AI message's `usage_metadata` as a `ModelUsage`: input tokens include the cached ones. */
100
+ declare function langchainUsage(message: BaseMessage): ModelUsage | null;
101
+
102
+ export { AgentMemoryOption, NiadraCallbackHandler, type NiadraCallbackOptions, type NiadraContextOptions, ProofSource, RECORDED, Session, SessionResolver, langchainUsage, niadraContext, niadraTools, recordTools, withNiadraContext };