@positronic/spec 0.0.52 → 0.0.54
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/api.d.ts +41 -12
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +192 -46
- package/dist/api.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/src/api.js +417 -56
- package/dist/src/index.js +1 -1
- package/package.json +1 -1
package/dist/src/api.js
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
5
|
+
}
|
|
6
|
+
function _array_with_holes(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return arr;
|
|
8
|
+
}
|
|
1
9
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
10
|
try {
|
|
3
11
|
var info = gen[key](arg);
|
|
@@ -27,10 +35,48 @@ function _async_to_generator(fn) {
|
|
|
27
35
|
});
|
|
28
36
|
};
|
|
29
37
|
}
|
|
38
|
+
function _iterable_to_array_limit(arr, i) {
|
|
39
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
40
|
+
if (_i == null) return;
|
|
41
|
+
var _arr = [];
|
|
42
|
+
var _n = true;
|
|
43
|
+
var _d = false;
|
|
44
|
+
var _s, _e;
|
|
45
|
+
try {
|
|
46
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
47
|
+
_arr.push(_s.value);
|
|
48
|
+
if (i && _arr.length === i) break;
|
|
49
|
+
}
|
|
50
|
+
} catch (err) {
|
|
51
|
+
_d = true;
|
|
52
|
+
_e = err;
|
|
53
|
+
} finally{
|
|
54
|
+
try {
|
|
55
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
56
|
+
} finally{
|
|
57
|
+
if (_d) throw _e;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return _arr;
|
|
61
|
+
}
|
|
62
|
+
function _non_iterable_rest() {
|
|
63
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
64
|
+
}
|
|
65
|
+
function _sliced_to_array(arr, i) {
|
|
66
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
67
|
+
}
|
|
30
68
|
function _type_of(obj) {
|
|
31
69
|
"@swc/helpers - typeof";
|
|
32
70
|
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
33
71
|
}
|
|
72
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
73
|
+
if (!o) return;
|
|
74
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
75
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
76
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
77
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
78
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
79
|
+
}
|
|
34
80
|
function _ts_generator(thisArg, body) {
|
|
35
81
|
var f, y, t, _ = {
|
|
36
82
|
label: 0,
|
|
@@ -2461,19 +2507,19 @@ export var brains = {
|
|
|
2461
2507
|
});
|
|
2462
2508
|
})();
|
|
2463
2509
|
},
|
|
2464
|
-
|
|
2465
|
-
* Test that
|
|
2466
|
-
* Requires a brain with
|
|
2510
|
+
watchAgentEvents: /**
|
|
2511
|
+
* Test that agent steps emit proper AGENT_* events in the SSE stream.
|
|
2512
|
+
* Requires a brain with an agent step that will pause on a webhook.
|
|
2467
2513
|
*
|
|
2468
2514
|
* Expected events before webhook pause:
|
|
2469
|
-
* -
|
|
2470
|
-
* -
|
|
2471
|
-
* -
|
|
2472
|
-
* -
|
|
2515
|
+
* - AGENT_START (with prompt and optional system)
|
|
2516
|
+
* - AGENT_ITERATION
|
|
2517
|
+
* - AGENT_TOOL_CALL
|
|
2518
|
+
* - AGENT_WEBHOOK (before WEBHOOK event)
|
|
2473
2519
|
* - WEBHOOK
|
|
2474
|
-
*/ function
|
|
2520
|
+
*/ function watchAgentEvents(fetch, agentBrainIdentifier) {
|
|
2475
2521
|
return _async_to_generator(function() {
|
|
2476
|
-
var runRequest, runResponse, brainRunId, watchRequest, watchResponse, events, reader, decoder, buffer, done, _ref, value, streamDone, eventEndIndex, message, event,
|
|
2522
|
+
var runRequest, runResponse, brainRunId, watchRequest, watchResponse, events, reader, decoder, buffer, done, _ref, value, streamDone, eventEndIndex, message, event, hasAgentStart, agentStartEvent, hasAgentIteration, hasAgentToolCall, webhookIndex, agentWebhookIndex, agentWebhookEvent, error;
|
|
2477
2523
|
return _ts_generator(this, function(_state) {
|
|
2478
2524
|
switch(_state.label){
|
|
2479
2525
|
case 0:
|
|
@@ -2483,14 +2529,14 @@ export var brains = {
|
|
|
2483
2529
|
,
|
|
2484
2530
|
12
|
|
2485
2531
|
]);
|
|
2486
|
-
// Start the
|
|
2532
|
+
// Start the agent brain
|
|
2487
2533
|
runRequest = new Request('http://example.com/brains/runs', {
|
|
2488
2534
|
method: 'POST',
|
|
2489
2535
|
headers: {
|
|
2490
2536
|
'Content-Type': 'application/json'
|
|
2491
2537
|
},
|
|
2492
2538
|
body: JSON.stringify({
|
|
2493
|
-
identifier:
|
|
2539
|
+
identifier: agentBrainIdentifier
|
|
2494
2540
|
})
|
|
2495
2541
|
});
|
|
2496
2542
|
return [
|
|
@@ -2605,74 +2651,74 @@ export var brains = {
|
|
|
2605
2651
|
7
|
|
2606
2652
|
];
|
|
2607
2653
|
case 10:
|
|
2608
|
-
// Verify required
|
|
2609
|
-
|
|
2610
|
-
return e.type === BRAIN_EVENTS.
|
|
2654
|
+
// Verify required agent events are present
|
|
2655
|
+
hasAgentStart = events.some(function(e) {
|
|
2656
|
+
return e.type === BRAIN_EVENTS.AGENT_START;
|
|
2611
2657
|
});
|
|
2612
|
-
if (!
|
|
2613
|
-
console.error('Missing
|
|
2658
|
+
if (!hasAgentStart) {
|
|
2659
|
+
console.error('Missing AGENT_START event in SSE stream');
|
|
2614
2660
|
return [
|
|
2615
2661
|
2,
|
|
2616
2662
|
false
|
|
2617
2663
|
];
|
|
2618
2664
|
}
|
|
2619
|
-
// Verify
|
|
2620
|
-
|
|
2621
|
-
return e.type === BRAIN_EVENTS.
|
|
2665
|
+
// Verify AGENT_START has prompt field
|
|
2666
|
+
agentStartEvent = events.find(function(e) {
|
|
2667
|
+
return e.type === BRAIN_EVENTS.AGENT_START;
|
|
2622
2668
|
});
|
|
2623
|
-
if (!
|
|
2624
|
-
console.error('
|
|
2669
|
+
if (!agentStartEvent.prompt || typeof agentStartEvent.prompt !== 'string') {
|
|
2670
|
+
console.error('AGENT_START event missing prompt field');
|
|
2625
2671
|
return [
|
|
2626
2672
|
2,
|
|
2627
2673
|
false
|
|
2628
2674
|
];
|
|
2629
2675
|
}
|
|
2630
|
-
|
|
2631
|
-
return e.type === BRAIN_EVENTS.
|
|
2676
|
+
hasAgentIteration = events.some(function(e) {
|
|
2677
|
+
return e.type === BRAIN_EVENTS.AGENT_ITERATION;
|
|
2632
2678
|
});
|
|
2633
|
-
if (!
|
|
2634
|
-
console.error('Missing
|
|
2679
|
+
if (!hasAgentIteration) {
|
|
2680
|
+
console.error('Missing AGENT_ITERATION event in SSE stream');
|
|
2635
2681
|
return [
|
|
2636
2682
|
2,
|
|
2637
2683
|
false
|
|
2638
2684
|
];
|
|
2639
2685
|
}
|
|
2640
|
-
|
|
2641
|
-
return e.type === BRAIN_EVENTS.
|
|
2686
|
+
hasAgentToolCall = events.some(function(e) {
|
|
2687
|
+
return e.type === BRAIN_EVENTS.AGENT_TOOL_CALL;
|
|
2642
2688
|
});
|
|
2643
|
-
if (!
|
|
2644
|
-
console.error('Missing
|
|
2689
|
+
if (!hasAgentToolCall) {
|
|
2690
|
+
console.error('Missing AGENT_TOOL_CALL event in SSE stream');
|
|
2645
2691
|
return [
|
|
2646
2692
|
2,
|
|
2647
2693
|
false
|
|
2648
2694
|
];
|
|
2649
2695
|
}
|
|
2650
|
-
// If we got a WEBHOOK event, verify
|
|
2696
|
+
// If we got a WEBHOOK event, verify AGENT_WEBHOOK came before it
|
|
2651
2697
|
webhookIndex = events.findIndex(function(e) {
|
|
2652
2698
|
return e.type === BRAIN_EVENTS.WEBHOOK;
|
|
2653
2699
|
});
|
|
2654
2700
|
if (webhookIndex !== -1) {
|
|
2655
|
-
|
|
2656
|
-
return e.type === BRAIN_EVENTS.
|
|
2701
|
+
agentWebhookIndex = events.findIndex(function(e) {
|
|
2702
|
+
return e.type === BRAIN_EVENTS.AGENT_WEBHOOK;
|
|
2657
2703
|
});
|
|
2658
|
-
if (
|
|
2659
|
-
console.error('Missing
|
|
2704
|
+
if (agentWebhookIndex === -1) {
|
|
2705
|
+
console.error('Missing AGENT_WEBHOOK event before WEBHOOK event');
|
|
2660
2706
|
return [
|
|
2661
2707
|
2,
|
|
2662
2708
|
false
|
|
2663
2709
|
];
|
|
2664
2710
|
}
|
|
2665
|
-
if (
|
|
2666
|
-
console.error('
|
|
2711
|
+
if (agentWebhookIndex >= webhookIndex) {
|
|
2712
|
+
console.error('AGENT_WEBHOOK event must come before WEBHOOK event');
|
|
2667
2713
|
return [
|
|
2668
2714
|
2,
|
|
2669
2715
|
false
|
|
2670
2716
|
];
|
|
2671
2717
|
}
|
|
2672
|
-
// Verify
|
|
2673
|
-
|
|
2674
|
-
if (!
|
|
2675
|
-
console.error('
|
|
2718
|
+
// Verify AGENT_WEBHOOK has required fields
|
|
2719
|
+
agentWebhookEvent = events[agentWebhookIndex];
|
|
2720
|
+
if (!agentWebhookEvent.toolCallId || !agentWebhookEvent.toolName) {
|
|
2721
|
+
console.error('AGENT_WEBHOOK event missing toolCallId or toolName fields');
|
|
2676
2722
|
return [
|
|
2677
2723
|
2,
|
|
2678
2724
|
false
|
|
@@ -2685,7 +2731,7 @@ export var brains = {
|
|
|
2685
2731
|
];
|
|
2686
2732
|
case 11:
|
|
2687
2733
|
error = _state.sent();
|
|
2688
|
-
console.error("Failed to test
|
|
2734
|
+
console.error("Failed to test agent events for ".concat(agentBrainIdentifier, ":"), error);
|
|
2689
2735
|
return [
|
|
2690
2736
|
2,
|
|
2691
2737
|
false
|
|
@@ -2698,19 +2744,19 @@ export var brains = {
|
|
|
2698
2744
|
});
|
|
2699
2745
|
})();
|
|
2700
2746
|
},
|
|
2701
|
-
|
|
2702
|
-
* Test full
|
|
2703
|
-
* 1. Start
|
|
2747
|
+
agentWebhookResume: /**
|
|
2748
|
+
* Test full agent webhook resumption flow:
|
|
2749
|
+
* 1. Start an agent brain that will pause on a webhook
|
|
2704
2750
|
* 2. Verify it pauses with WEBHOOK event
|
|
2705
2751
|
* 3. Trigger the webhook with a response
|
|
2706
|
-
* 4. Verify the brain resumes and emits WEBHOOK_RESPONSE and
|
|
2752
|
+
* 4. Verify the brain resumes and emits WEBHOOK_RESPONSE and AGENT_TOOL_RESULT
|
|
2707
2753
|
*
|
|
2708
2754
|
* Requires:
|
|
2709
|
-
* - A brain with
|
|
2755
|
+
* - A brain with an agent step that calls a tool returning { waitFor: webhook(...) }
|
|
2710
2756
|
* - The webhook slug and identifier to trigger
|
|
2711
|
-
*/ function
|
|
2757
|
+
*/ function agentWebhookResume(fetch, agentBrainIdentifier, webhookSlug, webhookPayload) {
|
|
2712
2758
|
return _async_to_generator(function() {
|
|
2713
|
-
var runRequest, runResponse, brainRunId, watchRequest, watchResponse, foundWebhookEvent, reader, decoder, buffer, _ref, value, done, eventEndIndex, message, event, webhookRequest, webhookResponse, webhookResult, resumeWatchRequest, resumeWatchResponse, resumeEvents, reader1, decoder1, buffer1, done1, _ref1, value1, streamDone, eventEndIndex1, message1, event1, hasWebhookResponse,
|
|
2759
|
+
var runRequest, runResponse, brainRunId, watchRequest, watchResponse, foundWebhookEvent, reader, decoder, buffer, _ref, value, done, eventEndIndex, message, event, webhookRequest, webhookResponse, webhookResult, resumeWatchRequest, resumeWatchResponse, resumeEvents, reader1, decoder1, buffer1, done1, _ref1, value1, streamDone, eventEndIndex1, message1, event1, hasWebhookResponse, hasAgentToolResult, completeEvent, error;
|
|
2714
2760
|
return _ts_generator(this, function(_state) {
|
|
2715
2761
|
switch(_state.label){
|
|
2716
2762
|
case 0:
|
|
@@ -2720,14 +2766,14 @@ export var brains = {
|
|
|
2720
2766
|
,
|
|
2721
2767
|
22
|
|
2722
2768
|
]);
|
|
2723
|
-
// Step 1: Start the
|
|
2769
|
+
// Step 1: Start the agent brain
|
|
2724
2770
|
runRequest = new Request('http://example.com/brains/runs', {
|
|
2725
2771
|
method: 'POST',
|
|
2726
2772
|
headers: {
|
|
2727
2773
|
'Content-Type': 'application/json'
|
|
2728
2774
|
},
|
|
2729
2775
|
body: JSON.stringify({
|
|
2730
|
-
identifier:
|
|
2776
|
+
identifier: agentBrainIdentifier
|
|
2731
2777
|
})
|
|
2732
2778
|
});
|
|
2733
2779
|
return [
|
|
@@ -2993,12 +3039,12 @@ export var brains = {
|
|
|
2993
3039
|
false
|
|
2994
3040
|
];
|
|
2995
3041
|
}
|
|
2996
|
-
// Verify
|
|
2997
|
-
|
|
2998
|
-
return e.type === BRAIN_EVENTS.
|
|
3042
|
+
// Verify AGENT_TOOL_RESULT event is present (with the webhook response as result)
|
|
3043
|
+
hasAgentToolResult = resumeEvents.some(function(e) {
|
|
3044
|
+
return e.type === BRAIN_EVENTS.AGENT_TOOL_RESULT;
|
|
2999
3045
|
});
|
|
3000
|
-
if (!
|
|
3001
|
-
console.error('Missing
|
|
3046
|
+
if (!hasAgentToolResult) {
|
|
3047
|
+
console.error('Missing AGENT_TOOL_RESULT event after resume');
|
|
3002
3048
|
return [
|
|
3003
3049
|
2,
|
|
3004
3050
|
false
|
|
@@ -3028,7 +3074,7 @@ export var brains = {
|
|
|
3028
3074
|
];
|
|
3029
3075
|
case 21:
|
|
3030
3076
|
error = _state.sent();
|
|
3031
|
-
console.error("Failed to test
|
|
3077
|
+
console.error("Failed to test agent webhook resume for ".concat(agentBrainIdentifier, ":"), error);
|
|
3032
3078
|
return [
|
|
3033
3079
|
2,
|
|
3034
3080
|
false
|
|
@@ -4430,6 +4476,213 @@ export var webhooks = {
|
|
|
4430
4476
|
}
|
|
4431
4477
|
});
|
|
4432
4478
|
})();
|
|
4479
|
+
},
|
|
4480
|
+
uiForm: /**
|
|
4481
|
+
* Test POST /webhooks/system/ui-form - Built-in webhook for UI form submissions.
|
|
4482
|
+
* This is used by pages generated via .ui() steps to submit form data.
|
|
4483
|
+
*
|
|
4484
|
+
* The endpoint:
|
|
4485
|
+
* - Accepts form data (application/x-www-form-urlencoded or multipart/form-data)
|
|
4486
|
+
* - Requires an `identifier` query parameter to match the waiting brain
|
|
4487
|
+
* - Returns { received: true, action: 'resumed' | 'not_found', ... }
|
|
4488
|
+
*/ function uiForm(fetch, identifier, formData) {
|
|
4489
|
+
return _async_to_generator(function() {
|
|
4490
|
+
var params, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, key, value, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, v, request, response, data, error;
|
|
4491
|
+
return _ts_generator(this, function(_state) {
|
|
4492
|
+
switch(_state.label){
|
|
4493
|
+
case 0:
|
|
4494
|
+
_state.trys.push([
|
|
4495
|
+
0,
|
|
4496
|
+
3,
|
|
4497
|
+
,
|
|
4498
|
+
4
|
|
4499
|
+
]);
|
|
4500
|
+
// Build URLSearchParams from form data
|
|
4501
|
+
params = new URLSearchParams();
|
|
4502
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
4503
|
+
try {
|
|
4504
|
+
for(_iterator = Object.entries(formData)[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
4505
|
+
_step_value = _sliced_to_array(_step.value, 2), key = _step_value[0], value = _step_value[1];
|
|
4506
|
+
if (Array.isArray(value)) {
|
|
4507
|
+
_iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
4508
|
+
try {
|
|
4509
|
+
for(_iterator1 = value[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
4510
|
+
v = _step1.value;
|
|
4511
|
+
params.append("".concat(key, "[]"), v);
|
|
4512
|
+
}
|
|
4513
|
+
} catch (err) {
|
|
4514
|
+
_didIteratorError1 = true;
|
|
4515
|
+
_iteratorError1 = err;
|
|
4516
|
+
} finally{
|
|
4517
|
+
try {
|
|
4518
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
4519
|
+
_iterator1.return();
|
|
4520
|
+
}
|
|
4521
|
+
} finally{
|
|
4522
|
+
if (_didIteratorError1) {
|
|
4523
|
+
throw _iteratorError1;
|
|
4524
|
+
}
|
|
4525
|
+
}
|
|
4526
|
+
}
|
|
4527
|
+
} else {
|
|
4528
|
+
params.append(key, value);
|
|
4529
|
+
}
|
|
4530
|
+
}
|
|
4531
|
+
} catch (err) {
|
|
4532
|
+
_didIteratorError = true;
|
|
4533
|
+
_iteratorError = err;
|
|
4534
|
+
} finally{
|
|
4535
|
+
try {
|
|
4536
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
4537
|
+
_iterator.return();
|
|
4538
|
+
}
|
|
4539
|
+
} finally{
|
|
4540
|
+
if (_didIteratorError) {
|
|
4541
|
+
throw _iteratorError;
|
|
4542
|
+
}
|
|
4543
|
+
}
|
|
4544
|
+
}
|
|
4545
|
+
request = new Request("http://example.com/webhooks/system/ui-form?identifier=".concat(encodeURIComponent(identifier)), {
|
|
4546
|
+
method: 'POST',
|
|
4547
|
+
headers: {
|
|
4548
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
4549
|
+
},
|
|
4550
|
+
body: params.toString()
|
|
4551
|
+
});
|
|
4552
|
+
return [
|
|
4553
|
+
4,
|
|
4554
|
+
fetch(request)
|
|
4555
|
+
];
|
|
4556
|
+
case 1:
|
|
4557
|
+
response = _state.sent();
|
|
4558
|
+
// Accept 200 (found and processed) or 404 (no brain waiting)
|
|
4559
|
+
if (response.status !== 200 && response.status !== 404) {
|
|
4560
|
+
console.error("POST /webhooks/system/ui-form returned ".concat(response.status, ", expected 200 or 404"));
|
|
4561
|
+
return [
|
|
4562
|
+
2,
|
|
4563
|
+
false
|
|
4564
|
+
];
|
|
4565
|
+
}
|
|
4566
|
+
return [
|
|
4567
|
+
4,
|
|
4568
|
+
response.json()
|
|
4569
|
+
];
|
|
4570
|
+
case 2:
|
|
4571
|
+
data = _state.sent();
|
|
4572
|
+
// Validate response structure
|
|
4573
|
+
if (typeof data.received !== 'boolean') {
|
|
4574
|
+
console.error("Expected received to be boolean, got ".concat(_type_of(data.received)));
|
|
4575
|
+
return [
|
|
4576
|
+
2,
|
|
4577
|
+
false
|
|
4578
|
+
];
|
|
4579
|
+
}
|
|
4580
|
+
if (!data.action || typeof data.action !== 'string') {
|
|
4581
|
+
console.error("Expected action to be string, got ".concat(_type_of(data.action)));
|
|
4582
|
+
return [
|
|
4583
|
+
2,
|
|
4584
|
+
false
|
|
4585
|
+
];
|
|
4586
|
+
}
|
|
4587
|
+
// Action should be 'resumed' or 'not_found'
|
|
4588
|
+
if (data.action !== 'resumed' && data.action !== 'not_found') {
|
|
4589
|
+
console.error("Expected action to be 'resumed' or 'not_found', got '".concat(data.action, "'"));
|
|
4590
|
+
return [
|
|
4591
|
+
2,
|
|
4592
|
+
false
|
|
4593
|
+
];
|
|
4594
|
+
}
|
|
4595
|
+
return [
|
|
4596
|
+
2,
|
|
4597
|
+
true
|
|
4598
|
+
];
|
|
4599
|
+
case 3:
|
|
4600
|
+
error = _state.sent();
|
|
4601
|
+
console.error('Failed to test POST /webhooks/system/ui-form:', error);
|
|
4602
|
+
return [
|
|
4603
|
+
2,
|
|
4604
|
+
false
|
|
4605
|
+
];
|
|
4606
|
+
case 4:
|
|
4607
|
+
return [
|
|
4608
|
+
2
|
|
4609
|
+
];
|
|
4610
|
+
}
|
|
4611
|
+
});
|
|
4612
|
+
})();
|
|
4613
|
+
},
|
|
4614
|
+
uiFormMissingIdentifier: /**
|
|
4615
|
+
* Test POST /webhooks/system/ui-form with missing identifier - Should return 400
|
|
4616
|
+
*/ function uiFormMissingIdentifier(fetch) {
|
|
4617
|
+
return _async_to_generator(function() {
|
|
4618
|
+
var request, response, data, error;
|
|
4619
|
+
return _ts_generator(this, function(_state) {
|
|
4620
|
+
switch(_state.label){
|
|
4621
|
+
case 0:
|
|
4622
|
+
_state.trys.push([
|
|
4623
|
+
0,
|
|
4624
|
+
3,
|
|
4625
|
+
,
|
|
4626
|
+
4
|
|
4627
|
+
]);
|
|
4628
|
+
request = new Request('http://example.com/webhooks/system/ui-form', {
|
|
4629
|
+
method: 'POST',
|
|
4630
|
+
headers: {
|
|
4631
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
4632
|
+
},
|
|
4633
|
+
body: 'test=data'
|
|
4634
|
+
});
|
|
4635
|
+
return [
|
|
4636
|
+
4,
|
|
4637
|
+
fetch(request)
|
|
4638
|
+
];
|
|
4639
|
+
case 1:
|
|
4640
|
+
response = _state.sent();
|
|
4641
|
+
if (response.status !== 400) {
|
|
4642
|
+
console.error("POST /webhooks/system/ui-form without identifier returned ".concat(response.status, ", expected 400"));
|
|
4643
|
+
return [
|
|
4644
|
+
2,
|
|
4645
|
+
false
|
|
4646
|
+
];
|
|
4647
|
+
}
|
|
4648
|
+
return [
|
|
4649
|
+
4,
|
|
4650
|
+
response.json()
|
|
4651
|
+
];
|
|
4652
|
+
case 2:
|
|
4653
|
+
data = _state.sent();
|
|
4654
|
+
if (!data.error || typeof data.error !== 'string') {
|
|
4655
|
+
console.error("Expected error to be string, got ".concat(_type_of(data.error)));
|
|
4656
|
+
return [
|
|
4657
|
+
2,
|
|
4658
|
+
false
|
|
4659
|
+
];
|
|
4660
|
+
}
|
|
4661
|
+
if (!data.error.toLowerCase().includes('identifier')) {
|
|
4662
|
+
console.error("Expected error message to mention identifier, got: ".concat(data.error));
|
|
4663
|
+
return [
|
|
4664
|
+
2,
|
|
4665
|
+
false
|
|
4666
|
+
];
|
|
4667
|
+
}
|
|
4668
|
+
return [
|
|
4669
|
+
2,
|
|
4670
|
+
true
|
|
4671
|
+
];
|
|
4672
|
+
case 3:
|
|
4673
|
+
error = _state.sent();
|
|
4674
|
+
console.error('Failed to test POST /webhooks/system/ui-form without identifier:', error);
|
|
4675
|
+
return [
|
|
4676
|
+
2,
|
|
4677
|
+
false
|
|
4678
|
+
];
|
|
4679
|
+
case 4:
|
|
4680
|
+
return [
|
|
4681
|
+
2
|
|
4682
|
+
];
|
|
4683
|
+
}
|
|
4684
|
+
});
|
|
4685
|
+
})();
|
|
4433
4686
|
}
|
|
4434
4687
|
};
|
|
4435
4688
|
export var pages = {
|
|
@@ -5148,3 +5401,111 @@ export var pages = {
|
|
|
5148
5401
|
})();
|
|
5149
5402
|
}
|
|
5150
5403
|
};
|
|
5404
|
+
/**
|
|
5405
|
+
* Bundle API Tests
|
|
5406
|
+
*
|
|
5407
|
+
* Tests for the /bundle/components.js endpoint which serves the component bundle.
|
|
5408
|
+
*
|
|
5409
|
+
* NOTE: These tests only verify the API endpoint behavior. The bundle build and
|
|
5410
|
+
* upload process is backend-specific and must be tested separately by each
|
|
5411
|
+
* backend implementation.
|
|
5412
|
+
*/ export var bundle = {
|
|
5413
|
+
get: /**
|
|
5414
|
+
* Test GET /bundle/components.js - Serve the component bundle
|
|
5415
|
+
*/ function get(fetch) {
|
|
5416
|
+
return _async_to_generator(function() {
|
|
5417
|
+
var request, response, contentType, content, content1, error;
|
|
5418
|
+
return _ts_generator(this, function(_state) {
|
|
5419
|
+
switch(_state.label){
|
|
5420
|
+
case 0:
|
|
5421
|
+
_state.trys.push([
|
|
5422
|
+
0,
|
|
5423
|
+
6,
|
|
5424
|
+
,
|
|
5425
|
+
7
|
|
5426
|
+
]);
|
|
5427
|
+
request = new Request('http://example.com/bundle/components.js', {
|
|
5428
|
+
method: 'GET'
|
|
5429
|
+
});
|
|
5430
|
+
return [
|
|
5431
|
+
4,
|
|
5432
|
+
fetch(request)
|
|
5433
|
+
];
|
|
5434
|
+
case 1:
|
|
5435
|
+
response = _state.sent();
|
|
5436
|
+
// Bundle may or may not exist depending on project setup
|
|
5437
|
+
// 200 = bundle exists and served correctly
|
|
5438
|
+
// 404 = bundle not found (expected if no components/ directory)
|
|
5439
|
+
if (response.status !== 200 && response.status !== 404) {
|
|
5440
|
+
console.error("GET /bundle/components.js returned unexpected status ".concat(response.status));
|
|
5441
|
+
return [
|
|
5442
|
+
2,
|
|
5443
|
+
false
|
|
5444
|
+
];
|
|
5445
|
+
}
|
|
5446
|
+
contentType = response.headers.get('Content-Type');
|
|
5447
|
+
if (!contentType || !contentType.includes('application/javascript')) {
|
|
5448
|
+
console.error("Expected Content-Type application/javascript, got ".concat(contentType));
|
|
5449
|
+
return [
|
|
5450
|
+
2,
|
|
5451
|
+
false
|
|
5452
|
+
];
|
|
5453
|
+
}
|
|
5454
|
+
if (!(response.status === 200)) return [
|
|
5455
|
+
3,
|
|
5456
|
+
3
|
|
5457
|
+
];
|
|
5458
|
+
return [
|
|
5459
|
+
4,
|
|
5460
|
+
response.text()
|
|
5461
|
+
];
|
|
5462
|
+
case 2:
|
|
5463
|
+
content = _state.sent();
|
|
5464
|
+
if (!content || content.length === 0) {
|
|
5465
|
+
console.error('Bundle endpoint returned 200 but empty content');
|
|
5466
|
+
return [
|
|
5467
|
+
2,
|
|
5468
|
+
false
|
|
5469
|
+
];
|
|
5470
|
+
}
|
|
5471
|
+
_state.label = 3;
|
|
5472
|
+
case 3:
|
|
5473
|
+
if (!(response.status === 404)) return [
|
|
5474
|
+
3,
|
|
5475
|
+
5
|
|
5476
|
+
];
|
|
5477
|
+
return [
|
|
5478
|
+
4,
|
|
5479
|
+
response.text()
|
|
5480
|
+
];
|
|
5481
|
+
case 4:
|
|
5482
|
+
content1 = _state.sent();
|
|
5483
|
+
if (!content1.includes('Bundle not found')) {
|
|
5484
|
+
console.error('Bundle 404 response missing helpful error message');
|
|
5485
|
+
return [
|
|
5486
|
+
2,
|
|
5487
|
+
false
|
|
5488
|
+
];
|
|
5489
|
+
}
|
|
5490
|
+
_state.label = 5;
|
|
5491
|
+
case 5:
|
|
5492
|
+
return [
|
|
5493
|
+
2,
|
|
5494
|
+
true
|
|
5495
|
+
];
|
|
5496
|
+
case 6:
|
|
5497
|
+
error = _state.sent();
|
|
5498
|
+
console.error("Failed to test GET /bundle/components.js:", error);
|
|
5499
|
+
return [
|
|
5500
|
+
2,
|
|
5501
|
+
false
|
|
5502
|
+
];
|
|
5503
|
+
case 7:
|
|
5504
|
+
return [
|
|
5505
|
+
2
|
|
5506
|
+
];
|
|
5507
|
+
}
|
|
5508
|
+
});
|
|
5509
|
+
})();
|
|
5510
|
+
}
|
|
5511
|
+
};
|
package/dist/src/index.js
CHANGED
|
@@ -13,4 +13,4 @@
|
|
|
13
13
|
*
|
|
14
14
|
* This interface provides lifecycle management for a server instance,
|
|
15
15
|
* abstracting away the underlying implementation details (process, worker, etc.)
|
|
16
|
-
*/ export { testStatus, resources, brains, schedules, secrets, webhooks, pages } from './api.js';
|
|
16
|
+
*/ export { testStatus, resources, brains, schedules, secrets, webhooks, pages, bundle } from './api.js';
|