rhachet 1.1.0
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/LICENSE +21 -0
- package/dist/__nonpublished_modules__/file-fns/src/getFile.d.ts +6 -0
- package/dist/__nonpublished_modules__/file-fns/src/getFile.js +14 -0
- package/dist/__nonpublished_modules__/file-fns/src/getFile.js.map +1 -0
- package/dist/__test_assets__/directory.d.ts +1 -0
- package/dist/__test_assets__/directory.js +5 -0
- package/dist/__test_assets__/directory.js.map +1 -0
- package/dist/__test_assets__/genContextLogTrail.d.ts +2 -0
- package/dist/__test_assets__/genContextLogTrail.js +12 -0
- package/dist/__test_assets__/genContextLogTrail.js.map +1 -0
- package/dist/__test_assets__/genContextStitchTrail.d.ts +2 -0
- package/dist/__test_assets__/genContextStitchTrail.js +8 -0
- package/dist/__test_assets__/genContextStitchTrail.js.map +1 -0
- package/dist/__test_assets__/getContextOpenAI.d.ts +2 -0
- package/dist/__test_assets__/getContextOpenAI.js +18 -0
- package/dist/__test_assets__/getContextOpenAI.js.map +1 -0
- package/dist/__test_assets__/stitchers/genStitcherCodeFileRead.d.ts +14 -0
- package/dist/__test_assets__/stitchers/genStitcherCodeFileRead.js +23 -0
- package/dist/__test_assets__/stitchers/genStitcherCodeFileRead.js.map +1 -0
- package/dist/__test_assets__/stitchers/genStitcherCodeFileWrite.d.ts +16 -0
- package/dist/__test_assets__/stitchers/genStitcherCodeFileWrite.js +29 -0
- package/dist/__test_assets__/stitchers/genStitcherCodeFileWrite.js.map +1 -0
- package/dist/__test_assets__/stitchers/genStitcherCodeReviewImagine.d.ts +15 -0
- package/dist/__test_assets__/stitchers/genStitcherCodeReviewImagine.js +97 -0
- package/dist/__test_assets__/stitchers/genStitcherCodeReviewImagine.js.map +1 -0
- package/dist/__test_assets__/stitchers/stitcherCodeDiffImagine.d.ts +13 -0
- package/dist/__test_assets__/stitchers/stitcherCodeDiffImagine.js +33 -0
- package/dist/__test_assets__/stitchers/stitcherCodeDiffImagine.js.map +1 -0
- package/dist/__test_assets__/stitchers/stitcherFanoutRandomSum.d.ts +13 -0
- package/dist/__test_assets__/stitchers/stitcherFanoutRandomSum.js +45 -0
- package/dist/__test_assets__/stitchers/stitcherFanoutRandomSum.js.map +1 -0
- package/dist/__test_assets__/stitchers/stitcherFanoutSubroutes.d.ts +29 -0
- package/dist/__test_assets__/stitchers/stitcherFanoutSubroutes.js +76 -0
- package/dist/__test_assets__/stitchers/stitcherFanoutSubroutes.js.map +1 -0
- package/dist/__test_assets__/threads/codeArtist.d.ts +6 -0
- package/dist/__test_assets__/threads/codeArtist.js +26 -0
- package/dist/__test_assets__/threads/codeArtist.js.map +1 -0
- package/dist/__test_assets__/threads/codeCritic.d.ts +6 -0
- package/dist/__test_assets__/threads/codeCritic.js +21 -0
- package/dist/__test_assets__/threads/codeCritic.js.map +1 -0
- package/dist/__test_assets__/threads/director.d.ts +6 -0
- package/dist/__test_assets__/threads/director.js +14 -0
- package/dist/__test_assets__/threads/director.js.map +1 -0
- package/dist/contract/sdk.d.ts +8 -0
- package/dist/contract/sdk.js +33 -0
- package/dist/contract/sdk.js.map +1 -0
- package/dist/domain/objects/Stitch.d.ts +42 -0
- package/dist/domain/objects/Stitch.js +9 -0
- package/dist/domain/objects/Stitch.js.map +1 -0
- package/dist/domain/objects/StitchChoice.d.ts +30 -0
- package/dist/domain/objects/StitchChoice.js +8 -0
- package/dist/domain/objects/StitchChoice.js.map +1 -0
- package/dist/domain/objects/StitchCycle.d.ts +44 -0
- package/dist/domain/objects/StitchCycle.js +8 -0
- package/dist/domain/objects/StitchCycle.js.map +1 -0
- package/dist/domain/objects/StitchFanout.d.ts +35 -0
- package/dist/domain/objects/StitchFanout.js +8 -0
- package/dist/domain/objects/StitchFanout.js.map +1 -0
- package/dist/domain/objects/StitchRoute.d.ts +22 -0
- package/dist/domain/objects/StitchRoute.js +8 -0
- package/dist/domain/objects/StitchRoute.js.map +1 -0
- package/dist/domain/objects/StitchSetEvent.d.ts +23 -0
- package/dist/domain/objects/StitchSetEvent.js +8 -0
- package/dist/domain/objects/StitchSetEvent.js.map +1 -0
- package/dist/domain/objects/StitchStep.d.ts +55 -0
- package/dist/domain/objects/StitchStep.js +11 -0
- package/dist/domain/objects/StitchStep.js.map +1 -0
- package/dist/domain/objects/StitchTrail.d.ts +26 -0
- package/dist/domain/objects/StitchTrail.js +19 -0
- package/dist/domain/objects/StitchTrail.js.map +1 -0
- package/dist/domain/objects/Stitcher.d.ts +105 -0
- package/dist/domain/objects/Stitcher.js +49 -0
- package/dist/domain/objects/Stitcher.js.map +1 -0
- package/dist/domain/objects/Stitcher.test.d.ts +1 -0
- package/dist/domain/objects/Stitcher.test.js +78 -0
- package/dist/domain/objects/Stitcher.test.js.map +1 -0
- package/dist/domain/objects/Thread.d.ts +31 -0
- package/dist/domain/objects/Thread.js +11 -0
- package/dist/domain/objects/Thread.js.map +1 -0
- package/dist/domain/objects/Threads.d.ts +56 -0
- package/dist/domain/objects/Threads.js +26 -0
- package/dist/domain/objects/Threads.js.map +1 -0
- package/dist/domain/objects/Weave.d.ts +0 -0
- package/dist/domain/objects/Weave.js +2 -0
- package/dist/domain/objects/Weave.js.map +1 -0
- package/dist/domain/objects/Weaver.d.ts +5 -0
- package/dist/domain/objects/Weaver.js +7 -0
- package/dist/domain/objects/Weaver.js.map +1 -0
- package/dist/domain/objects/index.d.ts +11 -0
- package/dist/domain/objects/index.js +30 -0
- package/dist/domain/objects/index.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/logic/stitch/adapters/imagineViaOpenAI.d.ts +13 -0
- package/dist/logic/stitch/adapters/imagineViaOpenAI.js +36 -0
- package/dist/logic/stitch/adapters/imagineViaOpenAI.js.map +1 -0
- package/dist/logic/stitch/enstitch.d.ts +27 -0
- package/dist/logic/stitch/enstitch.js +97 -0
- package/dist/logic/stitch/enstitch.js.map +1 -0
- package/dist/logic/stitch/enstitch.test.d.ts +1 -0
- package/dist/logic/stitch/enstitch.test.js +87 -0
- package/dist/logic/stitch/enstitch.test.js.map +1 -0
- package/dist/logic/stitch/invokeImagineStitcher.d.ts +10 -0
- package/dist/logic/stitch/invokeImagineStitcher.integration.test.d.ts +1 -0
- package/dist/logic/stitch/invokeImagineStitcher.integration.test.js +193 -0
- package/dist/logic/stitch/invokeImagineStitcher.integration.test.js.map +1 -0
- package/dist/logic/stitch/invokeImagineStitcher.js +23 -0
- package/dist/logic/stitch/invokeImagineStitcher.js.map +1 -0
- package/dist/logic/stitch/withStitchTrail.d.ts +16 -0
- package/dist/logic/stitch/withStitchTrail.js +40 -0
- package/dist/logic/stitch/withStitchTrail.js.map +1 -0
- package/dist/logic/thread/enroleThread.d.ts +4 -0
- package/dist/logic/thread/enroleThread.js +6 -0
- package/dist/logic/thread/enroleThread.js.map +1 -0
- package/dist/logic/thread/genThread.d.ts +7 -0
- package/dist/logic/thread/genThread.js +10 -0
- package/dist/logic/thread/genThread.js.map +1 -0
- package/dist/logic/weave/compose/GStitcherInferredFromChoice.generic.d.ts +17 -0
- package/dist/logic/weave/compose/GStitcherInferredFromChoice.generic.js +3 -0
- package/dist/logic/weave/compose/GStitcherInferredFromChoice.generic.js.map +1 -0
- package/dist/logic/weave/compose/GStitcherInferredFromChoice.generic.test.d.ts +1 -0
- package/dist/logic/weave/compose/GStitcherInferredFromChoice.generic.test.js +67 -0
- package/dist/logic/weave/compose/GStitcherInferredFromChoice.generic.test.js.map +1 -0
- package/dist/logic/weave/compose/GStitcherInferredFromCycle.generic.d.ts +18 -0
- package/dist/logic/weave/compose/GStitcherInferredFromCycle.generic.js +3 -0
- package/dist/logic/weave/compose/GStitcherInferredFromCycle.generic.js.map +1 -0
- package/dist/logic/weave/compose/GStitcherInferredFromCycle.generic.test.d.ts +1 -0
- package/dist/logic/weave/compose/GStitcherInferredFromCycle.generic.test.js +132 -0
- package/dist/logic/weave/compose/GStitcherInferredFromCycle.generic.test.js.map +1 -0
- package/dist/logic/weave/compose/GStitcherInferredFromFanout.generic.d.ts +23 -0
- package/dist/logic/weave/compose/GStitcherInferredFromFanout.generic.js +3 -0
- package/dist/logic/weave/compose/GStitcherInferredFromFanout.generic.js.map +1 -0
- package/dist/logic/weave/compose/GStitcherInferredFromFanout.generic.test.d.ts +1 -0
- package/dist/logic/weave/compose/GStitcherInferredFromFanout.generic.test.js +74 -0
- package/dist/logic/weave/compose/GStitcherInferredFromFanout.generic.test.js.map +1 -0
- package/dist/logic/weave/compose/GStitcherInferredFromRoute.generic.d.ts +24 -0
- package/dist/logic/weave/compose/GStitcherInferredFromRoute.generic.js +3 -0
- package/dist/logic/weave/compose/GStitcherInferredFromRoute.generic.js.map +1 -0
- package/dist/logic/weave/compose/GStitcherInferredFromRoute.generic.test.d.ts +1 -0
- package/dist/logic/weave/compose/GStitcherInferredFromRoute.generic.test.js +190 -0
- package/dist/logic/weave/compose/GStitcherInferredFromRoute.generic.test.js.map +1 -0
- package/dist/logic/weave/compose/ProcedureContextMerged.generic.d.ts +36 -0
- package/dist/logic/weave/compose/ProcedureContextMerged.generic.js +3 -0
- package/dist/logic/weave/compose/ProcedureContextMerged.generic.js.map +1 -0
- package/dist/logic/weave/compose/ProcedureContextMerged.generic.test.d.ts +1 -0
- package/dist/logic/weave/compose/ProcedureContextMerged.generic.test.js +29 -0
- package/dist/logic/weave/compose/ProcedureContextMerged.generic.test.js.map +1 -0
- package/dist/logic/weave/compose/ThreadsMerged.generic.d.ts +65 -0
- package/dist/logic/weave/compose/ThreadsMerged.generic.js +3 -0
- package/dist/logic/weave/compose/ThreadsMerged.generic.js.map +1 -0
- package/dist/logic/weave/compose/ThreadsMerged.generic.test.d.ts +1 -0
- package/dist/logic/weave/compose/ThreadsMerged.generic.test.js +420 -0
- package/dist/logic/weave/compose/ThreadsMerged.generic.test.js.map +1 -0
- package/dist/logic/weave/compose/asStitcher.d.ts +12 -0
- package/dist/logic/weave/compose/asStitcher.js +15 -0
- package/dist/logic/weave/compose/asStitcher.js.map +1 -0
- package/dist/logic/weave/compose/asStitcher.test.d.ts +1 -0
- package/dist/logic/weave/compose/asStitcher.test.js +95 -0
- package/dist/logic/weave/compose/asStitcher.test.js.map +1 -0
- package/dist/logic/weave/compose/asStitcherFlat.d.ts +10 -0
- package/dist/logic/weave/compose/asStitcherFlat.js +13 -0
- package/dist/logic/weave/compose/asStitcherFlat.js.map +1 -0
- package/dist/logic/weave/compose/asStitcherFlat.test.d.ts +1 -0
- package/dist/logic/weave/compose/asStitcherFlat.test.js +96 -0
- package/dist/logic/weave/compose/asStitcherFlat.test.js.map +1 -0
- package/dist/logic/weave/compose/genStitchChoice.d.ts +22 -0
- package/dist/logic/weave/compose/genStitchChoice.js +23 -0
- package/dist/logic/weave/compose/genStitchChoice.js.map +1 -0
- package/dist/logic/weave/compose/genStitchChoice.test.d.ts +1 -0
- package/dist/logic/weave/compose/genStitchChoice.test.js +200 -0
- package/dist/logic/weave/compose/genStitchChoice.test.js.map +1 -0
- package/dist/logic/weave/compose/genStitchCycle.d.ts +28 -0
- package/dist/logic/weave/compose/genStitchCycle.js +30 -0
- package/dist/logic/weave/compose/genStitchCycle.js.map +1 -0
- package/dist/logic/weave/compose/genStitchCycle.test.d.ts +1 -0
- package/dist/logic/weave/compose/genStitchCycle.test.js +152 -0
- package/dist/logic/weave/compose/genStitchCycle.test.js.map +1 -0
- package/dist/logic/weave/compose/genStitchFanout.d.ts +17 -0
- package/dist/logic/weave/compose/genStitchFanout.js +21 -0
- package/dist/logic/weave/compose/genStitchFanout.js.map +1 -0
- package/dist/logic/weave/compose/genStitchFanout.test.d.ts +1 -0
- package/dist/logic/weave/compose/genStitchFanout.test.js +79 -0
- package/dist/logic/weave/compose/genStitchFanout.test.js.map +1 -0
- package/dist/logic/weave/compose/genStitchRoute.d.ts +15 -0
- package/dist/logic/weave/compose/genStitchRoute.js +20 -0
- package/dist/logic/weave/compose/genStitchRoute.js.map +1 -0
- package/dist/logic/weave/compose/genStitchRoute.test.d.ts +1 -0
- package/dist/logic/weave/compose/genStitchRoute.test.js +120 -0
- package/dist/logic/weave/compose/genStitchRoute.test.js.map +1 -0
- package/dist/logic/weave/enweave.d.ts +0 -0
- package/dist/logic/weave/enweave.js +2 -0
- package/dist/logic/weave/enweave.js.map +1 -0
- package/dist/logic/weave/enweaveAllStitchers.d.ts +0 -0
- package/dist/logic/weave/enweaveAllStitchers.js +2 -0
- package/dist/logic/weave/enweaveAllStitchers.js.map +1 -0
- package/dist/logic/weave/enweaveOneChoice.d.ts +14 -0
- package/dist/logic/weave/enweaveOneChoice.js +48 -0
- package/dist/logic/weave/enweaveOneChoice.js.map +1 -0
- package/dist/logic/weave/enweaveOneChoice.test.d.ts +1 -0
- package/dist/logic/weave/enweaveOneChoice.test.js +181 -0
- package/dist/logic/weave/enweaveOneChoice.test.js.map +1 -0
- package/dist/logic/weave/enweaveOneCycle.d.ts +19 -0
- package/dist/logic/weave/enweaveOneCycle.js +98 -0
- package/dist/logic/weave/enweaveOneCycle.js.map +1 -0
- package/dist/logic/weave/enweaveOneCycle.test.d.ts +1 -0
- package/dist/logic/weave/enweaveOneCycle.test.js +180 -0
- package/dist/logic/weave/enweaveOneCycle.test.js.map +1 -0
- package/dist/logic/weave/enweaveOneFanout.d.ts +12 -0
- package/dist/logic/weave/enweaveOneFanout.integration.test.d.ts +1 -0
- package/dist/logic/weave/enweaveOneFanout.integration.test.js +166 -0
- package/dist/logic/weave/enweaveOneFanout.integration.test.js.map +1 -0
- package/dist/logic/weave/enweaveOneFanout.js +37 -0
- package/dist/logic/weave/enweaveOneFanout.js.map +1 -0
- package/dist/logic/weave/enweaveOneRoute.d.ts +12 -0
- package/dist/logic/weave/enweaveOneRoute.integration.test.d.ts +1 -0
- package/dist/logic/weave/enweaveOneRoute.integration.test.js +159 -0
- package/dist/logic/weave/enweaveOneRoute.integration.test.js.map +1 -0
- package/dist/logic/weave/enweaveOneRoute.js +33 -0
- package/dist/logic/weave/enweaveOneRoute.js.map +1 -0
- package/dist/logic/weave/enweaveOneStitcher.d.ts +11 -0
- package/dist/logic/weave/enweaveOneStitcher.integration.test.d.ts +2 -0
- package/dist/logic/weave/enweaveOneStitcher.integration.test.js +258 -0
- package/dist/logic/weave/enweaveOneStitcher.integration.test.js.map +1 -0
- package/dist/logic/weave/enweaveOneStitcher.js +42 -0
- package/dist/logic/weave/enweaveOneStitcher.js.map +1 -0
- package/package.json +88 -0
- package/readme.md +61 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.enweaveOneCycle = exports.StitcherHaltedError = void 0;
|
|
4
|
+
const uni_time_1 = require("@ehmpathy/uni-time");
|
|
5
|
+
const helpful_errors_1 = require("helpful-errors");
|
|
6
|
+
const StitchSetEvent_1 = require("../../domain/objects/StitchSetEvent");
|
|
7
|
+
const withStitchTrail_1 = require("../stitch/withStitchTrail");
|
|
8
|
+
const enweaveOneStitcher_1 = require("./enweaveOneStitcher");
|
|
9
|
+
class StitcherHaltedError extends helpful_errors_1.HelpfulError {
|
|
10
|
+
}
|
|
11
|
+
exports.StitcherHaltedError = StitcherHaltedError;
|
|
12
|
+
/**
|
|
13
|
+
* .what = executes a StitchCycle by looping repeatee until the decider chooses to stop
|
|
14
|
+
* .why =
|
|
15
|
+
* - enables iterative behaviors (e.g. retry, polling, feedback loops)
|
|
16
|
+
* - separates logic of repeated step vs control logic (decider)
|
|
17
|
+
* .note =
|
|
18
|
+
* - will halt by default after 100 cycles or 1 hr, configurable
|
|
19
|
+
* - if halted, will fail fast; can resume halted weaves on demand, after repair
|
|
20
|
+
*/
|
|
21
|
+
exports.enweaveOneCycle = (0, withStitchTrail_1.withStitchTrail)(async (input, context) => {
|
|
22
|
+
const { repeatee, decider, halter } = input.stitcher;
|
|
23
|
+
// declare the state we'll mutate while the stitch is in progress
|
|
24
|
+
const progress = {
|
|
25
|
+
beganAt: (0, uni_time_1.asUniDateTime)(new Date()),
|
|
26
|
+
repetitions: 0,
|
|
27
|
+
stitch: null,
|
|
28
|
+
threads: input.threads,
|
|
29
|
+
};
|
|
30
|
+
// declare mech to fulfil halter behavior
|
|
31
|
+
const threshold = {
|
|
32
|
+
repetitions: halter?.threshold?.repetitions ?? 100,
|
|
33
|
+
duration: halter?.threshold?.duration ?? { hours: 1 },
|
|
34
|
+
};
|
|
35
|
+
const hasBreached = () => {
|
|
36
|
+
if (progress.repetitions >= threshold.repetitions)
|
|
37
|
+
return true;
|
|
38
|
+
const now = (0, uni_time_1.asUniDateTime)(new Date());
|
|
39
|
+
const deadline = (0, uni_time_1.addDuration)(progress.beganAt, threshold.duration);
|
|
40
|
+
return now > deadline;
|
|
41
|
+
};
|
|
42
|
+
const throwHalted = ({ reason }) => StitcherHaltedError.throw(`Cycle halted due to ${reason === 'DECIDED' ? 'decider output.' : 'threshold breach'} (${reason}). See the log event stream output for details.`, {
|
|
43
|
+
reason,
|
|
44
|
+
threshold,
|
|
45
|
+
progress: {
|
|
46
|
+
...progress,
|
|
47
|
+
duration: (0, uni_time_1.getDuration)({
|
|
48
|
+
of: {
|
|
49
|
+
range: uni_time_1.isUniDateTimeRange.assure({
|
|
50
|
+
since: progress.beganAt,
|
|
51
|
+
until: (0, uni_time_1.asUniDateTime)(new Date()),
|
|
52
|
+
}),
|
|
53
|
+
},
|
|
54
|
+
}),
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
// loop until the decider chooses to stop
|
|
58
|
+
while (true) {
|
|
59
|
+
// fail fast if the halter's threshold was breached
|
|
60
|
+
if (hasBreached())
|
|
61
|
+
throwHalted({ reason: 'BREACHED' });
|
|
62
|
+
// run the repeatee step
|
|
63
|
+
const { stitch: repeateeStitch, threads: afterRepeatee } = await (0, enweaveOneStitcher_1.enweaveOneStitcher)({ stitcher: repeatee, threads: progress.threads }, context);
|
|
64
|
+
// update progress state
|
|
65
|
+
progress.stitch = repeateeStitch;
|
|
66
|
+
progress.threads = afterRepeatee;
|
|
67
|
+
progress.repetitions++;
|
|
68
|
+
// run the decider to determine whether to continue
|
|
69
|
+
const { stitch: deciderStitch, threads: afterDecider } = await (0, enweaveOneStitcher_1.enweaveOneStitcher)({ stitcher: decider, threads: progress.threads }, context);
|
|
70
|
+
const choice = deciderStitch.output?.choice;
|
|
71
|
+
if (!choice) {
|
|
72
|
+
helpful_errors_1.UnexpectedCodePathError.throw('no choice returned from cycle decider', {
|
|
73
|
+
deciderStitch,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
// update threads with decider result
|
|
77
|
+
progress.threads = afterDecider;
|
|
78
|
+
// determine next action
|
|
79
|
+
if (choice === 'halt')
|
|
80
|
+
throwHalted({ reason: 'DECIDED' });
|
|
81
|
+
if (choice === 'repeat')
|
|
82
|
+
continue;
|
|
83
|
+
if (choice === 'release')
|
|
84
|
+
break;
|
|
85
|
+
helpful_errors_1.UnexpectedCodePathError.throw('unexpected choice from decider', {
|
|
86
|
+
choice,
|
|
87
|
+
deciderStitch,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
// declare the final result as a StitchSetEvent
|
|
91
|
+
return StitchSetEvent_1.StitchSetEvent.build({
|
|
92
|
+
occurredAt: (0, uni_time_1.asUniDateTime)(new Date()),
|
|
93
|
+
stitch: progress.stitch ??
|
|
94
|
+
helpful_errors_1.UnexpectedCodePathError.throw('atleast one output stitch expected by now'),
|
|
95
|
+
threads: progress.threads,
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
//# sourceMappingURL=enweaveOneCycle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enweaveOneCycle.js","sourceRoot":"","sources":["../../../src/logic/weave/enweaveOneCycle.ts"],"names":[],"mappings":";;;AAAA,iDAM4B;AAC5B,mDAAuE;AAGvE,wEAAqE;AAErE,+DAA4D;AAC5D,6DAA0D;AAE1D,MAAa,mBAAoB,SAAQ,6BAAY;CAAG;AAAxD,kDAAwD;AAExD;;;;;;;;GAQG;AACU,Q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AAI,MAAM,KAAK,QAAQ;YAAE,SAAS;QAClC,IAAI,MAAM,KAAK,SAAS;YAAE,MAAM;QAChC,wCAAuB,CAAC,KAAK,CAAC,gCAAgC,EAAE;YAC9D,MAAM;YACN,aAAa;SACd,CAAC,CAAC;IACL,CAAC;IAED,+CAA+C;IAC/C,OAAO,+BAAc,CAAC,KAAK,CAAC;QAC1B,UAAU,EAAE,IAAA,wBAAa,EAAC,IAAI,IAAI,EAAE,CAAC;QACrC,MAAM,EACJ,QAAQ,CAAC,MAAM;YACf,wCAAuB,CAAC,KAAK,CAC3B,2CAA2C,CAC5C;QACH,OAAO,EAAE,QAAQ,CAAC,OAAO;KAC1B,CAAC,CAAC;AACL,CAAC,CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const uni_time_1 = require("@ehmpathy/uni-time");
|
|
4
|
+
const test_fns_1 = require("test-fns");
|
|
5
|
+
const genContextLogTrail_1 = require("../../__test_assets__/genContextLogTrail");
|
|
6
|
+
const genContextStitchTrail_1 = require("../../__test_assets__/genContextStitchTrail");
|
|
7
|
+
const StitchStep_1 = require("../../domain/objects/StitchStep");
|
|
8
|
+
const genThread_1 = require("../thread/genThread");
|
|
9
|
+
const genStitchCycle_1 = require("./compose/genStitchCycle");
|
|
10
|
+
const enweaveOneCycle_1 = require("./enweaveOneCycle");
|
|
11
|
+
describe('enweaveOneCycle', () => {
|
|
12
|
+
const context = {
|
|
13
|
+
...(0, genContextLogTrail_1.genContextLogTrail)(),
|
|
14
|
+
...(0, genContextStitchTrail_1.genContextStitchTrail)(),
|
|
15
|
+
};
|
|
16
|
+
(0, test_fns_1.given)('a simple repeatee that gets released', () => {
|
|
17
|
+
const repeatee = new StitchStep_1.StitchStepCompute({
|
|
18
|
+
slug: 'repeatee',
|
|
19
|
+
readme: 'Repeat logic',
|
|
20
|
+
form: 'COMPUTE',
|
|
21
|
+
stitchee: 'main',
|
|
22
|
+
invoke: () => ({ input: null, output: 'A' }),
|
|
23
|
+
});
|
|
24
|
+
const decider = new StitchStep_1.StitchStepCompute({
|
|
25
|
+
slug: 'decider',
|
|
26
|
+
readme: 'Choose to stop after one',
|
|
27
|
+
form: 'COMPUTE',
|
|
28
|
+
stitchee: 'main',
|
|
29
|
+
invoke: () => ({ input: null, output: { choice: 'release' } }),
|
|
30
|
+
});
|
|
31
|
+
const stitcher = (0, genStitchCycle_1.genStitchCycle)({
|
|
32
|
+
slug: 'release-after-one',
|
|
33
|
+
readme: null,
|
|
34
|
+
repeatee,
|
|
35
|
+
decider,
|
|
36
|
+
});
|
|
37
|
+
(0, test_fns_1.when)('run once and released', () => {
|
|
38
|
+
const threads = {
|
|
39
|
+
main: (0, genThread_1.genThread)({ role: 'main' }),
|
|
40
|
+
};
|
|
41
|
+
(0, test_fns_1.then)('it should return after one cycle with A', async () => {
|
|
42
|
+
const result = await (0, enweaveOneCycle_1.enweaveOneCycle)({ stitcher, threads }, context);
|
|
43
|
+
expect(result.stitch.output).toBe('A');
|
|
44
|
+
expect(result.threads.main.stitches.length).toBe(2);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
(0, test_fns_1.given)('a cycle that repeats twice then releases', () => {
|
|
49
|
+
let callCount = 0;
|
|
50
|
+
const repeatee = new StitchStep_1.StitchStepCompute({
|
|
51
|
+
slug: 'repeatee-twice',
|
|
52
|
+
readme: null,
|
|
53
|
+
form: 'COMPUTE',
|
|
54
|
+
stitchee: 'main',
|
|
55
|
+
invoke: () => ({ input: null, output: `call-${++callCount}` }),
|
|
56
|
+
});
|
|
57
|
+
const decider = new StitchStep_1.StitchStepCompute({
|
|
58
|
+
slug: 'decider-twice',
|
|
59
|
+
readme: null,
|
|
60
|
+
form: 'COMPUTE',
|
|
61
|
+
stitchee: 'main',
|
|
62
|
+
invoke: () => ({
|
|
63
|
+
input: null,
|
|
64
|
+
output: { choice: callCount === 2 ? 'release' : 'repeat' },
|
|
65
|
+
}),
|
|
66
|
+
});
|
|
67
|
+
const stitcher = (0, genStitchCycle_1.genStitchCycle)({
|
|
68
|
+
slug: 'repeat-twice-then-release',
|
|
69
|
+
readme: null,
|
|
70
|
+
repeatee,
|
|
71
|
+
decider,
|
|
72
|
+
});
|
|
73
|
+
(0, test_fns_1.when)('run until released', () => {
|
|
74
|
+
const threads = {
|
|
75
|
+
main: (0, genThread_1.genThread)({ role: 'main' }),
|
|
76
|
+
};
|
|
77
|
+
(0, test_fns_1.then)('it should run repeatee twice and return second output', async () => {
|
|
78
|
+
const result = await (0, enweaveOneCycle_1.enweaveOneCycle)({ stitcher, threads }, context);
|
|
79
|
+
expect(result.stitch.output).toBe('call-2');
|
|
80
|
+
expect(result.threads.main.stitches.length).toBe(4); // 2 repeatee + 2 decider
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
(0, test_fns_1.given)('a halting decider', () => {
|
|
85
|
+
const repeatee = new StitchStep_1.StitchStepCompute({
|
|
86
|
+
slug: 'rep',
|
|
87
|
+
readme: null,
|
|
88
|
+
form: 'COMPUTE',
|
|
89
|
+
stitchee: 'main',
|
|
90
|
+
invoke: () => ({ input: null, output: 'A' }),
|
|
91
|
+
});
|
|
92
|
+
const decider = new StitchStep_1.StitchStepCompute({
|
|
93
|
+
slug: 'halt-me',
|
|
94
|
+
readme: null,
|
|
95
|
+
form: 'COMPUTE',
|
|
96
|
+
stitchee: 'main',
|
|
97
|
+
invoke: () => ({ input: null, output: { choice: 'halt' } }),
|
|
98
|
+
});
|
|
99
|
+
const stitcher = (0, genStitchCycle_1.genStitchCycle)({
|
|
100
|
+
slug: 'halt-once',
|
|
101
|
+
readme: null,
|
|
102
|
+
repeatee,
|
|
103
|
+
decider,
|
|
104
|
+
});
|
|
105
|
+
(0, test_fns_1.when)('run and told to halt', () => {
|
|
106
|
+
const threads = {
|
|
107
|
+
main: (0, genThread_1.genThread)({ role: 'main' }),
|
|
108
|
+
};
|
|
109
|
+
(0, test_fns_1.then)('it should throw a StitcherHaltedError(reason=DECIDED)', async () => {
|
|
110
|
+
await expect((0, enweaveOneCycle_1.enweaveOneCycle)({ stitcher, threads }, context)).rejects.toThrowError(/DECIDED/);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
(0, test_fns_1.given)('a repeatee that never releases, with halter on repetitions', () => {
|
|
115
|
+
const stitcherRepeatee = new StitchStep_1.StitchStepCompute({
|
|
116
|
+
slug: 'infinite-step',
|
|
117
|
+
readme: 'Always increment',
|
|
118
|
+
form: 'COMPUTE',
|
|
119
|
+
stitchee: 'main',
|
|
120
|
+
invoke: () => ({ input: null, output: 'tick' }),
|
|
121
|
+
});
|
|
122
|
+
const stitcherDecider = new StitchStep_1.StitchStepCompute({
|
|
123
|
+
slug: 'always-repeat',
|
|
124
|
+
readme: null,
|
|
125
|
+
form: 'COMPUTE',
|
|
126
|
+
stitchee: 'main',
|
|
127
|
+
invoke: () => ({ input: null, output: { choice: 'repeat' } }),
|
|
128
|
+
});
|
|
129
|
+
const stitcherCycle = (0, genStitchCycle_1.genStitchCycle)({
|
|
130
|
+
slug: 'cycle-infinite-haltered',
|
|
131
|
+
readme: null,
|
|
132
|
+
repeatee: stitcherRepeatee,
|
|
133
|
+
decider: stitcherDecider,
|
|
134
|
+
halter: { threshold: { repetitions: 5 } },
|
|
135
|
+
});
|
|
136
|
+
(0, test_fns_1.when)('executed', () => {
|
|
137
|
+
const threads = {
|
|
138
|
+
main: (0, genThread_1.genThread)({ role: 'main' }),
|
|
139
|
+
};
|
|
140
|
+
(0, test_fns_1.then)('it should halt after 5 repetitions', async () => {
|
|
141
|
+
await expect((0, enweaveOneCycle_1.enweaveOneCycle)({ stitcher: stitcherCycle, threads }, context)).rejects.toThrow(enweaveOneCycle_1.StitcherHaltedError);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
(0, test_fns_1.given)('a repeatee that exceeds time halter', () => {
|
|
146
|
+
const stitcherRepeatee = new StitchStep_1.StitchStepCompute({
|
|
147
|
+
slug: 'sleepy-step',
|
|
148
|
+
readme: 'Sleeps each run',
|
|
149
|
+
form: 'COMPUTE',
|
|
150
|
+
stitchee: 'main',
|
|
151
|
+
invoke: async () => {
|
|
152
|
+
await (0, uni_time_1.sleep)({ seconds: 2 });
|
|
153
|
+
return { input: null, output: 'zzz' };
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
const stitcherDecider = new StitchStep_1.StitchStepCompute({
|
|
157
|
+
slug: 'always-repeat-sleepy',
|
|
158
|
+
readme: null,
|
|
159
|
+
form: 'COMPUTE',
|
|
160
|
+
stitchee: 'main',
|
|
161
|
+
invoke: () => ({ input: null, output: { choice: 'repeat' } }),
|
|
162
|
+
});
|
|
163
|
+
const stitcherCycle = (0, genStitchCycle_1.genStitchCycle)({
|
|
164
|
+
slug: 'cycle-timeout-halter',
|
|
165
|
+
readme: null,
|
|
166
|
+
repeatee: stitcherRepeatee,
|
|
167
|
+
decider: stitcherDecider,
|
|
168
|
+
halter: { threshold: { duration: { seconds: 3 } } },
|
|
169
|
+
});
|
|
170
|
+
(0, test_fns_1.when)('executed', () => {
|
|
171
|
+
const threads = {
|
|
172
|
+
main: (0, genThread_1.genThread)({ role: 'main' }),
|
|
173
|
+
};
|
|
174
|
+
(0, test_fns_1.then)('it should halt due to time threshold', async () => {
|
|
175
|
+
await expect((0, enweaveOneCycle_1.enweaveOneCycle)({ stitcher: stitcherCycle, threads }, context)).rejects.toThrow(enweaveOneCycle_1.StitcherHaltedError);
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
//# sourceMappingURL=enweaveOneCycle.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enweaveOneCycle.test.js","sourceRoot":"","sources":["../../../src/logic/weave/enweaveO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EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,CAAC;SAC9D,CAAC,CAAC;QAEH,MAAM,aAAa,GAAG,IAAA,+BAAc,EAAC;YACnC,IAAI,EAAE,sBAAsB;YAC5B,MAAM,EAAE,IAAI;YACZ,QAAQ,EAAE,gBAAgB;YAC1B,OAAO,EAAE,eAAe;YACxB,MAAM,EAAE,EAAE,SAAS,EAAE,EAAE,QAAQ,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE,EAAE;SACpD,CAAC,CAAC;QAEH,IAAA,eAAI,EAAC,UAAU,EAAE,GAAG,EAAE;YACpB,MAAM,OAAO,GAA6B;gBACxC,IAAI,EAAE,IAAA,qBAAS,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;aAClC,CAAC;YAEF,IAAA,eAAI,EAAC,sCAAsC,EAAE,KAAK,IAAI,EAAE;gBACtD,MAAM,MAAM,CACV,IAAA,iCAAe,EAAC,EAAE,QAAQ,EAAE,aAAa,EAAE,OAAO,EAAE,EAAE,OAAO,CAAC,CAC/D,CAAC,OAAO,CAAC,OAAO,CAAC,qCAAmB,CAAC,CAAC;YACzC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { StitchFanout } from '../../domain/objects/StitchFanout';
|
|
2
|
+
import { StitchSetEvent } from '../../domain/objects/StitchSetEvent';
|
|
3
|
+
import { GStitcher } from '../../domain/objects/Stitcher';
|
|
4
|
+
/**
|
|
5
|
+
* .what = mechanism to enweave a full stitch fanout
|
|
6
|
+
* .how =
|
|
7
|
+
* - executes a Promise.all(.parallels) and a .conclusion stitcher
|
|
8
|
+
*/
|
|
9
|
+
export declare const enweaveOneFanout: <TStitcher extends GStitcher>(input: {
|
|
10
|
+
stitcher: StitchFanout<TStitcher>;
|
|
11
|
+
threads: TStitcher['threads'];
|
|
12
|
+
}, context: TStitcher['context']) => Promise<StitchSetEvent<TStitcher['threads'], TStitcher['output']>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const helpful_errors_1 = require("helpful-errors");
|
|
4
|
+
const test_fns_1 = require("test-fns");
|
|
5
|
+
const genContextLogTrail_1 = require("../../__test_assets__/genContextLogTrail");
|
|
6
|
+
const genContextStitchTrail_1 = require("../../__test_assets__/genContextStitchTrail");
|
|
7
|
+
const getContextOpenAI_1 = require("../../__test_assets__/getContextOpenAI");
|
|
8
|
+
const genStitcherCodeReviewImagine_1 = require("../../__test_assets__/stitchers/genStitcherCodeReviewImagine");
|
|
9
|
+
const stitcherFanoutRandomSum_1 = require("../../__test_assets__/stitchers/stitcherFanoutRandomSum");
|
|
10
|
+
const stitcherFanoutSubroutes_1 = require("../../__test_assets__/stitchers/stitcherFanoutSubroutes");
|
|
11
|
+
const StitchStep_1 = require("../../domain/objects/StitchStep");
|
|
12
|
+
const Thread_1 = require("../../domain/objects/Thread");
|
|
13
|
+
const genThread_1 = require("../thread/genThread");
|
|
14
|
+
const genStitchFanout_1 = require("./compose/genStitchFanout");
|
|
15
|
+
const enweaveOneFanout_1 = require("./enweaveOneFanout");
|
|
16
|
+
describe('enweaveOneFanout', () => {
|
|
17
|
+
const context = { ...(0, genContextStitchTrail_1.genContextStitchTrail)(), ...(0, genContextLogTrail_1.genContextLogTrail)() };
|
|
18
|
+
(0, test_fns_1.given)('a fanout that computes 5 random numbers then sums them', () => {
|
|
19
|
+
const threadMain = new Thread_1.Thread({
|
|
20
|
+
context: { role: 'main' },
|
|
21
|
+
stitches: [],
|
|
22
|
+
});
|
|
23
|
+
(0, test_fns_1.when)('invoked with the correct thread', () => {
|
|
24
|
+
(0, test_fns_1.then)('it should return a number stitch equal to the sum of the random outputs', async () => {
|
|
25
|
+
const { stitch, threads } = await (0, enweaveOneFanout_1.enweaveOneFanout)({
|
|
26
|
+
stitcher: stitcherFanoutRandomSum_1.stitcherFanoutRandomSum,
|
|
27
|
+
threads: { main: threadMain },
|
|
28
|
+
}, context);
|
|
29
|
+
console.log({ stitch, threads });
|
|
30
|
+
// validate output is a number
|
|
31
|
+
expect(typeof stitch.output).toBe('number');
|
|
32
|
+
// validate input to the concluder is a number[]
|
|
33
|
+
expect(Array.isArray(stitch.input)).toBe(true);
|
|
34
|
+
expect(stitch.input.every((n) => typeof n === 'number')).toBe(true);
|
|
35
|
+
// validate stitch.output === sum(stitch.input)
|
|
36
|
+
const expectedSum = stitch.input.reduce((a, b) => a + b, 0);
|
|
37
|
+
expect(stitch.output).toBe(expectedSum);
|
|
38
|
+
// validate thread output is form: 'single'
|
|
39
|
+
expect(threads.main.stitches.at(-1)?.output).toBe(expectedSum);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
(0, test_fns_1.when)('invoked with an incorrect thread role', () => {
|
|
43
|
+
const threadWrong = new Thread_1.Thread({
|
|
44
|
+
context: { role: 'wrong' },
|
|
45
|
+
stitches: [],
|
|
46
|
+
});
|
|
47
|
+
(0, test_fns_1.then)('it should throw at compile time due to wrong role', async () => {
|
|
48
|
+
await (0, helpful_errors_1.getError)((0, enweaveOneFanout_1.enweaveOneFanout)({
|
|
49
|
+
stitcher: stitcherFanoutRandomSum_1.stitcherFanoutRandomSum,
|
|
50
|
+
// @ts-expect-error: wrong thread role
|
|
51
|
+
threads: { wrong: threadWrong },
|
|
52
|
+
}, context));
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
(0, test_fns_1.given)('a fanout with one route of 2 steps and another of 3 steps', () => {
|
|
57
|
+
const threadMain = new Thread_1.Thread({
|
|
58
|
+
context: { role: 'main' },
|
|
59
|
+
stitches: [],
|
|
60
|
+
});
|
|
61
|
+
(0, test_fns_1.then)('it should output a stitch where input = [3, 6] and output = 9', async () => {
|
|
62
|
+
const { stitch, threads } = await (0, enweaveOneFanout_1.enweaveOneFanout)({
|
|
63
|
+
stitcher: stitcherFanoutSubroutes_1.stitcherFanoutWithRoutes,
|
|
64
|
+
threads: { main: threadMain },
|
|
65
|
+
}, context);
|
|
66
|
+
expect(Array.isArray(stitch.input)).toBe(true);
|
|
67
|
+
expect(stitch.input).toEqual([3, 6]);
|
|
68
|
+
expect(stitch.output).toBe(9);
|
|
69
|
+
expect(threads.main.stitches.at(-1)?.output).toBe(9);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
test_fns_1.given.only('a route with imagine stitchers, parallelized (closer to real world usecase)', () => {
|
|
73
|
+
const stitchCodeRead = {
|
|
74
|
+
input: null,
|
|
75
|
+
output: {
|
|
76
|
+
path: '__path__',
|
|
77
|
+
content: `
|
|
78
|
+
import { UnexpectedCodePathError } from '@ehmpathy/error-fns';
|
|
79
|
+
import { UniDateTime } from '@ehmpathy/uni-time';
|
|
80
|
+
import { PickOne } from 'type-fns';
|
|
81
|
+
|
|
82
|
+
import { daoJobProspect } from '../../data/dao/jobProspectDao';
|
|
83
|
+
import { withDatabaseContext } from '../../utils/database/withDatabaseContext';
|
|
84
|
+
|
|
85
|
+
export const getProspects = withDatabaseContext(
|
|
86
|
+
async (
|
|
87
|
+
input: PickOne<{
|
|
88
|
+
byProvider: { providerUuid: string };
|
|
89
|
+
}> & {
|
|
90
|
+
page: {
|
|
91
|
+
since?: { openedAt: UniDateTime };
|
|
92
|
+
until?: { openedAt: UniDateTime };
|
|
93
|
+
limit: number;
|
|
94
|
+
};
|
|
95
|
+
},
|
|
96
|
+
context,
|
|
97
|
+
) => {
|
|
98
|
+
if (input.byProvider)
|
|
99
|
+
return daoJobProspect.findAllByProvider(
|
|
100
|
+
{
|
|
101
|
+
by: {
|
|
102
|
+
providerUuid: input.byProvider.providerUuid,
|
|
103
|
+
},
|
|
104
|
+
filter: {
|
|
105
|
+
sinceOpenedAt: input.page.since?.openedAt,
|
|
106
|
+
untilOpenedAt: input.page.until?.openedAt,
|
|
107
|
+
},
|
|
108
|
+
limit: input.page.limit,
|
|
109
|
+
},
|
|
110
|
+
context,
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
throw new UnexpectedCodePathError('unsupported input option');
|
|
114
|
+
},
|
|
115
|
+
`.trim(),
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
const stitcherCodeReviewConcluder = new StitchStep_1.StitchStepCompute({
|
|
119
|
+
slug: 'sum',
|
|
120
|
+
readme: null,
|
|
121
|
+
form: 'COMPUTE',
|
|
122
|
+
stitchee: 'critic',
|
|
123
|
+
invoke: ({ threads }) => {
|
|
124
|
+
const feedbacks = threads.critic.peers.map((peer) => peer.stitches.slice(-1)[0]?.output);
|
|
125
|
+
return {
|
|
126
|
+
input: feedbacks,
|
|
127
|
+
output: feedbacks,
|
|
128
|
+
};
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
const fanout = (0, genStitchFanout_1.genStitchFanout)({
|
|
132
|
+
slug: '[critic]<code:review>.<fanout>[[review]]',
|
|
133
|
+
readme: null,
|
|
134
|
+
parallels: [
|
|
135
|
+
(0, genStitcherCodeReviewImagine_1.genStitcherCodeReview)({ scope: 'technical', focus: 'blockers' }),
|
|
136
|
+
(0, genStitcherCodeReviewImagine_1.genStitcherCodeReview)({ scope: 'technical', focus: 'chances' }),
|
|
137
|
+
(0, genStitcherCodeReviewImagine_1.genStitcherCodeReview)({ scope: 'technical', focus: 'praises' }),
|
|
138
|
+
(0, genStitcherCodeReviewImagine_1.genStitcherCodeReview)({ scope: 'functional', focus: 'blockers' }),
|
|
139
|
+
(0, genStitcherCodeReviewImagine_1.genStitcherCodeReview)({ scope: 'functional', focus: 'chances' }),
|
|
140
|
+
(0, genStitcherCodeReviewImagine_1.genStitcherCodeReview)({ scope: 'functional', focus: 'praises' }),
|
|
141
|
+
],
|
|
142
|
+
concluder: stitcherCodeReviewConcluder,
|
|
143
|
+
});
|
|
144
|
+
(0, test_fns_1.when)('given the threads required', () => {
|
|
145
|
+
(0, test_fns_1.then)('it should successfully execute the stitches as a weave', async () => {
|
|
146
|
+
const output = await (0, enweaveOneFanout_1.enweaveOneFanout)({
|
|
147
|
+
stitcher: fanout,
|
|
148
|
+
threads: {
|
|
149
|
+
critic: {
|
|
150
|
+
...(0, genThread_1.genThread)({
|
|
151
|
+
role: 'critic',
|
|
152
|
+
tools: [],
|
|
153
|
+
facts: [],
|
|
154
|
+
}),
|
|
155
|
+
stitches: [stitchCodeRead],
|
|
156
|
+
},
|
|
157
|
+
director: (0, genThread_1.genThread)({ role: 'director' }),
|
|
158
|
+
},
|
|
159
|
+
}, { ...context, ...(0, getContextOpenAI_1.getContextOpenAI)() });
|
|
160
|
+
expect(output.stitch.output.length).toEqual(6);
|
|
161
|
+
console.log(output.stitch.output);
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
//# sourceMappingURL=enweaveOneFanout.integration.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enweaveOneFanout.integration.test.js","sourceRoot":"","sources":["../../../src/logic/weave/enweaveOneFanout.integration.test.ts"],"names":[],"mappings":";;AAAA,mDAA0C;AAC1C,uCAA6C;AAG7C,iFAA8E;AAC9E,uFAAoF;AACpF,6EAA0E;AAC1E,+GAAqG;AACrG,qGAAkG;AAClG,qGAAmG;AAEnG,gEAAoE;AAEpE,wDAAqD;AAErD,mDAAgD;AAChD,+DAA4D;AAC5D,yDAAsD;AAEtD,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,MAAM,OAAO,GAAG,EAAE,GAAG,IAAA,6CAAqB,GAAE,EAAE,GAAG,IAAA,uCAAkB,GAAE,EAAE,CAAC;IACxE,IAAA,gBAAK,EAAC,wDAAwD,EAAE,GAAG,EAAE;QACnE,MAAM,UAAU,GAAG,IAAI,eAAM,C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CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.enweaveOneFanout = void 0;
|
|
4
|
+
const uni_time_1 = require("@ehmpathy/uni-time");
|
|
5
|
+
const StitchSetEvent_1 = require("../../domain/objects/StitchSetEvent");
|
|
6
|
+
const enstitch_1 = require("../stitch/enstitch");
|
|
7
|
+
const withStitchTrail_1 = require("../stitch/withStitchTrail");
|
|
8
|
+
const enweaveOneStitcher_1 = require("./enweaveOneStitcher");
|
|
9
|
+
/**
|
|
10
|
+
* .what = mechanism to enweave a full stitch fanout
|
|
11
|
+
* .how =
|
|
12
|
+
* - executes a Promise.all(.parallels) and a .conclusion stitcher
|
|
13
|
+
*/
|
|
14
|
+
exports.enweaveOneFanout = (0, withStitchTrail_1.withStitchTrail)(async (input, context) => {
|
|
15
|
+
const { parallels, concluder } = input.stitcher;
|
|
16
|
+
// enweave parallel stitchers concurrently
|
|
17
|
+
const fanoutResults = await Promise.all(parallels.map((stitcher) => (0, enweaveOneStitcher_1.enweaveOneStitcher)({ stitcher, threads: input.threads }, context)));
|
|
18
|
+
// merge fanout results into grouped threads by role
|
|
19
|
+
const threadsAfterFanout = fanoutResults.reduce((acc, result) => {
|
|
20
|
+
for (const role of Object.keys(result.threads)) {
|
|
21
|
+
const thread = result.threads[role];
|
|
22
|
+
if (!acc[role])
|
|
23
|
+
acc[role] = { seed: input.threads[role], peers: [] };
|
|
24
|
+
acc[role].peers.push(thread);
|
|
25
|
+
}
|
|
26
|
+
return acc;
|
|
27
|
+
}, {});
|
|
28
|
+
// execute the concluder stitcher with the fanout threads
|
|
29
|
+
const { stitch: finalStitch, threads: finalThreads } = await (0, enstitch_1.enstitch)({ stitcher: concluder, threads: threadsAfterFanout }, context);
|
|
30
|
+
// declare the result
|
|
31
|
+
return StitchSetEvent_1.StitchSetEvent.build({
|
|
32
|
+
occurredAt: (0, uni_time_1.asUniDateTime)(new Date()),
|
|
33
|
+
stitch: finalStitch,
|
|
34
|
+
threads: finalThreads,
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
//# sourceMappingURL=enweaveOneFanout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enweaveOneFanout.js","sourceRoot":"","sources":["../../../src/logic/weave/enweaveOneFanout.ts"],"names":[],"mappings":";;;AAAA,iDAAmD;AAMnD,wEAAqE;AAGrE,iDAA8C;AAC9C,+DAA4D;AAC5D,6DAA0D;AAE1D;;;;GAIG;AACU,QAAA,gBAAgB,GAAG,IAAA,iCAAe,EAC7C,KAAK,EACH,KAGC,EACD,OAA6B,EACuC,EAAE;IACtE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC,QAAQ,CAAC;IAEhD,0CAA0C;IAC1C,MAAM,aAAa,GAAG,MAAM,OAAO,CAAC,GAAG,CACrC,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CACzB,IAAA,uCAAkB,EAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,EAAE,OAAO,CAAC,CAClE,CACF,CAAC;IAEF,oDAAoD;IACpD,MAAM,kBAAkB,GAAG,aAAa,CAAC,MAAM,CAC7C,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;QACd,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAC5B,MAAM,CAAC,OAAO,CACmB,EAAE,CAAC;YACpC,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAE,CAAC;YAErC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;gBAAE,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;YACtE,GAAG,CAAC,IAAI,CAAE,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAChC,CAAC;QAED,OAAO,GAAG,CAAC;IACb,CAAC,EACD,EAKC,CAC8B,CAAC;IAElC,yDAAyD;IACzD,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,MAAM,IAAA,mBAAQ,EACnE,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,kBAAkB,EAAE,EACpD,OAAO,CACR,CAAC;IAEF,qBAAqB;IACrB,OAAO,+BAAc,CAAC,KAAK,CAAC;QAC1B,UAAU,EAAE,IAAA,wBAAa,EAAC,IAAI,IAAI,EAAE,CAAC;QACrC,MAAM,EAAE,WAAW;QACnB,OAAO,EAAE,YAAY;KACtB,CAAC,CAAC;AACL,CAAC,CACF,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { StitchRoute } from '../../domain/objects/StitchRoute';
|
|
2
|
+
import { StitchSetEvent } from '../../domain/objects/StitchSetEvent';
|
|
3
|
+
import { GStitcher } from '../../domain/objects/Stitcher';
|
|
4
|
+
/**
|
|
5
|
+
* .what = mechanism to enweave a full stitch route
|
|
6
|
+
* .how =
|
|
7
|
+
* - executes a .sequence of stitchers
|
|
8
|
+
*/
|
|
9
|
+
export declare const enweaveOneRoute: <TStitcher extends GStitcher>(input: {
|
|
10
|
+
stitcher: StitchRoute<TStitcher>;
|
|
11
|
+
threads: TStitcher['threads'];
|
|
12
|
+
}, context: TStitcher['context']) => Promise<StitchSetEvent<TStitcher['threads'], TStitcher['output']>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|