@inbrowser/agent 0.0.0-placeholder → 0.2.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/LICENSE +21 -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/diagnostics/index.d.ts +5 -0
- package/dist/diagnostics/index.d.ts.map +1 -0
- package/dist/diagnostics/index.js +3 -0
- package/dist/diagnostics/index.js.map +1 -0
- package/dist/diagnostics/timing.d.ts +48 -0
- package/dist/diagnostics/timing.d.ts.map +1 -0
- package/dist/diagnostics/timing.js +85 -0
- package/dist/diagnostics/timing.js.map +1 -0
- package/dist/diagnostics/truthfulness.d.ts +36 -0
- package/dist/diagnostics/truthfulness.d.ts.map +1 -0
- package/dist/diagnostics/truthfulness.js +180 -0
- package/dist/diagnostics/truthfulness.js.map +1 -0
- package/dist/dispatch-memoization.d.ts +84 -0
- package/dist/dispatch-memoization.d.ts.map +1 -0
- package/dist/dispatch-memoization.js +197 -0
- package/dist/dispatch-memoization.js.map +1 -0
- package/dist/eval/comparison-report.d.ts +164 -0
- package/dist/eval/comparison-report.d.ts.map +1 -0
- package/dist/eval/comparison-report.js +316 -0
- package/dist/eval/comparison-report.js.map +1 -0
- package/dist/eval/fixture.d.ts +74 -0
- package/dist/eval/fixture.d.ts.map +1 -0
- package/dist/eval/fixture.js +217 -0
- package/dist/eval/fixture.js.map +1 -0
- package/dist/eval/index.d.ts +13 -0
- package/dist/eval/index.d.ts.map +1 -0
- package/dist/eval/index.js +7 -0
- package/dist/eval/index.js.map +1 -0
- package/dist/eval/load-node.d.ts +16 -0
- package/dist/eval/load-node.d.ts.map +1 -0
- package/dist/eval/load-node.js +58 -0
- package/dist/eval/load-node.js.map +1 -0
- package/dist/eval/metric-collector.d.ts +209 -0
- package/dist/eval/metric-collector.d.ts.map +1 -0
- package/dist/eval/metric-collector.js +293 -0
- package/dist/eval/metric-collector.js.map +1 -0
- package/dist/eval/run-record.d.ts +76 -0
- package/dist/eval/run-record.d.ts.map +1 -0
- package/dist/eval/run-record.js +32 -0
- package/dist/eval/run-record.js.map +1 -0
- package/dist/eval/runner.d.ts +140 -0
- package/dist/eval/runner.d.ts.map +1 -0
- package/dist/eval/runner.js +310 -0
- package/dist/eval/runner.js.map +1 -0
- package/dist/eval/spec-framework.d.ts +113 -0
- package/dist/eval/spec-framework.d.ts.map +1 -0
- package/dist/eval/spec-framework.js +100 -0
- package/dist/eval/spec-framework.js.map +1 -0
- package/dist/eval/spec-helpers.d.ts +245 -0
- package/dist/eval/spec-helpers.d.ts.map +1 -0
- package/dist/eval/spec-helpers.js +605 -0
- package/dist/eval/spec-helpers.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 +73 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +47 -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 +23 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +23 -0
- package/dist/node.js.map +1 -0
- package/dist/planner-executor.d.ts +132 -0
- package/dist/planner-executor.d.ts.map +1 -0
- package/dist/planner-executor.js +274 -0
- package/dist/planner-executor.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/skill-catalog.d.ts +81 -0
- package/dist/skill-catalog.d.ts.map +1 -0
- package/dist/skill-catalog.js +388 -0
- package/dist/skill-catalog.js.map +1 -0
- package/dist/skill-router.d.ts +95 -0
- package/dist/skill-router.d.ts.map +1 -0
- package/dist/skill-router.js +130 -0
- package/dist/skill-router.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 +45 -0
- package/dist/strategy.d.ts.map +1 -0
- package/dist/strategy.js +520 -0
- package/dist/strategy.js.map +1 -0
- package/dist/tools.d.ts +40 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +147 -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 +124 -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 +154 -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 +175 -0
- package/dist/types/trace.d.ts.map +1 -0
- package/dist/types/trace.js +26 -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,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,M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M,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
|
|
@@ -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;;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CAAC;IAAC,MAAM,EAAE,UAAU,CAAA;CAAE,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,124 @@
|
|
|
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
|
+
/**
|
|
77
|
+
* Opt-in critique-and-retry pass after a candidate final-answer turn.
|
|
78
|
+
*
|
|
79
|
+
* When `enabled === true`, the ReAct loop runs as usual, but instead of
|
|
80
|
+
* returning immediately on a turn that produced no tool calls the
|
|
81
|
+
* strategy issues a second chat call asking the model to evaluate its
|
|
82
|
+
* own last response against the prior tool results visible in the
|
|
83
|
+
* conversation. The evaluation returns a JSON verdict of the shape
|
|
84
|
+
* `{ "ok": boolean, "feedback"?: string }`. When the verdict is `ok`
|
|
85
|
+
* the original answer stands. When the verdict flags problems and the
|
|
86
|
+
* retry budget has not been exhausted, the strategy injects the
|
|
87
|
+
* feedback as a synthetic user message and loops back into the next
|
|
88
|
+
* ReAct iteration. When the retry budget is exhausted the strategy
|
|
89
|
+
* returns the most recent final-answer turn as-is — reflexion never
|
|
90
|
+
* blocks completion.
|
|
91
|
+
*
|
|
92
|
+
* A malformed verdict (non-JSON critique text, or JSON missing the
|
|
93
|
+
* `ok` field) is treated as `{ ok: true }`: fail-open, never block on a
|
|
94
|
+
* critique the strategy could not parse.
|
|
95
|
+
*
|
|
96
|
+
* The critique runs through the same `LlmClient` as the main loop; the
|
|
97
|
+
* trace emits an additional `llm_request` for the critique call with a
|
|
98
|
+
* `requestId` suffixed `#critique`, so trace consumers can distinguish
|
|
99
|
+
* critique requests from main-loop requests. The strategy emits a
|
|
100
|
+
* `custom` `StrategyEvent` named `'reflexion_critique'` with a
|
|
101
|
+
* `{ verdict, text, feedback? }` payload at every critique decision.
|
|
102
|
+
*
|
|
103
|
+
* Defaults: `maxRetries: 1`. When `enabled === false` (or the option
|
|
104
|
+
* is absent) the strategy's behavior is byte-for-byte identical to the
|
|
105
|
+
* pre-reflexion loop.
|
|
106
|
+
*/
|
|
107
|
+
export interface ReflexionConfig {
|
|
108
|
+
/** Opt-in switch. */
|
|
109
|
+
enabled: boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Maximum retries after the critique flags problems. Defaults to 1.
|
|
112
|
+
* Setting to 0 disables retries entirely (the critique runs and its
|
|
113
|
+
* verdict is emitted, but no retry is attempted on `ok: false`).
|
|
114
|
+
*/
|
|
115
|
+
maxRetries?: number;
|
|
116
|
+
/**
|
|
117
|
+
* System prompt used for the critique call. Defaults to a neutral
|
|
118
|
+
* prompt that asks the model to evaluate consistency with prior
|
|
119
|
+
* tool results and reply with `{"ok": boolean, "feedback"?: string}`
|
|
120
|
+
* JSON. Override when a skill needs a tighter verifier rubric.
|
|
121
|
+
*/
|
|
122
|
+
critiqueSystemPrompt?: string;
|
|
123
|
+
}
|
|
124
|
+
//# 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,MAA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,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,UAAU,CAAA;CAAE,GACvD;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;AACpC;4DAC4D;GAC1D;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAErD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,WAAW,eAAe;IAC9B,qBAAqB;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;;OAKG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B"}
|
|
@@ -0,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"}
|