orqo-node-sdk 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -43,7 +43,7 @@
43
43
  ## 📦 Installation
44
44
 
45
45
  ```bash
46
- npm install @orqo/sdk
46
+ npm install orqo-node-sdk
47
47
  ```
48
48
 
49
49
  > **Requirements:** Node.js 18+ (or any runtime with `globalThis.fetch`)
@@ -55,7 +55,7 @@ npm install @orqo/sdk
55
55
  ### 1. Provision an Instance
56
56
 
57
57
  ```typescript
58
- import { OrqoClient } from '@orqo/sdk';
58
+ import { OrqoClient } from 'orqo-node-sdk';
59
59
 
60
60
  const orqo = new OrqoClient({
61
61
  host: 'https://gateway.orqo.ai',
@@ -95,7 +95,7 @@ await instance.sendMessage({
95
95
  ### 4. Receive Events
96
96
 
97
97
  ```typescript
98
- import { createWebhookHandler } from '@orqo/sdk';
98
+ import { createWebhookHandler } from 'orqo-node-sdk';
99
99
 
100
100
  app.post('/webhooks/orqo', createWebhookHandler({
101
101
  secret: process.env.WEBHOOK_SECRET,
@@ -219,7 +219,7 @@ The `createWebhookHandler()` function provides a framework-agnostic webhook rece
219
219
 
220
220
  ```typescript
221
221
  import express from 'express';
222
- import { createWebhookHandler } from '@orqo/sdk';
222
+ import { createWebhookHandler } from 'orqo-node-sdk';
223
223
 
224
224
  const app = express();
225
225
  app.use(express.json());
@@ -252,7 +252,7 @@ app.post('/webhooks/orqo', createWebhookHandler({
252
252
 
253
253
  ```typescript
254
254
  import { Hono } from 'hono';
255
- import { createWebhookHandler } from '@orqo/sdk';
255
+ import { createWebhookHandler } from 'orqo-node-sdk';
256
256
 
257
257
  const app = new Hono();
258
258
 
@@ -366,7 +366,7 @@ Attempt 4 → wait 4000ms (if maxAttempts > 3)
366
366
  ## 🤝 Complete Workflow Example
367
367
 
368
368
  ```typescript
369
- import { OrqoClient, createWebhookHandler } from '@orqo/sdk';
369
+ import { OrqoClient, createWebhookHandler } from 'orqo-node-sdk';
370
370
  import express from 'express';
371
371
 
372
372
  // ── 1. Setup ─────────────────────────────────────────────
@@ -441,7 +441,7 @@ app.listen(3000, () => console.log('🚀 Running on :3000'));
441
441
 
442
442
  ```
443
443
  ┌──────────────────────────────────────────────────────────────┐
444
- @orqo/sdk
444
+ orqo-node-sdk
445
445
  ├──────────────┬─────────────────┬─────────────────────────────┤
446
446
  │ OrqoClient │ OrqoInstance │ createWebhookHandler() │
447
447
  │ (Admin) │ (Per-instance) │ (Event receiver) │
@@ -518,7 +518,7 @@ import type {
518
518
  HandoffEvent,
519
519
  OrqoWebhookEvent,
520
520
  WebhookHandlerOptions,
521
- } from '@orqo/sdk';
521
+ } from 'orqo-node-sdk';
522
522
  ```
523
523
 
524
524
  ---
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Orqo SDK — Fluent Builders
3
+ *
4
+ * Builder pattern classes that provide a chainable, ergonomic API
5
+ * for complex configuration objects. These are convenience wrappers —
6
+ * the underlying raw config objects remain fully supported.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * // Fluent Agent creation
11
+ * const agent = await instance
12
+ * .agent('Atendente')
13
+ * .prompt('Você é um atendente educado.')
14
+ * .tools('search', 'calendar')
15
+ * .identity('Ana', '👩‍💼')
16
+ * .create();
17
+ *
18
+ * // Fluent Provisioning
19
+ * const instance = await orqo
20
+ * .provision('Pizzaria do Zé')
21
+ * .withLLM('openai', 'gpt-4o-mini', process.env.OPENAI_KEY!)
22
+ * .withWebhook('https://api.example.com/events')
23
+ * .withTelegram(process.env.TG_BOT_TOKEN!)
24
+ * .execute();
25
+ * ```
26
+ */
27
+ import type { AgentConfig, Agent, ProvisionOptions, ProvisionResult, WebhookConfig } from './types.js';
28
+ import type { OrqoInstance } from './instance.js';
29
+ import type { AgentTypeValue, LLMProviderType } from './constants.js';
30
+ export declare class AgentBuilder {
31
+ private config;
32
+ private readonly _instance;
33
+ constructor(instance: OrqoInstance, name: string);
34
+ /** Set the agent type (default: 'chat'). */
35
+ type(type: AgentTypeValue): this;
36
+ /** Set the system prompt / instructions. */
37
+ prompt(systemPrompt: string): this;
38
+ /** Set the agent's custom ID. */
39
+ id(id: string): this;
40
+ /** Add tools the agent can use. */
41
+ tools(...toolNames: string[]): this;
42
+ /** Set the agent identity (display name + emoji). */
43
+ identity(displayName: string, emoji?: string): this;
44
+ /** Set routing rules (for router agents). */
45
+ routing(rules: Record<string, unknown>): this;
46
+ /** Set the fallback agent ID (for router agents). */
47
+ fallback(agentId: string): this;
48
+ /** Set any additional configuration property. */
49
+ set(key: string, value: unknown): this;
50
+ /** Build the raw config object without creating the agent. */
51
+ build(): AgentConfig;
52
+ /** Create the agent on the server. */
53
+ create(): Promise<Agent>;
54
+ }
55
+ export declare class ProvisionBuilder {
56
+ private options;
57
+ private readonly _client;
58
+ private _agents;
59
+ private _webhooks;
60
+ constructor(client: {
61
+ _doProvision(options: ProvisionOptions): Promise<{
62
+ instance: OrqoInstance;
63
+ result: ProvisionResult;
64
+ }>;
65
+ }, name: string);
66
+ /** Set instance description. */
67
+ description(desc: string): this;
68
+ /** Configure the LLM provider for this instance. */
69
+ withLLM(provider: LLMProviderType, model: string, apiKey: string): this;
70
+ /** Add a Telegram bot channel. */
71
+ withTelegram(botToken: string, webhookSecret?: string): this;
72
+ /** Queue an agent to be created after provisioning. */
73
+ withAgent(name: string, systemPrompt?: string): this;
74
+ /** Queue a webhook to be registered after provisioning. */
75
+ withWebhook(urlOrConfig: string | WebhookConfig): this;
76
+ /** Set the webhook URL for instance-level connection events. */
77
+ onEvents(webhookUrl: string, secret?: string): this;
78
+ /** Add arbitrary config. */
79
+ withConfig(config: Record<string, unknown>): this;
80
+ /** Build the raw options object without provisioning. */
81
+ build(): ProvisionOptions;
82
+ /**
83
+ * Execute provisioning and all queued setup steps.
84
+ * Returns the ready-to-use OrqoInstance.
85
+ */
86
+ execute(): Promise<{
87
+ instance: OrqoInstance;
88
+ result: ProvisionResult;
89
+ agents: Agent[];
90
+ webhooks: unknown[];
91
+ }>;
92
+ }
@@ -0,0 +1,161 @@
1
+ /**
2
+ * Orqo SDK — Fluent Builders
3
+ *
4
+ * Builder pattern classes that provide a chainable, ergonomic API
5
+ * for complex configuration objects. These are convenience wrappers —
6
+ * the underlying raw config objects remain fully supported.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * // Fluent Agent creation
11
+ * const agent = await instance
12
+ * .agent('Atendente')
13
+ * .prompt('Você é um atendente educado.')
14
+ * .tools('search', 'calendar')
15
+ * .identity('Ana', '👩‍💼')
16
+ * .create();
17
+ *
18
+ * // Fluent Provisioning
19
+ * const instance = await orqo
20
+ * .provision('Pizzaria do Zé')
21
+ * .withLLM('openai', 'gpt-4o-mini', process.env.OPENAI_KEY!)
22
+ * .withWebhook('https://api.example.com/events')
23
+ * .withTelegram(process.env.TG_BOT_TOKEN!)
24
+ * .execute();
25
+ * ```
26
+ */
27
+ // ============================================================================
28
+ // Agent Builder
29
+ // ============================================================================
30
+ export class AgentBuilder {
31
+ config;
32
+ _instance;
33
+ constructor(instance, name) {
34
+ this._instance = instance;
35
+ this.config = { name };
36
+ }
37
+ /** Set the agent type (default: 'chat'). */
38
+ type(type) {
39
+ this.config.type = type;
40
+ return this;
41
+ }
42
+ /** Set the system prompt / instructions. */
43
+ prompt(systemPrompt) {
44
+ this.config.systemPrompt = systemPrompt;
45
+ return this;
46
+ }
47
+ /** Set the agent's custom ID. */
48
+ id(id) {
49
+ this.config.id = id;
50
+ return this;
51
+ }
52
+ /** Add tools the agent can use. */
53
+ tools(...toolNames) {
54
+ this.config.tools = [...(this.config.tools || []), ...toolNames];
55
+ return this;
56
+ }
57
+ /** Set the agent identity (display name + emoji). */
58
+ identity(displayName, emoji) {
59
+ this.config.identity = { displayName, emoji };
60
+ return this;
61
+ }
62
+ /** Set routing rules (for router agents). */
63
+ routing(rules) {
64
+ this.config.routingRules = rules;
65
+ return this;
66
+ }
67
+ /** Set the fallback agent ID (for router agents). */
68
+ fallback(agentId) {
69
+ this.config.defaultAgentId = agentId;
70
+ return this;
71
+ }
72
+ /** Set any additional configuration property. */
73
+ set(key, value) {
74
+ this.config[key] = value;
75
+ return this;
76
+ }
77
+ /** Build the raw config object without creating the agent. */
78
+ build() {
79
+ return { ...this.config };
80
+ }
81
+ /** Create the agent on the server. */
82
+ async create() {
83
+ return this._instance.createAgent(this.config);
84
+ }
85
+ }
86
+ // ============================================================================
87
+ // Provision Builder
88
+ // ============================================================================
89
+ export class ProvisionBuilder {
90
+ options;
91
+ _client;
92
+ _agents = [];
93
+ _webhooks = [];
94
+ constructor(client, name) {
95
+ this._client = client;
96
+ this.options = { name };
97
+ }
98
+ /** Set instance description. */
99
+ description(desc) {
100
+ this.options.description = desc;
101
+ return this;
102
+ }
103
+ /** Configure the LLM provider for this instance. */
104
+ withLLM(provider, model, apiKey) {
105
+ this.options.llm = { provider, model, apiKey };
106
+ return this;
107
+ }
108
+ /** Add a Telegram bot channel. */
109
+ withTelegram(botToken, webhookSecret) {
110
+ this.options.telegram = { botToken, webhookSecret };
111
+ return this;
112
+ }
113
+ /** Queue an agent to be created after provisioning. */
114
+ withAgent(name, systemPrompt) {
115
+ const config = { name };
116
+ if (systemPrompt)
117
+ config.systemPrompt = systemPrompt;
118
+ this._agents.push(config);
119
+ return this;
120
+ }
121
+ /** Queue a webhook to be registered after provisioning. */
122
+ withWebhook(urlOrConfig) {
123
+ this._webhooks.push(urlOrConfig);
124
+ return this;
125
+ }
126
+ /** Set the webhook URL for instance-level connection events. */
127
+ onEvents(webhookUrl, secret) {
128
+ this.options.webhookUrl = webhookUrl;
129
+ if (secret)
130
+ this.options.webhookSecret = secret;
131
+ return this;
132
+ }
133
+ /** Add arbitrary config. */
134
+ withConfig(config) {
135
+ this.options.config = { ...this.options.config, ...config };
136
+ return this;
137
+ }
138
+ /** Build the raw options object without provisioning. */
139
+ build() {
140
+ return { ...this.options };
141
+ }
142
+ /**
143
+ * Execute provisioning and all queued setup steps.
144
+ * Returns the ready-to-use OrqoInstance.
145
+ */
146
+ async execute() {
147
+ // Step 1: Provision
148
+ const { instance, result } = await this._client._doProvision(this.options);
149
+ // Step 2: Create queued agents
150
+ const agents = [];
151
+ for (const agentConfig of this._agents) {
152
+ agents.push(await instance.createAgent(agentConfig));
153
+ }
154
+ // Step 3: Register queued webhooks
155
+ const webhooks = [];
156
+ for (const wh of this._webhooks) {
157
+ webhooks.push(await instance.addWebhook(wh));
158
+ }
159
+ return { instance, result, agents, webhooks };
160
+ }
161
+ }
package/dist/client.d.ts CHANGED
@@ -7,23 +7,65 @@
7
7
  */
8
8
  import type { OrqoClientConfig, ProvisionOptions, ProvisionResult, InstanceStatus } from './types.js';
9
9
  import { OrqoInstance } from './instance.js';
10
+ import { ProvisionBuilder } from './builders.js';
10
11
  export declare class OrqoClient {
11
12
  private readonly host;
12
13
  private readonly adminToken;
13
14
  private readonly _fetch;
14
15
  private readonly retry;
15
16
  constructor(config: OrqoClientConfig);
17
+ /**
18
+ * Create an OrqoClient from environment variables.
19
+ *
20
+ * Reads `ORQO_HOST` and `ORQO_ADMIN_TOKEN` from `process.env`.
21
+ * Throws a clear error if required variables are missing.
22
+ *
23
+ * @param overrides - Partial config to override env values
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * // Reads from .env automatically
28
+ * const orqo = OrqoClient.fromEnv();
29
+ *
30
+ * // Override host for local development
31
+ * const orqo = OrqoClient.fromEnv({ host: 'http://localhost:3001' });
32
+ * ```
33
+ */
34
+ static fromEnv(overrides?: Partial<OrqoClientConfig>): OrqoClient;
16
35
  private request;
17
36
  /** List all instances. */
18
37
  listInstances(): Promise<InstanceStatus[]>;
19
38
  /**
20
39
  * Quick-Provision: Create an instance, boot WhatsApp, and return QR code
21
40
  * in a single call. Returns an OrqoInstance ready for interaction.
41
+ *
42
+ * Accepts a name string (returns a ProvisionBuilder for fluent chaining)
43
+ * or a full ProvisionOptions object (returns directly).
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * // Fluent builder
48
+ * const { instance } = await orqo
49
+ * .provision('Pizzaria do Zé')
50
+ * .withLLM('openai', 'gpt-4o-mini', process.env.OPENAI_KEY!)
51
+ * .withAgent('Atendente', 'Você atende pedidos.')
52
+ * .withWebhook('https://api.example.com/events')
53
+ * .execute();
54
+ *
55
+ * // Direct (classic)
56
+ * const { instance } = await orqo.provision({ name: 'My Bot' });
57
+ * ```
22
58
  */
59
+ provision(name: string): ProvisionBuilder;
23
60
  provision(options: ProvisionOptions): Promise<{
24
61
  instance: OrqoInstance;
25
62
  result: ProvisionResult;
26
63
  }>;
64
+ /** @internal Performs the actual provisioning request. */
65
+ _doProvision(options: ProvisionOptions): Promise<{
66
+ instance: OrqoInstance;
67
+ result: ProvisionResult;
68
+ }>;
27
69
  /**
28
70
  * Get an OrqoInstance handle for an existing instance.
29
71
  * Does NOT validate the instance exists — use listInstances() first.
package/dist/client.js CHANGED
@@ -7,6 +7,7 @@
7
7
  */
8
8
  import { OrqoError } from './types.js';
9
9
  import { OrqoInstance } from './instance.js';
10
+ import { ProvisionBuilder } from './builders.js';
10
11
  export class OrqoClient {
11
12
  host;
12
13
  adminToken;
@@ -25,6 +26,41 @@ export class OrqoClient {
25
26
  };
26
27
  }
27
28
  // --------------------------------------------------------------------------
29
+ // Static Factory
30
+ // --------------------------------------------------------------------------
31
+ /**
32
+ * Create an OrqoClient from environment variables.
33
+ *
34
+ * Reads `ORQO_HOST` and `ORQO_ADMIN_TOKEN` from `process.env`.
35
+ * Throws a clear error if required variables are missing.
36
+ *
37
+ * @param overrides - Partial config to override env values
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * // Reads from .env automatically
42
+ * const orqo = OrqoClient.fromEnv();
43
+ *
44
+ * // Override host for local development
45
+ * const orqo = OrqoClient.fromEnv({ host: 'http://localhost:3001' });
46
+ * ```
47
+ */
48
+ static fromEnv(overrides) {
49
+ const host = overrides?.host || process.env.ORQO_HOST;
50
+ const adminToken = overrides?.adminToken || process.env.ORQO_ADMIN_TOKEN;
51
+ if (!host) {
52
+ throw new OrqoError('ORQO_HOST environment variable is required. Set it or pass { host } to fromEnv().', 0);
53
+ }
54
+ if (!adminToken) {
55
+ throw new OrqoError('ORQO_ADMIN_TOKEN environment variable is required. Set it or pass { adminToken } to fromEnv().', 0);
56
+ }
57
+ return new OrqoClient({
58
+ host,
59
+ adminToken,
60
+ ...overrides,
61
+ });
62
+ }
63
+ // --------------------------------------------------------------------------
28
64
  // Private helpers
29
65
  // --------------------------------------------------------------------------
30
66
  async request(path, options = {}) {
@@ -63,11 +99,14 @@ export class OrqoClient {
63
99
  async listInstances() {
64
100
  return this.request('/api/admin/instances');
65
101
  }
66
- /**
67
- * Quick-Provision: Create an instance, boot WhatsApp, and return QR code
68
- * in a single call. Returns an OrqoInstance ready for interaction.
69
- */
70
- async provision(options) {
102
+ provision(nameOrOptions) {
103
+ if (typeof nameOrOptions === 'string') {
104
+ return new ProvisionBuilder(this, nameOrOptions);
105
+ }
106
+ return this._doProvision(nameOrOptions);
107
+ }
108
+ /** @internal Performs the actual provisioning request. */
109
+ async _doProvision(options) {
71
110
  const result = await this.request('/api/admin/quick-provision', {
72
111
  method: 'POST',
73
112
  body: JSON.stringify(options),
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Orqo SDK — Constants
3
+ *
4
+ * Typed enum-like constants for common configuration values.
5
+ * These provide IDE autocomplete and documentation while still
6
+ * accepting any string value for extensibility.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { Events, LLMProvider } from 'orqo-node-sdk';
11
+ *
12
+ * // Use constants for autocomplete
13
+ * await instance.addWebhook({
14
+ * url: 'https://my-api.com/hook',
15
+ * events: [Events.MESSAGE_RECEIVED],
16
+ * });
17
+ *
18
+ * // Or use free-form strings
19
+ * await instance.addWebhook({
20
+ * url: 'https://my-api.com/hook',
21
+ * events: ['my.custom.event'],
22
+ * });
23
+ * ```
24
+ */
25
+ /** Well-known webhook event types. Custom event strings are also accepted. */
26
+ export declare const Events: {
27
+ /** A new message was received from a contact */
28
+ readonly MESSAGE_RECEIVED: "message.received";
29
+ /** A message was sent to a contact */
30
+ readonly MESSAGE_SENT: "message.sent";
31
+ /** A message was processed by the AI agent */
32
+ readonly MESSAGE_PROCESSED: "message.processed";
33
+ /** A session was handed off to a human operator */
34
+ readonly SESSION_HANDOFF: "session.handoff";
35
+ /** WhatsApp connection state changed */
36
+ readonly CONNECTION_CHANGED: "connection.changed";
37
+ /** A new contact was created */
38
+ readonly CONTACT_CREATED: "contact.created";
39
+ /** A contact was updated */
40
+ readonly CONTACT_UPDATED: "contact.updated";
41
+ };
42
+ /** Type for event values — accepts constants or custom string */
43
+ export type EventType = typeof Events[keyof typeof Events] | (string & {});
44
+ /** Default events used when none are specified */
45
+ export declare const DEFAULT_WEBHOOK_EVENTS: EventType[];
46
+ /** Well-known LLM provider identifiers. Custom provider strings are also accepted. */
47
+ export declare const LLMProvider: {
48
+ readonly OPENAI: "openai";
49
+ readonly GEMINI: "gemini";
50
+ readonly ANTHROPIC: "anthropic";
51
+ readonly GROQ: "groq";
52
+ readonly DEEPSEEK: "deepseek";
53
+ readonly OLLAMA: "ollama";
54
+ };
55
+ /** Type for provider values — accepts constants or custom string */
56
+ export type LLMProviderType = typeof LLMProvider[keyof typeof LLMProvider] | (string & {});
57
+ /** Well-known agent types. */
58
+ export declare const AgentType: {
59
+ /** Standard conversational agent */
60
+ readonly CHAT: "chat";
61
+ /** Routes messages to specialized agents */
62
+ readonly ROUTER: "router";
63
+ /** Domain-specific specialist agent */
64
+ readonly SPECIALIST: "specialist";
65
+ };
66
+ /** Type for agent type values — accepts constants or custom string */
67
+ export type AgentTypeValue = typeof AgentType[keyof typeof AgentType] | (string & {});
68
+ /** Well-known WhatsApp connection states. */
69
+ export declare const WhatsAppState: {
70
+ readonly INITIALIZING: "initializing";
71
+ readonly WAITING_QR: "waiting-qr";
72
+ readonly CONNECTED: "connected";
73
+ readonly DISCONNECTED: "disconnected";
74
+ };
75
+ /** Actions for custom guardrail rules. */
76
+ export declare const GuardrailAction: {
77
+ readonly BLOCK: "block";
78
+ readonly WARN: "warn";
79
+ readonly REDACT: "redact";
80
+ };
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Orqo SDK — Constants
3
+ *
4
+ * Typed enum-like constants for common configuration values.
5
+ * These provide IDE autocomplete and documentation while still
6
+ * accepting any string value for extensibility.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { Events, LLMProvider } from 'orqo-node-sdk';
11
+ *
12
+ * // Use constants for autocomplete
13
+ * await instance.addWebhook({
14
+ * url: 'https://my-api.com/hook',
15
+ * events: [Events.MESSAGE_RECEIVED],
16
+ * });
17
+ *
18
+ * // Or use free-form strings
19
+ * await instance.addWebhook({
20
+ * url: 'https://my-api.com/hook',
21
+ * events: ['my.custom.event'],
22
+ * });
23
+ * ```
24
+ */
25
+ // ============================================================================
26
+ // Webhook Events
27
+ // ============================================================================
28
+ /** Well-known webhook event types. Custom event strings are also accepted. */
29
+ export const Events = {
30
+ /** A new message was received from a contact */
31
+ MESSAGE_RECEIVED: 'message.received',
32
+ /** A message was sent to a contact */
33
+ MESSAGE_SENT: 'message.sent',
34
+ /** A message was processed by the AI agent */
35
+ MESSAGE_PROCESSED: 'message.processed',
36
+ /** A session was handed off to a human operator */
37
+ SESSION_HANDOFF: 'session.handoff',
38
+ /** WhatsApp connection state changed */
39
+ CONNECTION_CHANGED: 'connection.changed',
40
+ /** A new contact was created */
41
+ CONTACT_CREATED: 'contact.created',
42
+ /** A contact was updated */
43
+ CONTACT_UPDATED: 'contact.updated',
44
+ };
45
+ /** Default events used when none are specified */
46
+ export const DEFAULT_WEBHOOK_EVENTS = [
47
+ Events.MESSAGE_RECEIVED,
48
+ Events.MESSAGE_SENT,
49
+ Events.MESSAGE_PROCESSED,
50
+ Events.SESSION_HANDOFF,
51
+ ];
52
+ // ============================================================================
53
+ // LLM Providers
54
+ // ============================================================================
55
+ /** Well-known LLM provider identifiers. Custom provider strings are also accepted. */
56
+ export const LLMProvider = {
57
+ OPENAI: 'openai',
58
+ GEMINI: 'gemini',
59
+ ANTHROPIC: 'anthropic',
60
+ GROQ: 'groq',
61
+ DEEPSEEK: 'deepseek',
62
+ OLLAMA: 'ollama',
63
+ };
64
+ // ============================================================================
65
+ // Agent Types
66
+ // ============================================================================
67
+ /** Well-known agent types. */
68
+ export const AgentType = {
69
+ /** Standard conversational agent */
70
+ CHAT: 'chat',
71
+ /** Routes messages to specialized agents */
72
+ ROUTER: 'router',
73
+ /** Domain-specific specialist agent */
74
+ SPECIALIST: 'specialist',
75
+ };
76
+ // ============================================================================
77
+ // WhatsApp States
78
+ // ============================================================================
79
+ /** Well-known WhatsApp connection states. */
80
+ export const WhatsAppState = {
81
+ INITIALIZING: 'initializing',
82
+ WAITING_QR: 'waiting-qr',
83
+ CONNECTED: 'connected',
84
+ DISCONNECTED: 'disconnected',
85
+ };
86
+ // ============================================================================
87
+ // Guardrail Actions
88
+ // ============================================================================
89
+ /** Actions for custom guardrail rules. */
90
+ export const GuardrailAction = {
91
+ BLOCK: 'block',
92
+ WARN: 'warn',
93
+ REDACT: 'redact',
94
+ };
package/dist/index.d.ts CHANGED
@@ -1,36 +1,38 @@
1
1
  /**
2
- * @orqo/sdk — Plug-and-Play WhatsApp Integration
2
+ * orqo-node-sdk — Plug-and-Play WhatsApp + AI Agent Integration
3
3
  *
4
4
  * Zero-dependency TypeScript SDK for the Orqo Gateway.
5
5
  *
6
6
  * @example
7
7
  * ```typescript
8
- * import { OrqoClient } from '@orqo/sdk';
8
+ * import { OrqoClient, Events, LLMProvider } from 'orqo-node-sdk';
9
9
  *
10
- * const orqo = new OrqoClient({
11
- * host: 'https://orqo.example.com',
12
- * adminToken: 'your-admin-token',
13
- * });
10
+ * // Quick start from environment variables
11
+ * const orqo = OrqoClient.fromEnv();
14
12
  *
15
- * // Provision a new instance with WhatsApp
16
- * const { instance, result } = await orqo.provision({
17
- * name: 'My Bot',
18
- * webhookUrl: 'https://your-app.com/webhooks',
19
- * });
13
+ * // Fluent provisioning with builder pattern
14
+ * const { instance } = await orqo
15
+ * .provision('My Restaurant')
16
+ * .withLLM(LLMProvider.OPENAI, 'gpt-4o-mini', process.env.OPENAI_KEY!)
17
+ * .withAgent('Atendente', 'Você é um atendente educado.')
18
+ * .withWebhook('https://my-api.com/events')
19
+ * .execute();
20
20
  *
21
- * // Wait for QR scan (with live QR callback)
22
- * await instance.waitForConnection({
23
- * onQr: (qr) => console.log('Scan this QR:', qr),
24
- * });
21
+ * // Send a message (auto-formats phone to JID)
22
+ * await instance.send('5511999887766', 'Hello from Orqo! 🚀');
25
23
  *
26
- * // Send a message
27
- * await instance.sendMessage({
28
- * to: '5511999887766@s.whatsapp.net',
29
- * text: 'Hello from Orqo! 🚀',
30
- * });
24
+ * // Build agents fluently
25
+ * await instance
26
+ * .agent('Specialist')
27
+ * .prompt('You handle refunds.')
28
+ * .tools('refund_tool', 'lookup_order')
29
+ * .identity('Carlos', '🧑‍💻')
30
+ * .create();
31
31
  * ```
32
32
  */
33
33
  export { OrqoClient } from './client.js';
34
34
  export { OrqoInstance } from './instance.js';
35
35
  export { createWebhookHandler } from './webhook-handler.js';
36
- export { OrqoError, type OrqoClientConfig, type OrqoInstanceConfig, type RetryConfig, type ProvisionOptions, type ProvisionResult, type WhatsAppStatus, type SendMessageOptions, type SendMessageResult, type InstanceStatus, type AgentConfig, type Agent, type WebhookConfig, type Webhook, type GuardrailConfig, type HandoffOptions, type HandoffResult, type WebhookEvent, type ConnectionChangedEvent, type MessageReceivedEvent, type MessageProcessedEvent, type HandoffEvent, type OrqoWebhookEvent, type WebhookHandlerOptions, } from './types.js';
36
+ export { AgentBuilder, ProvisionBuilder } from './builders.js';
37
+ export { Events, LLMProvider, AgentType, WhatsAppState, GuardrailAction, DEFAULT_WEBHOOK_EVENTS, type EventType, type LLMProviderType, type AgentTypeValue, } from './constants.js';
38
+ export { OrqoError, type OrqoClientConfig, type OrqoInstanceConfig, type RetryConfig, type ProvisionOptions, type ProvisionResult, type WhatsAppStatus, type SendMessageOptions, type SendMessageResult, type InstanceStatus, type AgentConfig, type Agent, type WebhookConfig, type Webhook, type GuardrailConfig, type HandoffOptions, type HandoffResult, type WebhookEvent, type ConnectionChangedEvent, type MessageReceivedEvent, type MessageProcessedEvent, type HandoffEvent, type OrqoWebhookEvent, type WebhookHandlerOptions, type InstanceStats, type CronJob, type BackgroundJob, type InstanceLimits, type SessionInfo, type MessageRecord, } from './types.js';
package/dist/index.js CHANGED
@@ -1,36 +1,42 @@
1
1
  /**
2
- * @orqo/sdk — Plug-and-Play WhatsApp Integration
2
+ * orqo-node-sdk — Plug-and-Play WhatsApp + AI Agent Integration
3
3
  *
4
4
  * Zero-dependency TypeScript SDK for the Orqo Gateway.
5
5
  *
6
6
  * @example
7
7
  * ```typescript
8
- * import { OrqoClient } from '@orqo/sdk';
8
+ * import { OrqoClient, Events, LLMProvider } from 'orqo-node-sdk';
9
9
  *
10
- * const orqo = new OrqoClient({
11
- * host: 'https://orqo.example.com',
12
- * adminToken: 'your-admin-token',
13
- * });
10
+ * // Quick start from environment variables
11
+ * const orqo = OrqoClient.fromEnv();
14
12
  *
15
- * // Provision a new instance with WhatsApp
16
- * const { instance, result } = await orqo.provision({
17
- * name: 'My Bot',
18
- * webhookUrl: 'https://your-app.com/webhooks',
19
- * });
13
+ * // Fluent provisioning with builder pattern
14
+ * const { instance } = await orqo
15
+ * .provision('My Restaurant')
16
+ * .withLLM(LLMProvider.OPENAI, 'gpt-4o-mini', process.env.OPENAI_KEY!)
17
+ * .withAgent('Atendente', 'Você é um atendente educado.')
18
+ * .withWebhook('https://my-api.com/events')
19
+ * .execute();
20
20
  *
21
- * // Wait for QR scan (with live QR callback)
22
- * await instance.waitForConnection({
23
- * onQr: (qr) => console.log('Scan this QR:', qr),
24
- * });
21
+ * // Send a message (auto-formats phone to JID)
22
+ * await instance.send('5511999887766', 'Hello from Orqo! 🚀');
25
23
  *
26
- * // Send a message
27
- * await instance.sendMessage({
28
- * to: '5511999887766@s.whatsapp.net',
29
- * text: 'Hello from Orqo! 🚀',
30
- * });
24
+ * // Build agents fluently
25
+ * await instance
26
+ * .agent('Specialist')
27
+ * .prompt('You handle refunds.')
28
+ * .tools('refund_tool', 'lookup_order')
29
+ * .identity('Carlos', '🧑‍💻')
30
+ * .create();
31
31
  * ```
32
32
  */
33
+ // Core classes
33
34
  export { OrqoClient } from './client.js';
34
35
  export { OrqoInstance } from './instance.js';
35
36
  export { createWebhookHandler } from './webhook-handler.js';
37
+ // Fluent builders
38
+ export { AgentBuilder, ProvisionBuilder } from './builders.js';
39
+ // Constants (enum-like, with string escape hatches)
40
+ export { Events, LLMProvider, AgentType, WhatsAppState, GuardrailAction, DEFAULT_WEBHOOK_EVENTS, } from './constants.js';
41
+ // Type exports
36
42
  export { OrqoError, } from './types.js';
@@ -5,7 +5,8 @@
5
5
  * Guardrails, Handoff, and API Bridge — scoped to a specific
6
6
  * instance + API token.
7
7
  */
8
- import type { OrqoInstanceConfig, WhatsAppStatus, SendMessageOptions, SendMessageResult, InstanceStatus, AgentConfig, Agent, WebhookConfig, Webhook, GuardrailConfig, HandoffOptions, HandoffResult } from './types.js';
8
+ import type { OrqoInstanceConfig, WhatsAppStatus, SendMessageOptions, SendMessageResult, InstanceStatus, AgentConfig, Agent, WebhookConfig, Webhook, GuardrailConfig, HandoffOptions, HandoffResult, InstanceStats, CronJob, BackgroundJob, InstanceLimits, SessionInfo, MessageRecord } from './types.js';
9
+ import { AgentBuilder } from './builders.js';
9
10
  export declare class OrqoInstance {
10
11
  readonly instanceId: string;
11
12
  private readonly host;
@@ -39,18 +40,66 @@ export declare class OrqoInstance {
39
40
  timeoutMs?: number;
40
41
  onQr?: (qr: string) => void;
41
42
  }): Promise<WhatsAppStatus>;
42
- /** Send a text message via WhatsApp. */
43
+ /** Send a text message via WhatsApp (full options). */
43
44
  sendMessage(options: SendMessageOptions): Promise<SendMessageResult>;
45
+ /**
46
+ * Send a message with automatic JID formatting.
47
+ *
48
+ * @param phone - Phone number (e.g. "5511999887766") or full JID
49
+ * @param text - Text content to send
50
+ * @param opts - Optional extra parameters
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * // Simple — phone number auto-formatted to JID
55
+ * await instance.send('5511999887766', 'Seu pedido saiu!');
56
+ *
57
+ * // With options
58
+ * await instance.send('5511999887766', 'Confira!', { quotedMessageId: 'msg123' });
59
+ * ```
60
+ */
61
+ send(phone: string, text: string, opts?: Record<string, unknown>): Promise<SendMessageResult>;
44
62
  /** Create a new agent for this instance. */
45
63
  createAgent(config: AgentConfig): Promise<Agent>;
64
+ /**
65
+ * Start building an agent with a fluent API.
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * const agent = await instance
70
+ * .agent('Atendente')
71
+ * .prompt('Você é um atendente educado.')
72
+ * .tools('search', 'calendar')
73
+ * .identity('Ana', '👩‍💼')
74
+ * .create();
75
+ * ```
76
+ */
77
+ agent(name: string): AgentBuilder;
46
78
  /** List all agents. */
47
79
  listAgents(): Promise<Agent[]>;
48
80
  /** Update an existing agent. */
49
81
  updateAgent(agentId: string, updates: Partial<AgentConfig>): Promise<Agent>;
50
82
  /** Delete an agent. */
51
83
  deleteAgent(agentId: string): Promise<void>;
52
- /** Register a webhook to receive events. */
53
- addWebhook(config: WebhookConfig): Promise<Webhook>;
84
+ /**
85
+ * Register a webhook to receive events.
86
+ *
87
+ * Accepts a URL string (with all defaults applied) or a full config object.
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * // Shorthand — just a URL, all defaults applied
92
+ * await instance.addWebhook('https://my-api.com/hook');
93
+ *
94
+ * // Full config
95
+ * await instance.addWebhook({
96
+ * url: 'https://my-api.com/hook',
97
+ * events: [Events.MESSAGE_RECEIVED],
98
+ * name: 'My Hook',
99
+ * });
100
+ * ```
101
+ */
102
+ addWebhook(urlOrConfig: string | WebhookConfig): Promise<Webhook>;
54
103
  /** List all registered webhooks. */
55
104
  listWebhooks(): Promise<Webhook[]>;
56
105
  /** Remove a webhook. */
@@ -64,33 +113,33 @@ export declare class OrqoInstance {
64
113
  /** Resume bot control of a conversation after human handoff. */
65
114
  resumeBot(sessionId: string): Promise<HandoffResult>;
66
115
  /** Get instance statistics (messages, sessions, uptime). */
67
- getStats(): Promise<Record<string, unknown>>;
116
+ getStats(): Promise<InstanceStats>;
68
117
  /** Get conversation sessions with pagination. */
69
118
  getSessions(options?: {
70
119
  limit?: number;
71
120
  offset?: number;
72
- }): Promise<Array<Record<string, unknown>>>;
121
+ }): Promise<SessionInfo[]>;
73
122
  /** Get messages for a session or all messages. */
74
123
  getMessages(options?: {
75
124
  sessionKey?: string;
76
125
  limit?: number;
77
- }): Promise<Array<Record<string, unknown>>>;
126
+ }): Promise<MessageRecord[]>;
78
127
  /** Force reconnect WhatsApp (useful for stale connections). */
79
128
  reconnectWhatsApp(): Promise<InstanceStatus>;
80
129
  /** Get a specific agent by ID. */
81
130
  getAgent(agentId: string): Promise<Agent>;
82
131
  /** List cron jobs for this instance. */
83
- listCronJobs(): Promise<Array<Record<string, unknown>>>;
132
+ listCronJobs(): Promise<CronJob[]>;
84
133
  /** Create a new cron job. */
85
134
  createCronJob(config: {
86
135
  schedule: string;
87
136
  action: string;
88
137
  payload?: Record<string, unknown>;
89
- }): Promise<Record<string, unknown>>;
138
+ }): Promise<CronJob>;
90
139
  /** Delete a cron job. */
91
140
  deleteCronJob(jobId: string): Promise<void>;
92
141
  /** Manually trigger a cron job. */
93
- runCronJob(jobId: string): Promise<Record<string, unknown>>;
142
+ runCronJob(jobId: string): Promise<CronJob>;
94
143
  /**
95
144
  * Connect an external API via OpenAPI spec.
96
145
  * The agent will automatically gain tools from the spec.
@@ -138,15 +187,24 @@ export declare class OrqoInstance {
138
187
  tools: string[];
139
188
  }>;
140
189
  /** Update an existing webhook configuration. */
141
- updateWebhook(webhookId: string, updates: Record<string, unknown>): Promise<Record<string, unknown>>;
190
+ updateWebhook(webhookId: string, updates: Partial<WebhookConfig>): Promise<Webhook>;
142
191
  /** Send a test event to a webhook endpoint. */
143
- testWebhook(webhookId: string): Promise<Record<string, unknown>>;
192
+ testWebhook(webhookId: string): Promise<{
193
+ success: boolean;
194
+ statusCode: number;
195
+ [key: string]: unknown;
196
+ }>;
144
197
  /** Update an existing cron job. */
145
- updateCronJob(jobId: string, updates: Record<string, unknown>): Promise<Record<string, unknown>>;
198
+ updateCronJob(jobId: string, updates: Partial<CronJob>): Promise<CronJob>;
146
199
  /** Get resource limits and current usage. */
147
- getLimits(): Promise<Record<string, unknown>>;
200
+ getLimits(): Promise<InstanceLimits>;
148
201
  /** Create a backup of this instance. */
149
- backup(): Promise<Record<string, unknown>>;
202
+ backup(): Promise<{
203
+ url: string;
204
+ size: number;
205
+ createdAt: string;
206
+ [key: string]: unknown;
207
+ }>;
150
208
  /** Generate an agent configuration using AI. */
151
209
  generateAgent(config: {
152
210
  name: string;
@@ -155,12 +213,12 @@ export declare class OrqoInstance {
155
213
  language?: string;
156
214
  }): Promise<Agent>;
157
215
  /** List all background jobs for this instance. */
158
- listBackgroundJobs(): Promise<Record<string, unknown>[]>;
216
+ listBackgroundJobs(): Promise<BackgroundJob[]>;
159
217
  /** Get a specific background job by ID. */
160
- getBackgroundJob(jobId: string): Promise<Record<string, unknown>>;
218
+ getBackgroundJob(jobId: string): Promise<BackgroundJob>;
161
219
  /** Create a new background job. */
162
220
  createBackgroundJob(config: {
163
221
  agentId: string;
164
222
  input: string;
165
- }): Promise<Record<string, unknown>>;
223
+ }): Promise<BackgroundJob>;
166
224
  }
package/dist/instance.js CHANGED
@@ -6,12 +6,21 @@
6
6
  * instance + API token.
7
7
  */
8
8
  import { OrqoError } from './types.js';
9
+ import { AgentBuilder } from './builders.js';
10
+ import { DEFAULT_WEBHOOK_EVENTS } from './constants.js';
9
11
  const DEFAULT_RETRY = {
10
12
  maxAttempts: 3,
11
13
  backoffMs: 1000,
12
14
  multiplier: 2,
13
15
  retryOn: [429, 500, 502, 503, 504],
14
16
  };
17
+ /** Format a phone number to WhatsApp JID */
18
+ function toJid(phone) {
19
+ if (phone.includes('@'))
20
+ return phone; // Already a JID
21
+ const cleaned = phone.replace(/[\s\-\(\)\+]/g, '');
22
+ return `${cleaned}@s.whatsapp.net`;
23
+ }
15
24
  export class OrqoInstance {
16
25
  instanceId;
17
26
  host;
@@ -115,23 +124,62 @@ export class OrqoInstance {
115
124
  // --------------------------------------------------------------------------
116
125
  // Messaging
117
126
  // --------------------------------------------------------------------------
118
- /** Send a text message via WhatsApp. */
127
+ /** Send a text message via WhatsApp (full options). */
119
128
  async sendMessage(options) {
120
129
  return this.request('/messages/send', {
121
130
  method: 'POST',
122
131
  body: JSON.stringify(options),
123
132
  });
124
133
  }
134
+ /**
135
+ * Send a message with automatic JID formatting.
136
+ *
137
+ * @param phone - Phone number (e.g. "5511999887766") or full JID
138
+ * @param text - Text content to send
139
+ * @param opts - Optional extra parameters
140
+ *
141
+ * @example
142
+ * ```typescript
143
+ * // Simple — phone number auto-formatted to JID
144
+ * await instance.send('5511999887766', 'Seu pedido saiu!');
145
+ *
146
+ * // With options
147
+ * await instance.send('5511999887766', 'Confira!', { quotedMessageId: 'msg123' });
148
+ * ```
149
+ */
150
+ async send(phone, text, opts) {
151
+ return this.sendMessage({ to: toJid(phone), text, ...opts });
152
+ }
125
153
  // --------------------------------------------------------------------------
126
154
  // Agent CRUD
127
155
  // --------------------------------------------------------------------------
128
156
  /** Create a new agent for this instance. */
129
157
  async createAgent(config) {
158
+ const payload = {
159
+ type: 'chat', // Default to chat agent
160
+ ...config
161
+ };
130
162
  return this.request('/agents', {
131
163
  method: 'POST',
132
- body: JSON.stringify(config),
164
+ body: JSON.stringify(payload),
133
165
  });
134
166
  }
167
+ /**
168
+ * Start building an agent with a fluent API.
169
+ *
170
+ * @example
171
+ * ```typescript
172
+ * const agent = await instance
173
+ * .agent('Atendente')
174
+ * .prompt('Você é um atendente educado.')
175
+ * .tools('search', 'calendar')
176
+ * .identity('Ana', '👩‍💼')
177
+ * .create();
178
+ * ```
179
+ */
180
+ agent(name) {
181
+ return new AgentBuilder(this, name);
182
+ }
135
183
  /** List all agents. */
136
184
  async listAgents() {
137
185
  return this.request('/agents');
@@ -150,11 +198,37 @@ export class OrqoInstance {
150
198
  // --------------------------------------------------------------------------
151
199
  // Webhook Management
152
200
  // --------------------------------------------------------------------------
153
- /** Register a webhook to receive events. */
154
- async addWebhook(config) {
201
+ /**
202
+ * Register a webhook to receive events.
203
+ *
204
+ * Accepts a URL string (with all defaults applied) or a full config object.
205
+ *
206
+ * @example
207
+ * ```typescript
208
+ * // Shorthand — just a URL, all defaults applied
209
+ * await instance.addWebhook('https://my-api.com/hook');
210
+ *
211
+ * // Full config
212
+ * await instance.addWebhook({
213
+ * url: 'https://my-api.com/hook',
214
+ * events: [Events.MESSAGE_RECEIVED],
215
+ * name: 'My Hook',
216
+ * });
217
+ * ```
218
+ */
219
+ async addWebhook(urlOrConfig) {
220
+ const config = typeof urlOrConfig === 'string'
221
+ ? { url: urlOrConfig }
222
+ : urlOrConfig;
223
+ const payload = {
224
+ name: config.name || `Webhook ${Date.now()}`,
225
+ events: config.events || [...DEFAULT_WEBHOOK_EVENTS],
226
+ enabled: config.enabled ?? true,
227
+ ...config
228
+ };
155
229
  return this.request('/webhooks', {
156
230
  method: 'POST',
157
- body: JSON.stringify(config),
231
+ body: JSON.stringify(payload),
158
232
  });
159
233
  }
160
234
  /** List all registered webhooks. */
@@ -200,7 +274,7 @@ export class OrqoInstance {
200
274
  });
201
275
  }
202
276
  // --------------------------------------------------------------------------
203
- // Stats & Messages
277
+ // Stats & Messages (Strong Types)
204
278
  // --------------------------------------------------------------------------
205
279
  /** Get instance statistics (messages, sessions, uptime). */
206
280
  async getStats() {
@@ -241,7 +315,7 @@ export class OrqoInstance {
241
315
  return this.request(`/agents/${agentId}`);
242
316
  }
243
317
  // --------------------------------------------------------------------------
244
- // Cron Jobs
318
+ // Cron Jobs (Strong Types)
245
319
  // --------------------------------------------------------------------------
246
320
  /** List cron jobs for this instance. */
247
321
  async listCronJobs() {
@@ -345,7 +419,7 @@ export class OrqoInstance {
345
419
  });
346
420
  }
347
421
  // --------------------------------------------------------------------------
348
- // Background Jobs
422
+ // Background Jobs (Strong Types)
349
423
  // --------------------------------------------------------------------------
350
424
  /** List all background jobs for this instance. */
351
425
  async listBackgroundJobs() {
package/dist/types.d.ts CHANGED
@@ -44,6 +44,19 @@ export interface ProvisionOptions {
44
44
  webhookUrl?: string;
45
45
  /** HMAC secret for webhook signature verification */
46
46
  webhookSecret?: string;
47
+ /** Initial LLM Model Configuration */
48
+ llm?: {
49
+ provider: 'openai' | 'gemini' | 'anthropic' | 'groq' | string;
50
+ model: string;
51
+ apiKey: string;
52
+ [key: string]: unknown;
53
+ };
54
+ /** Initial Telegram Channel Configuration */
55
+ telegram?: {
56
+ enabled?: boolean;
57
+ botToken: string;
58
+ webhookSecret?: string;
59
+ };
47
60
  /** Additional instance configuration */
48
61
  config?: Record<string, unknown>;
49
62
  }
@@ -82,7 +95,7 @@ export interface AgentConfig {
82
95
  id?: string;
83
96
  /** Human-readable agent name */
84
97
  name: string;
85
- /** Agent type */
98
+ /** Agent type (Defaults to 'chat') */
86
99
  type?: 'chat' | 'router' | 'specialist';
87
100
  /** System prompt / instructions for the LLM */
88
101
  systemPrompt?: string;
@@ -95,6 +108,10 @@ export interface AgentConfig {
95
108
  };
96
109
  /** Routing rules for multi-agent setups */
97
110
  routingRules?: Record<string, unknown>;
111
+ /** Fallback Agent ID if this is a Router */
112
+ defaultAgentId?: string | null;
113
+ /** Message sent if no route matches (Router type) */
114
+ noRouteMessage?: string | null;
98
115
  /** Additional configuration */
99
116
  [key: string]: unknown;
100
117
  }
@@ -103,12 +120,16 @@ export interface Agent extends AgentConfig {
103
120
  createdAt?: number;
104
121
  }
105
122
  export interface WebhookConfig {
123
+ /** Human-readable name for the webhook */
124
+ name?: string;
106
125
  /** Destination URL for webhook delivery */
107
126
  url: string;
108
127
  /** HMAC secret for signature verification */
109
128
  secret?: string;
110
- /** Event type to listen for */
111
- event: string;
129
+ /** Events to listen for (Defaults to all message and session events) */
130
+ events?: string[];
131
+ /** Whether the webhook is enabled right away (Defaults to true) */
132
+ enabled?: boolean;
112
133
  }
113
134
  export interface Webhook extends WebhookConfig {
114
135
  id: string;
@@ -192,6 +213,66 @@ export interface WebhookHandlerOptions {
192
213
  /** Called on signature verification failure */
193
214
  onVerificationFailed?: (error: Error) => void;
194
215
  }
216
+ export interface InstanceStats {
217
+ totalMessages: number;
218
+ activeSessions: number;
219
+ uptime: number;
220
+ connectedChannels: string[];
221
+ /** Additional stats from the server */
222
+ [key: string]: unknown;
223
+ }
224
+ export interface CronJob {
225
+ id: string;
226
+ schedule: string;
227
+ action: string;
228
+ payload?: Record<string, unknown>;
229
+ enabled: boolean;
230
+ lastRun?: number;
231
+ nextRun?: number;
232
+ /** Additional fields */
233
+ [key: string]: unknown;
234
+ }
235
+ export interface BackgroundJob {
236
+ id: string;
237
+ agentId: string;
238
+ input: string;
239
+ status: 'pending' | 'running' | 'completed' | 'failed' | string;
240
+ result?: string;
241
+ error?: string;
242
+ createdAt: number;
243
+ completedAt?: number;
244
+ /** Additional fields */
245
+ [key: string]: unknown;
246
+ }
247
+ export interface InstanceLimits {
248
+ maxAgents: number;
249
+ maxWebhooks: number;
250
+ maxCronJobs: number;
251
+ currentAgents: number;
252
+ currentWebhooks: number;
253
+ currentCronJobs: number;
254
+ /** Additional limits */
255
+ [key: string]: unknown;
256
+ }
257
+ export interface SessionInfo {
258
+ sessionKey: string;
259
+ contactJid: string;
260
+ lastMessageAt: number;
261
+ messageCount: number;
262
+ agentId?: string;
263
+ /** Additional session data */
264
+ [key: string]: unknown;
265
+ }
266
+ export interface MessageRecord {
267
+ id: string;
268
+ sessionKey: string;
269
+ role: 'user' | 'assistant' | 'system' | string;
270
+ content: string;
271
+ timestamp: number;
272
+ agentId?: string;
273
+ /** Additional message data */
274
+ [key: string]: unknown;
275
+ }
195
276
  export declare class OrqoError extends Error {
196
277
  readonly status: number;
197
278
  readonly body?: unknown | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orqo-node-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Orqo Gateway — TypeScript SDK for plug-and-play WhatsApp integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",