-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathintegrations.ts
More file actions
211 lines (177 loc) · 7.13 KB
/
integrations.ts
File metadata and controls
211 lines (177 loc) · 7.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/**
* Integrations API Journey — Full lifecycle of integration management
*
* Demonstrates all IntegrationClient APIs:
* - Provider CRUD (save, get, list, delete)
* - Integration API CRUD (save, get, list, delete)
* - Query integrations (all, by category, available APIs, definitions)
* - Prompt association (associate, get, list)
* - Tag management (provider tags, integration tags)
*
* Note: This example uses mock integration data. In production,
* you would configure actual LLM providers, vector DBs, etc.
*
* Run:
* CONDUCTOR_SERVER_URL=http://localhost:8080 npx ts-node examples/api-journeys/integrations.ts
*/
import { OrkesClients } from "../../src/sdk";
async function main() {
const clients = await OrkesClients.from();
const integrations = clients.getIntegrationClient();
const providerName = "journey_example_provider";
const integrationName = "journey_example_model";
try {
// ── 1. Provider Management ──────────────────────────────────────
console.log("=== Provider Management ===\n");
// Save (create) a provider
await integrations.saveIntegrationProvider(providerName, {
category: "AI_MODEL",
type: "openai",
description: "Example OpenAI integration for API journey",
configuration: {
api_key: "sk-example-key",
},
enabled: true,
});
console.log("1. Saved integration provider:", providerName);
// Get provider
const provider = await integrations.getIntegrationProvider(providerName);
console.log("2. Provider:", JSON.stringify({
name: provider.name,
category: provider.category,
enabled: provider.enabled,
}));
// List all providers
const allProviders = await integrations.getIntegrationProviders();
console.log("3. Total providers:", allProviders.length);
// Get provider definitions
const defs = await integrations.getIntegrationProviderDefs();
console.log("4. Provider definitions:", defs.length);
// ── 2. Integration API Management ───────────────────────────────
console.log("\n=== Integration API Management ===\n");
// Save an integration API (model)
await integrations.saveIntegrationApi(providerName, integrationName, {
description: "GPT-4o model configuration",
configuration: {
model: "gpt-4o",
},
enabled: true,
});
console.log("5. Saved integration API:", integrationName);
// Get integration API
const api = await integrations.getIntegrationApi(
providerName,
integrationName
);
console.log("6. Integration API:", JSON.stringify({
name: api.name,
enabled: api.enabled,
}));
// List APIs for provider
const apis = await integrations.getIntegrationApis(providerName);
console.log("7. APIs for provider:", apis.length);
// Get available APIs
const available = await integrations.getIntegrationAvailableApis(
providerName
);
console.log("8. Available APIs:", available);
// ── 3. Query Integrations ───────────────────────────────────────
console.log("\n=== Query Integrations ===\n");
// Get all integrations
const allIntegrations = await integrations.getIntegrations();
console.log("9. Total integrations:", allIntegrations.length);
// Filter by category
const aiIntegrations = await integrations.getIntegrations(
"AI_MODEL",
true
);
console.log("10. Active AI integrations:", aiIntegrations.length);
// Get providers and integrations
const providersAndIntegrations =
await integrations.getProvidersAndIntegrations();
console.log(
"11. Providers and integrations:",
providersAndIntegrations.length
);
// ── 4. Tag Management ───────────────────────────────────────────
console.log("\n=== Tag Management ===\n");
// Provider tags
await integrations.setProviderTags(providerName, [
{ key: "team", value: "ml" },
{ key: "env", value: "staging" },
]);
console.log("12. Set provider tags");
const providerTags = await integrations.getProviderTags(providerName);
console.log("13. Provider tags:", JSON.stringify(providerTags));
await integrations.deleteProviderTags(providerName, [
{ key: "env", value: "staging" },
]);
console.log("14. Deleted provider tag");
// Integration tags
await integrations.setIntegrationTags(providerName, integrationName, [
{ key: "model", value: "gpt-4o" },
{ key: "capability", value: "chat" },
]);
console.log("15. Set integration tags");
const integrationTags = await integrations.getIntegrationTags(
providerName,
integrationName
);
console.log("16. Integration tags:", JSON.stringify(integrationTags));
await integrations.deleteIntegrationTags(providerName, integrationName, [
{ key: "capability", value: "chat" },
]);
console.log("17. Deleted integration tag");
// ── 5. Prompt Association ───────────────────────────────────────
console.log("\n=== Prompt Association ===\n");
// Associate a prompt (requires an existing prompt)
try {
const promptClient = clients.getPromptClient();
await promptClient.savePrompt(
"journey_assoc_prompt",
"Prompt for integration association",
"Hello, {{name}}!",
[`${providerName}:${integrationName}`]
);
await integrations.associatePromptWithIntegration(
providerName,
integrationName,
"journey_assoc_prompt"
);
console.log("18. Associated prompt with integration");
const prompts = await integrations.getPromptsWithIntegration(
providerName,
integrationName
);
console.log("19. Associated prompts:", prompts.length);
await promptClient.deletePrompt("journey_assoc_prompt");
console.log("20. Cleaned up prompt");
} catch (err) {
console.log(
"18-20. Prompt association skipped:",
(err as Error).message
);
}
// ── 6. Cleanup ──────────────────────────────────────────────────
console.log("\n=== Cleanup ===\n");
await integrations.deleteIntegrationApi(providerName, integrationName);
console.log("21. Deleted integration API");
await integrations.deleteIntegrationProvider(providerName);
console.log("22. Deleted provider");
} catch (err) {
console.error("Error:", err);
// Best-effort cleanup
try {
await integrations.deleteIntegrationApi(providerName, integrationName);
} catch { /* ignore */ }
try {
await integrations.deleteIntegrationProvider(providerName);
} catch { /* ignore */ }
}
console.log("\nDone.");
process.exit(0);
}
main().catch((err) => {
console.error(err);
process.exit(1);
});