@orchestration-ai/sdk 0.1.0 → 0.3.1
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 +280 -207
- package/dist/cjs/app-builder.d.ts +39 -0
- package/dist/cjs/app-builder.d.ts.map +1 -0
- package/dist/cjs/app-builder.js +589 -0
- package/dist/cjs/app-builder.js.map +1 -0
- package/dist/cjs/oauth-utils.d.ts +41 -0
- package/dist/cjs/oauth-utils.d.ts.map +1 -0
- package/dist/cjs/oauth-utils.js +194 -0
- package/dist/cjs/oauth-utils.js.map +1 -0
- package/dist/cjs/services.d.ts +33 -0
- package/dist/cjs/services.d.ts.map +1 -0
- package/dist/cjs/services.js +121 -0
- package/dist/cjs/services.js.map +1 -0
- package/dist/cjs/shared-types.d.ts +66 -0
- package/dist/cjs/shared-types.d.ts.map +1 -0
- package/dist/cjs/shared-types.js +30 -0
- package/dist/cjs/shared-types.js.map +1 -0
- package/dist/cjs/types.gen.d.ts +28 -0
- package/dist/cjs/types.gen.d.ts.map +1 -1
- package/dist/esm/app-builder.d.ts +39 -0
- package/dist/esm/app-builder.d.ts.map +1 -0
- package/dist/esm/app-builder.js +547 -0
- package/dist/esm/app-builder.js.map +1 -0
- package/dist/esm/oauth-utils.d.ts +41 -0
- package/dist/esm/oauth-utils.d.ts.map +1 -0
- package/dist/esm/oauth-utils.js +184 -0
- package/dist/esm/oauth-utils.js.map +1 -0
- package/dist/esm/services.d.ts +33 -0
- package/dist/esm/services.d.ts.map +1 -0
- package/dist/esm/services.js +104 -0
- package/dist/esm/services.js.map +1 -0
- package/dist/esm/shared-types.d.ts +66 -0
- package/dist/esm/shared-types.d.ts.map +1 -0
- package/dist/esm/shared-types.js +25 -0
- package/dist/esm/shared-types.js.map +1 -0
- package/dist/esm/types.gen.d.ts +28 -0
- package/dist/esm/types.gen.d.ts.map +1 -1
- package/package.json +73 -10
- package/dist/cjs/index.d.ts +0 -3
- package/dist/cjs/index.d.ts.map +0 -1
- package/dist/cjs/index.js +0 -72
- package/dist/cjs/index.js.map +0 -1
- package/dist/esm/index.d.ts +0 -3
- package/dist/esm/index.d.ts.map +0 -1
- package/dist/esm/index.js +0 -3
- package/dist/esm/index.js.map +0 -1
|
@@ -0,0 +1,547 @@
|
|
|
1
|
+
import express, { Router } from "express";
|
|
2
|
+
import { createServer } from "node:http";
|
|
3
|
+
import { createEngineClient, createApiClient } from "./services.js";
|
|
4
|
+
import { setupClientCredentials } from "./oauth-utils.js";
|
|
5
|
+
export function defineService(definition) {
|
|
6
|
+
return definition;
|
|
7
|
+
}
|
|
8
|
+
export function defineServiceWithDynamicDescription(definition) {
|
|
9
|
+
return definition;
|
|
10
|
+
}
|
|
11
|
+
export { getBooleanSetting, getTextSetting, getSecretSetting } from "./shared-types.js";
|
|
12
|
+
// --- Context Resolution ---
|
|
13
|
+
async function resolveContext(layerId, engineUrl, accessKey) {
|
|
14
|
+
const endpoint = `${engineUrl}/agents/context/${layerId}`;
|
|
15
|
+
return (await fetch(endpoint, {
|
|
16
|
+
headers: { Authorization: `Bearer ${accessKey}` },
|
|
17
|
+
})).json();
|
|
18
|
+
}
|
|
19
|
+
// --- Explore Page ---
|
|
20
|
+
function renderExplorePage(services, permissions) {
|
|
21
|
+
const permissionsHtml = permissions.length > 0
|
|
22
|
+
? permissions.map((p) => `<div class="permission"><code>${p.permission_name}</code><span>${p.justification}</span></div>`).join("")
|
|
23
|
+
: `<p class="no-tools">No permissions declared</p>`;
|
|
24
|
+
const serviceCards = services.map((s) => {
|
|
25
|
+
const isStatic = typeof s.description !== "function";
|
|
26
|
+
const tools = s.tools ? Object.keys(s.tools) : [];
|
|
27
|
+
const description = isStatic ? s.description : null;
|
|
28
|
+
let toolsHtml = "";
|
|
29
|
+
if (description && description.length > 0) {
|
|
30
|
+
toolsHtml = description.map((tool) => {
|
|
31
|
+
const paramInputs = Object.entries(tool.parameters).map(([name, p]) => {
|
|
32
|
+
const required = !p.optional ? 'required' : '';
|
|
33
|
+
if (p.type === "boolean") {
|
|
34
|
+
return `<label class="param-input-label"><input type="checkbox" name="${name}" data-type="boolean" />${name}${p.optional ? ' (optional)' : ''}</label>`;
|
|
35
|
+
}
|
|
36
|
+
return `<input class="param-input" type="text" name="${name}" placeholder="${name}${p.optional ? ' (optional)' : ''}" data-type="${p.type}" ${required} />`;
|
|
37
|
+
}).join("");
|
|
38
|
+
const params = Object.entries(tool.parameters).map(([name, p]) => `<span class="param">${name}${p.optional ? "?" : ""}: <span class="param-type">${p.type}</span></span>`).join("");
|
|
39
|
+
return `<div class="tool">
|
|
40
|
+
<div class="tool-header">
|
|
41
|
+
<span class="method method-${tool.method.toLowerCase()}">${tool.method}</span>
|
|
42
|
+
<code class="tool-path">${tool.path}</code>
|
|
43
|
+
<button class="try-btn" onclick="toggleForm(this)">Try</button>
|
|
44
|
+
</div>
|
|
45
|
+
<p class="tool-desc">${tool.description}</p>
|
|
46
|
+
${params ? `<div class="params">${params}</div>` : ""}
|
|
47
|
+
<form class="tool-form" style="display:none" onsubmit="callTool(event, '${s.unique_name}', '${tool.path}', '${tool.method}')">
|
|
48
|
+
<input class="param-input layer-id-input" type="text" name="__layerId__" placeholder="X-LayerId (optional)" />
|
|
49
|
+
${paramInputs}
|
|
50
|
+
<div class="form-actions">
|
|
51
|
+
<button type="submit" class="call-btn">Call</button>
|
|
52
|
+
</div>
|
|
53
|
+
<pre class="tool-response"></pre>
|
|
54
|
+
</form>
|
|
55
|
+
</div>`;
|
|
56
|
+
}).join("");
|
|
57
|
+
}
|
|
58
|
+
else if (tools.length > 0) {
|
|
59
|
+
toolsHtml = tools.map((t) => `<div class="tool">
|
|
60
|
+
<div class="tool-header">
|
|
61
|
+
<span class="method method-post">POST</span>
|
|
62
|
+
<code class="tool-path">${t}</code>
|
|
63
|
+
<button class="try-btn" onclick="toggleForm(this)">Try</button>
|
|
64
|
+
</div>
|
|
65
|
+
<form class="tool-form" style="display:none" onsubmit="callTool(event, '${s.unique_name}', '${t}', 'POST')">
|
|
66
|
+
<input class="param-input layer-id-input" type="text" name="__layerId__" placeholder="X-LayerId (optional)" />
|
|
67
|
+
<textarea class="raw-body" name="__raw__" placeholder='{ "key": "value" }' rows="3"></textarea>
|
|
68
|
+
<div class="form-actions">
|
|
69
|
+
<button type="submit" class="call-btn">Call</button>
|
|
70
|
+
</div>
|
|
71
|
+
<pre class="tool-response"></pre>
|
|
72
|
+
</form>
|
|
73
|
+
</div>`).join("");
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
toolsHtml = `<p class="no-tools">No tools exposed</p>`;
|
|
77
|
+
}
|
|
78
|
+
const dynamicBadge = !isStatic ? `<span class="badge">Dynamic</span>` : "";
|
|
79
|
+
const hasTouchBadge = s.touch ? `<span class="badge badge-touch">Touch</span>` : "";
|
|
80
|
+
return `<div class="service-card">
|
|
81
|
+
<div class="service-header">
|
|
82
|
+
<h2>${s.service_name}</h2>
|
|
83
|
+
<div class="badges">
|
|
84
|
+
<code class="service-id">${s.unique_name}</code>
|
|
85
|
+
${dynamicBadge}${hasTouchBadge}
|
|
86
|
+
</div>
|
|
87
|
+
</div>
|
|
88
|
+
<p class="service-desc">${s.service_description}</p>
|
|
89
|
+
<div class="tools-section">
|
|
90
|
+
<h3>Tools</h3>
|
|
91
|
+
${toolsHtml}
|
|
92
|
+
</div>
|
|
93
|
+
</div>`;
|
|
94
|
+
}).join("");
|
|
95
|
+
return `<!DOCTYPE html>
|
|
96
|
+
<html lang="en">
|
|
97
|
+
<head>
|
|
98
|
+
<meta charset="utf-8" />
|
|
99
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
100
|
+
<title>Explore Services — Orchestration AI</title>
|
|
101
|
+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet" />
|
|
102
|
+
<style>
|
|
103
|
+
:root {
|
|
104
|
+
--primary: #40babd;
|
|
105
|
+
--primary-dark: #339597;
|
|
106
|
+
--dark: #0d1117;
|
|
107
|
+
--dark-2: #161b22;
|
|
108
|
+
--dark-3: #1c2128;
|
|
109
|
+
--text: #e6edf3;
|
|
110
|
+
--text-muted: #8b949e;
|
|
111
|
+
--gradient: linear-gradient(135deg, #40babd, #75c181);
|
|
112
|
+
--radius: 12px;
|
|
113
|
+
}
|
|
114
|
+
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
|
115
|
+
body {
|
|
116
|
+
font-family: 'Inter', -apple-system, sans-serif;
|
|
117
|
+
background: var(--dark);
|
|
118
|
+
color: var(--text);
|
|
119
|
+
font-size: 15px;
|
|
120
|
+
line-height: 1.6;
|
|
121
|
+
-webkit-font-smoothing: antialiased;
|
|
122
|
+
padding: 48px 24px;
|
|
123
|
+
}
|
|
124
|
+
.container { max-width: 900px; margin: 0 auto; }
|
|
125
|
+
.page-header {
|
|
126
|
+
margin-bottom: 40px;
|
|
127
|
+
}
|
|
128
|
+
.page-header h1 {
|
|
129
|
+
font-size: 28px;
|
|
130
|
+
font-weight: 700;
|
|
131
|
+
background: var(--gradient);
|
|
132
|
+
-webkit-background-clip: text;
|
|
133
|
+
-webkit-text-fill-color: transparent;
|
|
134
|
+
background-clip: text;
|
|
135
|
+
}
|
|
136
|
+
.page-header p {
|
|
137
|
+
color: var(--text-muted);
|
|
138
|
+
margin-top: 8px;
|
|
139
|
+
}
|
|
140
|
+
.service-card {
|
|
141
|
+
background: var(--dark-2);
|
|
142
|
+
border: 1px solid var(--dark-3);
|
|
143
|
+
border-radius: var(--radius);
|
|
144
|
+
padding: 24px;
|
|
145
|
+
margin-bottom: 20px;
|
|
146
|
+
}
|
|
147
|
+
.service-header {
|
|
148
|
+
display: flex;
|
|
149
|
+
align-items: center;
|
|
150
|
+
justify-content: space-between;
|
|
151
|
+
flex-wrap: wrap;
|
|
152
|
+
gap: 8px;
|
|
153
|
+
margin-bottom: 8px;
|
|
154
|
+
}
|
|
155
|
+
.service-header h2 {
|
|
156
|
+
font-size: 18px;
|
|
157
|
+
font-weight: 600;
|
|
158
|
+
}
|
|
159
|
+
.badges { display: flex; align-items: center; gap: 8px; }
|
|
160
|
+
.service-id {
|
|
161
|
+
font-size: 12px;
|
|
162
|
+
background: var(--dark-3);
|
|
163
|
+
padding: 2px 8px;
|
|
164
|
+
border-radius: 4px;
|
|
165
|
+
color: var(--text-muted);
|
|
166
|
+
}
|
|
167
|
+
.badge {
|
|
168
|
+
font-size: 11px;
|
|
169
|
+
font-weight: 500;
|
|
170
|
+
padding: 2px 8px;
|
|
171
|
+
border-radius: 4px;
|
|
172
|
+
background: rgba(64, 186, 189, 0.15);
|
|
173
|
+
color: var(--primary);
|
|
174
|
+
}
|
|
175
|
+
.badge-touch {
|
|
176
|
+
background: rgba(117, 193, 129, 0.15);
|
|
177
|
+
color: #75c181;
|
|
178
|
+
}
|
|
179
|
+
.service-desc {
|
|
180
|
+
color: var(--text-muted);
|
|
181
|
+
margin-bottom: 16px;
|
|
182
|
+
}
|
|
183
|
+
.tools-section h3 {
|
|
184
|
+
font-size: 13px;
|
|
185
|
+
font-weight: 600;
|
|
186
|
+
text-transform: uppercase;
|
|
187
|
+
letter-spacing: 0.5px;
|
|
188
|
+
color: var(--text-muted);
|
|
189
|
+
margin-bottom: 10px;
|
|
190
|
+
}
|
|
191
|
+
.tool {
|
|
192
|
+
background: var(--dark-3);
|
|
193
|
+
border-radius: 8px;
|
|
194
|
+
padding: 12px 16px;
|
|
195
|
+
margin-bottom: 8px;
|
|
196
|
+
}
|
|
197
|
+
.tool-header {
|
|
198
|
+
display: flex;
|
|
199
|
+
align-items: center;
|
|
200
|
+
gap: 10px;
|
|
201
|
+
}
|
|
202
|
+
.method {
|
|
203
|
+
font-size: 11px;
|
|
204
|
+
font-weight: 700;
|
|
205
|
+
padding: 2px 6px;
|
|
206
|
+
border-radius: 4px;
|
|
207
|
+
text-transform: uppercase;
|
|
208
|
+
}
|
|
209
|
+
.method-post { background: rgba(64, 186, 189, 0.2); color: var(--primary); }
|
|
210
|
+
.method-get { background: rgba(117, 193, 129, 0.2); color: #75c181; }
|
|
211
|
+
.method-patch { background: rgba(255, 193, 7, 0.2); color: #ffc107; }
|
|
212
|
+
.method-delete { background: rgba(248, 81, 73, 0.2); color: #f85149; }
|
|
213
|
+
.method-put { background: rgba(169, 142, 255, 0.2); color: #a98eff; }
|
|
214
|
+
.tool-path {
|
|
215
|
+
font-size: 14px;
|
|
216
|
+
font-weight: 500;
|
|
217
|
+
color: var(--text);
|
|
218
|
+
}
|
|
219
|
+
.tool-desc {
|
|
220
|
+
color: var(--text-muted);
|
|
221
|
+
font-size: 13px;
|
|
222
|
+
margin-top: 6px;
|
|
223
|
+
}
|
|
224
|
+
.params {
|
|
225
|
+
display: flex;
|
|
226
|
+
flex-wrap: wrap;
|
|
227
|
+
gap: 6px;
|
|
228
|
+
margin-top: 8px;
|
|
229
|
+
}
|
|
230
|
+
.param {
|
|
231
|
+
font-size: 12px;
|
|
232
|
+
background: var(--dark-2);
|
|
233
|
+
padding: 2px 8px;
|
|
234
|
+
border-radius: 4px;
|
|
235
|
+
color: var(--text-muted);
|
|
236
|
+
}
|
|
237
|
+
.param-type { color: var(--primary); }
|
|
238
|
+
.no-tools {
|
|
239
|
+
color: var(--text-muted);
|
|
240
|
+
font-size: 13px;
|
|
241
|
+
font-style: italic;
|
|
242
|
+
}
|
|
243
|
+
.section-title {
|
|
244
|
+
font-size: 13px;
|
|
245
|
+
font-weight: 600;
|
|
246
|
+
text-transform: uppercase;
|
|
247
|
+
letter-spacing: 0.5px;
|
|
248
|
+
color: var(--text-muted);
|
|
249
|
+
margin-bottom: 12px;
|
|
250
|
+
margin-top: 32px;
|
|
251
|
+
}
|
|
252
|
+
.permissions-card {
|
|
253
|
+
background: var(--dark-2);
|
|
254
|
+
border: 1px solid var(--dark-3);
|
|
255
|
+
border-radius: var(--radius);
|
|
256
|
+
padding: 24px;
|
|
257
|
+
margin-bottom: 32px;
|
|
258
|
+
}
|
|
259
|
+
.permission {
|
|
260
|
+
display: flex;
|
|
261
|
+
align-items: baseline;
|
|
262
|
+
gap: 12px;
|
|
263
|
+
padding: 8px 0;
|
|
264
|
+
border-bottom: 1px solid var(--dark-3);
|
|
265
|
+
}
|
|
266
|
+
.permission:last-child { border-bottom: none; }
|
|
267
|
+
.permission code {
|
|
268
|
+
font-size: 13px;
|
|
269
|
+
font-weight: 500;
|
|
270
|
+
color: var(--primary);
|
|
271
|
+
white-space: nowrap;
|
|
272
|
+
}
|
|
273
|
+
.permission span {
|
|
274
|
+
font-size: 13px;
|
|
275
|
+
color: var(--text-muted);
|
|
276
|
+
}
|
|
277
|
+
.try-btn {
|
|
278
|
+
margin-left: auto;
|
|
279
|
+
font-size: 11px;
|
|
280
|
+
font-weight: 600;
|
|
281
|
+
padding: 3px 10px;
|
|
282
|
+
border-radius: 4px;
|
|
283
|
+
border: 1px solid var(--primary);
|
|
284
|
+
background: transparent;
|
|
285
|
+
color: var(--primary);
|
|
286
|
+
cursor: pointer;
|
|
287
|
+
transition: background 0.2s;
|
|
288
|
+
}
|
|
289
|
+
.try-btn:hover { background: rgba(64, 186, 189, 0.1); }
|
|
290
|
+
.tool-form {
|
|
291
|
+
margin-top: 12px;
|
|
292
|
+
display: flex;
|
|
293
|
+
flex-direction: column;
|
|
294
|
+
gap: 8px;
|
|
295
|
+
}
|
|
296
|
+
.param-input, .raw-body {
|
|
297
|
+
font-family: 'Inter', sans-serif;
|
|
298
|
+
font-size: 13px;
|
|
299
|
+
padding: 8px 12px;
|
|
300
|
+
border-radius: 6px;
|
|
301
|
+
border: 1px solid var(--dark-3);
|
|
302
|
+
background: var(--dark);
|
|
303
|
+
color: var(--text);
|
|
304
|
+
outline: none;
|
|
305
|
+
width: 100%;
|
|
306
|
+
resize: vertical;
|
|
307
|
+
}
|
|
308
|
+
.param-input:focus, .raw-body:focus {
|
|
309
|
+
border-color: var(--primary);
|
|
310
|
+
}
|
|
311
|
+
.layer-id-input {
|
|
312
|
+
border-style: dashed;
|
|
313
|
+
font-size: 12px;
|
|
314
|
+
}
|
|
315
|
+
.param-input-label {
|
|
316
|
+
font-size: 13px;
|
|
317
|
+
color: var(--text-muted);
|
|
318
|
+
display: flex;
|
|
319
|
+
align-items: center;
|
|
320
|
+
gap: 8px;
|
|
321
|
+
}
|
|
322
|
+
.form-actions {
|
|
323
|
+
display: flex;
|
|
324
|
+
gap: 8px;
|
|
325
|
+
}
|
|
326
|
+
.call-btn {
|
|
327
|
+
font-size: 12px;
|
|
328
|
+
font-weight: 600;
|
|
329
|
+
padding: 6px 16px;
|
|
330
|
+
border-radius: 6px;
|
|
331
|
+
border: none;
|
|
332
|
+
background: var(--gradient);
|
|
333
|
+
color: var(--dark);
|
|
334
|
+
cursor: pointer;
|
|
335
|
+
}
|
|
336
|
+
.call-btn:hover { opacity: 0.9; }
|
|
337
|
+
.tool-response {
|
|
338
|
+
font-size: 12px;
|
|
339
|
+
background: var(--dark);
|
|
340
|
+
border: 1px solid var(--dark-3);
|
|
341
|
+
border-radius: 6px;
|
|
342
|
+
padding: 10px 12px;
|
|
343
|
+
color: var(--text-muted);
|
|
344
|
+
white-space: pre-wrap;
|
|
345
|
+
word-break: break-all;
|
|
346
|
+
display: none;
|
|
347
|
+
max-height: 300px;
|
|
348
|
+
overflow: auto;
|
|
349
|
+
}
|
|
350
|
+
.tool-response.visible { display: block; }
|
|
351
|
+
</style>
|
|
352
|
+
</head>
|
|
353
|
+
<body>
|
|
354
|
+
<div class="container">
|
|
355
|
+
<div class="page-header">
|
|
356
|
+
<h1>Explore Services</h1>
|
|
357
|
+
<p>${services.length} service${services.length !== 1 ? "s" : ""} registered</p>
|
|
358
|
+
</div>
|
|
359
|
+
<div class="permissions-card">
|
|
360
|
+
<h3 class="section-title">Permissions</h3>
|
|
361
|
+
${permissionsHtml}
|
|
362
|
+
</div>
|
|
363
|
+
<h3 class="section-title">Services</h3>
|
|
364
|
+
${serviceCards}
|
|
365
|
+
</div>
|
|
366
|
+
<script>
|
|
367
|
+
function toggleForm(btn) {
|
|
368
|
+
const form = btn.closest('.tool').querySelector('.tool-form');
|
|
369
|
+
const visible = form.style.display !== 'none';
|
|
370
|
+
form.style.display = visible ? 'none' : 'flex';
|
|
371
|
+
btn.textContent = visible ? 'Try' : 'Hide';
|
|
372
|
+
}
|
|
373
|
+
async function callTool(e, service, path, method) {
|
|
374
|
+
e.preventDefault();
|
|
375
|
+
const form = e.target;
|
|
376
|
+
const responseEl = form.querySelector('.tool-response');
|
|
377
|
+
const rawField = form.querySelector('[name="__raw__"]');
|
|
378
|
+
const layerIdField = form.querySelector('[name="__layerId__"]');
|
|
379
|
+
const layerId = layerIdField ? layerIdField.value.trim() : '';
|
|
380
|
+
let body = {};
|
|
381
|
+
if (rawField) {
|
|
382
|
+
try { body = JSON.parse(rawField.value || '{}'); } catch { body = {}; }
|
|
383
|
+
} else {
|
|
384
|
+
for (const input of form.querySelectorAll('[name]')) {
|
|
385
|
+
if (input.name === '__layerId__') continue;
|
|
386
|
+
const name = input.name;
|
|
387
|
+
const type = input.dataset.type;
|
|
388
|
+
if (type === 'boolean') { body[name] = input.checked; }
|
|
389
|
+
else if (type === 'number') { body[name] = Number(input.value); }
|
|
390
|
+
else if (input.value) { body[name] = input.value; }
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
responseEl.textContent = 'Calling...';
|
|
394
|
+
responseEl.classList.add('visible');
|
|
395
|
+
try {
|
|
396
|
+
const isBodyMethod = ['POST', 'PUT', 'PATCH'].includes(method.toUpperCase());
|
|
397
|
+
const url = '/services/' + service + '/api/' + path;
|
|
398
|
+
const headers = {};
|
|
399
|
+
if (isBodyMethod) { headers['Content-Type'] = 'application/json'; }
|
|
400
|
+
if (layerId) { headers['X-LayerId'] = layerId; }
|
|
401
|
+
const opts = { method: method.toUpperCase(), headers };
|
|
402
|
+
if (isBodyMethod) { opts.body = JSON.stringify(body); }
|
|
403
|
+
const res = await fetch(url, opts);
|
|
404
|
+
const text = await res.text();
|
|
405
|
+
try { responseEl.textContent = JSON.stringify(JSON.parse(text), null, 2); }
|
|
406
|
+
catch { responseEl.textContent = text; }
|
|
407
|
+
} catch (err) {
|
|
408
|
+
responseEl.textContent = 'Error: ' + err.message;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
</script>
|
|
412
|
+
</body>
|
|
413
|
+
</html>`;
|
|
414
|
+
}
|
|
415
|
+
// --- App Builder ---
|
|
416
|
+
export function createApp(config) {
|
|
417
|
+
var _a, _b, _c, _d, _e;
|
|
418
|
+
const app = express();
|
|
419
|
+
const server = createServer(app);
|
|
420
|
+
const services = [];
|
|
421
|
+
let appPermissions = (_a = config === null || config === void 0 ? void 0 : config.permissions) !== null && _a !== void 0 ? _a : [];
|
|
422
|
+
const engineUrl = (_c = (_b = config === null || config === void 0 ? void 0 : config.engineUrl) !== null && _b !== void 0 ? _b : process.env.ENGINE_URL) !== null && _c !== void 0 ? _c : "";
|
|
423
|
+
const accessKey = (_e = (_d = config === null || config === void 0 ? void 0 : config.accessKey) !== null && _d !== void 0 ? _d : process.env.OAI_ACCESS_KEY) !== null && _e !== void 0 ? _e : "";
|
|
424
|
+
// Context middleware
|
|
425
|
+
app.use(async (req, res, next) => {
|
|
426
|
+
var _a;
|
|
427
|
+
const layerId = req.get("X-LayerId");
|
|
428
|
+
if (layerId) {
|
|
429
|
+
const context = await resolveContext(layerId, engineUrl, accessKey);
|
|
430
|
+
res.locals.context = context;
|
|
431
|
+
res.locals.engineClient = createEngineClient((_a = process.env.ENGINE_URL) !== null && _a !== void 0 ? _a : null, accessKey);
|
|
432
|
+
const apiClient = createApiClient();
|
|
433
|
+
setupClientCredentials(apiClient, {
|
|
434
|
+
client_id: accessKey,
|
|
435
|
+
client_secret: `${accessKey}:${context.identity.workspaceOwnerId}`,
|
|
436
|
+
});
|
|
437
|
+
res.locals.apiClient = apiClient;
|
|
438
|
+
}
|
|
439
|
+
next();
|
|
440
|
+
});
|
|
441
|
+
app.use(express.json());
|
|
442
|
+
function registerService(definition) {
|
|
443
|
+
var _a, _b;
|
|
444
|
+
services.push(definition);
|
|
445
|
+
const router = Router();
|
|
446
|
+
if (definition.defaultSettings) {
|
|
447
|
+
router.get("/api/default-settings", (_req, res) => {
|
|
448
|
+
res.status(200).json(definition.defaultSettings);
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
router.get("/api/description", async (_req, res) => {
|
|
452
|
+
try {
|
|
453
|
+
const context = res.locals.context;
|
|
454
|
+
const desc = typeof definition.description === "function"
|
|
455
|
+
? await definition.description(context, res.locals.engineClient, res.locals.apiClient)
|
|
456
|
+
: definition.description;
|
|
457
|
+
res.status(200).json(desc);
|
|
458
|
+
}
|
|
459
|
+
catch (e) {
|
|
460
|
+
console.warn(e);
|
|
461
|
+
res.status(500).send(`${e}`);
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
if (definition.touch) {
|
|
465
|
+
router.post("/api/touch", async (_req, res) => {
|
|
466
|
+
try {
|
|
467
|
+
const context = res.locals.context;
|
|
468
|
+
await definition.touch(context, res.locals.engineClient, res.locals.apiClient);
|
|
469
|
+
res.status(204).send();
|
|
470
|
+
}
|
|
471
|
+
catch (e) {
|
|
472
|
+
console.warn(e);
|
|
473
|
+
res.status(500).send(`${e}`);
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
if (definition.tools) {
|
|
478
|
+
for (const [toolName, handler] of Object.entries(definition.tools)) {
|
|
479
|
+
const toolDesc = typeof definition.description !== "function"
|
|
480
|
+
? definition.description.find((d) => d.path === toolName)
|
|
481
|
+
: undefined;
|
|
482
|
+
const method = (_b = (_a = toolDesc === null || toolDesc === void 0 ? void 0 : toolDesc.method) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : "post";
|
|
483
|
+
const routeHandler = async (req, res) => {
|
|
484
|
+
try {
|
|
485
|
+
const context = res.locals.context;
|
|
486
|
+
const result = await handler(req.body, context, res.locals.engineClient, res.locals.apiClient);
|
|
487
|
+
if (typeof result === "string") {
|
|
488
|
+
res.status(200).send(result);
|
|
489
|
+
}
|
|
490
|
+
else {
|
|
491
|
+
res.status(200).json(result);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
catch (e) {
|
|
495
|
+
console.warn(e);
|
|
496
|
+
res.status(500).send(`${e}`);
|
|
497
|
+
}
|
|
498
|
+
};
|
|
499
|
+
router[method](`/api/${toolName}`, routeHandler);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
app.use(`/services/${definition.unique_name}`, router);
|
|
503
|
+
}
|
|
504
|
+
function mountGlobalEndpoints() {
|
|
505
|
+
app.get("/services", (_req, res) => {
|
|
506
|
+
res.status(200).json(services.map((s) => ({
|
|
507
|
+
unique_name: s.unique_name,
|
|
508
|
+
service_name: s.service_name,
|
|
509
|
+
service_description: s.service_description,
|
|
510
|
+
})));
|
|
511
|
+
});
|
|
512
|
+
app.get("/permissions", (_req, res) => {
|
|
513
|
+
res.status(200).json(appPermissions);
|
|
514
|
+
});
|
|
515
|
+
if ((config === null || config === void 0 ? void 0 : config.explore) !== false) {
|
|
516
|
+
app.get("/explore", (_req, res) => {
|
|
517
|
+
res.status(200).send(renderExplorePage(services, appPermissions));
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
const oaiApp = {
|
|
522
|
+
expressApp: app,
|
|
523
|
+
httpServer: server,
|
|
524
|
+
service(definition) {
|
|
525
|
+
registerService(definition);
|
|
526
|
+
return oaiApp;
|
|
527
|
+
},
|
|
528
|
+
permissions(permissions) {
|
|
529
|
+
appPermissions = permissions;
|
|
530
|
+
return oaiApp;
|
|
531
|
+
},
|
|
532
|
+
listen(port) {
|
|
533
|
+
var _a;
|
|
534
|
+
mountGlobalEndpoints();
|
|
535
|
+
const p = (_a = port !== null && port !== void 0 ? port : config === null || config === void 0 ? void 0 : config.port) !== null && _a !== void 0 ? _a : 3001;
|
|
536
|
+
server.listen(p, () => {
|
|
537
|
+
console.log(`Server is running on http://localhost:${p}`);
|
|
538
|
+
if ((config === null || config === void 0 ? void 0 : config.explore) !== false) {
|
|
539
|
+
console.log(`Explore services at http://localhost:${p}/explore`);
|
|
540
|
+
}
|
|
541
|
+
});
|
|
542
|
+
return server;
|
|
543
|
+
},
|
|
544
|
+
};
|
|
545
|
+
return oaiApp;
|
|
546
|
+
}
|
|
547
|
+
//# sourceMappingURL=app-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-builder.js","sourceRoot":"","sources":["../../typescript/app-builder.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAA+B,MAAM,EAAE,MAAM,SAAS,CAAC;AACvE,OAAO,EAAE,YAAY,EAA6B,MAAM,WAAW,CAAC;AAQpE,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAiCvD,MAAM,UAAU,aAAa,CAC3B,UAAoC;IAEpC,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,mCAAmC,CACjD,UAAiD;IAEjD,OAAO,UAAU,CAAC;AACpB,CAAC;AAsBD,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAErF,6BAA6B;AAE7B,KAAK,UAAU,cAAc,CAC3B,OAAe,EACf,SAAiB,EACjB,SAAiB;IAEjB,MAAM,QAAQ,GAAG,GAAG,SAAS,mBAAmB,OAAO,EAAE,CAAC;IAC1D,OAAO,CACL,MAAM,KAAK,CAAC,QAAQ,EAAE;QACpB,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,SAAS,EAAE,EAAE;KAClD,CAAC,CACH,CAAC,IAAI,EAAE,CAAC;AACX,CAAC;AAED,uBAAuB;AAEvB,SAAS,iBAAiB,CAAC,QAAkC,EAAE,WAAyB;IACtF,MAAM,eAAe,GAAG,WAAW,CAAC,MAAM,GAAG,CAAC;QAC5C,CAAC,CAAC,WAAW,CAAC,GAA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,EAAE,GAAa,EAAE,EAAE;gBACnD,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC;YACpE,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,MAAM,MAAM,GAAW;QACrB,UAAU,EAAE,GAAG;QACf,UAAU,EAAE,MAAM;QAElB,OAAO,CAAC,UAAkC;YACxC,eAAe,CAAC,UAAU,CAAC,CAAC;YAC5B,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,WAAW,CAAC,WAAyB;YACnC,cAAc,GAAG,WAAW,CAAC;YAC7B,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,MAAM,CAAC,IAAsB;;YAC3B,oBAAoB,EAAE,CAAC;YACvB,MAAM,CAAC,GAAG,MAAA,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,mCAAI,IAAI,CAAC;YACvC,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE;gBACpB,OAAO,CAAC,GAAG,CAAC,yCAAyC,CAAC,EAAE,CAAC,CAAC;gBAC1D,IAAI,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAO,MAAK,KAAK,EAAE,CAAC;oBAC9B,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAC,UAAU,CAAC,CAAC;gBACnE,CAAC;YACH,CAAC,CAAC,CAAC;YACH,OAAO,MAAM,CAAC;QAChB,CAAC;KACF,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Client } from './client';
|
|
2
|
+
export interface OAuthTokens {
|
|
3
|
+
access_token: string;
|
|
4
|
+
refresh_token?: string;
|
|
5
|
+
token_type: string;
|
|
6
|
+
expires_in: number;
|
|
7
|
+
scope?: string;
|
|
8
|
+
expires_at: number;
|
|
9
|
+
}
|
|
10
|
+
export interface OAuthConfig {
|
|
11
|
+
client_id: string;
|
|
12
|
+
client_secret: string;
|
|
13
|
+
scope?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface OAuthBrowserConfig {
|
|
16
|
+
client_id: string;
|
|
17
|
+
redirect_uri: string;
|
|
18
|
+
scope?: string;
|
|
19
|
+
}
|
|
20
|
+
export declare function saveLogin(tokens: OAuthTokens): void;
|
|
21
|
+
export declare function getCurrentLogin(): OAuthTokens | null;
|
|
22
|
+
export declare function isLoginExpired(): boolean;
|
|
23
|
+
export declare function logout(): void;
|
|
24
|
+
export declare function initiateLogin(baseUrl: string, config: OAuthBrowserConfig, state?: string): void;
|
|
25
|
+
export type OAuthRedirectResult = {
|
|
26
|
+
granted: true;
|
|
27
|
+
code: string;
|
|
28
|
+
state?: string;
|
|
29
|
+
} | {
|
|
30
|
+
granted: false;
|
|
31
|
+
error: string;
|
|
32
|
+
error_description: string;
|
|
33
|
+
state?: string;
|
|
34
|
+
};
|
|
35
|
+
export declare function parseLoginRedirect(): OAuthRedirectResult;
|
|
36
|
+
export interface BrowserAuthOptions {
|
|
37
|
+
onRefreshToken?: () => Promise<OAuthTokens | null>;
|
|
38
|
+
}
|
|
39
|
+
export declare function setupBrowserAuth(sdkClient: Client, options?: BrowserAuthOptions): void;
|
|
40
|
+
export declare function setupClientCredentials(sdkClient: Client, config: OAuthConfig): void;
|
|
41
|
+
//# sourceMappingURL=oauth-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-utils.d.ts","sourceRoot":"","sources":["../../typescript/oauth-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAMvC,MAAM,WAAW,WAAW;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;I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