@osohq/langchain 0.1.0 → 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/README.md +66 -134
- package/dist/callbacks.d.ts +36 -51
- package/dist/callbacks.d.ts.map +1 -1
- package/dist/callbacks.js +136 -211
- package/dist/callbacks.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +9 -7
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# @osohq/langchain
|
|
2
2
|
|
|
3
|
-
Oso
|
|
3
|
+
Oso integration for LangChain 0.x agents.
|
|
4
4
|
|
|
5
|
-
Callback handler that automatically captures and sends all LangChain agent events to Oso
|
|
5
|
+
Callback handler that automatically captures and sends all LangChain agent events to Oso for monitoring, debugging, and security analysis.
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -19,138 +19,61 @@ yarn add @osohq/langchain
|
|
|
19
19
|
## Quick Start
|
|
20
20
|
|
|
21
21
|
```typescript
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
22
|
+
import { OsoCallback } from "@osohq/langchain";
|
|
23
|
+
import { createReactAgent } from "@langchain/langgraph/prebuilt";
|
|
24
24
|
import { ChatOpenAI } from "@langchain/openai";
|
|
25
25
|
|
|
26
|
-
// Create the callback (reads
|
|
27
|
-
const callback = new
|
|
26
|
+
// Create the callback (reads API key from OSO_AUTH environment variable)
|
|
27
|
+
const callback = new OsoCallback({
|
|
28
28
|
agentId: "my-support-agent",
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
-
//
|
|
31
|
+
// Create your agent
|
|
32
32
|
const llm = new ChatOpenAI({ model: "gpt-4" });
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
const tools = [tool1, tool2, tool3];
|
|
34
|
+
const prompt = "You help.";
|
|
35
|
+
const agent = await createReactAgent({ llm, tools, prompt });
|
|
36
|
+
|
|
37
|
+
// Use your agent -- NOTE: make sure you pass the callback into
|
|
38
|
+
// the `invoke` method, rather than attaching it to a particular
|
|
39
|
+
// LangGraph node, so that all events are captured.
|
|
40
|
+
const result = await agent.invoke({
|
|
41
|
+
input: "help!",
|
|
42
|
+
}, {
|
|
37
43
|
callbacks: [callback],
|
|
38
44
|
});
|
|
39
|
-
|
|
40
|
-
// Use your agent - all events are automatically captured
|
|
41
|
-
const result = await agentExecutor.invoke({
|
|
42
|
-
input: "Hello, how can I help?",
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
// Clean up
|
|
46
|
-
await callback.close();
|
|
47
45
|
```
|
|
48
46
|
|
|
49
47
|
## Configuration
|
|
50
48
|
|
|
51
49
|
### Environment Variables
|
|
52
50
|
|
|
53
|
-
Set these in your environment
|
|
51
|
+
Set these in your environment:
|
|
54
52
|
|
|
55
53
|
```bash
|
|
56
|
-
# Required: Your Oso
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
# Optional: Custom Oso endpoint (defaults to https://cloud.osohq.com/api/events)
|
|
60
|
-
OSO_ENDPOINT=https://cloud.osohq.com/api/events
|
|
54
|
+
# Required: Your Oso API key
|
|
55
|
+
OSO_AUTH=your-oso-api-key
|
|
61
56
|
|
|
62
|
-
# Optional:
|
|
63
|
-
|
|
57
|
+
# Optional: Custom Oso endpoint (defaults to https://cloud.osohq.com)
|
|
58
|
+
OSO_URL=https://cloud.osohq.com
|
|
64
59
|
```
|
|
65
60
|
|
|
66
61
|
### Constructor Parameters
|
|
67
62
|
|
|
68
63
|
```typescript
|
|
69
|
-
new
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
sessionId: "unique-session-
|
|
74
|
-
|
|
75
|
-
|
|
64
|
+
new OsoCallback({
|
|
65
|
+
url: "https://cloud.osohq.com", // Oso API URL (default: OSO_URL env var or https://cloud.osohq.com)
|
|
66
|
+
apiKey: "your-api-key", // Oso API key (default: OSO_AUTH env var)
|
|
67
|
+
agentId: "my-agent", // Agent identifier for tracking (default: "default-agent")
|
|
68
|
+
sessionId: "unique-session-uuid", // Session ID to group related conversations (default: auto-generated UUID)
|
|
69
|
+
users: [{ type: "User", id: "user-123" }], // Users associated with this session
|
|
70
|
+
metadata: { environment: "production" }, // Additional metadata to attach to all events
|
|
71
|
+
logger: (level, message, metadata) => console.log(level, message, metadata), // Custom logging function
|
|
76
72
|
});
|
|
77
73
|
```
|
|
78
74
|
|
|
79
75
|
All parameters are optional and fall back to environment variables or defaults.
|
|
80
76
|
|
|
81
|
-
## What Gets Captured
|
|
82
|
-
|
|
83
|
-
The callback automatically captures all LangChain events:
|
|
84
|
-
|
|
85
|
-
### LLM Events
|
|
86
|
-
|
|
87
|
-
- Model name and configuration
|
|
88
|
-
- Prompts sent to the LLM
|
|
89
|
-
- Generated responses
|
|
90
|
-
- Token usage (prompt, completion, total)
|
|
91
|
-
- Errors and failures
|
|
92
|
-
|
|
93
|
-
### Tool Events
|
|
94
|
-
|
|
95
|
-
- Tool name and description
|
|
96
|
-
- Input parameters
|
|
97
|
-
- Output/results
|
|
98
|
-
- Execution duration (milliseconds)
|
|
99
|
-
- Errors and stack traces
|
|
100
|
-
|
|
101
|
-
### Agent Events
|
|
102
|
-
|
|
103
|
-
- Agent reasoning and thought process
|
|
104
|
-
- Tool selection decisions
|
|
105
|
-
- Tool input parameters
|
|
106
|
-
- Final outputs
|
|
107
|
-
- Complete execution flow
|
|
108
|
-
|
|
109
|
-
### Chain Events
|
|
110
|
-
|
|
111
|
-
- Chain type and name
|
|
112
|
-
- Input parameters
|
|
113
|
-
- Output values
|
|
114
|
-
- Nested chain execution
|
|
115
|
-
|
|
116
|
-
### Execution Summary
|
|
117
|
-
|
|
118
|
-
At the end of each agent execution, a summary event is sent with:
|
|
119
|
-
|
|
120
|
-
- Total execution duration
|
|
121
|
-
- Number of LLM calls, tool calls, and agent steps
|
|
122
|
-
- Total token usage
|
|
123
|
-
- Error count
|
|
124
|
-
- Complete execution trace
|
|
125
|
-
|
|
126
|
-
## Event Structure
|
|
127
|
-
|
|
128
|
-
Every event sent to Oso has this structure:
|
|
129
|
-
|
|
130
|
-
```json
|
|
131
|
-
{
|
|
132
|
-
"event_type": "tool.completed",
|
|
133
|
-
"execution_id": "unique-execution-id",
|
|
134
|
-
"session_id": "conversation-session-id",
|
|
135
|
-
"timestamp": "2024-02-15T10:30:45.123Z",
|
|
136
|
-
"agent_id": "my-agent",
|
|
137
|
-
"data": {
|
|
138
|
-
/* event-specific data */
|
|
139
|
-
},
|
|
140
|
-
"metadata": {
|
|
141
|
-
/* your custom metadata */
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
### Event Types
|
|
147
|
-
|
|
148
|
-
- `llm.started` / `llm.completed` / `llm.error`
|
|
149
|
-
- `tool.started` / `tool.completed` / `tool.error`
|
|
150
|
-
- `agent.action` / `agent.finished`
|
|
151
|
-
- `chain.started` / `chain.completed` / `chain.error`
|
|
152
|
-
- `execution.summary` - Final summary with all accumulated data
|
|
153
|
-
|
|
154
77
|
## Error Handling
|
|
155
78
|
|
|
156
79
|
The callback is designed to fail gracefully:
|
|
@@ -161,22 +84,32 @@ The callback is designed to fail gracefully:
|
|
|
161
84
|
|
|
162
85
|
## Logging
|
|
163
86
|
|
|
164
|
-
The callback
|
|
87
|
+
The callback supports custom logging through the `logger` configuration option:
|
|
165
88
|
|
|
166
89
|
```typescript
|
|
167
|
-
|
|
168
|
-
|
|
90
|
+
const callback = new OsoCallback({
|
|
91
|
+
agentId: "my-agent",
|
|
92
|
+
logger: (level, message, metadata) => {
|
|
93
|
+
console.log(`[${level.toUpperCase()}] ${message}`, metadata);
|
|
94
|
+
},
|
|
95
|
+
});
|
|
169
96
|
```
|
|
170
97
|
|
|
98
|
+
The logger function receives three parameters:
|
|
99
|
+
- `level`: One of "error", "warn", "info", or "debug"
|
|
100
|
+
- `message`: The log message string
|
|
101
|
+
- `metadata`: Optional additional context (object)
|
|
102
|
+
|
|
171
103
|
## Examples
|
|
172
104
|
|
|
173
105
|
### Basic Agent with Tools
|
|
174
106
|
|
|
175
107
|
```typescript
|
|
176
|
-
import {
|
|
108
|
+
import { OsoCallback } from "@osohq/langchain";
|
|
177
109
|
import { createOpenAIToolsAgent, AgentExecutor } from "langchain/agents";
|
|
178
110
|
import { ChatOpenAI } from "@langchain/openai";
|
|
179
111
|
import { tool } from "@langchain/core/tools";
|
|
112
|
+
import { z } from "zod";
|
|
180
113
|
|
|
181
114
|
const searchOrders = tool(
|
|
182
115
|
async ({ customerId }: { customerId: string }) => {
|
|
@@ -192,36 +125,31 @@ const searchOrders = tool(
|
|
|
192
125
|
);
|
|
193
126
|
|
|
194
127
|
async function main() {
|
|
195
|
-
const callback = new
|
|
128
|
+
const callback = new OsoCallback({ agentId: "support-agent" });
|
|
196
129
|
|
|
197
130
|
const llm = new ChatOpenAI({ model: "gpt-4o-mini" });
|
|
198
131
|
const tools = [searchOrders];
|
|
199
132
|
|
|
200
133
|
const agent = await createOpenAIToolsAgent({ llm, tools, prompt });
|
|
201
|
-
const agentExecutor = new AgentExecutor({
|
|
202
|
-
agent,
|
|
203
|
-
tools,
|
|
204
|
-
callbacks: [callback],
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
const result = await agentExecutor.invoke({
|
|
208
|
-
input: "Find orders for customer CUST001",
|
|
209
|
-
});
|
|
134
|
+
const agentExecutor = new AgentExecutor({ agent, tools });
|
|
210
135
|
|
|
211
|
-
|
|
136
|
+
const result = await agentExecutor.invoke(
|
|
137
|
+
{ input: "Find orders for customer CUST001" },
|
|
138
|
+
{ callbacks: [callback] }
|
|
139
|
+
);
|
|
212
140
|
|
|
213
|
-
|
|
141
|
+
console.log(result);
|
|
214
142
|
}
|
|
215
143
|
```
|
|
216
144
|
|
|
217
|
-
### With Custom Metadata
|
|
145
|
+
### With Custom Metadata and Users
|
|
218
146
|
|
|
219
147
|
```typescript
|
|
220
|
-
const callback = new
|
|
148
|
+
const callback = new OsoCallback({
|
|
221
149
|
agentId: "support-agent",
|
|
222
150
|
sessionId: "user-session-123",
|
|
151
|
+
users: [{ type: "User", id: "user-456" }],
|
|
223
152
|
metadata: {
|
|
224
|
-
userId: "user-456",
|
|
225
153
|
environment: "production",
|
|
226
154
|
version: "1.2.3",
|
|
227
155
|
},
|
|
@@ -236,20 +164,24 @@ import { randomUUID } from "crypto";
|
|
|
236
164
|
const sessionId = randomUUID();
|
|
237
165
|
|
|
238
166
|
// Agent 1
|
|
239
|
-
const callback1 = new
|
|
167
|
+
const callback1 = new OsoCallback({
|
|
240
168
|
agentId: "agent-1",
|
|
241
169
|
sessionId,
|
|
242
170
|
});
|
|
243
|
-
const result1 = await agent1Executor.invoke(
|
|
244
|
-
|
|
171
|
+
const result1 = await agent1Executor.invoke(
|
|
172
|
+
{ input: "..." },
|
|
173
|
+
{ callbacks: [callback1] }
|
|
174
|
+
);
|
|
245
175
|
|
|
246
176
|
// Agent 2 - same session
|
|
247
|
-
const callback2 = new
|
|
177
|
+
const callback2 = new OsoCallback({
|
|
248
178
|
agentId: "agent-2",
|
|
249
179
|
sessionId,
|
|
250
180
|
});
|
|
251
|
-
const result2 = await agent2Executor.invoke(
|
|
252
|
-
|
|
181
|
+
const result2 = await agent2Executor.invoke(
|
|
182
|
+
{ input: "..." },
|
|
183
|
+
{ callbacks: [callback2] }
|
|
184
|
+
);
|
|
253
185
|
```
|
|
254
186
|
|
|
255
187
|
## TypeScript Support
|
|
@@ -258,8 +190,8 @@ This package is written in TypeScript and includes full type definitions. All ty
|
|
|
258
190
|
|
|
259
191
|
## Requirements
|
|
260
192
|
|
|
261
|
-
- Node.js
|
|
262
|
-
- @langchain/core >=
|
|
193
|
+
- Node.js 20.0.0 or higher
|
|
194
|
+
- @langchain/core >=0.1.0, <1.0.0
|
|
263
195
|
|
|
264
196
|
## License
|
|
265
197
|
|
package/dist/callbacks.d.ts
CHANGED
|
@@ -1,79 +1,64 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* LangChain callback handler for Oso
|
|
2
|
+
* LangChain callback handler for Oso integration.
|
|
3
3
|
*
|
|
4
4
|
* Example usage:
|
|
5
|
-
* import {
|
|
5
|
+
* import { OsoCallback } from '@osohq/langchain';
|
|
6
6
|
*
|
|
7
|
-
* const callback = new
|
|
8
|
-
*
|
|
9
|
-
* agentId: "my-support-agent"
|
|
7
|
+
* const callback = new OsoCallback({
|
|
8
|
+
* apiKey: "your-oso-api-key",
|
|
9
|
+
* agentId: "my-support-agent",
|
|
10
|
+
* users: [{ type: "User", id: "user-123" }]
|
|
10
11
|
* });
|
|
11
12
|
*
|
|
12
|
-
* const agent = createAgent({
|
|
13
|
-
* const result = await agent.invoke({ input: "Hello" });
|
|
14
|
-
* await callback.close();
|
|
13
|
+
* const agent = createAgent({ llm, tools, prompt });
|
|
14
|
+
* const result = await agent.invoke({ input: "Hello" }, { callbacks: [callback] });
|
|
15
15
|
*/
|
|
16
16
|
import { BaseCallbackHandler } from "@langchain/core/callbacks/base";
|
|
17
|
-
import type { AgentAction, AgentFinish } from "@langchain/core/agents";
|
|
18
|
-
import type { LLMResult } from "@langchain/core/outputs";
|
|
19
17
|
import type { Serialized } from "@langchain/core/load/serializable";
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
import type { ChainValues } from "@langchain/core/utils/types";
|
|
19
|
+
export type LogLevel = "error" | "warn" | "info" | "debug";
|
|
20
|
+
export type LoggingFn = (level: LogLevel, message: string, metadata?: Record<string, any>) => void;
|
|
21
|
+
export type Value = {
|
|
22
|
+
type: string;
|
|
23
|
+
id: string;
|
|
24
|
+
};
|
|
25
|
+
export interface OsoCallbackConfig {
|
|
26
|
+
/** Oso API URL (default: OSO_URL env var or https://cloud.osohq.com) */
|
|
27
|
+
url?: string;
|
|
28
|
+
/** Oso API key (default: OSO_AUTH env var) */
|
|
29
|
+
apiKey?: string;
|
|
27
30
|
/** Session ID to group related conversations (default: auto-generated UUID) */
|
|
28
31
|
sessionId?: string;
|
|
29
32
|
/** Additional metadata to attach to all events */
|
|
30
33
|
metadata?: Record<string, any>;
|
|
31
34
|
/** Agent identifier for tracking (default: "default-agent") */
|
|
32
35
|
agentId?: string;
|
|
36
|
+
/** Users associated with this session */
|
|
37
|
+
users?: Value[];
|
|
38
|
+
logger?: LoggingFn;
|
|
33
39
|
}
|
|
34
40
|
/**
|
|
35
|
-
* LangChain callback handler that sends agent events to Oso
|
|
36
|
-
*
|
|
37
|
-
* Automatically captures:
|
|
38
|
-
* - LLM calls (model, prompts, responses, token usage)
|
|
39
|
-
* - Tool executions (name, inputs, outputs, duration, errors)
|
|
40
|
-
* - Agent reasoning (decisions, thoughts, intermediate steps)
|
|
41
|
-
* - Chain executions (starts, ends, inputs, outputs)
|
|
42
|
-
* - Errors at any stage
|
|
41
|
+
* LangChain callback handler that sends agent events to Oso.
|
|
43
42
|
*/
|
|
44
|
-
export declare class
|
|
43
|
+
export declare class OsoCallback extends BaseCallbackHandler {
|
|
45
44
|
name: string;
|
|
46
|
-
private
|
|
47
|
-
private
|
|
48
|
-
private enabled;
|
|
45
|
+
private url;
|
|
46
|
+
private apiKey?;
|
|
49
47
|
private sessionId;
|
|
50
48
|
private metadata;
|
|
51
49
|
private agentId;
|
|
52
|
-
private
|
|
53
|
-
private
|
|
54
|
-
private
|
|
55
|
-
private
|
|
56
|
-
|
|
57
|
-
private
|
|
58
|
-
|
|
59
|
-
constructor(config?: OsoObservabilityCallbackConfig);
|
|
60
|
-
handleLLMStart(llm: Serialized, prompts: string[], runId: string, parentRunId?: string, extraParams?: Record<string, any>, tags?: string[], metadata?: Record<string, any>): Promise<void>;
|
|
61
|
-
handleLLMEnd(output: LLMResult, runId: string, parentRunId?: string): Promise<void>;
|
|
62
|
-
handleLLMError(error: Error, runId: string, parentRunId?: string): Promise<void>;
|
|
63
|
-
handleToolStart(tool: Serialized, input: string, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, any>): Promise<void>;
|
|
50
|
+
private users;
|
|
51
|
+
private logger;
|
|
52
|
+
private rootRunId?;
|
|
53
|
+
private toolNames;
|
|
54
|
+
constructor(config?: OsoCallbackConfig);
|
|
55
|
+
private getEventBase;
|
|
56
|
+
handleToolStart(tool: Serialized, input: string, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, any>, runName?: string): Promise<void>;
|
|
64
57
|
handleToolEnd(output: string, runId: string, parentRunId?: string): Promise<void>;
|
|
65
58
|
handleToolError(error: Error, runId: string, parentRunId?: string): Promise<void>;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
handleChainStart(chain: Serialized, inputs: Record<string, any>, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, any>): Promise<void>;
|
|
69
|
-
handleChainEnd(outputs: Record<string, any>, runId: string, parentRunId?: string): Promise<void>;
|
|
59
|
+
handleChainStart(chain: Serialized, inputs: ChainValues, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, any>): Promise<void>;
|
|
60
|
+
handleChainEnd(outputs: ChainValues, runId: string, parentRunId?: string): Promise<void>;
|
|
70
61
|
handleChainError(error: Error, runId: string, parentRunId?: string): Promise<void>;
|
|
71
62
|
private sendEvent;
|
|
72
|
-
private sendExecutionSummary;
|
|
73
|
-
/**
|
|
74
|
-
* Clean up resources. Call this when you're done using the callback.
|
|
75
|
-
*/
|
|
76
|
-
close(): Promise<void>;
|
|
77
63
|
}
|
|
78
|
-
export {};
|
|
79
64
|
//# sourceMappingURL=callbacks.d.ts.map
|
package/dist/callbacks.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"callbacks.d.ts","sourceRoot":"","sources":["../src/callbacks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC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,SAAS;CAiDxB"}
|
package/dist/callbacks.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* LangChain callback handler for Oso
|
|
3
|
+
* LangChain callback handler for Oso integration.
|
|
4
4
|
*
|
|
5
5
|
* Example usage:
|
|
6
|
-
* import {
|
|
6
|
+
* import { OsoCallback } from '@osohq/langchain';
|
|
7
7
|
*
|
|
8
|
-
* const callback = new
|
|
9
|
-
*
|
|
10
|
-
* agentId: "my-support-agent"
|
|
8
|
+
* const callback = new OsoCallback({
|
|
9
|
+
* apiKey: "your-oso-api-key",
|
|
10
|
+
* agentId: "my-support-agent",
|
|
11
|
+
* users: [{ type: "User", id: "user-123" }]
|
|
11
12
|
* });
|
|
12
13
|
*
|
|
13
|
-
* const agent = createAgent({
|
|
14
|
-
* const result = await agent.invoke({ input: "Hello" });
|
|
15
|
-
* await callback.close();
|
|
14
|
+
* const agent = createAgent({ llm, tools, prompt });
|
|
15
|
+
* const result = await agent.invoke({ input: "Hello" }, { callbacks: [callback] });
|
|
16
16
|
*/
|
|
17
17
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
18
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -27,271 +27,196 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
28
28
|
};
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.
|
|
30
|
+
exports.OsoCallback = void 0;
|
|
31
31
|
const base_1 = require("@langchain/core/callbacks/base");
|
|
32
32
|
const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
|
33
33
|
const crypto_1 = require("crypto");
|
|
34
34
|
/**
|
|
35
|
-
* LangChain callback handler that sends agent events to Oso
|
|
36
|
-
*
|
|
37
|
-
* Automatically captures:
|
|
38
|
-
* - LLM calls (model, prompts, responses, token usage)
|
|
39
|
-
* - Tool executions (name, inputs, outputs, duration, errors)
|
|
40
|
-
* - Agent reasoning (decisions, thoughts, intermediate steps)
|
|
41
|
-
* - Chain executions (starts, ends, inputs, outputs)
|
|
42
|
-
* - Errors at any stage
|
|
35
|
+
* LangChain callback handler that sends agent events to Oso.
|
|
43
36
|
*/
|
|
44
|
-
class
|
|
37
|
+
class OsoCallback extends base_1.BaseCallbackHandler {
|
|
45
38
|
constructor(config = {}) {
|
|
46
39
|
super();
|
|
47
|
-
this.name = "
|
|
48
|
-
|
|
49
|
-
this.
|
|
50
|
-
this.
|
|
51
|
-
this.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
config.
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
40
|
+
this.name = "OsoCallback";
|
|
41
|
+
this.logger = config.logger || (() => { });
|
|
42
|
+
this.url = new URL("api/agents/event", config.url || process.env.OSO_URL || "https://cloud.osohq.com");
|
|
43
|
+
this.apiKey = config.apiKey || process.env.OSO_AUTH;
|
|
44
|
+
if (!this.apiKey) {
|
|
45
|
+
this.logger("warn", "No API key provided for OsoCallback -- no events will be sent.");
|
|
46
|
+
}
|
|
47
|
+
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
48
|
+
if (config.sessionId && uuidRegex.test(config.sessionId)) {
|
|
49
|
+
this.sessionId = config.sessionId;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
if (config.sessionId) {
|
|
53
|
+
this.logger("warn", `Invalid UUID provided for sessionId: ${config.sessionId}. Generating a new one.`);
|
|
54
|
+
}
|
|
55
|
+
this.sessionId = (0, crypto_1.randomUUID)();
|
|
56
|
+
}
|
|
64
57
|
this.metadata = config.metadata || {};
|
|
65
58
|
this.agentId = config.agentId || "default-agent";
|
|
66
|
-
this.
|
|
67
|
-
this.
|
|
68
|
-
this.
|
|
69
|
-
|
|
70
|
-
`agentId=${this.agentId}, sessionId=${this.sessionId}, enabled=${this.enabled}`);
|
|
59
|
+
this.users = config.users || [];
|
|
60
|
+
this.toolNames = new Map();
|
|
61
|
+
this.logger("debug", `OsoCallback initialized: url=${this.url}, ` +
|
|
62
|
+
`agentId=${this.agentId}, sessionId=${this.sessionId}`);
|
|
71
63
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
-
var _a;
|
|
76
|
-
const modelName = (llm === null || llm === void 0 ? void 0 : llm.name) || ((_a = llm === null || llm === void 0 ? void 0 : llm.id) === null || _a === void 0 ? void 0 : _a[llm.id.length - 1]) || "unknown";
|
|
77
|
-
yield this.sendEvent("llm.started", {
|
|
78
|
-
model: modelName,
|
|
79
|
-
prompts,
|
|
80
|
-
num_prompts: prompts.length,
|
|
81
|
-
});
|
|
82
|
-
});
|
|
64
|
+
getEventBase() {
|
|
65
|
+
return Object.assign({ agent_id: this.agentId, session_id: this.sessionId, users: this.users, timestamp: new Date().toISOString() }, this.metadata);
|
|
83
66
|
}
|
|
84
|
-
|
|
67
|
+
// Tool callbacks
|
|
68
|
+
handleToolStart(tool, input, runId, parentRunId, tags, metadata, runName) {
|
|
85
69
|
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
const toolName = (tool === null || tool === void 0 ? void 0 : tool.name) || runName || "unknown";
|
|
71
|
+
this.toolNames.set(runId, toolName);
|
|
72
|
+
let toolParameters;
|
|
86
73
|
try {
|
|
87
|
-
|
|
88
|
-
const tokenUsage = llmOutput.tokenUsage || {};
|
|
89
|
-
const generations = [];
|
|
90
|
-
if (output.generations) {
|
|
91
|
-
for (const genList of output.generations) {
|
|
92
|
-
for (const gen of genList) {
|
|
93
|
-
generations.push({
|
|
94
|
-
text: gen.text || String(gen),
|
|
95
|
-
metadata: gen.generationInfo || {},
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
const callData = {
|
|
101
|
-
model: llmOutput.modelName || "unknown",
|
|
102
|
-
generations,
|
|
103
|
-
token_usage: {
|
|
104
|
-
prompt_tokens: tokenUsage.promptTokens || 0,
|
|
105
|
-
completion_tokens: tokenUsage.completionTokens || 0,
|
|
106
|
-
total_tokens: tokenUsage.totalTokens || 0,
|
|
107
|
-
},
|
|
108
|
-
};
|
|
109
|
-
this.llmCalls.push(callData);
|
|
110
|
-
yield this.sendEvent("llm.completed", callData);
|
|
74
|
+
toolParameters = JSON.parse(input);
|
|
111
75
|
}
|
|
112
|
-
catch (
|
|
113
|
-
|
|
114
|
-
yield this.sendEvent("llm.error", { error: String(error) });
|
|
76
|
+
catch (_a) {
|
|
77
|
+
toolParameters = { input };
|
|
115
78
|
}
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
handleLLMError(error, runId, parentRunId) {
|
|
119
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
-
const errorData = {
|
|
121
|
-
error_type: error.constructor.name,
|
|
122
|
-
error_message: error.message,
|
|
123
|
-
};
|
|
124
|
-
this.errors.push(Object.assign({ type: "llm_error" }, errorData));
|
|
125
|
-
yield this.sendEvent("llm.error", errorData);
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
// Tool callbacks
|
|
129
|
-
handleToolStart(tool, input, runId, parentRunId, tags, metadata) {
|
|
130
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
131
|
-
const toolName = (tool === null || tool === void 0 ? void 0 : tool.name) || "unknown";
|
|
132
|
-
const toolDescription = (tool === null || tool === void 0 ? void 0 : tool.description) || "";
|
|
133
|
-
this.toolStartTimes.set(runId, Date.now());
|
|
134
|
-
yield this.sendEvent("tool.started", {
|
|
135
|
-
tool_name: toolName,
|
|
136
|
-
tool_description: toolDescription,
|
|
137
|
-
input,
|
|
138
|
-
run_id: runId,
|
|
139
|
-
});
|
|
79
|
+
yield this.sendEvent("tool_call_request", Object.assign(Object.assign({}, this.getEventBase()), { tool_name: toolName, tool_parameters: toolParameters }));
|
|
140
80
|
});
|
|
141
81
|
}
|
|
142
82
|
handleToolEnd(output, runId, parentRunId) {
|
|
143
83
|
return __awaiter(this, void 0, void 0, function* () {
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
output
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
yield this.sendEvent("
|
|
153
|
-
this.
|
|
84
|
+
const toolName = this.toolNames.get(runId) || "unknown";
|
|
85
|
+
let toolResult;
|
|
86
|
+
try {
|
|
87
|
+
toolResult = JSON.parse(output);
|
|
88
|
+
}
|
|
89
|
+
catch (_a) {
|
|
90
|
+
toolResult = output;
|
|
91
|
+
}
|
|
92
|
+
yield this.sendEvent("tool_call_response", Object.assign(Object.assign({}, this.getEventBase()), { tool_name: toolName, tool_result: toolResult }));
|
|
93
|
+
this.toolNames.delete(runId);
|
|
154
94
|
});
|
|
155
95
|
}
|
|
156
96
|
handleToolError(error, runId, parentRunId) {
|
|
157
97
|
return __awaiter(this, void 0, void 0, function* () {
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
error_type: error.constructor.name,
|
|
162
|
-
error_message: error.message,
|
|
163
|
-
duration_ms: durationMs,
|
|
164
|
-
run_id: runId,
|
|
165
|
-
};
|
|
166
|
-
this.errors.push(Object.assign({ type: "tool_error" }, errorData));
|
|
167
|
-
yield this.sendEvent("tool.error", errorData);
|
|
168
|
-
this.toolStartTimes.delete(runId);
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
// Agent callbacks
|
|
172
|
-
handleAgentAction(action, runId, parentRunId) {
|
|
173
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
174
|
-
const stepData = {
|
|
175
|
-
step_type: "action",
|
|
176
|
-
tool: action.tool,
|
|
177
|
-
tool_input: action.toolInput,
|
|
178
|
-
reasoning: action.log,
|
|
179
|
-
};
|
|
180
|
-
this.agentSteps.push(stepData);
|
|
181
|
-
yield this.sendEvent("agent.action", stepData);
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
handleAgentEnd(action, runId, parentRunId) {
|
|
185
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
186
|
-
const finishData = {
|
|
187
|
-
return_values: action.returnValues,
|
|
188
|
-
final_reasoning: action.log || null,
|
|
189
|
-
};
|
|
190
|
-
yield this.sendEvent("agent.finished", finishData);
|
|
191
|
-
yield this.sendExecutionSummary();
|
|
98
|
+
const toolName = this.toolNames.get(runId) || "unknown";
|
|
99
|
+
yield this.sendEvent("tool_call_error", Object.assign(Object.assign({}, this.getEventBase()), { tool_name: toolName, error: error.message }));
|
|
100
|
+
this.toolNames.delete(runId);
|
|
192
101
|
});
|
|
193
102
|
}
|
|
194
103
|
// Chain callbacks
|
|
195
104
|
handleChainStart(chain, inputs, runId, parentRunId, tags, metadata) {
|
|
196
105
|
return __awaiter(this, void 0, void 0, function* () {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
106
|
+
if (!parentRunId) {
|
|
107
|
+
this.rootRunId = runId;
|
|
108
|
+
let message = "";
|
|
109
|
+
if (typeof inputs === "string") {
|
|
110
|
+
message = inputs;
|
|
111
|
+
}
|
|
112
|
+
else if (inputs.input) {
|
|
113
|
+
message =
|
|
114
|
+
typeof inputs.input === "string"
|
|
115
|
+
? inputs.input
|
|
116
|
+
: JSON.stringify(inputs.input);
|
|
117
|
+
}
|
|
118
|
+
else if (inputs.question) {
|
|
119
|
+
message =
|
|
120
|
+
typeof inputs.question === "string"
|
|
121
|
+
? inputs.question
|
|
122
|
+
: JSON.stringify(inputs.question);
|
|
123
|
+
}
|
|
124
|
+
else if (inputs.messages && Array.isArray(inputs.messages)) {
|
|
125
|
+
const lastMessage = inputs.messages[inputs.messages.length - 1];
|
|
126
|
+
message = (lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.content) || JSON.stringify(lastMessage);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
message = JSON.stringify(inputs);
|
|
130
|
+
}
|
|
131
|
+
yield this.sendEvent("message_from_user", Object.assign(Object.assign({}, this.getEventBase()), { message }));
|
|
132
|
+
}
|
|
203
133
|
});
|
|
204
134
|
}
|
|
205
135
|
handleChainEnd(outputs, runId, parentRunId) {
|
|
206
136
|
return __awaiter(this, void 0, void 0, function* () {
|
|
207
|
-
|
|
137
|
+
if (runId === this.rootRunId) {
|
|
138
|
+
let message = "";
|
|
139
|
+
if (typeof outputs === "string") {
|
|
140
|
+
message = outputs;
|
|
141
|
+
}
|
|
142
|
+
else if (outputs.output) {
|
|
143
|
+
message =
|
|
144
|
+
typeof outputs.output === "string"
|
|
145
|
+
? outputs.output
|
|
146
|
+
: JSON.stringify(outputs.output);
|
|
147
|
+
}
|
|
148
|
+
else if (outputs.text) {
|
|
149
|
+
message =
|
|
150
|
+
typeof outputs.text === "string"
|
|
151
|
+
? outputs.text
|
|
152
|
+
: JSON.stringify(outputs.text);
|
|
153
|
+
}
|
|
154
|
+
else if (outputs.response) {
|
|
155
|
+
message =
|
|
156
|
+
typeof outputs.response === "string"
|
|
157
|
+
? outputs.response
|
|
158
|
+
: JSON.stringify(outputs.response);
|
|
159
|
+
}
|
|
160
|
+
else if (outputs.messages && Array.isArray(outputs.messages)) {
|
|
161
|
+
const lastMessage = outputs.messages[outputs.messages.length - 1];
|
|
162
|
+
message = (lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.content) || JSON.stringify(lastMessage);
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
message = JSON.stringify(outputs);
|
|
166
|
+
}
|
|
167
|
+
yield this.sendEvent("message_to_user", Object.assign(Object.assign({}, this.getEventBase()), { message }));
|
|
168
|
+
this.rootRunId = undefined;
|
|
169
|
+
}
|
|
208
170
|
});
|
|
209
171
|
}
|
|
210
172
|
handleChainError(error, runId, parentRunId) {
|
|
211
173
|
return __awaiter(this, void 0, void 0, function* () {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
};
|
|
216
|
-
this.errors.push(Object.assign({ type: "chain_error" }, errorData));
|
|
217
|
-
yield this.sendEvent("chain.error", errorData);
|
|
174
|
+
if (runId === this.rootRunId) {
|
|
175
|
+
this.rootRunId = undefined;
|
|
176
|
+
}
|
|
218
177
|
});
|
|
219
178
|
}
|
|
220
179
|
// Internal methods
|
|
221
|
-
sendEvent(
|
|
180
|
+
sendEvent(path, payload) {
|
|
222
181
|
return __awaiter(this, void 0, void 0, function* () {
|
|
223
|
-
if (!this.
|
|
182
|
+
if (!this.apiKey) {
|
|
183
|
+
this.logger("warn", "Not sending event because no API key is set", {
|
|
184
|
+
path,
|
|
185
|
+
payload,
|
|
186
|
+
});
|
|
224
187
|
return;
|
|
225
188
|
}
|
|
189
|
+
const url = `${this.url}/${path}`;
|
|
226
190
|
try {
|
|
227
|
-
|
|
228
|
-
event_type: eventType,
|
|
229
|
-
execution_id: this.executionId,
|
|
230
|
-
session_id: this.sessionId,
|
|
231
|
-
timestamp: new Date().toISOString().replace("+00:00", "Z"),
|
|
232
|
-
data,
|
|
233
|
-
metadata: this.metadata,
|
|
234
|
-
agent_id: this.agentId,
|
|
235
|
-
};
|
|
236
|
-
console.debug(`Sending event: ${eventType}`);
|
|
191
|
+
this.logger("debug", `Sending event to ${path}`);
|
|
237
192
|
const headers = {
|
|
238
193
|
"Content-Type": "application/json",
|
|
194
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
239
195
|
};
|
|
240
|
-
|
|
241
|
-
headers["Authorization"] = `Bearer ${this.authToken}`;
|
|
242
|
-
}
|
|
243
|
-
const response = yield (0, cross_fetch_1.default)(this.endpoint, {
|
|
196
|
+
const response = yield (0, cross_fetch_1.default)(url, {
|
|
244
197
|
method: "POST",
|
|
245
198
|
headers,
|
|
246
199
|
body: JSON.stringify(payload),
|
|
247
200
|
});
|
|
248
201
|
if (![200, 201, 202].includes(response.status)) {
|
|
249
|
-
|
|
202
|
+
this.logger("warn", `Oso backend returned ${response.status} for ${path}`);
|
|
203
|
+
const text = yield response.text();
|
|
204
|
+
this.logger("error", `Response body: ${text}`);
|
|
250
205
|
}
|
|
251
206
|
else {
|
|
252
|
-
|
|
207
|
+
this.logger("debug", `Event sent successfully to ${path}`);
|
|
253
208
|
}
|
|
254
209
|
}
|
|
255
210
|
catch (error) {
|
|
256
211
|
if (error instanceof Error) {
|
|
257
|
-
|
|
212
|
+
this.logger("error", `Error sending event to ${path}: ${error.constructor.name}: ${error.message}`);
|
|
258
213
|
}
|
|
259
214
|
else {
|
|
260
|
-
|
|
215
|
+
this.logger("error", `Error sending event to ${path}: ${error}`);
|
|
261
216
|
}
|
|
262
217
|
}
|
|
263
218
|
});
|
|
264
219
|
}
|
|
265
|
-
sendExecutionSummary() {
|
|
266
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
267
|
-
const durationMs = Date.now() - this.executionStartTime;
|
|
268
|
-
const totalTokens = this.llmCalls.reduce((sum, call) => sum + (call.token_usage.total_tokens || 0), 0);
|
|
269
|
-
const summary = {
|
|
270
|
-
execution_id: this.executionId,
|
|
271
|
-
session_id: this.sessionId,
|
|
272
|
-
duration_ms: durationMs,
|
|
273
|
-
llm_calls_count: this.llmCalls.length,
|
|
274
|
-
tool_calls_count: this.toolCalls.length,
|
|
275
|
-
agent_steps_count: this.agentSteps.length,
|
|
276
|
-
errors_count: this.errors.length,
|
|
277
|
-
total_tokens: totalTokens,
|
|
278
|
-
llm_calls: this.llmCalls,
|
|
279
|
-
tool_calls: this.toolCalls,
|
|
280
|
-
agent_steps: this.agentSteps,
|
|
281
|
-
errors: this.errors,
|
|
282
|
-
};
|
|
283
|
-
yield this.sendEvent("execution.summary", summary);
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
/**
|
|
287
|
-
* Clean up resources. Call this when you're done using the callback.
|
|
288
|
-
*/
|
|
289
|
-
close() {
|
|
290
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
291
|
-
console.debug("OsoObservabilityCallback closed");
|
|
292
|
-
// No persistent connections to close in this implementation
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
220
|
}
|
|
296
|
-
exports.
|
|
221
|
+
exports.OsoCallback = OsoCallback;
|
|
297
222
|
//# sourceMappingURL=callbacks.js.map
|
package/dist/callbacks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"callbacks.js","sourceRoot":"","sources":["../src/callbacks.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;AAEH,yDAAqE;
|
|
1
|
+
{"version":3,"file":"callbacks.js","sourceRoot":"","sources":["../src/callbacks.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;AAEH,yDAAqE;AAGrE,8DAAgC;AAChC,mCAAoC;AAuCpC;;GAEG;AACH,MAAa,WAAY,SAAQ,0BAAmB;IAclD,YAAY,SAA4B,EAAE;QACxC,KAAK,EAAE,CAAC;QAdV,SAAI,GAAG,aAAa,CAAC;QAgBnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QAE1C,IAAI,CAAC,GAAG,GAAG,IAAI,GAAG,CAChB,kBAAkB,EAClB,MAAM,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,yBAAyB,CAC/D,CAAC;QAEF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;QACpD,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,IAAI,CAAC,MAAM,CACT,MAAM,EACN,gEAAgE,CACjE,CAAC;QACJ,CAAC;QAED,MAAM,SAAS,GACb,iEAAiE,CAAC;QACpE,IAAI,MAAM,CAAC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O;oBACP,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;iBAC9B,CAAC,CAAC;gBAEH,IAAI,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;oBAC/C,IAAI,CAAC,MAAM,CACT,MAAM,EACN,wBAAwB,QAAQ,CAAC,MAAM,QAAQ,IAAI,EAAE,CACtD,CAAC;oBACF,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;oBACnC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,kBAAkB,IAAI,EAAE,CAAC,CAAC;gBACjD,CAAC;qBAAM,CAAC;oBACN,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,8BAA8B,IAAI,EAAE,CAAC,CAAC;gBAC7D,CAAC;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;oBAC3B,IAAI,CAAC,MAAM,CACT,OAAO,EACP,0BAA0B,IAAI,KAAK,KAAK,CAAC,WAAW,CAAC,IAAI,KAAK,KAAK,CAAC,OAAO,EAAE,CAC9E,CAAC;gBACJ,CAAC;qBAAM,CAAC;oBACN,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,0BAA0B,IAAI,KAAK,KAAK,EAAE,CAAC,CAAC;gBACnE,CAAC;YACH,CAAC;QACH,CAAC;KAAA;CACF;AApRD,kCAoRC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* Oso observability integration for LangChain.
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.VERSION = exports.
|
|
6
|
+
exports.VERSION = exports.OsoCallback = void 0;
|
|
7
7
|
var callbacks_1 = require("./callbacks");
|
|
8
|
-
Object.defineProperty(exports, "
|
|
8
|
+
Object.defineProperty(exports, "OsoCallback", { enumerable: true, get: function () { return callbacks_1.OsoCallback; } });
|
|
9
9
|
var version_1 = require("./version");
|
|
10
10
|
Object.defineProperty(exports, "VERSION", { enumerable: true, get: function () { return version_1.VERSION; } });
|
|
11
11
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,yCAA0C;AAAjC,wGAAA,WAAW,OAAA;AACpB,qCAAoC;AAA3B,kGAAA,OAAO,OAAA"}
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.1.
|
|
1
|
+
export declare const VERSION = "0.1.1";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@osohq/langchain",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Oso
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Oso integration for LangChain agents",
|
|
5
5
|
"engines": {
|
|
6
|
-
"node": ">=
|
|
6
|
+
"node": ">=20.0.0"
|
|
7
7
|
},
|
|
8
8
|
"keywords": [
|
|
9
9
|
"langchain",
|
|
@@ -37,10 +37,11 @@
|
|
|
37
37
|
"prepublish": "yarn build"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@langchain/core": "
|
|
40
|
+
"@langchain/core": "<1.0.0",
|
|
41
41
|
"cross-fetch": "^4.1.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
+
"@langchain/langgraph": "<1.0.0",
|
|
44
45
|
"@types/jest": "^29.5.12",
|
|
45
46
|
"@types/node": "^20.0.0",
|
|
46
47
|
"eslint": "^8.0.1",
|
|
@@ -53,9 +54,10 @@
|
|
|
53
54
|
"prettier": "^3.2.5",
|
|
54
55
|
"rimraf": "^3.0.2",
|
|
55
56
|
"ts-jest": "^29.1.4",
|
|
56
|
-
"typescript": "^5.4.5"
|
|
57
|
+
"typescript": "^5.4.5",
|
|
58
|
+
"zod": "^3.0.0"
|
|
57
59
|
},
|
|
58
60
|
"peerDependencies": {
|
|
59
|
-
"@langchain/core": "
|
|
61
|
+
"@langchain/core": "<1.0.0"
|
|
60
62
|
}
|
|
61
|
-
}
|
|
63
|
+
}
|