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