@eidentic/studio 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +47 -0
- package/dist/index.cjs +403 -0
- package/dist/index.d.cts +113 -0
- package/dist/index.d.ts +113 -0
- package/dist/index.js +372 -0
- package/package.json +71 -0
- package/ui/dist/assets/index-BBjsyshz.js +50 -0
- package/ui/dist/assets/index-BS8_4ALL.css +1 -0
- package/ui/dist/index.html +13 -0
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 Derivative
|
|
95
|
+
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, excluding
|
|
103
|
+
those notices that do not pertain to any part of the Derivative
|
|
104
|
+
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 do
|
|
117
|
+
not modify the License. You may add Your own attribution notices
|
|
118
|
+
within Derivative Works that You distribute, alongside or as an
|
|
119
|
+
addendum to the NOTICE text from the Work, provided that such
|
|
120
|
+
additional attribution notices cannot be construed as modifying
|
|
121
|
+
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 2026 Baran Özdemir
|
|
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/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# @eidentic/studio
|
|
2
|
+
|
|
3
|
+
Local dev studio for Eidentic — inspect agent sessions, memory blocks, knowledge graph
|
|
4
|
+
facts, skill banks, and workflow run history via a built-in web dashboard. Designed as a
|
|
5
|
+
local development tool; not intended for production exposure without authentication.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @eidentic/studio
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or run it without installing via the CLI:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
eidentic studio
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { createStudio, serveNode } from "@eidentic/studio";
|
|
23
|
+
|
|
24
|
+
const studio = createStudio({
|
|
25
|
+
agents: { support: myAgent },
|
|
26
|
+
// auth: ApiKeyAuth({ "dev-key": { userId: "dev" } }), // optional
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
await serveNode(studio, { port: 4000 });
|
|
30
|
+
// Open http://localhost:4000 in your browser
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The Studio dashboard provides:
|
|
34
|
+
|
|
35
|
+
- **Sessions** — browse event streams for past and live sessions
|
|
36
|
+
- **Memory** — view and edit memory blocks and knowledge graph facts per scope
|
|
37
|
+
- **Skills** — list and approve skill bank entries
|
|
38
|
+
- **Workflows** — inspect step traces and outcomes of workflow runs
|
|
39
|
+
- **Costs** — per-session token usage and USD cost breakdown
|
|
40
|
+
|
|
41
|
+
## Links
|
|
42
|
+
|
|
43
|
+
- [GitHub](https://github.com/eidentic/eidentic)
|
|
44
|
+
- [Issue tracker](https://github.com/eidentic/eidentic/issues)
|
|
45
|
+
- [Root README](https://github.com/eidentic/eidentic#readme)
|
|
46
|
+
|
|
47
|
+
Apache-2.0
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
ApiKeyAuth: () => import_server.ApiKeyAuth,
|
|
24
|
+
NoAuth: () => import_server.NoAuth,
|
|
25
|
+
createStudio: () => createStudio,
|
|
26
|
+
createStudioApi: () => createStudioApi,
|
|
27
|
+
serveNode: () => import_server.serveNode,
|
|
28
|
+
serveStudio: () => serveStudio
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(index_exports);
|
|
31
|
+
var import_hono = require("hono");
|
|
32
|
+
var import_serve_static = require("@hono/node-server/serve-static");
|
|
33
|
+
var import_node_url = require("node:url");
|
|
34
|
+
var import_node_path = require("node:path");
|
|
35
|
+
var import_workflow = require("@eidentic/workflow");
|
|
36
|
+
var import_server = require("@eidentic/server");
|
|
37
|
+
var import_model = require("@eidentic/model");
|
|
38
|
+
var import_meta = {};
|
|
39
|
+
async function runAuth(auth, req) {
|
|
40
|
+
const headers = {};
|
|
41
|
+
req.headers.forEach((value, key) => {
|
|
42
|
+
headers[key.toLowerCase()] = value;
|
|
43
|
+
});
|
|
44
|
+
const url = new URL(req.url);
|
|
45
|
+
const authReq = {
|
|
46
|
+
method: req.method,
|
|
47
|
+
path: url.pathname,
|
|
48
|
+
headers
|
|
49
|
+
};
|
|
50
|
+
const principal = await auth.authenticate(authReq);
|
|
51
|
+
return principal !== null;
|
|
52
|
+
}
|
|
53
|
+
function hasGraph(store) {
|
|
54
|
+
return typeof store["queryFacts"] === "function";
|
|
55
|
+
}
|
|
56
|
+
function parseLimit(raw) {
|
|
57
|
+
if (raw === void 0) return void 0;
|
|
58
|
+
const n = Number(raw);
|
|
59
|
+
return Number.isFinite(n) && n > 0 ? Math.floor(n) : void 0;
|
|
60
|
+
}
|
|
61
|
+
function sessionUsage(events) {
|
|
62
|
+
let inputTokens = 0;
|
|
63
|
+
let outputTokens = 0;
|
|
64
|
+
let cachedInputTokens = 0;
|
|
65
|
+
let messages = 0;
|
|
66
|
+
for (const e of events) {
|
|
67
|
+
if (e.kind !== "assistant") continue;
|
|
68
|
+
messages++;
|
|
69
|
+
const usage = e.meta?.["usage"];
|
|
70
|
+
if (!usage) continue;
|
|
71
|
+
inputTokens += usage.inputTokens ?? 0;
|
|
72
|
+
outputTokens += usage.outputTokens ?? 0;
|
|
73
|
+
cachedInputTokens += usage.cachedInputTokens ?? 0;
|
|
74
|
+
}
|
|
75
|
+
return { inputTokens, outputTokens, cachedInputTokens, messages };
|
|
76
|
+
}
|
|
77
|
+
function usdForUsage(usage, prices, modelId) {
|
|
78
|
+
if (!modelId) return void 0;
|
|
79
|
+
const p = prices[modelId];
|
|
80
|
+
if (!p) return void 0;
|
|
81
|
+
const cachedToks = Math.min(usage.cachedInputTokens, usage.inputTokens);
|
|
82
|
+
const uncachedToks = usage.inputTokens - cachedToks;
|
|
83
|
+
const cacheRate = p.cachedInputPerMTok ?? p.inputPerMTok;
|
|
84
|
+
return (uncachedToks * p.inputPerMTok + cachedToks * cacheRate + usage.outputTokens * p.outputPerMTok) / 1e6;
|
|
85
|
+
}
|
|
86
|
+
function createStudioApi(opts) {
|
|
87
|
+
const auth = opts.auth ?? import_server.NoAuth;
|
|
88
|
+
const base = (opts.basePath ?? "/api").replace(/\/$/, "");
|
|
89
|
+
const app = new import_hono.Hono({ strict: false });
|
|
90
|
+
const wfRegistry = (0, import_workflow.createWorkflowRunRegistry)({ limit: 100 });
|
|
91
|
+
app.get(`${base}/health`, (c) => c.json({ ok: true }));
|
|
92
|
+
app.use(`${base}/*`, async (c, next) => {
|
|
93
|
+
if (c.req.path === `${base}/health`) {
|
|
94
|
+
return next();
|
|
95
|
+
}
|
|
96
|
+
const ok = await runAuth(auth, c.req.raw);
|
|
97
|
+
if (!ok) return c.json({ error: "Unauthorized" }, 401);
|
|
98
|
+
return next();
|
|
99
|
+
});
|
|
100
|
+
app.get(`${base}/agents`, (c) => {
|
|
101
|
+
const agents = Object.entries(opts.agents).map(([id, agent]) => {
|
|
102
|
+
const store = agent.store;
|
|
103
|
+
const hasMemory = typeof store["getBlocks"] === "function";
|
|
104
|
+
const hasSkills = opts.skillBanks?.[id] !== void 0 || agent.skillCatalog().length > 0;
|
|
105
|
+
const hasGraphFeature = hasGraph(store);
|
|
106
|
+
return {
|
|
107
|
+
id,
|
|
108
|
+
hasMemory,
|
|
109
|
+
hasSkills,
|
|
110
|
+
hasGraph: hasGraphFeature,
|
|
111
|
+
toolCount: agent.toolSchemas().length
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
return c.json(agents);
|
|
115
|
+
});
|
|
116
|
+
app.get(`${base}/agents/:id`, (c) => {
|
|
117
|
+
const id = c.req.param("id");
|
|
118
|
+
const agent = opts.agents[id];
|
|
119
|
+
if (!agent) return c.json({ error: `Unknown agent: ${id}` }, 404);
|
|
120
|
+
const store = agent.store;
|
|
121
|
+
const hasMemory = typeof store["getBlocks"] === "function";
|
|
122
|
+
const hasSkillsFlag = opts.skillBanks?.[id] !== void 0 || agent.skillCatalog().length > 0;
|
|
123
|
+
const hasGraphFeature = hasGraph(store);
|
|
124
|
+
return c.json({
|
|
125
|
+
id,
|
|
126
|
+
instructions: agent.instructions,
|
|
127
|
+
model: agent.modelId,
|
|
128
|
+
tools: agent.toolSchemas(),
|
|
129
|
+
hasMemory,
|
|
130
|
+
hasSkills: hasSkillsFlag,
|
|
131
|
+
hasGraph: hasGraphFeature
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
app.get(`${base}/agents/:id/sessions`, async (c) => {
|
|
135
|
+
const id = c.req.param("id");
|
|
136
|
+
const agent = opts.agents[id];
|
|
137
|
+
if (!agent) return c.json({ error: `Unknown agent: ${id}` }, 404);
|
|
138
|
+
const limit = parseLimit(c.req.query("limit"));
|
|
139
|
+
const sessions = await agent.store.listSessions({ agentId: id, limit });
|
|
140
|
+
const priceTable = opts.prices ?? import_model.defaultPrices;
|
|
141
|
+
const modelId = agent.modelId;
|
|
142
|
+
const enriched = await Promise.all(
|
|
143
|
+
sessions.map(async (s) => {
|
|
144
|
+
try {
|
|
145
|
+
const events = await agent.store.readEvents(s.id);
|
|
146
|
+
const usage = sessionUsage(events);
|
|
147
|
+
const usd = usdForUsage(usage, priceTable, modelId);
|
|
148
|
+
return { ...s, usage, usd };
|
|
149
|
+
} catch {
|
|
150
|
+
return s;
|
|
151
|
+
}
|
|
152
|
+
})
|
|
153
|
+
);
|
|
154
|
+
return c.json(enriched);
|
|
155
|
+
});
|
|
156
|
+
app.get(`${base}/agents/:id/sessions/:sid/events`, async (c) => {
|
|
157
|
+
const id = c.req.param("id");
|
|
158
|
+
const agent = opts.agents[id];
|
|
159
|
+
if (!agent) return c.json({ error: `Unknown agent: ${id}` }, 404);
|
|
160
|
+
const sid = c.req.param("sid");
|
|
161
|
+
const events = await agent.store.readEvents(sid);
|
|
162
|
+
return c.json({ events });
|
|
163
|
+
});
|
|
164
|
+
app.get(`${base}/agents/:id/cost`, async (c) => {
|
|
165
|
+
const id = c.req.param("id");
|
|
166
|
+
const agent = opts.agents[id];
|
|
167
|
+
if (!agent) return c.json({ error: `Unknown agent: ${id}` }, 404);
|
|
168
|
+
const priceTable = opts.prices ?? import_model.defaultPrices;
|
|
169
|
+
const pricedFrom = opts.prices ? "configured" : "default";
|
|
170
|
+
const modelId = agent.modelId;
|
|
171
|
+
const sessions = await agent.store.listSessions({ agentId: id });
|
|
172
|
+
let totalInput = 0;
|
|
173
|
+
let totalOutput = 0;
|
|
174
|
+
let totalCached = 0;
|
|
175
|
+
let totalMessages = 0;
|
|
176
|
+
let totalUsd = 0;
|
|
177
|
+
let hasUsd = false;
|
|
178
|
+
for (const s of sessions) {
|
|
179
|
+
try {
|
|
180
|
+
const events = await agent.store.readEvents(s.id);
|
|
181
|
+
const usage = sessionUsage(events);
|
|
182
|
+
totalInput += usage.inputTokens;
|
|
183
|
+
totalOutput += usage.outputTokens;
|
|
184
|
+
totalCached += usage.cachedInputTokens;
|
|
185
|
+
totalMessages += usage.messages;
|
|
186
|
+
const usd = usdForUsage(usage, priceTable, modelId);
|
|
187
|
+
if (usd !== void 0) {
|
|
188
|
+
totalUsd += usd;
|
|
189
|
+
hasUsd = true;
|
|
190
|
+
}
|
|
191
|
+
} catch {
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return c.json({
|
|
195
|
+
inputTokens: totalInput,
|
|
196
|
+
outputTokens: totalOutput,
|
|
197
|
+
cachedInputTokens: totalCached,
|
|
198
|
+
usd: hasUsd ? totalUsd : void 0,
|
|
199
|
+
messages: totalMessages,
|
|
200
|
+
sessions: sessions.length,
|
|
201
|
+
modelId: modelId ?? null,
|
|
202
|
+
pricedFrom,
|
|
203
|
+
pricesUpdatedAt: import_model.pricesUpdatedAt
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
app.get(`${base}/agents/:id/blocks`, async (c) => {
|
|
207
|
+
const id = c.req.param("id");
|
|
208
|
+
const agent = opts.agents[id];
|
|
209
|
+
if (!agent) return c.json({ error: `Unknown agent: ${id}` }, 404);
|
|
210
|
+
const userId = c.req.query("userId");
|
|
211
|
+
const scope = userId ? { kind: "user", agentId: id, userId } : { kind: "agent", agentId: id };
|
|
212
|
+
const blocks = await agent.store.listBlocks(scope);
|
|
213
|
+
return c.json(blocks);
|
|
214
|
+
});
|
|
215
|
+
app.put(`${base}/agents/:id/blocks/:label`, async (c) => {
|
|
216
|
+
const id = c.req.param("id");
|
|
217
|
+
const agent = opts.agents[id];
|
|
218
|
+
if (!agent) return c.json({ error: `Unknown agent: ${id}` }, 404);
|
|
219
|
+
const label = c.req.param("label");
|
|
220
|
+
const userId = c.req.query("userId");
|
|
221
|
+
const scope = userId ? { kind: "user", agentId: id, userId } : { kind: "agent", agentId: id };
|
|
222
|
+
let body;
|
|
223
|
+
try {
|
|
224
|
+
body = await c.req.json();
|
|
225
|
+
} catch {
|
|
226
|
+
return c.json({ error: "Invalid JSON body" }, 400);
|
|
227
|
+
}
|
|
228
|
+
if (typeof body !== "object" || body === null) {
|
|
229
|
+
return c.json({ error: "Body must be a JSON object" }, 400);
|
|
230
|
+
}
|
|
231
|
+
const { value, expectVersion } = body;
|
|
232
|
+
if (typeof value !== "string") {
|
|
233
|
+
return c.json({ error: "Missing or invalid 'value' field (string required)" }, 400);
|
|
234
|
+
}
|
|
235
|
+
if (expectVersion !== void 0 && typeof expectVersion !== "number") {
|
|
236
|
+
return c.json({ error: "'expectVersion' must be a number when provided" }, 400);
|
|
237
|
+
}
|
|
238
|
+
try {
|
|
239
|
+
const block = await agent.store.upsertBlock(
|
|
240
|
+
scope,
|
|
241
|
+
{ label, value },
|
|
242
|
+
typeof expectVersion === "number" ? expectVersion : void 0
|
|
243
|
+
);
|
|
244
|
+
return c.json(block);
|
|
245
|
+
} catch (err) {
|
|
246
|
+
if (err instanceof Error && /conflict/i.test(err.message)) {
|
|
247
|
+
return c.json({ error: "conflict", message: err.message }, 409);
|
|
248
|
+
}
|
|
249
|
+
throw err;
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
app.get(`${base}/agents/:id/facts`, async (c) => {
|
|
253
|
+
const id = c.req.param("id");
|
|
254
|
+
const agent = opts.agents[id];
|
|
255
|
+
if (!agent) return c.json({ error: `Unknown agent: ${id}` }, 404);
|
|
256
|
+
const userId = c.req.query("userId");
|
|
257
|
+
const subject = c.req.query("subject");
|
|
258
|
+
const scope = userId ? { kind: "user", agentId: id, userId } : { kind: "agent", agentId: id };
|
|
259
|
+
if (!hasGraph(agent.store)) {
|
|
260
|
+
return c.json([]);
|
|
261
|
+
}
|
|
262
|
+
const facts = await agent.store.queryFacts({ scope, ...subject ? { subject } : {} });
|
|
263
|
+
return c.json(facts);
|
|
264
|
+
});
|
|
265
|
+
app.get(`${base}/agents/:id/memories`, async (c) => {
|
|
266
|
+
const id = c.req.param("id");
|
|
267
|
+
const agent = opts.agents[id];
|
|
268
|
+
if (!agent) return c.json({ error: `Unknown agent: ${id}` }, 404);
|
|
269
|
+
const userId = c.req.query("userId");
|
|
270
|
+
const q = c.req.query("q") ?? "";
|
|
271
|
+
const scope = userId ? { kind: "user", agentId: id, userId } : { kind: "agent", agentId: id };
|
|
272
|
+
const snippets = await agent.store.searchMemory(scope, q, 20);
|
|
273
|
+
return c.json(snippets);
|
|
274
|
+
});
|
|
275
|
+
app.get(`${base}/agents/:id/skills`, (c) => {
|
|
276
|
+
const id = c.req.param("id");
|
|
277
|
+
const agent = opts.agents[id];
|
|
278
|
+
if (!agent) return c.json({ error: `Unknown agent: ${id}` }, 404);
|
|
279
|
+
const promptSkills = agent.skillCatalog().map((s) => ({
|
|
280
|
+
name: s.name,
|
|
281
|
+
description: s.description,
|
|
282
|
+
type: "prompt"
|
|
283
|
+
}));
|
|
284
|
+
const bank = opts.skillBanks?.[id];
|
|
285
|
+
const bankSkills = (bank ? bank.list() : []).map((rawLock) => {
|
|
286
|
+
const lock = rawLock;
|
|
287
|
+
return {
|
|
288
|
+
name: lock["name"] ?? lock["skillId"] ?? "?",
|
|
289
|
+
description: lock["description"] ?? "",
|
|
290
|
+
type: "executable",
|
|
291
|
+
quarantined: !!lock["quarantined"],
|
|
292
|
+
version: lock["version"],
|
|
293
|
+
author: lock["author"]
|
|
294
|
+
};
|
|
295
|
+
});
|
|
296
|
+
return c.json([...promptSkills, ...bankSkills]);
|
|
297
|
+
});
|
|
298
|
+
app.post(`${base}/agents/:id/skills/:skillId/approve`, (c) => {
|
|
299
|
+
const id = c.req.param("id");
|
|
300
|
+
if (!opts.agents[id]) return c.json({ error: `Unknown agent: ${id}` }, 404);
|
|
301
|
+
const bank = opts.skillBanks?.[id];
|
|
302
|
+
if (!bank) return c.json({ error: "No skill bank configured for this agent" }, 404);
|
|
303
|
+
const skillId = c.req.param("skillId");
|
|
304
|
+
const ok = bank.approve(skillId);
|
|
305
|
+
if (!ok) return c.json({ error: `Skill not found: ${skillId}` }, 404);
|
|
306
|
+
return c.json({ approved: true, name: skillId });
|
|
307
|
+
});
|
|
308
|
+
app.get(`${base}/workflows`, (c) => {
|
|
309
|
+
const runs = wfRegistry.list();
|
|
310
|
+
const summaries = runs.map((r) => ({
|
|
311
|
+
id: r.id,
|
|
312
|
+
name: r.name,
|
|
313
|
+
status: r.status,
|
|
314
|
+
startedAt: r.startedAt,
|
|
315
|
+
durationMs: r.durationMs,
|
|
316
|
+
stepCount: r.stepCount
|
|
317
|
+
}));
|
|
318
|
+
return c.json(summaries);
|
|
319
|
+
});
|
|
320
|
+
app.get(`${base}/workflows/:wid`, (c) => {
|
|
321
|
+
const wid = c.req.param("wid");
|
|
322
|
+
const run = wfRegistry.get(wid);
|
|
323
|
+
if (!run) return c.json({ error: `Unknown workflow run: ${wid}` }, 404);
|
|
324
|
+
return c.json(run);
|
|
325
|
+
});
|
|
326
|
+
app.post(`${base}/workflows`, async (c) => {
|
|
327
|
+
let body;
|
|
328
|
+
try {
|
|
329
|
+
body = await c.req.json();
|
|
330
|
+
} catch {
|
|
331
|
+
return c.json({ error: "Invalid JSON body" }, 400);
|
|
332
|
+
}
|
|
333
|
+
if (typeof body !== "object" || body === null) {
|
|
334
|
+
return c.json({ error: "Body must be a JSON object" }, 400);
|
|
335
|
+
}
|
|
336
|
+
const b = body;
|
|
337
|
+
const name = b["name"];
|
|
338
|
+
if (typeof name !== "string" || !name) {
|
|
339
|
+
return c.json({ error: "Missing or invalid 'name' field (non-empty string required)" }, 400);
|
|
340
|
+
}
|
|
341
|
+
const trace = b["trace"];
|
|
342
|
+
if (!Array.isArray(trace)) {
|
|
343
|
+
return c.json({ error: "Missing or invalid 'trace' field (array required)" }, 400);
|
|
344
|
+
}
|
|
345
|
+
const result = {
|
|
346
|
+
output: b["output"],
|
|
347
|
+
trace
|
|
348
|
+
};
|
|
349
|
+
const record = wfRegistry.record(name, result);
|
|
350
|
+
return c.json({ id: record.id, name: record.name, status: record.status }, 201);
|
|
351
|
+
});
|
|
352
|
+
const handle = app;
|
|
353
|
+
handle.recordWorkflow = function recordWorkflow(name, result) {
|
|
354
|
+
wfRegistry.record(name, result);
|
|
355
|
+
};
|
|
356
|
+
return handle;
|
|
357
|
+
}
|
|
358
|
+
function createStudio(opts) {
|
|
359
|
+
const run = (0, import_server.createServer)({
|
|
360
|
+
agents: opts.agents,
|
|
361
|
+
auth: opts.auth,
|
|
362
|
+
exposeEvents: true
|
|
363
|
+
});
|
|
364
|
+
const studioHandle = createStudioApi(opts);
|
|
365
|
+
const combined = new import_hono.Hono({ strict: false });
|
|
366
|
+
combined.route("/", run);
|
|
367
|
+
combined.route("/", studioHandle);
|
|
368
|
+
const handle = combined;
|
|
369
|
+
handle.recordWorkflow = studioHandle.recordWorkflow.bind(studioHandle);
|
|
370
|
+
return handle;
|
|
371
|
+
}
|
|
372
|
+
async function serveStudio(opts, { port = 3535 } = {}) {
|
|
373
|
+
let uiDist;
|
|
374
|
+
const metaUrl = import_meta.url;
|
|
375
|
+
if (metaUrl) {
|
|
376
|
+
const _dirname = (0, import_node_path.dirname)((0, import_node_url.fileURLToPath)(metaUrl));
|
|
377
|
+
uiDist = (0, import_node_path.join)(_dirname, "..", "ui", "dist");
|
|
378
|
+
} else {
|
|
379
|
+
const cjsDirname = typeof __dirname !== "undefined" ? __dirname : process.cwd();
|
|
380
|
+
uiDist = (0, import_node_path.join)(cjsDirname, "..", "ui", "dist");
|
|
381
|
+
}
|
|
382
|
+
const handle = createStudio(opts);
|
|
383
|
+
handle.use(
|
|
384
|
+
"/*",
|
|
385
|
+
(0, import_serve_static.serveStatic)({
|
|
386
|
+
root: uiDist,
|
|
387
|
+
rewriteRequestPath: (path) => {
|
|
388
|
+
return path === "/" ? "/index.html" : path;
|
|
389
|
+
}
|
|
390
|
+
})
|
|
391
|
+
);
|
|
392
|
+
handle.get("/*", (0, import_serve_static.serveStatic)({ root: uiDist, path: "/index.html" }));
|
|
393
|
+
return (0, import_server.serveNode)(handle, { port });
|
|
394
|
+
}
|
|
395
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
396
|
+
0 && (module.exports = {
|
|
397
|
+
ApiKeyAuth,
|
|
398
|
+
NoAuth,
|
|
399
|
+
createStudio,
|
|
400
|
+
createStudioApi,
|
|
401
|
+
serveNode,
|
|
402
|
+
serveStudio
|
|
403
|
+
});
|