@runflow-ai/sdk 1.0.38 → 1.0.40

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
@@ -740,115 +740,205 @@ The `execute` function receives:
740
740
 
741
741
  ### Connectors
742
742
 
743
- **Connectors** are pre-configured integrations with external services (HubSpot, Twilio, Email, Slack).
743
+ **Connectors** are dynamic integrations with external services defined in the Runflow backend. Connector tools automatically load schemas from the backend, support mock execution, and handle path parameters seamlessly.
744
+
745
+ #### Key Features
746
+
747
+ - 🔄 **Dynamic Schema Loading** - Schemas are fetched from the backend automatically
748
+ - 🎭 **Transparent Mocking** - Enable mock mode for development and testing
749
+ - 🛣️ **Path Parameter Resolution** - Automatic extraction and URL building
750
+ - ⚡ **Lazy Initialization** - Schemas loaded only when needed, cached globally
751
+ - 🔐 **Flexible Authentication** - Supports API Key, Bearer Token, Basic Auth, OAuth2
752
+ - ✅ **Type-Safe** - Automatic JSON Schema → Zod → LLM Parameters conversion
744
753
 
745
754
  #### Create Connector Tool
746
755
 
747
756
  ```typescript
748
- import { createConnectorTool } from '@runflow-ai/sdk';
757
+ import { createConnectorTool, Agent, openai } from '@runflow-ai/sdk';
749
758
 
750
- // HubSpot - Create contact
751
- const createContact = createConnectorTool(
752
- 'hubspot',
753
- 'contacts',
754
- 'create',
755
- {
756
- email: 'email',
757
- firstName: 'string?',
758
- lastName: 'string?',
759
- phone: 'string?',
760
- company: 'string?',
761
- }
762
- );
759
+ // Basic connector tool (schema loaded from backend)
760
+ const getClienteTool = createConnectorTool({
761
+ connector: 'api-contabil',
762
+ resource: 'clientes',
763
+ action: 'get',
764
+ description: 'Get customer by ID from accounting API',
765
+ enableMock: true, // Optional: enables mock mode
766
+ });
763
767
 
764
- // Twilio - Send WhatsApp
765
- const sendWhatsApp = createConnectorTool(
766
- 'twilio',
767
- 'messages',
768
- 'send-whatsapp',
769
- {
770
- to: 'string',
771
- message: 'string',
772
- mediaUrl: 'url?',
773
- }
774
- );
768
+ // Use with Agent
769
+ const agent = new Agent({
770
+ name: 'Accounting Agent',
771
+ instructions: 'You help manage customers in the accounting system.',
772
+ model: openai('gpt-4o'),
773
+ tools: {
774
+ getCliente: getClienteTool,
775
+ listClientes: createConnectorTool({
776
+ connector: 'api-contabil',
777
+ resource: 'clientes',
778
+ action: 'list',
779
+ }),
780
+ },
781
+ });
775
782
 
776
- // Email - Send email
777
- const sendEmail = createConnectorTool(
778
- 'email',
779
- 'messages',
780
- 'send',
781
- {
782
- to: 'email',
783
- subject: 'string',
784
- body: 'string',
785
- html: 'boolean?',
786
- }
787
- );
783
+ // First execution automatically loads schemas from backend
784
+ const result = await agent.process({
785
+ message: 'Get customer with ID 123',
786
+ sessionId: 'session-123',
787
+ companyId: 'company-456',
788
+ });
789
+ ```
788
790
 
789
- // Slack - Send message
790
- const sendSlack = createConnectorTool(
791
- 'slack',
792
- 'messages',
793
- 'send',
794
- {
795
- channel: 'string',
796
- message: 'string',
797
- username: 'string?',
798
- iconEmoji: 'string?',
799
- }
800
- );
791
+ #### Connector Tool Configuration
792
+
793
+ ```typescript
794
+ createConnectorTool({
795
+ connector: string, // Connector instance name (e.g., 'hubspot', 'api-contabil')
796
+ resource: string, // Resource name (e.g., 'contacts', 'clientes', 'tickets')
797
+ action: string, // Action name (e.g., 'get', 'list', 'create', 'update')
798
+ description?: string, // Optional: Custom description (defaults to auto-generated)
799
+ enableMock?: boolean, // Optional: Enable mock mode (adds useMock parameter)
800
+ })
801
801
  ```
802
802
 
803
- #### Use Built-in Shortcuts
803
+ #### Multiple Connector Tools
804
804
 
805
805
  ```typescript
806
- import { hubspot, twilio, email, slack } from '@runflow-ai/sdk';
806
+ // Create multiple tools for the same connector
807
+ const tools = {
808
+ listClientes: createConnectorTool({
809
+ connector: 'api-contabil',
810
+ resource: 'clientes',
811
+ action: 'list',
812
+ enableMock: true,
813
+ }),
814
+
815
+ getCliente: createConnectorTool({
816
+ connector: 'api-contabil',
817
+ resource: 'clientes',
818
+ action: 'get',
819
+ enableMock: true,
820
+ }),
821
+
822
+ createCliente: createConnectorTool({
823
+ connector: 'api-contabil',
824
+ resource: 'clientes',
825
+ action: 'create',
826
+ enableMock: true,
827
+ }),
828
+ };
807
829
 
808
830
  const agent = new Agent({
809
- name: 'Support Agent',
810
- instructions: 'You help customers.',
831
+ name: 'Customer Management Agent',
832
+ instructions: 'You help manage customers.',
833
+ model: openai('gpt-4o'),
834
+ tools,
835
+ });
836
+
837
+ // All schemas are loaded in parallel on first execution
838
+ const result = await agent.process({
839
+ message: 'Create a new customer named ACME Corp',
840
+ sessionId: 'session-123',
841
+ companyId: 'company-456',
842
+ });
843
+ ```
844
+
845
+ #### Using loadConnector Helper
846
+
847
+ For connectors with many resources, use the `loadConnector` helper:
848
+
849
+ ```typescript
850
+ import { loadConnector } from '@runflow-ai/sdk';
851
+
852
+ const contabil = loadConnector('api-contabil');
853
+
854
+ const agent = new Agent({
855
+ name: 'Accounting Agent',
856
+ instructions: 'You manage accounting data.',
811
857
  model: openai('gpt-4o'),
812
858
  tools: {
813
- // Built-in connector shortcuts
814
- createContact: hubspot.createContact(),
815
- getContact: hubspot.getContact(),
816
- createTicket: hubspot.createTicket(),
817
- sendWhatsApp: twilio.sendWhatsApp(),
818
- sendSMS: twilio.sendSMS(),
819
- sendEmail: email.send(),
820
- sendSlack: slack.sendMessage(),
859
+ listClientes: contabil.tool('clientes', 'list'),
860
+ getCliente: contabil.tool('clientes', 'get'),
861
+ createCliente: contabil.tool('clientes', 'create'),
862
+ updateCliente: contabil.tool('clientes', 'update'),
821
863
  },
822
864
  });
823
865
  ```
824
866
 
825
- #### Parameter Types
867
+ #### Path Parameters
868
+
869
+ Connectors automatically resolve path parameters from the resource URL:
826
870
 
827
871
  ```typescript
828
- const tool = createConnectorTool('service', 'resource', 'action', {
829
- // Basic types
830
- name: 'string',
831
- age: 'number',
832
- active: 'boolean',
833
- createdAt: 'date',
872
+ // Resource defined in backend: /clientes/{id}/pedidos/{pedidoId}
873
+ const getClientePedidoTool = createConnectorTool({
874
+ connector: 'api-contabil',
875
+ resource: 'clientes.pedidos',
876
+ action: 'get',
877
+ description: 'Get specific order from a customer',
878
+ });
879
+
880
+ // Agent automatically extracts path params from context
881
+ const result = await agent.process({
882
+ message: 'Get order 456 from customer 123',
883
+ sessionId: 'session-123',
884
+ companyId: 'company-456',
885
+ });
886
+
887
+ // Backend automatically resolves: /clientes/123/pedidos/456
888
+ ```
834
889
 
835
- // Optional (append ?)
836
- nickname: 'string?',
837
- score: 'number?',
890
+ #### Mock Execution
838
891
 
839
- // Special validations
840
- email: 'email',
841
- website: 'url',
892
+ Enable mock mode for development and testing:
842
893
 
843
- // Enum
844
- priority: { enum: ['low', 'medium', 'high'] },
894
+ ```typescript
895
+ const tool = createConnectorTool({
896
+ connector: 'api-contabil',
897
+ resource: 'clientes',
898
+ action: 'list',
899
+ enableMock: true, // Adds useMock parameter
900
+ });
845
901
 
846
- // Arrays
847
- tags: { array: 'string' },
848
- scores: { array: 'number' },
902
+ // Use mock mode in development
903
+ const result = await agent.process({
904
+ message: 'List customers (use mock data)',
905
+ sessionId: 'dev-session',
906
+ companyId: 'dev-company',
907
+ // Tool will automatically include useMock=true if mock data is configured
849
908
  });
850
909
  ```
851
910
 
911
+ #### How It Works
912
+
913
+ 1. **Tool Creation**: `createConnectorTool` creates a tool with a temporary schema
914
+ 2. **Lazy Loading**: On first agent execution, schemas are fetched from the backend in parallel
915
+ 3. **Schema Conversion**: JSON Schema → Zod → LLM Parameters (automatic)
916
+ 4. **Caching**: Schemas are cached globally to avoid repeated API calls
917
+ 5. **Execution**: Tool executes with proper authentication, path resolution, and error handling
918
+
919
+ #### Automatic Setup
920
+
921
+ The Agent automatically initializes connector tools on first execution:
922
+
923
+ ```typescript
924
+ const agent = new Agent({
925
+ name: 'My Agent',
926
+ model: openai('gpt-4o'),
927
+ tools: {
928
+ // Connector tools are automatically identified and initialized
929
+ tool1: createConnectorTool({ ... }),
930
+ tool2: createTool({ ... }), // Regular tool
931
+ tool3: createConnectorTool({ ... }),
932
+ },
933
+ });
934
+
935
+ // First process() call:
936
+ // 1. Identifies connector tools (marked with _isConnectorTool)
937
+ // 2. Loads schemas in parallel from backend
938
+ // 3. Updates tool parameters
939
+ // 4. Proceeds with normal execution
940
+ ```
941
+
852
942
  ---
853
943
 
854
944
  ### Workflows
@@ -1030,6 +1120,61 @@ const connectorStep = createConnectorStep(
1030
1120
 
1031
1121
  ---
1032
1122
 
1123
+ ### Prompts
1124
+
1125
+ The **Prompts** module manages prompt templates with support for global and tenant-specific prompts.
1126
+
1127
+ #### Standalone Prompts Manager
1128
+
1129
+ ```typescript
1130
+ import { Prompts } from '@runflow-ai/sdk';
1131
+
1132
+ const prompts = new Prompts();
1133
+
1134
+ // Get prompt (global or tenant-specific)
1135
+ const prompt = await prompts.get('sistema');
1136
+ console.log(prompt.content);
1137
+ console.log('Is global?', prompt.isGlobal);
1138
+
1139
+ // List all available prompts
1140
+ const allPrompts = await prompts.list({ limit: 50 });
1141
+ allPrompts.forEach(p => {
1142
+ console.log(`${p.name} ${p.isGlobal ? '🌍' : '🏢'}`);
1143
+ });
1144
+
1145
+ // Create tenant-specific prompt
1146
+ const custom = await prompts.create(
1147
+ 'my-prompt',
1148
+ 'You are a specialist in {{topic}}.',
1149
+ { variables: ['topic'] }
1150
+ );
1151
+
1152
+ // Update tenant prompt
1153
+ await prompts.update('my-prompt', {
1154
+ content: 'You are a SENIOR specialist in {{topic}}.'
1155
+ });
1156
+
1157
+ // Delete tenant prompt
1158
+ await prompts.delete('my-prompt');
1159
+
1160
+ // Render template with variables
1161
+ const rendered = prompts.render(
1162
+ 'Hello {{name}}, welcome to {{company}}!',
1163
+ { name: 'John', company: 'Runflow' }
1164
+ );
1165
+
1166
+ // Get and render in one call
1167
+ const text = await prompts.getAndRender('my-prompt', { topic: 'AI' });
1168
+ ```
1169
+
1170
+ **Security Rules:**
1171
+ - ✅ Can read global prompts (provided by Runflow)
1172
+ - ✅ Can create/update/delete own tenant prompts
1173
+ - ❌ Cannot modify global prompts
1174
+ - ❌ Cannot access other tenants' prompts
1175
+
1176
+ ---
1177
+
1033
1178
  ### Knowledge (RAG)
1034
1179
 
1035
1180
  The **Knowledge** module (also called RAG) manages semantic search in vector knowledge bases.
@@ -1,5 +1,15 @@
1
1
  import { z } from 'zod';
2
- export declare function createConnectorTool(connector: string, resource: string, action: string, parameters: ConnectorParameters, options?: ConnectorToolOptions): import("..").RunflowTool;
2
+ import { RunflowTool } from '../types';
3
+ export declare function createConnectorTool(config: {
4
+ connector: string;
5
+ resource: string;
6
+ action: string;
7
+ description?: string;
8
+ enableMock?: boolean;
9
+ }): RunflowTool;
10
+ export declare function loadConnector(name: string): {
11
+ tool(resource: string, action: string): RunflowTool;
12
+ };
3
13
  export type ConnectorParameters = Record<string, ConnectorParameter>;
4
14
  export type ConnectorParameter = 'string' | 'string?' | 'number' | 'number?' | 'boolean' | 'boolean?' | 'email' | 'email?' | 'url' | 'url?' | 'date' | 'date?' | {
5
15
  enum: string[];
@@ -12,18 +22,18 @@ export interface ConnectorToolOptions {
12
22
  outputSchema?: z.ZodSchema;
13
23
  }
14
24
  export declare const hubspot: {
15
- createContact: () => import("..").RunflowTool;
16
- getContact: () => import("..").RunflowTool;
17
- createTicket: () => import("..").RunflowTool;
25
+ createContact: () => RunflowTool;
26
+ getContact: () => RunflowTool;
27
+ createTicket: () => RunflowTool;
18
28
  };
19
29
  export declare const twilio: {
20
- sendWhatsApp: () => import("..").RunflowTool;
21
- sendSMS: () => import("..").RunflowTool;
30
+ sendWhatsApp: () => RunflowTool;
31
+ sendSMS: () => RunflowTool;
22
32
  };
23
33
  export declare const email: {
24
- send: () => import("..").RunflowTool;
34
+ send: () => RunflowTool;
25
35
  };
26
36
  export declare const slack: {
27
- sendMessage: () => import("..").RunflowTool;
37
+ sendMessage: () => RunflowTool;
28
38
  };
29
39
  //# sourceMappingURL=connector-creator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"connector-creator.d.ts","sourceRoot":"","sources":["../../src/connectors/connector-creator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,mBAAmB,EAC/B,OAAO,CAAC,EAAE,oBAAoB,4BAkB/B;AAMD,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;AAErE,MAAM,MAAM,kBAAkB,GAC1B,QAAQ,GACR,SAAS,GACT,QAAQ,GACR,SAAS,GACT,SAAS,GACT,UAAU,GACV,OAAO,GACP,QAAQ,GACR,KAAK,GACL,MAAM,GACN,MAAM,GACN,OAAO,GACP;IAAE,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,GAClB;IAAE,KAAK,EAAE,kBAAkB,CAAA;CAAE,CAAC;AAElC,MAAM,WAAW,oBAAoB;IACnC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC;CAC5B;AAkED,eAAO,MAAM,OAAO;;;;CAmBnB,CAAC;AAEF,eAAO,MAAM,MAAM;;;CAWlB,CAAC;AAEF,eAAO,MAAM,KAAK;;CASjB,CAAC;AAEF,eAAO,MAAM,KAAK;;CAOjB,CAAC"}
1
+ {"version":3,"file":"connector-creator.d.ts","sourceRoot":"","sources":["../../src/connectors/connector-creator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAiBvC,wBAAgB,mBAAmB,CAAC,MAAM,EAAE;IAC1C,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,GAAG,WAAW,CA+Fd;AAiMD,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM;mBAGvB,MAAM,UAAU,MAAM;EASxC;AAMD,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;AAErE,MAAM,MAAM,kBAAkB,GAC1B,QAAQ,GACR,SAAS,GACT,QAAQ,GACR,SAAS,GACT,SAAS,GACT,UAAU,GACV,OAAO,GACP,QAAQ,GACR,KAAK,GACL,MAAM,GACN,MAAM,GACN,OAAO,GACP;IAAE,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,GAClB;IAAE,KAAK,EAAE,kBAAkB,CAAA;CAAE,CAAC;AAElC,MAAM,WAAW,oBAAoB;IACnC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC;CAC5B;AAGD,eAAO,MAAM,OAAO;;;;CAqBnB,CAAC;AAEF,eAAO,MAAM,MAAM;;;CAclB,CAAC;AAEF,eAAO,MAAM,KAAK;;CAOjB,CAAC;AAEF,eAAO,MAAM,KAAK;;CAOjB,CAAC"}