@inbrowser/agent 0.0.0-placeholder → 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/AGENTS.md +270 -0
- package/README.md +117 -2
- package/bin/agent.ts +10 -0
- package/dist/cli/commands/describe.d.ts +14 -0
- package/dist/cli/commands/describe.d.ts.map +1 -0
- package/dist/cli/commands/describe.js +179 -0
- package/dist/cli/commands/describe.js.map +1 -0
- package/dist/cli/commands/events.d.ts +21 -0
- package/dist/cli/commands/events.d.ts.map +1 -0
- package/dist/cli/commands/events.js +59 -0
- package/dist/cli/commands/events.js.map +1 -0
- package/dist/cli/commands/fleet.d.ts +15 -0
- package/dist/cli/commands/fleet.d.ts.map +1 -0
- package/dist/cli/commands/fleet.js +149 -0
- package/dist/cli/commands/fleet.js.map +1 -0
- package/dist/cli/commands/help.d.ts +15 -0
- package/dist/cli/commands/help.d.ts.map +1 -0
- package/dist/cli/commands/help.js +93 -0
- package/dist/cli/commands/help.js.map +1 -0
- package/dist/cli/commands/migrate.d.ts +27 -0
- package/dist/cli/commands/migrate.d.ts.map +1 -0
- package/dist/cli/commands/migrate.js +109 -0
- package/dist/cli/commands/migrate.js.map +1 -0
- package/dist/cli/commands/run.d.ts +38 -0
- package/dist/cli/commands/run.d.ts.map +1 -0
- package/dist/cli/commands/run.js +535 -0
- package/dist/cli/commands/run.js.map +1 -0
- package/dist/cli/commands/schema.d.ts +8 -0
- package/dist/cli/commands/schema.d.ts.map +1 -0
- package/dist/cli/commands/schema.js +12 -0
- package/dist/cli/commands/schema.js.map +1 -0
- package/dist/cli/commands/serve.d.ts +39 -0
- package/dist/cli/commands/serve.d.ts.map +1 -0
- package/dist/cli/commands/serve.js +65 -0
- package/dist/cli/commands/serve.js.map +1 -0
- package/dist/cli/commands/undo.d.ts +36 -0
- package/dist/cli/commands/undo.d.ts.map +1 -0
- package/dist/cli/commands/undo.js +132 -0
- package/dist/cli/commands/undo.js.map +1 -0
- package/dist/cli/fixtures.d.ts +17 -0
- package/dist/cli/fixtures.d.ts.map +1 -0
- package/dist/cli/fixtures.js +107 -0
- package/dist/cli/fixtures.js.map +1 -0
- package/dist/cli/hardening.d.ts +39 -0
- package/dist/cli/hardening.d.ts.map +1 -0
- package/dist/cli/hardening.js +68 -0
- package/dist/cli/hardening.js.map +1 -0
- package/dist/cli/index.d.ts +28 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +19 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/llm/openrouter.d.ts +33 -0
- package/dist/cli/llm/openrouter.d.ts.map +1 -0
- package/dist/cli/llm/openrouter.js +285 -0
- package/dist/cli/llm/openrouter.js.map +1 -0
- package/dist/cli/main.d.ts +32 -0
- package/dist/cli/main.d.ts.map +1 -0
- package/dist/cli/main.js +106 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/cli/output.d.ts +36 -0
- package/dist/cli/output.d.ts.map +1 -0
- package/dist/cli/output.js +95 -0
- package/dist/cli/output.js.map +1 -0
- package/dist/cli/parse.d.ts +26 -0
- package/dist/cli/parse.d.ts.map +1 -0
- package/dist/cli/parse.js +160 -0
- package/dist/cli/parse.js.map +1 -0
- package/dist/cli/session-log.d.ts +34 -0
- package/dist/cli/session-log.d.ts.map +1 -0
- package/dist/cli/session-log.js +52 -0
- package/dist/cli/session-log.js.map +1 -0
- package/dist/cli/spec.d.ts +62 -0
- package/dist/cli/spec.d.ts.map +1 -0
- package/dist/cli/spec.js +510 -0
- package/dist/cli/spec.js.map +1 -0
- package/dist/cli/ui/RunView.d.ts +134 -0
- package/dist/cli/ui/RunView.d.ts.map +1 -0
- package/dist/cli/ui/RunView.js +341 -0
- package/dist/cli/ui/RunView.js.map +1 -0
- package/dist/events/codec.d.ts +79 -0
- package/dist/events/codec.d.ts.map +1 -0
- package/dist/events/codec.js +142 -0
- package/dist/events/codec.js.map +1 -0
- package/dist/events/log-core.d.ts +76 -0
- package/dist/events/log-core.d.ts.map +1 -0
- package/dist/events/log-core.js +73 -0
- package/dist/events/log-core.js.map +1 -0
- package/dist/events/log.d.ts +60 -0
- package/dist/events/log.d.ts.map +1 -0
- package/dist/events/log.js +193 -0
- package/dist/events/log.js.map +1 -0
- package/dist/events/replay.d.ts +106 -0
- package/dist/events/replay.d.ts.map +1 -0
- package/dist/events/replay.js +137 -0
- package/dist/events/replay.js.map +1 -0
- package/dist/events/wrap.d.ts +100 -0
- package/dist/events/wrap.d.ts.map +1 -0
- package/dist/events/wrap.js +141 -0
- package/dist/events/wrap.js.map +1 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/llm-adapter.d.ts +96 -0
- package/dist/llm-adapter.d.ts.map +1 -0
- package/dist/llm-adapter.js +132 -0
- package/dist/llm-adapter.js.map +1 -0
- package/dist/mcp/serve.d.ts +70 -0
- package/dist/mcp/serve.d.ts.map +1 -0
- package/dist/mcp/serve.js +154 -0
- package/dist/mcp/serve.js.map +1 -0
- package/dist/metrics/runs.d.ts +58 -0
- package/dist/metrics/runs.d.ts.map +1 -0
- package/dist/metrics/runs.js +99 -0
- package/dist/metrics/runs.js.map +1 -0
- package/dist/metrics.d.ts +38 -0
- package/dist/metrics.d.ts.map +1 -0
- package/dist/metrics.js +123 -0
- package/dist/metrics.js.map +1 -0
- package/dist/node.d.ts +22 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +22 -0
- package/dist/node.js.map +1 -0
- package/dist/session.d.ts +10 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +179 -0
- package/dist/session.js.map +1 -0
- package/dist/storage.d.ts +14 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +58 -0
- package/dist/storage.js.map +1 -0
- package/dist/strategy.d.ts +26 -0
- package/dist/strategy.d.ts.map +1 -0
- package/dist/strategy.js +200 -0
- package/dist/strategy.js.map +1 -0
- package/dist/tools.d.ts +26 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +129 -0
- package/dist/tools.js.map +1 -0
- package/dist/types/agent.d.ts +94 -0
- package/dist/types/agent.d.ts.map +1 -0
- package/dist/types/agent.js +17 -0
- package/dist/types/agent.js.map +1 -0
- package/dist/types/capabilities.d.ts +17 -0
- package/dist/types/capabilities.d.ts.map +1 -0
- package/dist/types/capabilities.js +13 -0
- package/dist/types/capabilities.js.map +1 -0
- package/dist/types/chat.d.ts +74 -0
- package/dist/types/chat.d.ts.map +1 -0
- package/dist/types/chat.js +10 -0
- package/dist/types/chat.js.map +1 -0
- package/dist/types/events.d.ts +115 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/events.js +30 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/llm.d.ts +89 -0
- package/dist/types/llm.d.ts.map +1 -0
- package/dist/types/llm.js +12 -0
- package/dist/types/llm.js.map +1 -0
- package/dist/types/metrics.d.ts +34 -0
- package/dist/types/metrics.d.ts.map +1 -0
- package/dist/types/metrics.js +10 -0
- package/dist/types/metrics.js.map +1 -0
- package/dist/types/observer.d.ts +41 -0
- package/dist/types/observer.d.ts.map +1 -0
- package/dist/types/observer.js +41 -0
- package/dist/types/observer.js.map +1 -0
- package/dist/types/project-context.d.ts +18 -0
- package/dist/types/project-context.d.ts.map +1 -0
- package/dist/types/project-context.js +11 -0
- package/dist/types/project-context.js.map +1 -0
- package/dist/types/runtime.d.ts +71 -0
- package/dist/types/runtime.d.ts.map +1 -0
- package/dist/types/runtime.js +21 -0
- package/dist/types/runtime.js.map +1 -0
- package/dist/types/session.d.ts +103 -0
- package/dist/types/session.d.ts.map +1 -0
- package/dist/types/session.js +11 -0
- package/dist/types/session.js.map +1 -0
- package/dist/types/storage.d.ts +20 -0
- package/dist/types/storage.d.ts.map +1 -0
- package/dist/types/storage.js +41 -0
- package/dist/types/storage.js.map +1 -0
- package/dist/types/strategy.d.ts +76 -0
- package/dist/types/strategy.d.ts.map +1 -0
- package/dist/types/strategy.js +10 -0
- package/dist/types/strategy.js.map +1 -0
- package/dist/types/tools.d.ts +136 -0
- package/dist/types/tools.d.ts.map +1 -0
- package/dist/types/tools.js +11 -0
- package/dist/types/tools.js.map +1 -0
- package/dist/types/trace.d.ts +125 -0
- package/dist/types/trace.d.ts.map +1 -0
- package/dist/types/trace.js +24 -0
- package/dist/types/trace.js.map +1 -0
- package/dist/types/workspace.d.ts +29 -0
- package/dist/types/workspace.d.ts.map +1 -0
- package/dist/types/workspace.js +18 -0
- package/dist/types/workspace.js.map +1 -0
- package/package.json +45 -14
- package/skills/agent-cli.md +218 -0
- package/index.js +0 -2
package/dist/metrics.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `MetricsCollector` implementation — pricing tables + cost
|
|
3
|
+
* derivation in one place. Pure functions; no I/O.
|
|
4
|
+
*
|
|
5
|
+
* Pricing is per-million-token USD figures. When the provider
|
|
6
|
+
* reports a cost (OpenRouter's `x-cost` header), the collector
|
|
7
|
+
* skips estimation and marks `costEstimated: false`. When the
|
|
8
|
+
* model isn't in the pricing table, cost is set to 0 with
|
|
9
|
+
* `costEstimated: true`.
|
|
10
|
+
*
|
|
11
|
+
* Update pricing rows below when providers revise rates — there's
|
|
12
|
+
* no API to introspect them.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Per-(provider, model) pricing table. Keys are `${llmId}:${model}`
|
|
16
|
+
* to avoid collisions when two providers ship a same-named model.
|
|
17
|
+
*/
|
|
18
|
+
const PRICING = {
|
|
19
|
+
'gemini:gemini-3.1-pro-preview': { input: 2.5, output: 20.0, cacheRead: 0.625 },
|
|
20
|
+
'gemini:gemini-3-flash-preview': { input: 0.5, output: 4.0, cacheRead: 0.125 },
|
|
21
|
+
'gemini:gemini-3.1-flash-lite': { input: 0.15, output: 0.6, cacheRead: 0.0375 },
|
|
22
|
+
// OpenRouter quotes cost on the response — we don't need a row.
|
|
23
|
+
// Ollama is local — no cost.
|
|
24
|
+
// Nano is on-device — no cost.
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Look up a pricing row. Returns undefined when the model isn't
|
|
28
|
+
* priced — caller skips the cost field rather than fabricating one.
|
|
29
|
+
*/
|
|
30
|
+
export function findPricing(llmId, model) {
|
|
31
|
+
return PRICING[`${llmId}:${model}`];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Derive a `TurnMetrics` value from one turn's raw usage. Pure
|
|
35
|
+
* function — used by both the collector below and direct callers
|
|
36
|
+
* that don't need session-level aggregation.
|
|
37
|
+
*/
|
|
38
|
+
export function computeTurnMetrics(input) {
|
|
39
|
+
const { llmId, model, rawUsage, isByok } = input;
|
|
40
|
+
const tokensCached = rawUsage.cachedTokens ?? 0;
|
|
41
|
+
const tokensReasoning = rawUsage.reasoningTokens ?? 0;
|
|
42
|
+
// Provider reported cost directly (OpenRouter): trust it.
|
|
43
|
+
if (typeof rawUsage.costUsd === 'number') {
|
|
44
|
+
return {
|
|
45
|
+
tokensIn: rawUsage.promptTokens,
|
|
46
|
+
tokensOut: rawUsage.completionTokens,
|
|
47
|
+
tokensCached,
|
|
48
|
+
tokensReasoning,
|
|
49
|
+
costUsd: rawUsage.costUsd,
|
|
50
|
+
costEstimated: false,
|
|
51
|
+
isByok,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
// Estimate from the table.
|
|
55
|
+
const row = findPricing(llmId, model);
|
|
56
|
+
if (!row) {
|
|
57
|
+
return {
|
|
58
|
+
tokensIn: rawUsage.promptTokens,
|
|
59
|
+
tokensOut: rawUsage.completionTokens,
|
|
60
|
+
tokensCached,
|
|
61
|
+
tokensReasoning,
|
|
62
|
+
costUsd: 0,
|
|
63
|
+
costEstimated: true,
|
|
64
|
+
isByok,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
// Math: cached tokens get the cache rate; the rest of the prompt
|
|
68
|
+
// gets the standard input rate; output tokens (which include
|
|
69
|
+
// reasoning per most providers' billing) get the output rate.
|
|
70
|
+
const billedInput = Math.max(0, rawUsage.promptTokens - tokensCached);
|
|
71
|
+
const costUsd = (billedInput * row.input) / 1_000_000 +
|
|
72
|
+
(tokensCached * row.cacheRead) / 1_000_000 +
|
|
73
|
+
(rawUsage.completionTokens * row.output) / 1_000_000;
|
|
74
|
+
return {
|
|
75
|
+
tokensIn: rawUsage.promptTokens,
|
|
76
|
+
tokensOut: rawUsage.completionTokens,
|
|
77
|
+
tokensCached,
|
|
78
|
+
tokensReasoning,
|
|
79
|
+
costUsd,
|
|
80
|
+
costEstimated: true,
|
|
81
|
+
isByok,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/** Build a stateful `MetricsCollector` for one session. */
|
|
85
|
+
export function createMetricsCollector() {
|
|
86
|
+
let totals = {
|
|
87
|
+
tokensTotal: 0,
|
|
88
|
+
tokensIn: 0,
|
|
89
|
+
tokensOut: 0,
|
|
90
|
+
tokensCached: 0,
|
|
91
|
+
tokensReasoning: 0,
|
|
92
|
+
costUsdTotal: 0,
|
|
93
|
+
turnCount: 0,
|
|
94
|
+
};
|
|
95
|
+
return {
|
|
96
|
+
recordTurn(input) {
|
|
97
|
+
const m = computeTurnMetrics(input);
|
|
98
|
+
totals = {
|
|
99
|
+
tokensTotal: totals.tokensTotal + m.tokensIn + m.tokensOut,
|
|
100
|
+
tokensIn: totals.tokensIn + m.tokensIn,
|
|
101
|
+
tokensOut: totals.tokensOut + m.tokensOut,
|
|
102
|
+
tokensCached: totals.tokensCached + m.tokensCached,
|
|
103
|
+
tokensReasoning: totals.tokensReasoning + m.tokensReasoning,
|
|
104
|
+
costUsdTotal: totals.costUsdTotal + m.costUsd,
|
|
105
|
+
turnCount: totals.turnCount + 1,
|
|
106
|
+
};
|
|
107
|
+
return m;
|
|
108
|
+
},
|
|
109
|
+
totals: () => ({ ...totals }),
|
|
110
|
+
reset() {
|
|
111
|
+
totals = {
|
|
112
|
+
tokensTotal: 0,
|
|
113
|
+
tokensIn: 0,
|
|
114
|
+
tokensOut: 0,
|
|
115
|
+
tokensCached: 0,
|
|
116
|
+
tokensReasoning: 0,
|
|
117
|
+
costUsdTotal: 0,
|
|
118
|
+
turnCount: 0,
|
|
119
|
+
};
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=metrics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics.js","sourceRoot":"","sources":["../src/metrics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAcH;;;GAGG;AACH,MAAM,OAAO,GAA+B;IAC1C,+BAA+B,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE;IAC/E,+BAA+B,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE;IAC9E,8BAA8B,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE;IAC/E,gEAAgE;IAChE,6BAA6B;IAC7B,+BAA+B;CAChC,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,KAAa,EAAE,KAAa;IACtD,OAAO,OAAO,CAAC,GAAG,KAAK,IAAI,KAAK,EAAE,CAAC,CAAC;AACtC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAsB;IACvD,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;IACjD,MAAM,YAAY,GAAG,QAAQ,CAAC,YAAY,IAAI,CAAC,CAAC;IAChD,MAAM,eAAe,GAAG,QAAQ,CAAC,eAAe,IAAI,CAAC,CAAC;IACtD,0DAA0D;IAC1D,IAAI,OAAO,QAAQ,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;QACzC,OAAO;YACL,QAAQ,EAAE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,YAAY,EAAE,CAAC;QACf,SAAS,EAAE,CAAC;KACb,CAAC;IACF,OAAO;QACL,UAAU,CAAC,KAAK;YACd,MAAM,CAAC,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;YACpC,MAAM,GAAG;gBACP,WAAW,EAAE,MAAM,CAAC,WAAW,GAAG,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,SAAS;gBAC1D,QAAQ,EAAE,MAAM,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ;gBACtC,SAAS,EAAE,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS;gBACzC,YAAY,EAAE,MAAM,CAAC,YAAY,GAAG,CAAC,CAAC,YAAY;gBAClD,eAAe,EAAE,MAAM,CAAC,eAAe,GAAG,CAAC,CAAC,eAAe;gBAC3D,YAAY,EAAE,MAAM,CAAC,YAAY,GAAG,CAAC,CAAC,OAAO;gBAC7C,SAAS,EAAE,MAAM,CAAC,SAAS,GAAG,CAAC;aAChC,CAAC;YACF,OAAO,CAAC,CAAC;QACX,CAAC;QACD,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,CAAC;QAC7B,KAAK;YACH,MAAM,GAAG;gBACP,WAAW,EAAE,CAAC;gBACd,QAAQ,EAAE,CAAC;gBACX,SAAS,EAAE,CAAC;gBACZ,YAAY,EAAE,CAAC;gBACf,eAAe,EAAE,CAAC;gBAClB,YAAY,EAAE,CAAC;gBACf,SAAS,EAAE,CAAC;aACb,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node-only entry point.
|
|
3
|
+
*
|
|
4
|
+
* The event log writer imports `node:fs` / `node:os` at module init
|
|
5
|
+
* for append-only NDJSON logging to disk. It lives here so the
|
|
6
|
+
* browser-facing root entry (`@inbrowser/agent`) stays free of Node
|
|
7
|
+
* builtins.
|
|
8
|
+
*
|
|
9
|
+
* Consumers running in Node (the CLI, the MCP server, sdk's agent
|
|
10
|
+
* definitions, integration tests) import from `@inbrowser/agent/node`.
|
|
11
|
+
* Browser consumers (playground) use the root entry, which exposes
|
|
12
|
+
* the browser-safe events helpers (`wrapMutating`, `replayEvents`,
|
|
13
|
+
* codec utilities) directly without going through `events/index.js`.
|
|
14
|
+
*
|
|
15
|
+
* Other Node-only files in this package (`metrics/runs`, `agents/
|
|
16
|
+
* firestore`, the CLI commands) have no external consumers via the
|
|
17
|
+
* public barrel today, so they stay reachable via relative paths
|
|
18
|
+
* within the package.
|
|
19
|
+
*/
|
|
20
|
+
export { openEventLog, defaultProjectLogDir } from './events/log.js';
|
|
21
|
+
export { generateEventId, buildRollbackEvent, HOST_AGENT_ID, EventTooLargeError, DEFAULT_MAX_EVENT_BYTES, } from './events/log-core.js';
|
|
22
|
+
//# sourceMappingURL=node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,kBAAkB,EAClB,uBAAuB,GACxB,MAAM,sBAAsB,CAAC"}
|
package/dist/node.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node-only entry point.
|
|
3
|
+
*
|
|
4
|
+
* The event log writer imports `node:fs` / `node:os` at module init
|
|
5
|
+
* for append-only NDJSON logging to disk. It lives here so the
|
|
6
|
+
* browser-facing root entry (`@inbrowser/agent`) stays free of Node
|
|
7
|
+
* builtins.
|
|
8
|
+
*
|
|
9
|
+
* Consumers running in Node (the CLI, the MCP server, sdk's agent
|
|
10
|
+
* definitions, integration tests) import from `@inbrowser/agent/node`.
|
|
11
|
+
* Browser consumers (playground) use the root entry, which exposes
|
|
12
|
+
* the browser-safe events helpers (`wrapMutating`, `replayEvents`,
|
|
13
|
+
* codec utilities) directly without going through `events/index.js`.
|
|
14
|
+
*
|
|
15
|
+
* Other Node-only files in this package (`metrics/runs`, `agents/
|
|
16
|
+
* firestore`, the CLI commands) have no external consumers via the
|
|
17
|
+
* public barrel today, so they stay reachable via relative paths
|
|
18
|
+
* within the package.
|
|
19
|
+
*/
|
|
20
|
+
export { openEventLog, defaultProjectLogDir } from './events/log.js';
|
|
21
|
+
export { generateEventId, buildRollbackEvent, HOST_AGENT_ID, EventTooLargeError, DEFAULT_MAX_EVENT_BYTES, } from './events/log-core.js';
|
|
22
|
+
//# sourceMappingURL=node.js.map
|
package/dist/node.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,kBAAkB,EAClB,uBAAuB,GACxB,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `createAgentSession()` — the host-facing session container.
|
|
3
|
+
*
|
|
4
|
+
* Generic over the strategy. Translates a `StrategyEvent` stream
|
|
5
|
+
* into the typed `SessionEvent` stream the host consumes. Tracks
|
|
6
|
+
* workspace + runtime patches as tool results flow in.
|
|
7
|
+
*/
|
|
8
|
+
import type { AgentSession, AgentSessionConfig } from './types/session.js';
|
|
9
|
+
export declare function createAgentSession(config: AgentSessionConfig): AgentSession;
|
|
10
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAgB,MAAM,oBAAoB,CAAC;AAOzF,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,GAAG,YAAY,CA+H3E"}
|
package/dist/session.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `createAgentSession()` — the host-facing session container.
|
|
3
|
+
*
|
|
4
|
+
* Generic over the strategy. Translates a `StrategyEvent` stream
|
|
5
|
+
* into the typed `SessionEvent` stream the host consumes. Tracks
|
|
6
|
+
* workspace + runtime patches as tool results flow in.
|
|
7
|
+
*/
|
|
8
|
+
let sessionCounter = 0;
|
|
9
|
+
export function createAgentSession(config) {
|
|
10
|
+
const id = config.id ?? `session-${++sessionCounter}-${Date.now().toString(36)}`;
|
|
11
|
+
let workspace = freezeWorkspace(config.history.length > 0 ? extractInitialWorkspace(config) : initialWorkspace());
|
|
12
|
+
let runtime = initialRuntime();
|
|
13
|
+
let history = [...config.history];
|
|
14
|
+
let currentAbort = null;
|
|
15
|
+
const session = {
|
|
16
|
+
id,
|
|
17
|
+
get workspace() {
|
|
18
|
+
return workspace;
|
|
19
|
+
},
|
|
20
|
+
get runtime() {
|
|
21
|
+
return runtime;
|
|
22
|
+
},
|
|
23
|
+
submit(prompt, externalSignal) {
|
|
24
|
+
// Compose an internal controller that listens to both the
|
|
25
|
+
// external signal and our `cancel()` override.
|
|
26
|
+
const inner = new AbortController();
|
|
27
|
+
currentAbort = inner;
|
|
28
|
+
const linked = linkSignals(externalSignal, inner.signal);
|
|
29
|
+
return run(prompt, linked);
|
|
30
|
+
},
|
|
31
|
+
cancel() {
|
|
32
|
+
currentAbort?.abort();
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
function bumpWorkspace(patch) {
|
|
36
|
+
if (!patch)
|
|
37
|
+
return false;
|
|
38
|
+
workspace = freezeWorkspace({ ...workspace, ...patch });
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
function bumpRuntime(patch) {
|
|
42
|
+
if (!patch)
|
|
43
|
+
return false;
|
|
44
|
+
runtime = freezeRuntime({ ...runtime, ...patch });
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
async function* run(prompt, signal) {
|
|
48
|
+
const turnId = `t-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 6)}`;
|
|
49
|
+
yield { kind: 'turn_started', turnId };
|
|
50
|
+
// Capture the user message in history so the next turn sees it.
|
|
51
|
+
const userMsg = {
|
|
52
|
+
id: `u-${turnId}`,
|
|
53
|
+
role: 'user',
|
|
54
|
+
text: prompt,
|
|
55
|
+
timestamp: Date.now(),
|
|
56
|
+
};
|
|
57
|
+
history = [...history, userMsg];
|
|
58
|
+
const systemPrompt = config.systemPromptBuilder(workspace, runtime);
|
|
59
|
+
const strategyEvents = config.strategy.run({
|
|
60
|
+
prompt,
|
|
61
|
+
history,
|
|
62
|
+
workspace,
|
|
63
|
+
runtime,
|
|
64
|
+
llm: config.llm,
|
|
65
|
+
tools: config.tools,
|
|
66
|
+
toolList: config.toolList,
|
|
67
|
+
toolContext: config.toolContext,
|
|
68
|
+
systemPrompt,
|
|
69
|
+
...(config.tracer ? { tracer: config.tracer } : {}),
|
|
70
|
+
turnId,
|
|
71
|
+
}, signal);
|
|
72
|
+
let assistantText = '';
|
|
73
|
+
const assistantId = `a-${turnId}`;
|
|
74
|
+
for await (const ev of strategyEvents) {
|
|
75
|
+
if (ev.kind === 'text') {
|
|
76
|
+
assistantText += ev.chunk;
|
|
77
|
+
yield { kind: 'text', turnId, chunk: ev.chunk };
|
|
78
|
+
}
|
|
79
|
+
else if (ev.kind === 'thinking') {
|
|
80
|
+
yield { kind: 'thinking', turnId, chunk: ev.chunk };
|
|
81
|
+
}
|
|
82
|
+
else if (ev.kind === 'tool_call') {
|
|
83
|
+
yield {
|
|
84
|
+
kind: 'tool_started',
|
|
85
|
+
turnId,
|
|
86
|
+
callId: ev.id,
|
|
87
|
+
name: ev.name,
|
|
88
|
+
args: ev.args,
|
|
89
|
+
...(ev.signature ? { signature: ev.signature } : {}),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
else if (ev.kind === 'tool_result') {
|
|
93
|
+
const wsBumped = bumpWorkspace(ev.result.workspacePatch);
|
|
94
|
+
const rtBumped = bumpRuntime(ev.result.runtimePatch);
|
|
95
|
+
yield { kind: 'tool_finished', turnId, callId: ev.id, result: ev.result };
|
|
96
|
+
if (wsBumped)
|
|
97
|
+
yield { kind: 'workspace_changed', workspace };
|
|
98
|
+
if (rtBumped)
|
|
99
|
+
yield { kind: 'runtime_changed', runtime };
|
|
100
|
+
}
|
|
101
|
+
else if (ev.kind === 'turn_complete') {
|
|
102
|
+
const metrics = config.metrics.recordTurn({
|
|
103
|
+
llmId: config.llm.id,
|
|
104
|
+
model: ev.details.requestedModel,
|
|
105
|
+
durationMs: 0,
|
|
106
|
+
rawUsage: ev.usage,
|
|
107
|
+
});
|
|
108
|
+
// Append assistant message to history.
|
|
109
|
+
const assistantMsg = {
|
|
110
|
+
id: assistantId,
|
|
111
|
+
role: 'assistant',
|
|
112
|
+
text: assistantText,
|
|
113
|
+
metrics,
|
|
114
|
+
details: ev.details,
|
|
115
|
+
timestamp: Date.now(),
|
|
116
|
+
};
|
|
117
|
+
history = [...history, assistantMsg];
|
|
118
|
+
yield { kind: 'turn_completed', turnId, metrics, details: ev.details };
|
|
119
|
+
}
|
|
120
|
+
else if (ev.kind === 'error') {
|
|
121
|
+
yield { kind: 'error', turnId, message: ev.message };
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
else if (ev.kind === 'custom') {
|
|
125
|
+
yield { kind: 'strategy_event', name: ev.name, data: ev.data };
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
yield { kind: 'completed' };
|
|
129
|
+
}
|
|
130
|
+
return session;
|
|
131
|
+
}
|
|
132
|
+
function initialWorkspace() {
|
|
133
|
+
return freezeWorkspace({
|
|
134
|
+
presetId: '',
|
|
135
|
+
rules: '',
|
|
136
|
+
code: '',
|
|
137
|
+
appSource: '',
|
|
138
|
+
stitch: { projectId: null, latestScreenUrl: null, brief: null },
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
function extractInitialWorkspace(config) {
|
|
142
|
+
// History-only resume — workspace can be threaded in by the caller
|
|
143
|
+
// via a follow-up patch, but the session's initial workspace shape
|
|
144
|
+
// matches the empty defaults until then.
|
|
145
|
+
void config;
|
|
146
|
+
return initialWorkspace();
|
|
147
|
+
}
|
|
148
|
+
function initialRuntime() {
|
|
149
|
+
return freezeRuntime({
|
|
150
|
+
terminal: [],
|
|
151
|
+
runSummary: null,
|
|
152
|
+
deploy: null,
|
|
153
|
+
parseError: null,
|
|
154
|
+
uiErrors: [],
|
|
155
|
+
sandboxVersion: 0,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
function freezeWorkspace(w) {
|
|
159
|
+
return Object.freeze({ ...w, stitch: Object.freeze({ ...w.stitch }) });
|
|
160
|
+
}
|
|
161
|
+
function freezeRuntime(r) {
|
|
162
|
+
return Object.freeze({
|
|
163
|
+
...r,
|
|
164
|
+
terminal: Object.freeze([...r.terminal]),
|
|
165
|
+
uiErrors: Object.freeze([...r.uiErrors]),
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
/** Combine two abort signals into one that fires when either fires. */
|
|
169
|
+
function linkSignals(a, b) {
|
|
170
|
+
const controller = new AbortController();
|
|
171
|
+
if (a.aborted || b.aborted) {
|
|
172
|
+
controller.abort();
|
|
173
|
+
return controller.signal;
|
|
174
|
+
}
|
|
175
|
+
a.addEventListener('abort', () => controller.abort(), { once: true });
|
|
176
|
+
b.addEventListener('abort', () => controller.abort(), { once: true });
|
|
177
|
+
return controller.signal;
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../src/session.ts"],"names":[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AM,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAwC;KAChF,CAAiB,CAAC;AACrB,CAAC;AAED,uEAAuE;AACvE,SAAS,WAAW,CAAC,CAAc,EAAE,CAAc;IACjD,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IACzC,IAAI,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;QAC3B,UAAU,CAAC,KAAK,EAAE,CAAC;QACnB,OAAO,UAAU,CAAC,MAAM,CAAC;IAC3B,CAAC;IACD,CAAC,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IACtE,CAAC,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IACtE,OAAO,UAAU,CAAC,MAAM,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `Storage` runtime helpers — adapters over the `Storage` interface
|
|
3
|
+
* in `./types/storage.ts`. `noopStorage` and `createMemoryStorage`
|
|
4
|
+
* are exported from the types module since they have no dependencies;
|
|
5
|
+
* this file adds adapters that DO have host-specific deps.
|
|
6
|
+
*/
|
|
7
|
+
import type { Storage } from './types/storage.js';
|
|
8
|
+
/**
|
|
9
|
+
* Browser-only adapter over `window.localStorage`. Errors (private
|
|
10
|
+
* browsing, quota-exceeded) are swallowed silently — `get` returns
|
|
11
|
+
* null, `set` is a no-op, the host doesn't crash.
|
|
12
|
+
*/
|
|
13
|
+
export declare function createLocalStorageAdapter(): Storage;
|
|
14
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAElD;;;;GAIG;AACH,wBAAgB,yBAAyB,IAAI,OAAO,CAwCnD"}
|
package/dist/storage.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `Storage` runtime helpers — adapters over the `Storage` interface
|
|
3
|
+
* in `./types/storage.ts`. `noopStorage` and `createMemoryStorage`
|
|
4
|
+
* are exported from the types module since they have no dependencies;
|
|
5
|
+
* this file adds adapters that DO have host-specific deps.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Browser-only adapter over `window.localStorage`. Errors (private
|
|
9
|
+
* browsing, quota-exceeded) are swallowed silently — `get` returns
|
|
10
|
+
* null, `set` is a no-op, the host doesn't crash.
|
|
11
|
+
*/
|
|
12
|
+
export function createLocalStorageAdapter() {
|
|
13
|
+
return {
|
|
14
|
+
get(key) {
|
|
15
|
+
try {
|
|
16
|
+
return globalThis.localStorage?.getItem(key) ?? null;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
set(key, value) {
|
|
23
|
+
try {
|
|
24
|
+
globalThis.localStorage?.setItem(key, value);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
/* quota / private-mode */
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
remove(key) {
|
|
31
|
+
try {
|
|
32
|
+
globalThis.localStorage?.removeItem(key);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
/* ignored */
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
keys(prefix) {
|
|
39
|
+
try {
|
|
40
|
+
const ls = globalThis.localStorage;
|
|
41
|
+
if (!ls)
|
|
42
|
+
return [];
|
|
43
|
+
const out = [];
|
|
44
|
+
for (let i = 0; i < ls.length; i++) {
|
|
45
|
+
const k = ls.key(i);
|
|
46
|
+
if (k !== null && (prefix === undefined || k.startsWith(prefix))) {
|
|
47
|
+
out.push(k);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;;;GAIG;AACH,MAAM,UAAU,yBAAyB;IACvC,OAAO;QACL,GAAG,CAAC,GAAG;YACL,IAAI,CAAC;gBACH,OAAO,UAAU,CAAC,YAAY,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC;YACvD,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QACD,GAAG,CAAC,GAAG,EAAE,KAAK;YACZ,IAAI,CAAC;gBACH,UAAU,CAAC,YAAY,EAAE,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YAC/C,CAAC;YAAC,MAAM,CAAC;gBACP,0BAA0B;YAC5B,CAAC;QACH,CAAC;QACD,MAAM,CAAC,GAAG;YACR,IAAI,CAAC;gBACH,UAAU,CAAC,YAAY,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC;YAC3C,CAAC;YAAC,MAAM,CAAC;gBACP,aAAa;YACf,CAAC;QACH,CAAC;QACD,IAAI,CAAC,MAAM;YACT,IAAI,CAAC;gBACH,MAAM,EAAE,GAAG,UAAU,CAAC,YAAY,CAAC;gBACnC,IAAI,CAAC,EAAE;oBAAE,OAAO,EAAE,CAAC;gBACnB,MAAM,GAAG,GAAa,EAAE,CAAC;gBACzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;oBACnC,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;oBACpB,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,IAAI,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;wBACjE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;oBACd,CAAC;gBACH,CAAC;gBACD,OAAO,GAAG,CAAC;YACb,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,EAAE,CAAC;YACZ,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `createReactLoopStrategy()` — the default `AgentStrategy`.
|
|
3
|
+
*
|
|
4
|
+
* Implements the playground's current ReAct-style behavior:
|
|
5
|
+
*
|
|
6
|
+
* 1. Compose `[system, ...history, user(prompt)]` as the message
|
|
7
|
+
* array.
|
|
8
|
+
* 2. Issue one chat call against the LLM with the tool list.
|
|
9
|
+
* 3. Stream `text` / `thinking` / `tool_call` events through.
|
|
10
|
+
* 4. When the LLM produces tool calls, dispatch each one, append
|
|
11
|
+
* the result message, and loop back to step 2.
|
|
12
|
+
* 5. When the LLM produces no tool calls in a turn, emit
|
|
13
|
+
* `turn_complete` and finish.
|
|
14
|
+
*
|
|
15
|
+
* Future strategies (planner-executor, graph-of-thoughts,
|
|
16
|
+
* parallel-branch ensembling) sit alongside this one — same
|
|
17
|
+
* `AgentStrategy` interface, different control flow.
|
|
18
|
+
*/
|
|
19
|
+
import type { AgentStrategy } from './types/strategy.js';
|
|
20
|
+
interface ReactLoopOptions {
|
|
21
|
+
/** Cap on loop iterations to avoid runaway tool-call ping-pong. Default 24. */
|
|
22
|
+
maxTurns?: number;
|
|
23
|
+
}
|
|
24
|
+
export declare function createReactLoopStrategy(options?: ReactLoopOptions): AgentStrategy;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=strategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategy.d.ts","sourceRoot":"","sources":["../src/strategy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAmC,MAAM,qBAAqB,CAAC;AAG1F,UAAU,gBAAgB;IACxB,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,uBAAuB,CAAC,OAAO,GAAE,gBAAqB,GAAG,aAAa,CAoIrF"}
|