@positronic/cli 0.0.2
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/dist/src/cli.js +739 -0
- package/dist/src/commands/backend.js +199 -0
- package/dist/src/commands/brain.js +446 -0
- package/dist/src/commands/brain.test.js +2936 -0
- package/dist/src/commands/helpers.js +1315 -0
- package/dist/src/commands/helpers.test.js +832 -0
- package/dist/src/commands/project-config-manager.js +197 -0
- package/dist/src/commands/project.js +130 -0
- package/dist/src/commands/project.test.js +1201 -0
- package/dist/src/commands/resources.js +272 -0
- package/dist/src/commands/resources.test.js +2511 -0
- package/dist/src/commands/schedule.js +73 -0
- package/dist/src/commands/schedule.test.js +1235 -0
- package/dist/src/commands/secret.js +87 -0
- package/dist/src/commands/secret.test.d.js +1 -0
- package/dist/src/commands/secret.test.js +761 -0
- package/dist/src/commands/server.js +816 -0
- package/dist/src/commands/server.test.js +1237 -0
- package/dist/src/commands/test-utils.js +737 -0
- package/dist/src/components/brain-history.js +169 -0
- package/dist/src/components/brain-list.js +108 -0
- package/dist/src/components/brain-rerun.js +313 -0
- package/dist/src/components/brain-show.js +65 -0
- package/dist/src/components/error.js +19 -0
- package/dist/src/components/project-add.js +95 -0
- package/dist/src/components/project-create.js +276 -0
- package/dist/src/components/project-list.js +88 -0
- package/dist/src/components/project-remove.js +91 -0
- package/dist/src/components/project-select.js +224 -0
- package/dist/src/components/project-show.js +41 -0
- package/dist/src/components/resource-clear.js +152 -0
- package/dist/src/components/resource-delete.js +189 -0
- package/dist/src/components/resource-list.js +174 -0
- package/dist/src/components/resource-sync.js +386 -0
- package/dist/src/components/resource-types.js +243 -0
- package/dist/src/components/resource-upload.js +366 -0
- package/dist/src/components/schedule-create.js +259 -0
- package/dist/src/components/schedule-delete.js +161 -0
- package/dist/src/components/schedule-list.js +176 -0
- package/dist/src/components/schedule-runs.js +103 -0
- package/dist/src/components/secret-bulk.js +262 -0
- package/dist/src/components/secret-create.js +199 -0
- package/dist/src/components/secret-delete.js +190 -0
- package/dist/src/components/secret-list.js +190 -0
- package/dist/src/components/secret-sync.js +303 -0
- package/dist/src/components/watch.js +184 -0
- package/dist/src/hooks/useApi.js +512 -0
- package/dist/src/positronic.js +33 -0
- package/dist/src/test/mock-api-client.js +371 -0
- package/dist/src/test/test-dev-server.js +1376 -0
- package/dist/types/cli.d.ts +9 -0
- package/dist/types/cli.d.ts.map +1 -0
- package/dist/types/commands/backend.d.ts +6 -0
- package/dist/types/commands/backend.d.ts.map +1 -0
- package/dist/types/commands/brain.d.ts +35 -0
- package/dist/types/commands/brain.d.ts.map +1 -0
- package/dist/types/commands/helpers.d.ts +55 -0
- package/dist/types/commands/helpers.d.ts.map +1 -0
- package/dist/types/commands/project-config-manager.d.ts +37 -0
- package/dist/types/commands/project-config-manager.d.ts.map +1 -0
- package/dist/types/commands/project.d.ts +55 -0
- package/dist/types/commands/project.d.ts.map +1 -0
- package/dist/types/commands/resources.d.ts +13 -0
- package/dist/types/commands/resources.d.ts.map +1 -0
- package/dist/types/commands/schedule.d.ts +27 -0
- package/dist/types/commands/schedule.d.ts.map +1 -0
- package/dist/types/commands/secret.d.ts +23 -0
- package/dist/types/commands/secret.d.ts.map +1 -0
- package/dist/types/commands/server.d.ts +12 -0
- package/dist/types/commands/server.d.ts.map +1 -0
- package/dist/types/commands/test-utils.d.ts +45 -0
- package/dist/types/commands/test-utils.d.ts.map +1 -0
- package/dist/types/components/brain-history.d.ts +7 -0
- package/dist/types/components/brain-history.d.ts.map +1 -0
- package/dist/types/components/brain-list.d.ts +2 -0
- package/dist/types/components/brain-list.d.ts.map +1 -0
- package/dist/types/components/brain-rerun.d.ts +9 -0
- package/dist/types/components/brain-rerun.d.ts.map +1 -0
- package/dist/types/components/brain-show.d.ts +6 -0
- package/dist/types/components/brain-show.d.ts.map +1 -0
- package/dist/types/components/error.d.ts +10 -0
- package/dist/types/components/error.d.ts.map +1 -0
- package/dist/types/components/project-add.d.ts +9 -0
- package/dist/types/components/project-add.d.ts.map +1 -0
- package/dist/types/components/project-create.d.ts +6 -0
- package/dist/types/components/project-create.d.ts.map +1 -0
- package/dist/types/components/project-list.d.ts +7 -0
- package/dist/types/components/project-list.d.ts.map +1 -0
- package/dist/types/components/project-remove.d.ts +8 -0
- package/dist/types/components/project-remove.d.ts.map +1 -0
- package/dist/types/components/project-select.d.ts +8 -0
- package/dist/types/components/project-select.d.ts.map +1 -0
- package/dist/types/components/project-show.d.ts +7 -0
- package/dist/types/components/project-show.d.ts.map +1 -0
- package/dist/types/components/resource-clear.d.ts +2 -0
- package/dist/types/components/resource-clear.d.ts.map +1 -0
- package/dist/types/components/resource-delete.d.ts +9 -0
- package/dist/types/components/resource-delete.d.ts.map +1 -0
- package/dist/types/components/resource-list.d.ts +2 -0
- package/dist/types/components/resource-list.d.ts.map +1 -0
- package/dist/types/components/resource-sync.d.ts +8 -0
- package/dist/types/components/resource-sync.d.ts.map +1 -0
- package/dist/types/components/resource-types.d.ts +7 -0
- package/dist/types/components/resource-types.d.ts.map +1 -0
- package/dist/types/components/resource-upload.d.ts +8 -0
- package/dist/types/components/resource-upload.d.ts.map +1 -0
- package/dist/types/components/schedule-create.d.ts +7 -0
- package/dist/types/components/schedule-create.d.ts.map +1 -0
- package/dist/types/components/schedule-delete.d.ts +7 -0
- package/dist/types/components/schedule-delete.d.ts.map +1 -0
- package/dist/types/components/schedule-list.d.ts +6 -0
- package/dist/types/components/schedule-list.d.ts.map +1 -0
- package/dist/types/components/schedule-runs.d.ts +8 -0
- package/dist/types/components/schedule-runs.d.ts.map +1 -0
- package/dist/types/components/secret-bulk.d.ts +8 -0
- package/dist/types/components/secret-bulk.d.ts.map +1 -0
- package/dist/types/components/secret-create.d.ts +9 -0
- package/dist/types/components/secret-create.d.ts.map +1 -0
- package/dist/types/components/secret-delete.d.ts +8 -0
- package/dist/types/components/secret-delete.d.ts.map +1 -0
- package/dist/types/components/secret-list.d.ts +7 -0
- package/dist/types/components/secret-list.d.ts.map +1 -0
- package/dist/types/components/secret-sync.d.ts +9 -0
- package/dist/types/components/secret-sync.d.ts.map +1 -0
- package/dist/types/components/watch.d.ts +7 -0
- package/dist/types/components/watch.d.ts.map +1 -0
- package/dist/types/hooks/useApi.d.ts +29 -0
- package/dist/types/hooks/useApi.d.ts.map +1 -0
- package/dist/types/positronic.d.ts +3 -0
- package/dist/types/positronic.d.ts.map +1 -0
- package/dist/types/test/mock-api-client.d.ts +25 -0
- package/dist/types/test/mock-api-client.d.ts.map +1 -0
- package/dist/types/test/test-dev-server.d.ts +129 -0
- package/dist/types/test/test-dev-server.d.ts.map +1 -0
- package/package.json +37 -0
- package/src/cli.ts +981 -0
- package/src/commands/backend.ts +63 -0
- package/src/commands/brain.test.ts +1004 -0
- package/src/commands/brain.ts +215 -0
- package/src/commands/helpers.test.ts +487 -0
- package/src/commands/helpers.ts +870 -0
- package/src/commands/project-config-manager.ts +152 -0
- package/src/commands/project.test.ts +502 -0
- package/src/commands/project.ts +109 -0
- package/src/commands/resources.test.ts +1052 -0
- package/src/commands/resources.ts +97 -0
- package/src/commands/schedule.test.ts +481 -0
- package/src/commands/schedule.ts +65 -0
- package/src/commands/secret.test.ts +210 -0
- package/src/commands/secret.ts +50 -0
- package/src/commands/server.test.ts +493 -0
- package/src/commands/server.ts +353 -0
- package/src/commands/test-utils.ts +324 -0
- package/src/components/brain-history.tsx +198 -0
- package/src/components/brain-list.tsx +105 -0
- package/src/components/brain-rerun.tsx +111 -0
- package/src/components/brain-show.tsx +92 -0
- package/src/components/error.tsx +24 -0
- package/src/components/project-add.tsx +59 -0
- package/src/components/project-create.tsx +83 -0
- package/src/components/project-list.tsx +83 -0
- package/src/components/project-remove.tsx +55 -0
- package/src/components/project-select.tsx +200 -0
- package/src/components/project-show.tsx +58 -0
- package/src/components/resource-clear.tsx +127 -0
- package/src/components/resource-delete.tsx +160 -0
- package/src/components/resource-list.tsx +177 -0
- package/src/components/resource-sync.tsx +170 -0
- package/src/components/resource-types.tsx +55 -0
- package/src/components/resource-upload.tsx +182 -0
- package/src/components/schedule-create.tsx +90 -0
- package/src/components/schedule-delete.tsx +116 -0
- package/src/components/schedule-list.tsx +186 -0
- package/src/components/schedule-runs.tsx +151 -0
- package/src/components/secret-bulk.tsx +79 -0
- package/src/components/secret-create.tsx +49 -0
- package/src/components/secret-delete.tsx +41 -0
- package/src/components/secret-list.tsx +41 -0
- package/src/components/watch.tsx +155 -0
- package/src/hooks/useApi.ts +183 -0
- package/src/positronic.ts +40 -0
- package/src/test/data/resources/config.json +1 -0
- package/src/test/data/resources/data/config.json +1 -0
- package/src/test/data/resources/data/logo.png +2 -0
- package/src/test/data/resources/docs/api.md +3 -0
- package/src/test/data/resources/docs/readme.md +3 -0
- package/src/test/data/resources/example.md +3 -0
- package/src/test/data/resources/file with spaces.txt +1 -0
- package/src/test/data/resources/readme.md +3 -0
- package/src/test/data/resources/test.txt +1 -0
- package/src/test/mock-api-client.ts +145 -0
- package/src/test/test-dev-server.ts +1003 -0
- package/tsconfig.json +11 -0
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
+
try {
|
|
3
|
+
var info = gen[key](arg);
|
|
4
|
+
var value = info.value;
|
|
5
|
+
} catch (error) {
|
|
6
|
+
reject(error);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (info.done) {
|
|
10
|
+
resolve(value);
|
|
11
|
+
} else {
|
|
12
|
+
Promise.resolve(value).then(_next, _throw);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function _async_to_generator(fn) {
|
|
16
|
+
return function() {
|
|
17
|
+
var self = this, args = arguments;
|
|
18
|
+
return new Promise(function(resolve, reject) {
|
|
19
|
+
var gen = fn.apply(self, args);
|
|
20
|
+
function _next(value) {
|
|
21
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
+
}
|
|
23
|
+
function _throw(err) {
|
|
24
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
+
}
|
|
26
|
+
_next(undefined);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function _ts_generator(thisArg, body) {
|
|
31
|
+
var f, y, t, _ = {
|
|
32
|
+
label: 0,
|
|
33
|
+
sent: function() {
|
|
34
|
+
if (t[0] & 1) throw t[1];
|
|
35
|
+
return t[1];
|
|
36
|
+
},
|
|
37
|
+
trys: [],
|
|
38
|
+
ops: []
|
|
39
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
40
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
41
|
+
return this;
|
|
42
|
+
}), g;
|
|
43
|
+
function verb(n) {
|
|
44
|
+
return function(v) {
|
|
45
|
+
return step([
|
|
46
|
+
n,
|
|
47
|
+
v
|
|
48
|
+
]);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function step(op) {
|
|
52
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
53
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
54
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
55
|
+
if (y = 0, t) op = [
|
|
56
|
+
op[0] & 2,
|
|
57
|
+
t.value
|
|
58
|
+
];
|
|
59
|
+
switch(op[0]){
|
|
60
|
+
case 0:
|
|
61
|
+
case 1:
|
|
62
|
+
t = op;
|
|
63
|
+
break;
|
|
64
|
+
case 4:
|
|
65
|
+
_.label++;
|
|
66
|
+
return {
|
|
67
|
+
value: op[1],
|
|
68
|
+
done: false
|
|
69
|
+
};
|
|
70
|
+
case 5:
|
|
71
|
+
_.label++;
|
|
72
|
+
y = op[1];
|
|
73
|
+
op = [
|
|
74
|
+
0
|
|
75
|
+
];
|
|
76
|
+
continue;
|
|
77
|
+
case 7:
|
|
78
|
+
op = _.ops.pop();
|
|
79
|
+
_.trys.pop();
|
|
80
|
+
continue;
|
|
81
|
+
default:
|
|
82
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
83
|
+
_ = 0;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
87
|
+
_.label = op[1];
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
91
|
+
_.label = t[1];
|
|
92
|
+
t = op;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
if (t && _.label < t[2]) {
|
|
96
|
+
_.label = t[2];
|
|
97
|
+
_.ops.push(op);
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
if (t[2]) _.ops.pop();
|
|
101
|
+
_.trys.pop();
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
op = body.call(thisArg, _);
|
|
105
|
+
} catch (e) {
|
|
106
|
+
op = [
|
|
107
|
+
6,
|
|
108
|
+
e
|
|
109
|
+
];
|
|
110
|
+
y = 0;
|
|
111
|
+
} finally{
|
|
112
|
+
f = t = 0;
|
|
113
|
+
}
|
|
114
|
+
if (op[0] & 5) throw op[1];
|
|
115
|
+
return {
|
|
116
|
+
value: op[0] ? op[1] : void 0,
|
|
117
|
+
done: true
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
import * as fs from 'fs';
|
|
122
|
+
import * as path from 'path';
|
|
123
|
+
/**
|
|
124
|
+
* Load the backend configuration from positronic.config.json
|
|
125
|
+
*/ function loadBackendConfig(projectRootPath) {
|
|
126
|
+
var configPath = path.join(projectRootPath, 'positronic.config.json');
|
|
127
|
+
var config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
|
128
|
+
if (!config.backend) {
|
|
129
|
+
throw new Error('No backend configuration found in positronic.config.json');
|
|
130
|
+
}
|
|
131
|
+
return config;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Load the backend module based on the configuration
|
|
135
|
+
*/ function loadBackendModule(projectRootPath) {
|
|
136
|
+
return _async_to_generator(function() {
|
|
137
|
+
var config, backendPackage, backendModule, packagePath, localModulePath;
|
|
138
|
+
return _ts_generator(this, function(_state) {
|
|
139
|
+
switch(_state.label){
|
|
140
|
+
case 0:
|
|
141
|
+
config = loadBackendConfig(projectRootPath);
|
|
142
|
+
backendPackage = config.backend.package;
|
|
143
|
+
if (!backendPackage.startsWith('file:')) return [
|
|
144
|
+
3,
|
|
145
|
+
2
|
|
146
|
+
];
|
|
147
|
+
// Load from local file path
|
|
148
|
+
packagePath = backendPackage.replace('file:', '');
|
|
149
|
+
localModulePath = path.join(packagePath, 'dist', 'src', 'node-index.js');
|
|
150
|
+
return [
|
|
151
|
+
4,
|
|
152
|
+
import(localModulePath)
|
|
153
|
+
];
|
|
154
|
+
case 1:
|
|
155
|
+
backendModule = _state.sent();
|
|
156
|
+
return [
|
|
157
|
+
3,
|
|
158
|
+
4
|
|
159
|
+
];
|
|
160
|
+
case 2:
|
|
161
|
+
return [
|
|
162
|
+
4,
|
|
163
|
+
import(backendPackage)
|
|
164
|
+
];
|
|
165
|
+
case 3:
|
|
166
|
+
// Load from npm package
|
|
167
|
+
backendModule = _state.sent();
|
|
168
|
+
_state.label = 4;
|
|
169
|
+
case 4:
|
|
170
|
+
return [
|
|
171
|
+
2,
|
|
172
|
+
backendModule
|
|
173
|
+
];
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
})();
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Create a dev server instance from the backend configuration
|
|
180
|
+
*/ export function createDevServer(projectRootPath) {
|
|
181
|
+
return _async_to_generator(function() {
|
|
182
|
+
var DevServer;
|
|
183
|
+
return _ts_generator(this, function(_state) {
|
|
184
|
+
switch(_state.label){
|
|
185
|
+
case 0:
|
|
186
|
+
return [
|
|
187
|
+
4,
|
|
188
|
+
loadBackendModule(projectRootPath)
|
|
189
|
+
];
|
|
190
|
+
case 1:
|
|
191
|
+
DevServer = _state.sent().DevServer;
|
|
192
|
+
return [
|
|
193
|
+
2,
|
|
194
|
+
new DevServer(projectRootPath)
|
|
195
|
+
];
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
})();
|
|
199
|
+
}
|
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
+
try {
|
|
3
|
+
var info = gen[key](arg);
|
|
4
|
+
var value = info.value;
|
|
5
|
+
} catch (error) {
|
|
6
|
+
reject(error);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (info.done) {
|
|
10
|
+
resolve(value);
|
|
11
|
+
} else {
|
|
12
|
+
Promise.resolve(value).then(_next, _throw);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function _async_to_generator(fn) {
|
|
16
|
+
return function() {
|
|
17
|
+
var self = this, args = arguments;
|
|
18
|
+
return new Promise(function(resolve, reject) {
|
|
19
|
+
var gen = fn.apply(self, args);
|
|
20
|
+
function _next(value) {
|
|
21
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
+
}
|
|
23
|
+
function _throw(err) {
|
|
24
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
+
}
|
|
26
|
+
_next(undefined);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function _class_call_check(instance, Constructor) {
|
|
31
|
+
if (!(instance instanceof Constructor)) {
|
|
32
|
+
throw new TypeError("Cannot call a class as a function");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function _defineProperties(target, props) {
|
|
36
|
+
for(var i = 0; i < props.length; i++){
|
|
37
|
+
var descriptor = props[i];
|
|
38
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
39
|
+
descriptor.configurable = true;
|
|
40
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
41
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
45
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
46
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
47
|
+
return Constructor;
|
|
48
|
+
}
|
|
49
|
+
function _ts_generator(thisArg, body) {
|
|
50
|
+
var f, y, t, _ = {
|
|
51
|
+
label: 0,
|
|
52
|
+
sent: function() {
|
|
53
|
+
if (t[0] & 1) throw t[1];
|
|
54
|
+
return t[1];
|
|
55
|
+
},
|
|
56
|
+
trys: [],
|
|
57
|
+
ops: []
|
|
58
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
59
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
60
|
+
return this;
|
|
61
|
+
}), g;
|
|
62
|
+
function verb(n) {
|
|
63
|
+
return function(v) {
|
|
64
|
+
return step([
|
|
65
|
+
n,
|
|
66
|
+
v
|
|
67
|
+
]);
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function step(op) {
|
|
71
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
72
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
73
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
74
|
+
if (y = 0, t) op = [
|
|
75
|
+
op[0] & 2,
|
|
76
|
+
t.value
|
|
77
|
+
];
|
|
78
|
+
switch(op[0]){
|
|
79
|
+
case 0:
|
|
80
|
+
case 1:
|
|
81
|
+
t = op;
|
|
82
|
+
break;
|
|
83
|
+
case 4:
|
|
84
|
+
_.label++;
|
|
85
|
+
return {
|
|
86
|
+
value: op[1],
|
|
87
|
+
done: false
|
|
88
|
+
};
|
|
89
|
+
case 5:
|
|
90
|
+
_.label++;
|
|
91
|
+
y = op[1];
|
|
92
|
+
op = [
|
|
93
|
+
0
|
|
94
|
+
];
|
|
95
|
+
continue;
|
|
96
|
+
case 7:
|
|
97
|
+
op = _.ops.pop();
|
|
98
|
+
_.trys.pop();
|
|
99
|
+
continue;
|
|
100
|
+
default:
|
|
101
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
102
|
+
_ = 0;
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
106
|
+
_.label = op[1];
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
110
|
+
_.label = t[1];
|
|
111
|
+
t = op;
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
if (t && _.label < t[2]) {
|
|
115
|
+
_.label = t[2];
|
|
116
|
+
_.ops.push(op);
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
if (t[2]) _.ops.pop();
|
|
120
|
+
_.trys.pop();
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
op = body.call(thisArg, _);
|
|
124
|
+
} catch (e) {
|
|
125
|
+
op = [
|
|
126
|
+
6,
|
|
127
|
+
e
|
|
128
|
+
];
|
|
129
|
+
y = 0;
|
|
130
|
+
} finally{
|
|
131
|
+
f = t = 0;
|
|
132
|
+
}
|
|
133
|
+
if (op[0] & 5) throw op[1];
|
|
134
|
+
return {
|
|
135
|
+
value: op[0] ? op[1] : void 0,
|
|
136
|
+
done: true
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
import { apiClient } from './helpers.js';
|
|
141
|
+
import React from 'react';
|
|
142
|
+
import { Text } from 'ink';
|
|
143
|
+
import { Watch } from '../components/watch.js';
|
|
144
|
+
import { BrainList } from '../components/brain-list.js';
|
|
145
|
+
import { BrainHistory } from '../components/brain-history.js';
|
|
146
|
+
import { BrainShow } from '../components/brain-show.js';
|
|
147
|
+
import { BrainRerun } from '../components/brain-rerun.js';
|
|
148
|
+
import { ErrorComponent } from '../components/error.js';
|
|
149
|
+
export var BrainCommand = /*#__PURE__*/ function() {
|
|
150
|
+
"use strict";
|
|
151
|
+
function BrainCommand() {
|
|
152
|
+
_class_call_check(this, BrainCommand);
|
|
153
|
+
}
|
|
154
|
+
_create_class(BrainCommand, [
|
|
155
|
+
{
|
|
156
|
+
key: "list",
|
|
157
|
+
value: function list(argv) {
|
|
158
|
+
return React.createElement(BrainList);
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
key: "history",
|
|
163
|
+
value: function history(param) {
|
|
164
|
+
var brainName = param.name, limit = param.limit;
|
|
165
|
+
return React.createElement(BrainHistory, {
|
|
166
|
+
brainName: brainName,
|
|
167
|
+
limit: limit
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
key: "show",
|
|
173
|
+
value: function show(param) {
|
|
174
|
+
var brainName = param.name;
|
|
175
|
+
return React.createElement(BrainShow, {
|
|
176
|
+
brainName: brainName
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
key: "rerun",
|
|
182
|
+
value: function rerun(param) {
|
|
183
|
+
var brainName = param.name, runId = param.runId, startsAt = param.startsAt, stopsAfter = param.stopsAfter;
|
|
184
|
+
return React.createElement(BrainRerun, {
|
|
185
|
+
brainName: brainName,
|
|
186
|
+
runId: runId,
|
|
187
|
+
startsAt: startsAt,
|
|
188
|
+
stopsAfter: stopsAfter
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
key: "run",
|
|
194
|
+
value: function run(_0) {
|
|
195
|
+
return _async_to_generator(function(param) {
|
|
196
|
+
var brainName, watch, apiPath, response, result, errorText, error;
|
|
197
|
+
return _ts_generator(this, function(_state) {
|
|
198
|
+
switch(_state.label){
|
|
199
|
+
case 0:
|
|
200
|
+
brainName = param.name, watch = param.watch;
|
|
201
|
+
apiPath = '/brains/runs';
|
|
202
|
+
_state.label = 1;
|
|
203
|
+
case 1:
|
|
204
|
+
_state.trys.push([
|
|
205
|
+
1,
|
|
206
|
+
8,
|
|
207
|
+
,
|
|
208
|
+
9
|
|
209
|
+
]);
|
|
210
|
+
return [
|
|
211
|
+
4,
|
|
212
|
+
apiClient.fetch(apiPath, {
|
|
213
|
+
method: 'POST',
|
|
214
|
+
headers: {
|
|
215
|
+
'Content-Type': 'application/json'
|
|
216
|
+
},
|
|
217
|
+
body: JSON.stringify({
|
|
218
|
+
brainName: brainName
|
|
219
|
+
})
|
|
220
|
+
})
|
|
221
|
+
];
|
|
222
|
+
case 2:
|
|
223
|
+
response = _state.sent();
|
|
224
|
+
if (!(response.status === 201)) return [
|
|
225
|
+
3,
|
|
226
|
+
4
|
|
227
|
+
];
|
|
228
|
+
return [
|
|
229
|
+
4,
|
|
230
|
+
response.json()
|
|
231
|
+
];
|
|
232
|
+
case 3:
|
|
233
|
+
result = _state.sent();
|
|
234
|
+
if (watch) {
|
|
235
|
+
// Return Watch component for CLI to render
|
|
236
|
+
return [
|
|
237
|
+
2,
|
|
238
|
+
this.watch({
|
|
239
|
+
runId: result.brainRunId,
|
|
240
|
+
_: [],
|
|
241
|
+
$0: ''
|
|
242
|
+
})
|
|
243
|
+
];
|
|
244
|
+
} else {
|
|
245
|
+
// Return React element displaying the run ID
|
|
246
|
+
return [
|
|
247
|
+
2,
|
|
248
|
+
React.createElement(Text, null, "Run ID: ".concat(result.brainRunId))
|
|
249
|
+
];
|
|
250
|
+
}
|
|
251
|
+
return [
|
|
252
|
+
3,
|
|
253
|
+
7
|
|
254
|
+
];
|
|
255
|
+
case 4:
|
|
256
|
+
if (!(response.status === 404)) return [
|
|
257
|
+
3,
|
|
258
|
+
5
|
|
259
|
+
];
|
|
260
|
+
// Handle brain not found with a helpful message
|
|
261
|
+
return [
|
|
262
|
+
2,
|
|
263
|
+
React.createElement(ErrorComponent, {
|
|
264
|
+
error: {
|
|
265
|
+
title: 'Brain Not Found',
|
|
266
|
+
message: "Brain '".concat(brainName, "' not found."),
|
|
267
|
+
details: 'Please check that:\n 1. The brain name is spelled correctly\n 2. The brain exists in your project\n 3. The brain has been properly defined and exported\n\nYou can list available brains with: positronic list'
|
|
268
|
+
}
|
|
269
|
+
})
|
|
270
|
+
];
|
|
271
|
+
case 5:
|
|
272
|
+
return [
|
|
273
|
+
4,
|
|
274
|
+
response.text()
|
|
275
|
+
];
|
|
276
|
+
case 6:
|
|
277
|
+
errorText = _state.sent();
|
|
278
|
+
console.error("Error starting brain run: ".concat(response.status, " ").concat(response.statusText));
|
|
279
|
+
console.error("Server response: ".concat(errorText));
|
|
280
|
+
process.exit(1);
|
|
281
|
+
_state.label = 7;
|
|
282
|
+
case 7:
|
|
283
|
+
return [
|
|
284
|
+
3,
|
|
285
|
+
9
|
|
286
|
+
];
|
|
287
|
+
case 8:
|
|
288
|
+
error = _state.sent();
|
|
289
|
+
console.error("Error connecting to the local development server.");
|
|
290
|
+
console.error("Please ensure the server is running ('positronic server' or 'px s').");
|
|
291
|
+
if (error.code === 'ECONNREFUSED') {
|
|
292
|
+
console.error('Reason: Connection refused. The server might not be running or is listening on a different port.');
|
|
293
|
+
} else {
|
|
294
|
+
console.error("Fetch error details: ".concat(error.message));
|
|
295
|
+
}
|
|
296
|
+
process.exit(1);
|
|
297
|
+
return [
|
|
298
|
+
3,
|
|
299
|
+
9
|
|
300
|
+
];
|
|
301
|
+
case 9:
|
|
302
|
+
return [
|
|
303
|
+
2
|
|
304
|
+
];
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
}).apply(this, arguments);
|
|
308
|
+
}
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
key: "watch",
|
|
312
|
+
value: function watch(_0) {
|
|
313
|
+
return _async_to_generator(function(param) {
|
|
314
|
+
var runId, brainName, port, apiPath, response, result, activeRun, port1, errorText, error;
|
|
315
|
+
return _ts_generator(this, function(_state) {
|
|
316
|
+
switch(_state.label){
|
|
317
|
+
case 0:
|
|
318
|
+
runId = param.runId, brainName = param.name;
|
|
319
|
+
// If a specific run ID is provided, return the Watch component
|
|
320
|
+
if (runId) {
|
|
321
|
+
port = process.env.POSITRONIC_PORT || '8787';
|
|
322
|
+
return [
|
|
323
|
+
2,
|
|
324
|
+
React.createElement(Watch, {
|
|
325
|
+
runId: runId,
|
|
326
|
+
port: port
|
|
327
|
+
})
|
|
328
|
+
];
|
|
329
|
+
}
|
|
330
|
+
if (!brainName) return [
|
|
331
|
+
3,
|
|
332
|
+
8
|
|
333
|
+
];
|
|
334
|
+
_state.label = 1;
|
|
335
|
+
case 1:
|
|
336
|
+
_state.trys.push([
|
|
337
|
+
1,
|
|
338
|
+
7,
|
|
339
|
+
,
|
|
340
|
+
8
|
|
341
|
+
]);
|
|
342
|
+
apiPath = "/brains/".concat(encodeURIComponent(brainName), "/active-runs");
|
|
343
|
+
return [
|
|
344
|
+
4,
|
|
345
|
+
apiClient.fetch(apiPath, {
|
|
346
|
+
method: 'GET'
|
|
347
|
+
})
|
|
348
|
+
];
|
|
349
|
+
case 2:
|
|
350
|
+
response = _state.sent();
|
|
351
|
+
if (!(response.status === 200)) return [
|
|
352
|
+
3,
|
|
353
|
+
4
|
|
354
|
+
];
|
|
355
|
+
return [
|
|
356
|
+
4,
|
|
357
|
+
response.json()
|
|
358
|
+
];
|
|
359
|
+
case 3:
|
|
360
|
+
result = _state.sent();
|
|
361
|
+
if (result.runs.length === 0) {
|
|
362
|
+
return [
|
|
363
|
+
2,
|
|
364
|
+
React.createElement(ErrorComponent, {
|
|
365
|
+
error: {
|
|
366
|
+
title: 'No Active Runs',
|
|
367
|
+
message: 'No currently running brain runs found for brain "'.concat(brainName, '".'),
|
|
368
|
+
details: "To start a new run, use: positronic run ".concat(brainName)
|
|
369
|
+
}
|
|
370
|
+
})
|
|
371
|
+
];
|
|
372
|
+
}
|
|
373
|
+
if (result.runs.length > 1) {
|
|
374
|
+
return [
|
|
375
|
+
2,
|
|
376
|
+
React.createElement(ErrorComponent, {
|
|
377
|
+
error: {
|
|
378
|
+
title: 'Multiple Active Runs',
|
|
379
|
+
message: "Found ".concat(result.runs.length, ' active runs for brain "').concat(brainName, '".'),
|
|
380
|
+
details: "Please specify a specific run ID with --run-id:\n".concat(result.runs.map(function(run) {
|
|
381
|
+
return " positronic watch --run-id ".concat(run.brainRunId);
|
|
382
|
+
}).join('\n'))
|
|
383
|
+
}
|
|
384
|
+
})
|
|
385
|
+
];
|
|
386
|
+
}
|
|
387
|
+
// Exactly one active run found - watch it
|
|
388
|
+
activeRun = result.runs[0];
|
|
389
|
+
port1 = process.env.POSITRONIC_PORT || '8787';
|
|
390
|
+
return [
|
|
391
|
+
2,
|
|
392
|
+
React.createElement(Watch, {
|
|
393
|
+
runId: activeRun.brainRunId,
|
|
394
|
+
port: port1
|
|
395
|
+
})
|
|
396
|
+
];
|
|
397
|
+
case 4:
|
|
398
|
+
return [
|
|
399
|
+
4,
|
|
400
|
+
response.text()
|
|
401
|
+
];
|
|
402
|
+
case 5:
|
|
403
|
+
errorText = _state.sent();
|
|
404
|
+
return [
|
|
405
|
+
2,
|
|
406
|
+
React.createElement(ErrorComponent, {
|
|
407
|
+
error: {
|
|
408
|
+
title: 'API Error',
|
|
409
|
+
message: 'Failed to get active runs for brain "'.concat(brainName, '".'),
|
|
410
|
+
details: "Server returned ".concat(response.status, ": ").concat(errorText)
|
|
411
|
+
}
|
|
412
|
+
})
|
|
413
|
+
];
|
|
414
|
+
case 6:
|
|
415
|
+
return [
|
|
416
|
+
3,
|
|
417
|
+
8
|
|
418
|
+
];
|
|
419
|
+
case 7:
|
|
420
|
+
error = _state.sent();
|
|
421
|
+
return [
|
|
422
|
+
2,
|
|
423
|
+
React.createElement(ErrorComponent, {
|
|
424
|
+
error: {
|
|
425
|
+
title: 'Connection Error',
|
|
426
|
+
message: 'Error connecting to the local development server.',
|
|
427
|
+
details: "Please ensure the server is running ('positronic server' or 'px s').\n\nError details: ".concat(error.message)
|
|
428
|
+
}
|
|
429
|
+
})
|
|
430
|
+
];
|
|
431
|
+
case 8:
|
|
432
|
+
// Neither runId nor brainName provided – return an error element.
|
|
433
|
+
return [
|
|
434
|
+
2,
|
|
435
|
+
React.createElement(Text, {
|
|
436
|
+
color: 'red'
|
|
437
|
+
}, 'Error: You must provide either a brain run ID or a brain name.')
|
|
438
|
+
];
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
}).apply(this, arguments);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
]);
|
|
445
|
+
return BrainCommand;
|
|
446
|
+
}();
|