@oya-ai/browser 1.0.295 → 1.0.298

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/index.cjs CHANGED
@@ -188,9 +188,9 @@ var Http = class _Http {
188
188
  return new _Http(this.baseUrl, this.apiKey, this.timeoutMs, this.fetchImpl, this.origin, merged);
189
189
  }
190
190
  /** Sends one request and returns the parsed answer, or throws an OyaError when it failed. */
191
- async request(method, path, body, timeoutMs = this.timeoutMs, headers = {}) {
192
- const res = await this.send(`${this.baseUrl}${path}`, this.init(method, body, timeoutMs, headers), timeoutMs);
193
- return readAnswer(res, `${method} ${path}`, this);
191
+ async request(method, path2, body, timeoutMs = this.timeoutMs, headers = {}) {
192
+ const res = await this.send(`${this.baseUrl}${path2}`, this.init(method, body, timeoutMs, headers), timeoutMs);
193
+ return readAnswer(res, `${method} ${path2}`, this);
194
194
  }
195
195
  /** The fetch options for one call, with this client's key on them. */
196
196
  init(method, body, timeoutMs, headers) {
@@ -464,8 +464,8 @@ var Browser = class {
464
464
  http;
465
465
  /** Runs one browser command; a command that ran and failed throws. */
466
466
  async command(action, params = {}, timeoutMs) {
467
- const path = `/api/browsers/${segment(this.id)}/command`;
468
- const result = await this.http.request("POST", path, { action, params }, timeoutMs);
467
+ const path2 = `/api/browsers/${segment(this.id)}/command`;
468
+ const result = await this.http.request("POST", path2, { action, params }, timeoutMs);
469
469
  if (result.ok === false) throw new OyaError(result.error || `${action} failed`, Status.UNPROCESSABLE, result);
470
470
  return result.data;
471
471
  }
@@ -577,8 +577,8 @@ var Browser = class {
577
577
  */
578
578
  async ask(prompt, { data, secrets } = {}) {
579
579
  const body = { messages: [{ role: "user", content: prompt }], data, secrets };
580
- const path = `/api/browsers/${segment(this.id)}/chat`;
581
- return agentAnswer(await this.http.request("POST", path, body, AGENT_TIMEOUT_MS)).text;
580
+ const path2 = `/api/browsers/${segment(this.id)}/chat`;
581
+ return agentAnswer(await this.http.request("POST", path2, body, AGENT_TIMEOUT_MS)).text;
582
582
  }
583
583
  /**
584
584
  * `ask()` for data: the agent does the task and answers in the shape of `schema`
@@ -586,8 +586,8 @@ var Browser = class {
586
586
  */
587
587
  async extract(prompt, schema, values = {}) {
588
588
  const body = { messages: [{ role: "user", content: prompt }], ...values, schema };
589
- const path = `/api/browsers/${segment(this.id)}/chat`;
590
- const res = agentAnswer(await this.http.request("POST", path, body, AGENT_TIMEOUT_MS));
589
+ const path2 = `/api/browsers/${segment(this.id)}/chat`;
590
+ const res = agentAnswer(await this.http.request("POST", path2, body, AGENT_TIMEOUT_MS));
591
591
  if (res.failed || res.data === void 0) throw new OyaError(res.text, Status.UNPROCESSABLE, res);
592
592
  return res.data;
593
593
  }
@@ -612,9 +612,9 @@ var Browser = class {
612
612
  * replaces the broken steps in the playbook (`healed`); off, the step's error is thrown.
613
613
  */
614
614
  async play(name, data = {}, { autoHeal = true } = {}) {
615
- const path = `/api/browsers/${segment(this.id)}/playbooks/${segment(name, "name")}/play`;
615
+ const path2 = `/api/browsers/${segment(this.id)}/playbooks/${segment(name, "name")}/play`;
616
616
  return agentAnswer(
617
- await this.http.request("POST", path, { variables: data, autoHeal }, AGENT_TIMEOUT_MS)
617
+ await this.http.request("POST", path2, { variables: data, autoHeal }, AGENT_TIMEOUT_MS)
618
618
  );
619
619
  }
620
620
  /**
@@ -644,8 +644,8 @@ var Browser = class {
644
644
  * 60 seconds. Mint one per viewer, the first connection spends it.
645
645
  */
646
646
  async liveStreamUrl() {
647
- const path = `/api/control/sessions/${segment(this.id)}/ticket`;
648
- const { ticket } = await this.http.request("POST", path, {});
647
+ const path2 = `/api/control/sessions/${segment(this.id)}/ticket`;
648
+ const { ticket } = await this.http.request("POST", path2, {});
649
649
  return `${this.http.baseUrl}/api/live/${segment(this.id)}?ticket=${encodeURIComponent(ticket)}`;
650
650
  }
651
651
  /**
@@ -660,8 +660,8 @@ var Browser = class {
660
660
  * expires or you revoke it, so treat it like a password.
661
661
  */
662
662
  async shareUrl({ control = false, expiresInSeconds = 3600 } = {}) {
663
- const path = `/api/control/sessions/${segment(this.id)}/share`;
664
- const c = await this.http.request("POST", path, { control, expiresIn: expiresInSeconds });
663
+ const path2 = `/api/control/sessions/${segment(this.id)}/share`;
664
+ const c = await this.http.request("POST", path2, { control, expiresIn: expiresInSeconds });
665
665
  return { url: shareLink(this.http.baseUrl, this.id, c.token), id: c.id, expiresAt: c.expiresAt };
666
666
  }
667
667
  /** Revoke a link from `shareUrl()` before it expires, by the id it returned. */
@@ -735,8 +735,8 @@ function startBody(options) {
735
735
  var idempotencyKeyOf = ({ idempotencyKey }) => idempotencyKey ? headerSafe(idempotencyKey, "idempotencyKey", 'Use letters, digits, "-" and "_".') : globalThis.crypto.randomUUID();
736
736
  async function start(http, wait, options) {
737
737
  const headers = { "Idempotency-Key": idempotencyKeyOf(options) };
738
- const path = "/api/browsers/start";
739
- const started = await http().request("POST", path, startBody(options), START_TIMEOUT_MS, headers);
738
+ const path2 = "/api/browsers/start";
739
+ const started = await http().request("POST", path2, startBody(options), START_TIMEOUT_MS, headers);
740
740
  if (started.status === "starting") {
741
741
  await wait(started.id, options.readyTimeoutMs ?? READY_TIMEOUT_MS + (options.queueMs || 0));
742
742
  started.cdpUrl = (await fetchBrowser(http, started.id)).cdpUrl;
@@ -978,6 +978,62 @@ var personaGroupApi = (http) => ({
978
978
  }
979
979
  });
980
980
 
981
+ // src/api/assistants.ts
982
+ var path = (id) => "/api/assistants/" + segment(id, "assistant ID");
983
+ var gateways = (http) => ({
984
+ /** Request device pairing. */
985
+ connectWhatsApp: (id) => http().request("POST", path(id) + "/whatsapp"),
986
+ /** Read the currently active pairing code or connection status. */
987
+ whatsAppStatus: (id) => http().request("GET", path(id) + "/whatsapp"),
988
+ /** Stop handling incoming messages and erase local WhatsApp credentials. */
989
+ disconnectWhatsApp: (id) => http().request("DELETE", path(id) + "/whatsapp"),
990
+ /** Rotate the key accepted by the assistant webhook. */
991
+ rotateInboundKey: (id) => http().request("POST", path(id) + "/inbound-key")
992
+ });
993
+ var skills = (http) => ({
994
+ /** List available reusable instructions. */
995
+ listSkills: async () => (await http().request("GET", "/api/assistants")).skills,
996
+ /** Permanently remove a project skill and detach it from every assistant. */
997
+ deleteSkill: (id) => http().request("DELETE", "/api/assistants/skills/" + segment(id, "skill ID")),
998
+ /** Save instructions once for several assistants. */
999
+ createSkill: (body) => http().request("POST", "/api/assistants/skills", body)
1000
+ });
1001
+ var definitions = (http) => ({
1002
+ /** Discover definitions in this project. */
1003
+ list: async () => (await http().request("GET", "/api/assistants")).assistants,
1004
+ /** Save a new assistant. */
1005
+ create: (body) => http().request("POST", "/api/assistants", body),
1006
+ /** Change the instructions for future turns. */
1007
+ update: (id, body) => http().request("PUT", path(id), body),
1008
+ /** Change one assistant's model without interrupting its device or contact memory. */
1009
+ setModel: (id, model) => http().request("PATCH", path(id) + "/model", { model }),
1010
+ /** Remove this assistant and its messages. */
1011
+ remove: (id) => http().request("DELETE", path(id))
1012
+ });
1013
+ var programs = (http) => ({
1014
+ /** Load a saved program and its revision. */
1015
+ getProgram: (id) => http().request("GET", path(id) + "/program"),
1016
+ /** Replace a program if its revision is still current. */
1017
+ saveProgram: (id, body) => http().request("PUT", path(id) + "/program", body),
1018
+ /** Preview a draft without delivering a message. */
1019
+ testProgram: (id, body) => http().request("POST", path(id) + "/program/test", body)
1020
+ });
1021
+ var conversations = (http) => ({
1022
+ /** Submit a contact message for asynchronous processing. */
1023
+ send: (id, body) => http().request("POST", path(id) + "/messages", body),
1024
+ /** Read the original receipt and latest response. */
1025
+ message: (id, messageId) => http().request("GET", path(id) + "/messages/" + segment(messageId, "message ID")),
1026
+ /** Erase a contact's conversation. */
1027
+ forget: (id, contact) => http().request("DELETE", path(id) + "/contacts/" + segment(contact, "contact"))
1028
+ });
1029
+ var assistantApi = (http) => ({
1030
+ ...definitions(http),
1031
+ ...skills(http),
1032
+ ...programs(http),
1033
+ ...conversations(http),
1034
+ ...gateways(http)
1035
+ });
1036
+
981
1037
  // src/api/config.ts
982
1038
  var configApi = (http) => ({
983
1039
  /** This key's settings. Secrets read back masked. */
@@ -1136,13 +1192,13 @@ var base64 = (bytes) => {
1136
1192
  }
1137
1193
  return btoa(binary);
1138
1194
  };
1139
- async function readPath(path) {
1195
+ async function readPath(path2) {
1140
1196
  const fs = await import(
1141
1197
  /* webpackIgnore: true */
1142
1198
  /* @vite-ignore */
1143
1199
  NODE_FS
1144
1200
  );
1145
- return { bytes: new Uint8Array(await fs.readFile(path)), name: path.split(/[\\/]/).pop() || "file" };
1201
+ return { bytes: new Uint8Array(await fs.readFile(path2)), name: path2.split(/[\\/]/).pop() || "file" };
1146
1202
  }
1147
1203
  async function readSource(source) {
1148
1204
  if (typeof source === "string") return readPath(source);
@@ -1227,6 +1283,8 @@ var Oya = class {
1227
1283
  personaGroups = personaGroupApi(() => this.http);
1228
1284
  /** The same as `personaGroups`, matching the `profiles` alias. */
1229
1285
  profileGroups = this.personaGroups;
1286
+ /** Build and message project-owned hosted assistants. */
1287
+ assistants = assistantApi(() => this.http);
1230
1288
  /** What this key has spent. */
1231
1289
  usage() {
1232
1290
  return this.http.request("GET", "/api/usage");
package/dist/index.d.cts CHANGED
@@ -1,3 +1,60 @@
1
+ /** Typed authoring contracts for an assistant's event functions and callable tools. */
2
+ type AssistantEvent = 'contact.first_seen' | 'turn.started' | 'message.received' | 'reply.prepared' | 'turn.completed' | 'turn.failed' | 'model.started' | 'model.succeeded' | 'model.failed' | 'browser.started' | 'browser.succeeded' | 'browser.failed' | 'tool.started' | 'tool.succeeded' | 'tool.failed' | 'workflow.started' | 'workflow.succeeded' | 'workflow.failed' | 'workflow.step.started' | 'workflow.step.succeeded' | 'workflow.step.failed' | 'whatsapp.connected' | 'whatsapp.disconnected' | 'whatsapp.reply.queued' | 'whatsapp.reply.submitted' | 'whatsapp.delivery.uncertain';
3
+ /** Required fields shared by functions and workflows offered to the model. */
4
+ interface ToolDefinition {
5
+ /** Stable model-facing identifier. */ name: string;
6
+ /** When to call this tool. */ description: string;
7
+ /** Named string arguments. */ inputs: string[];
8
+ }
9
+ /** A synchronous JavaScript body or an ordered sequence of named functions. */
10
+ type AssistantTool = ToolDefinition & ({
11
+ /** Selects the execution contract. */ kind: 'function';
12
+ /** Synchronous JavaScript body evaluated in isolation. */ code: string;
13
+ } | {
14
+ /** Selects the execution contract. */ kind: 'workflow';
15
+ /** Ordered function calls in this workflow. */ steps: {
16
+ /** Named function or workflow selected for execution. */ tool: string;
17
+ /** Select original arguments, the previous result, or a one-based index of an earlier step. */ from: 'input' | 'previous' | number;
18
+ }[];
19
+ });
20
+ /** Self-contained program saved independently of the persona and device. */
21
+ interface AssistantProgram {
22
+ /** JavaScript handlers keyed by lifecycle event. */ events: Partial<Record<AssistantEvent, string>>;
23
+ /** Definitions offered to the model. */ tools: AssistantTool[];
24
+ }
25
+ /** Compare-and-swap revision used to protect concurrent edits. */
26
+ interface AssistantProgramRevision {
27
+ /** Discoverable event contracts with safe sample payloads. */ eventCatalog?: {
28
+ /** Stable runtime event identifier. */ name: AssistantEvent;
29
+ /** Picker label for this event. */ label: string;
30
+ /** Lifecycle stage shown in the picker. */ group: string;
31
+ /** Boundary that dispatches the event. */ when: string;
32
+ /** Example JSON payload for a draft test. */ sample: object;
33
+ /** Return contract enforced at runtime. */ help: string;
34
+ /** Suggested JavaScript function body. */ code: string;
35
+ }[];
36
+ /** Assistant-owned events and callable tools. */ program: AssistantProgram;
37
+ /** Saved version required for a conditional write. */ revision: number;
38
+ }
39
+ /** Results are visible only to the project running this explicit draft test. */
40
+ interface ProgramPreview {
41
+ /** Whether the sample completed successfully. */ ok: boolean;
42
+ /** JSON value returned by execution. */ output?: unknown;
43
+ /** Builder-facing failure detail when execution fails. */ error?: string;
44
+ /** Steps observed during this execution. */ trace: {
45
+ /** Display or callable name used to identify this entry. */ name: string;
46
+ /** Lines printed by this step during an explicit draft test. */ logs?: string[];
47
+ /** Outcome recorded for this step. */ status: 'completed' | 'failed' | 'skipped' | 'handler failed';
48
+ /** Workflow owning an execution step. */ workflow?: string;
49
+ /** One-based step position. */ step?: number;
50
+ /** Function implementing this step. */ tool?: string;
51
+ /** Safe failure category. */ reason?: string;
52
+ /** Bounded sample arguments seen by this step during a draft test. */ input?: unknown;
53
+ /** JSON value returned by execution. */ output?: unknown;
54
+ /** Builder-facing failure detail when execution fails. */ error?: string;
55
+ }[];
56
+ }
57
+
1
58
  /**
2
59
  * Types for browsers themselves: starting one, what a page looks like to the
3
60
  * SDK, the results of CAPTCHA and MFA handling, and the fleet listing.
@@ -1264,6 +1321,82 @@ interface CookiesImported {
1264
1321
  total: number;
1265
1322
  }
1266
1323
 
1324
+ /** Managed assistant definitions and durable conversational messages for a project's backend. */
1325
+
1326
+ /** Instructions and display name chosen by the builder. */
1327
+ interface AssistantDefinition {
1328
+ /** Optional device preset for fresh, signed-out browsers. */ browserProfileId?: string | null;
1329
+ /** Project-owned skills to apply when replying. */ skillIds?: string[];
1330
+ /** Enabled first-party plugins. */ plugins?: 'public-web'[];
1331
+ /** Apps enabled for the assistant. */ connections?: ('googlecalendar' | 'hackernews' | 'jira' | 'clickup' | 'linkedin' | 'facebook' | 'gmail' | 'slack' | 'googledrive' | 'googlesheets')[];
1332
+ /** Pin a supported project model or inherit the default. */
1333
+ model?: {
1334
+ provider: string; /** Model identifier. */
1335
+ model: string;
1336
+ } | null;
1337
+ /** Public name for this assistant. */
1338
+ name: string;
1339
+ /** Builder's behavior and tone instructions. */
1340
+ instructions: string;
1341
+ }
1342
+ /** Saved project-scoped assistant. */
1343
+ interface Assistant extends AssistantDefinition {
1344
+ /** Stable assistant identifier. */
1345
+ id: string;
1346
+ }
1347
+ /** A durable receipt, including the saved reply after completion. */
1348
+ interface AssistantMessage {
1349
+ /** Server-generated ID for polling. */
1350
+ id: string;
1351
+ /** Current status of the turn. */
1352
+ state: 'queued' | 'running' | 'completed' | 'failed';
1353
+ /** Original message. */
1354
+ text: string;
1355
+ /** Saved response after completion. */
1356
+ reply?: string | null;
1357
+ /** A private terminal observer is still updating the receipt. */ tracePending?: boolean;
1358
+ /** Execution metadata present only on private dashboard test receipts. */
1359
+ trace?: {
1360
+ /** Lifecycle name or registered tool. */ name: string;
1361
+ /** Operation or observer result. */ status: string;
1362
+ /** Workflow that owns the step. */ workflow?: string;
1363
+ /** One-based step position. */ step?: number;
1364
+ /** Registered function name. */ tool?: string;
1365
+ /** Safe failure category. */ reason?: string;
1366
+ }[];
1367
+ /** WhatsApp transport status after a reply is saved. */
1368
+ delivery?: 'queued' | 'unknown' | 'submitted';
1369
+ }
1370
+ /** Stable retry key and contact identity are supplied by the builder's backend. */
1371
+ interface AssistantInput {
1372
+ /** Unique per contact, reused on transport retry. */
1373
+ messageId: string;
1374
+ /** Contact identifier local to this assistant. */
1375
+ contact: string;
1376
+ /** Incoming text. */
1377
+ text: string;
1378
+ }
1379
+ /** A linked-device enrollment, including the current QR material when requested by an administrator. */
1380
+ interface WhatsAppDevice {
1381
+ /** Pairing or connection status. */
1382
+ state: string;
1383
+ /** Short-lived pairing material. */
1384
+ qr: string | null;
1385
+ }
1386
+ /** Reusable instructions owned by a project. */
1387
+ interface AssistantSkill {
1388
+ /** Assignment identity. */ id: string;
1389
+ /** Builder-selected name. */ name: string;
1390
+ /** Private instructions. */ instructions: string;
1391
+ }
1392
+ /** Explicit sample input for one draft event or tool. */
1393
+ interface AssistantSampleRequest {
1394
+ /** Assistant-owned events and callable tools. */ program: AssistantProgram;
1395
+ /** Selects the execution contract. */ kind: 'event' | 'tool';
1396
+ /** Display or callable name used to identify this entry. */ name: string;
1397
+ /** JSON arguments supplied to the selected function. */ input: unknown;
1398
+ }
1399
+
1267
1400
  /**
1268
1401
  * The shapes Browser's methods take and return that are not part of the
1269
1402
  * exported types: tab listings, dialog answers, share links and the like.
@@ -1689,6 +1822,29 @@ declare class Oya {
1689
1822
  update: (name: string, personaIds: string[]) => Promise<PersonaGroup>;
1690
1823
  remove: (name: string) => Promise<void>;
1691
1824
  };
1825
+ /** Build and message project-owned hosted assistants. */
1826
+ readonly assistants: {
1827
+ connectWhatsApp: (id: string) => Promise<WhatsAppDevice>;
1828
+ whatsAppStatus: (id: string) => Promise<WhatsAppDevice>;
1829
+ disconnectWhatsApp: (id: string) => Promise<void>;
1830
+ rotateInboundKey: (id: string) => Promise<{
1831
+ secret: string;
1832
+ }>;
1833
+ send: (id: string, body: AssistantInput) => Promise<AssistantMessage>;
1834
+ message: (id: string, messageId: string) => Promise<AssistantMessage>;
1835
+ forget: (id: string, contact: string) => Promise<void>;
1836
+ getProgram: (id: string) => Promise<AssistantProgramRevision>;
1837
+ saveProgram: (id: string, body: AssistantProgramRevision) => Promise<AssistantProgramRevision>;
1838
+ testProgram: (id: string, body: AssistantSampleRequest) => Promise<ProgramPreview>;
1839
+ listSkills: () => Promise<AssistantSkill[]>;
1840
+ deleteSkill: (id: string) => Promise<void>;
1841
+ createSkill: (body: Omit<AssistantSkill, "id">) => Promise<AssistantSkill>;
1842
+ list: () => Promise<Assistant[]>;
1843
+ create: (body: AssistantDefinition) => Promise<Assistant>;
1844
+ update: (id: string, body: AssistantDefinition) => Promise<Assistant>;
1845
+ setModel: (id: string, model: NonNullable<AssistantDefinition["model"]> | null) => Promise<Assistant>;
1846
+ remove: (id: string) => Promise<void>;
1847
+ };
1692
1848
  /** What this key has spent. */
1693
1849
  usage(): Promise<unknown>;
1694
1850
  /** Waits for a starting browser to dial in, through this client's own list and session calls. */
@@ -1696,4 +1852,4 @@ declare class Oya {
1696
1852
  }
1697
1853
 
1698
1854
  export { Browser, MAX_FILE_BYTES, Oya, OyaError, Run, Oya as default, file };
1699
- export type { Activity, Analysis, AnalyzeOptions, AttentionRequest, Block, BrowserDetail, BrowserInfo, CaptchaResult, CaptchaSolver, Config, ConfigUpdate, ControlCredential, ControlEvent, ControlOverview, ControlRole, ControlSession, Cookie, CookieFormat, DesktopOptions, EcsAuth, EcsConfig, Element, FileValue, Fingerprint, Health, HumanInputAction, ImportOptions, LlmCatalogEntry, LlmProvider, MfaConfig, MfaResult, ModelOptions, OyaOptions, PageFormat, PersonaGroup, PersonaInfo, PersonaPrefs, PlayResult, Playbook, PlaybookAnswer, PlaybookExport, PlaybookSummary, ProjectSettings, Provider, ProxyCreate, ProxyInfo, RecoverOptions, RunData, RunInfo, RunResult, SandboxRuntime, Signup, SignupOptions, SiteCredentials, StartOptions, StartResult, StopResult, SubmitOptions };
1855
+ export type { Activity, Analysis, AnalyzeOptions, Assistant, AssistantDefinition, AssistantEvent, AssistantInput, AssistantMessage, AssistantProgram, AssistantProgramRevision, AssistantSampleRequest, AssistantSkill, AssistantTool, AttentionRequest, Block, BrowserDetail, BrowserInfo, CaptchaResult, CaptchaSolver, Config, ConfigUpdate, ControlCredential, ControlEvent, ControlOverview, ControlRole, ControlSession, Cookie, CookieFormat, DesktopOptions, EcsAuth, EcsConfig, Element, FileValue, Fingerprint, Health, HumanInputAction, ImportOptions, LlmCatalogEntry, LlmProvider, MfaConfig, MfaResult, ModelOptions, OyaOptions, PageFormat, PersonaGroup, PersonaInfo, PersonaPrefs, PlayResult, Playbook, PlaybookAnswer, PlaybookExport, PlaybookSummary, ProgramPreview, ProjectSettings, Provider, ProxyCreate, ProxyInfo, RecoverOptions, RunData, RunInfo, RunResult, SandboxRuntime, Signup, SignupOptions, SiteCredentials, StartOptions, StartResult, StopResult, SubmitOptions };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,60 @@
1
+ /** Typed authoring contracts for an assistant's event functions and callable tools. */
2
+ type AssistantEvent = 'contact.first_seen' | 'turn.started' | 'message.received' | 'reply.prepared' | 'turn.completed' | 'turn.failed' | 'model.started' | 'model.succeeded' | 'model.failed' | 'browser.started' | 'browser.succeeded' | 'browser.failed' | 'tool.started' | 'tool.succeeded' | 'tool.failed' | 'workflow.started' | 'workflow.succeeded' | 'workflow.failed' | 'workflow.step.started' | 'workflow.step.succeeded' | 'workflow.step.failed' | 'whatsapp.connected' | 'whatsapp.disconnected' | 'whatsapp.reply.queued' | 'whatsapp.reply.submitted' | 'whatsapp.delivery.uncertain';
3
+ /** Required fields shared by functions and workflows offered to the model. */
4
+ interface ToolDefinition {
5
+ /** Stable model-facing identifier. */ name: string;
6
+ /** When to call this tool. */ description: string;
7
+ /** Named string arguments. */ inputs: string[];
8
+ }
9
+ /** A synchronous JavaScript body or an ordered sequence of named functions. */
10
+ type AssistantTool = ToolDefinition & ({
11
+ /** Selects the execution contract. */ kind: 'function';
12
+ /** Synchronous JavaScript body evaluated in isolation. */ code: string;
13
+ } | {
14
+ /** Selects the execution contract. */ kind: 'workflow';
15
+ /** Ordered function calls in this workflow. */ steps: {
16
+ /** Named function or workflow selected for execution. */ tool: string;
17
+ /** Select original arguments, the previous result, or a one-based index of an earlier step. */ from: 'input' | 'previous' | number;
18
+ }[];
19
+ });
20
+ /** Self-contained program saved independently of the persona and device. */
21
+ interface AssistantProgram {
22
+ /** JavaScript handlers keyed by lifecycle event. */ events: Partial<Record<AssistantEvent, string>>;
23
+ /** Definitions offered to the model. */ tools: AssistantTool[];
24
+ }
25
+ /** Compare-and-swap revision used to protect concurrent edits. */
26
+ interface AssistantProgramRevision {
27
+ /** Discoverable event contracts with safe sample payloads. */ eventCatalog?: {
28
+ /** Stable runtime event identifier. */ name: AssistantEvent;
29
+ /** Picker label for this event. */ label: string;
30
+ /** Lifecycle stage shown in the picker. */ group: string;
31
+ /** Boundary that dispatches the event. */ when: string;
32
+ /** Example JSON payload for a draft test. */ sample: object;
33
+ /** Return contract enforced at runtime. */ help: string;
34
+ /** Suggested JavaScript function body. */ code: string;
35
+ }[];
36
+ /** Assistant-owned events and callable tools. */ program: AssistantProgram;
37
+ /** Saved version required for a conditional write. */ revision: number;
38
+ }
39
+ /** Results are visible only to the project running this explicit draft test. */
40
+ interface ProgramPreview {
41
+ /** Whether the sample completed successfully. */ ok: boolean;
42
+ /** JSON value returned by execution. */ output?: unknown;
43
+ /** Builder-facing failure detail when execution fails. */ error?: string;
44
+ /** Steps observed during this execution. */ trace: {
45
+ /** Display or callable name used to identify this entry. */ name: string;
46
+ /** Lines printed by this step during an explicit draft test. */ logs?: string[];
47
+ /** Outcome recorded for this step. */ status: 'completed' | 'failed' | 'skipped' | 'handler failed';
48
+ /** Workflow owning an execution step. */ workflow?: string;
49
+ /** One-based step position. */ step?: number;
50
+ /** Function implementing this step. */ tool?: string;
51
+ /** Safe failure category. */ reason?: string;
52
+ /** Bounded sample arguments seen by this step during a draft test. */ input?: unknown;
53
+ /** JSON value returned by execution. */ output?: unknown;
54
+ /** Builder-facing failure detail when execution fails. */ error?: string;
55
+ }[];
56
+ }
57
+
1
58
  /**
2
59
  * Types for browsers themselves: starting one, what a page looks like to the
3
60
  * SDK, the results of CAPTCHA and MFA handling, and the fleet listing.
@@ -1264,6 +1321,82 @@ interface CookiesImported {
1264
1321
  total: number;
1265
1322
  }
1266
1323
 
1324
+ /** Managed assistant definitions and durable conversational messages for a project's backend. */
1325
+
1326
+ /** Instructions and display name chosen by the builder. */
1327
+ interface AssistantDefinition {
1328
+ /** Optional device preset for fresh, signed-out browsers. */ browserProfileId?: string | null;
1329
+ /** Project-owned skills to apply when replying. */ skillIds?: string[];
1330
+ /** Enabled first-party plugins. */ plugins?: 'public-web'[];
1331
+ /** Apps enabled for the assistant. */ connections?: ('googlecalendar' | 'hackernews' | 'jira' | 'clickup' | 'linkedin' | 'facebook' | 'gmail' | 'slack' | 'googledrive' | 'googlesheets')[];
1332
+ /** Pin a supported project model or inherit the default. */
1333
+ model?: {
1334
+ provider: string; /** Model identifier. */
1335
+ model: string;
1336
+ } | null;
1337
+ /** Public name for this assistant. */
1338
+ name: string;
1339
+ /** Builder's behavior and tone instructions. */
1340
+ instructions: string;
1341
+ }
1342
+ /** Saved project-scoped assistant. */
1343
+ interface Assistant extends AssistantDefinition {
1344
+ /** Stable assistant identifier. */
1345
+ id: string;
1346
+ }
1347
+ /** A durable receipt, including the saved reply after completion. */
1348
+ interface AssistantMessage {
1349
+ /** Server-generated ID for polling. */
1350
+ id: string;
1351
+ /** Current status of the turn. */
1352
+ state: 'queued' | 'running' | 'completed' | 'failed';
1353
+ /** Original message. */
1354
+ text: string;
1355
+ /** Saved response after completion. */
1356
+ reply?: string | null;
1357
+ /** A private terminal observer is still updating the receipt. */ tracePending?: boolean;
1358
+ /** Execution metadata present only on private dashboard test receipts. */
1359
+ trace?: {
1360
+ /** Lifecycle name or registered tool. */ name: string;
1361
+ /** Operation or observer result. */ status: string;
1362
+ /** Workflow that owns the step. */ workflow?: string;
1363
+ /** One-based step position. */ step?: number;
1364
+ /** Registered function name. */ tool?: string;
1365
+ /** Safe failure category. */ reason?: string;
1366
+ }[];
1367
+ /** WhatsApp transport status after a reply is saved. */
1368
+ delivery?: 'queued' | 'unknown' | 'submitted';
1369
+ }
1370
+ /** Stable retry key and contact identity are supplied by the builder's backend. */
1371
+ interface AssistantInput {
1372
+ /** Unique per contact, reused on transport retry. */
1373
+ messageId: string;
1374
+ /** Contact identifier local to this assistant. */
1375
+ contact: string;
1376
+ /** Incoming text. */
1377
+ text: string;
1378
+ }
1379
+ /** A linked-device enrollment, including the current QR material when requested by an administrator. */
1380
+ interface WhatsAppDevice {
1381
+ /** Pairing or connection status. */
1382
+ state: string;
1383
+ /** Short-lived pairing material. */
1384
+ qr: string | null;
1385
+ }
1386
+ /** Reusable instructions owned by a project. */
1387
+ interface AssistantSkill {
1388
+ /** Assignment identity. */ id: string;
1389
+ /** Builder-selected name. */ name: string;
1390
+ /** Private instructions. */ instructions: string;
1391
+ }
1392
+ /** Explicit sample input for one draft event or tool. */
1393
+ interface AssistantSampleRequest {
1394
+ /** Assistant-owned events and callable tools. */ program: AssistantProgram;
1395
+ /** Selects the execution contract. */ kind: 'event' | 'tool';
1396
+ /** Display or callable name used to identify this entry. */ name: string;
1397
+ /** JSON arguments supplied to the selected function. */ input: unknown;
1398
+ }
1399
+
1267
1400
  /**
1268
1401
  * The shapes Browser's methods take and return that are not part of the
1269
1402
  * exported types: tab listings, dialog answers, share links and the like.
@@ -1689,6 +1822,29 @@ declare class Oya {
1689
1822
  update: (name: string, personaIds: string[]) => Promise<PersonaGroup>;
1690
1823
  remove: (name: string) => Promise<void>;
1691
1824
  };
1825
+ /** Build and message project-owned hosted assistants. */
1826
+ readonly assistants: {
1827
+ connectWhatsApp: (id: string) => Promise<WhatsAppDevice>;
1828
+ whatsAppStatus: (id: string) => Promise<WhatsAppDevice>;
1829
+ disconnectWhatsApp: (id: string) => Promise<void>;
1830
+ rotateInboundKey: (id: string) => Promise<{
1831
+ secret: string;
1832
+ }>;
1833
+ send: (id: string, body: AssistantInput) => Promise<AssistantMessage>;
1834
+ message: (id: string, messageId: string) => Promise<AssistantMessage>;
1835
+ forget: (id: string, contact: string) => Promise<void>;
1836
+ getProgram: (id: string) => Promise<AssistantProgramRevision>;
1837
+ saveProgram: (id: string, body: AssistantProgramRevision) => Promise<AssistantProgramRevision>;
1838
+ testProgram: (id: string, body: AssistantSampleRequest) => Promise<ProgramPreview>;
1839
+ listSkills: () => Promise<AssistantSkill[]>;
1840
+ deleteSkill: (id: string) => Promise<void>;
1841
+ createSkill: (body: Omit<AssistantSkill, "id">) => Promise<AssistantSkill>;
1842
+ list: () => Promise<Assistant[]>;
1843
+ create: (body: AssistantDefinition) => Promise<Assistant>;
1844
+ update: (id: string, body: AssistantDefinition) => Promise<Assistant>;
1845
+ setModel: (id: string, model: NonNullable<AssistantDefinition["model"]> | null) => Promise<Assistant>;
1846
+ remove: (id: string) => Promise<void>;
1847
+ };
1692
1848
  /** What this key has spent. */
1693
1849
  usage(): Promise<unknown>;
1694
1850
  /** Waits for a starting browser to dial in, through this client's own list and session calls. */
@@ -1696,4 +1852,4 @@ declare class Oya {
1696
1852
  }
1697
1853
 
1698
1854
  export { Browser, MAX_FILE_BYTES, Oya, OyaError, Run, Oya as default, file };
1699
- export type { Activity, Analysis, AnalyzeOptions, AttentionRequest, Block, BrowserDetail, BrowserInfo, CaptchaResult, CaptchaSolver, Config, ConfigUpdate, ControlCredential, ControlEvent, ControlOverview, ControlRole, ControlSession, Cookie, CookieFormat, DesktopOptions, EcsAuth, EcsConfig, Element, FileValue, Fingerprint, Health, HumanInputAction, ImportOptions, LlmCatalogEntry, LlmProvider, MfaConfig, MfaResult, ModelOptions, OyaOptions, PageFormat, PersonaGroup, PersonaInfo, PersonaPrefs, PlayResult, Playbook, PlaybookAnswer, PlaybookExport, PlaybookSummary, ProjectSettings, Provider, ProxyCreate, ProxyInfo, RecoverOptions, RunData, RunInfo, RunResult, SandboxRuntime, Signup, SignupOptions, SiteCredentials, StartOptions, StartResult, StopResult, SubmitOptions };
1855
+ export type { Activity, Analysis, AnalyzeOptions, Assistant, AssistantDefinition, AssistantEvent, AssistantInput, AssistantMessage, AssistantProgram, AssistantProgramRevision, AssistantSampleRequest, AssistantSkill, AssistantTool, AttentionRequest, Block, BrowserDetail, BrowserInfo, CaptchaResult, CaptchaSolver, Config, ConfigUpdate, ControlCredential, ControlEvent, ControlOverview, ControlRole, ControlSession, Cookie, CookieFormat, DesktopOptions, EcsAuth, EcsConfig, Element, FileValue, Fingerprint, Health, HumanInputAction, ImportOptions, LlmCatalogEntry, LlmProvider, MfaConfig, MfaResult, ModelOptions, OyaOptions, PageFormat, PersonaGroup, PersonaInfo, PersonaPrefs, PlayResult, Playbook, PlaybookAnswer, PlaybookExport, PlaybookSummary, ProgramPreview, ProjectSettings, Provider, ProxyCreate, ProxyInfo, RecoverOptions, RunData, RunInfo, RunResult, SandboxRuntime, Signup, SignupOptions, SiteCredentials, StartOptions, StartResult, StopResult, SubmitOptions };
package/dist/index.js CHANGED
@@ -156,9 +156,9 @@ var Http = class _Http {
156
156
  return new _Http(this.baseUrl, this.apiKey, this.timeoutMs, this.fetchImpl, this.origin, merged);
157
157
  }
158
158
  /** Sends one request and returns the parsed answer, or throws an OyaError when it failed. */
159
- async request(method, path, body, timeoutMs = this.timeoutMs, headers = {}) {
160
- const res = await this.send(`${this.baseUrl}${path}`, this.init(method, body, timeoutMs, headers), timeoutMs);
161
- return readAnswer(res, `${method} ${path}`, this);
159
+ async request(method, path2, body, timeoutMs = this.timeoutMs, headers = {}) {
160
+ const res = await this.send(`${this.baseUrl}${path2}`, this.init(method, body, timeoutMs, headers), timeoutMs);
161
+ return readAnswer(res, `${method} ${path2}`, this);
162
162
  }
163
163
  /** The fetch options for one call, with this client's key on them. */
164
164
  init(method, body, timeoutMs, headers) {
@@ -432,8 +432,8 @@ var Browser = class {
432
432
  http;
433
433
  /** Runs one browser command; a command that ran and failed throws. */
434
434
  async command(action, params = {}, timeoutMs) {
435
- const path = `/api/browsers/${segment(this.id)}/command`;
436
- const result = await this.http.request("POST", path, { action, params }, timeoutMs);
435
+ const path2 = `/api/browsers/${segment(this.id)}/command`;
436
+ const result = await this.http.request("POST", path2, { action, params }, timeoutMs);
437
437
  if (result.ok === false) throw new OyaError(result.error || `${action} failed`, Status.UNPROCESSABLE, result);
438
438
  return result.data;
439
439
  }
@@ -545,8 +545,8 @@ var Browser = class {
545
545
  */
546
546
  async ask(prompt, { data, secrets } = {}) {
547
547
  const body = { messages: [{ role: "user", content: prompt }], data, secrets };
548
- const path = `/api/browsers/${segment(this.id)}/chat`;
549
- return agentAnswer(await this.http.request("POST", path, body, AGENT_TIMEOUT_MS)).text;
548
+ const path2 = `/api/browsers/${segment(this.id)}/chat`;
549
+ return agentAnswer(await this.http.request("POST", path2, body, AGENT_TIMEOUT_MS)).text;
550
550
  }
551
551
  /**
552
552
  * `ask()` for data: the agent does the task and answers in the shape of `schema`
@@ -554,8 +554,8 @@ var Browser = class {
554
554
  */
555
555
  async extract(prompt, schema, values = {}) {
556
556
  const body = { messages: [{ role: "user", content: prompt }], ...values, schema };
557
- const path = `/api/browsers/${segment(this.id)}/chat`;
558
- const res = agentAnswer(await this.http.request("POST", path, body, AGENT_TIMEOUT_MS));
557
+ const path2 = `/api/browsers/${segment(this.id)}/chat`;
558
+ const res = agentAnswer(await this.http.request("POST", path2, body, AGENT_TIMEOUT_MS));
559
559
  if (res.failed || res.data === void 0) throw new OyaError(res.text, Status.UNPROCESSABLE, res);
560
560
  return res.data;
561
561
  }
@@ -580,9 +580,9 @@ var Browser = class {
580
580
  * replaces the broken steps in the playbook (`healed`); off, the step's error is thrown.
581
581
  */
582
582
  async play(name, data = {}, { autoHeal = true } = {}) {
583
- const path = `/api/browsers/${segment(this.id)}/playbooks/${segment(name, "name")}/play`;
583
+ const path2 = `/api/browsers/${segment(this.id)}/playbooks/${segment(name, "name")}/play`;
584
584
  return agentAnswer(
585
- await this.http.request("POST", path, { variables: data, autoHeal }, AGENT_TIMEOUT_MS)
585
+ await this.http.request("POST", path2, { variables: data, autoHeal }, AGENT_TIMEOUT_MS)
586
586
  );
587
587
  }
588
588
  /**
@@ -612,8 +612,8 @@ var Browser = class {
612
612
  * 60 seconds. Mint one per viewer, the first connection spends it.
613
613
  */
614
614
  async liveStreamUrl() {
615
- const path = `/api/control/sessions/${segment(this.id)}/ticket`;
616
- const { ticket } = await this.http.request("POST", path, {});
615
+ const path2 = `/api/control/sessions/${segment(this.id)}/ticket`;
616
+ const { ticket } = await this.http.request("POST", path2, {});
617
617
  return `${this.http.baseUrl}/api/live/${segment(this.id)}?ticket=${encodeURIComponent(ticket)}`;
618
618
  }
619
619
  /**
@@ -628,8 +628,8 @@ var Browser = class {
628
628
  * expires or you revoke it, so treat it like a password.
629
629
  */
630
630
  async shareUrl({ control = false, expiresInSeconds = 3600 } = {}) {
631
- const path = `/api/control/sessions/${segment(this.id)}/share`;
632
- const c = await this.http.request("POST", path, { control, expiresIn: expiresInSeconds });
631
+ const path2 = `/api/control/sessions/${segment(this.id)}/share`;
632
+ const c = await this.http.request("POST", path2, { control, expiresIn: expiresInSeconds });
633
633
  return { url: shareLink(this.http.baseUrl, this.id, c.token), id: c.id, expiresAt: c.expiresAt };
634
634
  }
635
635
  /** Revoke a link from `shareUrl()` before it expires, by the id it returned. */
@@ -703,8 +703,8 @@ function startBody(options) {
703
703
  var idempotencyKeyOf = ({ idempotencyKey }) => idempotencyKey ? headerSafe(idempotencyKey, "idempotencyKey", 'Use letters, digits, "-" and "_".') : globalThis.crypto.randomUUID();
704
704
  async function start(http, wait, options) {
705
705
  const headers = { "Idempotency-Key": idempotencyKeyOf(options) };
706
- const path = "/api/browsers/start";
707
- const started = await http().request("POST", path, startBody(options), START_TIMEOUT_MS, headers);
706
+ const path2 = "/api/browsers/start";
707
+ const started = await http().request("POST", path2, startBody(options), START_TIMEOUT_MS, headers);
708
708
  if (started.status === "starting") {
709
709
  await wait(started.id, options.readyTimeoutMs ?? READY_TIMEOUT_MS + (options.queueMs || 0));
710
710
  started.cdpUrl = (await fetchBrowser(http, started.id)).cdpUrl;
@@ -946,6 +946,62 @@ var personaGroupApi = (http) => ({
946
946
  }
947
947
  });
948
948
 
949
+ // src/api/assistants.ts
950
+ var path = (id) => "/api/assistants/" + segment(id, "assistant ID");
951
+ var gateways = (http) => ({
952
+ /** Request device pairing. */
953
+ connectWhatsApp: (id) => http().request("POST", path(id) + "/whatsapp"),
954
+ /** Read the currently active pairing code or connection status. */
955
+ whatsAppStatus: (id) => http().request("GET", path(id) + "/whatsapp"),
956
+ /** Stop handling incoming messages and erase local WhatsApp credentials. */
957
+ disconnectWhatsApp: (id) => http().request("DELETE", path(id) + "/whatsapp"),
958
+ /** Rotate the key accepted by the assistant webhook. */
959
+ rotateInboundKey: (id) => http().request("POST", path(id) + "/inbound-key")
960
+ });
961
+ var skills = (http) => ({
962
+ /** List available reusable instructions. */
963
+ listSkills: async () => (await http().request("GET", "/api/assistants")).skills,
964
+ /** Permanently remove a project skill and detach it from every assistant. */
965
+ deleteSkill: (id) => http().request("DELETE", "/api/assistants/skills/" + segment(id, "skill ID")),
966
+ /** Save instructions once for several assistants. */
967
+ createSkill: (body) => http().request("POST", "/api/assistants/skills", body)
968
+ });
969
+ var definitions = (http) => ({
970
+ /** Discover definitions in this project. */
971
+ list: async () => (await http().request("GET", "/api/assistants")).assistants,
972
+ /** Save a new assistant. */
973
+ create: (body) => http().request("POST", "/api/assistants", body),
974
+ /** Change the instructions for future turns. */
975
+ update: (id, body) => http().request("PUT", path(id), body),
976
+ /** Change one assistant's model without interrupting its device or contact memory. */
977
+ setModel: (id, model) => http().request("PATCH", path(id) + "/model", { model }),
978
+ /** Remove this assistant and its messages. */
979
+ remove: (id) => http().request("DELETE", path(id))
980
+ });
981
+ var programs = (http) => ({
982
+ /** Load a saved program and its revision. */
983
+ getProgram: (id) => http().request("GET", path(id) + "/program"),
984
+ /** Replace a program if its revision is still current. */
985
+ saveProgram: (id, body) => http().request("PUT", path(id) + "/program", body),
986
+ /** Preview a draft without delivering a message. */
987
+ testProgram: (id, body) => http().request("POST", path(id) + "/program/test", body)
988
+ });
989
+ var conversations = (http) => ({
990
+ /** Submit a contact message for asynchronous processing. */
991
+ send: (id, body) => http().request("POST", path(id) + "/messages", body),
992
+ /** Read the original receipt and latest response. */
993
+ message: (id, messageId) => http().request("GET", path(id) + "/messages/" + segment(messageId, "message ID")),
994
+ /** Erase a contact's conversation. */
995
+ forget: (id, contact) => http().request("DELETE", path(id) + "/contacts/" + segment(contact, "contact"))
996
+ });
997
+ var assistantApi = (http) => ({
998
+ ...definitions(http),
999
+ ...skills(http),
1000
+ ...programs(http),
1001
+ ...conversations(http),
1002
+ ...gateways(http)
1003
+ });
1004
+
949
1005
  // src/api/config.ts
950
1006
  var configApi = (http) => ({
951
1007
  /** This key's settings. Secrets read back masked. */
@@ -1104,13 +1160,13 @@ var base64 = (bytes) => {
1104
1160
  }
1105
1161
  return btoa(binary);
1106
1162
  };
1107
- async function readPath(path) {
1163
+ async function readPath(path2) {
1108
1164
  const fs = await import(
1109
1165
  /* webpackIgnore: true */
1110
1166
  /* @vite-ignore */
1111
1167
  NODE_FS
1112
1168
  );
1113
- return { bytes: new Uint8Array(await fs.readFile(path)), name: path.split(/[\\/]/).pop() || "file" };
1169
+ return { bytes: new Uint8Array(await fs.readFile(path2)), name: path2.split(/[\\/]/).pop() || "file" };
1114
1170
  }
1115
1171
  async function readSource(source) {
1116
1172
  if (typeof source === "string") return readPath(source);
@@ -1195,6 +1251,8 @@ var Oya = class {
1195
1251
  personaGroups = personaGroupApi(() => this.http);
1196
1252
  /** The same as `personaGroups`, matching the `profiles` alias. */
1197
1253
  profileGroups = this.personaGroups;
1254
+ /** Build and message project-owned hosted assistants. */
1255
+ assistants = assistantApi(() => this.http);
1198
1256
  /** What this key has spent. */
1199
1257
  usage() {
1200
1258
  return this.http.request("GET", "/api/usage");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oya-ai/browser",
3
- "version": "1.0.295",
3
+ "version": "1.0.298",
4
4
  "description": "TypeScript SDK for Oya, the HIPAA-compliant agentic browser: start cloud browsers, run playbooks, attach Playwright.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://oyabrowser.com",