langwatch 0.0.3 → 0.1.1
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/{chunk-AP23NJ57.mjs → chunk-OVS4NSDE.mjs} +373 -2
- package/dist/chunk-OVS4NSDE.mjs.map +1 -0
- package/dist/index.d.mts +47 -5
- package/dist/index.d.ts +47 -5
- package/dist/index.js +6275 -485
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +329 -349
- package/dist/index.mjs.map +1 -1
- package/dist/{utils-Dg5eWsAz.d.mts → utils-K-jSEpnZ.d.mts} +11 -7
- package/dist/{utils-Dg5eWsAz.d.ts → utils-K-jSEpnZ.d.ts} +11 -7
- package/dist/utils.d.mts +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +370 -0
- package/dist/utils.js.map +1 -1
- package/dist/utils.mjs +3 -1
- package/example/README.md +3 -1
- package/example/app/(chat)/chat/[id]/page.tsx +1 -1
- package/example/app/(chat)/page.tsx +10 -5
- package/example/app/langchain/page.tsx +27 -0
- package/example/app/langchain-rag/page.tsx +28 -0
- package/example/app/share/[id]/page.tsx +1 -1
- package/example/components/chat-list.tsx +1 -1
- package/example/components/chat-panel.tsx +1 -1
- package/example/components/header.tsx +35 -13
- package/example/components/prompt-form.tsx +1 -1
- package/example/components/stocks/stock-purchase.tsx +1 -1
- package/example/components/stocks/stocks.tsx +1 -1
- package/example/lib/chat/langchain-rag.tsx +191 -0
- package/example/lib/chat/langchain.tsx +112 -0
- package/example/lib/chat/{actions.tsx → vercel-ai.tsx} +4 -6
- package/example/package-lock.json +287 -4
- package/example/package.json +1 -0
- package/package.json +12 -2
- package/src/index.test.ts +96 -28
- package/src/index.ts +18 -9
- package/src/langchain.ts +557 -0
- package/src/types.ts +4 -4
- package/src/utils.ts +28 -1
- package/dist/chunk-AP23NJ57.mjs.map +0 -1
- /package/src/{helpers.ts → typeUtils.ts} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,49 @@
|
|
|
1
1
|
import EventEmitter from 'events';
|
|
2
|
-
import { M as Metadata, C as CollectorRESTParams, S as Span, P as PendingBaseSpan, a as PendingLLMSpan, b as PendingRAGSpan, c as SpanTypes } from './utils-
|
|
3
|
-
export { B as BaseSpan, d as ChatMessage, e as ChatRichContent, L as LLMSpan, R as RAGSpan, f as SpanInputOutput, h as captureError, g as convertFromVercelAIMessages } from './utils-
|
|
2
|
+
import { M as Metadata, C as CollectorRESTParams, S as Span, P as PendingBaseSpan, a as PendingLLMSpan, b as PendingRAGSpan, c as SpanTypes } from './utils-K-jSEpnZ.js';
|
|
3
|
+
export { B as BaseSpan, d as ChatMessage, e as ChatRichContent, L as LLMSpan, R as RAGSpan, f as SpanInputOutput, i as autoconvertTypedValues, h as captureError, g as convertFromVercelAIMessages } from './utils-K-jSEpnZ.js';
|
|
4
|
+
import { AgentAction, AgentFinish } from '@langchain/core/agents';
|
|
5
|
+
import { BaseCallbackHandler } from '@langchain/core/callbacks/base';
|
|
6
|
+
import { DocumentInterface } from '@langchain/core/documents';
|
|
7
|
+
import { Serialized } from '@langchain/core/load/serializable';
|
|
8
|
+
import { BaseMessage } from '@langchain/core/messages';
|
|
9
|
+
import { LLMResult } from '@langchain/core/outputs';
|
|
10
|
+
import { ChainValues } from '@langchain/core/utils/types';
|
|
4
11
|
import 'ai';
|
|
5
12
|
import 'llm-cost/model_prices_and_context_window.json';
|
|
6
13
|
|
|
14
|
+
declare class LangWatchCallbackHandler extends BaseCallbackHandler {
|
|
15
|
+
name: string;
|
|
16
|
+
trace: LangWatchTrace;
|
|
17
|
+
spans: Record<string, LangWatchSpan>;
|
|
18
|
+
constructor({ trace }: {
|
|
19
|
+
trace: LangWatchTrace;
|
|
20
|
+
});
|
|
21
|
+
handleLLMStart(llm: Serialized, prompts: string[], runId: string, parentRunId?: string | undefined, extraParams?: Record<string, unknown> | undefined, _tags?: string[] | undefined, metadata?: Record<string, unknown> | undefined, name?: string): Promise<void>;
|
|
22
|
+
private buildLLMSpan;
|
|
23
|
+
handleChatModelStart(llm: Serialized, messages: BaseMessage[][], runId: string, parentRunId?: string | undefined, extraParams?: Record<string, unknown> | undefined, tags?: string[] | undefined, metadata?: Record<string, unknown> | undefined, name?: string): Promise<void>;
|
|
24
|
+
handleNewToken(_token: string, runId: string): Promise<void>;
|
|
25
|
+
handleLLMEnd(response: LLMResult, runId: string, _parentRunId?: string | undefined): Promise<void>;
|
|
26
|
+
handleLLMError(err: Error, runId: string, _parentRunId?: string | undefined): Promise<void>;
|
|
27
|
+
handleChainStart(chain: Serialized, inputs: ChainValues, runId: string, parentRunId?: string | undefined, _tags?: string[] | undefined, _metadata?: Record<string, unknown> | undefined, _runType?: string, name?: string): Promise<void>;
|
|
28
|
+
handleChainEnd(output: ChainValues, runId: string, _parentRunId?: string | undefined): Promise<void>;
|
|
29
|
+
handleChainError(err: Error, runId: string, _parentRunId?: string | undefined, _tags?: string[] | undefined, _kwargs?: {
|
|
30
|
+
inputs?: Record<string, unknown> | undefined;
|
|
31
|
+
} | undefined): Promise<void>;
|
|
32
|
+
handleToolStart(tool: Serialized, input: string, runId: string, parentRunId?: string | undefined, _tags?: string[] | undefined, _metadata?: Record<string, unknown> | undefined, name?: string): Promise<void>;
|
|
33
|
+
handleToolEnd(output: string, runId: string, _parentRunId?: string | undefined): Promise<void>;
|
|
34
|
+
handleToolError(err: Error, runId: string, _parentRunId?: string | undefined, _tags?: string[] | undefined): Promise<void>;
|
|
35
|
+
handleRetrieverStart(retriever: Serialized, query: string, runId: string, parentRunId?: string | undefined, _tags?: string[] | undefined, _metadata?: Record<string, unknown> | undefined, name?: string | undefined): Promise<void>;
|
|
36
|
+
handleRetrieverEnd(documents: DocumentInterface<Record<string, any>>[], runId: string, _parentRunId?: string | undefined, _tags?: string[] | undefined): Promise<void>;
|
|
37
|
+
handleRetrieverError(err: Error, runId: string, _parentRunId?: string | undefined, _tags?: string[] | undefined): Promise<void>;
|
|
38
|
+
handleAgentAction(_action: AgentAction, runId: string, _parentRunId?: string | undefined, _tags?: string[] | undefined): Promise<void>;
|
|
39
|
+
handleAgentEnd(action: AgentFinish, runId: string, _parentRunId?: string | undefined, _tags?: string[] | undefined): Promise<void>;
|
|
40
|
+
private buildSpan;
|
|
41
|
+
private endSpan;
|
|
42
|
+
private errorSpan;
|
|
43
|
+
private autoconvertTypedValues;
|
|
44
|
+
private getParent;
|
|
45
|
+
}
|
|
46
|
+
|
|
7
47
|
declare class LangWatch extends EventEmitter {
|
|
8
48
|
apiKey: string | undefined;
|
|
9
49
|
endpoint: string;
|
|
@@ -24,6 +64,7 @@ declare class LangWatchTrace {
|
|
|
24
64
|
metadata?: Metadata;
|
|
25
65
|
finishedSpans: Record<string, Span>;
|
|
26
66
|
timeoutRef?: NodeJS.Timeout;
|
|
67
|
+
langchainCallback?: LangWatchCallbackHandler;
|
|
27
68
|
constructor({ client, traceId, metadata, }: {
|
|
28
69
|
client: LangWatch;
|
|
29
70
|
traceId: string;
|
|
@@ -35,6 +76,7 @@ declare class LangWatchTrace {
|
|
|
35
76
|
startSpan(params: Omit<Partial<PendingBaseSpan>, "parentId">): LangWatchSpan;
|
|
36
77
|
startLLMSpan(params: Omit<Partial<PendingLLMSpan>, "parentId">): LangWatchLLMSpan;
|
|
37
78
|
startRAGSpan(params: Omit<Partial<PendingRAGSpan>, "parentId">): LangWatchRAGSpan;
|
|
79
|
+
getLangChainCallback(): LangWatchCallbackHandler;
|
|
38
80
|
onEnd(span: Span): void;
|
|
39
81
|
delayedSendSpans(): void;
|
|
40
82
|
sendSpans(): Promise<void>;
|
|
@@ -45,12 +87,12 @@ declare class LangWatchSpan implements PendingBaseSpan {
|
|
|
45
87
|
parentId?: string | null;
|
|
46
88
|
type: SpanTypes;
|
|
47
89
|
name?: string | null;
|
|
48
|
-
input
|
|
49
|
-
|
|
90
|
+
input?: PendingBaseSpan["input"];
|
|
91
|
+
output?: PendingBaseSpan["output"];
|
|
50
92
|
error?: PendingBaseSpan["error"];
|
|
51
93
|
timestamps: PendingBaseSpan["timestamps"];
|
|
52
94
|
metrics: PendingBaseSpan["metrics"];
|
|
53
|
-
constructor({ trace, spanId, parentId, type, name, input,
|
|
95
|
+
constructor({ trace, spanId, parentId, type, name, input, output, error, timestamps, metrics, }: Partial<PendingBaseSpan> & {
|
|
54
96
|
trace: LangWatchTrace;
|
|
55
97
|
});
|
|
56
98
|
update(params: Partial<Omit<PendingBaseSpan, "spanId" | "parentId">>): void;
|