kernl 0.12.3 → 0.12.6
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +18 -0
- package/README.md +29 -0
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +2 -0
- package/dist/kernl/kernl.d.ts +6 -0
- package/dist/kernl/kernl.d.ts.map +1 -1
- package/dist/kernl/kernl.js +19 -0
- package/dist/kernl/types.d.ts +6 -0
- package/dist/kernl/types.d.ts.map +1 -1
- package/dist/lib/env.d.ts +2 -2
- package/dist/mcp/http.d.ts.map +1 -1
- package/dist/mcp/http.js +1 -5
- package/dist/mcp/sse.d.ts.map +1 -1
- package/dist/mcp/sse.js +1 -5
- package/dist/mcp/stdio.d.ts.map +1 -1
- package/dist/mcp/stdio.js +1 -5
- package/dist/task.d.ts.map +1 -1
- package/dist/task.js +0 -1
- package/dist/thread/__tests__/thread.test.js +241 -0
- package/dist/thread/thread.d.ts +5 -4
- package/dist/thread/thread.d.ts.map +1 -1
- package/dist/thread/thread.js +91 -22
- package/dist/thread/types.d.ts +5 -0
- package/dist/thread/types.d.ts.map +1 -1
- package/dist/tool/tool.d.ts +2 -2
- package/dist/tool/tool.d.ts.map +1 -1
- package/dist/tracing/__tests__/composite.test.d.ts +2 -0
- package/dist/tracing/__tests__/composite.test.d.ts.map +1 -0
- package/dist/tracing/__tests__/composite.test.js +146 -0
- package/dist/tracing/__tests__/dispatch.test.d.ts +2 -0
- package/dist/tracing/__tests__/dispatch.test.d.ts.map +1 -0
- package/dist/tracing/__tests__/dispatch.test.js +160 -0
- package/dist/tracing/__tests__/helpers.d.ts +69 -0
- package/dist/tracing/__tests__/helpers.d.ts.map +1 -0
- package/dist/tracing/__tests__/helpers.js +109 -0
- package/dist/tracing/__tests__/integration.test.d.ts +2 -0
- package/dist/tracing/__tests__/integration.test.d.ts.map +1 -0
- package/dist/tracing/__tests__/integration.test.js +675 -0
- package/dist/tracing/__tests__/span.test.d.ts +2 -0
- package/dist/tracing/__tests__/span.test.d.ts.map +1 -0
- package/dist/tracing/__tests__/span.test.js +188 -0
- package/dist/tracing/dispatch.d.ts +43 -0
- package/dist/tracing/dispatch.d.ts.map +1 -0
- package/dist/tracing/dispatch.js +70 -0
- package/dist/tracing/index.d.ts +8 -0
- package/dist/tracing/index.d.ts.map +1 -0
- package/dist/tracing/index.js +6 -0
- package/dist/tracing/span.d.ts +69 -0
- package/dist/tracing/span.d.ts.map +1 -0
- package/dist/tracing/span.js +64 -0
- package/dist/tracing/subscriber.d.ts +53 -0
- package/dist/tracing/subscriber.d.ts.map +1 -0
- package/dist/tracing/subscriber.js +1 -0
- package/dist/tracing/subscribers/composite.d.ts +26 -0
- package/dist/tracing/subscribers/composite.d.ts.map +1 -0
- package/dist/tracing/subscribers/composite.js +96 -0
- package/dist/tracing/subscribers/console.d.ts +22 -0
- package/dist/tracing/subscribers/console.d.ts.map +1 -0
- package/dist/tracing/subscribers/console.js +82 -0
- package/dist/tracing/types.d.ts +77 -0
- package/dist/tracing/types.d.ts.map +1 -0
- package/dist/tracing/types.js +1 -0
- package/package.json +6 -2
- package/src/agent.ts +2 -0
- package/src/index.ts +1 -0
- package/src/kernl/kernl.ts +21 -0
- package/src/kernl/types.ts +7 -0
- package/src/mcp/http.ts +1 -9
- package/src/mcp/sse.ts +1 -10
- package/src/mcp/stdio.ts +1 -10
- package/src/task.ts +0 -1
- package/src/thread/__tests__/thread.test.ts +280 -0
- package/src/thread/thread.ts +111 -24
- package/src/thread/types.ts +5 -0
- package/src/tool/tool.ts +1 -1
- package/src/tracing/__tests__/composite.test.ts +218 -0
- package/src/tracing/__tests__/dispatch.test.ts +222 -0
- package/src/tracing/__tests__/helpers.ts +138 -0
- package/src/tracing/__tests__/integration.test.ts +808 -0
- package/src/tracing/__tests__/span.test.ts +250 -0
- package/src/tracing/dispatch.ts +114 -0
- package/src/tracing/index.ts +39 -0
- package/src/tracing/span.ts +115 -0
- package/src/tracing/subscriber.ts +62 -0
- package/src/tracing/subscribers/composite.ts +102 -0
- package/src/tracing/subscribers/console.ts +101 -0
- package/src/tracing/types.ts +115 -0
- package/dist/trace/processor.d.ts +0 -1
- package/dist/trace/processor.d.ts.map +0 -1
- package/dist/trace/processor.js +0 -1
- package/dist/trace/traces.d.ts +0 -1
- package/dist/trace/traces.d.ts.map +0 -1
- package/dist/trace/traces.js +0 -73
- package/dist/trace/utils.d.ts +0 -22
- package/dist/trace/utils.d.ts.map +0 -1
- package/dist/trace/utils.js +0 -30
- package/src/trace/processor.ts +0 -0
- package/src/trace/traces.ts +0 -86
- package/src/trace/utils.ts +0 -38
package/.turbo/turbo-build.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @kernl/core
|
|
2
2
|
|
|
3
|
+
## 0.12.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- adc9cf2: Wire up abort signal for thread cancellation. Users can now pass an AbortSignal via ThreadExecuteOptions to cancel running threads.
|
|
8
|
+
|
|
9
|
+
## 0.12.5
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 7fc129b: Wire up abort signal for thread cancellation. Users can now pass an AbortSignal via ThreadExecuteOptions to cancel running threads.
|
|
14
|
+
|
|
15
|
+
## 0.12.4
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 296c377: Make tool execute method public for direct invocation
|
|
20
|
+
|
|
3
21
|
## 0.12.3
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# kernl
|
|
2
|
+
|
|
3
|
+
> **For AI agents**: These reference docs help coding agents understand the kernl SDK. If your agent gets stuck, share this page with it.
|
|
4
|
+
|
|
5
|
+
Core package containing the main abstractions and runtime for the kernl framework.
|
|
6
|
+
|
|
7
|
+
## Classes
|
|
8
|
+
|
|
9
|
+
| Class | Description |
|
|
10
|
+
| ----- | ----------- |
|
|
11
|
+
| [Agent](classes/Agent.md) | Define agents with instructions, tools, and memory |
|
|
12
|
+
| [Kernl](classes/Kernl.md) | Runtime orchestrator for agent registration and lifecycle |
|
|
13
|
+
| [Context](classes/Context.md) | Execution context passed through agent runs |
|
|
14
|
+
| [Memory](classes/Memory.md) | Three-tier memory system (working, short-term, long-term) |
|
|
15
|
+
| [RealtimeAgent](classes/RealtimeAgent.md) | Realtime/voice agent configuration |
|
|
16
|
+
| [RealtimeSession](classes/RealtimeSession.md) | Active realtime session |
|
|
17
|
+
| [Toolkit](classes/Toolkit.md) | Tool collection base class |
|
|
18
|
+
| [MCPToolkit](classes/MCPToolkit.md) | MCP-based tool provider |
|
|
19
|
+
|
|
20
|
+
## Functions
|
|
21
|
+
|
|
22
|
+
| Function | Description |
|
|
23
|
+
| -------- | ----------- |
|
|
24
|
+
| [tool](functions/tool.md) | Create a tool for agent use |
|
|
25
|
+
|
|
26
|
+
## More
|
|
27
|
+
|
|
28
|
+
- [Interfaces](interfaces/) — Thread management, memory config, storage adapters, lifecycle events
|
|
29
|
+
- [Type Aliases](type-aliases/) — Exported type definitions
|
package/dist/agent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,aAAa,EACb,iBAAiB,EACjB,4BAA4B,EAC7B,MAAM,qBAAqB,CAAC;AAG7B,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,mBAAmB,EACpB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAW,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EACL,cAAc,EACd,eAAe,EACf,KAAK,qBAAqB,EAC3B,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,SAAS,EAA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AQ,CAAC,GACvC,aAAa,CAAC,iBAAiB,CAAC;IA8DnC;;;;OAIG;IACH,IAAI,OAAO;mBAWI,MAAM,YAAY,iBAAiB;wBAE/B,IAAI,CAAC,kBAAkB,EAAE,SAAS,CAAC;sBAEpC,MAAM;uBACL,MAAM,WAAW,oBAAoB;yBAEnC,IAAI,CAAC,mBAAmB,EAAE,SAAS,GAAG,OAAO,CAAC;sBASjD,MAAM,SAAS,mBAAmB;MAGnD;CACF"}
|
package/dist/agent.js
CHANGED
|
@@ -62,6 +62,7 @@ export class Agent extends BaseAgent {
|
|
|
62
62
|
tid: options?.threadId,
|
|
63
63
|
namespace: options?.namespace,
|
|
64
64
|
storage: this.kernl.storage?.threads,
|
|
65
|
+
abort: options?.abort,
|
|
65
66
|
});
|
|
66
67
|
return this.kernl.spawn(thread);
|
|
67
68
|
}
|
|
@@ -119,6 +120,7 @@ export class Agent extends BaseAgent {
|
|
|
119
120
|
tid: options?.threadId,
|
|
120
121
|
namespace: options?.namespace,
|
|
121
122
|
storage: this.kernl.storage?.threads,
|
|
123
|
+
abort: options?.abort,
|
|
122
124
|
});
|
|
123
125
|
yield* this.kernl.spawnStream(thread);
|
|
124
126
|
return;
|
package/dist/kernl/kernl.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export declare class Kernl extends KernlHooks {
|
|
|
20
20
|
private readonly _models;
|
|
21
21
|
private readonly _memopts;
|
|
22
22
|
private readonly _storopts;
|
|
23
|
+
private readonly _subscriber;
|
|
23
24
|
readonly storage: KernlStorage;
|
|
24
25
|
athreads: Map<string, Thread<any, any>>;
|
|
25
26
|
private warnings;
|
|
@@ -59,5 +60,10 @@ export declare class Kernl extends KernlHooks {
|
|
|
59
60
|
* Initialize the memory system based on the storage + memory configuration.
|
|
60
61
|
*/
|
|
61
62
|
private initmem;
|
|
63
|
+
/**
|
|
64
|
+
* Gracefully shutdown the Kernl instance.
|
|
65
|
+
* Flushes and shuts down tracing subscribers, closes storage connections.
|
|
66
|
+
*/
|
|
67
|
+
shutdown(timeout?: number): Promise<void>;
|
|
62
68
|
}
|
|
63
69
|
//# sourceMappingURL=kernl.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kernl.d.ts","sourceRoot":"","sources":["../../src/kernl/kernl.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAmB,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EACL,MAAM,EAIP,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"kernl.d.ts","sourceRoot":"","sources":["../../src/kernl/kernl.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAmB,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EACL,MAAM,EAIP,MAAM,UAAU,CAAC;AAIlB,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAErD,OAAO,KAAK,EAAE,YAAY,EAAiC,MAAM,SAAS,CAAC;AAG3E;;;;;GAKG;AACH,qBAAa,KAAM,SAAQ,UAA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,eAAe,EAC7D,MAAM,EAAE,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,GAChC,aAAa,CAAC,iBAAiB,CAAC;IAYnC;;;;OAIG;IACH,OAAO,CAAC,OAAO;IA8Bf;;;OAGG;IACG,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAQhD"}
|
package/dist/kernl/kernl.js
CHANGED
|
@@ -2,6 +2,7 @@ import { resolveEmbeddingModel } from "@kernl-sdk/retrieval";
|
|
|
2
2
|
import { KernlHooks } from "../lifecycle.js";
|
|
3
3
|
import { InMemoryStorage } from "../storage/index.js";
|
|
4
4
|
import { Memory, MemoryByteEncoder, MemoryIndexHandle, buildMemoryIndexSchema, } from "../memory/index.js";
|
|
5
|
+
import { setSubscriber, clearSubscriber } from "../tracing/index.js";
|
|
5
6
|
import { logger } from "../lib/logger.js";
|
|
6
7
|
import { RThreads } from "../api/resources/threads/index.js";
|
|
7
8
|
import { RAgents } from "../api/resources/agents/index.js";
|
|
@@ -17,6 +18,7 @@ export class Kernl extends KernlHooks {
|
|
|
17
18
|
_models;
|
|
18
19
|
_memopts;
|
|
19
20
|
_storopts;
|
|
21
|
+
_subscriber = null;
|
|
20
22
|
storage;
|
|
21
23
|
athreads = new Map(); /* active threads */
|
|
22
24
|
warnings = {
|
|
@@ -38,6 +40,11 @@ export class Kernl extends KernlHooks {
|
|
|
38
40
|
this.threads = new RThreads(this.storage.threads);
|
|
39
41
|
this.agents = new RAgents(this._agents);
|
|
40
42
|
this.memories = this.initmem();
|
|
43
|
+
// wire tracing
|
|
44
|
+
if (options.tracer) {
|
|
45
|
+
this._subscriber = options.tracer;
|
|
46
|
+
setSubscriber(this._subscriber);
|
|
47
|
+
}
|
|
41
48
|
}
|
|
42
49
|
/**
|
|
43
50
|
* Registers a new agent with the kernl instance.
|
|
@@ -154,4 +161,16 @@ export class Kernl extends KernlHooks {
|
|
|
154
161
|
encoder,
|
|
155
162
|
});
|
|
156
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* Gracefully shutdown the Kernl instance.
|
|
166
|
+
* Flushes and shuts down tracing subscribers, closes storage connections.
|
|
167
|
+
*/
|
|
168
|
+
async shutdown(timeout) {
|
|
169
|
+
if (this._subscriber) {
|
|
170
|
+
await this._subscriber.flush();
|
|
171
|
+
await this._subscriber.shutdown(timeout);
|
|
172
|
+
clearSubscriber();
|
|
173
|
+
}
|
|
174
|
+
// TODO: close storage connections when storage supports it
|
|
175
|
+
}
|
|
157
176
|
}
|
package/dist/kernl/types.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { LanguageModel, EmbeddingModel } from "@kernl-sdk/protocol";
|
|
|
2
2
|
import { SearchIndex } from "@kernl-sdk/retrieval";
|
|
3
3
|
import { BaseAgent } from "../agent/base.js";
|
|
4
4
|
import { KernlStorage } from "../storage/index.js";
|
|
5
|
+
import type { Subscriber } from "../tracing/index.js";
|
|
5
6
|
/**
|
|
6
7
|
* Storage configuration for Kernl.
|
|
7
8
|
*/
|
|
@@ -68,6 +69,11 @@ export interface KernlOptions {
|
|
|
68
69
|
* Memory system configuration.
|
|
69
70
|
*/
|
|
70
71
|
memory?: MemoryOptions;
|
|
72
|
+
/**
|
|
73
|
+
* Tracer for observability. Receives span and event data.
|
|
74
|
+
* Use CompositeTracer to fan out to multiple backends.
|
|
75
|
+
*/
|
|
76
|
+
tracer?: Subscriber;
|
|
71
77
|
}
|
|
72
78
|
/**
|
|
73
79
|
* Agent registry interface.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/kernl/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CA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,WAAW,cAAc;IAC7B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAAC;CAC7C"}
|
package/dist/lib/env.d.ts
CHANGED
|
@@ -7,11 +7,11 @@ import { z } from "zod";
|
|
|
7
7
|
*/
|
|
8
8
|
declare const envSchema: z.ZodObject<{
|
|
9
9
|
LOG_LEVEL: z.ZodDefault<z.ZodEnum<{
|
|
10
|
+
error: "error";
|
|
10
11
|
trace: "trace";
|
|
11
12
|
debug: "debug";
|
|
12
13
|
info: "info";
|
|
13
14
|
warn: "warn";
|
|
14
|
-
error: "error";
|
|
15
15
|
fatal: "fatal";
|
|
16
16
|
}>>;
|
|
17
17
|
KERNL_LOG_MODEL_DATA: z.ZodPipe<z.ZodOptional<z.ZodEnum<{
|
|
@@ -31,7 +31,7 @@ declare const envSchema: z.ZodObject<{
|
|
|
31
31
|
* console.log(env.LOG_LEVEL);
|
|
32
32
|
*/
|
|
33
33
|
export declare const env: {
|
|
34
|
-
LOG_LEVEL: "
|
|
34
|
+
LOG_LEVEL: "error" | "trace" | "debug" | "info" | "warn" | "fatal";
|
|
35
35
|
KERNL_LOG_MODEL_DATA: boolean;
|
|
36
36
|
KERNL_LOG_TOOL_DATA: boolean;
|
|
37
37
|
};
|
package/dist/mcp/http.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/mcp/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAUnE,OAAO,EACL,aAAa,EAEd,MAAM,QAAQ,CAAC;AAChB,OAAO,KAAK,EACV,OAAO,EACP,qBAAqB,EACrB,8BAA8B,EAC9B,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,aAAa;IACxD,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,OAAO,EAAE,MA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dist/mcp/http.js
CHANGED
|
@@ -51,7 +51,6 @@ export class MCPServerStreamableHttp extends BaseMCPServer {
|
|
|
51
51
|
await this.close();
|
|
52
52
|
throw e;
|
|
53
53
|
}
|
|
54
|
-
this.logger.debug(`Connected to MCP server: ${this.id}`);
|
|
55
54
|
}
|
|
56
55
|
/**
|
|
57
56
|
* Closes the connection and cleans up resources.
|
|
@@ -76,7 +75,6 @@ export class MCPServerStreamableHttp extends BaseMCPServer {
|
|
|
76
75
|
throw new Error("Server not initialized. Make sure you call connect() first.");
|
|
77
76
|
}
|
|
78
77
|
const response = await this.session.listTools();
|
|
79
|
-
this.logger.debug(`Listed tools: ${JSON.stringify(response)}`);
|
|
80
78
|
return ListToolsResultSchema.parse(response).tools;
|
|
81
79
|
}
|
|
82
80
|
/**
|
|
@@ -93,8 +91,6 @@ export class MCPServerStreamableHttp extends BaseMCPServer {
|
|
|
93
91
|
timeout: this.timeout,
|
|
94
92
|
});
|
|
95
93
|
const parsed = CallToolResultSchema.parse(response);
|
|
96
|
-
|
|
97
|
-
this.logger.debug(`Called tool ${toolName} (args: ${JSON.stringify(args)}, result: ${JSON.stringify(result)})`);
|
|
98
|
-
return result;
|
|
94
|
+
return parsed.content;
|
|
99
95
|
}
|
|
100
96
|
}
|
package/dist/mcp/sse.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../src/mcp/sse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAUnE,OAAO,EAAE,aAAa,EAAsC,MAAM,QAAQ,CAAC;AAC3E,OAAO,KAAK,EACV,OAAO,EACP,qBAAqB,EACrB,mBAAmB,EACnB,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,qBAAa,YAAa,SAAQ,aAAa;IAC7C,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,OAAO,EA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U7B"}
|
package/dist/mcp/sse.js
CHANGED
|
@@ -48,7 +48,6 @@ export class MCPServerSSE extends BaseMCPServer {
|
|
|
48
48
|
await this.close();
|
|
49
49
|
throw e;
|
|
50
50
|
}
|
|
51
|
-
this.logger.debug(`Connected to MCP server: ${this.id}`);
|
|
52
51
|
}
|
|
53
52
|
/**
|
|
54
53
|
* Internal implementation: Fetches tools from the server.
|
|
@@ -60,7 +59,6 @@ export class MCPServerSSE extends BaseMCPServer {
|
|
|
60
59
|
throw new Error("Server not initialized. Make sure you call connect() first.");
|
|
61
60
|
}
|
|
62
61
|
const response = await this.session.listTools();
|
|
63
|
-
this.logger.debug(`Listed tools: ${JSON.stringify(response)}`);
|
|
64
62
|
return ListToolsResultSchema.parse(response).tools;
|
|
65
63
|
}
|
|
66
64
|
/**
|
|
@@ -77,9 +75,7 @@ export class MCPServerSSE extends BaseMCPServer {
|
|
|
77
75
|
timeout: this.timeout,
|
|
78
76
|
});
|
|
79
77
|
const parsed = CallToolResultSchema.parse(response);
|
|
80
|
-
|
|
81
|
-
this.logger.debug(`Called tool ${toolName} (args: ${JSON.stringify(args)}, result: ${JSON.stringify(result)})`);
|
|
82
|
-
return result;
|
|
78
|
+
return parsed.content;
|
|
83
79
|
}
|
|
84
80
|
/**
|
|
85
81
|
* Closes the connection and cleans up resources.
|
package/dist/mcp/stdio.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stdio.d.ts","sourceRoot":"","sources":["../../src/mcp/stdio.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAUnE,OAAO,EAAE,aAAa,EAAwC,MAAM,QAAQ,CAAC;AAC7E,OAAO,KAAK,EACV,OAAO,EACP,qBAAqB,EACrB,qBAAqB,EACrB,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,qBAAa,cAAe,SAAQ,aAAa;IAC/C,QAAQ,CAAC,EAAE,EAAE,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,IAAI,OAAO,CAAC,IAAI,CAAC;CAU7B"}
|
package/dist/mcp/stdio.js
CHANGED
|
@@ -43,7 +43,6 @@ export class MCPServerStdio extends BaseMCPServer {
|
|
|
43
43
|
this.serverInitializeResult = {
|
|
44
44
|
serverInfo: { name: this.id, version: "1.0.0" },
|
|
45
45
|
};
|
|
46
|
-
this.logger.debug(`Connected to MCP server: ${this.id}`);
|
|
47
46
|
}
|
|
48
47
|
catch (e) {
|
|
49
48
|
this.logger.error("Error initializing MCP server:", e);
|
|
@@ -59,7 +58,6 @@ export class MCPServerStdio extends BaseMCPServer {
|
|
|
59
58
|
throw new Error("Server not initialized. Make sure you call connect() first.");
|
|
60
59
|
}
|
|
61
60
|
const response = await this.session.listTools();
|
|
62
|
-
this.logger.debug(`Listed tools: ${JSON.stringify(response)}`);
|
|
63
61
|
return ListToolsResultSchema.parse(response).tools;
|
|
64
62
|
}
|
|
65
63
|
/**
|
|
@@ -76,9 +74,7 @@ export class MCPServerStdio extends BaseMCPServer {
|
|
|
76
74
|
timeout: this.timeout,
|
|
77
75
|
});
|
|
78
76
|
const parsed = CallToolResultSchema.parse(response);
|
|
79
|
-
|
|
80
|
-
this.logger.debug(`Called tool ${toolName} (args: ${JSON.stringify(args)}, result: ${JSON.stringify(result)})`);
|
|
81
|
-
return result;
|
|
77
|
+
return parsed.content;
|
|
82
78
|
}
|
|
83
79
|
/**
|
|
84
80
|
* Closes the connection and cleans up resources.
|
package/dist/task.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task.d.ts","sourceRoot":"","sources":["../src/task.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC;;;GAGG;AACH,qBAAa,IAAI,CAAC,QAAQ,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SAAS;IACnB;;;;OAIG;IACH,OAAO,YAAY;IAEnB;;;;;;;;;;OAUG;IACH,aAAa,kBAAkB;IAE/B;;;;;;;;;OASG;IACH,eAAe,oBAAoB;IAEnC;;;;;;;OAOG;IACH,OAAO,YAAY;IAEnB;;;;;;;OAOG;IACH,MAAM,WAAW;IAEjB;;;OAGG;IACH,IAAI,SAAS;CACd"}
|
package/dist/task.js
CHANGED
|
@@ -936,6 +936,247 @@ describe("Thread", () => {
|
|
|
936
936
|
expect(thread._tick).toBe(2);
|
|
937
937
|
});
|
|
938
938
|
});
|
|
939
|
+
describe("Event Sequencing", () => {
|
|
940
|
+
it("should assign incrementing seq values to all persisted events", async () => {
|
|
941
|
+
let callCount = 0;
|
|
942
|
+
const model = createMockModel(async (req) => {
|
|
943
|
+
callCount++;
|
|
944
|
+
if (callCount === 1) {
|
|
945
|
+
return {
|
|
946
|
+
content: [
|
|
947
|
+
{
|
|
948
|
+
kind: "message",
|
|
949
|
+
id: "msg_1",
|
|
950
|
+
role: "assistant",
|
|
951
|
+
content: [],
|
|
952
|
+
},
|
|
953
|
+
{
|
|
954
|
+
kind: "tool.call",
|
|
955
|
+
toolId: "echo",
|
|
956
|
+
state: IN_PROGRESS,
|
|
957
|
+
callId: "call_1",
|
|
958
|
+
arguments: JSON.stringify({ text: "test" }),
|
|
959
|
+
},
|
|
960
|
+
],
|
|
961
|
+
finishReason: "stop",
|
|
962
|
+
usage: { inputTokens: 2, outputTokens: 2, totalTokens: 4 },
|
|
963
|
+
warnings: [],
|
|
964
|
+
};
|
|
965
|
+
}
|
|
966
|
+
return {
|
|
967
|
+
content: [
|
|
968
|
+
{
|
|
969
|
+
kind: "message",
|
|
970
|
+
id: "msg_2",
|
|
971
|
+
role: "assistant",
|
|
972
|
+
content: [{ kind: "text", text: "Done!" }],
|
|
973
|
+
},
|
|
974
|
+
],
|
|
975
|
+
finishReason: "stop",
|
|
976
|
+
usage: { inputTokens: 4, outputTokens: 2, totalTokens: 6 },
|
|
977
|
+
warnings: [],
|
|
978
|
+
};
|
|
979
|
+
});
|
|
980
|
+
const echoTool = tool({
|
|
981
|
+
id: "echo",
|
|
982
|
+
description: "Echoes input",
|
|
983
|
+
parameters: z.object({ text: z.string() }),
|
|
984
|
+
execute: async (ctx, { text }) => `Echo: ${text}`,
|
|
985
|
+
});
|
|
986
|
+
const agent = new Agent({
|
|
987
|
+
id: "test",
|
|
988
|
+
name: "Test",
|
|
989
|
+
instructions: "Test agent",
|
|
990
|
+
model,
|
|
991
|
+
toolkits: [
|
|
992
|
+
new FunctionToolkit({ id: "test-tools", tools: [echoTool] }),
|
|
993
|
+
],
|
|
994
|
+
});
|
|
995
|
+
const thread = new Thread({ agent, input: userMessage("test") });
|
|
996
|
+
await thread.execute();
|
|
997
|
+
const history = thread.history;
|
|
998
|
+
// Verify all events have seq values
|
|
999
|
+
for (const event of history) {
|
|
1000
|
+
expect(event).toHaveProperty("seq");
|
|
1001
|
+
expect(typeof event.seq).toBe("number");
|
|
1002
|
+
}
|
|
1003
|
+
// Verify seq values increment: 0, 1, 2, 3, 4
|
|
1004
|
+
const seqValues = history.map((e) => e.seq);
|
|
1005
|
+
expect(seqValues).toEqual([0, 1, 2, 3, 4]);
|
|
1006
|
+
});
|
|
1007
|
+
it("should assign consistent tid to all events in a thread", async () => {
|
|
1008
|
+
const model = createMockModel(async (req) => {
|
|
1009
|
+
return {
|
|
1010
|
+
content: [
|
|
1011
|
+
{
|
|
1012
|
+
kind: "message",
|
|
1013
|
+
id: "msg_1",
|
|
1014
|
+
role: "assistant",
|
|
1015
|
+
content: [{ kind: "text", text: "Hello" }],
|
|
1016
|
+
},
|
|
1017
|
+
],
|
|
1018
|
+
finishReason: "stop",
|
|
1019
|
+
usage: { inputTokens: 2, outputTokens: 2, totalTokens: 4 },
|
|
1020
|
+
warnings: [],
|
|
1021
|
+
};
|
|
1022
|
+
});
|
|
1023
|
+
const agent = new Agent({
|
|
1024
|
+
id: "test",
|
|
1025
|
+
name: "Test",
|
|
1026
|
+
instructions: "Test agent",
|
|
1027
|
+
model,
|
|
1028
|
+
});
|
|
1029
|
+
const thread = new Thread({ agent, input: userMessage("test") });
|
|
1030
|
+
await thread.execute();
|
|
1031
|
+
const history = thread.history;
|
|
1032
|
+
const threadId = thread.tid;
|
|
1033
|
+
// All events should have the same tid as the thread
|
|
1034
|
+
for (const event of history) {
|
|
1035
|
+
expect(event).toHaveProperty("tid");
|
|
1036
|
+
expect(event.tid).toBe(threadId);
|
|
1037
|
+
}
|
|
1038
|
+
});
|
|
1039
|
+
it("should assign timestamps to all events", async () => {
|
|
1040
|
+
const model = createMockModel(async (req) => {
|
|
1041
|
+
return {
|
|
1042
|
+
content: [
|
|
1043
|
+
{
|
|
1044
|
+
kind: "message",
|
|
1045
|
+
id: "msg_1",
|
|
1046
|
+
role: "assistant",
|
|
1047
|
+
content: [{ kind: "text", text: "Hello" }],
|
|
1048
|
+
},
|
|
1049
|
+
],
|
|
1050
|
+
finishReason: "stop",
|
|
1051
|
+
usage: { inputTokens: 2, outputTokens: 2, totalTokens: 4 },
|
|
1052
|
+
warnings: [],
|
|
1053
|
+
};
|
|
1054
|
+
});
|
|
1055
|
+
const agent = new Agent({
|
|
1056
|
+
id: "test",
|
|
1057
|
+
name: "Test",
|
|
1058
|
+
instructions: "Test agent",
|
|
1059
|
+
model,
|
|
1060
|
+
});
|
|
1061
|
+
const thread = new Thread({ agent, input: userMessage("test") });
|
|
1062
|
+
await thread.execute();
|
|
1063
|
+
const history = thread.history;
|
|
1064
|
+
for (const event of history) {
|
|
1065
|
+
expect(event).toHaveProperty("timestamp");
|
|
1066
|
+
expect(event.timestamp).toBeInstanceOf(Date);
|
|
1067
|
+
}
|
|
1068
|
+
});
|
|
1069
|
+
it("should generate event ids in expected format", async () => {
|
|
1070
|
+
let callCount = 0;
|
|
1071
|
+
const model = createMockModel(async (req) => {
|
|
1072
|
+
callCount++;
|
|
1073
|
+
if (callCount === 1) {
|
|
1074
|
+
return {
|
|
1075
|
+
content: [
|
|
1076
|
+
{
|
|
1077
|
+
kind: "message",
|
|
1078
|
+
id: "msg_1",
|
|
1079
|
+
role: "assistant",
|
|
1080
|
+
content: [],
|
|
1081
|
+
},
|
|
1082
|
+
{
|
|
1083
|
+
kind: "tool.call",
|
|
1084
|
+
toolId: "simple",
|
|
1085
|
+
state: IN_PROGRESS,
|
|
1086
|
+
callId: "call_1",
|
|
1087
|
+
arguments: "{}",
|
|
1088
|
+
},
|
|
1089
|
+
],
|
|
1090
|
+
finishReason: "stop",
|
|
1091
|
+
usage: { inputTokens: 2, outputTokens: 2, totalTokens: 4 },
|
|
1092
|
+
warnings: [],
|
|
1093
|
+
};
|
|
1094
|
+
}
|
|
1095
|
+
return {
|
|
1096
|
+
content: [
|
|
1097
|
+
{
|
|
1098
|
+
kind: "message",
|
|
1099
|
+
id: "msg_2",
|
|
1100
|
+
role: "assistant",
|
|
1101
|
+
content: [{ kind: "text", text: "Done" }],
|
|
1102
|
+
},
|
|
1103
|
+
],
|
|
1104
|
+
finishReason: "stop",
|
|
1105
|
+
usage: { inputTokens: 2, outputTokens: 2, totalTokens: 4 },
|
|
1106
|
+
warnings: [],
|
|
1107
|
+
};
|
|
1108
|
+
});
|
|
1109
|
+
const simpleTool = tool({
|
|
1110
|
+
id: "simple",
|
|
1111
|
+
description: "Simple tool",
|
|
1112
|
+
parameters: undefined,
|
|
1113
|
+
execute: async () => "result",
|
|
1114
|
+
});
|
|
1115
|
+
const agent = new Agent({
|
|
1116
|
+
id: "test",
|
|
1117
|
+
name: "Test",
|
|
1118
|
+
instructions: "Test agent",
|
|
1119
|
+
model,
|
|
1120
|
+
toolkits: [
|
|
1121
|
+
new FunctionToolkit({ id: "test-tools", tools: [simpleTool] }),
|
|
1122
|
+
],
|
|
1123
|
+
});
|
|
1124
|
+
const thread = new Thread({ agent, input: userMessage("test") });
|
|
1125
|
+
await thread.execute();
|
|
1126
|
+
const history = thread.history;
|
|
1127
|
+
// Messages should have id format "message:{original_id}"
|
|
1128
|
+
const messages = history.filter((e) => e.kind === "message");
|
|
1129
|
+
for (const msg of messages) {
|
|
1130
|
+
expect(msg.id).toMatch(/^message:/);
|
|
1131
|
+
}
|
|
1132
|
+
// Tool calls use callId (not id), so tevent falls back to randomID()
|
|
1133
|
+
const toolCalls = history.filter((e) => e.kind === "tool.call");
|
|
1134
|
+
for (const tc of toolCalls) {
|
|
1135
|
+
expect(tc.id).toBeDefined();
|
|
1136
|
+
expect(typeof tc.id).toBe("string");
|
|
1137
|
+
}
|
|
1138
|
+
// Tool results also use callId, so tevent falls back to randomID()
|
|
1139
|
+
const toolResults = history.filter((e) => e.kind === "tool.result");
|
|
1140
|
+
for (const tr of toolResults) {
|
|
1141
|
+
expect(tr.id).toBeDefined();
|
|
1142
|
+
expect(typeof tr.id).toBe("string");
|
|
1143
|
+
}
|
|
1144
|
+
});
|
|
1145
|
+
it("should yield sequenced events during streaming", async () => {
|
|
1146
|
+
const model = createMockModel(async (req) => {
|
|
1147
|
+
return {
|
|
1148
|
+
content: [
|
|
1149
|
+
{
|
|
1150
|
+
kind: "message",
|
|
1151
|
+
id: "msg_1",
|
|
1152
|
+
role: "assistant",
|
|
1153
|
+
content: [{ kind: "text", text: "Hello" }],
|
|
1154
|
+
},
|
|
1155
|
+
],
|
|
1156
|
+
finishReason: "stop",
|
|
1157
|
+
usage: { inputTokens: 2, outputTokens: 2, totalTokens: 4 },
|
|
1158
|
+
warnings: [],
|
|
1159
|
+
};
|
|
1160
|
+
});
|
|
1161
|
+
const agent = new Agent({
|
|
1162
|
+
id: "test",
|
|
1163
|
+
name: "Test",
|
|
1164
|
+
instructions: "Test agent",
|
|
1165
|
+
model,
|
|
1166
|
+
});
|
|
1167
|
+
const thread = new Thread({ agent, input: userMessage("test") });
|
|
1168
|
+
const events = [];
|
|
1169
|
+
for await (const event of thread.stream()) {
|
|
1170
|
+
events.push(event);
|
|
1171
|
+
}
|
|
1172
|
+
// Find the complete message event (not deltas)
|
|
1173
|
+
const messageEvent = events.find((e) => e.kind === "message" && e.role === "assistant");
|
|
1174
|
+
expect(messageEvent).toBeDefined();
|
|
1175
|
+
expect(messageEvent).toHaveProperty("seq");
|
|
1176
|
+
expect(messageEvent).toHaveProperty("tid");
|
|
1177
|
+
expect(messageEvent).toHaveProperty("timestamp");
|
|
1178
|
+
});
|
|
1179
|
+
});
|
|
939
1180
|
describe("Final Output Parsing", () => {
|
|
940
1181
|
it("should return text output when output is 'text'", async () => {
|
|
941
1182
|
const model = createMockModel(async (req) => {
|
package/dist/thread/thread.d.ts
CHANGED
|
@@ -62,8 +62,9 @@ export declare class Thread<TContext = unknown, TOutput extends AgentOutputType
|
|
|
62
62
|
private persisted;
|
|
63
63
|
private history;
|
|
64
64
|
private tickres?;
|
|
65
|
-
private
|
|
65
|
+
private _abort?;
|
|
66
66
|
private storage?;
|
|
67
|
+
private _span?;
|
|
67
68
|
constructor(options: ThreadOptions<TContext, TOutput>);
|
|
68
69
|
/**
|
|
69
70
|
* Blocking execution - runs until terminal state or interruption
|
|
@@ -108,11 +109,11 @@ export declare class Thread<TContext = unknown, TOutput extends AgentOutputType
|
|
|
108
109
|
*/
|
|
109
110
|
append(...items: ThreadEventInner[]): ThreadEvent[];
|
|
110
111
|
/**
|
|
111
|
-
*
|
|
112
|
+
* Abort the running thread.
|
|
112
113
|
*
|
|
113
|
-
*
|
|
114
|
+
* @throws {Error} Not implemented - use AbortSignal via options instead
|
|
114
115
|
*/
|
|
115
|
-
|
|
116
|
+
abort(): void;
|
|
116
117
|
/**
|
|
117
118
|
* Emit an agent event with common fields auto-filled.
|
|
118
119
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread.d.ts","sourceRoot":"","sources":["../../src/thread/thread.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CA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