@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/types/session.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACrF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,MAAM,WAAW,kBAAkB;IACjC,0DAA0D;IAC1D,QAAQ,EAAE,aAAa,CAAC;IACxB,GAAG,EAAE,SAAS,CAAC;IACf,KAAK,EAAE,YAAY,CAAC;IACpB;;;6CAGyC;IACzC,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB;;yCAEqC;IACrC,WAAW,IAAI,WAAW,CAAC;IA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,GAC7E;IAAE,IAAI,EAAE,mBAAmB,CAAC;IAAC,SAAS,EAAE,SAAS,CAAA;CAAE,GACnD;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,OAAO,EAAE,YAAY,CAAA;CAAE,GAClD;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,WAAW,CAAC;IAAC,OAAO,EAAE,WAAW,CAAA;CAAE,GACtF;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACnD;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE;AACvB;;mCAEmC;GACjC;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `AgentSession` + `SessionEvent` — host-facing surfaces for one
|
|
3
|
+
* in-flight agent run.
|
|
4
|
+
*
|
|
5
|
+
* The session is a generic container — it owns the id, the workspace
|
|
6
|
+
* + runtime references, the cancellation token, and the typed event
|
|
7
|
+
* stream. The actual inference algorithm lives in an `AgentStrategy`
|
|
8
|
+
* (`./strategy.ts`).
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/types/session.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `Storage` — the platform-level key/value abstraction over
|
|
3
|
+
* `localStorage` / fs / in-memory. Used for BYOK keys, layout
|
|
4
|
+
* prefs, last-used project id, recent-sessions cache.
|
|
5
|
+
*
|
|
6
|
+
* Distinct from `@pyric/storage` (Firebase Storage adapter for
|
|
7
|
+
* user-owned cloud data). They live at different layers.
|
|
8
|
+
*/
|
|
9
|
+
export interface Storage {
|
|
10
|
+
get(key: string): string | null;
|
|
11
|
+
set(key: string, value: string): void;
|
|
12
|
+
remove(key: string): void;
|
|
13
|
+
/** Optionally list keys with a prefix. Implementations may degrade to []. */
|
|
14
|
+
keys(prefix?: string): string[];
|
|
15
|
+
}
|
|
16
|
+
/** No-op storage. Useful for tests + the headless CLI's default. */
|
|
17
|
+
export declare const noopStorage: Storage;
|
|
18
|
+
/** In-memory storage. Thread-safe within one event loop. */
|
|
19
|
+
export declare function createMemoryStorage(seed?: Record<string, string>): Storage;
|
|
20
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/types/storage.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,WAAW,OAAO;IACtB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAChC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACtC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,6EAA6E;IAC7E,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACjC;AAED,oEAAoE;AACpE,eAAO,MAAM,WAAW,EAAE,OASxB,CAAC;AAEH,4DAA4D;AAC5D,wBAAgB,mBAAmB,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAkB1E"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `Storage` — the platform-level key/value abstraction over
|
|
3
|
+
* `localStorage` / fs / in-memory. Used for BYOK keys, layout
|
|
4
|
+
* prefs, last-used project id, recent-sessions cache.
|
|
5
|
+
*
|
|
6
|
+
* Distinct from `@pyric/storage` (Firebase Storage adapter for
|
|
7
|
+
* user-owned cloud data). They live at different layers.
|
|
8
|
+
*/
|
|
9
|
+
/** No-op storage. Useful for tests + the headless CLI's default. */
|
|
10
|
+
export const noopStorage = Object.freeze({
|
|
11
|
+
get: () => null,
|
|
12
|
+
set: () => {
|
|
13
|
+
/* ignored */
|
|
14
|
+
},
|
|
15
|
+
remove: () => {
|
|
16
|
+
/* ignored */
|
|
17
|
+
},
|
|
18
|
+
keys: () => [],
|
|
19
|
+
});
|
|
20
|
+
/** In-memory storage. Thread-safe within one event loop. */
|
|
21
|
+
export function createMemoryStorage(seed) {
|
|
22
|
+
const map = new Map(seed ? Object.entries(seed) : []);
|
|
23
|
+
return {
|
|
24
|
+
get: (k) => map.get(k) ?? null,
|
|
25
|
+
set: (k, v) => {
|
|
26
|
+
map.set(k, v);
|
|
27
|
+
},
|
|
28
|
+
remove: (k) => {
|
|
29
|
+
map.delete(k);
|
|
30
|
+
},
|
|
31
|
+
keys: (prefix) => {
|
|
32
|
+
const out = [];
|
|
33
|
+
for (const k of map.keys()) {
|
|
34
|
+
if (prefix === undefined || k.startsWith(prefix))
|
|
35
|
+
out.push(k);
|
|
36
|
+
}
|
|
37
|
+
return out;
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../src/types/storage.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAUH,oEAAoE;AACpE,MAAM,CAAC,MAAM,WAAW,GAAY,MAAM,CAAC,MAAM,CAAC;IAChD,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI;IACf,GAAG,EAAE,GAAG,EAAE;QACR,aAAa;IACf,CAAC;IACD,MAAM,EAAE,GAAG,EAAE;QACX,aAAa;IACf,CAAC;IACD,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE;CACf,CAAC,CAAC;AAEH,4DAA4D;AAC5D,MAAM,UAAU,mBAAmB,CAAC,IAA6B;IAC/D,MAAM,GAAG,GAAG,IAAI,GAAG,CAAiB,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACtE,OAAO;QACL,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,IAAI;QAC9B,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YACZ,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAChB,CAAC;QACD,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE;YACZ,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAChB,CAAC;QACD,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE;YACf,MAAM,GAAG,GAAa,EAAE,CAAC;YACzB,KAAK,MAAM,CAAC,IAAI,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC;gBAC3B,IAAI,MAAM,KAAK,SAAS,IAAI,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC;oBAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAChE,CAAC;YACD,OAAO,GAAG,CAAC;QACb,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `AgentStrategy` — the pluggable inference algorithm.
|
|
3
|
+
*
|
|
4
|
+
* The current ReAct-style single-loop behavior is one strategy;
|
|
5
|
+
* future planner / graph / parallel-branch strategies are new files
|
|
6
|
+
* implementing this same interface. The session's external event
|
|
7
|
+
* surface stays stable; only the internals change.
|
|
8
|
+
*/
|
|
9
|
+
import type { ChatMessage, TurnDetails } from './chat.js';
|
|
10
|
+
import type { LlmClient, RawUsage } from './llm.js';
|
|
11
|
+
import type { RuntimeState } from './runtime.js';
|
|
12
|
+
import type { ToolContext, ToolDispatch, ToolHandler, ToolResult } from './tools.js';
|
|
13
|
+
import type { Tracer } from './trace.js';
|
|
14
|
+
import type { Workspace } from './workspace.js';
|
|
15
|
+
export interface AgentStrategy {
|
|
16
|
+
readonly id: string;
|
|
17
|
+
/**
|
|
18
|
+
* Execute one user prompt to completion. Returns the strategy's
|
|
19
|
+
* event stream — the session translates it into `SessionEvent`s.
|
|
20
|
+
*/
|
|
21
|
+
run(input: StrategyRunInput, signal: AbortSignal): AsyncIterable<StrategyEvent>;
|
|
22
|
+
}
|
|
23
|
+
export interface StrategyRunInput {
|
|
24
|
+
prompt: string;
|
|
25
|
+
history: ChatMessage[];
|
|
26
|
+
workspace: Workspace;
|
|
27
|
+
runtime: RuntimeState;
|
|
28
|
+
llm: LlmClient;
|
|
29
|
+
tools: ToolDispatch;
|
|
30
|
+
/** Already filtered by the active capabilities. */
|
|
31
|
+
toolList: ToolHandler[];
|
|
32
|
+
/** Factory — call per tool exec so the latest workspace/runtime flows in. */
|
|
33
|
+
toolContext(): ToolContext;
|
|
34
|
+
/** Pre-built by the session from `Workspace` + `RuntimeState`. */
|
|
35
|
+
systemPrompt: string;
|
|
36
|
+
/** Optional trace sink — emitted at well-defined moments in the
|
|
37
|
+
* loop (request about to dispatch; response complete). The
|
|
38
|
+
* strategy never inspects the impl. Absent = zero-cost no-op. */
|
|
39
|
+
tracer?: Tracer;
|
|
40
|
+
/** Optional session-scoped id used by the strategy when generating
|
|
41
|
+
* per-iteration `requestId`s. The session is what owns the turn
|
|
42
|
+
* identity; the strategy receives it for trace labeling only. */
|
|
43
|
+
turnId?: string;
|
|
44
|
+
}
|
|
45
|
+
export type StrategyEvent = {
|
|
46
|
+
kind: 'text';
|
|
47
|
+
chunk: string;
|
|
48
|
+
} | {
|
|
49
|
+
kind: 'thinking';
|
|
50
|
+
chunk: string;
|
|
51
|
+
} | {
|
|
52
|
+
kind: 'tool_call';
|
|
53
|
+
id: string;
|
|
54
|
+
name: string;
|
|
55
|
+
args: unknown;
|
|
56
|
+
signature?: string;
|
|
57
|
+
} | {
|
|
58
|
+
kind: 'tool_result';
|
|
59
|
+
id: string;
|
|
60
|
+
result: ToolResult;
|
|
61
|
+
} | {
|
|
62
|
+
kind: 'turn_complete';
|
|
63
|
+
usage: RawUsage;
|
|
64
|
+
details: TurnDetails;
|
|
65
|
+
} | {
|
|
66
|
+
kind: 'error';
|
|
67
|
+
message: string;
|
|
68
|
+
}
|
|
69
|
+
/** Custom milestone — name + arbitrary payload, surfaced as
|
|
70
|
+
* `SessionEvent.kind === 'strategy_event'` to the host. */
|
|
71
|
+
| {
|
|
72
|
+
kind: 'custom';
|
|
73
|
+
name: string;
|
|
74
|
+
data?: unknown;
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=strategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategy.d.ts","sourceRoot":"","sources":["../../src/types/strategy.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACrF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,GAAG,CAAC,KAAK,EAAE,gBAAgB,EAAE,MAAM,EAAE,WAAW,GAAG,aAAa,CAAC,aAAa,CAAC,CA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,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `AgentStrategy` — the pluggable inference algorithm.
|
|
3
|
+
*
|
|
4
|
+
* The current ReAct-style single-loop behavior is one strategy;
|
|
5
|
+
* future planner / graph / parallel-branch strategies are new files
|
|
6
|
+
* implementing this same interface. The session's external event
|
|
7
|
+
* surface stays stable; only the internals change.
|
|
8
|
+
*/
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategy.js","sourceRoot":"","sources":["../../src/types/strategy.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool registry + dispatch + handler types.
|
|
3
|
+
*
|
|
4
|
+
* The `ToolRegistry` is a configuration concern (what tools exist);
|
|
5
|
+
* `ToolDispatch` is a runtime concern (run the named one against this
|
|
6
|
+
* context). Splitting them lets a host wire the catalog at startup
|
|
7
|
+
* with `registry.register(handler)` and lets concurrent sessions
|
|
8
|
+
* share a stateless dispatcher.
|
|
9
|
+
*/
|
|
10
|
+
import type { Capabilities } from './capabilities.js';
|
|
11
|
+
import type { JsonSchema } from './llm.js';
|
|
12
|
+
import type { RuntimeState } from './runtime.js';
|
|
13
|
+
import type { StitchContext, Workspace } from './workspace.js';
|
|
14
|
+
export interface ToolHandler<A = unknown, D = unknown> {
|
|
15
|
+
name: string;
|
|
16
|
+
description: string;
|
|
17
|
+
parameters: JsonSchema;
|
|
18
|
+
/** Capability gate — handler is excluded from `list()` when this returns false. */
|
|
19
|
+
available?(capabilities: Capabilities): boolean;
|
|
20
|
+
execute(args: A, ctx: ToolContext): Promise<ToolResult<D>>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Session-scoped context handed to every tool's `execute`. Kept
|
|
24
|
+
* narrow per F8 — only `signal` is required; everything else is
|
|
25
|
+
* optional so headless hosts (Deployment Agent, MCP server) don't
|
|
26
|
+
* have to mock playground-shaped state.
|
|
27
|
+
*
|
|
28
|
+
* Per F2 + F5, factories capture their own deps at construction
|
|
29
|
+
* time (closure) and tool handlers only read from {deps, args, ctx}.
|
|
30
|
+
* Don't grow this interface to satisfy specific factories.
|
|
31
|
+
*/
|
|
32
|
+
export interface ToolContext {
|
|
33
|
+
/** Cancellation signal — tools should respect it for long-running ops. */
|
|
34
|
+
signal: AbortSignal;
|
|
35
|
+
/** Playground / session workspace (rules source, agent JS, etc.). */
|
|
36
|
+
workspace?: Workspace;
|
|
37
|
+
/** Playground / session runtime state (last sandbox run, etc.). */
|
|
38
|
+
runtime?: RuntimeState;
|
|
39
|
+
/** Per-session sandbox handle, when the host has one. */
|
|
40
|
+
sandbox?: SandboxHandle;
|
|
41
|
+
/** Pure-function lint, injected for testability. */
|
|
42
|
+
lint?: LintFn;
|
|
43
|
+
/** Optional Stitch client — absent when capability disables it. */
|
|
44
|
+
stitch?: StitchClient;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Minimal sandbox surface tools need. The host injects a concrete
|
|
48
|
+
* adapter (today: `@pyric/sandbox` runner). Kept narrow so tool tests
|
|
49
|
+
* can stub it without pulling in the whole sandbox package.
|
|
50
|
+
*/
|
|
51
|
+
export interface SandboxHandle {
|
|
52
|
+
run(code: string, signal?: AbortSignal): Promise<{
|
|
53
|
+
ok: boolean;
|
|
54
|
+
durationMs: number;
|
|
55
|
+
docsTouched: number;
|
|
56
|
+
errors: number;
|
|
57
|
+
entries: unknown[];
|
|
58
|
+
}>;
|
|
59
|
+
deployRules(source: string): Promise<{
|
|
60
|
+
ok: boolean;
|
|
61
|
+
messages: {
|
|
62
|
+
severity: 'info' | 'warn' | 'error';
|
|
63
|
+
text: string;
|
|
64
|
+
line?: number;
|
|
65
|
+
column?: number;
|
|
66
|
+
}[];
|
|
67
|
+
}>;
|
|
68
|
+
readState(opts?: {
|
|
69
|
+
path?: string;
|
|
70
|
+
maxDepth?: number;
|
|
71
|
+
}): Promise<unknown>;
|
|
72
|
+
reseed(opts: {
|
|
73
|
+
presetId: string;
|
|
74
|
+
}): void;
|
|
75
|
+
dispose(): void;
|
|
76
|
+
}
|
|
77
|
+
export type LintFn = (source: string) => {
|
|
78
|
+
warnings: LintWarning[];
|
|
79
|
+
};
|
|
80
|
+
export interface LintWarning {
|
|
81
|
+
severity: 'info' | 'warn' | 'error';
|
|
82
|
+
message: string;
|
|
83
|
+
line?: number;
|
|
84
|
+
column?: number;
|
|
85
|
+
}
|
|
86
|
+
/** Optional Stitch design client. Absent in headless / capability-off runs. */
|
|
87
|
+
export interface StitchClient {
|
|
88
|
+
hasKey(): boolean;
|
|
89
|
+
context(): StitchContext;
|
|
90
|
+
}
|
|
91
|
+
export interface ToolResult<D = unknown> {
|
|
92
|
+
ok: boolean;
|
|
93
|
+
/** One-line human-readable summary the model can quote back. */
|
|
94
|
+
summary: string;
|
|
95
|
+
data?: D;
|
|
96
|
+
/** Patches applied by the session to its own state. */
|
|
97
|
+
workspacePatch?: Partial<Workspace>;
|
|
98
|
+
runtimePatch?: Partial<RuntimeState>;
|
|
99
|
+
}
|
|
100
|
+
export interface ToolCall {
|
|
101
|
+
id: string;
|
|
102
|
+
name: string;
|
|
103
|
+
args: unknown;
|
|
104
|
+
}
|
|
105
|
+
export interface ToolRegistry {
|
|
106
|
+
/**
|
|
107
|
+
* Register a new handler. **Throws** if `handler.name` is already
|
|
108
|
+
* present — catches the "accidentally registered two factories
|
|
109
|
+
* with overlapping tools" footgun (F6). Use `replace` for explicit
|
|
110
|
+
* overlays.
|
|
111
|
+
*/
|
|
112
|
+
register(handler: ToolHandler): void;
|
|
113
|
+
/**
|
|
114
|
+
* Idempotent registration. Replaces an existing handler with the
|
|
115
|
+
* same name, or registers fresh. The standard shape for
|
|
116
|
+
* decoration via `.map` before register (F7):
|
|
117
|
+
*
|
|
118
|
+
* ```ts
|
|
119
|
+
* for (const t of createXxxTools(deps).map(wrapMutating)) {
|
|
120
|
+
* registry.register(t); // or replace(t) if re-wrapping
|
|
121
|
+
* }
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
replace(handler: ToolHandler): void;
|
|
125
|
+
unregister(name: string): boolean;
|
|
126
|
+
list(opts?: {
|
|
127
|
+
capabilities?: Capabilities;
|
|
128
|
+
}): ToolHandler[];
|
|
129
|
+
has(name: string): boolean;
|
|
130
|
+
/** Copy-on-write fork for per-session catalog overrides. */
|
|
131
|
+
fork(): ToolRegistry;
|
|
132
|
+
}
|
|
133
|
+
export interface ToolDispatch {
|
|
134
|
+
execute(call: ToolCall, ctx: ToolContext): Promise<ToolResult>;
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/types/tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE/D,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,UAAU,CAAC;IACvB,mFAAmF;IACnF,SAAS,CAAC,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC;IAChD,OAAO,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;CAC5D;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,WAAW;IAC1B,0EAA0E;IAC1E,M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AAG,OAAO,CAAC,UAAU,CAAC,CAAC;CAChE"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool registry + dispatch + handler types.
|
|
3
|
+
*
|
|
4
|
+
* The `ToolRegistry` is a configuration concern (what tools exist);
|
|
5
|
+
* `ToolDispatch` is a runtime concern (run the named one against this
|
|
6
|
+
* context). Splitting them lets a host wire the catalog at startup
|
|
7
|
+
* with `registry.register(handler)` and lets concurrent sessions
|
|
8
|
+
* share a stateless dispatcher.
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/types/tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent-loop request/response trace surface.
|
|
3
|
+
*
|
|
4
|
+
* Captures the exact shape of every LLM request the strategy
|
|
5
|
+
* dispatches — system prompt + messages + tool decls + model — at
|
|
6
|
+
* the layer the agent author thinks in (`@inbrowser/agent` types), not
|
|
7
|
+
* the provider-specific transform below it. A provider-level trace
|
|
8
|
+
* (Gemini's `GeminiBody`, OpenRouter's `messages[].content` parts)
|
|
9
|
+
* is a complementary concern that belongs to `@inbrowser/relay`;
|
|
10
|
+
* this surface is for "what did the model see, in agent terms."
|
|
11
|
+
*
|
|
12
|
+
* Emission is opt-in. A `Tracer` plugs into `AgentSessionConfig`
|
|
13
|
+
* (which threads it through `StrategyRunInput`); strategies that
|
|
14
|
+
* support tracing call `tracer.emit(...)` at well-defined moments.
|
|
15
|
+
* Strategies without a tracer field — or sessions that don't pass
|
|
16
|
+
* one — incur zero cost.
|
|
17
|
+
*
|
|
18
|
+
* Phase 1 captures `llm_request` only (the priority the playground
|
|
19
|
+
* needs to ship a prompt visualizer). `llm_response` shape is
|
|
20
|
+
* defined here so consumers can write against the full union from
|
|
21
|
+
* day one; emit-site wiring lands in Phase 2.
|
|
22
|
+
*/
|
|
23
|
+
import type { NormalizedMessage } from './chat.js';
|
|
24
|
+
/**
|
|
25
|
+
* Wire-level snapshot of a single LLM request as it leaves the
|
|
26
|
+
* strategy. Captured exactly once per ReAct iteration — N times per
|
|
27
|
+
* user prompt, where N >= 1 (final-answer turn) and grows by 1 per
|
|
28
|
+
* tool-using iteration.
|
|
29
|
+
*/
|
|
30
|
+
export interface LlmRequestTrace {
|
|
31
|
+
/** Stable per-iteration id, scoped to its session. The recommended
|
|
32
|
+
* format is `${turnId}#${iteration}`; the agent loop generates
|
|
33
|
+
* the value, hosts treat it as opaque. */
|
|
34
|
+
requestId: string;
|
|
35
|
+
/** The session-scoped turn id (matches `SessionEvent.turnId`). */
|
|
36
|
+
turnId: string;
|
|
37
|
+
/** 0-indexed ReAct iteration within this turn. */
|
|
38
|
+
iteration: number;
|
|
39
|
+
/** Wall-clock ms at the moment the request was about to dispatch. */
|
|
40
|
+
ts: number;
|
|
41
|
+
/** The system-prompt string the strategy received from
|
|
42
|
+
* `StrategyRunInput.systemPrompt`. Captured verbatim. */
|
|
43
|
+
systemPrompt: string;
|
|
44
|
+
/** The messages array exactly as the provider will see it. Includes
|
|
45
|
+
* the synthesized leading system message, the prior history, the
|
|
46
|
+
* current user prompt, and any assistant+tool entries the ReAct
|
|
47
|
+
* loop appended this turn. */
|
|
48
|
+
messages: NormalizedMessage[];
|
|
49
|
+
/** Tool declarations as filtered + shaped by the strategy. The
|
|
50
|
+
* `parameters` value is captured opaquely — providers normalize
|
|
51
|
+
* it (Gemini sanitizes; OpenRouter is permissive), so the trace
|
|
52
|
+
* shows the pre-provider canonical view. */
|
|
53
|
+
tools: ToolDeclarationView[];
|
|
54
|
+
/** Agent-loop-level model identity. The host enriches this with
|
|
55
|
+
* provider label / model label / temperature / reasoning-effort
|
|
56
|
+
* at consumption time — those values aren't visible to the
|
|
57
|
+
* strategy. */
|
|
58
|
+
llm: {
|
|
59
|
+
id: string;
|
|
60
|
+
supportsTools: boolean;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Tool-decl row as the agent loop produced it pre-provider. Mirrors
|
|
65
|
+
* the `toolDecls` shape strategy.ts builds when constructing the
|
|
66
|
+
* `ChatRequest`. Not coupled to the in-process `ToolHandler` type —
|
|
67
|
+
* the trace is a wire snapshot, not a live handle.
|
|
68
|
+
*/
|
|
69
|
+
export interface ToolDeclarationView {
|
|
70
|
+
name: string;
|
|
71
|
+
description: string;
|
|
72
|
+
parameters: unknown;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Response-side snapshot. Defined now so consumers can switch on
|
|
76
|
+
* `TraceEvent.kind` and handle the full union from the start. The
|
|
77
|
+
* emit-site in `strategy.ts` lands in Phase 2 — strategies are free
|
|
78
|
+
* to emit it earlier when the data is available.
|
|
79
|
+
*/
|
|
80
|
+
export interface LlmResponseTrace {
|
|
81
|
+
/** Same id as the matching `LlmRequestTrace.requestId`. */
|
|
82
|
+
requestId: string;
|
|
83
|
+
/** Wall-clock ms when the chat() iterator completed. */
|
|
84
|
+
ts: number;
|
|
85
|
+
/** Full assistant text emitted this iteration. */
|
|
86
|
+
text: string;
|
|
87
|
+
/** Hidden reasoning when the model surfaces it. Empty string for
|
|
88
|
+
* non-reasoning models. */
|
|
89
|
+
thinking: string;
|
|
90
|
+
/** Tool calls the model chose to emit this iteration. */
|
|
91
|
+
toolCalls: {
|
|
92
|
+
id: string;
|
|
93
|
+
name: string;
|
|
94
|
+
args: unknown;
|
|
95
|
+
signature?: string;
|
|
96
|
+
}[];
|
|
97
|
+
/** Provider-reported usage; absent on error / streaming-cancel /
|
|
98
|
+
* for providers that don't surface usage. */
|
|
99
|
+
usage?: {
|
|
100
|
+
promptTokens: number;
|
|
101
|
+
outputTokens: number;
|
|
102
|
+
cachedTokens?: number;
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
export type TraceEvent = {
|
|
106
|
+
kind: 'llm_request';
|
|
107
|
+
data: LlmRequestTrace;
|
|
108
|
+
} | {
|
|
109
|
+
kind: 'llm_response';
|
|
110
|
+
data: LlmResponseTrace;
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Pluggable trace sink. Hosts implement `emit()` to push events to a
|
|
114
|
+
* UI store, a NDJSON file, an eval harness, etc. The agent loop
|
|
115
|
+
* never inspects the implementation — it just hands off the event.
|
|
116
|
+
*
|
|
117
|
+
* Implementations MUST be synchronous and non-throwing. The agent
|
|
118
|
+
* loop intentionally doesn't `await` emit; surfacing a trace must
|
|
119
|
+
* never delay an LLM dispatch or fail it. If a host needs async
|
|
120
|
+
* work (network ship, etc.), it should queue internally.
|
|
121
|
+
*/
|
|
122
|
+
export interface Tracer {
|
|
123
|
+
emit(event: TraceEvent): void;
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=trace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace.d.ts","sourceRoot":"","sources":["../../src/types/trace.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAEnD;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B;;+CAE2C;IAC3C,SAAS,EAAE,MAAM,CAAC;IAClB,kEAAkE;IAClE,MAAM,EAAE,MAAM,CAAC;IACf,kDAAkD;IAClD,SAAS,EAAE,MAAM,CAAC;IAClB,qEAAqE;IACrE,EAAE,EAAE,MAAM,CAAC;IACX;8DAC0D;IAC1D,YAAY,EAAE,MAAM,CAAC;IACrB;;;mCAG+B;IAC/B,QAAQ,EAAE,iBAAiB,EAAE,CAAC;IAC9B;;;iDAG6C;IAC7C,KAAK,EAAE,mBAAmB,EAAE,CAAC;IAC7B;;;oBAGgB;IAChB,GAAG,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,OAAO,CAAA;KAAE,CAAC;CAC7C;AAED;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;CACrB;AAED;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B,2DAA2D;IAC3D,SAAS,EAAE,MAAM,CAAC;IAClB,wDAAwD;IACxD,EAAE,EAAE,MAAM,CAAC;IACX,kDAAkD;IAClD,IAAI,EAAE,MAAM,CAAC;IACb;gCAC4B;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,yDAAyD;IACzD,SAAS,EAAE;QACT,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,OAAO,CAAC;QACd,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,EAAE,CAAC;IACJ;kDAC8C;IAC9C,KAAK,CAAC,EAAE;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC/E;AAED,MAAM,MAAM,UAAU,GAClB;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,IAAI,EAAE,eAAe,CAAA;CAAE,GAC9C;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,IAAI,EAAE,gBAAgB,CAAA;CAAE,CAAC;AAErD;;;;;;;;;GASG;AACH,MAAM,WAAW,MAAM;IACrB,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;CAC/B"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent-loop request/response trace surface.
|
|
3
|
+
*
|
|
4
|
+
* Captures the exact shape of every LLM request the strategy
|
|
5
|
+
* dispatches — system prompt + messages + tool decls + model — at
|
|
6
|
+
* the layer the agent author thinks in (`@inbrowser/agent` types), not
|
|
7
|
+
* the provider-specific transform below it. A provider-level trace
|
|
8
|
+
* (Gemini's `GeminiBody`, OpenRouter's `messages[].content` parts)
|
|
9
|
+
* is a complementary concern that belongs to `@inbrowser/relay`;
|
|
10
|
+
* this surface is for "what did the model see, in agent terms."
|
|
11
|
+
*
|
|
12
|
+
* Emission is opt-in. A `Tracer` plugs into `AgentSessionConfig`
|
|
13
|
+
* (which threads it through `StrategyRunInput`); strategies that
|
|
14
|
+
* support tracing call `tracer.emit(...)` at well-defined moments.
|
|
15
|
+
* Strategies without a tracer field — or sessions that don't pass
|
|
16
|
+
* one — incur zero cost.
|
|
17
|
+
*
|
|
18
|
+
* Phase 1 captures `llm_request` only (the priority the playground
|
|
19
|
+
* needs to ship a prompt visualizer). `llm_response` shape is
|
|
20
|
+
* defined here so consumers can write against the full union from
|
|
21
|
+
* day one; emit-site wiring lands in Phase 2.
|
|
22
|
+
*/
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=trace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace.js","sourceRoot":"","sources":["../../src/types/trace.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `Workspace` — the user-authored half of the playground's state.
|
|
3
|
+
*
|
|
4
|
+
* Pure data. Immutable updates via the `WorkspaceTransitions`
|
|
5
|
+
* functions; no I/O, no React, no `localStorage`. Persistence is the
|
|
6
|
+
* host's job (Zustand in the React IDE, in-memory in the CLI).
|
|
7
|
+
*
|
|
8
|
+
* Distinct from `RuntimeState` (`./runtime.ts`), which holds what the
|
|
9
|
+
* agent's tools have produced — separate concerns, separate types.
|
|
10
|
+
*/
|
|
11
|
+
export interface Workspace {
|
|
12
|
+
/** Identifier of the active preset (e.g. "chess", "lobby", "owner"). */
|
|
13
|
+
presetId: string;
|
|
14
|
+
/** Firestore rules source the user / agent is currently editing. */
|
|
15
|
+
rules: string;
|
|
16
|
+
/** JavaScript code source for the agent's `runCode` tool. */
|
|
17
|
+
code: string;
|
|
18
|
+
/** TSX source for the App-panel rendered preview. */
|
|
19
|
+
appSource: string;
|
|
20
|
+
/** Stitch design context — orthogonal to rules/code/app, but session-scoped. */
|
|
21
|
+
stitch: StitchContext;
|
|
22
|
+
}
|
|
23
|
+
export interface StitchContext {
|
|
24
|
+
projectId: string | null;
|
|
25
|
+
latestScreenUrl: string | null;
|
|
26
|
+
brief: string | null;
|
|
27
|
+
}
|
|
28
|
+
export declare const EMPTY_WORKSPACE: Workspace;
|
|
29
|
+
//# sourceMappingURL=workspace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspace.d.ts","sourceRoot":"","sources":["../../src/types/workspace.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,WAAW,SAAS;IACxB,wEAAwE;IACxE,QAAQ,EAAE,MAAM,CAAC;IACjB,oEAAoE;IACpE,KAAK,EAAE,MAAM,CAAC;IACd,6DAA6D;IAC7D,IAAI,EAAE,MAAM,CAAC;IACb,qDAAqD;IACrD,SAAS,EAAE,MAAM,CAAC;IAClB,gFAAgF;IAChF,MAAM,EAAE,aAAa,CAAC;CACvB;AAED,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAED,eAAO,MAAM,eAAe,EAAE,SAMf,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `Workspace` — the user-authored half of the playground's state.
|
|
3
|
+
*
|
|
4
|
+
* Pure data. Immutable updates via the `WorkspaceTransitions`
|
|
5
|
+
* functions; no I/O, no React, no `localStorage`. Persistence is the
|
|
6
|
+
* host's job (Zustand in the React IDE, in-memory in the CLI).
|
|
7
|
+
*
|
|
8
|
+
* Distinct from `RuntimeState` (`./runtime.ts`), which holds what the
|
|
9
|
+
* agent's tools have produced — separate concerns, separate types.
|
|
10
|
+
*/
|
|
11
|
+
export const EMPTY_WORKSPACE = Object.freeze({
|
|
12
|
+
presetId: '',
|
|
13
|
+
rules: '',
|
|
14
|
+
code: '',
|
|
15
|
+
appSource: '',
|
|
16
|
+
stitch: Object.freeze({ projectId: null, latestScreenUrl: null, brief: null }),
|
|
17
|
+
});
|
|
18
|
+
//# sourceMappingURL=workspace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspace.js","sourceRoot":"","sources":["../../src/types/workspace.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAqBH,MAAM,CAAC,MAAM,eAAe,GAAc,MAAM,CAAC,MAAM,CAAC;IACtD,QAAQ,EAAE,EAAE;IACZ,KAAK,EAAE,EAAE;IACT,IAAI,EAAE,EAAE;IACR,SAAS,EAAE,EAAE;IACb,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,eAAe,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAkB;CAChG,CAAc,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,17 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inbrowser/agent",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"main": "index.js",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Agent runtime + CLI. Library exports AgentSession, AgentStrategy, ToolRegistry, LlmClient, MetricsCollector, SandboxObserver. Ships an `agent` binary with NDJSON output, --json stdin, --dry-run, schema introspection, and inverse-mode MCP serve. Domain-agnostic — hosts wire their own AgentDefinitions.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./cli": {
|
|
14
|
+
"types": "./dist/cli/index.d.ts",
|
|
15
|
+
"import": "./dist/cli/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./node": {
|
|
18
|
+
"types": "./dist/node.d.ts",
|
|
19
|
+
"import": "./dist/node.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"bin": {
|
|
23
|
+
"agent": "./bin/agent.ts"
|
|
24
|
+
},
|
|
25
|
+
"files": ["dist", "bin", "skills", "AGENTS.md", "README.md"],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsc",
|
|
28
|
+
"test": "bun test",
|
|
29
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
33
|
+
"@opentui/core": "^0.1.0",
|
|
34
|
+
"@opentui/react": "^0.1.0",
|
|
35
|
+
"react": "^19.0.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/bun": "latest",
|
|
39
|
+
"@types/react": "^19.0.0",
|
|
40
|
+
"typescript": "^5.7.0"
|
|
41
|
+
},
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "git+https://github.com/davideast/inbrowser-agent.git",
|
|
45
|
+
"directory": "packages/agent"
|
|
46
|
+
},
|
|
47
|
+
"license": "MIT"
|
|
17
48
|
}
|