kernl 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/.turbo/turbo-build.log +5 -0
- package/CHANGELOG.md +53 -0
- package/LICENSE +201 -0
- package/dist/agent.d.ts +43 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +130 -0
- package/dist/context.d.ts +70 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +111 -0
- package/dist/env.d.ts +45 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +31 -0
- package/dist/error.d.ts +1 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +1 -0
- package/dist/guardrail.d.ts +178 -0
- package/dist/guardrail.d.ts.map +1 -0
- package/dist/guardrail.js +34 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/kernel.d.ts +7 -0
- package/dist/kernel.d.ts.map +1 -0
- package/dist/kernel.js +7 -0
- package/dist/kernl.d.ts +18 -0
- package/dist/kernl.d.ts.map +1 -0
- package/dist/kernl.js +16 -0
- package/dist/lib/env.d.ts +43 -0
- package/dist/lib/env.d.ts.map +1 -0
- package/dist/lib/env.js +29 -0
- package/dist/lib/error.d.ts +88 -0
- package/dist/lib/error.d.ts.map +1 -0
- package/dist/lib/error.js +117 -0
- package/dist/lib/logger.d.ts +36 -0
- package/dist/lib/logger.d.ts.map +1 -0
- package/dist/lib/logger.js +43 -0
- package/dist/lib/serde/__tests__/codec.test.d.ts +2 -0
- package/dist/lib/serde/__tests__/codec.test.d.ts.map +1 -0
- package/dist/lib/serde/__tests__/codec.test.js +75 -0
- package/dist/lib/serde/codec.d.ts +12 -0
- package/dist/lib/serde/codec.d.ts.map +1 -0
- package/dist/lib/serde/codec.js +54 -0
- package/dist/lib/serde/json.d.ts +8 -0
- package/dist/lib/serde/json.d.ts.map +1 -0
- package/dist/lib/serde/json.js +13 -0
- package/dist/lib/serde/thread.d.ts +1 -0
- package/dist/lib/serde/thread.d.ts.map +1 -0
- package/dist/lib/serde/thread.js +172 -0
- package/dist/lib/serde/tool.d.ts +36 -0
- package/dist/lib/serde/tool.d.ts.map +1 -0
- package/dist/lib/serde/tool.js +1 -0
- package/dist/lib/utils.d.ts +19 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/utils.js +41 -0
- package/dist/lifecycle.d.ts +133 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +29 -0
- package/dist/logger.d.ts +36 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +43 -0
- package/dist/mcp/__tests__/base.test.d.ts +2 -0
- package/dist/mcp/__tests__/base.test.d.ts.map +1 -0
- package/dist/mcp/__tests__/base.test.js +268 -0
- package/dist/mcp/__tests__/fixtures/echo-server.d.ts +3 -0
- package/dist/mcp/__tests__/fixtures/echo-server.d.ts.map +1 -0
- package/dist/mcp/__tests__/fixtures/echo-server.js +92 -0
- package/dist/mcp/__tests__/fixtures/math-server.d.ts +3 -0
- package/dist/mcp/__tests__/fixtures/math-server.d.ts.map +1 -0
- package/dist/mcp/__tests__/fixtures/math-server.js +98 -0
- package/dist/mcp/__tests__/fixtures/server.d.ts +3 -0
- package/dist/mcp/__tests__/fixtures/server.d.ts.map +1 -0
- package/dist/mcp/__tests__/fixtures/server.js +162 -0
- package/dist/mcp/__tests__/fixtures/test-server.d.ts +3 -0
- package/dist/mcp/__tests__/fixtures/test-server.d.ts.map +1 -0
- package/dist/mcp/__tests__/fixtures/test-server.js +163 -0
- package/dist/mcp/__tests__/fixtures/utils.d.ts +17 -0
- package/dist/mcp/__tests__/fixtures/utils.d.ts.map +1 -0
- package/dist/mcp/__tests__/fixtures/utils.js +42 -0
- package/dist/mcp/__tests__/integration.test.d.ts +2 -0
- package/dist/mcp/__tests__/integration.test.d.ts.map +1 -0
- package/dist/mcp/__tests__/integration.test.js +360 -0
- package/dist/mcp/__tests__/stdio.test.d.ts +2 -0
- package/dist/mcp/__tests__/stdio.test.d.ts.map +1 -0
- package/dist/mcp/__tests__/stdio.test.js +180 -0
- package/dist/mcp/__tests__/test-utils.d.ts +17 -0
- package/dist/mcp/__tests__/test-utils.d.ts.map +1 -0
- package/dist/mcp/__tests__/test-utils.js +42 -0
- package/dist/mcp/__tests__/utils.test.d.ts +2 -0
- package/dist/mcp/__tests__/utils.test.d.ts.map +1 -0
- package/dist/mcp/__tests__/utils.test.js +300 -0
- package/dist/mcp/base.d.ts +88 -0
- package/dist/mcp/base.d.ts.map +1 -0
- package/dist/mcp/base.js +68 -0
- package/dist/mcp/http.d.ts +34 -0
- package/dist/mcp/http.d.ts.map +1 -0
- package/dist/mcp/http.js +100 -0
- package/dist/mcp/node.d.ts +60 -0
- package/dist/mcp/node.d.ts.map +1 -0
- package/dist/mcp/node.js +297 -0
- package/dist/mcp/sse.d.ts +34 -0
- package/dist/mcp/sse.d.ts.map +1 -0
- package/dist/mcp/sse.js +97 -0
- package/dist/mcp/stdio.d.ts +32 -0
- package/dist/mcp/stdio.d.ts.map +1 -0
- package/dist/mcp/stdio.js +96 -0
- package/dist/mcp/types.d.ts +172 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/mcp/types.js +16 -0
- package/dist/mcp/utils.d.ts +23 -0
- package/dist/mcp/utils.d.ts.map +1 -0
- package/dist/mcp/utils.js +44 -0
- package/dist/model.d.ts +175 -0
- package/dist/model.d.ts.map +1 -0
- package/dist/model.js +1 -0
- package/dist/providers/ai.d.ts +1 -0
- package/dist/providers/ai.d.ts.map +1 -0
- package/dist/providers/ai.js +1 -0
- package/dist/providers/default.d.ts +16 -0
- package/dist/providers/default.d.ts.map +1 -0
- package/dist/providers/default.js +17 -0
- package/dist/providers/registry.d.ts +1 -0
- package/dist/providers/registry.d.ts.map +1 -0
- package/dist/providers/registry.js +1 -0
- package/dist/sched/scheduler.d.ts +20 -0
- package/dist/sched/scheduler.d.ts.map +1 -0
- package/dist/sched/scheduler.js +1 -0
- package/dist/sched/task.d.ts +92 -0
- package/dist/sched/task.d.ts.map +1 -0
- package/dist/sched/task.js +102 -0
- package/dist/serde/__tests__/codec.test.d.ts +2 -0
- package/dist/serde/__tests__/codec.test.d.ts.map +1 -0
- package/dist/serde/__tests__/codec.test.js +75 -0
- package/dist/serde/codec.d.ts +12 -0
- package/dist/serde/codec.d.ts.map +1 -0
- package/dist/serde/codec.js +54 -0
- package/dist/serde/json.d.ts +8 -0
- package/dist/serde/json.d.ts.map +1 -0
- package/dist/serde/json.js +13 -0
- package/dist/serde/thread.d.ts +687 -0
- package/dist/serde/thread.d.ts.map +1 -0
- package/dist/serde/thread.js +158 -0
- package/dist/serde/tool.d.ts +36 -0
- package/dist/serde/tool.d.ts.map +1 -0
- package/dist/serde/tool.js +1 -0
- package/dist/session.d.ts +1 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +1 -0
- package/dist/task.d.ts +87 -0
- package/dist/task.d.ts.map +1 -0
- package/dist/task.js +97 -0
- package/dist/thread/__tests__/mock.d.ts +28 -0
- package/dist/thread/__tests__/mock.d.ts.map +1 -0
- package/dist/thread/__tests__/mock.js +74 -0
- package/dist/thread/__tests__/thread.test.d.ts +2 -0
- package/dist/thread/__tests__/thread.test.d.ts.map +1 -0
- package/dist/thread/__tests__/thread.test.js +1412 -0
- package/dist/thread/index.d.ts +2 -0
- package/dist/thread/index.d.ts.map +1 -0
- package/dist/thread/index.js +1 -0
- package/dist/thread/thread.d.ts +66 -0
- package/dist/thread/thread.d.ts.map +1 -0
- package/dist/thread/thread.js +472 -0
- package/dist/thread/utils.d.ts +19 -0
- package/dist/thread/utils.d.ts.map +1 -0
- package/dist/thread/utils.js +50 -0
- package/dist/tool/__tests__/fixtures.d.ts +45 -0
- package/dist/tool/__tests__/fixtures.d.ts.map +1 -0
- package/dist/tool/__tests__/fixtures.js +97 -0
- package/dist/tool/__tests__/tool.test.d.ts +2 -0
- package/dist/tool/__tests__/tool.test.d.ts.map +1 -0
- package/dist/tool/__tests__/tool.test.js +172 -0
- package/dist/tool/__tests__/toolkit.test.d.ts +2 -0
- package/dist/tool/__tests__/toolkit.test.d.ts.map +1 -0
- package/dist/tool/__tests__/toolkit.test.js +134 -0
- package/dist/tool/index.d.ts +4 -0
- package/dist/tool/index.d.ts.map +1 -0
- package/dist/tool/index.js +2 -0
- package/dist/tool/mcp.d.ts +75 -0
- package/dist/tool/mcp.d.ts.map +1 -0
- package/dist/tool/mcp.js +111 -0
- package/dist/tool/tool.d.ts +95 -0
- package/dist/tool/tool.d.ts.map +1 -0
- package/dist/tool/tool.js +176 -0
- package/dist/tool/toolkit.d.ts +121 -0
- package/dist/tool/toolkit.d.ts.map +1 -0
- package/dist/tool/toolkit.js +180 -0
- package/dist/tool/types.d.ts +187 -0
- package/dist/tool/types.d.ts.map +1 -0
- package/dist/tool/types.js +1 -0
- package/dist/tools.d.ts +362 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +220 -0
- package/dist/trace/processor.d.ts +1 -0
- package/dist/trace/processor.d.ts.map +1 -0
- package/dist/trace/processor.js +1 -0
- package/dist/trace/traces.d.ts +1 -0
- package/dist/trace/traces.d.ts.map +1 -0
- package/dist/trace/traces.js +73 -0
- package/dist/trace/utils.d.ts +22 -0
- package/dist/trace/utils.d.ts.map +1 -0
- package/dist/trace/utils.js +30 -0
- package/dist/types/agent.d.ts +91 -0
- package/dist/types/agent.d.ts.map +1 -0
- package/dist/types/agent.js +1 -0
- package/dist/types/proto.d.ts +1551 -0
- package/dist/types/proto.d.ts.map +1 -0
- package/dist/types/proto.js +531 -0
- package/dist/types/thread.d.ts +71 -0
- package/dist/types/thread.d.ts.map +1 -0
- package/dist/types/thread.js +5 -0
- package/dist/usage.d.ts +43 -0
- package/dist/usage.d.ts.map +1 -0
- package/dist/usage.js +61 -0
- package/package.json +52 -0
- package/src/agent.ts +203 -0
- package/src/context.ts +265 -0
- package/src/guardrail.ts +277 -0
- package/src/index.ts +3 -0
- package/src/kernl.ts +22 -0
- package/src/lib/env.ts +36 -0
- package/src/lib/error.ts +158 -0
- package/src/lib/logger.ts +78 -0
- package/src/lib/serde/json.ts +18 -0
- package/src/lib/serde/thread.ts +188 -0
- package/src/lifecycle.ts +181 -0
- package/src/mcp/__tests__/base.test.ts +344 -0
- package/src/mcp/__tests__/fixtures/server.ts +179 -0
- package/src/mcp/__tests__/fixtures/utils.ts +58 -0
- package/src/mcp/__tests__/integration.test.ts +447 -0
- package/src/mcp/__tests__/stdio.test.ts +236 -0
- package/src/mcp/__tests__/utils.test.ts +360 -0
- package/src/mcp/base.ts +162 -0
- package/src/mcp/http.ts +147 -0
- package/src/mcp/sse.ts +137 -0
- package/src/mcp/stdio.ts +136 -0
- package/src/mcp/types.ts +202 -0
- package/src/mcp/utils.ts +62 -0
- package/src/task.ts +119 -0
- package/src/thread/__tests__/mock.ts +95 -0
- package/src/thread/__tests__/thread.test.ts +1574 -0
- package/src/thread/index.ts +1 -0
- package/src/thread/thread.ts +611 -0
- package/src/thread/utils.ts +67 -0
- package/src/tool/__tests__/fixtures.ts +106 -0
- package/src/tool/__tests__/tool.test.ts +235 -0
- package/src/tool/__tests__/toolkit.test.ts +174 -0
- package/src/tool/index.ts +10 -0
- package/src/tool/tool.ts +264 -0
- package/src/tool/toolkit.ts +234 -0
- package/src/tool/types.ts +243 -0
- package/src/trace/processor.ts +0 -0
- package/src/trace/traces.ts +86 -0
- package/src/trace/utils.ts +38 -0
- package/src/types/agent.ts +145 -0
- package/src/types/thread.ts +86 -0
- package/tsconfig.json +13 -0
- package/vitest.config.ts +14 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# @kernl/core
|
|
2
|
+
|
|
3
|
+
## 0.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Initial release of Kernl AI agent framework with modular architecture
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @kernl/protocol@0.1.1
|
|
10
|
+
- @kernl/shared@0.1.1
|
|
11
|
+
|
|
12
|
+
## 0.1.0
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- cd1653b: Initial implementation of Kernl agent framework (v0.1.0)
|
|
17
|
+
|
|
18
|
+
This release implements the core architecture for building agentic applications with a Linux kernel-inspired design:
|
|
19
|
+
|
|
20
|
+
**Core Agent Framework:**
|
|
21
|
+
- Agent class with instructions, model configuration, tools, and guardrails
|
|
22
|
+
- Thread execution loop with tick-based model interaction
|
|
23
|
+
- Context management for passing data between components
|
|
24
|
+
- Lifecycle hooks for extensibility
|
|
25
|
+
|
|
26
|
+
**Thread Execution:**
|
|
27
|
+
- Multi-turn conversation handling with tool calls
|
|
28
|
+
- Parallel tool execution support
|
|
29
|
+
- Terminal state detection
|
|
30
|
+
- State tracking (tick counter, model responses, history)
|
|
31
|
+
|
|
32
|
+
**Tool System:**
|
|
33
|
+
- Function tool definition with Zod schema validation
|
|
34
|
+
- Toolkit for managing collections of tools
|
|
35
|
+
- MCP (Model Context Protocol) server integration (stdio, HTTP, SSE transports)
|
|
36
|
+
- Tool approval workflow support
|
|
37
|
+
- Error handling with custom error functions
|
|
38
|
+
|
|
39
|
+
**Infrastructure:**
|
|
40
|
+
- Language model interface and provider registry
|
|
41
|
+
- Serialization system (codec, JSON, thread, tool)
|
|
42
|
+
- Tracing and observability hooks
|
|
43
|
+
- Usage tracking
|
|
44
|
+
- Input/output guardrails
|
|
45
|
+
|
|
46
|
+
**Testing:**
|
|
47
|
+
- Comprehensive test suite for Thread class (13 tests)
|
|
48
|
+
- Tool and toolkit test coverage
|
|
49
|
+
- Mock language model for testing
|
|
50
|
+
|
|
51
|
+
This is the foundational "Hello World" implementation - a working agent that can execute tool calls and maintain conversation history.
|
|
52
|
+
|
|
53
|
+
- 6bcc501: Add comprehensive MCP testing and multi-toolkit support. Introduces 64 tests for MCP implementation and refactors agent architecture to support multiple toolkits with duplicate detection. Includes tool() and tools() methods for cross-toolkit lookups.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/dist/agent.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { LanguageModel, LanguageModelRequestSettings } from "@kernl/protocol";
|
|
2
|
+
import type { Context, UnknownContext } from "./context";
|
|
3
|
+
import { InputGuardrail, OutputGuardrail } from "./guardrail";
|
|
4
|
+
import { AgentHooks } from "./lifecycle";
|
|
5
|
+
import { Toolkit } from "./tool/toolkit";
|
|
6
|
+
import { Tool } from "./tool";
|
|
7
|
+
import type { AgentConfig, AgentResponseType } from "./types/agent";
|
|
8
|
+
import { TextResponse } from "./types/thread";
|
|
9
|
+
export declare class Agent<TContext = UnknownContext, TResponse extends AgentResponseType = TextResponse> extends AgentHooks<TContext, TResponse> implements AgentConfig<TContext, TResponse> {
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
instructions: (context: Context<TContext>) => Promise<string> | string;
|
|
13
|
+
model: LanguageModel;
|
|
14
|
+
modelSettings: LanguageModelRequestSettings;
|
|
15
|
+
toolkits: Toolkit<TContext>[];
|
|
16
|
+
guardrails: {
|
|
17
|
+
input: InputGuardrail[];
|
|
18
|
+
output: OutputGuardrail<AgentResponseType>[];
|
|
19
|
+
};
|
|
20
|
+
responseType: TResponse;
|
|
21
|
+
resetToolChoice: boolean;
|
|
22
|
+
constructor(config: AgentConfig<TContext, TResponse>);
|
|
23
|
+
/**
|
|
24
|
+
* Get a specific tool by ID from all toolkits.
|
|
25
|
+
*
|
|
26
|
+
* @param id The tool ID to look up
|
|
27
|
+
* @returns The tool if found, undefined otherwise
|
|
28
|
+
*/
|
|
29
|
+
tool(id: string): Tool<TContext> | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Get all tools available from all toolkits for the given context.
|
|
32
|
+
* Checks for duplicate tool IDs across toolkits and throws an error if found.
|
|
33
|
+
*
|
|
34
|
+
* (TODO): Consider returning toolkits alongside tools so we can serialize them
|
|
35
|
+
* together and give agents more options for dealing with tool groups.
|
|
36
|
+
*
|
|
37
|
+
* @param context The context to use for filtering tools
|
|
38
|
+
* @returns Array of all available tools
|
|
39
|
+
* @throws {MisconfiguredError} If duplicate tool IDs are found across toolkits
|
|
40
|
+
*/
|
|
41
|
+
tools(context: Context<TContext>): Promise<Tool<TContext>[]>;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAE9E,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAK9B,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,qBAAa,KAAK,CACd,QAAQ,GAAG,cAAc,EACzB,SAAS,SAAS,iBAAiB,GAAG,YAAY,CAEpD,SAAQ,UAAU,CAAC,QAAQ,EAAE,SAAS,CACtC,YAAW,WAAW,CAAC,QAAQ,EAAE,SAAS,CAAC;IAE3C,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;IAEvE,KAAK,EAAE,aAAa,CAAC;IACrB,aAAa,EAAE,4BAA4B,CAAC;IAC5C,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;IAa9B,UAAU,EAAE;QACV,KAAK,EAAE,cAAc,EAAE,CAAC;QACxB,MAAM,EAAE,eAAe,CAAC,iBAAiB,CAAC,EAAE,CAAC;KAC9C,CAAC;IACF,YAAY,EAAE,SAAS,CAAuB;IAC9C,eAAe,EAAE,OAAO,CAAC;gBAsBb,MAAM,EAAE,WAAW,CAAC,QAAQ,EAAE,SAAS,CAAC;IAsDpD;;;;;OAKG;IACH,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,SAAS;IAQ5C;;;;;;;;;;OAUG;IACG,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;CAwDnE"}
|
package/dist/agent.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { AgentHooks } from "./lifecycle";
|
|
2
|
+
// import { DEFAULT_LANGUAGE_MODEL } from "./providers/default";
|
|
3
|
+
import { MisconfiguredError } from "./lib/error";
|
|
4
|
+
export class Agent extends AgentHooks {
|
|
5
|
+
id;
|
|
6
|
+
name;
|
|
7
|
+
instructions;
|
|
8
|
+
model;
|
|
9
|
+
modelSettings;
|
|
10
|
+
toolkits;
|
|
11
|
+
// --- (TODO) ---
|
|
12
|
+
// handoffDescription: string; // ??
|
|
13
|
+
// handoffs: (Agent<any, TResponse> | Handoff<any, TResponse>)[];
|
|
14
|
+
// ----------
|
|
15
|
+
// /* Process/thread-group–wide signal state shared by all threads in the group: shared pending signals, job control
|
|
16
|
+
// (stops/cont, group exit), rlimits, etc. */
|
|
17
|
+
// signal: *struct signal_struct;
|
|
18
|
+
// /* Table of signal handlers (sa_handler, sa_mask, flags) shared by threads (CLONE_SIGHAND). RCU-protected so readers can access it locklessly. */
|
|
19
|
+
// sighand: *struct sighand_struct __rcu;
|
|
20
|
+
guardrails;
|
|
21
|
+
responseType = "text";
|
|
22
|
+
resetToolChoice;
|
|
23
|
+
// toolUseBehavior: ToolUseBehavior; (TODO)
|
|
24
|
+
// /**
|
|
25
|
+
// * Create an Agent with handoffs and automatically infer the union type for TResponse from the handoff agents' response types.
|
|
26
|
+
// */
|
|
27
|
+
// static create<
|
|
28
|
+
// TResponse extends AgentResponseType = TextResponse,
|
|
29
|
+
// Handoffs extends readonly (Agent<any, any> | Handoff<any, any>)[] = [],
|
|
30
|
+
// >(
|
|
31
|
+
// config: AgentConfigWithHandoffs<TResponse, Handoffs>,
|
|
32
|
+
// ): Agent<UnknownContext, TResponse | HandoffsOutputUnion<Handoffs>> {
|
|
33
|
+
// return new Agent<UnknownContext, TResponse | HandoffsOutputUnion<Handoffs>>(
|
|
34
|
+
// {
|
|
35
|
+
// ...config,
|
|
36
|
+
// handoffs: config.handoffs as any,
|
|
37
|
+
// responseType: config.responseType,
|
|
38
|
+
// handoffresponseTypeWarningEnabled: false,
|
|
39
|
+
// },
|
|
40
|
+
// );
|
|
41
|
+
// }
|
|
42
|
+
constructor(config) {
|
|
43
|
+
super();
|
|
44
|
+
if (config.id.trim() === "") {
|
|
45
|
+
throw new MisconfiguredError("Agent must have an id.");
|
|
46
|
+
}
|
|
47
|
+
this.id = config.id;
|
|
48
|
+
this.name = config.name;
|
|
49
|
+
this.instructions =
|
|
50
|
+
typeof config.instructions === "function"
|
|
51
|
+
? config.instructions
|
|
52
|
+
: () => config.instructions;
|
|
53
|
+
this.model = config.model; // TODO: Add default model
|
|
54
|
+
this.modelSettings = config.modelSettings ?? {};
|
|
55
|
+
this.toolkits = config.toolkits ?? [];
|
|
56
|
+
for (const toolkit of this.toolkits) {
|
|
57
|
+
toolkit.bind(this);
|
|
58
|
+
}
|
|
59
|
+
this.guardrails = config.guardrails ?? { input: [], output: [] };
|
|
60
|
+
if (config.responseType) {
|
|
61
|
+
this.responseType = config.responseType;
|
|
62
|
+
}
|
|
63
|
+
this.resetToolChoice = config.resetToolChoice ?? true;
|
|
64
|
+
// this.toolUseBehavior = config.toolUseBehavior ?? "run_llm_again";
|
|
65
|
+
// this.handoffDescription = config.handoffDescription ?? "";
|
|
66
|
+
// this.handoffs = config.handoffs ?? [];
|
|
67
|
+
// --- Runtime warning for handoff response type compatibility ---
|
|
68
|
+
// if (
|
|
69
|
+
// config.handoffresponseTypeWarningEnabled === undefined ||
|
|
70
|
+
// config.handoffresponseTypeWarningEnabled
|
|
71
|
+
// ) {
|
|
72
|
+
// if (this.handoffs && this.responseType) {
|
|
73
|
+
// const responseTypes = new Set<string>([
|
|
74
|
+
// JSON.stringify(this.responseType),
|
|
75
|
+
// ]);
|
|
76
|
+
// for (const h of this.handoffs) {
|
|
77
|
+
// if ("responseType" in h && h.responseType) {
|
|
78
|
+
// responseTypes.add(JSON.stringify(h.responseType));
|
|
79
|
+
// } else if ("agent" in h && h.agent.responseType) {
|
|
80
|
+
// responseTypes.add(JSON.stringify(h.agent.responseType));
|
|
81
|
+
// }
|
|
82
|
+
// }
|
|
83
|
+
// if (responseTypes.size > 1) {
|
|
84
|
+
// logger.warn(
|
|
85
|
+
// `[Agent] Warning: Handoff agents have different response types: ${Array.from(responseTypes).join(", ")}. You can make it type-safe by using Agent.create({ ... }) method instead.`,
|
|
86
|
+
// );
|
|
87
|
+
// }
|
|
88
|
+
// }
|
|
89
|
+
// }
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Get a specific tool by ID from all toolkits.
|
|
93
|
+
*
|
|
94
|
+
* @param id The tool ID to look up
|
|
95
|
+
* @returns The tool if found, undefined otherwise
|
|
96
|
+
*/
|
|
97
|
+
tool(id) {
|
|
98
|
+
for (const toolkit of this.toolkits) {
|
|
99
|
+
const tool = toolkit.get(id);
|
|
100
|
+
if (tool)
|
|
101
|
+
return tool;
|
|
102
|
+
}
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Get all tools available from all toolkits for the given context.
|
|
107
|
+
* Checks for duplicate tool IDs across toolkits and throws an error if found.
|
|
108
|
+
*
|
|
109
|
+
* (TODO): Consider returning toolkits alongside tools so we can serialize them
|
|
110
|
+
* together and give agents more options for dealing with tool groups.
|
|
111
|
+
*
|
|
112
|
+
* @param context The context to use for filtering tools
|
|
113
|
+
* @returns Array of all available tools
|
|
114
|
+
* @throws {MisconfiguredError} If duplicate tool IDs are found across toolkits
|
|
115
|
+
*/
|
|
116
|
+
async tools(context) {
|
|
117
|
+
const allTools = [];
|
|
118
|
+
const toolIds = new Set();
|
|
119
|
+
for (const toolkit of this.toolkits) {
|
|
120
|
+
const tools = await toolkit.list(context);
|
|
121
|
+
const duplicates = tools.map((t) => t.id).filter((id) => toolIds.has(id));
|
|
122
|
+
if (duplicates.length > 0) {
|
|
123
|
+
throw new MisconfiguredError(`Duplicate tool IDs found across toolkits: ${duplicates.join(", ")}`);
|
|
124
|
+
}
|
|
125
|
+
tools.forEach((t) => toolIds.add(t.id));
|
|
126
|
+
allTools.push(...tools);
|
|
127
|
+
}
|
|
128
|
+
return allTools;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Status of a tool call approval.
|
|
3
|
+
*/
|
|
4
|
+
export type ApprovalStatus = "approved" | "rejected" | "pending";
|
|
5
|
+
/**
|
|
6
|
+
* A propagation mechanism which carries execution-scoped values across API boundaries and between logically associated
|
|
7
|
+
* execution units.
|
|
8
|
+
*/
|
|
9
|
+
export declare class Context<TContext = UnknownContext> {
|
|
10
|
+
/**
|
|
11
|
+
* The inner context object.
|
|
12
|
+
*/
|
|
13
|
+
context: TContext;
|
|
14
|
+
/**
|
|
15
|
+
* Map of tool call IDs to their approval status.
|
|
16
|
+
* (TEMPORARY) Used until the actions system is refined.
|
|
17
|
+
*/
|
|
18
|
+
approvals: Map<string, ApprovalStatus>;
|
|
19
|
+
/**
|
|
20
|
+
* Approve a tool call by its call ID.
|
|
21
|
+
* (TEMPORARY) Used until the actions system is refined.
|
|
22
|
+
*/
|
|
23
|
+
approve(callId: string): void;
|
|
24
|
+
/**
|
|
25
|
+
* Reject a tool call by its call ID.
|
|
26
|
+
* (TEMPORARY) Used until the actions system is refined.
|
|
27
|
+
*/
|
|
28
|
+
reject(callId: string): void;
|
|
29
|
+
constructor(context?: TContext);
|
|
30
|
+
/**
|
|
31
|
+
* Renders the context as a prompt using the default format selected. Kernel would inject this info automatically, but exposed in case of control
|
|
32
|
+
*/
|
|
33
|
+
render(self: Context<TContext>): string;
|
|
34
|
+
/**
|
|
35
|
+
* Render the context object as a markdown string:
|
|
36
|
+
*
|
|
37
|
+
* <context>
|
|
38
|
+
* <user>
|
|
39
|
+
* <name>John</name>
|
|
40
|
+
* <email>john@gmail.com</email>
|
|
41
|
+
* </user>
|
|
42
|
+
* <org>
|
|
43
|
+
* <id>org_235234523</id>
|
|
44
|
+
* <name>Acme Corp.<name>
|
|
45
|
+
* </org>
|
|
46
|
+
* </context>
|
|
47
|
+
*
|
|
48
|
+
*/
|
|
49
|
+
md(): string;
|
|
50
|
+
/**
|
|
51
|
+
* Render the context object as a yaml string:
|
|
52
|
+
*
|
|
53
|
+
* context:
|
|
54
|
+
* user:
|
|
55
|
+
* name: John
|
|
56
|
+
* email: john@gmail.com
|
|
57
|
+
* org:
|
|
58
|
+
* id: org_235234523
|
|
59
|
+
* name: Acme Corp.
|
|
60
|
+
*/
|
|
61
|
+
yaml(): string;
|
|
62
|
+
toJSON(): {
|
|
63
|
+
context: any;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Context that is being passed around as part of the session is unknown
|
|
68
|
+
*/
|
|
69
|
+
export type UnknownContext = unknown;
|
|
70
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,UAAU,GAAG,SAAS,CAAC;AAEjE;;;GAGG;AACH,qBAAa,OAAO,CAAC,QAAQ,GAAG,cAAc;IAC5C;;OAEG;IACH,OAAO,EAAE,QAAQ,CAAC;IAMlB;;;OAGG;IACH,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAEvC;;;OAGG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI7B;;;OAGG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;gBAwBhB,OAAO,GAAE,QAAyB;IAQ9C;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG,MAAM;IAevC;;;;;;;;;;;;;;OAcG;IACH,EAAE,IAAI,MAAM;IAIZ;;;;;;;;;;OAUG;IACH,IAAI,IAAI,MAAM;IAId,MAAM,IAAI;QACR,OAAO,EAAE,GAAG,CAAC;KAGd;CAsIF;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,OAAO,CAAC"}
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A propagation mechanism which carries execution-scoped values across API boundaries and between logically associated
|
|
3
|
+
* execution units.
|
|
4
|
+
*/
|
|
5
|
+
export class Context {
|
|
6
|
+
/**
|
|
7
|
+
* The inner context object.
|
|
8
|
+
*/
|
|
9
|
+
context;
|
|
10
|
+
// ----------------------
|
|
11
|
+
// TEMPORARY: Tool approval tracking until actions system is refined
|
|
12
|
+
// ----------------------
|
|
13
|
+
/**
|
|
14
|
+
* Map of tool call IDs to their approval status.
|
|
15
|
+
* (TEMPORARY) Used until the actions system is refined.
|
|
16
|
+
*/
|
|
17
|
+
approvals;
|
|
18
|
+
/**
|
|
19
|
+
* Approve a tool call by its call ID.
|
|
20
|
+
* (TEMPORARY) Used until the actions system is refined.
|
|
21
|
+
*/
|
|
22
|
+
approve(callId) {
|
|
23
|
+
this.approvals.set(callId, "approved");
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Reject a tool call by its call ID.
|
|
27
|
+
* (TEMPORARY) Used until the actions system is refined.
|
|
28
|
+
*/
|
|
29
|
+
reject(callId) {
|
|
30
|
+
this.approvals.set(callId, "rejected");
|
|
31
|
+
}
|
|
32
|
+
// ----------------------
|
|
33
|
+
// End temporary approval tracking
|
|
34
|
+
// ----------------------
|
|
35
|
+
// /**
|
|
36
|
+
// * Serialization format in which to render the context to the agent
|
|
37
|
+
// */
|
|
38
|
+
// private format: "md" | "yaml" | "json" | "html" | "xml";
|
|
39
|
+
// /**
|
|
40
|
+
// * The usage of the agent run so far. For streamed responses, the usage will be stale until the
|
|
41
|
+
// * last chunk of the stream is processed.
|
|
42
|
+
// */
|
|
43
|
+
// usage: Usage;
|
|
44
|
+
// /**
|
|
45
|
+
// * A map of tool names to whether they have been approved.
|
|
46
|
+
// */
|
|
47
|
+
// #approvals: Map<string, ApprovalRecord>;
|
|
48
|
+
constructor(context = {}) {
|
|
49
|
+
this.context = context;
|
|
50
|
+
this.approvals = new Map();
|
|
51
|
+
// this.format = format; // (TODO): configure()
|
|
52
|
+
// this.usage = new Usage();
|
|
53
|
+
// this.#approvals = new Map();
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Renders the context as a prompt using the default format selected. Kernel would inject this info automatically, but exposed in case of control
|
|
57
|
+
*/
|
|
58
|
+
render(self) {
|
|
59
|
+
throw new Error("UNIMPLEMENTED");
|
|
60
|
+
// switch (self.format) {
|
|
61
|
+
// case "yaml":
|
|
62
|
+
// return self.yaml();
|
|
63
|
+
// // case "json":
|
|
64
|
+
// // return self.json();
|
|
65
|
+
// // case "xml":
|
|
66
|
+
// // return self.xml();
|
|
67
|
+
// case "md":
|
|
68
|
+
// default:
|
|
69
|
+
// return self.md();
|
|
70
|
+
// }
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Render the context object as a markdown string:
|
|
74
|
+
*
|
|
75
|
+
* <context>
|
|
76
|
+
* <user>
|
|
77
|
+
* <name>John</name>
|
|
78
|
+
* <email>john@gmail.com</email>
|
|
79
|
+
* </user>
|
|
80
|
+
* <org>
|
|
81
|
+
* <id>org_235234523</id>
|
|
82
|
+
* <name>Acme Corp.<name>
|
|
83
|
+
* </org>
|
|
84
|
+
* </context>
|
|
85
|
+
*
|
|
86
|
+
*/
|
|
87
|
+
md() {
|
|
88
|
+
throw new Error("UNIMPLEMENTED");
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Render the context object as a yaml string:
|
|
92
|
+
*
|
|
93
|
+
* context:
|
|
94
|
+
* user:
|
|
95
|
+
* name: John
|
|
96
|
+
* email: john@gmail.com
|
|
97
|
+
* org:
|
|
98
|
+
* id: org_235234523
|
|
99
|
+
* name: Acme Corp.
|
|
100
|
+
*/
|
|
101
|
+
yaml() {
|
|
102
|
+
throw new Error("UNIMPLEMENTED");
|
|
103
|
+
}
|
|
104
|
+
toJSON() {
|
|
105
|
+
return {
|
|
106
|
+
context: this.context,
|
|
107
|
+
// usage: this.usage,
|
|
108
|
+
// approvals: Object.fromEntries(this.#approvals.entries()),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
package/dist/env.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Environment variable validation schema
|
|
4
|
+
*
|
|
5
|
+
* This ensures all environment variables are valid at startup.
|
|
6
|
+
* All variables are optional with sensible defaults.
|
|
7
|
+
*/
|
|
8
|
+
declare const envSchema: z.ZodObject<{
|
|
9
|
+
LOG_LEVEL: z.ZodDefault<z.ZodEnum<{
|
|
10
|
+
trace: "trace";
|
|
11
|
+
debug: "debug";
|
|
12
|
+
info: "info";
|
|
13
|
+
warn: "warn";
|
|
14
|
+
error: "error";
|
|
15
|
+
fatal: "fatal";
|
|
16
|
+
}>>;
|
|
17
|
+
KERNL_LOG_MODEL_DATA: z.ZodPipe<z.ZodOptional<z.ZodEnum<{
|
|
18
|
+
true: "true";
|
|
19
|
+
false: "false";
|
|
20
|
+
}>>, z.ZodTransform<boolean, "true" | "false" | undefined>>;
|
|
21
|
+
KERNL_LOG_TOOL_DATA: z.ZodPipe<z.ZodOptional<z.ZodEnum<{
|
|
22
|
+
true: "true";
|
|
23
|
+
false: "false";
|
|
24
|
+
}>>, z.ZodTransform<boolean, "true" | "false" | undefined>>;
|
|
25
|
+
}, z.core.$strip>;
|
|
26
|
+
/**
|
|
27
|
+
* Validated and type-safe environment variables
|
|
28
|
+
*
|
|
29
|
+
* Use this throughout the library instead of process.env directly.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* import { env } from './env';
|
|
33
|
+
* console.log(env.LOG_LEVEL);
|
|
34
|
+
*/
|
|
35
|
+
export declare const env: {
|
|
36
|
+
LOG_LEVEL: "trace" | "debug" | "info" | "warn" | "error" | "fatal";
|
|
37
|
+
KERNL_LOG_MODEL_DATA: boolean;
|
|
38
|
+
KERNL_LOG_TOOL_DATA: boolean;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Type of the validated environment variables
|
|
42
|
+
*/
|
|
43
|
+
export type Env = z.infer<typeof envSchema>;
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=env.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;GAKG;AACH,QAAA,MAAM,SAAS;;;;;;;;;;;;;;;;;iBAab,CAAC;AAEH;;;;;;;;GAQG;AACH,eAAO,MAAM,GAAG;;;;CAA+B,CAAC;AAEhD;;GAEG;AACH,MAAM,MAAM,GAAG,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,SAAS,CAAC,CAAC"}
|