@elizaos/capacitor-agent 2.0.0-beta.1 → 2.0.11-beta.7

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/dist/esm/web.js CHANGED
@@ -1,4 +1,45 @@
1
1
  import { WebPlugin } from "@capacitor/core";
2
+ function assertNonEmptyText(text) {
3
+ if (typeof text !== "string" || text.trim().length === 0) {
4
+ throw new Error("Agent.chat requires non-empty text");
5
+ }
6
+ return text;
7
+ }
8
+ function assertRequestPath(path) {
9
+ if (typeof path !== "string" || path.trim().length === 0) {
10
+ throw new Error("Agent.request path must start with /");
11
+ }
12
+ const trimmed = path.trim();
13
+ if (!trimmed.startsWith("/") ||
14
+ trimmed.startsWith("//") ||
15
+ trimmed.includes("\\")) {
16
+ throw new Error("Agent.request requires a local path that starts with / and is not an absolute URL");
17
+ }
18
+ try {
19
+ const parsed = new URL(trimmed);
20
+ if (parsed.protocol) {
21
+ throw new Error("Agent.request requires a local path that starts with / and is not an absolute URL");
22
+ }
23
+ }
24
+ catch (err) {
25
+ if (err instanceof Error && err.message.includes("absolute URL")) {
26
+ throw err;
27
+ }
28
+ }
29
+ return trimmed;
30
+ }
31
+ function assertRequestMethod(method) {
32
+ if (method === undefined)
33
+ return "GET";
34
+ if (typeof method !== "string") {
35
+ throw new Error("Unsupported HTTP method");
36
+ }
37
+ const normalized = method.trim().toUpperCase();
38
+ if (!/^[A-Z]{1,16}$/.test(normalized)) {
39
+ throw new Error("Unsupported HTTP method");
40
+ }
41
+ return normalized;
42
+ }
2
43
  /**
3
44
  * Web fallback implementation.
4
45
  *
@@ -93,6 +134,27 @@ export class AgentWeb extends WebPlugin {
93
134
  // No explicit base — use relative URLs (works on http/https origins).
94
135
  return "";
95
136
  }
137
+ isLocalAgentIpcBase() {
138
+ const base = this.apiBase().trim();
139
+ if (!base)
140
+ return false;
141
+ const lower = base.toLowerCase();
142
+ if (lower === "eliza-local-agent://ipc" ||
143
+ lower.startsWith("eliza-local-agent://ipc/") ||
144
+ lower.startsWith("eliza-local-agent://ipc?")) {
145
+ return true;
146
+ }
147
+ try {
148
+ const parsed = new URL(base);
149
+ return (parsed.protocol === "eliza-local-agent:" &&
150
+ (parsed.hostname === "ipc" ||
151
+ parsed.pathname === "//ipc" ||
152
+ parsed.pathname.startsWith("//ipc/")));
153
+ }
154
+ catch {
155
+ return false;
156
+ }
157
+ }
96
158
  apiToken() {
97
159
  const global = typeof window !== "undefined"
98
160
  ? window.__ELIZA_API_TOKEN__
@@ -110,6 +172,8 @@ export class AgentWeb extends WebPlugin {
110
172
  }
111
173
  /** True when we can reach the API via HTTP. */
112
174
  canReachApi() {
175
+ if (this.isLocalAgentIpcBase())
176
+ return false;
113
177
  const global = typeof window !== "undefined"
114
178
  ? window.__ELIZA_API_BASE__
115
179
  : undefined;
@@ -121,7 +185,7 @@ export class AgentWeb extends WebPlugin {
121
185
  const proto = window.location.protocol;
122
186
  return proto === "http:" || proto === "https:";
123
187
  }
124
- async start() {
188
+ async start(_options) {
125
189
  if (!this.canReachApi()) {
126
190
  return {
127
191
  state: "not_started",
@@ -164,10 +228,11 @@ export class AgentWeb extends WebPlugin {
164
228
  return res.json();
165
229
  }
166
230
  async chat(options) {
231
+ const text = assertNonEmptyText(options.text);
167
232
  if (!this.canReachApi()) {
168
233
  return { text: "Agent API not available", agentName: "System" };
169
234
  }
170
- return this.chatViaConversation(options.text);
235
+ return this.chatViaConversation(text);
171
236
  }
172
237
  async getLocalAgentToken() {
173
238
  const token = this.apiToken();
@@ -177,11 +242,21 @@ export class AgentWeb extends WebPlugin {
177
242
  };
178
243
  }
179
244
  async request(options) {
180
- if (!options.path?.startsWith("/")) {
181
- throw new Error("Agent.request path must start with /");
245
+ const path = assertRequestPath(options.path);
246
+ const method = assertRequestMethod(options.method);
247
+ if (this.isLocalAgentIpcBase()) {
248
+ return {
249
+ status: 503,
250
+ statusText: "Service Unavailable",
251
+ headers: { "content-type": "application/json" },
252
+ body: JSON.stringify({
253
+ error: "native_agent_unavailable",
254
+ message: "Agent web fallback cannot handle eliza-local-agent://ipc; use the native Capacitor Agent plugin",
255
+ }),
256
+ };
182
257
  }
183
- const res = await fetch(`${this.apiBase()}${options.path}`, {
184
- method: options.method ?? "GET",
258
+ const res = await fetch(`${this.apiBase()}${path}`, {
259
+ method,
185
260
  headers: {
186
261
  ...this.authHeaders(),
187
262
  ...options.headers,
@@ -1 +1 @@
1
- {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAe5C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,QAAS,SAAQ,SAAS;IAC7B,4BAA4B;QAClC,MAAM,IAAI,GACR,IAAI,CAAC,OAAO,EAAE;YACd,CAAC,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC;QAC3E,OAAO,gCAAgC,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;IACpE,CAAC;IAEO,wBAAwB;QAC9B,IAAI,OAAO,MAAM,KAAK,WAAW;YAAE,OAAO,IAAI,CAAC;QAC/C,MAAM,MAAM,GAAG,MAAM,CAAC,cAAc,CAAC,OAAO,CAC1C,IAAI,CAAC,4BAA4B,EAAE,CACpC,CAAC;QACF,OAAO,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IAC/C,CAAC;IAEO,yBAAyB,CAAC,cAA6B;QAC7D,IAAI,OAAO,MAAM,KAAK,WAAW;YAAE,OAAO;QAC1C,MAAM,GAAG,GAAG,IAAI,CAAC,4BAA4B,EAAE,CAAC;QAChD,IAAI,cAAc,EAAE,IAAI,EAAE,EAAE,CAAC;YAC3B,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,EA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IAAI,CAAC,SAAS,CAAC;oBACnB,KAAK,EAAE,0BAA0B;oBACjC,OAAO,EACL,iGAAiG;iBACpG,CAAC;aACH,CAAC;QACJ,CAAC;QACD,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,EAAE,EAAE;YAClD,MAAM;YACN,OAAO,EAAE;gBACP,GAAG,IAAI,CAAC,WAAW,EAAE;gBACrB,GAAG,OAAO,CAAC,OAAO;aACnB;YACD,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,SAAS;SAChC,CAAC,CAAC;QACH,MAAM,OAAO,GAA2B,EAAE,CAAC;QAC3C,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;YACjC,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACvB,CAAC,CAAC,CAAC;QACH,OAAO;YACL,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,UAAU,EAAE,GAAG,CAAC,UAAU;YAC1B,OAAO;YACP,IAAI,EAAE,MAAM,GAAG,CAAC,IAAI,EAAE;SACvB,CAAC;IACJ,CAAC;CACF"}
@@ -5,9 +5,50 @@ var core = require('@capacitor/core');
5
5
  const Agent = core.registerPlugin("Agent", {
6
6
  web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.AgentWeb()),
7
7
  // Electrobun uses the preload bridge (agent:start, agent:stop, etc.)
8
- // iOS/Android will use the web fallback (HTTP to API server) for now
8
+ // iOS/Android use the native bridge when registered, otherwise the HTTP web fallback.
9
9
  });
10
10
 
11
+ function assertNonEmptyText(text) {
12
+ if (typeof text !== "string" || text.trim().length === 0) {
13
+ throw new Error("Agent.chat requires non-empty text");
14
+ }
15
+ return text;
16
+ }
17
+ function assertRequestPath(path) {
18
+ if (typeof path !== "string" || path.trim().length === 0) {
19
+ throw new Error("Agent.request path must start with /");
20
+ }
21
+ const trimmed = path.trim();
22
+ if (!trimmed.startsWith("/") ||
23
+ trimmed.startsWith("//") ||
24
+ trimmed.includes("\\")) {
25
+ throw new Error("Agent.request requires a local path that starts with / and is not an absolute URL");
26
+ }
27
+ try {
28
+ const parsed = new URL(trimmed);
29
+ if (parsed.protocol) {
30
+ throw new Error("Agent.request requires a local path that starts with / and is not an absolute URL");
31
+ }
32
+ }
33
+ catch (err) {
34
+ if (err instanceof Error && err.message.includes("absolute URL")) {
35
+ throw err;
36
+ }
37
+ }
38
+ return trimmed;
39
+ }
40
+ function assertRequestMethod(method) {
41
+ if (method === undefined)
42
+ return "GET";
43
+ if (typeof method !== "string") {
44
+ throw new Error("Unsupported HTTP method");
45
+ }
46
+ const normalized = method.trim().toUpperCase();
47
+ if (!/^[A-Z]{1,16}$/.test(normalized)) {
48
+ throw new Error("Unsupported HTTP method");
49
+ }
50
+ return normalized;
51
+ }
11
52
  /**
12
53
  * Web fallback implementation.
13
54
  *
@@ -102,6 +143,27 @@ class AgentWeb extends core.WebPlugin {
102
143
  // No explicit base — use relative URLs (works on http/https origins).
103
144
  return "";
104
145
  }
146
+ isLocalAgentIpcBase() {
147
+ const base = this.apiBase().trim();
148
+ if (!base)
149
+ return false;
150
+ const lower = base.toLowerCase();
151
+ if (lower === "eliza-local-agent://ipc" ||
152
+ lower.startsWith("eliza-local-agent://ipc/") ||
153
+ lower.startsWith("eliza-local-agent://ipc?")) {
154
+ return true;
155
+ }
156
+ try {
157
+ const parsed = new URL(base);
158
+ return (parsed.protocol === "eliza-local-agent:" &&
159
+ (parsed.hostname === "ipc" ||
160
+ parsed.pathname === "//ipc" ||
161
+ parsed.pathname.startsWith("//ipc/")));
162
+ }
163
+ catch {
164
+ return false;
165
+ }
166
+ }
105
167
  apiToken() {
106
168
  const global = typeof window !== "undefined"
107
169
  ? window.__ELIZA_API_TOKEN__
@@ -119,6 +181,8 @@ class AgentWeb extends core.WebPlugin {
119
181
  }
120
182
  /** True when we can reach the API via HTTP. */
121
183
  canReachApi() {
184
+ if (this.isLocalAgentIpcBase())
185
+ return false;
122
186
  const global = typeof window !== "undefined"
123
187
  ? window.__ELIZA_API_BASE__
124
188
  : undefined;
@@ -130,7 +194,7 @@ class AgentWeb extends core.WebPlugin {
130
194
  const proto = window.location.protocol;
131
195
  return proto === "http:" || proto === "https:";
132
196
  }
133
- async start() {
197
+ async start(_options) {
134
198
  if (!this.canReachApi()) {
135
199
  return {
136
200
  state: "not_started",
@@ -173,10 +237,11 @@ class AgentWeb extends core.WebPlugin {
173
237
  return res.json();
174
238
  }
175
239
  async chat(options) {
240
+ const text = assertNonEmptyText(options.text);
176
241
  if (!this.canReachApi()) {
177
242
  return { text: "Agent API not available", agentName: "System" };
178
243
  }
179
- return this.chatViaConversation(options.text);
244
+ return this.chatViaConversation(text);
180
245
  }
181
246
  async getLocalAgentToken() {
182
247
  const token = this.apiToken();
@@ -186,11 +251,21 @@ class AgentWeb extends core.WebPlugin {
186
251
  };
187
252
  }
188
253
  async request(options) {
189
- if (!options.path?.startsWith("/")) {
190
- throw new Error("Agent.request path must start with /");
254
+ const path = assertRequestPath(options.path);
255
+ const method = assertRequestMethod(options.method);
256
+ if (this.isLocalAgentIpcBase()) {
257
+ return {
258
+ status: 503,
259
+ statusText: "Service Unavailable",
260
+ headers: { "content-type": "application/json" },
261
+ body: JSON.stringify({
262
+ error: "native_agent_unavailable",
263
+ message: "Agent web fallback cannot handle eliza-local-agent://ipc; use the native Capacitor Agent plugin",
264
+ }),
265
+ };
191
266
  }
192
- const res = await fetch(`${this.apiBase()}${options.path}`, {
193
- method: options.method ?? "GET",
267
+ const res = await fetch(`${this.apiBase()}${path}`, {
268
+ method,
194
269
  headers: {
195
270
  ...this.authHeaders(),
196
271
  ...options.headers,
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from \"@capacitor/core\";\nexport * from \"./definitions\";\nexport const Agent = registerPlugin(\"Agent\", {\n web: () => import(\"./web\").then((m) => new m.AgentWeb()),\n // Electrobun uses the preload bridge (agent:start, agent:stop, etc.)\n // iOS/Android will use the web fallback (HTTP to API server) for now\n});\n//# sourceMappingURL=index.js.map","import { WebPlugin } from \"@capacitor/core\";\n/**\n * Web fallback implementation.\n *\n * On non-desktop platforms (iOS, Android, web), the agent runtime runs\n * on a server. This implementation delegates to the HTTP API.\n *\n * In Electrobun the desktop bridge calls the native main-process\n * implementation via RPC instead — this web fallback is only used when\n * no native plugin is available. If the page is served from a non-HTTP\n * origin (e.g. electrobun://), relative fetches would hit the\n * app shell HTML, so we bail early.\n *\n * Local-agent-on-Android (Phase E): when the host UI selects the\n * \"Local Agent\" tile, it sets `apiBase` to `http://127.0.0.1:31337`,\n * which the runtime mirrors into `window.__ELIZA_API_BASE__`. From this\n * plugin's perspective there is no special case — it simply HTTP-POSTs\n * to `${apiBase}/api/agent/start|stop|status`, which is exactly the same\n * surface Phase B's `ElizaAgentService` exposes. The web fallback path\n * therefore works unchanged for both remote and on-device agents.\n */\nexport class AgentWeb extends WebPlugin {\n legacyConversationStorageKey() {\n const base = this.apiBase() ||\n (typeof window !== \"undefined\" ? window.location.origin : \"same-origin\");\n return `eliza_agent_web_conversation:${encodeURIComponent(base)}`;\n }\n readLegacyConversationId() {\n if (typeof window === \"undefined\")\n return null;\n const stored = window.sessionStorage.getItem(this.legacyConversationStorageKey());\n return stored?.trim() ? stored.trim() : null;\n }\n writeLegacyConversationId(conversationId) {\n if (typeof window === \"undefined\")\n return;\n const key = this.legacyConversationStorageKey();\n if (conversationId?.trim()) {\n window.sessionStorage.setItem(key, conversationId.trim());\n return;\n }\n window.sessionStorage.removeItem(key);\n }\n async ensureLegacyConversationId() {\n const cached = this.readLegacyConversationId();\n if (cached)\n return cached;\n const res = await fetch(`${this.apiBase()}/api/conversations`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...this.authHeaders(),\n },\n body: JSON.stringify({ title: \"Quick Chat\" }),\n });\n if (!res.ok) {\n throw new Error(`Failed to create conversation: ${res.status}`);\n }\n const data = (await res.json());\n const conversationId = data.conversation?.id?.trim();\n if (!conversationId) {\n throw new Error(\"Conversation create response missing id\");\n }\n this.writeLegacyConversationId(conversationId);\n return conversationId;\n }\n async chatViaConversation(text, retryOnMissingConversation = true) {\n const conversationId = await this.ensureLegacyConversationId();\n // @duplicate-component-audit-allow: agent API message POST; server-side runtime owns model trajectory logging.\n const res = await fetch(`${this.apiBase()}/api/conversations/${encodeURIComponent(conversationId)}/messages`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...this.authHeaders(),\n },\n body: JSON.stringify({ text, channelType: \"DM\" }),\n });\n if (res.status === 404 && retryOnMissingConversation) {\n this.writeLegacyConversationId(null);\n return this.chatViaConversation(text, false);\n }\n if (!res.ok) {\n throw new Error(`Chat request failed: ${res.status}`);\n }\n return res.json();\n }\n apiBase() {\n const global = typeof window !== \"undefined\"\n ? window.__ELIZA_API_BASE__\n : undefined;\n if (typeof global === \"string\" && global.trim().length > 0)\n return global;\n // No explicit base — use relative URLs (works on http/https origins).\n return \"\";\n }\n apiToken() {\n const global = typeof window !== \"undefined\"\n ? window.__ELIZA_API_TOKEN__\n : undefined;\n if (typeof global === \"string\" && global.trim())\n return global.trim();\n if (typeof window === \"undefined\")\n return null;\n const stored = window.sessionStorage.getItem(\"eliza_api_token\");\n return stored?.trim() ? stored.trim() : null;\n }\n authHeaders() {\n const token = this.apiToken();\n return token ? { Authorization: `Bearer ${token}` } : {};\n }\n /** True when we can reach the API via HTTP. */\n canReachApi() {\n const global = typeof window !== \"undefined\"\n ? window.__ELIZA_API_BASE__\n : undefined;\n if (typeof global === \"string\" && global.trim().length > 0)\n return true;\n // No explicit base — relative fetches only work on http(s) origins.\n if (typeof window === \"undefined\")\n return false;\n const proto = window.location.protocol;\n return proto === \"http:\" || proto === \"https:\";\n }\n async start() {\n if (!this.canReachApi()) {\n return {\n state: \"not_started\",\n agentName: null,\n port: null,\n startedAt: null,\n error: \"No API endpoint\",\n };\n }\n const res = await fetch(`${this.apiBase()}/api/agent/start`, {\n method: \"POST\",\n headers: this.authHeaders(),\n });\n const data = await res.json();\n return data.status ?? data;\n }\n async stop() {\n if (!this.canReachApi()) {\n return { ok: false };\n }\n const res = await fetch(`${this.apiBase()}/api/agent/stop`, {\n method: \"POST\",\n headers: this.authHeaders(),\n });\n return res.json();\n }\n async getStatus() {\n if (!this.canReachApi()) {\n return {\n state: \"not_started\",\n agentName: null,\n port: null,\n startedAt: null,\n error: \"No API endpoint\",\n };\n }\n const res = await fetch(`${this.apiBase()}/api/status`, {\n headers: this.authHeaders(),\n });\n return res.json();\n }\n async chat(options) {\n if (!this.canReachApi()) {\n return { text: \"Agent API not available\", agentName: \"System\" };\n }\n return this.chatViaConversation(options.text);\n }\n async getLocalAgentToken() {\n const token = this.apiToken();\n return {\n available: Boolean(token),\n token,\n };\n }\n async request(options) {\n if (!options.path?.startsWith(\"/\")) {\n throw new Error(\"Agent.request path must start with /\");\n }\n const res = await fetch(`${this.apiBase()}${options.path}`, {\n method: options.method ?? \"GET\",\n headers: {\n ...this.authHeaders(),\n ...options.headers,\n },\n body: options.body ?? undefined,\n });\n const headers = {};\n res.headers.forEach((value, key) => {\n headers[key] = value;\n });\n return {\n status: res.status,\n statusText: res.statusText,\n headers,\n body: await res.text(),\n };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AAEY,MAAC,KAAK,GAAGA,mBAAc,CAAC,OAAO,EAAE;AAC7C,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC;AAC5D;AACA;AACA,CAAC;;ACLD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,QAAQ,SAASC,cAAS,CAAC;AACxC,IAAI,4BAA4B,GAAG;AACnC,QAAQ,MA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AG,IAAI,CAAC,QAAQ,EAAE;AACrC,QAAQ,OAAO;AACf,YAAY,SAAS,EAAE,OAAO,CAAC,KAAK,CAAC;AACrC,YAAY,KAAK;AACjB,SAAS;AACT,IAAI;AACJ,IAAI,MAAM,OAAO,CAAC,OAAO,EAAE;AAC3B,QAAQ,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE;AAC5C,YAAY,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC;AACnE,QAAQ;AACR,QAAQ,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE;AACpE,YAAY,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,KAAK;AAC3C,YAAY,OAAO,EAAE;AACrB,gBAAgB,GAAG,IAAI,CAAC,WAAW,EAAE;AACrC,gBAAgB,GAAG,OAAO,CAAC,OAAO;AAClC,aAAa;AACb,YAAY,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,SAAS;AAC3C,SAAS,CAAC;AACV,QAAQ,MAAM,OAAO,GAAG,EAAE;AAC1B,QAAQ,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK;AAC5C,YAAY,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK;AAChC,QAAQ,CAAC,CAAC;AACV,QAAQ,OAAO;AACf,YAAY,MAAM,EAAE,GAAG,CAAC,MAAM;AAC9B,YAAY,UAAU,EAAE,GAAG,CAAC,UAAU;AACtC,YAAY,OAAO;AACnB,YAAY,IAAI,EAAE,MAAM,GAAG,CAAC,IAAI,EAAE;AAClC,SAAS;AACT,IAAI;AACJ;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from \"@capacitor/core\";\nexport * from \"./definitions\";\nexport const Agent = registerPlugin(\"Agent\", {\n web: () => import(\"./web\").then((m) => new m.AgentWeb()),\n // Electrobun uses the preload bridge (agent:start, agent:stop, etc.)\n // iOS/Android use the native bridge when registered, otherwise the HTTP web fallback.\n});\n//# sourceMappingURL=index.js.map","import { WebPlugin } from \"@capacitor/core\";\nfunction assertNonEmptyText(text) {\n if (typeof text !== \"string\" || text.trim().length === 0) {\n throw new Error(\"Agent.chat requires non-empty text\");\n }\n return text;\n}\nfunction assertRequestPath(path) {\n if (typeof path !== \"string\" || path.trim().length === 0) {\n throw new Error(\"Agent.request path must start with /\");\n }\n const trimmed = path.trim();\n if (!trimmed.startsWith(\"/\") ||\n trimmed.startsWith(\"//\") ||\n trimmed.includes(\"\\\\\")) {\n throw new Error(\"Agent.request requires a local path that starts with / and is not an absolute URL\");\n }\n try {\n const parsed = new URL(trimmed);\n if (parsed.protocol) {\n throw new Error(\"Agent.request requires a local path that starts with / and is not an absolute URL\");\n }\n }\n catch (err) {\n if (err instanceof Error && err.message.includes(\"absolute URL\")) {\n throw err;\n }\n }\n return trimmed;\n}\nfunction assertRequestMethod(method) {\n if (method === undefined)\n return \"GET\";\n if (typeof method !== \"string\") {\n throw new Error(\"Unsupported HTTP method\");\n }\n const normalized = method.trim().toUpperCase();\n if (!/^[A-Z]{1,16}$/.test(normalized)) {\n throw new Error(\"Unsupported HTTP method\");\n }\n return normalized;\n}\n/**\n * Web fallback implementation.\n *\n * On non-desktop platforms (iOS, Android, web), the agent runtime runs\n * on a server. This implementation delegates to the HTTP API.\n *\n * In Electrobun the desktop bridge calls the native main-process\n * implementation via RPC instead — this web fallback is only used when\n * no native plugin is available. If the page is served from a non-HTTP\n * origin (e.g. electrobun://), relative fetches would hit the\n * app shell HTML, so we bail early.\n *\n * Local-agent-on-Android (Phase E): when the host UI selects the\n * \"Local Agent\" tile, it sets `apiBase` to `http://127.0.0.1:31337`,\n * which the runtime mirrors into `window.__ELIZA_API_BASE__`. From this\n * plugin's perspective there is no special case — it simply HTTP-POSTs\n * to `${apiBase}/api/agent/start|stop|status`, which is exactly the same\n * surface Phase B's `ElizaAgentService` exposes. The web fallback path\n * therefore works unchanged for both remote and on-device agents.\n */\nexport class AgentWeb extends WebPlugin {\n legacyConversationStorageKey() {\n const base = this.apiBase() ||\n (typeof window !== \"undefined\" ? window.location.origin : \"same-origin\");\n return `eliza_agent_web_conversation:${encodeURIComponent(base)}`;\n }\n readLegacyConversationId() {\n if (typeof window === \"undefined\")\n return null;\n const stored = window.sessionStorage.getItem(this.legacyConversationStorageKey());\n return stored?.trim() ? stored.trim() : null;\n }\n writeLegacyConversationId(conversationId) {\n if (typeof window === \"undefined\")\n return;\n const key = this.legacyConversationStorageKey();\n if (conversationId?.trim()) {\n window.sessionStorage.setItem(key, conversationId.trim());\n return;\n }\n window.sessionStorage.removeItem(key);\n }\n async ensureLegacyConversationId() {\n const cached = this.readLegacyConversationId();\n if (cached)\n return cached;\n const res = await fetch(`${this.apiBase()}/api/conversations`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...this.authHeaders(),\n },\n body: JSON.stringify({ title: \"Quick Chat\" }),\n });\n if (!res.ok) {\n throw new Error(`Failed to create conversation: ${res.status}`);\n }\n const data = (await res.json());\n const conversationId = data.conversation?.id?.trim();\n if (!conversationId) {\n throw new Error(\"Conversation create response missing id\");\n }\n this.writeLegacyConversationId(conversationId);\n return conversationId;\n }\n async chatViaConversation(text, retryOnMissingConversation = true) {\n const conversationId = await this.ensureLegacyConversationId();\n // @duplicate-component-audit-allow: agent API message POST; server-side runtime owns model trajectory logging.\n const res = await fetch(`${this.apiBase()}/api/conversations/${encodeURIComponent(conversationId)}/messages`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...this.authHeaders(),\n },\n body: JSON.stringify({ text, channelType: \"DM\" }),\n });\n if (res.status === 404 && retryOnMissingConversation) {\n this.writeLegacyConversationId(null);\n return this.chatViaConversation(text, false);\n }\n if (!res.ok) {\n throw new Error(`Chat request failed: ${res.status}`);\n }\n return res.json();\n }\n apiBase() {\n const global = typeof window !== \"undefined\"\n ? window.__ELIZA_API_BASE__\n : undefined;\n if (typeof global === \"string\" && global.trim().length > 0)\n return global;\n // No explicit base — use relative URLs (works on http/https origins).\n return \"\";\n }\n isLocalAgentIpcBase() {\n const base = this.apiBase().trim();\n if (!base)\n return false;\n const lower = base.toLowerCase();\n if (lower === \"eliza-local-agent://ipc\" ||\n lower.startsWith(\"eliza-local-agent://ipc/\") ||\n lower.startsWith(\"eliza-local-agent://ipc?\")) {\n return true;\n }\n try {\n const parsed = new URL(base);\n return (parsed.protocol === \"eliza-local-agent:\" &&\n (parsed.hostname === \"ipc\" ||\n parsed.pathname === \"//ipc\" ||\n parsed.pathname.startsWith(\"//ipc/\")));\n }\n catch {\n return false;\n }\n }\n apiToken() {\n const global = typeof window !== \"undefined\"\n ? window.__ELIZA_API_TOKEN__\n : undefined;\n if (typeof global === \"string\" && global.trim())\n return global.trim();\n if (typeof window === \"undefined\")\n return null;\n const stored = window.sessionStorage.getItem(\"eliza_api_token\");\n return stored?.trim() ? stored.trim() : null;\n }\n authHeaders() {\n const token = this.apiToken();\n return token ? { Authorization: `Bearer ${token}` } : {};\n }\n /** True when we can reach the API via HTTP. */\n canReachApi() {\n if (this.isLocalAgentIpcBase())\n return false;\n const global = typeof window !== \"undefined\"\n ? window.__ELIZA_API_BASE__\n : undefined;\n if (typeof global === \"string\" && global.trim().length > 0)\n return true;\n // No explicit base — relative fetches only work on http(s) origins.\n if (typeof window === \"undefined\")\n return false;\n const proto = window.location.protocol;\n return proto === \"http:\" || proto === \"https:\";\n }\n async start(_options) {\n if (!this.canReachApi()) {\n return {\n state: \"not_started\",\n agentName: null,\n port: null,\n startedAt: null,\n error: \"No API endpoint\",\n };\n }\n const res = await fetch(`${this.apiBase()}/api/agent/start`, {\n method: \"POST\",\n headers: this.authHeaders(),\n });\n const data = await res.json();\n return data.status ?? data;\n }\n async stop() {\n if (!this.canReachApi()) {\n return { ok: false };\n }\n const res = await fetch(`${this.apiBase()}/api/agent/stop`, {\n method: \"POST\",\n headers: this.authHeaders(),\n });\n return res.json();\n }\n async getStatus() {\n if (!this.canReachApi()) {\n return {\n state: \"not_started\",\n agentName: null,\n port: null,\n startedAt: null,\n error: \"No API endpoint\",\n };\n }\n const res = await fetch(`${this.apiBase()}/api/status`, {\n headers: this.authHeaders(),\n });\n return res.json();\n }\n async chat(options) {\n const text = assertNonEmptyText(options.text);\n if (!this.canReachApi()) {\n return { text: \"Agent API not available\", agentName: \"System\" };\n }\n return this.chatViaConversation(text);\n }\n async getLocalAgentToken() {\n const token = this.apiToken();\n return {\n available: Boolean(token),\n token,\n };\n }\n async request(options) {\n const path = assertRequestPath(options.path);\n const method = assertRequestMethod(options.method);\n if (this.isLocalAgentIpcBase()) {\n return {\n status: 503,\n statusText: \"Service Unavailable\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({\n error: \"native_agent_unavailable\",\n message: \"Agent web fallback cannot handle eliza-local-agent://ipc; use the native Capacitor Agent plugin\",\n }),\n };\n }\n const res = await fetch(`${this.apiBase()}${path}`, {\n method,\n headers: {\n ...this.authHeaders(),\n ...options.headers,\n },\n body: options.body ?? undefined,\n });\n const headers = {};\n res.headers.forEach((value, key) => {\n headers[key] = value;\n });\n return {\n status: res.status,\n statusText: res.statusText,\n headers,\n body: await res.text(),\n };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AAEY,MAAC,KAAK,GAAGA,mBAAc,CAAC,OAAO,EAAE;AAC7C,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC;AAC5D;AACA;AACA,CAAC;;ACLD,SAAS,kBAAkB,CAAC,IAAI,EAAE;AAClC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,E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GAAG,CAAC,GAAG,KAAK;AAChC,QAAQ,CAAC,CAAC;AACV,QAAQ,OAAO;AACf,YAAY,MAAM,EAAE,GAAG,CAAC,MAAM;AAC9B,YAAY,UAAU,EAAE,GAAG,CAAC,UAAU;AACtC,YAAY,OAAO;AACnB,YAAY,IAAI,EAAE,MAAM,GAAG,CAAC,IAAI,EAAE;AAClC,SAAS;AACT,IAAI;AACJ;;;;;;;;;"}
package/dist/plugin.js CHANGED
@@ -4,9 +4,50 @@ var capacitorAgent = (function (exports, core) {
4
4
  const Agent = core.registerPlugin("Agent", {
5
5
  web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.AgentWeb()),
6
6
  // Electrobun uses the preload bridge (agent:start, agent:stop, etc.)
7
- // iOS/Android will use the web fallback (HTTP to API server) for now
7
+ // iOS/Android use the native bridge when registered, otherwise the HTTP web fallback.
8
8
  });
9
9
 
10
+ function assertNonEmptyText(text) {
11
+ if (typeof text !== "string" || text.trim().length === 0) {
12
+ throw new Error("Agent.chat requires non-empty text");
13
+ }
14
+ return text;
15
+ }
16
+ function assertRequestPath(path) {
17
+ if (typeof path !== "string" || path.trim().length === 0) {
18
+ throw new Error("Agent.request path must start with /");
19
+ }
20
+ const trimmed = path.trim();
21
+ if (!trimmed.startsWith("/") ||
22
+ trimmed.startsWith("//") ||
23
+ trimmed.includes("\\")) {
24
+ throw new Error("Agent.request requires a local path that starts with / and is not an absolute URL");
25
+ }
26
+ try {
27
+ const parsed = new URL(trimmed);
28
+ if (parsed.protocol) {
29
+ throw new Error("Agent.request requires a local path that starts with / and is not an absolute URL");
30
+ }
31
+ }
32
+ catch (err) {
33
+ if (err instanceof Error && err.message.includes("absolute URL")) {
34
+ throw err;
35
+ }
36
+ }
37
+ return trimmed;
38
+ }
39
+ function assertRequestMethod(method) {
40
+ if (method === undefined)
41
+ return "GET";
42
+ if (typeof method !== "string") {
43
+ throw new Error("Unsupported HTTP method");
44
+ }
45
+ const normalized = method.trim().toUpperCase();
46
+ if (!/^[A-Z]{1,16}$/.test(normalized)) {
47
+ throw new Error("Unsupported HTTP method");
48
+ }
49
+ return normalized;
50
+ }
10
51
  /**
11
52
  * Web fallback implementation.
12
53
  *
@@ -101,6 +142,27 @@ var capacitorAgent = (function (exports, core) {
101
142
  // No explicit base — use relative URLs (works on http/https origins).
102
143
  return "";
103
144
  }
145
+ isLocalAgentIpcBase() {
146
+ const base = this.apiBase().trim();
147
+ if (!base)
148
+ return false;
149
+ const lower = base.toLowerCase();
150
+ if (lower === "eliza-local-agent://ipc" ||
151
+ lower.startsWith("eliza-local-agent://ipc/") ||
152
+ lower.startsWith("eliza-local-agent://ipc?")) {
153
+ return true;
154
+ }
155
+ try {
156
+ const parsed = new URL(base);
157
+ return (parsed.protocol === "eliza-local-agent:" &&
158
+ (parsed.hostname === "ipc" ||
159
+ parsed.pathname === "//ipc" ||
160
+ parsed.pathname.startsWith("//ipc/")));
161
+ }
162
+ catch {
163
+ return false;
164
+ }
165
+ }
104
166
  apiToken() {
105
167
  const global = typeof window !== "undefined"
106
168
  ? window.__ELIZA_API_TOKEN__
@@ -118,6 +180,8 @@ var capacitorAgent = (function (exports, core) {
118
180
  }
119
181
  /** True when we can reach the API via HTTP. */
120
182
  canReachApi() {
183
+ if (this.isLocalAgentIpcBase())
184
+ return false;
121
185
  const global = typeof window !== "undefined"
122
186
  ? window.__ELIZA_API_BASE__
123
187
  : undefined;
@@ -129,7 +193,7 @@ var capacitorAgent = (function (exports, core) {
129
193
  const proto = window.location.protocol;
130
194
  return proto === "http:" || proto === "https:";
131
195
  }
132
- async start() {
196
+ async start(_options) {
133
197
  if (!this.canReachApi()) {
134
198
  return {
135
199
  state: "not_started",
@@ -172,10 +236,11 @@ var capacitorAgent = (function (exports, core) {
172
236
  return res.json();
173
237
  }
174
238
  async chat(options) {
239
+ const text = assertNonEmptyText(options.text);
175
240
  if (!this.canReachApi()) {
176
241
  return { text: "Agent API not available", agentName: "System" };
177
242
  }
178
- return this.chatViaConversation(options.text);
243
+ return this.chatViaConversation(text);
179
244
  }
180
245
  async getLocalAgentToken() {
181
246
  const token = this.apiToken();
@@ -185,11 +250,21 @@ var capacitorAgent = (function (exports, core) {
185
250
  };
186
251
  }
187
252
  async request(options) {
188
- if (!options.path?.startsWith("/")) {
189
- throw new Error("Agent.request path must start with /");
253
+ const path = assertRequestPath(options.path);
254
+ const method = assertRequestMethod(options.method);
255
+ if (this.isLocalAgentIpcBase()) {
256
+ return {
257
+ status: 503,
258
+ statusText: "Service Unavailable",
259
+ headers: { "content-type": "application/json" },
260
+ body: JSON.stringify({
261
+ error: "native_agent_unavailable",
262
+ message: "Agent web fallback cannot handle eliza-local-agent://ipc; use the native Capacitor Agent plugin",
263
+ }),
264
+ };
190
265
  }
191
- const res = await fetch(`${this.apiBase()}${options.path}`, {
192
- method: options.method ?? "GET",
266
+ const res = await fetch(`${this.apiBase()}${path}`, {
267
+ method,
193
268
  headers: {
194
269
  ...this.authHeaders(),
195
270
  ...options.headers,
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from \"@capacitor/core\";\nexport * from \"./definitions\";\nexport const Agent = registerPlugin(\"Agent\", {\n web: () => import(\"./web\").then((m) => new m.AgentWeb()),\n // Electrobun uses the preload bridge (agent:start, agent:stop, etc.)\n // iOS/Android will use the web fallback (HTTP to API server) for now\n});\n//# sourceMappingURL=index.js.map","import { WebPlugin } from \"@capacitor/core\";\n/**\n * Web fallback implementation.\n *\n * On non-desktop platforms (iOS, Android, web), the agent runtime runs\n * on a server. This implementation delegates to the HTTP API.\n *\n * In Electrobun the desktop bridge calls the native main-process\n * implementation via RPC instead — this web fallback is only used when\n * no native plugin is available. If the page is served from a non-HTTP\n * origin (e.g. electrobun://), relative fetches would hit the\n * app shell HTML, so we bail early.\n *\n * Local-agent-on-Android (Phase E): when the host UI selects the\n * \"Local Agent\" tile, it sets `apiBase` to `http://127.0.0.1:31337`,\n * which the runtime mirrors into `window.__ELIZA_API_BASE__`. From this\n * plugin's perspective there is no special case — it simply HTTP-POSTs\n * to `${apiBase}/api/agent/start|stop|status`, which is exactly the same\n * surface Phase B's `ElizaAgentService` exposes. The web fallback path\n * therefore works unchanged for both remote and on-device agents.\n */\nexport class AgentWeb extends WebPlugin {\n legacyConversationStorageKey() {\n const base = this.apiBase() ||\n (typeof window !== \"undefined\" ? window.location.origin : \"same-origin\");\n return `eliza_agent_web_conversation:${encodeURIComponent(base)}`;\n }\n readLegacyConversationId() {\n if (typeof window === \"undefined\")\n return null;\n const stored = window.sessionStorage.getItem(this.legacyConversationStorageKey());\n return stored?.trim() ? stored.trim() : null;\n }\n writeLegacyConversationId(conversationId) {\n if (typeof window === \"undefined\")\n return;\n const key = this.legacyConversationStorageKey();\n if (conversationId?.trim()) {\n window.sessionStorage.setItem(key, conversationId.trim());\n return;\n }\n window.sessionStorage.removeItem(key);\n }\n async ensureLegacyConversationId() {\n const cached = this.readLegacyConversationId();\n if (cached)\n return cached;\n const res = await fetch(`${this.apiBase()}/api/conversations`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...this.authHeaders(),\n },\n body: JSON.stringify({ title: \"Quick Chat\" }),\n });\n if (!res.ok) {\n throw new Error(`Failed to create conversation: ${res.status}`);\n }\n const data = (await res.json());\n const conversationId = data.conversation?.id?.trim();\n if (!conversationId) {\n throw new Error(\"Conversation create response missing id\");\n }\n this.writeLegacyConversationId(conversationId);\n return conversationId;\n }\n async chatViaConversation(text, retryOnMissingConversation = true) {\n const conversationId = await this.ensureLegacyConversationId();\n // @duplicate-component-audit-allow: agent API message POST; server-side runtime owns model trajectory logging.\n const res = await fetch(`${this.apiBase()}/api/conversations/${encodeURIComponent(conversationId)}/messages`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...this.authHeaders(),\n },\n body: JSON.stringify({ text, channelType: \"DM\" }),\n });\n if (res.status === 404 && retryOnMissingConversation) {\n this.writeLegacyConversationId(null);\n return this.chatViaConversation(text, false);\n }\n if (!res.ok) {\n throw new Error(`Chat request failed: ${res.status}`);\n }\n return res.json();\n }\n apiBase() {\n const global = typeof window !== \"undefined\"\n ? window.__ELIZA_API_BASE__\n : undefined;\n if (typeof global === \"string\" && global.trim().length > 0)\n return global;\n // No explicit base — use relative URLs (works on http/https origins).\n return \"\";\n }\n apiToken() {\n const global = typeof window !== \"undefined\"\n ? window.__ELIZA_API_TOKEN__\n : undefined;\n if (typeof global === \"string\" && global.trim())\n return global.trim();\n if (typeof window === \"undefined\")\n return null;\n const stored = window.sessionStorage.getItem(\"eliza_api_token\");\n return stored?.trim() ? stored.trim() : null;\n }\n authHeaders() {\n const token = this.apiToken();\n return token ? { Authorization: `Bearer ${token}` } : {};\n }\n /** True when we can reach the API via HTTP. */\n canReachApi() {\n const global = typeof window !== \"undefined\"\n ? window.__ELIZA_API_BASE__\n : undefined;\n if (typeof global === \"string\" && global.trim().length > 0)\n return true;\n // No explicit base — relative fetches only work on http(s) origins.\n if (typeof window === \"undefined\")\n return false;\n const proto = window.location.protocol;\n return proto === \"http:\" || proto === \"https:\";\n }\n async start() {\n if (!this.canReachApi()) {\n return {\n state: \"not_started\",\n agentName: null,\n port: null,\n startedAt: null,\n error: \"No API endpoint\",\n };\n }\n const res = await fetch(`${this.apiBase()}/api/agent/start`, {\n method: \"POST\",\n headers: this.authHeaders(),\n });\n const data = await res.json();\n return data.status ?? data;\n }\n async stop() {\n if (!this.canReachApi()) {\n return { ok: false };\n }\n const res = await fetch(`${this.apiBase()}/api/agent/stop`, {\n method: \"POST\",\n headers: this.authHeaders(),\n });\n return res.json();\n }\n async getStatus() {\n if (!this.canReachApi()) {\n return {\n state: \"not_started\",\n agentName: null,\n port: null,\n startedAt: null,\n error: \"No API endpoint\",\n };\n }\n const res = await fetch(`${this.apiBase()}/api/status`, {\n headers: this.authHeaders(),\n });\n return res.json();\n }\n async chat(options) {\n if (!this.canReachApi()) {\n return { text: \"Agent API not available\", agentName: \"System\" };\n }\n return this.chatViaConversation(options.text);\n }\n async getLocalAgentToken() {\n const token = this.apiToken();\n return {\n available: Boolean(token),\n token,\n };\n }\n async request(options) {\n if (!options.path?.startsWith(\"/\")) {\n throw new Error(\"Agent.request path must start with /\");\n }\n const res = await fetch(`${this.apiBase()}${options.path}`, {\n method: options.method ?? \"GET\",\n headers: {\n ...this.authHeaders(),\n ...options.headers,\n },\n body: options.body ?? undefined,\n });\n const headers = {};\n res.headers.forEach((value, key) => {\n headers[key] = value;\n });\n return {\n status: res.status,\n statusText: res.statusText,\n headers,\n body: await res.text(),\n };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AAEY,UAAC,KAAK,GAAGA,mBAAc,CAAC,OAAO,EAAE;IAC7C,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC5D;IACA;IACA,CAAC;;ICLD;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACO,MAAM,QAAQ,SAASC,cAAS,CAAC;IACxC,IAAI,4BAA4B,GAAG;IACnC,QAAQ,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE;IACnC,aAAa,OAAO,MAAM,KAAK,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,aAAa,CAAC;IACpF,QAAQ,OAAO,CAAC,6BAA6B,EAAE,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC;IACzE,IAAI;IACJ,IAAI,wBAAwB,GAAG;IAC/B,QAAQ,IAAI,OAAO,MAAM,KAAK,WAAW;IACzC,YAAY,OAAO,IAAI;IACvB,QAAQ,MAAM,MAAM,GAAG,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,4BAA4B,EAAE,CAAC;IACzF,QAAQ,OAAO,MAAM,EAAE,IAAI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AE;IACpE,YAAY,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,KAAK;IAC3C,YAAY,OAAO,EAAE;IACrB,gBAAgB,GAAG,IAAI,CAAC,WAAW,EAAE;IACrC,gBAAgB,GAAG,OAAO,CAAC,OAAO;IAClC,aAAa;IACb,YAAY,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,SAAS;IAC3C,SAAS,CAAC;IACV,QAAQ,MAAM,OAAO,GAAG,EAAE;IAC1B,QAAQ,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK;IAC5C,YAAY,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK;IAChC,QAAQ,CAAC,CAAC;IACV,QAAQ,OAAO;IACf,YAAY,MAAM,EAAE,GAAG,CAAC,MAAM;IAC9B,YAAY,UAAU,EAAE,GAAG,CAAC,UAAU;IACtC,YAAY,OAAO;IACnB,YAAY,IAAI,EAAE,MAAM,GAAG,CAAC,IAAI,EAAE;IAClC,SAAS;IACT,IAAI;IACJ;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from \"@capacitor/core\";\nexport * from \"./definitions\";\nexport const Agent = registerPlugin(\"Agent\", {\n web: () => import(\"./web\").then((m) => new m.AgentWeb()),\n // Electrobun uses the preload bridge (agent:start, agent:stop, etc.)\n // iOS/Android use the native bridge when registered, otherwise the HTTP web fallback.\n});\n//# sourceMappingURL=index.js.map","import { WebPlugin } from \"@capacitor/core\";\nfunction assertNonEmptyText(text) {\n if (typeof text !== \"string\" || text.trim().length === 0) {\n throw new Error(\"Agent.chat requires non-empty text\");\n }\n return text;\n}\nfunction assertRequestPath(path) {\n if (typeof path !== \"string\" || path.trim().length === 0) {\n throw new Error(\"Agent.request path must start with /\");\n }\n const trimmed = path.trim();\n if (!trimmed.startsWith(\"/\") ||\n trimmed.startsWith(\"//\") ||\n trimmed.includes(\"\\\\\")) {\n throw new Error(\"Agent.request requires a local path that starts with / and is not an absolute URL\");\n }\n try {\n const parsed = new URL(trimmed);\n if (parsed.protocol) {\n throw new Error(\"Agent.request requires a local path that starts with / and is not an absolute URL\");\n }\n }\n catch (err) {\n if (err instanceof Error && err.message.includes(\"absolute URL\")) {\n throw err;\n }\n }\n return trimmed;\n}\nfunction assertRequestMethod(method) {\n if (method === undefined)\n return \"GET\";\n if (typeof method !== \"string\") {\n throw new Error(\"Unsupported HTTP method\");\n }\n const normalized = method.trim().toUpperCase();\n if (!/^[A-Z]{1,16}$/.test(normalized)) {\n throw new Error(\"Unsupported HTTP method\");\n }\n return normalized;\n}\n/**\n * Web fallback implementation.\n *\n * On non-desktop platforms (iOS, Android, web), the agent runtime runs\n * on a server. This implementation delegates to the HTTP API.\n *\n * In Electrobun the desktop bridge calls the native main-process\n * implementation via RPC instead — this web fallback is only used when\n * no native plugin is available. If the page is served from a non-HTTP\n * origin (e.g. electrobun://), relative fetches would hit the\n * app shell HTML, so we bail early.\n *\n * Local-agent-on-Android (Phase E): when the host UI selects the\n * \"Local Agent\" tile, it sets `apiBase` to `http://127.0.0.1:31337`,\n * which the runtime mirrors into `window.__ELIZA_API_BASE__`. From this\n * plugin's perspective there is no special case — it simply HTTP-POSTs\n * to `${apiBase}/api/agent/start|stop|status`, which is exactly the same\n * surface Phase B's `ElizaAgentService` exposes. The web fallback path\n * therefore works unchanged for both remote and on-device agents.\n */\nexport class AgentWeb extends WebPlugin {\n legacyConversationStorageKey() {\n const base = this.apiBase() ||\n (typeof window !== \"undefined\" ? window.location.origin : \"same-origin\");\n return `eliza_agent_web_conversation:${encodeURIComponent(base)}`;\n }\n readLegacyConversationId() {\n if (typeof window === \"undefined\")\n return null;\n const stored = window.sessionStorage.getItem(this.legacyConversationStorageKey());\n return stored?.trim() ? stored.trim() : null;\n }\n writeLegacyConversationId(conversationId) {\n if (typeof window === \"undefined\")\n return;\n const key = this.legacyConversationStorageKey();\n if (conversationId?.trim()) {\n window.sessionStorage.setItem(key, conversationId.trim());\n return;\n }\n window.sessionStorage.removeItem(key);\n }\n async ensureLegacyConversationId() {\n const cached = this.readLegacyConversationId();\n if (cached)\n return cached;\n const res = await fetch(`${this.apiBase()}/api/conversations`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...this.authHeaders(),\n },\n body: JSON.stringify({ title: \"Quick Chat\" }),\n });\n if (!res.ok) {\n throw new Error(`Failed to create conversation: ${res.status}`);\n }\n const data = (await res.json());\n const conversationId = data.conversation?.id?.trim();\n if (!conversationId) {\n throw new Error(\"Conversation create response missing id\");\n }\n this.writeLegacyConversationId(conversationId);\n return conversationId;\n }\n async chatViaConversation(text, retryOnMissingConversation = true) {\n const conversationId = await this.ensureLegacyConversationId();\n // @duplicate-component-audit-allow: agent API message POST; server-side runtime owns model trajectory logging.\n const res = await fetch(`${this.apiBase()}/api/conversations/${encodeURIComponent(conversationId)}/messages`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...this.authHeaders(),\n },\n body: JSON.stringify({ text, channelType: \"DM\" }),\n });\n if (res.status === 404 && retryOnMissingConversation) {\n this.writeLegacyConversationId(null);\n return this.chatViaConversation(text, false);\n }\n if (!res.ok) {\n throw new Error(`Chat request failed: ${res.status}`);\n }\n return res.json();\n }\n apiBase() {\n const global = typeof window !== \"undefined\"\n ? window.__ELIZA_API_BASE__\n : undefined;\n if (typeof global === \"string\" && global.trim().length > 0)\n return global;\n // No explicit base — use relative URLs (works on http/https origins).\n return \"\";\n }\n isLocalAgentIpcBase() {\n const base = this.apiBase().trim();\n if (!base)\n return false;\n const lower = base.toLowerCase();\n if (lower === \"eliza-local-agent://ipc\" ||\n lower.startsWith(\"eliza-local-agent://ipc/\") ||\n lower.startsWith(\"eliza-local-agent://ipc?\")) {\n return true;\n }\n try {\n const parsed = new URL(base);\n return (parsed.protocol === \"eliza-local-agent:\" &&\n (parsed.hostname === \"ipc\" ||\n parsed.pathname === \"//ipc\" ||\n parsed.pathname.startsWith(\"//ipc/\")));\n }\n catch {\n return false;\n }\n }\n apiToken() {\n const global = typeof window !== \"undefined\"\n ? window.__ELIZA_API_TOKEN__\n : undefined;\n if (typeof global === \"string\" && global.trim())\n return global.trim();\n if (typeof window === \"undefined\")\n return null;\n const stored = window.sessionStorage.getItem(\"eliza_api_token\");\n return stored?.trim() ? stored.trim() : null;\n }\n authHeaders() {\n const token = this.apiToken();\n return token ? { Authorization: `Bearer ${token}` } : {};\n }\n /** True when we can reach the API via HTTP. */\n canReachApi() {\n if (this.isLocalAgentIpcBase())\n return false;\n const global = typeof window !== \"undefined\"\n ? window.__ELIZA_API_BASE__\n : undefined;\n if (typeof global === \"string\" && global.trim().length > 0)\n return true;\n // No explicit base — relative fetches only work on http(s) origins.\n if (typeof window === \"undefined\")\n return false;\n const proto = window.location.protocol;\n return proto === \"http:\" || proto === \"https:\";\n }\n async start(_options) {\n if (!this.canReachApi()) {\n return {\n state: \"not_started\",\n agentName: null,\n port: null,\n startedAt: null,\n error: \"No API endpoint\",\n };\n }\n const res = await fetch(`${this.apiBase()}/api/agent/start`, {\n method: \"POST\",\n headers: this.authHeaders(),\n });\n const data = await res.json();\n return data.status ?? data;\n }\n async stop() {\n if (!this.canReachApi()) {\n return { ok: false };\n }\n const res = await fetch(`${this.apiBase()}/api/agent/stop`, {\n method: \"POST\",\n headers: this.authHeaders(),\n });\n return res.json();\n }\n async getStatus() {\n if (!this.canReachApi()) {\n return {\n state: \"not_started\",\n agentName: null,\n port: null,\n startedAt: null,\n error: \"No API endpoint\",\n };\n }\n const res = await fetch(`${this.apiBase()}/api/status`, {\n headers: this.authHeaders(),\n });\n return res.json();\n }\n async chat(options) {\n const text = assertNonEmptyText(options.text);\n if (!this.canReachApi()) {\n return { text: \"Agent API not available\", agentName: \"System\" };\n }\n return this.chatViaConversation(text);\n }\n async getLocalAgentToken() {\n const token = this.apiToken();\n return {\n available: Boolean(token),\n token,\n };\n }\n async request(options) {\n const path = assertRequestPath(options.path);\n const method = assertRequestMethod(options.method);\n if (this.isLocalAgentIpcBase()) {\n return {\n status: 503,\n statusText: \"Service Unavailable\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({\n error: \"native_agent_unavailable\",\n message: \"Agent web fallback cannot handle eliza-local-agent://ipc; use the native Capacitor Agent plugin\",\n }),\n };\n }\n const res = await fetch(`${this.apiBase()}${path}`, {\n method,\n headers: {\n ...this.authHeaders(),\n ...options.headers,\n },\n body: options.body ?? undefined,\n });\n const headers = {};\n res.headers.forEach((value, key) => {\n headers[key] = value;\n });\n return {\n status: res.status,\n statusText: res.statusText,\n headers,\n body: await res.text(),\n };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AAEY,UAAC,KAAK,GAAGA,mBAAc,CAAC,OAAO,EAAE;IAC7C,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC5D;IACA;IACA,CAAC;;ICLD,SAAS,kBAAkB,CAAC,IAAI,EAAE;IAClC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE;IAC9D,QAAQ,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC;IAC7D,IAAI;IACJ,IAAI,OAAO,IAAI;IACf;IACA,SAAS,iBAAiB,CAAC,IAAI,EAAE;IACjC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE;IAC9D,QAAQ,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC;IAC/D,IAAI;IACJ,IAAI,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE;IAC/B,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC;IAChC,QAAQ,OAAO,CAAC,UAA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