@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,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `MutationEvent` — the canonical record a mutating tool emits to the
|
|
3
|
+
* project event log. Three phases:
|
|
4
|
+
*
|
|
5
|
+
* - `plan` — emitted before the tool actually runs. Records intent +
|
|
6
|
+
* captured "before" snapshot. Always present.
|
|
7
|
+
* - `commit` — emitted after the tool returns successfully. Records
|
|
8
|
+
* "after" snapshot + the `reverseOp` (when one exists) so `agent
|
|
9
|
+
* undo` can roll it back.
|
|
10
|
+
* - `rollback` — emitted when execution failed mid-flight, or when
|
|
11
|
+
* `agent undo` reverses a previously-committed event. Helps the
|
|
12
|
+
* auditor distinguish "started but never finished" from "finished
|
|
13
|
+
* and later undone."
|
|
14
|
+
*
|
|
15
|
+
* The log is **append-only NDJSON** at
|
|
16
|
+
* `~/.pyric/projects/<projectId>/events.ndjson`. The whole point is
|
|
17
|
+
* that the file is replayable + diffable — never overwrite, never
|
|
18
|
+
* mutate previous lines.
|
|
19
|
+
*
|
|
20
|
+
* See `plans/specialized-firebase-agents.md` §7 for the design rationale.
|
|
21
|
+
*/
|
|
22
|
+
export type MutationPhase = 'plan' | 'commit' | 'rollback';
|
|
23
|
+
export type TargetKind = 'doc' | 'collection' | 'rules' | 'index' | 'service' | 'bucket' | 'hosting' | 'functions' | 'workspace' | 'other';
|
|
24
|
+
export interface MutationTarget {
|
|
25
|
+
kind: TargetKind;
|
|
26
|
+
/**
|
|
27
|
+
* Stable, fully-qualified identifier for the target. Examples:
|
|
28
|
+
* - `users/alice`
|
|
29
|
+
* - `projects/my-app/rulesets/active`
|
|
30
|
+
* - `firebasestorage.googleapis.com`
|
|
31
|
+
* - `my-app.firebasestorage.app`
|
|
32
|
+
* - `workspace.rules`
|
|
33
|
+
*/
|
|
34
|
+
path: string;
|
|
35
|
+
/** Optional friendly label. */
|
|
36
|
+
label?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface ReverseOp {
|
|
39
|
+
/** Tool name to invoke to reverse the committed mutation. */
|
|
40
|
+
tool: string;
|
|
41
|
+
/** Arguments to pass. The tool MUST be registered in the same
|
|
42
|
+
* ToolRegistry the caller used; otherwise undo cannot resolve it. */
|
|
43
|
+
args: unknown;
|
|
44
|
+
/** Free-form human-readable description of the reverse action. */
|
|
45
|
+
description?: string;
|
|
46
|
+
}
|
|
47
|
+
export interface MutationEvent {
|
|
48
|
+
/** Sortable, opaque event id (timestamp-prefixed). */
|
|
49
|
+
id: string;
|
|
50
|
+
/** ISO-8601 timestamp the event was emitted at. */
|
|
51
|
+
ts: string;
|
|
52
|
+
/** Agent that emitted it. `'host'` for direct CLI / library use. */
|
|
53
|
+
agent: string;
|
|
54
|
+
/** Session id from `AgentSession`. */
|
|
55
|
+
sessionId: string;
|
|
56
|
+
/** Tool that did (or planned) the mutation. */
|
|
57
|
+
tool: string;
|
|
58
|
+
/** Args the tool was invoked with. Stored verbatim so the event can
|
|
59
|
+
* be **replayed** against a different `ToolDispatch` (e.g. a
|
|
60
|
+
* production registry pointed at live Firestore). Optional for
|
|
61
|
+
* back-compat with legacy event files written before this field
|
|
62
|
+
* existed; legacy events can't be replayed without it. */
|
|
63
|
+
args?: unknown;
|
|
64
|
+
/** Lifecycle phase. */
|
|
65
|
+
phase: MutationPhase;
|
|
66
|
+
/** What was (or would be) mutated. */
|
|
67
|
+
target: MutationTarget;
|
|
68
|
+
/** Captured pre-image. Absent when the API doesn't expose one or the
|
|
69
|
+
* caller opted out. */
|
|
70
|
+
before?: unknown;
|
|
71
|
+
/** Captured post-image. Always present for `commit` phase. */
|
|
72
|
+
after?: unknown;
|
|
73
|
+
/** Whether the API supports reversing this mutation. Hard-false for
|
|
74
|
+
* irreversible ops (service enablement, hosting release rollbacks
|
|
75
|
+
* past retention window, etc) — `agent undo` refuses with the
|
|
76
|
+
* message in `irreversibleReason`. */
|
|
77
|
+
reversible: boolean;
|
|
78
|
+
/** When `reversible: false`, why. Surfaced to the user. */
|
|
79
|
+
irreversibleReason?: string;
|
|
80
|
+
/** When `reversible: true`, the tool+args to invoke to roll back.
|
|
81
|
+
* Absent during `plan` phase (intent, not commitment); always
|
|
82
|
+
* present on `commit` phase for reversible events. */
|
|
83
|
+
reverseOp?: ReverseOp;
|
|
84
|
+
/** Free-form metadata the host can stash on the event. The event log
|
|
85
|
+
* treats this as opaque — readers can use it to correlate with their
|
|
86
|
+
* own systems (Linear ticket id, deploy build number, etc). */
|
|
87
|
+
metadata?: Record<string, unknown>;
|
|
88
|
+
}
|
|
89
|
+
export interface MutationEventFilter {
|
|
90
|
+
/** Restrict to a single session. */
|
|
91
|
+
sessionId?: string;
|
|
92
|
+
/** Restrict to a single tool name. */
|
|
93
|
+
tool?: string;
|
|
94
|
+
/** Restrict to a single agent. */
|
|
95
|
+
agent?: string;
|
|
96
|
+
/** ISO-8601 lower bound (inclusive). */
|
|
97
|
+
since?: string;
|
|
98
|
+
/** ISO-8601 upper bound (exclusive). */
|
|
99
|
+
until?: string;
|
|
100
|
+
/** Restrict to a single phase. */
|
|
101
|
+
phase?: MutationPhase;
|
|
102
|
+
/** Restrict to a single target kind. */
|
|
103
|
+
targetKind?: TargetKind;
|
|
104
|
+
/** Restrict by event id (for undo). */
|
|
105
|
+
id?: string;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Identifier used in event records when the host didn't name an agent.
|
|
109
|
+
* Lives in the types module (zero side effects) so it's safe on the
|
|
110
|
+
* universal `@inbrowser/agent` entry — the value lives in `events/log.ts`
|
|
111
|
+
* too, but that file imports `node:fs` / `node:os` and can't ship to
|
|
112
|
+
* the browser.
|
|
113
|
+
*/
|
|
114
|
+
export declare const HOST_AGENT_ID = "host";
|
|
115
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/types/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,QAAQ,GAAG,UAAU,CAAC;AAE3D,MAAM,MAAM,UAAU,GAClB,KAAK,GACL,YAAY,GACZ,OAAO,GACP,OAAO,GACP,SAAS,GACT,QAAQ,GACR,SAAS,GACT,WAAW,GACX,WAAW,GACX,OAAO,CAAC;AAEZ,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,UAAU,CAAC;IACjB;;;;;;;OAOG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,SAAS;IACxB,6DAA6D;IAC7D,IAAI,EAAE,MAAM,CAAC;IACb;0EACsE;IACtE,IAAI,EAAE,OAAO,CAAC;IACd,kEAAkE;IAClE,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,aAAa;IAC5B,sDAAsD;IACtD,EAAE,EAAE,MAAM,CAAC;IACX,mDAAmD;IACnD,EAAE,EAAE,MAAM,CAAC;IACX,oEAAoE;IACpE,KAAK,EAAE,MAAM,CAAC;IACd,sCAAsC;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,+CAA+C;IAC/C,IAAI,EAAE,MAAM,CAAC;IACb;;;;+DAI2D;IAC3D,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,uBAAuB;IACvB,KAAK,EAAE,aAAa,CAAC;IACrB,sCAAsC;IACtC,MAAM,EAAE,cAAc,CAAC;IACvB;4BACwB;IACxB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,8DAA8D;IAC9D,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;;2CAGuC;IACvC,UAAU,EAAE,OAAO,CAAC;IACpB,2DAA2D;IAC3D,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B;;2DAEuD;IACvD,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB;;oEAEgE;IAChE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,mBAAmB;IAClC,oCAAoC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sCAAsC;IACtC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,kCAAkC;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wCAAwC;IACxC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wCAAwC;IACxC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kCAAkC;IAClC,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,wCAAwC;IACxC,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,uCAAuC;IACvC,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,SAAS,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `MutationEvent` — the canonical record a mutating tool emits to the
|
|
3
|
+
* project event log. Three phases:
|
|
4
|
+
*
|
|
5
|
+
* - `plan` — emitted before the tool actually runs. Records intent +
|
|
6
|
+
* captured "before" snapshot. Always present.
|
|
7
|
+
* - `commit` — emitted after the tool returns successfully. Records
|
|
8
|
+
* "after" snapshot + the `reverseOp` (when one exists) so `agent
|
|
9
|
+
* undo` can roll it back.
|
|
10
|
+
* - `rollback` — emitted when execution failed mid-flight, or when
|
|
11
|
+
* `agent undo` reverses a previously-committed event. Helps the
|
|
12
|
+
* auditor distinguish "started but never finished" from "finished
|
|
13
|
+
* and later undone."
|
|
14
|
+
*
|
|
15
|
+
* The log is **append-only NDJSON** at
|
|
16
|
+
* `~/.pyric/projects/<projectId>/events.ndjson`. The whole point is
|
|
17
|
+
* that the file is replayable + diffable — never overwrite, never
|
|
18
|
+
* mutate previous lines.
|
|
19
|
+
*
|
|
20
|
+
* See `plans/specialized-firebase-agents.md` §7 for the design rationale.
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* Identifier used in event records when the host didn't name an agent.
|
|
24
|
+
* Lives in the types module (zero side effects) so it's safe on the
|
|
25
|
+
* universal `@inbrowser/agent` entry — the value lives in `events/log.ts`
|
|
26
|
+
* too, but that file imports `node:fs` / `node:os` and can't ship to
|
|
27
|
+
* the browser.
|
|
28
|
+
*/
|
|
29
|
+
export const HOST_AGENT_ID = 'host';
|
|
30
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/types/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAuGH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `LlmClient` — narrow provider interface.
|
|
3
|
+
*
|
|
4
|
+
* Implementations live in adapter packages (one per provider). The
|
|
5
|
+
* client knows about model calls and streamed events; it knows
|
|
6
|
+
* **nothing** about BYOK forms, localStorage, model pickers, or
|
|
7
|
+
* pricing tables. Receives its config explicitly at construction
|
|
8
|
+
* time so concurrent sessions can use different keys/models against
|
|
9
|
+
* the same provider without contention.
|
|
10
|
+
*/
|
|
11
|
+
import type { NormalizedMessage } from './chat.js';
|
|
12
|
+
import type { TurnDetails, TurnMetrics } from './chat.js';
|
|
13
|
+
export interface LlmConfig {
|
|
14
|
+
apiKey?: string;
|
|
15
|
+
model: string;
|
|
16
|
+
/** Base URL override (e.g. for OpenAI-compatible proxies). */
|
|
17
|
+
baseUrl?: string;
|
|
18
|
+
/** Reasoning effort for providers that support it (OpenRouter). */
|
|
19
|
+
reasoningEffort?: 'low' | 'medium' | 'high';
|
|
20
|
+
/** Caller-side flag — affects metrics' `isByok`. */
|
|
21
|
+
isByok?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface ChatRequest {
|
|
24
|
+
messages: NormalizedMessage[];
|
|
25
|
+
/** Tool declarations the model may invoke. Empty array → plain chat. */
|
|
26
|
+
tools: ToolDeclaration[];
|
|
27
|
+
/** Lighter than `tools.length === 0`; lets adapters skip tool-mode encoding entirely. */
|
|
28
|
+
toolUseEnabled: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface ToolDeclaration {
|
|
31
|
+
name: string;
|
|
32
|
+
description: string;
|
|
33
|
+
/** JSON Schema describing the tool's arguments. */
|
|
34
|
+
parameters: JsonSchema;
|
|
35
|
+
}
|
|
36
|
+
export type JsonSchema = {
|
|
37
|
+
type?: string;
|
|
38
|
+
description?: string;
|
|
39
|
+
properties?: Record<string, JsonSchema>;
|
|
40
|
+
required?: string[];
|
|
41
|
+
items?: JsonSchema | JsonSchema[];
|
|
42
|
+
enum?: unknown[];
|
|
43
|
+
[key: string]: unknown;
|
|
44
|
+
};
|
|
45
|
+
export interface LlmClient {
|
|
46
|
+
readonly id: string;
|
|
47
|
+
readonly supportsTools: boolean;
|
|
48
|
+
chat(req: ChatRequest, signal: AbortSignal): AsyncIterable<ChatEvent>;
|
|
49
|
+
}
|
|
50
|
+
export type ChatEvent = {
|
|
51
|
+
kind: 'text';
|
|
52
|
+
chunk: string;
|
|
53
|
+
} | {
|
|
54
|
+
kind: 'thinking';
|
|
55
|
+
chunk: string;
|
|
56
|
+
} | {
|
|
57
|
+
kind: 'tool_call';
|
|
58
|
+
id: string;
|
|
59
|
+
name: string;
|
|
60
|
+
args: unknown;
|
|
61
|
+
signature?: string;
|
|
62
|
+
} | {
|
|
63
|
+
kind: 'turn_complete';
|
|
64
|
+
usage: RawUsage;
|
|
65
|
+
details: TurnDetails;
|
|
66
|
+
} | {
|
|
67
|
+
kind: 'error';
|
|
68
|
+
message: string;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Raw token usage as the provider reports it — interpreted by
|
|
72
|
+
* `MetricsCollector` to derive `TurnMetrics` (cost, cached
|
|
73
|
+
* fraction, reasoning fraction). Different providers report
|
|
74
|
+
* different shapes; the collector handles them.
|
|
75
|
+
*/
|
|
76
|
+
export interface RawUsage {
|
|
77
|
+
promptTokens: number;
|
|
78
|
+
completionTokens: number;
|
|
79
|
+
cachedTokens?: number;
|
|
80
|
+
reasoningTokens?: number;
|
|
81
|
+
/** Provider-supplied cost (OpenRouter), when available — bypasses pricing tables. */
|
|
82
|
+
costUsd?: number;
|
|
83
|
+
}
|
|
84
|
+
export interface LlmClientFactory {
|
|
85
|
+
create(config: LlmConfig): LlmClient;
|
|
86
|
+
}
|
|
87
|
+
/** Re-export so consumers don't have to dig into `./chat.js`. */
|
|
88
|
+
export type { TurnDetails, TurnMetrics };
|
|
89
|
+
//# sourceMappingURL=llm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm.d.ts","sourceRoot":"","sources":["../../src/types/llm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE1D,MAAM,WAAW,SAAS;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,8DAA8D;IAC9D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mEAAmE;IACnE,eAAe,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;IAC5C,oDAAoD;IACpD,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,iBAAiB,EAAE,CAAC;IAC9B,wEAAwE;IACxE,KAAK,EAAE,eAAe,EAAE,CAAC;IACzB,yFAAyF;IACzF,cAAc,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,mDAAmD;IACnD,UAAU,EAAE,UAAU,CAAC;CACxB;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACxC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,KAAK,CAAC,EAAE,UAAU,GAAG,UAAU,EAAE,CAAC;IAClC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AAEF,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;IAChC,IAAI,CAAC,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;CACvE;AAED,MAAM,MAAM,SAAS,GACjB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC/B;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACnC;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GAClF;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,KAAK,EAAE,QAAQ,CAAC;IAAC,OAAO,EAAE,WAAW,CAAA;CAAE,GAChE;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvC;;;;;GAKG;AACH,MAAM,WAAW,QAAQ;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,qFAAqF;IACrF,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,SAAS,CAAC;CACtC;AAED,iEAAiE;AACjE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `LlmClient` — narrow provider interface.
|
|
3
|
+
*
|
|
4
|
+
* Implementations live in adapter packages (one per provider). The
|
|
5
|
+
* client knows about model calls and streamed events; it knows
|
|
6
|
+
* **nothing** about BYOK forms, localStorage, model pickers, or
|
|
7
|
+
* pricing tables. Receives its config explicitly at construction
|
|
8
|
+
* time so concurrent sessions can use different keys/models against
|
|
9
|
+
* the same provider without contention.
|
|
10
|
+
*/
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=llm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm.js","sourceRoot":"","sources":["../../src/types/llm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `MetricsCollector` — translates raw provider usage into typed
|
|
3
|
+
* turn metrics + session totals.
|
|
4
|
+
*
|
|
5
|
+
* Pure functions. Receives provider id + raw usage and returns a
|
|
6
|
+
* cost breakdown. Pricing tables live here, not inside provider
|
|
7
|
+
* implementations.
|
|
8
|
+
*/
|
|
9
|
+
import type { RawUsage, TurnMetrics } from './llm.js';
|
|
10
|
+
export interface MetricsCollector {
|
|
11
|
+
/** Stamp a turn-completion event. Returns the typed metrics shape. */
|
|
12
|
+
recordTurn(input: RecordTurnInput): TurnMetrics;
|
|
13
|
+
/** Aggregate across all recorded turns in this collector's lifetime. */
|
|
14
|
+
totals(): SessionTotals;
|
|
15
|
+
/** Reset the collector — call on session reset / clear. */
|
|
16
|
+
reset(): void;
|
|
17
|
+
}
|
|
18
|
+
export interface RecordTurnInput {
|
|
19
|
+
llmId: string;
|
|
20
|
+
rawUsage: RawUsage;
|
|
21
|
+
model: string;
|
|
22
|
+
durationMs: number;
|
|
23
|
+
isByok?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface SessionTotals {
|
|
26
|
+
tokensTotal: number;
|
|
27
|
+
tokensIn: number;
|
|
28
|
+
tokensOut: number;
|
|
29
|
+
tokensCached: number;
|
|
30
|
+
tokensReasoning: number;
|
|
31
|
+
costUsdTotal: number;
|
|
32
|
+
turnCount: number;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=metrics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../src/types/metrics.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEtD,MAAM,WAAW,gBAAgB;IAC/B,sEAAsE;IACtE,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,WAAW,CAAC;IAChD,wEAAwE;IACxE,MAAM,IAAI,aAAa,CAAC;IACxB,2DAA2D;IAC3D,KAAK,IAAI,IAAI,CAAC;CACf;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `MetricsCollector` — translates raw provider usage into typed
|
|
3
|
+
* turn metrics + session totals.
|
|
4
|
+
*
|
|
5
|
+
* Pure functions. Receives provider id + raw usage and returns a
|
|
6
|
+
* cost breakdown. Pricing tables live here, not inside provider
|
|
7
|
+
* implementations.
|
|
8
|
+
*/
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=metrics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../src/types/metrics.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `SandboxObserver` — centralized error sink for simulated services.
|
|
3
|
+
*
|
|
4
|
+
* Every site inside `@pyric/sandbox`, `@pyric/admin`,
|
|
5
|
+
* `@pyric/firestore` (sandbox target), `@pyric/storage` (sandbox
|
|
6
|
+
* target) that throws / errors / surfaces denials calls
|
|
7
|
+
* `observer.onEvent({...})` *before* the throw or callback. The
|
|
8
|
+
* structured error returns the SDK already provides are unchanged.
|
|
9
|
+
*
|
|
10
|
+
* Append-only from the sandbox's perspective — emitting an event
|
|
11
|
+
* must never throw, never block, never affect the operation's
|
|
12
|
+
* return value. Pure side-channel.
|
|
13
|
+
*
|
|
14
|
+
* NOTE: this is the agent-layer *host-observer* event — a coarse
|
|
15
|
+
* error-sink shape. It is distinct from `@pyric/sandbox`'s
|
|
16
|
+
* `SandboxEvent` (the substrate-level discriminated union of every
|
|
17
|
+
* evaluated op). The two were briefly name-colliding; this one is
|
|
18
|
+
* `ObserverEvent` to keep them unambiguous. See issue #307.
|
|
19
|
+
*/
|
|
20
|
+
export interface ObserverEvent {
|
|
21
|
+
kind: 'denial' | 'snapshot_error' | 'transaction_conflict' | 'runtime_error' | 'lint_warning';
|
|
22
|
+
timestamp: number;
|
|
23
|
+
/** Stable identifier for the originating operation. */
|
|
24
|
+
operationId?: string;
|
|
25
|
+
/** Path the operation touched. */
|
|
26
|
+
path?: string;
|
|
27
|
+
/** Identity context at the time of the event. */
|
|
28
|
+
auth?: {
|
|
29
|
+
uid: string | null;
|
|
30
|
+
};
|
|
31
|
+
/** Structured detail — denial reason, error code, message. */
|
|
32
|
+
detail: unknown;
|
|
33
|
+
}
|
|
34
|
+
export interface SandboxObserver {
|
|
35
|
+
onEvent(event: ObserverEvent): void;
|
|
36
|
+
}
|
|
37
|
+
/** Compose multiple observers into one. */
|
|
38
|
+
export declare function combineObservers(...observers: SandboxObserver[]): SandboxObserver;
|
|
39
|
+
/** No-op observer — the default when no host subscribes. */
|
|
40
|
+
export declare const noopObserver: SandboxObserver;
|
|
41
|
+
//# sourceMappingURL=observer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observer.d.ts","sourceRoot":"","sources":["../../src/types/observer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,QAAQ,GAAG,gBAAgB,GAAG,sBAAsB,GAAG,eAAe,GAAG,cAAc,CAAC;IAC9F,SAAS,EAAE,MAAM,CAAC;IAClB,uDAAuD;IACvD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kCAAkC;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,iDAAiD;IACjD,IAAI,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;IAC9B,8DAA8D;IAC9D,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI,CAAC;CACrC;AAED,2CAA2C;AAC3C,wBAAgB,gBAAgB,CAAC,GAAG,SAAS,EAAE,eAAe,EAAE,GAAG,eAAe,CAYjF;AAED,4DAA4D;AAC5D,eAAO,MAAM,YAAY,EAAE,eAIzB,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `SandboxObserver` — centralized error sink for simulated services.
|
|
3
|
+
*
|
|
4
|
+
* Every site inside `@pyric/sandbox`, `@pyric/admin`,
|
|
5
|
+
* `@pyric/firestore` (sandbox target), `@pyric/storage` (sandbox
|
|
6
|
+
* target) that throws / errors / surfaces denials calls
|
|
7
|
+
* `observer.onEvent({...})` *before* the throw or callback. The
|
|
8
|
+
* structured error returns the SDK already provides are unchanged.
|
|
9
|
+
*
|
|
10
|
+
* Append-only from the sandbox's perspective — emitting an event
|
|
11
|
+
* must never throw, never block, never affect the operation's
|
|
12
|
+
* return value. Pure side-channel.
|
|
13
|
+
*
|
|
14
|
+
* NOTE: this is the agent-layer *host-observer* event — a coarse
|
|
15
|
+
* error-sink shape. It is distinct from `@pyric/sandbox`'s
|
|
16
|
+
* `SandboxEvent` (the substrate-level discriminated union of every
|
|
17
|
+
* evaluated op). The two were briefly name-colliding; this one is
|
|
18
|
+
* `ObserverEvent` to keep them unambiguous. See issue #307.
|
|
19
|
+
*/
|
|
20
|
+
/** Compose multiple observers into one. */
|
|
21
|
+
export function combineObservers(...observers) {
|
|
22
|
+
return {
|
|
23
|
+
onEvent: (event) => {
|
|
24
|
+
for (const o of observers) {
|
|
25
|
+
try {
|
|
26
|
+
o.onEvent(event);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
// Side-channel; never let one observer's bug crash another.
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** No-op observer — the default when no host subscribes. */
|
|
36
|
+
export const noopObserver = Object.freeze({
|
|
37
|
+
onEvent: () => {
|
|
38
|
+
/* intentionally empty */
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
//# sourceMappingURL=observer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observer.js","sourceRoot":"","sources":["../../src/types/observer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAmBH,2CAA2C;AAC3C,MAAM,UAAU,gBAAgB,CAAC,GAAG,SAA4B;IAC9D,OAAO;QACL,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;YACjB,KAAK,MAAM,CAAC,IAAI,SAAS,EAAE,CAAC;gBAC1B,IAAI,CAAC;oBACH,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;gBACnB,CAAC;gBAAC,MAAM,CAAC;oBACP,4DAA4D;gBAC9D,CAAC;YACH,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAED,4DAA4D;AAC5D,MAAM,CAAC,MAAM,YAAY,GAAoB,MAAM,CAAC,MAAM,CAAC;IACzD,OAAO,EAAE,GAAG,EAAE;QACZ,yBAAyB;IAC3B,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ProjectContext` — credential bundle Firebase-aware agents (rules
|
|
3
|
+
* audits, scripted deploys, hosted-app tooling) need to talk to a
|
|
4
|
+
* live project. The agent runtime stays Firebase-agnostic at the
|
|
5
|
+
* type level: `getFirestore()` is typed as `unknown` so the agent
|
|
6
|
+
* package has no `firebase-admin` dependency. Host packages that
|
|
7
|
+
* supply a ProjectContext narrow the return type at the call site
|
|
8
|
+
* via a cast (`ctx.getFirestore() as Firestore`).
|
|
9
|
+
*/
|
|
10
|
+
export interface ProjectContext {
|
|
11
|
+
readonly projectId: string;
|
|
12
|
+
resolveToken(): Promise<string>;
|
|
13
|
+
/** Returns the host's `firebase-admin/firestore` Firestore (or
|
|
14
|
+
* equivalent). Typed `unknown` to keep agent runtime free of a
|
|
15
|
+
* firebase-admin dep; callers cast at the use site. */
|
|
16
|
+
getFirestore(): unknown;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=project-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project-context.d.ts","sourceRoot":"","sources":["../../src/types/project-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAChC;;4DAEwD;IACxD,YAAY,IAAI,OAAO,CAAC;CACzB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ProjectContext` — credential bundle Firebase-aware agents (rules
|
|
3
|
+
* audits, scripted deploys, hosted-app tooling) need to talk to a
|
|
4
|
+
* live project. The agent runtime stays Firebase-agnostic at the
|
|
5
|
+
* type level: `getFirestore()` is typed as `unknown` so the agent
|
|
6
|
+
* package has no `firebase-admin` dependency. Host packages that
|
|
7
|
+
* supply a ProjectContext narrow the return type at the call site
|
|
8
|
+
* via a cast (`ctx.getFirestore() as Firestore`).
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=project-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project-context.js","sourceRoot":"","sources":["../../src/types/project-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `RuntimeState` — what the agent's tools have produced this session.
|
|
3
|
+
*
|
|
4
|
+
* Per-session. Owned by `AgentSession`, mutated by tool handlers via
|
|
5
|
+
* the patch returned from `ToolResult.runtimePatch`. The host reads
|
|
6
|
+
* this through `runtime_changed` session events; it does not write
|
|
7
|
+
* directly.
|
|
8
|
+
*
|
|
9
|
+
* Ephemeral by design — not persisted across reloads. The user's
|
|
10
|
+
* authored content lives in `Workspace`; this is the volatile
|
|
11
|
+
* runtime view.
|
|
12
|
+
*/
|
|
13
|
+
export interface RuntimeState {
|
|
14
|
+
terminal: TerminalSection[];
|
|
15
|
+
runSummary: RunSummary | null;
|
|
16
|
+
deploy: DeployState | null;
|
|
17
|
+
parseError: ParseError | null;
|
|
18
|
+
uiErrors: UiError[];
|
|
19
|
+
/** Bumped on reseed / preset switch / sandbox reset; consumers watch to remount. */
|
|
20
|
+
sandboxVersion: number;
|
|
21
|
+
}
|
|
22
|
+
export interface TerminalSection {
|
|
23
|
+
id: string;
|
|
24
|
+
kind: 'run' | 'deploy' | 'system';
|
|
25
|
+
title: string;
|
|
26
|
+
timestamp: number;
|
|
27
|
+
entries: TerminalEntry[];
|
|
28
|
+
}
|
|
29
|
+
export interface TerminalEntry {
|
|
30
|
+
level: 'info' | 'warn' | 'error' | 'denial';
|
|
31
|
+
message: string;
|
|
32
|
+
path?: string;
|
|
33
|
+
detail?: unknown;
|
|
34
|
+
}
|
|
35
|
+
export interface RunSummary {
|
|
36
|
+
ok: boolean;
|
|
37
|
+
durationMs: number;
|
|
38
|
+
docsTouched: number;
|
|
39
|
+
errors: number;
|
|
40
|
+
message?: string;
|
|
41
|
+
}
|
|
42
|
+
export interface DeployState {
|
|
43
|
+
ok: boolean;
|
|
44
|
+
messages: DeployMessage[];
|
|
45
|
+
timestamp: number;
|
|
46
|
+
}
|
|
47
|
+
export interface DeployMessage {
|
|
48
|
+
severity: 'info' | 'warn' | 'error';
|
|
49
|
+
text: string;
|
|
50
|
+
line?: number;
|
|
51
|
+
column?: number;
|
|
52
|
+
}
|
|
53
|
+
export interface ParseError {
|
|
54
|
+
message: string;
|
|
55
|
+
line: number;
|
|
56
|
+
column: number;
|
|
57
|
+
expected?: string;
|
|
58
|
+
}
|
|
59
|
+
export interface UiError {
|
|
60
|
+
source: 'compile' | 'runtime' | 'render';
|
|
61
|
+
message: string;
|
|
62
|
+
/** Filled when the error came from rule denial — request/resource context. */
|
|
63
|
+
denialContext?: Record<string, unknown>;
|
|
64
|
+
/** Compile errors carry source location. */
|
|
65
|
+
line?: number;
|
|
66
|
+
column?: number;
|
|
67
|
+
/** Runtime errors carry an error code (e.g. `permission-denied`). */
|
|
68
|
+
code?: string;
|
|
69
|
+
}
|
|
70
|
+
export declare const EMPTY_RUNTIME: RuntimeState;
|
|
71
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/types/runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC5B,UAAU,EAAE,UAAU,GAAG,IAAI,CAAC;IAC9B,MAAM,EAAE,WAAW,GAAG,IAAI,CAAC;IAC3B,UAAU,EAAE,UAAU,GAAG,IAAI,CAAC;IAC9B,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,oFAAoF;IACpF,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,KAAK,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,aAAa,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;IAC5C,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,OAAO,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,OAAO,CAAC;IACZ,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,8EAA8E;IAC9E,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,4CAA4C;IAC5C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qEAAqE;IACrE,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,eAAO,MAAM,aAAa,EAAE,YAOV,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `RuntimeState` — what the agent's tools have produced this session.
|
|
3
|
+
*
|
|
4
|
+
* Per-session. Owned by `AgentSession`, mutated by tool handlers via
|
|
5
|
+
* the patch returned from `ToolResult.runtimePatch`. The host reads
|
|
6
|
+
* this through `runtime_changed` session events; it does not write
|
|
7
|
+
* directly.
|
|
8
|
+
*
|
|
9
|
+
* Ephemeral by design — not persisted across reloads. The user's
|
|
10
|
+
* authored content lives in `Workspace`; this is the volatile
|
|
11
|
+
* runtime view.
|
|
12
|
+
*/
|
|
13
|
+
export const EMPTY_RUNTIME = Object.freeze({
|
|
14
|
+
terminal: Object.freeze([]),
|
|
15
|
+
runSummary: null,
|
|
16
|
+
deploy: null,
|
|
17
|
+
parseError: null,
|
|
18
|
+
uiErrors: Object.freeze([]),
|
|
19
|
+
sandboxVersion: 0,
|
|
20
|
+
});
|
|
21
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/types/runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAmEH,MAAM,CAAC,MAAM,aAAa,GAAiB,MAAM,CAAC,MAAM,CAAC;IACvD,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,EAAuB,CAAiC;IAChF,UAAU,EAAE,IAAI;IAChB,MAAM,EAAE,IAAI;IACZ,UAAU,EAAE,IAAI;IAChB,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,EAAe,CAAyB;IAChE,cAAc,EAAE,CAAC;CAClB,CAAiB,CAAC"}
|
|
@@ -0,0 +1,103 @@
|
|
|
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
|
+
import type { ChatMessage, TurnDetails, TurnMetrics } from './chat.js';
|
|
11
|
+
import type { LlmClient } from './llm.js';
|
|
12
|
+
import type { MetricsCollector } from './metrics.js';
|
|
13
|
+
import type { RuntimeState } from './runtime.js';
|
|
14
|
+
import type { AgentStrategy } from './strategy.js';
|
|
15
|
+
import type { ToolContext, ToolDispatch, ToolHandler, ToolResult } from './tools.js';
|
|
16
|
+
import type { Tracer } from './trace.js';
|
|
17
|
+
import type { Workspace } from './workspace.js';
|
|
18
|
+
export interface AgentSessionConfig {
|
|
19
|
+
/** Pluggable inference algorithm. See `./strategy.ts`. */
|
|
20
|
+
strategy: AgentStrategy;
|
|
21
|
+
llm: LlmClient;
|
|
22
|
+
tools: ToolDispatch;
|
|
23
|
+
/** Tool declarations the LLM should see this turn. Caller filters by
|
|
24
|
+
* capabilities before construction. Empty list disables function
|
|
25
|
+
* calling and the LLM is driven via plain-chat — typically a host
|
|
26
|
+
* bug rather than an intended state. */
|
|
27
|
+
toolList: ToolHandler[];
|
|
28
|
+
/** Factory producing a fresh `ToolContext` for each tool exec — lets the
|
|
29
|
+
* session thread its current workspace/runtime through without
|
|
30
|
+
* closing over stale references. */
|
|
31
|
+
toolContext(): ToolContext;
|
|
32
|
+
/** Build the system prompt from live workspace + runtime. */
|
|
33
|
+
systemPromptBuilder(workspace: Workspace, runtime: RuntimeState): string;
|
|
34
|
+
metrics: MetricsCollector;
|
|
35
|
+
/** Empty for fresh sessions; loaded for resume. */
|
|
36
|
+
history: ChatMessage[];
|
|
37
|
+
/** Optional session id; one is generated when absent. */
|
|
38
|
+
id?: string;
|
|
39
|
+
/** Optional trace sink. Forwarded to the strategy alongside the
|
|
40
|
+
* session-owned `turnId` so the host can correlate
|
|
41
|
+
* `LlmRequestTrace.turnId` back to `SessionEvent`s. Absent =
|
|
42
|
+
* zero-cost no-op. */
|
|
43
|
+
tracer?: Tracer;
|
|
44
|
+
}
|
|
45
|
+
export interface AgentSession {
|
|
46
|
+
readonly id: string;
|
|
47
|
+
readonly workspace: Workspace;
|
|
48
|
+
readonly runtime: RuntimeState;
|
|
49
|
+
/** Run one prompt to completion. The iterable closes when the run is done. */
|
|
50
|
+
submit(prompt: string, signal: AbortSignal): AsyncIterable<SessionEvent>;
|
|
51
|
+
/** Cancel any in-flight submit. Safe to call when idle. */
|
|
52
|
+
cancel(): void;
|
|
53
|
+
}
|
|
54
|
+
export type SessionEvent = {
|
|
55
|
+
kind: 'turn_started';
|
|
56
|
+
turnId: string;
|
|
57
|
+
} | {
|
|
58
|
+
kind: 'text';
|
|
59
|
+
turnId: string;
|
|
60
|
+
chunk: string;
|
|
61
|
+
} | {
|
|
62
|
+
kind: 'thinking';
|
|
63
|
+
turnId: string;
|
|
64
|
+
chunk: string;
|
|
65
|
+
} | {
|
|
66
|
+
kind: 'tool_started';
|
|
67
|
+
turnId: string;
|
|
68
|
+
callId: string;
|
|
69
|
+
name: string;
|
|
70
|
+
args: unknown;
|
|
71
|
+
signature?: string;
|
|
72
|
+
} | {
|
|
73
|
+
kind: 'tool_finished';
|
|
74
|
+
turnId: string;
|
|
75
|
+
callId: string;
|
|
76
|
+
result: ToolResult;
|
|
77
|
+
} | {
|
|
78
|
+
kind: 'workspace_changed';
|
|
79
|
+
workspace: Workspace;
|
|
80
|
+
} | {
|
|
81
|
+
kind: 'runtime_changed';
|
|
82
|
+
runtime: RuntimeState;
|
|
83
|
+
} | {
|
|
84
|
+
kind: 'turn_completed';
|
|
85
|
+
turnId: string;
|
|
86
|
+
metrics: TurnMetrics;
|
|
87
|
+
details: TurnDetails;
|
|
88
|
+
} | {
|
|
89
|
+
kind: 'error';
|
|
90
|
+
turnId?: string;
|
|
91
|
+
message: string;
|
|
92
|
+
} | {
|
|
93
|
+
kind: 'completed';
|
|
94
|
+
}
|
|
95
|
+
/** Strategy-emitted milestones (planner phases, branch expansions, …)
|
|
96
|
+
* — generic envelope so new strategies can surface custom events
|
|
97
|
+
* without expanding the union. */
|
|
98
|
+
| {
|
|
99
|
+
kind: 'strategy_event';
|
|
100
|
+
name: string;
|
|
101
|
+
data?: unknown;
|
|
102
|
+
};
|
|
103
|
+
//# sourceMappingURL=session.d.ts.map
|