@runflow-ai/sdk 1.0.39 → 1.0.41
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 +170 -80
- package/dist/connectors/connector-creator.d.ts +18 -8
- package/dist/connectors/connector-creator.d.ts.map +1 -1
- package/dist/connectors/connector-creator.js +268 -86
- package/dist/connectors/connector-creator.js.map +1 -1
- package/dist/connectors/index.d.ts +1 -1
- package/dist/connectors/index.d.ts.map +1 -1
- package/dist/connectors/index.js +2 -1
- package/dist/connectors/index.js.map +1 -1
- package/dist/core/agent.d.ts +8 -5
- package/dist/core/agent.d.ts.map +1 -1
- package/dist/core/agent.js +320 -65
- package/dist/core/agent.js.map +1 -1
- package/dist/core/api-client.d.ts +1 -1
- package/dist/core/api-client.d.ts.map +1 -1
- package/dist/core/api-client.js +12 -8
- package/dist/core/api-client.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/types/all-types.d.ts +66 -1
- package/dist/types/all-types.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -740,113 +740,203 @@ The `execute` function receives:
|
|
|
740
740
|
|
|
741
741
|
### Connectors
|
|
742
742
|
|
|
743
|
-
**Connectors** are
|
|
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
|
-
//
|
|
751
|
-
const
|
|
752
|
-
'
|
|
753
|
-
'
|
|
754
|
-
'
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
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
|
-
//
|
|
765
|
-
const
|
|
766
|
-
'
|
|
767
|
-
'
|
|
768
|
-
'
|
|
769
|
-
{
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
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
|
-
//
|
|
777
|
-
const
|
|
778
|
-
'
|
|
779
|
-
'
|
|
780
|
-
'
|
|
781
|
-
|
|
782
|
-
|
|
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
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
'
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
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
|
-
####
|
|
803
|
+
#### Multiple Connector Tools
|
|
804
804
|
|
|
805
805
|
```typescript
|
|
806
|
-
|
|
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: '
|
|
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
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
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
|
-
####
|
|
867
|
+
#### Path Parameters
|
|
868
|
+
|
|
869
|
+
Connectors automatically resolve path parameters from the resource URL:
|
|
826
870
|
|
|
827
871
|
```typescript
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
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
|
+
});
|
|
834
879
|
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
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
|
+
```
|
|
838
889
|
|
|
839
|
-
|
|
840
|
-
email: 'email',
|
|
841
|
-
website: 'url',
|
|
890
|
+
#### Mock Execution
|
|
842
891
|
|
|
843
|
-
|
|
844
|
-
priority: { enum: ['low', 'medium', 'high'] },
|
|
892
|
+
Enable mock mode for development and testing:
|
|
845
893
|
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
894
|
+
```typescript
|
|
895
|
+
const tool = createConnectorTool({
|
|
896
|
+
connector: 'api-contabil',
|
|
897
|
+
resource: 'clientes',
|
|
898
|
+
action: 'list',
|
|
899
|
+
enableMock: true, // Adds useMock parameter
|
|
900
|
+
});
|
|
901
|
+
|
|
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
|
|
908
|
+
});
|
|
909
|
+
```
|
|
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
|
+
},
|
|
849
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
|
|
850
940
|
```
|
|
851
941
|
|
|
852
942
|
---
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
|
|
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: () =>
|
|
16
|
-
getContact: () =>
|
|
17
|
-
createTicket: () =>
|
|
25
|
+
createContact: () => RunflowTool;
|
|
26
|
+
getContact: () => RunflowTool;
|
|
27
|
+
createTicket: () => RunflowTool;
|
|
18
28
|
};
|
|
19
29
|
export declare const twilio: {
|
|
20
|
-
sendWhatsApp: () =>
|
|
21
|
-
sendSMS: () =>
|
|
30
|
+
sendWhatsApp: () => RunflowTool;
|
|
31
|
+
sendSMS: () => RunflowTool;
|
|
22
32
|
};
|
|
23
33
|
export declare const email: {
|
|
24
|
-
send: () =>
|
|
34
|
+
send: () => RunflowTool;
|
|
25
35
|
};
|
|
26
36
|
export declare const slack: {
|
|
27
|
-
sendMessage: () =>
|
|
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;
|
|
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"}
|